05-31-2007 11:59 AM
Hi,
I have to upload data from text file and create customers using bdc call transaction.
This is the code I have written but getting no output.
Pls help me out.
Thanks
REPORT znewbdc
NO STANDARD PAGE HEADING LINE-SIZE 255.
TABLES: kna1.
DATA: gv_program LIKE bdcdata-program,
gv_dynpro LIKE bdcdata-dynpro,
gv_dynbegin LIKE bdcdata-dynbegin,
gv_fnam LIKE bdcdata-fnam,
gv_fval LIKE bdcdata-fval.
*--Internal Table to Store Error Records.
DATA : BEGIN OF gt_errcust OCCURS 0,
kunnr,
emsg(255),
END OF gt_errcust.
*--Internal Table to Store Successful Records.
DATA : BEGIN OF gt_succust OCCURS 0,
kunnr,
smsg(255),
END OF gt_succust.
*--Internal Table for Storing the BDC data.
DATA : gt_bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
*--Internal Table for storing the messages
DATA : gt_bdcmsgcoll LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
DATA : v_flag1(1) VALUE ' ', "Flag used for opening session.
v_tlines LIKE sy-tabix, "For storing total records processed.
v_elines LIKE sy-tabix, "For storing the no of error records.
v_slines LIKE sy-tabix. "For storing the no of success records.
DATA: BEGIN OF tp_kna1 OCCURS 0,
ktokd,
bukrs,
name1,
sort1,
land1,
ktocd,
akont,
message(100) TYPE c,
END OF tp_kna1.
DATA: gs_bdc_tcode LIKE tstc-tcode.
SELECTION-SCREEN BEGIN OF BLOCK b1.
PARAMETERS : v_fname LIKE rlgrap-filename.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
DATA : lv_file TYPE string.
lv_file = v_fname.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = lv_file
FILETYPE = 'ASC'
has_field_separator = 'X'
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
NO_AUTH_CHECK = ' '
IMPORTING
FILELENGTH =
HEADER =
TABLES
data_tab = tp_kna1
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.
DESCRIBE TABLE tp_kna1 LINES v_tlines.
ENDIF.
LOOP AT tp_kna1.
PERFORM bdc_dynpro USING 'SAPMF02D' '0100'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RF02D-BUKRS'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'RF02D-BUKRS'
tp_kna1-bukrs. "'0001'.
PERFORM bdc_field USING 'RF02D-KTOKD'
tp_kna1-ktokd. "'CPD'.
PERFORM bdc_dynpro USING 'SAPMF02D' '0110'.
PERFORM bdc_field USING 'BDC_CURSOR'
'KNA1-SPRAS'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=VW'.
PERFORM bdc_field USING 'KNA1-NAME1'
'tp_KNA1-NAME1'.
PERFORM bdc_field USING 'KNA1-SORTL'
'tp_KNA1-SORTL'.
PERFORM bdc_field USING 'KNA1-LAND1'
'TP_KNA1-LAND1'.
PERFORM bdc_field USING 'KNA1-SPRAS'
'TP_KNA1-SPRAS'.
PERFORM bdc_dynpro USING 'SAPMF02D' '0120'.
PERFORM bdc_field USING 'BDC_CURSOR'
'KNA1-KTOCD'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=VW'.
PERFORM bdc_field USING 'KNA1-KTOCD'
'TP_KNA1-KTOCD'.
PERFORM bdc_dynpro USING 'SAPMF02D' '0210'.
PERFORM bdc_field USING 'BDC_CURSOR'
'KNB1-AKONT'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=UPDA'.
PERFORM bdc_field USING 'KNB1-AKONT'
'140000'.
CALL TRANSACTION 'XD01' USING gt_bdcdata MODE 'N' UPDATE 'S'
MESSAGES INTO gt_bdcmsgcoll.
*--Getting the total no of error records.
DESCRIBE TABLE gt_errcust LINES v_elines.
*--Getting the total no of successful records.
DESCRIBE TABLE gt_succust LINES v_slines.
DATA : lv_msg(255).
IF NOT gt_bdcmsgcoll IS INITIAL.
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 = lv_msg
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc = 0.
WRITE 😕 lv_msg.
ENDIF.
ULINE.
ENDIF.
ENDLOOP.
&----
*& Form bdc_dynpro
&----
text
----
-->P_GV_PROGRAM text
-->P_GV_DYNPRO text
----
FORM bdc_dynpro USING p_gv_program LIKE bdcdata-program
p_gv_dynpro LIKE bdcdata-dynpro.
CLEAR gt_bdcdata.
gt_bdcdata-program = p_gv_program.
gt_bdcdata-dynpro = p_gv_dynpro.
gt_bdcdata-dynbegin = 'X'.
APPEND gt_bdcdata.
ENDFORM. "BDC_DYNPRO
&----
*& Form BDC_FIELD
&----
text
----
-->P_GV_FNAM text
-->P_GV_FVAL text
----
FORM bdc_field USING p_gv_fnam
p_gv_fval.
CLEAR gt_bdcdata.
gt_bdcdata-fnam = p_gv_fnam.
gt_bdcdata-fval = p_gv_fval.
APPEND gt_bdcdata.
ENDFORM. "BDC_FIELD
05-31-2007 5:30 PM
Hi
CALL TRANSACTION 'XD01' USING gt_bdcdata MODE 'N' UPDATE 'S'
MESSAGES INTO gt_bdcmsgcoll.
<b>Refresh gt_bdcdata.</b>
Regards
Haritha.
05-31-2007 12:08 PM
Hi,
Do this in your coding.This will work for you.
LOOP AT tp_kna1.
REFRESH gt_bdcdata----
> write this in your code
PERFORM bdc_dynpro USING 'SAPMF02D' '0100'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RF02D-BUKRS'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
.
.
.
Regards
Ram
05-31-2007 12:35 PM
05-31-2007 12:48 PM
Hi,
At last you need to perform this operations.
APPEND Your Internal Table.
CLEAR Your Work Area.
CLEAR Your Internal Table.
REFRESH your MSGTAB.
This time it should work.Check it.
Regards
Ram
05-31-2007 12:35 PM
hi,
Refresh the other
bdctab.
by the way a small suggestion
Use LSMW rather than BDC it will give u good
performance upto 2 to 3 times
if u have any queries please post
05-31-2007 1:32 PM
This time I have to do this with BDC can u tell me whats wrong with the code.
Thanks.
05-31-2007 5:30 PM
Hi
CALL TRANSACTION 'XD01' USING gt_bdcdata MODE 'N' UPDATE 'S'
MESSAGES INTO gt_bdcmsgcoll.
<b>Refresh gt_bdcdata.</b>
Regards
Haritha.
05-31-2007 5:34 PM
See the below code and i modfied :
REPORT znewbdc
NO STANDARD PAGE HEADING LINE-SIZE 255.
TABLES: kna1.
DATA: gv_program LIKE bdcdata-program,
gv_dynpro LIKE bdcdata-dynpro,
gv_dynbegin LIKE bdcdata-dynbegin,
gv_fnam LIKE bdcdata-fnam,
gv_fval LIKE bdcdata-fval.
*--Internal Table to Store Error Records.
DATA : BEGIN OF gt_errcust OCCURS 0,
kunnr,
emsg(255),
END OF gt_errcust.
*--Internal Table to Store Successful Records.
DATA : BEGIN OF gt_succust OCCURS 0,
kunnr,
smsg(255),
END OF gt_succust.
*--Internal Table for Storing the BDC data.
DATA : gt_bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
*--Internal Table for storing the messages
DATA : gt_bdcmsgcoll LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
DATA : v_flag1(1) VALUE ' ', "Flag used for opening session.
v_tlines LIKE sy-tabix, "For storing total records processed.
v_elines LIKE sy-tabix, "For storing the no of error records.
v_slines LIKE sy-tabix. "For storing the no of success records.
DATA: BEGIN OF tp_kna1 OCCURS 0,
ktokd,
bukrs,
name1,
sort1,
land1,
ktocd,
akont,
message(100) TYPE c,
END OF tp_kna1.
DATA: gs_bdc_tcode LIKE tstc-tcode.
SELECTION-SCREEN BEGIN OF BLOCK b1.
PARAMETERS : v_fname LIKE rlgrap-filename.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
DATA : lv_file TYPE string.
lv_file = v_fname.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = lv_file
FILETYPE = 'ASC'
has_field_separator = 'X'
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
NO_AUTH_CHECK = ' '
IMPORTING
FILELENGTH =
HEADER =
TABLES
data_tab = tp_kna1
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.
DESCRIBE TABLE tp_kna1 LINES v_tlines.
ENDIF.
LOOP AT tp_kna1.
PERFORM bdc_dynpro USING 'SAPMF02D' '0100'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RF02D-BUKRS'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'RF02D-BUKRS'
tp_kna1-bukrs. "'0001'.
PERFORM bdc_field USING 'RF02D-KTOKD'
tp_kna1-ktokd. "'CPD'.
PERFORM bdc_dynpro USING 'SAPMF02D' '0110'.
PERFORM bdc_field USING 'BDC_CURSOR'
'KNA1-SPRAS'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=VW'.
PERFORM bdc_field USING 'KNA1-NAME1'
'tp_KNA1-NAME1'.
PERFORM bdc_field USING 'KNA1-SORTL'
'tp_KNA1-SORTL'.
PERFORM bdc_field USING 'KNA1-LAND1'
'TP_KNA1-LAND1'.
PERFORM bdc_field USING 'KNA1-SPRAS'
'TP_KNA1-SPRAS'.
PERFORM bdc_dynpro USING 'SAPMF02D' '0120'.
PERFORM bdc_field USING 'BDC_CURSOR'
'KNA1-KTOCD'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=VW'.
PERFORM bdc_field USING 'KNA1-KTOCD'
'TP_KNA1-KTOCD'.
PERFORM bdc_dynpro USING 'SAPMF02D' '0210'.
PERFORM bdc_field USING 'BDC_CURSOR'
'KNB1-AKONT'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=UPDA'.
PERFORM bdc_field USING 'KNB1-AKONT'
'140000'.
CALL TRANSACTION 'XD01' USING gt_bdcdata MODE 'N' UPDATE 'S'
MESSAGES INTO gt_bdcmsgcoll.
*--Getting the total no of error records.
DESCRIBE TABLE gt_errcust LINES v_elines.
*--Getting the total no of successful records.
DESCRIBE TABLE gt_succust LINES v_slines.
DATA : lv_msg(255).
IF NOT gt_bdcmsgcoll IS INITIAL.
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 = lv_msg
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc = 0.
WRITE 😕 lv_msg.
ENDIF.
ULINE.
ENDIF.
refresh gt_bdcdata.
clear : tp_kna1,
gt_bdcdata.
ENDLOOP.
&----
*& Form bdc_dynpro
&----
text
----
-->P_GV_PROGRAM text
-->P_GV_DYNPRO text
----
FORM bdc_dynpro USING p_gv_program LIKE bdcdata-program
p_gv_dynpro LIKE bdcdata-dynpro.
CLEAR gt_bdcdata.
gt_bdcdata-program = p_gv_program.
gt_bdcdata-dynpro = p_gv_dynpro.
gt_bdcdata-dynbegin = 'X'.
APPEND gt_bdcdata.
ENDFORM. "BDC_DYNPRO
&----
*& Form BDC_FIELD
&----
text
----
-->P_GV_FNAM text
-->P_GV_FVAL text
----
FORM bdc_field USING p_gv_fnam
p_gv_fval.
CLEAR gt_bdcdata.
gt_bdcdata-fnam = p_gv_fnam.
gt_bdcdata-fval = p_gv_fval.
APPEND gt_bdcdata.
ENDFORM. "BDC_FIELD
06-01-2007 5:49 AM
Thanks a lot
Now when I am reading the flat file into the internal table all the records are coming under single column as the fields in the flat file are separated by a 'comma'. How should I proceed?
06-01-2007 5:51 AM
Hi mahendra,
Use SPLIT command to split the records into different fields of internal table.
LOOP AT itab.
split itab-line into itab_1-fld1 itab_1-fld2 ...etc seaparated by ','.
Endloop.
Regards,
Atish
06-01-2007 6:22 AM
Hi,
Thanks for the answer.
Apart from split is there any other way to perform the same.
split tp_kna1 AT ',' into tp_kna1-ktokd tp_kna1-bukrs tp_kna1-name1
tp_kna1-sortl tp_kna1-land1 tp_kna1-ktocd tp_kna1-akont .
I am doing the above code but still the internal table is not proper.
06-01-2007 6:25 AM
Hi mahendra,
There are two option,
1. Use the internal table of the same format as that of file so that data will properly come in each field.
2. Get data into a single field of a table and then use SPLIT.
Revert back if further query.
Reward points to all useful answers.
Regards,
Atish
06-01-2007 6:49 AM
Thanks.
This is the first time I am working on this so can u give me the syntax of the same pls.