Application Development 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: 

How to perform Error Handling in this Bdc Code

Former Member
0 Kudos

Hi,

I had created this BDC for the tcode MB1B and i want to know how to perform the ERROR HANDLING in it ..

Plzz provide me guidelines for doing it . here's d code:-

report ZBDC_MB1B

no standard page heading line-size 255.

include bdcrecx1.

data: begin of record OCCURS 0,

WERKS_001(004), "Plant

MATNR_002(018), "ItemId

ERFMG_003(013), "Quantity in Unit of Entry

ERFME_004(003), "Unit of Entry

LGORT_005(004), "Storage Location

CHARG_006(010), "BatchId

KDAUF_007(010), "Sales Order Number

KDPOS_008(006), "Item Number in Sales Order

end of record.

PARAMETERS : P_FILNAM LIKE RLGRAP-FILENAME.

initialization.

CTUMODE = 'A'.

CUPDATE = 'A'.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILNAM.

CALL FUNCTION 'WS_FILENAME_GET'

EXPORTING

MASK = ',. '

MODE = 'O'

IMPORTING

FILENAME = P_FILNAM

EXCEPTIONS

INV_WINSYS = 1

NO_BATCH = 2

SELECTION_CANCEL = 3

SELECTION_ERROR = 4

OTHERS = 5

.

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.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

FILENAME = P_FILNAM

FILETYPE = 'DAT'

TABLES

DATA_TAB = RECORD

EXCEPTIONS

CONVERSION_ERROR = 1

FILE_OPEN_ERROR = 2

FILE_READ_ERROR = 3

INVALID_TYPE = 4

NO_BATCH = 5

UNKNOWN_ERROR = 6

INVALID_TABLE_WIDTH = 7

GUI_REFUSE_FILETRANSFER = 8

CUSTOMER_ERROR = 9

NO_AUTHORITY = 10

OTHERS = 11

.

IF SY-SUBRC <> 0.

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

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

ENDIF.

LOOP AT RECORD.

*********************************************************

  • BEGIN OF SCREEN 1

*********************************************************

perform bdc_dynpro using 'SAPMM07M' '0400'.

perform bdc_field using 'BDC_CURSOR'

'RM07M-SOBKZ'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

*perform bdc_field using 'MKPF-BLDAT'

  • '22.12.2008'.

*perform bdc_field using 'MKPF-BUDAT'

  • '22.12.2008'.

perform bdc_field using 'RM07M-BWARTWA'

'411'.

perform bdc_field using 'RM07M-SOBKZ'

'E'.

perform bdc_field using 'RM07M-WERKS'

RECORD-WERKS_001. "Plant

perform bdc_field using 'XFULL'

'X'.

perform bdc_field using 'RM07M-WVERS2'

'X'.

*********************************************************

  • BEGIN OF SCREEN 2

*********************************************************

perform bdc_dynpro using 'SAPMM07M' '0421'.

perform bdc_field using 'BDC_CURSOR'

'MSEG-CHARG(01)'.

perform bdc_field using 'BDC_OKCODE'

'/00'.

perform bdc_field using 'MSEG-MATNR(01)'

RECORD-MATNR_002. "ITEMID

perform bdc_field using 'MSEG-ERFMG(01)'

RECORD-ERFMG_003. "QTY.

perform bdc_field using 'MSEG-ERFME(01)'

RECORD-ERFME_004. "UOM

perform bdc_field using 'MSEG-LGORT(01)'

RECORD-LGORT_005. "ST.LOC

perform bdc_field using 'MSEG-CHARG(01)'

RECORD-CHARG_006. "BATCHID

perform bdc_field using 'MSEGK-MAT_KDAUF'

RECORD-KDAUF_007. "S.O.

perform bdc_field using 'MSEGK-MAT_KDPOS'

RECORD-KDPOS_008. "S.O.LINE ITEM

perform bdc_field using 'DKACB-FMORE'

'X'.

*********************************************************

  • BEGIN OF SCREEN 3

*********************************************************

perform bdc_dynpro using 'SAPLKACB' '0002'.

perform bdc_field using 'BDC_OKCODE'

'=ENTE'.

perform bdc_field using 'DKACB-FMORE'

'X'.

perform bdc_dynpro using 'SAPLKACB' '0002'.

perform bdc_field using 'BDC_OKCODE'

'=ENTE'.

perform bdc_dynpro using 'SAPMM07M' '0421'.

perform bdc_field using 'BDC_CURSOR'

'MSEG-ERFMG(01)'.

perform bdc_field using 'BDC_OKCODE'

'=BU'.

perform bdc_field using 'DKACB-FMORE'

'X'.

*********************************************************

  • BEGIN OF SCREEN 4

*********************************************************

perform bdc_dynpro using 'SAPLKACB' '0002'.

perform bdc_field using 'BDC_OKCODE'

'=ENTE'.

perform bdc_transaction using 'MB1B'.

ENDLOOP.

11 REPLIES 11

Former Member
0 Kudos

Hi Ricx,

Error handling in BDC is done using the internal table of type BDCMSGCOLL.

Declare an internal table of type BDCMSGCOLL. After the CALL TRANSACTION. If Sy-Subrc NE 0, then move that record to the BDCMSGCOLL type internal table. Looping through that internal table, Write the error messages on to the screen. Correct those errors and run the BDC again.

Response is appreciated.

Regards

Sravan

0 Kudos

hi,

i had made some error handling in the code and when ever some data is wrong or not uploaded it is displyed after executing the BDC . here's d code:-

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

FILENAME = P_FILNAM

FILETYPE = 'DAT'

TABLES

DATA_TAB = RECORD

EXCEPTIONS

CONVERSION_ERROR = 1

FILE_OPEN_ERROR = 2

FILE_READ_ERROR = 3

INVALID_TYPE = 4

NO_BATCH = 5

UNKNOWN_ERROR = 6

INVALID_TABLE_WIDTH = 7

GUI_REFUSE_FILETRANSFER = 8

CUSTOMER_ERROR = 9

NO_AUTHORITY = 10

OTHERS = 11

it shows the data in it , plzz provide me guidelines for it......

former_member181995
Active Contributor
0 Kudos

Since it is Session method You should get messages in Log file of session method.Otherwise you can handle with MESSTAB

0 Kudos

ih,

it is the call tranasaction method i am using it and i am handling the error in the above code. i want to know is that right way also? bcoz it generates the data that these are the fields whic are uploaded and the errors occured while uploading it.

0 Kudos

I cannot see where you handled the messages?

CALL TRANSACTION 'J1ID' USING bdcdata MESSAGES INTO messtab.

CALL FUNCTION 'FORMAT_MESSAGE'

0 Kudos

Hello Ricx,

In the code you have posted, you did not mention you are using CALL TRANSACTION method. In CALL TRANSACTION method you need to handle the error cases explicitly.

Here's how to handle the errors:


DATA : 
L_IT_MSG TYPE STANDARD TABLE OF BDCMSGCOLL,
L_WA_MSG    TYPE BDCMSGCOLL,
L_ST_OPT    TYPE CTU_PARAMS.

L_ST_OPT-DISMODE = 'N'. "No Screen Display
L_ST_OPT-UPDMODE = 'S'. "Synchronous Update

* Post the VAT Protocols using FB41 transaction
 CALL TRANSACTION 'MB1B' 
 USING L_IT_BDC
 OPTIONS  FROM L_ST_OPT
 MESSAGES INTO L_IT_MSG.

LOOP AT L_IT_MSG INTO L_WA_MSG.
* Get the Message Text
  CALL FUNCTION 'FORMAT_MESSAGE'
  EXPORTING
  ID        = L_WA_MSG-MSGID
  LANG      = SY-LANGU
  NO        = L_WA_MSG-MSGNR
  V1        = L_WA_MSG-MSGV1
  V2        = L_WA_MSG-MSGV2
  V3        = L_WA_MSG-MSGV3
  V4        = L_WA_MSG-MSGV4
  IMPORTING
  MSG       = L_V_MSGTX " --> Contains the message text
  EXCEPTIONS
  NOT_FOUND = 1
  OTHERS    = 2.
ENDLOOP.

You can use this message text & display it in a log.

BR,

Suhas

Edited by: Suhas Saha on Dec 24, 2008 7:15 AM

Former Member
0 Kudos

Hi,

in u r code u r not mention which method u r choosing,and there is no call transaction syntax also .

syntax :calltransaction 'tcode' using BDCDATA

MODE 'A'

update 'A/s'

messages into bdcmsgcoll.

after the if sy-subrc = 0.

successfully upload the record if not then call the FM 'FORMATE_MESSAGE' and decleared the internal table like BDCMSGCALL error records are passed to that internal table.

then check u r flate file it is in proper order r not,some times its getting with problem with file is not uploaded successfully and internal table declearations.

regards,

madhu

Former Member
0 Kudos

hi,

check this code in bold letters.

INCLUDE BDCRECX1.

TABLES : MARC.

TYPES : BEGIN OF TY_UPLOAD,

MATNR TYPE MARA-MATNR,

WERKS TYPE MARC-WERKS,

STEUC TYPE MARC-STEUC,

END OF TY_UPLOAD.

TYPES : BEGIN OF TY_MARC,

MATNR TYPE MARA-MATNR,

WERKS TYPE MARC-WERKS,

END OF TY_MARC.

TYPES : BEGIN OF TY_MTART,

MATNR TYPE MARA-MATNR,

MTART TYPE MARA-MTART,

END OF TY_MTART.

DATA : T_MARC TYPE STANDARD TABLE OF TY_MARC,

: T_UPLOAD TYPE STANDARD TABLE OF TY_UPLOAD,

: T_BASIC TYPE STANDARD TABLE OF TY_UPLOAD,

: T_SALES TYPE STANDARD TABLE OF TY_UPLOAD,

: T_ERROR TYPE STANDARD TABLE OF TY_UPLOAD.

DATA : IT_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE,

IT_BDCDATA_VIEW LIKE BDCDATA OCCURS 0 WITH HEADER LINE,

IT_DATA(3200) OCCURS 0 WITH HEADER LINE,

IT_FIELD(3200) OCCURS 0 WITH HEADER LINE,

IT_BDCMSG TYPE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

DATA GI_MSG LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

DATA : CHAR1(500),

CHAR2(500),

CHAR3 TYPE STRING,

V_SELECTION TYPE STRING. " For View Selection

DATA : W_MARC TYPE TY_MARC,

WA_UPLOAD TYPE TY_UPLOAD,

WA_BASIC TYPE TY_UPLOAD,

WA_SALES TYPE TY_UPLOAD,

WA_ERROR TYPE TY_UPLOAD,

WA_MTART TYPE TY_MTART.

DATA : VAR TYPE N,

VAR1 TYPE STRING.

SELECTION-SCREEN : BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001. "SELECTION SCREEN

PARAMETERS: P_FNAM LIKE RLGRAP-FILENAME.

PARAMETERS: P_BAS LIKE RLGRAP-FILENAME.

PARAMETERS: P_SAL LIKE RLGRAP-FILENAME.

PARAMETERS: P_ERR LIKE RLGRAP-FILENAME.

SELECTION-SCREEN : END OF BLOCK B1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FNAM.

PERFORM SEARCH USING P_FNAM.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_BAS.

PERFORM SEARCH USING P_BAS.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_SAL.

PERFORM SEARCH USING P_SAL.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_ERR.

PERFORM SEARCH USING P_ERR.

&----


*& Form SEARCH

&----


  • text

----


  • -->PFNAME text

----


FORM SEARCH USING PFNAME.

CALL FUNCTION 'KD_GET_FILENAME_ON_F4'

EXPORTING

STATIC = 'X'

CHANGING

FILE_NAME = PFNAME.

ENDFORM. "SEARCH

START-OF-SELECTION.

PERFORM UPLOAD_PROCESS USING P_FNAM.

PERFORM OPEN_GROUP.

PERFORM PROCESS.

PERFORM CLOSE_GROUP.

IF NOT T_BASIC[] IS INITIAL.

PERFORM DOWNLOAD TABLES T_BASIC[] USING P_BAS .

ENDIF.

IF NOT T_SALES[] IS INITIAL.

PERFORM DOWNLOAD TABLES T_SALES[] USING P_SAL .

ENDIF.

IF NOT T_ERROR[] IS INITIAL.

PERFORM DOWNLOAD TABLES T_ERROR[] USING P_ERR.

ENDIF.

&----


*& Form PROCESS

&----


  • text

----


FORM PROCESS.

LOOP AT T_UPLOAD INTO WA_UPLOAD.

PERFORM CONV_ROUTINE USING WA_UPLOAD-MATNR

CHANGING WA_UPLOAD-MATNR.

SELECT COUNT(*) FROM MARA WHERE MATNR = WA_UPLOAD-MATNR.

IF SY-SUBRC NE 0.

MOVE-CORRESPONDING WA_UPLOAD TO WA_BASIC.

APPEND WA_BASIC TO T_BASIC.

CLEAR WA_BASIC.

CONTINUE.

ENDIF.

SELECT COUNT(*) FROM MARC WHERE MATNR = WA_UPLOAD-MATNR

AND WERKS = WA_UPLOAD-WERKS

AND PSTAT LIKE '%V%'.

IF SY-SUBRC NE 0.

MOVE-CORRESPONDING WA_UPLOAD TO WA_SALES.

APPEND WA_SALES TO T_SALES.

CLEAR WA_SALES.

CONTINUE.

ENDIF.

CLEAR : WA_MTART.

SELECT SINGLE MATNR MTART FROM MARA INTO WA_MTART WHERE MATNR = WA_UPLOAD-MATNR.

PERFORM BDC_DYNPRO USING 'SAPLMGMM' '0060'.

PERFORM BDC_FIELD USING 'BDC_CURSOR'

'RMMG1-MATNR'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'=AUSW'.

PERFORM BDC_FIELD USING 'RMMG1-MATNR'

WA_UPLOAD-MATNR.

CALL FUNCTION 'MATERIAL_BTCI_SELECTION_NEW' " Function module

EXPORTING

MATERIAL = WA_UPLOAD-MATNR " Material number

MATERIALART = WA_MTART-MTART " Material Type

SELECTION = 'V' "

TCODE = 'MM02' " Tcode where view's are called.

TABLES

BTCI_D0070 = IT_BDCDATA_VIEW

EXCEPTIONS

MATERIAL_NOT_FOUND = 1

MATERIAL_NUMBER_MISSING = 2

MATERIAL_TYPE_MISSING = 3

MATERIAL_TYPE_NOT_FOUND = 4

NO_ACTIVE_DYNPRO_SELECTED = 5

NO_AUTHORITY = 6

OTHERS = 7.

READ TABLE IT_BDCDATA_VIEW WITH KEY FVAL = 'X'.

IF SY-SUBRC = 0.

V_SELECTION = IT_BDCDATA_VIEW-FNAM.

ELSE.

CONTINUE.

ENDIF.

VAR = IT_BDCDATA_VIEW-FNAM+17(2).

VAR = VAR + 3.

CONCATENATE 'MSICHTAUSW-KZSEL(' '0' VAR ')' INTO VAR1.

PERFORM BDC_DYNPRO USING 'SAPLMGMM' '0070'.

PERFORM BDC_FIELD USING 'BDC_CURSOR'

'MSICHTAUSW-DYTXT(06)'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'=ENTR'.

PERFORM BDC_FIELD USING VAR1

'X'.

CLEAR VAR.

CLEAR VAR1.

  • PERFORM BDC_FIELD USING 'MSICHTAUSW-KZSEL(06)'

  • 'X'.

PERFORM BDC_DYNPRO USING 'SAPLMGMM' '0080'.

PERFORM BDC_FIELD USING 'BDC_CURSOR'

'RMMG1-VKORG'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'=ENTR'.

PERFORM BDC_FIELD USING 'RMMG1-WERKS'

WA_UPLOAD-WERKS.

PERFORM BDC_DYNPRO USING 'SAPLMGMM' '4004'.

PERFORM BDC_FIELD USING 'BDC_OKCODE'

'=BU'.

  • PERFORM BDC_FIELD USING 'MAKT-MAKTX'

  • 'MTI_ESE_HALB_01'.

PERFORM BDC_FIELD USING 'MARC-STEUC'

WA_UPLOAD-STEUC.

PERFORM BDC_FIELD USING 'BDC_CURSOR'

'MARC-HERKR'.

PERFORM BDC_FIELD USING 'MARC-HERKL'

'IN'.

PERFORM BDC_FIELD USING 'MARC-HERKR'

'MAH'.

PERFORM BDC_TRANSACTION USING 'MM02'.

    • move the error record into seperate internal table nad down load it ****

IF MESSTAB-MSGTYP = 'E'.

MOVE-CORRESPONDING WA_UPLOAD TO WA_ERROR.

APPEND WA_ERROR TO T_ERROR.

CLEAR WA_ERROR.

ENDIF.

ENDLOOP.

ENDFORM. "PROCESS

&----


*& Form UPLOAD_PROCESS

&----


  • text

----


  • -->PFNAME text

----


FORM UPLOAD_PROCESS USING PFNAME.

DATA : PFNAME1 TYPE STRING.

PFNAME1 = PFNAME.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = PFNAME1

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

TABLES

DATA_TAB = T_UPLOAD[].

IF SY-SUBRC <> 0.

ENDIF.

ENDFORM. "UPLOAD_PROCESS

&----


*& Form CONV_ROUTINE

&----


  • text

----


  • -->P_INPUT text

  • -->P_OUTPUT text

----


FORM CONV_ROUTINE USING P_INPUT

CHANGING P_OUTPUT.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

INPUT = P_INPUT

IMPORTING

OUTPUT = P_OUTPUT.

ENDFORM. "CONV_ROUTINE

&----


*& Form DOWNLOAD

&----


  • text

----


  • -->GI_FINAL text

  • -->PFNAME text

----


FORM DOWNLOAD TABLES

GI_FINAL

USING PFNAME .

DATA : FNAME TYPE STRING.

FNAME = PFNAME.

CALL FUNCTION 'GUI_DOWNLOAD'

EXPORTING

FILENAME = FNAME

FILETYPE = 'DAT'

WRITE_FIELD_SEPARATOR = 'x'

  • HEADER = '00'

  • IMPORTING

  • FILELENGTH =

TABLES

DATA_TAB = GI_FINAL[]

  • FIELDNAMES = GI_FIELDNAMES[]

.

IF SY-SUBRC = 0.

MESSAGE 'FILE DOWNLOADED SUCCESSFULLY' TYPE 'I'.

ENDIF.

ENDFORM. " DOWNLOAD

Regards

Siva Prasad

Former Member
0 Kudos

Hi Ricx,

Fro errors handled in BDC using internal table of type BDCMSGCOLL. Here use GUI_DOWNLOAD function module you can download all error records into excel file or txt file.

If you use session, There log file will genarate. You can check there.

Regards

Md.MahaboobKhan

Former Member
0 Kudos

Error handling in BDC is done using the internal table of type BDCMSGCOLL.

Yoy have not declared an internal table of type BDCMSGCOLL in your program..

After the CALL TRANSACTION check Sy-Subrc NE 0, then move that record to the BDCMSGCOLL type internal table.

Looping through that internal table, Write the error messages on to the screen. Correct those errors and run the

BDC again.

syntx:

call transaction 'MB1B' using BDCDATA

mode 'A'

update 'S'

message into BDCMSGCOLL.

LOOP AT L_IT_MSG INTO L_WA_MSG.

  • Get the Message Text

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = L_WA_MSG-MSGID

LANG = SY-LANGU

NO = L_WA_MSG-MSGNR

V1 = L_WA_MSG-MSGV1

V2 = L_WA_MSG-MSGV2

V3 = L_WA_MSG-MSGV3

V4 = L_WA_MSG-MSGV4

IMPORTING

MSG = L_V_MSGTX " --> Contains the message text

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2.

ENDLOOP.

Former Member
0 Kudos

Hi,

your uploading the data using call transaction method, then define internal table of type BDCMSGCOLL

after CALL TRANSACTION <transaction name>, if sy-subrc NE 0 then move the error records to the internal table of type BDCMSGCOLL

while looping that internal table write the related error messages to the screen, recorrect those errors and execute BDC again.