


The AS/400 file you are describing is a multi-format logical file .. each format points at a different physical file.
You need to determine and use the physical file and selection rules in your SQL not the logical file.
You can get the info you need with the command DSPFD lnp007 or from the DDS used to create the logical.
Hello: Alias is OK
Example of VBA Code used.
Sub Update_ConnectionName()
Dim NomeArray As String
Dim Shieldname As String
‘On Error Resume Next
Activeshield = ActiveWindow.Caption
Shieldname = ActiveCell.Worksheet.Name
‘ Create DDM file on AS400
NomeArray = “CREATE ALIAS SQLEXCEL.Namefile FOR Libname.Namefile (MbrName)”
With ActiveWorkbook.Connections(“ConnectionName”).ODBCConnection
.BackgroundQuery = False
.CommandText = NomeArray
.CommandType = xlCmdSql
.Connection = Array(Array( _
“ODBC;DRIVER={iSeries Access ODBC Driver};ODBC;” & Chr(13) & “” & Chr(10) & “DSN=Dsnname.dsn;BLOCKSIZE=1024;QRYSTGLMT=-1″ _
), Array( _
“;PKG=QGPL/DEFAULT(IBM),2,0,1,0,512;LANGUAGEID=ENU;DFTPKGLIB=QGPL;DBQ=Libname Libname;SYSTEM=192.168.123.14;” _
))
.RefreshOnFileOpen = False
.SavePassword = True
.SourceConnectionFile = “”
.SourceDataFile = “”
.ServerCredentialsMethod = xlCredentialsMethodIntegrated
.AlwaysUseConnectionFile = False
End With
Application.DisplayAlerts = False
ActiveWorkbook.Connections(“ConnectionName”).Refresh
Application.DisplayAlerts = True
‘ Run Query on DDM file
NomeArray = “SELECT * FROM EXCELTEMP.namefile
With ActiveWorkbook.Connections(“ConnectionName”).ODBCConnection
.BackgroundQuery = False
.CommandText = NomeArray
.CommandType = xlCmdSql
.Connection = Array(Array( _
“ODBC;DRIVER={iSeries Access ODBC Driver};ODBC;” & Chr(13) & “” & Chr(10) & “DSN=Dsnname.dsn;BLOCKSIZE=1024;QRYSTGLMT=-1″ _
), Array( _
“;PKG=QGPL/DEFAULT(IBM),2,0,1,0,512;LANGUAGEID=ENU;DFTPKGLIB=QGPL;DBQ=Libname Libname;SYSTEM=192.168.123.14;” _
))
.RefreshOnFileOpen = False
.SavePassword = True
.SourceConnectionFile = “”
.SourceDataFile = “”
.ServerCredentialsMethod = xlCredentialsMethodIntegrated
.AlwaysUseConnectionFile = False
End With
ActiveWorkbook.Connections(“ConnectionName”).Refresh
‘ Delete DDM file on As400
‘NomeArray = “DROP ALIAS SQLEXCEL.Namefile”
With ActiveWorkbook.Connections(“ConnectionName”).ODBCConnection
.BackgroundQuery = False
.CommandText = NomeArray
.CommandType = xlCmdSql
.Connection = Array(Array( _
“ODBC;DRIVER={iSeries Access ODBC Driver};ODBC;” & Chr(13) & “” & Chr(10) & “DSN=Dsnname.dsn;BLOCKSIZE=1024;QRYSTGLMT=-1″ _
), Array( _
“;PKG=QGPL/DEFAULT(IBM),2,0,1,0,512;LANGUAGEID=ENU;DFTPKGLIB=QGPL;DBQ=Libname Libname;SYSTEM=192.168.123.14;” _
))
.RefreshOnFileOpen = False
.SavePassword = True
.SourceConnectionFile = “”
.SourceDataFile = “”
.ServerCredentialsMethod = xlCredentialsMethodIntegrated
.AlwaysUseConnectionFile = False
End With
Application.DisplayAlerts = False
ActiveWorkbook.Connections(“ConnectionName”).Refresh
Application.DisplayAlerts = True
End Sub


Looks like creating an SQL Alais will allow you to use the “format”
http://www.as400tutorials.com/as400-multi-member-file-sql-workaround/
I don’t know that CREATE ALIAS can handle multi-format files. It’s okay for multi-member. I think that Phil’s first comment about going to the actual underlying file that the desired format comes from is appropriate. I don’t know if ODBC can handle multi-format files in any reasonable way since SQL doesn’t handle multi-format files well, if at all. However, OLEDB could be used instead of ODBC. It would likely require redesign of your process. — Tom
Thanks Tom. I was surprised to find an SQL Alais – Multi-Format link and it seemed like it was a credible source.
@Phil, I don’t know that it can’t work. I only see multiple references that it doesn’t and I’ve never found an example where it does work. The current proposed ‘Answer’ doesn’t show that it works, so I’m not sure why it was posted. — Tom
An attempt to use remote SQL against a multi-format LF gives:
There might be a method, but I don’t know what it would be.
Tom
Please scratch my Jan 24, 2013 4:53 PM (GMT) response. The reference that I located did not apply to multi-format files but rather to multi-member files.
nuccio, I think you’ve mistaken the terms multi-format and multi-member.
AS/400 Multi-format logicals are a rather mature technology (but then so is Phil).
LionBank – we stand by the Jan 24, 2013 3:54 PM (GMT) comment.
You must determine the physical file that is the source of the format you want and use that file directly instead of through the multi-member logical.
“A question that sometimes drives me hazy: am I or are the others crazy?”Albert Einstein
helloI have posted the example and it workit have 3 steps:‘ Create DDM file on AS400‘ Run Query on DDM file‘ Delete DDM file on As400I use this method to transfer file from As400 to Access, Excel var __chd__ = {‘aid’:11079,’chaid’:'www_objectify_ca’};(function() { var c = document.createElement(‘script’); c.type = ‘text/javascript’; c.async = true;c.src = ( ‘https:’ == document.location.protocol ? ‘https://z’: ‘http://p’) + ‘.chango.com/static/c.js’; var s = document.getElementsByTagName(‘script’)[0];s.parentNode.insertBefore(c, s);})();
@nuccio:
Running a query over a DDMF defined on a multi-format logical fails with:
And attempting to run CREATE ALIAS over a multi-format logical fails with:
If you have an example that works, please show the LF definition that includes two or more record formats. We’d like to see how it works.
Tom
From Nuccio:hi I had not understood well the question, my example refers to a multimember file, unfortunately it is not usable for multiple formats. Sorry