IDOC INBOUND WRITE TO DB

Aus SAP Wiki ツ
Version vom 18. Juli 2021, 15:03 Uhr von M1ch3lde (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „== Deklaration == DATA: ls_idoc_data TYPE edidd, lt_idoc_data TYPE TABLE OF edidd, lt_idoc_prev TYPE TABLE OF e…“)
(Unterschied) ← Nächstältere Version | Aktuelle Version (Unterschied) | Nächstjüngere Version → (Unterschied)

Deklaration

DATA: ls_idoc_data           TYPE edidd,
       lt_idoc_data           TYPE TABLE OF edidd,
       lt_idoc_prev           TYPE TABLE OF edidd,
       ls_idoc_control_master TYPE edidc,
       lv_segnum_count        TYPE i.
 DATA: lt_errors          TYPE bal_t_msg,
       lt_success         TYPE bal_t_msg,
       ls_message         TYPE bal_s_msg,

Codeschnipsel

ls_idoc_control_master-sndprt = 'LS'.
ls_idoc_control_master-direct = '2'.
CONCATENATE sy-sysid 'CLNT' sy-mandt INTO ls_idoc_control_master-sndprn.
CONCATENATE 'SAP_' sy-sysid '_00' INTO ls_idoc_control_master-sndpor.
ls_idoc_control_master-rcvprn = ls_idoc_control_master-sndprn.
ls_idoc_control_master-rcvprt = ls_idoc_control_master-sndprt.
CONCATENATE 'SAP' sy-sysid INTO ls_idoc_control_master-rcvpor.
ls_idoc_control_master-mestyp = ls_zbc_if_cust-message_type.
ls_idoc_control_master-idoctp = ls_zbc_if_cust-basis_type.

MOVE-CORRESPONDING <ls_idoc_format_tmp> TO <fs_segnam>.
ls_idoc_data-sdata = <fs_segnam>.
ls_idoc_data-segnam = lv_segnam.
lv_segnum_count = lv_segnum_count + 1.
ls_idoc_data-hlevel = '2'.
ls_idoc_data-segnum = lv_segnum_count.
CLEAR lv_segnum_count.
APPEND ls_idoc_data TO lt_idoc_data.

CLEAR ls_idoc_data.

CALL FUNCTION 'IDOC_INBOUND_WRITE_TO_DB'
     TABLES
       t_data_records    = lt_idoc_data
     CHANGING
       pc_control_record = ls_idoc_control_master
     EXCEPTIONS
       idoc_not_saved    = 1
       OTHERS            = 2.
   IF sy-subrc <> 0.
     ls_message-msgty = 'E'. ls_message-msgid = 'ZBC_IF_IDOC'. ls_message-msgno = '001'.
     ls_message-msgv1 = <fs_row_in_file>. ls_message-msgv2 = <fs_filename>.
     APPEND ls_message TO lt_errors.
   ELSE.
     ls_message-msgty = 'S'. ls_message-msgid = 'ZBC_IF_IDOC'. ls_message-msgno = '009'.
     ls_message-msgv1 = <fs_row_in_file>. ls_message-msgv2 = <fs_filename>.
     APPEND ls_message TO lt_success.
   ENDIF.