‎2007 Nov 06 8:23 AM
Can anybody give me step by step procedure for creating BDC for VA01 trscation.
‎2007 Nov 06 9:27 AM
Hi,
Please go through the following lines of code:
Batch Input Program for Transaction VA01
How to Create a batch input program for transaction VA01.
The scenerio is
Input fields: Manditory fields to create a new Sales Order using VA01.
Hint: Take an existing Sales Order and use the master data which was previously used.
Conditions:
1)Upload the input data from a text file stored in your note pc.
2)Use call transaction method.
3)Your program should allow to input the file path and file name to select the data.
Here I'm attaching BDC Code for 'VA01'.
report ZBDC3_VA01
no standard page heading line-size 255.
include bdcrecx1.
types : begin of ty_head,
auart(4),
vkorg(4),
vtweg(2),
spart(2),
kunnr(10),
bstkd(10),
end of ty_head.
types: begin of ty_item,
matnr(18) type c,
kwmeng(13) type c,
end of ty_item.
data: it_head type table of ty_head. " Header
data: wa_head like line of it_head.
data: it_item type table of ty_item. " Item
data: wa_item like line of it_item.
data:v_kwmeng(30) type c,
v_mabnr(30) type c.
DATA: VAL(2) TYPE N VALUE 01.
DATA : w_file2 TYPE string,
w_file1 TYPE string.
PARAMETERS: filename LIKE rlgrap-filename.
PARAMETERS: filenam1 LIKE rlgrap-filename.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR filename.
CALL FUNCTION 'F4_FILENAME'
IMPORTING
file_name = filename.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR filenam1.
CALL FUNCTION 'F4_FILENAME'
IMPORTING
file_name = filenam1.
START-OF-SELECTION.
w_file2 = filename.
w_file1 = filenam1.
HEADER ************************
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = w_file2
filetype = 'ASC'
has_field_separator = 'X'
TABLES
data_tab = it_head.
Item *******************
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = w_file1
filetype = 'ASC'
has_field_separator = 'X'
TABLES
data_tab = it_item.
perform open_group.
loop at it_head into wa_head.
.
perform bdc_dynpro using 'SAPMV45A' '0101'.
perform bdc_field using 'BDC_CURSOR'
'VBAK-AUART'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'VBAK-AUART'
WA_HEAD-AUART.
perform bdc_field using 'VBAK-VKORG'
WA_HEAD-VKORG.
perform bdc_field using 'VBAK-VTWEG'
WA_HEAD-VTWEG.
perform bdc_field using 'VBAK-SPART'
WA_HEAD-SPART.
perform bdc_dynpro using 'SAPMV45A' '4001'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'VBKD-BSTKD'
WA_HEAD-BSTKD.
perform bdc_field using 'VBKD-BSTDK'
'30.01.2006'.
perform bdc_field using 'KUAGV-KUNNR'
WA_HEAD-KUNNR.
perform bdc_field using 'RV45A-KETDAT'
'30.01.2006'.
perform bdc_field using 'RV45A-KPRGBZ'
'D'.
perform bdc_field using 'VBKD-ZTERM'
'0001'.
perform bdc_field using 'VBKD-INCO1'
'CIF'.
perform bdc_field using 'VBKD-INCO2'
'COST INSUSRABCE FRIEGHT'.
loop at it_item into wa_item .
CONCATENATE 'RV45A-MABNR(' '0' VAL ')' INTO v_MABNR. CONCATENATE 'RV45A-KWMENG(' '0' VAL ')' INTO v_kwmeng.
perform bdc_field using 'BDC_CURSOR'
v_kwmeng.
perform bdc_field using v_mabnr
wa_item-matnr.
perform bdc_field using v_kwmeng
wa_item-kwmeng.
perform bdc_dynpro using 'SAPMV45A' '4001'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
VAL = VAL + 1.
IF VAL > 5.
VAL = 5.
ENDIF.
endloop.
VAL = 01.
perform bdc_dynpro using 'SAPMV45A' '4001'.
perform bdc_field using 'BDC_OKCODE'
'=SICH'.
perform bdc_transaction using 'VA01'.
endloop.
perform close_group.
reward is usefull.
Thanks.
patil
‎2007 Nov 06 9:43 AM
Hi Harman,
<b>BDC:</b>
<b>Batch Data Communication (BDC)</b> 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.
Differences between Call Transaction and Sessions Method:
Session method.
1) synchronous processing.
2) can tranfer large amount of data.
3) processing is slower.
4) error log is created
5) data is not updated until session is processed.
6) generally used for back ground jobs.
7) at atime we can update to more than one screens.
Call transaction.
1) asynchronous processing
2) can transfer small amount of data
3) processing is faster.
4) errors need to be handled explicitly
5) data is updated automatically
6) for background n fore ground jobs.
7) at atime we can update to a single screen.
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
Check these link:
http://www.sap-img.com/abap/difference-between-batch-input-and-call-transaction-in-bdc.htm
http://www.sap-img.com/abap/question-about-bdc-program.htm
http://www.itcserver.com/blog/2006/06/30/batch-input-vs-call-transaction/
http://www.planetsap.com/bdc_main_page.htm
Sample BDC
report ZABSALES_ORDER no standard page heading line-size 255.
TABLES: vbak, vbap.
DATA: bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
DATA: messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
SELECTION-SCREEN BEGIN OF SCREEN 500 AS WINDOW.
SELECTION-SCREEN BEGIN OF BLOCK salesblock WITH FRAME TITLE text-001.
SELECTION-SCREEN SKIP 1.
PARAMETERS : Order_ty LIKE vbak-auart DEFAULT 'OR'
modif id SC1,
Customer LIKE kuagv-kunnr OBLIGATORY VALUE CHECK,
Purchase LIKE vbkd-bstkd OBLIGATORY VALUE CHECK,
Material LIKE vbap-matnr OBLIGATORY VALUE CHECK,
Quantity LIKE rv45a-kwmeng OBLIGATORY VALUE CHECK.
SELECTION-SCREEN END OF BLOCK salesblock.
SELECTION-SCREEN END OF SCREEN 500.
CALL SELECTION-SCREEN 500.
*At selection-screen on Order_ty.
*IF Order_ty <> 'OR'.
MESSAGE E080(ZVIKALP).
ENDIF.
start-of-selection.
perform bdc_dynpro using 'SAPMV45A' '0101'.
perform bdc_field using 'BDC_CURSOR'
'VBAK-AUART'.
perform bdc_field using 'BDC_OKCODE'
'=UER1'.
perform bdc_field using 'VBAK-AUART'
Order_ty.
perform bdc_dynpro using 'SAPMV45A' '4001'.
perform bdc_field using 'BDC_OKCODE'
'=SICH'.
perform bdc_field using 'VBKD-BSTKD'
Purchase.
perform bdc_field using 'KUAGV-KUNNR'
Customer.
perform bdc_dynpro using 'SAPMSSY0' '0120'.
perform bdc_field using 'BDC_CURSOR'
'04/05'.
perform bdc_field using 'BDC_OKCODE'
'SICH'.
perform bdc_field using 'RV45A-KETDAT'
'06-05-2005'.
perform bdc_field using 'RV45A-KPRGBZ'
'D'.
perform bdc_field using 'VBKD-PRSDT'
'05-29-2005'.
perform bdc_field using 'BDC_CURSOR'
'RV45A-KWMENG(01)'.
perform bdc_field using 'RV45A-MABNR(01)'
Material.
perform bdc_field using 'RV45A-KWMENG(01)'
Quantity.
perform bdc_dynpro using 'SAPLSPO2' '0101'.
perform bdc_field using 'BDC_OKCODE'
'=OPT1'.
CALL TRANSACTION 'VA01' USING bdcdata
MODE 'N'
UPDATE 'A'
MESSAGES INTO messtab.
loop at messtab.
if messtab-msgtyp = 'S'.
FORMAT COLOR 5.
elseif messtab-msgtyp = 'E'.
FORMAT COLOR 6.
ENDIF.
write: / messtab-msgtyp, messtab-msgnr.
endloop.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF SCREEN-GROUP1 = 'SC1'.
screen-input = 0.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
----
Start new screen *
----
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM.
----
Insert field *
----
FORM BDC_FIELD USING FNAM FVAL.
IF FVAL <> ' '.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDIF.
ENDFORM.
***********By session method
report ZAB_PURCHASE no standard page heading line-size 255.
tables: ekko, ekpo, t100.
DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF T_MSG OCCURS 0.
INCLUDE STRUCTURE T100.
DATA: END OF T_MSG.
*include bdcrecx1.
*SELECTION-SCREEN BEGIN OF SCREEN 500 AS WINDOW.
SELECTION-SCREEN BEGIN OF BLOCK salesblock WITH FRAME TITLE text-001.
PARAMETERS : Vendor like Ekko-lifnr OBLIGATORY,
Order_ty like RM06E-BSART obligatory,
Pur_org like ekko-ekorg obligatory value check,
Pur_grp like ekko-ekgrp obligatory value check,
Material like ekpo-ematn obligatory value check,
Quantity(13) type n,
Plant like ekpo-werks obligatory value check.
SELECTION-SCREEN END OF BLOCK salesblock.
*SELECTION-SCREEN END OF SCREEN 500.
*CALL SELECTION-SCREEN 500.
TOP-OF-PAGE.
WRITE :/40 'Creating Purchase Order' COLOR 4 INTENSIFIED ON INVERSE ON
.
ULINE.
FORMAT COLOR 7 INVERSE ON.
WRITE :/1(20) 'Mesaage Type',
25(20) 'Message'.
ULINE.
start-of-selection.
*perform open_group.
perform bdc_dynpro using 'SAPMM06E' '0100'.
perform bdc_field using 'BDC_CURSOR'
'EKKO-EKGRP'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'EKKO-LIFNR'
Vendor.
perform bdc_field using 'RM06E-BSART'
Order_ty.
perform bdc_field using 'RM06E-BEDAT'
'05-30-2005'.
perform bdc_field using 'EKKO-EKORG'
Pur_org.
perform bdc_field using 'EKKO-EKGRP'
Pur_grp.
perform bdc_field using 'RM06E-LPEIN'
'T'.
perform bdc_dynpro using 'SAPMM06E' '0120'.
perform bdc_field using 'BDC_CURSOR'
'EKPO-WERKS(01)'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'EKPO-EMATN(01)'
Material.
perform bdc_field using 'EKPO-MENGE(01)'
Quantity.
perform bdc_field using 'EKPO-WERKS(01)'
Plant.
*perform bdc_transaction using 'ME21'.
*CALL TRANSACTION 'ME21' USING BDCDATA
MODE 'A'
UPDATE 'A'
MESSAGES INTO MESSTAB.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
DEST = FILLER8
GROUP = 'ZAP3'
HOLDDATE = FILLER8
KEEP = 'X'
USER = SY-UNAME
RECORD = FILLER1
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.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'ME21'
POST_LOCAL = NOVBLOCAL
PRINTING = NOPRINT
TABLES
dynprotab = 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.
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.
end-of-selection.
loop at messtab.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = messtab-MSGID
LANG = 'EN'
NO = messtab-msgnr
V1 = messtab-MSGV1
V2 = messtab-MSGV2
V3 = messtab-MSGV3
V4 = messtab-MSGV4
IMPORTING
MSG = T_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.
if messtab-msgtyp = 'S'.
FORMAT COLOR 5 inverse on.
elseif messtab-msgtyp = 'E'.
FORMAT COLOR 6 inverse on.
else.
FORMAT COLOR 3 inverse on.
ENDIF.
WRITE : /1(20) messtab-msgtyp ,
25(60) t_msg.
endloop.
*perform close_group.
----
Start new screen *
----
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM.
----
Insert field *
----
FORM BDC_FIELD USING FNAM FVAL.
IF FVAL <> ' '.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDIF.
ENDFORM.
<b>Reward points if Useful</b>
Regards
Gokul
‎2007 Nov 06 9:49 AM
Hi
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 doesnt 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 transactions 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.
Reward if usefull