Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CLASS zcl_rnpt_processor DEFINITION
- PUBLIC
- CREATE PUBLIC .
- PUBLIC SECTION.
- TYPES:
- mtt_zrnpt TYPE TABLE OF zrnpt_input_doc .
- TYPES mtt_rseg TYPE mrm_tab_mrmrseg .
- TYPES mtt_rbco TYPE mrm_tab_mrmrbco .
- CLASS-METHODS process_rnpt_by_miro
- IMPORTING
- !iv_invoicedocnumber TYPE re_belnr
- !iv_fiscalyear TYPE gjahr
- !iv_save_mode TYPE flag
- !iv_repeat_mode TYPE flag OPTIONAL
- !iv_update_batch TYPE flag OPTIONAL
- !iv_log_mode TYPE flag DEFAULT abap_true
- EXPORTING
- !et_ret TYPE bapiret2_t
- !et_rn_reg TYPE j_3rm_rn_reg_t .
- CLASS-METHODS process_rn_by_storno_miro
- IMPORTING
- !iv_invoicedocnumber TYPE re_belnr
- !iv_fiscalyear TYPE gjahr
- !iv_save_mode TYPE flag OPTIONAL
- !iv_log_mode TYPE flag DEFAULT abap_true
- !iv_repeat_mode TYPE flag OPTIONAL
- EXPORTING
- !et_ret TYPE bapiret2_t .
- PROTECTED SECTION.
- PRIVATE SECTION.
- TYPES:
- BEGIN OF mty_fae,
- belnr TYPE belnr_d,
- gjahr TYPE gjahr,
- buzei TYPE rblgp,
- cobl_nr TYPE cobl_nr,
- END OF mty_fae .
- TYPES:
- BEGIN OF mty_clause,
- line(72) TYPE c,
- END OF mty_clause .
- TYPES:
- BEGIN OF mty_fae_mseg,
- mblnr TYPE mblnr,
- mjahr TYPE mjahr,
- zeile TYPE mblpo,
- END OF mty_fae_mseg .
- TYPES:
- BEGIN OF mty_invoic,
- r_budat TYPE budat,
- r_belnr TYPE re_belnr,
- r_buzei TYPE rblgp,
- r_gjahr TYPE gjahr,
- r_bukrs TYPE bukrs,
- r_lfbnr TYPE lfbnr,
- r_ebeln TYPE ebeln,
- r_ebelp TYPE ebelp,
- r_lfgja TYPE lfgja,
- r_lfpos TYPE lfpos,
- r_waers TYPE waers,
- r_wbs_element TYPE ps_psp_pnr,
- r_aufnr TYPE aufnr,
- r_anln1 TYPE anln1,
- r_anln2 TYPE anln2,
- r_matnr TYPE matnr,
- r_erfnam TYPE erfnam,
- rnpt TYPE j_3rm_rn_ext_num,
- land TYPE herkl,
- wrbtr TYPE rseg-wrbtr,
- m_mjahr TYPE mjahr,
- m_mblnr TYPE mblnr,
- m_zeile TYPE mblpo,
- m_batch TYPE charg_d,
- r_menge TYPE menge_d,
- r_meins TYPE bstme,
- * r_erfnam TYPE erfnam,
- f_belnr TYPE belnr_d,
- f_pos TYPE buzei,
- f_gjahr TYPE gjahr,
- tnved TYPE zmara_tnved-ztnved_kod,
- rnpt_type_doc TYPE zrnpt_input_doc-type_doc,
- rnpt_doc_id TYPE zrnpt_input_doc-doc_id,
- rnpt_pos_id TYPE zrnpt_input_doc-pos_id,
- rnpt_sub_pos TYPE zrnpt_input_doc-sub_pos,
- rnpt_type_input TYPE zrnpt_input_doc-type_input,
- END OF mty_invoic .
- TYPES:
- mtt_fae TYPE STANDARD TABLE OF mty_fae WITH DEFAULT KEY .
- TYPES:
- mtt_j3 TYPE TABLE OF j_3rm_rn_reg WITH DEFAULT KEY .
- TYPES:
- mtt_clause TYPE STANDARD TABLE OF mty_clause WITH DEFAULT KEY .
- TYPES:
- mtt_invoic TYPE STANDARD TABLE OF mty_invoic WITH DEFAULT KEY .
- CLASS-METHODS _filter_doc
- IMPORTING
- !iv_pos_id TYPE char2
- VALUE(it_zrnpt) TYPE mtt_zrnpt
- RETURNING
- VALUE(rt_fae) TYPE mtt_fae .
- CLASS-METHODS get_rn_reg_by_full_key
- IMPORTING
- !iv_company_code TYPE bukrs OPTIONAL
- !iv_rn_ext_number TYPE j_3rm_rn_ext_num OPTIONAL
- !iv_rn_reg_date TYPE j_3rm_rn_date OPTIONAL
- !iv_batch TYPE charg_d OPTIONAL
- !iv_material TYPE matnr OPTIONAL
- !iv_serial_number TYPE gernr OPTIONAL
- !iv_asset_num TYPE anln1 OPTIONAL
- !iv_asset_subnum TYPE anln2 OPTIONAL
- !iv_wbs_element TYPE ps_psp_pnr OPTIONAL
- !iv_invest_order TYPE aufnr OPTIONAL
- RETURNING
- VALUE(rt_rn_reg) TYPE mtt_j3 .
- CLASS-METHODS _build_dynamic_where
- IMPORTING
- !iv_company_code TYPE bukrs OPTIONAL
- !iv_rn_ext_number TYPE j_3rm_rn_ext_num OPTIONAL
- !iv_rn_reg_date TYPE j_3rm_rn_date OPTIONAL
- !iv_batch TYPE charg_d OPTIONAL
- !iv_material TYPE matnr OPTIONAL
- !iv_serial_number TYPE gernr OPTIONAL
- !iv_asset_num TYPE anln1 OPTIONAL
- !iv_asset_subnum TYPE anln2 OPTIONAL
- !iv_wbs_element TYPE ps_psp_pnr OPTIONAL
- !iv_invest_order TYPE aufnr OPTIONAL
- RETURNING
- VALUE(rt_where_clause) TYPE mtt_clause .
- CLASS-METHODS rn_reg_create
- IMPORTING
- !is_invoic TYPE mty_invoic OPTIONAL
- !it_invoic TYPE mtt_invoic
- EXPORTING
- !et_ret TYPE bapiret2_t
- !et_rn_reg TYPE mtt_j3 .
- CLASS-METHODS rn_reg_update
- IMPORTING
- !it_rn_reg TYPE mtt_j3
- !is_invoic TYPE mty_invoic OPTIONAL
- !it_invoic TYPE mtt_invoic
- EXPORTING
- !et_ret TYPE bapiret2_t .
- CLASS-METHODS _add_message
- IMPORTING
- !iv_num TYPE sy-msgno
- CHANGING
- !ct_ret TYPE bapiret2_t .
- ENDCLASS.
- CLASS zcl_rnpt_processor IMPLEMENTATION.
- * <SIGNATURE>---------------------------------------------------------------------------------------+
- * | Static Private Method ZCL_RNPT_PROCESSOR=>GET_RN_REG_BY_FULL_KEY
- * +-------------------------------------------------------------------------------------------------+
- * | [--->] IV_COMPANY_CODE TYPE BUKRS(optional)
- * | [--->] IV_RN_EXT_NUMBER TYPE J_3RM_RN_EXT_NUM(optional)
- * | [--->] IV_RN_REG_DATE TYPE J_3RM_RN_DATE(optional)
- * | [--->] IV_BATCH TYPE CHARG_D(optional)
- * | [--->] IV_MATERIAL TYPE MATNR(optional)
- * | [--->] IV_SERIAL_NUMBER TYPE GERNR(optional)
- * | [--->] IV_ASSET_NUM TYPE ANLN1(optional)
- * | [--->] IV_ASSET_SUBNUM TYPE ANLN2(optional)
- * | [--->] IV_WBS_ELEMENT TYPE PS_PSP_PNR(optional)
- * | [--->] IV_INVEST_ORDER TYPE AUFNR(optional)
- * | [<-()] RT_RN_REG TYPE MTT_J3
- * +--------------------------------------------------------------------------------------</SIGNATURE>
- METHOD get_rn_reg_by_full_key.
- DATA: lt_where_clause TYPE mtt_clause.
- IF iv_material IS INITIAL " если все пустые, то выходим
- AND iv_batch IS INITIAL
- AND iv_serial_number IS INITIAL
- AND iv_asset_num IS INITIAL
- AND iv_asset_subnum IS INITIAL
- AND iv_wbs_element IS INITIAL
- AND iv_invest_order IS INITIAL.
- RETURN.
- ENDIF.
- lt_where_clause = _build_dynamic_where( iv_company_code = iv_company_code
- iv_rn_ext_number = iv_rn_ext_number
- iv_rn_reg_date = iv_rn_reg_date
- iv_batch = iv_batch
- iv_material = iv_material
- iv_serial_number = iv_serial_number
- iv_asset_num = iv_asset_num
- iv_asset_subnum = iv_asset_subnum
- iv_wbs_element = iv_wbs_element
- iv_invest_order = iv_invest_order ).
- SELECT * FROM j_3rm_rn_reg
- INTO CORRESPONDING FIELDS OF TABLE @rt_rn_reg
- WHERE (lt_where_clause).
- ENDMETHOD.
- * <SIGNATURE>---------------------------------------------------------------------------------------+
- * | Static Public Method ZCL_RNPT_PROCESSOR=>PROCESS_RNPT_BY_MIRO
- * +-------------------------------------------------------------------------------------------------+
- * | [--->] IV_INVOICEDOCNUMBER TYPE RE_BELNR
- * | [--->] IV_FISCALYEAR TYPE GJAHR
- * | [--->] IV_SAVE_MODE TYPE FLAG
- * | [--->] IV_REPEAT_MODE TYPE FLAG(optional)
- * | [--->] IV_UPDATE_BATCH TYPE FLAG(optional)
- * | [--->] IV_LOG_MODE TYPE FLAG (default =ABAP_TRUE)
- * | [<---] ET_RET TYPE BAPIRET2_T
- * | [<---] ET_RN_REG TYPE J_3RM_RN_REG_T
- * +--------------------------------------------------------------------------------------</SIGNATURE>
- METHOD process_rnpt_by_miro.
- DATA: lv_doc_id TYPE zrnpt_doc_id,
- lt_fae TYPE TABLE OF mty_fae,
- lt_fae_mseg TYPE TABLE OF mty_fae_mseg,
- lt_invoic TYPE TABLE OF mty_invoic,
- lt_grp TYPE TABLE OF mty_invoic,
- lv_pos_id TYPE zrnpt_pos_id,
- lt_rn_reg TYPE mtt_j3,
- * lt_rn_reg TYPE TABLE OF J_3RM_RN_CREATED_RET,
- lt_ret TYPE bapiret2_t,
- lv_mass TYPE abap_bool,
- lo_log TYPE REF TO zcl_bal_log.
- IF lo_log IS INITIAL AND iv_log_mode = abap_true.
- lo_log = NEW #( im_extnumber = |{ iv_invoicedocnumber }{ iv_fiscalyear }| im_object = 'ZRNPT' im_subobject = 'IN_INVOICE' ).
- lo_log->add_free_text( |{ 'IV_INVOICEDOCNUMBER: ' } { iv_invoicedocnumber }| ).
- lo_log->add_free_text( |{ 'IV_FISCALYEAR: ' } { iv_fiscalyear }| ).
- lo_log->add_free_text( |{ 'IV_SAVE_MODE: ' } { iv_save_mode }| ).
- * lo_log->add_free_text( |{ 'IV_TEST_MODE: ' } { iv_test_mode }| ).
- lo_log->add_free_text( |{ 'IV_REPEAT_MODE: ' } { iv_repeat_mode }| ).
- lo_log->add_free_text( |{ 'IV_UPDATE_BATCH: ' } { iv_update_batch }| ).
- lo_log->add_free_text( |{ 'IV_LOG_MODE: ' } { iv_log_mode }| ).
- ENDIF.
- IF iv_invoicedocnumber IS INITIAL.
- _add_message( EXPORTING iv_num = 065 CHANGING ct_ret = et_ret ).
- RETURN.
- ENDIF.
- IF iv_fiscalyear IS INITIAL.
- _add_message( EXPORTING iv_num = 066 CHANGING ct_ret = et_ret ).
- RETURN.
- ENDIF.
- lv_doc_id = |{ iv_invoicedocnumber }{ iv_fiscalyear }|.
- SELECT * FROM zrnpt_input_doc
- WHERE doc_id = @lv_doc_id
- AND type_doc = 'BUS2081'
- AND rnpt <> ''
- INTO TABLE @DATA(lt_zrnpt).
- IF iv_repeat_mode <> 'X'.
- DELETE lt_zrnpt WHERE rn_reg_year IS NOT INITIAL.
- ENDIF.
- IF lt_zrnpt IS INITIAL.
- _add_message( EXPORTING iv_num = 067 CHANGING ct_ret = et_ret ).
- RETURN.
- ENDIF.
- SELECT SINGLE * FROM rbkp
- WHERE belnr = @iv_invoicedocnumber
- AND gjahr = @iv_fiscalyear
- INTO @DATA(ls_rbkp).
- IF ls_rbkp-rbstat <> '5'.
- _add_message( EXPORTING iv_num = 068 CHANGING ct_ret = et_ret ).
- RETURN.
- ENDIF.
- IF ls_rbkp-ivtyp = '5'.
- _add_message( EXPORTING iv_num = 069 CHANGING ct_ret = et_ret ).
- RETURN.
- ENDIF.
- IF ls_rbkp-stblg IS NOT INITIAL.
- _add_message( EXPORTING iv_num = 070 CHANGING ct_ret = et_ret ).
- RETURN.
- ENDIF.
- SELECT * FROM bkpf
- WHERE awtyp = 'RMRP'
- AND awkey = @lv_doc_id
- INTO TABLE @DATA(lt_bkpf).
- IF sy-subrc = 0.
- SELECT * FROM bseg
- INTO TABLE @DATA(lt_bseg)
- FOR ALL ENTRIES IN @lt_bkpf
- WHERE bukrs = @lt_bkpf-bukrs
- AND belnr = @lt_bkpf-belnr
- AND gjahr = @lt_bkpf-gjahr.
- ENDIF.
- lt_fae = _filter_doc( it_zrnpt = lt_zrnpt iv_pos_id = 'ЗП' ).
- IF lt_fae IS NOT INITIAL.
- SELECT * FROM rseg
- FOR ALL ENTRIES IN @lt_fae
- WHERE belnr = @lt_fae-belnr
- AND gjahr = @lt_fae-gjahr
- AND buzei = @lt_fae-buzei
- INTO TABLE @DATA(lt_rseg).
- ENDIF.
- IF lt_rseg IS NOT INITIAL.
- SELECT * FROM rbco
- FOR ALL ENTRIES IN @lt_rseg
- WHERE belnr = @lt_rseg-belnr
- AND gjahr = @lt_rseg-gjahr
- AND buzei = @lt_rseg-buzei
- INTO TABLE @DATA(lt_rbco_rseg).
- ENDIF.
- lt_fae = _filter_doc( it_zrnpt = lt_zrnpt iv_pos_id = 'ОС' ).
- IF lt_fae IS NOT INITIAL.
- SELECT * FROM rbco
- FOR ALL ENTRIES IN @lt_fae
- WHERE belnr = @lt_fae-belnr
- AND gjahr = @lt_fae-gjahr
- AND cobl_nr = @lt_fae-cobl_nr
- INTO TABLE @DATA(lt_rbco).
- ENDIF.
- IF lt_rseg IS NOT INITIAL.
- SELECT * FROM zmara_tnved
- INTO TABLE @DATA(lt_tnved)
- FOR ALL ENTRIES IN @lt_rseg
- WHERE matnr = @lt_rseg-matnr.
- ENDIF.
- LOOP AT lt_rseg INTO DATA(ls_rseg).
- APPEND INITIAL LINE TO lt_invoic ASSIGNING FIELD-SYMBOL(<fs_row>).
- <fs_row>-r_buzei = ls_rseg-buzei.
- <fs_row>-r_lfbnr = ls_rseg-lfbnr.
- <fs_row>-r_ebeln = ls_rseg-ebeln.
- <fs_row>-r_ebelp = ls_rseg-ebelp.
- <fs_row>-r_lfgja = ls_rseg-lfgja.
- <fs_row>-r_lfpos = ls_rseg-lfpos.
- <fs_row>-r_matnr = ls_rseg-matnr.
- <fs_row>-r_menge = ls_rseg-menge.
- <fs_row>-r_meins = ls_rseg-meins.
- <fs_row>-wrbtr = ls_rseg-wrbtr.
- IF <fs_row>-r_lfbnr IS NOT INITIAL.
- APPEND VALUE #( mblnr = <fs_row>-r_lfbnr mjahr = <fs_row>-r_lfgja zeile = <fs_row>-r_lfpos ) TO lt_fae_mseg.
- ENDIF.
- READ TABLE lt_tnved WITH KEY matnr = <fs_row>-r_matnr INTO DATA(ls_tnved).
- IF sy-subrc = 0.
- <fs_row>-tnved = ls_tnved-ztnved_kod.
- ENDIF.
- <fs_row>-r_budat = ls_rbkp-budat.
- <fs_row>-r_belnr = ls_rbkp-belnr.
- <fs_row>-r_gjahr = ls_rbkp-gjahr.
- <fs_row>-r_bukrs = ls_rbkp-bukrs.
- <fs_row>-r_waers = ls_rbkp-waers.
- <fs_row>-r_erfnam = ls_rbkp-erfnam.
- READ TABLE lt_bseg WITH KEY ebeln = <fs_row>-r_ebeln ebelp = <fs_row>-r_ebelp INTO DATA(ls_bseg).
- IF sy-subrc = 0.
- <fs_row>-f_belnr = ls_bseg-belnr.
- <fs_row>-f_pos = ls_bseg-buzei.
- <fs_row>-f_gjahr = ls_bseg-gjahr.
- ENDIF.
- READ TABLE lt_rbco_rseg WITH KEY belnr = <fs_row>-r_belnr
- gjahr = <fs_row>-r_gjahr
- buzei = <fs_row>-r_buzei INTO DATA(ls_rbco_rseg).
- IF sy-subrc = 0.
- <fs_row>-r_wbs_element = ls_rbco_rseg-ps_psp_pnr.
- <fs_row>-r_aufnr = ls_rbco_rseg-aufnr.
- <fs_row>-r_anln1 = ls_rbco_rseg-anln1.
- <fs_row>-r_anln2 = ls_rbco_rseg-anln2.
- lv_pos_id = |{ 'ОС' }{ ls_rbco_rseg-cobl_nr }|.
- * READ TABLE lt_zrnpt WITH KEY pos_id = lv_pos_id INTO DATA(ls_zrnpt).
- CLEAR lv_mass.
- LOOP AT lt_zrnpt INTO DATA(ls_zrnpt) WHERE pos_id = lv_pos_id.
- * IF sy-subrc = 0.
- IF lv_mass = abap_true. " если уже есть строка с текущим РНПТ, то дублируем строку
- APPEND INITIAL LINE TO lt_invoic ASSIGNING FIELD-SYMBOL(<fs_copy>).
- <fs_copy> = CORRESPONDING #( <fs_row> ).
- <fs_copy>-rnpt = ls_zrnpt-rnpt.
- <fs_copy>-land = ls_zrnpt-land.
- <fs_copy>-r_menge = ls_zrnpt-menge.
- <fs_copy>-r_meins = ls_zrnpt-meins.
- <fs_copy>-wrbtr = ls_zrnpt-amount.
- <fs_copy>-rnpt_type_doc = ls_zrnpt-type_doc.
- <fs_copy>-rnpt_doc_id = ls_zrnpt-doc_id.
- <fs_copy>-rnpt_pos_id = ls_zrnpt-pos_id.
- <fs_copy>-rnpt_sub_pos = ls_zrnpt-sub_pos.
- <fs_copy>-rnpt_type_input = ls_zrnpt-type_input.
- ELSE.
- <fs_row>-rnpt = ls_zrnpt-rnpt.
- <fs_row>-land = ls_zrnpt-land.
- <fs_row>-r_menge = ls_zrnpt-menge.
- <fs_row>-r_meins = ls_zrnpt-meins.
- <fs_row>-wrbtr = ls_zrnpt-amount.
- <fs_row>-rnpt_type_doc = ls_zrnpt-type_doc.
- <fs_row>-rnpt_doc_id = ls_zrnpt-doc_id.
- <fs_row>-rnpt_pos_id = ls_zrnpt-pos_id.
- <fs_row>-rnpt_sub_pos = ls_zrnpt-sub_pos.
- <fs_row>-rnpt_type_input = ls_zrnpt-type_input.
- ENDIF.
- * ENDIF.
- lv_mass = abap_true.
- ENDLOOP.
- ENDIF.
- IF <fs_row>-rnpt IS INITIAL.
- lv_pos_id = |{ 'ЗП' }{ ls_rseg-buzei }|.
- * READ TABLE lt_zrnpt WITH KEY pos_id = lv_pos_id INTO ls_zrnpt.
- CLEAR: lv_mass.
- LOOP AT lt_zrnpt INTO ls_zrnpt WHERE pos_id = lv_pos_id.
- * IF sy-subrc = 0.
- IF lv_mass = abap_true. " если уже есть строка с текущим РНПТ, то дублируем строку
- APPEND INITIAL LINE TO lt_invoic ASSIGNING <fs_copy>.
- <fs_copy> = CORRESPONDING #( <fs_row> ).
- <fs_copy>-rnpt = ls_zrnpt-rnpt.
- <fs_copy>-land = ls_zrnpt-land.
- <fs_copy>-r_menge = ls_zrnpt-menge.
- <fs_copy>-r_meins = ls_zrnpt-meins.
- <fs_copy>-wrbtr = ls_zrnpt-amount.
- <fs_copy>-rnpt_type_doc = ls_zrnpt-type_doc.
- <fs_copy>-rnpt_doc_id = ls_zrnpt-doc_id.
- <fs_copy>-rnpt_pos_id = ls_zrnpt-pos_id.
- <fs_copy>-rnpt_sub_pos = ls_zrnpt-sub_pos.
- <fs_copy>-rnpt_type_input = ls_zrnpt-type_input.
- ELSE.
- <fs_row>-rnpt = ls_zrnpt-rnpt.
- <fs_row>-land = ls_zrnpt-land.
- <fs_row>-r_menge = ls_zrnpt-menge.
- <fs_row>-r_meins = ls_zrnpt-meins.
- <fs_row>-wrbtr = ls_zrnpt-amount.
- <fs_row>-rnpt_type_doc = ls_zrnpt-type_doc.
- <fs_row>-rnpt_doc_id = ls_zrnpt-doc_id.
- <fs_row>-rnpt_pos_id = ls_zrnpt-pos_id.
- <fs_row>-rnpt_sub_pos = ls_zrnpt-sub_pos.
- <fs_row>-rnpt_type_input = ls_zrnpt-type_input.
- ENDIF.
- * ENDIF.
- lv_mass = abap_true.
- ENDLOOP.
- ENDIF.
- ENDLOOP.
- IF lt_fae_mseg IS NOT INITIAL.
- SELECT * FROM mseg
- INTO TABLE @DATA(lt_mseg)
- FOR ALL ENTRIES IN @lt_fae_mseg
- WHERE mblnr = @lt_fae_mseg-mblnr
- AND mjahr = @lt_fae_mseg-mjahr
- AND zeile = @lt_fae_mseg-zeile.
- LOOP AT lt_invoic ASSIGNING <fs_row> WHERE r_lfbnr IS NOT INITIAL.
- READ TABLE lt_mseg WITH KEY mblnr = <fs_row>-r_lfbnr
- mjahr = <fs_row>-r_lfgja
- zeile = <fs_row>-r_lfpos INTO DATA(ls_mseg).
- IF sy-subrc = 0.
- <fs_row>-m_mblnr = ls_mseg-mblnr.
- <fs_row>-m_batch = ls_mseg-charg.
- <fs_row>-m_mjahr = ls_mseg-mjahr.
- <fs_row>-m_zeile = ls_mseg-zeile.
- ENDIF.
- ENDLOOP.
- ENDIF.
- LOOP AT lt_invoic INTO DATA(ls_invoic)
- GROUP BY ( r_bukrs = ls_invoic-r_bukrs
- r_rnpt = ls_invoic-rnpt
- m_batch = ls_invoic-m_batch
- r_matnr = ls_invoic-r_matnr
- r_anln1 = ls_invoic-r_anln1
- r_anln2 = ls_invoic-r_anln2
- r_wbs_element = ls_invoic-r_wbs_element
- r_aufnr = ls_invoic-r_aufnr ).
- CLEAR: lt_ret, lt_rn_reg.
- lt_rn_reg = get_rn_reg_by_full_key( iv_company_code = ls_invoic-r_bukrs
- iv_rn_ext_number = ls_invoic-rnpt
- iv_batch = ls_invoic-m_batch
- iv_material = ls_invoic-r_matnr
- * iv_serial_number = ls_invoic-
- iv_asset_num = ls_invoic-r_anln1
- iv_asset_subnum = ls_invoic-r_anln2
- iv_wbs_element = ls_invoic-r_wbs_element
- iv_invest_order = ls_invoic-r_aufnr ).
- CLEAR lt_grp.
- LOOP AT GROUP ls_invoic INTO DATA(ls_grp).
- APPEND ls_grp TO lt_grp.
- ENDLOOP.
- IF lt_rn_reg IS INITIAL.
- rn_reg_create(
- EXPORTING
- is_invoic = ls_invoic
- it_invoic = lt_grp
- IMPORTING
- et_ret = lt_ret
- et_rn_reg = lt_rn_reg ).
- ELSE.
- rn_reg_update(
- EXPORTING
- it_rn_reg = lt_rn_reg
- is_invoic = ls_invoic
- it_invoic = lt_grp
- IMPORTING
- et_ret = lt_ret ).
- ENDIF.
- APPEND LINES OF lt_ret TO et_ret.
- CLEAR: lt_ret, lt_rn_reg.
- ENDLOOP.
- IF iv_log_mode = abap_true.
- LOOP AT et_ret INTO DATA(ls_ret).
- lo_log->add_message(
- EXPORTING
- im_msgid = ls_ret-id
- im_msgno = ls_ret-number
- im_msgty = ls_ret-type
- im_msgv1 = ls_ret-message_v1
- im_msgv2 = ls_ret-message_v2
- im_msgv3 = ls_ret-message_v3
- im_msgv4 = ls_ret-message_v4 ).
- ENDLOOP.
- lo_log->save( ).
- ENDIF.
- LOOP AT et_ret TRANSPORTING NO FIELDS WHERE type CA 'EAX'.
- EXIT.
- ENDLOOP.
- IF iv_save_mode = abap_true.
- CALL FUNCTION 'J_3RM_RN_REG_COMMIT_WORK'
- EXPORTING
- iv_wait = abap_true.
- ENDIF.
- * IF iv_save_mode = abap_true.
- * IF iv_test_mode = abap_true OR sy-subrc = 0.
- * CALL FUNCTION 'J_3RM_RN_REG_ROLLBACK_WORK'.
- * ELSE. "IF iv_save_mode = 'X' AND sy-subrc <> 0.
- * CALL FUNCTION 'J_3RM_RN_REG_COMMIT_WORK'
- * EXPORTING
- * iv_wait = abap_true.
- * ENDIF.
- * ENDIF.
- ENDMETHOD.
- * <SIGNATURE>---------------------------------------------------------------------------------------+
- * | Static Public Method ZCL_RNPT_PROCESSOR=>PROCESS_RN_BY_STORNO_MIRO
- * +-------------------------------------------------------------------------------------------------+
- * | [--->] IV_INVOICEDOCNUMBER TYPE RE_BELNR
- * | [--->] IV_FISCALYEAR TYPE GJAHR
- * | [--->] IV_SAVE_MODE TYPE FLAG(optional)
- * | [--->] IV_LOG_MODE TYPE FLAG (default =ABAP_TRUE)
- * | [--->] IV_REPEAT_MODE TYPE FLAG(optional)
- * | [<---] ET_RET TYPE BAPIRET2_T
- * +--------------------------------------------------------------------------------------</SIGNATURE>
- METHOD process_rn_by_storno_miro.
- ENDMETHOD.
- * <SIGNATURE>---------------------------------------------------------------------------------------+
- * | Static Private Method ZCL_RNPT_PROCESSOR=>RN_REG_CREATE
- * +-------------------------------------------------------------------------------------------------+
- * | [--->] IS_INVOIC TYPE MTY_INVOIC(optional)
- * | [--->] IT_INVOIC TYPE MTT_INVOIC
- * | [<---] ET_RET TYPE BAPIRET2_T
- * | [<---] ET_RN_REG TYPE MTT_J3
- * +--------------------------------------------------------------------------------------</SIGNATURE>
- METHOD rn_reg_create.
- DATA: lt_rn_reg TYPE j_3rm_rn_reg_t,
- lt_rn_doc TYPE j_3rm_rn_doc_t,
- lt_created_rn TYPE j_3rm_rn_created_ret,
- lv_prim_doc_type TYPE j_3rm_primdoctype,
- lv_prim_doc_num TYPE j_3rm_rn_primdocnr,
- lv_prim_doc_year TYPE j_3rm_rn_primdocyr,
- lv_prim_doc_pos TYPE j_3rm_rn_primdocpos,
- lt_rn_reg_cre TYPE j_3rm_rn_created_ret,
- lt_ret TYPE j_3rm_rn_messages_ret,
- ls_rn_reg TYPE j_3rm_rn_reg,
- lt_rnpt_upd TYPE TABLE OF zrnpt_input_doc,
- lv_quantity TYPE j_3rm_rn_avquant.
- LOOP AT it_invoic INTO DATA(ls).
- lv_quantity = lv_quantity + ls-r_menge.
- ENDLOOP.
- APPEND VALUE j_3rm_rn_reg_s(
- internal_id = '00001'
- rn_ext_num = is_invoic-rnpt
- rn_reg_date = is_invoic-r_budat
- src_oper_type = '01'
- material = is_invoic-r_matnr
- asset_num = is_invoic-r_anln1
- asset_subnum = is_invoic-r_anln2
- company_code = is_invoic-r_bukrs
- country_of_origin = is_invoic-land
- batch = is_invoic-m_batch
- unit_of_measure = is_invoic-r_meins
- * serial_number = " ???
- quantity = lv_quantity "is_invoic-r_menge
- wbs_element = is_invoic-r_wbs_element
- * invest_order = " ???
- ) TO lt_rn_reg.
- " Для группы заполняем параметр
- LOOP AT it_invoic INTO DATA(ls_invoic).
- IF ls_invoic-r_anln1 IS NOT INITIAL OR ls_invoic-r_wbs_element IS NOT INITIAL.
- lv_prim_doc_type = '06'.
- ELSE.
- lv_prim_doc_type = '01'.
- ENDIF.
- IF ls_invoic-m_mblnr IS INITIAL.
- lv_prim_doc_num = ls_invoic-f_belnr.
- lv_prim_doc_year = ls_invoic-f_gjahr.
- ELSE.
- lv_prim_doc_num = ls_invoic-m_mblnr.
- lv_prim_doc_year = ls_invoic-m_mjahr.
- ENDIF.
- IF ls_invoic-m_zeile IS INITIAL.
- lv_prim_doc_pos = ls_invoic-f_pos.
- ELSE.
- lv_prim_doc_pos = ls_invoic-m_zeile.
- ENDIF.
- APPEND VALUE j_3rm_rn_doc_s(
- internal_id = '00001'
- prim_doc_type = lv_prim_doc_type
- prim_doc_num = lv_prim_doc_num
- prim_doc_year = lv_prim_doc_year
- prim_doc_pos = lv_prim_doc_pos
- mm_invoice_num = ls_invoic-r_belnr
- mm_invoice_year = ls_invoic-r_gjahr
- mm_invoice_pos = ls_invoic-r_buzei
- fi_invoice_num = ls_invoic-f_belnr
- fi_invoice_year = ls_invoic-f_gjahr
- quantity = ls_invoic-r_menge
- * tnved = " ?
- * okpd2 = " ?
- * cancelled_by = " ?
- * created_by = sy-uname
- * created_on = sy-datum
- amount = ls_invoic-wrbtr
- currency = ls_invoic-r_waers
- operation_date = ls_invoic-r_budat
- tnved = ls_invoic-tnved
- ) TO lt_rn_doc.
- ENDLOOP.
- CALL FUNCTION 'J_3RM_RN_REG_CREATE'
- EXPORTING
- it_rn_reg = lt_rn_reg
- it_rn_doc = lt_rn_doc
- iv_savemode = ''
- iv_external_doc = 'X'
- IMPORTING
- et_messages = lt_ret
- et_created_rn = lt_rn_reg_cre.
- LOOP AT lt_rn_reg_cre INTO DATA(ls_rn_reg_cre).
- cl_j3rm_rn_processor=>get_rn_by_key(
- EXPORTING
- iv_reg_id = ls_rn_reg_cre-rn_id
- iv_reg_year = ls_rn_reg_cre-rn_year
- IMPORTING
- es_rn_reg = ls_rn_reg ).
- APPEND ls_rn_reg TO et_rn_reg.
- IF line_exists( lt_ret[ type = 'E' ] ).
- ls_rn_reg_cre-rn_id = 'ERROR'.
- CLEAR ls_rn_reg_cre-rn_year.
- ENDIF.
- APPEND VALUE #( rn_reg_id = ls_rn_reg_cre-rn_id
- rn_reg_year = ls_rn_reg_cre-rn_year
- type_doc = is_invoic-rnpt_type_doc
- doc_id = is_invoic-rnpt_doc_id
- pos_id = is_invoic-rnpt_pos_id
- sub_pos = is_invoic-rnpt_sub_pos
- rnpt = is_invoic-rnpt
- land = is_invoic-land
- meins = is_invoic-r_meins
- menge = is_invoic-r_menge
- amount = is_invoic-wrbtr
- type_input = is_invoic-rnpt_type_input ) TO lt_rnpt_upd.
- ENDLOOP.
- CALL FUNCTION 'Z_UPDATE_ZRNPT_INPUT_DOC' IN UPDATE TASK
- EXPORTING
- it_rnpt = lt_rnpt_upd
- iv_doc_id = is_invoic-rnpt_doc_id
- iv_type_doc = is_invoic-rnpt_type_doc
- iv_generate = abap_true.
- et_ret = CORRESPONDING #( lt_ret ).
- ENDMETHOD.
- * <SIGNATURE>---------------------------------------------------------------------------------------+
- * | Static Private Method ZCL_RNPT_PROCESSOR=>RN_REG_UPDATE
- * +-------------------------------------------------------------------------------------------------+
- * | [--->] IT_RN_REG TYPE MTT_J3
- * | [--->] IS_INVOIC TYPE MTY_INVOIC(optional)
- * | [--->] IT_INVOIC TYPE MTT_INVOIC
- * | [<---] ET_RET TYPE BAPIRET2_T
- * +--------------------------------------------------------------------------------------</SIGNATURE>
- METHOD rn_reg_update.
- DATA: lt_rn_reg_chg TYPE j_3rm_rn_reg_tt,
- lt_rn_doc_new TYPE j_3rm_rn_doc_tt,
- lv_prim_doc_type TYPE j_3rm_primdoctype,
- lv_prim_doc_num TYPE j_3rm_rn_primdocnr,
- lv_prim_doc_year TYPE j_3rm_rn_primdocyr,
- lv_prim_doc_pos TYPE j_3rm_rn_primdocpos,
- lt_ret TYPE j_3rm_rn_messages_ret,
- lt_rnpt_upd TYPE TABLE OF zrnpt_input_doc,
- lv_quantity TYPE j_3rm_rn_avquant.
- LOOP AT it_invoic INTO DATA(ls_sum).
- lv_quantity = lv_quantity + ls_sum-r_menge.
- ENDLOOP.
- LOOP AT it_rn_reg INTO DATA(ls_rn_reg).
- APPEND INITIAL LINE TO lt_rn_reg_chg ASSIGNING FIELD-SYMBOL(<fs_reg>).
- <fs_reg>-rn_reg_id = ls_rn_reg-rn_reg_id.
- <fs_reg>-rn_reg_year = ls_rn_reg-rn_reg_year.
- <fs_reg>-rn_reg_date = ls_rn_reg-rn_reg_date.
- <fs_reg>-rn_ext_num = ls_rn_reg-rn_ext_num.
- <fs_reg>-src_oper_type = ls_rn_reg-src_oper_type.
- * <fs_reg>-manually_created = ''.
- <fs_reg>-matnr = is_invoic-r_matnr.
- <fs_reg>-asset_num = is_invoic-r_anln1.
- <fs_reg>-asset_subnum = is_invoic-r_anln2.
- <fs_reg>-company_code = is_invoic-r_bukrs.
- <fs_reg>-country_of_origin = is_invoic-land.
- <fs_reg>-batch = is_invoic-m_batch.
- * <fs_reg>-serial_number = is_invoic- " ?
- <fs_reg>-wbs_element = is_invoic-r_wbs_element.
- <fs_reg>-invest_order = is_invoic-r_aufnr.
- <fs_reg>-meins = is_invoic-r_meins.
- <fs_reg>-avail_quantity = 0. "is_invoic-r_menge.
- <fs_reg>-created_by = ls_rn_reg-created_by.
- <fs_reg>-created_on = ls_rn_reg-created_on.
- <fs_reg>-changed_by = ls_rn_reg-changed_by.
- <fs_reg>-changed_on = ls_rn_reg-changed_on.
- ENDLOOP.
- LOOP AT it_invoic INTO DATA(ls_invoic).
- IF ls_invoic-r_anln1 IS NOT INITIAL OR ls_invoic-r_wbs_element IS NOT INITIAL..
- lv_prim_doc_type = '06'.
- ELSE.
- lv_prim_doc_type = '01'.
- ENDIF.
- IF ls_invoic-m_mblnr IS INITIAL.
- lv_prim_doc_num = ls_invoic-f_belnr.
- lv_prim_doc_year = ls_invoic-f_gjahr.
- ELSE.
- lv_prim_doc_num = ls_invoic-m_mblnr.
- lv_prim_doc_year = ls_invoic-m_mjahr.
- ENDIF.
- IF ls_invoic-m_zeile IS INITIAL.
- lv_prim_doc_pos = ls_invoic-f_pos.
- ELSE.
- lv_prim_doc_pos = ls_invoic-m_zeile.
- ENDIF.
- APPEND INITIAL LINE TO lt_rn_doc_new ASSIGNING FIELD-SYMBOL(<fs_doc>).
- <fs_doc>-rn_reg_id = ls_rn_reg-rn_reg_id.
- <fs_doc>-rn_reg_year = ls_rn_reg-rn_reg_year.
- * <fs_doc>-rn_reg_movmnt = " ?
- <fs_doc>-prim_doc_type = lv_prim_doc_type.
- <fs_doc>-prim_doc_num = lv_prim_doc_num.
- <fs_doc>-prim_doc_year = lv_prim_doc_year.
- <fs_doc>-prim_doc_pos = lv_prim_doc_pos.
- <fs_doc>-mm_invoice_num = ls_invoic-r_belnr.
- <fs_doc>-mm_invoice_year = ls_invoic-r_gjahr.
- <fs_doc>-mm_invoice_pos = ls_invoic-r_buzei.
- <fs_doc>-fi_invoice_num = ls_invoic-f_belnr.
- <fs_doc>-fi_invoice_year = ls_invoic-f_gjahr.
- <fs_doc>-menge = ls_invoic-r_menge.
- <fs_doc>-tnved = ls_invoic-tnved.
- * <fs_doc>-okpd2 = " ?
- * <fs_doc>-cancelled_by = " ?
- <fs_doc>-created_by = sy-uname.
- <fs_doc>-created_on = sy-datum.
- <fs_doc>-amount = ls_invoic-wrbtr.
- <fs_doc>-currency = ls_invoic-r_waers.
- <fs_doc>-operation_date = ls_invoic-r_budat.
- ENDLOOP.
- CALL FUNCTION 'J_3RM_RN_REG_UPDATE'
- EXPORTING
- it_rn_reg_chg = lt_rn_reg_chg
- * IT_RN_DOC_CHG =
- iv_save_mode = ''
- iv_disable_checks = 'X'
- IMPORTING
- et_messages = lt_ret
- CHANGING
- ct_rn_doc_new = lt_rn_doc_new.
- LOOP AT lt_rn_doc_new INTO DATA(ls).
- IF line_exists( lt_ret[ type = 'E' ] ).
- ls-rn_reg_id = 'ERROR'.
- CLEAR ls-rn_reg_year.
- ENDIF.
- APPEND VALUE #( rn_reg_id = ls-rn_reg_id
- rn_reg_year = ls-rn_reg_year
- type_doc = is_invoic-rnpt_type_doc
- doc_id = is_invoic-rnpt_doc_id
- pos_id = is_invoic-rnpt_pos_id
- sub_pos = is_invoic-rnpt_sub_pos
- rnpt = is_invoic-rnpt
- land = is_invoic-land
- meins = is_invoic-r_meins
- menge = is_invoic-r_menge
- amount = is_invoic-wrbtr
- type_input = is_invoic-rnpt_type_input ) TO lt_rnpt_upd.
- ENDLOOP.
- CALL FUNCTION 'Z_UPDATE_ZRNPT_INPUT_DOC' IN UPDATE TASK
- EXPORTING
- it_rnpt = lt_rnpt_upd
- iv_doc_id = is_invoic-rnpt_doc_id
- iv_type_doc = is_invoic-rnpt_type_doc
- iv_generate = abap_true.
- et_ret = CORRESPONDING #( lt_ret ).
- ENDMETHOD.
- * <SIGNATURE>---------------------------------------------------------------------------------------+
- * | Static Private Method ZCL_RNPT_PROCESSOR=>_ADD_MESSAGE
- * +-------------------------------------------------------------------------------------------------+
- * | [--->] IV_NUM TYPE SY-MSGNO
- * | [<-->] CT_RET TYPE BAPIRET2_T
- * +--------------------------------------------------------------------------------------</SIGNATURE>
- METHOD _add_message.
- DATA ls_bapiret2 TYPE bapiret2.
- ls_bapiret2-type = 'E'.
- ls_bapiret2-id = 'ZL_RN000001'.
- ls_bapiret2-number = iv_num.
- MESSAGE ID ls_bapiret2-id
- TYPE ls_bapiret2-type
- NUMBER ls_bapiret2-number
- WITH ls_bapiret2-message_v1
- ls_bapiret2-message_v2
- ls_bapiret2-message_v3
- ls_bapiret2-message_v4
- INTO ls_bapiret2-message.
- APPEND ls_bapiret2 TO ct_ret.
- ENDMETHOD.
- * <SIGNATURE>---------------------------------------------------------------------------------------+
- * | Static Private Method ZCL_RNPT_PROCESSOR=>_BUILD_DYNAMIC_WHERE
- * +-------------------------------------------------------------------------------------------------+
- * | [--->] IV_COMPANY_CODE TYPE BUKRS(optional)
- * | [--->] IV_RN_EXT_NUMBER TYPE J_3RM_RN_EXT_NUM(optional)
- * | [--->] IV_RN_REG_DATE TYPE J_3RM_RN_DATE(optional)
- * | [--->] IV_BATCH TYPE CHARG_D(optional)
- * | [--->] IV_MATERIAL TYPE MATNR(optional)
- * | [--->] IV_SERIAL_NUMBER TYPE GERNR(optional)
- * | [--->] IV_ASSET_NUM TYPE ANLN1(optional)
- * | [--->] IV_ASSET_SUBNUM TYPE ANLN2(optional)
- * | [--->] IV_WBS_ELEMENT TYPE PS_PSP_PNR(optional)
- * | [--->] IV_INVEST_ORDER TYPE AUFNR(optional)
- * | [<-()] RT_WHERE_CLAUSE TYPE MTT_CLAUSE
- * +--------------------------------------------------------------------------------------</SIGNATURE>
- METHOD _build_dynamic_where.
- DATA: lt_condtab TYPE TABLE OF hrcond.
- IF iv_company_code IS NOT INITIAL.
- APPEND VALUE #( field = 'COMPANY_CODE' opera = 'EQ' low = iv_company_code ) TO lt_condtab.
- ENDIF.
- IF iv_rn_ext_number IS NOT INITIAL.
- APPEND VALUE #( field = 'RN_EXT_NUM' opera = 'EQ' low = iv_rn_ext_number ) TO lt_condtab.
- ENDIF.
- IF iv_rn_reg_date IS NOT INITIAL.
- APPEND VALUE #( field = 'RN_REG_DATE' opera = 'EQ' low = iv_rn_reg_date ) TO lt_condtab.
- ENDIF.
- IF iv_batch IS NOT INITIAL.
- APPEND VALUE #( field = 'BATCH' opera = 'EQ' low = iv_batch ) TO lt_condtab.
- ENDIF.
- IF iv_material IS NOT INITIAL.
- APPEND VALUE #( field = 'MATNR' opera = 'EQ' low = iv_material ) TO lt_condtab.
- ENDIF.
- IF iv_serial_number IS NOT INITIAL.
- APPEND VALUE #( field = 'SERIAL_NUMBER' opera = 'EQ' low = iv_serial_number ) TO lt_condtab.
- ENDIF.
- IF iv_asset_num IS NOT INITIAL.
- APPEND VALUE #( field = 'ASSET_NUM' opera = 'EQ' low = iv_asset_num ) TO lt_condtab.
- ENDIF.
- IF iv_asset_subnum IS NOT INITIAL.
- APPEND VALUE #( field = 'ASSET_SUBNUM' opera = 'EQ' low = iv_asset_subnum ) TO lt_condtab.
- ENDIF.
- IF iv_wbs_element IS NOT INITIAL.
- APPEND VALUE #( field = 'WBS_ELEMENT' opera = 'EQ' low = iv_wbs_element ) TO lt_condtab.
- ENDIF.
- IF iv_invest_order IS NOT INITIAL.
- APPEND VALUE #( field = 'INVEST_ORDER' opera = 'EQ' low = iv_invest_order ) TO lt_condtab.
- ENDIF.
- CHECK lt_condtab IS NOT INITIAL.
- CALL FUNCTION 'RH_DYNAMIC_WHERE_BUILD'
- EXPORTING
- dbtable = space
- TABLES
- condtab = lt_condtab
- where_clause = rt_where_clause
- EXCEPTIONS
- empty_condtab = 01
- no_db_field = 02
- unknown_db = 03
- wrong_condition = 04.
- ENDMETHOD.
- * <SIGNATURE>---------------------------------------------------------------------------------------+
- * | Static Private Method ZCL_RNPT_PROCESSOR=>_FILTER_DOC
- * +-------------------------------------------------------------------------------------------------+
- * | [--->] IV_POS_ID TYPE CHAR2
- * | [--->] IT_ZRNPT TYPE MTT_ZRNPT
- * | [<-()] RT_FAE TYPE MTT_FAE
- * +--------------------------------------------------------------------------------------</SIGNATURE>
- METHOD _filter_doc.
- rt_fae = VALUE #( FOR ls_rnpt IN it_zrnpt WHERE ( pos_id(2) = iv_pos_id )
- ( belnr = ls_rnpt-doc_id(10)
- gjahr = ls_rnpt-doc_id+10(4)
- buzei = ls_rnpt-pos_id+2
- cobl_nr = ls_rnpt-pos_id+2 ) ).
- SORT rt_fae BY belnr gjahr buzei.
- DELETE ADJACENT DUPLICATES FROM rt_fae COMPARING belnr gjahr buzei.
- ENDMETHOD.
- ENDCLASS.
Add Comment
Please, Sign In to add comment