It’s been a while since I put a post out about code, and since I’ve been spending a lot of time creating screens lately, I thought I’d drop a quick tidbit out there for any of you programmers out there. Lately, I’ve been creating screens to work as a configuration screen for one of our applications. What this means is that there are lots of screen elements, radial buttons, etc in order to make it look good. I have a table behind the scenes to hold all the information, but like normal screen design, you don’t make a table that goes 1 to 1 with the screen, it’s too inefficient.
Why do you care about any of this? Well, by following a standard naming convention, you can make life really easy on yourself. Let me give you an example. I have a screen with about 100 radial buttons (30 rows, some with 2 options, some with 3, some with 4). Well, by following a naming convention with a standard prefix, putting the field name in the same spot, and adding the occasional suffix, you can dynamically read the field name and make it work for everything you put on the screen without having to read every line.
In your PBO, you can do something like this:
LOOP AT SCREEN.
CLEAR: FIELD, VIS, I, Z_CONFIG_WA.
if screen-input = 0.
FIELD = SCREEN-NAME+3(4).
READ TABLE Z_CONFIG INTO Z_CONFIG_WA WITH KEY FIELD = FIELD GRPNAM = GRP.
IF SY-SUBRC <> 0.
READ TABLE Z_CONFIG INTO Z_CONFIG_WA WITH KEY FIELD = FIELD.
IF Z_CONFIG_WA-FIELD IS NOT INITIAL.
ASSIGN (SCREEN-NAME) TO <FIELD>.
<FIELD> = ‘X’.
<FIELD> = ”.
Now, some of the key things to notice, one is that the loop continues if you can’t input anything. this is purely to speed things up. Next, by using the position, you can check for the prefix. In this example, it’s CH_
Next, it finds the key field name to plug into the configuration table. Next up, it checks to make sure that the table entry exists in the custom configuration table. As long as it finds an entry, we use a field symbol to assign the value to the screen field.
The awesome part of this is that as long as you maintain a consistent naming scheme, you can set the values for multiple screens and reuse the code.
anyway, I hope this is useful for you.
If there’s anything we can do to help you out, please use the Contact Us Button above and let us know what we can do for you .
Thanks for reading,