Skip to main content

Command Palette

Search for a command to run...

DAY-10: PARAMETERS, SELECT-OPTIONS & DATATYPES in SAP ABAP

Published
β€’4 min read
DAY-10: PARAMETERS, SELECT-OPTIONS & DATATYPES in SAP ABAP
R

On a journey of continuous learning πŸš€ I share the concepts I learn daily through blogs. Learn concepts with me β€” one topic at a time.

#LearningInPublic #ContinuousLearning

Today we move into core ABAP programming fundamentals.

If you understand Day-10 clearly, you can write basic SAP reports confidently.

We will cover:

  • βœ… Datatypes

  • βœ… Variables

  • βœ… TYPES (Structure creation)

  • βœ… Internal Tables

  • βœ… PARAMETERS

  • βœ… SELECT-OPTIONS

  • βœ… LOOP

  • βœ… IF Conditions

  • βœ… BREAK-POINT

  • βœ… Input & Output

  • βœ… Selection Screen Frames

Everything explained in simple language πŸ‘‡


1️⃣ What is a Datatype in ABAP?

A datatype defines what kind of data a variable can store.

Think like this:

  • i β†’ Whole numbers (10, 20, 100)

  • string β†’ Text

  • p β†’ Decimal numbers (money)

  • abap_bool β†’ True / False


Basic Datatypes Example

DATA: gv_text   TYPE string,        "Stores text
      gv_count  TYPE i,             "Stores integer numbers
      gv_price  TYPE p DECIMALS 2,  "Stores decimal values
      gv_flag   TYPE abap_bool.     "True or False

Explanation:

VariableDatatypePurpose
gv_textstringStores text
gv_countiStores numbers
gv_pricepStores currency
gv_flagabap_boolBoolean value

2️⃣ Creating a File Name Variable

DATA: gv_filename TYPE string.

gv_filename = '/usr/sap/tmp/flight_data.txt'.

This stores a file path.

Used in:

  • File upload

  • File download

  • Application server file handling


3️⃣ TYPES – Creating Custom Structure

In ABAP, TYPES is used to create a structure.

Structure = Group of fields.

Example:

TYPES: BEGIN OF ty_flight,
         carrid TYPE sflight-carrid,
         connid TYPE sflight-connid,
         price  TYPE sflight-price,
       END OF ty_flight.

Explanation:

  • sflight β†’ Standard SAP flight table

  • We are copying its field definitions

  • Ensures datatype consistency


4️⃣ Internal Table & Work Area

Internal Table = Stores multiple rows
Work Area = Stores one row

DATA: it_flight TYPE STANDARD TABLE OF ty_flight,
      wa_flight TYPE ty_flight.
ObjectMeaning
it_flightInternal table
wa_flightWork area

5️⃣ PARAMETERS & SELECT-OPTIONS

These create input fields on selection screen.


PARAMETERS

Used for single input.

PARAMETERS: p_carr TYPE sflight-carrid.

User enters one airline.

Example input:

LH

SELECT-OPTIONS

Used for range input.

SELECT-OPTIONS: s_price FOR sflight-price.

User can enter:

  • Single value

  • Multiple values

  • Range (100 to 500)

  • Exclude values

Example:

100 – 800

6️⃣ Selection Screen Frame

To group fields:

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
  PARAMETERS: p_max TYPE i DEFAULT 5.
SELECTION-SCREEN END OF BLOCK b1.

Creates a box around selection fields.


7️⃣ BREAK-POINT (Debugging)

BREAK-POINT.

Stops program execution for debugging.

Used in:

  • Testing

  • Error checking


8️⃣ SELECT Statement (Database Fetch)

SELECT carrid
       connid
       price
  FROM sflight
  INTO TABLE it_flight
  UP TO p_max ROWS
  WHERE carrid = p_carr
    AND price IN s_price.

What happens here?

  • Fetch data from SFLIGHT

  • Apply filter

  • Store in internal table

ClauseMeaning
INTO TABLEStore data
UP TO p_max ROWSLimit records
WHEREApply condition

9️⃣ LOOP Processing

LOOP AT it_flight INTO wa_flight.

Reads internal table row by row.


πŸ”Ÿ IF Condition

IF wa_flight-price > 500.
  gv_flag = abap_true.
ELSE.
  gv_flag = abap_false.
ENDIF.

Simple logic:

If price > 500 β†’ True
Else β†’ False


1️⃣1️⃣ WRITE (Output)

WRITE: / wa_flight-carrid,
         wa_flight-connid,
         wa_flight-price,
         gv_flag.

/ β†’ New line

Displays output in classic list format.


1️⃣2️⃣ System Function Example

WRITE: / 'Total Records:', lines( it_flight ).

lines( ) returns number of rows.


🧠 Complete Beginner Version of Code

Here is the full clean program:

REPORT z_abap_all_basics_demo.

* Variables
DATA: gv_flag TYPE abap_bool.

* Structure
TYPES: BEGIN OF ty_flight,
         carrid TYPE sflight-carrid,
         connid TYPE sflight-connid,
         price  TYPE sflight-price,
       END OF ty_flight.

* Internal table
DATA: it_flight TYPE STANDARD TABLE OF ty_flight,
      wa_flight TYPE ty_flight.

* Selection screen
PARAMETERS: p_carr TYPE sflight-carrid.
SELECT-OPTIONS: s_price FOR sflight-price.

* Fetch data
SELECT carrid connid price
  INTO TABLE it_flight
  FROM sflight
  WHERE carrid = p_carr
    AND price IN s_price.

* Loop
LOOP AT it_flight INTO wa_flight.

  IF wa_flight-price > 500.
    gv_flag = abap_true.
  ELSE.
    gv_flag = abap_false.
  ENDIF.

  WRITE: / wa_flight-carrid,
           wa_flight-connid,
           wa_flight-price,
           gv_flag.

ENDLOOP.

WRITE: / 'Total Records:', lines( it_flight ).

🎯 Final Understanding

ConceptSimple Meaning
DatatypeType of data
TYPESCreate structure
Internal TableMultiple rows
Work AreaSingle row
PARAMETERSSingle input
SELECT-OPTIONSRange input
LOOPRead table
IFCondition
WRITEDisplay
BREAK-POINTDebug

πŸš€ Real-World Usage

Used in:

  • Reports

  • ALV

  • Data filtering

  • Custom SAP programs

  • Business reporting

More from this blog