<p>In our previous posts, we&#8217;ve learned basic rules with <a href="https://saphcmsolutions.com/advanced-lsmw/" target="_blank" rel="noopener">LSMW</a>. 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, <a href="https://saphcmsolutions.com/data-conversion-sap-ale/" target="_blank" rel="noopener">IDOC</a>, flat files, <a href="https://saphcmsolutions.com/load-several-files-lsmw/" target="_blank" rel="noopener">complex files</a>, batch input. But all these are useless if we can&#8217;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.</p>
<p>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.</p>
<p><a href="http://saphr.ru/wp-content/uploads/lsmw_transformation_rules.png"><img class="alignnone size-full wp-image-2895" src="http://saphr.ru/wp-content/uploads/lsmw_transformation_rules.png" alt="SAP LSMW transformation rules" width="909" height="375" /></a></p>
<p><!--more--></p>
<h3>LSMW Fixed Values</h3>
<p>This conversion allows defining some fixed value which you can use further in conversion. It&#8217;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.</p>
<div id="attachment_2896" style="width: 1029px" class="wp-caption alignnone"><a href="http://saphr.ru/wp-content/uploads/lsmw_transformation_rules_02.png"><img aria-describedby="caption-attachment-2896" class="wp-image-2896 size-full" src="http://saphr.ru/wp-content/uploads/lsmw_transformation_rules_02.png" alt="SAP LSMW recording" width="1019" height="716" /></a><p id="caption-attachment-2896" class="wp-caption-text">SAP LSMW recording</p></div>
<p>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.</p>
<h3>LSMW Translations Rules</h3>
<p>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.</p>
<div id="attachment_2898" style="width: 863px" class="wp-caption alignnone"><a href="http://saphr.ru/wp-content/uploads/lsmw_transformation_rules_03.png"><img aria-describedby="caption-attachment-2898" class="wp-image-2898 size-full" src="http://saphr.ru/wp-content/uploads/lsmw_transformation_rules_03.png" alt="LSMW Translation Rules" width="853" height="691" /></a><p id="caption-attachment-2898" class="wp-caption-text">LSMW Translation Rules</p></div>
<p>For curious, there is a FORM <strong>lsmw_translate_execute </strong>in the source code <strong>/SAPDMC/SAP_LSMW_CONV_FORMS </strong>which stores business logic for data conversion.</p>
<p>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.</p>
<p>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.</p>
<p><a href="http://saphr.ru/wp-content/uploads/lsmw_transformation_rules_04.png"><img class="alignnone size-full wp-image-2902" src="http://saphr.ru/wp-content/uploads/lsmw_transformation_rules_04.png" alt="LSMW 1:1 transformation" width="820" height="319" /></a></p>
<p>If you need an interval selection, do it this way:</p>
<p><a href="http://saphr.ru/wp-content/uploads/lsmw_transformation_rules_05.png"><img class="alignnone size-full wp-image-2903" src="http://saphr.ru/wp-content/uploads/lsmw_transformation_rules_05.png" alt="LSMW Interval Transformation Rules" width="753" height="360" /></a></p>
<p>Fields length defined on the first tab &#8211; Source Field, Target Field.</p>
<p>If the system didn&#8217;t find the right value we can return a constant. Let&#8217;s say &#8216;ERROR&#8217;.</p>
<p><a href="http://saphr.ru/wp-content/uploads/lsmw_transformation_rules_06.png"><img class="alignnone size-full wp-image-2904" src="http://saphr.ru/wp-content/uploads/lsmw_transformation_rules_06.png" alt="LSMW Transformation" width="885" height="608" /></a></p>
<p>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.</p>
<p>Remain options:</p>
<p><strong>Transfer (MOVE)</strong> &#8211; copy value as is.</p>
<p><strong>Initial Value</strong> &#8211; setup default value for this type of field.</p>
<p><strong>No Action</strong> &#8211; do nothing.</p>
<h3>User-defined routines or custom ABAP translation rules</h3>
<p>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 :)</p>
<h3>Test conversions</h3>
<p>Once we&#8217;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>
<p>P.S. Here is also my video on Youtube how to do a basic LSMW project:</p>
<p><strong style="color: #ff9900;">Share this post with your SAP friends and colleagues. It won&#8217;t cost you anything but will motivate us to write more interesting content.</strong><br />
<!-- Begin MailChimp Signup Form --></p>
<style type="text/css">
	#mc_embed_signup{background:#fff; clear:left; font:14px Helvetica,Arial,sans-serif; width:100%;}<br />	/* Add your own MailChimp form style overrides in your site stylesheet or in this style block.<br />	 We recommend moving this block and the preceding CSS link to the HEAD of your HTML file. */<br /></style>
<div id="mc_embed_signup">
<form id="mc-embedded-subscribe-form" class="validate" action="https://saphcmsolutions.us3.list-manage.com/subscribe/post?u=9946caca159afc9a77502e9a5&;id=ba2e54e4b1" method="post" name="mc-embedded-subscribe-form" novalidate="" target="_blank">
<div id="mc_embed_signup_scroll"><label for="mce-EMAIL">Stay tuned for our best practices and top-notch advice</label><br />
<input id="mce-EMAIL" class="email" name="EMAIL" required="" type="email" value="" placeholder="email address" /><br />
<!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups--></p>
<div style="position: absolute; left: -5000px;" aria-hidden="true"><input tabindex="-1" name="b_9946caca159afc9a77502e9a5_ba2e54e4b1" type="text" value="" /></div>
<div class="clear"><input id="mc-embedded-subscribe" class="button" name="subscribe" type="submit" value="Subscribe" /></div>
</div>
</form>
</div>
<p><!--End mc_embed_signup--></p>