M
M
Maxim2014-12-09 02:45:29
PHP
Maxim, 2014-12-09 02:45:29

Importing data into SAP (sap rfc), how to do it?

There is a site that has already configured export from SAP to the site database for several modules.
Getting data from SAP is something like this for these modules:

$data = $this->authorize_sap()->execute_function('МОДУЛЬ');
$data->Call();
$arr = $data->LIST->Export();

in arr, the data is obtained
this - the class for working with sap,
authorize_sap and execute_function:
private function authorize_sap(){
        try{
            $this->sap = new SAPConnection;
            $this->sap->connectToApplicationServer($this->sap_host, "00");
            $this->sap->Open($this->sap_client, $this->sap_login, $this->sap_password, "ru");
            if($this->sap->GetStatus() != SAPRFC_OK)
                throw new Exception('Connection problem(SAP).');
        } catch(Exception $e){
            echo $e->getMessage();
        }
        return $this;
    }

    private function execute_function($f){
        return $this->sap->NewFunction($f);
    }

This is all clear, and logically for such modules there is also an Import method.
The problem is that according to the required module $this->authorize_sap()->execute_function('MODULE'); does not return a LIST object, so Export cannot be called either.
You need to import data (several fields) and get one field in response.
And I don't understand how to do it.
A bit of background:
I have not encountered SAP before, it became necessary to refine the system, while the deadlines are burning strongly.
I could not find normal documentation, an example too (there was only export on the site).
It turns out that I'm doing practically at random.
I tried with saprfc->callFunction('module', parameters), but it didn't work yet, although it seems to me that this is it.
The task intuitively seems very simple, just not enough information.
I will be very glad to councils.
I post the output of the execute_function('MODULE') function:
for the module whose export works:
object(SAPFunction)#3 (11) {
  ["rfc"]=>
  resource(7) of type (saprfc handle)
  ["fce"]=>
  resource(8) of type (saprfc function module)
  ["name"]=>
  string(22) "ИМЯ МОДУЛЯ"
  ["exception"]=>
  string(0) ""
  ["server"]=>
  bool(false)
  ["bapi"]=>
  bool(false)
  ["def"]=>
  array(1) {
    [0]=>
    array(4) {
      ["name"]=>
      string(4) "LIST"
      ["type"]=>
      string(5) "TABLE"
      ["optional"]=>
      int(0)
      ["def"]=>
      array(18) {
        [0]=>
        array(5) {
          ["name"]=>
          string(5) "MATNR"
          ["abap"]=>
          string(1) "C"
          ["len"]=>
          int(18)
          ["dec"]=>
          int(0)
          ["offset"]=>
          int(0)
        }
        [1]=>
        array(5) {
          ["name"]=>
          string(9) "SERV_CODE"
          ["abap"]=>
          string(1) "C"
          ["len"]=>
          int(10)
          ["dec"]=>
          int(0)
          ["offset"]=>
          int(18)
        }
        [2]=>
        array(5) {
          ["name"]=>
          string(9) "SERV_NAME"
          ["abap"]=>
          string(1) "C"
          ["len"]=>
          int(40)
          ["dec"]=>
          int(0)
          ["offset"]=>
          int(28)
        }
        [3]=>
        array(5) {
          ["name"]=>
          string(9) "SERV_TYPE"
          ["abap"]=>
          string(1) "C"
          ["len"]=>
          int(10)
          ["dec"]=>
          int(0)
          ["offset"]=>
          int(68)
        }
        ... дальше описание полей ...
      }
    }
  }
  ["status"]=>
  int(0)
  ["statusInfos"]=>
  string(0) ""
  ["debug"]=>
  bool(false)
  ["LIST"]=>
  object(SAPTable)#4 (9) {
    ["fce"]=>
    resource(8) of type (saprfc function module)
    ["name"]=>
    string(4) "LIST"
    ["row"]=>
    array(0) {
    }
    ["rowNum"]=>
    int(0)
    ["rowStruct"]=>
    array(18) {
      [0]=>
      string(5) "MATNR"
      [1]=>
     ... перечисление полей ...
    }
    ["rowLast"]=>
    int(0)
    ["status"]=>
    int(0)
    ["statusInfos"]=>
    string(0) ""
    ["debug"]=>
    bool(false)
  }
}

For the second, in which you need to organize the import:
object(SAPFunction)#3 (10) {
  ["rfc"]=>
  resource(7) of type (saprfc handle)
  ["fce"]=>
  resource(8) of type (saprfc function module)
  ["name"]=>
  string(14) "ИМЯ МОДУЛЯ"
  ["exception"]=>
  string(0) ""
  ["server"]=>
  bool(false)
  ["bapi"]=>
  bool(false)
  ["def"]=>
  array(3) {
    [0]=>
    array(4) {
      ["name"]=>
      string(3) "NUM"
      ["type"]=>
      string(6) "EXPORT"
      ["optional"]=>
      int(0)
      ["def"]=>
      array(1) {
        [0]=>
        array(5) {
          ["name"]=>
          string(0) ""
          ["abap"]=>
          string(1) "C"
          ["len"]=>
          int(10)
          ["dec"]=>
          int(0)
          ["offset"]=>
          int(0)
        }
      }
    }
    [1]=>
    array(4) {
      ["name"]=>
      string(5) "RCODE"
      ["type"]=>
      string(6) "EXPORT"
      ["optional"]=>
      int(0)
      ["def"]=>
      array(1) {
        [0]=>
        array(5) {
          ["name"]=>
          string(0) ""
          ["abap"]=>
          string(1) "b"
          ["len"]=>
          int(1)
          ["dec"]=>
          int(0)
          ["offset"]=>
          int(0)
        }
      }
    }
    [2]=>
    array(4) {
      ["name"]=>
      string(4) "DATA"
      ["type"]=>
      string(6) "IMPORT"
      ["optional"]=>
      int(0)
      ["def"]=>
      array(34) {
        [0]=>
        array(5) {
          ["name"]=>
          string(5) "MANDT"
          ["abap"]=>
          string(1) "C"
          ["len"]=>
          int(3)
          ["dec"]=>
          int(0)
          ["offset"]=>
          int(0)
        }
        [1]=>
        array(5) {
          ["name"]=>
          string(6) "WI_NUM"
          ["abap"]=>
          string(1) "C"
          ["len"]=>
          int(10)
          ["dec"]=>
          int(0)
          ["offset"]=>
          int(3)
        }
        [2]=>
        array(5) {
          ["name"]=>
          string(5) "ERDAT"
          ["abap"]=>
          string(1) "D"
          ["len"]=>
          int(8)
          ["dec"]=>
          int(0)
          ["offset"]=>
          int(13)
        }
        .. дальше остальные поля ..
      }
    }
  }
  ["status"]=>
  int(0)
  ["statusInfos"]=>
  string(0) ""
  ["debug"]=>
  bool(false)
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Popov, 2018-01-19
@IronBream

Hello, I understand that the question was asked a very long time ago and perhaps it is no longer relevant, but the answer will most likely be of interest to many specialists who are starting their work with SAP systems.
SAP has a number of restrictions on the technologies used, for example, for an RFC call to a functional module (functional modul) or BAPI, the module must have certain properties. Roughly speaking, it must be available for remote calling.
In addition, the module must have a structure or a response table. So, in order to correctly call the module from SAP, it is advisable to talk with a programmer or at least a SAP consultant. If this is not possible, then you need to go into SAP itself and check the called module in transaction se37.
In short, something like this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question