采购订单屏幕BADI增强.docx
- 文档编号:11211149
- 上传时间:2023-02-25
- 格式:DOCX
- 页数:26
- 大小:287.43KB
采购订单屏幕BADI增强.docx
《采购订单屏幕BADI增强.docx》由会员分享,可在线阅读,更多相关《采购订单屏幕BADI增强.docx(26页珍藏版)》请在冰豆网上搜索。
采购订单屏幕BADI增强
ME21N/ME22N/ME23N屏幕增强
这次的屏幕增强主要用到两个BADI:
ME_GUI_PO_CUST和ME_PROCESS_PO_CUST
这两个BADI都是有例子的,可以在se18那里按GoTo->Samplecode->Display来查看,也可以直接在SE24查看类CL_EXM_IM_ME_GUI_PO_CUST和CL_EXM_IM_ME_PROCESS_PO_CUST
现在我们对POheader加上自己的subscreen,SAP的例子提供的是对item增加subscreen.
Step1:
CreateFunctionGroup
仿照FunctionGroup MEPOBADIEX建一个FunctionGroup
我建的FunctionGroup如下图所示
Step2:
在FunctionGroup里建Screen,screennumber随便
在TOP里面加入对应屏幕的变量,这里我是直接用tables.
Step3:
给BADIME_GUI_PO_CUST建一个implementation
在PublicSection里加上TYPE-POOLS mmmfd .
Step4:
在MethodIF_EX_ME_GUI_PO_CUST~SUBSCRIBE,加入customsubscreen的设置代码
1.METHOD if_ex_me_gui_po_cust~subscribe.
2. DATA:
lw_subscribers TYPE mepo_subscribers.
3.
4.* we want to add a customer subscreen on the Header tab
5. CHECK im_application = 'PO'.
6. CHECK im_element = 'HEADER'.
7.
8. CLEAR lw_subscribers.
9. lw_subscribers-name = subscreen1.
10. lw_subscribers-dynpro = '0100'.
11. lw_subscribers-program = 'SAPLZCI_EKKODB'.
12. lw_subscribers-struct_name = 'CI_EKKODB'.
13. lw_subscribers-label = 'Zero test2'.
14. lw_subscribers-position = 11.
15. lw_subscribers-height = 8.
16. APPEND lw_subscribers TO re_subscribers.
17.ENDMETHOD.
METHODif_ex_me_gui_po_cust~subscribe.
DATA:
lw_subscribersTYPEmepo_subscribers.
*wewanttoaddacustomersubscreenontheHeadertab
CHECKim_application='PO'.
CHECKim_element='HEADER'.
CLEARlw_subscribers.
lw_subscribers-name=subscreen1.
lw_subscribers-dynpro='0100'.
lw_subscribers-program='SAPLZCI_EKKODB'.
lw_subscribers-struct_name='CI_EKKODB'.
lw_subscribers-label='Zerotest2'.
lw_subscribers-position=11.
lw_subscribers-height=8.
APPENDlw_subscribersTOre_subscribers.
ENDMETHOD.
Step5:
在IF_EX_ME_GUI_PO_CUST~MAP_DYNPRO_FIELDS,加入代码,使fieldname和它的数字编号关联起来
1.FIELD-SYMBOLS:
2.
3.LOOP AT ch_mapping ASSIGNING
4. CASE
5. WHEN 'LV_TEST1'.
6. WHEN 'LV_TEST2'.
7. WHEN 'LV_TEST3'.
8. ENDCASE.
9.ENDLOOP.
FIELD-SYMBOLS:
LOOPATch_mappingASSIGNING
CASE
WHEN'LV_TEST1'.
WHEN'LV_TEST2'.
WHEN'LV_TEST3'.
ENDCASE.
ENDLOOP.
Custom的field估计只能加9个,因为我在TYPE-POOLS mmmfd看到最大的是mmfd_cust_09,
这里也可以把一些standardfield弄到customsubscreen上.
经过以上五步,我们可以在ME23N看到customsubscreen,但在ME21N和ME22N依然是看不到的...这个是为什么,我还搞不清楚.
Step6:
给BADIME_PROCESS_PO_CUST建一个implementation
在PublicSection加入TYPE-POOLS mmmfd .
Step7:
在MethodIF_EX_ME_PROCESS_PO_CUST~FIELDSELECTION_HEADER加入代码,改变表ch_fieldselection的fieldstatus
'-'代表hidden,'+'或'.'表示editable,'*'代表display
1.METHOD if_ex_me_process_po_cust~fieldselection_header.
2. DATA:
lv_persistent TYPE mmpur_bool.
3. FIELD-SYMBOLS:
4.
5. DEFINE set_input.
6. read table ch_fieldselection assigning
7. if sy-subrc = 0.
8. if im_header->is_changeable( ) = mmpur_yes.
9.
10. else.
11.
12. endif.
13. endif.
14. END-OF-DEFINITION.
15.
16.* if the item is already on the database, we disallow to change field badi_bsgru
17. lv_persistent = im_header->is_persistent( ).
18.
19. set_input mmmfd_cust_01.
20. set_input mmmfd_cust_02.
21. set_input mmmfd_cust_03.
22.
23.ENDMETHOD.
METHODif_ex_me_process_po_cust~fieldselection_header.
DATA:
lv_persistentTYPEmmpur_bool.
FIELD-SYMBOLS:
DEFINEset_input.
readtablech_fieldselectionassigning
ifsy-subrc=0.
ifim_header->is_changeable()=mmpur_yes.
else.
endif.
endif.
END-OF-DEFINITION.
*iftheitemisalreadyonthedatabase,wedisallowtochangefieldbadi_bsgru
lv_persistent=im_header->is_persistent().
set_inputmmmfd_cust_01.
set_inputmmmfd_cust_02.
set_inputmmmfd_cust_03.
ENDMETHOD.
这里有两点注意下:
1.im_header->is_changeable()可以判断当前这些field是不是处于可编辑状态,如果是则为'X'.比如刚进TCODEME21N,ME22N它们是可编辑的,但当按save保存成功后,它们暂时是不可以编辑的,要再按
把它改回编辑状态才可以编辑,这里就实现了这个功能.
2.im_header->is_persistent()可以判断当这些field在数据库里有值了,它就是'X',当我们把数据写进表里就不想它被修改时,可以用这个来判断,比如把某个field设置成ME21N可编辑,ME22N不可编辑.
经过这七步,ME21N/ME22N/ME23N都可以看到这个customsubscreen,但所有自建field都是可编辑状态,必需做完第八步,才能正常显示
Step8:
在screen中调用2个module
这两个module存放在下图的程序里
注意:
如果不调用这两个module,BADI ME_GUI_PO_CUST下面的4个method都不会触发
TRANSPORT_FROM_MODEL
TRANSPORT_TO_DYNP
TRANSPORT_FROM_DYNP
TRANSPORT_TO_MODEL
Step9:
在MethodIF_EX_ME_GUI_PO_CUST~TRANSPORT_FROM_MODEL加入代码
把header的三个自建field传到attributedynp_data_pho里
1.METHOD if_ex_me_gui_po_cust~transport_from_model.
2. DATA:
lw_header TYPE REF TO if_purchase_order_mm,
3. lw_mepoheader TYPE mepoheader,
4. lw_customer TYPE ci_ekkodb.
5.*--------------------------------------------------------------------*
6.* system asks to transport data from the business logic into the view
7.*--------------------------------------------------------------------*
8.
9. IF im_name = subscreen1.
10.* is it an Header?
im_model can be header or item.
11. mmpur_dynamic_cast lw_header im_model.
12. CHECK NOT lw_header IS INITIAL.
13.* transport standard fields
14. lw_mepoheader = lw_header->get_data( ).
15.* store info for later use
16. MOVE-CORRESPONDING lw_mepoheader TO dynp_data_pbo.
17. ENDIF.
18.
19.ENDMETHOD.
METHODif_ex_me_gui_po_cust~transport_from_model.
DATA:
lw_headerTYPEREFTOif_purchase_order_mm,
lw_mepoheaderTYPEmepoheader,
lw_customerTYPEci_ekkodb.
*--------------------------------------------------------------------*
*systemaskstotransportdatafromthebusinesslogicintotheview
*--------------------------------------------------------------------*
IFim_name=subscreen1.
*isitanHeader?
im_modelcanbeheaderoritem.
mmpur_dynamic_castlw_headerim_model.
CHECKNOTlw_headerISINITIAL.
*transportstandardfields
lw_mepoheader=lw_header->get_data().
*storeinfoforlateruse
MOVE-CORRESPONDINGlw_mepoheaderTOdynp_data_pbo.
ENDIF.
ENDMETHOD.
Step10:
在MethodIF_EX_ME_GUI_PO_CUST~TRANSPORT_TO_DYNP加入代码
通过调用FM:
ZCI_EKKODB_PUSH把attribute
1.METHOD if_ex_me_gui_po_cust~transport_to_dynp.
2.
3. IF im_name = subscreen1.
4. CALL FUNCTION 'ZCI_EKKODB_PUSH'
5. EXPORTING
6. im_dynp_data = dynp_data_pbo.
7. ENDIF.
8.ENDMETHOD.
METHODif_ex_me_gui_po_cust~transport_to_dynp.
IFim_name=subscreen1.
CALLFUNCTION'ZCI_EKKODB_PUSH'
EXPORTING
im_dynp_data=dynp_data_pbo.
ENDIF.
ENDMETHOD.
Step11:
在IF_EX_ME_GUI_PO_CUST~TRANSPORT_FROM_DYNP加入代码
PAI事件时,把屏幕的值传到attribute dynp_data_pai,并且比较dynp_data_pbo和dynp_data_pai,确定自建field的值有所改变,把re_changed置为'X',这样IF_EX_ME_PROCESS_PO_CUST~PROCESS_HEADER就会触发.
1.METHOD if_ex_me_gui_po_cust~transport_from_dynp.
2. IF im_name = subscreen1.
3. CALL FUNCTION 'ZCI_EKKODB_POP'
4. IMPORTING
5. ex_dynp_data = dynp_data_pai.
6.
7. ENDIF.
8.
9. IF dynp_data_pai <> dynp_data_pbo.
10.* something has changed therefor we have to notify the framework
11.* to transport data to the model
12. re_changed = mmpur_yes.
13. ENDIF.
14.ENDMETHOD.
METHODif_ex_me_gui_po_cust~transport_from_dynp.
IFim_name=subscreen1.
CALLFUNCTION'ZCI_EKKODB_POP'
IMPORTING
ex_dynp_data=dynp_data_pai.
ENDIF.
IFdynp_data_pai<>dynp_data_pbo.
*somethinghaschangedthereforwehavetonotifytheframework
*totransportdatatothemodel
re_changed=mmpur_yes.
ENDIF.
ENDMETHOD.
Step12:
在IF_EX_ME_GUI_PO_CUST~TRANSPORT_TO_MODEL加入代码,把修改后的数据传到bussinessobject里
1.METHOD if_ex_me_gui_po_cust~transport_to_model.
2.
3. DATA:
lw_header TYPE REF TO if_purchase_order_mm,
4. lw_mepoheader TYPE mepoheader,
5. lw_customer TYPE ci_ekkodb,
6. lw_po_header_handle TYPE REF TO cl_po_header_handle_mm.
7.*--------------------------------------------------------------------*
8.* data have to be transported to business logic
9.*--------------------------------------------------------------------*
10. IF im_name = subscreen1.
11.
12.* is it an item?
im_model can be header or item.
13. mmpur_dynamic_cast lw_header im_model.
14. CHECK NOT lw_header IS INITIAL.
15. lw_mepoheader = lw_header->get_data( ).
16.* standard fields changed?
17. IF dynp_data_pbo-lv_test1 <> dynp_data_pai-lv_test1
18. OR dynp_data_pbo-lv_test2 <> dynp_data_pai-lv_test2
19. OR dynp_data_pbo-lv_test3 <> dynp_data_pai-lv_test3.
20.* update standard fields
21. lw_mepoheader-lv_test1 = dynp_data_pai-lv_test1.
22. lw_mepoheader-lv_test2 = dynp_data_pai-lv_test2.
23. lw_mepoheader-lv_test3 = dynp_data_pai-lv_test3.
24.
25. CALL METHOD lw_header->set_data
26. EXPORTING
27. im_data = lw_mepoheader.
28.
29. ENDIF.
30. ENDIF.
31.ENDMETHOD.
METHODif_ex_me_gui_po_cust~transport_to_model.
DATA:
lw_headerTYPEREFTOif_purchase_order_mm,
lw_mepoheaderTYPEmepoheader,
lw_customerTYPEci_ekkodb,
lw_po_header_handleTYPEREFTOcl_po_header_handle_mm.
*-----------------
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 采购 订单 屏幕 BADI 增强
![提示](https://static.bdocx.com/images/bang_tan.gif)