Gme Moreno
Gme Moreno

Reputation: 19

Get value from a table and save it inside of a structure

I am new in ABAP and I have to modify these lines of code:

LOOP AT t_abc ASSIGNING <fs_abc> WHERE lgart = xyz.
  g_abc-lkj = g_abc-lkj + <fs_abc>-abc.
ENDLOOP.

A coworker told me that I have to use a structure and not a field symbol.

How will be the syntax and why to use a structure in this case?

Upvotes: 0

Views: 1353

Answers (2)

Klaus Hopp
Klaus Hopp

Reputation: 41

Your code is correct, because Field symbol functions almost the same as a structure.

For Field symbol

  • Field symbol is a pointer,
  • so there is no data copy action for field symbol, and the performance is better
  • Well if we changed the value via field symbol, the internal table get changed also

For Structure

  • Structure is a copy of the data, so there is a data copy action, and the performance is bad if the data row is bigger than 200 bytes (based on the SAP ABAP programming guide for performance)
  • If changed the data in the structure, the original internal table remains the same because there are 2 copies of the data in memory

Upvotes: 0

Jagger
Jagger

Reputation: 10524

I have no idea why the co-worker wants that you use a structure in this case, because using a field symbol while looping is usually more performant. The reason could be that you are doing some kind of a novice training and he wants you to learn different syntax variants.

Using a structure while looping would like this

LOOP AT t_abc INTO DATA(ls_abc)
  WHERE lgart = xyz.
  g_abc-lkj = g_abc-lkj + ls_abc-abc.
ENDLOOP.

Upvotes: 4

Related Questions