Everybody of us, know that we can
DEFINE VARIABLE myARRAY AS CHAR NO-UNDO EXTENT 5 INITIAL ["A","B","C","D","E"].
DISPLAY "Third position stores " myArray.
To get a message that displays sort of "Third position stores C".
Is there an instruction that could allow me to get:
"Letter D in in position 4"
without resorting to a DO i =1 to length_of_array: if myArray[i] = value_searched THEN Display.....
I'm talking about some LOOKUP kind of function or instruction that allows to search the values inside an array?
I think you are underestimating the number of computation .indexOf() has.
But an object could be created:
A = new WhatChaMaCallit(myArray).
D = A:indexOf("D")
L = A:lengthOf()
Using a temp-table in it instead of an array, allows more flexibility, the constructor simply walks the array and make a record for each element.
Then ya could:
If you want to know this because you have to do this a gazillion times in a loop, then I think a TT with all the values from your array will be your best friend. I am not aware of some sort of reversed-index instruction to get the position of an element in an array.
Other alternative may be to place the array elements in a comma separated list and use the LOOKUP function. But either way, you need to do some extra things before you find the element's position.
You should also add this an Idea (enhancement request) too.