Joined: 17 Dec 2002 Posts: 53 Topics: 14 Location: BengaLuru
Posted: Thu Jul 22, 2004 10:18 am Post subject: copying a portion of a file
Hello,
I have a report which has both the detailed records and the summary records. I want to copy the summary records along with the header into another file.
To give an idea, the report has,
Report-id Title Date
page-num
header1
header2
-----------------------------------------------------------------
detail1
detail2
detail3
-----------------------------------------------------------------
Report-id Title Date
page-num
header1
header2
------------------------------------------------------------------
Summary for report:
Summary1
Summary2
grand total
Now, I want to use sort, preferably syncsort, to write the summary portion of the report into another file.
What would the best way be? I am thinking on the lines,
1. get the line number of the record having 'Summary for report' - as this has a fixed position always. Lets say it is 'n'
2. subtract 5 lines to get the line number of the previous header record
3. use SKIPREC=n-5 or using STARTREC and ENDREC
I am not sure if I can do an arithmetic operation in the SKIPREC statement.
Any ideas as to how good this is? or any other alternatives?
Regards
Vallish _________________ If you're not failing every now and again, it's a sign you're not doing anything very innovative.
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
Posted: Thu Jul 22, 2004 10:38 am Post subject:
vallish,
Everything you asked for is achievable. Let me know the following details.
1. What is the LRECL & RECFM of the input file
2. What is the position of the string 'Summary for report'?
3. post a sample of input and expected output. I was confused with your logic of subtracting 5 from record number.
Joined: 17 Dec 2002 Posts: 53 Topics: 14 Location: BengaLuru
Posted: Thu Jul 22, 2004 10:53 am Post subject:
1. LRECL = 132, RECFM=FB
2. The position of 'SUMMARY OF REPORT' is 1
3. Sample of input:
Quote:
RPT:00001 BANK AMOUNTS REPORT Date:22/7/2004
Page: 1
__________________________________________________________________
Bank Code: ABC
Bank Name: ABC Bank
__________________________________________________________________
Customer1 - 10000 USD
Customer2 - 20000 USD
Customer3 - 30000 USD
--------------------------------------------------------------------------------------------
RPT:00001 BANK AMOUNTS REPORT Date:22/7/2004
Page: 2
__________________________________________________________________
Bank Code: DEF
Bank Name: DEF Bank
__________________________________________________________________
Customer5 - 50000 USD
Customer1 - 500 USD
--------------------------------------------------------------------------------------------
RPT:00001 BANK AMOUNTS REPORT Date:22/7/2004
Page: 3
__________________________________________________________________
Bank Code:
Bank Name:
__________________________________________________________________
Summary for report
Customer 1 : 10500 USD
Customer 2 : 20000 USD
Customer 3 : 30000 USD
Customer 5 : 50000 USD
Total : 110500 USD
__________________________________________________________________
Expected output:
Quote:
RPT:00001 BANK AMOUNTS REPORT Date:22/7/2004
Page: 3
__________________________________________________________________
Bank Code:
Bank Name:
__________________________________________________________________
Summary for report
Customer 1 : 10500 USD
Customer 2 : 20000 USD
Customer 3 : 30000 USD
Customer 5 : 50000 USD
Total : 110500 USD
__________________________________________________________________
The solid lines '__' are present in the report and '----' indicates page breaks.
The reason why I thought of the logic to subtract 5 lines was, I want to copy the header record for that portion of the report too along with the summary details into the new file. Makes sense?
- Vallish _________________ If you're not failing every now and again, it's a sign you're not doing anything very innovative.
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
Posted: Thu Jul 22, 2004 11:10 am Post subject:
Valish,
The following JCL will give you the desired results. If you want the header record for the summary page, you actually need to subtract 6 from the record no: of "summary report"
A brief description of the job. The first copy operator takes in the input report file and adds a seqnum to all the records. This is the record no: of each record. Now using include on outfil we select the "summary report" record and create dynamic control cards.
The next copy step uses this dynamically created control card and copies the desired records to the output file.
Code:
//STEP0100 EXEC PGM=SYNCTOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD *
RPT:00001 BANK AMOUNTS REPORT DATE:22/7/2004
PAGE: 1
______________________________________________
BANK CODE: ABC
BANK NAME: ABC BANK
______________________________________________
CUSTOMER1 - 10000 USD
CUSTOMER2 - 20000 USD
CUSTOMER3 - 30000 USD
----------------------------------------------
RPT:00001 BANK AMOUNTS REPORT DATE:22/7/2004
PAGE: 2
______________________________________________
BANK CODE: DEF
BANK NAME: DEF BANK
______________________________________________
CUSTOMER5 - 50000 USD
CUSTOMER1 - 500 USD
----------------------------------------------
RPT:00001 BANK AMOUNTS REPORT DATE:22/7/2004
PAGE: 3
______________________________________________
BANK CODE:
BANK NAME:
______________________________________________
SUMMARY FOR REPORT
CUSTOMER 1 : 10500 USD
CUSTOMER 2 : 20000 USD
CUSTOMER 3 : 30000 USD
CUSTOMER 5 : 50000 USD
TOTAL : 110500 USD
______________________________________________
//TOOLIN DD *
COPY FROM(IN) USING(CTL1)
COPY FROM(IN) USING(CTL2)
//OUT DD SYSOUT=*
//CTL1CNTL DD *
OUTREC FIELDS=(1,132,SEQNUM,8,ZD)
OUTFIL FNAMES=CTL2CNTL,
INCLUDE=(1,18,CH,EQ,C'SUMMARY FOR REPORT'),
OUTREC=(C' OUTFIL FNAMES=OUT,STARTREC=',
+6,SUB,133,8,ZD,EDIT=(TTTTTTTT),80:X)
//CTL2CNTL DD DSN=&C1,DISP=(,PASS),SPACE=(TRK,(1,1),RLSE)
/*
Joined: 17 Dec 2002 Posts: 53 Topics: 14 Location: BengaLuru
Posted: Thu Jul 22, 2004 12:34 pm Post subject:
Sorry! I found the mistake with the INCLUDE statement. I corrected that.
Now I get an error with OUTFIL statement,
Quote:
CTL1CNTL :
OUTREC FIELDS=(1,132,SEQNUM,8,ZD)
OUTFIL FNAMES=CTL2CNTL,
INCLUDE COND=(1,18,C'SUMMARY FOR REPORT'),
*
OUTREC=(C' OUTFIL FNAMES=OUT,STARTREC=',+6,SUB,133,8,ZD,
*
EDIT=(TTTTTTTT),80:X)
*
WER428I CALLER-PROVIDED IDENTIFIER IS "0001"
WER268A OUTFIL STATEMENT : SYNTAX ERROR
WER269A OUTREC STATEMENT : DUPLICATE STATEMENT FOUND
WER275A NO KEYWORDS FOUND ON CONTROL STATEMENT
WER211B SYNCSMF CALLED BY SYNCSORT; RC=0000
WER449I SYNCSORT GLOBAL DSM SUBSYSTEM ACTIVE
Can I not edit my post? I wanted to delete the earlier reply. _________________ If you're not failing every now and again, it's a sign you're not doing anything very innovative.
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
Posted: Thu Jul 22, 2004 1:42 pm Post subject:
vallishar,
In your previous post you mentioned that your input file is FB and is 132 bytes in length.
Now you are saying that it is FBA and the LRECL is 133. If that is the case then the string "summary report" actually starts from pos 2. so change your include condition to
Joined: 17 Dec 2002 Posts: 53 Topics: 14 Location: BengaLuru
Posted: Thu Jul 22, 2004 1:51 pm Post subject:
Also, In the output can I replace the PAGE:3 to page:1 by overriding it? _________________ If you're not failing every now and again, it's a sign you're not doing anything very innovative.
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
Posted: Thu Jul 22, 2004 2:03 pm Post subject:
vallish,
Quote:
I am still not very clear about the second OUTREC. Can you please explain?
Sure can.We are creating a dynamic control card CTL2CNTL. let us say we have a file of 100 records and we want to copy from 50 record onwards. For achieving this we Usually code(one of the n number of ways)
Code:
OUTFIL STARTREC=50
I am doing the same over here also. I am just writting to a DD name OUT. once we found the record no(with include cond), we are subtracting 6 from the record no.
80:X is used to pad spaces to the 80th byte after writting the other outrec fields.
So basically the output will look like this
Code:
OUTFIL FNAMES=OUT,STARTREC=00000020
C' OUTFIL FNAMES=OUT,STARTREC=', means write a text of OUTFIL FNAMES=OUT,STARTREC
+6,SUB,133,8,ZD means subtract 6 from the value at 133 which is of 8 bytes long and
EDIT=(TTTTTTTT) means print out the result after the arthimetic operation is complete
80:X) means pad spaces to the 80th byte.
Quote:
If I have to use DFSORT instead of SYNCSORT what changes should i do?
Joined: 26 Nov 2002 Posts: 12375 Topics: 75 Location: San Jose
Posted: Thu Jul 22, 2004 2:22 pm Post subject:
Vallish,
Quote:
Also, In the output can I replace the PAGE:3 to page:1 by overriding it?
Sure can. we use CHANGE parm to change the page number. if the position 2 has the value of PAGE we change the value in the bytes 7 thru 4. I assumed the page number can go upto a max of 9999 pages. Change your control cards to the following.
Why should it be 80 bytes in the control card, though we are having the record length as 133?
The SYSIN data set(control cards) usually resides in the input stream; however, it can be defined as a sequential data set or as a member of a partitioned data set.
The data set must be defined with a RECFM of F or FB. The LRECL can be 80, or more (when valid). If the LRECL is greater than 80, DFSORT will use the first 80 bytes of each record.
check this link which explains in detail about the control cards(sysin) dataset
I changed it to,
OUTREC FIELDS=(1,114,115,5,CHANGE=(13,C'PAGE:',C'PAGE: 1'),
NOMATCH=(115,13),128,4)
since the position of the page was at 115.
What difference will it make if we use or don't use the FIELDS parameter? _________________ If you're not failing every now and again, it's a sign you're not doing anything very innovative.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum