Page 1 of 1
Numeric check on ZEROS in COBOL.
Posted: Wed Sep 20, 2017 10:39 pm
by KavalJeet
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)?
Re: Numeric check on ZEROS in COBOL.
Posted: Wed Sep 20, 2017 11:53 pm
by Robert Sample
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.
Re: Numeric check on ZEROS in COBOL.
Posted: Thu Sep 21, 2017 11:13 am
by KavalJeet
Actually the real problem came in when I started looking at an existing program. The code is something like this:
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
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
IF (WS-C1 IS NUMERIC) AND
(WS-PENALITY1 > 0)
?
Re: Numeric check on ZEROS in COBOL.
Posted: Thu Sep 21, 2017 5:17 pm
by Robert Sample
WS-C1 is a penalty and will always be numeric
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!
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.
Posted: Fri Sep 22, 2017 9:15 am
by KavalJeet
Robert Sample wrote: WS-C1 is a penalty and will always be numeric
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!
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.
For other points of your I shall research and get back.