Example 4: Sign Program
This example is adapted from W.B.KHAN, figure 5-10, page 114.
I called the input file: sign-in and the output file: sign-out.
I made appropriate changes to input negative values.
The new version is called sign.cbl. I placed this example,
and its input data file called sign.in in the following directory:
~jclevin/HTML/COURSE/COBOL/EXAMPLE
You may copy this example and the corresponding input data file
to your account, compile it and run it.
1. INPUT RECORD:
Using signed input data (+1200 instead of 01200), I declared the field
employee-rate-in (to accept negative values):
02 employee-rate-in pic S9(2)v99 sign is leading separate character.
2. OUTPUT RECORD:
I changed the declaration of the output record to include a sign for
the rate-out and gross-pay:
02 employee-rate-out pic -9(2).99.
02 gross-pay-out pic -9(4).99.
3. WORKING STORAGE:
I made the following changes to the working storage area:
02 special-value pic S9(5)v99 value -15.00 sign is leading separate character.
02 ws-gross-pay pic S9(5)v99 value 0 sign is leading separate character.
02 ws-overtime-pay pic S9(5)v99 value 0 sign is leading separate character.
02 ws-overtime-rate pic S9(5)v99 value 0 sign is leading separate character.
4. CHECKING FOR NEGATIVE VALUES:
I did the following checks for negative values (special-value is set
to the value: -15):
if employee-rate-in is negative
display ws-gross-pay.
if employee-rate-in is equal to special-value
display ws-gross-pay.
I guess the most important aspect here was to specify a sign as leading,
separate character, in declaring the data.
The next slides include:
* the program source code
* the input data file
* the program compile and execute commands
You can download them to your account by accessing these slides, then type:
* a backslash (\) to access the HTML document
* a (p) to save the file to your account.
Or you can copy the examples from the following directory:
~jclevin/HTML/COURSE/COBOL/EXAMPLE