Adding leading zeroes in alpahnumeric field in cobol



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Adding leading zeroes in alpahnumeric field in cobol

Postby vivek naik » Thu Jun 12, 2014 7:16 pm

I have a field
05 WS-ALPHA PIC X(10).

WS-ALPHA can have only left justified digits of length varying from 1 to 5(rest filled with spaces) e.g. "1 " "12 " "123 " "1234 " "12345 ".

Now I have to format and display the value of WS-ALPHA in SYSOUD with leading zero if the length is less than 5. so if the value of WS-ALPHA is "1 " it should be displayed as "00001"

I have made many unsuccessful attempt. Please help me know how i can do it.

one of the bad attmepts:

 01  WS-VARIABLES.                                           
     05 WS-ALPHA-PARM            PIC X(10) VALUE '1         '.
     05 WS-ALPHA-05-PARM         PIC X(05) VALUE SPACES.     
     05 WS-NUM-05-PARM           PIC 9(05) VALUE ZEROES.     
     05 WS-NUM-05-PARM2         PIC 9(05) VALUE ZEROES.       
/                                                             
 PROCEDURE DIVISION.                                         
                                                             
      MOVE WS-ALPHA-PARM TO WS-ALPHA-05-PARM                 
      MOVE WS-ALPHA-05-PARM TO WS-NUM-05-PARM                 
      MOVE WS-NUM-05-PARM   TO WS-NUM-05-PARM2               
      DISPLAY 'WS-NUM-05-PARM :' WS-NUM-05-PARM               
      DISPLAY 'WS-NUM-05-PARM2:' WS-NUM-05-PARM2             

result: WS-NUM-05-PARM :1   0 
WS-NUM-05-PARM2:1   0   
Working On A Dream
vivek naik
 
Posts: 6
Joined: Wed Jan 18, 2012 11:24 am
Has thanked: 0 time
Been thanked: 0 time

Re: Adding leading zeroes in alpahnumeric field in cobol

Postby Robert Sample » Thu Jun 12, 2014 7:29 pm

The easiest way is find the Language Reference manual for your version of Enterprise COBOL and read up on intrinsic function NUMVAL.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post