MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Insert new record in a detail record based on a condition

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities
View previous topic :: View next topic  
Author Message
shuko
Beginner


Joined: 08 Nov 2005
Posts: 73
Topics: 20

PostPosted: Wed May 28, 2008 3:49 am    Post subject: Insert new record in a detail record based on a condition Reply with quote

I have a file with header and detail records. The header records always starts with 1 in postion 1 and detail records with 2 in position 2.
The file is FB with LRECL=68.

Example of a file with header and trailer records.

Input file
Code:



----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+-

start pos 1                      start pos 34                    start pos 66
 
1HEADER1                         xxxxxxxxxxxxxxxxxxx             
2AAAAA                           bbbbbb                          s
2WS-TITLE                        ABC CLEANUP IBNR - ACYEAR=2001  S                     
2BBBBB                           20030401                        S
2........                        ....                            .
1HEADER2                         xxxxxxxxxxxxxxxxxxx             
2AAAAA                           bbbbbb                          S
2WS-TITLE                        ABC CLEANUP IBNR - ACYEAR=2001  S 
2BBBBB                           20030401                        S
2GGGGGGG                         0                               S
2........                        ....                            .

and so on.



I want to check for all detail records with 2WS-TITLE, get the value which is in position 53-64, which is ACYEAR=2001 in the first case and insert a new details record 2ACYEAR start position 1,2001 in position 34 and S in position 66 just after detail record 2WS-TITLE. This should be done every time a detail record with 2WS-TITLE is found.


Expected output file


Code:

----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+-

start pos 1                      start pos 34                    start pos 66
 
1HEADER1                         xxxxxxxxxxxxxxxxxxx             
2AAAAA                           bbbbbb                          s
2WS-TITLE                        ABC CLEANUP IBNR - ACYEAR=2001  S 
2ACYEAR                          2001                            S 
2BBBBB                           20030401                        S
2........                        ....                            .
1HEADER2                         xxxxxxxxxxxxxxxxxxx             
2AAAAA                           bbbbbb                           S
2WS-TITLE                        ABC CLEANUP IBNR - ACYEAR=2003  S 
2ACYEAR                          2003                            S 
2BBBBB                           20030401                        S
2GGGGGGG                         0                               S
2........                        ....                            .



Thank you
Shuko
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Wed May 28, 2008 9:55 am    Post subject: Reply with quote

shuko,

The following DFSORT JCL will give you the desired results

Code:

//STEP0100 EXEC PGM=SORT                                           
//SYSOUT   DD SYSOUT=*                                             
//SORTIN   DD *                                                   
1HEADER1                         XXXXXXXXXXXXXXXXXXX               
 2AAAAA                           BBBBBB                         S
----+----1----+----2----+----3----+----4----+----5----+----6----+--
 2WS-TITLE                        ABC CLEANUP IBNR - ACYEAR=2001 S
 2BBBBB                           20030401                       S
 2........                        ....                           .
1HEADER2                         XXXXXXXXXXXXXXXXXXX               
 2AAAAA                           BBBBBB                         S
 2WS-TITLE                        ABC CLEANUP IBNR - ACYEAR=2001 S
 2BBBBB                           20030401                       S
 2GGGGGGG                         0                              S
 2........                        ....                           .
//SORTOUT  DD SYSOUT=*                                             
//SYSIN    DD *                                                   
  OPTION COPY                                                     
  OUTFIL IFOUTLEN=80,                                             
  IFTHEN=(WHEN=(2,9,CH,EQ,C'2WS-TITLE'),                           
  BUILD=(01,80,/,2:C'2',54,6,34:61,4,66:C'S',80:X)),               
  IFTHEN=(WHEN=NONE,BUILD=(01,80))                                 
//*                                                               


Hope this helps...

Cheers
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
shuko
Beginner


Joined: 08 Nov 2005
Posts: 73
Topics: 20

PostPosted: Mon Jun 02, 2008 1:47 am    Post subject: Reply with quote

Thank you kolusu. I just had to make a few changes and the code worked as expected.

Code:

  IFTHEN=(WHEN=(2,9,CH,EQ,C'WS-TITLE'),             
     BUILD=(01,80,/,1:C'2',53,6,34:60,4,66:C'S',80:X)),
  IFTHEN=(WHEN=NONE,BUILD=(01,80))       


Shuko
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Mon Jun 02, 2008 10:24 am    Post subject: Reply with quote

shuko,

I realized that you actually don't need the WHEN=NONE statement , you can actually do get the desired results with the following control cards

Code:

//SYSIN    DD *                                 
  OPTION COPY                                   
  OUTFIL IFTHEN=(WHEN=(2,9,CH,EQ,C'2WS-TITLE'),
  BUILD=(01,80,/,2:C'2',53,6,34:60,4,66:C'S')) 
//*                                             


Hope this helps...

Cheers
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
shuko
Beginner


Joined: 08 Nov 2005
Posts: 73
Topics: 20

PostPosted: Mon Jun 02, 2008 12:50 pm    Post subject: Reply with quote

Thank you Kolusu.

Shuko
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group