falazure123

Untitled

Sep 16th, 2022 (edited)
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ABAP 38.68 KB | None | 0 0
  1. CLASS zcl_rnpt_processor DEFINITION
  2.   PUBLIC
  3.   CREATE PUBLIC .
  4.  
  5.   PUBLIC SECTION.
  6.  
  7.     TYPES:
  8.       mtt_zrnpt TYPE TABLE OF zrnpt_input_doc .
  9.     TYPES mtt_rseg TYPE mrm_tab_mrmrseg .
  10.     TYPES mtt_rbco TYPE mrm_tab_mrmrbco .
  11.  
  12.     CLASS-METHODS process_rnpt_by_miro
  13.       IMPORTING
  14.         !iv_invoicedocnumber TYPE re_belnr
  15.         !iv_fiscalyear       TYPE gjahr
  16.         !iv_save_mode        TYPE flag
  17.         !iv_repeat_mode      TYPE flag OPTIONAL
  18.         !iv_update_batch     TYPE flag OPTIONAL
  19.         !iv_log_mode         TYPE flag DEFAULT abap_true
  20.       EXPORTING
  21.         !et_ret              TYPE bapiret2_t
  22.         !et_rn_reg           TYPE j_3rm_rn_reg_t .
  23.     CLASS-METHODS process_rn_by_storno_miro
  24.       IMPORTING
  25.         !iv_invoicedocnumber TYPE re_belnr
  26.         !iv_fiscalyear       TYPE gjahr
  27.         !iv_save_mode        TYPE flag OPTIONAL
  28.         !iv_log_mode         TYPE flag DEFAULT abap_true
  29.         !iv_repeat_mode      TYPE flag OPTIONAL
  30.       EXPORTING
  31.         !et_ret              TYPE bapiret2_t .
  32.   PROTECTED SECTION.
  33.   PRIVATE SECTION.
  34.  
  35.     TYPES:
  36.       BEGIN OF mty_fae,
  37.         belnr   TYPE belnr_d,
  38.         gjahr   TYPE gjahr,
  39.         buzei   TYPE rblgp,
  40.         cobl_nr TYPE cobl_nr,
  41.       END OF mty_fae .
  42.     TYPES:
  43.       BEGIN OF mty_clause,
  44.         line(72) TYPE c,
  45.       END OF mty_clause .
  46.     TYPES:
  47.       BEGIN OF mty_fae_mseg,
  48.         mblnr TYPE mblnr,
  49.         mjahr TYPE mjahr,
  50.         zeile TYPE mblpo,
  51.       END OF mty_fae_mseg .
  52.     TYPES:
  53.       BEGIN OF mty_invoic,
  54.         r_budat         TYPE budat,
  55.         r_belnr         TYPE re_belnr,
  56.         r_buzei         TYPE rblgp,
  57.         r_gjahr         TYPE gjahr,
  58.         r_bukrs         TYPE bukrs,
  59.         r_lfbnr         TYPE lfbnr,
  60.         r_ebeln         TYPE ebeln,
  61.         r_ebelp         TYPE ebelp,
  62.         r_lfgja         TYPE lfgja,
  63.         r_lfpos         TYPE lfpos,
  64.         r_waers         TYPE waers,
  65.         r_wbs_element   TYPE ps_psp_pnr,
  66.         r_aufnr         TYPE aufnr,
  67.         r_anln1         TYPE anln1,
  68.         r_anln2         TYPE anln2,
  69.         r_matnr         TYPE matnr,
  70.         r_erfnam        TYPE erfnam,
  71.         rnpt            TYPE j_3rm_rn_ext_num,
  72.         land            TYPE herkl,
  73.         wrbtr           TYPE rseg-wrbtr,
  74.         m_mjahr         TYPE mjahr,
  75.         m_mblnr         TYPE mblnr,
  76.         m_zeile         TYPE mblpo,
  77.         m_batch         TYPE charg_d,
  78.         r_menge         TYPE menge_d,
  79.         r_meins         TYPE bstme,
  80. *      r_erfnam      TYPE erfnam,
  81.         f_belnr         TYPE belnr_d,
  82.         f_pos           TYPE buzei,
  83.         f_gjahr         TYPE gjahr,
  84.         tnved           TYPE zmara_tnved-ztnved_kod,
  85.         rnpt_type_doc   TYPE zrnpt_input_doc-type_doc,
  86.         rnpt_doc_id     TYPE zrnpt_input_doc-doc_id,
  87.         rnpt_pos_id     TYPE zrnpt_input_doc-pos_id,
  88.         rnpt_sub_pos    TYPE zrnpt_input_doc-sub_pos,
  89.         rnpt_type_input TYPE zrnpt_input_doc-type_input,
  90.       END OF mty_invoic .
  91.     TYPES:
  92.       mtt_fae TYPE STANDARD TABLE OF mty_fae WITH DEFAULT KEY .
  93.     TYPES:
  94.       mtt_j3    TYPE TABLE OF j_3rm_rn_reg WITH DEFAULT KEY .
  95.     TYPES:
  96.       mtt_clause TYPE STANDARD TABLE OF mty_clause WITH DEFAULT KEY .
  97.     TYPES:
  98.       mtt_invoic TYPE STANDARD TABLE OF mty_invoic WITH DEFAULT KEY .
  99.  
  100.     CLASS-METHODS _filter_doc
  101.       IMPORTING
  102.         !iv_pos_id      TYPE char2
  103.         VALUE(it_zrnpt) TYPE mtt_zrnpt
  104.       RETURNING
  105.         VALUE(rt_fae)   TYPE mtt_fae .
  106.     CLASS-METHODS get_rn_reg_by_full_key
  107.       IMPORTING
  108.         !iv_company_code  TYPE bukrs OPTIONAL
  109.         !iv_rn_ext_number TYPE j_3rm_rn_ext_num OPTIONAL
  110.         !iv_rn_reg_date   TYPE j_3rm_rn_date OPTIONAL
  111.         !iv_batch         TYPE charg_d OPTIONAL
  112.         !iv_material      TYPE matnr OPTIONAL
  113.         !iv_serial_number TYPE gernr OPTIONAL
  114.         !iv_asset_num     TYPE anln1 OPTIONAL
  115.         !iv_asset_subnum  TYPE anln2 OPTIONAL
  116.         !iv_wbs_element   TYPE ps_psp_pnr OPTIONAL
  117.         !iv_invest_order  TYPE aufnr OPTIONAL
  118.       RETURNING
  119.         VALUE(rt_rn_reg)  TYPE mtt_j3 .
  120.     CLASS-METHODS _build_dynamic_where
  121.       IMPORTING
  122.         !iv_company_code       TYPE bukrs OPTIONAL
  123.         !iv_rn_ext_number      TYPE j_3rm_rn_ext_num OPTIONAL
  124.         !iv_rn_reg_date        TYPE j_3rm_rn_date OPTIONAL
  125.         !iv_batch              TYPE charg_d OPTIONAL
  126.         !iv_material           TYPE matnr OPTIONAL
  127.         !iv_serial_number      TYPE gernr OPTIONAL
  128.         !iv_asset_num          TYPE anln1 OPTIONAL
  129.         !iv_asset_subnum       TYPE anln2 OPTIONAL
  130.         !iv_wbs_element        TYPE ps_psp_pnr OPTIONAL
  131.         !iv_invest_order       TYPE aufnr OPTIONAL
  132.       RETURNING
  133.         VALUE(rt_where_clause) TYPE mtt_clause .
  134.     CLASS-METHODS rn_reg_create
  135.       IMPORTING
  136.         !is_invoic TYPE mty_invoic OPTIONAL
  137.         !it_invoic TYPE mtt_invoic
  138.       EXPORTING
  139.         !et_ret    TYPE bapiret2_t
  140.         !et_rn_reg TYPE mtt_j3 .
  141.     CLASS-METHODS rn_reg_update
  142.       IMPORTING
  143.         !it_rn_reg TYPE mtt_j3
  144.         !is_invoic TYPE mty_invoic OPTIONAL
  145.         !it_invoic TYPE mtt_invoic
  146.       EXPORTING
  147.         !et_ret    TYPE bapiret2_t .
  148.     CLASS-METHODS _add_message
  149.       IMPORTING
  150.         !iv_num TYPE sy-msgno
  151.       CHANGING
  152.         !ct_ret TYPE bapiret2_t .
  153. ENDCLASS.
  154.  
  155.  
  156.  
  157. CLASS zcl_rnpt_processor IMPLEMENTATION.
  158.  
  159.  
  160. * <SIGNATURE>---------------------------------------------------------------------------------------+
  161. * | Static Private Method ZCL_RNPT_PROCESSOR=>GET_RN_REG_BY_FULL_KEY
  162. * +-------------------------------------------------------------------------------------------------+
  163. * | [--->] IV_COMPANY_CODE                TYPE        BUKRS(optional)
  164. * | [--->] IV_RN_EXT_NUMBER               TYPE        J_3RM_RN_EXT_NUM(optional)
  165. * | [--->] IV_RN_REG_DATE                 TYPE        J_3RM_RN_DATE(optional)
  166. * | [--->] IV_BATCH                       TYPE        CHARG_D(optional)
  167. * | [--->] IV_MATERIAL                    TYPE        MATNR(optional)
  168. * | [--->] IV_SERIAL_NUMBER               TYPE        GERNR(optional)
  169. * | [--->] IV_ASSET_NUM                   TYPE        ANLN1(optional)
  170. * | [--->] IV_ASSET_SUBNUM                TYPE        ANLN2(optional)
  171. * | [--->] IV_WBS_ELEMENT                 TYPE        PS_PSP_PNR(optional)
  172. * | [--->] IV_INVEST_ORDER                TYPE        AUFNR(optional)
  173. * | [<-()] RT_RN_REG                      TYPE        MTT_J3
  174. * +--------------------------------------------------------------------------------------</SIGNATURE>
  175.   METHOD get_rn_reg_by_full_key.
  176.  
  177.     DATA: lt_where_clause TYPE mtt_clause.
  178.  
  179.     IF iv_material IS INITIAL " если все пустые, то выходим
  180.        AND iv_batch IS INITIAL
  181.        AND iv_serial_number IS INITIAL
  182.        AND iv_asset_num IS INITIAL
  183.        AND iv_asset_subnum IS INITIAL
  184.        AND iv_wbs_element IS INITIAL
  185.        AND iv_invest_order IS INITIAL.
  186.       RETURN.
  187.     ENDIF.
  188.  
  189.     lt_where_clause = _build_dynamic_where( iv_company_code = iv_company_code
  190.                                             iv_rn_ext_number = iv_rn_ext_number
  191.                                             iv_rn_reg_date   = iv_rn_reg_date
  192.                                             iv_batch         = iv_batch
  193.                                             iv_material      = iv_material
  194.                                             iv_serial_number = iv_serial_number
  195.                                             iv_asset_num     = iv_asset_num
  196.                                             iv_asset_subnum  = iv_asset_subnum
  197.                                             iv_wbs_element   = iv_wbs_element
  198.                                             iv_invest_order  = iv_invest_order ).
  199.  
  200.     SELECT * FROM j_3rm_rn_reg
  201.       INTO CORRESPONDING FIELDS OF TABLE @rt_rn_reg
  202.       WHERE (lt_where_clause).
  203.  
  204.   ENDMETHOD.
  205.  
  206.  
  207. * <SIGNATURE>---------------------------------------------------------------------------------------+
  208. * | Static Public Method ZCL_RNPT_PROCESSOR=>PROCESS_RNPT_BY_MIRO
  209. * +-------------------------------------------------------------------------------------------------+
  210. * | [--->] IV_INVOICEDOCNUMBER            TYPE        RE_BELNR
  211. * | [--->] IV_FISCALYEAR                  TYPE        GJAHR
  212. * | [--->] IV_SAVE_MODE                   TYPE        FLAG
  213. * | [--->] IV_REPEAT_MODE                 TYPE        FLAG(optional)
  214. * | [--->] IV_UPDATE_BATCH                TYPE        FLAG(optional)
  215. * | [--->] IV_LOG_MODE                    TYPE        FLAG (default =ABAP_TRUE)
  216. * | [<---] ET_RET                         TYPE        BAPIRET2_T
  217. * | [<---] ET_RN_REG                      TYPE        J_3RM_RN_REG_T
  218. * +--------------------------------------------------------------------------------------</SIGNATURE>
  219.   METHOD process_rnpt_by_miro.
  220.     DATA: lv_doc_id   TYPE zrnpt_doc_id,
  221.           lt_fae      TYPE TABLE OF mty_fae,
  222.           lt_fae_mseg TYPE TABLE OF mty_fae_mseg,
  223.           lt_invoic   TYPE TABLE OF mty_invoic,
  224.           lt_grp      TYPE TABLE OF mty_invoic,
  225.           lv_pos_id   TYPE zrnpt_pos_id,
  226.           lt_rn_reg   TYPE mtt_j3,
  227. *          lt_rn_reg   TYPE TABLE OF J_3RM_RN_CREATED_RET,
  228.           lt_ret      TYPE bapiret2_t,
  229.           lv_mass     TYPE abap_bool,
  230.           lo_log      TYPE REF TO zcl_bal_log.
  231.  
  232.     IF lo_log IS INITIAL AND iv_log_mode = abap_true.
  233.       lo_log = NEW #( im_extnumber = |{ iv_invoicedocnumber }{ iv_fiscalyear }| im_object = 'ZRNPT' im_subobject = 'IN_INVOICE' ).
  234.       lo_log->add_free_text( |{ 'IV_INVOICEDOCNUMBER: ' } { iv_invoicedocnumber }| ).
  235.       lo_log->add_free_text( |{ 'IV_FISCALYEAR: ' } { iv_fiscalyear }| ).
  236.       lo_log->add_free_text( |{ 'IV_SAVE_MODE: ' } { iv_save_mode }| ).
  237. *      lo_log->add_free_text( |{ 'IV_TEST_MODE: ' } { iv_test_mode }| ).
  238.       lo_log->add_free_text( |{ 'IV_REPEAT_MODE: ' } { iv_repeat_mode }| ).
  239.       lo_log->add_free_text( |{ 'IV_UPDATE_BATCH: ' } { iv_update_batch }| ).
  240.       lo_log->add_free_text( |{ 'IV_LOG_MODE: ' } { iv_log_mode }| ).
  241.     ENDIF.
  242.  
  243.     IF iv_invoicedocnumber IS INITIAL.
  244.       _add_message( EXPORTING iv_num = 065 CHANGING ct_ret = et_ret ).
  245.       RETURN.
  246.     ENDIF.
  247.  
  248.     IF iv_fiscalyear IS INITIAL.
  249.  
  250.       _add_message( EXPORTING iv_num = 066 CHANGING ct_ret = et_ret ).
  251.       RETURN.
  252.     ENDIF.
  253.  
  254.     lv_doc_id = |{ iv_invoicedocnumber }{ iv_fiscalyear }|.
  255.  
  256.     SELECT * FROM zrnpt_input_doc
  257.      WHERE doc_id = @lv_doc_id
  258.        AND type_doc = 'BUS2081'
  259.        AND rnpt <> ''
  260.        INTO TABLE @DATA(lt_zrnpt).
  261.  
  262.     IF iv_repeat_mode <> 'X'.
  263.       DELETE lt_zrnpt WHERE rn_reg_year IS NOT INITIAL.
  264.     ENDIF.
  265.  
  266.     IF lt_zrnpt IS INITIAL.
  267.       _add_message( EXPORTING iv_num = 067 CHANGING ct_ret = et_ret ).
  268.       RETURN.
  269.     ENDIF.
  270.  
  271.     SELECT SINGLE * FROM rbkp
  272.       WHERE belnr = @iv_invoicedocnumber
  273.         AND gjahr = @iv_fiscalyear
  274.       INTO @DATA(ls_rbkp).
  275.  
  276.     IF ls_rbkp-rbstat <> '5'.
  277.       _add_message( EXPORTING iv_num = 068 CHANGING ct_ret = et_ret ).
  278.       RETURN.
  279.     ENDIF.
  280.  
  281.     IF ls_rbkp-ivtyp = '5'.
  282.       _add_message( EXPORTING iv_num = 069 CHANGING ct_ret = et_ret ).
  283.       RETURN.
  284.     ENDIF.
  285.  
  286.     IF ls_rbkp-stblg IS NOT INITIAL.
  287.       _add_message( EXPORTING iv_num = 070 CHANGING ct_ret = et_ret ).
  288.       RETURN.
  289.     ENDIF.
  290.  
  291.     SELECT * FROM bkpf
  292.       WHERE awtyp = 'RMRP'
  293.         AND awkey = @lv_doc_id
  294.       INTO TABLE @DATA(lt_bkpf).
  295.     IF sy-subrc = 0.
  296.       SELECT * FROM bseg
  297.         INTO TABLE @DATA(lt_bseg)
  298.         FOR ALL ENTRIES IN @lt_bkpf
  299.         WHERE bukrs = @lt_bkpf-bukrs
  300.           AND belnr = @lt_bkpf-belnr
  301.           AND gjahr = @lt_bkpf-gjahr.
  302.     ENDIF.
  303.  
  304.     lt_fae = _filter_doc( it_zrnpt = lt_zrnpt iv_pos_id = 'ЗП' ).
  305.     IF lt_fae IS NOT INITIAL.
  306.       SELECT * FROM rseg
  307.         FOR ALL ENTRIES IN @lt_fae
  308.         WHERE belnr = @lt_fae-belnr
  309.           AND gjahr = @lt_fae-gjahr
  310.           AND buzei = @lt_fae-buzei
  311.       INTO TABLE @DATA(lt_rseg).
  312.     ENDIF.
  313.  
  314.     IF lt_rseg IS NOT INITIAL.
  315.       SELECT * FROM rbco
  316.         FOR ALL ENTRIES IN @lt_rseg
  317.         WHERE belnr = @lt_rseg-belnr
  318.           AND gjahr = @lt_rseg-gjahr
  319.           AND buzei = @lt_rseg-buzei
  320.         INTO TABLE @DATA(lt_rbco_rseg).
  321.     ENDIF.
  322.  
  323.     lt_fae = _filter_doc( it_zrnpt = lt_zrnpt iv_pos_id = 'ОС' ).
  324.     IF lt_fae IS NOT INITIAL.
  325.       SELECT * FROM rbco
  326.         FOR ALL ENTRIES IN @lt_fae
  327.         WHERE belnr   = @lt_fae-belnr
  328.           AND gjahr   = @lt_fae-gjahr
  329.           AND cobl_nr = @lt_fae-cobl_nr
  330.       INTO TABLE @DATA(lt_rbco).
  331.     ENDIF.
  332.  
  333.     IF lt_rseg IS NOT INITIAL.
  334.       SELECT * FROM zmara_tnved
  335.         INTO TABLE @DATA(lt_tnved)
  336.         FOR ALL ENTRIES IN @lt_rseg
  337.         WHERE matnr = @lt_rseg-matnr.
  338.     ENDIF.
  339.  
  340.     LOOP AT lt_rseg INTO DATA(ls_rseg).
  341.       APPEND INITIAL LINE TO lt_invoic ASSIGNING FIELD-SYMBOL(<fs_row>).
  342.       <fs_row>-r_buzei = ls_rseg-buzei.
  343.       <fs_row>-r_lfbnr = ls_rseg-lfbnr.
  344.       <fs_row>-r_ebeln = ls_rseg-ebeln.
  345.       <fs_row>-r_ebelp = ls_rseg-ebelp.
  346.       <fs_row>-r_lfgja = ls_rseg-lfgja.
  347.       <fs_row>-r_lfpos = ls_rseg-lfpos.
  348.       <fs_row>-r_matnr = ls_rseg-matnr.
  349.       <fs_row>-r_menge = ls_rseg-menge.
  350.       <fs_row>-r_meins = ls_rseg-meins.
  351.       <fs_row>-wrbtr   = ls_rseg-wrbtr.
  352.       IF <fs_row>-r_lfbnr IS NOT INITIAL.
  353.         APPEND VALUE #( mblnr = <fs_row>-r_lfbnr mjahr = <fs_row>-r_lfgja zeile = <fs_row>-r_lfpos ) TO lt_fae_mseg.
  354.       ENDIF.
  355.  
  356.       READ TABLE lt_tnved WITH KEY matnr = <fs_row>-r_matnr INTO DATA(ls_tnved).
  357.       IF sy-subrc = 0.
  358.         <fs_row>-tnved = ls_tnved-ztnved_kod.
  359.       ENDIF.
  360.  
  361.       <fs_row>-r_budat = ls_rbkp-budat.
  362.       <fs_row>-r_belnr = ls_rbkp-belnr.
  363.       <fs_row>-r_gjahr = ls_rbkp-gjahr.
  364.       <fs_row>-r_bukrs = ls_rbkp-bukrs.
  365.       <fs_row>-r_waers = ls_rbkp-waers.
  366.       <fs_row>-r_erfnam = ls_rbkp-erfnam.
  367.  
  368.       READ TABLE lt_bseg WITH KEY ebeln = <fs_row>-r_ebeln ebelp = <fs_row>-r_ebelp INTO DATA(ls_bseg).
  369.       IF sy-subrc = 0.
  370.         <fs_row>-f_belnr = ls_bseg-belnr.
  371.         <fs_row>-f_pos   = ls_bseg-buzei.
  372.         <fs_row>-f_gjahr = ls_bseg-gjahr.
  373.       ENDIF.
  374.  
  375.       READ TABLE lt_rbco_rseg WITH KEY belnr = <fs_row>-r_belnr
  376.                                        gjahr = <fs_row>-r_gjahr
  377.                                        buzei = <fs_row>-r_buzei INTO DATA(ls_rbco_rseg).
  378.       IF sy-subrc = 0.
  379.         <fs_row>-r_wbs_element = ls_rbco_rseg-ps_psp_pnr.
  380.         <fs_row>-r_aufnr = ls_rbco_rseg-aufnr.
  381.         <fs_row>-r_anln1 = ls_rbco_rseg-anln1.
  382.         <fs_row>-r_anln2 = ls_rbco_rseg-anln2.
  383.  
  384.         lv_pos_id = |{ 'ОС' }{ ls_rbco_rseg-cobl_nr }|.
  385.  
  386. *        READ TABLE lt_zrnpt WITH KEY pos_id = lv_pos_id INTO DATA(ls_zrnpt).
  387.         CLEAR lv_mass.
  388.         LOOP AT lt_zrnpt INTO DATA(ls_zrnpt) WHERE pos_id = lv_pos_id.
  389. *        IF sy-subrc = 0.
  390.           IF lv_mass = abap_true. " если уже есть строка с текущим РНПТ, то дублируем строку
  391.             APPEND INITIAL LINE TO lt_invoic ASSIGNING FIELD-SYMBOL(<fs_copy>).
  392.             <fs_copy> = CORRESPONDING #( <fs_row> ).
  393.             <fs_copy>-rnpt = ls_zrnpt-rnpt.
  394.             <fs_copy>-land = ls_zrnpt-land.
  395.             <fs_copy>-r_menge = ls_zrnpt-menge.
  396.             <fs_copy>-r_meins = ls_zrnpt-meins.
  397.             <fs_copy>-wrbtr = ls_zrnpt-amount.
  398.             <fs_copy>-rnpt_type_doc = ls_zrnpt-type_doc.
  399.             <fs_copy>-rnpt_doc_id = ls_zrnpt-doc_id.
  400.             <fs_copy>-rnpt_pos_id = ls_zrnpt-pos_id.
  401.             <fs_copy>-rnpt_sub_pos = ls_zrnpt-sub_pos.
  402.             <fs_copy>-rnpt_type_input = ls_zrnpt-type_input.
  403.           ELSE.
  404.             <fs_row>-rnpt = ls_zrnpt-rnpt.
  405.             <fs_row>-land = ls_zrnpt-land.
  406.             <fs_row>-r_menge = ls_zrnpt-menge.
  407.             <fs_row>-r_meins = ls_zrnpt-meins.
  408.             <fs_row>-wrbtr = ls_zrnpt-amount.
  409.             <fs_row>-rnpt_type_doc = ls_zrnpt-type_doc.
  410.             <fs_row>-rnpt_doc_id = ls_zrnpt-doc_id.
  411.             <fs_row>-rnpt_pos_id = ls_zrnpt-pos_id.
  412.             <fs_row>-rnpt_sub_pos = ls_zrnpt-sub_pos.
  413.             <fs_row>-rnpt_type_input = ls_zrnpt-type_input.
  414.           ENDIF.
  415. *        ENDIF.
  416.           lv_mass = abap_true.
  417.         ENDLOOP.
  418.       ENDIF.
  419.  
  420.       IF <fs_row>-rnpt IS INITIAL.
  421.         lv_pos_id = |{ 'ЗП' }{ ls_rseg-buzei }|.
  422. *        READ TABLE lt_zrnpt WITH KEY pos_id = lv_pos_id INTO ls_zrnpt.
  423.         CLEAR: lv_mass.
  424.         LOOP AT lt_zrnpt INTO ls_zrnpt WHERE pos_id = lv_pos_id.
  425. *        IF sy-subrc = 0.
  426.           IF lv_mass = abap_true. " если уже есть строка с текущим РНПТ, то дублируем строку
  427.             APPEND INITIAL LINE TO lt_invoic ASSIGNING <fs_copy>.
  428.             <fs_copy> = CORRESPONDING #( <fs_row> ).
  429.             <fs_copy>-rnpt = ls_zrnpt-rnpt.
  430.             <fs_copy>-land = ls_zrnpt-land.
  431.             <fs_copy>-r_menge = ls_zrnpt-menge.
  432.             <fs_copy>-r_meins = ls_zrnpt-meins.
  433.             <fs_copy>-wrbtr = ls_zrnpt-amount.
  434.             <fs_copy>-rnpt_type_doc = ls_zrnpt-type_doc.
  435.             <fs_copy>-rnpt_doc_id = ls_zrnpt-doc_id.
  436.             <fs_copy>-rnpt_pos_id = ls_zrnpt-pos_id.
  437.             <fs_copy>-rnpt_sub_pos = ls_zrnpt-sub_pos.
  438.             <fs_copy>-rnpt_type_input = ls_zrnpt-type_input.
  439.           ELSE.
  440.             <fs_row>-rnpt = ls_zrnpt-rnpt.
  441.             <fs_row>-land = ls_zrnpt-land.
  442.             <fs_row>-r_menge = ls_zrnpt-menge.
  443.             <fs_row>-r_meins = ls_zrnpt-meins.
  444.             <fs_row>-wrbtr = ls_zrnpt-amount.
  445.             <fs_row>-rnpt_type_doc = ls_zrnpt-type_doc.
  446.             <fs_row>-rnpt_doc_id = ls_zrnpt-doc_id.
  447.             <fs_row>-rnpt_pos_id = ls_zrnpt-pos_id.
  448.             <fs_row>-rnpt_sub_pos = ls_zrnpt-sub_pos.
  449.             <fs_row>-rnpt_type_input = ls_zrnpt-type_input.
  450.           ENDIF.
  451. *        ENDIF.
  452.           lv_mass = abap_true.
  453.         ENDLOOP.
  454.       ENDIF.
  455.  
  456.     ENDLOOP.
  457.  
  458.     IF lt_fae_mseg IS NOT INITIAL.
  459.       SELECT * FROM mseg
  460.         INTO TABLE @DATA(lt_mseg)
  461.         FOR ALL ENTRIES IN @lt_fae_mseg
  462.         WHERE mblnr = @lt_fae_mseg-mblnr
  463.           AND mjahr = @lt_fae_mseg-mjahr
  464.           AND zeile = @lt_fae_mseg-zeile.
  465.  
  466.       LOOP AT lt_invoic ASSIGNING <fs_row> WHERE r_lfbnr IS NOT INITIAL.
  467.         READ TABLE lt_mseg WITH KEY mblnr = <fs_row>-r_lfbnr
  468.                                     mjahr = <fs_row>-r_lfgja
  469.                                     zeile = <fs_row>-r_lfpos INTO DATA(ls_mseg).
  470.         IF sy-subrc = 0.
  471.           <fs_row>-m_mblnr = ls_mseg-mblnr.
  472.           <fs_row>-m_batch = ls_mseg-charg.
  473.           <fs_row>-m_mjahr = ls_mseg-mjahr.
  474.           <fs_row>-m_zeile = ls_mseg-zeile.
  475.         ENDIF.
  476.       ENDLOOP.
  477.     ENDIF.
  478.  
  479.     LOOP AT lt_invoic INTO DATA(ls_invoic)
  480.       GROUP BY ( r_bukrs       = ls_invoic-r_bukrs
  481.                  r_rnpt        = ls_invoic-rnpt
  482.                  m_batch       = ls_invoic-m_batch
  483.                  r_matnr       = ls_invoic-r_matnr
  484.                  r_anln1       = ls_invoic-r_anln1
  485.                  r_anln2       = ls_invoic-r_anln2
  486.                  r_wbs_element = ls_invoic-r_wbs_element
  487.                  r_aufnr       = ls_invoic-r_aufnr ).
  488.       CLEAR: lt_ret, lt_rn_reg.
  489.  
  490.       lt_rn_reg = get_rn_reg_by_full_key( iv_company_code = ls_invoic-r_bukrs
  491.                                           iv_rn_ext_number = ls_invoic-rnpt
  492.                                           iv_batch = ls_invoic-m_batch
  493.                                           iv_material = ls_invoic-r_matnr
  494. *                                          iv_serial_number = ls_invoic-
  495.                                           iv_asset_num = ls_invoic-r_anln1
  496.                                           iv_asset_subnum = ls_invoic-r_anln2
  497.                                           iv_wbs_element = ls_invoic-r_wbs_element
  498.                                           iv_invest_order = ls_invoic-r_aufnr ).
  499.       CLEAR lt_grp.
  500.       LOOP AT GROUP ls_invoic INTO DATA(ls_grp).
  501.         APPEND ls_grp TO lt_grp.
  502.       ENDLOOP.
  503.  
  504.       IF lt_rn_reg IS INITIAL.
  505.         rn_reg_create(
  506.           EXPORTING
  507.             is_invoic = ls_invoic
  508.             it_invoic = lt_grp
  509.           IMPORTING
  510.             et_ret = lt_ret
  511.             et_rn_reg = lt_rn_reg ).
  512.       ELSE.
  513.         rn_reg_update(
  514.           EXPORTING
  515.             it_rn_reg = lt_rn_reg
  516.             is_invoic = ls_invoic
  517.             it_invoic = lt_grp
  518.           IMPORTING
  519.             et_ret = lt_ret ).
  520.  
  521.       ENDIF.
  522.       APPEND LINES OF lt_ret TO et_ret.
  523.  
  524.       CLEAR: lt_ret, lt_rn_reg.
  525.     ENDLOOP.
  526.  
  527.     IF iv_log_mode = abap_true.
  528.       LOOP AT et_ret INTO DATA(ls_ret).
  529.         lo_log->add_message(
  530.           EXPORTING
  531.             im_msgid = ls_ret-id
  532.             im_msgno = ls_ret-number
  533.             im_msgty = ls_ret-type
  534.             im_msgv1 = ls_ret-message_v1
  535.             im_msgv2 = ls_ret-message_v2
  536.             im_msgv3 = ls_ret-message_v3
  537.             im_msgv4 = ls_ret-message_v4 ).
  538.       ENDLOOP.
  539.       lo_log->save( ).
  540.     ENDIF.
  541.  
  542.     LOOP AT et_ret TRANSPORTING NO FIELDS WHERE type CA 'EAX'.
  543.       EXIT.
  544.     ENDLOOP.
  545.  
  546.     IF iv_save_mode = abap_true.
  547.       CALL FUNCTION 'J_3RM_RN_REG_COMMIT_WORK'
  548.         EXPORTING
  549.           iv_wait = abap_true.
  550.     ENDIF.
  551.  
  552. *    IF iv_save_mode = abap_true.
  553. *      IF iv_test_mode = abap_true OR sy-subrc = 0.
  554. *        CALL FUNCTION 'J_3RM_RN_REG_ROLLBACK_WORK'.
  555. *      ELSE. "IF iv_save_mode = 'X' AND sy-subrc <> 0.
  556. *        CALL FUNCTION 'J_3RM_RN_REG_COMMIT_WORK'
  557. *          EXPORTING
  558. *            iv_wait = abap_true.
  559. *      ENDIF.
  560. *    ENDIF.
  561.  
  562.   ENDMETHOD.
  563.  
  564.  
  565. * <SIGNATURE>---------------------------------------------------------------------------------------+
  566. * | Static Public Method ZCL_RNPT_PROCESSOR=>PROCESS_RN_BY_STORNO_MIRO
  567. * +-------------------------------------------------------------------------------------------------+
  568. * | [--->] IV_INVOICEDOCNUMBER            TYPE        RE_BELNR
  569. * | [--->] IV_FISCALYEAR                  TYPE        GJAHR
  570. * | [--->] IV_SAVE_MODE                   TYPE        FLAG(optional)
  571. * | [--->] IV_LOG_MODE                    TYPE        FLAG (default =ABAP_TRUE)
  572. * | [--->] IV_REPEAT_MODE                 TYPE        FLAG(optional)
  573. * | [<---] ET_RET                         TYPE        BAPIRET2_T
  574. * +--------------------------------------------------------------------------------------</SIGNATURE>
  575.   METHOD process_rn_by_storno_miro.
  576.   ENDMETHOD.
  577.  
  578.  
  579. * <SIGNATURE>---------------------------------------------------------------------------------------+
  580. * | Static Private Method ZCL_RNPT_PROCESSOR=>RN_REG_CREATE
  581. * +-------------------------------------------------------------------------------------------------+
  582. * | [--->] IS_INVOIC                      TYPE        MTY_INVOIC(optional)
  583. * | [--->] IT_INVOIC                      TYPE        MTT_INVOIC
  584. * | [<---] ET_RET                         TYPE        BAPIRET2_T
  585. * | [<---] ET_RN_REG                      TYPE        MTT_J3
  586. * +--------------------------------------------------------------------------------------</SIGNATURE>
  587.   METHOD rn_reg_create.
  588.  
  589.     DATA: lt_rn_reg        TYPE j_3rm_rn_reg_t,
  590.           lt_rn_doc        TYPE j_3rm_rn_doc_t,
  591.           lt_created_rn    TYPE j_3rm_rn_created_ret,
  592.           lv_prim_doc_type TYPE j_3rm_primdoctype,
  593.           lv_prim_doc_num  TYPE j_3rm_rn_primdocnr,
  594.           lv_prim_doc_year TYPE j_3rm_rn_primdocyr,
  595.           lv_prim_doc_pos  TYPE j_3rm_rn_primdocpos,
  596.           lt_rn_reg_cre    TYPE j_3rm_rn_created_ret,
  597.           lt_ret           TYPE j_3rm_rn_messages_ret,
  598.           ls_rn_reg        TYPE j_3rm_rn_reg,
  599.           lt_rnpt_upd      TYPE TABLE OF zrnpt_input_doc,
  600.           lv_quantity      TYPE j_3rm_rn_avquant.
  601.  
  602.     LOOP AT it_invoic INTO DATA(ls).
  603.       lv_quantity = lv_quantity + ls-r_menge.
  604.     ENDLOOP.
  605.  
  606.     APPEND VALUE j_3rm_rn_reg_s(
  607.                     internal_id       = '00001'
  608.                     rn_ext_num        = is_invoic-rnpt
  609.                     rn_reg_date       = is_invoic-r_budat
  610.                     src_oper_type     = '01'
  611.                     material          = is_invoic-r_matnr
  612.                     asset_num         = is_invoic-r_anln1
  613.                     asset_subnum      = is_invoic-r_anln2
  614.                     company_code      = is_invoic-r_bukrs
  615.                     country_of_origin = is_invoic-land
  616.                     batch             = is_invoic-m_batch
  617.                     unit_of_measure   = is_invoic-r_meins
  618. *                    serial_number    =  " ???
  619.                     quantity          = lv_quantity "is_invoic-r_menge
  620.                     wbs_element       = is_invoic-r_wbs_element
  621. *                    invest_order     = " ???
  622.                                   ) TO lt_rn_reg.
  623.  
  624.     " Для группы заполняем параметр
  625.     LOOP AT it_invoic INTO DATA(ls_invoic).
  626.       IF ls_invoic-r_anln1 IS NOT INITIAL OR ls_invoic-r_wbs_element IS NOT INITIAL.
  627.         lv_prim_doc_type = '06'.
  628.       ELSE.
  629.         lv_prim_doc_type = '01'.
  630.       ENDIF.
  631.  
  632.       IF ls_invoic-m_mblnr IS INITIAL.
  633.         lv_prim_doc_num = ls_invoic-f_belnr.
  634.         lv_prim_doc_year = ls_invoic-f_gjahr.
  635.       ELSE.
  636.         lv_prim_doc_num = ls_invoic-m_mblnr.
  637.         lv_prim_doc_year = ls_invoic-m_mjahr.
  638.       ENDIF.
  639.  
  640.       IF ls_invoic-m_zeile IS INITIAL.
  641.         lv_prim_doc_pos = ls_invoic-f_pos.
  642.       ELSE.
  643.         lv_prim_doc_pos = ls_invoic-m_zeile.
  644.       ENDIF.
  645.  
  646.       APPEND VALUE j_3rm_rn_doc_s(
  647.                       internal_id = '00001'
  648.                       prim_doc_type   = lv_prim_doc_type
  649.                       prim_doc_num    = lv_prim_doc_num
  650.                       prim_doc_year   = lv_prim_doc_year
  651.                       prim_doc_pos    = lv_prim_doc_pos
  652.                       mm_invoice_num  = ls_invoic-r_belnr
  653.                       mm_invoice_year = ls_invoic-r_gjahr
  654.                       mm_invoice_pos  = ls_invoic-r_buzei
  655.                       fi_invoice_num  = ls_invoic-f_belnr
  656.                       fi_invoice_year = ls_invoic-f_gjahr
  657.                       quantity        = ls_invoic-r_menge
  658. *                    tnved           = " ?
  659. *                    okpd2           = " ?
  660. *                    cancelled_by    = " ?
  661. *                    created_by      = sy-uname
  662. *                    created_on      = sy-datum
  663.                       amount          = ls_invoic-wrbtr
  664.                       currency        = ls_invoic-r_waers
  665.                       operation_date  = ls_invoic-r_budat
  666.                       tnved           = ls_invoic-tnved
  667.                                     ) TO lt_rn_doc.
  668.     ENDLOOP.
  669.  
  670.  
  671.     CALL FUNCTION 'J_3RM_RN_REG_CREATE'
  672.       EXPORTING
  673.         it_rn_reg       = lt_rn_reg
  674.         it_rn_doc       = lt_rn_doc
  675.         iv_savemode     = ''
  676.         iv_external_doc = 'X'
  677.       IMPORTING
  678.         et_messages     = lt_ret
  679.         et_created_rn   = lt_rn_reg_cre.
  680.  
  681.     LOOP AT lt_rn_reg_cre INTO DATA(ls_rn_reg_cre).
  682.       cl_j3rm_rn_processor=>get_rn_by_key(
  683.         EXPORTING
  684.           iv_reg_id   = ls_rn_reg_cre-rn_id
  685.           iv_reg_year = ls_rn_reg_cre-rn_year
  686.         IMPORTING
  687.           es_rn_reg   = ls_rn_reg ).
  688.       APPEND ls_rn_reg TO et_rn_reg.
  689.  
  690.       IF line_exists( lt_ret[ type = 'E' ] ).
  691.         ls_rn_reg_cre-rn_id = 'ERROR'.
  692.         CLEAR ls_rn_reg_cre-rn_year.
  693.       ENDIF.
  694.  
  695.       APPEND VALUE #( rn_reg_id   = ls_rn_reg_cre-rn_id
  696.                       rn_reg_year = ls_rn_reg_cre-rn_year
  697.                       type_doc    = is_invoic-rnpt_type_doc
  698.                       doc_id      = is_invoic-rnpt_doc_id
  699.                       pos_id      = is_invoic-rnpt_pos_id
  700.                       sub_pos     = is_invoic-rnpt_sub_pos
  701.                       rnpt        = is_invoic-rnpt
  702.                       land        = is_invoic-land
  703.                       meins       = is_invoic-r_meins
  704.                       menge       = is_invoic-r_menge
  705.                       amount      = is_invoic-wrbtr
  706.                       type_input  = is_invoic-rnpt_type_input ) TO lt_rnpt_upd.
  707.  
  708.     ENDLOOP.
  709.  
  710.     CALL FUNCTION 'Z_UPDATE_ZRNPT_INPUT_DOC' IN UPDATE TASK
  711.       EXPORTING
  712.         it_rnpt     = lt_rnpt_upd
  713.         iv_doc_id   = is_invoic-rnpt_doc_id
  714.         iv_type_doc = is_invoic-rnpt_type_doc
  715.         iv_generate = abap_true.
  716.  
  717.     et_ret = CORRESPONDING #( lt_ret ).
  718.  
  719.   ENDMETHOD.
  720.  
  721.  
  722. * <SIGNATURE>---------------------------------------------------------------------------------------+
  723. * | Static Private Method ZCL_RNPT_PROCESSOR=>RN_REG_UPDATE
  724. * +-------------------------------------------------------------------------------------------------+
  725. * | [--->] IT_RN_REG                      TYPE        MTT_J3
  726. * | [--->] IS_INVOIC                      TYPE        MTY_INVOIC(optional)
  727. * | [--->] IT_INVOIC                      TYPE        MTT_INVOIC
  728. * | [<---] ET_RET                         TYPE        BAPIRET2_T
  729. * +--------------------------------------------------------------------------------------</SIGNATURE>
  730.   METHOD rn_reg_update.
  731.     DATA: lt_rn_reg_chg    TYPE j_3rm_rn_reg_tt,
  732.           lt_rn_doc_new    TYPE j_3rm_rn_doc_tt,
  733.           lv_prim_doc_type TYPE j_3rm_primdoctype,
  734.           lv_prim_doc_num  TYPE j_3rm_rn_primdocnr,
  735.           lv_prim_doc_year TYPE j_3rm_rn_primdocyr,
  736.           lv_prim_doc_pos  TYPE j_3rm_rn_primdocpos,
  737.           lt_ret           TYPE j_3rm_rn_messages_ret,
  738.           lt_rnpt_upd      TYPE TABLE OF zrnpt_input_doc,
  739.           lv_quantity      TYPE j_3rm_rn_avquant.
  740.  
  741.     LOOP AT it_invoic INTO DATA(ls_sum).
  742.       lv_quantity = lv_quantity + ls_sum-r_menge.
  743.     ENDLOOP.
  744.  
  745.  
  746.     LOOP AT it_rn_reg INTO DATA(ls_rn_reg).
  747.       APPEND INITIAL LINE TO lt_rn_reg_chg ASSIGNING FIELD-SYMBOL(<fs_reg>).
  748.       <fs_reg>-rn_reg_id = ls_rn_reg-rn_reg_id.
  749.       <fs_reg>-rn_reg_year = ls_rn_reg-rn_reg_year.
  750.       <fs_reg>-rn_reg_date = ls_rn_reg-rn_reg_date.
  751.       <fs_reg>-rn_ext_num  = ls_rn_reg-rn_ext_num.
  752.       <fs_reg>-src_oper_type = ls_rn_reg-src_oper_type.
  753. *      <fs_reg>-manually_created = ''.
  754.       <fs_reg>-matnr = is_invoic-r_matnr.
  755.       <fs_reg>-asset_num = is_invoic-r_anln1.
  756.       <fs_reg>-asset_subnum = is_invoic-r_anln2.
  757.       <fs_reg>-company_code = is_invoic-r_bukrs.
  758.       <fs_reg>-country_of_origin = is_invoic-land.
  759.       <fs_reg>-batch = is_invoic-m_batch.
  760. *      <fs_reg>-serial_number = is_invoic- " ?
  761.       <fs_reg>-wbs_element = is_invoic-r_wbs_element.
  762.       <fs_reg>-invest_order = is_invoic-r_aufnr.
  763.       <fs_reg>-meins = is_invoic-r_meins.
  764.       <fs_reg>-avail_quantity = 0. "is_invoic-r_menge.
  765.       <fs_reg>-created_by = ls_rn_reg-created_by.
  766.       <fs_reg>-created_on = ls_rn_reg-created_on.
  767.       <fs_reg>-changed_by = ls_rn_reg-changed_by.
  768.       <fs_reg>-changed_on = ls_rn_reg-changed_on.
  769.     ENDLOOP.
  770.  
  771.     LOOP AT it_invoic INTO DATA(ls_invoic).
  772.  
  773.       IF ls_invoic-r_anln1 IS NOT INITIAL OR ls_invoic-r_wbs_element IS NOT INITIAL..
  774.         lv_prim_doc_type = '06'.
  775.       ELSE.
  776.         lv_prim_doc_type = '01'.
  777.       ENDIF.
  778.  
  779.       IF ls_invoic-m_mblnr IS INITIAL.
  780.         lv_prim_doc_num  = ls_invoic-f_belnr.
  781.         lv_prim_doc_year = ls_invoic-f_gjahr.
  782.       ELSE.
  783.         lv_prim_doc_num  = ls_invoic-m_mblnr.
  784.         lv_prim_doc_year = ls_invoic-m_mjahr.
  785.       ENDIF.
  786.  
  787.       IF ls_invoic-m_zeile IS INITIAL.
  788.         lv_prim_doc_pos = ls_invoic-f_pos.
  789.       ELSE.
  790.         lv_prim_doc_pos = ls_invoic-m_zeile.
  791.       ENDIF.
  792.  
  793.       APPEND INITIAL LINE TO lt_rn_doc_new ASSIGNING FIELD-SYMBOL(<fs_doc>).
  794.       <fs_doc>-rn_reg_id = ls_rn_reg-rn_reg_id.
  795.       <fs_doc>-rn_reg_year = ls_rn_reg-rn_reg_year.
  796. *      <fs_doc>-rn_reg_movmnt  = " ?
  797.       <fs_doc>-prim_doc_type   = lv_prim_doc_type.
  798.       <fs_doc>-prim_doc_num    = lv_prim_doc_num.
  799.       <fs_doc>-prim_doc_year   = lv_prim_doc_year.
  800.       <fs_doc>-prim_doc_pos    = lv_prim_doc_pos.
  801.       <fs_doc>-mm_invoice_num  = ls_invoic-r_belnr.
  802.       <fs_doc>-mm_invoice_year = ls_invoic-r_gjahr.
  803.       <fs_doc>-mm_invoice_pos  = ls_invoic-r_buzei.
  804.       <fs_doc>-fi_invoice_num  = ls_invoic-f_belnr.
  805.       <fs_doc>-fi_invoice_year = ls_invoic-f_gjahr.
  806.       <fs_doc>-menge           = ls_invoic-r_menge.
  807.       <fs_doc>-tnved           = ls_invoic-tnved.
  808. *      <fs_doc>-okpd2          = " ?
  809. *      <fs_doc>-cancelled_by   = " ?
  810.       <fs_doc>-created_by      = sy-uname.
  811.       <fs_doc>-created_on      = sy-datum.
  812.       <fs_doc>-amount          = ls_invoic-wrbtr.
  813.       <fs_doc>-currency        = ls_invoic-r_waers.
  814.       <fs_doc>-operation_date  = ls_invoic-r_budat.
  815.     ENDLOOP.
  816.  
  817.     CALL FUNCTION 'J_3RM_RN_REG_UPDATE'
  818.       EXPORTING
  819.         it_rn_reg_chg     = lt_rn_reg_chg
  820. *       IT_RN_DOC_CHG     =
  821.         iv_save_mode      = ''
  822.         iv_disable_checks = 'X'
  823.       IMPORTING
  824.         et_messages       = lt_ret
  825.       CHANGING
  826.         ct_rn_doc_new     = lt_rn_doc_new.
  827.  
  828.     LOOP AT lt_rn_doc_new INTO DATA(ls).
  829.  
  830.       IF line_exists( lt_ret[ type = 'E' ] ).
  831.         ls-rn_reg_id = 'ERROR'.
  832.         CLEAR ls-rn_reg_year.
  833.       ENDIF.
  834.  
  835.       APPEND VALUE #( rn_reg_id   = ls-rn_reg_id
  836.                       rn_reg_year = ls-rn_reg_year
  837.                       type_doc    = is_invoic-rnpt_type_doc
  838.                       doc_id      = is_invoic-rnpt_doc_id
  839.                       pos_id      = is_invoic-rnpt_pos_id
  840.                       sub_pos     = is_invoic-rnpt_sub_pos
  841.                       rnpt        = is_invoic-rnpt
  842.                       land        = is_invoic-land
  843.                       meins       = is_invoic-r_meins
  844.                       menge       = is_invoic-r_menge
  845.                       amount      = is_invoic-wrbtr
  846.                       type_input  = is_invoic-rnpt_type_input  ) TO lt_rnpt_upd.
  847.     ENDLOOP.
  848.  
  849.     CALL FUNCTION 'Z_UPDATE_ZRNPT_INPUT_DOC' IN UPDATE TASK
  850.       EXPORTING
  851.         it_rnpt     = lt_rnpt_upd
  852.         iv_doc_id   = is_invoic-rnpt_doc_id
  853.         iv_type_doc = is_invoic-rnpt_type_doc
  854.         iv_generate = abap_true.
  855.  
  856.     et_ret = CORRESPONDING #( lt_ret ).
  857.  
  858.   ENDMETHOD.
  859.  
  860.  
  861. * <SIGNATURE>---------------------------------------------------------------------------------------+
  862. * | Static Private Method ZCL_RNPT_PROCESSOR=>_ADD_MESSAGE
  863. * +-------------------------------------------------------------------------------------------------+
  864. * | [--->] IV_NUM                         TYPE        SY-MSGNO
  865. * | [<-->] CT_RET                         TYPE        BAPIRET2_T
  866. * +--------------------------------------------------------------------------------------</SIGNATURE>
  867.   METHOD _add_message.
  868.  
  869.     DATA ls_bapiret2 TYPE bapiret2.
  870.  
  871.     ls_bapiret2-type = 'E'.
  872.     ls_bapiret2-id   = 'ZL_RN000001'.
  873.     ls_bapiret2-number = iv_num.
  874.  
  875.     MESSAGE ID  ls_bapiret2-id
  876.            TYPE ls_bapiret2-type
  877.          NUMBER ls_bapiret2-number
  878.            WITH ls_bapiret2-message_v1
  879.                 ls_bapiret2-message_v2
  880.                 ls_bapiret2-message_v3
  881.                 ls_bapiret2-message_v4
  882.            INTO ls_bapiret2-message.
  883.  
  884.     APPEND ls_bapiret2 TO ct_ret.
  885.  
  886.   ENDMETHOD.
  887.  
  888.  
  889. * <SIGNATURE>---------------------------------------------------------------------------------------+
  890. * | Static Private Method ZCL_RNPT_PROCESSOR=>_BUILD_DYNAMIC_WHERE
  891. * +-------------------------------------------------------------------------------------------------+
  892. * | [--->] IV_COMPANY_CODE                TYPE        BUKRS(optional)
  893. * | [--->] IV_RN_EXT_NUMBER               TYPE        J_3RM_RN_EXT_NUM(optional)
  894. * | [--->] IV_RN_REG_DATE                 TYPE        J_3RM_RN_DATE(optional)
  895. * | [--->] IV_BATCH                       TYPE        CHARG_D(optional)
  896. * | [--->] IV_MATERIAL                    TYPE        MATNR(optional)
  897. * | [--->] IV_SERIAL_NUMBER               TYPE        GERNR(optional)
  898. * | [--->] IV_ASSET_NUM                   TYPE        ANLN1(optional)
  899. * | [--->] IV_ASSET_SUBNUM                TYPE        ANLN2(optional)
  900. * | [--->] IV_WBS_ELEMENT                 TYPE        PS_PSP_PNR(optional)
  901. * | [--->] IV_INVEST_ORDER                TYPE        AUFNR(optional)
  902. * | [<-()] RT_WHERE_CLAUSE                TYPE        MTT_CLAUSE
  903. * +--------------------------------------------------------------------------------------</SIGNATURE>
  904.   METHOD _build_dynamic_where.
  905.     DATA: lt_condtab TYPE TABLE OF hrcond.
  906.  
  907.     IF iv_company_code IS NOT INITIAL.
  908.       APPEND VALUE #( field = 'COMPANY_CODE' opera = 'EQ' low = iv_company_code ) TO lt_condtab.
  909.     ENDIF.
  910.  
  911.     IF iv_rn_ext_number IS NOT INITIAL.
  912.       APPEND VALUE #( field = 'RN_EXT_NUM' opera = 'EQ' low = iv_rn_ext_number ) TO lt_condtab.
  913.     ENDIF.
  914.  
  915.     IF iv_rn_reg_date IS NOT INITIAL.
  916.       APPEND VALUE #( field = 'RN_REG_DATE' opera = 'EQ' low = iv_rn_reg_date ) TO lt_condtab.
  917.     ENDIF.
  918.  
  919.     IF iv_batch IS NOT INITIAL.
  920.       APPEND VALUE #( field = 'BATCH' opera = 'EQ' low = iv_batch ) TO lt_condtab.
  921.     ENDIF.
  922.  
  923.     IF iv_material IS NOT INITIAL.
  924.       APPEND VALUE #( field = 'MATNR' opera = 'EQ' low = iv_material ) TO lt_condtab.
  925.     ENDIF.
  926.  
  927.     IF iv_serial_number IS NOT INITIAL.
  928.       APPEND VALUE #( field = 'SERIAL_NUMBER' opera = 'EQ' low = iv_serial_number ) TO lt_condtab.
  929.     ENDIF.
  930.  
  931.     IF iv_asset_num IS NOT INITIAL.
  932.       APPEND VALUE #( field = 'ASSET_NUM' opera = 'EQ' low = iv_asset_num ) TO lt_condtab.
  933.     ENDIF.
  934.  
  935.     IF iv_asset_subnum IS NOT INITIAL.
  936.       APPEND VALUE #( field = 'ASSET_SUBNUM' opera = 'EQ' low = iv_asset_subnum ) TO lt_condtab.
  937.     ENDIF.
  938.  
  939.     IF iv_wbs_element IS NOT INITIAL.
  940.       APPEND VALUE #( field = 'WBS_ELEMENT' opera = 'EQ' low = iv_wbs_element ) TO lt_condtab.
  941.     ENDIF.
  942.  
  943.     IF iv_invest_order IS NOT INITIAL.
  944.       APPEND VALUE #( field = 'INVEST_ORDER' opera = 'EQ' low = iv_invest_order ) TO lt_condtab.
  945.     ENDIF.
  946.  
  947.     CHECK lt_condtab IS NOT INITIAL.
  948.  
  949.     CALL FUNCTION 'RH_DYNAMIC_WHERE_BUILD'
  950.       EXPORTING
  951.         dbtable         = space
  952.       TABLES
  953.         condtab         = lt_condtab
  954.         where_clause    = rt_where_clause
  955.       EXCEPTIONS
  956.         empty_condtab   = 01
  957.         no_db_field     = 02
  958.         unknown_db      = 03
  959.         wrong_condition = 04.
  960.  
  961.   ENDMETHOD.
  962.  
  963.  
  964. * <SIGNATURE>---------------------------------------------------------------------------------------+
  965. * | Static Private Method ZCL_RNPT_PROCESSOR=>_FILTER_DOC
  966. * +-------------------------------------------------------------------------------------------------+
  967. * | [--->] IV_POS_ID                      TYPE        CHAR2
  968. * | [--->] IT_ZRNPT                       TYPE        MTT_ZRNPT
  969. * | [<-()] RT_FAE                         TYPE        MTT_FAE
  970. * +--------------------------------------------------------------------------------------</SIGNATURE>
  971.   METHOD _filter_doc.
  972.     rt_fae = VALUE #( FOR ls_rnpt IN it_zrnpt WHERE ( pos_id(2) = iv_pos_id )
  973.                       ( belnr = ls_rnpt-doc_id(10)
  974.                         gjahr = ls_rnpt-doc_id+10(4)
  975.                         buzei = ls_rnpt-pos_id+2
  976.                         cobl_nr = ls_rnpt-pos_id+2 ) ).
  977.  
  978.     SORT rt_fae BY belnr gjahr buzei.
  979.     DELETE ADJACENT DUPLICATES FROM rt_fae COMPARING belnr gjahr buzei.
  980.   ENDMETHOD.
  981. ENDCLASS.
Add Comment
Please, Sign In to add comment