SAPNWRFC Connection how to WRITE DATA php

2019-06-02 10:45发布

Below code used to fetch and display data from PHP

<?php
use SAPNWRFC\Connection as SapConnection;
use SAPNWRFC\Exception as SapException;
//print_r($_POST);
$config = [
    'ashost' => '###.###.###.###',
    'sysnr'  => '##',
    'client' => '###',
    'user'   => '####',
    'passwd' => '*******',
    'trace'  => SapConnection::TRACE_LEVEL_OFF
];
$sap = false;
$sapMTList = "";
try {
    $sap = new SapConnection($config);
    $result=$sap->getFunction("ZBAPI_SAMPLE_LIST_V1");
    $parms = [
       // 'I_MATTYPE' => 'FERT', 'I_PLANT' => 'XXXX'
        "I_MATTYPE" => "FERT", "I_PLANT" => "XXXX"
        ];
    if(isset($_POST['submit']) && $_POST['submit'] === 'sap_params'){
        $plantNumber="";
        if(isset($_POST['plantNumber'])){
            $plantNumber=$_POST['plantNumber'];
        }
        $parms = [
            "I_MATTYPE" => "FERT", "I_PLANT" => "$plantNumber"
        ];
    }
    $test = $result->invoke( $parms);
    $sapMTList = array_shift($test);
} catch(SapException $ex) {
    echo 'Exception: ' . $ex->getMessage() . PHP_EOL;
}

?>
<?php
 if($sapMTList != "" && !empty($sapMTList)){
        $i=0;
        foreach ($sapMTList as $column){
          // displays data
       }
?>

The code works fantastic to read data. ref: https://gkralik.github.io/php7-sapnwrfc/introduction.html

Can anyone tell me how to write data?

Tried my level best to find resource but couldn't find anywhere. Any help would be highly appreciated. Thanks in advance.

Forgot to mention i use:

PHP Version 7.0.21

SAPNWRFC VERSION Version 1.1.2

SAP NW RFC SDK 7200.0.33

iis server (in 2k12)

Hi used below code got success message but null value in sap

$INputParams = [
    'MATNR'=>'12345678.02',
    'WERKS'=>'1000',
    'KTEXT'=>'Men in Black 2',
    'LAEDA'=>'20170907',
    'MTART'=>'FERT',
    'MATKL'=>'01',
    'MEINS'=>'KARMA',
    'EKGRP'=>'002',
    'DISMM'=>'PD',
    'BKLAS'=>'7920',
    'VPRSV'=>'S',
    'PREIS'=>123.45,
    'WAERS'=>'AED',
    'PEINH'=>1,
    'ERNAM'=>'SAP01'
  ];

$parms = [
       // 'I_MATTYPE' => 'FERT', 'I_PLANT' => '1000'
        "IT_MATERILALS" => ['defaultValue' => $INputParams]
        ];

$test = $result->invoke( $parms);

print_r($test);

/////// GOT OUTPUT

Array
(
    [RETURN] => Array
        (
            [TYPE] => S
            [ID] => ZMM                 
            [NUMBER] => 100
            [MESSAGE] => Successfully Updated                                                                                                                                                                                                        
            [LOG_NO] =>                     
            [LOG_MSG_NO] => 000000
            [MESSAGE_V1] =>                                                   
            [MESSAGE_V2] =>                                                   
            [MESSAGE_V3] =>                                                   
            [MESSAGE_V4] =>                                                   
            [PARAMETER] =>                                 
            [ROW] => 0
            [FIELD] =>                               
            [SYSTEM] =>           
        )

    [IT_MATERILALS] => Array
        (
            [0] => Array
                (
                    [MATNR] => 12345678.02
                    [WERKS] => 1000
                    [KTEXT] => Men in Black 2                         
                    [LAEDA] => 20170907
                    [MTART] => FERT
                    [MATKL] => 01       
                    [MEINS] => KARMA
                    [EKGRP] => 002
                    [DISMM] => PD
                    [BKLAS] => 7920
                    [VPRSV] => S
                    [PREIS] => 123.45
                    [WAERS] => AED  
                    [PEINH] => 1
                    [ERNAM] => SAP01       
                )

        )

)

//////

When i check in SAP GUI record with null values is saved.

Can anyone help?

标签: php sap saprfc
0条回答
登录 后发表回答