Consultor Eletrônico



Kbase P25940: How to use Character string lists
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   5/27/2003
Status: Unverified

GOAL:

How to use Character string lists

FACT(s) (Environment):

Progress 9.1x

FIX:

When you need an unknown quantity but small number of variables you can take the string list approach. This approach uses a character variable and packs multiple items into it using a delimiter. Progress provides several functions and statements to aid in using this flexible (if not fast) data structure.

ENTRY    - Returns the element in the list by number  (Function)
        - Replaces an element in the list by number  (Statement)
LOOKUP   - Locates an element and returns its number
CAN-DO   - Checks for existence of element in the list
+ ...    - String concatenation and other string handling statements

Many of these string list oriented activities now take an additional parameter to specify the delimiter. This is great for parsing input from external sources or allowing multiple layers within a single string list.

The selection list and combo-box widgets take a string list to manage the list of items. As such you often have the need to keep a matching list of record references. This can be accomplished by keeping a second string list, in the same sequence, of the record keys.

Sample - (Imaginary State table)

---- Code insert begins ----

DEF VAR  t-state-keys  AS CHAR   NO-UNDO.
DEF VAR  t-state-list  AS CHAR   NO-UNDO.
DEF VAR  t-current-id  AS INT    NO-UNDO.
DEF VAR  t-pos         AS INT    NO-UNDO.

FOR EACH State NO-LOCK:
 ASSIGN
   t-state-keys = t-state-keys + MIN(",",t-state-keys)
                + STRING(State.IDNum)
   t-state-list = t-state-list + MIN(",",t-state-list)
                + State.Abbrv.
END.

/** To return the ID for a selected entry **/

ASSIGN
 t-pos        = LOOKUP("NC",t-state-list)
 t-current-id = (IF t-pos > 0 AND t-pos < NUM-ENTRIES(t-state-keys)
                   THEN INT(ENTRY(t-pos,t-state-keys))
                   ELSE ?).

---- Code insert ends ----

The two disadvantages are the speed of string operations and the requirement to convert values to and from strings.