Vous êtes sur la page 1sur 38

Kavitha .A.

DAY-5 CONTENTS

BDC & LSMW

¾ What is BDC or batch input

¾ BDC functions:

¾ BDC methods

¾ BDC techniques used in programs

¾ EXERCISE
ƒ call transaction method
ƒ call by session method

¾ BDC RECORDING

¾ LSMW

• SAP Data Migration with LSMW


• EXERCISE
• DEfine source structure
• Define target structure
• Field mapping
• Specify file: location of the source file
Kavitha .A.S

BATCH DATA COMMUNICATION

What is BDC or batch input

The Batch Input is a SAP technique that allows automating the input in transactions from
the NON-SAP environment to SAP environment. It lies on a BDC (Batch Data
commands) scenario.

BDC functions:

· BDC_OPEN_GROUP : Opens a session group

· BDC_CLOSE_GROUP : Closes a session

· BDC_INSERT : Insert a BDC scenario in the session

· The ABAP statement "CALL TRANSACTION" is also called to run directly a


transaction from its BDC table.

It runs the program RSBDCSUB in order to launch automatically the session. The session
management is done through the transaction code SM35.

The object itself is maintainable through the transaction SE24.

BDC methods:

Method Description Parameters


OPEN_SESSION Opens a session SUBRC (Return Code – 0 OK)

SESSIONNAME (Session to be created)


CLOSE_SESSION Closes a session None
RESET_BDCDATA Resets the BDC Internal None. Normally, for internal purpose…
Table...
BDC_DYNPRO Handles a new screen PROGNAME (Name of the program)

DYNPRONR (Screen Number)


BDC_FIELD Puts a value on the FIELDNAME (Name of the field)
screen
FIELDVALUE (Value to be passed)
CONSTRUCTOR Constructor - Initializes NODATA (No data character). The
NO_DATA constructor is called automatically when
the object is created.
RUN_SESSION Launches a session with None
RSBDCBTC
Kavitha .A.S

CALL_TRANSACTION Calls a transaction with MODE (Display Mode)


the current BDC Data
UPDATE (Update Mode)

TCODE (Transaction to be called)


BDC_INSERT Inserts the BDC scenario TCODE (Transaction to be called)
in the session

BDC techniques used in programs:

1) Building a BDC table and calling a transaction,

2) Building a session and a set of BDC scenarios and keeping the session
available in SM35,

3) Building a session and launching the transaction right after closing the
session.

EXERCISE

CALL TRANSACTION METHOD

Start the transaction SE38 and enter the program name.


Kavitha .A.S

Fill in the ATTRIBUTES screen with the TITLE, TYPE & STATUS.

Declare the tables being used in the program. Here the ZKA_EMP.
Then declare the internal table.

Now declare the BDC internal table using the syntax>


DATA: <bdc-int-tab> LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
Kavitha .A.S

Now call the function ‘UPLOAD’ which can upload the data from the non-sap
environment to the SAP environment. For that, Click on the PATTERN button and enter
the function name to be UPLOAD and click CONTINUE.

Now uncomment the word EXPORTING and FILENAME & FILETYPE.


Here the FILENAME is the path where the data is stored in the NON-SAP environment.
For Eg: Notepad.
Kavitha .A.S

Lets take the notepad to the NON-SAP environment and so create the data in the
Notepad.

The BDCDATA table has the following components.

1. PROGRAM – The screenpainter program for the corresponding table.


2. DYNPRO – The screenno.
3. DYNBEGIN – Just a flag set.
4. FNAM – The field name.
5. FVAL – The field value stored in the internal table.

Summary:
REPORT ZKA_BDC .

TABLES: ZKA_EMP.

DATA: ITAB LIKE ZKA_EMP OCCURS 0 WITH HEADER LINE.


DATA: BDCITAB LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
DATA: ITAB_COMMA LIKE ITAB OCCURS 0 WITH HEADER LINE.
Kavitha .A.S

CALL FUNCTION 'UPLOAD'


EXPORTING
* CODEPAGE = ' '
FILENAME = ' '
FILETYPE = ' '
* ITEM = ' '
* FILEMASK_MASK = ' '
* FILEMASK_TEXT = ' '
* FILETYPE_NO_CHANGE = ' '
* FILEMASK_ALL = ' '
* FILETYPE_NO_SHOW = ' '
* LINE_EXIT = ' '
* USER_FORM = ' '
* USER_PROG = ' '
* SILENT = 'S'
* IMPORTING
* FILESIZE =
* CANCEL =
* ACT_FILENAME =
* ACT_FILETYPE =
TABLES
DATA_TAB = ITAB
* EXCEPTIONS
* CONVERSION_ERROR = 1
* INVALID_TABLE_WIDTH = 2
* INVALID_TYPE = 3
* NO_BATCH = 4
* UNKNOWN_ERROR = 5
* GUI_REFUSE_FILETRANSFER = 6
* OTHERS = 7
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

LOOP AT ITAB.
WRITE:/ ITAB.
ENDLOOP.

LOOP AT ITAB.
SPLIT ITAB AT ',' INTO
ITAB_COMMA-EMPNO
ITAB_COMMA-EMPNAME
ITAB_COMMA-EMPPHONE
ITAB_COMMA-EMPID.
APPEND ITAB_COMMA.
CLEAR ITAB_COMMA.
ENDLOOP.

LOOP AT ITAB_COMMA.
BDCITAB-PROGRAM = 'ZKA_SCREENPAINTER'.
BDCITAB-DYNPRO = '0001'.
BDCITAB-DYNBEGIN = 'X'.
APPEND BDCITAB.
CLEAR BDCITAB.

BDCITAB-FNAM = 'ZKA_EMP-EMPNO'.
BDCITAB-FVAL = ITAB_COMMA-EMPNO.
Kavitha .A.S

APPEND BDCITAB.
CLEAR BDCITAB.

BDCITAB-FNAM = 'ZKA_EMP-EMPNAME'.
BDCITAB-FVAL = ITAB_COMMA-EMPNAME.
APPEND BDCITAB.
CLEAR BDCITAB.

BDCITAB-FNAM = 'ZKA_EMP-EMPPHONE'.
BDCITAB-FVAL = ITAB_COMMA-EMPPHONE.
APPEND BDCITAB.
CLEAR BDCITAB.

BDCITAB-FNAM = 'ZKA_EMP-EMPID'.
BDCITAB-FVAL = ITAB_COMMA-EMPID.
APPEND BDCITAB.
CLEAR BDCITAB.

ENDLOOP.

CALL TRANSACTION 'ZKA_TRNEMP' USING BDCITAB MODE 'A'.

Double click on the transaction code which will guide to the transaction code builder
Kavitha .A.S

Now SAVE, CHECK & ACTIVATE the program.


Click on the TEST button.
Kavitha .A.S

Click on TRANSFER button.

Thus the BDC-CALL TRANSACTION METHOD which is used to transfer the data
from the non-sap environment to the sap Environment.
Kavitha .A.S

BDC-CALL BY SESSION METHOD


Start the transaction SE38 and enter the program name.

Fill in the ATTRIBUTES screen with the TITLE, TYPE & STATUS.
Kavitha .A.S

Declare the tables being used in the program. Here the ZKA_EMP.

Then declare the internal table.

Now declare the BDC internal table using the syntax>

DATA: <bdc-int-tab> LIKE BDCDATA OCCURS 0 WITH HEADER LINE.

Now call the function ‘UPLOAD’ which can upload the data from the non-sap
environment to the SAP environment.

For that, Click on the PATTERN button and enter the function name to be UPLOAD
and click CONTINUE.
Kavitha .A.S

Now uncomment the word EXPORTING and FILENAME & FILETYPE.


Here the FILENAME is the path where the data is stored in the NON-SAP environment.
For Eg: Notepad.
Kavitha .A.S

The BDCDATA table has the following components.

6. PROGRAM – The screenpainter program for the corresponding table.


7. DYNPRO – The screenno.
8. DYNBEGIN – Just a flag set.
9. FNAM – The field name.
10. FVAL – The field value stored in the internal table.

Summary:
REPORT ZKA_BDC .

TABLES: ZKA_EMP.

DATA: ITAB LIKE ZKA_EMP OCCURS 0 WITH HEADER LINE.


DATA: BDCITAB LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
DATA: ITAB_COMMA LIKE ITAB OCCURS 0 WITH HEADER LINE.

CALL FUNCTION 'UPLOAD'


EXPORTING
* CODEPAGE = ' '
FILENAME = ' '
FILETYPE = ' '
* ITEM = ' '
* FILEMASK_MASK = ' '
* FILEMASK_TEXT = ' '
* FILETYPE_NO_CHANGE = ' '
* FILEMASK_ALL = ' '
* FILETYPE_NO_SHOW = ' '
* LINE_EXIT = ' '
* USER_FORM = ' '
* USER_PROG = ' '
* SILENT = 'S'
* IMPORTING
* FILESIZE =
* CANCEL =
* ACT_FILENAME =
* ACT_FILETYPE =
TABLES
DATA_TAB = ITAB
* EXCEPTIONS
* CONVERSION_ERROR = 1
* INVALID_TABLE_WIDTH = 2
* INVALID_TYPE = 3
* NO_BATCH = 4
* UNKNOWN_ERROR = 5
* GUI_REFUSE_FILETRANSFER = 6
* OTHERS = 7
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
Kavitha .A.S

ENDIF.

LOOP AT ITAB.
WRITE:/ ITAB.
ENDLOOP.

LOOP AT ITAB.
SPLIT ITAB AT ',' INTO
ITAB_COMMA-EMPNO
ITAB_COMMA-EMPNAME
ITAB_COMMA-EMPPHONE
ITAB_COMMA-EMPID.
APPEND ITAB_COMMA.
CLEAR ITAB_COMMA.
ENDLOOP.

LOOP AT ITAB_COMMA.
BDCITAB-PROGRAM = 'ZKA_SCREENPAINTER'.
BDCITAB-DYNPRO = '0001'.
BDCITAB-DYNBEGIN = 'X'.
APPEND BDCITAB.
CLEAR BDCITAB.

BDCITAB-FNAM = 'ZKA_EMP-EMPNO'.
BDCITAB-FVAL = ITAB_COMMA-EMPNO.
APPEND BDCITAB.
CLEAR BDCITAB.

BDCITAB-FNAM = 'ZKA_EMP-EMPNAME'.
BDCITAB-FVAL = ITAB_COMMA-EMPNAME.
APPEND BDCITAB.
CLEAR BDCITAB.

BDCITAB-FNAM = 'ZKA_EMP-EMPPHONE'.
BDCITAB-FVAL = ITAB_COMMA-EMPPHONE.
APPEND BDCITAB.
CLEAR BDCITAB.

BDCITAB-FNAM = 'ZKA_EMP-EMPID'.
BDCITAB-FVAL = ITAB_COMMA-EMPID.
APPEND BDCITAB.
CLEAR BDCITAB.
ENDLOOP.

In order to view the session, go to the transaction code SM35 ( Batch Input session
overview). Select the session name and click on PROCESS button.
Kavitha .A.S

The process starts and the data in the NON-SAP environment is uploaded to the SAP
environment.
Kavitha .A.S

If the session processes without any errors, then the session overview is completed and it
shows the status to be processed.
Kavitha .A.S

BDC RECORDING
Click on the RECORDING button in the SM35 ( BATCH INPUT SESSION
OVERVIEW) transaction or can directly put in the transaction code SHDB.

Click on the NEW RECORDING button and enter the recording name and the
transaction code and click on the START RECORDING button.
Kavitha .A.S

Give the field value and perform some operations and u can find each and every click on
the screen and the no. of screens processed with the date and the time.

Thus the BDC recording.


Kavitha .A.S

LSMW

The LSM (Legacy System Migration) Workbench is an R/3-based tool that supports You when transferring
1
data from non-SAP systems ("Legacy Systems") to SAP systems once or periodically.

The tool supports conversion of data of the legacy system in a convenient way. The data can then be
imported into the SAP system via batch input, direct input, BAPIs or IDocs.

Furthermore, the LSM Workbench provides a recording function that allows to generate a "data migration
object" in an entry or change transaction.

SAP Data Migration with LSMW


No ABAP effort are required for the SAP data migration. However, effort are required to map the data into
the structure according to the pre-determined format as specified by the pre-written ABAP upload program
of the LSMW.

The Legacy System Migration Workbench (LSMW) is a tool recommended by SAP that you can use to
transfer data once only or periodically from legacy systems into an R/3 System.

More and more medium-sized firms are implementing SAP solutions, and many of them have their legacy
data in desktop programs. In this case, the data is exported in a format that can be read by PC spreadsheet
systems. As a result, the data transfer is mere child's play: Simply enter the field names in the first line of the
table, and the LSM Workbench's import routine automatically generates the input file for your conversion
program.

The LSM Workbench lets you check the data for migration against the current settings of your customizing.
The check is performed after the data migration, but before the update in your database.

So although it was designed for uploading of legacy data it is not restricted to this use.

We use it for mass changes, i.e. uploading new/replacement data and it is great, but there are limits on its
functionality, depending on the complexity of the transaction you are trying to replicate.

The SAP transaction code is 'LSMW' for SAP version 4.6x.

For those with the older SAP version (4.7 and below), the data migration programs might not have been pre-
loaded.

The LSMW comprises the following main steps:

• Read data (legacy data in spreadsheet tables and/or sequential files).


• Convert data (from the source into the target format).
• Import data (to the database used by the R/3 application.

But, before these steps, you need to perform following steps :


Kavitha .A.S

• Define source structure : structure of data in the source file.


• Define target structure : structure of SAP that receives data.
• Field mapping: Mapping between the source and target structure with
conversions, if any.
• Specify file: location of the source file

EXERCISE

Call Legacy System Migration Workbench by entering transaction code LSMW.

. Every conversion task is grouped together as Project / Subproject / Object structure.


Create a Project called TR-EMP and a Subproject as KAVI-EMP and Object as EMP.
Kavitha .A.S

The main screen of LSMW provides wizard-like step-by-step tasks,. To complete your
data conversion, you need to execute these steps in sequence. Once a step is executed, the
cursor is automatically positioned to the next step.
Kavitha .A.S

Step 1: Maintain Object attributes


In this example, you will be updating the customer master records with the help of
recording a transaction (XD02). Choose radio button Batch Input Recording and click
on the recording overview icon to record the R/3 transaction.

Enter the Recording name with the short description and click on the OK button.
Kavitha .A.S

Enter the transaction code of the table corresponding to the screen.

Now click on the OK button and the recording starts. Start Recording and finally click on
the EXIT button.
Kavitha .A.S

Once the transaction is completed, R/3 records the flow of screens and fields and saves the information.
Note that the fields are populated with default values. The values you entered when you recorded the
transaction are set by default.

Note that if you have more fields in the recording than needed, you can remove them by

clicking ‘Remove Screen field’ icon.

Observe that the transaction-recording process stores field names in a technical format.
By pressing the F1 key on individual screen fields and then pressing the F9 key, the
system displays technical names.

Save your changes. When you go back to the initial screen, you will see that the initial
screen steps have changed. Since you want to import data via the BDC method, the
Direct Input and IDoc-related steps are hidden, as they are not relevant.
Kavitha .A.S

Step 2. Maintain Source Structures

Give a name and a description to the source structure

Step 3. Maintain Source Fields


In this step, you need to list what fields are present in the source structure. The easiest
way is to click on ‘Table Maintenance’ icon to enter Fieldname, Type and Length for
each field as shown
Kavitha .A.S

.Once after entering all the details u can fid the below screen.

Step 4: Maintain Structure Relations


Execute a step to ‘Maintain Structure Relations’. Since, there is only one Source and
Target Structure, the relationship is defaulted automatically.
Kavitha .A.S

Step 5: Maintain field mapping and conversion rules.

Now we need to do field mapping.


So click on EXTRAS Æ AUTO FIELD MAPPING.

If ypur fields in the source and the target are same then choose “MATCH FIELDAS WITH
IDENTICAL NAMES’ else CHOOSE ‘MATCH FIELDS WITH SIMILAR NAMES”.

Once all the fields are mapped, you should have an overview screen
Kavitha .A.S

Step 6: Maintain fixed values, translations, user-defined routines


You can also maintain re-usable translations and user-defined routines, which can be
used across conversion tasks. In this case, that step is not required.

Step 7: Specify files


In this step, we define how the layout of the input file is.

We need to double click “ ON THE PC FRONTEND’.

The input file is a [Tab] delimited with the first row as field names. It is present on my
PC (local drive) as C:/BDC-EMP wherein the delimiter is ‘comma’.
Kavitha .A.S
Kavitha .A.S

Step 8: Assign files


Execute step ‘Assign Files’ (Figure 15) and the system automatically defaults the
filename to the source structure

Step 9: Read data


In this step, LSMW reads the data from the source file (from your PC’s local drive). You
have the option to read only selected rows and convert data values to Internal format.
Kavitha .A.S

Step 10: Display read data


This step is optional. If required, you can review the field contents for the rows of data
read.
Kavitha .A.S

Step 11: Convert data


This is the step that actually converts the source data (in source format) to a target format.
Based on the conversion rules defined, source fields are mapped to target fields.
Kavitha .A.S

Step 12: Display Converted data


Again this is an optional step to view how the source data is converted to internal SAP
format (Figure 18).

Step 13: Create batch input session


Once the source data is converted in an internal format, you can create a batch session to
process updates (Figure 19).
Kavitha .A.S

Step 14: Run Batch Input Session

You can execute the BDC session by Run Batch input session. Executing a batch input session is a
standard SM35 transaction for managing BDC sessions. Once you have successfully executed the batch
input session, the customer master records are updated in the system. You can confirm this by viewing the
customer master records (XD03).

In order to view the session, go to the transaction code SM35 ( Batch Input session
overview). Select the session name and click on PROCESS button.
Kavitha .A.S

The process starts and the data in the NON-SAP environment is uploaded to the SAP
environment.
Kavitha .A.S

If the session processes without any errors, then the session overview is completed and it
shows the status to be processed.
Kavitha .A.S

Of all the methods used for data migration like BDC, LSMW , Call Transaction
which one is used most of the time?
How is the decision made which method should be followed? What is the procedure
followed for this analysis?

All the 3 methods are used to migrate data. Selection of these methods depends on the scenario, amount of
data need to transfer. LSMW is a ready tool provided by SAP and you have to follow some 17 steps to
migrate master data. While in BDCs Session method is the better choice because of some advantages over
call transaction. But call transaction is also very useful to do immediate updation of small amout of data. (In
call transaction developer has to handle errors).
SO Bottom line is make choice of these methods based of real time requirements.

These methods are chosen completely based on situation you are in. Direct input method is not available for
all scenario, else, they are the simplest ones. In batch input method ,you need to do recording for the
transaction concerned. Similarly, IDoc, and BAPI are there, and use of these need to be decided based on
the requirement.

Try to go through the some material on these four methods, and implement them. You will then have a fair
idea about when to use which.

Vous aimerez peut-être aussi