Woodyka
Woodyka

Reputation: 51

SAP RFC table read with filter

I'm new in PHP SAP RFC. I use an our integrated function, but now I need to read lines from a table. But how can I do to read only a few lines, filter the results by a criteria, because this table has some millions of rows.

Is it possible?

Upvotes: 0

Views: 1835

Answers (1)

Woodyka
Woodyka

Reputation: 51

Here is a code part, that is use recently, works well and quick on very big tables too. I hope it helps others too.

//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);

Upvotes: 1

Related Questions