December 11, 2013

In part one of this series, we looked at calling an IBMi API with an RPG user program.  It would be nice to call the same API directly from 2E but in this case, it does not work. That is because the API is not a program we can call directly.  You can see this by the name of the API – access().  For us to call it simply with 2E, we need it to be a program.

Let’s look at another simple example of an API called QUSCMDLN.  This API can be added to 2e and allow you to call a command line within a program.  If you do a WRKOBJ on this API, you also find it in SYS and a type of Program.  Since we find it as a program, we know it will be an API that can be called directly in 2E.

In order to set this up in 2E, there are a few simple steps to follow:

1. Create a User Program.

2. Z into the User program and change the Program to QUSCMDLN.

3. Define any parameters that are needed.  In the case of this API, there are no needed parameters.  Once you have defined the API in 2E, it can be called from a function.


We will use a Prompt Record as our sample program. Create a simple prompt record similar to the illustration below.


Add code into the action diagram user point User defined action.  The code should call the API QUSCMDLN function.  There are no parameters to include in this call.


Now, generate and compile the function and call it from the command line.


Finally, use the F10 command key or the key you defined in your action diagram to call the API.  The API will create a popup window command line.  With this API, you are easily able to add command line capability from within functions in your application.