‎2007 May 23 4:54 AM
hi all,
i have a problem with my bdc program
even if i am sending only five records i am getting the 5+2 = 7 messages
i don' t know why it is giving me the extra two messages that are repeating so please see to the program that i am sending with this and suggest me to rectify my mistake
thanks in advance
REPORT ZHCL_BDC11 .
TYPES: BEGIN OF tw_data,
bukrs TYPE bukrs,
ekorg TYPE ekorg,
ktokk TYPE ktokk,
name1 TYPE name1,
sortl TYPE sortl,
land1 TYPE land1_gp,
akont TYPE akont,
fdgrv TYPE fdgrv,
waers TYPE waers,
END OF tw_data,
ti_data TYPE STANDARD TABLE OF tw_data.
TYPES: BEGIN OF tw_error,
bukrs TYPE bukrs,
ekorg TYPE ekorg,
ktokk TYPE ktokk,
name1 TYPE name1,
land1 TYPE land1_gp,
sortl TYPE sortl,
akont TYPE akont,
fdgrv TYPE fdgrv,
END OF tw_error,
ti_error TYPE STANDARD TABLE OF tw_error.
DATA: wa_data TYPE tw_data, "work area for the upload data
it_data TYPE ti_data, "internal table for the upload data
wa_error TYPE tw_error, " work area for the erroneous records
it_error TYPE ti_error, "internal table for the errroneous
"records
lf_fname TYPE string, " variable to store uploading file path
lf_dname TYPE string, "variable to store downloading file path
lf_size TYPE i, " variable to store the file size for
"existence check
lf_exist TYPE c, "variable to store the existence of the file.
wa_bdcdata TYPE bdcdata, "work area for the bdcdata table
it_bdcdata TYPE STANDARD TABLE OF bdcdata,"internal table for
"the bdcdata table
wa_bdcmsgcoll TYPE bdcmsgcoll, "work area for cathing the
"messages
it_bdcmsgcoll TYPE STANDARD TABLE OF bdcmsgcoll,"internal table
"for cathing the
"messages
it_bdcmsgcoll1 TYPE STANDARD TABLE OF bdcmsgcoll.
*parameter to get the file path for uploading data
SELECTION-SCREEN BEGIN OF BLOCK 1 WITH FRAME TITLE text-005.
PARAMETERS: p_fname TYPE localfile.
SELECTION-SCREEN END OF BLOCK 1.
*parameter to get the file path for erroneous records if any
SELECTION-SCREEN BEGIN OF BLOCK 2 WITH FRAME TITLE text-006.
PARAMETERS: p_dname TYPE localfile.
SELECTION-SCREEN END OF BLOCK 2.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.
*for adding the f4 functionality to the uploading file path
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
IMPORTING
file_name = p_fname.
*for adding the f4 functionality to the downloading file path
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_dname.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
IMPORTING
file_name = p_dname.
*initialization event
INITIALIZATION.
p_fname = 'D:\ibrahim\'.
AT SELECTION-SCREEN.
*for checking whether the file exists or not
CALL FUNCTION 'TMP_GUI_GET_FILE_EXIST'
EXPORTING
fname = p_fname
IMPORTING
EXIST =
ISDIR =
filesize = lf_size
EXCEPTIONS
fileinfo_error = 1
OTHERS = 2
.
IF sy-subrc <> 0.
message e000(zhcl_msg).
ENDIF.
*to check whether the path is given or not
IF lf_size < 0 .
MESSAGE e000(ZHCL_MSG). "WITH 'Enter the correct file path'.
ENDIF.
*to check whether the file is initial or not
IF lf_size = 0.
MESSAGE e001(ZHCL_MSG). "WITH 'The file given is empty'.
ENDIF.
*start of selection event
START-OF-SELECTION.
lf_fname = p_fname.
lf_dname = p_dname.
*function module gui_upload for uploading the flat file to
*the internal table lt_data
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = lf_fname
filetype = 'ASC'
has_field_separator = 'X' "since tab delimited file
TABLES
data_tab = it_data
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 the table is not uploaded then error message is given
IF sy-subrc <> 0.
MESSAGE e002(ZHCL_MSG). " WITH 'The table is not uploaded'.
ENDIF.
LOOP AT it_data INTO wa_data.
*clearing the work area of the bdcdata table
CLEAR wa_bdcdata.
*refreshing the internal table of the bdcdata table
REFRESH it_bdcdata[].
*paste the perform statements from the recording done for the
*particular transaction(xk01).
PERFORM bdc_dynpro USING 'SAPMF02K' '0100'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RF02K-KTOKK'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'RF02K-BUKRS'
wa_data-bukrs.
PERFORM bdc_field USING 'RF02K-EKORG'
wa_data-ekorg.
PERFORM bdc_field USING 'RF02K-KTOKK'
wa_data-ktokk.
PERFORM bdc_dynpro USING 'SAPMF02K' '0110'.
PERFORM bdc_field USING 'BDC_CURSOR'
'LFA1-LAND1'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'LFA1-NAME1'
wa_data-name1.
PERFORM bdc_field USING 'LFA1-SORTL'
wa_data-sortl.
PERFORM bdc_field USING 'LFA1-LAND1'
wa_data-land1.
PERFORM bdc_dynpro USING 'SAPMF02K' '0120'.
PERFORM bdc_field USING 'BDC_CURSOR'
'LFA1-KUNNR'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_dynpro USING 'SAPMF02K' '0130'.
PERFORM bdc_field USING 'BDC_CURSOR'
'LFBK-BANKS(01)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ENTR'.
PERFORM bdc_dynpro USING 'SAPMF02K' '0210'.
PERFORM bdc_field USING 'BDC_CURSOR'
'LFB1-FDGRV'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'LFB1-AKONT'
wa_data-akont.
PERFORM bdc_field USING 'LFB1-FDGRV'
wa_data-fdgrv.
PERFORM bdc_dynpro USING 'SAPMF02K' '0215'.
PERFORM bdc_field USING 'BDC_CURSOR'
'LFB1-ZTERM'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_dynpro USING 'SAPMF02K' '0220'.
PERFORM bdc_field USING 'BDC_CURSOR'
'LFB5-MAHNA'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_dynpro USING 'SAPMF02K' '0610'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'BDC_CURSOR'
'LFB1-QLAND'.
PERFORM bdc_dynpro USING 'SAPMF02K' '0310'.
PERFORM bdc_field USING 'BDC_CURSOR'
'LFM1-WAERS'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'LFM1-WAERS'
wa_data-waers.
PERFORM bdc_dynpro USING 'SAPMF02K' '0320'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RF02K-LIFNR'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ENTR'.
PERFORM bdc_dynpro USING 'SAPLSPO1' '0300'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=YES'.
*callling the call transaction method for uploading the data
CALL TRANSACTION 'XK01' USING it_bdcdata MODE 'N' UPDATE 'S' MESSAGES
INTO it_bdcmsgcoll.
APPEND LINES OF it_bdcmsgcoll TO it_bdcmsgcoll1.
clear: wa_data.
refresh: it_bdcmsgcoll.
ENDLOOP.
PERFORM fr_format_message . "for capturing the messages from internal
"table lt_bdcmsgcoll
&----
*& Form bdc_dynpro
&----
text
----
-->P_0252 text
-->P_0253 text
----
FORM bdc_dynpro USING program
dynpro.
CLEAR wa_bdcdata.
wa_bdcdata-program = program.
wa_bdcdata-dynpro = dynpro.
wa_bdcdata-dynbegin = 'X'.
APPEND wa_bdcdata TO it_bdcdata.
ENDFORM. " bdc_dynpro
&----
*& Form bdc_field
&----
text
----
-->P_0257 text
-->P_0258 text
----
FORM bdc_field USING fnam
fval.
*checking whether fval field is initial or not
IF fval NE space.
CLEAR wa_bdcdata.
wa_bdcdata-fnam = fnam.
wa_bdcdata-fval = fval.
ENDIF.
*appending the internal table of bdcdata with the workarea
APPEND wa_bdcdata TO it_bdcdata.
ENDFORM. " bdc_field
&----
*& Form fr_format_message
&----
text
----
--> p1 text
<-- p2 text
----
FORM fr_format_message .
DATA: lf_msg TYPE string. " taking a local string type variabe for
"capturing the message
WRITE: /10 text-001,
35 text-002,
45 text-003,
55 text-004.
*starting the loop of the messages internal table
LOOP AT it_bdcmsgcoll1 INTO wa_bdcmsgcoll.
*reading the data table with index
READ TABLE it_data INTO wa_data INDEX sy-tabix.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = wa_bdcmsgcoll-msgid
lang = 'EN'
no = wa_bdcmsgcoll-msgnr
v1 = wa_bdcmsgcoll-msgv1
v2 = wa_bdcmsgcoll-msgv2
v3 = wa_bdcmsgcoll-msgv3
v4 = wa_bdcmsgcoll-msgv4
IMPORTING
msg = lf_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.
*endif.
WRITE: /10 wa_bdcmsgcoll-msgid,
35 wa_bdcmsgcoll-msgnr,
45 wa_bdcmsgcoll-msgtyp,
55 lf_msg.
*checking whether the msg. type is success or not.
IF wa_bdcmsgcoll-msgtyp NE 'S'.
*if message type is not success then sending the un uploaded records
*into erroneous work area
wa_error-bukrs = wa_data-bukrs.
wa_error-ekorg = wa_data-ekorg.
wa_error-ktokk = wa_data-ktokk.
wa_error-name1 = wa_data-name1.
wa_error-sortl = wa_data-sortl.
*appending the erroneous work area to the erroneous internal table
APPEND wa_error TO it_error.
ENDIF.
TO DOWN LOAD THE ERRANEOUS RECORDS
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = lf_dname
filetype = 'ASC'
write_field_separator = 'X'
TABLES
data_tab = it_error
EXCEPTIONS
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
OTHERS = 22.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*ending the loop
ENDLOOP.
ENDFORM. " fr_format_message
‎2007 May 23 5:12 AM
Are all those messages error or success messages?? I think 2 of them might be warning or information messages.
Can you please check and let us know?
‎2007 May 23 5:12 AM
Are all those messages error or success messages?? I think 2 of them might be warning or information messages.
Can you please check and let us know?
‎2007 May 23 5:19 AM
hi shah,
i am catching all the messages.for checking whether the programming is running properly or not i gave the records that could be successful as the first and the last and in the middle i gave the records that will be unsuccessfull.
i am getting the success messages in the last and the first positions but the two messages are getting repeated in the middle.
i hope that i have given you the correct information.
thanks.
‎2007 May 23 5:27 AM
Still little confused.
IF you need 5 messages (Success messages for successful records and error message for unsuccessful records) then you can use:
LOOP AT it_bdcmsgcoll1 INTO wa_bdcmsgcoll. -- change this to
LOOP AT it_bdcmsgcoll1 INTO wa_bdcmsgcoll where MSGTYP = 'E ' or MSGTYP = 'S'.
If this is not what you are looking for, can you paste the messages here?
‎2007 May 23 5:19 AM
Hi Sara,
Ignore the warning messages.
Consider
change this code as foolws
LOOP AT it_bdcmsgcoll1 INTO wa_bdcmsgcoll. -- change this to
LOOP AT it_bdcmsgcoll1 INTO wa_bdcmsgcoll where MSGTYP = 'E '.
tHIS SHOULD SOLVE YOUR PROBLEM
Award points if helpful
‎2007 May 23 5:21 AM
hi venki,
the thing is i am creating a vendor group here so i need to catch up the success messages also to know the vendor account.
pls see through it.
thanks.
‎2007 May 23 8:11 AM
Can you change the logic for displaying messages?
Rather than displaying the messages in seperate subroutine, why don't you display all the messages right after the CALL TRANSACTION?
‎2007 May 23 8:19 AM
Hi,
Check the value of field MSGV2 for all records. May be you got 2 messages(like Warning or Success or Error) for single record.
If you want to capture all success and error then you can write loop at and enloop 2 times with MSGTYP = 'E' and MSGTYP = 'S'.
Cheers,
Bujji
‎2007 May 23 8:26 AM
Hi,
CALL TRANSACTION 'XK01' USING it_bdcdata MODE 'N' UPDATE 'S' MESSAGES
INTO it_bdcmsgcoll.
APPEND LINES OF it_bdcmsgcoll TO it_bdcmsgcoll1.
You are appending it_bdcmsgcoll to it_bdcmsgcoll1, so if the same error occured for two records of it_data , it will storre both of them bcoz you are not checking for duplicates.!
Also, when one of the records of it_data are erroneous, there may be more than one error msg returned in table it_bdcmsgcoll1 (not neccessarily one)
If you want to check this, go to debug mode and analyse each error msg returned in table it_bdcmsgcoll1 for each record in it_data individually!
Hope that this helps you.
Regards,
Sooness.