GOS Anlagen (ATTA-URL-NOTE/) Lesen / Schreiben / Löschen

Nützliche Abap Codes und Code Fragmente

GOS Anlagen (ATTA-URL-NOTE/) Lesen / Schreiben / Löschen

Postby Tron » Sun Jan 26, 2020 2:46 pm

Moin.
Ich hatte vor kurzem das Vergnügen eine generische Schnittstelle für das GOS zu programmieren in Form von RFC-Funktionsbausteinen (soll auch für ODATA sein).
Zusätzlich möchte ich eine dynamische Check Funktion hervorheben, die prüfen soll, ob der Beleg überhaupt existiert an den man eine Anlage hängen möchte !
Diese funktioniert für die gängigen Objektypen, wie BUS2032 oder BKPF.
Falls nicht, oder bei Eigenentwicklung, kann man die eingebaute Prüfung abschalten.
Die Mimik mit dem Autocommit dient der Tatsache , das z. B: das Anlegen einer Anlage auch im Verbucher stattfinden kann, aber ohne Commit funktioniert das Anlegen nicht .

Hier nun das Anlegen / Lesen und Löschen von GOS Dokumenten vom Typ ATTA / URL / NOTE:

Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. FUNCTION z_bc_create_attachment2.
  2. *"----------------------------------------------------------------------
  3. *"*"Local Interface:
  4. *"  IMPORTING
  5. *"     VALUE(DOCUMENT) TYPE  SIBFBORIID
  6. *"     VALUE(BUSOBJECT) TYPE  SIBFTYPEID
  7. *"     VALUE(RELTYPE) TYPE  OBLRELTYPE DEFAULT 'ATTA'
  8. *"     VALUE(CHECK_BO) TYPE  XFELD DEFAULT 'X'
  9. *"     VALUE(XCOMMIT) TYPE  CHAR01 DEFAULT '2'
  10. *"     VALUE(S_DOC_DATA) TYPE  SOFOLENTI1
  11. *"     VALUE(ALIGN_NOTE_TEXT) TYPE  XFELD DEFAULT 'X'
  12. *"  TABLES
  13. *"      T_CONTENT_HEX STRUCTURE  SOLIX OPTIONAL
  14. *"      T_CONTENT_TXT STRUCTURE  SOLISTI1 OPTIONAL
  15. *"      T_RETURN STRUCTURE  BAPIRET2 OPTIONAL
  16. *"----------------------------------------------------------------------
  17.     c_catid  TYPE sibfcatid  VALUE 'BO',
  18.     c_region TYPE sofd-folrg VALUE 'B',
  19.     c_typeid TYPE sibftypeid VALUE 'MESSAGE'.
  20.  
  21.   " Define Messages
  22.   _bapi_message_data_definition.
  23.  
  24.   DATA:
  25.     " Folder
  26.     : gs_folder      TYPE soodk,
  27.  
  28.     " Link: Source & Target
  29.     gs_object      TYPE sibflporb,
  30.     gs_objtgt      TYPE sibflporb,
  31.  
  32.     " Document Basic data
  33.     gs_doc_info    TYPE sofolenti1,
  34.     gs_doc_data    TYPE sodocchgi1,
  35.     gd_doc_type    TYPE soodk-objtp,
  36.     "gv_reltype TYPE oblreltype,
  37.  
  38.     in_update_task TYPE sy-subrc,
  39.     rc             TYPE sy-subrc,
  40.  
  41.     ls_return      TYPE bapiret2.
  42.  
  43.   IF reltype NE 'ATTA' AND reltype NE 'NOTE' AND reltype NE 'URL'.
  44.     _bapi_message2 'No valid RELTYPE found.' '' '' ''.
  45.     APPEND _bapi_return TO t_return.
  46.     EXIT.
  47.   ENDIF.
  48.  
  49.   IF reltype EQ 'NOTE' AND NOT align_note_text IS INITIAL.
  50.     PERFORM align_note_text TABLES t_content_txt.
  51.   ENDIF.
  52.  
  53.   IF NOT check_bo IS INITIAL.
  54.     PERFORM check_entry_exist USING document busobject CHANGING rc.
  55.     IF rc NE 0.
  56.       CASE rc.
  57.         WHEN 1 .
  58.           _bapi_message1 'E' '60' '071'.
  59.           APPEND _bapi_return TO t_return.
  60.         WHEN 2.
  61.           _bapi_message1 'E' 'KX' '069'.
  62.           APPEND _bapi_return TO t_return.
  63.         WHEN 3.
  64.           _bapi_message1 'E' '5V' '076'.
  65.           APPEND _bapi_return TO t_return.
  66.         WHEN OTHERS.
  67.       ENDCASE.
  68.  
  69.       EXIT.
  70.     ENDIF.
  71.   ENDIF.
  72.  
  73.   " Get Root-Folder
  74.   CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
  75.     EXPORTING
  76.       region    = c_region
  77.     IMPORTING
  78.       folder_id = gs_folder.
  79.  
  80.   " Create document
  81.   CLEAR  gs_doc_data .
  82.   MOVE-CORRESPONDING s_doc_data TO gs_doc_data .
  83.   CALL FUNCTION 'SO_DOCUMENT_INSERT_API1'
  84.     EXPORTING
  85.       folder_id      = gs_folder
  86.       document_data  = gs_doc_data
  87.       document_type  = s_doc_data-obj_type
  88.     IMPORTING
  89.       document_info  = gs_doc_info
  90.     TABLES
  91.       object_content = t_content_txt
  92.       contents_hex   = t_content_hex.
  93.  
  94.   " Businessobject-ID remains
  95.   gs_object-instid  = document.
  96.   gs_object-typeid  = busobject.
  97.   gs_object-catid   = c_catid.
  98.  
  99.   " Documentdata to Destination
  100.   CONCATENATE gs_folder gs_doc_info-object_id
  101.      INTO gs_objtgt-instid RESPECTING BLANKS.
  102.   gs_objtgt-typeid  = c_typeid.
  103.   gs_objtgt-catid   = c_catid.
  104.  
  105.   TRY.
  106.       " Create Link
  107.  
  108.       cl_binary_relation=>create_link(
  109.         EXPORTING
  110.           is_object_a = gs_object
  111.           is_object_b = gs_objtgt
  112.           ip_reltype  = reltype ).
  113.  
  114.       CASE xcommit.
  115.         WHEN '1'.
  116.           COMMIT WORK AND WAIT.
  117.  
  118.         WHEN '2'.
  119.           " see if we are in update task
  120.           CALL FUNCTION 'TH_IN_UPDATE_TASK'
  121.             IMPORTING
  122.               in_update_task = in_update_task.
  123.  
  124.           IF in_update_task IS INITIAL.
  125.             COMMIT WORK AND WAIT.
  126.           ENDIF.
  127.  
  128.         WHEN OTHERS.
  129.       ENDCASE.
  130.  
  131.     CATCH cx_obl_parameter_error cx_obl_model_error cx_obl_internal_error.
  132.   ENDTRY.
  133.  
  134.  
  135.  
  136.  
  137. *&---------------------------------------------------------------------*
  138. *&      Form  Check_entry_exist
  139. *&---------------------------------------------------------------------*
  140. *       text
  141. *----------------------------------------------------------------------*
  142. *      -->DOCUMENT   text
  143. *      -->BUSOBJECT  text
  144. *      -->RC         text
  145. *----------------------------------------------------------------------*
  146. FORM check_entry_exist USING    document TYPE sibfboriid
  147.                                 busobject TYPE sibftypeid
  148.                        CHANGING rc TYPE sy-subrc.
  149.  
  150.   DATA:
  151.     l_bo_model_id TYPE rpybobs-objtype,
  152.     t_keys        TYPE TABLE OF rpyboke,
  153.     s_keys        TYPE rpyboke.
  154.  
  155.   DATA:
  156.     t_dfies  TYPE TABLE OF dfies,
  157.     t_dfies1 TYPE TABLE OF dfies,
  158.     s_dfies  TYPE dfies,
  159.     l_tab    TYPE ddobjname,
  160.     l_field  TYPE dfies-fieldname,
  161.     ls_sel   TYPE ddshselopt,
  162.     lt_sel   TYPE TABLE OF ddshselopt,
  163.     l_where  TYPE string,
  164.     l_off    TYPE i.
  165.  
  166.   l_bo_model_id = busobject.
  167.  
  168.   CALL FUNCTION 'RPY_OBJECTTYPE_READ'
  169.     EXPORTING
  170.       objecttype_id                = l_bo_model_id
  171.       language                     = sy-langu
  172.       cico_mode                    = 'R'
  173.       cico_request_no              = ' '
  174.       with_verbs                   = 'X'
  175.       with_parameters              = ' '
  176.       with_exceptions              = ' '
  177.       with_texts                   = ' '
  178.       with_formatted_documentation = ' '
  179.       with_sapscript_documentation = ' '
  180.     TABLES
  181.       keyfields                    = t_keys
  182.     EXCEPTIONS
  183.       not_found                    = 1
  184.       permission_error             = 2
  185.       OTHERS                       = 3.
  186.  
  187.  
  188.   IF sy-subrc <> 0.
  189.     rc = 1.
  190.     EXIT.
  191.   ENDIF.
  192.  
  193.   READ TABLE  t_keys INTO  s_keys INDEX 1.
  194.   IF sy-subrc <> 0.
  195.     rc = 2.
  196.     EXIT.
  197.   ENDIF.
  198.  
  199.   LOOP AT t_keys INTO s_keys.
  200.     l_tab = s_keys-refstruct.
  201.     l_field = s_keys-reffield.
  202.  
  203.     REFRESH t_dfies1.
  204.     CALL FUNCTION 'DDIF_FIELDINFO_GET'
  205.       EXPORTING
  206.         tabname        = l_tab
  207.         fieldname      = l_field
  208.       TABLES
  209.         dfies_tab      = t_dfies1
  210.       EXCEPTIONS
  211.         not_found      = 1
  212.         internal_error = 2
  213.         OTHERS         = 3.
  214.  
  215.     IF sy-subrc <> 0.
  216.       rc = 1.
  217.       EXIT.
  218.     ENDIF.
  219.     APPEND LINES OF t_dfies1 TO t_dfies.
  220.  
  221.   SORT t_dfies ASCENDING BY position.
  222.  
  223.   LOOP AT t_dfies INTO s_dfies.
  224.     CLEAR ls_sel.
  225.     ls_sel-shlpfield = s_dfies-fieldname.
  226.     ls_sel-sign = 'I'.
  227.     ls_sel-option = 'EQ'.
  228.     ls_sel-low = document+l_off(s_dfies-leng).
  229.     l_off = l_off + s_dfies-leng.
  230.     APPEND ls_sel TO lt_sel.
  231.  
  232.   CALL FUNCTION 'F4_CONV_SELOPT_TO_WHERECLAUSE'
  233.     IMPORTING
  234.       where_clause = l_where
  235.     TABLES
  236.       selopt_tab   = lt_sel.
  237.  
  238.   SELECT SINGLE COUNT(*) FROM (l_tab) WHERE (l_where).
  239.   rc = sy-subrc.
  240.  
  241. ENDFORM.                    "Check_entry_exist
  242.  
  243. *&---------------------------------------------------------------------*
  244. *&      Form  ALIGN_NOTE_TEXT
  245. *&---------------------------------------------------------------------*
  246. *       text
  247. *----------------------------------------------------------------------*
  248. FORM align_note_text TABLES t_content_txt STRUCTURE solisti1.
  249.   DATA l_str TYPE string.
  250.   DATA ls_contt TYPE solisti1.
  251.  
  252.   LOOP AT t_content_txt INTO ls_contt.
  253.     IF sy-tabix > 1.
  254.       CONCATENATE l_str
  255.       ls_contt-line
  256.       INTO l_str SEPARATED BY space.
  257.     ELSE.
  258.       CONCATENATE l_str
  259.       ls_contt-line
  260.       INTO l_str.
  261.     ENDIF.
  262.  
  263.   REFRESH t_content_txt.
  264.   CALL FUNCTION 'SCMS_STRING_TO_FTEXT'
  265.     EXPORTING
  266.       text      = l_str
  267.     TABLES
  268.       ftext_tab = t_content_txt.
  269.  
  270. ENDFORM.                    "ALIGN_NOTE_TEXT
GeSHi ©

Der Top include mit dem Makros:

Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. FUNCTION-POOL ZGOSUTILS2.                    "MESSAGE-ID ..
  2.  
  3. DEFINE _bapi_message_data_definition.
  4.   data:
  5.          _mess1 type sy-msgv1,
  6.          _mess2 type sy-msgv2,
  7.          _mess3 type sy-msgv3,
  8.          _mess4 type sy-msgv4,
  9.          _bapi_return type BAPIRET2.
  10.  
  11. * use Message from T100
  12. DEFINE _bapi_message1.
  13.   call function 'FS_BAPI_BAPIRET2_FILL'
  14.     exporting
  15.       type   = &1
  16.       cl     = &2
  17.       number = &3
  18.     importing
  19.       return = _bapi_return.
  20.  
  21. * Free defined Message with up to 4 Parameters
  22. DEFINE _bapi_message2.
  23.   _mess1 = &1.
  24.   _mess2 = &2.
  25.   _mess3 = &3.
  26.   _mess4 = &4.
  27.   call function 'FS_BAPI_BAPIRET2_FILL'
  28.     exporting
  29.       type   = 'E'
  30.       cl     = '00'
  31.       number = '398'
  32.       par1   =  _mess1
  33.       par2   =  _mess2
  34.       par3   =  _mess3
  35.       par4   =  _mess4
  36.     importing
  37.       return = _bapi_return.
GeSHi ©


und nun das Lesen von GOS-Dokumenten.

Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. FUNCTION z_bc_read_attachment2.
  2. *"----------------------------------------------------------------------
  3. *"*"Local Interface:
  4. *"  IMPORTING
  5. *"     VALUE(DOCUMENT) TYPE  SIBFBORIID
  6. *"     VALUE(BUSOBJECT) TYPE  SIBFTYPEID
  7. *"     VALUE(INSTID_B) TYPE  SIBFBORIID OPTIONAL
  8. *"  EXPORTING
  9. *"     VALUE(S_DOC_DATA) TYPE  SOFOLENTI1
  10. *"  TABLES
  11. *"      T_CONTENT_HEX STRUCTURE  SOLIX OPTIONAL
  12. *"      T_CONTENT_TXT STRUCTURE  SOLISTI1 OPTIONAL
  13. *"      T_RETURN STRUCTURE  BAPIRET2 OPTIONAL
  14. *"----------------------------------------------------------------------
  15.     c_catid     TYPE sibfcatid  VALUE 'BO',
  16.     c_region    TYPE sofd-folrg VALUE 'B',
  17.     c_typeid    TYPE sibftypeid VALUE 'MESSAGE',
  18.     "c_reltyp TYPE oblreltype VALUE 'ATTA',
  19.     c_role_type TYPE mdoblrol-roletype VALUE 'GOSAPPLOBJ'.
  20.  
  21.   TYPES:
  22.     BEGIN OF gys_key,
  23.       foltp     TYPE so_fol_tp,
  24.       folyr     TYPE so_fol_yr,
  25.       folno     TYPE so_fol_no,
  26.       objtp     TYPE so_obj_tp,
  27.       objyr     TYPE so_obj_yr,
  28.       objno     TYPE so_obj_no,
  29.       forwarder TYPE so_usr_nam,
  30.     END OF gys_key.
  31.  
  32.   " Define Messages
  33.   _bapi_message_data_definition.
  34.  
  35.   DATA:
  36.     " key of Business-Objects
  37.     gs_object TYPE sibflporb,
  38.  
  39.     " Link to Object
  40.     gt_links  TYPE obl_t_link,
  41.     gs_links  TYPE obl_s_link,
  42.  
  43.     " Link options
  44.     gt_relopt TYPE obl_t_relt,
  45.     gs_relopt TYPE obl_s_relt,
  46.  
  47.     " Key of Link
  48.     gs_key    TYPE gys_key,
  49.  
  50.     " Document-ID
  51.     gd_doc_id TYPE so_entryid.
  52.  
  53.   " Document content Text and Binary
  54. *     ls_return TYPE bapiret2,
  55. *     l_mess TYPE sy-msgv2.
  56.  
  57.   " Assign Businessobject-ID
  58.   gs_object-instid  = document.
  59.   gs_object-typeid  = busobject.
  60.   gs_object-catid   = c_catid.
  61.  
  62.   " Link types:
  63.   gs_relopt-sign = 'I'.
  64.   gs_relopt-option = 'CP'.
  65.  
  66.   " Attachments
  67.   gs_relopt-low = '*'.
  68.   APPEND gs_relopt TO gt_relopt.
  69.  
  70.   TRY.
  71.       " Read links to objects
  72.       cl_binary_relation=>read_links_of_binrels(
  73.         EXPORTING
  74.           is_object           = gs_object
  75.           it_relation_options = gt_relopt
  76.           ip_role             = c_role_type
  77.         IMPORTING
  78.           et_links            = gt_links ).
  79.  
  80.       IF NOT instid_b IS INITIAL.
  81.         DELETE gt_links WHERE instid_b NE instid_b.
  82.       ENDIF.
  83.  
  84.       LOOP AT gt_links INTO gs_links WHERE typeid_b = c_typeid.
  85.  
  86.         gs_key = gs_links-instid_b.
  87.         .
  88.         " The document ID for SAPOffice is according to the instance ID
  89.         gd_doc_id = gs_links-instid_b.
  90.  
  91.         " clear content
  92.         CLEAR:t_content_txt, t_content_hex.
  93.  
  94.         " read document
  95.         CALL FUNCTION 'SO_DOCUMENT_READ_API1'
  96.           EXPORTING
  97.             document_id                = gd_doc_id
  98.           IMPORTING
  99.             document_data              = s_doc_data
  100.           TABLES
  101.             object_content             = t_content_txt
  102.             contents_hex               = t_content_hex
  103.           EXCEPTIONS
  104.             document_id_not_exist      = 1
  105.             operation_no_authorization = 2
  106.             x_error                    = 3
  107.             OTHERS                     = 4.
  108.  
  109.         " In case that there is a link without content
  110.         IF sy-subrc NE 0.
  111.           _bapi_message2 gd_doc_id 'has no Data/Content' '' ''.
  112.           APPEND _bapi_return TO t_return.
  113.         ENDIF.
  114.  
  115.         EXIT. " only single document
  116.       ENDLOOP.
  117.     CATCH cx_obl_parameter_error cx_obl_internal_error cx_obl_model_error.
  118.       " Error handling: Read links
  119.   ENDTRY.
  120.  
GeSHi ©


.. Das LÖSCHEN von Anlagen:..
(bei INSTID_B = ALL, werden alle Anlagen des Belegs gelöscht)

Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. FUNCTION Z_BC_DELETE_ATTACHMENT2.
  2. *"--------------------------------------------------------------------
  3. *"*"Local Interface:
  4. *"  IMPORTING
  5. *"     VALUE(DOCUMENT) TYPE  SIBFBORIID
  6. *"     VALUE(BUSOBJECT) TYPE  SIBFTYPEID
  7. *"     VALUE(INSTID_B) TYPE  SIBFBORIID OPTIONAL
  8. *"     VALUE(XCOMMIT) TYPE  CHAR01 DEFAULT '1'
  9. *"  TABLES
  10. *"      T_RETURN STRUCTURE  BAPIRET2 OPTIONAL
  11. *"      T_DELETED_DATA STRUCTURE  SOFOLENTI1 OPTIONAL
  12. *"--------------------------------------------------------------------
  13.   c_catid TYPE sibfcatid  VALUE 'BO',
  14.   c_region TYPE sofd-folrg VALUE 'B',
  15.   c_typeid  TYPE sibftypeid VALUE 'MESSAGE',
  16.   c_role_type TYPE mdoblrol-roletype VALUE 'GOSAPPLOBJ'.
  17.  
  18.   TYPES:
  19.       BEGIN OF gys_key,
  20.         foltp TYPE so_fol_tp,
  21.         folyr TYPE so_fol_yr,
  22.         folno TYPE so_fol_no,
  23.         objtp TYPE so_obj_tp,
  24.         objyr TYPE so_obj_yr,
  25.         objno TYPE so_obj_no,
  26.         forwarder TYPE so_usr_nam,
  27.       END OF gys_key.
  28.  
  29.   " Define Messages
  30.   _bapi_message_data_definition.
  31.  
  32.   DATA:
  33.       " key of Business-Objects
  34.       gs_object   TYPE sibflporb,
  35.  
  36.       " Link to Object
  37.      gt_links    TYPE obl_t_link,
  38.      gs_links    TYPE obl_s_link,
  39.      s_obj_a TYPE sibflporb,
  40.      s_obj_b TYPE sibflporb,
  41.      l_reltype TYPE oblreltype, " ATTA URL NOTE
  42.  
  43.       " Link options
  44.      gt_relopt   TYPE obl_t_relt,
  45.      gs_relopt   TYPE obl_s_relt,
  46.      s_doc_data  TYPE  sofolenti1,
  47.  
  48.       " Key of Link
  49.      gs_key      TYPE gys_key,
  50.  
  51.       " Document-ID
  52.      gd_doc_id   TYPE so_entryid,
  53.  
  54.       " Document content Text and Binary
  55.      ls_return TYPE bapiret2,
  56.      in_update_task TYPE sy-subrc,
  57.      l_rc TYPE sy-subrc.
  58.  
  59.   " Assign Businessobject-ID
  60.   gs_object-instid  = document.
  61.   gs_object-typeid  = busobject.
  62.   gs_object-catid   = c_catid.
  63.  
  64.   " Link types:
  65.   gs_relopt-sign = 'I'.
  66.   gs_relopt-option = 'CP'.
  67.  
  68.   " Attachments
  69.   gs_relopt-low = '*'.
  70.   APPEND gs_relopt TO gt_relopt.
  71.  
  72.  
  73.   REFRESH t_deleted_data.
  74.   TRY.
  75.       " Read links to objects
  76.       cl_binary_relation=>read_links_of_binrels(
  77.         EXPORTING
  78.           is_object           = gs_object
  79.           it_relation_options = gt_relopt
  80.           ip_role             = c_role_type
  81.         IMPORTING
  82.           et_links            = gt_links ).
  83.  
  84.       IF NOT instid_b = 'ALL'.
  85.         IF NOT instid_b IS INITIAL.
  86.           DELETE gt_links WHERE instid_b NE instid_b.
  87.           IF gt_links[] IS INITIAL.
  88.             _bapi_message2 'No Links found.' '' '' ''.
  89.             APPEND _bapi_return TO t_return.
  90.             EXIT.
  91.           ENDIF.
  92.         ELSE.
  93.           _bapi_message2 'No Key Parameter.' '' '' ''.
  94.           APPEND _bapi_return TO t_return.
  95.           EXIT.
  96.         ENDIF.
  97.       ENDIF.
  98.  
  99.       LOOP AT gt_links INTO gs_links WHERE typeid_b = c_typeid.
  100.  
  101.         gs_key = gs_links-instid_b.
  102.         .
  103.         " The document ID for SAPOffice is according to the instance ID
  104.         gd_doc_id = gs_links-instid_b.
  105.  
  106.         " read document
  107.         CALL FUNCTION 'SO_DOCUMENT_READ_API1'
  108.           EXPORTING
  109.             document_id                = gd_doc_id
  110.           IMPORTING
  111.             document_data              = s_doc_data
  112.           EXCEPTIONS
  113.             document_id_not_exist      = 1
  114.             operation_no_authorization = 2
  115.             x_error                    = 3
  116.             OTHERS                     = 4.
  117.  
  118.         l_rc = sy-subrc.
  119.  
  120.         CASE l_rc.
  121.           WHEN 0.
  122.           WHEN 1.
  123.             _bapi_message2 'SO_DOCUMENT_READ_API1' 'document_id_not_exist' '' ''.
  124.             APPEND _bapi_return TO t_return.
  125.           WHEN 2.
  126.             _bapi_message2 'SO_DOCUMENT_READ_API1' 'operation_no_authorization' '' ''.
  127.             APPEND _bapi_return TO t_return.
  128.           WHEN OTHERS.
  129.             _bapi_message2 'SO_DOCUMENT_READ_API1' 'unknown error' '' ''.
  130.             APPEND _bapi_return TO t_return.
  131.         ENDCASE.
  132.  
  133.         IF l_rc = 0.
  134.           CALL FUNCTION 'SO_DOCUMENT_DELETE_API1'
  135.             EXPORTING
  136.               document_id                = gd_doc_id
  137.               unread_delete              = 'X'
  138.               put_in_trash               = ' '
  139.             EXCEPTIONS
  140.               document_not_exist         = 1
  141.               operation_no_authorization = 2
  142.               parameter_error            = 3
  143.               x_error                    = 4
  144.               enqueue_error              = 5
  145.               OTHERS                     = 6.
  146.  
  147.           l_rc = sy-subrc.
  148.  
  149.           CASE l_rc.
  150.             WHEN 0.
  151.             WHEN 1.
  152.               _bapi_message2 'SO_DOCUMENT_DELETE_API1' 'document_id_not_exist' '' ''.
  153.               APPEND _bapi_return TO t_return.
  154.             WHEN 2.
  155.               _bapi_message2 'SO_DOCUMENT_DELETE_API1' 'operation_no_authorization' '' ''.
  156.               APPEND _bapi_return TO t_return.
  157.             WHEN 3.
  158.               _bapi_message2 'SO_DOCUMENT_DELETE_API1' 'parameter_error' '' ''.
  159.               APPEND _bapi_return TO t_return.
  160.             WHEN 4.
  161.               _bapi_message2 'SO_DOCUMENT_DELETE_API1' 'x_error' '' ''.
  162.               APPEND _bapi_return TO t_return.
  163.             WHEN 5.
  164.               _bapi_message2 'SO_DOCUMENT_DELETE_API1' 'enqueue_error' '' ''.
  165.               APPEND _bapi_return TO t_return.
  166.             WHEN OTHERS.
  167.               _bapi_message2 'SO_DOCUMENT_DELETE_API1' 'unknown error' '' ''.
  168.               APPEND _bapi_return TO t_return.
  169.           ENDCASE.
  170.  
  171.           IF l_rc = 0.
  172.             s_obj_a-instid = gs_links-instid_a.
  173.             s_obj_a-typeid = gs_links-typeid_a.
  174.             s_obj_a-catid  = gs_links-catid_a.
  175.             s_obj_b-instid = gs_links-instid_b.
  176.             s_obj_b-typeid = gs_links-typeid_b.
  177.             s_obj_b-catid  = gs_links-catid_b.
  178.             l_reltype = gs_links-reltype.
  179.  
  180.             TRY.
  181.                 cl_binary_relation=>delete_link(
  182.                   EXPORTING
  183.                     is_object_a = s_obj_a
  184.                     is_object_b = s_obj_b
  185.                     ip_reltype  = l_reltype ).
  186.  
  187.                 " remember deleted links
  188.                 APPEND s_doc_data TO t_deleted_data.
  189.  
  190.               CATCH cx_obl_parameter_error cx_obl_internal_error cx_obl_model_error.
  191.  
  192.             ENDTRY.
  193.  
  194.             CASE xcommit.
  195.               WHEN '1'.
  196.                 COMMIT WORK AND WAIT.
  197.               WHEN '2'.
  198.                 " see if we are in update task
  199.                 CALL FUNCTION 'TH_IN_UPDATE_TASK'
  200.                   IMPORTING
  201.                     in_update_task = in_update_task.
  202.  
  203.                 IF in_update_task IS INITIAL.
  204.                   COMMIT WORK AND WAIT.
  205.                 ENDIF.
  206.               WHEN OTHERS.
  207.             ENDCASE.
  208.  
  209.           ENDIF.
  210.  
  211.         ENDIF.
  212.  
  213.       ENDLOOP.
  214.     CATCH cx_obl_parameter_error cx_obl_internal_error cx_obl_model_error.
  215.       " Error handling: Read links
  216.   ENDTRY.
  217.  
GeSHi ©



... Ermitteln aller Anlagen zum Beleg plus Schlüsselfelder des Businessobjekts...

Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. FUNCTION Z_BC_GOS_INFO2.
  2. *"--------------------------------------------------------------------
  3. *"*"Local Interface:
  4. *"  IMPORTING
  5. *"     VALUE(DOCUMENT) TYPE  SIBFBORIID
  6. *"     VALUE(BUSOBJECT) TYPE  SIBFTYPEID
  7. *"     VALUE(READ_KEYFIELDS) TYPE  XFELD DEFAULT 'X'
  8. *"  TABLES
  9. *"      T_LINKS STRUCTURE  OBL_S_LINK OPTIONAL
  10. *"      T_RETURN STRUCTURE  BAPIRET2 OPTIONAL
  11. *"      T_KEYFIELDS STRUCTURE  RPYBOKE OPTIONAL
  12. *"--------------------------------------------------------------------
  13.     c_catid     TYPE sibfcatid  VALUE 'BO',
  14.     c_role_type TYPE mdoblrol-roletype VALUE 'GOSAPPLOBJ'.
  15.  
  16.   " Define Messages
  17.   _bapi_message_data_definition.
  18.  
  19.   DATA:
  20.     " Schlüssel des Business-Objekts
  21.     gs_object  TYPE sibflporb,
  22.  
  23.     " Verknüpfungen zum Objekt
  24.     gt_links   TYPE obl_t_link,
  25. *     gs_links    TYPE obl_s_link,
  26.  
  27.     " Verknüpfungsoptionen
  28.     gt_relopt  TYPE obl_t_relt,
  29.     gs_relopt  TYPE obl_s_relt,
  30.     lv_objtype TYPE rpybobs-objtype.
  31.  
  32.  
  33.   " Businessobjekt-ID übernehmen
  34.   gs_object-instid  = document.
  35.   gs_object-typeid  = busobject.
  36.   gs_object-catid   = c_catid.
  37.  
  38.   " Verknüpfungstypen:
  39.   gs_relopt-sign = 'I'.
  40.   gs_relopt-option = 'CP'.
  41.  
  42.   " Anhänge
  43.   gs_relopt-low = '*'.
  44.  
  45.   APPEND gs_relopt TO gt_relopt.
  46.  
  47.   TRY.
  48.       " Verknüpfungen zum Objekt lesen
  49.       cl_binary_relation=>read_links_of_binrels(
  50.         EXPORTING
  51.           is_object           = gs_object
  52.           it_relation_options = gt_relopt
  53.           ip_role             = c_role_type
  54.         IMPORTING
  55.           et_links            = gt_links ).
  56.  
  57.       t_links[] = gt_links.
  58.  
  59.     CATCH cx_obl_parameter_error cx_obl_internal_error cx_obl_model_error.
  60.   ENDTRY.
  61.  
  62.  
  63.   IF gt_links[] IS INITIAL.
  64.     _bapi_message2 'No Links found.for' busobject document ''.
  65.     APPEND _bapi_return TO t_return.
  66.   ENDIF.
  67.  
  68.   CHECK NOT read_keyfields IS INITIAL.
  69.  
  70.   lv_objtype = busobject.
  71.  
  72.   CALL FUNCTION 'RPY_OBJECTTYPE_READ'
  73.     EXPORTING
  74.       objecttype_id                = lv_objtype
  75.       with_verbs                   = 'X'
  76.       with_parameters              = ' '
  77.       with_exceptions              = ' '
  78.       with_texts                   = ' '
  79.       with_formatted_documentation = ' '
  80.       with_sapscript_documentation = ' '
  81.     TABLES
  82.       keyfields                    = t_keyfields
  83.     EXCEPTIONS
  84.       not_found                    = 1
  85.       permission_error             = 2
  86.       OTHERS                       = 3.
  87.   IF sy-subrc <> 0.
  88.     _bapi_message2 'No Keyfields found.for' lv_objtype '' ''.
  89.     APPEND _bapi_return TO t_return.
  90.   ENDIF.
  91.  
  92.  
GeSHi ©


.Das Testprogramm:.


Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. *&---------------------------------------------------------------------*
  2. *& Report  Z_CREATE_GOS2
  3. *&
  4. *&---------------------------------------------------------------------*
  5. *&
  6. *&
  7. *&---------------------------------------------------------------------*
  8.  
  9. REPORT  z_create_gos2.
  10.     " Dokumenten-Grunddaten
  11.     gs_doc_info TYPE sofolenti1
  12.  
  13.     " Dokumenteninhalt binär
  14.   , gt_contx    TYPE solix_tab
  15.  
  16.     " Dateiinformationen
  17.   , gd_file     TYPE string
  18.   , gd_flen     TYPE i
  19.   .
  20.     " Eingabefelder für die ID des Business-Objekts
  21.    p_instid    TYPE sibfboriid OBLIGATORY DEFAULT '0000000008',
  22.    p_typeid    TYPE sibftypeid OBLIGATORY DEFAULT 'BUS2032',
  23.    p_catid     TYPE sibfcatid  OBLIGATORY DEFAULT 'BO',
  24.    p_file      TYPE ibipparms-path OBLIGATORY VISIBLE LENGTH 40 DEFAULT 'C:\temp\Test.pdf'.
  25.  
  26. AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  27.  
  28.   CALL FUNCTION 'F4_FILENAME'
  29.     EXPORTING
  30.       program_name  = syst-cprog
  31.       dynpro_number = syst-dynnr
  32.       field_name    = 'P_FILE'
  33.     IMPORTING
  34.       file_name     = p_file.
  35.  
  36.  
  37.  
  38.   gd_file = p_file.
  39.  
  40.   " Datei hochladen
  41.   CALL FUNCTION 'GUI_UPLOAD'
  42.     EXPORTING
  43.       filename   = gd_file
  44.       filetype   = 'BIN'
  45.     IMPORTING
  46.       filelength = gd_flen
  47.     TABLES
  48.       data_tab   = gt_contx
  49.     EXCEPTIONS
  50.       OTHERS     = 1.
  51.  
  52.  
  53.   DATA:
  54.         doc_descr TYPE sodocchgi1-obj_descr VALUE 'Das ist ein Test',
  55.         doc_name  TYPE sodocchgi1-obj_name VALUE 'Test.pdf'.
  56.   DATA t_return TYPE TABLE OF bapiret2.
  57.  
  58.  
  59.  
  60.   gs_doc_info-obj_type = 'PDF'.
  61.   gs_doc_info-doc_size = gd_flen.
  62.   gs_doc_info-obj_descr = doc_descr.
  63.   gs_doc_info-obj_name = doc_name.
  64.  
  65.   CALL FUNCTION 'Z_BC_CREATE_ATTACHMENT2'
  66.     EXPORTING
  67.       document   = p_instid
  68.       busobject  = p_typeid
  69.       RELTYPE    = 'ATTA'
  70.       check_bo   = 'X'
  71.       xcommit    = '2'
  72.       s_doc_data = gs_doc_info
  73.     TABLES
  74.     t_content_hex = gt_contx
  75.     t_return   = t_return.
  76.  
GeSHi ©


. Testprogramm Create URL.

Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. *&---------------------------------------------------------------------*
  2. *& Report  Z_CREATE_GOS5
  3. *&
  4. *&---------------------------------------------------------------------*
  5. *&
  6. *& Create URL
  7. *&---------------------------------------------------------------------*
  8.  
  9. REPORT  z_create_gos6.
  10.     " Dokumenten-Grunddaten
  11.     s_doc_data TYPE sofolenti1
  12.  
  13.     " Dokumenteninhalt binär
  14.   , gt_contt    TYPE TABLE OF solisti1
  15.   , gs_contt    TYPE  solisti1
  16.   , t_return    TYPE TABLE OF bapiret2
  17.   .
  18.     " Eingabefelder für die ID des Business-Objekts
  19.    p_insid1    TYPE sibfboriid OBLIGATORY DEFAULT '2130001978',
  20.    p_typeid    TYPE sibftypeid OBLIGATORY DEFAULT 'BUS2032'.
  21.  
  22. s_doc_data-obj_name = p_insid1.
  23. s_doc_data-obj_descr = 'Test with URL'.
  24. s_doc_data-obj_langu = sy-langu.
  25. s_doc_data-obj_type = 'URL'.
  26. *s_doc_data-doc_size  MUST BE INITIAL !!!
  27.  
  28. REFRESH gt_contt.
  29. gs_contt = '&KEY&https://www.abapforum.com/forum/'.
  30. APPEND gs_contt TO gt_contt.
  31.  
  32. CALL FUNCTION 'Z_BC_CREATE_ATTACHMENT2'
  33.   EXPORTING
  34.     document   = p_insid1
  35.     busobject  = p_typeid
  36.     reltype    = 'URL'
  37. *   CHECK_BO            = 'X'
  38. *   XCOMMIT             = '1'
  39.     s_doc_data          = s_doc_data
  40. *   T_CONTENT_HEX       =
  41.     t_content_txt       = gt_contt
  42.     t_return            = t_return.
  43.  
GeSHi ©


.. Anlegen NOTE.

Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. *&---------------------------------------------------------------------*
  2. *& Report  Z_CREATE_GOS5
  3. *&
  4. *&---------------------------------------------------------------------*
  5. *&
  6. *& Create NOTE
  7. *&---------------------------------------------------------------------*
  8.  
  9. REPORT  z_create_gos5.
  10. CONSTANTS _crlf(2) VALUE %_cr_lf.
  11.     " Dokumenten-Grunddaten
  12.     s_doc_data TYPE sofolenti1
  13.  
  14.     " Dokumenteninhalt binär
  15.   , gt_contt    TYPE TABLE OF solisti1
  16.   , gs_contt    TYPE  solisti1
  17.   , t_return    TYPE TABLE OF bapiret2
  18.   .
  19.     " Eingabefelder für die ID des Business-Objekts
  20.    p_insid1    TYPE sibfboriid OBLIGATORY DEFAULT '2130001978',
  21.    p_typeid    TYPE sibftypeid OBLIGATORY DEFAULT 'BUS2032'.
  22.  
  23. s_doc_data-obj_name = p_insid1.
  24. s_doc_data-obj_descr = 'Test with Note'.
  25. s_doc_data-obj_langu = sy-langu.
  26. *s_doc_data-doc_size  MUST BE INITIAL !!!
  27. s_doc_data-obj_type = 'TXT'.
  28.  
  29. gs_contt-line = 'bei der Nutzung eines User-Exits möchte ich gewisse Schritte nur ausführen wenn sich Inhalte geändert haben'.
  30. APPEND gs_contt TO gt_contt.
  31. gs_contt-line = 'kenne es so, und so sind die internen Tabelle auch bezeichnet, dass in den Tabellen YVBPA etc. die Inhalte zum'.
  32. APPEND gs_contt TO gt_contt.
  33. gs_contt-line = 'Start der Transaktion befinden, in den Tabelle XVBPA etc. die aktuellen Belegdaten. Das System erkennt dann bei'.
  34. APPEND gs_contt TO gt_contt.
  35. gs_contt-line = 'Unterschieden zwischen z.B. XVBPA und YVBPA ob sich Inhalte geändert haben und der Beleg gespeichert werden'.
  36. APPEND gs_contt TO gt_contt.
  37. gs_contt-line = 'Leider sind die Tabellen YVBPA etc. leer. Wie kann ich erkennen ob sich z.B. der WE oder die Materialnummer'.
  38. APPEND gs_contt TO gt_contt.
  39.  
  40.  
  41.  
  42.  
  43. CALL FUNCTION 'Z_BC_CREATE_ATTACHMENT2'
  44.   EXPORTING
  45.     document   = p_insid1
  46.     busobject  = p_typeid
  47.     RELTYPE    = 'NOTE'
  48. *   CHECK_BO            = 'X'
  49. *   XCOMMIT             = '1'
  50.     s_doc_data          = s_doc_data
  51. *   T_CONTENT_HEX       =
  52.     t_content_txt       = gt_contt
  53.     t_return            = t_return.
  54.  
GeSHi ©


gruß Jens
Tron
.....
.....
 
Posts: 1098
Joined: Sat Aug 04, 2007 10:21 pm

Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 1 guest

cron
  • Latest Topics