View previous topic :: View next topic
|
Author |
Message |
Debasis Misra Warnings : 1 New User
Joined: 16 Sep 2008 Posts: 72 Location: Bangalore
|
|
|
|
This is the code:
-------------------------
01 B PIC X(7).
01 WS-VAR.
05 D PIC S9(9)V9(2) USAGE COMP-3.
Move B to D.
INSPECT WS-VAR
REPLACING ALL LOW-VALUES BY SPACES.
---------------------------
Now if B = 0001200
then D = 40400120400
but the right value of D should be = 00000120000
Here I cant change the declaration of D.
How to handle this problem? |
|
Back to top |
|
|
shankar.v
Active User
Joined: 25 Jun 2007 Posts: 196 Location: Bangalore
|
|
|
|
Debasis Misra,
You can use NUMVAL function as follows:
COMPUTE D = FUNCTION NUMVAL ( B )
Reference : NUMVAL
Thanks,
Shankar |
|
Back to top |
|
|
Debasis Misra Warnings : 1 New User
Joined: 16 Sep 2008 Posts: 72 Location: Bangalore
|
|
|
|
Sorry its not working,
the D = D = 40400120400 still.
Help!!! |
|
Back to top |
|
|
shankar.v
Active User
Joined: 25 Jun 2007 Posts: 196 Location: Bangalore
|
|
|
|
Debasis Misra,
Please check with the below code. NUMVAL result matches expected.
Code: |
IDENTIFICATION DIVISION.
PROGRAM-ID. NV.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 B PIC X(7).
01 WS-VAR.
05 D PIC S9(9)V9(2) USAGE COMP-3.
PROCEDURE DIVISION.
MOVE '0001200' TO B
COMPUTE
D = FUNCTION NUMVAL ( B )
END-COMPUTE
DISPLAY D
GOBACK.
|
Output:
Thanks,
Shankar |
|
Back to top |
|
|
rajulan
New User
Joined: 11 Jan 2008 Posts: 66 Location: India
|
|
|
|
Hi shankar.v
I have executed the below code. I has been executed successfully.
May i know why we are bringing here NUMVAL?
Code: |
IDENTIFICATION DIVISION.
PROGRAM-ID. NUMVAL.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 A PIC X(7).
01 WS-VAR.
05 B PIC S9(9)V9(2) USAGE COMP-3.
PROCEDURE DIVISION.
DISPLAY 'ENTER THE VALUE FOR A'.
ACCEPT A.
MOVE A TO B.
DISPLAY B.
STOP RUN.
OUTPUT:
|
ENTER THE VALUE FOR A
00000120000 |
|
Back to top |
|
|
shankar.v
Active User
Joined: 25 Jun 2007 Posts: 196 Location: Bangalore
|
|
|
|
rajulan,
Quote: |
The NUMVAL function returns the numeric value represented by the alphanumeric character string or national character string specified as the argument. The function removes any leading or trailing spaces in the string to produce a numeric value. |
Refer: NUMVAL
Thanks,
Shankar |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
Debasis Misra wrote: |
Sorry its not working,
the D = D = 40400120400 still.
Help!!! |
The FUNCTION NUMVAL replaces both the MOVE and the INSPECT. |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Debasis Misra wrote: |
This is the code:
-------------------------
01 B PIC X(7).
01 WS-VAR.
05 D PIC S9(9)V9(2) USAGE COMP-3.
Move B to D.
INSPECT WS-VAR
REPLACING ALL LOW-VALUES BY SPACES.
---------------------------
Now if B = 0001200
then D = 40400120400
but the right value of D should be = 00000120000
Here I cant change the declaration of D.
How to handle this problem? |
LOW VALUES are valid in a comp-3 field, it would just be two digits of zero. Tell us what are you trying to do? |
|
Back to top |
|
|
Debasis Misra Warnings : 1 New User
Joined: 16 Sep 2008 Posts: 72 Location: Bangalore
|
|
|
|
Two things are existing production code.
1. Declaration of 'D'
2. Inspect clause. because in actual program its applicable for many of other variables.
So, my doubt is that can I do some intermediate calculation before populating the "D" variable? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Quote: |
Two things are existing production code. |
Suggest you do what is appropriate for this particular situation and leave the "other vairables" out of this.
You should not use a single MOVE a value of x'F0F0F0F1F2F0F0' to a comp-3 field - and there is no reason that you should. . .
Suggest you make sure you validate the value in the pic x field or there will be abends later when the input is not numeric. . . |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
Debasis Misra wrote: |
2. Inspect clause. because in actual program its applicable for many of other variables. |
STOP!
Looking for low values in a comp3 data item will see two zeros in a row in the same byte as low values.
pic s9(7) value 1000 is x'F0F0F0F1F0F0C0'
pic s9(7) comp3 value 1000 is x'0001000C'
Code: |
00000
12345
-----
00000
0100C |
where the zero over zero (bytes 1,3 & 4) is low values...... |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
Debasis Misra wrote: |
This is the code:
-------------------------
01 B PIC X(7).
01 WS-VAR.
05 D PIC S9(9)V9(2) USAGE COMP-3.
Move B to D.
INSPECT WS-VAR
REPLACING ALL LOW-VALUES BY SPACES.
---------------------------
Now if B = 0001200
then D = 40400120400
but the right value of D should be = 00000120000
Here I cant change the declaration of D.
How to handle this problem? |
You've got the answer to your question: replace the 2 lines (MOVE and INSPECT) by a simple COMPUTE.
Why is there still a problem ?????
NB. The INSPECT statement just replaces correct values by garbage. If you leave it, it will never work, that's as easy as that! |
|
Back to top |
|
|
|