SAPNWRFC连接如何写PHP数据

时间:2018-02-24 12:14:56

标签: php sap saprfc

下面用于从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
       }
?>

该代码非常适合读取数据。 参考:https://gkralik.github.io/php7-sapnwrfc/introduction.html

有谁能告诉我如何写数据?

尽我所能找到资源,却无法找到任何地方。 任何帮助将受到高度赞赏。提前谢谢。

忘记提及我使用:

PHP版本7.0.21

SAPNWRFC VERSION Version 1.1.2

SAP NW RFC SDK 7200.0.33

iis服务器(2k12)

您在下面的代码中使用了获得成功消息但在sap

中为null值
$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       
                )

        )

)

//////

当我签入时,保存了具有空值的SAP GUI记录。

有人可以帮忙吗?

0 个答案:

没有答案