Yep!! I found a bug and fixed. In any occrance if the first byete is spaces then my code will add an extra space.
I do not find any other mistake in that. Did you find time to run that code?
Also could you please post why you believe that the previous code will not work as intended? (Just out of curiosity
)
Just added an IF statement and changed the value of
J. See the changes tagged with
ARUN**.
Modified code: IDENTIFICATION DIVISION.
PROGRAM-ID. SAMPLE
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.
01 VAR1.
05 VAR-A1 PIC X(65) OCCURS 3 TIMES.
01 VAR-A2 PIC X(200).
01 WS-ID PIC 9(02) VALUE 1.
01 I PIC 9(02) VALUE 1.
ARUN***01 J PIC 9(02) VALUE 1.
ARUN** 01 J PIC 9(02) VALUE 0.
PROCEDURE DIVISION.
MOVE ' THIS IS A SAMPLE LINE ' TO
VAR-A1(1).
MOVE ' THIS IS 2ND LINE ' TO
VAR-A1(2).
MOVE 'THIS IS THIRD LINE ' TO
VAR-A1(3).
PERFORM LOOP-FOR-EACH-ARRAY
THRU LOOP-FOR-EACH-ARRAY-XT UNTIL WS-ID > 3.
DISPLAY 'VAR-A2 :' VAR-A2.
GOBACK.
LOOP-FOR-EACH-ARRAY.
MOVE 1 TO I.
ARUN** IF VAR-A1(WS-ID) (I:1) NOT = ' '
MOVE SPACES TO VAR-A2(J:1)
ADD 1 TO J
ARUN** END-IF.
PERFORM UNTIL I = 65
IF NOT VAR-A1(WS-ID) (I:1) = ' '
MOVE VAR-A1(WS-ID) (I:1) TO VAR-A2(J:1)
COMPUTE J = (J + 1) END-COMPUTE
COMPUTE I = (I + 1) END-COMPUTE
ELSE
COMPUTE I = (I + 1) END-COMPUTE
IF NOT VAR-A1(WS-ID) (I:1) = ' '
COMPUTE I = (I - 1) END-COMPUTE
MOVE VAR-A1(WS-ID) (I:1) TO VAR-A2(J:1)
COMPUTE I = (I + 1) END-COMPUTE
COMPUTE J = (J + 1) END-COMPUTE
MOVE VAR-A1(WS-ID) (I:1) TO VAR-A2(J:1)
COMPUTE J = (J + 1) END-COMPUTE
COMPUTE I = (I + 1) END-COMPUTE
END-IF
END-IF
END-PERFORM.
ADD 1 TO WS-ID.
LOOP-FOR-EACH-ARRAY-XT.