* const, include
include com_product_const001.
include com_product_const003.
include com_product_const009.
include com_product_const011.
include com_settype_attribute_const03.
tables: comm_iproduct, "#EC NEEDED
comm_product.
constants:
gc_program type programm value 'COM_PRODUCT_DELETE_SINGLE'.
data: gv_product_guid type comt_product_guid,
gv_prty type comt_product_type,
gv_syslog(70) type c,
lv_mobile_active type comt_boolean,
lv_delete type comt_boolean value 'X'.
data: lt_settypes type comt_frgtype_tab_ext,
lt_status_guid type comt_prd_status_guid_tab.
data: begin of lt_products occurs 0,
product_id like comm_product-product_id,
product_guid like comm_product-product_guid,
end of lt_products.
select-options: s_prid for comm_product-product_id.
*parameters: p_prid type comt_product_id obligatory,
parameters: p_prty type comt_product_type obligatory default '01',
p_logs type comt_logsys obligatory,
p_objf type comt_product_object_family,
p_send as checkbox modif id 001 default on,
p_usage as checkbox modif id 001 default off,
p_test as checkbox default 'X'.
if lv_mobile_active is initial.
loop at screen.
check screen-group1 = '001'. "disable field p_send, p_usage
screen-active = '0'.
modify screen.
endloop.
endif.
start-of-selection.
* perform check_authority.
** Write syslog entry
* concatenate 'Rep. ' sy-repid ': ' p_prid(30) '/' p_prty '/' p_logs
* into gv_syslog. "#EC NOTEXT
* call 'C_WRITE_SYSLOG_ENTRY'
* id 'TYP' field ' '
* id 'KEY' field 'C00'
* id 'DATA' field gv_syslog .
** inactive product are not supported here
* select * from comm_iproduct
* where product_id = p_prid
* and product_type = p_prty
* and object_family = p_objf
* and logsys = p_logs.
* endselect.
* if sy-subrc = 0.
* write: / text-001, text-005.
* exit.
* endif.
* read products according to the selection criteria
select * from comm_product
into corresponding fields of table lt_products
where product_id in s_prid
and product_type = p_prty
and object_family = p_objf
and logsys = p_logs.
if sy-subrc ne 0.
write: / text-010.
exit.
endif.
loop at lt_products.
* read product and enqueue
perform product_enqueue
using lt_products-product_id
p_prty
p_logs
p_objf
changing gv_product_guid
gv_prty.
check not gv_product_guid is initial.
if p_usage = on.
perform check_usage
using gv_product_guid
changing lv_delete.
endif.
check lv_delete = on.
check p_test = space.
* first delete the component of the IBase
perform delete_ibasecomponent
using gv_product_guid.
perform delete_extensions
using gv_product_guid
lt_settypes.
perform delete_settypes
using gv_product_guid
lt_settypes
changing lt_status_guid.
perform delete_interlinkages
using gv_product_guid.
perform delete_pme_data "multivalue attributes
using gv_product_guid.
perform delete_decoupled_data "long text, longmatnr,
using gv_product_guid. "ibase prodvar,...
perform delete_status
using lt_status_guid.
perform delete_favorites
using gv_product_guid.
perform delete_clear_case
using gv_product_guid.
if p_send = 'X'.
perform send_deletion_to_mw
using gv_product_guid.
endif.
delete from comm_product where product_guid = gv_product_guid.
delete from comm_producth where product_guid = gv_product_guid.
delete from comm_product_idx where product_guid = gv_product_guid.
delete from comm_prwb_user_2 client specified
where client = sy-mandt and last_object = gv_product_guid.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
*&---------------------------------------------------------------------*
*& Form product
*&---------------------------------------------------------------------*
form product_enqueue
using iv_prid type comt_product_id
iv_prty type comt_product_type
iv_logs type comt_logsys
iv_objf type comt_product_object_family
changing ev_pguid type comt_product_guid
ev_prty type comt_product_type.
if sy-subrc <0> 2.
write: / text-001, space, iv_prid.
write: text-007. "Product enqueued
exit.
else.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
exit.
endif.
exit.
endif.
ev_prty = ls_product-product_type.
** special authotirty check (with considering the assigned
** categories)
* call function 'COM_PRODUCT_CT_AUTHORITY_CHECK'
* exporting
* iv_auth_act = '06'
* iv_product_guid = ev_pguid
* exceptions
* no_authority = 1
* wrong_call = 2
* internal_error = 3
* others = 4.
* if sy-subrc <> 0.
* message id sy-msgid type sy-msgty number sy-msgno
* with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
* endif.
endform. " product
*&---------------------------------------------------------------------*
*& Form delete_extensions
*&---------------------------------------------------------------------*
form delete_extensions
using iv_product_guid type comt_product_guid
et_settype type comt_frgtype_tab_ext.
data: lv_db_tab type ddobjname,
lv_subrc_pr_guid like sy-subrc,
table_name_ref type ref to data,
lt_extension type comt_frgtype_tab_ext,
ls_extension type comm_frgtype_ext.
field-symbols: <table_name> type any,
<field_name> type any.
check not iv_product_guid is initial.
* delete extensions e.g. COMM_PRFREEATTR, CRMM_PR_TAX, COMM_PR_UNIT,
* COMM_PR_SHTEXT,COMM_PR_GTIN, comm_prprdcatr,..
perform load_extensions
using iv_product_guid
changing lt_extension
et_settype.
loop at lt_extension into ls_extension.
lv_db_tab = ls_extension-frgtype_tab.
check not lv_db_tab is initial. "CRM_CAT_SAT & CRM_CAT_PUR
* does table exist ?
call function 'DDIF_NAMETAB_GET'
exporting
tabname = lv_db_tab
exceptions
not_found = 1
others = 2.
check sy-subrc = 0.
* Due to any reason (I don't know why) sometimes we have product_guid
* and sometimes we have frg_guid as name of the key field.
create data table_name_ref type (lv_db_tab).
assign table_name_ref->* to <table_name>.
assign component 'PRODUCT_GUID' of structure <table_name>
to <field_name>.
lv_subrc_pr_guid = sy-subrc.
if lv_subrc_pr_guid = 0.
delete from (lv_db_tab)
where product_guid = iv_product_guid.
else.
delete from (lv_db_tab)
where frg_guid = iv_product_guid.
endif.
* delete history of extension table
concatenate ls_extension-frgtype_tab 'H' into lv_db_tab.
create data table_name_ref type (lv_db_tab).
assign table_name_ref->* to <table_name>.
assign component 'LOGSYS' of structure <table_name>
to <field_name>.
check sy-subrc = 0.
if lv_subrc_pr_guid = 0.
delete from (lv_db_tab)
where product_guid = iv_product_guid.
else.
delete from (lv_db_tab)
where frg_guid = iv_product_guid.
endif.
endloop. " end of loop for all extensions
endform. " delete_extensions
*&---------------------------------------------------------------------*
*& Form delete_settypes
*&---------------------------------------------------------------------*
form delete_settypes
using iv_product_guid type comt_product_guid
it_settypes type comt_frgtype_tab_ext
changing et_status_guid type comt_prd_status_guid_tab.
data: ls_reldesc type coms_pr_org_rel,
lt_reldesc type comt_pr_org_rel_tab,
lt_reltab type ref to data,
ls_settype type comt_settype_ext,
ls_table type tabname,
ls_status_guid type crmt_object_guid.
field-symbols:
<fs_reltab> type any table,
<fs_relrow> type any,
<fs_settype> type comt_frgtype_guid,
<fs_setguid> type comt_frg_guid,
<fs_statguid> type crmt_object_guid.
* memorise product status guide
ls_status_guid = iv_product_guid.
append ls_status_guid to et_status_guid.
* for all links...
loop at <fs_reltab> assigning <fs_relrow>.
assign component 'FRAGMENT_TYPE' of structure <fs_relrow>
to <fs_settype>.
assign component 'FRAGMENT_GUID' of structure <fs_relrow>
to <fs_setguid>.
assign component 'STATUS_OBJECT' of structure <fs_relrow>
to <fs_statguid>.
read table it_settypes with key frgtype_guid = <fs_settype>
into ls_settype.
check sy-subrc = 0.
* settype table
delete from (ls_settype-frgtype_tab)
where frg_guid = <fs_setguid>.
* history table
concatenate ls_settype-frgtype_tab 'H' into ls_table.
delete from (ls_table)
where frg_guid = <fs_setguid>.
* memorise settype status guide
if not <fs_statguid> is initial.
ls_status_guid = <fs_statguid>.
append ls_status_guid to et_status_guid.
endif.
endloop. "of links
* relation table (e.g. comm_pr_frg_rel)
delete from (ls_reldesc-link_table)
where product_guid = iv_product_guid.
* history table
concatenate ls_reldesc-link_table 'H' into ls_table.
delete from (ls_table) where product_guid = iv_product_guid.
endloop. " of relation types
endform. " delete_settypes
*&---------------------------------------------------------------------*
*& Form delete_interlinkages
*&---------------------------------------------------------------------*
form delete_interlinkages
using iv_product_guid type comt_product_guid.
constants: cv_db_name(8) type c value 'COMM_IL_',
cv_suffix_h(2) type c value '_H'.
data: lt_ilinks type comt_il_data_tab,
lt_reltype type comc_il_reltype_tab with header line,
lv_ddictype type dd02v-tabclass,
lv_dbname type comt_structure.
* CHECK p_objf IS INITIAL.
* first we have to read all ILs where the productguid is sourceguid
refresh lt_ilinks.
check not lt_ilinks[] is initial.
delete adjacent duplicates from lt_ilinks comparing reltype.
* read ilinkage customizing
select * from comc_il_reltype into table lt_reltype
for all entries in lt_ilinks where reltyp = lt_ilinks-reltype.
* delete interlinkages
loop at lt_reltype.
if lt_reltype-streltyp ne space.
concatenate cv_db_name lt_reltype-streltyp into lv_dbname.
else.
concatenate cv_db_name lt_reltype-reltyp into lv_dbname.
endif.
delete from (lv_dbname) where sourceguid = iv_product_guid.
endloop.
endform. "delete_interlinkages
*&---------------------------------------------------------------------*
*& Form delete_pme_data
*&---------------------------------------------------------------------*
form delete_pme_data
using iv_product_guid type comt_product_guid.
* delete multivalue attributes from PME
data: lt_pmemap like standard table of comm_pme_prd_map,
ls_pmemap like comm_pme_prd_map.
select * into table lt_pmemap
from comm_pme_prd_map
where crm_object_guid = iv_product_guid.
check sy-subrc = 0.
loop at lt_pmemap into ls_pmemap.
call function 'CRM_SCE_DB_KB_DELETE'
exporting
iv_kbid = ls_pmemap-kbid.
endloop.
delete comm_pme_prd_map from table lt_pmemap.
endform. "delete_pme_data
*&---------------------------------------------------------------------*
*& Form send_deletion_to_mw
*&---------------------------------------------------------------------*
form send_deletion_to_mw
using iv_product_guid type comt_product_guid.
data: cv_function_module like rs38l-name
value 'CRM_PROD_SEND_DELETION_MESSAGE'. "#EC NOTEXT
data: lt_product_guid type comt_product_s_tab with header line.
call function cv_function_module
exporting
it_product_guid = lt_product_guid[]
iv_test_only = space
exceptions
internal_error = 1
others = 2.
if sy-subrc <0> 0.
ev_mobile_active = on.
endif.
endform. " check_mobile_download
*&---------------------------------------------------------------------
*& Form check_authority
*&---------------------------------------------------------------------
form check_authority.
tables: t000, comc_pr_tool_reg. "#EC NEEDED
* check productiv system - report must not be executed
select single * from t000 client specified "#EC CI_CLIENT
where mandt = sy-mandt.
if t000-cccategory = 'P'.
message e807(com_product) .
leave.
leave to transaction ' '.
endif.
if sy-subrc ne 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
* MESSAGE e808(com_product).
leave.
leave to transaction ' '.
endif.
* Additional step: registration
select single * from comc_pr_tool_reg
where program_name = gc_program
and user_name = sy-uname
and exec_date = sy-datum.
if sy-subrc ne 0.
message e809(com_product).
endif.
endform. " check_authority
*&---------------------------------------------------------------------
*& Form delete_decoupled_data
*&---------------------------------------------------------------------
form delete_decoupled_data
using iv_product_guid type comt_product_guid.
include com_product_const018.
* Deleting decoupled and customer requested data (long_text, longmatnr,
* upload registry, ibase product variants coming from R/3,
* archive verify registry). Documents like PDF,XLS,DOC,JPG stored in
* Content Management will not be deleted
* load BADI implementations
class: cl_exithandler definition load.
data: exit_obj type ref to if_ex_com_product_delete.
*&---------------------------------------------------------------------*
*& Form load_extensions
*&---------------------------------------------------------------------*
form load_extensions
using iv_product_guid type comt_product_guid
changing et_extension type comt_frgtype_tab_ext
et_settype type comt_frgtype_tab_ext.
data: lt_prd_cat type comt_prod_cat_rel_tab,
ls_prd_cat type comt_prod_cat_rel,
lt_cat_frg type comt_prcat_frag_rel_tab,
ls_cat_frg type comt_prcat_frag_rel,
lt_settype_guid type comt_frgtypeguid_tab,
ls_settype_guid type comt_frgtype_guid,
lt_settype type comt_frgtype_tab_ext.
refresh et_extension.
* read categories assigned to product
call function 'COM_PROD_CAT_REL_READ_WITH_PR'
exporting
iv_product_guid = iv_product_guid
importing
et_set = lt_prd_cat.
* only settypes
et_settype[] = lt_settype[].
delete et_settype[] where
( prod_comp_type = gc_prod_comp_type-extension or
prod_comp_type = gc_prod_comp_type-simple_extension ).
* only extensions
delete lt_settype[] where
( prod_comp_type ne gc_prod_comp_type-extension and
prod_comp_type ne gc_prod_comp_type-simple_extension ).
et_extension[] = lt_settype[].
endif.
endloop. " end of product categories
endform. " load_extensions
*&---------------------------------------------------------------------*
*& Form delete_status
*&---------------------------------------------------------------------*
form delete_status
using it_status_guid type comt_prd_status_guid_tab.
data:
lt_status like crm_jsto_pre occurs 0,
ls_status type crm_jsto_pre,
ls_status_guid type crmt_object_guid.
loop at it_status_guid into ls_status_guid.
ls_status-objnr = ls_status_guid.
append ls_status to lt_status.
endloop.
call function 'CRM_STATUS_DELETE_MULTI'
tables
objnr_table = lt_status.
endform. " delete_status
*&---------------------------------------------------------------------
*& Form delete_favorites
*&---------------------------------------------------------------------
form delete_favorites
using iv_product_guid type comt_product_guid.
call function 'COM_PRODUCT_DELETE_FAVORITES'
exporting
iv_object_guid = iv_product_guid.
endform. " delete_favorites
*&---------------------------------------------------------------------
*& Form delete_clear_case
*&---------------------------------------------------------------------
form delete_clear_case
using iv_product_guid type comt_product_guid.
data: ls_customizing type comc_product,
lv_clear_case_guid type comt_clear_case_guid.
select single clear_case_guid from comm_clear_targ "#EC *
into lv_clear_case_guid
where object_guid = iv_product_guid "active
and object_class = 'PROD'.
* normaly two entries for active and inaktive product version
delete from comm_clear_targ
where clear_case_guid = lv_clear_case_guid
and object_class = 'PROD'.
delete from comm_clear_stack
where guid = lv_clear_case_guid
and application = 'PROD'.
endform. "delete_clear_case
*&---------------------------------------------------------------------
*& Form check_usages
*&---------------------------------------------------------------------
form check_usage
using iv_product_guid type comt_product_guid
changing ev_delete type comt_boolean.
include sbal_constants.
data: cv_function_module like rs38l-name
value 'COM_PRODUCT_USAGE_CHECK'. "#EC NOTEXT
data: ls_product type comt_product,
lt_product type comt_product_tab.
data: ls_logheader type bal_s_log, "Kopfdaten des Protokolls
lv_loghandle type balloghndl.
data: ls_msg_filter type bal_s_mfil,
ls_log_filter type bal_s_lfil,
lt_msg_handle type bal_t_msgh,
ls_log_handle type bal_s_logh,
ls_msg_handle type balmsghndl,
ls_msg type bal_s_msg,
ls_string type string.
* does CRM function exist
call function 'FUNCTION_EXISTS'
exporting
funcname = cv_function_module
exceptions
function_not_exist = 1
others = 2.
message id ls_msg-msgid type ls_msg-msgty number ls_msg-msgno
with ls_msg-msgv1 ls_msg-msgv2 ls_msg-msgv3 ls_msg-msgv4
into ls_string.
write: /, ls_string.
clear ls_msg.
endloop.
endform. " check_usages
*&---------------------------------------------------------------------*
*& Form delete_ibasecomponent
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GV_PRODUCT_GUID text
*----------------------------------------------------------------------*
form delete_ibasecomponent using p_product_guid.
data: lv_guid22 like sysuuid-c22,
ls_comp type ibas_dat1.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.