Add Numbers

77 NUM PIC 9(5).
77 I PIC 99.
77 J PIC 99.
77 K PIC 99.
77 Q PIC 99.
01 NUM-TABLE1.
02 ONE PIC X(9) VALUE "ONE ".
02 TWO PIC X(9) VALUE "TWO ".
02 THREE PIC X(9) VALUE "THREE ".
02 FOUR PIC X(9) VALUE "FOUR ".
02 FIVE PIC X(9) VALUE "FIVE ".
02 SIX PIC X(9) VALUE "SIX ".
02 SEVEN PIC X(9) VALUE "SEVEN ".
02 EIGHT PIC X(9) VALUE "EIGHT ".
02 NINE PIC X(9) VALUE "NINE ".
02 TEN PIC X(9) VALUE "TEN ".
02 ELEVEN PIC X(9) VALUE "ELEVEN ".
02 TWELVE PIC X(9) VALUE "TWELVE ".
02 THIRTEEN PIC X(9) VALUE "THIRTEEN ".
02 FOURTEEN PIC X(9) VALUE "FOURTEEN ".
02 FIFTEEN PIC X(9) VALUE "FIFTEEN ".
02 SIXTEEN PIC X(9) VALUE "SIXTEEN ".
02 SEVENTEEN PIC X(9) VALUE "SEVENTEEN".
02 EIGHTEEN PIC X(9) VALUE "EIGHTEEN ".
02 NINETEEN PIC X(9) VALUE "NINETEEN ".

01 TABLE1 REDEFINES NUM-TABLE1.
02 TAB11 PIC X(9) OCCURS 19 TIMES.

01 NUM-TABLE2.
02 TWENTY PIC X(9) VALUE "TWENTY ".
02 THIRTY PIC X(9) VALUE "THIRTY ".
02 FORTY PIC X(9) VALUE "FORTY ".
02 FIRTY PIC X(9) VALUE "FIFTY ".
02 SIXTY PIC X(9) VALUE "SIXTY ".
02 SEVENTY PIC X(9) VALUE "SEVENTY ".
02 EIGHTY PIC X(9) VALUE "EIGHTY ".
02 NINETY PIC X(9) VALUE "NINETY ".

01 TABLE2 REDEFINES NUM-TABLE2.
02 TAB22 PIC X(9) OCCURS 8 TIMES.

PROCEDURE DIVISION.
START-PARA.
DISPLAY (1 1) ERASE.
DISPLAY "ENTER ANY NUMBER : ".
ACCEPT NUM.
DIVIDE 1000 INTO NUM GIVING Q REMAINDER NUM.
IF (Q > 0)
IF (Q NOT > 19)
DISPLAY TAB11 (Q), "THOUSAND "
ELSE
DIVIDE 10 INTO Q GIVING Q REMAINDER J
COMPUTE Q = Q - 1
DISPLAY TAB22 (Q) TAB11 (J), "THOUSAND ".
DIVIDE 100 INTO NUM GIVING Q REMAINDER NUM.
IF ( Q > 0)
DISPLAY TAB11 (Q), "HUNDRED "
DIVIDE 10 INTO NUM GIVING Q REMAINDER NUM.
IF (Q > 0)
IF (Q NOT > 1) DISPLAY TAB11 (Q)
ELSE
COMPUTE Q = Q - 1
DISPLAY TAB22 (Q) TAB11 (NUM).
STOP RUN