SAP data migration: Create project milestone

引用:翱翔云天

This report is used to create milestone.

REPORT ZUP4 .
DATA:
  BEGIN OF RTAB ,
    PROJECT(24),
    WBS(24),
    USAGE(5),
    DESC(40),
    FBDATE(10),
    ACDATE(10),
    SALES(1),
    IVPER(10),
  END OF RTAB.
DATA: ITAB LIKE STANDARD TABLE OF RTAB.
DATA: TEMP LIKE STANDARD TABLE OF RTAB WITH HEADER LINE.
DATA: PRO_DEF LIKE BAPI_PROJECT_DEFINITION,
      PRO_DEF_UP LIKE BAPI_PROJECT_DEFINITION_UP.
DATA: MED_PRO LIKE BAPI_METHOD_PROJECT OCCURS 0 WITH HEADER LINE,
      MIL_STO LIKE BAPI_WBS_MILESTONE OCCURS 0 WITH HEADER LINE,
      MIL_STO_UP LIKE BAPI_WBS_MILESTONE_UPD OCCURS 0 WITH HEADER LINE.
DATA: RC LIKE BAPIRETURN1.
DATA: DATE1 TYPE D,DATE2 TYPE D.
PARAMETERS: FILE LIKE RLGRAP-FILENAME OBLIGATORY.
perform UPLOAD_FILE.
CHECK NOT ITAB[] IS INITIAL.
*******
SORT ITAB BY PROJECT WBS.
LOOP AT ITAB INTO RTAB.
  APPEND RTAB TO TEMP.
  AT END OF WBS.
    LOOP AT TEMP.
      PRO_DEF-PROJECT_DEFINITION = RTAB-PROJECT.
      PRO_DEF_UP-PROJECT_DEFINITION = 'X'.
      MED_PRO-OBJECTTYPE = 'WBSMILESTONE'.
      MED_PRO-METHOD = 'CREATE'.
      MED_PRO-REFNUMBER = '000001'.
      APPEND MED_PRO.
      CLEAR: MED_PRO.
      MED_PRO-METHOD = 'SAVE'.
      APPEND MED_PRO.
      MIL_STO-WBS_ELEMENT = TEMP-WBS.
      MIL_STO-MILESTONE_USAGE = TEMP-USAGE.
      MIL_STO-DESCRIPTION = TEMP-DESC.
      CLEAR: DATE1,DATE2.
      CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
           EXPORTING
                DATE_EXTERNAL            = TEMP-FBDATE
           IMPORTING
                DATE_INTERNAL            = DATE1
           EXCEPTIONS
                DATE_EXTERNAL_IS_INVALID = 1
                OTHERS                   = 2.
      MIL_STO-FIXED_MILESTONE_DATE_BASIC = DATE1.
      CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
           EXPORTING
                DATE_EXTERNAL            = TEMP-ACDATE
           IMPORTING
                DATE_INTERNAL            = DATE2
           EXCEPTIONS
                DATE_EXTERNAL_IS_INVALID = 1
                OTHERS                   = 2.
      MIL_STO-ACTUAL_DATE = DATE2.
      MIL_STO-SALES_DOC_DATE_INIDICATOR = TEMP-SALES.
      MIL_STO-INVOICE_PERCENTAGE = TEMP-IVPER.
      APPEND MIL_STO.
      MIL_STO_UP-WBS_ELEMENT = 'X'.
      MIL_STO_UP-MILESTONE_USAGE = 'X'.
      MIL_STO_UP-DESCRIPTION = 'X'.
      MIL_STO_UP-FIXED_MILESTONE_DATE_BASIC = 'X'.
      MIL_STO_UP-ACTUAL_DATE = 'X'.
      MIL_STO_UP-SALES_DOC_DATE_INIDICATOR = 'X'.
      MIL_STO_UP-INVOICE_PERCENTAGE = 'X'.
      APPEND MIL_STO_UP.
*    ******
      CALL FUNCTION 'BAPI_PROJECT_MAINTAIN'
           EXPORTING
                I_PROJECT_DEFINITION         = PRO_DEF
                I_PROJECT_DEFINITION_UPD     = PRO_DEF_UP
           IMPORTING
                RETURN                       = RC
           TABLES
                I_METHOD_PROJECT             = MED_PRO
                I_WBS_MILESTONE_TABLE        = MIL_STO
                I_WBS_MILESTONE_TABLE_UPDATE = MIL_STO_UP.
      CLEAR: PRO_DEF,RC,MED_PRO,MED_PRO[],MIL_STO,MIL_STO[],
      MIL_STO_UP,MIL_STO_UP[],PRO_DEF_UP.
    ENDLOOP.
    CLEAR: TEMP,TEMP[].
  ENDAT.
ENDLOOP.
*&---------------------------------------------------------------------*
*&      Form  UPLOAD_FILE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_DATASET  text
*----------------------------------------------------------------------*
FORM UPLOAD_FILE.
  CALL FUNCTION 'WS_UPLOAD'
       EXPORTING
            FILENAME                = FILE
            FILETYPE                = 'DAT'
       TABLES
            DATA_TAB                = ITAB
       EXCEPTIONS
            CONVERSION_ERROR        = 1
            FILE_OPEN_ERROR         = 2
            FILE_READ_ERROR         = 3
            INVALID_TYPE            = 4
            NO_BATCH                = 5
            UNKNOWN_ERROR           = 6
            INVALID_TABLE_WIDTH     = 7
            GUI_REFUSE_FILETRANSFER = 8
            CUSTOMER_ERROR          = 9
            OTHERS                  = 10.
ENDFORM.                    " UPLOAD_FILE

你可能感兴趣的:(migration)