Original Assets in Asset management
I am writing this document for those who are facing problems while determining Original assets in Asset management. I hope this information will meet your requirement.
Pre-requisites:
1. SAP Tables that you need to consider ANLA, ANEK, ANEP, ANLB.
2. Input selection screen
3. Selection texts
4. Text sysmbols
5. We need to determine the following information
• Original Asset Company code
• Original Asset Number
• Original Asset Subnumber
• Original Asset Ord.depreciation start date
6. Related program code
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* Developer : B Raghu Prasad (Mouritech Pvt Ltd.)
* Creation Date : Jul 23rd 2015
* Functional Area : Asset management
* Purpose : This Program will determine Original assets
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
REPORT sy-repid.
*-Local variable declarations
DATA: lv_anlkl TYPE anla-anlkl,
lv_asset TYPE anla-anln1,
lv_zuper TYPE anla-zuper,
lv_bukrs TYPE bukrs,
lv_anln1 TYPE anln1,
lv_anln2 TYPE anln2,
lv_pbukr TYPE pbukr,
lv_aibn1 TYPE aibn1,
lv_aibn2 TYPE aibn2,
lv_deakt TYPE deakt,
lv_zugdt TYPE dzugdat,
lv_afabg TYPE afabg,
lv_tablines(5) TYPE n.
*-Structure declarations
TYPES: BEGIN OF ty_anln1,
anln1 TYPE anla-anln1,
anln2 TYPE anla-anln2,
END OF ty_anln1.
*-Asset transfer chain
TYPES: BEGIN OF ty_asset_chain,
bukrs TYPE anla-bukrs,
anln1 TYPE anla-anln1,
anln2 TYPE anla-anln2,
zugdt TYPE anla-zugdt,
afabg TYPE anlb-afabg,
deakt TYPE anla-deakt,
END OF ty_asset_chain.
*-Output structure
TYPES: BEGIN OF ty_output,
bukrs TYPE bukrs,
anln1 TYPE anln1,
anln2 TYPE anln2,
afabg TYPE afabg,
oribukrs TYPE bukrs,
orianln1 TYPE anln1,
orianln2 TYPE anln2,
oriafabg TYPE afabg,
END OF ty_output.
*-Internal table and workarea declarations
DATA: wa_anln1 TYPE ty_anln1,
it_anln1 TYPE STANDARD TABLE OF ty_anln1,
gt_anla TYPE TABLE OF anla,
wa_anla TYPE anla,
wa_output TYPE ty_output,
it_output TYPE STANDARD TABLE OF ty_output.
DATA: it_fieldcatalog TYPE slis_t_fieldcat_alv,
wa_fieldcatalog TYPE slis_fieldcat_alv,
wa_fieldlayout TYPE slis_layout_alv,
gd_repid TYPE sy-repid.
*-Asset list transfer chain
DATA: it_asset_chain TYPE STANDARD TABLE OF ty_asset_chain,
wa_asset_chain TYPE ty_asset_chain.
*-Selection screen
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS : p_bukrs LIKE bkpf-bukrs DEFAULT 'HU01',
p_gjahr LIKE bkpf-gjahr DEFAULT sy-datum+0(4).
SELECT-OPTIONS: s_zuper FOR lv_zuper NO-EXTENSION,
s_anlkl FOR lv_anlkl OBLIGATORY,
s_asset FOR lv_asset.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
*-Fetch data from ANLA with Deactivation date Empty (Only Active Assets)
CLEAR: gt_anla[].
SELECT * FROM anla INTO TABLE gt_anla WHERE bukrs = p_bukrs
AND anln1 IN s_asset
AND anlkl IN s_anlkl
AND zujhr = p_gjahr
AND zuper IN s_zuper
AND deakt = '00000000'.
IF gt_anla IS NOT INITIAL.
*-Loop over all the assets and determine their Original assets
LOOP AT gt_anla INTO wa_anla.
lv_bukrs = wa_anla-bukrs.
lv_anln1 = wa_anla-anln1.
lv_anln2 = wa_anla-anln2.
CLEAR: it_anln1[].
DO.
CLEAR: wa_anln1.
READ TABLE it_anln1 INTO wa_anln1 WITH KEY anln1 = lv_anln1 anln2 = lv_anln2 .
IF sy-subrc NE 0.
CLEAR: wa_anln1.
wa_anln1-anln1 = lv_anln1.
wa_anln1-anln2 = lv_anln2.
APPEND wa_anln1 TO it_anln1.
ELSE.
EXIT.
ENDIF.
SELECT SINGLE a~aibn1 a~aibn2 a~zugdt a~deakt b~afabg
INTO (lv_aibn1, lv_aibn2, lv_zugdt, lv_deakt, lv_afabg)
FROM anla AS a INNER JOIN anlb AS b ON
a~bukrs = b~bukrs AND
a~anln1 = b~anln1 AND
a~anln2 = b~anln2 AND
b~afabe = '01' "Depreciation area in my case
WHERE a~bukrs = lv_bukrs AND
a~anln1 = lv_anln1 AND
a~anln2 = lv_anln2.
*-Get the company code of original asset
PERFORM get_partner_bukrs USING lv_bukrs lv_anln1 lv_anln2
lv_aibn1 lv_aibn2
CHANGING lv_pbukr.
CLEAR wa_asset_chain.
wa_asset_chain-bukrs = lv_bukrs.
wa_asset_chain-anln1 = lv_anln1.
wa_asset_chain-anln2 = lv_anln2.
wa_asset_chain-deakt = lv_deakt.
wa_asset_chain-zugdt = lv_zugdt.
wa_asset_chain-afabg = lv_afabg.
APPEND wa_asset_chain TO it_asset_chain.
CLEAR: wa_asset_chain.
IF lv_aibn1 IS INITIAL.
EXIT.
ENDIF.
lv_bukrs = lv_pbukr.
lv_anln1 = lv_aibn1.
lv_anln2 = lv_aibn2.
ENDDO.
IF it_asset_chain IS NOT INITIAL.
CLEAR: wa_asset_chain.
READ TABLE it_asset_chain INTO wa_asset_chain INDEX 1.
IF wa_asset_chain-anln1 IS NOT INITIAL.
wa_output-bukrs = wa_asset_chain-bukrs.
wa_output-anln1 = wa_asset_chain-anln1.
SHIFT wa_output-anln1 LEFT DELETING LEADING '0'.
wa_output-anln2 = wa_asset_chain-anln2.
wa_output-afabg = wa_asset_chain-afabg.
ENDIF.
lv_tablines = lines( it_asset_chain ).
CLEAR: wa_asset_chain.
READ TABLE it_asset_chain INTO wa_asset_chain INDEX lv_tablines.
IF wa_asset_chain-anln1 IS NOT INITIAL.
wa_output-oribukrs = wa_asset_chain-bukrs.
wa_output-orianln1 = wa_asset_chain-anln1.
SHIFT wa_output-orianln1 LEFT DELETING LEADING '0'.
wa_output-orianln2 = wa_asset_chain-anln2.
wa_output-oriafabg = wa_asset_chain-afabg.
ENDIF.
ENDIF.
APPEND wa_output TO it_output.
CLEAR: wa_output,wa_anla,lv_bukrs,lv_bukrs,lv_deakt,lv_afabg,lv_aibn1,
lv_anln1,lv_anln1,lv_zugdt,lv_aibn2,lv_tablines,
lv_anln2,lv_anln2,lv_pbukr,it_asset_chain[].
ENDLOOP.
ENDIF.
END-OF-SELECTION.
PERFORM build_fieldcat.
PERFORM display_alv.
*&---------------------------------------------------------------------*
*& Form GET_PARTNER_BUKRS
*&---------------------------------------------------------------------*
* Find compnay code of the original asset from which internal
* transfer was made
FORM get_partner_bukrs USING pv_bukrs
pv_anln1
pv_anln2
pv_aibn1
pv_aibn2
CHANGING cv_partner_bukrs.
IF NOT pv_aibn1 IS INITIAL.
SELECT SINGLE k~pbukr INTO cv_partner_bukrs
FROM anep AS p INNER JOIN anek AS k ON
p~bukrs = k~bukrs AND
p~anln1 = k~anln1 AND
p~anln2 = k~anln2 AND
p~gjahr = k~gjahr AND
p~lnran = k~lnran
WHERE p~bukrs = pv_bukrs AND
p~anln1 = pv_anln1 AND
p~anln2 = pv_anln2 AND
p~afabe = '01' AND
p~lnsan = 0 AND
k~anlu1 = pv_aibn1 AND
k~anlu2 = pv_aibn2.
ENDIF.
IF cv_partner_bukrs IS INITIAL.
cv_partner_bukrs = pv_bukrs.
ENDIF.
ENDFORM. " GET_PARTNER_BUKRS
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM build_fieldcat .
wa_fieldcatalog-col_pos = 1.
wa_fieldcatalog-fieldname = 'BUKRS'.
wa_fieldcatalog-tabname = 'IT_OUTPUT'.
wa_fieldcatalog-seltext_m = 'Comp.Code'.
wa_fieldcatalog-seltext_l = 'Company code'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR wa_fieldcatalog.
wa_fieldcatalog-col_pos = 2.
wa_fieldcatalog-fieldname = 'ANLN1'.
wa_fieldcatalog-tabname = 'IT_OUTPUT'.
wa_fieldcatalog-seltext_m = 'Asset Num.'.
wa_fieldcatalog-seltext_l = 'Asset Number'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR wa_fieldcatalog.
wa_fieldcatalog-col_pos = 3.
wa_fieldcatalog-fieldname = 'ANLN2'.
wa_fieldcatalog-tabname = 'IT_OUTPUT'.
wa_fieldcatalog-seltext_m = 'Asset Subnum.'.
wa_fieldcatalog-seltext_l = 'Asset Subnumber'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR wa_fieldcatalog.
wa_fieldcatalog-col_pos = 4.
wa_fieldcatalog-fieldname = 'AFABG'.
wa_fieldcatalog-tabname = 'IT_OUTPUT'.
wa_fieldcatalog-seltext_m = 'Ord.dep.st.date'.
wa_fieldcatalog-seltext_l = 'Ord.depreciation start date'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR wa_fieldcatalog.
wa_fieldcatalog-col_pos = 5.
wa_fieldcatalog-fieldname = 'ORIBUKRS'.
wa_fieldcatalog-tabname = 'IT_OUTPUT'.
wa_fieldcatalog-seltext_m = 'Ori.Comp.Code'.
wa_fieldcatalog-seltext_l = 'Ori.Company code'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR wa_fieldcatalog.
wa_fieldcatalog-col_pos = 6.
wa_fieldcatalog-fieldname = 'ORIANLN1'.
wa_fieldcatalog-tabname = 'IT_OUTPUT'.
wa_fieldcatalog-seltext_m = 'Ori.Asset Num.'.
wa_fieldcatalog-seltext_l = 'Ori.Asset Number'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR wa_fieldcatalog.
wa_fieldcatalog-col_pos = 7.
wa_fieldcatalog-fieldname = 'ORIANLN2'.
wa_fieldcatalog-tabname = 'IT_OUTPUT'.
wa_fieldcatalog-seltext_m = 'Ori.Asset Subnum.'.
wa_fieldcatalog-seltext_l = 'Ori.Asset Subnumber'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR wa_fieldcatalog.
wa_fieldcatalog-col_pos = 8.
wa_fieldcatalog-fieldname = 'ORIAFABG'.
wa_fieldcatalog-tabname = 'IT_OUTPUT'.
wa_fieldcatalog-seltext_m = 'Ori.Ord.dep.st.date'.
wa_fieldcatalog-seltext_l = 'Original Ord.depreciation start date'.
APPEND wa_fieldcatalog TO it_fieldcatalog.
CLEAR wa_fieldcatalog.
ENDFORM. " BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM display_alv .
gd_repid = sy-repid.
wa_fieldlayout-colwidth_optimize = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = gd_repid
it_fieldcat = it_fieldcatalog
is_layout = wa_fieldlayout
TABLES
t_outtab = it_output
EXCEPTIONS
program_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " DISPLAY_ALV
7. Execute the report
8. Resultant Output
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
3 | |
3 | |
2 | |
2 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 |