Produce meaningful pre-load validation reports using LSMW

Jimbo's picture

https://s-media-cache-ak0.pinimg.com/564x/6c/6a/0b/6c6a0b7490de8d0bbe1994e303d43286.jpg|https://c2.staticflickr.com/8/7181/6926781482_c2a6cd7d29.jpg|https://s-media-cache-ak0.pinimg.com/236x/6c/6a/0b/6c6a0b7490de8d0bbe1994e303d43286.jpg|http://1.bp.blogspot.com/_m8z0LDxt1qY/TSiHknX460I/AAAAAAAABRw/X6JBwWZiWSU/s1600/far_side_mountain_goat.jpg|http://static.fjcdn.com/pictures/Mountain_19716e_291487.jpg|http://66.media.tumblr.com/0024fd820003f7975d5161974d5173da/tumblr_mo1ld3Z1wQ1s5f36lo1_250.jpg|http://2.bp.blogspot.com/_ZDEr-dli0Wg/SOOacRZfNNI/AAAAAAAAACw/rXG2q8mVPKk/s320/far+side+mountain+goat.bmp|http://rwg.cc/uploads/monthly_04_2013/post-32-136656906612.jpg|http://rwg.cc/uploads/monthly_04_2013/post-32-136656906612.jpg|http://rwg.cc/uploads/monthly_04_2013/post-32-136656906612.jpg|http://hemi.nu/Gary_Larsson/index-filer/obj14geo14pg1p3.jpg|http://img.ifcdn.com/images/6519e72b12d7877ee623f4ccb3b0db8a454938778cb36ba30c8f97de1ef54b82_1.jpg|https://media.licdn.com/mpr/mpr/p/6/005/07b/1a3/3993214.jpg|https://s-media-cache-ak0.pinimg.com/564x/bc/fc/c0/bcfcc0f3edea74bf531a93dde84b9cc2.jpgThe whole point of validating data prior to loading is to give functional team members a chance to fix the data by preparing it again in a way that can be loaded into SAP or by configuring SAP to allow for the data. A meaningful report comes with all of the relevant source data along with a detailed explanation of why the record cannot be loaded to SAP.

Many conversion specialists prefer a method of error correction that calls for the data to be loaded to SAP followed by a complex process of combing through the batch log for error messages. Seldom are these error messages meaningful enough to tell why the record failed--especially when the batch is run in the background or as IDOCs. By validating the data against check tables or by calling validating functions provided by SAP, a report that documents each and every potential problem with the data can be produced for use by the functional team. This data is invaluable when coupled with instructions on how to fix the problems.

Some examples of problems with data that can be caught with validating ABAP code along with their solution are:

  • Missing Vendor, Customer or Material -- Create the dependency master data.
  • Externally assigned number falls outside the predefined number range -- Provide a new number or expand the allowable number range.
  • Master data not extended to requisite Company Code, Purchasing Org, Sales Org, Plant, Storage Location, Warehouse . . . -- Extend the dependency master data.
  • Date and number formats incompatible with configuration of SAP -- Transform the data to be aligned with SAP standards.
  • Master data flagged for deletion or in blocked status -- Remove deletion flag or blocked status.
  • Master data or transactional data already exists -- Skip loading the redundant data.

Reports don't need to be overly complicated.

/image.php?image=misc/backlash.jpg|/image.php?image=misc/backlash.jpg|/image.php?image=misc/backlash.jpg|/image.php?image=misc/backlash.jpg|/image.php?image=misc/backlash.jpg|/image.php?image=misc/backlash.jpg|/image.php?image=misc/backlash.jpg|/image.php?image=misc/backlash.jpg|/image.php?image=misc/backlash.jpg|/image.php?image=misc/backlash.jpg|/image.php?image=misc/backlash.jpg|/image.php?image=misc/backlash.jpg|http://www.thefishermansjournal.com/wp-content/uploads/2016/02/backlash2.jpg|http://www.distractioncharters.com/wp-content/uploads/2008/07/P72900461.jpg|http://scontent.cdninstagram.com/t51.2885-15/s480x480/e35/11380995_380296458847554_1488972618_n.jpg?ig_cache_key=MTAyMDU5MTE0MDkyMjEwNjYyMA%3D%3D.2|http://www.distractioncharters.com/wp-content/uploads/2008/07/P72900461.jpg|http://www.ifish.net/gallery/data/500/medium/backlash.jpg|http://cdn0.wideopenspaces.com/wp-content/uploads/2015/04/backlash.jpg|https://fishwithjd.com/wp-content/uploads/2007/06/Backlash.jpg|http://3.bp.blogspot.com/-E_pyIFEZEdk/VcYtjZwN2mI/AAAAAAABtlg/fUgTG-ZDRY4/s1600/photos_of_things_you_dont_see_everyday_640_11.jpgThe easiest way to present the data to the functional team member is as an Excel spreadsheet. By exporting directly to Excel in an easy-to-read format, one eliminates errors caused by manual transformations into Excel and improves the chance that some action will be taken on the reported errors.

An internal table with the significant fields from the source data, an error type and a detailed error message is a great way to store data as the conversion runs so that it can be written out as a fixed-width report. If each field is just big enough to hold the needed data, then the report need not wrap lines of text. Here is a great example of code used to produce an error report during the conversion of inventory records.

In the GLOBAL_DATA section of the LMSW Field Mapping and Conversion Rules, this snippet of code creates a structure to hold the error log, an internal table called it_ErrorLog and a working area called wa_ErrorLog that acts as a holding area for data to be added to the internal table or read from it.

types: begin of t_ErrorLog,
        Index type i,
        BKTXT(10) type c,
        MATNR(18) type c,
        WERKS(4) type c,
        CHARG(10) type c,
        LGORT(4) type c,
        ErrorType(15) type c,
        ErrorMessage(60) type c,
       end of t_ErrorLog.
data: it_ErrorLog type standard table of t_ErrorLog initial size 0.
data: wa_ErrorLog type t_ErrorLog, cErrorMessage(60) type c.

http://www.thefishermansjournal.com/wp-content/uploads/2016/02/backlash2.jpg|http://www.distractioncharters.com/wp-content/uploads/2008/07/P72900461.jpg|http://scontent.cdninstagram.com/t51.2885-15/s480x480/e35/11380995_380296458847554_1488972618_n.jpg?ig_cache_key=MTAyMDU5MTE0MDkyMjEwNjYyMA%3D%3D.2|http://www.distractioncharters.com/wp-content/uploads/2008/07/P72900461.jpg|http://www.ifish.net/gallery/data/500/medium/backlash.jpg|http://cdn0.wideopenspaces.com/wp-content/uploads/2015/04/backlash.jpg|https://fishwithjd.com/wp-content/uploads/2007/06/Backlash.jpgHere is an example of a validation that is performed on the data as it is being converted in LSMW. Each material must be maintained in the plant where it is being created or moved to and this code provides an easy way to check that it is. When the material is not maintained in a plant then a record is added to the internal table with all of the necessary information needed to explain why the record cannot be created. Then the skip_transaction statement ensures that this record is not loaded. Note that MB11S is the structure of the source data.

select single * from MARC into lMARC
 where MATNR eq MB11S-MATNR
   and WERKS eq MB11S-WERKS.
if sy-subrc ne 0.
    concatenate 'Not maintained in plant' MB11S-WERKS
     into cErrorMessage separated by space.
    perform AppendErrorLog using 'Missing Plant' cErrorMessage.
  add 1 to nWERKS.
  skip_transaction.
endif.

The inventory load conversion should have more than one dozen validations like this. After the records have been converted and the internal table is full of information to be loaded, a simple loop produces a perfect fixed-width report for easy use in Excel. This code goes in the END_OF_PROCESSING section of the LMSW Field Mapping and Conversion Rules.

Note: Later revisions of this report included code designed to obviate the need to copy-past or import fixed-width text into Excel.

 
loop at it_ErrorLog into wa_ErrorLog.
  write: / wa_ErrorLog-Index, wa_ErrorLog-MATNR, wa_ErrorLog-WERKS,
   wa_ErrorLog-BKTXT, wa_ErrorLog-ErrorType, wa_ErrorLog-ErrorMessage.
endloop.

Finally, this short form adds the data to the internal table without having to be passed each and every field. This goes in the FORM_ROUTINES section of the LMSW Field Mapping and Conversion Rules.

form AppendErrorLog using cErrorType cErrorMessage.
    wa_ErrorLog-Index = nIndex.
    wa_ErrorLog-BKTXT = MB11S-BKTXT.
    wa_ErrorLog-MATNR = MB11S-MATNR.
    wa_ErrorLog-WERKS = MB11S-WERKS.
    wa_ErrorLog-LGORT = MB11S-LGORT.
    wa_ErrorLog-CHARG = MB11S-CHARG.
    wa_ErrorLog-ErrorType = cErrorType.
    wa_ErrorLog-ErrorMessage = cErrorMessage.
    append wa_ErrorLog to it_ErrorLog.
endform.

The finished report should look like this and be easy for the functional team to understand. Be sure to add an index so that it is clear what line in the source code the error relates to.