COBOL Module 5
Text handling: STRING, UNSTRING, INSPECT and text functions interview questions
Interview questions on “Text handling: STRING, UNSTRING, INSPECT and text functions”.
Warm-up questions
Short questions with short answers, each answered in full.
-
Fresher to mid
Why does STRING FIRST-NAME DELIMITED BY SPACE " " LAST-NAME DELIMITED BY SPACE drop the space?
Answered in the lesson STRING, UNSTRING and reference modification
-
Fresher to mid
What does NAME(3:4) mean, and what happens when the slice runs past the end of NAME?
Answered in the lesson STRING, UNSTRING and reference modification
-
Fresher to mid
How does INSPECT ... TALLYING FOR ALL differ from FOR LEADING?
Questions with model answers
What each question tests, the first step of a good answer and the follow-ups to expect.
-
Mid to senior
A partner now sends payments as comma-separated lines, which the program splits with UNSTRING DELIMITED BY ",". Since the switch, some payments post to the wrong branch and a few amounts arrive cut short, yet the batch reports no errors. How do you find the bad lines, and what do you change?
- What it tests
- Knowing what UNSTRING does with empty fields, extra delimiters, leading spaces and long values, and using TALLYING IN, COUNT IN and ON OVERFLOW to reject a line instead of posting it.
- First step
- Add the checks UNSTRING already offers and count what fails. In the lesson an empty field became spaces, the last field kept its leading spaces, a count of 15 exposed a value longer than its 9-byte field, and a line with one field too many ran ON OVERFLOW. A value that contains a comma moves every later field along by one.
- Follow-ups
-
- What do you do about a name that contains a comma?
- How should the program report a bad line?
- How do you test the parser?
From the lesson STRING, UNSTRING and reference modification
Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.Opening the model answers with your pass…
Model answers open with any MySmartCoPilot pass.
- Pro pass · 1 week₹79$2.99
- 30 days₹179$5.99
- 1 year₹1,699$45
One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.
Passes can’t be bought right now, so the model answers can’t be opened at the moment. If you have a pass, enter your licence key.
It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).
In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Fresher to mid
A statement program builds each detail line with STRING into PRINT-LINE. For some customers the line ends with an extra amount that belongs to the customer printed before them, although no statement moves that amount there. What is happening, and how do you fix and test it?
- What it tests
- Knowing that STRING writes only the positions it fills, clearing a receiver before building it, and testing lines of different lengths in sequence.
- First step
- Compare a wrong line with the line printed just before it. In the lesson, STRING "RAVI" into a field that held ANITA DESAI left RAVIA DESAI: STRING never clears its receiver, so a shorter line keeps the tail of a longer one.
- Follow-ups
-
- Why does it happen for some customers only?
- Is MOVE SPACES before every STRING enough?
- Which test would have caught it?
From the lesson STRING, UNSTRING and reference modification
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
After a move to GnuCOBOL 3.2, an upload of branch amounts posted 12.50 for a line that read 12.5.0, and an old check that rejected bad amounts when NUMVAL returned zero now rejects nothing. What changed, and how do you validate the amounts from now on?
- What it tests
- Knowing that GnuCOBOL 3.2 NUMVAL skips invalid characters instead of returning zero, validating with TEST-NUMVAL or TEST-NUMVAL-C before converting, and testing the rules with malformed input.
- First step
- Read the GnuCOBOL 3.2 NEWS: NUMVAL used to return zero for an argument that breaks its rules, and now skips the invalid data. In the lesson NUMVAL turned 12.5.0 into 12.500, while TEST-NUMVAL returned 5, the position of the second point.
- Follow-ups
-
- Which inputs would you put in a test file?
- Would you switch the old behaviour back on?
- How do amounts with Indian digit grouping or a currency prefix fit in?
From the lesson INSPECT, TRIM, UPPER-CASE and NUMVAL
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes
-
Mid to senior
An audit finds full account numbers in the job logs of a nightly COBOL batch, written by DISPLAY statements in its error paths. How do you remove them without losing what support staff need, and how do you make sure none come back?
- What it tests
- Masking data before it is displayed, finding every place that logs it, keeping enough for support to find a record, and testing the logs against a pattern.
- First step
- Find every DISPLAY that names the account field or a record that contains it, then mask a copy before it is shown. In the lesson
INSPECT ACCT-NO(1:6) REPLACING CHARACTERS BY "*"turned AC00417321 into******7321. - Follow-ups
-
- How many characters may stay visible?
- How do you keep the masking from changing the record itself?
- Which test catches a full number that comes back?
From the lesson INSPECT, TRIM, UPPER-CASE and NUMVAL
Model answer, Pro.In the answer:
- Model answer
- Follow-up answers
- Common mistakes
- Rubric
- Variants
- about 3 minutes