Site icon SAP Human Resources Experts And Solutions

SAP LSMW Translation Rules

In our previous posts, we’ve learned basic rules with LSMW. Today we need to clarify one the most important technique in data migration in SAP projects. We know how to use different migration tools like BAPI, IDOC, flat files, complex files, batch input. But all these are useless if we can’t convert data on the fly. This is a great advantage of Legacy Workbench in SAP is to able to convert data with integrated translation rules.

So, the translation rules are used when we need to map one value in the incoming file to any other value which is to store in SAP. It could be just simple text concatenation, substitutions or even complex ABAP logic with a lot of functional module calls retrieving some data out of the system.

LSMW Fixed Values

This conversion allows defining some fixed value which you can use further in conversion. It’s like a constant which is set once in one place and used widely across the system. If you need to change value, you change it only in this fixed value definition and the system distributes the value everywhere. The very simple example is loading infotype. We can change M200 wage type code to a constant and change it whatever we load at the moment.

SAP LSMW recording

When we match source fields with target structure in LSMW we can use either a constant value for wage type, can load wage type value from the file or can refer to this fixed value translation rule. This solution could be used in hierarchical files when the same key fields could repeat on different file levels.

LSMW Translations Rules

By its naming translation rules is the main conversion tool in LSMW. They have a wide variety of tools to manage data. Have a look at the screenshot below.

LSMW Translation Rules

For curious, there is a FORM lsmw_translate_execute in the source code /SAPDMC/SAP_LSMW_CONV_FORMS which stores business logic for data conversion.

If you pay attention, we have three frames on the screen: Variant, First Alternative, Second Alternative. During data translation systems, first of all, runs a Variant (1:1 or Interval translation). If it was not able to run translation (value was not found), it tries First Alternative, then Second Alternative if first one failed. This is a three level decision making tree.

The first level (Variant frame) allows two types of changes: one to one or interval. values we provide on corresponding tabs on the same screen. Enter value and tick checkbox next to it.

If you need an interval selection, do it this way:

Fields length defined on the first tab – Source Field, Target Field.

If the system didn’t find the right value we can return a constant. Let’s say ‘ERROR’.

Or we choose User-Defined Routine and use an ABAP code to perform any sort of conversion. This is the power of the translation rules.

Remain options:

Transfer (MOVE) – copy value as is.

Initial Value – setup default value for this type of field.

No Action – do nothing.

User-defined routines or custom ABAP translation rules

This is the most simple and complex rule. You can implement all options we were talking about right here with couple lines of code. Or code ZSAP for your convenience :)

Test conversions

Once we’ve done with translation rules we need to assign them to the fields. We do this in Define Field Mapping and Conversion Rules, where we assign the source field to the target (hit Source Field button), then click on Translation button to choose your conversion rule.

P.S. Here is also my video on Youtube how to do a basic LSMW project:

Share this post with your SAP friends and colleagues. It won’t cost you anything but will motivate us to write more interesting content.



Exit mobile version