View previous topic :: View next topic |
Author |
Message |
radham Beginner
Joined: 04 Nov 2005 Posts: 7 Topics: 4
|
Posted: Fri Nov 04, 2005 7:48 am Post subject: data conversion |
|
|
hi can u plzz tel me how to convert alphanumeric datatype to numeric and vice versa in COBOL.i also need the syntax |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
|
Back to top |
|
 |
radham Beginner
Joined: 04 Nov 2005 Posts: 7 Topics: 4
|
Posted: Sun Nov 06, 2005 11:23 pm Post subject: |
|
|
thanks kolusu
i want to know----if we can know the length of the numeric data stored in the alphanumeric field.
for example.....if a variable declared as x(10) has a value '5000'......can we know its length. |
|
Back to top |
|
 |
Phantom Data Mgmt Moderator

Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
|
Posted: Mon Nov 07, 2005 4:20 am Post subject: |
|
|
Radham,
Quote: |
----if we can know the length of the numeric data stored in the alphanumeric field
|
Well, alphanumeric field does not distinguish data by any class - Pure numeric, Alpha, Special characters. It just stores the data in the same format as you pass to it.
whatever be the data, the Alphanumeric field stores the bytes from Left (Left aligned). So you will have 6 spaces after 5000 (like this: "5000______". You can find the length in many ways.
1. Using INSPECT - TALLYING
Code: |
Example:
WORKING-STORAGE SECTION.
01 WS-ALPHA PIC X(10) VALUE '5000'.
01 WS-CNT PIC S9(04) COMP.
PROCEDURE DIVISION.
MAIN-LINE.
INSPECT
WS-ALPHA
TALLYING
WS-CNT
FOR LEADING SPACE.
COMPUTE WS-CNT = WS-CNT - 1.
DISPLAY 'LENGTH OF VARIABLE: ' WS-CNT
|
The above code, scans the alphanumeric field - byte by byte for "Leading" blank character and stores the offset into WS-CNT. You will get the length of your field when you subtract 1 from this offset.
2. Use the LENGTH function available in Language Environment. This question is already been discussed so many time. check the following links.
http://www.mvsforums.com/helpboards/viewtopic.php?t=1282&highlight=length
http://www.mvsforums.com/helpboards/viewtopic.php?t=525&highlight=length
Hope this helps,
Thanks,
Phantom |
|
Back to top |
|
 |
radham Beginner
Joined: 04 Nov 2005 Posts: 7 Topics: 4
|
Posted: Mon Nov 07, 2005 7:58 pm Post subject: |
|
|
thanks a lot....it was helpful |
|
Back to top |
|
 |
|
|