PS模块第六节:PS常用BAPI以及调用示例

2022-03-07 14:52:01 浏览数 (1)

声明:本文仅代表原作者观点,仅用于SAP软件的应用与学习,不代表SAP公司。注:文中所示截图来源SAP软件,相应著作权归SAP所有。

01

目录

1项目定义

1.1 查询

1.1.1 BAPI_PROJECTDEF_GETLIST生成选择标准的项目定义的清单

1.1.2 BAPI_PROJECTDEF_GETDETAIL读取项目定义的细节

1.1.3 BAPI_BUS2001_GETDATA 项目定义的详细数据

1.1.4 其他类查询

1.2 新增

1.2.1 BAPI_PROJECTDEF_CREATE旧的不可以增强的新增

1.2.2 BAPI_BUS2001_CREATE项目定义新增,可扩展字段

1.2.3 项目定义屏幕增强CMOD,添加历史项目编号和历史项目名称

1.2.4 BAPI增强添加历史项目编号和历史项目名称

1.3 修改

1.4 删除

2 WBS

2.1 查询

2.1.1BAPI_PROJECT_EXISTENCECHECK判断是否存在,并查询BAPI_PROJECT_GETINFO

2.1.2 BAPI_BUS2054_GETDATA根据输入的WBS号查询WBS详情

2.1.3 BAPI_BUS2054_GET_STATUS 获取WBS状态

2.2 新增

2.2.1 BAPI_BUS2054_CREATE_MULTI只创建WBS,可维护增强字段

2.1.5 BAPI_PROJECT_SAVEREPLICA |复制工作分解结构 (ALE),可增强

2.3 修改

2.3.1 BAPI_BUS2054_SET_STATUS |设置/重置 BUS2054 状态 (工作分解结构)|

2.3.2 BAPI_BUS2054_CHANGE_MULTI |使用 BAPI 更改 WBS 要素|

2.3.3 BAPI_BUS2054_DELETE_MULTI|使用 BAPI 删除 WBS 要素|

3 网络

3.1 网络查询

3.1.1 BAPI_NETWORK_GETLIST查询网络清单

3.1.2 BAPI_BUS2002_GETDATA |网络抬头的详细数据 |

3.1.3 BAPI_NETWORK_GETDETAIL |读取网络的明细信息(包括所有对象),只能查询一个网络

3.1.4 BAPI_NETWORK_GETINFO |读取网络的详细信息 (包括所有对象) |可以查询多个网络

3.2 网络新增

3.2.1 BAPI_BUS2002_CREATE |创建网络 |

3.3 网络删除

3.3.1 BAPI_BUS2002_DELETE|删除网络 |

4 活动(作业)

4.1 BAPI_BUS2002_ACT_GETDATA |活动的详细数据 |

4.2 BAPI_BUS2002_ACT_CREATE_MULTI |清单: 创建网络活动 |

4.3 BAPI_BUS2002_ACT_CHANGE_MULTI|清单: 更改网络活动

5 物料组件

5.1 BAPI_NETWORK_COMP_GETLIST |网络所有组件的清单 |

5.2 BAPI_NETWORK_COMP_GETDETAIL|网络作业物料组件的详述数据

5.3 BAPI_NETWORK_COMP_ADD|为网络填加物料组件 |

5.4 BAPI_NETWORK_COMP_CHANGE|为网络更改物料组件 |

5.5 BAPI_NETWORK_COMP_REMOVE|从网络中删除物料组件 |

6 项目预算BAPI

7 服务主数据类采购申请创建

7.1 外部活动创建

7.2 服务活动创建,必须输入服务主数据

从项目定义,到WBS,到网络,到活动,到物料组件

1项目定义

1.1 查询

1.1.1 BAPI_PROJECTDEF_GETLIST生成选择标准的项目定义的清单

代码语言:javascript复制
*&---------------------------------------------------------------------*
*& Report ZLGZBAPI_PROJECTDEF_GETLIST
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZLGZBAPI_PROJECTDEF_GETLIST.


TABLEs:vbak,proj.
"第一步,定义变量
data: iv_max_rows type BAPIF4A-MAX_ROWS.
data: lt_PROJECT_DEFINITION_LIST TYPE TABLE of BAPIPREXP."定义的对外显示的信息



"第二步,定义range

"二种定义函数中range方法
*选项介绍:
*1.SIGN  值为I和E I包含 E是排除 一般使用I
*2.OPTION 如果HIGH 为空  为单值选择 有 EQ、NE、GT、LE、LT等逻辑操作  对于*的  CP包含  NP是排除
*         如果HIGH 不为空 为区间选择 有BT,NB可选
*3.LOW     低值
*4.HIGH    高值


"方法一,查找函数range的LOW和HIGH的类型,采用type RANGE OF 不过这种方式,已经跳到函数内部了,失去了函数封装的意义了,下面就是例如针对结构BAPI_2002_PD_RANGE的示例

*DATA lt_pspid TYPE RANGE OF PS_PSPID."项目定义ID
*DATA wa_pspid LIKE LINE OF lt_pspid.




"    wa_pspid-sign   = 'I'.
"    wa_pspid-option = 'BT'.
"    wa_pspid-low    = 'PSCN02_2020001'.
"    wa_pspid-high    = 'PSCN02_2020003'.
"  APPEND wa_pspid TO lt_pspid.




"方法二,直接用data引用封装好的range

data lt_pd_range type table of BAPI_2002_PD_RANGE."这个是封装的项目编号range
data wa_pd_range type BAPI_2002_PD_RANGE.


data lt_descr_range type table of BAPI_2002_DESCR_RANGE."这个是封装的项目描述range
data wa_descr_range type BAPI_2002_DESCR_RANGE.




"第三步,定义选择条件
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
  PARAMETERS p_p1 TYPE BAPIF4A-MAX_ROWS .
SELECTION-SCREEN END OF BLOCK b1.


SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-001.

  SELECT-OPTIONS: range0 for  proj-PSPID DEFAULT '0' TO 'PSCN02_2020003' OPTION BT.
  SELECT-OPTIONS: range1 FOR  proj-POST1 DEFAULT 'ZCN02基建项目' TO 'ZCN02基建项目' OPTION BT.

  "也可以根据定义的range结构定义选择条件
* SELECT-OPTIONS: range0 for  wa_pd_range DEFAULT '0' TO 'PSCN02_2020003' OPTION BT.
* SELECT-OPTIONS: range1 FOR  wa_descr_range DEFAULT 'ZCN02基建项目' TO 'ZCN02基建项目' OPTION BT.
SELECTION-SCREEN END OF BLOCK b2.



"第四步,将选择条件的值赋值给range

"屏幕选择的操作
iv_max_rows = p_p1."将输入显示行数赋值给参数1iv_max_rows
*wa_descr_range = range0.  "直接将range0复制到wa_pd_range貌似把高的值无法复制过来,那就强行赋值了,给第一个range赋值
clear wa_pd_range.
wa_pd_range-sign = range0-sign.
wa_pd_range-option = range0-option.
wa_pd_range-low = range0-low.
wa_pd_range-high = range0-high.
APPEND wa_pd_range to lt_pd_range.



*wa_pd_range = range1.  "直接将range0复制到wa_pd_range貌似把高的值无法复制过来,那就强行赋值了
clear wa_descr_range.
wa_descr_range-sign = range1-sign.
wa_descr_range-option = range1-option.
wa_descr_range-low = range1-low.
wa_descr_range-high = range1-high.
APPEND wa_descr_range to lt_descr_range.



"未赋值判断

IF p_p1 is  INITIAL.
    MESSAGE '最好选择行数,不然撑爆' type 'I'.
ENDIF.


"第五步,调用BAPI


"调用函数
CALL FUNCTION 'BAPI_PROJECTDEF_GETLIST'
 EXPORTING
   MAX_ROWS                       = iv_max_rows
* IMPORTING
*   RETURN                         =
  TABLES
    project_definition_list        = lt_PROJECT_DEFINITION_LIST
    PROJECT_DEFINITION_RANGE       = lt_pd_range
    "DESCRIPTION_RANGE              = lt_descr_range
          .


"第六步,显示
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
 EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                =
*   I_BUFFER_ACTIVE                   =
*   I_CALLBACK_PROGRAM                = ' '
*   I_CALLBACK_PF_STATUS_SET          = ' '
*   I_CALLBACK_USER_COMMAND           = ' '
*   I_CALLBACK_TOP_OF_PAGE            = ' '
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
   I_STRUCTURE_NAME                  = 'BAPIPREXP'
*   I_BACKGROUND_ID                   = ' '
*   I_GRID_TITLE                      =
*   I_GRID_SETTINGS                   =
*   IS_LAYOUT_LVC                     =
*   IT_FIELDCAT_LVC                   =
*   IT_EXCLUDING                      =
*   IT_SPECIAL_GROUPS_LVC             =
*   IT_SORT_LVC                       =
*   IT_FILTER_LVC                     =
*   IT_HYPERLINK                      =
*   IS_SEL_HIDE                       =
*   I_DEFAULT                         = 'X'
*   I_SAVE                            = ' '
*   IS_VARIANT                        =
*   IT_EVENTS                         =
*   IT_EVENT_EXIT                     =
*   IS_PRINT_LVC                      =
*   IS_REPREP_ID_LVC                  =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE                 = 0
*   I_HTML_HEIGHT_TOP                 =
*   I_HTML_HEIGHT_END                 =
*   IT_ALV_GRAPHICS                   =
*   IT_EXCEPT_QINFO_LVC               =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
  TABLES
    t_outtab                          = lt_PROJECT_DEFINITION_LIST
* EXCEPTIONS
*   PROGRAM_ERROR                     = 1
*   OTHERS                            = 2
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

调用示例:

1.1.2 BAPI_PROJECTDEF_GETDETAIL读取项目定义的细节

代码语言:javascript复制
*&---------------------------------------------------------------------*
*& Report ZLGZBAPI_PROJECTDEF_GETDETAIL
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZLGZBAPI_PROJECTDEF_GETDETAIL.


"第一步,定义变量
data: WA_PROJECT_DEFI type BAPI_PROJ_KEY-PROJECT_DEFI."项目定义编号
data: WA_PROJ_KEY_INT TYPE BAPI_PROJ_KEY-PROJ_KEY_INT."项目内部编号

data: LT_PROJECT_DEFINITION_EX type TABLE of BAPI_PROJECT_DEFINITION_EX."定义输出变量
data: WA_PROJECT_DEFINITION_EX type BAPI_PROJECT_DEFINITION_EX."定义输出变量


"第二步,定义屏幕参数

PARAMETERS p_p1 TYPE PROJ-PSPID.

PARAMETERS p_p2 TYPE PROJ-PSPNR.



"第三步,赋值


WA_PROJECT_DEFI = p_p1.
WA_PROJ_KEY_INT = p_p2.




"第四步,调用函数

CALL FUNCTION 'BAPI_PROJECTDEF_GETDETAIL'
  EXPORTING
    currentexternalproje          = WA_PROJECT_DEFI
    currentinternalproje          = WA_PROJ_KEY_INT
 IMPORTING
   PROJECT_DEFINITION_STRU       = WA_PROJECT_DEFINITION_EX
*   RETURN                        =
          .

APPEND WA_PROJECT_DEFINITION_EX TO LT_PROJECT_DEFINITION_EX.

"第五步,ALV输出

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
 EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                =
*   I_BUFFER_ACTIVE                   =
*   I_CALLBACK_PROGRAM                = ' '
*   I_CALLBACK_PF_STATUS_SET          = ' '
*   I_CALLBACK_USER_COMMAND           = ' '
*   I_CALLBACK_TOP_OF_PAGE            = ' '
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
   I_STRUCTURE_NAME                  = 'BAPI_PROJECT_DEFINITION_EX'
*   I_BACKGROUND_ID                   = ' '
*   I_GRID_TITLE                      =
*   I_GRID_SETTINGS                   =
*   IS_LAYOUT_LVC                     =
*   IT_FIELDCAT_LVC                   =
*   IT_EXCLUDING                      =
*   IT_SPECIAL_GROUPS_LVC             =
*   IT_SORT_LVC                       =
*   IT_FILTER_LVC                     =
*   IT_HYPERLINK                      =
*   IS_SEL_HIDE                       =
*   I_DEFAULT                         = 'X'
*   I_SAVE                            = ' '
*   IS_VARIANT                        =
*   IT_EVENTS                         =
*   IT_EVENT_EXIT                     =
*   IS_PRINT_LVC                      =
*   IS_REPREP_ID_LVC                  =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE                 = 0
*   I_HTML_HEIGHT_TOP                 =
*   I_HTML_HEIGHT_END                 =
*   IT_ALV_GRAPHICS                   =
*   IT_EXCEPT_QINFO_LVC               =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
  TABLES
    t_outtab                          = LT_PROJECT_DEFINITION_EX
* EXCEPTIONS
*   PROGRAM_ERROR                     = 1
*   OTHERS                            = 2
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

1.1.3 BAPI_BUS2001_GETDATA 项目定义的详细数据

再看看新版的项目定义,有哪些区别,可增强,自定义字段按需获取。至于扩展字段的查询稍后再演示。

代码语言:javascript复制
*&---------------------------------------------------------------------*
*& Report ZLGZBAPI_BUS2001_GETDATA
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZLGZBAPI_BUS2001_GETDATA.


"第一步,定义变量
"输出和输入
DATA:
ld_e_project_definition   TYPE BAPI_BUS2001_DETAIL ,
lt_e_project_definition   TYPE STANDARD TABLE OF BAPI_BUS2001_DETAIL ,
ld_i_project_definition   TYPE BAPI_BUS2001_DETAIL-PROJECT_DEFINITION ,


"返回变量
it_et_return   TYPE STANDARD TABLE OF BAPIRET2 ,
wa_et_return   LIKE LINE OF it_et_return,

"语言
ld_i_language   TYPE BAPI_BUS2001_DETAIL-LANGU_ISO ,


"扩展的输入变量,扩展字段使用
it_extensionin   TYPE STANDARD TABLE OF BAPIPAREX ,
wa_extensionin   LIKE LINE OF it_extensionin,

"扩展的输出变量,扩展字段使用
it_extensionout   TYPE STANDARD TABLE OF BAPIPAREX ,
wa_extensionout   LIKE LINE OF it_extensionout.


"第二步,赋值
ld_i_project_definition = 'LGZXS002'.
"populate fields of struture and append to itab
append wa_et_return to it_et_return.


ld_i_language = 'ZH'.


"populate fields of struture and append to itab
append wa_extensionin to it_extensionin.


"populate fields of struture and append to itab
append wa_extensionout to it_extensionout.
.



"第三步,调用函数及lvc展示
CALL FUNCTION 'BAPI_BUS2001_GETDATA'
  EXPORTING
    i_project_definition =       ld_i_project_definition
*   i_language =                 ld_i_language
  IMPORTING
    e_project_definition =       ld_e_project_definition
* TABLES
*   et_return =                  it_et_return
*   extensionin =                it_extensionin
*   extensionout =               it_extensionout
    .  "  BAPI_BUS2001_GETDATA

IF SY-SUBRC EQ 0.
  APPEND ld_e_project_definition to lt_e_project_definition.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
 EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                =
*   I_BUFFER_ACTIVE                   =
*   I_CALLBACK_PROGRAM                = ' '
*   I_CALLBACK_PF_STATUS_SET          = ' '
*   I_CALLBACK_USER_COMMAND           = ' '
*   I_CALLBACK_TOP_OF_PAGE            = ' '
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
   I_STRUCTURE_NAME                  = 'BAPI_BUS2001_DETAIL'
*   I_BACKGROUND_ID                   = ' '
*   I_GRID_TITLE                      =
*   I_GRID_SETTINGS                   =
*   IS_LAYOUT_LVC                     =
*   IT_FIELDCAT_LVC                   =
*   IT_EXCLUDING                      =
*   IT_SPECIAL_GROUPS_LVC             =
*   IT_SORT_LVC                       =
*   IT_FILTER_LVC                     =
*   IT_HYPERLINK                      =
*   IS_SEL_HIDE                       =
*   I_DEFAULT                         = 'X'
*   I_SAVE                            = ' '
*   IS_VARIANT                        =
*   IT_EVENTS                         =
*   IT_EVENT_EXIT                     =
*   IS_PRINT_LVC                      =
*   IS_REPREP_ID_LVC                  =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE                 = 0
*   I_HTML_HEIGHT_TOP                 =
*   I_HTML_HEIGHT_END                 =
*   IT_ALV_GRAPHICS                   =
*   IT_EXCEPT_QINFO_LVC               =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
  TABLES
    t_outtab                          = lt_e_project_definition
* EXCEPTIONS
*   PROGRAM_ERROR                     = 1
*   OTHERS                            = 2
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDIF.

1.1.4 其他类查询

代码语言:javascript复制
*&---------------------------------------------------------------------*
*& Report ZLGZBAPI_BUS2001_GET_STATUS
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZLGZBAPI_BUS2001_GET_STATUS.

DATA:
ld_return   TYPE BAPIRETURN1 ,

ld_internalitemnumber   TYPE BAPI_PRPS_KEY-INTERNALITEMNUMBER ,
ld_externalitemnumber   TYPE BAPI_PRPS_KEY-EXTERNALITEMNUMBER .




ld_externalitemnumber = 'LGZXS00212'.

ld_internalitemnumber = ''.






CALL FUNCTION 'BAPI_PS_INITIALIZATION'.

CALL FUNCTION 'BAPI_PROJECT_EXISTENCECHECK'
  EXPORTING
    internalitemnumber =         ld_internalitemnumber
    externalitemnumber =         ld_externalitemnumber
  IMPORTING
    return =                     ld_return

    .  "  BAPI_PROJECT_EXISTENCECHECK

IF SY-SUBRC EQ 0.
  IF ld_return is INITIAL.
    WRITE:/ '存在该WBS,可以获取该WBS的状态了:'.
  ENDIF.
ENDIF.




"第一步:定义变量

DATA:

ld_project_definition   TYPE BAPIPR-PROJECT_DEFINITION ,"项目定义输入条件

it_e_system_status   TYPE STANDARD TABLE OF BAPI_SYSTEM_STATUS ,"系统状态定义
wa_e_system_status   LIKE LINE OF it_e_system_status,


it_e_user_status   TYPE STANDARD TABLE OF BAPI_USER_STATUS ,"用户状态定义
wa_e_user_status   LIKE LINE OF it_e_user_status.


"第二步:初始化变量
ld_project_definition = 'LGZXS002'.




clear ld_return.

CALL FUNCTION 'BAPI_PS_INITIALIZATION'.
CALL FUNCTION 'BAPI_BUS2001_GET_STATUS'
  EXPORTING
    project_definition =         ld_project_definition
  IMPORTING
    return =                     ld_return
 TABLES
   e_system_status =            it_e_system_status
   e_user_status =              it_e_user_status
    .  "  BAPI_BUS2001_GET_STATUS

IF SY-SUBRC EQ 0.

    LOOP AT it_e_system_status into wa_e_system_status.
      IF wa_e_system_status is not INITIAL.
        WRITE:/ '输出系统状态:',wa_e_system_status-SYSTEM_STATUS.
      ENDIF.

    ENDLOOP.


    LOOP AT it_e_user_status into wa_e_user_status.
      IF wa_e_user_status is not INITIAL.
        WRITE:/ '输出用户状态:',wa_e_user_status-USER_STATUS.
      ENDIF.

    ENDLOOP.



ENDIF.

1.2 新增

1.2.1 BAPI_PROJECTDEF_CREATE旧的不可以增强的新增

代码语言:javascript复制

*根据给出的流水号创建项目
  DATA:ls_stru   TYPE bapi_project_definition,
       lt_return TYPE TABLE OF bapi_meth_message WITH HEADER LINE,
       p_message type char1.
*FS上只标注了项目定义、描述、业务范围、成本控制范围、公司代码、工厂、负责人编号




  PARAMETERS p_char1 TYPE char40."项目定义
  PARAMETERS p_char2 TYPE char40."项目描述
  PARAMETERS p_char3 TYPE PROJ-VBUKR."公司代码
  PARAMETERS p_char4 TYPE PROJ-VKOKR."成本控制范围
  PARAMETERS p_char5 TYPE PROJ-PROFL."项目参数文件
  PARAMETERS p_char6 TYPE PROJ-WERKS."工厂
  PARAMETERS p_char7 TYPE PROJ-PRCTR."利润中心



  ls_stru-project_definition = p_char1.
  ls_stru-description        = p_char2.
  ls_stru-comp_code          = p_char3.
  ls_stru-controlling_area   = p_char4.
  ls_stru-project_profile    = p_char5.
  ls_stru-plant              = p_char6.
  ls_stru-PROFIT_CTR         = p_char7 .



  CALL FUNCTION 'BAPI_PROJECTDEF_CREATE'
    EXPORTING
      project_definition_stru = ls_stru
* IMPORTING
*     RETURN                  =
    TABLES
      e_message_table         = lt_return.

  READ TABLE lt_return WITH KEY message_type = 'E'.
  IF sy-subrc EQ 0.
    p_message = 'E'.
    MESSAGE '创建失败' TYPE 'S'.
  ELSE.
    p_message = 'S'.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait = 'X'.
    MESSAGE '创建成功' TYPE 'S'.
  ENDIF.

1.2.2 BAPI_BUS2001_CREATE项目定义新增,可扩展字段

代码语言:javascript复制
*&---------------------------------------------------------------------*
*& Report ZLGZBAPI_BUS2001_CREATE
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zlgzbapi_bus2001_create.



DATA :is_proj TYPE proj.

"第一步,创建变量
  DATA:ls_return      TYPE bapi_meth_message,
       lt_stru_proj_define TYPE TABLE OF bapi_bus2001_new,
       wa_stru_proj_define TYPE  bapi_bus2001_new,


       lt_message TYPE TABLE OF bapiret2,
       wa_message TYPE  bapiret2.

*FS上只标注了项目定义、描述、业务范围、成本控制范围、公司代码、工厂、负责人编号


  "第二步,画参数

  "MOVE-CORRESPONDING ld_e_project_definition TO wa_stru_proj_define.

  PARAMETERS p_char1 TYPE char40 ."项目定义
  PARAMETERS p_char2 TYPE char40."项目描述
  PARAMETERS p_char3 TYPE proj-vbukr DEFAULT '6888'."公司代码
  PARAMETERS p_char4 TYPE proj-vkokr DEFAULT '6888'."成本控制范围
  PARAMETERS p_char5 TYPE proj-profl DEFAULT 'ZPS8802'."项目参数文件
  PARAMETERS p_char6 TYPE bapi_bus2001_new-plant DEFAULT '8810'."工厂
  PARAMETERS p_char7 TYPE bapi_bus2001_new-profit_ctr DEFAULT 'P6888001'."利润中心
  PARAMETERS p_char8 TYPE bapi_bus2001_new-start  DEFAULT '20210208'."开始日期
  PARAMETERS p_char9 TYPE bapi_bus2001_new-finish  DEFAULT '20210828'."结束日期



  wa_stru_proj_define-project_definition = p_char1.
  wa_stru_proj_define-description        = p_char2.
  wa_stru_proj_define-company_code       = p_char3.
  wa_stru_proj_define-controlling_area   = p_char4.
  wa_stru_proj_define-project_profile    = p_char5.
  wa_stru_proj_define-plant              = p_char6.
  wa_stru_proj_define-profit_ctr         = p_char7 .
  wa_stru_proj_define-start              = p_char8 .
  wa_stru_proj_define-finish             = p_char9 .
  "wa_stru_proj_define-time_unit          = ''.

  "第三步,调用创建
  CALL FUNCTION 'BAPI_PS_INITIALIZATION'.
  CALL FUNCTION 'BAPI_BUS2001_CREATE'
    EXPORTING
      i_project_definition       = wa_stru_proj_define
   TABLES
     et_return                  = lt_message
*     EXTENSIONIN                =
*     EXTENSIONOUT               =
            .


  "第四步,做预提交,判断消息是否有A或者E的,表示是异常
LOOP AT lt_message INTO wa_message WHERE type CA 'AE'.


    MESSAGE ID wa_message-id TYPE wa_message-type NUMBER wa_message-number
        INTO wa_message-message
        WITH wa_message-message_v1 wa_message-message_v2
             wa_message-message_v3 wa_message-message_v4.

  ENDLOOP.

"如果loop循环中遍历到A或者E的消息,则subrc是0,执行函数,重新初始化,然后下面check后的subrc,就自动退出主程序了
IF sy-subrc EQ 0.
    CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'.
    CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
      EXPORTING
        i_precommit_ok = 'Y'.

  ENDIF.


"如果subrc是非0,表示未检查到loop循环有A或者E的消息,则执行下面函数来做预提交
 CHECK sy-subrc NE 0.
  CALL FUNCTION 'BAPI_PS_PRECOMMIT'
    TABLES
      et_return = lt_message.





  "第五步,正式提交
  LOOP AT lt_message INTO wa_message WHERE type CA 'AE'.
    MESSAGE ID wa_message-id TYPE wa_message-type NUMBER wa_message-number
        INTO wa_message-message
        WITH wa_message-message_v1 wa_message-message_v2
             wa_message-message_v3 wa_message-message_v4.
  ENDLOOP.


"同理,如果预提交后,有A或者E的消息则做回滚,否则做正式提交
  IF sy-subrc EQ 0.

    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
      IMPORTING
        return = lt_message.

    CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'.

    CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
      EXPORTING
        i_precommit_ok = 'Y'.

  ELSE.


    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait   = 'X'
      IMPORTING
        return = wa_message.



*   项目定义创建成功


  ENDIF.

1.2.3 项目定义屏幕增强CMOD,添加历史项目编号和历史项目名称

1.结构增强,在CI_PROJ

2.查找增强,工具或者小程序

3.定义全局变量,为了方便跟CNCI_PROJ_EXP和CNCI_PROJ_IMP进行交互

4.定义屏幕

定义两个字段

在显示之前,要和项目定义的修改按钮保持同步,如果项目可以修改,那么这两个字段才可以维护

5.传递输入信息到变量中。

此处发现,EXIT_SAPLCJWB_002有3个输入变量,分别为proj、CNCI_PROJ_IMP和SAP_DISPLAY_ONLY

其中proj是把整个项目信息都可以搞过来,如果咱们只处理增强信息的话,完全可以用CNCI_PROJ_IMP变量。

SAP_DISPLAY_ONLY代表的时当前项目总的状态,可修改还是只读。

那么我们改程序,把输入的扩展字段信息放到CNCI_PROJ中,同时把是否只读的状态放到G_DISPLAY中

6.更新变量到输出 此处发现,EXIT_SAPLCJWB_003有2个输出变量,分别为CNCI_PROJ_EXP和FLG_CLR_OK_CODE_EXP(屏幕的操作对象)

把更新后的CNCI_PROJ结果传递回CNCI_PROJ_EXP,用来保存使用。

7设置几个断点,看一下整个添加结构的调用过程:

刚进入客户增强屏幕时,断到EXIT_SAPLCJWB_002,读取数据库的数据到屏幕

继续执行,断到屏幕显示前

已经读取到了

更改字段信息后回车,断在了EXIT_SAPLCJWB_003,将信息更新,类似于保存,但不保存

同时回车为了显示肯定也断在EXIT_SAPLCJWB_002

保存时断在EXIT_SAPLCJWB_003,执行新数据更新数据库

1.2.4 BAPI增强添加历史项目编号和历史项目名称

如果需要添加扩展字段,首先要找到扩展结构,项目定义的扩展结构是BAPI_TE_PROJECT_DEFINITION,一般可以通过函数找到

比原先代码多的部分,贴出来

代码语言:javascript复制
*&---------------------------------------------------------------------*
*& Report  ZLGZBAPI_BUS2001_CREATE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZLGZBAPI_BUS2001_CREATE.



DATA :is_proj TYPE proj.

"第一步,创建变量
  DATA:
        "输入参数,项目定义

       lt_stru_proj_define TYPE TABLE OF bapi_bus2001_new,
       wa_stru_proj_define TYPE  bapi_bus2001_new,


        "输入参数,扩展容器

        lt_EXTENSIONIN type STANDARD TABLE OF BAPIPAREX,
        wa_EXTENSIONIN type BAPIPAREX,

        "输入参数,扩展字段
        wa_BAPI_TE_PROJECT_DEFINITION type BAPI_TE_PROJECT_DEFINITION,"这是多出来的,要定义扩充的结构

        "返回参数
       ls_return      TYPE bapi_meth_message,
       it_BAPIRET2 TYPE TABLE OF bapiret2,
       wa_bapiret2 TYPE  bapiret2.

*FS上只标注了项目定义、描述、业务范围、成本控制范围、公司代码、工厂、负责人编号


  "第二步,画参数

  "MOVE-CORRESPONDING ld_e_project_definition TO wa_stru_proj_define.

  PARAMETERS p_char1 TYPE char40 ."项目定义
  PARAMETERS p_char2 TYPE char40."项目描述
  PARAMETERS p_char3 TYPE proj-vbukr DEFAULT '1000'."公司代码
  PARAMETERS p_char4 TYPE proj-vkokr DEFAULT '1000'."成本控制范围
  PARAMETERS p_char5 TYPE proj-profl DEFAULT '2000'."项目参数文件
  PARAMETERS p_char6 TYPE bapi_bus2001_new-plant DEFAULT '1300'."工厂
  PARAMETERS p_char7 TYPE bapi_bus2001_new-profit_ctr DEFAULT '1300'."利润中心
  PARAMETERS p_char8 TYPE bapi_bus2001_new-start  DEFAULT '20210208'."开始日期
  PARAMETERS p_char9 TYPE bapi_bus2001_new-finish  DEFAULT '20210828'."结束日期
  PARAMETERS p_char10 TYPE BAPI_TE_PROJECT_DEFINITION-ZPSPNR  DEFAULT '12345'."历史项目编号,这是多出来的
  PARAMETERS p_char11 TYPE BAPI_TE_PROJECT_DEFINITION-ZPSPNR1  DEFAULT '上山打老虎'."历史项目名称,这是多出来的

  wa_stru_proj_define-project_definition = p_char1.
  wa_stru_proj_define-description        = p_char2.
  wa_stru_proj_define-company_code       = p_char3.
  wa_stru_proj_define-controlling_area   = p_char4.
  wa_stru_proj_define-project_profile    = p_char5.
  wa_stru_proj_define-plant              = p_char6.
  wa_stru_proj_define-profit_ctr         = p_char7 .
  wa_stru_proj_define-start              = p_char8 .
  wa_stru_proj_define-finish             = p_char9 .
  wa_BAPI_TE_PROJECT_DEFINITION-PROJECT_DEFINITION     = p_char1. "这是多出来的,要赋值项目定义
  wa_BAPI_TE_PROJECT_DEFINITION-ZPSPNR                 = p_char10 ."这是多出来的,要赋值历史项目编号
  wa_BAPI_TE_PROJECT_DEFINITION-ZPSPNR1                 = p_char11 ."这是多出来的,要赋值历史项目名称
  "wa_stru_proj_define-time_unit          = ''.



  CLEAR: wa_EXTENSIONIN.
  wa_EXTENSIONIN-structure = 'BAPI_TE_PROJECT_DEFINITION'."这是多出来的,要把存储扩展信息的结构放到wa_EXTENSIONIN的structure
  wa_EXTENSIONIN-valuepart1 = wa_BAPI_TE_PROJECT_DEFINITION."这是多出来的,要把存储扩展信息全放到wa_EXTENSIONIN的valuepart1
  APPEND wa_EXTENSIONIN to lt_EXTENSIONIN.


  "第三步,调用创建
  CALL FUNCTION 'BAPI_PS_INITIALIZATION'.
  CALL FUNCTION 'BAPI_BUS2001_CREATE'
    EXPORTING
      i_project_definition       = wa_stru_proj_define
   TABLES
     et_return                  = it_BAPIRET2
     EXTENSIONIN                = lt_EXTENSIONIN
*     EXTENSIONOUT               =
            .

"第四步:判断是否有错误消息
LOOP AT it_BAPIRET2 INTO wa_bapiret2 WHERE type CA 'AE'.


    MESSAGE ID wa_bapiret2-id TYPE wa_bapiret2-type NUMBER wa_bapiret2-number
        INTO wa_bapiret2-message
        WITH wa_bapiret2-message_v1 wa_bapiret2-message_v2
             wa_bapiret2-message_v3 wa_bapiret2-message_v4.
    WRITE:/ '创建时报错:',wa_bapiret2-message.

  ENDLOOP.


"第四步:如果有错误消息则退出
  IF sy-subrc EQ 0.

    CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'.

    CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
      EXPORTING
        i_precommit_ok = 'Y'.

  ENDIF.


  CHECK sy-subrc NE 0.

"第四步:没有错误消息则执行预提交
  CALL FUNCTION 'BAPI_PS_PRECOMMIT'
    TABLES
      et_return = it_BAPIRET2.

  LOOP AT it_BAPIRET2 INTO wa_bapiret2 WHERE type CA 'AE'.


    MESSAGE ID wa_bapiret2-id TYPE wa_bapiret2-type NUMBER wa_bapiret2-number
        INTO wa_bapiret2-message
        WITH wa_bapiret2-message_v1 wa_bapiret2-message_v2
             wa_bapiret2-message_v3 wa_bapiret2-message_v4.
    WRITE:/ '预提交时报错:',wa_bapiret2-message.

  ENDLOOP.


"第五步:预提交有错误消息则执行回滚
  IF sy-subrc EQ 0.

    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
      IMPORTING
        return = it_BAPIRET2.

    CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'.

    CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
      EXPORTING
        i_precommit_ok = 'Y'.

  ELSE.
"第五步:预提交无错误消息则执行正式提交
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait   = 'X'
      IMPORTING
        return = wa_BAPIRET2.
    WRITE:/ '带增强字段的项目定义创建成功:',wa_bapiret2-message.
*   WBS元素创建成功


  ENDIF.

1.3 修改

1.4 删除

2 WBS

2.1 查询

2.1.1BAPI_PROJECT_EXISTENCECHECK判断是否存在,并查询BAPI_PROJECT_GETINFO

代码语言:javascript复制
*&---------------------------------------------------------------------*
*& Report ZLGZBAPI_PROJECT01
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZLGZBAPI_PROJECT01.


data: iv_project type BAPIPR-PROJECT_DEFINITION.

data: lt_wbs_element_table TYPE TABLE of BAPI_WBS_ELEMENT_EXP,
      lt_wbs_hierarchie_table TYPE table of BAPI_WBS_HIERARCHIE,
      lt_act_table  TYPE table of  BAPI_NETWORK_ACTIVITY_EXP.


"iv_project = 'LGZXS002'.

PARAMETERS p_p7 TYPE proj-PSPID .

iv_project = p_p7.


CALL FUNCTION 'BAPI_PROJECT_GETINFO'
      EXPORTING
        project_definition     = iv_project
        with_activities        = 'X'
      TABLES
        e_wbs_element_table    = lt_wbs_element_table
        e_wbs_hierarchie_table = lt_wbs_hierarchie_table
        e_activity_table       = lt_act_table.




*调用alv,根据项目定义返回WBS元素

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
 EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                =
*   I_BUFFER_ACTIVE                   =
*   I_CALLBACK_PROGRAM                = ' '
*   I_CALLBACK_PF_STATUS_SET          = ' '
*   I_CALLBACK_USER_COMMAND           = ' '
*   I_CALLBACK_TOP_OF_PAGE            = ' '
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
   I_STRUCTURE_NAME                  = 'BAPI_WBS_ELEMENT_EXP'
*   I_BACKGROUND_ID                   = ' '
*   I_GRID_TITLE                      =
*   I_GRID_SETTINGS                   =
*   IS_LAYOUT_LVC                     =
*   IT_FIELDCAT_LVC                   =
*   IT_EXCLUDING                      =
*   IT_SPECIAL_GROUPS_LVC             =
*   IT_SORT_LVC                       =
*   IT_FILTER_LVC                     =
*   IT_HYPERLINK                      =
*   IS_SEL_HIDE                       =
*   I_DEFAULT                         = 'X'
*   I_SAVE                            = ' '
*   IS_VARIANT                        =
*   IT_EVENTS                         =
*   IT_EVENT_EXIT                     =
*   IS_PRINT_LVC                      =
*   IS_REPREP_ID_LVC                  =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE                 = 0
*   I_HTML_HEIGHT_TOP                 =
*   I_HTML_HEIGHT_END                 =
*   IT_ALV_GRAPHICS                   =
*   IT_EXCEPT_QINFO_LVC               =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
  TABLES
    t_outtab                          = lt_wbs_element_table
* EXCEPTIONS
*   PROGRAM_ERROR                     = 1
*   OTHERS                            = 2
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.






*调用alv,根据项目定义返回WBS元素的上下左右元素

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
 EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                =
*   I_BUFFER_ACTIVE                   =
*   I_CALLBACK_PROGRAM                = ' '
*   I_CALLBACK_PF_STATUS_SET          = ' '
*   I_CALLBACK_USER_COMMAND           = ' '
*   I_CALLBACK_TOP_OF_PAGE            = ' '
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
   I_STRUCTURE_NAME                  = 'BAPI_WBS_HIERARCHIE'
*   I_BACKGROUND_ID                   = ' '
*   I_GRID_TITLE                      =
*   I_GRID_SETTINGS                   =
*   IS_LAYOUT_LVC                     =
*   IT_FIELDCAT_LVC                   =
*   IT_EXCLUDING                      =
*   IT_SPECIAL_GROUPS_LVC             =
*   IT_SORT_LVC                       =
*   IT_FILTER_LVC                     =
*   IT_HYPERLINK                      =
*   IS_SEL_HIDE                       =
*   I_DEFAULT                         = 'X'
*   I_SAVE                            = ' '
*   IS_VARIANT                        =
*   IT_EVENTS                         =
*   IT_EVENT_EXIT                     =
*   IS_PRINT_LVC                      =
*   IS_REPREP_ID_LVC                  =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE                 = 0
*   I_HTML_HEIGHT_TOP                 =
*   I_HTML_HEIGHT_END                 =
*   IT_ALV_GRAPHICS                   =
*   IT_EXCEPT_QINFO_LVC               =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
  TABLES
    t_outtab                          = lt_wbs_hierarchie_table
* EXCEPTIONS
*   PROGRAM_ERROR                     = 1
*   OTHERS                            = 2
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

2.1.2 BAPI_BUS2054_GETDATA根据输入的WBS号查询WBS详情

输入和输出,输入是项目定义(可选)和WBS列表(可选),输出是wbs列表详细信息

代码语言:javascript复制
*&---------------------------------------------------------------------*
*& Report ZLGZBAPI_BUS2054_GETDATA
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZLGZBAPI_BUS2054_GETDATA.







"第一步,定义变量
"输出和输入
DATA:
wa_e_project_wbs   TYPE BAPI_BUS2054_DETAIL ,
lt_e_project_wbs   TYPE STANDARD TABLE OF BAPI_BUS2054_DETAIL ,

"输入参数,项目定义
ld_i_project_definition   TYPE BAPI_BUS2054_DETAIL-PROJECT_DEFINITION ,

"输入参数,WBS信息
wa_i_project_wbs type BAPI_WBS_LIST,
lt_i_project_wbs type STANDARD TABLE OF BAPI_WBS_LIST,
"语言
ld_i_language   TYPE BAPI_BUS2054_DETAIL-LANGU_ISO ,

"最大展示行

ld_i_num type BAPIF4A-MAX_ROWS,


"返回变量
it_et_return   TYPE STANDARD TABLE OF BAPIRET2 ,
wa_et_return   LIKE LINE OF it_et_return,


"扩展的输入变量,扩展字段使用
it_extensionin   TYPE STANDARD TABLE OF BAPIPAREX ,
wa_extensionin   LIKE LINE OF it_extensionin,



"扩展的输出变量,扩展字段使用
it_extensionout   TYPE STANDARD TABLE OF BAPIPAREX ,
wa_extensionout   LIKE LINE OF it_extensionout.



"第二步,赋值

"如果仅指定项目定义,那么展示的WBS详细信息就是项目定义下的所有WBS
ld_i_project_definition = 'LGZXS002'.
"populate fields of struture and append to itab
append wa_et_return to it_et_return.


ld_i_language = 'ZH'.



"如果指定了具体的WBS,那么展示的是具体的WBS信息
wa_i_project_wbs-WBS_ELEMENT = 'LGZXS00212'.
APPEND wa_i_project_wbs to lt_i_project_wbs.



ld_i_num = 100.

"populate fields of struture and append to itab
append wa_extensionin to it_extensionin.


"populate fields of struture and append to itab
append wa_extensionout to it_extensionout.
.



"第三步,调用函数及lvc展示
CALL FUNCTION 'BAPI_BUS2054_GETDATA'
 EXPORTING
*   I_PROJECT_DEFINITION       = ld_i_project_definition
   I_LANGUAGE                 = ld_i_language
   I_MAX_ROWS                 = ld_i_num
 TABLES
   IT_WBS_ELEMENT             =  lt_i_project_wbs
   ET_WBS_ELEMENT             = lt_e_project_wbs
   ET_RETURN                  = it_et_return
*   EXTENSIONIN                =
*   EXTENSIONOUT               =
          .





IF SY-SUBRC EQ 0.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
 EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                =
*   I_BUFFER_ACTIVE                   =
*   I_CALLBACK_PROGRAM                = ' '
*   I_CALLBACK_PF_STATUS_SET          = ' '
*   I_CALLBACK_USER_COMMAND           = ' '
*   I_CALLBACK_TOP_OF_PAGE            = ' '
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
   I_STRUCTURE_NAME                  = 'BAPI_BUS2054_DETAIL'
*   I_BACKGROUND_ID                   = ' '
*   I_GRID_TITLE                      =
*   I_GRID_SETTINGS                   =
*   IS_LAYOUT_LVC                     =
*   IT_FIELDCAT_LVC                   =
*   IT_EXCLUDING                      =
*   IT_SPECIAL_GROUPS_LVC             =
*   IT_SORT_LVC                       =
*   IT_FILTER_LVC                     =
*   IT_HYPERLINK                      =
*   IS_SEL_HIDE                       =
*   I_DEFAULT                         = 'X'
*   I_SAVE                            = ' '
*   IS_VARIANT                        =
*   IT_EVENTS                         =
*   IT_EVENT_EXIT                     =
*   IS_PRINT_LVC                      =
*   IS_REPREP_ID_LVC                  =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE                 = 0
*   I_HTML_HEIGHT_TOP                 =
*   I_HTML_HEIGHT_END                 =
*   IT_ALV_GRAPHICS                   =
*   IT_EXCEPT_QINFO_LVC               =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
  TABLES
    t_outtab                          = lt_e_project_wbs
* EXCEPTIONS
*   PROGRAM_ERROR                     = 1
*   OTHERS                            = 2
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDIF.

2.1.3 BAPI_BUS2054_GET_STATUS 获取WBS状态

输入参数是WBS列表(必输) 输出参数是系统状态、用户状态以及错误消息(可选)

代码语言:javascript复制
*&---------------------------------------------------------------------*
*& Report ZLGZBAPI_BUS2054_GET_STATUS
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZLGZBAPI_BUS2054_GET_STATUS.










"第一步:定义变量

DATA:


lt_project_wbs TYPE STANDARD TABLE OF BAPI_WBS_ELEMENTS ,"WBS列表
wa_project_wbs like line of lt_project_wbs,



it_e_system_status   TYPE STANDARD TABLE OF BAPI_WBS_SYSTEM_STATUS ,"系统状态定义
wa_e_system_status   LIKE LINE OF it_e_system_status,


it_e_user_status   TYPE STANDARD TABLE OF BAPI_WBS_USER_STATUS ,"用户状态定义
wa_e_user_status   LIKE LINE OF it_e_user_status,



ld_return type BAPIRETURN1,"定义返回变量


it_BAPI_STATUS_RESULT type STANDARD TABLE OF BAPI_STATUS_RESULT."设置/重置状态错误消息内表,如果报错该内表会有值

"第二步:初始化变量

wa_project_wbs-WBS_ELEMENT = 'LGZXS00212'.
APPEND wa_project_wbs to lt_project_wbs.



clear ld_return.

CALL FUNCTION 'BAPI_PS_INITIALIZATION'.

CALL FUNCTION 'BAPI_BUS2054_GET_STATUS'
 IMPORTING
   RETURN                = ld_return
  TABLES
    i_wbs_elements        = lt_project_wbs
    E_SYSTEM_STATUS       = it_e_system_status
    E_USER_STATUS         = it_e_user_status
   E_RESULT              = it_BAPI_STATUS_RESULT
          .







IF SY-SUBRC EQ 0.

    LOOP AT it_e_system_status into wa_e_system_status.
      IF wa_e_system_status is not INITIAL.
        WRITE:/ '输出系统状态:',wa_e_system_status-SYSTEM_STATUS.
      ENDIF.

    ENDLOOP.


    LOOP AT it_e_user_status into wa_e_user_status.
      IF wa_e_user_status is not INITIAL.
        WRITE:/ '输出用户状态:',wa_e_user_status-USER_STATUS.
      ENDIF.

    ENDLOOP.



ENDIF.

2.2 新增

2.2.1 BAPI_BUS2054_CREATE_MULTI只创建WBS,可维护增强字段

输入输出:输入是项目定义(必选)、项目WBS元素、WBS的up和left

代码语言:javascript复制
*&---------------------------------------------------------------------*
*& Report ZLGZBAPI_BUS2054_CREATE_MULTI
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZLGZBAPI_BUS2054_CREATE_MULTI.



"第一步:定义变量
data:

ld_PROJECT_DEFINITION type BAPI_BUS2001_NEW-PROJECT_DEFINITION,"项目定义,要挂在哪个项目上

"定义WBS详情
it_BAPI_BUS2054_NEW type STANDARD TABLE OF BAPI_BUS2054_NEW,
wa_BAPI_BUS2054_NEW type BAPI_BUS2054_NEW,


"定义返回参数

it_BAPIRET2 type STANDARD TABLE OF BAPIRET2,
wa_BAPIRET2 type BAPIRET2.


"第二步:赋值

"项目定义
ld_PROJECT_DEFINITION = 'LGZXS002'.


"WBS

    wa_BAPI_BUS2054_NEW-wbs_element                    = 'LGZXS00217'.     "工作分解结构元素 (WBS 元素)
    wa_BAPI_BUS2054_NEW-description                    = '结项'.     "PS: 短描述 (第一行文本)
    wa_BAPI_BUS2054_NEW-responsible_no                 = ''.         "负责人编号
    wa_BAPI_BUS2054_NEW-profit_ctr                     = 'P6888001'.     "利润中心
    wa_BAPI_BUS2054_NEW-proj_type                      = ''.     "项目类型
    wa_BAPI_BUS2054_NEW-WBS_PLANNING_ELEMENT           = 'X'.
    wa_BAPI_BUS2054_NEW-wbs_account_assignment_element = 'X'.     "标志:科目分配元素
    wa_BAPI_BUS2054_NEW-wbs_billing_element            = 'X'.     "标识符: 开票元素
    wa_BAPI_BUS2054_NEW-wbs_left                       = 'LGZXS00215'."左侧WBS
    wa_BAPI_BUS2054_NEW-wbs_up                         = 'LGZXS0021'.  "上级WBS
"    wa_BAPI_BUS2054_NEW-user_field_char20_1            = gs_wbs-usr00.     "业务类别
"    wa_BAPI_BUS2054_NEW-user_field_char20_2            = gs_wbs-usr01.     "CRM 商机编码
 "   wa_BAPI_BUS2054_NEW-user_field_char10_1            = 'X'.              "产品
    wa_BAPI_BUS2054_NEW-statistical                    = ''.     "统计
    wa_BAPI_BUS2054_NEW-wbs_cctr_posted_actual         = ''.     "CCtr 过账

  APPEND wa_BAPI_BUS2054_NEW TO it_BAPI_BUS2054_NEW.




"第三步:调用函数

  CALL FUNCTION 'BAPI_PS_INITIALIZATION'.

  CALL FUNCTION 'BAPI_BUS2054_CREATE_MULTI'
    EXPORTING
      i_project_definition       = ld_PROJECT_DEFINITION
    tables
      it_wbs_element             = it_BAPI_BUS2054_NEW
     ET_RETURN                  = it_BAPIRET2
*     EXTENSIONIN                =
*     EXTENSIONOUT               =
.


"第四步:判断是否有错误消息
LOOP AT it_BAPIRET2 INTO wa_bapiret2 WHERE type CA 'AE'.


    MESSAGE ID wa_bapiret2-id TYPE wa_bapiret2-type NUMBER wa_bapiret2-number
        INTO wa_bapiret2-message
        WITH wa_bapiret2-message_v1 wa_bapiret2-message_v2
             wa_bapiret2-message_v3 wa_bapiret2-message_v4.
    WRITE:/ '创建时报错:',wa_bapiret2-message.

  ENDLOOP.


"第四步:如果有错误消息则退出
  IF sy-subrc EQ 0.

    CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'.

    CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
      EXPORTING
        i_precommit_ok = 'Y'.

  ENDIF.


  CHECK sy-subrc NE 0.

"第四步:没有错误消息则执行预提交
  CALL FUNCTION 'BAPI_PS_PRECOMMIT'
    TABLES
      et_return = it_BAPIRET2.

  LOOP AT it_BAPIRET2 INTO wa_bapiret2 WHERE type CA 'AE'.


    MESSAGE ID wa_bapiret2-id TYPE wa_bapiret2-type NUMBER wa_bapiret2-number
        INTO wa_bapiret2-message
        WITH wa_bapiret2-message_v1 wa_bapiret2-message_v2
             wa_bapiret2-message_v3 wa_bapiret2-message_v4.
    WRITE:/ '预提交时报错:',wa_bapiret2-message.

  ENDLOOP.


"第五步:预提交有错误消息则执行回滚
  IF sy-subrc EQ 0.

    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
      IMPORTING
        return = it_BAPIRET2.

    CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'.

    CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
      EXPORTING
        i_precommit_ok = 'Y'.

  ELSE.
"第五步:预提交无错误消息则执行正式提交
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait   = 'X'
      IMPORTING
        return = wa_BAPIRET2.
    WRITE:/ 'WBS创建成功:',wa_bapiret2-message.
*   WBS元素创建成功


  ENDIF.

2.1.5 BAPI_PROJECT_SAVEREPLICA |复制工作分解结构 (ALE),可增强

先略过

2.3 修改

2.3.1 BAPI_BUS2054_SET_STATUS |设置/重置 BUS2054 状态 (工作分解结构)|

输入输出:

输入是系统状态列表(可选)和用户状态列表(可选),

输出是设置是否成功

2.3.2 BAPI_BUS2054_CHANGE_MULTI |使用 BAPI 更改 WBS 要素|

输入:项目定义(必选)、WBS内容(要修改的)、修改标识(要修改的)

代码语言:javascript复制
*&---------------------------------------------------------------------*
*& Report ZLGZBAPI_BUS2054_CHANGE_MULTI
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZLGZBAPI_BUS2054_CHANGE_MULTI.





"第一步,定义更改变量


data:
"项目定义

ld_i_project_definition type BAPI_BUS2001_NEW-PROJECT_DEFINITION,

"要更新的WBS信息
wa_e_project_wbs_chg   TYPE BAPI_BUS2054_CHG ,
lt_e_project_wbs_chg   TYPE STANDARD TABLE OF BAPI_BUS2054_CHG ,

"要更新那些WBS字段
wa_e_project_wbs_upd   TYPE BAPI_BUS2054_UPD ,
lt_e_project_wbs_upd   TYPE STANDARD TABLE OF BAPI_BUS2054_UPD,

"定义返回参数

it_BAPIRET2 type STANDARD TABLE OF BAPIRET2,
wa_BAPIRET2 type BAPIRET2.



"第二步,赋值

  ld_i_project_definition = 'LGZXS002'.
  "MOVE-CORRESPONDING  wa_e_project_wbs to wa_e_project_wbs_chg."通过查询的WBS拷贝变量
  wa_e_project_wbs_chg-WBS_ELEMENT = 'LGZXS00217'.
  wa_e_project_wbs_chg-DESCRIPTION ='完工结项1'."更改描述

  "设置更新标志
  wa_e_project_wbs_upd-WBS_ELEMENT = wa_e_project_wbs_chg-WBS_ELEMENT.
  wa_e_project_wbs_upd-DESCRIPTION = 'X'.

  APPEND wa_e_project_wbs_chg to lt_e_project_wbs_chg.
  APPEND wa_e_project_wbs_upd to lt_e_project_wbs_upd.



"第三步,调用
CALL FUNCTION 'BAPI_PS_INITIALIZATION'.

CALL FUNCTION 'BAPI_BUS2054_CHANGE_MULTI'
  EXPORTING
    i_project_definition        = ld_i_project_definition
  tables
    it_wbs_element              = lt_e_project_wbs_chg
    it_update_wbs_element       = lt_e_project_wbs_upd
   ET_RETURN                   = it_BAPIRET2
*   EXTENSIONIN                 =
*   EXTENSIONOUT                =
          .



"第四步:判断是否有错误消息
LOOP AT it_BAPIRET2 INTO wa_bapiret2 WHERE type CA 'AE'.


    MESSAGE ID wa_bapiret2-id TYPE wa_bapiret2-type NUMBER wa_bapiret2-number
        INTO wa_bapiret2-message
        WITH wa_bapiret2-message_v1 wa_bapiret2-message_v2
             wa_bapiret2-message_v3 wa_bapiret2-message_v4.
    WRITE:/ '修改时报错:',wa_bapiret2-message.

  ENDLOOP.


"第四步:如果有错误消息则退出
  IF sy-subrc EQ 0.

    CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'.

    CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
      EXPORTING
        i_precommit_ok = 'Y'.

  ENDIF.


  CHECK sy-subrc NE 0.

"第四步:没有错误消息则执行预提交
  CALL FUNCTION 'BAPI_PS_PRECOMMIT'
    TABLES
      et_return = it_BAPIRET2.

  LOOP AT it_BAPIRET2 INTO wa_bapiret2 WHERE type CA 'AE'.


    MESSAGE ID wa_bapiret2-id TYPE wa_bapiret2-type NUMBER wa_bapiret2-number
        INTO wa_bapiret2-message
        WITH wa_bapiret2-message_v1 wa_bapiret2-message_v2
             wa_bapiret2-message_v3 wa_bapiret2-message_v4.
    WRITE:/ '预提交时报错:',wa_bapiret2-message.

  ENDLOOP.


"第五步:预提交有错误消息则执行回滚
  IF sy-subrc EQ 0.

    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
      IMPORTING
        return = it_BAPIRET2.

    CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'.

    CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
      EXPORTING
        i_precommit_ok = 'Y'.

  ELSE.
"第五步:预提交无错误消息则执行正式提交
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait   = 'X'
      IMPORTING
        return = wa_BAPIRET2.

    WRITE:/ 'WBS修改成功:',wa_bapiret2-message.
*   WBS元素创建成功


  ENDIF.


2.3.3 BAPI_BUS2054_DELETE_MULTI|使用 BAPI 删除 WBS 要素|

代码语言:javascript复制
*&---------------------------------------------------------------------*
*& Report ZLGZBAPI_BUS2054_DELETE_MULTI
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZLGZBAPI_BUS2054_DELETE_MULTI.



"第一步,定义更改变量


data:
"项目定义

ld_i_project_definition type BAPI_BUS2001_NEW-PROJECT_DEFINITION,

"要删除的WBS信息
wa_e_project_wbs_del   TYPE BAPI_WBS_LIST ,
lt_e_project_wbs_del   TYPE STANDARD TABLE OF BAPI_WBS_LIST,


"定义返回参数

it_BAPIRET2 type STANDARD TABLE OF BAPIRET2,
wa_BAPIRET2 type BAPIRET2.



"第二步,赋值

  ld_i_project_definition = 'LGZXS002'.
  "MOVE-CORRESPONDING  wa_e_project_wbs to wa_e_project_wbs_chg."通过查询的WBS拷贝变量
  wa_e_project_wbs_del-WBS_ELEMENT = 'LGZXS00217'.

  APPEND wa_e_project_wbs_del to lt_e_project_wbs_del.




"第三步,调用
CALL FUNCTION 'BAPI_PS_INITIALIZATION'.


CALL FUNCTION 'BAPI_BUS2054_DELETE_MULTI'
  EXPORTING
    i_project_definition        = ld_i_project_definition
  tables
    it_delete_wbs_element       = lt_e_project_wbs_del
   ET_RETURN                   = it_BAPIRET2
*   EXTENSIONIN                 =
*   EXTENSIONOUT                =
          .




"第四步:判断是否有错误消息
LOOP AT it_BAPIRET2 INTO wa_bapiret2 WHERE type CA 'AE'.


    MESSAGE ID wa_bapiret2-id TYPE wa_bapiret2-type NUMBER wa_bapiret2-number
        INTO wa_bapiret2-message
        WITH wa_bapiret2-message_v1 wa_bapiret2-message_v2
             wa_bapiret2-message_v3 wa_bapiret2-message_v4.
    WRITE:/ '修改时报错:',wa_bapiret2-message.

  ENDLOOP.


"第四步:如果有错误消息则退出
  IF sy-subrc EQ 0.

    CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'.

    CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
      EXPORTING
        i_precommit_ok = 'Y'.

  ENDIF.


  CHECK sy-subrc NE 0.

"第四步:没有错误消息则执行预提交
  CALL FUNCTION 'BAPI_PS_PRECOMMIT'
    TABLES
      et_return = it_BAPIRET2.

  LOOP AT it_BAPIRET2 INTO wa_bapiret2 WHERE type CA 'AE'.


    MESSAGE ID wa_bapiret2-id TYPE wa_bapiret2-type NUMBER wa_bapiret2-number
        INTO wa_bapiret2-message
        WITH wa_bapiret2-message_v1 wa_bapiret2-message_v2
             wa_bapiret2-message_v3 wa_bapiret2-message_v4.
    WRITE:/ '预提交时报错:',wa_bapiret2-message.

  ENDLOOP.


"第五步:预提交有错误消息则执行回滚
  IF sy-subrc EQ 0.

    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
      IMPORTING
        return = it_BAPIRET2.

    CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'.

    CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
      EXPORTING
        i_precommit_ok = 'Y'.

  ELSE.
"第五步:预提交无错误消息则执行正式提交
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait   = 'X'
      IMPORTING
        return = wa_BAPIRET2.

    WRITE:/ 'WBS修改成功:',wa_bapiret2-message.
*   WBS元素创建成功


  ENDIF.

3 网络

3.1 网络查询

3.1.1 BAPI_NETWORK_GETLIST查询网络清单

输入:最大显示(可选)、网络编号range(可选)、工厂range(可选)、短文本range(可选) 输出:网络清单(必选)

代码语言:javascript复制
*&---------------------------------------------------------------------*
*& Report ZLGZBAPI_NETWORK_GETLIST
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zlgzbapi_network_getlist.

"第一步:定义变量
DATA:
      ld_i_MAX_ROWS LIKE bapif4a-max_rows,"输入最大的显示行
      ld_e_BAPIRET2 LIKE bapiret2,"输出执行日志
      lt_BAPI_NETWORK_LIST_EXP LIKE STANDARD TABLE OF bapi_network_list_exp,"定义输出网络清单
      wa_BAPI_NETWORK_LIST_EXP LIKE  bapi_network_list_exp."定义输出网络清单



"第二步:变量赋值
      ld_i_MAX_ROWS = 100.


"第三步:调用函数
      CALL FUNCTION 'BAPI_NETWORK_GETLIST'
       EXPORTING
         max_rows               = ld_i_MAX_ROWS
       IMPORTING
         return                 = ld_e_BAPIRET2
        tables
          network_list           = lt_BAPI_NETWORK_LIST_EXP
*         NETWORK_RANGE          =
*         PLANT_RANGE            =
*         SHORT_TEXT_RANGE       =
                .


"第四步:ALV显示

       CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
 EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                =
*   I_BUFFER_ACTIVE                   =
*   I_CALLBACK_PROGRAM                = ' '
*   I_CALLBACK_PF_STATUS_SET          = ' '
*   I_CALLBACK_USER_COMMAND           = ' '
*   I_CALLBACK_TOP_OF_PAGE            = ' '
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
   I_STRUCTURE_NAME                  = 'bapi_network_list_exp'
*   I_BACKGROUND_ID                   = ' '
*   I_GRID_TITLE                      =
*   I_GRID_SETTINGS                   =
*   IS_LAYOUT_LVC                     =
*   IT_FIELDCAT_LVC                   =
*   IT_EXCLUDING                      =
*   IT_SPECIAL_GROUPS_LVC             =
*   IT_SORT_LVC                       =
*   IT_FILTER_LVC                     =
*   IT_HYPERLINK                      =
*   IS_SEL_HIDE                       =
*   I_DEFAULT                         = 'X'
*   I_SAVE                            = ' '
*   IS_VARIANT                        =
*   IT_EVENTS                         =
*   IT_EVENT_EXIT                     =
*   IS_PRINT_LVC                      =
*   IS_REPREP_ID_LVC                  =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE                 = 0
*   I_HTML_HEIGHT_TOP                 =
*   I_HTML_HEIGHT_END                 =
*   IT_ALV_GRAPHICS                   =
*   IT_EXCEPT_QINFO_LVC               =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
  TABLES
    t_outtab                          = lt_BAPI_NETWORK_LIST_EXP
* EXCEPTIONS
*   PROGRAM_ERROR                     = 1
*   OTHERS                            = 2
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.

3.1.2 BAPI_BUS2002_GETDATA |网络抬头的详细数据 |

输入:网络号(必选)、语言(可选) 输出:网络详细结构(必选)

先读取网络清单,根据网络清单形成alv

代码语言:javascript复制
*&---------------------------------------------------------------------*
*& Report ZLGZBAPI_BUS2002_GETDATA
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZLGZBAPI_BUS2002_GETDATA.

"第一步:定义变量
DATA:
      ld_i_MAX_ROWS LIKE bapif4a-max_rows,"输入最大的显示行

      ld_e_BAPIRET2 LIKE bapiret2,
      lt_e_BAPIRET2 like STANDARD TABLE OF BAPIRET2,

      lt_BAPI_NETWORK_LIST_EXP LIKE STANDARD TABLE OF bapi_network_list_exp,"定义输出网络清单
      wa_BAPI_NETWORK_LIST_EXP LIKE  bapi_network_list_exp."定义输出网络清单


      "详细网络信息对象,不是简单的清单那么少的信息
data:
      wa_BAPI_BUS2002_DETAIL type BAPI_BUS2002_DETAIL,
      it_BAPI_BUS2002_DETAIL type STANDARD TABLE OF BAPI_BUS2002_DETAIL.

      "定义

"第二步:变量赋值
      ld_i_MAX_ROWS = 100.


"第三步:调用函数
      CALL FUNCTION 'BAPI_NETWORK_GETLIST'
       EXPORTING
         max_rows               = ld_i_MAX_ROWS
       IMPORTING
         return                 = ld_e_BAPIRET2
        tables
          network_list           = lt_BAPI_NETWORK_LIST_EXP
*         NETWORK_RANGE          =
*         PLANT_RANGE            =
*         SHORT_TEXT_RANGE       =
.


"第四步:根据网络清单,调用具体网络信息

IF sy-subrc = 0.
  LOOP AT lt_BAPI_NETWORK_LIST_EXP INTO wa_BAPI_NETWORK_LIST_EXP.


    "调用获取数据
    CALL FUNCTION 'BAPI_BUS2002_GETDATA'
  EXPORTING
    i_number           = wa_BAPI_NETWORK_LIST_EXP-NETWORK
*   I_LANGUAGE         =
 IMPORTING
   E_NETWORK          = wa_BAPI_BUS2002_DETAIL
 TABLES
   ET_RETURN          = lt_e_BAPIRET2
*   EXTENSIONIN        =
*   EXTENSIONOUT       =
.
    APPEND wa_BAPI_BUS2002_DETAIL to it_BAPI_BUS2002_DETAIL.
    clear wa_BAPI_NETWORK_LIST_EXP.
  ENDLOOP.

ENDIF.



"第五步:ALV显示

       CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
 EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                =
*   I_BUFFER_ACTIVE                   =
*   I_CALLBACK_PROGRAM                = ' '
*   I_CALLBACK_PF_STATUS_SET          = ' '
*   I_CALLBACK_USER_COMMAND           = ' '
*   I_CALLBACK_TOP_OF_PAGE            = ' '
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
   I_STRUCTURE_NAME                  = 'BAPI_BUS2002_DETAIL'
*   I_BACKGROUND_ID                   = ' '
*   I_GRID_TITLE                      =
*   I_GRID_SETTINGS                   =
*   IS_LAYOUT_LVC                     =
*   IT_FIELDCAT_LVC                   =
*   IT_EXCLUDING                      =
*   IT_SPECIAL_GROUPS_LVC             =
*   IT_SORT_LVC                       =
*   IT_FILTER_LVC                     =
*   IT_HYPERLINK                      =
*   IS_SEL_HIDE                       =
*   I_DEFAULT                         = 'X'
*   I_SAVE                            = ' '
*   IS_VARIANT                        =
*   IT_EVENTS                         =
*   IT_EVENT_EXIT                     =
*   IS_PRINT_LVC                      =
*   IS_REPREP_ID_LVC                  =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE                 = 0
*   I_HTML_HEIGHT_TOP                 =
*   I_HTML_HEIGHT_END                 =
*   IT_ALV_GRAPHICS                   =
*   IT_EXCEPT_QINFO_LVC               =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
  TABLES
    t_outtab                          = it_BAPI_BUS2002_DETAIL
* EXCEPTIONS
*   PROGRAM_ERROR                     = 1
*   OTHERS                            = 2
          .
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.


          .

3.1.3 BAPI_NETWORK_GETDETAIL |读取网络的明细信息(包括所有对象),只能查询一个网络

输入:网络号(必选)、不返回网络(可选)、不返回活动(可选)、不返回关系(可选)、不返回活动元素(可选)、不返回活动里程碑(可选)、不返回物料组件(可选)

输出:网络、活动、关系、活动元素、里程碑、物料组件

代码语言:javascript复制
*&---------------------------------------------------------------------*
*& Report ZLGZBAPI_NETWORK_GETDETAIL
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZLGZBAPI_NETWORK_GETDETAIL.


DATA:

"返回参数
ld_return   TYPE BAPIRETURN1 ,


"网络号
ld_number   TYPE BAPI_NETWORK_LIST-NETWORK ,



"是否返回网络
ld_i_without_network   TYPE BAPINWGI-WO_NETWORK ,
"是否返回作业
ld_i_without_network_activity   TYPE BAPINWGI-WO_NETWORK_ACT ,
"是否返回活动关系
ld_i_without_relation   TYPE BAPINWGI-WO_RELATION ,
"是否返回作业元素
ld_i_without_activity_element   TYPE BAPINWGI-WO_ACT_ELEMENT ,
"是否返回里程碑信息
ld_i_without_activity_mistone   TYPE BAPINWGI-WO_ACT_MILESTONE ,
"是否返回物料组件信息
ld_i_without_component   TYPE BAPINWGI-WO_COMPONENT ,



"返回的网络信息
it_e_network   TYPE STANDARD TABLE OF BAPI_NETWORK_EXP ,
wa_e_network   LIKE LINE OF it_e_network,

"返回的作业信息
it_e_activity   TYPE STANDARD TABLE OF BAPI_NETWORK_ACTIVITY_EXP ,
wa_e_activity   LIKE LINE OF it_e_activity,


"返回的活动关系
it_e_relation   TYPE STANDARD TABLE OF BAPI_NETWORK_RELATION_EXP ,
wa_e_relation   LIKE LINE OF it_e_relation,

"返回的里程碑信息
it_e_message_table   TYPE STANDARD TABLE OF BAPI_METH_MESSAGE ,
wa_e_message_table   LIKE LINE OF it_e_message_table,

"返回的作业元素信息
it_e_activity_element   TYPE STANDARD TABLE OF BAPI_ACT_ELEMENT_EXP ,
wa_e_activity_element   LIKE LINE OF it_e_activity_element,

"返回的里程碑信息信息
it_e_activity_milestone   TYPE STANDARD TABLE OF BAPI_ACT_MILESTONE_EXP ,
wa_e_activity_milestone   LIKE LINE OF it_e_activity_milestone,
"返回的物料组件信息
it_e_component   TYPE STANDARD TABLE OF BAPI_COMPONENT_EXP ,
wa_e_component   LIKE LINE OF it_e_component.



ld_number = '4500245'.

"populate fields of struture and append to itab
append wa_e_network to it_e_network.

ld_i_without_network = 'X'.

"populate fields of struture and append to itab
append wa_e_activity to it_e_activity.

ld_i_without_network_activity = 'X'.

"populate fields of struture and append to itab
append wa_e_relation to it_e_relation.


ld_i_without_relation = ''.

"populate fields of struture and append to itab
append wa_e_message_table to it_e_message_table.


ld_i_without_activity_element = ''.

"populate fields of struture and append to itab
append wa_e_activity_element to it_e_activity_element.

ld_i_without_activity_mistone = ''.

"populate fields of struture and append to itab
append wa_e_activity_milestone to it_e_activity_milestone.

ld_i_without_component = ''.

"populate fields of struture and append to itab
append wa_e_component to it_e_component.


.

CALL FUNCTION 'BAPI_NETWORK_GETDETAIL'
  EXPORTING
    number =                     ld_number
   i_without_network =          ld_i_without_network
   i_without_network_activity =    ld_i_without_network_activity
*   i_without_relation =         ld_i_without_relation
*   i_without_activity_element =    ld_i_without_activity_element
*   i_without_activity_milestone =    ld_i_without_activity_milestone
*   i_without_component =        ld_i_without_component
  IMPORTING
    return =                     ld_return
 TABLES
   e_network =                  it_e_network
   e_activity =                 it_e_activity
   e_relation =                 it_e_relation
   e_message_table =            it_e_message_table
   e_activity_element =         it_e_activity_element
   e_activity_milestone =       it_e_activity_milestone
   e_component =                it_e_component
    .  "  BAPI_NETWORK_GETDETAIL

IF SY-SUBRC EQ 0.
  "All OK
ENDIF.

BREAK-POINT.

3.1.4 BAPI_NETWORK_GETINFO |读取网络的详细信息 (包括所有对象) |可以查询多个网络

输入:网络号列表(必选)、不返回网络(可选)、不返回活动(可选)、不返回关系(可选)、不返回活动元素(可选)、不返回活动里程碑(可选)、不返回物料组件(可选)

输出:网络、活动、关系、活动元素、里程碑、物料组件

代码语言:javascript复制
*&---------------------------------------------------------------------*
*& Report ZLGZBAPI_NETWORK_GETINFO
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZLGZBAPI_NETWORK_GETINFO.




DATA:

"返回参数
ld_return   TYPE BAPIRETURN1 ,



"网络号内表
it_BAPI_NETWORK_LIST type STANDARD TABLE OF BAPI_NETWORK_LIST,
wa_BAPI_NETWORK_LIST type  BAPI_NETWORK_LIST,



"是否返回网络
ld_i_without_network   TYPE BAPINWGI-WO_NETWORK ,
"是否返回作业
ld_i_without_network_activity   TYPE BAPINWGI-WO_NETWORK_ACT ,
"是否返回活动关系
ld_i_without_relation   TYPE BAPINWGI-WO_RELATION ,
"是否返回作业元素
ld_i_without_activity_element   TYPE BAPINWGI-WO_ACT_ELEMENT ,
"是否返回里程碑信息
ld_i_without_activity_mistone   TYPE BAPINWGI-WO_ACT_MILESTONE ,
"是否返回物料组件信息
ld_i_without_component   TYPE BAPINWGI-WO_COMPONENT ,



"返回的网络信息
it_e_network   TYPE STANDARD TABLE OF BAPI_NETWORK_EXP ,
wa_e_network   LIKE LINE OF it_e_network,

"返回的作业信息
it_e_activity   TYPE STANDARD TABLE OF BAPI_NETWORK_ACTIVITY_EXP ,
wa_e_activity   LIKE LINE OF it_e_activity,


"返回的活动关系
it_e_relation   TYPE STANDARD TABLE OF BAPI_NETWORK_RELATION_EXP ,
wa_e_relation   LIKE LINE OF it_e_relation,

"返回的里程碑信息
it_e_message_table   TYPE STANDARD TABLE OF BAPI_METH_MESSAGE ,
wa_e_message_table   LIKE LINE OF it_e_message_table,

"返回的作业元素信息
it_e_activity_element   TYPE STANDARD TABLE OF BAPI_ACT_ELEMENT_EXP ,
wa_e_activity_element   LIKE LINE OF it_e_activity_element,

"返回的里程碑信息信息
it_e_activity_milestone   TYPE STANDARD TABLE OF BAPI_ACT_MILESTONE_EXP ,
wa_e_activity_milestone   LIKE LINE OF it_e_activity_milestone,
"返回的物料组件信息
it_e_component   TYPE STANDARD TABLE OF BAPI_COMPONENT_EXP ,
wa_e_component   LIKE LINE OF it_e_component.



wa_BAPI_NETWORK_LIST-NETWORK = '4500245'.
APPEND wa_BAPI_NETWORK_LIST to it_BAPI_NETWORK_LIST.
wa_BAPI_NETWORK_LIST-NETWORK = '4500249'.
APPEND wa_BAPI_NETWORK_LIST to it_BAPI_NETWORK_LIST.


"populate fields of struture and append to itab
append wa_e_network to it_e_network.

ld_i_without_network = 'X'.

"populate fields of struture and append to itab
append wa_e_activity to it_e_activity.

ld_i_without_network_activity = 'X'.

"populate fields of struture and append to itab
append wa_e_relation to it_e_relation.


ld_i_without_relation = ''.

"populate fields of struture and append to itab
append wa_e_message_table to it_e_message_table.


ld_i_without_activity_element = ''.

"populate fields of struture and append to itab
append wa_e_activity_element to it_e_activity_element.

ld_i_without_activity_mistone = ''.

"populate fields of struture and append to itab
append wa_e_activity_milestone to it_e_activity_milestone.

ld_i_without_component = ''.

"populate fields of struture and append to itab
append wa_e_component to it_e_component.


.


CALL FUNCTION 'BAPI_NETWORK_GETINFO'
* EXPORTING
*   I_WITHOUT_NETWORK                  = ld_i_without_network
*   I_WITHOUT_NETWORK_ACTIVITY         = ld_i_without_network_activity
*   I_WITHOUT_RELATION                 =
*   I_WITHOUT_ACTIVITY_ELEMENT         =
*   I_WITHOUT_ACTIVITY_MILESTONE       =
*   I_WITHOUT_COMPONENT                =
 IMPORTING
   RETURN                             = ld_return
  TABLES
    i_network_list                     =  it_BAPI_NETWORK_LIST "输入网络号的清单列表
   E_NETWORK                          = it_e_network
   E_ACTIVITY                         = it_e_activity
   E_RELATION                         = it_e_relation
   E_MESSAGE_TABLE                    = it_e_message_table
   E_ACTIVITY_ELEMENT                 = it_e_activity_element
   E_ACTIVITY_MILESTONE               = it_e_activity_milestone
   E_COMPONENT                        = it_e_component
          .



IF SY-SUBRC EQ 0.
  "All OK
ENDIF.

BREAK-POINT.

3.2 网络新增

3.2.1 BAPI_BUS2002_CREATE |创建网络 |

输入:网络对象信息

输出:

代码语言:javascript复制
*&---------------------------------------------------------------------*
*& Report ZLGZBAPI_BUS2002_CREATE
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZLGZBAPI_BUS2002_CREATE.


"定义返回参数
data:


it_BAPI_BUS2002_NEW type STANDARD TABLE OF BAPI_BUS2002_NEW,
wa_BAPI_BUS2002_NEW type BAPI_BUS2002_NEW,

it_BAPIRET2 type STANDARD TABLE OF BAPIRET2,
wa_BAPIRET2 type BAPIRET2.

 CLEAR : wa_BAPI_BUS2002_NEW.
  wa_BAPI_BUS2002_NEW-project_definition = 'LGZXS002'.       "项目定义
  wa_BAPI_BUS2002_NEW-wbs_element        = 'LGZXS00212'.       "工作分解结构元素 (WBS 元素)
  wa_BAPI_BUS2002_NEW-short_text         = 'BAPI测试创建网络'.       "描述
  wa_BAPI_BUS2002_NEW-NETWORK_TYPE       ='ZP68'."网络类型
  wa_BAPI_BUS2002_NEW-plant              = '8810'.       "工厂
  wa_BAPI_BUS2002_NEW-mrp_controller     = '881'.       "MRP控制者

  CALL FUNCTION 'BAPI_PS_INITIALIZATION'.

  CALL FUNCTION 'BAPI_BUS2002_CREATE'
    EXPORTING
      i_network = wa_BAPI_BUS2002_NEW
    TABLES
      et_return = it_BAPIRET2.



"第四步:判断是否有错误消息
LOOP AT it_BAPIRET2 INTO wa_bapiret2 WHERE type CA 'AE'.


    MESSAGE ID wa_bapiret2-id TYPE wa_bapiret2-type NUMBER wa_bapiret2-number
        INTO wa_bapiret2-message
        WITH wa_bapiret2-message_v1 wa_bapiret2-message_v2
             wa_bapiret2-message_v3 wa_bapiret2-message_v4.
    WRITE:/ '创建时报错:',wa_bapiret2-message.

  ENDLOOP.


"第四步:如果有错误消息则退出
  IF sy-subrc EQ 0.

    CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'.

    CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
      EXPORTING
        i_precommit_ok = 'Y'.

  ENDIF.


  CHECK sy-subrc NE 0.

"第四步:没有错误消息则执行预提交
  CALL FUNCTION 'BAPI_PS_PRECOMMIT'
    TABLES
      et_return = it_BAPIRET2.

  LOOP AT it_BAPIRET2 INTO wa_bapiret2 WHERE type CA 'AE'.


    MESSAGE ID wa_bapiret2-id TYPE wa_bapiret2-type NUMBER wa_bapiret2-number
        INTO wa_bapiret2-message
        WITH wa_bapiret2-message_v1 wa_bapiret2-message_v2
             wa_bapiret2-message_v3 wa_bapiret2-message_v4.
    WRITE:/ '预提交时报错:',wa_bapiret2-message.

  ENDLOOP.


"第五步:预提交有错误消息则执行回滚
  IF sy-subrc EQ 0.

    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
      IMPORTING
        return = it_BAPIRET2.

    CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'.

    CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
      EXPORTING
        i_precommit_ok = 'Y'.

  ELSE.
"第五步:预提交无错误消息则执行正式提交
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait   = 'X'
      IMPORTING
        return = wa_BAPIRET2.
    WRITE:/ '网络创建成功:',wa_bapiret2-message.
*   WBS元素创建成功


  ENDIF.

3.3 网络删除

3.3.1 BAPI_BUS2002_DELETE|删除网络 |

输入:网络号

代码语言:javascript复制
*&---------------------------------------------------------------------*
*& Report ZLGZBAPI_BUS2002_DELETE
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZLGZBAPI_BUS2002_DELETE.

"第一步,判断网络是否存在

data:
is_network_exist type BAPI_NETWORK_LIST-NETWORK,

it_BAPIRETURN1 type STANDARD TABLE OF BAPIRETURN1,
wa_BAPIRETURN1 type BAPIRETURN1,

it_BAPIRET2 type STANDARD TABLE OF BAPIRET2,
wa_BAPIRET2 type BAPIRET2.


is_network_exist = '4500300'.


CALL FUNCTION 'BAPI_NETWORK_EXISTENCECHECK'
  EXPORTING
    number        = is_network_exist
 IMPORTING
   RETURN        = wa_BAPIRETURN1

   .

IF wa_BAPIRETURN1-TYPE = 'E'.
  WRITE:/ '网络不存在:',is_network_exist.
ENDIF.


  CALL FUNCTION 'BAPI_PS_INITIALIZATION'.
CALL FUNCTION 'BAPI_BUS2002_DELETE'
  EXPORTING
    i_number           = is_network_exist
 TABLES
   ET_RETURN          = it_BAPIRET2
*   EXTENSIONIN        =
*   EXTENSIONOUT       =
          .


"第四步:判断是否有错误消息
LOOP AT it_BAPIRET2 INTO wa_bapiret2 WHERE type CA 'AE'.


    MESSAGE ID wa_bapiret2-id TYPE wa_bapiret2-type NUMBER wa_bapiret2-number
        INTO wa_bapiret2-message
        WITH wa_bapiret2-message_v1 wa_bapiret2-message_v2
             wa_bapiret2-message_v3 wa_bapiret2-message_v4.
    WRITE:/ '创建时报错:',wa_bapiret2-message.

  ENDLOOP.


"第四步:如果有错误消息则退出
  IF sy-subrc EQ 0.

    CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'.

    CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
      EXPORTING
        i_precommit_ok = 'Y'.

  ENDIF.


  CHECK sy-subrc NE 0.

"第四步:没有错误消息则执行预提交
  CALL FUNCTION 'BAPI_PS_PRECOMMIT'
    TABLES
      et_return = it_BAPIRET2.

  LOOP AT it_BAPIRET2 INTO wa_bapiret2 WHERE type CA 'AE'.


    MESSAGE ID wa_bapiret2-id TYPE wa_bapiret2-type NUMBER wa_bapiret2-number
        INTO wa_bapiret2-message
        WITH wa_bapiret2-message_v1 wa_bapiret2-message_v2
             wa_bapiret2-message_v3 wa_bapiret2-message_v4.
    WRITE:/ '预提交时报错:',wa_bapiret2-message.

  ENDLOOP.


"第五步:预提交有错误消息则执行回滚
  IF sy-subrc EQ 0.

    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
      IMPORTING
        return = it_BAPIRET2.

    CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'.

    CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
      EXPORTING
        i_precommit_ok = 'Y'.

  ELSE.
"第五步:预提交无错误消息则执行正式提交
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait   = 'X'
      IMPORTING
        return = wa_BAPIRET2.
    WRITE:/ '网络删除成功:',wa_bapiret2-message.
*   WBS元素创建成功


  ENDIF.



BREAK-POINT.

4 活动(作业)

4.1 BAPI_BUS2002_ACT_GETDATA |活动的详细数据 |

输入:网络号(必选)、活动列表(可选)、语言(可选)、最大显示行(可选)等信息

代码语言:javascript复制
*&---------------------------------------------------------------------*
*& Report ZLGZBAPI_BUS2002_ACT_GETDATA
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZLGZBAPI_BUS2002_ACT_GETDATA.


"第一步,数据定义
DATA:
"输入
it_it_activity_list   TYPE STANDARD TABLE OF BAPI_ACTIVITY_LIST,"活动(作业)列表定义
wa_it_activity_list   LIKE LINE OF it_it_activity_list ,


ld_i_network_number   TYPE BAPI_BUS2002_ACT_DETAIL-NETWORK ,
ld_i_max_rows   TYPE BAPIF4A-MAX_ROWS ,
ld_i_language   TYPE BAPI_BUS2002_ACT_DETAIL-LANGU_ISO ,

"输出
it_et_activities   TYPE STANDARD TABLE OF BAPI_BUS2002_ACT_DETAIL,"TABLES PARAM
wa_et_activities   LIKE LINE OF it_et_activities ,


it_et_return   TYPE STANDARD TABLE OF BAPIRET2,"TABLES PARAM
wa_et_return   LIKE LINE OF it_et_return ,

it_extensionin   TYPE STANDARD TABLE OF BAPIPAREX,"TABLES PARAM
wa_extensionin   LIKE LINE OF it_extensionin ,

it_extensionout   TYPE STANDARD TABLE OF BAPIPAREX,"TABLES PARAM
wa_extensionout   LIKE LINE OF it_extensionout .





"第二步,数据赋值
ld_i_network_number = '4500245'."网络号
ld_i_language = 'ZH'."语言
ld_i_max_rows = 123 ."最大显示行


"输入,将活动结构放到内表
"populate fields of struture and append to itab
append wa_it_activity_list to it_it_activity_list.






CALL FUNCTION 'BAPI_BUS2002_ACT_GETDATA'
  EXPORTING
    i_network_number =           ld_i_network_number
   i_language =                 ld_i_language
   i_max_rows =                 ld_i_max_rows
 TABLES
*   it_activity_list =           it_it_activity_list
   et_activities =              it_et_activities
   et_return =                  it_et_return
*   extensionin =                it_extensionin
*   extensionout =               it_extensionout
    .  "  BAPI_BUS2002_ACT_GETDATA




IF SY-SUBRC EQ 0.

   CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
 EXPORTING
*   I_INTERFACE_CHECK                 = ' '
*   I_BYPASSING_BUFFER                =
*   I_BUFFER_ACTIVE                   =
*   I_CALLBACK_PROGRAM                = ' '
*   I_CALLBACK_PF_STATUS_SET          = ' '
*   I_CALLBACK_USER_COMMAND           = ' '
*   I_CALLBACK_TOP_OF_PAGE            = ' '
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
   I_STRUCTURE_NAME                  = 'BAPI_BUS2002_ACT_DETAIL'
*   I_BACKGROUND_ID                   = ' '
*   I_GRID_TITLE                      =
*   I_GRID_SETTINGS                   =
*   IS_LAYOUT_LVC                     =
*   IT_FIELDCAT_LVC                   =
*   IT_EXCLUDING                      =
*   IT_SPECIAL_GROUPS_LVC             =
*   IT_SORT_LVC                       =
*   IT_FILTER_LVC                     =
*   IT_HYPERLINK                      =
*   IS_SEL_HIDE                       =
*   I_DEFAULT                         = 'X'
*   I_SAVE                            = ' '
*   IS_VARIANT                        =
*   IT_EVENTS                         =
*   IT_EVENT_EXIT                     =
*   IS_PRINT_LVC                      =
*   IS_REPREP_ID_LVC                  =
*   I_SCREEN_START_COLUMN             = 0
*   I_SCREEN_START_LINE               = 0
*   I_SCREEN_END_COLUMN               = 0
*   I_SCREEN_END_LINE                 = 0
*   I_HTML_HEIGHT_TOP                 =
*   I_HTML_HEIGHT_END                 =
*   IT_ALV_GRAPHICS                   =
*   IT_EXCEPT_QINFO_LVC               =
*   IR_SALV_FULLSCREEN_ADAPTER        =
* IMPORTING
*   E_EXIT_CAUSED_BY_CALLER           =
*   ES_EXIT_CAUSED_BY_USER            =
  TABLES
    t_outtab                          = it_et_activities
* EXCEPTIONS
*   PROGRAM_ERROR                     = 1
*   OTHERS                            = 2
          .

ENDIF.

4.2 BAPI_BUS2002_ACT_CREATE_MULTI |清单: 创建网络活动 |

输入:网络号(必选)、活动信息(必选)

输出:

代码语言:javascript复制
*&---------------------------------------------------------------------*
*& Report ZLGZBAPI_BUS2002_ACT_CREATE_MU
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZLGZBAPI_BUS2002_ACT_CREATE_MU.


"第一步:定义变量
data:

"定义网络号
I_NUMBER type BAPI_NETWORK_LIST-NETWORK,

"定义输入活动
it_BAPI_BUS2002_ACT_NEW type STANDARD TABLE OF BAPI_BUS2002_ACT_NEW,
wa_BAPI_BUS2002_ACT_NEW type BAPI_BUS2002_ACT_NEW,

"定义返回参数
it_BAPIRET2 type STANDARD TABLE OF BAPIRET2,
wa_BAPIRET2 type BAPIRET2.


 "第二步:赋值
""网络号
 I_NUMBER = '4500245'.



 "作业赋值
    wa_BAPI_BUS2002_ACT_NEW-activity           = '0020'.       "在网络和库网络中的作业编号
    wa_BAPI_BUS2002_ACT_NEW-description        = 'BAPI创建活动测试'.       "工序短文本
    wa_BAPI_BUS2002_ACT_NEW-control_key        = 'LG01'.       "控制码-内协(ZPS1)和成本(ZPS3)
    wa_BAPI_BUS2002_ACT_NEW-wbs_element        = 'LGZXS00212'.       "工作分解结构元素 (WBS 元素)
    wa_BAPI_BUS2002_ACT_NEW-work_cntr          = ''.       "工作中心
    wa_BAPI_BUS2002_ACT_NEW-work_activity      = ''.       "工作(时间单位H)

    wa_BAPI_BUS2002_ACT_NEW-calculation_key    = 0.       "用于计算的码


    wa_BAPI_BUS2002_ACT_NEW-acttype            = ''.       "活动类型
    wa_BAPI_BUS2002_ACT_NEW-cost_elem          = ''.       "成本要素编码
    wa_BAPI_BUS2002_ACT_NEW-profit_ctr         = ''.       "利润中心

    wa_BAPI_BUS2002_ACT_NEW-activity_costs   = ''.       "作业中的成本


  APPEND wa_BAPI_BUS2002_ACT_NEW to it_BAPI_BUS2002_ACT_NEW.


 "第三步:调用函数
  CALL FUNCTION 'BAPI_PS_INITIALIZATION'.

  CALL FUNCTION 'BAPI_BUS2002_ACT_CREATE_MULTI'
    EXPORTING
      i_number    =  I_NUMBER
    TABLES
      it_activity = it_BAPI_BUS2002_ACT_NEW
      et_return   = it_BAPIRET2.



"第四步:判断是否有错误消息
LOOP AT it_BAPIRET2 INTO wa_bapiret2 WHERE type CA 'AE'.


    MESSAGE ID wa_bapiret2-id TYPE wa_bapiret2-type NUMBER wa_bapiret2-number
        INTO wa_bapiret2-message
        WITH wa_bapiret2-message_v1 wa_bapiret2-message_v2
             wa_bapiret2-message_v3 wa_bapiret2-message_v4.
    WRITE:/ '创建时报错:',wa_bapiret2-message.

  ENDLOOP.


"第四步:如果有错误消息则退出
  IF sy-subrc EQ 0.

    CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'.

    CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
      EXPORTING
        i_precommit_ok = 'Y'.

  ENDIF.


  CHECK sy-subrc NE 0.

"第四步:没有错误消息则执行预提交
  CALL FUNCTION 'BAPI_PS_PRECOMMIT'
    TABLES
      et_return = it_BAPIRET2.

  LOOP AT it_BAPIRET2 INTO wa_bapiret2 WHERE type CA 'AE'.


    MESSAGE ID wa_bapiret2-id TYPE wa_bapiret2-type NUMBER wa_bapiret2-number
        INTO wa_bapiret2-message
        WITH wa_bapiret2-message_v1 wa_bapiret2-message_v2
             wa_bapiret2-message_v3 wa_bapiret2-message_v4.
    WRITE:/ '预提交时报错:',wa_bapiret2-message.

  ENDLOOP.


"第五步:预提交有错误消息则执行回滚
  IF sy-subrc EQ 0.

    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
      IMPORTING
        return = it_BAPIRET2.

    CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'.

    CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
      EXPORTING
        i_precommit_ok = 'Y'.

  ELSE.
"第五步:预提交无错误消息则执行正式提交
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait   = 'X'
      IMPORTING
        return = wa_BAPIRET2.
    WRITE:/ '活动(作业)创建成功:',wa_bapiret2-message.
*   WBS元素创建成功


  ENDIF.

4.3 BAPI_BUS2002_ACT_CHANGE_MULTI|清单: 更改网络活动

5 物料组件

5.1 BAPI_NETWORK_COMP_GETLIST |网络所有组件的清单 |

输入:网络号(必输)、显示内容(可选)、range 输出:物料组件列表(必选) 注意前导零。

代码语言:javascript复制
*&---------------------------------------------------------------------*
*& Report ZLGZBAPI_NETWORK_COMP_GETLIST
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZLGZBAPI_NETWORK_COMP_GETLIST.

"第一步,定义变量
DATA:

"输入

ld_number   TYPE BAPI_NETWORK_LIST-NETWORK ,"网络号


"活动的范围range
it_i_activity_range   TYPE STANDARD TABLE OF BAPI_NETWORK_COMP_ACT_RNG ,
wa_i_activity_range   LIKE LINE OF it_i_activity_range,


"最大显示行
ld_max_rows   TYPE BAPIF4A-MAX_ROWS ,



it_e_components_list   TYPE STANDARD TABLE OF BAPI_NETWORK_COMP_LIST ,
wa_e_components_list   LIKE LINE OF it_e_components_list,


"返回值
ld_return   TYPE BAPIRET2 .




ld_number = '000004500249'.

"populate fields of struture and append to itab
append wa_i_activity_range to it_i_activity_range.

ld_max_rows = 123  .

"populate fields of struture and append to itab

append wa_e_components_list to it_e_components_list.


.

CALL FUNCTION 'BAPI_NETWORK_COMP_GETLIST'
  EXPORTING
    number =                     ld_number
   max_rows =                   ld_max_rows
  IMPORTING
    return =                     ld_return
  TABLES
*   i_activity_range =           it_i_activity_range
    e_components_list =          it_e_components_list
    .  "  BAPI_NETWORK_COMP_GETLIST

IF SY-SUBRC EQ 0.
  "All OK
ENDIF.


BREAK-POINT.

5.2 BAPI_NETWORK_COMP_GETDETAIL|网络作业物料组件的详述数据

只比上个查询多一个物料号的条件,但是详细信息很丰富,只有这个详细信息才能达到创建的条件的哦

输入:网络号(必输)、显示内容range(可选)、物料组件唯一编号(预留 流水)

输出:组件信息,非常详细。

代码语言:javascript复制
*&---------------------------------------------------------------------*
*& Report ZLGZBAPI_NETWORK_COMP_GETLIST
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZLGZBAPI_NETWORK_COMP_GETLIST.

"第一步,定义变量
DATA:

"输入

ld_number   TYPE BAPI_NETWORK_LIST-NETWORK ,"网络号


"活动的范围range
it_i_activity_range   TYPE STANDARD TABLE OF BAPI_NETWORK_COMP_ACT_RNG ,
wa_i_activity_range   LIKE LINE OF it_i_activity_range,


"最大显示行
ld_max_rows   TYPE BAPIF4A-MAX_ROWS ,

"组件ID
ld_BAPI_NETWORK_COMP_ID like BAPI_NETWORK_COMP_ID,
it_BAPI_NETWORK_COMP_ID like TABLE OF BAPI_NETWORK_COMP_ID,




"输出物料组件列表信息

it_e_components_list   TYPE STANDARD TABLE OF BAPI_NETWORK_COMP_LIST ,
wa_e_components_list   LIKE LINE OF it_e_components_list,

"输出物料组件详细信息


it_BAPI_NETWORK_COMP_DETAIL TYPE STANDARD TABLE OF BAPI_NETWORK_COMP_DETAIL,
wa_BAPI_NETWORK_COMP_DETAIL LIKE LINE OF it_BAPI_NETWORK_COMP_DETAIL,

"返回值
ld_return   TYPE BAPIRET2 .




ld_number = '000004500249'.

ld_BAPI_NETWORK_COMP_ID-COMPONENT = '00005018220001'."这儿不是物料编号,是预留的唯一编号 预留序号

APPEND ld_BAPI_NETWORK_COMP_ID to it_BAPI_NETWORK_COMP_ID.

"populate fields of struture and append to itab
append wa_i_activity_range to it_i_activity_range.

ld_max_rows = 123  .

"populate fields of struture and append to itab

append wa_e_components_list to it_e_components_list.


.

CALL FUNCTION 'BAPI_NETWORK_COMP_GETLIST'
  EXPORTING
   number =                     ld_number
   max_rows =                   ld_max_rows
  IMPORTING
    return =                     ld_return
  TABLES
*   i_activity_range =           it_i_activity_range
    e_components_list =          it_e_components_list
    .  "  BAPI_NETWORK_COMP_GETLIST

IF SY-SUBRC EQ 0.
  "All OK
ENDIF.







CALL FUNCTION 'BAPI_NETWORK_COMP_GETDETAIL'
  EXPORTING
    number                    = ld_number
*   MAX_ROWS                  = 0
 IMPORTING
   RETURN                    = ld_return
  tables
*   I_ACTIVITY_RANGE          =
   I_COMPONENTS_ID           = it_BAPI_NETWORK_COMP_ID
    e_components_detail       = it_BAPI_NETWORK_COMP_DETAIL
          .


BREAK-POINT.

5.3 BAPI_NETWORK_COMP_ADD|为网络填加物料组件 |

输入:网络号(必选)以及组件信息(必选) 输出:日志

注意:决定采购类型的是TYPE_OF_PUR_RESV字段,一般会将TYPE_OF_PUR_RESV与采购标识符做个影射,前台选择采购标识符,具体可参见团子大神文章。《跟着团子学SAP PS—项目中的物料需求逻辑及导入程序设计要点(采购标识符/BAPI_NETWORK_COMP_ADD)》

代码语言:javascript复制
*&---------------------------------------------------------------------*
*& Report ZLGZBAPI_NETWORK_COMP_ADD
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zlgzbapi_network_comp_add.

"第一步,定义变量

"输入,网络号
DATA:
i_NUMBER TYPE bapi_network_list-network,

"输入的组件信息
wa_I_COMPONENTS_ADD TYPE BAPI_NETWORK_COMP_ADD,
it_I_COMPONENTS_ADD TYPE STANDARD TABLE OF BAPI_NETWORK_COMP_ADD,


"输出
wa_BAPIRET2 TYPE bapiret2,
it_BAPIRET2 TYPE STANDARD TABLE OF bapiret2,


"输出的消息信息

wa_E_MESSAGE_TABLE TYPE bapi_meth_message,
it_E_MESSAGE_TABLE TYPE STANDARD TABLE OF bapi_meth_message.


"第二步,变量赋值

  "网络编号
  i_NUMBER = '000004500249'.

  "物料组件
  wa_I_COMPONENTS_ADD-activity        = '0010'. "活动编号
  wa_I_COMPONENTS_ADD-TYPE_OF_PUR_RESV = '5'. "采购类型
  wa_I_COMPONENTS_ADD-material        = '000000000068100001'."物料号
  wa_I_COMPONENTS_ADD-entry_quantity  = '188'.  "数量
  wa_I_COMPONENTS_ADD-PUR_GROUP = '881'."采购组
  wa_I_COMPONENTS_ADD-req_date        = '20210830'."需求日期
  wa_I_COMPONENTS_ADD-item_text       = '测试bapi物料挂载'.  "项目文本行
  wa_I_COMPONENTS_ADD-item_cat        = 'L'.
  wa_I_COMPONENTS_ADD-base_uom        = 'BT'. "基本计量单位
  APPEND wa_I_COMPONENTS_ADD to it_I_COMPONENTS_ADD.


 "第三步:调用函数
  CALL FUNCTION 'BAPI_PS_INITIALIZATION'.
  CALL FUNCTION 'BAPI_NETWORK_COMP_ADD'
    EXPORTING
      number                 = i_NUMBER
   IMPORTING
     RETURN                 = wa_BAPIRET2
    tables
      i_components_add       = it_I_COMPONENTS_ADD
      e_message_table        = it_E_MESSAGE_TABLE
            .



APPEND wa_BAPIRET2 to it_BAPIRET2.
"第四步:判断是否有错误消息
LOOP AT it_BAPIRET2 INTO wa_bapiret2 WHERE type CA 'AE'.


    MESSAGE ID wa_bapiret2-id TYPE wa_bapiret2-type NUMBER wa_bapiret2-number
        INTO wa_bapiret2-message
        WITH wa_bapiret2-message_v1 wa_bapiret2-message_v2
             wa_bapiret2-message_v3 wa_bapiret2-message_v4.
    WRITE:/ '创建时报错:',wa_bapiret2-message.

  ENDLOOP.


"第四步:如果有错误消息则退出
  IF sy-subrc EQ 0.

    CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'.

    CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
      EXPORTING
        i_precommit_ok = 'Y'.

  ENDIF.


  CHECK sy-subrc NE 0.

"第四步:没有错误消息则执行预提交
  CALL FUNCTION 'BAPI_PS_PRECOMMIT'
    TABLES
      et_return = it_BAPIRET2.

  LOOP AT it_BAPIRET2 INTO wa_bapiret2 WHERE type CA 'AE'.


    MESSAGE ID wa_bapiret2-id TYPE wa_bapiret2-type NUMBER wa_bapiret2-number
        INTO wa_bapiret2-message
        WITH wa_bapiret2-message_v1 wa_bapiret2-message_v2
             wa_bapiret2-message_v3 wa_bapiret2-message_v4.
    WRITE:/ '预提交时报错:',wa_bapiret2-message.

  ENDLOOP.


"第五步:预提交有错误消息则执行回滚
  IF sy-subrc EQ 0.

    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
      IMPORTING
        return = it_BAPIRET2.

    CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'.

    CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
      EXPORTING
        i_precommit_ok = 'Y'.

  ELSE.
"第五步:预提交无错误消息则执行正式提交
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait   = 'X'
      IMPORTING
        return = wa_BAPIRET2.
    WRITE:/ '活动(作业)创建成功:',wa_bapiret2-message.
*   WBS元素创建成功


  ENDIF.

5.4 BAPI_NETWORK_COMP_CHANGE|为网络更改物料组件 |

5.5 BAPI_NETWORK_COMP_REMOVE|从网络中删除物料组件 |

6 项目预算BAPI

KBPP_EXTERN_UPDATE_CO

1、一定要先修改顶层WBS,再一层一层往下修改,不然的话,检查上层预算不够,就会报错

2、i_delta_amounts这个参数等于’X’的话,就是追加,等于’’,就是修改

3、i_rollup_data这个参数等于’X’的话,就会自动往上层的WBS上加预算,等于’’,就不会自动加

代码语言:javascript复制
REPORT ZLGZKBPP_EXTERN_UPDATE_CO.


tables: prps.

     DATA: lt_bpak TYPE STANDARD TABLE OF bpak WITH HEADER LINE."预算/计划更新

     DATA:lt_bpak_n TYPE STANDARD TABLE OF bpak WITH HEADER LINE. "预算/计划更新,年度预算

     DATA: lt_retturn TYPE STANDARD TABLE OF bapiret2 WITH HEADER LINE. "返回参数

     DATA: l_wtjhr like bpak-wert.  " 预算金额


*select-options l_pspnr for prps-pspnr.
    PARAMETER: l_pspnr like prps-pspnr. "WBS编号
    PARAMETER: l_bpwert like bpak-wert." 预算金额
    PARAMETER: P_vorga LIKE BPIN-VORGA. "应用类型  cj30 using KBUD; cj32 using KBFR;cj40 using KBN0

start-of-selection.

*    "转换内码
*    DATA: l_pspnr LIKE prps-pspnr.
*    CALL FUNCTION 'CONVERSION_EXIT_ABPSP_INPUT'
*      EXPORTING
*        input     = l_pspnri
*      IMPORTING
*        output    = l_pspnr
*      EXCEPTIONS
*        not_found = 1
*        OTHERS    = 2.
*    IF sy-subrc <> 0.
*      MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
*              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
*    ENDIF.



    clear: l_wtjhr. " 清空预算金额

    SELECT SINGLE objnr INTO lt_bpak-e_objnr FROM prps WHERE pspnr = l_pspnr. "根据输入的WBS,把WBS的对象号放到 内表中

    IF sy-subrc EQ 0.
      "找到WBS以后做以下赋值
      lt_bpak-e_vorga = 'KBFR'. "预算类型预算/计划
      lt_bpak-twaer = 'CNY'. "币种
      lt_bpak-wert = l_bpwert. "预算金额


      APPEND lt_bpak.

      SELECT wtjhr INTO l_wtjhr FROM  bpja
        WHERE objnr = lt_bpak-e_objnr "根据对象编号,去BPJA年度预算表查询年度预算金额,放到l_wtjhr中
        AND wrttp = '41'
        AND vorga = 'KBUD'
        AND twaer = 'CNY'
        AND gjahr = '2021'.

        lt_bpak-wert = lt_bpak-wert   l_wtjhr.
        CLEAR l_wtjhr.
      ENDSELECT.




      "也把金额同步拷贝到lt_bpak_n内表一份,为年度预算使用
      MOVE-CORRESPONDING lt_bpak TO lt_bpak_n.

      lt_bpak_n-wert = l_bpwert.
      lt_bpak_n-S_GJAHR = '2021'.    " add year to change data belong this year 发送方年度
      lt_bpak_n-E_GJAHR = '2021'.    "if not add ; change total budget ,接收方年度
      APPEND lt_bpak_n.


    ENDIF.

    CLEAR: lt_bpak,lt_bpak_n.







*i_delta_amounts这个参数等于'X'的话,就是追加,等于'',就是修改
*i_rollup_data这个参数等于'X'的话,就会自动往上层的WBS上加预算,等于'',就不会自动加
*一定要先修改顶层WBS,再一层一层往下修改,不然的话,检查上层预算不够,就会报错

 CALL FUNCTION 'KBPP_EXTERN_UPDATE_CO'
   EXPORTING
     i_budget_activity            = 'KBUD'
*     i_budget_activ_sup_ret       = 'X'
*     I_COMMIT_DATA                = 'X'
     i_delta_amounts              = ''
     i_rollup_data                = ''
*    I_CHECK_PLAN_DATA            = 'X'
*    i_application                = 'P'
    i_commit_all                 = 'X'
* IMPORTING
*   E_ERRORS_FOUND               =
   TABLES
     it_bpak                      = lt_bpak[]
     it_return                    = lt_retturn[]
  EXCEPTIONS
    no_update                    = 1
    OTHERS                       = 2
            .

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

**修改年度预算

    REFRESH lt_retturn.
  CALL FUNCTION 'KBPP_EXTERN_UPDATE_CO'
   EXPORTING
     i_budget_activity            = 'KBUD'
*     i_budget_activ_sup_ret       = 'X'
*     I_COMMIT_DATA                = 'X'
     i_delta_amounts              = ''
     i_rollup_data                = ''
*    I_CHECK_PLAN_DATA            = 'X'
    i_application                = 'P'
    i_commit_all                 = 'X'
* IMPORTING
*   E_ERRORS_FOUND               =
   TABLES
     it_bpak                      = lt_bpak_n[]
     it_return                    = lt_retturn[]
  EXCEPTIONS
    no_update                    = 1
    OTHERS                       = 2
            .

  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.

7 服务主数据类采购申请创建

7.1 外部活动创建

代码语言:javascript复制
*&---------------------------------------------------------------------*
*& Report ZLGZBAPI_BUS2002_ACT_CREATE_M1
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZLGZBAPI_BUS2002_ACT_CREATE_M1.



"第一步:定义变量
data:

"定义网络号
I_NUMBER type BAPI_NETWORK_LIST-NETWORK,

"定义输入活动
it_BAPI_BUS2002_ACT_NEW type STANDARD TABLE OF BAPI_BUS2002_ACT_NEW,
wa_BAPI_BUS2002_ACT_NEW type BAPI_BUS2002_ACT_NEW,

"定义返回参数
it_BAPIRET2 type STANDARD TABLE OF BAPIRET2,
wa_BAPIRET2 type BAPIRET2.


 "第二步:赋值
""网络号
 I_NUMBER = '4500245'.



 "作业赋值
    wa_BAPI_BUS2002_ACT_NEW-activity           = '0030'.       "在网络和库网络中的作业编号
    wa_BAPI_BUS2002_ACT_NEW-description        = 'BAPI创建外部活动测试'.       "工序短文本
    wa_BAPI_BUS2002_ACT_NEW-control_key        = 'LG02'.       "控制码-内协(ZPS1)和成本(ZPS3)
    wa_BAPI_BUS2002_ACT_NEW-wbs_element        = 'LGZXS00212'.       "工作分解结构元素 (WBS 元素)
    wa_BAPI_BUS2002_ACT_NEW-work_cntr          = ''.       "工作中心
    wa_BAPI_BUS2002_ACT_NEW-work_activity      = ''.       "工作(时间单位H)

    wa_BAPI_BUS2002_ACT_NEW-calculation_key    = 0.       "用于计算的码


    wa_BAPI_BUS2002_ACT_NEW-acttype            = ''.       "活动类型
    wa_BAPI_BUS2002_ACT_NEW-cost_elem          = ''.       "成本要素编码
    wa_BAPI_BUS2002_ACT_NEW-profit_ctr         = ''.       "利润中心

    wa_BAPI_BUS2002_ACT_NEW-activity_costs   = ''.       "作业中的成本

    wa_BAPI_BUS2002_ACT_NEW-PLANT = '8810'."工厂

    wa_BAPI_BUS2002_ACT_NEW-PURCH_ORG = '6888'."采购组织

    wa_BAPI_BUS2002_ACT_NEW-MATL_GROUP = '001'."物料组

    wa_BAPI_BUS2002_ACT_NEW-PUR_GROUP  = '881'."采购组

    wa_BAPI_BUS2002_ACT_NEW-PRICE  = '881'."价格

    wa_BAPI_BUS2002_ACT_NEW-PRICE_UNIT  = '881'."价格单位


    wa_BAPI_BUS2002_ACT_NEW-OPERATION_QTY  = '2'."数量


    wa_BAPI_BUS2002_ACT_NEW-OPERATION_MEASURE_UNIT  = 'H'."数量单位

    wa_BAPI_BUS2002_ACT_NEW-COST_ELEM  = '13100000'."成本要素



  APPEND wa_BAPI_BUS2002_ACT_NEW to it_BAPI_BUS2002_ACT_NEW.


 "第三步:调用函数
  CALL FUNCTION 'BAPI_PS_INITIALIZATION'.

  CALL FUNCTION 'BAPI_BUS2002_ACT_CREATE_MULTI'
    EXPORTING
      i_number    =  I_NUMBER
    TABLES
      it_activity = it_BAPI_BUS2002_ACT_NEW
      et_return   = it_BAPIRET2.



"第四步:判断是否有错误消息
LOOP AT it_BAPIRET2 INTO wa_bapiret2 WHERE type CA 'AE'.


    MESSAGE ID wa_bapiret2-id TYPE wa_bapiret2-type NUMBER wa_bapiret2-number
        INTO wa_bapiret2-message
        WITH wa_bapiret2-message_v1 wa_bapiret2-message_v2
             wa_bapiret2-message_v3 wa_bapiret2-message_v4.
    WRITE:/ '创建时报错:',wa_bapiret2-message.

  ENDLOOP.


"第四步:如果有错误消息则退出
  IF sy-subrc EQ 0.

    CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'.

    CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
      EXPORTING
        i_precommit_ok = 'Y'.

  ENDIF.


  CHECK sy-subrc NE 0.

"第四步:没有错误消息则执行预提交
  CALL FUNCTION 'BAPI_PS_PRECOMMIT'
    TABLES
      et_return = it_BAPIRET2.

  LOOP AT it_BAPIRET2 INTO wa_bapiret2 WHERE type CA 'AE'.


    MESSAGE ID wa_bapiret2-id TYPE wa_bapiret2-type NUMBER wa_bapiret2-number
        INTO wa_bapiret2-message
        WITH wa_bapiret2-message_v1 wa_bapiret2-message_v2
             wa_bapiret2-message_v3 wa_bapiret2-message_v4.
    WRITE:/ '预提交时报错:',wa_bapiret2-message.

  ENDLOOP.


"第五步:预提交有错误消息则执行回滚
  IF sy-subrc EQ 0.

    CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
      IMPORTING
        return = it_BAPIRET2.

    CALL FUNCTION 'PS_FLAG_INIT_GLOBAL_FLAGS'.

    CALL FUNCTION 'PS_FLAG_SET_GLOBAL_FLAGS'
      EXPORTING
        i_precommit_ok = 'Y'.

  ELSE.
"第五步:预提交无错误消息则执行正式提交
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        wait   = 'X'
      IMPORTING
        return = wa_BAPIRET2.
    WRITE:/ '活动(作业)创建成功:',wa_bapiret2-message.
*   WBS元素创建成功


  ENDIF.

7.2 服务活动创建,必须输入服务主数据

目前先暂用BDC实现,用BAPI真不好弄啊。BDC最大的坏处是只能重新建网络。

02

关于作者

李钢柱,一位久经沙场的PS老兵,喜欢将SAP化繁为简,期待让普通玩家也能轻松上手。

版权归原作者所有,如有侵权请联系删除


免责声明:本文所用视频、图片、文字如涉及作品版权问题,请第一时间告知,我们将根据您提供的证明材料确认版权并按国家标准支付稿酬或立即删除内容!本文内容为原作者观点,并不代表本公众号赞同其观点和对其真实性负责。

分享是一种精

0 人点赞