Inicio > ABAP/4 > GOS – Crear Anexo/URL en MIR7/MIRO

GOS – Crear Anexo/URL en MIR7/MIRO

Caso: Se desea grabar una URL en documentos factura de la MIR7 o MIRO, utilizando la función del botón GOS (Generic Object Services).

Solución: obtenido del blog que indico abajo, definimos una función que contiene la lógica.

1. Ingresar a la SE37 y crear la función:

FUNCTION zbc_gos_create_url.
*"----------------------------------------------------------------------
*"*"Interfase local
*"  IMPORTING
*"     REFERENCE(I_OBJECTTYPE) LIKE  BORIDENT-OBJTYPE
*"     REFERENCE(I_OBJECTKEY) LIKE  BORIDENT-OBJKEY
*"     REFERENCE(I_URL) LIKE  SOLI-LINE
*"     REFERENCE(I_URLDES) LIKE  SOOD1-OBJDES
*"     REFERENCE(I_NOCOMMIT) TYPE  XFELD
*"  TABLES
*"      OT_RETURN STRUCTURE  BAPIRET2
*"----------------------------------------------------------------------
*
*local data definitions.
  DATA: l_owner         LIKE      soud-usrnam,
        l_folderid      LIKE      soodk,
        l_obj_id        LIKE      soodk,
        l_objdata       LIKE      sood1,
        lt_objcont      TYPE TABLE OF soli WITH HEADER LINE,
        lt_objhead      TYPE TABLE OF soli WITH HEADER LINE,
        l_object        LIKE     borident,
        l_reldoc        LIKE     borident,
        l_syst          LIKE     syst.
*-----------------------------------------------------------------------
*
*1.GET folder id.
  l_owner = sy-uname.
  CALL FUNCTION 'SO_FOLDER_ROOT_ID_GET'
    EXPORTING
      owner                 = l_owner
      region                = 'B'
    IMPORTING
      folder_id             = l_folderid
    EXCEPTIONS
      communication_failure = 1
      owner_not_exist       = 2
      system_failure        = 3
      x_error               = 4
      OTHERS                = 5.
  IF sy-subrc <> 0.
    l_syst = syst.
    PERFORM collect_message USING ot_return l_syst '1.FolderRoot'.
    APPEND ot_return.
    EXIT.
  ENDIF.
 
*2. INSERT object
 
  l_objdata-objla     = sy-langu.
  l_objdata-objdes    = i_urldes.
  l_objdata-objsns    = 'O'.
 
  CONCATENATE '&KEY&' i_url INTO lt_objcont.
  APPEND lt_objcont.
 
  CALL FUNCTION 'SO_OBJECT_INSERT'
    EXPORTING
      folder_id                  = l_folderid
      object_type                = 'URL'
      object_hd_change           = l_objdata
      owner                      = l_owner
    IMPORTING
      object_id                  = l_obj_id
    TABLES
      objcont                    = lt_objcont
      objhead                    = lt_objhead
    EXCEPTIONS
      active_user_not_exist      = 1
      communication_failure      = 2
      component_not_available    = 3
      dl_name_exist              = 4
      folder_not_exist           = 5
      folder_no_authorization    = 6
      object_type_not_exist      = 7
      operation_no_authorization = 8
      owner_not_exist            = 9
      parameter_error            = 10
      substitute_not_active      = 11
      substitute_not_defined     = 12
      system_failure             = 13
      x_error                    = 14
      OTHERS                     = 15.
  IF sy-subrc <> 0.
    l_syst = syst.
    PERFORM collect_message USING ot_return l_syst '2.ObjectInsert'.
    APPEND ot_return.
    EXIT.
  ENDIF.
 
*3. CREATE binary relation
  l_object-objkey  = i_objectkey.
  l_object-objtype = i_objecttype.
 
  CONCATENATE l_folderid l_obj_id INTO l_reldoc-objkey.
  l_reldoc-objtype = 'MESSAGE'.
 
  CALL FUNCTION 'BINARY_RELATION_CREATE'
    EXPORTING
      obj_rolea      = l_object
      obj_roleb      = l_reldoc
      relationtype   = 'URL'
    EXCEPTIONS
      no_model       = 1
      internal_error = 2
      unknown        = 3
      OTHERS         = 4.
  IF sy-subrc <> 0.
    l_syst = syst.
    PERFORM collect_message USING ot_return l_syst
    '3.BinaryRelationCreate'.
    APPEND ot_return.
    EXIT.
  ENDIF.
 
*4. commit luw
*   all successful, sent success message.
 
  CLEAR: l_syst-msgid, l_syst-msgno.
  l_syst-msgty = 'S'.
  l_syst-msgv1 = 'Like creado OK'.
 
  PERFORM collect_message USING ot_return l_syst '4. URLLinkCreated'.
  APPEND ot_return.
  IF i_nocommit IS INITIAL.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
  ENDIF.
 
ENDFUNCTION.
  1. Creamos un include en el grupo de funciones donde creamos la función y agregamos la visualización del mensaje:
*----------------------------------------------------------------------*
***INCLUDE LZMM_FACT_PROVEEDORESF01 .
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Form  COLLECT_MESSAGE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
 FORM collect_message USING o_return LIKE bapiret2
                            i_syst LIKE syst
                            i_callpoint LIKE bapiret2-parameter.
*
   CLEAR o_return.
   o_return-type   = i_syst-msgty.
   IF i_syst-msgty IS INITIAL.
     o_return-type = 'E'.
     i_syst-msgty      = 'E'.
   ENDIF.
   o_return-id     = i_syst-msgid.
   o_return-number = i_syst-msgno.
   o_return-message_v1    = i_syst-msgv1.
   o_return-message_v2    = i_syst-msgv2.
   o_return-message_v3    = i_syst-msgv3.
   o_return-message_v4    = i_syst-msgv4.
 
   o_return-parameter = i_callpoint.
 
   MESSAGE ID i_syst-msgid TYPE i_syst-msgty NUMBER i_syst-msgno INTO
   o_return-message.
*
 ENDFORM.                    " collect_message
  1. Finalmente la llamada es:

 

*&---------------------------------------------------------------------*
*&      Form  CREAR_URL_ADJUNTA
*&---------------------------------------------------------------------*
*       Crea la URL para cada uno de los registros procesados
*----------------------------------------------------------------------*
FORM crear_url_adjunta.
 
  DATA: lv_objecttype   LIKE borident-objtype,
        lv_objectkey    LIKE borident-objkey,
        lv_url          LIKE soli-line,
        lv_urldes       LIKE sood1-objdes,
        lv_nocommit     TYPE xfeld,
        lt_return       LIKE bapiret2 OCCURS 0,
        l_url           TYPE smen_buffi-url.
 
* The object type is the same as you are used to in SWO1 (BKPF for FI documents, BUS2081 for incoming invoices (MIROs), BUS2012 for POs and so on.
* The object key is the full key of the object (For FI  documents, it is the document, company code and year)
* The URL is the actual URL that you wish to attach.
* The URL description is the name for the URL you see when you display attachments of the object.
* The last input parameter controls whether you wish to commit( blank) or not(X).
* Messages are returned in tables parameter OT_RETURN.
    lv_objecttype = 'BUS2081'.  
    CONCATENATE lv_belnr lv_gjahr INTO lv_objectkey.
    lv_url          = 'www.sap.com'. " URL
    CONCATENATE 'FACTURA #' lv_belnr lv_gjahr INTO lv_urldes SEPARATED BY space.
 
    lv_nocommit = space.
 
    CALL FUNCTION 'ZBC_GOS_CREATE_URL'
      EXPORTING
        i_objecttype = lv_objecttype
        i_objectkey  = lv_objectkey
        i_url        = lv_url
        i_urldes     = lv_urldes
        i_nocommit   = lv_nocommit
      TABLES
        ot_return    = lt_return.
 
ENDFORM.                    " CREAR_URL_ADJUNTA

4. En la MIR7, podemos ver el resultado del link agregado:

attc1c2c

attc1c2c

 

Fuente: http://subrc0.wordpress.com/2012/11/13/gos-adding-an-external-link-to-an-object/

  1. Bharath
    08/06/2016 a las 10:42

    I used same process to attach PDF.. but every time it is appending new PDF.. bu I want to overwrite the same PDF. can you please provide related code?

    • 08/06/2016 a las 11:25

      Hi Bharath, I think that you must use SO_OBJECT_UPDATE to this issue, not SO_OBJECT_INSERT, or SO_OBJECT_INSERT only the first time.

  1. No trackbacks yet.

Responder

Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de WordPress.com

Estás comentando usando tu cuenta de WordPress.com. Cerrar sesión / Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión / Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión / Cambiar )

Google+ photo

Estás comentando usando tu cuenta de Google+. Cerrar sesión / Cambiar )

Conectando a %s

A %d blogueros les gusta esto: