The last section (part1) covered the steps required to enhance vendor master( table/screens ). In this section I will demonstrate the procedure to update the custom fields of vendor master and generate change pointers for these fields ( to eventually generate IDOCS for changes to field values).
Unfortunately since there is no standard BAPI to update the vendor master record, the only other options available to update custom fields of vendor master are to either 1) Perform a BDC on XK02 transaction to update custom fields on subscreen with these fields. 2) Enhance vendor API class VMD_EI_API to process and update custom fields.
The former (BDC) may not be feasible in many scenarios, specially if the custom screen fields are read only( like in my case) fields or these fields are not added to the subscreen in the first place.
Given this shortcoming of BDC I will only cover ( and recommend ) the second option for vendor master update ( vendor API class).
Step1: Enhance structure of importing parameter to pass values for custom fields.
Step2: Implement enhancement to read the values passed for custom fields and assign them to LFA1 structure which is already being populated by the standard code. The screenshot below shows implementation of explicit enhancement section EHP603_EXTERN_TO_ECC_UPDATE_02 of enhancement spot ES_VMD_EI_API_MAP_STRUCTURE.
This completes the enhancements required in the vendor master API class for updating vendor master.
Step3: The next step involves calling the MAINTAIN method of VMD_EI_API class to update vendor master. In my scenario I am reading vendor master details from an XML file, transforming it and updating Vendor master, however The code snippet only shows the call to update vendor master, rest is beyond scope of this article.
METHOD update_vendor_master.
DATA: ls_vmds_ei_main TYPE vmds_ei_main,
ls_message TYPE cvis_message,
lt_return TYPE bapiret2_t,
ls_return LIKE LINE OF lt_return.
DATA: lt_vmds_ei_extern TYPE vmds_ei_extern_t,
ls_vmds_ei_extern LIKE LINE OF lt_vmds_ei_extern.
DATA: lv_success TYPE sap_bool,
ls_lfa1_new TYPE lfa1.
DATA: ls_update_err TYPE LINE OF zmmtt_lifnr_update_failed_list.
** Populate the method input parameters.
ls_vmds_ei_extern-header-object_instance = iv_lifnr.
ls_vmds_ei_extern-header-object_task = 'U'. "<- indicator to update
ls_vmds_ei_extern-zzvend_safety_compl = is_safety_score. "<- input parameter to this method, originally read from XML
APPEND ls_vmds_ei_extern TO lt_vmds_ei_extern.
ls_vmds_ei_main-vendors = lt_vmds_ei_extern.
vmd_ei_api=>maintain(
EXPORTING
is_master_data = ls_vmds_ei_main " Vendor Total Data
IMPORTING
es_error = ls_message )." Error Indicator and System Messages
IF ls_message-is_error IS INITIAL.
COMMIT WORK AND WAIT. "<-- Explicit commit required to finalize changes in database
IF sy-subrc EQ 0.
lv_success = abap_true.
ENDIF.
ELSE.
lv_success = abap_false.
ENDIF.
IF lv_success EQ abap_true.
ls_lfa1_new = is_lfa1_old.
ls_lfa1_new-zzvscs_company_name = is_safety_score-zzvscs_company_name.
ls_lfa1_new-zzvscs_isn_code = is_safety_score-zzvscs_isn_code.
ls_lfa1_new-zzvscs_naics_code = is_safety_score-zzvscs_naics_code.
ls_lfa1_new-zzvscs_trir_3_years = is_safety_score-zzvscs_trir_3_years.
ls_lfa1_new-zzvscs_fatality_3_years = is_safety_score-zzvscs_fatality_3_years.
ls_lfa1_new-zzvscs_scq_v_score = is_safety_score-zzvscs_scq_v_score.
ls_lfa1_new-zzvscs_emr_3_years = is_safety_score-zzvscs_emr_3_years.
ls_lfa1_new-zzvscs_ravs_score = is_safety_score-zzvscs_ravs_score.
ls_lfa1_new-zzvscs_citation_info = is_safety_score-zzvscs_citation_info.
ls_lfa1_new-zzvscs_dashboard_score = is_safety_score-zzvscs_dashboard_score.
ls_lfa1_new-zzvscs_hes_showstpr = is_safety_score-zzvscs_hes_showstpr.
ls_lfa1_new-zzvscs_eval_rept = is_safety_score-zzvscs_eval_rept.
ls_lfa1_new-zzvscs_score_accept_hdr = is_safety_score-zzvscs_score_accept_hdr.
ls_lfa1_new-zzvscs_changed_by = is_safety_score-zzvscs_changed_by.
ls_lfa1_new-zzvscs_changed_at = is_safety_score-zzvscs_changed_at.
ls_lfa1_new-zzvscs_changed_on = is_safety_score-zzvscs_changed_on.
rv_success = me->perform_update_change_pointers( iv_lifnr = iv_lifnr is_lfa1_old = is_lfa1_old is_lfa1_new = ls_lfa1_new ).
" perform_update_change_pointers -> covered in next step
ELSE.
" custom error handling logic based on requirements.
ls_update_err-lifnr = iv_lifnr.
ls_update_err-name = is_lfa1_old-name1.
ls_update_err-changed_on = sy-datum.
ls_update_err-text = text-e06.
lt_return = ls_message-messages.
READ TABLE lt_return INTO ls_return WITH KEY type = 'E'.
IF sy-subrc EQ 0.
REPLACE FIRST OCCURRENCE OF '&' IN ls_update_err-text WITH ls_return-message.
ENDIF.
APPEND ls_update_err TO me->mt_lfa1_failed.
CLEAR ls_update_err.
ENDIF.
ENDMETHOD.
Step3: If the vendor master update is successful in the previous method, the next step is creation of change documents for the custom fields, which will eventually create the change pointers ( for IDOC creation).
METHOD perform_update_change_pointers.
DATA:
l_lfb1 TYPE lfb1,
l_lfm1 TYPE lfm1,
l_ylfa1 TYPE lfa1,
l_ylfb1 TYPE lfb1,
l_ylfm1 TYPE lfm1,
lt_xlfas TYPE STANDARD TABLE OF flfas,
lt_xlfb5 TYPE STANDARD TABLE OF flfb5,
lt_xlfbk TYPE STANDARD TABLE OF flfbk,
lt_xlfza TYPE STANDARD TABLE OF flfza,
lt_ylfas TYPE STANDARD TABLE OF flfas,
lt_ylfb5 TYPE STANDARD TABLE OF flfb5,
lt_ylfbk TYPE STANDARD TABLE OF flfbk,
lt_ylfza TYPE STANDARD TABLE OF flfza,
lt_xknvk TYPE STANDARD TABLE OF fknvk,
lt_xlfat TYPE STANDARD TABLE OF flfat,
lt_xlfbw TYPE STANDARD TABLE OF flfbw,
lt_xlfei TYPE STANDARD TABLE OF flfei,
lt_xlflr TYPE STANDARD TABLE OF flflr,
lt_xlfm2 TYPE STANDARD TABLE OF flfm2,
lt_xwyt1 TYPE STANDARD TABLE OF fwyt1,
lt_xwyt1t TYPE STANDARD TABLE OF fwyt1t,
lt_xwyt3 TYPE STANDARD TABLE OF fwyt3.
DATA: lv_objectid TYPE cdobjectv,
ls_update_err TYPE LINE OF ZMMTT_LIFNR_UPDATE_FAILED_LIST.
lv_objectid = iv_lifnr.
GET TIME. "<- Gets the latest date and time.
CALL FUNCTION 'KRED_WRITE_DOCUMENT' IN UPDATE TASK
EXPORTING
objectid = lv_objectid
tcode = me->gc_tcode_change
utime = sy-uzeit
udate = sy-datum
username = sy-uname
planned_change_number = ' '
object_change_indicator = me->gc_update
planned_or_real_changes = ' '
no_change_pointers = ' '
upd_knvk = space
n_lfa1 = is_lfa1_new
o_ylfa1 = is_lfa1_old
upd_lfa1 = abap_true
upd_lfas = ' '
upd_lfat = ' '
n_lfb1 = l_lfb1
o_ylfb1 = l_lfb1
upd_lfb1 = ' '
upd_lfb5 = ' '
upd_lfbk = ' '
upd_lfbw = ' '
upd_lfei = ' '
upd_lflr = ' '
n_lfm1 = l_lfm1
o_ylfm1 = l_lfm1
upd_lfm1 = ' '
upd_lfm2 = ' '
upd_lfza = ' '
upd_wyt1 = ' '
upd_wyt1t = ' '
upd_wyt3 = ' '
TABLES
xknvk = lt_xknvk
yknvk = lt_xknvk
xlfas = lt_xlfas
ylfas = lt_xlfas
xlfat = lt_xlfat
ylfat = lt_xlfat
xlfb5 = lt_xlfb5
ylfb5 = lt_xlfb5
xlfbk = lt_xlfbk
ylfbk = lt_ylfbk
xlfbw = lt_xlfbw
ylfbw = lt_xlfbw
xlfei = lt_xlfei
ylfei = lt_xlfei
xlflr = lt_xlflr
ylflr = lt_xlflr
xlfm2 = lt_xlfm2
ylfm2 = lt_xlfm2
xlfza = lt_xlfza
ylfza = lt_xlfza
xwyt1 = lt_xwyt1
ywyt1 = lt_xwyt1
xwyt1t = lt_xwyt1t
ywyt1t = lt_xwyt1t
xwyt3 = lt_xwyt3
ywyt3 = lt_xwyt3.
if sy-subrc eq 0.
COMMIT WORK AND WAIT. "<-- Explicit commit required to finalize changes in database
if sy-subrc eq 0.
rv_success = abap_true.
endif.
ENDIF.
"Custom error handing logic
if rv_success ne abap_true.
ls_update_err-lifnr = iv_lifnr.
ls_update_err-name = is_lfa1_new-name1.
ls_update_err-changed_on = SY-DATUM.
ls_update_err-text = text-e05.
APPEND ls_update_err to me->mt_lfa1_failed.
CLEAR ls_update_err.
ENDIF.
ENDMETHOD.
This completes vendor master update. In the next part will cover creation of CREAMAS idocs for vendor master changes.- part3
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
2 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 | |
1 |