Reputation: 1
I am working on an enhancement in transaction MM01
. I need to perform different actions depending on a class assigned to created material. Does anybody know where can I find an information about the class of the material that is being saved?
My enhancement is located in the include LMGMMF2J
of program SAPLMGMM
if that helps.
I looked for some information in the internet, but I found nothing about this case.
thanks in advance
Upvotes: 0
Views: 234
Reputation: 1722
To get the material's class, use the function module BAPI_OBJCL_GETCLASSES
. The parameters you need to pass are:
OBJECTKEY_IMP <material_number>
OBJECTTABLE_IMP MARA
CLASSTYPE_IMP 001
The BAPI will return all classes assigned to the material, it can be more than one.
If you need additional information from the classification (i.e. characteristics and their values), call afterwards function module BAPI_OBJCL_GETDETAIL
.
You can also read the assigned classes for the material directly from KLAH
, KSSK
tables, but calling the BAPIs provided by SAP is a preferred way as they handle a lot of special cases.
I wrote some code to show the usage of the mentioned possibilities:
" sample variable of the material number type and value
DATA: lv_matnr TYPE matnr VALUE '000000000071006094'.
WRITE: / |Material classification for { lv_matnr }|.
SELECT class FROM klah
LEFT JOIN kssk ON klah~clint = kssk~clint
WHERE kssk~objek = @lv_matnr
AND klah~klart = '001'
INTO TABLE @DATA(lt_klah).
LOOP AT lt_klah ASSIGNING FIELD-SYMBOL(<fs_klah>).
WRITE: / |{ <fs_klah>-class }|.
ENDLOOP.
DATA: lt_class TYPE STANDARD TABLE OF bapi1003_alloc_list,
lt_return TYPE STANDARD TABLE OF bapiret2.
CALL FUNCTION 'BAPI_OBJCL_GETCLASSES'
EXPORTING
objectkey_imp = CONV objnum( lv_matnr )
objecttable_imp = 'MARA'
classtype_imp = '001'
TABLES
alloclist = lt_class
return = lt_return.
IF NOT ( line_exists( lt_return[ type = 'E' ] ) OR line_exists( lt_return[ type = 'A' ] ) ).
LOOP AT lt_class ASSIGNING FIELD-SYMBOL(<fs_class>).
WRITE: / |{ <fs_class>-classnum }|.
DATA: lt_values_num TYPE STANDARD TABLE OF bapi1003_alloc_values_num,
lt_values_char TYPE STANDARD TABLE OF bapi1003_alloc_values_char,
lt_values_curr TYPE STANDARD TABLE OF bapi1003_alloc_values_curr.
CALL FUNCTION 'BAPI_OBJCL_GETDETAIL'
EXPORTING
objectkey = CONV objnum( iv_matnr )
objecttable = <fs_class>-objtyp
classnum = <fs_class>-classnum
classtype = <fs_class>-classtype
TABLES
allocvaluesnum = lt_values_num
allocvalueschar = lt_values_char
allocvaluescurr = lt_values_curr
return = lt_return.
ENDLOOP.
ENDIF.
Upvotes: 0