Page 1 of 1

String formatting using DFSORT/ICETOOL

PostPosted: Wed Mar 13, 2013 11:28 pm
by nikesh_rai
Hi Guys,

I want to format certain string into a different format. My Input file will have the strings given below:

S9
S9V9
S99
S99V9
S99V99
S999
S999V9
S999V99
S999V999
S9(X)V9(X)

X= NUMBER OF OCCURANCE OF 9

I think you understand that its a COBOL data format.. and I have to modify these strings into SAS equivalent data format... and the output should be:

S9 - PD1.
S9V9 - PD1.1
S99 - PD2.
S99V9 - PD2.1
S99V99 - PD2.2
S999 - PD3.
S999V9 - PD3.1
S999V99 - PD3.2
S999V999 - PD3.3
S9(X)V9(X) - PDX.X

Please suggest me some ideas.. I have done it with Parse.. but the code became too huge for this.. is there any other way to do this.. like using ICETOOL
I have gone through a link.. which seems me a good one..

http://ibmmainframes.com/about56572.html

but still want yours opinion

Thanks
Nikesh

Re: String formatting using DFSORT/ICETOOL

PostPosted: Wed Mar 13, 2013 11:39 pm
by skolusu
nikesh_rai wrote:I think you understand that its a COBOL data format.. and I have to modify these strings into SAS equivalent data format... and the output should be:

Please suggest me some ideas.. I have done it with Parse.. but the code became too huge for this.. is there any other way to do this.. like using ICETOOL
I have gone through a link.. which seems me a good one..

http://ibmmainframes.com/about56572.html

but still want yours opinion

Thanks
Nikesh


Nikesh all your variables defined as COMP-3? What happens if any of fields are Comp, Comp-1, Comp-2 or comp-5?. Don't get hung up using parse as there are other simple ways to do what you want.

Re: String formatting using DFSORT/ICETOOL

PostPosted: Thu Mar 14, 2013 12:04 am
by nikesh_rai
Thanks Kolusu..

Yes.. it will have only comp-3.. just for your information.. please don't be confused with data and data declaration :) .. I have nothing to do with data at this step.. the data declaration is only the data as input.. and I need to format it into PDX.X format as I have mention above..

My input file looks like

WXXX-BAA-SAA-NAA                   S9(4)   
WXXX-CAA-IA                        S9(10)   
WXXX-RAAA-SAAAA-VAA-NAA            S999
WXXX-GAA-AAA                       S9(9)V9(4)
WXXX-PAAA-IAAAA                    S9(4)V999


and output should looks like

WXXX-BAA-SAA-NAA                   PD4.   
WXXX-CAA-IA                        PD10.   
WXXX-RAAA-SAAAA-VAA-NAA            PD3.
WXXX-GAA-AAA                       PD9.4
WXXX-PAAA-IAAAA                    PD4.3

Re: String formatting using DFSORT/ICETOOL

PostPosted: Thu Mar 14, 2013 1:07 am
by enrico-sorichetti
just curious ... here is a POC on how to do it in REXX

/* REXX */
Trace "O"

pic.1 = "S9(4)"
pic.2 = "S9(10)"
pic.3 = "S999"
pic.4 = "S9(9)V9(4)"
pic.5 = "S9(4)V999"
pic.0 = 5

do  p = 1 to pic.0
    format = "PD"
    /* isolate integer and decimal part */
    parse var pic.p ipic "V" dpic

    /* try xx(yy) format */
    parse var ipic . "(" digits ")"
    if  digits = "" then ,
        digits = length(ipic) - 1
    format = format || digits

    if  dpic = "" then do
        format = format || "."
    end
    else do
        parse var dpic . "(" digits ")"
        if  digits = "" then ,
            digits = length(dpic)
        format = format || "." || digits
    end
    say left(pic.p, 10) "..." format

end

exit

and here is the result
S9(4)      ... PD4.
S9(10)     ... PD10.
S999       ... PD3.
S9(9)V9(4) ... PD9.4
S9(4)V999  ... PD4.3

Re: String formatting using DFSORT/ICETOOL

PostPosted: Thu Mar 14, 2013 1:38 am
by enrico-sorichetti
hit enter too quickly
change
parse var ipic . "(" digits ")"

to
parse var ipic . "(" digits ")" .


and
parse var dpic . "(" digits ")"

to
parse var dpic . "(" digits ")" .


the before works, but the after is more compliant with a proper parsing logic

Re: String formatting using DFSORT/ICETOOL

PostPosted: Thu Mar 14, 2013 4:32 am
by skolusu
Here is a DFSORT JCL which will give you the desired results. I assumed that you field declarations start at pos 36 and you can have S9999... upto 20 and v9999... upto 20.

//STEP0100 EXEC PGM=SORT                                             
//SYSOUT   DD SYSOUT=*                                               
//SORTIN   DD *                                                       
----+----1----+----2----+----3----+----4----+----5----+----6----+----7
WXXX-BAA-SAA-NAA                   S9(4)                             
WXXX-CAA-IA                        S9(10)                             
WXXX-RAAA-SAAAA-VAA-NAA            S999                               
WXXX-GAA-AAA                       S9(9)V9(4)                         
WXXX-PAAA-IAAAA                    S9(4)V999                         
WXXX-PAAA-IBBBB                    S9V99999                           
//SORTOUT  DD SYSOUT=*                                               
//SYSIN    DD *                                                       
  OPTION COPY                                                         
  INREC IFOUTLEN=120,IFTHEN=(WHEN=INIT,                               
  PARSE=(%01=(ABSPOS=36,STARTAFT=C'S',ENDBEFR=C'V',ENDBEFR=C' ',     
              FIXLEN=20),                                             
         %02=(FIXLEN=20)),OVERLAY=(81:%01,%02)),                     
                                                                     
  IFTHEN=(WHEN=(81,20,SS,NE,C'('),                                   
  OVERLAY=(081:81,20,TRAN=ALTSEQ,121:C'PD',                           
           081,1,ZD,ADD,082,1,ZD,ADD,083,1,ZD,ADD,084,1,ZD,ADD,       
           085,1,ZD,ADD,086,1,ZD,ADD,087,1,ZD,ADD,088,1,ZD,ADD,       
           089,1,ZD,ADD,090,1,ZD,ADD,091,1,ZD,ADD,092,1,ZD,ADD,       
           093,1,ZD,ADD,094,1,ZD,ADD,095,1,ZD,ADD,096,1,ZD,ADD,       
           097,1,ZD,ADD,098,1,ZD,ADD,099,1,ZD,ADD,100,1,ZD,           
           EDIT=(IT),C'.',81:121,5,15X),HIT=NEXT),                   
                                                                     
  IFTHEN=(WHEN=(101,20,SS,NE,C'(',AND,101,20,CH,GT,C' '),             
  OVERLAY=(101:101,20,TRAN=ALTSEQ,                                   
           101:101,1,ZD,ADD,102,1,ZD,ADD,103,1,ZD,ADD,104,1,ZD,ADD,   
               105,1,ZD,ADD,106,1,ZD,ADD,107,1,ZD,ADD,108,1,ZD,ADD,   
               109,1,ZD,ADD,110,1,ZD,ADD,111,1,ZD,ADD,112,1,ZD,ADD,   
               113,1,ZD,ADD,114,1,ZD,ADD,115,1,ZD,ADD,116,1,ZD,ADD,   
               117,1,ZD,ADD,118,1,ZD,ADD,119,1,ZD,ADD,120,1,ZD,       
               EDIT=(II),18X))                                       
  ALTSEQ CODE=(F9F1,40F0)                                             
                                                                     
  OUTREC IFTHEN=(WHEN=INIT,FINDREP=(STARTPOS=081,ENDPOS=100,   
  INOUT=(C'9(',C'PD',C') ',C'. '))),                           
  IFTHEN=(WHEN=INIT,FINDREP=(STARTPOS=101,                     
  INOUT=(C'9(',C'  ',C') ',C'  '))),                           
  IFTHEN=(WHEN=INIT,BUILD=(1,35,81,40,SQZ=(SHIFT=LEFT)))       
                                                               
//*

Re: String formatting using DFSORT/ICETOOL

PostPosted: Sat Mar 16, 2013 12:08 pm
by nikesh_rai
Thanks a lot Kolusu... Its working.. :)

Thanks Enrico...