How To Populate Sets with a Recording

Jimbo's picture

http://tinmanphotoblog.com/wp-content/uploads/2014/12/14-574-post/AS1R5355-Edit-2.jpg|http://i.dailymail.co.uk/i/pix/2013/09/01/article-0-1B8FFD81000005DC-736_634x471.jpg|http://ayay.co.uk/backgrounds/animals/goats/Mountain-Goat-Kids.jpg|https://media-cdn.tripadvisor.com/media/photo-s/01/f6/26/67/mountain-goat-kids-jumping.jpg|http://www.outdoorphotographer.com/blog/wp-content/uploads/2014/01/Mountain-Goat-Kids-Jumping-by-Tin-Man-Lee.jpgSets are a great way to group objects together for accounting purposes and for custom reporting. Understanding sets can seem daunting at first, but it is important to understand that a set is nothing more than a list of individual values that point to objects within SAP.

At first glance it would seem that the easiest way to populate a set is by manually entering in countless records one after another. While it is possible to trick a recording into loading screens full of records into a Set, the simplest way by far is by creating a recording that shifts the contents of the set down and inserts one record at the top. This recording can be called once for each record in the source data such that all records are eventually loaded in reverse order into the Set. The order of the Set contents probably doesn't matter, but if it does then the source data should be reversed so that is loaded in reverse of the desired order; this will make more sense once the operation of the recording is understood.

Start by creating a new LSMW object. In the initial LSMW screen click the new button and populate the fields according to the LSMW project and sub-project in the target development system.

In the Change Object Attributes screen choose Batch Input Recording and then click the "Recordings: Overview" button.

Click on the "New Recording" button and then name the recording after the transaction that will be used. Describe the recording accordingly so that future developers will know what the recording does. Press "Enter" or click the check box and then tell LSMW what transaction will be used. In this case the transaction is "GS02".

Assuming that the set has already been created, type the name of the set to be populated. Press "Enter".

This is where the magic of this particular recording will come into play. Click the "Insert Row" button. The cursor is on the first line, so the first line and everything below it will be shifted down one row and leave a blank line at the very top.

Now populate the first line with source data. Be sure to touch each of the three fields to be populated: From Value, To Value and Short Text. Fields that are not touched by the cursor will not appear in the recording. After touching all of the desired fields, click the "Save" button.

The recording is now created, but not saved. Each field that was touched needs a field name and a description. LSMW can populate field names and descriptions automatically when the "Default All" button is clicked. Add an "X" to the first set of To, From and Title fields--these are the same fields before the "Insert Row" button has been pressed. These fields should be left blank until after the "Insert Row" button has been pressed. Be sure to save the recording by clicking the "Save" button.

Be sure to put in the name of the newly created recording before saving the LSMW object attributes. The recording is now the basis of the LSMW object.

In the Change Source Structures screen create a new structure. It is good form to use the name of the transaction followed by the letter "S" to denote the source data. This makes it easier to write custom ABAP in the LSMW later.

In the Change Field Mapping and Conversion Rules screen add the four desired fields to the Source Structure that was created in the last step. Click on the source and then click on the New Field button. Populate the field name and the description of the field. Note that the field created goes directly under the cursor. Field order isn't necessarily important, but it is good form to align the field names with the actual source data.

In Change Field Mapping and Conversion Rules assign the fields from the source data to the fields in the recording. Click the field and then click the "Source Field" button. When the list of fields appears double-click the desired source field and LSMW will automatically write in the ABAP code that populates the recording field with the desired source field. Repeat this process for each field. Save the newly created rules by clicking the "Save" button.

In the Change Structure Relationships screen the Source structure is already related to the recording. Simply click the "Save" button and then back out of this screen.

In Specify Files add a new source file to the Legacy Data line. Click on "Legacy Data" and then click the "New File" button. Type the path to the file and ensure that the settings under File Contents matches the source file.

It is good form to use Tab-delimited text with headers. Not all fields are mandatory; those fields not represented will simply be left blank when the recording is run.

All that remains is to Read in the data, Convert the data and then run the Batch that is created. It's that simple.

Download the project

For the purposes of recycling code the whole project is available at the link below. This includes the recording and ABAP code.
LSMW_SETS

http://tinmanphotoblog.com/wp-content/uploads/2014/12/14-574-post/AS1R5355-Edit-2.jpg|http://i.dailymail.co.uk/i/pix/2013/09/01/article-0-1B8FFD81000005DC-736_634x471.jpg|http://ayay.co.uk/backgrounds/animals/goats/Mountain-Goat-Kids.jpg|https://media-cdn.tripadvisor.com/media/photo-s/01/f6/26/67/mountain-goat-kids-jumping.jpg|http://www.outdoorphotographer.com/blog/wp-content/uploads/2014/01/Mountain-Goat-Kids-Jumping-by-Tin-Man-Lee.jpg