View previous topic :: View next topic
|
Author |
Message |
gsmohanty
New User
Joined: 23 Mar 2010 Posts: 1 Location: Bangalore
|
|
|
|
Hi All,
I am writing a program where I am picking out data from a String. The String contains the data in various formats like numeric, packed decimal, alphanumeric, all present together. I am using REFERENCE MODIFICATION while pulling out the data by mentioning the starting position of the data in the string and length occupied by the data. For alphanumeric data and non decimal numeric data it is working fine. Now the situation I am facing is while handling numeric data which are supposed to be decimal. We use copybook to build the string but when my program is reading the string it doesn't have access to the copybook, so my program doesnot know if data is decimal or numeric. The decimal data which I am reading I am moving it to a Variable S9(11)V9(4).
For Example:
01 WS-TEST-VARIABLE.
05 WS-NAME PIC X(5) VALUE 'NAME '.
05 WS-TEST-TET1 PIC S9(3)V9(2) VALUE ZEROS.
01 WS-TTTTT PIC S9(11)V9(2) VALUE ZEROS.
01 WS-T PIC S9(11)V9(2) VALUE ZEROS.
.
.
.
.
MOVE 5.6 TO WS-TEST-TET1
MOVE WS-TEST-VARIABLE(6:5) TO WS-TTTTT
COMPUTE WS-T = WS-TTTTT + 5
DISPLAY WS-TEST-TET1
DISPLAY WS-TTTTT
DISPLAY WS-T
.
.
.
OUTPUT
0056{
000000005600{
5650{
It is treating the value in WS-TTTTT as 560 instead of 5.6
As the expected value of WS-T should be 1060{ instead of
5650{
Please suggest how can I handle this scenario, also please suggest if via Reference Modification in COBOL if we can handle decimal numbers.
Thanks in Advance,[/b] |
|
Back to top |
|
|
cvishu
Active User
Joined: 31 Jul 2007 Posts: 136 Location: india
|
|
|
|
am not sure if it will work but try to Redifne WS-TEST-TET1 as a edited picture clause PIC S9(3).9(2) and the move the edited picture caluse to
WS-TTTTT .
Also am not sure y u want to specificy the positions, when u know ur input is going to be numeric , u can just dirctly move WS-TEST-TET1 .
The gropu variable will alweaya be treated as a character if i am not wrong. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
The V in a PICTURE clause is an implied decimal point. You need to either use FUNCTION NUMVAL (which I have not verified to work for what you are attempting), or handle the digits before and after the decimal point separately. |
|
Back to top |
|
|
GuyC
Senior Member
Joined: 11 Aug 2009 Posts: 1281 Location: Belgium
|
|
|
|
This :
MOVE WS-TEST-VARIABLE(6:5) TO WS-TTTTT
will try to convert the content to numeric before moving to ws-tttt, because ws-tttt is numeric
this:
MOVE WS-TEST-VARIABLE(6:5) TO WS-TTTTT (1:)
will move the content as alphanumeric, because ws-ttttt(1:) is alphanumeric. (length must be the same)
Redefining ws-ttttt as ws-tttttX pic X(5) , and moving to ws-ttttX will also work. |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
The problem lays in this move:
Quote: |
MOVE WS-TEST-VARIABLE(6:5) TO WS-TTTTT |
The group field WS-TEST contains "NAME 00560". As Robert says, the decimal point is implied.
When you look at it this way, then WS-TEST-VARIABLE(6:5) contains 00560, not 005.60 |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
You might try this to get the alignment you need:
MOVE WS-TEST-VARIABLE(6:5) TO WS-TTTTT(9:5) |
|
Back to top |
|
|
|