Expand AND Expansion STATEMENTS

PURPOSE:  ACCENT R offers the EXPANSION capability as an alternative method of designing lengthy programs.  This design groups primary statements at the beginning of a section, then presents the detail for each primary statement as a block later in the section.  This will clarify the overall flow of logic.  The block of statements is preceded by the EXPANSION statement.  The primary statement is identified by the EXPAND statement.  This capability can be used in any executable section.  The limit on the number EXPANSIONS that could be defined in a PM is 8191.

SYNTAX

EXPAND name

EXPAND name

directs program flow to a later EXPANSION of the same name.  Syntax for the name is the same as for field names.

EXPANSION name

heads the group of statements that are to be executed when the EXPAND name statement is encountered.

EXPANSIONs are like Routines in that they cannot include the inter-record functions.  However, the EXPAND statement and its EXPANSION must be within the same section.  A given expansion can only be called once.  The EXPAND statement must precede the EXPANSION.  EXPANSIONs must be the last object in a section.  An EXPANSION can only be terminated by another EXPANSION statement, by a section name, or by the end of the Process Module (PM).  EXPANSIONs can contain any statement appropriate to the section in which they appear.  This supports the concept of top down design and allows you to design the solution in a given section to be separated into smaller logically coded groups of statements.

Example

If there are multiple statements within each part of an IF nest, the following structure makes it much easier to see the overall logic of the program than if all the statements were included "in place."

!=============
DETAIL SECTION
!=============
IF statement
EXPAND name1
ELSE statement
EXPAND name2
CONTINUE
EXPAND name3
.
.
.
EXPANSION name1
!==================
statements
EXPANSION name2
!==================
statements
EXPANSION name3
!==================
statements
!==============
FINAL SECTION
!==============

The EXPAND statements and comments show clearly what tasks the DETAIL section covers.  The detail of those tasks is expanded later defined in the groups of statements headed by the EXPANSION statement.

!=============
DETAIL SECTION
!=============
!get & check store data
EXPAND STORE_CHECK
!get & check order data
EXPAND ORDER_CHECK
!get date
EXPAND DATE
!supply discount amounts
EXPAND DISCOUNT_CHECK
!print to proof report
PRINT 10B,STORE_CODE,3B,ORD_NUM,4B,ORD_DATE,& 4B,QTY @1,3B,TITLE_CODE:M
!
!EXPANSIONS FOLLOW
EXPANSION STORE_CHECK
!=======================
TYPE @CR, "ENTER STORE CODE: ", NOCR HUSH
START:10
ACCEPT STORE_CODE:M
SETUP TO OMIT MASTER IF STORE_CODE:M = " "
EXIT PROCESS IF STORE_CODE:M = " "
GET MATCH BY STORE_CODE:M FROM AUX1 HUSH
LEAVE:10 IF @AUX = "YES"
TYPE"STORE CODE NOT IN MASTER FILE",@CR, & 
"PLEASE RE-ENTER:",NOCR
REPEAT:10
EXPANSION ORDER_CHECK
!=======================
START:10
TYPE "ENTER ORDER NUMBER: ", NOCR
ACCEPT ORD_NUM:M
GET MATCH BY STORE_CODE,ORD_NUM:M FROM AUX2 HUSH
LEAVE:10 IF (@AUX = "YES")
TYPE "ENTRY MUST BE FOR AN EXISTING ORDER",&
"NUMBER.", @CR, "PLEASE RE-ENTER", NOCR
REPEAT:10
  EXPANSION DATE
TYPE "ENTER ORDER DATE: ", NOCR
ACCEPT DATE:M
EXPANSION DISCOUNT_CHECK
!=======================
TYPE "ENTER ORDER QUANTITY: ", NOCR
ACCEPT QTY:D
IF QTY > 100
.1 TO DISCOUNT
ELSE
0 TO DISCOUNT
CONTINUE