Skip to end of metadata
Go to start of metadata

Author: Michael Hoerisch
Submitted: 09/28/2007
Related Links:

  • How to guide: How To... Improve the runtime of the 0FI_GL_4 extractor (link)
  • Blog

Description
This Coding is related to the Howto paper mentioned above. Please read the Howto and use the blog to provide input and feedback.

*&---------------------------------------------------------------------*
*& Report  YBW_FI_GL_4_DELTA_COLLECT
*&
*&---------------------------------------------------------------------*
*&
*& This report collects new and changed documents for the 0FI_GL_4 from
*& the FI application tables and writes them to the delta queues of all
*& connected BW system.
*&
*& The BW extractor itself therefore needs only to process a small
*& amount of records from the application tables to the delta queue,
*& before the content of the delta queue is sent to the BW system.
*&
*&---------------------------------------------------------------------*
REPORT ybw_fi_gl_4_delta_collect.
TYPE-POOLS: sbiw.
* Constants
* The 'DUMMY_BW' constant is the same as defined in Step 1 of the How to guide
CONSTANTS: c_dlogsys    TYPE logsys     VALUE 'DUMMY_BW',
           c_oltpsource TYPE roosourcer VALUE '0FI_GL_4'.
* Filed symbols
FIELD-SYMBOLS: <l_s_roosprmsc> TYPE roosprmsc,
               <l_s_roosprmsf> TYPE roosprmsf.
* Variables
DATA: l_slogsys      TYPE logsys,
      l_tfstruc      TYPE rotfstruc,
      l_lines_read   TYPE sy-tabix,
      l_subrc        TYPE sy-subrc,
      l_s_rsbasidoc  TYPE rsbasidoc,
      l_s_roosgen    TYPE roosgen,
      l_s_parameters TYPE roidocprms,
      l_t_fields     TYPE TABLE OF rsfieldsel,
      l_t_roosprmsc  TYPE TABLE OF roosprmsc,
      l_t_roosprmsf  TYPE TABLE OF roosprmsf.
* Selection parameters
SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECTION-SCREEN SKIP 1.
PARAMETER prlogsys LIKE tbdls-logsys OBLIGATORY.
SELECTION-SCREEN: END OF BLOCK b1.
AT SELECTION-SCREEN.
* Check logical system
  SELECT COUNT * FROM  tbdls BYPASSING BUFFER
                  WHERE logsys = prlogsys.
  IF sy-subrc <> 0.
    MESSAGE e454(b1) WITH prlogsys.
* The logical system & has not yet been defined
  ENDIF.
START-OF-SELECTION.
* Check if logical system for dummy BW is defined (Transaction BD54)
  SELECT COUNT * FROM  tbdls BYPASSING BUFFER
                  WHERE logsys = c_dlogsys.
  IF sy-subrc <> 0.
    MESSAGE e454(b1) WITH c_dlogsys.
* The logical system & has not yet been defined
  ENDIF.
* Get own logical system
  CALL FUNCTION 'RSAN_LOGSYS_DETERMINE'
    EXPORTING
      i_client = sy-mandt
    IMPORTING
      e_logsys = l_slogsys.
* Check if transfer rules exist for this extractor in BW
  SELECT SINGLE * FROM  roosgen INTO l_s_roosgen
                  WHERE oltpsource = c_oltpsource
                  AND   rlogsys    = prlogsys
                  AND   slogsys    = l_slogsys.
  IF sy-subrc <> 0.
    MESSAGE e025(rj) WITH prlogsys.
* No transfer rules for target system &
  ENDIF.
* Copy record for dummy BW system
  l_s_roosgen-rlogsys = c_dlogsys.
  MODIFY roosgen FROM l_s_roosgen.
  IF sy-subrc <> 0.
    MESSAGE e053(rj) WITH text-002.
* Update of table ROOSGEN failed
  ENDIF.
* Assignment of source system to BW system
  SELECT SINGLE * FROM  rsbasidoc INTO l_s_rsbasidoc
                  WHERE slogsys = l_slogsys
                  AND   rlogsys = prlogsys.
  IF sy-subrc <> 0 OR
     ( l_s_rsbasidoc-objstat = sbiw_c_objstat-inactive ).
    MESSAGE e053(rj) WITH text-003.
* Remote destination not valid
  ENDIF.
* Copy record for dummy BW system
  l_s_rsbasidoc-rlogsys = c_dlogsys.
  MODIFY rsbasidoc FROM l_s_rsbasidoc.
  IF sy-subrc <> 0.
    MESSAGE e053(rj) WITH text-004.
* Update of table RSBASIDOC failed
  ENDIF.
* Delta initializations
  SELECT * FROM  roosprmsc INTO TABLE l_t_roosprmsc
           WHERE oltpsource = c_oltpsource
           AND   rlogsys    = prlogsys
           AND   slogsys    = l_slogsys.
  IF sy-subrc <> 0.
    MESSAGE e020(rsqu).
* Some of the initialization requirements have not been completed
  ENDIF.
  LOOP AT l_t_roosprmsc ASSIGNING <l_s_roosprmsc>.
    IF <l_s_roosprmsc>-initstate = ' '.
      MESSAGE e020(rsqu).
* Some of the initialization requirements have not been completed
    ENDIF.
    <l_s_roosprmsc>-rlogsys = c_dlogsys.
    <l_s_roosprmsc>-gottid  = ''.
    <l_s_roosprmsc>-gotvers = '0'.
    <l_s_roosprmsc>-gettid  = ''.
    <l_s_roosprmsc>-getvers = '0'.
  ENDLOOP.
* Delete old records for dummy BW system
  DELETE FROM  roosprmsc
         WHERE oltpsource = c_oltpsource
           AND rlogsys    = c_dlogsys
           AND slogsys    = l_slogsys.
* Copy records for dummy BW system
  MODIFY roosprmsc FROM TABLE l_t_roosprmsc.
  IF sy-subrc <> 0.
    MESSAGE e053(rj) WITH text-005.
* Update of table ROOSPRMSC failed
  ENDIF.
* Filter values for delta initializations
  SELECT * FROM  roosprmsf INTO TABLE l_t_roosprmsf
           WHERE oltpsource = c_oltpsource
           AND   rlogsys    = prlogsys
           AND   slogsys    = l_slogsys.
  IF sy-subrc <> 0.
    MESSAGE e020(rsqu).
* Some of the initialization requirements have not been completed
  ENDIF.
  LOOP AT l_t_roosprmsf ASSIGNING <l_s_roosprmsf>.
    <l_s_roosprmsf>-rlogsys = c_dlogsys.
  ENDLOOP.
* Delete old records for dummy BW system
  DELETE FROM  roosprmsf
         WHERE oltpsource = c_oltpsource
           AND rlogsys    = c_dlogsys
           AND slogsys    = l_slogsys.
* Copy records for dummy BW system
  MODIFY roosprmsf FROM TABLE l_t_roosprmsf.
  IF sy-subrc <> 0.
    MESSAGE e053(rj) WITH text-006.
* Update of table ROOSPRMSF failed
  ENDIF.
*************************************
* COMMIT WORK for changed meta data *
*************************************
  COMMIT WORK.
* Delete RFC queue of dummy BW system
* (Just in case entries of other delta requests exist)
  CALL FUNCTION 'RSC1_TRFC_QUEUE_DELETE_DATA'
    EXPORTING
      i_osource           = c_oltpsource
      i_rlogsys           = c_dlogsys
      i_all               = 'X'
    EXCEPTIONS
      tid_not_executed    = 1
      invalid_parameter   = 2
      client_not_found    = 3
      error_reading_queue = 4
      OTHERS              = 5.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
*******************************************
* COMMIT WORK for deletion of delta queue *
*******************************************
  COMMIT WORK.
* Get MAXLINES for data package
  CALL FUNCTION 'RSAP_IDOC_DETERMINE_PARAMETERS'
    EXPORTING
      i_oltpsource   = c_oltpsource
      i_slogsys      = l_slogsys
      i_rlogsys      = prlogsys
      i_updmode      = 'D '
    IMPORTING
      e_s_parameters = l_s_parameters
      e_subrc        = l_subrc.
  .
  IF l_subrc <> 0.
    MESSAGE e053(rj) WITH text-007.
* Error in function module RSAP_IDOC_DETERMINE_PARAMETERS
  ENDIF.
* Transfer structure depends on transfer method
  CASE l_s_roosgen-tfmethode.
    WHEN 'I'.
      l_tfstruc = l_s_roosgen-tfstridoc.
    WHEN 'T'.
      l_tfstruc = l_s_roosgen-tfstruc.
  ENDCASE.
* Determine transfer structure field list
  PERFORM fill_field_list(saplrsap) TABLES l_t_fields
                                    USING  l_tfstruc.
* Start the delta extraction for the dummy BW system
  CALL FUNCTION 'RSFH_GET_DATA_SIMPLE'
    EXPORTING
      i_requnr                     = 'DUMMY'
      i_osource                    = c_oltpsource
      i_showlist                   = ' '
      i_maxsize                    = l_s_parameters-maxlines
      i_maxfetch                   = '9999'
      i_updmode                    = 'D '
      i_rlogsys                    = c_dlogsys
      i_read_only                  = ' '
    IMPORTING
      e_lines_read                 = l_lines_read
    TABLES
      i_t_field                    = l_t_fields
    EXCEPTIONS
      generation_error             = 1
      interface_table_error        = 2
      metadata_error               = 3
      error_passed_to_mess_handler = 4
      no_authority                 = 5
      OTHERS                       = 6.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
*********************************
* COMMIT WORK for delta request **********************************
   COMMIT WORK.
* Delete RFC queue of dummy BW system
  CALL FUNCTION 'RSC1_TRFC_QUEUE_DELETE_DATA'
    EXPORTING
      i_osource           = c_oltpsource
      i_rlogsys           = c_dlogsys
      i_all               = 'X'
    EXCEPTIONS
      tid_not_executed    = 1
      invalid_parameter   = 2
      client_not_found    = 3
      error_reading_queue = 4
      OTHERS              = 5.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
* Data collection for 0FI_GL_4 delta queue successful
  MESSAGE s053(rj) WITH text-008.