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

session method program

Former Member
0 Likes
2,171

can any body help me , how to write a bdc programming using session method .

and can u explain me how to use bdc_insert , bdc_open , bdc_close in session method programe.

2 REPLIES 2
Read only

Former Member
0 Likes
1,861

Hi,

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.

&----


*& Report ZSR_BDC_MADHU_SESSION

*&

&----


*&

*&

&----


report zsr_bdc_madhu_session.

parameter: p_file like rlgrap-filename default 'C:/DATA2.TXT'

.

types: begin of ff,

lifnr like rf02k-lifnr,

  • BUKRS LIKE RF02K-BUKRS,

ktokk like rf02k-ktokk,

  • ANRED LIKE LFA1-ANRED,

name1 like lfa1-name1,

sortl like lfa1-sortl,

land1 like lfa1-land1,

spras like lfa1-spras,

  • KUNNR LIKE LFA1-KUNNR,

end of ff.

data: p_file1 type string,

v_index type i value 1,

v_index1 type i value 1,

vs_count type i value 0,

vf_count type i value 0,

vt_count type i value 0.

data: it_ff type ff occurs 0 with header line.

data: if_ff type ff occurs 0 with header line.

data: is_ff type ff occurs 0 with header line.

data: it_bdc like bdcdata occurs 0 with header line.

data: it_msg type bdcmsgcoll occurs 0 with header line.

start-of-selection.

perform get_data.

perform generate.

perform bdc_insert.

perform close_session.

&----


*& Form get_data

&----


  • get_data

----


form get_data .

p_file1 = p_file.

call function 'GUI_UPLOAD'

exporting

filename = p_file1

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 = it_ff

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.

endform. " get_data

&----


*& Form generate

&----


  • text

----


form generate .

data: lv_msg(255) type c.

loop at it_ff.

perform populate using :

'SAPMF02K' '0100' 'X',

'' 'BDC_OKCODE' '/00',

'' 'RF02K-LIFNR' it_ff-lifnr,

  • '' 'RF02K-BUKRS' it_ff-bukrs,

'' 'RF02K-KTOKK' it_ff-ktokk,

'SAPMF02K' '110' 'X',

'' 'BDC_OKCODE' '/00',

  • '' 'LFA1-ANRED' it_ff-anred,

'' 'LFA1-NAME1' it_ff-name1,

'' 'LFA1-SORTL' it_ff-sortl,

'' 'LFA1-LAND1' it_ff-land1,

'' 'lfa1-spras' it_ff-spras,

'SAPMF02K' '120' 'X',

'' 'BDC_OKCODE' '/00',

  • '' 'LFA1-KUNNR' it_ff-kunnr,

'SAPMF02K' '0130' 'X',

'' 'BDC_OKCODE' '=ENTR',

  • 'SAPMF02K' '0210' 'X',

  • '' 'BDC_OKCODE' '/00',

  • 'SAPMF02K' '0215' 'X',

  • '' 'BDC_OKCODE' '/00',

  • 'SAPMF02K' '0220' 'X',

  • '' 'BDC_OKCODE' '/00',

'SAPLSPO1' '0300' 'X',

'' 'BDC_OKCODE' '=YES'.

call transaction 'XK01'

using it_bdc

mode 'N'

update 'S'

messages into it_msg.

if sy-subrc = 0.

read table it_ff index v_index.

is_ff-lifnr = it_ff-lifnr.

  • IS_FF-BUKRS = IT_FF-BUKRS.

is_ff-ktokk = it_ff-ktokk.

  • IS_FF-ANRED = IT_FF-ANRED.

is_ff-name1 = it_ff-name1.

is_ff-sortl = it_ff-sortl.

is_ff-land1 = it_ff-land1.

is_ff-spras = it_ff-spras.

append is_ff.

vs_count = vs_count + 1.

else.

read table it_ff index v_index.

if_ff-lifnr = it_ff-lifnr.

  • IF_FF-BUKRS = IT_FF-BUKRS.

  • IF_FF-KTOKK = IT_FF-KTOKK.

  • IF_FF-ANRED = IT_FF-ANRED.

if_ff-name1 = it_ff-name1.

if_ff-sortl = it_ff-sortl.

if_ff-land1 = it_ff-land1.

if_ff-spras = it_ff-spras.

append if_ff.

vf_count = vf_count + 1.

endif.

v_index = v_index + 1.

if not it_msg[] is initial.

loop at it_msg.

call function 'FORMAT_MESSAGE'

exporting

id = it_msg-msgid

lang = '-D'

no = it_msg-msgnr

v1 = it_msg-msgv1

v2 = it_msg-msgv2

v3 = it_msg-msgv3

v4 = it_msg-msgv4

importing

msg = lv_msg

exceptions

not_found = 1

others = 2.

if sy-subrc = 0.

write:/ lv_msg.

endif.

endloop.

endif.

clear: it_bdc[],

it_msg[].

endloop.

vt_count = vs_count + vf_count.

write:/ 'total = ' , vt_count.

write:/ 'succesfully = ' , vs_count.

loop at is_ff.

write:/ is_ff-lifnr,

  • IS_FF-BUKRS,

is_ff-ktokk,

  • IS_FF-ANRED,

is_ff-name1,

is_ff-sortl,

is_ff-land1.

  • is_ff-spras.

endloop.

  • write:/ 'Failed DATA = ' , vf_count.

loop at if_ff.

write:/ if_ff-lifnr,

  • IF_FF-BUKRS,

if_ff-ktokk,

  • IF_FF-ANRED,

if_ff-name1,

if_ff-sortl,

if_ff-land1.

  • if_ff-spras.

endloop.

endform. " generate

&----


*& Form POPULATE

&----


  • text

----


  • -->P_0182 text

  • -->P_0183 text

  • -->P_0184 text

----


form populate using value(p_val1)

value(p_val2)

value(p_val3).

if not p_val1 is initial.

it_bdc-program = p_val1.

it_bdc-dynpro = p_val2.

it_bdc-dynbegin = p_val3.

else.

it_bdc-fnam = p_val2.

it_bdc-fval = p_val3.

endif.

append it_bdc.

clear it_bdc.

endform. " POPULATE

&----


*& Form close_session

&----


  • text

----


form close_session .

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_session

&----


*& Form bdc_insert

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form bdc_insert .

data: lv_date like sy-datum.

lv_date = sy-datum - 1.

call function 'BDC_OPEN_GROUP'

exporting

client = sy-mandt

  • DEST = FILLER8

group = 'ZSR'

holddate = lv_date

keep = 'X'

user = sy-uname

  • RECORD = FILLER1

  • PROG = SY-CPROG

  • 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.

loop at if_ff.

perform populate using :

'SAPMF02K' '0100' 'X',

'' 'BDC_OKCODE' '/00',

'' 'RF02K-LIFNR' if_ff-lifnr,

  • '' 'RF02K-BUKRS' if_ff-bukrs,

'' 'RF02K-KTOKK' if_ff-ktokk,

'SAPMF02K' '0110' 'X',

'' 'BDC_OKCODE' '/00',

  • '' 'LFA1-ANRED' if_ff-anred,

'' 'LFA1-NAME1' if_ff-name1,

'' 'LFA1-SORTL' if_ff-sortl,

'' 'LFA1-LAND1' if_ff-land1,

'SAPMF02K' '0120' 'X',

'' 'BDC_OKCODE' '/00',

  • '' 'LFA1-KUNNR' if_ff-kunnr,

  • 'SAPMF02K' '0130' 'X',

  • '' 'BDC_OKCODE' '=ENTR',

  • 'SAPMF02K' '0210' 'X',

  • '' 'BDC_OKCODE' '/00',

  • 'SAPMF02K' '0215' 'X',

  • '' 'BDC_OKCODE' '/00',

  • 'SAPMF02K' '0220' 'X',

  • '' 'BDC_OKCODE' '/00',

'SAPLSPO1' '0300' 'X',

'' 'BDC_OKCODE' '=YES'.

call function 'BDC_INSERT'

exporting

tcode = 'XK01'

  • POST_LOCAL = NOVBLOCAL

  • PRINTING = NOPRINT

  • SIMUBATCH = ' '

  • CTUPARAMS = ' '

tables

dynprotab = it_bdc.

  • EXCEPTIONS

  • INTERNAL_ERROR = 1

  • NOT_OPEN = 2

  • QUEUE_ERROR = 3

  • TCODE_INVALID = 4

  • PRINTING_INVALID = 5

  • POSTING_INVALID = 6

  • OTHERS = 7

.

clear it_bdc[].

if sy-subrc <> 0.

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

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

endif.

endloop.

endif.

endform. " bdc_insert

Read only

Former Member
0 Likes
1,861

Hi

1)Could any one give in steps.

Transaction Recorder (SHDB)

How to Upload Presentation Server Flat file to SAP R/3 system???

How to upload application server file to R/3 system?

Definition

Example - Call Transaction Method

Transaction Recorder (SHDB)

Before you work with the Batch Input methods, you should know the purpose of the tool

Transaction Recorder.

Use:

You can use the transaction recorder to record a series of transactions and their screens.

Features:

You can use the recording to create

Data transfer programs that use batch input or CALL TRANSACTION

Batch input sessions

Test data

Function modules.

Note: It doesn’t record F1, F4 and Scrollbar movements

Upload Flat file from Presentation Server to SAP R/3

CALL FUNCTION ‘GUI_UPLOAD'

EXPORTING

CODEPAGE = ‘IBM'

FILENAME = P_UFILE

FILETYPE = 'DAT'

TABLES

DATA_TAB = INT_TAB

EXCEPTIONS

CONVERSION_ERROR = 1

FILE_OPEN_ERROR = 2

FILE_READ_ERROR = 3

INVALID_TYPE = 4

NO_BATCH = 5

UNKNOWN_ERROR = 6

INVALID_TABLE_WIDTH = 7

GUI_REFUSE_FILETRANSFER = 8

CUSTOMER_ERROR = 9

OTHERS = 10 .

IF SY-SUBRC NE 0.

MESSAGE E999(FR) WITH 'ERROR IN FILE UPLOAD'.

ENDIF.

Upload file from application server to SAP R/3

Open the the application server file

OPEN DATASET <dsn> FOR INPUT <mode>

Read the data from application server file

READ DATASET <dsn> INTO <wa>

And then close the application server file

CLOSE DATASET <dsn>

Definition- Declaring BDC Table

DATA: BDC_TAB LIKE STANDARD TABLE OF

BDCDATA INITIAL SIZE 6

WITH HEADER LINE .

The internal table used to collect the transaction’s information must be declared “LIKE BDCDATA”.

Filling BDC Table – Method #1

FORM FILL_BDC_TAB.

REFRESH BDC_TAB.

CLEAR BDC_TAB.

BDC_TAB-PROGRAM = ‘SAPMF02K’.

BDC_TAB-DYNPRO = ‘01016’.

BDC_TAB-DYNBEGIN = ‘X’.

APPEND BDC_TAB.

CLEAR BDC_TAB.

BDC_TAB-FNAM = ‘RF02K-LIFNR’.

BDC_TAB-FVAL = ‘TEST1’.

APPEND BDC_TAB.

CLEAR BDC_TAB.

BDC_TAB-FNAM = ‘RF02K-D0010’.

BDC_TAB-FVAL = ‘X’.

APPEND BDC_TAB.

CLEAR BDC_TAB.

BDC_TAB-PROGRAM = ‘SAPMF02K’.

BDC_TAB-DYNPRO = ‘0110’.

BDC_TAB-DYNBEGIN = ‘X’.

APPEND BDC_TAB.

CLEAR BDC_TAB.

BDC_TAB-FNAM = ‘LFA1-STRAS’.

BDC_TAB-FVAL = ‘123 Main St.’.

APPEND BDC_TAB.

CLEAR BDC_TAB.

BDC_TAB-FNAM = ‘BDC_OKCODE’.

BDC_TAB-FVAL = ‘/11’.

APPEND BDC_TAB.

ENDFORM.

Filling BDC Table – Method #2

FORM FILL_BDC_TAB.

REFRESH BDC_TAB.

PERFORM POPULATE_BDC_TAB

USING:

‘1’ ‘SAPMF02K’ ‘0106’,

‘ ‘ ‘RF02K-LIFNR’ ‘TEST1’,

‘ ‘ ‘RF02K-D0010’ ‘X’,

‘1’ ‘SAPMF02K’ ‘0110’,

‘ ‘ ‘LFA1-STRAS’, ‘123 Main St.’,

‘ ‘ ‘BDC_OKCODE’, ‘/11’.

ENDFORM.

FORM POPULATE_BDC_TAB USING FLAG VAR1 VAR2.

CLEAR BDC_TAB.

IF FLAG = ‘1’.

BDC_TAB-PROGRAM = VAR1.

BDC_TAB-DYNPRO = VAR2..

BDC_TAB-DYNBEGIN = ‘X’.

ELSE.

BDC_TAB-FNAM = VAR1.

BDC_TAB-FVAL = VAR2.

ENDIF.

APPEND BDC_TAB.

ENDFORM.

This two subroutine method to fill the BDC table is preferable because the “POPULATE_BDC_TABLE” subroutine is reusable throughout all batch input programs.

Example #1 - Change Vendor (Call Transaction Method)

Example #1- Declaration Section

REPORT Y180DM10.

DATA: BDC_TAB LIKE STANDARD TABLE OF

BDCDATA INITIAL SIZE 6 WITH HEADER LINE.

INFILE(20) VALUE ‘/tmp/bc180_file4’.

DATA: BEGIN OF INREC.

VENDNUM LIKE LFA1-LIFNR.

STREET LIKE LFA1-STRAS.

END OF INREC.

PARAMETERS: DISPMODE DEFAULT ‘A’,

UPDAMODE DEFAULT ‘S’.

START-OF-SELECTION.

OPEN DATASET INFILE

FOR INPUT IN TEXT MODE.

DO.

READ DATASET INFILE INTO INREC.

IF SY-SUBRC < > 0. EXIT. ENDIF.

PERFORM FILL_BDC_TAB.

CALL TRANSACTION ‘FK02’

USING BDC_TAB

MODE DISPMODE

UPDATE UPDAMODE.

IF SY-SUBRC < > 0.

WRITE: /‘ERROR’.

ENDIF.

ENDDO.

CLOSE DATASET INFILE.

synchronous updating

DO.

………

PERFORM FILL_BDC_TAB.

CALL TRANSACTION ‘FK02’

USING BDC_TAB

MODE ‘N’

UPDATE ‘S’.

IF SY-SUBRC < > 0.

WRITE: /‘ERROR’.

ENDIF.

ENDDO.

With synchronous updating, we can check SY-SUBRC to determine the success of the transaction and the actual update to the database.

asynchronous updating

DO.

………

PERFORM FILL_BDC_TAB.

CALL TRANSACTION ‘FK02’

USING BDC_TAB

MODE ‘N’

UPDATE ‘A’.

IF SY-SUBRC < > 0.

WRITE: /‘ERROR’.

ENDIF.

ENDDO.

With asynchronous updating, we can check SY-SUBRC to determine the success of the transaction only, not the actual update to the database.

Error Handling

Write an error report.

Send the record(s) in error to an error file.

Create a batch input session with the record(s) in error.

To store error messages ( CALL TRANSACTION )

data: begin of Tab_Mess occurs 0.

include structure bdcmsgcoll.

data : end of Tab_Mess,

CALL TRANSACTION ‘FK02’ USING BDC_TAB MODE ‘N’ UPDATE ‘S’

MESSAGES INTO TAB_MESS.

IF SY-SUBRC NE 0.

WRITE: / Tab_MESS-TCODE, Tab_MESS-DYNUMB, Tab_MESS-MSGTYP ,

Tab_MESS-MSGID.

ENDIF.

2)what is the role of ABAPER in it

total BDC specification is given by Functional consultant , our role in BDC is to develop a program for them , max work will be done by ABAPERS

3)Could any one give some best scenario ,where we will use BDC ,nowadays with some business requirement.

suppose one client useing some non SAP system like morphis or mainframes etc..supose that client wants to change the technology to SAP then that total DATA available in that old technology must be uploaded into SAP system

4)In real time whether they use Call transaction or session method

maximum they use CALL TRANSACTION

now a days they are useing LSMW

7)Whether Nowadays ,are we using BDC

useing but not more

now days they are useing LSMW also

<b>reward if useful</b>