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: 

pls help to check why I couldn't update database

Former Member
0 Kudos
230

Hi, pls help to check why I couldn't update

Data itab like table of zz with header line.

clear ZZ.

Select * from ZZ into corresponding fields of table ITAB.

Loop at itab.

If itab-Name is initial.

select single name1 into itab-Name

from KNA1 where kunnr EQ ITAB-SOLD_TO.

elseif itab-MATL_DESC is initial.

select single maktx into itab-matl_desc

from makt where matnr EQ ITAB-MATERIAL and spras EQ SY-LANGU.

elseif itab-VTEXT is initial.

select single vtext into itab-VTEXT FROM TSPAT where SPART eq

ITAB-DIVISION and Spras EQ SY-LANGU.

endif.

modify zz from itab.

Endloop.

thanks a lot!

elly

1 ACCEPTED SOLUTION

Former Member
0 Kudos
171

Elly,

Are you sure the work values have changed from the original values, just check that once in debug mode.

Finally, USE COMMIT WORK.

regards,

Ravi

Note : Please mark the helpful answers

13 REPLIES 13

Former Member
0 Kudos
172

Elly,

Are you sure the work values have changed from the original values, just check that once in debug mode.

Finally, USE COMMIT WORK.

regards,

Ravi

Note : Please mark the helpful answers

Former Member
0 Kudos
171

HI,

Just write <b>MODIFY dbtab FROM TABLE itab</b>,

COMMIT WORK.

thanks

Sudheer

0 Kudos
171

Hi, I have checked in debug mode, the work area data has changed, even I use MODIFY dbtab FROM TABLE itab,

COMMIT WORK.

it doesn't work.

thanks a lot!

elly

0 Kudos
171

HI Elly,

1. Primary key

2. make sure the record u are checking

is of correct primary key.

(MODIFY works automatically based upon

the primary key field combination,

if the combination is found in dbtab (as compared to workarea),

then automatically UPDATE is done,

other wise INSERT is done

)

3. U have used many IFs.

For testing purpose,

HARDCODE some value (and do not use any if)

and put it in itab.

Then use MODIFY ZZ from itab.

COMMIT Work.

4. Then check, it should work.

(there is some minor mistake only)

regards,

amit m.

Former Member
0 Kudos
171

Hi Elly,

what is ZZ here. can't figure out from few of your statements like

clear ZZ.

regards,

Kinshuk

Former Member
0 Kudos
171

where is your update statement?

your not insert or append any record into ITAB. then how did you update into zz table?

Thanks & regards

Vasu

Former Member
0 Kudos
171

Hi,

Message was edited by: Manoj Gupta

Former Member
0 Kudos
171

Hi Elly

You are getting records in the internal table work area (data is changin in the work area) i.e. itab but until and unless you dont append/insert those records into internal table body how will records be transferred to internal table body??

so in this case table itab i.e. itab[] is empty and thats why table zz is not getting updated from the table itab.

just put append/insert itab statment in your code.

Thanks

Former Member
0 Kudos
171

Hi Elly

You are getting records in the internal table work area (data is changin in the work area) i.e. itab but until and unless you dont append/insert those records into internal table body how will records be transferred to internal table body??

so in this case table itab i.e. itab[] is empty and thats why table zz is not getting updated from the table itab.

just put append/insert itab statment in your code.

Thanks

Former Member
0 Kudos
171

Hi!

You have to append or insert into your internal table else how it will work...

Regards,

Sangeeta.

Former Member
0 Kudos
171

Hi,

Refer this code:

IF GT_ZCO001[] IS NOT INITIAL.
* Modify the custom table ZCO001 with the entries in ZCO001.
      MODIFY  ZCO001 FROM TABLE GT_ZCO001.
      IF SY-SUBRC NE 0.
* If the DB modification encounters an error, throw appropriate message.
        ROLLBACK WORK.
        MESSAGE S002(ZPS01).    "Unable to insert values into the table
      ELSE.
        COMMIT WORK.
        MESSAGE S003(ZPS01).    "Records Updated.
      ENDIF.
    ELSE.
      MESSAGE S012(ZPS01).
    ENDIF.

Regards,

Gayathri

former_member181962
Active Contributor
0 Kudos
171

Hi Elly,

I doubt your approach to update the descriptions.

Actually the modify statement is working, but it is updating the table with the same old values again and again.

Refer the following code:

Loop at itab.

If itab-Name is initial.

select single name1 into itab-Name

from KNA1 where kunnr EQ ITAB-SOLD_TO.

endif.

if itab-MATL_DESC is initial.

select single maktx into itab-matl_desc

from makt where matnr EQ ITAB-MATERIAL and spras EQ SY-LANGU.

endif.

if itab-VTEXT is initial.

select single vtext into itab-VTEXT FROM TSPAT where SPART eq

ITAB-DIVISION and Spras EQ SY-LANGU.

endif.

modify zz from itab.

Endloop.

Your previous code updates only one of either name1 or vtext or maktx.

This code will update any text that is empty.

Hope it helps you.

Regards,

Ravi

Former Member
0 Kudos
171

Hi,

The following code will modify the ZZ table :-

Data: itab like table of zz,

wa_itab like line of zz.

refresh itab.

clear wa_itab.

Select *

from ZZ

into table ITAB.

check sy- subrc = 0.

Loop at itab into wa_itab.

If itab-Name is initial.

select single name1

into wa_itab-Name

from KNA1

where kunnr EQ ITAB-SOLD_TO.

elseif itab-MATL_DESC is initial.

select single maktx

into itab-matl_desc

from makt

where matnr EQ ITAB-MATERIAL

and spras EQ SY-LANGU.

elseif itab-VTEXT is initial.

select single vtext

into itab-VTEXT

FROM TSPAT

where SPART eq ITAB-DIVISION

and Spras EQ SY-LANGU.

endif.

modify itab from wa_itab.

Endloop.

<b>Modify zz from table itab.</b>

Regards,

Sameena