I want to write Header1 in output file if there is data in input file using DFSORT utility. I want to write Header2 if there is no data in input file. Can someone please tell me if IFTHEN can be used with OUTFIL to send different headers to output file.
Thanks Elo. Actually, the DB2 step already generates 9 reports. We need to add headers in the reports thru 9 different SORT steps. Generating Return Code might not be feasible. Any other way we can handle this - using OUTFIL statement or something similar.
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
Hello,
Quote:
We need to add headers in the reports thru 9 different SORT steps.
Seems like it might be better to add the headers in the program that generates the reports?
Quote:
Generating Return Code might not be feasible.
Why not
Is there one decision to make or 9 (1 per report)?
If there are 9, there is a slick little trick using powers of 2 that will let you set a return code that will cover all 9 off/on conditions. . . This would be much better than 9 steps to look for empty file(s).
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
Kodalis,
For the empty and non-empty cases, show an example of what you expect for output. Give the RECFM and LRECL of each input file and the expected output files.
Dick,
We need to make 9 decisions (1 per report). Can you please explain how to use powers of 2.
not everybody can see attachments
attachment inlined and deleted
Sample Input file:
Code:
****************************************************************************************************************
1ENO ERRORS FOUND
2N988004988004*07170GHANA CEDI NEW GHS 001.5340000002011-09-08 001.5055000002011-05-31
Sample Outputs:
1)
Code:
*****************************************************************************************************************
PROGRAM NAME: MSU380 PRICE RECORD IS FUTURE PAGE: 1
RUN DATE: 09/20/11 TIME: 00:36:44
NO ERRORS FOUND
2)
Code:
*****************************************************************************************************************
PROGRAM NAME: MSU380 PRICE RECORD IS FUTURE PAGE: 1
RUN DATE: 09/20/11 TIME: 00:36:44
PROCESS DATE: 09/20/11
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
Hello,
In the program that generates the 9 reports, set the Return Code as follows:
Define an accumulator (i call it ws-build-rc).
Move zero to ws-build-rc.
If the first report had data, add 1 to ws-build-rc.
If the second report had data, add 2 to ws-build-rc.
If the third report had data, add 4 to ws-build-rc.
If the fourth report had data, add 8 to ws-build-rc.
If the fifth report had data, add 16 to ws-build-rc.
If the sixth report had data, add 32 to ws-build-rc.
If the seventh report had data, add 64 to ws-build-rc.
If the eighth report had data, add 128 to ws-build-rc.
If the ninth report had data, add 256 to ws-build-rc.
Move ws-build-rc to RETURN-CODE.
GOBACK.
Looking over this, i would probably have the program that creates the reports use the same 9 compares and generate a jobstream that contains only the "copy" processes for the reports that had data (rather than setting the RETURN-CODE). This jobstream would then be submitted via the internal reader.
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
Kodalis,
All I see in your attachment is a sample input file with some records. That's not what I asked for. If you want my help, you need to give me what I asked for. Please don't attach files. Just show them inline here with code tags.
Again:
Quote:
For the empty and non-empty cases, show an example of what you expect for output. Give the RECFM and LRECL of each input file and the expected output files.
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
Quote:
Can someone please tell me if IFTHEN can be used with OUTFIL to send different headers to output file.
IFTHEN cannot be used to control HEADERx. IFTHEN can be used to control BUILD. Whether or not you can do what you want depends on exactly what you need to do (see my previous posts).
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
Well, something like this would work for one report, and separate jobs like this would work for each report, but I don't think it's what you're looking for.
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
kodalis wrote:
This will make 27 steps in total and doesn't work for us. Neverthelss, we learned some new features. Thanks for your help.
Kodalis,
Not really. Have you considered using IDCAMS to set the return code and then copy the appropriate header contents?
ex:
You will have 2 header statements .
EMTHDR file will have DFSORT statements for a empty file
DATHDR file will have DFSORT statements if your input as atleast 1 record.
Now using the PRINT function of IDCAMS and validating the return code you will copy either EMTHDR file or DATHDR file. Return-code = 0 means your input has atleast 1 record and you will repro DATHDR file and if RETURN-CODE=4 means your input is empty and you will repro EMTHDR file.
//SYSIN DD *
PRINT INFILE(IN01) CHARACTER COUNT(1)
IF LASTCC = 0 THEN DO
REPRO IFILE(DATHDR) OFILE(HD01)
END
ELSE IF LASTCC = 4 THEN DO
REPRO IFILE(EMTHDR) OFILE(HD01)
END
SET LASTCC = 0
PRINT INFILE(IN02) CHARACTER COUNT(1)
IF LASTCC = 0 THEN DO
REPRO IFILE(DATHDR) OFILE(HD02)
END
ELSE IF LASTCC = 4 THEN DO
REPRO IFILE(EMTHDR) OFILE(HD02)
END
SET LASTCC = 0
.... repeat the same for other 7 files
replacing the approriate DD names
//*
Now once you generated the apporiate header file all you need to do is simply concatenate that file to your sysin card like shown below