Hi,
I have written a user-exit for AS01, AS02, AS11 transaction. (AIST0002 -> EXIT_SAPLAIST_003).
Basically I am trying to change the value (Depreciation key, Planned useful life in years & periods) in Depreciation Area based on Local Stat. Class & Tax Class in Allocation tab. i.e. I am picking value from custom table and updating the value. (Updating the value in ANLB table)
If user press "Save" button, my code will be executed. My code is working properly for AS01 transaction i.e. based on the Allocation Keys Depreciation Area (3 fields) is getting updated.
But for AS02 transaction my code is not working properly. Custom table value are not getting updated everytime.
When I went in debug mode... I am seeing field like KZ has to be updated... But I am not knowing excatly what's happening. when I go out of exit the internal table (field-symbol) is containing the value which I need but when it goes near to ASSET_MASTER_RECORD_UPDATE function module, the value are not what I am expecting, KZ field also set to space instead of 'U'.
(Enclosing the code below)
Your help will be highly appreciated.
Thanks & Regards,
Balaji Viswanath.
***********************************************************************
CONSTANTS DECLARATION
***********************************************************************
CONSTANTS: c_as01 TYPE sy-tcode VALUE 'AS01', "Create Asset master
c_as02 TYPE sy-tcode VALUE 'AS02', "Change Asset master
c_as11 TYPE sy-tcode VALUE 'AS11', "Create Asset Sub no
c_buch TYPE sy-ucomm VALUE 'BUCH', "Save button
c_class TYPE char4 VALUE '0000', "Local Statutory Class
c_1 TYPE /ds1/fi_mt_drate-ordnr VALUE '1', "Order no
c_2 TYPE /ds1/fi_mt_drate-ordnr VALUE '2', "Group no
c_30 TYPE anlb-afabe VALUE '30', "Local Stat. Class
c_02 TYPE anlb-afabe VALUE '02', "Tax Class
c_i TYPE ranlb-kz VALUE 'I',
c_u TYPE ranlb-kz VALUE 'U'.
***********************************************************************
INTERNAL TABLES DECLARACTION
***********************************************************************
DATA: lt_anla TYPE STANDARD TABLE OF ranla,
lt_anlb TYPE STANDARD TABLE OF ranlb,
***********************************************************************
WORK AREA DECLARACTION
***********************************************************************
lw_anla TYPE ranla,
lw_anlb TYPE ranlb,
***********************************************************************
VARIABLES DECLARACTION
***********************************************************************
l_afapl TYPE t093c-afapl, "Chart of depreciaton asset valuation
l_afasl TYPE /ds1/fi_mt_drate-afasl, "Depreciation key
l_ndjar TYPE /ds1/fi_mt_drate-ndjar, "Planned life in years
l_ndper TYPE /ds1/fi_mt_drate-ndper, "Planned life in Period
l_fld_anla TYPE char30 VALUE '(SAPLAIST)XANLA[]', "ANLA Table
l_fld_anlb TYPE char30 VALUE '(SAPLAIST)XANLB[]'. "ANLB Table
***********************************************************************
FIELD-SYMBOLS DECLARACTION
***********************************************************************
FIELD-SYMBOLS: <fs_anla> TYPE STANDARD TABLE,
<fs_anlb> TYPE STANDARD TABLE.
Check the transaction codes.
IF sy-tcode = c_as01 OR
sy-tcode = c_as02 OR
sy-tcode = c_as11.
If user click Save button.
IF sy-ucomm = c_buch.
ASSIGN (l_fld_anla) TO <fs_anla>.
MOVE <fs_anla> TO lt_anla.
CLEAR lw_anla.
READ TABLE lt_anla INTO lw_anla INDEX 1.
If ANLA-ORD41 is blank, return an error message.
IF lw_anla-ord41 = space.
MESSAGE ID '/DS1/A' TYPE 'A' NUMBER '014'
WITH 'Please enter Local Statutory Class'(001).
ELSEIF lw_anla-ord41 = c_class.
Select Chart of depreciaton from Company codes in Asset Accounting.
CLEAR l_afapl.
SELECT SINGLE afapl
INTO l_afapl
FROM t093c
WHERE bukrs = lw_anla-bukrs.
Select Depreciation Key from ANKB table (BDATU not used).
CLEAR: l_afasl, l_ndjar, l_ndper.
SELECT afasl ndjar ndper
INTO (l_afasl, l_ndjar, l_ndper)
FROM ankb
UP TO 1 ROWS
WHERE anlkl = lw_anla-anlkl AND
afapl = l_afapl AND
afabe = c_30.
ENDSELECT.
If not found display error message.
IF sy-subrc <> 0.
MESSAGE ID '/DS1/A' TYPE 'A' NUMBER '014'
WITH 'Depreciation terms not maintained for'(003)
lw_anla-anlkl.
LEAVE.
ELSE.
If found, update ANLB table.
Assign ANLB table to field symbol.
ASSIGN (l_fld_anlb) TO <fs_anlb>.
MOVE <fs_anlb> TO lt_anlb.
LOOP AT lt_anlb INTO lw_anlb.
If Real depreciation area is 30.
IF lw_anlb-afabe = c_30.
Assign Depreciation key, Planned useful life in years, period.
lw_anlb-afasl = l_afasl.
lw_anlb-ndjar = l_ndjar.
lw_anlb-ndper = l_ndper.
MODIFY lt_anlb
FROM lw_anlb
TRANSPORTING afasl ndjar ndper. "kz.
ENDIF.
ENDLOOP.
IF sy-tcode = c_as02.
LOOP AT lt_anlb INTO lw_anlb.
lw_anlb-kz = c_u.
MODIFY lt_anlb FROM lw_anlb INDEX sy-tabix.
ENDLOOP.
ENDIF.
<fs_anlb>[] = lt_anlb[].
ENDIF. "IF sy-subrc <> 0.
Should work only if Evaluation group 1 <> 00000 AND <> SPACE.
ELSE.
Select Chart of depreciaton from Company codes in Asset Accounting.
CLEAR l_afapl.
SELECT SINGLE afapl
INTO l_afapl
FROM t093c
WHERE bukrs = lw_anla-bukrs.
Select Depreciation Key from Depreciation Rate Substitution table.
CLEAR: l_afasl, l_ndjar, l_ndper.
SELECT SINGLE afasl ndjar ndper
INTO (l_afasl, l_ndjar, l_ndper)
FROM /ds1/fi_mt_drate
WHERE afapl = l_afapl AND
ordnr = c_1 AND
ord4x = lw_anla-ord41.
If not found display error message.
IF sy-subrc <> 0.
MESSAGE ID '/DS1/A' TYPE 'A' NUMBER '014'
WITH 'Depreciation terms not maintained for'(003)
lw_anla-ord41.
LEAVE.
ELSE.
If found, update ANLB table.
Assign ANLB table to field symbol.
ASSIGN (l_fld_anlb) TO <fs_anlb>.
MOVE <fs_anlb> TO lt_anlb.
LOOP AT lt_anlb INTO lw_anlb.
If Real depreciation area is 30.
IF lw_anlb-afabe = c_30.
Assign Depreciation key, Planned useful life in years, period.
lw_anlb-afasl = l_afasl.
lw_anlb-ndjar = l_ndjar.
lw_anlb-ndper = l_ndper.
MODIFY lt_anlb
FROM lw_anlb
TRANSPORTING afasl ndjar ndper. "kz.
ENDIF.
ENDLOOP.
IF sy-tcode = c_as02.
LOOP AT lt_anlb INTO lw_anlb.
lw_anlb-kz = c_u.
MODIFY lt_anlb FROM lw_anlb INDEX sy-tabix.
ENDLOOP.
ENDIF.
<fs_anlb>[] = lt_anlb[].
ENDIF. "IF sy-subrc <> 0.
ENDIF. "IF lw_anla-ord41 = space.
If ANLA-ORD42 is blank, return an error message.
IF lw_anla-ord42 = space.
MESSAGE ID '/DS1/A' TYPE 'A' NUMBER '014'
WITH 'Please enter Local Tax Class'(002).
LEAVE.
ELSEIF lw_anla-ord42 = c_class.
Select Chart of depreciaton from Company codes in Asset Accounting.
CLEAR l_afapl.
SELECT SINGLE afapl
INTO l_afapl
FROM t093c
WHERE bukrs = lw_anla-bukrs.
Select Depreciation Key from ANKB table (BDATU not used).
CLEAR: l_afasl, l_ndjar, l_ndper.
SELECT afasl ndjar ndper
INTO (l_afasl, l_ndjar, l_ndper)
FROM ankb
UP TO 1 ROWS
WHERE anlkl = lw_anla-anlkl AND
afapl = l_afapl AND
afabe = c_02.
ENDSELECT.
If not found display error message.
IF sy-subrc <> 0.
MESSAGE ID '/DS1/A' TYPE 'A' NUMBER '014'
WITH 'Depreciation terms not maintained for'(003)
lw_anla-anlkl.
LEAVE.
ELSE.
If found, update ANLB table.
Assign ANLB table to field symbol.
ASSIGN (l_fld_anlb) TO <fs_anlb>.
MOVE <fs_anlb> TO lt_anlb.
LOOP AT lt_anlb INTO lw_anlb.
If Real depreciation area is 02.
IF lw_anlb-afabe = c_02.
Assign Depreciation key, Planned useful life in years, period.
lw_anlb-afasl = l_afasl.
lw_anlb-ndjar = l_ndjar.
lw_anlb-ndper = l_ndper.
MODIFY lt_anlb
FROM lw_anlb
TRANSPORTING afasl ndjar ndper. "kz.
ENDIF.
ENDLOOP.
IF sy-tcode = c_as02.
LOOP AT lt_anlb INTO lw_anlb.
lw_anlb-kz = c_u.
MODIFY lt_anlb FROM lw_anlb INDEX sy-tabix.
ENDLOOP.
ENDIF.
<fs_anlb>[] = lt_anlb[].
ENDIF. "IF sy-subrc <> 0.
Should work only if Evaluation group 2 <> 00000.
ELSE.
Select Chart of depreciaton from Company codes in Asset Accounting.
CLEAR l_afapl.
SELECT SINGLE afapl
INTO l_afapl
FROM t093c
WHERE bukrs = lw_anla-bukrs.
Select Depreciation Key from Depreciation Rate Substitution table.
CLEAR: l_afasl, l_ndjar, l_ndper.
SELECT SINGLE afasl ndjar ndper
INTO (l_afasl, l_ndjar, l_ndper)
FROM /ds1/fi_mt_drate
WHERE afapl = l_afapl AND
ordnr = c_2 AND
ord4x = lw_anla-ord42.
If not found display error message.
IF sy-subrc <> 0.
MESSAGE ID '/DS1/A' TYPE 'A' NUMBER '014'
WITH 'Depreciation terms not maintained for'(003)
lw_anla-ord42.
LEAVE.
ELSE.
If found, update ANLB table.
Assign ANLB table to field symbol.
ASSIGN (l_fld_anlb) TO <fs_anlb>.
MOVE <fs_anlb> TO lt_anlb.
LOOP AT lt_anlb INTO lw_anlb.
If Real depreciation area is 02.
IF lw_anlb-afabe = c_02.
Assign Depreciation key, Planned useful life in years, period.
lw_anlb-afasl = l_afasl.
lw_anlb-ndjar = l_ndjar.
lw_anlb-ndper = l_ndper.
MODIFY lt_anlb
FROM lw_anlb
TRANSPORTING afasl ndjar ndper. "kz.
ENDIF.
ENDLOOP.
IF sy-tcode = c_as02.
LOOP AT lt_anlb INTO lw_anlb.
lw_anlb-kz = c_u.
MODIFY lt_anlb FROM lw_anlb INDEX sy-tabix.
ENDLOOP.
ENDIF.
<fs_anlb>[] = lt_anlb[].
ENDIF. "IF sy-subrc <> 0.
ENDIF. "IF lw_anla-ord42 = space.
ENDIF. "IF sy-ucomm = 'BUCH'.
ENDIF. "IF sy-tcode = 'AS01'