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.