PS:项目创建BAPI_PROJECT_MAINTAIN

1.数据校验:

在表:PROJ(项目定义)中查询项目ID是否已经存在。

  DATA: lv_PSPID TYPE proj-PSPID.

*项目是否存在
  SELECT SINGLE PSPID INTO lv_PSPID FROM proj WHERE pspid = ps_proj-pspid.
  IF sy-subrc = 0.
    ps_output-msgtx = '项目编码' && ls_proj-pspid && '在SAP系统内已经存在'.
    ps_output-msgty = gc_cons_e.   
    RETURN.
  ENDIF.

2.预先生成网络信息

  DATA: lv_proj_def   TYPE ps_posid,
        lv_network    TYPE afko-aufnr,
        lt_wbs_first  LIKE TABLE OF zsps_0002,   "项目;WBS相关上下文信息
        lt_wbs_second LIKE TABLE OF zsps_0002,
        lt_wbs_third  LIKE TABLE OF zsps_0002.

  RANGES: r_wbs_first FOR zsps_0002-posid,
          r_wbs_second FOR zsps_0002-posid.
  CALL FUNCTION 'NUMBER_GET_NEXT'
    EXPORTING
      nr_range_nr             = '15'
      object                  = 'AUFTRAG'
    IMPORTING
      number                  = lv_network
    EXCEPTIONS
      interval_not_found      = 1
      number_range_not_intern = 2
      object_not_found        = 3
      quantity_is_0           = 4
      quantity_is_not_1       = 5
      interval_overflow       = 6
      buffer_overflow         = 7
      OTHERS                  = 8.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ELSE.
    CONDENSE lv_network.
    lv_network = |{ lv_network ALPHA = IN  }|.
  ENDIF.

  READ TABLE pt_wbs INTO DATA(wa_wbs) INDEX 1.
  IF sy-subrc = 0.
    lv_proj_def = wa_wbs-pspid.
  ENDIF.

*第一层---
  CLEAR: r_wbs_first, r_wbs_first[].
  LOOP AT pt_wbs INTO wa_wbs WHERE posid = lv_proj_def.
    r_wbs_first(3) = 'IEQ'.
    r_wbs_first-low = wa_wbs-posid.
    APPEND r_wbs_first.
  ENDLOOP.

*第二层
  CLEAR: r_wbs_second, r_wbs_second[].
  LOOP AT pt_wbs INTO wa_wbs WHERE up IN r_wbs_first[].
    IF ps_proj-prart NE 'PS' AND ps_proj-prart NE 'PH'.
      APPEND wa_wbs TO pt_wbs_net.
    ELSE.
      r_wbs_second(3) = 'IEQ'.
      r_wbs_second-low = wa_wbs-posid.
      APPEND r_wbs_second.
    ENDIF.
  ENDLOOP.

*第三层
  IF ps_proj-prart ='PS' OR ps_proj-prart = 'PH'.
    LOOP AT pt_wbs INTO wa_wbs WHERE up IN r_wbs_second[].
      APPEND wa_wbs TO pt_wbs_net.
    ENDLOOP.
  ENDIF.

  SORT pt_wbs_net BY posid.
  LOOP AT pt_wbs_net INTO DATA(wa_wbs_net).
    lv_network = lv_network + 1.
    CONDENSE lv_network.
    lv_network = |{ lv_network ALPHA = IN  }|.

    wa_wbs_net-znet_work = lv_network.
    MODIFY pt_wbs_net FROM wa_wbs_net.
  ENDLOOP.

将处理好的结果返回到 pt_wbs_net 

3.SET METHODS

  DATA: ls_methods  TYPE bapi_method_project,
        ls_methods2 TYPE bapi_method_project,
        lt_methods  TYPE TABLE OF bapi_method_project.
  DATA: lv_network  LIKE gv_max_network,
        lv_activity TYPE cn_vornr.

  CLEAR: lt_methods.
  "项目
  CLEAR ls_methods.
  ls_methods-objecttype =  'ProjectDefinition'.
  ls_methods-method = 'Create'.
  ls_methods-objectkey = ps_proj-pspid.
  ls_methods-refnumber = '000001'.
  APPEND ls_methods TO lt_methods.

  "第二、三...层WBS.
  CLEAR ls_methods.
  LOOP AT pt_wbs INTO DATA(wa_wbs).
    ls_methods-objecttype = 'WBS-Element'.
    ls_methods-method = 'Create'.
    ls_methods-objectkey = wa_wbs-posid.
    ls_methods-refnumber = ls_methods-refnumber + 1.
    APPEND ls_methods TO lt_methods.
  ENDLOOP.

  "创建上下左右关系
  CLEAR ls_methods.
  ls_methods-objecttype = 'WBS Hierarchy'.
  ls_methods-method = 'CREATE'.
  APPEND ls_methods TO lt_methods.

  "创建网络(多个)
  LOOP AT pt_wbs_net INTO DATA(wa_net).
    ls_methods-objecttype = 'Network'.
    ls_methods-method = 'Create'.
    ls_methods-refnumber = ls_methods-refnumber + 1.
    ls_m

你可能感兴趣的:(SAP,PS,sap)