Your Browser is not longer supported

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

{{viewport.spaceProperty.prod}}

Storing command output in variables

&pagelevel(4)&pagelevel

If the data and messages output by a command are to be collected for further analysis, output intended for SYSOUT may, for instance, be rerouted to a file or list variable and subsequently processed by string access functions. This method is, however, cumbersome and error-prone. Instead, the EXECUTE-CMD command can be used to output the text and return code supplied by any command to a variable directly. In addition, output from certain commands can be stored in variable structures in the form of pure user data that is then directly available for programming. The example below illustrates this method: a list of file names is compiled which is then used in a loop as input to the TRANSFER-FILE command:

/DECL-PARAM PATTERN
/DECL-VAR FILELIST(TYPE=*STRUCT),MULT-ELEM=*LIST
/DECL-VAR FILE(TYPE=*STRUCT)
/EXEC-CMD (SHOW-FILE-ATTR &PATTERN), -
/   TEXT-OUTPUT=*NONE,      "no output to SYSOUT" -
/   STRUCT-OUTPUT=FILELIST,  "struct. output in variable" -
/   RETURNCODE=*VAR(SUBCODE1=S1,     "== 0 if ok" -
/                   SUBCODE2=*NONE,  "not required" -
/                   MAINCODE=M)      "error code if any"
/IF (S1 > 0)
/  WRITE-TEXT 'error &M'
/  EXIT-PROC ERROR=*YES(MAIN=&M)   "return error to caller"
/END-IF
/FOR FILE = *LIST(FILELIST)
/  TRANSFER-FILE TO,HOSTXYZ,(&(FILE.F-NAME)),(...)
/END-FOR

The option of storing the messages output during command execution in variable structures is also provided. Message codes and variable inserts are stored separately, enabling them to be processed directly without analysis of the body of the message text.

A detailed description of the EXECUTE-CMD command is given on "EXECUTE-CMD Execute command and structured output ". The output structures generated by SDF-P commands are described in section “Structured output in Svariables”; information on other commands that support structured output can be found in the appropriate manuals.