Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Loop At Assigning syntax question

Former Member
0 Kudos

I have a table that I want to reverse the values of each of the numeric fields. I want to use a Loop At I_TABLE assigning <fs>. Then within that structure I want to calculate the inverse of each of the fields in the internal table containing the appropriate field names. Here is my sample code:

*Loop at each record in internal table...

LOOP AT DATA_PACKAGE assigning <DP>.

  • Loop at table with numeric field names

LOOP AT I_DD03L INTO WA_DD03L.

MOVE WA_DD03L-FIELDNAME TO FNAME.

ASSIGN (FNAME) TO <F>.

  • Reverse each numeric field in <DP>

<DP>-<F> = <DP>-<F> * (-1).

ENDLOOP.

ENDLOOP.

I get an error that states <DP>-<F> does not exist.

Any ideas?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Try this piece of code

<b>DATA: i_dd03l TYPE dd03l OCCURS 0 WITH HEADER LINE.

DATA: data_package TYPE t001 OCCURS 0.

DATA: fname(61).

DATA: wa_t001 TYPE t001.

FIELD-SYMBOLS: <dp> STRUCTURE wa_t001 DEFAULT wa_t001, <f>.

SELECT * FROM t001 INTO TABLE data_package.

SELECT * FROM dd03l INTO TABLE i_dd03l WHERE tabname EQ 'T001'.

*Loop at each record in internal table...

LOOP AT data_package ASSIGNING <dp>.

NEW-LINE.

  • Loop at table with numeric field names

LOOP AT i_dd03l.

CONCATENATE '<DP>-' i_dd03l-fieldname INTO fname.

ASSIGN (fname) TO <f>.

WRITE: <f>.

ENDLOOP.

ENDLOOP.</b>

used WRITE for testing.

Rishi

3 REPLIES 3

Former Member
0 Kudos

Try this piece of code

<b>DATA: i_dd03l TYPE dd03l OCCURS 0 WITH HEADER LINE.

DATA: data_package TYPE t001 OCCURS 0.

DATA: fname(61).

DATA: wa_t001 TYPE t001.

FIELD-SYMBOLS: <dp> STRUCTURE wa_t001 DEFAULT wa_t001, <f>.

SELECT * FROM t001 INTO TABLE data_package.

SELECT * FROM dd03l INTO TABLE i_dd03l WHERE tabname EQ 'T001'.

*Loop at each record in internal table...

LOOP AT data_package ASSIGNING <dp>.

NEW-LINE.

  • Loop at table with numeric field names

LOOP AT i_dd03l.

CONCATENATE '<DP>-' i_dd03l-fieldname INTO fname.

ASSIGN (fname) TO <f>.

WRITE: <f>.

ENDLOOP.

ENDLOOP.</b>

used WRITE for testing.

Rishi

0 Kudos

I see where you are going here and it looks like it will work. I am trying to avoid the MODIFY DATA_PACKAGE and trying to directly change the values by using the field symbol for performance reasons (I have millions of records to change).

Will I still need the MODIFY statement or will the "<F> = <F> * (-1)." write directly to the field symbol and avoid the need for the MODIFY statement?

0 Kudos

new enhanced version....

<b>DATA: i_dd03l TYPE dd03l OCCURS 0 WITH HEADER LINE.

DATA: data_package TYPE t001 OCCURS 0.

DATA: fname(61).

DATA: wa_t001 TYPE t001.

FIELD-SYMBOLS: <dp> STRUCTURE wa_t001 DEFAULT wa_t001, <f>.

SELECT * FROM t001 INTO TABLE data_package.

SELECT * FROM dd03l INTO TABLE i_dd03l WHERE tabname EQ 'T001'.

*Loop at each record in internal table...

LOOP AT data_package ASSIGNING <dp>.

NEW-LINE.

  • Loop at table with numeric field names

LOOP AT i_dd03l.

CONCATENATE '<DP>-' i_dd03l-fieldname INTO fname.

ASSIGN (fname) TO <f>.

IF i_dd03l-fieldname EQ 'BUTXT'.

<f> = 'Rishi'.

ENDIF.

ENDLOOP.

ENDLOOP.

  • contents have changed without modify

LOOP AT data_package ASSIGNING <dp>.

WRITE / <dp>.

ENDLOOP.</b>

notice that there is no modify.

Rishi