aXesTerminalServiceの例
この例は、人事デモ・システムと共に提供される保守プログラムを利用して5250セッションをオートメーション化し、PSLMSTファイルに社員詳細を挿入します。
aXesTerminalServiceのコマンドやキーワードの使用方法を示すため、LANSAで書かれたJSMX (RDMLX) BIFを使ったコード例が以下に提供されています。
注:これは社員ID A9090を使って、新しい社員を挿入する例です。社員IDは、人事システム・ファイル内で一意のものでなければなりません。このIDが既に存在しないかを確認してください。この例を実行する度に、実行前に社員レコードを削除するか、もしくはコードで使用する社員IDを変更して、ファンクションを再コンパイルする必要があります。
注:この例では主要なプログラム手順が明確になるように、かなり限定的な例外処理コードを意図的に使用しています。
この例を利用する際は、以下を行ってください。
1. LANSA人事デモストレーション・システムにアクセスでき、権限があるユーザー・プロファイル名を確認します。また、このコード例は以下を前提に提供されます。
- ユーザーの最初のメニューの18行、7列の位置にコマンド・エントリーがある。(この例のプログラムではこの位置にLANSAコマンドをタイプして、人事システムの社員入力ファンクションを開始させます。)
- ユーザーにコマンド使用の権限がある。(LANSAとSIGNOFF)
- ユーザーの初期ライブラリ・リストに必要なLANSAライブラリが含まれている。
選択したユーザーが上記のいずれかの条件に当てはまらない場合、それに合わせて提供されたコード例を変更する必要があります。
2. ユーザーのシステムのaXesターミナル・サーバー接続に必要な以下の詳細を確認します。
HOST |
ユーザー環境でのaXesターミナル・サーバーのホスト名。通常はaXesがインストールされ実行されているIBM i システムのネットワーク名が使用できます。 |
PORT |
aXesターミナル・サーバーのリスナー・ポート番号。省略値ではaXesはポート番号80を使用します。 |
USER |
上記のHOSTシステムで定義されたIBM i ユーザー・プロファイル名。 |
PASSWORD |
上記のUSERに対応するパスワード。 |
3.コード例のCONNECTサービス・コマンドを作成して実行する部分を上記で確認した内容を使用するように変更します。
* -----------------------------------------------
* Process ........:Tutorial
* Function .......:AXES001
* Created on .....:July 13, 2011
* Description ....:Utilising the AxesTerminalService
* -----------------------------------------------
Function Options(*DIRECT)
* If these required fields are already defined in the repository then comment or remove these definitions
Define Field(#jsmsts) Type(*char) Length(20)
Define Field(#jsmmsg) Type(*char) Length(255)
Define Field(#jsmxhdle1) Type(*char) Length(4)
Define Field(#jsmxcmd) Type(*char) Length(355)
* Field to receive the aXes screen name from the aXesTerminalService
* (not used in this example program, but included for illustration)
Define Field(#AXSCREEN) Type(*Char) Length(256)
* Dummy working list used to exchange fields with the JSM
Def_list Name(#EXCHANGE1) Fields(#AXSCREEN) Type(*Working) Entrys(1)
* -----------------------------------------------
* Program Mainline
* -----------------------------------------------
* Open a connection to the JSM
Use Builtin(JSMX_OPEN) To_Get(#JSMSTS #JSMMSG #jsmxhdle1)
Execute Subroutine(CHECK_STS) With_Parms(#jsmxhdle1)
* Load the aXesTerminalService
#JSMXCMD := 'SERVICE_LOAD'
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD 'SERVICE' 'AXESTERMINALSERVICE')
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD 'TRACE' '*YES')
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXHDLE1)
* Connect to the aXes server
* NB:PLEASE CHANGE CONNECTION DETAILS TO SUIT YOUR ENVIRONMENT
* NOTE THE USE OF THE #EXCHANGE1 DUMMY WORKING LIST TO EXCHANGE
* FUNCTION FIELD VALUES WITH THE SERVICE.(THE FIELDS ARE NOT
* USED IN THIS EXAMPLE.)YOU COULD ADD 'SERVICE_EXCHANGE(*FIELD)'
* TO THE JSM COMMAND STRING FOR SIMILAR EFFECT.
* IN THIS CASE, THIS ALLOWS US TO RECEIVE THE AXES SCREEN NAME
* OF THE RESULTING 5250 SCREEN INTO THE FUNCTION FIELD #AXSCREEN.
#JSMXCMD := CONNECT
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD HOST 'MYSERVER')
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD PORT '80')
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD USER 'MYUSER')
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD PASSWORD 'MYPASSWORD')
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD #EXCHANGE1) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXCMD)
* Send (Press Enter) Command to continue
* (This is in case the "Display Program Messages" display is shown)
* (NOTE AGAIN THE USE OF THE #EXCHANGE1 DUMMY WORKING LIST)
#JSMXCMD := SEND
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD #EXCHANGE1) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXCMD)
* Start LANSA to execute the Enrol function in PSLSYS Process
* (NOTE AGAIN THE USE OF THE #EXCHANGE1 DUMMY WORKING LIST)
#JSMXCMD := SETBYPOS
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD ROW '18')
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD COL '7')
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD SENDKEY ENTER)
Use Builtin(TCONCAT) With_Args(#jsmxcmd ' VALUE("LANSA REQUEST(RUN) PROCESS(PSLSYS) FUNCTION(ENROL) PARTITION(DEM) LANGUAGE(ENG)")') To_Get(#JSMXCMD)
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD #EXCHANGE1) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXCMD)
* Type the Employee ID
* NB:Employee ID used must NOT be already used
#JSMXCMD := SETBYPOS
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD ROW '3')
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD COL '43')
Use Builtin(TCONCAT) With_Args(#jsmxcmd ' VALUE(A9090)') To_Get(#JSMXCMD)
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXCMD)
* Type the Surname
#JSMXCMD := SETBYPOS
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD ROW '4')
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD COL '43')
Use Builtin(TCONCAT) With_Args(#jsmxcmd ' VALUE(Smith)') To_Get(#JSMXCMD)
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXCMD)
* Type the Given Name
#JSMXCMD := SETBYPOS
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD ROW '5')
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD COL '43')
Use Builtin(TCONCAT) With_Args(#jsmxcmd ' VALUE(John)') To_Get(#JSMXCMD)
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXCMD)
* Type the Street Address
#JSMXCMD := SETBYPOS
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD ROW '6')
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD COL '43')
Use Builtin(TCONCAT) With_Args(#jsmxcmd ' VALUE(1 Some Street)') To_Get(#JSMXCMD)
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXCMD)
* Type the Suburb
#JSMXCMD := SETBYPOS
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD ROW '7')
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD COL '43')
Use Builtin(TCONCAT) With_Args(#jsmxcmd ' VALUE(Sometown)') To_Get(#JSMXCMD)
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXCMD)
* Type the State and Country
#JSMXCMD := SETBYPOS
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD ROW '8')
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD COL '43')
Use Builtin(TCONCAT) With_Args(#jsmxcmd ' VALUE(CCC)') To_Get(#JSMXCMD)
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXCMD)
* Type the Zip code
#JSMXCMD := SETBYPOS
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD ROW '9')
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD COL '43')
Use Builtin(TCONCAT) With_Args(#jsmxcmd ' VALUE(7111)') To_Get(#JSMXCMD)
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXCMD)
* Type the Home Phone Number
#JSMXCMD := SETBYPOS
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD ROW '10')
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD COL '43')
Use Builtin(TCONCAT) With_Args(#jsmxcmd ' VALUE(1222222)') To_Get(#JSMXCMD)
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXCMD)
* Type the Business phone Number
#JSMXCMD := SETBYPOS
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD ROW '11')
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD COL '43')
Use Builtin(TCONCAT) With_Args(#jsmxcmd ' VALUE(133333)') To_Get(#JSMXCMD)
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXCMD)
* Type the Department Code
#JSMXCMD := SETBYPOS
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD ROW '12')
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD COL '43')
Use Builtin(TCONCAT) With_Args(#jsmxcmd ' VALUE(ADM)') To_Get(#JSMXCMD)
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXCMD)
* Type the Section Code
#JSMXCMD := SETBYPOS
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD ROW '13')
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD COL '43')
Use Builtin(TCONCAT) With_Args(#jsmxcmd ' VALUE(04)') To_Get(#JSMXCMD)
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXCMD)
* Type the Employee Salary
#JSMXCMD := SETBYPOS
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD ROW '14')
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD COL '43')
Use Builtin(TCONCAT) With_Args(#jsmxcmd ' VALUE(31222)') To_Get(#JSMXCMD)
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXCMD)
* Type the Start Date
* AND press ENTER to submit the details
* (NOTE AGAIN THE USE OF THE #EXCHANGE1 DUMMY WORKING LIST)
#JSMXCMD := SETBYPOS
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD SENDKEY ENTER)
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD ROW '15')
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD COL '43')
Use Builtin(TCONCAT) With_Args(#jsmxcmd ' VALUE(100311)') To_Get(#JSMXCMD)
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD #EXCHANGE1) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXCMD)
* Press F3 to return to the main menu
* (NOTE AGAIN THE USE OF THE #EXCHANGE1 DUMMY WORKING LIST)
#JSMXCMD := SEND
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD SENDKEY F3)
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD #EXCHANGE1) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXCMD)
* Type the SIGNOFF command and press ENTER
#JSMXCMD := SETBYPOS
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD ROW '18')
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD COL '7')
Execute Subroutine(KEYWRD) With_Parms(#JSMXCMD SENDKEY ENTER)
Use Builtin(TCONCAT) With_Args(#jsmxcmd ' VALUE("SIGNOFF")') To_Get(#JSMXCMD)
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXCMD)
* Disconnect from the aXes terminal server
#JSMXCMD := DISCONNECT
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXCMD)
* Unload the aXesTerminalService
#JSMXCMD := 'SERVICE_UNLOAD'
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXHDLE1)
* Close the connection to the JSM
Use Builtin(JSMX_CLOSE) With_Args(#JSMXHDLE1) To_Get(#JSMSTS #JSMMSG)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXHDLE1)
Return
* -----------------------------------------------
* Subroutine to build JSM commands
* -----------------------------------------------
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) Length(255) Reffld(#STD_TEXTL)
#W_CMDX += ' ' + #W_KEYWRD + '(' + #W_KEYVAL + ')'
Endroutine
* -----------------------------------------------
* Subroutine to check the JSM status
* -----------------------------------------------
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