IBMi (AS400) fans only ' How to access multimember physical file using SQL alias

#IBMiSample

Each IBMi user knows they run the most efficient system. All others just have too much money.



SQL has no direct access to IBM i multiple-member physical file but OS/400 support an SQL alias statement.

Therefore, I need to create an alias for the member I want to access with SQL.



I give an example using the IBM i PUB400 public server.

Work with members using PDM  on IBMi

In library VDOTEST1, file QDDSLF I have 8 members.
CLANA01L
CLANA02L
CLANA03L
CLANA04L
CLANA05L
CLANA06L
CNCON01L
OTORD01L


I want to access member CLANA03L via SQL.

I type STRSQL (Enter) then I create the ALIAS:



create alias A_CLANA03L for VDOTEST1.QDDSLF(CLANA03L)
SQL statement  on IBMi


The alias is a persistent object. The ALIAS object has attribute DDMF.

Work with object using PDM  on IBMi


Now I can access the member with SQL:

SQL statement  on IBMi


Display data from CLANA03L
Display data  on IBMi

Don't forget to remove the ALIAS with a "DROP" command:

DROP ALIAS myLibrary/myAlias

SQL statement  on IBMi

That’s it.




Thanks to the suggestion of my friend Don Anderson I add this way:

SELECT CAST(LINE AS CHAR(120))                     
FROM TABLE (                                      qsys2.ifs_read(path_name =>                        
'/qsys.lib/vdotest1.lib/qddslf.file/clana03l.mbr'))

SQL statement  on IBMi


Display data on IBMi



I appreciate all the comments made on this blog.






Comments

  1. I wish I could learn like this every day.

    ReplyDelete
  2. Thanks for the recognition Aldo! Cheers :) Don

    ReplyDelete

Post a Comment

Popular posts from this blog

IBMi (AS400) fans only ‘ Memories (IBM Coding Forms)

IBMi (AS400) fans only ' SQLCODE values: Dear readers, unleash your suggestions!