Your Browser is not longer supported

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

{{viewport.spaceProperty.prod}}

Format of an S procedure

&pagelevel(4)&pagelevel

If a procedure is to make use of the programming facilities offered by SDF-P, it has to contain certain declaration and control commands in addition to the execution commands proper. The sample procedure below is intended to illustrate this; the meaning of each of the commands is subsequently explained.

This sample procedure outputs the last lines of a text file to SYSOUT (default: last ten lines):

/SET-PROC-OPT IMPLICIT-DECLARATION=*NO
/BEG-PARAM-DECL
/  DECL-PARAM FILE(TYPE=*STRING)
/  DECL-PARAM NUMBER-LINES(TYPE=*INTEGER,INIT=10)
/END-PARAM-DECL
/
/"For FILE a fully-qualified file name is expected       "
/"(without generation/version) or an element             "
/"specification in the format                            "
/" '[*LIBRARY-ELEMENT](library,element[(version)],type)' "
/
/"Required auxiliary variables:"
/DECL-VAR I(TYPE=*INTEGER)
/DECL-VAR DATA(TYPE=*STRING),MULTIPLE-ELEMENTS=*LIST
/DECL-VAR LIB(TYPE=*STRING)
/
/"Check whether the file/element exists to enable"
/"output of a specific error message"
/I = INDEX(FILE,'(')
/IF (I > 0)   "Name contains '(', therefore library"
/  LIB = SUBLIST(SUBSTR(FILE,I),1)   "library name"
/  IF NOT IS-CATALOGED-FILE(LIB)
/    WRITE-TEXT 'library &LIB does not exist!'
/    EXIT-PROCEDURE ERROR=*YES
/  END-IF
/  IF NOT IS-LIBRARY(LIB)
/    WRITE-TEXT 'file &LIB is not a library!'
/    EXIT-PROCEDURE ERROR=*YES
/  END-IF
/ELSE-IF NOT IS-CATALOGED-FILE(FILE)
/  WRITE-TEXT 'file &FILE does not exist!'
/  EXIT-PROCEDURE ERROR=*YES
/END-IF
/
/"Read data to a variable list"
/READ-VAR *LIST(DATA),STRING-QUOTES=*NO,INPUT=&FILE
/
/I = SIZE('DATA') - NUMBER-LINES + 1 "Calculate start position"
/IF (I < 1); I = 1; END-IF         "not before first line!"
/FOR I = *COUNTER( FROM = I, TO = SIZE('DATA'), INCREMENT = 1 )
/  WRITE-TEXT &(TO-C-LITERAL(DATA#I))
/END-FOR