Your Browser is not longer supported

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

{{viewport.spaceProperty.prod}}

Re-using S variables

&pagelevel(6)&pagelevel
Example 4
/write-text 'There are &(var#3.F-SIZE) PAM pages reserved for 
file &(var#3.SHORT-F-NAME)'
There are 3 PAM pages reserved for file JOBC

Example 4 is based on the structured output of Example 2.

The contents of S variables var#3.SHORT-F-NAME and var#3.F-SIZE can be re-used by means of expression substitution.

Example 5

The contents of S variable FILES are to be re-used in S procedure proc.s-var.

S procedure proc.s-var
/DECL-VAR FILES(TYPE=*STRUCTURE),MULTIPLE-ELEM=*LIST---------------------------(1)
/DECL-VAR INCR(TYPE=*STRUCTURE)------------------------------------------------(2)
/DECL-VAR FILES-OLD,MULTIPLE-ELEM=*LIST----------------------------------------(3)
/
/WRITE-TEXT '*******************************************************'
/WRITE-TEXT '** This procedure lists all files which have         **'
/WRITE-TEXT '** not been modified for over 365 days               **'
/WRITE-TEXT '*******************************************************'
/
/
/EXEC-CMD (SHOW-FILE-ATTR *ALL,INF=*PAR(HIST=*YES),
/          SELECT=*BY-ATTR(LAST-ACCESS-DATE=*INTERVAL(TO=-365))),
/          STRUCTURE-OUTPUT=FILES,TEXT-OUTPUT=*NONE ---------------------------(4)
/
/WRITE-TEXT 'The following files have not been modified in the last 365 days:'
/FOR INCR=*LIST(FILES)
/    WRITE-TEXT 'FILE: &(INCR.SHORT-F-NAME)' ----------------------------------(5)
/    MODIFY-FILE-ATTRIBUTES FILE-NAME=&(INCR.SHORT-F-NAME),
/           NEW-NAME=&('OLD.'//INCR.SHORT-F-NAME) -----------------------------(6)
/    IF-CMD-ERROR -------------------------------------------------------------(7)
/       WRITE-TEXT 'Error renaming file: -
/                   &(INCR.SHORT-F-NAME)'
/    END-IF
/    ELSE
/       SET-VAR FILES-OLD='&('OLD.'//INCR.SHORT-F-NAME)',WRITE-MODE=*EXTEND ---(8)
/    END-IF
/END-FOR
/WRITE-TEXT 'List of all files with the prefix OLD'
/SHOW-VAR FILES-OLD,INF=*PAR(LIST-INDEX-NUMBER=*YES) --------------------------(9)

(1)

S variable FILES is declared as a structured list variable.

(2)

An incrementing variable is declared for the subsequent FOR loop; this must also be of type STRUCTURE.

(3)

FILES-OLD is declared as a list variable. Here all the file names starting with the prefix “OLD” will be stored.

(4)

The EXECUTE-CMD command causes the output of SHOW-FILE-ATTRIBUTES INF=*PAR(HIST=*YES) to be stored in the FILES S variable. Output to SYSOUT is suppressed by TEXT-OUTPUT=*NONE. The SELECT operand selects all files last modified over 365 days ago.

(5)

Each file that has not been modified for over 365 days is listed under its file name as stored in the INCR.SHORT-F-NAME S variable.

(6)

The MODIFY-FILE-ATTRIBUTES command adds the prefix “OLD.” to the names of the selected files.

(7)

If an error occurs while MODIFY-FILE-ATTRIBUTES is executing, it is handled by the IF-CMD-ERROR block.

(8)

The SET-VARIABLE command assigns the new file name with the prefix “OLD.” to the FILES-OLD S variable. The MODE=*EXTEND argument causes FILES-OLD to be extended by one list element each time the rename loop iterates.

(9)

The contents of FILES-OLD are output by the SHOW-VAR command.

Execution log

/call-proc proc.s-var

*******************************************************
** This procedure lists all files which have         **
** not been modified for over 365 days               **
*******************************************************
The following files have not been modified in the last 365 days:
FILE: ISAM
FILE: MESSAGEMAKER
FILE: MSE1
FILE: MSE2
FILE: MSG.OUTPUT
FILE: MSG.PROC
FILE: README.RZ
FILE: README.RZ.ISAM
FILE: README.RZ.OLD
FILE: VAR.PROC
List of all files with the prefix OLD
FILES-OLD#1 = OLD.ISAM
FILES-OLD#2 = OLD.MESSAGEMAKER
FILES-OLD#3 = OLD.MSE1
FILES-OLD#4 = OLD.MSE2
FILES-OLD#5 = OLD.MSG.OUTPUT
FILES-OLD#6 = OLD.MSG.PROC
FILES-OLD#7 = OLD.README.RZ
FILES-OLD#8 = OLD.README.RZ.ISAM
FILES-OLD#9 = OLD.README.RZ.OLD
FILES-OLD#10 = OLD.VAR.PROC

Example 6

Example 6 builds on the S procedure described in Example 5. If you want to restore the original file names of all files with the prefix “OLD.”, you can do so interactively using the following commands:

/decl-var restore(type=struc),mult-elem=*list
/exec-cmd (show-file-attr old.*,inf=*all),struc-output=restore,text-output=*none
/decl-var y(type=struc)
/for y=*list(restore)
%FOR/mod-fi-attr &(y.SHORT-F-NAME),&(substring(y.SHORT-F-NAME,5))
%FOR/end-for