Professional Documents
Culture Documents
Oder Actual
Oder Actual
Oder Actual
Note: Code “Mat” represents material item, and code “Ser” represents service item.
I did not find any standard transaction which shows maintenance order plan/actual side by side as shown above.
Standard Transaction CJI3 gives only actual values(but not plan/actual values side by side) as a result i was forced
to develop a Z-report.
i did not get any solution here, but after going through various tables i found some solution.It may not be a great
discovery but i thought sharing the solution would be useful to some community members (although saving data in
tables depends on various customization procedures which vary from organization to organization) my intention is to
show how the tables are linked.
For a given PM Order i could get the plan qty , plan cost (of material components) from RESB table and Service
components from AFVC , ESLH and ESLL table , for getting actual’s i used table AUFM.
if i pass Order number to AUFNR field i am able to get corresponding actuals of that particular Order. In order to
show plan and actual’s side by side i need to link by some reference,for material components i used RSNUM , RSPOS
fields to link plan and actual’s(i.e for qty and cost),where as for linking services i.e for linking services in Plan with
services in actual’s i could not find a unique matching field. Here i encountered a problem, but after observing all the
fields i was able to match plan actuals (match PLN_PACKNO , PLAN_INTROW of actuals with PACKNO and INTROW of
plan).
For actuals i directly passed EBELN, EBELP from AUFM to ML_ESLL-EBELN and ML_ESLL_EBELP ,but again i
encountered some problem the cost posted in the field DMBTR of table ML_ESLL(view of ESLH and ESLL) is base
value its not included with with tax which is given while creating the Purchase Order.
However this problem was overcome by using table EKBE(where the DMBTR field stored services actual cost
including tax) but again the PACKNO of EKBE did not matched with PACKNO of plan details , again to overcome this,
linked LFBNR(entry sheet no) of EKBE with EBELN of ML_ESLL and the corresponding PACKNO is linked with
PLN_PACKNO of ML_ESLL by passing EBELN and EBLEP from AUFM table, finally linked PLN_PACKNO , PLN_INTROW
of actual with PACKNO and INTROW of plan data.
Report ZXXXX
tables : viaufkst,resb.
include : <cl_alv_control>.
include : <ICON>.
data : BEGIN OF wa_poesll, "purchase order esll table(by passing ebeln, ebelp of AUFM to table ML_ESLL)
packno type ml_esll-packno,
introw type ml_esll-introw,
extrow type ml_esll-extrow,
del type ml_esll-del,
srvpos type ml_esll-srvpos,
menge type ml_esll-menge,
brtwr type ml_esll-brtwr,
ktext1 type ml_esll-ktext1,
pln_packno type ml_esll-pln_packno, "these 2 are important, these pln_packno and pln_introw should be
matched with packno introw of Plan values
pln_introw type ml_esll-pln_introw,
act_menge type ml_esll-act_menge, "Purchase Order: Entered Quantity
fpackno type ml_esll-fpackno,
ebeln type ml_esll-ebeln,
ebelp type ml_esll-ebelp,
mapno type ml_esll-mapno,
END OF wa_poesll.
data : it_poesll like TABLE OF wa_poesll.
SELECTION-SCREEN skip 1.
SELECTION-SCREEN skip 1.
*****************************************************************
START-OF-SELECTION.
select aufnr
equnr
auart "order type whether PM10 or PM80 or PM85
autyp
ktext "order text
erdat
rsnum "reservation number
objnr
werks
ftrmi "actual release date
prctr "profit center
kostl "cost center
vaplz "main work center
ZZ_VERNR "person responsible number
aufpl
from viaufkst
into CORRESPONDING FIELDS OF TABLE it_viaufkst
WHERE aufnr in so_aufnr.
PERFORM match_plan_actuals.
PERFORM main_alv_display.
FORM GET_PLAN_DETAILS .
select rsnum
rspos
xloek "deletion indicator
kzear "final issue for material
werks
matnr
bdmng
meins
enmng
enwrt "value withdrawn
shkzg
aufnr
objnr
bwart "movement type
gpreis "price
gsber
postp "Item category L = Stock, N = Non stock
saknr "G/L account number
aufpl
aplzl
FROM resb
into CORRESPONDING FIELDS OF TABLE it_resb
FOR ALL ENTRIES IN it_viaufkst
WHERE rsnum eq it_viaufkst-rsnum.
endif.
wa_resb-bdmng = -1 * wa_resb-bdmng.
* wa_resb-enmng = -1 * wa_resb-enmng.
* wa_resb-enwrt = -1 * wa_resb-enwrt.
endif.
endloop.
*from here remove manually deleted material components(this code is used inorder to differentiate between
manually deletd and CLSD or TECH orders)*****
select objnr
stat
inact
chgnr
FROM jest
into TABLE it_jest
FOR ALL ENTRIES IN it_resb
WHERE objnr eq it_resb-objnr
and inact eq ''.
endif.
if wa_jest-stat eq 'I0013'. "Deletion Flag indicator (DLT) (this flag is set for manually deleted items bot not
for CLSD and TECO status)
endif.
endloop.
endloop.
loop at it_viaufkst INTO wa_viaufkst. "loop to get Plan for all materials
temp_viaufkst = wa_viaufkst.
at new aufnr.
REFRESH : it_resb1.
clear : wa_fin.
endloop.
wa_fin-aufnr = temp_viaufkst-aufnr.
wa_fin-code = 'Mat'.
wa_fin-rsnum = wa_resb1-rsnum.
wa_fin-rspos = wa_resb1-rspos.
wa_fin-matnr = wa_resb1-matnr.
wa_fin-saknr = wa_resb1-saknr.
endloop.
ENDAT.
endloop.
*to get services plan qty and plan costs ****************************************
select aufpl
aplzl
vornr "activity
ltxa1 "activity short text
steus "control key(PM03 = for services, PM01 = for material)
loekz "for PM order loekz is set when corresponding activity is deleted manually(but not for CLSD or TECO
status)
packno "very imp to get services
from afvc
into CORRESPONDING FIELDS OF TABLE it_afvc
FOR ALL ENTRIES IN it_viaufkst
WHERE aufpl eq it_viaufkst-aufpl
and steus eq 'PM03'
and loekz ne 'X'.
endif.
*instead of using ESLH and ESLL let us directly fetch from ML_ESLL(view for ESLH and ESLL)*********
select packno
introw
extrow
del
srvpos
menge " Quantity with Sign
meins " Base Unit of Measure
brtwr "Gross price
netwr
ktext1
pln_packno "source package number (used to match with actuals)
pln_introw "(used to match with actuals)
fpackno "packno from table AFVC is passed to this field
tbtwr "Gross price
mapno "Mapping Field f. PACKNO, INTROW at Item Level for Commitment
FROM ml_esll
into CORRESPONDING FIELDS OF TABLE it_pesll "plan esll table
FOR ALL ENTRIES IN it_afvc
WHERE fpackno eq it_afvc-packno
and del ne 'X'
and srvpos ne ''.
endif.
temp_viaufkst = wa_viaufkst.
at new aufnr.
clear : wa_fin.
if sy-subrc = 0.
wa_fin-aufnr = temp_viaufkst-aufnr.
wa_fin-code = 'Ser'.
wa_fin-packno = wa_pesll-packno.
wa_fin-introw = wa_pesll-introw.
wa_fin-extrow = wa_pesll-extrow.
wa_fin-matnr = wa_pesll-srvpos.
wa_fin-matxt = wa_pesll-ktext1.
wa_fin-meins = wa_pesll-meins.
wa_fin-bdmng = wa_pesll-menge.
wa_fin-pcost = wa_pesll-brtwr.
endif.
endloop.
endloop.
ENDAT.
endloop.
FORM GET_ACTUAL_DETAILS .
select mblnr
mjahr
zeile
budat
bwart
matnr
lifnr
shkzg
dmbtr "price
erfmg "qty
erfme "units
ebeln
ebelp
aufnr "PM order number
rsnum
rspos
sakto
aufpl
aplzl
FROM aufm
into CORRESPONDING FIELDS OF TABLE it_aufm
WHERE aufnr in so_aufnr.
wa_aufm-dmbtr = -1 * wa_aufm-dmbtr.
wa_aufm-erfmg = -1 * wa_aufm-erfmg.
endif.
endloop.
*for some records in AUFM only aufpl, aplzl is updated but not rsnum and rspos...below code is used to update
rsnum, rspos where only aufpl , aplzl is updated*
if sy-subrc = 0.
wa_aufm-rsnum = wa_resb-rsnum.
wa_aufm-rspos = wa_resb-rspos.
endif.
endif.
endloop.
it_aufm1[] = it_aufm[].
if it_aufm1[] is NOT INITIAL. "first get details from EKBE(PO History table)
select ebeln
ebelp
zekkn
vgabe "9=service entry sheet, 1=goods receipt, 2=invoice receipt
gjahr
belnr
buzei
bwart "101 = goods receipt
menge
dmbtr
lfbnr "invouce number
lfpos "invoice item
srvpos "service number
packno
introw
FROM ekbe
into CORRESPONDING FIELDS OF TABLE it_ekbe
FOR ALL ENTRIES IN it_aufm1
WHERE ebeln eq it_aufm1-ebeln
and ebelp eq it_aufm1-ebelp
and vgabe eq '1'. "here vgabe = 1 taken(goods recepit) because some times invoice is
parked(vgabe=P) instead of 9.
endif.
endif.
select packno
introw
extrow
del
srvpos
menge
brtwr
ktext1
pln_packno "these 2 are important, these pln_packno and pln_introw should be matched with packno
introw of Plan values
pln_introw
act_menge "Purchase Order: Entered Quantity
fpackno
ebeln
ebelp
mapno
FROM ml_esll
into CORRESPONDING FIELDS OF TABLE it_poesll "Purchase Order esll table
FOR ALL ENTRIES IN it_aufm1
WHERE ebeln eq it_aufm1-ebeln
and ebelp eq it_aufm1-ebelp
and del ne 'X'
and srvpos ne ''.
endif.
*now put every thing in to it_ekeb(i.e pln_packno, pln_introw of it_poesll into it_ekbe : so that pln_packno,
pln_introw can be matched with packno and introw of esll plan details)
if sy-subrc = 0.
if sy-subrc = 0.
wa_ekbe-pln_packno = wa_poesll-pln_packno.
wa_ekbe-pln_introw = wa_poesll-pln_introw.
endif.
endif.
endloop.
FORM MATCH_PLAN_ACTUALS .
loop at it_aufm INTO wa_aufm WHERE rsnum eq wa_fin-rsnum and rspos eq wa_fin-rspos.
endloop.
endif.
endloop.
loop at it_ekbe INTO wa_ekbe WHERE pln_packno eq wa_fin-packno and pln_introw eq wa_fin-introw.
endloop.
wa_fin-enmng = lv_asqty.
wa_fin-acost = lv_ascost.
endif.
endloop.
FORM MAIN_ALV_DISPLAY .
REFRESH it_fcat1.
clear wa_fcat1.
wa_fcat1-col_pos = 1.
wa_fcat1-fieldname = 'AUFNR'.
wa_fcat1-tabname = 'IT_FIN'.
wa_fcat1-outputlen = 12.
wa_fcat1-coltext = 'PM Order No'.
wa_fcat1-style = ALV_STYLE_FONT_BOLD.
*wa_fcat1-just = 'C'.
wa_fcat1-emphasize = 'C601'.
APPEND wa_fcat1 to it_fcat1.
clear wa_fcat1.
clear wa_fcat1.
wa_fcat1-col_pos = 2.
wa_fcat1-fieldname = 'CODE'.
wa_fcat1-tabname = 'IT_FIN'.
wa_fcat1-outputlen = 10.
wa_fcat1-coltext = 'Code'.
*wa_fcat1-style = ALV_STYLE_FONT_BOLD.
*wa_fcat1-just = 'C'.
*wa_fcat1-emphasize = 'C501'.
APPEND wa_fcat1 to it_fcat1.
clear wa_fcat1.
clear wa_fcat1.
wa_fcat1-col_pos = 3.
wa_fcat1-fieldname = 'MATNR'.
wa_fcat1-tabname = 'IT_FIN'.
wa_fcat1-outputlen = 18.
wa_fcat1-coltext = 'Mat/Ser Code'.
wa_fcat1-style = ALV_STYLE_FONT_BOLD.
*wa_fcat1-just = 'C'.
wa_fcat1-emphasize = 'C601'.
APPEND wa_fcat1 to it_fcat1.
clear wa_fcat1.
clear wa_fcat1.
wa_fcat1-col_pos = 4.
wa_fcat1-fieldname = 'MATXT'.
wa_fcat1-tabname = 'IT_FIN'.
wa_fcat1-outputlen = 40.
wa_fcat1-coltext = 'Mat/Ser Desc'.
wa_fcat1-style = ALV_STYLE_FONT_BOLD.
*wa_fcat1-just = 'C'.
*wa_fcat1-emphasize = 'C501'.
APPEND wa_fcat1 to it_fcat1.
clear wa_fcat1.
clear wa_fcat1.
wa_fcat1-col_pos = 5.
wa_fcat1-fieldname = 'MEINS'.
wa_fcat1-tabname = 'IT_FIN'.
wa_fcat1-outputlen = 4.
wa_fcat1-coltext = 'Units'.
*wa_fcat1-style = ALV_STYLE_FONT_BOLD.
*wa_fcat1-just = 'C'.
*wa_fcat1-emphasize = 'C501'.
APPEND wa_fcat1 to it_fcat1.
clear wa_fcat1.
clear wa_fcat1.
wa_fcat1-col_pos = 6.
wa_fcat1-fieldname = 'BDMNG'.
wa_fcat1-tabname = 'IT_FIN'.
wa_fcat1-outputlen = 15.
wa_fcat1-coltext = 'Plan Qty'.
*wa_fcat1-style = ALV_STYLE_FONT_BOLD.
*wa_fcat1-just = 'C'.
wa_fcat1-emphasize = 'C601'.
APPEND wa_fcat1 to it_fcat1.
clear wa_fcat1.
clear wa_fcat1.
wa_fcat1-col_pos = 7.
wa_fcat1-fieldname = 'PCOST'.
wa_fcat1-tabname = 'IT_FIN'.
wa_fcat1-outputlen = 15.
wa_fcat1-coltext = 'Plan Cost'.
*wa_fcat1-style = ALV_STYLE_FONT_BOLD.
*wa_fcat1-just = 'C'.
wa_fcat1-emphasize = 'C601'.
wa_fcat1-do_sum = 'X'.
APPEND wa_fcat1 to it_fcat1.
clear wa_fcat1.
clear wa_fcat1.
wa_fcat1-col_pos = 8.
wa_fcat1-fieldname = 'ENMNG'.
wa_fcat1-tabname = 'IT_FIN'.
wa_fcat1-outputlen = 15.
wa_fcat1-coltext = 'Act Qty'.
*wa_fcat1-style = ALV_STYLE_FONT_BOLD.
*wa_fcat1-just = 'C'.
wa_fcat1-emphasize = 'C401'.
APPEND wa_fcat1 to it_fcat1.
clear wa_fcat1.
clear wa_fcat1.
wa_fcat1-col_pos = 9.
wa_fcat1-fieldname = 'ACOST'.
wa_fcat1-tabname = 'IT_FIN'.
wa_fcat1-outputlen = 15.
wa_fcat1-coltext = 'Act Cost'.
*wa_fcat1-style = ALV_STYLE_FONT_BOLD.
*wa_fcat1-just = 'C'.
wa_fcat1-emphasize = 'C401'.
wa_fcat1-do_sum = 'X'.
APPEND wa_fcat1 to it_fcat1.
clear wa_fcat1.
v_repid1 = sy-repid.
wa_sort1-fieldname = 'AUFNR'.
wa_sort1-subtot = 'X'.
APPEND wa_sort1 to it_sort1.
*******************************************************
REFRESH it_fin[].