Index in a multi-dimensional Array/Matrix

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
talk2shaanc
Charter Member
Charter Member
Posts: 199
Joined: Tue Jan 18, 2005 2:50 am
Location: India

Index in a multi-dimensional Array/Matrix

Post by talk2shaanc »

I would like to find index of a string in a MATRIX/Multi-dimensional array.
Does anyone know a function to get the same?
Shantanu Choudhary
WoMaWil
Participant
Posts: 482
Joined: Thu Mar 13, 2003 7:17 am
Location: Amsterdam

Post by WoMaWil »

there are several look into manual or help
Wolfgang Hürter
Amsterdam
talk2shaanc
Charter Member
Charter Member
Posts: 199
Joined: Tue Jan 18, 2005 2:50 am
Location: India

Post by talk2shaanc »

WoMaWil wrote:there are several look into manual or help
if you are refering to Index function then that wont help.

I will explain my requirement. assume i have 3X3 matrix as

Code: Select all

Bill     Jon      Pam
Male   Male    Female
25      29       62
I have requirement where i need to search "Pam" in the matrix and then read all other elements related to "Pam". So in the end I want the result to be "Pam", "Female", "62"...

In my example I have mentioned the dimension (3X3); but in actual dimension is also unknown/variable.

The index function will return 7, assuming no spaces added for "Bill"/"Jon
Shantanu Choudhary
kcbland
Participant
Posts: 5208
Joined: Wed Jan 15, 2003 8:56 am
Location: Lutz, FL
Contact:

Post by kcbland »

If your example was in 3x3 dynamic array:

Code: Select all

example=""
example<1,1>="BILL"
example<1,2>="JON"
example<1,3>="PAM"
example<2,1>="MALE"
example<2,2>="MALE"
example<2,3>="FEMALE"
example<3,1>="25"
example<3,1>="29"
example<3,1>="62"
You would use the LOCATE statement to search one row of the matrix for values. Upon finding the matching value, the statement returns the position in the array. That position can be used to reference the remaining rows. The statement has an if-then-else structure to let you handle it being found or not:

Code: Select all

LOCATE "JON" IN EXAMPLE<1> SETTING PSN THEN
   GENDER = example<2,PSN>
   AGE = example<3,PSN>
END ELSE
   GENDER = "UNKNOWN"
   AGE = 0
END
Kenneth Bland

Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

FIND may be easier to manage than LOCATE.

Or you could make a 1x9 matrix, copy from one to the other (using MAT keyword) and search that using LOCATE. If name found, add six to the where-found value to identify the element number of the desired age.

Or you could MATBUILD a nine-element dynamic array.

There are even more possibilities, you should be well under way with just these and those of the other posters.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply