Page 1 of 2

Adding leading Zero to output value

PostPosted: Tue Mar 01, 2011 10:59 pm
by rjambu
I am trying to add leading zero to a alphanumeric value o/p.
not working as expected

//SYSIN DD *
SORT FIELDS=COPY
INREC PARSE=(%00=(ENDBEFR=X'6A',FIXLEN=04),
%01=(ENDBEFR=X'6A',FIXLEN=05)),

BUILD=(%00,%01,UFF,M11,)
/*


i/p:
----+----

1212¦1000
1213¦R001
1214¦XXXX

o/p should be :
----+----

121201000
12130R001
12140XXXX

I need the 2nd columns should be having leading zero (5 char length ) in the answerset


when i Use the below code i get the correct answer for numeric data alone,
But doesnt work for alphanuberic values.

is there any solution for this ?

Thanks,
JRS

Re: Adding leading Zero to output value

PostPosted: Tue Mar 01, 2011 11:34 pm
by Frank Yaeger
Going by your example, it appears all you need to do is overlay the 5th column with a 0 so you could use these DFSORT control statements:

  OPTION COPY             
  INREC OVERLAY=(5:C'0')   


If your requirement is really more complicated than that, please show an example of your input records and expected output records that show the actual complexity of what you're trying to do, and explain the rules for getting from input to output.

Re: Adding leading Zero to output value

PostPosted: Wed Mar 02, 2011 1:08 am
by rjambu
Hi Frank,

I tried using the bleow code

//SYSIN DD *
OPTION COPY
INREC OVERLAY=(5:C'0'),
PARSE=(%00=(ENDBEFR=X'6A',FIXLEN=04),
%01=(ENDBEFR=X'6A',FIXLEN=05)),
BUILD=(%00,%01)
/*
//

Gives syntax error, Donno wheather i used ur code in right place!

Re: Adding leading Zero to output value

PostPosted: Wed Mar 02, 2011 2:11 am
by Frank Yaeger
Sigh. You DON'T NEED PARSE to overlay one character in position 5 - you just need OVERLAY like this:

//SYSIN DD *
  OPTION COPY             
  INREC OVERLAY=(5:C'0')
/*

Re: Adding leading Zero to output value

PostPosted: Wed Mar 02, 2011 7:43 pm
by rjambu
Hi Frank,

i tried with the overlay removing the parse from JCL, Not sure how to change the existing code to overlay


//SORTIN DD DSN=A.B.SRC_IN,DISP=SHR
//SORTOUT DD DSN=A.B.TGT_OUT,
// UNIT=DISK,SPACE=(TRK,(1,2),RLSE),
// DCB=(LRECL=302,BLKSIZE=0,RECFM=FB),
// DISP=(NEW,CATLG,DELETE)
//SYSSORT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//*
//SYSIN DD *
OPTION COPY
INREC OVERLAY=(5:C'0'),(%00=(ENDBEFR=X'6A',FIXLEN=04),
%01=(ENDBEFR=X'6A',FIXLEN=05)),
BUILD=(%00,%01)
/*

Can you help me in this

Thanks
JRS

Re: Adding leading Zero to output value

PostPosted: Wed Mar 02, 2011 8:15 pm
by NicC
why are you not using Frank's code as supplied? He has given a complete solution. Why your ENDBEFR, FIXLEN & BUILD?

Re: Adding leading Zero to output value

PostPosted: Wed Mar 02, 2011 8:24 pm
by enrico-sorichetti
most probably the initial requirement was not properly defined/described!

Re: Adding leading Zero to output value

PostPosted: Wed Mar 02, 2011 9:16 pm
by rjambu
Hey Guys Sorry for not giving the correct source scenario,

Here is the new CSV i/p data that I get.

1st column comes blank
2nd column with 4 char length
3rd column Blank data
4th Column contain City
5th Column Contain State code


Source data Required O/p Data

¦1340¦¦Scranton¦PA --01340----Scranton-------PA
¦2140¦¦ Cleveland¦OH --02140----Cleveland------OH
¦R000¦¦Chicago¦IL --0R000----Chicago--------IL
¦X990¦¦¦ --0X990---------------------


In the o/p file layout, I represent the spaces as ‘-’ , the o/p needs the exact same layout as this will be used by a cobol PGM that will use this layout.

That is the reason I used the PARSE statement.


Before the requirement to add Zero before the 2nd column the JCL code looked like this and worked fine :

//SORTIN DD DSN=A.B.C,DISP=SHR
//SORTOUT DD DSN=A.B.C,
// UNIT=DISK,SPACE=(TRK,(1,2),RLSE),
// DCB=(LRECL=28,BLKSIZE=0,RECFM=FB),
// DISP=(NEW,CATLG,DELETE)
//SYSSORT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//*
//SYSIN DD *
SORT FIELDS=COPY
INREC PARSE=(%00=(ENDBEFR=X'6A',FIXLEN=02),
%01=(ENDBEFR=X'6A',FIXLEN=05),
%02=(ENDBEFR=X'6A',FIXLEN=04),
%03=(ENDBEFR=X'6A',FIXLEN=15),
%04=(ENDBEFR=X'6A',FIXLEN=02)),
BUILD=(%00,%01,%02,%03,%04)
/*

thx
JRS

Re: Adding leading Zero to output value

PostPosted: Wed Mar 02, 2011 10:40 pm
by NicC
Are the ¦s actually in the data? Probably best if you show the data as it is - cut'n'paste and use code tags so that we cn see the real alignment.

Re: Adding leading Zero to output value

PostPosted: Wed Mar 02, 2011 10:53 pm
by rjambu
Here is the Source data and the required o/p data


Source data

¦1340¦¦Scranton¦PA
¦2140¦¦ Cleveland¦OH
¦R000¦¦Chicago¦IL
¦X990¦¦¦


Required O/p Data

  01340    Scranton       PA
  02140    Cleveland      OH
  0R000    Chicago        IL
  0X990                   


Thanks JRS