Difference between %scan and %lookup in RPGLE?

If I scan 'NDIA' in 'INDIAN' by using %scan(), a value greater than 0 returned. If I do same using %lookup() in an array then 0 is returned. Why?

Program 1

D VAR1 s 10a inz('INDIAN') D S1 S 10S 0 C 'NDIA' SCAN VAR1 S1 C S1 DSPLY /free *inlr = *on; /end-free 

Program 2

D ARR1 s 10a DIM(5) D S1 S 10S 0 C EVAL ARR1(1) = 'AMERICA' C EVAL ARR1(2) = 'INDIA' C EVAL ARR1(3) = 'CHINA' /free S1 = %LOOKUP('NDIA':ARR1); DSPLY S1; *inlr = *on; /end-free 

What is difference in both programs?

3

1 Answer

%lookup() looks for an exact match, not a partial match. If you change your %lookup to look for 'INDIA' it will return a match.

By the way, there is no reason to use the Fixed Format C specs in both of your examples. They can be entirely /free.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like