|
View previous topic :: View next topic
|
| Author |
Message |
zh_lad
Active User
Joined: 06 Jun 2009 Posts: 115 Location: UK
|
|
|
|
Hi,
I like to display difference between current and previous value in column:
Input file - FB, LRECL 6
| Code: |
Column 1 (P1, L6)
000001
000009
000020
000035
000100
000135
000250
......
......
......
990901
990914 |
| Code: |
output should be:
Col 1 Column 2 (P10, L6)
000001
000009 8
000020 11
000035 15
000100 65
000135 35
000240 105
......
......
......
990901 ...
990914 13 |
I have not tried anything so far. Please give me few hints and I will try.
Thanks.
Code'd |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Two ways: JOINKEYS with the same dataset for both files. In JNF1CNTL add a sequence number, starting from zero, in the JNF2CNTL a sequence number starting from one. The sequence numbers are the key. You need JOIN UNMATCHED,F1. The only unmatched you get is the first record. For all the matches, you have your current record (F1) and the previous record (F2). Use the REFORMAT to get the values you need. In the main task do the subtraction and formatting that you need.
The other way is with WHEN=GROUP, have a look here. |
|
| Back to top |
|
 |
zh_lad
Active User
Joined: 06 Jun 2009 Posts: 115 Location: UK
|
|
|
|
Thanks to moderator who code'd it. I noticed errors in post but it was locked by mods.
Thanks Bill for your hints. It worked. I have used below jcl to get the difference.
| Code: |
//S1 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN1 DD DISP=SHR,DSN=MY INPUT FILE
//T1 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,2)),DISP=(,PASS)
//T2 DD DSN=&&T1,UNIT=SYSDA,SPACE=(CYL,(5,2)),DISP=(,PASS)
//MYOUT DD DSN=TTMA.VERMRWP.SWRDCKEY.GAPS,
// DISP=(,CATLG),SPACE=(CYL,(5,2))
//TOOLIN DD *
COPY FROM(IN1) USING(CTL1)
COPY JKFROM USING(CTL2)
/*
//CTL1CNTL DD *
OUTFIL FNAMES=T1,BUILD=(1,6,X,SEQNUM,6,ZD,START=0)
OUTFIL FNAMES=T2,BUILD=(1,6,X,SEQNUM,6,ZD,START=1)
/*
//JNF1CNTL DD *
OPTION COPY
//JNF2CNTL DD *
OPTION COPY
/*
//CTL2CNTL DD *
JOINKEYS F1=T1,FIELDS=(8,6,A)
JOINKEYS F2=T2,FIELDS=(8,6,A)
JOIN UNPAIRED,F1,F2
REFORMAT FIELDS=(?,F1:1,6,F2:1,6)
OPTION COPY
OUTFIL FNAMES=MYOUT,INCLUDE=(1,1,CH,EQ,C'B'),
BUILD=(2,6,X,2,6,ZD,SUB,8,6,ZD)
/* |
When I name DD MYOUT as SORTOF01 and use OUTFIL FILES=01 instead of OUTFIL FNAMES=MYOUT, it gives error 'ICE056A 9 CTL2OF01 NOT DEFINED'. Why is that? |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
You have 10 minutes after posting to make an edit (or delete). After that, editing is blocked (except for Moderators).
You've overcomplicated things slightly by feeling the need to use ICETOOL.
| Code: |
//SORTIN DD *
JOINKEYS F1=T1,FIELDS=(8,6,A),SORTED,NOSEQCK
JOINKEYS F2=T2,FIELDS=(8,6,A)SORTED,NOSEQCK
JOIN UNPAIRED,F1,F2
REFORMAT FIELDS=(?,F1:1,6,F2:1,6)
OPTION COPY
OUTFIL FNAMES=MYOUT,INCLUDE=(1,1,CH,EQ,C'B'),
BUILD=(2,6,X,2,6,ZD,SUB,8,6,ZD)
//JNF1CNTL DD *
OPTION COPY
INREC OVERLAY=(8:SEQNUM,6,ZD,START=0)
//JNF2CNTL DD *
OPTION COPY
INREC OVERLAY=(8:SEQNUM,6,ZD,START=1)
|
If you want to INCLUDE/OMIT in the main task and you have no processing to set conditions for the INCLUDE/OMIT, just use INCLUDE/OMIT COND=.
If you only want Bs anyway, take out the JOIN and you will only get matches.
Specifying no name on the OUTFIL gets you SORTOUT.
Did you look up the message? Did you note the comment underneath the Programmer Response? Why it is like that I don't know, but that is how it is. |
|
| Back to top |
|
 |
zh_lad
Active User
Joined: 06 Jun 2009 Posts: 115 Location: UK
|
|
|
|
Thanks Bill.
Once I had error message saying you can not use OUTREC on JNF1CNTL (CNTL on JOIN), hence I assumed I can not use INREC on JNFnCNTL as well. In future, I will use INREC as and where required to utilize JNFnCNTL's power.
I am aware I should use SORTED on JOINKEYS if records are already sorted. I was just lazy. I will read more about NOSEQCK to write efficient SORT (JOIN).
I think I need to use OVERLAY more and more to write efficient code.
Thanks for all your help. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
If you look at the section on DFSORT Processing, and Figure 2, then the chapter on JOINKEYS and Figure 15, you should be able to see why OUTREC and OUTFIL are not available on the JNFnCNTL files.
There are various restrictions, for similar reasons, on various ICETOOL operators.
OVERLAY is (generally) more efficient, and where it can be used, better expresses what you want to achieve. Since you only specify the locations where you want to OVERLAY, there is less to go wrong, also.
I think if an OVERLAY extends a record, all the data in a record will be moved, so there is not always a "performance" question.
There is always a "current record". OVERLAY operates on the current record (unless the record is extended, when a new current record will be created).
BUILD always creates a new current record.
With BUILD, you can't overwrite a field you've already written. With OVERLAY you can.
Because BUILD creates a new current record, you can do (2,1,1,1), try that with OVERLAY and you'll get an unexpected result.
Experiment. Add one thing at a time and look at the output. "If the data were like that I could do it" so is it possible make the data like that?
There's also a mass of good stuff from Frank Yaeger and Kolusu spread around the place. Find something that looks complicated, and work out how it works. |
|
| Back to top |
|
 |
zh_lad
Active User
Joined: 06 Jun 2009 Posts: 115 Location: UK
|
|
|
|
| Thanks Bill. I will keep these points in mind while working on a new solution. I am glad to know more about OVERLAY. Cheers! |
|
| Back to top |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|