Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Leading zeroes in Alphanumeric field

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Leading zeroes in Alphanumeric field
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    Post subject:
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    Post subject:
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    Post subject:
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: 6968
Location: porcelain throne

PostPosted: Wed Sep 10, 2008 5:28 pm    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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: 8165
Location: East Dubuque, Illinois, USA

PostPosted: Thu Sep 11, 2008 7:22 am    Post subject:
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: 2504
Location: Atlanta, Georgia, USA

PostPosted: Thu Sep 11, 2008 7:53 am    Post subject: Re: Leading zeroes in Alphanumeric field
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    Post subject:
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    Post subject: Reply to: Leading zeroes in Alphanumeric field
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming 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 length exceeds ... maxsubrat DFSORT/ICETOOL 7 Wed Oct 04, 2017 4:48 pm
No new posts Partial color change of a field in CI... waseem0424 CICS 5 Fri Sep 29, 2017 7:56 pm
No new posts Remove leading spaces from numeric field rexx77 SYNCSORT 6 Wed Sep 06, 2017 2:15 am
No new posts JES2 job size field matching Windows ... SRICOBSAS All Other Mainframe Topics 4 Tue Sep 05, 2017 5:49 pm
No new posts READ A PACKED "NEGATIVE" FI... jdesouza CA Products 3 Tue May 02, 2017 11:43 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us