Advertisement
Guest User

Проверка диапазонов номеров

a guest
Jan 6th, 2016
347
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. *&---------------------------------------------------------------------*
  2. *& Проверка диапазонов номеров
  3. *&---------------------------------------------------------------------*
  4. report yecc_bc_check_09.
  5.  
  6. data: begin of gs_report,
  7.         status    type icon-id,
  8.         object    type tnro-object,
  9.         devclass  type tadir-devclass,
  10.         yearind   type tnro-yearind,
  11.         dtelsobj  type tnro-dtelsobj,
  12.         next_year type char1,
  13.         is_used   type char1,
  14.         txtshort  type tnrot-txtshort,
  15.  
  16.         code         type tnro-code,
  17.  
  18.         nrrangenr    type nriv-nrrangenr,
  19.  
  20.         percentage   type tnro-percentage,
  21.         percentage_f type tnro-percentage,
  22.  
  23.         txt      type tnrot-txt,
  24.         include  type cross-include,
  25.         messages type bapiret2_tab,
  26.         msgty    type sy-msgty,
  27.       end of gs_report.
  28.  
  29. selection-screen begin of block b_sel with frame title text-001.
  30. select-options: s_obj for gs_report-object default 'Z*' option cp.
  31. parameters:  p_year type nriv-toyear obligatory memory id gjr.
  32. selection-screen end of block b_sel.
  33.  
  34. data: gt_report like gs_report occurs 0 with header line.
  35. field-symbols: <fs_report> like gs_report.
  36.  
  37. data: gr_table type ref to cl_salv_table.
  38.  
  39. data: p_year_next type nriv-toyear.
  40.  
  41. start-of-selection.
  42.   p_year_next = p_year + 1.
  43.  
  44.   perform select_data.
  45.   perform display_alv.
  46.  
  47. end-of-selection.
  48.  
  49. form select_data.
  50.   select *
  51.     into corresponding fields of table gt_report
  52.     from tnro
  53.     where tnro~object in s_obj.
  54.  
  55.   loop at gt_report assigning <fs_report>.
  56.     select single txt txtshort
  57.       from tnrot
  58.       into corresponding fields of <fs_report>
  59.       where object = <fs_report>-object
  60.         and langu = sy-langu.
  61.  
  62.     select single devclass from tadir into corresponding fields of <fs_report>
  63.       where pgmid = 'R3TR'
  64.         and object = 'NROB'
  65.         and obj_name = <fs_report>-object.
  66.   endloop.
  67.  
  68.   loop at gt_report assigning <fs_report>.
  69.     data: lt_nriv type standard table of nriv with header line.
  70.  
  71.     clear lt_nriv.
  72.     clear lt_nriv[].
  73.  
  74.     if <fs_report>-yearind = 'X'.
  75.       lt_nriv-toyear = p_year.
  76.     else.
  77.       lt_nriv-toyear = ''.
  78.     endif.
  79.     lt_nriv-object = <fs_report>-object.
  80.  
  81.     select * from nriv into table lt_nriv
  82.       where object = lt_nriv-object
  83.         and toyear = lt_nriv-toyear.
  84.  
  85.     if lines( lt_nriv ) = 0.
  86.       <fs_report>-is_used = '-'.
  87.     else.
  88.       if lines( lt_nriv ) = 1.
  89.         <fs_report>-nrrangenr = lt_nriv[ 1 ]-nrrangenr.
  90.       else.
  91.         <fs_report>-nrrangenr = 'XX'.
  92.       endif.
  93.  
  94.       loop at lt_nriv.
  95.         if lt_nriv-nrlevel ne space.
  96.           <fs_report>-is_used = 'X'.
  97.  
  98.           data: lv_percentage type f.
  99.           lv_percentage = ( lt_nriv-nrlevel - lt_nriv-fromnumber ) / (  lt_nriv-tonumber - lt_nriv-fromnumber ) * 100.
  100.  
  101.           if  lv_percentage > <fs_report>-percentage_f.
  102.             <fs_report>-percentage_f = lv_percentage.
  103.           endif.
  104.         endif.
  105.       endloop.
  106.  
  107.       data: lt_nriv_next type standard table of nriv with header line.
  108.  
  109.       clear lt_nriv_next.
  110.       clear lt_nriv_next[].
  111.  
  112.       if <fs_report>-yearind = 'X'.
  113.         select * from nriv into table lt_nriv_next
  114.           where object = <fs_report>-object
  115.             and toyear = p_year_next.
  116.  
  117.         if lines( lt_nriv_next ) > 0.
  118.           <fs_report>-next_year = 'X'.
  119.         endif.
  120.       endif.
  121.  
  122.     endif.
  123.   endloop.
  124.  
  125.   data: lt_cross type standard table of cross with header line.
  126.   select * from cross into table lt_cross
  127.       where type = 'F'
  128.         and name = 'NUMBER_GET_NEXT'
  129.         and ( include like 'Z%' or  include like 'LZ%' ).
  130.  
  131.   data: lt_abap type abaptxt255_tab.
  132.   data: lv_abap type abaptxt255.
  133.  
  134.   data: lv_fm_begin type char1.
  135.  
  136.   loop at lt_cross.
  137.     clear lt_abap[].
  138.  
  139.     read report lt_cross-include into lt_abap.
  140.     assert sy-subrc = 0.
  141.  
  142.     lv_fm_begin = ' '.
  143.  
  144.     loop at lt_abap into lv_abap.
  145.       if lv_abap cs 'NUMBER_GET_NEXT'.
  146.         if lv_abap(1) ne '*'.
  147.           lv_fm_begin = 'X'.
  148.         endif.
  149.       endif.
  150.  
  151.       if lv_fm_begin = 'X' and lv_abap cs '.'.
  152.         lv_fm_begin = ' '.
  153.       endif.
  154.  
  155.       if lv_fm_begin = 'X'.
  156.         data: lt_result type match_result_tab.
  157.  
  158.         find regex `OBJECT.*=.*'(.*)'`
  159.              in lv_abap
  160.              ignoring case
  161.              submatches data(lv_obj).
  162.         if sy-subrc = 0.
  163.           read table gt_report assigning <fs_report> with key object = lv_obj.
  164.           if sy-subrc = 0.
  165.             if <fs_report>-include = space.
  166.               <fs_report>-include = lt_cross-include.
  167.             else.
  168.               <fs_report>-include = '*'.
  169.             endif.
  170.           endif.
  171.         endif.
  172.  
  173.       endif.
  174.  
  175.     endloop.
  176.  
  177.   endloop.
  178.  
  179.   data: lv_message type string.
  180.  
  181.   loop at gt_report assigning <fs_report>.
  182.     if <fs_report>-yearind = 'X' and <fs_report>-is_used = 'X' and <fs_report>-next_year = 'X'.
  183.  
  184.       message i000(xt) with 'Перенесен в следующий год' into lv_message.
  185.       perform append_message using lv_message changing <fs_report>-messages <fs_report>-msgty.
  186.  
  187.     endif.
  188.  
  189.     if <fs_report>-yearind = 'X' and <fs_report>-is_used = 'X' and <fs_report>-next_year = ' '.
  190.       case <fs_report>-object.
  191.         when 'FIAA-BELNR'
  192.           or 'SO_OBJ_ADR'
  193.           or 'SO_OBJ_ALI'
  194.           or 'SO_OBJ_DLI'
  195.           or 'SO_OBJ_EXT'
  196.           or 'SO_OBJ_FOL'
  197.           or 'SO_OBJ_OBJ'
  198.           or 'SO_OBJ_RAW'
  199.           or 'SO_OBJ_RCP'
  200.           or 'SO_OBJ_USR'.
  201.  
  202.           message w000(xt) with 'Не перенесен в следующий год' into lv_message.
  203.           perform append_message using lv_message changing <fs_report>-messages <fs_report>-msgty.
  204.         when others.
  205.           message e000(xt) with 'Не перенесен в следующий год' into lv_message.
  206.           perform append_message using lv_message changing <fs_report>-messages <fs_report>-msgty.
  207.       endcase.
  208.     endif.
  209.  
  210.     if ( <fs_report>-percentage_f + <fs_report>-percentage ) >= 100.
  211.       message w000(xt) with 'Диапазон кончается' into lv_message.
  212.       perform append_message using lv_message changing <fs_report>-messages <fs_report>-msgty.
  213.     endif.
  214.  
  215.   endloop.
  216.  
  217.   loop at gt_report assigning <fs_report>.
  218.     if <fs_report>-object(1) = 'Z' and <fs_report>-include = space.
  219.       message w000(xt) with 'Не найдено использование объекта' into lv_message.
  220.       perform append_message using lv_message changing <fs_report>-messages <fs_report>-msgty.
  221.     endif.
  222.   endloop.
  223.  
  224.  
  225.   loop at gt_report assigning <fs_report>.
  226.     case <fs_report>-msgty.
  227.       when 'I'. <fs_report>-status = '@5B@'.
  228.       when 'W'. <fs_report>-status = '@5D@'.
  229.       when 'E'. <fs_report>-status = '@5C@'.
  230.     endcase.
  231.   endloop.
  232.  
  233.  
  234. endform.
  235.  
  236. form append_message using iv_message changing ct_messages type bapiret2_tab
  237.                                               cv_msgty type sy-msgty.
  238.   data: ls_bapiret type bapiret2.
  239.   ls_bapiret-message    = iv_message.
  240.   ls_bapiret-type       = sy-msgty.
  241.   ls_bapiret-id         = sy-msgid.
  242.   ls_bapiret-number     = sy-msgno.
  243.   ls_bapiret-message_v1 = sy-msgv1.
  244.   ls_bapiret-message_v2 = sy-msgv2.
  245.   ls_bapiret-message_v3 = sy-msgv3.
  246.   ls_bapiret-message_v4 = sy-msgv4.
  247.  
  248.   append ls_bapiret to ct_messages.
  249.  
  250.   if cv_msgty = space.
  251.     cv_msgty = sy-msgty.
  252.   elseif cv_msgty = 'I' and ( sy-msgty = 'W' or sy-msgty = 'E' ).
  253.     cv_msgty = sy-msgty.
  254.   elseif cv_msgty = 'W' and ( sy-msgty = 'E' ).
  255.     cv_msgty = sy-msgty.
  256.   endif.
  257.  
  258. endform.
  259.  
  260.  
  261. class lcl_handle_events definition.
  262.   public section.
  263.     methods:
  264.       on_double_click for event double_click of cl_salv_events_table
  265.         importing row column.
  266. endclass.                                                       "lcl_handle_events DEFINITION
  267.  
  268.  
  269. *----------------------------------------------------------------------*
  270. *       CLASS lcl_handle_events IMPLEMENTATION
  271. *----------------------------------------------------------------------*
  272. *
  273. *----------------------------------------------------------------------*
  274. class lcl_handle_events implementation.
  275.   method on_double_click.
  276.     perform show_cell_info using row column.
  277.   endmethod.                                                    "on_double_click
  278. endclass.                                                       "lcl_handle_events IMPLEMENTATION
  279.  
  280.  
  281. form show_cell_info using row type salv_de_row
  282.                           column type salv_de_column.
  283.  
  284.   check row ne 0.
  285.   read table gt_report index row.
  286.  
  287.   case column.
  288.     when 'STATUS'.
  289.       call function 'FINB_BAPIRET2_DISPLAY'
  290.         exporting
  291.           it_message = gt_report-messages[].
  292.     when others.
  293.   endcase.
  294.  
  295. endform.
  296.  
  297. form display_alv.
  298.   try.
  299.       call method cl_salv_table=>factory
  300.         importing
  301.           r_salv_table = gr_table
  302.         changing
  303.           t_table      = gt_report[].
  304.  
  305.  
  306.       data: gr_layout type ref to cl_salv_layout.
  307.       data: ls_key    type salv_s_layout_key.
  308.       gr_layout     = gr_table->get_layout( ).
  309.       ls_key-report = sy-repid.
  310.       gr_layout->set_key( ls_key ).
  311.       gr_layout->set_save_restriction( cl_salv_layout=>restrict_none ).
  312.  
  313.       data: lr_columns type ref to cl_salv_columns_table,
  314.             lr_column  type ref to cl_salv_column_table.
  315.  
  316.       lr_columns = gr_table->get_columns( ).
  317.       lr_columns->set_optimize( 'X' ).
  318.       lr_column ?= lr_columns->get_column( 'MSGTY' ). lr_column->set_visible( ' ' ).
  319.       lr_column ?= lr_columns->get_column( 'PERCENTAGE' ). lr_column->set_visible( ' ' ).
  320.  
  321.       lr_column ?= lr_columns->get_column( 'STATUS' ).   lr_column->set_short_text( '' ).   lr_column->set_medium_text( '' ).
  322.       lr_column->set_long_text( 'Статус' ).
  323.       lr_column->set_alignment( 3 ).
  324.  
  325.       lr_column ?= lr_columns->get_column( 'IS_USED' ).   lr_column->set_short_text( '' ).   lr_column->set_medium_text( '' ).
  326.       lr_column->set_long_text( 'Используется' ).
  327.  
  328.       lr_column ?= lr_columns->get_column( 'NEXT_YEAR' ).   lr_column->set_short_text( '' ).   lr_column->set_medium_text( '' ).
  329.       lr_column->set_long_text( 'Следующий год' ).
  330.  
  331.       lr_column ?= lr_columns->get_column( 'PERCENTAGE_F' ).   lr_column->set_short_text( '' ).   lr_column->set_medium_text( '' ).
  332.       lr_column->set_long_text( 'Факт.исп.' ).
  333.  
  334.  
  335.       data: lr_events       type ref to lcl_handle_events.
  336.       data: lr_events_table type ref to cl_salv_events_table.
  337.       lr_events_table = gr_table->get_event( ).
  338.       create object lr_events.
  339.       set handler lr_events->on_double_click for lr_events_table.
  340.  
  341.  
  342.       data: gr_functions type ref to cl_salv_functions_list.
  343.       gr_functions = gr_table->get_functions( ).
  344.       gr_functions->set_default( ).
  345.  
  346.       gr_table->display( ).
  347.  
  348.     catch cx_root.
  349.       message 'Ошибка ALV' type 'A'.
  350.   endtry.
  351. endform.
Advertisement
RAW Paste Data Copied
Advertisement