09-10-2008 11:42 AM
hi all ,
i have data in my ztable (zcust) and i need to download it into a notepad. i hav started but it gives me runtime error when calling the FM i,e gui_download. so pls can u correct my code incase if i have gone wrong. below is my code:
PARAMETERS: p_file TYPE rlgrap-filename.
Data: Begin of i_string occurs 0,
line(1024) type c,
End of i_string.
types: begin of s_cust1,
zempno like zcust1-zempno,
zcustnumber like zcust1-zcustnumber,
zcustname like zcust1-zcustname,
zcustbd like zcust1-zcustbd,
zno_chil like zcust1-zno_chil,
END OF s_cust1.
data: i_cust1 TYPE STANDARD TABLE OF s_cust1 WITH HEADER LINE.
data: wa_cust1 like LINE OF i_cust1.
Data: filename type string,
delim(1) type c value '|',
g_lines type i.
select zempno
zcustnumber
zcustname
zcustbd
zno_chil
from zcust1
into CORRESPONDING FIELDS OF TABLE i_cust1.
if sy-subrc = 0.
message i009(zdd) with 'records fetched'.
endif.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
CHANGING
file_name = p_file.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = 'c:\Documents and Settings\Desktop\down.txt'
FILETYPE = 'ASC'
WRITE_FIELD_SEPARATOR = 'X'
tables
data_tab = i_cust1.
thanks in advance
jacob
09-10-2008 11:43 AM
Hi,
In FM,
in parameter FILENAME, give p_file, the variable in which you are getting the filename from 'KD_GET_FILENAME_ON_F4'.
Try with this. If any further issue, revert back.
Regards
Natasha Garg
09-10-2008 11:48 AM
hi ,
PARAMETERS: p_file TYPE rlgrap-filename.
DATA: BEGIN OF i_string OCCURS 0,
line(1024) TYPE c,
END OF i_string.
TYPES: BEGIN OF s_cust1,
zempno LIKE zcust1-zempno,
zcustnumber LIKE zcust1-zcustnumber,
zcustname LIKE zcust1-zcustname,
zcustbd LIKE zcust1-zcustbd,
zno_chil LIKE zcust1-zno_chil,
END OF s_cust1.
DATA: i_cust1 TYPE STANDARD TABLE OF s_cust1 WITH HEADER LINE.
DATA: wa_cust1 LIKE LINE OF i_cust1.
data : w_path type string . "------> declare this variable
DATA: filename TYPE string,
delim(1) TYPE c VALUE '|',
g_lines TYPE i.
SELECT zempno
zcustnumber
zcustname
zcustbd
zno_chil
FROM zcust1
INTO CORRESPONDING FIELDS OF TABLE i_cust1.
IF sy-subrc = 0.
MESSAGE i009(zdd) WITH 'records fetched'.
ENDIF.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
CHANGING
file_name = p_file.
w_path = p_file. "-------> include this in ur code
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
* bin_filesize =
filename = w_path "--------> pass this path as parameter
filetype = 'ASC'
* append = ' '
write_field_separator = 'X'
TABLES
data_tab = i_cust1.
*
IF sy-subrc 0.
* message id sy-msgid type sy-msgty number sy-msgno
* with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
09-10-2008 11:56 AM
it works fine but how can i display the data in the note pad pls assist me
if sy-subrc = 0.
loop at i_cust1.
split i_string-line at delim into i_cust1-zempno i_cust1-zcustnumber i_cust1-zcustname.
append i_cust1.
endloop.
endif.
DESCRIBE TABLE i_cust1 LINES g_lines.
write : g_lines, 'lines updated into notepad'.
will it work fine ????????//
09-10-2008 11:48 AM
I think you are getting short dump when you are passing the p_file directly(since filename should be string).
I just used sflight instead of your table.
REPORT ztest_file.
DATA: BEGIN OF i_string OCCURS 0,
line(1024) TYPE c,
END OF i_string.
DATA: i_cust1 TYPE STANDARD TABLE OF sflight WITH HEADER LINE.
DATA: wa_cust1 LIKE LINE OF i_cust1.
DATA: filename TYPE string,
delim(1) TYPE c VALUE '|',
g_lines TYPE i.
PARAMETERS: p_file TYPE rlgrap-filename.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
CHANGING
file_name = p_file.
START-OF-SELECTION. "Added
IF p_file IS NOT INITIAL.
filename = p_file. "Added
ENDIF.
SELECT *
FROM sflight
INTO CORRESPONDING FIELDS OF TABLE i_cust1.
IF sy-subrc = 0.
MESSAGE i009(zdd) WITH 'records fetched'.
ENDIF.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = filename "Added
filetype = 'ASC'
write_field_separator = 'X'
TABLES
data_tab = i_cust1.
09-10-2008 11:53 AM
09-10-2008 12:01 PM
After Download you want the data to be displayed in the notepad .
By default a file will be created in the specified path.
if you want to show it in the notepad then...you can do some thing like this...
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = filename
filetype = 'ASC'
write_field_separator = 'X'
TABLES
data_tab = i_cust1.
cl_gui_frontend_services=>execute(
EXPORTING
DOCUMENT = filename
OPERATION = 'OPEN'
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
BAD_PARAMETER = 3
FILE_NOT_FOUND = 4
PATH_NOT_FOUND = 5
FILE_EXTENSION_UNKNOWN = 6
ERROR_EXECUTE_FAILED = 7
SYNCHRONOUS_FAILED = 8
NOT_SUPPORTED_BY_GUI = 9
).
IF sy-subrc ne 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.