Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Good afternoon all,
I have a FOR...LOOP where I want to check the existence of a field value in a conditional statement and thought 'exists' would do the job. However, I cannot seem to achieve it. Take this simple code below which shows the issue:
LOAD * INLINE [
F1, F2
A, 1
B, 2
C, 3
E, 4
G, 5
T, 6
];
LET vExists = if (exists(F1, 'B'), 1, 0);
IF vExists = 1 THEN
SET vVal = Y;
END IF
Is using 'exists' outside of a LOAD illegal? How can I achieve what I am after?
Help appreciated.
Regards,
Gordon
I'm not sure if Exists can be used outside of a LOAD. You may be able to use Fieldindex() to do the same thing:
LET vExists = if (Fieldindex(F1, 'B') > 0, 1, 0);
IF vExists = 1 THEN
SET vVal = Y;
END IF
I don't believe you can use exists outside of a LOAD.
You can try lookup Let vAux = lookup('F1', 'F1', 'B');
If performance is a concert then you can do something like
LOAD * INLINE [
F1, F2
A, 1
B, 2
C, 3
E, 4
G, 5
T, 6
];
TAB1:
load
exists(F1, 'B') AS F3
AUTOGENERATE(1);
LET vExists = if (exists(PEEK('F3'), 'B'), 1, 0);
DROP TAB1;
IF vExists = 1 THEN
SET vVal = Y;
END IF
Thanks chaps.
The fieldindex is the way to go for me but both solutions work.
Regards,
Gordon