View previous topic :: View next topic
|
Author |
Message |
suma_infy
New User
Joined: 03 Oct 2008 Posts: 25 Location: chennai
|
|
|
|
Hi,
I have following variable declaration -
01 WS-S.
03 WS-NUM PIC S9(2) COMP-3 VALUE ZEROES.
03 WS-CHAR PIC X(2) VALUE 'AB'.
i have run the below piece of code -
MOVE WS-CHAR TO WS-NUM
DISPLAY WS-NUM
ADD +1 TO WS-NUM
DISPLAY 'CHAR :' WS-CHAR
DISPLAY 'NUM1:' WS-NUM
STOP RUN
.
I'm expecting SOC7 to occur since i'm doing arithmetic operation with the non-numeric data.
But i got the following output -
12
CHAR :AB
NUM1:13
Please explain.
Thanks,
Suma |
|
Back to top |
|
|
Pandora-Box
Global Moderator
Joined: 07 Sep 2006 Posts: 1592 Location: Andromeda Galaxy
|
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Review the "POPS" (Principles of Operation) manual and find exactly what an Assembler "PACK" instruction does.
You'll then understand why "AB" becomes 12, add 1 and you end up with 13.
The following link should suffice -
publibfp.boulder.ibm.com/epubs/pdf/dz9zr006.pdf
Mr. Bill |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
suma_infy wrote: |
I'm expecting SOC7 to occur since i'm doing arithmetic operation with the non-numeric data. |
the above is not true.
only if a source has non/numerics.
and as you proved yourself, the numeric fields contain numeric data. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
If you use the SEARCH function on this forum, and use airthmetic non-numeric as your search values, and restrict only to the COBOL forum -- you get 227 returned hits. This topic has been discussed many, many, many times before. Your lack of knowledge about COBOL variables and internal formats indicates you need to spend time reading the COBOL Language Reference and Programming Guide manuals (link at the top of this page). |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
suma_infy wrote: |
Hi,
I have following variable declaration -
01 WS-S.
03 WS-NUM PIC S9(2) COMP-3 VALUE ZEROES.
03 WS-CHAR PIC X(2) VALUE 'AB'.
i have run the below piece of code -
MOVE WS-CHAR TO WS-NUM
DISPLAY WS-NUM
ADD +1 TO WS-NUM
DISPLAY 'CHAR :' WS-CHAR
DISPLAY 'NUM1:' WS-NUM
STOP RUN
.
I'm expecting SOC7 to occur since i'm doing arithmetic operation with the non-numeric data.
But i got the following output -
12
CHAR :AB
NUM1:13
Please explain.
Thanks,
Suma |
Why would you want to move PIC XX to COMP-3 PIC S99? I've never felt the need to do that.
If I had a PIC XX that should contain a numeric which I want to MOVE to a numeric field, I'd redefine it as PIC 99, test it for NUMERIC and do the move with that.
If you don't do something to deal with it properly, using the NUMERIC test, you will potentially give yourself problems which, at best, will give a S0C7, but at worst will just infect your system with rubbish data which, after you've done the MOVE, looks just like any other number and which may become difficult to track back to the original value for problem determination.
I hope nobody coded anything like that thinking "if it isn't numeric, we'll get a S0C7, so it's OK". If they did, you could well have a long search trying to identify the rubbish.
If you have to embark on the search, it is important to know the implications for your data of the compiler options NUMPROC(NOPFD) and NUMPROC(PFD) (or NUMPROC(MIG) in less-likely cases). |
|
Back to top |
|
|
|