ABAP Development, PLM Enterprise Asset Management (EAM)/Plant Maintenance (PM)

Displaying Plant Maintenance Order Plan/Actual Line Item Wise

I had a client requirement where i was asked to show Plant Maintenance Order Plan/Actual (line item wise) side by side like below.

Note : Code “Mat” represents material item, and code “Ser” represents service item.

Read More: SAP ABAP 7.4 Certification Preparation Guide

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.

Below is my entire code for reference

Report ZXXXX

type-pools : slis, kaep.

tables : viaufkst,resb.

include : <cl_alv_control>.

include : <ICON>.

*alv declaration *************************

data : wa_fcat1 type lvc_s_fcat,
       it_fcat1 type lvc_t_fcat.

data : wa_fcat2 type lvc_s_fcat,
       it_fcat2 type lvc_t_fcat.

data : wa_layout1 type lvc_s_layo.

data : wa_sort1 type lvc_s_sort,
       it_sort1 type lvc_t_sort.

data : wa_listheader1 type slis_listheader,
       it_listheader1 TYPE slis_t_listheader.

data : v_repid1 type sy-repid.

data : wa_title1 type lvc_title.

data : r_ucomm type sy-ucomm,
       rs_selfield type slis_selfield,
       rs_lineinfo type slis_lineinfo.

data : wt type lvc_s_scol,
       ct type lvc_t_scol.

*******Data and Internal Table declaration**********************

data : BEGIN OF wa_viaufkst,
       aufnr type viaufkst-aufnr,
       equnr type viaufkst-equnr,
       auart type viaufkst-auart,    "order type whether PM10 or PM80 or PM85
       autyp type viaufkst-autyp,
       ktext type viaufkst-ktext,    "order text
       erdat type viaufkst-erdat,
       rsnum type viaufkst-rsnum,     "reservation number
       objnr type viaufkst-objnr,
       werks type viaufkst-werks,
       ftrmi type viaufkst-ftrmi,      "actual release date
       prctr type viaufkst-prctr,      "profit center
       kostl type viaufkst-kostl,      "cost center
       vaplz type viaufkst-vaplz,      "main work center
       ZZ_VERNR type viaufkst-zz_vernr,    "person responsible number
       aufpl type viaufkst-aufpl,          "routing number of operations in the order
       END OF wa_viaufkst.
data : it_viaufkst like TABLE OF wa_viaufkst.

data : temp_viaufkst like wa_viaufkst.

data : BEGIN OF wa_resb,
       aufnr type resb-aufnr,
       rsnum type resb-rsnum,
       rspos type resb-rspos,
       xloek type resb-xloek,
       kzear type resb-kzear,
       werks type resb-werks,
       matnr type resb-matnr,
       bdmng type resb-bdmng,
       meins type resb-meins,
       enmng type resb-enmng,
       enwrt type resb-enwrt,
       shkzg type resb-shkzg,
       objnr type resb-objnr,
       bwart type resb-bwart,
       gpreis type resb-gpreis,
       gsber type resb-gsber,
       postp type resb-postp,
       saknr type resb-saknr,     "G/L Account Number
       aufpl type resb-aufpl,
       aplzl type resb-aplzl,
       END OF wa_resb.
data : it_resb like TABLE OF wa_resb.

data : wa_resb1 like wa_resb,
       it_resb1 like TABLE OF wa_resb.

data : BEGIN OF wa_jest,
       objnr type jest-objnr,
       stat type jest-stat,
       inact type jest-inact,
       chgnr type jest-chgnr,
       END OF wa_jest.
data : it_jest like TABLE OF wa_jest.

Data : wa_skat type skat,
       it_skat type STANDARD TABLE OF skat.

data : wa_makt type makt,
       it_makt type TABLE OF makt.

data : temp_resb like wa_resb.

data : BEGIN OF wa_resb2,
       matnr type resb-matnr,
       rsnum type resb-rsnum,
       rspos type resb-rspos,
       bdmng type resb-bdmng,
       meins type resb-meins,
       gpreis type resb-gpreis,
       enmng type resb-enmng,
       enwrt type resb-enwrt,
       saknr type resb-saknr,
       END OF wa_resb2.
data : it_resb2 like TABLE OF wa_resb2.

data : lv_bdmng type resb-bdmng,
       lv_bdmng_cost type resb-gpreis.

data : BEGIN OF wa_fin,
       aufnr type viaufkst-aufnr,
       rsnum type resb-rsnum,
       rspos type resb-rspos,
       code type c LENGTH 20,        "Mat/Serv

       packno type ml_esll-packno,
       introw type ml_esll-introw,
       extrow type ml_esll-extrow,

       matnr type resbdget-matnr,    "material/ service number
       matxt type resbdget-matxt,    "material/service description
       meins type resbdget-meins,
       postp type resbdget-postp,    "Item Category

       bdmng type resbdget-bdmng,    "plan qty
       pcost type resbdget-gpreis,   "plan cost

       enmng type resbdget-enmng,    "actual qty
       acost type resbdget-enwrt,    "actual cost

       pln_packno type ml_esll-pln_packno,
       pln_introw type ml_esll-pln_introw,

       saknr type resbdget-saknr,
       stext type skat-txt20,      "cost element text
       END OF wa_fin.

data : it_fin like TABLE OF wa_fin.

data : BEGIN OF wa_afvc,
       aufpl type afvc-aufpl,
       aplzl type afvc-aplzl,
       vornr type afvc-vornr,
       steus type afvc-steus,
       ltxa1 type afvc-ltxa1,
       loekz type afvc-loekz,
       objnr type afvc-objnr,
       banfn type afvc-banfn,
       bnfpo type afvc-bnfpo,
       packno type afvc-packno,
       END OF wa_afvc.
data : it_afvc like TABLE OF wa_afvc.

*data : BEGIN OF wa_eslh,
*       packno TYPE eslh-packno,
*       ebeln TYPE eslh-ebeln,
*       ebelp type eslh-ebelp,
*       del type eslh-del,
*       END OF wa_eslh.
*data : it_eslh like TABLE OF wa_eslh.
*
*
*data : BEGIN OF wa_esll,
*       srvpos type esll-srvpos,               " Activity Number
*       packno type esll-packno,               " Package number
*       introw type esll-introw,               " Line Number
*       extrow type esll-extrow,
*       menge  type esll-menge,                " Quantity with Sign
*       meins  type esll-meins,                " Base Unit of Measure
*       brtwr  type esll-brtwr,                " Gross Price
*       netwr  type esll-netwr,
*       ktext1 type esll-ktext1,                " Short Text
*       tbtwr  type esll-tbtwr,                 " Gross Price
*       kstar  type esll-kstar,                 "cost element
*       END OF wa_esll.
*data : it_esll like TABLE OF wa_esll.

data : BEGIN OF wa_pesll,             "Plan esll table
       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,         " Quantity with Sign
       meins type ml_esll-meins,         " Base Unit of Measure
       brtwr type ml_esll-brtwr,          "Gross price
       netwr type ml_esll-netwr,
       ktext1 type ml_esll-ktext1,
       pln_packno type ml_esll-pln_packno,     "source package number (used to match with actuals)
       pln_introw type ml_esll-pln_introw,                           "(used to match with actuals)
       fpackno type ml_esll-fpackno,       "packno from table AFVC is passed to this field
       tbtwr type ml_esll-tbtwr,         "Gross price
       mapno type ml_esll-mapno,         "Mapping Field f. PACKNO, INTROW at Item Level for Commitment
       END OF wa_pesll.
data : it_pesll like TABLE OF wa_pesll.

data : BEGIN OF wa_aufm,
       aufnr type aufm-aufnr,
       mblnr type aufm-mblnr,
       mjahr type aufm-mjahr,
       zeile type aufm-zeile,  "item in material document
       budat type aufm-budat,
       bwart type aufm-bwart,
       matnr type aufm-matnr,
       lifnr type aufm-lifnr,
       shkzg type aufm-shkzg,
       dmbtr type aufm-dmbtr,   "price
       erfmg type aufm-erfmg,   "qty
       erfme type aufm-erfme,   "units
       ebeln type aufm-ebeln,
       ebelp type aufm-ebelp,
       rsnum type aufm-rsnum,
       rspos type aufm-rspos,
       sakto type aufm-sakto,
       aufpl type aufm-aufpl,
       aplzl type aufm-aplzl,
       END OF wa_aufm.
data : it_aufm like TABLE OF wa_aufm.

data : wa_aufm1 like wa_aufm,
       it_aufm1 like TABLE OF wa_aufm1.

data : BEGIN OF wa_ekbe,
       ebeln type ekbe-ebeln,
       ebelp type ekbe-ebelp,
       zekkn type ekbe-zekkn,
       vgabe type ekbe-vgabe,    "9=service entry sheet, 1=goods receipt, 2=invoice receipt
       gjahr type ekbe-gjahr,
       belnr type ekbe-belnr,
       buzei type ekbe-buzei,
       bwart type ekbe-bwart,  "101 = goods receipt
       srvpos type ekbe-srvpos,  "service number
       packno type ekbe-packno,
       introw type ekbe-introw,
       menge type ekbe-menge,
       dmbtr type ekbe-dmbtr,
       lfbnr type ekbe-lfbnr,   "invoice number
       lfpos type ekbe-lfpos,   "invoice item

       pln_packno type ml_esll-pln_packno,       "match this with packno of actuals(very imp)
       pln_introw type ml_esll-pln_introw,       "match this with introw of actuals(very imp)
       END OF wa_ekbe.
data : it_ekbe like TABLE OF wa_ekbe.

data : BEGIN OF wa_sesll,            "service entry sheet 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_sesll.
data : it_sesll like TABLE OF wa_sesll.

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.

data : lv_amqty type aufm-erfmg,
       lv_amcost type aufm-dmbtr,
       lv_asqty type ekbe-menge,      "actual service qty
       lv_ascost type ekbe-dmbtr.     "actual service cost

*sel screen declaration ****************************************
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.

 SELECTION-SCREEN skip 1.

 SELECT-OPTIONS : so_aufnr for viaufkst-aufnr.

 SELECTION-SCREEN skip 1.

SELECTION-SCREEN END OF BLOCK b1.

*****************************************************************

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 get_plan_details.          "get material and services plan details

PERFORM get_actual_details.        "get material and services actual details

PERFORM match_plan_actuals.

PERFORM main_alv_display.

FORM GET_PLAN_DETAILS .

if it_viaufkst[] is NOT INITIAL.

  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.

  loop at it_resb into wa_resb.

   if wa_resb-shkzg eq 'S'.              "If shkzg eq 'S' then negative qty

     wa_resb-bdmng = -1 * wa_resb-bdmng.
*     wa_resb-enmng = -1 * wa_resb-enmng.
*     wa_resb-enwrt = -1 * wa_resb-enwrt.

   endif.

    MODIFY it_resb FROM wa_resb TRANSPORTING bdmng . "enmng enwrt.

endloop.

*from here remove manually deleted material components(this code is used inorder to differentiate between manually deletd and CLSD or TECH orders)*****

if it_resb[] is NOT INITIAL.

   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 ''.

   Select * from skat
            into table it_skat
            FOR ALL ENTRIES IN it_resb
            where saknr eq it_resb-saknr
            and SPRAS = 'EN'
            and KTOPL = '4000' .

   select * FROM makt
            into TABLE it_makt
            FOR ALL ENTRIES IN it_resb
            WHERE matnr eq it_resb-matnr
            and spras eq 'EN'.

 endif.

 loop at it_resb into wa_resb.

   loop at it_jest into wa_jest WHERE objnr eq wa_resb-objnr.

     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)

       delete it_resb WHERE objnr eq wa_resb-objnr.

     endif.

   endloop.

endloop.

 sort it_viaufkst by aufnr.

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.

      loop at it_resb INTO wa_resb WHERE aufnr eq temp_viaufkst-aufnr.

         APPEND wa_resb to it_resb1.

      endloop.

       loop at it_resb1 INTO wa_resb1.

           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.

           READ TABLE it_makt into wa_makt with key matnr = wa_fin-matnr.
           if sy-subrc = 0.
           wa_fin-matxt = wa_makt-maktx.
           endif.

          wa_fin-meins = wa_resb1-meins.    "units
          wa_fin-postp = wa_resb1-postp.

          wa_fin-bdmng = wa_resb1-bdmng.                               "item wise plan qty for a particular material
          wa_fin-pcost = ( wa_resb1-bdmng * wa_resb1-gpreis ).          "item wise plan cost for a particular material = qty * price

          wa_fin-saknr = wa_resb1-saknr.

          READ TABLE it_skat into wa_skat with key saknr = wa_fin-saknr.
          if sy-subrc = 0.
          wa_fin-stext = wa_skat-txt20.
          endif.

          APPEND wa_fin to it_fin.

       endloop.


    ENDAT.

 endloop.

*to get services plan qty and plan costs ****************************************

 if it_viaufkst[] is NOT INITIAL.

   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.

*if it_afvc[] is NOT INITIAL.
*
*  select  packno
*          ebeln
*          ebelp
*          del         "deletion indicator
*          FROM eslh
*          INTO TABLE it_eslh
*          FOR ALL ENTRIES IN it_afvc
*          WHERE fpackno eq it_afvc-packno
*          and del ne 'X'.        "deletion indicator.
*
* endif.


*if it_eslh[] is NOT INITIAL.
*
*  SELECT  packno                  " Package number
*          introw                  " Line Number
*          extrow
*          srvpos                  " Activity Number
*          menge                   " Quantity with Sign
*          meins                   " Base Unit of Measure
*          brtwr                   " Gross Price
*          netwr
*          ktext1                  " Short Text
*          tbtwr                   " Gross Price
*          kstar                   "cost element
*          FROM esll
*          INTO CORRESPONDING FIELDS OF TABLE it_esll
*          FOR ALL ENTRIES IN it_eslh
*          WHERE packno EQ it_eslh-packno
*          AND srvpos NE ''.
*
*endif.

*instead of using ESLH and ESLL let us directly fetch from ML_ESLL(view for ESLH and ESLL)*********

 if it_afvc[] is NOT INITIAL.

   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.

 sort it_viaufkst by aufnr.

loop at it_viaufkst INTO wa_viaufkst.

  temp_viaufkst = wa_viaufkst.

   at new aufnr.

     clear : wa_fin.

   loop at it_afvc INTO wa_afvc WHERE aufpl eq temp_viaufkst-aufpl.


        loop at it_pesll INTO wa_pesll WHERE fpackno eq wa_afvc-packno.

            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.

*             wa_fin-pln_packno = wa_pesll-pln_packno.     "these two are required for actuals only
*             wa_fin-pln_introw = wa_pesll-pln_introw.

             APPEND wa_fin to it_fin.

            endif.

         endloop.

     endloop.

   ENDAT.

 endloop.

 ENDFORM.    "end form of Get_Plan_Details

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.

loop at it_aufm into wa_aufm.

  if wa_aufm-matnr is NOT INITIAL and wa_aufm-shkzg eq 'S'.   "make material devolutions negative (check that BWARt eq '261' receipt for order)

     wa_aufm-dmbtr = -1 * wa_aufm-dmbtr.
     wa_aufm-erfmg = -1 * wa_aufm-erfmg.

  endif.

    MODIFY it_aufm FROM wa_aufm TRANSPORTING dmbtr erfmg.

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*

 loop at it_aufm INTO wa_aufm.

   if wa_aufm-rsnum is INITIAL and wa_aufm-aufpl is NOT INITIAL.

      READ TABLE it_resb INTO wa_resb with key aufpl = wa_aufm-aufpl
                                               aplzl = wa_aufm-aplzl.

            if sy-subrc = 0.

               wa_aufm-rsnum = wa_resb-rsnum.
               wa_aufm-rspos = wa_resb-rspos.

            endif.

       MODIFY it_aufm FROM wa_aufm TRANSPORTING rsnum rspos.

    endif.

 endloop.

*end of code to update rsnum***************************

*end of material actuals*******************************************************

***from here get services actuals**********************************************

it_aufm1[] = it_aufm[].

delete it_aufm1 WHERE ebeln is INITIAL and ebelp is INITIAL.

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.

delete it_ekbe WHERE lfbnr is INITIAL.

 if it_ekbe[] is NOT INITIAL.

    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_sesll   "service entry sheet esll table
           FOR ALL ENTRIES IN it_ekbe
           WHERE ebeln eq it_ekbe-lfbnr
           and del ne 'X'
           and srvpos ne ''.

 endif.

 if it_aufm1[] is NOT INITIAL.

    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)


 loop at it_ekbe INTO wa_ekbe.


   READ TABLE it_sesll INTO wa_sesll with key packno = wa_ekbe-packno
                                              introw = wa_ekbe-introw.

     if sy-subrc = 0.


        READ TABLE it_poesll INTO wa_poesll with key packno = wa_sesll-pln_packno
                                                     introw = wa_sesll-pln_introw.

           if sy-subrc = 0.

              wa_ekbe-pln_packno = wa_poesll-pln_packno.
              wa_ekbe-pln_introw = wa_poesll-pln_introw.

           endif.

      endif.

     MODIFY it_ekbe FROM wa_ekbe TRANSPORTING pln_packno pln_introw.

 endloop.

ENDFORM.               " GET_ACTUAL_DETAILS


FORM MATCH_PLAN_ACTUALS .


sort it_fin by aufnr code.

sort it_aufm by aufnr.


loop at it_fin INTO wa_fin.

   clear : lv_amqty, lv_amcost.

   if wa_fin-rsnum is NOT INITIAL and wa_fin-rspos is NOT INITIAL.

      loop at it_aufm INTO wa_aufm WHERE rsnum eq wa_fin-rsnum and rspos eq wa_fin-rspos.

          lv_amqty = lv_amqty + wa_aufm-erfmg.        "lv_amqty = actual material qty
          lv_amcost = lv_amcost + wa_aufm-dmbtr.      "lv_amcost = actual material price

       endloop.

     wa_fin-enmng = lv_amqty.       "enmng = actual qty
     wa_fin-acost = lv_amcost.      "acost = actual cost

     MODIFY it_fin FROM wa_fin TRANSPORTING enmng acost.

    endif.

 endloop.

 loop at it_fin INTO wa_fin.

    clear : lv_asqty, lv_ascost.

    if wa_fin-packno is NOT INITIAL and wa_fin-introw is NOT INITIAL.

       loop at it_ekbe INTO wa_ekbe WHERE pln_packno eq wa_fin-packno and pln_introw eq wa_fin-introw.

            lv_asqty = lv_asqty + wa_ekbe-menge.       "lv_asqty = actual service qty
            lv_ascost = lv_ascost + wa_ekbe-dmbtr.     "lv_ascost = actual service cost

       endloop.

       wa_fin-enmng = lv_asqty.
       wa_fin-acost = lv_ascost.

      MODIFY it_fin FROM wa_fin TRANSPORTING enmng acost.

    endif.

 endloop.

ENDFORM.                  " MATCH_PLAN_ACTUALS


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.

****layout declaration *****************************
wa_layout1-zebra = 'X'.
wa_layout1-CWIDTH_OPT = 'X'.
*wa_lvc_layout-GRID_TITLE = 'Project Type Wise - WBS Details'.

v_repid1 =  sy-repid.

wa_title1 = 'PM Order Plan/Actuals Line Item WIse'.

*sort declaration **********************************
REFRESH it_sort1.
clear  : wa_sort1.

wa_sort1-fieldname = 'AUFNR'.
wa_sort1-subtot = 'X'.
APPEND wa_sort1 to it_sort1.

*******************************************************

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
  EXPORTING
   I_CALLBACK_PROGRAM                = v_repid1
*   I_CALLBACK_USER_COMMAND           = ' '
*    I_CALLBACK_TOP_OF_PAGE            = 'TOP_OF_PAGE'
*   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
*   I_CALLBACK_HTML_END_OF_LIST       = ' '
   I_GRID_TITLE                      = wa_title1
   IS_LAYOUT_LVC                     = wa_layout1
   IT_FIELDCAT_LVC                   = it_fcat1
*   IT_EXCLUDING                      =
    IT_SORT_LVC                       = it_sort1
   I_DEFAULT                         = 'X'
   I_SAVE                            = 'A'
*   IS_VARIANT                        =
*   IT_EVENTS                         =
  TABLES
    T_OUTTAB                          = it_fin
 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.

REFRESH it_fin[].

ENDFORM.                    " MAIN_ALV_DISPLAY

Leave a Reply

Your email address will not be published. Required fields are marked *