Friday 26 May 2017

Export ABAP transparent table content to PostgreSQL table

Now ABAP table COMM_PRODUCT is successfully replicated to PostgreSQL:

SAP ABAP PostgreSQL, SAP ABAP Guide, SAP ABAB Tutorials and Materials
In my ABAP server table COMM_PRODUCT has totally 94331 entries:

SAP ABAP PostgreSQL, SAP ABAP Guide, SAP ABAB Tutorials and Materials

Execute the report below:

REPORT zexport_data.

DATA: lt_export  TYPE string_table,
      l_filename TYPE string,
      l_path     TYPE string,
      l_fullpath TYPE string,
      lv_from    TYPE string,
      lv_to      TYPE string,
      lt_result  TYPE TABLE OF comm_product.

SELECT * INTO TABLE lt_result FROM comm_product.

LOOP AT lt_result INTO DATA(r).
  PERFORM format_timestamp USING r-valid_from CHANGING lv_from.
  PERFORM format_timestamp USING r-valid_to CHANGING lv_to.
  DATA(lv_line) = |{ r-client };{ r-product_guid };{ r-product_id };{ r-product_type };| &
  |{ r-config };{ r-xnosearch };{ r-object_family };{ r-batch_dedicated };{ r-competitor_prod };| &
  |{ lv_from };{ lv_to };{ r-upname };{ r-histex };{ r-logsys }| .
  APPEND lv_line TO lt_export.
ENDLOOP.

CALL METHOD cl_gui_frontend_services=>file_save_dialog
  EXPORTING
    window_title         = 'Save export data file'
    default_file_name    = 'PostgreSQL.txt'
  CHANGING
    filename             = l_filename
    path                 = l_path
    fullpath             = l_fullpath
  EXCEPTIONS
    cntl_error           = 1
    error_no_gui         = 2
    not_supported_by_gui = 3
    OTHERS               = 4.

IF sy-subrc <> 0.
  WRITE:/ 'file save dialog failed.'.
  RETURN.
ENDIF.

CALL METHOD cl_gui_frontend_services=>gui_download
  EXPORTING
    filename                = l_fullpath
  CHANGING
    data_tab                = lt_export
  EXCEPTIONS
    file_write_error        = 1
    no_batch                = 2
    gui_refuse_filetransfer = 3
    invalid_type            = 4
    no_authority            = 5
    unknown_error           = 6
    header_not_allowed      = 7
    separator_not_allowed   = 8
    filesize_not_allowed    = 9
    header_too_long         = 10
    dp_error_create         = 11
    dp_error_send           = 12
    dp_error_write          = 13
    unknown_dp_error        = 14
    access_denied           = 15
    dp_out_of_memory        = 16
    disk_full               = 17
    dp_timeout              = 18
    file_not_found          = 19
    dataprovider_exception  = 20
    control_flush_error     = 21
    not_supported_by_gui    = 22
    error_no_gui            = 23
    OTHERS                  = 24.

FORM format_timestamp USING iv_timestamp TYPE comt_valid_from CHANGING cv_line.
  CONVERT TIME STAMP iv_timestamp TIME ZONE 'UTC' INTO DATE DATA(date)
     TIME DATA(time).
  CLEAR: cv_line.
  cv_line = |{ date DATE = ISO } { time TIME = ISO }|.
ENDFORM.

Those entries are exported from ABAP server to my local laptop stored in txt format.

SAP ABAP PostgreSQL, SAP ABAP Guide, SAP ABAB Tutorials and Materials

Now go back to PostgreSQL console, choose import from context menu:

SAP ABAP PostgreSQL, SAP ABAP Guide, SAP ABAB Tutorials and Materials

Load the local text file:

SAP ABAP PostgreSQL, SAP ABAP Guide, SAP ABAB Tutorials and Materials

And you can see import successful notification:

SAP ABAP PostgreSQL, SAP ABAP Guide, SAP ABAB Tutorials and Materials

Click detail hyperlink, and you see totally 94331 lines are imported from ABAP server.

SAP ABAP PostgreSQL, SAP ABAP Guide, SAP ABAB Tutorials and Materials

Just do some double click to confirm whether the data imported are exactly equal to the records in ABAP server.

SAP ABAP PostgreSQL, SAP ABAP Guide, SAP ABAB Tutorials and Materials

No comments:

Post a Comment