Page 1 of 1

Count SPACE character without INSPECT and STRING in COBOL?

Posted: Tue Feb 20, 2018 5:50 pm
by Shahid
Hi

Count SPACE character without INSPECT and STRING in COBOL?

In one of the interview I was asked that how to count the space characters in particular variable (15 characters) without using INSPECT and STRING?

My answer was to use PERFORM and use Reference Modification but it was not correct, can someone please answer what can be correct answer for it?

Re: Count SPACE character without INSPECT and STRING in COBOL?

Posted: Tue Feb 20, 2018 8:35 pm
by Anuj Dhawan
May be redefine the variable with OCCURS 15 times of one byte each. PERFORM varying with a counter should get what you've asked for. :?

Re: Count SPACE character without INSPECT and STRING in COBOL?

Posted: Wed Feb 21, 2018 9:14 am
by Robert Sample
can someone please answer what can be correct answer for it?
Why not ask the interviewer? There are at least 3 possible ways to do this:
1. INSPECT
2. Reference modification
3. REDEFINES as an array and iterate across the array.

All of them are viable solutions -- but only the interviewer could tell you what their "correct" solution is.