2007 Apr 09 8:18 AM
Hi ,
I am sending excel attachment through email .
This excel attachment is generated from an ALV Grid Output .
The excel file has all columns fixed to its initial length due to which the entire column content isnt visible unless its extended at the time of checking its content .
Can anyone suggest a remedy to this or send any code which can be used to read the Grid Output and Convert into excel sheet ?
Thanks and Regards
Soumyadip Pal
Hi ,
I am sending excel attachment through email .
This excel attachment is generated from an ALV Grid Output .
The excel file has all columns fixed to its initial length due to which the entire column content isnt visible unless its extended at the time of checking its content .
Can anyone suggest a remedy to this or send any code which can be used to read the Grid Output and Convert into excel sheet ?
Thanks and Regards
Soumyadip Pal
2007 Apr 09 8:21 AM
Try passing the following parameter for layout in ALV
G_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
2007 Apr 09 8:22 AM
https://forums.sdn.sap.com/click.jspa?searchID=1994815&messageID=2919787
check the above link where they discussed about this similar problem
Dont forget to award points if found helpful
DATA: column TYPE ole2_object.
CALL METHOD OF h_excel 'Columns' = column NO FLUSH.
FREE OBJECT h_excel NO FLUSH.
CALL METHOD OF column 'Autofit' NO FLUSH.
FREE OBJECT column NO FLUSH.
2007 Apr 09 10:03 AM
hi
try using ALV_DISPLAY_BASIC_LIST.
Pl. award appropriate points.
regards
ravish
2007 Apr 09 10:09 AM
Hi Soumyadip Pal,
Check this code.
REPORT z_email_abap_report.
----
E-mail an Abap report *
----
DATA : w_name TYPE sos04-l_adr_name.
SELECT-OPTIONS :
Recipient address
s_name FOR w_name DEFAULT sy-uname NO INTERVALS.
----
START-OF-SELECTION.
E-mail Abap report
PERFORM f_send_mail.
----
Form f_send_mail
----
FORM f_send_mail.
Data Declaration
DATA:
l_datum(10),
ls_docdata TYPE sodocchgi1,
lt_objpack TYPE TABLE OF sopcklsti1 WITH HEADER LINE,
lt_objhead TYPE TABLE OF solisti1 WITH HEADER LINE,
lt_objtxt TYPE TABLE OF solisti1 WITH HEADER LINE,
lt_objbin TYPE TABLE OF solisti1 WITH HEADER LINE,
lt_reclist TYPE TABLE OF somlreci1 WITH HEADER LINE,
lt_listobject TYPE TABLE OF abaplist WITH HEADER LINE,
l_tab_lines TYPE i,
l_att_type LIKE soodk-objtp.
WRITE sy-datum TO l_datum.
List of Users According to Logon Date and Password Change
NOTE: Create ALI/OTF Document in Spool
SUBMIT rsusr200 WITH valid = 'X'
WITH notvalid = space
WITH unlocked = 'X'
WITH locked = space
EXPORTING LIST TO MEMORY AND RETURN.
Read list from memory into table
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = lt_listobject
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
Error in function module &1
MESSAGE ID '61' TYPE 'E' NUMBER '731'
WITH 'LIST_FROM_MEMORY'.
ENDIF.
Because listobject is of size RAW(1000)
and objbin is of size CHAR(255) we make this table copy
CALL FUNCTION 'TABLE_COMPRESS'
TABLES
in = lt_listobject
out = lt_objbin
EXCEPTIONS
compress_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
Error in function module &1
MESSAGE ID '61' TYPE 'E' NUMBER '731'
WITH 'TABLE_COMPRESS'.
ENDIF.
NOTE: Creation of attachment is finished yet.
For your report, the attachment should be placed into table
objtxt for plain text or
objbin for binary content.
Now create the message and send the document.
Create Message Body
Title and Description
ls_docdata-obj_name = 'USERS_LIST'.
CONCATENATE 'List of Users' sy-sysid '-' l_datum "#EC *
INTO ls_docdata-obj_descr SEPARATED BY space.
Main Text
lt_objtxt = 'List of Users According to Logon Date' &
' and Password Change'. "#EC *
APPEND lt_objtxt.
Write Packing List (Main)
DESCRIBE TABLE lt_objtxt LINES l_tab_lines.
READ TABLE lt_objtxt INDEX l_tab_lines.
ls_docdata-doc_size = ( l_tab_lines - 1 ) * 255 + STRLEN( lt_objtxt ).
CLEAR lt_objpack-transf_bin.
lt_objpack-head_start = 1.
lt_objpack-head_num = 0.
lt_objpack-body_start = 1.
lt_objpack-body_num = l_tab_lines.
lt_objpack-doc_type = 'RAW'.
APPEND lt_objpack.
Create Message Attachment
Write Packing List (Attachment)
l_att_type = 'ALI'.
DESCRIBE TABLE lt_objbin LINES l_tab_lines.
READ TABLE lt_objbin INDEX l_tab_lines.
lt_objpack-doc_size = ( l_tab_lines - 1 ) * 255 + STRLEN( lt_objbin ).
lt_objpack-transf_bin = 'X'.
lt_objpack-head_start = 1.
lt_objpack-head_num = 0.
lt_objpack-body_start = 1.
lt_objpack-body_num = l_tab_lines.
lt_objpack-doc_type = l_att_type.
lt_objpack-obj_name = 'ATTACHMENT'.
lt_objpack-obj_descr = 'List_of_Users'. "#EC *
APPEND lt_objpack.
Create receiver list
LOOP AT s_name.
lt_reclist-receiver = s_name-low.
lt_reclist-rec_type = 'B'.
APPEND lt_reclist.
ENDLOOP.
Send Message
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = ls_docdata
put_in_outbox = ''
TABLES
packing_list = lt_objpack
object_header = lt_objhead
contents_bin = lt_objbin
contents_txt = lt_objtxt
receivers = lt_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.
IF sy-subrc = 0.
Document sent
MESSAGE ID 'SO' TYPE 'S' NUMBER '022'.
ELSE.
Document <&> could not be sent
MESSAGE ID 'SO' TYPE 'S' NUMBER '023'
WITH ls_docdata-obj_name.
ENDIF.
ENDFORM. " F_SEND_MAIL
END OF PROGRAM Z_EMAIL_ABAP_REPORT ******************
Hope this resolves your query.
Reward all the helpful answers.
Regards
2007 Apr 09 10:11 AM
Hi,
If u r using the FM <b>"REUSE_ALV_GRID_DISPLAY"</b>,
try using the following parameter:
wa_fieldcat-outputlen = 'X'.
wa_fieldcat-intlen = 'X'.
wa_fieldcat is of type SLIS_FIELDCAT_ALV.
Hope this helps u.
regards,
Thasneem
2007 Apr 09 10:23 AM
Hi,
Which function module are u using to generate the internal table for sending the attachment?.Bcoz the field length depends on the generated internal table.
Thanks
Ahasan
2007 Apr 09 11:12 AM
Read List details from Memory
CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
listobject = listobject
EXCEPTIONS
not_found = 1
OTHERS = 2.
Generate LIST for excel file
CALL FUNCTION 'LIST_TO_TXT'
TABLES
listtxt = ttxt
listobject = listobject
EXCEPTIONS
empty_list = 1
list_index_invalid = 2
OTHERS = 3.
LOOP AT ttxt.
REPLACE ALL OCCURRENCES OF '|' IN ttxt-line
WITH cl_abap_char_utilities=>horizontal_tab.
MODIFY ttxt.
ENDLOOP.
Send the document
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_type = 'RAW'
document_data = x_doc_chng
commit_work = 'X'
TABLES
contents_txt = t_email
object_header = int_objhead
packing_list = int_objpack
contents_bin = ttxt
receivers = lt_receiver
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
OTHERS = 99.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |