Step 2 Build the JSM Commands for the FTP Service

LANSA Integrator

Step 2. Build the JSM Commands for the FTP Service

INT003 - Using the FTP Service

In this step, working with function iiiFN03, you will use the template BBJSMXCMD to build the JSM commands to perform the following tasks using the FTP service:

  • Connect to a FTP site
  • Login with a userid and password
  • Set the directory
  • List the files in the path specified
  • Quit the FTP site.

Using the BBJSMXCMD template, you will use the following command, keywords and values:

Command

Keyword

Value

Working List

CONNECT

HOST

#S_218HOST

 

LOGIN

USER

#S_218USER

 

PASSWORD

#S_218PSWD

CHGDIR

PATH

#S_218DIR

 

LIST

DIR

 

WL_218

QUIT

 

 

 

 

 

1.  Working with your iiiFN03 function, execute a template BBJSMXCMD:

a.  Before you begin position the cursor at the start of the comment line after the YOUR OWN LOGIC HERE comment, then on the Design ribbon, click on the Template Wizard button.

b.  From the list of templates select BBJSMXCMD.

c.  Answer the template questions as shown in the table following:

Question

Answer

Comments

Use this template to build a command in a function generated by JSMXSKEL.

Press Enter to continue

This is an informative panel.

Type in the JSM command you want to build.

CONNECT

 

How many keywords do you want to specify?

1

 

Type in the keyword name.

HOST

 

Type in the value for the HOST keyword.

#S_218HOST

The Host value entered on the screen.

Type in the name of a working list if this command uses one.

Press ENTER

No working list is required by this command

Do you wish to enter another JSM command?

Y

 

Type in the JSM command you want to build.

LOGIN

 

How many keywords do you want to specify?

2

 

Type in the keyword name.

USER

 

Type in the value for the USER keyword.

#S_218USER

The User value entered on the screen.

Type in the keyword name.

PASSWORD

 

Type in the value for the PASSWORD keyword.

#S_218PSWD

The Password value entered on the screen.

Type in the name of a working list if this command uses one.

Press ENTER

No working list is required by this command

Do you wish to enter another JSM command?

Y

 

Type in the JSM command you want to build.

CHGDIR

 

How many keywords do you want to specify?

1

 

Type in the keyword name.

PATH

 

Type in the value for the PATH keyword.

#S_218DIR

The path entered on the screen.

Type in the name of a working list if this command uses one.

Press ENTER

No working list is required by this command

Do you wish to enter another JSM command?

Y

 

Type in the JSM command you want to build.

LIST

 

How many keywords do you want to specify?

1

 

Type in the keyword name.

PATH

 

Type in the value for the PATH keyword.

Blank out the field holding the previous value entered and Press ENTER

This keyword does not require a value.

Type in the name of a working list if this command uses one.

WL_218

The working list to get the list of files back.

Do you wish to enter another JSM command?

Y

 

Type in the JSM command you want to build.

QUIT

 

How many keywords do you want to specify?

0

This command has no keywords.

Do you wish to enter another JSM command?

N

 

 

 

d.  Once the BBJSMCMD template has completed, you will have all of the required code for working with the FTP service.

     Your RDMLX code might appear as:

* BUILD THE JSM COMMAND
#JSMXCMD := CONNECT
EXECUTE SUBROUTINE(KEYWRD) WITH_PARMS(#JSMXCMD HOST #S_218HOST)
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMSTS #JSMMSG)
EXECUTE SUBROUTINE(CHECK_STS) WITH_PARMS(#JSMXCMD)
*
#JSMXCMD := LOGIN
EXECUTE SUBROUTINE(KEYWRD) WITH_PARMS(#JSMXCMD USER #S_218USER)
EXECUTE SUBROUTINE(KEYWRD) WITH_PARMS(#JSMXCMD PASSWORD #S_218PSWD)
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMSTS #JSMMSG)
EXECUTE SUBROUTINE(CHECK_STS) WITH_PARMS(#JSMXCMD)
*
#JSMXCMD := CHGDIR
EXECUTE SUBROUTINE(KEYWRD) WITH_PARMS(#JSMXCMD PATH #S_218DIR)
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMSTS #JSMMSG)
EXECUTE SUBROUTINE(CHECK_STS) WITH_PARMS(#JSMXCMD)
*
#JSMXCMD := LIST
EXECUTE SUBROUTINE(KEYWRD) WITH_PARMS(#JSMXCMD PATH *BLANKS)
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMSTS #JSMMSG #WL_218)
EXECUTE SUBROUTINE(CHECK_STS) WITH_PARMS(#JSMXCMD)
*
#JSMXCMD := QUIT
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMSTS #JSMMSG)
EXECUTE SUBROUTINE(CHECK_STS) WITH_PARMS(#JSMXCMD)
 

Your complete RDML/RDMLX code might appear as follows:

iiiFN04:

* =======================================================
* Copyright .....: (C) LANSA, 1989
* Process .......: IIIPRO02
* Function ......: IIIFN04
* Created by ....: PCXUSER
* Created on ....: 08/06/23 at 10:58:57
* Description ...: Display FTP Service
* =======================================================
* Working fields, lists and groups
* =======================================================
DEFINE FIELD(#W_TYPE) TYPE(*CHAR) LENGTH(1) DESC('Type of file')
DEFINE FIELD(#W_FILE) TYPE(*CHAR) LENGTH(80) COLHDG('File Name')

DEF_LIST NAME(#WL_218) FIELDS(#W_TYPE #W_FILE) TYPE(*WORKING) ENTRYS(500)
DEF_LIST NAME(#BL_218) FIELDS(#W_FILE) ENTRYS(500)

* Group for all input fields
DEFINE FIELD(#S_218DIR) TYPE(*CHAR) LENGTH(200) DESC('FTP Directory')
GROUP_BY NAME(#GB_PNLDTA) FIELDS(#S_218HOST #S_218DIR #S_218USER #S_218PSWD)
*
* =======================================================
* Program Mainline : IIIFN04
* =======================================================
*
FUNCTION OPTIONS(*DIRECT)

BEGIN_LOOP
REQUEST FIELDS(#GB_PNLDTA) BROWSELIST(#BL_218)
CLR_LIST NAMED(#WL_218)
CLR_LIST NAMED(#BL_218)
EXCHANGE FIELDS(#GB_PNLDTA)
CALL PROCESS(*DIRECT) FUNCTION(#IIIFN03) PASS_LST(#WL_218)
SELECTLIST NAMED(#WL_218)
ADD_ENTRY TO_LIST(#BL_218)
ENDSELECT
END_LOOP 

iiiFN03:

* ====================================================

*  Process ........:  JMIPRO02

*  Function .......:  JMIFN03
*  Created on .....:  08/11/13  at  15:11:06
*  Description ....:  Use FTP Service
*  Template........:  JSMXSKEL
* ====================================================
FUNCTION OPTIONS(*DIRECT) RCV_LIST(#wl_218)
DEFINE FIELD(#W_TYPE) TYPE(*CHAR) LENGTH(1) DESC('Type of file')
DEFINE FIELD(#W_FILE) TYPE(*CHAR) LENGTH(80) COLHDG('File Name')
DEF_LIST NAME(#WL_218) FIELDS(#W_TYPE #W_FILE) TYPE(*WORKING) ENTRYS(500)
*
*  OPEN JSM AND VERIFY STATUS

USE BUILTIN(JSMX_OPEN) TO_GET(#JSMSTS #JSMMSG #JSMXHDLE1)
EXECUTE SUBROUTINE(CHECK_STS) WITH_PARMS(#JSMXHDLE1)
*
* BUILD THE SERVICE LOAD COMMAND
#JSMXCMD := 'SERVICE_LOAD'
EXECUTE SUBROUTINE(KEYWRD) WITH_PARMS(#JSMXCMD 'SERVICE' 'FTPSERVICE')
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMSTS #JSMMSG)
EXECUTE SUBROUTINE(CHECK_STS) WITH_PARMS(#JSMXHDLE1)
*
*     YOUR OWN LOGIC HERE
*
* BUILD THE JSM COMMAND
#JSMXCMD := CONNECT
EXECUTE SUBROUTINE(KEYWRD) WITH_PARMS(#JSMXCMD HOST #S_218HOST)
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMSTS #JSMMSG)
EXECUTE SUBROUTINE(CHECK_STS) WITH_PARMS(#JSMXCMD)
*
#JSMXCMD := LOGIN
EXECUTE SUBROUTINE(KEYWRD) WITH_PARMS(#JSMXCMD USER #S_218USER)
EXECUTE SUBROUTINE(KEYWRD) WITH_PARMS(#JSMXCMD PASSWORD #S_218PSWD)
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMSTS #JSMMSG)
EXECUTE SUBROUTINE(CHECK_STS) WITH_PARMS(#JSMXCMD)
*
#JSMXCMD := CHGDIR
EXECUTE SUBROUTINE(KEYWRD) WITH_PARMS(#JSMXCMD PATH #S_218DIR)
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMSTS #JSMMSG)
EXECUTE SUBROUTINE(CHECK_STS) WITH_PARMS(#JSMXCMD)
*
#JSMXCMD := LIST
EXECUTE SUBROUTINE(KEYWRD) WITH_PARMS(#JSMXCMD PATH *BLANKS)
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMSTS #JSMMSG #WL_218)
EXECUTE SUBROUTINE(CHECK_STS) WITH_PARMS(#JSMXCMD)
*
#JSMXCMD := QUIT
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMSTS #JSMMSG)
EXECUTE SUBROUTINE(CHECK_STS) WITH_PARMS(#JSMXCMD)
*
* UNLOAD SERVICE
#JSMXCMD := 'SERVICE_UNLOAD'
USE BUILTIN(JSMX_COMMAND) WITH_ARGS(#JSMXHDLE1 #JSMXCMD) TO_GET(#JSMSTS #JSMMSG)
EXECUTE SUBROUTINE(CHECK_STS) WITH_PARMS(#JSMXHDLE1)
* CLOSE JSM AND VERIFY STATUS
USE BUILTIN(JSMX_CLOSE) WITH_ARGS(#JSMXHDLE1) TO_GET(#JSMSTS #JSMMSG)
EXECUTE SUBROUTINE(CHECK_STS) WITH_PARMS(#JSMXHDLE1)
*
RETURN
*
* Subroutine to build JSM commands. existing JSM command
*
SUBROUTINE NAME(KEYWRD) PARMS((#W_CMDX *BOTH) (#W_KEYWRD *RECEIVED) (#W_KEYVAL *RECEIVED))
DEFINE FIELD(#W_CMDX) REFFLD(#JSMXCMD)
DEFINE FIELD(#W_KEYWRD) REFFLD(#STD_TEXT)
DEFINE FIELD(#W_KEYVAL) REFFLD(#STD_TEXTL)
#W_CMDX += ' ' + #W_KEYWRD + '(' + #W_KEYVAL + ')'
ENDROUTINE
*
*  Check the status of the JSM command issued
*
SUBROUTINE NAME(CHECK_STS) PARMS(#W_HDLE)
*
DEFINE FIELD(#MSGDTA) TYPE(*CHAR) LENGTH(132)
DEFINE FIELD(#W_HDLE) TYPE(*CHAR) LENGTH(4)
*
IF COND('#JSMSTS *NE OK')
*
#MSGDTA := 'Error Status Code: ' + #JSMSTS
MESSAGE MSGID(DCM9899) MSGF(DC@M01) MSGDTA(#MSGDTA)
#MSGDTA := 'Error Message: ' + #JSMMSG
MESSAGE MSGID(DCM9899) MSGF(DC@M01) MSGDTA(#MSGDTA)
ENDIF
*
ENDROUTINE