[ABAP] Alle SAP-Objekttypen + Texte auflisten

DATA: it_types_in TYPE STANDARD TABLE OF KO105 WITH DEFAULT KEY.
DATA: it_types_out TYPE STANDARD TABLE OF KO100 WITH DEFAULT KEY.

* Intern: Tabelle mit allen Objekttypen inklusive Texten
CALL FUNCTION 'TRINT_OBJECT_TABLE'
  EXPORTING
    iv_complete  = abap_true
  TABLES
    tt_types_in  = it_types_in
    tt_types_out = it_types_out.

cl_demo_output=>write_data( it_types_in ).
cl_demo_output=>write_data( it_types_out ).
* HTML-Code vom Demo-Output holen
DATA(lv_html) = cl_demo_output=>get( ).
* Daten im Inline-Browser im SAP-Fenster anzeigen
cl_abap_browser=>show_html( EXPORTING title       = 'SAP-Objekttypen'
                                      html_string = lv_html
                                      container   = cl_gui_container=>default_screen ).

* cl_gui_container=>default_screen erzwingen
WRITE: space.

[ABAP] Tabelleninhalt in Transportauftrag übernehmen

DATA: lv_result TYPE cts_result.
DATA: lv_messages TYPE cts_messages.
DATA: lv_request TYPE cts_request.
DATA: lv_object_locks TYPE cts_object_locks.
DATA: lv_trkorr TYPE trkorr.

TRY.
    cl_adt_cts_management=>insert_objects_in_wb_request( EXPORTING pgmid        = 'R3TR'
                                                                   object       = 'TABU'
                                                                   obj_name     = CONV #( 'Z_TABLE_NAME' )
                                                                   as4text      = 'Neuer Transportauftrag für Tabelleninhalt'
                                                         IMPORTING result       = lv_result
                                                                   messages     = lv_messages
                                                                   request      = lv_request
                                                                   object_locks = lv_object_locks
                                                         CHANGING  trkorr       = lv_trkorr ).

    cl_demo_output=>write_data( lv_trkorr ).
    cl_demo_output=>write_data( lv_result ).
    cl_demo_output=>write_data( lv_messages ).
    cl_demo_output=>write_data( lv_request ).
    cl_demo_output=>write_data( lv_object_locks ).

* HTML-Code vom Demo-Output holen
    DATA(lv_html) = cl_demo_output=>get( ).
* Daten im Inline-Browser im SAP-Fenster anzeigen
    cl_abap_browser=>show_html( EXPORTING title       = 'Transport Info'
                                          html_string = lv_html
                                          container   = cl_gui_container=>default_screen ).

* cl_gui_container=>default_screen erzwingen
    WRITE: space.
  CATCH cx_root INTO DATA(e_txt).
    WRITE: / e_txt->get_text( ).
ENDTRY.

[ABAP] Unterpakete zu einem Paket holen

TRY.
    cl_pak_package_queries=>get_all_subpackages( EXPORTING im_package                  = 'Z_PACKAGE_NAME'
                                                 IMPORTING et_subpackages              = DATA(it_sub_packages)
                                                           et_subpackages_with_details = DATA(it_sub_packages_details) ).

    cl_demo_output=>write_data( it_sub_packages ).
    cl_demo_output=>write_data( it_sub_packages_details ).

* HTML-Code vom Demo-Output holen
    DATA(lv_html) = cl_demo_output=>get( ).
* Daten im Inline-Browser im SAP-Fenster anzeigen
    cl_abap_browser=>show_html( EXPORTING title       = 'Übersicht Unterpakete'
                                          html_string = lv_html
                                          container   = cl_gui_container=>default_screen ).

* cl_gui_container=>default_screen erzwingen
    WRITE: space.
  CATCH cx_root INTO DATA(e_txt).
    WRITE: / e_txt->get_text( ).
ENDTRY.

[ABAP] Leeren Transportauftrag anlegen

* TRFUNCTION
*  K  Workbench-Auftrag
*  W  Customizing-Auftrag
*  C  Umzug von Objekten ohne Paketwechsel
*  O  Umzug von Objekten mit Paketwechsel
*  E  Umzug eines kompletten Pakets
*  T  Transport von Kopien
*  S  Entwicklung/Korrektur
*  R  Reparatur
*  X  Unklassifizierte Aufgabe
*  Q  Customizing-Aufgabe
*  G  Stückliste für CTS-Projekt
*  M  Auftrag für Mandantentransport
*  P  Stückliste für Upgrade
*  D  Stückliste für Patch
*  F  Stückliste
*  L  Löschtransport
TRY.
    cl_adt_cts_management=>create_empty_request( EXPORTING iv_type           = 'K'
                                                           iv_text           = 'Text für Transportauftrag'
*                                                           iv_owner          =
*                                                           it_users          =
*                                                           iv_target         =
                                                 IMPORTING es_request_header = DATA(lv_request_header) ).

    cl_demo_output=>write_data( lv_request_header ).

* HTML-Code vom Demo-Output holen
    DATA(lv_html) = cl_demo_output=>get( ).
* Daten im Inline-Browser im SAP-Fenster anzeigen
    cl_abap_browser=>show_html( EXPORTING title       = 'Übersicht Unterpakete'
                                          html_string = lv_html
                                          container   = cl_gui_container=>default_screen ).

* cl_gui_container=>default_screen erzwingen
    WRITE: space.
  CATCH cx_root INTO DATA(e_txt).
    WRITE: / e_txt->get_text( ).
ENDTRY.

[ABAP] F4-Hilfe für Transportaufträge und Transportaufgaben

* Siehe Typgruppe SCTSC (Konstanten CTS)
DATA: lv_tkorr TYPE e070-trkorr.
DATA: lv_korr_head TYPE trwbo_request_header.

* F4-Hilfe für Aufträge/Aufgaben
CALL FUNCTION 'TR_F4_REQUESTS'
  EXPORTING
    iv_username             = sy-uname
    iv_client               = sy-mandt
    iv_trfunctions          = 'KW'     "TRFUNCTION: Workbench - K, Customizing - W"
    iv_trstatus             = 'DLRO'   "TRSTATUS: Änderbar - D, Geschützt - L, Freigabe gestartet - O, Freigegeben - R"
    iv_via_selection_screen = abap_true
    iv_complete_requests    = abap_true
  IMPORTING
    ev_selected_request     = lv_tkorr
    es_selected_request     = lv_korr_head.

cl_demo_output=>write_data( lv_tkorr ).
cl_demo_output=>write_data( lv_korr_head ).
cl_demo_output=>display( ).

[ABAP] Transport von Kopien aus Transportauftrag anlegen und Aufgaben/Objekte übernehmen

* Siehe Typgruppe SCTSC (Konstanten CTS)

SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT (20) lbl1 FOR FIELD p_trkorr.
  PARAMETERS: p_trkorr LIKE e070-trkorr OBLIGATORY.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT (20) lbl2 FOR FIELD p_tar.
  PARAMETERS: p_tar TYPE trheader-tarsystem OBLIGATORY VALUE CHECK DEFAULT 'XYZ'.
SELECTION-SCREEN END OF LINE.

INITIALIZATION.
  lbl1 = 'Transport-Auftrag:'.
  lbl2 = 'Transportziel:'.

START-OF-SELECTION.

  DATA: lv_req TYPE trwbo_request.

* (Nach-)Lesen von Einzelbestandteilen eines Auftrags
  CALL FUNCTION 'TR_READ_REQUEST'
    EXPORTING
      iv_read_e070     = abap_true
      iv_read_e07t     = abap_true
      iv_trkorr        = p_trkorr
    CHANGING
      cs_request       = lv_req
    EXCEPTIONS
      error_occured    = 1
      no_authorization = 2
      OTHERS           = 3.

  IF sy-subrc = 0.

    WRITE: / 'Kopfdaten des Auftrages', p_trkorr, 'gelesen.'.

* Text übernehmen
    DATA(lv_as4text) = CONV as4text( |TvK:{ lv_req-h-as4text }| ).
    DATA: lv_tvk TYPE trwbo_request_header.

* Auftrag mit Aufgaben anlegen (ohne Dialog)
    CALL FUNCTION 'TR_INSERT_REQUEST_WITH_TASKS'
      EXPORTING
        iv_type            = sctsc_type_transport " TvK anlegen
        iv_text            = lv_as4text
        iv_owner           = sy-uname
        iv_target          = p_tar
        iv_with_badi_check = abap_true
      IMPORTING
        es_request_header  = lv_tvk
      EXCEPTIONS
        insert_failed      = 1
        enqueue_failed     = 2
        OTHERS             = 3.

    IF sy-subrc = 0.

      WRITE: / 'Ziel-Auftrag', lv_tvk-trkorr, 'angelegt.'.

* Quell-Auftrag kopieren
* Kopieren von Aufträgen/Aufgaben
      CALL FUNCTION 'TR_COPY_COMM'
        EXPORTING
          wi_dialog                = abap_false
          wi_trkorr_from           = p_trkorr
          wi_trkorr_to             = lv_tvk-trkorr
          wi_without_documentation = abap_true
        EXCEPTIONS
          db_access_error          = 1
          trkorr_from_not_exist    = 2
          trkorr_to_is_repair      = 3
          trkorr_to_locked         = 4
          trkorr_to_not_exist      = 5
          trkorr_to_released       = 6
          user_not_owner           = 7
          no_authorization         = 8
          wrong_client             = 9
          wrong_category           = 10
          object_not_patchable     = 11
          OTHERS                   = 12.

      IF sy-subrc = 0.

        WRITE: / 'Objekte des Quell-Auftrages', p_trkorr, 'nach', lv_tvk-trkorr, 'kopiert'.

        DATA(lv_ok) = abap_true.

* Quell-Aufgaben kopieren
        SELECT FROM e070
          FIELDS trkorr
          WHERE strkorr = @p_trkorr
          INTO TABLE @DATA(it_trkorr_aufg).

        WRITE: / lines( it_trkorr_aufg ), 'Aufgaben des Quell-Auftrages', p_trkorr, 'gelesen.'.

* alle Quell-Aufgaben des Quell-Auftrages
        LOOP AT it_trkorr_aufg ASSIGNING FIELD-SYMBOL(<a>).
* Kopieren von Aufträgen/Aufgaben
          CALL FUNCTION 'TR_COPY_COMM'
            EXPORTING
              wi_dialog                = abap_false
              wi_trkorr_from           = <a>-trkorr
              wi_trkorr_to             = lv_tvk-trkorr
              wi_without_documentation = abap_true
            EXCEPTIONS
              db_access_error          = 1
              trkorr_from_not_exist    = 2
              trkorr_to_is_repair      = 3
              trkorr_to_locked         = 4
              trkorr_to_not_exist      = 5
              trkorr_to_released       = 6
              user_not_owner           = 7
              no_authorization         = 8
              wrong_client             = 9
              wrong_category           = 10
              object_not_patchable     = 11
              OTHERS                   = 12.
          IF sy-subrc = 0.
            WRITE: / 'Aufgabe',<a>-trkorr,'des Quell-Auftrages', p_trkorr, 'nach', lv_tvk-trkorr, 'kopiert'.
          ELSE.
            lv_ok = abap_false.
            WRITE: / 'Fehler (', sy-subrc, ') beim Kopieren der Quell-Aufgabe:', <a>-trkorr.
            EXIT.
          ENDIF.
        ENDLOOP.

        IF lv_ok = abap_true.
* Objekte und Schlüssel eines Auftrags sortieren
          CALL FUNCTION 'TR_SORT_AND_COMPRESS_COMM'
            EXPORTING
              iv_trkorr                      = lv_tvk-trkorr
            EXCEPTIONS
              trkorr_not_found               = 1
              order_released                 = 2
              error_while_modifying_obj_list = 3
              tr_enqueue_failed              = 4
              no_authorization               = 5
              OTHERS                         = 6.

          IF sy-subrc = 0.
            WRITE: / 'Ziel-Transportauftrag', lv_tvk-trkorr, 'erfolgreich sortiert und verdichtet.'.
          ELSE.
            WRITE: / 'Fehler (', sy-subrc, ') beim Verdichten von Transportauftrag:', lv_tvk-trkorr.
          ENDIF.

        ELSE.
          WRITE: / 'Fehler beim Kopieren der Quell-Aufgaben in Transportauftrag:', lv_tvk-trkorr.
        ENDIF.

      ELSE.
        WRITE: / 'Fehler (', sy-subrc, ') beim Lesen des Quell-Auftrages:', p_trkorr.
      ENDIF.

    ELSE.
      WRITE: / 'Fehler (', sy-subrc, ') beim Anlegen des Ziel-Auftrages'.
    ENDIF.

  ELSE.
    WRITE: / 'Fehler (', sy-subrc, ') beim Lesen des Quell-Auftrages:', p_trkorr.
  ENDIF.

[ABAP] Transportauftrag freigeben

* Siehe Typgruppe SCTSC (Konstanten CTS)

SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT (20) lbl1 FOR FIELD p_trkorr.
  PARAMETERS: p_trkorr LIKE e070-trkorr OBLIGATORY.
SELECTION-SCREEN END OF LINE.

INITIALIZATION.
  lbl1 = 'Transport-Auftrag:'.

START-OF-SELECTION.
* Freigabe eines Auftrags/einer Aufgabe
  CALL FUNCTION 'TR_RELEASE_REQUEST'
    EXPORTING
      iv_trkorr                  = p_trkorr
      iv_dialog                  = abap_true
      iv_as_background_job       = abap_false
      iv_success_message         = abap_false
      iv_display_export_log      = abap_false
    EXCEPTIONS
      cts_initialization_failure = 1
      enqueue_failed             = 2
      no_authorization           = 3
      invalid_request            = 4
      request_already_released   = 5
      repeat_too_early           = 6
      error_in_export_methods    = 7
      object_check_error         = 8
      docu_missing               = 9
      db_access_error            = 10
      action_aborted_by_user     = 11
      export_failed              = 12
      OTHERS                     = 13.

  IF sy-subrc = 0.
    WRITE: / 'Auftrag', p_trkorr, 'freigegeben.'.
  ENDIF.

[ABAP] Transportauftrag prüfen

* Siehe Typgruppe SCTSC (Konstanten CTS)

SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT (20) lbl1 FOR FIELD p_trkorr.
  PARAMETERS: p_trkorr LIKE e070-trkorr OBLIGATORY.
SELECTION-SCREEN END OF LINE.

INITIALIZATION.
  lbl1 = 'Transport-Auftrag:'.

START-OF-SELECTION.

  DATA: lv_req TYPE trwbo_request.

* (Nach-)Lesen von Einzelbestandteilen eines Auftrags
  CALL FUNCTION 'TR_READ_REQUEST'
    EXPORTING
      iv_read_e070     = abap_true
      iv_read_e07t     = abap_true
      iv_trkorr        = p_trkorr
    CHANGING
      cs_request       = lv_req
    EXCEPTIONS
      error_occured    = 1
      no_authorization = 2
      OTHERS           = 3.

  IF sy-subrc = 0.

    DATA: lv_messages TYPE ctsgerrmsgs.

* Prüfe kompletten Auftrag
    CALL FUNCTION 'TR_CHECK_REQUEST'
      EXPORTING
        is_request           = lv_req
        iv_check_lockability = abap_true
        iv_collect_mode      = abap_true
      IMPORTING
        et_messages          = lv_messages
      EXCEPTIONS
        header_error         = 1
        attribute_error      = 2
        obj_or_key_error     = 3
        OTHERS               = 4.

    IF sy-subrc = 0.
      cl_demo_output=>write_data( lv_messages ).
      cl_demo_output=>display( ).
    ENDIF.
  ENDIF.

[ABAP] Transportaufträge: Kommandodatei (Cofile) laden

Variante 1 (TR_READ_GLOBAL_INFO_OF_REQUEST)

SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT (20) lbl1 FOR FIELD p_trkorr.
  PARAMETERS: p_trkorr LIKE e070-trkorr OBLIGATORY.
SELECTION-SCREEN END OF LINE.

INITIALIZATION.
  lbl1 = 'Transport-Auftrag:'.

START-OF-SELECTION.

  DATA: lv_cofile TYPE ctslg_cofile.
  DATA: lv_user TYPE e070-as4user.
  DATA: lv_project TYPE trkorr.

* Kommandodatei lesen und abhängig vom Aufruf aufbereiten
  CALL FUNCTION 'TR_READ_GLOBAL_INFO_OF_REQUEST'
    EXPORTING
      iv_trkorr   = p_trkorr
      iv_dir_type = 'T'          " Typ Directory: T(ransport), P(ut)
    IMPORTING
      es_cofile   = lv_cofile
      ev_user     = lv_user
      ev_project  = lv_project.

  cl_demo_output=>write_data( lv_cofile ).
  cl_demo_output=>write_data( lv_user ).
  cl_demo_output=>write_data( lv_project ).
* html-code holen
data(lv_html) = cl_demo_output=>get( ).
* Daten im Inline-Browser im SAP-Fenster anzeigen
  cl_abap_browser=>show_html( EXPORTING title       = 'Transportauftrag Cofile'
                                        html_string = lv_html
                                        container   = cl_gui_container=>default_screen ).
* cl_gui_container=>default_screen erzwingen
  WRITE: space.

Variante 2 (STRF_READ_COFILE)

SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT (20) lbl1 FOR FIELD p_trkorr.
  PARAMETERS: p_trkorr LIKE e070-trkorr OBLIGATORY.
SELECTION-SCREEN END OF LINE.

INITIALIZATION.
  lbl1 = 'Transport-Auftrag:'.

START-OF-SELECTION.

  DATA: lv_ev_cofi_header TYPE tstrfcofih.
  DATA: lv_ev_project TYPE trkorr_p.
  DATA: lv_et_predecessors TYPE tms_trkorrs.

  DATA: it_tt_cofi_lines TYPE STANDARD TABLE OF tstrfcofil WITH DEFAULT KEY.

* SL-intern: Lesen und Interpretieren Inhalt von cofiles-Dateien
  CALL FUNCTION 'STRF_READ_COFILE'
    EXPORTING
      iv_dirtype             = 'T'         " Typ Directory: T(ransport), P(ut)
      iv_trkorr              = p_trkorr
      iv_read_header         = 'X'
      iv_transport_directory = ' '
    IMPORTING
      ev_cofi_header         = lv_ev_cofi_header
      ev_project             = lv_ev_project
      et_predecessors        = lv_et_predecessors
    TABLES
      tt_cofi_lines          = it_tt_cofi_lines
    EXCEPTIONS
      wrong_call             = 1
      no_info_found          = 2
      OTHERS                 = 3.

  IF sy-subrc = 0.

    cl_demo_output=>write_data( lv_ev_cofi_header ).
    cl_demo_output=>write_data( lv_ev_project ).
    cl_demo_output=>write_data( lv_et_predecessors ).
    cl_demo_output=>write_data( it_tt_cofi_lines ).

* html-code holen
    DATA(lv_html) = cl_demo_output=>get( ).
* Daten im Inline-Browser im SAP-Fenster anzeigen
    cl_abap_browser=>show_html( EXPORTING title       = 'Transportauftrag Cofile'
                                          html_string = lv_html
                                          container   = cl_gui_container=>default_screen ).
* cl_gui_container=>default_screen erzwingen
    WRITE: space.
  ENDIF.

[ABAP] Transportauftrag als ZIP-Datei speichern

SELECTION-SCREEN BEGIN OF LINE.
  SELECTION-SCREEN COMMENT (20) lbl1 FOR FIELD p_trkorr.
  PARAMETERS: p_trkorr LIKE e070-trkorr OBLIGATORY.
SELECTION-SCREEN END OF LINE.

INITIALIZATION.

  lbl1 = 'Transport-Auftrag:'.

START-OF-SELECTION.
  TRY.
      DATA: lv_req TYPE trwbo_request.

* (Nach-)Lesen von Einzelbestandteilen eines Auftrags
      CALL FUNCTION 'TR_READ_REQUEST'
        EXPORTING
          iv_read_e070     = abap_true
          iv_read_e07t     = abap_true
          iv_trkorr        = p_trkorr
        CHANGING
          cs_request       = lv_req
        EXCEPTIONS
          error_occured    = 1
          no_authorization = 2
          OTHERS           = 3.

      IF sy-subrc = 0.
*D Änderbar
*L Änderbar, geschützt
*O Freigabe gestartet
*R Freigegeben
*N Freigegeben (Importschutz für reparierte Objekte aktiv)
        IF lv_req-h-trstatus = 'R'.

          DATA: lv_trans_cofile_dir TYPE stpa-file.
          DATA: lv_trans_data_dir TYPE stpa-file.

* intern: Pfade der Transportverzeichnisse
          CALL FUNCTION 'TRINT_FI_GET_DIRECTORY_NAMES'
            EXPORTING
              iv_dir_type          = 'T'
            IMPORTING
              ev_data_dir          = lv_trans_data_dir
              ev_cofiles_dir       = lv_trans_cofile_dir
            EXCEPTIONS
              get_dir_trans_failed = 1
              build_path_failed    = 2
              OTHERS               = 3.

          IF sy-subrc = 0.
* Name
            DATA(lv_syst) = |{ p_trkorr(3) }|.
            DATA(lv_num) = |{ p_trkorr+4 }|.
            DATA(lv_name) = |{ lv_num }.{ lv_syst }|.

* Cofile lesen
            DATA: lv_xstr_cofile TYPE xstring.
            DATA(lv_cofile) = |{ lv_trans_cofile_dir }/K{ lv_name }|.

            OPEN DATASET lv_cofile FOR INPUT IN BINARY MODE.
            READ DATASET lv_cofile INTO lv_xstr_cofile.
            CLOSE DATASET lv_cofile.

* Data lesen
            DATA: lv_xstr_data TYPE xstring.
            DATA(lv_data) = |{ lv_trans_data_dir }/R{ lv_name }|.

            OPEN DATASET lv_data FOR INPUT IN BINARY MODE.
            READ DATASET lv_data INTO lv_xstr_data.
            CLOSE DATASET lv_data.

* Zip
            DATA(o_zip) = NEW cl_abap_zip( ).

            o_zip->add( name    = |K{ lv_name }|
                        content = lv_xstr_cofile ).

            o_zip->add( name    = |R{ lv_name }|
                        content = lv_xstr_data ).

            DATA(lv_xstr_zip) = o_zip->save( ).

* SOLIX
            DATA(it_raw_data) = cl_bcs_convert=>xstring_to_solix( EXPORTING iv_xstring = lv_xstr_zip ).

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

            DATA(lv_default) = |{ lv_req-h-as4text }_{ p_trkorr }|.

* alle Vorkommen, die nicht [a-zA-Z0-9_] entsprechen, durch '_' ersetzen
            REPLACE ALL OCCURRENCES OF REGEX '[^\w]+' IN lv_default WITH '_'.

* Save-Dialog
            cl_gui_frontend_services=>file_save_dialog( EXPORTING default_file_name = lv_default
                                                                  default_extension = 'zip'
                                                                  file_filter       = |{ cl_gui_frontend_services=>filetype_all }|
                                                        CHANGING  filename          = lv_filename
                                                                  path              = lv_path
                                                                  fullpath          = lv_fullpath
                                                                  user_action       = lv_action ).

            IF lv_action EQ cl_gui_frontend_services=>action_ok.

* Datei lokal speichern
              cl_gui_frontend_services=>gui_download( EXPORTING filename     = lv_fullpath
                                                                filetype     = 'BIN'
                                                                bin_filesize = xstrlen( lv_xstr_zip )
                                                      CHANGING  data_tab     = it_raw_data ).
            ENDIF.

          ELSE.
            WRITE: / |Systemverzeichnisse nicht gefunden.|.
          ENDIF.
        ELSE.
          WRITE: / |Auftrag { p_trkorr } nicht frei gegeben.|.
        ENDIF.

      ELSE.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO DATA(lv_msg).
        WRITE: / lv_msg.
      ENDIF.
    CATCH cx_root INTO DATA(e_txt).
      WRITE: / e_txt->get_text( ).
  ENDTRY.