- SAP ABAP
- What is SAP ABAP
- SAP ABAP Data Dictionary and Domain
- SAP ABAP Data Element
- SAP ABAP Database Table
- SAP ABAP Database tables and views
- SAP ABAP Foreign Key
- SAP ABAP Indexes
- SAP ABAP Structure
- SAP ABAP Package
- SAP ABAP Adding Fields to SAP Standard Table
- SAP ABAP Internal Table and Database Table
- SAP ABAP Select Option and Parameter
- SAP ABAP Types of Internal Table
- SAP ABAP ways of Declaring Internal Tables
- SAP ABAP Mastering Initialization Technique
- SAP ABAP Operations on Internal Table
- SAP ABAP Record Retrieval
- SAP ABAP Insert, Modify and Delete data in the Internal table by using Keywords
- SAP ABAP Sorting and Removing Adjacent Duplicates
- SAP ABAP Seamless Data Transfer Between Internal Tables
- SAP ABAP Search Help Types
- SAP ABAP Lock Objects and Types
- SAP ABAP Buffering and Its Types
- SAP ABAP TMG
- SAP ABAP Table Types
- SAP ABAP Views
- SAP ABAP Control Break Statement
- SAP ABAP COMMIT and ROLLBACK
- SAP ABAP Joins
- SAP For All Entries
- SAP ABAP Procedure to Fill Final Internal Table
- SAP ABAP Modularization
- SAP ABAP Function Group and Function Module
- SAP ABAP SELECT Options
24DDIC1108 – SELECT-OPTIONS and Its Screen Components
SELECT-OPTIONS allow users to specify ranges or individual values for a selection field. These options are stored in an internal table with several important components that help define the selection criteria:
- SIGN: Indicates whether the selection is an inclusion ( I for “Include”) or exclusion ( E for “Exclude”).
- OPTION: Specifies the type of selection, such as EQ (Equal), BT (Between), GT (Greater Than), etc.
- LOW: The lower limit of the range or the actual value.
- HIGH: The upper limit of the range (relevant for range options like BT ).
Example: Using SELECT-OPTIONS with Components
Let’s create a report that demonstrates how to access and use these components of SELECT-OPTIONS with an internal table. We will filter flight data from the SFLIGHT table based on a range of dates provided by the user.
REPORT zexample_select_options_components.
- Define selection screen with SELECT-OPTIONS
SELECT-OPTIONS: so_fldate FOR sflight-fldate.
- Internal table to hold data from the database
DATA: lt_flights TYPE TABLE OF sflight.
- Internal table to process selection criteria
DATA: lt_select_options TYPE TABLE OF sflight-fldate.
- Start of the report logic
START-OF-SELECTION.
- Clear internal table before fetching data
CLEAR lt_flights.
- Access and process the SELECT-OPTIONS components
LOOP AT so_fldate INTO DATA(ls_option).
WRITE: / ‘Sign:’, ls_option-sign,
‘Option:’, ls_option-option,
‘Low:’, ls_option-low,
‘High:’, ls_option-high.
ENDLOOP.
- Fetch data based on the user’s input range
SELECT * FROM sflight
INTO TABLE lt_flights
WHERE fldate IN so_fldate.
- Check if data was retrieved
IF lines( lt_flights ) > 0.
- Display the retrieved data
LOOP AT lt_flights INTO DATA(ls_flight).
WRITE: / ‘Carrier ID:’, ls_flight-carrid,
‘Connection ID:’, ls_flight-connid,
‘Flight Date:’, ls_flight-fldate,
‘Price:’, ls_flight-price.
ENDLOOP.
ELSE.
- No data found
WRITE: / ‘No flights found for the selected date range.’.
ENDIF.
Explanation of Components
- SELECT-OPTIONS Declaration:
SELECT-OPTIONS: so_fldate FOR sflight-fldate.
– This line declares so_fldate as a selection option for the fldate field from the SFLIGHT table.
- Internal Table for Data:
DATA: lt_flights TYPE TABLE OF sflight.
– lt_flights is an internal table used to store the flight records fetched from the database.
- Internal Table for Selection Criteria:
DATA: lt_select_options TYPE TABLE OF sflight-fldate
– lt_select_options is defined to hold selection criteria. However, it’s not used directly in this example but demonstrates how you might process selection criteria.
- Accessing SELECT-OPTIONS Components:
LOOP AT so_fldate INTO DATA(ls_option).
WRITE: / ‘Sign:’, ls_option-sign,
‘Option:’, ls_option-option,
‘Low:’, ls_option-low,
‘High:’, ls_option-high.
ENDLOOP.
– This loop iterates over the so_fldate internal table (which is implicitly created by SELECT-OPTIONS ) and writes out each component:
– SIGN indicates whether the criterion is an inclusion ( I ) or exclusion ( E ).
– OPTION shows the type of comparison (e.g., BT for between, EQ for equal).
– LOW and HIGH define the range for the selection criterion.
- Fetching and Displaying Data:
SELECT * FROM sflight
INTO TABLE lt_flights
WHERE fldate IN so_fldate.
– This SELECT statement retrieves records from the SFLIGHT table based on the range of dates specified by so_fldate .
- Processing Results:
IF lines( lt_flights ) > 0.
- Display the retrieved data
LOOP AT lt_flights INTO DATA(ls_flight).
WRITE: / ‘Carrier ID:’, ls_flight-carrid,
‘Connection ID:’, ls_flight-connid,
‘Flight Date:’, ls_flight-fldate,
‘Price:’, ls_flight-price.
ENDLOOP.
ELSE.
- No data found
WRITE: / ‘No flights found for the selected date range.’.
ENDIF.
– If data is found, it is displayed. If no records are found, a message is displayed indicating that no data matches the criteria.
This example shows how SELECT-OPTION works with its components and how to use them effectively in ABAP to filter and display data from a database table.
Author : Aniket Pawar, 9373518385
24DDIC1108 – SELECT-OPTIONS and Its Screen Components
SELECT-OPTIONS allow users to specify ranges or individual values for a selection field. These options are stored in an internal table with several important components that help define the selection criteria:
- SIGN: Indicates whether the selection is an inclusion ( I for “Include”) or exclusion ( E for “Exclude”).
- OPTION: Specifies the type of selection, such as EQ (Equal), BT (Between), GT (Greater Than), etc.
- LOW: The lower limit of the range or the actual value.
- HIGH: The upper limit of the range (relevant for range options like BT ).
Example: Using SELECT-OPTIONS with Components
Let’s create a report that demonstrates how to access and use these components of SELECT-OPTIONS with an internal table. We will filter flight data from the SFLIGHT table based on a range of dates provided by the user.
REPORT zexample_select_options_components.
- Define selection screen with SELECT-OPTIONS
SELECT-OPTIONS: so_fldate FOR sflight-fldate.
- Internal table to hold data from the database
DATA: lt_flights TYPE TABLE OF sflight.
- Internal table to process selection criteria
DATA: lt_select_options TYPE TABLE OF sflight-fldate.
- Start of the report logic
START-OF-SELECTION.
- Clear internal table before fetching data
CLEAR lt_flights.
- Access and process the SELECT-OPTIONS components
LOOP AT so_fldate INTO DATA(ls_option).
WRITE: / ‘Sign:’, ls_option-sign,
‘Option:’, ls_option-option,
‘Low:’, ls_option-low,
‘High:’, ls_option-high.
ENDLOOP.
- Fetch data based on the user’s input range
SELECT * FROM sflight
INTO TABLE lt_flights
WHERE fldate IN so_fldate.
- Check if data was retrieved
IF lines( lt_flights ) > 0.
- Display the retrieved data
LOOP AT lt_flights INTO DATA(ls_flight).
WRITE: / ‘Carrier ID:’, ls_flight-carrid,
‘Connection ID:’, ls_flight-connid,
‘Flight Date:’, ls_flight-fldate,
‘Price:’, ls_flight-price.
ENDLOOP.
ELSE.
- No data found
WRITE: / ‘No flights found for the selected date range.’.
ENDIF.
Explanation of Components
- SELECT-OPTIONS Declaration:
SELECT-OPTIONS: so_fldate FOR sflight-fldate.
– This line declares so_fldate as a selection option for the fldate field from the SFLIGHT table.
- Internal Table for Data:
DATA: lt_flights TYPE TABLE OF sflight.
– lt_flights is an internal table used to store the flight records fetched from the database.
- Internal Table for Selection Criteria:
DATA: lt_select_options TYPE TABLE OF sflight-fldate
– lt_select_options is defined to hold selection criteria. However, it’s not used directly in this example but demonstrates how you might process selection criteria.
- Accessing SELECT-OPTIONS Components:
LOOP AT so_fldate INTO DATA(ls_option).
WRITE: / ‘Sign:’, ls_option-sign,
‘Option:’, ls_option-option,
‘Low:’, ls_option-low,
‘High:’, ls_option-high.
ENDLOOP.
– This loop iterates over the so_fldate internal table (which is implicitly created by SELECT-OPTIONS ) and writes out each component:
– SIGN indicates whether the criterion is an inclusion ( I ) or exclusion ( E ).
– OPTION shows the type of comparison (e.g., BT for between, EQ for equal).
– LOW and HIGH define the range for the selection criterion.
- Fetching and Displaying Data:
SELECT * FROM sflight
INTO TABLE lt_flights
WHERE fldate IN so_fldate.
– This SELECT statement retrieves records from the SFLIGHT table based on the range of dates specified by so_fldate .
- Processing Results:
IF lines( lt_flights ) > 0.
- Display the retrieved data
LOOP AT lt_flights INTO DATA(ls_flight).
WRITE: / ‘Carrier ID:’, ls_flight-carrid,
‘Connection ID:’, ls_flight-connid,
‘Flight Date:’, ls_flight-fldate,
‘Price:’, ls_flight-price.
ENDLOOP.
ELSE.
- No data found
WRITE: / ‘No flights found for the selected date range.’.
ENDIF.
– If data is found, it is displayed. If no records are found, a message is displayed indicating that no data matches the criteria.
This example shows how SELECT-OPTION works with its components and how to use them effectively in ABAP to filter and display data from a database table.
Author : Aniket Pawar, 9373518385