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

regarding the bdc

Former Member
0 Likes
533

hi,

how to maintain the error log in bdc for the call transaction method.

thanks in advance

4 REPLIES 4
Read only

Former Member
0 Likes
516

Refer to these related threads

Read only

Former Member
0 Likes
516

In call transaction method use the attribute "messages into it_bdcmsgcoll" after Call Transaction, where it_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 :Write_Message which combines all messages into one field(MESSAGE-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 Write_Message

Endloop.

Please reward points if useful

Arjun

Read only

Former Member
0 Likes
516

Hi

In call transaction we can explicitly provide the logic for handling error records, for that one we create internal table of type BDCMSGCOLL.

syntax:

DATA: IT_ERROR LIKE BDCMSGCOLL WITH HEADER LINE.

CALL TRANSACTION <transaction-name> using BDCDATA

mode <A/N/E>

update <A/S/L>

MESSAGES INTO IT_ERROR.

We can create a internal table like 'bsgmcgcoll'. All themessages will go to ternal table. We can get errors inthis internal table.

Below messages are go to internal table. when you run the

call transaction.

- Message type

- Message id

- Message Number

- Variable1

- Variable2

- Variable3

by using FORMAT_MESSAGES function module we can process the error records.

or

by using session method also we can handle error records in

CALL TRANSACTION method.

CALL TRANSACTION <transaction-name> using BDCDATA

mode <A/N/E>

update <A/S/L>.

IF SY-SUBRC <> 0.

here call BDC_OPEN_GROUP for creating session.

here call BDC_INSERT for adding trassaction and table BDCDATA to handling error records.

here call BDC_CLOSE_GROUP for closing the session.

now all the error records available in logfile, for handling error records follow these steps.

1) goto SM35.

2) here select your SESSION name.

3) and choose LOG tab

4) press the selected LOG tab, then it will display error records.

Hope this helpful.

****Reward points if helpful.

All the best

Read only

Former Member
0 Likes
516

Hi

See the sample program in which the errors are handled using the fun module FORMAT_MESSAGE

REPORT ZMMBDC1_1 NO STANDARD PAGE HEADING MESSAGE-ID ZT.

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

  • Declaration of internal tables

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

  • internal table for selecting data from flat file

DATA : BEGIN OF IT_DATA OCCURS 0,

MBRSH, " Industry sector

MTART(4), " Material type

KZSEL, " Checkbox

MAKTX(40), " Material description

MEINS(3), " Base unit of measure

MATKL(9), " Material group

BISMT(18), " Old material number

END OF IT_DATA.

  • internal table for bdcdata

DATA : IT_BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.

  • internal table to handle messages

DATA : IT_MESSAGES LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

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

  • Variables & Flag declaration

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

  • variables declaration

DATA : V_MESG(50).

  • flag declaration

DATA : FG_BDC,

FG_FLAG1 TYPE I.

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

  • selection screen

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

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

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

  • parameter

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

PARAMETERS : P_FILE LIKE RLGRAP-FILENAME OBLIGATORY.

SELECTION-SCREEN END OF BLOCK BLK1.

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

  • initialization

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

INITIALIZATION.

  • peform to initialize parameter

PERFORM INIT_PARM.

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

  • start of selection

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

start-of-selection.

  • perform to upload it_data

PERFORM UP_LOAD_IT_DATA.

  • perform transfer data

PERFORM TRANSFER_DATA.

  • end of selection

END-OF-SELECTION.

&----


*& Form INIT_PARM

&----


  • Initializing parameter

----


FORM INIT_PARM.

P_FILE = 'C:\'.

ENDFORM. " INIT_PARM

&----


*& Form UP_LOAD_IT_DATA

&----


  • Transfering data from file to internal table

----


FORM UP_LOAD_IT_DATA.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

FILENAME = P_FILE

FILETYPE = 'ASC'

TABLES

DATA_TAB = IT_DATA

EXCEPTIONS

CONVERSION_ERROR = 1

FILE_OPEN_ERROR = 2

FILE_READ_ERROR = 3

INVALID_TABLE_WIDTH = 4

INVALID_TYPE = 5

NO_BATCH = 6

UNKNOWN_ERROR = 7

GUI_REFUSE_FILETRANSFER = 8

OTHERS = 9.

IF SY-SUBRC = 2 .

FG_FLAG1 = 1.

MESSAGE I001.

ENDIF.

ENDFORM. " UP_LOAD_IT_DATA

&----


*& Form TRANSFER_DATA

&----


  • Processing the data

----


FORM TRANSFER_DATA.

FG_BDC = 'N'.

LOOP AT IT_DATA.

  • perform to fill it_bdcdata.

PERFORM FILL_IT_BDCDATA.

CALL TRANSACTION 'MM01' USING IT_BDCDATA MODE 'N' UPDATE 'S'

MESSAGES INTO IT_MESSAGES.

IF SY-SUBRC <> 0.

FG_FLAG1 = 1.

  • if error occurs in transaction mode run bdc session for that data

PERFORM BDC_PROCESS.

ENDIF.

  • Handles error messages

PERFORM ERROR_MESSAGES.

CLEAR : IT_BDCDATA,IT_DATA,IT_MESSAGES.

REFRESH : IT_BDCDATA,IT_MESSAGES.

ENDLOOP.

IF FG_FLAG1 = 0.

MESSAGE I003.

ENDIF.

IF FG_BDC = 'O'.

  • close bdc if it is open

PERFORM CLOSE_BDC.

ENDIF.

ENDFORM. " TRANSFER_DATA

&----


*& Form FILL_IT_BDCDATA

&----


  • Filling Bdcdata structure with it_data

  • Some fields have been commented for future updations

----


FORM FILL_IT_BDCDATA.

PERFORM BDC_DYNPRO USING : 'SAPLMGMM' '0060'.

PERFORM BDC_FIELD USING : 'BDC_OKCODE' '/00',

: 'BDC_CURSOR' 'RMMG1_REF-MATNR',

: 'RMMG1-MBRSH' IT_DATA-MBRSH,

: 'RMMG1-MTART' IT_DATA-MTART.

PERFORM BDC_DYNPRO USING : 'SAPLMGMM' '0070'.

PERFORM BDC_FIELD USING : 'BDC_OKCODE' '=RESA'.

PERFORM BDC_DYNPRO USING : 'SAPLMGMM' '0070'.

PERFORM BDC_FIELD USING : 'BDC_OKCODE' '=ENTR',

: 'MSICHTAUSW-KZSEL(01)' IT_DATA-KZSEL.

PERFORM BDC_DYNPRO USING : 'SAPLMGMM' '4000'.

PERFORM BDC_FIELD USING : 'BDC_OKCODE' '=BU',

: 'BDC_SUBSCR' 'SAPLMGMM' & ' 2000TABFRA1',

: 'BDC_SUBSCR' 'SAPLMGD1' & ' 1002SUB1',

: 'BDC_CURSOR' 'MAKT-MAKTX',

: 'MAKT-MAKTX' IT_DATA-MAKTX,

: 'BDC_SUBSCR' 'SAPLMGD1' & ' 2001SUB2',

: 'MARA-MEINS' IT_DATA-MEINS,

: 'MARA-MATKL' IT_DATA-MATKL,

: 'MARA-BISMT' IT_DATA-BISMT,

: 'BDC_OKCODE' '=BU'.

*perform bdc_field using 'MARA-EXTWG' ''.

*perform bdc_field using 'MARA-LABOR' ''.

*perform bdc_field using 'MARA-KOSCH' ''.

*perform bdc_field using 'MARA-MSTAE' ''.

*perform bdc_field using 'MARA-MSTDE' ''.

*perform bdc_field using 'BDC_SUBSCR' 'SAPLMGD1' & ' 2561SUB3'.

*perform bdc_field using 'MARA-BEGRU' ''.

*perform bdc_field using 'BDC_SUBSCR' 'SAPLMGD1' & ' 2007SUB4'.

*perform bdc_field using 'MARA-NTGEW' ''.

*perform bdc_field using 'MARA-BRGEW' ''.

*perform bdc_field using 'MARA-GEWEI' ''.

*perform bdc_field using 'MARA-VOLUM' ''.

*perform bdc_field using 'MARA-VOLEH' ''.

*PERFORM BDC_FIELD USING 'MARA-GROES' ''.

*perform bdc_field using 'MARA-EAN11' ''.

*perform bdc_field using 'MARA-NUMTP' ''.

*PERFORM BDC_FIELD USING 'BDC_SUBSCR' 'SAPLMGD1' & ' 2005SUB5'.

*perform bdc_field using 'BDC_SUBSCR' 'SAPLMGD1' & ' 2011SUB6'.

*perform bdc_field using 'MARA-MAGRV' ''.

ENDFORM. " FILL_IT_BDCDATA

&----


*& Form BDC_DYNPRO

&----


  • Filling the it_bdcdata table with program name & screen number

----


FORM BDC_DYNPRO USING PROGRAM LIKE BDCDATA-PROGRAM

DYNPRO LIKE BDCDATA-DYNPRO.

IT_BDCDATA-PROGRAM = PROGRAM.

IT_BDCDATA-DYNPRO = DYNPRO.

IT_BDCDATA-DYNBEGIN = 'X'.

APPEND IT_BDCDATA.

CLEAR IT_BDCDATA.

ENDFORM. " BDC_DYNPRO

&----


*& Form BDC_FIELD

&----


  • Filling it_bdcdata with field name and field value

----


FORM BDC_FIELD USING FNAM LIKE BDCDATA-FNAM

FVAL.

IT_BDCDATA-FNAM = FNAM.

IT_BDCDATA-FVAL = FVAL.

APPEND IT_BDCDATA.

CLEAR IT_BDCDATA.

ENDFORM. " BDC_FIELD

&----


<b>*& Form ERROR_MESSAGES

&----


  • Displaying error messages

----


FORM ERROR_MESSAGES.

CALL FUNCTION 'FORMAT_MESSAGE'

EXPORTING

ID = SY-MSGID

LANG = '-D'

IMPORTING

MSG = V_MESG

EXCEPTIONS

NOT_FOUND = 1

OTHERS = 2.

LOOP AT IT_MESSAGES WHERE MSGTYP = 'E'.

WRITE : / 'Message :'(I06) ,V_MESG.

CLEAR IT_MESSAGES.

ENDLOOP.

ENDFORM. " ERROR_MESSAGES</b>

&----


*& Form BDC_PROCESS

&----


  • Open bdc session if call transaction fails

----


FORM BDC_PROCESS.

IF FG_BDC = 'N'.

  • open bdc session

PERFORM OPEN_BDC.

FG_BDC = 'O'.

ENDIF.

IF FG_BDC = 'O'.

  • insert data into bdc session

PERFORM INSERT_BDC.

ENDIF.

ENDFORM. " BDC_PROCESS

&----


*& Form OPEN_BDC

&----


  • Calling function module to open bdc session

----


FORM OPEN_BDC.

CALL FUNCTION 'BDC_OPEN_GROUP'

EXPORTING

CLIENT = SY-MANDT

GROUP = 'SMM1'

KEEP = 'X'

USER = SY-UNAME

EXCEPTIONS

CLIENT_INVALID = 1

DESTINATION_INVALID = 2

GROUP_INVALID = 3

GROUP_IS_LOCKED = 4

HOLDDATE_INVALID = 5

INTERNAL_ERROR = 6

QUEUE_ERROR = 7

RUNNING = 8

SYSTEM_LOCK_ERROR = 9

USER_INVALID = 10

OTHERS = 11.

ENDFORM. " OPEN_BDC

&----


*& Form INSERT_BDC

&----


  • Insert it_bdcdata into bdc by calling function module bdc_insert

----


FORM INSERT_BDC.

CALL FUNCTION 'BDC_INSERT'

EXPORTING

TCODE = 'MM01'

TABLES

DYNPROTAB = IT_BDCDATA

EXCEPTIONS

INTERNAL_ERROR = 1

NOT_OPEN = 2

QUEUE_ERROR = 3

TCODE_INVALID = 4

PRINTING_INVALID = 5

POSTING_INVALID = 6

OTHERS = 7.

ENDFORM. " INSERT_BDC

&----


*& Form CLOSE_BDC

&----


  • Closing bdc session

----


FORM CLOSE_BDC.

CALL FUNCTION 'BDC_CLOSE_GROUP'

EXCEPTIONS

NOT_OPEN = 1

QUEUE_ERROR = 2

OTHERS = 3.

ENDFORM. " CLOSE_BDC

<b>Reward points for useful Answers</b>

Regards

Anji