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: 

Header Filednames not showing in FM GUI_DOWNLOAD

former_member207480
Participant
0 Kudos

Hi,

I am generting csv file with some sales data and trying to capture the header fieldnames of each field by using FM GUI_DOWNLOAD.

I have passed the required header fields in FM through internal table but,only data is coming in csv file. The header fields are showing blank.

Please suggest the same.

Thanks & Regards

Amol Khochare

8 REPLIES 8

Richa_Gupta
Contributor
0 Kudos

Hi Amol,

Please share your logic how are you trying to achieve this.

If you are populating the header field names in the correct way at index 1 of internal table, it should be downloaded.

Regards,

Richa

0 Kudos

Hi Richa,

Please check the code below.

TYPE-POOLS: truxs.

   TYPES : BEGIN OF ty_afpo,

           aufnr TYPE afpo-aufnr,

           kdauf TYPE afpo-kdauf,

           kdpos TYPE afpo-kdpos,

           END OF ty_afpo,

           BEGIN OF ty_vbpa,

           vbeln TYPE vbpa-vbeln,

           kunnr TYPE vbpa-kunnr,

           pernr TYPE vbpa-pernr,

           parvw TYPE vbpa-parvw,

           END OF ty_vbpa,

           BEGIN OF ty_vbak,

           vbeln TYPE vbak-vbeln,

           kunnr TYPE vbak-kunnr,

           vkorg TYPE vbak-vkorg,

           vtweg TYPE vbak-vtweg,

           spart TYPE vbak-spart,

           END OF ty_vbak,

           BEGIN OF ty_knmt,

           kunnr TYPE knmt-kunnr,

           vkorg TYPE knmt-vkorg,

           vtweg TYPE knmt-vtweg,

           kdmat TYPE knmt-kdmat,

           postx TYPE knmt-postx,

           END OF ty_knmt,

           BEGIN OF ty_header,

           handling_units(2),

           plant(4),

           sold_to(10),

           sold_to_name(40),

           ship_to(10),

           ship_to_name(40),

           location(35),

           customer_product_code(35),

           customer_product_desc(40),

           material_id(18),

           material_desc(40),

           production_order(10),

           hu_qty(18),

           hu_uom(3),

           delivery(10),

           delivery_item(6),

           so_item(16),

           sales_order(10),

           sales_item(6),

           END OF ty_header.

   DATA : wa_header LIKE LINE OF it_header,

          wa_items LIKE LINE OF it_items,

          it_hulblsv TYPE TABLE OF zhulblsv,

          wa_hulblsv TYPE zhulblsv,

          gt_text TYPE truxs_t_text_data,

          filepath TYPE string,

          i_header TYPE TABLE OF ty_header,

          w_header TYPE ty_header,

          x_header TYPE xstring,

          it_afpo  TYPE TABLE OF ty_afpo,

          wa_afpo  TYPE          ty_afpo,

          it_vbpa_ag  TYPE TABLE OF ty_vbpa,

          wa_vbpa_ag  TYPE          ty_vbpa,

          it_vbpa_we  TYPE TABLE OF ty_vbpa,

          wa_vbpa_we  TYPE          ty_vbpa,

          it_vbak     TYPE TABLE OF ty_vbak,

          wa_vbak     TYPE          ty_vbak,

          it_knmt     TYPE TABLE OF ty_knmt,

          wa_knmt     TYPE          ty_knmt.

*         is_header51 TYPE          header51,

*         it_header2  LIKE LINE OF is_header51.

   MOVE 'Handling Unit'     TO w_header-handling_units.

   MOVE 'Plant'             TO w_header-plant.

   MOVE 'Sold-To'           TO w_header-sold_to.

   MOVE 'Sold-To-Name'      TO w_header-sold_to_name.

   MOVE 'Ship-To'           TO w_header-ship_to.

   MOVE 'Ship-To-Name'      TO w_header-ship_to_name.

   MOVE 'Location'          TO w_header-location.

   MOVE 'Cust Product Code' TO w_header-customer_product_code.

   MOVE 'Cust Product Desc' TO w_header-customer_product_desc.

   MOVE 'Material Id'       TO w_header-material_id.

   MOVE 'Material Desc'     TO w_header-material_desc.

   MOVE 'Prod Order'        TO w_header-production_order.

   MOVE 'HU Qty'            TO w_header-hu_qty.

   MOVE 'HU Uom'            TO w_header-hu_uom.

   MOVE 'Delivery No'       TO w_header-delivery.

   MOVE 'Delivery Item'     TO w_header-delivery_item.

   MOVE 'So & Item'         TO w_header-so_item.

   MOVE 'Sales Order'       TO w_header-sales_order.

   MOVE 'Sales Item'        TO w_header-sales_item.

   APPEND w_header TO i_header.

   IF it_items[] IS NOT INITIAL.

     LOOP AT it_items INTO wa_items.

       READ TABLE it_header INTO wa_header WITH KEY

       venum = wa_items-venum.

       IF sy-subrc = 0.

         MOVE : wa_header-exidv      TO wa_hulblsv-exidv,

                wa_items-werks       TO wa_hulblsv-werks,

                wa_items-matnr       TO wa_hulblsv-matnr,

                wa_header-vpobjkey   TO wa_hulblsv-aufnr,

                wa_items-vemng       TO wa_hulblsv-vemng,

                wa_items-vemeh       TO wa_hulblsv-vemeh,

                wa_items-vbeln       TO wa_hulblsv-vbeln,

                wa_items-posnr       TO wa_hulblsv-posnr,

                wa_items-sonum       TO wa_hulblsv-sonum,

                wa_items-sonum+0(10) TO wa_hulblsv-vgbel,

                wa_items-sonum+10(6) TO wa_hulblsv-vgpos.

         APPEND wa_hulblsv TO it_hulblsv.

       ENDIF.

       CLEAR : wa_hulblsv,wa_items,wa_header.

     ENDLOOP.

   ENDIF.

   SORT it_hulblsv BY exidv.

   DELETE ADJACENT DUPLICATES FROM it_hulblsv.

   IF it_hulblsv[] IS NOT INITIAL.

     SELECT aufnr kdauf kdpos FROM afpo

       INTO TABLE it_afpo

       FOR ALL ENTRIES IN it_hulblsv

       WHERE aufnr = it_hulblsv-aufnr.

     IF it_afpo[] IS NOT INITIAL.

       SELECT vbeln kunnr pernr parvw FROM vbpa

         INTO TABLE it_vbpa_ag

         FOR ALL ENTRIES IN it_afpo

         WHERE vbeln = it_afpo-kdauf

         AND parvw = 'AG'.

       SELECT vbeln kunnr pernr parvw FROM vbpa

         INTO TABLE it_vbpa_we

         FOR ALL ENTRIES IN it_afpo

         WHERE vbeln = it_afpo-kdauf

         AND parvw = 'WE'.

     ENDIF.

     SELECT vbeln kunnr vkorg vtweg spart FROM vbak

       INTO TABLE it_vbak

       FOR ALL ENTRIES IN it_afpo

       WHERE vbeln = it_afpo-kdauf.

     IF it_vbak[] IS NOT INITIAL.

       SELECT kunnr vkorg vtweg kdmat postx FROM knmt

         INTO TABLE it_knmt

         FOR ALL ENTRIES IN it_vbak

         WHERE kunnr = it_vbak-kunnr

         AND vkorg = it_vbak-vkorg

         AND vtweg = it_vbak-vtweg.

     ENDIF.

   ENDIF.

   SORT it_afpo BY aufnr.

   SORT it_vbpa_ag BY vbeln.

   SORT it_vbpa_we BY vbeln.

   LOOP AT it_hulblsv INTO wa_hulblsv.

     CALL FUNCTION 'GET_PLANT_DETAILS'

   EXPORTING

     i_werks               = wa_hulblsv-werks

    i_get_address         = ','

  IMPORTING

    e_name                = wa_hulblsv-e_name

    e_addr1               = wa_hulblsv-e_addr1

    e_addr2               = wa_hulblsv-e_addr2

    e_addr3               = wa_hulblsv-e_addr3

    e_addr4               = wa_hulblsv-e_addr4

*       E_T001W               =

  EXCEPTIONS

    not_found             = 1

    parameter_error       = 2

    OTHERS                = 3

           .

     IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

     ENDIF.

     MODIFY it_hulblsv FROM wa_hulblsv.

     READ TABLE it_afpo INTO wa_afpo WITH KEY

     aufnr = wa_hulblsv-aufnr BINARY SEARCH.

     IF sy-subrc = 0.

       IF wa_hulblsv-vgbel IS INITIAL.

         wa_hulblsv-vgbel = wa_afpo-kdauf.

         wa_hulblsv-vgpos = wa_afpo-kdpos.

         MODIFY it_hulblsv FROM wa_hulblsv.

       ENDIF.

     ENDIF.

     READ TABLE it_vbpa_ag INTO wa_vbpa_ag WITH KEY

     vbeln = wa_hulblsv-vgbel BINARY SEARCH.

     IF sy-subrc = 0.

       IF wa_vbpa_ag-parvw = 'AG'.

         wa_hulblsv-kunag = wa_vbpa_ag-kunnr.

       ENDIF.

       MODIFY it_hulblsv FROM wa_hulblsv.

     ENDIF.

     READ TABLE it_vbpa_we INTO wa_vbpa_we WITH KEY

     vbeln = wa_hulblsv-vgbel BINARY SEARCH.

     IF sy-subrc = 0.

       IF wa_vbpa_we-parvw = 'WE'.

         wa_hulblsv-kunnr = wa_vbpa_we-kunnr.

       ENDIF.

       MODIFY it_hulblsv FROM wa_hulblsv.

     ENDIF.

     SELECT SINGLE name1 FROM kna1 INTO (wa_hulblsv-shipto_name)

           WHERE kunnr = wa_hulblsv-kunag.

     MODIFY it_hulblsv FROM wa_hulblsv.

     SELECT SINGLE name1 ort01 FROM kna1

       INTO (wa_hulblsv-soldto_name,wa_hulblsv-ort01)

           WHERE kunnr = wa_hulblsv-kunnr.

     MODIFY it_hulblsv FROM wa_hulblsv.

     READ TABLE it_vbak INTO wa_vbak WITH KEY

     vbeln = wa_hulblsv-vgbel.

     IF sy-subrc = 0.

       READ TABLE it_knmt INTO wa_knmt WITH KEY

       kunnr = wa_vbak-kunnr

       vkorg = wa_vbak-vkorg

       vtweg = wa_vbak-vtweg.

       IF sy-subrc = 0.

         wa_hulblsv-kdmat = wa_knmt-kdmat.

         wa_hulblsv-postx = wa_knmt-postx.

         MODIFY it_hulblsv FROM wa_hulblsv.

       ENDIF.

     ENDIF.

     SELECT SINGLE maktx FROM makt INTO wa_hulblsv-maktx

       WHERE matnr = wa_hulblsv-matnr

       AND spras = 'EN'.

     MODIFY it_hulblsv FROM wa_hulblsv.

     CLEAR : wa_hulblsv,wa_vbpa_ag,wa_vbpa_we,wa_afpo,wa_vbak,wa_knmt.

   ENDLOOP.

   CALL FUNCTION 'SAP_CONVERT_TO_TEX_FORMAT'

     EXPORTING

       i_field_seperator    = ','  " Comma seperator

       i_line_header        = 'X'

     TABLES

       i_tab_sap_data       = it_hulblsv

     CHANGING

       i_tab_converted_data = gt_text

     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.

   filepath = 'D:\Parksons Packaging\HU Label Development\Label.csv'.

   CALL METHOD cl_gui_frontend_services=>gui_download(

     EXPORTING

       filename                = filepath

       fieldnames              = i_header

       append                  = 'X'

     CHANGING

       data_tab                = gt_text

*      fieldnames              = i_header

     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

       not_supported_by_gui    = 22

       error_no_gui            = 23

       OTHERS                  = 24 ).

   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 & Regards

Amol Khochare

0 Kudos

Hi Amol,

Why in CHANGING parameter of the FM GUI_DOWNLOAD, the line fieldnames = header is commented.

Please uncomment it and try to run your program.

Regards,

Swati

0 Kudos

Hi Swati,

I had tried before but, I got the below syntax error while checking and activating the code.

Formal parameter "FIELDNAMES" is not a CHANGING parameter; it is a

IMPORTING parameter.

Thanks & Regards

Amol Khochare

0 Kudos

HI,

The definition in ty_header should be like below.

types: begin of ty_header,

     text(35),

end of ty_header.

data: t_header type standard table of ty_header,

          w_header type ty_header.

w_header-text = 'Handling Unit'.

append w_header to t_header.

Now append all your header like this and then pass T_HEADER in the fieldnames parameter.

Hope this helps.

VenkatRamesh_V
Active Contributor
0 Kudos

Hi Amol,

Inside a function module,  Header line is cleared by default.

View the sample code logic,

TYPES: BEGIN OF ty_tab,

        matnr type mara-matnr,

        mtart type mara-mtart,

        matkl type mara-matkl,

        END OF ty_tab,

       

        begin of ty_excel_heading,

          text(20) type c,

       end of ty_excel_heading.

DATA: lt_heading    type table of ty_excel_heading,

       excel_heading like line of  lt_heading,

       it_tab        type table of ty_tab,

       wa_tab        like line of  it_tab,

       lv_heading    type string,

       itab          type table of string,

         xtab        type string,

         lv_path     type string.

START-OF-SELECTION.

wa_tab-matnr = '100'.

wa_tab-mtart = 'FERT'.

wa_tab-matkl = 'RG1'.

APPEND wa_tab to it_tab.

excel_heading-text = 'Material'.

APPEND excel_heading TO lt_heading.

excel_heading-text = 'Type'.

APPEND excel_heading TO lt_heading.

excel_heading-text = 'Group'.

APPEND excel_heading TO lt_heading.

LOOP AT lt_heading into excel_heading.

IF sy-tabix EQ 1.

lv_heading = excel_heading-text.

ELSE.

CONCATENATE lv_heading excel_heading INTO lv_heading SEPARATED BY ','.

ENDIF.

ENDLOOP.

MOVE lv_heading to xtab.

APPEND xtab to itab.

LOOP AT it_tab into wa_tab.

CLEAR xtab.

CONCATENATE wa_tab-matnr

             wa_tab-mtart

             wa_tab-matkl

             INTO xtab

             SEPARATED BY ','.

APPEND xtab to itab.

ENDLOOP.

     CALL FUNCTION 'GUI_DOWNLOAD'

       EXPORTING

         filename              = lv_path

         filetype              = 'ASC'

         append                = 'X'

         trunc_trailing_blanks = 'X'

         show_transfer_status  = 'X'

       TABLES

         data_tab              = itab

       EXCEPTIONS

         file_open_error       = 1

         file_write_error      = 2

         OTHERS                = 3.


Hope it helpful,

Regards,

Venkat

ipravir
Active Contributor
0 Kudos

Hi Amol,

Follow the below flow to get the data in EXCEL with Header.

DATA: BEGIN OF HEADER OCCURS 1,

       STRING(255),

     END OF TB_HEADER.

append field name in HEADER table as below

CONCATENATE

field_name1

field_name

.

.N into header-string seperated by '|'.

then create file with header.

call CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD

EXPORTING

    FILENAME = File_name

CHANGING

    DATA_TAB                  = tb_header[].

then append file table data into excel.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD

      EXPORTING

        FILENAME                  = File_name

        DAT_MODE                  = 'A'

CHANGING

        DATA_TAB                  = Internal_table.

Regards,

Praveer.

akshatrander1990
Explorer
0 Kudos

Hi Amol,

Try this.

*---- Add Header Structure in File

call function 'GUI_DOWNLOAD'

   exporting

    filename                        = lv_filename

    filetype                        = 'ASC'

   tables

    data_tab                        = gt_filehead          "Header Structure Table

  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.

*---- Add Data in File

call function 'GUI_DOWNLOAD'

   exporting

    filename                        = lv_filename

    filetype                        = 'ASC'

    append                          = 'X'            " Add Data below Header Structure

    trunc_trailing_blanks           = 'X'

   tables

    data_tab                        = gt_final       " Data Table

  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 eq 0.

    concatenate text-003 lv_filename into lv_message separated by space.

   message lv_message type 'S'.

   endif.