August 17, 2005, 12:37 PM
tikababy9using an array (or variable index)
Here is my delima. I want to search a table by an array (or variable index) of user prompted input. Once they type in the their search criteria and type done, they will get a list of what they are looking for.
Here is an example:
-SET &N = 0;
-TYPE TYPE DONE WHEN FINISHED
-LOOP
-PROMPT &PARTNUM.ENTER PART NUMBER OR DONE.;
-IF &PARTNUM EQ 'DONE' GOTO OUT;
-SET &N = &N+1;
-SET &ARRAY.&N = &PARTNUM;
-GOTO LOOP
-OUT
TABLE FILE PART_NUMBERS
PRINT
PART_ID
LOCATION
QTY
WHERE PART_ID IN (&ARRAY);
END
Does anyone have any ideas of how to accomplish this on the mainframe?
August 17, 2005, 04:52 PM
reFOCUSingIf you change
-SET &ARRAY.&N = &PARTNUM;
to
-SET &ARRAY = IF &N EQ 1 THEN &ARRAY ELSE &ARRAY || ',' || &PARTNUM;
would it work for you?
August 17, 2005, 08:45 PM
tikababy9This solution works great! Here is the finished code for those who need the same answer. Thank you! The part numbers are an alphanumeric field so I added the four tick marks at the front, end, and inbetween.
-SET &N = 0;
-SET &ARRAY = '''';
-TYPE TYPE DONE WHEN FINISHED
-LOOP
-PROMPT &PARTNUM.ENTER PARTNUMBER.;
-IF &PARTNUM EQ 'DONE' GOTO DONE;
-SET &N = &N+1;
-SET &ARRAY = IF &N EQ 1 THEN &ARRAY || &PARTNUM
- ELSE &ARRAY || ''',''' || &PARTNUM;
-GOTO LOOP
-DONE
-SET &ARRAY = &ARRAY || '''';
TABLE FILE PART_NUMBERS
PRINT
PART_ID
LOCATION
QTY
WHERE PART_ID IN (&ARRAY);
END