DBF Upload

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

Post Reply
ilgvars
Posts: 5
Joined: Mon Oct 21, 2002 2:34 am

DBF Upload

Post by ilgvars » Mon Oct 21, 2002 2:37 am

Hi,

is it possible upload a DBF (FoxPro) file into internal table? May be somebody knows some smart sollution?

Ilgvars

TwoABAPers
Posts: 990
Joined: Sun Oct 20, 2002 9:16 pm
Location: web
Contact:

Post by TwoABAPers » Tue Oct 22, 2002 1:19 am

Hello Ilgvars.

Don't know if it is the smart solution you were looking for or not.

1. Download the data from DBF to text format. (copy to <filename> sdf)
2. Use normal SAP FMs for data upload.

Regards
Sudhir/Mohit

Marina
Posts: 53
Joined: Tue Oct 22, 2002 5:24 am
Location: Russia

Post by Marina » Tue Oct 22, 2002 6:42 am

Hi!
I have a code of a form which uploads .dbf file, but what really this form does is: opens .dbf in Excel
saves it as .dat file
uploads .dat file into internal table
deletes .dat file
If you are interested I can mail you the code
Marina

ilgvars
Posts: 5
Joined: Mon Oct 21, 2002 2:34 am

Post by ilgvars » Thu Oct 24, 2002 7:15 am

Hi, Marina!

I am very interested in this code. Please, send this code to:
ilgvars.lopatko@microlink.lv


Thanks,
Ilgvars
Last edited by ilgvars on Thu Oct 24, 2002 7:16 am, edited 1 time in total.

kevin
Posts: 147
Joined: Sun Oct 20, 2002 10:18 pm
Location: Mumbai, India
Contact:

Post by kevin » Sun Oct 27, 2002 10:17 pm

Hi Marina,

the cod4 sounds interesting,

Could you mail it to me -> kevin_hill68@yahoo.co.in



Thanks and regards,

Kevin Hill

Marina
Posts: 53
Joined: Tue Oct 22, 2002 5:24 am
Location: Russia

Post by Marina » Sun Oct 27, 2002 11:47 pm

Hi!
Here is a text of the form I've mentioned:

Code: Select all

*&---------------------------------------------------------------------*
*&      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
Marina

Fishal
Posts: 25
Joined: Wed Dec 17, 2003 7:20 am

Upload from DBase format

Post by Fishal » Thu Jan 29, 2004 6:22 am

The solution proposed below fails miserably for large DBF files because Excel cannot open files with millions of records.

I hope someone has a better solution, one in which the DBF file itself could be shoved down SAP's throat!

:P

Please help!
Thanks!

Fishal

Dr Sidewalk
Posts: 3531
Joined: Mon Oct 21, 2002 11:06 am
Location: Everywhere...

eh!

Post by Dr Sidewalk » Thu Jan 29, 2004 6:25 am

Jesus, why make life so hard for yourself.

Foxpro can be output in comma delimetered mode, so why not use it ?
There's a standard foxpro (DBF) export tool for this.

Dr Sidewalk
"In the middle of difficulty lies opportunity" - Albert Einstein
"Money isn't everything in life, unless you don't have it"
"Fail to plan, plan to fail"
"Success is a journey, not a destination."

Fishal
Posts: 25
Joined: Wed Dec 17, 2003 7:20 am

No such function

Post by Fishal » Thu Jan 29, 2004 7:17 am

Apparently this version of Foxpro (release 1988) has no such export function. So we are back to square one.

:lol:
Thanks!

Fishal

Post Reply