‎2012 Nov 02 7:07 PM
Hello Experts,
This might be a simple question but still, I couldn't figure out the solution.
Here's the requirement: I have a custom ztable which has fields changed by user name and changed on date along with the other fields. Now I am pulling the data from this database table using ALV grid report. This output of this ALV grid report has two editable fields. When I edit a existing editable field cell or add new data into my editable field cell and click on SAVE then my database table should get updated only for these edited fields changing the changed by user name to sy-uname and changed on date to sy-datum.
But, currently when I am doing a SAVE it updates all the records with sy-uname and sy-datum which is not supposed to do that. Can anybody suggest me an idea for doing this?
Below is my code.
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
RS_SELFIELD TYPE SLIS_SELFIELD.
CASE SY-UCOMM.
WHEN '&DATA_SAVE'.
LOOP AT ITAB INTO WA.
CLEAR: GV_NAM, GV_NAM1, GV_MESS, GV_MESS1.
SELECT SINGLE BNAME FROM USR21 INTO GV_NAM WHERE BNAME = WA-NAME.
SELECT SINGLE ZGR FROM ZTABLE INTO GV_NAM1 WHERE ZGR = WA-ZGR.
IF GV_NAM = WA-NAME AND GV_NAM1 = WA-ZGR.
UPDATE ZTABLE2 SET NAME = WA-NAME
NOTE = WA-NOTE
ZCHANGE_DATE = SY-DATUM
ZCHANGE_USER = SY-UNAME
WHERE TEXT = WA-TEXT.
ELSEIF GV_NAM NE WA-NAME.
CONCATENATE TEXT-067 WA-NAME TEXT-069 INTO GV_MESS SEPARATED BY SPACE.
MESSAGE GV_MESS TYPE GC_E.
ELSEIF GV_NAM1 NE WA-ZGR.
CONCATENATE TEXT-068 WA-ZGR TEXT-069 INTO GV_MESS1 SEPARATED BY SPACE.
MESSAGE GV_MESS1 TYPE GC_E.
ENDIF.
ENDLOOP.
ENDCASE.
ENDFORM. "USER_COMMAND
Thanks,
Nani
‎2012 Nov 02 7:31 PM
hello,
you have a condition
WHERE TEXT = WA-TEXT.
so update will update the DB where this condition satisfies.
If you need to update the ones edited you need to mark them in your internal table and the update the DB using those entries only.
best regards,
swanand
‎2012 Nov 02 7:39 PM
Hi Swanand,
Thanks for the reply. How do I need to mark my internal table fields when a change is done? This at run time. How can I achieve this?
Thanks,
Nani
‎2012 Nov 02 7:43 PM
Hello,
Is the program updating more records then it should? I blame it on your UPDATE statement.
Does the where condition give you distinct records? If the query results in more than one record, it will update all the records. I recommend passing all primary keys in the where condition, or builld you work area and then MODIFY the dbtable using MODIFY ..from wa.
Thanks,
VM.
‎2012 Nov 02 8:20 PM
Hi Venkat,
Thanks for the reply. The table only has one primary key. I am giving that in my WHERE condition.
Let me give you an example:
My ALV output records(When I first run this report I get all the fields from ZTABLE2):
Name(editable) Note(editable) field1 field2 ZCHANGE_DATE ZCHANGE_USER
Nani123 ABC AB CD 09/12/2011 NANI
Nani567 DEF EF GH 08/10/2011 JOHN
JK LM 09/10/2011 KAREN
Now I edit/add/remove some records and when I 'SAVE' it should update only that particular fields in my database: (Since I edited 1 and 3 records, only these records should update my DB table)
Name(editable) Note(editable) field1 field2 ZCHANGE_DATE ZCHANGE_USER
ABC AB CD 11/02/2012 NANI
Nani567 DEF EF GH 08/10/2011 JOHN
Nani843 JK LM 11/02/2012 NANI
Currently the way my program works in the following way(which is incorrect):
Name(editable) Note(editable) field1 field2 ZCHANGE_DATE ZCHANGE_USER
ABC AB CD 11/02/2012 NANI
Nani567 DEF EF GH 11/02/2012 NANI
Nani843 JK LM 11/02/2012 NANI
Can anybody suggest me good ideas on achieving this?
Thanks,
Nani
‎2012 Nov 03 8:48 AM
Hi Nani ,
Just keep the check box in ALV Report , then make the condition , if check box is ticked then update records .
Regards ,
Ram .
‎2012 Nov 04 4:13 AM
Hi Ram,
Thanks for the reply. I cannot put a checkbox in my ALV. It is against my requirement. Since I am coding this in my user command subroutine, if user modifies/adds the data to the existing record, then only do a update. But how do I need to capture the modified/add rows in my internal table at runtime. Please suggest me. My routine uses SLIS_SELFIELD and SY_UCOMM, will this be any help to me. Please advise me.
Thanks,
Nani
‎2023 Jan 30 10:51 AM
Hello Nani,
Did you got the solution for that I too have the same requirement not getting how to do! please suggest me the process.
THANKS,
‎2023 Jan 30 10:55 AM
Hello Experts,
I too have the same requirement can anybody suggest an idea!