Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Insert leading zeros to numeric value

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
View previous topic :: :: View next topic  
Author Message
srajanbose
Warnings : 1

New User


Joined: 11 Oct 2004
Posts: 69
Location: chennai

PostPosted: Wed Mar 28, 2012 6:34 pm    Post subject: Insert leading zeros to numeric value
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    Post subject:
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    Post subject: overlay field with edited contents of field
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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Wed Mar 28, 2012 8:18 pm    Post subject: Reply to: Insert leading zeros to numeric value
Reply with quote

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

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7223

PostPosted: Wed Mar 28, 2012 9:05 pm    Post subject: Reply to: Insert leading zeros to numeric value
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    Post subject: Reply to: Insert leading zeros to numeric value
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    Post subject:
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
Warnings : 1

New User


Joined: 11 Oct 2004
Posts: 69
Location: chennai

PostPosted: Thu Mar 29, 2012 11:55 am    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Sort records based on numeric field. Alks SYNCSORT 2 Wed Oct 19, 2016 10:14 pm
No new posts Insert Lines in JCL with Rexx after a... Willy Jensen CLIST & REXX 3 Tue Aug 30, 2016 4:18 pm
No new posts How to insert a lengthy string havin... vidyaa DB2 7 Thu Aug 25, 2016 5:20 pm
No new posts Casting a Binary Number to Numeric in... Bob Steinkraus Java & MQSeries 6 Tue Aug 09, 2016 5:58 pm
This topic is locked: you cannot edit posts or make replies. Alphanumeric to Numeric move on UNIX mistah kurtz COBOL Programming 16 Wed Jul 27, 2016 8:47 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us