Track Transactional Data With Discreet Keys

Jimbo's picture

Load Characteristic Values with a BAPITransactional data is some of the trickiest to load. Many documents have dozens of dependencies which, in turn, are stacked on top of other dependencies. It's not always possible to catch every problem and a partial load might make for a failed project.

Planting a discreet key in each source record allows for the ability to link the records from the source file to documents created in SAP. This link allows for delta loads to be performed as obstacles to loading are removed and dependencies are provided and reduces the risk of duplicate records when performing delta loads. Additionally, editing (or reversing and re-creating) documents becomes a much simpler matter when errors are discovered after the data has been loaded.

The discreet key can go in nearly any free-text field in any part of the document. Great examples of places to store a discreet key are free text fields like insurance notes, sales notes or document header text or line item text in financial documents.

For this example the material movement transaction MB11 is used and the discreet key is tucked into the header text field. The first step is adding the information to the source file. After the source data is imported to Excel the process of adding the discreet key can begin.

The header text field in the material movement document (MKPF-BKTXT) is 30 characters, but for this example the discreet key will be limited to 10 characters so that it can be recycled in other objects like packing and putting away of materials.

In the BKTXT column add an initial discreet key that is related to the content being loaded. In this case it is for inventory created in the Waldorf manufacturing plant. The fist discreet key will be WALDO00001. This first five characters describe the source of the data and the last five characters will be used as an incremental counter to ensure that each discreet key is unique in the source. Enter the discreet key in the first BKTXT field and add the formula below (adjusted for your spreadsheet) to the second BKTXT field.


Insert discreet key into source data.

Save this spreadsheet as text to be read into LSMW. Ensure that the integrity of the data is preserved.

The type of LSMW object used is immaterial as Standard Batch, Recording, BAPI and IDoc all have the capacity to populate the header text field. Start by adding these lines to the GLOBAL_DATA section under the Change Field Mapping and Conversion Rules section of the LSMW object.

data: lMKPF like MKPF, lMSEG like MSEG.
data: it_MKPF type standard table of MKPF initial size 0.
data: wa_MKPF like MKPF.

In the BEGIN of PROCESSING section add this code. This will load a subsection of the material movement document header table (MKPF) into memory and drastically improve the speed of the LSMW object. This article better explains why caching data in internal tables is so effective.

select * from MKPF into wa_MKPF where BKTXT ne '' order by BKTXT.
  append wa_MKPF to it_MKPF.

Now the filtering can begin. For this task the system need only check to see if there is already an existing document in the system with the same document header text and skip the transaction when the document already exists. As a bonus, the program creates a list the document number associated with the record allowing for the quick production of an easy-to-use reconciliation report.

loop at it_MKPF into wa_MKPF where BKTXT eq MB11S-BKTXT.
  write: / MB11S-BKTXT, wa_MKPF-MBLNR, 'Inventory document already loaded.'.