My requirement is to copy records from input file to output file, if the job is running on a particular day and time(Ex: Wednesday after 7.00 PM) and it needs to be done through JCL directly(not through Cobol or some other Programming language).
I am planning to implement it as follows:
1. Write a SQL step as below to get the current day and time
//DSNTIAUL EXEC DSNTIAUL,DBSID=...,PARAM='SQL'
//SYSPUNCH DD DSN=...
// DISP=(,CATLG,DELETE)
//SYSREC00 DD DSN=...
// DISP=(,CATLG,DELETE),
// SPACE=(1,(2000,500)),AVGREC=M
//SYSIN DD *
SELECT dayofweek(current date), current time from sysibm.sysdummy1;
/*
2. Write a SORT step with include condition with the given days and time, so that output is 1 record or 0 records
3. Write IDCAMS step as below so that it returns either return code 0(if 1 record) or 4(if 0 records)
4. write SORT step to copy depending on this return code above
But, Is there a better way, instead of using steps 2 , 3 and 4 above? is it possible to copy records from input file2 to Output file, if the record in input file1(it contains only 1 record) contains a particular value?
Thanks for your suggestion. I have mentioned, I can use IDCAMS to get a return code of 0 or 4 based on file is empty or not. But my aactual question is as follows:
Suppose, there are two input files in which file1 contains only 1 record(ex: date) and file2 contains hundred records. Is it possible to use a SORT to copy all records from file2 to output file, if date in file1 matches a particular value.
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
smudunuru,
Your requirement can be achieved in a single DFSORT step. I need the following details
1. LRECL and RECFM of your input file
2. Position and format of the DAY field in your input file
3. position and format of the TIME field in your input file
4. Show me a sample input and desired output
1. file1(contains day and time): LRECL= 80, RECFM=FB
Code:
6 11.27.42
file2(actual data): LRECL= 200, RECFM=FB
Outfile: LRECL=200, RECFM=FB
2&3. Day: position 1, length 1
Time: position 11, length 8
4. If the day in file1 is 5 and time is greater than 19.00.00, then outfile should contain the same data as file2, otherwise outfile should not contain any records
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
smudunuru,
I don't see a reason as to why you need to check the first file, if your intention is to copy the records based on the hard coded values.It is just a simple include condition . if your input has any records that satisfy that condition they will be written to the output or else you will have an empty file.
Even if you wanted to pick the current day values you don't need the other file. The system symbol LWDAY gives you the day of the week in 3 letter form. MON, TUE, WED,THU...
We pad this at the end of every record i.e pos 201.
Dayofweek function in DB2 returns an integer in the range of 1 to 7 that represents the day of the week where 1 is Sunday and 7 is Saturday. using a Bunch of IFTHEN's we convert the day of the week we got from system symbol to a numeric value and use it on the include condition on OUTFIL. since today is day 6 (FRI) , I only pick one value from the sample output.