3.1.4 Sample LANSA RDML Client Programs
Following is a very simple LANSA function that opens and then closes a connection to the JSM. If an error occurs, the status and message are displayed. This program does not use any services.
For further examples of RDML client applications, refer to Client Application Examples.
Example 1 - Using default (JSMCLTDTA data area)
FUNCTION OPTIONS(*DIRECT)
*
DEFINE FIELD(#JSMSTS) TYPE(*CHAR) LENGTH(20)
DEFINE FIELD(#JSMMSG) TYPE(*CHAR) LENGTH(256)
DEFINE FIELD(#JSMCMD) TYPE(*CHAR) LENGTH(256)
*
USE BUILTIN(JSM_OPEN) TO_GET(#JSMSTS #JSMMSG)
IF COND('#JSMSTS *NE OK')
DISPLAY FIELDS(#JSMSTS #JSMMSG)
ENDIF
*
USE BUILTIN(JSM_CLOSE) TO_GET(#JSMSTS #JSMMSG)
IF COND('#JSMSTS *NE OK')
DISPLAY FIELDS(#JSMSTS #JSMMSG)
ENDIF
Example 2 - Using server argument
FUNCTION OPTIONS(*DIRECT)
*
DEFINE FIELD(#JSMSRV) TYPE(*CHAR) LENGTH(50)
DEFINE FIELD(#JSMSTS) TYPE(*CHAR) LENGTH(20)
DEFINE FIELD(#JSMMSG) TYPE(*CHAR) LENGTH(256)
DEFINE FIELD(#JSMCMD) TYPE(*CHAR) LENGTH(256)
*
CHANGE FIELD(#JSMSRV) TO('LOCALHOST:4560')
*
USE BUILTIN(JSM_OPEN) WITH_ARGS(#JSMSRV)TO_GET(#JSMSTS #JSMMSG)
IF COND('#JSMSTS *NE OK')
DISPLAY FIELDS(#JSMSTS #JSMMSG)
ENDIF
*
USE BUILTIN(JSM_CLOSE) TO_GET(#JSMSTS #JSMMSG)
IF COND('#JSMSTS *NE OK')
DISPLAY FIELDS(#JSMSTS #JSMMSG)
ENDIF
The following example shows how the JSM BIFs are used together and in what order. This is not a complete RDML function. In this example JSM_OPEN opens a connection to the Java Service Manager and starts a thread.
A series of JSM_COMMANDs are issued to:
- Load the FTPService service
- Connect to the host
- Login using the specified user/password
- Change the directory path
- Set mode to binary
- Put the file to the FTP site
- Quit the FTP session
- Unload the service.
JSM_CLOSE ends the connection.
FUNCTION OPTIONS(*DIRECT)
DEFINE FIELD(#JSMSRV) TYPE(*CHAR) LENGTH(50)
DEFINE FIELD(#JSMSTS) TYPE(*CHAR) LENGTH(20)
DEFINE FIELD(#JSMMSG) TYPE(*CHAR) LENGTH(256)
DEFINE FIELD(#JSMCMD) TYPE(*CHAR) LENGTH(256)
USE BUILTIN(JSM_OPEN) TO_GET(#JSMSTS #JSMMSG)
USE BUILTIN(JSM_COMMAND) WITH_ARGS('SERVICE_LOAD SERVICE(FTPSERVICE)') TO_GET(#JSMSTS #JSMMSG)
USE BUILTIN(JSM_COMMAND) WITH_ARGS('CONNECT HOST(LOCALHOST)') TO_GET(#JSMSTS #JSMMSG)
USE BUILTIN(JSM_COMMAND) WITH_ARGS('LOGIN USER(user) PASSWORD(code)') TO_GET(#JSMSTS #JSMMSG)
USE BUILTIN(JSM_COMMAND) WITH_ARGS('CHGDIR PATH(/JSM)') TO_GET(#JSMSTS #JSMMSG)
USE BUILTIN(JSM_COMMAND) WITH_ARGS('BINARY') TO_GET(#JSMSTS #JSMMSG)
USE BUILTIN(JSM_COMMAND) WITH_ARGS('PUT FROM(file) TO(/TMP/DIR/file)') TO_GET(#JSMSTS #JSMMSG)
USE BUILTIN(JSM_COMMAND) WITH_ARGS('QUIT') TO_GET(#JSMSTS #JSMMSG)
USE BUILTIN(JSM_COMMAND) WITH_ARGS('SERVICE_UNLOAD') TO_GET(#JSMSTS #JSMMSG)
USE BUILTIN(JSM_CLOSE) TO_GET(#JSMSTS #JSMMSG)