• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • API Corner: Database APIs

    September 28, 2005 Shannon O'Donnell

    The code for this article is available for download.

    If you want to gather some information about an OS/400 database, there are several ways you can go about it. You could use the DSPFD (Display File Description) command to display top level information about a file. Or you could use the DSPFFD (Display File Field Descriptions) command to display information about each field. However, neither command has a very convenient method of getting the resulting information into a format that can be easily used by your applications. To do that, you need to use the database APIs.

    The Database APIs

    There are several database APIs that you can access to retrieve the specific types of information you are most interested in:

    • QDBLDBR: List Database Relations
    • QUSLRCD: List Record Formats
    • QUSMBRD: Retrieve Member Description
    • QUSLFLD: Retrieve File Field Information

    In addition, there is a very handy API, QUSLOBJ (List Objects), which you can use to retrieve a list of OS/400 *FILE objects into a user space, which can then be displayed and acted upon by your application program.

    For this article, I have written a series of four RPGLE programs which use all five of these APIs. The combined programs can be used independently or can be all executed in a chained fashion, as they are in the code samples for this article, to create a very handy OS/400 database file information utility.

    The four programs are:

    • LSTFILR1: This program uses the QUSLOBJ and QUSMBRD APIs to build a list of physical files from a specific, user selected library, into a user space. The output from this program is very similar to the WRKOBJ (Work with Objects) command.
    • LSTDBRR1: This program uses the QDBLDBR API to list the database relations for a selected file into a user space object. The output from this program is very similar to the DSPDBR (Display Database Relations) command.
    • LSTFMTR1: This program uses the QUSLRCD API to create a list of record formats, for a user specified file, into a user space object.
    • LSTFLDR1: This program uses the QUSLFLD API to create a list of file field information into a user space, for a user selected file. The output from this program is very similar to the DSPFFD (Display File Field Descriptions) command.

    The Mechanics

    The mechanics of how all these programs work is very similar to how all the other list API programs that have appeared in previous API Corner articles in this newsletter. Because they are so similar, I will not repeat all that information here. Instead, I will highly recommend that you go back and read any of those previous API Corner articles if you have any questions about how to use list APIs such as those used in the four programs described in this article.

    Instead, I will briefly describe the architecture of this utility and then you can download the source code for each of these and compile them on your own system to try them out.

    Remember, if you so desire, you can run each of these programs as standalone entities. However, I find that the database APIs are most useful when used in conjunction with other database APIs. Therefore, I’ve tied all these programs together in a somewhat logical order.

    When you’ve compiled the programs on your system, start the utility by calling the LSTFILR1 program (CALL LSTFILR1). You will be prompted to enter the name of a library that you want to get a list of physical files for. When you enter this library name and press Enter on this screen, the QUSLOBJ API will be executed, retrieving a list of *FILE objects for your selected library, into a user space. The user space will then be read, extracting each returned entry and testing it to make sure that it’s a file type of “PF” (physical file) and that it is a data file. The data file test is accomplished by passing the retrieved file name to the QUSMBRD API to determine whether this file is a data file or a source file. If it’s a data file, it will be written to the subfile.


    From the resulting subfile list, you can now choose to display the database relations for any file in this list, or display the record formats for any file in this list. When you select the display database relations option, program LSTDBRR1 will be called, passing to it the file selected, and the library name it resides in.

    LSTDBRR1 will execute the QDBLDBR API to retrieve a list of dependent files and display them in a subfile. From this new subfile, you can choose to display the record formats of the returned logical file.

    Regardless of how you got here, when you choose to display the file record formats, program LSTFMTR1 will be called, passing to it the library and file name selected. This program will then list the record formats for this file into the subfile. You can now choose to display the fields defined for this record format by selecting a record format from the subfile and pressing the Enter key.

    To display the file fields, the LSTFLDR1 program is called, passing to it the library, file name and record format name selected. LSTFLDR1 will then execute the QUSLFLD API to list the fields into a subfile. The returned information will contain some basic information about each field defined for that record format.

    Extending the Utility

    Each of the database APIs described in these programs can return much, much more information than is included in the utility. In fact, you will probably want to extend the utility to display more information, such as change and save dates, as well as more detailed information about each field. Each API’s receiver variable has already been pre-defined in its entirety in each program, for your convenience. All you need to do is add that data to the subfiles.

    RELATED RESOURCE

    API Corner: List Spooled Files From an Application

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    WorksRight Software

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.com

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    MaxAv’s New Wizard Simplifies Remote Journaling Setup Bsafe Steps Forward with New OS/400 Security Tools, Partners

    One thought on “API Corner: Database APIs”

    • Sai Krishna says:
      March 29, 2019 at 8:42 am

      The Programs run nice. But there is issue while LSTFLDR1 getting invoked.

      The call to *LIBL/LSTFLDR1 ended in error (C G D F).

      Message ID . . . . . . : RNQ0202 Severity . . . . . . . : 99
      Message type . . . . . : Inquiry
      Date sent . . . . . . : 03/29/19 Time sent . . . . . . : 08:37:24

      Message . . . . : The call to *LIBL/LSTFLDR1 ended in error (C G D F).
      Cause . . . . . : RPG procedure LSTFMTR1 in program SKESA/LSTFMTR1 at
      statement 029900 called program or procedure *LIBL/LSTFLDR1, which ended in
      error. If the name is *N, the call was a bound call by procedure pointer.
      Recovery . . . : Check the job log for more information on the cause of the
      error and contact the person responsible for program maintenance.
      Possible choices for replying to message . . . . . . . . . . . . . . . :
      D — Obtain RPG formatted dump.
      S — Obtain system dump.
      G — Continue processing at *GETIN.
      C — Cancel.
      F — Obtain full formatted dump.

      JOBLOG:
      Ownership of object LSTFILE in QTEMP type *USRSPC changed.
      Ownership of object LRCDFMT in QTEMP type *USRSPC changed.
      LSTFLDR1 was called recursively.
      Function check. RNX8888 unmonitored by LSTFLDR1 at statement *N,
      instruction X’0000′.
      The call to *LIBL/LSTFLDR1 ended in error (C G D F).
      The call to *LIBL/LSTFLDR1 ended in error (C G D F).

      Reply

    Leave a Reply Cancel reply

Volume 5, Number 36 -- September 28, 2005
THIS ISSUE
SPONSORED BY:

T.L. Ashford
WorksRight Software
Profound Logic Software

Table of Contents

  • API Corner: Database APIs
  • SQL Record Selection with Dynamic Lists
  • Admin Alert: Limiting the Long Reach of OS/400 Security Officers

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • POWERUp 2025 –Your Source For IBM i 7.6 Information
  • Maxava Consulting Services Does More Than HA/DR Project Management – A Lot More
  • Guru: Creating An SQL Stored Procedure That Returns A Result Set
  • As I See It: At Any Cost
  • IBM i PTF Guide, Volume 27, Number 19
  • IBM Unveils Manzan, A New Open Source Event Monitor For IBM i
  • Say Goodbye To Downtime: Update Your Database Without Taking Your Business Offline
  • i-Rays Brings Observability To IBM i Performance Problems
  • Another Non-TR “Technology Refresh” Happens With IBM i TR6
  • IBM i PTF Guide, Volume 27, Number 18

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle