LOOKUP

1150 pts.
Tags:
RPG
RPG LOOKUP
when lookup is unsuccessful what is the value of array index?

Answer Wiki

Thanks. We'll let you know when a new response is added.

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.

Discuss This Question: 8  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • WoodEngineer
    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.
    6,275 pointsBadges:
    report
  • Cwc
    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,290 pointsBadges:
    report
  • WoodEngineer
    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.
    6,275 pointsBadges:
    report
  • Sloopy
    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 pointsBadges:
    report
  • Cwc
    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,290 pointsBadges:
    report
  • Cwc
    Sorry Sloopy, I didn't see that you had already elaborated on this.
    4,290 pointsBadges:
    report
  • Sloopy
    I got here before you for a change, Cwc!
    2,195 pointsBadges:
    report
  • bogeybetsy
    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 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following