Skip to content

Data Conversion

Abap2xlsx maps ABAP data types to Excel cell types and applies conversion exits where necessary. This page documents how common ABAP types are handled, what conversion helpers are available, and how to control the conversion behaviour.

ABAP → Excel type mapping

ABAP typeABAP type kindExcel cell typeNotes
I IntegeriNumberStored as integer
F FloatfNumberIEEE 754 double
P PackedpNumberDecimal separator locale-aware
DECFLOAT16aNumber16-digit decimal float
DECFLOAT34eNumber34-digit decimal float
D DatedNumber (date serial)Days since 1900-01-00; worksheet date format applied
T TimetNumber (time fraction)Fractional day (0.5 = 12:00:00)
UTCLONGp (internal)Number (datetime serial)S/4HANA only — see below
C CharactercStringLeading zeros preserved
N Numeric textnString or NumberTreated as string to preserve leading zeros
STRINGgString
X / XSTRINGx / yNot directly mappedEncode as base64 string or embed as a drawing

UTCLONG support (S/4HANA)

UTCLONG is the S/4HANA UTC timestamp type (16-byte packed, microsecond precision). When set_cell receives a value whose runtime type resolves to the internal typekind 'p' and the data reference matches the variable_utclong pattern, the value is converted to an Excel datetime serial number (combined date + time fraction).

This conversion is transparent — simply pass the UTCLONG field directly:

abap
DATA: lv_ts TYPE utclong.
GET TIME STAMP FIELD lv_ts.

lo_worksheet->set_cell(
  ip_column = 3
  ip_row    = 5
  ip_value  = lv_ts ).

Apply a combined date-time number format to the cell style so Excel renders it correctly:

abap
DATA(lv_style) = lo_worksheet->change_cell_style(
  ip_column                     = 3
  ip_row                        = 5
  ip_number_format_format_code  = 'YYYY-MM-DD HH:MM:SS' ).

UTCLONG is only available on systems running SAP_BASIS 7.55 or higher (S/4HANA 2020+). On ECC / older NetWeaver systems, use TIMESTAMP (P type, 15 digits) and format it as a date/time string before passing to set_cell.

ip_abap_type override

When automatic type detection produces the wrong Excel type, pass ip_abap_type explicitly:

abap
" Force a numeric string field to be treated as a number
lo_worksheet->set_cell(
  ip_column    = 2
  ip_row       = 4
  ip_value     = '000123'
  ip_abap_type = cl_abap_typedescr=>typekind_int ).

" Force a packed field to be treated as text (preserve formatting)
lo_worksheet->set_cell(
  ip_column    = 2
  ip_row       = 5
  ip_value     = lv_packed
  ip_abap_type = cl_abap_typedescr=>typekind_char ).

The ip_abap_type parameter accepts constants from cl_abap_typedescr (typekind_int, typekind_char, typekind_float, etc.).

ip_data_type — explicit Excel type

For direct control of the Excel cell type tag use ip_data_type (type zexcel_cell_data_type):

ConstantXML valueWhen to use
zcl_excel_worksheet=>c_cell_type_stringsForce string shared table entry
zcl_excel_worksheet=>c_cell_type_formulafFormula result type override
zcl_excel_worksheet=>c_cell_type_numbernNumeric (default for numbers)
zcl_excel_worksheet=>c_cell_type_booleanbTRUE / FALSE

Conversion exits

ip_conv_exit_length

When abap_true, applies the LENGTH conversion exit to a field before writing. This pads the value to the field's declared length, which preserves leading spaces in fixed-length character fields:

abap
lo_worksheet->set_cell(
  ip_column           = 1
  ip_row              = 5
  ip_value            = lv_field
  ip_conv_exit_length = abap_true ).

The same parameter is available on bind_table as ip_conv_exit_length (applies to all fields in the table).

ip_conv_curr_amt_ext

When abap_true on bind_table, applies the external currency-amount conversion exit to all CURR fields. This formats the value according to the currency's decimal places definition in table TCURX:

abap
lo_worksheet->bind_table(
  ip_table             = lt_sales
  it_field_catalog     = lt_catalog
  ip_conv_curr_amt_ext = abap_true ).

Currency fields in bind_table

For proper currency formatting, populate the currency field in zexcel_s_fieldcatalog and the corresponding ref_field pointing to the currency code column:

abap
ls_cat-fieldname = 'AMOUNT'.
ls_cat-currency  = 'EUR'.
ls_cat-ref_field = 'WAERS'.   " column holding the currency key
APPEND ls_cat TO lt_catalog.

The writer then formats the number cell with the matching Excel currency number format.

zcl_excel_common helper methods

MethodPurpose
convert_column2alphaInteger column number → alpha (1'A', 26'Z', 27'AA')
convert_column2intAlpha column → integer ('AA'27)
convert_date2excelABAP D date → Excel serial number
convert_time2excelABAP T time → fractional day
convert_excel2dateExcel serial → ABAP date
convert_columnrow2alphaColumn int + row int → cell reference string (2,3'B3')
excel_string_to_dateParse a date string from a cell value
excel_string_to_timeParse a time string from a cell value
abap
" Column number to letter
DATA(lv_alpha) = zcl_excel_common=>convert_column2alpha( 4 ).  " → 'D'

" ABAP date to Excel serial
DATA(lv_serial) = zcl_excel_common=>convert_date2excel( sy-datum ).

See also