How to create an own switch with the Switch Framework from SAP?

You may have experienced the case, that you must implement something, and then you need to build a switch to simply turn on or off your implementation or a part of it. For that, SAP has implemented the Switch Framework, where you can simply define states of “functions” via switches.

In this short demo, I want to show you how to define a such switch, how to embed it into the Switch Framework Browser and finally how to use it in your implementation to check, if the switch state is active or not.

Definition

To create a new switch, enter the transaction SFW1, where you can define a new name of the switch state. Note that this switch should have a meaningful name, since it will be later visible to the key users as well.

Select “normal switch” and enter a short text.

After that, we have the option to assign the switch to a business function or create a new one. Since we just want to create a switch, we also need to create a new business function.

Note: In most cases, please define your own business function set (SFW3) and/or business function (SFW2) to not customize or even modify the standard.

A small showcase how to create at least a business function, which can later be found via the switch framework browser.

Now when we have business function we can assign it to an existing business function set or create again a new one. In this case we assign it directly to UTILITIES.

Then don’t forget to activate the switch and functions.

Usage

Now open the Switch Framework Browser by the transaction SFW_BROWSER, you can now see there your switch, which you have created previously.

The red lights next to it indicates, that it is currently turned off.

To manage the switch you need the to open the Switch Framework Customizing (SFW5). There you can activate the business function with its corresponding switches:

You can see in the set UTILITIES our function.

On the right side, you will find a check box, which you can check. Then you only have to save the changes.

After you have confirmed the change, you will soon see a light bulb next to it lightning. This means, that now the business function is active and so also the switch.

Implementation

In your implementation, there is a cool class called CL_ABAP_SWITCH, which you can use to simply check, if there the switch is turned on or off. Or if the switch exists.

Now when you want to check the state of your function, we execute the methode GET_SWITCH_STATE and enter the ID of the switch:

As the result, we receive a “F” meaning for false. As soon as we activate the business function, we receive then the return state “T” for true.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Ads Blocker Image Powered by Code Help Pro

Ad blocker detected

We have detected that you are using extensions to block ads. Please support us by disabling your ad blocker.

Powered By
Best Wordpress Adblock Detecting Plugin | CHP Adblock