Skip to Content
Technical Articles
Author's profile photo J. Graus

Field symbol in iteration expression

In table iteration expression (like the FOR expression) one can decide to either use a work area or field symbol.

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

The ABAP help does indicate: For each read line, the result is either assigned to a local work area wa1 or to a field symbol <fs>.

In my own developments I prefer to use reference variables over field symbols. In a table iteration expression only field symbol or work area can be used. Because of performance reason I prefer to use field symbols here. But not completely sure there is a difference in performance as the expression does get processed internally. I double check by a small test program: Using field symbol within a table iteration expression does have a performance improvement.

DATA:
  lt_mara            TYPE mara_tt,
  lt_matnr           TYPE table_matnr,
  lv_timestamp_start TYPE timestampl,
  lv_timestamp_end   TYPE timestampl,
  lv_timestamp       TYPE timestampl.

SELECT * FROM mara INTO TABLE lt_mara.

GET TIME STAMP FIELD lv_timestamp_start.
DO 1000 TIMES.
  lt_matnr = VALUE table_matnr( FOR ls_mara IN lt_mara ( ls_mara-matnr ) ).
ENDDO.
GET TIME STAMP FIELD lv_timestamp_end.
lv_timestamp = lv_timestamp_end - lv_timestamp_start.
WRITE / `Workarea: ` && lv_timestamp.

GET TIME STAMP FIELD lv_timestamp_start.
DO 1000 TIMES.
  lt_matnr = VALUE table_matnr( FOR <ls_mara> IN lt_mara ( <ls_mara>-matnr ) ).
ENDDO.
GET TIME STAMP FIELD lv_timestamp_end.
lv_timestamp = lv_timestamp_end - lv_timestamp_start.
WRITE / `Field symbol: ` && lv_timestamp.
Test

Workarea: 1.6138080
Field symbol: 0.5876100

Assigned Tags

      4 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Sandra Rossi
      Sandra Rossi

      Thanks. I could run the tests on my system, but I would trust you if you could show some data about the performance gain 😉

      Author's profile photo Wolfgang Janes
      Wolfgang Janes

      Ohh thanks. Nice to know that field symbols have a performance boost. 🙂

      Author's profile photo Denis Galand
      Denis Galand

      I didn't know we could use field symbols there, thanks for the tip 🙂

      Author's profile photo Shailesh Kumar
      Shailesh Kumar

      replacing wa in my for loops with field symbols henceforth!