Summary
We need to add a user-defined field to a LO-Cockpit DataSource. This field can change with no other field of the standard extract structure changing at the same time. We want this change to be registered by the DataSource's delta queue.
In the following example we will see how to add a custom field for the sales rep specified in a sales document. We will assume that the sales rep is modeled as a line-item partner function, and we will therefore enhance the DataSource 2LIS_11_VDITM (Sales Document Item Data).
Author: Davide Cavallari
Company: Trilog S.p.A.
Created on: 07/09/2009
Author Bio
After studying piano and composition, taking a degree in physics and working for two years in a neuroscience laboratory, Davide got involved with IT and Web technologies. After joining Trilog S.p.A., he moved to the SAP Netweaver platform, focusing on the Information Integration layer (BI, KM, Search and Classification). His main focus now is on business requirements gathering and data modelling for the SAP BI platform.
Table of Contents
Introduction
1. Enhancing the LIS communication structure
2. Customizing the extract structure
3. Implementing the extraction logic for delta process
4. Implementing the extraction logic for the initialisation run
Related content
Introduction
The extraction process for the Logistics DataSources (those found in the LO Customising Cockpit, transaction code LBWE) is pretty complex. No wonder that, when you need to add a custom field to one of such DataSources, you have to pay especially carefull attention in order to avoid losing data from the DataSource's extraction or delta queues. On top of that, if your custom field is delta relevant as well, you may well end up with a broken delta process, where document changes are not always sent to the delta queue.
Here delta relevant means that when this field changes, this change should be felt by the V3 delta process, even though no additional field in the standard extract structure changes. It can be difficult to figure out exactly which steps are needed to ensure that the delta process works--although there is some good piece information around, such as this one, all in all I find the documentation available is pretty fragmented.
In the following I will concisely discuss an example which illustrates how to add a custom field for the sales rep specified in a sales document. We will assume that the sales rep is modeled as a line-item partner function, which in our example will have the value 'Z1'. We will therefore enhance the DataSource 2LIS_11_VDITM (Sales Document Item Data). I will not give details as to use the LO Customising Cockpit (LBWE) or implement an enhancement through the CMOD, though. If you need information about these tools, you should probably look for some specific documents on these topics as well. I do not even expalain the concept of before- and after-image records--should you need such information please refer to the related content section at the end of this document.
1. Enhancing the LIS communication structure
First of all, we need to add an extra field (YYKAM, in the example) in the LIS communication structure for sales documents' item data (MCVBAP).
We will insert an append structure (ZAMCVBAPUS, in the example) into the include structure MCVBAPUSR, and insert the new field YYKAM into this append structure:
2. Customizing the extract structure
The custom field YYKAM is now available in the LO Customizing Cockpit (transaction code LBWE), so we can add it to the extract structure MC11VA0ITM:
3. Implementing the extraction logic for delta process
In this step we will implement the code for extracting the value of the sales rep when a sales order's line item is created, modified or deleted (delta process). In the last step, instead, we will implement the extraction logic needed when performing the initialisation of a delta process.
The code for the delta extraction has to be written into the function EXIT_SAPLMCS1_002 (this function refers to the sales orders' line items) of the enhancement MCS10001 (SIS: Statistics update, sales documents). This can be done via the transaction CMOD:
Every time a line item is changed, deleted, or added, the EXIT function is called two times: one execution step processes the status of the data before the change (before-image), while the other the status after the change (after-image).
The field YY_KAM has to be filled with the value of the sales rep before or after the change, depending on whether the record is the before- or after-image. We can figure out which record is being processed through the field i_xmcvbap-supkz--its value being 1 for the before-image or 2 for the after-image record:
Being the sales rep a partner function, its before- and after-image values will be read from internal tables YVBPA and XVBPA respectively. These two internal tables are defined and filled in the program SAPMV45A, and to access to their content we need to reference them through the ABAP instruction ASSIGN:
When users modify the sales rep in an order line item, they can enter the original value again. When this happens, the before-image and the after-image values for the field YYKAM have to be the same. In this case, however, the table YVBPA does not contain the before-image value, so we will need to fetch it from the after-image table XVBPA:
Here is the complete example code:
4. Implementing the extraction logic for the initialisation run
The code in the EXIT above is only run when a sales document line is created, modified, or deleted (delta process). However, that code is not executed during the initialisation of the delta process, i.e. when all data from setup tables are loaded in BW.
In order for the extraction to take place also during the initialisation run, we need to implement the same extraction logic in the function EXIT_SAPLRSAP_001 (normally used to enhance non-LO transactional DataSources) of the enhancement RSAP0001 (Customer function calls in the service API).
Since we have already implemented the extraction logic for the delta process, we have to make sure that the code we put here is executed only when data are requested in full mode--i.e. when the field i_updmode has the value 'F' (transfer of all requested data), 'C' (initialization of the delta transfer), 'S' (simulation of initialzation of delta transfer), or 'I' (transfer of an opening balance for non-cumulative values, not relevant in our case), but not when its value is 'D' (transfer of the delta since the last request) and 'R' (repetition of the transfer of a data packet):
Related Content
- SAP Network Blog LOGISTIC COCKPIT - WHEN YOU NEED MORE - First option: enhance it !
- SAP Note 576886: Change to user-defined fields not extracted (SMP login required)
- SAP Note 216448: BW/SIS: Incorrect update / SD user exit (SMP login required)
- SAP Note 757361: Additional data records in BW when document changed (SMP login required)
How-to enhance LO-Cockpit DataSources with delta-relevant fields
We need to add a user-defined field to a LO-Cockpit DataSource. This field can change with no other field of the standard extract structure changing at the same time. We want this change to be registered by the DataSource's delta queue.
13 Comments
Unknown User (102r4ogah)
I found this article extremely helpful. It is very well written and gives detailed instructions. It's been a life saver.
Unknown User (102r4ogah)
wondering if there is a way to modify this code to look for more than one change, like sales rep1, sales rep2 etc.
Anonymous
Some people have told me there are some issues in the sample code provided in the article.
For example, instructions such as these:
ASSIGN ('(SAPMV45A)YVBPA[]') TO.
should instead be:
ASSIGN ('(SAPMV45A)YVBPA[]') TO <y1>.
I think the wiki's renderer is truncating such lines--probably, I should have quoted characters such as '<' or '>'.
Unfortunately I cannot edit this page (such an inconvenient feature of the SDN's wiki!). I hope the moderator will allow me to make the corrections needed ASAP.
Davide
Unknown User (102r4ogah)
changing the config settings for partner functions seems to effect what gets written to the delta queue, using this code, is that correct?
Unknown User (99f3um74)
Hi Davide,
This is an excellent article.This has been very informative and helpful for people like me who are in the learning phase.I sincerely appreciate the effort taken to come up with this article.I am hoping you will come up with some more stuff in the future.
I still have some questions regarding the article and who better to answer than the writer himself.
1)"In this step we will implement the code for extracting the value of the sales rep when a sales order's line item is created, modified or deleted (delta process)."
So does this mean,the code extracts the values of Sales Rep only when Sales Orders's line item is changed.Does it not bring the deltas when only the sale rep values has been changed?Does it have to be a change on line item level in order to capture the delta for sales Rep.
2)How was it deduced that the code was to written in the enhancement MCS10001?Writing under the EXIT_SAPLMCS1_002 makes as its for Line item.
3) How was it deduced that the Before & after images were read from the Internal tables YVBPA & XVBPA?
4) How was it deduced that the Program SAPMV45A was used to fill the internal programs?
5)What does the statement ASSIGN ('(SAPMV45A)XVBPA[]') TO.perfom in this case?
6) Is this the same method to enhance any Datasource with a Delta-enaled field or does that change by application(FI)?
Looking forward for your reply.
Anonymous
Hi vamsi Kondapaneni,
here are my answers:
1) No, if you implement the solution suggested in this article the delta process works even if only the sales rep is changed.
2) I got this information in the quoted weblog by Roberto Negro ( http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/1262 ).
Specifically, in the section "Using the LIS enhancement on available communication structures" Roberto lists the following 3 enhancements:
MCS10001 - SIS: Statistics update, sales documents
MCS50001 - SIS: Statistics update, deliveries
MCS60001 - SIS: Statistics update, invoices
Of these, only the first has a description that refers to sales documents, so I understood this was the enhancement I was looking for.
3) Again, I got this from Roberto's weblog, as well as SAP Note 216448: https://service.sap.com/sap/support/notes/216448
4) An ABAP developer helped me debug the code that is called when a sales document is saved.
5) Please notice that, as I wrote in a previous comment, the complete instruction is "ASSIGN ('(SAPMV45A)YVBPA[]') TO <y1>.". Basically, it assigns the memory area of the internal table YVBPA to the field symbol <y1>. You can then access the contents of YVBPA through the field symbol <y1>--i.e. <y1> is a pointer to YVBPA.
6) No, the method I described is specific to the DataSources you can find in the Logistic Cockpit (LO DataSources, transaction LBWE).
I hope you have a better picture now.
Cheers, Davide
Anonymous
Hi SJB,
you asked whether changing the configuration settings for partner functions affects what gets written to the delta queue.
I would say that the one thing that affects the extraction logic is the name of the partner function involved. In my example I use partner function 'Z1'. However, it is likely that your partner function has a different name, and so you should use that different name.
What other configuration settings are you thinking of?
Regards,
Davide
Unknown User (tqsk5st)
Hi Davide,
your article is very very helpful to me. thanks very much.
but I have met two problems. first I can't find the userexit for 2LIS_08TRFKZ. I check the function group 'XMCV' but get nothing.
second How can I debug into the userexit which you said. I use the T-code 'SBIW' and set update method as 'D'. but it is not work.
Looking forward for your reply
Regards,
Macro
Anonymous
Hi Macro,
in order to debug my example user exit, you should put a break-point in it. Then you should change or create a sales order. As soon as you save the sales document, the debugger should start.
As for the user exits for application Transportation (08), I suppose they are EXIT_SAPLMCST_001 (header level) and EXIT_SAPLMCST_002 (item level), from enhancement MCST0001. I looked for the enhancemnts which start with "MC" and, luckily, I found this one whose description is: "SIS: Statistics Update Transportation".
Hope this helps,
Davide
Unknown User (102dayvge)
Hi Davide,
Thank you for your suggestion, It works. but there are still some problems.
First, 'MCST0001', it is for transportation, but what I need is for 'shipment costs'. (tcode: VI01). Does 'shipment costs' not a part of 'LIS'?
Second, I get a request, it is so difficult. Users want to enhance the datasource '2LIS_11_VAITM' , adding the 'Delivery status' 'Billing status' and 'Posting Status'. when full loading, it is no problem, but delta loading, I can't get before-image status.
Do you have any idea about that?
Looking forward for your reply
Regards,
Macro
Unknown User (102dayvge)
Hi Davide,
I have solve my problem and would like share my idea.
I find out the function 'MCV_STATISTICS_ORDER ' which can create delta items when call it.
I put it in 'document_save' userexit of delivery document. Then when you create, delete,modify,post and reverse delivery document, sales order delta items will create.
for 2LIS_08TRFKZ, the function is 'VTRBW_SD_SCD_SAVE', but there are no userexit for me to enhance. so it do no helps to me except
I modify it.
Thanks again for your help.
Regards,
Macro.
Unknown User (zc719vt)
Hi,
Thanks for a good article.
This means that there exists two user exists:
1) EXIT_SAPLMCS1_002
2) EXIT_SAPLRSAP_001
Both are called by sales order transaction like VA01 and VA02 in above order (Delta Load).
For Initial Load of data to BW only the last user exit is called.
I prefer to have ABAP code to derive field values in only one place and as only the last user exit is called both for Delta and Initial Load it has to be here.
But for Delta Load the last user exit is only triggered if the first user exit found a difference between before and after image. I therefore inserted a field called ZZDELTA_TRIGGER to structure MCVBAPUSR.
This field is set to value 'X' in first user exit if the second user exit should be triggered.
This means that I only use the first user exit to trigger the second user exit for each sales order item. And for the first user exit I only look for After Image records: Should field ZZDELTA_TRIGGER be set to 'X' or not.
Example of ABAP Code to trigger second user exit:
EXIT_SAPLMCS1_002
* Check for Create or Change
case i_control-trtyp.
* Create Sales Document (T180-TRTYP)
when 'H'.
* Change Sales Document (T180-TRTYP)
when 'V'.
* Get xvbpa and yvbpa tables from SAPMV45A
perform get_tables.
case i_xmcvbap-supkz.
* Before Image
when '1'.
* After Image
when '2'.
perform determine_zzdelta_trigger_i using i_xmcvbap-posnr
i_xmcvbap-updkz.
if zw_delta_trigger_i = 'X'.
e_xmcvbapusr-zzdelta_trigger = 'X'. "<= this trigger EXIT_SAPLRSAP_001
endif.
endcase.
endcase.
form GET_TABLES.
* Get Before and After Image only one time
check: zw_header_control is initial.
zw_header_control = 'X'.
* Get Before Image YVBPA
assign ('(SAPMV45A)YVBPA[]') to <it_yvbpa>.
if sy-subrc = 0.
it_yvbpa[] = <it_yvbpa>.
endif.
* Get After Image XVBPA
assign ('(SAPMV45A)XVBPA[]') to <it_xvbpa>.
if sy-subrc = 0.
it_xvbpa[] = <it_xvbpa>.
endif.
endform. " GET_TABLES
form DETERMINE_ZZDELTA_TRIGGER_I using p_posnr
p_updkz.
clear: zw_delta_trigger_i.
* If p_updkz <> ' ' then user exit EXIT_SAPLRSAP_001 will be triggered
check: p_updkz is initial.
* See if change has been made to item and partner Z1 (Update or Insert)
loop at it_xvbpa
where posnr = p_posnr "Item Partner
and parvw = 'Z1' "Partner Z1 has been changed
and updkz <> ' '. "Update or Insert has been made (when xvbpa)
endloop.
if sy-subrc = 0.
zw_delta_trigger_i = 'X'.
endif.
check: zw_delta_trigger_i is initial.
* See if change has been made to item and partner Z1 (Delete)
loop at it_yvbpa
where posnr = p_posnr "Item Partner
and parvw = 'Z1' "Partner Z1 has been changed
and updkz <> ' '. "Delete has been made (when yvbpa)
endloop.
if sy-subrc = 0.
zw_delta_trigger_i = 'X'.
endif.
endform. " DETERMINE_ZZDELTA_TRIGGER_I
Changes for EXIT_SAPLRSAP_001 are not described here. It can be the same as listed in 4. Implementing the extraction logic for the initialisation run.
Regards,
Jens
Unknown User (100byrrzy)
Thanks for the article Davide. I am in the process of combining 2 ECC & BW systems which involves applying the enhancements from Material Movements extractor ECC system to another. Your step by step guide is a great help.
Thanks,
Pete
ABAP Training