Exchange Infrastructure (XI)
XI Scenarios
Collect Multiple IDocs to File using BPM
By Suraj Kumar Pabbathi, PI Competency Lead, YASH Technologies
- Create
and configure the IDocs in Source system
For
eg:-
IDoc
Type: ZEMHDR02
Message Type: ZEMHDR
|
Segment
|
Fields
|
|
Z1EMHDR
|
SSN
|
|
|
FNAME
|
|
|
LNAME
|
|
|
DOB
|
IDoc
Type: ZWKDET02
Message Type: ZWKDET
|
Segment
|
Fields
|
|
Z1WKDET
|
SSN
|
|
|
WEEKNO
|
|
|
TOTHOURS
|
|
|
HRLYRATE
|
IDoc
Type: ZCLDET02
Message Type: ZCLDET
|
Segment
|
Fields
|
|
Z1CLDET
|
SSN
|
|
|
CLSITE
|
|
|
WORKDESC
|
Sender
system: YRACLNT100
Receiver
system: yhsapdev05/xi_test(File directory)
- Create
Customer Distribution Model
- Create
custom program to generate three custom IDocs
*&---------------------------------------------------------------------*
*& Report ZRBDSEEMP *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZRBDSEEMP .
*&---------------------------------------------------------------------*
* Parameters
*&---------------------------------------------------------------------*
selection-screen : begin of block b1 with frame title text-001.
*object key (social securtiy number for the employee)
parameters: p_ssn like zempdetail-ssn.
*destination system
parameters: p_logsys like tbdlst-logsys.
selection-screen: end of block b1.
*&---------------------------------------------------------------------*
* Constants
*&---------------------------------------------------------------------*
constants:
*segment names
c_header_segment like edidd-segnam value 'Z1EMHDR',
c_weekly_details_segment like edidd-segnam value 'Z1WKDET',
c_client_details_segment like edidd-segnam value 'Z1CLDET',
*message type
c_emp_header_msg_type like edidc-mestyp value 'ZEMPHDR',
c_emp_work_det_msg_type like edidc-mestyp value 'ZWKDET',
c_emp_client_det_msg_type like edidc-mestyp value 'ZCLDET',
*IDoc type
c_emp_header_idoc_type like edidc-idoctp value 'ZEMPHDR02',
c_emp_work_det_idoc_type like edidc-idoctp value 'ZWKDET02',
c_emp_client_det_idoc_type like edidc-idoctp value 'ZCLDET02'.
*&---------------------------------------------------------------------*
* Data declarations
*&---------------------------------------------------------------------*
*IDoc control record
data: control_record_out_emp like edidc,
control_record_out_wkdet like edidc,
control_record_out_cldet like edidc.
data: fs_emphdr_data like z1emhdr, " Employee header data
fs_week_data like z1wkdet, " Employee weekly details data
fs_clientdet_data like z1cldet. " Client details data
*total hours and amount for the summary segment
data: total_hrs_month type i,
total_amt_month type i.
*&---------------------------------------------------------------------*
* Database Tables
*&---------------------------------------------------------------------*
*Application data tables
tables: zempdetail, " Employee header data
zempwkdet. " Employee weekly details data
*&---------------------------------------------------------------------*
* Internal Tables
*&---------------------------------------------------------------------*
*Header details - Header data of employee
data: it_emhdr like zempdetail occurs 0 with header line,
*weekly details - application data
it_wkdet like zempwkdet occurs 0 with header line,
*data records
int_edidd_emhdr like edidd occurs 0 with header line,
int_edidd_wkdet like edidd occurs 0 with header line,
int_edidd_cldet like edidd occurs 0 with header line,
*communication IDocs generated
it_comm_idocs_emhdr like edidc occurs 0 with header line,
it_comm_idocs_wkdet like edidc occurs 0 with header line,
it_comm_idocs_cldet like edidc occurs 0 with header line.
*&---------------------------------------------------------------------*
* Program Logic
*&---------------------------------------------------------------------*
start-of-selection.
perform data_retrieval.
perform build_control_record.
perform build_data_records.
perform pass_control_ale_layer.
*&---------------------------------------------------------------------*
*& Form data_retrieval
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* Description:
*----------------------------------------------------------------------*
form data_retrieval .
select single *
from zempdetail
where ssn = p_ssn.
if sy-subrc ne 0.
message e001(0) with p_ssn.
exit.
endif.
select *
from zempwkdet
into table it_wkdet where ssn = p_ssn.
if sy-subrc ne 0.
message e001(0) with p_ssn.
exit.
endif.
endform. " data_retrieval
*&---------------------------------------------------------------------*
*& Form build_control_record
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
form build_control_record .
*Fill control record information for employee header
control_record_out_emp-mestyp = c_emp_header_msg_type.
control_record_out_emp-idoctp = c_emp_header_idoc_type.
control_record_out_emp-rcvprt = 'LS'.
control_record_out_emp-rcvprn = p_logsys.
*Fill control record information for employee work details
control_record_out_wkdet-mestyp = c_emp_work_det_msg_type.
control_record_out_wkdet-idoctp = c_emp_work_det_idoc_type.
control_record_out_wkdet-rcvprt = 'LS'.
control_record_out_wkdet-rcvprn = p_logsys.
*Fill control record information for employee client details
control_record_out_cldet-mestyp = c_emp_client_det_msg_type.
control_record_out_cldet-idoctp = c_emp_client_det_idoc_type.
control_record_out_cldet-rcvprt = 'LS'.
control_record_out_cldet-rcvprn = p_logsys.
endform. " build_control_record
*&---------------------------------------------------------------------*
*& Form build_data_records
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
form build_data_records .
*Employee header
fs_emphdr_data-lname = zempdetail-lname.
fs_emphdr_data-fname = zempdetail-fname.
fs_emphdr_data-ssn = zempdetail-ssn.
fs_emphdr_data-dob = zempdetail-dob.
*Fill the administrative section of the data record
int_edidd_emhdr-segnam = c_header_segment.
int_edidd_emhdr-sdata = fs_emphdr_data.
append int_edidd_emhdr.
*Employee Weekly details
loop at it_wkdet.
*Fill the weekly details for each week
fs_week_data-weekno = it_wkdet-weekno.
fs_week_data-tothours = it_wkdet-tothours.
fs_week_data-hrlyrate = it_wkdet-hrlyrate.
*Add administrative information to the data record
int_edidd_wkdet-segnam = c_weekly_details_segment.
int_edidd_wkdet-sdata = fs_week_data.
append int_edidd_wkdet.
*Client details of each week
fs_clientdet_data-clsite = it_wkdet-clsite.
fs_clientdet_data-workdesc = it_wkdet-workdesc.
*Add administrative information to the data record
int_edidd_cldet-segnam = c_client_details_segment.
int_edidd_cldet-sdata = fs_clientdet_data.
append int_edidd_cldet.
endloop. " loop at it_wkdet.
endform. " build_data_records
*&---------------------------------------------------------------------*
*& Form pass_control_ale_layer
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
form pass_control_ale_layer .
*For Employee header details
CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'
EXPORTING
master_idoc_control = control_record_out_emp
* OBJ_TYPE = ''
* CHNUM = ''
tables
communication_idoc_control = it_comm_idocs_emhdr
master_idoc_data = int_edidd_emhdr
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.
message e000(0) with p_ssn.
else.
loop at it_comm_idocs_emhdr.
write : / 'IDoc generated', it_comm_idocs_emhdr-docnum.
endloop. " loop at it_comm_idocs.
commit work.
ENDIF.
*For Employee Weekly Details
CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'
EXPORTING
master_idoc_control = control_record_out_wkdet
* OBJ_TYPE = ''
* CHNUM = ''
tables
communication_idoc_control = it_comm_idocs_wkdet
master_idoc_data = int_edidd_wkdet
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.
message e000(0) with p_ssn.
else.
loop at it_comm_idocs_wkdet.
write : / 'IDoc generated', it_comm_idocs_wkdet-docnum.
endloop. " loop at it_comm_idocs.
commit work.
ENDIF.
*Employee Client Details
CALL FUNCTION 'MASTER_IDOC_DISTRIBUTE'
EXPORTING
master_idoc_control = control_record_out_cldet
* OBJ_TYPE = ''
* CHNUM = ''
tables
communication_idoc_control = it_comm_idocs_cldet
master_idoc_data = int_edidd_cldet
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.
message e000(0) with p_ssn.
else.
loop at it_comm_idocs_cldet.
write : / 'IDoc generated', it_comm_idocs_cldet-docnum.
endloop. " loop at it_comm_idocs.
commit work.
ENDIF.
endform. " pass_control_ale_layer
contd..
|