Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

ALV report - internal table to file - no display

Former Member
0 Kudos

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.

10 REPLIES 10

Former Member
0 Kudos

Anyone with any suggestions please? Thanks.

0 Kudos

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

0 Kudos

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 |

0 Kudos

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

Former Member
0 Kudos

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

0 Kudos

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.

0 Kudos

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.

0 Kudos

Thanks. Will get back.

0 Kudos

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.

0 Kudos

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