View previous topic :: View next topic
|
Author |
Message |
chinnielr
New User
Joined: 11 Jul 2005 Posts: 87
|
|
|
|
Hi,
I have the requirement as below.
Input file has a field AMOUNT is PIC 9(13) V99.
AMOUNT can contain X'404040404040404040404040404040' which is spaces.
I need to check this condition in my COBOL program. If AMOUNT is spaces then I should not process the I/P record otherwise I should process it.
Could someone suggest me how to check this condition in the COBOL program.
Thanks in advance.
Chinni. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
AMOUNT is a numeric display field.
you could redefine the amount with an alpha pic and then compare for spaces.
OR
you could
Code: |
IF AMOUNT NUMERIC
THEN
IF AMOUNT > ZERO
|
|
|
Back to top |
|
|
chinnielr
New User
Joined: 11 Jul 2005 Posts: 87
|
|
|
|
Thanks for the reply Dick.
I have redefined the AMOUNT field to Alphanumeric one and handled it but still its not working.
Below is the piece of code.
05 WS-AMOUNT PIC 9(13) V99.
05 WS-AMOUNT-R REDEFINES WS-AMOUNT
PIC X(15).
MOVE AMOUNT TO WS-AMOUNT
IF WS-AMOUNT-R = SPACES
CONTINUE
ELSE
PROCESS THE RECORD
END-IF.
When I coded the above way. The value in WS-AMOUNT-R (redefined value) contains 0 and is failing in the condition even though the
The I/P file has the value X'404040404040404040404040404040'.
Can you please suggest a way to make it work!!
Thanks in advance.
Chinni. |
|
Back to top |
|
|
anil.csk
New User
Joined: 22 Oct 2007 Posts: 16 Location: Noida
|
|
|
|
do one things
use directly if amount is numeric
then process
else
exit from
the para.. |
|
Back to top |
|
|
chinnielr
New User
Joined: 11 Jul 2005 Posts: 87
|
|
|
|
Anil. I think you did not go through my requirement completely. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
chinnielr,
Anil hit the nail on the head. Your amount field is display, which means (especially if you are using COBOL 3) that a move to the numeric display type will treat spaces as zeros.
so, as Anil said, and I provided as a second case,
IF NUMERIC
THEN
IF > ZERO
THEN
PROCESS
You only want to use the field if it is NUMERIC and it is > ZERO.
but code it as I showed, NOT:
IF NUMERIC and > zero |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
Whenever a display-numeric field is move to another display-numeric field (without using reference modification), the COBOL compiler will ensure that the last byte of the receiving field has its ZONE Nibble set to a 4-Bit "F" (via an OI instruction under the covers after the MVC).
So, if the last byte in AMOUNT was a space (X'40'), it becomes a zero (X'F0') in the last byte WS-AMOUNT after the numeric-to-numeric move, causing your test to fail. All other bytes moved from AMOUNT to WS-AMOUNT remain unchanged.
However, if you'd like to avoid this, use reference modification -
Code: |
03 AMOUNT PIC 9(13)V99.
03 WS-AMOUNT PIC 9(13)V99.
MOVE AMOUNT (1:) TO WS-AMOUNT (1:).
|
After the above move, WS-AMOUNT will contain the exact value found in AMOUNT, such as all spaces, because a single MVC instruction is generated and the OI is bypassed.
Note that this type of move works best when both fields have the same length (this is why the length portion of the reference modification was not included). Otherwise, inclusion/adjustments would be necessary to the reference modification length(s), but that should not pose a real problem.
HTH....
Regards,
Bill |
|
Back to top |
|
|
|