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

Modifying a database table

Former Member
0 Likes
2,060

Hi Friends,

I need to modify my database table from the internal table, pls tell me how to do it.

Regards,

Parvez

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,039

Use below like statement

describe table int_table lines v_line.

if not v_line is initial.

comitt work.

modify dbtable from table int_table.

endif.

Thanks

Seshu

24 REPLIES 24
Read only

Former Member
0 Likes
2,039

MODIFY dbtab FROM itab.

Check the standard SAP help for MODIFY statement for examples and details.

Use the F1 power

Read only

0 Likes
2,039

Sorry I am not getting the stadard SAP help here.

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
2,039

Hi,

MODIFY dbtab FROM TABLE itab.

Check this link for mor einformation.

http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/modify.htm

Read only

Former Member
0 Likes
2,040

Use below like statement

describe table int_table lines v_line.

if not v_line is initial.

comitt work.

modify dbtable from table int_table.

endif.

Thanks

Seshu

Read only

0 Likes
2,039

Hi

Here is my code, can you please correct it.

LOOP AT lt_invmov INTO lw_invmov.

IF lw_invmov-check = 'X'.

move 'CL' to lw_invmov-status.

ENDIF.

append lw_invmov to lt_invmov.

ENDLOOP.

MODIFY zinv_mov FROM lt_invmov.

regards,

Line

Read only

0 Likes
2,039

LOOP AT lt_invmov INTO lw_invmov.

IF lw_invmov-check = 'X'.

move 'CL' to lw_invmov-status.

ENDIF.

append lw_invmov to lt_invmov.

ENDLOOP.

MODIFY zinv_mov FROM <b>table</b> lt_invmov.

Read only

0 Likes
2,039

Hi Seshu,

I checked it but even though it is displaying the same error 'The work area "LT_INVMOV" is not long enough'

LOOP AT lt_invmov INTO lw_invmov.

IF lw_invmov-check = 'X'.

move 'CL' to lw_invmov-status.

ENDIF.

modify lt_invmov from lw_invmov index sy-tabix.

ENDLOOP.

MODIFY zinv_mov FROM table lt_invmov.

Read only

0 Likes
2,039

Hi,

I checked it but even though it is displaying the same error 'The work area "LT_INVMOV" is not long enough'

LOOP AT lt_invmov INTO lw_invmov.

IF lw_invmov-check = 'X'.

move 'CL' to lw_invmov-status.

ENDIF.

modify lt_invmov from lw_invmov index sy-tabix.

ENDLOOP.

MODIFY zinv_mov FROM table lt_invmov.

Thanx in advance,

Read only

0 Likes
2,039

YOUR INT TABLE SHOULD BE THE SAME STRUCTURE AS YOUR DATABASE TABLE.

DATA : lt_invmov LIKE zinv_mov OCCURS 0 WITH HEADER LINE. OR SOMETHING LIKE THAT....

REGARDS

SHIBA DUTTA

Read only

0 Likes
2,039

Sorry for delay..

decalre internal table or work area as like table

data : wa_mara like mara.

data : i_mara like <b>mara</b> occurs 0.

here i_mara is same like mara.

now use modify command.

Read only

0 Likes
2,039

Hi Shiba,

Thanx for your reply.

I have data in the table control and i need to update only selected record from the table control selection to the database table.

How to do it, Can you please tell me

Regards,

Read only

0 Likes
2,039
Read only

0 Likes
2,039

just declare a table like your database table now from your table cntrl table pass the value to the int table like database table...now use modify statement with the newly declare table(like database table)...

i think in your pai you are writting the code like this..

loop at itab where mark = 'X'."here itab tab cntrl int tab and mark is selection field

itabnew-f1 = itab-f1.

itabnew-f2 = itab-f2.

append itabnew.

endloop.

now use

modify itab from table itabnew.

if you want to only update the existing record then better to use update with where condition.

regards

shiba dutta

Read only

0 Likes
2,039

Hi Shiba,

I will try and let you know.

Regards

Read only

0 Likes
2,039

Hi Shiba,

But it is modifying only one record at a time can you tell me how to modify batch of records once.

Regards

Read only

0 Likes
2,039

Pls find my code

LOOP AT lt_invmov INTO lw_invmov WHERE check = 'X'.

itab_reg-lifnr = lw_invmov-lifnr.

itab_reg-xblnr = lw_invmov-xblnr.

itab_reg-bukrs = lw_invmov-inv_date.

itab_reg-inv_date = lw_invmov-inv_date.

itab_reg-invr_date = lw_invmov-invr_date.

itab_reg-zterm = lw_invmov-zterm.

itab_reg-dmbtr = lw_invmov-dmbtr.

itab_reg-waers = lw_invmov-waers.

itab_reg-kursf = lw_invmov-kursf.

MOVE 'CL' TO itab_reg-status.

APPEND itab_reg.

ENDLOOP.

MODIFY zinv_reg FROM itab_reg.

Read only

0 Likes
2,039

put the break point on modify statement and check the table how much data it contain? and let us know if it contain more than one data?

regards

shiba dutta

Read only

0 Likes
2,039

Yes it contains more than one record but it is only modifying the first record.

Read only

0 Likes
2,039

just check you have repeating the value or not for the secondary index of that table if it is so then it will not update the database from the repeating value and you will get the sy-subrc as 4.

regards

shiba dutta

Read only

0 Likes
2,039

Hi,

Try giving

MODIFY zinv_reg FROM <b>table</b> itab_reg.

Read only

Former Member
0 Likes
2,039

Check with below program ,here i am getting the data from file and updating the data into custom table using modify statement.

REPORT ZLWMI151_UPLOAD no standard page heading

line-size 100 line-count 60.

*tables : zbatch_cross_ref.

data : begin of t_text occurs 0,

werks(4) type c,

cmatnr(15) type c,

srlno(12) type n,

matnr(7) type n,

charg(10) type n,

end of t_text.

data: begin of t_zbatch occurs 0,

werks like zbatch_cross_ref-werks,

cmatnr like zbatch_cross_ref-cmatnr,

srlno like zbatch_cross_ref-srlno,

matnr like zbatch_cross_ref-matnr,

charg like zbatch_cross_ref-charg,

end of t_zbatch.

data : g_repid like sy-repid,

g_line like sy-index,

g_line1 like sy-index,

$v_start_col type i value '1',

$v_start_row type i value '2',

$v_end_col type i value '256',

$v_end_row type i value '65536',

gd_currentrow type i.

data: itab like alsmex_tabline occurs 0 with header line.

data : t_final like zbatch_cross_ref occurs 0 with header line.

selection-screen : begin of block blk with frame title text.

parameters : p_file like rlgrap-filename obligatory.

selection-screen : end of block blk.

initialization.

g_repid = sy-repid.

at selection-screen on value-request for p_file.

CALL FUNCTION 'F4_FILENAME'

EXPORTING

PROGRAM_NAME = g_repid

IMPORTING

FILE_NAME = p_file.

start-of-selection.

  • Uploading the data into Internal Table

perform upload_data.

perform modify_table.

top-of-page.

CALL FUNCTION 'Z_HEADER'

  • EXPORTING

  • FLEX_TEXT1 =

  • FLEX_TEXT2 =

  • FLEX_TEXT3 =

.

&----


*& Form upload_data

&----


  • text

----


FORM upload_data.

CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'

EXPORTING

FILENAME = p_file

I_BEGIN_COL = $v_start_col

I_BEGIN_ROW = $v_start_row

I_END_COL = $v_end_col

I_END_ROW = $v_end_row

TABLES

INTERN = itab

EXCEPTIONS

INCONSISTENT_PARAMETERS = 1

UPLOAD_OLE = 2

OTHERS = 3.

IF SY-SUBRC <> 0.

write:/10 'File '.

ENDIF.

if sy-subrc eq 0.

read table itab index 1.

gd_currentrow = itab-row.

loop at itab.

if itab-row ne gd_currentrow.

append t_text.

clear t_text.

gd_currentrow = itab-row.

endif.

case itab-col.

when '0001'.

t_text-werks = itab-value.

when '0002'.

t_text-cmatnr = itab-value.

when '0003'.

t_text-srlno = itab-value.

when '0004'.

t_text-matnr = itab-value.

when '0005'.

t_text-charg = itab-value.

endcase.

endloop.

endif.

append t_text.

ENDFORM. " upload_data

&----


*& Form modify_table

&----


  • Modify the table ZBATCH_CROSS_REF

----


FORM modify_table.

loop at t_text.

t_final-werks = t_text-werks.

t_final-cmatnr = t_text-cmatnr.

t_final-srlno = t_text-srlno.

t_final-matnr = t_text-matnr.

t_final-charg = t_text-charg.

t_final-erdat = sy-datum.

t_final-erzet = sy-uzeit.

t_final-ernam = sy-uname.

t_final-rstat = 'U'.

append t_final.

clear t_final.

endloop.

delete t_final where werks = ''.

describe table t_final lines g_line.

sort t_final by werks cmatnr srlno.

  • Deleting the Duplicate Records

perform select_data.

describe table t_final lines g_line1.

modify zbatch_cross_ref from table t_final.

if sy-subrc ne 0.

write:/ 'Updation failed'.

else.

Skip 1.

Write:/12 'Updation has been Completed Sucessfully'.

skip 1.

Write:/12 'Records in file ',42 g_line .

write:/12 'Updated records in Table',42 g_line1.

endif.

delete from zbatch_cross_ref where werks = ''.

ENDFORM. " modify_table

&----


*& Form select_data

&----


  • Deleting the duplicate records

----


FORM select_data.

select werks

cmatnr

srlno from zbatch_cross_ref

into table t_zbatch for all entries in t_final

where werks = t_final-werks

and cmatnr = t_final-cmatnr

and srlno = t_final-srlno.

sort t_zbatch by werks cmatnr srlno.

loop at t_zbatch.

read table t_final with key werks = t_zbatch-werks

cmatnr = t_zbatch-cmatnr

srlno = t_zbatch-srlno.

if sy-subrc eq 0.

delete table t_final .

endif.

clear: t_zbatch,

t_final.

endloop.

ENDFORM. " select_data

Thanks

Seshu

Read only

Former Member
0 Likes
2,039

see the modify query ...

SELECT INVOICE_NO GATE_ENTRY_NUM
INTO CORRESPONDING FIELDS OF TABLE I_ZFBPS_INV_LINK
FROM ZFBPS_INV_LINK
FOR ALL ENTRIES IN GATEIN_ITAB
WHERE GATE_ENTRY_NUM = GATEIN_ITAB-GATE_ENTRY_NUM.
 
 
LOOP AT I_ZFBPS_INV_LINK.
read table  GATEIN_ITAB  with key  GATE_ENTRY_NUM =  I_ZFBPS_INV_LINK-GATE_ENTRY_NUM
****just    have  if  logic    it will work   
IF  GATEIN_ITAB-INVOICE_NO = I_ZFBPS_INV_LINK-INVOICE_NO   .
MODIFY GATEIN_ITAB INDEX SY-TABIX.
ENDIF .
ENDLOOP.

reward points if it is usefull ..

Girish