Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Propagating value from nth record to the group

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
View previous topic :: :: View next topic  
Author Message
ganasrinivasan

New User


Joined: 06 Nov 2006
Posts: 27
Location: Montreal

PostPosted: Fri Nov 30, 2018 8:31 am    Post subject: Propagating value from nth record to the group
Reply with quote

Hi,

Could someone please suggest on how to achieve below o/p? '+' denotes start of group.

I/p:
Code:
REC1 +
REC2 $
REC3 1234
REC4 abc
REC5 +
REC6 $
REC7 5678
REC8 abc
REC9 def

Expected o/p: (Need the data from 3rd record to the entire group)
Code:
REC1 +    1234
REC2 $    1234
REC3 1234 1234
REC4 abc  1234
REC5 +    5678
REC6 $    5678
REC7 5678 5678
REC8 abc  5678
REC9 def  5678


EDITED to add code tags, and also fixed a typo in the sample data. The propagated key for the second group was also '1234'. Corrected to '5678'. Use code tags and pay attention to the details before posting.
Back to top
View user's profile Send private message

expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8744
Location: Welsh Wales

PostPosted: Fri Nov 30, 2018 12:32 pm    Post subject:
Reply with quote

And if there are not three records in a group ?

And just some of the basics if you don't mind helping those that help you ....

Sort version / release level
dataset RECFM
dataset LRECL
Key positions and lengths
Data formats of the keys

It is best to give ALL of the information at the start of a topic rather than coming back later stating it don't work with packed decimal.
Back to top
View user's profile Send private message
sergeyken

Active User


Joined: 29 Apr 2008
Posts: 388
Location: Maryland

PostPosted: Fri Nov 30, 2018 9:19 pm    Post subject:
Reply with quote

The info requested by expat is needed at the latest stage of this project's implementation. Before actual coding one needs to understand the overall logic, or algorithm, required to get the given result. At this primary stage none of the mentioned details are used. At this moment it even doesn't matter what tool exactly is used (DFSORT, or another one), to say nothing about its version.

So, the order must be as follows:
1) design an algorithm
2) choose the more convenient/available tool for implementation of this task
3) prepare the actual code keeping in mind the specifics of particular tool finally chosen
4) test and debug the code using specific limited test data, instead of real production data
5) finally run the fixed code with actual production data.

For stage #1 I suggest the following logic. Since no value from the third line of any group can be propagated under any circumstances into preceeding records of the same dataset, then it is obvious for myself that two steps of processing are necessary.

Step 1: run SORT utility to process the original file and add sequential group number, and record number within this group to each record
Code:
0001 001 REC1 +
0001 002 REC2 $
0001 003 REC3 1234
0001 004 REC4 abc
0002 001 REC5 +
0002 002 REC6 $
0002 003 REC7 1234
0002 004 REC8 abc
0002 005 REC9 def


Step2: run SORT utility to perform JOIN of two input DD statements on the same dataset from Step 1.
//MASTER DD - full data from Step 1
//DETAILS DD - data from Step 1 restricted by record number 003

JOINKEYS F1=MASTER,FIELDS=(...)

JOINKEYS F2=DETAILS,FIELDS=(1,4,A,6,3,A),INCLUDE=(6,3,ZD,EQ,+3)
Can be simplified to FIELDS=(1,8,A)

Then use REFORMAT to include only required fields into joined records.

Specific syntax of the code may need adjustments depending on actually used utility/version, but the idea remains the same.
Back to top
View user's profile Send private message
sergeyken

Active User


Joined: 29 Apr 2008
Posts: 388
Location: Maryland

PostPosted: Fri Nov 30, 2018 10:18 pm    Post subject:
Reply with quote

Sorry, found my own typo.
Must be like this

sergeyken wrote:

JOINKEYS F2=DETAILS,FIELDS=(1,4,A),INCLUDE=(6,3,ZD,EQ,+3)
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2448
Location: @my desk

PostPosted: Fri Nov 30, 2018 10:29 pm    Post subject:
Reply with quote

ganasrinivasan,

Here is an example that does not need multiple steps or a JOIN operation. The idea is to save record-1 and record-2 in each group starting with a '+' onto the record-3, then recreate it in the OUTFIL.

The below example assumes input and output to be of FB/LRECL=80 and that you always have 3 records in a group, you could modify it as per your actual definitions.

Like expat has mentioned above, it would always help if you post all the requested information in the very first post, especially the things that only you know. If something does not work for you, please include ALL the relevant information in your next post. Good luck.
Code:
//STEP01 EXEC PGM=SORT           
//SORTIN   DD *                 
REC1 +                           
REC2 $                           
REC3 1234                       
REC4 abc                         
REC5 +                           
REC6 $                           
REC7 5678                       
REC8 abc                         
REC9 def                         
//SYSOUT   DD SYSOUT=*           
//SORTOUT  DD SYSOUT=*           
//SYSIN    DD *                                                     
  OPTION COPY                                                       
  OUTREC IFTHEN=(WHEN=GROUP,BEGIN=(6,1,CH,EQ,C'+'),                 
           PUSH=(081:ID=8,SEQ=4)),                                   
         IFTHEN=(WHEN=GROUP,BEGIN=(89,4,ZD,EQ,1),END=(89,4,ZD,EQ,3),
           PUSH=(093:1,80)),                                         
         IFTHEN=(WHEN=GROUP,BEGIN=(89,4,ZD,EQ,2),END=(89,4,ZD,EQ,3),
           PUSH=(173:1,80)),                                         
         IFTHEN=(WHEN=GROUP,BEGIN=(89,4,ZD,EQ,3),                   
           PUSH=(011:6,4))                                           
  OUTFIL IFOUTLEN=80,OMIT=(089,4,ZD,LT,3),                           
         IFTHEN=(WHEN=(089,4,ZD,EQ,3),                               
          BUILD=(093,10,6,4,80:X,/,                                 
                 173,10,6,4,/,                                       
                 001,80)) 
SORTOUT had
Code:
REC1 +    1234
REC2 $    1234
REC3 1234 1234
REC4 abc  1234
REC5 +    5678
REC6 $    5678
REC7 5678 5678
REC8 abc  5678
REC9 def  5678
Back to top
View user's profile Send private message
sergeyken

Active User


Joined: 29 Apr 2008
Posts: 388
Location: Maryland

PostPosted: Fri Nov 30, 2018 10:43 pm    Post subject:
Reply with quote

Yes, in specific simple cases this approach will work. But in many cases of real life it will not:
1) RECFM=VB
2) LRECL= huge value
3) required record number is much greater than 3, let's say 300
4) desired record number can vary for different files

Etc.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2448
Location: @my desk

PostPosted: Fri Nov 30, 2018 10:48 pm    Post subject:
Reply with quote

My solution was based on OP's specific mention about record-3. There is no need to waste resources by JOINing data sets in cases where only a single pass solution is sufficient.

If someone has a requirement to propagate the key at nth record (something >>3), still a JOIN with a copy operation would do. Here in the below example, the 3rd record is forced to match the first record of each group.
Code:
//STEP01 EXEC PGM=SORT
//INA      DD *       
REC1 +                 
REC2 $                 
REC3 1234             
REC4 abc               
REC5 +                 
REC6 $                 
REC7 5678             
REC8 abc               
REC9 def               
//INB      DD *             
REC1 +                       
REC2 $                       
REC3 1234                   
REC4 abc                     
REC5 +                       
REC6 $                       
REC7 5678                   
REC8 abc                     
REC9 def                     
//SYSOUT   DD SYSOUT=*       
//SORTOUT  DD SYSOUT=*       
//SYSIN    DD *                                               
 JOINKEYS F1=INA,FIELDS=(81,9,A),SORTED,NOSEQCK               
 JOINKEYS F2=INB,FIELDS=(81,9,A),SORTED,NOSEQCK               
 JOIN UNPAIRED,F1                                             
 REFORMAT FIELDS=(F1:1,93,F2:6,4)                             
 SORT FIELDS=COPY                                             
 OUTREC IFTHEN=(WHEN=GROUP,BEGIN=(90,4,ZD,EQ,1),PUSH=(94:94,4))
 OUTFIL BUILD=(1,11,94,4,80:X)                                 
//JNF1CNTL DD *                                               
 INREC IFTHEN=(WHEN=GROUP,BEGIN=(6,1,CH,EQ,C'+'),             
         PUSH=(81:ID=8,90:SEQ=4)),                             
       IFTHEN=(WHEN=(90,4,ZD,EQ,1),OVERLAY=(89:C'A'))         
//JNF2CNTL DD *                                               
 INREC IFTHEN=(WHEN=GROUP,BEGIN=(6,1,CH,EQ,C'+'),             
         PUSH=(81:ID=8,90:SEQ=4)),                             
       IFTHEN=(WHEN=(90,4,ZD,EQ,3),OVERLAY=(89:C'A'))
SORTOUT had the same results.
Back to top
View user's profile Send private message
ganasrinivasan

New User


Joined: 06 Nov 2006
Posts: 27
Location: Montreal

PostPosted: Sat Dec 01, 2018 1:16 am    Post subject: Reply to: Propagating value from nth record to the group
Reply with quote

Thanks everyone for your ideas! I am able to proceed with the solution.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Problem with OVERLAY - BI on SMF Record Ghellar DFSORT/ICETOOL 4 Sat Dec 01, 2018 9:41 pm
No new posts Previous record x current record jackare SYNCSORT 1 Thu Nov 29, 2018 7:56 am
No new posts Process Last Key of a record based on... naveen katkuri DFSORT/ICETOOL 5 Mon Nov 12, 2018 9:54 am
This topic is locked: you cannot edit posts or make replies. Get value from 2nd record and PUSH it... ashokakash JCL & VSAM 1 Wed Oct 17, 2018 11:41 am
No new posts Merge data from record pairs ashokakash DFSORT/ICETOOL 5 Wed Oct 17, 2018 11:38 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us