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

Insert leading zeros to numeric value


IBM Mainframe Forums -> DFSORT/ICETOOL
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
srajanbose

New User


Joined: 11 Oct 2004
Posts: 69
Location: chennai

PostPosted: Wed Mar 28, 2012 6:34 pm
Reply with quote

Hi,

I have a requirement to add leading zeros to the numeric value using dfsort.
My input file is sequential with lrecl 10.(pic x(10).
Example input data:
Code:
123457
34567r
997654d3
4568
23

Expected output:
Code:
000123457
34567r
997654d3
0000004568
0000000023

srajanbose@yahoo.co.in
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Mar 28, 2012 7:38 pm
Reply with quote

i imagine
IFWHENTHEN thingy:

Note: Numeric tests can also be used in the WHEN condition of an IFTHEN clause. For example:
INREC IFTHEN=(WHEN=(15,3,FS,NE,NUM),OVERLAY=(15:C'000'))


*from the sorttrck.pdf ftp-download.

Then during INREC:

PARSE=(%00=(ABSPOS=1,ENDAT=BLANKS))
and a simple substring search:
WHEN=(1,10,CH,EQ,C'0123456789 '),
and then a
BUILD=
or
FIELDS=
(%00, ,TO=ZD,LENGTH=10)


now, alittle disclaimer:

1. not able to implement/syntax check/test.

2. not sure about the impact on record length the build vs felds has,
but you can test that out.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Mar 28, 2012 8:12 pm
Reply with quote

i would think that this is a better title for your topic:

OCCASIONALLY OVERLAY FIELD WITH EDITED CONTENTS OF FIELD

sorry guys, just visited my local huka dealer.
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Mar 28, 2012 8:18 pm
Reply with quote

RECFM is fixed or variable?
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Mar 28, 2012 9:05 pm
Reply with quote

OK, assume fixed:

Code:

//LEADZERO EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SORTOUT  DD SYSOUT=*
//SYSIN    DD *
 SORT FIELDS=COPY
 INREC IFOUTLEN=10,
       IFTHEN=(WHEN=INIT,OVERLAY=(11:1,10)),
       IFTHEN=(WHEN=(10,1,CH,EQ,C' '),OVERLAY=(2:1,9,1:C'0'),HIT=NEXT),
       IFTHEN=(WHEN=(10,1,CH,EQ,C' '),OVERLAY=(2:1,9,1:C'0'),HIT=NEXT),
       IFTHEN=(WHEN=(10,1,CH,EQ,C' '),OVERLAY=(2:1,9,1:C'0'),HIT=NEXT),
       IFTHEN=(WHEN=(10,1,CH,EQ,C' '),OVERLAY=(2:1,9,1:C'0'),HIT=NEXT),
       IFTHEN=(WHEN=(10,1,CH,EQ,C' '),OVERLAY=(2:1,9,1:C'0'),HIT=NEXT),
       IFTHEN=(WHEN=(10,1,CH,EQ,C' '),OVERLAY=(2:1,9,1:C'0'),HIT=NEXT),
       IFTHEN=(WHEN=(10,1,CH,EQ,C' '),OVERLAY=(2:1,9,1:C'0'),HIT=NEXT),
       IFTHEN=(WHEN=(10,1,CH,EQ,C' '),OVERLAY=(2:1,9,1:C'0'),HIT=NEXT),
       IFTHEN=(WHEN=(10,1,CH,EQ,C' '),OVERLAY=(2:1,9,1:C'0'),HIT=NEXT),
       IFTHEN=(WHEN=(1,10,FS,NE,NUM),OVERLAY=(1:11,10))

//*
//SORTIN   DD *
123457
34567R
997654D3
4568
23
1
                                                                   
GGGGGGG
1234567890


Output is:

Code:
0000123457
34567R   
997654D3 
0000004568
0000000023
0000000001
         
GGGGGGG   
1234567890


And yes, that is nine identical ithen/overlays.
Back to top
View user's profile Send private message
Skolusu

Senior Member


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

PostPosted: Wed Mar 28, 2012 9:49 pm
Reply with quote

srajanbose,

Assuming that you don't want to reformat if you find any alphabet in the first 10 bytes the following DFSORT JCL will give you the desired results.


Code:

//STEP0100 EXEC PGM=SORT                                         
//SYSOUT   DD SYSOUT=*                                           
//SYMNAMES DD *                                                 
ALPHA,C'A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z'     
//SORTIN   DD *                                                 
123457                                                           
34567R                                                           
997654D3                                                         
4568                                                             
23                                                               
//SORTOUT  DD SYSOUT=*                                           
//SYSIN    DD *                                                 
  SORT FIELDS=COPY                                               
  INREC IFTHEN=(WHEN=(01,01,SS,EQ,ALPHA,OR,02,01,SS,EQ,ALPHA,OR,
                      03,01,SS,EQ,ALPHA,OR,04,01,SS,EQ,ALPHA,OR,
                      05,01,SS,EQ,ALPHA,OR,06,01,SS,EQ,ALPHA,OR,
                      07,01,SS,EQ,ALPHA,OR,08,01,SS,EQ,ALPHA,OR,
                      09,01,SS,EQ,ALPHA,OR,10,01,SS,EQ,ALPHA),   
  BUILD=(1,10)),                                                 
  IFTHEN=(WHEN=NONE,BUILD=(1,10,UFF,M11,LENGTH=10))             
//*


The output of the above job is
Code:

0000123457
34567R     
997654D3   
0000004568
0000000023
Back to top
View user's profile Send private message
Skolusu

Senior Member


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

PostPosted: Wed Mar 28, 2012 9:57 pm
Reply with quote

Alternatively you can use ALTSEQ to replace the spaces to zeros and NUM function to check for all numbers and then pad leading zeroes with editmask and get the desired results

Code:

//STEP0100 EXEC PGM=SORT                                             
//SYSOUT   DD SYSOUT=*                                               
//SORTIN   DD *                                                     
123457                                                               
34567R                                                               
997654D3                                                             
4568                                                                 
23                                                                   
//SORTOUT  DD SYSOUT=*                                               
//SYSIN    DD *                                                     
  SORT FIELDS=COPY                                                   
  INREC IFOUTLEN=10,IFTHEN=(WHEN=INIT,OVERLAY=(11:1,10,TRAN=ALTSEQ)),
  IFTHEN=(WHEN=(11,10,FS,EQ,NUM),OVERLAY=(1:1,10,UFF,M11,LENGTH=10))
  ALTSEQ CODE=(40F0)                                                 
//*
Back to top
View user's profile Send private message
srajanbose

New User


Joined: 11 Oct 2004
Posts: 69
Location: chennai

PostPosted: Thu Mar 29, 2012 11:55 am
Reply with quote

Thanks all for your Reply.It worked fine for me.
Thanks again.
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 Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts Keep leading zero(s) after convert fl... SYNCSORT 7
No new posts Remove leading zeroes SYNCSORT 4
No new posts leading spaces can be removed in trai... DFSORT/ICETOOL 1
No new posts Insert header record with record coun... DFSORT/ICETOOL 14
Search our Forums:

Back to Top