10-04-2005 4:39 PM
Hi,
I'm trying to send an itab using the function-module SO_NEW_DOCUMENT_ATT_SEND_API1.
I already know how to use this function module and how to add attachements.
Now I want to create an attachement from an internal table (maybe even with a little formatting, for example the column-names), but I'm not sure how to do that.
Any suggestions? Thanks in advance,
Regards
Jan Hempel
10-04-2005 5:12 PM
You just need to have your internal table defined in the format you want. For Example you want Material No / Description as two columns with headers in your TEXT attachment.
DATA : BEGIN OF ITAB OCCURS 0 ,
MATNR (30),
MAKTX(50),
END OF ITAB.
ITAB-MATNR = 'MATERIAL'.
ITAB-MAKTX = 'DESCRIPTION'.
APPEND ITAB.
....
....
Populate Itab with various Material Num & Description.
...
...
Loop at itab.
move itab to objbin.
append objbin.
endloop.
Now use OBJBIN in the FM SO_NEW_DOCUMENT_ATT_SEND_API1.
Cheers
10-04-2005 5:12 PM
You just need to have your internal table defined in the format you want. For Example you want Material No / Description as two columns with headers in your TEXT attachment.
DATA : BEGIN OF ITAB OCCURS 0 ,
MATNR (30),
MAKTX(50),
END OF ITAB.
ITAB-MATNR = 'MATERIAL'.
ITAB-MAKTX = 'DESCRIPTION'.
APPEND ITAB.
....
....
Populate Itab with various Material Num & Description.
...
...
Loop at itab.
move itab to objbin.
append objbin.
endloop.
Now use OBJBIN in the FM SO_NEW_DOCUMENT_ATT_SEND_API1.
Cheers
10-06-2005 10:01 AM
Hi,
I tried what You recommended, but I wanted a solution, where the user can view the table inside of the SAP-Office. After a bit of trial and error I found the following solution:
I call a "helper-program" which is displaying the table as a ALV (so it is formated nicely, with header etc.). I'm calling this program using "SUBMIT ... EXPORTING LIST TO MEMORY AND RETURN". By doing this, the ALV is not actually displayed but exported to memory (guess that...). I then use the function modules LIST_FROM_MEMORY and TABLE_COMPRESS to get the table from memory and convert it into the format needed by SO_NEW_DOCUMENT_ATT_SEND_API1. As document-type for the attachement I can now use ALI (abap-list), which can be viewed inside SAP-Office.
This is the code I used, in case somebody is interested:
* put table as alv into memory using an external program:
EXPORT table_xyz TO MEMORY ID 'ITAB'.
SUBMIT z_alv_helper EXPORTING LIST TO MEMORY AND RETURN.
* import formated table from memory:
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = lt_listobject
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE s035(zsd).
ENDIF.
* compress table to linesize of 255
CALL FUNCTION 'TABLE_COMPRESS'
TABLES
in = lt_listobject
out = i_contents_bin
EXCEPTIONS
compress_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE s035(zsd).
ENDIF.
* build packlist for attachement
DESCRIBE TABLE i_contents_bin LINES h_lines_bin.
READ TABLE i_contents_bin INTO w_contents_bin INDEX h_lines_bin.
w_packlist-transf_bin = 'X'.
w_packlist-head_start = 1.
w_packlist-head_num = 0.
w_packlist-body_start = 1.
w_packlist-body_num = h_lines_bin.
w_packlist-doc_type = 'ALI'.
w_packlist-doc_size = ( h_lines_bin - 1 ) * 255 + STRLEN( w_contents_bin ).
w_packlist-obj_name = 'ATTACHEMENT'.
w_packlist-obj_descr = text-030.
APPEND w_packlist TO i_packlist.
* send mail
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = w_docdata
put_in_outbox = 'X'
commit_work = 'X'
IMPORTING
sent_to_all = h_sent_to_all
TABLES
packing_list = i_packlist
contents_bin = i_contents_bin
contents_txt = i_contents_txt
receivers = i_reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
And here the code for the external "helper-program":
DATA: table_xyz TYPE TABLE OF zstructure_xyz.
IMPORT table_xyz FROM MEMORY ID 'ITAB'.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_structure_name = 'ZSTRUCTURE_XYZ'
TABLES
t_outtab = table_xyz.
regards
Jan Hempel