Start of Content Area

Checkboxes and Radio Buttons with Function Codes  Locate the document in its SAP Library structure

In the Screen Painter, you can assign a function code (up to 20 characters long) to checkboxes and radio buttons.

Checkboxes and radio buttons without a function code behave like normal input/output fields. Clicking the object changes the contents of the field, but does not trigger the PAI event. (Clicking a pushbutton, on the other hand, always triggers the PAI event, even if it has an empty function code.)

When a function code is assigned to a checkbox or radio button, clicking it not only changes the field contents, but also triggers the PAI event and places the function code in the OK CODE field. For further information, refer to Reading Function Codes.

While it is possible to assign an individual function code to each checkbox, you can only assign one function code to all of the radio buttons in a group. When you assign a function code to a radio button in the Screen Painter, the system automatically applies the same function code to all of the other radio buttons in the group.

You can use checkboxes and radio buttons with function codes as follows:

As when you create pushbuttons, you should ensure when you assign function codes to checkboxes and radio buttons that they do not coincide with function codes from the GUI status.

Example

PROGRAM demo_dynpro_check_radio.

DATA: radio1(1) TYPE c, radio2(1) TYPE c, radio3(1) TYPE c,
      field1(10) TYPE c, field2(10) TYPE c, field3(10) TYPE c,
      box TYPE c.

DATA: ok_code TYPE sy-ucomm,
      save_ok TYPE sy-ucomm.

CALL SCREEN 100.

MODULE user_command_0100 INPUT.
  save_ok = ok_code.
  CLEAR ok_code.
  CASE save_ok.
    WHEN 'RADIO'.
      IF radio1 = 'X'.
        field1 = 'Selected!'.
        CLEAR: field2, field3.
      ELSEIF radio2 = 'X'.
        field2 = 'Selected!'.
        CLEAR: field1, field3.
      ELSEIF radio3 = 'X'.
        field3 = 'Selected!'.
        CLEAR: field1, field2.
      ENDIF.
    WHEN 'CANCEL'.
      LEAVE PROGRAM.
  ENDCASE.
ENDMODULE.

The next screen (statically defined) for screen 100 is itself. It has the following layout:

This graphic is explained in the accompanying text

The part of the element list relevant for the screen fields is as follows:

Name

Type

DefLg

Format

Function code

RADIO1

Radio

1

CHAR

RADIO

FIELD1

I/O

10

CHAR

 

RADIO2

Radio

1

CHAR

RADIO

FIELD2

I/O

10

CHAR

 

RADIO3

Radio

1

CHAR

RADIO

FIELD3

I/O

10

CHAR

 

BOX

Check

1

CHAR

CANCEL

OK_CODE

OK

20

OK

 

The input option for the screen fields FIELD1 to FIELD3 has been switched off in the Screen Painter.

The screen flow logic is as follows:

PROCESS BEFORE OUTPUT.

PROCESS AFTER INPUT.
  MODULE user_command_0100.

Each time you select one of the three radio buttons, the PAI event is triggered and the function code RADIO and the contents of the screen fields are passed to the ABAP program. The dialog module USER_COMMAND_100 fills the fields FIELD1 to FIELD3 according to the radio button that was selected. These field contents appear the next time the screen is sent.

The PAI event is also triggered if you select the checkbox. In this case, the function code CANCEL is passed to the ABAP program, and the dialog module USER_COMMAND_100 terminates the program immediately.