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 TO DOWNLOAD THE EXCEL

divsmart
Participant
0 Kudos

code.txtop.jpgexcel-op.jpg

Hi Expert,

I have one task to download the report in "Excel" format. I have designed the ALV but i have issue's in it..

1. My download .XLS format NOT showing the 1st and last column header's name?

2. "the sorted value of price ,currency,weight and unit" value not display in excel download?

Please guidance me what mistake i made. (Attached my code , output(ALV) , excel ).

Thanks,

Senthil.

7 REPLIES 7

Sandra_Rossi
Active Contributor
0 Kudos

Your code is rather short, so you may directly paste it here. You may also show the screenshots instead of attaching them. Like this:

op.jpg:

excel-op.jpg:

Code:

REPORT  zsen_zsflight776.
TABLES: zsflight776.
DATA: it_zsflight776 TYPE TABLE OF zsflight776,
      wa_zsflight776 TYPE          zsflight776.
DATA: it_fcat TYPE lvc_t_fcat,
      wa_fcat TYPE lvc_s_fcat.
DATA: wa_layo TYPE lvc_s_layo.
DATA: BEGIN OF ls_title,
        name TYPE c LENGTH 30,
      END OF ls_title.
DATA: t_header LIKE TABLE OF ls_title.

START-OF-SELECTION.
  PERFORM get_form.
  PERFORM display_form.
  PERFORM f_download.

FORM get_form .

  SELECT carrid
         firstname
         lastname
         dob
         connid
         fldate
         bookid
         forcuram
         forcurkey
         luggweight
         wunit INTO CORRESPONDING FIELDS OF TABLE it_zsflight776 FROM zsflight776.

  SORT it_zsflight776 ASCENDING BY fldate.
  IF sy-subrc = 0.
    APPEND 'Airline Code' TO t_header.
    APPEND 'Firstname'    TO t_header.
    APPEND 'Lastname'     TO t_header.
    APPEND 'Date Of Birth' TO t_header.
    APPEND 'Connection Number' TO t_header.
    APPEND 'Flight date' TO t_header.
    APPEND 'Flight Bookid' TO t_header.
    APPEND 'Flight Price' TO t_header.
    APPEND 'Flight Currency' TO t_header.
    APPEND 'Flight Weight' TO t_header.
    APPEND 'Flight unit' TO t_header.
  ENDIF.
ENDFORM.                    " get_form


FORM display_form .

  CLEAR wa_fcat.
  wa_fcat-fieldname = 'CARRID'.
  wa_fcat-coltext = 'Airline Code'.
  APPEND wa_fcat TO it_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname = 'FIRSTNAME'.
  wa_fcat-coltext = 'Firstname'.
  APPEND wa_fcat TO it_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname = 'LASTNAME'.
  wa_fcat-coltext = 'Lastname'.
  APPEND wa_fcat TO it_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname = 'DOB'.
  wa_fcat-coltext = 'Date Of Birth'.
  APPEND wa_fcat TO it_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname ='CONNID' .
  wa_fcat-coltext = 'Connection Number'.
  APPEND wa_fcat TO it_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname = 'FLDATE' .
  wa_fcat-coltext = 'Flight date'.
  APPEND wa_fcat TO it_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname = 'BOOKID'.
  wa_fcat-coltext = 'Flight Bookid'.
  APPEND wa_fcat TO it_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname = 'FORCURAM'.
  wa_fcat-coltext = 'Flight Price' .
  wa_fcat-do_sum = 'X' .
  wa_fcat-qfieldname = 'FORCURKEY' .
  APPEND wa_fcat TO it_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname = 'FORCURKEY'.
  wa_fcat-coltext = 'Flight Currency'.
  APPEND wa_fcat TO it_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname = 'LUGGWEIGHT'.
  wa_fcat-coltext = 'Flight Weight'.
  wa_fcat-do_sum = 'X' .
  wa_fcat-cfieldname = 'WUNIT' .
  APPEND wa_fcat TO it_fcat.

  CLEAR wa_fcat.
  wa_fcat-fieldname = 'WUNIT'  .
  wa_fcat-coltext = 'Flight unit'.
  APPEND wa_fcat TO it_fcat.


  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      i_callback_program = sy-repid
      is_layout_lvc      = wa_layo
      it_fieldcat_lvc    = it_fcat
      i_default          = 'X'
      i_save             = 'A'
    TABLES
      t_outtab           = it_zsflight776
    EXCEPTIONS
      program_error      = 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.
ENDFORM.                    " display_form


FORM f_download .

  DATA: lv_filename       TYPE string,
        lv_path           TYPE string,
        lv_fullpath       TYPE string,
        lv_result         TYPE i,
        lv_default_fname  TYPE string,
        lv_fname          TYPE string.
*        lv_filesize       TYPE I.

  call method cl_gui_frontend_services=>file_save_dialog
    exporting
      window_title      = 'File Directory'
      default_extension = 'XLS'
      initial_directory = 'D:\'
    changing
      filename          = lv_filename
      path              = lv_path
      fullpath          = lv_fullpath
      user_action       = lv_result.
*  BREAK-POINT.

  lv_fname = lv_fullpath.

  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      bin_filesize        = ''
      filename            = lv_fname
      filetype            = 'DAT'
    TABLES
      data_tab            = it_zsflight776
      fieldnames          = t_header
    EXCEPTIONS
      file_open_error     = 1
      file_write_error    = 2
      invalid_filesize    = 3
      invalid_table_width = 4
      invalid_type        = 5
      no_batch            = 6
      unknown_error       = 7
      OTHERS              = 8.
ENDFORM.                    " f_download

ClausB
Active Participant
0 Kudos

What does your table structure zsflight776 look like?

Sandra_Rossi
Active Contributor
0 Kudos

Could you show the list of fields of zsflight776?

divsmart
Participant
0 Kudos

Hi Expert,

Please find my custom-table.

0 Kudos

Please use the COMMENT button for comments, questions, adding details, replying to OP comment, etc., ANSWER is only to propose a solution, dixit SAP text at the right of the answer area.

If you want to target someone, if this person has posted an Answer, use the button REPLY, if this person is the Original Poster of the question he/she will be automatically informed, otherwise copy/paste their hyperlinked name so that the person receives a warning (NB: @ doesn't work/but typing this character will suggest hyperlinked names).

Sandra_Rossi
Active Contributor
0 Kudos

Fields of zsflight776:

Sandra_Rossi
Active Contributor
0 Kudos

1. My download .XLS format NOT showing the 1st and last column header's name?

Your internal table has first component 'MANDT', hence the downloaded file has MANDT at first position. So you should add 'MANDT' as first column header (T_HEADER).

2. "the sorted value of price ,currency,weight and unit" value not display in excel download?

Your internal table doesn't contain what is displayed in the ALV. If you want your internal table contain the sum of columns by currency code, you have to do code it yourself (not related to ALV).