Extract ALV list to a file in the background

I am currently working on an ALV report which the user requires that a file be generated automatically based on the ALV list output. Any ideas? Thanks in advance.

Hello Emmanuel,
I have had the same problem, and i found no solution on the forums... So i have implemented my own solution: I implemented a child class, in order to add a new method write_file. This coding creates a file on the application server, considering the field catalog from the choosen variant. It can be enhanced in order to get the sort and the filter criteria (but if the file is exported to excel, the sort and filter can be managed within excel). Such a program can be run in background, and it works perfectly!
Sample coding:
REPORT z_alv_download_file.
      CLASS LCL_GUI_ALV_GRID  INHERITING FRO
      Local child-class in order to implement a new method for      *
      download in a file in background                              *
CLASS lcl_gui_alv_grid DEFINITION INHERITING FROM cl_gui_alv_grid.
  PUBLIC SECTION.
    METHODS: write_file IMPORTING i_structure_name TYPE dd02l-tabname
                                  is_variant       TYPE disvariant
                                  i_default        TYPE char01
                                  i_save           TYPE char01
                                  i_file           TYPE fileextern
                        CHANGING  it_outtab        TYPE STANDARD TABLE.
ENDCLASS.
      CLASS lcl_gui_alv_grid IMPLEMENTATION
      Implementation of the new method write_file                   *
CLASS lcl_gui_alv_grid IMPLEMENTATION.
  METHOD write_file.
  Local types
    TYPES: BEGIN OF ty_fieldnames,
             field(60),
             field2 TYPE help_info-tabname,
             field3 TYPE help_info-fieldname,
             key(1),
           END OF ty_fieldnames.
  Local data
    DATA: lt_catalog      TYPE lvc_t_fcat,
          ls_catalog      TYPE lvc_s_fcat,
          lt_datatab      TYPE TABLE OF hrdatatab,
          ls_datatab      TYPE hrdatatab,
          lt_fieldnames   TYPE TABLE OF ty_fieldnames,
          ls_fieldnames   TYPE ty_fieldnames,
          ls_record       TYPE string,
          l_field(60)     TYPE c,
          l_nbcol         TYPE i,
          l_colpos        TYPE i,
          l_colpos_c(2)   TYPE c,
          l_fieldname(21) TYPE c VALUE 'ls_datatab-langtext  '.
    FIELD-SYMBOLS <f> TYPE ANY.
  Call the grid display
    CALL METHOD me->set_table_for_first_display
         EXPORTING i_structure_name = i_structure_name
                   is_variant = is_variant
                   i_default = i_default
                   i_save = i_save
         CHANGING  it_outtab        = it_outtab.
  Get the field catalog according to the display variant which is used
    CALL METHOD me->get_frontend_fieldcatalog
         IMPORTING et_fieldcatalog = lt_catalog.
  Get an internal table with only the fields from the field catalog
    CALL FUNCTION 'ALV_CONVERT_DATA'
         EXPORTING
              alv_fieldcat    = lt_catalog
         TABLES
              alv_datatab     = it_outtab
              hr_datatab      = lt_datatab
              hr_fieldnametab = lt_fieldnames.
  Keep only the displayed fields from the field catalog
    DELETE lt_catalog WHERE no_out = 'X'.
    SORT lt_catalog BY col_pos DESCENDING.
    READ TABLE lt_catalog INTO ls_catalog INDEX 1.
    IF sy-subrc = 0.
      CLEAR ls_record.
      l_nbcol = ls_catalog-col_pos.
    Open the file
      OPEN DATASET i_file FOR OUTPUT IN TEXT MODE.
    Write the column names
      LOOP AT lt_fieldnames INTO ls_fieldnames.
        CONDENSE ls_fieldnames-field.
        CONCATENATE ls_record ls_fieldnames-field
                    INTO ls_record SEPARATED BY ';'.
      ENDLOOP.
      SHIFT ls_record.
      TRANSFER ls_record TO i_file.
    Write the lines
      LOOP AT lt_datatab INTO ls_datatab.
        CLEAR: l_colpos,
               ls_record.
      Condense the fields in a single string, separated by ';' (csv)
        DO l_nbcol TIMES.
          ADD 1 TO l_colpos.
          CLEAR l_colpos_c.
          l_colpos_c = l_colpos.
          CONDENSE l_colpos_c.
          l_fieldname+19(2) = l_colpos_c.
          ASSIGN (l_fieldname) TO <f>.
          WRITE <f> TO l_field.
          CONDENSE l_field.
          CONCATENATE ls_record l_field INTO ls_record SEPARATED BY ';'.
        ENDDO.
        SHIFT ls_record.
        TRANSFER ls_record TO i_file.
      ENDLOOP.
    Close the file
      CLOSE DATASET i_file.
    ENDIF.
  ENDMETHOD.
ENDCLASS.
      MAIN PROGRAM
DATA: wo_alv      TYPE REF TO lcl_gui_alv_grid,
      wt_sflight TYPE TABLE OF sflight,
      ws_variant    TYPE disvariant.
PARAMETERS: p_file TYPE fileextern OBLIGATORY
                   DEFAULT '/usr/sap/.../file.csv',
            p_vari TYPE slis_vari
                   DEFAULT 'DEFAULT'.
START-OF-SELECTION.
  ws_variant-report = sy-repid.
  ws_variant-username = sy-uname.
  ws_variant-variant = p_vari.
  SELECT * FROM sflight INTO TABLE wt_sflight.
  CREATE OBJECT wo_alv EXPORTING i_parent = cl_gui_container=>screen0.
  CALL METHOD wo_alv->write_file
       EXPORTING i_structure_name = 'SFLIGHT'
                 is_variant       = ws_variant
                 i_default        = 'X'
                 i_save           = 'A'
                 i_file           = p_file
       CHANGING  it_outtab        = wt_sflight.

Similar Messages

  • How to convert alv list into excel file?

    Hi Experts,
            i have created one report for Due Date Analysis.
    Now My output is displaying in ALV list. But I need to convert the data which in alv list into Excel File. then only i have to send the Excel File to the Customer Thro Email.
         So i need the Function Module to Convert the Data into Excel File.
    Thanks,
    Neptune.M

    Hi,
      U can use function module gui_download.
      CALL FUNCTION 'GUI_DOWNLOAD'
         EXPORTING
        BIN_FILESIZE       =
          filename           = 'C:\Transportaionlane.XLS'
          filetype                       = 'DAT'
        WRITE_FIELD_SEPARATOR           = ' '
        HEADER                          = '00'
        TABLES
          ata_tab                       = t_trans_lane_dis[]
           OTHERS                          = 22
    if u want with header then pass the header.
    regards
    Ahasan

  • MRP list: collective requirements (MD06) in the background mode

    Hi Friends,
    We have requirement to run MRP list: collective requirements (MD06) in the background mode per MRP controller. Is there any way we can run MD06 in the background?
    Appreciate your response.
    Thanks,
    Srinivas

    Dear Srinivas
    if you need to run planning as a background job please try t-code MDBT;
    as far as i know you can't run MD06 as a backgroun job.
    you could ask your abaper to create a custom program based on functional module MD_MRP_LIST_OVERVIEW
    after that you will set up this custom code as a background job.
    good luck!

  • Reg RFCSDK files download for reading file in the background.

    Hi All,
    I am trying to read a file in the background for which I need the RFCSDK. i am using R/3 Version 4.6C...
    I searched every where in the service market place but with no luck. Can any one tell me if there is any other location to find the same.
    <removed by moderator>
    Any help would be highly appreciated.
    BR,
    Krishna.
    Edited by: Thomas Zloch on Oct 25, 2010 9:58 AM

    Hi Krishna,
    Try at below link,
    [http://blogs.msdn.com/b/adapters/archive/2007/10/07/obtaining-the-rfc-sdk-unicode-libraries-from-sap-service-marketplace.aspx]

  • Down loading ALV List to local file /print

    hi ,
    We have a program that displays data on an ALV list. Then, when you click on the 'Print' icon, or try to download to a local file, it gives a short dump with a message 'OBJECTS_NOT_CHARLIKE'.
    Any solutions on the same ....
    thanks

    Hi,
    i hope you have all your data in and internal table.
    If this is so use the following code,
    *--- Down load the file
    CALL FUNCTION 'WS_DOWNLOAD'
    EXPORTING
    filename = lv_file
    filetype = 'DAT'
    TABLES
    data_tab = gt_excel1
    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 i000(zf) WITH text-017.
    ELSE.
    MESSAGE e939(zf) WITH lv_file. "Errors while downloading.
    ENDIF.
    Following should be passed,
    v_file --> file path with file name (provide filename with '.xls' extension)
    gt_excel --> Internal table which has to be downloaded to excel.
    thanks
    vijay
    reward points if helpful.

  • How do I print a list of sent files for the year?

    How do I print a list of sent files for this year?

    Hi lasersrq,
    What a great question! There is no functionality that allows you to print a list the files you've sent via Adobe Send (or SendNow).
    Please feel free to submit a feature request--it's a good idea! https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform&loc=en
    Best,
    Sara

  • Populate updatable drop down list based on files in the folder path

    Hi, 
    I am a beginner in labview. I am stuggling on where to start.
    Here's what I need to do. 
    I want to create an updatable drop down list. It can be automatic upon opening the program or manually update by clicking an update button. The drop down list will list all the filenames that are in .cvs format. These files are stored in a folder path.  Insider the folder, they are stored in different subfolders, the drop box should be able to find those files inside the subfolders. Once the user select a filename from the list, the program will read the data inside that file and import into an array so I can display the data. 
    I have an idea on how to display the data, but I don't how to populate the drop down list based on the files in the folder, make it updatable and then import that user selected file's data into the the array. 
    Can anyone help me with this? 
    Thanks, Ruth

    Yup, ListFolder with a pattern of *.csv.  Then use a property node on a combo box or ring to set the items in the drop down.  Here is some free training if you are interested in learning more general LabVIEW tools.
    NI Learning Center
    NI Getting Started
    -Hardware Basics
    -LabVEW Basics
    -DAQ Application Tutorials
    3 Hour LabVIEW Introduction
    6 Hour LabVIEW Introduction
    Self Paced training for students
    Self Paced training beginner to advanced, SSP Required
    LabVIEW Wiki on Training
    Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
    If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.

  • Special character on reading file in the background

    Hi All.
    I am trying to read a file taht looks like below.
    When I read in background using READ DATASET it gives an extra character in the beginning of the 1st line only.
      OPEN DATASET is_sel_data-app_path IN TEXT MODE ENCODING
      DEFAULT FOR INPUT.
    This does not happen when i read using GUI_UPLOAD.
    This distorts our data column indication in the background. Please suggest what could be the reason for this.
    | |MANDT|MATNR               |WERKS |STAWN              |
    | |203  |000000000010089283  |A041  |38249099           |
    | |203  |000000000010089292  |A041  |38249099           |
    | |203  |000000000010059745  |A041  |38249099           |
    | |203  |000000000010059802  |A041  |34029090           |
    Thanks,
    Vinotha M
    Edited by: Vinotha M on Oct 21, 2010 9:30 AM
    Edited by: Vinotha M on Oct 21, 2010 9:33 AM
    Edited by: Vinotha M on Oct 21, 2010 9:34 AM

    Thanks for your reply!.
    This is a standard GTS Program i.e its a load program.
    Is there anything else I can do.

  • Downloading Document Files in the Background

    Hello,
    I have two questions regarding downloading document files to a Windows server in the background.
    <u>First Question:</u>
    My company is currently on SAP R/3 4.6B. We have several programs that use function module WS_DOWNLOAD to download documents to a Windows directory (C drive, network server, etc.). However, WS_DOWNLOAD will only work when run in the foreground, since there is no connection to the presentation server when run in the background. Our work around for this has been to create a UNIX file and then FTP it to the Windows server, which can all be done in the background. Is there another way to download directly from SAP to a Windows server in the background with 4.6B.
    <u>Second Question:</u>
    We have an upgrade to mySAP ERP 2004 scheduled in the near future. Is it possible to do what I've asked above in mySAP ERP 2004?
    Thanks,
    Jamey

    for your first question
    Well you can do it in two ways.
    1: instead of using FTP from unix, you can use it from within SAP using ftp function modules. for durther details and examples you can check development class SFTP in se80 for function modules and demo programs.
    The advantage of this technique is that if FTP fails for some reason, you abap code can generate a proper error message or log so that user can see that file is not transfered.
    2: you can run sap supplied program RFCEXEC.exe on your windows server thus making it as an RFC server, that create an RFC destination pointing to this server in SAP (Transaction code SM59) and use this destination to call RFC function modules to create a file on destination from an internal table. you can use the RFC function RFC_REMOTE_FILE
    example: your data is in table outtab
      CALL FUNCTION 'RFC_REMOTE_FILE'
         DESTINATION p_dest
         EXPORTING
             file = file
             write = write
         TABLES
             filedata = outtab
         EXCEPTIONS
           communication_failure = 1 MESSAGE msg_text
           system_failure        = 2 MESSAGE msg_text.
    cheers

  • The word "background" is no longer italicized in any of my files in the background layers. The eye and lock remain unchanged. Did I somehow screw this layer up permanently?

    I'm practicing for my photoshop 1 exam and converted the background layer to a regular layer and forgot how to change it back to the background layer format.  I tried going back to the original version of the image via the histogram, that didn't work. So, I closed the doc and didn't save it.  I eventually figured out how to covert the layer back to a background layer (thanks Adobe Help!) but I still notice that the word "background" is no longer italicized in any document that I open.  Did I somehow screw up the background layer in the entire PS program? (I also tried reseting PS on opening - cmd+alt+shift while clicking on the PS icon) Will this change affect the functionality of the background layer? Help Thanks!!!!

    All you need to do is flatten your layers to get a background layer.

  • How to clean up the list of recent files in the Getting Started Window?

    The pinned/not pinned distinction for projects appearing in the getting stared window (GSW) is a bit moot if like me you are working on only a few projects.
    What I find particularly distracting is projects popping up in this list if, say, I check out some examples, or temporarily load a project from an alternate location, etc.
    I want to remove those from the list right away, but as simple as the request sounds, I could not figure out how to do that elegantly.
    Pinning/Unpinning doesn't work, there is no "Clear recent file/project list" in the corresponding LV menus and the only way I can think of doing that is by editing the ini file.
    Am I missing something?

    This has been one of those majorly annoying things I have screamed about for a long time.  And when they created the "new" GSW with the pinned projects and recent files, I was so hoping they would just add a simple right-click menu to remove an item from the list.  But no.  It didn't happen.
    Here are a couple of Idea Exchange entries I found with a really quick search:
    Exclude Examples from RECENT FILES and RECENT PROJECTS
    Menu selections to clear history of recent files and/or projects (wow, only 3 kudos so far!)
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How to Downlaod Data from Alv List to Excel File

    Hi,
      I have a Requirement like While download data from ALV to Excel File .After Download data into Excel we will not allow user to edit the Excel data..
    Plz  help me to complete this scenario.
    Thanks & Regards,
    Kumaran Duraiswamy.

    hi,
    try these following fm's
    MS_EXCEL_OLE_STANDARD_DAT
    EXCEL_OLE_STANDARD_DAT
    CALL FUNCTION 'MS_EXCEL_OLE_STANDARD_DAT'
    EXPORTING
    file_name = 'Your Path' " enter your path to save the file.
    CREATE_PIVOT = 0
    * DATA_SHEET_NAME = ' '
    * PIVOT_SHEET_NAME = ' '
    * PASSWORD = ' '
    * PASSWORD_OPTION = 0
    VISIBLE = '0'
    No_DIALOG = 'X'
    TABLES
    * PIVOT_FIELD_TAB =
    DATA_TAB = t_deli_final
    * FIELDNAMES =
    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.
    2nd fm
      CALL FUNCTION 'EXCEL_OLE_STANDARD_DAT'
           EXPORTING
                FILE_NAME                 = 'Your Path' "path to save your file
                DATA_SHEET_NAME           = V_SHEET_NAME
           TABLES
                DATA_TAB                  = TLX
           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 NE 0.
        WRITE:/ 'ERROR OPENING EXCEL'.
      ENDIF.
    ELSE.
      WRITE:/ 'ERROR OR NO DATA'.
    ENDIF.

  • Alv list display tripple dot behind the character

    Hi everyone,
    when I display my report, I found one colume which is cost center.
    it display like this
         2000020  ...
         2000010  ...
    while another cost center colume display like this
         2000020
         2000020
    so I wonder what is "..." behind the first cost center??
    Is it the standard sign of ALV?, if yes, what is it mean?
    Does anyone has experience about this sign, please kindly advise
    thank you
    Boonsom

    Can you explain more? thank you

  • Attaching office files in the Background

    Dear Friends,
    I want to attach a pdf file via email as a background process in a workflow step,how do I acheive this?
    any solutions
    Thanks & Regards
    Sreeni

    hi sreeni ,
    Create FM and call it from a method or any where. this will help for your problem.
    Re: Sending email attachment as pdf file.
    Posted: Nov 29, 2005 11:02 PM            
    Reply
    E-mail this post
    hi
    this is just a function to send any attachment
    FUNCTION zsend_mail_attachment.
    ""Local interface:
    *"  IMPORTING
    *"     REFERENCE(V_FILE_PATH) TYPE  STRING OPTIONAL
    *"     REFERENCE(V_SUBJECT) TYPE  SO_OBJ_DES
    *"  TABLES
    *"      IT_RECEIVERS STRUCTURE  SOMLRECI1
    *"      IT_MESSAGE STRUCTURE  SOLISTI1
      DATA: gd_cnt TYPE i,
            gd_sent_all(1) TYPE c,
            gd_doc_data LIKE sodocchgi1,
            gd_error TYPE sy-subrc.
      DATA objbin LIKE solisti1 OCCURS 0 WITH HEADER LINE.
      DATA : it_packing_list LIKE sopcklsti1 OCCURS 0 WITH HEADER LINE.
    Binary store for File
      DATA : BEGIN OF it_file OCCURS 0,
               row(255),
             END OF it_file.
    splitting of the filepath
      DATA : BEGIN OF i_split OCCURS 0,
               row(50),
             END OF i_split.
      DATA tab_lines LIKE sy-tabix.
      REFRESH : it_file, objbin, it_packing_list, i_split.
      CLEAR   : it_file, objbin, it_packing_list, i_split.
      DESCRIBE TABLE it_message LINES tab_lines.
      READ     TABLE it_message INDEX tab_lines.
      gd_doc_data-doc_size = ( tab_lines - 1 ) * 255 + STRLEN( it_message ).
      gd_doc_data-obj_langu  = sy-langu.
      gd_doc_data-obj_name   = 'SENDFILE'.
      gd_doc_data-obj_descr  = v_subject.
      gd_doc_data-sensitivty = 'O'.
      CLEAR it_packing_list.
      it_packing_list-head_start = 1.
      it_packing_list-head_num   = 0.
      it_packing_list-body_start = 1.
      it_packing_list-doc_type   = 'RAW'.
      it_packing_list-body_num   = tab_lines.
      APPEND it_packing_list.
      IF v_file_path IS NOT INITIAL.
        DATA : v_len      TYPE i,
               v_index    LIKE sy-index,
               v_doc_type TYPE  so_obj_tp,
               v_filename TYPE  so_obj_des .
        v_len = STRLEN( v_file_path ) - 3.
        v_doc_type = v_file_path+v_len(3) .
        TRANSLATE v_doc_type TO UPPER CASE .
        SPLIT v_file_path AT '\' INTO TABLE i_split .
        DESCRIBE TABLE i_split LINES v_index .
        READ TABLE i_split INDEX v_index .
        v_filename = i_split-row .
        v_len = STRLEN( v_filename ) - 4.
        v_filename = v_filename(v_len) .
    <b>    CALL FUNCTION 'GUI_UPLOAD'
          EXPORTING
            filename = v_file_path
            filetype = 'BIN'
          TABLES
            data_tab = it_file.</b>
        LOOP AT it_file.
          MOVE it_file-row TO objbin-line.
          APPEND objbin.
        ENDLOOP.
        CLEAR it_packing_list.
        DESCRIBE TABLE objbin LINES tab_lines.
        it_packing_list-transf_bin = 'X'.
        it_packing_list-head_start = 1.
        it_packing_list-head_num   = 1.
        it_packing_list-body_start = 1.
        it_packing_list-doc_type   = v_doc_type.
        it_packing_list-body_num   = tab_lines.
        it_packing_list-doc_size   = tab_lines * 255.
        it_packing_list-obj_descr  = v_filename.
        APPEND it_packing_list.
      ENDIF.
    it_receivers-receiver = '[email protected]'.
    it_receivers-rec_type = 'U'.
    it_receivers-com_type = 'INT'.
    APPEND it_receivers .
    Call the FM to post the message to SAPMAIL
      CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
        EXPORTING
          document_data = gd_doc_data
          put_in_outbox = 'X'
          commit_work   = 'X'
      IMPORTING
        sent_to_all = gd_sent_all
        TABLES
          packing_list = it_packing_list
          contents_txt = it_message
          contents_bin = objbin
          receivers    = it_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.
    ENDFUNCTION.
    <b>
    i hope this will solve ur problem</b>
    Regards
    <b>Sankar</b>

  • Extracting object from a picture and erase the background

    Whats the best tool or way to extract an object, or person from a picture and earse the backgroung. Then puting it into illustrator? How do i save it to where theirs no background and only the picture that i selected?

    There is no "best tool". It depends entirely on the image and the talent of the person using the tool (or more likely technique).
    But you may wish to spend some time studying the Pen tool.
    Also, knowing your version of Photoshop would also help those who wish to help you.
    You topic title would also make a great Google search. :)

Maybe you are looking for