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

Leading zeroes in Alphanumeric field


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
neelesht

New User


Joined: 24 Jul 2006
Posts: 99
Location: Los Angeles

PostPosted: Wed Sep 10, 2008 9:24 am
Reply with quote

Hi All,

I have an Alphanumeric fields X(6) , i want leading zeroes in it.......e.g if value is E6 it shud be 0000E6 (this field can have any value E8 or ABC or TYRS)

one way is to count how till next space and then do it.

I wanted to know if there are any other ways, more simple ones ?

Thanks Everyone
Back to top
View user's profile Send private message
XungoPejcao

New User


Joined: 04 Sep 2008
Posts: 5
Location: EspaƱa

PostPosted: Wed Sep 10, 2008 4:19 pm
Reply with quote

Hi!

You can try with Inspect sentence:

01 CT-E6 PIC X(6) VALUE ' E6'.

------------------------------------------------

INSPECT CT-E6 REPLACING ALL ' ' BY '0'

CT-E6 = '0000E6'
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Wed Sep 10, 2008 5:23 pm
Reply with quote

Code:

inspect ws-var replacing leading spaces by zero

Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Wed Sep 10, 2008 5:25 pm
Reply with quote

I think instead of REPLACING ALL it should be REPLACING LEADING.


if value is 'E 6'
with REPLACING ALL SPACES output will be '000E06'
with REPLACING LEADING SPACES output will be '000E 6'

Now depends on neelesht what he wants.. icon_smile.gif
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Wed Sep 10, 2008 5:28 pm
Reply with quote

since you might be clobbered by justification problems,
you need to know where your non-space data will be.
Code:

'E6     '  or '     E6'. 

If you can insure that the 'significant characters' will be right justified,
then the suggestions about INSPECT REPLACING will be appropriate.

But, if the data is left justified,
you are going to need write some kind of byte manipulation routine;
either with subscripts, indexes or reference modification.
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Wed Sep 10, 2008 5:30 pm
Reply with quote

Sorry Ashimer, i couldnt see your post as i was typing mine...
you were 2 min ahead... icon_smile.gif icon_smile.gif icon_smile.gif
Moderators delete my post if not required
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Wed Sep 10, 2008 5:32 pm
Reply with quote

Quote:

Sorry Ashimer, i couldnt see your post as i was typing mine...



You post does have valid suggestions ...
Back to top
View user's profile Send private message
neelesht

New User


Joined: 24 Jul 2006
Posts: 99
Location: Los Angeles

PostPosted: Thu Sep 11, 2008 3:30 am
Reply with quote

Hi All,

I guess I was not clear enough.
It wont have leading spaces, it will have trailing spaces like 'E6 '

In this case I cant even say INSPECT CT-E6 REPLACING ALL ' ' BY '0' coze it will make it
'E60000'

'E6 ' should look in file as '0000E6'

Sorry for not being clear.

Thanks everyone.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Thu Sep 11, 2008 7:22 am
Reply with quote

neelesht: I haven't tried this but I believe it'll meet your need. Define a variable PIC X(06) JUST RIGHT and move your field to this variable. Do the INSPECT REPLACING LEADING SPACE on this variable.
Back to top
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Thu Sep 11, 2008 7:53 am
Reply with quote

Give this a try -

Code:

           03  WS-WORK-AREA        PIC  X(06).                           
           03  WS-CT-E6            PIC  X(06)      VALUE ' E6'.           
           03  WS-SUB              PIC  9(08)      BINARY.               
                                                                         
           MOVE LENGTH OF WS-WORK-AREA TO WS-SUB.                         
           MOVE WS-SUB                 TO TALLY.                         
           MOVE ZERO                   TO WS-WORK-AREA.                   
      *                                                                   
           PERFORM UNTIL TALLY < 1                                       
               IF  WS-CT-E6 (TALLY:1) > SPACE                             
                   MOVE WS-CT-E6 (TALLY:1)                               
                                       TO WS-WORK-AREA (WS-SUB:1)         
                   SUBTRACT 1          FROM WS-SUB                       
               END-IF                                                     
               SUBTRACT 1              FROM TALLY                         
           END-PERFORM.                                                   
      *                                                                   
      *    AT THIS POINT, 'WS-WORK-AREA' CONTAINS '0000E6'               
      *                                                                   

Regards,

Bill
Back to top
View user's profile Send private message
neelesht

New User


Joined: 24 Jul 2006
Posts: 99
Location: Los Angeles

PostPosted: Thu Sep 11, 2008 8:18 am
Reply with quote

Thanks Bill/Robert and everyone else.

I will try this tomorrow and let you all know.

Thanks for the help.

Regards
Neelesh
Back to top
View user's profile Send private message
Cristopher

New User


Joined: 31 Jul 2008
Posts: 53
Location: NY

PostPosted: Thu Sep 11, 2008 1:22 pm
Reply with quote

Neelesh,

You can very well use the code been suggested by Bill, it will take care of leading or trailing spaces.
But u need to either move zeroes to WS-WORK-AREA in the begining or
use inspect WS-WORK-AREA replacing leading spaces by zero after the Perform to get the desired result.

Regards,
Cris
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Thu Sep 11, 2008 6:43 pm
Reply with quote

Hi Robert,

The parameter JUSTifies on the difference in the sending/receiving VARIABLE lengths, not the difference between the sending string length and the receiving VARIABLE length.
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
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 Join 2 files according to one key field. JCL & VSAM 3
Search our Forums:

Back to Top