Page 1 of 2

String manupulation in JCL

PostPosted: Fri Mar 08, 2013 4:30 pm
by nikesh_rai
Hi,

I have a file with inputs like:

BIT-STRD-INFO
BIT-SEQ-NBR
TEL-LINE-NBR

and needs to process the input and output should be:

B-S-I
B-S-N
T-L-N


Can wo do this using Sort JCL or better to go with REXX...
Please suggest..

Thanks
Nikesh

Re: String manupulation in JCL

PostPosted: Fri Mar 08, 2013 4:39 pm
by BillyBoyo
If you use PARSE with "-" to delimit the fields, you can then
  BUILD=(%00,2:C'-',%01,4:C'-',%03,6:75X)


That is for 80-byte records. If you want five bytes for your LRECL, then you might be able to use IFOUTLEN or another BUILD of 1,5.

Re: String manupulation in JCL

PostPosted: Fri Mar 08, 2013 4:44 pm
by nikesh_rai
Thanks Billy,

But the problem is variable string length, like

RATE-STRUC-ST-DT
PBE-INSTNC
BILG-ELMT-CAT-CODE


Which shoud be processed as

R-S-S-D
P-I
B-E-C-C

Re: String manupulation in JCL

PostPosted: Fri Mar 08, 2013 5:13 pm
by enrico-sorichetti
did You care to read the <sort> manuals or search the forum for examples of the PARSE clause ???

Re: String manupulation in JCL

PostPosted: Fri Mar 08, 2013 5:31 pm
by BillyBoyo
Well, you need enough PARSEd fields for your maximum number of elements, and only to put the "-" if the "next" PARSEd field is not equal to spaces.

Re: String manupulation in JCL

PostPosted: Fri Mar 08, 2013 5:33 pm
by nikesh_rai
I have already checked with PARSE and some manuals as well, but was not able to resolve my problem.

Re: String manupulation in JCL

PostPosted: Fri Mar 08, 2013 5:40 pm
by enrico-sorichetti
You will need a two stage approach ...
PARSE to split the single tokens
<BUILD> to extract the first char

Re: String manupulation in JCL

PostPosted: Fri Mar 08, 2013 6:18 pm
by BillyBoyo
Something like this, which is for "four-element" names, so note what happened to the last test data.

//STEP0100 EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SORTOUT  DD SYSOUT=*
//SYSIN    DD *
  OPTION COPY
  INREC IFTHEN=(WHEN=INIT,
                PARSE=(%00=(ENDBEFR=C'-',FIXLEN=1),
                       %01=(ENDBEFR=C'-',FIXLEN=1),
                       %02=(ENDBEFR=C'-',FIXLEN=1),
                       %03=(ENDBEFR=C'-',FIXLEN=1))),
        IFTHEN=(WHEN=INIT,
                BUILD=(%00,C'-',%01,C'-',%02,C'-',%03)),
        IFTHEN=(WHEN=(1,1,CH,EQ,C' '),
                OVERLAY=(2:79X)),
        IFTHEN=(WHEN=(3,1,CH,EQ,C' '),
                OVERLAY=(2:79X)),
        IFTHEN=(WHEN=(5,1,CH,EQ,C' '),
                OVERLAY=(4:77X)),
        IFTHEN=(WHEN=(7,1,CH,EQ,C' '),
                OVERLAY=(6:75X))
                                                       
//SORTIN   DD *
RATE-STRUC-ST-DT
PBE-INSTNC
BILG-ELMT-CAT-CODE
                                                       
TEST
TEST-TOST-TIST
1-2-3-4-5


Gives:

R-S-S-D
P-I   
B-E-C-C
       
T     
T-T-T 
1-2-3-4

Re: String manupulation in JCL

PostPosted: Fri Mar 08, 2013 11:13 pm
by skolusu
BillyBoyo,

You can simplify the job using the parm "STARTAT" instead of "ENDBEFR" on PARSE and then pick the values. Makes it quite easy. :D Something like this

//STEP0100 EXEC PGM=SORT                               
//SYSOUT   DD SYSOUT=*                                 
//SORTIN   DD *                                       
RATE-STRUC-ST-DT                                       
PBE-INSTNC                                             
BILG-ELMT-CAT-CODE                                     
                                                       
TEST                                                   
TEST-TOST-TIST                                         
1-2-3-4-5                                             
//SORTOUT  DD SYSOUT=*                                 
//SYSIN    DD *                                       
  OPTION COPY                                         
  INREC PARSE=(%01=(ABSPOS=2,STARTAT=C'-',FIXLEN=2),   
               %02=(STARTAT=C'-',FIXLEN=2),           
               %03=(STARTAT=C'-',FIXLEN=2)),           
  BUILD=(1,1,%01,%02,%03)                             
//*


The output
R-S-S-D 
P-I     
B-E-C-C 
         
T       
T-T-T   
1-2-3-4 


You can use an OMIT condition to remove all spaces records.

Re: String manupulation in JCL

PostPosted: Sat Mar 09, 2013 12:06 am
by BillyBoyo
Yes, that's much neater!