Skip to Content
Technical Articles
Author's profile photo Sinela Anwar

Module Pool Programming from Scratch using Radio Button and Check Box (Part-2)

This is my second blog post in this series. Here is the previous blog post Module Pool Programming from Scratch (Part-1). In the previous blog post we learned how to create transaction, screen, pushbutton, table fields in a basic module pool program.

In this blog post you will learn how to create and work on check box and radio buttons in screen.

How to Create Radio Button

Step 1: Open Layout of your screen and  create a radio button by clicking on the “Radio Button” on the left toolbox and placing it on the screen wherever you want. Similarly, create two such radio buttons as given below.

Step 2: Now select all the radio buttons and then right click on the box and click on “Radio Button Group” then click on “define” to assign a radio button group to the radio button.

Step 3: Double click on the box and then assign a function code to the group which will be used for all the radio buttons in user command. Now save and activate the screen and then go to user command module.

Step 4: Now write code in user command for the radio buttons using function code as given below

MODULE USER_COMMAND_0100 INPUT.
  CASE SY-UCOMM.
    WHEN 'FC_1'.
      PERFORM GET_DATA.
    WHEN 'FC2'.
      LEAVE PROGRAM.
    WHEN 'RB'.
      IF RB1 = 'X'.
        MESSAGE 'FIRST RADIO BUTTON IS SELECTED' TYPE 'I'.
      ELSEIF RB2 = 'X'.
        MESSAGE 'SECOND RADIO BUTTON IS SELECTED' TYPE 'I'.
      ELSEIF RB3 = 'X'.
        MESSAGE 'THIRD RADIO BUTTON IS SELECTED' TYPE 'I'.
      ENDIF.
    WHEN OTHERS.
  ENDCASE.
ENDMODULE.

Step 5: Define the names of radio buttons and activate the program.

Output

 

How to Create Checkbox

Step 1: Open Layout of your screen and  create a check box by clicking on the “Check Box” on the left toolbox and placing it on the screen wherever you want and give text and function code which will be used in user command to provide a functionality to the code. Similarly, another checkbox as given below.

 

Step 2: Now save and activate the screen, and go to user command.

Step 3: Now write the code using function code for check box as given below.

WHEN 'CHK1'.
        MESSAGE 'FIRST CHECK BOX IS CHECKED' TYPE 'I'.

WHEN 'CHK2'.
        MESSAGE 'SECOND CHECKBOX IS CHECKED' TYPE 'I'.

Now define the names of check box and activate the program.

Output:

Refer to the code below for the whole program.

*&---------------------------------------------------------------------*
*& Module Pool      Z1015035_MPP_MARA_
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*

INCLUDE ZMARATOP                                .    " Global Data
START-OF-SELECTION.
CALL SCREEN 100.

* INCLUDE ZMARAO01                                .  " PBO-Modules
* INCLUDE ZMARAI01                                .  " PAI-Modules
 INCLUDE ZMARAF01                                .  " FORM-Routines
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
* SET PF-STATUS 'xxxxxxxx'.
* SET TITLEBAR 'xxx'.
ENDMODULE.
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
  CASE SY-UCOMM.
    WHEN 'FC_1'.
      PERFORM GET_DATA.
    WHEN 'FC2'.
      LEAVE PROGRAM.
    WHEN 'RB'.
      IF RB1 = 'X'.
        MESSAGE 'FIRST RADIO BUTTON IS SELECTED' TYPE 'I'.
      ENDIF.
      IF RB2 = 'X'.
        MESSAGE 'SECOND RADIO BUTTON IS SELECTED' TYPE 'I'.
      ENDIF.
      IF RB3 = 'X'.
        MESSAGE 'THIRD RADIO BUTTON IS SELECTED' TYPE 'I'.
      ENDIF.
      WHEN 'CHK1'.
        MESSAGE 'FIRST CHECK BOX IS CHECKED' TYPE 'I'.

      WHEN 'CHK2'.
        MESSAGE 'SECOND CHECKBOX IS CHECKED' TYPE 'I'.

    WHEN OTHERS.
  ENDCASE.
ENDMODULE.

INCLUDE TOP

*&---------------------------------------------------------------------*
*& Include ZMARATOP                                 - Module Pool      Z1015035_MPP_MARA_
*&---------------------------------------------------------------------*
PROGRAM Z1015035_MPP_MARA_.
TABLES: MARA.
DATA:RB1,RB2,RB3, CHK1, CHK2.

INCLUDE FORM

*&---------------------------------------------------------------------*
*& Include          ZMARAF01
*&---------------------------------------------------------------------*



*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM GET_DATA .
  SELECT
    SINGLE
    MATNR
    ERSDA
    CREATED_AT_TIME
    ERNAM
    MTART
    MATKL
    FROM MARA INTO CORRESPONDING FIELDS OF MARA WHERE MATNR = MARA-MATNR.

ENDFORM.

By following the steps you will be able to create basic Module Pool Program using Radio Buttons and Check box. I hope this blog post helped you as beginner. Since this blog is for beginners I have used forms in the future blog posts I will start using methods.

As we continue to learn more in this series about MPP, I will use this blog post to link all the parts of this series.

Follow my account  Sinela Anwar to be notified of the next blog post. Please feel free to ask any questions you have in the comments section below.

Join the conversation about the ABAP programming by following the tag  ABAP Development

Post questions and answer related to tag by following the tag Questions & Answers

Read other blog post on topic ABAP Development.

 

Assigned Tags

      3 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Shai Sinai
      Shai Sinai

      Hi,

      A few tips/suggestions:

      1. The described method is for "manual" creation of screen fields. It is also possible (and in most cases preferable) to import fields from a dictionary structure.
      2. It's worth mentioning that radio-buttons / checkboxes can be added without assigning to them a function code at all (In case not required).
      3. In the example, it might be better to distinguish between the checkbox field name and its' function code so it would be clear that these are two separate artifacts.
      4. The following radio-button handling might be more readable:
        CASE ABAP_TRUE.
          WHEN RB1.
            MESSAGE 'FIRST RADIO BUTTON IS SELECTED' TYPE 'I'.
          WHEN RB2.
            MESSAGE 'SECOND RADIO BUTTON IS SELECTED' TYPE 'I'.
          WHEN RB3.
            MESSAGE 'THIRD RADIO BUTTON IS SELECTED' TYPE 'I'.
        ENDCASE.​
      Author's profile photo Sinela Anwar
      Sinela Anwar
      Blog Post Author

      Thanks for your input, actually the screen fields are imported from dictionary which have been explained in my previous blog post, for reference I have linked it in the beginning of this blog post.

      Author's profile photo Shai Sinai
      Shai Sinai

      When you import a field from dictionary via the wizard, you may choose whether it would be a radio-button, checkbox or text field: