Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

capturing bdc messages and modifying internal table

Former Member
0 Likes
1,056

hi experts,

my requirement in VA01 BDC is to capture the error messages which gets generated during BDC transaction and then highlight that error message into the last column of internal table of that particular errornous row.

Pls help.

Thanks,

Gaurav

1 REPLY 1
Read only

Former Member
0 Likes
565

While doing call transaction, if an error occurs in updation, we declare bdcmsgcoll and store our messages in it, but how to retreive error message from it .

Internal table BDCMSG like BDCMSGCOLL.

Syntax:

DATA KTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

Example code:

tables zemptab1.

data: begin of itab1 occurs 0,

str(255),

end of itab1.

data: begin of itab occurs 0,

zempid3 like zemptab1-zempid3,

zename3 like zemptab1-zename3,

zedepid like zemptab1-zedepid,

zsalkey like zemptab1-zsalkey,

salary like zemptab1-salary,

end of itab.

data bdc_data like bdcdata occurs 0 with header line.

data: bdcmsg like bdcmsgcoll occurs 0 with header line.

data: var1 like rlgrap-filename.

data : name1 type string.

call function 'KD_GET_FILENAME_ON_F4'

exporting

program_name = syst-repid

dynpro_number = syst-dynnr

changing

file_name = var1.

if sy-subrc <> 0.

endif.

name1 = var1.

call function 'GUI_UPLOAD'

exporting

filename = name1

  • FILETYPE = 'ASC'

has_field_separator = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

  • VIRUS_SCAN_PROFILE =

  • IMPORTING

  • FILELENGTH =

  • HEADER =

tables

data_tab = itab.

  • 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.

loop at itab1.

split itab1-str at ',' into itab-zempid3 itab-zename3 itab-zedepid itab-zsalkey." ITAB-SALARY.

append itab.

endloop.

loop at itab.

insert into zemptab1 values itab.

if sy-subrc = 0.

message 'RECORDS INSERTED SUCCESSFULLY' type 'S'.

else.

perform proginfo using 'SAPLSD41' '2200'.

perform fldinfo using zemptab1-zempid3 itab-zempid3.

perform fldinfo using zemptab1-zename3 itab-zename3.

perform fldinfo using zemptab1-zedepid itab-zedepid.

perform fldinfo using zemptab1-zsalkey itab-zsalkey.

perform fldinfo using zemptab1-salary itab-salary.

endif.

endloop.

call transaction 'SM30' using bdc_data mode 'N' messages into bdcmsg.

loop at bdcmsg.

write : / bdcmsg.

endloop.

form proginfo using program dynpro.

clear bdc_data.

bdc_data-program = program.

bdc_data-dynpro = dynpro.

bdc_data-dynbegin = 'X'.

append bdc_data.

endform.

form fldinfo using fnam fval.

  • IF FVAL <> NODATA.

clear bdc_data.

bdc_data-fnam = fnam.

bdc_data-fval = fval.

append bdc_data.

  • ENDIF.

endform.

*******************************************************************

Using function module 'FORMAT_MESSAGE' you can capture the messages.

Here is a sample of the program code for that:

LOOP AT it_messtab.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

id = it_messtab-msgid

lang = it_messtab-msgspra

no = it_messtab-msgnr

v1 = it_messtab-msgv1

v2 = it_messtab-msgv2

IMPORTING

msg = g_msg

EXCEPTIONS

OTHERS = 0.

IF it_messtab-msgtyp = 'S'.

it_sucess-sucess_rec = g_msg.

it_sucess-lifnr = it_header-lifnr." Based on your field

it_sucess-tabix = v_lines.

APPEND it_sucess.

ELSEIF it_messtab-msgtyp = 'E'.

it_error-error_rec = g_msg.

it_error-lifnr = it_header-lifnr.

it_error-tabix = v_lines.

APPEND it_error.

ELSE.

it_info-info_rec = g_msg.

it_info-lifnr = it_header-lifnr.

it_info-tabix = v_lines.

APPEND it_info.

ENDIF.

ENDLOOP.

Hope this solves ur problem,

Regards,

Sri