Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

bdc

Former Member
0 Likes
590

hi, I am new to BDC

please help me with some sample programs on BDC.

Also relevant documentation of the same.

thanks,

hema.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
534

hi,

refer this, will guide u.

LSMW IS JUST A TOOL TO GET THE DATA FROM A LEGACY SYSTEM.

IN BDC WE HAVE 2 WRITE THE CODE AND CALL THE REQUIRED METHOD

THATS IT. IN FUNCTIONALITY PERSPECTIVE THERE IS NO

DIFFERENCE.

LSMW and BDC are vastly different.

BDC (Batch Data Communication) is a technology used for data transfer. it is meant for transferring data thru SAP transactions itself. when u use BDC for data transfer, the sequence of steps is the same as when u use standard sap transaction screens for data upload. the only difference is that u can use different options for foreground/background processing.

LSMW on the other hand is a tool that helps migrate data from a legacy system (non-sap system ) to SAP system. it offers u various options to use either batch input, direct input, BAPIs or idocs. it involves a series of some 17-18 steps to migrate data.

BDC:

Batch Data Communication (BDC) is the process of transferring data from one SAP System to another SAP system or from a non-SAP system to SAP System.

Features :

BDC is an automatic procedure.

This method is used to transfer large amount of data that is available in electronic medium.

BDC can be used primarily when installing the SAP system and when transferring data from a legacy system (external system).

BDC uses normal transaction codes to transfer data.

Types of BDC :

CLASSICAL BATCH INPUT (Session Method)

CALL TRANSACTION

BATCH INPUT METHOD:

This method is also called as ‘CLASSICAL METHOD’.

Features:

Asynchronous processing.

Synchronous Processing in database update.

Transfer data for more than one transaction.

Batch input processing log will be generated.

During processing, no transaction is started until the previous transaction has been written to the database.

CALL TRANSACTION METHOD :

This is another method to transfer data from the legacy system.

Features:

Synchronous processing. The system performs a database commit immediately before and after the CALL TRANSACTION USING statement.

Updating the database can be either synchronous or asynchronous. The program specifies the update type.

Transfer data for a single transaction.

Transfers data for a sequence of dialog screens.

No batch input processing log is generated.

For BDC:

http://myweb.dal.ca/hchinni/sap/bdc_home.htm

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/home/bdc&;

http://www.sap-img.com/abap/learning-bdc-programming.htm

http://www.sapdevelopment.co.uk/bdc/bdchome.htm

http://www.sap-img.com/abap/difference-between-batch-input-and-call-transaction-in-bdc.htm

http://help.sap.com/saphelp_47x200/helpdata/en/69/c250684ba111d189750000e8322d00/frameset.htm

http://www.sapbrain.com/TUTORIALS/TECHNICAL/BDC_tutorial.html

LSMW:

The LSM Workbench is an R/3-based tool that supports You when transferring data from non-SAP systems ("Legacy Systems") to R/3 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 R/3 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.

The main advantages of the LSM Workbench:

• Part of R/3 and thus independent of individual platforms

• A variety of technical possibilities of data conversion:

• Data consistency due to standard import techniques:

Batch input

Direct input

BAPIs (Business Application Programming Interfaces)

IDocs (Intermediate Documents)

The import technique to be used in an individual case depends on the business object.

• Generation of the conversion program on the basis of defined rules

• Clear interactive process guide

• Interface for data in spreadsheet format

• Creation of data migration objects on the basis of recorded transactions

• Charge-free for SAP customers and SAP partners

http://help.sap.com/saphelp_nw04s/helpdata/en/87/f3ae74e68111d1b3ff006094b944c8/content.htm

http://www.sap-img.com/sap-data-migration.htm

http://www.scmexpertonline.com/downloads/SCM_LSMW_StepsOnWeb.doc

http://allsaplinks.com/lsmw.html

http://myweb.dal.ca/hchinni/sap/lsmw_home.htm

bye,

madhavi.

3 REPLIES 3
Read only

Former Member
0 Likes
535

hi,

refer this, will guide u.

LSMW IS JUST A TOOL TO GET THE DATA FROM A LEGACY SYSTEM.

IN BDC WE HAVE 2 WRITE THE CODE AND CALL THE REQUIRED METHOD

THATS IT. IN FUNCTIONALITY PERSPECTIVE THERE IS NO

DIFFERENCE.

LSMW and BDC are vastly different.

BDC (Batch Data Communication) is a technology used for data transfer. it is meant for transferring data thru SAP transactions itself. when u use BDC for data transfer, the sequence of steps is the same as when u use standard sap transaction screens for data upload. the only difference is that u can use different options for foreground/background processing.

LSMW on the other hand is a tool that helps migrate data from a legacy system (non-sap system ) to SAP system. it offers u various options to use either batch input, direct input, BAPIs or idocs. it involves a series of some 17-18 steps to migrate data.

BDC:

Batch Data Communication (BDC) is the process of transferring data from one SAP System to another SAP system or from a non-SAP system to SAP System.

Features :

BDC is an automatic procedure.

This method is used to transfer large amount of data that is available in electronic medium.

BDC can be used primarily when installing the SAP system and when transferring data from a legacy system (external system).

BDC uses normal transaction codes to transfer data.

Types of BDC :

CLASSICAL BATCH INPUT (Session Method)

CALL TRANSACTION

BATCH INPUT METHOD:

This method is also called as ‘CLASSICAL METHOD’.

Features:

Asynchronous processing.

Synchronous Processing in database update.

Transfer data for more than one transaction.

Batch input processing log will be generated.

During processing, no transaction is started until the previous transaction has been written to the database.

CALL TRANSACTION METHOD :

This is another method to transfer data from the legacy system.

Features:

Synchronous processing. The system performs a database commit immediately before and after the CALL TRANSACTION USING statement.

Updating the database can be either synchronous or asynchronous. The program specifies the update type.

Transfer data for a single transaction.

Transfers data for a sequence of dialog screens.

No batch input processing log is generated.

For BDC:

http://myweb.dal.ca/hchinni/sap/bdc_home.htm

https://www.sdn.sap.com/irj/sdn/wiki?path=/display/home/bdc&;

http://www.sap-img.com/abap/learning-bdc-programming.htm

http://www.sapdevelopment.co.uk/bdc/bdchome.htm

http://www.sap-img.com/abap/difference-between-batch-input-and-call-transaction-in-bdc.htm

http://help.sap.com/saphelp_47x200/helpdata/en/69/c250684ba111d189750000e8322d00/frameset.htm

http://www.sapbrain.com/TUTORIALS/TECHNICAL/BDC_tutorial.html

LSMW:

The LSM Workbench is an R/3-based tool that supports You when transferring data from non-SAP systems ("Legacy Systems") to R/3 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 R/3 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.

The main advantages of the LSM Workbench:

• Part of R/3 and thus independent of individual platforms

• A variety of technical possibilities of data conversion:

• Data consistency due to standard import techniques:

Batch input

Direct input

BAPIs (Business Application Programming Interfaces)

IDocs (Intermediate Documents)

The import technique to be used in an individual case depends on the business object.

• Generation of the conversion program on the basis of defined rules

• Clear interactive process guide

• Interface for data in spreadsheet format

• Creation of data migration objects on the basis of recorded transactions

• Charge-free for SAP customers and SAP partners

http://help.sap.com/saphelp_nw04s/helpdata/en/87/f3ae74e68111d1b3ff006094b944c8/content.htm

http://www.sap-img.com/sap-data-migration.htm

http://www.scmexpertonline.com/downloads/SCM_LSMW_StepsOnWeb.doc

http://allsaplinks.com/lsmw.html

http://myweb.dal.ca/hchinni/sap/lsmw_home.htm

bye,

madhavi.

Read only

Former Member
0 Likes
534

hi refer this .

BDC:

BATCH DATA COMMUNICATION

About Data Transfer In R/3 System

When a company decides to implement the SAP R/3 to manage business-critical data, it usually does not start from a no-data situation. Normally, a SAP R/3 project comes into replace or complement existing application.

In the process of replacing current applications and transferring application data, two situations might occur:

• The first is when application data to be replaced is transferred at once, and only once.

• The second situation is to transfer data periodically from external systems to SAP and vice versa.

• There is a period of time when information has to be transferred from existing application, to SAP R/3, and often this process will be repetitive.

The SAP system offers two primary methods for transferring data into SAP systems. From non-SAP systems or legacy system. These two methods are collectively called “batch input” or “batch data communication”.

1. SESSION METHOD

2. CALL TRANSACTION

3. DIRECT INPUT

Advantages offered by BATCH INPUT method:

1. Can process large data volumes in batch.

2. Can be planned and submitted in the background.

3. No manual interaction is required when data is transferred.

4. Data integrity is maintained as whatever data is transferred to the table is through transaction. Hence batch input data is submitted to all the checks and validations.

To implement one of the supported data transfers, you must often write the program that exports the data from your non-SAP system. This program, known as a “data transfer” program must map the data from the external system into the data structure required by the SAP batch input program.

The batch input program must build all of the input to execute the SAP transaction.

Two main steps are required:

• To build an internal table containing every screen and every field to be filled in during the execution of an SAP transaction.

• To pass the table to SAP for processing.

Prerequisite for Data Transfer Program

Writing a Data Transfer Program involves following prerequisites:

Analyzing data from local file

Analyzing transaction

Analyzing transaction involves following steps:

• The transaction code, if you do not already know it.

• Which fields require input i.e., mandatory.

• Which fields can you allow to default to standard values.

• The names, types, and lengths of the fields that are used by a transaction.

• Screen number and Name of module pool program behind a particular transaction.

To analyze a transaction::

• Start the transaction by menu or by entering the transaction code in the command box.

(You can determine the transaction name by choosing System – Status.)

• Step through the transaction, entering the data will be required for processing your batch input data.

• On each screen, note the program name and screen (dynpro) number.

(dynpro = dyn + pro. Dyn = screen, pro = number)

• Display these by choosing System – Status. The relevant fields are Program (dynpro) and Dynpro number. If pop-up windows occur during execution, you can get the program name and screen number by pressing F1 on any field or button on the screen.

The technical info pop-up shows not only the field information but also the program and screen.

• For each field, check box, and radio button on each screen, press F1 (help) and then choose Technical Info.

Note the following information:

The field name for batch input, which you’ll find in its own box.

The length and data type of the field. You can display this information by double clicking on the Data Element field.

• Find out the identification code for each function (button or menu) that you must execute to process the batch-input data (or to go to new screen).

Place the cursor on the button or menu entry while holding down the left mouse button. Then press F1.

In the pop-up window that follows, choose Technical info and note the code that is shown in the Function field.

You can also run any function that is assigned to a function key by way of the function key number. To display the list of available function keys, click on the right mouse button. Note the key number that is assigned to the functions you want to run.

Once you have program name, screen number, field name (screen field name), you can start writing.

DATA TRANSFER program.

Declaring internal table

First Integral Table similar to structure like local file.

Declaring internal table like BDCDATA

The data from internal table is not transferred directly to database table, it has to go through transaction. You need to pass data to particular screen and to particular screen-field. Data is passed to transaction in particular format, hence there is a need for batch input structure.

The batch input structure stores the data that is to be entered into SAP system and the actions that are necessary to process the data. The batch input structure is used by all of the batch input methods. You can use the same structure for all types of batch input, regardless of whether you are creating a session in the batch input queue or using CALL TRANSACTION.

This structure is BDCDATA, which can contain the batch input data for only a single run of a transaction. The typical processing loop in a program is as follows:

• Create a BDCDATA structure

• Write the structure out to a session or process it with CALL TRANSACTION USING; and then

• Create a BDCDATA structure for the next transaction that is to be processed.

Within a BDCDATA structure, organize the data of screens in a transaction. Each screen that is processed in the course of a transaction must be identified with a BDCDATA record. This record uses the Program, Dynpro, and Dynbegin fields of the structure.

The screen identifier record is followed by a separate BDCDATA record for each value, to be entered into a field. These records use the FNAM and FVAL fields of the BDCDATA structure. Values to be entered in a field can be any of the following:

• Data that is entered into screen fields.

• Function codes that are entered into the command field. Such function codes execute functions in a transaction, such as Save or Enter.

The BDCDATA structure contains the following fields:

• PROGRAM: Name of module pool program associated with the screen. Set this field only for the first record for the screen.

• DYNPRO: Screen Number. Set this field only in the first record for the screen.

• DYNBEGIN: Indicates the first record for the screen. Set this field to X, only for the first record for the screen. (Reset to ‘ ‘ (blank) for all other records.)

• FNAM: Field Name. The FNAM field is not case-sensitive.

• FVAL: Value for the field named in FNAM. The FVAL field is case-sensitive. Values assigned to this field are always padded on the right, if they are less than 132 characters. Values must be in character format.

Transferring data from local file to internal table

Data is uploaded to internal table by UPLOAD of WS_UPLOAD function.

Population of BDCDATA

For each record of internal table, you need to populate Internal table, which is similar to BDCDATA structure.

All these five initial steps are necessary for any type of BDC interface.

DATA TRANSFER program can call SESSION METHOD or CALL TRANSACTION. The initial steps for both the methods are same.

First step for both the methods is to upload the data to internal table. From Internal Table, the data is transferred to database table by two ways i.e., Session method and Call transaction.

SESSION METHOD

About Session method

In this method you transfer data from internal table to database table through sessions.

In this method, an ABAP/4 program reads the external data that is to be entered in the SAP System and stores the data in session. A session stores the actions that are required to enter your data using normal SAP transaction i.e., Data is transferred to session which in turn transfers data to database table.

Session is intermediate step between internal table and database table. Data along with its action is stored in session i.e., data for screen fields, to which screen it is passed, the program name behind it, and how the next screen is processed.

When the program has finished generating the session, you can run the session to execute the SAP transactions in it. You can either explicitly start and monitor a session or have the session run in the background processing system.

Unless session is processed, the data is not transferred to database table.

BDC_OPEN_GROUP

You create the session through program by BDC_OPEN_GROUP function.

Parameters to this function are:

• User Name: User name

• Group: Name of the session

• Lock Date: The date on which you want to process the session.

• Keep: This parameter is passed as ‘X’ when you want to retain session after

processing it or ‘ ‘ to delete it after processing.

BDC_INSERT

This function creates the session & data is transferred to Session.

Parameters to this function are:

• Tcode: Transaction Name

• Dynprotab: BDC Data

BDC_CLOSE_GROUP

This function closes the BDC Group. No Parameters.

Some additional information for session processing

When the session is generated using the KEEP option within the BDC_OPEN_GROUP, the system always keeps the sessions in the queue, whether it has been processed successfully or not.

However, if the session is processed, you have to delete it manually. When session processing is completed successfully while KEEP option was not set, it will be removed automatically from the session queue. Log is not removed for that session.

If the batch-input session is terminated with errors, then it appears in the list of INCORRECT session and it can be processed again. To correct incorrect session, you can analyze the session. The Analysis function allows to determine which screen and value has produced the error. If you find small errors in data, you can correct them interactively, otherwise you need to modify batch input program, which has generated the session or many times even the data file.

CALL TRANSACTION

About CALL TRANSACTION

A technique similar to SESSION method, while batch input is a two-step procedure, Call Transaction does both steps online, one after the other. In this method, you call a transaction from your program by

Call transaction <tcode> using <BDCTAB>

Mode <A/N/E>

Update <S/A>

Messages into <MSGTAB>.

Parameter – 1 is transaction code.

Parameter – 2 is name of BDCTAB table.

Parameter – 3 here you are specifying mode in which you execute transaction

A is all screen mode. All the screen of transaction are displayed.

N is no screen mode. No screen is displayed when you execute the transaction.

E is error screen. Only those screens are displayed wherein you have error record.

Parameter – 4 here you are specifying update type by which database table is updated.

S is for Synchronous update in which if you change data of one table then all the related Tables gets updated. And sy-subrc is returned i.e., sy-subrc is returned for once and all.

A is for Asynchronous update. When you change data of one table, the sy-subrc is returned. And then updating of other affected tables takes place. So if system fails to update other tables, still sy-subrc returned is 0 (i.e., when first table gets updated).

Parameter – 5 when you update database table, operation is either successful or unsuccessful or operation is successful with some warning. These messages are stored in internal table, which you specify along with MESSAGE statement. This internal table should be declared like BDCMSGCOLL, a structure available in ABAP/4. It contains the following fields:

1. Tcode: Transaction code

2. Dyname: Batch point module name

3. Dynumb: Batch input Dyn number

4. Msgtyp: Batch input message type (A/E/W/I/S)

5. Msgspra: Batch input Lang, id of message

6. Msgid: Message id

7. MsgvN: Message variables (N = 1 - 4)

For each entry, which is updated in database, table message is available in BDCMSGCOLL. As BDCMSGCOLL is structure, you need to declare a internal table which can contain multiple records (unlike structure).

Steps for CALL TRANSACTION method

1. Internal table for the data (structure similar to your local file)

2. BDCTAB like BDCDATA

3. UPLOAD or WS_UPLOAD function to upload the data from local file to itab. (Considering file is local file)

4. Loop at itab.

Populate BDCTAB table.

Call transaction <tcode> using <BDCTAB>

Mode <A/N/E>

Update <S/A>.

Refresh BDCTAB.

Endloop.

(To populate BDCTAB, You need to transfer each and every field)

The major differences between Session method and Call transaction are as follows:

SESSION METHOD CALL TRANSACTION

1. Data is not updated in database table unless Session is processed. Immediate updation in database table.

2. No sy-subrc is returned. Sy-subrc is returned.

3. Error log is created for error records. Errors need to be handled explicitly

4. Updation in database table is always synchronous Updation in database table can be synchronous Or Asynchronous.

Error Handling in CALL TRANSACTION

When Session Method updates the records in database table, error records are stored in the log file. In Call transaction there is no such log file available and error record is lost unless handled. Usually you need to give report of all the error records i.e., records which are not inserted or updated in the database table. This can be done by the following method:

Steps for the error handling in CALL TRANSACTION

1. Internal table for the data (structure similar to your local file)

2. BDCTAB like BDCDATA

3. Internal table BDCMSG like BDCMSGCOLL

4. Internal table similar to Ist internal table

(Third and fourth steps are for error handling)

5. UPLOAD or WS_UPLOAD function to upload the data from the local file to itab. (Considering file is local file)

6. Loop at itab.

Populate BDCTAB table.

Call transaction <tr.code> using <Bdctab>

Mode <A/N/E>

Update <S/A>

Messages <BDCMSG>.

Perform check.

Refresh BDCTAB.

Endloop.

7 Form check.

IF sy-subrc 0. (Call transaction returns the sy-subrc if updating is not successful).

Call function Format_message.

(This function is called to store the message given by system and to display it along with record)

Append itab2.

Display the record and message.

madhavi.

Read only

Former Member
0 Likes
534

Hi Sundar,

I am sending one sample program to upload the purchase order details .

report ZGPO no standard page heading line-size 255.

*%%%%%%%%%########$$$$$$$$$$$$$$$$$$$$$$$$$_______FLAT FILE

*H 1000 nb 26.12.2004 1000 001

*I 100-100 35 92 1000 0001

*I 100-110 35 90 1000 0001

*I 100-120 35 95 1000 0001

*H 1000 nb 28.12.2004 1000 001

*I 100-100 35 92 1000 0001

*I 100-110 35 90 1000 0001

*I 100-120 35 95 1000 0001

*H 1000 nb 29.12.2004 1000 001

*I 100-100 35 92 1000 0001

*I 100-110 35 90 1000 0001

*I 100-120 35 95 1000 0001

*H 1000 nb 29.12.2004 1000 001

*I 100-100 35 92 1000 0001

*I 100-110 35 90 1000 0001

*I 100-120 35 95 1000 0001

*H 1000 nb 31.12.2004 1000 001

*I 100-100 35 92 1000 0001

*I 100-110 35 90 1000 0001

*I 100-120 35 95 1000 0001

*H 1000 nb 01.01.2005 1000 001

*I 100-100 35 92 1000 0001

*I 100-110 35 90 1000 0001

*I 100-120 35 95 1000 0001

*H 1000 nb 02.02.2006 1000 001

*I 100-100 35 92 1000 0001

*I 100-110 35 90 1000 0001

*I 100-120 35 95 1000 0001

TABLES: T024E,

T024,

T001W,

T001L,

LFA1,

LFM1,

MARA,

MARC,

T100.

*CONSTANTS

*VARIABLES

DATA:V_LIFNR LIKE LFA1-LIFNR,

V_BSART LIKE EKKO-BSART,

V_BEDAT LIKE EKKO-BEDAT,

V_BEDAT1(10),

V_EKORG LIKE EKKO-EKORG,

V_EKGRP LIKE EKKO-EKGRP,

V_NETPR(14),

V_H_ERROR,

V_I_ERROR,

V_I_CORRECT,

V_ERROR_LEVEL(5),

N TYPE I VALUE 0,

M TYPE I VALUE 0,

V_PATH(128),

L_MSTRING(480),

GUIFILE TYPE STRING.

*INTERNAL TABLES

*INTERNAL TABLE FOR UPLOADING DATA FROM FLAT FILE

DATA:BEGIN OF I_INPUT OCCURS 0,

X TYPE STRING,

V1(10),

V2 TYPE STRING,

V3 TYPE STRING,

V4 TYPE STRING,

V5 TYPE STRING,

END OF I_INPUT.

*INTERNAL TABLE TO COPY DATA FROM I_INPUT ACCORDING TO OUR REQUIRED

*FORMAT

DATA:begin of I_ME21 occurs 0,

LIFNR LIKE LFA1-LIFNR,

BSART LIKE EKKO-BSART,

BEDAT(10),

EKORG LIKE EKKO-EKORG,

EKGRP LIKE EKKO-EKGRP,

EMATN LIKE EKPO-EMATN,

MENGE(17),

NETPR(14),

WERKS LIKE EKPO-WERKS,

LGORT LIKE EKPO-LGORT,

END OF I_ME21.

*INTERNAL TABLE TO HOLD RECORS THAT PASS THROUGH VALIDATION

DATA:BEGIN OF I_ME21_PTV OCCURS 0,

LIFNR LIKE LFA1-LIFNR,

BSART LIKE EKKO-BSART,

BEDAT(10),

EKORG LIKE EKKO-EKORG,

EKGRP LIKE EKKO-EKGRP,

EMATN LIKE EKPO-EMATN,

MENGE(17),

NETPR(14),

WERKS LIKE EKPO-WERKS,

LGORT LIKE EKPO-LGORT,

END OF I_ME21_PTV.

*INTERNAL TABLE TO HOLD RECORS THAT FAIL THROUGH VALIDATION

DATA:BEGIN OF I_ME21_FTV OCCURS 0,

LIFNR LIKE LFA1-LIFNR,

BSART LIKE EKKO-BSART,

BEDAT(10), " LIKE EKKO-BEDAT,

EKORG LIKE EKKO-EKORG,

EKGRP LIKE EKKO-EKGRP,

EMATN LIKE EKPO-EMATN,

MENGE(17), " LIKE EKPO-MENGE,

NETPR(14),

WERKS LIKE EKPO-WERKS,

LGORT LIKE EKPO-LGORT,

ERR_MSG(255),

END OF I_ME21_FTV.

*INTERNAL TABLE TO HANDLE ERRORS FOR CALL TRANSACTION METHOD

DATA:I_ERROR like I_ME21_FTV OCCURS 0 WITH HEADER LINE,

I_ME21_IM LIKE I_ME21 OCCURS 0 WITH HEADER LINE.

DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.

SELECTION-SCREEN : BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.

*TEXT-001 = SELECT ANY RADIOBUTTON

PARAMETER : R1 RADIOBUTTON GROUP G1,

*SELECT R1 FOR PRESENTATION SERVER FILE PATH AND PRESS ENTER

R2 RADIOBUTTON GROUP G1.

*SELECT R2 FOR APPLICATION SERVER FILE PATH AND PRESS ENTER

SELECTION-SCREEN : END OF BLOCK B1 .

SELECTION-SCREEN : BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.

*TEXT-002 = FILEPATH

PARAMETER :P_PATH LIKE RLGRAP-FILENAME MODIF ID ABC,

  • "P_PATH = PRESENTATION SERVER FILE PATH

A_PATH(128) MODIF ID BCA. "APPLICATION SERVER FILE PATH

SELECTION-SCREEN : END OF BLOCK B2.

SELECTION-SCREEN : BEGIN OF BLOCK B3 WITH FRAME TITLE TEXT-003.

*TEXT-003 = SESSION PARAMETERS DETAILS

PARAMETERS :SESSION(12),

HOLDDATE LIKE SY-DATUM.

SELECTION-SCREEN : END OF BLOCK B3.

*SELECTION-SCREEN : BEGIN OF BLOCK B3 WITH FRAME TITLE TEXT-003.

*

*PARAMETERS :CTUMODE LIKE CTU_PARAMS-DISMODE DEFAULT 'N',

  • "A: show all dynpros

  • "E: show dynpro on error only

  • "N: do not display dynpro

  • CUPDATE LIKE CTU_PARAMS-UPDMODE DEFAULT 'S'.

*"S: synchronously

*"A: asynchronously

*"L: local

*SELECTION-SCREEN : END OF BLOCK B3.

AT SELECTION-SCREEN OUTPUT.

LOOP AT SCREEN.

IF R1 EQ 'X'.

*"R1 = RADIO BUTTON TO ACTIVATE P_PATH

IF SCREEN-GROUP1 EQ 'BCA'.

SCREEN-INPUT = 0.

ENDIF.

*"R2 = RADIO BUTTON TO ACTIVATE A_PATH

ELSEIF R2 EQ 'X'. "R3 = RADIO

IF SCREEN-GROUP1 EQ 'ABC'.

SCREEN-INPUT = 0.

ENDIF.

ENDIF.

MODIFY SCREEN.

ENDLOOP.

*VALUE REQUEST PATH OF THE FILE ON PRESENTATION SERVER.

AT selection-SCREEN ON VALUE-REQUEST FOR P_PATH.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = SYST-CPROG

  • DYNPRO_NUMBER = SYST-DYNNR

  • FIELD_NAME = ' '

IMPORTING

FILE_NAME = V_PATH.

IF NOT V_PATH IS INITIAL.

P_PATH = V_PATH.

ENDIF.

AT SELECTION-SCREEN ON SESSION.

IF SESSION IS INITIAL.

MESSAGE E010(ZMSG) WITH 'ENTER NAME OF THE SESSION'.

ENDIF.

AT SELECTION-SCREEN ON P_PATH.

IF P_PATH IS INITIAL.

MESSAGE E011(ZMSG) WITH 'ENTER NAME OF THE PATH'.

ENDIF.

*AT SELECTION-SCREEN ON A_PATH.

*

  • IF P_PATH IS INITIAL.

  • MESSAGE E011(ZMSG) WITH 'ENTER NAME OF THE PATH'.

  • ENDIF.

start-of-selection.

IF R1 EQ 'X'.

GUIFILE = P_PATH.

*UPLOADING THE DATA INTO THE INTERNAL TABLE

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = GUIFILE

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

DATA_TAB = I_INPUT

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17.

ELSEIF R2 EQ 'X'.

IF NOT A_PATH IS INITIAL.

OPEN DATASET A_PATH FOR APPENDING IN BINARY MODE .

IF SY-SUBRC EQ 0.

WRITE:/ 'FILE OPENED',sy-sysid.

ENDIF.

ENDIF.

DO .

READ DATASET A_PATH INTO I_ME21.

IF SY-SUBRC EQ 0.

APPEND I_ME21.

CLEAR I_ME21.

else .

exit.

ENDIF.

ENDDO.

CLOSE DATASET A_PATH.

ENDIF.

*TRANFER THE DATA FROM I_INPUT TO I_ME21 TO GET REQUIRED FORMAT

LOOP AT I_INPUT.

IF I_INPUT-X = 'H'.

I_ME21-LIFNR = I_INPUT-V1.

I_ME21-BSART = I_INPUT-V2.

I_ME21-BEDAT = I_INPUT-V3.

I_ME21-EKORG = I_INPUT-V4.

I_ME21-EKGRP = I_INPUT-V5.

APPEND I_ME21.

CLEAR I_ME21.

ELSE.

I_ME21-EMATN = I_INPUT-V1.

I_ME21-MENGE = I_INPUT-V2.

I_ME21-NETPR = I_INPUT-V3.

I_ME21-WERKS = I_INPUT-V4.

I_ME21-LGORT = I_INPUT-V5.

APPEND I_ME21.

CLEAR I_ME21.

ENDIF.

ENDLOOP.

PERFORM OPEN_GROUP USING SESSION HOLDDATE.

LOOP AT I_ME21_PTV.

IF NOT I_ME21_PTV-LIFNR IS INITIAL.

IF NOT SY-TABIX EQ 1.

perform save.

ENDIF.

perform scr_100.

ELSE.

N = N + 1.

IF N = 1.

perform scr_120_01.

ELSEIF N GE 2.

perform scr_120_02.

ENDIF.

ENDIF.

ENDLOOP.

perform save.

PERFORM CLOSE_GROUP.

&----


*& Form OPEN_GROUP

&----


  • text

----


  • -->P_SESSIONID text

  • -->P_HOLDDATE text

----


FORM OPEN_GROUP USING P_SESSIONID

P_HOLDDATE.

  • open batchinput group

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING CLIENT = SY-MANDT

GROUP = P_SESSIONID

USER = SY-UNAME

KEEP = 'X'

HOLDDATE = P_HOLDDATE.

WRITE: /(30) 'BDC_OPEN_GROUP'(I02),

(12) 'returncode:'(I05),

SY-SUBRC.

ENDFORM. " OPEN_GROUP

&----


*& Form CLOSE_GROUP

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM CLOSE_GROUP .

CALL FUNCTION 'BDC_CLOSE_GROUP'.

WRITE: /(30) 'BDC_CLOSE_GROUP'(I04),

(12) 'returncode:'(I05),

SY-SUBRC.

.

ENDFORM. " CLOSE_GROUP

*&----


*

*& Form scr_100

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM scr_100 .

perform bdc_dynpro using 'SAPMM06E' '0100'.

perform bdc_field using 'BDC_CURSOR'

'EKKO-EKGRP'.

perform bdc_field using 'BDC_OKCODE'

'=AB'.

perform bdc_field using 'EKKO-LIFNR'

I_ME21_PTV-LIFNR. "'1000'.

perform bdc_field using 'RM06E-BSART'

I_ME21_PTV-BSART."'nb'.

perform bdc_field using 'RM06E-BEDAT'

I_ME21_PTV-BEDAT."'31.05.2007'.

perform bdc_field using 'EKKO-EKORG'

I_ME21_PTV-EKORG. "'1000'.

perform bdc_field using 'EKKO-EKGRP'

I_ME21_PTV-EKGRP. "'001'.

I_ME21_IM = I_ME21_PTV.

APPEND I_ME21_IM.

CLEAR I_ME21_IM.

ENDFORM. " scr_100

*&----


*

*& Form scr_120_01

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM scr_120_01 .

perform bdc_dynpro using 'SAPMM06E' '0120'.

perform bdc_field using 'BDC_CURSOR'

'EKPO-LGORT(01)'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'EKPO-EMATN(01)'

I_ME21_PTV-EMATN.

perform bdc_field using 'EKPO-MENGE(01)'

I_ME21_PTV-MENGE.

perform bdc_field using 'EKPO-NETPR(01)'

I_ME21_PTV-NETPR.

perform bdc_field using 'EKPO-WERKS(01)'

I_ME21_PTV-WERKS.

perform bdc_field using 'EKPO-LGORT(01)'

I_ME21_PTV-LGORT.

I_ME21_IM = I_ME21_PTV.

APPEND I_ME21_IM.

CLEAR I_ME21_IM.

ENDFORM. " scr_120_01

*&----


*

*& Form scr_120_02

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM scr_120_02 .

perform bdc_dynpro using 'SAPMM06E' '0120'.

perform bdc_field using 'BDC_CURSOR'

'EKPO-LGORT(02)'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'RM06E-EBELP'

'10'.

perform bdc_field using 'EKPO-EMATN(02)'

I_ME21_PTV-EMATN. "100-120'.

perform bdc_field using 'EKPO-MENGE(02)'

I_ME21_PTV-MENGE.

perform bdc_field using 'EKPO-NETPR(02)'

I_ME21_PTV-NETPR.

perform bdc_field using 'EKPO-WERKS(02)'

I_ME21_PTV-WERKS. " '1000'.

perform bdc_field using 'EKPO-LGORT(02)'

I_ME21_PTV-LGORT. "'0001'.

perform bdc_dynpro using 'SAPMM06E' '0120'.

perform bdc_field using 'BDC_CURSOR'

'RM06E-EBELP'.

perform bdc_field using 'BDC_OKCODE'

'=NP'.

perform bdc_field using 'RM06E-EBELP'

'10'.

I_ME21_IM = I_ME21_PTV.

APPEND I_ME21_IM.

CLEAR I_ME21_IM.

ENDFORM. " scr_120_02

*&----


*

*& Form save

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

FORM save .

DATA:L_MSG(255).

perform bdc_dynpro using 'SAPMM06E' '0120'.

perform bdc_field using 'BDC_CURSOR'

'RM06E-EBELP'.

perform bdc_field using 'BDC_OKCODE'

'=BU'.

PERFORM BDC_TRANSACTION USING 'ME21'.

  • call transaction 'ME21' using BDCDATA

  • MODE CTUMODE

  • UPDATE CUPDATE

  • MESSAGES INTO MESSTAB.

*

  • IF SY-SUBRC EQ 0.

  • CLEAR BDCDATA.

  • REFRESH BDCDATA.

  • M = M + 1. "CALCULATION FOR TOTAL NO.OF RECORDS CREATED.

*

  • ELSE.

**ERROR HANDLING IN CALL TRANSACTION.

  • CLEAR BDCDATA.

  • REFRESH BDCDATA.

  • CALL FUNCTION 'FORMAT_MESSAGE'

  • EXPORTING

  • ID = SY-MSGID

  • LANG = '-D'

  • NO = SY-MSGNO

  • V1 = SY-MSGV1

  • V2 = SY-MSGV2

  • V3 = SY-MSGV3

  • V4 = SY-MSGV4

  • IMPORTING

  • MSG = L_MSG

  • EXCEPTIONS

  • NOT_FOUND = 1

  • OTHERS = 2.

  • IF SY-SUBRC EQ 0.

*

  • LOOP AT I_ME21_IM.

*

  • I_ERROR-LIFNR = I_ME21_IM-LIFNR.

  • I_ERROR-BEDAT = I_ME21_IM-BEDAT.

  • I_ERROR-BSART = I_ME21_IM-BSART.

  • I_ERROR-EKORG = I_ME21_IM-EKORG.

  • I_ERROR-EKGRP = I_ME21_IM-EKGRP.

*

  • I_ERROR-EMATN = I_ME21_IM-EMATN.

  • I_ERROR-MENGE = I_ME21_IM-MENGE.

  • I_ERROR-WERKS = I_ME21_IM-WERKS.

  • I_ERROR-LGORT = I_ME21_IM-LGORT.

  • I_ERROR-ERR_MSG = L_MSG.

*

  • APPEND I_ERROR.

  • CLEAR I_ERROR.

  • ENDLOOP.

  • REFRESH I_ME21_IM.

  • ENDIF.

  • ENDIF.

ENDFORM. " save