Inline Declarations in New ABAP Syntax


Please go through the collection of some basic inline declarations frequently used in ABAP new syntax coding.

*<!-- Declaring variables without data element -->

DATA(lv_text) = 'My Text'. 

*<!-- Select statement -->

*-- Single field
SELECT SINGLE bukrs FROM bkpf INTO @DATA(lv_bukrs).

*-- Multiple Fields
SELECT SINGLE bukrs, belnr FROM bkpf INTO (@DATA(lv_bukrs), @DATA(lv_belnr)).

*-- Work Area
SELECT SINGLE bukrs, belnr, gjahr FROM bkpf INTO @DATA(ls_bkpf).

*-- Internal Table
SELECT bukrs, belnr, gjahr, budat, bldat
  FROM bkpf
  INTO TABLE @DATA(lt_bkpf)
 WHERE bukrs = @lv_bukrs
   AND belnr = @lv_belnr
   AND gjahr = @lv_gjahr.

*<!-- Creating instance of class using NEW keyword instead of CREATE OBJECT -->

DATA(lo_object) = NEW zcl_my_class( ).

*<!-- Return parameter of a method in OO-ABAP -->

DATA(lv_return) = zcl_test_class=>meth1( ). 

*<!-- Method parameters -->

lo_object->my_method( (
         IMPORTING iv_param = DATA(lv_value) 
         ).


*<!-- Looping at internal tables -->

LOOP AT lt_itab INTO DATA(ls_line).
  
ENDLOOP.


*<!-- Loop internal tables using field symbols -->

LOOP AT lt_bkpf ASSIGNING FIELD-SYMBOL(<fs_bkpf>).

*<!---->
ENDLOOP.

*<!-- Read Internal Table -->

READ TABLE lt_bkpf INTO DATA(ls_bkpf) WITH KEY....
READ TABLE lt_bkpf ASSIGNING FIELD-SYMBOL(<fs_bkpf>) WITH KEY....

*<!-- Or -->

TRY.

*READ TABLE lt_itab INTO DATA(ls_line) INDEX 1.
  DATA(ls_line) = lt_itab[ 1 ].
  MESSAGE "Read successful" TYPE 'S'.
CATCH cx_sy_itab_line_not_found.

*<!-- Always use try-catch block to avoid dumps -->
  MESSAGE 'Read failed' TYPE 'E'.    
ENDTRY.

Post a Comment

Previous Post Next Post