1 Reply Latest reply on Mar 30, 2014 7:40 AM by BKBK

    Passing parameters to Java JT400 object

    reggiejackson44

      I need to pass a byte array as my input and an int as the output length for the Class ProgramCall.

      My error is   

      parameterList[0] (null): Parameter value is not valid.

      My thoughts are

      I think (but I'm not completely sure) I'm having trouble because I'm passing a Coldfusion Array where a Java Array is needed to pass the arguments.

      Coldfusion arrays start at index 1 and Java Arrays start at index 0.

      (1) Am I correct in what I believe is causing my error?

      (2) How can I convert the Coldfusion Array to a Java Array?

      Here is the documentation for Java JT400 object Class ProgramCall

      http://publib.boulder.ibm.com/iseries/v5r1/ic2924/info/rzahh/javadoc/com/ibm/as400/access/ ProgramCall.html

      Here is my code

      <!--- I am the system object --->

      <cfobject
              action="create"
              type="java"
              class="com.ibm.as400.access.AS400"
              name="mysystem">

      <!--- I am the program call object ---> 

      <cfobject
              action="create"
              type="java"
              class="com.ibm.as400.access.ProgramCall"
              name="myprogram">

       

      <!--- I am the program parameter object ---> 

      <cfobject
              action="create"
              type="java"
              class="com.ibm.as400.access.ProgramParameter"
              name="myparameter">

      <!--- I am the as400 text object ---> 

      <cfobject
              action="create"
              type="java"
              class="com.ibm.as400.access.AS400Text"
              name="mytext">
                               
      <!--- Initialize our system object --->

      <cfset mysystem.init(AS400system,Trim(UCase(loginname)),Left(Trim(loginpass),10)) />

      <!--- Execute our AS400 username validation --->

      <cfset mysystem.ValidateSignon() />

      <!--- Initialize our as400 text object and convert string to a byte array --->

      <cfset mytext.init(5) />
      <cfset nametext = mytext.toBytes("hello") />

      <!--- Initalize our program parameter object --->

      <cfset myparameter.init(2) />

      <!--- Set input data and output data length using the Class methods of ProgramParameter --->

      <cfset myparameter.setInputData(nametext) />
      <cfset myparameter.setOutputDataLength(20) />

      <!--- Set parameters to a Coldfusion Array --->

      <cfset parameterlist = ArrayNew(1) />
      <cfset parameterlist[1] = myparameter.getInputData() />
      <cfset parameterlist[2] = myparameter.getOutputDataLength() />

      <!--- Initalize our program object and run our program --->

      <cfset myprogram.init(iseries,ProgramtoRun, parameterlist) />
      <cfset myprogram.run() />

       

        • 1. Re: Passing parameters to Java JT400 object
          BKBK Adobe Community Professional & MVP

          reggiejackson44 wrote:

           

          I need to pass a byte array as my input and an int as the output length for the Class ProgramCall.

          My error is   

          parameterList[0] (null): Parameter value is not valid.

          My thoughts are

          I think (but I'm not completely sure) I'm having trouble because I'm passing a Coldfusion Array where a Java Array is needed to pass the arguments.

          Coldfusion arrays start at index 1 and Java Arrays start at index 0.

          (1) Am I correct in what I believe is causing my error?

          (2) How can I convert the Coldfusion Array to a Java Array?

          (1) Yes.

           

          (2) A ColdFusion array and a Java array are 2 entirely different things. You have yourself identified one difference, the starting index. In fact, the following line of code will tell you that a ColdFusion array is essentially a Java vector.

           

          <cfoutput>#arrayNew(1).getClass().getSuperClass().getname()#</cfoutput>

           

          In my opinion, your question should read the other way around: how to convert a Java array into ColdFusion, not necessarily into a ColdFusion array.

           

          Here are some tips and tricks:

           

          http://blogs.adobe.com/cantrell/archives/2004/01/byte_arrays_and_1.html

          http://www.bennadel.com/blog/1030-Building-Java-Arrays-In-ColdFusion-Using-Reflection.htm