[ABAP] Verarbeitungsprotokoll zu Nachrichten lesen (NAST, CMFK, CMFP)

* https://www.berater-wiki.de/Access_Tabellenbeziehung_Fehlerprotokoll

DATA: lv_kappl TYPE nast-kappl.
DATA: lv_objky TYPE nast-objky.
DATA: lv_kschl TYPE nast-kschl.
DATA: lv_erdat TYPE nast-erdat.
DATA: lv_eruhr TYPE nast-eruhr.
DATA: lv_usnam TYPE nast-usnam.

SELECT-OPTIONS: so_kappl FOR lv_kappl.
SELECT-OPTIONS: so_objky FOR lv_objky.
SELECT-OPTIONS: so_kschl FOR lv_kschl.
SELECT-OPTIONS: so_erdat FOR lv_erdat.
SELECT-OPTIONS: so_eruhr FOR lv_eruhr.
SELECT-OPTIONS: so_usnam FOR lv_usnam.

INITIALIZATION.

* Applikation für Nachrichtenkonditionen ('EF' = Bestellungen)
  so_kappl[] = VALUE #( ( sign = 'I' option = 'EQ' low = 'EF' high = '' ) ).
* Nachrichtenart
  so_kschl[] = VALUE #( ( sign = 'I' option = 'EQ' low = 'NEU' high = '' ) ).

START-OF-SELECTION.

* NAST (Nachrichtenstatus)
* CMFK (Speicherstruktur für den Kopf des Fehlerprotokolls)
* CMFP (Speicherstruktur für die gesammelten Fehler)
  SELECT FROM nast AS na
         LEFT OUTER JOIN cmfk AS ck ON na~cmfpnr = ck~nr
         LEFT OUTER JOIN cmfp AS cp ON na~cmfpnr = cp~nr
         FIELDS na~kappl,
                na~objky,
                na~kschl,
                na~parnr,
                na~erdat,
                na~eruhr,
                na~nacha,
                na~vsztp,
                na~usnam,
                na~tcode,
                na~ldest,
                na~tdreceiver,
                na~tdcovtitle,
                na~tdarmod,
                na~objtype,
                na~cmfpnr,
                ck~aplid,
                ck~nr,
                ck~datum,
                ck~uzeit,
                ck~uname,
                ck~objid,
                cp~msgcnt,
                cp~arbgb,
                cp~msgty,
                cp~msgnr,
                cp~msgv1,
                cp~msgv2,
                cp~msgv3,
                cp~msgv4,
                cp~logsys
         WHERE na~kappl IN @so_kappl
           AND na~objky IN @so_objky
           AND na~kschl IN @so_kschl
           AND na~erdat IN @so_erdat
           AND na~eruhr IN @so_eruhr
           AND na~usnam IN @so_usnam
         INTO TABLE @DATA(it_nast).

  IF sy-subrc = 0.
    cl_demo_output=>write_data( it_nast ).
* 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        = 'Verarbeitungsprotokoll Nachrichten'
                                  html_string  = lv_html
                                  container    = cl_gui_container=>default_screen ).

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

[ABAP] Datenbeschaffung für Lieferscheindruck

PARAMETERS: p_kappl TYPE t681a-kappl DEFAULT 'V2'.
PARAMETERS: p_kschl TYPE t685-kschl.

START-OF-SELECTION.

  SELECT SINGLE *
    INTO @DATA(lv_nast)
    FROM nast
    WHERE kappl = @p_kappl
      AND kschl = @p_kschl
      AND spras = @sy-langu.

  IF sy-subrc = 0.

    DATA(lv_vbco3) = VALUE vbco3( spras = lv_nast-spras  " Message language
                                  vbeln = lv_nast-objky  " Vertriebsbelegnummer
                                  kunde = lv_nast-parnr  " Partnernummer (KUNNR, LIFNR, PERNR, PARNR) mit Konv.Routine
                                  parvw = lv_nast-parvw  " Partnerrolle
                                ).

    DATA: lv_vbdkl TYPE vbdkl.
    DATA: it_vbdpl TYPE STANDARD TABLE OF vbdpl WITH DEFAULT KEY.

* Datenbeschaffung für Lieferscheindruck
    CALL FUNCTION 'RV_DELIVERY_PRINT_VIEW'
      EXPORTING
        comwa = lv_vbco3
      IMPORTING
        kopf  = lv_vbdkl
      TABLES
        pos   = it_vbdpl.

    cl_demo_output=>write_data( lv_vbdkl ).
    cl_demo_output=>write_data( it_vbdpl ).

* 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.