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

sorting with separate sign


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

New User


Joined: 01 Nov 2006
Posts: 56

PostPosted: Thu Sep 03, 2009 6:17 pm
Reply with quote

Hai

this is my dataset

AB+25
SA-30
AB-20
SA+55
AB-10

The first two positions are a code. The next three positions are a Cobol numeric field, where the sign is leading as a separate character

The outcome has to be

AB-05
SA+25

AB-05 because +25 + -20 + -10 = -05
SA+25 because -30 + +55 = +25

How do I do this?
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: Thu Sep 03, 2009 10:03 pm
Reply with quote

You can use a DFSORT job like the following to do what you asked for:

Code:

//S1    EXEC  PGM=SORT
//SYSOUT    DD  SYSOUT=*
//SORTIN DD *
AB+25
SA-30
AB-20
SA+55
AB-10
/*
//SORTOUT DD SYSOUT=*
//SYSIN    DD    *
  SORT FIELDS=(1,2,CH,A)
  OUTFIL REMOVECC,NODETAIL,
    SECTIONS=(1,2,
      TRAILER3=(1,2,TOT=(3,3,FS,EDIT=(STT),SIGNS=(+,-))))
/*
Back to top
View user's profile Send private message
revdpoel

New User


Joined: 01 Nov 2006
Posts: 56

PostPosted: Thu Sep 03, 2009 10:55 pm
Reply with quote

Thank you Frank
I've been looking iin the manual, but don't understand it all

What do the SECTIONS and TRAILER keyword do?
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: Thu Sep 03, 2009 11:16 pm
Reply with quote

SECTIONS says to treat each change in value for positions 1-3 as a group of records and TRAILER3 creates a trailer record for each such group.
Since NODETAIL is specified, only the trailer3 records will be written, not the data records.

So the AB records would be a group and their trailer record would be written, and the SA records would be another group and their trailer record would be written. 1,2 in TRAILER3 puts positions 1-2 from the last record of the group in the trailer record. TOT puts the total for the group in the trailer record.
Back to top
View user's profile Send private message
revdpoel

New User


Joined: 01 Nov 2006
Posts: 56

PostPosted: Thu Sep 03, 2009 11:36 pm
Reply with quote

ok Frank
if 1,2 in TRAILER3 puts positions 1-2 from the last record of the group in the trailer record, what does "SECTIONS=(1,2," do then? Especially what does the 1,2, in SECTIONS do?
Back to top
View user's profile Send private message
Skolusu

Senior Member


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

PostPosted: Fri Sep 04, 2009 12:06 am
Reply with quote

revdpoel,

Check this for a detailed explanation of "Creating Reports with OUTFIL"

publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/ICE1CG30/2.6.8?

If you're not familiar with DFSORT and DFSORT's ICETOOL, I'd suggest reading through "z/OS DFSORT: Getting Started". It's an excellent tutorial, with lots of examples, that will show you how to use DFSORT, DFSORT's ICETOOL and DFSORT Symbols. You can access it online, along with all of the other DFSORT books, from:

Use [URL] BBCode for External Links
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: Fri Sep 04, 2009 12:41 am
Reply with quote

SECTIONS=(1,2 identifies the value that defines a section. The first "section" is the AB records and the second "section" is the SA records. When the value in positions 1-2 changes from AB to SA, we start a new section.
Back to top
View user's profile Send private message
revdpoel

New User


Joined: 01 Nov 2006
Posts: 56

PostPosted: Fri Sep 04, 2009 1:35 am
Reply with quote

Frank, i wanted to give the example in an easier way for myself to understand it more clearly

But the real dataset is FB 50, with a header (first position 1), data (first position 2) and trailer (first position 3)

120090903
2AB+25
2SA-30
2AB-20
2SA+55
2AB-10
30007

The outcome has to be

120090903
2AB-05
2SA+25
30004

This means that the number of records in the trailer has to change after the sort from 7 to 4
Does this make things more difficult or DFSort?
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: Fri Sep 04, 2009 1:58 am
Reply with quote

I'd take a different approach for that and use these DFSORT control statements:

Code:

  OMIT COND=(1,1,CH,EQ,C'3')                         
  INREC OVERLAY=(51:4,3,FS,TO=ZD,LENGTH=2)           
  SORT FIELDS=(1,3,CH,A)                             
  SUM FIELDS=(51,2,ZD)                               
  OUTREC IFTHEN=(WHEN=(1,1,CH,EQ,C'2'),             
    OVERLAY=(4:51,2,ZD,EDIT=(STT),SIGNS=(+,-)))     
  OUTFIL REMOVECC,BUILD=(1,50),                     
    TRAILER1=('3',COUNT+1=(M11,LENGTH=4))           
Back to top
View user's profile Send private message
revdpoel

New User


Joined: 01 Nov 2006
Posts: 56

PostPosted: Fri Sep 04, 2009 4:47 pm
Reply with quote

Frank, please read the attachment
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: Sat Sep 05, 2009 6:18 am
Reply with quote

Huh? Your control statements seem to be set up to sum these two fields:

0000034+000000000004908460
0000034-000000000003908455

But you say you want your output to be:

0000068+000000000004908460

That would only be a sum of the first field, not the second one. So I don't really understand what you want or what you're doing.

The + and - field was originally 3 bytes. Now it's 19 bytes, so you convert it to an 18-byte ZD value, but then you use an EDIT mask of EDIT=(STT) which is only three bytes, not 19 bytes so you're truncating the result.

Since I don't understand your new requirement, I can't really help you fix your control statements.
Back to top
View user's profile Send private message
revdpoel

New User


Joined: 01 Nov 2006
Posts: 56

PostPosted: Sat Sep 05, 2009 3:10 pm
Reply with quote

sorry Frank
I turned things around

'Output expected' and 'output we get' should be turned around

Output we get
020090731200907FJQ00001
11167000300030EUR69KS010011D0000000000010000000000000000001999990000068+000000000004908460
90000000003

Output expected
020090731200907FJQ00001
11167000300030EUR69KS010011D0000000000010000000000000000001999990000068+000000000001000005
90000000003

probably the EDIT mask has to be EDIT=(STTTTTTTTTTTTTTTTTT) ?
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: Sun Sep 06, 2009 10:49 pm
Reply with quote

Quote:
probably the EDIT mask has to be EDIT=(STTTTTTTTTTTTTTTTTT) ?


Yes.
Back to top
View user's profile Send private message
revdpoel

New User


Joined: 01 Nov 2006
Posts: 56

PostPosted: Mon Sep 07, 2009 1:56 pm
Reply with quote

Frank it works
thnx
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
This topic is locked: you cannot edit posts or make replies. Automation need help in sorting the data DFSORT/ICETOOL 38
No new posts Sorting a record spanned over multipl... DFSORT/ICETOOL 13
No new posts Creating additional seqnum/Literal wh... DFSORT/ICETOOL 4
No new posts SEPARATE UNIQUE and NON-UNIQUE in SEP... SYNCSORT 6
This topic is locked: you cannot edit posts or make replies. Missing Negative sign in COBOL COBOL Programming 6
Search our Forums:

Back to Top