0% found this document useful (0 votes)
43 views

Code Backup FM

This document contains a program for creating and updating customer mappings between an SAP S/4HANA system and an ECC system using IDOCs. It retrieves the BP number from ECC, calls BAPI functions to create the BP in S/4HANA if not exist, maps it to the ECC customer, and calls standard IDOC processing FMs to post updates to both systems. If the BP already exists, it just updates the mapping and calls the standard FM in update mode.

Uploaded by

Sri Tayi
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Code Backup FM

This document contains a program for creating and updating customer mappings between an SAP S/4HANA system and an ECC system using IDOCs. It retrieves the BP number from ECC, calls BAPI functions to create the BP in S/4HANA if not exist, maps it to the ECC customer, and calls standard IDOC processing FMs to post updates to both systems. If the BP already exists, it just updates the mapping and calls the standard FM in update mode.

Uploaded by

Sri Tayi
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

*

* q@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@$|
* ._qKQQ@@@@@@@@@@@@@@@@@@@@@@@@@@@$|
* .__gQQQ@$ `'=4@$@@@$@@$@@@$@@$@$@$p|
* ._gQ@$K=* (@@@@Q0o-., `<Y@$@$@@$@@@$@@@@@$|
* _gQ@@p9=` __Qgg^~<=v4@@@Qz. `<Y@@@@$@$@@@$@$p|
* .gQ@@@=~ ._Q@$$V=4_._ (4q@@O_. 74$@@@@@$@@@@$|
* =@@@@L [@@@N` (@@@Q; .QQ@@@V` .Q@@$@$@@@$@$p|
* (q@@@__ K@@@;. (@@@@QQ@@@@@*` ._z@@@$m@@@$@@@@$|
* <q@@@Q_ (K@@Q_g@@@@$K='` __g@@@@F+ 4@$@p|
* 7Y@@@Q_ -<YKK.._._._.+0@@@Hv* __QQ@@$@p|
* .v4@@@o__. (@@@@@@@pY0=' .__gQ@@@@@@@$$|
* <7Y@@@@$,,,,,..,,,.;;ggQ@@@@@@@@@@@@$@p|
* `~=7<QQQQQQ@@@@@@@@@@@@@@@@@@@$@@@@$|
* (@QQ@@@@Q@$@Q@@Q@Q@Q@Q@Q@Q@Q@Q@X|
*
" .oQ@@q_gvq@| <=@@F* (=q$=>(v@p== (=q@V===4kg_, <4@@=+ .1Q
" 7 Q=JT .g@` ~@Q| .p+ q@| [@: =qQ_ {qQ JF@|
" .@QH` .Qp q@. .@! {@| [@Q [Q@ {qQ QL_a@l
" .@pT .@$ . ([email protected] {@| [@Q [@Q {qQ .1V~^~q@.
" .g@! qQ@ ;" 7@$| ..@l_. .1@_.._._Q$F .{Q$., .g$. Jq$;
" (=' <=^>` =! ^=^^^~ :^^^==>^=^< ^^^^^` 7^^^^ ^<<^
*-----------------------------------------------------------------------
* PROGRAM : Z_MM_VEND_CREATE
* CREATED BY : Sri Tayi
* CREATED ON : 25.10.2021
* COPIED FROM : IDOC_INPUT_DEBITOR
* USER : n/a
* TRANSPORT # : S4WK900776
* Description : This is the inbound FM copied from the standard FM
IDOC_INPUT_DEBITOR
* for the DEBMAS idoc being sent from ECC this fm will use the standard posting
logic to post the idoc
*and when teh posting is success, then we will create mapping between BP and
customer in CFIN table
***********************************************************************
*---------------------------------------------------------------------*
* MODIFICATION LOG (latest first)
*---------------------------------------------------------------------*
* Trans request: INITIAL
* Bug # :
* Author :
* Date :
* Description :
***********************************************************************
FUNCTION z_sd_cust_create.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(INPUT_METHOD) LIKE BDWFAP_PAR-INPUTMETHD
*" VALUE(MASS_PROCESSING) LIKE BDWFAP_PAR-MASS_PROC
*" VALUE(PI_XD99_USED) TYPE CHAR1 DEFAULT SPACE
*" VALUE(PI_KNVK_SPECIAL) TYPE CHAR1 DEFAULT SPACE
*" EXPORTING
*" VALUE(WORKFLOW_RESULT) LIKE BDWFAP_PAR-RESULT
*" VALUE(APPLICATION_VARIABLE) LIKE BDWFAP_PAR-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
*"----------------------------------------------------------------------

* get the BP number based on the ECC customer number


NEW zcl_post_bp( )->m_read_mapping( EXPORTING it_idoc_data = idoc_data[]
iv_koart = 'D'
IMPORTING ev_partner = DATA(lv_partner)
ev_posting_type = DATA(lv_ptype)
ev_flag = DATA(lv_flag)
ev_code = DATA(lv_kunnr) ).

* update the ecc values with S4 mapping values


NEW zcl_post_bp( )->m_update_mapping( EXPORTING iv_ptype = lv_ptype iv_partner
= lv_kunnr iv_koart = 'D'
CHANGING ct_idoc_data = idoc_data[] ).
* if sameno indicator is X, then call the standard idoc processing FM
IF lv_flag = zcl_post_bp=>gc_insert.
IF lv_ptype-sameno_ind = abap_true.
PERFORM f_call_standard_idoc TABLES idoc_contrl idoc_data idoc_status
return_variables serialization_info
USING input_method mass_processing pi_xd99_used
pi_knvk_special idoc_contrl-docnum
CHANGING workflow_result application_variable
in_update_task call_transaction_done.

ELSEIF lv_ptype-sameno_ind = abap_false AND lv_ptype-prefix IS NOT INITIAL.

NEW zcl_post_bp( )->m_pop_bapi_cust(


EXPORTING
it_doc_data = idoc_data[]
IMPORTING
ev_seg_kna1 = DATA(ls_kna1)
ev_seg_knb1 = DATA(ls_knb1)
ev_org = DATA(lv_org)
ev_addr = DATA(lv_address)
ev_central = DATA(lv_central) ).
CLEAR: lv_flag, gv_partner.

gv_bp_partner = lv_ptype-prefix && lv_kunnr.


NEW zcl_post_bp( )->m_vend_prefix_conv(
EXPORTING
iv_lifnr = lv_kunnr
iv_ptype = lv_ptype
IMPORTING
ev_code = DATA(lv_code)
CHANGING
cv_partner = gv_bp_partner ).

REFRESH gt_return[].
SELECT SINGLE bu_group FROM tbd001 INTO @DATA(lv_partner_grp) WHERE ktokd =
@ls_kna1-ktokd.
IF sy-subrc IS NOT INITIAL.
CLEAR lv_partner_grp.
ENDIF.
CALL FUNCTION 'BAPI_BUPA_CREATE_FROM_DATA'
EXPORTING
businesspartnerextern = gv_bp_partner
partnercategory = gv_cat
partnergroup = lv_partner_grp
centraldata = lv_central
centraldataorganization = lv_org
addressdata = lv_address
IMPORTING
businesspartner = gv_partner
TABLES
return = gt_return.
READ TABLE gt_return INTO DATA(ls_return) WITH KEY type = 'E'.
IF sy-subrc IS NOT INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true.
DATA(lv_msg) = TEXT-000 && | : | && gv_partner .
* update IDOC status
NEW zcl_post_bp( )->m_pop_idoc_status( EXPORTING iv_idocnum =
idoc_contrl-docnum
iv_msgv1 = CONV #( lv_msg
)
iv_status = '53'
it_return = gt_return
CHANGING ct_idoc_status =
idoc_status[] ).
*create mapping between BP and ECC customer in CFIN tables
NEW zcl_post_bp( )->m_create_mapping(
EXPORTING iv_partner = gv_partner
iv_eccno = lv_kunnr
iv_idocnum = idoc_contrl-docnum
iv_mapent = gc_mapent
iv_koart = 'D'
CHANGING ct_idoc_status = idoc_status[] ).
ELSEIF sy-subrc IS INITIAL.
lv_flag = abap_true.
* update IDOC status
NEW zcl_post_bp( )->m_pop_idoc_status( EXPORTING iv_idocnum =
idoc_contrl-docnum
iv_msgv1 = TEXT-002
iv_status = '51'
it_return = gt_return
CHANGING ct_idoc_status =
idoc_status[] ).
ENDIF.

IF lv_flag = abap_false.
REFRESH : gt_return.
* add vendor role to the BP created
NEW zcl_post_bp( )->m_add_role(
EXPORTING
iv_partner = gv_partner
iv_idocnum = idoc_contrl-docnum
iv_role = gc_role
IMPORTING
ev_flag = lv_flag
CHANGING
ct_return = gt_return
ct_idoc_status = idoc_status[] ).
ENDIF.
READ TABLE idoc_status WITH KEY status = '51' TRANSPORTING NO FIELDS.
IF sy-subrc IS NOT INITIAL.
* update the ecc customer number with bp in s4
NEW zcl_post_bp( )->m_update_bp_c( EXPORTING iv_partner = gv_partner
CHANGING ct_idoc_data = idoc_data[] ).

* AFTER ALL THE UPDATES ARE DONE IN CREATE MODE , WE WILL TRIGGER IDOC AGAIN IN
CHANGE MODE FOR ZSEGMENTS UPDATION
PERFORM f_call_standard_idoc TABLES idoc_contrl idoc_data idoc_status
return_variables serialization_info
USING input_method mass_processing pi_xd99_used
pi_knvk_special idoc_contrl-docnum
CHANGING workflow_result application_variable
in_update_task call_transaction_done.
READ TABLE idoc_status WITH KEY status = '51' TRANSPORTING NO FIELDS.
IF sy-subrc IS INITIAL.
LOOP AT idoc_status ASSIGNING FIELD-SYMBOL(<lfs_status>).
<lfs_status>-status = '51'.
ENDLOOP.
ENDIF.
ENDIF.
ENDIF.
ELSEIF lv_flag = zcl_post_bp=>gc_update.
* update the ecc customer number with bp in s4
NEW zcl_post_bp( )->m_update_bp_c( EXPORTING iv_partner = gv_partner CHANGING
ct_idoc_data = idoc_data[] ).
* if the BP already exist then call the standard FM to update the changes in UPDATE
mode

PERFORM f_call_standard_idoc TABLES idoc_contrl idoc_data idoc_status


return_variables serialization_info
USING input_method mass_processing
pi_xd99_used pi_knvk_special idoc_contrl-docnum
CHANGING workflow_result
application_variable in_update_task call_transaction_done.
ENDIF.
ENDFUNCTION.

You might also like