Query the commission contract which without cost center(分批处理数据,多线程异步调用)

Posted haru

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Query the commission contract which without cost center(分批处理数据,多线程异步调用)相关的知识,希望对你有一定的参考价值。


FUNCTION /nsl/_icm_call_without_cos_cen.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(S_DATE) TYPE  BEGDATUM
*"     VALUE(CTRTBU_ID) TYPE  ISIS_CONTRACT_ID
*"     VALUE(P_APPL) TYPE  CACSAPPL
*"  TABLES
*"      TAB_CONTRACT STRUCTURE  CACS_CTRTBU
*"      SO_CON_D STRUCTURE  ZDM_RANGE_CONTRA
*"----------------------------------------------------------------------
  TYPES:
    BEGIN OF ty_ctrtbu_id,
      ctrtbu_id TYPE isis_contract_id,
      version      TYPE  cacsversion,
      leav_date    TYPE cacs_leav_date,
    END OF ty_ctrtbu_id,
    tt_ctrtbu_id TYPE STANDARD TABLE OF ty_ctrtbu_id,

    BEGIN OF ty_cost_center,
      kostl     TYPE char10,
      ctrtbu_id TYPE isis_contract_id,
      branch    TYPE char4,
    END OF ty_cost_center,

*------------------ Start edit by James on 2018/05/10-----------------*
    BEGIN OF ty_export,
      pol_nr         TYPE pfo_pol_nr,
      coveragenr_tt  TYPE /dfi/pfo_coveragenr_tt,
      cycle_date     TYPE dats,
      cacs_ctrtbu_id TYPE cacs_ctrtbu_id,
    END OF ty_export,
    tt_export TYPE STANDARD TABLE OF ty_export,

    BEGIN OF ty_output,
      pol_nr         TYPE pfo_pol_nr,
      coveragenr_tt  TYPE /dfi/pfo_coveragenr_tt,
      cycle_date     TYPE dats,
      cacs_ctrtbu_id TYPE cacs_ctrtbu_id,
      cost_center    TYPE kostl,
      branch         TYPE /nsl/branchplace,
    END OF ty_output,
    tt_output TYPE STANDARD TABLE OF ty_output.
*------------------ END edit by James on 2018/05/10-----------------*

  DATA:
    gt_cost_center_show TYPE STANDARD TABLE OF zdm_com_con_cost,
    gt_ctrtbu           TYPE tt_ctrtbu_id,
    gs_cost_center      TYPE zdm_com_con_cost,
    ls_ctrtbu_id        TYPE ty_ctrtbu_id,
    lv_kostl            TYPE char10,
    lv_branch           TYPE j_1bbranc_,
    contract_id         TYPE isis_contract_id,
*------------------ Start edit by James on 2018/05/10-----------------*
    gt_ctrtbu_new       TYPE tt_export,
    gs_ctrtbu_new       TYPE ty_export,
    gt_output           TYPE tt_output,
    gs_output           TYPE ty_output,
    gs_ctrtbu           TYPE ty_ctrtbu_id.
*------------------ END edit by James on 2018/05/10-----------------*
  CONSTANTS:
    c_space  TYPE char1 VALUE  .

  CLEAR:
    gt_ctrtbu_new,
    gs_ctrtbu_new,
    gt_output,
    gs_output,
    gs_ctrtbu.

  IF tab_contract[] IS NOT INITIAL.
    LOOP AT tab_contract INTO gs_ctrtbu.
      gs_ctrtbu_new-cacs_ctrtbu_id = gs_ctrtbu-ctrtbu_id.
      gs_ctrtbu_new-cycle_date     = s_date.
      APPEND gs_ctrtbu_new TO gt_ctrtbu_new.
      CLEAR:
        gs_ctrtbu_new,
        gs_ctrtbu.
    ENDLOOP.

    IF gt_ctrtbu_new IS NOT INITIAL.
      CALL FUNCTION /NSL/ICM_GET_CTRT_INFO "#EC CI_SUBRC
        EXPORTING
          it_input              = gt_ctrtbu_new
        TABLES
          et_output             = gt_output
        EXCEPTIONS
          input_parameter_empty = 1
          OTHERS                = 2.
      IF sy-subrc <> 0.
*Implement suitable error handling here
      ENDIF.

      LOOP AT gt_output INTO gs_output.
        gs_cost_center-kostl     = gs_output-cost_center.
        gs_cost_center-ctrtbu_id = gs_output-cacs_ctrtbu_id.
        gs_cost_center-branch    = gs_output-branch.
        APPEND gs_cost_center TO gt_cost_center_show.
        CLEAR:
          gs_output,
          gs_cost_center.
      ENDLOOP.

      IF gt_cost_center_show IS NOT INITIAL.
        MODIFY zdm_com_con_cost FROM TABLE gt_cost_center_show.
        IF sy-subrc <> 0.
          ROLLBACK WORK.
          MESSAGE  have error when save entry to db! TYPE E.
        ELSEIF sy-subrc = 0.
          COMMIT WORK.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.
ENDFUNCTION.

 

*&---------------------------------------------------------------------*
*& Report  Y_CONTRACT_WITHOUT_COSTCENTER
*&---------------------------------------------------------------------*
*&Created by James on 2018/04/18
*&---------------------------------------------------------------------*
*&Query the commission contract which without cost center
*&---------------------------------------------------------------------*
REPORT y_contract_without_costcenter.

TYPE-POOLS: slis.

TYPES:
  BEGIN OF ty_ctrtbu_id,
    ctrtbu_id TYPE isis_contract_id,
    version      TYPE  cacsversion,
    leav_date    TYPE cacs_leav_date,
  END OF ty_ctrtbu_id,
  tt_ctrtbu_id TYPE STANDARD TABLE OF ty_ctrtbu_id,

  BEGIN OF ty_cost_center,
    ctrtbu_id TYPE isis_contract_id,
    kostl     TYPE char10,
    branch    TYPE char4,
  END OF ty_cost_center,
  tt_cost_center TYPE STANDARD TABLE OF ty_cost_center,

*------------------ Start edit by James on 2018/05/10-----------------*
  BEGIN OF ty_export,
    pol_nr         TYPE pfo_pol_nr,
    coveragenr_tt  TYPE /dfi/pfo_coveragenr_tt,
    cycle_date     TYPE dats,
    cacs_ctrtbu_id TYPE cacs_ctrtbu_id,
  END OF ty_export,
  tt_export TYPE STANDARD TABLE OF ty_export,

  BEGIN OF ty_output,
    pol_nr         TYPE pfo_pol_nr,
    coveragenr_tt  TYPE /dfi/pfo_coveragenr_tt,
    cycle_date     TYPE dats,
    cacs_ctrtbu_id TYPE cacs_ctrtbu_id,
    cost_center    TYPE kostl,
    branch         TYPE /nsl/branchplace,
  END OF ty_output,
  tt_output TYPE STANDARD TABLE OF ty_output.
*------------------ END edit by James on 2018/05/10-----------------*


DATA:
  gt_cost_center_show      TYPE STANDARD TABLE OF zdm_com_con_cost,
  gt_cost_center_show_temp TYPE tt_cost_center,
  gt_cost_center_show_p    TYPE STANDARD TABLE OF zdm_com_con_cost,
  gt_ctrtbu                TYPE tt_ctrtbu_id,
  gs_ctrtbu                TYPE ty_ctrtbu_id,
  gt_ctrtbu_new            TYPE tt_export,
  gs_ctrtbu_new            TYPE ty_export,
  gt_output                TYPE tt_output,
  gs_output                TYPE ty_output,
  gt_fieldcat              TYPE lvc_t_fcat,
  gs_fieldcat              TYPE lvc_s_fcat,
  gs_layout                TYPE lvc_s_layo,
  gs_cost_center           TYPE zdm_com_con_cost,
  ls_ctrtbu_id             TYPE ty_ctrtbu_id,
  lv_kostl                 TYPE char10,
  lv_branch                TYPE j_1bbranc_,
  contract_id              TYPE isis_contract_id.

TYPES:
  BEGIN OF gty_pol,
    batch       TYPE i,
    tb_contract TYPE REF TO data,
  END OF gty_pol,

  BEGIN OF gty_contract,
    ctrtbu_id    TYPE isis_contract_id,
    version         TYPE  cacsversion,
    leav_date       TYPE cacs_leav_date,
    cancel_fg(1),
  END OF gty_contract,
  gtt_contract TYPE STANDARD TABLE OF gty_contract.

DATA:
  gv_lines    TYPE i,
  gs_contract TYPE gty_contract,
  gt_contract TYPE STANDARD TABLE OF gty_contract,
  gv_batch    TYPE i,
  lv_batch    TYPE i,
  gt_pol      TYPE STANDARD TABLE OF gty_pol,
  gs_pol      TYPE gty_pol,
  s_date1     TYPE datum.

DATA:
  r_pol          TYPE RANGE OF cacs_ctrtbu-ctrtbu_id,
  r_pol_line     LIKE LINE OF r_pol,
  lv_cursor      TYPE cursor,
  g_running      TYPE i,
  g_taskno       TYPE string,
  lv_packet_size TYPE i.

CONSTANTS:
  c_space           TYPE char1 VALUE  .
*&---------------------------------------------------------------------*
*&  INITIALIZATION
*&---------------------------------------------------------------------*
INITIALIZATION.
  CLEAR:
   gt_cost_center_show,
   gt_ctrtbu,
   gt_fieldcat,
   gs_fieldcat,
   gs_layout,
   gs_cost_center,
   ls_ctrtbu_id,
   lv_kostl,
   gt_ctrtbu_new,
   gs_ctrtbu_new,
   gt_output,
   gs_output,
   gs_ctrtbu.

*&---------------------------------------------------------------------*
*&  PARAMETERS DEFINITION
*&---------------------------------------------------------------------*
  SELECTION-SCREEN BEGIN OF BLOCK b01 WITH FRAME TITLE text-b01.
  SELECT-OPTIONS:so_con_d FOR contract_id.
  PARAMETERS: p_appl TYPE cacsappl DEFAULT ZICNSL.
  PARAMETERS: s_date TYPE begdatum.
  SELECTION-SCREEN END OF BLOCK b01.

  SELECTION-SCREEN BEGIN OF BLOCK bk3 WITH FRAME.
  PARAMETERS: p_pll    AS CHECKBOX,
              p_prcno  TYPE i DEFAULT 50 OBLIGATORY,
              p_maxpol TYPE i DEFAULT 2000 OBLIGATORY,
              p_pksz   TYPE i DEFAULT 2000000 OBLIGATORY.
  SELECTION-SCREEN END OF BLOCK bk3.
*&---------------------------------------------------------------------*
*&  START-OF-SELECTION
*&---------------------------------------------------------------------*
START-OF-SELECTION.

  OPEN CURSOR WITH HOLD lv_cursor FOR
  SELECT ctrtbu_id version leav_date FROM cacs_ctrtbu
    WHERE ctrtbu_id IN so_con_d AND
     flg_cancel_obj   = c_space AND
     flg_cancel_vers  = c_space.

  CLEAR gv_batch.
  DO.
    FETCH NEXT CURSOR lv_cursor INTO CORRESPONDING FIELDS OF TABLE gt_contract
      PACKAGE SIZE p_pksz.
    IF sy-subrc <> 0.
      CLOSE CURSOR lv_cursor.
      EXIT.
    ELSE.
      SORT gt_contract DESCENDING BY ctrtbu_id version.
      DELETE ADJACENT DUPLICATES FROM gt_contract COMPARING ctrtbu_id.
*------------------ Start edit by James on 2018/05/10-----------------*
      DELETE gt_contract WHERE leav_date IS NOT INITIAL.
*------------------ END edit by James on 2018/05/10-----------------*
    ENDIF.
    gv_batch = gv_batch + 1.
    CLEAR gs_pol.
    gs_pol-batch = gv_batch.
    CREATE DATA gs_pol-tb_contract TYPE STANDARD TABLE OF gty_contract.
    ASSIGN gs_pol-tb_contract->* TO FIELD-SYMBOL(<lfs_tb>).
    <lfs_tb> = gt_contract[].
    APPEND gs_pol TO gt_pol.
  ENDDO.

  CLEAR lv_batch.
  FIELD-SYMBOLS <lfs_temp> TYPE ANY TABLE.
  DO gv_batch TIMES.
    lv_batch = lv_batch + 1.
    CLEAR gt_contract.
    READ TABLE gt_pol INTO gs_pol WITH KEY batch = lv_batch.
    IF sy-subrc = 0.
      ASSIGN gs_pol-tb_contract->* TO <lfs_temp>.
      gt_contract = <lfs_temp>.
    ENDIF.
    IF p_pll = X AND gt_contract IS NOT INITIAL.
      PERFORM parallel_processing.
    ELSE.
      PERFORM get_data.
    ENDIF.
  ENDDO.
*------------------ Start edit by James on 2018/05/10-----------------*
  PERFORM frm_set_layout.
  PERFORM frm_set_fieldcat.
  PERFORM frm_display_alv.
*------------------ END edit by James on 2018/05/10-----------------*
*&---------------------------------------------------------------------*
*&      Form  FRM_SET_LAYOUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_set_layout .
  gs_layout-cwidth_opt = X.
  gs_layout-zebra      = X.
  gs_layout-sel_mode   = D.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_SET_FIELDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_set_fieldcat .

  gs_fieldcat-fieldname = CTRTBU_ID.
  gs_fieldcat-coltext   = COMMISSION_CONTRACT.
  gs_fieldcat-outputlen = 20.
  APPEND gs_fieldcat TO gt_fieldcat.
  CLEAR gs_fieldcat.
  gs_fieldcat-fieldname = KOSTL.
  gs_fieldcat-coltext   = CONST_CENTER.
  gs_fieldcat-outputlen = 20.
  APPEND gs_fieldcat TO gt_fieldcat.
  CLEAR gs_fieldcat.
  gs_fieldcat-fieldname = BRANCH.
  gs_fieldcat-coltext   = BRANCH.
  gs_fieldcat-outputlen = 20.
  APPEND gs_fieldcat TO gt_fieldcat.
  CLEAR gs_fieldcat.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_DISPLAY_ALV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_display_alv .
*------------------Start edit by James on 2018/04/24-------------------*

  IF p_pll = X AND gt_contract IS NOT INITIAL.

    IF gt_contract IS NOT INITIAL.
      SELECT * FROM zdm_com_con_cost
        INTO TABLE gt_cost_center_show_p
        FOR ALL ENTRIES IN gt_contract
        WHERE ctrtbu_id = gt_contract-ctrtbu_id.
    ENDIF.

    IF gt_cost_center_show_p IS NOT INITIAL.
      CALL FUNCTION REUSE_ALV_GRID_DISPLAY_LVC
        EXPORTING
          i_callback_program = sy-repid
          is_layout_lvc      = gs_layout
          it_fieldcat_lvc    = gt_fieldcat
*         I_SAVE             = ‘A‘
        TABLES
          t_outtab           = gt_cost_center_show_p
        EXCEPTIONS
          program_error      = 1
          OTHERS             = 2.
    ENDIF.
  ELSE.
    IF gt_cost_center_show IS NOT INITIAL.
      CALL FUNCTION REUSE_ALV_GRID_DISPLAY_LVC
        EXPORTING
          i_callback_program = sy-repid
          is_layout_lvc      = gs_layout
          it_fieldcat_lvc    = gt_fieldcat
*         I_SAVE             = ‘A‘
        TABLES
          t_outtab           = gt_cost_center_show
        EXCEPTIONS
          program_error      = 1
          OTHERS             = 2.
    ENDIF.
    MODIFY zdm_com_con_cost FROM TABLE gt_cost_center_show.
    IF sy-subrc = 0.
      COMMIT WORK.
    ELSE.
      ROLLBACK WORK.
      MESSAGE have error when save to db! TYPE E.
    ENDIF.
  ENDIF.
*------------------ End edit by James on 2018/04/24-------------------*

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_data .

* get data
  SELECT ctrtbu_id version leav_date FROM cacs_ctrtbu
    INTO CORRESPONDING FIELDS OF TABLE gt_ctrtbu
    WHERE ctrtbu_id IN so_con_d AND
     flg_cancel_obj   = c_space AND
     flg_cancel_vers  = c_space.

  SORT gt_ctrtbu DESCENDING BY ctrtbu_id version.
  DELETE ADJACENT DUPLICATES FROM gt_ctrtbu COMPARING ctrtbu_id.
  DELETE gt_ctrtbu WHERE leav_date IS NOT INITIAL.

  IF gt_ctrtbu IS NOT INITIAL.

    LOOP AT gt_ctrtbu INTO gs_ctrtbu.
      gs_ctrtbu_new-cacs_ctrtbu_id = gs_ctrtbu-ctrtbu_id.
      gs_ctrtbu_new-cycle_date     = s_date.
      APPEND gs_ctrtbu_new TO gt_ctrtbu_new.
      CLEAR:
        gs_ctrtbu_new,
        gs_ctrtbu.
    ENDLOOP.

    IF gt_ctrtbu_new IS NOT INITIAL.
      CALL FUNCTION /NSL/ICM_GET_CTRT_INFO
        EXPORTING
          it_input              = gt_ctrtbu_new
        TABLES
          et_output             = gt_output
        EXCEPTIONS
          input_parameter_empty = 1
          OTHERS                = 2.
      IF sy-subrc <> 0.
*       Implement suitable error handling here
      ENDIF.

      LOOP AT gt_output INTO gs_output.
        gs_cost_center-kostl     = gs_output-cost_center.
        gs_cost_center-ctrtbu_id = gs_output-cacs_ctrtbu_id.
        gs_cost_center-branch    = gs_output-branch.
        APPEND gs_cost_center TO gt_cost_center_show.
        CLEAR:
          gs_output,
          gs_cost_center.
      ENDLOOP.

      IF gt_cost_center_show IS NOT INITIAL.
        MODIFY zdm_com_con_cost FROM TABLE gt_cost_center_show.
        IF sy-subrc <> 0.
          ROLLBACK WORK.
          MESSAGE  have error when save entry to db! TYPE E.
        ELSEIF sy-subrc = 0.
          COMMIT WORK.
        ENDIF.
      ENDIF.
    ENDIF.
  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  PARALLEL_PROCESSING
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM parallel_processing .
  DATA: l_last,
        l_rec_cnt     TYPE i,
        l_task_idx(5) TYPE n.

  DATA: lo_cx_root       TYPE REF TO cx_root,
        l_exception      TYPE        string,
        l_error_msg(100),
        ls_contract      TYPE gty_contract.

  DATA  lt_contract_pall TYPE STANDARD TABLE OF cacs_ctrtbu.
  DATA  ls_contract_pall TYPE cacs_ctrtbu.
  DATA  lv_no_of_pp TYPE i .

  CLEAR:
    l_rec_cnt,
    lt_contract_pall,
    ls_contract.

  LOOP AT gt_contract INTO ls_contract.
    ls_contract_pall-ctrtbu_id = ls_contract-ctrtbu_id .
    ls_contract_pall-leav_date = ls_contract-leav_date.
    APPEND ls_contract_pall TO lt_contract_pall.
    l_rec_cnt = l_rec_cnt + 1.

    AT LAST.
      l_last = X.
    ENDAT.

    IF l_rec_cnt >= p_maxpol OR l_last = X.
      l_task_idx = l_task_idx + 1.
      CONCATENATE ZDM_ICM_ACCBAL l_task_idx INTO g_taskno.
      DO 1 TIMES.
        TRY.
            CALL FUNCTION /NSL/_ICM_CALL_WITHOUT_COS_CEN
              STARTING NEW TASK g_taskno
              DESTINATION IN GROUP DEFAULT
              PERFORMING end_of_process ON END OF TASK
              EXPORTING
                s_date                = s_date
                ctrtbu_id             = ls_contract_pall-ctrtbu_id
                p_appl                = p_appl
              TABLES
                tab_contract          = lt_contract_pall
                so_con_d              = so_con_d
              EXCEPTIONS
                communication_failure = 1 MESSAGE l_error_msg
                system_failure        = 2 MESSAGE l_error_msg
                resource_failure      = 3
                other                 = 99.
            IF sy-subrc = 1.
            ELSEIF sy-subrc = 2.
            ELSEIF sy-subrc = 3.
            ENDIF.
          CATCH cx_root INTO lo_cx_root.
            l_exception = lo_cx_root->get_text( ).
        ENDTRY.

        CASE sy-subrc.
          WHEN 0.
            g_running = g_running + 1.
            EXIT.
          WHEN 1 OR 2 OR 99.
            IF l_exception NE space.
              l_error_msg = l_exception.
            ENDIF.

            IF l_error_msg IS INITIAL.
              MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                      INTO l_error_msg
                      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
            ENDIF.
            WRITE:/ g_taskno, RFC call failed:, l_error_msg.
            EXIT.
          WHEN 3.
            WAIT UP TO 5 SECONDS.
            WAIT FOR ASYNCHRONOUS TASKS UNTIL g_running < lv_no_of_pp.
            IF sy-index = 10.
              WRITE:/ g_taskno, RFC call failed: Waited resource for more than 10 times.
              EXIT.
            ENDIF.
* check number of available resource with SPBT_INITIALIZE
        ENDCASE.
      ENDDO.
      CLEAR: l_rec_cnt, lt_contract_pall.
    ENDIF.
*    WAIT FOR ASYNCHRONOUS TASKS UNTIL g_running < lv_no_of_pp.
    CLEAR:
    ls_contract.
  ENDLOOP.
* wait until all jobs finished
*  WAIT FOR ASYNCHRONOUS TASKS UNTIL g_running = 0.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  END_OF_PROCESS
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM end_of_process  USING    p_taskno.

  DATA: l_msg(100).

  RECEIVE RESULTS FROM FUNCTION /NSL/_ICM_CALL_WITHOUT_COS_CEN
    EXCEPTIONS
      communication_failure = 1 MESSAGE l_msg
      system_failure        = 2 MESSAGE l_msg
      OTHERS                = 3.
  IF sy-subrc = 0.
  ELSE.
    WRITE:/ p_taskno, RFC call failed(Receive):, l_msg.
  ENDIF.
  g_running = g_running - 1.
ENDFORM.

/NSL/_ICM_CALL_WITHOUT_COS_CEN

 

以上是关于Query the commission contract which without cost center(分批处理数据,多线程异步调用)的主要内容,如果未能解决你的问题,请参考以下文章

[hdu4010]: Query on The Trees

MySQL Query Latency with the DTrace pid Provider

百度之星2014~复赛 解题报告~正解The Query on the Tree

HQL: The Hibernate Query Language

HDU 4836 The Query on the Tree lca || 欧拉序列 || 动态树

40.1. The Query Tree