IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

To extract part of a string from a record


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
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
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 Developer


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

PostPosted: Tue Dec 07, 2010 12:27 am
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
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
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Tue Dec 07, 2010 1:27 pm
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: 2481
Location: @my desk

PostPosted: Tue Dec 07, 2010 2:02 pm
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
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: 2481
Location: @my desk

PostPosted: Tue Dec 07, 2010 5:34 pm
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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Tue Dec 07, 2010 5:37 pm
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
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
Reply with quote

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

DFSORT Developer


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

PostPosted: Tue Dec 07, 2010 10:01 pm
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
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: 2481
Location: @my desk

PostPosted: Wed Dec 08, 2010 10:54 am
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DFSORT/ICETOOL

 


Similar Topics
Topic Forum Replies
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
Search our Forums:

Back to Top