Page 1 of 1

COBOL interview question.

Posted: Fri Dec 02, 2022 1:40 pm
by s0c7s0c4
Hi everyone,

I faced the following question, for which I could not answer, I think. Could you please have a look and help:

Input file contains data as follows:

Code: Select all

##  99ijkl
123abcde
fghij
How to remove these leading spaces and ## so that the Output looks like this:

Code: Select all

99ijkl
123abcde
fghij

Re: COBOL interview question.

Posted: Sat Dec 03, 2022 12:19 am
by Robert Sample
IF statement would be easiest (if not very generic):

Code: Select all

IF INPUT-VAR (1 : 4) = '##  ' 
THEN INPUT-VAR = INPUT-VAR (5: ) .
A more generic solution would be to strip off the first two # signs, then use a loop to determine the number of leading spaces, then use a similar INPUT-VAR = to remove leading spaces.

Re: COBOL interview question.

Posted: Mon Dec 05, 2022 5:20 pm
by S Vikram
You can also use INSPECT VARYING for this.