ABAP Language 7.4 bring a lot of brand new functionality, this article will focus on the large number of new features that have been introduced into ABAP 7.4. These features are divided into the following categories database access, creating data, string processing, calling function, conditional logic, internal table, OOP, etc.
1.ABAP Language 7.4 Database Access.
a.CASE statement in SQL Queries
One of the new features of ABAP 7.4 is the ability to insert CASE statements into SQL Queries. Please check ABAP Code below.
1 2 3 4 5 6 7 |
START-OF-SELECTION. SELECT CASE WHEN auart = 'Z1IN' THEN 'Z1IN' WHEN auart = 'Z2KP' THEN 'Z2KP' ELSE 'OTHERS' END AS group, vbeln FROM vbak INTO TABLE @DATA(li_vbeln). |
@ symbols is to let SAP System know you are not talking about field in the database, @DATA(li_Vbeln) is means SAP System will create internal table LI_VBELN directly so you dont need declare before.
b. INNER JOIN Improvement
If you ever used Inner Join in ABAP you must to list field one by one from the main table , this improvement you can list all of the fields. Please check out this ABAP Code.
Before ABAP 7.4
1 2 3 4 |
SELECT a~vbeln b~posnr b~matnr FROM vbak AS a INNER JOIN b AS vbap ON a~vbeln = b~vbeln INTO TABLE li_vbeln WHERE a~auart = 'Z1IN'. |
ABAP 7.4
1 2 3 4 |
SELECT a~*, b~posnr, b~matnr FROM vbak AS a INNER JOIN vbap as b ON a~vbeln = b~vbeln WHERE a~auart = 'Z1IN' INTO TABLE @DATA(li_vbeln). |
The symbol * ( asterisk ) it acts just like the wildcard SELECT * , and for this sample you will get all fields in VBAK table.
If you double click column A ( Flat Structure ) in Debugger, you will see all field in VBAK table.
c.Ommiting Data Type Declarations
In ABAP 7.4 has made it less important to declare variables at the start of your routine or method, the ABAP Compiler knows what data type it should be, instead of declaring it yourself and can save you several lines of code.
Before ABAP 7.4
1 2 3 |
DATA : lv_string type string. lv_string = 'ABAPGurus SAP ABAP Tutorial'. |
ABAP 7.4
1 |
DATA(lv_string) = 'ABAPGurus SAP ABAP Tutorial'. |
d.NEW keyword for Creating Objects
Normally in Java you need to use NEW to create instances of objects, but in the ABAP 7.4 , you can use NEW to instances object instead of use CREATE OBJECT.
Before ABAP 7.4
1 2 3 |
DATA : lo_myclass TYPE REF TO ZCL_MYCLASS. CREATE OBJECT lo_myclass EXPORTING myname = 'ABAPGurus'. |
ABAP 7.4
1 2 3 |
DATA : lo_myclass TYPE REF TO ZCL_MYCLASS. lo_myclass = NEW zcl_Myclass( myname = 'ABAPGurus' ). |
e.New String Features in ABAP 7.4
Normally you can use the CONCATENATE statement to concatenate two or more string. but start from ABAP 7.02 you can use pipes and curly bracket to concatenate two or more string.
Before ABAP 7.02 and ABAP 7.04
1 2 |
CONCATENATE 'MY First String' LV_NUMBER INTO LV_TEMP SEPARATED BY SPACES. CONCATENATE LV_TEMP LV_STATUS INTO LV_RESULT SEPARATED BY ' / '. |
ABAP 7.03 and ABAP 7.04
You can simpler ABAP Code for two lines before like this
1 |
lv_string = | My First String { lv_number } / { lv_status } |. |
In ABAP 7.40 You don’t need use CONVERSION_EXIT_ALPHA_INPUT and CONVERSION_EXIT_ALPHA_OUTPUT , you just need ALPHA keyword formatting option with OUT or IN.
1 2 3 4 5 6 7 |
DATA : lv_kunnr TYPE kunnr VALUE '110000010'. START-OF-SELECTION. DATA(lv_real) = |{ lv_kunnr ALPHA = IN } |. WRITE lv_real. |
f.Avoiding Type Mismatch Dump when Calling Function Module
Normally to call function module you need to pass some variable to function module parameter, the dump error occured when we declare different type our variable than parameter of function module.
In ABAP 7.40 you can declaring the variable from method /function module at the start of the routine but the rather at the instant they have their values filled by the method.
1 2 3 |
CALL FUNCTION 'ZMY_FM' EXPORTING ID = LV_MYID IMPORTING NAMEZ = DATA( LV_NAMEZ ). |
This approach has several advantages, fewer code lines, and avoid type mismatch error.
g. Using SWITCH statement as replacement for CASE
Using CASE you need to keep mentioning what variable you’re filling in every branch in CASE Statement.
1 2 3 4 5 6 7 8 9 |
... CASE LV_INDICATOR. WHEN 1. LV_DAY = 'January'. WHEN 2. LV_DAY = 'February'. ... ENDCASE. |
If you use SWITCH statement, you dont need mention LV_DAY variable in every branch.
1 2 3 4 5 6 |
lv_indicator = 1. DATA(lv_day) = SWITCH char10( lv_indicator WHEN 1 THEN 'January' WHEN 2 THEN 'February' ). write lv_day. |
h. COND statement as replacement for IF/ELSE
You can use IF/ELSE conditional in more compact using COND.
1 2 3 4 5 6 7 8 9 10 11 12 |
DATA : lv_indicator TYPE i. DATA : lv_desc TYPE char30. START-OF-SELECTION. lv_desc = COND char30( WHEN lv_indicator = 1 THEN 'January' WHEN lv_indicator = 2 THEN 'February' ELSE 'Nothing'). WRITE lv_desc. |