Copyright 2022 - 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.

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

          data   = im_string
          buffer = lv_string_output
          len    = lv_length ).

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

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'
    buffer     = lv_xml_xstring
    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.

  close dataset p_file.