Searching and updating Array

I want to get the the postion of the array when searching and update.
Example:
IF My-Array(*) = 123
My-Array(i) := 456
END-IF

If 123 is found i want to update the record to 456.

If you can redefine the elements as alpha, then you can EXAMINE #MY-ARRAY (*) … GIVING INDEX …

Otherwise you will need to check each value in a FOR loop.

examine my-array for ‘123’ giving index i
if i = 0
not found…
else
update…
end-if

A minor point that prove more efficient.

DEFINE #MY-STRING (A10000)
2 #MY-ARRAY (A5/1:2000)

You still have the array available for your coding.

However, what you can also do is EXAMINE #MY-STRING FOR … GIVING POSITION

If the array has a lot of entries examining the string will be far more efficient.

Whoops. Forgot to include something.

Suppose I have a table like ABC DEF GHI … etc. Is BCD in our table? Clearly not.
The simplest way to deal with this is shown below:

1 #TABLE (2000)
2 #MY-ARRAY (A5)
2 #filler (A1) INIT ALL <‘*’>
1 REDEFINE #TABLE
2 #MY-STRING (A12000)

I used an asterisk above. The assumption is that an asterisk (or whatever you might use) is not a valid character for the values in #MY-ARRAY.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.