This post will be the final post in a series on IBM APIs. Since you have had a chance to run though some basic APIs we are going to go through a more complex example that gives you a chance to tie everything together.
In this example we are going to create a list of users that are signed on to an IBMi. The list will be dynamically created at the time the API is called. These examples are RPGIV based
Create a Structure file called API Functions. This structure file will be the place to put all the API definitions. Create two User Source functions. One is to CVT BIN to DEC and the second is to CVT Dec to BIN. E into each function if found and add the source code below for the respective function.
Convert Binary to Decimal source code.
Convert Decimal to Binary source code.
Create an API Call Wrappers for each of the three APIs that will be used.
In the API Functions file add the needed functions. The source name for each of these should be the IBMi native program name.
1. API:List Signed on Users
2. API: Create User Space
3. API: Delete User Space
Create three Arrays for managing parameters.
1. P:API Error Structure
2. P:API List Entry Value
3. P:API List LoggedIn Users
Now, create the internal functions that will be called in the 2E programs.
These Internal Functions will contain the steps necessary to call the API programs. You will need functions to do the following actions.
1. Create User Space
2. Delete User Space
4. Retrieve User Space Details
5. List Active Users
Assemble the Functions and Create Display
Now all the functions are created that need to be assembled a way to display the contents of the User Space. We are going to use a temporary file that only contains a sequence number. We will write sequence numbers to this file in QTEMP and then use the file to display the actual contents of the user space written for the List Active Users API. In our demonstration, we will do the following:
1. Create External function that will put the results file in QTEMP. The function needs to copy the DSR Display Results file into QTEMP. Call our Display File to display the List of Active Users and then delete the User Space and DSR Display Results file from QTEMP.
2. Create a Display File over DSR Display Results with a screen display similar to this.
3. Add the following actions in the Initialize.
Call the List Active Users API.
Call the RTV User Space header API.
Set the LCL DSR Sequence to Zero.
Perform a loop to and create records in the DSR Display Results file. The LCL DSR Sequence will indicate the number of users to list.
a. Retrieve the User Space Entry.
Check to see if there is a value in field Userspace Entry 1-250. If there is a value we have a good record so we must substring the values.
b. Substring the Display station
c. Substring the User ID
d. Substring the User Job
e. Substring the Activity
5. Compile the programs and test. The first time the API runs, it can take a bit of time. You should get a display of all the active users on the IBMi at the time you run the program.
This was a quick walk through of using IBM APIs with 2E. It can give you a basic framework to use in developing applications that use APIs. Once you integrate the API to 2E any developer can now use what you have created and be up and coding.