ABAP New Syntax

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 50

ABAP NEW SYNTAX

AUTHOR: SUSHANT SINGH CHHATRYA (11066)


SAP BRF+ CONSULTANT

Purpose:

- To familiarize ABAP developers with the new syntax introduced in versions 7.4 and 7.5.

Scope:

- Covers the new syntax enhancements in ABAP versions 7.4 and 7.5
- Comparison with old syntax is provided in code.

Benefits:

- Empowers developers to leverage enhanced programming capabilities.

Notes:

- All programs are in the HET Server under the package name ZNEWSYNTAX.
- Please refrain from modifying existing code; instead, create your own test code.

JUNE 19, 2024


INVENIOLSI

SUSHANT SINGH 0
Table of Contents

1. Introduction
2. New Features of OPEN SQL
3. Inline Declaration
4. COND as Replacement for IF
5. SWITCH as Replacement for CASE
6. String Expression || as Replacement for CONCATENATE
7. VALUE as Replacement for APPEND (BASE)
8. CORRESPONDING (Except/Mapping)
9. ALPHA(IN/OUT) as Replacement for Conversion FM
10. NEW
11. LET
12. CONV
13. REDUCE as Replacement for LOOP
14. FILTER
15. Table Expression as Replacement for READ TABLE
16. Join Improvements

Extra:

17. Control Break Statements

• at first
• at last
• at new field_name (Add on: SUM)
• at end of field_name

18. Database Operators

• Insert
• Update
• Delete
• Modify

19. Use of Field Symbol over Work Area

SUSHANT SINGH 1
Introduction:

- BASIC:

Open SQL statements are a subset of Standard SQL that is fully integrated in ABAP.
Native SQL is a variant of SQL specific to the database system and is executed directly by
the database system.
1.

2.

- Data Objects: Variable, Internal tables, work area, select option (That hold the data)

SUSHANT SINGH 2
- OLD

- NEW

- Checkout Program: ZNEWSYNTX_OPEN_SQL(HET Server)

3. CASE:

OLD Way:

- Fetch Data with Select Query:

- Fetched data:

SUSHANT SINGH 3
- Looping over this table, and based on condition, fetching it over new table:

- Had to define 2 different structures as per requirement:

SUSHANT SINGH 4
NEW Way:

Check Program: ZNEWSYNTX_OPEN_SQL_CASE (HET Server)

4.

SUSHANT SINGH 5
NOTE: Use of Literal is to check whether entry exists in the table or not
without bringing data to application layer!

- OLD:
- To validate data: we can use internal table, work area, variable:

SUSHANT SINGH 6
- Now we are not using this table
- If data is there, we are displaying it as shown below:

- Below is Highlighted NEW way:

- Check Program - ZNEWSYNTX_OPEN_SQL_LITERALS (HET Server)

SUSHANT SINGH 7
IMPORTANT:

- Role of Application layer is getting minimised.


- Most of the work is done ta application layer.

Check Programs: HET Server

- ZNEWSYNTX_OPEN_SQL_AGG_FUNCT1
- ZNEWSYNTX_OPEN_SQL_AGG_FUNCT2

Note Below Information: (Extra)

Character Data type:

- C (Character)
- N (Numeric)
- D (Date)

Numeric Data type:

- I (Integer)
- P (Packed decimal)
- F (Floating point)

SUSHANT SINGH 8
Summary:

SUSHANT SINGH 9
1. Inline Declarations:

➔ First Declare: Explicit Data Declaration #OLD

➔ #NEW

2. Conditional statement:

1. IF can be replaced by COND statement as below:

SUSHANT SINGH 10
2. CASE can be replaced by SWITCH statement as below:

SUSHANT SINGH 11
➔ Performance wise- It is same-But-Less number of lines

SUSHANT SINGH 12
SUSHANT SINGH 13
- Program - ZNEWSYNTX_VALUE (HET Server)

SUSHANT SINGH 14
➔ Can be used as 2 ways:

- Whenever create structure type: Can insert only one record, as it will treat as a work
area.
- Below: Structure type: lty_data

Defining Structure Type: Single Record Insertion

SUSHANT SINGH 15
- Use it as below:

➔ Create a table type: to insert multiple records.

Defining table type: Multiple Records Insertion

IMP: In the new syntax for this standard internal table declaration, we
have to mention that we not specifying any key!

SUSHANT SINGH 16
➔ Add multiple records:

- Using #, we must tell SAP that we are going to insert data to internal table.
- SO, declare Internal table explicitly, otherwise error:

- No error in below:
- No inline data declaration - IMP

- Below Will overwrite the internal table:

SUSHANT SINGH 17
- It will append after existing records

➔ IMP: User Case of BASE

SUSHANT SINGH 18
- Suppose 2 different structures and 2 different internal tables
- Pass data from one internal table to another
- We must map via work areas and then append it to internal Stable, or use
CORRESPONDING

➔ If structure of two internal table is same and same sequence of fields:


➔ It will do column wise mapping

OR

SUSHANT SINGH 19
or

(Table Type)

EXCEPT: This column data will not move.

MAPPING: Particular column name data(ernam) will move particular column(uname).

SUSHANT SINGH 20
IMP: Only Data of matching columns will move, rest all fields will be blank!

QnA:

~ Value Operator: is used to insert data into internal table


~ Corresponding operator: is to move data from one internal table to another

------------------------------------------------------------------------------------------------------------------------------------

- 2 FM for Conversion:

SUSHANT SINGH 21
NOTE:

- Storage format (Internal format)


- Display format (External format)
- In Sales header table (VBAK), VBELN (Sales Document Number).
- At domain level, Routine (ALPHA) is used.
- This Routine has those 2 FM.

- SAP Use these FM, while storing VBLEN (SAP adds the leading 0)

- While displaying SAP removes the leading 0

SUSHANT SINGH 22
- With New Syntax:

------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------- --------

- Refer: ZNEWKEYWORD and ZNEWKEYWORD_WITH_PARAM

SUSHANT SINGH 23
- New with Parameter
- Used Constructor here

SUSHANT SINGH 24
1. They(lv_input) cannot be used outside the scope of the expression (VALUE).
2. These variable/field symbol defined for LET Expression cannot be redefined again.

3. Can be used in following:

- Program: ZLETKEYWORD (HET Server)

SUSHANT SINGH 25
- Below here in type cast with the help of variable (LV_file below):

SUSHANT SINGH 26
Check Program: ZNEWSYNTX_CONV (HET Server)

- I want to count total sales order category:


- OLD way below:

SUSHANT SINGH 27
- New way:

- Syntax:

Check Program - ZNEWSYNTX_REDUCE_01 and ZNEWSYNTX_REDUCE_02

SUSHANT SINGH 28
SUSHANT SINGH 29
IMP:

Check Program: HET Server

- ZNEWSYNTX_FILTER
- ZNEWSYNTX_FILTER01

SUSHANT SINGH 30
READ TABLE: Reads first matching record!

SUSHANT SINGH 31
- SY-subrc is not used in case of table Expression:

- If entry not found, it will give runtime error.

- Use line_exists instead:

SUSHANT SINGH 32
SUSHANT SINGH 33
- Below is wrong approach:

- Below is correct approach

----------- I hope you are enjoying this Learning! ------------

SUSHANT SINGH 34
ABAP Programming:
- Event – Always require ACTION or it will trigger
automatically when time has reached!
- Here, control break events – Do not require action for
our end.

SUSHANT SINGH 35
➔ Below 2 make group based upon specified field name.

Check Program: ZCONTROL_BREAK01 (HET Server)

SUSHANT SINGH 36
SUSHANT SINGH 37
- If we took one extra column in the internal table, which is on the
left-hand side of specified field name:
NOTE: If values on the left-hand side change so AT NEW and AT END OF
will trigger.

- Approach:

SUSHANT SINGH 38
- Instead of changing seq. in select query, create
temp. itab and copy the sequence over there.
- Other Important Points:

Reason – Not Specifying the field name here.

SUSHANT SINGH 39
Check Program: HET Server
- ZCONTROL_BREAK02

SUSHANT SINGH 40
1. Insert:
- Insert single record:

- Insert multiple record

Note:
- Structure of table must match with the structure of
the work area/internal table. (No. of columns)

2. Delete:
- Single record:

SUSHANT SINGH 41
- Multiple record

3. Update:
- Entry should already exist
- Can update value of non-key column

4. Modify – Insert + Update

- All operations shown in Program (ZDB_OPERATION)


– HET Server

SUSHANT SINGH 42
- Whatever we do with the field symbol, it will impact
data objects

Note: FS do not occupy memory

1. Typed: Data object and FS should be compatible.


- System checks the compatibility.

SUSHANT SINGH 43
2. Generic:

- Any: structure or variable


- Any table: internal table

-> Scenario 1:
1. Declare Field Symbol

IMP: Always check the field symbol is assigned or not to avoid runtime
error.
2.Assign FS to data object

- We change the value here in this E.g.

SUSHANT SINGH 44
- We address FS and it will automatically address
data objects. – IMP

➔ Scenario 2: assign a part to the FS:

➔ Scenario 3: In Loop

- If we change work area it will not impact internal


table.

- If we use FS, it will change internal table as it directly points to


it.

SUSHANT SINGH 45
Note: This is OLD Syntax of declaring and assigning.

➔ In Read Table:

Note: IMP: FS should be assigned, always check it,


otherwise runtime error:

SUSHANT SINGH 46
1. Can use MODIFY statement:
- Less performance.

2.Using FS - Improve performance

SUSHANT SINGH 47
➔ Append Internal table:
- Append one by one using work area

➔ Using FS:

- Inserting blank line to internal table and assigning it to


FS.

SUSHANT SINGH 48
Thank you for exploring the ABAP syntax.

Happy Learning

SUSHANT SINGH 49

You might also like