Skip to Content

With release 7.40 ABAP becomes extensively expression oriented. Besides the news I blogged about up to now, there are many new expression enabled operand positions, some new formatting options for string templates, and new built-in functions (e.g. ipow that can be used instead of **).

How do you write assignments in such an expression oriented world?

Clearly as

lhs = rhs.

Where rhs is

  • any data object
  • a functional method call
  • a call of a built-in function
  • an arithmetic expression
  • a string expression
  • a bit expression
  • a constuctor expression
  • a table expression

And some expression can be even lhs.

In this world there is no place for old fashioned statements MOVE and COMPUTE any more.

So it’s time to say goodbye and both are declared obsolete in the ABAP Keyword documentation
(like CALL METHOD for static method calls in Release 7.03/7.31 before).

A farewell to MOVE

You remember that one?

MOVE rhs TO lhs.

Everything you can write with MOVE you can write with the assignment operator =.

But you cannot write everything that is possible with the assignment operator with MOVE!

  • You cannot MOVE constructor expressions, table expressions, arithmetic expressions, string expressions, bit expressions, and not all built-in functions.
  • You cannot MOVE to LHS-expressions.

Clearly MOVE has expired …

A farewell to COMPUTE

With COMPUTE it’s another way around.

COMPUTE lhs = rhs.

You can write COMPUTE in front of each assignment with the assignment operator = and it has absolutely no effect on the statement!

You can even write

COMPUTE lhs ?= rhs.

That makes no sense!

The only assignment where COMPUTE makes sense from the literal meaning of the word is that where you have an arithmetic expression as rhs, That’s where it comes from (in stone age ABAP we had only assignments of data objects with MOVE and arithmetic calculations with COMPUTE). But nowadays it is simply superfluous to write COMPUTE in front of assignments.

Leave it away in new programs!

To report this post you need to login first.

11 Comments

You must be Logged on to comment or reply to a post.

  1. Volker Wegert

    Couldn’t agree more. I haven’t used either MOVE or COMPUTE for over 10 years of ABAP programming, and I certainly won’t start now.

    (0) 
  2. Peter Inotai

    I definitely won’t miss them. 🙂

    Is there some kind of code inspector check for lower releases, which would help already to avoid using these statements?

    Thanks,

    Peter

    (0) 
    1. Horst Keller Post author
      • Step 1: 

        MOVE-CORRESPONDING is extended with Release 7.40, SP05. You can move components of internal tables now:

        MOVE-CORRESPONDING [EXACT] itab1 TO itab2
            [EXPANDING NESTED TABLES] [KEEPING TARGET LINES].

      • Step 2:

        An new operator CORRESPONDING( … ) is under development that covers most of the statement MOVE-CORRESPONDING and will add additional features (mapping of different component names!). Hopefully with Release 7.40, SP05 too. -> Usage of the operator will be recommended then.

      (0) 
      1. Ralf Wenzel

        I have a functional method class=>method. The return value of this method is an internal table with a column ‘OBJ’, that contents an object. An instance attribute of this object is a structure.

        I do have an itab “target” as well, same structure as the object attribut.

        loop at class=>method( ) assigning field-symbol(<source>).

          append initial line to target assigning field-symbol(<target>).

          move-corresponding <source>-obj->attrib to <target>.

          ” <source> is a line of the table, that is returned by class=>method.

          ” a field of this structure <source> contains an object ‘OBJ’, which

          ” has an instance attribute ‘ATTRIB’ which has the same structure

          ” like <target>.

        endloop.

        Because <source> und <target> do have the same declaration, I’d like to have a shorter way to append, but I do not find – even in SAP Help.

        Something like:

        append lines of class=>method( )-obj->attrib to target.

        BUT:

        append does not work, because the return value of class=>method is a table.

        append lines of  does not work, because class=>method( )-obj->attrib is NOT a table.

        Do you have an idea for a shorter form of that LOOP?

        (0) 
        1. Horst Keller Post author

          Do you have an idea for a shorter form of that LOOP?

            target = VALUE #( FOR <source> IN class=>method( )
                             ( CORRESPONDING #( <source>obj->attrib ) ) ).

          (0) 

Leave a Reply