Writing internal table contents to excel
hi,
i need to write data in my internal table to an excel spread sheet which should be similar to my internal table structure.
can someone help me out.
thanks,
ravi.
Hi,
Try this one
FORM f9008_f4_hlp_for_pc_file.
DATA: li_filetable TYPE STANDARD TABLE OF file_table,
lv_return TYPE i,
lw_filetable TYPE file_table.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = 'Select file for download'
default_extension = '.txt'
initial_directory = 'C:'
CHANGING
file_table = li_filetable
rc = lv_return
EXCEPTIONS
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
OTHERS = 4
IF sy-subrc <> 0.
MESSAGE e006 WITH text-077.
ELSE.
READ TABLE li_filetable INTO lw_filetable INDEX 1.
v_fnam = lw_filetable-filename.
ENDIF.
FORM f9007_download_file TABLES p_output.
DATA: lv_size TYPE i.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
filename = v_fnam
filetype = 'DAT'
IMPORTING
filelength = lv_size
TABLES
data_tab = p_output
EXCEPTIONS
file_open_error = 1
file_write_error = 2
invalid_filesize = 3
invalid_type = 4
no_batch = 5
unknown_error = 6
invalid_table_width = 7
gui_refuse_filetransfer = 8
customer_error = 9
OTHERS = 10.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " f9007_download_file
<b>While downloading file, u wont get the header part, u have to append the header part</b>. Then u pass the final output table with header to the function module.
So that it will read the first line that will be header and then remaning data.
<i>Sample code:</i>U can create an internal table.
TYPES: begin of ty_itab ,
name(4) TYPE c,
***(3) Type c,
end of ty_itab.
DATA: i_itab type standard table of ty_itab,
w_itab type ty_itab.
Then do as below.
w_itab-name = 'NAME'.
w_itab-*** = '***'.
APPEND w_itab to i_output_final.
i_output[] = i_output_final.
APPEND i_output_final.
Now pass this final table to the functionmodule, so it is now with header.
Try this out.
Get back to me if u want any clarification.
Similar Messages
-
Problem in displaying internal table contents to excel(color)
Hello Gurus!!!!!
The code is given below :-
*& Module pool ZDEMO_DOWNLD1
PROGRAM ZDEMO_DOWNLD1.
*& Module USER_COMMAND_0100 INPUT
text
MODULE USER_COMMAND_0100 INPUT.
DATA : f_name(120) type c,
f_name1(120) type c.
case sy-ucomm.
when 'ATTACH'.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
DEF_FILENAME = ' '
DEF_PATH = ' '
MASK = ' '
MODE = ' '
TITLE = ' '
IMPORTING
FILENAME = f_name
RC =
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS = 5
*f_name = DEF_FILENAME.
f_name1 = f_name.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
endcase.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Module STATUS_0100 OUTPUT
text
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'xxxxxxxx'.
SET TITLEBAR 'xxx'.
type-pools ole2.
data: h_excel type ole2_object, " Excel object
h_mapl type ole2_object, " list of workbooks
h_map type ole2_object, " workbook
h_zl type ole2_object, " cell
h_f type ole2_object, " font
h_interior type ole2_object. " Color
*tables: spfli.
DATA: ls_emp TYPE zpm_emp_det,
lt_emp TYPE zpm_emp_det OCCURS 0,
l_projectname TYPE zpm_emp_item_det-project_name,
l_projectname_last TYPE zpm_emp_item_det-project_name,
l_empid TYPE zpm_emp_item_det-empid,
l_empid_last TYPE zpm_emp_item_det-empid.
DATA: l_projectname_key TYPE lvc_nkey,
l_role_of_emp_key TYPE lvc_nkey,
l_last_key TYPE lvc_nkey.
DATA : lt_project_main TYPE TABLE OF zsach_pm ,
ls_project_main TYPE zsach_pm,
lt_project TYPE zsach_pm OCCURS 0,
ls_project TYPE zsach_pm.
internal table for excel headings
DATA : BEGIN OF lt_project_ex OCCURS 0,
line(50) TYPE c,
END OF lt_project_ex.
DATA: lt_project1 TYPE zsach_pm OCCURS 0,
ls_project1 TYPE zsach_pm.
DATA : lt_project_temp TYPE zsach_pm OCCURS 0 ,
ls_project_temp TYPE zsach_pm.
DATA: lt_project2 TYPE zsach_pm OCCURS 0,
ls_project2 TYPE zsach_pm.
TYPES: BEGIN OF st_username,
username TYPE zuser_names-username,
END OF st_username.
DATA: it_tab TYPE TABLE OF st_username,
wa_tab TYPE st_username.
data : lt_project_excel like zsach_pm occurs 0 with header line.
*DATA: f_name TYPE string.
data h type i.
table of flights
data: it_spfli like spfli occurs 10 with header line.
*& Event START-OF-SELECTION
SELECT empid
project_name
role_of_emp
competancy
manager
price_category
rate_per_hour
first_day_pro
last_day_pro
ckey
FROM zpm_emp_item_det
INTO CORRESPONDING FIELDS OF TABLE lt_project.
LOOP AT lt_project INTO ls_project.
ENDLOOP.
SELECT projectid project_name client begin_date end_date
FROM zpm_project_det
INTO CORRESPONDING FIELDS OF TABLE lt_project_temp FOR ALL ENTRIES IN lt_project
WHERE project_name = lt_project-project_name.
LOOP AT lt_project_temp INTO ls_project_temp.
MODIFY lt_project FROM ls_project_temp TRANSPORTING
projectid project_name client begin_date end_date
WHERE project_name = ls_project_temp-project_name.
ENDLOOP.
SELECT empid
employee_name
designation
employee_type
date_of_joining
FROM zpm_emp_head_det
INTO CORRESPONDING FIELDS OF TABLE lt_project1 FOR ALL ENTRIES IN lt_project
WHERE empid = lt_project-empid.
LOOP AT lt_project1 INTO ls_project1.
MODIFY lt_project FROM ls_project1 TRANSPORTING
empid
employee_name
designation
employee_type
date_of_joining
WHERE empid = ls_project1-empid.
ENDLOOP.
tell user what is going on
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
PERCENTAGE = 0
text = text-007
exceptions
others = 1.
start Excel
create object h_excel 'EXCEL.APPLICATION'.
perform err_hdl.
set property of h_excel 'Visible' = 1.
perform err_hdl.
tell user what is going on
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
PERCENTAGE = 0
text = text-008
exceptions
others = 1.
get list of workbooks, initially empty
call method of h_excel 'Workbooks' = h_mapl.
perform err_hdl.
add a new workbook
call method of h_mapl 'Add' = h_map.
perform err_hdl.
tell user what is going on
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
PERCENTAGE = 0
text = text-009
exceptions
others = 1.
output column headings to active Excel sheet
perform fill_cell using 1 1 1 'Project ID'(001).
perform fill_cell using 1 2 1 'Emp ID'(002).
perform fill_cell using 1 3 1 'Project Name'(003).
perform fill_cell using 1 4 1 'Client'(004).
perform fill_cell using 1 5 1 'Begin Date'(005).
perform fill_cell using 1 6 1 'End Date'(006).
perform fill_cell using 1 7 1 'Role of Employee'(007).
perform fill_cell using 1 8 1 'Module / Competancy'(008).
perform fill_cell using 1 9 1 'Employee name'(009).
perform fill_cell using 1 10 1 'Price Category'(010).
perform fill_cell using 1 11 1 'Rate P/H'(011).
perform fill_cell using 1 12 1 '1st day in project'(012).
perform fill_cell using 1 13 1 'Last day in project'(013).
perform fill_cell using 1 14 1 'Currency'(014).
perform fill_cell using 1 15 1 'Manager'(015).
perform fill_cell using 1 16 1 'Emp Type'(016).
perform fill_cell using 1 17 1 'Designation'(017).
perform fill_cell using 1 18 1 'Joining Date'(018).
perform fill_cell using 1 19 1 'Last Date'(019).
loop at lt_project into ls_project.
*lt_project_excel[] = lt_project[].
endloop.
copy flights to active EXCEL sheet
h = sy-tabix + 1.
*perform fill_cell1 using h 1 0 ls_project-PROJECTID.
*perform fill_cell1 using h 2 0 ls_project-EMPID.
*perform fill_cell1 using h 3 0 ls_project-PROJECT_NAME.
*perform fill_cell1 using h 4 0 ls_project-client.
*perform fill_cell1 using h 5 0 ls_project-BEGIN_DATE.
*perform fill_cell1 using h 6 0 ls_project-END_DATE.
*perform fill_cell1 using h 7 0 ls_project-ROLE_OF_EMP.
*perform fill_cell1 using h 8 0 ls_project-COMPETANCY.
*perform fill_cell1 using h 9 0 ls_project-EMPLOYEE_NAME.
*perform fill_cell1 using h 10 0 ls_project-PRICE_CATEGORY.
*perform fill_cell1 using h 11 0 ls_project-RATE_PER_HOUR.
*perform fill_cell1 using h 12 0 ls_project-FIRST_DAY_PRO.
*perform fill_cell1 using h 13 0 ls_project-LAST_DAY_PRO.
*perform fill_cell1 using h 14 0 ls_project-CKEY.
*perform fill_cell1 using h 15 0 ls_project-MANAGER.
*perform fill_cell1 using h 16 0 ls_project-EMPLOYEE_TYPE.
*perform fill_cell1 using h 17 0 ls_project-DESIGNATION.
*perform fill_cell1 using h 18 0 ls_project-DATE_OF_JOINING.
*perform fill_cell1 using h 19 0 ls_project-LAST_WORKING_DAT.
perform fill_cell1 using h 1 0 lt_project_excel-PROJECTID.
perform fill_cell1 using h 2 0 lt_project_excel-EMPID.
perform fill_cell1 using h 3 0 lt_project_excel-PROJECT_NAME.
perform fill_cell1 using h 4 0 lt_project_excel-client.
perform fill_cell1 using h 5 0 lt_project_excel-BEGIN_DATE.
perform fill_cell1 using h 6 0 lt_project_excel-END_DATE.
perform fill_cell1 using h 7 0 lt_project_excel-ROLE_OF_EMP.
perform fill_cell1 using h 8 0 lt_project_excel-COMPETANCY.
perform fill_cell1 using h 9 0 lt_project_excel-EMPLOYEE_NAME.
perform fill_cell1 using h 10 0 lt_project_excel-PRICE_CATEGORY.
perform fill_cell1 using h 11 0 lt_project_excel-RATE_PER_HOUR.
perform fill_cell1 using h 12 0 lt_project_excel-FIRST_DAY_PRO.
perform fill_cell1 using h 13 0 lt_project_excel-LAST_DAY_PRO.
perform fill_cell1 using h 14 0 lt_project_excel-CKEY.
perform fill_cell1 using h 15 0 lt_project_excel-MANAGER.
perform fill_cell1 using h 16 0 lt_project_excel-EMPLOYEE_TYPE.
perform fill_cell1 using h 17 0 lt_project_excel-DESIGNATION.
perform fill_cell1 using h 18 0 lt_project_excel-DATE_OF_JOINING.
perform fill_cell1 using h 19 0 lt_project_excel-LAST_WORKING_DAT.
*endloop.
disconnect from Excel
*CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
EXPORTING
DOCUMENT_DATA =
PUT_IN_OUTBOX = ' '
SENDER_ADDRESS = SY-UNAME
SENDER_ADDRESS_TYPE = 'B'
COMMIT_WORK = ' '
IMPORTING
SENT_TO_ALL =
NEW_OBJECT_ID =
SENDER_ID =
TABLES
PACKING_LIST =
OBJECT_HEADER =
CONTENTS_BIN =
CONTENTS_TXT =
CONTENTS_HEX =
OBJECT_PARA =
OBJECT_PARB =
RECEIVERS =
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.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*ENDIF.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
free object h_excel.
perform err_hdl.
ENDMODULE. " STATUS_0100 OUTPUT
FORM FILL_CELL *
sets cell at coordinates i,j to value val boldtype bold *
form fill_cell using i j bold val.
call method of h_excel 'Cells' = h_zl exporting #1 = i #2 = j.
perform err_hdl.
set property of h_zl 'Value' = val .
perform err_hdl.
get property of h_zl 'Font' = h_f.
perform err_hdl.
set property of h_f 'Bold' = bold .
perform err_hdl.
SET PROPERTY OF h_f 'ColorIndex' = 11 .
perform err_hdl.
endform.
*& Form fill_cell1
text
-->P_H text
-->P_1 text
-->P_0 text
-->P_IT_SPFLI_CARRID text
form fill_cell1 using i j bold val.
call method of h_excel 'Cells' = h_zl exporting #1 = i #2 = j.
perform err_hdl.
set property of h_zl 'Value' = val .
perform err_hdl.
get property of h_zl 'Font' = h_f.
perform err_hdl.
set property of h_f 'Bold' = bold .
perform err_hdl.
SET PROPERTY OF h_f 'ColorIndex' = 14 .
perform err_hdl.
endform. " fill_cell1
*& Form ERR_HDL
outputs OLE error if any *
--> p1 text
<-- p2 text
form err_hdl.
if sy-subrc <> 0.
write: / 'Error in OLE-Automation:'(010), sy-subrc.
stop.
endif.
endform. " ERR_HDL
Entire excel file is displayed ,but the problem is I want to display the excel file in one shot i.e not <b>line by line</b>
Kindly suggest if there is any keyword or FM to display the contents in excel using internal table.
It should not take much time. Just by executing code , the contents of internal table should be displayed.
Helpful answers will be rewarded
Thanks,
SachinHi Kavitha,
maybe it's not sophisticated enough for your requirement, but I found function XXL_FULL_API easy to use. This will give same functionality as 'download' button in ALV-Grid display.
Regards,
Christian -
How to download values in an internal table into an excel file
is there any fn module to download the values in an internal table into an excel file..
hi
the function module "GUI_DOWNLOAD" downloads the data from
an internal table into a file (can be xl, dat ,doc etc) .
Plz follow the usage below ;
Parameters : pa_pfile LIKE rlgrap-filename OBLIGATORY.
Data : lv_filename TYPE STRING.
lv_filename = pa_pfile.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE =
FILENAME = lv_filename
FILETYPE = 'ASC'
APPEND = ' '
WRITE_FIELD_SEPARATOR = 'X'
HEADER = '00'
TRUNC_TRAILING_BLANKS = ' '
WRITE_LF = 'X'
COL_SELECT = ' '
COL_SELECT_MASK = ' '
DAT_MODE = ' '
CONFIRM_OVERWRITE = ' '
NO_AUTH_CHECK = ' '
IMPORTING
FILELENGTH =
TABLES
DATA_TAB = tb_download " table data to b downlaoded
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Regards
Pankaj -
Download internal table data to Excel in background
Hi all ,
Can anyone tell that how i can download internal table data
into Excel sheet in Backgroud Mode .
I used both fun mod ws and gui download but these are not working in background mod .
Please help issue is urgent .
Answer is rewarded by point .
With Regards ,
Nilesh Jainhi,
you have to use function module 'SAP_CONVERT_TO_XLS_FORMAT'.
DATA:
ITAB1 TYPE TRUXS_T_TEXT_DATA.
CALL FUNCTION 'SAP_CONVERT_TO_XLS_FORMAT'
EXPORTING
I_FIELD_SEPERATOR = ';'
I_LINE_HEADER =
i_filename = filename
I_APPL_KEEP = ' '
tables
i_tab_sap_data = itab
CHANGING
I_TAB_CONVERTED_DATA = itab1
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 2
*IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*ENDIF.
try this one.
reward points if useful,
thanks & regards,
rajee. -
Downloading the internal table contents into presentation server
Hi
I have a requirement like i need to download the contetns of my internal table into an excel sheet in the presemtation server and i am using GUI_DOWNLOAD.
I would like to place my header also in the excel sheet can any one suggest me how to do that?
thanksHi,
U can see the following example,
TYPES:
BEGIN OF TYPE_S_FLIGHT,
MANDT(15) TYPE C,
CARRID(15) TYPE C,
CONNID(15) TYPE C,
FLDATE(15) TYPE C,
END OF TYPE_S_FLIGHT.
data:
T_HEADER TYPE TABLE OF TYPE_S_FLIGHT WITH HEADER LINE,
t_sflight type table of SFLIGHT.
T_HEADER-MANDT = 'MANDT'.
T_HEADER-CARRID = 'CARRID'.
T_HEADER-CONNID = 'CONNID'.
T_HEADER-FLDATE = 'FLDATE'.
APPEND T_HEADER.
PERFORM GUI_DOWNLOAD TABLES T_HEADER USING ' '.
select MANDT
CARRID
CONNID
FLDATE
from sflight into CORRESPONDING FIELDS OF table t_sflight.
PERFORM GUI_DOWNLOAD TABLES T_SFLIGHT USING 'X'.
form GUI_DOWNLOAD TABLES P_TABLE USING VALUE(P_APPEND).
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = 'C:\TEMP1\FLIGHT.XLS'
APPEND = P_APPEND
WRITE_FIELD_SEPARATOR = 'X'
tables
data_tab = P_TABLE
In this case u have to populate the one table for header. The other one is for data.
Thanks,
Nithya.
Edited by: Nithya Murugesan on Feb 8, 2009 1:00 PM -
How to move large number of internal table data to excel by program
Hi,
Iam working on a classical report wherein my requirement is:
Have around 25 internal tables which I am displaying using a selection screen.I need to transfer this all internal tables data to Excel file by executing.
Now, let me know how can I transfer all those to excel by execution.
P.S.: GUI_DOWNLOAD or any other excel download related FMs are used to transfer for single/fewer internal tables.
But here I need to download 25 internal tables data through program.
How can I meet the requirement..?
Kindly advice.
Thanks,
Shiv.Hi,
Refer to the following code:
*& Report ZDOWNLOAD_PROGRAM
report zdownload_program.
parameter : p_path type rlgrap-filename default 'C:\Pdata.xls'.
data : gt_output type standard table of trdirt,
wa_output type trdirt,
p_filen type string.
at selection-screen on value-request for p_path.
clear p_path.
call function 'F4_FILENAME'
importing
file_name = p_path.
start-of-selection.
select * from trdirt
into table gt_output
where name like 'Z%'
or name like 'Y%'.
end-of-selection.
move : p_path to p_filen.
call function 'GUI_DOWNLOAD'
exporting
BIN_FILESIZE =
filename = p_filen
filetype = 'ASC'
APPEND = ' '
write_field_separator =
cl_abap_char_utilities=>horizontal_tab
HEADER = '00'
TRUNC_TRAILING_BLANKS = ' '
WRITE_LF = 'X'
COL_SELECT = ' '
COL_SELECT_MASK = ' '
DAT_MODE = ' '
CONFIRM_OVERWRITE = ' '
NO_AUTH_CHECK = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
WRITE_BOM = ' '
TRUNC_TRAILING_BLANKS_EOL = 'X'
WK1_N_FORMAT = ' '
WK1_N_SIZE = ' '
WK1_T_FORMAT = ' '
WK1_T_SIZE = ' '
WRITE_LF_AFTER_LAST_LINE = ABAP_TRUE
IMPORTING
FILELENGTH =
tables
data_tab = gt_output
FIELDNAMES =
exceptions
file_write_error = 1
no_batch = 2
gui_refuse_filetransfer = 3
invalid_type = 4
no_authority = 5
unknown_error = 6
header_not_allowed = 7
separator_not_allowed = 8
filesize_not_allowed = 9
header_too_long = 10
dp_error_create = 11
dp_error_send = 12
dp_error_write = 13
unknown_dp_error = 14
access_denied = 15
dp_out_of_memory = 16
disk_full = 17
dp_timeout = 18
file_not_found = 19
dataprovider_exception = 20
control_flush_error = 21
others = 22
if sy-subrc <> 0.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
Regards
Rajesh Kumar -
Download internal table data in excel format
Hi ,
i have a requirement where i need to download the internal table data in excel format .. I tried using the FM SAP_CONVERT_TO_XLS_FORMAT but this downloads to excel sheet same as .txt file foemat without columns ... i need to have the data in excel sheet with column heading and separated by each coulmn which should be similar as a general sheet with column names and the respective data in the columns . Appreciate any inputs .
Thanks,
Latha.Hi,
you can this in Debugging mode,
say,once you got entire data into ITAB
salect the TABLE option and provide the table name
now on the top most you can see excel icon,you click
on that,now system will prompts you for to the file to be saved.
Regards,
Vijaya. -
How to convert internal table data into excel format?
Hi all,
I want to convert internal table data in excel format and then
send it as email attachment in workflow.
Please tell me how do i perform this.
Regards,
Arpita.Hi Arpita,
Try this sample code::
Send mail
maildata-obj_name = 'TEST'.
maildata-obj_descr = 'Test Subject'.
loop at htmllines.
mailtxt = htmllines.
append mailtxt.
endloop.
mailrec-receiver = 'your receiver mail id'.
mailrec-rec_type = 'U'.
append mailrec.
call function 'SO_NEW_DOCUMENT_SEND_API1'
exporting
document_data = maildata
document_type = 'EXL'
put_in_outbox = 'X'
tables
object_header = mailtxt
object_content = mailtxt
receivers = mailrec
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.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
Hope it will help you.
Regards,
NIkita -
Internal Table attached as Excel file to an eMail - BCS_EXAMPLE_7 for UC
Hi forums,
SAP provided an example report to send out internal tables attached as an Excel file to a recipients eMail address. I attached the coding of the BCS_EXAMPLE_7 programm to this thread.
report bcs_example_7.
This report provides an example for sending an Excel
attachment in Unicode Systems
constants:
gc_tab type c value cl_bcs_convert=>gc_tab,
gc_crlf type c value cl_bcs_convert=>gc_crlf.
parameters:
mailto type ad_smtpadr
default 'john.doe(a)crazy-company.com'. "#EC *
data send_request type ref to cl_bcs.
data document type ref to cl_document_bcs.
data recipient type ref to if_recipient_bcs.
data bcs_exception type ref to cx_bcs.
data main_text type bcsy_text.
data binary_content type solix_tab.
data size type so_obj_len.
data sent_to_all type os_boolean.
start-of-selection.
perform create_content.
perform send.
*& Form send
form send.
try.
-------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).
-------- create and set document with attachment ---------------
create document object from internal table with text
append 'Hello world!' to main_text. "#EC NOTEXT
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = main_text
i_subject = 'Test Created By BCS_EXAMPLE_7' ). "#EC NOTEXT
add the spread sheet as attachment to document object
document->add_attachment(
i_attachment_type = 'xls' "#EC NOTEXT
i_attachment_subject = 'ExampleSpreadSheet' "#EC NOTEXT
i_attachment_size = size
i_att_content_hex = binary_content ).
add document object to send request
send_request->set_document( document ).
--------- add recipient (e-mail address) -----------------------
create recipient object
recipient = cl_cam_address_bcs=>create_internet_address( mailto ).
add recipient object to send request
send_request->add_recipient( recipient ).
---------- send document ---------------------------------------
sent_to_all = send_request->send( i_with_error_screen = 'X' ).
commit work.
if sent_to_all is initial.
message i500(sbcoms) with mailto.
else.
message s022(so).
endif.
------------ exception handling ----------------------------------
replace this rudimentary exception handling with your own one !!!
catch cx_bcs into bcs_exception.
message i865(so) with bcs_exception->error_type.
endtry.
endform. "send
*& Form create_content
Create Example Content
1) Write example text into a string
2) convert this string to solix_tab
form create_content.
data lv_string type string.
data ls_t100 type t100.
as example content we use some system messages out of t100
get them for all installed languages from db
and write one line for each language into the spread sheet
columns are separated by TAB and each line ends with CRLF
concatenate 'This Is Just Example Text!' "#EC NOTEXT
gc_crlf gc_crlf
into lv_string.
header line
concatenate lv_string
'MSGID' gc_tab
'MSGNO' gc_tab
'Language' gc_tab "#EC NOTEXT
'Text' gc_crlf "#EC NOTEXT
into lv_string.
data lines
select * from t100 into ls_t100
where arbgb = 'SO' and msgnr = '182'.
concatenate lv_string
ls_t100-arbgb gc_tab
ls_t100-msgnr gc_tab
ls_t100-sprsl gc_tab
ls_t100-text gc_crlf
into lv_string.
endselect.
select * from t100 into ls_t100
where arbgb = 'SO' and msgnr = '316'.
concatenate lv_string
ls_t100-arbgb gc_tab
ls_t100-msgnr gc_tab
ls_t100-sprsl gc_tab
ls_t100-text gc_crlf
into lv_string.
endselect.
convert the text string into UTF-16LE binary data including
byte-order-mark. Mircosoft Excel prefers these settings
all this is done by new class cl_bcs_convert (see note 1151257)
try.
cl_bcs_convert=>string_to_solix(
exporting
iv_string = lv_string
iv_codepage = '4103' "suitable for MS Excel, leave empty
iv_add_bom = 'X' "for other doc types
importing
et_solix = binary_content
ev_size = size ).
catch cx_bcs.
message e445(so).
endtry.
endform. "create_content
NOTES:
UTF-16LE including the BOM (Byte order mark)
is preferred by Microsoft Excel. If you want to create
other binary content you may choose another codepage (e.g.
'4110' (UTF-8) which is standard for e-mails).
Find SAP codepage names in the drop down list
for the codepage setting of node SMTP in transaction SCOT.
Or: leave iv_codepage and iv_add_bom empty. Then the target
codepage is set according to SAPconnect settings
Important:
SAP neither guarantees that the attachment created
by this report can be opened by all Excel Versions nor
that it can be opened by any 3rd party software at all
Best regards to you
Thorsten Hüser
SAP CRM Senior consultant
arvato / BertelsmannHi forums,
SAP provided an example report to send out internal tables attached as an Excel file to a recipients eMail address. I attached the coding of the BCS_EXAMPLE_7 programm to this thread.
report bcs_example_7.
This report provides an example for sending an Excel
attachment in Unicode Systems
constants:
gc_tab type c value cl_bcs_convert=>gc_tab,
gc_crlf type c value cl_bcs_convert=>gc_crlf.
parameters:
mailto type ad_smtpadr
default 'john.doe(a)crazy-company.com'. "#EC *
data send_request type ref to cl_bcs.
data document type ref to cl_document_bcs.
data recipient type ref to if_recipient_bcs.
data bcs_exception type ref to cx_bcs.
data main_text type bcsy_text.
data binary_content type solix_tab.
data size type so_obj_len.
data sent_to_all type os_boolean.
start-of-selection.
perform create_content.
perform send.
*& Form send
form send.
try.
-------- create persistent send request ------------------------
send_request = cl_bcs=>create_persistent( ).
-------- create and set document with attachment ---------------
create document object from internal table with text
append 'Hello world!' to main_text. "#EC NOTEXT
document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = main_text
i_subject = 'Test Created By BCS_EXAMPLE_7' ). "#EC NOTEXT
add the spread sheet as attachment to document object
document->add_attachment(
i_attachment_type = 'xls' "#EC NOTEXT
i_attachment_subject = 'ExampleSpreadSheet' "#EC NOTEXT
i_attachment_size = size
i_att_content_hex = binary_content ).
add document object to send request
send_request->set_document( document ).
--------- add recipient (e-mail address) -----------------------
create recipient object
recipient = cl_cam_address_bcs=>create_internet_address( mailto ).
add recipient object to send request
send_request->add_recipient( recipient ).
---------- send document ---------------------------------------
sent_to_all = send_request->send( i_with_error_screen = 'X' ).
commit work.
if sent_to_all is initial.
message i500(sbcoms) with mailto.
else.
message s022(so).
endif.
------------ exception handling ----------------------------------
replace this rudimentary exception handling with your own one !!!
catch cx_bcs into bcs_exception.
message i865(so) with bcs_exception->error_type.
endtry.
endform. "send
*& Form create_content
Create Example Content
1) Write example text into a string
2) convert this string to solix_tab
form create_content.
data lv_string type string.
data ls_t100 type t100.
as example content we use some system messages out of t100
get them for all installed languages from db
and write one line for each language into the spread sheet
columns are separated by TAB and each line ends with CRLF
concatenate 'This Is Just Example Text!' "#EC NOTEXT
gc_crlf gc_crlf
into lv_string.
header line
concatenate lv_string
'MSGID' gc_tab
'MSGNO' gc_tab
'Language' gc_tab "#EC NOTEXT
'Text' gc_crlf "#EC NOTEXT
into lv_string.
data lines
select * from t100 into ls_t100
where arbgb = 'SO' and msgnr = '182'.
concatenate lv_string
ls_t100-arbgb gc_tab
ls_t100-msgnr gc_tab
ls_t100-sprsl gc_tab
ls_t100-text gc_crlf
into lv_string.
endselect.
select * from t100 into ls_t100
where arbgb = 'SO' and msgnr = '316'.
concatenate lv_string
ls_t100-arbgb gc_tab
ls_t100-msgnr gc_tab
ls_t100-sprsl gc_tab
ls_t100-text gc_crlf
into lv_string.
endselect.
convert the text string into UTF-16LE binary data including
byte-order-mark. Mircosoft Excel prefers these settings
all this is done by new class cl_bcs_convert (see note 1151257)
try.
cl_bcs_convert=>string_to_solix(
exporting
iv_string = lv_string
iv_codepage = '4103' "suitable for MS Excel, leave empty
iv_add_bom = 'X' "for other doc types
importing
et_solix = binary_content
ev_size = size ).
catch cx_bcs.
message e445(so).
endtry.
endform. "create_content
NOTES:
UTF-16LE including the BOM (Byte order mark)
is preferred by Microsoft Excel. If you want to create
other binary content you may choose another codepage (e.g.
'4110' (UTF-8) which is standard for e-mails).
Find SAP codepage names in the drop down list
for the codepage setting of node SMTP in transaction SCOT.
Or: leave iv_codepage and iv_add_bom empty. Then the target
codepage is set according to SAPconnect settings
Important:
SAP neither guarantees that the attachment created
by this report can be opened by all Excel Versions nor
that it can be opened by any 3rd party software at all
Best regards to you
Thorsten Hüser
SAP CRM Senior consultant
arvato / Bertelsmann -
How to download internal table data to excel in WebUI
Hi everyone,
I am trying to download the contents of an internal table to excel in CRM Web UI.
One way, would be to create a table view and use the export to excel button.
However, wish to avoid this and directly download using code.
Also tried converting to xstring and setting data in the response object. However, this works only when I execute the component directly from BSP_WD_CMPWB. In the UI framework however, when I click on custom button(for download), it navigates to a screen where the contents of string are shown directly on browser.
Is there any other way of doing this?
Thanks in advance.
Regards,
DeepakHi,
there are two ways to download excel from the webclient using table views. The first is a XML stream that is send to Excel directly. Only works for Excel 2003 and later. The second is the fall back to a .csv.
I do not know if for the second option a direct connection is established as mentioned in the last post or there is actually a file stream send to the client.
Anyway the SAP provides the excel download through a seperate webservice. Have a look at CL_CHTMLB_CONFIG_TAB_EXCEL_EXP->IF_HTTP_EXTENSION~HANDLE_REQUEST( ).
I suppose going the same direction with your excel download will work. This service opens a new download stream with the excel content... Maybe it is even possible to copy it and adjust it to your needs...
cheers Carsten -
Error Exporting Table Content into Excel
Hi there,
I have code that reads a TableView and exports its content into excel file. The code is running right now in an iView that is stored in a protal role. The code has been developed using PDK. I'm running portal 6.0 SP16.
Here is what the code does:
1. Reads the content of the table and stores it in an HSSFSheet inside an HSSFWorkbooK object.
2. Gets HttpServletResponse from the portal request and updates its content type and headers
HttpServletResponse response = ((IPortalComponentRequest)getRequest()).getServletResponse(true);
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachement;filename="EmployeeEntitlementRpt.xls"");
3. Writes the excel file to the response output stream.
ServletOutputStream fileOut = null;
try{
fileOut = response.getOutputStream();
wb.write(fileOut);
fileOut.close();
} catch(IOException ie){
throw new PortalRuntimeException("IOException when getting output steam from response, writing to the outputstream or closing it.", ie);
The code gives me the following error message, if invoked from the iview inside the detailed navigation.
<b>"Internet Explorer cannot download ...ge!2fcom.sap.portal.innerpage from portald.global.ad
Internet Explorer was not able to open this Internet site. The requested site is either unavailable or cannot be found. Please try again later."</b>
However, when I navigate to the same iView and open it in a new window, the code functions as expected.
This is the URL to the iView when opened inside the detailed navigation: https://companyserver.global.ad/irj/servlet/prt/portal/prtpos/pcd!253aportal!255fcontent!252fevery!255fuser!252fgeneral!252fdefaultDesktop!252fframeworkPages!252fframeworkpage!252fcom!252esap!252eportal!252einnerpage!7b!3b2!7d.com!252esap!252eportal!252edynamicNavigationArea!7bHideMode!7d_com!252esap!252eportal!252etargetsiView!7bHideMode!7d_com!252esap!252eportal!252etargetsiView!255f!7bHideMode!7d-/prttarget/com!252enexeninc!252etots!252eiv_entitlement_report.content/prteventname/HtmlbEvent/prtroot/pcd!3aportal_content!2fevery_user!2fgeneral!2fdefaultDesktop!2fframeworkPages!2fframeworkpage!2fcom.sap.portal.innerpage
This is the URL to the iView when opened in a new window:
https://companyserver.global.ad/irj/servlet/prt/portal/prtroot/com.sap.portal.pagebuilder.iviewmodeproxy?iview_id=pcd%3aportal_content/com.nexeninc.fld_nexen_content/fld_all_users/fld_time_off_tracking/fld_administrators/com.nexeninc.tots.ro_administrator/com.nexeninc.tots.ws_user_components/com.nexeninc.portal.navigation.ws_my_workspace_my_applications/com.nexeninc.portal.navigation.ws_my_workspace/fld_general_applications/fld_track_time_off/fld_admin/com.nexeninc.tots.iv_entitlement_report&iview_mode=defaultHi,
In the iView properties, for the property Entry Point, mark the property as yes instead of the default no. May be this could help u.
Regards,
Sujana -
Why "Modify itab index sy-tabix." makes internal table content blank?
We have an internal table itab which looks like to have the following content:
A---B---C
1----3----
2----2----
We would like to get the column C value in this internal table itab by summing Column A and Column B, and then fill C column values into this internal table. We know that the program would looks like:
Loop at itab into wa_itab.
wa_itab-C = wa_itab-A + wa_itab-B.
Modify itab index sy-tabix.
EndLoop.
But after executing the above code, all itab becomes blank. Through debugging, find it's caused by the statement "Modify itab index sy-tabix.". Could any ABAP expert here let us know the reason and we will give you reward points!hi,
what you tried is correct.but instead of using
modify itab index sy-tabix
use
modify itab index sy-tabix from wa_itab.
the reason for blank data is you are not mentioning from where that record is to be updated.your specifying the record using index.one thing is no need to use index also because in a loop you are modifying so automatically it will take you to the record.
try the following code.
types:begin of it,
a type i,
b type i,
c type i,
end of it.
data:itab type standard table of it.
data:wa_itab type it.
wa_itab-a = 3. wa_itab-b = 4.
append wa_itab to itab.
Loop at itab into wa_itab.
wa_itab-C = wa_itab-A + wa_itab-B.
Modify itab index sy-tabix from wa_itab.
*you can use Modify itab from wa_itab.
EndLoop.
loop at itab into wa_itab.
write:wa_itab-a,wa_itab-b,wa_itab-c.
endloop.
<REMOVED BY MODERATOR>
Edited by: Alvaro Tejada Galindo on Apr 8, 2008 5:49 PM -
Transfer of Internal table contents to ftp server
Hi,
I have data in one internal table, which needs to transferred to file on ftp server,
please tell me how to create file on ftp server, how should i transfer contents of this internal table to file on ftp server.
please help me.Hi,
Please refer following code, which create a log file in Ftp server,
Step 1 Connect to Ftp server.
SET EXTENDED CHECK OFF.
g_slen = STRLEN( p_pwd ).
CALL FUNCTION 'HTTP_SCRAMBLE'
EXPORTING
SOURCE = p_pwd
sourcelen = g_slen
key = g_key
IMPORTING
destination = p_pwd.
CALL FUNCTION 'FTP_CONNECT'
EXPORTING
user = p_user <----- Pass User ID
password = p_pwd <---- Pass Password
host = p_host <---- Pass IP Address
rfc_destination = p_dest <----- RFC destination SAPFTP
IMPORTING
handle = g_hdl
EXCEPTIONS
not_connected = 1
OTHERS = 2.
IF sy-subrc <> 0.
sy-msgty = 'E'.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
* MESSAGE SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4 TYPE 'I'.
ENDIF.
Step 2 Reading file from FTP
CALL FUNCTION 'FTP_SERVER_TO_R3'
EXPORTING
handle = g_hdl
fname = p_fname <---- File path
* CHARACTER_MODE =
IMPORTING
BLOB_LENGTH = l_xml_table_size
TABLES
BLOB = l_xml_table
* TEXT =
EXCEPTIONS
TCPIP_ERROR = 1
COMMAND_ERROR = 2
DATA_ERROR = 3
OTHERS = 4
Step 3 Write a file
g_docid = l_filename.
* **Transferring the data from internal table to FTP Server.
DESCRIBE TABLE gt_log LINES l_count.
g_slen = l_count * 275.
CALL FUNCTION 'FTP_R3_TO_SERVER'
EXPORTING
handle = g_hdl
fname = g_docid <---File name
BLOB_LENGTH = g_slen <---- Length
CHARACTER_MODE = 'X'
TABLES
* BLOB =
TEXT = gt_log
EXCEPTIONS
TCPIP_ERROR = 1
COMMAND_ERROR = 2
DATA_ERROR = 3
OTHERS = 4 -
Download internal table data into excel sheet with column heading and data
Hi,
I am having one internal table with column headings and other table with data.
i want to download the data with these tables into an excel sheet.
It should ask the user for file name to save it on their own name. They should give the file name in runtime and it should be downloaded into an excel sheet.
Can anyone tell what is the right function module for downloading these two internal table data with column heading and data.
what we have to do for storing the file name in runtime.
Can anyone help me on this.
Thanks,
Rose.Hi Camila,
Try this
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = PATH2
FILETYPE = 'XLS'
TABLES
DATA_TAB = IT_DATA
FIELDNAMES = IT_HEADINGS
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22 -
Internal Table data to Excel Sheet
Hi All,
I have an internal table have some data , which I have to populate and save excel sheet on presentation server and application server both according to options, with column heading and header text through program.
could any one help me how to do it, if possible a sample code.
thanks
bobbyHI bobby,
Transferring Data from ABAP Internal Table to Excel Sheet
If you wish to transfer data from ABAP internal table to EXCEL you can use the following function module.
MS_EXCEL_OLE_STANDARD_DAT
This function module populates an existing excel sheet with the data from the ABAP internal table. Please find below code which shows hwo to declare and populate the import and important parameters. In the next section we will see in depth how this function module operates.
REPORT ZEX_DATATOEXCEL .
Parameters: P_file like RLGRAP-FILENAME.
data : begin of int_head occurs 0,
Filed1(20) type c, " Header Data
end of int_head.
data : begin of int_data occurs 0,
Field1(20) type c, " Data
Field2(20) type c,
Field3(20) type c,
Field4(20) type c,
end of int_data.
int_head-Filed1 = 'Sales Ord'.
APPEND int_head.
CLEAR int_head.
int_head-Filed1 = 'Sold-to-Party'.
APPEND int_head.
CLEAR int_head.
int_head-Filed1 = 'Purchase Ord'.
APPEND int_head.
CLEAR int_head.
int_head-Filed1 = 'Ship-to-Party'.
APPEND int_head.
CLEAR int_head.
int_data-field1 = '1JOHN'.
int_data-field2 = '2TOM'.
int_data-field3 = '3BRAD'.
int_data-field4 = '4PETER'.
Append int_data.
Clear int_data.
CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'
EXPORTING
file_name = p_file " path offile where u need to download
CREATE_PIVOT = 0
DATA_SHEET_NAME = ' '
PIVOT_SHEET_NAME = ' '
PASSWORD = ' '
PASSWORD_OPTION = 0
TABLES
PIVOT_FIELD_TAB =
data_tab = int_data "internal table with data
fieldnames = int_head "internal table with header
EXCEPTIONS
file_not_exist = 1
filename_expected = 2
communication_error = 3
ole_object_method_error = 4
ole_object_property_error = 5
invalid_filename = 6
invalid_pivot_fields = 7
download_problem = 8
OTHERS = 9
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
thanks
karthik
Maybe you are looking for
-
AD RMS 2.1 - API Server is not Syncing templates from server
Hello, I couldn't find any information on this before, apologies if this is a duplicate response. We have a server running AD RMS 2.1, it's currently set up in production mode. We have an API that runs on IIS in that box which protects documents, amo
-
I need to visit the HSBC Careers Site website, to perform some sort of assessment for a job I'm applying for; the site asks me to use mozilla firefox 1.5 or 2.0 I, I may of course, be just stupid, but I don't see how I might achieve this trick? Any s
-
We have constant problems with our Apple TV, and are at the point of returning it and giving up. We have had it about 6 months, is it still under warranty. It won't load, or loads 10 seconds and then stops. All we watch are youtube videos, and it is
-
Information about table TOAOM_C
Hi, Can anyone please provide me with some inforamtion about the table TOAOM_C. I will reward all the relevant answers. Thanks in advance for the help!!! Mohit Goel.
-
Seeking Spry Gallery mouseovered thumbnail identifier/ID
Hi! I would like to ask my earlier question about the Dynamic Image Preview extension in a different way. I think my point was not clear. Operating in a Spry gallery of thumbnails with my images in 'images/' directory, what is the identifier that wil