Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Programming statement sequences

&pagelevel(4)&pagelevel

Normally, if a program attempts to read statements from an S procedure and the next line of the procedure contains a command, the EOF condition is set for statement input, causing the program to terminate. This behavior is meant to prevent that a missing END statement will cause the program to continue, which may result in uncontrolled termination when another program is loaded at a later time.

On the other hand, it may be desirable to control the processing sequence of commands as well as statements via SDF-P control structures. This is supported by a BEGIN block with PROGRAM-INPUT=*MIXED-WITH-CMD which may contain a mixture of commands and statements. If the program expects a statement and detects a command instead, it is interrupted and resumed with the next statement:

/DECL-PARAM CONTROLFILE
/&*     In S procedures, SYSDTA and SYSSTMT are
/&*     assigned to SYSCMD by default
/DECL-VAR ADDLIST,MULT-ELEM=*LIST
/READ-VAR *LIST(ADDLIST),STRING-QUOTES=*NO,INPUT=&CONTROLFILE
/SHOW-VAR ADDLIST
/BEGIN-BLOCK PROGRAM-INPUT=*MIXED-WITH-CMD
/  START-LMS
//   OPEN-LIB PROJECT-LIB,*UPDATE
/    FOR NAME=*LIST(ADDLIST)
//     ADD-ELEM PROJ.&NAME,*LIB-ELEM(*STD,&NAME(*INCR),S)
/    END-FOR
// END
/END-BLOCK

In this example, a number of names are read into a list variable. Subsequently, the LMS statement ADD-ELEMENT is executed once for each list element, the name being repeatedly inserted in the statement by means of & replacement.

By analogy, data records can be programmed in the same way as statements. The SEND-DATA command enables the S procedure syntax to be used for data lines as well (e.g. with respect to indentation or continuation handling) and ensures that the use of variables will not cause any problems (by default, no & replacement is performed in data records). SEND-DATA expects a string expression as operand; the value of this operand is passed as a data line to a program that reads from SYSDTA. As an alternative, the operand value *EOF can be used to set an end condition for SYSDTA.