Skip to Content
Author's profile photo Rajio Urkude

Vendor Code addition in MB21 Screen

We got the requirement from the client that to add Vendor code field in Reservation screen (Tcode-MB21/22) & Update Vendor Code against Reservation.

So I have looked all the EXIT provide by SAP but none of then contained Screen Exit. So I have looked on SCN for any further possibility to full fill this requirement. Mostly talked about same EXIT & BADI’s  But strangely I could not find any particular solution which will solve my quest.

I thought it’s better to share my solution that how we solve this quest So that It might be helpful to people with the same requirement.

Let’s get started 😉 …!!!

As a developer, debugging is the best tool to find & understand the flow of the program.

After lots of debugging the standard programs, we come to the solution that we will provide a pop up to add vendor code as they need in the header level & fortunately user accepted our solution.

As there is no screen exit for ME21/22 so we fulfill the requirement by just giving the pop up during SAVE.

During debugging I have found various enhancement spot but very few spots fulfill our requirement & below is the detailed solution for that.

Program Name: MM07RFR0

Just Create Enhancement spot at the end of the subroutine: rsegmente_generieren 

as shown in below screenshot:

Below is the Code Sample:

ENHANCEMENT 1  ZMB_VENDOR_POP_UP.    "active version
    IF sy-tcode EQ 'MB21' OR sy-tcode EQ 'MB22'.
    DATA:
          it_resb  TYPE STANDARD TABLE OF sval,
          wa_resb TYPE sval,
          it_resb_ext TYPE STANDARD TABLE OF resb,
          lv_lifnr TYPE resb-lifnr.

    IF it_resb IS INITIAL.
    wa_resb-tabname = 'RESB'.
    wa_resb-fieldname = 'LIFNR'.
    IF xresb-lifnr IS NOT INITIAL.
*--Display Vendor--*
          wa_resb-value = xresb-lifnr.
    ENDIF.
    APPEND wa_resb TO  it_resb.
    ENDIF.
*--Pop up for Vendor--*
    CALL FUNCTION 'POPUP_GET_VALUES'
      EXPORTING
        popup_title           = 'Select Vendor'
      tables
        fields                = it_resb
     EXCEPTIONS
       ERROR_IN_FIELDS       = 1
       OTHERS                = 2           .
    IF sy-subrc <> 0.
* Implement suitable error handling here
    ENDIF.

      READ TABLE it_resb ASSIGNING FIELD-SYMBOL(<fs_resb>) INDEX 1.
*--Fill the Vendor in RESB--*
      IF sy-subrc IS INITIAL.
        lv_lifnr = <fs_resb>-value.
      ENDIF.
    IF xresb IS NOT INITIAL.
      LOOP AT xresb ASSIGNING FIELD-SYMBOL(<fs_xresbz>).
            IF lv_lifnr IS NOT INITIAL.
              <fs_xresbz>-lifnr = lv_lifnr.
          ENDIF.
      ENDLOOP.
    ENDIF.
*--For No change--*
    IF upd_resb IS INITIAL AND upd_rkpf IS INITIAL AND
       new_resb IS INITIAL AND sy-tcode EQ 'MB22'.
       IF xresb-rsnum IS NOT INITIAL.
       SELECT
         *
         FROM resb
         INTO TABLE it_resb_ext
         WHERE rsnum = xresb-rsnum.
        IF sy-subrc IS INITIAL.
          LOOP AT it_resb_ext ASSIGNING FIELD-SYMBOL(<fs_resb_update>).
            IF <fs_resb_update>-lifnr NE lv_lifnr.
            <fs_resb_update>-lifnr = lv_lifnr.
*--Update the Vendor--*
             UPDATE resb SET lifnr = <fs_resb_update>-lifnr
                         WHERE rsnum EQ <fs_resb_update>-rsnum
                          AND  rspos EQ <fs_resb_update>-rspos
                          AND  rsart EQ <fs_resb_update>-rsart.
            ENDIF.
          ENDLOOP.
        ENDIF.
       ENDIF.
    ENDIF.
   ENDIF.

ENDENHANCEMENT.

Above solution handle both the requirement i.e. during creating (MB21) it saved the Vendor code against Reservation & during change (MB22) it should display the previous vendor & able to change the same at the SAVE moment.

 

Final output:

When clicking on SAVE button (MB21) the user will get pop up for vendor code –

After Saved Vendor got updated against reservation in Table – RESB

Also, the same will be reflected in MIGO –

Your feedback & improvement are always welcome! 🙂

Regards,

Rajio Urkude

 

Assigned Tags

      2 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Praveen Kumar Sharma
      Praveen Kumar Sharma

      Nice blog, very useful

      Author's profile photo Alejandro Piwarczuk
      Alejandro Piwarczuk

      Thats nice. Thanks!