Could you reference a column in DECLARATIVES section when the column is used with SUM clause in COBOL REPORT WRITER Module? - cobol

Aside from the specific platform and the compiler, suppose you have this defined in a COBOL program using Report Writer Module:
01 CF-MM TYPE CONTROL FOOTING WS-MM.
02 LINE PLUS 1.
03 COLUMN 1 VALUE "* CF MONTH: ".
03 COLUMN PLUS 1 PIC 99 SOURCE WS-MM.
03 S-MM COLUMN PLUS 5 PIC S9(4)V99 SUM WS-TUTION-PAY.
03 VAL-NN COLUMN PLUS 5 PIC S9(4)V99 SOURCE S-MM.
<...>
PROCEDURE DIVISION.
DECLARATIVES.
SEC2 SECTION.
USE BEFORE REPORTING
CF-MM.
DISPLAY "SUM MM LEVEL:" S-MM
.
Furthermore, suppose that the program reported 3 lines where SUM WS-TUTION-PAY resulted in 126.
What would be the value resulting from the statement in SEC2 SECTION that displays S-MM value? I guess it should be 126 but I am getting ZERO displayed. This maybe because the value 126 was not yet moved to S-MM, but I am not sure.
What is the value that "should" be displayed in the declaratives section for S-MM

Q: Could you reference a column in DECLARATIVES section when the column is used with SUM clause in COBOL REPORT WRITER Module?
03 S-MM COLUMN PLUS 5 PIC S9(4)V99 SUM WS-TUTION-PAY.
S-MM is a data-name format of the entry-name clause. Quoting from the 2002 COBOL standard, Report group description entry, 13.13.2 Syntax rules:
7) The data-name format of the entry-name clause shall be specified when the data-name is referenced in a GENERATE statement, a USE BEFORE REPORTING statement, as a qualifier for a SUM counter, in the UPON phrase of the SUM clause, or as an operand in a SUM clause. The data-name shall not be referenced in any other way.
Given that S-MM qualifies, it may be referenced "as a qualifier for a SUM counter".
[The COBOL 74 and 85 standards stated, "Data-name-1 is optional but may be specified in any entry. Data-name-1, however, may be referenced only if the entry defines a sum counter."]
The compiler I used for the following code is Micro Focus COBOL 85.
Code:
program-id. rw-test.
environment division.
input-output section.
select report-file assign "rpt.txt"
organization line sequential.
data division.
fd report-file
report is report-1.
working-storage section.
01 n comp pic 99 value 0.
01 test-table.
02 test-data.
03 pic 9999 value 1001.
03 pic 9999 value 1002.
03 pic 9999 value 1003.
03 pic 9999 value 2004.
03 pic 9999 value 2005.
03 pic 9999 value 2006.
02 test-entry redefines test-data pic 9999 occurs 6.
01 report-entry.
03 test-group pic 9.
03 test-value pic 999.
report section.
rd report-1
control is test-group.
01 rw-detail type de.
02 line plus 1.
03 grp column 1 pic 9 source test-group.
03 val column 4 pic zz9 source test-value.
01 rw-foot type cf test-group.
02 line plus 1.
03 column 1 pic x(6) value "- ---".
02 line plus 1.
03 column 1 pic 9 source test-group.
03 s-mm column 4 pic zz9 *> s.mm defined
sum test-value
reset test-group.
02 line plus 1 pic x value space.
procedure division.
declaratives.
decl-rpt section.
use before reporting rw-foot.
display s-mm. *> s.mm referenced
end declaratives.
main-line section.
open output report-file.
initiate report-1
perform varying n from 1 by 1
until n > 6
move test-entry (n) to report-entry
generate rw-detail
end-perform
terminate report-1
close report-file
stop run.
end program rw-test.
Report:
1 1
1 2
1 3
- ---
1 6
2 4
2 5
2 6
- ---
2 15
Display:
006
015

Related

Decimal value in an input file if the user inputs to it in COBOL

Another COBOL question here again. I have been playing around with COBOL and the problem is, I have to input a decimal value in the input file. So the output in the input file should look something like this:
2019-00042Alexander Bell 1.501.752.25
...
The numbers are grades in a quiz. 1.00 to 5.00.
So I'm assuming in the print line, which is named as INF-PRINT-LINE in my code, I have to declare it as:
01 INF-PRINT-LINE.
02 SNO-IN PIC X(10).
02 SNAME-IN PIC X(25).
02 Q1-IN PIC 9.9(2).
02 Q2-IN PIC 9.9(2).
02 Q3-IN PIC 9.9(2).
Now on the WORKING-STORAGE SECTION I have declared three separate variables (STUD-QX-IN) so that I'll move it later on to the INF-PRINT-LINE variables (QX-IN) which can be seen here:
01 STUD-Q1-IN PIC 999.
01 STUD-Q2-IN PIC 999.
01 STUD-Q3-IN PIC 999.
Now, when this program is executed, I'd get a chance to see what's the value of STUD-QX-IN and QX-IN because of the DISPLAY line that will be shown on Column 45 so the program should look now something like this in the command line:
ENTER STUDENT NUMBER: 2019-00042
ENTER STUDENT NAME: Alexander Bell
ENTER QUIZ 1: 150 150 0.00
ENTER QUIZ 2: 175 175 5.00
ENTER QUIZ 3: 225 225 5.00
ENTER ANOTHER STUDENT(Y/N)
Now as you can see, what has passed down into the QX-IN variable is just the last digit of STUD-QX-IN, and the input file now would like something like this instead of what I was thinking about:
2019-00042Alexander Bell 0.005.005.00
...
What should I declare on the STUD-QX-IN so that I can pass down the correct value to QX-IN? I did try PIC 9V99 on STUD-QX-IN but it also doesn't work. Is the QX-IN PIC clause value were wrong after all?
Here's the full code:
* -----------------------------
IDENTIFICATION DIVISION.
PROGRAM-ID. exercise.
* -----------------------------
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
* INPUT
* OUTPUT
SELECT INF-STUD-GRADES ASSIGN TO "STUDENTGRADES.DAT".
DATA DIVISION.
FILE SECTION.
FD INF-STUD-GRADES.
01 INF-PRINT-REC PIC X(80).
WORKING-STORAGE SECTION.
*> INPUT THE ANSWER IN THIS SECTION
01 INF-PRINT-LINE.
02 SNO-IN PIC X(10).
02 SNAME-IN PIC X(25).
02 Q1-IN PIC 9.9(2).
02 Q2-IN PIC 9.9(2).
02 Q3-IN PIC 9.9(2).
01 ANS PIC X VALUE 'Y'.
01 L PIC 9.
01 STUD-NO-IN PIC X(10).
01 STUD-NAME-IN PIC X(25).
01 STUD-Q1-IN PIC 999.
01 STUD-Q2-IN PIC 999.
01 STUD-Q3-IN PIC 999.
SCREEN SECTION.
01 BSCRN.
02 BLANK SCREEN.
PROCEDURE DIVISION.
OPEN OUTPUT INF-STUD-GRADES.
PERFORM INPUT-GRADES-RTN UNTIL ANS = 'N' OR ANS = 'n'.
PERFORM CLOSE-INPUT-GRADES-RTN.
PERFORM FINAL-CLOSE-RTN.
INPUT-GRADES-RTN.
DISPLAY BSCRN.
MOVE 4 TO L.
DISPLAY "ENTER STUDENT NUMBER: " LINE L COLUMN 5.
ACCEPT STUD-NO-IN LINE L COLUMN 35.
MOVE STUD-NO-IN TO SNO-IN.
ADD 1 TO L.
DISPLAY "ENTER STUDENT NAME: " LINE L COLUMN 5.
ACCEPT STUD-NAME-IN LINE L COLUMN 35.
MOVE STUD-NAME-IN TO SNAME-IN.
ADD 1 TO L.
DISPLAY "ENTER QUIZ 1: " LINE L COLUMN 5.
ACCEPT STUD-Q1-IN LINE L COLUMN 35.
DISPLAY STUD-Q1-IN LINE L COLUMN 45.
MOVE STUD-Q1-IN TO Q1-IN.
DISPLAY Q1-IN LINE L COLUMN 55.
ADD 1 TO L.
DISPLAY "ENTER QUIZ 2: " LINE L COLUMN 5.
ACCEPT STUD-Q2-IN LINE L COLUMN 35.
DISPLAY STUD-Q2-IN LINE L COLUMN 45.
MOVE STUD-Q2-IN TO Q2-IN.
DISPLAY Q2-IN LINE L COLUMN 55.
ADD 1 TO L.
DISPLAY "ENTER QUIZ 3: " LINE L COLUMN 5.
ACCEPT STUD-Q3-IN LINE L COLUMN 35.
DISPLAY STUD-Q3-IN LINE L COLUMN 45.
MOVE STUD-Q3-IN TO Q3-IN.
DISPLAY Q3-IN LINE L COLUMN 55.
ADD 2 TO L.
WRITE INF-PRINT-REC FROM INF-PRINT-LINE BEFORE 1 LINE.
DISPLAY "ENTER ANOTHER STUDENT(Y/N)" LINE L COLUMN 30.
ACCEPT ANS.
CLOSE-INPUT-GRADES-RTN.
CLOSE INF-STUD-GRADES.
FINAL-CLOSE-RTN.
STOP RUN.
You need to move fields defined as 9v99 to the output fields. The v means assumed decimal place.
What you can do is
01 work fields
03 STUD-Q1-IN PIC 999.
03 STUD-Q1-IN-V redefines STUD-Q1-IN PIC 9v99.
03 STUD-Q2-IN PIC 999.
03 STUD-Q2-IN-V redefines STUD-Q2-IN PIC 9v99.
03 STUD-Q3-IN PIC 999.
03 STUD-Q3-IN-V redefines STUD-Q3-IN PIC 9v99.
You would then do
MOVE STUD-Q1-IN-V TO Q1-IN.
You could also do
compute Q1-IN = STUD-Q1-IN / 100
end-compute
Redefines keyword
The Redefines keyword lets you give a different definition to a field
So if you do
Move 123 to STUD-Q1-IN.
Then
STUD-Q1-IN = 123
STUD-Q1-IN-V = 1.23

I have written a Cobol Report Writer program, but I cannot compile it

I wrote this after I read that Cobol supports Report Writer, only to discover afterwards the version of z/OS we have here at school doesn't actually support it.
I'm wondering if there is a way for this to easily be converted to basic Cobol or if there is any kind of compiler i might find and use.
Thanks for any help you can offer.
Having seen the REPORT SECTION; yes, it may be easily converted.
For the conversion, a choice needs to be made between using IBM POSITIONING or standard COBOL ADVANCING in the WRITE statement; and END-OF-PAGE exception or writing your own code for moving to the next page.
I adjusted some spacing and made a few corrections to the original. I generated 120 records for test data, all random numbers.
REPORT SECTION.
RD PRODUCT-REPORT
PAGE LIMIT 59
HEADING 1
FIRST DETAIL 6
LAST DETAIL 59.
01 HEAD1 TYPE PH.
03 LINE 1.
05 COLUMN 1 PIC X(5) VALUE 'DATE:'.
05 COLUMN 8 PIC 9(2) SOURCE WS-CD-MONTH.
05 COLUMN 10 PIC X VALUE '/'.
05 COLUMN 11 PIC 9(2) SOURCE WS-CD-DAY.
05 COLUMN 13 PIC X VALUE '/'.
05 COLUMN 14 PIC 9(2) SOURCE WS-CD-YEAR.
05 COLUMN 33 PIC X(19) VALUE 'MASTER PRODUCT LIST'.
05 COLUMN 72 PIC X(5) VALUE 'PAGE:'.
05 COLUMN 77 PIC ZZ9 SOURCE PAGE-COUNTER.
03 LINE 2.
05 COLUMN 1 PIC X(5) VALUE 'TIME:'.
05 COLUMN 9 PIC 9(2) SOURCE WS-CD-HOURS.
05 COLUMN 11 PIC X VALUE ':'.
05 COLUMN 12 PIC 9(2) SOURCE WS-CD-MINUTES.
05 COLUMN 72 PIC X(8) VALUE 'PRODLIST'.
03 LINE 4.
05 COLUMN 1 PIC X(5) VALUE 'CODE:'.
05 COLUMN 8 PIC X(5) VALUE 'TYPE:'.
05 COLUMN 18 PIC X(12) VALUE 'DESCRIPTION:'.
05 COLUMN 66 PIC X(6) VALUE 'PRICE:'.
03 LINE 5.
05 COLUMN 1 PIC X(80) VALUE ALL '='.
01 PRODLINE TYPE DE.
03 LINE PLUS 1.
05 COLUMN 1 PIC X(5) SOURCE PRODCODE.
05 COLUMN 8 PIC X(8) SOURCE PRODTYPE.
05 COLUMN 18 PIC X(32) SOURCE PRODDESC.
05 COLUMN 66 PIC $ZZZ,ZZZ,ZZ9 SOURCE PRODCOST.
Ran the program and got this partial output.
DATE: 11/08/18 MASTER PRODUCT LIST PAGE: 1
TIME: 15:54 PRODLIST
CODE: TYPE: DESCRIPTION: PRICE:
================================================================================
47638 54784935 48116892 $ 1,461,160
26450 06251370 81421270 $ 7,765,877
The IBM COBOL family does provide Report Writer. All you need is a compiler "plug-in". Look for product 5798-DYR COBOL Report writer Precompiler. It works seamlessly. No need to convert any code. Ask for free on-line user manual.

What is an easy way to get the ASCII value of a character in Cobol

We have to find more than one way to get the ascii value of a character.
On top of that we also need to get the sum of all the characters's ascii values.
I currently have the below and works alright for the first section where you need individual values
.
I just need to know if there is an easier way or a function to do this in Cobol?
DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.
01 WS-COUNTERS.
03 WS-COUNTER PIC 9(05).
03 WS-INPUT PIC X(01).
03 WS-DISPLAY PIC 9(03).
01 W1-ARRAY.
03 ALPHABETIC-CHARS OCCURS 26 TIMES PIC X.
01 W3-ARRAY.
03 NUMERIC-CHARS OCCURS 26 TIMES PIC X.
PROCEDURE DIVISION.
A000-MAIN SECTION.
BEGIN.
PERFORM B000-INITIALIZE.
PERFORM C000-PROCESS UNTIL WS-COUNTER > 26.
PERFORM D000-END.
A099-EXIT.
STOP RUN.
B000-INITIALIZE SECTION.
ACCEPT WS-INPUT.
MOVE "ABCDEFGHIJKLMNOPQRSTUVWXYZ" TO W1-ARRAY.
MOVE "01234567890000000000000000" TO W3-ARRAY.
MOVE 1 TO WS-COUNTER.
MOVE 0 TO WS-DISPLAY.
B099-EXIT.
EXIT.
C000-PROCESS SECTION.
C001-BEGIN.
IF WS-INPUT IS NUMERIC
IF NUMERIC-CHARS(WS-COUNTER) = WS-INPUT
COMPUTE WS-DISPLAY = WS-COUNTER + 48 - 1
END-IF
ELSE
IF ALPHABETIC-CHARS(WS-COUNTER) = WS-INPUT
COMPUTE WS-DISPLAY = WS-COUNTER + 65 - 1
END-IF
END-IF.
ADD 1 TO WS-COUNTER.
C099-EXIT.
EXIT.
Have a look at FUNCTION ORD and keep in mind that you will get the ordinal number in the program's collating sequence (which may be EBCDIC or not the full ASCII).
As this function was introduced in the COBOL85 standard it should be available in most compilers (your question misses the compiler/machine you use).

Is it possible to display multiple screens in a loop in cobol?

So I'm trying to make a program in OpenCobolIDE that uses the SCREEN SECTION feature in COBOL to create a menu where the user chooses whether he wants to input data or display it.
This data is being recorded in a sequential .txt file. The writing process works fine so I don't add the code of this part here. The problem is in the reading process. I wanted the program to display multiple times the DISPLAY-SCREEN in a PERFORM loop showing all the records in my file but this is not working. I thought that by removing the BLANK SCREEN from my DISPLAY-SCREEN it would work the way I wanted but all that happens is that the program shows the DISPLAY-SCREEN a single time and it doesn't even display any records. What could be the problem? Here is the code:
IDENTIFICATION DIVISION.
PROGRAM-ID.PGM001.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT MYFILE ASSIGN TO "DATA.TXT"
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD MYFILE.
01 FS-TB.
02 FS-ID PIC X(03).
02 FS-NAME PIC A(15).
02 FS-PHONE PIC X(09).
WORKING-STORAGE SECTION.
01 WS-TB.
02 WS-ID PIC X(03).
02 WS-NAME PIC A(15).
02 WS-PHONE PIC X(09).
01 WS-EOF PIC A(01) VALUE "N".
01 WS-COUNT PIC 9(01) VALUE ZERO.
01 WS-OP PIC 9(01).
SCREEN SECTION.
01 MENU-SCREEN.
02 BLANK SCREEN.
02 LINE 1 COL 1 VALUE "------------------------------------".
02 LINE 2 COL 1 VALUE "- MENU -".
02 LINE 3 COL 1 VALUE "------------------------------------".
02 LINE 4 COL 1 VALUE "- (1).REGISTER -".
02 LINE 5 COL 1 VALUE "- (2).DISPLAY -".
02 LINE 6 COL 1 VALUE "- (3).EXIT -".
02 LINE 7 COL 1 VALUE "- -".
02 LINE 8 COL 1 VALUE " OPTION:( ) -".
02 LINE 9 COL 1 VALUE "------------------------------------".
02 LINE 8 COL 20 PIC 9(01) TO WS-OP.
01 DISPLAY-SCREEN.
02 LINE 1 COL 1 VALUE "------------------------------------".
02 LINE 2 COL 1 VALUE "- DISPLAY -".
02 LINE 3 COL 1 VALUE "------------------------------------".
02 LINE 4 COL 1 VALUE "-(1).ID : -".
02 LINE 4 COL 18 PIC X(03) FROM WS-ID.
02 LINE 5 COL 1 VALUE "-(2).NAME : -".
02 LINE 5 COL 18 PIC A(15) FROM WS-NAME.
02 LINE 6 COL 1 VALUE "-(3).PHONE : -".
02 LINE 6 COL 18 PIC X(09) FROM WS-PHONE.
02 LINE 7 COL 1 VALUE "------------------------------------".
PROCEDURE DIVISION.
A-100.
DISPLAY MENU-SCREEN.
ACCEPT MENU-SCREEN.
EVALUATE WS-OP
WHEN 1
GO TO A-200
WHEN 2
GO TO A-300
WHEN 3
STOP RUN
WHEN OTHER
GO TO A-100
END-EVALUATE.
A-200.
A-300.
OPEN INPUT MYFILE
PERFORM UNTIL WS-EOF = "Y"
READ MYFILE INTO WS-TB
AT END MOVE "Y" TO WS-EOF
NOT AT END DISPLAY DISPLAY-SCREEN
END-READ
END-PERFORM
CLOSE MYFILE.
STOP RUN.
END PROGRAM PGM001.
As Bill pointed out already: The PERFORM and DISPLAY is too fast.
To see every record you´d need to add an ACCEPT after the DISPLAY, I guess ACCEPT OMITTED will work, if not add a dummy var and ACCEPT this.
You seem to not want to stop the program during the PERFORM then you may add an ACCEPT DUMMY at the program's end (always useful if you use extended DISPLAY/ACCEPT). But you would only get the last item displayed.
Depending on your needs a CALL 'CBL_OC_NANOSLEEP' USING 500000000 (wait one-half second) or CALL 'C$SLEEP' USING 1 after the DISPLAY DISPLAY-SCREEN may be the result you want.
But likely the best option would be ACCEPT dummy WITH TIMEOUT time (if you press ENTER it goes directly to the next DISPLAY if you don't it will wait the specified time before doing the next DISPLAY.

88 level on a particular digit in a numeric array?

I was working on a brute-force implementation of this RosettaCode challenge. I wanted to be able to handle numbers bigger than USAGE BINARY-DOUBLE so I wrote a dead simple bignum routine for adding.
If I want to limit myself to a certain number of iterations and that number is greater than 9(18) then that's tricky. So I hit upon the idea of an 88 on a particular element of the array, thus the code below.
03 DIGITS1 OCCURS 40 TIMES PIC 9.
03 FILLER REDEFINES DIGITS1.
05 FILLER pic 9999999999.
05 FILLER pic 999999999.
05 filler pic 9.
88 EOR value 1.
05 filler pic 9999999999.
05 filler pic 9999999999.
So I'm still wondering if this is the only way to go or is there some other way of handling when I get to 10^20.
This is the full "solution". It's a mess but it almost working.
identification division.
program-id. Program1.
data division.
working-storage section.
01 COUNTER.
03 DIGITS1 OCCURS 40 TIMES PIC 9.
03 FILLER REDEFINES DIGITS1.
05 filler pic 9999999999.
05 FILLER pic 9999999999.
05 filler pic 9999999999.
05 filler pic 999.
05 filler pic 9.
88 EOR value 1.
05 filler pic 999999.
01 INCREMENTOR.
03 DIGITS1 OCCURS 40 TIMES PIC 9.
01 ACCUMULATOR.
03 DIGITS1 OCCURS 40 TIMES PIC 9.
01 IN-NUMBER usage binary-double unsigned.
01 I USAGE BINARY-DOUBLE UNSIGNED.
01 N USAGE BINARY-DOUBLE UNSIGNED.
01 THREE-COUNTER USAGE BINARY-CHAR value 1.
88 IS-THREE VALUE 3.
01 FIVE-COUNTER USAGE BINARY-CHAR value 1.
88 IS-FIVE VALUE 5.
01 ANSWER pic x(40).
procedure division.
initialize COUNTER ACCUMULATOR incrementor.
10-MAIN-PROCEDURE.
move 1 to IN-NUMBER.
call "MOVENUMTOBIGNUM" using by content in-number
by reference incrementor.
move 1 to IN-NUMBER.
call "MOVENUMTOBIGNUM" using by content in-number
by reference counter.
PERFORM 20-INNER-LOOP WITH TEST AFTER UNTIL eor.
move ACCUMULATOR to ANSWER.
inspect answer REPLACING LEADING '0'
by space.
DISPLAY answer.
STOP RUN.
20-INNER-LOOP.
IF IS-THREE OR IS-FIVE
call "ADDBIGNUMS" using by content counter
by reference accumulator
IF IS-THREE
MOVE 1 TO THREE-COUNTER
ELSE
ADD 1 TO THREE-COUNTER
END-IF
IF IS-FIVE
MOVE 1 TO FIVE-COUNTER
ELSE
ADD 1 TO FIVE-COUNTER
END-IF
ELSE
ADD 1 TO FIVE-COUNTER END-ADD
ADD 1 TO THREE-COUNTER END-ADD
END-IF.
call "ADDBIGNUMS" using by content INCREMENTOR
by reference counter.
EXIT.
end program Program1.
identification division.
PROGRAM-ID. MOVENUMTOBIGNUM.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 num-MOD usage binary-CHAR.
01 num-DIV usage binary-DOUBLE unsigned.
01 IN-COUNTER usage binary-char.
LINKAGE SECTION.
01 num usage binary-double.
01 BIGNUM.
03 DIGITS1 OCCURS 40 TIMES PIC 9.
PROCEDURE DIVISION USING NUM BIGNUM.
10-MOVE.
move 40 to IN-COUNTER.
perform until num = 0
divide num by 10
giving num-DIV
REMAINDER num-MOD
end-divide
move num-MOD to DIGITS1 of BIGNUM(IN-COUNTER)
move NUM-DIV to NUM
subtract 1 from IN-COUNTER end-subtract
END-PERFORM.
GOBACK.
END PROGRAM MOVENUMTOBIGNUM.
*Add Bignum to Bignum, modifying second Bignum in situ
identification division.
program-id. ADDBIGNUMS.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 IN-COUNTER usage binary-char.
01 ADD-FLAG pic 9.
88 STILL-ADDING VALUE 0.
88 DONE-ADDING VALUE 9.
01 CARRIER usage binary-char.
01 REGISTER-A usage binary-char.
LINKAGE SECTION.
01 BIGNUM1.
03 DIGITS1 OCCURS 40 TIMES PIC 9.
01 BIGNUM2.
03 DIGITS1 OCCURS 40 TIMES PIC 9.
PROCEDURE DIVISION USING BIGNUM1 BIGNUM2.
10-ADD-WITH-CARRY.
move zero to CARRIER.
move 40 to IN-COUNTER.
move zero to ADD-FLAG.
perform until DONE-ADDING
add DIGITS1 of BIGNUM1(IN-COUNTER)
DIGITS1 of BIGNUM2(IN-COUNTER)
CARRIER GIVING REGISTER-A
END-ADD
move zero to CARRIER
if REGISTER-A > 9
divide REGISTER-A by 10
giving CARRIER
remainder REGISTER-A
end-divide
else
if REGISTER-A = zero
move 9 to ADD-FLAG
END-IF
end-if
if STILL-ADDING
move REGISTER-A to DIGITS1 of BIGNUM2(IN-COUNTER)
subtract 1 from IN-COUNTER end-subtract
end-if
END-PERFORM.
goback.
END PROGRAM ADDBIGNUMS.
Although you already don't seem to like the structure, I'll stick to it. It will work with your structure as well. No need for the REDEFINES or those other FILLERs.
05 FILLER.
10 FILLER OCCURS 40 TIMES.
15 DIGITS1 PIC 9.
88 DIGITS1-MEANS-SOMETHING
VALUE 1.
01 NAME-THAT-REVEALS-INFORMATION BINARY PIC 9(4).
IF DIGITS1-MEANS-SOMETHING
( NAME-THAT-REVEALS-INFORMATION )
do some stuff
END-IF
I've changed you PIC 9 to PIC X. Unless you are doing calculations, there is never a need to define a field as 9 for "numeric". If a field happens to contain numbers, or happens to have the word number, or something like that in its name, don't be tricked into defining it as a number.
Extra (generated) code ensues and it carries the meaning "numeric stuff will be done with this", so misleads. If/when you need to do a "numeric edit" for output, there's always the REDEFINES at that point. Doesn't have to have these other costs to make that happen.
I've now reverted to your PIC 9, as, after your edit, I can see you are using it for calculations :-)

Resources