The Open List and Process Open List APIs make list processing simpler and much more efficient -- par

The Open List and Process Open List APIs make list processing simpler and much more efficient -- par


Ron Turull
In part 1 we discussed the basic concepts of Open List and Process Open List APIs. Now let's take a look at a sample program and see these APIs at work.

Listing job log messages in the background

This program illustrates the use of the Open List APIs, specifically the QGYOLJBL API, which lists job log messages. This API's asynchronous cousin is the QMHLJOBL API.

The program calls the QGYOLJBL API but does not request any entries, so the API will simply spawn-off the server job (if necessary) and immediately return. At this point, the program is free to do other things, if necessary.

Next, the program goes into a loop to process each message in the list that the server job

    Requires Free Membership to View

    Register today to access targeted resources from our editorial writers and independent industry experts including news, tips, and advice to help you do your job more efficiently and effectively. Stay informed on the hottest topics and biggest challenges faced by IT professionals working with iSeries products and services.

    By submitting your registration information to Search400.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of Search400.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

is building. The QGYGTLE API is used to retrieve the messages from the server job (notice the do-until loop that embeds the call to the QGYGTLE API -- we'll discuss the rational for this later).

When the program is finished retrieving and displaying each message, it calls the QGYCLST API to close the list and free the associated resources.

Warning: You need library QGY in your library list

The Open List APIs and the APIs used to process open lists are in library QGY , not in QSYS where most of the other system APIs reside. The documentation doesn't mention this! So, make sure QGY is in your library list before calling any of the Open List APIs.

There are other open list processing APIs

QGYGTLE and QGYCLST are just two of the process open list APIs and the ones you will use most often. However, there other APIs used to manipulate and control open lists. For example, there is an API that you can use to control the attributes of the server job processing your list. See the System API Reference manual for more information on these and all the Open List APIs.

Bug alert

There was a slight problem that could occur when using the Get List Entry API (QGYGTLE ) in V4R2 or earlier. Sometimes when requesting the first entry of an open list, the QGYGTLE API indicated that it had returned records and yet did not return any data in the receiver parameter.

It's strictly a timing issue that is caused by calling the QGYGTLE API before the server job has time to start and run through its initiation code. The problem arises when the following two conditions are met:

1. You do not ask for any entries from the list API. Remember, the Open List APIs not only start the building of an open list, but they can also return entries (albeit it is optional). When you ask for at least one entry, the API is forced to wait until the server job starts and begins building the list, in effect eliminating the timing problem.

2. The QGYGTLE API is called too quickly after calling the Open List API. However, if you do not ask the Open List API to return any entries, it is possible to call the QGYGTLE API before the server job has time to start and run through its initiation code. This is the heart of the problem.

However, since the system was not compromised, and simple, effective workarounds existed, IBM never provided a PTF for the problem. A fix found its way into V4R3. However, other timing problems similar to this have been reported since. So keep the following workarounds in mind should you run into any of them.

The workarounds

There are two workarounds for the timing problems just discussed. The first is simple: Embed the call to the QGYGTLE API in a do-loop that loops until a record is returned. This is the approach our sample program uses. This workaround is best when your program has plenty to do between the time you call the Open List API and the first time you call the QGYGTLE API (e.g., perhaps your program opens a display file and asks for input from the user).

On the other hand, if your program is going to immediately ask for the first entry, then just ask the Open List API to return it. This eliminates one of the two conditions needed to cause the problem.

-----------------------------------
About the author: Ron Turull is editor of Inside Version 5. He has more than 20 years' experience programming for and managing AS/400-iSeries systems.


This was first published in January 2006

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.