12-21-2009 3:07 PM
Hello experts,
In my ALV report, I have a few records in my internal table and would like to throw these records into a file on my PC without displaying these records. The format of the output file should be identical to the format that we get from Export -> Localfile -> unconverted functionality on ALV report. Any thoughts / suggestions please? Thanks.
12-21-2009 3:29 PM
12-21-2009 3:53 PM
Hello Adrian,
I have written a sample code for your req. Does this fit the bill:
TYPE-POOLS slis.
DATA:
itab TYPE STANDARD TABLE OF t001.
SELECT * FROM t001 INTO TABLE itab UP TO 20 ROWS.
IF sy-subrc = 0.
DATA: st_print TYPE slis_print_alv,
v_spono TYPE rspoid,
v_file TYPE localfile.
st_print-print = 'X'.
st_print-no_print_listinfos = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_structure_name = 'T001'
is_print = st_print
TABLES
t_outtab = itab
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc = 0.
v_spono = sy-spono.
CONCATENATE 'C:\Documents and Settings\ssaha\' sy-spono
'.txt' INTO v_file.
CALL FUNCTION 'RSPO_DOWNLOAD_SPOOLJOB'
EXPORTING
id = v_spono
fname = v_file.
WRITE: / 'File downloaded successfully to:', 50 v_file.
ENDIF.
ENDIF.
BR,
Suhas
12-21-2009 4:28 PM
Hello,
Thanks for your post. It is not exactly what I am looking for but it is pretty close. Couple of modifications to what you suggested.
1. I do not want any pop-up for printer name selection. Once we execute the program, the file should be written without any user interaction in between.
2. The file format that I am getting with your suggestion is
-------------------------------------------------------------------
|CoCd|Company name |City |Cty|Crcy|
|-------------------------------------------------------------------
|0001 |SAP A.G. |Walldorf |DE |EUR |
|0MB1|IS-B Musterbank Deutschl.|Walldorf |DE |EUR |
I am interested in the format that we get if we display the records using REUSE_ALV_GRID_DISPLAY and go wtih Localfile -> unconverted which would look like below
12/21/2009
------------------------------------------------------------------
------------------------------------------------------------------
|CoCd|Company name |City |Cty|Crcy|
------------------------------------------------------------------
|0001|SAP A.G. |Walldorf |DE |EUR |
|0MB1|IS-B Musterbank Deutschl.|Walldorf |DE |EUR |
12-21-2009 4:48 PM
Hi Adrian
If you want to download the print to a local file without to display it, I think u should create a new report submits the ALV report with option EXPORTING LIST TO MEMORY, the u can catch the list by fm LIST_FROM_MEMORY and then download it.
Max
12-21-2009 5:08 PM
You can also submit your output to spool and then save this spool locally or convert to PDF.
Search SDN on this to know more.
Edited by: Harsh Bhalla on Dec 21, 2009 10:39 PM
12-21-2009 5:36 PM
Hello Max,
Thanks for your response. I will give it a try and get back. One more quick question. If we display our records using REUSE_ALV_GRID_DISPLAY like below, we get field descriptions in the column headings . Is there a setting some where in REUSE_ALV_GRID_DISPLAY to have field names in the column headings instead. For instance instead of CoCd I would like to have BUKRS as column heading. Please suggest. Thanks.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
i_structure_name = 'T001'
TABLES
t_outtab = itab
EXCEPTIONS
program_error = 1
OTHERS = 2.
12-21-2009 5:52 PM
Hi
You need to change the catalog table by your self using the fm REUSE_ALV_FIELDCATALOG_MERGE in order to replace the description with the field name:
TYPE-POOLS SLIS.
DATA: T_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV WITH HEADER LINE.
*
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME = 'T001'
CHANGING
CT_FIELDCAT = T_FIELDCAT[].
LOOP AT T_FIELDCAT.
T_FIELDCAT-SELTEXT_L = T_FIELDCAT-FIELDNAME.
T_FIELDCAT-SELTEXT_M = T_FIELDCAT-FIELDNAME.
T_FIELDCAT-SELTEXT_S = T_FIELDCAT-FIELDNAME.
MODIFY T_FIELDCAT.
ENDLOOP.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IT_FIELDCAT = T_FIELDCAT[]
TABLES
T_OUTTAB = ITAB.
12-21-2009 5:55 PM
12-22-2009 6:48 PM
Max,
As per your suggestion, I used SUBMIT EXPORTING LIST TO MEMORY and FM's LIST_FROM_MEMORY and LIST_TO_ASCI to catch the ALV report output. I am getting everything I need but just one problem. For some reason, some of the records are getting truncated. Not sure where this limitation of length is coming from. I believe my problem is related to below thread and solution suggested in this thread was to "write to application server or write to spool and read it back". Not sure how to do this. Any suggestions please? Thanks.
12-23-2009 11:46 AM
Hi
U can check the fm RSPO_DISPLAY_SPOOLJOB in order to understand how to read a job spool (I think routine FORM read_data), so u can use that abap code in order to read the spool and downloaded the file.
Max