0

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.

Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Archana Palani
  • 247
  • 1
  • 6
  • 23

2 Answers2

1

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

Archana Palani
  • 247
  • 1
  • 6
  • 23
0

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.

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
  • as you said i have followed your steps , but still i am getting the same , in sap side i am getting proper output. but in PHP side its not working. – Archana Palani Feb 18 '16 at 04:40