alphanumeric to numeric value padding with ZEROS in COBOL
Moderators: dbzTHEdinosauer, Moderator Group
alphanumeric to numeric value padding with ZEROS in COBOL
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.
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.
- dbzTHEdinosauer
- Moderator
- Posts: 981
- Joined: Mon Oct 02, 2006 8:31 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?
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.
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.
Thanks for the reply.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?
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.
- dbzTHEdinosauer
- Moderator
- Posts: 981
- Joined: Mon Oct 02, 2006 8:31 pm
i am in the initial stage of development.dbzTHEdinosauer wrote:what code are you using that does not work?
data layout, code.....
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.
- dbzTHEdinosauer
- Moderator
- Posts: 981
- Joined: Mon Oct 02, 2006 8:31 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.
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.
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.
COBOL FUNCTION NUMVAL INSPECT REPLACING
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.
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.
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'.
WS-NUMERIC defined with 9(7)
WS-ALPHANUMERIC defined with X(7)
the number padded with ZEROES will be in WS-ALPHANUMERIC.
Natarajan
Chennai
Chennai
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
- Cobol Interview Questions
50+ Interview Questions - JCL Interview Questions
50+ Interview Questions - DB2 Interview Questions
100+ Interview Questions - CICS Interview Questions
70+ Interview Questions - VSAM Interview Questions
27 Interview Questions
Other References
Mainframe Tools and others
- XPEDITER Reference
Explains how we can debug a program - FILEAID Reference
Explains how to browse , edit and delete datasets - Change Man Reference
Quick Start tutorial on Changeman - Abend Reference
Important Abend codes explained - FaceBook Page
MainframeGurukul FaceBook Page - LinkedIn Page
MainframeGurkul Linkedin Page