SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Загрузка DBF в таблицу с использованием ODBC Data Source



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Programming Techniques | Приемы программирования -> Conversion
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Wed Dec 10, 2008 9:27 pm    Post subject: Загрузка DBF в таблицу с использованием ODBC Data Source Reply with quote

Автор: NickS
Source: http://www.sapboard.ru/forum/viewtopic.php?f=13&t=63439

Code:
* создаем объекты
  CREATE OBJECT excel 'EXCEL.APPLICATION'.
  subrc1 '052'  .
*  SET PROPERTY OF excel 'Visible'    = 1.
  CALL METHOD OF excel 'Workbooks' = h_book.
  subrc1 '053'  .
  CALL METHOD OF h_book 'Add'.
  subrc1 '053' .
  CALL METHOD OF excel 'Worksheets' = h_sheet
    EXPORTING #1 = 'Лист1'.
  subrc1 '053' .
  CALL METHOD OF h_sheet 'Activate'.
  subrc1 '053' .
  SET PROPERTY OF excel 'DisplayAlerts' = 'False'.
  subrc1 '054' .
  GET PROPERTY OF excel 'ActiveWorkBook' = h_book.
  subrc1 '054' .
* сохраняем книгу
  CALL METHOD OF h_book 'SAVEAS'
    EXPORTING #1 = lc_temp.
  subrc1 '053' .
  SET PROPERTY OF excel 'DisplayAlerts' = 'True'.
  subrc1 '054' .
  connectionstring  = 'ODBC;DSN=dBASE Files;DefaultDir=C:\;DriverId=533;MaxBufferSize=2048;PageTimeout=5;'.
* создаем соединение и строим запрос к БД
  CONCATENATE 'SELECT NEWNUM as BANKL, NEWNUM as bnklz, NAMEP as banka , NNP as ort01, KSNP as BRNCH, ADR as STRAS FROM '
               tab_file-filename INTO sql SEPARATED BY space.
  CALL METHOD OF h_sheet 'Range' = h_range
    EXPORTING #1 = 'A1'.
  subrc1 '053' .
  CALL METHOD OF h_range 'WorkSheet' = h_tables.
  subrc1 '053' .
  CALL METHOD OF h_tables 'QueryTables' = h_tables.
  subrc1 '053' .
  CALL METHOD OF h_tables 'Add' = h_table
    EXPORTING
    #1 = connectionstring
    #2 = h_range
    #3 = sql.
  subrc1 '053'.
  SET PROPERTY OF h_table 'AdjustColumnWidth' = 0.
  subrc1 '054' .
  SET PROPERTY OF h_table 'RefreshStyle' = 0.
  subrc1 '054'.
* считываем данные из БД
  CALL METHOD OF h_table 'Refresh'.
  subrc1 '053' .
*** вставляем задержку
  WAIT UP TO '1.200' SECONDS.
  CALL METHOD OF h_table 'Delete'.
  subrc1 '053' .
  CALL FUNCTION 'FLUSH'
    EXCEPTIONS
      OTHERS = 1.
  IF sy-subrc NE 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
** Удаляем запрос из книги (данные остаются)
  GET PROPERTY OF  h_sheet 'UsedRange' = h_over.
  GET PROPERTY OF  h_over  'Rows'      = h_over1.
  GET PROPERTY OF h_over1  'Count'     = lc_count.   "определяем к-во записей в запросе
  IF lc_count < 2.     " на всякий случай если ошибемся
    lc_count =  9999.
  ENDIF.
* Close  и выходим из Excel
  CALL METHOD OF h_book 'SAVE'.
  subrc1 '053'.
  CALL METHOD OF h_book 'CLOSE'.
  subrc1 '053' .
  CALL METHOD OF excel 'QUIT'.
  subrc1 '053' .
  free_ole.
  WAIT UP TO '0.200' SECONDS.
**** Считываем данные в таблицу
  CALL FUNCTION '****EXCEL_TO_INTERNAL_TABLE'
    EXPORTING
      m_file_name             = lc_temp
      i_begin_col             = 1
      i_begin_row             = 1
      i_end_col               = 6
      i_end_row               = lc_count
    TABLES
      ch_data                 = lt_bnka
    EXCEPTIONS
      inconsistent_parameters = 1
      upload_ole              = 2
      read_failed             = 3
      OTHERS                  = 4.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
             WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ELSE.
    IF lt_bnka IS NOT INITIAL .
      LOOP AT lt_bnka INTO wa_loc.
        CLEAR wa_itab.
        MOVE-CORRESPONDING wa_loc TO wa_itab.
        APPEND  wa_itab TO itab_bnka.
      ENDLOOP.
    ENDIF.
  ENDIF.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Programming Techniques | Приемы программирования -> Conversion All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.