Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

bdc error

Hi frnds ,

I have written BDC for XK01 , below i m giving my code , my problem is i m not getting the write statement regarding SUCCESS RECORDS.

the below part of code is not getting executed if at all after bdc there are succesful records.

  • Display Successful Records

write: /5 'Sucessful Records' color col_positive.

loop at it_success into wa_success.

write : /5 wa_success-lineno, wa_success-lifnr, wa_success-name1.

endloop.

Here is my complete code.

<code>

eport zbdc

no standard page heading line-size 255.

*PARAMETERS: P_PFILE LIKE RLGRAP-FILENAME.

data: file type ibipparms-path,

fname type string.

*-BDC Related Data Decleration

types : begin of st_lfa1,

ktokk type rf02k-ktokk,

anred type lfa1-anred,

name1 type lfa1-name1,

sortl type lfa1-sortl,

stras type lfa1-stras,

ort01 type lfa1-ort01,

pstlz type lfa1-pstlz,

land1 type lfa1-land1,

konzs type lfa1-konzs,

stcd1 type lfa1-stcd1,

stkza type lfa1-stkza,

stkzu type lfa1-stkzu,

banks type lfbk-banks,

bankl type lfbk-bankl,

bankn type lfbk-bankn,

banka type bnka-banka,

end of st_lfa1.

types: begin of st_error,

lineno type i,

lifnr type lfa1-lifnr,

message type string,

end of st_error.

types: begin of st_success,

lineno type i,

lifnr type lfa1-lifnr,

name1 type lfa1-name1,

end of st_success.

*------INTERNAL TABLE DECLARATION

data: it_lfa1 type standard table of st_lfa1,

wa_lfa1 type st_lfa1.

data: it_bdctab type standard table of bdcdata ,

it_messages type standard table of bdcmsgcoll ,

it_error type standard table of st_error,

it_success type standard table of st_success,

wa_bdctab like line of it_bdctab,

wa_messages like line of it_messages,

wa_success type st_success,

wa_error type st_error.

data : v_count type i,

v_errors type i,

v_success type i,

v_index like sy-tabix,

v_tot_lines type i,

v_err_lines type i,

v_suc_lines type i,

v_err_grp type c.

*------SELECTION-SCREEN.

selection-screen begin of block b1 with frame title text-001.

parameters: p_file type rlgrap-filename.

selection-screen begin of line.

parameters: r1 radiobutton group g1 default 'X' user-command us1.

selection-screen comment 4(20) text-003 for field r1.

selection-screen end of line.

selection-screen begin of line.

parameters: r2 radiobutton group g1 .

selection-screen comment 4(20) text-004 for field r2.

selection-screen end of line.

parameters: p_sess(12) type c.

parameters: p_ress as checkbox default 'X'.

selection-screen end of block b1.

*------AT SELECTION-SCREEN.

at selection-screen on value-request for p_file.

perform get_file.

*------ Start of selection

start-of-selection.

  • To upload file

perform upload_file.

  • CLEAR WA_LFA1.

loop at it_lfa1 into wa_lfa1.

v_count = sy-tabix.

perform load_bdcdata.

if r1 eq 'X'.

perform call_transaction.

elseif r2 eq 'X'.

perform session.

endif.

endloop.

end-of-selection.

perform disp_summary.

*&----


*

*& Form sele_file

*&----


*

  • text

*----


*

  • --> p1 text

  • <-- p2 text

*----


*

form get_file .

call function 'F4_FILENAME'

  • EXPORTING

  • PROGRAM_NAME = SYST-CPROG

  • DYNPRO_NUMBER = SYST-DYNNR

  • FIELD_NAME = ' '

importing

file_name = p_file.

endform. "

*include bdcrecx1.

form upload_file .

data: l_filename type string.

l_filename = p_file.

call function 'GUI_UPLOAD'

exporting

filename = l_filename

filetype = 'ASC'

has_field_separator = 'X'

tables

data_tab = it_lfa1

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.

write 'file not found'.

endif.

endform. " UPLOAD_FILE

*&----


*

*& Form load_bdcdata

*&----


*

  • text

*----


*

form load_bdcdata.

perform append_bdc_tab

using : 'X' 'SAPMF02K' '0100',

' ' 'BDC_OKCODE' '/00',

' ' 'RF02K-KTOKK' wa_lfa1-ktokk,

'X' 'SAPMF02K' '0110',

' ' 'BDC_OKCODE' '/00',

' ' 'LFA1-ANRED' wa_lfa1-anred,

' ' 'LFA1-NAME1' wa_lfa1-name1,

' ' 'LFA1-SORTL' wa_lfa1-sortl,

' ' 'LFA1-STRAS' wa_lfa1-stras,

' ' 'LFA1-ORT01' wa_lfa1-ort01,

' ' 'LFA1-PSTLZ' wa_lfa1-pstlz,

' ' 'LFA1-LAND1' wa_lfa1-land1,

' ' 'BDC_OKCODE' '/00',

'X' 'SAPMF02K' '0120',

' ' 'BDC_OKCODE' '/00',

' ' 'LFA1-KONZS' wa_lfa1-konzs,

' ' 'LFA1-STCD1' wa_lfa1-stcd1,

' ' 'LFA1-STKZA' 'X',

' ' 'LFA1-STKZU' 'X',

' ' 'BDC_OKCODE' '/00',

'X' 'SAPMF02K' '0130',

' ' 'BDC_OKCODE' '=ENTR',

' ' 'LFBK-BANKS(01)' wa_lfa1-banks,

' ' 'LFBK-BANKL(01)' wa_lfa1-bankl,

' ' 'LFBK-BANKN(01)' wa_lfa1-bankn,

' ' 'BDC_OKCODE' '=ENTR',

' ' 'BNKA-BANKA' wa_lfa1-banka.

endform. "load_bdcdata

*&----


*

*& Form append_bdc_tab

*&----


*

form append_bdc_tab using p_flag

p_fname

p_fval.

clear it_bdctab.

if p_flag = 'X'.

wa_bdctab-program = p_fname.

wa_bdctab-dynpro = p_fval.

wa_bdctab-dynbegin = 'X'.

append wa_bdctab to it_bdctab.

elseif not p_fval is initial.

wa_bdctab-fnam = p_fname.

wa_bdctab-fval = p_fval.

append wa_bdctab to it_bdctab.

endif.

endform. " append_bdc_tab

*&----


*

*& Form CALL_TRANSACTION

*&----


*

form call_transaction .

call transaction 'XK01' using it_bdctab

mode 'N'

update 'S'

messages into it_messages.

if sy-subrc = 0.

  • Append successful record to Succss Table

read table it_messages into wa_messages with key msgtyp = 'S'.

if sy-subrc = 0.

wa_success-lineno = v_count.

wa_success-lifnr = wa_messages-msgv1.

wa_success-name1 = wa_lfa1-name1.

append wa_success to it_success.

clear wa_success.

endif.

else.

read table it_messages into wa_messages with key msgtyp = 'E'.

if sy-subrc = 0.

  • Format the error message

call function 'FORMAT_MESSAGE'

exporting

id = sy-msgid

no = wa_messages-msgnr

v1 = wa_messages-msgv1

v2 = wa_messages-msgv2

v3 = wa_messages-msgv3

v4 = wa_messages-msgv4

importing

msg = wa_error-message

exceptions

others = 0.

wa_error-lineno = v_count.

append wa_error to it_error.

clear wa_error.

endif.

*----create session for error records.

if v_err_grp eq 'X'.

data : p_grp(12) value 'VEN_ERR',

p_keep(1).

call function 'BDC_OPEN_GROUP'

exporting

client = sy-mandt

group = p_grp

user = sy-uname

keep = p_keep

prog = sy-cprog

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 = 'XK01'

tables

dynprotab = it_bdctab

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.

endif.

endif.

clear: it_bdctab, it_messages.

refresh: it_bdctab, it_messages.

endform. "CALL_TRANSACTION

*&----


*

*& Form SESSION

*&----


*

form session .

perform bdc_open.

perform bdc_insert.

perform bdc_close.

endform. " SESSION

*&----


*

*& Form BDC_OPEN

*&----


*

form bdc_open .

call function 'BDC_OPEN_GROUP'

exporting

client = sy-mandt

group = p_sess

user = sy-uname

prog = sy-cprog

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. "BDC_OPEN

*&----


*

*& Form BDC_INSERT

*&----


*

form bdc_insert .

call function 'BDC_INSERT'

exporting

tcode = 'XK01'

tables

dynprotab = it_bdctab

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 BDC_CLOSE

*&----


*

form bdc_close .

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. "BDC_CLOSE

*&----


*

*& Form disp_summary

*&----


*

form disp_summary .

if r2 eq 'X'.

message 'Sesion has been created' type 'S'.

elseif r1 eq 'X'.

describe table it_lfa1 lines v_tot_lines.

describe table it_error lines v_err_lines.

*---DESCRIBE TABLE IT_SUCCESS LINES V_SUC_REC.

v_suc_lines = v_tot_lines - v_err_lines.

format color 4 on.

write : /8 'RECONCILIATION REPORT'.

skip 1.

write : /5 'Total Records Processed :', 25 v_tot_lines,

/5 'Error Records :', 25 v_err_lines,

/5 'Successful Records :', 25 v_suc_lines.

format color 4 off.

skip 2.

  • Display Successful Records

write: /5 'Sucessful Records' color col_positive.

loop at it_success into wa_success.

write : /5 wa_success-lineno, wa_success-lifnr, wa_success-name1.

endloop.

skip 2.

  • Display Error Records

write: /5 'Error Records' color col_negative..

loop at it_error into wa_error.

write : /5 wa_error-lineno,wa_error-message.

endloop.

endif.

endform. "disp_summary

</code>

Thanks,

sanjay

Tags:
Former Member
Not what you were looking for? View more on this topic or Ask a question