Introduction
In this blog, we’ll learn how to export multilingual translation data into a CSV file with UTF-8 encoding using ABAP. This ensures that special characters from various languages are preserved and correctly displayed in Excel or Notepad.
🔹1. Define the Structure for Translations
Here, we define a structure TY_TRANSLATION with fields for each language. Each field is of type STRING to support multilingual characters (e.g., accents, umlauts).
🔹2. Declare Data Objects
🔹3. Fill Sample Translation Data
This section assigns translated words to each language and adds the entry to the internal table.
🔹4. Add UTF-8 BOM (Byte Order Mark)
Why? Without the BOM, Excel might not recognize the file as UTF-8 and misinterpret special characters. The BOM ensures the file opens correctly in tools like Excel.
🔹5. Add Header Row to CSV
Adds a readable header row for the CSV file.
🔹6. Create CSV Content from Internal Table
Each translation line is merged into one string using commas and added to the output table.
🔹7. Download the CSV File
This function downloads the CSV to the desktop. The CODEPAGE = 4110 ensures UTF-8 encoding.
🔹8. Success/Failure Message
After attempting the download, the program shows a success or failure message.
REPORT ZLANG_DOWNLOAD_FILE2.
TYPES: BEGIN OF TY_TRANSLATION,
SPANISH TYPE STRING,
PORTUGUESE TYPE STRING,
GERMAN TYPE STRING,
FRENCH TYPE STRING,
ITALIAN TYPE STRING,
DUTCH TYPE STRING,
GREEK TYPE STRING,
TURKISH TYPE STRING,
CZECH TYPE STRING,
POLISH TYPE STRING,
NORWEGIAN TYPE STRING,
SWEDISH TYPE STRING,
SLOVAK TYPE STRING,
HUNGARIAN TYPE STRING,
DANISH TYPE STRING,
END OF TY_TRANSLATION.
DATA: LT_TRANSLATION TYPE STANDARD TABLE OF TY_TRANSLATION,
LS_TRANSLATION TYPE TY_TRANSLATION,
LT_OUTPUT TYPE STANDARD TABLE OF STRING,
LV_LINE TYPE STRING,
LV_SEPARATOR TYPE C VALUE ','.
* Fill one translation line
LS_TRANSLATION-SPANISH = 'Tapa extremo'.
LS_TRANSLATION-PORTUGUESE = 'Tampa terminal'.
LS_TRANSLATION-GERMAN = 'Endkappe'.
LS_TRANSLATION-FRENCH = 'Capuchon extrémité tappo terminale'.
LS_TRANSLATION-ITALIAN = 'Einddop'.
LS_TRANSLATION-DUTCH = 'Ακροκάλυμμα'.
LS_TRANSLATION-GREEK = 'Uç kapağı'.
LS_TRANSLATION-TURKISH = 'Koncová krytka'.
LS_TRANSLATION-CZECH = 'Zatyczka'.
LS_TRANSLATION-POLISH = 'Zatyczka'.
LS_TRANSLATION-NORWEGIAN = 'Ändkåpa'.
LS_TRANSLATION-SWEDISH = 'Koncový kryt'.
LS_TRANSLATION-SLOVAK = 'Végzáró sapka'.
LS_TRANSLATION-HUNGARIAN = 'Endehætte'.
LS_TRANSLATION-DANISH = 'poykorkki'.
APPEND LS_TRANSLATION TO LT_TRANSLATION.
* Add UTF-8 BOM (to make Excel recognize encoding properly)
DATA: LV_BOM TYPE STRING.
LV_BOM = cl_abap_conv_in_ce=>uccp( 'FEFF' ).
APPEND LV_BOM TO LT_OUTPUT.
* Optional: Add CSV header
APPEND 'Spanish,Portuguese,German,French,Italian,Dutch,Greek,Turkish,Czech,Polish,Norwegian,Swedish,Slovak,Hungarian,Danish'
TO LT_OUTPUT.
* Fill content
LOOP AT LT_TRANSLATION INTO LS_TRANSLATION.
CONCATENATE LS_TRANSLATION-SPANISH
LS_TRANSLATION-PORTUGUESE
LS_TRANSLATION-GERMAN
LS_TRANSLATION-FRENCH
LS_TRANSLATION-ITALIAN
LS_TRANSLATION-DUTCH
LS_TRANSLATION-GREEK
LS_TRANSLATION-TURKISH
LS_TRANSLATION-CZECH
LS_TRANSLATION-POLISH
LS_TRANSLATION-NORWEGIAN
LS_TRANSLATION-SWEDISH
LS_TRANSLATION-SLOVAK
LS_TRANSLATION-HUNGARIAN
LS_TRANSLATION-DANISH
INTO LV_LINE SEPARATED BY LV_SEPARATOR.
APPEND LV_LINE TO LT_OUTPUT.
ENDLOOP.
* Download the CSV file in UTF-8 with BOM
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = 'C:\Users\naveenda\Desktop\Welcome_f.csv'
FILETYPE = 'ASC'
CODEPAGE = '4110' " UTF-8
TABLES
DATA_TAB = LT_OUTPUT
EXCEPTIONS
OTHERS = 1.
IF SY-SUBRC = 0.
WRITE: / '✅ File downloaded successfully to desktop.'.
ELSE.
WRITE: / '❌ Download failed.'.
ENDIF.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 12 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 |