‎2006 Sep 11 1:50 PM
Hii All,
I wanted to download data from text file into ABAP Database Table.Can any one help me out in this regard by giving a simple example of textfile having only two columns.
Thanks in Advance.
Devendra Phate.
‎2006 Sep 11 1:57 PM
If I understand your requirement well you wish to upload the data from a text file to a database table.
U can use the below logic.
1. Upload the text file using GUI_UPLOAD function module.
2. Validate the upload data.
3. If correct, populate the database table.
CALL FUNCTION 'GUI_UPLOAD'
exporting
filename = 'C:\test.txt'
table
data_tab = itab.
Loop at itab.
-->Validate the record.
modify ztab from itab.
endloop.
‎2006 Sep 11 1:57 PM
Hi devendrakumar,
1. use this kind of logic.
2. a) first use GUI_UPLOAD fm
to upload the text file data
into internal table.
b) suppose your internal table is same as
your Database table format,
c) then
d) LOOP AT ITAB.
MODIFY ZDBTAB FROM ITAB.
ENDLOOP.
Note : MODIFY statement will automatically
take care of insert/update
based upon the primary key combination
found / not found in z table.
regards,
amit m.
‎2006 Sep 11 2:03 PM
Hi devendrakumar,
1. use this kind of logic.
2. a) first use GUI_UPLOAD fm
to upload the text file data
into internal table.
b) suppose your internal table is same as
your Database table format,
c) then
d) LOOP AT ITAB.
MODIFY ZDBTAB FROM ITAB.
ENDLOOP.
Note : MODIFY statement will automatically
take care of insert/update
based upon the primary key combination
found / not found in z table.
regards,
amit m.
‎2006 Sep 11 2:45 PM
hi,
chk this, put the data into an excel file.then download.
suppose data base name is
db_name_age
fields inside it are name and age.
**************************************
sample excel sheet.
coloumn 1 is name and column 2 is age
name age
A 8
C 13
D 55
************************************
DATA : int_excel LIKE alsmex_tabline OCCURS 0 WITH HEADER LINE.
data : record like db_name_age occurs 0 with header line.
DATA : v_start_col TYPE i VALUE '1', "starting col
v_start_row TYPE i VALUE '1', " starting row
v_end_col TYPE i VALUE '2', " total columns
v_end_row TYPE i VALUE '10'. "total no of record
FORM f_upload .
CLEAR : int_excel, int_excel[].
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = wf_filename
i_begin_col = v_start_col
i_begin_row = v_start_row
i_end_col = v_end_col
i_end_row = v_end_row
TABLES
intern = int_excel
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.
IF sy-subrc <> 0.
*Message is 'Unable to upload data from ' wf_filename.
MESSAGE e169(zm050) WITH wf_filename.
ELSE.
SORT int_excel BY row col.
REFRESH : record.
CLEAR : record.
LOOP AT int_excel.
CASE int_excel-col. "go thru each column.
WHEN 1.
record-name = int_excel-value.
WHEN 2.
record-age = int_excel-value.
ENDCASE.
AT END OF row.
APPEND record.
CLEAR record.
ENDAT.
ENDLOOP.
*inserting into table
modfiy db_name_age from table record.
ENDIF.
if this helped pld rewrd points,
rgrds
anver