Enterprise Architecture Blog Posts
Need a little more room to share your thoughts with the community? Post a blog in the SAP Enterprise Architecture group to explain the more complex topics.
cancel
Showing results for 
Search instead for 
Did you mean: 
Naveennani8523
Explorer
1,392

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

Naveennani8523_0-1745840542028.png

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

Naveennani8523_1-1745840542029.png

  • LT_TRANSLATION – Table to store all translation entries.
  • LS_TRANSLATION – Work area for one row.
  • LT_OUTPUT – Table to store final CSV content.
  • LV_LINE – Line to hold concatenated fields for CSV
  • LV_SEPARATOR – Delimiter (comma for CSV).

🔹3. Fill Sample Translation Data

Naveennani8523_2-1745840542032.png

This section assigns translated words to each language and adds the entry to the internal table.

🔹4. Add UTF-8 BOM (Byte Order Mark)

Naveennani8523_3-1745840542033.png

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

Naveennani8523_4-1745840542034.png

Adds a readable header row for the CSV file.

🔹6. Create CSV Content from Internal Table

Naveennani8523_5-1745840542036.png

Each translation line is merged into one string using commas and added to the output table.

🔹7. Download the CSV File

Naveennani8523_6-1745840542038.png

This function downloads the CSV to the desktop. The CODEPAGE = 4110 ensures UTF-8 encoding.

🔹8. Success/Failure Message

Naveennani8523_7-1745840542038.png

After attempting the download, the program shows a success or failure message.

REPORT ZLANG_DOWNLOAD_FILE2.

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

DATALT_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)
DATALV_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.