Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Select statement for selection screen - my first ABAP

mateusz_wrobel
Explorer
0 Kudos

Hello everyone,

I am working on my first program with ABAP. I have created table zemployees with the structure & data attached - employee.png.

Then wrote some code, see below.

I am struggling with two (2) problems:

1. When Initalization and At selection screen is turned on, the select statement does not work. When its turned off (*) it works.

2. I do not know how to wrote a code for parameters to select data based what is entered on the screen. I only managed to wrote for my_dob and my_ee, but have more to handle below:

my_g

mybox1, mybox2

my_rb1, my_rb2, my_rb3

SELECTION-SCREEN BEGIN OF BLOCK myblock1 WITH FRAME TITLE text-001.

PARAMETERS:

*  my_ee LIKE zemployees-employee VALUE CHECK,

  my_g  LIKE zemployees-gender VALUE CHECK.

SELECT-OPTIONS my_dob FOR zemployees-dob.

SELECT-OPTIONS my_ee FOR zemployees-employee.



SELECTION-SCREEN END OF BLOCK myblock1.





SELECTION-SCREEN BEGIN OF BLOCK myblock2 WITH FRAME TITLE text-002.



PARAMETERS:

  my_box1 AS CHECKBOX,                                                            "Domestic employee ?

  my_box2 AS CHECKBOX,                                                            "Foreign employee ?

  my_rb3  RADIOBUTTON GROUP gr1,                                                  "All Employees

  my_rb1  RADIOBUTTON GROUP gr1,                                                  "Contract of Employment

  my_rb2  RADIOBUTTON GROUP gr1.                                                  "B2B





SELECTION-SCREEN END OF BLOCK myblock2.








INITIALIZATION.



AT SELECTION-SCREEN.                                                

  IF
    my_g IS INITIAL AND
    my_dob IS INITIAL AND
    my_ee IS INITIAL.

    MESSAGE e000(zmes1).                "Fill data on selection screen
ENDIF.


SELECT * FROM zemployees.

  IF
    zemployees-dob        IN my_dob    AND
    zemployees-employee   IN my_ee.
   WRITE: / zemployees.
  ENDIF.

ENDSELECT.
1 ACCEPTED SOLUTION

raymond_giuseppi
Active Contributor

First, read some documentation on event block in executable programs - picture

8 REPLIES 8

srikanthnalluri
Active Participant

Display the data after START-OF-SELECTION.

raymond_giuseppi
Active Contributor

First, read some documentation on event block in executable programs - picture

mateusz_wrobel
Explorer
0 Kudos

question 1 handled, thank you.

Can anyone help me with question 2 ?

Why dont you put it in where clause of select, its basic SQL?

0 Kudos

mateusz_wrobel
Explorer
0 Kudos

I am not a programist. But wanted to learn ABAP so started few days ago. This is my first contact with such language. That's why asking for little help.

Now my code looks like below. I want to include:

1. my_box1 when zemployees-domestic eq 'x'

2. my_box2 when zemployees-domestic is initial.

3. my_rb1 when zemployees-form -> all values

4. my_rb2 when zemployees-form -> for value "UoP"

5. my_rb3 when zemployees-form -> for value "B2B"

REPORT z_employee_list_01
LINE-SIZE 132
NO STANDARD PAGE HEADING.


TABLES zemployees.




*****


SELECTION-SCREEN BEGIN OF BLOCK myblock1 WITH FRAME TITLE text-001.


PARAMETERS:


                my_bb     TYPE zemployees-gender       NO-DISPLAY.


SELECT-OPTIONS:


                 my_ee    FOR  zemployees-employee DEFAULT  '10000001' TO '19999999',
                 my_dob   FOR  zemployees-dob,
                 my_g     FOR  zemployees-gender.


SELECTION-SCREEN END OF BLOCK   myblock1.




SELECTION-SCREEN BEGIN OF BLOCK myblock2 WITH FRAME TITLE text-002.


PARAMETERS:
  my_box1 AS CHECKBOX        LIKE zemployees-domestic DEFAULT 'X',                     "Domestic employee
  my_box2 AS CHECKBOX        LIKE zemployees-domestic DEFAULT 'X'.                     "Foreign employee


SELECTION-SCREEN SKIP.


PARAMETERS:
  my_rb3 RADIOBUTTON GROUP       gr1,                                                  "All types of employment
  my_rb1 RADIOBUTTON GROUP       gr1,                                                  "Contract of emploment
  my_rb2 RADIOBUTTON GROUP       gr1.                                                  "B2B




SELECTION-SCREEN END OF BLOCK   myblock2.




**********
INITIALIZATION.


AT SELECTION-SCREEN.                                                
  IF
    my_g IS INITIAL AND
    my_dob IS INITIAL AND
    my_ee IS INITIAL.


    MESSAGE e000(zmes1).




  ENDIF.


*****


START-OF-SELECTION.


  SELECT * FROM zemployees.


    IF


      zemployees-dob        IN my_dob    AND
      zemployees-employee   IN my_ee     AND
      zemployees-gender     IN my_g.


      WRITE: / zemployees.


    ENDIF.
  ENDSELECT.
END-OF-SELECTION.

0 Kudos

First, you dont have to SELECT...ENDSELECT to check the parameter, put it in where clause like:

SELECT * FROM zemployees
WHERE 
  dob        IN my_dob    AND
  employee   IN my_ee     AND
  gender     IN my_g.

Second, you have condition for SQL so build it first, after that put it into where clause too:

if my_box1 = 'X'.
 lv_1 = 'X'
endif.
SELECT * FROM zemployees
WHERE 
  dob        IN my_dob    AND
  employee   IN my_ee     AND
  gender     IN my_g AND
  domestic   EQ lv_1.

former_member184158
Active Contributor
0 Kudos

Read more tutorials SQL and ABAP programming.