Load Material Long Texts Using a Recording

Jimbo's picture

http://www.apogeephoto.com/oct2013/Long_photos/rubbing-off-goat-mtn-goats_5392.jpg|http://www.wakeolda.com/Photos/mtevans99/goat_climbing_2.jpg|http://bloximages.chicago2.vip.townnews.com/missoulian.com/content/tncms/assets/v3/editorial/2/95/295319a2-dd10-11e2-aaa0-0019bb2963f4/51c8b1d9b08cf.image.jpg|http://ngm.nationalgeographic.com/u/TvyamNb-BivtNwcoxtkc5xGBuGkIMh_nj4UJHQKuorjj2yrzzTsBkwgD8q53LHYCkF7IMbQbjmJgWA/|http://www.maxingout.com/images/100%20update/big-horn-goat.jpg|http://cache2.allpostersimages.com/p/LRG/28/2806/OUCOD00Z/posters/edwards-walter-meayers-close-view-of-a-goat-with-long-horns.jpgLoading long texts can be a daunting task, but using a recording can make the task very easy. There are plenty of other solutions (Saplicity and SAVE_TEXT), but a recording is a simple and clean solution to an otherwise cumbersome mess.

In order to load the Long Texts using a recording, it is necessary to break the text into multiple 72-character chunks and then load each line one after the other. The first chunk will go into an empty editor screen and then each subsequent chunk will be appended to the end by simply running the recording again.

Start by creating an LSMW Object and then setting the attributes to be a recording. In the recording screen, create a recording that calls the MM02 transaction and then step through it like this.

Put in the number of a sample material and then select "Basic View". Press Enter to go to the Basic View of the material.

On the Basic View view, click the button shown here and then select the view that has the Long Texts that will be edited; for this example, the Purchase Order Texts are selected. If there is another Long Text to be loaded, be sure to build the recording accordingly.

The field that appears in the screen to hold long texts cannot be accessed by recording, so the text editor will be used to load the long texts. Each line in the text editor is a field that can be accessed by LSMW as a recording, but first it is necessary to position the cursor after the very last line of the existing text (which is blank in the case of the first line).

Click on Edit → Position Cursor and then type "99999" for the line number. This will position the very last line at the top of the text editor and the second line will be the next available blank line.

Type some text in the second line of the text editor as shown below. Be sure that it is on the second line and not the first. Do not worry about having a blank line at the top of the Long Text; SAP automatically rolls the text up so as to ignore the blank line.

Now back out of the text editor by pressing F3 (or clicking the Back arrow). Be sure to click the "Yes" button to ensure that the text that was just added is stored temporarily in memory.

Press F3 again and click the "Yes" button to save the material and create the recording. The hard work is finished.

Click the "Default All" button (circled below). Note that the second line of the text editor is referred to by the system as TXLINE_03.

Now step through the creation of the LSMW Object as usual and be sure to add a field on the import file big enough to hold the Long Text. For this example, there is only a 999-character LONGTEXT field, but multiple lines can be read into LSMW and concatenated later if the source data is longer than that.

Adding a snippet of code to populate all of the necessary fields is a snap. The first line is added to the field of the recording and then the transfer_record and transfer_transaction statements are called so that all the data added will be sent to the Converted Data file.

Then the ABAP code steps through the remainder of the field in 72-byte chunks.

MM02PLT-MATNR = MM02S-MATNR.
MM02PLT-KZSEL_01 = 'X'.  "Make sure that "Basic Data" is selected.
MM02PLT-WERKS = MM02S-WERKS.
MM02PLT-TXLINENR = '99999'.  "Show this as the first line.
*** Commit the first 72 characters ***
MM02PLT-TXLINE_03 = MM02S-LONGTEXT+0(72).
transfer_record. transfer_transaction.

*** Loop through the LONGTEXT in 72-character chunks. ***
while not MM02S-LONGTEXT co space.
  SHIFT MM02S-LONGTEXT by 72 places left.
  MM02PLT-TXLINE_03 = MM02S-LONGTEXT+0(72).
  if not MM02PLT-TXLINE_03 co space.
    transfer_record. transfer_transaction.
  endif.
endwhile.

In this manner, the Long Text from the source data is broken into 72-character chunks and loaded as appended text one chunk at a time. The end result will look something like this; note the original line of text is still there as all new text was simply appended to what was there before.