Quantcast
Channel: SCN : Blog List - ABAP Development
Viewing all articles
Browse latest Browse all 943

Mandatory Views in Material Master - MM01 and MM02

$
0
0


'How to make material master views mandatory ?'. This is one of the often asked questions on SCN. I also came across a similar requirement and after going through several posts in got an idea on how to achieve this. However , the steps to achieve the requirement were not properly documented and were spread across multiple posts which prompted me to write this blog post.

 

 

Requirement:

 

  • Make Basic Data 1 , Basic Data 2 and Classification Data Views as mandatory. An error message should be triggered if the user tries to save a material without maintaining these views.
  • Make all material classes and material characteristics mandatory.
  • This should work for both MM01 and MM02. Thus a user should get an error is a new material  is being created without mandatory views through MM01 or changes are being done to an existing material not having the mandatory views.

 

 

Approach:

 

  • We will make use of  customer-exit EXIT_SAPLMGMU_001 to write our logic.

  • Function module MAIN_PARAMETER_GET will be used to get the views currently being maintained or views already present for a material ( material extension or change scenario).

  • CLAP_DDB_ALLOCATION_FR_BUFFER will be used to read the material classes in buffer.

  • CLAP_DDB_GET_BUFFER_PARAMS to read the material characteristic values in buffer.

  • CLAF_CLASSIFICATION_OF_OBJECTS to get the material characteristics from database.
  • Further explanations are given below as a part of comments in code snippets for better understanding.



Check for mandatory views:

 

Function module MAIN_PARAMETER_GET will give the list of material master tables that are going to be updated. The tables parameter MTAB is filled with the list of used tables at run time.

 

This table has 2 fields which we need to read to get the views being maintained.

 

MTAB-BISTSTAT will have the list of views that already exist for a material.

 

MTAB-PFSTATUS will have the list of views currently being maintained.

 

 

Code:

 

CALL FUNCTION 'MAIN_PARAMETER_GET'

      TABLES

        mtab = lt_mtab.

    IF sy-subrc EQ 0.

*--Check the existing view and current views being created.Read for table MARA. The status for  Basic Data is 'K' and classification data is 'C'.

      CLEAR ls_mtab.

      READ TABLE lt_mtab INTO ls_mtab WITH KEY tbnam = 'MARA'

      IF sy-subrc EQ 0.

*--Check for basic view

        IF ls_mtab-biststat CA 'K' OR ls_mtab-pfstatus CA 'K'.

*--Basic Data View is present ( Do nothing )

        ELSE.

*--Give error message

         MESSAGE 'Material Master Views Basic Data 1 / Basic Data 2 are mandatory' Type 'E'.

        ENDIF.

*--Check for classification view

        IF ls_mtab-biststat CA 'C' OR ls_mtab-pfstatus CA 'C'.

*--Classification Data View is present ( Do nothing )

       ELSE.

          MESSAGE 'Material Master View Classification is mandatory' type 'E'.

        ENDIF.

      ENDIF.

    ENDIF.

 

 

Check for mandatory classes and characteristic values in Classification View:


If user is currently maintaining classification view ( MM01 material create ) then the check should be done from the buffer values else in case of material extension or change ( MM02 ) the values should be read from database to check for completeness.


Code:


Check buffer values ( material create - MM01 ).

*--If classification data tab is currently being maintained


IF ls_mtab-pfstatus CA lc_c.


*--Check for material classes


      CLEAR lv_objkey.

 

*--Pass material number in object key


       lv_objkey = cmara-matnr.

*--Read buffer values


       CALL FUNCTION 'CLAP_DDB_ALLOCATION_FR_BUFFER'
EXPORTING
      object                       = lv_objkey
      classtype                  = '001'
      ptable                       = 'MARA'
TABLES
      t_allocations            =  lt_allocations
EXCEPTIONS
      no_allocations_in_buffer = 1
      class_not_in_buffer        = 2
      allocation_not_in_buffer = 3
      missing_parameter        = 4
      others                           = 5.

*--Delete the values in lt_allocations where VBKZ is 'D' (deleted allocation )
*--So after delete we will only have unchanged values ( VBKZ ' ') or
*--newly added ( VBKZ 'U' ).This ensures that we take care of allocations
*--being deleted in current maintenance

DELETE lt_allocations WHERE vbkz EQ 'D'. 


*--Now we can check in table lt_allocations whether all classes are present or not

*--Loop at the table and check if all the  required material classes  are present.

*--If required classes are not maintained give error message else proceed.

 

*--Check for mandatory classifications

 

CALL FUNCTION 'CLAP_DDB_GET_BUFFER_PARAMS'
EXPORTING
      object    
= lv_objkey
      classtype 
= '001'
      obtab     
= 'MARA'
TABLES
      e_ausp_tab
= lt_ausp.

*--Delete the values in lt_ausp where STATU is 'L' ( old values )
*--So after delete we will only have unchanged values ( STATU ' ') or
*--new changed values ( STATU 'H' ).This ensures there is only 1 entry
*--per classification


DELETE lt_ausp WHERE statu EQ 'L'


*--Now we can check in table lt_ausp whether values for all material classifications are present

*--or not. If not the trigger error message.


 

Code:

 

Check data base values ( MM01 - material extension scenario where classification tab is not maintained currently OR MM02 - material change ).

 

 

*--If classification tab is not being maintained currently


ELSE.


*--Pass material as object key

 


lv_objkey = cmara-matnr.


CALL FUNCTION 'CLAF_CLASSIFICATION_OF_OBJECTS'
EXPORTING
      classtype          = ‘001’
      object               = lv_objkey
TABLES
      t_class             = lt_class
      t_objectdata      = lt_objectdata
EXCEPTIONS
      no_classification    = 1
      no_classtypes        = 2
      invalid_class_type  = 3
      OTHERS              = 4.

*--Check for mandatory classes

*--Check in table LT_CLASS if all the material classes are present. If not then trigger an error message.

 

 

*--Check for characteristic values


*--Fetch the characteristic details from CABN

*--Check if values exist for each characteristic in table LT_OBJECTDATA.

*--To determine if a value for characteristic has been given compare with character ‘?’

*--If values are not present  CLAF_CLASSIFICATION_OF_OBJECTS returns '?' else it can be blank or some value.

 


ENDIF.

 

 

NOTE:

 

  • The class type for material class is '001'.
  • Material classes and characteristics related data can be fetched from tables KLAH ,KSML.
  • Characteristic details can also be fetched from table CABN.

Viewing all articles
Browse latest Browse all 943

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>