This guideline is very simple, yet it will allow LANSA programs to be completed more quickly and accurately.
When working on the code of a specific RDML function, always attempt to use a "top down" approach to coding. For instance, you may be given a program "specification" which looks like this:
- Repeat until program terminated at user request
- Get the user to input an order number
- Get details of the order, and handle record not found
- Get details of all the order lines
- Display the order details and the line details
You must now "translate" this specification into the LANSA rapid development language.
With a structured (or organized) approach to coding, the program will follow similar steps to the example below.
Note how the arrow --> is used to indicate the new lines inserted in each step:
Step 1
--> ********** Do until terminated by EXIT or MENU key --> BEGIN_LOOP --> END_LOOP
Step 2
********** Do until terminated by EXIT or MENU key BEGIN_LOOP --> ********** Request order number input until order is found --> ********** Build a list of all order lines --> ********** Display the order and its lines to the user END_LOOP
Step 3
********** Do until terminated by EXIT or MENU key BEGIN_LOOP ********** Request order number until order is found --> DOUNTIL COND('#IO$STS = OK') --> ENDUNTIL ********** Build a list of all order lines ********** Display the order and its lines to the user END_LOOP
Step 4
********** Do until terminated by EXIT or MENU key BEGIN_LOOP ********** Request order number until order is found DOUNTIL COND('#IO$STS = OK') ENDUNTIL ********** Build a list of all order lines --> CLR_LIST NAMED(#LINES) --> SELECT FIELDS(#LINES) FROM_FILE(ORDLIN) WITH_KEY(#ORDNUM) --> ENDSELECT ********** Display the order and its lines to the user END_LOOP
Step 5
********** Do until terminated by EXIT or MENU key BEGIN_LOOP ********** Request order number until order is found DOUNTIL COND('#IO$STS = OK') ENDUNTIL ********** Build a list of all order lines CLR_LIST NAMED(#LINES) SELECT FIELDS(#LINES) FROM_FILE(ORDLIN) WITH_KEY(#ORDNUM) ENDSELECT ********** Display the order and its lines to the user --> DISPLAY FIELDS(#HEADER) BROWSELIST(#LINES) END_LOOP
Step 6
********** Do until terminated by EXIT or MENU key BEGIN_LOOP ********** Request order number until order is found DOUNTIL COND('#IO$STS = OK') --> ********** Request user inputs an order number --> ********** Attempt to locate the order --> ********** Issue message if order was not found ENDUNTIL ********** Build a list of all order lines CLR_LIST NAMED(#LINES) SELECT FIELDS(#LINES) FROM_FILE(ORDLIN) WITH_KEY(#ORDNUM) ENDSELECT ********** Display the order and its lines to the user DISPLAY FIELDS(#HEADER) BROWSELIST(#LINES) END_LOOP
Step 7
********** Do until terminated by EXIT or MENU key BEGIN_LOOP ********** Request order number until order is found DOUNTIL COND('#IO$STS = OK') ********** Request user inputs an order number REQUEST FIELDS(#ORDNUM) ********** Attempt to locate the order --> FETCH FIELDS(#HEAD) FROM_FILE(ORDMST) WITH_KEY(#ORDNUM) ********** Issue message if order was not found ENDUNTIL ********** Build a list of all order lines CLR_LIST NAMED(#LINES) SELECT FIELDS(#LINES) FROM_FILE(ORDLIN) WITH_KEY(#ORDNUM) ENDSELECT ********** Display the order and its lines to the user DISPLAY FIELDS(#HEADER) BROWSELIST(#LINES) END_LOOP
Step 8
********** Do until terminated by EXIT or MENU key BEGIN_LOOP ********** Request order number until order is found DOUNTIL COND('#IO$STS = OK') ********** Request user inputs an order number REQUEST FIELDS(#ORDNUM) ********** Attempt to locate the order FETCH FIELDS(#HEAD) FROM_FILE(ORDMST) WITH_KEY(#ORDNUM) ********** Issue message if order was not found --> IF_STATUS WAS_NOT(*OKAY) --> ENDIF ENDUNTIL ********** Build a list of all order lines CLR_LIST NAMED(#LINES) SELECT FIELDS(#LINES) FROM_FILE(ORDLIN) WITH_KEY(#ORDNUM) ENDSELECT ********** Display the order and its lines to the user DISPLAY FIELDS(#HEADER) BROWSELIST(#LINES) END_LOOP
Step 9
********** Do until terminated by EXIT or MENU key BEGIN_LOOP ********** Request order number until order is found DOUNTIL COND('#IO$STS = OK') ********** Request user inputs an order number REQUEST FIELDS(#ORDNUM) ********** Attempt to locate the order FETCH FIELDS(#HEAD) FROM_FILE(ORDMST) WITH_KEY(#ORDNUM) ********** Issue message if order was not found IF_STATUS WAS_NOT(*OKAY) --> MESSAGE MSGTXT('No details of this order found') ENDIF ENDUNTIL ********** Build a list of all order lines CLR_LIST NAMED(#LINES) SELECT FIELDS(#LINES) FROM_FILE(ORDLIN) WITH_KEY(#ORDNUM) ENDSELECT ********** Display the order and its lines to the user DISPLAY FIELDS(#HEADER) BROWSELIST(#LINES) END_LOOP
Step 10
********** Do until terminated by EXIT or MENU key BEGIN_LOOP ********** Request order number until order is found DOUNTIL COND('#IO$STS = OK') ********** Request user inputs an order number REQUEST FIELDS(#ORDNUM) ********** Attempt to locate the order FETCH FIELDS(#HEAD) FROM_FILE(ORDMST) WITH_KEY(#ORDNUM) ********** Issue message if order was not found IF_STATUS WAS_NOT(*OKAY) MESSAGE MSGTXT('No details of this order found') ENDIF ENDUNTIL ********** Build a list of all order lines CLR_LIST NAMED(#LINES) SELECT FIELDS(#LINES) FROM_FILE(ORDLIN) WITH_KEY(#ORDNUM) --> ADD_ENTRY TO_LIST(#LINES) ENDSELECT ********** Display the order and its lines to the user DISPLAY FIELDS(#HEADER) BROWSELIST(#LINES) END_LOOP
You should find that well structured and documented programs are very easy to produce by using this type of approach, which basically consists of always:
- entering the structured programming constructs completely before coming back to fill in the details. For example: BEGIN_LOOP/END_LOOP, DOUNTIL/ENDUNTIL, SELECT/ENDSELECT, IF/ELSE/END, etc. etc.
- including the comments before the commands.