Transaction Variants are very good for hiding the Screen Elements. Simple code snippet to get the Transaction code variant name.
When using Transaction Variants, the changes are kind of static – means you can’t hide the screen elements based on the field content. This code would get you the Transaction Variant which is being used for that particular transaction. Once known, you can make appropriate changes to screen fields based on the Transaction Variant name using LOOP AT SCREEN.
Get Current Transaction Variant Name
DATA : v_variant TYPE shdfv-tcvariant, v_client_dep TYPE char1. * Get the variant of current transaction CALL 'DY_GET_TX_VARIANT' ID 'VARIANT' FIELD v_variant ID 'CLIENT INDEPENDENT' FIELD v_client_dep. " V_VARIANT would contain the current Transaction Variant " V_CLIENT_DEP would contain if the Variant is client dependent
Get Transaction Variant using FM
As skrishna pointed out, you can also use the FM RS_HDSYS_GET_TC_VARIANT to do the same
call function 'RS_HDSYS_GET_TC_VARIANT' importing tcvariant = l_tcvariant flag_client_independent = l_xclientind rc = l_rc.
For Example : In Sales Order processing, you can set up a Transaction Variant in the customization for a Sales Order Type. If you want to override the value when you are in blah blah transaction variant, you can use this code snippet to get to know the transaction variant name.
Do you have a Code Snippet which you want to share, Submit Code Snippet here