01 WS-VARS.
05 WS-DATA PIC X(44)
VALUE '11245668796981831928381768678756'.
05 WS-REDEF REDEFINES WS-DATA.
10 WS-A PIC 9(09).
10 WS-B PIC 9(07).
10 WS-C PIC 9(07).
10 WS-D PIC 9(07).
10 WS-E PIC X(14).
05 WS-B1-CALC PIC 9(09).
05 FILLER REDEFINES WS-B1-CALC.
10 WS-A1-REMAINDER PIC 99.
10 WS-B1 PIC 9(07).
05 WS-C1-CALC PIC 9(09).
05 FILLER REDEFINES WS-C1-CALC.
10 WS-B1-REMAINDER PIC 99.
10 WS-C1 PIC 9(07).
05 WS-D1-CALC PIC 9(09).
05 FILLER REDEFINES WS-D1-CALC.
10 WS-C1-REMAINDER PIC 99.
10 WS-D1 PIC 9(07).
05 WS-E1-STRING PIC X(16).
05 FILLER REDEFINES WS-E1-STRING.
10 WS-D1-REMAINDER PIC 99.
10 WS-E1 PIC X(14).
05 WS-E1-CALC PIC 9(16).
05 WS-E-NUM PIC 9(14).
05 WS-MODULUS-VALUE PIC 9(02) VALUE 97.
05 WS-RESULT PIC 9(02).
05 WS-E-DIGITS PIC 9(02).
05 WS-DIVISOR PIC 9(09).
05 WS-DIVIDEND PIC 9(09).
PROCEDURE DIVISION.
MOVE WHEN-COMPILED TO W-WHEN-COMPILED
DIVIDE WS-A BY WS-MODULUS-VALUE
GIVING WS-DIVISOR
REMAINDER WS-A1-REMAINDER
MOVE WS-B TO WS-B1
MOVE WS-C TO WS-C1
MOVE WS-D TO WS-D1
MOVE WS-E TO WS-E1
DIVIDE WS-A BY WS-MODULUS-VALUE
GIVING WS-DIVISOR
REMAINDER WS-B1-REMAINDER
DIVIDE WS-B1-CALC BY WS-MODULUS-VALUE
GIVING WS-DIVISOR
REMAINDER WS-B1-REMAINDER
DIVIDE WS-C1-CALC BY WS-MODULUS-VALUE
GIVING WS-DIVISOR
REMAINDER WS-C1-REMAINDER
DIVIDE WS-D1-CALC BY WS-MODULUS-VALUE
GIVING WS-DIVISOR
REMAINDER WS-D1-REMAINDER
DIVIDE WS-D1-CALC BY WS-MODULUS-VALUE
GIVING WS-DIVISOR
REMAINDER WS-D1-REMAINDER
UNSTRING WS-E1-STRING DELIMITED BY SPACE
INTO WS-E1-CALC
DIVIDE WS-E1-CALC BY WS-MODULUS-VALUE
GIVING WS-DIVISOR
REMAINDER WS-RESULT
DISPLAY 'FIRST DIVISION ' WS-A ' ' WS-A1-REMAINDER
DISPLAY 'SECOND DIVISION ' WS-B ' ' WS-B1-REMAINDER
DISPLAY 'THIRD DIVISION ' WS-C ' ' WS-C1-REMAINDER
DISPLAY 'FOURTH DIVISION ' WS-D ' ' WS-D1-REMAINDER
DISPLAY 'SECOND DIVISION ' WS-E ' ' WS-RESULT
GOBACK
.
05 WS-DATA PIC X(44)
VALUE '11245668796981831928381768678756'.
05 WS-REDEF REDEFINES WS-DATA.
10 WS-A PIC 9(09).
10 WS-B PIC 9(07).
10 WS-C PIC 9(07).
10 WS-D PIC 9(07).
10 WS-E PIC X(14).
05 WS-B1-CALC PIC 9(09).
05 FILLER REDEFINES WS-B1-CALC.
10 WS-A1-REMAINDER PIC 99.
10 WS-B1 PIC 9(07).
05 WS-C1-CALC PIC 9(09).
05 FILLER REDEFINES WS-C1-CALC.
10 WS-B1-REMAINDER PIC 99.
10 WS-C1 PIC 9(07).
05 WS-D1-CALC PIC 9(09).
05 FILLER REDEFINES WS-D1-CALC.
10 WS-C1-REMAINDER PIC 99.
10 WS-D1 PIC 9(07).
05 WS-E1-STRING PIC X(16).
05 FILLER REDEFINES WS-E1-STRING.
10 WS-D1-REMAINDER PIC 99.
10 WS-E1 PIC X(14).
05 WS-E1-CALC PIC 9(16).
05 WS-E-NUM PIC 9(14).
05 WS-MODULUS-VALUE PIC 9(02) VALUE 97.
05 WS-RESULT PIC 9(02).
05 WS-E-DIGITS PIC 9(02).
05 WS-DIVISOR PIC 9(09).
05 WS-DIVIDEND PIC 9(09).
PROCEDURE DIVISION.
MOVE WHEN-COMPILED TO W-WHEN-COMPILED
DIVIDE WS-A BY WS-MODULUS-VALUE
GIVING WS-DIVISOR
REMAINDER WS-A1-REMAINDER
MOVE WS-B TO WS-B1
MOVE WS-C TO WS-C1
MOVE WS-D TO WS-D1
MOVE WS-E TO WS-E1
DIVIDE WS-A BY WS-MODULUS-VALUE
GIVING WS-DIVISOR
REMAINDER WS-B1-REMAINDER
DIVIDE WS-B1-CALC BY WS-MODULUS-VALUE
GIVING WS-DIVISOR
REMAINDER WS-B1-REMAINDER
DIVIDE WS-C1-CALC BY WS-MODULUS-VALUE
GIVING WS-DIVISOR
REMAINDER WS-C1-REMAINDER
DIVIDE WS-D1-CALC BY WS-MODULUS-VALUE
GIVING WS-DIVISOR
REMAINDER WS-D1-REMAINDER
DIVIDE WS-D1-CALC BY WS-MODULUS-VALUE
GIVING WS-DIVISOR
REMAINDER WS-D1-REMAINDER
UNSTRING WS-E1-STRING DELIMITED BY SPACE
INTO WS-E1-CALC
DIVIDE WS-E1-CALC BY WS-MODULUS-VALUE
GIVING WS-DIVISOR
REMAINDER WS-RESULT
DISPLAY 'FIRST DIVISION ' WS-A ' ' WS-A1-REMAINDER
DISPLAY 'SECOND DIVISION ' WS-B ' ' WS-B1-REMAINDER
DISPLAY 'THIRD DIVISION ' WS-C ' ' WS-C1-REMAINDER
DISPLAY 'FOURTH DIVISION ' WS-D ' ' WS-D1-REMAINDER
DISPLAY 'SECOND DIVISION ' WS-E ' ' WS-RESULT
GOBACK
.
Output is:
FIRST DIVISION 112456687 28
SECOND DIVISION 9698183 20
THIRD DIVISION 1928381 86
FOURTH DIVISION 7686787 59
SECOND DIVISION 56 39
SECOND DIVISION 9698183 20
THIRD DIVISION 1928381 86
FOURTH DIVISION 7686787 59
SECOND DIVISION 56 39
The remainder is preprended to a copy of each segment of the input. The final one, with a variable number of digits prepended with the previous remainder, is made into a number using UNSTRING to a numeric field. It will even work when the last 14 bytes are blank, because there will always be a numeric value (the remainder from the previous calculation).