Question

  Asked: Jun 20 2008   8:30 PM GMT
  Asked by: Doctor-job


SQL Fetch


Fetch, Join logical files, SQL

I an joing tow files with inner join. I want all the fields from the first file and only two fields from the other file. I defined an external DS for the first file then included that DS in another DS with the two fields from the other file but program will no compile. Will not read the last DS in the fetch statement.

RLS e ds extname(rs)

rd ds
fmt1 likeds(rls)
fmt2 30a
fmt3 2a

Fetch CSR into : rd does not work.
Any ideas why

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0



You need to use the keyword QUALIFIED on the DS specification for data structure RD :

RLS e ds extname(rs)

rd ds QUALIFIED
fmt1 likeds(rls)
fmt2 30a
fmt3 2a

Now your program will compile, BUT, I suspect that you will have problems with the SQL.

This is because the data structure is now qualified - that is, every field name in the structure is prefixed by the structure name. So, your FMT2 field is now called RD.FMT2 - and so SQL cannot match it with the names of the fields in the files it is referencing.

I'm afraid that you will have to do it the boring way, by creating a data structure (unqualified and not externally-described) with the names of all the fields explicitly stated as subfield names.

Or, you can create two externally-described data structures, one for each of the files you are reading from in your SQL, and then in the SELECT and FETCH statements you write the full explicit list of field names. This is the way I prefer to do it.

Regards,

Sloopy


Thanks you but I got it to work by just coding the two remaining fields at the end of the DS statement:

rd eds extname(rdlftm)
fmt1 30a
fmt2 2a.


From Sloopy:

Excellent! Do you know, I did not think you could do that - thanks for teaching me something new!

-- Sloopy
  • AddThis Social Bookmark Button

Browse more Questions and Answers on AS/400 and Development.

Looking for relevant AS/400 Whitepapers? Visit the Search400.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register

Mrdenny  |   Jun 20 2008  8:40PM GMT

It would be helpful if you said which programming language you are using.