2022 Dec 13 1:34 PM
Hello dear abapers;
I am facing a strange problem. I need to create an "ANSI" encoded text file using the common OPEN DATASET / TRANSFER / CLOSE DATASET abap commands. I tried to achieve this by playing with ENCODING or CODE PAGE paremeters but it didn't help. Even tried to create the file with the help of SXPG_COMMAND_EXECUTE via Windows' built in CMD. The resulting file is always in "UTF-8" encoding . Does anyone have an idea to solve this?
Kind regards.
2022 Dec 13 1:46 PM
2022 Dec 13 2:07 PM
To create an ANSI encoded file with ABAP, you can use the OPEN DATASET statement along with the ENCODING addition to specify the encoding you want to use.
OPEN DATASET file FOR OUTPUT IN TEXT MODE ENCODING 'ANSI'.
TRANSFER <data> TO file.
CLOSE DATASET file.
2022 Dec 13 5:54 PM
2022 Dec 13 5:53 PM
"ANSI" code page is very confusing (see there: Windows code page - Wikipedia).
If you mean Windows 1252, it's SAP Code Page 1160.
Example:
DATA(file) = '/usr/sap/whatever'.
OPEN DATASET file FOR OUTPUT IN LEGACY TEXT MODE CODE PAGE '1160'.
TRANSFER 'Line 1' TO file.
TRANSFER 'Line 2' TO file.
CLOSE DATASET file.