Application Development and Automation 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: 
Read only

Dynamic table - MODIFY with WHERE condition

Former Member
0 Likes
3,173

Hi,

I'm using dynamic itab and now I need to update several rows with same values - these rows has also the same value in "key column". I

For classic itab I can use:

modify itab from work_area transportating field1 field2 where pspnr = wa-pspnr.

for dynamic I tried:

modify <itab> from <work_area> transportating ('FIELD1') ('FIELD2) where ???? - how to write where condition? I need to update all rows with same PSPNR value in work area...

Many thanks Jiri

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,897

MOVE 'pspnr' TO LV_STRING.

ASSIGN COMPONENT lv_string OF STRUCTURE <itab> TO <fs_symbol>.

in your WHERE statement use <fs_symbol> = XXX


7 REPLIES 7
Read only

Former Member
0 Likes
1,898

MOVE 'pspnr' TO LV_STRING.

ASSIGN COMPONENT lv_string OF STRUCTURE <itab> TO <fs_symbol>.

in your WHERE statement use <fs_symbol> = XXX


Read only

0 Likes
1,897

Hi Carlos,

for this code (I have more rows with same PSPNR value in itab and I want to update them all):

ASSIGN COMPONENT 'PSPNR' OF STRUCTURE <fs_data> TO <fs_cell>.
          MODIFY <gt_fin_spp> FROM <fs_data>  TRANSPORTING ('BELNR') ('STATUS') WHERE <fs_cell> = <fs_cell>.

Still getting error:

In "LOOP ... WHERE ..." the row type of the table must be statically  
defined .  

Thanks Jiri


Read only

0 Likes
1,897

Hello Jiri,

maybe this can help you:

" <fs_tab> is a field symbol that is an alias to dynamic internal table

  LOOP AT <fs_tab> ASSIGNING <fs_line>.

    ASSIGN COMPONENT 'PSPNR' OF STRUCTURE <fs_line> TO <fs_field>.

    IF <fs_field> EQ 'VAL'.   " Field PSPNR has value VAL

      " Modify fields FIELD1 and FIELD2, for example

     

      ASSIGN COMPONENT 'FIELD1' OF STRUCTURE <fs_line> TO <fs_field>.

      <fs_field> = 1000.

     

      ASSIGN COMPONENT 'FIELD2' OF STRUCTURE <fs_line> TO <fs_field>.

      <fs_field> = 2000.

    ENDIF.

  ENDLOOP.

Hope it helps

Read only

0 Likes
1,897

Hi David,

this is one of the other possibilities, but what about performance?

I'm loopiing first dynamic itab with more than 50 000 lines:

lv_string = 'PSPNR'

LOOP AT <fs_tab> ASSIGNING <fs_line>.

AT END OF (lv_string)

*Do some CO accoutning for WBS elements

*so here I have to loop the same table:

      

LOOP AT <fs_tab> ASSIGNING <fs_line2>.

ASSIGN COMPONENT 'PSPNR' OF STRUCTURE <fs_line> TO <fs_field>.

ASSIGN COMPONENT 'PSPNR OF STRUCTURE <fs_line2> TO <fs_field2>.

IF <fs_field> = <fs_field2>.

ASSIGN COMPONENT 'STATUS' OF STRUCTURE <fs_line> TO <fs_field>.

<fs_field> = 'something'.

ENDIF.

ENDLOOP.


ENDAT.

ENDLOOP

Code above will work, but what about performance?

Thanks Jiri

Read only

0 Likes
1,897

Hi Jiri,

You can try like this,

  ASSIGN COMPONENT 'PSPNR' OF STRUCTURE <fs_data> TO <fs_cell>.

  MODIFY <gt_fin_spp> FROM <fs_data>  TRANSPORTING ('BELNR') ('STATUS')

  WHERE ( 'PSPNR = <fs_cell>').

if you need to specify two conditions in the where just specify like this without space before open and closing quotes within the brackets.


  ASSIGN COMPONENT 'PSPNR' OF STRUCTURE <fs_data> TO <fs_cell>.

ASSIGN COMPONENT 'STATUS' OF STRUCTURE <fs_data> TO <fs_status>.

  MODIFY <gt_fin_spp> FROM <fs_data>  TRANSPORTING ('BELNR') ('STATUS')

  WHERE ( 'PSPNR = <fs_cell> AND STATUS = `APPROVED`').

Regards,

Uma

Read only

Former Member
0 Likes
1,897

Hi

FIELD-SYMBOLS : <lt_pay_data>   TYPE STANDARD  TABLE,

               <fs_data>
TYPE any.


loop at  <lt_pay_data> ASSIGNING  <fs_data>.

<fs_data>-variable = '123'.

endloop.

With regards

Suneesh

Read only

0 Likes
1,897

Hi Suneesh,

your code will not work (syntax error), because:

<fs_data>-variable = '123'.

Table is dynamic, so you cannot directly access components of table line by column name. You have to use:

ASSIGN COMPONENT 'STATUS' OF STRUCTURE <fs_line> TO <fs_field>.

Another problem with your code is you will change all rows in the table.


Thanks Jiri