Code listing for: ZTEST9010 Description: 12345 *&---------------------------------------------------------------------* *& Report ZTEST_ASYNC_RFC *&---------------------------------------------------------------------* *& *&---------------------------------------------------------------------* REPORT ztest_async_rfc. **global type, data *TYPES: BEGIN OF gty_s_key_flight, * carrid TYPE sflight-carrid, * connid TYPE sflight-connid, * fldate TYPE sflight-fldate, * END OF gty_s_key_flight. *TYPES: gty_t_key_flight TYPE TABLE OF gty_s_key_flight. TYPES: BEGIN OF gty_s_flight_package, task_name TYPE char10, keys TYPE zflight_t_key, END OF gty_s_flight_package. DATA: gt_package TYPE TABLE OF gty_s_flight_package, gt_results TYPE TABLE OF sflight, gv_snd_jobs TYPE i, gv_rcv_jobs TYPE i, gv_pp_running TYPE i. **selection screen SELECTION-SCREEN BEGIN OF BLOCK svr_group WITH FRAME TITLE title. PARAMETERS: p_group TYPE rzllitab-classname DEFAULT 'parallel_generators' MODIF ID svr, p_parpro TYPE int1 DEFAULT 3 MODIF ID svr, p_size TYPE i DEFAULT 5 MODIF ID svr. " normally 100, 1000" SELECTION-SCREEN END OF BLOCK svr_group. INITIALIZATION. title = 'Settings for Parallel Processing'. START-OF-SELECTION. "..build packages" PERFORM build_packages. "..parallel processing" PERFORM parallel_processing. "..display result" PERFORM display_result. FORM build_packages. DATA: lv_cursor TYPE cursor, lv_index TYPE char4, lv_task_counter TYPE char8, lt_keys TYPE zflight_t_key, ls_package TYPE gty_s_flight_package. OPEN CURSOR WITH HOLD @lv_cursor FOR SELECT carrid, connid, fldate FROM sflight WHERE carrid = 'AA' OR carrid = 'AZ'. DO. lv_index = sy-index. CONCATENATE 'TASK' lv_index INTO lv_task_counter. FETCH NEXT CURSOR @lv_cursor INTO TABLE @lt_keys PACKAGE SIZE @p_size. IF sy-subrc <> 0. EXIT. ENDIF. ls_package = VALUE #( task_name = lv_task_counter keys = lt_keys ). APPEND ls_package TO gt_package. ENDDO. ENDFORM. FORM parallel_processing. DATA: lv_wp_total TYPE i, lv_wp_free TYPE i, lv_curr_wp_total TYPE i, lv_curr_wp_free TYPE i, lv_allow_wp TYPE i. IF p_group IS NOT INITIAL. " Get the list of application server available and those are free (no of WP & free WP)" CALL FUNCTION 'SPBT_INITIALIZE' EXPORTING group_name = p_group IMPORTING max_pbt_wps = lv_wp_total free_pbt_wps = lv_wp_free EXCEPTIONS invalid_group_name = 1 internal_error = 2 pbt_env_already_initialized = 3 currently_no_resources_avail = 4 no_pbt_resources_found = 5 cant_init_different_pbt_groups = 6 OTHERS = 7. IF sy-subrc <> 0 AND sy-subrc <> 3. MESSAGE 'No resources available.' TYPE 'E'. EXIT. ENDIF. ENDIF. LOOP AT gt_package INTO DATA(ls_package). " generating jobs" gv_snd_jobs = gv_snd_jobs + 1. gv_pp_running = gv_pp_running + 1. IF p_group IS NOT INITIAL. DO. " get the current available workprocess(time-dependent)" CALL FUNCTION 'SPBT_GET_CURR_RESOURCE_INFO' IMPORTING max_pbt_wps = lv_curr_wp_total free_pbt_wps = lv_curr_wp_free EXCEPTIONS internal_error = 1 pbt_env_not_initialized_yet = 2 OTHERS = 3. IF p_parpro > 0. lv_allow_wp = p_parpro. ELSE. "if maximum number of processes is not restricted, take only half of the free processes" lv_allow_wp = lv_curr_wp_free / 2. ENDIF. " if current free wp is available with more than 2 wp" " and the current running is less than allowed wp," " then there is enough wp for work of parallelization" IF lv_curr_wp_free GT 2 AND gv_pp_running LT lv_allow_wp. call function 'ZTEST_FLIGHT_GETDETAIL' STARTING NEW TASK ls_package-task_name DESTINATION IN GROUP p_group PERFORMING call_back ON END OF TASK EXPORTING it_keys = ls_package-keys EXCEPTIONS communication_failure = 1 system_failure = 2 resource_failure = 3. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ELSE. EXIT. ENDIF. ELSE. " otherwise, it needs to wait until the wp are available" WAIT UP TO 1 SECONDS. CONTINUE. ENDIF. ENDDO. ELSE. "if no server group has been selected, then parallel processing use the Default Group" call function 'ZTEST_FLIGHT_GETDETAIL' STARTING NEW TASK ls_package-task_name DESTINATION IN GROUP DEFAULT PERFORMING call_back ON END OF TASK EXPORTING it_keys = ls_package-keys EXCEPTIONS communication_failure = 1 system_failure = 2 resource_failure = 3. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. EXIT. ENDIF. ENDIF. ENDLOOP. " wait, until all the jobs were received." WAIT UNTIL gv_rcv_jobs >= gv_snd_jobs. ENDFORM. FORM call_back USING p_task TYPE clike. DATA: lt_results TYPE STANDARD TABLE OF sflight. " reveived jobs" gv_rcv_jobs = gv_rcv_jobs + 1. " retrieve results from parallelization" RECEIVE RESULTS FROM FUNCTION 'ZTEST_FLIGHT_GETDETAIL' IMPORTING et_results = lt_results. IF sy-subrc = 0. " running jobs" gv_pp_running = gv_pp_running - 1. ENDIF. APPEND LINES OF lt_results TO gt_results. ENDFORM. FORM display_result. DATA: lo_alv TYPE REF TO cl_salv_table. CALL METHOD cl_salv_table=>factory IMPORTING r_salv_table = lo_alv CHANGING t_table = gt_results. lo_alv->display( ). ENDFORM. *Messages *---------------------------------------------------------- * * Message class: Hard coded * No resources available. Extracted by Mass Download version 1.5.5 - E.G.Mellodew. 1998-2022. Sap Release 756
标签:gv,sy,package,lv,ABAP,wp,多线程,TYPE From: https://www.cnblogs.com/ZJY-1314/p/17439902.html