1,150 pts.
 LOOKUP
when lookup is unsuccessful what is the value of array index?

Software/Hardware used:
ASKED: April 8, 2009  2:55 PM
UPDATED: July 16, 2009  4:38 PM

Answer Wiki:
Cozzi: "When the LOOKUP operation is successful, the index variable is set to the index of the located variable". p 312 In other words it will not change on an unsuccessful LOOKUP. You can use NOT %Found to test for a failure to find correct index.: Category LOOKUP ItemCat if NOT %Found() CallP BadCategory() endif KSoniat Hi, I'm not sure, but I believe that if the lookup is unsuccessful, the array index remains whatever it was before the lookup operation. Regards, Martin Gilbert.
Last Wiki Answer Submitted:  April 9, 2009  10:42 am  by  KSoniat   610 pts.
All Answer Wiki Contributors:  KSoniat   610 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

If you like built-in functions, try %lookup.
For example, in free form RPG, X = %lookup(searchValue : Array)
X will be zero if searchValue is not found.
I think this also works with an EVAL statement in fixed format RPG.

 5,555 pts.

 

To confirm, all BIFs will also work in fixed format via the EVAL operation, although you would likely run into the dreaded column cram with a few of them, depending on the number of parameters and how long your variable names are. So, I’d rather be /Free.

 4,275 pts.

 

I agree with CWC – be /free if you can.
If that is not allowed in your shop I believe you can use the + (plus sign) to extend an EVAL statement to a second, third, fourth line as needed.

 5,555 pts.

 

You don’t need a plus sign in fixed or free-format RPG to extend code to new lines.

In /free format code, I have noticed that often the code becomes quite untidy and difficult to read – this is not a fault with free-format code, but in the attitude of the writer.

In fixed-column AND in free-format, I tend to align code when it extends to other lines – example below (which will be mucked up by the text editor!)….

       Eval      RtnData = EditFld( wkData        
                                  : dbffldb (I)   
                                  : wkFldType     
                                  : dbffldd (I)   
                                  : dbffldp (I)   
                                  : wkEdtCde      
                                  : '    '      ) 

Sloopy

 2,195 pts.

 

With either format, the plus sign to continue a line isn’t needed – but with free format, the compiler does need a semi colon to mark the end of each statement.

 4,275 pts.

 

Sorry Sloopy, I didn’t see that you had already elaborated on this.

 4,275 pts.

 

I got here before you for a change, Cwc!

 2,195 pts.

 

Hey Sloopy,

I saw your tip about the back loading of arrays. I applied it and I got a program that runs for about an hour down to about 15 minutes. That was an awesome tip! Thanks!

Now…

…In other words it will not change on an unsuccessful LOOKUP. You can use NOT %Found to test for a failure to find correct index.:…

For LOOKUP, the index value becomes 1 if it is unsuccessful. For %LookUp, the index value becomes 0.

Regards,

Alln

 560 pts.