You are on page 1of 7

Hong Kong Institute of Vocational Education

IT114105 HD in Software Engineering


ITP4512 Enterprise Software
Topic 5: Selection Screen
Lab 6 – Selection Screen

Intended Learning Outcomes


Upon completion of this tutorial/lab, you should be able to:
o Identify how to handle selection screen in an SAP R/3 system.
o Create simple ABAP programs to handle selection screens.
o Create simple ABAP programs to use SELECT-OPTIONS and selection text.

Exercise 1

1. Create a program called Z_06_SELECT_SCR1.


2. In the program, show two input parameters.
3. They are all coming from table SBOOK.
4. For the first one, Airline Code, it is a mandatory field.
5. For the second one, Smoker, is a checkbox.

6. If the checkbox is checked, all smoker passengers’ ID and name are displayed.

1
7. Otherwise, non-smokers’ ID and name are displayed.

Ans:
REPORT Z_06_SELECT_SCR1 .
tables: sbook.
parameters:
p_carrid type sbook-carrid OBLIGATORY,
p_smoker as checkbox.
write: / 'Air-code', 10 'CustomerID', 25 'CustomerName'.
if p_smoker eq 'X'.
write / p_carrid.
select * from sbook
where smoker eq 'X' and carrid eq p_carrid.
write: / sbook-customid under 'CustomerID',
sbook-passname under 'CustomerName'.
endselect.
else.
write / p_carrid.
select * from sbook
where smoker ne 'X' and carrid eq p_carrid.
write: / sbook-customid under 'CustomerID',
sbook-passname under 'CustomerName'.
endselect.
endif.

Exercise 2

1. Create a program called Z_06_SELECT_SCR_2.


2. In the program, show two selection criteria in the selection screen.
3. They are all coming from table SBOOK ( i.e., Booking Date and Airline Code ).

4. Use the selection criteria to retrieve data from table SBOOK and display the result.

2
Ans:
REPORT Z_06_SELECT_SCR2 .
TABLES sbook.
select-options orderd for sbook-order_DATE.
select-options airline for sbook-carrid.
write: / 'Customer ID', 15 'Booking Date'.
select * from sbook.
if sbook-order_date in orderd and sbook-carrid in airline.
write: / sbook-customid under 'Customer ID', sbook-order_date under 'Booking Date'.
endif.
endselect.

Exercise 3

1. Create a program called Z_06_SELECT_SCR_3.


2. In the program, show the selection screen as follows:
[Hint: SELECT-OPTIONS fd FOR sy-datlo NO INTERVALS DEFAULT sy-datum.]
[Flight Date is set to system date and the selection criteria is : Before Flight Date.]

3
3. Select data from tables SBOOK and SPFLI (join on same CARRID and CONNID)
according to what the user had selected and display the CARRID, CONNID,
CITYFROM, CITYTO, FLDATE and CLASS to screen. Output should be similar to the
following when class=B:

[Hint : Use Open SQL statement similar to below:


SELECT …..
FROM spfli INNER JOIN sbook ON sbook~carrid = spfli~carrid ……
INTO CORRESPONDING FIELDS OF WA …….]
4. All the labels should be maintained in the Text elements.

4
Ans:
REPORT Z_06_SELECT_SCR3 .
TABLES spfli.
SELECTION-SCREEN BEGIN OF BLOCK options WITH FRAME TITLE Text-001.
PARAMETERS r1 RADIOBUTTON GROUP gr1.
PARAMETERS r2 RADIOBUTTON GROUP gr1 DEFAULT 'X'.
PARAMETERS r3 RADIOBUTTON GROUP gr1.
SELECT-OPTIONS s_carrid FOR spfli-carrid.
SELECT-OPTIONS s_connid FOR spfli-connid NO INTERVALS.
SELECT-OPTIONS s_flight FOR sy-datlo NO INTERVALS DEFAULT sy-datum.
SELECTION-SCREEN END OF BLOCK options.

TYPES: BEGIN OF rec,


carrid type sbook-carrid,
connid type sbook-connid,
cityfrom type spfli-cityfrom,
cityto type spfli-cityto,
fldate type sbook-fldate,
class type sbook-class,
END OF rec.
DATA wa TYPE rec.
DATA tab TYPE TABLE OF rec.
DATA cls TYPE sbook-class.

IF r1 = 'X'.
cls = 'B'.
ELSEIF r2 = 'X'.
cls = 'Y'.
ELSE.
cls = 'F'.
ENDIF.

SELECT sbook~carrid sbook~connid cityfrom cityto fldate class


INTO TABLE tab
FROM sbook INNER JOIN spfli
ON sbook~carrid = spfli~carrid
AND sbook~connid = spfli~connid
WHERE sbook~carrid IN s_carrid
AND sbook~connid IN s_connid
AND fldate LE s_fldate
AND class = cls.

LOOP AT tab INTO wa.


WRITE: / wa-carrid, wa-connid, wa-cityfrom,
wa-cityto, wa-fldate, wa-class.
ENDLOOP.

5
Exercise 4

1. Create a table named Z06T_FLIGHT with structure as below:

2. Create a program named Z_06_SELECT_SCR4.


3. Design and set the selection screen as below:

4. When the program is executed, the following report is displayed:

[Hint : Use Open SQL statement similar to below:


SELECT …..
FROM spfli INNER JOIN sbook ……
INTO CORRESPONDING FIELDS OF WA …….]

6
Answer:
REPORT z_06_select_scr4 .
TABLES: spfli,sbook, z06t_flight.
SELECTION-SCREEN BEGIN OF BLOCK options WITH FRAME TITLE text-001.
PARAMETERS r1 RADIOBUTTON GROUP gr1.
PARAMETERS r2 RADIOBUTTON GROUP gr1 DEFAULT 'X'.
PARAMETERS r3 RADIOBUTTON GROUP gr1.
SELECT-OPTIONS s_carrid FOR spfli-carrid.
SELECT-OPTIONS fd FOR sy-datlo.
SELECTION-SCREEN END OF BLOCK options.

DATA wa TYPE z06t_flight.

WRITE: 'Airline', 'Connection No.', 'Customer ID', (15) 'Passager Name',


(15) 'City-From', 'City-To'.
SKIP.

SELECT spfli~carrid spfli~connid spfli~cityfrom spfli~cityto


sbook~customid sbook~passname
FROM spfli INNER JOIN sbook
ON spfli~carrid = sbook~carrid
AND spfli~connid = sbook~connid
INTO CORRESPONDING FIELDS OF WA
WHERE spfli~carrid IN s_carrid AND sbook~fldate IN fd.
WRITE: / wa-carrid UNDER 'Airline',
wa-connid UNDER 'Connection No.',
wa-customid UNDER 'Customer ID',
wa-passname UNDER 'Passager Name',
wa-cityfrom under 'City-From',
wa-cityto under 'City-To'.
ENDSELECT.

You might also like