Joyjit Ghosh, Kolkata.
To do error handling in LSMW object we can write validation logic in step “5 Maintain Field Mapping and Conversion Rule”. All custom codes written in this section will be part of the conversion program once we generate it.
Following steps are required for error handling:
- Define an internal table to store all error messages
- Write logic to validate the data and populate the error table when validation fails
- Display error messages as part of conversion program output
All these steps should be performed under step “5 Maintain Field Mapping and Conversion Rule” from transaction LSMW.
Step 1: Define an internal table to store all error messages
In __GLOBAL_DATA__ section define the internal table that will store the error messages.
Step 2: Write logic to validate the data and populate the error table when validation fails
Now write validation logic for the fields those we want to validate. If validation fails then populate the error table and after that call the macro “SKIP_TRANSACTION” so that this error record can be skipped and control will go to next record in the file.
Step 3: Display error messages as part of conversion program output
Now at __END_OF_PROCESSING__ section write logic to display the error table.
After writing the above steps, check the syntax of the custom code by clicking the appropriate button () on application toolbar. It will display a pop-up screen where we need to press ‘Yes’ button.
If everything is OK then it will display message that conversion program is regenerated successfully.
After this follow the LSMW steps like “7 Specify Files”, “8 Assign Files”, “9 Read Data”, “10 Display Read Data”. And lastly perform the step “11 Convert Data” where SAP actually executes the validation logic (written in step “5 Maintain Field Mapping and Conversion Rule”) as part of conversion program. And display the error messages those are generated due to error handling.
Output: