0

I am working on a project that would allow upload to SAP using PHP.

I used the code:

// Call-Function

$parameters = array(

    array("IMPORT", "ZMM_", "*"),
    //array("EXPORT", "*", array()),
    array("TABLE", "IMT_", array())
  );

$result = $sap->callFunction('ZMM_', $parameters);

I want to display the contents of the table but is getting an error message for import parameter. can anyone please help me to solve this?

Thanks

1 Answer 1

5

It seems that you use this - https://github.com/sensational/php-saprfc/blob/php7/saprfc.php - php callFunction implementation for a call to a user defined function ZMM_ ( a SAP function that is in the Z_ namespace and which you implemented in SAP by yourself - for ZMM_ does standardly not exist in the system and all existing ZMM* are not remote enabled), which holds a table, in SAP over SAP rfcsdk. not!!! remote enabled

  1. Did you remote enable this function(like for example the one shown in pic1 RFC_READ_TABLE is) that you built by your own in SAP? If not it can't work together with SAP rfcsdk rfc remote enabled

  2. If yes - your parameters can't be right. This is an example for a tyical call to an existing rfc function in SAP within that framework, that you !!seem!!(I only can guess it, for you do not explain it) to use.

P.S.: If you don't use a php framework for E. Koucky's saprfc 1.4.1 extension dll (which you !!seem!! to use) you can use direct calls, which means direct calls in the compiled extension[php_functions]. I indicated the direct calls with ****....****. You can directly call like that:

 ...
                            // router string 
 $LOGIN = array ("ASHOST"=>"/H/xx.xx.xx.com/S/port/W/xx/H/localhost",   
               "SYSNR"   =>"00",
               "CLIENT"  =>"800",
               "USER"    =>"xxxxxxxx",
               "PASSWD"  =>"xxxxxxxx",  
               "LANG"    =>"E");
    ...
    $table="T100";
    $criteria="SPRSL EQ 'E' AND TEXT GE 'Must e' AND TEXT LT 'N'";
    $options=array("TEXT"=>$criteria);
    ...
    $rfc = ****saprfc_open**** ($LOGIN);
    $fce = ****saprfc_function_discover****($rfc,"RFC_READ_TABLE"); 
    ...
    // set import parameters 
    saprfc_import ($fce,"DELIMITER","*");
    saprfc_import ($fce,"NO_DATA","");
    saprfc_import ($fce,"QUERY_TABLE",$table);
    saprfc_import ($fce,"ROWCOUNT","");
    saprfc_import ($fce,"ROWSKIPS","");

    saprfc_table_init ($fce,"FIELDS");
    saprfc_table_init ($fce,"OPTIONS");
    saprfc_table_init ($fce,"DATA");
    // options look at the top -> $criteria
    ****saprfc_table_append**** ($fce,"OPTIONS", $options); 
    ...
     for($i=1; $i<=$data_row;$i++)
        {
            $DATA[$i] = ****saprfc_table_read**** ($fce,"DATA",$i);
            $ex = explode("*",$DATA[$i]["WA"]);
    ...

You can find a working saprfc extension for php-7.1.11-nts-x32 together with SAPGUI 7.4 (rfcsdk 7.4) here https://sourceforge.net/projects/saprfcsdk/files/PHP%207.1.11%20NTS%20VC14%20%20SAP%20GUI%207.4%20-%20x32%20%20NUC/

You can grab the directly callable extension-functions by using

$extensions= get_loaded_extensions();
$functions=array();

foreach($extensions as $ext) 
{
    if($ext=="saprfc-gimba")
    {
        echo "<font size='4' color='green'>".$ext."</font><font size='2' color='green'> ist geladen<br></font>";
        echo "<font size='1' color='green'>vorhandene Funktionen:<br></font>";
        $functions =  get_extension_funcs($ext);
    }
}
foreach($functions as $text) 
{
    echo "<font size='1' color='green'>$text<br></font>";
}

Then you get that result directly callable php saprfc extension functions

Here you have a table query from table TFDIR which returns all the RFC_* functions in the system. If you set FMODE EQ 'R' you get all functions of the system which are remotely callable.

$table="TFDIR";
    $criteria="FUNCNAME GE 'RFC_' AND FUNCNAME LT 'RFC_ZZZZ'";
    $options=array("TEXT"=>$criteria);

    $LOGIN = array ("ASHOST"=>"/H/sapx.x.x.com/S/port/W/x/H/localhost",
               "SYSNR" =>"00",
               "CLIENT"=>"800",
               "USER"  =>"xxx",    
               "PASSWD"=>"xxx",     
               "LANG"  =>"E");
    $rfc = saprfc_open ($LOGIN);
    $fce = saprfc_function_discover($rfc,"RFC_READ_TABLE");
    if (! $fce )
    {
        echo "Discovering interface of function module failed";
        exit;
    }
    saprfc_import ($fce,"DELIMITER","*");
    saprfc_import ($fce,"NO_DATA","");
    saprfc_import ($fce,"QUERY_TABLE",$table);
    saprfc_import ($fce,"ROWCOUNT","");
    saprfc_import ($fce,"ROWSKIPS","");
    saprfc_table_init ($fce,"FIELDS");
    saprfc_table_init ($fce,"OPTIONS");
    saprfc_table_init ($fce,"DATA");
    saprfc_table_append ($fce,"OPTIONS", $options); 
    $rc = saprfc_call_and_receive ($fce);
    if ($rc != SAPRFC_OK)
    {
        if ($rfc == SAPRFC_EXCEPTION )
        {
            echo ("Exception raised: ".saprfc_exception($fce));
        }
        else
        {
            echo ("Call error: ".saprfc_error($fce));
        }
        exit;
    }
    $data_row = saprfc_table_rows ($fce,"DATA");
    $field_row = saprfc_table_rows ($fce,"FIELDS");
    echo "<div align='center'><p style='font-size:22px;color:midnightblue'>SAP - QUERY TABLE - TFDIR - PHP 7.1.11</p>".
         "<table><tr bgcolor='#dddddd' style='font-size:15px; color:midnightblue;'>".
         "<td>FUNCNAME</td><td>PNAME</td><td>INCLUDE</td><td>FREEDATE</td><td>APPL</td><td>MAND</td><td>FMODE</td><td>HOST</td><td>U_TASK</td><td>PNAME_MAIN</td><td>STEXT</td>";
    for($i=1; $i<=$data_row;$i++)
    {
        $DATA[$i] = saprfc_table_read ($fce,"DATA",$i);
        $ex = explode("*",$DATA[$i]["WA"]);
        echo "<tr style='font-size:12px;'>";
        for ($n=0;$n<=sizeof($ex);$n++)                         
        {
            if($ex[$n] != '')
            {
                echo "<td id=".$i."_".$n.">".$ex[$n]."</td>";
            }
            if(sizeof($ex) == 4 && $n==3)
            {
                echo "<td id=".$i."_".$n.">&nbsp;</td>";
                echo "<td id=".$i."_".$n.">&nbsp;</td>";
                echo "<td id=".$i."_".$n.">&nbsp;</td>";
            }
        }
        echo "</tr>";
    }
    echo "</table></div>";
    //saprfc_function_debug_info($fce);
    saprfc_function_free($fce);
    saprfc_close($rfc);

The result is: all RFC_* functions

If you need unicode support for example for german etc. you insert this here:

$rfc = saprfc_open ($LOGIN);
// enabling the same codepage as SAPGUI - unicode - for  ö,ü,ä etc.
saprfc_set_code_page ($rfc,"4110");

Or if you use the E. Koucky framework:

$rfc->SetCodePage("4110");

Best regards Axel Arnold Bangert

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.