PDA

View Full Version : Problem bei Lookup



Chris.jan
13-09-18, 10:40
Ich steh hier grad aufm Schlauch und weiß nicht weiter.
ich hab ein compiletimearray den ich durchsuchen will:

d table1 s 1 dim(36) ctdata perrcd(36)

c eval int = %lookup(input(i):table1)

**
ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890

Jetzt wirft mir der Compiler die Meldung aus, daß der zweite Parameter von lookup nicht korrekt wäre.
Jemand eine Idee wo mein Denkfehler ist?

RobertMack
13-09-18, 10:46
c eval int = %lookup(input(i):table1:1)

B.Hauser
13-09-18, 11:01
Bei Compile Time Arrays musst Du die Funktion %TLookupXX verwenden.
%LookUpXX ist nur für Feldgruppen.
%TLookup (https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_73/rzasd/bbtloo.htm)

Birgitta

Chris.jan
13-09-18, 11:03
Super, vielen lieben Dank!
Konnte ja auch nur so ne dumme Kleinigkeit sein.

Fuerchau
13-09-18, 11:23
Der Gedankenfehler liegt in folgendem begründet:

CTDATA
The CTDATA keyword indicates that the array or table is loaded using compile-time data. The data is
specified at the end of the program following the ** or **CTDATA(array/table name) specification.

Der Unterschied zwischen Array und Table liegt im Namen:
Alle Arrays, die mit "TAB" anfangen sind eine Table:

Table Names
The following additional rules apply to table names:
v A table name can contain from 3 to 10 characters.
v A table name must begin with the letters TAB.
v A table cannot be defined in a subprocedure.

Tables
The explanation of arrays applies to tables except for the following differences:
Activity
Differences
Defining
A table name must be a unique symbolic name that begins with the letters TAB.
Loading
Tables can be loaded only at compilation time and prerun-time.
Using and Modifying table elements
Only one element of a table is active at one time. The table name is used to refer to the active
element. An index cannot be specified for a table.
Searching
The LOOKUP operation is specified differently for tables. Different built-in functions are used for
searching tables.

Daher erklärt sich auch, dass Tabelle eben per TLOOKUP bedient werden muss und ein Array-Indexzugriff "Tabelle1(I)" nicht möglich ist.
Benennst du die Tabelle um "Zeichen", dann gilt wieder %lookup und Arrayindex.

Chris.jan
14-09-18, 13:35
Das schlimme ist ja daß ich das alles mal wusste, aber jetzt 10 jahre nicht aktiv benutzt und schlicht vergessen.

Fuerchau
14-09-18, 18:20
Nun ja, was bei mir generell hängen blieb war: Definiere ein Array (E, DIM) nie mit TABxxx!
Und das geht einem bei dem Namen "Tabelle" schnell unter, da RPG immer noch case insensitive ist.