MUNDOSAP

MUNDOSAP (foro/index.php)
-   Programación ABAP IV (foro/forumdisplay.php?f=4)
-   -   Anexar attachment a candidatos (foro/showthread.php?t=8090)

HRU 02/10/07 09:08:53

Anexar attachment a candidatos
 
Hola, necesito anexar attachments a candidatos(PB30) en modo background (no puede ser en dialogo con la ventana). He probado con la función ARCHIV_CREATE_FILE y con la SO_ATTACHMENT_INSERT pero el resultado ha sido negativo. Alguien ha podido hacer esto??.

Gracias!!!

HRU 02/10/07 15:07:19

Respuesta
 
Al final encontre como hacerlo lo dejo aqui por si le interesa a alguien:

* clases necesarias
CLASS cl_binary_relation DEFINITION LOAD.
CLASS cl_obl_object DEFINITION LOAD.



DATA:
p_botype LIKE obl_s_pbor-typeid VALUE 'APPLICANT',"en otro caso puede
" ser otro tipo de objeto
p_bo_id LIKE obl_s_pbor-instid,
pc_file(128),
* Object_b
p_docty LIKE borident-objtype VALUE 'MESSAGE',
p_reltyp LIKE breltyp-reltype VALUE 'ATTA',"puede ser otro tipo
p_msgtyp LIKE sofm-doctp VALUE 'EXT'."puede ser otro tipo


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.
TYPES : BEGIN OF ty_binary,
binary_field(255) TYPE c,
END OF ty_binary.
DATA : lt_binary TYPE TABLE OF ty_binary WITH HEADER LINE,
wa_binary TYPE ty_binary.
DATA : lv_message_key TYPE ty_message_key.
DATA : lo_message TYPE swc_object.
DATA : lt_doc_content TYPE STANDARD TABLE OF soli-line WITH HEADER LINE.
DATA: listobject LIKE abaplist OCCURS 1 WITH HEADER LINE.
DATA: lv_doc_size TYPE i.
DATA: filesize TYPE so_doc_len.
DATA: l_file_lines TYPE i.
DATA help_objcont LIKE soli OCCURS 0 WITH HEADER LINE.
DATA file_type LIKE rlgrap-filetype.
DATA act_filetype LIKE rlgrap-filetype.
DATA act_filename LIKE rlgrap-filename.
DATA h_filename LIKE rlgrap-filename.
DATA doc_length LIKE soxwd-doc_length.
DATA def_filename(12).
DATA:filestring TYPE xstring.
DATA: object_hd_display LIKE sood2,
l_filename TYPE string,
l_title(60) TYPE c.


pc_file = <guardamos fila a subir>.
CONCATENATE 'Curriculum' g_aplno INTO l_title."titulo con el que se guardar
p_msgtyp = 'DOC'.
p_bo_id = <id del objeto en el cual anexaremos el attachemtn>.
DO 2 TIMES.
* 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' l_title.
swc_set_element lt_message_container 'DOCUMENTLANGU' 'E'.
swc_set_element lt_message_container 'NO_DIALOG' 'X'.
swc_set_element lt_message_container 'DOCUMENTNAME' p_docty.
swc_set_element lt_message_container 'DOCUMENTTYPE' p_msgtyp.
swc_set_element lt_message_container 'FILEEXTENSION' 'DOC'.
* 'DocumentContent' is a multi-line element ( itab ).


* In case of URLs..it should be concatenated with &KEY& in the begining.
CASE p_msgtyp.
WHEN 'URL'.
* In case of Notes or Private Notes, get the data from files on appl
* server or from wherever(? - remember background).
WHEN 'RAW'.

* In case of File attachments
WHEN 'OTHERS'.
*************************
* open dataset p_fname for input in binarymode.
*OPEN DATASET PC_FILE FOR INPUT IN BINARY MODE.
*READ DATASET PC_FILE INTO FILESTRING.
*CLOSE DATASET PC_FILE.
ENDCASE.
* CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
* EXPORTING
* buffer = filestring
** APPEND_TO_TABLE = ' '
* IMPORTING
* output_length = lv_doc_size
* TABLES
* binary_tab = lt_binary
.
* swc_set_table lt_message_container 'DocumentContent' lt_binary.

l_filename = pc_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = l_filename
filetype = 'BIN'
TABLES
data_tab = lt_doc_content.

DESCRIBE TABLE lt_doc_content LINES l_file_lines.

READ TABLE lt_doc_content INDEX l_file_lines.

lv_doc_size = ( 255 * ( l_file_lines - 1 ) ) +
STRLEN( lt_doc_content ).

swc_set_table lt_message_container 'DocumentContent' lt_doc_content.
swc_set_element lt_message_container 'DOCUMENTSIZE' lv_doc_size.
swc_refresh_object lo_message.
swc_call_method lo_message 'CREATE' lt_message_container.
* Refresh to get the reference of create 'MESSAGE' object for attachment
* swc_refresh_object lo_message.
* 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 = p_bo_id.
lo_is_object_a-objtype = p_botype.
* 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 = p_docty.

CALL FUNCTION 'BINARY_RELATION_CREATE'
EXPORTING
obj_rolea = lo_is_object_a
obj_roleb = lo_is_object_b
relationtype = p_reltyp
EXCEPTIONS
OTHERS = 1.

COMMIT WORK AND WAIT.

Saludos


Husos Horarios son GMT. La hora en este momento es 04:49:12.

www.mundosap.com 2006 - Spain
software crm, crm on demand, software call center, crm act, crm solutions, crm gratis, crm web