View previous topic :: View next topic
|
Author |
Message |
revdpoel
New User
Joined: 01 Nov 2006 Posts: 56
|
|
|
|
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 |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
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 |
|
|
revdpoel
New User
Joined: 01 Nov 2006 Posts: 56
|
|
|
|
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 |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
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 |
|
|
revdpoel
New User
Joined: 01 Nov 2006 Posts: 56
|
|
|
|
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 |
|
|
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
Back to top |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
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 |
|
|
revdpoel
New User
Joined: 01 Nov 2006 Posts: 56
|
|
|
|
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 |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
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 |
|
|
revdpoel
New User
Joined: 01 Nov 2006 Posts: 56
|
|
|
|
Frank, please read the attachment |
|
Back to top |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
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 |
|
|
revdpoel
New User
Joined: 01 Nov 2006 Posts: 56
|
|
|
|
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 |
|
|
Frank Yaeger
DFSORT Developer
Joined: 15 Feb 2005 Posts: 7129 Location: San Jose, CA
|
|
|
|
Quote: |
probably the EDIT mask has to be EDIT=(STTTTTTTTTTTTTTTTTT) ? |
Yes. |
|
Back to top |
|
|
revdpoel
New User
Joined: 01 Nov 2006 Posts: 56
|
|
|
|
Frank it works
thnx |
|
Back to top |
|
|
|