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

Hinweise, Tips und Tricks, FAQs - keine Anfragen!!
1 Beitrag • Seite 1 von 1
1 Beitrag Seite 1 von 1

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

Beitrag von Tron (Top Expert / 1327 / 35 / 332 ) »
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: Alles auswählen.

FUNCTION z_bc_create_attachment2.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(DOCUMENT) TYPE  SIBFBORIID
*"     VALUE(BUSOBJECT) TYPE  SIBFTYPEID
*"     VALUE(RELTYPE) TYPE  OBLRELTYPE DEFAULT 'ATTA'
*"     VALUE(CHECK_BO) TYPE  XFELD DEFAULT 'X'
*"     VALUE(XCOMMIT) TYPE  CHAR01 DEFAULT '2'
*"     VALUE(S_DOC_DATA) TYPE  SOFOLENTI1
*"     VALUE(ALIGN_NOTE_TEXT) TYPE  XFELD DEFAULT 'X'
*"  TABLES
*"      T_CONTENT_HEX STRUCTURE  SOLIX OPTIONAL
*"      T_CONTENT_TXT STRUCTURE  SOLISTI1 OPTIONAL
*"      T_RETURN STRUCTURE  BAPIRET2 OPTIONAL
*"----------------------------------------------------------------------
  CONSTANTS:
    c_catid  TYPE sibfcatid  VALUE 'BO',
    c_region TYPE sofd-folrg VALUE 'B',
    c_typeid TYPE sibftypeid VALUE 'MESSAGE'.

  " Define Messages
  _bapi_message_data_definition.

  DATA:
    " Folder
    : gs_folder      TYPE soodk,

    " Link: Source & Target
    gs_object      TYPE sibflporb,
    gs_objtgt      TYPE sibflporb,

    " Document Basic data
    gs_doc_info    TYPE sofolenti1,
    gs_doc_data    TYPE sodocchgi1,
    gd_doc_type    TYPE soodk-objtp,
    "gv_reltype TYPE oblreltype,

    in_update_task TYPE sy-subrc,
    rc             TYPE sy-subrc,

    ls_return      TYPE bapiret2.

  IF reltype NE 'ATTA' AND reltype NE 'NOTE' AND reltype NE 'URL'.
    _bapi_message2 'No valid RELTYPE found.' '' '' ''.
    APPEND _bapi_return TO t_return.
    EXIT.
  ENDIF.

  IF reltype EQ 'NOTE' AND NOT align_note_text IS INITIAL.
    PERFORM align_note_text TABLES t_content_txt.
  ENDIF.

  IF NOT check_bo IS INITIAL.
    PERFORM check_entry_exist USING document busobject CHANGING rc.
    IF rc NE 0.
      CASE rc.
        WHEN 1 .
          _bapi_message1 'E' '60' '071'.
          APPEND _bapi_return TO t_return.
        WHEN 2.
          _bapi_message1 'E' 'KX' '069'.
          APPEND _bapi_return TO t_return.
        WHEN 3.
          _bapi_message1 'E' '5V' '076'.
          APPEND _bapi_return TO t_return.
        WHEN OTHERS.
      ENDCASE.

      EXIT.
    ENDIF.
  ENDIF.

  " Get Root-Folder
  CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
    EXPORTING
      region    = c_region
    IMPORTING
      folder_id = gs_folder.

  " Create document
  CLEAR  gs_doc_data .
  MOVE-CORRESPONDING s_doc_data TO gs_doc_data .
  CALL FUNCTION 'SO_DOCUMENT_INSERT_API1'
    EXPORTING
      folder_id      = gs_folder
      document_data  = gs_doc_data
      document_type  = s_doc_data-obj_type
    IMPORTING
      document_info  = gs_doc_info
    TABLES
      object_content = t_content_txt
      contents_hex   = t_content_hex.

  " Businessobject-ID remains
  gs_object-instid  = document.
  gs_object-typeid  = busobject.
  gs_object-catid   = c_catid.

  " Documentdata to Destination
  CONCATENATE gs_folder gs_doc_info-object_id
     INTO gs_objtgt-instid RESPECTING BLANKS.
  gs_objtgt-typeid  = c_typeid.
  gs_objtgt-catid   = c_catid.

  TRY.
      " Create Link

      cl_binary_relation=>create_link(
        EXPORTING
          is_object_a = gs_object
          is_object_b = gs_objtgt
          ip_reltype  = reltype ).

      CASE xcommit.
        WHEN '1'.
          COMMIT WORK AND WAIT.

        WHEN '2'.
          " see if we are in update task
          CALL FUNCTION 'TH_IN_UPDATE_TASK'
            IMPORTING
              in_update_task = in_update_task.

          IF in_update_task IS INITIAL.
            COMMIT WORK AND WAIT.
          ENDIF.

        WHEN OTHERS.
      ENDCASE.

    CATCH cx_obl_parameter_error cx_obl_model_error cx_obl_internal_error.
  ENDTRY.



ENDFUNCTION.

*&---------------------------------------------------------------------*
*&      Form  Check_entry_exist
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->DOCUMENT   text
*      -->BUSOBJECT  text
*      -->RC         text
*----------------------------------------------------------------------*
FORM check_entry_exist USING    document TYPE sibfboriid
                                busobject TYPE sibftypeid
                       CHANGING rc TYPE sy-subrc.

  DATA:
    l_bo_model_id TYPE rpybobs-objtype,
    t_keys        TYPE TABLE OF rpyboke,
    s_keys        TYPE rpyboke.

  DATA:
    t_dfies  TYPE TABLE OF dfies,
    t_dfies1 TYPE TABLE OF dfies,
    s_dfies  TYPE dfies,
    l_tab    TYPE ddobjname,
    l_field  TYPE dfies-fieldname,
    ls_sel   TYPE ddshselopt,
    lt_sel   TYPE TABLE OF ddshselopt,
    l_where  TYPE string,
    l_off    TYPE i.

  l_bo_model_id = busobject.

  CALL FUNCTION 'RPY_OBJECTTYPE_READ'
    EXPORTING
      objecttype_id                = l_bo_model_id
      language                     = sy-langu
      cico_mode                    = 'R'
      cico_request_no              = ' '
      with_verbs                   = 'X'
      with_parameters              = ' '
      with_exceptions              = ' '
      with_texts                   = ' '
      with_formatted_documentation = ' '
      with_sapscript_documentation = ' '
    TABLES
      keyfields                    = t_keys
    EXCEPTIONS
      not_found                    = 1
      permission_error             = 2
      OTHERS                       = 3.


  IF sy-subrc <> 0.
    rc = 1.
    EXIT.
  ENDIF.

  READ TABLE  t_keys INTO  s_keys INDEX 1.
  IF sy-subrc <> 0.
    rc = 2.
    EXIT.
  ENDIF.

  LOOP AT t_keys INTO s_keys.
    l_tab = s_keys-refstruct.
    l_field = s_keys-reffield.

    REFRESH t_dfies1.
    CALL FUNCTION 'DDIF_FIELDINFO_GET'
      EXPORTING
        tabname        = l_tab
        fieldname      = l_field
      TABLES
        dfies_tab      = t_dfies1
      EXCEPTIONS
        not_found      = 1
        internal_error = 2
        OTHERS         = 3.

    IF sy-subrc <> 0.
      rc = 1.
      EXIT.
    ENDIF.
    APPEND LINES OF t_dfies1 TO t_dfies.
  ENDLOOP.

  SORT t_dfies ASCENDING BY position.

  LOOP AT t_dfies INTO s_dfies.
    CLEAR ls_sel.
    ls_sel-shlpfield = s_dfies-fieldname.
    ls_sel-sign = 'I'.
    ls_sel-option = 'EQ'.
    ls_sel-low = document+l_off(s_dfies-leng).
    l_off = l_off + s_dfies-leng.
    APPEND ls_sel TO lt_sel.
  ENDLOOP.

  CALL FUNCTION 'F4_CONV_SELOPT_TO_WHERECLAUSE'
    IMPORTING
      where_clause = l_where
    TABLES
      selopt_tab   = lt_sel.

  SELECT SINGLE COUNT(*) FROM (l_tab) WHERE (l_where).
  rc = sy-subrc.

ENDFORM.                    "Check_entry_exist

*&---------------------------------------------------------------------*
*&      Form  ALIGN_NOTE_TEXT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM align_note_text TABLES t_content_txt STRUCTURE solisti1.
  DATA l_str TYPE string.
  DATA ls_contt TYPE solisti1.

  LOOP AT t_content_txt INTO ls_contt.
    IF sy-tabix > 1.
      CONCATENATE l_str
      ls_contt-line
      INTO l_str SEPARATED BY space.
    ELSE.
      CONCATENATE l_str
      ls_contt-line
      INTO l_str.
    ENDIF.
  ENDLOOP.

  REFRESH t_content_txt.
  CALL FUNCTION 'SCMS_STRING_TO_FTEXT'
    EXPORTING
      text      = l_str
    TABLES
      ftext_tab = t_content_txt.

ENDFORM.                    "ALIGN_NOTE_TEXT
Der Top include mit dem Makros:

Code: Alles auswählen.

FUNCTION-POOL ZGOSUTILS2.                    "MESSAGE-ID ..

DEFINE _bapi_message_data_definition.
  data:
         _mess1 type sy-msgv1,
         _mess2 type sy-msgv2,
         _mess3 type sy-msgv3,
         _mess4 type sy-msgv4,
         _bapi_return type BAPIRET2.
END-OF-DEFINITION.

* use Message from T100
DEFINE _bapi_message1.
  call function 'FS_BAPI_BAPIRET2_FILL'
    exporting
      type   = &1
      cl     = &2
      number = &3
    importing
      return = _bapi_return.
END-OF-DEFINITION.

* Free defined Message with up to 4 Parameters
DEFINE _bapi_message2.
  _mess1 = &1.
  _mess2 = &2.
  _mess3 = &3.
  _mess4 = &4.
  call function 'FS_BAPI_BAPIRET2_FILL'
    exporting
      type   = 'E'
      cl     = '00'
      number = '398'
      par1   =  _mess1
      par2   =  _mess2
      par3   =  _mess3
      par4   =  _mess4
    importing
      return = _bapi_return.
END-OF-DEFINITION.
und nun das Lesen von GOS-Dokumenten.

Code: Alles auswählen.

FUNCTION z_bc_read_attachment2.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(DOCUMENT) TYPE  SIBFBORIID
*"     VALUE(BUSOBJECT) TYPE  SIBFTYPEID
*"     VALUE(INSTID_B) TYPE  SIBFBORIID OPTIONAL
*"  EXPORTING
*"     VALUE(S_DOC_DATA) TYPE  SOFOLENTI1
*"  TABLES
*"      T_CONTENT_HEX STRUCTURE  SOLIX OPTIONAL
*"      T_CONTENT_TXT STRUCTURE  SOLISTI1 OPTIONAL
*"      T_RETURN STRUCTURE  BAPIRET2 OPTIONAL
*"----------------------------------------------------------------------
  CONSTANTS:
    c_catid     TYPE sibfcatid  VALUE 'BO',
    c_region    TYPE sofd-folrg VALUE 'B',
    c_typeid    TYPE sibftypeid VALUE 'MESSAGE',
    "c_reltyp TYPE oblreltype VALUE 'ATTA',
    c_role_type TYPE mdoblrol-roletype VALUE 'GOSAPPLOBJ'.

  TYPES:
    BEGIN OF gys_key,
      foltp     TYPE so_fol_tp,
      folyr     TYPE so_fol_yr,
      folno     TYPE so_fol_no,
      objtp     TYPE so_obj_tp,
      objyr     TYPE so_obj_yr,
      objno     TYPE so_obj_no,
      forwarder TYPE so_usr_nam,
    END OF gys_key.

  " Define Messages
  _bapi_message_data_definition.

  DATA:
    " key of Business-Objects
    gs_object TYPE sibflporb,

    " Link to Object
    gt_links  TYPE obl_t_link,
    gs_links  TYPE obl_s_link,

    " Link options
    gt_relopt TYPE obl_t_relt,
    gs_relopt TYPE obl_s_relt,

    " Key of Link
    gs_key    TYPE gys_key,

    " Document-ID
    gd_doc_id TYPE so_entryid.

  " Document content Text and Binary
*     ls_return TYPE bapiret2,
*     l_mess TYPE sy-msgv2.

  " Assign Businessobject-ID
  gs_object-instid  = document.
  gs_object-typeid  = busobject.
  gs_object-catid   = c_catid.

  " Link types:
  gs_relopt-sign = 'I'.
  gs_relopt-option = 'CP'.

  " Attachments
  gs_relopt-low = '*'.
  APPEND gs_relopt TO gt_relopt.

  TRY.
      " Read links to objects
      cl_binary_relation=>read_links_of_binrels(
        EXPORTING
          is_object           = gs_object
          it_relation_options = gt_relopt
          ip_role             = c_role_type
        IMPORTING
          et_links            = gt_links ).

      IF NOT instid_b IS INITIAL.
        DELETE gt_links WHERE instid_b NE instid_b.
      ENDIF.

      LOOP AT gt_links INTO gs_links WHERE typeid_b = c_typeid.

        gs_key = gs_links-instid_b.
        .
        " The document ID for SAPOffice is according to the instance ID
        gd_doc_id = gs_links-instid_b.

        " clear content
        CLEAR:t_content_txt, t_content_hex.

        " read document
        CALL FUNCTION 'SO_DOCUMENT_READ_API1'
          EXPORTING
            document_id                = gd_doc_id
          IMPORTING
            document_data              = s_doc_data
          TABLES
            object_content             = t_content_txt
            contents_hex               = t_content_hex
          EXCEPTIONS
            document_id_not_exist      = 1
            operation_no_authorization = 2
            x_error                    = 3
            OTHERS                     = 4.

        " In case that there is a link without content
        IF sy-subrc NE 0.
          _bapi_message2 gd_doc_id 'has no Data/Content' '' ''.
          APPEND _bapi_return TO t_return.
        ENDIF.

        EXIT. " only single document
      ENDLOOP.
    CATCH cx_obl_parameter_error cx_obl_internal_error cx_obl_model_error.
      " Error handling: Read links
  ENDTRY.

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

Code: Alles auswählen.

FUNCTION Z_BC_DELETE_ATTACHMENT2.
*"--------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(DOCUMENT) TYPE  SIBFBORIID
*"     VALUE(BUSOBJECT) TYPE  SIBFTYPEID
*"     VALUE(INSTID_B) TYPE  SIBFBORIID OPTIONAL
*"     VALUE(XCOMMIT) TYPE  CHAR01 DEFAULT '1'
*"  TABLES
*"      T_RETURN STRUCTURE  BAPIRET2 OPTIONAL
*"      T_DELETED_DATA STRUCTURE  SOFOLENTI1 OPTIONAL
*"--------------------------------------------------------------------
CONSTANTS:
  c_catid TYPE sibfcatid  VALUE 'BO',
  c_region TYPE sofd-folrg VALUE 'B',
  c_typeid  TYPE sibftypeid VALUE 'MESSAGE',
  c_role_type TYPE mdoblrol-roletype VALUE 'GOSAPPLOBJ'.

  TYPES:
      BEGIN OF gys_key,
        foltp TYPE so_fol_tp,
        folyr TYPE so_fol_yr,
        folno TYPE so_fol_no,
        objtp TYPE so_obj_tp,
        objyr TYPE so_obj_yr,
        objno TYPE so_obj_no,
        forwarder TYPE so_usr_nam,
      END OF gys_key.

  " Define Messages
  _bapi_message_data_definition.

  DATA:
      " key of Business-Objects
      gs_object   TYPE sibflporb,

      " Link to Object
     gt_links    TYPE obl_t_link,
     gs_links    TYPE obl_s_link,
     s_obj_a TYPE sibflporb,
     s_obj_b TYPE sibflporb,
     l_reltype TYPE oblreltype, " ATTA URL NOTE

      " Link options
     gt_relopt   TYPE obl_t_relt,
     gs_relopt   TYPE obl_s_relt,
     s_doc_data  TYPE  sofolenti1,

      " Key of Link
     gs_key      TYPE gys_key,

      " Document-ID
     gd_doc_id   TYPE so_entryid,

      " Document content Text and Binary
     ls_return TYPE bapiret2,
     in_update_task TYPE sy-subrc,
     l_rc TYPE sy-subrc.

  " Assign Businessobject-ID
  gs_object-instid  = document.
  gs_object-typeid  = busobject.
  gs_object-catid   = c_catid.

  " Link types:
  gs_relopt-sign = 'I'.
  gs_relopt-option = 'CP'.

  " Attachments
  gs_relopt-low = '*'.
  APPEND gs_relopt TO gt_relopt.


  REFRESH t_deleted_data.
  TRY.
      " Read links to objects
      cl_binary_relation=>read_links_of_binrels(
        EXPORTING
          is_object           = gs_object
          it_relation_options = gt_relopt
          ip_role             = c_role_type
        IMPORTING
          et_links            = gt_links ).

      IF NOT instid_b = 'ALL'.
        IF NOT instid_b IS INITIAL.
          DELETE gt_links WHERE instid_b NE instid_b.
          IF gt_links[] IS INITIAL.
            _bapi_message2 'No Links found.' '' '' ''.
            APPEND _bapi_return TO t_return.
            EXIT.
          ENDIF.
        ELSE.
          _bapi_message2 'No Key Parameter.' '' '' ''.
          APPEND _bapi_return TO t_return.
          EXIT.
        ENDIF.
      ENDIF.

      LOOP AT gt_links INTO gs_links WHERE typeid_b = c_typeid.

        gs_key = gs_links-instid_b.
        .
        " The document ID for SAPOffice is according to the instance ID
        gd_doc_id = gs_links-instid_b.

        " read document
        CALL FUNCTION 'SO_DOCUMENT_READ_API1'
          EXPORTING
            document_id                = gd_doc_id
          IMPORTING
            document_data              = s_doc_data
          EXCEPTIONS
            document_id_not_exist      = 1
            operation_no_authorization = 2
            x_error                    = 3
            OTHERS                     = 4.

        l_rc = sy-subrc.

        CASE l_rc.
          WHEN 0.
          WHEN 1.
            _bapi_message2 'SO_DOCUMENT_READ_API1' 'document_id_not_exist' '' ''.
            APPEND _bapi_return TO t_return.
          WHEN 2.
            _bapi_message2 'SO_DOCUMENT_READ_API1' 'operation_no_authorization' '' ''.
            APPEND _bapi_return TO t_return.
          WHEN OTHERS.
            _bapi_message2 'SO_DOCUMENT_READ_API1' 'unknown error' '' ''.
            APPEND _bapi_return TO t_return.
        ENDCASE.

        IF l_rc = 0.
          CALL FUNCTION 'SO_DOCUMENT_DELETE_API1'
            EXPORTING
              document_id                = gd_doc_id
              unread_delete              = 'X'
              put_in_trash               = ' '
            EXCEPTIONS
              document_not_exist         = 1
              operation_no_authorization = 2
              parameter_error            = 3
              x_error                    = 4
              enqueue_error              = 5
              OTHERS                     = 6.

          l_rc = sy-subrc.

          CASE l_rc.
            WHEN 0.
            WHEN 1.
              _bapi_message2 'SO_DOCUMENT_DELETE_API1' 'document_id_not_exist' '' ''.
              APPEND _bapi_return TO t_return.
            WHEN 2.
              _bapi_message2 'SO_DOCUMENT_DELETE_API1' 'operation_no_authorization' '' ''.
              APPEND _bapi_return TO t_return.
            WHEN 3.
              _bapi_message2 'SO_DOCUMENT_DELETE_API1' 'parameter_error' '' ''.
              APPEND _bapi_return TO t_return.
            WHEN 4.
              _bapi_message2 'SO_DOCUMENT_DELETE_API1' 'x_error' '' ''.
              APPEND _bapi_return TO t_return.
            WHEN 5.
              _bapi_message2 'SO_DOCUMENT_DELETE_API1' 'enqueue_error' '' ''.
              APPEND _bapi_return TO t_return.
            WHEN OTHERS.
              _bapi_message2 'SO_DOCUMENT_DELETE_API1' 'unknown error' '' ''.
              APPEND _bapi_return TO t_return.
          ENDCASE.

          IF l_rc = 0.
            s_obj_a-instid = gs_links-instid_a.
            s_obj_a-typeid = gs_links-typeid_a.
            s_obj_a-catid  = gs_links-catid_a.
            s_obj_b-instid = gs_links-instid_b.
            s_obj_b-typeid = gs_links-typeid_b.
            s_obj_b-catid  = gs_links-catid_b.
            l_reltype = gs_links-reltype.

            TRY.
                cl_binary_relation=>delete_link(
                  EXPORTING
                    is_object_a = s_obj_a
                    is_object_b = s_obj_b
                    ip_reltype  = l_reltype ).

                " remember deleted links
                APPEND s_doc_data TO t_deleted_data.

              CATCH cx_obl_parameter_error cx_obl_internal_error cx_obl_model_error.

            ENDTRY.

            CASE xcommit.
              WHEN '1'.
                COMMIT WORK AND WAIT.
              WHEN '2'.
                " see if we are in update task
                CALL FUNCTION 'TH_IN_UPDATE_TASK'
                  IMPORTING
                    in_update_task = in_update_task.

                IF in_update_task IS INITIAL.
                  COMMIT WORK AND WAIT.
                ENDIF.
              WHEN OTHERS.
            ENDCASE.

          ENDIF.

        ENDIF.

      ENDLOOP.
    CATCH cx_obl_parameter_error cx_obl_internal_error cx_obl_model_error.
      " Error handling: Read links
  ENDTRY.

ENDFUNCTION.

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

Code: Alles auswählen.

FUNCTION Z_BC_GOS_INFO2.
*"--------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(DOCUMENT) TYPE  SIBFBORIID
*"     VALUE(BUSOBJECT) TYPE  SIBFTYPEID
*"     VALUE(READ_KEYFIELDS) TYPE  XFELD DEFAULT 'X'
*"  TABLES
*"      T_LINKS STRUCTURE  OBL_S_LINK OPTIONAL
*"      T_RETURN STRUCTURE  BAPIRET2 OPTIONAL
*"      T_KEYFIELDS STRUCTURE  RPYBOKE OPTIONAL
*"--------------------------------------------------------------------
  CONSTANTS:
    c_catid     TYPE sibfcatid  VALUE 'BO',
    c_role_type TYPE mdoblrol-roletype VALUE 'GOSAPPLOBJ'.

  " Define Messages
  _bapi_message_data_definition.

  DATA:
    " Schlüssel des Business-Objekts
    gs_object  TYPE sibflporb,

    " Verknüpfungen zum Objekt
    gt_links   TYPE obl_t_link,
*     gs_links    TYPE obl_s_link,

    " Verknüpfungsoptionen
    gt_relopt  TYPE obl_t_relt,
    gs_relopt  TYPE obl_s_relt,
    lv_objtype TYPE rpybobs-objtype.


  " Businessobjekt-ID übernehmen
  gs_object-instid  = document.
  gs_object-typeid  = busobject.
  gs_object-catid   = c_catid.

  " Verknüpfungstypen:
  gs_relopt-sign = 'I'.
  gs_relopt-option = 'CP'.

  " Anhänge
  gs_relopt-low = '*'.

  APPEND gs_relopt TO gt_relopt.

  TRY.
      " Verknüpfungen zum Objekt lesen
      cl_binary_relation=>read_links_of_binrels(
        EXPORTING
          is_object           = gs_object
          it_relation_options = gt_relopt
          ip_role             = c_role_type
        IMPORTING
          et_links            = gt_links ).

      t_links[] = gt_links.

    CATCH cx_obl_parameter_error cx_obl_internal_error cx_obl_model_error.
  ENDTRY.


  IF gt_links[] IS INITIAL.
    _bapi_message2 'No Links found.for' busobject document ''.
    APPEND _bapi_return TO t_return.
  ENDIF.

  CHECK NOT read_keyfields IS INITIAL.

  lv_objtype = busobject.

  CALL FUNCTION 'RPY_OBJECTTYPE_READ'
    EXPORTING
      objecttype_id                = lv_objtype
      with_verbs                   = 'X'
      with_parameters              = ' '
      with_exceptions              = ' '
      with_texts                   = ' '
      with_formatted_documentation = ' '
      with_sapscript_documentation = ' '
    TABLES
      keyfields                    = t_keyfields
    EXCEPTIONS
      not_found                    = 1
      permission_error             = 2
      OTHERS                       = 3.
  IF sy-subrc <> 0.
    _bapi_message2 'No Keyfields found.for' lv_objtype '' ''.
    APPEND _bapi_return TO t_return.
  ENDIF.

ENDFUNCTION.
.Das Testprogramm:.

Code: Alles auswählen.

*&---------------------------------------------------------------------*
*& Report  Z_CREATE_GOS2
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  z_create_gos2.
DATA:
    " Dokumenten-Grunddaten
    gs_doc_info TYPE sofolenti1

    " Dokumenteninhalt binär
  , gt_contx    TYPE solix_tab

    " Dateiinformationen
  , gd_file     TYPE string
  , gd_flen     TYPE i
  .
PARAMETERS:
    " Eingabefelder für die ID des Business-Objekts
   p_instid    TYPE sibfboriid OBLIGATORY DEFAULT '0000000008',
   p_typeid    TYPE sibftypeid OBLIGATORY DEFAULT 'BUS2032',
   p_catid     TYPE sibfcatid  OBLIGATORY DEFAULT 'BO',
   p_file      TYPE ibipparms-path OBLIGATORY VISIBLE LENGTH 40 DEFAULT 'C:\temp\Test.pdf'.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

  CALL FUNCTION 'F4_FILENAME'
    EXPORTING
      program_name  = syst-cprog
      dynpro_number = syst-dynnr
      field_name    = 'P_FILE'
    IMPORTING
      file_name     = p_file.


START-OF-SELECTION.

  gd_file = p_file.

  " Datei hochladen
  CALL FUNCTION 'GUI_UPLOAD'
    EXPORTING
      filename   = gd_file
      filetype   = 'BIN'
    IMPORTING
      filelength = gd_flen
    TABLES
      data_tab   = gt_contx
    EXCEPTIONS
      OTHERS     = 1.


  DATA:
        doc_descr TYPE sodocchgi1-obj_descr VALUE 'Das ist ein Test',
        doc_name  TYPE sodocchgi1-obj_name VALUE 'Test.pdf'.
  DATA t_return TYPE TABLE OF bapiret2.



  gs_doc_info-obj_type = 'PDF'.
  gs_doc_info-doc_size = gd_flen.
  gs_doc_info-obj_descr = doc_descr.
  gs_doc_info-obj_name = doc_name.

  CALL FUNCTION 'Z_BC_CREATE_ATTACHMENT2'
    EXPORTING
      document   = p_instid
      busobject  = p_typeid
      RELTYPE    = 'ATTA'
      check_bo   = 'X'
      xcommit    = '2'
      s_doc_data = gs_doc_info
    TABLES
    t_content_hex = gt_contx
    t_return   = t_return.
. Testprogramm Create URL.

Code: Alles auswählen.

*&---------------------------------------------------------------------*
*& Report  Z_CREATE_GOS5
*&
*&---------------------------------------------------------------------*
*&
*& Create URL
*&---------------------------------------------------------------------*

REPORT  z_create_gos6.
DATA:
    " Dokumenten-Grunddaten
    s_doc_data TYPE sofolenti1

    " Dokumenteninhalt binär
  , gt_contt    TYPE TABLE OF solisti1
  , gs_contt    TYPE  solisti1
  , t_return    TYPE TABLE OF bapiret2
  .
PARAMETERS:
    " Eingabefelder für die ID des Business-Objekts
   p_insid1    TYPE sibfboriid OBLIGATORY DEFAULT '2130001978',
   p_typeid    TYPE sibftypeid OBLIGATORY DEFAULT 'BUS2032'.

s_doc_data-obj_name = p_insid1.
s_doc_data-obj_descr = 'Test with URL'.
s_doc_data-obj_langu = sy-langu.
s_doc_data-obj_type = 'URL'.
*s_doc_data-doc_size  MUST BE INITIAL !!!

REFRESH gt_contt.
gs_contt = '&KEY&https://www.abapforum.com/forum/'.
APPEND gs_contt TO gt_contt.

CALL FUNCTION 'Z_BC_CREATE_ATTACHMENT2'
  EXPORTING
    document   = p_insid1
    busobject  = p_typeid
    reltype    = 'URL'
*   CHECK_BO            = 'X'
*   XCOMMIT             = '1'
    s_doc_data          = s_doc_data
 TABLES
*   T_CONTENT_HEX       =
    t_content_txt       = gt_contt
    t_return            = t_return.
.. Anlegen NOTE.

Code: Alles auswählen.

*&---------------------------------------------------------------------*
*& Report  Z_CREATE_GOS5
*&
*&---------------------------------------------------------------------*
*&
*& Create NOTE
*&---------------------------------------------------------------------*

REPORT  z_create_gos5.
CONSTANTS _crlf(2) VALUE %_cr_lf.
DATA:
    " Dokumenten-Grunddaten
    s_doc_data TYPE sofolenti1

    " Dokumenteninhalt binär
  , gt_contt    TYPE TABLE OF solisti1
  , gs_contt    TYPE  solisti1
  , t_return    TYPE TABLE OF bapiret2
  .
PARAMETERS:
    " Eingabefelder für die ID des Business-Objekts
   p_insid1    TYPE sibfboriid OBLIGATORY DEFAULT '2130001978',
   p_typeid    TYPE sibftypeid OBLIGATORY DEFAULT 'BUS2032'.

s_doc_data-obj_name = p_insid1.
s_doc_data-obj_descr = 'Test with Note'.
s_doc_data-obj_langu = sy-langu.
*s_doc_data-doc_size  MUST BE INITIAL !!!
s_doc_data-obj_type = 'TXT'.

gs_contt-line = 'bei der Nutzung eines User-Exits möchte ich gewisse Schritte nur ausführen wenn sich Inhalte geändert haben'.
APPEND gs_contt TO gt_contt.
gs_contt-line = 'kenne es so, und so sind die internen Tabelle auch bezeichnet, dass in den Tabellen YVBPA etc. die Inhalte zum'.
APPEND gs_contt TO gt_contt.
gs_contt-line = 'Start der Transaktion befinden, in den Tabelle XVBPA etc. die aktuellen Belegdaten. Das System erkennt dann bei'.
APPEND gs_contt TO gt_contt.
gs_contt-line = 'Unterschieden zwischen z.B. XVBPA und YVBPA ob sich Inhalte geändert haben und der Beleg gespeichert werden'.
APPEND gs_contt TO gt_contt.
gs_contt-line = 'Leider sind die Tabellen YVBPA etc. leer. Wie kann ich erkennen ob sich z.B. der WE oder die Materialnummer'.
APPEND gs_contt TO gt_contt.




CALL FUNCTION 'Z_BC_CREATE_ATTACHMENT2'
  EXPORTING
    document   = p_insid1
    busobject  = p_typeid
    RELTYPE    = 'NOTE'
*   CHECK_BO            = 'X'
*   XCOMMIT             = '1'
    s_doc_data          = s_doc_data
 TABLES
*   T_CONTENT_HEX       =
    t_content_txt       = gt_contt
    t_return            = t_return.
.gruß Jens.

Folgende Benutzer bedankten sich beim Autor Tron für den Beitrag (Insgesamt 4):
black_adeptewxJandeejey

<:: XING-Gruppe Tricktresor::>
Die deutsche Rechtschreibung ist Freeware, du darfst sie kostenlos nutzen –
Aber sie ist nicht Open Source, d. h. du darfst sie nicht verändern oder in veränderter Form veröffentlichen.

gesponsert
Stellenangebote auf ABAPforum.com schalten
kostenfrei für Ausbildungsberufe und Werksstudenten


Seite 1 von 1

Vergleichbare Themen

1
Antw.
4747
Views
Anlagen ohne Spur löschen
von alicemal » 19.01.2009 18:15 • Verfasst in Financials
3
Antw.
1717
Views
Excel Serverseitig lesen/schreiben?!?
von Kriskra » 01.04.2005 07:48 • Verfasst in ABAP® Core
4
Antw.
2638
Views
Excel von einer BSP aus Lesen/Schreiben!?!
von Kriskra » 01.04.2005 07:45 • Verfasst in Web-Dynpro, BSP + BHTML
0
Antw.
1521
Views
1
Antw.
7778
Views
Unterschied: Sequentielles lesen, direktes lesen
von MarkusW » 07.08.2008 16:46 • Verfasst in ABAP® für Anfänger

Über diesen Beitrag

Tron

Unterstütze die Community und teile den Beitrag für mehr Leser und Austausch

Newsletter Anmeldung

Keine Beiträge verpassen! Wöchentlich versenden wir lesenwerte Beiträge aus unserer Community.
Die letzte Ausgabe findest du hier.
Details zum Versandverfahren und zu Ihren Widerrufsmöglichkeiten findest du in unserer Datenschutzerklärung.

Unbeantwortete Forenbeiträge

aRFC im OO-Kontext
vor 4 Wochen von ralf.wenzel 1 / 1661
Hilfe bei SWEC/SWE2
letzen Monat von retsch 1 / 8263