Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Checking for SPACES - Help required

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Checking for SPACES - Help required
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    Post subject:
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    Post subject:
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    Post subject: Reply to: Checking for SPACES - Help required
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    Post subject:
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    Post subject:
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: 2502
Location: Atlanta, Georgia, USA

PostPosted: Wed Sep 10, 2008 6:42 pm    Post subject: Re: Checking for SPACES - Help required
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    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 To trim spaces in a pipe delimited da... Nish84 COBOL Programming 16 Mon Oct 10, 2016 1:54 pm
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am
No new posts Syncsort - NULL in Integer field chec... nartcr SYNCSORT 4 Thu Oct 06, 2016 6:47 am
No new posts Removing Extra Spaces in a comma sepa... Puspojit DFSORT/ICETOOL 3 Tue Sep 13, 2016 7:46 am
No new posts Reasonable way of checking wildcards ... sergeyken CLIST & REXX 5 Wed Sep 07, 2016 8:43 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us