Copyright 2024 - BV TallVision IT

Large strings: type XSTRING can be used to hold large XML file content or even in the process of creating a PDF file. XSTRING is a predefined data type in Abap/4. It works pretty much like a string, but with no limits to it's size. Both STRING and XSTRING have a variabele maximum size.

The maximum size of STRING is determined by a systems profile parameter ztta/max_memreq_MB - "Limit for a single request to memory" which is set to 2047 on our system (Check report RSPARAM). That's 2047MB of data in a String, makes you wonder what xstring is really for ? Me too. 

To transform your string into an xstring, there is a utility class available, which can be used like so:

data: lv_string_input type string, 
      lv_string_output type xsequence, 
      lv_length type i, 
      lo_convout type ref to cl_abap_conv_out_ce.

  try.
      l_convout = cl_abap_conv_out_ce=>create(
          encoding = 'UTF-8' ).

      l_convout->convert(
        exporting
          data   = im_string
        importing
          buffer = lv_string_output
          len    = lv_length ).

    catch cx_root.
      message 'Conversion failure' type 'E'.
  endtry.

Function module SCMS_STRING_TO_XSTRING gets this job done (as function module call). There is also a module SCMS_XSTRING_TO_BINARYwhich can be used to save your data as a binary file, as per example:

data lt_binary_records type table of x255 with header line.

lv_file_len = xstrlen( lv_xml_xstring ).
call function 'SCMS_XSTRING_TO_BINARY'
  exporting
    buffer     = lv_xml_xstring
  tables
    binary_tab = lt_binary_records.

  open dataset p_file for output in binary mode.
  loop at lt_binary_records.
    transfer lt_binary_records to p_file.
  endloop.

  close dataset p_file.