10-19-2015 4:08 AM
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.
10-19-2015 7: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.
10-19-2015 5:56 AM
Hi Rhonald,
please try it with
TYPES : BEGIN OF GTY_FIELDNAMES,
TITLE(20),
END OF GTY_FIELDNAMES.
Same issue?
Regards,
Klaus
10-19-2015 6: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.
10-19-2015 7:17 AM
Hi Matthew,
The requirements are given like that. Maybe because the users are more used to maintaining their data using spreadsheets.
10-19-2015 8:43 AM
10-19-2015 9:37 AM
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.
10-19-2015 6:55 AM
10-19-2015 7: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.
10-19-2015 7:19 AM
10-19-2015 7:24 AM
Hi Rhonald,
No change is required in select statement - it will only fill the chain_id field of the structure/table - date and time will remain initial as you need.
Regards,
Pranav.
10-19-2015 8:20 AM
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
10-19-2015 8:26 AM
Hi,
Pass your Final internal table for the tables Data tab not your fieldnames table.
regards,
Revan.