Numeric check on ZEROS in COBOL.
Numeric check on ZEROS in COBOL.
Hi,
Will checking a variable like
WS-VAR > 0 and
WS-VAR > ZEROS
will yield the same results? When WS-VAR is defined as PIC (X)?
Will checking a variable like
WS-VAR > 0 and
WS-VAR > ZEROS
will yield the same results? When WS-VAR is defined as PIC (X)?
- Robert Sample
- Global Moderator
- Posts: 1903
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: Numeric check on ZEROS in COBOL.
Do you not have a system you could test this on? The code takes a couple of minutes to write / compile / execute. ZERO / ZEROES is the same as the number 0 and the IF tests will compare the same. And the PIC X will not impact the results since a zoned decimal value could be PIC 9 or PIC X.
Furthermore, the Enterprise COBOL manuals are easily accessed on IBM's web site and the Language Reference manual will tell you what you want to know as well.
Furthermore, the Enterprise COBOL manuals are easily accessed on IBM's web site and the Language Reference manual will tell you what you want to know as well.
Re: Numeric check on ZEROS in COBOL.
Actually the real problem came in when I started looking at an existing program. The code is something like this:
WS-C1 is a penalty and will always be numeric, so if we keep initial value of WS-C1 as ZEROS, will not we can get rid of this AND in this IF and make it simple:
?
Code: Select all
05 WS-PENALTY.
10 WS-C1 PIC X(4) VALUE SPACES.
10 WS-C2 PIC X(2) VALUE '00'.
05 WS-PENALITY1 REDEFINES WS-PENALTY
PIC 9(6).
Code: Select all
.
.
.
CALL 'A-TABLE-ROUTINE' USING TBLE-VARIABLE
IF TBLE-RESP
MOVE VALUE-FROM-TABLE TO WS-C1
ELSE
MOVE 'Y' TO WS-ERROR-SW
MOVE '120-' TO WS-PARAGRAPH
MOVE 'BAD TABLE CALL ' TO WS-MSG-ACTION
MOVE WS-DB2-ERROR-MSG TO ERRMSGO
PERFORM 999-ABEND
END-IF
IF (WS-C1 IS NUMERIC) AND
(WS-PENALITY1 > 0)
CONTINUE
ELSE
MOVE 'Y' TO WS-ERROR-SW
MOVE -1 TO XYPDCFL
MOVE UNPR-ANUM-BRT-NMDT TO XYRECNFA
MOVE SPACES TO XYRECNFI
MOVE SPACES TO XYRECNFO
MOVE '*** PENALTY NOT SET ***'
TO ERRMSGO
GO TO 100-EXIT
END-IF
Code: Select all
IF (WS-C1 IS NUMERIC) AND
(WS-PENALITY1 > 0)
- Robert Sample
- Global Moderator
- Posts: 1903
- Joined: Fri Jun 28, 2013 1:22 am
- Location: Dubuque Iowa
Re: Numeric check on ZEROS in COBOL.
You REALLY need to learn COBOL rather than spouting off about things you have no clue about. In the code you posted, WS-C1 is PIC X(4) and starts the program with spaces in it; spaces are NOT numeric and hence your statement I quoted is TOTALLY BOGUS!WS-C1 is a penalty and will always be numeric
Furthermore, unless WS-PENALTY is part of TBLE-VARIABLE (and you did NOT post anything to indicate that this is the case), your change of the IF statement is HIGHLY likely to fail. You did not tell us how TBLE-RESP is set in the subprogram, so changing the IF statement could have all sorts of side effects, up to and including program ABENDS.
Re: Numeric check on ZEROS in COBOL.
I could not really put my point correctly. I was saying that "Business-users will always put a number in penalty field". In COBOL program, it has been defined as PIC X(4) years back for some reason but in reality it will always be number, a dollar amount, and will never be a text.Robert Sample wrote:You REALLY need to learn COBOL rather than spouting off about things you have no clue about. In the code you posted, WS-C1 is PIC X(4) and starts the program with spaces in it; spaces are NOT numeric and hence your statement I quoted is TOTALLY BOGUS!WS-C1 is a penalty and will always be numeric
For other points of your I shall research and get back.
Create an account or sign in to join the discussion
You need to be a member in order to post a reply
Create an account
Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute