‎2010 Mar 04 1:00 PM
Hi Experts,
I added a field to table LIPS. I wrote a report to change that field (its a Flag so it is 'X' or ' '). To track changes to that field I want to use tables cdhdr and cdpos. I can't turn the "log data changes" in SE11 on as this would be tracking all changes in LIPS. I just need to track my added flag.
I wrote this coding:
FORM change_doc USING i_vbeln TYPE vbeln
i_posnr TYPE posnr
i_flag_new TYPE flag
i_flag_old TYPE flag.
DATA: lv_objectclass TYPE cdobjectcl,
lv_objectid TYPE cdobjectv,
lv_changenr TYPE cdchangenr,
ls_workarea_lips_new TYPE lips,
ls_workarea_lips_old TYPE lips.
SELECT SINGLE * FROM lips INTO ls_workarea_lips_old
WHERE vbeln = i_vbeln AND posnr = i_posnr.
MOVE-CORRESPONDING ls_workarea_lips_old TO ls_workarea_lips_new.
ls_workarea_lips_new-yytourengeplant = i_flag_new.
ls_workarea_lips_old-yytourengeplant = i_flag_old.
lv_objectclass = 'LIEFERUNG'. lv_objectid = i_vbeln.
CALL FUNCTION 'CHANGEDOCUMENT_OPEN'
EXPORTING
objectclass = lv_objectclass
objectid = lv_objectid
planned_or_real_changes = 'R'.
IF sy-subrc = 0.
CALL FUNCTION 'CHANGEDOCUMENT_SINGLE_CASE'
EXPORTING
change_indicator = 'I'
tablename = 'LIPS'
workarea_new = ls_workarea_lips_new
workarea_old = ls_workarea_lips_old.
IF sy-subrc = 0.
CALL FUNCTION 'CHANGEDOCUMENT_CLOSE'
EXPORTING
date_of_change = sy-datum
objectclass = lv_objectclass
objectid = lv_objectid
tcode = 'YAENDERN_VERPLANT_KZ'
time_of_change = sy-uzeit
username = sy-uname
object_change_indicator = 'U'
planned_or_real_changes = 'R'
IMPORTING
changenumber = lv_changenr.
ENDIF.
ENDIF.
ENDFORM.It does create a good line in CDHDR. Problem is in CDPOS:
OBJECTCLASS and -ID, CHANGENR, TABNAME, TABKEY are all good and what I want. But FNAME which should be the changed field in table Lips is set to "KEY" which is not from me... my fieldname is "YYTOURENGEPLANT".
And second: my VALUE_NEW or VALUE_OLD... one should be "X". What is my fault? Thanks in advance! Manfred
‎2010 Mar 04 2:08 PM
Hi you two!
First of all: thanks for your Reply!
I tried but it did not quite work somehow...
In this case the CHANGEDOCUMENT_CLOSE delivers a sy-subrc =2 : no_position_inserted.
I am playing a bit already but I dont know the reason. Right now I am debugging the function to get a clue what I did wrong.
Regards
Manfred
‎2010 Mar 04 1:19 PM
You declared an "insertion" into database
change_indicator = 'I'So only "key" of the record is stored - use "U" for update.
Look at [Writing the fields in the program|http://help.sap.com/saphelp_nw70/helpdata/en/2a/fa01c3493111d182b70000e829fbfe/frameset.htm] in [Change documents |http://help.sap.com/saphelp_nw70/helpdata/en/2a/fa015b493111d182b70000e829fbfe/frameset.htm]
Regards,
Raymond
‎2010 Mar 04 1:19 PM
Hello
1. For fieldname
CALL FUNCTION 'CHANGEDOCUMENT_SINGLE_CASE'
EXPORTING
change_indicator = 'U' " <- set U instead of I
tablename = 'LIPS'
workarea_new = ls_workarea_lips_new
workarea_old = ls_workarea_lips_old.
2. Check values i_flag_new and i_flag_old. They must be different.
I hope it will help you.
‎2010 Mar 04 2:08 PM
Hi you two!
First of all: thanks for your Reply!
I tried but it did not quite work somehow...
In this case the CHANGEDOCUMENT_CLOSE delivers a sy-subrc =2 : no_position_inserted.
I am playing a bit already but I dont know the reason. Right now I am debugging the function to get a clue what I did wrong.
Regards
Manfred
‎2010 Mar 04 2:12 PM
In "U"pdate mode, there MUST be a difference between workarea_new and workarea_old.
Some questions
- Why don't you call LIEFERUNG_WRITE_DOCUMENT directly, in fact i don't know if you can use LIFIERUNG object without LIKP record.
- Have you activated the change-document flag of the data-element of the appended field?
Regards,
Raymond
‎2010 Mar 04 2:25 PM
Hi Raymond!
I ensured that both are different with an assert.
"Have you activated the change-document flag of the data-element of the appended field?" How can I do that?
"LIEFERUNG_WRITE_DOCUMENT" I have not found yet. Does it hit my attached fields as well? Playing with it right now.
Thanks so far!
Manfred
‎2010 Mar 04 2:29 PM
Call SE11 on LIPS, double-click on the data element of your appended ZZ-field, in the Definition tab of the data-element, in the Attributes box, there is a flag that must be checked for the fields to be recorded in CDPOS. (Your question suggests it is not checked.) (Read [Set change document flag|http://help.sap.com/SAPHELP_nwmobile71/helpdata/EN/2a/fa019c493111d182b70000e829fbfe/frameset.htm])
LIEFERUNG_WRITE_DOCUMENT is the actual FM executed in update-task when SAP programs update delivery. (Check transaction SCDO, Generation Info, you will get the FM and the name of some includes to use in your program - Read [Integrating the functionality into the program|http://help.sap.com/SAPHELP_nwmobile71/helpdata/EN/2a/fa01b6493111d182b70000e829fbfe/frameset.htm])
Regards,
Raymond
‎2010 Mar 04 3:14 PM
Hi again,
Hm I feel a bit stupid right now but it still wont work. I did the change in se11 and now all changes to my flag should be tracked.
Now I have this coding:
LOOP AT lt_lips INTO ls_lips.
IF ls_lips-yytourengeplant NE p_sollkz.
SELECT * FROM lips INTO CORRESPONDING FIELDS OF TABLE lt_lipsy WHERE vbeln = ls_lips-vbeln AND posnr = ls_lips-posnr.
UPDATE lips SET yytourengeplant = p_sollkz WHERE vbeln = ls_lips-vbeln AND posnr = ls_lips-posnr.
COMMIT WORK.
SELECT * FROM lips INTO CORRESPONDING FIELDS OF TABLE lt_lipsx WHERE vbeln = ls_lips-vbeln AND posnr = ls_lips-posnr.
ENDIF.
DATA: lv_objectid TYPE cdobjectv.
lv_objectid = ls_lips-vbeln.
CALL FUNCTION 'LIEFERUNG_WRITE_DOCUMENT'
EXPORTING
objectid = lv_objectid
tcode = 'YAENDERN_VERPLANT_KZ'
utime = sy-uzeit
udate = sy-datum
username = sy-uname
* PLANNED_CHANGE_NUMBER = ' '
* OBJECT_CHANGE_INDICATOR = 'U'
planned_or_real_changes = 'R'
* NO_CHANGE_POINTERS = ' '
* UPD_ICDTXT_LIEFERUNG = ' '
* N_LIKP =
* O_LIKP =
upd_likp = 'X'
upd_lips = 'X'
* UPD_VBPA = ' '
n_vbuk = ls_n_vbuk
o_vbuk = ls_o_vbuk
* UPD_VBUK = ' '
TABLES
* ICDTXT_LIEFERUNG =
xlips = lt_lipsx
ylips = lt_lipsy.
* XVBPA =
* YVBPA =
* .
Ok it can be optimized (all positions of one delivery at once) but right now I am just testing only one position so I will care later about that.
Within that Function the call of CHANGEDOCUMENT_CLOSE results in a sy-subrc = 4 (NO_POSITION_INSERTED = 4). Btw, the update of LIPS works... just the change-tables do not.
I hope my failure is not too stupid.. your post is great already!
Manfred
‎2010 Mar 04 3:39 PM
Dont read a second time LIPS from database, there will be buffer and delayed database commit problem.
Build the new table from the old one and update the changed flag in your program.
Also the FM can be called in update task, before the COMMIT WORK.
for each delivery
- read LIKP
- read LIPS in internal table
- build before table (KZ = U)
- update itab LIPS with your flag
- build after table (KZ =U)
- call FM in update task
- update database
- Commit work
Regards,
Raymond
‎2010 Mar 05 10:16 AM
Hi Raymond!
Sorry that I did not answer yesterday... it did not work and I had not the brains left to find out after 10 hours of working. But today I got it fixed. All your hints where right. I just had one additional mistake while calling the function. To help others reading this post hopefully I want document the problem by posting the working function call:
DATA ls_n_vbuk TYPE vbuk.
DATA ls_o_vbuk TYPE vbuk.
DATA lt_lipsx TYPE ulips OCCURS 0.
DATA lt_lipsy TYPE ulips OCCURS 0.
DATA: lv_objectid TYPE cdobjectv.
CALL FUNCTION 'LIEFERUNG_WRITE_DOCUMENT' IN UPDATE TASK
EXPORTING
objectid = lv_objectid
tcode = 'YAENDERN_VERPLANT_KZ'
utime = sy-uzeit
udate = sy-datum
username = sy-uname
object_change_indicator = 'U'
planned_or_real_changes = 'R'
upd_likp = ' '
upd_lips = 'U' "<----- NOT just 'X'
n_vbuk = ls_n_vbuk
o_vbuk = ls_o_vbuk
TABLES
xlips = lt_lipsx
ylips = lt_lipsy.
My final problem was that I set upd_lips to 'X' assuming this is a flagfield.. but it is not!
So thanks again Raymond and thanks all others helping me out!
‎2016 Jan 23 7:23 AM