#1
|
|||
|
|||
Convertir factura a PDF y anexarla al documento VBRK
A quien pueda ayudarme:
Como parte del proceso de facturación, creo un documento PDF con una copia de la factura (generada desde smartofrms), el siguiente paso es anexarlo al documento factura (VBRK). En principio, ambos pasos funcionan tengo un PDF correcto donde he pedido y un anexo en la lista de anexos (GOS) de la factura, pero al pulsar en el GOS para abrirlo con el ACROBAT se produce un error porque busca un archivo PDF corrupto y con un nombre parecido en c:\.. ..sapworkdir !!!. Esta es la parte del código que genera el PDF en local: _______________________________________________________ FORM convert_to_pdf. * Convert to PDF ... CALL FUNCTION 'CONVERT_OTF' EXPORTING format = 'PDF' IMPORTING bin_filesize = lv_doc_size TABLES otf = ls_job_info-otfdata lines = lines EXCEPTIONS err_conv_not_possible = 1 err_bad_otf = 2. * Download to your PC ... CONCATENATE 'C:\TEMP\' vbeln '.pdf' INTO file. CALL FUNCTION 'GUI_DOWNLOAD' EXPORTING bin_filesize = lv_doc_size filename = file filetype = 'BIN' TABLES data_tab = lines[]. IF sy-subrc = 0. MESSAGE 'Descarga completada normalmente' TYPE 'S'. ENDIF. ENDFORM. "convert_to_pdf _______________________________________________________ Esta es la parte del código anexa el PDF a la factura: _______________________________________________________ FORM crear_anexo. * Include for BO macros INCLUDE : <cntn01>. * Load class. CLASS cl_binary_relation DEFINITION LOAD. CLASS cl_obl_object DEFINITION LOAD. TYPES: BEGIN OF ty_message_key, foltp TYPE so_fol_tp, folyr TYPE so_fol_yr, folno TYPE so_fol_no, doctp TYPE so_doc_tp, docyr TYPE so_doc_yr, docno TYPE so_doc_no, fortp TYPE so_for_tp, foryr TYPE so_for_yr, forno TYPE so_for_no, END OF ty_message_key. DATA : lv_message_key TYPE ty_message_key. DATA : lo_message TYPE swc_object. DATA : p_reltyp LIKE mdoblrel-reltype. DATA : lv_title TYPE string. * First derive the Attachment's ( MESSAGE ) document type. p_reltyp = 'ATTA'. CONCATENATE 'Copia factura nº: ' vbeln INTO lv_title SEPARATED BY space. * Create an initial instance of BO 'MESSAGE' - to call the * instance-independent method 'Create'. swc_create_object lo_message 'MESSAGE' lv_message_key. * define container to pass the parameter values to the method call * in next step. swc_container lt_message_container. * Populate container with parameters for method swc_set_element lt_message_container 'DOCUMENTTITLE' vbeln. swc_set_element lt_message_container 'DOCUMENTLANGU' 'S'. swc_set_element lt_message_container 'NO_DIALOG' 'X'. swc_set_element lt_message_container 'DOCUMENTPATH' 'C:\TEMP\'. swc_set_element lt_message_container 'DOCUMENTNAME' vbeln. swc_set_element lt_message_container 'DOCUMENTTYPE' 'PDF'. swc_set_element lt_message_container 'DOCUMENTSIZE' lv_doc_size. swc_set_element lt_message_container 'FILEEXTENSION' 'pdf'. swc_set_element lt_message_container 'LinkAttachement' lo_message. swc_set_table lt_message_container 'DocumentContent' ls_job_info-otfdata[]. * Refresh to get the reference of create 'MESSAGE' object for attachment swc_refresh_object lo_message. swc_call_method lo_message 'CREATE' lt_message_container. * Get Key of new object swc_get_object_key lo_message lv_message_key. * Now we have attachment as a business object instance. We can now * attach it to our main business object instance. * Create main BO object_a DATA: lo_is_object_a TYPE borident. lo_is_object_a-objkey = vbeln. lo_is_object_a-objtype = 'VBRK'. * Create attachment BO object_b DATA: lo_is_object_b TYPE borident. lo_is_object_b-objkey = lv_message_key. lo_is_object_b-objtype = 'MESSAGE'. DATA x_reltyp LIKE breltyp-reltype VALUE 'ATTA'. CALL FUNCTION 'BINARY_RELATION_CREATE' EXPORTING obj_rolea = lo_is_object_a obj_roleb = lo_is_object_b relationtype = x_reltyp EXCEPTIONS OTHERS = 1. ENDFORM. "crear_anexo _______________________________________________________ He realizado numerosas pruebas modificando los valores de lt_message_container pero no he conseguido que el documento anexado sea el que he creado en el primer paso. Evidentemente hay algo que no estoy haciendo bien pero no sé verlo. Por favor, alguien puede ofrecerme una pista. Muchas gracias por anticipado |
Herramientas | Buscar en Tema |
Desplegado | |
|
|