Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Inspect Low values : Comp3 variable

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Inspect Low values : Comp3 variable
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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: 1250
Location: Israel

PostPosted: Mon Feb 16, 2009 4:06 pm    Post subject:
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    Post subject: Re: Inspect Low values : Comp3 variable
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    Post subject:
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

Site Director


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

PostPosted: Tue Feb 17, 2009 1:57 am    Post subject:
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: 3158
Location: Tucson AZ

PostPosted: Tue Feb 17, 2009 2:09 am    Post subject:
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: 1250
Location: Israel

PostPosted: Tue Feb 17, 2009 9:19 pm    Post subject: Re: Inspect Low values : Comp3 variable
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Move from Comp3 variable to Edited Va... Revathy.nair0485 COBOL Programming 7 Fri Nov 03, 2017 3:30 pm
This topic is locked: you cannot edit posts or make replies. Can a alphanumeric data be moved to a... nico_neoz COBOL Programming 10 Mon Oct 30, 2017 8:28 am
No new posts Extend the decimal values in DIVISION Balaryan DFSORT/ICETOOL 3 Thu Oct 05, 2017 4:05 pm
No new posts Working with hex values in Filemanage... Emile Straker IBM Tools 0 Tue Sep 12, 2017 1:42 am
No new posts DB2 NULL Values display V S Amarendra Reddy DB2 3 Thu Sep 07, 2017 6:59 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us