SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

BDC Processing & Idoc status update



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Interfaces | Интерфейсы
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1639

PostPosted: Mon Sep 10, 2007 8:18 pm    Post subject: BDC Processing & Idoc status update Reply with quote

Code:
**********************************************************************
*---- Data definition -------------------------------------------------
  DATA: BEGIN OF BDCDATA OCCURS 5.
          INCLUDE STRUCTURE BDCDATA.
  DATA: END OF BDCDATA.
  DATA: C_TCODE LIKE BKPF-TCODE VALUE 'FB01'.
  DATA BEGIN OF MESSTAB OCCURS 10.       
         INCLUDE STRUCTURE BDCMSGCOLL.
  DATA END OF MESSTAB.                   


**********************************************************************
*---- Call transaction ------------------------------------------------
FORM Main_Program
  REFRESH BDCDATA.
  PERFORM APPEND_BDC USING 'SAPMF05A' '0100' '          ' '        '.
  PERFORM APPEND_BDC USING '        ' '    ' 'BKPF-BLDAT' '09031998'.
  PERFORM APPEND_BDC USING '        ' '    ' 'BDC_OKCODE' '/00'.
  PERFORM APPEND_BDC USING 'SAPMF05A' '0300' '          ' '   '.
  PERFORM APPEND_BDC USING '        ' '    ' 'BSEG-WRBTR' '*'.
  PERFORM APPEND_BDC USING '        ' '    ' 'BDC_OKCODE' 'BU'.

  CALL TRANSACTION 'FB01' USING BDCDATA MODE 'N' UPDATE 'S'.
  PERFORM UPDATE_IDOC_STATUS.
ENDFORM.

**********************************************************************
*--- Call transaction with errors to BDC -----------------------------
  REFRESH MESSTAB.
  CALL TRANSACTION C_TCODE USING BDCDATA MODE 'N' UPDATE 'S'
       MESSAGES INTO MESSTAB.

  RETURN_CODE = SY-SUBRC.
  IF RETURN_CODE = 0.
    LOOP AT MESSTAB.
      IF MESSTAB-MSGTYP = 'E'.
        RETURN_CODE = MESSTAB-MSGNR.
        SY-MSGID = 'B1'.
        SY-MSGNO = 999.
        SY-MSGV1 = 'Error: Check BDC'.
      ENDIF.
    ENDLOOP.
  ENDIF.

*--- Here we check the return code, if there was an error, we put the
*    transaction in a BDC session for the user to review and correct.
  IF RETURN_CODE NE 0.
    CALL FUNCTION 'BDC_OPEN_GROUP'
         EXPORTING
              CLIENT = SY-MANDT
              GROUP  = 'ZKJW'
              USER   = SY-UNAME
              KEEP   = 'X'.
    CALL FUNCTION 'BDC_INSERT'
         EXPORTING
              TCODE     = C_TCODE
         TABLES
              DYNPROTAB = BDCDATA.
    CALL FUNCTION 'BDC_CLOSE_GROUP'
         EXCEPTIONS
              NOT_OPEN    = 1
              QUEUE_ERROR = 2
              OTHERS      = 3.
  ENDIF.

**********************************************************************
*--- Append BDCDATA internal table ------------------------------------
FORM APPEND_BDC USING    VALUE(P_PROG)
                         VALUE(P_SCREEN)
                         VALUE(P_NAM)
                         VALUE(P_VAL).
  CLEAR BDCDATA.

  IF P_PROG NE SPACE.
    BDCDATA-PROGRAM   = P_PROG.
    BDCDATA-DYNPRO    = P_SCREEN.
    BDCDATA-DYNBEGIN  = 'X'.
    BDCDATA-FNAM      = P_NAM.
    BDCDATA-FVAL      = P_VAL.
  ELSE.
    BDCDATA-FNAM      = P_NAM.
    BDCDATA-FVAL      = P_VAL.
  ENDIF.

  APPEND BDCDATA.

ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  UPDATE_IDOC_STATUS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM UPDATE_IDOC_STATUS.

*--- Now we check the CALL TRANSACTION return code and set IDOC status
  CLEAR IDOC_STATUS.
  IF RETURN_CODE = 0.
    WORKFLOW_RESULT = '0'.
    IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.
    IDOC_STATUS-STATUS = '53'.
    IDOC_STATUS-UNAME = SY-UNAME.
    IDOC_STATUS-REPID = SY-REPID.
    IDOC_STATUS-MSGTY = SY-MSGTY.
    IDOC_STATUS-MSGID = SY-MSGID.
    IDOC_STATUS-MSGNO = SY-MSGNO.
    IDOC_STATUS-MSGV1 = SY-MSGV1.
    IDOC_STATUS-MSGV2 = SY-MSGV2.
    IDOC_STATUS-MSGV3 = SY-MSGV3.
    IDOC_STATUS-MSGV4 = SY-MSGV4.
    RETURN_VARIABLES-WF_PARAM = 'Processed_IDOCs'.
    RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM.
    APPEND RETURN_VARIABLES.
  ELSE.
    WORKFLOW_RESULT = '99999'.
    IDOC_STATUS-DOCNUM = IDOC_CONTRL-DOCNUM.
    IDOC_STATUS-STATUS = '51'.
    IDOC_STATUS-UNAME = SY-UNAME.
    IDOC_STATUS-REPID = SY-REPID.
    IDOC_STATUS-MSGTY = SY-MSGTY.
    IDOC_STATUS-MSGID = SY-MSGID.
    IDOC_STATUS-MSGNO = SY-MSGNO.
    IDOC_STATUS-MSGV1 = SY-MSGV1.
    IDOC_STATUS-MSGV2 = SY-MSGV2.
    IDOC_STATUS-MSGV3 = SY-MSGV3.
    IDOC_STATUS-MSGV4 = SY-MSGV4.
    RETURN_VARIABLES-WF_PARAM = 'Error_IDOCs'.
    RETURN_VARIABLES-DOC_NUMBER = IDOC_CONTRL-DOCNUM.
    APPEND RETURN_VARIABLES.
  ENDIF.
  APPEND IDOC_STATUS.
ENDFORM.                               " UPDATE_IDOC_STATUS
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Interfaces | Интерфейсы All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.