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 insert rows into database table

Former Member
0 Likes
9,842

I hv created a table name "zsamptab1"

I hav created an internaltable named "t_itab"

I would like to insert few rows using internal table into table ..

Table name : "zsamptab1"

Fields I would like to insert : custno, custname, custadd

Internal table name = t_itab

Please let me know the statement to insert the above fields to database table...

4 REPLIES 4
Read only

Former Member
0 Likes
3,025

Hi pavan,

Which all fields are there in Z table and internal table?

Regards,

Atish

Read only

Former Member
0 Likes
3,025

HI,

Try this..



DATA: WA_ZSAMPTAB1 TYPE ZSAMPTAB1.
DATA: T_DATA TYPE STANDARD TABLE OF ZSAMPTAB1.

WA_ZSAMPTAB1-CUSTNO = 'TEST'.
WA_ZSAMPTAB1-CUSTNAME = 'TEST CUSTOMER'.
WA_ZSAMPTAB1-CUSTADD    = '44 TEST'.
APPEND WA_ZSAMPTAB1 TO T_DATA.

WA_ZSAMPTAB1-CUSTNO = 'TEST2'.
WA_ZSAMPTAB1-CUSTNAME = 'TEST CUSTOMER 2'.
WA_ZSAMPTAB1-CUSTADD    = '44 TEST 2'.
APPEND WA_ZSAMPTAB1 TO T_DATA.


* INsert the records.
INSERT ZSAMPTAB1 FROM TABLE T_DATA.

* Commit.
COMMIT WORK.

Thanks

Naren

Read only

Former Member
0 Likes
3,025

Hi,

Check these demo programs

RSDEMO_TABLE_CONTROL

DEMO_DYNPRO_TABLE_CONTROL_1

DEMO_DYNPRO_TABLE_CONTROL_2

RSDEMO_TABLE_CONTROL

RSDEMO02

<b>Reward points</b>

Regards

Read only

Former Member
0 Likes
3,025

Hi Pavan,

What I assumed is that your database table has three columns as custno, custname & custadd, with custno as Key field.

You want to update these fields from an internal table to your database table. Again only few rows of internal table you want to update in the database table depending on some condition or so.

For this, create one more internal table having type same as database table. Pass the values from the t_tab into this internal table depending on condition and finally update the database table.


TABLES: ZSAMPTAB1.

DATA: T_TAB2 TYPE TABLE OF ZSAMPTAB1,
      WA_TAB2 TYPE ZSAMPTAB1.

LOOP AT T_ITAB INTO WA_TAB1.
* On some condition, fill the second internal table
  IF WA_TAB1-CUSTNO EQ 'CONDITION'.
     MOVE WA_TAB1-CUSTNO TO WA_TAB2-CUSTNO.
     MOVE WA_TAB1-CUSTNAME TO WA_TAB2-CUSTNAME.
     MOVE WA_TAB1-CUSTADD TO WA_TAB2-CUSTADD.
     APPEND WA_TAB2 TO T_TAB2.
     CLEAR WA_TAB2.
  ENDIF.
  CLEAR WA_TAB1.
ENDLOOP.

* If the data is available in the second internal table, 
* insert it into database table
IF NOT T_TAB2 IS INITIAL.
  INSERT ZSAMPTAB1 FROM TABLE T_TAB2.
ENDIF.

Hope this helps.

PS If the answer solves the query, plz close the thread by rewarding each reply and marking it Solved.

Regards

Message was edited by:

Sapna Modi