‎2007 Jun 01 9:41 AM
Hi folks,
I' writing a report in order to delete orders but before deleteing these orders i have to delete the follow-up documents. in some cases follow-up document also have another follow up, so before delete the first on i have to delete the last one and the the Order. i wrote loop at lt_doc_flow into ls_doc_flow.
lv_objects_to_delete = ls_doc_flow-REF_GUID.
insert ls_doc_flow-REF_GUID into table lt_objects_to_delete.
endloop.
and the call function'crm-order_delete.
in order to delte all docflow, but it doesn't work.
do u have any idea , how i can delete it recursive?
thanks .
‎2007 Jun 01 1:48 PM
Hello Liliane
You have to define a recursive function in order to delete your documents.
The following sample reports shows how to do that:
*&---------------------------------------------------------------------*
*& Report ZUS_SDN_RECURSIVE_CALLS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zus_sdn_recursive_calls.
TYPE-POOLS: abap.
TYPES: BEGIN OF ty_s_doc.
TYPES: guid(3) TYPE n.
TYPES: ref_guid(3) TYPE n.
TYPES: text(50) TYPE c.
TYPES: deleted TYPE abap_bool.
TYPES: END OF ty_s_doc.
TYPES: ty_t_doc TYPE STANDARD TABLE OF ty_s_doc
WITH DEFAULT KEY.
DATA:
gs_doc TYPE ty_s_doc,
gt_doc TYPE ty_t_doc.
START-OF-SELECTION.
PERFORM fill_docs.
SORT gt_doc BY guid ref_guid.
WRITE: / 'Flow of Documents:'.
PERFORM write_docs.
WRITE: / 'Deleted Documents:'.
LOOP AT gt_doc INTO gs_doc
WHERE ( deleted = abap_false ).
PERFORM delete_doc
USING gs_doc.
ENDLOOP.
write: / syst-uline.
SKIP 2.
" Reset delete flag
gs_doc-deleted = abap_false.
MODIFY gt_doc FROM gs_doc
TRANSPORTING deleted
WHERE ( deleted = abap_true ).
" Change sorting
SORT gt_doc BY ref_guid.
WRITE: / 'Flow of Documents:'.
PERFORM write_docs.
WRITE: / 'Deleted Documents:'.
LOOP AT gt_doc INTO gs_doc
WHERE ( deleted = abap_false ).
PERFORM delete_doc
USING gs_doc.
ENDLOOP.
END-OF-SELECTION.
*&---------------------------------------------------------------------*
*& Form FILL_DOCS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fill_docs .
* define local data
DATA:
ls_doc TYPE ty_s_doc.
" Example: Doc_001 -> referenced by Doc_011 -> referenced by Doc_101
" Doc_002 -> Doc_012, Doc_013 -> Doc_112, Doc_113
" Doc_003 -> not referenced
CLEAR: ls_doc.
ls_doc-guid = '001'.
ls_doc-ref_guid = '000'. " no reference to other document
ls_doc-text = 'Document 001'.
APPEND ls_doc TO gt_doc.
*
CLEAR: ls_doc.
ls_doc-guid = '011'.
ls_doc-ref_guid = '001'.
ls_doc-text = 'Document 011'.
APPEND ls_doc TO gt_doc.
*
CLEAR: ls_doc.
ls_doc-guid = '101'.
ls_doc-ref_guid = '011'.
ls_doc-text = 'Document 101'.
APPEND ls_doc TO gt_doc.
CLEAR: ls_doc.
ls_doc-guid = '002'.
ls_doc-ref_guid = '000'. " no reference to other document
ls_doc-text = 'Document 002'.
APPEND ls_doc TO gt_doc.
*
CLEAR: ls_doc.
ls_doc-guid = '012'.
ls_doc-ref_guid = '002'.
ls_doc-text = 'Document 012'.
APPEND ls_doc TO gt_doc.
*
CLEAR: ls_doc.
ls_doc-guid = '013'.
ls_doc-ref_guid = '002'.
ls_doc-text = 'Document 013'.
APPEND ls_doc TO gt_doc.
*
CLEAR: ls_doc.
ls_doc-guid = '112'.
ls_doc-ref_guid = '012'.
ls_doc-text = 'Document 112'.
APPEND ls_doc TO gt_doc.
*
CLEAR: ls_doc.
ls_doc-guid = '113'.
ls_doc-ref_guid = '013'.
ls_doc-text = 'Document 113'.
APPEND ls_doc TO gt_doc.
CLEAR: ls_doc.
ls_doc-guid = '004'.
ls_doc-ref_guid = '000'. " no reference to other document
ls_doc-text = 'Document 004'.
APPEND ls_doc TO gt_doc.
ENDFORM. " FILL_DOCS
*&---------------------------------------------------------------------*
*& Form delete_doc
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_GS_DOC_GUID text
*----------------------------------------------------------------------*
FORM delete_doc
USING
value(us_doc) TYPE ty_s_doc.
* define local data
DATA:
ls_doc TYPE ty_s_doc.
LOOP AT gt_doc INTO ls_doc
WHERE ( ref_guid = us_doc-guid )
AND ( deleted = abap_false ).
PERFORM delete_doc
USING ls_doc.
ENDLOOP.
IF ( syst-subrc NE 0 ).
us_doc-deleted = abap_true.
MODIFY gt_doc FROM us_doc
TRANSPORTING deleted
WHERE ( guid = us_doc-guid ).
WRITE: / us_doc-guid, us_doc-text+0(15), us_doc-ref_guid.
ENDIF.
ENDFORM. " delete_doc
*&---------------------------------------------------------------------*
*& Form WRITE_DOCS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM write_docs .
* define local data
DATA:
ls_doc TYPE ty_s_doc.
LOOP AT gt_doc INTO ls_doc.
WRITE: / ls_doc-guid, ls_doc-text+0(15), ls_doc-ref_guid.
ENDLOOP.
SKIP.
ENDFORM. " WRITE_DOCSRegards
Uwe