alphanumeric to numeric value padding with ZEROS in COBOL

This is a Mainframe COBOL forum - you can post your queries on Mainframe COBOL, VS COBOL II, COBOL/370 , Enterprise COBOL

Moderators: dbzTHEdinosauer, Moderator Group

Post Reply
rohan
Member
Posts: 4
Joined: Fri Mar 27, 2009 12:37 pm
Contact:

alphanumeric to numeric value padding with ZEROS in COBOL

Post by rohan » Fri Mar 27, 2009 1:22 pm

Hello friends,

I need to have a PIC clause value padded with '0'.

The problem is like, I have a PIC 9(7) clause and want to get a user input value stored into that. If supplied value is less than 7 char, then the value should be padded with '0' to occupy all 7 digits.

Example-

User Supplied Value :- 1234
Padded Value:- 0001234

Please help out on this issue. I need a solution urgently.

Thanks in advance.

User avatar
dbzTHEdinosauer
Moderator
Posts: 981
Joined: Mon Oct 02, 2006 8:31 pm

Post by dbzTHEdinosauer » Fri Mar 27, 2009 1:39 pm

*sigh*

1. if you want to store negative signs, you need a pic S9(7).

2. what is your source? x-type? if x-type, use NUMVAL.

3. any reason you need to use display instead of a real numeric like PACKED-DECIMAL?
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.

rohan
Member
Posts: 4
Joined: Fri Mar 27, 2009 12:37 pm
Contact:

Post by rohan » Fri Mar 27, 2009 2:02 pm

dbzTHEdinosauer wrote:*sigh*

1. if you want to store negative signs, you need a pic S9(7).

2. what is your source? x-type? if x-type, use NUMVAL.

3. any reason you need to use display instead of a real numeric like PACKED-DECIMAL?
Thanks for the reply.

What I need that is just for a "Customer Number" field. So I don't need to perform any calculation or sign.

and it just needs to be padded.

User avatar
Natarajan
Moderator
Posts: 537
Joined: Fri Oct 10, 2008 12:57 pm
Location: chennai
Contact:

Post by Natarajan » Fri Mar 27, 2009 4:06 pm

Let us know , if you are still facing the issue.
Natarajan
Chennai

rohan
Member
Posts: 4
Joined: Fri Mar 27, 2009 12:37 pm
Contact:

Post by rohan » Fri Mar 27, 2009 4:23 pm

Yes, I'm still facing this issue. Kindly let me know.
Thanks.

User avatar
dbzTHEdinosauer
Moderator
Posts: 981
Joined: Mon Oct 02, 2006 8:31 pm

Post by dbzTHEdinosauer » Fri Mar 27, 2009 4:31 pm

what code are you using that does not work?

data layout, code.....
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.

rohan
Member
Posts: 4
Joined: Fri Mar 27, 2009 12:37 pm
Contact:

Post by rohan » Fri Mar 27, 2009 5:02 pm

dbzTHEdinosauer wrote:what code are you using that does not work?

data layout, code.....
i am in the initial stage of development.
All I have done is declared a variable

WS-CUST-NUM PIC 9(7).

The program ACCEPT the input value given on the CICS designed screen and stores it in this variable.
This input has to be then padded with 0's

if input is 1234, I want it to be changed into 0001234.
this is only used as an ID number. No arithmetic operation is to be performed.

User avatar
dbzTHEdinosauer
Moderator
Posts: 981
Joined: Mon Oct 02, 2006 8:31 pm

Post by dbzTHEdinosauer » Fri Mar 27, 2009 5:24 pm

suggest you try ACCEPTing to an x-type field and then use NUMVAL to move the data to the display-numeric (WS-CUST-NUM) field.

the NUMVAL function will correctly justify the numeric portion of the x-type field (the accept destination) and zero fill to the left.

display-numeric fields are not really 'numeric'.

ACCEPT from CICS? normally RECEIVE is used to import a map (or any data) from a terminal.
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.

User avatar
Natarajan
Moderator
Posts: 537
Joined: Fri Oct 10, 2008 12:57 pm
Location: chennai
Contact:

COBOL FUNCTION NUMVAL INSPECT REPLACING

Post by Natarajan » Fri Mar 27, 2009 9:10 pm

Method 1) In cics-bms programs
In cics programs.. you can do this by coding appropriate picture clause in BMS maps ( PICOUT attribute ) ,
if your work is to display the numeric data with padding zeros.


Method 2) applies to any COBOL program

Here is the basic solution for this.

Code: Select all


MOVE  '  345   ' TO WS-ALPHANUMERIC.                 

COMPUTE WS-NUMERIC = FUNCTION NUMVAL(WS-ALPHANUMERIC)  

MOVE WS-NUMERIC  TO  WS-ALPHANUMERIC.                  

INSPECT WS-ALPHANUMERIC REPLACING ALL SPACES BY '0'. 

In above code...
WS-NUMERIC defined with 9(7)
WS-ALPHANUMERIC defined with X(7)

the number padded with ZEROES will be in WS-ALPHANUMERIC.
Natarajan
Chennai

academyindia4

Topic deleted by Admin

Post by academyindia4 » Wed Jan 27, 2016 8:21 pm

<< Content deleted By Admin >>

academyindia4

Topic deleted by Admin

Post by academyindia4 » Sat Jan 30, 2016 11:41 pm

<< Content deleted By Admin >>

academyindia4

Topic deleted by Admin

Post by academyindia4 » Mon Feb 01, 2016 10:08 pm

<< Content deleted By Admin >>

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others