COBOL interview question.

All sort of Mainframes Interview Questions.
Post Reply
s0c7s0c4
New Member
Posts: 1
Joined: Wed Apr 08, 2015 1:48 pm

COBOL interview question.

Post 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
User avatar
Robert Sample
Global Moderator
Global Moderator
Posts: 1896
Joined: Fri Jun 28, 2013 1:22 am
Location: Dubuque Iowa
United States of America

Re: COBOL interview question.

Post 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.
S Vikram
New Member
Posts: 8
Joined: Mon Jan 05, 2015 2:22 pm

Re: COBOL interview question.

Post by S Vikram »

You can also use INSPECT VARYING for this.
Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Return to “Interview Questions.”