Jul 14, 2026

Upload Internal Table to Application Server (AL11) in CSV format Using Class CL_RSDA_CSV_CONVERTER, Method STRUCTURE_TO_CSV

Here is another way to upload internal table to Application Server into CSV format.  
And upload using statement OPEN DATASET.

  DATA: lt_csv_format TYPE truxs_t_text_data, " Standard table type for text
        lv_filepath   TYPE string,
        lv_csv_line   TYPE string.    

  " .... Assuming GT_CSV already populated.

  " Convert internal table to CSV structure
  DATA: lv_c4096 TYPE c LENGTH 4096.
  DATA(lo_csv) = cl_rsda_csv_converter=>create( ).

  " Covert line by line item
  LOOP AT gt_csv ASSIGNING FIELD-SYMBOL(<ls_csv>).
    CLEAR lv_c4096.
    lo_csv->structure_to_csv( EXPORTING i_s_data = <ls_csv>
                              IMPORTING e_data   = lv_c4096 ).
    APPEND INITIAL LINE TO lt_csv_format ASSIGNING FIELD-SYMBOL(<ls_csv_format>).
    IF sy-subrc EQ 0.
      <ls_csv_format> = lv_c4096.
    ENDIF.
  ENDLOOP.

  IF sy-subrc = 0.

    " Write to Application Server
    OPEN DATASET lv_filepath FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

    IF sy-subrc = 0.
      LOOP AT lt_csv_format INTO lv_csv_line.
        TRANSFER lv_csv_line TO lv_filepath.
      ENDLOOP.
      CLOSE DATASET lv_filepath.
    ENDIF.

  ENDIF.

No comments :