简体   繁体   中英

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.

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

First of all, you should never hardcode character characters/strings in any programming language and particularly in ABAP. In most cases SAP systems are multilingual systems, which are utulized internationally, therefore symbols hardcoded in one environment could be interpreted differently in another environment. Under term environment I mean logon language, user parameters and et cetera.

Hence we don't know exactly the way how literals will be treated during call of your FM, possible steps we can make in this case are following:

  1. First and foremost, convert your literal in CONCATENATE statement into text-symbol . Text symbols is a recommended way storing character strings in ABAP.
  2. Then I recommend you to check whether your SAP system is Unicode. This can be done via System > Status > Unicode system menu. It is highly unlikely that your system is non-Unicode but, nevertheless, this check is strongly appreciated.

  3. [Optional] This step is optional and makes sense only if your system is non-Unicode, nevertheless, it would be useful anyway. Set your environment codepage into Chinese by statement

    SET LOCALE LANGUAGE 1.

    Put the statement into the start fo the FM.

  4. Also it will be sensible to ensure that Unicode system checks are enabled in your function module. To so this you should go to Go to > Main program > Go to > Attributes and make sure that Unicode checks active checkbox is active.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM