06-14-2007 11:03 AM
Hi ,
I am new to OOP ABAP.i want the code to upload a flat file from PC to appl server using CL_GUI_FRONTEND_SERVICES.
Thanks,
Rakesh.
06-14-2007 11:11 AM
Hi,
check this code below
DATA:
FRONTEND TYPE REF TO CL_GUI_FRONTEND_SERVICES,
GUI_FILENAME TYPE STRING.
CREATE OBJECT FRONTEND
EXCEPTIONS
NOT_SUPPORTED_BY_GUI = 1
CNTL_ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL METHOD FRONTEND->GUI_UPLOAD "replace UPLOAD
EXPORTING
FILENAME = GUI_FILENAME
FILETYPE = 'ASC'
* HAS_FIELD_SEPARATOR = 'X' "for tab separated import
CHANGING
DATA_TAB = _TAB
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
NOT_SUPPORTED_BY_GUI = 17
ERROR_NO_GUI = 18
OTHERS = 19.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
06-14-2007 11:11 AM
Hi,
check this code below
DATA:
FRONTEND TYPE REF TO CL_GUI_FRONTEND_SERVICES,
GUI_FILENAME TYPE STRING.
CREATE OBJECT FRONTEND
EXCEPTIONS
NOT_SUPPORTED_BY_GUI = 1
CNTL_ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL METHOD FRONTEND->GUI_UPLOAD "replace UPLOAD
EXPORTING
FILENAME = GUI_FILENAME
FILETYPE = 'ASC'
* HAS_FIELD_SEPARATOR = 'X' "for tab separated import
CHANGING
DATA_TAB = _TAB
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
NOT_SUPPORTED_BY_GUI = 17
ERROR_NO_GUI = 18
OTHERS = 19.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
06-14-2007 11:15 AM
Hi,
How should i declare the internal table.Its giving error for the follwoing:
DATA : begin of itab,
rec(500) type c,
end of itab.
06-14-2007 11:18 AM
Hi Rakesh ,
Here is a code which worked well inm y system
types : begin of ty_1 ,
str type string ,
end of ty_1.
data : it_1 type table of ty_1.
data : file type string.
file = 'c:arun.txt'.
start-of-selection.
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = file
* FILETYPE = 'ASC'
* HAS_FIELD_SEPARATOR = SPACE
* HEADER_LENGTH = 0
* IMPORTING
* FILELENGTH =
* HEADER =
changing
data_tab = it_1
* EXCEPTIONS
* FILE_OPEN_ERROR = 1
* FILE_READ_ERROR = 2
* NO_BATCH = 3
* GUI_REFUSE_FILETRANSFER = 4
* INVALID_TYPE = 5
* NO_AUTHORITY = 6
* UNKNOWN_ERROR = 7
* BAD_DATA_FORMAT = 8
* HEADER_NOT_ALLOWED = 9
* SEPARATOR_NOT_ALLOWED = 10
* HEADER_TOO_LONG = 11
* UNKNOWN_DP_ERROR = 12
* ACCESS_DENIED = 13
* DP_OUT_OF_MEMORY = 14
* DISK_FULL = 15
* DP_TIMEOUT = 16
* others = 17
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
Hope this helps.
Regards
Arun
06-14-2007 11:20 AM
hi,
declare internal table using TYPE REF TO keyword which has the structure of CL_GUI_FRONTEND_SERVICES as
data: itab TYPE REF TO CL_GUI_FRONTEND_SERVICES with header line.
then
call function CL_GUI_FRONTEND_SERVICES
importing.........
exporting.........
tables
tab = itab.
if sy-subrc ne 0...........
if help ful reward some points.
with regards,
suresh.
06-14-2007 11:22 AM
Hi,
Please have a look at the below data.You can copy the same to a text file and try reading it in ITAB using GUI_UPLOAD.The problem here is it reads only data.
Please have a look at my code also.
DATA : file type rlgrap-filename.
data : begin of itab occurs 0,
rec(80) type c,
end of itab.
clear : itab.
refresh : itab.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'C:\bop3.txt'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
VIRUS_SCAN_PROFILE =
IMPORTING
FILELENGTH =
HEADER =
TABLES
DATA_TAB = itab
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
open dataset file for output in text mode encoding default.
clear itab.
loop at itab.
transfer itab-rec to file.
clear itab.
endloop.
close dataset file.
DATA IS :
078041953 0000000001000000052507 0000070000 R 078041953 0000000003000000052507 0000199500 R 078041953 0000000005000000052507 0000530000 R 078041953 0000000007000000052507 0000005000 R 078041953 0000000008000000052507 0000004000 R 078041953 0001000000000000052507 0000058250 R 029005582 0001000000000000052507 0000012300 R 029005582 0001000001000000052507 0009438200 R 030404975 0001000000000000052507 0000056700 R 030404975 0001000001000000052507 0000004500 R 314018577 0001000002000000052507 0000001500 R 314018577 0001000003000000052507 0000435300 R 314018577 0001000007000000052507 0000066600 R
Thanks,
Rakesh.
06-14-2007 11:30 AM
Hi Rakesh ,
What i understand is that the data given here is given as a single line and not as is displayed.
To see this open your file in notepad and follow the menu Format->Word Wrap.
Uncheck it , basically what word wrap does is it accomodiates the string based on the length of your window and the rest of the string is displayed on the next line.
Please check it at your end , and revert back.
Regards
Arun
06-14-2007 11:33 AM
hi,
OOP'S doesn,t support internal table with header line, for that sake u must create internal table without header line.
1) create internal table in SE11 using objects <b>LINE TYPE</b>(it's behave like work area) and<b> ROW TYPE</b> (it's behave like body).
<b>or</b>
<b>1) create structure in program.</b>
data/types: begin of stru,
field1 type <refarence-field>,
field2 type <refarence-field>,
end of stru.
<b>2) create header line(work area).</b>
data: it_wa type/like stru.
<b>3) create internal table body.</b>
data: it_body type table of stru.
for uploading we use gui_upload, it is static(class based method) forthat we call this method by using CLASS NAME cl_gui_frontend_services.
call method cl_gui_frontend_services=>gui_upload
exporting
filename = ' ' " here specifies the file name
file type = 'asc' "default
has_field_separator = 'x'
changing
data_tab = it_body.
regards,
Ashokreddy.