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

to handle errors

Former Member
0 Likes
421

Hi, if tr r 100 records to be updated, if 3, 52 and 99 records are failed ,what happens in case of session and calltransaction method, how we can correct the errors in both cases and what happens they will update remaining fields or not.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
397

hi,

if you use session u can check unprocessed records using SM35 tcode.In sm35 after processing the session you can check error log for unprocessed records depending up on the error message we can modify that particular record.

In the call transaction method we have to explicitly catch errors using BDCMSGCOLL and FORMAT_messages.

just check the below coding.

Handling errors in calltransaction using XK01 tcode.

REPORT ZSR_BDC_CT_ERROR1.

TABLES : RF02K,LFA1.

DATA: BEGIN OF ITAB OCCURS 0,

LIFNR LIKE RF02K-LIFNR,

KTOKK LIKE RF02K-KTOKK,

NAME1 LIKE LFA1-NAME1,

SORTL LIKE LFA1-SORTL,

LAND1 LIKE LFA1-LAND1,

SPRAS LIKE LFA1-SPRAS,

END OF ITAB.

DATA : BDCTAB LIKE BDCDATA OCCURS 0 WITH HEADER LINE,

BDCMSG LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

INCLUDE BDCRECX1.

START-OF-SELECTION.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'z:\flatfiles\sr1.txt'

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

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

*perform open_group.

LOOP AT ITAB.

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-LIFNR'

ITAB-LIFNR.

PERFORM BDC_FIELD USING 'RF02K-KTOKK'

ITAB-KTOKK.

PERFORM BDC_DYNPRO USING 'SAPMF02K' '0110'.

PERFORM BDC_FIELD USING 'BDC_CURSOR'

'LFA1-SPRAS'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'/00'.

PERFORM BDC_FIELD USING 'LFA1-NAME1'

ITAB-NAME1.

PERFORM BDC_FIELD USING 'LFA1-SORTL'

ITAB-SORTL.

PERFORM BDC_FIELD USING 'LFA1-LAND1'

ITAB-LAND1.

PERFORM BDC_FIELD USING 'LFA1-SPRAS'

ITAB-SPRAS.

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 'SAPLSPO1' '0300'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'=YES'.

PERFORM BDC_TRANSACTION USING 'XK01'.

IF SY-SUBRC <> 0.

*LOOP AT bdcmsg.

*WRITE: bdcmsg-DYNAME,

  • bdcmsg-DYNUMB,

  • bdcmsg-MSGTYP,

  • bdcmsg-MSGSPRA,

  • bdcmsg-MSGID,

  • bdcmsg-MSGNR,

  • bdcmsg-MSGV1,

  • bdcmsg-MSGV2,

  • bdcmsg-MSGV3,

  • bdcmsg-MSGV4.

*ENDLOOP.

READ TABLE BDCMSG WITH KEY MSGTYP = 'E'.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = BDCMSG-MSGID

LANG = SY-LANGU

NO = BDCMSG-MSGNR

V1 = BDCMSG-MSGV1

V2 = BDCMSG-MSGV2

V3 = BDCMSG-MSGV3

V4 = BDCMSG-MSGV4

IMPORTING

MSG = BDCMSG-MSGV1

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

WRITE : / BDCMSG-MSGV1.

ENDIF.

ENDLOOP.

*perform close_group.

2 REPLIES 2
Read only

Former Member
0 Likes
397

Hi,

In Session method, you can go to transaction SM35 and re-process the errored records.

In Call transaction, you have to handle error programatically.

I hope this helps.

Let me know if you need more information.

Regards,

RS

Read only

Former Member
0 Likes
398

hi,

if you use session u can check unprocessed records using SM35 tcode.In sm35 after processing the session you can check error log for unprocessed records depending up on the error message we can modify that particular record.

In the call transaction method we have to explicitly catch errors using BDCMSGCOLL and FORMAT_messages.

just check the below coding.

Handling errors in calltransaction using XK01 tcode.

REPORT ZSR_BDC_CT_ERROR1.

TABLES : RF02K,LFA1.

DATA: BEGIN OF ITAB OCCURS 0,

LIFNR LIKE RF02K-LIFNR,

KTOKK LIKE RF02K-KTOKK,

NAME1 LIKE LFA1-NAME1,

SORTL LIKE LFA1-SORTL,

LAND1 LIKE LFA1-LAND1,

SPRAS LIKE LFA1-SPRAS,

END OF ITAB.

DATA : BDCTAB LIKE BDCDATA OCCURS 0 WITH HEADER LINE,

BDCMSG LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

INCLUDE BDCRECX1.

START-OF-SELECTION.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'z:\flatfiles\sr1.txt'

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

  • HEADER_LENGTH = 0

  • READ_BY_LINE = 'X'

  • DAT_MODE = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • CHECK_BOM = ' '

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

*perform open_group.

LOOP AT ITAB.

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-LIFNR'

ITAB-LIFNR.

PERFORM BDC_FIELD USING 'RF02K-KTOKK'

ITAB-KTOKK.

PERFORM BDC_DYNPRO USING 'SAPMF02K' '0110'.

PERFORM BDC_FIELD USING 'BDC_CURSOR'

'LFA1-SPRAS'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'/00'.

PERFORM BDC_FIELD USING 'LFA1-NAME1'

ITAB-NAME1.

PERFORM BDC_FIELD USING 'LFA1-SORTL'

ITAB-SORTL.

PERFORM BDC_FIELD USING 'LFA1-LAND1'

ITAB-LAND1.

PERFORM BDC_FIELD USING 'LFA1-SPRAS'

ITAB-SPRAS.

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 'SAPLSPO1' '0300'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'=YES'.

PERFORM BDC_TRANSACTION USING 'XK01'.

IF SY-SUBRC <> 0.

*LOOP AT bdcmsg.

*WRITE: bdcmsg-DYNAME,

  • bdcmsg-DYNUMB,

  • bdcmsg-MSGTYP,

  • bdcmsg-MSGSPRA,

  • bdcmsg-MSGID,

  • bdcmsg-MSGNR,

  • bdcmsg-MSGV1,

  • bdcmsg-MSGV2,

  • bdcmsg-MSGV3,

  • bdcmsg-MSGV4.

*ENDLOOP.

READ TABLE BDCMSG WITH KEY MSGTYP = 'E'.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = BDCMSG-MSGID

LANG = SY-LANGU

NO = BDCMSG-MSGNR

V1 = BDCMSG-MSGV1

V2 = BDCMSG-MSGV2

V3 = BDCMSG-MSGV3

V4 = BDCMSG-MSGV4

IMPORTING

MSG = BDCMSG-MSGV1

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

WRITE : / BDCMSG-MSGV1.

ENDIF.

ENDLOOP.

*perform close_group.