[ABAP] Google-API: QR-Code generieren und Bild herunterladen/speichern

* Dateiname der Bilddatei zum hochladen
PARAMETERS: p_fname TYPE file_table-filename OBLIGATORY.

START-OF-SELECTION.
* URL zur Google-API für die Erstellung des QR-Codes
  DATA(lv_url) = |http://chart.apis.google.com/chart?chs=200x200&cht=qr&chld=\|1&chl=viele%20lustige%20Zeichen/chart.png|.

  TRY.
      DATA: o_client TYPE REF TO if_http_client.
* Client-Objekt erzeugen
      cl_http_client=>create_by_url( EXPORTING
                                       url     = lv_url
                                     IMPORTING
                                       client  = o_client ).
      IF sy-subrc = 0.
* HTTP GET senden
        o_client->send( ).

* Response lesen
        o_client->receive( ).

        DATA: lv_http_status TYPE i.
        DATA: lv_status_text TYPE string.

* HTTP Return Code holen
        o_client->response->get_status( IMPORTING
                                          code   = lv_http_status
                                          reason = lv_status_text ).

* Wenn Status 200 (Ok)
        IF lv_http_status = 200.

* Binärdaten (QR-Code) auslesen
          DATA(lv_xdata) = o_client->response->get_data( ).

          o_client->close( ).

* xstring -> solix
          DATA(it_img_conv_data) = cl_bcs_convert=>xstring_to_solix( iv_xstring = lv_xdata ).

          WRITE: / |{ p_fname }.png|.

* Image lokal speichern
          cl_gui_frontend_services=>gui_download( EXPORTING
                                                    filename = |{ p_fname }.png|
                                                    filetype = 'BIN'
                                                  CHANGING
                                                    data_tab = it_img_conv_data ).

        ENDIF.
      ENDIF.
    CATCH cx_root INTO DATA(e_txt).
      WRITE: / e_txt->get_text( ).
  ENDTRY.

[ABAP] SMARTFORM-Formular (OTF) als PDF speichern und anzeigen

* Tabelle STXFADM
PARAMETERS: p_form TYPE stxfadm-formname DEFAULT 'ZFORMULARNAME'.
PARAMETERS: p_open TYPE abap_bool DEFAULT abap_true.

START-OF-SELECTION.
  DATA: lv_control_parameters TYPE ssfctrlop.

  lv_control_parameters-langu = to_upper( sy-langu ).
  lv_control_parameters-no_dialog = abap_true.
  lv_control_parameters-getotf = abap_true.

  DATA: lv_devtype TYPE rspoptype.

* Smart Forms: Gerätetyp nach Sprache ermitteln
  CALL FUNCTION 'SSF_GET_DEVICE_TYPE'
    EXPORTING
      i_language             = lv_control_parameters-langu
    IMPORTING
      e_devtype              = lv_devtype
    EXCEPTIONS
      no_language            = 1
      language_not_installed = 2
      no_devtype_found       = 3
      system_error           = 4
      OTHERS                 = 5.

  IF sy-subrc = 0.
    DATA: lv_output_options TYPE ssfcompop.
    lv_output_options-tdprinter = lv_devtype.

* FuBa Name ermitteln
    DATA: lv_fm_name TYPE rs38l_fnam.

* Smart Forms: Name des Funktionsbausteins bestimmen
    CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
      EXPORTING
        formname           = p_form
      IMPORTING
        fm_name            = lv_fm_name
      EXCEPTIONS
        no_form            = 1
        no_function_module = 2
        OTHERS             = 3.

    IF sy-subrc = 0.

      DATA: lv_document_output_info TYPE ssfcrespd.
      DATA: lv_job_output_info TYPE ssfcrescl.
      DATA: lv_job_output_options TYPE ssfcresop.

* FuBa der Form aufrufen und OTF-Daten erzeugen
      CALL FUNCTION lv_fm_name
        EXPORTING
          control_parameters   = lv_control_parameters
          output_options       = lv_output_options
        IMPORTING
          document_output_info = lv_document_output_info
          job_output_info      = lv_job_output_info
          job_output_options   = lv_job_output_options
        EXCEPTIONS
          formatting_error     = 1
          internal_error       = 2
          send_error           = 3
          user_canceled        = 4
          OTHERS               = 5.

      IF sy-subrc = 0.

        DATA: lv_bin_filesize TYPE i.
*        DATA: lv_pdf_xstring TYPE xstring.
        DATA: it_lines TYPE tline_t.

* Konvertieren von OTF-Format in verschiedene Formate (TLINE Tabelle)
        CALL FUNCTION 'CONVERT_OTF'
          EXPORTING
            format                = 'PDF'
          IMPORTING
            bin_filesize          = lv_bin_filesize
*           bin_file              = lv_pdf_xstring             " PDF Binärdaten
          TABLES
            otf                   = lv_job_output_info-otfdata " Input OTF
            lines                 = it_lines                   " Output
          EXCEPTIONS
            err_max_linewidth     = 1
            err_format            = 2
            err_conv_not_possible = 3
            err_bad_otf           = 4
            OTHERS                = 5.

        IF sy-subrc = 0.

          DATA: lv_action TYPE i.
          DATA: lv_filename TYPE string.
          DATA: lv_fullpath TYPE string.
          DATA: lv_path TYPE string.

          TRY.
* Speichern-Dialog
              cl_gui_frontend_services=>file_save_dialog( EXPORTING
                                                            default_file_name = |{ p_form }.pdf|
                                                            default_extension = 'pdf'
                                                            file_filter       = '(*.pdf)|*.pdf|'
                                                          CHANGING
                                                            filename          = lv_filename
                                                            path              = lv_path
                                                            fullpath          = lv_fullpath
                                                            user_action       = lv_action ).

              IF lv_action EQ cl_gui_frontend_services=>action_ok.
* Daten lokal speichern
                cl_gui_frontend_services=>gui_download( EXPORTING
                                                          bin_filesize = lv_bin_filesize
                                                          filename     = lv_fullpath
                                                          filetype     = 'BIN'
                                                        CHANGING
                                                          data_tab     = it_lines ).

                WRITE: / |Datei erfolgreich unter { lv_fullpath } gespeichert.|.

                IF abap_true = p_open.
* Datei anzeigen
                  cl_gui_frontend_services=>execute( document = lv_fullpath ).
                ENDIF.
              ENDIF.

            CATCH cx_root INTO DATA(e_text).
              WRITE: / e_text->get_text( ).
          ENDTRY.
        ENDIF.
      ELSE.

        DATA: it_sf_errors TYPE tsferror.

* Smart Forms: Lesen der Fehlertabelle nach Aufruf
        CALL FUNCTION 'SSF_READ_ERRORS'
          IMPORTING
            errortab = it_sf_errors.

        cl_demo_output=>display( it_sf_errors ).
      ENDIF.

    ELSE.
      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
    ENDIF.

  ELSE.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

[ABAP] Screenshot speichern

DATA: lv_mime_type TYPE string.
DATA: lv_image_bytes TYPE xstring.

TRY.
* Screenshot aufnehmen
    cl_gui_frontend_services=>get_screenshot( IMPORTING
                                                mime_type_str = lv_mime_type
                                                image         = lv_image_bytes ).

* MIME-Typ (PNG) ausgeben
    WRITE: / lv_mime_type.

    DATA: lv_action TYPE i.
    DATA: lv_filename TYPE string.
    DATA: lv_fullpath TYPE string.
    DATA: lv_path TYPE string.

* Savedialog anzeigen
    cl_gui_frontend_services=>file_save_dialog( EXPORTING
                                                  default_file_name = 'image.png'
                                                  default_extension = 'png'
                                                  file_filter       = '(*.png)|*.png|'
                                                CHANGING
                                                  filename          = lv_filename
                                                  path              = lv_path
                                                  fullpath          = lv_fullpath
                                                  user_action       = lv_action ).

    IF lv_action EQ cl_gui_frontend_services=>action_ok.

* XSTRING -> SOLIX (RAW)
      DATA(it_raw_data) = cl_bcs_convert=>xstring_to_solix( EXPORTING iv_xstring = lv_image_bytes ).

* Daten lokal speichern
      cl_gui_frontend_services=>gui_download( EXPORTING
                                                filename = lv_fullpath
                                                filetype = 'BIN'
                                              CHANGING
                                                data_tab = it_raw_data ).

    ENDIF.
  CATCH cx_root INTO DATA(e_txt).
ENDTRY.

[ABAP] Listenausgabe in Spool umleiten und als PDF ausgeben

* Liste -> Spool (ID)
NEW-PAGE PRINT ON NO DIALOG.
WRITE: / 'Hello World'.
NEW-PAGE PRINT OFF.

COMMIT WORK.

DATA: it_pdf_tline TYPE tline_tab.
DATA: lv_bin_length TYPE i.

* Spool (ID) -> PDF
CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
  EXPORTING
    src_spoolid              = CONV tsp01-rqident( sy-spono )
    no_dialog                = abap_true
    get_size_from_format     = abap_true
  IMPORTING
    pdf_bytecount            = lv_bin_length
  TABLES
    pdf                      = it_pdf_tline
  EXCEPTIONS
    err_no_abap_spooljob     = 1
    err_no_spooljob          = 2
    err_no_permission        = 3
    err_conv_not_possible    = 4
    err_bad_destdevice       = 5
    user_cancelled           = 6
    err_spoolerror           = 7
    err_temseerror           = 8
    err_btcjob_open_failed   = 9
    err_btcjob_submit_failed = 10
    err_btcjob_close_failed  = 11
    OTHERS                   = 12.

IF sy-subrc = 0.

  DATA: lv_action TYPE i.
  DATA: lv_filename TYPE string.
  DATA: lv_fullpath TYPE string.
  DATA: lv_path TYPE string.

  TRY.
* SaveDialog aufrufen
      cl_gui_frontend_services=>file_save_dialog( EXPORTING
                                                    default_extension   = 'pdf'
                                                    default_file_name   = 'ListOutput'
                                                    file_filter         = |PDF (*.pdf)\|*.pdf\|{ cl_gui_frontend_services=>filetype_all }|
                                                    prompt_on_overwrite = abap_true
                                                  CHANGING
                                                    filename          = lv_filename
                                                    path              = lv_path
                                                    fullpath          = lv_fullpath
                                                    user_action       = lv_action ).

      IF lv_action EQ cl_gui_frontend_services=>action_ok.
* iTab (bytes) -> lokale Datei
        cl_gui_frontend_services=>gui_download( EXPORTING
                                                  filename = lv_fullpath
                                                  filetype = 'BIN'
                                                CHANGING
                                                  data_tab = it_pdf_tline ).
      ENDIF.

    CATCH cx_root INTO DATA(e_txt).
      MESSAGE e_txt->get_text( ) TYPE 'S'.
  ENDTRY.
ENDIF.

Siehe auch: [ABAP] Spoolaufträge (OTF, OTFHPL2, SMART, TEXT) in PDF wandeln

[ABAP] XML-Daten in eine Datei (*.xml) schreiben

Variante 1 (lokal über XML-String)

* ixml Factory
  DATA(o_ixml) = cl_ixml=>create( ).

* Encoding UTF-8
  DATA(o_encoding) = o_ixml->create_encoding( character_set = 'UTF-8'
                                              byte_order = if_ixml_encoding=>co_none ).

* DOM Object Model
  DATA(o_doc) = o_ixml->create_document( ).

  ...

* XML-Dokument rendern
  DATA(o_sf) = o_ixml->create_stream_factory( ).

* XML-String
  DATA: lv_xml TYPE string.

* Stream für Ausgabe in XML-String
  DATA(o_stream) = o_sf->create_ostream_cstring( lv_xml ).
  o_stream->set_encoding( encoding = o_encoding ).
  o_stream->set_pretty_print( pretty_print = abap_true ).

* Render-Objekt
  DATA(o_render) = o_ixml->create_renderer( ostream  = o_stream
                                            document = o_doc ).

* XML-String in lv_xml generieren
  DATA(lv_rc) = o_render->render( ).

* Dateigröße in Bytes
  DATA(lv_size) = o_stream->get_num_written_raw( ).
  
* Stream schließen
  o_stream->close( ).

* Wenn alles ok
  IF lv_rc = 0 AND lv_size > 0.
  * XML-String in XML-Document wandeln
    DATA(o_xml_doc) = NEW cl_xml_document( ).
    o_xml_doc->parse_string( lv_xml ).

  * XML-Document als Datei speichern
    o_xml_doc->export_to_file( 'c:\temp\test.xml' ).
  ENDIF.

Variante 2 (lokal über XML-iTab)

* ixml Factory
  DATA(o_ixml) = cl_ixml=>create( ).

* Encoding UTF-8
  DATA(o_encoding) = o_ixml->create_encoding( character_set = 'UTF-8'
                                              byte_order = if_ixml_encoding=>co_none ).

* DOM Object Model
  DATA(o_doc) = o_ixml->create_document( ).

  ...

* XML-Dokument rendern
  DATA(o_sf) = o_ixml->create_stream_factory( ).

* XML-iTab
  DATA: it_xml_out TYPE STANDARD TABLE OF char255 WITH DEFAULT KEY.

* Encoding UTF-8
  DATA(o_encoding) = o_ixml->create_encoding( character_set = 'UTF-8'
                                              byte_order = if_ixml_encoding=>co_none ).

* Stream für Ausgabe in XML-iTab
  DATA(o_stream) = o_sf->create_ostream_itable( table = it_xml_out ).
  o_stream->set_encoding( encoding = o_encoding ).

* Render-Objekt
  DATA(o_render) = o_ixml->create_renderer( ostream  = o_stream
                                            document = o_doc ).

  o_render->set_normalizing( is_normalizing = space ).

* XML-String in it_xml_out generieren
  DATA(lv_rc) = o_render->render( ).

* Dateigröße in Bytes
  DATA(lv_size) = o_stream->get_num_written_raw( ).
  
* Stream schließen
  o_stream->close( ).

* Wenn alles ok
  IF lv_rc = 0 AND lv_size > 0.
* Tabelle als Binär-Daten herunterladen
    cl_gui_frontend_services=>gui_download( EXPORTING
                                              filename = 'c:\temp\test.xml'
                                              filetype = 'BIN'
                                              bin_filesize = lv_size
                                            CHANGING
                                              data_tab = it_xml_out ).
  ENDIF.

Variante 3 (Applikationsserver)

* ixml Factory
  DATA(o_ixml) = cl_ixml=>create( ).

* DOM Object Model
  DATA(o_doc) = o_ixml->create_document( ).
  
  ...
  
* XML-Dokument rendern
  DATA(o_sf) = o_ixml->create_stream_factory( ).

* Encoding UTF-8
  DATA(o_encoding) = o_ixml->create_encoding( character_set = 'UTF-8'
                                              byte_order = if_ixml_encoding=>co_none ).

* Stream für Ausgabe in Datei '/tmp/test/test.xml' auf dem Applikationsserver
  DATA(o_stream) = o_sf->create_ostream_uri( system_id = '/tmp/test/test.xml' ).
  o_stream->set_encoding( encoding = o_encoding ).
  o_stream->set_pretty_print( pretty_print = abap_true ).

* Render-Objekt
  DATA(o_render) = o_ixml->create_renderer( ostream  = o_stream
                                            document = o_doc ).

* XML-String in Datei auf Applikationsserver generieren
  DATA(lv_rc) = o_render->render( ).

* Dateigröße in Bytes
  DATA(lv_size) = o_stream->get_num_written_raw( ).
  
* Stream schließen
  o_stream->close( ).

* Wenn alles ok
  IF lv_rc = 0 AND lv_size > 0.
    ...
  ENDIF.

[ABAP] IDoc als XML-Datei speichern

PARAMETERS: p_idoc TYPE edi_docnum.

START-OF-SELECTION.

  TRY.
      DATA(o_idoc_xml) = NEW cl_idoc_xml1( docnum = p_idoc ).

      DATA: lv_xml TYPE string.

      o_idoc_xml->get_xmldata_as_string( IMPORTING data_string = lv_xml ).

      DATA(it_xml) = VALUE stringtab( ( |{ lv_xml }| ) ).

      DATA: lv_temp_dir TYPE string.

* Temp-Directory holen
      cl_gui_frontend_services=>get_desktop_directory( CHANGING desktop_directory = lv_temp_dir ).
* Note 1442303, sonst ist lv_temp_dir leer
      cl_gui_cfw=>flush( ).

* Dateinamen zusammenbauen
      DATA(lv_filename) = |{ lv_temp_dir }\\my_xml.xml|.

* Datei im Zielverzeichnis erzeugen
      cl_gui_frontend_services=>gui_download( EXPORTING
                                                filename = lv_filename
                                                filetype = 'ASC'
                                              CHANGING
                                                data_tab = it_xml ).

      WRITE: / lv_filename.
    CATCH cx_root INTO DATA(e_txt).
      WRITE: / e_txt->get_text( ).
  ENDTRY.

[ABAP] VBA-Code ausführen

* VBA-Code
DATA(it_vba_code) = VALUE stringtab( ( |Dim app| )
                                     ( |Set app = CreateObject("Access.Application")| )
                                     ( |Dim msg| )
                                     ( |msg = MsgBox ("My Message.", 0, "Warning")| ) ).

DATA: lv_temp_dir TYPE string.

* Temp-Directory holen
cl_gui_frontend_services=>get_desktop_directory( CHANGING desktop_directory = lv_temp_dir ).
* Note 1442303, sonst ist lv_temp_dir leer
cl_gui_cfw=>flush( ).

* Dateinamen zusammenbauen
DATA(lv_filename) = |{ lv_temp_dir }\\my_script.vbs|.

* Datei im Zielverzeichnis erzeugen
cl_gui_frontend_services=>gui_download( EXPORTING
                                          filename = lv_filename
                                          filetype = 'ASC'
                                        CHANGING
                                          data_tab = it_vba_code ).

LOOP AT it_vba_code ASSIGNING FIELD-SYMBOL(<fs_line>).
  WRITE: / <fs_line>.
ENDLOOP.

SKIP.

WRITE: / lv_filename.

* VBA über Scripting Host ausführen
* "" für lv_filename ergänzen, sonst wird der Pfad unter parameter nicht korrekt übergeben,
* da Leerzeichen im Pfad als Trennung in einzelne Parameter erkannt wird
cl_gui_frontend_services=>execute( application = 'WSCRIPT.EXE'
                                   parameter   = |"{ lv_filename }"| ).

[ABAP] Spoolaufträge (OTF, OTFHPL2, SMART, TEXT) in PDF wandeln

TYPES: BEGIN OF ty_spool,
         rqident   TYPE tsp01-rqident,
         rqtitle   TYPE tsp01-rqtitle,
         rqdest    TYPE tsp01-rqdest,
         rqpaper   TYPE tsp01-rqpaper,
         rqdoctype TYPE tsp01-rqdoctype,
       END OF ty_spool.

* Nr. des Spoolauftrags
PARAMETERS: p_spool TYPE tsp01-rqident OBLIGATORY.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_spool.
  DATA: it_spool TYPE TABLE OF ty_spool.
  DATA: it_return TYPE TABLE OF ddshretval.

  CLEAR: it_spool.

  SELECT rqident, rqtitle, rqdest, rqpaper, rqdoctype FROM tsp01
    INTO CORRESPONDING FIELDS OF TABLE @it_spool
    ORDER BY rqident.

* eigene Suuchhilfe für Auswahl der Spooljobs anzeigen
  CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
    EXPORTING
      retfield        = 'RQIDENT'     " Spalte der internen Tabelle bei value_tab
      dynpprog        = sy-repid
      dynpnr          = sy-dynnr
      dynprofield     = 'P_SPOOL'     " Name des Dynpro-Feldes für die automatische Werterückgabe
      value_org       = 'S'           " Werteübergabe: C: zellenweise, S: strukturiert
      window_title    = 'Auswahl'
    TABLES
      value_tab       = it_spool      " Übergabe-Tabelle mit Werten für die Anzeige und Auswahl
      return_tab      = it_return     " Rückgabe-Tabelle mit den ausgewählten (geklickten) Elementen
    EXCEPTIONS
      parameter_error = 1
      no_values_found = 2
      OTHERS          = 3.

  IF sy-subrc = 0.
    IF lines( it_return ) > 0.
      MESSAGE it_return[ 1 ]-fieldval TYPE 'S'.
    ENDIF.
  ENDIF.

START-OF-SELECTION.
  DATA: lv_tsp01_sel TYPE tsp01.

  SELECT SINGLE * FROM tsp01
    INTO CORRESPONDING FIELDS OF @lv_tsp01_sel
    WHERE rqident = @p_spool.

  IF sy-subrc = 0.
* Dummys für Aufruf von RSPO_RETURN_SPOOLJOB
    DATA: it_otf TYPE STANDARD TABLE OF soli.
    DATA: it_pdf TYPE STANDARD TABLE OF tline.

* Spooljob als iTab holen
    CALL FUNCTION 'RSPO_RETURN_SPOOLJOB'
      EXPORTING
        rqident              = p_spool
        desired_type         = 'RAW' " RAW, ALI, OTF, PDF
      TABLES
        buffer               = it_otf
        buffer_pdf           = it_pdf
      EXCEPTIONS
        no_such_job          = 1
        job_contains_no_data = 2
        selection_empty      = 3
        no_permission        = 4
        can_not_access       = 5
        read_error           = 6
        type_no_match        = 7
        OTHERS               = 8.

    IF sy-subrc <> 0.
      WRITE: 'Spoolauftrag nicht vorhanden: ', sy-subrc.
    ELSE.
      DATA: lv_objtype TYPE rststype-type.
      DATA: lv_type TYPE rststype-type.

* Eigenschaften des TemSe Objektes holen
      CALL FUNCTION 'RSTS_GET_ATTRIBUTES'
        EXPORTING
          authority     = 'SP01'
          client        = lv_tsp01_sel-rqclient
          name          = lv_tsp01_sel-rqo1name
          part          = 1
        IMPORTING
          objtype       = lv_objtype
        EXCEPTIONS
          fb_error      = 1
          fb_rsts_other = 2
          no_object     = 3
          no_permission = 4.

      IF sy-subrc <> 0.
        WRITE: 'Fehler beim Holen der Attribute.', sy-subrc.
      ELSE.
        DATA: numbytes TYPE i.
        DATA: pdfspoolid LIKE tsp01-rqident.
        DATA: jobname TYPE tbtcjob-jobname.
        DATA: jobcount TYPE tbtcjob-jobcount.
        DATA: pdf TYPE STANDARD TABLE OF tline.

* Konvertierung anhand des Typs vornehmen
        CASE lv_objtype.
          WHEN 'OTF' OR 'OTFHPL2' OR 'SMART'.
            CALL FUNCTION 'CONVERT_OTFSPOOLJOB_2_PDF'
              EXPORTING
                src_spoolid              = p_spool
                no_dialog                = ' '
              IMPORTING
                pdf_bytecount            = numbytes
                pdf_spoolid              = pdfspoolid
                btc_jobname              = jobname
                btc_jobcount             = jobcount
              TABLES
                pdf                      = pdf
              EXCEPTIONS
                err_no_otf_spooljob      = 1
                err_no_spooljob          = 2
                err_no_permission        = 3
                err_conv_not_possible    = 4
                err_bad_dstdevice        = 5
                user_cancelled           = 6
                err_spoolerror           = 7
                err_temseerror           = 8
                err_btcjob_open_failed   = 9
                err_btcjob_submit_failed = 10
                err_btcjob_close_failed  = 11.

            IF sy-subrc <> 0.
              WRITE: / 'Fehler bei der OTF->PDF Konvertierung:', sy-subrc.
            ELSE.

            ENDIF.

          WHEN 'TEXT'.
            CALL FUNCTION 'CONVERT_ABAPSPOOLJOB_2_PDF'
              EXPORTING
                src_spoolid              = p_spool
                no_dialog                = ' '
                get_size_from_format     = 'X'
              IMPORTING
                pdf_bytecount            = numbytes
                pdf_spoolid              = pdfspoolid
                btc_jobname              = jobname
                btc_jobcount             = jobcount
              TABLES
                pdf                      = pdf
              EXCEPTIONS
                err_no_abap_spooljob     = 1
                err_no_spooljob          = 2
                err_no_permission        = 3
                err_conv_not_possible    = 4
                err_bad_destdevice       = 5
                user_cancelled           = 6
                err_spoolerror           = 7
                err_temseerror           = 8
                err_btcjob_open_failed   = 9
                err_btcjob_submit_failed = 10
                err_btcjob_close_failed  = 11.

            IF sy-subrc <> 0.
              WRITE: / 'Fehler bei der TEXT->PDF Konvertierung: ', sy-subrc.
            ELSE.

            ENDIF.

          WHEN OTHERS.
            WRITE: / 'Verarbeitungsschritt derzeit nicht implementiert:', lv_objtype.
        ENDCASE.

* wenn erfolgreich -> PDF speichern
        IF ( numbytes > 0 ) AND ( NOT pdf IS INITIAL ).
          DATA: lv_action TYPE i.
          DATA: lv_filename TYPE string.
          DATA: lv_fullpath TYPE string.
          DATA: lv_path TYPE string.

          TRY.
              cl_gui_frontend_services=>file_save_dialog( EXPORTING
                                                            default_file_name = |{ p_spool }|
                                                            default_extension   = 'pdf'
                                                            file_filter         = '(*.pdf)|*.pdf|'
                                                          CHANGING
                                                            filename          = lv_filename
                                                            path              = lv_path
                                                            fullpath          = lv_fullpath
                                                            user_action       = lv_action ).

              IF lv_action EQ cl_gui_frontend_services=>action_ok.
                cl_gui_frontend_services=>gui_download( EXPORTING
                                                          filename = lv_fullpath
                                                          filetype = 'BIN'
                                                        CHANGING
                                                          data_tab = pdf ).

* PDF im ECL viewer anzeigen
                DATA(o_viewer) = NEW cl_gui_ecl_viewerbox( ).

* Fullscreen
                o_viewer->set_alignment( alignment = cl_gui_control=>align_at_left + cl_gui_control=>align_at_right + cl_gui_control=>align_at_top + cl_gui_control=>align_at_bottom ).

* PDF öffnen
                o_viewer->open_document( file = CONV #( lv_fullpath )
                                         file_type = 'application/pdf' ).

                WRITE: / |Datei erfolgreich unter { lv_fullpath } gespeichert.|.
              ENDIF.

            CATCH cx_root INTO DATA(e_text).          " Oberklasse für Exceptions abfangen und Kurztext übergeben
              WRITE: / e_text->get_text( ).
          ENDTRY.

        ENDIF.
      ENDIF.
    ENDIF.
  ELSE.
    WRITE: / |Spoolauftrag { p_spool } nicht vorhanden.|.
  ENDIF.

[ABAP] Interne Tabelle als Datei (CSV) auf den lokalen Rechner speichern

DATA: itab TYPE STANDARD TABLE OF string.
DATA: lv_file TYPE string VALUE 'c:\temp\test.txt'.

...
 
TRY.
  cl_gui_frontend_services=>gui_download(
    EXPORTING
      filename = lv_file
      filetype = 'DAT'  " mögliche Filetypen: BIN, ASC, DAT, DBF, WK1, VSS, IBM
      codepage = '4110' " UTF-8 Encoding: 4110, UTF-16 Big Endian : 4102, UTF-16 Little Endian : 4103.    
    CHANGING
      data_tab = itab ).
  CATCH cx_root INTO DATA(e_text).
    MESSAGE e_text->get_text( ) TYPE 'I'.
ENDTRY.

Weiterführende Infos: Link