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

Getting data in parallel in a report.



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



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Sun Sep 05, 2021 4:28 pm    Post subject: Getting data in parallel in a report. Reply with quote

Sometimes, to speed up a report, you have to do data processing in parallel.

Code:
*&---------------------------------------------------------------------*
*& Report zvga_parallel_tasks
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT  zvga_parallel_tasks.

INCLUDE zvga_parallel_top.

TYPES: BEGIN OF ty_task_types,
        get_bseg TYPE char1,
        get_ekpo TYPE char1,
        get_lips TYPE char1,
        get_vbrp TYPE char1,
       END OF ty_task_types.

DATA: gs_get_types TYPE ty_task_types,
      gt_bseg TYPE bseg_t,
      gt_ekpo TYPE ekpo_tty,
      gt_lips TYPE tab_lips,
      gt_vbrp TYPE tab_vbrp.

CLEAR gs_get_types WITH 'X'.

PERFORM get_data.

*&---------------------------------------------------------------------*
*&      Form  get_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM get_data.

  DATA: lv_error(80) VALUE space,
        ls_count TYPE string,
        lv_type TYPE fm_taskname,
        lt_type TYPE TABLE OF fm_taskname.

  APPEND gc_get_bseg TO lt_type.
  APPEND gc_get_ekpo TO lt_type.
  APPEND gc_get_lips TO lt_type.
  APPEND gc_get_vbrp TO lt_type.

  FREE: gt_bseg, gt_ekpo, gt_lips, gt_vbrp.

  CALL FUNCTION 'SPBT_INITIALIZE'.

  LOOP AT lt_type INTO lv_type.

    CALL FUNCTION 'ZVGA_GET_DATA'
      DESTINATION gc_rfcdest
      STARTING NEW TASK lv_type
      PERFORMING return_data ON END OF TASK
      EXPORTING
        iv_taskname           = lv_type
      EXCEPTIONS
        communication_failure = 1  MESSAGE lv_error
        system_failure        = 2  MESSAGE lv_error
        resource_failure      = 3
        OTHERS                = 4.

    IF sy-subrc IS NOT INITIAL.
      IF lv_error IS INITIAL.
        lv_error = 'Getting data error!'.
      ENDIF.
      EXIT.
    ENDIF.

  ENDLOOP.

  DO 60 TIMES.
    WAIT UNTIL gs_get_types IS INITIAL UP TO 300 SECONDS.
    IF gs_get_types IS NOT INITIAL.
      CALL FUNCTION 'TH_REDISPATCH'.
    ELSE.
      EXIT.
    ENDIF.
  ENDDO.

  IF lv_error IS NOT INITIAL OR gs_get_types IS NOT INITIAL.
    MESSAGE e000(su) WITH lv_error.
  ENDIF.

  DESCRIBE TABLE gt_bseg LINES ls_count.  WRITE: / 'READ ', ls_count, 'LINES OF bseg.'.
  DESCRIBE TABLE gt_ekpo LINES ls_count.  WRITE: / 'READ ', ls_count, 'LINES OF ekpo.'.
  DESCRIBE TABLE gt_lips LINES ls_count.  WRITE: / 'READ ', ls_count, 'LINES OF lips.'.
  DESCRIBE TABLE gt_vbrp LINES ls_count.  WRITE: / 'READ ', ls_count, 'LINES OF vbrp.'.

ENDFORM.                    "get_data


*&---------------------------------------------------------------------*
*&      Form  return_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->TASKNAME   text
*----------------------------------------------------------------------*
FORM return_data USING taskname TYPE clike.

  DATA: lv_error(80) VALUE space,
        lt_bseg LIKE gt_bseg,
        lt_ekpo LIKE gt_ekpo,
        lt_lips LIKE gt_lips,
        lt_vbrp LIKE gt_vbrp.

  RECEIVE RESULTS FROM FUNCTION 'ZVGA_GET_DATA'
  IMPORTING
    et_bseg = lt_bseg
    et_ekpo = lt_ekpo
    et_lips = lt_lips
    et_vbrp = lt_vbrp
  EXCEPTIONS
    communication_failure = 1  MESSAGE lv_error
    system_failure        = 2  MESSAGE lv_error
    resource_failure      = 3
    OTHERS                = 4.
  IF sy-subrc IS INITIAL.
    CASE taskname.
      WHEN gc_get_bseg.
        gt_bseg = lt_bseg.
        CLEAR gs_get_types-get_bseg.
      WHEN gc_get_ekpo.
        gt_ekpo = lt_ekpo.
        CLEAR gs_get_types-get_ekpo.
      WHEN gc_get_lips.
        gt_lips = lt_lips.
        CLEAR gs_get_types-get_lips.
      WHEN gc_get_vbrp.
        gt_vbrp = lt_vbrp.
        CLEAR gs_get_types-get_vbrp.
    ENDCASE.
  ELSE.
    MESSAGE s000(su) WITH taskname ' -> subrc = ' sy-subrc lv_error.
  ENDIF.
ENDFORM.                    "return_data

*&---------------------------------------------------------------------*
*&  Include           ZVGA_PARALLEL_TOP
*&---------------------------------------------------------------------*

CONSTANTS: gc_rfcdest TYPE rfcdest VALUE 'NONE',
           gc_get_bseg TYPE fm_taskname VALUE 'GET_BSEG',
           gc_get_ekpo TYPE fm_taskname VALUE 'GET_EKPO',
           gc_get_lips TYPE fm_taskname VALUE 'GET_LIPS',
           gc_get_vbrp TYPE fm_taskname VALUE 'GET_VBRP'.

* Remote-enable function module
FUNCTION zvga_get_data.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(IV_TASKNAME) TYPE  FM_TASKNAME DEFAULT 'NEW_TASK'
*"  EXPORTING
*"     VALUE(ET_BSEG) TYPE  BSEG_T
*"     VALUE(ET_EKPO) TYPE  EKPO_TTY
*"     VALUE(ET_LIPS) TYPE  TAB_LIPS
*"     VALUE(ET_VBRP) TYPE  TAB_VBRP
*"  EXCEPTIONS
*"      COMMUNICATION_FAILURE
*"      SYSTEM_FAILURE
*"      RESOURCE_FAILURE
*"----------------------------------------------------------------------

  CASE iv_taskname.
    WHEN gc_get_bseg.
      SELECT * FROM bseg INTO TABLE et_bseg UP TO 1000 ROWS.
    WHEN gc_get_ekpo.
      SELECT * FROM ekpo INTO TABLE et_ekpo UP TO 1000 ROWS.
    WHEN gc_get_lips.
      SELECT * FROM lips INTO TABLE et_lips UP TO 1000 ROWS.
    WHEN gc_get_vbrp.
      SELECT * FROM vbrp INTO TABLE et_vbrp UP TO 1000 ROWS.
  ENDCASE.

ENDFUNCTION.


* INCLUDE LZERU_VGATOP

FUNCTION-POOL zeru_vga.                     "MESSAGE-ID ..
INCLUDE zvga_parallel_top.
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 | Приемы программирования 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.