Validate Valuation Class Based On Material Type

Jimbo's picture

One of the most important things that a Data Migration team can do is produce validation reports that explain in great detail any issues that will prevent the loading of source data into an SAP system before trying to load it. This tremendous value-add is what separates great data migration resources from mediocre ones.

Even the most detailed army of pre-load validation routines can still miss small inconsistencies between systems due to customization and configuration. Dealing with disperate material types over a landscape of development, quality assurance and production system can still allow errors to sneak through--like inconsistencies between Material Type and Valuation Class.

Solution 1

After some guerrilla-style triage programming during go-live, a rough--but functional--solution was in place to analyze incoming source data to ensure that SAP would accept the combination of Material Type and Valuation Class therein. It involves using a simple-enough function and checking for just one error code.

call function 'MBEW_BKLAS_RETAIL'
  exporting
    WMBEW_BKLAS     = BMMH1-BKLAS
    WMBEW_BWKEY     = ''
    WMBEW_BWTTY     = ''
    WMBEW_BWTAR     = ''
    WMARA_MATNR     = ''
    WMARA_ATTYP     = ''
    LMBEW_BKLAS     = ''
    OMBEW_BKLAS     = ''
    P_AKTYP         = ''
    NEUFLAG         = ''
    WRMMG1_MTART    = BMM00-MTART
  exceptions
    NO_BKLAS             = 1
    ERROR_BKLAS          = 2
    ERROR_NACHRICHT      = 3.
if sy-subrc eq 2.  "Error with BKLAS
  write: / MM01S-BISMT,
   BMMH1-BKLAS color col_negative,
   'valuation class not allowed for material type',
   BMM00-MTART.
  skip_transaction.
endif.

Solution 2

After analyzing the source code of the function, it becomes clear that the system is simply comparing the Account category reference (KKREF) fields of the T134 table (Material Types) and the T025 table (Valuation Classes). An even simpler snippet involves stepping through these tables and validating both the Valuation Class and Material Type at the same time.

data: lT025 like T025, lT134 like T134.

select single * from T134 into lT134 where MTART eq BMM00-MTART.
if sy-subrc ne 0.
  write: / MM02S-BISMT,
   BMM00-MTART color col_negative, 'Invalid material type.'.
  skip_transaction.
else.
  select single * from T025 into lT025 where BKLAS eq BMMH1-BKLAS.
  if sy-subrc ne 0.
    write: / MM02S-BISMT,
     BMMH1-BKLAS color col_negative, 'Invalid Valuation Class.'.
    skip_transaction.
  else.
    if lT134-KKREF ne lT025-KKREF. "Valuation class not for Mat.Type.
      write: / MM02S-BISMT,
       BMMH1-BKLAS color col_negative,
        'valuation class not allowed for material type',
        BMM00-MTART.
      skip_transaction.
    endif.
  endif.
endif.
Programming Language: 
ABAP