SAP / gorfc

SAP NW RFC Connector for GO
Apache License 2.0
96 stars 42 forks source link

RFC result incomplete for Chinese character #6

Closed vanvenj closed 4 years ago

vanvenj commented 7 years ago

I wrote a script to read production order detail and have a problem .

The component material description is a unicode string like "壹贰叁肆伍陆柒捌玖拾一二三四五六七八九十1234567890". The length of the material description is 30 when it is Unicode. But when i call the script below, the result show "壹贰叁肆伍陆柒捌玖拾一二三�". The result was incomplete. When i use pyrfc,the result was complete.

After some testing I have found the length of "MATERIAL DESCRIPTION" field of "COMPONENT" table in BAPI_PRODORD_GET_DETAIL is 40 char. While the length of the material description i haved used is 70 when it is UTF8.

I realize the problem may be caused by the utf8,but i don't know how to fixed it. Any help or advice would be really appreciated. Thank you.

I am using Ubuntu 17.04 64bit.

The code i have used is below:

func main() {
    params := map[string]interface{}{
        "NUMBER": "800000039964",
        "ORDER_OBJECTS": map[string]interface{}{
            "COMPONENTS": "X",
        },
    }
    c, err := gorfc.ConnectionFromParams(abapSystem())
    checkErr(err)

    defer c.Close()
    result, err := c.Call("BAPI_PRODORD_GET_DETAIL", params)
    checkErr(err)
    for tableName, table := range result {
        if tableName == "COMPONENT" {
            for _, row := range table.([]interface{}) {
                rowMap := row.(map[string]interface{})
                if rowMap["DELETION_INDICATOR"] != "X" {
                    fmt.Println(rowMap["MATERIAL_DESCRIPTION"].(string))
                }
            }
        }
    }
}
hanxueming126 commented 6 years ago

Hi, i just got this problem too ,and what i do is just change the gorfc code below like this

at line 284 result = C.GoStringN(utf8str, length)

change to result = C.GoString(utf8str)

and it works

JonasDann commented 6 years ago

@hanxueming126 If you create a pull request for this, I will merge it.