First of all, a FLAT file is a Physical file.
I’m thinking your question is really “How do I know if a file is externally defined?”
Using RTVMBRD, you can determine if it is a PF or LF.
To deteremine if the file is externally defined, you could to do a DSPFFD to a work file in QTEMP. Then do a RTVMBRD of that workfile and check for number of records. If move than one, it would have an external definition (whick would be in the workfile).
There is an exception to this and that is if the file is a PF-SRC. Then it would have 3 fields.
It can depend on what you mean by “flat file”. There are generally three possible meanings of the term for AS/400 developers. One meaning relates to a type of mainframe file that would only be of interest to AS/400 developers who also work with mainframe functions, so we’ll ignore that one.
On an AS/400, a “flat file” could be either a “program-described” file or a streamfile. Since streamfiles are fundamentally different and clearly recognizable, we can probably assume that you mean a “program-described” file.
Generally, a “program-described” file is a physical file (PF) that was created without DDS (and without SQL DDL). Such a file has a record format with a single field. You can create one with a command such as:<pre>
CRTPF FILE( QTEMP/FLAT ) RCDLEN( 80 )</pre>
Here is an example ILE CL program that returns an indication that QTEMP/FLAT is a “program-described” file:<pre>
dcl &qfile *char 20
dcl &file *char 10 value( ‘FLAT ‘ )
dcl &lib *char 10 value( ‘QTEMP ‘ )
dcl &fd *char 512
dcl &lfd *int value( 512 )
dcl &pgmdBits *char 1
dcl &pdBit *uint value( 7 )
dcl &pdTyp *int value( -1 )
chgvar &qfile ( &file *cat &lib )
call QDBRTVFD ( +
‘ ‘ +
‘*FIRST ‘ +
‘*LCL ‘ +
‘*EXT ‘ +
chgvar &pgmdBits %sst( &fd 61 1 )
callprc ‘_TSTBTS’ ( +
( &pdBit *byval ) +
rtnval( &pdTyp )
The program takes the file name and library and creates a qualified file name. It passes that to the <a href=”http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/apis/qdbrtvfd.htm”>Retrieve Database File Description (QDBRTVFD) API</a> and asks for the File definition template (format FILD0100) to be returned.
At position 61 of the File definition template there is a bit field called Qaaf (Additional attribute flags). Bit 7 of that bit field is Qdbfpgmd (Program described file indicator).
Generally, you can test that byte to see if it’s equal to x’01′. If it is, then you have a program-described file. If the value is x’00′, then it’s an externally-described file.
However, the example program uses the <a href=”http://publib.boulder.ibm.com/infocenter/iseries/v5r4/index.jsp?topic=/rzatk/TSTBTS.htm”>Test Bit in String (TSTBTS)</a> MI builtin function to test bit 7 (the value from &pdBit) to get an on/off indication. The indication is returned in &pdTyp . The program tests the bit directly because IBM has the first bits of that bit field as ‘reserved’ — their values may change without prior notice to you. (They haven’t changed in maybe 20 years, but it’s better to expect changes.)
You should be able to compile the ILE CL example program. Paste it into a source member of type CLLE in PDM and compile with option 14. (Or just run CRTBNDCL over the member.) Then run the CRTPF command from above for QTEMP/FLAT and call the program in that job. The dump created by the program should show that &pdTyp returns the value 1.
If you change the values of &file and &lib to point to some file that you know is externally-described, the dump should show that &pdTyp returns the value 0.