‎2010 Feb 08 10:37 PM
Hi,
I have a scenario in which i have to send MBGMCR02 Idoc from SAP to XI.
I created a new Outbound process code and now I have to code the function module that populates data into the segments.
Does anyone have sample code for this, i.e code to put in the finction module of an outbound process code?
‎2010 Feb 09 6:42 AM
hi..
Try with these Function Modules
MASTER_IDOC_DISTRIBUTE
IDOC_OUTBOUND_WRITE_TO_DB
Thank you.
Regards,
Lokeswari.
‎2010 Feb 09 6:42 AM
hi..
Try with these Function Modules
MASTER_IDOC_DISTRIBUTE
IDOC_OUTBOUND_WRITE_TO_DB
Thank you.
Regards,
Lokeswari.
‎2010 Feb 09 6:45 AM
hi...
please find the below code.
&----
*& Report ZPROGRAM11
*&
&----
*&
*&
&----
REPORT ZPROGRAM11.
tables : likp,vbuk,vbfa,ibin,vbap,vbak,kna1.
types : begin of iy_tab,
vbeln type vbfa-vbeln,
vbelv type vbfa-vbelv,
posnv type vbfa-posnv,
end of iy_tab.
types : begin of iy_tab1,
vbeln type vbuk-vbeln,
wbstk type vbuk-wbstk,
end of iy_tab1.
types : begin of iy_tab2,
vbeln type vbak-vbeln,
kunnr type vbak-kunnr,
vkorg type vbak-vkorg,
vtweg type vbak-vtweg,
spart type vbak-spart,
end of iy_tab2.
data : i_ibase type ib_ibase.
data : i_kunnr type vbak-kunnr.
data : it_tab type table of iy_tab with header line,
it_tab1 type standard table of iy_tab1 ,
wa_tab1 type iy_tab1,
it_tab2 type standard table of iy_tab2 ,
wa_tab2 type iy_tab2.
data : t_edidd type standard table of edidd .
data : t_edidc type edidc.
data : t_edidc1 type standard table of edidc .
data : wa type edidd.
data : wa1 type e1edl20.
data : wa2 type zibase.
data : wa3 type e1edl32.
data : wa4 type e1edl44.
data : wa5 type e1edl37.
data : wa6 type e1edl28.
data : wa7 type e1edl30.
data : wa8 type e1edl24.
data : wa9 type e1adrm1.
data : begin of it_tab3 occurs 10,
vbeln type iy_tab-vbelv,
posnr type iy_tab-posnv,
i_ibase type ib_ibase,
end of it_tab3.
types : begin of iy_tab4 ,
valfr type ibin-valfr,
ibase type ibin-ibase,
amount type ibin-amount,
unit type ibin-unit,
end of iy_tab4.
data : it_tab4 type standard table of iy_tab4,
wa_tab4 type iy_tab4.
data : begin of it_tab5 occurs 10,
vbeln type vbfa-vbelv,
posnr type vbfa-posnv,
ibase type ibib-ibase,
valfr type ibin-valfr,
amount type ibin-amount,
unit type ibin-unit,
matnr type vbap-matnr,
kunnr type vbak-kunnr,
vkorg type vbak-vkorg,
vtweg type vbak-vtweg,
spart type vbak-spart,
name1 type kna1-name1,
end of it_tab5.
types : begin of iy_tab6,
vbeln type vbap-vbeln,
posnr type vbap-posnr,
matnr type vbap-matnr,
end of iy_tab6.
data : it_tab6 type standard table of iy_tab6,
wa_tab6 type iy_tab6.
types : begin of iy_tab7,
kunnr type kna1-kunnr,
name1 type kna1-name1,
end of iy_tab7.
data: it_tab7 type standard table of iy_tab7,
wa_tab7 type iy_tab7.
data : wa_table type ytable1.
selection-screen: begin of block b1 with frame title text-t00.
parameters: p_vbeln type vbfa-vbeln.
selection-screen: end of block b1.
start-of-selection.
select vbeln vbelv posnv from vbfa into table it_tab
where vbeln = p_vbeln.
if sy-subrc eq 0.
loop at it_tab.
select vbeln wbstk from vbuk into table it_tab1
for all entries in it_tab
where vbeln = it_tab-vbeln.
endloop.
endif.
loop at it_tab1 into wa_tab1.
if wa_tab1-wbstk = 'C'.
loop at it_tab.
call function 'IBSD_CREATE_IBASE'
exporting
i_vbeln = it_tab-vbelv
i_posnr = it_tab-posnv
i_as_sold = '0'
i_as_build = '0'
i_capid = '0'
I_CHANGE = ' '
i_commit = 'X'
I_COMMIT_WAIT = ' '
importing
e_ibase = i_ibase
exceptions
order_not_found = 1
position_not_found = 2
nothing_to_do = 3
too_much_to_do = 4
missing_authorization = 5
foreign_lock = 6
others = 7
.
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
else.
move it_tab-vbelv to it_tab3-vbeln.
move it_tab-posnv to it_tab3-posnr.
move i_ibase to it_tab3-i_ibase.
append it_tab3.
if sy-subrc eq 0.
select valfr ibase amount unit from ibin into table it_tab4
for all entries in it_tab3
where ibase = it_tab3-i_ibase.
if sy-subrc eq 0.
select vbeln posnr matnr from vbap into table it_tab6
for all entries in it_tab3
where vbeln = it_tab3-vbeln and posnr = it_tab3-posnr .
if sy-subrc eq 0.
select vbeln kunnr vkorg vtweg spart from vbak into table it_tab2
for all entries in it_tab
where vbeln = it_tab-vbelv.
sort it_tab2 by vbeln.
delete adjacent duplicates from it_tab2 comparing all fields.
if sy-subrc <> 0.
select kunnr name1 from kna1 into table it_tab7
for all ENTRIES IN it_tab2
where kunnr = it_tab2-kunnr.
endif.
endif.
endif.
endif.
endif.
endloop.
else.
exit.
if sy-subrc eq 0.
*
*
endif.
endif.
endloop.
loop at it_tab3.
move it_tab3-vbeln to it_tab5-vbeln.
move it_tab3-posnr to it_tab5-posnr.
move it_tab3-i_ibase to it_tab5-ibase.
if sy-subrc eq 0.
read table it_tab4 into wa_tab4 with key ibase = it_tab3-i_ibase.
move wa_tab4-valfr to it_tab5-valfr.
move wa_tab4-amount to it_tab5-amount.
move wa_tab4-unit to it_tab5-unit.
if sy-subrc eq 0.
read table it_tab6 into wa_tab6 with key vbeln = it_tab3-vbeln posnr = it_tab3-posnr.
move wa_tab6-matnr to it_tab5-matnr.
if sy-subrc eq 0.
read table it_tab2 into wa_tab2 with key vbeln = it_tab3-vbeln.
move wa_tab2-kunnr to it_tab5-kunnr.
move wa_tab2-vkorg to it_tab5-vkorg.
move wa_tab2-vtweg to it_tab5-vtweg.
move wa_tab2-spart to it_tab5-spart.
if sy-subrc eq 0.
read table it_tab7 into wa_tab7 with key kunnr = wa_tab2-kunnr.
move wa_tab7-name1 to it_tab5-name1.
append it_tab5.
endif.
endif.
endif.
endif.
append it_tab5.
endloop.
loop at it_tab5.
move it_tab5-vbeln to wa_table-vbeln.
move it_tab5-kunnr to wa_table-kunnr.
move it_tab5-vbeln to wa_table-vbeln.
move it_tab5-ibase to wa_table-ibase.
move it_tab5-matnr to wa_table-matnr.
move it_tab5-valfr to wa_table-valfr.
move it_tab5-unit to wa_table-unit.
move it_tab5-amount to wa_table-amount.
move it_tab5-vkorg to wa_table-vkorg.
move it_tab5-vtweg to wa_table-vtweg.
move it_tab5-spart to wa_table-spart.
move it_tab5-name1 to wa_table-name1.
insert ytable1 from wa_table.
endloop.
*INSERT ytable1 FROM TABLE it_tab5.
loop at it_tab5.
wa1-vbeln = it_tab-vbeln.
wa1-vkorg = it_tab5-vkorg.
wa-segnam = 'E1EDL20'.
wa-sdata = wa1.
wa-hlevel = 2.
append wa to t_edidd.
loop at it_tab3.
wa2-i_ibase = it_tab5-ibase.
wa2-i_qty = it_tab5-amount.
wa2-i_dat = it_tab5-valfr.
wa-segnam = 'ZIBASE'.
wa-sdata = wa2.
wa-hlevel = 3.
append wa to t_edidd.
endloop.
wa9-name1 = it_tab5-name1.
wa-segnam = 'E1ADRM1'.
wa-sdata = wa9.
wa-hlevel = 3.
append wa to t_edidd.
wa-segnam = 'E1EDL28'.
wa-sdata = wa6.
wa-hlevel = 3.
append wa to t_edidd.
wa-segnam = 'E1EDL30'.
wa-sdata = wa7.
wa-hlevel = 4.
append wa to t_edidd.
wa3-kunnr = it_tab5-kunnr.
wa-segnam = 'E1EDL32'.
wa-sdata = wa3.
wa-hlevel = 5.
append wa to t_edidd.
wa8-meins = it_tab5-unit.
wa8-vtweg = it_tab5-vtweg.
wa8-spart = it_tab5-spart.
wa-segnam = 'E1EDL24'.
wa-sdata = wa8.
wa-hlevel = 3.
append wa to t_edidd.
wa-segnam = 'E1EDL37'.
wa-sdata = wa5.
wa-hlevel = 3.
append wa to t_edidd.
wa4-vbeln = it_tab5-vbeln.
wa4-posnr = it_tab5-posnr.
wa4-matnr = it_tab5-matnr.
wa-segnam = 'E1EDL44'.
wa-sdata = wa4.
wa-hlevel = 4.
append wa to t_edidd.
endloop.
t_edidc-mandt = sy-mandt.
t_edidc-direct = '1'.
t_edidc-rcvpor = 'A000000062'.
t_edidc-rcvprt = 'LS'.
t_edidc-rcvprn = 'O2C_ASSET'.
t_edidc-rcvpfc = 'LS'.
t_edidc-sndpor = 'SAPSIT'.
t_edidc-sndprt = 'LS'.
t_edidc-sndprn = 'T90CLNT090'.
t_edidc-sndpfc = 'LS'.
t_edidc-mestyp = 'DELVRY'.
t_edidc-idoctp = 'DELVRY03'.
*t_edidc-rcvpfc = 'LS'.
t_edidc-sndpfc = 'LS'.
t_edidc-cimtyp = 'ZDELVRY03'.
append t_edidc to t_edidc1.
call function 'MASTER_IDOC_DISTRIBUTE'
exporting
master_idoc_control = t_edidc
OBJ_TYPE = ''
CHNUM = ''
tables
communication_idoc_control = t_edidc1
master_idoc_data = t_edidd
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.
CALL FUNCTION 'DB_COMMIT'
.
CALL FUNCTION 'DEQUEUE_ALL'
EXPORTING
_SYNCHRON = ' '
.
COMMIT WORK.
endif.
endloop.
‎2010 Feb 22 7:00 PM
Used the following link to code the FM
http://help.sap.com/saphelp_nw04/helpdata/en/dc/6b7dbd43d711d1893e0000e8323c4f/frameset.htm