on 12-09-2018 5:03 AM
I am trying to send IDOC via reports. Please find the code for the same. However, occationaly the IDOC is sent but majority of time the status code is 30. Though I can send the IDOC from the transaction BD87 but how can I do that automatically.
*&---------------------------------------------------------------------*
*& Report Z_SENDING_IDOC2
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT Z_SENDING_IDOC2.
TABLES: zemployees.
DATA: header_segment_name LIKE edidd-segnam VALUE 'Z1KNA2',
item_segment_name LIKE edidd-segnam VALUE 'Z1KNBK2',
idoc_name LIKE edidc-idoctp VALUE 'ZDEBMAS05'.
DATA: header_segment_data LIKE z1kna2,
item_segment_data LIKE z1knbk2.
DATA: control_record LIKE edidc.
DATA: messagetyp LIKE edmsg-msgtyp VALUE 'ZCUST_MSG1'.
DATA: i_communication LIKE edidc occurs 0 with header line,
i_data LIKE edidd occurs 0 with header line.
DATA: BEGIN of i_ekko OCCURS 0,
FORENAME LIKE zemployees-FORENAME,
SURNAME LIKE zemployees-SURNAME,
TITLE LIKE zemployees-TITLE,
END OF i_ekko.
DATA: BEGIN of i_ekpo OCCURS 0,
DOB LIKE zemployees-DOB,
END OF i_ekpo.
***Start selection from table
start-of-selection.
*SELECT * FROM zemployees.
* WRITE zemployees.
*ENDSELECT.
SELECT FORENAME SURNAME TITLE FROM zemployees
INTO table i_ekko.
***IDOC control data
control_record-mestyp = messagetyp.
control_record-rcvprt = 'LS'.
control_record-idoctp = idoc_name.
control_record-rcvprn = 'ZAWSAPI'.
LOOP AT i_ekko.
header_segment_data-FORENAME = i_ekko-FORENAME.
header_segment_data-SURNAME = i_ekko-SURNAME.
header_segment_data-TITLE = i_ekko-TITLE.
i_data-segnam = header_segment_name.
i_data-sdata = header_segment_data.
APPEND i_data.
SELECT DOB FROM zemployees
INTO TABLE i_ekpo.
LOOP AT i_ekpo.
item_segment_data-DOB = i_ekpo-DOB.
i_data-segnam = item_segment_name.
i_data-sdata = item_segment_data.
append i_data.
ENDLOOP.
clear i_ekpo.
refresh i_ekpo.
ENDLOOP.
*IF sy-subrc is initial.
* commit work.
* write 'inside commit work'.
* else.
* message id sy-msgid type sy-msgty number sy-msgno
* with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
*ENDIF.
call function 'MASTER_IDOC_DISTRIBUTE'
exporting
master_idoc_control = control_record
OBJ_TYPE = ''
CHNUM = '1000'
tables
communication_idoc_control = i_communication
master_idoc_data = i_data
exceptions
error_in_idoc_control = 1
error_writing_idoc_status = 2
error_in_idoc_data = 3
sending_logical_system_unknown = 4
others = 5
.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
else.
loop at i_communication.
write: 'IDOC GENERATED', i_communication-docnum.
endloop.
commit work.
endif
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.