Wednesday, November 3, 2010

Using routines and exception handling in LSMW

Step1: Use the transaction code LSMW to upload the data using Legacy System Migration Work Bench. Here in this scenario describes routines and exception handling.

Click execute button.

Step2: The following screen appears.

Save and click BACK button.

Step3: Select step1 ‘Maintain Object Attributes’ and Execute.

Provide the Object and Method details as shown below.

Save and click BACK button.

Step4: Now select step2 ‘Maintain Source Structure’ and click execute button.

Step5: Place the cursor on Source structure and click create. Provide name and description

Save and click BACK button.

Step6: : Select step3 ‘Maintain Source Fields’ and click execute button.

Press create button and provide details for Field Name, Field Description and Field Length.

Step7: Enter all required fields as shown below.

Save and click BACK button.

Step8: : Select step4 ‘’Maintain Source Relations’.

Save and click BACK button.

Step9: Select step5 ‘Maintain Field Mapping and Conversion Rules’.

Step10: Place the cursor on the desired field and click fixed value button on application tool bar. Choose the valid value in the VALUE field. And click ENTER button.

Now the screen appears like this.

Step11: Place the cursor on the field for which we want to translate and click the RULE on the Application tool bar. Select Translate radio button.

Step12: Provide name and press enter.

Step13: Now perform statement appears in the field as shown.

Here, SKIP_TRANSACTION function is used to control not to create ERRORNESS record.

Step14: Select step6 ‘Maintain Fixed Values, Translations, User-Defined Routines’ and execute.

Double click on G_MEINS. Then the following screen appears. Made the changes in length as per our requirement.



Step15: Now, go to TRANSLATION VALUE tab strip.

Step16: Select step7 ‘Specify Files’. Create a test file with the same structure as defined earlier.

Step17: Select step8 ‘Assign Files’ and click execute.

Assign File Structure to Source Structure.

Step18: Select step9 ‘Read Data’ and click execute.

Click Execute button again.

Click BACK button and return to main screen.

Step19: Select step10 ‘Display Read Data’ and execute.

Select .

Step20: Select step11 ‘Convert Data’ and execute.

And click the execute button again.

Click BACK button and return to main screen.

Step21: Select step12 ‘Display Converted Data’ and execute.

And press ENTER.

Click BACK button and return to main screen.

Step22: Select step13 ‘Start Direct Input Program’ and execute.

Click ENTER.




Validations in LSMW

Requirement: Validation in LSMW. Here we are taking a simple example to change the customer telephone number. Do the validation in LSMW to check whether the provided customer is valid or not. We will handle the Validations in 5th step (Maintain field mapping and conversion rules) of LSMW. If the customer is invalid collect the record to the error internal table and skip the further processing of the record. Download all the error customers into an excel file once the conversion of the all the customers is done. This example mainly will help you to write the custom code in LSMW.

Create the Project, Subproject and Object in the LSMW Transaction.

1. Maintain Object Attributes

Do the recording to change the customer telephone number.

2. Maintain Source Structures

Create the source structure - CUST_DETAILS

3. Maintain Source Fields

Maintain the source fields as per the input file. Here we are taking only Customer and Telephone number as our flat file contains only those two fields shown blow.

4. Maintain Structure Relations

5. Maintain Field Mapping and Conversion Rules

We will do the validation in this step. Execute this step. Go to the change mode.

Click on the button (layout) and select all the check boxes.

Double click on Global Data (this block is like Global data in normal ABAP programs), will get an ABAP editor. Declare the required fields and Internal tables here as shown below.

Validate the customer:

Double click on BEGIN_OF_TRANSACTION block (this block will trigger for every new transaction), and write the validation code as shown below.



We can validate the given customer by checking the table KNA1. If the customer is invalid, then append the Customer to the error internal table with appropriate message. Skip further execution of the record using the Global function skip_transaction (Insert->Global Function-> skip_transaction). This statement will skip the current record and goes to the next record.

Download the Error records:

Double click on the END_OF_PROCESSING block (this block will trigger after conversion of all the transactions), and write the code to download and display the error records as shown below.

The error records will download to the specified file path when we execute the convert data step and same will be displayed.

6. Specify Files

Specify the input file

7. Assign Files

Assign the file and save.

8. Read Data

Execute the read data step to read the input file data.

9. Display Read Data [optional]

10. Convert Data

The validations will take place when we execute the convert data step. The error records will download to the specified file path if there any and same will be displayed here as shown below.

And the snap shot downloaded excel wile is

11) Further continue with the processing (Create batch input session and Run batch input Session) to update the valid customers.

Uploading long text for Material Master 'Purchase Order Text"

Requirement: Loading the purchasing long text for the given materials.

The flat file in our example contains the long text for multiple materials. The header record contains the material information (Material Number and Text ID) and is identified by the starting character ‘H’. The item records contain the long text to be uploaded for the material and the starting character ‘I’ identifies the record. See the screenshot below:

Create a Project, Subproject and Object in the LSMW transaction

1. Maintain Object Attributes

Select the standard direct input method

Object - 0001

Method - 0001

2. Maintain Source Structures

Create two structures one for Header and one for Item. The item structure will be at lower level for the Header

3. Maintain Source Fields

Define the fields as per the flat file structure. In both the structures the first field must be identifier. Create the identifier field of character 1 and specify the identifying field content 'H' for header structure and 'I' for item stricture as shown below.

Here the Field LINE of item structure is char 132, so each text line from the input file must be less than or equal to the length 132.

4. Maintain Structure Relations

Assign the header source structure to the Header target structure and Item source structure to Item target structure.

5. Maintain Field Mapping and Conversion Rules

Map the source fields to the target fields

Header mapping

For NAME and ID map the source fields MATNR and TEXID respectively.

For OBJECT and SPRAS pass the constants. To enter a constant value for any field, place the cursor on the field and enter a value by clicking on constant button available in the application toolbar.

Item mapping

For TEXTFORMAT pass the constant '*' and for the TEXTLINE map the input field LINE of the ITEM structure.

Save the changes.

6. Specify Files

Place the cursor on Legacy data and click create button

Enter the input file details

Select the Radio button 'data for Multiple source structures' as we are populating the header and Item structures from the same input file

Select the delimiter 'Tabulator', if the fields in the input file are separated by tab.

7. Assign Files

Assign the input file to both the structures

8. Read Data

Execute the Read data.

9. Display Read Data [optional]

10. Convert Data - Execute the convert data

11. Display Converted Data [optional]

12. Start Direct Input Program - Execute this step.

Result: The Long text will be updated for the given Materials

Transaction MM03, View - Purchase order text

Handling multiple recordings in LSMW

This example is related to PO output type creation using batch input method.

In this example, we need to handle more than one recording, because based on message transmission medium screens will change.

In this example, have created two separate recordings when message medium is ‘1’ and message medium is ‘6’ respectively.

1. LSMW project.

2. Maintain object attributes.

Here we need to create two separate recordings one for medium type is printer and one for medium type is EDI as shown below.

Select BACK button and in batch input recording need to select more recordings as shown below.

Here initially only one recording will be displayed, then we need to add second recording manually as shown below.

3. Maintain source structure as shown below.

4. Maintain source fields.

5. Maintain structure relations as shown below.

6. Maintain field mapping and conversion rules.

Here we need to write code to handle recordings based on Message medium as shown below.

7. Specify files

And execute remaining steps.

Tutorials on SAP-ABAP

Adobe Interactive Forms Tutorials

Business Server Pages (BSP)

Userexits/BADIs

Web Dynpro for ABAP (Step by step procedure for web dynpro,Tutorials on Web Dynpro,)

ALV Tutorials

goodsites