ABAP New Syntax
ABAP New Syntax
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:
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.
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:
• at first
• at last
• at new field_name (Add on: SUM)
• at end of field_name
• Insert
• Update
• Delete
• Modify
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
3. CASE:
OLD Way:
- Fetched data:
SUSHANT SINGH 3
- Looping over this table, and based on condition, fetching it over new table:
SUSHANT SINGH 4
NEW Way:
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:
SUSHANT SINGH 7
IMPORTANT:
- ZNEWSYNTX_OPEN_SQL_AGG_FUNCT1
- ZNEWSYNTX_OPEN_SQL_AGG_FUNCT2
- C (Character)
- N (Numeric)
- D (Date)
- I (Integer)
- P (Packed decimal)
- F (Floating point)
SUSHANT SINGH 8
Summary:
SUSHANT SINGH 9
1. Inline Declarations:
➔ #NEW
2. Conditional statement:
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
SUSHANT SINGH 15
- Use it as below:
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
SUSHANT SINGH 17
- It will append after existing records
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
OR
SUSHANT SINGH 19
or
(Table Type)
SUSHANT SINGH 20
IMP: Only Data of matching columns will move, rest all fields will be blank!
QnA:
------------------------------------------------------------------------------------------------------------------------------------
- 2 FM for Conversion:
SUSHANT SINGH 21
NOTE:
- SAP Use these FM, while storing VBLEN (SAP adds the leading 0)
SUSHANT SINGH 22
- With New Syntax:
------------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------- --------
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.
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)
SUSHANT SINGH 27
- New way:
- Syntax:
SUSHANT SINGH 28
SUSHANT SINGH 29
IMP:
- 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:
SUSHANT SINGH 32
SUSHANT SINGH 33
- Below is wrong approach:
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.
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:
SUSHANT SINGH 39
Check Program: HET Server
- ZCONTROL_BREAK02
SUSHANT SINGH 40
1. Insert:
- Insert single 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
SUSHANT SINGH 42
- Whatever we do with the field symbol, it will impact
data objects
SUSHANT SINGH 43
2. Generic:
-> 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
SUSHANT SINGH 44
- We address FS and it will automatically address
data objects. – IMP
➔ Scenario 3: In Loop
SUSHANT SINGH 45
Note: This is OLD Syntax of declaring and assigning.
➔ In Read Table:
SUSHANT SINGH 46
1. Can use MODIFY statement:
- Less performance.
SUSHANT SINGH 47
➔ Append Internal table:
- Append one by one using work area
➔ Using FS:
SUSHANT SINGH 48
Thank you for exploring the ABAP syntax.
Happy Learning
SUSHANT SINGH 49