Add A Custom Screen On Purchase Requisition Header - SAP Community
Add A Custom Screen On Purchase Requisition Header - SAP Community
m
m
Products and Technology Groups Partners Topics Events What's New Get Star
u
ni
t
y
SAP Community Products and Technology Enterprise Resource Planning ERP Blogs by Members
Add a Custom Screen on Purchase Requisition Header
former_member249594
Participant
2017 Jan 11 8:43 AM
13 Kudos 36,042
I had saw some threads/posts in SAP forums, they were asking for the solutions on how
to adding a custom screen/tab on the purchase requisition. But just as my knowledge,
SAP has not provided any user-exit/Badi/SMOD for enhancing the screen of header part
of purchase requisition.
And as we also know, purchase requisition database designing is different from other
businesses object documents. A general designing of database table for business
documents should commonly have Header and Items, some has Schedule Lines. For
example, EKKO and EKPO for purchase order, VBAK and VBAP for sales order, BKPF
and BSEG for FI documents……
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 1/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
For purchase requisition, it seems that the data is stored on item level, we only have
EBAN for purchase requisition (other database table is not taken into account in this blog,
for example account assignment table EBKN).
No standard enhancement and even no database design for purchase requisition header.
Well, it seems that it is not possible to adding a custom screen for purchase requisition
header level.
Some years ago we really cannot do it unless we put lots of effort on changing standard
program. Of course this approach is hardly acceptable.
But now, thanks for the new generation of enhancement technique, we can achieve the
requirement by the implicit enhancement, and plus some SMOD/CMOD enhancement
and Badi.
In this document, I would like to share two solutions on how to make a custom header for
purchase requisition. Actually, I like the first one(And I think most of you too)
The result of the idea is we have an enhancement function for purchase requisition, but I
hope the idea can also provide us a new thinking for other similar enhancement
requirements.
As everyone knows, the transactions for purchase requisition generally include ME51N,
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 2/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
For the purchase requisition application, the main screen is 0014 of program SAPLMEGUI
(or function group MEGUI), and GUI Status is REQ of program SAPLMEGUI (or function
group MEGUI).
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 3/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
Generally, there only a Texts subscreen on the tabstrip. If you press F1 help on the
screen field, you will find the program of screen editor is different from the program of
the main screen.
By debugging, I found the function module MEGUI_BUILD_REQ_HEADER_PLUGIN is
used for integrated to components of tabstrip, and the text editor is plus to tabstrip in this
function module.
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 4/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
When I investigate the program at this point, I believe we can add a new subscreen (or
more than one) onto the tabstrip by adopting the similar approach. (Yes, this is my idea
on first solution)
Also by debugging, I found the application GUI Status is set in method PBO of class
CL_WINDOW_MM (Inheriting from class CL_COMPOSITE_SCREEN_VIEW_MM), and the
GUI Status is determined by method EXCLUDING_FUNCTIONS. The attributes DYNPRO
and PROG indicate the current screen and program.
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 5/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
OK, I believe some people have got another idea on the solution now.
Yes, we can develop a new custom program and insert a GUI Status as the program
component, and we also add a new button, saying Custom Header, into the Application
Toolbar of the GUI Status. Then we can replace the original standard GUI status
(l_pfstatus) and its program (l_pfprogram) by our custom objects. The best replacing
position, of cause, should be located at the end of method EXCLUDING_FUNCTIONS,
and everyone knows we can do it by implicit enhancement.
It is better to copy the standard GUI Status REQ to our new custom GUI Status, so that
we can preserve the original buttons and menus (Actually, this is very important.
Otherwise we will lose lots of functionalities when processing a purchase requisition).
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 6/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
But don’t forget that application program needs to response the new button.
Thanks the new generation enhancement technique again, we can place an implicit
enhancement at the end of this method, so that the program can response the user
command.
Beside the function group MEGUI, there has a function group MEREQ inside the whole
application. This function group plays the role of processing purchase requisition
document; it just looks like the Model of MVC pattern. There have lots of local classes in
this function group; I would like to mention two local classes, which are involved in my
document.
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 7/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
My demo business requirement is: Users want to add two subscreens on the tabstrip of
purchase requisition header, one is used for storing the related sales data of PR, another
is used for storing procurement planning data of the PR.
2.1 Step 1 – Create a Database table for custom header of purchase requisition:
Create a new database table in SE11 ABAP dictionary. In my case, the database table is
ZEBAN_HEADER.
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 8/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
1 METHOD ZZGET_NEXT_SUBVIEW_COUNT .
2 RE_COUNT = LINES( SUBVIEWS ) + 1.
3 ENDMETHOD.
This method is used for counting the subview (subscreen) of the tabstrip
2.3 Step 3 - Create a function group as the core processing logic of the enhancement,
and at the meantime, it also provides subscreens.
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 9/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
There have two INCLUDE programs in the TOP. I believe lots of ABAP programmers are
familiar with LMEVIEWSF01, which is used in enhancements on purchase order
subscreens.
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 10/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
*&------------------------------------------------------------
---------*
*& Include LZME51N_HEADER_ENHMCLS
*&------------------------------------------------------------
---------*
CLASS lcl_custom_header DEFINITION
INHERITING FROM cl_foreign_application_view_mm.
PUBLIC SECTION.
METHODS: constructor
IMPORTING im_dynpro TYPE sy-dynnr
im_prog TYPE sy-repid
im_priority TYPE i OPTIONAL
im_foreign_prog TYPE sy-repid
im_foreign_dynpro TYPE sy-dynnr
im_metafield TYPE
mmpur_metafield.
PROTECTED SECTION.
METHODS: build_dynpro_fields REDEFINITION.
METHODS: transport_from_model REDEFINITION.
PRIVATE SECTION.
DATA: custom_metafield TYPE mmpur_metafield.
ENDCLASS. "lcl_custom_header DEFINITION
*-------------------------------------------------------------
---------*
* CLASS lcl_custom_header IMPLEMENTATION
*-------------------------------------------------------------
---------*
*
*-------------------------------------------------------------
---------*
CLASS lcl_custom_header IMPLEMENTATION.
METHOD constructor.
41 im_foreign_prog = im_foreign_prog
42 im_foreign_dynpro = im_foreign_dynpro.
43 custom_metafield = im_metafield.
44 ENDMETHOD. "CONSTRUCTOR
45 METHOD build_dynpro_fields.
46 DATA: l_dynpro_entry LIKE LINE OF my_dynpro_fields.
47 l_dynpro_entry-metafield = custom_metafield.
48 INSERT l_dynpro_entry INTO TABLE my_dynpro_fields.
49 ENDMETHOD. "BUILD_DYNPRO_FIELDS
50 METHOD transport_from_model.
foreign_application_ok = mmpur_yes.
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 12/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
Screen
Description Purpose
Number
Subscreen Used for the screen container of
9899
Container other two subscreens
Used for displaying/inputting the
9900 Subscreen - Sales
related sales data of PR
Subscreen - Used for displaying/inputting the
9901
Procument related procurement data of PR
Subscreen 9899:
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 13/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
Above PBO and PAI modules are located at the INCLUDE program LMEVIEWSF01.
Subscreen 9900:
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 14/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
The fields on 9900 are getting from custom table ZEBAN_HEADER (We had declared it in
the TOP INCLUDE program by TABLES statement).
Customer PO - ZEBAN_HEADER-BSTKD
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 15/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 16/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
1 *-------------------------------------------------------------
2 ---------*
3 ***INCLUDE LZME51N_HEADER_ENHMO01.
4 *-------------------------------------------------------------
5 ---------*
6 *&------------------------------------------------------------
7 ---------*
8 *& Module MODIFY_CUSTOM_SCREEN OUTPUT
9 *&------------------------------------------------------------
10 ---------*
11 * text
12 *-------------------------------------------------------------
13 ---------*
14 MODULE modify_custom_screen OUTPUT.
15
16 IF processed_model IS BOUND.
17 CLEAR g_trtyp.
18 PERFORM get_transaction_type
19 IN PROGRAM saplmereq
20 IF FOUND
21 USING processed_model
22 CHANGING g_trtyp.
23 ELSE.
24 g_trtyp = 'A'.
25 ENDIF.
26
27 LOOP AT SCREEN.
28 IF g_trtyp = 'A'.
29 screen-input = '0'.
30 ELSE.
screen-input = '1'.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
ENDMODULE. " MODIFY_CUSTOM_SCREEN OUTPUT
Subscreen 9901:
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 17/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
Country - ZEBAN_HEADER-LAND1
Region - ZEBAN_HEADER-REGIO
The PBO module of 9901 is same as 9900, I don't demonstrate at here again.
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 18/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 19/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
*&------------------------------------------------------------
---------*
*& Include LZME51N_HEADER_ENHMF01
*&------------------------------------------------------------
---------*
*&------------------------------------------------------------
---------*
*& Form ADD_SUBSCREN
*&------------------------------------------------------------
---------*
FORM add_subscren USING value(u_tab_subscreen) type
sydynnr
value(u_tab_label) type clike
value(u_tab_header_text) type
clike
uo_model_holder TYPE REF TO
CL_TABSTRIP_VIEW_MM.
DATA: lo_custom_view TYPE REF TO lcl_custom_header.
DATA: l_label_text TYPE string40,
l_header_text TYPE string40,
l_structure TYPE tabname VALUE 'ZEBAN_HEADER'.
DATA: l_repid TYPE syrepid VALUE 'SAPLZME51N_HEADER_ENHM'.
l_label_text = u_tab_label.
l_header_text = u_tab_header_text.
40 EXPORTING
41 im_screen_view = lo_custom_view
42 im_position = uo_model_holder-
>zzget_next_subview_count( ).
SET HANDLER lo_custom_view-
>if_observer_mm~handle_subject_changed
FOR uo_model_holder.
SET HANDLER uo_model_holder-
>if_observer_mm~handle_subject_changed FOR
lo_custom_view.
ENDIF.
ENDFORM. " ADD_SUBSCREN
2.6 Step 6 – Insert below function modules into the function group
ZME51N_HEADER_ENHM.
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 21/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
1 FUNCTION zpr_check_transaction_state .
2 *"------------------------------------------------------------
3 ----------
4 *"*"Local Interface:
5 *" IMPORTING
6 *" REFERENCE(IM_BANFN) TYPE BANFN
7 *" CHANGING
8 *" REFERENCE(CH_CHANGED) TYPE FLAG OPTIONAL
9 *"------------------------------------------------------------
10 ----------
11 DATA: l_count TYPE i.
DATA: ls_custom_header TYPE zeban_header.
12 g_original_changed_flag = ch_changed. "backup the original
13 'changed' indicator
14 CHECK ch_changed IS INITIAL.
15 SELECT COUNT( * ) INTO l_count FROM eban
16 WHERE banfn = im_banfn.
17 CHECK l_count >= 1.
18 *THE PROCESSED PR IS EXISTED IN DB
19 SELECT SINGLE * INTO ls_custom_header
20 FROM zeban_header
21 WHERE banfn = im_banfn.
22 IF ls_custom_header-vbeln <> zeban_header-vbeln OR
23 ls_custom_header-bstkd <> zeban_header-bstkd OR
24 ls_custom_header-sbudget <> zeban_header-sbudget OR
25 ls_custom_header-pplan <> zeban_header-pplan OR
26 ls_custom_header-land1 <> zeban_header-land1 OR
27 ls_custom_header-regio <> zeban_header-regio.
28 * THE CUSTOM FIELDS IN RUNTIME IS DIFFERENT FROM DB
29 * THE PR HAS BEEN CHANGED
30 ch_changed = 'X'.
ENDIF.
ENDFUNCTION.
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 22/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
1 FUNCTION zpr_custom_header_tab_add.
2 *"------------------------------------------------------------
3 ----------
4 *"*"Local Interface:
5 *" IMPORTING
6 *" REFERENCE(IM_O_MODEL_HOLDER) TYPE REF TO
7 CL_TABSTRIP_VIEW_MM
8 *"------------------------------------------------------------
9 ----------
10 *add subscreen for sales
11 PERFORM add_subscren
12 USING '9900'
13 'Custom Header- Sales' "tab label
14 'ADDITIONAN HEADER - Sales' "header text
15 im_o_model_holder.
16 *add subscreen for procurement
17 PERFORM add_subscren
18 USING '9901'
19 'Custom Header- Procurement' "tab label
'ADDITIONAN HEADER - Procurement' "header
text
im_o_model_holder.
ENDFUNCTION.
1 FUNCTION zpr_export_buffer.
2 *"------------------------------------------------------------
3 ----------
4 *" EXPORTING
5 *" REFERENCE(EX_BANFN) TYPE BANFN
6 *" REFERENCE(EX_ORIGINAL_CHANGED) TYPE FLAG
7 *"------------------------------------------------------------
8 ----------
9 ex_banfn = zeban_header-banfn.
10 ex_original_changed = g_original_changed_flag.
CLEAR g_original_changed_flag.
ENDFUNCTION.
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 23/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
1 FUNCTION zpr_header_custom_save.
2 *"------------------------------------------------------------
3 ----------
4 *"*"Local Interface:
5 *" IMPORTING
6 *" REFERENCE(IM_BANFN) TYPE BANFN
7 *"------------------------------------------------------------
8 ----------
9 DATA: l_changed TYPE flag.
10 DATA: l_count TYPE i.
11 SELECT COUNT( * ) INTO l_count
12 FROM eban
13 WHERE banfn = im_banfn.
14 IF l_count >= 1.
15 * not create mode
16 * we need to check if data has been changed
17 CALL FUNCTION 'ZPR_CHECK_TRANSACTION_STATE'
18 EXPORTING
19 im_banfn = im_banfn
20 CHANGING
21 ch_changed = l_changed.
22 CHECK l_changed IS NOT INITIAL.
23 ENDIF.
24 zeban_header-banfn = im_banfn.
25 CALL FUNCTION 'ZPR_HEADER_CUSTOM_SAVE_CORE' IN UPDATE TASK
26 EXPORTING
im_s_header = zeban_header.
ENDFUNCTION.
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 24/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
1 FUNCTION zpr_header_custom_save_core.
2 *"------------------------------------------------------------
3 ----------
4 *" IMPORTING
5 *" VALUE(IM_S_HEADER) TYPE ZEBAN_HEADER
6 *"------------------------------------------------------------
7 ----------
8 *please set this module as update module
MODIFY zeban_header FROM IM_S_HEADER.
ENDFUNCTION.
1 FUNCTION zpr_open.
2 *"------------------------------------------------------------
3 ----------
4 *" IMPORTING
5 *" REFERENCE(IO_HEADER) TYPE REF TO
6 IF_PURCHASE_REQUISITION
7 *"------------------------------------------------------------
8 ----------
9 DATA: ls_header TYPE mereq_header.
10 DATA: l_count TYPE i.
11 CLEAR zeban_header.
12 clear g_original_changed_flag.
13 ls_header = io_header->get_data( ).
14 SELECT COUNT( * ) INTO l_count FROM eban
15 WHERE banfn = ls_header-banfn.
16 CHECK l_count >= 1.
17 *THE PROCESSED PR IS EXISTED IN DB
18 SELECT SINGLE * FROM zeban_header
19 WHERE banfn = ls_header-banfn.
20 IF sy-subrc <> 0.
zeban_header-banfn = ls_header-banfn.
ENDIF.
ENDFUNCTION.
2.7 Step 7 – Apply implicit enhancement implementation to add the new subscreens
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 25/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
1 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
(1) Function Module MEGUI_BUILD_REQ_HEADER_PLUGIN, End
A
2 *$*$-Start: (1)-----------------------------------------------
----------------------------------$*$*
3 ENHANCEMENT 1 ZPR_CUSTOM_TAB_MEGUI. "active version
4 if sy-uname = 'CHENGANGRONG' AND
5 ( SY-TCODE = 'ME51N' OR
6 SY-TCODE = 'ME52N' OR
7 SY-TCODE = 'ME53N' OR
8 SY-TCODE = 'ME54N' ).
9 CALL FUNCTION 'ZPR_CUSTOM_HEADER_TAB_ADD'
10 EXPORTING
11 IM_O_MODEL_HOLDER = header_view.
12 ENDIF.
13 ENDENHANCEMENT.
14 *$*$-End: (1)-----------------------------------------------
----------------------------------$*$*
Once the above steps are done, you can see the two subscreens are appearing on the
tabstrip of PR header.
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 26/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
Based on the exporting parameter of the method, we know that this method is used for
returning the transaction states of the purchase requisition, for example, whether the
purchase requisition has been changed.
When users just change the data in the enhanced custom header screen but leave the
standard data unchanged (EBAN, EBKN, TEXT, etc), the application will not recognize
the changing of the document. So application will not trigger the saving process for the
document.
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 27/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
Because it has a CHECK statement in the method, we need to add the implicit
enhancement at the beginning of the method; otherwise the implemented codes will be
skipped under certain circumstance (for example, Create Mode, ME51N), see below
screenshot.
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 28/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
1 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
(1) Class LCL_REQ_HEADER, Interface IF_PURCHASE_REQUISITION,
Method GET_TRANSACTION_STATE, Start
A
2 *$*$-Start: (1)-----------------------------------------------
----------------------------------$*$*
3 ENHANCEMENT 1 ZPR_CUSTOM_TAB_MEREQ. "active version
4 if sy-uname = 'CHENGANGRONG' AND
5 SY-DYNNR = '0014' AND
6 ( SY-TCODE = 'ME51N' OR
7 SY-TCODE = 'ME52N' OR
8 SY-TCODE = 'ME53N' OR
9 SY-TCODE = 'ME54N' ).
10 IF my_state->changed IS INITIAL.
11 CALL FUNCTION 'ZPR_CHECK_TRANSACTION_STATE'
12 EXPORTING
13 im_banfn = my_state->header-banfn
14 CHANGING
15 CH_CHANGED = my_state->changed.
16 ENDIF.
17 endif.
18
19 ENDENHANCEMENT.
20 *$*$-End: (1)-----------------------------------------------
----------------------------------$*$*
2.9 Step 9 – Implement the Badi ME_PROCESS_REQ_CUST, and then insert below
codes into the method OPEN (It is easy to understand that application need to initialize
and read the custom header data when a new purchase requisition is opened).
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 29/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
1 METHOD if_ex_me_process_req_cust~open.
2 IF sy-uname = 'CHENGANGRONG' AND
3 ( sy-tcode = 'ME51N' OR
4 sy-tcode = 'ME52N' OR
5 sy-tcode = 'ME53N' OR
6 sy-tcode = 'ME54N' ).
7 CALL FUNCTION 'ZPR_OPEN'
8 EXPORTING
9 io_header = im_header.
10 ENDIF.
11 ENDMETHOD.
I use the EXIT function module EXIT_SAPLMEREQ_008 as saving position of the custom
header data (The SMOD enhancement is MEREQ001, it is a common enhancement, so
that I would not explain the CMOD project in detail).
Maybe someone will ask me why do not put the saving process at method POST of Badi
ME_PROCESS_REQ_CUST.
Actually I had tried but it doesn’t work in some case. For example, if user just changes
the custom header data but leave the standard data unchanged (EBAN, EBKN, TEXT,
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 30/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
etc), the application would not trigger the implemented POST method of
ME_PROCESS_REQ_CUST. So I have to make the enhancement position at
EXIT_SAPLMEREQ_008.
2.11 Step 11 – Add a new public method zzcustom_after_post into local class
LCL_REQ_HEADER.
Once we implement the custom header screen on purchase requisition, the system
behaviors of change mode (ME52N) will have some difference from the original
behaviors after saving the PR document.
The original behavior: the system will alternate the transaction type from change mode to
display mode (my_state->trtyp). And changed indicator my_state->changed will be reset
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 31/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
New behavior of our implementation: If user only changes custom header data but leave
standard data unchanged (EBAN, EBKN, TEXT, etc), the method prepare_post will raise
an exception no_changes before reset of the changed indicator and alternation of
transaction type. In this case the purchase requisition will leave to changed state and
change mode after saving the PR document. This is different from the original system
behavior.
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 32/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
To overcome the gap between original behavior and new behavior, we need to have a
method to set the transaction type and changed indicator as what it is in standard
behavior after the document is saved. So I introduce the new method
zzcustom_after_post for local class LCL_REQ_HEADER.
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 33/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
1 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
(1) Class LCL_REQ_HEADER, Vor den PUBLIC-Methoden
S
2 *$*$-Start: (1)-----------------------------------------------
----------------------------------$*$*
3 ENHANCEMENT 2 ZPR_CUSTOM_TAB_MEREQ. "active version
4 METHODS: zzcustom_after_post.
5 ENDENHANCEMENT.
6 *$*$-End: (1)-----------------------------------------------
----------------------------------$*$*
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 34/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
1 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
(1) Class LCL_REQ_HEADER, End
S
2 *$*$-Start: (1)-----------------------------------------------
----------------------------------$*$*
3 ENHANCEMENT 3 ZPR_CUSTOM_TAB_MEREQ. "active version
4 METHOD zzcustom_after_post.
5 me->my_state->trtyp = me->my_state->aktyp = anz.
6
7 me->my_state->changed = mmpur_no.
8 ENDMETHOD.
9 ENDENHANCEMENT.
10 *$*$-End: (1)-----------------------------------------------
----------------------------------$*$*
And please see Step 12 on how we using the new enhancement method.
2.12 Step 12 – Add an implicit enhancement at the POST method of local class
LCL_INSTANCE_FACTORY.
The POST method of local class LCL_INSTANCE_FACTORY is located at INCLUDE
program LMEREQF06 of function group MEREQ.
Just as I had mentioned at above some steps, if user only change the custom header
data but leave standard data unchanged (EBAN, EBKN, TEXT, etc), the application will
not recognize the changing of the document.
Although we had added an implicit enhancement at Step 8 for replacing the changed
indicator of the document, the application still doesn’t trigger the commit work, if no any
standard data is changed.
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 35/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
So we have to take a solution for triggering the commit work in case of standard data
unchanged.
At last, by debugging, I found the best implementation position is at the end of POST
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 36/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
method of LCL_INSTANCE_FACTORY.
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 37/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
(1) Class LCL_INSTANCE_FACTORY, Method POST, End
A
*$*$-Start: (1)-----------------------------------------------
----------------------------------$*$*
ENHANCEMENT 4 ZPR_CUSTOM_TAB_MEREQ. "active version
DATA: l_zzehm_banfn TYPE banfn.
DATA: ls_zzehm_hashed_entry TYPE hash_table_entry.
data: l_zzhm_original_changed type flag.
IF sy-uname = 'CHENGANGRONG' AND
sy-dynnr = '0014' AND
( sy-tcode = 'ME51N' OR
sy-tcode = 'ME52N' OR
sy-tcode = 'ME53N' OR
sy-tcode = 'ME54N' ).
CALL FUNCTION 'ZPR_EXPORT_BUFFER'
IMPORTING
ex_banfn = l_zzehm_banfn
ex_original_changed = l_zzhm_original_changed.
IF l_zzhm_original_changed IS INITIAL.
* no changed for PR data(standard DB data)
* program would not execute commit at previous step
* in this case, we have to execute commit so that
* the FM ZPR_HEADER_CUSTOM_SAVE_CORE can be submit to commit
* (see FM EXIT_SAPLMEREQ_008 and ZPR_HEADER_CUSTOM_SAVE)
IF im_no_commit EQ mmpur_no
AND im_wait EQ cl_mmpur_constants=>no .
COMMIT WORK.
ELSEIF im_no_commit EQ mmpur_no
AND im_wait EQ cl_mmpur_constants=>yes .
COMMIT WORK AND WAIT.
ENDIF.
ENDIF.
READ TABLE my_hash_table INTO ls_zzehm_hashed_entry
WITH KEY banf = l_zzehm_banfn.
IF sy-subrc = 0.
* resume the changed indicator for header state
ls_zzehm_hashed_entry-header->zzcustom_after_post( ).
ENDIF.
ENDIF.
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 38/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
38
39 ENDENHANCEMENT.
40 *$*$-End: (1)-----------------------------------------------
----------------------------------$*$*
And now you will see the method zzcustom_after_post is called after the commit, so that
the changed indicator and transaction type are reset.
1 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
(1) Include LMEREQFXX, End
S
2 *$*$-Start: (1)-----------------------------------------------
----------------------------------$*$*
3 ENHANCEMENT 5 ZPR_CUSTOM_TAB_MEREQ. "active version
4 include ZZMEREQ_ENHANCEMENT.
5 ENDENHANCEMENT.
6 *$*$-End: (1)-----------------------------------------------
----------------------------------$*$*
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 39/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
1 *&------------------------------------------------------------
2 ---------*
3 *& Include ZZMEREQ_ENHANCEMENT
4 *&------------------------------------------------------------
5 ---------*
6 FORM get_transaction_type
7 USING uo_model TYPE REF TO if_model_mm
8 CHANGING c_trtyp TYPE trtyp.
9 DATA: lo_req_header TYPE REF TO lcl_req_header.
10
11 mmpur_dynamic_cast lo_req_header uo_model.
12 CHECK NOT lo_req_header IS INITIAL.
13 c_trtyp = lo_req_header->my_state->trtyp.
ENDFORM. "get_transaction_type
If we have no this subroutine, the subscreens PBO can’t get the transaction type of PR,
that means we can’t modify INPUT attribute of the subscreen fields by different
transactions types (please see PBO module MODIFY_CUSTOM_SCREEN).
Well , the first solution is finished. We can see there have tow custom subscreens on the
tabstrip of the PR header.
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 40/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
Although I really like the first solution, I would like to show you my second solution.
The demo requirement of second solution is: User want to have a button (In my case is
Custom Header) on application toolbar of PR screen. If the button is clicked, a dialog box
screen is generated and, the custom header data can be display/input on the screen.
This second solution will have lots of common part with the first solution, I only
demonstrate the necessary steps for this solution.
2.1 Step 1 – Insert below declaration into TOP INCLUDE of function group
ZME51N_HEADER_ENHM.
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 41/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
2.2 Step 2 – Create a GUI Status for replacing the original standard GUI status REQ
of SAPLMEGUI. And do not forget to copy/adjust the buttons from standard GUI status
REQ of SAPLMEGUI.
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 42/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 43/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
After adjusting the new GUI Status REQ from standard GUI Status REQ of SAPLMEGUI,
we need to add a new button into the application toolbar, so that we can develop the
logic for generating the custom header screen. In my case, the function code of new
button is ZCUSTOM, and also input the related icon text and preferred icon name.
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 44/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
2.3 Step 3 – Create a dialog box screen for custom header of purchase requisition.
I would not demonstrate the screen creation in detail, since it is just a common
development technique. And do not forget to create a dialog box GUI Status and title for
this new screen.
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 45/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 46/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 47/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
1 *&------------------------------------------------------------
2 ---------*
3 *& Module STATUS_0001 OUTPUT
4 *&------------------------------------------------------------
5 ---------*
6 * text
7 *-------------------------------------------------------------
8 ---------*
9 MODULE status_0001 OUTPUT.
10 SET PF-STATUS 'CUSTOM_DYN'.
11 SET TITLEBAR 'CUSTOM_DYN_TITLE'.
12 LOOP AT SCREEN.
13 IF screen-name = 'ZEBAN_HEADER-VBELN'.
14 IF g_trtyp = 'A'.
15 * display mode, input not possible
16 screen-input = '0'.
17 ELSE.
18 * change or create mode, input activated
19 screen-input = '1'.
20 ENDIF.
21 ENDIF.
MODIFY SCREEN.
ENDLOOP.
ENDMODULE. " STATUS_0001 OUTPUT
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 48/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
1 *-------------------------------------------------------------
2 ---------*
3 ***INCLUDE LZME51N_HEADER_ENHMI01.
4 *-------------------------------------------------------------
5 ---------*
6 *&------------------------------------------------------------
7 ---------*
8 *& Module USER_COMMAND_0001 INPUT
9 *&------------------------------------------------------------
10 ---------*
11 * text
12 *-------------------------------------------------------------
13 ---------*
14 MODULE user_command_0001 INPUT.
15 CASE okcode.
16 WHEN 'OK'.
17 GS_HEADER_BACKUP = ZEBAN_HEADER.
18 WHEN 'EXIT'.
19 ZEBAN_HEADER = GS_HEADER_BACKUP.
ENDCASE.
SET SCREEN 0.
LEAVE SCREEN.
ENDMODULE. " USER_COMMAND_0001 INPUT
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 49/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
In my case, the dialog box GUI Status for the screen 0001 is CUSTOM_DYN, and the GUI
title is CUSTOM_DYN_TITLE.
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 50/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 51/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
1 FUNCTION zpr_header_custom_screen_call.
2 *"------------------------------------------------------------
3 ----------
4 *" IMPORTING
5 *" REFERENCE(IM_O_MODEL) TYPE REF TO IF_MODEL_MM
6 *" REFERENCE(IM_TRTYP) TYPE TRTYP
7 *"------------------------------------------------------------
8 ----------
9 DATA: l_changed TYPE flag.
10 DATA: lo_processing_req TYPE REF TO if_purchase_requisition.
11 lo_processing_req ?= im_o_model.
12 g_trtyp = im_trtyp.
13 CHECK lo_processing_req IS BOUND.
14 lo_processing_req->get_transaction_state(
15 IMPORTING
16 ex_changed = l_changed ).
17 IF g_trtyp = 'H' AND
18 l_changed = space.
19 *create mode but no data is inputted
*a blank purchase requisition
20 MESSAGE 'Please input the PR data first......' TYPE 'S'
21 DISPLAY LIKE 'E'.
22 EXIT.
23 ENDIF.
24 main_okcode = sy-ucomm.
25 gs_header_backup = zeban_header.
26 CALL SCREEN '0001' STARTING AT 25 6
27 ENDING AT 88 10.
sy-ucomm = main_okcode.
ENDFUNCTION.
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 52/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
1 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
(1) Class CL_COMPOSITE_SCREEN_VIEW_MM, Method
EXCLUDING_FUNCTIONS, End
2 A
*$*$-Start: (1)-----------------------------------------------
3 ----------------------------------$*$*
4 ENHANCEMENT 1 ZPR_CUSTOM_TAB_COMP_SCREEN. "active version
5 IF sy-uname = 'CHENGANGRONG' AND
6 sy-dynnr = '0014' AND
7 ( sy-tcode = 'ME51N' OR
8 sy-tcode = 'ME52N' OR
9 sy-tcode = 'ME53N' OR
10 sy-tcode = 'ME54N' ).
11 IF dynpro = '0014' AND
12 prog = 'SAPLMEGUI'.
13 ch_pfprogram = 'SAPLZME51N_HEADER_ENHM'.
14 ch_pfstatus = 'REQ'.
15 ENDIF.
16 ENDIF.
17
18 ENDENHANCEMENT.
*$*$-End: (1)-----------------------------------------------
----------------------------------$*$*
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 53/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
Once we have above implementation, a new button will appear on the application tool
bar of purchase requisition applications (ME51N/ME52N/ME53N/ME54N).
In my demo case, if user click Custom Header button, then program will call a dialog box
screen 0001 in the enhancement function group ZME51N_HEADER_ENHM.
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 54/55
9/13/24, 9:43 PM Add a Custom Screen on Purchase Requisition Header - SAP Community
1 """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
(1) Class LCL_DOCUMENT_CMD,Follow
Interface IF_COMMAND_MM, Method
EXECUTE, End
2 A
*$*$-Start: (1)-----------------------------------------------
3 ----------------------------------$*$*
Privacy Terms of Use
https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/add-a-custom-screen-on-purchase-requisition-header/ba-p/13333143 55/55