New Syntax (ABAP)
Inline data declaration
Inline data declaration is a new way of declaring variables and
field symbols at operand positions.
There is no need to declarethe variables separately. The keyword used is DATA for inline
declarations.
In old method, we need to declare the objects like types, internal
table and work area first then we can use that object.
But as per new syntax we can declare the object where we use it.
It can be used for declaring below:
Declaration of Variable
Declaration of table, types, work areas.
Declaration of actual parameters:
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 2
Inline data declaration
1).Declaration of Variable
DATA (v_name) = 'ABC 199 XYZ'.
WRITE: 'Output :’, v_name.
2). Declaration of work areas:
LOOP AT itab INTO DATA(wa).
...
ENDLOOP.
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 3
Inline data declaration
Declaration of actual parameters:
Old method
DATA a1 TYPE … DATA a2 TYPE …
oref->meth( IMPORTING p1 = a1
IMPORTING p2 = a2
…)
New Method
oref->meth( IMPORTING p1 = DATA(a1) IMPORTING p2 = DATA(a2)
… ).
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 4
Inline data declaration
Input Output
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 5
Standard internal table declaration
TYPES t_itab TYPE STANDARD TABLE OF i WITH DEFAULT KEY.
DATA(dref) = NEW t_itab( ( 100 ) ( ) ( 3000 ) ).
Output in debug mode:
Here as we have declared the internal table as standard table so the values stored as 100->0->3000
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 6
Sorted internal table declaration
TYPES t_itab TYPE SORTED TABLE OF i WITH UNIQUE KEY table_line.
DATA(dref) = NEW t_itab( ( 100 ) ( ) ( 3000 ) ).
The keyword TABLE_LINE is used for dynamic table /Variable insert
Here as we have declared the internal table as sorted table so the values stored
as 0->100->3000
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 7
Sorted internal table declaration
If you declared some specific component in type then you have to write
‘ Component = ‘ while using the keyword NEW otherwise you will get an error.
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 8
Internal table with more components
TYPES: tt_data TYPE MD_RANGE_T_MATNR.
DATA(ta_data_multi_comp) =
NEW tt_data( ( sign = 'I' Option = 'EQ' low = '00463928' )
( sign = 'I' Option = 'EQ' low = '00463929' ) ).
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 9
MOVE-CORRESPONDING for Internal Tables
You can use MOVE-CORRESPONDING not only for structures but also for internal tables .
Components of the same name are assigned row by row.
New additions EXPANDING NESTED TABLES and KEEPING TARGET LINES
allow to resolve tabular components of structures and to append lines instead of
overwriting existing lines.
Example:
OLD :
MOVE-CORRESPONDING wa1 TO wa2.
New:
MOVE-CORRESPONDING itab1 TO itab2 EXPANDING NESTED TABLES
KEEPING TARGET LINES.
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 10
MOVE-CORRESPONDING for Internal Tables
Input :
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 11
MOVE-CORRESPONDING for Internal Tables
Output :
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 12
Table expressions
Table expressions replace READ TABLE statement
You need to use the square bracket [ ]. Within the bracket, you would
need to specify the component you want to use as the key.
When table entry doesn’t exist, a catchable exception
CX_SY_ITAB_LINE_NOT_FOUND is raised.
• Old syntax
READ TABLE IT_SALES INTO WA_SALES WITH KEY
kunnr = '0000009000’
vbeln = 'S2’.
• New syntax
data(wa_sales1) = it_sales[ kunnr = '0000009000’
vbeln = 'S2' ].
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 13
Table expressions
Input Output
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 14
CONVERSION_EXIT_ALPHA_INPUT/OURPUT
OLD : Traditionally the function modules
CONVERSION_EXIT_ALPHA_INPUT and
CONVERSION_EXIT_ALPHA_OUTPUT were used for conversion
New :You just need to use the ALPHA keyword formatting option with OUT or IN.
Eg : KUNNR value of ‘12345’ changes to ‘000001235’, 5 zero added as
KUNNR length is 10 CHAR
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 15
CONVERSION_EXIT_ALPHA_INPUT/OURPUT
Input Output
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 16
Escape Character for Host Variables
• ABAP data objects used in Open SQL statements usually variables are interpreted as host
variables.
• Host variables should be prefixed with the escape character @.
• In the below example, pcarrid is the host variable and CARRID is the guest variable.
• Similarly ITSCARR is the host variable and SCARR is the guest.
DATA PCARRID TYPE SCARR-CARRID VALUE 'AA’.
SELECT CARRID,CARRNAME,CURRCODE,URL FROM SCARR
INTO TABLE @DATA(ITSCARR) WHERE CARRID = @PCARRID.
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 17
Using SWITCH statement
Use SWITCH statement instead of CASE statement
Old: By using CASE Statement , you need to keep mentioning what variable
you’re filling in every branch
Eg . CASE LV_INDICATOR.
WHEN 1. LV_DAY = 'January'. WHEN 2. LV_DAY = 'February'.
ENDCASE.
New : Using Switch statement, you don’t need to keep mentioning what variable you’re
filling in every branch .
Eg. DATA(lv_day) = SWITCH char10( lv_indicator
WHEN 1 THEN 'January‘
WHEN 2 THEN 'February' ).
In the above example,using SWITCH statement, you don’t need to mention
LV_DAY variable in every branch
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 18
Using SWITCH statement
The keyword #(Hash) is used when you are sure of the no. of characters that
the switch statement will return
PARAMETERS p_day type i .
DATA(lv_month) = SWITCH #( p_month
WHEN 1 THEN 'January‘
WHEN 2 THEN 'February' ).
else 'Invalid' ).
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 19
Using SWITCH statement
Input
Output
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 20
INNER JOIN Improvement
You can use wildcard like SELECT * in new inner join
Old syntax
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'.
New syntax:
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).
Note: The symbol * ( asterisk ) it acts just like the wildcard SELECT * , and for this sample
you will get all fields in VBAK table.
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 21
INNER JOIN Improvement
Input
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 22
NEW keyword for creating Objects
Use the keyword ‘NEW’ to create instances of an object instead of the
keyword CREATE OBJECT.
Old syntax
DATA : obj TYPE REF TO ZCL_MYCLASS.
CREATE OBJECT obj EXPORTING myname = 'India’.
New syntax:
obj = NEW ZCL_MYCLASS( myname = 'India' ).
Note: Key word ‘NEW’ is used to create instance of class ZCL_MYCLASS,
Here obj is the object name.
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 23
FILTER expressions
The new FILTER operator enables two kinds of filtering an internal table
Filter with single values
Filter with filter table
Filter with single values: Simply extract the lines from an internal
table into a tabular result, that fulfill a simple value condition.
DATA(extract) = FILTER #( spfli_tab USING KEY carr_city
WHERE carrid = CONV #( to_upper( carrid ) ) AND cityfrom = CONV
#( to_upper( cityfrom ) ) ).
Note: As a prerequisite, the filtered table (spfli_tab) must have a sorted or a hash key
(primary or secondary), that is evaluated behind WHERE.
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 24
FILTER expressions
Input
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 25
FILTER expressions
Output
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 26
Internal table with more components
TYPES: tt_data TYPE MD_RANGE_T_MATNR.
DATA(ta_data_multi_comp) =
NEW tt_data( ( sign = 'I' Option = 'EQ' low = '00463928' )
( sign = 'I' Option = 'EQ' low = '00463929' ) ).
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 27
Explicit type declaration
TYPES ty_matnr TYPE matnr. DATA(tp_matnr) = NEW ty_matnr( 9001 ).
Here TP_MATNR get the characteristic of MATNR (40) though TY_MATNR value passed 4 character (90
Output in debug mode:
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 28
How to work with deep structure
TYPES: BEGIN OF ty_alv_data,
kunnr TYPE kunnr,
name1 TYPE name1,
ort01 TYPE ort01,
land1 TYPE land1,
t_color TYPE lvc_t_scol, “structure
END OF ty_alv_data.
TYPES: tt_alv_data TYPE STANDARD TABLE OF ty_alv_data WITH DEFAULT KEY.
DATA(o_alv_data) = NEW tt_alv_data(
( Build 1st row
( Build inner rows i.e for
t_color ) )
( Build 2nd row
( Build inner rows i.e for
t_color ) )
)
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 29
How to work with deep structure
Code Snippet for Deep Structure
Field t_color is again a structure
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 30
How to work with deep structure
Output in debug mode:
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 31
Table expressions
Demo Code Snippet
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 32
GROUP BY clause for Internal Tables
GROUP BY replaces the AT NEW or other means of going through grouped data.
What happens here is that the first LOOP statement is executed over all internal table
lines in one go and the new GROUP BY addition groups the lines.
Technically, the lines are bound internally to a group that belongs to a group key that is
specified behind GROUP BY.
LOOP AT flights INTO DATA(flight)
GROUP BY ( carrier = flight-carrid cityfr = flight-cityfrom )
ASCENDING
ASSIGNING FIELD-SYMBOL(<group>).
CLEAR members.
LOOP AT GROUP <group> ASSIGNING FIELD-SYMBOL(<flight>).
members = VALUE #( BASE members ( <flight> ) ).
ENDLOOP.
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 33
GROUP BY clause for Internal Tables
Input : Output :
Presentation Title | Author | Date © Capgemini 2018. All rights reserved | 34
About Capgemini
A global leader in consulting, technology services and digital transformation,
Capgemini is at the forefront of innovation to address the entire breadth of clients’
opportunities in the evolving world of cloud, digital and platforms. Building on its
strong 50-year heritage and deep industry-specific expertise, Capgemini enables
organizations to realize their business ambitions through an array of services from
strategy to operations. Capgemini is driven by the conviction that the business value
of technology comes from and through people. It is a multicultural company of
200,000 team members in over 40 countries. The Group reported 2017 global
revenues of EUR 12.8 billion.
Learn more about us at
[Link]
This presentation contains information that may be privileged or confidential
and is the property of the Capgemini Group.
Copyright © 2018 Capgemini. All rights reserved.