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
801

HI ,

This prog is not exe. can anyone of u check out.

TABLES : lfa1, rf02k.

DATA: msg(255) TYPE c.

DATA : BEGIN OF itab OCCURS 0 ,

lifnr LIKE rf02k-lifnr,

ktokk LIKE rf02k-ktokk,

name1 LIKE lfa1-name1,

sortl LIKE lfa1-sortl,

land1 LIKE lfa1-land1,

spras LIKE lfa1-spras,

END OF itab.

DATA : btab LIKE bdcdata OCCURS 0 WITH HEADER LINE,

messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.

LOOP AT itab.

REFRESH btab.

PERFORM form1.

CALL TRANSACTION 'XK01' USING btab MODE 'A' UPDATE 'S' MESSAGES INTO messtab.

ENDLOOP.

LOOP AT messtab.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = MESSTAB-MSGID

LANG = 'E'

NO = MESSTAB-MSGNR

V1 = MESSTAB-MSGV1

V2 = MESSTAB-MSGV2

V3 = MESSTAB-MSGV3

V4 = MESSTAB-MSGV4

IMPORTING

MSG = MSG

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2

.

IF sy-subrc <> 0.

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

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

ENDIF.

WRITE:/ MSG.

ENDLOOP.

*WRITE:/ 'WELCOME'.

FORM FORM1.

PERFORM FORM_FILL USING: 'X' 'SAPMF02K' '100',

' ' 'RF02K-LIFNR' ITAB-LIFNR,

' ' 'RF02K-KTOKK' ITAB-KTOKK,

' ' 'BDC_OKCODE' '/00',

'X' 'SAPMF02K' '110',

' ' 'LFA1-NAME1' ITAB-NAME1,

' ' 'LFA1-SORTL' ITAB-SORTL,

' ' 'LFA1-LAND1' ITAB-LAND1,

' ' 'LFA1-SPRAS' ITAB-SPRAS,

' ' 'BDC_OKCODE' '/00',

'X' 'SAPMF02K' '120',

' ' 'BDC_CURSOR' 'LFA1-KUNNR',

' ' 'BDC_OKCODE' '/00',

'X' 'SAPMF02K' '130',

' ' 'bdc_cursor' 'lfbk-banks(01)',

' ' 'bdc_okcode' '/00',

'X' 'SAPLSP01' '300',

' ' 'bdc_okcode' '/=yes'.

ENDFORM.

FORM FORM_FILL USING P1 P2 P3.

IF P1 = 'X'.

BTAB-DYNBEGIN = P1.

BTAB-PROGRAM = P2.

BTAB-DYNPRO = P3.

APPEND BTAB.

ELSE.

BTAB-FNAM = P2.

BTAB-FVAL = P3.

APPEND BTAB.

ENDIF.

CLEAR BTAB.

ENDFORM.

Regards,

kb

7 REPLIES 7
Read only

hymavathi_oruganti
Active Contributor
0 Likes
776

pls explain clearly what is ur doubt.

Read only

Former Member
0 Likes
776

Hi

the BDC program should be in this format

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

<b>Transaction Recorder (SHDB)</b>

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

Transaction Recorder.

<b>Use:</b>

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

<b>Features:</b>

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

<b>Upload Flat file from Presentation Server to SAP R/3</b>

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.

<b>Upload file from application server to SAP R/3</b>

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

<b>Filling BDC Table – Method #1</b>

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.

<b>Filling BDC Table – Method #2</b>

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.

<b>Example #1 - Change Vendor (Call Transaction Method)</b>

<u>

Example #1- Declaration Section</u>

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.

<b>synchronous updating</b>

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.

<b>asynchronous updating</b>

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.

<b>Error Handling</b>

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.

<b>i am giving you example for Change Vendor you practice for ur tcode</b>

For our example, we will use the “Change Vendor” transaction (“FK02”) to add a street address to an already existing vendor.

<b>Step #1</b>

Use “System&#61664;Status” menu path to determine online program name (SAPMF02K), screen number (0110)

<b>Step #2</b>

Use “F1” key and “Technical Info” pushbutton in each screen field to be filled to determine the field name.

<b>

Step #3</b>

Determine how to proceed in the transaction

(save the record by clicking on the ‘Save’ pushbutton or pressing the ‘F11’ key).

<b>

BDC Table Contents</b>

After researching the transaction we can determine the contents of the BDC table.

PROGRAM DYNPRO DYNBEGIN FNAM FVAL

SAMPF02K 0106 X

RF02K-LIFNR TEST1

RF02K-D0110 X

SAMPF02K 0110 X

LFA1-STRAS 123 Main St.

BDC_OKCODE /11

<b>

Batch Input Methods</b>

“CALL TRANSACTION USING”

STATEMENT

<b>Call transaction - for data transfer</b>

Processing batch input data with CALL TRANSACTION USING is the faster of the two recommended data transfer methods. In this method, legacy data is processed inline in your data transfer program.

Syntax:

CALL TRANSACTION <tcode>

USING <bdc_tab>

MODE <mode>

UPDATE <update>

A Display all

E Display errors only

N No display

S Synchronous

A Asynchronous

L Local update

<b>The process flow of CALL TRANSACTION</b>

A program that uses CALL TRANSACTION USING to process legacy data should execute thefollowing steps:

Prepare a BDCDATA structure for the transaction that you wish to run.

Prepare a internal table to store error messages Tab_Mess like structure of BDCMSGCOLL.

With a CALL TRANSACTION USING statement, call the transaction and prepare the BDCDATA structure. For example:

CALL TRANSACTION ‘MM01' USING BDCDATA MODE 'A' UPDATE 'S'. MESSAGES INTO TAB_MESS.

IF SY-SUBRC <> 0.

<Error_handling>.

ENDIF.

<b>Overview of Batch Input Session</b>

The first batch input method is to create a batch input session. It is the processing of this batch input session that updates the database, not the execution of the batch input program.

<b>Reward if usefull</b>

Read only

Former Member
0 Likes
776

with out uploading/populating any data into the internal table <b>ITAB</b> the program will not be executed/display any output.

Read only

Former Member
0 Likes
776

Hi,

In the code , I haven't found where you are populating table ITAB.

Populate the ITAB first.

Regards,

Tanmay

Read only

varma_narayana
Active Contributor
0 Likes
776

Hi..

See the Changes :

DATA: msg(255) TYPE c.

DATA : BEGIN OF itab OCCURS 0 ,

lifnr LIKE rf02k-lifnr,

ktokk LIKE rf02k-ktokk,

name1 LIKE lfa1-name1,

sortl LIKE lfa1-sortl,

land1 LIKE lfa1-land1,

spras LIKE lfa1-spras,

END OF itab.

DATA : btab LIKE bdcdata OCCURS 0 WITH HEADER LINE,

messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.

<<<<HERE YOU HAVE TO CALL THE function module GUI_UPLOAD>>>

<<To get the data of Flat file into the internal table ITAB>>>>>

LOOP AT itab.

REFRESH btab.

PERFORM form1.

CALL TRANSACTION 'XK01' USING btab MODE 'A' UPDATE 'S' MESSAGES INTO messtab.

ENDLOOP.

<b>reward if Helpful.</b>

Read only

Former Member
0 Likes
776

REPLACE THIS WITH. BECAUSE BDCDATA HAVE VARIABLES

PROGRAM

DYNPRO

DYNBEGIN

FNAM

FVAL

WHERE FNAM AND FVAL ARE FIELD NAME AND FIELD VALUE

DYNPRO IS SCREEN AND PROGRAM IS PROGRAM

DYNBEGIN FOR CURSOR ON SCREEN.

SECOND THING

USE UPLOAD / GUI_UPLOAD / WS_UPLOAD FUNCTION TO POPULATE

ITAB

FORM FORM_FILL USING P1 P2 P3.

IF P1 = 'X'.

BTAB-DYNBEGIN = P1.

BTAB-PROGRAM = P2.

BTAB-DYNPRO = P3.

APPEND BTAB.

ELSE.

BTAB-FNAM = P2.

BTAB-FVAL = P3.

APPEND BTAB.

ENDIF.

CLEAR BTAB.

ENDFORM.

<b>WITH</b>

&----


*& Form BDC_DYNPRO

&----


FORM BDC_DYNPRO USING PROGRAM DYNPRO.

CLEAR BDCDATA.

BDCDATA-PROGRAM = PROGRAM.

BDCDATA-DYNPRO = DYNPRO.

BDCDATA-DYNBEGIN = 'X'.

APPEND BDCDATA.

ENDFORM. " BDC_DYNPRO

&----


*& Form BDC_FIELD

&----


FORM BDC_FIELD USING FNAM FVAL.

CLEAR BDCDATA.

BDCDATA-FNAM = FNAM.

BDCDATA-FVAL = FVAL.

APPEND BDCDATA.

ENDFORM. " BDC_FIELD

REWARD IF USEFUL.

AMIT SINGLA

Message was edited by:

Amit Singla

Read only

Former Member
0 Likes
776

thanks