Embedded SQL in SQLRPGLE using JOIN on multiple files

pts.
Tags:
IBM DB2
RPG ILE
Greetings, In the past I've used embedded SQL in an SQLRPGLE program and on the FETCH INTO statement I specify an externally defined data structure with the definition of the file I am SQLing thus allowing me to read in the entire record's fields mapped correctly in one FETCH INTO statement... This works great when you're SQLing one file... I'm currently joining 5 files together and I would like to capture the content of all 5 record's fields mapped correctly using one FETCH INTO statement...? Can I use this same trick when joining two or more files...? Can this be done or am I barking up the wrong tree...? Thanks.

Answer Wiki

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

I have done this before with JOIN on multiple files with no problems. Just make sure the data structure you fetch into is defined to match the fields on your SELECT.

All fields will be defined in the same data structure. This makes it kind of hard to just define the data structure externally to match a particular file layout. Are you pulling in all fields from each file in the join? You could create a dummy file containing all fields from each file being joined in the order the SELECT pulls them in and then use this empty file just to define the data structure.

The one problem you might run into when joining depends on if you are doing a straight join or a left join. With a left join you could get null values pulled in on secondary file fields and if you don’t define the fields on your SELECT with an IFNULL or COALESCE to set the input data to zeros or blanks, this could cause a problem on the fetch.

Sorry but this does not answeer the question of how to join more than 2 files

Discuss This Question:  

 
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

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