| Note: Usage options |
The SELECT command is used in conjunction with the ENDSELECT command to form a "loop" to process one or more records from a file that match certain criteria.
For example, the SELECT / ENDSELECT loop:
--->SELECT FIELDS(#ORDLIN #PRODUCT #QUANTITY)
| FROM_FILE(ORDLIN) WITH_KEY(#ORDER)
|
| DISPLAY FIELDS(#ORDER #ORDLIN #PRODUCT #QUANTITY)
|
----ENDSELECT
Forms a loop to read all records from file ORDLIN that have an order number matching the value in field #ORDER.
Each time a record is read the DISPLAY command, which is within the SELECT / ENDSELECT loop will display details of the record just read.
The SELECT command is probably the most flexible command in the LANSA RDML and some experience with it is required before the full power can be utilized. Some of the types of database processing supported by it include:
Entry sequence processing
Full key processing
Partial key processing
Generic key processing
Execution time modification of the number of keys to be used
Conditional selection of records
Forwards or backwards processing of selected records
Start at (or near) a key then process backwards or forwards
In addition, the SELECT command can be used in conjunction with the IBM i operating system command OPNQRYF (Open Query File). This extends the power of the SELECT command to include:
Execution time modification of record selection criteria
Execution time modification of the order records are processed
Field content searching
Field substringing during selection comparisons
Searching without regard to the case (upper or lower) of fields
For more details of how to use the IBM i operating system command OPNQRYF refer to the OPEN command in this guide first.
When fields A, B and C are selected in a SELECT loop like this:
SELECT FIELDS(#A #B #C)
FROM_FILE(...)
WHERE(...............)
.......
.......
ENDSELECT
they have a predictable and consistent value within the loop across all platforms.
These fields do not have a predictable and consistent value outside the loop. So this:
SELECT FIELDS(#A #B #C) FROM_FILE(...)
.......
IF COND(#A < 35.5)
.......
ENDIF
.......
ENDSELECT
is a predictable piece of logic, while:
SELECT FIELDS(#A #B #C)
FROM_FILE(...)
WHERE(...............)
.......
.......
ENDSELECT
IF COND(#A < 35.5)
.......
ENDIF
in any form or variation, is an unpredictable piece of logic.
The value of A (B and C), in terms of data read from the selection table, after exit from the SELECT loop, are actually defined as "not defined". This means that their values at the termination of a SELECT / ENDSELECT loop are not predictable or consistent across platforms.
Portability Considerations |
7.107.2 SELECT Comments / Warnings
Required SELECT ---------- FIELDS ---------- field name field attributes -----> >-- FROM_FILE -------- file name . *FIRST ----------------> -------------------------------------------------------------------------- Optional >-- WHERE ----------- 'condition' ------------------------> >-- WITH_KEY --------- key field values ------------------> >-- NBR_KEYS -------- *WITHKEY ------------------------> >-- GENERIC ---------- *NO ------------------------------> >-- IO_STATUS -------- *STATUS --------------------------> >-- IO_ERROR --------- *ABORT --------------------------> >-- VAL_ERROR ------- *LASTDIS ---------------------------> >-- END_FILE --------- *NEXT ------------------------------> >-- ISSUE_MSG ------ *NO ---------------------------------> >-- LOCK ------------ *NO ---------------------------------> >-- RETURN_RRN --- *NONE -------------------------------> >-- OPTIONS ------- up to 5 options allowed --------------| |