Sie sind auf Seite 1von 48

Advanced LSMW Tips

and Tricks for Data


Conversion and
Migration During Your
R/3 Enterprise Upgrade
Mitresh Kundalia
Quality Systems & Software
2005 Wellesley Information Services. All rights reserved.
What Well Cover

Data conversion using LSMW


Tips and tricks for getting the most out of LSMW
Wrap-up

2
What Well Cover

Data conversion using LSMW


Tips and tricks for getting the most out of LSMW
Wrap-up

3
Data Conversion Using LSMW

LSMW is one of SAPs best data conversion tools


Data conversion using standard interface programs
! Available for most R/3 master and transactional data
! e.g., Customer master, Material master

! e.g., FI documents, Sales documents,


Purchasing documents
Data conversion using transaction recordings
! You record an SAP transaction, updating only required fields
! LSMW runs recording with data from source system

4
Data Conversion Using LSMW (cont.)

LSMW features
! No need for ABAP programming skills
! Most conversion and migration tasks can be accomplished
with standard functionality
! With little ABAP coding, you can use LSMW for more
complex data conversion activities
! Provides data reformatting options
! Simple mapping to complex data reformatting rules

! Can be used for conversion tasks against production data


! Not just for legacy data!

So, LSMW is the right choice for most conversion


and migration
! LSMW is SAPs preferred Data Conversion Tool
5
LSMW Load Process Overview

Legacy System or R/3 System

PC/Appl. Server Tab delimited Fixed record

Conversion Rules
Read Data
1 : 1 Translation
Interval Translation Read Data
Initial value
Constant
Assign Source field
Prefix/Suffix
Concatenate Converted Data

SAP R/3 System

Batch Input Direct Input IDocs

6
What Well Cover

Data conversion using LSMW


Tips and tricks for getting the most out of LSMW
Wrap-up

7
Limitations of Data Conversion Using LSMW

Typical LSMW limitations


! The Transaction Recording has to follow the pre-fixed screens
and fields sequence
! Flexibility is restricted and the input data has to strictly
follow the structure layout
! Calling different screens not allowed
! e.g., calling different screens depending on the data
content is not allowed
However ...
! Did you know that you can still build in enough flexibility to
use LSMW for more complex data conversion requirements
with a little ABAP?

8
LSMW Tips and Tricks

LSMW provides features for logical processing


! By inserting only a small amount of code in LSMW, you can
avoid writing complex ABAP programs
Examples of how functional team members can tap into
advanced LSMW features:
! 1 FI Documents Header and Multiple Lines
! Dealing with varied document data

! 2 If then else processing


! Dealing with conditional processing

! 3 Variable Number of Lines for Documents


! Dealing with an unknown number of line items

9
1 FI Documents Multiple Accounting Lines

Scenario upload FI documents with multiple


accounting items
! Typical solution
! Create a batch recording (transaction FB01 or F-02) to
enter the FI document
! Create data file with fixed structure layout

! Drawback to the typical solution


! Number of account line items have to be fixed and are
known in advance
! Will not work if each document has multiple account lines

" You may end up writing multiple LSMWs for example,


one LSMW for two accounting lines, another for three
accounting lines, etc.
10
1 FI Documents Multiple Accounting Lines (cont.)

LSMW Trick: Use standard object 0100 to post


FI documents
! Standard Object
! Object 0100 Financial documents
! Method 0000
! Program Name RFBIBL00
! Program type B Batch Input
! Define two structures and a key field
! Header structure for FI document header
! Detail structure for account line items
! Define key field (Doc_No) for linking header and line items
! Define two input files for the two structures

11
1 FI Documents Multiple Accounting Lines (cont.)

Object Attributes
Standard Object
! 0100 Financial
Documents
! Method 0000
! Program Name
RFBIBL00
! Program type
B Batch Input

12
1 FI Documents Multiple Accounting Lines (cont.)

Define two structures


! Header structure for FI
document header
! Define source fields
for header structure
! Detail structure for
line items
! Define source fields
for detail structure
! Define key field for linking
header and detail
structures

13
1 FI Documents Multiple Accounting Lines (cont.)

Maintain structure relations


! BBKPF Header
! BBSEG Line Items
! BGR00 BI Session

14
1 FI Documents Multiple Accounting Lines (cont.)

Assign and specify source files


! Header file with FI document header information
! Detail file with FI line Items

15
1 FI Documents Multiple Accounting Lines (cont.)

Data files
! Header file with FI document header information
! Detail file with FI line Items
! Document Number is the key field to join two files together

16
2 If Then ... Else Conditional Processing

Scenario update the rows only if the data meets


specific conditions
! For example
! You are using LSMW to update posting periods using
transaction OB52
! Posting periods are maintained in table T001B. However, in
addition to posting periods for financials, T001B table also
has data records for SPL and CO-PA
! You are using the data records from T001B

! To update posting periods, you want to ignore records


with account type C or G

17
2 If Then ... Else Conditional Processing (cont.)

Maintain posting periods


! Posting periods are maintained by transaction OB52
! Allowed posting periods can be maintained for account types
! e.g., A Assets, D Customers, K Vendors, S G/L accounts

Txn
OB52

18
2 If Then ... Else Conditional Processing (cont.)

Maintain posting periods (cont.)


! Technically, the posting periods are stored in Table T001B
! In addition to FI posting periods, T001B also stores SPL
posting periods

Txn
SE16

19
2 If Then ... Else Conditional Processing (cont.)

Scenario LSMW to update posting periods


! You want to use LSMW to update posting periods
! For example:

" Close the current posting period

" Open the next posting period

! You will create an LSMW project with transaction recording for OB52
! The data records for input file are prepared from T001B table
! Transaction OB52 wont accept account type G
Txn
OB52

20
2 If Then ... Else Conditional Processing (cont.)

Scenario if ... then ... else conditional processing


! Typical solution
! Create an input file with only those rows that meet the
specific conditions
! Drawback
! Preparing the input file is cumbersome and
time consuming
" Prepare an Excel file with all records (SE16 > T001B)

" Filter out rows which do not meet criteria (manually


remove records with account type G)
" Save the input file as text file

21
2 If Then ... Else Conditional Processing (cont.)

LSMW trick SKIP_RECORD or TRANSFER_RECORD


features
! SKIP_RECORD
! Ignores the input record for further processing

! You could use the SKIP_RECORD feature if the input data


does not meet specific criteria
! TRANSFER_RECORD
! Forwards the input row for further processing

! TRANSFER_RECORD is a default action

22
TRANSFER_RECORD and SKIP_RECORD

Read Data Read Data

TRANSFER_RECORD SKIP_RECORD

Converted Data Converted Data

23
2 If Then ... Else Conditional Processing (cont.)

LSMW trick
! Create a transaction recording and map fields from the source
structure, as usual
! For example, record transaction OB52 and create
Solution
recording OB52_REC
! Maintain field mappings from source data file, as usual

! __END__OF__RECORD__ allows you to do additional data


processing after all the fields of the record are mapped
! Use SKIP_RECORD or TRANSFER_RECORD in the section
__END__OF__RECORD__

24
2 If Then ... Else Conditional Processing (cont.)

LSMW trick (cont.)


! Double-click on Maintain field mapping and rules
! Click on Extras

Solution
! Click on Display variant

! Choose Processing points checkbox

! Review the _END_OF_RECORD_ section

" By default, coding is set as TRANSFER_RECORD

" Double-click on Coding and write a simple code with


SKIP_RECORD or TRANSFER_RECORD

25
2 If Then ... Else Conditional Processing (cont.)

26
2 If Then ... Else Conditional Processing (cont.)

Read and convert data


! Say that your input file has 10 rows, out of which 2 records
have account type C or G
! Read Data reads all records from input file, i.e., 10 records
! Convert Data converts only 8 records that meet the
specific criteria


Solution
Thus you avoided having to massage the input data file

27
2 If Then ... Else Conditional Processing (cont.)

Did you know?


! You dont need developer access to write these small
ABAP routines
! This is one of the advantages of LSMW: Even functional
analysts can tweak the processing logic without heavily
relying on ABAPers

28
3 Variable Number of Order Items

Scenario
! You want to update all line items for specific Sales Orders,
but you dont know how many line items there are
! i.e., there are a variable number of lines

Typical solution
! Create an input file with specific sales order numbers and all
line items for those orders
! Drawback:
! You first have to collect all orders and items in one file

" i.e., run SE16 twice once to retrieve the sales


order headers and once to retrieve the line items
for those orders

29
3 Variable Number of Order Items (cont.)

Manual steps involved in preparing input file


11! Prepare a data file with Sales Order Numbers
22! For all these Sales Order Numbers, get the Line Item Numbers
33! Use LSMW to update Sales Order Line Items

Prepare a file Use LSMW


Input file with with
with Order Number and Transaction Recording
Sales Order Item Numbers (VA02 using
Numbers (use SE16 on VBAP) order and item number)

11 22 33
Step 2 is the most time consuming!

30
3 Variable Number of Order Items (cont.)

Manual steps involved in preparing input file (cont.)


! Prepare a data file with Sales Order Numbers
! For all these Sales Order Numbers, get the Line
Item Numbers
Sales Order Item Number
(VBAP-VBELN) (VBAP-POSNR)

11 10001 10
Sales Order 10001 20
(VBAK-VBELN) 22 10001 30
10001 10013 20

10013 10013 30
10013 50
10024
10013 70
10025
10024 20
10025 40
10025 50
31
3 Variable Number of Order Items (cont.)

Typical LSMW conversion


! Use Transaction Recording with VA02

33
VA02
Transaction
Recording

Assign Order
Number from
Source data file

Assign Item
Number

Change Plant to
1000
32
3 Variable Number of Order Items (cont.)

Drawback with typical LSMW conversion


! Preparing the input file with Order Number and Item
Number is cumbersome and time consuming
Issue

Prepare a file Use LSMW


Input file with
with
with Transaction Recording
Order Number and
Sales Order (VA02 using
Item Numbers
Numbers Order and Item Number)
(Use SE16 on VBAP)

11 22 33

I wish I could use a


file with just the
Sales Order
Numbers
33
3 Variable Number of Order Items (cont.)

LSMW trick
! Use an input file with just Sales Order Numbers
! Within LSMW, loop through the Sales Order item table (VBAP)
and use TRANFER_RECORD multiple times

SELECT POSNR
INTO VA02_REC-POSNR
FROM VBAP
WHERE VBELN = VA02S-ORDERNO.
TRANSFER_RECORD
ENDSELECT.
Solution
34
3 Variable Number of Order Items (cont.)

35
3 Variable Number of Order Items (cont.)

36
3 Variable Number of Order Items (cont.)

How does it work?


! Use input file with just Sales Order Numbers
! The code gets the item numbers and creates data records;
it repeats as many times as there are items for the order
! The code first converts the Sales Order Number in SAPs
internal format
" SO# 12345 is internally stored as 0000012345

" Use function module


CONVERSION_EXIT_ALPHA_INPUT to convert
! It loops through VBAP table for this sales order

" Gets the Item Number

" Assigns Item Number to target VA02_REC-POSNR

" Transfers this data row for further processing


37
3 Variable Number of Order Items (cont.)

Extended scenario
! You want to update all line items for specific Sales Orders,
which are not shipped yet
Challenge
! Preparing an input file with Sales Order and Item Number
! For example:
! Prepare a data file with Sales Order Numbers
(SE16 on VBAK)
! Based on Sales Order Numbers, get the Item Numbers
(SE16 on VBAP)
! Based on Sales Orders and Item Numbers, get Item Status
(SE16 on VBUP)
! Prepare an Input file with Sales Order and Item Numbers
38
3 Variable Number of Order Items (cont.)

Manual steps involved in preparing input file


! With specific Sales Orders and Items only
SO# Item Dlvy
(VBAP- # Status
VBELN)
Sales Order Item No (VBAP- (VBUP- Sales Order Item No
POSNR) LFSTA)
(VBAP- (VBAP- (VBAP- (VBAP-
VBELN) POSNR) 10001 10 C
VBELN) POSNR)
Sales Order
10001 10 10001 20 B 10001 20
(VBAK-
VBELN) 10001 20 10001 30 C 10013 20
10001
10001 30 10013 20 A 10013 50
10013 10013 20 10013 30 C 10013 70
10024 10013 30 10025 50
10013 50 A
10025 10013 50
10013 70 A
10013 70
10024 20 C
10024 20
10025 40 10025 40 C

10025 50 10025 50 B

39
3 Variable Number of Order Items (cont.)

LSMW trick
! Use an input file with just Sales Order Numbers
! Within LSMW:
! Loop through Sales Order Item Table (VBAP), Get Item
Numbers
! Find the Delivery Status from VBUP Table

! If Delivery Status <> Complete

" Use TRANSFER_RECORD

Solution
40
3 Variable Number of Order Items (cont.)

41
3 Variable Number of Order Items (cont.)

Another scenario
! You want to update account assignments of all line items for
specific Sales Orders; variable number of items

Solution

42
LSMW Tips and Tricks

Flexibility is restricted for LSMW transaction recordings


However, you can still add enough flexibility to leverage
LSMW for more complex data conversion requirements
LSMW can be used in many more situations than you
might think possible

43
What Well Cover

Data conversion using LSMW


Tips and tricks for getting the most out of LSMW
Wrap-up

44
Resources

LSMW on the SAP service marketplace


! http://service.sap.com/LSMW
! Requires login credentials to the SAP Service Marketplace
" Detailed information and literature
" Sample examples and exercises

OSS component BC-SRV-DX-LSM


LSMW papers published by me
! Fast Data Conversion, Migration and Updates for Functional
Analysts with LSMW (SAP Financials Expert,
July/August 2003)
! Mass Changes with LSMW: An Easier Method for Complex
Requirements (SCM Expert, July 2004)

45
7 Key Points to Take Home

LSMW is one the most flexible data conversion tools


LSMW supports data conversion using standard SAP
objects or by recording your own transactions
You can use standard SAP object 0100 Financial
Documents to post FI documents
! Create two structures/files header and accounting items
LSMW is designed for functional team members
! Lets functional team visually define conversion rules to
reformat and map source data without ABAP

46
7 Key Points to Take Home (cont.)

With a little ABAP code, you can infuse a lot of flexibility


into LSMW data conversion
! e.g., retrieving last years object numbers and conditionally
extending to current year
You can use LSMW to update all line items of Sales
Orders by just preparing a data file with Order Numbers
! Preparing one with Item Numbers is cumbersome as well
SKIP_RECORD and TRANSFER_RECORD enable
conditional processing
! SKIP_RECORD skips the data record for any more
processing and TRANSFER_RECORD forwards the data
record for further processing

47
Your Turn!

Questions?

How to contact me:


Mitresh@QSandS.com
48

Das könnte Ihnen auch gefallen