Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

To extract part of a string from a record

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

New User


Joined: 02 Mar 2010
Posts: 8
Location: Bangalore

PostPosted: Mon Dec 06, 2010 3:51 pm    Post subject: To extract part of a string from a record
Reply with quote

Hi,

I have the below requirement to be performed using DFSORT.

Input File
Code:

----+----1----+--
IBMMAINFRAMES0106
IBMMAINFRAMES0508


Based on the value in positions (14,2) and (16,2) I need to cut a part of the string from (1,13)

Required Output File
Code:

----+----1----
IBMMAI
INFRAMES



Can someone tell me if this is possible using DFSORT?
Back to top
View user's profile Send private message

Frank Yaeger

DFSORT Moderator


Joined: 15 Feb 2005
Posts: 7130
Location: San Jose, CA

PostPosted: Tue Dec 07, 2010 12:27 am    Post subject:
Reply with quote

Are you saying that you want to use the value in 14,2 as the starting position and the value in 16,2 as the length?

If so, that would be:

01-06 -> IBMMAI
05-08 -> AINFRAME

so why do you show INFRAMES instead of AINFRAME?

Please do a better job of explaing what you're trying to do. Also, give the RECFM and LRECL of the input file.
Back to top
View user's profile Send private message
neopandya

New User


Joined: 02 Mar 2010
Posts: 8
Location: Bangalore

PostPosted: Tue Dec 07, 2010 12:33 pm    Post subject:
Reply with quote

Yes Frank, my mistake there icon_redface.gif

My expected output should have been as you mentioned -
Code:

----+----1----
IBMMAI
AINFRAME


LRECL = 17 and RECFM = FB (for input)
LRECL = 13 and RECFM = FB (for output)

And yes, the value in 14,2 is to be used as the starting position and the value in 16,2 is to be used as the length.
Back to top
View user's profile Send private message
Guest







PostPosted: Tue Dec 07, 2010 12:44 pm    Post subject:
Reply with quote

Hi Neo,
Please find the jcl for your requirement:
Code:

//STEP0100 EXEC PGM=SORT                                             
//SYSOUT   DD SYSOUT=*                                               
//SORTIN   DD *                                                       
IBMMAINFRAMES0106                                                     
IBMMAINFRAMES0508                                                     
//SORTOUT  DD DSN=CARD.NEXT,DISP=OLD                                 
//SYSIN    DD *                                                       
  OPTION COPY                                                         
  OUTREC OVERLAY=(81:SEQNUM,3,ZD)                                     
  OUTFIL REMOVECC,NODETAIL,BUILD=(80X),                               
  HEADER1('  INREC OVERLAY=(81:SEQNUM,3,ZD)',/,                       
          '  OPTION COPY',/,                                         
          '  OUTREC IFTHEN=(WHEN=(81,3,CH,EQ,C''','AAA''','),',/,     
          '  BUILD(1,80)),'),                                         
  SECTIONS=(81,3,                                                     
  HEADER3=('         IFTHEN=(WHEN=(81,3,ZD,EQ,',81,3,'),',/,         
           '         BUILD=(',14,2,',',16,2,')),'),                   
  TRAILER3=('*')),                                                   
 TRAILER1=('  IFTHEN=(WHEN=(81,3,CH,EQ,C''','AAA''','),BUILD=(1,80))')
/*                                                                   
//*                                                                   
//STEP0200 EXEC PGM=SORT                                             
//SYSOUT   DD SYSOUT=*                                               
//SORTIN   DD *                                                       
IBMMAINFRAMES0106                                                     
IBMMAINFRAMES0508                                                     
//SORTOUT  DD SYSOUT=*                                               
//SYSIN    DD DSN=CARD.NEXT,DISP=SHR


Please let me know if your requirement is met.
Hope better suggestions would flow in icon_smile.gif
Back to top
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10203
Location: italy

PostPosted: Tue Dec 07, 2010 1:27 pm    Post subject: Reply to: To extract part of a string from a record
Reply with quote

nice attempt icon_biggrin.gif
but the sort control statements of the first step
<build> an IFTHEN/BUILD for each and every record of SORTIN
nobody will care/notice if SORTIN contains very/very few records
but if the file is large ... ... !

even if the question looks academic, it is worth meditating anyway on the <best> solution

... <sort> on the <substring> start/length <build> the IFTHEN/BUILD only once for each <substring> start/length
Back to top
View user's profile Send private message
Arun Raj

Moderator


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

PostPosted: Tue Dec 07, 2010 2:02 pm    Post subject:
Reply with quote

devil13,

Here's an attempt to simplify your first sortcard.
Code:
//SYSIN    DD *                                                     
 OPTION COPY                                                         
 INREC OVERLAY=(81:SEQNUM,3,ZD)                                     
 OUTFIL REMOVECC,                                                   
    HEADER1=(' OPTION COPY',/,                                       
             ' INREC IFTHEN=(WHEN=INIT,OVERLAY=(81:SEQNUM,3,ZD)),'),
     BUILD=(C' IFTHEN=(WHEN=(81,3,ZD,EQ,',81,3,C'),',80:X,/,         
            C' BUILD=(',14,2,C',',16,2,C')),'),                     
   TRAILER1=(' IFOUTLEN=13')                                         
But as enrico said already, it might not be the best approach when there are more input records.
Back to top
View user's profile Send private message
Guest







PostPosted: Tue Dec 07, 2010 5:09 pm    Post subject:
Reply with quote

Enrico,
Thanks!! I strongly second your opinion. If the file is small then this can be used else its not the best approach icon_smile.gif

Arun,
Thanks for the new method. I am learning a lot from here icon_smile.gif

Rajesh,
You can use the function Subset of ICETOOL to attain this.

Code:

//S1 EXEC PGM=ICETOOL                             
//TOOLMSG DD SYSOUT=*                             
//DFSMSG DD SYSOUT=*                               
//IN1 DD DSN=INPUT.TEST1,DISP=OLD         
//OUT1 DD DSN=OUTPUT.TEST2,DISP=OLD       
//TOOLIN DD *                                     
SUBSET FROM(IN1) TO(OUT1) INPUT KEEP HEADER TRAILER
/*   
Back to top
Arun Raj

Moderator


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

PostPosted: Tue Dec 07, 2010 5:34 pm    Post subject:
Reply with quote

devil13 wrote:
Rajesh,
You can use the function Subset of ICETOOL to attain this.
How does this relate to the topic!!!
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10203
Location: italy

PostPosted: Tue Dec 07, 2010 5:37 pm    Post subject: Reply to: To extract part of a string from a record
Reply with quote

the answer relates to a unrelated question asked by some lazy poster
appended as happens ( for laziness and carelessness ) to an unrelated issue
http://ibmmainframes.com/viewtopic.php?t=52524&highlight=

I' ll clean up the whole thing in a while
Back to top
View user's profile Send private message
Guest







PostPosted: Tue Dec 07, 2010 5:52 pm    Post subject:
Reply with quote

Yeah Enrico is right icon_biggrin.gif
Back to top
Frank Yaeger

DFSORT Moderator


Joined: 15 Feb 2005
Posts: 7130
Location: San Jose, CA

PostPosted: Tue Dec 07, 2010 10:01 pm    Post subject:
Reply with quote

I would suggest writing an E15 or E35 exit to do this. The exit could easily extract the starting position and length from each record , use them to extract the needed bytes, and pass them back to DFSORT for output. There's really no built-in functions for that kind of thing.
Back to top
View user's profile Send private message
Skolusu

Senior Member


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

PostPosted: Tue Dec 07, 2010 10:33 pm    Post subject: Reply to: To extract part of a string from a record
Reply with quote

neopandya,

As Frank pointed out , an exit is the right way to do it. However your input LRECL is only 13 and hence the result can be achieved using a bunch of IFTHEN statements. The trick here is to pad the starting bytes with spaces to pick the values from middle. for ex if you want to pick the string from pos 5 for 8 bytes you pad out the first 4 bytes with spaces and then use JFY to shift to the left making the 5th byte as 1st byte. To know the number of spaces to be filled , just subtract 1 from the begin position. Once you get that then it is easy to build the output file like shown below.

Code:

//STEP0100 EXEC PGM=SORT                                         
//SYSOUT   DD SYSOUT=*                                           
//SORTIN   DD *                                                 
IBMMAINFRAMES0106                                               
IBMMAINFRAMES0508                                               
//SORTOUT  DD SYSOUT=*                                           
//SYSIN    DD *                                                 
  SORT FIELDS=COPY                                               
  INREC IFTHEN=(WHEN=INIT,OVERLAY=(18:14,2,ZD,SUB,+1,EDIT=(TT))),
  IFTHEN=(WHEN=(18,2,ZD,EQ,01),OVERLAY=(1:01X)),                 
  IFTHEN=(WHEN=(18,2,ZD,EQ,02),OVERLAY=(1:02X)),                 
  IFTHEN=(WHEN=(18,2,ZD,EQ,03),OVERLAY=(1:03X)),                 
  IFTHEN=(WHEN=(18,2,ZD,EQ,04),OVERLAY=(1:04X)),                 
  IFTHEN=(WHEN=(18,2,ZD,EQ,05),OVERLAY=(1:05X)),                 
  IFTHEN=(WHEN=(18,2,ZD,EQ,06),OVERLAY=(1:06X)),                 
  IFTHEN=(WHEN=(18,2,ZD,EQ,07),OVERLAY=(1:07X)),                 
  IFTHEN=(WHEN=(18,2,ZD,EQ,08),OVERLAY=(1:08X)),                 
  IFTHEN=(WHEN=(18,2,ZD,EQ,09),OVERLAY=(1:09X)),                 
  IFTHEN=(WHEN=(18,2,ZD,EQ,10),OVERLAY=(1:10X)),                 
  IFTHEN=(WHEN=(18,2,ZD,EQ,11),OVERLAY=(1:11X)),                 
  IFTHEN=(WHEN=(18,2,ZD,EQ,12),OVERLAY=(1:12X))                 
                                                                 
  OUTREC IFOUTLEN=13,                                           
  IFTHEN=(WHEN=INIT,OVERLAY=(1:1,13,JFY=(SHIFT=LEFT))),         
  IFTHEN=(WHEN=(16,2,ZD,EQ,01),BUILD=(1,01)),                   
  IFTHEN=(WHEN=(16,2,ZD,EQ,02),BUILD=(1,02)),                   
  IFTHEN=(WHEN=(16,2,ZD,EQ,03),BUILD=(1,03)),                   
  IFTHEN=(WHEN=(16,2,ZD,EQ,04),BUILD=(1,04)),                   
  IFTHEN=(WHEN=(16,2,ZD,EQ,05),BUILD=(1,05)),                   
  IFTHEN=(WHEN=(16,2,ZD,EQ,06),BUILD=(1,06)),                   
  IFTHEN=(WHEN=(16,2,ZD,EQ,07),BUILD=(1,07)),                   
  IFTHEN=(WHEN=(16,2,ZD,EQ,08),BUILD=(1,08)),                   
  IFTHEN=(WHEN=(16,2,ZD,EQ,09),BUILD=(1,09)),                   
  IFTHEN=(WHEN=(16,2,ZD,EQ,10),BUILD=(1,10)),                   
  IFTHEN=(WHEN=(16,2,ZD,EQ,11),BUILD=(1,11)),                   
  IFTHEN=(WHEN=(16,2,ZD,EQ,12),BUILD=(1,12)),                   
  IFTHEN=(WHEN=(16,2,ZD,EQ,13),BUILD=(1,13))                     
//* 
Back to top
View user's profile Send private message
Arun Raj

Moderator


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

PostPosted: Wed Dec 08, 2010 10:54 am    Post subject:
Reply with quote

Good one Kolusu.
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 How to update a portion of text in a ... Bill Woodger DFSORT/ICETOOL 25 Wed Nov 09, 2016 9:41 pm
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
No new posts sort with previous record anatol DFSORT/ICETOOL 9 Thu Oct 06, 2016 2:36 am
No new posts Get Record count in summary record fo... Atul Banke DFSORT/ICETOOL 21 Fri Sep 23, 2016 4:17 pm
No new posts Change date (DD/MM/YY) in 2nd record ... uday kiran DFSORT/ICETOOL 12 Wed Sep 07, 2016 10:57 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us