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.



Execution Snapshots:

Go to MM01 to create material:

/wp-content/uploads/2015/06/1_718483.png

Enter material number , industry sector and material type. Select views to be maintained. Do not select Basic Data views.

/wp-content/uploads/2015/06/2_718511.png

Enter data on views selected:

/wp-content/uploads/2015/06/3_718512.png

/wp-content/uploads/2015/06/4_718513.png

Save the material.

/wp-content/uploads/2015/06/5_718514.png

Error message is triggered.

NOTE:

  • The class type for material class is ‘001’.
  • Material classes and characteristics related data can be fetched from tables KLAH ,KSML, AUSP and INOB.
  • Characteristic details can also be fetched from table CABN and CAWN.
  • The buffer related function modules and FM MAIN_PARAMETER_GET will only work when material is created through transactions and not when created through BAPIs.
To report this post you need to login first.

7 Comments

You must be Logged on to comment or reply to a post.

  1. Philippe Campels

    Badi BADI_MATERIAL_CHECK can also be used to make these kinds of checks.

    That’s what we have done to have the classification view mandatory for any new material creation.

    (0) 
    1. Tanmay Verma Post author

      Hi Philippe ,

      Thanks for the info. I think i had checked this BADI but was not able to use it as per my requirements. It would be great if you can share how you used it.

      Thanks.

      Tanmay.

      (0) 
    1. Tanmay Verma Post author

      Hi Sergiu,

      PFB:

      *–tables

      DATA:

      lt_mtab        TYPE STANDARD TABLE OF sptap,

      lt_class       TYPE STANDARD TABLE OF sclass,

      lt_objectdata  TYPE STANDARD TABLE OF clobjdat,

      lt_allocations TYPE STANDARD TABLE OF rmclkssk,

      lt_ausp        TYPE STANDARD TABLE OF rmclausp.

      *–Work areas
      DATA:

      ls_mtab        TYPE sptap,

      ls_objectdata  TYPE clobjdat,

      lv_objkey      TYPE objnum.

      ~Tanmay

      (0) 
  2. DSB INFORMATIK

    Thanks for sharing.

    But when I try to syntax check, it says: FIELD LC_C is unknown.

    Can you please share the data declaration OR explain where this should be specified?

    Thanks

    Karsten

    (0) 

Leave a Reply