Page 1 of 1

How can I include headder information in the details

PostPosted: Sat Sep 08, 2012 1:14 am
by gdchipi
Hi everyone:

I have to find the way to make a report with the following information:

Input file

       BH0125JO29
       PT220010731120000001000
       PT220010731120000001000     
       BH0125JO30
       PT220020831120000001000
       PT220020831120000001000   
       PT220020831120000001000         


Output file should be

 JO29  22001  07/31/12        2,000.00
 JO30  22002  08/31/12        3,000.00


I need to include this info from the header JO29,JO30 and 22001-22002 , 07/31/12- 08/31/12 from the details. Also need to sum the amounts in the detail (2 records with 1000 in the first group and 3 records with 1000 in the second one). Key is in the header (JO29-JO30) and match with the field from 3-7 in the details (22001 in the first group and 22002 in the second one).


Is there a way to build the output using SORT instruction? I tried but I couldn't.

Code'd

Re: How can I include headder information in the details

PostPosted: Sat Sep 08, 2012 1:21 am
by BillyBoyo
Have a look at WHEN=GROUP with BEGIN, assuming your DFSORT is up-to-date. PUSH on the GROUP allows you to copy data from the record defining the group to all the records that are part of the group.

Search here and in the manuals for examples. Let us know how it goes. Someone will be here if you get stuck.

Edit: KEYBEGIN corrected to BEGIN.

Re: How can I include headder information in the details

PostPosted: Sat Sep 08, 2012 1:21 am
by dick scherrer
Hello and welcome to the forum,

Suggest you post what you tried and what happened.

Post any diagnostic or error information that was presented. If the results were other than what you wanted, show what you wanted and what was actually generated.

Mention the recfm and lrecl of the input and output files.

Use the "Code" tag to preserve alignment and improve readability.

Re: How can I include headder information in the details

PostPosted: Sat Sep 08, 2012 1:27 am
by gdchipi
input file RECFM=FB,LRECL=180
output file RECFM=FB,LRECL=72


I tried usign IFWHEN, PARSE but I cant get any result.

Re: How can I include headder information in the details

PostPosted: Sat Sep 08, 2012 3:12 am
by skolusu
gdchipi,

Use the following DFSORT JCL which will give you the desired results.

//STEP0100 EXEC PGM=SORT                                         
//SYSOUT   DD SYSOUT=*                                           
//SORTIN   DD *                                                   
BH0125JO29                                                       
PT220010731120000001000                                           
PT220010731120000001000                                           
----+----1----+----2----+----3----+----4----+----5----+----6----+-
BH0125JO30                                                       
PT220020831120000001000                                           
PT220020831120000001000                                           
PT220020831120000001000                                           
//SORTOUT  DD SYSOUT=*                                           
//SYSIN    DD *                                                   
  SORT FIELDS=COPY                                               
  INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,2,CH,EQ,C'BH'),PUSH=(181:7,4))
  OUTFIL REMOVECC,NODETAIL,BUILD=(72X),                           
  SECTIONS=(181,4,                                               
  TRAILER3=(181,4,X,3,5,X,8,2,'/',10,2,'/',12,2,X,               
            TOT=(20,4,ZD,EDIT=(III,IIT)),'.00'))                 
//*

Re: How can I include headder information in the details

PostPosted: Mon Sep 10, 2012 9:40 pm
by gdchipi
Thanks a lot. It works

I forgot to include another thing so my case was incomplete. What I really need is to sum the mount in the details and not include the header. Below is what I have:

BH0125JO30      4   1   1000                                                 
PT220020831120000001000                                           
PT220020831120000001000                                           
PT220020831120000001000 



The amount should sum 3,000 and not what is in the header.

In there a way to do that?

Code'd

Re: How can I include headder information in the details

PostPosted: Mon Sep 10, 2012 10:46 pm
by skolusu
gdchipi wrote:Thanks a lot. It works The amount should sum 3,000 and not what is in the header.


gdchipi,

Did you even run the job I gave you? You say it works and then again you say it is NOT summing. If you had run the job as is you would have seen that I am indeed summing the detail records.

Re: How can I include headder information in the details

PostPosted: Mon Sep 10, 2012 11:00 pm
by gdchipi
I tried to run using
BH0125JO29           4   1000
PT220010731120000001000
PT220010731120000001000
BH0125JO30           4   1000
PT220020831120000001000
PT220020831120000001000
PT220020831120000001000



and I get

JO29 22001 07/31/12   3,000.00
JO30 22002 08/31/12   4,000.00



So was summing the header too

Code'd

Re: How can I include headder information in the details

PostPosted: Mon Sep 10, 2012 11:46 pm
by skolusu
When posting Data, please use CODE tags , so that it is easy to understand. If you look at my example, the header record BH is having spaces at position 20 and hence I only got the summed value of detail records.

Use the following DFSORT JCL which will give you the desired results
//STEP0100 EXEC PGM=SORT                                     
//SYSOUT   DD SYSOUT=*                                       
//SORTIN   DD *                                             
BH0125JO29         1000                                     
PT220010731120000001000                                     
PT220010731120000001000                                     
BH0125JO30         1000                                     
PT220020831120000001000                                     
PT220020831120000001000                                     
PT220020831120000001000                                     
//SORTOUT  DD SYSOUT=*                                       
//SYSIN    DD *                                             
  SORT FIELDS=COPY                                           
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(185:20,4)),               
  IFTHEN=(WHEN=GROUP,BEGIN=(1,2,CH,EQ,C'BH'),PUSH=(181:7,4)),
  IFTHEN=(WHEN=(1,2,CH,EQ,C'BH'),OVERLAY=(185:4C'0'))       
                                                             
  OUTFIL REMOVECC,NODETAIL,BUILD=(72X),                     
  SECTIONS=(181,4,                                           
  TRAILER3=(181,4,X,3,5,X,8,2,'/',10,2,'/',12,2,X,           
            TOT=(185,4,ZD,EDIT=(III,IIT)),'.00'))           
//*


The output from this is
JO29 22001 07/31/12   2,000.00
JO30 22002 08/31/12   3,000.00

Re: How can I include headder information in the details

PostPosted: Tue Sep 11, 2012 3:16 am
by gdchipi
Thanks a lot:
Works perfecly. Its what I wanted.
Thanks a lot again.