Skip to content

RFC_READ_TABLE

Read any transparent database table generically — without writing an ABAP program.

Purpose

RFC_READ_TABLE returns rows from any SAP transparent table via RFC. It's the go-to FM for quick data extraction, third-party integrations (Python, Java, .NET), and prototyping — because you don't need to write a custom ABAP program just to read a table.

Not for production data loads

The FM has a hard row-width limit of 512 characters (older systems) or 32 KB (newer). Wide tables with many fields can silently truncate rows. For production-grade extraction use a proper ABAP SELECT or a dedicated BAPI.

Signature (the parts you'll actually use)

Parameter Direction Type Notes
QUERY_TABLE IMPORTING DD02L-TABNAME Table name. Required.
DELIMITER IMPORTING CHAR1 Column separator in the output (default: space). Use \| to avoid collisions.
NO_DATA IMPORTING CHAR1 Pass 'X' to get only field metadata, no rows.
ROWSKIPS IMPORTING INT4 Skip first N rows (pagination).
ROWCOUNT IMPORTING INT4 Max rows to return (0 = all).
FIELDS TABLES RFC_DB_FLD Which fields to return. Leave empty = all fields.
OPTIONS TABLES RFC_DB_OPT WHERE clause fragments — each row max 72 chars.
DATA TABLES TAB512 Output rows as flat strings, split by DELIMITER.

Example — read with a WHERE clause

DATA: lt_fields  TYPE STANDARD TABLE OF rfc_db_fld,
      lt_options TYPE STANDARD TABLE OF rfc_db_opt,
      lt_data    TYPE STANDARD TABLE OF tab512.

" Restrict columns
APPEND VALUE rfc_db_fld( fieldname = 'BNAME'  ) TO lt_fields.
APPEND VALUE rfc_db_fld( fieldname = 'USTYP'  ) TO lt_fields.
APPEND VALUE rfc_db_fld( fieldname = 'GLTGB'  ) TO lt_fields.

" WHERE clause — each line max 72 chars, they are concatenated with spaces
APPEND VALUE rfc_db_opt( text = 'MANDT = SY-MANDT' ) TO lt_options.
APPEND VALUE rfc_db_opt( text = 'AND USTYP = ''A'''  ) TO lt_options.

CALL FUNCTION 'RFC_READ_TABLE'
  EXPORTING
    query_table = 'USR02'
    delimiter   = '|'
    rowcount    = 200
  TABLES
    fields      = lt_fields
    options     = lt_options
    data        = lt_data
  EXCEPTIONS
    table_not_available      = 1
    table_without_data       = 2
    option_not_valid         = 3
    field_not_valid          = 4
    not_authorized           = 5
    data_buffer_exceeded     = 6
    OTHERS                   = 7.

IF sy-subrc <> 0.
  MESSAGE ID sy-msgid TYPE 'E' NUMBER sy-msgno.
ENDIF.

" Parse each row by the delimiter
LOOP AT lt_data INTO DATA(ls_row).
  SPLIT ls_row-wa AT '|' INTO DATA(lv_bname) DATA(lv_ustyp) DATA(lv_gltgb).
  WRITE: / lv_bname, lv_ustyp, lv_gltgb.
ENDLOOP.

Common pitfalls

Row width limit

The output table DATA has a field width of 512 bytes. If the sum of selected field lengths exceeds this (or 32 KB on patched systems), DATA_BUFFER_EXCEEDED fires. Always specify FIELDS — never leave it empty on wide tables.

WHERE clause formatting

Each OPTIONS row is appended as-is with a space between rows. The total WHERE string has no length limit, but each line must be ≤ 72 characters. String literals inside the WHERE clause need doubled single quotes: 'AND NAME = ''SMITH'''.

  • Client-dependency: the FM does not automatically filter by MANDT. Add MANDT = SY-MANDT to OPTIONS for client-dependent tables, or you'll get data from all clients.
  • Authorization: the caller needs S_TABU_DIS with activity 03 for the table's authorization group. Missing auth returns NOT_AUTHORIZED.
  • No JOINs: one table at a time. For joined data, use a proper SELECT or a custom RFC wrapper.

Alternatives

Need Better option
Production extraction Custom SELECT in an RFC-enabled FM
Wide tables SSFCOMP_PDF_GET or OData service
From external system SAP NW RFC SDK + RFC_READ_TABLE is fine for low-volume
S/4HANA CDS views Query via OData / RAP instead

See also

  • /BODS/RFC_READ_TABLE — a patched version with extended row width (available in some systems)
  • BBP_RFC_READ_TABLE — another common variant
  • Transaction SE16 / SE16N — interactive table browser using the same principle

Comments