cancel
Showing results for 
Search instead for 
Did you mean: 

bdc error log file

Former Member
0 Kudos

Hi experts,

I have created one BDC program.If any error occurs during the process of BDC, i need to store that file in

'usr/sap/put/alb/sapout'.How can i do this?

This is my BDC program



REPORT Z_TEST100 NO STANDARD PAGE HEADING.

TABLES: VBUK,
        VBUP,
        VBEP,
        VBAK,
        TVAK.


DATA:MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE,
     BDCDATA LIKE BDCDATA    OCCURS 0 WITH HEADER LINE.


DATA: BEGIN OF BDCTAB OCCURS 10.       "BDC table
        INCLUDE STRUCTURE BDCDATA.
DATA: END OF BDCTAB.


DATA: BEGIN OF T_HDR OCCURS 0,
      VBELN LIKE VBUK-VBELN,
      AUART LIKE VBAK-AUART,
      LFARV LIKE TVAK-LFARV,
    END OF T_HDR.

DATA: BEGIN OF T_DET OCCURS 0,
      VBELN LIKE VBUK-VBELN,
      LFSTK LIKE VBUK-LFSTK,
      BESTK LIKE VBUK-BESTK,
      POSNR LIKE VBUP-POSNR,
      LFART LIKE LIKP-LFART,
      BMENG(10),
    END OF T_DET.

*SELECT-OPTIONS S_VBELN FOR VBUK-VBELN.

START-OF-SELECTION.
  PERFORM COLLECT_DATA.
  PERFORM PROCESS_BDC.

END-OF-SELECTION.

*&--------------------------------------------------------------------*
*&      Form  COLLECT_DATA
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM COLLECT_DATA.

  SELECT VBELN BESTK LFSTK FROM VBUK
        INTO CORRESPONDING FIELDS OF TABLE T_HDR
               WHERE
*               VBELN IN S_VBELN. " OR
               LFSTK EQ 'A' OR
               LFSTK EQ 'B'.

  LOOP AT T_HDR.
    SELECT SINGLE * FROM VBAK WHERE VBELN = T_HDR-VBELN.
    IF SY-SUBRC = 0.
      T_HDR-AUART = VBAK-AUART.
      MODIFY T_HDR.
    ENDIF.

    SELECT SINGLE * FROM TVAK WHERE AUART = VBAK-AUART.
    IF SY-SUBRC = 0.
      T_HDR-LFARV = TVAK-LFARV.
      MODIFY T_HDR.
    ENDIF.
  ENDLOOP.


 DELETE T_HDR WHERE LFARV NE 'ZLKB' AND
                    LFARV NE 'ZKKB'.

  CHECK NOT T_HDR[] IS INITIAL.

  SELECT VBELN POSNR
     INTO CORRESPONDING FIELDS OF TABLE T_DET FROM VBUP
      FOR ALL ENTRIES IN T_HDR
      WHERE VBELN = T_HDR-VBELN.


  LOOP AT T_DET.
    SELECT SINGLE * FROM VBEP WHERE VBELN = T_DET-VBELN.
    IF SY-SUBRC = 0.
      T_DET-BMENG = VBEP-BMENG.
      MODIFY T_DET.
    ENDIF.
  ENDLOOP.
ENDFORM.                    "COLLECT_DATA

*&--------------------------------------------------------------------*
*&      Form  PROCESS_BDC
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM PROCESS_BDC.
  DATA: V_DATE(10).
  DATA: LNUM(2) TYPE N.
  DATA: MFIELD(20).
  DATA: LFIELD(20).
  DATA: PFIELD(20).

  CONCATENATE SY-DATUM+6(2) '.' SY-DATUM+4(2) '.'
                   SY-DATUM+0(4) '.' INTO  V_DATE.

  LOOP AT T_HDR.
*--SCREEN 4001

    REFRESH BDCDATA.

    PERFORM BDC_DYNPRO      USING 'SAPMV50A' '4001'.
    PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                  'LIKP-VSTEL'.
    PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                    '/00'.

    IF T_HDR-LFARV = 'ZLKB'.
      PERFORM BDC_FIELD       USING 'LIKP-VSTEL'
                                    'PLWN'.
    ELSEIF T_HDR-LFARV = 'ZKKB'.
      PERFORM BDC_FIELD       USING 'LIKP-VSTEL'
                                    'KHWN'.
    ENDIF.


    PERFORM BDC_FIELD       USING 'LV50C-DATBI'
                                   V_DATE.

    PERFORM BDC_FIELD       USING 'LV50C-VBELN'
                                   T_HDR-VBELN.


*--SCREEN 1000(1)

    LOOP AT T_DET WHERE VBELN = T_HDR-VBELN.

      LNUM = LNUM + 1.

      PERFORM BDC_DYNPRO      USING 'SAPMV50A' '1000'.
      PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                      '=T02'.

      CONCATENATE 'LIPS-MATNR' '(' LNUM ')' INTO MFIELD.

      PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                      MFIELD.       "'LIPS-MATNR(02)'.

*--SCREEN 1000(2)


      CONCATENATE 'LIPSD-G_LFIMG' '(' LNUM ')' INTO LFIELD.

      PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                     LFIELD. "'LIPSD-G_LFIMG(01)'.

      PERFORM BDC_FIELD       USING  LFIELD
                                      T_DET-BMENG.


      CONCATENATE 'LIPSD-PIKMG' '(' LNUM ')' INTO PFIELD.

      PERFORM BDC_FIELD       USING 'BDC_CURSOR'
                                     PFIELD.

      PERFORM BDC_FIELD       USING  PFIELD
                                     T_DET-BMENG.

      PERFORM BDC_FIELD       USING 'BDC_OKCODE'
                                      '=WABU_T'.


      CALL TRANSACTION 'VL01N' USING BDCDATA
         MODE 'A' UPDATE 'S' MESSAGES INTO MESSTAB.
    ENDLOOP.
  ENDLOOP.




ENDFORM.                    "PROCESS_BDC



*-------------------------------------------------------*
*      Form  BDC_DYNPRO
*-------------------------------------------------------*

FORM BDC_DYNPRO USING PROGRAM DYNPRO.
  CLEAR BDCDATA.
  BDCDATA-PROGRAM  = PROGRAM.
  BDCDATA-DYNPRO   = DYNPRO.
  BDCDATA-DYNBEGIN = 'X'.
  APPEND BDCDATA.
ENDFORM.                               " BDC_DYNPRO

*-------------------------------------------------------*
*      Form  BDC_FIELD
*-------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
  CLEAR BDCDATA.
  BDCDATA-FNAM = FNAM.
  BDCDATA-FVAL = FVAL.
  APPEND BDCDATA.
ENDFORM.                    "bdc_field

*-----------------------------------------------------------*
* FORM NAME        : BDC_TAB
* FORM DESCRIPTION : This routine fills the BDC table.
*-----------------------------------------------------------*

FORM BDC_TAB USING DYNBEGIN PROGRAM DYNPRO.
  CLEAR BDCTAB.
  IF DYNBEGIN = 'X'.
    BDCTAB-DYNBEGIN = DYNBEGIN.
    BDCTAB-PROGRAM  = PROGRAM.
    BDCTAB-DYNPRO   = DYNPRO.
    APPEND BDCTAB.
  ELSE.
    BDCTAB-FNAM     = PROGRAM.
    BDCTAB-FVAL     = DYNPRO.
    APPEND BDCTAB.
  ENDIF.
ENDFORM.                    "bdc_tab

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Look at this for reading the errors and writing them out. Instead of writing them out, you can put them in an internal table.

suresh_datti
Active Contributor
0 Kudos

Hi Kaki,

You can use the follwing code as a starter..


data: begin of messages occurs 0,
        vbeln  type vbeln,
        text like t100-text.
        include structure bdcmsgcoll.
data: end of messages.

loop at messtab.
  move-corresponding messtab to messages.
  messages-vbeln t_hdr-vbeln.
  call function 'FORMAT_MESSAGE'
    exporting
      id        = messtab-msgid
      lang      = messtab-msgspra
      no        = messtab-msgnr
      v1        = messtab-msgv1
      v2        = messtab-msgv2
      v3        = messtab-msgv3
      v4        = messtab-msgv4
    importing
      msg       = messages-text
    exceptions
      not_found = 01
      others    = 02.
  if sy-subrc <> 0.
    clear messages-text.
  endif.
  append messages.
endloop.
open dataset w_physical_file for output in text mode.
loop at messages..
  transfer messages to w_physical_file.
endloop.

close dataset w_physical_file.

Regards,

Suresh Datti

Answers (4)

Answers (4)

former_member186741
Active Contributor
0 Kudos

SOMETHIN LIKE:

CALL TRANSACTION 'VL01N' USING BDCDATA

MODE 'A' UPDATE 'S' MESSAGES INTO MESSTAB.

DESCRIBE TABLE MESSTAB LINES ZLINE.

IF ZLINE > 0.

PERFORM BDC_ERRORS.

ENDIF.

.................

FORM BDC_ERRORS.

LOOP AT MESSTAB.

MSG_ID = MESSTAB-MSGID.

MSG_NO = MESSTAB-MSGNR.

MSG_VAR1 = MESSTAB-MSGV1.

MSG_VAR2 = MESSTAB-MSGV2.

MSG_VAR3 = MESSTAB-MSGV3.

MSG_VAR4 = MESSTAB-MSGV4.

CALL FUNCTION 'MESSAGE_PREPARE'

EXPORTING

LANGUAGE = MESSTAB-MSGSPRA

MSG_ID = MSG_ID

MSG_NO = MSG_NO

MSG_VAR1 = MSG_VAR1

MSG_VAR2 = MSG_VAR2

MSG_VAR3 = MSG_VAR3

MSG_VAR4 = MSG_VAR4

IMPORTING

MSG_TEXT = W_ERRTXT

EXCEPTIONS

FUNCTION_NOT_COMPLETED = 1

MESSAGE_NOT_FOUND = 2

OTHERS = 3.

APPEND W_ERRTXT TO T_ERRS.

ENDLOOP.

ENDFORM.

Former Member
0 Kudos

Error handling is very specific to your company and sometimes even to the business process you are implementing. You have decide how you want to store the failed records, how you want notify someone about the errors and how you want to store the messages.

Do you want to just dump the error messages coming out of the call transaction onto a file, then you already have the solutions here. Basically you loop at your bdcmessages table where msgtyp is 'E', prepare the message and then insert the message into another table. After all the messages are stored in the internal table, you will then you use 'open dataset' to open the application server file and loop at this message table. Within the loop your will use 'transfer dataset' to transfer each record of the internal table onto the file. Once all the records are transferred, you will then use 'close dataset' to complete the data transfer to the file.

Now if you also want to store the error data records, you need to come up with a logic that identifies the error data records that went into the call transaction. This may another internal table of the same structure as your itab. Another standard way of storing the data is after call transaction, if you determine that an error occured, you can then put the same BDCDATA into a session. That way you don't have repeat the creation of BDCDATA and someone can easily go to SM35 and process the session to correct it. To put the same data into a session, you will use BDC_OPEN_GROUP, BDC_INSERT and BDC_CLOSE_GROUP function modules. You can search this forum for these function module usage and examples. There are tonnes of examples on this forum about them.

Hope this helps,

Srinivas

former_member186741
Active Contributor
0 Kudos

after your call tran the table messtab has the current error messages. Add these messages to another table with some other key info to identify which transaction iteration the message belong to. At end of program send the contents of this new table to your file.

Former Member
0 Kudos

Can any one gime the sample code pls.

kaki

suresh_datti
Active Contributor
0 Kudos

Hi Kaki,

Errors if any during your BDC will be stored in MESSTAB. You can use MESSAGE_TEXT_BUILD function module to get the message texts into another internal table. You can then use OPEN DATASET to transfer the messages table to the desired location.

Regards,

Suresh Datti