方法1:Runtime#execを使う
例
http://publib.boulder.ibm.com/html/as400/v4r5/ic2962/info/java/rzaha/callclex.htm
import java.io.*; public class CallCLPgm { public static void main(String[] args) { try { Process theProcess = Runtime.getRuntime().exec("/QSYS.LIB/JAVSAMPLIB.LIB/DSPJVA.PGM"); } catch(IOException e) { System.err.println("Error on exec() method"); e.printStackTrace(); } } // end main() method } // end class
方法2:Toolkit for Java を使う
Java <-> RPG で型の変換が色々必要になるので注意。
使用するライブラリはログインユーザの JOBD のINLLIBLに設定されているものになる。
CRTJOBD TEST/TESTJOBD INLLIBL(QTEMP QGPL TESTLIB) CHGUSRPRF USER1 JOBD(TEST/TESTJOBD)
みたいな感じで利用するライブラリを変更できる。
必要なライブラリ
- jt400.jar
- x4j400.jar
例1
test.java
import com.ibm.as400.access.AS400; import com.ibm.as400.access.ProgramCall; import com.ibm.as400.access.AS400Message; public class test{ public static void main(String[] args) { AS400 as400 = new AS400("hoge","user","pass"); try { ProgramCall pc = new ProgramCall(as400 ); String programName = "/QSYS.LIB/TESTLIB.LIB/TESTPROG.PGM"; // 引数設定 ProgramParameter[] parmlist = new ProgramParameter[2]; AS400Text nametext = new AS400Text(8); parmlist[0] = new ProgramParameter( nametext.toBytes("John Doe") ); parmlist[1] = new ProgramParameter( 50 ); pc.setProgram( progName, parmlist ); if (pc.run() != true) { // Report failure. System.out.println("Program failed!"); // Show the messages. AS400Message[] messagelist = pc.getMessageList(); for (int i = 0; i < messagelist.length; ++i) { // Show each message. System.out.println(messagelist[i]); } } } catch (Exception ex) { ex.printStackTrace(); } finally { as400.disconnectAllServices(); } } }
例2:実行時にライブラリを変更する
import com.ibm.as400.access.AS400; import com.ibm.as400.access.ProgramCall; import com.ibm.as400.access.AS400Message; public class test{ public static void main(String[] args) { AS400 as400 = new AS400("hoge","user","pass"); try { CommandCall command = new CommandCall(as400); if (!command.run("ADDLIBLE LIB(TESTLIB) POSITION(*FIRST)")){ System.out.println("Call failed!"); return; } ProgramCall pc = new ProgramCall(as400); String programName = "/QSYS.LIB/TESTLIB.LIB/TESTPROG.PGM"; // 引数設定 ProgramParameter[] parmlist = new ProgramParameter[2]; AS400Text nametext = new AS400Text(8); parmlist[0] = new ProgramParameter( nametext.toBytes("John Doe") ); parmlist[1] = new ProgramParameter( 50 ); pc.setProgram( progName, parmlist ); if (pc.run() != true) { // Report failure. System.out.println("Program failed!"); // Show the messages. AS400Message[] messagelist = pc.getMessageList(); for (int i = 0; i < messagelist.length; ++i) { // Show each message. System.out.println(messagelist[i]); } } } catch (Exception ex) { ex.printStackTrace(); } finally { as400.disconnectAllServices(); } } }
応答待ちに反応する
MessageQueue QueuedMessage
あたりを使う。
方法3:PCML(Program Call Markup Language) を使う
Toolkit for Java の呼出をXMLを使って簡単にする方法
必要なライブラリ
- jt400.jar
- x4j400.jar
例1
SAMPLE00.pcml
<pcml version="1.0"> <program name="SAMPLE00" path="/QSYS.LIB/PRIMULA.LIB/SAMPLE00.PGM"> </program> </pcml>
PCMLtest.java
import com.ibm.as400.access.AS400; import com.ibm.as400.data.ProgramCallDocument; public class PCMLTest { public static void main(String[] args) { try { AS400 as400 = new AS400("shuflle","primula","nerine"); ProgramCallDocument testPCML = new ProgramCallDocument(as400,"SAMPLE00"); if(testPCML.callProgram("SAMPLE00")) { System.out.println("SAMPLE00:実行完了"); } } catch (Exception ex) { ex.printStackTrace(); } } }
例2
SAMPLE01.pcml
<pcml version="1.0"> <program name="SAMPLE01" path="/QSYS.LIB/PRIMULA.LIB/SAMPLE01.PGM"> <data name="IN1" type="packed" length="21" precision="2" usage="input"/> <data name="OUT1" type="packed" length="21" precision="2" usage="output"/> </program> </pcml>
PCMLtest.java
import java.math.BigDecimal; import com.ibm.as400.access.AS400; import com.ibm.as400.data.ProgramCallDocument; public class PCMLTest { public static void main(String[] args) { try { AS400 as400 = new AS400("SHUFFLE","PRIMULA","NERINE"); ProgramCallDocument testPCML = new ProgramCallDocument(as400,"SAMPLE01"); // 入出力のパラメータを作成 BigDecimal in1 = new BigDecimal("12.34"); BigDecimal out1 = new BigDecimal("0.00"); // パラメータセット testPCML.setValue("SAMPLE01.IN1", in1); if(testPCML.callProgram("SAMPLE01")) { System.out.println("SAMPLE01:実行完了"); out1 = (BigDecimal)testPCML.getValue("SAMPLE01.OUT1"); System.out.println("入力値:"+ in1); System.out.println("戻り値:"+ out1); } } catch (Exception ex) { ex.printStackTrace(); } } }
[カテゴリ: プログラミング言語 > RPG]
[カテゴリ: プログラミング言語 > Java]
[通知用URL]
Tweet
最終更新時間:2015年07月23日 22時15分14秒