Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Uploading DBF file

Former Member
0 Likes
1,859

Dear friends,

I'm trying to upload DBF file.

I can easily convert DBF to CSV in excel and upload the CSV file by standard FM. But client wants to upload directly from DBF, no conversion in between.

I resoted to following techniques:-

1. Tried WS_UPLOAD, UPLOAD, GUI_UPLOAD without any successful results.

2. Convert DBF to DAT using include ole2incl but no conversion happening.

The above mentioned ways were of no help. Please suggest a way to crack this problem.

Regards,

Deva Jyothi Singh.

Dear friends,

I'm trying to upload DBF file.

I can easily convert DBF to CSV in excel and upload the CSV file by standard FM. But client wants to upload directly from DBF, no conversion in between.

I resoted to following techniques:-

1. Tried WS_UPLOAD, UPLOAD, GUI_UPLOAD without any successful results.

2. Convert DBF to DAT using include ole2incl but no conversion happening.

The above mentioned ways were of no help. Please suggest a way to crack this problem.

Regards,

Deva Jyothi Singh.

8 REPLIES 8
Read only

andreas_mann3
Active Contributor
0 Likes
1,371

Hi,

try CL_GUI_FRONTEND_SERVICES method GUI_UPLOAD

Andreas

Read only

0 Likes
1,371

Hi Andreas,

Thanx friend. But the static method GUI_UPLOAD of class CL_GUI_FRONTEND_SERVICES uses GUI_UPLOAD FM only.

Regards,

Deva.

Read only

Former Member
0 Likes
1,371

Hi,

RSUT_TABLE_TO_TEXT_FORMAT

Check this FM. I think it may be helpful as there is a parameter I_FORMAT DEFAULT 'ASC'

here i think u can specify the format which you want

Read only

0 Likes
1,371

Hi Lavanya,

The FM RSUT_TABLE_TO_TEXT_FORMAT works for converting an ITAB to CSV text. It doesn't convert my local DBF file to CSV.

Thanx for replying.

Regards,

Deva.

Read only

0 Likes
1,371

hi,

direct conversion is not possible bec at some level size will issue .

Read only

Former Member
0 Likes
1,371

Hi Deva Jyothi Singh,

Try the below code...

This form does is: opens .dbf in Excel,saves it as .dat file ,uploads .dat file into internal table,deletes .dat file.

&----


*& Form load_dbf_file

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM load_dbf_file TABLES input_table

USING value(t_filename) LIKE rlgrap-filename.

DATA: application TYPE ole2_object,

workbooks TYPE ole2_object,

fworkbook TYPE ole2_object,

fsheets TYPE ole2_object,

fsheet TYPE ole2_object,

dsheet TYPE ole2_object,

frange TYPE ole2_object,

frow TYPE ole2_object.

DATA: return,

filename(128) TYPE c,

l_filename TYPE string.

  • Filename conversion

MOVE t_filename TO filename.

TRANSLATE t_filename TO UPPER CASE.

REPLACE '.DBF' WITH '.DAT' INTO t_filename.

IF sy-subrc NE 0.

  • error - filename extension is not DBF "TODO

MESSAGE w899(f5) WITH 'Error - filename extension is not DBF'.

EXIT.

ENDIF.

  • check file existence

CALL FUNCTION 'WS_QUERY'

EXPORTING

filename = filename

query = 'FE'

IMPORTING

return = return

EXCEPTIONS

inv_query = 1

no_batch = 2

frontend_error = 3

OTHERS = 4.

IF ( sy-subrc NE 0 ) OR ( return EQ 0 ).

  • error - file does not exist "TODO

MESSAGE w899(f5) WITH 'Error - file does not exist'.

EXIT.

ENDIF.

          • Working through OLE (MS Excel) *****

  • OLE initialization

CREATE OBJECT dsheet 'Excel.Sheet'.

IF sy-subrc NE 0.

  • error - OLE initialization of MS Excel "TODO

MESSAGE e899(f5) WITH 'Error - OLE initialization of MS Excel'.

EXIT.

ENDIF.

  • supress messages from MS Excel

CALL METHOD OF dsheet 'Application' = application.

SET PROPERTY OF application 'DisplayAlerts' = 0.

  • opening DBF-file

CALL METHOD OF application 'Workbooks' = workbooks.

CALL METHOD OF workbooks 'Open' EXPORTING #1 = filename

#2 = 0

#3 = 1.

  • remove header line from DBF data

GET PROPERTY OF application 'ActiveWorkbook' = fworkbook.

CALL METHOD OF fworkbook 'Sheets' = fsheets.

CALL METHOD OF fsheets 'Item' = fsheet EXPORTING #1 = 1.

GET PROPERTY OF fsheet 'Rows' = frange.

CALL METHOD OF frange 'Item' = frow EXPORTING #1 = 1.

CALL METHOD OF frow 'Delete'.

  • save as DAT file

CALL METHOD OF fworkbook 'SaveAs' EXPORTING #1 = t_filename

#2 = 20.

  • close the book without saving

CALL METHOD OF fworkbook 'Close' EXPORTING #1 = 0.

  • &#1086;&#1095;&#1080;&#1089;&#1090;&#1082;&#1072; &#1089;&#1089;&#1099;&#1083;&#1082;&#1080; &#1085;&#1072; OLE-&#1086;&#1073;&#1098;&#1077;&#1082;&#1090;

FREE OBJECT dsheet.

          • Filling internal table with data *****

REFRESH input_table.

l_filename = t_filename.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = l_filename

has_field_separator = 'X'

TABLES

data_tab = input_table

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.

  • error - loading DAT file "TODO

MESSAGE w899(f5) WITH 'Error - loading DAT file'.

EXIT.

ELSE.

  • the loading was successfull "TODO

ENDIF.

          • Delete temporary DAT-file *****

CALL FUNCTION 'GUI_DELETE_FILE'

EXPORTING

file_name = t_filename

EXCEPTIONS

OTHERS = 1.

IF sy-subrc <> 0.

CALL FUNCTION 'WS_QUERY'

EXPORTING

filename = t_filename

query = 'FE'

IMPORTING

return = return

EXCEPTIONS

inv_query = 1

no_batch = 2

frontend_error = 3

OTHERS = 4.

IF ( sy-subrc NE 0 ) OR ( return EQ 0 ).

EXIT.

ELSE.

  • error - deleting temporary file "TODO

ENDIF.

ENDIF.

ENDFORM. " load_dbf_file

You can even try this...Foxpro can be output in comma delimetered mode, so why not use it ?

There's a standard foxpro (DBF) export tool for this.

Regards,

Raj

Read only

0 Likes
1,371

Hi Raj,

Thanx. I tried this set of code which was earlier posted in SDN. But it doesn't seem to work.

Regards,

Deva.

Read only

0 Likes
1,371