SAP function moduleObjectSCMS_XSTRING_TO_BINARYModuleABAP

SCMS_XSTRING_TO_BINARY — Convert XSTRING to Binary Table

SCMS_XSTRING_TO_BINARY is a released, standard SAP function module that converts an XSTRING value into a binary table (fixed-length raw records, typically SOLIX-structured) plus an exact output length. It is used whenever a byte stream generated as XSTRING must be handed to an older interface, download routine, or attachment API that still expects a binary table rather than a raw string.

This page covers the standard XSTRING-to-binary-table conversion utility used throughout custom ABAP code that bridges modern byte-string handling with legacy binary-table interfaces such as file download or document attachment. It focuses on the parameters that actually matter for correctness, the single generic exception and what it hides, and the padding trap that corrupts output files when OUTPUT_LENGTH is ignored.

Published 16 Sept 2026· 986 words

What it does

SCMS_XSTRING_TO_BINARY converts a value of type XSTRING into a binary table, generally structured like SOLIX (a table of 255 or 1024-byte raw records depending on the structure used), together with the exact byte length of the converted data. It exists because many older or still-current APIs, including file download routines and document/attachment interfaces, were built to accept binary tables rather than the XSTRING type introduced later in the ABAP type system. It is a released, generic Basis-level utility function module, safe for direct use in custom ABAP code and widely used in reports, class methods, and RFC-enabled programs that need to move byte data between XSTRING-based logic and binary-table-based logic without writing manual chunking code.

Parameters

  • BUFFER (importing, type XSTRING) - the source byte data to convert. If initial, the function has nothing meaningful to convert and downstream output will be empty.
  • APPEND_TO_TABLE (importing, optional, flag) - when set, the converted records are appended to whatever is already in BINARY_TAB instead of overwriting it. Leaving the target table uncleared between calls while using this flag mixes old and new data.
  • BINARY_TAB (tables parameter) - the resulting binary table, filled with fixed-length raw records. This is the structure passed on to consumers such as file download or attachment-building routines.
  • OUTPUT_LENGTH (exporting, type i or similar integer) - the exact number of bytes contained in BINARY_TAB, as opposed to the raw size of the table (number of lines times record length). This is the value that must be used wherever an exact file or content size is required.

Exceptions

  • FAILED - a single, generic catch-all exception. It does not distinguish between an empty BUFFER, an internal conversion problem, or any other failure mode; it simply signals that no usable binary table was produced.
  • When FAILED is not checked, the calling program proceeds with an empty or partial BINARY_TAB and a meaningless OUTPUT_LENGTH. The visible symptom shows up downstream, not here: a zero-byte downloaded file, an email attachment that fails to open, or a document viewer reporting a damaged file, none of which point a first responder back to this function module unless the call site is inspected directly.
  • Because the exception carries no further detail, diagnosing the real cause means checking the state of BUFFER before the call, not interrogating the exception after it.

How to call it safely

Call the function module passing the source XSTRING into BUFFER, and receive BINARY_TAB and OUTPUT_LENGTH. Immediately after the call, check the sy-subrc from the FAILED exception, then check that OUTPUT_LENGTH is greater than zero and roughly consistent with the expected content size. Do not derive the byte count from the number of lines in BINARY_TAB multiplied by the record length; the final record is padded to full length and that padding is not part of the real content. Whatever length value is passed onward to a download, attachment, or archiving API must be OUTPUT_LENGTH, never a computed table size.

ECC vs S/4HANA

SCMS_XSTRING_TO_BINARY remains available and functionally unchanged on S/4HANA. It is not marked obsolete and has no announced replacement; XSTRING and binary-table interfaces continue to coexist because many attachment, archiving, and download APIs still expect binary tables. In a strict clean-core development model on SAP BTP ABAP environment, its release-for-cloud-development status should be checked before reuse, but in classic on-premise and private-cloud custom development it is treated as an ordinary, stable Basis utility with no migration pressure attached to it.

Common pitfalls

  • Using BINARY_TAB line count times record length as the file size instead of OUTPUT_LENGTH, which appends trailing null-byte padding to the last record and corrupts binary formats such as PDF, ZIP, or Office documents at the end of the file.
  • Passing an initial or empty BUFFER without checking for it first, so FAILED is either silently ignored or triggers a generic short dump far from the actual root cause.
  • Calling this in a loop without clearing BINARY_TAB between iterations while relying on APPEND_TO_TABLE, resulting in a table that accumulates records from all prior iterations instead of holding only the current document.
  • Confusing this function module with its inverse, SCMS_BINARY_TO_XSTRING, and chaining unnecessary round-trip conversions that add processing time and additional points of failure for no functional gain.
  • Assuming the exception text explains what went wrong; FAILED gives no diagnostic detail, so troubleshooting has to start from the caller's input data, not from the exception message.

Whose problem this is

This is a Basis-owned generic utility, not tied to any functional module. In practice, failures traced to it are almost always a defect in the custom program calling it, so ownership sits with the development team that wrote the calling code, not with Basis or a functional team. Basis involvement is warranted only if there is genuine evidence of a kernel-level or runtime defect, which is rare.

Related SAP objects

Reviewed pages this object connects to in the ERPClimb knowledge graph.

Source: ERPClimb — https://erpclimb.com/sap-function-modules/scms-xstring-to-binaryERPClimb is an independent platform and is not affiliated with SAP SE. Reference pages are written and reviewed by SAP consultants for learning and troubleshooting.