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 |
(2) | An incrementing variable is declared for the subsequent FOR loop; this must also be of type STRUCTURE. |
(3) |
|
(4) | The EXECUTE-CMD command causes the output of |
(5) | Each file that has not been modified for over 365 days is listed under its file name as stored in the |
(6) | The |
(7) | If an error occurs while |
(8) | The |
(9) | The contents of |
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