MM02 BDC – Select Specific Material Master View

By | September 24, 2008 | Classical | 14,599 | 2

Creating a BDC of the MM02 will not be an easy task. As soon as we enter the material and hit enter it will ask us to choose the required Material master views. This popup contains the available material master views and they are not constant. Sometimes MRP1 comes at the 12th line and sometimes it comes to 6th line. This dynamic of the views are solely depended on the Status (MARA-VPSTA).

To overcome of this dynamics we need to get to know where exactly our required view will appear e.g. line 6 or line 10 or line 15. We will use the FM SELECTION_VIEWS_FIND to find out which view will come at which position.

In our BDC, we will follow these steps:
1. Always select the Basic Data 1
2. Get the respective user command for the tab by Executing the FM SELECTION_VIEWS_FIND.

Status (MARA-VPSTA) contains the combination of the View indicator. You can find the relation of the status indicator and view name in the documentation of the data element PSTAT_D or follow this table:


User department Maintenance status
Work scheduling A
Accounting B
Classification C
MRP D
Purchasing E
Production resources/tools F
Costing G
Basic data K
Storage L
Forecasting P
Quality management Q
Warehouse management S
Sales V
Plant stocks X
Storage location stocks Z

In this my test BDC, I want to update the MRP type. MRP type comes under the “MRP 1” view of the material master. So, I will first select the Basic Data and than move to MRP 1 view and update the MRP type.
Code Snippet to Select View in MM02

REPORT ztest_np_mm02
       NO STANDARD PAGE HEADING LINE-SIZE 255.
*
* Local data
DATA:   messtab LIKE bdcmsgcoll OCCURS WITH HEADER LINE.
DATA:   bdcdata LIKE bdcdata    OCCURS WITH HEADER LINE.
*
* Selection Screen
PARAMETERSp_matnr TYPE mara-matnr OBLIGATORY,
            p_werks TYPE marc-werks OBLIGATORY,
            p_lgort TYPE rmmg1-lgort OBLIGATORY,
            p_dismm TYPE marc-dismm OBLIGATORY.
*
*
START-OF-SELECTION.
*
* Material views ....................................................
  DATA:  l_vpsta LIKE t130m-pstat.
*
  SELECT SINGLE vpsta
         INTO   l_vpsta
         FROM   mara
         WHERE  matnr p_matnr.
*
* Get View sequence .................................................
  DATAl_bild  LIKE t133a-bilds,
        lt_bild LIKE mbildtab OCCURS WITH HEADER LINE.
*
* Screen Sequence for Standard Industry tab pages in material master
  l_bild '21'.
*
* Get screen sequence
  CALL FUNCTION 'SELECTION_VIEWS_FIND'
    EXPORTING
      bildsequenz     l_bild
      pflegestatus    l_vpsta
    TABLES
      bildtab         lt_bild
    EXCEPTIONS
      call_wrong      1
      empty_selection 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.
*
* Get the Tab page for MRP1 .........................................
  DATAl_tab_mrp1 TYPE sy-ucomm.
*
* reading table with MRP view
  READ TABLE lt_bild WITH KEY pstat 'D'.
  IF sy-subrc 0.
    l_tab_mrp1 lt_bild-guifu.
  ENDIF.
*
* make ok code for the MRP1
  CONCATENATE '=' l_tab_mrp1 INTO l_tab_mrp1.
*
* BDC ...............................................................
  PERFORM bdc_dynpro      USING 'SAPLMGMM' '0060'.
  PERFORM bdc_field       USING 'RMMG1-MATNR'
                                 p_matnr.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '=ENTR'.
*
  PERFORM bdc_dynpro      USING 'SAPLMGMM' '0070'.
  PERFORM bdc_field       USING 'MSICHTAUSW-KZSEL(01)'
                                'X'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '=ENTR'.
*
  PERFORM bdc_dynpro      USING 'SAPLMGMM' '4004'.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                l_tab_mrp1.
*
  PERFORM bdc_dynpro      USING 'SAPLMGMM' '0081'.
  PERFORM bdc_field       USING 'RMMG1-WERKS'
                                p_werks.
  PERFORM bdc_field       USING 'RMMG1-LGORT'
                                p_lgort.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '=ENTR'.
*
  PERFORM bdc_dynpro      USING 'SAPLMGMM' '4000'.
  PERFORM bdc_field       USING 'MARC-DISMM'
                                p_dismm.
  PERFORM bdc_field       USING 'BDC_OKCODE'
                                '=BU'.
*
  PERFORM bdc_transaction USING 'MM02'.
*
*&---------------------------------------------------------------------*
*&      Form  BDC_DYNPRO
*&---------------------------------------------------------------------*
FORM bdc_dynpro USING p_program
                      p_screen.
*
  MOVEp_program TO bdcdata-program,
        p_screen  TO bdcdata-dynpro,
        'X'       TO bdcdata-dynbegin.
*
  APPEND bdcdata.
  CLEAR  bdcdata.
*
ENDFORM.                    " BDC_DYNPRO
*
*&---------------------------------------------------------------------*
*&      Form  BDC_FIELD
*&---------------------------------------------------------------------*
FORM bdc_field USING p_field_name
                     p_field_value.
*
  MOVEp_field_name  TO bdcdata-fnam,
        p_field_value TO bdcdata-fval.
*
  APPEND bdcdata.
  CLEAR  bdcdata.
*
ENDFORM.                    " BDC_FIELD
*
*
*&---------------------------------------------------------------------*
*&      Form  BDC_TRANSACTION
*&---------------------------------------------------------------------*
FORM bdc_transaction USING tcode.
  DATAl_mstring(480).
  DATAl_subrc LIKE sy-subrc.
* batch input session
  REFRESH messtab.
  CALL TRANSACTION tcode USING bdcdata
                   MODE   'A'
                   "A: show all dynpros
                   "E: show dynpro on error only
                   "N: do not display dynpro
*
                   UPDATE 'L'
                   MESSAGES INTO messtab.
  REFRESH bdcdata.
ENDFORM.                    "BDC_TRANSACTION

Like It? Share!!

Don't miss an Update

Get notified of the new post, right into your inbox

Naimesh Patel{274 articles}

I'm SAP ABAP Consultant for more than a decade. I like to experiment with ABAP especially OO. I have been SDN Top Contributor.
Follow :

Explore all of his 274 articles.

Load comments

2 Comments

  • Anonymous

    This artical helped me a lot to resolve the same issue.

  • Anonymous

    Too good !!! source
    thank you !!
    AAbhar tamaro !!

Comments on this Post are now closed. If you have something important to share, you can always contact me.

You seem to be new here. Subscribe to stay connected.