Using REXX, could you please tell me how to copy one file (main-file) to a backup file. And then modify some data at definite positions in the Main-File (not the backup file). This is required to be done in a single JCL.
I have written a JCL which will execute in the following manner.
STEP1 - In the first STEP of the Parent JCL, run a JCL which will create a backup file of the main file with system time added to the end of backup file name.
STEP2 - In the second STEP of the Parent JCL, execute another REXX program which will do the modification of data in the main file.
Problem: When this Parent JCL is run, then main file is getting modified as required. But the backup file is also getting modified which is not required.
/* REXX Code for copying main file to back up file */
/* Program name = USERID.REXX.EXEC.DEMOPROG(PROG1) */
/* REXX */
PARSE ARG odsn inpfile
Call CurrTime
Call ChngFileNm
Call CreateBckFile
EXIT
/* END of Main Program */
CurrTime:
tod = TIME()
PARSE VAR tod hh ':' mn ':' ss
timedd = hh||mn
RETURN
/* End of Current Time */
ChngFileNm:
ndsn = odsn'.T'timedd
"RENAME '"odsn"' '"ndsn"' "
RETURN
/* End of Rename File */
CreateBckFile:
"alloc DA('"inpfile"') f(indd) shr reuse"
"alloc DA('"ndsn"') f(outdd) shr reuse"
"EXECIO * DISKR indd (STEM record."
"EXECIO 0 DISKR indd (FINIS"
"EXECIO" record.0 "DISKW outdd (STEM record."
"EXECIO 0 DISKW outdd (FINIS"
"FREE f(indd)"
"FREE f(outdd)"
RETURN
/* End of Create Back-up File */
------
/* REXX Code for modifying tha data in main input file */
/* Program name = USERID.REXX.EXEC.DEMOPROG(DEMOPROG) */
/* REXX */
PARSE ARG infile
Say '*******************'
Say '* MAIN PROGRAM *'
Say '*******************'
Say
Call DateRet
rc = 0
"alloc DA('"infile"') f(updd) OLD"
Call RevDate
EXIT
/* End Of Main */
DateRet:
"alloc DA('userid.rexx.exec.infile2') f(indd) shr reuse"
"EXECIO 1 DISKR indd (FINIS"
PULL record
PARSE VAR record 1 date1 11
PARSE VAR record 1 date1 11
PARSE VAR date1 1 year 5 6 mnth 8 9 day
date3 = year||mnth||day
"FREE f(indd)"
RETURN
/* End of Data retrieval */
Say
/* Start of Data Modification */
RevDate:
"EXECIO * DISKRU updd (STEM rec. FINIS"
IF rc = 0 THEN
DO
Say "-----------------------------------"
Say "- "rec.0 "records are read -"
Say "-----------------------------------"
Say
DO i = 1 TO rec.0
PARSE VAR rec.i 1 idx 3 remdata
IF idx = 00 THEN
DO
PARSE VAR remdata 1 val 3 date2 13 rest
remdata = val||date1||rest
rec.i = idx||remdata
END
ELSE
IF idx = 12 THEN
DO
PARSE VAR remdata 1 val 2 date2 10 rest
remdata = val||date3||rest
rec.i = idx||remdata
END
ELSE NOP
END
"EXECIO" rec.0 "DISKW updd (STEM rec."
IF rc = 0 THEN
DO
Say
Say rec.0 "records are modified"
END
ELSE
DO
rc = RC
Say
Say "Error during write, return code is" rc
END
END
ELSE
DO
rc = RC
Say
Say "Error during write, return code is" rc
END
Say
"EXECIO 0 DISKW updd (FINIS"
"FREE f(updd)"
RETURN
/* End of Reverse Data Modification */
------------
Above are the programs that I have written.
Please tell me if there is any possible solution for the above mentioned issue.
Joined: 08 May 2006 Posts: 1193 Location: Dublin, Ireland
You are submitting a job to run the REXX to copy the file in the first step. How do you know how soon this will run?
Youll probably find that the copy job is executing after the REXX to modify the file is run - so you get the same details in bopth the original and the copy.
I'd suggest you rethink your approach. Maybe setup the 'parent' JCL to use IEBCOPY or IEBGENER to copy the original file and only when the copy has completed run the REXX.