본문 바로가기

아빠별/ABAP

CBO Table Data Migration Program

반응형
  *&---------------------------------------------------------------------*
*& Report  ZGBDEVR0003                                                 *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

report  zgbdevr0003 message-id zmgbdev.

*----------------------------------------------------------------------*
* Include
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Table
*----------------------------------------------------------------------*
tables : dd02l,
         dd03l,
         rfc_db_opt.
*----------------------------------------------------------------------*
* Global Type
*----------------------------------------------------------------------*
type-pools: slis,
              vrm.

*----------------------------------------------------------------------*
* Global Variables
*----------------------------------------------------------------------*
data : ls_fieldcat type slis_fieldcat_alv.

*----------------------------------------------------------------------*
* INTERNAL TABLE & Variables
*----------------------------------------------------------------------*
data : gt_dd03l type table of dd03l with header line.

field-symbols: <fs_tab> type standard table,
                 <fs_field> type any.

*----------------------------------------------------------------------*
* ALV Variable
*----------------------------------------------------------------------*
data: g_repid             like sy-repid,
      gs_print            type slis_print_alv,
      gt_list_top_of_page type slis_t_listheader,
      gt_events           type slis_t_event,
      gt_sort             type slis_t_sortinfo_alv,
      gs_layout           type slis_layout_alv,
      gt_fieldcat         type slis_t_fieldcat_alv,
      fieldcat_in         type slis_fieldcat_alv,
      col_pos             type i,
      g_variant           type disvariant,
      g_save              value 'A',
      g_lights_fieldname  type slis_fieldname value 'LIGHTS',
      g_user_command type slis_formname value 'USER_COMMAND'.

*----------------------------------------------------------------------*
* MACRO
*----------------------------------------------------------------------*
define append_fieldcat.
  clear ls_fieldcat.
  ls_fieldcat-tabname = pv_table.
  ls_fieldcat-fieldname = &1.
  ls_fieldcat-seltext_l = &2.
  ls_fieldcat-just = &3.
  ls_fieldcat-key = &4.
  ls_fieldcat-outputlen = &5.
  append ls_fieldcat to gt_fieldcat.
end-of-definition.

*----------------------------------------------------------------------*
* INITIALIZATION
*----------------------------------------------------------------------*
initialization.

*----------------------------------------------------------------------*
* SELECTION SCREEN LAYOUT
*----------------------------------------------------------------------*
  selection-screen begin of block bl_1 with frame title text-001.
  parameters : pv_table like dd02l-tabname obligatory ,
                  pv_dest(32as listbox visible length 32.
  select-options: pv_opt for rfc_db_opt-text no intervals.
  selection-screen end of block bl_1.

  selection-screen begin of block bl_2 with frame title text-002.
  parameters : pv_modif as checkbox" default 'X'.
  selection-screen end of block bl_2.

*----------------------------------------------------------------------*
* AT SELECTION-SCREEN
*----------------------------------------------------------------------*
at selection-screen output.
  data : lv_name  type vrm_id,
         lv_list  type vrm_values,
         lv_value like line of lv_list,
         lt_rfcdest type table of rfcdes with header line.

  perform get_rfc_destination tables lt_rfcdest.

  move 'PV_DEST' to lv_name.
  loop at lt_rfcdest.
    lv_value-key = lt_rfcdest-rfcdest.
    lv_value-text = lt_rfcdest-rfcdest.
    append lv_value to lv_list.
  endloop.

  call function 'VRM_SET_VALUES'
    exporting
      id     = lv_name
      values = lv_list.


*----------------------------------------------------------------------*
* START-OF-SELECTION
*----------------------------------------------------------------------*
start-of-selection.

*-- Call Monitoring
  call method zgb_ca_monitoring=>monitor
    exporting
      ip_progname = sy-repid
      ip_tcode    = sy-tcode.


  perform get_columns.
  perform create_dynamic_internal_table.
  perform process_data.


*----------------------------------------------------------------------*
* END-OF-SELECTION
*----------------------------------------------------------------------*
end-of-selection.
  perform display_data.
*&---------------------------------------------------------------------*
*&      Form  get_rfc_destination
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_LT_RFCDEST  text
*----------------------------------------------------------------------*
form get_rfc_destination  tables   pt_rfcdest structure rfcdes.
  select *
    into corresponding fields of table pt_rfcdest
    from rfcdes
    where rfctype = '3'.
endform.                    " get_rfc_destination
*&---------------------------------------------------------------------*
*&      Form  get_columns
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form get_columns .
  select *
  into corresponding fields of table gt_dd03l
  from dd03l
  where tabname = pv_table
     and comptype = 'E'.

  if sy-subrc ne '0'.
    message i000 with 'Data Not Found!!'.
    stop.

  endif.

  sort gt_dd03l by position.
endform.                    " get_columns
*&---------------------------------------------------------------------*
*&      Form  create_dynamic_internal_table
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form create_dynamic_internal_table .
  data: lv_dref type ref to data.

  create data lv_dref type table of (pv_table).
  assign lv_dref->* to <fs_tab>.
  free lv_dref.

  create data lv_dref type (pv_table).
  assign lv_dref->* to <fs_field>.
  free lv_dref.
endform.                    " create_dynamic_internal_table
*&---------------------------------------------------------------------*
*&      Form  process_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form process_data .
  data : lt_data type table of ztab8000 with header line,
          lt_opt type standard table of rfc_db_opt ,
          lt_fields type standard table of rfc_db_fld,
          wa_options like line of lt_opt.



  field-symbols <fs_data> type any.
  if pv_opt[] is not initial.
    loop at pv_opt.
      clear wa_options.
      move : pv_opt-low to wa_options-text.
      append wa_options to lt_opt.
    endloop.
  endif.

  if pv_dest is initial.
    call function 'ZRFC_READ_TABLE'
      exporting
        query_table          = pv_table
      tables
        options              = lt_opt
        fields               = lt_fields
        data                 = lt_data
      exceptions
        table_not_available  = 1
        table_without_data   = 2
        option_not_valid     = 3
        field_not_valid      = 4
        not_authorized       = 5
        data_buffer_exceeded = 6
        others               = 7.
  else.
    call function 'ZRFC_READ_TABLE'
      destination pv_dest
      exporting
        query_table          = pv_table
      tables
        options              = lt_opt
        fields               = lt_fields
        data                 = lt_data
      exceptions
        table_not_available  = 1
        table_without_data   = 2
        option_not_valid     = 3
        field_not_valid      = 4
        not_authorized       = 5
        data_buffer_exceeded = 6
        others               = 7.
  endif.

  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  else.
    loop at lt_data.
      assign lt_data-wa to <fs_data> casting type (pv_table).
      move <fs_data> to <fs_field>.
      append <fs_field> to <fs_tab>.

      if pv_modif eq 'X'.
        modify (pv_table) from <fs_field>.
      endif.
    endloop.
  endif.

endform.                    " process_data
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form display_data .
  if <fs_tab>[] is not initial.
    perform setting_layout.
    perform setting_catalog.
    perform display_alv.
  endif.
endform.                    " DISPLAY_DATA



*&---------------------------------------------------------------------*
*&      Form  setting_layout
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form setting_layout .
*  gs_layout-colwidth_optimize = 'X'.
*  gs_layout-grid_title = 'GroupWare Account Management'.
*  gs_layout-sel_mode = 'D'.
endform.                    "setting_layout

*&---------------------------------------------------------------------*
*&      Form  setting_catalog
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form setting_catalog .
  loop at gt_dd03l.
    append_fieldcat gt_dd03l-fieldname
                        gt_dd03l-fieldname
                        'L'
                        gt_dd03l-keyflag
                        gt_dd03l-leng.
  endloop.

endform.                    " setting_catalog

*&---------------------------------------------------------------------*
*&      Form  display_alv
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form display_alv .
  call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
*        I_INTERFACE_CHECK               = 'ALV_BACKGROUD'
         i_callback_program              = g_repid
         i_callback_pf_status_set        = ''
         i_callback_user_command         = ''
*        I_STRUCTURE_NAME                =
         is_layout                       = gs_layout
         it_fieldcat                     = gt_fieldcat[]
*        IT_EXCLUDING                    =
*        IT_SPECIAL_GROUPS               =
         it_sort                         = gt_sort
*        IT_FILTER                       =
*        IS_SEL_HIDE                     =
*        I_DEFAULT                       = 'X'
         i_save                          = g_save
         is_variant                      = g_variant
*         IT_EVENTS                       = gt_events[]
*        IT_EVENT_EXIT                   =
*        IS_PRINT                        =
*        IS_REPREP_ID                    =
*        I_SCREEN_START_COLUMN           = 0
*        I_SCREEN_START_LINE             = 0
*        I_SCREEN_END_COLUMN             = 0
*        I_SCREEN_END_LINE               = 0
*     IMPORTING
*        E_EXIT_CAUSED_BY_CALLER         =
*        ES_EXIT_CAUSED_BY_USER          =
      tables
         t_outtab                        = <fs_tab>
       exceptions
         program_error                   = 1
         others                          = 2.
endform.                    "display_alv

반응형