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

Updating database table from a dynamic internal table

Former Member
0 Likes
1,428

Hi all

I have a dynamic internal table which is populated with data accoring to select-option.

Now i have to make updations to the data fetched into this dynamic table and then update the database table with these changes. To do this, i need access to the work area of the dynamic internal table, but i am not able to either access it or create it.

Kindly suggest how to go about it.

PS : The task is being performed using classes and methods a nd not function modules.

Thanks & Regards

Ravish Garg

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
732

Hi,

you can create a field-symbols..try this..

Continuation with my previous example..


* Work area for the dynamic internal table.
  CREATE DATA WA LIKE LINE OF <gt_table>.
 
  WRITE: / 'Dynamic internal table created'.

  field-symbols : <FS>.
 
* Process the internal table
  LOOP AT <gt_table> INTO WA.
    
* get the column value
     ASSIGN COMPONENT 'MATNR' OF STRUCTURE WA TO <FS>.
  
     CHECK sy-subrc = 0.

* Modify the value...
     <FS>   = 'test'.

* Modify the internal table.
      MODIFY <gt_table> FROM WA.

  ENDLOOP.

<b>Please make sure to reward points for helpful answers..</b>Thanks

naren

4 REPLIES 4
Read only

Former Member
0 Likes
732

Hi,

Check this example of how create work area for a dynamic internal table.


PARAMETERS: p_input TYPE i OBLIGATORY.

START-OF-SELECTION.

  DATA: v_fieldname  TYPE char30.
  DATA: v_char       TYPE numc4.
  DATA: it_fldcat    TYPE lvc_t_fcat.
  DATA: wa_it_fldcat LIKE LINE OF it_fldcat.
  DATA: gp_table     TYPE REF TO data.

  FIELD-SYMBOLS: <gt_table> TYPE table.

  DO p_input TIMES.

    v_fieldname = 'COL'.
    v_char      = sy-index.

    CONCATENATE v_fieldname v_char INTO v_fieldname.
    CONDENSE v_fieldname.

    CLEAR wa_it_fldcat.
    wa_it_fldcat-fieldname = v_fieldname.
    wa_it_fldcat-datatype = 'CHAR'.
    wa_it_fldcat-outputlen = 5.
    wa_it_fldcat-intlen = 5.
    APPEND wa_it_fldcat TO it_fldcat .

  ENDDO.

* Internal table creation..
  CALL METHOD cl_alv_table_create=>create_dynamic_table
  EXPORTING it_fieldcatalog = it_fldcat
  IMPORTING ep_table = gp_table.

  ASSIGN gp_table->* TO <gt_table>.

  CHECK sy-subrc = 0.

  DATA: WA TYPE REF TO DATA.

* Work area for the dynamic internal table.
  CREATE DATA WA LIKE LINE OF <gt_table>.

  WRITE: / 'Dynamic internal table created'.

* Process the internal table
  LOOP AT <gt_table> INTO WA.
    
***********Do all your stuffs there..    

  ENDLOOP.

Thanks

Naren

Read only

0 Likes
732

Hi Naren

thanks for the solution. i have another query.

when my data is passed from the internal table to work area, i need access to a particular column of the work area(the column is chosen dynamically) and update the same with a new value.

Kindly help.

Thanks & Regards

Ravish Garg

Read only

Former Member
0 Likes
732

Ravi,

Please find the document for How to use Dynamic Tables ?

/people/rich.heilman2/blog/2005/07/27/dynamic-internal-tables-and-structures--abap

All the very best to you.

- Mohan Vamsi Krishna

Read only

Former Member
0 Likes
733

Hi,

you can create a field-symbols..try this..

Continuation with my previous example..


* Work area for the dynamic internal table.
  CREATE DATA WA LIKE LINE OF <gt_table>.
 
  WRITE: / 'Dynamic internal table created'.

  field-symbols : <FS>.
 
* Process the internal table
  LOOP AT <gt_table> INTO WA.
    
* get the column value
     ASSIGN COMPONENT 'MATNR' OF STRUCTURE WA TO <FS>.
  
     CHECK sy-subrc = 0.

* Modify the value...
     <FS>   = 'test'.

* Modify the internal table.
      MODIFY <gt_table> FROM WA.

  ENDLOOP.

<b>Please make sure to reward points for helpful answers..</b>Thanks

naren