简体   繁体   中英

How can I reinitialize a single column in a table using the new ABAP statement FOR

I have appended two fieldcategory tables together:

rt_joined = value #( ( lines of it_left ) ( lines of it_right ) ).

Now I would like to reinitialise the col_pos field of the new table.

Previously I would do something like this:

loop at rt_joined assigning <ls_fcat>.
  <ls_fcat>-col_pos = sy-tabix.
endloop.

Is it possible to do this using the FOR statement (ABAP 7.4 SP8)?

Edit: A Simple example to test with:

report test1.

types:
  begin of line,
    col1 type i,
    col2 type i,
    col3 type i,
  end of line,

  itab type standard table of line with empty key.


data: itab2 type standard table of line with empty key.

"Fills the table with some initial data
data(itab) = value itab(
     for j = 11 then j + 10 until j > 40
     ( col1 = j col2 = j + 1 col3 = j + 2  ) ).

"Results IN:
" COL1  COL2    COL3
" 11      12      13
" 21      22      23
" 31      32      33

"Now I copy the table to a second table and try to set col1 as an index
itab2 = itab1.
itab2 = value itab( for i = 1 while i <= lines( itab )
                   ( col1 = i ) ).

"Results IN:
" COL1  COL2    COL3
" 1       0       0
" 2       0       0
" 3       0       0

"I would like this to be:
" COL1  COL2    COL3
" 1       12      13
" 2       22      23
" 3       32      33   

This does what I want using the test example:

itab2 = value #( for wa in itab index into idx
                 ( col1 = idx
                   col2 = wa-col2
                   col3 = wa-col3 ) ).
itab = itab2.

But I don't think this is better than:

loop at itab assigning <wa>.
  <wa>-col1 = sy-tabix.
endloop.

It is neccesary to move each field in the structure manually, plus there is an additional table assignment, so I'm not sure how it compares performance wise

This shouldn't be completely off, however I'm not sure if using a new itab for this is necessary:

DATA(lt_initialized) = VALUE rt_joined(
                       FOR i = 1 THEN i + 1 WHILE i <= lines( rt_joined )
                       ( col_pos = i  ) ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM