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
910

Hi gems,

how to find error records and how to upload it to a flat file?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
884

You have to use BDCMSGCALL structure for error.

data:msgtab type bdcmsgcall occurs 0 with header line.

call transaction 'MM01' using bdcdata mode 'A' update 'A'

messages into msgtab.

loop at msgtab.

write:/ msgtab-msgid,msgtab-msgtype.

endloop.

Thanks

Ankur Sharma

11 REPLIES 11
Read only

Former Member
0 Likes
885

You have to use BDCMSGCALL structure for error.

data:msgtab type bdcmsgcall occurs 0 with header line.

call transaction 'MM01' using bdcdata mode 'A' update 'A'

messages into msgtab.

loop at msgtab.

write:/ msgtab-msgid,msgtab-msgtype.

endloop.

Thanks

Ankur Sharma

Read only

0 Likes
884

can u just give me some real time example with coding?

Read only

0 Likes
884

hi,

check this sample BDC program for fk01.

&----


*& Report ZFK01_CALLTRANSACTION *

*& *

&----


*& *

*& *

&----


REPORT ZGM_FK01_CALLTRANSACTION no standard page heading line-size 255.

data: it_bdcdata type standard table of bdcdata with header line,

it_msg type standard table of bdcmsgcoll with header line.

data: begin of it_fk01 occurs 0,

bukrs(4) type c,

ktokk(4) type c,

name1(40) type c,

sortl(40) type c,

land1(2) type c,

spras(2) type c,

end of it_fk01.

DATA : W_FILE TYPE STRING.

SELECTION-SCREEN BEGIN OF BLOCK 1 WITH FRAME TITLE TEXT-001.

PARAMETERs : filename LIKE RLGRAP-FILENAME.

SELECTION-SCREEN END OF BLOCK 1.

      • ACCEPTING THE FILE FROM USER **************

AT SELECTION-SCREEN ON VALUE-REQUEST FOR filename.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = SYST-CPROG

DYNPRO_NUMBER = SYST-DYNNR

FIELD_NAME = ' '

IMPORTING

FILE_NAME = filename.

.

START-OF-SELECTION.

************UPLOADING THE FILE *****************************

START-OF-SELECTION.

W_FILE = filename.

*CALLING THE FUNC GUI_UPLAOD TO COPY THE DATA FROM FLAT FILE TO

  • INTERNAL TABLE

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = W_FILE

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

tables

data_tab = it_fk01.

IF sy-subrc <> 0.

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

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

ENDIF.

                                          • Creation the Fill_Data ****************

loop at it_fk01.

refresh it_bdcdata.

clear it_bdcdata.

*call transaction 'PA40' using it_bdcdata mode 'A' messages into it_msg

.

                            • Inserting the Data from Bdc_data File******************

perform bdc_dynpro using 'SAPMF02K' '0105'.

perform bdc_field using 'BDC_CURSOR'

'RF02K-KTOKK'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'RF02K-BUKRS'

it_fk01-bukrs.

perform bdc_field using 'RF02K-KTOKK'

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

it_fk01-name1.

perform bdc_field using 'LFA1-SORTL'

it_fk01-sortl.

perform bdc_field using 'LFA1-LAND1'

it_fk01-land1.

perform bdc_field using 'LFA1-SPRAS'

it_fk01-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 'SAPMF02K' '0210'.

perform bdc_field using 'BDC_CURSOR'

'LFB1-AKONT'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_dynpro using 'SAPMF02K' '0215'.

perform bdc_field using 'BDC_CURSOR'

'LFB1-ZTERM'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_dynpro using 'SAPMF02K' '0220'.

perform bdc_field using 'BDC_CURSOR'

'LFB5-MAHNA'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_dynpro using 'SAPMF02K' '0610'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'BDC_CURSOR'

'LFB1-QLAND'.

call transaction 'FK01' using it_bdcdata mode 'A' messages into it_msg.

endloop.

----


  • Start new screen *

----


FORM BDC_DYNPRO USING PROGRAM DYNPRO.

CLEAR it_bdcdata.

it_bdcdata-PROGRAM = PROGRAM.

it_bdcdata-DYNPRO = DYNPRO.

it_bdcdata-DYNBEGIN = 'X'.

APPEND it_bdcdata.

ENDFORM.

----


  • Insert field *

----


FORM BDC_FIELD USING FNAM FVAL.

  • IF FVAL <> NODATA.

CLEAR it_bdcdata.

it_bdcdata-FNAM = FNAM.

it_bdcdata-FVAL = FVAL.

APPEND it_bdcdata.

  • ENDIF.

ENDFORM.

dont forget to reward points if hlpful.

Read only

Former Member
0 Likes
884

Hi razak,

In CALL TRANSACTION method we use BDCMSGCOLL structure u capture error records

Error handling when submission via CALL TRANSACTION fails ,either by using the internal table to be filled by the system messages which is of TYPE BDCMSGCOLS and can be specified in CALL TRANSACTION statement with the addition MESSAGES INTO .

Or error handling by sending the mail to a predefined recipient.

Or for each and every transaction that fails create a

single BDC SESSION by using BDC_OPEN_GROUP function module

and submitting the intenal bdc data table to it.

For each and every error a report should display them

all at the end of the program so that the transacton in error can be identified.

The approach of opening a BDC SESSION is often used with an error report when an error occurs as all the transaction in error can be seen and executed in the session manager

REPORT Y730_BDC5 .
*HANDLING TABLE CONTROL IN BDC
DATA : BEGIN OF IT_DUMMY OCCURS 0,
       DUMMY(100) TYPE C,
       END OF IT_DUMMY.
DATA : BEGIN OF IT_XK01 OCCURS 0,
       LIFNR(10) TYPE C,
       BUKRS(4)  TYPE C,
       EKORG(4)  TYPE C,
       KTOKK(4)  TYPE C,
       NAME1(30) TYPE C,
       SORTL(10) TYPE C,
       LAND1(3)  TYPE C,
       SPRAS(2)  TYPE C,
       AKONT(6)  TYPE C,
       FDGRV(2)  TYPE C,
       WAERS(3)  TYPE C,
       END OF IT_XK01,
       BEGIN OF IT_BANK OCCURS 0,
       BANKS(3)  TYPE C,
       BANKL(10) TYPE C,
       BANKN(10) TYPE C,
       KOINH(30) TYPE C,
       LIFNR(10) TYPE C,
       END OF IT_BANK.
DATA : IT_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE,
       IT_BDCMSGCOLL LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

CALL FUNCTION 'WS_UPLOAD'
 EXPORTING
   FILENAME                      = 'C:\VENDOR.TXT'
   FILETYPE                      = 'ASC'
 TABLES
   DATA_TAB                      = IT_DUMMY.

LOOP AT IT_DUMMY.
  IF IT_DUMMY-DUMMY+0(2) = '11'.
    IT_XK01-LIFNR = IT_DUMMY-DUMMY+2(10).
    IT_XK01-BUKRS = IT_DUMMY-DUMMY+12(4).
    IT_XK01-EKORG = IT_DUMMY-DUMMY+16(4).
    IT_XK01-KTOKK = IT_DUMMY-DUMMY+20(4).
    IT_XK01-NAME1 = IT_DUMMY-DUMMY+24(30).
    IT_XK01-SORTL = IT_DUMMY-DUMMY+54(10).
    IT_XK01-LAND1 = IT_DUMMY-DUMMY+64(3).
    IT_XK01-SPRAS = IT_DUMMY-DUMMY+67(2).
    IT_XK01-AKONT = IT_DUMMY-DUMMY+69(6).
    IT_XK01-FDGRV = IT_DUMMY-DUMMY+75(2).
    IT_XK01-WAERS = IT_DUMMY-DUMMY+77(3).
    APPEND IT_XK01.
  ELSE.
    IT_BANK-BANKS = IT_DUMMY-DUMMY+2(3).
    IT_BANK-BANKL = IT_DUMMY-DUMMY+5(10).
    IT_BANK-BANKN = IT_DUMMY-DUMMY+15(10).
    IT_BANK-KOINH = IT_DUMMY-DUMMY+25(30).
    IT_BANK-LIFNR = IT_DUMMY-DUMMY+55(10).
    APPEND IT_BANK.
  ENDIF.
ENDLOOP.

LOOP AT IT_XK01.
REFRESH IT_BDCDATA.
perform bdc_dynpro      using 'SAPMF02K' '0100'.
perform bdc_field       using 'BDC_CURSOR'
                              'RF02K-REF_LIFNR'.
perform bdc_field       using 'BDC_OKCODE'
                              '/00'.
perform bdc_field       using 'RF02K-LIFNR'
                              IT_XK01-LIFNR.
perform bdc_field       using 'RF02K-BUKRS'
                              IT_XK01-BUKRS.
perform bdc_field       using 'RF02K-EKORG'
                              IT_XK01-EKORG.
perform bdc_field       using 'RF02K-KTOKK'
                              IT_XK01-KTOKK.
perform bdc_dynpro      using 'SAPMF02K' '0110'.
perform bdc_field       using 'BDC_CURSOR'
                              'LFA1-TELX1'.
perform bdc_field       using 'BDC_OKCODE'
                              '/00'.
perform bdc_field       using 'LFA1-NAME1'
                              IT_XK01-NAME1.
perform bdc_field       using 'LFA1-SORTL'
                              IT_XK01-SORTL.
perform bdc_field       using 'LFA1-LAND1'
                              IT_XK01-LAND1.
perform bdc_field       using 'LFA1-SPRAS'
                              IT_XK01-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-KOINH(02)'.
perform bdc_field       using 'BDC_OKCODE'
                              '=ENTR'.
DATA : FNAM(20) TYPE C,
       IDX      TYPE C.
  MOVE 1 TO IDX.
LOOP AT IT_BANK WHERE LIFNR = IT_XK01-LIFNR.
  CONCATENATE 'LFBK-BANKS(' IDX ')' INTO FNAM.
  perform bdc_field       using FNAM
                                IT_BANK-BANKS.

  CONCATENATE 'LFBK-BANKL(' IDX ')' INTO FNAM.
  perform bdc_field       using FNAM
                                IT_BANK-BANKL.

  CONCATENATE 'LFBK-BANKN(' IDX ')' INTO FNAM.
  perform bdc_field       using FNAM
                                IT_BANK-BANKN.

  CONCATENATE 'LFBK-KOINH(' IDX ')' INTO FNAM.
  perform bdc_field       using FNAM
                                IT_BANK-KOINH.
  IDX = IDX + 1.
ENDLOOP.

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 'SAPMF02K' '0210'.
perform bdc_field       using 'BDC_CURSOR'
                              'LFB1-FDGRV'.
perform bdc_field       using 'BDC_OKCODE'
                              '/00'.
perform bdc_field       using 'LFB1-AKONT'
                              IT_XK01-AKONT.
perform bdc_field       using 'LFB1-FDGRV'
                              IT_XK01-FDGRV.
perform bdc_dynpro      using 'SAPMF02K' '0215'.
perform bdc_field       using 'BDC_CURSOR'
                              'LFB1-ZTERM'.
perform bdc_field       using 'BDC_OKCODE'
                              '/00'.
perform bdc_dynpro      using 'SAPMF02K' '0220'.
perform bdc_field       using 'BDC_CURSOR'
                              'LFB5-MAHNA'.
perform bdc_field       using 'BDC_OKCODE'
                              '/00'.
perform bdc_dynpro      using 'SAPMF02K' '0310'.
perform bdc_field       using 'BDC_CURSOR'
                              'LFM1-WAERS'.
perform bdc_field       using 'BDC_OKCODE'
                              '/00'.
perform bdc_field       using 'LFM1-WAERS'
                              IT_XK01-WAERS.
perform bdc_dynpro      using 'SAPMF02K' '0320'.
perform bdc_field       using 'BDC_CURSOR'
                              'WYT3-PARVW(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 IT_BDCDATA
                        MODE  'A'
                       UPDATE 'S'
                     MESSAGES INTO IT_BDCMSGCOLL.
ENDLOOP.

FORM BDC_DYNPRO USING PROG SCR.
  CLEAR IT_BDCDATA.
  IT_BDCDATA-PROGRAM = PROG.
  IT_BDCDATA-DYNPRO  = SCR.
  IT_BDCDATA-DYNBEGIN = 'X'.
  APPEND IT_BDCDATA.
ENDFORM.

FORM BDC_FIELD USING FNAM FVAL.
  CLEAR IT_BDCDATA.
  IT_BDCDATA-FNAM = FNAM.
  IT_BDCDATA-FVAL  = FVAL.
  APPEND IT_BDCDATA.
ENDFORM.

Best regards,

raam

Read only

GauthamV
Active Contributor
0 Likes
884

hi razak,

welcome to SDN.

u can get error records in a seperate session in sm35 if u r using session method.

u can capture error records in ur program using bdcmsgcoll structure if u r using call transaction method.

reward points if hlpful.

Read only

Former Member
0 Likes
884

Hello,

If there are only 10 records, you may process them manually. Please process the session (SM35) with Processing Mode 'Display Errors Only' and you can interactively correct the errors. If there are more error records, correct the input data/program and recreate the sessions.

capture error in call transaction -


>>>>>>

IN CALL TRANSACTION TO CAPTURE THE ERRORS WE SHOULD PERFORM THE FOLLOWING.

FIRST ME MUST DECLARE AN INTERNAL TABLE WITH THE STRUCTURE OF BDCMSGCOLL TABLE.

THEN WHILE WRITING THE CALL TRANSACTION STATEMENT WE SHOULD PUT THE 'E' MODE FOR CAPTURING ALL THE ERRORS.

THEN FINALLY THE CAPTURED ERRORS MUST TO SENT TO THE INTERNAL TABLE WHICH WE DECLARED IN THE BEGINNING WITH BDCMSGCOLL BY USING THE FUNCTION MODULE "FORMAT_MESSAGE"

AND THUS THE ERROR MESSAGES WILL BE SENT TO THE INTERNAL TABLE WHICH WE DECLARED AT THE BEGINNING

CALL TRANSACTION 'FK01' USING IT_BDCDATA MODE 'A'

UPDATE 'S'

MESSAGES INTO IT_MESSAGES.

WRITe:/ SY-SUBRC.

PERFORM FORMAT_MESSAGES.

CLEAR IT_BDCDATA.

REFRESH IT_BDCDATA.

form FORMAT_MESSAGES .

DATA: L_MSG(100).

LOOP AT IT_MESSAGES.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = IT_MESSAGES-MSGID

LANG = SY-LANGU

NO = IT_MESSAGES-MSGNR

V1 = IT_MESSAGES-MSGV1

V2 = IT_MESSAGES-MSGV2

V3 = IT_MESSAGES-MSGV3

V4 = IT_MESSAGES-MSGV4

IMPORTING

MSG = L_MSG

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2

.

write:/ l_msg.

endloop.

Reward the points.

Thanks,

Sridhar.

Read only

Former Member
0 Likes
884

you kan also use format_message function module for formatting error.

CALL TRANSACTION tcode USING lt_bdcdata

MODE 'E' MESSAGES INTO it_message.

LOOP AT it_message INTO message.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

id = message-msgid

lang = 'EN'

no = message-msgnr

v1 = message-msgv1

v2 = message-msgv2

v3 = message-msgv3

v4 = message-msgv4

IMPORTING

msg = msg

EXCEPTIONS

not_found = 1

OTHERS = 2.

IF sy-subrc EQ 0.

WRITE / msg.

ENDIF. " IF sy-subrc EQ 0.

ENDLOOP.

Rewards points if satisfied.

Thanks

Ankur Sharma

Read only

Former Member
0 Likes
884

capture error in call transaction -


>>>>>>

IN CALL TRANSACTION TO CAPTURE THE ERRORS WE SHOULD PERFORM THE FOLLOWING.

FIRST ME MUST DECLARE AN INTERNAL TABLE WITH THE STRUCTURE OF BDCMSGCOLL TABLE.

THEN WHILE WRITING THE CALL TRANSACTION STATEMENT WE SHOULD PUT THE 'E' MODE FOR CAPTURING ALL THE ERRORS.

THEN FINALLY THE CAPTURED ERRORS MUST TO SENT TO THE INTERNAL TABLE WHICH WE DECLARED IN THE BEGINNING WITH BDCMSGCOLL BY USING THE FUNCTION MODULE "FORMAT_MESSAGE"

AND THUS THE ERROR MESSAGES WILL BE SENT TO THE INTERNAL TABLE WHICH WE DECLARED AT THE BEGINNING

CALL TRANSACTION 'FK01' USING IT_BDCDATA MODE 'A'

UPDATE 'S'

MESSAGES INTO IT_MESSAGES.

WRITe:/ SY-SUBRC.

PERFORM FORMAT_MESSAGES.

CLEAR IT_BDCDATA.

REFRESH IT_BDCDATA.

form FORMAT_MESSAGES .

DATA: L_MSG(100).

LOOP AT IT_MESSAGES.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = IT_MESSAGES-MSGID

LANG = SY-LANGU

NO = IT_MESSAGES-MSGNR

V1 = IT_MESSAGES-MSGV1

V2 = IT_MESSAGES-MSGV2

V3 = IT_MESSAGES-MSGV3

V4 = IT_MESSAGES-MSGV4

IMPORTING

MSG = L_MSG

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2

.

write:/ l_msg.

endloop.

Read only

Former Member
0 Likes
884

Hi abdul..

after the transaction..use the fm..format message..which collects all the records..of success and error and download to a file

if needed.

please folow the code

loop at ....

  • Calling Transaction XK01

CALL TRANSACTION 'XK01' USING i_bdcdata

MODE 'N'

UPDATE 'S'

MESSAGES INTO i_bdcmsgcoll.

PERFORM populate_status_msg.

endloop.

----


  • DOWNLOAD OF STATUS OF RECORDS *

----


*

PERFORM download_status_file TABLES i_success i_success_vendor

USING v2_file.

PERFORM download_status_file TABLES i_error i_error_vendor

USING v3_file.

----


  • SUBROUTINES *

----


&----


*& Form DOWNLOAD_STAT_MSG

&----


*Routine for Downloadng Status of Records

FORM populate_status_msg.

SORT i_bdcmsgcoll BY msgtyp msgv1 DESCENDING.

READ TABLE i_bdcmsgcoll

INTO w_bdcmsgcoll

WITH KEY msgtyp = 'E'.

IF sy-subrc EQ 0.

*Function Module for Formatting the Messages

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

id = w_bdcmsgcoll-msgid

lang = '-D'

no = w_bdcmsgcoll-msgnr

v1 = w_bdcmsgcoll-msgv1

v2 = w_bdcmsgcoll-msgv2

v3 = w_bdcmsgcoll-msgv3

v4 = w_bdcmsgcoll-msgv4

IMPORTING

msg = v_msgstr

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.

  • Moving Error Records to Error Internal Table

w_error-errmsg1 = w_xk01.

w_error-errmsg2 = v_msgstr.

APPEND w_error TO i_error.

CLEAR w_error.

ENDIF.

READ TABLE i_bdcmsgcoll

INTO w_bdcmsgcoll

WITH KEY msgtyp = 'S'.

IF sy-subrc = 0.

  • Function Module for Formatting the Messages

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

id = w_bdcmsgcoll-msgid

lang = '-D'

no = w_bdcmsgcoll-msgnr

v1 = w_bdcmsgcoll-msgv1

v2 = w_bdcmsgcoll-msgv2

v3 = w_bdcmsgcoll-msgv3

v4 = w_bdcmsgcoll-msgv4

IMPORTING

msg = v_msgstr

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.

  • Moving Success Records to Success Internal Table

w_success-legven = w_xk01-lifnr.

w_success-sapven = w_bdcmsgcoll-msgv1.

APPEND w_success TO i_success.

CLEAR w_success.

ENDIF.

REFRESH i_bdcmsgcoll.

ENDFORM. "DOWNLOAD_STAT_MSG

*

&----


*& Form download_status_file

&----


FORM download_status_file TABLES table1 table2 USING filename TYPE any.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

filename = filename

filetype = 'ASC'

TABLES

data_tab = table1

fieldnames = table2.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

ENDFORM. "download_status_file

reward all helpful answers

regards,

sampath

Read only

Former Member
0 Likes
884

if you need whoe code give me ur id will send u code.

or send me test mai! at ankur_sharmain20 at yahoocom

Thanks

Read only

Former Member
0 Likes
884

Excellents answeres with suitable examples to my question