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

How to update database table from dynamic internal table

Former Member
0 Likes
1,279

Hi all,

i want to update database table from dynamic internal table.

Below is my piece of code.

<b>* Modify the internal table.

MODIFY <dyn_table> FROM <dyn_wa>.

  • Modify database table.

update ??? from table <dyn_table>.

modify ??? .</b>

ENDLOOP.

Since my table is dynamic so i m confuse what shud i write in place of ????.

p_table is a parameter name for fetching the table name.

Thanks in advance.

Regards,

Swati Garg

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
665

HI,

see this code.

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

I_STRUCTURE_NAME = DB_TABLE

CHANGING

CT_FIELDCAT = FCAT1[].

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

EXPORTING

IT_FIELDCATALOG = FCAT1[]

IMPORTING

EP_TABLE = DYN_ITAB.

ASSIGN DYN_ITAB->* TO <DISP_TABLE>.

CREATE DATA WA LIKE LINE OF <DISP_TABLE>.

ASSIGN WA->* TO <WA>.

MODIFY <dyn_table> FROM <dyn_wa>.

<b>

update (DB_TABLE) from table <dyn_table>.</b>

rgds,

bharat.

4 REPLIES 4
Read only

Former Member
0 Likes
665

Hi,

check out the following link it might help you in resolving your problem

http://en.wikipedia.org/wiki/ABAP

*********please reward points if the information is helpful to you************

Read only

Former Member
0 Likes
665

refer this demo code -

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.

Read only

former_member582701
Contributor
0 Likes
665

MODIFY (p_table) FROM TABLE <dyn_table>

Reward helpfull answers

Read only

Former Member
0 Likes
666

HI,

see this code.

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

I_STRUCTURE_NAME = DB_TABLE

CHANGING

CT_FIELDCAT = FCAT1[].

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

EXPORTING

IT_FIELDCATALOG = FCAT1[]

IMPORTING

EP_TABLE = DYN_ITAB.

ASSIGN DYN_ITAB->* TO <DISP_TABLE>.

CREATE DATA WA LIKE LINE OF <DISP_TABLE>.

ASSIGN WA->* TO <WA>.

MODIFY <dyn_table> FROM <dyn_wa>.

<b>

update (DB_TABLE) from table <dyn_table>.</b>

rgds,

bharat.