‎2008 May 05 8:50 AM
hai friends
iam getting idocs form xi system (matmas)
in this MBEWM segement is repeting meny times
in this segment BWTAR field some times not having any value
at that time
if the that segement is is first segment then it is posting proparly
but if we get that segement at other than first is not posting .
how can i do this .
pls help me.
srikanth vipparla
‎2008 May 06 1:54 PM
Hi Srikanth,
As per the description you are receiving the Idoc from the XI system. So, in this case it is actually an inbound scenario, how you are handling the Inbound idocs? I mean of course that would be a process code but is it through an activity or through a function module? If you are using the standard function module then, I would suggest you to go for a custom function module where you have handeled such scenarios (like the one that you have mentioned) and post the documents in SAP.
Warm Regards.
Abhijit.
‎2008 May 26 12:41 PM
plz suggest me how to write custom FM for Inbound Idoc ?
thanks for in advance..
‎2008 May 27 11:15 PM
Source Code
function z_idoc_input_sach .
*"----
""Local interface:
*" IMPORTING
*" VALUE(INPUT_METHOD) LIKE BDWFAP_PAR-INPUTMETHD
*" VALUE(MASS_PROCESSING) LIKE BDWFAP_PAR-MASS_PROC
*" VALUE(NO_APPLICATION_LOG) LIKE SY-DATAR OPTIONAL
*" VALUE(MASSSAVEINFOS) LIKE MASSSAVINF STRUCTURE MASSSAVINF
*" OPTIONAL
*" EXPORTING
*" VALUE(WORKFLOW_RESULT) LIKE BDWF_PARAM-RESULT
*" VALUE(APPLICATION_VARIABLE) LIKE BDWF_PARAM-APPL_VAR
*" VALUE(IN_UPDATE_TASK) LIKE BDWFAP_PAR-UPDATETASK
*" VALUE(CALL_TRANSACTION_DONE) LIKE BDWFAP_PAR-CALLTRANS
*" TABLES
*" IDOC_CONTRL STRUCTURE EDIDC
*" IDOC_DATA STRUCTURE EDIDD
*" IDOC_STATUS STRUCTURE BDIDOCSTAT
*" RETURN_VARIABLES STRUCTURE BDWFRETVAR
*" SERIALIZATION_INFO STRUCTURE BDI_SER
*" EXCEPTIONS
*" WRONG_FUNCTION_CALLED
*"----
include mbdconwf.
data : it_emp_data like zsach1 occurs 0 with header line.
data : gen_data like zsach1 .
workflow_result = c_wf_result_ok.
data : counter type int4.
select count( * ) from zsach1 into counter.
counter = counter + 1.
loop at idoc_contrl.
if idoc_contrl-mestyp ne 'ZSACH'.
raise wrong_function_called.
endif.
clear gen_data.
refresh it_emp_data.
loop at idoc_data where docnum eq idoc_contrl-docnum.
if idoc_data-segnam = 'ZSACH'.
gen_data = idoc_data-sdata.
it_emp_data-mandt = counter.
it_emp_data-lname = gen_data-lname.
it_emp_data-fname = gen_data-fname.
counter = counter + 1.
append it_emp_data.
else.
message 'ERROR' type 'I'.
endif.
endloop.
endloop.
insert zsach1 from table it_emp_data.
*****
call function 'EDI_DOCUMENT_OPEN_FOR_EDIT'
exporting
document_number = idoc_data-docnum
importing
idoc_control = idoc_contrl
tables
idoc_data = idoc_data
exceptions
document_foreign_lock = 1
document_not_exist = 2
document_not_open = 3
status_is_unable_for_changing = 4
others = 5.
call function 'EDI_CHANGE_DATA_SEGMENTS'
tables
idoc_changed_data_range = idoc_data
exceptions
idoc_not_open = 1
data_record_not_exist = 2
others = 3.
data t_itab_edids40 like edi_ds40 occurs 0 with header line.
clear t_itab_edids40.
t_itab_edids40-docnum = idoc_data-docnum.
t_itab_edids40-status = '51'.
t_itab_edids40-repid = sy-repid.
t_itab_edids40-tabnam = 'EDI_DS'.
t_itab_edids40-mandt = sy-mandt.
t_itab_edids40-stamqu = 'SAP'.
t_itab_edids40-stamid = 'B1'.
t_itab_edids40-stamno = '999'.
t_itab_edids40-stapa1 = 'Sold to changed to '.
*t_itab_edids40-stapa2 = t_new_kunnr.
t_itab_edids40-logdat = sy-datum.
t_itab_edids40-logtim = sy-uzeit.
append t_itab_edids40.
call function 'EDI_DOCUMENT_CLOSE_EDIT'
exporting
document_number = idoc_data-docnum
do_commit = 'X'
do_update = 'X'
write_all_status = 'X'
tables
status_records = t_itab_edids40
exceptions
idoc_not_open = 1
db_error = 2
others = 3.
endfunction.
Use this function module. Reward if it is useful.
Cheers
R.Rajendran
‎2008 May 28 6:52 AM
Hi ,
It is simple .
1. Just retrieve the data from the Idoc
2 . Put in ur Interanl table table .
3.Upadate the Transaction using appropriate method .
BAPI or BDC.
FUNCTION z7_idoc_input_ordchg.
*"----
""Local Interface:
*" IMPORTING
*" REFERENCE(INPUT_METHOD) LIKE BDWFAP_PAR-INPUTMETHD
*" REFERENCE(MASS_PROCESSING) LIKE BDWFAP_PAR-MASS_PROC
*" EXPORTING
*" REFERENCE(WORKFLOW_RESULT) LIKE BDWFAP_PAR-RESULT
*" REFERENCE(APPLICATION_VARIABLE) LIKE BDWFAP_PAR-APPL_VAR
*" REFERENCE(IN_UPDATE_TASK) LIKE BDWFAP_PAR-UPDATETASK
*" REFERENCE(CALL_TRANSACTION_DONE) LIKE BDWFAP_PAR-CALLTRANS
*" REFERENCE(DOCUMENT_NUMBER) LIKE VBAK-VBELN
*" TABLES
*" IDOC_CONTRL STRUCTURE EDIDC
*" IDOC_DATA STRUCTURE EDIDD
*" IDOC_STATUS STRUCTURE BDIDOCSTAT
*" RETURN_VARIABLES STRUCTURE BDWFRETVAR
*" SERIALIZATION_INFO STRUCTURE BDI_SER
*" EDI_TEXT STRUCTURE EDIORDTXT1 OPTIONAL
*" EDI_TEXT_LINES STRUCTURE EDIORDTXT2 OPTIONAL
*"----
&----
*& Function module Z7_IDOC_INPUT_ORDCHG *
&----
************************************************************************
TITLE : Inbound Function module *
AUTHOR : Sree M *
CREATED DATE : 20/MAY/2008 *
=====================================================================*
Description : Inbound FUnction module for updating the data in the *
sale order *
=====================================================================*
Loop at IDOC_CONTRL.
IF idoc_contrl-idoctp NE 'ORDERS05'.
MESSAGE e899(f4) WITH text-001.
ENDIF.
****Retrieving the date from IDOC
LOOP AT idoc_data WHERE docnum EQ idoc_contrl-docnum.
CASE idoc_data-segnam.
WHEN 'E1EDK01'.
MOVE idoc_data-sdata TO is_e1edk01.
WHEN 'E1EDP01'.
MOVE idoc_data-sdata TO is_e1edp01.
MOVE is_e1edp01-posex TO l_posnr.
MOVE is_e1edp01-abgrt TO wa_vbap-zzcontract_num.
ENDCASE.
ENDLOOP.
v_vbeln = is_e1edk01-belnr.
L_POSNR = IS_e1edp01-posex.
.
Select single * from vbap into wa_vbap
where vbeln = v_vbeln
and
posnr = l_posnr.
If sy-subrc = 0.
Check ( IS_e1edp01-abgrt NE wa_vbap-zzcontract_num ).
Wa_vbap-zzcontract_num = IS_e1edp01-abgrt.
****Updating the Transaction
***Here using lock Object I updated
CALL FUNCTION 'ENQUEUE_EMVBAP'
EXPORTING
MODE_VBAP = 'E'
MANDT = SY-MANDT
VBELN = v_VBELN
POSNR = l_posnr
X_VBELN = ' '
X_POSNR = ' '
_SCOPE = '2'
_WAIT = ' '
_COLLECT = ' '
EXCEPTIONS
FOREIGN_LOCK = 1
SYSTEM_FAILURE = 2
OTHERS = 3
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
idoc_status-docnum = idoc_contrl-docnum.
Update vbap from wa_vbap.
IF SY-SUBRC = 0.
v_flag = 'X'.
ENDIF.
CALL FUNCTION 'DEQUEUE_EMVBAP'
EXPORTING
MODE_VBAP = 'E'
MANDT = SY-MANDT
VBELN = v_VBELN
POSNR = l_posnr
X_VBELN = ' '
X_POSNR = ' '
_SCOPE = '3'
_SYNCHRON = ' '
_COLLECT = ' '
.
IF V_FLAG = 'X'.
idoc_status-status = '53'.
idoc_status-msgty = 'S'.
idoc_status-msgid = sy-msgid.
idoc_status-msgno = sy-msgno.
idoc_status-msgv1 = sy-msgv1.
idoc_status-msgv2 = sy-msgv2.
idoc_status-msgv3 = sy-msgv3.
idoc_status-msgv4 = sy-msgv4.
APPEND idoc_status.
ELSE.
idoc_status-status = '51'.
idoc_status-msgty = 'E'.
idoc_status-msgid = sy-msgid.
idoc_status-msgno = sy-msgno.
idoc_status-msgv1 = sy-msgv1.
idoc_status-msgv2 = sy-msgv2.
idoc_status-msgv3 = sy-msgv3.
idoc_status-msgv4 = sy-msgv4.
APPEND idoc_status.
return_variables-wf_param = eid.
return_variables-doc_number = idoc_contrl-docnum.
APPEND return_variables.
workflow_result = c_wf_result_error.
ENDIF.
ENDIF.
ENDLOOP.
ENDFUNCTION.
Rgds
Sree M