Skip to Content
0
Former Member
Jan 13, 2006 at 03:02 AM

bdc error log file

482 Views

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