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 KSoniat610 pts.
If you live outside the United States, by submitting your email address you consent to having your personal data transferred to and processed in the United States.
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.
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.
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.
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!)….
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.
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.
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.
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.
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.
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
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.
Sorry Sloopy, I didn’t see that you had already elaborated on this.
I got here before you for a change, Cwc!
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