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: 

How to create an ANSI encoded file with Abap?

former_member848108
Active Participant
0 Kudos
2,814

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.

4 REPLIES 4

FredericGirod
Active Contributor
0 Kudos
2,403

Could you post your code ? especialy the OPEN DATASET

harishankar714
Participant
0 Kudos
2,403

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.

0 Kudos
2,403

It doesn't compile.

Sandra_Rossi
Active Contributor
0 Kudos
2,403

"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.