The Robot API is a new feature used to record any application flow against an AS400 through the normal 5250 interface. In the Studio create a special class ?5250 Robot which creates a normal Java class together with a script file with the .api extension. Open the .api file and type in the address to the AS400 and start record.
In and out parameters can be specified in the .api file The Java class is used to call and run the script with parameters. The main method contains example code how to call the script:
The Java class can also be used to handle unexpected screens in the flow. Screens can show up depending on some data in the system, the Java class can be used to identify when this happens and from code navigate back to the recorded flow. There is also a debug mode where each 5250 screen is displayed with step buttons.
Pooling is also supported, pooling keep the job open and the job starts to execute from a specific screen in the recorded flow. A start and stop screen is specified at recording time. When running in pooled and a new job is created the flow is played until the start mark after that the script is executed to the stop mark and returned to the pool. The AS400 job is now waiting at the end mark. When a new job is about to start the job is executed from that position to the end mark again and then returned to the pool. All job is closed when the pool is closed or when a job has been idle longer than the idle timeout. At closing the opened jobs are executed from the stop mark to the end of the script.
To summarize before the start mark is login and setup of environment and company etc. and after the stop mark is logoff.
1. Create Robot class
The class is called DemoChangeDataArea and the package is com.demo. Finish the create class wizard and two files are created. The Java class is used to run the script and pass parameters or retrieve data.
Open the .api file and enter the address to an AS400 to record against
Press new recording and go through all logon screens and setting up environment etc. At the command line we will start our flow that potentially can be executed over and over again, therefore we press "Start pool point" since this is the screen where we would like to start from when we have checked out the robot from the pool.
In this case we come to a command line where we enter chgdtaara end press F4
We change the dataarea xtellus/testdta the value is here set to dummy since this is the value we will pass in from the Java program
After pressing enter we are back at the command line and "Stop pool point" is pressed. After that simply logout until the login screen is displayed.
Press the "Save" button in the right bottom of the window.
The .api file (which is a normal xml file) is populated with request and response nodes. When selecting a request or response the AS400 screen is displayed at the right hand side.
Scroll down until the request where the data area is found
Select the dummy tag and mark this as a parameter, name it parm1. Any unique name will do but here it is named parm1
After the .api file is saved it is ready to be executed. Open DemoChangeDataArea and in the main(String) method sample code how to execute the script has been auto generated. First there are code generated how to execute the script from start to end and bellow that how to run it in pooled mode.
In this example the script is executed from start to end. RobotInput contains all input parameters and bellow the parm1 parameter is set to "demo value". After that the class DemoChangeDataArea which inherits from RobotAdapter is instantiated and the execute is called with RobotInput as the only parameter.
Run the class and the value in the data area at the AS00 is changed to "demo value"
The class contains a callback method that is called when a new screen arrives from the AS400. The first parameter is an XMLNode named response which contains the data from the AS400, the second parameter is the recorded node and the third boolean indicate if the returned screen is the expected recorded screen. This method can be used to collect returned data in the flow and also do manual navigation by sending new request to the server. This is useful if screens not shows up that where not part of the recorded flow.
Two other useful parameters in the execute and executePooled methods. If the debug parameter is set to true the emulator is displayed when the script is executed and each screen can be stepped