[ABAP] ABAP-Listausgabe in interne ASCII-Tabelle ausgeben

DATA(i) = 0.

WHILE i < 10.

  WRITE: / i.
  i = i + 1.

ENDWHILE.

DATA: it_abaplist TYPE STANDARD TABLE OF abaplist WITH DEFAULT KEY.

* Sichern einer Liste
CALL FUNCTION 'SAVE_LIST'
  TABLES
    listobject         = it_abaplist
  EXCEPTIONS
    list_index_invalid = 1
    OTHERS             = 2.

IF sy-subrc = 0.

  DATA: it_list_ascii TYPE list_string_table.

* Konvertieren eines (gesicherten) Listobjekts nach ASCI
  CALL FUNCTION 'LIST_TO_ASCI'
    IMPORTING
      list_string_ascii  = it_list_ascii
    TABLES
      listobject         = it_abaplist
    EXCEPTIONS
      empty_list         = 1
      list_index_invalid = 2
      OTHERS             = 3.

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

[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] 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] Leistungstammsatz anlegen

DATA: lv_service  TYPE bapisrv_asmd.
DATA: lv_servicex TYPE bapisrv_asmdx.
DATA: it_bapiret2 TYPE STANDARD TABLE OF bapiret2 WITH DEFAULT KEY.

lv_service-service           = '1234567890'. " Leistungsnummer
lv_service-matl_group        = '10000000'.   " Warengruppe
lv_service-base_uom          = 'ST'.         " Basismengeneinheit
lv_service-serv_cat          = 'SERV'.       " Leistungstyp
lv_service-val_class         = '1000'.       " Bewertungsklasse
lv_service-master_langu      = sy-langu.     " Sprache
lv_service-master_langu_iso  = cl_i18n_languages=>sap1_to_sap2( im_lang_sap1 = lv_service-master_langu ).

lv_servicex-service          = lv_service-service.
lv_servicex-matl_group       = abap_true.
lv_servicex-base_uom         = abap_true.
lv_servicex-serv_cat         = abap_true.
lv_servicex-val_class        = abap_true.
lv_servicex-master_langu     = abap_true.
lv_servicex-master_langu_iso = abap_true.

DATA it_shorttext TYPE STANDARD TABLE OF bapisrv_asmdt WITH DEFAULT KEY.

it_shorttext = VALUE #( ( language     = lv_service-master_langu
                          language_iso = lv_service-master_langu_iso
                          short_text   = 'Kurztext'
                          change_id    = 'I' ) ).

DATA(it_longtext) = VALUE srv_sm_text_tty( ( language     = sy-langu
                                             language_iso = cl_i18n_languages=>sap1_to_sap2( im_lang_sap1 = sy-langu )
                                             format       = '/'
                                             line         = 'Langtext'
                                             change_id    = 'I' ) ).

CALL FUNCTION 'BAPI_SERVICE_CREATE'
  EXPORTING
    im_service_data     = lv_service
    im_service_datax    = lv_servicex
    testrun             = ''
  TABLES
    return              = it_bapiret2
    service_description = it_shorttext
    service_long_texts  = it_longtext.

TRY.
    IF lines( it_bapiret2 ) > 0.
      IF it_bapiret2[ 1 ]-type CA 'EAX'.
        CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
      ELSE.
        CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
      ENDIF.
    ENDIF.
  CATCH cx_sy_itab_line_not_found.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDTRY.

cl_demo_output=>write_data( lv_service ).
cl_demo_output=>write_data( lv_servicex ).
cl_demo_output=>write_data( it_shorttext ).
cl_demo_output=>write_data( it_longtext ).
cl_demo_output=>write_data( it_bapiret2 ).

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

* cl_gui_container=>default_screen erzwingen
WRITE: space.

[ABAP] Leistungstammsatz lesen

PARAMETERS: p_srv_nr TYPE asmd-asnum. "bapisrvpar-service.

START-OF-SELECTION.
  DATA: lv_service_info TYPE bapisrv.
  DATA: it_servicetextlines TYPE STANDARD TABLE OF bapisrvtxt WITH DEFAULT KEY.
  DATA: it_bapiret2 TYPE STANDARD TABLE OF bapiret2 WITH DEFAULT KEY.

  CALL FUNCTION 'BAPI_SERVICE_GET_DETAIL'
    EXPORTING
      servicenumber      = p_srv_nr
    IMPORTING
      servicegeneraldata = lv_service_info
    TABLES
      servicetextlines   = it_servicetextlines
      return             = it_bapiret2.

  cl_demo_output=>write_data( p_srv_nr ).
  cl_demo_output=>write_data( lv_service_info ).
  cl_demo_output=>write_data( it_servicetextlines ).
  cl_demo_output=>write_data( it_bapiret2 ).

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

* cl_gui_container=>default_screen erzwingen
  WRITE: space.

[ABAP] Adressenaufbereitung mit CUSTOMER_ADDRESS_TO_ITF

DATA: lv_address TYPE bapiaddr3.
DATA: it_bapi_return TYPE STANDARD TABLE OF bapiret2 WITH DEFAULT KEY.
 
CALL FUNCTION 'BAPI_USER_GET_DETAIL'
  EXPORTING
    username = sy-uname
  IMPORTING
    address  = lv_address
  TABLES
    return   = it_bapi_return.

DATA: lv_customer TYPE scustom.
lv_customer-name = lv_address-fullname.
lv_customer-street = lv_address-street.
lv_customer-postbox = lv_address-po_box.
lv_customer-postcode = lv_address-postl_cod1.
lv_customer-city   = lv_address-city.
lv_customer-country = lv_address-country.
lv_customer-region = lv_address-region.
lv_customer-telephone = lv_address-tel1_numbr.
lv_customer-email = lv_address-e_mail.

DATA: lv_sender_country TYPE szad_field-send_cntry.
lv_sender_country = 'US'.

DATA: it_address_lines TYPE tline_tab.

CALL FUNCTION 'CUSTOMER_ADDRESS_TO_ITF'
  EXPORTING
    is_customer        = lv_customer
    iv_sending_country = lv_sender_country
*   IV_NUMBER_OF_LINES = 5
  IMPORTING
    et_address         = it_address_lines.

cl_demo_output=>write_data( lv_address ).
cl_demo_output=>write_data( lv_customer ).
cl_demo_output=>write_data( lv_sender_country ).
cl_demo_output=>write_data( it_address_lines ).
cl_demo_output=>display( ).