I need to create a CL pgm to copy data from 2 files into one. The first file's name to be copied is constant but the second file's name changes on a daily basis. Could anyone help with the syntax required to do this?
Thx
Software/Hardware used:
ASKED:
May 11, 2009 1:50 PM
UPDATED:
May 12, 2009 2:37 PM
Hi,
You could do something like the following :-
PGM PARM(&FILE &LIB)
DCL &FILE *CHAR 10
DCL &LIB *CHAR 10
CPYF FROMFIL(LIB1/FILE1) TOFILE(LIB1/NEWFILE) MBROPT(*REPLACE)
CPYF FROMFILE(&LIB/&FILE) TOFILE(LIB1/NEWFILE) MBROPT(*ADD)
ENDPGM
Where LIB1/FILE1 is the (from)file which is always the same name and LIB1/NEWFILE is the file you have to copy to. &FILE is the variable file name and &LIB is the library that contains the variable file name.
You could then call the program :-
CALL PROGRAM PARM(Myfile Mylib)
To process file Myfile in library Mylib. If your variable file is always in the same library then you could remove the &LIB coding and replace the library name in the CPYF command – you also wouldn’t need to pass the library on the CALL command.
Regards,
Martin Gilbert.
Many thx.
The 2 files contain details of reports that are produced on a daily basis, which are to be downloaded into a report archive system for people to view. The first file name is constant but the second changes daily in the format of the date e.g. CYYMMDD
File name examples as follows:
DOWNLOAD
C090512
I need a cl pgm to copy the report data on a daily basis from these 2 files into a new file, that will then be used to download the reports to the archive software.
I don’t know how to include the data from the file name that changes, and whether I need to declare any variables or message monitoring etc.
I would appreciate any help you can give.
Thx
Hi,
You could try the following – this gets the date from the system values and uses that to build the file name – it assumes that all the files are in library YOURLIB. It creates a file called ARCHIVE with a record length of 132 which you can then download – maybe you’ll need to increase the record length, depending on your input files. You may need some extra MONMSG’s for the CPYF statements. :-
PGM
DCL &FILENAME *CHAR 10
DCL &DD *CHAR 2
DCL &MM *CHAR 2
DCL &YY *CHAR 2
RTVSYSVAL QDAY &DD
RTVSYSVAL QMONTH &MM
RTVSYSVAL QYEAR &YY
CHGVAR &FILENAME (‘C’ || &YY || &MM || &DD)
CRTPF FILE(YOURLIB/ARCHIVE) RCDLEN(132)
MONMSG CPF7302
CPYF FROMFILE(YOURLIB/DOWNLOAD) TOFILE(YOURLIB/ARCHIVE) MBROPT(*REPLACE)
CPYF FROMFILE(YOURLIB/&FILENAME) TOFILE(YOURLIB/ARCHIVE) MBROPT(*ADD)
ENDPGM
Regards,
Martin Gilbert.
Gilly400,
Thx for input. I know only the basics when it comes to cl.
The 2 files are already created and it is these files that are required to be copied. How do you get the data from the correct file? The format of the file is YYMMDD preceded always by the letter ‘C’. E.G C090512.
So, after our end of day processing today the system will create the next days file which will be C090513, and populate it with the data needed.
How do you get the correct data from the current file as the previous ones are still held in the library until save/deleted?
Thx
Hi,
You can use RTVSYSVAL to retrieve the system date. Then you can use the date as (part of) the file name. This is what the CHGVAR command does in my example – it “concatenates” the letter C and the year, month and day to give C090512 for the 12th of May 2009. Of course you would need to do this on the same day as your file is created.
Regards,
Martin Gilbert.
Hi,
Many thanks for your help. I’ll set this up in our test system.
Regards
Keith