‎2007 Aug 06 3:52 AM
Hi,
I want to download data into a textfile with the fieldname of an internal table as the header line. What would be the easiest way of doing that ?
For eg.
PERNR BEGDA ENDDA <-- is the Header
10000000 20070101 99991231 <-- is the data
I tried using :- Insert wa into itab index 1 but it insert a blank line instead of the fieldname.
Can anyone advice me ?
p/s: i've search thru the forum but none i find it helpful for my case.
Thanks,
Loo
‎2007 Aug 06 3:55 AM
IT_HEADING-TEXT = 'Company Code'.
append IT_HEADING.
IT_HEADING-TEXT = 'RFQ Number'.
append IT_HEADING.
IT_HEADING-TEXT = 'RFQ Line Item'.
append IT_HEADING.
IT_HEADING-TEXT = 'MO Number'.
append IT_HEADING.
IT_HEADING-TEXT = 'MO Text'.
append IT_HEADING.
IT_HEADING-TEXT = 'Material SVC Grp'.
append IT_HEADING.
IT_HEADING-TEXT = 'PO Number'.
append IT_HEADING.
IT_HEADING-TEXT = 'PO Line Item'.
append IT_HEADING.
IT_HEADING-TEXT = 'RFQ Quantity'.
append IT_HEADING.
IT_HEADING-TEXT = 'RFQ Unit'.
append IT_HEADING.
IT_HEADING-TEXT = 'RFQ Amount'.
append IT_HEADING.
IT_HEADING-TEXT = 'RFQ Currency'.
append IT_HEADING.
IT_HEADING-TEXT = 'RFQ Platform'.
append IT_HEADING.
IT_HEADING-TEXT = 'RFQ Equipment'.
append IT_HEADING.
IT_HEADING-TEXT = 'PO Quantity'.
append IT_HEADING.
IT_HEADING-TEXT = 'PO Unit'.
append IT_HEADING.
IT_HEADING-TEXT = 'PO Amount'.
append IT_HEADING.
IT_HEADING-TEXT = 'PO Currency'.
append IT_HEADING.
IT_HEADING-TEXT = 'PO Platform'.
append IT_HEADING.
IT_HEADING-TEXT = 'PO Equipment'.
append IT_HEADING.
move P_FNAME to L_FNAME.
call function 'GUI_DOWNLOAD'
exporting
FILENAME = L_FNAME
FILETYPE = 'DAT'
tables
DATA_TAB = IT_FINAL
FIELDNAMES = IT_HEADING " HEADER to be passed here
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 <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.Regards
Gopi
‎2007 Aug 06 3:59 AM
Hardcoding it is the best option
second best option would be to generate a subroutine pool
to do that you have to make a program in an internal table (you can easily put the fieldnames in that program by getting the names from REUSE_ALV_FIELDCATALOG_MERGE
" internal table declaration
data: begin of gt_itab occurs 0,
line(255) type c,
end of gt_itab.and after populating the internal table, use this
data: gv_fname(30) type c value 'ZTEST_KRIS', "program name
gv_err(120) type c. "error variable
generate subroutine pool gt_itab name gv_fname message gv_err.
if sy-subrc eq 0.
perform exec_sql in program (gv_fname) using it_mara
if found.
write:/ gv_err .
clear gv_err.
endif.
‎2007 Aug 06 4:17 AM
Hi Kris,
I wouldn't want to hardcode the fieldname as i'll be downloading more than 1 file which doesn't seems to be the feasible way. _
Is there any other way than using the subroutine and to grab the fieldname using this FM REUSE_ALV_FIELDCATALOG_MERGE??
Thanks,
Loo
‎2007 Aug 06 4:20 AM
‎2007 Aug 06 4:23 AM
use the fn module GET_COMPONENT_LIST
DATA : IRSTRUCINFO LIKE RSTRUCINFO OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'GET_COMPONENT_LIST'
EXPORTING
PROGRAM = sy-repid
FIELDNAME = 'ITAB' "INT_TABNAME
TABLES
COMPONENTS = IRSTRUCINFO.
now pass the irstrucinfo to gui_download.
regards
shiba dutta