Using an array in embedded SQL in RPGLE

1410 pts.
Tags:
Application development
DB2 Universal Database
Development
RPGLE
SQL
Is there a way to specify a host array element in a where clause in embedded SQL? This is what I am trying to do: C+ Where TkPart01 = :odPart(01) C+ and TkQty01 = :odQty(01) C+ and TkPart02 = :odPart(02) C+ and TkQty02 = :odQty(02) There's more to it than that but that should give you the general idea. The message I get is that the variable is either not defined or not usable. Yes, I've read the manual and it says that you can't use a multi-dimension array, which implies that you can use a one-dimension array.

Answer Wiki

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

As far as I know, SQL has no way to subscript your host variable and therefore no way to reference an array element directly. I always move the array element into a work field, execute the SQL statement, and then put the work field back into the array element (if needed).

Discuss This Question: 2  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
  • JDMurray
    Try using datastructure overlays to give each array element a unique variable name: D odParts DS D odPart01 9 D odPart02 9 D odPart03 9 D odPart04 9 D odPart05 9 D odPart06 9 D odPart07 9 D odPart08 9 D odPart09 9 D odPart10 9 D odPart11 9 D odPart12 9 D odPart13 9 D odPart14 9 D odPart15 9 D odPart16 9 D odPart17 9 D odPart18 9 D odPart19 9 D odPart20 9 D arParts 9 Dim(20) D Overlay(odParts) Then use Where TkPart01 = odPart01 in your sql and still use the array in RPG. This assumes that you will always want to put arParts(01) into TkPart01. If you are really looking for TkPart=arParts(x) then the previous reply is going to be best.
    0 pointsBadges:
    report
  • SteveCCNJ
    In my experience, the SQL precompiler can't successfully resolve to subfields in a data structure either. If someone gets it to work, I would love to see it.
    0 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