[ABAP] Dokumente per URL im Document Viewer anzeigen

PARAMETERS: p_url TYPE swk_url DEFAULT 'https://google.de'.

START-OF-SELECTION.

* https://help.sap.com/docs/SAP_NETWEAVER_731_BW_ABAP/70396d7dec4c4f19b9ca3b2e47559d12/493278eee8c55aabe10000000a42189d.html
  TRY.
      DATA: o_viewer TYPE REF TO i_oi_document_viewer.

* Container-Control-Factory-Klasse
      c_oi_container_control_creator=>get_document_viewer( IMPORTING viewer = o_viewer ).
* Standardcontainer nutzen
      o_viewer->init_viewer( parent = cl_gui_container=>default_screen ).
* Dokument inplace anhand einer URL anzeigen
      o_viewer->view_document_from_url( document_url = p_url
                                        show_inplace = abap_true ).

      WRITE: space.

    CATCH cx_root.
  ENDTRY.

[ABAP] Statusinformationen des ICMAN lesen

DATA: lv_info_data TYPE icm_info.
DATA: it_servlist TYPE STANDARD TABLE OF icm_sinfo2 WITH DEFAULT KEY.
DATA: it_thrlist TYPE STANDARD TABLE OF icm_thrlst WITH DEFAULT KEY.
DATA: it_servlist3 TYPE STANDARD TABLE OF icm_sinfo3 WITH DEFAULT KEY.

* Statistikdaten des ICM lesen
CALL FUNCTION 'ICM_GET_INFO2'
  IMPORTING
    info_data          = lv_info_data
  TABLES
    servlist           = it_servlist
    thrlist            = it_thrlist
    servlist3          = it_servlist3
  EXCEPTIONS
    icm_error          = 1
    icm_timeout        = 2
    icm_not_authorized = 3
    OTHERS             = 4.

IF sy-subrc = 0.
* Hier Objekte für die Ausgabe hinzufügen
  cl_demo_output=>write_data( lv_info_data ).
  cl_demo_output=>write_data( it_servlist ).
  cl_demo_output=>write_data( it_thrlist ).
  cl_demo_output=>write_data( it_servlist3 ).

* 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       = 'Daten'
                                        html_string = lv_html
                                        container   = cl_gui_container=>default_screen ).

* cl_gui_container=>default_screen erzwingen
  WRITE: space.
ENDIF.

[ABAP] SAP-ShortCode-Datei (*.sap) erzeugen

Variante 1 (SWN_CREATE_SHORTCUT -> *.sap-Datei speichern)

* SAP ShortCode-Dateien sind mit der installierten SAPGUI verknüpft und werden von dieser beim Doppelklick auf den Dateinamen geöffnet und ausgeführt
* SAP ShortCode-Dateien können auch im SAPGUI über den Button "Erstellt eine Verknüpfung" erzeugt werden
* SAP Hinweis: 103019 - SAPshortcut: Programmparameter
* http://troublefreeabap.blogspot.com/2013/06/creating-sapgui-shortcuts.html
PARAMETERS: p_matnr TYPE mara-matnr.

START-OF-SELECTION.

* Kommando (i_system_command):
* - fasst i_transaction und i_parameter zusammen
* - Transaktion MM03 in neuem Fenster anzeigen
*   - '/o' --> neuen Modus öffnen
*   - '*' --> überspringt Selektionsbild
* - Übergabe: MATNR an Dynpro-Feld für die MATNR im Selektionsbild (RMMG1-MATNR)
* - entfernen führenden Nullen (ALPHA = OUT)
  DATA(lv_cmd) = |/o*MM03 RMMG1-MATNR={ p_matnr ALPHA = OUT }|.
* Texttabelle mit generierten Daten für die Shortcut-Datei (*.sap)
  DATA(it_sap_shortcut_data) = VALUE soli_tab( ).

* WF Notif: SAP Shortcut als Anlage erzeugen
  CALL FUNCTION 'SWN_CREATE_SHORTCUT'
    EXPORTING
      i_system_command        = CONV char40( lv_cmd )
*      i_transaction           = '*MM03'
*      i_parameter             = CONV text255( |RMMG1-MATNR={ p_matnr ALPHA = OUT }| )
      i_user                  = ''
      i_windowsize            = 'Maximized' " oder 'Normal window'
      i_title                 = CONV char80( |MM03 - Material anzeigen| )
    IMPORTING
      shortcut_table          = it_sap_shortcut_data
    EXCEPTIONS
      inconsistent_parameters = 1
      OTHERS                  = 2.

  IF sy-subrc = 0.
* *.sap ShortCut-Datei speichern
    TRY.
        DATA: lv_action TYPE i.
        DATA: lv_filename TYPE string.
        DATA: lv_fullpath TYPE string.
        DATA: lv_path TYPE string.

* Save-Dialog
        cl_gui_frontend_services=>file_save_dialog( EXPORTING default_file_name = 'Start_MM03.sap'
                                                              default_extension = 'sap'
                                                              file_filter       = |ShortCut-Datei (*.sap)\|*.sap\|{ 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     = 'DAT'
                                                  CHANGING  data_tab     = it_sap_shortcut_data ).

        ENDIF.
      CATCH cx_root INTO DATA(e_text).
        MESSAGE e_text->get_text( ) TYPE 'I'.
    ENDTRY.
  ENDIF.

Variante 2 (SICF-Service /sap/public/bc/workflow/shortcut)

PARAMETERS: p_matnr TYPE mara-matnr.

START-OF-SELECTION.

  DATA: it_servlist TYPE STANDARD TABLE OF icm_sinfo2 WITH DEFAULT KEY.

* Statistikdaten des ICM lesen
  CALL FUNCTION 'ICM_GET_INFO2'
    TABLES
      servlist           = it_servlist
    EXCEPTIONS
      icm_error          = 1
      icm_timeout        = 2
      icm_not_authorized = 3
      OTHERS             = 4.

  IF sy-subrc = 0.
* protocol 1: HTTP
* protocol 2: HTTPS
    IF line_exists( it_servlist[ protocol = 2 ] ).
* URL für workflow-shortcut zusammenbauen
* SICF-Service muss aktiv sein: /sap/public/bc/workflow/shortcut
* Daten werden in der Klasse CL_SWN_HTTP_SHORTCUT prozessiert
      DATA(lv_server) = it_servlist[ protocol = 2 ].
      DATA(lv_html) = |https://{ lv_server-hostname }:{ lv_server-service }|.
      lv_html = lv_html && |/sap/public/bc/workflow/shortcut?|.
      lv_html = lv_html && |sysid={ sy-sysid }&client={ sy-mandt }|.
      lv_html = lv_html && |&logonid=&uname={ sy-uname }|.
      lv_html = lv_html && |&langu=DE|.
      lv_html = lv_html && |&transaction=*MM03|.
      lv_html = lv_html && |&param=RMMG1-MATNR%3d{ p_matnr ALPHA = OUT }|.

      WRITE: / lv_html.
    ENDIF.
  ENDIF.

[ABAP] ITS: Aufruf einer Transaktion über HTTPS in der WebGui

PARAMETERS: p_matnr TYPE mara-matnr.

START-OF-SELECTION.

  DATA: it_servlist TYPE STANDARD TABLE OF icm_sinfo2 WITH DEFAULT KEY.

* Statistikdaten des ICM lesen
  CALL FUNCTION 'ICM_GET_INFO2'
    TABLES
      servlist           = it_servlist
    EXCEPTIONS
      icm_error          = 1
      icm_timeout        = 2
      icm_not_authorized = 3
      OTHERS             = 4.

  IF sy-subrc = 0.
* protocol 1: HTTP
* protocol 2: HTTPS
    IF line_exists( it_servlist[ protocol = 2 ] ).
* URL für Transaktions-Anzeige in der ITS-WebGui zusammenbauen
* SICF-Service muss aktiv sein: /sap/bc/gui/sap/its/webgui
* Daten werden in der Klasse CL_HTTP_EXT_ITS prozessiert
      DATA(lv_server) = it_servlist[ protocol = 2 ].
      DATA(lv_html) = |https://{ lv_server-hostname }:{ lv_server-service }|.
      lv_html = lv_html && |/sap/bc/gui/sap/its/webgui?|.
      lv_html = lv_html && |~transaction=*MM03%20RMMG1-MATNR={ p_matnr ALPHA = OUT WIDTH = 10 }|. " MM03 + MATNR --> Selektionbild überspringen
      lv_html = lv_html && |&sap-client={ sy-mandt }|.
      lv_html = lv_html && |&sap-language=DE|.

* Browserfenster mit default_screen als Container
      DATA(o_hv) = NEW cl_gui_html_viewer( parent = cl_gui_container=>default_screen ).
* SSO
*      o_hv->enable_sapsso( enabled = abap_true ).
* ITS: WebGui inline (im SAPGUI) anzeigen
      o_hv->show_url( url      = CONV swk_url( lv_html )
                      in_place = abap_true ).

* Führt alle gesammelten OLE-Calls aus
      cl_gui_cfw=>flush( ).

* Toolbar ausblenden
      cl_abap_list_layout=>suppress_toolbar( ).

* erzwingt Anzeige über cl_gui_container=>default_screen
      WRITE: / space.
    ENDIF.
  ENDIF.

Links

[ABAP] Daten einer Internetseite als interne Tabelle bereitstellen

PARAMETERS: p_url TYPE w3url DEFAULT 'https://google.de'.

DATA: lv_size          TYPE  i.
DATA: lv_errorstate    TYPE  i.
DATA: lv_ret_type      TYPE  c.
DATA: lv_ret_subtype   TYPE  c.
DATA: lv_date          TYPE  sy-datum.
DATA: lv_time          TYPE  sy-uzeit.
DATA: it_response TYPE STANDARD TABLE OF docs WITH DEFAULT KEY.

* Stellt die Daten eines URLs in eine interne Tabelle
CALL FUNCTION 'DP_GET_STREAM_FROM_URL'
  EXPORTING
    url               = p_url
  IMPORTING
    size              = lv_size
    errorstate        = lv_errorstate
    ret_type          = lv_ret_type
    ret_subtype       = lv_ret_subtype
    date              = lv_date
    time              = lv_time
  TABLES
    data              = it_response
  EXCEPTIONS
    dp_fail           = 1
    dp_failed_init    = 2
    blocked_by_policy = 3
    unknown_error     = 4
    OTHERS            = 5.

IF sy-subrc = 0.
* Hier Objekte für die Ausgabe hinzufügen
  cl_demo_output=>write_data( lv_size ).
  cl_demo_output=>write_data( lv_errorstate ).
  cl_demo_output=>write_data( lv_ret_type ).
  cl_demo_output=>write_data( lv_ret_subtype ).
  cl_demo_output=>write_data( lv_date ).
  cl_demo_output=>write_data( lv_time ).
  cl_demo_output=>write_data( it_response ).

*   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        = 'Daten'
                                html_string  = lv_html
                                container    = cl_gui_container=>default_screen ).

*   cl_gui_container=>default_screen erzwingen
  WRITE: space.
ENDIF.

[ABAP] HTTP-Daten lesen

DATA: lv_no_logon TYPE abap_bool VALUE abap_true.
DATA: lv_url TYPE swk_url VALUE 'https://google.de'.
DATA: lv_user TYPE char50.
DATA: lv_passwd TYPE char50.
DATA: lv_timeout TYPE i VALUE 60.

DATA: lv_length TYPE i.
DATA: lv_status_code TYPE char3.
DATA: lv_status_text TYPE char128.

DATA: it_head TYPE STANDARD TABLE OF docs WITH DEFAULT KEY.
DATA: it_body TYPE STANDARD TABLE OF docs WITH DEFAULT KEY.

* HTTP Get
CALL FUNCTION 'HTTP2_GET'
  EXPORTING
    absolute_uri                = lv_url
    user                        = lv_user
    password                    = lv_passwd
    timeout                     = lv_timeout
    no_logon                    = lv_no_logon
  IMPORTING
    status_code                 = lv_status_code
    status_text                 = lv_status_text
    response_entity_body_length = lv_length
  TABLES
    response_entity_body        = it_body
    response_headers            = it_head
  EXCEPTIONS
    connect_failed              = 1
    timeout                     = 2
    internal_error              = 3
    tcpip_error                 = 4
    data_error                  = 5
    system_failure              = 6
    communication_failure       = 7
    OTHERS                      = 8.

IF sy-subrc = 0.
  cl_demo_output=>write_data( lv_status_code ).
  cl_demo_output=>write_data( lv_status_text ).
  cl_demo_output=>write_data( lv_length ).
  cl_demo_output=>write_data( it_head ).
  cl_demo_output=>write_data( it_body ).

* 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       = 'HTTP2_GET'
                                        html_string = lv_html
                                        container   = cl_gui_container=>default_screen ).

* cl_gui_container=>default_screen erzwingen
  WRITE: space.
ENDIF.

[ABAP] Versand von Emails auf Basis von CDS-Views

https://weberpatrick.de/e-mail-templates/
https://weberpatrick.de/e-mail-templates-einfaches-beispiel/

https://blogs.sap.com/2019/10/12/e-mail-templates-in-s4-hana/
https://blogs.sap.com/2020/05/07/e-mail-templates-in-s-4-hana-translations/
https://blogs.sap.com/2022/08/17/e-mail-templates-in-s-4-hana-display-table-in-the-email-template/

[ABAP] ABAP-Listausgabe in HTML wandeln

**********************************************************************
* Testausgabe
**********************************************************************
* Farbe definieren
FORMAT COLOR COL_HEADING.
* Überschriftentext
WRITE: / |Testausgabe|.
* Leerzeichen am Zeilenende, damit der Farbbalken durchgezogen wird
WRITE AT sy-linsz space.
* Farbdefinition abschalten
FORMAT COLOR OFF.

WRITE: / 'Grün' COLOR COL_POSITIVE.
WRITE: / 'Rot' COLOR COL_NEGATIVE.

ULINE.

**********************************************************************
* Aufbereitung der Listausgabe für HTML
**********************************************************************
DATA: it_list TYPE STANDARD TABLE OF abaplist WITH DEFAULT KEY.

* Listausgabe in Form einer binären internen Tabelle speichern
* Sichern einer Liste
CALL FUNCTION 'SAVE_LIST'
  TABLES
    listobject         = it_list
  EXCEPTIONS
    list_index_invalid = 1
    OTHERS             = 2.

DATA: it_html TYPE STANDARD TABLE OF w3html.

* Listausgabe -> HTML
* Converts a given listobject to html
CALL FUNCTION 'WWW_HTML_FROM_LISTOBJECT'
  TABLES
    html          = it_html
    listobject    = it_list.

* HTML-Viewer
DATA(o_hv) = NEW cl_gui_html_viewer( parent = cl_gui_container=>default_screen ).
* URL holen
DATA: lv_url TYPE swk_url.

o_hv->load_data( IMPORTING
                   assigned_url = lv_url
                 CHANGING
                   data_table   = it_html ).

* HTML-Daten anzeigen
o_hv->show_url( url      = lv_url
                in_place = abap_false ).

* cl_gui_container=>default_screen erzwingen
WRITE: space.

[ABAP] ITS: HTML aus einem Dynpro generieren

* Paket: SITS_ABAP

* SE11 - Report
DATA: lv_prog TYPE d020s-prog VALUE 'SAPLSD_ENTRY'.
* Dynpro 1000
DATA: lv_dynnr TYPE d020s-dnum VALUE '1000'.
* '' / C - Classic, B - HTML-Business, W - WebGUI
DATA: lv_style TYPE w3style VALUE 'B'.

DATA: lv_html_xstr TYPE xstring.
DATA: it_html TYPE STANDARD TABLE OF w3html WITH DEFAULT KEY.

* Template von Dynpro generieren
CALL FUNCTION 'ITS_GENERATE_HTML_FROM_DYNPRO'
  EXPORTING
    progname                       = lv_prog
    dynnr                          = lv_dynnr
    style_2006                     = lv_style
  IMPORTING
    source_stream                  = lv_html_xstr
  TABLES
    meta_html                      = it_html
  EXCEPTIONS
    style_not_valid                = 1
    dynnr_or_programname_not_valid = 2
    css_not_valid                  = 3
    xsl_not_valid                  = 4
    placeholder_not_valid          = 5
    no_card_identifiers_used       = 6
    error_occured                  = 7
    OTHERS                         = 8.

IF sy-subrc = 0.
  cl_demo_output=>write_data( it_html ).
  DATA(lv_html) = cl_demo_output=>get( ).

* Daten im Inline-Browser im SAP-Fenster anzeigen
  cl_abap_browser=>show_html( EXPORTING
                                title        = 'HTML'
                                html_string  = lv_html
                                container    = cl_gui_container=>default_screen ).

* cl_gui_container=>default_screen erzwingen
  WRITE: space.
ENDIF.