Liquid UI - WS Reference Library

toUTF8()


Purpose

The toUTF8() command is used to encode text returned by a call command into UTF-8. If you are working in a non-English environment, you may need to convert the data returned by a call command into a readable format. However, when we call a function module using a call command, and the result strings have special characters, WS does not automatically encode the text, resulting in unreadable data being displayed. To correctly display these special characters, you need to use the toUTF8() command.


Syntax

toUTF8(STRING);

The 'STRING' value is the is the substring that contains the characters that are being incorrectly displayed.


Options

The toUTF8() command does not take any options.


Example

The following example demonstrates the command usage:

  1. Open the script file for the SAP Easy Access screen and enter the following code.

    clearscreen();
    var arMatDesc = ["ICP*RFC*"];
    arF4MatList = [];
    call("BAPI_MATERIAL_GETLIST",{"table.MATERIALSHORTDESCSEL":"arMatDesc","table.MATNRLIST":"arF4MatList"});
    println('----arF4MatList='+arF4MatList);
    for(var ii=0; ii<arF4MatList.length; ii++){
    text([ii,0],arF4MatList[ii].substring(18,58),{"name":"z_test"+ii,"size":50});
    }
  2. Run the script and verify that some data returned will appear as unreadable characters, as shown in the:


  3. To correct this problem, we will use the toUTF8() command in your script. Once you get the array from the function module call, each array element needs to be converted in to UTF8. After that, we can get the substrings. The revised code is:

    clearscreen();
    var arMatDesc = ["ICP*RFC*"];
    arF4MatList = [];
    call("BAPI_MATERIAL_GETLIST",{"table.MATERIALSHORTDESCSEL":"arMatDesc","table.MATNRLIST":"arF4MatList"});
    println('----arF4MatList='+arF4MatList);
    for(var ii=0; ii<arF4MatList.length; ii++)
    {
    	var convertedString = toUTF8(arF4MatList[ii]);
    	text([ii,0],convertedString.substring(18,58),{"name":"z_test"+ii,"size":50});
    }
  4. The characters that initially appeared in an unreadable format, now appear correct: