Application Development 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: 

bdc creation

Former Member
0 Kudos

1in real time what are the steps we need to fallow to upload the data through bdc(steps)

3 REPLIES 3

Former Member
0 Kudos

&----


*& Report Z_XK01_BDC1 *

*& *

&----


*& *

*& *

&----


REPORT z_xk01_bdc1 LINE-SIZE 255 . .

TYPES : BEGIN OF t_disp ,

vendorno(9),

compcc(13),

purchorg(14),

accgroup(15),

title(7),

name(5),

country(8),

ordcurr(14),

END OF t_disp.

TYPES : BEGIN OF t_err,

msgtyp LIKE bdcmsgcoll-msgtyp,

l_mstring(250),

END OF t_err.

DATA: i_disp TYPE STANDARD TABLE OF t_disp,

wa_disp TYPE t_disp,

i_err TYPE STANDARD TABLE OF t_err,

wa_err TYPE t_err.

-


data definition

-


Batchinputdata of single transaction

DATA: bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.

messages of call transaction

DATA: messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.

error session opened (' ' or 'X')

DATA: e_group_opened.

message texts

TABLES: t100.

PARAMETER : p_file1 LIKE ibipparms-path,

p_cmode LIKE ctu_params-dismode DEFAULT 'N'.

"A: show all dynpros

"E: show dynpro on error only

"N: do not display dynpro

*selction screen.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file1.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = syst-cprog

dynpro_number = syst-dynnr

IMPORTING

file_name = p_file1.

AT SELECTION-SCREEN ON p_file1.

IF p_file1 IS INITIAL .

MESSAGE 'FILE IS NOT FOUND' TYPE 'E'.

ENDIF.

START-OF-SELECTION.

PERFORM f_disp_file1.

END-OF-SELECTION.

PERFORM f_disp_errs.

&----


*& Form F_DISP_FILE1

&----


text

-


--> p1 text

<-- p2 text

-


FORM f_disp_file1 .

DATA: l_filename1 TYPE string.

MOVE p_file1 TO l_filename1.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = l_filename1

filetype = 'ASC'

has_field_separator = 'X'

HEADER_LENGTH = 0

READ_BY_LINE = 'X'

DAT_MODE = ' '

CODEPAGE = ' '

IGNORE_CERR = ABAP_TRUE

REPLACEMENT = '#'

CHECK_BOM = ' '

IMPORTING

FILELENGTH =

HEADER =

TABLES

data_tab = i_disp

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

.

IF sy-subrc 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

*? prepare BDC data

DELETE i_disp INDEX 1.

LOOP AT i_disp INTO wa_disp .

PERFORM bdc_dynpro USING 'SAPMF02K' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR'

'RF02K-KTOKK'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'RF02K-LIFNR'

wa_disp-vendorno.

'ztest_1'.

PERFORM bdc_field USING 'RF02K-BUKRS'

wa_disp-compcc.

'0001'.

PERFORM bdc_field USING 'RF02K-EKORG'

wa_disp-purchorg.

'0001'.

PERFORM bdc_field USING 'RF02K-KTOKK'

wa_disp-accgroup.

'0001'.

PERFORM bdc_dynpro USING 'SAPMF02K' '0110'.

PERFORM bdc_field USING 'BDC_CURSOR'

'LFA1-SPRAS'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=VW'.

PERFORM bdc_field USING 'LFA1-ANRED'

wa_disp-title.

'Mr.'.

PERFORM bdc_field USING 'LFA1-NAME1'

wa_disp-name.

'test name'.

PERFORM bdc_field USING 'LFA1-SORTL'

'TEST NAME'.

PERFORM bdc_field USING 'LFA1-LAND1'

wa_disp-country.

'in'.

PERFORM bdc_field USING 'LFA1-SPRAS'

'en'.

PERFORM bdc_dynpro USING 'SAPMF02K' '0120'.

PERFORM bdc_field USING 'BDC_CURSOR'

'LFA1-KUNNR'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=VW'.

PERFORM bdc_dynpro USING 'SAPMF02K' '0130'.

PERFORM bdc_field USING 'BDC_CURSOR'

'LFBK-BANKS(01)'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=VW'.

PERFORM bdc_dynpro USING 'SAPMF02K' '0210'.

PERFORM bdc_field USING 'BDC_CURSOR'

'LFB1-AKONT'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=VW'.

PERFORM bdc_dynpro USING 'SAPMF02K' '0215'.

PERFORM bdc_field USING 'BDC_CURSOR'

'LFB1-ZTERM'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=VW'.

PERFORM bdc_dynpro USING 'SAPMF02K' '0220'.

PERFORM bdc_field USING 'BDC_CURSOR'

'LFB5-MAHNA'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=VW'.

PERFORM bdc_dynpro USING 'SAPMF02K' '0310'.

PERFORM bdc_field USING 'BDC_CURSOR'

'LFM1-WAERS'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=UPDA'.

PERFORM bdc_field USING 'LFM1-WAERS'

wa_disp-ordcurr.

'inr'.

PERFORM bdc_transaction USING 'XK01'.

WRITE:/ WA_DISP-VendorNo,

WA_DISP-COMPCC,

WA_DISP-PURCHORG,

WA_DISP-ACCGROUP,

WA_DISP-title,

WA_DISP-name,

WA_DISP-country,

WA_DISP-ORDCURR.

clear: WA_disp.

Refresh bdcdata.

ENDLOOP.

ENDFORM. " F_DISP_FILE1

-


Start new screen *

-


FORM bdc_dynpro USING program dynpro.

CLEAR bdcdata.

bdcdata-program = program.

bdcdata-dynpro = dynpro.

bdcdata-dynbegin = 'X'.

APPEND bdcdata.

ENDFORM. "BDC_DYNPRO

-


Insert field *

-


FORM bdc_field USING fnam fval.

IF FVAL NODATA.

CLEAR bdcdata.

bdcdata-fnam = fnam.

bdcdata-fval = fval.

APPEND bdcdata.

ENDIF.

ENDFORM. "BDC_FIELD

&----


*& Form bdc_transaction

&----


text

-


-->P_0322 text

-


FORM bdc_transaction USING tcode.

DATA: l_mstring(480),

l_subrc LIKE sy-subrc.

REFRESH messtab.

CALL TRANSACTION tcode USING bdcdata

MODE p_cmode

UPDATE 'L'

MESSAGES INTO messtab.

l_subrc = sy-subrc.

IF SMALLLOG 'X'.

WRITE: / 'CALL_TRANSACTION',

TCODE,

'returncode:'(I05),

L_SUBRC,

'RECORD:',

SY-INDEX.

LOOP AT messtab.

SELECT SINGLE * FROM t100 WHERE sprsl = messtab-msgspra

AND arbgb = messtab-msgid

AND msgnr = messtab-msgnr.

IF sy-subrc = 0.

l_mstring = t100-text.

IF l_mstring CS '&1'.

REPLACE '&1' WITH messtab-msgv1 INTO l_mstring.

REPLACE '&2' WITH messtab-msgv2 INTO l_mstring.

REPLACE '&3' WITH messtab-msgv3 INTO l_mstring.

REPLACE '&4' WITH messtab-msgv4 INTO l_mstring.

ELSE.

REPLACE '&' WITH messtab-msgv1 INTO l_mstring.

REPLACE '&' WITH messtab-msgv2 INTO l_mstring.

REPLACE '&' WITH messtab-msgv3 INTO l_mstring.

REPLACE '&' WITH messtab-msgv4 INTO l_mstring.

ENDIF.

CONDENSE l_mstring.

WRITE: / messtab-msgtyp, l_mstring(250).

*? Send this errors to err internal table

wa_err-msgtyp = messtab-msgtyp.

wa_err-l_mstring = l_mstring.

APPEND wa_err TO i_err.

ELSE.

WRITE: / messtab.

ENDIF.

CLEAR: messtab, wa_err.

ENDLOOP.

SKIP.

ENDIF.

ENDFORM. " bdc_transaction

&----


*& Form f_disp_errs

&----


text

-


--> p1 text

<-- p2 text

-


FORM f_disp_errs .

SORT i_err BY msgtyp.

LOOP AT i_err INTO wa_err.

AT FIRST.

WRITE : / text-002.

uline.

ENDAT.

AT NEW msgtyp.

IF wa_err-msgtyp = 'S'.

WRITE : / text-003.

uline.

ELSEIF wa_err-msgtyp = 'E'.

WRITE : / text-001.

uline.

ENDIF.

ENDAT.

WRITE : / wa_err-msgtyp, wa_err-l_mstring.

clear wa_err.

ENDLOOP.

ENDFORM. " f_disp_errs

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/d62292b3-0301-0010-df98-aaac31cd...

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/d62292b3-0301-0010-df98-aaac31cd...

Reward points..

Former Member
0 Kudos

Hi,

TABLES : MARA,MAKT.

DATA : BEGIN OF T_MARA OCCURS 0,

MATNR LIKE MARA-MATNR,

MBRSH LIKE MARA-MBRSH,

MTART LIKE MARA-MTART,

MAKTX LIKE MAKT-MAKTX,

MEINS LIKE MARA-MEINS,

END OF T_MARA.

DATA : I_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.

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

PARAMETERS: P_FILE TYPE IBIPPARMS-PATH.

SELECTION-SCREEN END OF BLOCK B1.

DATA: V_FILE TYPE STRING.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.

CALL FUNCTION 'F4_FILENAME'

  • EXPORTING

  • PROGRAM_NAME = SYST-CPROG

  • DYNPRO_NUMBER = SYST-DYNNR

  • FIELD_NAME = ' '

IMPORTING

FILE_NAME = P_FILE.

.

MOVE P_FILE TO V_FILE.

*************************************************************************

START-OF-SELECTION.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = V_FILE

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'x'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • VIRUS_SCAN_PROFILE =

  • NO_AUTH_CHECK = ' '

  • IMPORTING

  • FILELENGTH =

  • HEADER =

TABLES

DATA_TAB = T_MARA

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

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

***********************************************************************************

PERFORM OPEN_GROUP.

LOOP AT T_MARA.

REFRESH I_BDCDATA.

PERFORM BDC_DYNPRO USING 'SAPLMGMM' '0060'.

PERFORM BDC_FIELD USING 'BDC_CURSOR'

'RMMG1-MTART'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'=AUSW'.

PERFORM BDC_FIELD USING 'RMMG1-MATNR'

T_MARA-MATNR.

PERFORM BDC_FIELD USING 'RMMG1-MBRSH'

T_MARA-MBRSH.

PERFORM BDC_FIELD USING 'RMMG1-MTART'

T_MARA-MTART.

PERFORM BDC_DYNPRO USING 'SAPLMGMM' '0070'.

PERFORM BDC_FIELD USING 'BDC_CURSOR'

'MSICHTAUSW-DYTXT(02)'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'=ENTR'.

PERFORM BDC_FIELD USING 'MSICHTAUSW-KZSEL(01)'

'X'.

PERFORM BDC_FIELD USING 'MSICHTAUSW-KZSEL(02)'

'X'.

PERFORM BDC_DYNPRO USING 'SAPLMGMM' '4004'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'/00'.

PERFORM BDC_FIELD USING 'BDC_CURSOR'

'MAKT-MAKTX'.

PERFORM BDC_FIELD USING 'MAKT-MAKTX'

T_MARA-MAKTX.

PERFORM BDC_FIELD USING 'MARA-MEINS'

T_MARA-MEINS.

PERFORM BDC_FIELD USING 'MARA-MTPOS_MARA'

'VOLL'.

PERFORM BDC_DYNPRO USING 'SAPLMGMM' '4004'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'/00'.

PERFORM BDC_FIELD USING 'BDC_CURSOR'

'MAKT-MAKTX'.

PERFORM BDC_FIELD USING 'MAKT-MAKTX'

T_MARA-MAKTX.

PERFORM BDC_DYNPRO USING 'SAPLSPO1' '0300'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'=YES'.

PERFORM BDC_INSERT.

ENDLOOP.

PERFORM CLOSE_GROUP.

WRITE : /'success'.

*************************************************************************

FORM OPEN_GROUP .

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

CLIENT = SY-MANDT

  • DEST = FILLER8

GROUP = 'naresh1'

  • HOLDDATE = FILLER8

KEEP = 'x'

USER = SY-UNAME

  • RECORD = FILLER1

  • PROG = SY-CPROG

  • DCPFM = '%'

  • DATFM = '%'

  • IMPORTING

  • QID =

EXCEPTIONS

CLIENT_INVALID = 1

DESTINATION_INVALID = 2

GROUP_INVALID = 3

GROUP_IS_LOCKED = 4

HOLDDATE_INVALID = 5

INTERNAL_ERROR = 6

QUEUE_ERROR = 7

RUNNING = 8

SYSTEM_LOCK_ERROR = 9

USER_INVALID = 10

OTHERS = 11

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " open_group

***************************************************************

FORM BDC_INSERT .

CALL FUNCTION 'BDC_INSERT'

EXPORTING

TCODE = 'MM01'

  • POST_LOCAL = NOVBLOCAL

  • PRINTING = NOPRINT

  • SIMUBATCH = ' '

  • CTUPARAMS = ' '

TABLES

DYNPROTAB = I_BDCDATA

EXCEPTIONS

INTERNAL_ERROR = 1

NOT_OPEN = 2

QUEUE_ERROR = 3

TCODE_INVALID = 4

PRINTING_INVALID = 5

POSTING_INVALID = 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.

ENDFORM. " BDC_INSERT

***************************************************************

FORM CLOSE_GROUP .

CALL FUNCTION 'BDC_CLOSE_GROUP'

EXCEPTIONS

NOT_OPEN = 1

QUEUE_ERROR = 2

OTHERS = 3

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. " close_group

****************************************************************

FORM BDC_DYNPRO USING P_PGM P_SCR.

I_BDCDATA-PROGRAM = P_PGM.

I_BDCDATA-DYNPRO = P_SCR.

I_BDCDATA-DYNBEGIN = 'X'.

APPEND I_BDCDATA.

CLEAR I_BDCDATA.

ENDFORM. " bdc_dynpro

*******************************************************************

FORM BDC_FIELD USING P_FNAM P_FVAL.

I_BDCDATA-FNAM = P_FNAM.

I_BDCDATA-FVAL = P_FVAL.

APPEND I_BDCDATA.

CLEAR I_BDCDATA.

ENDFORM. " bdc_field

*********************************************************************

Reward If Helpfull,

Naresh.

Former Member
0 Kudos

Hi Chari,

Please check this form

Steps in BDC

Step1:

Create a BDC Recording using transaction SHDB.

Step2:

Create a ZProgram from the Recording (from tcode SHDB).

Step3:

Upload the legacy data.. Use FM GUI_UPLOAD.

Step4:

Loop at the internal table (with legacy data)

Put the BDC code inside the loop and replace the values which you gave while recording with the internal table fields respectively.

Step5:

Activate the program and execute.

here is the brief description of the same...

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.

Best regatds,

raam