Está en la página 1de 7

PROGRAM trans_routine.

*---------------------------------------------------------------------*
* CLASS routine DEFINITION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_transform DEFINITION.
PUBLIC SECTION.

* Attributs
DATA:
p_check_master_data_exist
TYPE RSODSOCHECKONLY READ-ONLY,
*- Instance for getting request runtime attributs;
* Available information: Refer to methods of
* interface 'if_rsbk_request_admintab_view'
p_r_request
TYPE REF TO if_rsbk_request_admintab_view READ-ONLY.

PRIVATE SECTION.

TYPE-POOLS: rsd, rstr.

* Rule specific types


TYPES:
BEGIN OF _ty_s_SC_1,
* InfoObject: 0AC_DOC_NO Accounting document number.
AC_DOC_NO TYPE /BI0/OIAC_DOC_NO,
* InfoObject: 0COMP_CODE Company code.
COMP_CODE TYPE /BI0/OICOMP_CODE,
* InfoObject: 0ITEM_NUM Number of line item within accounting docum
*ent.
ITEM_NUM TYPE /BI0/OIITEM_NUM,
* InfoObject: 0FISCPER ������/�‫�ڼ‬.
FISCPER TYPE /BI0/OIFISCPER,
* InfoObject: 0AC_DOC_TYP Document type.
AC_DOC_TYP TYPE /BI0/OIAC_DOC_TYP,
* InfoObject: 0ORG_DOC_NO Document Number of Source Document.
ORG_DOC_NO TYPE /BI0/OIORG_DOC_NO,
* InfoObject: 0ORG_DOC_YR Fiscal Year for Source Document Number.
ORG_DOC_YR TYPE /BI0/OIORG_DOC_YR,
* InfoObject: 0PLANT Plant.
PLANT TYPE /BI0/OIPLANT,
* InfoObject: 0TXTLG ������.
TXTLG TYPE RSTXTLG,
* InfoObject: 0VENDOR ��Ӧ��.
VENDOR TYPE /BI0/OIVENDOR,
* InfoObject: 0DOC_NUM BW: Document Number.
DOC_NUM TYPE /BI0/OIDOC_NUM,
* InfoObject: ZTCODE �������.
/BIC/ZTCODE TYPE /BIC/OIZTCODE,
* Field: RECORD.
RECORD TYPE RSARECORD,
END OF _ty_s_SC_1.
TYPES:
BEGIN OF _ty_s_TG_1,
* InfoObject: 0CREDITOR Account number of supplier/vendor.
CREDITOR TYPE /BI0/OICREDITOR,
END OF _ty_s_TG_1.

*$*$ begin of global - insert your declaration only below this line *-*

*** version 1.0 by luojianchao on 2014.1.10

TYPES: BEGIN OF ty_doc1,


org_doc_no TYPE /bi0/oiorg_doc_no,
comp_code TYPE /bi0/oicomp_code,
END OF ty_doc1.

TYPES: BEGIN OF ty_doc2,


org_doc_no TYPE /bi0/oiorg_doc_no,
END OF ty_doc2.

TYPES: BEGIN OF ty_doc3,


org_doc_yr TYPE /bi0/oiorg_doc_yr,
org_doc_no TYPE /bi0/oiorg_doc_no,
doc_item TYPE /bi0/oidoc_item,
END OF ty_doc3.

TYPES: BEGIN OF ty_doc4,


VENDOR TYPE /BI0/OIVENDOR,
PURCH_ORG TYPE /BI0/OIPURCH_ORG,
END OF ty_doc4.

TYPES: BEGIN OF ty_doc5,


org_doc_yr TYPE /bi0/oiorg_doc_yr,
org_doc_no TYPE /bi0/oiorg_doc_no,
END OF ty_doc5.

TYPES: BEGIN OF ty_doc6,


/BIC/ZUONR TYPE /BIC/OIZUONR,
VENDOR TYPE /BI0/OIvendor,
END OF ty_doc6.

TYPES: BEGIN OF ty_inv,


bbp_inv_id TYPE /bi0/oibbp_inv_id,
fiscyear TYPE /bi0/oifiscyear,
inv_pty TYPE /bi0/oiinv_pty,
END OF ty_inv.

TYPES: BEGIN OF ty_bf,


doc_num TYPE /bi0/oidoc_num,
doc_item TYPE /bi0/oidoc_item,
vendor TYPE /bi0/oivendor,
END OF ty_bf.

TYPES: BEGIN OF ty_ap,


AC_DOC_NO TYPE /BI0/OIAC_DOC_NO,
COMP_CODE TYPE /BI0/OICOMP_CODE,
CREDITOR TYPE /bi0/oiCREDITOR,
END OF ty_ap.

TYPES: BEGIN OF ty_hd,


DOC_NUM TYPE /BI0/OIDOC_NUM,
VENDOR TYPE /BI0/OIvendor,
INV_PARTY TYPE /BI0/OIINV_PARTY,
END OF ty_hd.

TYPES: BEGIN OF ty_vp,


/BIC/ZVEN_PORG TYPE /BIC/OIZVEN_PORG,
PURCH_ORG TYPE /BI0/OIPURCH_ORG,
INV_PARTY TYPE /BI0/OIINV_PARTY,
END OF ty_vp.

DATA :
*** for the ZFI_AP_4 of Doc and Company
it_doc1 TYPE TABLE OF ty_doc1,
wa_doc1 TYPE ty_doc1,
*** for the ZLIS02HD of PO
it_doc2 TYPE TABLE OF ty_doc2,
wa_doc2 TYPE ty_doc2,
*** for the ZLIS03BF of Material Doc and Item
it_doc3 TYPE TABLE OF ty_doc3,
wa_doc3 TYPE ty_doc3,
*** for the consignment of Vender
it_doc4 TYPE TABLE OF ty_doc4,
wa_doc4 TYPE ty_doc4,
*** for IR
it_doc5 TYPE TABLE OF ty_doc5,
wa_doc5 TYPE ty_doc5,
*** for GR
it_doc6 TYPE TABLE OF ty_doc6,
wa_doc6 TYPE ty_doc6,

it_inv TYPE TABLE OF ty_inv,


*** for the ZLIS03BF of Vender
it_bf TYPE TABLE OF ty_bf,
*** for the ZFI_AP_4 of CREDITOR
it_ap TYPE TABLE OF ty_ap,
*** for the ZLIS02HD of PI
it_hd TYPE TABLE OF ty_hd,
*** for the ZVEN_PORG of PI
it_vp TYPE TABLE OF ty_vp,
*** for the ZFIAPD08 of ZUONR
it_APD08 TYPE TABLE OF /BIC/AZFIAPD0800,
wa_APD08 TYPE /BIC/AZFIAPD0800.

DATA: tab_nam TYPE tabname,


*** for the PI Company and Vender
IT_ZCOMP_COV TYPE TABLE OF /BIC/MZCOMP_COV,
WA_ZCOMP_COV TYPE /BIC/MZCOMP_COV,
*** for Company On Live Time
IT_ZCOMP_COW TYPE TABLE OF /BIC/MZCOMP_COW,
WA_ZCOMP_COW TYPE /BIC/MZCOMP_COW,
*** for fetch pant
IT_ZPLANT TYPE TABLE OF /BIC/MZPLANT,
WA_ZPLANT TYPE /BIC/MZPLANT.

*$*$ end of global - insert your declaration only before this line *-*

METHODS
compute_0CREDITOR
IMPORTING
request type rsrequest
datapackid type rsdatapid
SOURCE_FIELDS type _ty_s_SC_1
segid type RSBK_SEGID
EXPORTING
RESULT type _ty_s_TG_1-CREDITOR
monitor type rstr_ty_t_monitor
RAISING
cx_rsrout_abort
cx_rsrout_skip_record
cx_rsrout_skip_val
cx_rsbk_errorcount.
METHODS
invert_0CREDITOR
IMPORTING
i_th_fields_outbound TYPE rstran_t_field_inv
i_r_selset_outbound TYPE REF TO cl_rsmds_set
i_is_main_selection TYPE rs_bool
i_r_selset_outbound_complete TYPE REF TO cl_rsmds_set
i_r_universe_inbound TYPE REF TO cl_rsmds_universe
CHANGING
c_th_fields_inbound TYPE rstran_t_field_inv
c_r_selset_inbound TYPE REF TO cl_rsmds_set
c_exact TYPE rs_bool.
ENDCLASS. "routine DEFINITION

*$*$ begin of 2nd part global - insert your code only below this line *

*$*$ end of 2nd part global - insert your code only before this line *

*---------------------------------------------------------------------*
* CLASS routine IMPLEMENTATION
*---------------------------------------------------------------------*
*
*---------------------------------------------------------------------*
CLASS lcl_transform IMPLEMENTATION.

*----------------------------------------------------------------------*
* Method compute_0CREDITOR
*----------------------------------------------------------------------*
* This subroutine allows the mapping from source to target fields
* of a transformation rule using ABAP for application specific
* coding.
*----------------------------------------------------------------------*
* Customer comment:
*----------------------------------------------------------------------*
METHOD compute_0CREDITOR.

* IMPORTING
* request type rsrequest
* datapackid type rsdatapid
* SOURCE_FIELDS-AC_DOC_NO TYPE /BI0/OIAC_DOC_NO
* SOURCE_FIELDS-COMP_CODE TYPE /BI0/OICOMP_CODE
* SOURCE_FIELDS-ITEM_NUM TYPE /BI0/OIITEM_NUM
* SOURCE_FIELDS-FISCPER TYPE /BI0/OIFISCPER
* SOURCE_FIELDS-AC_DOC_TYP TYPE /BI0/OIAC_DOC_TYP
* SOURCE_FIELDS-ORG_DOC_NO TYPE /BI0/OIORG_DOC_NO
* SOURCE_FIELDS-ORG_DOC_YR TYPE /BI0/OIORG_DOC_YR
* SOURCE_FIELDS-PLANT TYPE /BI0/OIPLANT
* SOURCE_FIELDS-TXTLG TYPE RSTXTLG
* SOURCE_FIELDS-VENDOR TYPE /BI0/OIVENDOR
* SOURCE_FIELDS-DOC_NUM TYPE /BI0/OIDOC_NUM
* SOURCE_FIELDS-/BIC/ZTCODE TYPE /BIC/OIZTCODE
* EXPORTING
* RESULT type _ty_s_TG_1-CREDITOR

DATA:
MONITOR_REC TYPE rsmonitor.

*$*$ begin of routine - insert your code only below this line *-*
... "insert your code here
*-- fill table "MONITOR" with values of structure "MONITOR_REC"
*- to make monitor entries
... "to cancel the update process
* raise exception type CX_RSROUT_ABORT.
... "to skip a record
* raise exception type CX_RSROUT_SKIP_RECORD.
... "to clear target fields
* raise exception type CX_RSROUT_SKIP_VAL.

*** version 1.0 by luojianchao on 2014.1.10

FIELD-SYMBOLS: <fs_ap> TYPE ty_ap,


<fs_hd> TYPE ty_hd,
<fs_bf> TYPE ty_bf,
<fs_vp> TYPE ty_vp,
<fs_inv> TYPE ty_inv.

SORT it_bf BY doc_num doc_item.


SORT it_ap BY AC_DOC_NO COMP_CODE.
SORT it_hd BY DOC_NUM.
SORT it_vp BY /BIC/ZVEN_PORG PURCH_ORG.
SORT it_inv BY bbp_inv_id fiscyear.

IF SOURCE_FIELDS-VENDOR IS INITIAL.
*** for jugde the PI of company
read table IT_ZCOMP_COV into WA_ZCOMP_COV with key
/BIC/ZCOMP_COV = SOURCE_FIELDS-COMP_CODE.

IF sy-subrc = 0.
*** Fetch the ZFI_AP_4 of vender
READ TABLE it_ap ASSIGNING <fs_ap> WITH KEY
AC_DOC_NO = SOURCE_FIELDS-AC_DOC_NO
COMP_CODE = SOURCE_FIELDS-COMP_CODE
binary search.
if sy-subrc = 0.
RESULT = <fs_ap>-CREDITOR.
else.

READ TABLE it_inv ASSIGNING <fs_inv> WITH KEY


bbp_inv_id = SOURCE_FIELDS-org_doc_no
fiscyear = SOURCE_FIELDS-org_doc_yr
binary search.
IF sy-subrc = 0.
RESULT = <fs_inv>-inv_pty.
ENDIF.
endif.
ELSE.

*** fetch the ZLIS03BF of vender


READ TABLE it_bf ASSIGNING <fs_bf>
WITH KEY doc_num = SOURCE_FIELDS-org_doc_no
doc_item = SOURCE_FIELDS-txtlg(6)
binary search.

if sy-subrc = 0.
RESULT = <fs_bf>-vendor.

else.

*** fetch ZLIS02HD of vender


READ TABLE it_hd ASSIGNING <fs_hd> WITH KEY
DOC_NUM = SOURCE_FIELDS-DOC_NUM
binary search.

if sy-subrc = 0.
RESULT = <fs_hd>-VENDOR.

else.

*** fetch the ZFI_AP_4 of CREDITOR


READ TABLE it_ap ASSIGNING <fs_ap> WITH KEY
AC_DOC_NO = SOURCE_FIELDS-AC_DOC_NO
COMP_CODE = SOURCE_FIELDS-COMP_CODE
binary search.
IF sy-subrc = 0.
RESULT = <fs_ap>-CREDITOR.
ELSE.

*** fetch ZLIS06IN of vender


READ TABLE it_inv ASSIGNING <fs_inv> WITH KEY
bbp_inv_id = SOURCE_FIELDS-org_doc_no
fiscyear = SOURCE_FIELDS-org_doc_yr
binary search.
IF sy-subrc = 0.
RESULT = <fs_inv>-inv_pty.
endif.
ENDIF.
endif.

endif.

ENDIF.

ELSE.

RESULT = SOURCE_FIELDS-VENDOR.

ENDIF.

IF RESULT = 'BYD��SH'.
RESULT = 'BYD_SH'.
ENDIF.

*$*$ end of routine - insert your code only before this line *-*
ENDMETHOD. "compute_0CREDITOR
*----------------------------------------------------------------------*
* Inverse method invert_0CREDITOR
*----------------------------------------------------------------------*
* This subroutine needs to be implemented only for direct access
* (for better performance) and for the Report/Report Interface
* (drill through).
* The inverse routine should transform a projection and
* a selection for the target to a projection and a selection
* for the source, respectively.
* If the implementation remains empty all fields are filled and
* all values are selected.
*----------------------------------------------------------------------*
* Customer comment:
*----------------------------------------------------------------------*
METHOD invert_0CREDITOR.

También podría gustarte