0% found this document useful (0 votes)
26 views6 pages

SAP ABAP Basic Syntax Programming for Beginners

The document provides an overview of basic syntax programming in SAP ABAP, detailing key elements such as program structure, data declaration, data types, arithmetic operations, conditional statements, loops, string manipulation, internal tables, work areas, SQL queries, output statements, and comments. Each section includes explanations, syntax rules, and examples to illustrate the concepts. This serves as a useful reference for individuals learning or revising ABAP programming.

Uploaded by

debarshi1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views6 pages

SAP ABAP Basic Syntax Programming for Beginners

The document provides an overview of basic syntax programming in SAP ABAP, detailing key elements such as program structure, data declaration, data types, arithmetic operations, conditional statements, loops, string manipulation, internal tables, work areas, SQL queries, output statements, and comments. Each section includes explanations, syntax rules, and examples to illustrate the concepts. This serves as a useful reference for individuals learning or revising ABAP programming.

Uploaded by

debarshi1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

1

Basic Syntax Programming in SAP ABAP


ABAP (Advanced Business Application Programming) is SAP’s proprietary language for
developing applications in the SAP environment. Its syntax is structured, readable, and
resembles. Below are key basic syntax elements with explanations and examples, perfect for
creating a Word file for revision or sharing.

1. Program Structure
• Explanation: Every ABAP program starts with a declaration (e.g., REPORT) and
includes sections for data declaration, logic, and output. It’s event-driven, with
blocks like START-OF-SELECTION for main processing.
• Syntax Rules:
o Case-insensitive (e.g., write = WRITE).
o Statements end with a period (.).
• Example:

REPORT z_basic_program.

WRITE: 'Hello, SAP World!'.

o Outputs "Hello, SAP World!".

2. Data Declaration
• Explanation: Variables are declared using DATA to store values. Types can be
predefined or linked to DDIC objects.
• Syntax Rules:
o Use TYPE for data type, VALUE for initial values.
• Example:

DATA: lv_number TYPE i VALUE 10,


lv_name TYPE char20 VALUE 'Rudra'.

WRITE: lv_number, lv_name.

o Declares an integer (10) and a string ("Rudra"), then displays them.

AVADHESH YADAV – SAP ABAP CONSULTANT


2

3. Data Types
• Explanation: ABAP supports various data types for different kinds of data (e.g.,
numbers, text, dates). Common types include I (integer), C (character), N (numeric
text), D (date), STRING (variable-length string).
• Syntax Rules:
o Specify length for C (e.g., CHAR10) or use dynamic types like STRING.
• Example:

DATA: lv_int TYPE i VALUE 100, " Integer


lv_char TYPE c LENGTH 5 VALUE 'SAP', " Fixed-length character
lv_date TYPE d VALUE '20250325'. " Date (YYYYMMDD)
WRITE: lv_int, lv_char, lv_date.

o Declares and displays an integer (100), character ("SAP"), and date (2025-03-
25).

4. Arithmetic Operations
• Explanation: ABAP supports basic arithmetic operations using operators.
• Syntax Rules:
o Operators: +, -, *, /, MOD, **.
• Example:

DATA: lv_a TYPE i VALUE 5,


lv_result TYPE i.

lv_result = lv_a * 2.

WRITE: 'Result:', lv_result.

o Multiplies 5 by 2 and displays 10.

5. Conditional Statements (IF-ELSE)


• Explanation: IF checks conditions, with ELSEIF/ELSE for alternatives.
• Syntax Rules:
o Use comparison operators: =, <>, <, >.
• Example:

AVADHESH YADAV – SAP ABAP CONSULTANT


3

DATA: lv_score TYPE i VALUE 85.


IF lv_score >= 60.
WRITE: 'Pass'.
ELSE.
WRITE: 'Fail'.
ENDIF.

o Outputs "Pass" since 85 ≥ 60.

6. Loops
• Explanation: DO and WHILE repeat code execution.
• Syntax Rules:
o End with ENDDO or ENDWHILE.
• Example:

DATA: lv_count TYPE i.

DO 3 TIMES.
lv_count = lv_count + 1.
WRITE: / lv_count.
ENDDO.

o Displays 1, 2, 3 on new lines.

7. Concatenate
• Explanation: The CONCATENATE statement combines multiple strings into one, with
an optional separator.
• Syntax Rules:
o Use SEPARATED BY for delimiters (e.g., space, comma).
• Example:

DATA: lv_fname TYPE char10 VALUE 'Rudra',


lv_lname TYPE char10 VALUE ‘Yadav',
lv_fullname TYPE string.

CONCATENATE lv_fname lv_lname INTO lv_fullname SEPARATED BY ' '.


WRITE: lv_fullname.

o Combines "Rudra" and “Yadav" into "Rudra Yadav".

AVADHESH YADAV – SAP ABAP CONSULTANT


4

8. Split
• Explanation: SPLIT divides a string into parts based on a delimiter, storing results in
variables or a table.
• Syntax Rules:
o Use AT to specify the separator.
• Example:

DATA: lv_text TYPE string VALUE 'SAP-ABAP-2025',


lv_part1 TYPE string,
lv_part2 TYPE string,
lv_part3 TYPE string.

SPLIT lv_text AT '-' INTO lv_part1 lv_part2 lv_part3.


WRITE: / lv_part1, lv_part2, lv_part3.

o Splits "SAP-ABAP-2025" into "SAP", "ABAP", "2025".

9. Internal Tables
• Explanation: Internal tables store multiple records in memory, like a temporary
database table.
• Syntax Rules:
o Declare with TYPE TABLE OF, use APPEND to add data.
• Example:

TYPES: BEGIN OF ty_student,


id TYPE i,
name TYPE char20,
END OF ty_student.

DATA: it_student TYPE TABLE OF ty_student.


DATA: wa_student TYPE ty_student.
wa_student-id = 1.
wa_student-name = 'Rudra'.
APPEND wa_student TO it_student.

o Creates an internal table and adds one record.

10. Work Area


• Explanation: A work area (structure) is a single row used to interact with internal
tables (e.g., for appending or reading).
• Syntax Rules:

AVADHESH YADAV – SAP ABAP CONSULTANT


5

o Matches the structure of the internal table.


• Example:

DATA: it_student TYPE TABLE OF ty_student,


wa_student TYPE ty_student.

wa_student-id = 2.
wa_student-name = 'Avi'.

APPEND wa_student TO it_student.

LOOP AT it_student INTO wa_student.


WRITE: / wa_student-id, wa_student-name.
ENDLOOP.

o Uses wa_student to add and display a record (2, "Avi").

11. SQL Query (Open SQL)


• Explanation: Open SQL is ABAP’s database access language, used to read/write data
from SAP tables.
• Syntax Rules:
o Use SELECT to fetch data, INTO to store results.
• Example:

DATA: lv_carrid TYPE spfli-carrid,


lv_connid TYPE spfli-connid.

SELECT carrid connid


FROM spfli
INTO (lv_carrid, lv_connid)
WHERE carrid = 'Rudra Airways'.

WRITE: / lv_carrid, lv_connid.


ENDSELECT.

o Fetches and displays flight data from table SPFLI for carrier "Rudra Airways".

12. WRITE Statement (Output)


• Explanation: WRITE displays data on the screen.
• Syntax Rules:
o Use / for new lines.

AVADHESH YADAV – SAP ABAP CONSULTANT


6

• Example:

WRITE: 'SAP', / 'ABAP'.

o Outputs "SAP" and "ABAP" on separate lines.

13. Comments
• Explanation: Comments improve code readability.
• Syntax Rules:
o * for full-line, " for inline.
• Example:

*Program start
DATA: lv_flag TYPE c VALUE 'Y'. " Yes flag
WRITE: lv_flag.

o Adds comments to a simple program.

AVADHESH YADAV – SAP ABAP CONSULTANT

You might also like