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

appending dynamic table

Former Member
0 Likes
571

Hi,

I am working on appending a dynamic internal table. In the table s_brd5 there are three records 101, 102 and 103. But <fs_table> gets three records all with 103. Rest of the components are all coming correctly. It seems the last record is overwriting them all. Any thoughtsabout corrections? I am not getting errors but the appending is not happening correctly.

my code goes ike this...

field-symbols: <gi_data> TYPE STANDARD TABLE,
               <fs_table> TYPE STANDARD TABLE.
               <fs_wa> type any,
               <fs_var> type any.

 loop at s_brd5.
     loop at <gi_data> assigning <fs_wa>.
       assign component 4 of structure <fs_wa> to <fs_var>.
*       if sy-subrc = 0.
         <fs_var> = s_brd5-low.
*       endif.
       assign component 12 of structure <fs_wa> to <fs_var>.
       <fs_var>+2(8) = s_brd5-low.
*       append <fs_wa> to <fs_table>.
       endloop.
       append <fs_wa> to <fs_table>.
endloop.
modify <tablename> from table <fs_table>.

thanks in advance,

VG

Please use code tags

Edited by: Rob Burbank on Dec 6, 2010 4:20 PM

4 REPLIES 4
Read only

Former Member
0 Likes
505

Actually I did something like this...

go_struct ?= cl_abap_typedescr=>describe_by_name( v_tabname ) .
  TRY.
      CALL METHOD cl_abap_tabledescr=>create
        EXPORTING
          p_line_type  = go_struct
          p_table_kind = 'S'
        RECEIVING
          p_result     = go_table.
    CATCH cx_sy_table_creation .
*MESSAGE e000 WITH text-004.
  ENDTRY.
* creating internal table of table type just created
  CREATE DATA gi_data TYPE HANDLE go_table.
* Assigning the internal table to field symbol
  ASSIGN gi_data->* TO <gi_data>.
  ASSIGN gi_data->* TO <fs_table>.

  concatenate 'objid' 'EQ' p_brd5 into i_query-line separated by space.
  append i_query.

** get the data into the internal table from db table
      SELECT * INTO TABLE <gi_data> FROM (v_tabname) where (i_query).
**** get the  ids from HRP1000
   *loop at s_brd5.*    
 loop at <gi_data> assigning <fs_wa>.
       assign component 4 of structure <fs_wa> to <fs_var>.
*       if sy-subrc = 0.
         <fs_var> = s_brd5-low.
*       endif.
*       unassign: <fs_wa>, <fs_var>.
       assign component 12 of structure <fs_wa> to <fs_var>.
       <fs_var>+2(8) = s_brd5-low.
*       append <fs_wa> to <fs_table>.
       endloop.
       append <fs_table>.
   endloop.

My problem is for every record in s_brd5, replace the id and create a new record in <fs_table>. for three records 101, 102 and 103 I need to have just three records in the table <fs_table>. It is not happening that way. Thanks in advance,

I have used the code tags now. Thanks Rob..

VG

Read only

alex_cook
Active Participant
0 Likes
505

Howdy,

You don't need to do the append <fs_table> unless you want to add an extra row, and you don't need a modify statement either.

If you just want to modify existing rows then you just assign the field symbol and make the change:


       assign component 4 of structure <fs_wa> to <fs_var>.
       if sy-subrc = 0.
         <fs_var> = s_brd5-low.
       endif.

Always check that the assignment was successful.

Cheers

Alex

Read only

Former Member
0 Likes
505

thanks for the response.

My ultimate goal is to update the database table. I am aware that I can do it here one at a time. But i puts a lot of stress on the data base and since I am using nested loops, might cause a performance issue. Hence I am trying to collect all the records in <fs_table> for all the values from 's_brd' and then use modify statement that updates all the records at one go.. I have to use the dynamic process here because I shall not know the table until run time.

Hence if there is a way to append the records into <fs_table> through the process, it shall be helpful. Any thoughts?

Thanks,

VG

Read only

Former Member
0 Likes
505

Hi folks,

I tried the same code and worked fine with out any performance issues. I was abit apprensive because of nested loops and modifying the database table. It worked fine for me without any issues.

Thanks,

VG