How to read Function code from %GC_
This is my first blog, please feel free to point out the mistakes.
It’s always tedious to find out the function code in standard screens e.g. a pushbutton inside a custom control. In this case, say a button click event cannot be captured throughout the flow of the standard program on all places.
When we want to know the function code on our exact part of code it will be dynamically assigned like ‘%_GC 178 10’ and it cannot be used directly to know what the user function is. This might be the case we may face when we do any enhancement to the standard program.
I’ve searched through out the community network and couldn’t find a convincing way of knowing the function code. Any reference to the GUI is a private attribute (I don’t know why SAP wants to hid the function code)
After extensive analysis I found out a way to know the function code. I think it may help someone who is in search of such a scenario and so I am sharing the idea.
It’s a simple way of two method calls as explained below.
Scenario – I want to change the standard ‘PRINT’ (the one marked) for a supplementary customs declaration page. This subscreen is a custom control tab and buttons get dynamic function codes which are processed to know the actual function code (here it is ‘&PRINT_BACK’) when it’s necessary.
I have to capture the Print function code and insert our business logic instead of standard printing.
Inside the USER_COMMAND for the custom control, I’ve created an Implicit enhancement where the OK_CODE for this Print button is this junk ‘%_GC 178 10’.
There are no attribute to give the correct OK_CODE and so I have used the following logic to fetch the same
DATA: lo_control TYPE REF TO cl_gui_control,
lv_event TYPE string.
FIELD-SYMBOLS: <lo_event> TYPE REF TO cl_gui_event.
IF ok_code+0(4) EQ ‘%_GC’.
CALL METHOD cl_gui_control=>get_focus
control = lo_control
cntl_error = 1
cntl_system_error = 2
OTHERS = 3.
IF NOT lo_control IS INITIAL.
ASSIGN lo_control->cur_event TO <lo_event>.
CALL METHOD <lo_event>->get_event_param
pid = ‘0’
value = lv_event.
LV_EVENT carries the current function code. Here in this case, it contains &PRINT_BACK.