Create WBS for a project using BAPI


  1. BAPI_BUS2054_CREATE_MULTI'
* Initialization of BAPIs
  CALL FUNCTION 'BAPI_PS_INITIALIZATION'.
* Add location Pifs
  CALL FUNCTION 'BAPI_BUS2054_CREATE_MULTI'
    EXPORTING
      I_PROJECT_DEFINITION = P_F_PIFID (Project ID)
    TABLES
      IT_WBS_ELEMENT       = P_L_T_WBSELEMENTS
      ET_RETURN            = P_L_T_RETURN.

  REFRESH P_L_T_WBSELEMENTS.
  CLEAR G_F_ERROR.
  LOOP AT P_L_T_RETURN INTO G_R_RETURN.
    IF G_R_RETURN-TYPE CA G_C_AEX.
      G_F_ERROR = G_C_X.
    ENDIF.
  ENDLOOP.

* Error handling / end processing
  IF G_F_ERROR IS INITIAL.

*-- Post changes
    REFRESH G_T_RETURN2.
    CALL FUNCTION 'BAPI_PS_PRECOMMIT'
      TABLES
        ET_RETURN = G_T_RETURN2.
    APPEND LINES OF G_T_RETURN2 TO P_L_T_RETURN.

    CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
      EXPORTING
        I_PRECOMMIT_OK = 'Y'.
*-- Check for errors
    LOOP AT P_L_T_RETURN INTO G_R_RETURN.  "
      IF G_R_RETURN-TYPE CA G_C_AEX.
        G_F_ERROR = G_C_X.
      ENDIF.
    ENDLOOP.

*-- Everything ok
    IF G_F_ERROR IS INITIAL.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          WAIT = G_C_X.
      COMMIT WORK.
    ELSE.
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
      REFRESH G_T_RETURN2.
      CALL FUNCTION 'BAPI_PS_PRECOMMIT'
        TABLES
          ET_RETURN = G_T_RETURN2.
      APPEND LINES OF G_T_RETURN2 TO P_L_T_RETURN.
      REFRESH G_T_RETURN2.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
    ENDIF.

* Error occured
  ELSE.
    REFRESH G_T_RETURN2.
    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
    REFRESH G_T_RETURN2.
    CALL FUNCTION 'BAPI_PS_PRECOMMIT'
      TABLES
        ET_RETURN = G_T_RETURN2.
    APPEND LINES OF G_T_RETURN2 TO P_L_T_RETURN.
    REFRESH G_T_RETURN2.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
  ENDIF.

No comments:

Post a Comment

/*Newer Post*/ Older Post Home