cancel
Showing results for 
Search instead for 
Did you mean: 

Change several sales views (MVKE) in userexit MGA00001

Raphael_Sommer
Participant
1,442

Hello,

while saving material changes e.g. via MM02 but also in general, we want to update MVKE-PRDHA and MVKE-VMSTA for several sales orgs, depending on old and new MARA-PRDHA. How can this be done?

What we already tried:

  • Calling BAPI 'BAPI_MATERIAL_SAVEDATA' for every sales org in userexit MGA00001 --> Problem some structures are changed and original changes are not persisted only the ones from the BAPI (changes on MVKE table were fine but not on MARA)
  • Calling BAPI 'BAPI_MATERIAL_SAVEDATA' for every sales org in userexit MGA00001 with a wrapper function module 'IN UPDATE TASK' --> Problem changes are not persisted only the ones from MARA MM02 and not the ones from the BAPI call MVKE)
  • Seems to work: Make an enhancement after function module calls 'MATERIAL_UPDATE_DB' and 'OPEN_FI_PERFORM_00001250_E' in Include LMGMUF01 and in this enhancement BAPI BAPI_MATERIAL_SAVEDATA is called for every sales organization.
  • Not tried yet: use BTE Business Transaction Event OPEN_FI_PERFORM_00001250_E to react on changes and update MVKE fields

Thank you, best regards.

View Entire Topic
Raphael_Sommer
Participant
0 Kudos

Solution was to make a Z function module as a wrapper:

This Z function module has processing type:

In this Z function module just the SAP function module gets called:

  CONSTANTS: lc_tcode_exit    TYPE char10 VALUE '(EXIT)',
             lc_kz_no_warn    TYPE messagetyp VALUE 'N',
             lc_call_mode_mdg TYPE mmd_c_mode VALUE 'MDG'.


  CALL FUNCTION 'MATERIAL_MAINTAIN_DARK'
    EXPORTING
      flag_muss_pruefen      = abap_false
      p_kz_no_warn           = lc_kz_no_warn
      kz_prf                 = abap_false
      kz_dispo               = abap_false
      call_mode              = lc_call_mode_mdg
      call_mode2             = lc_call_mode_mdg
      flg_mass               = abap_true
      iv_change_doc_tcode    = lc_tcode_exit
    TABLES
      amara_ueb              = it_mara
      amvke_ueb              = it_mvke
    EXCEPTIONS
      kstatus_empty          = 1
      tkstatus_empty         = 2
      t130m_error            = 3
      internal_error         = 4
      too_many_errors        = 5
      update_error           = 6
      error_propagate_header = 7
      OTHERS                 = 8.

In the userexit it was neccessary to hinder recursive calls:

DATA: lt_abap_stack TYPE  abap_callstack,
        lt_sys_stack  TYPE  sys_callst.

  CALL FUNCTION 'SYSTEM_CALLSTACK'
    IMPORTING
      callstack    = lt_abap_stack
      et_callstack = lt_sys_stack.

  READ TABLE lt_abap_stack WITH KEY blockname = 'Z_MATERIAL_MAINTAIN_DARK' TRANSPORTING NO FIELDS.
  IF sy-subrc EQ 0.
    DATA(lv_is_called_from_z_fb) = abap_true.
  ENDIF.

  IF lv_is_called_from_z_fb EQ abap_false.
   ....
  ENDIF.