string_to_solix - kazumov/abap GitHub Wiki

functional beginning:

report z_temp.
types: begin of rep,
         str1 type string,
         str2 type string,
         int3 type i,
       end of rep.
constants: c_tab type c value cl_bcs_convert=>gc_tab,
           c_cr  type c value cl_bcs_convert=>gc_crlf.
data: w_rep       type rep,
      t_rep       type table of rep,
      r_descr     type ref to cl_abap_structdescr,
      t_component type abap_component_tab.
field-symbols: <component> like line of t_component,
               <rep>       type rep,
               <cell>      type any.


w_rep-str1 = 'all'.
w_rep-str2 = 'you'.
w_rep-int3 = 1.
append w_rep to t_rep.

w_rep-str1 = 'need'.
w_rep-str2 = 'is'.
w_rep-int3 = 2.
append w_rep to t_rep.

w_rep-str1 = 'love'.
w_rep-str2 = '!'.
w_rep-int3 = 3.
append w_rep to t_rep.

r_descr ?= cl_abap_typedescr=>describe_by_data( w_rep ).
t_component = r_descr->get_components( ).

data: cell_cast type string,
      line      type string,
      raw       type string.

loop at t_rep assigning <rep>.
  loop at t_component assigning <component>.
    assign component <component>-name of structure <rep> to <cell>.
    cell_cast = <cell>.
    concatenate line cell_cast c_tab into line.
    unassign <cell>.
    clear cell_cast.
  endloop.
  concatenate raw line c_cr into raw.
  clear line.
endloop.

data: l_line type string,
      gt_binary_content type solix_tab,
      gv_size type so_obj_len.

l_line = raw.

try.
    cl_bcs_convert=>string_to_solix(
    exporting
    iv_string = l_line
    iv_codepage = '4103' "suitable for MS Excel, leave empty
    iv_add_bom = 'X' "for other doc types
    importing
    et_solix = gt_binary_content
    ev_size = gv_size ).
  catch cx_bcs.
    " message e445(so).
endtry.


cl_demo_output=>write_data( t_rep ).
cl_demo_output=>write_data( raw ).

cl_demo_output=>display( ).
⚠️ **GitHub.com Fallback** ⚠️