Skip to Content
avatar image
Former Member

Internal Table to Excel using GUI_DOWNLOAD

Hi experts,

I have a requirement to extract all process chain ids and download it as an excel file. I am able to get the list of the active process chains from RSPCLOGCHAIN table and then put it on an internal table and then to an excel file using FM GUI_DOWNLOAD. But my problem is, I have to put headers on my excel file. I must have three fields: chain_id, start date, and start time. Just to be clear, the start date and start time fields must be empty because after a user downloads the generated file, he/she must input the start date and start time of when that specific process chain is scheduled to run and then upload that excel file back to the program. Below is my code, the problem here is, the 'start date' and 'start time' is not showing, only the 'chain id'. I have used the 'FIELDNAMES' parameter of GUI_DOWNLOAD to append my headers. Is there something wrong with what I am doing? Any help would be appreciated. Thanks!

REPORT  ZGETLIST_TEST.

PARAMETERS : PC_FILE(150).

TYPES : BEGIN OF GTY_FIELDNAMES,

               TITLE(100),

         END OF GTY_FIELDNAMES.

DATA: GIT_FIELDNAMES TYPE STANDARD TABLE OF GTY_FIELDNAMES,

       GWA_FIELDNAMES TYPE GTY_FIELDNAMES.

DATA : GD_FILENAME TYPE STRING,

        GD_PATH     TYPE STRING,

        GD_FULLPATH TYPE STRING,

        GD_RESULT   TYPE I.

DATA: BEGIN OF GIT_FINAL OCCURS 0,

           chainid type rspclogchain-chain_id,

       END OF GIT_FINAL.

SELECT DISTINCT chain_id  FROM rspclogchain INTO TABLE GIT_FINAL UP TO 50 ROWS.

CLEAR GWA_FIELDNAMES.

GWA_FIELDNAMES-TITLE = 'Chain ID'.

APPEND GWA_FIELDNAMES TO GIT_FIELDNAMES.

CLEAR GWA_FIELDNAMES.

GWA_FIELDNAMES-TITLE = 'Start Date'.

APPEND GWA_FIELDNAMES TO GIT_FIELDNAMES.

CLEAR GWA_FIELDNAMES.

GWA_FIELDNAMES-TITLE = 'Start Time'.

APPEND GWA_FIELDNAMES TO GIT_FIELDNAMES.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR PC_FILE.

CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG

   EXPORTING

     WINDOW_TITLE      = 'Save File As...'

     DEFAULT_EXTENSION = 'XLS'

     DEFAULT_FILE_NAME = 'PCList'

     INITIAL_DIRECTORY = 'C:\'

   CHANGING

     FILENAME          = GD_FILENAME

     PATH              = GD_PATH

     FULLPATH          = GD_FULLPATH

     USER_ACTION       = GD_RESULT.

CHECK GD_RESULT EQ '0'.

PC_FILE = GD_FULLPATH.

* Check user did not cancel request

START-OF-SELECTION.

CALL FUNCTION 'GUI_DOWNLOAD'

   EXPORTING

     FILENAME              = GD_FULLPATH

     FILETYPE              = 'ASC'

     WRITE_FIELD_SEPARATOR = 'X'

   TABLES

     DATA_TAB              = GIT_FIELDNAMES                  " Internal table having data

    FIELDNAMES            = GIT_FIELDNAMES     " Internal table having headings

   EXCEPTIONS

     FILE_OPEN_ERROR       = 1                           "#EC ARGCHECKED

     FILE_WRITE_ERROR      = 2

     OTHERS                = 3.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    avatar image
    Former Member
    Oct 19, 2015 at 06:06 AM

    Hi,

    Two corrections:

    Add the date and time fields in below structure

    DATA: BEGIN OF GIT_FINAL OCCURS 0,

               chainid type rspclogchain-chain_id,

               date type datum,  -> added

                time type SYTIME,  -> added

           END OF GIT_FINAL.


    And pass the data while calling FM


       TABLES

         DATA_TAB              = GIT_FInal       and not field name.

    Regards,

    Pranav.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi @Pranavjeet

      This solved my problem. I am receiving the standard format of date and time on my excel because of sydatum and time. Thanks!

      Regards,

      Rhonald

  • Oct 19, 2015 at 05:23 AM

    You download data from SAP into Excel, so that data can be entered and the Excel uploaded? Why not write a program in SAP that allows the data to be entered directly?`

    Seems a crazy design to me.

    Add comment
    10|10000 characters needed characters exceeded

    • Firstly, your solution is already sub-optimal. You are proposing an internal table with a header line. Such constructs are obsolete and should be avoided.

      Do not confuse a requirement with a proposed solution. The requirement in this instance is to be able to set the schedule for process chains. The solution proposed is "download, modify in Excel, upload".

      Years ago, I was asked (by a FICO functional analyst) to make a report downloadable, so that the users could cut and paste the report results from excel into the selection screen of another report. Both reports were custom. I suggested that perhaps they'd like the first report modified so that it could directly call the second report with the selected data. The response was "wow - you can do that?". The users were delighted with the new solution as it made their lives so much easier.

      Always be prepared to challenge requirements if you can suggest a better way. Developers can (and should) have a role in improving user experience. Be proactive.

  • Oct 19, 2015 at 04:56 AM

    Hi Rhonald,

    please try it with

    TYPES : BEGIN OF GTY_FIELDNAMES,

                   TITLE(20),

            END OF GTY_FIELDNAMES.

    Same issue?

    Regards,

    Klaus

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 19, 2015 at 05:55 AM

    What - exactly - is your problem, you want to have solved?

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 19, 2015 at 07:26 AM

    Hi,

    Pass your Final internal table for the tables Data tab not your fieldnames table.

    regards,

    Revan.

    Add comment
    10|10000 characters needed characters exceeded