Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2008
    Posts
    11

    Unanswered: calling an rpg program with PHP

    I am not sure if this is the correct place to ask this question but I'll give it a shot. What I would like to do is call and rpg program with PHP. I want to pass three pieces of data to my RPG program, that program will verify the data and display it back.

    Currently it errors out with this message:
    - Call error: Unexpected error while processing description

    PHP CODE:
    PHP Code:
    <?php 
    // very basic example
    $input_1 "RP8512";
    $input_2 "RP8512";  
    $input_3 "Y";  

    $description =
    file_get_contents("/www/zendcore/htdocs/DEON/DEON_TEST.pcml")
    or 
    trigger_error("Error while opening PCML file"E_USER_ERROR);


      
    $conn i5_connect("xxx""xxx""xxx")
                         or die(
    "Connect error: ");
             
      
    $pgm i5_program_prepare_PCML($description) or die("Prepare error: " i5_errormsg());
          
        

      
    $inparms = array("PITEM" => $input_1,
                         
    "PIMAG1" => $input_2,
                       
    "ERROR" => $input_3);
              
      
    $outparms = array("PITEM" => "ITEM",
                          
    "PIMAG1" => "IMAG1");

      
    i5_program_call($pgm$inparms$outparms)         // Perform the actual call
                      
    or die("Call error: " i5_errormsg());

      echo 
    "<table border=\"1\" cellspacing=\"0\" cellpadding=\"3\" bordercolor=\"#999999\" align=\"center\">";
      echo 
    "<tr><td>";
      echo 
    "<div align=\"center\">";
      echo 
    "<h3><font face=\"Arial, Helvetica, sans-serif\">";
      echo 
    "<br> Item : $ITEM ";
      echo 
    "<br> Image : $IMAG1 ";
      
    //echo "<br> Error : $ERROR ";
      
    echo "</h3>";
      echo 
    "</td>";
      echo 
    "</tr><tr><td>";
      echo 
    "<br>";
      echo 
    "This is the IBM Demo with some added text";
      echo 
    "</td></tr></font>";
      echo 
    "</table>";
      
    i5_close($conn);                             

    ?>
    </body>
    </html>
    MY PCML file:
    PHP Code:
    <pcml version="4.0">
       <!-- 
    RPG programPHPTEST  -->
       <!-- 
    created2008-04-30 -->
       <!-- 
    sourceMASTER/QRPGLESRC(PHPTEST) -->
       <
    program name="TESTPHP" path="/QSYS.LIB/MASTER.LIB/TESTPHP.PGM">
         
          <
    data name="PITEM" type="char" length="25" usage="input" />
                   <
    data name="PITEM" type="char" length="25" usage="output" />
          <
    data name="PIMAG1" type="char" length="29" usage="input" />
                  <
    data name="PIMAG1" type="char" length="29" usage="output" />
          <
    data name="ERROR" type="char" length="1" usage="input" />
                  <
    data name="ERROR" type="char" length="1" usage="output" />
          
       </
    program>
    </
    pcml
    I need to input and output but I am not sure how to do that?

    Any help at all would really be appreciated - Thanks,
    j

  2. #2
    Join Date
    Jan 2008
    Posts
    11

    figured it out

    For those of you interested - I found a solution to this problem. First off I did away with calling the PCML file and just invoked the call straight from my PHP file. What I did was add some debugging to my code and found that I wasn't able to include an additional Library that my RPG program was calling - so instead of calling the RPG program by itself, I called a CL program that included the library I needed to reach.

    Here is my code:

    PHP Code:
    //start query
    $options = array("i5_lib" => "FILES");

    $conn i5_connect("BOB""LOB""LAW" $options);
                        
                         if (!
    $conn){
                         
    throw_error("i5_connect");
                         exit();
                         }
             
      
    $description = array(
              array(
                   
    "Name" => "PITEM",
                   
    "IO" => I5_INOUT,
                   
    "Type" => I5_TYPE_CHAR,
                   
    "Length" => "25"
                   
    ),
            array(
                   
    "Name" => "PIMAG1",
                   
    "IO" => I5_INOUT,
                   
    "Type" => I5_TYPE_CHAR,
                   
    "Length" => "29"
                   
    ),
            array(
                   
    "Name" => "ERROR",
                   
    "IO" => I5_INOUT,
                   
    "Type" => I5_TYPE_CHAR,
                   
    "Length" => "1"
                   
    )
                   );
                   
        echo 
    "<br> Array is Formed";
        echo 
    "<br>";
        
                   
                   
    //opening stream to RPG program
                   
    $pgm i5_program_prepare("MASTER/TESTPHPC"$description);
                               
                          if (!
    $pgm){
                        
    throw_error("i5_program_prepare");
                        exit();
                        }
                        
        echo 
    "<br> Stream opened to CL program";
        echo 
    "<br>";
        

      
    $inparms = array("PITEM" => "SPN12xx",
                         
    "PIMAG1" => "FISH.jpg",
                       
    "ERROR" => "");
              
      
    $outparms = array("PITEM" => "PITEM",
                          
    "PIMAG1" => "PIMAG1",
                        
    "ERROR" => "ERROR");

      
    // Sending information back and forth through opened stream
      
    $ret i5_program_call($pgm$inparms$outparms);
                     
                if (!
    $ret){
                
    throw_error("i5_program_call");
                exit();
                }
       
    // having fun
      
    echo "<br> I have made it to line 86 of my code";
      echo 
    "<br>";
      echo 
    "<br>";

                
      
    //echo data to the screen - SUCCESS!
      
    echo "<table border=\"1\" cellspacing=\"0\" cellpadding=\"3\" bordercolor=\"#999999\" align=\"center\">";
      echo 
    "<tr><td>";
      echo 
    "<div align=\"center\">";
      echo 
    "<h3><font face=\"Arial, Helvetica, sans-serif\">";
      echo 
    "<br> Item : $PITEM ";
      echo 
    "<br> Image : $PIMAG1 ";
      echo 
    "<br> Error : $ERROR ";
      echo 
    "</h3>";
      echo 
    "</td>";
      echo 
    "</tr>";
      echo 
    "</font>";
      echo 
    "</table>";
      
    i5_program_close($pgm);
      
    i5_close($conn);       
      
      
      
    //throw error function
     
    function throw_error($func){
      echo 
    "<table border=\"1\" cellspacing=\"0\"><tr><td>";
      echo 
    "-------------------------------------------------------<br>";
      echo 
    "-------------------------------------------------------";
      echo 
    "<font color=\"red\">";
      echo 
    "<br>";
      echo 
    "<br> Error in function: " .$func." --- ";
      echo 
    "<br> Error Number: " .i5_errno()." --- ";
      echo 
    "<br> Error Message: " .i5_errormsg()."";
      echo 
    "<br></font>";
      echo 
    "-------------------------------------------------------<br>";
      echo 
    "-------------------------------------------------------";
      echo 
    "</td></tr>";
      echo 
    "</table>";
      } 
    Thanks for checking out and possibly put thought into it.

    Cheers!
    j

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •