赞
踩
- 如果CO_XT_COMPONENT_ADD缺少需要的字段
- 可以拷贝出来,
- 在ZCO_XT_COMPONENT_ADD
- 添加字段例如:I_TEST 和 I_TESTX
- 或者memory id传值
- 在220行左右添加代码后调用BAPI即可
- if i_testx is not initial.
- ls_resbd_new-TEST = I_TEST.
- endif.
-
- 也可以调用bapi后直接修改
- (SAPLCOBC)RESB_BT[]
- 内的对应字段
1.创建
-
- data:is_order_key type coxt_ord_key,
- i_material type coxt_material,
- is_storage_location type coxt_s_storage_location,
- is_storage_locationx type coxt_s_storage_locationx,
- is_requ_quan type coxt_s_quantity,
- i_operation type afvc-aplzl,
- i_posno type cif_r3res-positionno,
- ls_return type coxt_bapireturn,
- lv_error type c.
- data:
- lv_matnr type mara-matnr,
- lv_aufnr type afpo-aufnr,
- lv_sortf type resb-sortf,
- lv_sortfx type c,
- lv_posnr type char4.
-
- types: begin of ty_resb_bt.
- include type resbb.
- types: indold type syst_tabix.
- types: no_req_upd type syst_datar.
- types: end of ty_resb_bt.
-
- types tt_resb_bt type table of ty_resb_bt.
-
- field-symbols: <ft_resb_bt> type tt_resb_bt,
- <fs_resb_bt> type ty_resb_bt.
-
- data:begin of lt_aufnr occurs 0,
- aufnr type afpo-aufnr,
- end of lt_aufnr.
-
- refresh lt_aufnr.
-
- loop at gt_data1 assigning <fs_data1> where check eq 'X'
- and cellcolor is initial
- and icon ne icon_led_green.
- lt_aufnr-aufnr = <fs_data1>-aufnr.
- append lt_aufnr.
- clear lt_aufnr.
- endloop.
-
- sort lt_aufnr.
- delete adjacent duplicates from lt_aufnr.
-
- loop at lt_aufnr.
-
- loop at gt_data1 assigning <fs_data1> where aufnr eq lt_aufnr-aufnr.
-
- clear:lv_matnr,lv_aufnr,lv_posnr,is_requ_quan,is_storage_location,is_storage_locationx,
- ls_return,lv_error,lv_sortf,lv_sortfx.
-
- unassign:<ft_resb_bt>,<fs_resb_bt>.
-
- lv_aufnr = <fs_data1>-aufnr.
- lv_matnr = <fs_data1>-matnr.
-
- call function 'CONVERSION_EXIT_ALPHA_INPUT'
- exporting
- input = lv_aufnr
- importing
- output = lv_aufnr.
-
- call function 'CONVERSION_EXIT_ALPHA_INPUT'
- exporting
- input = lv_matnr
- importing
- output = lv_matnr.
-
- is_order_key = lv_aufnr.
- i_material = lv_matnr.
-
- is_requ_quan-quantity = <fs_data1>-menge.
-
- is_storage_location-werks = <fs_data1>-werks.
- is_storage_locationx-werks = 'X'.
-
- if <fs_data1>-lgort is not initial.
- is_storage_location-lgort = <fs_data1>-lgort.
- is_storage_locationx-lgort = 'X'.
- endif.
-
- call function 'CO_XT_COMPONENT_ADD'
- exporting
- is_order_key = is_order_key
- i_material = i_material
- is_requ_quan = is_requ_quan
- i_operation = i_operation
- is_storage_location = is_storage_location
- is_storage_locationx = is_storage_locationx
- i_postp = 'L'
- i_posno = i_posno
- importing
- es_bapireturn = ls_return
- e_error_occurred = lv_error.
-
- if lv_error is initial.
-
- assign ('(SAPLCOBC)RESB_BT[]') to <ft_resb_bt>.
-
- data(line) = lines( <ft_resb_bt> ).
-
- loop at <ft_resb_bt> assigning <fs_resb_bt>.
-
- "新增行数据处理
- if sy-tabix = line.
- if <fs_data1>-posnr is not initial.
- <fs_resb_bt>-posnr = <fs_data1>-posnr.
- else.
- select single max( posnr )
- into <fs_resb_bt>-posnr
- from resb
- where aufnr eq lv_aufnr.
- <fs_resb_bt>-posnr = <fs_resb_bt>-posnr + 1.
- lv_posnr = <fs_resb_bt>-posnr.
- endif.
- call function 'CONVERSION_EXIT_ALPHA_INPUT'
- exporting
- input = <fs_resb_bt>-posnr
- importing
- output = <fs_resb_bt>-posnr.
- if <fs_data1>-sortf is not initial.
- <fs_resb_bt>-sortf = <fs_data1>-sortf.
- endif.
- if <fs_resb_bt>-xwaok is initial.
- <fs_resb_bt>-xwaok = 'X'.
- endif.
- endif.
- endloop.
- call function 'CO_XT_ORDER_PREPARE_COMMIT'
- importing
- es_bapireturn = ls_return
- e_error_occurred = lv_error.
- if ( ls_return-type = 'S' or ls_return-type = 'W' or ls_return-type = 'I' ) or
- ls_return is initial.
- call function 'BAPI_TRANSACTION_COMMIT'
- exporting
- wait = 'X'.
- call function 'CO_XT_ORDER_INITIALIZE'.
- <fs_data1>-mseg = '新增成功'.
- * <fs_data1>-color = 'C500'.
- <fs_data1>-icon = icon_led_green.
- perform save_history_add using <fs_data1> lv_posnr.
- else.
- call function 'BAPI_TRANSACTION_ROLLBACK'.
- <fs_data1>-mseg = ls_return-message.
- <fs_data1>-icon = icon_led_red.
- endif.
- else.
- call function 'BAPI_TRANSACTION_ROLLBACK'.
- <fs_data1>-mseg = ls_return-message.
- <fs_data1>-icon = icon_led_red.
- endif.
- wait up to 1 seconds.
- endloop.
- endloop.
2.修改
- data:lt_resb like table of resb with header line.
- data:lv_message type string,
- lv_matny type mara-matnr.
- data:ft_return type table of bapiret2 with header line.
- data:lt_return type table of bapiret2 with header line.
-
- data:ls_return type coxt_bapireturn,
- ls_return2 type bapiret2,
- error type c.
-
- data:order type coxt_ord_key,
- compkey type coxt_s_ord_comp_key,
- ret type coxt_bapireturn,
- bapiret type coxt_t_bapireturn.
-
- data : is_order_key type coxt_ord_key,
- is_order_component_key type coxt_s_ord_comp_key,
- is_requirement_quantity type coxt_s_quantity,
- is_requirement_quantityx type coxt_s_quantityx,
- is_confirmed_quantity type coxt_s_quantity,
- is_confirmed_quantityx type coxt_s_quantityx,
- i_material type coxt_material,
- i_materialx type coxt_materialx,
- is_order_operation_key type coxt_s_ord_opr_key,
- is_order_operation_keyx type coxt_s_ord_opr_keyx,
- is_requirement_date type coxt_s_date,
- is_requirement_datex type coxt_s_datex,
- is_storage_location type coxt_s_storage_location,
- is_storage_locationx type coxt_s_storage_locationx,
- i_batch type coxt_batch,
- i_batchx type coxt_batchx,
- i_mi_configuration_object type coxt_config_object,
- i_mi_configuration_objectx type coxt_config_objectx.
-
- data :wa_resb type resb,
- es_bapireturn type coxt_bapireturn,
- e_error_occurred type c.
-
- data:begin of lt_aufnr occurs 0,
- aufnr type afpo-aufnr,
- end of lt_aufnr.
-
- refresh:lt_aufnr,lt_return.
-
- loop at gt_data2 assigning <fs_data2> where check eq 'X'
- and cellcolor is initial
- and icon ne icon_led_green.
- lt_aufnr-aufnr = <fs_data2>-aufnr.
- append lt_aufnr.
- clear lt_aufnr.
- endloop.
-
- sort lt_aufnr.
- delete adjacent duplicates from lt_aufnr.
-
- loop at lt_aufnr.
-
- clear is_order_key.
-
- is_order_key = lt_aufnr-aufnr.
-
- call function 'CONVERSION_EXIT_ALPHA_INPUT'
- exporting
- input = is_order_key
- importing
- output = is_order_key.
-
- loop at gt_data2 assigning <fs_data2> where aufnr eq lt_aufnr-aufnr.
-
- clear:lv_matny,ft_return[],ft_return,lv_message.
-
- lv_matny = <fs_data2>-matny.
-
- call function 'CONVERSION_EXIT_ALPHA_INPUT'
- exporting
- input = lv_matny
- importing
- output = lv_matny.
-
- if <fs_data2>-potx1 is initial and p_bf ne 'X'.
- select *
- into corresponding fields of table lt_resb
- from resb
- where aufnr eq is_order_key
- and matnr eq lv_matny
- and xloek ne 'X'.
- else.
- select *
- into corresponding fields of table lt_resb
- from resb
- where aufnr eq is_order_key
- and matnr eq lv_matny
- and xloek ne 'X'
- and potx1 eq <fs_data2>-potx1.
- endif.
-
-
- if lt_resb[] is initial.
- <fs_data2>-mseg = '无该原物料可替换'.
- <fs_data2>-icon = icon_led_red.
- continue.
- endif.
-
- loop at lt_resb.
-
- clear:ls_return,ls_return2,is_order_component_key,
- is_requirement_quantity,is_requirement_quantityx,
- is_storage_location,is_storage_locationx,i_material,i_materialx,
- is_storage_location,is_storage_locationx,lv_message,error.
-
- move-corresponding lt_resb to is_order_component_key.
-
- if <fs_data2>-matnr is initial.
- i_material = <fs_data2>-matny.
- else.
- i_material = <fs_data2>-matnr.
- endif.
- call function 'CONVERSION_EXIT_ALPHA_INPUT'
- exporting
- input = i_material
- importing
- output = i_material.
- i_materialx = 'X'.
-
- is_storage_location-werks = lt_resb-werks.
- is_storage_locationx-werks = 'X'.
-
- if <fs_data2>-menge is not initial.
- is_requirement_quantity-quantity = <fs_data2>-menge.
- is_requirement_quantityx-quantity = 'X'.
- endif.
- if <fs_data2>-lgort is not initial.
- is_storage_location-lgort = <fs_data2>-lgort.
- is_storage_locationx-lgort = 'X'.
- endif.
-
- clear lv_zcomp.
-
-
- if <fs_data2>-matnr is initial."新物料号为空 组件为原物料号
- concatenate lt_resb-posnr lt_resb-matnr into lv_zcomp separated by '/'.
- else."新物料号不为空 修改的是新物料号的 数量和库区
- concatenate lt_resb-posnr <fs_data2>-matnr into lv_zcomp separated by '/'.
- endif.
-
- call function 'CO_XT_COMPONENT_CHANGE'
- exporting
- is_order_key = is_order_key
- is_order_component_key = is_order_component_key
- is_requirement_quantity = is_requirement_quantity
- is_requirement_quantityx = is_requirement_quantityx
- is_confirmed_quantity = is_confirmed_quantity
- is_confirmed_quantityx = is_confirmed_quantityx
- i_material = i_material
- i_materialx = i_materialx
- is_storage_location = is_storage_location
- is_storage_locationx = is_storage_locationx
- i_batch = i_batch
- i_batchx = i_batchx
- i_mi_configuration_object = i_mi_configuration_object
- i_mi_configuration_objectx = i_mi_configuration_objectx
- importing
- es_bapireturn = ls_return
- e_error_occurred = error.
-
- if error is initial.
-
- call function 'CO_XT_ORDER_PREPARE_COMMIT'
- importing
- e_order_key = is_order_key
- es_bapireturn = ret
- e_error_occurred = error.
- if ( ret-type = 'S' or ret-type = 'W' or ret-type = 'I' ) or ret is initial.
-
- data :lt_resb_get type table of resbdget,
- lw_resb_get like line of lt_resb_get.
- clear:lt_resb_get[],lw_resb_get.
- call function 'CO_BC_RESBD_OF_ORDER_GET'
- exporting
- aufnr_act = is_order_key
- * GET_OLD = ' '
- * NO_MAKTX = 'X'
- * NO_STATX = 'X'
- * CHECK_DELETED = ' '
- * NO_READ = ' '
- * CHECK_VBKZ_DEL = 'X'
- * I_ARCHIVE = ' '
- tables
- * ARESB_EXP =
- resbd_get = lt_resb_get[].
- loop at lt_resb_get into lw_resb_get where rsnum = lt_resb-rsnum
- and rspos = lt_resb-rspos
- and rsart = lt_resb-rsart..
- if <fs_data2>-sortf is not initial.
- lw_resb_get-sortf = <fs_data2>-sortf.
- endif.
- modify lt_resb_get from lw_resb_get index sy-tabix.
- endloop.
-
- call function 'CO_BC_UPDATE_CMP_OF_ORDERS'
- * EXPORTING
- * FLG_BANF_UPD = YX
- * FLG_CALC_CHK = YX
- * FLG_LVS_CHK = YX
- * IMPORTING
- * FLG_LVS =
- tables
- resbd_get = lt_resb_get[].
-
-
- call function 'BAPI_TRANSACTION_COMMIT'
- exporting
- wait = 'X'.
-
- call function 'CO_XT_ORDER_INITIALIZE'.
-
- endif.
-
- else.
-
- call function 'BAPI_TRANSACTION_ROLLBACK'.
-
-
- endif.
-
- wait up to 1 seconds.
-
- endloop.
-
-
- endloop.
- endloop.
3.删除
- data:lt_resb type table of resb with header line.
- data:lt_return type coxt_t_bapireturn with header line.
- data:ls_return type bapiret2.
- data it_resb type coxt_t_resbdel with header line .
- data:lv_matnr type mara-matnr,
- lv_aufnr type afko-aufnr,
- lv_message type string,
- lv_error type c.
-
-
- data:ft_return type table of bapiret2 with header line.
-
- data:begin of lt_aufnr occurs 0,
- aufnr type afpo-aufnr,
- end of lt_aufnr.
-
- refresh lt_aufnr.
-
- loop at gt_data3 assigning <fs_data3> where check eq 'X'
- and cellcolor is initial
- and icon ne icon_led_green.
- lt_aufnr-aufnr = <fs_data3>-aufnr.
- append lt_aufnr.
- clear lt_aufnr.
- endloop.
-
- sort lt_aufnr.
- delete adjacent duplicates from lt_aufnr.
-
- loop at lt_aufnr.
-
- clear:lt_resb[],lt_resb,lv_message,ft_return[],ft_return,ls_return,lv_error,
- lt_return[],lt_return,it_resb[],it_resb.
-
- loop at gt_data3 assigning <fs_data3> where aufnr eq lt_aufnr-aufnr.
-
- clear:lv_matnr,lv_aufnr.
-
- lv_matnr = <fs_data3>-matnr.
- lv_aufnr = <fs_data3>-aufnr.
-
- call function 'CONVERSION_EXIT_ALPHA_INPUT'
- exporting
- input = lv_matnr
- importing
- output = lv_matnr.
- call function 'CONVERSION_EXIT_ALPHA_INPUT'
- exporting
- input = lv_aufnr
- importing
- output = lv_aufnr.
-
- if <fs_data3>-potx1 is initial and p_bf ne 'X'.
- select rsnum rspos matnr posnr sortf aufnr
- into corresponding fields of table lt_resb
- from resb
- where aufnr eq lv_aufnr
- and matnr eq lv_matnr
- and xloek ne 'X'.
- else.
- select rsnum rspos matnr posnr sortf aufnr
- into corresponding fields of table lt_resb
- from resb
- where aufnr eq lv_aufnr
- and matnr eq lv_matnr
- and xloek ne 'X'
- and potx1 eq <fs_data3>-potx1.
- endif.
-
- if lt_resb[] is initial.
- <fs_data3>-mseg = '无该物料可删除'.
- <fs_data3>-icon = icon_led_red.
- continue.
- endif.
-
- endloop.
-
- call function 'CO_XT_COMPONENTS_DELETE'
- exporting
- it_resbkeys_to_delete = it_resb[]
- tables
- ct_bapireturn = lt_return
- exceptions
- delete_failed = 1
- others = 2.
-
- if lt_return[] is initial.
- *刷新变量
- perform change_flag_set(saplcozv).
- *数据更新到DB
- call function 'CO_XT_ORDER_PREPARE_COMMIT'
- importing
- es_bapireturn = ls_return
- e_error_occurred = lv_error.
-
- if ( ls_return-type = 'S' or ls_return-type = 'W' or ls_return-type = 'I' )
- or ls_return is initial.
- *DB COMMMIT
- call function 'BAPI_TRANSACTION_COMMIT'
- exporting
- wait = 'X'.
- *刷新变量
- call function 'CO_XT_ORDER_INITIALIZE'.
-
- loop at gt_data3 assigning <fs_data3> where aufnr eq lt_aufnr-aufnr.
- <fs_data3>-mseg = '删除成功'.
- <fs_data3>-icon = icon_led_green.
- endloop.
-
-
- else.
- clear: lv_error,ls_return.
- call function 'BAPI_TRANSACTION_ROLLBACK'.
- endif.
-
- else.
-
- call function 'BAPI_TRANSACTION_ROLLBACK'.
-
-
- loop at gt_data3 assigning <fs_data3> where aufnr eq lt_aufnr-aufnr.
- <fs_data3>-mseg = lv_message.
- <fs_data3>-icon = icon_led_red.
- endloop.
-
- clear lv_message.
-
- endif.
-
- endloop.
USE BAPI_ALM_ORDER_MAINTAIN TO CREATE OR CHANGE PM WORK ORDER
最近做一个sap和外部程序的接口,外部应用程序需要创建PM订单,于是我找到了BAPI_ALM_ORDER_MAINTAIN,然后做了一些测试,这是个能够创建、修改PM订单的BAPI。它需要的一些参数如下:
IT_METHODS LIKE BAPI_ALM_ORDER_METHOD
处理方法,必选项,存储CREATE CREATETONOTIF CHANGE DELETE RELEASE TECHNICALCOMPLETE ATPCHECK CALCULATE SCHEDULE DELELTEDSEX ADD SAVE DIALOG TRACE这些处理动作。
IT_HEADER LIKE BAPI_ALM_ORDER_HEADERS_I
订单的header信息
IT_HEADER_UP LIKE BAPI_ALM_ORDER_HEADERS_UP
修改的订单的header信息,如果是对订单header的修改,需要将对应字段置X
IT_HEADER_SRV LIKE BAPI_ALM_ORDER_SRVDAT_E
对象服务信息
IT_HEADER_SRV_UP LIKE BAPI_ALM_ORDER_SRVDAT_UP
IT_USERSTATUS LIKE BAPI_ALM_ORDER_USRSTAT
用户状态信息
IT_PARTNER LIKE BAPI_ALM_ORDER_PARTN_MUL
合作伙伴信息
IT_PARTNER_UP LIKE BAPI_ALM_ORDER_PARTN_MUL_UP
IT_OPERATION LIKE BAPI_ALM_ORDER_OPERATION
工序信息
IT_OPERATION_UP LIKE BAPI_ALM_ORDER_OPERATION_UP
IT_RELATION LIKE BAPI_ALM_ORDER_RELATION
IT_RELATION_UP LIKE BAPI_ALM_ORDER_RELATION_UP
IT_COMPONENT LIKE BAPI_ALM_ORDER_COMPONENT
组件信息
IT_COMPONENT_UP LIKE BAPI_ALM_ORDER_COMPONENT_UP
IT_TEXT LIKE BAPI_ALM_TEXT
IT_TEXT_LINES LIKE BAPI_ALM_TEXT_LINES
EXTENSION_IN LIKE BAPIPAREX
RETURN LIKE BAPIRET2
返回消息
ET_NUMBERS LIKE BAPI_ALM_NUMBERS
返回订单编码信息
1、创建一个带工序的订单
CLEAR IT_METHODS.
IT_METHODS-REFNUMBER = '1'.”对应下面header表中相应行的数据
IT_METHODS-OBJECTTYPE = 'HEADER'.”需要操作的对象类型
IT_METHODS-METHOD = 'CREATE'.”相应动作
IT_METHODS-OBJECTKEY = '%00000000001'.”PM订单号,我们用的系统内部给号,此处使用临时编码'%00000000001',bapi结束时,会返回真正的订单号
APPEND IT_METHODS.
CLEAR IT_METHODS.
IT_METHODS-REFNUMBER = '1'.”对应下面OPERATION表中相应行的数据
IT_METHODS-OBJECTTYPE = 'OPERATION'.”需要操作的对象类型
IT_METHODS-METHOD = 'CREATE'.”相应动作
IT_METHODS-OBJECTKEY = '%00000000001'.”PM订单号,我们用的系统内部给号,此处使用临时编码'%00000000001',bapi结束时,会返回真正的订单号
APPEND IT_METHODS.”多个工序时,要加入多条数据,REFNUMBER 对应OPERATION的行数
CLEAR IT_METHODS.
IT_METHODS-METHOD = 'SAVE'.”最后要插入一个save或dialog方法,否则bapi会报错
APPEND IT_METHODS.”IT_METHODS已经填充完毕
"填充header数据
IT_HEADER-ORDERID = '%00000000001'.”临时订单号
IT_HEADER-ORDER_TYPE = 'PM11'..”订单类型
IT_HEADER-EQUIPMENT = ‘JB200101’.
IT_HEADER-SHORT_TEXT= 'PM ORDER TEXT'.
.........
APPEND IT_HEADER
"填充工序数据表
IT_OPERATION-ACTIVITY = ‘0010’.”operation num
IT_OPERATION-DESCRIPTION = ‘operation text’.
IT_OPERATION-CONTROL_KEY = 'PM01'.”control key
APPEND IT_OPERATION."多个工序加入多条,要和IT_method对应。
CALL FUNCTION 'BAPI_ALM_ORDER_MAINTAIN'
TABLES
IT_METHODS = IT_METHODS
IT_HEADER = IT_HEADER
* IT_HEADER_UP =
* IT_HEADER_SRV =
* IT_HEADER_SRV_UP =
* IT_USERSTATUS =
* IT_PARTNER =
* IT_PARTNER_UP =
IT_OPERATION = IT_OPERATION
* IT_OPERATION_UP =
* IT_RELATION =
* IT_RELATION_UP =
* IT_COMPONENT =
* IT_COMPONENT_UP =
* IT_TEXT =
* IT_TEXT_LINES =
* EXTENSION_IN =
RETURN = RETURN
ET_NUMBERS = ET_NUMBERS
.
然后判断RETURN中的消息,做BAPI_TRANSACTION_COMMIT或者BAPI_TRANSACTION_ROLLBACK,这样就创建了一个PM订单。
2、修改一个PM订单的组件信息。
CLEAR IT_METHODS.
IT_METHODS-REFNUMBER = '1'.
IT_METHODS-OBJECTTYPE = 'COMPONENT'."
IT_METHODS-METHOD = 'CHANGE'.
IT_METHODS-OBJECTKEY = ‘90012343’.“订单号
APPEND IT_METHODS.”如果修改多个组件,要加入多条
CLEAR IT_METHODS.
IT_METHODS-METHOD = 'SAVE'.
APPEND IT_METHODS.
CLEAR IT_COMPONENT.
IT_COMPONENT-RESERV_NO = ‘18933‘.“预留号
IT_COMPONENT-RES_ITEM = ’1‘.预留项目
IT_COMPONENT-WITHDRAWN = 'X'.“最后发货标识,要修改这个字段
APPEND IT_COMPONENT.”如果修改多个组件,要加入多条
IT_COMPONENTUP-WITHDRAWN = 'X'.“最后发货标识,要修改哪个字段,需要在UP表中将该字段值为X
APPEND IT_COMPONENTUP.”如果修改多个组件,要加入多条
CALL FUNCTION 'BAPI_ALM_ORDER_MAINTAIN'
TABLES
IT_METHODS = IT_METHODS
* IT_HEADER =
* IT_HEADER_UP =
* IT_HEADER_SRV =
* IT_HEADER_SRV_UP =
* IT_USERSTATUS =
* IT_PARTNER =
* IT_PARTNER_UP =
* IT_OPERATION =
* IT_OPERATION_UP =
* IT_RELATION =
* IT_RELATION_UP =
IT_COMPONENT = IT_COMPONENT
IT_COMPONENT_UP = IT_COMPONENTUP
* IT_TEXT =
* IT_TEXT_LINES =
* EXTENSION_IN =
RETURN = RETURN
ET_NUMBERS = ET_NUMBERS
.
然后做transaction commit或rollback操作就OK了
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。