Simulate MM17 transaction using LSMW

Jimbo's picture

Z-fields (and some standard fields) are inaccessible in MASS and MM17; the program cannot be modified without extreme difficulty. This LSMW object creates a BDC with a separate transaction for each material to be updated. The batch can then be managed and monitored in SM35.

The first step is to determine what materials are to be updated. This is accomplished by the use of a simple selection in Global Data Definitions and Declarations pulling materials from the MARA table. Additional filtering can be accomplished by specifying plants that contain materials. This additional filtering is highly recommended when updating plant-specific views like Purchasing, Accounting and MRP.

tables: mara, marc.
selection-screen begin of block block1 with frame title bTitle1.
SELECT-OPTIONS :
 s_MATNR for MARA-MATNR,
 s_WERKS for MARC-WERKS.
selection-screen end of block block1.

Select ViewsThe second step is determining what View the field is on. This task is handled by use of listbox populated in advance with the names of the views. The list that is being passed is an internal table with the concatenated values from BILDS and AUSWG from the T133A table along with the associated names of views in the T133B table. These values are used later to identify the screen container and the OKCODE used to call the desired screen.

data:
 wa_T133B like T133B, wa_T133A like T133A,
 it_MARA type standard table of MARA initial size 0,
 wa_MARA like MARA.
TYPE-POOLS: VRM.
DATA: NAME  TYPE VRM_ID,
      LIST  TYPE VRM_VALUES,
      VALUE LIKE LINE OF LIST.
    parameters: p_Screen(30) as listbox visible length 50.
AT SELECTION-SCREEN OUTPUT.
  select * from T133A into wa_T133A
   where BILDS eq 'Z1' and GUIST eq 'DATE00'.
    select * from T133B into wa_T133B
     where BILDS eq wa_T133A-BILDS and AUSWG eq wa_T133A-AUSWG
       and SPRAS eq sy-langu.
      concatenate wa_T133A-BILDS wa_T133A-AUSWG into VALUE-KEY.
      VALUE-TEXT = wa_T133B-DYTXT.
      APPEND VALUE TO LIST.
    endselect.
  endselect.
  NAME = 'P_SCREEN'.
  CALL FUNCTION 'VRM_SET_VALUES'
    EXPORTING
      ID     = NAME
      VALUES = LIST.


Once the it_MARA internal table is populated with the desired materials to be updated the software loops through the table and adds a transaction for each material in the internal table. The wa_T133A variable contains the values used to populated the screen number. The GUIFU field in the T133A is the OKCODE from the Basic View that opens the actual desired screen.

  select single * from T133A into wa_T133A
   where BILDS eq p_Screen+0(2) and AUSWG eq p_Screen+2(2).
  perform bdc_open_group using 'MM02_MASS'.
  loop at it_MARA into wa_MARA.
    " Pick the material.
    perform bdc_dynpro using 'SAPLMGMM' '0060'.
    perform bdc_field using 'BDC_OKCODE' 'ENTR'.
    perform bdc_field using 'RMMG1-MATNR' wa_MARA-MATNR.
    " Select basic view
    perform bdc_dynpro using 'SAPLMGMM' '0070'.
    perform bdc_field using 'BDC_OKCODE' 'ENTR'.
    perform bdc_field using 'MSICHTAUSW-KZSEL(01)' 'X'. "Basic view
    " Select the desired screen
    perform bdc_dynpro using 'SAPLMGMM' '4004'.
    perform bdc_field using 'BDC_OKCODE' wa_T133A-GUIFU.
    if wa_T133A-GUIFU ne 'SP01' and wa_T133A-GUIFU ne 'SP02'.
      "This is not a basic view and there may be Oganizational Levels.
      perform bdc_dynpro using 'SAPLMGMM' '0081'.
      perform bdc_field using 'BDC_OKCODE' 'ENTR'.
      if p_WERKS ne ''.
        perform bdc_field using 'RMMG1-WERKS' p_WERKS.
      endif.
      if p_LGORT ne ''.
        perform bdc_field using 'RMMG1-LGORT' p_LGORT.
      endif.
      if p_VKORG ne ''.
        perform bdc_field using 'RMMG1-VKORG' p_VKORG.
      endif.
      if p_VTWEG ne ''.
        perform bdc_field using 'RMMG1-VTWEG' p_VTWEG.
      endif.
    endif.
    " Find the correct screen number (DYPNO).
    perform bdc_dynpro using 'SAPLMGMM' wa_T133A-DYPNO.
    perform bdc_field using 'BDC_OKCODE' 'BU'.
    perform bdc_field using p_Field p_Value.
    perform bdc_insert using 'MM02'.
  endloop.
  perform close_batch_Input.

Organizational LevelsIn the middle of the code above is a check to see if wa_T133A-GUIFU does not equal "SP01" or "SP02". If not, then the "Organizational Levels" screen is expected and the fields will be populated with the related parameters. If this screen is not added to the BDC then the batch will stop here while SAP waits for the screen to be populated.

The remainder is simple forms to be called to simplify the creation of the BDC. These could be called directly in the code above, but the code is much nicer when called this way.

****************************************************************
*- BDC OPEN
****************************************************************
FORM bdc_open_group using p_1.
  CALL FUNCTION 'BDC_OPEN_GROUP'
    EXPORTING
      CLIENT = SY-MANDT
      GROUP  = p_1
      KEEP   = 'X'
      USER   = SY-UNAME.
ENDFORM.                    "bdc_open_group
****************************************************************
*- BDC CLOSE
****************************************************************
FORM close_batch_input.
  CALL FUNCTION 'BDC_CLOSE_GROUP'.
ENDFORM.                    "close_batch_input
****************************************************************
*-BDC DYNPRO
****************************************************************
FORM bdc_dynpro using p_1 p_2.
  itbdc-program = p_1.
  itbdc-dynpro = p_2.
  itbdc-dynbegin = 'X'.
  append itbdc. clear itbdc.
ENDFORM.                    "bdc_dynpro
****************************************************************
*- BDC FIELD
****************************************************************
FORM bdc_field using p_1 p_2.
  itbdc-fnam = p_1.
  itbdc-fval  = p_2.
  append itbdc. clear itbdc.
ENDFORM.                    "bdc_field
****************************************************************
*- BDC INSERT
****************************************************************
FORM bdc_insert using p_1.
  CALL FUNCTION 'BDC_INSERT'
    EXPORTING
      tcode     = p_1
    TABLES
      dynprotab = itbdc.
ENDFORM.                    "bdc_insert
****************************************************************

Download this LSMW object

The entire project is available here. There are no additional dependencies.

Related articles:
The Workarounds section of SAPLSMW.com
Handling Disperate Material Masters in MM02 with a Recording