SAP: Setting Attributes of Screen Objects Dynamically

In visual basic, you could easily change any property of a specific control dynamically. We could also do that in ABAP. The sample code below will show you the basics on how to loop on all objects in a screen and change its property at runtime.

Let say we have a set of textbox in our screen that contains details of a single customer from table KNA1(General Data in Customer Master). Now we want to disable all textboxes that has already a value on it so that empty textboxes are the only editable field in the screen. To do this, we need to create a code on PBO(Process Before Output) module that will loop on all objects in the screen.

But before we proceed with the coding, we have to specify a MODIF ID or Modification Group ID. This will enable us to modify object before the selection screen is displayed, using the statement MODIFY SCREEN. The name of the modification group ID must be directly specified and can have a maximum length of three characters. There are two ways to set the mod ID of an object.

One is through code:

PARAMETERS: p_sample TYPE c LENGTH 10 MODIF ID GR1.

In this sample code, we set the mod ID of p_sample to “GR1″

Another way is through screen painter:

On the screen painter, select a specific object on the screen and then go to its attributes(double click or press F2). A window will appear showing the attributes of the object. You will see 4 textboxes in a row which is indicated as Groups. Type-in GR1 in the first textbox. Close the attributes window and click save.

We could now create the codes that will loop on all objects in a screen. In our case, we only want to loop on all textboxes in a screen so set the mod ID of all textboxes to GR1.

FIELD-SYMBOLS : <FS> TYPE ANY.

LOOP AT SCREEN.
  IF SCREEN-GROUP1 = ‘GR1′.
    ASSIGN (SCREEN-NAME) TO <FS>.
    IF <FS> IS NOT INITIAL.
      SCREEN-INPUT    = ‘0′.
    ENDIF.
  ENDIF.
  MODIFY SCREEN.
ENDLOOP.

Using the code above, one loop pass is executed for every screen element of the current dynpro. SCREEN-NAME is the name of the element, SCREEN-GROUP1 refers to the modification group of the element, and SCREEN-INPUT is the input property of the element. MODIFY SCREEN affects the attributes input, output and invisible.

The table below shows the components of screen and their assignment to the field properties in the dynpro.

Component

Length

Type

Meaning

Attribute

name

132

C

Name of the screen field

Name

group1

3

C

Modification group 1

Group 1

group2

3

C

Modification group 2

Group2

group3

3

C

Modification group 3

Group3

group4

3

C

Modification group 4

Group4

required

1

C

Field input is mandatory

Mandatory field

input

1

C

Field is ready for input

Entry

output

1

C

Field is for display only

The output is as follows:

intensified

1

C

Field is highlighted

Highlighted

invisible

1

C

Field is suppressed

Invisible

length

1

X

Field length

VisLg

active

1

C

Field is active

Input/Output/Invisible

display_3d

1

C

Three-dimensional box

Two-dimensional

value_help

1

C

Input help button display

Input helps

request

1

C

Input exists

-


0 Responses to “SAP: Setting Attributes of Screen Objects Dynamically”


  1. No Comments

Leave a Reply