Hi
Use below code which gets the errors and success records. You change the code as your requirement.
REPORT ybdc_errlog.
DATA: w_ref_alv TYPEREFTO cl_salv_table.
DATA:
BEGINOF mttab OCCURS4,
off(02) TYPE n,
len(02) TYPE n,
text(99),
ENDOF mttab.
DATA:
BEGINOF par,
len(02) TYPE n,
text(254),
ENDOF par.
FIELD-SYMBOLS:
<mtxt>,
<vtxt>.
DATA save_mpar TYPE bdc_mpar.
DATA:
digits(10) TYPEcVALUE'0123456789',
mtext(124) TYPEc,
mtext1(124) TYPEc,
mtext2(273) TYPEc,
do_condense TYPEc,
mtvaroff TYPEi,
showtyp(05) TYPEc,
lmapn(12) TYPEc,
date1 TYPE d,
linct0 LIKE sy-linct,
parcnt TYPEi,
sp_len TYPEi,
charcnt TYPEi,
wcnt TYPEi,
mparcnt TYPEi,
qfound(04) TYPE n,
x(1) VALUE'X'.
DATA: BEGINOF logtable OCCURS50,
enterdate LIKE btctle-enterdate,
entertime LIKE btctle-entertime,
logmessage(400) TYPEc,
ENDOF logtable.
DATA lm TYPE bdclm.
DATABEGINOF bdclm OCCURS0.
INCLUDESTRUCTURE bdclm.
DATA: counter TYPEi,
longtext TYPE bdc_mpar,
isdetail(1) TYPEc,
ENDOF bdclm .
DATA: logtab_temse TYPESTANDARDTABLEOF apql .
DATA: wa_log TYPE apql,
wa_ld TYPE ztt_bdc,
w_bdcld TYPE ztt_bdc,
logname(80),
bdcld TYPESTANDARDTABLEOF ztt_bdc,
selected_protocol TYPEi.
SELECT * FROM apql INTOTABLE logtab_temse
WHERE qid = '10120911353254644605'.
LOOPAT logtab_temse INTO wa_log.
CLEAR wa_ld.
wa_ld-temseid = wa_log-temseid.
wa_ld-lmand = wa_log-mandant.
wa_ld-edate = wa_log-credate.
wa_ld-etime = wa_log-cretime.
wa_ld-luser = wa_log-creator.
wa_ld-grpn = wa_log-groupid.
wa_ld-quid = wa_log-qid.
wa_ld-local_host = wa_log-destsys(8).
APPEND wa_ld TO bdcld.
ENDLOOP.
* now bdcld contains the log files for the given qid
SORT bdcld BY edate DESCENDING etime DESCENDING.
DESCRIBETABLE bdcld LINES selected_protocol.
IF selected_protocol > 0.
READTABLE bdcld INTO w_bdcld INDEX1.
logname = w_bdcld-logname.
PERFORM read_bdc_log_plain
TABLES logtable
USING w_bdcld-temseid w_bdcld-lmand.
PERFORM extend_message_texts.
ENDIF.
IF bdclm ISNOTINITIAL.
TRY.
CALLMETHOD cl_salv_table=>factory
IMPORTING
r_salv_table = w_ref_alv
CHANGING
t_table = bdclm[].
CATCH cx_salv_msg .
ENDTRY.
w_ref_alv->display( ).
ENDIF.
*&---------------------------------------------------------------------*
*& Form extend_message_texts
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM extend_message_texts.
LOOPAT bdclm .
lm = bdclm.
save_mpar = bdclm-mpar.
PERFORM get_text.
bdclm-longtext = mtext.
bdclm-mpar = save_mpar.
MODIFY bdclm.
ENDLOOP.
ENDFORM. "extend_message_texts
*&---------------------------------------------------------------------*
*& Form get_text
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM get_text.
*
*** Aufbereiten des Messagetextes
*
TABLES t100.
DATA: shiftln TYPEi,
vartcnt TYPEi,
fdpos LIKE sy-fdpos.
IF bdclm-mparcnt CN digits.
bdclm-mparcnt = 0.
ENDIF.
SELECTSINGLE * FROM t100
WHERE sprsl = sy-langu
AND arbgb = bdclm-mid
AND msgnr = bdclm-mnr.
*
IF sy-subrc EQ0.
CLEAR: mtext,
parcnt,
mparcnt,
charcnt,
wcnt,
* mt,
sp_len,
sy-fdpos.
*
MOVE bdclm-mparcnt TO mparcnt.
*
IF t100-textCA'$&'.
MOVE t100-textTO mtext1.
ELSE.
MOVE t100-textTO mtext.
EXIT.
ENDIF.
CLEAR shiftln.
DO mparcnt TIMES.
MOVE bdclm-mpar TO par.
IF par-len CN digits OR par-len EQ0.
par-len = 1.
par-text = ' '.
shiftln = 2.
ELSE.
shiftln = par-len + 2.
ENDIF.
WRITE par-textTO mttab-text(par-len).
MOVE par-len TO mttab-len.
MOVE mparcnt TO mttab-off.
APPEND mttab.
SHIFT bdclm-mpar BY shiftln PLACES.
ENDDO.
*
mtext2 = mtext1.
IF bdclm-mid EQ '00'AND " sonderbehandlung s00368
bdclm-mnr EQ'368'AND
bdclm-mart EQ'S'.
CLEAR mtext2.
CLEAR mttab.
READTABLE mttab INDEX1.
WRITE mttab-textTO mtext2+0(mttab-len).
CLEAR mttab.
READTABLE mttab INDEX2.
WRITE mttab-textTO mtext2+35(mttab-len).
mtext = mtext2.
EXIT.
ENDIF.
do_condense = x.
CLEAR: vartcnt, mtvaroff.
WHILE vartcnt LE3.
vartcnt = vartcnt + 1.
IF mtext1 CA'$&'.
parcnt = parcnt + 1.
IF sy-fdpos GT0.
fdpos = sy-fdpos - 1.
ELSE.
fdpos = sy-fdpos.
ENDIF.
SHIFT mtext1 BY sy-fdpos PLACES.
IF mtext1(1) EQ'&'.
SHIFT mtext1 BY1PLACES.
CASE mtext1(1).
WHEN' '. "'& '
PERFORM replace_var USING'& ' parcnt fdpos.
WHEN'$'. "'&&'
PERFORM replace_var USING'&&'0 fdpos.
WHEN'1'. "'&1'
PERFORM replace_var USING'&1'1 fdpos.
WHEN'2'. "'&2'
PERFORM replace_var USING'&2'2 fdpos.
WHEN'3'. "'&3'
PERFORM replace_var USING'&3'3 fdpos.
WHEN'4'. "'&4'
PERFORM replace_var USING'&4'4 fdpos.
WHENOTHERS. "'&'
PERFORM replace_var USING'&<' parcnt fdpos.
ENDCASE.
ENDIF.
IF mtext1(1) EQ'$'.
SHIFT mtext1 BY1PLACES.
CASE mtext1(1).
WHEN' '. "'$ '
PERFORM replace_var USING'$ ' parcnt fdpos.
WHEN'$'. "'$$'
PERFORM replace_var USING'$$'0 fdpos.
WHEN'1'. "'$1'
PERFORM replace_var USING'$1'1 fdpos.
WHEN'2'. "'$2'
PERFORM replace_var USING'$2'2 fdpos.
WHEN'3'. "'$3'
PERFORM replace_var USING'$3'3 fdpos.
WHEN'4'. "'$4'
PERFORM replace_var USING'$4'4 fdpos.
WHENOTHERS. "'$'
PERFORM replace_var USING'$<' parcnt fdpos.
ENDCASE.
ENDIF.
ENDIF.
ENDWHILE.
*
IF mtext2 CA'%%D%%'.
REPLACE'%%D%%'WITH'$'INTO mtext2.
ENDIF.
IF mtext2 CA'%%A%%'.
REPLACE'%%A%%'WITH'&'INTO mtext2.
ENDIF.
IF do_condense EQ space.
mtext = mtext2.
ELSE.
CONDENSE mtext2 .
mtext = mtext2.
ENDIF.
ELSE.
mtext = '???????????????????????????????????????????????????'.
ENDIF.
*
ENDFORM. " get_text1
*&---------------------------------------------------------------------*
*& Form READ_BDC_LOG_PLAIN
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LOGTABLE text
* -->P_BDCLD_TEMSEID text
* -->P_BDCLD_LMAND text
*----------------------------------------------------------------------*
FORM read_bdc_log_plain TABLES log_table
USING p_bdcld_temseid
p_bdcld_lmand.
DATA: charcp LIKE rststype-charco VALUE'0000'.
FREE log_table.
CALLFUNCTION'RSTS_GET_ATTRIBUTES'
EXPORTING
authority = ' '
client = sy-mandt
name = p_bdcld_temseid
IMPORTING
charco = charcp
EXCEPTIONS
fb_error = 1
fb_rsts_other = 2
no_object = 3
no_permission = 4
OTHERS = 5.
IF cl_abap_char_utilities=>charsize > 1.
charcp = '0000'.
ENDIF.
CALLFUNCTION'RSTS_OPEN_RLC'
EXPORTING
name = p_bdcld_temseid
client = sy-mandt
authority = 'BATCH'
prom = 'I'
rectyp = 'VNL----'
charco = charcp
EXCEPTIONS
fb_call_handle = 4
fb_error = 8
fb_rsts_noconv = 12
fb_rsts_other = 16
no_object = 20
OTHERS = 24.
IF sy-subrc > 0.
EXIT.
ENDIF.
CALLFUNCTION'RSTS_READ'
TABLES
datatab = log_table
EXCEPTIONS
fb_call_handle = 4
fb_error = 8
fb_rsts_noconv = 12
fb_rsts_other = 16
OTHERS = 16.
IF sy-subrc > 0.
EXIT.
ENDIF.
CALLFUNCTION'RSTS_CLOSE'
EXCEPTIONS
OTHERS = 4.
IF sy-subrc > 0.
EXIT.
ENDIF.
CLEAR bdclm[].
LOOPAT logtable.
CLEAR bdclm.
bdclm-indate = logtable-enterdate.
bdclm-intime = logtable-entertime.
bdclm+14(352) = logtable-logmessage.
IF bdclm-mcnt > 0.
bdclm-mcnt = bdclm-mcnt - 1.
ENDIF.
IF bdclm-mid EQ'00'.
IF ( bdclm-mnr EQ'162' )
OR ( bdclm-mnr EQ'368' ).
bdclm-isdetail = 'X'.
ENDIF.
ENDIF.
APPEND bdclm.
ENDLOOP.
ENDFORM. " READ_BDC_LOG_PLAIN
*&---------------------------------------------------------------------*
*& Form replace_var
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->VARK text
* -->VARI text
* -->VARPOS text
*----------------------------------------------------------------------*
FORM replace_var USING vark vari varpos.
DATA: var(02),
var1,
moff TYPEi.
*
CLEAR: mttab , moff.
var = vark.
SHIFT var BY1PLACES.
CASE var.
WHEN' '. "'& '
READTABLE mttab INDEX vari.
IF sy-subrc EQ0.
moff = varpos + mtvaroff.
ASSIGN mtext2+moff(*) TO<mtxt>.
ASSIGN mttab-text(mttab-len) TO<vtxt>.
var1 = vark.
REPLACE var1 WITH<vtxt> INTO<mtxt>.
mtvaroff = mttab-len.
ELSE.
IF vari GT mparcnt.
moff = varpos + mtvaroff.
ASSIGN mtext2+moff(*) TO<mtxt>.
REPLACE vark WITH' 'INTO<mtxt>.
mtvaroff = 2.
ELSE.
moff = varpos + mtvaroff.
ASSIGN mtext2+moff(*) TO<mtxt>.
REPLACE vark WITH'%%Z%%'INTO<mtxt>.
mtvaroff = 7.
ENDIF.
ENDIF.
WHEN'$'. "'&&'
moff = varpos + mtvaroff.
ASSIGN mtext2+moff(*) TO<mtxt>.
REPLACE vark WITH'%%D%%'INTO<mtxt>.
mtvaroff = 7.
WHEN'&'. "'&&'
moff = varpos + mtvaroff.
ASSIGN mtext2+moff(*) TO<mtxt>.
REPLACE vark WITH'%%A%%'INTO<mtxt>.
mtvaroff = 7.
WHEN'<'. "'&1'
READTABLE mttab INDEX vari.
IF sy-subrc EQ0.
IF vark EQ'&<'.
moff = varpos + mtvaroff.
ASSIGN mtext2+moff(*) TO<mtxt>.
ASSIGN mttab-text(mttab-len) TO<vtxt>.
REPLACE'&'WITH<vtxt> INTO<mtxt>.
mtvaroff = mttab-len.
ENDIF.
IF vark EQ'$<'.
moff = varpos + mtvaroff.
ASSIGN mtext2+moff(*) TO<mtxt>.
ASSIGN mttab-text(mttab-len) TO<vtxt>.
REPLACE'$'WITH<vtxt> INTO<mtxt>.
mtvaroff = mttab-len.
ENDIF.
ELSE.
IF vark EQ'&<'.
moff = varpos + mtvaroff.
ASSIGN mtext2+moff(*) TO<mtxt>.
REPLACE'&'WITH' 'INTO<mtxt>.
mtvaroff = 1.
ENDIF.
IF vark EQ'$<'.
moff = varpos + mtvaroff.
ASSIGN mtext2+moff(*) TO<mtxt>.
REPLACE'$'WITH' 'INTO<mtxt>.
mtvaroff = 1.
ENDIF.
ENDIF.
WHEN'1'. "'&1'
READTABLE mttab INDEX1.
IF sy-subrc EQ0.
moff = varpos + mtvaroff.
ASSIGN mtext2+moff(*) TO<mtxt>.
ASSIGN mttab-text(mttab-len) TO<vtxt>.
REPLACE vark WITH<vtxt> INTO<mtxt>.
mtvaroff = mttab-len.
ELSE.
IF vari GT mparcnt.
moff = varpos + mtvaroff.
ASSIGN mtext2+moff(*) TO<mtxt>.
REPLACE vark WITH' 'INTO<mtxt>.
mtvaroff = 2.
ELSE.
moff = varpos + mtvaroff.
ASSIGN mtext2+moff(*) TO<mtxt>.
REPLACE vark WITH'%%Z%%'INTO<mtxt>.
mtvaroff = 7.
ENDIF.
ENDIF.
WHEN'2'. "'&2'
READTABLE mttab INDEX2.
IF sy-subrc EQ0.
moff = varpos + mtvaroff.
ASSIGN mtext2+moff(*) TO<mtxt>.
ASSIGN mttab-text(mttab-len) TO<vtxt>.
REPLACE vark WITH<vtxt> INTO<mtxt>.
mtvaroff = mttab-len.
ELSE.
IF vari GT mparcnt.
moff = varpos + mtvaroff.
ASSIGN mtext2+moff(*) TO<mtxt>.
REPLACE vark WITH' 'INTO<mtxt>.
mtvaroff = 2.
ELSE.
moff = varpos + mtvaroff.
ASSIGN mtext2+moff(*) TO<mtxt>.
REPLACE vark WITH'%%Z%%'INTO<mtxt>.
mtvaroff = 7.
ENDIF.
ENDIF.
WHEN'3'. "'&3'
READTABLE mttab INDEX3.
IF sy-subrc EQ0.
moff = varpos + mtvaroff.
ASSIGN mtext2+moff(*) TO<mtxt>.
ASSIGN mttab-text(mttab-len) TO<vtxt>.
REPLACE vark WITH<vtxt> INTO<mtxt>.
mtvaroff = mttab-len.
ELSE.
IF vari GT mparcnt.
moff = varpos + mtvaroff.
ASSIGN mtext2+moff(*) TO<mtxt>.
REPLACE vark WITH' 'INTO<mtxt>.
mtvaroff = 2.
ELSE.
moff = varpos + mtvaroff.
ASSIGN mtext2+moff(*) TO<mtxt>.
REPLACE vark WITH'%%Z%%'INTO<mtxt>.
mtvaroff = 7.
ENDIF.
ENDIF.
WHEN'4'. "'&4'
READTABLE mttab INDEX4.
IF sy-subrc EQ0.
moff = varpos + mtvaroff.
ASSIGN mtext2+moff(*) TO<mtxt>.
ASSIGN mttab-text(mttab-len) TO<vtxt>.
REPLACE vark WITH<vtxt> INTO<mtxt>.
mtvaroff = mttab-len.
ELSE.
IF vari GT mparcnt.
moff = varpos + mtvaroff.
ASSIGN mtext2+moff(*) TO<mtxt>.
REPLACE vark WITH' 'INTO<mtxt>.
mtvaroff = 2.
ELSE.
moff = varpos + mtvaroff.
ASSIGN mtext2+moff(*) TO<mtxt>.
REPLACE vark WITH'%%Z%%'INTO<mtxt>.
mtvaroff = 7.
ENDIF.
ENDIF.
ENDCASE.
do_condense = space.
ENDFORM.