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

Checking for SPACES - Help required


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
chinnielr

New User


Joined: 11 Jul 2005
Posts: 87

PostPosted: Wed Sep 10, 2008 1:51 pm
Reply with quote

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

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Sep 10, 2008 2:07 pm
Reply with quote

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

New User


Joined: 11 Jul 2005
Posts: 87

PostPosted: Wed Sep 10, 2008 2:33 pm
Reply with quote

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

New User


Joined: 22 Oct 2007
Posts: 16
Location: Noida

PostPosted: Wed Sep 10, 2008 3:15 pm
Reply with quote

do one things

use directly if amount is numeric

then process

else
exit from
the para..
Back to top
View user's profile Send private message
chinnielr

New User


Joined: 11 Jul 2005
Posts: 87

PostPosted: Wed Sep 10, 2008 3:31 pm
Reply with quote

Anil. I think you did not go through my requirement completely.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Wed Sep 10, 2008 3:36 pm
Reply with quote

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

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Wed Sep 10, 2008 6:42 pm
Reply with quote

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
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 leading spaces can be removed in trai... DFSORT/ICETOOL 1
No new posts Cobol program with sequence number ra... COBOL Programming 5
No new posts To Remove spaces (which is in hex for... JCL & VSAM 10
No new posts How to remove spaces in between. SYNCSORT 12
No new posts REXX - Dataset checking in a do forev... CLIST & REXX 6
Search our Forums:

Back to Top