You are on page 1of 3

SAP Note

    1334202 - How to get current action ID and transaction group  


Version   5     Validity: 15.05.2009 - active   Language   English (Master)

Header Data
Released On 15.05.2009 10:45:46
Release Status Released for Customer
Component SRM-EBP-CA-DEX Document Extensibility
Priority Recommendations / Additional Info
Category Consulting

Symptom
Within the ITS UI technology used in SRM releases older than SRM 6.0, system control variables like
SY-TCODE and SY-UCOMM were used in customer BAdI implementations to retrieve information of the
environment of the BAdI call.

Other Terms
SY-TCODE, SY-UCOMM, BAdI implementation, workaround

Reason and Prerequisites


Within the ITS UI technology used in older SRM releases, system control variables like SY-TCODE and
SY-UCOMM were used in customer BAdI implementations to retrieve information of the environment of
the BAdI call.
Since WebDynpro technology has in contrast to the SAPGUI technology no access to theses system
variables, this Note describes a workaround to substitute the usage of these variables.

Solution
The values for the transaction groups in this solution would substitute the usage of the system
variable SY-TCODE, formerly used in the context of the SAPGUI technology.
The values for the actions would substitute the usage of system variable SY-UCOMM.
The actions in SRM 6.0 and up were defined in a standardized way. The action values and the
corresonding set type are returned as defined in view "/SAPSRM/V_ACTSET". Corresponding constants
can be found in interface /SAPSRM/IF_PDO_ACTION_C.
The supported actions are associated with the buttons on the FPM (Floor Plan Manager) button row of
the OIF and GAF component.

DISCLAIMER:
This SAP Note describes UI specfic information.
There will be no guarantee, that the provided interface will stay stable, if the UI or the
global architecture would be changed.
This SAP Note is meant as substitute and workaraound for the system fields SY-TCODE,
SY_UCOMM used in BAdIs with ITS technology.
Any problems caused by applying this note is the responsibility of the customer
modification.

Suggested workaround:

To retrieve the values stored for the action and transaction code class
"/SAPSRM/CL_TRANSACTION_CONTEXT"
provides methods to get the values of the current action as well as the transaction group.
These method calls could be added to the coding of the method of the of the customer BAdI
implementation (e.g. "BBP_DOC_CHANGE_BADI").
The first step would be to get the instance of the transaction context class, i.e. method
"/SAPSRM/CL_TRANSACTION_CONTEXT=>/SAPSRM/IF_TRANSACTION_CONTEXT~GET_INSTANCE( )" needs to be called
to get an instance of the class.
The instance method "/SAPSRM/IF_TRANSACTION_CONTEXT->GET_CURRENT_ACTION( )" can be called to get the
currently executed action.
The returned action ID is filled with the action ID as it is used in the PDO layer and for metadata.
The instance method "/SAPSRM/IF_TRANSACTION_CONTEXT->GET_TRANSACTION_GROUP( )" can be called to get
the currently transaction context.
To destinguish between the supported transction groups, constants are available as attributes in
interface "/SAPSRM/IF_TRANSACTION_CONTEXT" (see example coding below).
This coding could be added for example in the change-BAdI or anywhere else in the coding that is run
when an action is executed.
Example coding could look like this:

"
DATA: lo_transaction_context TYPE REF TO /sapsrm/if_transaction_context.
lo_transaction_context = /sapsrm/cl_transaction_context=>/sapsrm/if_transaction_context~get_instance
( ) .

CASE lo_transaction_context->get_current_action( ).
  WHEN /sapsrm/if_pdo_action_c=>gc_action_edit.
                                      "'EDIT', PDO Action to Edit

    " ...

  WHEN /sapsrm/if_pdo_action_c=>gc_action_save.
                                      "'SAVE', PDO Action for Save

    " ...

ENDCASE.
CASE lo_transaction_context->get_transaction_group( ).
  WHEN if_transaction_context=>gc_ta_group_sc.
                              "Process Shopping Cart 'BUS2121'

    " ...

  WHEN if_transaction_context=>gc_ta_group_sc_wizard.
                              " Shopping Cart Wizard 'BUS2121_WIZARD'
    " ...

  WHEN if_transaction_context=>gc_ta_group_soco.
                              " Sourcing Cockpit 'SOCO'

    " ...

ENDCASE.
"

Workaround for other actions:


Actions that are not contained in the IDR (Identification Region) in the upper part of the browser
window, but in a detail screen, for example, are not registered automatically. In that case method
"GET_CURRENT_ACTION( )" does not return anything. If this is needed you can do the modification free
enhancement described below to register the action:

The necessary steps are to first find the event handler of the action. Then the action ID needs to
be set before and cleared after this event handler call. To read the action ID e.g. in a BAdI
implementation follow the steps described above.

Start application. Click right and select "More field help". A popup "More Field Help" appears
displaying technical details of the following topics:

l Web Dynpro Component

l View Information

l Field ID

Copy this information for use in transaction SE80.


Call transaction SE80 and navigate to the view of the Web Dynpro Component.
Click inside the layout tab of the view on the button or search for it in the hierarchy tree.
Select the button of the corresponding action. Copy the action name of the events attribute onAction
in the UI Element properties.
Go to the tab Methods and look for the method name of the Event Handler.
By this the Event Handler triggered by the button could be determined.

To make this information available the set method "SET_CURRENT_ACTION" needs to be called before the
event handler is triggered. This could be done in a pre coding part of the event handler method.
After the event handler was triggered a further call of method "SET_CURRENT_ACTION" is necessary to
clear the action value.
This could be done in a post-coding part of the event handler method.
I.e. the set method needs to be called twice, before the action is triggered by the event handler
and after the event handler call to clear the action value.

To create the pre- and post-method, proceed as follows:


Go to the methods tab of the view of the Web Dynpro component.
Enter the enhancement mode by pressing the "Enhance" button.
A popup "Select or Create Enhancement Implementation" appears.
Choose button "Create Enhancement Implementation" or select an existing one.
To create a new one enter a name for the Enhancement Implementation and a short text and press
button okay.
In the method tab, which is shown in status "Active(Enhancement Implemtn. # Inactive)" place the
cursor on the event handler method you determined above "ONACTION#".
Click on the button "Create Pre-Exit" in the same row. The button you can find on the right hand
side of the table control.
The editor of the "Pre-Exit of "ONACTION#"" can now be accessed.
Insert the adapted sample coding for the pre-exit below.
Check and activate the method.

Example coding could look like this:


"
* Start of pre-exit coding part

DATA lv_action              TYPE /sapsrm/pdo_action_type.


DATA lo_transaction_context TYPE REF TO /sapsrm/cl_transaction_context.

* Get instance of transaction object


*
lo_transaction_context ?
= /sapsrm/cl_transaction_context=>/sapsrm/if_transaction_context~get_instance( ).
* Set action id
*
lv_action = '...'.
lo_transaction_context->set_current_action( iv_current_action = lv_action ).
* End of pre-exit coding part
"

Proceed the same for the post-exit coding part:


Go back to the method list.
Click on the button "Create Post-Exit" in the same row. The button you can find on the right hand
side of the table control.
The editor of the "Post-Exit of "ONACTION#"" can now be accessed.
Insert the adapted sample coding for the post-exit below.
Check and activate the method.

* Begin of post-exit method coding part


DATA lv_action              TYPE /sapsrm/pdo_action_type.
DATA lo_transaction_context TYPE REF TO /sapsrm/cl_transaction_context.

* Get instance of transaction object


*
lo_transaction_context ?
= /sapsrm/cl_transaction_context=>/sapsrm/if_transaction_context~get_instance( ).

* Clear action id
*
lo_transaction_context->set_current_action( iv_current_action = space ).

* End of post-exit coding part


"

Validity
Software Component From Rel. To Rel. And Subsequent
SRM_SERVER 700 700  

701 701  

You might also like