Tuesday, January 17, 2017

ABAP inline declarations

One of the new features of ABAP version 74 is inline declarations within ABAP expressions. The feature helps to shorten ABAP statements as there is no need for specific data variable creation upfront the statement.

The inline declaration is executed using an operator in a expression while placed in declaration position. Result of the inline declaration is used within the ABAP statement at the statement operand.

Examples:
DATA:
TYPES t_itab TYPE TABLE OF i 
             
WITH NON-UNIQUE KEY table_line

DATA(itab) = VALUE t_itab( ( ) ( ) ( ) ). 
LOOP AT itab INTO DATA(wa). 
  
... 
ENDLOOP.
DATA(text) = ’…’.

FIELD-SYMBOL:
TYPES t_itab TYPE TABLE OF i 
             
WITH NON-UNIQUE KEY table_line

DATA(dref) = NEW t_itab( ( ) ( ) ( ) ). 

ASSIGN dref->TO FIELD-SYMBOL(). 

LOOP:

LOOP AT  ASSIGNING FIELD-SYMBOL(). 
  
... 
ENDLOOP.

ASSIGN:
ASSIGN ... TO FIELD-SYMBOL().

READ TABLE:
READ TABLE itab INTO DATA(wa) ...
READ TABLE itab ASSIGNING FIELD-SYMBOL() ... 

FIND:
FIND ... IN ... MATCH COUNT DATA(cnt).

CALL TRANSFORMATION:
CALL TRANSFORMATION ... RESULT XML DATA(xml).

Method call:
oref->methIMPORTING p1 DATA(a1)
 
IMPORTING p2 DATA(a2)
 
... ).
DATA(ref) = class=>factory( ... ).
DATA(ixml) = cl_ixml=>create( ).
DATA(stream_factory) = ixml->create_stream_factory( ).
DATA(document) = ixml->create_document( ). 

SELECT:
Target is work area:
  SELECT SINGLE @abap_true FROM /bic/pcompcod
    
WHERE /bic/pcompcod @i_compcod AND objvers 'A'
    
INTO @DATA(lv_compcode).
Target is internal table:
  SELECT scarr~*spfli~*
     
FROM scarr INNER JOIN spfli ON scarr~carrid spfli~carrid
     
WHERE scarr~carrid @carrier
     
ORDER BY scarr~carrid
     
INTO TABLE @DATA(jtab).


More information:
ABAP demo report: DEMO_SELECT_INLINE_DECLARATION
ABAP News for Release 7.40 – Inline Declarations

No comments: