Question

Here is an example I used for INSPECT verb.

INSPECT FUNCTION REVERSE (WS-ADDR(7:4)) TALLYING WS-COUNT FOR LEADING SPACES
             DISPLAY 'COUNT  :' WS-COUNT
             COMPUTE WS-LENGTH = 4 - WS-COUNT
             DISPLAY 'LENGTH  :' WS-LENGTH

I am not getting the right output with the below input,

Input-1  - 43WE 
WS-COUNT = 0
LENGTH   = 4

Input-2  - 85
WS-COUNT = 2
LENGTH   = 2

Input-3  - 74OI
WS-COUNT = 2
LENGTH   = 2

For the input-3 the WS-COUNT should come as 0 but I am getting 2 as a value. Please find the console window screen shot below,

IN-VALUES  :%ORIG243WE
COUNT  :000
LENGTH  :004
ADDRESSLINES:  43WE<br>  
WS-SUB  :004
IN-VALUES  :%ORIG385  
COUNT  :002
LENGTH  :002
ADDRESSLINES:  85<br>    
WS-SUB  :005
IN-VALUES  :%ORIG474OI
COUNT  :002
LENGTH  :002

Could you anyone help me to resolve this.

Was it helpful?

Solution

You must initialize identifier-2 before execution of the INSPECT statement begins.

So says the IBM Enterprise COBOL Language Reference, and the words will be similar in any COBOL manual.

identifier-2 is the target field of your TALLLYING.

If you do not set this to an initial value prior to the INSPECT, the current value will be used to add to (or not, in your case).

This is useful sometimes, but if you do not want to make use of it, you must set the identifier-2 field to zero before the INPSECT.

In your case that would be, for example (you could also use INITIALIZE, SET an 88 which has a zero in the first position of its VALUE clause, etc):

MOVE ZERO TO WS-COUNT

If you show your data-definitions, representative sample input and expected output, you may even get some hints about doing what it is that you want in a tidier way. If you tell us what it is you want.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top