Skip to Content

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

call transaction error handling

how to maintain the log i.e sucess/failures like below.

Line No. Success/ Failure Document No Error Details

1 S Doc 740000001

2 S Doc 740000002

3 F Co- code does not exist

4 F GL Account does not exist

I'm getting only one last document no: but i need all the documents to be displayed i.e either success/failures.

below is my code.

TYPES: BEGIN OF ty_filedata,

bukrs TYPE bukrs, "Company code

blart TYPE blart, "Document type

bldat TYPE char10, "Document Date

budat TYPE char10, "Posting date

xblnr TYPE xblnr, "Reference

bktxt TYPE bktxt, "Document Header text

waers TYPE waers, "Currency

newbs TYPE bschl, "Posting Key for the next line item

wrbtr TYPE char10, "Amount

zuonr LIKE bsik-zuonr, "Assignment

sgtxt TYPE sgtxt, "Text

newko TYPE hkont, "Account for the next line item

END OF ty_filedata.

TYPES: BEGIN OF ty_detail_log,

item_no TYPE i, " Item line no.

status(1) TYPE c, " Status - success/failure

doc_no TYPE bkpf-belnr," Document No.

message TYPE string, " Message

END OF ty_detail_log.

&----


*& DATA declaration of internal tables

&----


  • Internal Table declaration for excel data

DATA: it_itab TYPE STANDARD TABLE OF alsmex_tabline INITIAL SIZE 0,

  • Internal Table declaration for upload data

it_upload TYPE STANDARD TABLE OF ty_filedata INITIAL SIZE 0,

  • Internal Table Declaration for BDCDATA

it_bdcdata TYPE STANDARD TABLE OF bdcdata,

  • Internal Table Declaration for BDCMSGCOLL

it_bdcmsgcoll TYPE STANDARD TABLE OF bdcmsgcoll,

  • Internal Table Declaration for FILENMAE

lf_fname TYPE rlgrap-filename.

  • t_err_log TYPE STANDARD TABLE OF ty_err

  • INITIAL SIZE 0, " table for validation error log

  • t_DETAIL_LOG TYPE STANDARD TABLE OF TY_DETAIL_LOG.

  • C_MSGNO TYPE BDC_MNR VALUE '312',

&----


*& DATA declaration of work area

&----


  • Work Area declaration for Excel Data

DATA: w_itab TYPE alsmex_tabline,

  • Work Area declaration for upload data

w_upload TYPE ty_filedata,

  • Work Area declaration for upload data

w_upload_n TYPE ty_filedata,

  • Work Area declaration for upload data

w_bdcdata TYPE bdcdata,

  • Work Area declaration for upload data

w_bdcmsgcoll TYPE bdcmsgcoll,

w_detail_log TYPE ty_detail_log.

&----


*& SELECTION-SCREEN

&----


SELECTION-SCREEN: BEGIN OF BLOCK bk1 WITH FRAME TITLE text-001.

PARAMETERS:p_file TYPE rlgrap-filename. " MODIF ID G1.

SELECTION-SCREEN: END OF BLOCK bk1.

&----


*& AT SELECTION SCREEN

&----


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

dynpro_number = syst-dynnr

CHANGING

file_name = p_file

EXCEPTIONS

mask_too_long = 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.

&----


*& START-OF-SELECTION

&----


START-OF-SELECTION.

DATA: lw_itab TYPE alsmex_tabline.

lf_fname = p_file.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

filename = lf_fname

i_begin_col = '1'

i_begin_row = '6'

i_end_col = '12'

i_end_row = '999'

TABLES

intern = it_itab[]

EXCEPTIONS

inconsistent_parameters = 1

upload_ole = 2

OTHERS = 3.

IF sy-subrc <> 0.

*MESSAGE S205(ZF_COMMON_MSGS_FIN1) DISPLAY LIKE C_E.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

  • ELSE.

IF it_itab IS NOT INITIAL.

SORT it_itab BY row col.

  • DELETE it_itab WHERE row LT 6.

LOOP AT it_itab INTO lw_itab.

w_itab = lw_itab.

AT NEW row.

CLEAR: w_upload.

ENDAT.

CASE w_itab-col.

WHEN '0001'.

w_upload-bukrs = w_itab-value.

WHEN '0002'.

w_upload-blart = w_itab-value.

WHEN '0003'.

w_upload-bldat = w_itab-value.

WHEN '0004'.

w_upload-budat = w_itab-value.

WHEN '0005'.

w_upload-xblnr = w_itab-value.

WHEN '0006'.

w_upload-bktxt = w_itab-value.

WHEN '0007'.

w_upload-waers = w_itab-value.

WHEN '0008'.

w_upload-newbs = w_itab-value.

WHEN '0009'.

w_upload-wrbtr = w_itab-value.

WHEN '0010'..

w_upload-zuonr = w_itab-value.

WHEN '0011'.

w_upload-sgtxt = w_itab-value.

WHEN '0012'.

w_upload-newko = w_itab-value.

ENDCASE.

AT END OF row.

APPEND w_upload TO it_upload.

CLEAR: w_upload.

ENDAT.

ENDLOOP.

*endif.

ENDIF.

DATA: lw_upload TYPE ty_filedata,

lv_lines TYPE sy-tabix,

lv_index TYPE sy-tabix.

DESCRIBE TABLE it_upload LINES lv_lines.

LOOP AT it_upload INTO lw_upload.

lv_index = sy-tabix.

w_upload = lw_upload.

IF NOT w_upload-bukrs IS INITIAL.

IF lv_index GT 1.

  • CALL TRANSACTION 'FB01' USING it_bdcdata

  • MODE 'N' UPDATE 'S' MESSAGES INTO it_bdcmsgcoll.

  • PERFORM fr_format_message_text.

REFRESH: it_bdcdata.

ENDIF.

PERFORM bdc_dynpro USING 'SAPMF05A' '0100'.

PERFORM bdc_field USING 'BDC_CURSOR'

'BKPF-XBLNR'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'BKPF-BLDAT'

w_upload-bldat.

PERFORM bdc_field USING 'BKPF-BLART'

w_upload-blart.

PERFORM bdc_field USING 'BKPF-BUKRS'

w_upload-bukrs.

PERFORM bdc_field USING 'BKPF-BUDAT'

w_upload-budat.

PERFORM bdc_field USING 'BKPF-WAERS'

w_upload-waers.

PERFORM bdc_field USING 'BKPF-XBLNR'

w_upload-xblnr.

*perform bdc_field using 'FS006-DOCID'

  • '*'.

PERFORM bdc_field USING 'RF05A-NEWBS'

w_upload-newbs.

PERFORM bdc_field USING 'RF05A-NEWKO'

w_upload-newko.

ENDIF.

IF lv_index NE lv_lines.

lv_index = lv_index + 1.

READ TABLE it_upload INTO w_upload_n INDEX lv_index.

PERFORM bdc_dynpro USING 'SAPMF05A' '0300'.

PERFORM bdc_field USING 'BDC_CURSOR'

'BSEG-WRBTR'.

PERFORM bdc_field USING 'BDC_OKCODE'

'/00'.

PERFORM bdc_field USING 'BSEG-WRBTR'

w_upload-wrbtr.

PERFORM bdc_field USING 'RF05A-NEWBS'

w_upload_n-newbs.

PERFORM bdc_field USING 'RF05A-NEWKO'

w_upload_n-newko.

ELSE.

PERFORM bdc_dynpro USING 'SAPMF05A' '0300'.

PERFORM bdc_field USING 'BDC_CURSOR'

'BSEG-WRBTR'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=BU'.

PERFORM bdc_field USING 'BSEG-WRBTR'

w_upload-wrbtr.

ENDIF.

PERFORM bdc_dynpro USING 'SAPLKACB' '0002'.

PERFORM bdc_field USING 'BDC_CURSOR'

'COBL-ANLN1'.

PERFORM bdc_field USING 'BDC_OKCODE'

'=ENTE'.

ENDLOOP.

CALL TRANSACTION 'FB01' USING it_bdcdata

MODE 'N' UPDATE 'S' MESSAGES INTO it_bdcmsgcoll.

PERFORM fr_format_message_text .

REFRESH: it_bdcdata.

&----


*& Form BDC_DYNPRO

&----


FORM bdc_dynpro USING program dynpro.

CLEAR w_bdcdata.

w_bdcdata-program = program.

w_bdcdata-dynpro = dynpro.

w_bdcdata-dynbegin = 'X'.

APPEND w_bdcdata TO it_bdcdata.

ENDFORM. "BDC_DYNPRO

----


  • Insert field *

----


FORM bdc_field USING fnam fval.

IF fval <> space.

CLEAR w_bdcdata.

w_bdcdata-fnam = fnam.

w_bdcdata-fval = fval.

APPEND w_bdcdata TO it_bdcdata.

ENDIF.

ENDFORM. "BDC_FIELD

&----


*& Form fr_format_message_text

&----


FORM fr_format_message_text.

DATA: lf_msg TYPE string.

WRITE:/ sy-uline(125).

FORMAT COLOR 1 INTENSIFIED ON.

WRITE : /1 sy-vline,

2 text-041 , "'record Number',

16 sy-vline,

17 text-042 , " 'success/failure',

35 sy-vline,

36 text-043, " 'document no',

55 sy-vline,

56 text-044, "'Error details',

125 sy-vline.

WRITE:/ sy-uline(125).

LOOP AT it_bdcmsgcoll INTO w_bdcmsgcoll.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

id = w_bdcmsgcoll-msgid

lang = sy-langu

no = w_bdcmsgcoll-msgnr

v1 = w_bdcmsgcoll-msgv1

v2 = w_bdcmsgcoll-msgv2

v3 = w_bdcmsgcoll-msgv3

v4 = w_bdcmsgcoll-msgv4

IMPORTING

msg = lf_msg

EXCEPTIONS

not_found = 1

OTHERS = 2.

IF sy-subrc EQ 0.

WRITE:/01 sy-vline,

02 sy-tabix,

16 sy-vline,

17 w_bdcmsgcoll-msgtyp,

35 sy-vline,

36 w_bdcmsgcoll-msgv1,

55 sy-vline,

56 lf_msg,

125 sy-vline.

WRITE:/ sy-uline(125).

ENDIF.

ENDLOOP.

ENDFORM. "fr_format_message_text

Thanks in advance.

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