01-16-2007 2:41 PM
Hi,
I want to access the file from application server. for that i want to put the file from presentation server to application server.
In the flat file the seperator is tab. and it is having 9 fields. I want to put the file file into application server. for that first i uploaded the file into an internal table using 'gui_upload'. i given filetype as 'asc' and the seperator is 'X'. it is working fine.
Then in the program, i read the file into an internal table having one field text(255) type char. Then i am trying to split the record into an internal table having 9 fields. But only the first field i am able to get into the required internal table. the sy-subrc is returning 4. How can i get all the fields into the required internal table.
But in the 'gui_upload' if i remove the seperator i am able to get all the records. But i want to give the seperator and i want to get all the fields here........ Can any body help me how to get.......
If any body having the code, to upload the file using 'gui_upload' and then to put the file into application server in real time scenario, Please send it to me.......
Urgent....
Thanks & Regards............
01-16-2007 2:58 PM
Hi Anil,
<b>has_field_separator = 'X' "file is TAB delimited</b>
This indicates the file is tab delimited , since u r giving ASC u should give space in has_field_separator
Check this code,
REPORT zuploadtab .
PARAMETERS: p_infile LIKE rlgrap-filename
OBLIGATORY DEFAULT '/usr/sap/'..
*DATA: ld_file LIKE rlgrap-filename.
DATA: gd_file type string.
*Internal tabe to store upload data
TYPES: BEGIN OF t_record,
name1 LIKE pa0002-vorna,
name2 LIKE pa0002-name2,
age TYPE i,
END OF t_record.
DATA: it_record TYPE STANDARD TABLE OF t_record INITIAL SIZE 0,
wa_record TYPE t_record.
*Internal table to upload data into
DATA: BEGIN OF it_datatab OCCURS 0,
row(500) TYPE c,
END OF it_datatab.
*Text version of data table
TYPES: BEGIN OF t_uploadtxt,
name1(10) TYPE c,
name2(15) TYPE c,
age(5) TYPE c,
END OF t_uploadtxt.
DATA: wa_uploadtxt TYPE t_uploadtxt.
*String value to data in initially.
DATA: wa_string(255) TYPE c.
CONSTANTS: con_tab TYPE x VALUE '09'.
*If you have Unicode check active in program attributes then you will
*need to declare constants as follows:
*class cl_abap_char_utilities definition load.
*constants:
con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB.
************************************************************************
*AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_INFILE.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_infile.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_filename = p_infile
mask = ',*.txt.'
mode = 'O'
title = 'Upload File'(078)
IMPORTING
filename = p_infile
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.
************************************************************************
*START-OF-SELECTION
START-OF-SELECTION.
gd_file = p_infile.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = gd_file
has_field_separator = 'X' <b>"file is TAB delimited</b>
TABLES
data_tab = it_record
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 NE 0.
write: 'Error ', sy-subrc, 'returned from GUI_UPLOAD FM'.
skip.
endif.
<b>* Alternative method, where by you split fields at each TAB after you
have returned the data. No point unless you dont have access to
GUI_UPLOAD but just included for information
*
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = gd_file
filetype = 'ASC'
TABLES
data_tab = it_datatab "ITBL_IN_RECORD[]
EXCEPTIONS
file_open_error = 1
OTHERS = 2.
IF sy-subrc NE 0.
ELSE.
LOOP AT it_datatab.
CLEAR: wa_string, wa_uploadtxt.
wa_string = it_datatab.
SPLIT wa_string AT con_tab INTO wa_uploadtxt-name1
wa_uploadtxt-name2
wa_uploadtxt-age.
MOVE-CORRESPONDING wa_uploadtxt TO wa_record.
APPEND wa_record TO it_record.
ENDLOOP.
ENDIF.
***********************************************************************
*END-OF-SELECTION
END-OF-SELECTION.
*!! Text data is now contained within the internal table IT_RECORD
Display report data for illustration purposes
LOOP AT it_record INTO wa_record.
WRITE:/ sy-vline,
(10) wa_record-name1, sy-vline,
(10) wa_record-name2, sy-vline,
(10) wa_record-age, sy-vline.
ENDLOOP.</b>
01-16-2007 2:53 PM
01-16-2007 2:58 PM
Hi Anil,
<b>has_field_separator = 'X' "file is TAB delimited</b>
This indicates the file is tab delimited , since u r giving ASC u should give space in has_field_separator
Check this code,
REPORT zuploadtab .
PARAMETERS: p_infile LIKE rlgrap-filename
OBLIGATORY DEFAULT '/usr/sap/'..
*DATA: ld_file LIKE rlgrap-filename.
DATA: gd_file type string.
*Internal tabe to store upload data
TYPES: BEGIN OF t_record,
name1 LIKE pa0002-vorna,
name2 LIKE pa0002-name2,
age TYPE i,
END OF t_record.
DATA: it_record TYPE STANDARD TABLE OF t_record INITIAL SIZE 0,
wa_record TYPE t_record.
*Internal table to upload data into
DATA: BEGIN OF it_datatab OCCURS 0,
row(500) TYPE c,
END OF it_datatab.
*Text version of data table
TYPES: BEGIN OF t_uploadtxt,
name1(10) TYPE c,
name2(15) TYPE c,
age(5) TYPE c,
END OF t_uploadtxt.
DATA: wa_uploadtxt TYPE t_uploadtxt.
*String value to data in initially.
DATA: wa_string(255) TYPE c.
CONSTANTS: con_tab TYPE x VALUE '09'.
*If you have Unicode check active in program attributes then you will
*need to declare constants as follows:
*class cl_abap_char_utilities definition load.
*constants:
con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB.
************************************************************************
*AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_INFILE.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_infile.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_filename = p_infile
mask = ',*.txt.'
mode = 'O'
title = 'Upload File'(078)
IMPORTING
filename = p_infile
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.
************************************************************************
*START-OF-SELECTION
START-OF-SELECTION.
gd_file = p_infile.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = gd_file
has_field_separator = 'X' <b>"file is TAB delimited</b>
TABLES
data_tab = it_record
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 NE 0.
write: 'Error ', sy-subrc, 'returned from GUI_UPLOAD FM'.
skip.
endif.
<b>* Alternative method, where by you split fields at each TAB after you
have returned the data. No point unless you dont have access to
GUI_UPLOAD but just included for information
*
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = gd_file
filetype = 'ASC'
TABLES
data_tab = it_datatab "ITBL_IN_RECORD[]
EXCEPTIONS
file_open_error = 1
OTHERS = 2.
IF sy-subrc NE 0.
ELSE.
LOOP AT it_datatab.
CLEAR: wa_string, wa_uploadtxt.
wa_string = it_datatab.
SPLIT wa_string AT con_tab INTO wa_uploadtxt-name1
wa_uploadtxt-name2
wa_uploadtxt-age.
MOVE-CORRESPONDING wa_uploadtxt TO wa_record.
APPEND wa_record TO it_record.
ENDLOOP.
ENDIF.
***********************************************************************
*END-OF-SELECTION
END-OF-SELECTION.
*!! Text data is now contained within the internal table IT_RECORD
Display report data for illustration purposes
LOOP AT it_record INTO wa_record.
WRITE:/ sy-vline,
(10) wa_record-name1, sy-vline,
(10) wa_record-name2, sy-vline,
(10) wa_record-age, sy-vline.
ENDLOOP.</b>
01-16-2007 3:30 PM
Moving ahead from the previous posts..Considering that the data is read perfectly and residing seperately in the corresponding 9 different fields.
Here I am sending you details of how to write file onto Application Server.
IF NOT INT_FILE[] IS INITIAL.
OPEN DATASET APP_FILE_PATH FOR OUTPUT IN TEXT MODE.
LOOP AT INT_FILE.
CONCATENATE INT_FILE-FIELD1
INT_FILE-FIELD2
....
INT_FILE-FIELD9
to TXTLINE SEPERATED BY ';'.
TRANSFER TXTLINE TO FILE_PATH.
ENDLOOP.
CLOSE DATASET APP_FILE_PATH.
ENDIF.
If this post is helpful please reward points.
Rgds,
Mayank
01-16-2007 3:05 PM
Hi,
If you want to do it through program, then call the FM:
C13Z_FRONT_END_TO_APPL to upload the file from presentation server to Application server.
Regards
Subramanian
01-16-2007 4:47 PM
Hi Anil why dont you use the function module : ARCHIVFILE_CLIENT_TO_SERVER directly to upload the file to the application server?