IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Inspect Low values : Comp3 variable


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Debasis Misra
Warnings : 1

New User


Joined: 16 Sep 2008
Posts: 72
Location: Bangalore

PostPosted: Mon Feb 16, 2009 11:19 am
Reply with quote

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
View user's profile Send private message
shankar.v

Active User


Joined: 25 Jun 2007
Posts: 196
Location: Bangalore

PostPosted: Mon Feb 16, 2009 11:41 am
Reply with quote

Debasis Misra,

You can use NUMVAL function as follows:

COMPUTE D = FUNCTION NUMVAL ( B )

Reference : NUMVAL

Thanks,
Shankar
Back to top
View user's profile Send private message
Debasis Misra
Warnings : 1

New User


Joined: 16 Sep 2008
Posts: 72
Location: Bangalore

PostPosted: Mon Feb 16, 2009 2:13 pm
Reply with quote

Sorry its not working,
the D = D = 40400120400 still.
Help!!!
Back to top
View user's profile Send private message
shankar.v

Active User


Joined: 25 Jun 2007
Posts: 196
Location: Bangalore

PostPosted: Mon Feb 16, 2009 2:32 pm
Reply with quote

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:
Code:
00000120000

Thanks,
Shankar
Back to top
View user's profile Send private message
rajulan

New User


Joined: 11 Jan 2008
Posts: 66
Location: India

PostPosted: Mon Feb 16, 2009 3:00 pm
Reply with quote

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
View user's profile Send private message
shankar.v

Active User


Joined: 25 Jun 2007
Posts: 196
Location: Bangalore

PostPosted: Mon Feb 16, 2009 3:27 pm
Reply with quote

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
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Mon Feb 16, 2009 4:06 pm
Reply with quote

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
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Mon Feb 16, 2009 5:36 pm
Reply with quote

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
View user's profile Send private message
Debasis Misra
Warnings : 1

New User


Joined: 16 Sep 2008
Posts: 72
Location: Bangalore

PostPosted: Mon Feb 16, 2009 10:33 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Feb 17, 2009 1:57 am
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Feb 17, 2009 2:09 am
Reply with quote

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
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Tue Feb 17, 2009 9:19 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts INCLUDE OMIT COND for Multiple values... DFSORT/ICETOOL 5
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Null values are considered in Total c... DFSORT/ICETOOL 6
No new posts Variable Output file name DFSORT/ICETOOL 8
Search our Forums:

Back to Top