Page 1 of 1

Store index in some other variable?

Posted: Tue Oct 13, 2015 2:28 pm
by divyaanand
Hi,

Can index be stored in some other variable? The question was like, assume we have a table like this:

Code: Select all

01 SOME-VARIABLE-1 PIC X(36). 
05 SOME-VARIABLE--2 REDEFINES STRING-1 PIC X(1) OCCURS 36 TIMES 
INDEXED BY INDX1. 


SEARCH STRING-2 WHEN SOME-VARIABLE-2 (INDX1) = TEMP(i:1) 
SET INDX1 UP BY 1. 
Now can we get INDX1 into some other variable?

I'm not sure if we can do that?

Re: Store index in some other variable?

Posted: Tue Oct 13, 2015 4:19 pm
by William Collins
You use SET.

Exactly how you do it depends on what you want. Do you to save the value of the index, or do you want the "occurrence number" of the index? It may not make a big difference for a one-byte OCCURS.

What do you feel that code is doing anyway?

Please use scope-terminators (like END-SEARCH) instead of full-stops/periods.

Re: Store index in some other variable?

Posted: Tue Oct 13, 2015 6:12 pm
by Robert Sample
Look at USAGE INDEX in the Enterprise COBOL Language Reference manual.