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: 

Modify Database table

Former Member
0 Kudos

Hi All

I know my code will not work since Modify doesn,t support where,but my problem is like that..can u suggest how can i get the same result

I ahve to modify the TAble "JEST' there are 3 cases

i have a internal table T_OBJLIST having a single field

objid.

Actually JEST has 4 Fields OBJNR,STAT,INCTV,CHGNR

DATA : E_JEST type JEST .

Loop at T_OBJLIST.

clear e_jest.

MOVE : T_OBJLIST-OBJID TO E_JEST-OBJNR ,

C_E0001 TO E_JEST-STAT ,

SPACE TO E_JEST-INACT .

CASE1-MODIFY only INACT if it is X and OBJID in JEST & STATUS is E0001 do,nt change CCHGNR of Jest.

But below query changes CHGNR also.

MODIFY JEST FROM E_JEST WHERE OBJNR EQ T_OBJLIST-OBJID

AND STAT EQ E0001

AND INACT EQ C_X .

IF SY-SUBRC EQ 0.

COMMIT WORK.

ELSE.

ROLLBACK WORK..

ENDIF.

Case2-Modify only when Objid is Same but STSUS is not E0001

MODIFY JEST FROM E_JEST WHERE OBJNR eq T_OBJLIST-OBJID

AND STAT NE C_E0001 .

Case 3- Modify when OBJID not found in JEST

MOVE : C_001 TO E_JEST-CHGNR .

MODIFY JEST FROM E_JEST WHERE OBJNR NE E_JEST-OBJNR .

Thanks

SAurabh Tiwari

2 REPLIES 2

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

I believe the UPDATE statement supports a WHERE clause.

You really need to be careful when modifying a standard SAP table like JEST. Really you shouldn't be doing this.

Regards,

Rich HEilman

Former Member
0 Kudos

I do agree with Rich it is not advisable to update SAP standard tables but here is the logic if you have to ...

Loop at T_objlist.

select * into ijest from jest where objnr = objid.

if sy-subrc = 0.

if ijest-stat = 'E00001'.

ejest-objnr = ijest-objid.

ejest-stat = ijest-stat.

ejest-chgnr = ijest-chgnr.

check ijest-inctv = 'X'.

ejest-inact = space.

endif.

else.

ejest-objnr = ijest-objid.

ejest-stat = ijest-stat.

ejest-chgnr = C_001

ejest-inctv = space.

endif.

modify jest from ejest.

commit work.

endloop.