‎2007 Feb 28 8:53 AM
hi friends could you please guide me to write BDC call Transaction program to upload Va01. I need any example programs and the pattern of the flat file to enter, please i am new to BDC.
‎2007 Feb 28 9:02 AM
Hi Kalyan,
BDC (Batch Data Communication) works based on the data in the Internal table of structure "BDCDATA", and some of the very important lines with information (in sequence) Dynpro, Cursor-field and Data Fields, then call Transaction / Session Creation Logic.
In Call Transaction method of BDC, the Message is handled manually using the structure "BDCMSGCOLL" and by refering to messages in "T100" Table. [Refer the standard Include BECRECX1 for more information.
BDC can be created by Recording tool or my scracth creating a new program. Use transaction code 'SHDB'.
A sample code by using the Recording method (Here both Call transaction and Session Method of BDC will be created by standard Recording tool [this you can find in include BDCRECX1])
**********************
Code Only the Program, withoug Include BDCRECX1 (This std, inclu you can find)
**********************************************
***INCLUDE BDCRECX1.
for programs doing a data transfer by creating a batch-input session
and
for programs doing a data transfer by CALL TRANSACTION USING
selection-screen begin of line.
parameters session radiobutton group ctu. "create session
selection-screen comment 3(20) text-s07 for field session.
selection-screen position 45.
parameters ctu radiobutton group ctu. "call transaction
selection-screen comment 48(20) text-s08 for field ctu.
selection-screen end of line.
selection-screen begin of line.
selection-screen comment 3(20) text-s01 for field group.
selection-screen position 25.
parameters group(12). "group name of session
selection-screen comment 48(20) text-s05 for field ctumode.
selection-screen position 70.
parameters ctumode like ctu_params-dismode default 'N'.
"A: show all dynpros
"E: show dynpro on error only
"N: do not display dynpro
selection-screen end of line.
selection-screen begin of line.
selection-screen comment 3(20) text-s02 for field user.
selection-screen position 25.
parameters: user(12) default sy-uname. "user for session in batch
selection-screen comment 48(20) text-s06 for field cupdate.
selection-screen position 70.
parameters cupdate like ctu_params-updmode default 'L'.
"S: synchronously
"A: asynchronously
"L: local
selection-screen end of line.
selection-screen begin of line.
selection-screen comment 3(20) text-s03 for field keep.
selection-screen position 25.
parameters: keep as checkbox. "' ' = delete session if finished
"'X' = keep session if finished
selection-screen comment 48(20) text-s09 for field e_group.
selection-screen position 70.
parameters e_group(12). "group name of error-session
selection-screen end of line.
selection-screen begin of line.
selection-screen comment 3(20) text-s04 for field holddate.
selection-screen position 25.
parameters: holddate like sy-datum.
selection-screen comment 51(17) text-s02 for field e_user.
selection-screen position 70.
parameters: e_user(12) default sy-uname. "user for error-session
selection-screen end of line.
selection-screen begin of line.
selection-screen comment 51(17) text-s03 for field e_keep.
selection-screen position 70.
parameters: e_keep as checkbox. "' ' = delete session if finished
"'X' = keep session if finished
selection-screen end of line.
selection-screen begin of line.
selection-screen comment 51(17) text-s04 for field e_hdate.
selection-screen position 70.
parameters: e_hdate like sy-datum.
selection-screen end of line.
selection-screen skip.
selection-screen begin of line.
selection-screen comment 1(33) text-s10 for field nodata.
parameters: nodata default '/' lower case. "nodata
selection-screen end of line.
selection-screen begin of line.
selection-screen comment 1(33) text-s11 for field smalllog.
parameters: smalllog as checkbox. "' ' = log all transactions
"'X' = no transaction logging
selection-screen end of line.
----
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.
----
at selection screen *
----
at selection-screen.
group and user must be filled for create session
if session = 'X' and
group = space or user = space.
message e613(ms).
endif.
----
open dataset *
----
form open_dataset using p_dataset.
open dataset p_dataset
for input in text mode
encoding default.
if sy-subrc <> 0.
write: / text-e00, sy-subrc.
stop.
endif.
endform.
----
close dataset *
----
form close_dataset using p_dataset.
close dataset p_dataset.
endform.
----
create batchinput session *
(not for call transaction using...) *
----
form open_group.
if session = 'X'.
skip.
write: /(20) 'Create group'(i01), group.
skip.
open batchinput group
call function 'BDC_OPEN_GROUP'
exporting client = sy-mandt
group = group
user = user
keep = keep
holddate = holddate.
write: /(30) 'BDC_OPEN_GROUP'(i02),
(12) 'returncode:'(i05),
sy-subrc.
endif.
endform.
----
end batchinput session *
(call transaction using...: error session) *
----
form close_group.
if session = 'X'.
close batchinput group
call function 'BDC_CLOSE_GROUP'.
write: /(30) 'BDC_CLOSE_GROUP'(i04),
(12) 'returncode:'(i05),
sy-subrc.
else.
if e_group_opened = 'X'.
call function 'BDC_CLOSE_GROUP'.
write: /.
write: /(30) 'Fehlermappe wurde erzeugt'(i06).
e_group_opened = ' '.
endif.
endif.
endform.
----
Start new transaction according to parameters *
----
form bdc_transaction using tcode.
data: l_mstring(480).
data: l_subrc like sy-subrc.
batch input session
if session = 'X'.
call function 'BDC_INSERT'
exporting tcode = tcode
tables dynprotab = bdcdata.
if smalllog <> 'X'.
write: / 'BDC_INSERT'(i03),
tcode,
'returncode:'(i05),
sy-subrc,
'RECORD:',
sy-index.
endif.
call transaction using
else.
refresh messtab.
call transaction tcode using bdcdata
mode ctumode
update cupdate
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).
else.
write: / messtab.
endif.
endloop.
skip.
endif.
Erzeugen fehlermappe ************************************************
if l_subrc <> 0 and e_group <> space.
if e_group_opened = ' '.
call function 'BDC_OPEN_GROUP'
exporting client = sy-mandt
group = e_group
user = e_user
keep = e_keep
holddate = e_hdate.
e_group_opened = 'X'.
endif.
call function 'BDC_INSERT'
exporting tcode = tcode
tables dynprotab = bdcdata.
endif.
endif.
refresh bdcdata.
endform.
----
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 <> nodata.
clear bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
append bdcdata.
endif.
endform.
You can find many example programs in SDN or Google....
Regards,
Kishore
‎2007 Feb 28 9:02 AM
The flat file layout will be relevant to your needs - no one elses.
Do you really need to use BDC. You should use a BAPI.
‎2007 Feb 28 9:19 AM
Hi kalyan
First u should get the exact requirement
1)we have to analyse the flat file
2)Analyse the corresponding transaction
what is the program name,screen no,what are all the fields to be processed during the updation process.make a note of it.
3) go to SHDB for recording,after recording from there come to ABAP EDITOR by clicking genereate program
4)create an internal table
5) create an internal table related to BDCDATA structure.
via this only we can pass all the data to the database tables
6)create an internal table related to BDCMSGCOLL structure to handle the error
7) upload the falt file to the internal tabe by GUI_UPLOAD
😎 Than to the BDCDATA table
9)call the transaction
syntax : call transaction TCODE using BDCDATA mode 'all screen/errorscreen/no screen' update 'syn/asyn' messages in to bdcmsgcoll structure
10) check subrc value,if not 0
handle the error by using FORMAT_MESSAGE fn module
If u find this will be helpul up to some extend,reward pts
Regards
P.Thangaraj
‎2007 Feb 28 9:22 AM
See the following sample prog for VA01
DATA: bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
DATA : w_auart(4) TYPE c,
w_vkorg(4) TYPE c,
w_vtweg(2) TYPE c,
w_spart(2) TYPE c,
w_kunnr(10) TYPE c,
w_kunrg(10) TYPE c,
w_bstkd(35) TYPE c,
w_bstdk(10) TYPE c,
w_kwmeng(18) TYPE c,
w_zterm(4) TYPE c,
w_inco1(3) TYPE c,
w_inco2(28) TYPE c,
w_augru(3) TYPE c.
DATA : var1 TYPE string,
var2 TYPE c VALUE '(',
var3 TYPE c VALUE ')',
num(2) TYPE c,
flag(1) TYPE c.
DATA : BEGIN OF it_order, " Internal table Structure
auart(4) TYPE c, " Sales Order Type
vkorg(4) TYPE c, " Sales Organization
vtweg(2) TYPE c, " Distribution Channel
spart(2) TYPE c, " Division
kunnr(10) TYPE c, " Sold-to-Party
kunrg(10) TYPE c, " Ship-to-Party
bstkd(35) TYPE c, " Purchase Order No
bstdk(10) TYPE c, " Purchase Order Date
zterm(4) TYPE c, " Payment Terms
inco1(3) TYPE c, " Inco Terms1
inco2(20) TYPE c, " Inco Terms2
augru(3) TYPE c, " Order Reason
mabnr(18) TYPE c, " Material No
kwmeng(18) TYPE c, " Quantity
END OF it_order,
itab LIKE STANDARD TABLE OF it_order WITH HEADER LINE.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETER filename LIKE rlgrap-filename.
PARAMETER session LIKE apqi-groupid.
SELECTION-SCREEN END OF BLOCK b1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR filename.
************************************************************************
Get the file path
************************************************************************
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_filename = filename
def_path = ' '
mask = ',.,..'
mode = 'O'
title = 'Select File'
IMPORTING
filename = filename
EXCEPTIONS
selection_cancel = 1.
CHECK sy-subrc = 0.
START-OF-SELECTION.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
codepage = ' '
filename = filename
filetype = 'ASC'
headlen = ' '
line_exit = ' '
trunclen = ' '
user_form = ' '
user_prog = ' '
dat_d_format = ' '
IMPORTING
FILELENGTH =
TABLES
data_tab = itab
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 <> 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 itab.
CLEAR : w_auart,w_vkorg,w_vtweg,w_spart,w_kunnr,w_kunrg,
w_bstkd,w_bstdk,w_zterm,w_inco1,w_inco2,w_augru.
w_auart = itab-auart.
w_vkorg = itab-vkorg.
w_vtweg = itab-vtweg.
w_spart = itab-spart.
w_kunnr = itab-kunnr.
w_kunrg = itab-kunrg.
w_bstkd = itab-bstkd.
w_bstdk = itab-bstdk.
w_zterm = itab-zterm.
w_inco1 = itab-inco1.
w_inco2 = itab-inco2.
w_augru = itab-augru.
ON CHANGE OF itab-kunnr OR itab-kunrg OR itab-bstkd .
flag = 0.
num = 1.
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' " Order Type
itab-auart.
PERFORM bdc_field USING 'VBAK-VKORG' " Sales Organization
itab-vkorg.
PERFORM bdc_field USING 'VBAK-VTWEG' " Distribution Channel
itab-vtweg.
PERFORM bdc_field USING 'VBAK-SPART' " Division
itab-spart.
PERFORM bdc_dynpro USING 'SAPMV45A' '4001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'VBKD-BSTKD' " PO Number
itab-bstkd.
PERFORM bdc_field USING 'VBKD-BSTDK' " PO Date
itab-bstdk.
PERFORM bdc_field USING 'KUAGV-KUNNR' " Sold to Party
itab-kunnr.
PERFORM bdc_field USING 'KUWEV-KUNNR' " Ship to Party
itab-kunrg.
PERFORM bdc_field USING 'VBKD-ZTERM' " Payment Terms
itab-zterm.
PERFORM bdc_field USING 'VBKD-INCO1' " Inco Terms1
itab-inco1.
PERFORM bdc_field USING 'VBKD-INCO2' " Inco Terms2
itab-inco2.
PERFORM bdc_field USING 'VBAK-AUGRU' " Order Reason
itab-augru.
ENDON.
IF flag = 0.
LOOP AT itab WHERE bstkd = itab-bstkd AND kunnr = itab-kunnr .
var1 = 'RV45A-MABNR'.
CONCATENATE var1 var2 num var3 INTO var1.
PERFORM bdc_field USING var1
itab-mabnr.
var1 = 'RV45A-KWMENG'.
CONCATENATE var1 var2 num var3 INTO var1.
PERFORM bdc_field USING var1
itab-kwmeng.
PERFORM bdc_dynpro USING 'SAPMV45A' '4001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
num = 2.
ENDLOOP.
ELSE.
CONTINUE.
ENDIF.
flag = 1.
PERFORM bdc_dynpro USING 'SAPMV45A' '4001'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=SICH'.
PERFORM bdc_transaction USING 'VA01'.
ENDLOOP.
PERFORM close_group.
WRITE : / 'Session',session, 'was Created'.
FORM open_group.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
group = session
user = sy-uname
keep = 'X'.
ENDFORM.
FORM close_group.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
ENDFORM.
FORM bdc_transaction USING tcode.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = tcode
TABLES
dynprotab = bdcdata.
ENDFORM.
FORM bdc_dynpro USING program dynpro.
CLEAR bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
ENDFORM.
FORM bdc_field USING fnam fval.
IF fval <> ' '.
CLEAR bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
APPEND bdcdata.
ENDIF.
ENDFORM.