Application Development 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: 

Updating database table from internal table

Former Member
0 Kudos

I am updating the database table from internal table for this is have used the following syntax

Update kna1 from table itab.

And it is giving error message as the work are itab is not long enough.

Please help me.

11 REPLIES 11

Former Member
0 Kudos

Hi

modifying datbase table useing internal table

advises before updating this datbase table plz lock that table to avoid incosistency

write the logic for modifying

  • Modify the database table as per new dunning procedure

MODIFY fkkvkp FROM TABLE lt_fkkvkp .

and finally unlock the table

example

*To lock table for further operations

constants: lc_tabname TYPE rstable-tabname VALUE 'FKKVKP' . "FKKVKP

CALL FUNCTION 'ENQUEUE_E_TABLE'

EXPORTING

tabname = lc_tabname

EXCEPTIONS

foreign_lock = 1

system_failure = 2

OTHERS = 3.

IF sy-subrc EQ 0.

  • To fetch all the contract accounts for customers of the segment

  • Households/SME.

PERFORM fetch_contract_accounts using lc_tabname .

ENDIF. " IF sy-subrc EQ 0.

*wrote the logic

  • Modify the database table as per new dunning procedure from internal table

MODIFY fkkvkp FROM TABLE lt_fkkvkp .

*unlock the tbale

CALL FUNCTION 'DEQUEUE_E_TABLE'

EXPORTING

TABNAME = uc_tabname .

Reward if usefull

Former Member
0 Kudos

Hi,

Dont use UPDATE Statement. You can use MODIFY when you are trying to update the standard sap tables.

Cheers,

Bujji

Former Member
0 Kudos

hi,

1. give it inside a loop.

2. check whether itab has exact fields..

loop at itab.

update dbtable from itab.

endloop.

With Rgds,

S.Barani

Former Member
0 Kudos

Hi Babji,

If the data already exists in the db table then u go for update n u need to give the primary key wher u want it to update the kna1 table..

ellse u need to use INsert...

what error r u getting exactly...

Regards,

Kaveri

0 Kudos

I HAVE DECLARED INTERNAL TABLE IN THE FOLLOWING WAY

types: begin of ty_itab,

kunnr type kunnr,

land1 type LAND1_GP,

end of ty_itab.

data: it_itab type standard table of ty_itab initial size 0.

data: wa_itab type ty_itab.

0 Kudos

loop at it_itab into wa_itab.

update kna1 set land1 = wa_itab-land1 where kunnr = wa_itab-kunnr.

endloop.

0 Kudos

Hi Babji,

Fine...if the data already exists n u r trying to midify then..

use

Modify kna1 from itab .

else use..

kna1-kunnr = itab-kunnr.

kna1-land =.....

Insert kna1 .

Regards,

Kaveri

Former Member
0 Kudos

Hi,

There is a mismatch in the structure of internal table . Make sure the structure of internal table is correct.

Regards,

Vani.

former_member386202
Active Contributor
0 Kudos

Hi,

Refer this code

&----


*& Form SUB_READ_UPDATE_BSEG

&----


  • text

----


FORM sub_read_update_bseg.

IF NOT it_final[] IS INITIAL.

LOOP AT it_final INTO wa_final.

UPDATE bseg SET zuonr = wa_final-ccnum

WHERE bukrs EQ wa_final-bukrs

AND belnr EQ wa_final-vbeln

AND rfzei EQ wa_final-rfzei

AND saknr NE ' '.

ENDLOOP.

*--Message data updated successfully

MESSAGE i888 WITH text-002.

LEAVE LIST-PROCESSING.

ELSE.

*--Message No data found

MESSAGE i888 WITH text-003.

LEAVE LIST-PROCESSING.

ENDIF.

ENDFORM. " SUB_READ_UPDATE_BSEG

Regards,

PRashant

Former Member
0 Kudos

Hi babji,

It is not used Update Statement. You can use MODIFY Statement.

<b>Modify <d.table> from table <itab> where <condition>.</b>

Regards,

s.suresh.

reward if useful...

Message was edited by:

suresh selvarajan

Former Member
0 Kudos

Hi babji,

It is not used <b>Update</b> Statement. You can use <b>Modify</b> Statement.

<b>Modify <d.table> from table <itab> where <condition>.</b>

Regards,

s.suresh.

reward if useful...