Professional Documents
Culture Documents
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.
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:
01.*---------------------------------------------------------------------* 02.* INCLUDE ZXMCVU02 * 03.*----------------------------------------------------------------------* 04.* importing VALUE(I_XMCVBAK) LIKE MCVBAKB STRUCTURE MCVBAKB 05.*" VALUE(I_XMCVBUK) LIKE MCVBUKB STRUCTURE MCVBUKB 06.*" VALUE(I_XMCVBAP) LIKE MCVBAPB STRUCTURE MCVBAPB 07.*" VALUE(I_XMCVBUP) LIKE MCVBUPB STRUCTURE MCVBUPB 08.*" VALUE(I_XMCVBKD) LIKE MCVBKDB STRUCTURE MCVBKDB 09.*" VALUE(I_CONTROL) LIKE MCCONTROL STRUCTURE MCCONTROL 10.*" EXPORTING 11.*" VALUE(E_XMCVBAPUSR) LIKE MCVBAPUSR 12.*" STRUCTURE MCVBAPUSR 13.*----------------------------------------------------------------------* 14.* 15.* [...] 16.* 17.[...] 18. 19.DATA lv_old_kz VALUE '1'. 20.DATA lv_new_kz VALUE '2'. 21. 22.[...] 23. 24.CASE i_xmcvbap-supkz. 25. 26.** before-image record 27.WHEN lv_old_kz . 28. 29.[...] 30. 31.** after-image record 32.WHEN lv_new_kz. 33. 34.[...] 35. 36.ENDCASE. 37.[...]
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:
01.FIELD-SYMBOLS:TYPE table. 02.FIELD-SYMBOLS:TYPE table. 03.
04.DATA lv_old_kz VALUE '1'. 05.DATA lv_new_kz VALUE '2'. 06.DATA tb_pa LIKE vbpavb OCCURS 0 WITH HEADER LINE. 07.REFRESH tb_pa. CLEAR tb_pa. 08. 09.CASE i_xmcvbap-supkz. 10. 11.** before-image record 12.WHEN lv_old_kz . 13.""reference to before-image table 14.ASSIGN ('(SAPMV45A)YVBPA[]') TO Y1. 15.IF sy-subrc EQ 0. 16.tb_pa[] =. 17. 18.[...] 19. 20.ENDIF. 21. 22.**after-image record 23.WHEN lv_new_kz. 24.""reference to after-image table 25.ASSIGN ('(SAPMV45A)XVBPA[]') TO Y1. 26.IF sy-subrc EQ 0. 27.tb_pa[] =. 28.ENDIF. 29. 30.ENDCASE. 31.[...]
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:
01.** before-image record 02.WHEN lv_old_kz . 03.""reference to before-image table 04.ASSIGN ('(SAPMV45A)YVBPA[]') TO Y1. 05.IF sy-subrc EQ 0. 06.tb_pa[] =. 07. 08.READ TABLE tb_pa WITH KEY parvw = 'Z1'. 09."Z1 is the sales rep's partner function 10.IF sy-subrc ne 0. 11.""when user does not change the sales rep, Y- table does not 12.""contain the partner function Z1, so before-image state has to be 13.""read from X- table. 14.ASSIGN ('(SAPMV45A)XVBPA[]') TO Y1.
37.""when user does not change the sales rep, Y- table does not 38.""contain the partner function Z1, so before-image state has to be 39.""read from X- table. 40.ASSIGN ('(SAPMV45A)XVBPA[]') TO Y1. 41.IF sy-subrc EQ 0. 42.tb_pa[] =. 43.ENDIF. 44.ENDIF. 45. 46.ENDIF. 47. 48.** after-image record 49.WHEN lv_new_kz. 50.""reference to after-image table 51.ASSIGN ('(SAPMV45A)XVBPA[]') TO Y1. 52.IF sy-subrc EQ 0. 53.tb_pa[] =. 54.ENDIF. 55. 56.ENDCASE. 57. 58.** we take the line-item value unless not present 59.** in which case we take the header value 60.READ TABLE tb_pa WITH KEY posnr = i_xmcvbap-posnr 61.parvw = 'Z1'. 62.IF sy-subrc NE 0. 63.READ TABLE tb_pa WITH KEY posnr = '000000' 64.parvw = 'Z1'. 65.ENDIF. 66. 67.IF sy-subrc EQ 0. 68.MOVE tb_pa-lifnr TO e_xmcvbapusr-yykam. 69.ENDIF.
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):
01.[...] 02. 03.CASE i_datasource. 04. 05.[...] 06. 07.WHEN '2LIS_11_VAITM'. 08.DATA: s_mc11va0itm LIKE mc11va0itm. 09. 10.LOOP AT c_t_data INTO s_mc11va0itm. 11.wk_tabx = sy-tabix. 12. 13.*-- The following code must be executed during initialisation only 14.*-- (the extraction logic for delta update in EXIT_SAPLMCS6_002) 15.* 16.** we take the line-item value unless not present 17.** in which case we take the header value 18. 19.* only during initialisation 20.IF i_updmode EQ 'F' OR " F Transfer of all requested data 21.i_updmode EQ 'C' OR " C Initialization of the delta transfer 22.i_updmode EQ 'S' OR " S Simulation of Initialzation of Delta Transfer 23.i_updmode EQ 'I'. " I Transfer of an opening balance for non-cumulative values 24.* D Transfer of the Delta Since the Last Request 25.* R Repetition of the transfer of a data packet 26. 27.SELECT SINGLE lifnr INTO l_lifnr 28.FROM vbpa 29.WHERE vbeln = s_mc11va0itm-vbeln AND 30.posnr = s_mc11va0itm-posnr AND 31.parvw = 'Z1'. 32. 33.IF sy-subrc NE 0. 34.SELECT SINGLE lifnr INTO l_lifnr 35.FROM vbpa 36.WHERE vbeln = s_mc11va0itm-vbeln AND 37.posnr = '000000' AND 38.parvw = 'Z1'. 39.ENDIF. 40. 41.IF sy-subrc EQ 0. 42.MOVE l_lifnr TO s_mc11va0itm-yykam.
43.ENDIF. 44.ENDIF.