ABAP 7.40 Quick Reference

+ -

So you're an experienced ABAP programmer wanting to leverage off the fantastic new functionality available to you in ABAP 7.40!

 

However, searching for information on this topic leads you to fragmented pages or blogs that refer to only a couple of the new features available to you.

What you need is a quick reference guide which gives you the essentials you need and shows you how the code you are familiar with can be improved with ABAP 7.40.

 

The below document contains exactly this!

 

It gives examples of "classic" ABAP and its 740 equivalent. It goes into more details on the more difficult topics normally via examples. This allows the reader to dive in to the level they desire. While this document does not contain everything pertaining to ABAP 740 it certainly covers the most useful parts in the experience of the author.

 

The document has been compiled by drawing on existing material available online as well as trial and error by the author. In particular the blogs by Horst Keller have been useful and are the best reference I have found (prior to this document ). He has a landing page of sorts for his various blogs on the topic here:

ABAP Language News for Release 7.40

 

Credit also goes to Naimesh Patel for his useful explanations and examples on ABAP 7.40. Here is his example of the "FOR iteration expression" which I leaned on (links to his other 740 articles can be found at the bottom of the link):

http://zevolving.com/2015/05/abap-740-for-iteration-expression/

 

I compiled the below document to make the transition to using ABAP 740 easier for myself and my project team. It has worked well for us and I hope it will do the same for you.

 

Regards,

Jeff Towell

 

 

ABAP 7.40 Quick Reference  

 

 

Author:

Jeffrey Towell

Created:

2015

 

Contents

 

1. Inline Declarations

2. Table Expressions

3. Conversion Operator CONV

     I.  Definition

     II. Example

4. Value Operator VALUE

     I.   Definition

     II.  Example for structures

     III. Examples for internal tables

5. FOR operator

     I.   Definition

     II.  Explanation

     III. Example 1

     IV. Example 2

     V. FOR with THEN and UNTIL|WHILE

6. Reduce

     I.   Definition

     II.  Note

     III. Example 1

     IV. Example 2

     V.  Example 3

7. Conditional operators COND and SWITCH

     I.   Definition

     II.  Example for COND

     III. Example for SWITCH

8.Strings

     I.   String Templates

     II.  Concatenation

     III. Width/Alignment/Padding.

     IV. Case

     V.  ALPHA conversion

     VI.  Date conversion

9. Classes/Methods

     I.   Referencing fields within returned structures

     II.  Methods that return a type BOOLEAN

     III. NEW operator

10. Meshes

     I.   Problem

     II.  Solution

     III. Output

11. Filter

     I.   Definition

     II.  Problem

     III. Solution

 

1. Inline Declarations

 

Description

Before 7.40

With 7.40

Data statement

DATA text TYPE string.
text = `ABC`.

DATA(text) = `ABC`.

Loop at into work area

DATA wa like LINE OF itab.
LOOP AT itab
INTO wa.  
  ...
ENDLOOP.

LOOP AT itab INTO DATA(wa).  
  ...
ENDLOOP
.

Call method

DATA a1 TYPE ...

DATA a2 TYPE ...

oref->meth( IMPORTING p1 = a1

            IMPORTING p2 = a2

          ).

oref->meth(

        IMPORTING p1 = DATA(a1)

        IMPORTING p2 = DATA(a2) ).

Loop at assigning

FIELD-SYMBOLS: <line> type …

LOOP AT itab ASSIGNING <line>.

  ...

ENDLOOP.

LOOP AT itab

   ASSIGNING FIELD-SYMBOL(<line>).
   ...
ENDLOOP.

Read assigning

FIELD-SYMBOLS: <line> type …

READ TABLE itab

           ASSIGNING <line>.

READ TABLE itab

   ASSIGNING FIELD-SYMBOL(<line>).

Select into

table

DATA itab TYPE TABLE OF dbtab.

SELECT * FROM dbtab

   INTO TABLE itab

        WHERE fld1 = lv_fld1.

SELECT * FROM dbtab

   INTO TABLE DATA(itab) 

        WHERE fld1 = @lv_fld1.

Select single

into

SELECT SINGLE f1 f2 

  FROM dbtab

  INTO (lv_f1, lv_f2)

WHERE ...

WRITE: / lv_f1, lv_f2.

SELECT SINGLE f1 AS my_f1,

              F2 AS abc  

         FROM dbtab

         INTO @DATA(ls_str) "struc

        WHERE ...

WRITE: / ls_str-my_f1, ls_str-abc.

 

 

 

2. Table Expressions

If a table line is not found, the exception CX_SY_ITAB_LINE_NOT_FOUND is raised. No sy-subrc.


Description

Before 7.40

With 7.40

Read Table  index

READ TABLE itab INDEX idx

      INTO wa.

wa = itab[ idx ].

Read Table  using key

READ TABLE itab INDEX idx

     USING KEY key

      INTO wa.

wa = itab[ KEY key INDEX idx ].

Read Table  with key

READ TABLE itab

  WITH KEY col1 =

           col2 =

       INTO wa.

wa = itab[ col1 = col2 = ].

Read Table  with key components

READ TABLE itab

      WITH TABLE KEY key

COMPONENTS col1 =

           col2 =

      INTO wa.

wa = itab[ KEY key col1 =

                    col2 = ].

Does record exist?

READ TABLE itab ...

    TRANSPORTING NO FIELDS.

IF sy-subrc = 0.

  ...

ENDIF.

IF line_exists( itab[ ... ] ).

...

ENDIF.

Get table index

DATA idx type sy-tabix.

READ TABLE ...

  TRANSPORTING NO FIELDS.

  idx = sy-tabix.

DATA(idx) =

       line_index( itab[ ... ] ).

 

NB: There will be a short dump if you use an inline expression that references a non-existent record.

        SAP says you should therefore assign a field symbol and check sy-subrc.

 

ASSIGN lt_tab[ 1 ] to FIELD-SYMBOL(<ls_tab>).
IF sy-subrc = 0.
...

ENDIF.


NB: Use itab [ table_line = … ] for untyped tables.


 

3. Conversion Operator CONV

I.  Definition

CONV dtype|#( ... )

dtype = Type you want to convert to (explicit)

#     = compiler must use the context to decide the type to convert to (implicit)


II. Example

Method cl_abap_codepage=>convert_to expects a string

Before 7.40

DATA text TYPE c LENGTH 255.

DATA helper TYPE string.

DATA xstr   TYPE xstring.

 

helper = text.

xstr = cl_abap_codepage=>convert_to( source = helper ).

With 7.40

DATA text TYPE c LENGTH 255.

 

DATA(xstr) = cl_abap_codepage=>convert_to( source = CONV string( text ) ).

OR

DATA(xstr) = cl_abap_codepage=>convert_to( source = CONV #( text ) ).

 

 

 

4. Value Operator VALUE

I. Definition

     Variables:    VALUE dtype|#( )

     Structures:  VALUE dtype|#( comp1 = a1 comp2 = a2 ... )

     Tables:         VALUE dtype|#( ( ... ) ( ... ) ... ) ...

 

II. Example for structures

     TYPES:  BEGIN OF ty_columns1, “Simple structure
                     cols1 TYPE i,
                     cols2 TYPE i,
                   END OF ty_columns1.

      TYPES: BEGIN OF ty_columnns2,  “Nested structure
                     coln1 TYPE i,
                     coln2 TYPE ty_columns1,
                  END OF ty_columns2.

      DATA: struc_simple TYPE ty_columns1,
                struc_nest    TYPE ty_columns2.

 

     struct_nest   = VALUE t_struct(coln1 = 1
                                                  coln2-cols1 = 1
                                                  coln2-cols2 = 2 ).


     OR


     struct_nest   = VALUE t_struct(coln1 = 1
                                                   coln2 = VALUE #( cols1 = 1

                                                   cols2 = 2 ) ).


III. Examples for internal tables

Elementary line type:

 

TYPES t_itab TYPE TABLE OF i WITH EMPTY KEY.

DATA itab TYPE t_itab.

itab = VALUE #( ( ) ( 1 ) ( 2 ) ).

 

Structured line type (RANGES table):

 

DATA itab TYPE RANGE OF i.

itab = VALUE #( sign = 'I'  option = 'BT' ( low = 1  high = 10 )
( low = 21 high = 30 )
( low = 41 high = 50 )
option = 'GE' ( low = 61 )  ).


 

5. FOR operator

I. Definition

     FOR wa|<fs> IN itab [INDEX INTO idx] [cond]

 

II. Explanation

This effectively causes a loop at itab. For each loop the row read is assigned to a work area (wa) or field-symbol(<fs>).

This wa or <fs> is local to the expression i.e. if declared in a subrourine the variable wa or <fs> is a local variable of

that subroutine. Index like SY-TABIX in loop.

Given: 

TYPES: BEGIN OF ty_ship,
           tknum
TYPE tknum,     "Shipment Number
           name 
TYPE ernam,     "Name of Person who Created the Object
           city 
TYPE ort01,     "Starting city
           route
TYPE route,     "Shipment route
      
END OF ty_ship.
TYPES: ty_ships TYPE SORTED TABLE OF ty_ship WITH UNIQUE KEY tknum.
TYPES: ty_citys TYPE STANDARD TABLE OF ort01 WITH EMPTY KEY.

 

GT_SHIPS type ty_ships. -> has been populated as follows:

RowTKNUM[C(10)]Name[C(12)]City[C(25)]Route[C(6)]
1001JohnMelbourneR0001
2002GavinSydneyR0003
3003LucyAdelaideR0001
4004ElainePerthR0003