2008 Jun 16 12:59 PM
Hi Experts,
I had an .csv file in the PC which I brought into an internal table btab using the FM ALSM_EXTERN_TO_INTERNAL_TABLE.This CSV file contains 15 rows of header and then the body.
Btab has the structure of ALSMEX_TABLINE.
Now I want to put the whole internal table data into a dataset in the application server.I have a directory in the server.
How do I do this so that the whole internal table is transferred into the dataset.
Please help.Im stuck.
Regards
Ankit Harish
Hi Experts,
I had an .csv file in the PC which I brought into an internal table btab using the FM ALSM_EXTERN_TO_INTERNAL_TABLE.This CSV file contains 15 rows of header and then the body.
Btab has the structure of ALSMEX_TABLINE.
Now I want to put the whole internal table data into a dataset in the application server.I have a directory in the server.
How do I do this so that the whole internal table is transferred into the dataset.
Please help.Im stuck.
Regards
Ankit Harish
2008 Jun 16 1:04 PM
Hi,
use open dataset <dsname> for input in text mode encoding default.
if sy-subrc = 0.
do.
transfer itab to <dsnam>.
endddo.
endif.
close dataset.
<dsnam.> file is created in ur directory.
for this u have to give a path .
go to AL11 and see the file.
Rgds.,
subash
2008 Jun 16 1:06 PM
A sample program for you.
DATA: file TYPE string VALUE `test.dat`,
result TYPE string.
loop at itab into wa.
OPEN DATASET file FOR OUTPUT IN TEXT MODE
ENCODING DEFAULT
WITH SMART LINEFEED.
TRANSFER wa TO file.
endloop.
CLOSE DATASET file.
Here test.dat is the file in your app server. if it is inside any directory place it before with front slash.
itab is your internal table you have got and wa is each record of it.
reward points if useful.
Thanks,
Mainak
2008 Jun 16 1:08 PM
Use AUTHORITY_CHECK_DATASET for writing into application server.
Use OPEN DATA (filename) FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
If sy-subrc eq 0.
TRANSFER It_header TO (filename).
endif.
CLOSE DATASET (filename).
Regards
Kannaiah
2008 Jun 16 1:08 PM
Hello,
Try using the open dataset command.
A file test.dat is created as a text file, then filled with data, changed, and read. Since each TRANSFER statement adds on an end-of-line selection to the written content, the content of the file is double-lined after the change. The first line contains " 12ABCD". The second line contains "890". The character "7" was overwritten by the end-of-line selection of the first line.
DATA: file TYPE string VALUE `test.dat`,
result TYPE string.
OPEN DATASET file FOR OUTPUT IN TEXT MODE
ENCODING DEFAULT
WITH SMART LINEFEED.
TRANSFER `1234567890` TO file.
CLOSE DATASET file.
OPEN DATASET file FOR UPDATE IN TEXT MODE
ENCODING DEFAULT
WITH SMART LINEFEED
AT POSITION 2.
TRANSFER `ABCD` TO file.
CLOSE DATASET file.
OPEN DATASET file FOR INPUT IN TEXT MODE
ENCODING DEFAULT
WITH SMART LINEFEED.
WHILE sy-subrc = 0.
READ DATASET file INTO result.
WRITE / result.
ENDWHILE.
CLOSE DATASET file.
INCLUDE ABAPOPEN_DATASET_ENCODING OBJECT DOKU ID SD
INCLUDE ABAPOPEN_DATASET_LINEFEED OBJECT DOKU ID SD
Regards.
2008 Jun 16 1:09 PM
use..
wf_path_c2 is the path in appserver where the table needs to be stored.
OPEN DATASET wf_path_c2 FOR OUTPUT IN TEXT "binary "TEXT150408
MODE.
IF sy-subrc NE 0 .
CLEAR wf_path_c2.
EXIT.
ELSE.
*---Data is downloaded to the application server file path
CLEAR wa_c2_output.
LOOP AT tb_c2_output INTO wa_c2_output.
TRANSFER wa_c2_output TO wf_path_c2 .
CLEAR wa_c2_output.
ENDLOOP.
ENDIF.
*--Close the Application server file .
CLOSE DATASET wf_path_c2.
Reward points...if its useful...
Regards
Rudra
2008 Jun 16 1:09 PM
Hi ,
below is sample code to upload file on Application server...
Note: Instead a select query below ... you use function module to retrieve data....
TABLES:
bkpf.
*" Parameters..........................................................*
PARAMETERS:
p_bukrs TYPE bkpf-bukrs, " Company Code
p_gjahr TYPE bkpf-gjahr. " Fiscal Year
*" Data declarations...................................................
*"--------------------------------------------------------------------*
* Work variables *
*"--------------------------------------------------------------------*
DATA:
w_file_path(35) TYPE c VALUE 'yh1071_trainee.txt'.
" Apllication Server File Name
*"--------------------------------------------------------------------*
* Declaring Internal Table To hold Accounting Document table *
*"--------------------------------------------------------------------*
DATA :
t_bkpf LIKE
STANDARD TABLE
OF bkpf.
*"--------------------------------------------------------------------*
* Data declaration of the structure to hold data from table bkpf *
*"--------------------------------------------------------------------*
DATA: fs_bkpf LIKE LINE OF t_bkpf.
*"--------------------------------------------------------------------*
* AT SELECTION-SCREEN. *
*"--------------------------------------------------------------------*
AT SELECTION-SCREEN .
IF p_bukrs IS INITIAL AND p_gjahr IS INITIAL.
MESSAGE 'Enter the Values' TYPE 'E'.
ENDIF. " IF p_bukrs IS INITIAL.
*"--------------------------------------------------------------------*
* START-OF-SELECTION. *
*"--------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM get_data_from_account_table.
*"--------------------------------------------------------------------*
* END-OF-SELECTION. *
*"--------------------------------------------------------------------*
END-OF-SELECTION.
PERFORM write_data_into_file.
*&---------------------------------------------------------------------*
*& Form get_data_from_account_table *
*&---------------------------------------------------------------------*
* Subroutine to Get data from Accounting Document Header Table *
*----------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine. *
*----------------------------------------------------------------------*
FORM get_data_from_account_table .
SELECT bukrs " Company Code
belnr " Bill Number
gjahr " Fiscal Year
blart " Document Type
bldat " Bill Date
FROM bkpf
INTO CORRESPONDING FIELDS
OF TABLE t_bkpf
WHERE bukrs EQ p_bukrs
AND gjahr EQ p_gjahr.
CHECK sy-subrc NE 0.
MESSAGE e008(ztrainees).
ENDFORM. " get_data_from_account_table
*&---------------------------------------------------------------------*
*& Form write_data_into_file *
*&---------------------------------------------------------------------*
* Subroutine to write data into application server file. *
*----------------------------------------------------------------------*
* There are no interface parameters to be passed to this subroutine. *
*----------------------------------------------------------------------*
FORM write_data_into_file .
OPEN DATASET w_file_path FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc EQ 0.
LOOP AT t_bkpf INTO fs_bkpf.
TRANSFER fs_bkpf TO w_file_path.
CLEAR fs_bkpf.
ENDLOOP. " LOOP AT t_bkpf INTO fs_bkpf
ENDIF. " IF sy-subrc EQ 0
CLOSE DATASET w_file_path. " Closing file
ENDFORM. " write_data_into_fileregards ,
Brijesh...
2008 Jun 16 1:15 PM
Hi Ankit,
use the data set to transfer the data from internal table to App server.
Sample code to refer the below links
[http://abap4.tripod.com/Upload_and_Download_ABAP_Source_Code.html|http://abap4.tripod.com/Upload_and_Download_ABAP_Source_Code.html]
[http://www.sapfans.com/sapfans/alex.htm|http://www.sapfans.com/sapfans/alex.htm].
or
use the method APPSERVER_FILE_WRITE of class CL_RSAN_UT_APPSERV_FILE_WRITER to transfer the data from internal table to App server.
CL_RSAN_UT_APPSERV_FILE_WRITER=>APPSERVER_FILE_WRITE.
Sample.
REPORT zb_file.
TYPES: ty_line TYPE string,
ty_t_type TYPE STANDARD TABLE OF ty_line .
DATA: it_tab TYPE ty_t_type,
wa_tab TYPE ty_line.
CONCATENATE 'Welcome' 'to all' INTO wa_tab SEPARATED BY space.
APPEND wa_tab TO it_tab.
CLEAR wa_tab.
START-OF-SELECTION.
CALL METHOD cl_rsan_ut_appserv_file_writer=>appserver_file_write
EXPORTING
i_filename ='\tmp'
i_lines_from = 1
i_lines_to = -1
i_overwrite = SPACE
i_data_tab = it_tab
IMPORTING
e_lines_written =
EXCEPTIONS
open_failed = 1
write_failed = 2
close_failed = 3
OTHERS = 4
.
IF sy-subrc <> 0.
CASE sy-subrc.
WHEN 1.
MESSAGE 'Open failed' TYPE 'E'.
WHEN 2.
MESSAGE 'Write failed' TYPE 'E'.
WHEN 3.
MESSAGE 'Close failed' TYPE 'E'.
ENDCASE.
ENDIF.
it_tab is the table of string type.
so you concatenate your data and fill the internal table it_tab
Reward if found helpful.
Regards,
Boobalan Suburaj