Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

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.

Tags:
Former Member
Former Member replied

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.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question