AS/400 Queries Are Easy As Pie

One of my all time favorite tools for creatingsecond fields listed will be from the secondary
reports, data lookup inquiry screens or custom filefiles.
downloads for the AS/400 and iSeries platformsNow that you have the files joined together and
is IBMs very own Query/400. This is amazing toolthe matching fields defined it is time to create the
is an additional licensed program but I find theconstraints by taking the option for select
cost worth it since it is a user friendly menurecords. Once on the select records screen simply
driven application and it makes creating customenter in the field you want to build the constraint
reports a snap.on along with the test condition such as equal, not
The first step is to actually create a Query/400equal, greater than, data range and so on and the
query definition by issuing the commandvalue. The value can be a constant, field name,
WRKQRY. And the first option is to specify thenumber or more.
file selections you will use for the query. This isOne feature I absolutely love about Query/400 is
where you tell query which file or files you will bethat if you are using multiple files it will
using to create your report, so you will specifyautomatically prefix all of the field names T01,
each file, library and member if the file hasT02 and so on. This makes it very easy to find
multiple members. If you need to add another filethe file and field name combination you wish to
simply press the F9 key.use and it completely eliminates problems with
Once you have specified the files it is time to letduplicate field names between files.
query know how it is going to join them together,Now that you have defined the query constraints
if you have any experience with SQL then thisit's time to actually run the report and see some
step should come naturally but if you aren'tdata results, this can be done any time you are in
familiar with SQL let me explain. The joinquery by using the F5 key. A word of caution
operation tells Query/400 which fields matchthough that if you are doing joins with multiple
between the selected files so it can query themfiles the system may need to build a temporary
together at the same time and present theindex and this can take awhile depending on the
resulting data set as if it is one large logical file. Ondata files in use and other factors used by the
the join field you will typically select eitherAS/400s query optimizer engine.
matched records or matched records withThe last step I usually take after running the
primary file. In all my years of writing Query/400query a few times using F5 and making sure the
queries I have not once needed to use thereport looks corect on the screen is to take the
unmatched records option.option to select output type and output form.
After choosing the matching type it is time to tellDepending on the desired output of the query I
query what fields you are going to match by.will either select a printable report or display
Simply type in the first field with the testoutput type. If you choose printer there will be
condition followed by the second matching field. Ifsome additional options to configure like the
you are using multiple files and matching recordsaddition or removal of a header page, which I
with the primary file the first set of match fieldstypically remove to save the wasted sheet of
will always be from the primary file and thepaper.