Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Conditional Header using DFSORT - OUTFIL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
View previous topic :: :: View next topic  
Author Message
kodalis

New User


Joined: 20 Nov 2009
Posts: 5
Location: Mumbai

PostPosted: Mon Sep 19, 2011 4:41 pm    Post subject: Conditional Header using DFSORT - OUTFIL
Reply with quote

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.
Back to top
View user's profile Send private message

THINKSRINIII
Warnings : 1

New User


Joined: 09 Jan 2009
Posts: 88
Location: India

PostPosted: Mon Sep 19, 2011 5:20 pm    Post subject:
Reply with quote

Hi,

I would suggest read the input file in one step and set the return code accordiingly if data is present .

Based on the return code, execute the sort step to print the header to output file.
Back to top
View user's profile Send private message
kodalis

New User


Joined: 20 Nov 2009
Posts: 5
Location: Mumbai

PostPosted: Mon Sep 19, 2011 5:29 pm    Post subject: Reply to: Conditional Header using DFSORT - OUTFIL
Reply with quote

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.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Sep 19, 2011 8:36 pm    Post subject:
Reply with quote

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 icon_confused.gif

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).
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Moderator


Joined: 15 Feb 2005
Posts: 7130
Location: San Jose, CA

PostPosted: Mon Sep 19, 2011 11:21 pm    Post subject:
Reply with quote

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.
Back to top
View user's profile Send private message
kodalis

New User


Joined: 20 Nov 2009
Posts: 5
Location: Mumbai

PostPosted: Tue Sep 20, 2011 11:24 am    Post subject: Reply to: Conditional Header using DFSORT - OUTFIL
Reply with quote

Frank,

Input file:
RECFM = FB
LRECL = 132

Output is routed to Mobius. Sample attached.


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                         
                                                                               
 BBH#     CUSIP#        DESC                           CURR LTST PX         LTST PX DA   M/E PX         M/E PX DA             
 ______   ____________  ______________________________ ____ ______________  __________   _____________ __________
                                                                               
 988004   988004*07170  GHANA CEDI NEW                 GHS  001.5340000000  2011-09-08   001.505500000 2011-05-31 
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Tue Sep 20, 2011 8:19 pm    Post subject:
Reply with quote

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.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Moderator


Joined: 15 Feb 2005
Posts: 7130
Location: San Jose, CA

PostPosted: Wed Sep 21, 2011 1:49 am    Post subject:
Reply with quote

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.
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Moderator


Joined: 15 Feb 2005
Posts: 7130
Location: San Jose, CA

PostPosted: Wed Sep 21, 2011 1:51 am    Post subject:
Reply with quote

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).
Back to top
View user's profile Send private message
kodalis

New User


Joined: 20 Nov 2009
Posts: 5
Location: Mumbai

PostPosted: Wed Sep 21, 2011 11:25 am    Post subject:
Reply with quote

Frank, hope this helps....


Quote:
For the empty case, example of header that we expect for output

Code:

PROGRAM NAME:  MSU380                         PRICE RECORD IS FUTURE                           PAGE:      1     
RUN DATE:  09/20/11                                                                          TIME: 00:36:44




Quote:
For the non-empty case, example of header that we expect for output

Code:

PROGRAM NAME:  MSU380                         PRICE RECORD IS FUTURE                        PAGE:      1             
RUN DATE:  09/20/11                                                                       TIME: 00:36:44           
PROCESS DATE:  09/20/11                         
                                                                               
 BBH#     CUSIP#        DESC                  CURR LTST PX         LTST PX DA   M/E PX         M/E PX DA     

Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Moderator


Joined: 15 Feb 2005
Posts: 7130
Location: San Jose, CA

PostPosted: Thu Sep 22, 2011 1:17 am    Post subject:
Reply with quote

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.

Code:

//S1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=...  input file
//SORTOUT DD DUMMY
//SYSIN DD *
  OPTION COPY
  OUTFIL NULLOFL=RC4
/*
//S2 EXEC PGM=SORT,COND=(0,EQ,S1)
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=... input file
//SORTOUT DD SYSOUT=*
//SYSIN DD *
  OPTION COPY
  OUTFIL HEADER1=('HEADER1')
/*
//S3 EXEC PGM=SORT,COND=(4,EQ,S1)
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=...  input file
//SORTOUT DD SYSOUT=*
//SYSIN DD *
  OPTION COPY
  OUTFIL HEADER1=('HEADER1'),HEADER2=('HEADER2')
/*
Back to top
View user's profile Send private message
kodalis

New User


Joined: 20 Nov 2009
Posts: 5
Location: Mumbai

PostPosted: Thu Sep 22, 2011 9:41 am    Post subject:
Reply with quote

This will make 27 steps in total and doesn't work for us. Neverthelss, we learned some new features. Thanks for your help.
Back to top
View user's profile Send private message
gcicchet

Senior Member


Joined: 28 Jul 2006
Posts: 1703
Location: Australia

PostPosted: Thu Sep 22, 2011 10:53 am    Post subject:
Reply with quote

Hi,

this would be more appropriate, no need to read the entire file to test if file is empty
Code:
  OPTION COPY,STOPAFT=1   
  OUTFIL NULLOFL=RC4     



Gerry
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Thu Sep 22, 2011 7:58 pm    Post subject:
Reply with quote

Hello,

Unless i am mistaken, you have 2 choices (other than do nothing):

1. Make the needed changes to the report creation program
2. Implement the multi-step solution Frank provided.
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Thu Sep 22, 2011 10:15 pm    Post subject:
Reply with quote

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.

Code:

//STEP0100 EXEC PGM=IDCAMS                         
//SYSPRINT DD SYSOUT=*                             
//EMTHDR   DD *                                     
  OUTFIL REMOVECC,                                 
  HEADER1=(001:'PROGRAM NAME:  MSU380',             
           047:'PRICE RECORD IS FUTURE',           
           115:'PAGE :',PAGE,/,                     
           001:'RUN DATE    :  ',DATE,             
           115:'TIME :',TIME,/)                     
//*                                                 
//DATHDR   DD *                                     
  OUTFIL REMOVECC,                                 
  HEADER1=(001:'PROGRAM NAME:  MSU380',             
           047:'PRICE RECORD IS FUTURE',           
           115:'PAGE :',PAGE,/,                     
           001:'RUN DATE    :  ',DATE,             
           115:'TIME :',TIME,/,                     
           001:'PROCESS DATE:  ',DATE,/,/,         
           003:'BBH#',011:'CUSIP#',025:'DESC',     
           047:'CURR LTST PX',068:'LTST PX DA',     
           081:'M/E PX',096:'M/E PX DA',//)         
//*                                                 
//IN01     DD DISP=SHR,DSN=Your Input FB 132 byte File1   
//IN02     DD DISP=SHR,DSN=Your Input FB 132 byte File2   
//IN03     DD DISP=SHR,DSN=Your Input FB 132 byte File3   
//IN04     DD DISP=SHR,DSN=Your Input FB 132 byte File4   
//IN05     DD DISP=SHR,DSN=Your Input FB 132 byte File5   
//IN06     DD DISP=SHR,DSN=Your Input FB 132 byte File6   
//IN07     DD DISP=SHR,DSN=Your Input FB 132 byte File7   
//IN08     DD DISP=SHR,DSN=Your Input FB 132 byte File8   
//IN09     DD DISP=SHR,DSN=Your Input FB 132 byte File9
//*   
//HD01     DD DSN=&&HD01,DISP=(,PASS),             
//            SPACE=(TRK,(1,1),RLSE),             
//            DCB=(LRECL=80,RECFM=FB,BLKSIZE=27920)
//*                                               
//HD02     DD DSN=&&HD02,DISP=(,PASS),             
//            SPACE=(TRK,(1,1),RLSE),             
//            DCB=(LRECL=80,RECFM=FB,BLKSIZE=27920)
//*               
.... repeat the declarations of other header files
                               
//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

Code:

//STEP0200 EXEC PGM=SORT                           
//SYSOUT   DD SYSOUT=*                             
//SORTIN   DD DISP=SHR,DSN=Your Input FB 132 byte File1 
//SORTOUT  DD SYSOUT=*                             
//SYSIN    DD *                                   
  SORT FIELDS=COPY
  ..any other Sort statements                                 
//         DD DSN=&&HD01,DISP=SHR                 
//*
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts How to get the remainder and quotient... vnktrrd DFSORT/ICETOOL 2 Mon Oct 31, 2016 10:59 am
No new posts Change date (DD/MM/YY) in 2nd record ... uday kiran DFSORT/ICETOOL 12 Wed Sep 07, 2016 10:57 pm
No new posts DFSORT sorting only specific records akodakka DFSORT/ICETOOL 4 Thu Aug 04, 2016 11:24 am
No new posts Symbolic Parameters in SYSIN DD state... madishpa DFSORT/ICETOOL 3 Mon Jun 27, 2016 6:23 pm
No new posts DFSORT to match two files and write John F Dutcher DFSORT/ICETOOL 6 Thu May 12, 2016 5:17 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us