View previous topic :: View next topic
|
Author |
Message |
rgupta71
Active User
Joined: 21 Jun 2009 Posts: 160 Location: Indore
|
|
|
|
Hi All,
I have a condition in program to check a variable S9(11)V9(2).If that variable is not numeric then it will give an error.
Code: |
IF VARIABLE NUMERIC
SUBTRACT
ELSE
MOVE ERROR
END-IF |
poster too slack to "Code"
When I am displaying that variable it is having zero value (13 zeros in this case ,when I do a hex on).
Cobol definition is
Code: |
05 BIG-AREA X(180).
05 TEMP-1 REDEFINES BIG-AREA.
10 A X(2).
10 B X(2).
10 C S9(03). COMP-3.
10 D S9(9)V9(2).
05 TEMP-4 REDEFINES BIG-AREA.
10 A4 X(2).
10 B4 S9(11)v9(2) COMP-3.
10 VARIABLE S9(11)v9(2) COMP-3. |
ditto
BIG-AREA is redefined several times.How can I determine that from where I am getting that value.Also when I am displaying it is showing as zero only but why it is not going inside the if condition.
Thanks. |
|
Back to top |
|
|
david jackson
New User
Joined: 24 Jan 2011 Posts: 22 Location: California
|
|
|
|
Which is it???
is it a S9(11)v9(2) as per your first line - or s9(11)v9(2) comp-3 as per your cut and paste ??
10 VARIABLE S9(11)v9(2) COMP-3.
This is a packed decimal field occupying 7 bytes. So should contain:
0000000
000000C
Not as you say"...When I am displaying that variable it is having zero value (13 zeros in this case ,when I do a hex on). ..."
If you are indeed expecting this in packed decimal - are you seeing the sign in the rightmost byte? |
|
Back to top |
|
|
rgupta71
Active User
Joined: 21 Jun 2009 Posts: 160 Location: Indore
|
|
|
|
Hi david,
It is not having sign in the end.
It is coming as
Code: |
0000000000000
FFFFFFFFFFFFF
0000000000000
|
|
|
Back to top |
|
|
daveporcelan
Active Member
Joined: 01 Dec 2006 Posts: 792 Location: Pennsylvania
|
|
|
|
What about the answer to his first question:
Quote: |
Which is it???
is it a S9(11)v9(2) as per your first line - or s9(11)v9(2) comp-3 as per your cut and paste ??
|
The data you show is not packed (sort of), why are two FF missing?
The definition in your redefines is packed data.
If that is what your progran is using, then the data you display is NOT NUMERIC.
You are showing conflicting and inaccurate information, yet you expect an exact answer. How well does that work? |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
Use the compile option MAP to generate a storage map. For each variable, it will tell you the offset and length of the variable (in Assembler format) and which base cell is being used (each file has its own base cell whereas all WORKING-STORAGE variables use a sequence of base cells starting at zero and going up as needed. With the map you can look at other variables that use the same offsets to determine exactly where your data is coming from.
AND BEFORE YOU DO ANYTHING ELSE, you need to click on the Manuals link at the top of the page, find the COBOL Language Reference manual, and read section 5.3.17 on USAGE clause and the internal formats for the various types of data. If you don't know how COBOL stores the data, you cannot write a valid IF NUMERIC test. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
In addition to learning how things are stored (i.e. internal formats) you also need to understand that when data is redefined as this has been posted, there has to be some way to know which format of the data is being worked with. . . |
|
Back to top |
|
|
rgupta71
Active User
Joined: 21 Jun 2009 Posts: 160 Location: Indore
|
|
|
|
THe variable PIC clause are defined correctly .
I copy-pasted the value from the mainframe only.I don't know how it missed 2 'F'.
I will look into internal storage of those variables now. |
|
Back to top |
|
|
daveporcelan
Active Member
Joined: 01 Dec 2006 Posts: 792 Location: Pennsylvania
|
|
|
|
Quote: |
THe variable PIC clause are defined correctly |
There you have it then.
Your definition is looking for packed data, but your data is not packed.
Hence it is NOT NUMERIC.
Your program is working correctly as it is coded. |
|
Back to top |
|
|
david jackson
New User
Joined: 24 Jan 2011 Posts: 22 Location: California
|
|
|
|
rgupta71 wrote: |
Hi david,
It is not having sign in the end.
It is coming as
Code: |
0000000000000
FFFFFFFFFFFFF
0000000000000
|
|
Then quite clearly this is 13 bytes character format and NOT 7 bytes of packed decimal.
You say your PIC clause as defined is correct. i.e. pic 9(11)v9(2) COMP-3.
Therefore PIC 9(11)v9(2) COMP-3 does NOT match the character format that you are testing for numeric so will fail. |
|
Back to top |
|
|
rgupta71
Active User
Joined: 21 Jun 2009 Posts: 160 Location: Indore
|
|
|
|
Thanks Everyone. |
|
Back to top |
|
|
|