Saprfc表用过滤器读取

时间:2015-01-05 09:21:12

标签: php sap saprfc

我是php saprfc的新手。我使用了我们的集成函数,但现在我需要从表中读取行。但是我怎么能只阅读几行,按标准过滤结果,因为这个表有几百万行。

有可能吗?

1 个答案:

答案 0 :(得分:1)

这是一个代码部分,最近使用,在非常大的表上运行良好和快速。我希望它也有助于其他人。

//Try to connect to SAP using our Login array 
    $rfc = saprfc_open ($saplogin);
    IF (! $rfc ) { ECHO "The RFC connection has failed with the following error:".saprfc_error();EXIT; }
    //We must know if the function really exists
    $fce = saprfc_function_discover($rfc, "RFC_READ_TABLE");
    IF (! $fce ) { ECHO "The function module has failed.";ECHO $rfc;EXIT; }
    //Convert to uppercase the name of the table to show
    $Table = "HERE_THE_TABLE_NAME";
    //Pass import parameters
    saprfc_import ($fce,"QUERY_TABLE",$Table);saprfc_import ($fce,"DELIMITER","/");
    //Pass table parameters
    saprfc_table_init ($fce,"OPTIONS");
    saprfc_table_append ($fce,"OPTIONS", array ("TEXT"=>"TABLE_FIELD_NAME = '{$input}'")); //input field, filter by this variable
    saprfc_table_init ($fce,"FIELDS");
    saprfc_table_append ($fce,"FIELDS", array ("FIELDNAME"=>"INT_UI")); //wanted answer field
    saprfc_table_init ($fce,"DATA");
    //Call and execute the function
    $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; 
      }
    //Fetch the data from the internal tables
    $data_row = saprfc_table_rows ($fce,"DATA");$field_row = saprfc_table_rows ($fce,"FIELDS");
    for($i=1; $i<=$data_row ; $i++)
     { $DATA[$i] = saprfc_table_read ($fce,"DATA",$i);$TEST[] = SPLIT("/",$DATA[$i]['WA']); }  // get the rows to $TEST variable


    //release the function and close the connection
  saprfc_function_free($fce);