Search code examples
phpsaprfcfunction-module

How to send Chinese characters from SAP to PHP through RFC?


i am communicating to PHP through RFC using function module.i tried to send chinese characters from function module to PHP , but in PHP side i am getting chinese charcters in the form of ###### ,

i don't understand which side the problem is ,either PHP side or SAP side? anyone give me suggestion which side do i need to focus to rectify this problem ? or any other way to send chinese character to PHP?

SAP FM Code:FN Name: ZMM_PHP_TO_SAP

     t_log-msgty = 'E'.
    CONCATENATE p_uname '用户无检料权限' INTO t_log-msgtx SEPARATED BY space.
    APPEND t_log.

PHP Code:

 $LOGIN = array ("ASHOST"=>$row_login1["sap_server"],
            "SYSNR"=>$row_login1["sap_system_number"],
            "CLIENT"=>$row_login1["sap_client"],
            "USER"=>$row_login1["sap_username"],
            "PASSWD"=>$row_login1["sap_password"],
            "CODEPAGE"=>"8300");

$rfc = saprfc_open ($LOGIN);

if(!$rfc){
$error=saprfc_error();
return "The RFC connection has failed with the following error:".saprfc_error();
exit;}
$fce = saprfc_function_discover($rfc,"ZMM_PHP_TO_SAP");
if(!$fce){
    return "The function module has failed.";
    return $rfc;
    exit;}saprfc_import ($fce,"P_UNAME","demo-china");
saprfc_table_init ($fce,"T_LOG");

// Call and execute the function
$rc = saprfc_call_and_receive ($fce);
if ($rfc_rc != SAPRFC_OK){
    if ($rfc == SAPRFC_EXCEPTION ){
        echo ("Exception raised: ".saprfc_exception($fce));
    } else {
        echo ("Call error: ".saprfc_error($fce));
    }
    echo "failure";
    exit;
}
$data_row = saprfc_table_rows ($fce,"T_LOG");
    $log_msg='';
    if($data_row != 0 || $data_row != '')   
    {
        for ($i=1; $i<=$data_row; $i++)
        {
        $DATA = saprfc_table_read ($fce,"T_LOG",$i);
        echo $DATA['MSGTX'];
            if($DATA['MSGTY'] == "E")
            {
            $log_msg =$DATA['MSGTX'];
            }
            if($DATA['MSGNO'] == "D")
            {
            $log_msg ="D";

            }

        }
    }

when itry to print $DATA['MSGTX'] the output is DEMO-CHINA ¥Î###®Æ#­­ , how to get exact Chinese characters. thanks in advance.


Solution

  • Found answer finally.

    $LOGIN = array ("ASHOST"=>$row_login1["sap_server"],
            "SYSNR"=>$row_login1["sap_system_number"],
            "CLIENT"=>$row_login1["sap_client"],
            "USER"=>$row_login1["sap_username"],
            "PASSWD"=>$row_login1["sap_password"],
            "CODEPAGE"=>"4110");
    

    CODEPAGE from 8300 to 4110 solves my issue