2006 Jun 30 2:39 PM
Hello All:
I am brand new to ABAP and wondering if I could get some help on BDC like some documentation and examples. I know what it is but if anyone can send me some sample code examples and give me some walkthroughs where I can create BDC from scratch for understanding and PRACTICE. Thanks in advance.
2006 Jun 30 2:45 PM
hi mithun,
simple example
REPORT zxxx.
&----
*& internal table declaration
**&----
*
data: begin of record,
data element: BUKRS
BUKRS_001(004),
data element: KTOKK
KTOKK_002(004),
data element: NAME1_GP
NAME1_003(035),
data element: SORTL
SORTL_004(010),
data element: LAND1_GP
LAND1_005(003),
end of record.
data: it_vendor like recOrd occurs 0 with header line.
DATA: IT_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
DATA: IT_MESSAGES LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
***************************************************
*selection screen.
***************************************************
selection-screen: begin of block b1 with frame.
parameters: p_file like rlgrap-filename default 'c:/vendor.txt'
obligatory.
selection-screen: end of block b1.
***************************************************
*at selection screen.
***************************************************
at selection-screen on value-request for p_file.
perform f4_help using p_file.
***************************************************
*start of selection
***************************************************
start-of-selection.
*******uploading file
perform upload_file using p_file.
******open session.
perform POPULATE_DATA.
&----
*& Form f4_help
&----
text
----
-->P_P_FILE text
----
form f4_help using p_p_file.
data: l_file type ibipparms-path.
CALL FUNCTION 'F4_FILENAME'
IMPORTING
FILE_NAME = l_file.
p_file = l_file.
endform. " f4_help
&----
*& Form upload_file
&----
text
----
-->P_P_FILE text
----
form upload_file using p_p_file.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
CODEPAGE = ' '
FILENAME = p_p_file
FILETYPE = 'dat'
HEADLEN = ' '
LINE_EXIT = ' '
TRUNCLEN = ' '
USER_FORM = ' '
USER_PROG = ' '
DAT_D_FORMAT = ' '
IMPORTING
FILELENGTH =
TABLES
data_tab = it_vendor
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
NO_AUTHORITY = 10
OTHERS = 11
.
IF sy-subrc <> 0.
message i000(zz) with p_p_file.
ENDIF.
endform. " upload_file
&----
*& Form POPULATE_DATA
&----
text
----
--> p1 text
<-- p2 text
----
form POPULATE_DATA .
LOOP AT IT_VENDOR.
perform bdc_dynpro using 'SAPMF02K' '0105'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-KTOKK'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF02K-BUKRS'
IT_VENDOR-BUKRS_001.
perform bdc_field using 'RF02K-KTOKK'
IT_VENDOR-KTOKK_002.
perform bdc_dynpro using 'SAPMF02K' '0110'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-LAND1'.
perform bdc_field using 'BDC_OKCODE'
'=UPDA'.
perform bdc_field using 'LFA1-NAME1'
IT_VENDOR-NAME1_003.
perform bdc_field using 'LFA1-SORTL'
IT_VENDOR-SORTL_004.
perform bdc_field using 'LFA1-LAND1'
IT_VENDOR-LAND1_005.
******CALL TRANSACTION.
CALL TRANSACTION 'FK01' USING IT_BDCDATA MODE 'A'
UPDATE 'S'
MESSAGES INTO IT_MESSAGES.
WRITe:/ SY-SUBRC.
PERFORM FORMAT_MESSAGES.
CLEAR IT_BDCDATA.
REFRESH IT_BDCDATA.
ENDLOOP.
endform. " POPULATE_DATA
&----
*& Form FORMAT_MESSAGES
&----
text
----
--> p1 text
<-- p2 text
----
form FORMAT_MESSAGES .
DATA: L_MSG(100).
LOOP AT IT_MESSAGES.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = IT_MESSAGES-MSGID
LANG = SY-LANGU
NO = IT_MESSAGES-MSGNR
V1 = IT_MESSAGES-MSGV1
V2 = IT_MESSAGES-MSGV2
V3 = IT_MESSAGES-MSGV3
V4 = IT_MESSAGES-MSGV4
IMPORTING
MSG = L_MSG
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2
.
write:/ l_msg.
endloop.
endform. " FORMAT_MESSAGES
&----
*& Form bdc_dynpro
&----
text
----
-->P_0173 text
-->P_0174 text
----
form bdc_dynpro using value(p_PROGRAM)
value(p_SCREEN).
IT_BDCDATA-PROGRAM = P_PROGRAM.
IT_BDCDATA-DYNPRO = P_SCREEN.
IT_BDCDATA-DYNBEGIN = 'X'.
APPEND IT_BDCDATA.
CLEAR IT_BDCDATA.
endform. " bdc_dynpro
&----
*& Form bdc_field
&----
text
----
-->P_0178 text
-->P_0179 text
----
form bdc_field using value(p_FNAM)
value(p_FVAL).
IT_BDCDATA-FNAM = P_FNAM.
IT_BDCDATA-FVAL = P_FVAL.
APPEND IT_BDCDATA.
CLEAR IT_BDCDATA.
endform. " bdc_field
check these links..
http://help.sap.com/saphelp_47x200/helpdata/en/fa/097022543b11d1898e0000e8322d00/frameset.htm
http://www.sappoint.com/abap/bdcconcept.pdf
http://www.sap-img.com/abap/question-about-bdc-program.htm
http://www.sapdevelopment.co.uk/bdc/bdc_ctcode.htm
http://www.sapdevelopment.co.uk/bdc/bdc_recording.htm
http://www.sap-img.com/bdc.htm
table control in bdc
http://www.sap-img.com/abap/bdc-example-using-table-control-in-bdc.htm
hope this helps,
do reward if it helps,
priya.
Hello All:
I am brand new to ABAP and wondering if I could get some help on BDC like some documentation and examples. I know what it is but if anyone can send me some sample code examples and give me some walkthroughs where I can create BDC from scratch for understanding and PRACTICE. Thanks in advance.
2006 Jun 30 2:43 PM
Hi Mithun,
Here are some sample code for BDC
1. Call Transaction
&----
*& Report Zxx_BDC_CALLTRANSACTION *
*& *
&----
*& *
*& *
&----
REPORT Zxxx_BDC_CALLTRANSACTION .
data:begin of record,
data element: LIF16
*
LIFNR_001(016),
data element: BUKRS
BUKRS_002(004),
data element: KTOKK
KTOKK_003(004),
data element: ANRED
ANRED_004(015),
data element: NAME1_GP
NAME1_005(035),
data element: SORTL
SORTL_006(010),
data element: STRAS_GP
STRAS_007(035),
data element: LAND1_GP
LAND1_008(003),
end of record.
data:itab like record occurs 0 with header line.
data:it_bdc type bdcdata occurs 0 with header line.
selection-screen begin of block b1 with frame title text-001.
parameters:p_file type rlgrap-filename default 'vendor.txt' obligatory.
selection-screen end of block b1.
at selection-screen on value-request for p_file.
perform f4_filename using p_file.
start-of-selection.
*--upload
perform upload_file using p_file.
perform populate .
&----
*& Form f4_filename
&----
text
----
-->P_P_FILE text
----
form f4_filename using p_p_file.
data:l_file type ibipparms-path.
CALL FUNCTION 'F4_FILENAME'
IMPORTING
FILE_NAME = l_file.
p_p_file = l_file.
.
endform. " f4_filename
&----
*& Form upload_file
&----
text
----
-->P_P_FILE text
----
form upload_file using p_p_file.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
CODEPAGE = ' '
FILENAME = p_p_file
FILETYPE = 'DAT'
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
NO_AUTHORITY = 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. " upload_file
&----
*& Form populate
&----
text
----
--> p1 text
<-- p2 text
----
form populate .
loop at itab into record.
perform bdc_dynpro using 'SAPMF02K' '0105'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-KTOKK'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
*perform bdc_field using 'RF02K-LIFNR'
record-LIFNR_001.
perform bdc_field using 'RF02K-BUKRS'
record-BUKRS_002.
perform bdc_field using 'RF02K-KTOKK'
record-KTOKK_003.
perform bdc_dynpro using 'SAPMF02K' '0110'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-STRAS'.
perform bdc_field using 'BDC_OKCODE'
'=UPDA'.
perform bdc_field using 'LFA1-ANRED'
record-ANRED_004.
perform bdc_field using 'LFA1-NAME1'
record-NAME1_005.
perform bdc_field using 'LFA1-SORTL'
record-SORTL_006.
perform bdc_field using 'LFA1-STRAS'
record-STRAS_007.
perform bdc_field using 'LFA1-LAND1'
record-LAND1_008.
call transaction'FK01' using it_bdc mode 'A' update 'S'.
write:/ sy-subrc.
clear it_bdc.
refresh it_bdc.
endloop.
endform. " populate
&----
*& Form bdc_dynpro
&----
text
----
-->P_0163 text
-->P_0164 text
----
form bdc_dynpro using value(p_0163)
value(p_0164).
it_bdc-program = p_0163.
it_bdc-dynpro = p_0164.
it_bdc-dynbegin = 'X'.
append it_bdc.
clear it_bdc.
endform. " bdc_dynpro
&----
*& Form bdc_field
&----
text
----
-->P_0173 text
-->P_0174 text
----
form bdc_field using value(p_0173)
value(p_0174).
it_bdc-fnam = p_0173.
it_bdc-fval = p_0174.
append it_bdc.
clear it_bdc.
endform.
" bdc_field
report zxx_recording_fk01 .
************************************************************************
Program name : zxx_recording_fk01 *
Description : This program will get all the vendor details *
from a flat file . *
************************************************************************
************************************************************************
T A B L E S *
************************************************************************
tables : lfa1 . " Vendor Master.
************************************************************************
I N T E R N A L T A B L E - D E C L A R A T I O N *
************************************************************************
data : begin of it_tab occurs 0,
lifnr(16), "account number of vendor
ktokk(4), "Vendor Number
anred(15), "Account Group
name1(35), "Name
sortl(10), "Sort field
land1(3) , "Land
spras(1), "Language Key
kunnr(10), "customer number
banks(3), "Bank country key
bankl(15), "Bank Key
bankn(18), "Bank Account Number
koinh(60), "Account Holder Name
banka(60), "Name of bank
provz(3), "region
end of it_tab.
data : begin of it_tab1 occurs 0,
banks(3), "Bank country key
bankl(15), "Bank Key
bankn(18), "Bank Account Number
koinh(60), "Account Holder Name
banka(60), "Name of bank
provz(3), "region
end of it_tab1.
DATA:it_BDCtab LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
ERROR MESSAGE TABLE
DATA:it_MSGtab LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
data: program type BDCDATA-PROGRAM,
dynpro type BDCDATA-dynpro,
fnam type BDCDATA-fnam,
fval type BDCDATA-fval.
************************************************************************
S E L E C T I O N - S C R E E N *
************************************************************************
selection-screen : begin of block bl1 with frame.
parameter : p_file type rlgrap-filename default
'C:\Vendor.txt.txt' obligatory,
p_file1 type rlgrap-filename default
'C:\Vendor1.txt.txt' obligatory.
selection-screen : end of block bl1.
************************************************************************
A T S E L E C T I O N - S C R E E N *
************************************************************************
at selection-screen on value-request for p_file.
to get F4 help for p_file
perform f4_get_help using p_file.
to get F4 help for p_file
perform f4_get_help1 using p_file1.
************************************************************************
S T A R T O F S E L E C T I O N *
************************************************************************
start-of-selection.
Uploading data from flat file into it_tab
perform bdc_upload.
perform bdc_upload1.
perform populate_bdc.
************************************************************************
E N D O F S E L E C T I O N *
************************************************************************
end-of-selection.
displaying fields which r uploaded from flat file.
perform display_report.
************************************************************************
T O P _ O F _ P A G E *
************************************************************************
top-of-page.
to display header in the report
perform header.
&----
*& Form f4_get_help
&----
text
----
-->P_P_FILE text
----
form f4_get_help using p_p_file.
call function 'F4_FILENAME'
exporting
program_name = syst-cprog
dynpro_number = syst-dynnr
FIELD_NAME = ' '
importing
file_name = p_p_file.
.
endform. " f4_get_help
&----
*& Form bdc_upload
&----
text
----
--> p1 text
<-- p2 text
----
form bdc_upload .
data: v_file type string.
v_file = p_file.
call function 'GUI_UPLOAD'
exporting
filename = v_file
filetype = 'ASC'
HAS_FIELD_SEPARATOR = ' '
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
IMPORTING
FILELENGTH =
HEADER =
tables
data_tab = it_tab
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.
endform. " bdc_upload
&----
*& Form display_report
&----
text
----
--> p1 text
<-- p2 text
----
form display_report .
uline 1(86).
loop at it_tab .
format color 2.
write :/1 sy-vline,
2 it_tab-lifnr,
12 it_tab-ktokk ,
18 it_tab-anred ,
30 it_tab-name1 ,
55 it_tab-sortl ,
58 it_tab-land1 ,
72 it_tab-spras ,
76 it_tab-kunnr ,
88 it_tab-banks ,
94 it_tab-bankl ,
112 it_tab-bankn ,
132 it_tab-koinh ,
194 it_tab-banka ,
256 it_tab-provz ,
260 sy-vline.
.
endloop.
uline 1(86).
endform. " display_report
&----
*& Form header
&----
text
----
--> p1 text
<-- p2 text
----
form header .
uline 1(86).
format color col_heading.
write :/1 sy-vline,
2 'VEN.NO',
12 'ACC' ,
18 'TITLE' ,
30 'NAME' ,
55 'ST',
58 'LAND' ,
72 'L' ,
76 'CUSTNO',
88 'CKI',
94 'BANKKEY',
112 'B.NO',
132 'ACC HOLDER NAME',
194 'BANK NAME',
256 'reg',
260 sy-vline.
endform. " header
&----
*& Form populate_bdc
&----
text
----
form populate_bdc .
loop at it_tab.
perform build_screen_details using 'SAPMF02K' '0105'.
*
perform build_fields using: 'BDC_OKCODE' '/00',
'RF02K-LIFNR' it_tab-lifnr,
'RF02K-KTOKK' it_tab-ktokk.
perform build_screen_details using 'SAPMF02K' '0110'.
perform build_fields using: 'BDC_OKCODE' '/00',
'LFA1-ANRED' it_tab-anred,
'LFA1-NAME1' it_tab-name1,
'LFA1-SORTL' it_tab-sortl,
'LFA1-LAND1' it_tab-land1,
'LFA1-SPRAS' it_tab-spras.
perform build_screen_details using 'SAPMF02K' '0120'.
perform build_fields using: 'BDC_OKCODE' '/00'.
perform build_screen_details using 'SAPMF02K' '0130'.
perform build_fields using: 'BDC_OKCODE' '=BANK',
'LFBK-BANKS(01)' it_tab-banks,
'LFBK-BANKL(01)' it_tab-bankl,
'LFBK-BANKN(01)' it_tab-bankn,
'LFBK-KOINH(01)' it_tab-koinh.
perform build_screen_details using 'SAPLBANK' '0100'.
perform build_fields using: 'BDC_OKCODE' '=ENTR',
'BNKA-BANKA' it_tab-banka,
'BNKA-PROVZ' it_tab-provz.
perform build_screen_details using 'SAPMF02K' '0130'.
perform build_fields using: 'BDC_OKCODE' '=UPDA'.
endloop.
call transaction 'FK01' using it_bdctab mode 'A' update
'S' messages into it_msgtab.
clear it_bdctab.
refresh it_bdctab.
loop at it_msgtab.
perform format_message.
endloop.
endform. " populate_bdc
&----
*& Form build_screen_details
&----
text
----
form build_screen_details using p_program type BDCDATA-PROGRAM
p_dynpro type BDCDATA-dynpro.
it_BDCtab-PROGRAM = p_program. " Program Name
it_BDCtab-DYNPRO = p_dynpro. " Screen Number
it_BDCtab-DYNBEGIN = 'X'. " New screen
Append it_bdctab.
clear it_bdctab.
endform. " build_screen_details
&----
*& Form build_fields
&----
text
----
form build_fields using p_fnam
p_fval.
it_BDCtab-FNAM = p_fnam.
it_BDCtab-FVAL = p_fval.
Append it_bdctab.
clear it_bdctab.
endform. " build_fields
&----
*& Form format_message
&----
text
----
--> p1 text
<-- p2 text
----
form format_message .
call function 'FORMAT_MESSAGE'
EXPORTING
ID = SY-MSGID
LANG = sy-langu
NO = SY-MSGNO
V1 = SY-MSGV1
V2 = SY-MSGV2
V3 = SY-MSGV3
V4 = SY-MSGV4
IMPORTING
MSG = it_msgtab
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.
endform. " format_message
&----
*& Form bdc_upload1
&----
text
----
--> p1 text
<-- p2 text
----
form bdc_upload1 .
data : v_file1 type string.
v_file1 = p_file1.
call function 'GUI_UPLOAD'
exporting
filename = v_file1
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = ' '
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
IMPORTING
FILELENGTH =
HEADER =
tables
data_tab = it_tab1
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.
endform. " bdc_upload1
&----
*& Form f4_get_help1
&----
text
----
-->P_P_FILE1 text
----
form f4_get_help1 using p_p_file1.
call function 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
FILE_NAME = p_p_file1
.
endform. " f4_get_help1
2.Session Method
&----
*& Report ZSUDHA_FK01_SESION *
*& *
&----
*& *
*& *
&----
REPORT ZSUDHA_FK01_SESION message-id ztraining .
&----
*-- data declarationn
&----
types: begin of s_file ,
comp_code type lfb1-bukrs,
account_grp type lfa1-ktokk,
title type lfa1-anred,
name type lfa1-name1,
search type lfa1-sortl,
country type lfa1-land1,
end of s_file.
data:itab type s_file occurs 0 with header line.
data:it_bdc type bdcdata occurs 0 with header line.
&----
selection-screen
&----
selection-screen begin of block b1 with frame title text-001.
parameters:p_file type rlgrap-filename default 'c:\vendor.txt'
obligatory.
selection-screen end of block b1.
&----
*
&----
at selection-screen on value-request for p_file.
perform file_help using p_file.
start-of-selection.
perform upload_file using p_file.
perform open_session.
perform populate_bdctable .
perform close_session.
end-of-selection.
write:/ itab-comp_code.
&----
*& Form file_help
&----
text
----
-->P_P_FILE text
----
FORM file_help USING P_P_FILE.
data:l_file type ibipparms-path.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
IMPORTING
FILE_NAME = l_file.
p_file = l_file .
ENDFORM. " file_help
&----
*& Form upload_file
&----
text
----
-->P_P_FILE text
----
FORM upload_file USING P_P_FILE.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
CODEPAGE = ' '
FILENAME = P_P_FILE
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
NO_AUTHORITY = 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.
message i001.
ENDIF.
ENDFORM. " upload_file
&----
*& Form open_session
&----
text
----
-->P_P_FILE text
----
FORM open_session .
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
DEST = FILLER8
GROUP = 'ZSUDHA1'
HOLDDATE = FILLER8
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.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " open_session
&----
*& Form populate_bdctable
&----
text
----
-->P_P_FILE text
----
FORM populate_bdctable .
loop at itab.
perform bdc_dynpro using 'SAPMF02K' '0105'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-KTOKK'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF02K-BUKRS'
'0001'.
perform bdc_field using 'RF02K-KTOKK'
'0001'.
perform bdc_dynpro using 'SAPMF02K' '0110'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-SORTL'.
perform bdc_field using 'BDC_OKCODE'
'=UPDA'.
perform bdc_field using 'LFA1-ANRED'
'ITAB-ANRED'.
perform bdc_field using 'LFA1-NAME1'
'ITAB-NAME'.
perform bdc_field using 'LFA1-SORTL'
'ITAB-SEARCH'.
perform bdc_field using 'LFA1-LAND1'
'ITAB-COUNTRY'.
perform bdc_insert.
clear it_bdc.
refresh it_bdc.
endloop.
ENDFORM. " populate_bdctable
&----
*& Form bdc_dynpro
&----
text
----
-->P_P_FILE text
----
FORM bdc_dynpro USING value(p_program)
value(p_screen).
IT_BDC-PROGRAM = P_PROGRAM.
IT_BDC-DYNPRO = P_SCREEN.
IT_BDC-DYNBEGIN = 'X'.
APPEND IT_BDC.
CLEAR IT_BDC.
ENDFORM. " bdc_dynpro
&----
*& Form bdc_insert
&----
text
----
--> p1 text
<-- p2 text
----
FORM bdc_insert .
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'FK01'
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.
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_session
&----
text
----
--> p1 text
<-- p2 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_field
&----
text
----
-->P_0247 text
-->P_0248 text
----
FORM bdc_field USING VALUE(P_FIELDNAME)
VALUE(P_FIELDVALUE).
IT_BDC-FNAM = P_FIELDNAME.
IT_BDC-FVAL = P_FIELDVALUE.
APPEND IT_BDC.
CLEAR IT_BDC.
ENDFORM. " bdc_field
http://www.sappoint.com/abap.html
www.sapgenie.com/abap/tips_and_tricks.htm
Regards
Laxmi.
2006 Jul 01 2:03 PM
2006 Jun 30 2:44 PM
HI,
Check this out
BDC
http://www.sap-img.com/bdc.htm
give me your mail id i will send you a documnet fot the smae
Regards,
Santosh
2006 Jun 30 2:45 PM
hi mithun,
simple example
REPORT zxxx.
&----
*& internal table declaration
**&----
*
data: begin of record,
data element: BUKRS
BUKRS_001(004),
data element: KTOKK
KTOKK_002(004),
data element: NAME1_GP
NAME1_003(035),
data element: SORTL
SORTL_004(010),
data element: LAND1_GP
LAND1_005(003),
end of record.
data: it_vendor like recOrd occurs 0 with header line.
DATA: IT_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
DATA: IT_MESSAGES LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
***************************************************
*selection screen.
***************************************************
selection-screen: begin of block b1 with frame.
parameters: p_file like rlgrap-filename default 'c:/vendor.txt'
obligatory.
selection-screen: end of block b1.
***************************************************
*at selection screen.
***************************************************
at selection-screen on value-request for p_file.
perform f4_help using p_file.
***************************************************
*start of selection
***************************************************
start-of-selection.
*******uploading file
perform upload_file using p_file.
******open session.
perform POPULATE_DATA.
&----
*& Form f4_help
&----
text
----
-->P_P_FILE text
----
form f4_help using p_p_file.
data: l_file type ibipparms-path.
CALL FUNCTION 'F4_FILENAME'
IMPORTING
FILE_NAME = l_file.
p_file = l_file.
endform. " f4_help
&----
*& Form upload_file
&----
text
----
-->P_P_FILE text
----
form upload_file using p_p_file.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
CODEPAGE = ' '
FILENAME = p_p_file
FILETYPE = 'dat'
HEADLEN = ' '
LINE_EXIT = ' '
TRUNCLEN = ' '
USER_FORM = ' '
USER_PROG = ' '
DAT_D_FORMAT = ' '
IMPORTING
FILELENGTH =
TABLES
data_tab = it_vendor
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
NO_AUTHORITY = 10
OTHERS = 11
.
IF sy-subrc <> 0.
message i000(zz) with p_p_file.
ENDIF.
endform. " upload_file
&----
*& Form POPULATE_DATA
&----
text
----
--> p1 text
<-- p2 text
----
form POPULATE_DATA .
LOOP AT IT_VENDOR.
perform bdc_dynpro using 'SAPMF02K' '0105'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-KTOKK'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF02K-BUKRS'
IT_VENDOR-BUKRS_001.
perform bdc_field using 'RF02K-KTOKK'
IT_VENDOR-KTOKK_002.
perform bdc_dynpro using 'SAPMF02K' '0110'.
perform bdc_field using 'BDC_CURSOR'
'LFA1-LAND1'.
perform bdc_field using 'BDC_OKCODE'
'=UPDA'.
perform bdc_field using 'LFA1-NAME1'
IT_VENDOR-NAME1_003.
perform bdc_field using 'LFA1-SORTL'
IT_VENDOR-SORTL_004.
perform bdc_field using 'LFA1-LAND1'
IT_VENDOR-LAND1_005.
******CALL TRANSACTION.
CALL TRANSACTION 'FK01' USING IT_BDCDATA MODE 'A'
UPDATE 'S'
MESSAGES INTO IT_MESSAGES.
WRITe:/ SY-SUBRC.
PERFORM FORMAT_MESSAGES.
CLEAR IT_BDCDATA.
REFRESH IT_BDCDATA.
ENDLOOP.
endform. " POPULATE_DATA
&----
*& Form FORMAT_MESSAGES
&----
text
----
--> p1 text
<-- p2 text
----
form FORMAT_MESSAGES .
DATA: L_MSG(100).
LOOP AT IT_MESSAGES.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = IT_MESSAGES-MSGID
LANG = SY-LANGU
NO = IT_MESSAGES-MSGNR
V1 = IT_MESSAGES-MSGV1
V2 = IT_MESSAGES-MSGV2
V3 = IT_MESSAGES-MSGV3
V4 = IT_MESSAGES-MSGV4
IMPORTING
MSG = L_MSG
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2
.
write:/ l_msg.
endloop.
endform. " FORMAT_MESSAGES
&----
*& Form bdc_dynpro
&----
text
----
-->P_0173 text
-->P_0174 text
----
form bdc_dynpro using value(p_PROGRAM)
value(p_SCREEN).
IT_BDCDATA-PROGRAM = P_PROGRAM.
IT_BDCDATA-DYNPRO = P_SCREEN.
IT_BDCDATA-DYNBEGIN = 'X'.
APPEND IT_BDCDATA.
CLEAR IT_BDCDATA.
endform. " bdc_dynpro
&----
*& Form bdc_field
&----
text
----
-->P_0178 text
-->P_0179 text
----
form bdc_field using value(p_FNAM)
value(p_FVAL).
IT_BDCDATA-FNAM = P_FNAM.
IT_BDCDATA-FVAL = P_FVAL.
APPEND IT_BDCDATA.
CLEAR IT_BDCDATA.
endform. " bdc_field
check these links..
http://help.sap.com/saphelp_47x200/helpdata/en/fa/097022543b11d1898e0000e8322d00/frameset.htm
http://www.sappoint.com/abap/bdcconcept.pdf
http://www.sap-img.com/abap/question-about-bdc-program.htm
http://www.sapdevelopment.co.uk/bdc/bdc_ctcode.htm
http://www.sapdevelopment.co.uk/bdc/bdc_recording.htm
http://www.sap-img.com/bdc.htm
table control in bdc
http://www.sap-img.com/abap/bdc-example-using-table-control-in-bdc.htm
hope this helps,
do reward if it helps,
priya.
2006 Jun 30 2:45 PM
There are about 6 different examples of BDC here
http://www.sap-img.com/bdc.htm
Regards,
Ravi
Note : Please mark the helpful answers
2006 Jun 30 2:57 PM
That was fast. Thanks everyone for all the information. I know I have to go through the code and understand but can someone please send some documentation for the code if possible. I read somewhere there are 2 steps in BDC and first step is BDC recording using Tcode sm35 anduse that in code in the next step. I could not get myhead around it! Sorry, I am trying to learn and your feedback would be great. Thanks.
2006 Jun 30 2:59 PM
Record the transaction using SHDB. THe view the recording which will show you the values you need to insert into your BDC table.
You can also generate code from SHDB which is helpful.
hope this helps....
2006 Jun 30 3:02 PM
Give me you email address, I have a helpful document for BDC starter
BAR
2006 Jun 30 3:03 PM
HI MITHUN,
STEPS:
1) GOTO transaction SHDB (or) SM35
2) click on new recording and enter the name and give the transaction and start you recording
3) after recording click on Save button to save your recording and then press back button.
4) select ur recording and click on the button Program.
this will generate the program for the recording u have done use that program and do the changes u want to.
2006 Jun 30 3:18 PM
Thanks BAR and everyone. My email address is [email protected].
2006 Jun 30 3:31 PM
hi Mithun,
I have sent you a document to your email id
Reward if it helps
Regards,
Santosh
2006 Jul 01 2:11 PM
Thanks again to everyone for all the useful information you sent to me. Now I have lot of information I can go through and learn BDC programming. I want to create one small sample program myself to learn all this and I trying to think of the best way of doing it! What is the best way to practice it? Can I just create one small sequential file and go from there? Sorry, if I ask any DUMB questions but I have to really practice it to see how it works. Thanks for all your help again.
Regards,
Mithun.