IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Control Break using DFSORT


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Mon Nov 16, 2009 5:45 pm
Reply with quote

Hi All,

I am converting an Easytrieve program to cobol and the existing program is having a control statement on 3 fields is there any way to change the control statement in easytrieve Control statement to DFSORT

My requirement is below

Year Product Type Amount

2008 ABC 01 200
2008 ABC 02 200
2008 XYZ 02 200
2008 XYZ 01 200
2008 ABC 01 200
2008 XYZ 02 200
!
!
records for 2009

required output is

Year Product Type Amount
2008 ABC 01 400
2008 ABC 02 200
2008 ABC 600
2008 XYZ 01 200
2008 XYZ 02 400
2008 1200


The input file is a sorted file on Year,Product and Type. If anyone of these changes I need to display the Corresponding totals

I hope the requirement is clear.Please help me out in this I will be very thankful

Regards,
Chandan
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Mon Nov 16, 2009 8:42 pm
Reply with quote

Hello,

Well, i'm confused. . .

If the work being done is converting the Easytrieve code to COBOL, how will sort control statements help?
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Mon Nov 16, 2009 10:10 pm
Reply with quote

Quote:
2008 XYZ 02 400
2008 ABC 01 400
icon_eek.gif Cant see these records in i/p. Or am i missing something in the logic.

Could you please explain in more detail about the requirement.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Mon Nov 16, 2009 10:15 pm
Reply with quote

Hi Vasanth,

Those too are summaries, i believe. . .
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1742
Location: Tirupur, India

PostPosted: Mon Nov 16, 2009 10:55 pm
Reply with quote

Hi D,
You are right, they seem to be like summaries.

The logic maybe,

If year,product & type are same, then add the amount fields and produce one record with year,product,total.
Then finally a subtotal record of Year & product with total.

On MHO, I would write this in COBOL rather than DFSORT, since a lot of logic is involved.

On the other hand after seeing this thread ibmmainframes.com/viewtopic.php?t=45058&postdays=0&postorder=asc&start=15 , it appears anything can be done in DFSORT icon_smile.gif WOW!!
Back to top
View user's profile Send private message
Frank Yaeger

DFSORT Developer


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

PostPosted: Tue Nov 17, 2009 12:08 am
Reply with quote

Chandan,

You need to do a better job of explaining the "rules" for getting from input to output. What rule tells us to create these two output records:

2008 ABC 600

2008 1200

Perhaps an example with more input and output records covering all possible cases would help.

Also, give the RECFM and LRECL of the input file, and the starting position, length and format of each relevant field.
Back to top
View user's profile Send private message
Skolusu

Senior Member


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

PostPosted: Tue Nov 17, 2009 12:19 am
Reply with quote

chandan.ist,

The following DFSORT/ICETOOL JCL will give you the desired results, assuming that you want 3 columns.

Break 1 on Year,Product and Type
Break 2 on Year and Product
Break 3 on Year

Code:

//STEP0100 EXEC PGM=ICETOOL                                       
//TOOLMSG  DD SYSOUT=*                                             
//DFSMSG   DD SYSOUT=*                                             
//IN       DD *                                                   
2008 ABC 01 200                                                   
2008 ABC 02 200                                                   
2008 XYZ 02 200                                                   
2008 XYZ 01 200                                                   
2008 ABC 01 200                                                   
2008 XYZ 02 200                                                   
//T1       DD DSN=&&T1,DISP=(,PASS),SPACE=(CYL,(1,1),RLSE)         
//OUT      DD SYSOUT=*                                             
//TOOLIN   DD *                                                   
  SORT FROM(IN) USING(CTL1)                                       
  COPY FROM(T1) USING(CTL2)                                       
//CTL1CNTL DD *                                                   
  INREC OVERLAY=(81:5C'0',13,3)                                   
  SORT FIELDS=(1,11,CH,A),EQUALS                                   
  SUM FIELDS=(81,8,ZD)                                             
  OUTFIL FNAMES=T1,REMOVECC,BUILD=(1,12,81,8,ZD,M10,LENGTH=8,8X), 
  SECTIONS=(1,9,TRAILER3=(1,9,21:TOT=(81,8,ZD,M10,LENGTH=8)))     
//CTL2CNTL DD *                                                   
  OUTFIL FNAMES=OUT,REMOVECC,IFOUTLEN=20,                         
  IFTHEN=(WHEN=(21,8,CH,EQ,C' '),BUILD=(1,20)),                   
  IFTHEN=(WHEN=(21,8,CH,GT,C' '),BUILD=(1,12,21,8)),               
  SECTIONS=(1,4,TRAILER3=(1,5,11:TOT=(13,8,UFF,M10,LENGTH=10)))   
//*


The output of this job is

Code:
                                                               
2008 ABC 01      400
2008 ABC 02      200
2008 ABC         600
2008 XYZ 01      200
2008 XYZ 02      400
2008 XYZ         600
2008            1200
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Tue Nov 17, 2009 9:15 am
Reply with quote

Thanks for the replies guys..

Answers to few questions in the posts:
1. Eazytrive gives the desired output in one run. But when trying to
convert to cobol cobol gives the file which I mentioned as Input. So get
desired output I was thinking of DFSORT instead of writing a complex
logic as that Input file having 3-4 field to sum.
2. The requirement is exactly same which Vasanth has mentioned

I will check it out the solution given above and I will be very thankful if anyone explain how this sort card work

Regards,
Chandan
Back to top
View user's profile Send private message
Skolusu

Senior Member


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

PostPosted: Wed Nov 18, 2009 12:33 am
Reply with quote

chandan.inst,

Since you wanted 3 different breaks , we achieve that in 2 passes of data.

The first SORT operation will handle 2 breaks

Break 1 on Year,Product and Type is achieved by SUM Fileds sorting on all the 3 columns. You only showed 3 bytes for amount, so in order to account for overflow after summation we padded amount with 5 leading zeros and sum it as 8 byte field instead of 3 byte field

Break 2 is achieved using SECTIONS on OUTFIL which will total the amount value based on the Year and Product.

The second COPY operation will handle the final break on (Year) . This is done using SECTIONS and we total the Summed values and write out the output

Btw just so you know the logic isn't that complex as you think , It is quite simple and can be done in cobol very easily
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Wed Nov 18, 2009 12:56 am
Reply with quote

Hello,

A bit late to the party and apologies if i'm barging in. . .

Quote:
So get desired output I was thinking of DFSORT instead of writing a complex logic as that Input file having 3-4 field to sum.
There should be no complexity. . .

As Kolusu mentioned:
Quote:
It is quite simple and can be done in cobol very easily


To elaborate just a little, the first thing is to get the data into the proper sequence - if the volume is not huge, i'd use the cobol internal sort specifying USING & OUTPUT PROCEDURE. In the output procedure, return the records and if the control info is the same as previous, accumulate the amount. If the control info changes, print the accumulated total, add the total to the next higher level accumulator, and zero out that level. When all of the records have been returned from the sort, process the last set of totals including the final total.

If you have doubts about how to do this, it would be a good learning exercise. I believe the code will be far less complex and more easily understood by others (which will be important if the requirement grows later).
Back to top
View user's profile Send private message
chandan.inst

Active User


Joined: 03 Nov 2005
Posts: 275
Location: Mumbai

PostPosted: Wed Nov 18, 2009 1:33 pm
Reply with quote

Hi Dick,

Thanks for the reply..

After reading your reply I am agree that there will be no complexity as I didnt thougt about about Cobol internal Sort and tried to do it with Cobol Read storing current data and comparing with previous data..

Surely I will check this with interal Sort

Thanks a ton guys..

Regards,
Chandan
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Modifying Date Format Using DFSORT DFSORT/ICETOOL 9
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Using Dynamic file handler in the Fil... COBOL Programming 2
No new posts DFsort help with SUM() DFSORT/ICETOOL 12
Search our Forums:

Back to Top