Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Unicode RFC types

Former Member
0 Kudos

Could anybody provide clear definitions and usage examples for the following 'character' types in the SAP RFCSDK (in addition to the comments in the source code:)?

- rfc_char_t

- SAP_CHAR

- SAP_UC

- RFC_CHAR

- ?

1 REPLY 1

Ulrich_Schmidt
Product and Topic Expert
Product and Topic Expert
0 Kudos

If you are using the non-Unicode RFC SDK, all four types basically typedef to char. So they basically represent one-byte character data like ISO-Latin-1, Micorsoft CP1252 etc, depending on the platform you run.

If you are using the Unicode RFC SDK or the NetWeaver RFC SDK, then all four types represent platform-independent 2-byte UTF-16 data. On Windows they typedef to wchar_t (because Windows uses 2-byte UTF-16 as its Unicode representation), on Linux and most Unixes they typedef to a 2-byte unsigned short. (Which is different from wchar_t in most cases, as most Unixes use a 4-byte wchar_t.)

Don't forget to compile you code with -DSAPwithUNICODE, otherwise you'll get segmentation fautls as the buffers you feed into the RFC APIs is only half as long as the RFC APIs expect them to be....

This is most convenient, of your program is Unicode anyway. However, if you program is processing non-Unicode data that it gets from other legacy libraries, databases, user input, etc, you first need to convert from your platform encoding to UTF-16, before passing the data to the RFC APIs. If you are running on Linux, where the platform is using UTF-8 as its default encoding, you can simply use the API RfcUTF8ToSAPUC() (and the corresponding RfcSAPUCToUTF8() for the other way around) to convert to the SAP_UC type (and back). (This API is available in the NetWeaver RFC SDK.)

If you are dealing with let's say ISO-Latin-1 for example, you could use standard GNU functions iconv_open() and iconv() to convert from ISO-Latin-1 to UTF-16. (Giving a pointer to a SAP_UC[] as "outbuf" in the iconv() call.) See [http://pubs.opengroup.org/onlinepubs/009695399/functions/iconv.html|http://pubs.opengroup.org/onlinepubs/009695399/functions/iconv.html] and also

[http://www.gnu.org/software/libiconv/|http://www.gnu.org/software/libiconv/]

I think libiconv is available on all Unixes and Linux distributions these days.

On Windows we have the MultiByteToWideChar(), WideCharToMultiByte(), etc functions, which convert to wchar_t and back. (Despite their name, they can handle single-byte codepages like CP1252 as well....)

Best Regards, Ulrich