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

bdc

Former Member
0 Likes
661

hi,

how we can identify and display the successfull and failure records in session and call transaction method

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
631

hi,

you can check errors in SM35 for Session method.

Call transaction we have to hadle errors explicitly.

for call transaction check this example.we can trnsfer unprocessed records into flat file and even we can open Session for unprocessed records.

REPORT ZSR_BDC_CT_ERROR.

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,

it_error like itab occurs 0 with header line,

BDCMSG LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

START-OF-SELECTION.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'z:\ct.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 dynpro using p2.

*perform bdc_field using p3 p4.

LOOP AT ITAB.

REFRESH BDCTAB.

*

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

CALL TRANSACTION 'XK01' USING BDCTAB MODE 'A' UPDATE 'A' MESSAGES INTO BDCMSG.

*LOOP AT BDCMSG.

if sy-subrc <> 0.

move-corresponding itab to it_error.

endif.

READ TABLE BDCMSG WITH KEY MSGTYP = 'E'.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = BDCMSG-MSGID

LANG = 'EN'

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-MSGNR,BDCMSG-MSGV1.

ENDLOOP.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE = BIN_FILESIZE

filename = 'z:\cerror.txt'

FILETYPE = 'ASC'

  • APPEND = ' '

WRITE_FIELD_SEPARATOR = 'X'

  • HEADER = '00'

  • TRUNC_TRAILING_BLANKS = ' '

  • WRITE_LF = 'X'

  • COL_SELECT = ' '

  • COL_SELECT_MASK = ' '

  • DAT_MODE = ' '

  • CONFIRM_OVERWRITE = ' '

  • NO_AUTH_CHECK = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • WRITE_BOM = ' '

  • TRUNC_TRAILING_BLANKS_EOL = 'X'

  • WK1_N_FORMAT = ' '

  • WK1_N_SIZE = ' '

  • WK1_T_FORMAT = ' '

  • WK1_T_SIZE = ' '

  • IMPORTING

  • FILELENGTH = FILELENGTH

TABLES

data_tab = it_error

  • FIELDNAMES = FIELDNAMES

  • EXCEPTIONS

  • FILE_WRITE_ERROR = 1

  • NO_BATCH = 2

  • GUI_REFUSE_FILETRANSFER = 3

  • INVALID_TYPE = 4

  • NO_AUTHORITY = 5

  • UNKNOWN_ERROR = 6

  • HEADER_NOT_ALLOWED = 7

  • SEPARATOR_NOT_ALLOWED = 8

  • FILESIZE_NOT_ALLOWED = 9

  • HEADER_TOO_LONG = 10

  • DP_ERROR_CREATE = 11

  • DP_ERROR_SEND = 12

  • DP_ERROR_WRITE = 13

  • UNKNOWN_DP_ERROR = 14

  • ACCESS_DENIED = 15

  • DP_OUT_OF_MEMORY = 16

  • DISK_FULL = 17

  • DP_TIMEOUT = 18

  • FILE_NOT_FOUND = 19

  • DATAPROVIDER_EXCEPTION = 20

  • CONTROL_FLUSH_ERROR = 21

  • OTHERS = 22

.

IF sy-subrc <> 0.

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

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

ENDIF.

&----


*& Form dynpro

&----


*

FORM BDC_DYNPRO USING P_P1

P_P2.

CLEAR BDCTAB.

BDCTAB-PROGRAM = P_P1.

BDCTAB-DYNPRO = P_P2.

BDCTAB-DYNBEGIN = 'X'.

APPEND BDCTAB.

ENDFORM. " dynpro

&----


*& Form bdc_field

&----


FORM BDC_FIELD USING P_P3

P_P4.

CLEAR BDCTAB.

BDCTAB-FNAM = P_P3.

BDCTAB-FVAL = P_P4.

APPEND BDCTAB.

ENDFORM. " bdc_field

6 REPLIES 6
Read only

Former Member
0 Likes
631

Hi pandu,

In case of session method, you get error log. just goto SM35 select the session and click LOG.

In case of call transaction, You need to declare an internal table with ref to BDCMSGCOLL and use it as.

CALL TRANSACTION <tcode> using BDCDATA mode 'N' MESSAGES into itab(declared with ref to BDCMSGCOLL). Loop at Table and see the errors.

Reward Points!!!

Younus

Read only

0 Likes
631

but what is the procedure to display that records both successful and failure in to the screen

Read only

0 Likes
631

Pandu,

<b>1/BDC Session :</b> Log will be generated once user run the session in SM35.Unitll unless session ran by user, data will not be loaded and hence log cannot be generated. So SM35 is the only option in this case.

<b>2/ Call Transaction :</b> Use the attribute "messages into t_bdcmsgcoll" after Call Transaction. Where t_bdcmsgcoll is an internal table similar to structure bdcmsgcoll.This structure have fields like MSGNR, MSGTY, MSGV1,MSGV2,MSGV3,MSGV4.

Now -

Loop At t_bdcmsgcoll.

Call Function Module :<b>Write_Message</b> which combines all messages into one field(MESSAHE-MSGTX) accepts above fields value and return a structure MESSAGE*. Now you can write MESSAGE-MSGTX which is the complete message of failure or success after call transaction.

*MESSAGE is retuened after call of <b>Write_Message</b>

Endloop.

Please REWARD THE POINTS.

thanks

Kishor

Read only

Former Member
0 Likes
632

hi,

you can check errors in SM35 for Session method.

Call transaction we have to hadle errors explicitly.

for call transaction check this example.we can trnsfer unprocessed records into flat file and even we can open Session for unprocessed records.

REPORT ZSR_BDC_CT_ERROR.

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,

it_error like itab occurs 0 with header line,

BDCMSG LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

START-OF-SELECTION.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'z:\ct.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 dynpro using p2.

*perform bdc_field using p3 p4.

LOOP AT ITAB.

REFRESH BDCTAB.

*

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

CALL TRANSACTION 'XK01' USING BDCTAB MODE 'A' UPDATE 'A' MESSAGES INTO BDCMSG.

*LOOP AT BDCMSG.

if sy-subrc <> 0.

move-corresponding itab to it_error.

endif.

READ TABLE BDCMSG WITH KEY MSGTYP = 'E'.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = BDCMSG-MSGID

LANG = 'EN'

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-MSGNR,BDCMSG-MSGV1.

ENDLOOP.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

  • BIN_FILESIZE = BIN_FILESIZE

filename = 'z:\cerror.txt'

FILETYPE = 'ASC'

  • APPEND = ' '

WRITE_FIELD_SEPARATOR = 'X'

  • HEADER = '00'

  • TRUNC_TRAILING_BLANKS = ' '

  • WRITE_LF = 'X'

  • COL_SELECT = ' '

  • COL_SELECT_MASK = ' '

  • DAT_MODE = ' '

  • CONFIRM_OVERWRITE = ' '

  • NO_AUTH_CHECK = ' '

  • CODEPAGE = ' '

  • IGNORE_CERR = ABAP_TRUE

  • REPLACEMENT = '#'

  • WRITE_BOM = ' '

  • TRUNC_TRAILING_BLANKS_EOL = 'X'

  • WK1_N_FORMAT = ' '

  • WK1_N_SIZE = ' '

  • WK1_T_FORMAT = ' '

  • WK1_T_SIZE = ' '

  • IMPORTING

  • FILELENGTH = FILELENGTH

TABLES

data_tab = it_error

  • FIELDNAMES = FIELDNAMES

  • EXCEPTIONS

  • FILE_WRITE_ERROR = 1

  • NO_BATCH = 2

  • GUI_REFUSE_FILETRANSFER = 3

  • INVALID_TYPE = 4

  • NO_AUTHORITY = 5

  • UNKNOWN_ERROR = 6

  • HEADER_NOT_ALLOWED = 7

  • SEPARATOR_NOT_ALLOWED = 8

  • FILESIZE_NOT_ALLOWED = 9

  • HEADER_TOO_LONG = 10

  • DP_ERROR_CREATE = 11

  • DP_ERROR_SEND = 12

  • DP_ERROR_WRITE = 13

  • UNKNOWN_DP_ERROR = 14

  • ACCESS_DENIED = 15

  • DP_OUT_OF_MEMORY = 16

  • DISK_FULL = 17

  • DP_TIMEOUT = 18

  • FILE_NOT_FOUND = 19

  • DATAPROVIDER_EXCEPTION = 20

  • CONTROL_FLUSH_ERROR = 21

  • OTHERS = 22

.

IF sy-subrc <> 0.

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

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

ENDIF.

&----


*& Form dynpro

&----


*

FORM BDC_DYNPRO USING P_P1

P_P2.

CLEAR BDCTAB.

BDCTAB-PROGRAM = P_P1.

BDCTAB-DYNPRO = P_P2.

BDCTAB-DYNBEGIN = 'X'.

APPEND BDCTAB.

ENDFORM. " dynpro

&----


*& Form bdc_field

&----


FORM BDC_FIELD USING P_P3

P_P4.

CLEAR BDCTAB.

BDCTAB-FNAM = P_P3.

BDCTAB-FVAL = P_P4.

APPEND BDCTAB.

ENDFORM. " bdc_field

Read only

0 Likes
631

hi sudha rani,

i got a best answer but how to display that error records to frontend user in both methods

Read only

Former Member
0 Likes
631

Hi,

For session Method , u have to use SM35 & check for the LOG ... as per my knowledge , u cant diaplay in the output for the front user.

For Call transaction method, in the above program, u have got all the error records in the error table it_error. so put a loop on that internal table & use WRITE statement , ur error records will be displayed.

Reward Points if it is Useful.

Thanks,

Manjunath MS