2012 Jun 29 3:23 PM
Hi Experts,
I’m new to SAP so I was wondering if any help could be given with the following:
I’ve been asked to alter our existing custom version of SAVE_DOCUMENT_PREPARE.At the moment it is pulling data at item level from the table mara.Now the business wish this to be altered so data is pulled at "header level”. How do I do this?
Any help appreciated!!
Regards,
Michael
2012 Jun 29 5:06 PM
Method save_document_prepare is called in include MV45AF0B_BELEG_SICHERN during the save of the sales order:
**************************************************************************************************************
call method l_sd_sales_exit->save_document_prepare
EXPORTING
ft180 = t180
CHANGING
f_subrc = da_subrc
fvbak = vbak
fxvbap = xvbap[]
fxkomv = xkomv[]
fxvbapf = xvbapf[]
fxvbfa = xvbfa[]
fxvbep = xvbep[]
fxvbkd = xvbkd[]
fxvbpa = xvbpa[]
fxvbuk = xvbuk[]
fxvbup = xvbup[]
fxfpla = xfpla[]
fxfplt = xfplt[]
fyvbak = yvbak
fyvbap = yvbap[]
fyvbapf = yvbapf[]
fyvbfa = yvbfa[]
*************************************************************************************************************
VBAK is a table that contains the sales order header information and is probably the table you are looking for.
VBAP contains the item data; the item of a sales order will contain a material which has information stored in table MARA. Therefore, I assume this is what you are referring to.
Hope this helps.
2012 Jun 29 5:10 PM
It would not be logical to obtain data from MARA at the "header" (VBAK) level of a sales order. The materials exist only in the item level (table VBAP). So, what could you possibly obtain from MARA, based upon the content of VBAK?
2012 Jul 02 9:21 AM
Hi guys,
thanks for the responses.Maybe if i put up the code i have now that might make things clearer.If anyone could take a look at the following and even point me in the right direction it would be appreciated.
The enclosed code is what i have as is,but the business want it changed to perform a check on partner function at header level.
*If IS_VBAK-VKORG NE '4200' and IS_VBAK-SPART NE '10'.
*---> Check that this enhancement is active in switch framework using ID = YSD008
CHECK is_vbak-vkorg NE ' '.
CHECK /chc/cl_enhswitch=>is_enh_active(
iv_enhancement_id = /chcie/cl_bc_constants=>enh_id_sd_generic
iv_salesorg = is_vbak-vkorg
iv_distrchan = is_vbak-vtweg ) EQ abap_true.
*---> Check that the Order Reason Code, Order Type, Order Category are relevant for this enhancement
*===> CHANGE REQUEST 64 to remove the check on Order Reason (augru) for this Named Patient check.
clear lv_patient_check.
IF is_vbak-ernam ne 'BATCH-IECR'.
IF is_vbak-auart = 'YOR' or is_vbak-auart = 'YSO'.
if ( is_vbak-vkorg = '4400' or is_vbak-vkorg = '4500' ).
if is_vbak-auart = 'YSO'.
lv_patient_check = 'X'.
else.
clear lv_kdgrp.
select single kdgrp into lv_kdgrp from KNVV where
kunnr = is_vbak-kunnr and
vkorg = is_vbak-vkorg and
vtweg = is_vbak-vtweg and
spart = is_vbak-spart.
if lv_kdgrp ne '01'.
lv_patient_check = 'X'.
endif.
endif.
else.
lv_patient_check = 'X'.
endif.
endif.
endif.
*---> Only process the Named Patient check when LV_PATIENT_CHECK is set.
if lv_patient_check = 'X'.
*---> The following line iemoved as requested by Audrey as not sure who requested change from YOR to YTR.
* CHECK is_vbak-auart = 'YTR'. "'YOR'. MSA2011
*---> Next loop thru all line item Order entries and if the Product Hier for the product starts
* with 'Y0012' then create a partner function Y2 (Named Patient) entry if one has NOT
* already been entered.
* If the Y2 partner function exists without the name and address details (or one has just
* been added), then add an entry to the Incompletion Log.
LOOP AT it_vbap INTO ls_vbap.
SELECT SINGLE prdha INTO lv_prdha FROM mara WHERE matnr = ls_vbap-matnr.
IF sy-subrc = 0 AND lv_prdha+0(5) = /chcie/cl_bc_constants=>c_article_hier. " Staring with 'Y0012'.
*---> Check if a Y2 Partner Function exists for this line item
CLEAR lv_partner_exists.
LOOP AT ct_vbpa INTO ls_vbpa WHERE posnr = ls_vbap-posnr AND
parvw = /chcie/cl_bc_constants=>c_named_patient_pf. "'Y2'.
lv_partner_exists = abap_true.
*---> Check that a name has been entered and if not add entry to Incompletion Log.
If ls_vbpa-name1 = ' ' or ls_vbpa-name1 = '<Enter Patient Name Here>'.
lv_partner_exists = 'P'. "Partially exists as name not added
endif.
EXIT.
ENDLOOP.
*---> Check if the Line Item is to be deleted or not
if ls_vbap-updkz ne 'D'.
if lv_partner_exists = ' '. "Partner Y2 does NOT exist
*---> Insert entry into table CT_VBPA for the missing Partner Type
CLEAR ls_vbpa.
DESCRIBE TABLE ct_vbpa LINES sy-tabix.
READ TABLE ct_vbpa INTO ls_vbpa INDEX sy-tabix.
ls_vbpa-posnr = ls_vbap-posnr.
ls_vbpa-parvw = /chcie/cl_bc_constants=>c_named_patient_pf.
ls_vbpa-kunnr = /chcie/cl_bc_constants=>c_named_patient_cust. " '4000000001'.
ls_vbpa-updkz = 'I'.
ls_vbpa-adrda = 'D'.
SELECT SINGLE adrnr INTO ls_vbpa-adrnr FROM kna1
WHERE kunnr = ls_vbpa-kunnr.
CLEAR ls_vbpa-name1.
APPEND ls_vbpa TO ct_vbpa.
endif.
check lv_partner_exists ne 'X'. "Missing or Partially added
*---> Next add an entry to the Incompletion Log for this Line Item / Missing Partner 'Y2' / Missing Name
CLEAR ls_vbuv.
ls_vbuv-mandt = sy-mandt.
ls_vbuv-vbeln = is_vbak-vbeln.
ls_vbuv-posnr = ls_vbap-posnr.
ls_vbuv-parvw = /chcie/cl_bc_constants=>c_named_patient_pf. " 'Y2'.
ls_vbuv-tbnam = 'VBPA'.
ls_vbuv-fdnam = 'KUNNR'.
ls_vbuv-fehgr = '07'.
ls_vbuv-statg = '04'.
ls_vbuv-fcode = 'KPAR_SUB'.
ls_vbuv-sortf = '0001'.
COLLECT ls_vbuv INTO ct_vbuv.
* else.
**---> As the Line Item is to be deleted, delete the entry from VBPA and VBUF if one exists.
* LOOP AT ct_vbuv into ls_vbuv where parvw = /chcie/cl_bc_constants=>c_named_patient_pf and
* posnr = ls_vbap-posnr.
* DELETE ct_vbuv.
* READ TABLE ct_vbpa into ls_vbpa WITH KEY
* posnr = ls_vbuv-posnr
* parvw = ls_vbuv-parvw
* kunnr = /chcie/cl_bc_constants=>c_named_patient_cust.
* IF sy-subrc = 0.
* DELETE ct_vbpa index sy-tabix.
* ENDIF.
* ENDLOOP.
endif.
endif.
ENDLOOP.
ENDIF.