Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

*&---------------------------------------------------------------------*
* Report:              : ZPROCESSORD
* AUTHOR               : Aveek Ghose                                   *
* SUPPLIER             :                                           *
*======================================================================*
* CHANGE HISTORY LOG                                                   *
*----------------------------------------------------------------------*
* MOD. NO.|  DATE   | NAME   | CORRECTION NUMBER | CHANGE REFERENCE   #*
*----------------------------------------------------------------------*
* MOD-001 |DD/MM/YYYY| XXXXXX | XXXXXXXXXX       | XXXXXXXXX           *
* DESCRIPTION:                                                         *
*----------------------------------------------------------------------*
* MOD-002 |DD/MM/YYYY| XXXXXX | XXXXXXXXXX       | XXXXXXXXX           *
* DESCRIPTION:                                                         *
*----------------------------------------------------------------------*
****** Top Include for Declarations
* include ZPROCESSORDTOP.

*&---------------------------------------------------------------------*
*&  Include           ZPROCESSORDTOP
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&  Include           ZPROCESSORDTOP
*&---------------------------------------------------------------------*
REPORT  ZPROCESSORD LINE-SIZE 125 MESSAGE-ID ZDEV.

DATA : wa_afko TYPE afko, " Order header data PP orders
       wa_cssl TYPE cssl. " Cost Center / Activity Type

*--------------------Ranges -----------------------------------------*
TYPES: BEGIN OF ty_r_bwart,
         sign TYPE char1,
         option TYPE char2,
         low  TYPE bwart,
         high TYPE bwart,
       END OF ty_r_bwart.

DATA: i_r_bwart TYPE STANDARD TABLE OF ty_r_bwart INITIAL SIZE 0,
      wa_bwart  TYPE ty_r_bwart.

TYPES : ty_stprs  TYPE p LENGTH 8 DECIMALS 2,               "MOD-101
*       ty_stprs  TYPE p LENGTH 8 DECIMALS 3,               "MOD-101
        ty_stprs1 TYPE p LENGTH 8 DECIMALS 2,               "MOD-101
        ty_menge  TYPE p LENGTH 8 DECIMALS 6,               "MOD-101
        ty_vgwrt(9) TYPE p DECIMALS 3.                      "MOD-101

*------------------Constants Declaration-----------------------------*
CONSTANTS:
  c_x          TYPE char1    VALUE 'X',   " Constant X
  c_objtyp     TYPE cr_objty VALUE 'A',   " Object Type
  c_txt_dlv    TYPE char4    VALUE 'DLV', " Order Status Delivered
  c_txt_cnf    TYPE char4    VALUE 'CNF', " Order status confirmed
  c_back       TYPE syucomm  VALUE 'BACK'," Back
  c_trde       TYPE syucomm  VALUE 'TRDE'," Order Details
  c_trpi       TYPE syucomm  VALUE 'TRPI'," Choose
  c_trsl       TYPE syucomm  VALUE 'TRSL'," Choose
  c_sums       TYPE syucomm  VALUE 'SUMS'," Summary Report
  c_qty        TYPE syucomm  VALUE 'QTY', " Quantities
  c_fisc       TYPE syucomm  VALUE 'FISC'," Fiscal Values
  c_kgm        TYPE syucomm  VALUE 'KGM', " KGM
  c_ordu       TYPE syucomm  VALUE 'ORDU'," Order UOM
  c_zero       TYPE syucomm  VALUE 'ZERO'," Zero Loss
  c_std        TYPE syucomm  VALUE 'STD', " Non Zero Loss
  c_sign       TYPE char1    VALUE 'I',    " Range Sign
  c_option     TYPE char2    VALUE 'EQ',   " Range Option
  c_movm_low_261 TYPE bwart  VALUE '261',  " Range-low value OF movement
  c_movm_low_262 TYPE bwart  VALUE '262',  " Range-low value OF movement
  c_movm_low_531 TYPE bwart  VALUE '531',  " Range-low value OF movement
  c_movm_low_532 TYPE bwart  VALUE '532',  " Range-low value OF movement
  c_tlevel_2     TYPE char2  VALUE '02',   " Tree level
  c_plus        TYPE char15  VALUE 'SYM_PLUS_FOLDER',
  c_minus       TYPE char16  VALUE 'SYM_MINUS_FOLDER',
  c_text1       TYPE char14  VALUE 'NODELIST-TEXT1',
  c_trep        TYPE syucomm  VALUE 'TREP'," Expand subtree
  c_trcm        TYPE syucomm  VALUE 'TRCM'," Collapse subtree
  c_exit        TYPE syucomm  VALUE '&F15', "Exit
  c_101         TYPE bwart    VALUE '101',  "Movement type
  c_102         TYPE bwart    VALUE '102',  "Movement type
  c_teco        TYPE char4    VALUE 'TECO',
  c_s           TYPE shkzg    VALUE 'S',  "Debit/Credit Indicator

  c_0           TYPE char1    VALUE '0',
  c_100         TYPE int4     VALUE 100,
  c_perc        TYPE char1    VALUE '%',
  c_brac        TYPE char1    VALUE ')',

*" BEGIN OF MOD-101
  c_zeroval    TYPE ty_vgwrt VALUE '0.000',

  c_detl       TYPE syucomm  VALUE 'DETL'," Detail Report
  c_phas       TYPE syucomm  VALUE 'PHAS'," Phase Report

  c_tlevel_3    TYPE char2  VALUE '03',   " Tree level
  c_tlevel_4    TYPE char2  VALUE '04',   " Tree level

  c_40          TYPE int4     VALUE 40,

  c_1           TYPE int4     VALUE 1,
  c_2           TYPE int4     VALUE 2,
  c_3           TYPE int4     VALUE 3,
  c_4           TYPE int4     VALUE 4,
  c_5           TYPE int4     VALUE 5,
  c_6           TYPE int4     VALUE 6,
  c_8           TYPE int4     VALUE 8,
  c_10          TYPE int4     VALUE 10,
  c_12          TYPE int4     VALUE 12,
  c_14          TYPE int4     VALUE 14,
  c_18          TYPE int4     VALUE 18,
  c_20          TYPE int4     VALUE 20,
  c_22          TYPE int4     VALUE 22,
  c_24          TYPE int4     VALUE 24,
  c_25          TYPE int4     VALUE 25,
  c_26          TYPE int4     VALUE 26,
  c_30          TYPE int4     VALUE 30,
  c_33          TYPE int4     VALUE 33,
  c_35          TYPE int4     VALUE 35,
  c_37          TYPE int4     VALUE 37,
  c_42          TYPE int4     VALUE 42,
  c_45          TYPE int4     VALUE 45,

  c_1_1         TYPE char3    VALUE '1_1',
  c_2_1         TYPE char3    VALUE '2_1',
  c_2_2         TYPE char3    VALUE '2_2',
  c_3_1         TYPE char3    VALUE '3_1',
  c_3_2         TYPE char3    VALUE '3_2',
  c_3_3         TYPE char3    VALUE '3_3',
  c_3_4         TYPE char3    VALUE '3_4',
  c_4_1         TYPE char3    VALUE '4_1',
  c_4_2         TYPE char3    VALUE '4_2',
  c_5_1         TYPE char3    VALUE '5_1',
  c_5_2         TYPE char3    VALUE '5_2',
  c_6_1         TYPE char3    VALUE '6_1',
  c_6_2         TYPE char3    VALUE '6_2',

*  c_1_1         TYPE char3    VALUE '1_1',
*  c_1           TYPE int4     VALUE 1,
*  c_40          TYPE int4     VALUE 40,
*  c_2_1         TYPE char3    VALUE '2_1',
*  c_3_1         TYPE char3    VALUE '3_1',
*  c_2           TYPE int4     VALUE 2,
*  c_22          TYPE int4     VALUE 22,
*  c_15          TYPE int4     VALUE 15,
*  c_25          TYPE int4     VALUE 25,
*  c_20          TYPE int4     VALUE 20,
*  c_3           TYPE int4     VALUE 3,
*  c_4           TYPE int4     VALUE 4,
*  c_2_2         TYPE char3    VALUE '2_2',
*  c_3_3         TYPE char3    VALUE '3_3',
*  c_3_4         TYPE char3    VALUE '3_4',
*  c_6_1         TYPE char3    VALUE '6_1',
*  c_3_2         TYPE char3    VALUE '3_2',
*  C_35          TYPE int4     VALUE  32,
*  C_36          TYPE int4     VALUE  36,
*  c_4_1         TYPE char3    VALUE '4_1',
*  c_18          TYPE int4     VALUE 18,
*  c_30          TYPE int4     VALUE 30,
*  c_35_1        TYPE int4     VALUE 35,
*  c_6           TYPE int4     VALUE 6,
*  c_19          TYPE int4     VALUE 19,
*  c_29          TYPE int4     VALUE 29,
*  c_21          TYPE int4     VALUE 21,
*  c_12          TYPE int4     VALUE 12,
*  c_33          TYPE int4     VALUE 30, "33,
*  c_37          TYPE int4     VALUE 37,
*  c_10          TYPE int4     VALUE 10,
*  c_42          TYPE int4     VALUE 42,
*  c_3_5         TYPE char3    VALUE '3_5',
*  c_45          TYPE int4     VALUE 45,
*  c_44          TYPE int4     VALUE 44,
*  c_3_6         TYPE char3    VALUE '3_6',
*  c_26          TYPE int4     VALUE 26,
*  c_5           TYPE int4     VALUE 5,
*"END OF MOD-101

  c_m           TYPE char1    VALUE 'M',
  c_y           TYPE char1    VALUE 'Y',
  c_hyp         TYPE char1    VALUE '-',
  c_a           TYPE char1    VALUE 'A', "Object type
  c_000         TYPE versn    VALUE '000', "Version
  c_prog        TYPE sycprog  VALUE '/EUR/RGBPTR_PRO_ORDER_VARIANCE'.

*------------------Data Declaration----------------------------------*
DATA:
  v_waers           TYPE waers,                " Currency Key
  v_uom             TYPE char5,
  v_msehi           TYPE msehi VALUE 'SGL',
  v_werks           TYPE werks_d,                           "#EC NEEDED
  v_output_text(60) TYPE c,
  v_plant_effic(3)  TYPE n,
  v_dummy(4)        TYPE c,         " Dummy variable for Ord. Status
  flg_color(1)      TYPE c,
***Begin of MOD-001
   v_ucomm  TYPE syucomm,
   v_ucomm1 TYPE syucomm,
   v_stat1  TYPE j_istat,
   v_stat2  TYPE j_istat,
   v_conv_rc TYPE char1,
   v_rep     TYPE syucomm,
   v_oldf    TYPE char3,
   v_newf    TYPE char3,

   v_prs     TYPE ty_stprs1,
****End of MOD-001

****mod-03.
   v_meins  TYPE msehi. "to store c_kgm value.
****mod-03.

*------------------ Types Declaration -------------------------------*
TYPES:
* Type for Work Center Header
  BEGIN OF ty_crhd,
    objid TYPE cr_objid,         " Object ID of the resource
    arbpl TYPE arbpl,            " Work center
    vgwts TYPE vorgschl,         " Std. Value Key            "MOD-101
  END OF   ty_crhd,

* Type for Cost Center Master Data
  BEGIN OF ty_csks,
    kokrs TYPE kokrs,            " Controlling Area
    kostl TYPE kostl,            " Cost Center
  END OF   ty_csks,

* Type for Assignment of Work Center to Cost Center
  BEGIN OF ty_crco,
    objty TYPE cr_objty,
    objid TYPE cr_objid,
    kokrs TYPE kokrs,
    kostl TYPE kostl,
    lstar TYPE lstar,                                       "MOD-101
  END OF ty_crco,

* Type for process order with order status text
  BEGIN OF ty_order_status_text,
    aufnr TYPE aufnr,
    sttxt(100) TYPE c,
  END OF ty_order_status_text,

* Type for Order status texts
  BEGIN OF ty_tj02t,
    istat TYPE j_istat, " Status number " MOD-101+
    txt04 TYPE j_txt04,
  END OF   ty_tj02t,

* Type for plant Materials
  BEGIN OF ty_marc,
    matnr TYPE matnr,
    werks TYPE werks_d,
    kausf TYPE kausf,
  END OF ty_marc,

*" BEGIN OF MOD-101
* Type for Orders
  BEGIN OF ty_orders,
    aufnr      TYPE aufnr,      " Order Number

    werks      TYPE werks_d,    " Plant
    kokrs      TYPE kokrs,      " Controlling Area

    objnr      TYPE j_objnr,    " Object number

    gltrp      TYPE sydatum,    " Date
    gstrp      TYPE co_gstrp,   " Basic start Date

    rsnum      TYPE rsnum,      " Reservation number

    gamng      TYPE gamng,      " Total order quantity
    gmein      TYPE meins,      " order uom

    plnbez     TYPE matnr,      " Material Number

    plnty      TYPE plnty,      " Task list type
    plnnr      TYPE plnnr,      " Key for task list group
    plnal      TYPE plnal,      " Group counter

    stlst      TYPE stlst,      " BOM Status
    stlty      TYPE stlty,      " BOM category
    stlnr      TYPE stnum,      " Bill of material
    sdatv      TYPE datuv,      " Valid-From Date
    stlal      TYPE stalt,      " Alternative BOM
    stlan      TYPE stlan,      " BOM Usage

    aufpl      TYPE co_aufpl,   " Routing no for operations in order
    zaehl      TYPE cim_count,  " Internal counter
    rueck      TYPE co_rueck,   " Confirmation number of operation

    auart      TYPE aufart,     " Order Type

** Begin of change on 31-05-2005
    aufld      TYPE co_aufld,
    " Date of BOM Explosion/Routing Transfer
** End of change on 31-05-2005

    capid      TYPE capid,      " BOM Application

    menge      TYPE menge_d,    " Quantity
    erfmg      TYPE erfmg,      " Quantity
    lmnga      TYPE ru_lmnga,   " Yield currently to be confirmed

    maktx      TYPE maktx,      " Material Description
    bmeng      TYPE basmn,      " Base Quantity
    bmein      TYPE basme,      " Base unit of measure for BOM
    kausf      TYPE kausf,      " Component scrap in percent
* Qty in base UoM
   blmnga      TYPE ru_lmnga,   " Yield currently to be confirmed
   bmenge      TYPE menge_d,    " GR Quantity
   bgamng      TYPE gamng,      " Total Order Qty
   bbmeng      TYPE basmn,      " Base Quantity in Base UoM
* UoM
    gruom      TYPE meins,      " gr uom
    cfuom      TYPE meins,      " conf uom
    bsuom      TYPE meins,      " base uom
    gewei      TYPE gewei,      " weight uom
    ntgew      TYPE ntgew,

    del,
  END OF ty_orders,

* Type for BOM Appln
  BEGIN OF ty_bomapp,
    werks  TYPE werks_d,    " Plant
    auart  TYPE aufart,     " Order Type
    capid  TYPE capid,      " BOM Appln
  END OF ty_bomapp,

* Type for Operation within an order
  BEGIN OF ty_afvc,
    aufpl TYPE co_aufpl,
    aplzl TYPE co_aplzl,

    ltxa1 TYPE ltxa1,

    plnkn TYPE plnkn,
    plnty TYPE plnty,
    plnnr TYPE plnnr,
    zaehl TYPE cim_count,

    vornr TYPE vornr,
    steus TYPE steus,
    arbid TYPE cr_objid,

    rueck TYPE co_rueck,

    phflg TYPE phflg,
    sumnr TYPE sumkntnr,
    vgwts TYPE vorgschl,
    lar01 TYPE lstar,
    lar02 TYPE lstar,
    lar03 TYPE lstar,
    lar04 TYPE lstar,
    lar05 TYPE lstar,
    lar06 TYPE lstar,

    aufnr TYPE aufnr,
    lmnga TYPE lmnga,
    cfuom TYPE meins,
    gmein TYPE meins,
  END OF ty_afvc,

* Type for quantities/dates/values in the operations
  BEGIN OF ty_afvv,
    aufpl TYPE co_aufpl, " Routing number of operations in the order
    aplzl TYPE co_aplzl, " General counter for order

    meinh TYPE vorme,    " Activity unit of measure
    bmsch TYPE bmsch,    " Base Quantity

    umren TYPE cp_umren,
    umrez TYPE cp_umrez,

    vge01 TYPE vgwrteh,  " Unit of measure for the standard value
    vgw01 TYPE vgwrt,    " Standard value
    vge02 TYPE vgwrteh,  " Unit of measure for the standard value
    vgw02 TYPE vgwrt,    " Standard value
    vge03 TYPE vgwrteh,  " Unit of measure for the standard value
    vgw03 TYPE vgwrt,    " Standard value
    vge04 TYPE vgwrteh,  " Unit of measure for the standard value
    vgw04 TYPE vgwrt,    " Standard value
    vge05 TYPE vgwrteh,  " Unit of measure for the standard value
    vgw05 TYPE vgwrt,    " Standard value
    vge06 TYPE vgwrteh,  " Unit of measure for the standard value
    vgw06 TYPE vgwrt,    " Standard value

    mgvrg TYPE mgvrg,    " Operation Quantity
    lmnga TYPE lmnga,    " Total Yield Confirmed
    gmnga TYPE gmnga,    " Yield Confirmed in order UoM

    ism01 TYPE co_rumng, " Previously confirmed activity
    ism02 TYPE co_rumng, " Previously confirmed activity
    ism03 TYPE co_rumng, " Previously confirmed activity
    ism04 TYPE co_rumng, " Previously confirmed activity
    ism05 TYPE co_rumng, " Previously confirmed activity
    ism06 TYPE co_rumng, " Previously confirmed activity

    ssavd TYPE ssavd,    " Latest scheduled start: Execution (date)

    gamng  TYPE gamng,
    bbmsch TYPE bmsch,
    prduom TYPE meins,
    bsuom  TYPE vorme,
  END OF ty_afvv,

* Type for Document Segment: Material
  BEGIN OF ty_mseg,
    aufnr TYPE aufnr,
    aufpl TYPE co_aufpl,
    aplzl TYPE co_aplzl,
    matnr TYPE matnr,

    mblnr TYPE mblnr,
    mjahr TYPE mjahr,
    zeile TYPE mblpo,

    bwart TYPE bwart,

    werks TYPE werks_d,
    lgort TYPE lgort_d,
    charg TYPE charg_d,

    menge TYPE menge_d,
    meins TYPE meins,

    erfmg TYPE erfmg,
    erfme TYPE erfme,

    rsnum TYPE rsnum,
    rspos TYPE rspos,
    rsart TYPE rsart,

    bmenge TYPE menge_d,
    bmeins TYPE meins,
    gewei  TYPE gewei,
    ntgew  TYPE ntgew,
  END OF ty_mseg,

* Type for Document Segment: Material - Sum of Qtys
  BEGIN OF ty_mseg_sum,
    aufnr TYPE aufnr,
    aufpl TYPE co_aufpl,
    aplzl TYPE co_aplzl,
    matnr TYPE matnr,

    meins  TYPE meins,

    erfmg  TYPE erfmg,
    erfmg1 TYPE erfmg,
    erfmg2 TYPE erfmg,
    erfmg5 TYPE erfmg,
    erfme  TYPE erfme,

    bmenge  TYPE menge_d,
    bmenge1 TYPE menge_d,
    bmenge2 TYPE menge_d,
    bmenge5 TYPE menge_d,
    bmeins  TYPE meins,

    gewei   TYPE gewei,
    bwart   TYPE bwart,                                     "23-06-2005
  END OF ty_mseg_sum,

* Type for Order completion confirmations
  BEGIN OF ty_afru,
    aufnr TYPE aufnr,
    rueck TYPE co_rueck,

    gmnga TYPE ru_gmnga,
    lmnga TYPE ru_lmnga,

    gmein TYPE meins,
    meinh TYPE ru_vorme,

    meilr TYPE meilr,
    stokz TYPE co_stokz,
    rueck_mst TYPE co_rueck,

    aufpl TYPE co_aufpl,
    aplzl TYPE co_aplzl,
  END OF ty_afru,

* Type for Reservation/dependent requirements
  BEGIN OF ty_resb,
    rsnum TYPE rsnum,
    rspos TYPE rspos,
    rsart TYPE rsart,
    xloek TYPE xloek,

    matnr TYPE matnr,
    werks TYPE werks_d,

    bdmng TYPE bdmng,
    meins TYPE meins,
    shkzg TYPE shkzg,

    aufnr TYPE aufnr,
    dumps TYPE dumps,

    aufpl TYPE co_aufpl,
    vornr TYPE vornr,
    aplzl TYPE co_aplzl,

    postp  TYPE postp,
    kzkup  TYPE kzkup,
    rgekz  TYPE rgekz,
    ausch  TYPE cs_e_ausch,

    stlty TYPE stlty,
    stlnr TYPE stnum,
    stlkn TYPE stlkn,
    stpoz TYPE cim_count,

    bwart  TYPE bwart,          "Neel 30/06/2005

    bbdmng TYPE bdmng,
    bmeins TYPE meins,

    flagp  TYPE char1,                                      " MOD-GT1+
  END OF ty_resb,

* Individual materials for production order.
  BEGIN OF ty_ordmats,
    aufnr TYPE aufnr,                     " Order number
    aufpl TYPE co_aufpl,
    aplzl TYPE co_aplzl,
    matnr TYPE matnr,                     " Component material
    mtart TYPE mtart,                     " material type
    stufe TYPE histu,
*>>NEEL 4/6/2005
    wegxx TYPE cs_e_vwegx,
    ttidx TYPE ttidx,
    vwegx TYPE wegxx,
*<<NEEL 4/6/2005
    ojtxb TYPE ojtxb,                     " parent object text
    ojtxp TYPE ojtxp,                     " object text

    menge  TYPE menge_d,                  " component qty
    menges TYPE menge_d,                  " component qty with scrap
    mengez TYPE menge_d,                  " component qty with zero loss
    meins  TYPE meins,                     " component uom

    xmeng  TYPE cs_e_xbmng,                " BoM Base Qty (Next Level)
    xmengs TYPE cs_e_xbmng,      " BoM Base Qty (Next Level) w scrap
    xmengz TYPE cs_e_xbmng,      " BoM Base Qty (Next Level) w zero loss
    xmein  TYPE cs_e_xbmen,                " BoM Base UoM (Next Level)

    mnglg  TYPE cs_e_mnglg,                " Calc. Comp. Qty in Base UoM
    mnglgs TYPE cs_e_mnglg,         " Calc.Comp.Qty in Base UoM w scrap
    mnglgz TYPE cs_e_mnglg,
    " Calc.Comp.Qty in Base UoM w zero loss
    mmein  TYPE meins,                     " base UoM

    stprs TYPE stprs,                     " std price
    peinh TYPE peinh,                     " price unit

    postp  TYPE postp,                    " Item category ( BOM )
    msign  TYPE cs_e_msign,               " +/- sign
    rgekz  TYPE rgekz,                    " back flush indicator

    ausch  TYPE cs_e_ausch,               " component scrap
    kausf  TYPE cs_e_kausf,               " component scrap %
*    yyzero TYPE /glb/rgtpt_yyzero,        " Zero loss conversion factor

    bom    TYPE char1,
    bomd   TYPE char1,
    byprod TYPE char1,                    " by product indicator

    stlty  TYPE stlty,
    stlnr  TYPE stnum,
    stlkn  TYPE stlkn,
    stpoz  TYPE cim_count,
  END OF ty_ordmats,

* Type for Material Production unit
  BEGIN OF ty_marc1,
    matnr TYPE matnr,
    werks TYPE werks_d,
    frtme TYPE frtme,
  END OF ty_marc1,

* Type for Material Production unit
  BEGIN OF ty_mara,
    matnr TYPE matnr,
    mtart TYPE mtart,
    meins TYPE meins,
    gewei TYPE gewei,
    ntgew TYPE ntgew,
  END OF ty_mara,

* Type for parameter ID
  BEGIN OF ty_param,
    vgwts TYPE vorgschl,
    par01 TYPE paramid,
    par02 TYPE paramid,
    par03 TYPE paramid,
    par04 TYPE paramid,
    par05 TYPE paramid,
    par06 TYPE paramid,
  END OF ty_param,

* Type for keyword for parameter ID
  BEGIN OF ty_param_key,
    parid TYPE paramid,
    txtlg TYPE paraltxt,
  END OF ty_param_key,

  BEGIN OF ty_mbew1,
    matnr TYPE matnr,
    bwkey TYPE bwkey,
    stprs TYPE stprs,
    peinh TYPE peinh,
  END OF ty_mbew1,

  BEGIN OF ty_hier_order,
    aufnr   TYPE aufnr,      " Order number
* Dates
    gltrp   TYPE sydatum,
    gstrp   TYPE sydatum,
* Material
    plnbez  TYPE matnr,      " Material Number
    maktx   TYPE maktx,      " Material desc
* Bottleneck Resource
    botlnck TYPE arbpl,      " bottleneck resorc
    resdesc TYPE ktext,      " resorc desc
* Efficiencies
    el_effc TYPE vgwrt,      " expected line effic
    ac_effc TYPE vgwrt,      " actual line effic
* Qty
    prdqty  TYPE gamng,      " PO qty displayed
    prduom  TYPE meins,      " PO UoM displayed
   bprdqty  TYPE gamng,

    lmnga   TYPE ru_lmnga,   " Yield currently to be confirmed
    menge   TYPE menge_d,    " GR Quantity
    erfmg   TYPE erfmg,      " GR Quantity
    gamng   TYPE gamng,      " Total Order Qty
    bmeng   TYPE basmn,      " Base Quantity in BOM
* Qty in base UoM
    blmnga  TYPE ru_lmnga,   " Yield currently to be confirmed
    bmenge  TYPE menge_d,    " GR Quantity
    bgamng  TYPE gamng,      " Total Order Qty
    bbmeng  TYPE basmn,      " Base Quantity in Base UoM
* Std price
    cstprs  TYPE stprs,      " Calc Price
    stprs   TYPE stprs,      " Std Price
    peinh   TYPE peinh,      " Price unit
* UoM
    gruom   TYPE meins,      " gr uom
    cfuom   TYPE meins,      " conf uom
    bsuom   TYPE meins,      " base uom
    frtme   TYPE frtme,      " production unit
    gewei   TYPE gewei,      " weight uom
    ntgew   TYPE ntgew,
  END OF ty_hier_order,

  BEGIN OF ty_hier_phase,
    aufnr   TYPE aufnr,

    aufpl   TYPE co_aufpl,
    aplzl   TYPE co_aplzl,

    vornr   TYPE vornr,

    ltxa1   TYPE ltxa1,
    steus   TYPE steus,
    rueck   TYPE co_rueck,

    arbid   TYPE arbid,
    arbpl   TYPE arbpl,
    ktext   TYPE cr_ktext,

    el_effc TYPE vgwrt,
    ac_effc TYPE vgwrt,

    vgwts   TYPE vorgschl,

    lmnga   TYPE lmnga,
    gmnga   TYPE gmnga,
    blmnga  TYPE lmnga,
    bgmnga  TYPE gmnga,

    prdqty  TYPE gamng,
    prduom  TYPE meins,
   bprdqty  TYPE gamng,

    cfuom   TYPE meins,
    bsuom   TYPE meins,
    gewei   TYPE gewei,
    ntgew   TYPE ntgew,

    runtime,
  END OF ty_hier_phase,

  BEGIN OF ty_hier_act,
    aufnr   TYPE aufnr,
    parxx   TYPE paramid,
    aufpl   TYPE co_aufpl,
    aplzl   TYPE co_aplzl,
    vornr   TYPE vornr,

    vgwts   TYPE vorgschl,

    mgvrg   TYPE mgvrg,
    bmsch   TYPE bmsch,
    meinh   TYPE vorme,

    bmgvrg  TYPE mgvrg,
    bbmsch  TYPE bmsch,
    bmeinh  TYPE vorme,

    txtxx   TYPE paraltxt,
* actual usage
    ismxx   TYPE ru_ismng,
    ilexx   TYPE co_ismngeh,
* std usage
    vgexx    TYPE vgwrteh,
    vgwxx    TYPE ty_vgwrt,

    tkgxx   TYPE tkgxxx,
    tkexx   TYPE tkexxx,

    togxx  TYPE togxxx,
    toexx  TYPE toexxx,

    actu    TYPE ty_stprs,
    stdu    TYPE ty_stprs,
    varu    TYPE ty_stprs,

    stdvar  TYPE ty_vgwrt,
    varper  TYPE co_rumng,

    cstprs  TYPE stprs,
    stprs   TYPE stprs,
    peinh   TYPE peinh,
  END OF ty_hier_act,

  BEGIN OF ty_hier_mat,
    aufnr   TYPE aufnr,
    matnr   TYPE matnr,
    byprod  TYPE char1,
    aufpl   TYPE co_aufpl,
    aplzl   TYPE co_aplzl,
    vornr   TYPE vornr,

    maktx   TYPE maktx,

    actusg  TYPE menge_d,
    stdusg  TYPE menge_d,
    stdusgs  TYPE menge_d,
    stdusgz  TYPE menge_d,

    stdvar  TYPE menge_d,
    varper  TYPE menge_d,

    kausf   TYPE kausf,
*    yyzero  TYPE /glb/rgtpt_yyzero,

    bsuom   TYPE meins,
    gruom   TYPE meins,
    gewei   TYPE gewei,
    ntgew   TYPE ntgew,
    bomuom  TYPE meins,

    cstprs  TYPE stprs,
    vstprs  TYPE ty_stprs,
    stprs   TYPE stprs,
    peinh   TYPE peinh,

    sumi    TYPE char1,

    bwart   TYPE bwart,                                     "23-05-2005
  END OF ty_hier_mat,

  BEGIN OF ty_hier_act_sum,
    parxx   TYPE paramid,
    txtxx   TYPE paraltxt,

    ismxx   TYPE ru_ismng,
    ilexx   TYPE co_ismngeh,

    vgexx   TYPE vgwrteh,
    vgwxx   TYPE ty_vgwrt,

    actu    TYPE ty_stprs,
    stdu    TYPE ty_stprs,

    varu    TYPE ty_stprs,
    stdvar  TYPE ty_vgwrt,
    varper  TYPE co_rumng,
  END OF ty_hier_act_sum,

  BEGIN OF ty_hier_mat_sum,
    matnr  TYPE matnr,
    maktx  TYPE maktx,

    actusg TYPE menge_d,
    actuom TYPE meins,

    stdusg TYPE menge_d,
    stduom TYPE meins,

    stdvar TYPE menge_d,
    varuom TYPE meins,

    astprs  TYPE ty_stprs,
    sstprs  TYPE ty_stprs,
    varprs  TYPE ty_stprs,

    varper TYPE menge_d,
  END OF ty_hier_mat_sum,

* Type for Order confirmations
  BEGIN OF ty_ord_conf,
    rueck TYPE co_rueck,
    rmzhl TYPE co_rmzhl,
    ism01 TYPE ru_ismng,
    ile01 TYPE co_ismngeh,
    ism02 TYPE ru_ismng,
    ile02 TYPE co_ismngeh,
    ism03 TYPE ru_ismng,
    ile03 TYPE co_ismngeh,
    ism04 TYPE ru_ismng,
    ile04 TYPE co_ismngeh,
    ism05 TYPE ru_ismng,
    ile05 TYPE co_ismngeh,
    ism06 TYPE ru_ismng,
    ile06 TYPE co_ismngeh,
    stokz TYPE co_stokz,
  END OF ty_ord_conf,

* Type for Parameters
  BEGIN OF ty_par,
    parxx TYPE paramid,
  END OF ty_par,

* Type for selection parameters for reading PLPO
  BEGIN OF ty_plpo_sel,
    plnty TYPE plnty,
    plnnr TYPE plnnr,
    plnkn TYPE plnkn,
    zaehl TYPE cim_count,
  END OF ty_plpo_sel,

* Type for selection parameters for reading AFRU
  BEGIN OF ty_afru_sel,
    rueck TYPE co_rueck,
  END OF ty_afru_sel,

* Type for Control Keys
  BEGIN OF ty_ckey,
    plnaw TYPE plnaw,
    steus TYPE steus,
    kalkz TYPE ck_kalkz,
  END OF ty_ckey,

* Type for object statuses
  BEGIN OF ty_obj_stat,
    objnr TYPE j_objnr, " Object number
    stat  TYPE j_istat, " Status number
  END OF ty_obj_stat,

  ty_t_stb TYPE STANDARD TABLE OF stpox
           WITH NON-UNIQUE DEFAULT KEY,

* Type for BOM data,
  BEGIN OF ty_bomdat,
    capid TYPE capid,   " BOM Application
    datuv TYPE datuv,   " Valid-From Date
    mtnrv TYPE matnr,   " Material
    stlal TYPE stalt,   " Alternative BOM
    stlan TYPE stlan,   " BOM Usage
    werks TYPE werks_d, " Plant

    tmat  TYPE cstmat,
    stb   TYPE ty_t_stb,
  END OF ty_bomdat,

  ty_t_bomdat TYPE SORTED TABLE OF ty_bomdat
              WITH UNIQUE KEY capid
                              datuv
                              mtnrv
                              stlal
                              stlan
                              werks,
** Type for Orders
*  BEGIN OF ty_orders,
*    aufnr      TYPE aufnr,      " Order Number
*    werks      TYPE werks_d,    " Plant
*    kokrs      TYPE kokrs,      " Controlling Area
*    objnr      TYPE j_objnr,    " Object number
*    gltrp      TYPE sydatum,    " Date
*    rsnum      TYPE rsnum,      " Reservation number
*    gamng      TYPE gamng,      " Total order quantity
*    gmein      TYPE meins,      " order uom
*    plnbez     TYPE matnr,      " Material Number
*    plnty      TYPE plnty,      " Task list type
*    plnnr      TYPE plnnr,      " Key for task list group
*    plnal      TYPE plnal,      " Group counter
*    stlst      TYPE stlst,      " BOM Status " MOD-001
*    stlty      TYPE stlty,      " BOM category
*    stlnr      TYPE stnum,      " Bill of material
*    stlal      TYPE stalt,      " Alternative BOM
*    aufpl      TYPE co_aufpl,   " Routing no for operations in order
*    zaehl      TYPE cim_count,  " Internal counter
*    rueck      TYPE co_rueck,   " Confirmation number of operation
*  END OF ty_orders,
*
** Type for Process orders details
*  BEGIN OF ty_pro_orders,
*    aufnr      TYPE aufnr,      " Order Number
*    werks      TYPE werks_d,    " Plant
*    kokrs      TYPE kokrs,      " Controlling Area
*    objnr      TYPE j_objnr,    " Object number
*    gltrp      TYPE sydatum,    " Date
*    rsnum      TYPE rsnum,      " Reservation number
*    gamng      TYPE gamng,      " Total order quantity
*    gmein      TYPE meins,      " order uom
*    plnbez     TYPE matnr,      " Material Number
*    plnty      TYPE plnty,      " Task list type
*    plnnr      TYPE plnnr,      " Key for task list group
*    plnal      TYPE plnal,      " Group counter
*    stlst      TYPE stlst,      " BOM Status " MOD-001
*    stlty      TYPE stlty,      " BOM category
*    stlnr      TYPE stnum,      " Bill of material
*    stlal      TYPE stalt,      " Alternative BOM
*    aufpl      TYPE co_aufpl,   " Routing no for operations in order
*    zaehl      TYPE cim_count,  " Internal counter
*    rueck      TYPE co_rueck,   " Confirmation number of operation
*    wdate      TYPE sydatum,    " System date
*    dayflg(1)  TYPE n,          " Day flag
*    pos1(3)    TYPE n,          " position
*    arbpl      TYPE arbpl,      " Work center
*    sttxt(100) TYPE c,          " Status text
*    menge      TYPE menge_d,    " Quantity
*    lmnga      TYPE ru_lmnga,   " Yield currently to be confirmed
*    arbid      TYPE objektid,   " Object ID
*    plnkn      TYPE plnkn,      " Number of the task list node
*    pl_efic(3) TYPE n,          " Plant effic
*    gruom      TYPE meins,      " gr uom
*    cfuom      TYPE meins,      " conf uom
*  END OF ty_pro_orders,

** Type for Operation within an order
*  BEGIN OF ty_afvc,
*    aufpl TYPE co_aufpl,
*    aplzl TYPE co_aplzl,
*    plnkn TYPE plnkn,
*    plnty TYPE plnty,
*    plnnr TYPE plnnr,
*    zaehl TYPE cim_count,
*    vornr TYPE vornr,
*    arbid TYPE cr_objid,
*    rueck TYPE co_rueck,
*    steus TYPE steus,
*    phflg TYPE phflg,
*  END OF ty_afvc,
*
** Type for quantities/dates/values in the operations
*  BEGIN OF ty_afvv,
*    aufpl TYPE co_aufpl, " Routing number of operations in the order
*    aplzl TYPE co_aplzl, " General counter for order
*    bmsch TYPE bmsch,    " Base Quantity
*    vgw02 TYPE vgwrt,    " Standard value
*    lmnga TYPE lmnga,    " Total Yield Confirmed
*    ism02 TYPE co_rumng, " Previously confirmed activity
*    ssavd TYPE ssavd,    " Latest scheduled start: Execution (date)
*  END OF ty_afvv,
*
** Type for Order Operatons
*  BEGIN OF ty_ordops,
*    aufnr TYPE aufnr,
*    aufpl TYPE co_aufpl,
*    aplzl TYPE co_aplzl,
*    plnkn TYPE plnkn,
*    plnty TYPE plnty,
*    plnnr TYPE plnnr,
*    zaehl TYPE cim_count,
*    vornr TYPE vornr,
*    arbid TYPE cr_objid,
*    rueck TYPE co_rueck,
*    ssavd TYPE ssavd,
*    plt_effic(3) TYPE n,
*    arbpl TYPE arbpl,
**********MOD-005**************
*    lmnga TYPE lmnga,
*    cfuom TYPE meins,
*********MOD-005**************
*  END   OF ty_ordops,
*
** Type for Document Segment: Material
*  BEGIN OF ty_mseg,
*    aufnr TYPE aufnr,
*    mblnr TYPE mblnr,
*    mjahr TYPE mjahr,
*    zeile TYPE mblpo,
*    matnr TYPE matnr,
*    bwart TYPE bwart,
*    menge TYPE menge_d,
*    meins TYPE meins,
**    sjahr TYPE mjahr,
**    smbln TYPE mblnr,
**    smblp TYPE mblpo,
*    rsnum TYPE rsnum,
*    rspos TYPE rspos,
*    rsart TYPE rsart,
***** Mod-002**********
*    erfmg TYPE erfmg,
*    erfme TYPE erfme,
**** Mod-002***********
*  END OF ty_mseg,
*
** Type for Order completion confirmations
*  BEGIN OF ty_afru,
*    aufnr TYPE aufnr,
*    rueck TYPE co_rueck,
*    gmnga TYPE ru_gmnga,
*    lmnga TYPE ru_lmnga,
*    gmein TYPE meins,
*    meinh TYPE ru_vorme,
*    meilr TYPE meilr,
*    stokz TYPE co_stokz,
*    rueck_mst TYPE co_rueck,
*  END   OF ty_afru,
*
** Type for Document Segment material
*  BEGIN OF ty_doc_segment,
*    aufnr TYPE aufnr,
*    mblnr TYPE mblnr,
*    mjahr TYPE mjahr,
*    zeile TYPE mblpo,
*    matnr TYPE matnr,
*    bwart TYPE bwart,
*    menge TYPE menge_d,
*    meins TYPE meins,
**    sjahr TYPE mjahr,
**    smbln TYPE mblnr,
**    smblp TYPE mblpo,
*    rsnum TYPE rsnum,
*    rspos TYPE rspos,
*    rsart TYPE rsart,
*  END OF ty_doc_segment,
*
** Type for linked documents prev_doc
*  BEGIN OF ty_prev_doc,
*    mblnr TYPE mblnr,
*    mjahr TYPE mjahr,
*    zeile TYPE mblpo,
*    sjahr TYPE mjahr,
*    smbln TYPE mblnr,
*    smblp TYPE mblpo,
*    rsnum TYPE rsnum,
*    rspos TYPE rspos,
*    rsart TYPE rsart,
*  END OF ty_prev_doc,
*
** Type for Issued materials
*  BEGIN OF ty_issued_mat,
*    aufnr TYPE aufnr,
*    rsnum TYPE rsnum,
*    rspos TYPE rspos,
*    rsart TYPE rsart,
*    matnr TYPE matnr,
*    menge TYPE menge_d,
*    meins TYPE meins,
*    stprs TYPE stprs,                     "std price
*    peinh TYPE peinh,                     "price uom
*  END OF ty_issued_mat,
*
** Type for Reservation/dependent requirements
*  BEGIN OF ty_reservations,
*    rsnum TYPE rsnum,
*    rspos TYPE rspos,
*    rsart TYPE rsart,
*    xloek TYPE xloek,
*    matnr TYPE matnr,
*    werks TYPE werks_d,
*    bdmng TYPE bdmng,
*    meins TYPE meins,
*    shkzg TYPE shkzg,
*    aufnr TYPE aufnr,
*    dumps TYPE dumps,
*    vornr TYPE vornr,
*    rgekz TYPE rgekz,
*    stlty TYPE stlty,
*    stlnr TYPE stnum,
*    stlkn TYPE stlkn,
*    stpoz TYPE cim_count,
*  END OF ty_reservations,
*
** Individual materials for production order.
*  BEGIN OF ty_ordmats,
*    aufnr TYPE aufnr,                     "Order number
*    matnr TYPE matnr,                     "Component material
*    vornr TYPE vornr,                     "Phase number
*    rsnum TYPE rsnum,                     "Reservation number
*    rspos TYPE rspos,                     "Reservation position
*    rsart TYPE rsart,
*    bdmng TYPE bdmng,                     "Component qty
*    menge TYPE menge_d,                   "Issued qty
*    stdqy TYPE bdmng,                     "component std qty
*    zloss TYPE bdmng,                     "comp zero loss qty
*    amein TYPE meins,                     "used uom
*    meins TYPE meins,                     "std uom
*    stprs TYPE stprs,                     "std price
*    peinh TYPE peinh,                     "price uom
*  END OF ty_ordmats,
*
** Type for BOM Item
*  BEGIN OF ty_stpo,
*    stlty TYPE stlty,
*    stlnr TYPE stnum,
*    stlkn TYPE stlkn,
*    stpoz TYPE cim_count,
*    meins TYPE kmpme,
*    menge TYPE kmpmg,
*    ausch TYPE kausf,
*    yyzero TYPE /glb/rgtpt_yyzero,
*  END OF ty_stpo,

** Type for Material Valuation
*  BEGIN OF ty_mat_valuation,
*    matnr TYPE matnr,
*    bwkey TYPE bwkey,
*    stprs TYPE stprs,
*    peinh TYPE peinh,
*  END OF ty_mat_valuation,

** Type for Order confirmations
*  BEGIN OF ty_ord_conf,
*    rueck TYPE co_rueck,
*    rmzhl TYPE co_rmzhl,
*    ism01 TYPE ru_ismng,
*    ism02 TYPE ru_ismng,
*    ism03 TYPE ru_ismng,
*    ism04 TYPE ru_ismng,
*    ism05 TYPE ru_ismng,
*    ism06 TYPE ru_ismng,
*    stokz TYPE co_stokz,
*  END OF ty_ord_conf,

** Type for activities
*BEGIN OF ty_sum_activity,
*  lar        TYPE lstar,
*  afru_ism   TYPE ru_ismng,
*  ism_should TYPE ru_ismng,
*  ism_var    TYPE ru_ismng,
*  costd(8)   TYPE p DECIMALS 2,
*  coact(8)   TYPE p DECIMALS 2,
*  covar(8)   TYPE p DECIMALS 2,
*END   OF ty_sum_activity,

** Type for Summary Order Materials
*  BEGIN OF ty_sum_ordmats,
*        matnr  TYPE matnr,             " material number
*        num(6) TYPE n,                 " count
*        menge  TYPE menge_d,           " used qty
*        stdqy  TYPE menge_d,           " std qty
*        zloss  TYPE menge_d,           " zero loss qty
*        amein  TYPE meins,             " used uom
*        meins  TYPE meins,             " std uom
*       stprs   TYPE stprs,             " std price
*       peinh   TYPE peinh,             " price uom
*  END OF ty_sum_ordmats,
*"END OF MOD-101

* Type for Materials
  BEGIN OF ty_material_no,
    matnr TYPE matnr,
    bwart TYPE bwart,
  END OF ty_material_no,

* Type for Materials Descriptions
  BEGIN OF ty_material_des,
    matnr TYPE matnr,
    maktx TYPE maktx,
  END OF ty_material_des,

* Type for Object Id and text
  BEGIN OF ty_wc_text,
    objid TYPE cr_objid,
    ktext TYPE cr_ktext,
  END OF ty_wc_text,

* Type for System Function Codes
  BEGIN OF ty_fcode,
    fcode TYPE syucomm,
  END OF ty_fcode.

**START OF MOD-03.
*type definition for ty_mtart.
TYPES:BEGIN OF ty_mtart,
        matnr TYPE matnr,
        mtart TYPE mtart,
      END OF ty_mtart.
**END OF MOD-03.

DATA: BEGIN OF struct_activity.
        INCLUDE STRUCTURE ttl_activ.
DATA: END   OF struct_activity.

*" BEGIN OF MOD-101+
DATA:
*  Internal table for Work Center Header
   i_crhd TYPE STANDARD TABLE OF ty_crhd,
   wa_crhd TYPE ty_crhd,

*  Internal table for Cost Center Master Data
   i_csks TYPE STANDARD TABLE OF ty_csks,
   wa_csks TYPE ty_csks,                                    "#EC NEEDED

*  Internal table for Assignment of Work Center to Cost Center
   i_crco TYPE STANDARD TABLE OF ty_crco,
   wa_crco TYPE ty_crco,

*  Internal table for status texts
   i_tj02t TYPE STANDARD TABLE OF ty_tj02t,
   wa_tj02t TYPE ty_tj02t,

*  Internal table for View "Order Headers PP/CO"
   i_orders TYPE STANDARD TABLE OF ty_orders,
   wa_orders TYPE ty_orders,

*  Internal table for Operation within an order
   i_afvc  TYPE STANDARD TABLE OF ty_afvc,
   i_afvc1 TYPE STANDARD TABLE OF ty_afvc,
   i_afvc2 TYPE STANDARD TABLE OF ty_afvc,
   wa_afvc  TYPE ty_afvc,
   wa_afvc1 TYPE ty_afvc,

*  Internal table for quantities/dates/values in the operations
   i_afvv  TYPE STANDARD TABLE OF ty_afvv,
   i_afvv1 TYPE STANDARD TABLE OF ty_afvv,
   wa_afvv  TYPE ty_afvv,
   wa_afvv1 TYPE ty_afvv,

*  Internal table for Document Segment: Material
   i_mseg  TYPE STANDARD TABLE OF ty_mseg,
   i_mseg1 TYPE STANDARD TABLE OF ty_mseg,
   wa_mseg TYPE ty_mseg,

*  Internal table for Document Segment: Material - Sum
   i_msegs  TYPE STANDARD TABLE OF ty_mseg_sum,
   i_msegs1 TYPE STANDARD TABLE OF ty_mseg_sum,
   wa_msegs TYPE ty_mseg_sum,

   i_issued_mat TYPE STANDARD TABLE OF ty_mseg,
   wa_issued_mat TYPE ty_mseg,

   i_stbtmp TYPE STANDARD TABLE OF stpox,
   wa_stb   TYPE stpox,

   i_cmat  TYPE STANDARD TABLE OF cscmat,
   wa_tmat TYPE cstmat,

   i_bomdat  TYPE ty_t_bomdat,
   wa_bomdat TYPE ty_bomdat,

   i_h_ord  TYPE STANDARD TABLE OF ty_hier_order,
   wa_h_ord TYPE ty_hier_order,

   i_h_phs  TYPE STANDARD TABLE OF ty_hier_phase,
   wa_h_phs TYPE ty_hier_phase,

   i_h_act  TYPE STANDARD TABLE OF ty_hier_act,
   wa_h_act TYPE ty_hier_act,

   i_h_mat  TYPE STANDARD TABLE OF ty_hier_mat,
   wa_h_mat TYPE ty_hier_mat,

   wa_acts TYPE ty_hier_act_sum,
   wa_mats TYPE ty_hier_mat_sum,

   i_afru  TYPE STANDARD TABLE OF ty_afru,
   i_afru1 TYPE STANDARD TABLE OF ty_afru,
   wa_afru  TYPE ty_afru,
   wa_afru1 TYPE ty_afru,

* Internal table for Reservation/dependent requirements
   i_resb TYPE STANDARD TABLE OF ty_resb,
   wa_resb TYPE ty_resb,

   i_marc1  TYPE STANDARD TABLE OF ty_marc1,
   wa_marc1 TYPE ty_marc1,

   i_mara  TYPE STANDARD TABLE OF ty_mara,
   wa_mara TYPE ty_mara,

   i_param  TYPE STANDARD TABLE OF ty_param,
   wa_param TYPE ty_param,

   i_param_key  TYPE STANDARD TABLE OF ty_param_key,
   wa_param_key TYPE ty_param_key,

   i_mbew1  TYPE STANDARD TABLE OF ty_mbew1,
   wa_mbew1 TYPE ty_mbew1,

   i_ordmats TYPE STANDARD TABLE OF ty_ordmats,
   wa_ordmats TYPE ty_ordmats,

   i_plpo TYPE STANDARD TABLE OF plpo,
   wa_plpo TYPE plpo,

   i_plpo1 TYPE STANDARD TABLE OF plpo,
   wa_plpo1 TYPE plpo,

   i_plpo2 TYPE STANDARD TABLE OF plpo,
   wa_plpo2 TYPE plpo,

   i_ord_conf TYPE STANDARD TABLE OF ty_ord_conf,
   wa_ord_conf TYPE ty_ord_conf,

   i_ord_conf1 TYPE STANDARD TABLE OF ty_ord_conf,
   wa_ord_conf1 TYPE ty_ord_conf,

* Internal table for Additional Information for Hierarchy Nodes
   i_nodestab TYPE STANDARD TABLE OF snodetext,
   wa_nodestab TYPE snodetext,

   i_material_des TYPE STANDARD TABLE OF ty_material_des,
   wa_material_des TYPE ty_material_des,

   i_wc_text TYPE STANDARD TABLE OF ty_wc_text,
   wa_wc_text TYPE ty_wc_text,

   i_plpo_sel  TYPE STANDARD TABLE OF ty_plpo_sel,
   wa_plpo_sel TYPE ty_plpo_sel,

   i_afru_sel  TYPE STANDARD TABLE OF ty_afru_sel,
   wa_afru_sel TYPE ty_afru_sel,

   i_fcode TYPE STANDARD TABLE OF ty_fcode,
   wa_fcode TYPE ty_fcode,

   i_mtart  TYPE STANDARD TABLE OF ty_mtart,
   wa_mtart TYPE ty_mtart,

   i_matn  TYPE STANDARD TABLE OF ty_material_no,
   wa_matn TYPE ty_material_no,

   i_parn  TYPE STANDARD TABLE OF ty_par,
   wa_parn TYPE ty_par,

   i_ckey  TYPE STANDARD TABLE OF ty_ckey,
   wa_ckey TYPE ty_ckey,

   i_obj_stat  TYPE STANDARD TABLE OF ty_obj_stat,
   wa_obj_stat TYPE ty_obj_stat,

   r_steus  TYPE RANGE OF steus,
   wa_steus LIKE LINE OF r_steus.
****** Include for Selection Screen
* include ZPROCESSORDTOPVARSEL.

*&---------------------------------------------------------------------*
*&  Include           ZPROCESSORDTOPVARSEL
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*&  Include           ZPROCESSORDTOPVARSEL
*&---------------------------------------------------------------------*
*------------------ Selection Screen --------------------------------
SELECTION-SCREEN BEGIN OF BLOCK sel WITH FRAME
                             TITLE text-001.
SELECT-OPTIONS: s_aufnr FOR wa_afko-aufnr MEMORY ID br1,
"Process Order number
                s_datuv FOR sy-datum MEMORY ID dat.
                " Selection Date Range
SELECT-OPTIONS: s_arbpl FOR wa_crhd-arbpl MATCHCODE OBJECT cram
                                          MEMORY ID agr, "Resource
                s_fevor FOR wa_afko-fevor.
                "Production Scheduler "MOD-101+

PARAMETERS: p_werks TYPE werks_d OBLIGATORY, "MEMORY ID wrk, " Plant
            p_usage LIKE mast-stlan OBLIGATORY DEFAULT '1'.  " BOM usage
SELECT-OPTIONS: s_steus FOR wa_plpo-steus MEMORY ID aat.
" Control Key
PARAMETERS:
*WORT TYPE C LENGTH 4 DEFAULT 'WORT'.
*      p_machs TYPE lstar MEMORY ID lar," Activity Type     "MOD-101-
*      p_kokrs TYPE cssl-kokrs OBLIGATORY MEMORY ID cac,
       p_kokrs TYPE cssl-kokrs MEMORY ID cac,

       " Controlling Area - MOD IB like cssl-kokrs
       p_mtart TYPE mara-mtart MEMORY ID mta.
       " Material Type

SELECT-OPTIONS: s_matnr FOR wa_mara-matnr MATCHCODE OBJECT mat1
                                          MEMORY ID mat,
                                          " Material
                s_kostl FOR wa_cssl-kostl MATCHCODE OBJECT kost
                                          MEMORY ID kos.
                                          " Cost center
*" START OF MOD-101
*s_stats FOR v_dummy MATCHCODE OBJECT /eur/rgbpte_ordstat. " Order
*Status

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (28) text-071.
SELECTION-SCREEN POSITION 33.
PARAMETERS: p_stats1 TYPE char4 MATCHCODE OBJECT /eur/rgbpte_ordstat.
SELECTION-SCREEN POSITION 39.
PARAMETERS: p_s1_chk AS CHECKBOX.
SELECTION-SCREEN COMMENT 41(5) text-072.
SELECTION-SCREEN COMMENT 51(4) text-073.
SELECTION-SCREEN POSITION 58.
PARAMETERS: p_stats2 TYPE char4 MATCHCODE OBJECT /eur/rgbpte_ordstat.
SELECTION-SCREEN POSITION 64.
PARAMETERS: p_s2_chk AS CHECKBOX.
SELECTION-SCREEN COMMENT 66(5) text-072.
SELECTION-SCREEN END OF LINE.
*" END OF MOD-101
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN COMMENT 32(40) text-020.
SELECTION-SCREEN END OF BLOCK sel.

SELECTION-SCREEN BEGIN OF BLOCK typ WITH FRAME TITLE text-021.
*detail, summary or phase
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS:     rb_detl RADIOBUTTON GROUP rad1.
SELECTION-SCREEN COMMENT (20) text-003 FOR FIELD rb_detl.
SELECTION-SCREEN POSITION 30.
PARAMETERS:     rb_summ   RADIOBUTTON GROUP rad1.
SELECTION-SCREEN COMMENT (20) text-004 FOR FIELD rb_summ.
SELECTION-SCREEN POSITION 60.
PARAMETERS:     rb_phase  RADIOBUTTON GROUP rad1.
SELECTION-SCREEN COMMENT (20) text-005 FOR FIELD rb_phase.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK typ.

SELECTION-SCREEN BEGIN OF BLOCK out WITH FRAME TITLE text-002.
*fiscal or quantity
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS:     rb_fiscl RADIOBUTTON GROUP rad2.
SELECTION-SCREEN COMMENT (20) text-006 FOR FIELD rb_fiscl.
SELECTION-SCREEN POSITION 30.
PARAMETERS:     rb_quant  RADIOBUTTON GROUP rad2.
SELECTION-SCREEN COMMENT (20) text-007 FOR FIELD rb_quant.
SELECTION-SCREEN END OF LINE.
*actual or planned production
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS:     rb_actl RADIOBUTTON GROUP rad3.
SELECTION-SCREEN COMMENT (20) text-008 FOR FIELD rb_actl.
SELECTION-SCREEN POSITION 30.
PARAMETERS:     rb_pland  RADIOBUTTON GROUP rad3.
SELECTION-SCREEN COMMENT (20) text-009 FOR FIELD rb_pland.
SELECTION-SCREEN END OF LINE.
*produced or confirmed quantity
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS:     rb_prod   RADIOBUTTON GROUP rad4.
SELECTION-SCREEN COMMENT (20) text-010 FOR FIELD rb_prod.
SELECTION-SCREEN POSITION 30.
PARAMETERS:     rb_conf   RADIOBUTTON GROUP rad4.
SELECTION-SCREEN COMMENT (20) text-011 FOR FIELD rb_conf.
SELECTION-SCREEN END OF LINE.
*all components or non b/flushed only
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS:     rb_bflsh RADIOBUTTON GROUP rad5.
SELECTION-SCREEN COMMENT (20) text-013 FOR FIELD rb_bflsh.
SELECTION-SCREEN POSITION 30.
PARAMETERS:     rb_nflsh RADIOBUTTON GROUP rad5.
SELECTION-SCREEN COMMENT (20) text-012 FOR FIELD rb_nflsh.
SELECTION-SCREEN END OF LINE.
*include/exclude zero production
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS:     rb_ezero  RADIOBUTTON GROUP rad6.
SELECTION-SCREEN COMMENT (20) text-014 FOR FIELD rb_ezero.
SELECTION-SCREEN POSITION 30.
PARAMETERS:     rb_izero  RADIOBUTTON GROUP rad6.
SELECTION-SCREEN COMMENT (20) text-015 FOR FIELD rb_izero.
SELECTION-SCREEN END OF LINE.
*standard planned or zero loss planned
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS:     rb_stdpl  RADIOBUTTON GROUP rad7.
SELECTION-SCREEN COMMENT (20) text-016 FOR FIELD rb_stdpl.
SELECTION-SCREEN POSITION 30.
PARAMETERS:     rb_zloss  RADIOBUTTON GROUP rad7.
SELECTION-SCREEN COMMENT (20) text-017 FOR FIELD rb_zloss.
SELECTION-SCREEN END OF LINE.
*order uom or kgm
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS:     rb_order  RADIOBUTTON GROUP rad8.
SELECTION-SCREEN COMMENT (20) text-018 FOR FIELD rb_order.
SELECTION-SCREEN POSITION 30.
PARAMETERS:     rb_kgm    RADIOBUTTON GROUP rad8.
SELECTION-SCREEN COMMENT (20) text-019 FOR FIELD rb_kgm.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK out.

*** Initialization Event
INITIALIZATION.
  PERFORM fill_movement_types.

*******BEGIN OF MOD-003.
**"Validate BOM usage
*AT SELECTION-SCREEN ON p_usage.
*  PERFORM validate_stlan.

*"Validate control key
*at selection-screen on s_steus.
*perform validate_steus.

*"validate machine hours indicator.
*at selection-screen on p_machs.
*perform validate_lstar.
******END OF MOD-003.

*"BEGIN OF MOD-101
AT SELECTION-SCREEN ON s_steus.
*"Validate control key
  PERFORM validate_steus.
*"END OF MOD-101.

*** At Selection Screen Event
AT SELECTION-SCREEN.

* Checking the plant and get currency
  PERFORM get_currency.

* Checking Materials, material type.
  PERFORM check_materials  .

*** Start of Selection Event
START-OF-SELECTION.
  SET PF-STATUS 'MAIN'.

* Setup Control Key selection range
  CLEAR : s_steus, s_steus[].
  s_steus-sign = 'I'.
  s_steus-option = 'EQ'.
  LOOP AT i_ckey INTO wa_ckey.
    s_steus-low = wa_ckey-steus.
    APPEND s_steus.
  ENDLOOP.
*"END OF MOD-101

* Retrieve Order status
*  PERFORM get_status     . "MOD-101-

* Retrieve work center
*  PERFORM get_work_center. "MOD-101-

* Retrieve Cost center
  PERFORM get_cost_center.

* Retrieve Order Headers PP/CO
  PERFORM get_orders.

* Orders are exists according to the selection
* then retrieve Operations, Material segment and bom details
  IF NOT i_orders[] IS INITIAL.
    PERFORM get_operations.
    PERFORM get_mat_segment.
    PERFORM get_bom_info.
  ELSE.
    MESSAGE s007.
  ENDIF.

*** End of Selection Event
END-OF-SELECTION.

* Displaying output only for +ve records
  IF NOT i_orders IS INITIAL.
* Displaying output by selection ( Detail, Summary or Phase report )
    PERFORM build_output_tabs.
    PERFORM output.
    PERFORM list_display.
  ELSE.
    MESSAGE s007.
    LEAVE LIST-PROCESSING.
  ENDIF.

****** Include for Forms

* include ZPROCESSORDVARF01.

*&---------------------------------------------------------------------*
*&  Include           ZPROCESSORDVARF01
*&---------------------------------------------------------------------*
**&---------------------------------------------------------------------
*
** Report:              : ZPROCESSORD
** AUTHOR               : Aveek Ghose
*
** SUPPLIER             :                                        *
**======================================================================
*
** CHANGE HISTORY LOG
*
**----------------------------------------------------------------------
*
** MOD. NO.|  DATE   | NAME   | CORRECTION NUMBER | CHANGE REFERENCE
**----------------------------------------------------------------------
*
** MOD-001 |DD/MM/YYYY| XXXXXX | XXXXXXXXXX       | XXXXXXXXX
*
** DESCRIPTION:
*
**----------------------------------------------------------------------
*
** MOD-002 |DD/MM/YYYY| XXXXXX | XXXXXXXXXX       | XXXXXXXXX
*
** DESCRIPTION:
*
**----------------------------------------------------------------------
*
**&---------------------------------------------------------------------
*
**&  Include           ZPROCESSORDVARF01
**&---------------------------------------------------------------------
*
*
*FORM fill_movement_types .
*
*  REFRESH i_r_bwart.
*
**  wa_bwart-sign   = c_sign.
**  wa_bwart-option = c_option.
**  wa_bwart-low    = '101'.
**  APPEND wa_bwart TO i_r_bwart.
**  CLEAR wa_bwart.
**
**  wa_bwart-sign   = c_sign.
**  wa_bwart-option = c_option.
**  wa_bwart-low    = '102'.
**  APPEND wa_bwart TO i_r_bwart.
**  CLEAR wa_bwart.
*
*  wa_bwart-sign   = c_sign.
*  wa_bwart-option = c_option.
*  wa_bwart-low    = c_movm_low_261.
*  APPEND wa_bwart TO i_r_bwart.
*  CLEAR wa_bwart.
*
*  wa_bwart-sign   = c_sign.
*  wa_bwart-option = c_option.
*  wa_bwart-low    = c_movm_low_262.
*  APPEND wa_bwart TO i_r_bwart.
*  CLEAR wa_bwart.
*
*  wa_bwart-sign   = c_sign.
*  wa_bwart-option = c_option.
*  wa_bwart-low    = c_movm_low_531.
*  APPEND wa_bwart TO i_r_bwart.
*  CLEAR wa_bwart.
*
*  wa_bwart-sign   = c_sign.
*  wa_bwart-option = c_option.
*  wa_bwart-low    = c_movm_low_532.
*  APPEND wa_bwart TO i_r_bwart.
*  CLEAR wa_bwart.
*ENDFORM.                    " fill_movement_types
*
**&---------------------------------------------------------------------
*
**&      Form  get_currency
**&---------------------------------------------------------------------
*
**       text
**----------------------------------------------------------------------
*
*FORM get_currency.
*
*****Begin of MOD-001
*  DATA :  l_bukrs TYPE bukrs,
*          l_waers TYPE waers.
*
*  CLEAR : v_waers.
*
*  IF NOT p_werks IS INITIAL.
*    SELECT SINGLE werks FROM t001w INTO v_werks
*    WHERE werks = p_werks.
*    IF sy-subrc <> 0.
*      MESSAGE e001 WITH p_werks. " Invalid Plant
*    ENDIF.
*  ENDIF.
**
**Retrieve the company code
*  SELECT SINGLE bukrs
*    FROM t001k
*    INTO l_bukrs
*   WHERE bwkey = p_werks.
*
*  IF sy-subrc = 0.
*
**Get the currence at company
*    SELECT SINGLE waers
*      FROM t001
*      INTO v_waers
*     WHERE bukrs = l_bukrs.
*
*  ENDIF.
*
**  SELECT SINGLE waers
**  FROM tka01 INTO l_waers
**  WHERE kokrs = p_kokrs.
**
**  IF sy-subrc <> 0.
**    MESSAGE e046. " Invalid Controlling area entered.
**
**  ELSEIF v_waers IS INITIAL.
***If the currency is not maintained at companmy level
**    v_waers = l_waers.
**  ENDIF.
******************MOD-004******************************
*  AUTHORITY-CHECK OBJECT 'C_AFKO_AWK'
*           ID 'WERKS' FIELD p_werks
*           ID 'AUFART' DUMMY.
*  IF sy-subrc <> 0.
*    MESSAGE e000 WITH
*     'You do not have authorisation to display report'(070).
*  ENDIF.
****************MOD-004************************************
*
**  IF NOT p_werks IS INITIAL.
**    SELECT SINGLE werks FROM t001w INTO v_werks
**    WHERE werks = p_werks.
**    IF sy-subrc <> 0.
**      MESSAGE e001 WITH p_werks. " Invalid Plant
**    ENDIF.
**  ENDIF.
***********End of MOD-001.
*ENDFORM.                    " get_currency
*
**&---------------------------------------------------------------------
*
**&      Form  check_materials
**&---------------------------------------------------------------------
*
**       text - Checking material number and material type values
**----------------------------------------------------------------------
*
*FORM check_materials.
*  DATA : l_matnr TYPE matnr,                                "#EC NEEDED
*         l_mtart TYPE mtart.                                "#EC NEEDED
*
** Checking material(s) valid or not
*  IF NOT ( s_matnr[] IS INITIAL ).
** Checking at leaset one material is valid for select-options material.
*    SELECT SINGLE matnr
*    FROM mara
*    INTO l_matnr
*    WHERE matnr IN s_matnr.                                 "#EC *
*    IF sy-subrc <> 0.
*      MESSAGE e000 WITH 'Material(s) not found for this selection'(062)
.
*    ENDIF.
*  ENDIF.
*
** Checking material type valid or not
*  IF NOT ( p_mtart IS INITIAL ).
*    SELECT SINGLE mtart
*    FROM t134 INTO l_mtart  "MOD IB mara-mtart
*    WHERE mtart = p_mtart.
*    IF sy-subrc <> 0.
*      MESSAGE e000 WITH 'Incorrect Material Type'(063).
*    ENDIF.
*  ENDIF.
*
** Checking material number and type valid or not.
*  IF NOT ( s_matnr[] IS INITIAL ) AND
*     NOT ( p_mtart   IS INITIAL ).
** Checking at leaset one material is valid for select-options material
** and for material type
*
*    CLEAR l_matnr.
*    SELECT SINGLE matnr
*    FROM mara
*    INTO l_matnr
*    WHERE matnr IN s_matnr AND
*          mtart = p_mtart.                                  "#EC *
*    IF sy-subrc <> 0.
*      MESSAGE e000
*      WITH 'Incorrect material number & type combination'(064).
*    ENDIF.
*  ENDIF.
*ENDFORM.                    " check_materials
*
**&---------------------------------------------------------------------
*
**&      Form  get_status
**&---------------------------------------------------------------------
*
**       text -- Retreving System status texts from table TJ02T
**----------------------------------------------------------------------
*
*FORM get_status USING    fp_txt04 TYPE j_txt04
*                CHANGING fp_stat  TYPE j_istat.
*** >>>> MOD-101+
*  CLEAR : fp_stat.
*  SELECT SINGLE istat
*    FROM tj02t
*    INTO fp_stat
*   WHERE txt04 = fp_txt04
*     AND spras = sy-langu.                            "#EC CI_SGLSELECT
**** if select fails stat is returned empty, so no check required.
*
*** <<<< MOD-101+
**  REFRESH i_tj02t.
**  CLEAR   wa_tj02t.
**  IF NOT ( s_stats[] IS INITIAL ).
**    SELECT txt04
**    FROM tj02t INTO TABLE i_tj02t
**    WHERE txt04 IN s_stats
**    AND   spras =  sy-langu.                "#EC CI_SGLSELECT
***    IF sy-subrc = 0.
**** The check is not required here since the
**** system status text is not  mandatory
***    ENDIF.
**  ENDIF.
**
**  IF rb_ezero = c_x.
**    IF rb_prod = c_x.
**      wa_tj02t-txt04 = c_txt_dlv.
**    ENDIF.
**
**    IF rb_conf = c_x.
**      wa_tj02t-txt04 = c_txt_cnf.
**    ENDIF.
**    APPEND wa_tj02t TO i_tj02t.
**    CLEAR  wa_tj02t.
**  ENDIF.
**  SORT i_tj02t BY txt04 AS TEXT.  " MOD IB (SORT i_tj02t)
**  DELETE ADJACENT DUPLICATES FROM i_tj02t.
*ENDFORM.                    " get_status
*
**&---------------------------------------------------------------------
*
**&      Form  get_status_info
**&---------------------------------------------------------------------
*
**       text
**----------------------------------------------------------------------
*
*FORM get_status_info USING    fp_l_orders_objnr TYPE j_objnr
*                              fp_l_sttxt        TYPE any.
*
*  DATA: l_text(4) TYPE c,
*        l_stsma   TYPE j_stsma,
*
** START MOD IB
*        i_status  TYPE STANDARD TABLE OF jstat INITIAL SIZE 0,
*        wa_status TYPE jstat.
** END MOD IB
*  REFRESH i_status.
*
** Get all active statuses for the order
*  CALL FUNCTION 'STATUS_READ'
*    EXPORTING
*      objnr       = fp_l_orders_objnr
*      only_active = c_x
*    IMPORTING
*      stsma       = l_stsma
*    TABLES
*      status      = i_status.
*
*  CLEAR: fp_l_sttxt.
*
*  LOOP AT i_status INTO wa_status.
** Get the text for each status
*    CALL FUNCTION 'STATUS_NUMBER_CONVERSION'
*      EXPORTING
*        language      = sy-langu
*        status_number = wa_status-stat
*        stsma         = l_stsma
*      IMPORTING
*        txt04         = l_text.
** Add status text found to current list
*    CONCATENATE fp_l_sttxt l_text INTO fp_l_sttxt.
*    CLEAR : wa_status.
*  ENDLOOP.
*ENDFORM.                    " get_status_info
*
**&---------------------------------------------------------------------
*
**&      Form  get_work_center
**&---------------------------------------------------------------------
*
**       text
**----------------------------------------------------------------------
*
*FORM get_work_center.
*  CLEAR:   wa_crhd.
*  REFRESH: i_crhd.
*
*  SELECT objid
*         arbpl
*  FROM crhd INTO TABLE i_crhd
*  WHERE objty = c_objtyp
*    AND werks = p_werks
*    AND arbpl IN s_arbpl.
**  IF sy-subrc = 0.
*** sy-subrc check is not required, there must be atleast one record for
*** this selection.
**  ENDIF.
*ENDFORM.                    " get_work_center
*
**&---------------------------------------------------------------------
*
**&      Form  get_cost_center
**&---------------------------------------------------------------------
*
**       text
**----------------------------------------------------------------------
*
*FORM get_cost_center.
*  IF NOT ( s_kostl[] IS INITIAL ).
*    CLEAR : i_csks.
*    SELECT kokrs kostl
*      FROM csks
*      INTO TABLE i_csks
*     WHERE kokrs = p_kokrs
*       AND kostl IN s_kostl.
*    IF sy-subrc = 0.
*      SORT i_csks BY kokrs kostl.
*    ENDIF.
*  ENDIF.
*ENDFORM.                    " get_cost_center
*
*****
***** BEGIN OF MOD-101
*****
**&---------------------------------------------------------------------
*
**&      Form  get_orders
**&---------------------------------------------------------------------
*
**       text
**----------------------------------------------------------------------
*
*FORM get_orders.
*
*  DATA: l_sttxt(100)  TYPE c,
*        flg_status(1) TYPE c.
*  FIELD-SYMBOLS : <fs_orders> TYPE ty_orders.
*
*  MOVE 'Extracting Process Orders'(022) TO v_output_text.
*  PERFORM inform_user_of_progress.
*
*  IF NOT p_mtart IS INITIAL.
**"selection filter on material type
*    SELECT matnr     "material number
*           mtart     "material type
*      INTO TABLE i_mtart
*      FROM mara
*     WHERE matnr IN s_matnr
*       AND mtart  = p_mtart.
*    IF sy-subrc = c_0.
** refill S_MATNR with I_MTART values
*      REFRESH : s_matnr.
*
*      s_matnr-sign   = c_sign.
*      s_matnr-option = c_option.
*      LOOP AT i_mtart INTO wa_mtart.
*        s_matnr-low = wa_mtart-matnr.
*        APPEND s_matnr.
*      ENDLOOP.
*
*    ELSE.
** No data was selected for material type
*      MESSAGE i072 WITH p_mtart.
*      LEAVE LIST-PROCESSING.
*    ENDIF.
*  ENDIF.
*
*  SELECT aufnr
*
*         werks
*         kokrs
*         objnr
*
*         gltrp
*         gstrp
*
*         rsnum
*
*         gamng
*         gmein
*         plnbez
*
*         plnty
*         plnnr
*         plnal
*
*         stlst
*         stlty
*         stlnr
*         sdatv
*         stlal
*         stlan
*
*         aufpl
*         zaehl
*         rueck
*
*         auart
*
*         aufld                                              "31-05-2005
*
*    INTO TABLE i_orders FROM caufv
*   WHERE aufnr  IN s_aufnr
*     AND werks   = p_werks
**    AND kokrs   = p_kokrs
*     AND fevor   IN s_fevor
*     AND plnbez  IN s_matnr
**    AND stlan   = p_usage
*     AND ( gstrp IN s_datuv OR
*           gltrp IN s_datuv ).
*  IF sy-subrc <> 0.
*    MESSAGE s007.
*    LEAVE LIST-PROCESSING.
*  ENDIF.
*
*  SORT i_orders BY aufnr.
*
** Take status txt from sel screen and get status number
*  IF NOT p_stats1 IS INITIAL.
*    PERFORM get_status USING p_stats1 CHANGING v_stat1.
*  ENDIF.
*
*  IF NOT p_stats2 IS INITIAL.
*    PERFORM get_status USING p_stats2 CHANGING v_stat2.
*  ENDIF.
*
** get object numbers and statuses for orders
*  CLEAR : i_obj_stat.
*  SELECT objnr
*         stat
*    FROM jest
*    INTO TABLE i_obj_stat
*     FOR ALL ENTRIES IN i_orders
*   WHERE objnr = i_orders-objnr
*     AND stat  IN (v_stat1,v_stat2).
*
** cull orders
*  LOOP AT i_orders ASSIGNING <fs_orders>.
*    IF NOT v_stat1 IS INITIAL.
*      READ TABLE i_obj_stat INTO wa_obj_stat
*                            WITH KEY objnr = <fs_orders>-objnr
*                                     stat  = v_stat1.
*      IF sy-subrc = 0 AND p_s1_chk EQ c_x.
*        <fs_orders>-del = c_x.
*      ELSEIF sy-subrc NE 0 AND p_s1_chk NE c_x.
*        <fs_orders>-del = c_x.
*      ENDIF.
*    ENDIF.
*
*    IF NOT v_stat2 IS INITIAL.
*      READ TABLE i_obj_stat INTO wa_obj_stat
*                            WITH KEY objnr = <fs_orders>-objnr
*                                     stat  = v_stat2.
*      IF sy-subrc = 0 AND p_s2_chk EQ c_x.
*        <fs_orders>-del = c_x.
*      ELSEIF sy-subrc NE 0 AND p_s2_chk NE c_x.
*        <fs_orders>-del = c_x.
*      ENDIF.
*    ENDIF.
*  ENDLOOP.
*
*MOD-004**********************************
*  DELETE i_orders WHERE del = c_x.
*MOD-004**********************************
**  LOOP AT i_orders INTO wa_orders.
**    IF NOT i_tj02t[] IS INITIAL .
**      PERFORM get_status_info USING wa_orders-objnr l_sttxt.
**
**      CLEAR: flg_status, wa_tj02t.
**      LOOP AT i_tj02t INTO wa_tj02t.
**        IF l_sttxt NS wa_tj02t-txt04.
**          CLEAR flg_status.
**          EXIT.
**        ELSE.
**          flg_status = c_x.
**          CONTINUE.
**        ENDIF.
**        CLEAR : wa_tj02t.
**      ENDLOOP.
**
**      IF flg_status <> c_x.
**        DELETE i_orders.
**        CONTINUE.
**      ENDIF.
**    ENDIF.
**  ENDLOOP.
*ENDFORM.                    " get_orders
*
**&---------------------------------------------------------------------
*
**&      Form  get_operations
**&---------------------------------------------------------------------
*
**       text
**----------------------------------------------------------------------
*
*FORM get_operations.
*
*  DATA l_tabix TYPE sytabix.
*
** Let the user know whats up
*  MOVE 'Extracting Phase Information'(023) TO v_output_text.
*  PERFORM inform_user_of_progress.
*
** select process order item lines
*  SELECT aufpl
*         aplzl
*
*         ltxa1
*
*         plnkn
*         plnty
*         plnnr
*         zaehl
*
*         vornr
*         steus
*         arbid
*         rueck
*
*         phflg
*         sumnr
*         vgwts
*
*         lar01
*         lar02
*         lar03
*         lar04
*         lar05
*         lar06
*    INTO TABLE i_afvc
*    FROM afvc
*     FOR ALL ENTRIES IN i_orders
*   WHERE aufpl = i_orders-aufpl
*     AND steus IN s_steus
*     AND phflg = c_x.
*
*  IF sy-subrc = 0.
** select process order item values
*    SELECT aufpl
*           aplzl
*
*           meinh
*           bmsch
*
*           umren
*           umrez
*
*           vge01
*           vgw01
*           vge02
*           vgw02
*           vge03
*           vgw03
*           vge04
*           vgw04
*           vge05
*           vgw05
*           vge06
*           vgw06
*
*           mgvrg
*           lmnga
*           gmnga
*
*           ism01
*           ism02
*           ism03
*           ism04
*           ism05
*           ism06
*
*           ssavd
*      FROM afvv INTO TABLE i_afvv
*       FOR ALL ENTRIES IN i_afvc
*     WHERE aufpl  = i_afvc-aufpl
*       AND aplzl  = i_afvc-aplzl
*       AND ssavd IN s_datuv.
*    IF sy-subrc = 0.
*      SORT i_afvv BY aufpl aplzl.
*    ENDIF.
*
** select process order related work centre data
*    SELECT objty
*           objid
*           kokrs
*           kostl
*           lstar
*      FROM crco
*      INTO TABLE i_crco
*       FOR ALL ENTRIES IN i_afvc
*     WHERE objty = c_objtyp
*       AND objid = i_afvc-arbid
*       AND kostl IN s_kostl.
*    IF sy-subrc = 0.
*      SORT i_crco BY objty objid kostl.
*    ENDIF.
*
** Retrieve work center details
*    SELECT objid
*           arbpl
*           vgwts
*      FROM crhd
* APPENDING TABLE i_crhd
*       FOR ALL ENTRIES IN i_afvc
*     WHERE objty = c_objtyp
*       AND objid = i_afvc-arbid
*       AND werks = p_werks
*       AND arbpl IN s_arbpl.
*
*    SORT i_crhd   BY objid.
*    SORT i_orders BY aufpl.
*    SORT i_afvc BY aufpl vornr DESCENDING.
*
*    LOOP AT i_afvc INTO wa_afvc.
*      l_tabix = sy-tabix.
*
**** link PrO number to phase through the routing number
*      CLEAR : wa_orders.
*      READ TABLE i_orders INTO wa_orders WITH KEY aufpl = wa_afvc-aufpl
.
*      IF sy-subrc = 0.
*        wa_afvc-aufnr = wa_orders-aufnr.
*        MODIFY i_afvc FROM wa_afvc INDEX l_tabix TRANSPORTING aufnr.
*
**** check cost centre of phase
*        IF NOT ( s_kostl[] IS INITIAL ).
*          READ TABLE i_crco INTO wa_crco WITH KEY objty = c_objtyp
*                                                  objid = wa_afvc-arbid
*                                              BINARY SEARCH.
*          IF sy-subrc = 0.
**** see if cost centre of phase is valid
*            READ TABLE i_csks INTO wa_csks
*                              WITH KEY kostl = wa_crco-kostl.
*            IF sy-subrc <> 0.
**** delete invalid phases
*              DELETE i_afvv WHERE aufpl = wa_afvc-aufpl
*                              AND aplzl = wa_afvc-aplzl.
*              DELETE i_afvc INDEX l_tabix.
*              CONTINUE.
*            ENDIF.
*          ENDIF.
*        ENDIF.
*
**** Check work centre details with resource
*        IF NOT ( s_arbpl[] IS INITIAL ).
*          READ TABLE i_crhd INTO wa_crhd
*                            WITH KEY objid = wa_afvc-arbid.
*          IF sy-subrc <> 0.
*            DELETE i_afvv WHERE aufpl = wa_afvc-aufpl
*                            AND aplzl = wa_afvc-aplzl.
*            DELETE i_afvc INDEX l_tabix.
*            CONTINUE.
*          ENDIF.
*
*        ENDIF.
*        CLEAR: wa_crco, wa_crhd, l_tabix.
*
*      ELSE.
**** if routing number is not linked to any valid order
**** delete phase
*        DELETE i_afvc INDEX l_tabix.
*      ENDIF.
*    ENDLOOP.
*  ENDIF.
*
** Begin of MOD-002++
*  LOOP AT i_orders INTO wa_orders.
*    CLEAR: wa_afvc, l_tabix.
*    l_tabix = sy-tabix.
*    READ TABLE i_afvc INTO wa_afvc WITH KEY aufpl = wa_orders-aufpl.
*MOD-004********************************
**    IF sy-subrc NE 0.
**      DELETE i_orders INDEX l_tabix.
**    ENDIF.
**MOD-004*******************************
*  ENDLOOP.
** End of MOD-002++
*
*ENDFORM.                    " get_operations
*
**&--------------------------------------------------------------------*
**&      Form  get_order_mats
**&--------------------------------------------------------------------*
**       text
**---------------------------------------------------------------------*
*FORM get_order_mats.
*
*  DATA : l_v_erfme TYPE erfme,
*         l_v_chec  TYPE char1,
*         l_bwart   TYPE bwart.
*
** get materials issued/receipt against order
*  SELECT aufnr aufpl aplzl matnr mblnr mjahr zeile bwart
*         werks lgort charg
*         menge meins erfmg erfme
*         rsnum rspos rsart
*    FROM aufm
*    INTO TABLE i_mseg1
*     FOR ALL ENTRIES IN i_orders
*   WHERE aufnr = i_orders-aufnr.
*  IF sy-subrc = 0.
*
**** get base UoM for all materials
*    CLEAR: i_mara.
*    SELECT matnr
*           mtart
*           meins
*           gewei
*           ntgew
*      FROM mara
* APPENDING TABLE i_mara
*       FOR ALL ENTRIES IN i_mseg1
*     WHERE matnr = i_mseg1-matnr.
*
*    SORT i_mseg1 BY aufnr aufpl aplzl matnr.
**** get material qty in base UoM and summarize material data
*    LOOP AT i_mseg1 INTO wa_mseg.
*      CLEAR : wa_mara.
**** read material master for base UoM
*      READ TABLE i_mara INTO wa_mara WITH KEY matnr = wa_mseg-matnr.
*      IF sy-subrc = 0.
*        IF wa_mseg-meins <> wa_mara-meins.
*          CLEAR : wa_mseg-bmenge.
**** convert GR quant into base units
*          PERFORM conv_to_from_base USING 'X'
*                                          wa_mseg-matnr
*                                          wa_mseg-menge
*                                          wa_mseg-meins
*                                          wa_mara-meins
*                                 CHANGING wa_mseg-bmenge
*                                          v_conv_rc.
*        ELSE.
*          wa_mseg-bmenge = wa_mseg-menge.
*        ENDIF.
*
*        wa_mseg-bmeins = wa_mara-meins.
*        wa_mseg-gewei  = wa_mara-gewei.
*        wa_mseg-ntgew  = wa_mara-ntgew.
*        MODIFY i_mseg1 FROM wa_mseg TRANSPORTING bmenge bmeins.
*      ENDIF.
*
*      wa_msegs-aufnr  = wa_mseg-aufnr.
*      wa_msegs-aufpl  = wa_mseg-aufpl.
*      wa_msegs-aplzl  = wa_mseg-aplzl.
*      wa_msegs-matnr  = wa_mseg-matnr.
*      wa_msegs-meins  = wa_mseg-meins.
*      wa_msegs-bmeins = wa_mseg-bmeins.
*      wa_msegs-gewei  = wa_mseg-gewei.
** Begin of MOD-002++
*      IF ( wa_mseg-bwart <> 'ZU1' ) AND ( wa_mseg-bwart <> 'ZU2' ).
*        wa_msegs-erfme  = wa_mseg-erfme.
*      ENDIF.
** End of MOD-002++
*
*      AT NEW matnr.
*        l_v_erfme = wa_msegs-erfme.
*        CLEAR : l_v_chec.
*      ENDAT.
*
*      IF l_v_erfme <> wa_mseg-erfme.
**** set flag if different GR mvts have diff. GR UoM
*        l_v_chec = c_x.
*      ENDIF.
*
**** Sum up material qtys based on movement
*      CASE wa_mseg-bwart.
*        WHEN '101'.
**** GR of material
*          wa_msegs-bmenge1 = wa_msegs-bmenge1 + wa_mseg-bmenge.
*          wa_msegs-erfmg1  = wa_msegs-erfmg1  + wa_mseg-erfmg.
*          wa_msegs-erfme   = wa_mseg-erfme.
*          l_bwart    = '101'.                               "23-05-2005
*
*        WHEN '261'.
**** Consumption of material
*          wa_msegs-bmenge2 = wa_msegs-bmenge2 + wa_mseg-bmenge.
*          wa_msegs-erfmg2  = wa_msegs-erfmg2  + wa_mseg-erfmg.
*          l_bwart    = '261'.                               "23-05-2005
*
*
*        WHEN '532'.
**** reversal of 531
*          wa_msegs-bmenge5 = wa_msegs-bmenge5 + wa_mseg-bmenge.
*          wa_msegs-erfmg5  = wa_msegs-erfmg5  + wa_mseg-erfmg.
*
*        WHEN '102'.
**** reversal of 101
*          wa_msegs-bmenge1 = wa_msegs-bmenge1 - wa_mseg-bmenge.
*          wa_msegs-erfmg1  = wa_msegs-erfmg1  + wa_mseg-erfmg.
*
*        WHEN '262'.
**** reversal of 261
*          wa_msegs-bmenge2 = wa_msegs-bmenge2 - wa_mseg-bmenge.
*          wa_msegs-erfmg2  = wa_msegs-erfmg2  + wa_mseg-erfmg.
*
*        WHEN '531'.
**** By-product material mvt
*          wa_msegs-bmenge5 = wa_msegs-bmenge5 - wa_mseg-bmenge.
*          wa_msegs-erfmg5  = wa_msegs-erfmg5  + wa_mseg-erfmg.
*          l_bwart    = '531'.                               "23-05-2005
*
*      ENDCASE.
*
**** If the diff. GR qtys have different UoM then do not cumulate
**** actual qty values
*      IF l_v_chec = c_x.
*        CLEAR : wa_msegs-erfmg1, wa_msegs-erfmg2 , wa_msegs-erfmg5.
*      ENDIF.
*
*      AT END OF matnr.
*        wa_msegs-bmenge = wa_msegs-bmenge1 + wa_msegs-bmenge2 +
*                          wa_msegs-bmenge5.
*        wa_msegs-erfmg  = wa_msegs-erfmg1  + wa_msegs-erfmg2 +
*                          wa_msegs-erfmg5.
*        wa_msegs-bwart  = l_bwart .
*
*        APPEND wa_msegs TO i_msegs.
*        CLEAR : wa_msegs,
*                l_bwart.
*      ENDAT.
*    ENDLOOP.
*  ENDIF.
*ENDFORM.                    "get_order_mats
*
**&---------------------------------------------------------------------
*
**&      Form  get_mat_segment
**&---------------------------------------------------------------------
*
*FORM get_mat_segment.
*  DATA: l_tabix  TYPE sytabix.
*
*  FIELD-SYMBOLS : <l_fs_orders> TYPE ty_orders,
*                  <l_fs_afvc>   TYPE ty_afvc.
*
*  IF NOT ( i_orders[] IS INITIAL ).
**** get material master data for PO materials
*    CLEAR: i_mara , i_mseg , i_mseg1 , i_msegs , i_msegs1.
*    SELECT matnr
*           mtart
*           meins
*           gewei
*           ntgew
*      FROM mara
*      INTO TABLE i_mara
*       FOR ALL ENTRIES IN i_orders
*     WHERE matnr = i_orders-plnbez.
*
*    IF NOT ( rb_prod IS INITIAL ).
**** Tell user we are Extracting goods receipt information
*      MOVE 'Extracting Goods Receipt Information'(024) TO v_output_text
.
*      PERFORM inform_user_of_progress.
*
**** get the materials to process
*      PERFORM get_order_mats.
*
**** create alternate working tables for mat. mvts
*      i_mseg   = i_mseg1.
*      i_msegs1 = i_msegs.
*
**** retain only order material in internal table and get order qty in
**** base UoM
*      LOOP AT i_orders ASSIGNING <l_fs_orders>.
*
**** retain mat. mvts only for the main material of the PrO
*        DELETE i_mseg WHERE aufnr =  <l_fs_orders>-aufnr
*                        AND matnr <> <l_fs_orders>-plnbez.
*
*        DELETE i_msegs1 WHERE aufnr =  <l_fs_orders>-aufnr
*                          AND matnr <> <l_fs_orders>-plnbez.
*
**** read material master for base UoM of material
*        CLEAR : wa_mara.
*        READ TABLE i_mara INTO wa_mara
*                          WITH KEY matnr = <l_fs_orders>-plnbez.
*        IF sy-subrc = 0.
*          IF wa_mara-meins <> <l_fs_orders>-gmein.
**** convert order quantity to base UoM
*            PERFORM conv_to_from_base USING 'X'
*                                            <l_fs_orders>-plnbez
*                                            <l_fs_orders>-gamng
*                                            <l_fs_orders>-gmein
*                                            wa_mara-meins
*                                   CHANGING <l_fs_orders>-bgamng
*                                            v_conv_rc.
*          ELSE.
*            <l_fs_orders>-bgamng = wa_orders-gamng.
*          ENDIF.
*
*          <l_fs_orders>-bsuom  = wa_mara-meins.
*          <l_fs_orders>-gewei  = wa_mara-gewei.
*          <l_fs_orders>-ntgew  = wa_mara-ntgew.
*        ENDIF.
*      ENDLOOP.
*
*      SORT i_mseg   BY aufnr.
*      SORT i_msegs1 BY aufnr.
*      SORT i_orders BY aufnr.
*
**** Calculatin the quantity according to the movement type and
**** assign the value to i_orders internal table
*      LOOP AT i_orders ASSIGNING <l_fs_orders>.
*        CLEAR : wa_msegs.
*        READ TABLE i_msegs1 INTO wa_msegs
*                            WITH KEY aufnr = <l_fs_orders>-aufnr
*                                     matnr = <l_fs_orders>-plnbez.
*        IF rb_ezero EQ c_x AND wa_msegs-bmenge1 = 0.
**** Don't want zero production orders
*          DELETE i_afvc   WHERE aufnr = <l_fs_orders>-aufnr.
*MOD-004****************************************************
**         DELETE i_orders WHERE aufnr = <l_fs_orders>-aufnr.
*MOD-004****************************************************
*          CONTINUE.
*        ENDIF.
*
*        <l_fs_orders>-erfmg  = wa_msegs-erfmg1.
*        <l_fs_orders>-bmenge = wa_msegs-bmenge1.
*        <l_fs_orders>-gruom  = wa_msegs-erfme.
*      ENDLOOP.
*
*    ELSE.
**** Here we're Extracting confirmation information
*      MOVE 'Extracting Confirmation Information'(025) TO v_output_text.
*      PERFORM inform_user_of_progress.
*
**** get order qty in base UoM and get base UoM and weight UoM
*      LOOP AT i_orders ASSIGNING <l_fs_orders>.
*
*        CLEAR : wa_mara.
*        READ TABLE i_mara INTO wa_mara
*                          WITH KEY matnr = <l_fs_orders>-plnbez.
*
*        IF sy-subrc = 0.
*          IF wa_mara-meins <> wa_orders-gmein.
**** convert order quantity to base UoM
*            PERFORM conv_to_from_base USING 'X'
*                                            <l_fs_orders>-plnbez
*                                            <l_fs_orders>-gamng
*                                            <l_fs_orders>-gmein
*                                            wa_mara-meins
*                                   CHANGING <l_fs_orders>-bgamng
*                                            v_conv_rc.
*          ELSE.
*            <l_fs_orders>-bgamng = <l_fs_orders>-gamng.
*          ENDIF.
*
*          <l_fs_orders>-bsuom  = wa_mara-meins.
*          <l_fs_orders>-gewei  = wa_mara-gewei.
*          <l_fs_orders>-ntgew  = wa_mara-ntgew.
*        ENDIF.
*      ENDLOOP.
*
**** Select confirmations using operation confirmation number instead of
**** order number
*      CLEAR : i_afvv1 , i_afvc1 , i_afru , i_afru1.
**** get 'bottleneck' phases
*      LOOP AT i_afvc INTO wa_afvc WHERE steus = 'YBN1'
*                                    AND phflg = c_x.
*        APPEND wa_afvc TO i_afvc1.
**** get 'bottleneck' phase values
*        LOOP AT i_afvv INTO wa_afvv WHERE aufpl = wa_afvc-aufpl
*                                      AND aplzl = wa_afvc-aplzl.
*          APPEND wa_afvv TO i_afvv1.
*        ENDLOOP.
*      ENDLOOP.
*
*      IF NOT i_afvc1 IS INITIAL.
*        SORT i_afvc1 BY aufpl aplzl plnkn plnty plnnr.
**** get confirmations for the various phases
*        SELECT aufnr
*               rueck
*               gmnga
*               lmnga
*               gmein
*               meinh
*               meilr
*               stokz
*               rueck_mst
*               aufpl
*               aplzl
*          INTO TABLE i_afru
*          FROM afru
*           FOR ALL ENTRIES IN i_afvc
*         WHERE rueck = i_afvc-rueck
*           AND werks = p_werks
*           AND aufpl = i_afvc-aufpl
*           AND aplzl = i_afvc-aplzl.
*
*        SORT i_afru BY aufnr rueck aufpl aplzl.
*
*        LOOP AT i_afvc1 INTO wa_afvc.
*          LOOP AT i_afru INTO wa_afru
*                         WHERE aufnr = wa_afvc-aufnr
*                           AND rueck = wa_afvc-rueck
*                           AND aufpl = wa_afvc-aufpl
*                           AND aplzl = wa_afvc-aplzl.
**** get 'bottleneck' related confirmations
*            APPEND wa_afru TO i_afru1.
*          ENDLOOP.
*        ENDLOOP.
*
*        IF NOT i_afvv1 IS INITIAL.
*          SORT i_afvv1 BY aufpl aplzl.
*
**** get total confirmation on order for 'bottleneck' phases,
**** this will be the confirmed qty for whole order
*          LOOP AT i_afvc ASSIGNING <l_fs_afvc>.
*
*            wa_afvc = <l_fs_afvc>.
**** ensuring the phase is related to a valid PrO
*            CLEAR : wa_orders.
*            READ TABLE i_orders INTO wa_orders
*                                WITH KEY aufnr = wa_afvc-aufnr.
*            IF sy-subrc = 0.
**** is it a bottleneck phase?
*              READ TABLE i_afvc1 INTO wa_afvc1
*                                 WITH KEY aufpl = wa_orders-aufpl
*                                          plnty = wa_afvc-plnty
*                                          plnnr = wa_afvc-plnnr
*                                          plnkn = wa_afvc-plnkn
*                                          zaehl = wa_afvc-zaehl.
*              IF sy-subrc = 0.
**** get phase operation values
*                READ TABLE i_afvv1 INTO wa_afvv1
*                                   WITH KEY aufpl = wa_afvc1-aufpl
*                                            aplzl = wa_afvc1-aplzl
*                                   BINARY SEARCH.
*                IF sy-subrc = 0.
**** does the phase have any std runtime m/c confirmations
*                  CHECK wa_afvv1-vgw02 NE 0.
*
**** get actual bottleneck phase confirmations
*                  PERFORM get_confirmation_qty_new
*                                             USING wa_orders-aufnr
*                                                   wa_afvc1-rueck
*                                                   wa_afvc1-aufpl
*                                                   wa_afvc1-aplzl
*                                             CHANGING
*                                                   wa_afvc-lmnga
*                                                   wa_afvc-cfuom.
**** save confirmation values against phase
*                  <l_fs_afvc>-lmnga = wa_afvc-lmnga.
*                  <l_fs_afvc>-cfuom = wa_afvc-cfuom.
*                ENDIF.
*              ENDIF.
*            ENDIF.
*          ENDLOOP.
*        ENDIF.
*      ENDIF.
*
**** retain only bottleneck related confirmation phases,
**** as this gives confirmation qty for order
*      i_afvc2 = i_afvc.
*      IF rb_ezero = c_x.
**** no zero confirmation qty phases wanted
*        DELETE i_afvc2 WHERE lmnga EQ 0.
*      ENDIF.
*      DELETE ADJACENT DUPLICATES FROM i_afvc2
*                                 COMPARING aufnr
*                                           aufpl
*                                           aplzl
*                                           plnkn
*                                           plnty
*                                           plnnr
*                                           zaehl
*                                           vornr.
*
**** get order qty in base UoM and get base UoM and weight UoM
*      LOOP AT i_orders ASSIGNING <l_fs_orders>.
*
**** get confirmed qty
*        READ TABLE i_afvc2 INTO wa_afvc
*                           WITH KEY aufnr = <l_fs_orders>-aufnr.
*        IF sy-subrc = 0.
*          <l_fs_orders>-lmnga = wa_afvc-lmnga.
*          <l_fs_orders>-cfuom = wa_afvc-cfuom.
*
*          IF <l_fs_orders>-cfuom <> <l_fs_orders>-bsuom.
**** convert confirmation quantity to base UoM
*            PERFORM conv_to_from_base USING 'X'
*                                            <l_fs_orders>-plnbez
*                                            <l_fs_orders>-lmnga
*                                            <l_fs_orders>-cfuom
*                                            <l_fs_orders>-bsuom
*                                   CHANGING <l_fs_orders>-blmnga
*                                            v_conv_rc.
*          ELSE.
*            <l_fs_orders>-blmnga = <l_fs_orders>-lmnga.
*          ENDIF.
*
*        ELSE.
**** if the order has no confirmed qty against it, remove it
**** from further processing
*          <l_fs_orders>-del = c_x.
*        ENDIF.
*      ENDLOOP.
*MOD-004*********************************
*      DELETE i_orders WHERE del = c_x.
*MOD-004*********************************
*    ENDIF.
*  ENDIF.
*ENDFORM.                    " get_mat_segment
*
**&---------------------------------------------------------------------
*
**&      Form  get_confirmation_qty_new
**&---------------------------------------------------------------------
*
*FORM get_confirmation_qty_new USING    fp_aufnr TYPE aufnr
*                                       fp_rueck TYPE co_rueck
*                                       fp_aufpl TYPE co_aufpl
*                                       fp_aplzl TYPE co_aplzl
*                              CHANGING fp_lmnga TYPE ru_lmnga
*                                       fp_cfuom TYPE meins.
*
*  DATA: last_lmnga  TYPE ru_lmnga,
*        last_lmnga1 TYPE ru_lmnga,
*        last_lmnga2 TYPE ru_lmnga,
*
*        l_v_meinh   TYPE ru_vorme.
*
*  CLEAR: last_lmnga.
*
** Check this record. If there is no link to another confirmation and
** a quantity has been confirmed and it is a milestone confirmation
** then we want to select all of the confirmations for it.
*  LOOP AT i_afru1 INTO wa_afru1 WHERE aufnr = fp_aufnr
*                                  AND rueck = fp_rueck
*                                  AND aufpl = fp_aufpl
*                                  AND aplzl = fp_aplzl.
*    CHECK wa_afru1-lmnga NE 0.
*
*    IF l_v_meinh IS INITIAL.
*      l_v_meinh = wa_afru1-meinh.
*    ENDIF.
*
*    last_lmnga1 = wa_afru1-lmnga.
*
*    IF l_v_meinh <> wa_afru1-meinh.
*      CLEAR : last_lmnga2.
*      PERFORM conv_to_from_base USING 'X'
*                                      wa_orders-plnbez
*                                      wa_afru1-lmnga
*                                      wa_afru1-meinh
*                                      wa_orders-bsuom
*                             CHANGING last_lmnga2
*                                      v_conv_rc.
*
*      PERFORM conv_to_from_base USING ' '
*                                      wa_orders-plnbez
*                                      last_lmnga2
*                                      l_v_meinh
*                                      wa_orders-bsuom
*                             CHANGING last_lmnga1
*                                      v_conv_rc.
*
*    ENDIF.
*
*    IF wa_afru1-stokz IS INITIAL.
*      last_lmnga = last_lmnga + last_lmnga1.
*    ELSE.
*      last_lmnga = last_lmnga - last_lmnga1.
*    ENDIF.
*  ENDLOOP.
*
*  MOVE last_lmnga TO fp_lmnga.
*  fp_cfuom = l_v_meinh.
*
*ENDFORM.                    " get_confirmation_qty_new
*
**&---------------------------------------------------------------------
*
**&      Form  get_bom_info
**&---------------------------------------------------------------------
*
*FORM get_bom_info.
*  DATA: l_tabix TYPE sytabix,
*
*        l_v_kausf TYPE kausf,
*
*        l_v_dmeng  TYPE ty_menge,
*        l_v_dmengs TYPE ty_menge,
*        l_v_dmengz TYPE ty_menge,
*
*        l_v_menge TYPE kmpmg,
*
*        l_v_mnglg  TYPE cs_e_mnglg,
*        l_v_mnglgs TYPE cs_e_mnglg,
*        l_v_mnglgz TYPE cs_e_mnglg,
*
*        l_i_bomapp  TYPE STANDARD TABLE OF ty_bomapp,
*        l_wa_bomapp TYPE ty_bomapp,
*
*        l_idx TYPE ttidx.            "NEEL 4/6/2005
*
*  FIELD-SYMBOLS : <l_fs_orders>  TYPE ty_orders,
*                  <l_fs_ordmats> TYPE ty_ordmats.
*
*  IF NOT i_orders[] IS INITIAL.
** this tells users whats happening
*    MOVE 'Extracting BOM Information'(026) TO v_output_text.
*    PERFORM inform_user_of_progress.
*
** Get order related bom appln
*    CLEAR : l_i_bomapp.
*
*    SELECT werks
*           auart
*           capid
*      FROM t399x
*      INTO TABLE l_i_bomapp
*       FOR ALL ENTRIES IN i_orders
*     WHERE werks = i_orders-werks
*       AND auart = i_orders-auart.
*
*    SORT l_i_bomapp BY werks auart.
*
** Get issued materials for all process orders
*    IF i_mseg1 IS INITIAL.
** get materials to process
*      PERFORM get_order_mats.
*
*      i_mseg   = i_mseg1.
*      i_msegs1 = i_msegs.
*    ENDIF.
*
*    LOOP AT i_orders ASSIGNING <l_fs_orders>.
*      DELETE i_mseg WHERE aufnr =  <l_fs_orders>-aufnr
*                      AND matnr <> <l_fs_orders>-plnbez.
*
*      DELETE i_msegs1 WHERE aufnr =  <l_fs_orders>-aufnr
*                        AND matnr <> <l_fs_orders>-plnbez.
*
*
*      CLEAR : l_wa_bomapp.
**** Assign a default in case read fails
*      l_wa_bomapp-capid = 'PI01'.
*      READ TABLE l_i_bomapp INTO l_wa_bomapp
*                            WITH KEY werks = <l_fs_orders>-werks
*                                     auart = <l_fs_orders>-auart
*                            BINARY SEARCH.
**** Get BOM application id
*      <l_fs_orders>-capid = l_wa_bomapp-capid.
*
**** Get list of materials that have been issued
*      LOOP AT i_mseg1 INTO wa_issued_mat
*                      WHERE aufnr = <l_fs_orders>-aufnr
*                        AND bwart IN i_r_bwart.
*        APPEND wa_issued_mat TO i_issued_mat.
*      ENDLOOP.
*    ENDLOOP.
*
*    CLEAR : i_bomdat.
** do BOM explosion and get related BOM data for the materials
*    LOOP AT i_orders ASSIGNING <l_fs_orders>.
**** build key table for later selection from table PLPO,
**** the master recipe table
*      wa_plpo_sel-plnty = <l_fs_orders>-plnty.
*      wa_plpo_sel-plnnr = <l_fs_orders>-plnnr.
*      wa_plpo_sel-zaehl = <l_fs_orders>-zaehl.
*      APPEND wa_plpo_sel TO i_plpo_sel.
*
**** build key table for later selection from table AFRU,
**** the confirmations table
*      wa_afru_sel-rueck = <l_fs_orders>-rueck.
*      APPEND wa_afru_sel TO i_afru_sel.
*
*      l_tabix = sy-tabix.
*
*      CLEAR : wa_tmat , i_stbtmp , wa_bomdat.
**** check if same BOM has been retrieved before
*      READ TABLE i_bomdat INTO wa_bomdat
*                          WITH KEY capid = <l_fs_orders>-capid
*                                   datuv = <l_fs_orders>-sdatv
*                                   mtnrv = <l_fs_orders>-plnbez
*                                   stlal = <l_fs_orders>-stlal
*                                   stlan = <l_fs_orders>-stlan
*                                   werks = <l_fs_orders>-werks.
*      IF sy-subrc = 0.
**** if yes then use it
*        wa_tmat  = wa_bomdat-tmat.
*        i_stbtmp = wa_bomdat-stb.
*
*      ELSE.
**** if no then get BOM explosion
*        CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
*          EXPORTING
*            aumgb                       = 'X'
*            capid                       = <l_fs_orders>-capid
**            datuv                       = <l_fs_orders>-sdatv
**** Begin of change on 31-05-2005
*            datuv                       = <l_fs_orders>-aufld
*            " 31-05-2005
**** End of change on 31-05-2005
*            mbwls                       = 'X'
*            mehrs                       = 'X'
*            mtnrv                       = <l_fs_orders>-plnbez
*            stlal                       = <l_fs_orders>-stlal
*            stlan                       = <l_fs_orders>-stlan
*            werks                       = <l_fs_orders>-werks
*          IMPORTING
*            topmat                      = wa_tmat
*          TABLES
*            stb                         = i_stbtmp
**          matcat                      = i_cmat
*          EXCEPTIONS
*            alt_not_found               = 1
*            call_invalid                = 2
*            material_not_found          = 3
*            missing_authorization       = 4
*            no_bom_found                = 5
*            no_plant_data               = 6
*            no_suitable_bom_found       = 7
*            conversion_error            = 8
*            OTHERS                      = 9.
*        IF sy-subrc = 0.
**** add to BOM buffer table
*          wa_bomdat-capid = <l_fs_orders>-capid.
*          wa_bomdat-datuv = <l_fs_orders>-sdatv.
*          wa_bomdat-mtnrv = <l_fs_orders>-plnbez.
*          wa_bomdat-stlal = <l_fs_orders>-stlal.
*          wa_bomdat-stlan = <l_fs_orders>-stlan.
*          wa_bomdat-werks = <l_fs_orders>-werks.
*          wa_bomdat-tmat  = wa_tmat.
*          wa_bomdat-stb   = i_stbtmp.
*
*          INSERT wa_bomdat INTO TABLE i_bomdat.
*
*          DELETE i_stbtmp WHERE schgt = c_x.
*        ENDIF.
*      ENDIF.
*
*
*      IF NOT i_stbtmp IS INITIAL.
**** First get the primary level values from the exploded BOM
*        LOOP AT i_stbtmp INTO wa_stb WHERE stlal = <l_fs_orders>-stlal
*                                       AND stlan = <l_fs_orders>-stlan
*                                       AND stlty = <l_fs_orders>-stlty
*                                       AND stlnr = <l_fs_orders>-stlnr.
*
*          CHECK wa_stb-postp <> 'N'.
*
*          CLEAR : wa_ordmats.
*          wa_ordmats-aufnr = <l_fs_orders>-aufnr.
*          wa_ordmats-matnr = wa_stb-idnrk.
*          wa_ordmats-mtart = wa_stb-mtart.
*          wa_ordmats-stufe = wa_stb-stufe.
**>>NEEL 4/6/2005
*          wa_ordmats-wegxx = wa_stb-wegxx.
*          wa_ordmats-ttidx = wa_stb-ttidx.
*          wa_ordmats-vwegx = wa_stb-vwegx.
**<<NEEL 4/6/2005
*          wa_ordmats-ojtxb = wa_stb-ojtxb.
*          wa_ordmats-ojtxp = wa_stb-ojtxp.
*
*          wa_ordmats-ausch  = wa_stb-ausch.
**         wa_ordmats-yyzero = wa_stb-yyzero.
*
*          IF NOT wa_stb-ausch IS INITIAL.
*            l_v_kausf = 1 + ( wa_stb-ausch / 100 ).
*          ELSE.
*            l_v_kausf = 1 + ( wa_stb-kausf / 100 ).
*          ENDIF.
*
*          wa_ordmats-kausf  = l_v_kausf.
*
*          wa_ordmats-menge  = wa_stb-menge.
*          wa_ordmats-menges = wa_stb-menge * wa_ordmats-kausf.
**          wa_ordmats-mengez = wa_stb-menge * wa_ordmats-yyzero.
*          wa_ordmats-meins  = wa_stb-meins.
*
*          wa_ordmats-xmeng  = wa_stb-xmeng.
*          wa_ordmats-xmengs = wa_stb-xmeng * wa_ordmats-kausf.
**         wa_ordmats-xmengz = wa_stb-xmeng * wa_ordmats-yyzero.
*
*          wa_ordmats-xmein  = wa_stb-xmein.
*
*          wa_ordmats-mnglg  = wa_stb-mnglg.
*          wa_ordmats-mnglgs = wa_stb-mnglg.
*          wa_ordmats-mnglgz = wa_stb-mnglg.
*          wa_ordmats-mmein  = wa_stb-mmein.
*          wa_ordmats-msign  = wa_stb-msign.
*          wa_ordmats-postp  = wa_stb-postp.
*
*          IF wa_stb-kzkup = space AND wa_stb-msign = '-'.
*            wa_ordmats-byprod = c_x.
*          ENDIF.
*
*          wa_ordmats-stprs = wa_stb-stprs.
*          wa_ordmats-peinh = wa_stb-preih.
*
*          wa_ordmats-bom    = c_x.
*
*          wa_ordmats-stlty = wa_stb-stlty.
*          wa_ordmats-stlnr = wa_stb-stlnr.
*          wa_ordmats-stlkn = wa_stb-stlkn.
*          wa_ordmats-stpoz = wa_stb-stpoz.
*
*          APPEND wa_ordmats TO i_ordmats.
*        ENDLOOP.
*
**** now recurse into exploded BOM to get lower level details
*        LOOP AT i_ordmats ASSIGNING <l_fs_ordmats> WHERE bomd <> c_x.
*
*          IF <l_fs_ordmats>-xmeng > 0.
*            l_v_dmeng  = <l_fs_ordmats>-menge  / <l_fs_ordmats>-xmeng.
*            l_v_dmengs = <l_fs_ordmats>-menges / <l_fs_ordmats>-xmeng.
*            l_v_dmengz = <l_fs_ordmats>-mengez / <l_fs_ordmats>-xmeng.
*
*          ELSE.
*            l_v_dmeng  = 1.
*            l_v_dmengs = 1.
*            l_v_dmengz = 1.
*          ENDIF.
*
*
*          l_idx = <l_fs_ordmats>-stufe + 1.      "NEEL 4/6/2005++
*          LOOP AT i_stbtmp INTO wa_stb
**                           WHERE ojtxb = <l_fs_ordmats>ojtxp. NEEL-
*                      WHERE ttidx = l_idx               "NEEL 4/6/2005
*                        AND vwegx = <l_fs_ordmats>-wegxx.
*            CLEAR : wa_ordmats.
*            wa_ordmats-aufnr = <l_fs_orders>-aufnr.
*            wa_ordmats-matnr = wa_stb-idnrk.
*            wa_ordmats-mtart = wa_stb-mtart.
*            wa_ordmats-stufe = wa_stb-stufe.
**>>NEEL 4/6/2005
*            wa_ordmats-wegxx = wa_stb-wegxx.
*            wa_ordmats-ttidx = wa_stb-ttidx.
*            wa_ordmats-vwegx = wa_stb-vwegx.
**<<NEEL 4/6/2005
*            wa_ordmats-ojtxb = wa_stb-ojtxb.
*            wa_ordmats-ojtxp = wa_stb-ojtxp.
*
*            wa_ordmats-ausch  = wa_stb-ausch.
**           wa_ordmats-yyzero = wa_stb-yyzero.
*
*            IF NOT wa_stb-ausch IS INITIAL.
*              l_v_kausf = 1 + ( wa_stb-ausch / 100 ).
*            ELSE.
*              l_v_kausf = 1 + ( wa_stb-kausf / 100 ).
*            ENDIF.
*            wa_ordmats-kausf  = l_v_kausf.
*
*            l_v_menge = wa_stb-menge * l_v_dmengs.
*            wa_ordmats-menges = l_v_menge * wa_ordmats-kausf.
*
*            l_v_menge = wa_stb-menge * l_v_dmengz.
**           wa_ordmats-mengez = l_v_menge * wa_ordmats-yyzero.
*
*            l_v_menge = wa_stb-menge * l_v_dmeng.
*            wa_ordmats-menge = l_v_menge.
*
*            wa_ordmats-meins = wa_stb-meins.
*
*            l_v_mnglg  = wa_ordmats-menge.
*            l_v_mnglgs = wa_ordmats-menges.
*            l_v_mnglgz = wa_ordmats-mengez.
*
*            IF wa_stb-meins = wa_stb-mmein.
*              wa_ordmats-mnglg  = l_v_mnglg.
*              wa_ordmats-mnglgs = l_v_mnglgs.
*              wa_ordmats-mnglgz = l_v_mnglgz.
*
*            ELSE.
** convert BOM quantity to base UoM
*              PERFORM conv_to_from_base USING 'X'
*                                              wa_ordmats-matnr
*                                              l_v_mnglg
*                                              wa_ordmats-meins
*                                              wa_ordmats-mmein
*                                     CHANGING wa_ordmats-mnglg
*                                              v_conv_rc.
*
*              PERFORM conv_to_from_base USING 'X'
*                                              wa_ordmats-matnr
*                                              l_v_mnglgs
*                                              wa_ordmats-meins
*                                              wa_ordmats-mmein
*                                     CHANGING wa_ordmats-mnglgs
*                                              v_conv_rc.
*
*              PERFORM conv_to_from_base USING 'X'
*                                              wa_ordmats-matnr
*                                              l_v_mnglgz
*                                              wa_ordmats-meins
*                                              wa_ordmats-mmein
*                                     CHANGING wa_ordmats-mnglgz
*                                              v_conv_rc.
*            ENDIF.
*            wa_ordmats-mmein = wa_stb-mmein.
*            wa_ordmats-msign = wa_stb-msign.
*
*            wa_ordmats-xmeng  = wa_stb-xmeng.
*            wa_ordmats-xmengs = wa_stb-xmeng * wa_ordmats-kausf.
**           wa_ordmats-xmengz = wa_stb-xmeng * wa_ordmats-yyzero.
*
*            wa_ordmats-xmein = wa_stb-xmein.
*
*            wa_ordmats-stprs = wa_stb-stprs.
*            wa_ordmats-peinh = wa_stb-preih.
**           wa_ordmats-yyzero = wa_stb-yyzero.
*            wa_ordmats-bom    = c_x.
*
*            wa_ordmats-stlty = wa_stb-stlty.
*            wa_ordmats-stlnr = wa_stb-stlnr.
*            wa_ordmats-stlkn = wa_stb-stlkn.
*            wa_ordmats-stpoz = wa_stb-stpoz.
*
*            APPEND wa_ordmats TO i_ordmats.
*          ENDLOOP.
*
*          <l_fs_ordmats>-bomd = c_x.
*        ENDLOOP.
*
*        <l_fs_orders>-maktx = wa_tmat-maktx.
*        <l_fs_orders>-bmeng = wa_tmat-bmeng.
*        <l_fs_orders>-bmein = wa_tmat-bmein.
*        <l_fs_orders>-kausf = wa_tmat-kausf.
*
*        IF <l_fs_orders>-bmein <> <l_fs_orders>-bsuom.
** convert BOM base quantity to base UoM
*          PERFORM conv_to_from_base USING 'X'
*                                          <l_fs_orders>-plnbez
*                                          <l_fs_orders>-bmeng
*                                          <l_fs_orders>-bmein
*                                          <l_fs_orders>-bsuom
*                                 CHANGING <l_fs_orders>-bbmeng
*                                          v_conv_rc.
*        ELSE.
*          <l_fs_orders>-bbmeng = <l_fs_orders>-bmeng.
*        ENDIF.
*      ENDIF.
*    ENDLOOP.
*
*    SORT i_ordmats BY aufnr matnr.
*
** Selecting reservations for order
*    SELECT rsnum rspos rsart xloek matnr werks bdmng meins shkzg
*           aufnr dumps aufpl vornr aplzl
*           postp kzkup rgekz ausch
*           stlty stlnr stlkn stpoz bwart
*      FROM resb INTO TABLE i_resb
*       FOR ALL ENTRIES IN i_orders
*     WHERE rsnum = i_orders-rsnum
**       AND xloek = ' '
*       AND aufnr = i_orders-aufnr
*       AND bdmng > 0
*       AND dumps = space
*       AND postp <> 'N'
*       AND schgt = space.
*
*    LOOP AT i_resb INTO wa_resb.
*      READ TABLE i_issued_mat INTO wa_issued_mat
*                              WITH KEY matnr = wa_resb-matnr.
*      CHECK sy-subrc <> 0.
**** If a material was issued but is not part of the PrO
**** reservations, add it to list
*      CLEAR : wa_issued_mat.
*      wa_issued_mat-matnr = wa_resb-matnr.
*      wa_issued_mat-werks = wa_resb-werks.
*      APPEND wa_issued_mat TO i_issued_mat.
*    ENDLOOP.
*
** we just need the issued mat numbers not captured by BOM explosion
*    SORT i_issued_mat BY matnr.
*    DELETE ADJACENT DUPLICATES FROM i_issued_mat COMPARING matnr.
*
*    IF NOT i_issued_mat IS INITIAL.
** get material master data
*      SELECT matnr
*             mtart
*             meins
*             gewei
*        FROM mara
*   APPENDING TABLE i_mara
*         FOR ALL ENTRIES IN i_issued_mat
*       WHERE matnr = i_issued_mat-matnr.
*
** getting pricing data
*      CLEAR : i_mbew1 , i_material_des.
*      SELECT matnr bwkey stprs peinh
*        FROM mbew
*        INTO TABLE i_mbew1
*         FOR ALL ENTRIES IN i_issued_mat
*       WHERE matnr = i_issued_mat-matnr
*         AND bwkey = i_issued_mat-werks.
*
** Selecting material descriptions
*      SELECT matnr maktx
*        FROM makt
*        INTO TABLE i_material_des
*         FOR ALL ENTRIES IN i_issued_mat
*       WHERE spras = sy-langu
*         AND matnr = i_issued_mat-matnr.
*    ENDIF.
*
** prepare selection table for selecting from AFRU
*    LOOP AT i_afvc INTO wa_afvc.
*      wa_plpo_sel-plnty = wa_afvc-plnty.
*      wa_plpo_sel-plnnr = wa_afvc-plnnr.
*      wa_plpo_sel-plnkn = wa_afvc-plnkn.
*      wa_plpo_sel-zaehl = wa_afvc-zaehl.
*      APPEND wa_plpo_sel TO i_plpo_sel.
*
*      wa_afru_sel-rueck = wa_afvc-rueck.
*      APPEND wa_afru_sel TO i_afru_sel.
*    ENDLOOP.
*
*    SORT : i_plpo_sel , i_afru_sel.
*
*    DELETE ADJACENT DUPLICATES FROM i_plpo_sel.
*    DELETE ADJACENT DUPLICATES FROM i_afru_sel.
*
** Retrieve task list information of operations/activity from PLPO table
*    SELECT *
*      FROM plpo
*      INTO TABLE i_plpo
*       FOR ALL ENTRIES IN i_plpo_sel
*     WHERE plnty = i_plpo_sel-plnty
*       AND plnnr = i_plpo_sel-plnnr
*       AND zaehl = i_plpo_sel-zaehl.
*    IF sy-subrc = 0.
*      SORT i_plpo BY plnty plnnr plnkn datuv DESCENDING.
*    ENDIF.
** get confirmation data for order and its items
*    SELECT rueck
*           rmzhl
*           ism01
*           ile01
*           ism02
*           ile02
*           ism03
*           ile03
*           ism04
*           ile04
*           ism05
*           ile05
*           ism06
*           ile06
*           stokz
*      FROM afru
*      INTO TABLE i_ord_conf
*       FOR ALL ENTRIES IN i_afru_sel
*     WHERE rueck = i_afru_sel-rueck.
*  ENDIF.
*
*  IF NOT i_afvc IS INITIAL.
*    LOOP AT i_afvc INTO wa_afvc.
**** get master recipe records for selected phases
*      LOOP AT i_plpo INTO wa_plpo WHERE plnty = wa_afvc-plnty
*                                    AND plnnr = wa_afvc-plnnr
*                                    AND plnkn = wa_afvc-plnkn
*                                    AND zaehl = wa_afvc-zaehl.
*        APPEND wa_plpo TO i_plpo1.
*      ENDLOOP.
*
**** get confirmation records for selected phases
*      LOOP AT i_ord_conf INTO wa_ord_conf WHERE rueck = wa_afvc-rueck.
*        APPEND wa_ord_conf TO i_ord_conf1.
*      ENDLOOP.
*    ENDLOOP.
*
*    SORT i_plpo1 BY plnty plnnr plnkn zaehl datuv DESCENDING.
*  ENDIF.
*
*  UNASSIGN : <l_fs_orders>.
*ENDFORM.                    " get_bom_info
*
**&--------------------------------------------------------------------*
**&      Form  build_output_tabs
**&--------------------------------------------------------------------*
**       text
**---------------------------------------------------------------------*
*FORM build_output_tabs.
*  DATA : l_qty   TYPE gamng,
*         l_effic TYPE vgwrt,
*         l_tmp   TYPE vgwrt,
*         l_tmp1  TYPE vgwrt,
*
*         l_lmnga  TYPE lmnga,
*
*         l_v_rc    TYPE char1,
*         l_v_kausf TYPE kausf,
*         l_v_sumi  TYPE char1,
*
*         l_v_smeng  TYPE ty_menge,
*         l_v_smengs TYPE ty_menge,
*         l_v_smengz TYPE ty_menge,
*
*         l_wa_afvv  TYPE ty_afvv.
*
*  FIELD-SYMBOLS : <l_fs_resb> TYPE ty_resb.
*
*  MOVE 'Formatting Output'(027) TO v_output_text.
*  PERFORM inform_user_of_progress.
*
*  CLEAR: i_marc1.
*  SELECT matnr
*         werks
*         frtme
*    FROM marc
*    INTO TABLE i_marc1
*     FOR ALL ENTRIES IN i_orders
*   WHERE matnr = i_orders-plnbez
*     AND werks = i_orders-werks.
** Not required to handle, ok if prod unit not found
*
** get parameter IDs
*  SELECT vgwts
*         par01
*         par02
*         par03
*         par04
*         par05
*         par06
*    FROM tc21
*    INTO TABLE i_param
*     FOR ALL ENTRIES IN i_afvc
*   WHERE vgwts = i_afvc-vgwts.
*
*  IF sy-subrc = 0.
** get parameter ID texts
*    SELECT parid
*           txtlg
*      FROM tc20t
*      INTO TABLE i_param_key
*       FOR ALL ENTRIES IN i_param
*     WHERE spras = sy-langu
*       AND ( parid = i_param-par01
*          OR parid = i_param-par02
*          OR parid = i_param-par03
*          OR parid = i_param-par04
*          OR parid = i_param-par05
*          OR parid = i_param-par06 ).
*  ENDIF.
*
** Selecting Work centers descriptions
*  SELECT objid ktext
*    FROM crtx
*    INTO TABLE i_wc_text
*     FOR ALL ENTRIES IN i_afvc
*   WHERE objty = c_objtyp
*     AND objid = i_afvc-arbid
*     AND spras = sy-langu.
**Work centers descriptions are optional
*
*  SELECT matnr bwkey stprs peinh
*    FROM mbew
*    APPENDING TABLE i_mbew1
*     FOR ALL ENTRIES IN i_orders
*   WHERE matnr = i_orders-plnbez
*     AND bwkey = i_orders-werks.
*
*  LOOP AT i_orders INTO wa_orders.
****
**** Build Order Table
****
*    wa_h_ord-aufnr = wa_orders-aufnr.
*
*    wa_h_ord-gltrp = wa_orders-gltrp.
*    wa_h_ord-gstrp = wa_orders-gstrp.
*
*    wa_h_ord-plnbez = wa_orders-plnbez.
*    wa_h_ord-maktx  = wa_orders-maktx.
*
*    wa_h_ord-lmnga  = wa_orders-lmnga.
*    wa_h_ord-blmnga = wa_orders-blmnga.
*    wa_h_ord-bmenge = wa_orders-bmenge.
*    wa_h_ord-bgamng = wa_orders-bgamng.
*    wa_h_ord-bbmeng = wa_orders-bbmeng.
*
*    wa_h_ord-gruom = wa_orders-gruom.
*    wa_h_ord-cfuom = wa_orders-cfuom.
*    wa_h_ord-bsuom = wa_orders-bsuom.
*
*    CLEAR : wa_marc1.
*    READ TABLE i_marc1 INTO wa_marc1 WITH KEY matnr = wa_orders-plnbez
*                                              werks = wa_orders-werks.
*    wa_h_ord-frtme = wa_marc1-frtme.
*    wa_h_ord-gewei = wa_orders-gewei.
*    wa_h_ord-ntgew = wa_orders-ntgew.
*
*    IF rb_pland = c_x.
** Planned Production Quantities
*      wa_h_ord-prduom = wa_h_ord-frtme.
*      wa_h_ord-prdqty = wa_h_ord-bgamng.
*    ELSE.
** Actual Production Quantities
*      IF rb_prod = c_x.
**** Produced Qty
*        wa_h_ord-prdqty = wa_h_ord-bmenge.
*        wa_h_ord-prduom = wa_h_ord-gruom.
*      ELSE.
**** Confirmed Qty
*        wa_h_ord-prdqty = wa_h_ord-blmnga.
*        wa_h_ord-prduom = wa_h_ord-cfuom.
*      ENDIF.
*    ENDIF.
*
*    wa_h_ord-bprdqty = wa_h_ord-prdqty.
*
*    IF wa_h_ord-prduom <> wa_h_ord-bsuom.
*      l_qty = wa_h_ord-prdqty.
*      PERFORM conv_to_from_base USING ' '
*                                      wa_h_ord-plnbez
*                                      l_qty
*                                      wa_h_ord-prduom
*                                      wa_h_ord-bsuom
*                             CHANGING wa_h_ord-prdqty
*                                      v_conv_rc.
*      IF v_conv_rc = 'X'.
*        wa_h_ord-prdqty = l_qty.
*        wa_h_ord-prduom = wa_h_ord-bsuom.
*      ENDIF.
*    ENDIF.
*
** Resource Information
*    CLEAR : wa_afvc , wa_crhd , wa_wc_text.
*    READ TABLE i_afvc INTO wa_afvc WITH KEY aufpl = wa_orders-aufpl
*                                            steus = 'YBN1'.
*    IF sy-subrc = 0.
*      READ TABLE i_crhd INTO wa_crhd WITH KEY objid = wa_afvc-arbid.
*      READ TABLE i_wc_text INTO wa_wc_text WITH KEY objid =
*      wa_afvc-arbid.
*    ENDIF.
*
*    wa_h_ord-botlnck = wa_crhd-arbpl.
*    wa_h_ord-resdesc = wa_wc_text-ktext.
*
** Expected Line Efficiency
*    CLEAR : i_plpo2 , l_effic.
*    LOOP AT i_plpo1 INTO wa_plpo WHERE plnty = wa_orders-plnty
*                                   AND plnnr = wa_orders-plnnr
*                                   AND steus = 'YBN1'.
*      IF NOT wa_plpo-vgw02 IS INITIAL.
*        l_effic = wa_plpo-usr04.
*
*        wa_plpo2 = wa_plpo.
*        APPEND wa_plpo2 TO i_plpo2.
*      ENDIF.
*    ENDLOOP.
*
*    wa_h_ord-el_effc = l_effic.
*
** Actual Line Efficiency
*    CLEAR : l_tmp , l_tmp1 , l_effic.
*    LOOP AT i_plpo2 INTO wa_plpo2.
*      CLEAR: wa_afvc, wa_afvv , l_effic.
*      READ TABLE i_afvc INTO wa_afvc WITH KEY plnty = wa_plpo2-plnty
*                                              plnnr = wa_plpo2-plnnr
*                                              plnkn = wa_plpo2-plnkn
*                                              zaehl = wa_plpo2-zaehl
*                                              aufpl = wa_orders-aufpl.
*      IF sy-subrc = 0.
*        READ TABLE i_afvv INTO wa_afvv WITH KEY aufpl = wa_afvc-aufpl
*                                                aplzl = wa_afvc-aplzl.
*        IF wa_plpo2-vgw02 <> 0.
*          l_tmp = wa_plpo2-bmsch / wa_plpo2-vgw02.
*
*          IF l_tmp <> 0.
*            l_tmp1 = wa_afvv-lmnga / l_tmp.
*
*            IF wa_afvv-ism02 <> 0.
*              l_tmp1 = ( l_tmp1 / wa_afvv-ism02 ) * 100.
*              MOVE l_tmp1 TO l_effic.
*            ENDIF.
*          ENDIF.
*        ENDIF.
*      ENDIF.
*    ENDLOOP.
*
*    wa_h_ord-ac_effc = l_effic.
*
*    CLEAR : wa_mbew1.
*    READ TABLE i_mbew1 INTO wa_mbew1 WITH KEY matnr = wa_orders-plnbez
*                                              bwkey = wa_orders-werks.
*    wa_h_ord-stprs = wa_mbew1-stprs.
*    wa_h_ord-peinh = wa_mbew1-peinh.
*
*    APPEND wa_h_ord TO i_h_ord.
*
****
**** Build Phase Table
****
*    LOOP AT i_afvc INTO wa_afvc WHERE aufnr = wa_orders-aufnr
*                                  AND aufpl = wa_orders-aufpl.
*      CLEAR : wa_h_phs.
*
*      wa_h_phs-aufnr = wa_afvc-aufnr.
*      wa_h_phs-aufpl = wa_afvc-aufpl.
*      wa_h_phs-aplzl = wa_afvc-aplzl.
*      wa_h_phs-vornr = wa_afvc-vornr.
*
*      wa_h_phs-steus = wa_afvc-steus.
*      wa_h_phs-rueck = wa_afvc-rueck.
*      wa_h_phs-vgwts = wa_afvc-vgwts.
*      wa_h_phs-ltxa1 = wa_afvc-ltxa1.
*
*      IF wa_afvc-cfuom IS INITIAL.
*        CLEAR : wa_afvv, l_lmnga.
*        LOOP AT i_afvv INTO l_wa_afvv WHERE aufpl = wa_afvc-aufpl
*                                        AND aplzl = wa_afvc-aplzl.
*          wa_h_phs-lmnga = wa_h_phs-lmnga + l_wa_afvv-lmnga.
*        ENDLOOP.
*        wa_h_phs-cfuom = l_wa_afvv-meinh.
*
*      ELSE.
*        wa_h_phs-lmnga = wa_afvc-lmnga.
*        wa_h_phs-cfuom = wa_afvc-cfuom.
*
** afvv contains std vals for operation qty
*        CLEAR : l_wa_afvv.
*        READ TABLE i_afvv INTO l_wa_afvv
*                          WITH KEY aufpl = wa_afvc-aufpl
*                                   aplzl = wa_afvc-aplzl.
*      ENDIF.
*
*      wa_h_phs-bsuom = wa_h_ord-bsuom.
*      wa_h_phs-gewei = wa_h_ord-gewei.
*      wa_h_phs-ntgew = wa_h_ord-ntgew.
*
*      IF wa_h_phs-cfuom <> wa_h_phs-bsuom.
*        l_lmnga = wa_h_phs-lmnga.
*        PERFORM conv_to_from_base USING 'X'
*                                        wa_h_ord-plnbez
*                                        l_lmnga
*                                        wa_h_phs-cfuom
*                                        wa_h_phs-bsuom
*                               CHANGING wa_h_phs-blmnga
*                                        v_conv_rc.
*        IF v_conv_rc = 'X'.
*          CLEAR : wa_h_phs-blmnga.
*        ENDIF.
*
*      ELSE.
*        wa_h_phs-blmnga = wa_h_phs-lmnga.
*      ENDIF.
*
*      IF rb_actl = c_x AND rb_conf = c_x.
*        wa_h_phs-prduom  = wa_h_ord-cfuom.
*        wa_h_phs-prdqty  = wa_h_ord-lmnga.
*        wa_h_phs-bprdqty = wa_h_ord-blmnga.
*
*      ELSE.
*        wa_h_phs-prduom  = wa_h_ord-prduom.
*        wa_h_phs-prdqty  = wa_h_ord-prdqty.
*        wa_h_phs-bprdqty = wa_h_ord-bprdqty.
*      ENDIF.
*
*      wa_h_phs-arbid = wa_afvc-arbid.
*
*      CLEAR : wa_crhd , wa_wc_text.
*      READ TABLE i_crhd INTO wa_crhd WITH KEY objid = wa_afvc-arbid.
*
*      READ TABLE i_wc_text INTO wa_wc_text
*                           WITH KEY objid = wa_afvc-arbid.
*
*      wa_h_phs-arbpl = wa_crhd-arbpl.
*      wa_h_phs-ktext = wa_wc_text-ktext.
*
*      IF wa_h_phs-steus = 'YBN1'.
** Expected Line Efficiency
*        CLEAR : i_plpo2 , l_effic.
*        LOOP AT i_plpo1 INTO wa_plpo WHERE plnty = wa_afvc-plnty
*                                       AND plnnr = wa_afvc-plnnr
*                                       AND plnkn = wa_afvc-plnkn
*                                       AND zaehl = wa_afvc-zaehl
*                                       AND steus = 'YBN1'.
*          IF NOT wa_plpo-vgw02 IS INITIAL.
*            l_effic = wa_plpo-usr04.
*
*            wa_plpo2 = wa_plpo.
*            APPEND wa_plpo2 TO i_plpo2.
*          ENDIF.
*        ENDLOOP.
*
*        wa_h_phs-el_effc = l_effic.
*
** Actual Line Efficiency
*        CLEAR : l_tmp , l_tmp1 , l_effic.
*        LOOP AT i_plpo2 INTO wa_plpo2.
*          CLEAR: l_effic.
*          IF wa_plpo2-vgw02 <> 0.
*            l_tmp = wa_plpo2-bmsch / wa_plpo2-vgw02.
*
*            IF l_tmp <> 0.
*              l_tmp1 = l_wa_afvv-lmnga / l_tmp.
*
*              IF l_wa_afvv-ism02 <> 0.
*                l_tmp1 = ( l_tmp1 / l_wa_afvv-ism02 ) * 100.
*                MOVE l_tmp1 TO l_effic.
*
*                wa_h_phs-runtime = c_x.
*              ENDIF.
*            ENDIF.
*          ENDIF.
*        ENDLOOP.
*
*        wa_h_phs-ac_effc = l_effic.
*      ENDIF.
****
**** Build Phase-Activity Table
****
*      CLEAR : l_v_rc.
*      PERFORM build_act_tab USING    wa_orders-aufnr  wa_orders-plnbez
*                                     wa_h_phs-bprdqty wa_h_phs-bsuom
*                                     wa_orders-gmein
*                                     wa_h_phs-el_effc wa_afvc
*                                     l_wa_afvv
*                            CHANGING l_v_rc.
*      IF l_v_rc = c_x.
*        APPEND wa_h_phs TO i_h_phs.
*      ENDIF.
****
**** Build Material-Phase Table
****
*      LOOP AT i_resb ASSIGNING <l_fs_resb>
*                         WHERE aufnr = wa_orders-aufnr.
*
*        IF <l_fs_resb>-aufpl = wa_afvc-aufpl AND
*           <l_fs_resb>-vornr = wa_afvc-vornr AND
*           <l_fs_resb>-aplzl = wa_afvc-aplzl.
*
*          CLEAR : wa_resb.
*          PERFORM build_mat_tab USING <l_fs_resb>.
*          <l_fs_resb>-flagp = c_y.
*
*        ELSEIF <l_fs_resb>-flagp IS INITIAL.
*          <l_fs_resb>-flagp = 'N'.
*        ENDIF.
*      ENDLOOP.
*    ENDLOOP.
*
*****
***** Add Extra Materials to Material-Phase Table
*****
*    LOOP AT i_resb ASSIGNING <l_fs_resb>
*                       WHERE aufnr = wa_orders-aufnr
*                         AND flagp = 'N'.
*      CLEAR : wa_resb.
*      PERFORM build_mat_tab USING <l_fs_resb>.
*    ENDLOOP.
*  ENDLOOP.
*
*  SORT i_h_ord BY aufnr.
*  SORT i_h_mat BY aufnr aufpl aplzl matnr byprod.
*
*  SORT i_h_phs BY aufnr vornr.
*  SORT i_h_act BY aufnr vornr.
*
*  LOOP AT i_h_mat INTO wa_h_mat.
*    CLEAR : l_v_sumi.
*
*    AT END OF byprod.
*      l_v_sumi = c_x.
*    ENDAT.
*
*    wa_h_mat-sumi = l_v_sumi.
*
*    MODIFY i_h_mat FROM wa_h_mat TRANSPORTING sumi.
*  ENDLOOP.
*
*ENDFORM.                    "build_output_tabs
*
*
**&--------------------------------------------------------------------*
**&      Form  build_mat_tab
**&--------------------------------------------------------------------*
**       text
**---------------------------------------------------------------------*
*FORM build_mat_tab USING fp_resb TYPE ty_resb.
*
*  DATA : l_v_kausf TYPE kausf,
*
*         l_v_smeng  TYPE ty_menge,
*         l_v_smengs TYPE ty_menge,
*         l_v_smengz TYPE ty_menge.
*
*  wa_resb = fp_resb.
*
*  CLEAR : wa_h_mat , l_v_smeng , l_v_smengs ,
*          l_v_smengz.
*
*  CHECK wa_resb-postp <> 'N' AND
*        NOT ( wa_resb-kzkup = c_x AND
*              wa_resb-matnr = wa_h_ord-plnbez ).
*
*  wa_h_mat-aufnr = wa_resb-aufnr.
*  wa_h_mat-aufpl = wa_resb-aufpl.
*  wa_h_mat-aplzl = wa_resb-aplzl.
*  wa_h_mat-vornr = wa_resb-vornr.
*
*  wa_h_mat-matnr = wa_resb-matnr.
*
*  CLEAR : wa_mara.
*  READ TABLE i_mara INTO wa_mara WITH KEY matnr = wa_h_mat-matnr.
*
*  CLEAR : wa_msegs.
*  READ TABLE i_msegs INTO wa_msegs WITH KEY aufnr = wa_h_mat-aufnr
*                                            matnr = wa_h_mat-matnr
*                                            bwart = wa_resb-bwart.
*  IF sy-subrc <> 0.
*    READ TABLE i_msegs INTO wa_msegs WITH KEY aufnr = wa_h_mat-aufnr
*                                              matnr = wa_h_mat-matnr.
*  ENDIF.
*
*  CLEAR : wa_ordmats.
*  READ TABLE i_ordmats INTO wa_ordmats
*                       WITH KEY aufnr = wa_resb-aufnr
*                                matnr = wa_resb-matnr
*                                stlty = wa_resb-stlty
*                                stlnr = wa_resb-stlnr
*                                stlkn = wa_resb-stlkn
*                                stpoz = wa_resb-stpoz.
*  IF sy-subrc = 0.
*    wa_h_mat-maktx = wa_ordmats-ojtxp.
*
*    wa_h_mat-stprs = wa_ordmats-stprs.
*    wa_h_mat-peinh = wa_ordmats-peinh.
*
*    wa_h_mat-bomuom = wa_ordmats-meins.
*
*    IF wa_orders-bbmeng <> 0.
*      l_v_smeng  = wa_ordmats-mnglg  / wa_orders-bbmeng.
*      l_v_smengs = wa_ordmats-mnglgs / wa_orders-bbmeng.
*      l_v_smengz = wa_ordmats-mnglgz / wa_orders-bbmeng.
*    ENDIF.
*
*    wa_h_mat-byprod = wa_ordmats-byprod.
*  ELSE.
*    CLEAR : wa_mbew1.
*    READ TABLE i_mbew1 INTO wa_mbew1
*                       WITH KEY matnr = wa_h_mat-matnr
*                                bwkey = p_werks.
*    CLEAR : wa_material_des.
*    READ TABLE i_material_des INTO wa_material_des
*                              WITH KEY matnr = wa_h_mat-matnr.
*
*    wa_h_mat-maktx = wa_material_des-maktx.
*
*    wa_h_mat-stprs = wa_mbew1-stprs.
*    wa_h_mat-peinh = wa_mbew1-peinh.
*
*    wa_h_mat-bomuom = wa_resb-meins.
*
*    wa_resb-bmeins = wa_mara-meins.
*    IF wa_mara-meins <> wa_resb-meins.
*      PERFORM conv_to_from_base USING 'X'
*                                      wa_resb-matnr
*                                      wa_resb-bdmng
*                                      wa_resb-meins
*                                      wa_mara-meins
*                             CHANGING wa_resb-bbdmng
*                                      v_conv_rc.
*      IF v_conv_rc = 'X'.
*        CLEAR : wa_resb-bbdmng.
*      ENDIF.
*
*    ELSE.
*      wa_resb-bbdmng = wa_resb-bdmng.
*    ENDIF.
*
*    wa_ordmats-rgekz = wa_resb-rgekz.
*  ENDIF.
*
*  IF rb_nflsh <> c_x OR wa_ordmats-rgekz EQ c_x.
*    wa_h_mat-stdusg  = l_v_smeng  * wa_h_ord-bprdqty.
*    wa_h_mat-stdusgs = l_v_smengs * wa_h_ord-bprdqty.
*    wa_h_mat-stdusgz = l_v_smengz * wa_h_ord-bprdqty.
*  ELSE.
*    CLEAR : wa_h_mat-stdusg.
*  ENDIF.
*
*  IF wa_h_mat-byprod = c_x.
*    wa_h_mat-actusg = wa_msegs-bmenge5.
*
*  ELSEIF wa_resb-kzkup = c_x.
*    wa_h_mat-actusg = 0 - wa_msegs-bmenge1.
*
*  ELSE.
*    wa_h_mat-actusg = wa_msegs-bmenge2.
*  ENDIF.
*
*  wa_h_mat-bsuom = wa_mara-meins.
*  wa_h_mat-gewei = wa_mara-gewei.
*  wa_h_mat-ntgew = wa_mara-ntgew.
*
*  IF wa_h_mat-actusg <> 0.
*    wa_h_mat-gruom = wa_msegs-erfme.
*  ENDIF.
*
*  wa_h_mat-bwart = wa_resb-bwart.                     "NEEL 30/06/2005
*
*  APPEND wa_h_mat TO i_h_mat.
*
*  wa_matn-matnr = wa_h_mat-matnr.
*  wa_matn-bwart = wa_h_mat-bwart.                           "23-06-2005
*
*  COLLECT wa_matn INTO i_matn.
*
*ENDFORM.                    "build_mat_tab
*
**&--------------------------------------------------------------------*
**&      Form  build_act_tab
**&--------------------------------------------------------------------*
**       text
**---------------------------------------------------------------------*
*FORM build_act_tab USING    fp_aufnr TYPE aufnr
*                            fp_matnr TYPE matnr
*                            fp_bqty  TYPE gamng
*                            fp_buom  TYPE meins
*                            fp_gmein TYPE meins
*                            fp_effic TYPE vgwrt
*                            fp_afvc  TYPE ty_afvc
*                            fp_afvv  TYPE ty_afvv
*                   CHANGING fp_rc    TYPE char1.
*
*  DATA : l_ism01 TYPE ru_ismng,
*         l_ile01 TYPE co_ismngeh,
*         l_ism02 TYPE ru_ismng,
*         l_ile02 TYPE co_ismngeh,
*         l_ism03 TYPE ru_ismng,
*         l_ile03 TYPE co_ismngeh,
*         l_ism04 TYPE ru_ismng,
*         l_ile04 TYPE co_ismngeh,
*         l_ism05 TYPE ru_ismng,
*         l_ile05 TYPE co_ismngeh,
*         l_ism06 TYPE ru_ismng,
*         l_ile06 TYPE co_ismngeh,
*
*         l_effic TYPE vgwrt,
*
*         l_v_bmsch TYPE bmsch,
*         l_pqty    TYPE gamng.
*
*  DATA: l_vgw01 TYPE vgwrt,
*        l_vgw02 TYPE vgwrt,
*        l_vgw03 TYPE vgwrt,
*        l_vgw04 TYPE vgwrt,
*        l_vgw05 TYPE vgwrt,
*        l_vgw06 TYPE vgwrt.
*
*
*
*  CLEAR : wa_h_act.
*
*  wa_h_act-aufnr = fp_aufnr.
*  wa_h_act-aufpl = fp_afvc-aufpl.
*  wa_h_act-aplzl = fp_afvc-aplzl.
*  wa_h_act-vornr = fp_afvc-vornr.
*
*  wa_h_act-vgwts = fp_afvc-vgwts.
*
*  l_effic = fp_effic / 100.
*  IF l_effic = 0.
*    l_effic = 1.
*  ENDIF.
*
*  wa_afvv = fp_afvv.
*  CHECK NOT wa_afvv IS INITIAL.
*
*  wa_h_act-mgvrg = wa_afvv-mgvrg.
*  wa_h_act-meinh = wa_afvv-meinh.
*  wa_h_act-bmsch = wa_afvv-bmsch.
*
*  CLEAR : wa_param.
*  READ TABLE i_param INTO wa_param WITH KEY vgwts = wa_h_act-vgwts.
*
** Actual Usage
*  CLEAR : wa_ord_conf1.
*  LOOP AT i_ord_conf1 INTO wa_ord_conf1 WHERE rueck = fp_afvc-rueck.
*    IF wa_ord_conf1-stokz IS INITIAL.
*      l_ism01 = l_ism01 + wa_ord_conf1-ism01.
*      l_ism02 = l_ism02 + wa_ord_conf1-ism02.
*      l_ism03 = l_ism03 + wa_ord_conf1-ism03.
*      l_ism04 = l_ism04 + wa_ord_conf1-ism04.
*      l_ism05 = l_ism05 + wa_ord_conf1-ism05.
*      l_ism06 = l_ism06 + wa_ord_conf1-ism06.
*    ELSE.
*      l_ism01 = l_ism01 - wa_ord_conf1-ism01.
*      l_ism02 = l_ism02 - wa_ord_conf1-ism02.
*      l_ism03 = l_ism03 - wa_ord_conf1-ism03.
*      l_ism04 = l_ism04 - wa_ord_conf1-ism04.
*      l_ism05 = l_ism05 - wa_ord_conf1-ism05.
*      l_ism06 = l_ism06 - wa_ord_conf1-ism06.
*    ENDIF.
*  ENDLOOP.
*
*  l_ile01 = wa_ord_conf1-ile01.
*  l_ile02 = wa_ord_conf1-ile02.
*  l_ile03 = wa_ord_conf1-ile03.
*  l_ile04 = wa_ord_conf1-ile04.
*  l_ile05 = wa_ord_conf1-ile05.
*  l_ile06 = wa_ord_conf1-ile06.
*
*  CLEAR : fp_rc , l_pqty.
*
*  l_pqty    = fp_bqty.
*  l_v_bmsch = wa_afvv-bmsch.
*
*  IF wa_afvv-umren > 0.
*    l_v_bmsch = l_v_bmsch * ( wa_afvv-umrez / wa_afvv-umren ).
*  ENDIF.
*
*  IF wa_afvv-meinh <> fp_buom.
*    PERFORM conv_to_from_base USING 'X'
*                                    fp_matnr
*                                    l_v_bmsch
*                                    wa_afvv-meinh
*                                    fp_buom
*                           CHANGING wa_afvv-bmsch
*                                    v_conv_rc.
*    IF v_conv_rc = 'X'.
*      wa_afvv-bmsch = l_v_bmsch.
*    ENDIF.
*
**** Begin of Change on 25-05-2005
*
*    IF fp_afvc-vgwts+0(3) = 'YGE'.
*      PERFORM conv_to_from_base USING 'X'
*                                      fp_matnr
*                                      wa_afvv-vgw01
*                                      wa_afvv-meinh
*                                      fp_buom
*                             CHANGING l_vgw01
*                                      v_conv_rc.
*      IF v_conv_rc = space.
*        wa_afvv-vgw01 = l_vgw01.
*      ENDIF.
*    ENDIF.
*
*    PERFORM conv_to_from_base USING 'X'
*                                     fp_matnr
*                                     wa_afvv-vgw02
*                                     wa_afvv-meinh
*                                     fp_buom
*                            CHANGING l_vgw02
*                                     v_conv_rc.
*    IF v_conv_rc = space.
*      wa_afvv-vgw02 = l_vgw02.
*    ENDIF.
*
*    IF fp_afvc-vgwts+0(3) = 'YGE'.
*      PERFORM conv_to_from_base USING 'X'
*                                       fp_matnr
*                                       wa_afvv-vgw03
*                                       wa_afvv-meinh
*                                       fp_buom
*                              CHANGING l_vgw03
*                                       v_conv_rc.
*      IF v_conv_rc = space.
*        wa_afvv-vgw03 = l_vgw03.
*      ENDIF.
*    ENDIF.
*
*    PERFORM conv_to_from_base USING 'X'
*                                     fp_matnr
*                                     wa_afvv-vgw04
*                                     wa_afvv-meinh
*                                     fp_buom
*                            CHANGING l_vgw04
*                                     v_conv_rc.
*    IF v_conv_rc = space.
*      wa_afvv-vgw04 = l_vgw04.
*    ENDIF.
*
*    PERFORM conv_to_from_base USING 'X'
*                                     fp_matnr
*                                     wa_afvv-vgw05
*                                     wa_afvv-meinh
*                                     fp_buom
*                            CHANGING l_vgw05
*                                     v_conv_rc.
*    IF v_conv_rc = space.
*      wa_afvv-vgw05 = l_vgw05.
*    ENDIF.
*
*    PERFORM conv_to_from_base USING 'X'
*                                     fp_matnr
*                                     wa_afvv-vgw06
*                                     wa_afvv-meinh
*                                     fp_buom
*                            CHANGING l_vgw06
*                                     v_conv_rc.
*    IF v_conv_rc = space.
*      wa_afvv-vgw06 = l_vgw06.
*    ENDIF.
**** End of Change on 25-05-2005
*
*
*  ENDIF.
*
*  IF NOT fp_afvc-lar01 IS INITIAL OR NOT fp_afvc-lar02 IS INITIAL OR
*     NOT fp_afvc-lar03 IS INITIAL OR NOT fp_afvc-lar04 IS INITIAL OR
*     NOT fp_afvc-lar05 IS INITIAL OR NOT fp_afvc-lar06 IS INITIAL.
*
*    IF NOT fp_afvc-lar01 IS INITIAL OR
*       NOT wa_afvv-vgw01 IS INITIAL.
*      CLEAR : wa_param_key.
*      READ TABLE i_param_key INTO wa_param_key
*                             WITH KEY parid = wa_param-par01.
*
*      wa_h_act-parxx = wa_param-par01.
*      wa_h_act-txtxx = wa_param_key-txtlg.
*      wa_h_act-ismxx = l_ism01.
*      wa_h_act-ilexx = l_ile01.
*
*      IF fp_afvc-sumnr = 0.
*        wa_h_act-vgwxx = wa_afvv-vgw01.
*        wa_h_act-vgexx = wa_afvv-vge01.
*      ELSE.
*        wa_h_act-vgwxx = wa_afvv-vgw01 * ( l_pqty / wa_afvv-bmsch ).
*        wa_h_act-vgexx = wa_afvv-vge01.
*      ENDIF.
*
*      wa_h_act-stdvar = wa_h_act-vgwxx - wa_h_act-ismxx.
*
*      PERFORM get_act_cost USING    fp_afvc-arbid
*                                    fp_afvc-lar01
*                           CHANGING wa_h_act-togxx
*                                    wa_h_act-toexx.
*      APPEND wa_h_act TO i_h_act.
*
*      wa_parn-parxx = wa_h_act-parxx.
*      COLLECT wa_parn INTO i_parn.
*
*      fp_rc = c_x.
*    ENDIF.
*
*    IF NOT fp_afvc-lar02 IS INITIAL OR
*       NOT wa_afvv-vgw02 IS INITIAL.
*      CLEAR : wa_param_key.
*      READ TABLE i_param_key INTO wa_param_key
*                             WITH KEY parid = wa_param-par02.
*
*      wa_h_act-parxx = wa_param-par02.
*      wa_h_act-txtxx = wa_param_key-txtlg.
*      wa_h_act-ismxx = l_ism02.
*      wa_h_act-ilexx = l_ile02.
** Begin of MOD-002++
**      wa_h_act-vgwxx = wa_afvv-vgw02 * ( l_pqty / wa_afvv-bmsch ).
**      wa_h_act-vgwxx = wa_h_act-vgwxx / l_effic.
*  wa_h_act-vgwxx =
*      ( wa_afvv-vgw02 *  l_pqty / wa_afvv-bmsch  ) / l_effic.
** End of MOD-002++
*      wa_h_act-vgexx = wa_afvv-vge02.
*
*      wa_h_act-stdvar = wa_h_act-vgwxx - wa_h_act-ismxx.
*
*      PERFORM get_act_cost USING    fp_afvc-arbid
*                                    fp_afvc-lar02
*                           CHANGING wa_h_act-togxx
*                                    wa_h_act-toexx.
*
*      APPEND wa_h_act TO i_h_act.
*
*      wa_parn-parxx = wa_h_act-parxx.
*      COLLECT wa_parn INTO i_parn.
*
*      fp_rc = c_x.
*    ENDIF.
*
*    IF NOT fp_afvc-lar03 IS INITIAL OR
*       NOT wa_afvv-vgw03 IS INITIAL.
*      CLEAR : wa_param_key.
*      READ TABLE i_param_key INTO wa_param_key
*                             WITH KEY parid = wa_param-par03.
*
*      wa_h_act-parxx = wa_param-par03.
*      wa_h_act-txtxx = wa_param_key-txtlg.
*      wa_h_act-ismxx = l_ism03.
*      wa_h_act-ilexx = l_ile03.
*
*      IF fp_afvc-sumnr = 0.
*        wa_h_act-vgwxx = wa_afvv-vgw03.
*        wa_h_act-vgexx = wa_afvv-vge03.
*      ELSE.
*        wa_h_act-vgwxx = wa_afvv-vgw03 * ( l_pqty / wa_afvv-bmsch ).
*        wa_h_act-vgexx = wa_afvv-vge03.
*      ENDIF.
*
*      wa_h_act-stdvar = wa_h_act-vgwxx - wa_h_act-ismxx.
*
*      PERFORM get_act_cost USING    fp_afvc-arbid
*                                    fp_afvc-lar03
*                           CHANGING wa_h_act-togxx
*                                    wa_h_act-toexx.
*
*      APPEND wa_h_act TO i_h_act.
*
*      wa_parn-parxx = wa_h_act-parxx.
*      COLLECT wa_parn INTO i_parn.
*
*      fp_rc = c_x.
*    ENDIF.
*
*    IF NOT fp_afvc-lar04 IS INITIAL OR
*       NOT wa_afvv-vgw04 IS INITIAL.
*      CLEAR : wa_param_key.
*      READ TABLE i_param_key INTO wa_param_key
*                             WITH KEY parid = wa_param-par04.
*
*      wa_h_act-parxx = wa_param-par04.
*      wa_h_act-txtxx = wa_param_key-txtlg.
*      wa_h_act-ismxx = l_ism04.
*      wa_h_act-ilexx = l_ile04.
** Begin of MOD-002++
**      wa_h_act-vgwxx = wa_afvv-vgw04 * ( l_pqty / wa_afvv-bmsch ).
**      wa_h_act-vgwxx = wa_h_act-vgwxx / l_effic.
*      wa_h_act-vgwxx =
*   ( wa_afvv-vgw04 * l_pqty / wa_afvv-bmsch ) / l_effic.
** End of MOD-002++
*
*      wa_h_act-vgexx = wa_afvv-vge04.
*
*      wa_h_act-stdvar = wa_h_act-vgwxx - wa_h_act-ismxx.
*
*      PERFORM get_act_cost USING    fp_afvc-arbid
*                                    fp_afvc-lar04
*                           CHANGING wa_h_act-togxx
*                                    wa_h_act-toexx.
*
*      APPEND wa_h_act TO i_h_act.
*
*      wa_parn-parxx = wa_h_act-parxx.
*      COLLECT wa_parn INTO i_parn.
*
*      fp_rc = c_x.
*    ENDIF.
*
*    IF NOT fp_afvc-lar05 IS INITIAL OR
*       NOT wa_afvv-vgw05 IS INITIAL.
*      CLEAR : wa_param_key.
*      READ TABLE i_param_key INTO wa_param_key
*                             WITH KEY parid = wa_param-par05.
*
*      wa_h_act-parxx = wa_param-par05.
*      wa_h_act-txtxx = wa_param_key-txtlg.
*      wa_h_act-ismxx = l_ism05.
*      wa_h_act-ilexx = l_ile05.
*      wa_h_act-vgwxx = wa_afvv-vgw05 * ( l_pqty / wa_afvv-bmsch ).
*      wa_h_act-vgexx = wa_afvv-vge05.
*
*      wa_h_act-stdvar = wa_h_act-vgwxx - wa_h_act-ismxx.
*
*      PERFORM get_act_cost USING    fp_afvc-arbid
*                                    fp_afvc-lar05
*                           CHANGING wa_h_act-togxx
*                                    wa_h_act-toexx.
*
*      APPEND wa_h_act TO i_h_act.
*
*      wa_parn-parxx = wa_h_act-parxx.
*      COLLECT wa_parn INTO i_parn.
*
*      fp_rc = c_x.
*    ENDIF.
*
*    IF NOT fp_afvc-lar06 IS INITIAL OR
*       NOT wa_afvv-vgw06 IS INITIAL.
*      CLEAR : wa_param_key.
*      READ TABLE i_param_key INTO wa_param_key
*                             WITH KEY parid = wa_param-par06.
*
*      wa_h_act-parxx = wa_param-par06.
*      wa_h_act-txtxx = wa_param_key-txtlg.
*      wa_h_act-ismxx = l_ism06.
*      wa_h_act-ilexx = l_ile06.
*      wa_h_act-vgwxx = wa_afvv-vgw06 * ( l_pqty / wa_afvv-bmsch ).
*      wa_h_act-vgexx = wa_afvv-vge06.
*
*      wa_h_act-stdvar = wa_h_act-vgwxx - wa_h_act-ismxx.
*
*      PERFORM get_act_cost USING    fp_afvc-arbid
*                                    fp_afvc-lar06
*                           CHANGING wa_h_act-togxx
*                                    wa_h_act-toexx.
*
*      APPEND wa_h_act TO i_h_act.
*
*      wa_parn-parxx = wa_h_act-parxx.
*      COLLECT wa_parn INTO i_parn.
*
*      fp_rc = c_x.
*    ENDIF.
*  ENDIF.
*ENDFORM.                    "build_act_tab
*
**&--------------------------------------------------------------------*
**&      Form  get_act_cost
**&--------------------------------------------------------------------*
**       text
**---------------------------------------------------------------------*
*FORM get_act_cost  USING   fp_arbid  TYPE cr_objid
*                           fp_larxx  TYPE lstar
*                  CHANGING fp_tog001 TYPE togxxx
*                           fp_toe001 TYPE toexxx.
*  DATA: l_kokrs TYPE kokrs,
*        l_kostl TYPE kostl,
*        l_objnr TYPE j_objnr.
*
*  CLEAR: l_kokrs, l_kostl, l_objnr,
*         fp_tog001.
*
*  fp_toe001 = 1.
*
*  SELECT SINGLE kokrs kostl
*    FROM crco
*    INTO (l_kokrs, l_kostl)
*   WHERE objty = c_a
*     AND objid = fp_arbid
*     AND lstar = fp_larxx.
*  IF sy-subrc = 0.
*
*    SELECT SINGLE objnr
*      FROM cssl
*      INTO l_objnr
*     WHERE kokrs = l_kokrs
*       AND kostl = l_kostl
*       AND lstar = fp_larxx
*       AND gjahr = sy-datum(4).
*    IF sy-subrc = 0.
*
*      SELECT SINGLE tog001 toe001
*        FROM cost
*        INTO (fp_tog001, fp_toe001)
*       WHERE objnr = l_objnr
*         AND gjahr = sy-datum(4)
*         AND versn = c_000.
*
*      fp_tog001 = fp_tog001 / 10.
*      fp_toe001 = fp_toe001 / 10.
*
*      IF fp_toe001 = 0.
*        fp_toe001 = 1.
*      ENDIF.
*
*    ENDIF.
*  ENDIF.
*ENDFORM.                    "get_act_cost
*
**&---------------------------------------------------------------------
*
**&      Form  output
**&---------------------------------------------------------------------
*
**       text
**----------------------------------------------------------------------
*
*FORM output.
*  CASE c_x.
*    WHEN rb_detl.
*      v_rep = c_detl.
*      PERFORM display_detail_report.
*
*    WHEN rb_summ.
*      v_rep = c_sums.
*      PERFORM display_summary_report.
*
*    WHEN rb_phase.
*      v_rep = c_phas.
*      PERFORM display_phase_report.
*  ENDCASE.
*
*  PERFORM tree_rebuild.
*ENDFORM.                    " output
*
**&--------------------------------------------------------------------*
**&      Form  display_detail_report
**&--------------------------------------------------------------------*
**       text
**---------------------------------------------------------------------*
*FORM display_detail_report.
*  DATA : l_date_low  TYPE char10,
*         l_date_high TYPE char10,
*
*         l_prdqty  TYPE gamng,
*         l_wprdqty TYPE menge_d,
*
*         l_prduom  TYPE meins,
*         l_uom     TYPE meins,
*         l_prdq(20),
*
*         l_effic  TYPE char16,
*
*         l_act    TYPE char16,
*         l_std    TYPE char16,
*
*         l_amenge TYPE menge_d,
*         l_smenge TYPE menge_d,
*         l_menge  TYPE menge_d,
*
*         l_aqty TYPE char18,
*         l_sqty TYPE char18,
*         l_svar TYPE char18,
*         l_svarp  TYPE char18,
*
*         l_aqtys TYPE char18,
*         l_sqtys TYPE char18,
*         l_svars TYPE char18,
*
*         l_aqtyg TYPE char18,
*         l_sqtyg TYPE char18,
*         l_svarg TYPE char18,
*
*         l_matuom TYPE meins,
*         l_stduom TYPE meins,
*         l_varuom TYPE meins,
*
*         l_astprs    TYPE ty_stprs,
*         l_sstprs    TYPE ty_stprs,
*         l_stprs     TYPE ty_stprs,
*
*         l_total1  TYPE char1,
*         l_total2  TYPE char1,
*         l_total3  TYPE char1,
*
*         l_totalg1  TYPE char1,
*         l_totalg2  TYPE char1,
*         l_totalg3  TYPE char1,
*
*         l_aplzl    TYPE co_aplzl,
*
*         l_wa_act  TYPE ty_hier_act,
*         l_wa_mat  TYPE ty_hier_mat_sum,
*         l_wa_matg TYPE ty_hier_mat_sum.
*
*  PERFORM pfstatus.
*  SET PF-STATUS 'MAIN' EXCLUDING i_fcode.
*  SET TITLEBAR 'VARI' WITH text-066.
*
*  MOVE 'Display Detail Report'(028) TO v_output_text.
*  PERFORM inform_user_of_progress.
*
** Clearing local variables
*  CLEAR wa_nodestab.
*  REFRESH i_nodestab.
*
*  wa_nodestab-id = c_1_1.
*  wa_nodestab-tlevel = c_1.
*  wa_nodestab-text = 'Production Variances'(031).
*  wa_nodestab-tlength = c_20.
*  wa_nodestab-compress = c_x.
*  APPEND wa_nodestab TO i_nodestab.
*
*  CLEAR : l_wa_matg , l_sqtyg   , l_aqtyg  , l_svarg,
*          l_totalg1 , l_totalg2 , l_totalg3.
*  LOOP AT i_h_ord INTO wa_h_ord.
*    CLEAR: wa_nodestab, l_date_low, l_date_high, l_prdqty, l_prduom.
*
*    wa_nodestab-id = c_2_1.
*    wa_nodestab-tlevel = c_2.
*    wa_nodestab-parent = c_1_1.
*
** Order Number text
*    wa_nodestab-text = 'Order Num:'(032).
*    wa_nodestab-tlength = c_12.
*    wa_nodestab-tcolor = c_1.
*
** Order number
*    WRITE wa_h_ord-aufnr TO wa_nodestab-text1 NO-ZERO.
*    wa_nodestab-tlength1 = c_12.
*    wa_nodestab-tcolor1 = c_1.
*
** Date Range
*    WRITE wa_h_ord-gstrp TO l_date_low.
*    WRITE wa_h_ord-gltrp TO l_date_high.
*    CONCATENATE l_date_low c_hyp l_date_high INTO wa_nodestab-text2
*                                             SEPARATED BY space.
*    wa_nodestab-tlength2 = c_25.
*    wa_nodestab-tcolor2 = c_1.
*
** Material Number
*    WRITE wa_h_ord-plnbez TO wa_nodestab-text3 NO-ZERO.
*    wa_nodestab-tlength3 = c_18.
*    wa_nodestab-tcolor3 = c_1.
*
** Material Description
*    wa_nodestab-text4 = wa_h_ord-maktx.
*    wa_nodestab-tlength4 = c_33.
*    wa_nodestab-tcolor4 = c_1.
*
** Produced Quantity / Confirmed Quantity
*    l_prdqty = wa_h_ord-prdqty.
*    l_prduom = wa_h_ord-prduom.
*
** convert to KG?
*    IF rb_kgm = c_x AND l_prduom <> 'KG'.
*      IF wa_h_ord-bsuom <> 'KG'.
*        PERFORM convert_to_kg USING   wa_h_ord-plnbez wa_h_ord-bsuom
*                                      wa_h_ord-gewei  wa_h_ord-ntgew
*                                      wa_h_ord-bprdqty
*                             CHANGING l_wprdqty
*                                      v_conv_rc.
*        IF v_conv_rc <> 'X'.
*          l_prdqty = l_wprdqty.
*          l_prduom = 'KG'.
*        ENDIF.
*
*      ELSE.
*        l_prdqty = wa_h_ord-bprdqty.
*        l_prduom = 'KG'.
*      ENDIF.
*    ENDIF.
*
*    WRITE l_prdqty TO l_prdq UNIT l_prduom.
*    WRITE l_prduom TO l_uom.
*
**** text for Order Qty
*    IF rb_pland = c_x.
*** Planned Production
*      CONCATENATE 'Plan Qty:'(076) l_prdq l_uom
*             INTO wa_nodestab-text5 SEPARATED BY space.
*    ELSE.
*** Actual Production
*      IF rb_prod = c_x.
** Produced
*        CONCATENATE 'Prod Qty:'(033) l_prdq l_uom
*               INTO wa_nodestab-text5 SEPARATED BY space.
*      ELSE.
** Confirmed
*        CONCATENATE 'Conf Qty:'(034) l_prdq l_uom
*               INTO wa_nodestab-text5 SEPARATED BY space.
*      ENDIF.
*    ENDIF.
*
*    CONDENSE : wa_nodestab-text5.
*
*    wa_nodestab-tlength5 = c_35.
*    wa_nodestab-tcolor5  = c_1.
*
*    APPEND wa_nodestab TO i_nodestab.
*
** Resource Information
*    CLEAR : wa_nodestab , l_effic.
*    wa_nodestab-id     = c_3_1.
*    wa_nodestab-tlevel = c_3.
*    wa_nodestab-parent = c_2_1.
*
*    wa_nodestab-text = 'Resource:'(035).
*    wa_nodestab-tlength = c_14.
*    wa_nodestab-tcolor  = c_4.
*
*    wa_nodestab-text1    = wa_h_ord-botlnck.
*    wa_nodestab-tlength1 = c_8.
*    wa_nodestab-tcolor1  = c_4.
*
*    wa_nodestab-text2    = wa_h_ord-resdesc.
*    wa_nodestab-tlength2 = c_37.
*    wa_nodestab-tcolor2  = c_4.
*
*    l_effic = wa_h_ord-el_effc.
*    CONCATENATE 'Exp. Line Eff.'(036) l_effic c_perc
*           INTO wa_nodestab-text3 SEPARATED BY space.
*    CONDENSE wa_nodestab-text3.
*    wa_nodestab-tlength3 = c_30.
*    wa_nodestab-tcolor3  = c_4.
*
*    l_effic = wa_h_ord-ac_effc.
*    CONCATENATE 'Act. Line Eff.'(037) l_effic c_perc
*           INTO wa_nodestab-text4 SEPARATED BY space.
*    CONDENSE wa_nodestab-text4.
*    wa_nodestab-tlength4 = c_30.
*    wa_nodestab-tcolor4  = c_4.
*
*    APPEND wa_nodestab TO i_nodestab.
*
** Phase Information
*    READ TABLE i_h_act INTO wa_h_act WITH KEY aufnr = wa_h_ord-aufnr.
*    IF sy-subrc = 0.
*      CLEAR : wa_nodestab.
*
*      wa_nodestab-id     = c_3_2.
*      wa_nodestab-tlevel = c_3.
*      wa_nodestab-parent = c_2_1.
*
*      wa_nodestab-text = 'Phase'(038).
*      wa_nodestab-tlength = c_8.
*      wa_nodestab-tcolor  = c_4.
*
*      wa_nodestab-tlength1 = c_42.
**    wa_nodestab-tcolor1  = c_4.
*
*      IF rb_fiscl = c_x.
*        CONCATENATE 'Actual Usage'(040) v_waers
*               INTO wa_nodestab-text2 SEPARATED BY space.
*      ELSE.
*        CONCATENATE 'Actual Usage'(040) 'UoM'
*               INTO wa_nodestab-text2 SEPARATED BY space.
*      ENDIF.
*      wa_nodestab-tlength2 = c_20.
*      wa_nodestab-tcolor2  = c_4.
*
*      IF rb_fiscl = c_x.
*        CONCATENATE 'Standard Usage'(041) v_waers
*               INTO wa_nodestab-text3 SEPARATED BY space.
*      ELSE.
*        CONCATENATE 'Standard Usage'(041) 'UoM'
*               INTO wa_nodestab-text3 SEPARATED BY space.
*      ENDIF.
*      wa_nodestab-tlength3 = c_20.
*      wa_nodestab-tcolor3  = c_4.
*
*      IF rb_fiscl = c_x.
*        CONCATENATE 'Standard Usage Var'(042) v_waers
*               INTO wa_nodestab-text4 SEPARATED BY space.
*      ELSE.
*        CONCATENATE 'Standard Usage Var'(042) 'UoM'
*               INTO wa_nodestab-text4 SEPARATED BY space.
*      ENDIF.
*      wa_nodestab-tlength4 = c_24.
*      wa_nodestab-tcolor4  = c_4.
*
*      CONCATENATE 'Standard Usage Var'(042) c_perc
*             INTO wa_nodestab-text5 SEPARATED BY space.
*      wa_nodestab-tlength5 = c_20.
*      wa_nodestab-tcolor5  = c_4.
*
*      APPEND wa_nodestab TO i_nodestab.
*
**** Activities
*      CLEAR : flg_color, l_act    , l_std    , l_svar , l_svarp ,
*              l_wa_act , l_total1 , l_total2 , l_aplzl.
*      LOOP AT i_h_act INTO wa_h_act WHERE aufnr = wa_h_ord-aufnr.
*
*        IF l_aplzl <> wa_h_act-aplzl.
*          CLEAR : wa_afvc.
*          READ TABLE i_h_phs INTO wa_h_phs WITH KEY aufnr =
*          wa_h_act-aufnr
*                                                    aufpl =
*                                                    wa_h_act-aufpl
*                                                    aplzl =
*                                                    wa_h_act-aplzl.
*          l_aplzl = wa_h_act-aplzl.
*        ENDIF.
*
*        CLEAR  wa_nodestab.
*        wa_nodestab-id     = c_4_1.
*        wa_nodestab-tlevel = c_4.
*        wa_nodestab-parent = c_3_2.
*
*        wa_nodestab-text    = wa_h_act-vornr.
*        wa_nodestab-tlength = c_4.
*
*        CONCATENATE wa_h_phs-steus wa_h_phs-arbpl
*                    wa_h_act-txtxx INTO wa_nodestab-text1
*                                   SEPARATED BY '  '.
*        wa_nodestab-tlength1 = c_42.
*
*        IF rb_quant = c_x.
*          WRITE : wa_h_act-ismxx TO l_act UNIT wa_h_act-ilexx
*          NO-GROUPING,
*                  wa_h_act-ilexx TO l_uom.
*          CONCATENATE l_act l_uom INTO wa_nodestab-text2
*                                  SEPARATED BY space.
*          wa_nodestab-tlength2 = c_20.
*
*          WRITE : wa_h_act-vgwxx TO l_std UNIT wa_h_act-vgexx
*          NO-GROUPING,
*                  wa_h_act-vgexx TO l_uom.
*          CONCATENATE l_std l_uom INTO wa_nodestab-text3
*                                  SEPARATED BY space.
*          wa_nodestab-tlength3 = c_20.
*
*          WRITE : wa_h_act-stdvar TO l_svar UNIT wa_h_act-vgexx
*          NO-GROUPING,
*                  wa_h_act-vgexx TO l_uom.
*          CONCATENATE l_svar l_uom INTO wa_nodestab-text4
*                                   SEPARATED BY space.
*          wa_nodestab-tlength4 = c_24.
*
*          IF wa_h_act-ismxx <> 0.
*            IF l_total2 <> c_x.
*              l_total2 = c_x.
*              l_wa_act-ilexx = wa_h_act-ilexx.
*            ENDIF.
*
*            IF l_wa_act-ilexx = wa_h_act-ilexx.
*
*              l_wa_act-ismxx = l_wa_act-ismxx + wa_h_act-ismxx.
*              l_wa_act-ilexx = wa_h_act-ilexx.
*
*            ELSEIF wa_h_act-ismxx <> 0.
*              CLEAR : l_wa_act-ismxx , l_wa_act-ilexx.
*            ENDIF.
*          ENDIF.
*
*          IF wa_h_act-vgwxx <> 0.
*            IF l_total1 <> c_x.
*              l_total1 = c_x.
*              l_wa_act-vgexx = wa_h_act-vgexx.
*            ENDIF.
*
*            IF l_wa_act-vgexx = wa_h_act-vgexx.
*              l_wa_act-vgwxx  = l_wa_act-vgwxx  + wa_h_act-vgwxx.
*              l_wa_act-stdvar = l_wa_act-stdvar + wa_h_act-stdvar.
*              l_wa_act-vgexx = wa_h_act-vgexx.
*
*            ELSEIF wa_h_act-vgwxx <> 0.
*              CLEAR : l_wa_act-vgwxx , l_wa_act-vgexx, l_wa_act-stdvar.
*            ENDIF.
*          ENDIF.
*
*          IF wa_h_act-vgwxx <> 0.
*    wa_h_act-varper = ( wa_h_act-stdvar / wa_h_act-vgwxx ) * 100
*            .
*          ENDIF.
*
*        ELSE.
*          wa_h_act-actu = wa_h_act-ismxx *
*                        ( wa_h_act-togxx / wa_h_act-toexx ).
*
*          WRITE : wa_h_act-actu TO l_act CURRENCY v_waers NO-GROUPING,
*                  v_waers TO l_uom.
*          CONCATENATE l_act l_uom INTO wa_nodestab-text2
*                                  SEPARATED BY space.
*          wa_nodestab-tlength2 = c_20.
*
*          wa_h_act-stdu = wa_h_act-vgwxx *
*                        ( wa_h_act-togxx / wa_h_act-toexx ).
*
*          WRITE : wa_h_act-stdu TO l_std CURRENCY v_waers NO-GROUPING.
*          CONCATENATE l_std l_uom INTO wa_nodestab-text3
*                                  SEPARATED BY space.
*          wa_nodestab-tlength3 = c_20.
*
*          wa_h_act-varu = wa_h_act-stdvar *
*                        ( wa_h_act-togxx / wa_h_act-toexx ).
*
*          WRITE wa_h_act-varu TO l_svar CURRENCY v_waers NO-GROUPING.
*          CONCATENATE l_svar l_uom INTO wa_nodestab-text4
*                                   SEPARATED BY space.
*          wa_nodestab-tlength4 = c_24.
*
*          l_wa_act-actu = l_wa_act-actu + wa_h_act-actu.
*          l_wa_act-stdu = l_wa_act-stdu + wa_h_act-stdu.
*          l_wa_act-varu = l_wa_act-varu + wa_h_act-varu.
*
*          IF wa_h_act-stdu <> 0.
*            wa_h_act-varper = ( wa_h_act-varu / wa_h_act-stdu ) * 100.
*          ENDIF.
*        ENDIF.
*
*        WRITE wa_h_act-varper TO l_svarp NO-GROUPING DECIMALS 2.
*        CONCATENATE l_svarp c_perc INTO wa_nodestab-text5
*                                   SEPARATED BY space.
*        wa_nodestab-tlength5 = c_20.
*
*        IF flg_color = c_x.
*          CLEAR flg_color.
*          wa_nodestab-tcolor  = c_3.
*          wa_nodestab-tcolor1 = c_3.
*          wa_nodestab-tcolor2 = c_3.
*          wa_nodestab-tcolor3 = c_3.
*          wa_nodestab-tcolor4 = c_3.
*          wa_nodestab-tcolor5 = c_3.
*          wa_nodestab-tcolor6 = c_3.
*          wa_nodestab-tcolor7 = c_3.
*          wa_nodestab-tcolor8 = c_3.
*        ELSE.
*          flg_color = c_x.
*          wa_nodestab-tcolor  = c_2.
*          wa_nodestab-tcolor1 = c_2.
*          wa_nodestab-tcolor2 = c_2.
*          wa_nodestab-tcolor3 = c_2.
*          wa_nodestab-tcolor4 = c_2.
*          wa_nodestab-tcolor5 = c_2.
*          wa_nodestab-tcolor6 = c_2.
*          wa_nodestab-tcolor7 = c_2.
*          wa_nodestab-tcolor8 = c_2.
*        ENDIF.
*        APPEND wa_nodestab TO i_nodestab.
*      ENDLOOP.
**** Displaying Activity Subtotals
*      CLEAR  wa_nodestab.
*      wa_nodestab-id     = c_4_1.
*      wa_nodestab-tlevel = c_4.
*      wa_nodestab-parent = c_3_2.
*
*      wa_nodestab-text    = 'Activity Totals'(074).
*      wa_nodestab-tlength =  c_20.
*      wa_nodestab-tcolor  =  c_6.
*
*      wa_nodestab-text1 = space.
*      wa_nodestab-tlength1 = c_26.
*      wa_nodestab-tcolor1  = c_6.
*
*      IF rb_quant = c_x.
*        WRITE : l_wa_act-ismxx  TO l_act  UNIT l_wa_act-ilexx
*        NO-GROUPING,
*                l_wa_act-vgwxx  TO l_std  UNIT l_wa_act-vgexx
*                NO-GROUPING,
*                l_wa_act-stdvar TO l_svar UNIT l_wa_act-vgexx
*                NO-GROUPING,
*                wa_h_act-ilexx TO l_uom.
*
*        CONCATENATE l_act  l_uom INTO wa_nodestab-text2
*                                 SEPARATED BY space.
*        WRITE : wa_h_act-vgexx TO l_uom.
*        CONCATENATE l_std  l_uom INTO wa_nodestab-text3
*                                      SEPARATED BY space.
*        CONCATENATE l_svar l_uom INTO wa_nodestab-text4
*                                      SEPARATED BY space.
*      ELSE.
*        WRITE : l_wa_act-actu TO l_act  CURRENCY v_waers NO-GROUPING,
*                l_wa_act-stdu TO l_std  CURRENCY v_waers NO-GROUPING,
*                l_wa_act-varu TO l_svar CURRENCY v_waers NO-GROUPING,
*                v_waers TO l_uom.
*
*        CONCATENATE l_act  l_uom INTO wa_nodestab-text2
*                                 SEPARATED BY space.
*        CONCATENATE l_std  l_uom INTO wa_nodestab-text3
*                                 SEPARATED BY space.
*        CONCATENATE l_svar l_uom INTO wa_nodestab-text4
*                                 SEPARATED BY space.
*      ENDIF.
*      wa_nodestab-tlength2 = c_20.
*      wa_nodestab-tcolor2  = c_6.
*
*      wa_nodestab-tlength3 = c_20.
*      wa_nodestab-tcolor3  = c_6.
*
*      wa_nodestab-tlength4 = c_24.
*      wa_nodestab-tcolor4  = c_6.
*
*      APPEND wa_nodestab TO i_nodestab.
*      CLEAR : wa_nodestab.
*    ENDIF.
*
** Material Information
*    READ TABLE i_h_mat INTO wa_h_mat WITH KEY aufnr = wa_h_ord-aufnr.
*    CHECK sy-subrc = 0.
*
*    CLEAR : wa_nodestab.
*    wa_nodestab-id      = c_3_3.
*    wa_nodestab-tlevel  = c_3.
*    wa_nodestab-parent  = c_2_1.
*    PERFORM material_header USING wa_nodestab.
*
*    APPEND wa_nodestab TO i_nodestab.
*
*    CLEAR : wa_nodestab , l_menge  , l_stprs  ,
*            l_wa_mat    ,
*            l_total1    , l_total2 , l_total3 ,
*            l_aqtys     , l_sqtys  , l_svars  .
*    LOOP AT i_h_mat INTO wa_h_mat WHERE aufnr = wa_h_ord-aufnr.
*
*      l_smenge = l_menge.
*      l_sstprs = l_stprs.
*      PERFORM do_mat_calc CHANGING wa_h_mat
*                                   l_aqty    l_matuom
*                                   l_sqty    l_stduom
*                                   l_svar    l_varuom
*                                   l_svarp
*                                   l_amenge  l_smenge
*                                   l_astprs  l_sstprs.
*      l_menge = l_menge + l_smenge.
*      l_stprs = l_stprs + l_sstprs.
*
*      CHECK wa_h_mat-sumi = c_x.
*
*      CLEAR: wa_nodestab , l_menge , l_stprs.
*      wa_nodestab-id     = c_4_2.
*      wa_nodestab-tlevel = c_4.
*      wa_nodestab-parent = c_3_3.
*
** Material Number
*      WRITE wa_h_mat-matnr TO wa_nodestab-text NO-ZERO.
** Material Description
*      wa_nodestab-text1 = wa_h_mat-maktx.
*
*      wa_nodestab-tlength  = c_18.
*      wa_nodestab-tlength1 = c_30.
*      wa_nodestab-tlength2 = c_22.
*      wa_nodestab-tlength3 = c_22.
*      wa_nodestab-tlength4 = c_24.
*      wa_nodestab-tlength5 = c_20.
*
*      IF l_matuom <> v_waers.
*        WRITE : l_matuom TO l_uom.
*      ELSE.
*        WRITE : v_waers TO l_uom.
*      ENDIF.
*      CONCATENATE l_aqty l_uom INTO wa_nodestab-text2
*                               SEPARATED BY space.
*      IF l_stduom <> v_waers.
*        WRITE : l_stduom TO l_uom.
*      ELSE.
*        WRITE : v_waers TO l_uom.
*      ENDIF.
*      CONCATENATE l_sqty l_uom INTO wa_nodestab-text3
*                               SEPARATED BY space.
*      IF l_varuom <> v_waers.
*        WRITE : l_varuom TO l_uom.
*      ELSE.
*        WRITE : v_waers TO l_uom.
*      ENDIF.
*      CONCATENATE l_svar l_uom INTO wa_nodestab-text4
*                               SEPARATED BY space.
*
*      CONCATENATE l_svarp c_perc INTO wa_nodestab-text5
*                                 SEPARATED BY space.
*
*      wa_nodestab-tcolor   = c_3.
*      wa_nodestab-tcolor1  = c_3.
*      wa_nodestab-tcolor2  = c_3.
*      wa_nodestab-tcolor3  = c_3.
*      wa_nodestab-tcolor4  = c_3.
*      wa_nodestab-tcolor5  = c_3.
*
*      APPEND wa_nodestab TO i_nodestab.
*      CLEAR : wa_nodestab.
*
*      IF l_aqty CA '123456789'.
*        IF l_total1 <> c_x.
*          l_total1 = c_x.
*          l_wa_mat-actuom = l_matuom.
*        ENDIF.
*
*        IF l_wa_mat-actuom <> l_matuom.
*          CLEAR : l_wa_mat-actusg, l_wa_mat-astprs, l_wa_mat-actuom,
*                  l_aqtys, l_amenge,
*                  l_wa_matg-actusg, l_wa_matg-astprs, l_wa_matg-actuom,
*                  l_aqtyg, l_astprs.
*        ENDIF.
*      ENDIF.
*
*      IF l_sqty CA '123456789'.
*        IF l_total2 <> c_x.
*          l_total2 = c_x.
*          l_wa_mat-stduom  = l_stduom.
*        ENDIF.
*
*        IF l_wa_mat-stduom <> l_stduom.
*          CLEAR : l_wa_mat-stdusg, l_wa_mat-sstprs, l_wa_mat-stduom,
*                  l_sqtys,         l_smenge,       l_wa_matg-stdusg,
*                  l_wa_matg-sstprs, l_wa_matg-stduom,
*                  l_sqtyg, l_sstprs.
*        ENDIF.
*      ENDIF.
*
*      IF l_svar CA '123456789'.
*        IF l_total3 <> c_x.
*          l_total3 = c_x.
*          l_wa_mat-varuom  = l_varuom.
*        ENDIF.
*
*        IF l_wa_mat-varuom <> l_varuom.
*          CLEAR : l_wa_mat-stdvar , l_wa_mat-varprs  , l_wa_mat-varuom
*                  l_svars, wa_h_mat-stdvar,
*                  l_wa_matg-stdvar, l_wa_matg-varprs , l_wa_matg-varuom
*                  l_svarg, wa_h_mat-vstprs.
*        ENDIF.
*      ENDIF.
*
*      CASE c_x.
*        WHEN rb_quant.
*          l_wa_mat-actusg  = l_wa_mat-actusg  + l_amenge.
*          WRITE l_wa_mat-actusg TO l_aqtys UNIT l_wa_mat-actuom
*          NO-GROUPING.
*
*          l_wa_mat-stdusg  = l_wa_mat-stdusg  + l_smenge.
*          WRITE l_wa_mat-stdusg TO l_sqtys UNIT l_wa_mat-stduom
*          NO-GROUPING.
*
*          l_wa_mat-stdvar  = l_wa_mat-stdvar  + wa_h_mat-stdvar.
*          WRITE : l_wa_mat-stdvar TO l_svars UNIT l_wa_mat-stduom
*          NO-GROUPING.
*
*        WHEN rb_fiscl.
*          l_wa_mat-astprs  = l_wa_mat-astprs  + l_astprs.
*          v_prs = l_wa_mat-astprs.
*          WRITE v_prs TO l_aqtys CURRENCY v_waers NO-GROUPING.
*
*          l_wa_mat-varprs  = l_wa_mat-varprs  + wa_h_mat-vstprs.
*          v_prs = l_wa_mat-varprs.
*          WRITE v_prs TO l_svars CURRENCY v_waers NO-GROUPING.
*
*          l_wa_mat-sstprs  = l_wa_mat-sstprs  + l_sstprs.
*          v_prs = l_wa_mat-sstprs.
*          WRITE v_prs TO l_sqtys CURRENCY v_waers NO-GROUPING.
*      ENDCASE.
*    ENDLOOP.
*
**** Displaying Material Subtotals
*    CLEAR  wa_nodestab.
*    wa_nodestab-id     = c_4_2.
*    wa_nodestab-tlevel = c_4.
*    wa_nodestab-parent = c_3_3.
*
*    wa_nodestab-text    = 'Material Totals'(043).
*    wa_nodestab-text1   = space.
*
*    wa_nodestab-tlength  =  c_18.
*    wa_nodestab-tlength1 = c_30.
*    wa_nodestab-tlength2 = c_22.
*    wa_nodestab-tlength3 = c_22.
*    wa_nodestab-tlength4 = c_24.
*
*    IF l_wa_mat-actuom <> v_waers.
*      WRITE : l_wa_mat-actuom TO l_uom.
*    ELSE.
*      WRITE : v_waers TO l_uom.
*    ENDIF.
*    CONCATENATE l_aqtys l_uom INTO wa_nodestab-text2
*                              SEPARATED BY space.
*    IF l_wa_mat-stduom <> v_waers.
*      WRITE : l_wa_mat-stduom TO l_uom.
*    ELSE.
*      WRITE : v_waers TO l_uom.
*    ENDIF.
*    CONCATENATE l_sqtys l_uom INTO wa_nodestab-text3
*                              SEPARATED BY space.
*
*    IF l_wa_mat-varuom <> v_waers.
*      WRITE : l_wa_mat-varuom TO l_uom.
*    ELSE.
*      WRITE : v_waers TO l_uom.
*    ENDIF.
*    CONCATENATE l_svars l_uom INTO wa_nodestab-text4
*                              SEPARATED BY space.
*    wa_nodestab-tcolor  =  c_6.
*    wa_nodestab-tcolor1  = c_6.
*    wa_nodestab-tcolor2  = c_6.
*    wa_nodestab-tcolor3  = c_6.
*    wa_nodestab-tcolor4  = c_6.
*
*    APPEND wa_nodestab TO i_nodestab.
*    CLEAR : wa_nodestab.
*
*    IF l_aqtys CA '123456789'.
*      IF l_totalg1 <> c_x.
*        l_totalg1 = c_x.
*        l_wa_matg-actuom = l_wa_mat-actuom.
*      ENDIF.
*
*      IF l_wa_matg-actuom <> l_wa_mat-actuom.
*        CLEAR : l_wa_matg-actusg , l_wa_matg-astprs , l_wa_matg-actuom,
*                l_aqtyg, l_wa_mat-actusg, l_wa_mat-astprs.
*      ENDIF.
*    ENDIF.
*
*    IF l_sqtys CA '123456789'.
*      IF l_totalg2 <> c_x.
*        l_totalg2 = c_x.
*        l_wa_matg-stduom = l_wa_mat-stduom.
*      ENDIF.
*
*      IF l_wa_matg-stduom <> l_wa_mat-stduom.
*        CLEAR : l_wa_matg-stdusg , l_wa_matg-stduom , l_wa_matg-sstprs
*                l_sqtyg, l_wa_mat-stdusg, l_wa_mat-sstprs.
*      ENDIF.
*    ENDIF.
*
*    IF l_svars CA '123456789'.
*      IF l_totalg3 <> c_x.
*        l_totalg3 = c_x.
*        l_wa_matg-varuom  = l_wa_mat-varuom.
*      ENDIF.
*
*      IF l_wa_matg-varuom  <> l_wa_mat-varuom.
*        CLEAR : l_wa_matg-stdvar, l_wa_matg-varprs , l_wa_matg-varuom,
*                l_svarg, l_wa_mat-stdvar, l_wa_mat-varprs.
*      ENDIF.
*    ENDIF.
*
*    CASE c_x.
*      WHEN rb_quant.
*        l_wa_matg-actusg  = l_wa_matg-actusg  + l_wa_mat-actusg.
*        WRITE : l_wa_matg-actusg TO l_aqtyg UNIT l_wa_mat-actuom
*        NO-GROUPING.
*
*        l_wa_matg-stdusg  = l_wa_matg-stdusg  + l_wa_mat-stdusg.
*        WRITE : l_wa_matg-stdusg TO l_sqtyg UNIT l_wa_mat-stduom
*        NO-GROUPING.
*
*        l_wa_matg-stdvar  = l_wa_matg-stdvar  + l_wa_mat-stdvar.
*        WRITE : l_wa_matg-stdvar TO l_svarg UNIT l_wa_mat-varuom
*        NO-GROUPING.
*
*      WHEN rb_fiscl.
*        l_wa_matg-astprs  = l_wa_matg-astprs  + l_wa_mat-astprs
*                            + l_wa_act-actu.
**                           + l_wa_act-actu * 10. "NEEL++ 13/07/2005++
*        v_prs = l_wa_matg-astprs.
*        WRITE v_prs TO l_aqtyg CURRENCY v_waers NO-GROUPING.
*
*        l_wa_matg-sstprs  = l_wa_matg-sstprs  + l_wa_mat-sstprs
*                            + l_wa_act-stdu.
**                           + l_wa_act-stdu * 10. "NEEL++ 13/07/2005++
*
*        v_prs = l_wa_matg-sstprs.
*        WRITE v_prs TO l_sqtyg CURRENCY v_waers NO-GROUPING.
*
*        l_wa_matg-varprs  = l_wa_matg-varprs  + l_wa_mat-varprs
*                            + l_wa_act-varu.
**                            + l_wa_act-varu * 10. "NEEL++ 13/07/2005++
*
*        v_prs = l_wa_matg-varprs.
*        WRITE v_prs TO l_svarg CURRENCY v_waers NO-GROUPING.
*    ENDCASE.
*
*    CLEAR : l_sqtys , l_aqtys , l_svars.
*
**** Displaying Grand Total
*    AT LAST.
*      CLEAR wa_nodestab.
*      wa_nodestab-id     = c_2_2.
*      wa_nodestab-tlevel = c_2.
*      wa_nodestab-parent = c_1_1.
*
*      wa_nodestab-text   = 'Process Order Totals'(044).
*      wa_nodestab-text1  = space.
*
*      wa_nodestab-tlength  = c_26.
*      wa_nodestab-tlength1 = c_30.
*      wa_nodestab-tlength2 = c_22.
*      wa_nodestab-tlength3 = c_22.
*      wa_nodestab-tlength4 = c_24.
*
*      IF l_wa_matg-actuom <> v_waers.
*        WRITE : l_wa_matg-actuom TO l_uom.
*      ELSE.
*        WRITE : v_waers TO l_uom.
*      ENDIF.
*      CONCATENATE l_aqtyg l_uom INTO wa_nodestab-text2
*                                SEPARATED BY space.
*
*      IF l_wa_matg-stduom <> v_waers.
*        WRITE : l_wa_matg-stduom TO l_uom.
*      ELSE.
*        WRITE : v_waers TO l_uom.
*      ENDIF.
*      CONCATENATE l_sqtyg l_uom INTO wa_nodestab-text3
*                                SEPARATED BY space.
*
*      IF l_wa_matg-varuom <> v_waers.
*        WRITE : l_wa_matg-varuom TO l_uom.
*      ELSE.
*        WRITE : v_waers TO l_uom.
*      ENDIF.
*      CONCATENATE l_svarg l_uom INTO wa_nodestab-text4
*                                SEPARATED BY space.
*      wa_nodestab-tcolor   = c_5.
*      wa_nodestab-tcolor1  = c_5.
*      wa_nodestab-tcolor2  = c_5.
*      wa_nodestab-tcolor3  = c_5.
*      wa_nodestab-tcolor4  = c_5.
*
*      APPEND wa_nodestab TO i_nodestab.
*    ENDAT.
*  ENDLOOP.
*ENDFORM.                    " DISPLAY_DETAIL_REPORT
*
**&--------------------------------------------------------------------*
**&      Form  display_phase_report
**&--------------------------------------------------------------------*
**       text
**---------------------------------------------------------------------*
*FORM display_phase_report.
*
*  DATA: l_date_low(10)  TYPE c,
*        l_date_high(10) TYPE c,
*
*        l_effic  TYPE char16,
*        l_arbpl  TYPE arbpl,
*
*        l_prdqty  TYPE gamng,
*        l_prdq    TYPE char18,
*        l_wprdqty TYPE menge_d,
*        l_prduom  TYPE meins,
*
*        l_act    TYPE char16,
*        l_std    TYPE char16,
*
*        l_amenge TYPE menge_d,
*        l_smenge TYPE menge_d,
*        l_menge  TYPE menge_d,
*
*        l_aqty TYPE char18,
*        l_sqty TYPE char18,
*        l_svar TYPE char18,
*        l_svarp  TYPE char18,
*
*        l_aqtys TYPE char18,
*        l_sqtys TYPE char18,
*        l_svars TYPE char18,
*
*        l_matuom TYPE meins,
*        l_stduom TYPE meins,
*        l_varuom TYPE meins,
*        l_uom    TYPE meins,
*
*        l_astprs TYPE ty_stprs,
*        l_sstprs TYPE ty_stprs,
*        l_stprs  TYPE ty_stprs,
*
*        l_total1  TYPE char1,
*        l_total2  TYPE char1,
*        l_total3  TYPE char1,
*
*        l_wa_act  TYPE ty_hier_act,
*        l_wa_mat  TYPE ty_hier_mat_sum,
*        l_wa_phs  TYPE ty_hier_phase,
*        l_i_phs   TYPE STANDARD TABLE OF ty_hier_phase.
*
*  PERFORM pfstatus.
*  SET PF-STATUS 'MAIN' EXCLUDING i_fcode.
*  SET TITLEBAR 'VARI' WITH text-068.
*
*  l_i_phs = i_h_phs.
*
*  SORT i_h_phs BY aufnr arbpl vornr.
*
*  CLEAR wa_nodestab.
*  REFRESH i_nodestab.
*
*  MOVE 'Display Phase Report'(030) TO v_output_text.
*  PERFORM inform_user_of_progress.
*
*  CLEAR wa_nodestab.
*  wa_nodestab-id = c_1_1.
*  wa_nodestab-tlevel = c_1.
*  wa_nodestab-text = 'Production Variances'(031).
*  wa_nodestab-tlength = c_20.
*  wa_nodestab-compress = c_x.
*  APPEND wa_nodestab TO i_nodestab.
*
*  LOOP AT i_h_ord INTO wa_h_ord.
*
*    CLEAR: wa_nodestab, l_date_low, l_date_high.
*
*    wa_nodestab-id     = c_2_1.
*    wa_nodestab-tlevel = c_2.
*    wa_nodestab-parent = c_1_1.
*
** Order Number text
*    wa_nodestab-text    = 'Order Num:'(032).
*    wa_nodestab-tlength = c_12.
*    wa_nodestab-tcolor  = c_1.
*
** Order number
*    WRITE wa_h_ord-aufnr TO wa_nodestab-text1 NO-ZERO.
*    wa_nodestab-tlength1 = c_12.
*    wa_nodestab-tcolor1  = c_1.
*
** Date Range
*    WRITE wa_h_ord-gstrp TO l_date_low.
*    WRITE wa_h_ord-gltrp TO l_date_high.
*    CONCATENATE l_date_low c_hyp l_date_high INTO wa_nodestab-text2
*                                             SEPARATED BY space.
*    wa_nodestab-tlength2 = c_25.
*    wa_nodestab-tcolor2  = c_1.
*
** Material Number
*    WRITE wa_h_ord-plnbez TO wa_nodestab-text3 NO-ZERO.
*    wa_nodestab-tlength3 = c_18.
*    wa_nodestab-tcolor3  = c_1.
*
** Material Description
*    wa_nodestab-text4    = wa_h_ord-maktx.
*    wa_nodestab-tlength4 = c_33.
*    wa_nodestab-tcolor4  = c_1.
*
*    APPEND wa_nodestab TO i_nodestab.
*
*    CLEAR :  l_aqtys, l_sqtys, l_svars, l_arbpl.
*    LOOP AT i_h_phs INTO wa_h_phs WHERE aufnr = wa_h_ord-aufnr.
*      l_wa_phs = wa_h_phs.
*
*      IF l_arbpl <> wa_h_phs-arbpl.
*        CLEAR : wa_h_phs.
*        READ TABLE i_h_phs INTO wa_h_phs
*        WITH KEY aufnr = wa_h_ord-aufnr
*                 arbpl = l_wa_phs-arbpl
*                                                  steus = 'YBN1'
*                                                  runtime = c_x.
** Resource Information
*        CLEAR : wa_nodestab.
*        wa_nodestab-id     = c_3_1.
*        wa_nodestab-tlevel = c_3.
*        wa_nodestab-parent = c_2_1.
*
*        wa_nodestab-text = 'Resource:'(035).
*        wa_nodestab-tlength = c_14.
*        wa_nodestab-tcolor  = c_4.
*
*        wa_nodestab-text1    = l_wa_phs-arbpl.
*        wa_nodestab-tlength1 = c_8.
*        wa_nodestab-tcolor1  = c_4.
*
*        wa_nodestab-text2    = l_wa_phs-ktext.
*        wa_nodestab-tlength2 = c_37.
*        wa_nodestab-tcolor2  = c_4.
*
*        IF l_wa_phs-steus = 'YBN1'.
*          l_effic = wa_h_phs-el_effc.
*          CONCATENATE 'Exp. Line Eff.'(036) l_effic c_perc
*                 INTO wa_nodestab-text3 SEPARATED BY space.
*          CONDENSE wa_nodestab-text3.
*          wa_nodestab-tlength3 = c_30.
*          wa_nodestab-tcolor3  = c_4.
*
*          l_effic = wa_h_phs-ac_effc.
*          CONCATENATE 'Act. Line Eff.'(037) l_effic c_perc
*                 INTO wa_nodestab-text4 SEPARATED BY space.
*          CONDENSE wa_nodestab-text4.
*          wa_nodestab-tlength4 = c_30.
*          wa_nodestab-tcolor4  = c_4.
*        ENDIF.
*        APPEND wa_nodestab TO i_nodestab.
*
*        l_arbpl = l_wa_phs-arbpl.
*        wa_h_phs = l_wa_phs.
*      ENDIF.
*
*      CLEAR : wa_nodestab.
*      wa_nodestab-id     = c_4_1.
*      wa_nodestab-tlevel = c_4.
*      wa_nodestab-parent = c_3_1.
*** Phase Number
*      wa_nodestab-text    = 'Phase'(038).
*      wa_nodestab-tlength =  c_10.
*      wa_nodestab-tcolor  =  c_4.
*
*      CONCATENATE wa_h_phs-vornr wa_h_phs-steus
*                  wa_h_phs-ltxa1
*             INTO wa_nodestab-text1
*             SEPARATED BY space.
*      wa_nodestab-tlength1 =  c_40.
*      wa_nodestab-tcolor1  =  c_4.
*
*** PO Quantity
**      l_prdqty = wa_h_phs-lmnga.
*      l_prdqty = wa_h_phs-prdqty.
*      l_prduom = wa_h_phs-prduom.
*
*      IF rb_kgm = c_x AND l_prduom <> 'KG'.
*        IF wa_h_phs-bsuom <> 'KG'.
*          PERFORM convert_to_kg USING   wa_h_ord-plnbez wa_h_phs-bsuom
*                                        wa_h_phs-gewei  wa_h_phs-ntgew
*                                        wa_h_phs-bprdqty
*                               CHANGING l_wprdqty
*                                        v_conv_rc.
*          IF v_conv_rc <> 'X'.
*            l_prdqty = l_wprdqty.
*            l_prduom = 'KG'.
*          ENDIF.
*
*        ELSE.
*          l_prdqty = wa_h_phs-bprdqty.
*          l_prduom = 'KG'.
*        ENDIF.
*      ENDIF.
*
*      WRITE : l_prdqty TO l_prdq UNIT l_prduom NO-GROUPING,
*              l_prduom TO l_uom.
*
**** text for Order Qty
*      IF rb_pland = c_x.
*** Planned Production
*        CONCATENATE 'Plan Qty:'(076) l_prdq l_uom
*               INTO wa_nodestab-text2 SEPARATED BY space.
*      ELSE.
*** Actual Production
*        IF rb_prod = c_x.
** Produced
*          CONCATENATE 'Prod Qty:'(033) l_prdq l_uom
*                 INTO wa_nodestab-text2 SEPARATED BY space.
*        ELSE.
** Confirmed
*          CONCATENATE 'Conf Qty:'(034) l_prdq l_uom
*                 INTO wa_nodestab-text2 SEPARATED BY space.
*        ENDIF.
*      ENDIF.
*
*      CONDENSE : wa_nodestab-text2.
*
*      wa_nodestab-tlength2 =  32.
*      wa_nodestab-tcolor2  =  c_4.
*      APPEND wa_nodestab TO i_nodestab.
****
**** Activity Information
****
*      CLEAR  wa_nodestab.
*      wa_nodestab-id     = c_5_1.
*      wa_nodestab-tlevel = c_5.
*      wa_nodestab-parent = c_4_1.
*
*      wa_nodestab-text    = 'Activity'(052).
*      wa_nodestab-tlength = 34.
*
*      wa_nodestab-text1    = 'Actual Usage'(040).
*      wa_nodestab-tlength1 = c_20.
*
*      wa_nodestab-text2    = 'Standard Usage'(041).
*      wa_nodestab-tlength2 = c_20.
*
*      IF rb_fiscl = c_x.
*        CONCATENATE 'Standard Usage Var'(042) v_waers
*               INTO wa_nodestab-text3 SEPARATED BY space.
*      ELSE.
*        CONCATENATE 'Standard Usage Var'(042) 'UoM'
*               INTO wa_nodestab-text3 SEPARATED BY space.
*      ENDIF.
*      wa_nodestab-tlength3 = c_24.
*
*      CONCATENATE 'Standard Usage Var'(042) c_perc
*             INTO wa_nodestab-text4 SEPARATED BY space.
*      wa_nodestab-tlength4 = c_20.
*
*      wa_nodestab-tcolor  = c_4.
*      wa_nodestab-tcolor1 = c_4.
*      wa_nodestab-tcolor2 = c_4.
*      wa_nodestab-tcolor3 = c_4.
*      wa_nodestab-tcolor4 = c_4.
*
*      APPEND wa_nodestab TO i_nodestab.
*
*      CLEAR : flg_color , l_act , l_std , l_svar , l_svarp , l_wa_act,
*              l_total1  , l_total2.
*      LOOP AT i_h_act INTO wa_h_act WHERE aufnr = wa_h_phs-aufnr
*                                      AND aufpl = wa_h_phs-aufpl
*                                      AND aplzl = wa_h_phs-aplzl
*                                      AND vornr = wa_h_phs-vornr.
*        CLEAR : wa_nodestab.
*        wa_nodestab-id     = c_6_1.
*        wa_nodestab-tlevel = c_6.
*        wa_nodestab-parent = c_5_1.
*
*        wa_nodestab-text    = wa_h_act-txtxx.
*        wa_nodestab-tlength = c_30.
*        wa_nodestab-tlength1 = c_20.
*        wa_nodestab-tlength2 = c_20.
*        wa_nodestab-tlength3 = c_24.
*        wa_nodestab-tlength4 = c_20.
*
*        IF rb_quant = c_x.
*          WRITE : wa_h_act-ismxx TO l_act UNIT wa_h_act-ilexx
*          NO-GROUPING,
*                  wa_h_act-ilexx TO l_uom.
*          CONCATENATE l_act l_uom INTO wa_nodestab-text1
*                                  SEPARATED BY space.
*
*          WRITE : wa_h_act-vgwxx TO l_std UNIT wa_h_act-vgexx
*          NO-GROUPING,
*                  wa_h_act-vgexx TO l_uom.
*          CONCATENATE l_std l_uom INTO wa_nodestab-text2
*                                  SEPARATED BY space.
*
*          WRITE wa_h_act-stdvar TO l_svar UNIT wa_h_act-vgexx
*          NO-GROUPING.
*          CONCATENATE l_svar l_uom INTO wa_nodestab-text3
*                                   SEPARATED BY space.
*          IF wa_h_act-ismxx <> 0.
*            IF l_total2 <> c_x.
*              l_total2 = c_x.
*              l_wa_act-ilexx = wa_h_act-ilexx.
*            ENDIF.
*
*            IF l_wa_act-ilexx = wa_h_act-ilexx.
*              l_wa_act-ismxx = l_wa_act-ismxx + wa_h_act-ismxx.
*              l_wa_act-ilexx = wa_h_act-ilexx.
*
*            ELSEIF wa_h_act-ismxx <> 0.
*              CLEAR : l_wa_act-ismxx , l_wa_act-ilexx.
*            ENDIF.
*          ENDIF.
*
*          IF wa_h_act-vgwxx <> 0.
*            IF l_total1 <> c_x.
*              l_total1 = c_x.
*              l_wa_act-vgexx = wa_h_act-vgexx.
*            ENDIF.
*
*            IF l_wa_act-vgexx = wa_h_act-vgexx.
*              l_wa_act-vgwxx  = l_wa_act-vgwxx  + wa_h_act-vgwxx.
*              l_wa_act-stdvar = l_wa_act-stdvar + wa_h_act-stdvar.
*              l_wa_act-vgexx = wa_h_act-vgexx.
*
*            ELSEIF wa_h_act-vgwxx <> 0.
*              CLEAR : l_wa_act-vgwxx , l_wa_act-vgexx, l_wa_act-stdvar.
*            ENDIF.
*          ENDIF.
*
*          IF wa_h_act-vgwxx <> 0.
*     wa_h_act-varper = ( wa_h_act-stdvar / wa_h_act-vgwxx ) * 100
*            .
*          ENDIF.
*
*        ELSE.
*
*          wa_h_act-actu = wa_h_act-ismxx * ( wa_h_act-togxx /
*                wa_h_act-toexx ).
*
*          WRITE : wa_h_act-actu TO l_act CURRENCY v_waers NO-GROUPING,
*                  v_waers TO l_uom.
*          CONCATENATE l_act l_uom INTO wa_nodestab-text1
*                                  SEPARATED BY space.
*
*          wa_h_act-stdu = wa_h_act-vgwxx *
*                        ( wa_h_act-togxx / wa_h_act-toexx ).
*
*          WRITE wa_h_act-stdu TO l_std CURRENCY v_waers NO-GROUPING.
*          CONCATENATE l_std l_uom INTO wa_nodestab-text2
*                                  SEPARATED BY space.
*
*          wa_h_act-varu = wa_h_act-stdvar *
*                        ( wa_h_act-togxx / wa_h_act-toexx ).
*
*          WRITE wa_h_act-varu TO l_svar CURRENCY v_waers NO-GROUPING.
*          CONCATENATE l_svar l_uom INTO wa_nodestab-text3
*                                   SEPARATED BY space.
*          IF wa_h_act-stdu <> 0.
*            wa_h_act-varper = ( wa_h_act-varu / wa_h_act-stdu ) * 100.
*          ENDIF.
*
*          l_wa_act-actu = l_wa_act-actu + wa_h_act-actu.
*          l_wa_act-stdu = l_wa_act-stdu + wa_h_act-stdu.
*          l_wa_act-varu = l_wa_act-varu + wa_h_act-varu.
*        ENDIF.
*
*        WRITE wa_h_act-varper TO l_svarp NO-GROUPING DECIMALS 2.
*        CONCATENATE l_svarp c_perc INTO wa_nodestab-text4
*                                   SEPARATED BY space.
*        IF flg_color = c_x.
*          CLEAR flg_color.
*          wa_nodestab-tcolor  = c_3.
*          wa_nodestab-tcolor1 = c_3.
*          wa_nodestab-tcolor2 = c_3.
*          wa_nodestab-tcolor3 = c_3.
*          wa_nodestab-tcolor4 = c_3.
*          wa_nodestab-tcolor5 = c_3.
*          wa_nodestab-tcolor6 = c_3.
*          wa_nodestab-tcolor7 = c_3.
*          wa_nodestab-tcolor8 = c_3.
*        ELSE.
*          flg_color = c_x.
*          wa_nodestab-tcolor  = c_2.
*          wa_nodestab-tcolor1 = c_2.
*          wa_nodestab-tcolor2 = c_2.
*          wa_nodestab-tcolor3 = c_2.
*          wa_nodestab-tcolor4 = c_2.
*          wa_nodestab-tcolor5 = c_2.
*          wa_nodestab-tcolor6 = c_2.
*          wa_nodestab-tcolor7 = c_2.
*          wa_nodestab-tcolor8 = c_2.
*        ENDIF.
*
*        APPEND wa_nodestab TO i_nodestab.
*      ENDLOOP.
**** Displaying Activity Subtotals
*      CLEAR  wa_nodestab.
*      wa_nodestab-id     = c_6_1.
*      wa_nodestab-tlevel = c_6.
*      wa_nodestab-parent = c_5_1.
*
*      wa_nodestab-text    = 'Activity Totals'(074).
*      wa_nodestab-tlength =  c_30.
*      wa_nodestab-tcolor  =  c_6.
*
*      IF rb_quant = c_x.
*        WRITE : l_wa_act-ismxx TO l_act UNIT l_wa_act-ilexx NO-GROUPING
*                l_wa_act-ilexx TO l_uom.
*        CONCATENATE l_act l_uom INTO wa_nodestab-text1
*                                SEPARATED BY space.
*
*        WRITE : l_wa_act-vgwxx TO l_std UNIT l_wa_act-vgexx NO-GROUPING
*                l_wa_act-vgexx TO l_uom.
*        CONCATENATE l_std l_uom INTO wa_nodestab-text2
*                                SEPARATED BY space.
*
*        WRITE : l_wa_act-stdvar TO l_svar UNIT l_wa_act-vgexx
*        NO-GROUPING.
*        CONCATENATE l_svar l_uom INTO wa_nodestab-text3
*                                 SEPARATED BY space.
*
*      ELSE.
*        WRITE : l_wa_act-actu TO l_act CURRENCY v_waers NO-GROUPING,
*                v_waers TO l_uom.
*        CONCATENATE l_act l_uom INTO wa_nodestab-text1
*                                SEPARATED BY space.
*
*        WRITE : l_wa_act-stdu TO l_std CURRENCY v_waers NO-GROUPING.
*        CONCATENATE l_std l_uom INTO wa_nodestab-text2
*                                SEPARATED BY space.
*
*        WRITE : l_wa_act-varu TO l_svar UNIT l_wa_act-vgexx NO-GROUPING
.
*        CONCATENATE l_svar l_uom INTO wa_nodestab-text3
*                                 SEPARATED BY space.
*      ENDIF.
*
*      wa_nodestab-tlength1 = c_20.
*      wa_nodestab-tlength2 = c_20.
*      wa_nodestab-tlength3 = c_24.
*
*      wa_nodestab-tcolor1  = c_6.
*      wa_nodestab-tcolor2  = c_6.
*      wa_nodestab-tcolor3  = c_6.
*      APPEND wa_nodestab TO i_nodestab.
*      CLEAR : wa_nodestab.
*
****
**** Material Information
****
*      READ TABLE i_h_mat INTO wa_h_mat WITH KEY aufnr = wa_h_phs-aufnr
*                                                aufpl = wa_h_phs-aufpl
*                                                aplzl = wa_h_phs-aplzl
*                                                vornr = wa_h_phs-vornr.
*      CHECK sy-subrc = 0.
*
*      CLEAR : wa_nodestab.
*      wa_nodestab-id      = c_5_2.
*      wa_nodestab-tlevel  = c_5.
*      wa_nodestab-parent  = c_4_1.
*      PERFORM material_header USING wa_nodestab.
*
*      APPEND wa_nodestab TO i_nodestab.
*
*      CLEAR : wa_nodestab , l_menge  , l_stprs  ,
*              l_total1    , l_total2 , l_total3 ,
*              l_wa_mat    , l_aqtys  , l_sqtys  , l_svars.
*      LOOP AT i_h_mat INTO wa_h_mat WHERE aufnr = wa_h_phs-aufnr
*                                      AND aufpl = wa_h_phs-aufpl
*                                      AND aplzl = wa_h_phs-aplzl
*                                      AND vornr = wa_h_phs-vornr.
*        l_smenge = l_menge.
*        l_sstprs = l_stprs.
*        PERFORM do_mat_calc CHANGING wa_h_mat
*                                     l_aqty    l_matuom
*                                     l_sqty    l_stduom
*                                     l_svar    l_varuom
*                                     l_svarp
*                                     l_amenge  l_smenge
*                                     l_astprs  l_sstprs.
*        l_menge = l_menge + l_smenge.
*        l_stprs = l_stprs + l_sstprs.
*
*        CHECK wa_h_mat-sumi = c_x.
*
*        CLEAR: wa_nodestab , l_menge , l_stprs.
*        wa_nodestab-id     = c_6_2.
*        wa_nodestab-tlevel = c_6.
*        wa_nodestab-parent = c_5_2.
** Material Number
*        WRITE wa_h_mat-matnr TO wa_nodestab-text NO-ZERO.
** Material Description
*        wa_nodestab-text1 = wa_h_mat-maktx.
*
*        wa_nodestab-tlength  = c_18.
*        wa_nodestab-tlength1 = c_30.
*        wa_nodestab-tlength2 = c_22.
*        wa_nodestab-tlength3 = c_22.
*        wa_nodestab-tlength4 = c_24.
*        wa_nodestab-tlength5 = c_20.
*
*        IF l_matuom <> v_waers.
*          WRITE : l_matuom TO l_uom.
*        ELSE.
*          WRITE : v_waers TO l_uom.
*        ENDIF.
*        CONCATENATE l_aqty l_uom INTO wa_nodestab-text2
*                                 SEPARATED BY space.
*
*        IF l_stduom <> v_waers.
*          WRITE : l_stduom TO l_uom.
*        ELSE.
*          WRITE : v_waers TO l_uom.
*        ENDIF.
*        CONCATENATE l_sqty l_uom INTO wa_nodestab-text3
*                                 SEPARATED BY space.
*
*        IF l_varuom <> v_waers.
*          WRITE : l_varuom TO l_uom.
*        ELSE.
*          WRITE : v_waers TO l_uom.
*        ENDIF.
*        CONCATENATE l_svar l_uom INTO wa_nodestab-text4
*                                 SEPARATED BY space.
*
*        CONCATENATE l_svarp c_perc INTO wa_nodestab-text5
*                                   SEPARATED BY space.
*        wa_nodestab-tcolor   = c_3.
*        wa_nodestab-tcolor1  = c_3.
*        wa_nodestab-tcolor2  = c_3.
*        wa_nodestab-tcolor3  = c_3.
*        wa_nodestab-tcolor4  = c_3.
*        wa_nodestab-tcolor5  = c_3.
*
*        APPEND wa_nodestab TO i_nodestab.
*
*        IF l_aqty CA '123456789'.
*          IF l_total1 <> c_x.
*            l_total1 = c_x.
*            l_wa_mat-actuom = l_matuom.
*          ENDIF.
*
*          IF l_wa_mat-actuom <> l_matuom.
*            CLEAR : l_wa_mat-actusg , l_wa_mat-astprs , l_wa_mat-actuom
*                    l_aqtys, l_amenge , l_astprs.
*          ENDIF.
*        ENDIF.
*
*        IF l_sqty CA '123456789'.
*          IF l_total2 <> c_x.
*            l_total2 = c_x.
*            l_wa_mat-stduom  = l_stduom.
*          ENDIF.
*
*          IF l_wa_mat-stduom <> l_stduom.
*            CLEAR : l_wa_mat-stdusg , l_wa_mat-sstprs ,
*                    l_wa_mat-stduom ,
*                    l_sqtys, l_smenge , l_sstprs.
*          ENDIF.
*        ENDIF.
*
*        IF l_svar CA '123456789'.
*          IF l_total3 <> c_x.
*            l_total3 = c_x.
*            l_wa_mat-varuom  = l_varuom.
*          ENDIF.
*
*          IF l_wa_mat-varuom  <> l_varuom.
*            CLEAR : l_wa_mat-stdvar, l_wa_mat-varprs , l_wa_mat-varuom,
*                    l_svars, wa_h_mat-vstprs , wa_h_mat-stdvar.
*          ENDIF.
*        ENDIF.
*
*        CASE c_x.
*          WHEN rb_quant.
*            l_wa_mat-actusg  = l_wa_mat-actusg  + l_amenge.
*            WRITE l_wa_mat-actusg TO l_aqtys UNIT l_wa_mat-actuom
*            NO-GROUPING.
*
*            l_wa_mat-stdusg  = l_wa_mat-stdusg  + l_smenge.
*            WRITE l_wa_mat-stdusg TO l_sqtys UNIT l_wa_mat-stduom
*            NO-GROUPING.
*
*            l_wa_mat-stdvar  = l_wa_mat-stdvar  + wa_h_mat-stdvar.
*            WRITE : l_wa_mat-stdvar TO l_svars UNIT l_wa_mat-stduom
*            NO-GROUPING.
*
*          WHEN rb_fiscl.
*            l_wa_mat-astprs  = l_wa_mat-astprs  + l_astprs.
*            v_prs = l_wa_mat-astprs.
*            WRITE v_prs TO l_aqtys CURRENCY v_waers NO-GROUPING.
*
*            l_wa_mat-sstprs  = l_wa_mat-sstprs  + l_sstprs.
*            v_prs = l_wa_mat-sstprs.
*            WRITE v_prs TO l_sqtys CURRENCY v_waers NO-GROUPING.
*
*            l_wa_mat-varprs  = l_wa_mat-varprs  + wa_h_mat-vstprs.
*            v_prs = l_wa_mat-varprs.
*            WRITE v_prs TO l_svars CURRENCY v_waers NO-GROUPING.
*        ENDCASE.
*      ENDLOOP.
**** Displaying Material Subtotals
*      CLEAR  wa_nodestab.
*      wa_nodestab-id     = c_6_2.
*      wa_nodestab-tlevel = c_6.
*      wa_nodestab-parent = c_5_2.
*
*      wa_nodestab-text  = 'Material Totals'(043).
*      wa_nodestab-text1 = space.
*
*      wa_nodestab-tlength  = c_18.
*      wa_nodestab-tlength1 = c_30.
*      wa_nodestab-tlength2 = c_22.
*      wa_nodestab-tlength3 = c_22.
*      wa_nodestab-tlength4 = c_24.
*
*      IF l_wa_mat-actuom <> v_waers.
*        WRITE : l_wa_mat-actuom TO l_uom.
*      ELSE.
*        WRITE : v_waers TO l_uom.
*      ENDIF.
*      CONCATENATE l_aqtys l_uom INTO wa_nodestab-text2
*                                SEPARATED BY space.
*
*      IF l_wa_mat-stduom <> v_waers.
*        WRITE : l_wa_mat-stduom TO l_uom.
*      ELSE.
*        WRITE : v_waers TO l_uom.
*      ENDIF.
*      CONCATENATE l_sqtys l_uom INTO wa_nodestab-text3
*                                SEPARATED BY space.
*
*      IF l_wa_mat-varuom <> v_waers.
*        WRITE : l_wa_mat-varuom TO l_uom.
*      ELSE.
*        WRITE : v_waers TO l_uom.
*      ENDIF.
*      CONCATENATE l_svars l_uom INTO wa_nodestab-text4
*                                SEPARATED BY space.
*      wa_nodestab-tcolor   = c_6.
*      wa_nodestab-tcolor1  = c_6.
*      wa_nodestab-tcolor2  = c_6.
*      wa_nodestab-tcolor3  = c_6.
*      wa_nodestab-tcolor4  = c_6.
*
*      APPEND wa_nodestab TO i_nodestab.
*      CLEAR : wa_nodestab, l_aqtys, l_sqtys, l_svars.
*    ENDLOOP.
*  ENDLOOP.
*
*  i_h_phs = l_i_phs.
*ENDFORM.                    " DISPLAY_PHASE_REPORT
*
**&--------------------------------------------------------------------*
**&      Form  display_summary_report
**&--------------------------------------------------------------------*
**       text
**---------------------------------------------------------------------*
*FORM display_summary_report.
*
*  DATA: l_prdqty  TYPE gamng,
*        l_prdq    TYPE char18,
*        l_wprdqty TYPE menge_d,
*        l_tprdqty TYPE menge_d,
*        l_prduom  TYPE meins,
*
*        l_act    TYPE char16,
*        l_std    TYPE char16,
*
*        l_actt   TYPE char16,
*        l_stdt   TYPE char16,
*        l_svart  TYPE char18,
*
*        l_amenge TYPE menge_d,
*        l_smenge TYPE menge_d,
*        l_menge  TYPE menge_d,
*
*        l_astprs  TYPE ty_stprs,
*        l_sstprs  TYPE ty_stprs,
*        l_stprs   TYPE ty_stprs,
*        l_stprsq  TYPE ty_stprs,
*        l_varprsq TYPE ty_stprs,
*
*        l_matuom TYPE meins,
*        l_stduom TYPE meins,
*        l_varuom TYPE meins,
*        l_uom    TYPE meins,
*
*        l_aqty   TYPE char18,
*        l_sqty   TYPE char18,
*        l_svar   TYPE char18,
*        l_svarp  TYPE char18,
*        l_svarq  TYPE char18,
*
*        l_aqtyv  TYPE char18,
*        l_sqtyv  TYPE char18,
*        l_svarv  TYPE char18,
*        l_svarpv TYPE char18,
*
*        l_aqtyg  TYPE char18,
*        l_sqtyg  TYPE char18,
*        l_svarg  TYPE char18,
*        l_svargq TYPE char18,
*
*        l_aqtys  TYPE char18,
*        l_sqtys  TYPE char18,
*        l_svars  TYPE char18,
*
*        l_total1  TYPE char1,
*        l_total2  TYPE char1,
*        l_total3  TYPE char1,
*
*        l_totalg1 TYPE char1,
*        l_totalg2 TYPE char1,
*        l_totalg3 TYPE char1,
*
*        l_wa_acts TYPE ty_hier_act_sum,
*        l_wa_mats TYPE ty_hier_mat_sum.
*
*  PERFORM pfstatus.
*  SET PF-STATUS 'MAIN' EXCLUDING i_fcode.
*  SET TITLEBAR 'VARI' WITH text-067.
*
*  REFRESH : i_nodestab.
*
*  MOVE 'Display Summary Report'(029) TO v_output_text.
*  PERFORM inform_user_of_progress.
*
*  CLEAR wa_nodestab.
*  wa_nodestab-id = c_1_1.
*  wa_nodestab-tlevel = c_1.
*  wa_nodestab-text = 'Production Variances'(031).
*  wa_nodestab-tlength = c_20.
*  wa_nodestab-compress = c_x.
*  APPEND wa_nodestab TO i_nodestab.
*
*  CLEAR: wa_nodestab.
*  wa_nodestab-id     = c_2_1.
*  wa_nodestab-tlevel = c_2.
*  wa_nodestab-parent = c_1_1.
*
*  CONCATENATE 'Summary of Orders for'(046) 'Plant:'(047) p_werks
*         INTO wa_nodestab-text SEPARATED BY space.
*  wa_nodestab-tlength = c_45.
*  wa_nodestab-tcolor  = c_1.
*
*  IF r_steus IS INITIAL.
*    wa_nodestab-text1 = 'Control Key : ALL'(075).
*  ELSE.
*    CLEAR : wa_steus.
*    READ TABLE r_steus INTO wa_steus INDEX 1.
*    CONCATENATE 'Control Key:'(048) wa_steus-low 'TO' wa_steus-high
*           INTO wa_nodestab-text1 SEPARATED BY space.
*  ENDIF.
*  wa_nodestab-tlength1 = c_25.
*  wa_nodestab-tcolor1  = c_1.
*
*  IF s_arbpl[] IS INITIAL.
*    wa_nodestab-text2 = 'Resources: All'(049).
*  ELSE.
*    CONCATENATE 'Resources:'(065) s_arbpl-low c_hyp s_arbpl-high
*           INTO wa_nodestab-text2 SEPARATED BY space.
*  ENDIF.
*  wa_nodestab-tlength2 = c_25.
*  wa_nodestab-tcolor2  = c_1.
*
*  APPEND wa_nodestab TO i_nodestab.
*
*  CLEAR : l_tprdqty.
*  LOOP AT i_h_ord INTO wa_h_ord.
** convert to KG
*    CLEAR : l_wprdqty.
*    IF wa_h_ord-bsuom <> 'KG'.
*      PERFORM convert_to_kg USING   wa_h_ord-plnbez wa_h_ord-bsuom
*                                    wa_h_ord-gewei  wa_h_ord-ntgew
*                                    wa_h_ord-bprdqty
*                           CHANGING l_wprdqty
*                                    v_conv_rc.
*      IF v_conv_rc <> 'X'.
*        l_prdqty = l_wprdqty.
*        l_prduom = 'KG'.
*      ELSE.
*        CLEAR : l_wprdqty.
*      ENDIF.
*
*    ELSE.
*      l_prdqty = wa_h_ord-bprdqty.
*      l_prduom = 'KG'.
*    ENDIF.
*
*    l_tprdqty = l_tprdqty + l_prdqty.
*  ENDLOOP.
*
*  WRITE : l_tprdqty TO l_prdq UNIT 'KG' NO-GROUPING.
*
*  CLEAR : wa_nodestab.
*  wa_nodestab-id     = c_3_1.
*  wa_nodestab-tlevel = c_3.
*  wa_nodestab-parent = c_2_1.
*
**** text for Order Qty
*  IF rb_pland = c_x.
*** Planned Production
*    CONCATENATE 'Plan Qty:'(076) l_prdq 'KG'
*           INTO wa_nodestab-text SEPARATED BY space.
*  ELSE.
*** Actual Production
*    IF rb_prod = c_x.
** Produced
*      CONCATENATE 'Prod Qty:'(033) l_prdq 'KG'
*             INTO wa_nodestab-text SEPARATED BY space.
*    ELSE.
** Confirmed
*      CONCATENATE 'Conf Qty:'(034) l_prdq 'KG'
*             INTO wa_nodestab-text SEPARATED BY space.
*    ENDIF.
*  ENDIF.
*
*  CONDENSE : wa_nodestab-text.
*
*  wa_nodestab-tlength = c_35.
*  wa_nodestab-tcolor  = c_1.
*
*  APPEND wa_nodestab TO i_nodestab.
*
****
**** Activity Summary
****
*  CLEAR : wa_nodestab.
*  wa_nodestab-id     = c_3_2.
*  wa_nodestab-tlevel = c_3.
*  wa_nodestab-parent = c_2_1.
*
*  wa_nodestab-text    = 'Activity'(052).
*  wa_nodestab-tlength = 34.
*
*  wa_nodestab-tlength1 = c_20.
*  wa_nodestab-tlength2 = c_20.
*  wa_nodestab-tlength3 = c_24.
*  wa_nodestab-tlength4 = c_20.
*
*  IF rb_fiscl = c_x.
*    CONCATENATE 'Actual Usage'(040) v_waers
*           INTO wa_nodestab-text1 SEPARATED BY space.
*
*    CONCATENATE 'Standard Usage'(041) v_waers
*           INTO wa_nodestab-text2 SEPARATED BY space.
*
*    CONCATENATE 'Standard Usage Var'(042) v_waers
*           INTO wa_nodestab-text3 SEPARATED BY space.
*
*  ELSE.
*    CONCATENATE 'Actual Usage'(040) 'UoM'
*           INTO wa_nodestab-text1 SEPARATED BY space.
*
*    CONCATENATE 'Standard Usage'(041) 'UoM'
*           INTO wa_nodestab-text2 SEPARATED BY space.
*
*    CONCATENATE 'Standard Usage Var'(042) 'UoM'
*           INTO wa_nodestab-text3 SEPARATED BY space.
*
*  ENDIF.
*
*  CONCATENATE 'Standard Usage Var'(042) c_perc
*         INTO wa_nodestab-text4 SEPARATED BY space.
*
*  wa_nodestab-tcolor  = c_4.
*  wa_nodestab-tcolor1 = c_4.
*  wa_nodestab-tcolor2 = c_4.
*  wa_nodestab-tcolor3 = c_4.
*  wa_nodestab-tcolor4 = c_4.
*  APPEND wa_nodestab TO i_nodestab.
*
*  CLEAR : flg_color , l_actt , l_stdt , l_svart , l_svarp,
*          l_wa_acts.
*  LOOP AT i_parn INTO wa_parn.
*    CLEAR : wa_acts, flg_color , l_act , l_std , l_svar , l_svarp.
*    LOOP AT i_h_act INTO wa_h_act WHERE parxx = wa_parn-parxx.
*      wa_acts-parxx = wa_h_act-parxx.
*      wa_acts-txtxx = wa_h_act-txtxx.
*
*      IF rb_quant EQ c_x.
*        wa_acts-ilexx  = wa_h_act-ilexx.
*        wa_acts-ismxx  = wa_acts-ismxx  + wa_h_act-ismxx.
*        wa_acts-vgexx  = wa_h_act-vgexx.
*        wa_acts-vgwxx  = wa_acts-vgwxx  + wa_h_act-vgwxx.
*        wa_acts-stdvar = wa_acts-stdvar + wa_h_act-stdvar.
*
*        IF wa_acts-ilexx IS INITIAL AND NOT wa_acts-vgexx IS INITIAL.
*          wa_acts-ilexx = wa_acts-vgexx.
*
*        ELSEIF NOT wa_acts-ilexx IS INITIAL AND
*                   wa_acts-vgexx IS INITIAL.
*          wa_acts-vgexx = wa_acts-ilexx.
*        ENDIF.
*
*      ELSE.
*
*        IF wa_h_act-toexx <> 0.
*          wa_acts-actu = wa_acts-actu + wa_h_act-ismxx  *
*                       ( wa_h_act-togxx / wa_h_act-toexx ).
*          wa_acts-stdu = wa_acts-stdu + wa_h_act-vgwxx  *
*                       ( wa_h_act-togxx / wa_h_act-toexx ).
*          wa_acts-varu = wa_acts-varu + wa_h_act-stdvar *
*                       ( wa_h_act-togxx / wa_h_act-toexx ).
*        ENDIF.
*      ENDIF.
*    ENDLOOP.
*
*    CLEAR : wa_nodestab.
*    wa_nodestab-id     = c_4_1.
*    wa_nodestab-tlevel = c_4.
*    wa_nodestab-parent = c_3_2.
*
*    wa_nodestab-text    = wa_acts-txtxx.
*    wa_nodestab-tlength = c_30.
*    wa_nodestab-tlength1 = c_20.
*    wa_nodestab-tlength2 = c_20.
*    wa_nodestab-tlength3 = c_24.
*    wa_nodestab-tlength4 = c_20.
*
*    IF rb_quant = c_x.
*      WRITE : wa_acts-ismxx TO l_act UNIT wa_acts-ilexx NO-GROUPING,
*              wa_acts-ilexx TO l_uom.
*      CONCATENATE l_act l_uom INTO wa_nodestab-text1
*                              SEPARATED BY space.
*
*      WRITE : wa_acts-vgwxx TO l_std UNIT wa_acts-vgexx NO-GROUPING,
*              wa_acts-vgexx TO l_uom.
*      CONCATENATE l_std l_uom INTO wa_nodestab-text2
*                              SEPARATED BY space.
*
*      WRITE : wa_acts-stdvar TO l_svar UNIT wa_acts-vgexx NO-GROUPING.
*      CONCATENATE l_svar l_uom INTO wa_nodestab-text3
*                               SEPARATED BY space.
*      IF wa_acts-vgwxx <> 0.
*        wa_acts-varper = ( wa_acts-stdvar / wa_acts-vgwxx ) * 100.
*      ENDIF.
*
*      WRITE wa_acts-varper TO l_svarp DECIMALS 2 NO-GROUPING.
*      CONCATENATE l_svarp c_perc INTO wa_nodestab-text4
*                                 SEPARATED BY space.
*      IF wa_acts-ismxx <> 0.
*        IF l_total2 <> c_x.
*          l_total2 = c_x.
*          l_wa_acts-ilexx = wa_acts-ilexx.
*        ENDIF.
*
*        IF l_wa_acts-ilexx = wa_acts-ilexx AND NOT l_wa_acts-ilexx IS
*        INITIAL.
*          l_wa_acts-ismxx = l_wa_acts-ismxx + wa_acts-ismxx.
*          l_wa_acts-ilexx = wa_acts-ilexx.
*
*        ELSEIF wa_acts-ismxx <> 0.
*          CLEAR : l_wa_acts-ismxx , l_wa_acts-ilexx, l_actt.
*        ENDIF.
*      ENDIF.
*
*      IF wa_acts-vgwxx <> 0.
*        IF l_total1 <> c_x.
*          l_total1 = c_x.
*          l_wa_acts-vgexx = wa_acts-vgexx.
*        ENDIF.
*
*        IF l_wa_acts-vgexx = wa_acts-vgexx AND NOT l_wa_acts-vgexx IS
*        INITIAL.
*          l_wa_acts-vgwxx  = l_wa_acts-vgwxx  + wa_acts-vgwxx.
*          l_wa_acts-stdvar = l_wa_acts-stdvar + wa_acts-stdvar.
*          l_wa_acts-vgexx = wa_acts-vgexx.
*
*        ELSEIF wa_acts-vgwxx <> 0.
*          CLEAR : l_wa_acts-vgwxx , l_wa_acts-vgexx, l_wa_acts-stdvar,
*                  l_stdt, l_svart.
*        ENDIF.
*      ENDIF.
*
*      WRITE l_wa_acts-ismxx  TO l_actt
*      UNIT l_wa_acts-ilexx NO-GROUPING
*      .
*      WRITE l_wa_acts-vgwxx  TO l_stdt
*       UNIT l_wa_acts-vgexx NO-GROUPING
*      .
*      WRITE l_wa_acts-stdvar TO l_svart
*      UNIT l_wa_acts-vgexx NO-GROUPING
*      .
*
*    ELSE.
*      WRITE : wa_acts-actu TO l_act CURRENCY v_waers NO-GROUPING.
**      l_act = wa_acts-actu.
*      CONCATENATE l_act v_waers INTO wa_nodestab-text1
*                                SEPARATED BY space.
*
*      WRITE : wa_acts-stdu TO l_std CURRENCY v_waers NO-GROUPING.
**      l_std = wa_acts-stdu.
*      CONCATENATE l_std v_waers INTO wa_nodestab-text2
*                                SEPARATED BY space.
*
*      WRITE : wa_acts-varu TO l_svar CURRENCY v_waers NO-GROUPING.
**      l_svar = wa_acts-varu.
*      CONCATENATE l_svar v_waers INTO wa_nodestab-text3
*                                 SEPARATED BY space.
*
*      IF wa_acts-stdu <> 0.
*        wa_acts-varper = ( wa_acts-varu / wa_acts-stdu ) * 100.
*      ENDIF.
*      l_svarp = wa_acts-varper.
*      CONCATENATE l_svarp c_perc INTO wa_nodestab-text4
*                                 SEPARATED BY space.
*
*      l_wa_acts-actu = l_wa_acts-actu + wa_acts-actu.
*      l_wa_acts-stdu = l_wa_acts-stdu + wa_acts-stdu.
*      l_wa_acts-varu = l_wa_acts-varu + wa_acts-varu.
*
*      WRITE l_wa_acts-actu TO l_actt CURRENCY v_waers NO-GROUPING.
*      WRITE l_wa_acts-stdu TO l_stdt CURRENCY v_waers NO-GROUPING.
*      WRITE l_wa_acts-varu TO l_svart CURRENCY v_waers NO-GROUPING.
*      l_wa_acts-ilexx = v_waers.
*      l_wa_acts-vgexx = v_waers.
*    ENDIF.
*
*    IF flg_color = c_x.
*      CLEAR flg_color.
*      wa_nodestab-tcolor  = c_3.
*      wa_nodestab-tcolor1 = c_3.
*      wa_nodestab-tcolor2 = c_3.
*      wa_nodestab-tcolor3 = c_3.
*      wa_nodestab-tcolor4 = c_3.
*    ELSE.
*      flg_color = c_x.
*      wa_nodestab-tcolor  = c_2.
*      wa_nodestab-tcolor1 = c_2.
*      wa_nodestab-tcolor2 = c_2.
*      wa_nodestab-tcolor3 = c_2.
*      wa_nodestab-tcolor4 = c_2.
*    ENDIF.
*    APPEND wa_nodestab TO i_nodestab.
*  ENDLOOP.
** Displaying Activity Subtotals
*  CLEAR  wa_nodestab.
*  wa_nodestab-id     = c_4_1.
*  wa_nodestab-tlevel = c_4.
*  wa_nodestab-parent = c_3_2.
*
*  wa_nodestab-text     = 'Activity Totals'(074).
*  wa_nodestab-tlength  = c_30.
*  wa_nodestab-tlength1 = c_20.
*  wa_nodestab-tlength2 = c_20.
*  wa_nodestab-tlength3 = c_24.
*
*  IF l_wa_acts-ilexx <> v_waers.
*    WRITE : l_wa_acts-ilexx TO l_uom.
*  ELSE.
*    WRITE : v_waers TO l_uom.
*  ENDIF.
*  CONCATENATE l_actt  l_uom INTO wa_nodestab-text1
*                            SEPARATED BY space.
*
*  IF l_wa_acts-vgexx <> v_waers.
*    WRITE : l_wa_acts-vgexx TO l_uom.
*  ELSE.
*    WRITE : v_waers TO l_uom.
*  ENDIF.
*  CONCATENATE l_stdt  l_uom INTO wa_nodestab-text2
*                            SEPARATED BY space.
*
*  CONCATENATE l_svart l_uom INTO wa_nodestab-text3
*                            SEPARATED BY space.
*
*  wa_nodestab-tcolor  =  c_6.
*  wa_nodestab-tcolor1  = c_6.
*  wa_nodestab-tcolor2  = c_6.
*  wa_nodestab-tcolor3  = c_6.
*
*  APPEND wa_nodestab TO i_nodestab.
*  CLEAR : wa_nodestab.
*
****
**** Material Information
****
*  READ TABLE i_h_mat INTO wa_h_mat INDEX 1.
*  IF sy-subrc = 0.
*
*    CLEAR : wa_nodestab.
*    wa_nodestab-id      = c_3_3.
*    wa_nodestab-tlevel  = c_3.
*    wa_nodestab-parent  = c_2_1.
*    PERFORM material_header USING wa_nodestab.
*
*    APPEND wa_nodestab TO i_nodestab.
*
*    CLEAR : wa_nodestab , l_amenge  , l_smenge  , l_wa_mats,
*            l_totalg1   , l_totalg2 , l_totalg3 ,
*            l_sqtyg     , l_aqtyg   , l_svarg ,
*            l_svargq    , l_stprsq.
*
*    LOOP AT i_matn INTO wa_matn.
*      CLEAR : wa_mats  , l_sqty   , l_aqty  , l_svar  , l_svarp,
*              l_svarq  , l_varprsq,
*              l_total1 , l_total2 , l_total3, l_menge , l_stprs.
*
*      LOOP AT i_h_mat INTO wa_h_mat WHERE matnr = wa_matn-matnr
*                                      AND bwart = wa_matn-bwart.
*        "28/06/2005++
*        CLEAR : l_amenge , l_astprs , l_smenge , l_sstprs.
*
*        l_sstprs = l_stprs.
*        l_smenge = l_menge.
*        PERFORM do_mat_calc CHANGING wa_h_mat
*                                     l_aqtyv   l_matuom
*                                     l_sqtyv   l_stduom
*                                     l_svarv   l_varuom
*                                     l_svarpv
*                                     l_amenge  l_smenge
*                                     l_astprs  l_sstprs.
*        l_stprs = l_stprs + l_sstprs.
*        l_menge = l_menge + l_smenge.
*
*        CHECK wa_h_mat-sumi = c_x.
*        CLEAR : l_menge , l_stprs.
*
*        IF rb_quant EQ c_x.
*          IF l_matuom IS INITIAL OR l_matuom EQ l_stduom.
*            wa_h_mat-stdvar = l_smenge - l_amenge.
*          ENDIF.
*
*          IF l_amenge <> 0.
*            IF l_total1 <> c_x.
*              l_total1 = c_x.
*              wa_mats-actuom = l_matuom.
*            ENDIF.
*
*            IF wa_mats-actuom = l_matuom.
*              wa_mats-actusg = wa_mats-actusg + l_amenge.
*            ELSE.
*              CLEAR : wa_mats-actusg , wa_mats-actuom, l_aqty ,
*                      wa_mats-actuom.
*            ENDIF.
*          ENDIF.
*
*          IF l_smenge <> 0.
*            IF l_total2 <> c_x.
*              l_total2 = c_x.
*              wa_mats-stduom = l_stduom.
*            ENDIF.
*
*            IF wa_mats-stduom = l_stduom.
*              wa_mats-stdusg = wa_mats-stdusg + l_smenge.
*            ELSE.
*              CLEAR : wa_mats-stdusg , wa_mats-stduom, l_sqty ,
*                      wa_mats-stduom.
*            ENDIF.
*          ENDIF.
*
*          IF wa_h_mat-stdvar <> 0.
*            IF l_total3 <> c_x.
*              l_total3 = c_x.
*              wa_mats-varuom = l_stduom.
*            ENDIF.
*
*            IF wa_mats-varuom = l_stduom.
*              wa_mats-stdvar = wa_mats-stdvar + wa_h_mat-stdvar.
*            ELSE.
*              CLEAR : wa_mats-stdvar, wa_mats-varuom, l_svar.
*            ENDIF.
*          ENDIF.
*
*          WRITE : wa_mats-actusg TO l_aqty UNIT wa_mats-actuom
*                                           NO-GROUPING.
*          WRITE : wa_mats-stdusg TO l_sqty UNIT wa_mats-stduom
*                                           NO-GROUPING.
*          WRITE : wa_mats-stdvar TO l_svar UNIT wa_mats-stduom
*                                           NO-GROUPING.
*
*          wa_mats-astprs = wa_mats-astprs + l_astprs.
*          wa_mats-sstprs = wa_mats-sstprs + l_sstprs.
*          wa_mats-varprs = wa_mats-varprs + l_sstprs - l_astprs.
*
*          v_prs = wa_mats-varprs.
*          WRITE : v_prs TO l_svarq CURRENCY v_waers NO-GROUPING.
*        ELSE.
*
*          wa_mats-astprs = wa_mats-astprs + l_astprs.
*          wa_mats-sstprs = wa_mats-sstprs + l_sstprs.
*          wa_mats-varprs = wa_mats-varprs + l_sstprs - l_astprs.
*
*          wa_mats-actuom = v_waers.
*          wa_mats-stduom = v_waers.
*          wa_mats-varuom = v_waers.
*
*          v_prs = wa_mats-astprs.
*          WRITE : v_prs TO l_aqty CURRENCY v_waers NO-GROUPING.
*          v_prs = wa_mats-sstprs.
*          WRITE : v_prs TO l_sqty CURRENCY v_waers NO-GROUPING.
*          v_prs = wa_mats-varprs.
*          WRITE : v_prs TO l_svar CURRENCY v_waers NO-GROUPING.
*        ENDIF.
*
*        wa_mats-matnr  = wa_h_mat-matnr.
*        wa_mats-maktx  = wa_h_mat-maktx.
*
*        l_varprsq = wa_mats-varprs.
*      ENDLOOP.
*
*      IF wa_mats-stduom  = wa_mats-actuom OR wa_mats-actuom IS INITIAL.
*        CASE c_x.
*          WHEN rb_quant.
*            IF wa_mats-stdusg > 0.
*              wa_mats-varper = ( wa_mats-stdvar / wa_mats-stdusg ) *
*                                 100.
*            ELSE.
*              wa_mats-varper = 0.
*            ENDIF.
*
*          WHEN rb_fiscl.
*            IF wa_mats-sstprs > 0.
*              wa_mats-varper = ( wa_mats-varprs / wa_mats-sstprs ) *
*                                 100.
*            ELSE.
*              wa_mats-varper = 0.
*            ENDIF.
*        ENDCASE.
*      ENDIF.
*      WRITE wa_mats-varper TO l_svarp DECIMALS 2 NO-GROUPING.
*
*      IF l_aqty CA '123456789'.
*        IF l_totalg1 <> c_x.
*          l_totalg1 = c_x.
*          l_wa_mats-actuom = wa_mats-actuom.
*        ENDIF.
*
*        IF l_wa_mats-actuom <> wa_mats-actuom.
*          CLEAR : l_wa_mats-actusg , l_wa_mats-astprs , l_aqtyg ,
*                  l_wa_mats-actuom , wa_mats-actusg , wa_mats-astprs.
*        ENDIF.
*      ENDIF.
*
*      IF l_sqty CA '123456789'.
*        IF l_totalg2 <> c_x.
*          l_totalg2 = c_x.
*          l_wa_mats-stduom  = wa_mats-stduom.
*        ENDIF.
*
*        IF l_wa_mats-stduom <> wa_mats-stduom.
*          CLEAR : l_wa_mats-stdusg , l_wa_mats-sstprs , l_sqtyg ,
*                  l_wa_mats-stduom , wa_mats-stdusg , wa_mats-sstprs .
*        ENDIF.
*      ENDIF.
*
*      IF l_svar CA '123456789'.
*        IF l_totalg3 <> c_x.
*          l_totalg3 = c_x.
*          l_wa_mats-varuom  = wa_mats-varuom.
*        ENDIF.
*
*        IF l_wa_mats-varuom  <> wa_mats-varuom.
*          CLEAR : l_wa_mats-stdvar, l_wa_mats-varprs , l_svarg ,
*                  l_wa_mats-varuom, wa_mats-stdvar , wa_mats-varprs.
*        ENDIF.
*      ENDIF.
*
*      CASE c_x.
*        WHEN rb_quant.
*          l_wa_mats-actusg  = l_wa_mats-actusg  + wa_mats-actusg.
*          WRITE : l_wa_mats-actusg TO l_aqtyg UNIT l_wa_mats-actuom
*          NO-GROUPING.
*
*          l_wa_mats-stdusg  = l_wa_mats-stdusg  + wa_mats-stdusg.
*          WRITE : l_wa_mats-stdusg TO l_sqtyg UNIT l_wa_mats-stduom
*          NO-GROUPING.
*
*          l_wa_mats-stdvar  = l_wa_mats-stdvar  + wa_mats-stdvar.
*          WRITE : l_wa_mats-stdvar TO l_svarg UNIT l_wa_mats-varuom
*          NO-GROUPING.
*
*          l_stprsq  = l_stprsq  + l_varprsq.
*          v_prs = l_stprsq.
*          WRITE : v_prs TO l_svargq CURRENCY v_waers NO-GROUPING.
*
*        WHEN rb_fiscl.
*          l_wa_mats-astprs  = l_wa_mats-astprs  + wa_mats-astprs.
*          v_prs = l_wa_mats-astprs.
*          WRITE : v_prs TO l_aqtyg CURRENCY v_waers NO-GROUPING.
*
*          l_wa_mats-sstprs  = l_wa_mats-sstprs  + wa_mats-sstprs.
*          v_prs = l_wa_mats-sstprs.
*          WRITE : v_prs TO l_sqtyg CURRENCY v_waers NO-GROUPING.
*
*          l_wa_mats-varprs  = l_wa_mats-varprs  + wa_mats-varprs.
*          v_prs = l_wa_mats-varprs.
*          WRITE : v_prs TO l_svarg CURRENCY v_waers NO-GROUPING.
*      ENDCASE.
*
*      CLEAR: wa_nodestab.
*      wa_nodestab-id     = c_4_2.
*      wa_nodestab-tlevel = c_4.
*      wa_nodestab-parent = c_3_3.
*
*      wa_nodestab-tcolor   = c_3.
*      wa_nodestab-tcolor1  = c_3.
*      wa_nodestab-tcolor2  = c_3.
*      wa_nodestab-tcolor3  = c_3.
*      wa_nodestab-tcolor4  = c_3.
*      wa_nodestab-tcolor5  = c_3.
*
*      wa_nodestab-tlength  = c_18.
*      wa_nodestab-tlength1 = c_30.
*      wa_nodestab-tlength2 = c_22.
*      wa_nodestab-tlength3 = c_22.
*      wa_nodestab-tlength4 = c_24.
*      wa_nodestab-tlength5 = c_20.
*
** Material Number
*      WRITE wa_mats-matnr TO wa_nodestab-text NO-ZERO.
** Material Description
*      wa_nodestab-text1 = wa_mats-maktx.
*
*      IF wa_mats-actuom <> v_waers.
*        WRITE : wa_mats-actuom TO l_uom.
*      ELSE.
*        WRITE : v_waers TO l_uom.
*      ENDIF.
*      CONCATENATE l_aqty l_uom INTO wa_nodestab-text2
*                               SEPARATED BY space.
*
*      IF wa_mats-stduom <> v_waers.
*        WRITE : wa_mats-stduom TO l_uom.
*      ELSE.
*        WRITE : v_waers TO l_uom.
*      ENDIF.
*      CONCATENATE l_sqty l_uom INTO wa_nodestab-text3
*                               SEPARATED BY space.
*
*      IF wa_mats-varuom <> v_waers.
*        WRITE : wa_mats-varuom TO l_uom.
*      ELSE.
*        WRITE : v_waers TO l_uom.
*      ENDIF.
*      CONCATENATE l_svar l_uom INTO wa_nodestab-text4
*                               SEPARATED BY space.
*
*      CONCATENATE l_svarp c_perc INTO wa_nodestab-text5
*                                 SEPARATED BY space.
*
*      IF rb_quant = c_x.
*        wa_nodestab-tcolor6   = c_3.
*        wa_nodestab-tlength6  = c_24.
*        CONCATENATE l_svarq v_waers INTO wa_nodestab-text6
*                                    SEPARATED BY space.
*      ENDIF.
*
*      APPEND wa_nodestab TO i_nodestab.
*      CLEAR : wa_nodestab.
*    ENDLOOP.
*
**** Displaying Material Subtotals
*    CLEAR  wa_nodestab.
*    wa_nodestab-id     = c_4_2.
*    wa_nodestab-tlevel = c_4.
*    wa_nodestab-parent = c_3_3.
*
*    wa_nodestab-text    = 'Material Totals'(043).
*    wa_nodestab-text1 = space.
*
*    wa_nodestab-tlength =  c_18.
*    wa_nodestab-tlength2 = c_22.
*    wa_nodestab-tlength1 = c_30.
*    wa_nodestab-tlength3 = c_22.
*    wa_nodestab-tlength4 = c_24.
*    wa_nodestab-tlength5 = c_20.
*
*    IF l_wa_mats-actuom <> v_waers.
*      WRITE : l_wa_mats-actuom TO l_uom.
*    ELSE.
*      WRITE : v_waers TO l_uom.
*    ENDIF.
*    CONCATENATE l_aqtyg l_uom INTO wa_nodestab-text2
*                              SEPARATED BY space.
*
*    IF l_wa_mats-stduom <> v_waers.
*      WRITE : l_wa_mats-stduom TO l_uom.
*    ELSE.
*      WRITE : v_waers TO l_uom.
*    ENDIF.
*    CONCATENATE l_sqtyg l_uom INTO wa_nodestab-text3
*                              SEPARATED BY space.
*
*    IF l_wa_mats-varuom <> v_waers.
*      WRITE : l_wa_mats-varuom TO l_uom.
*    ELSE.
*      WRITE : v_waers TO l_uom.
*    ENDIF.
*    CONCATENATE l_svarg l_uom INTO wa_nodestab-text4
*                              SEPARATED BY space.
*
*    IF rb_quant = c_x.
*      wa_nodestab-tcolor6   = c_6.
*      wa_nodestab-tlength6  = c_24.
*      CONCATENATE l_svargq v_waers INTO wa_nodestab-text6
*                                  SEPARATED BY space.
*    ENDIF.
*
*    wa_nodestab-tcolor  =  c_6.
*    wa_nodestab-tcolor2  = c_6.
*    wa_nodestab-tcolor3  = c_6.
*    wa_nodestab-tcolor4  = c_6.
*
*    APPEND wa_nodestab TO i_nodestab.
*    CLEAR : wa_nodestab.
*  ENDIF.
*
**** Displaying Summary totals
*  IF rb_fiscl = c_x.
**    l_astprs = l_wa_acts-actu * 10 + l_wa_mats-astprs.
**    l_sstprs = l_wa_acts-stdu * 10 + l_wa_mats-sstprs.
*    l_astprs = l_wa_acts-actu + l_wa_mats-astprs.
*    l_sstprs = l_wa_acts-stdu + l_wa_mats-sstprs.
*
*    l_stprs  = l_sstprs - l_astprs.
*
*    v_prs = l_astprs.
*    WRITE : v_prs TO l_aqtys CURRENCY v_waers NO-GROUPING.
*    v_prs = l_sstprs.
*    WRITE : v_prs TO l_sqtys CURRENCY v_waers NO-GROUPING.
*    v_prs = l_stprs.
*    WRITE : v_prs TO l_svars CURRENCY v_waers NO-GROUPING.
*
*    CLEAR  wa_nodestab.
*    wa_nodestab-id     = c_3_4.
*    wa_nodestab-tlevel = c_3.
*    wa_nodestab-parent = c_2_1.
*
*    wa_nodestab-text    = 'Summary Totals'.
*    wa_nodestab-text1 = space.
*
*    wa_nodestab-tlength =  c_18.
*    wa_nodestab-tlength2 = c_22.
*    wa_nodestab-tlength1 = c_30.
*    wa_nodestab-tlength3 = c_22.
*    wa_nodestab-tlength4 = c_24.
*
*    WRITE : v_waers TO l_uom.
*    CONCATENATE l_aqtys l_uom INTO wa_nodestab-text2
*                              SEPARATED BY space.
*
*    CONCATENATE l_sqtys l_uom INTO wa_nodestab-text3
*                              SEPARATED BY space.
*
*    CONCATENATE l_svars l_uom INTO wa_nodestab-text4
*                              SEPARATED BY space.
*    wa_nodestab-tcolor  =  c_5.
*    wa_nodestab-tcolor1  = c_5.
*    wa_nodestab-tcolor2  = c_5.
*    wa_nodestab-tcolor3  = c_5.
*    wa_nodestab-tcolor4  = c_5.
*
*    APPEND wa_nodestab TO i_nodestab.
*    CLEAR : wa_nodestab.
*  ENDIF.
*
*ENDFORM.                    " DISPLAY_SUMMARY_REPORT
*
**&--------------------------------------------------------------------*
**&      Form  material_header
**&--------------------------------------------------------------------*
**       text
**---------------------------------------------------------------------*
*FORM material_header USING fp_nodestab TYPE snodetext.
*
*  fp_nodestab-text    = 'Material'(058).
*  fp_nodestab-tlength = c_22.
*  fp_nodestab-tcolor  = c_4.
*  fp_nodestab-propfaw = c_x.
*
*  fp_nodestab-text1    = 'Description'(059).
*  fp_nodestab-tlength1 = c_30.
*  fp_nodestab-tcolor1  = c_4.
*
*  IF rb_fiscl = c_x.
*    CONCATENATE 'Actual Usage'(040) v_waers INTO fp_nodestab-text2
*                                            SEPARATED BY space.
*  ELSE.
*    CONCATENATE 'Actual Usage'(040) 'UoM' INTO fp_nodestab-text2
*                                          SEPARATED BY space.
*  ENDIF.
*  fp_nodestab-tlength2 = c_22.
*  fp_nodestab-tcolor2  = c_4.
*
*  IF rb_fiscl = c_x.
*    CONCATENATE 'Standard Usage'(041) v_waers INTO fp_nodestab-text3
*                                              SEPARATED BY space.
*  ELSE.
*    CONCATENATE 'Standard Usage'(041) 'UoM' INTO fp_nodestab-text3
*                                            SEPARATED BY space.
*  ENDIF.
*  fp_nodestab-tlength3 = c_22.
*  fp_nodestab-tcolor3  = c_4.
*
*  IF rb_fiscl = c_x.
*    CONCATENATE 'Standard Usage Var'(042)
*    v_waers INTO fp_nodestab-text4
*                                                  SEPARATED BY space.
*  ELSE.
*    CONCATENATE 'Standard Usage Var'(042) 'UoM' INTO fp_nodestab-text4
*                                                SEPARATED BY space.
*  ENDIF.
*  fp_nodestab-tlength4 = c_24.
*  fp_nodestab-tcolor4  = c_4.
*
*  CONCATENATE 'Standard Usage Var'(042) c_perc INTO fp_nodestab-text5
*                                               SEPARATED BY space.
*  fp_nodestab-tlength5 = c_20.
*  fp_nodestab-tcolor5  = c_4.
*
*  IF rb_summ = c_x AND rb_quant = c_x.
*    CONCATENATE 'Standard Usage Var'(042)
*    v_waers INTO fp_nodestab-text6
*                                                  SEPARATED BY space.
*    fp_nodestab-tlength6 = c_24.
*    fp_nodestab-tcolor6  = c_4.
*  ENDIF.
*
*ENDFORM.                    " MATERIAL_HEADER
*
***&--------------------------------------------------------------------
***
***&      Form  get_orders
***&--------------------------------------------------------------------
***
***       text
***---------------------------------------------------------------------
***
**FORM get_orders.
**
**  DATA: l_sttxt(100)  TYPE c,
**        flg_status(1) TYPE c.
**
**
**  MOVE 'Extracting Process Orders'(022) TO v_output_text.
**
**  PERFORM inform_user_of_progress.
**
**
****START OF MOD-003.
**  IF NOT p_mtart IS INITIAL.
***"selection filter on material type
**    SELECT matnr     "material number
**           mtart     "material type
**    INTO  TABLE i_mtart
**    FROM mara
**    WHERE matnr IN  s_matnr
**    AND   mtart = p_mtart.
**
**    IF sy-subrc <> 0. " if no corresponding data is found
**
**      MESSAGE i072 WITH p_mtart.
**      "No data was selected for  material type
**      LEAVE LIST-PROCESSING.
**
**    ENDIF.
**  ENDIF.
**
**
**  IF NOT i_mtart IS INITIAL.
**    SELECT aufnr
**           werks
**           kokrs
**           objnr
**           gltrp
**           rsnum
**           gamng
**           gmein
**           plnbez
**           plnty
**           plnnr
**           plnal
**           stlst                                            "mod-001
**           stlty
**           stlnr
**           stlal
**           aufpl
**           zaehl
**           rueck
**           INTO TABLE i_orders FROM caufv
*           FOR ALL ENTRIES IN i_mtart          "----MOD-003
**           WHERE aufnr  IN s_aufnr  AND
**                 werks   = p_werks  AND
**                 kokrs   = p_kokrs  AND
**                 stlan   = p_usage   AND
*                 plnbez  = i_mtart-matnr AND       "----MOD-003
**               ( gstrp IN s_datuv OR gltrp IN s_datuv ).
****END OF MOD-003.
**
**  ELSE.  "----MOD-003
**    SELECT aufnr
**          werks
**          kokrs
**          objnr
**          gltrp
**          rsnum
**          gamng
**          gmein
**          plnbez
**          plnty
**          plnnr
**          plnal
**          stlst                                             " MOD-001
**          stlty
**          stlnr
**          stlal
**          aufpl
**          zaehl
**          rueck
**          INTO TABLE i_orders FROM caufv
**          WHERE aufnr  IN s_aufnr  AND
**                werks   = p_werks  AND
**                kokrs   = p_kokrs  AND
**                plnbez  IN s_matnr AND
**                stlan   = p_usage   AND
**               ( gstrp IN s_datuv OR gltrp IN s_datuv ).
**
**  ENDIF. "----MOD-003
**
**
**  IF sy-subrc <> 0.
**    MESSAGE s007.
**    LEAVE LIST-PROCESSING.
**  ENDIF.
**
**  SORT i_orders BY aufnr.
**
**  LOOP AT i_orders INTO wa_orders.
**
**    IF NOT i_tj02t[] IS INITIAL .
**      PERFORM get_status_info USING wa_orders-objnr l_sttxt.
**
**      CLEAR: flg_status, wa_tj02t.
**      LOOP AT i_tj02t INTO wa_tj02t.
**        IF l_sttxt NS wa_tj02t-txt04.
**          CLEAR flg_status.
**          EXIT.
**        ELSE.
**          flg_status = c_x.
**          CONTINUE.
**        ENDIF.
**        CLEAR : wa_tj02t.
**      ENDLOOP.
**
**      IF flg_status <> c_x.
**        DELETE i_orders.
**        CONTINUE.
**      ENDIF.
**
**      wa_order_status_text-aufnr = wa_orders-aufnr.
**      wa_order_status_text-sttxt = l_sttxt.
**      APPEND wa_order_status_text TO i_order_status_text.
**      CLEAR  wa_order_status_text.
**    ENDIF.
**
**    CLEAR : wa_orders.
**
**  ENDLOOP.
**
***  ENDIF.
**
**ENDFORM.                    " get_orders
***&--------------------------------------------------------------------
***
***&      Form  get_operations
***&--------------------------------------------------------------------
***
***       text
***---------------------------------------------------------------------
**
***---------------------------------------------------------------------
**
**FORM get_operations.
**
**  DATA l_tabix TYPE sytabix.
**
**  MOVE 'Extracting Phase Information'(023) TO v_output_text.
**  PERFORM inform_user_of_progress.
**
**  SELECT aufpl
**         aplzl
**         plnkn
**         plnty
**         plnnr
**         zaehl
**         vornr
**         arbid
**         rueck
**         steus
**         phflg
**         INTO TABLE i_afvc
**         FROM afvc
**         FOR ALL ENTRIES IN i_orders
**         WHERE aufpl = i_orders-aufpl AND
**               steus IN s_steus       AND
**               phflg = c_x.
**
**  IF sy-subrc = 0.
**    SELECT aufpl
**           aplzl
**           bmsch
**           vgw02
**           lmnga
**           ism02
**           ssavd
**           FROM afvv INTO TABLE i_afvv
**           FOR ALL ENTRIES IN i_afvc
**           WHERE aufpl = i_afvc-aufpl AND
**                 aplzl = i_afvc-aplzl AND
**                 ssavd IN s_datuv.
**
**    IF sy-subrc = 0.
**      SORT i_afvv BY aufpl aplzl.
**    ENDIF.
**    IF NOT ( s_kostl[] IS INITIAL ).
**
**      SELECT objty objid kokrs kostl
**      FROM crco INTO TABLE i_crco
**      FOR ALL ENTRIES IN i_afvc
**      WHERE objty = c_objtyp
**        AND objid = i_afvc-arbid.
**      IF sy-subrc = 0.
**        SORT i_crco BY kostl.
**      ENDIF.
**    ENDIF.
**
**    SORT i_crhd   BY objid.
**    SORT i_orders BY aufpl.
**
**    SORT i_afvc BY aufpl vornr DESCENDING.
**
**    LOOP AT i_afvc INTO wa_afvc.
**
**      l_tabix = sy-tabix.
**
**      IF NOT ( s_kostl[] IS INITIAL ).
**        READ TABLE i_crco INTO wa_crco
**              WITH KEY objty = c_objtyp
**                       objid = wa_afvc-arbid
**                       BINARY SEARCH.
**        IF sy-subrc = 0.
**          READ TABLE i_csks INTO wa_csks
**                WITH KEY kostl = wa_crco-kostl.
**          IF sy-subrc <> 0.
**            DELETE i_afvv   WHERE aufpl = wa_afvc-aufpl
**                              AND aplzl = wa_afvc-aplzl.
**            DELETE i_afvc INDEX l_tabix.
**            CONTINUE.
**          ENDIF.
**        ENDIF.
**      ENDIF.
**
*** Check work centre details with resource
**      IF NOT ( s_arbpl[] IS INITIAL ).
**        READ TABLE i_crhd INTO wa_crhd
**              WITH KEY objid = wa_afvc-arbid BINARY SEARCH.
**        IF sy-subrc <> 0.
**          DELETE i_afvv   WHERE aufpl = wa_afvc-aufpl
**                            AND aplzl = wa_afvc-aplzl.
**          DELETE i_afvc INDEX l_tabix.
**          CONTINUE.
**        ELSE.
**          PERFORM move_data2_ordops.
**        ENDIF.
**      ELSE.
**        READ TABLE i_crhd INTO wa_crhd
**            WITH KEY objid = wa_afvc-arbid BINARY SEARCH.
**        PERFORM move_data2_ordops.
**      ENDIF.
**      CLEAR: wa_crco, wa_crhd, l_tabix, wa_afvc.
**    ENDLOOP.
**
**  ENDIF.
**
**ENDFORM.                    " get_operations
***&--------------------------------------------------------------------
***
***&      Form  get_mat_segment
***&--------------------------------------------------------------------
***
***       text
***---------------------------------------------------------------------
***
***---------------------------------------------------------------------
***
**FORM get_mat_segment.
**  DATA: l_menge TYPE menge_d,
**        l_gamng type menge_d,
**        v_menge type menge_d,
**        l_meins TYPE meins,
**        struct_mara type mara,
**        struct_marc type marc.
**  DATA: l_lmnga  TYPE LMNGA,
**        L_CFUOM type meins.
**
**  IF NOT ( i_pro_orders[] IS INITIAL ).
**    IF NOT ( rb_prod IS INITIAL ).
**
*** Extracting goods receipt information
**MOVE 'Extracting Goods Receipt Information'(024) TO v_output_text.
**      PERFORM inform_user_of_progress.
******* Mod-002******************************************************
**      SELECT aufnr mblnr mjahr zeile matnr bwart menge meins
**                                         " sjahr smbln smblp
**             rsnum rspos rsart erfmg erfme
**        FROM aufm               "Table : Goods movements for order
**        INTO TABLE i_mseg1
**         FOR ALL ENTRIES IN i_pro_orders
**       WHERE aufnr = i_pro_orders-aufnr.
***         AND matnr = i_pro_orders-plnbez.
*******Mod-002********************************************************
**      IF sy-subrc = 0.
**
***Addition
**        i_mseg =  i_mseg1.
**        LOOP AT i_pro_orders INTO wa_pro_orders.
**          DELETE i_mseg WHERE aufnr = wa_pro_orders-aufnr
**                          AND matnr <> wa_pro_orders-plnbez.
**        ENDLOOP.
***End of addition
************************Mod-002***************************************
*
**
**        clear: struct_marc.
**        select single *
**        into struct_marc
**        from marc
**        where matnr = wa_pro_orders-plnbez and
**              werks = wa_pro_orders-werks.
**
**        clear: struct_mara.
**        select single *
**        into struct_mara
**        from mara
**        where matnr = wa_pro_orders-plnbez.
**
***************MOD-002************************************************
*
**
**        SORT i_mseg BY aufnr.
**        SORT i_pro_orders BY aufnr.
*** Calculatin the quantity according to the movement type and
*** assign the value to i_pro_orders internal table
**
**        LOOP AT i_mseg INTO wa_mseg.
**          AT NEW aufnr.
**            CLEAR: l_menge, l_meins, v_menge.
**          ENDAT.
**          IF wa_mseg-bwart = c_101.
**            if struct_marc-frtme is initial.
***              l_menge = l_menge + wa_mseg-menge.
***              l_meins = wa_mseg-erfme.
**              if wa_mseg-erfme = struct_mara-meins.
**                l_menge = l_menge + wa_mseg-erfmg.
**                l_meins = wa_mseg-erfme.
**              else.
**                CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
**                  EXPORTING
**                    i_matnr              = wa_pro_orders-plnbez
**                    i_in_me              = wa_mseg-erfme
**                    i_out_me             = struct_mara-meins
**                    i_menge              = wa_mseg-erfmg
**                  IMPORTING
**                    e_menge              = v_menge
**                  EXCEPTIONS
**                    error_in_application = 1
**                    error                = 2
**                    OTHERS               = 3.
**                IF sy-subrc = 0.
**                  wa_mseg-erfmg = v_menge.
**                ENDIF.
**                l_menge = l_menge + wa_mseg-erfmg.
**                l_meins = wa_mseg-erfme.
**              endif.
**            ELSEIF struct_marc-frtme is not initial.
**              if ( struct_marc-frtme = struct_mara-meins ) and
**                 ( wa_mseg-erfme = struct_marc-frtme ).
**                l_menge = l_menge + wa_mseg-erfmg.
**                l_meins = wa_mseg-erfme.
**              elseif ( struct_marc-frtme = struct_mara-meins ) and
**                     ( wa_mseg-erfme ne struct_marc-frtme ).
**                CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
**                  EXPORTING
**                    i_matnr              = wa_pro_orders-plnbez
**                    i_in_me              = wa_mseg-erfme
**                    i_out_me             = struct_marc-frtme
**                    i_menge              = wa_mseg-erfmg
**                  IMPORTING
**                    e_menge              = v_menge
**                  EXCEPTIONS
**                    error_in_application = 1
**                    error                = 2
**                    OTHERS               = 3.
**                IF sy-subrc = 0.
**                  wa_mseg-erfmg = v_menge.
**                ENDIF.
**                l_menge = l_menge + wa_mseg-erfmg.
**                l_meins = wa_mseg-erfme.
**              elseif ( struct_marc-frtme ne struct_mara-meins ) and
**                     ( wa_mseg-erfme ne struct_marc-frtme ).
**                CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
**                  EXPORTING
**                    i_matnr              = wa_pro_orders-plnbez
**                    i_in_me              = wa_mseg-erfme
**                    i_out_me             = struct_marc-frtme
**                    i_menge              = wa_mseg-erfmg
**                  IMPORTING
**                    e_menge              = v_menge
**                  EXCEPTIONS
**                    error_in_application = 1
**                    error                = 2
**                    OTHERS               = 3.
**                IF sy-subrc = 0.
**                  wa_mseg-erfmg = v_menge.
**                ENDIF.
**                l_menge = l_menge + wa_mseg-erfmg.
**                l_meins = wa_mseg-erfme.
**              else.
**                CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
**                  EXPORTING
**                    i_matnr              = wa_pro_orders-plnbez
**                    i_in_me              = wa_mseg-erfme
**                    i_out_me             = struct_marc-frtme
**                    i_menge              = wa_mseg-erfmg
**                  IMPORTING
**                    e_menge              = v_menge
**                  EXCEPTIONS
**                    error_in_application = 1
**                    error                = 2
**                    OTHERS               = 3.
**                IF sy-subrc = 0.
**                  wa_mseg-erfmg = v_menge.
**                ENDIF.
**                l_menge = l_menge + wa_mseg-erfmg.
**                l_meins = wa_mseg-erfme.
**
**              endif.
**            endif.
**          ELSEIF wa_mseg-bwart = c_102.
**            if struct_marc-frtme is initial.
***              l_menge = l_menge - wa_mseg-menge.
***              l_meins = wa_mseg-erfme.
**
**              if wa_mseg-erfme = struct_mara-meins.
**                l_menge = l_menge - wa_mseg-erfmg.
**                l_meins = wa_mseg-erfme.
**              else.
**                CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
**                  EXPORTING
**                    i_matnr              = wa_pro_orders-plnbez
**                    i_in_me              = wa_mseg-erfme
**                    i_out_me             = struct_mara-meins
**                    i_menge              = wa_mseg-erfmg
**                  IMPORTING
**                    e_menge              = v_menge
**                  EXCEPTIONS
**                    error_in_application = 1
**                    error                = 2
**                    OTHERS               = 3.
**                IF sy-subrc = 0.
**                  wa_mseg-erfmg = v_menge.
**                ENDIF.
**                l_menge = l_menge - wa_mseg-erfmg.
**                l_meins = wa_mseg-erfme.
**              endif.
**            ELSEIF struct_marc-frtme is not initial.
**              if ( struct_marc-frtme = struct_mara-meins ) and
**                 ( wa_mseg-erfme = struct_marc-frtme ).
**                l_menge = l_menge - wa_mseg-erfmg.
**                l_meins = wa_mseg-erfme.
**              elseif ( struct_marc-frtme = struct_mara-meins ) and
**                     ( wa_mseg-erfme ne struct_marc-frtme ).
**                CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
**                  EXPORTING
**                    i_matnr              = wa_pro_orders-plnbez
**                    i_in_me              = wa_mseg-erfme
**                    i_out_me             = struct_marc-frtme
**                    i_menge              = wa_mseg-erfmg
**                  IMPORTING
**                    e_menge              = v_menge
**                  EXCEPTIONS
**                    error_in_application = 1
**                    error                = 2
**                    OTHERS               = 3.
**                IF sy-subrc = 0.
**                  wa_mseg-erfmg = v_menge.
**                ENDIF.
**                l_menge = l_menge - wa_mseg-erfmg.
**                l_meins = wa_mseg-erfme.
**              elseif ( struct_marc-frtme ne struct_mara-meins ) and
**                     ( wa_mseg-erfme ne struct_marc-frtme ).
**                CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
**                  EXPORTING
**                    i_matnr              = wa_pro_orders-plnbez
**                    i_in_me              = wa_mseg-erfme
**                    i_out_me             = struct_marc-frtme
**                    i_menge              = wa_mseg-erfmg
**                  IMPORTING
**                    e_menge              = v_menge
**                  EXCEPTIONS
**                    error_in_application = 1
**                    error                = 2
**                    OTHERS               = 3.
**                IF sy-subrc = 0.
**                  wa_mseg-erfmg = v_menge.
**                ENDIF.
**                l_menge = l_menge - wa_mseg-erfmg.
**                l_meins = wa_mseg-erfme.
**              else.
**                CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
**                  EXPORTING
**                    i_matnr              = wa_pro_orders-plnbez
**                    i_in_me              = wa_mseg-erfme
**                    i_out_me             = struct_marc-frtme
**                    i_menge              = wa_mseg-erfmg
**                  IMPORTING
**                    e_menge              = v_menge
**                  EXCEPTIONS
**                    error_in_application = 1
**                    error                = 2
**                    OTHERS               = 3.
**                IF sy-subrc = 0.
**                  wa_mseg-erfmg = v_menge.
**                ENDIF.
**                l_menge = l_menge - wa_mseg-erfmg.
**                l_meins = wa_mseg-erfme.
**              endif.
**            endif.
***          l_menge = l_menge - wa_mseg-menge.*
**          ENDIF.
***          l_meins = wa_mseg-meins.
**
******* End of MOD-002***************************************
**
**          AT END OF aufnr.
**********Mod-002********************************************
*** Don't want zero production orders
**            IF NOT ( rb_ezero IS INITIAL ) AND l_menge = 0.
**              DELETE i_ordops WHERE aufnr = wa_mseg-aufnr.
**              DELETE i_pro_orders WHERE aufnr = wa_mseg-aufnr.
**              CONTINUE.
**            ENDIF.
**            READ TABLE i_pro_orders INTO wa_pro_orders
**              WITH KEY aufnr = wa_mseg-aufnr.
**            wa_pro_orders-menge = l_menge.
**            wa_pro_orders-gruom = l_meins.
**            IF wa_pro_orders-gruom NE wa_pro_orders-gmein.
**              CLEAR l_menge.
**
*** If no conversion possible just use gr qty
**              CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'
**                EXPORTING
**                  kzmeinh              = c_x
**                  input                = wa_pro_orders-menge
**                  matnr                = wa_pro_orders-plnbez
**                  meinh                = wa_pro_orders-gmein
**                  meins                = wa_pro_orders-gruom
**                IMPORTING
**                  output               = l_menge
**                EXCEPTIONS
**                  conversion_not_found = 1
**                  input_invalid        = 2
**                  material_not_found   = 3
**                  meinh_not_found      = 4
**                  meins_missing        = 5
**                  no_meinh             = 6
**                  output_invalid       = 7
**                  overflow             = 8
**                  OTHERS               = 9.
**              IF sy-subrc = 0.
**                wa_pro_orders-menge = l_menge.
**              ENDIF.
************************MOD-003**************************************
**              clear: l_gamng.
**
**              CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'
**                EXPORTING
**                  kzmeinh              = c_x
**                  input                = wa_pro_orders-gamng
**                  matnr                = wa_pro_orders-plnbez
**                  meinh                = wa_pro_orders-gmein
**                  meins                = wa_pro_orders-gruom
**                IMPORTING
**                  output               = l_gamng
**                EXCEPTIONS
**                  conversion_not_found = 1
**                  input_invalid        = 2
**                  material_not_found   = 3
**                  meinh_not_found      = 4
**                  meins_missing        = 5
**                  no_meinh             = 6
**                  output_invalid       = 7
**                  overflow             = 8
**                  OTHERS               = 9.
**              IF sy-subrc = 0.
**                wa_pro_orders-gamng = l_gamng.
**              ENDIF.
**************************MOD-003*************************************
*
***
**            ENDIF.
**            MODIFY i_pro_orders FROM wa_pro_orders
**            TRANSPORTING menge gruom gamng
**            WHERE aufnr = wa_mseg-aufnr.
**          ENDAT.
*************************MOD-003**************************************
**          CLEAR : wa_mseg.
*************************MOD-003**************************************
**
**        ENDLOOP.
**      ENDIF.
*********************MOD-008******************************************
***** Select confirmations using operation confirmation
*     number instead of
***** order number
***      SELECT aufpl
***            aplzl
***            plnkn
***            plnty
***            plnnr
***            zaehl
***            vornr
***            arbid
***            rueck
***            steus
***            phflg
***            INTO TABLE i_afvc1
***            FROM afvc
***            FOR ALL ENTRIES IN i_ordops
***            WHERE aufpl = I_ORDOPS-aufpl AND
***                  steus = 'YBN1' AND
***                  phflg = c_x.
***
***      IF sy-subrc = 0.
***        SORT I_AFVC1 BY aufpl
***                        aplzl
***                        plnkn
***                        plnty
***                        plnnr.
***
***        SELECT aufpl
***               aplzl
***               bmsch
***               vgw02
***               lmnga
***               ism02
***               ssavd
***               FROM afvv INTO TABLE i_afvv1
***               FOR ALL ENTRIES IN i_afvc1
***               WHERE aufpl = i_afvc1-aufpl AND
***                     aplzl = i_afvc1-aplzl.
***
***        IF SY-SUBRC = 0.
***          SORT I_AFVV1 BY AUFPL APLZL.
***        ENDIF.
***      ENDIF.
**
*********************MOD-008******************************************
**      ELSE.
*** Extracting confirmation information
**MOVE 'Extracting Confirmation Information'(025) TO v_output_text.
**        PERFORM inform_user_of_progress.
**
***      SELECT aufnr rueck gmnga lmnga gmein meinh
***             meilr stokz rueck_mst
***       FROM afru INTO TABLE i_afru
***       FOR ALL ENTRIES IN i_pro_orders
***       WHERE rueck = i_pro_orders-rueck AND
**** MOD-001- Begin of change
***             lmnga NE c_0. "    AND
****            meilr NE space.
**** MOD-001- End of change
***      IF sy-subrc = 0.
***        SORT i_afru BY aufnr .
*************MOD-002************************************************
**
**
******************MOD-004*********************************************
***
***      LOOP AT I_ORDOPS INTO WA_ORDOPS.
***        SELECT SINGLE *
***        INTO WA_PLPO3
***        FROM plpo
***        WHERE plnty = WA_ordops-plnty and
***              plnnr = wa_ordops-plnnr and
***              PLNKN = wa_ordops-plnkn and
***              ZAEHL = wa_ordops-zaehl.
***        IF SY-SUBRC = 0.
***          APPEND WA_PLPO3 TO I_PLPO3.
***        ENDIF.
***      ENDLOOP.
****             and   steus = 'YBN1'.
***
******************MOD-005*********************************************
*
****        LOOP AT I_PRO_ORDERS into WA_PRO_ORDERS.
***********************mod-004****************************************
****          READ TABLE I_PLPO3 INTO WA_PLPO3 WITH KEY
****               plnty = wa_pro_orders-plnty
****               plnnr = wa_pro_orders-plnnr
****               plnkn = wa_pro_orders-plnkn
****               zaehl = wa_pro_orders-zaehl.
*****              steus = 'YBN1'.
*********************MOD-004******************************************
*
***
***
******************************MOD-005*******************************
***      LOOP AT I_ORDOPS INTO WA_ORDOPS.
******************************MOD-005******************************
****        READ table i_afvc into wa_afvc with key
*****             aufpl = wa_pro_orders-aufpl
****              aufpl = wa_ordops-aufpl binary search.
****              steus = 'YBN1'
****              phflg = c_x binary search.
***
***********************MOD-005*************************************
***
**********************MOD-006*************************************
***        CLEAR: WA_PLPO3.
***        READ TABLE I_PLPO3 INTO WA_PLPO3 WITH KEY
***               plnty = wa_ordops-plnty
***               plnnr = wa_ordops-plnnr
****               plnkn = wa_ordops-plnkn
****               zaehl = wa_ordops-zaehl
***               steus = 'YBN1' binary search.
****               vornr = wa_ordops-vornr
****               werks = p_werks binary search.
***
**********************MOD-006*************************************
***        IF SY-SUBRC = 0.
****         READ table i_afvc into wa_afvc with key
****              aufpl = wa_ordops-aufpl
****              aplzl = wa_ordops-aplzl
****              plnkn = wa_ordops-plnkn
****              plnty = wa_ordops-plnty
****              plnnr = wa_ordops-plnnr
****              zaehl = wa_ordops-zaehl BINARY SEARCH.
*******************mod-006*******************************************
***          check wa_plpo3-vgw02 IS NOT INITIAL.
***          clear: wa_afvc.
***          READ TABLE i_afvc INTO wa_afvc
***             WITH KEY plnty = wa_plpo3-plnty
***                      plnnr = wa_plpo3-plnnr
***                      plnkn = wa_plpo3-plnkn
***                      zaehl = wa_plpo3-zaehl
***                      aufpl = wa_ordops-aufpl.
***********************MOD-006*************************************
***          if sy-subrc = 0.
********************mod-004*******************************************
*
***
***            CLEAR: WA_AFVV.
***            READ TABLE I_AFVV into wa_afvv with key
***                 aufpl = wa_afvc-aufpl
***                 aplzl = wa_afvc-aplzl binary search.
***            if sy-subrc = 0.
***              CLEAR: I_AFRU.
***              SELECT aufnr rueck gmnga lmnga gmein meinh
***                     meilr stokz rueck_mst
***               FROM afru INTO TABLE i_afru
***               WHERE rueck = wa_afvc-rueck AND
****                WHERE rueck = wa_ordops-rueck AND
****                      aufnr = wa_pro_orders-aufnr.
***                     aufnr = wa_ordops-aufnr.
***
***              if sy-subrc = 0.
***                SORT i_afru BY aufnr RUECK.
***                LOOP AT i_afru INTO wa_afru.
****                          READ TABLE i_pro_orders INTO wa_pro_orders
****                          WITH KEY aufnr = wa_afru-aufnr.
***                  IF sy-subrc = 0.
***                    l_lmnga = l_lmnga + wa_afru-lmnga.
***                    l_cfuom = wa_afru-gmein.
****                            wa_pro_orders-lmnga = wa_afru-lmnga.
****                            wa_pro_orders-cfuom = wa_afru-gmein.
****                            MODIFY i_pro_orders FROM wa_pro_orders
****                            TRANSPORTING lmnga cfuom
****                             WHERE aufnr = wa_afru-aufnr.
***                  ENDIF.
***                ENDLOOP.
***              endif.
*************************MOD-005**************************************
***              wa_ordops-lmnga = l_lmnga.
***              wa_ordops-cfuom = l_cfuom.
***              MODIFY i_ordops FROM wa_ordops
***                  TRANSPORTING lmnga cfuom
******************************MOD-006********************************
***                  where plnty = wa_ordops-plnty and
***                        plnnr = wa_ordops-plnnr and
****                         plnkn = wa_ordops-plnkn and
****                         zaehl = wa_ordops-zaehl and
***                        aufpl = wa_ordops-aufpl.
****************************MOD-006*********************************
***
*******************MOD-003******************************************
***              clear: l_lmnga, l_cfuom.
*******************mod-003**************************************
***            ENDIF.
***          ENDIF.
****           clear: wa_pro_orders.
*****************************mod-004********************************
***        ENDIF.
***        clear: wa_ordops.
***      ENDLOOP.
**************************MOD-005*************************************
***
***      i_ordops1[] = i_ordops[].
***      delete i_ordops1 where lmnga eq 0.
***
***      LOOP AT I_PRO_ORDERS INTO WA_PRO_ORDERS.
***        read table i_ordops1 into wa_ordops1 with key
***                  aufnr = wa_pro_orders-aufnr binary search.
***        IF SY-SUBRC = 0.
***          wa_pro_orders-lmnga = wa_ordops1-lmnga.
***          wa_pro_orders-cfuom = wa_ordops1-cfuom.
***          if wa_pro_orders-menge is initial.
***            wa_pro_orders-menge = wa_pro_orders-gamng.
***          endif.
***          MODIFY i_pro_orders FROM wa_pro_orders
***              TRANSPORTING lmnga cfuom menge
***              where aufnr = wa_ordops1-aufnr.
***        ENDIF.
***      ENDLOOP.
***    endif.
*********************************MOD-007******************************
**
**** Select confirmations using operation confirmation number instead of
**** order number
**        SELECT aufpl
**              aplzl
**              plnkn
**              plnty
**              plnnr
**              zaehl
**              vornr
**              arbid
**              rueck
**              steus
**              phflg
**              INTO TABLE i_afvc1
**              FROM afvc
**              FOR ALL ENTRIES IN i_ordops
**              WHERE aufpl = I_ORDOPS-aufpl AND
**                    steus = 'YBN1' AND
**                    phflg = c_x.
**
**        IF sy-subrc = 0.
**          SORT I_AFVC1 BY aufpl
**                          aplzl
**                          plnkn
**                          plnty
**                          plnnr.
**
**          SELECT aufpl
**                 aplzl
**                 bmsch
**                 vgw02
**                 lmnga
**                 ism02
**                 ssavd
**                 FROM afvv INTO TABLE i_afvv1
**                 FOR ALL ENTRIES IN i_afvc1
**                 WHERE aufpl = i_afvc1-aufpl AND
**                       aplzl = i_afvc1-aplzl.
**
**          IF SY-SUBRC = 0.
**            SORT I_AFVV1 BY AUFPL APLZL.
**
**            LOOP AT I_ORDOPS INTO WA_ORDOPS.
**              READ TABLE I_PRO_ORDERS INTO WA_PRO_ORDERS WITH KEY
**                                            AUFNR = WA_ORDOPS-AUFNR
**                                                      BINARY SEARCH.
**              IF SY-SUBRC = 0.
**                READ table i_afvc1 into wa_afvc1 with key
**                              plnty = wa_ORDOPS-plnty
**                              plnnr = wa_ORDOPS-plnnr
**                              plnkn = wa_ORDOPS-plnkn
**                              zaehl = wa_ORDOPS-zaehl
**                              aufpl = wa_pro_orders-aufpl.
**                IF SY-SUBRC = 0.
**                  READ TABLE I_AFVV1 into wa_afvv1 with key
**                         aufpl = wa_afvc1-aufpl
**                         aplzl = wa_afvc1-aplzl binary search.
**                  IF SY-SUBRC = 0.
**                    CHECK WA_AFVV1-VGW02 NE 0.
**                    select  aufnr
**                            rueck
**                            gmnga
**                            lmnga
**                            gmein
**                            meinh
**                            meilr
**                            stokz
**                            rueck_mst
**                      INTO TABLE I_AFRU1
**                      from afru
**                      where rueck = wa_afvc1-rueck AND
**                            werks = p_werks and
**                            aufnr = WA_PRO_ORDERS-aufnr and
**                            AUFPL = WA_AFVC1-AUFPL AND
**                            APLZL = WA_AFVC1-APLZL.
**
**                    IF SY-SUBRC = 0.
**
**                      perform get_confirmation_qty_new using
**                                                  wa_ordops-lmnga
**                                                  wa_ordops-cfuom.
**
**                      MODIFY i_ordops FROM wa_ordops
**                              TRANSPORTING lmnga cfuom.
**                    ENDIF.
**                  ENDIF.
**                ENDIF.
**              ENDIF.
**
**            ENDLOOP.
**          ENDIF.
**        ENDIF.
**
**        i_ordops1[] = i_ordops[].
**        delete i_ordops1 where lmnga eq 0.
**        delete adjacent duplicates from i_ordops1 comparing
**                                                    aufnr
**                                                    aufpl
**                                                    aplzl
**                                                    plnkn
**                                                    plnty
**                                                    plnnr
**                                                    zaehl
**                                                    vornr.
**
**
**        LOOP AT I_PRO_ORDERS INTO WA_PRO_ORDERS.
**          read table i_ordops1 into wa_ordops1 with key
**                    aufnr = wa_pro_orders-aufnr binary search.
**          IF SY-SUBRC = 0.
**            wa_pro_orders-lmnga = wa_ordops1-lmnga.
**            wa_pro_orders-cfuom = wa_ordops1-cfuom.
**            if wa_pro_orders-menge is initial.
**              wa_pro_orders-menge = wa_pro_orders-gamng.
**            endif.
**            MODIFY i_pro_orders FROM wa_pro_orders
**                TRANSPORTING lmnga cfuom menge
**                where aufnr = wa_ordops1-aufnr.
**          ENDIF.
**        ENDLOOP.
**      endif.
**  endif.
*********MOD-007******************************************************
**
**
**ENDFORM.                    " get_mat_segment
***&--------------------------------------------------------------------
***
***&      Form  get_bom_info
***&--------------------------------------------------------------------
***
***       text
***---------------------------------------------------------------------
***
***---------------------------------------------------------------------
***
**FORM get_bom_info.
**  DATA: wa_doc_segment1 TYPE ty_doc_segment,
**        l_qty TYPE bdmng,
**        l_per TYPE p DECIMALS 3,
**        l_tabix TYPE sytabix,
**        v_menge like ekpo-menge.
**  DATA: STRUCT_MARC TYPE MARC,
**        STRUCT_MARA TYPE MARA.
**
***- Begin of MOD-001
**
**  TYPES: BEGIN OF l_ty_bom_header,
**            stlty TYPE stlty, " BOM category
**            stlnr TYPE stnum, " Bill of material
**            stlal TYPE stalt, " Alternative BOM
**            bmein TYPE basme, " Base unit of measure for BOM
**            bmeng TYPE basmn, " Base Quantity
**          END OF l_ty_bom_header.
**
**  DATA: l_i_bom_header TYPE STANDARD TABLE OF l_ty_bom_header
**        INITIAL SIZE 0,
**
**        l_wa_bom_header TYPE l_ty_bom_header.
**
***- End of MOD-001
**
**  IF NOT i_pro_orders[] IS INITIAL.
**    MOVE 'Extracting BOM Information'(026) TO v_output_text.
**    PERFORM inform_user_of_progress.
**
*** Get issued materials for all process orders
**
***Begin of addition
**
**    IF i_mseg1 IS INITIAL.
**** Mod-002*******************************************************
**      SELECT aufnr mblnr mjahr zeile matnr bwart menge meins
**             rsnum rspos rsart erfmg erfme
**         FROM aufm               "Table : Goods movements for order
**         INTO TABLE i_mseg1
**          FOR ALL ENTRIES IN i_pro_orders
**        WHERE aufnr = i_pro_orders-aufnr.
***          AND matnr = i_pro_orders-plnbez.
****** Mod-002***************************************************
**    ENDIF.
**
**    LOOP AT i_pro_orders INTO wa_pro_orders.
**
**      LOOP AT i_mseg1 INTO wa_doc_segment
**                    WHERE mjahr = wa_pro_orders-wdate+0(4)
**                      AND bwart IN i_r_bwart
**                      AND aufnr = wa_pro_orders-aufnr.
**
**        APPEND wa_doc_segment TO i_doc_segment.
**
**        CLEAR : wa_doc_segment.
**      ENDLOOP.
**      CLEAR : wa_pro_orders.
**    ENDLOOP.
**
**    IF NOT i_doc_segment IS INITIAL.
**
**      SELECT mblnr mjahr zeile sjahr smbln smblp rsnum rspos rsart
**        FROM mseg INTO TABLE i_prev_doc
**         FOR ALL ENTRIES IN i_doc_segment
**       WHERE mblnr = i_doc_segment-mblnr
**         AND mjahr = i_doc_segment-mjahr
**         AND zeile = i_doc_segment-zeile.
**
**    ENDIF.
**
**    IF NOT i_doc_segment IS INITIAL.
**
***End of addition
**
**      SORT i_doc_segment BY aufnr.
**
**      LOOP AT i_doc_segment INTO wa_doc_segment1.
**
**        wa_issued_mat-aufnr = wa_doc_segment1-aufnr.
**
*** No reservation number so see if any other link exists
**
**        IF wa_doc_segment1-rsnum IS INITIAL.
**
*** Try to find any linked previous movements
**          READ TABLE i_prev_doc INTO wa_prev_doc
**          WITH KEY mblnr = wa_doc_segment1-mblnr
**                   mjahr = wa_doc_segment1-mjahr
**                   zeile = wa_doc_segment1-zeile.
**        ENDIF.
**
**        IF wa_doc_segment1-rsnum IS INITIAL AND
**           wa_prev_doc-smbln NE space.
**
**          READ TABLE i_prev_doc INTO wa_prev_doc
**          WITH KEY mblnr = wa_prev_doc-smbln
**                   mjahr = wa_prev_doc-sjahr
**                   zeile = wa_prev_doc-smblp.
**
**          IF sy-subrc = 0 AND NOT ( wa_doc_segment1-rsnum IS INITIAL )
.
***   found a previous record
**            wa_issued_mat-rsnum = wa_prev_doc-rsnum.
**            wa_issued_mat-rspos = wa_prev_doc-rspos.
**            wa_issued_mat-rsart = wa_prev_doc-rsart.
**          ENDIF.
**
**        ELSE.
**          wa_issued_mat-rsnum = wa_doc_segment1-rsnum.
**          wa_issued_mat-rspos = wa_doc_segment1-rspos.
**          wa_issued_mat-rsart = wa_doc_segment1-rsart.
**        ENDIF.
**        wa_issued_mat-matnr = wa_doc_segment1-matnr.
**        IF wa_doc_segment1-bwart = c_movm_low_262
**            OR wa_doc_segment1-bwart = c_movm_low_531.
**          wa_issued_mat-menge = wa_doc_segment1-menge * -1.
**        ELSE.
**          wa_issued_mat-menge = wa_doc_segment1-menge.
**        ENDIF.
**        wa_issued_mat-meins = wa_doc_segment1-meins.
**        COLLECT wa_issued_mat INTO i_issued_mat.
**        CLEAR : wa_doc_segment1, wa_prev_doc.
**      ENDLOOP.
**    ENDIF.
**
*** Selecting reservations
**    SELECT rsnum rspos rsart xloek matnr werks bdmng
**           meins shkzg aufnr dumps vornr rgekz
**           stlty stlnr stlkn stpoz
**           FROM resb INTO TABLE i_reservations
**           FOR ALL ENTRIES IN i_pro_orders
**           WHERE  rsnum = i_pro_orders-rsnum AND
**           aufnr = i_pro_orders-aufnr
**           AND   bdmng > 0
**           AND   dumps = space.
**    IF sy-subrc = 0.
**      SORT i_reservations.
*** Selecting material standard price and price unit
***      SELECT stlty stlnr stlkn stpoz ausch " MOD-001 --
**      SELECT stlty stlnr stlkn stpoz
**      meins menge ausch yyzero"MOD-001++
**              FROM stpo INTO TABLE i_stpo
**              FOR ALL ENTRIES IN i_reservations
**              WHERE stlty = i_reservations-stlty
**              AND   stlnr = i_reservations-stlnr
**              AND   stlkn = i_reservations-stlkn
**              AND   stpoz = i_reservations-stpoz.
**
**      IF sy-subrc = 0.
***Not required to handle as Component scrap in percent is optional
**      ENDIF.
**
**      SELECT matnr werks kausf
**             FROM marc INTO TABLE i_marc
**             FOR ALL ENTRIES IN i_reservations
**             WHERE matnr = i_reservations-matnr
**             AND   werks = i_reservations-werks.
**
**      IF sy-subrc = 0.
***Not required to handle as Component scrap in percent (plant level) is
***optional
**      ENDIF.
**
**      SELECT matnr bwkey stprs peinh
**             FROM mbew INTO TABLE i_mat_valuation
**             FOR ALL ENTRIES IN i_reservations
**             WHERE matnr = i_reservations-matnr
**             AND   bwkey = i_reservations-werks.
**
**      IF sy-subrc = 0.
***Not required to handle Standard Price and
** Price Unit are not mandatory
**      ENDIF.
***- Begin of MOD-001
**      SELECT stlty stlnr stlal bmein bmeng
**             INTO TABLE l_i_bom_header
**             FROM stko
**             FOR ALL ENTRIES IN i_pro_orders
**             WHERE stlty = i_pro_orders-stlty
**               AND stlnr = i_pro_orders-stlnr
**               AND stlal = i_pro_orders-stlal.
**
**      IF sy-subrc = 0.
*** There must be at least one record for process order.
**      ENDIF.
**
***- End of MOD-001
**
**      LOOP AT i_reservations INTO wa_reservations.
**        CLEAR: wa_order_status_text.
**        l_tabix = sy-tabix.
**
**        IF wa_reservations-xloek NE space.
**          READ TABLE i_order_status_text INTO wa_order_status_text
**          WITH KEY aufnr = wa_reservations-aufnr.
**          IF sy-subrc = 0
**            AND wa_order_status_text-sttxt NS c_teco.
**            DELETE i_issued_mat WHERE rsnum = wa_reservations-rsnum
**                                  AND rspos = wa_reservations-rspos
**                                  AND rsart = wa_reservations-rsart.
**            DELETE i_reservations INDEX l_tabix.
**            CONTINUE.
**          ENDIF.
**        ENDIF.
**
**        IF NOT ( rb_nflsh IS INITIAL )
**           AND wa_reservations-rgekz NE space.
**          DELETE i_issued_mat WHERE rsnum = wa_reservations-rsnum
**                                AND rspos = wa_reservations-rspos
**                                AND rsart = wa_reservations-rsart.
**          DELETE i_reservations INDEX l_tabix.
**          CONTINUE.
**        ENDIF.
**        wa_ordmats-aufnr = wa_reservations-aufnr.
**        wa_ordmats-matnr = wa_reservations-matnr.
**        wa_ordmats-vornr = wa_reservations-vornr.
**        wa_ordmats-rsnum = wa_reservations-rsnum.
**        wa_ordmats-rspos = wa_reservations-rspos.
**        wa_ordmats-rsart = wa_reservations-rsart.
**        wa_ordmats-bdmng = wa_reservations-bdmng.
**        wa_ordmats-meins = wa_reservations-meins.
**
**        READ TABLE i_issued_mat INTO wa_issued_mat
**        WITH KEY rsnum = wa_reservations-rsnum
**                 rspos = wa_reservations-rspos
**                 rsart = wa_reservations-rsart.
**        IF sy-subrc = 0.
**          wa_ordmats-menge = wa_ordmats-menge + wa_issued_mat-menge.
**          wa_ordmats-amein = wa_issued_mat-meins.
**        ELSE.
**          wa_ordmats-amein = wa_reservations-meins.
**        ENDIF.
***     Use the reservation quantity as the standard planned quantity
***     If material is by-product need to turn it into a negative number
.
**        IF wa_reservations-shkzg = c_s.
**          wa_ordmats-bdmng = wa_ordmats-bdmng * -1.
**        ENDIF.
**
**        READ TABLE i_pro_orders INTO wa_pro_orders
**        WITH KEY aufnr = wa_reservations-aufnr.
***************MOD-003*************************************
**        clear: l_qty.
***************MOD-003*************************************
**        IF rb_prod IS INITIAL.
**          l_qty = wa_pro_orders-lmnga.  "confirmed qty
****************MOD-003************************************
**        ELSEIF ( rb_prod is not initial ) and ( rb_actl is initial ).
**          l_qty = wa_pro_orders-gamng.
**        ELSEIF ( RB_PROD IS NOT INITIAL ) and
**               ( RB_ACTL is not initial ).
**          l_qty = wa_pro_orders-menge.  "goods receipt qty
**        ENDIF.
**
*** Calculate the standard quantity
********************MOD-003****************************
***      IF NOT rb_actl IS INITIAL.
********************MOD-003****************************
**
*********************mod-007*****************************
**        IF L_QTY IS INITIAL.
**          SELECT aufnr rueck gmnga lmnga gmein meinh
**                 meilr stokz rueck_mst
**           FROM afru INTO TABLE i_afru
**           FOR ALL ENTRIES IN i_pro_orders
**           WHERE rueck = i_pro_orders-rueck AND
**                 lmnga NE c_0.
**
**          READ TABLE i_pro_orders INTO wa_pro_orders
**            WITH KEY aufnr = wa_reservations-aufnr.
**          IF SY-SUBRC = 0.
**            READ table i_afvc into wa_afvc with key
**                  aufpl = wa_pro_orders-aufpl
**                  steus = 'YBN1'
**                  phflg = c_x binary search.
**            IF SY-SUBRC = 0.
**              READ TABLE I_AFVV into wa_afvv with key
**                     aufpl = wa_afvc-aufpl
**                     aplzl = wa_afvc-aplzl binary search.
**              if sy-subrc = 0.
**                SORT i_afru BY aufnr RUECK.
**                LOOP AT i_afru INTO wa_afru
**                  WHERE  AUFNR = WA_PRO_ORDERS-AUFNR AND
**                         RUECK = WA_AFVC-RUECK.
**                  IF sy-subrc = 0.
**                    l_QTY = l_QTY + wa_afru-lmnga.
**                  ENDIF.
**                ENDLOOP.
**                check wa_pro_orders-gamng ne 0.
**                clear: wa_ordmats-stdqy.
**                wa_ordmats-stdqy = ( l_qty / wa_pro_orders-gamng ) *
**                                                      wa_ordmats-bdmng
**
**              endif.
**            ENDIF.
**          ENDIF.
**********************************MOD-007*****************************
**        ELSE.
**          check wa_pro_orders-gamng ne 0.
**          clear: wa_ordmats-stdqy.
**          wa_ordmats-stdqy = ( l_qty / wa_pro_orders-gamng ) *
**                                                wa_ordmats-bdmng.
**        ENDIF.
********************MOD-006***********************
**
***        check wa_pro_orders-gamng ne 0.
***        clear: wa_ordmats-stdqy.
***        wa_ordmats-stdqy = ( l_qty / wa_pro_orders-gamng ) *
***                                        wa_ordmats-bdmng.
********************mod-006************************
***        ELSE.
*********MOD-002****************************************
****          check wa_pro_orders-menge ne 0.
****          wa_ordmats-stdqy = ( l_qty / wa_pro_orders-menge ) *
****                              wa_ordmats-bdmng.
***          check wa_pro_orders-gamng ne 0.
***          wa_ordmats-stdqy = ( l_qty / wa_pro_orders-gamng ) *
***                                          wa_ordmats-bdmng.
***      ENDIF.
********MOD-002*******************************************
**********************MOD-003*******************************
**
**
*** gets the zero loss figure from the bom
**
***- Begin of MOD-001
**
***        READ TABLE i_stpo INTO wa_stpo
***        WITH KEY stlty = wa_reservations-stlty
***                 stlnr = wa_reservations-stlnr
***                 stlkn = wa_reservations-stlkn
***                 stpoz = wa_reservations-stpoz.
***        IF sy-subrc = 0 AND NOT ( wa_stpo-ausch IS INITIAL ).
***          l_per = ( wa_stpo-ausch / c_100 ) * wa_ordmats-stdqy.
***        ELSE.
***          READ TABLE i_marc INTO wa_marc
***          WITH KEY matnr = wa_reservations-matnr
***                   werks = wa_reservations-werks.
***          IF sy-subrc = 0 AND NOT ( wa_marc-kausf IS INITIAL ).
***            l_per = ( wa_marc-kausf / c_100 ) * wa_ordmats-stdqy.
***          ELSE.
***            MOVE c_0 TO l_per.
***          ENDIF.
***        ENDIF.
**
***        wa_ordmats-zloss = wa_ordmats-stdqy - l_per.
**
**        CLEAR l_qty.
**        IF rb_actl IS INITIAL.
**          l_qty = wa_pro_orders-gamng.
**        ELSEIF rb_pland IS INITIAL.
**          l_qty = wa_pro_orders-menge.
**        ENDIF.
**
**        READ TABLE l_i_bom_header INTO l_wa_bom_header
**             WITH KEY stlty = wa_pro_orders-stlty
**                      stlnr = wa_pro_orders-stlnr
**                      stlal = wa_pro_orders-stlal.
**
**        IF sy-subrc IS INITIAL.
***************mod-002**************************************
**          IF L_WA_BOM_HEADER-BMEIN NE WA_PRO_ORDERS-GMEIN.
**            CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
**              EXPORTING
**                i_matnr              = wa_pro_orders-PLNBEZ
**                i_in_me              = wa_pro_orders-gmein
**                i_out_me             = l_wa_bom_header-bmein
**                i_menge              = l_qty
**              IMPORTING
**                e_menge              = v_menge
**              EXCEPTIONS
**                error_in_application = 1
**                error                = 2
**                OTHERS               = 3.
**            IF sy-subrc = 0.
**              l_qty = v_menge.
**            ENDIF.
**          ENDIF.
**
**
*************mod-002*****************************************
**          IF l_wa_bom_header-bmeng IS NOT INITIAL.
**
**            READ TABLE i_stpo INTO wa_stpo
**            WITH KEY stlty = wa_reservations-stlty
**                     stlnr = wa_reservations-stlnr
**                     stlkn = wa_reservations-stlkn
**                     stpoz = wa_reservations-stpoz.
**
**            l_per = wa_stpo-menge *
**                    ( l_qty / l_wa_bom_header-bmeng ).
**
**            wa_ordmats-zloss = l_per * wa_stpo-yyzero.
**
**          ENDIF.
**
**        ENDIF.
**
***- End of MOD-001
**        READ TABLE i_mat_valuation INTO wa_mat_valuation
**        WITH KEY matnr = wa_reservations-matnr
**                 bwkey = wa_reservations-werks.
**        IF sy-subrc = 0.
**          wa_ordmats-stprs = wa_mat_valuation-stprs.
**          wa_ordmats-peinh = wa_mat_valuation-peinh.
**        ENDIF.
**
*** Adding material number to I_MATERIAL_NO internal table
**        wa_material_no-matnr = wa_reservations-matnr.
**
**        APPEND: wa_ordmats TO i_ordmats,
**                wa_material_no TO i_material_no.
**        CLEAR:  wa_ordmats, l_qty, l_per, wa_stpo, wa_marc,
**                wa_issued_mat, wa_pro_orders, wa_mat_valuation,
**                wa_material_no, l_tabix, wa_reservations.
**
**      ENDLOOP.
*** Now we need to see if any of the materials issued to the order
*** are not on the BOM (ie replacement materials)
*** First summarise the data
**      SORT i_ordmats BY aufnr matnr rsnum.
**      LOOP AT i_issued_mat INTO wa_issued_mat.
**        READ TABLE i_ordmats INTO wa_ordmats
**         WITH KEY aufnr = wa_issued_mat-aufnr
**                  matnr = wa_issued_mat-matnr
**                  rsnum = wa_issued_mat-rsnum
**                  BINARY SEARCH.
**        IF sy-subrc GE 4.
*** material not on bom table so add it
**          CLEAR: wa_ordmats.
*** Get the standard price info for costing purposes in output
**          READ TABLE i_mat_valuation INTO wa_mat_valuation
**          WITH KEY matnr = wa_issued_mat-matnr
**                   bwkey = p_werks.
**          wa_issued_mat-stprs = wa_mat_valuation-stprs.
**          wa_issued_mat-peinh = wa_mat_valuation-peinh.
**          MODIFY i_issued_mat FROM wa_issued_mat.
**          wa_ordmats-stprs = wa_mat_valuation-stprs.
**          wa_ordmats-peinh = wa_mat_valuation-peinh.
**          MOVE: wa_issued_mat-aufnr TO wa_ordmats-aufnr,
**                wa_issued_mat-matnr TO wa_ordmats-matnr,
**                wa_issued_mat-menge TO wa_ordmats-menge,
**                wa_issued_mat-meins TO wa_ordmats-meins,
**                wa_issued_mat-meins TO wa_ordmats-amein.
**          COLLECT wa_ordmats INTO i_ordmats.
**
**        ELSE.
*** material is on bom table so delete from sum_msegi
**          DELETE i_issued_mat. " FROM wa_issued_mat.
**        ENDIF.
**        CLEAR : wa_issued_mat.
**      ENDLOOP.
**
**      CLEAR wa_issued_mat.
**
*** Retrieve task list information of operations/activity
**  from PLPO table
**      SELECT * FROM plpo INTO TABLE i_plpo
**            FOR ALL ENTRIES IN i_pro_orders
**            WHERE plnty = i_pro_orders-plnty
**            AND   plnnr = i_pro_orders-plnnr
**            AND   plnkn = i_pro_orders-plnkn
**            AND   zaehl = i_pro_orders-zaehl.
**
**      IF sy-subrc = 0.
***Not required to handle
***Task list - operation/activity information is optional
**      ENDIF.
**
**      SELECT rueck rmzhl ism01 ism02 ism03 ism04 ism05 ism06 stokz
**             FROM afru INTO TABLE i_ord_conf
**             FOR ALL ENTRIES IN i_pro_orders
**             WHERE rueck = i_pro_orders-rueck.
**
**
**      IF sy-subrc = 0.
***Not required to handle
***Order Confirmations information is not mandatiory
**      ENDIF.
**    ENDIF.
**
**    IF NOT i_ordops[] IS INITIAL.
**
**      SELECT * FROM plpo INTO TABLE i_plpo1
**            FOR ALL ENTRIES IN i_ordops
**            WHERE plnty = i_ordops-plnty
**            AND   plnnr = i_ordops-plnnr
**            AND   plnkn = i_ordops-plnkn
**            AND   zaehl = i_ordops-zaehl.
**
**      IF sy-subrc = 0.
***Not required to handle
***operations information is optional.
**      ENDIF.
**
**      SELECT rueck rmzhl ism01 ism02 ism03 ism04 ism05 ism06 stokz
**             FROM afru INTO TABLE i_ord_conf1
**             FOR ALL ENTRIES IN i_ordops
**             WHERE rueck = i_ordops-rueck.
**
**      IF sy-subrc = 0.
***Not required to handle
***Order Confirmations information is not mandatiory
**      ENDIF.
**
**    ENDIF.
**  ENDIF.
**ENDFORM.                    " get_bom_info
**
***&--------------------------------------------------------------------
***
***&      Form  output
***&--------------------------------------------------------------------
***
***       text
***---------------------------------------------------------------------
***
***---------------------------------------------------------------------
***
**FORM output.
**
**  MOVE 'Formatting Output'(027) TO v_output_text.
**  PERFORM inform_user_of_progress.
**
*** Selecting material descriptions
**  SELECT matnr maktx
**         FROM makt INTO TABLE i_material_des
**         FOR ALL ENTRIES IN i_material_no
**         WHERE spras = sy-langu
**         AND   matnr = i_material_no-matnr.
**
**  IF sy-subrc = 0.
***Not required to handle
***Material desc is optinal
**  ENDIF.
**
**
*** Selecting Work centers descriptions
**  SELECT objid ktext
**         FROM crtx INTO TABLE i_wc_text
**         FOR ALL ENTRIES IN i_pro_orders
**         WHERE objty = c_objtyp
**         AND   objid = i_pro_orders-arbid
**         AND   spras = sy-langu.
**
**  IF sy-subrc = 0.
***Not required to handle
***Work centers descriptions are optional
**  ENDIF.
**
**  CASE c_x.
**    WHEN rb_detl.
**      PERFORM display_detail_report.
**    WHEN rb_summ.
**      PERFORM display_summary_report.
**    WHEN rb_phase.
**      PERFORM display_phase_report.
**  ENDCASE.
**
**
**ENDFORM.                    " output
**
***&--------------------------------------------------------------------
**
***&      Form  move_data2_ordops
***&--------------------------------------------------------------------
***
***       text
***---------------------------------------------------------------------
***
***---------------------------------------------------------------------
***
**FORM move_data2_ordops.
**
**  READ TABLE i_afvv INTO wa_afvv WITH KEY aufpl = wa_afvc-aufpl
**                               aplzl = wa_afvc-aplzl BINARY SEARCH.
**  READ TABLE i_orders INTO wa_orders WITH KEY aufpl = wa_afvc-aufpl.
**  " BINRAY SEARCH.
**  IF sy-subrc = 0.
*******************
**
**READ TABLE i_ordops INTO wa_ordops WITH KEY aufnr = wa_orders-aufnr.
*******************
**    IF sy-subrc <> 0.
**      MOVE-CORRESPONDING wa_orders TO wa_pro_orders.
**      wa_pro_orders-wdate = wa_afvv-ssavd.
**      wa_pro_orders-zaehl = wa_afvc-zaehl.
**      wa_pro_orders-arbpl = wa_crhd-arbpl.
**      wa_pro_orders-arbid = wa_afvc-arbid.
**      wa_pro_orders-plnnr = wa_afvc-plnnr.
**      wa_pro_orders-plnkn = wa_afvc-plnkn.
*********MOD-002*****************************
***     wa_pro_orders-rueck = wa_afvc-rueck.
********MOD-002*******************************
**      IF wa_pro_orders-rueck IS INITIAL.
**        wa_pro_orders-rueck = wa_afvc-rueck.
**      ENDIF.
**
**      wa_material_no-matnr = wa_orders-plnbez.
**
**      APPEND: wa_pro_orders TO i_pro_orders,
**              wa_material_no TO i_material_no.
**      CLEAR:  wa_pro_orders, wa_material_no.
**    ENDIF.
**
**    wa_ordops-aufnr = wa_orders-aufnr.
**    wa_ordops-aufpl = wa_afvc-aufpl.
**    wa_ordops-aplzl = wa_afvc-aplzl.
**    wa_ordops-plnty = wa_afvc-plnty.
**    wa_ordops-plnkn = wa_afvc-plnkn.
**    wa_ordops-plnnr = wa_afvc-plnnr.
**    wa_ordops-zaehl = wa_afvc-zaehl.
**    wa_ordops-vornr = wa_afvc-vornr.
**    wa_ordops-arbid = wa_afvc-arbid.
**    wa_ordops-rueck = wa_afvc-rueck.
**    wa_ordops-ssavd = wa_afvv-ssavd.
**    wa_ordops-arbpl = wa_crhd-arbpl.
**
**    APPEND wa_ordops TO i_ordops.
**    CLEAR  wa_ordops.
**  ENDIF.
**  CLEAR: wa_afvv, wa_orders.
**
**ENDFORM.                    " move_data2_ordops
***&--------------------------------------------------------------------
***
***&      Form  DISPLAY_DETAIL_REPORT
***&--------------------------------------------------------------------
***
***       text
***---------------------------------------------------------------------
***
***---------------------------------------------------------------------
**
**FORM display_detail_report.
**
**  DATA: l_date_low(10)  TYPE c,
**        l_date_high(10) TYPE c,
**        l_diff          TYPE menge_d,
**        l_plan_effic    TYPE char05,                        "MOD-001++
**        l_plant_effic   TYPE char05,                        "MOD-001++
**        l_gamng         TYPE menge_d,
**        l_gamng1(20)    TYPE c,
**        l_qty    TYPE menge_d,
**        l_prdqty TYPE menge_d,
**        l_conv   TYPE menge_d,
**        l_aqty   TYPE menge_d,
**        l_sqty   TYPE menge_d,
**        l_gmein  TYPE meins,
**
**        l_pcent(3)  TYPE p DECIMALS 2,
**        l_cost(8)   TYPE p DECIMALS 2,
**
**        l_act_total(8) TYPE p DECIMALS 2,
**        l_std_total(8) TYPE p DECIMALS 2,
**        l_var_total(8) TYPE p DECIMALS 2,
**
**        l_act_gtot(8)  TYPE p DECIMALS 2,
**        l_std_gtot(8)  TYPE p DECIMALS 2,
**        l_var_gtot(8)  TYPE p DECIMALS 2,
**
**        l_fromuom TYPE meins.
***- Begin of MOD-001
**  DATA: l_value TYPE char16,
**        l_tmp TYPE lmnga,
**        l_tmp1 TYPE lmnga,
**        l_effic TYPE p DECIMALS 1,
**        l_uom   TYPE char03.
***- End of MOD-001
**
**  PERFORM pfstatus.
**  SET PF-STATUS 'MAIN' EXCLUDING i_fcode.
**  SET TITLEBAR 'VARI' WITH text-066.
**  MOVE 'Display Detail Report'(028) TO v_output_text.
**  PERFORM inform_user_of_progress.
**
*** Clearing local variables
**  CLEAR: l_cost, l_pcent, l_qty, l_conv, l_aqty, l_sqty,
**         l_diff, l_plan_effic, l_gamng, l_date_low,l_date_high,
**         l_act_gtot, l_std_gtot, l_var_gtot.
**  CLEAR wa_nodestab.
**  REFRESH i_nodestab.
**
*****Begin of MOD-001
**  IF sy-ucomm = c_zero OR rb_zloss IS NOT INITIAL.
**
**    v_ucomm = c_zero.
**
**  ELSEIF sy-ucomm = c_std OR rb_stdpl IS NOT INITIAL.
**
**    CLEAR : v_ucomm.
**
**  ENDIF.
**
**  IF sy-ucomm = c_fisc.
**
**    v_ucomm1 = c_fisc.
**
**  ELSEIF sy-ucomm = c_qty.
**
**    v_ucomm1 = c_qty.
**
**  ENDIF.
*****End of MOD-001
**
**  wa_nodestab-id = c_1_1.
**  wa_nodestab-tlevel = c_1.
**  wa_nodestab-text = 'Production Variances'(031).
**  wa_nodestab-tlength = c_20.
**  wa_nodestab-compress = c_x.
**  APPEND wa_nodestab TO i_nodestab.
**
**  LOOP AT i_pro_orders INTO wa_pro_orders.
**
**    CLEAR: wa_nodestab, l_date_low, l_date_high, l_gamng,
**           wa_material_des.
**
**    l_gamng = wa_pro_orders-gamng.
**************MOD-002************************
**    l_gmein = wa_pro_orders-gmein.
**************MOD-002***********************
**    wa_nodestab-id = c_2_1.
**    wa_nodestab-tlevel = c_2.
**    wa_nodestab-parent = c_1_1.
**
*** Order Number text
**    wa_nodestab-text = 'Order Num:'(032).
**    wa_nodestab-tlength = c_12.
**    wa_nodestab-tcolor = c_1.
*** Order number
**    WRITE wa_pro_orders-aufnr TO wa_nodestab-text1 NO-ZERO.
**    wa_nodestab-tlength1 = c_12.
**    wa_nodestab-tcolor1 = c_1.
**
*** Date Range
**    WRITE wa_pro_orders-wdate TO l_date_low.
**    WRITE wa_pro_orders-gltrp TO l_date_high.
**    CONCATENATE l_date_low c_hyp l_date_high
**    INTO wa_nodestab-text2 SEPARATED BY space.
**    wa_nodestab-tlength2 = c_25.
**    wa_nodestab-tcolor2 = c_1.
**
*** Material Number
**    WRITE wa_pro_orders-plnbez TO wa_nodestab-text3 NO-ZERO.
**    wa_nodestab-tlength3 = c_18.
**    wa_nodestab-tcolor3 = c_1.
**
*** Material Description
**    READ TABLE i_material_des INTO wa_material_des
**                WITH KEY matnr = wa_pro_orders-plnbez.
**    wa_nodestab-text4 = wa_material_des-maktx.
**    wa_nodestab-tlength4 = c_33.
**    wa_nodestab-tcolor4 = c_1.
**
*** Get actual produced Quantity or Confirm Quantity
**    IF NOT ( rb_prod IS INITIAL ).
**      l_prdqty  = wa_pro_orders-menge.
**      l_fromuom = wa_pro_orders-gruom.
**    ELSE.
***********MOD-002***************************************
**      LOOP AT i_plpo1 INTO wa_plpo1
**                WHERE plnty = wa_pro_orders-plnty
**                AND plnnr = wa_pro_orders-plnnr
**                AND steus = 'YBN1'.
**        IF wa_plpo1-vgw02 IS NOT INITIAL.
*************MOD-005****************************
***          wa_plpo2 = wa_plpo1.
***          append wa_plpo2 to i_plpo2.
***        ENDIF.
***      ENDLOOP.
*************mod-005***************************
**          CLEAR: wa_afvc, wa_afvv.
**          READ TABLE i_afvc INTO wa_afvc
**               WITH KEY plnty = wa_plpo1-plnty
**                        plnnr = wa_plpo1-plnnr
**                        plnkn = wa_plpo1-plnkn
**                        zaehl = wa_plpo1-zaehl
**                        aufpl = wa_pro_orders-aufpl.
**
**
**          IF sy-subrc IS INITIAL.
**            READ TABLE i_afvv INTO wa_afvv
**                 WITH KEY aufpl = wa_afvc-aufpl
**                          aplzl = wa_afvc-aplzl.
**
***      READ table i_afvc into wa_afvc with key
***            aufpl = wa_pro_orders-aufpl binary search.
***      if sy-subrc = 0.
***        READ TABLE I_AFVV into wa_afvv with key
***             aufpl = wa_afvc-aufpl
***             aplzl = wa_afvc-aplzl binary search.
**            IF sy-subrc = 0.
**              l_prdqty  = wa_afvv-lmnga.
*********************MOD-006**********************
**              IF wa_pro_orders-cfuom IS INITIAL.
**                SELECT aufnr rueck gmnga lmnga gmein meinh
**                        meilr stokz rueck_mst
**                FROM afru INTO TABLE i_afru
**                WHERE rueck = wa_afvc-rueck AND
**                      aufnr = wa_pro_orders-aufnr.
**                IF NOT i_afru[] IS INITIAL.
**                  READ TABLE i_afru INTO wa_afru INDEX 1.
**                  IF sy-subrc = 0.
**                    l_fromuom = wa_afru-gmein.
**                  ENDIF.
**                ENDIF.
**              ELSE.
**                l_fromuom = wa_pro_orders-cfuom.
**              ENDIF.
********************MOD-006***********************
**            ENDIF.
**          ENDIF.
***********MOD-002***************************************
***      l_prdqty  = wa_pro_orders-lmnga.
***      l_fromuom = wa_pro_orders-cfuom.
**        ENDIF.
**      ENDLOOP.
**    ENDIF.
**
*************mod-003**********************
**    IF NOT rb_pland IS INITIAL.
**      IF rb_conf IS INITIAL.
**        l_prdqty  = wa_pro_orders-gamng.
**      ELSE.
**        l_prdqty = wa_afvv-lmnga.
**      ENDIF.
**    ENDIF.
************mod-003***********************
**    IF rb_kgm = c_x.
*** do actual conversion
**      PERFORM uom_convert USING wa_pro_orders-plnbez
**                                l_prdqty
**                                l_fromuom
**                                l_conv.
**      l_prdqty = l_conv.
*** do planned conversion
**********MOD-002*************************
***     l_fromuom = wa_pro_orders-gmein.
**      l_fromuom = 'KG'.
**
**      PERFORM uom_convert USING wa_pro_orders-plnbez
**                                wa_pro_orders-gamng
**                                l_fromuom
**                                l_conv.
**
**      l_gamng = l_conv.
**    ENDIF.
**
*** Produced Quantity / Confirmed Quantity
**    MOVE l_prdqty TO wa_nodestab-text5(20).
**    MOVE l_fromuom TO l_uom.                                "MOD-001++
***    WRITE l_prdqty TO i_nodestab-text5(20).
**
**    IF NOT ( rb_prod IS INITIAL ).
***      CONCATENATE 'Prod Qty: '(033) wa_nodestab-text5 "MOD-001-
**      CONCATENATE 'Prod Qty: '(033) wa_nodestab-text5 l_uom "MOD-001+
**        INTO wa_nodestab-text5 SEPARATED BY space.
**
**    ELSE.
***      CONCATENATE 'Conf Qty: '(034) wa_nodestab-text5 "MOD-001-
**      CONCATENATE 'Conf Qty: '(034) wa_nodestab-text5 l_uom "MOD-001+
**       INTO wa_nodestab-text5 SEPARATED BY space.
**    ENDIF.
**
**
***    wa_nodestab-tlength5 = c_30.  "MOD-001-
**    wa_nodestab-tlength5 = c_35_1.                          "MOD-001+
**    wa_nodestab-tcolor5  = c_1.
**
**    APPEND wa_nodestab TO i_nodestab.
**
*** Resource Information
**    CLEAR  wa_nodestab.
**    wa_nodestab-id     = c_2_2.
**    wa_nodestab-tlevel = c_3.
**    wa_nodestab-parent = c_1_1.
**
**    CONCATENATE 'Resource:'(035) wa_pro_orders-arbpl
**    INTO wa_nodestab-text SEPARATED BY space.
**    wa_nodestab-tlength = c_25.
**    wa_nodestab-tcolor  = c_4.
**
**    READ TABLE i_wc_text INTO wa_wc_text
**             WITH KEY objid = wa_pro_orders-arbid.
**    wa_nodestab-text1 = wa_wc_text-ktext.
**    wa_nodestab-tlength1 = c_37.
**    wa_nodestab-tcolor1  = c_4.
**
*** Calculating Plan Effic value
***- Begin of MOD-001
***    IF l_gamng GT 0.
***      l_diff = l_gamng - l_prdqty.
***      l_plan_effic = c_100 - c_100 * ( l_diff / l_gamng ).
***    ELSE.
***      CLEAR l_plan_effic.
***    ENDIF.
**
***** Mod-002*********************
**    CLEAR: wa_plpo1.
******mOD-002*********************
**    LOOP AT i_plpo1 INTO wa_plpo1
**            WHERE plnty = wa_pro_orders-plnty
**              AND plnnr = wa_pro_orders-plnnr
**              AND steus = 'YBN1'.
**      IF wa_plpo1-vgw02 IS NOT INITIAL.
**        MOVE wa_plpo1-usr04 TO l_effic. "L_VALUE.
**        WRITE l_effic TO l_plan_effic.
**        wa_plpo2 = wa_plpo1.
**        APPEND wa_plpo2 TO i_plpo2.
**
***       L_PLAN_EFFIC = floor( L_VALUE )
***************MOD-002**************************
***      ELSE.
***        CLEAR l_plan_effic.
**      ENDIF.
**************MOD-002***************************
**    ENDLOOP.
**
**
***    CONCATENATE 'Plan Effic:'(036) l_plan_effic c_perc "'%'
**    CONCATENATE 'Exp. Line Eff.'(036) l_plan_effic c_perc "'%'
**    INTO wa_nodestab-text2 SEPARATED BY space.
**    wa_nodestab-tlength2 = c_25.
**    wa_nodestab-tcolor2  = c_4.
**
**    CLEAR l_effic.
**** Mod-002***************
**
**
***    READ TABLE i_afvc INTO wa_afvc
***         WITH KEY plnty = wa_plpo1-plnty
***                  plnnr = wa_plpo1-plnnr
***                  zaehl = wa_plpo1-zaehl.
**
****************MOD-008***********************
***    LOOP AT I_ORDOPS INTO WA_ORDOPS.
***      READ TABLE I_PRO_ORDERS INTO WA_PRO_ORDERS WITH KEY
***                                    AUFNR = WA_ORDOPS-AUFNR
***                                              BINARY SEARCH.
***      IF SY-SUBRC = 0.
***        READ table i_afvc1 into wa_afvc1 with key
***                      plnty = wa_ORDOPS-plnty
***                      plnnr = wa_ORDOPS-plnnr
***                      plnkn = wa_ORDOPS-plnkn
***                      zaehl = wa_ORDOPS-zaehl
***                      aufpl = wa_pro_orders-aufpl.
***        IF SY-SUBRC = 0.
***          READ TABLE I_AFVV1 into wa_afvv1 with key
***                 aufpl = wa_afvc1-aufpl
***                 aplzl = wa_afvc1-aplzl binary search.
***          IF SY-SUBRC = 0.
***            CHECK WA_AFVV1-VGW02 NE 0.
***            l_tmp = wa_afvv1-bmsch * wa_afvv1-ism02.
***            IF l_tmp IS NOT INITIAL.
***
***              l_tmp1 = ( wa_afvv1-lmnga * wa_afvv1-vgw02 ) / l_tmp.
***
***              l_tmp1 = l_tmp1 * 100.
***
***              MOVE l_tmp1 TO l_effic.
***
***            ENDIF.
***          ENDIF.
***        ENDIF.
***      ENDIF.
***    ENDLOOP.
**
***************MOD-008************************
**    CLEAR: wa_afvc, wa_afvv.
**    LOOP AT i_plpo2 INTO wa_plpo2.
**      READ TABLE i_afvc INTO wa_afvc
**           WITH KEY plnty = wa_plpo2-plnty
**                    plnnr = wa_plpo2-plnnr
**                    plnkn = wa_plpo2-plnkn
**                    zaehl = wa_plpo2-zaehl
**                    aufpl = wa_pro_orders-aufpl.
**
**      IF sy-subrc IS INITIAL.
**        READ TABLE i_afvv INTO wa_afvv
**             WITH KEY aufpl = wa_afvc-aufpl
**                      aplzl = wa_afvc-aplzl.
**
**        l_tmp = wa_afvv-bmsch * wa_afvv-ism02.
**        IF l_tmp IS NOT INITIAL.
**
**          l_tmp1 = ( wa_afvv-lmnga * wa_afvv-vgw02 ) / l_tmp.
**
**          l_tmp1 = l_tmp1 * 100.
**
**          MOVE l_tmp1 TO l_effic.
**
**        ENDIF.
**      ENDIF.
**    ENDLOOP.
**
**    WRITE l_effic TO l_plant_effic.
**
***    CLEAR v_plant_effic.
***    PERFORM plant_effic USING wa_pro_orders-plnty
***                            wa_pro_orders-plnnr
***                            wa_pro_orders-plnkn
***                            wa_pro_orders-zaehl
***                      CHANGING v_plant_effic.
**
***    CONCATENATE 'Plant Effic:'(037) v_plant_effic c_perc "'%'
**    CONCATENATE 'Act. Line Eff.'(037) l_plant_effic c_perc "'%'
**                                                            " MOD-001+
**    INTO wa_nodestab-text3 SEPARATED BY space.
**    wa_nodestab-tlength3 = c_25.
**    wa_nodestab-tcolor3  = c_4.
***- End of MOD-001
**
**    APPEND wa_nodestab TO i_nodestab.
**
*** Phase Information
**    CLEAR  wa_nodestab.
**    wa_nodestab-id     = c_3_3.
**    wa_nodestab-tlevel =  c_3.
**    wa_nodestab-parent = c_1_1.
**
**    wa_nodestab-text = 'Phase'(038).
**    wa_nodestab-tlength = c_10.
**    wa_nodestab-tcolor  = c_4.
**
**    MOVE l_gamng TO l_gamng1.
**    CONCATENATE 'Activity (Std Plan:'(039) l_gamng1 c_brac " ')'
**    INTO wa_nodestab-text1 SEPARATED BY space.
**    wa_nodestab-tlength1 = c_42.
**    wa_nodestab-tcolor1  = c_4.
**
**    IF rb_fiscl = c_x.
**      CONCATENATE 'Actual Usage'(040) v_waers
**      INTO wa_nodestab-text2 SEPARATED BY space.
**    ELSE.
**      wa_nodestab-text2 = 'Actual Usage'(040).
**    ENDIF.
**    wa_nodestab-tlength2 = c_20.
**    wa_nodestab-tcolor2  = c_4.
**
**    IF rb_fiscl = c_x.
**      CONCATENATE 'Standard Usage'(041) v_waers
**      INTO wa_nodestab-text3 SEPARATED BY space.
**    ELSE.
**      wa_nodestab-text3 = 'Standard Usage'(041).
**    ENDIF.
**    wa_nodestab-tlength3 = c_20.
**    wa_nodestab-tcolor3  = c_4.
**
**    IF rb_fiscl = c_x.
**      CONCATENATE 'Activity Variance'(042) v_waers
**      INTO wa_nodestab-text4 SEPARATED BY space.
**    ELSE.
**      wa_nodestab-text4 = 'Activity Variance'(042).
**    ENDIF.
**    wa_nodestab-tlength4 = c_35.
**    wa_nodestab-tcolor4  = c_4.
**
**    APPEND wa_nodestab TO i_nodestab.
**
*** Display acitivity report
**    CLEAR flg_color.
**    LOOP AT i_ordops INTO wa_ordops
**             WHERE aufnr = wa_pro_orders-aufnr.
**      IF flg_color IS INITIAL.
**        flg_color = c_x.
**      ELSE.
**        CLEAR flg_color.
**      ENDIF.
**      PERFORM activity_report USING l_prdqty l_gamng l_uom l_gmein.
**    ENDLOOP.
**
*** Material Information
**    CLEAR  wa_nodestab.
**    wa_nodestab-id     = c_3_4.
**    wa_nodestab-tlevel =  c_3.
**    wa_nodestab-parent = c_1_1.
**
**    PERFORM material_header.
**
**    CLEAR: l_act_total, l_std_total, l_var_total.
*** Individual material details
**    LOOP AT i_ordmats INTO wa_ordmats
**              WHERE aufnr = wa_pro_orders-aufnr.
**
******************mod-003************************
**      CLEAR: l_aqty, l_sqty, l_qty.
*****************mod-003*************************
**
**      CLEAR: wa_nodestab.
**      wa_nodestab-id     = c_4_1.
**      wa_nodestab-tlevel =  c_4.
**      wa_nodestab-parent = c_3_2.
**
*** Material Number
**      WRITE wa_ordmats-matnr TO wa_nodestab-text NO-ZERO.
**      wa_nodestab-tlength = c_18.
**      wa_nodestab-tcolor  = c_3.
**
*** Material Description
**      CLEAR wa_material_des.
**      READ TABLE i_material_des INTO wa_material_des
**           WITH KEY matnr = wa_ordmats-matnr.
**      wa_nodestab-text1 = wa_material_des-maktx.
**      wa_nodestab-tlength1 = c_30.
**      wa_nodestab-tcolor1  = c_3.
**
*** Standard planned or zero loss planned
**
**      IF rb_zloss IS INITIAL.
**        l_qty = wa_ordmats-stdqy.
****************MOD-004***********************
**
**************MOD-004************************
**      ELSE.
**        l_qty = wa_ordmats-zloss.
**      ENDIF.
**
*** Order uom or kgm
**      IF rb_kgm IS INITIAL.
**        l_aqty = wa_ordmats-menge.
**        l_sqty = l_qty.
**      ELSE.
*** do actual conversion
**        PERFORM uom_convert USING wa_ordmats-matnr
**                                  wa_ordmats-menge
**                                  wa_ordmats-amein
**                                  l_aqty.
*** do std/zloss conversion
**        PERFORM uom_convert USING wa_ordmats-matnr
**                                  wa_ordmats-stdqy
**                                  wa_ordmats-meins
**                                  l_sqty.
**      ENDIF.
********************MOD-003**********************************
**      IF wa_ordmats-meins = 'EA' OR
**        wa_ordmats-meins = 'CS'.
**        l_sqty = CEIL( l_sqty ).
**      ENDIF.
********************MOD-003**********************************
**
**      PERFORM std_percentage_calc USING l_aqty l_sqty l_pcent.
**
*** Fiscal or quantity
**      IF rb_fiscl IS INITIAL.
**        MOVE l_aqty TO wa_nodestab-text2(20). " Actual Usage
**        wa_nodestab-tlength2 = c_20.
**        wa_nodestab-tcolor2  = c_3.
**        MOVE l_sqty TO wa_nodestab-text3(20). " Standard Usage
**        wa_nodestab-tlength3 = c_20.
**        wa_nodestab-tcolor3  = c_3.
**
**      ELSE.
**        IF NOT wa_ordmats-peinh IS INITIAL.
**          CLEAR l_cost.
**          l_cost = ( wa_ordmats-stprs * wa_ordmats-menge )
**                                     / wa_ordmats-peinh.
**          MOVE l_cost TO wa_nodestab-text2(20). " Acutal Usage
**          wa_nodestab-tlength2 = c_20.
**          wa_nodestab-tcolor2  = c_3.
**
**          l_act_total = l_act_total + l_cost. " Subtotal of actual
**          l_act_gtot  = l_act_gtot  + l_cost. " Grand total
**
**        ENDIF.
**        IF NOT wa_ordmats-peinh IS INITIAL.
**          CLEAR l_cost.
*****Begin of MOD-001
**          IF v_ucomm = c_zero.
****************************MOD-003*******************************
**            IF wa_ordmats-meins = 'EA' OR
**               wa_ordmats-meins = 'CS'.
**              l_qty = CEIL( l_qty ).
**            ENDIF.
****************************MOD-003*******************************
**            l_cost = ( wa_ordmats-stprs * l_qty ) "wa_ordmats-stdqy )
**                                      / wa_ordmats-peinh.
**
**
**          ELSE.
****************************MOD-003*******************************
**            IF wa_ordmats-meins = 'EA' OR
**               wa_ordmats-meins = 'CS'.
**              wa_ordmats-stdqy = CEIL( wa_ordmats-stdqy ).
**            ENDIF.
****************************MOD-003*******************************
**
**            l_cost = ( wa_ordmats-stprs * wa_ordmats-stdqy )
**                                      / wa_ordmats-peinh.
**
**
**          ENDIF.
*****End of MOD-001
**
**          MOVE l_cost TO wa_nodestab-text3(20). " Standard Usage
**          wa_nodestab-tlength3 = c_20.
**          wa_nodestab-tcolor3 = c_3.
**
**          l_std_total = l_std_total + l_cost. " Subtotal of standard
**          l_std_gtot  = l_std_gtot  + l_cost. " Grand Total
**
**        ENDIF.
**      ENDIF.
**
**      MOVE l_pcent TO wa_nodestab-text4(17). " Variance Percentage
**      CONCATENATE wa_nodestab-text4(17) c_perc "'%'
**      INTO wa_nodestab-text4(19) SEPARATED BY space.
**      wa_nodestab-tlength4 = c_19.
**      wa_nodestab-tcolor4  = c_3.
**      CLEAR: l_diff, l_cost.
**
*******Begin of MOD-001
**      IF ( v_ucomm = c_zero ).
**
**        l_diff = wa_ordmats-menge - l_qty.
**
**      ELSE.
**
**        l_diff = wa_ordmats-menge - wa_ordmats-stdqy.
**
**      ENDIF.
*******End of MOD-001
**
**      IF NOT wa_ordmats-peinh IS INITIAL.
**        l_cost = ( wa_ordmats-stprs * l_diff ) / wa_ordmats-peinh.
**        l_cost = l_cost * -1.
**      ENDIF.
**
*******Begin of MOD-001
***      IF v_ucomm1 = c_qty.
***
***        MOVE l_diff TO wa_nodestab-text5(15). " Variance
***
***      ELSE.
**
**      MOVE l_cost TO wa_nodestab-text5(15). " Variance
**
***      ENDIF.
********End of MOD-001
**
**      wa_nodestab-tlength5 = c_15.
**      wa_nodestab-tcolor5  = c_3.
**
**      l_var_total = l_var_total + l_cost. " Subtotal of Variance
**      l_var_gtot  = l_var_gtot  + l_cost. " Grand total
**
**      APPEND wa_nodestab TO i_nodestab.
*****************MOD-003*********************
**      CLEAR: wa_ordmats.
****************mod-003**********************
**
**    ENDLOOP.
**
*** Displaying Subtotals
**
**    CLEAR  wa_nodestab.
**    wa_nodestab-id     = c_4_1.
**    wa_nodestab-tlevel =  c_4.
**    wa_nodestab-parent = c_3_2.
**
**    wa_nodestab-text    = 'Material Totals'(043).
**    wa_nodestab-tlength =  c_18.
**    wa_nodestab-tcolor  =  c_6.
**
**    wa_nodestab-text1 = space.
**    wa_nodestab-tlength1 = c_30.
**    wa_nodestab-tcolor1  = c_6.
**
**    MOVE l_act_total TO wa_nodestab-text2(20) .
**    wa_nodestab-tlength2 = c_20.
**    wa_nodestab-tcolor2  = c_6.
**
**    MOVE l_std_total TO wa_nodestab-text3(20) .
**    wa_nodestab-tlength3 = c_20.
**    wa_nodestab-tcolor3  = c_6.
**
**    wa_nodestab-text4 = space.
**    wa_nodestab-tlength4 = c_19.
**    wa_nodestab-tcolor4  = c_6.
**
**    MOVE l_var_total TO wa_nodestab-text5(15) .
**    wa_nodestab-tlength5 = c_15.
**    wa_nodestab-tcolor5  = c_6.
**
**    APPEND wa_nodestab TO i_nodestab.
**    CLEAR : wa_pro_orders, wa_nodestab.
**
**  ENDLOOP.
**
*** Displaying Grand total
**  CLEAR wa_nodestab.
**  wa_nodestab-id     = c_2_1.
**  wa_nodestab-tlevel =  c_2.
**  wa_nodestab-parent = c_1_1.
**
**  wa_nodestab-text = 'Process Order Totals'(044).
**  wa_nodestab-tlength = c_26.
**  wa_nodestab-tcolor  = c_5.
**
**  wa_nodestab-text1    = space.
**  wa_nodestab-tlength1 = c_30.
**  wa_nodestab-tcolor1  = c_5.
**
**  MOVE l_act_gtot TO wa_nodestab-text2(20) .
**  wa_nodestab-tlength2 = c_20.
**  wa_nodestab-tcolor2  = c_5.
**
**  MOVE l_std_gtot TO wa_nodestab-text3(20) .
**  wa_nodestab-tlength3 = c_20.
**  wa_nodestab-tcolor3  = c_5.
**
**  wa_nodestab-text4 = space.
**  wa_nodestab-tlength4 = c_19.
**  wa_nodestab-tcolor4  = c_5.
**
**  MOVE l_var_gtot TO wa_nodestab-text5(15) .
**  wa_nodestab-tlength5 = c_15.
**  wa_nodestab-tcolor5  = c_5 .
**
**  APPEND wa_nodestab TO i_nodestab.
**
**  CLEAR : wa_nodestab.
**
**ENDFORM.                    " DISPLAY_DETAIL_REPORT
***&--------------------------------------------------------------------
***
***&      Form  DISPLAY_SUMMARY_REPORT
***&--------------------------------------------------------------------
***
***       text
***---------------------------------------------------------------------
***
***---------------------------------------------------------------------
***
**FORM display_summary_report.
**  DATA: l_diff          TYPE menge_d,
**        l_gamng         TYPE menge_d,
**        l_gmein         TYPE meins,
**
**        l_ltext         TYPE ktext,
**
**        l_tot_orders    TYPE i,
**
**        l_effic              TYPE p DECIMALS 1,             "
**  MOD-001++
**        l_effic1             TYPE p DECIMALS 1,             "
**  MOD-001++
**        l_plan_effic         TYPE char05,                   "
**  MOD-001++
**        l_plant_effic        TYPE char05,                   "
**  MOD-001++
**        l_sum_plan_effic TYPE p DECIMALS 1,
**        l_sum_plant_effic TYPE p DECIMALS 1,
**
**        l_qty    TYPE menge_d,
**        l_conv   TYPE menge_d,
**        l_aqty   TYPE menge_d,
**        l_sqty   TYPE menge_d,
**
**        l_prdqty     TYPE menge_d,
**        l_sum_prdqty TYPE menge_d,
**
**        l_pcent(3)  TYPE p DECIMALS 2,
**        l_cost(8)   TYPE p DECIMALS 2,
**
**        l_act_total(8) TYPE p DECIMALS 2,
**        l_std_total(8) TYPE p DECIMALS 2,
**        l_var_total(8) TYPE p DECIMALS 2,
**
**        l_fromuom TYPE meins.
**
***- Begin of MOD-001
**  DATA: l_value TYPE char16,
**        l_tmp TYPE lmnga,
**        l_tmp1 TYPE lmnga.
***- End of MOD-001
**
**  PERFORM pfstatus.
**  SET PF-STATUS 'MAIN' EXCLUDING i_fcode.
**  SET TITLEBAR 'VARI' WITH text-067.
**
**  CLEAR wa_nodestab.
**  REFRESH i_nodestab.
**
**  MOVE 'Display summary Report'(029) TO v_output_text.
**  PERFORM inform_user_of_progress.
**
**  CLEAR wa_nodestab.
**  wa_nodestab-id     = c_1.
**  wa_nodestab-tlevel = c_1.
**  wa_nodestab-text = 'Production Variances (Summary Report)'(045).
**  wa_nodestab-tlength = c_40.
**  wa_nodestab-compress = c_x.
**  APPEND wa_nodestab TO  i_nodestab.
**
**  CLEAR wa_nodestab.
**  wa_nodestab-id     =  c_2_1.
**  wa_nodestab-tlevel =  c_2.
**  wa_nodestab-parent =  c_1_1.
**
**  wa_nodestab-text = 'Summary of Orders for'(046).
**  wa_nodestab-tlength = c_22.
**  wa_nodestab-tcolor  = c_1.
**
**  CONCATENATE 'Plant:'(047) p_werks
**  INTO wa_nodestab-text1 SEPARATED BY space.
**  wa_nodestab-tlength1 = c_15.
**  wa_nodestab-tcolor1  = c_1.
**
**  CONCATENATE 'Phase Key:'(048) s_steus-low s_steus-high
**  INTO wa_nodestab-text2 SEPARATED BY space.
**  wa_nodestab-tlength2 = c_25.
**  wa_nodestab-tcolor2  = c_1.
**
**  IF s_arbpl[] IS INITIAL.
**    wa_nodestab-text3 = 'Resources: All'(049).
**  ELSE.
**    CONCATENATE 'Resources:'(065) s_arbpl-low c_hyp s_arbpl-high
**    INTO wa_nodestab-text3 SEPARATED BY space.
**  ENDIF.
**  wa_nodestab-tlength3 = c_20.
**  wa_nodestab-tcolor3  = c_1.
**
**  APPEND wa_nodestab TO i_nodestab.
**
******Begin of MOD-001
**  CLEAR: l_sum_plan_effic, i_sum_ordmats, i_sum_activity.
******End of MOD-001
**
**  LOOP AT i_pro_orders INTO wa_pro_orders.
**
**    l_gamng = wa_pro_orders-gamng.
**    l_gmein = wa_pro_orders-gmein.
**
*** Get actual produced Quantity or Confirm Quantity
**    IF NOT ( rb_prod IS INITIAL ).
**      l_prdqty  = wa_pro_orders-menge.
**      l_fromuom = wa_pro_orders-gruom.
**    ELSE.
**      l_prdqty  = wa_pro_orders-lmnga.
**
**************************MOD-006**********************
***     l_fromuom = wa_pro_orders-cfuom.
**      IF wa_pro_orders-cfuom IS INITIAL.
**        SELECT aufnr rueck gmnga lmnga gmein meinh
**                meilr stokz rueck_mst
**        FROM afru INTO TABLE i_afru
**        WHERE aufnr = wa_pro_orders-aufnr.
**        IF NOT i_afru[] IS INITIAL.
**          READ TABLE i_afru INTO wa_afru INDEX 1.
**          IF sy-subrc = 0.
**            l_fromuom = wa_afru-gmein.
**          ENDIF.
**        ENDIF.
**      ELSE.
**        l_fromuom = wa_pro_orders-cfuom.
**      ENDIF.
**************************MOD-006*********************
**    ENDIF.
**    IF rb_kgm = c_x.
*** do actual conversion
**      PERFORM uom_convert USING wa_pro_orders-plnbez
**                                l_prdqty
**                                l_fromuom
**                                l_conv.
**      l_prdqty = l_conv.
*** do planned conversion
*********MOD-002********************************
***      l_fromuom = wa_pro_orders-gmein.
**      l_fromuom = 'KG'.
*********Mod-002********************************
**      PERFORM uom_convert USING wa_pro_orders-plnbez
**                                wa_pro_orders-gamng
**                                l_fromuom
**                                l_conv.
**      l_gamng = l_conv.
**    ENDIF.
*** Calculating Plan Effic value
**    CLEAR l_plan_effic.
***- Begin of MOD-001
***    IF l_gamng GT 0.
***      l_diff = l_gamng - l_prdqty.
***      l_plan_effic = 100 - 100 * ( l_diff / l_gamng ).
***    ELSE.
***      CLEAR l_plan_effic.
***    ENDIF.
**
**    LOOP AT i_plpo1 INTO wa_plpo1
**            WHERE plnty = wa_pro_orders-plnty
**              AND plnnr = wa_pro_orders-plnnr
**              AND steus = 'YBN1'.
**      IF wa_plpo1-vgw02 IS NOT INITIAL.
**        MOVE wa_plpo1-usr04 TO l_effic. "L_VALUE.
**        wa_plpo2 = wa_plpo1.
**        APPEND wa_plpo2 TO i_plpo2.
******************mod-002************************
***    CONDENSE L_VALUE.
***    write l_effic to l_plan_effic.
***    L_PLAN_EFFIC = floor( L_VALUE ).
******************mod-002************************
**      ELSE.
**        CLEAR l_plan_effic.
**      ENDIF.
**
**    ENDLOOP.
**
**********************MOD-008**************************************
***    LOOP AT I_ORDOPS INTO WA_ORDOPS.
***      READ TABLE I_PRO_ORDERS INTO WA_PRO_ORDERS WITH KEY
***                                    AUFNR = WA_ORDOPS-AUFNR
***                                              BINARY SEARCH.
***      IF SY-SUBRC = 0.
***        READ table i_afvc1 into wa_afvc1 with key
***                      plnty = wa_ORDOPS-plnty
***                      plnnr = wa_ORDOPS-plnnr
***                      plnkn = wa_ORDOPS-plnkn
***                      zaehl = wa_ORDOPS-zaehl
***                      aufpl = wa_pro_orders-aufpl.
***        IF SY-SUBRC = 0.
***          READ TABLE I_AFVV1 into wa_afvv1 with key
***                 aufpl = wa_afvc1-aufpl
***                 aplzl = wa_afvc1-aplzl binary search.
***          IF SY-SUBRC = 0.
***            CHECK WA_AFVV1-VGW02 NE 0.
***            l_tmp = wa_afvv1-bmsch * wa_afvv1-ism02.
***            IF l_tmp IS NOT INITIAL.
***
***              l_tmp1 = ( wa_afvv1-lmnga * wa_afvv1-vgw02 ) / l_tmp.
***
***              l_tmp1 = l_tmp1 * 100.
***
***              MOVE l_tmp1 TO l_effic.
***
***            ENDIF.
***          ENDIF.
***        ENDIF.
***      ENDIF.
***    ENDLOOP.
********************MOD-008*******************************************
*
**
*******Mod-002*******************************
***    READ TABLE i_afvc INTO wa_afvc
***         WITH KEY plnty = wa_plpo1-plnty
***                  plnnr = wa_plpo1-plnnr
***                  zaehl = wa_plpo1-zaehl.
**
**    LOOP AT i_plpo2 INTO wa_plpo2..
**      CLEAR: wa_afvc, wa_afvv.
**      READ TABLE i_afvc INTO wa_afvc
**           WITH KEY plnty = wa_plpo2-plnty
**                    plnnr = wa_plpo2-plnnr
**                    plnkn = wa_plpo2-plnkn
**                    zaehl = wa_plpo2-zaehl
**                    aufpl = wa_pro_orders-aufpl.
**
***Mod-002*************************************
**
**      IF sy-subrc IS INITIAL.
**        READ TABLE i_afvv INTO wa_afvv
**             WITH KEY aufpl = wa_afvc-aufpl
**                      aplzl = wa_afvc-aplzl.
**
**        l_tmp = wa_afvv-bmsch * wa_afvv-ism02.
**        IF l_tmp IS NOT INITIAL.
**
**          l_tmp1 = ( wa_afvv-lmnga * wa_afvv-vgw02 ) / l_tmp.
**
**          l_tmp1 = l_tmp1 * 100.
**
**          MOVE l_tmp1 TO l_effic1.
**
**        ENDIF.
**
**      ENDIF.
**    ENDLOOP.
**
***    CLEAR v_plant_effic.
***    PERFORM plant_effic USING wa_pro_orders-plnty
***                            wa_pro_orders-plnnr wa_pro_orders-plnkn
***                            wa_pro_orders-zaehl
***                      CHANGING v_plant_effic.
***    l_sum_plan_effic  = l_sum_plan_effic  + l_plan_effic.
**    l_sum_plan_effic  = l_sum_plan_effic  + l_effic.
***    l_sum_plant_effic = l_sum_plant_effic + v_plant_effic.
**    l_sum_plant_effic = l_sum_plant_effic + l_effic1.
***- End of MOD-001
**    l_sum_prdqty      = l_sum_prdqty  + l_prdqty.
**
*****Begin of MOD-001
***    CLEAR: i_sum_activity. "l_prdqty
*****End of MOD-001
**    LOOP AT i_ordops INTO wa_ordops
**           WHERE aufnr = wa_pro_orders-aufnr.
**      PERFORM activity_report USING l_prdqty l_gamng l_fromuom l_gmein
.
**      CLEAR : wa_ordops.
**    ENDLOOP.
**
**LOOP AT i_ordmats INTO wa_ordmats WHERE aufnr = wa_pro_orders-aufnr.
**      PERFORM summary_materials.
**      CLEAR : wa_ordmats.
**    ENDLOOP.
**    CLEAR : wa_pro_orders.
**  ENDLOOP.
**  CLEAR: l_plan_effic, v_plant_effic, l_prdqty, l_tot_orders.
**
*** Passing summraised data to internal table for printing.
**  DESCRIBE TABLE i_pro_orders LINES l_tot_orders.
**  IF l_tot_orders > 0.
***    l_plan_effic = l_sum_plan_effic / l_tot_orders. " MOD-001--
**    l_effic = l_sum_plan_effic / l_tot_orders.              "
**  MOD-001++
***    v_plant_effic = l_sum_plant_effic / l_tot_orders." MOD-001--
**    l_effic1 = l_sum_plant_effic / l_tot_orders.            "
**  MOD-001++
**  ENDIF.
**  CLEAR  wa_nodestab.
**  wa_nodestab-id     = c_2_2.
**  wa_nodestab-tlevel = c_3.
**  wa_nodestab-parent = c_1_1.
**
**  IF NOT ( rb_prod IS INITIAL ).
**    wa_nodestab-text = 'Produced Qty:'(050).
**  ELSE.
**    wa_nodestab-text = 'Confirmed Qty:'(051).
**  ENDIF.
**  wa_nodestab-tlength = c_15.
**  wa_nodestab-tcolor  = c_4.
**
**  MOVE l_sum_prdqty TO wa_nodestab-text1(20).
**  wa_nodestab-tlength1 = c_20.
**  wa_nodestab-tcolor1  = c_4.
**
***  CONCATENATE 'Plan Effic:'(036) l_plan_effic c_perc "'%'
**  WRITE l_effic TO l_plan_effic.
**  CONCATENATE 'Exp. Line Eff.'(036) l_plan_effic c_perc "'%'
**  INTO wa_nodestab-text2 SEPARATED BY space.
**  wa_nodestab-tlength2 = c_25.
**  wa_nodestab-tcolor2  = c_4.
**
***  CONCATENATE 'Plant Effic:'(037) v_plant_effic c_perc "'%'
**  WRITE l_effic1 TO l_plant_effic.
**  CONCATENATE 'Act. Line Eff.'(037) l_plant_effic c_perc "'%'
**  INTO wa_nodestab-text3 SEPARATED BY space.
**  wa_nodestab-tlength3 = c_25.
**  wa_nodestab-tcolor3  = c_4.
**
**  APPEND wa_nodestab TO i_nodestab.
**
*** Summarised Phase Information
**  CLEAR  wa_nodestab.
**  wa_nodestab-id     = c_3_3.
**  wa_nodestab-tlevel = c_3.
**  wa_nodestab-parent = c_1_1.
**
**  wa_nodestab-text = 'Activity'(052).
**  wa_nodestab-tlength = c_40.
**  wa_nodestab-tcolor  = c_4.
**
**  IF rb_fiscl = c_x.
**    CONCATENATE 'Actual Usage'(040) v_waers
**    INTO wa_nodestab-text1 SEPARATED BY space.
**  ELSE.
**    wa_nodestab-text1 = 'Actual Usage'(040).
**  ENDIF.
**  wa_nodestab-tlength1 = c_20.
**  wa_nodestab-tcolor1  = c_4.
**
**  IF rb_fiscl = c_x.
**    CONCATENATE 'Standard Usage'(041) v_waers
**    INTO wa_nodestab-text2 SEPARATED BY space.
**  ELSE.
**    wa_nodestab-text2 = 'Standard Usage'(041).
**  ENDIF.
**  wa_nodestab-tlength2 = c_20.
**  wa_nodestab-tcolor2  = c_4.
**
**  IF rb_fiscl = c_x.
**    CONCATENATE 'Activity Variance'(042) v_waers
**    INTO wa_nodestab-text3 SEPARATED BY space.
**  ELSE.
**    wa_nodestab-text3 = 'Activity Variance'(042).
**  ENDIF.
**  wa_nodestab-tlength3 = c_35.
**  wa_nodestab-tcolor3  = c_4.
**
**  APPEND wa_nodestab TO i_nodestab.
**
*** Summarized activities
**  CLEAR: l_act_total, l_std_total, l_var_total.
**  SORT i_sum_activity BY lar.
**  LOOP AT i_sum_activity INTO wa_sum_activity.
**
**    SELECT ltext FROM  cslt INTO l_ltext
**       WHERE  spras       = sy-langu
**       AND    kokrs       = p_kokrs
**       AND    lstar       = wa_sum_activity-lar.
**    ENDSELECT.
**
**
**    IF sy-subrc = 0.
***Not required to handle
**    ENDIF.
**
**
**    CLEAR  wa_nodestab.
**    wa_nodestab-id     =  c_3_4.
**    wa_nodestab-tlevel =  c_4.
**    wa_nodestab-parent =  c_3_3.
**
**    wa_nodestab-text1 = l_ltext.
**    wa_nodestab-tlength1 = c_36.
**    wa_nodestab-tcolor1  = c_3.
**
**    IF rb_fiscl IS INITIAL.
**      MOVE wa_sum_activity-afru_ism TO wa_nodestab-text2(20).
**      wa_nodestab-tlength2 = c_20.
**      wa_nodestab-tcolor2  = c_3.
**
**      MOVE wa_sum_activity-ism_should TO wa_nodestab-text3(20).
**      wa_nodestab-tlength3 = c_20.
**      wa_nodestab-tcolor3  = c_3.
**
**      MOVE wa_sum_activity-ism_var TO wa_nodestab-text4(20).
**      wa_nodestab-tlength4 = c_20.
**      wa_nodestab-tcolor4  = c_3.
**
**    ELSE.
**      MOVE wa_sum_activity-coact TO wa_nodestab-text2(20).
**      wa_nodestab-tlength2 = c_20.
**      wa_nodestab-tcolor2  = c_3.
**
**      MOVE wa_sum_activity-costd TO wa_nodestab-text3(20).
**      wa_nodestab-tlength3 = c_20.
**      wa_nodestab-tcolor3  = c_3.
**
**      MOVE wa_sum_activity-covar TO wa_nodestab-text4(20).
**      wa_nodestab-tlength4 = c_20.
**      wa_nodestab-tcolor4  = c_3.
**
**      l_act_total = l_act_total + wa_sum_activity-coact.
**      l_std_total = l_std_total + wa_sum_activity-costd.
**      l_var_total = l_var_total + wa_sum_activity-covar.
**    ENDIF.
**    APPEND wa_nodestab TO i_nodestab.
**    CLEAR : wa_nodestab, wa_sum_activity.
**  ENDLOOP.
**  IF NOT ( rb_fiscl IS INITIAL ).
**
*** Display sub-total of Activities.
**    CLEAR  wa_nodestab.
**    wa_nodestab-id     = c_3_4.
**    wa_nodestab-tlevel =  c_4.
**    wa_nodestab-parent = c_3_3.
**
**    IF rb_fiscl = c_x.
**      CONCATENATE 'Fiscal Activity Totals:'(053) v_waers
**      INTO wa_nodestab-text1 SEPARATED BY space.
**    ELSE.
**      wa_nodestab-text1 = 'Fiscal Activity Totals:'(053).
**    ENDIF.
**    wa_nodestab-tlength1 = c_36.
**    wa_nodestab-tcolor1  = c_2.
**
**    MOVE l_act_total TO wa_nodestab-text2(20).
**    wa_nodestab-tlength2 = c_20.
**    wa_nodestab-tcolor2  = c_2.
**
**    MOVE l_std_total TO wa_nodestab-text3(20).
**    wa_nodestab-tlength3 = c_20.
**    wa_nodestab-tcolor3  = c_2.
**
**    MOVE l_var_total TO wa_nodestab-text4(20).
**    wa_nodestab-tlength4 = c_20.
**    wa_nodestab-tcolor4  = c_2.
**
**    APPEND wa_nodestab TO i_nodestab.
**  ENDIF.
*** Summarized Material Information
**  CLEAR  wa_nodestab.
**  wa_nodestab-id     = c_6_1.
**  wa_nodestab-tlevel =  c_3.
**  wa_nodestab-parent = c_2_2.
**
**  PERFORM material_header.
**
**  CLEAR: l_act_total, l_std_total, l_var_total.
**  SORT i_sum_ordmats BY matnr.
**  LOOP AT i_sum_ordmats INTO wa_sum_ordmats .
**    CLEAR: wa_nodestab.
**    wa_nodestab-id     = c_4_1.
**    wa_nodestab-tlevel = c_4.
**    wa_nodestab-parent = c_3_2.
**
*** Material Number
**    WRITE wa_sum_ordmats-matnr TO wa_nodestab-text NO-ZERO.
**    wa_nodestab-tlength = c_18.
**    wa_nodestab-tcolor  = c_3.
**
*** Material Description
**    CLEAR wa_material_des.
**    READ TABLE i_material_des INTO wa_material_des
**       WITH KEY matnr = wa_sum_ordmats-matnr.
**    wa_nodestab-text1 = wa_material_des-maktx.
**    wa_nodestab-tlength1 = c_30.
**    wa_nodestab-tcolor1  = c_3.
**
*** Standard planned or zero loss planned
**
**    IF rb_zloss IS INITIAL.
**      l_qty = wa_sum_ordmats-stdqy.
**    ELSE.
**      l_qty = wa_sum_ordmats-zloss.
**    ENDIF.
**
*** Order uom or kgm
**    IF rb_kgm IS INITIAL.
**      l_aqty = wa_sum_ordmats-menge.
**      l_sqty = l_qty.
**    ELSE.
*** do actual conversion
**      PERFORM uom_convert USING wa_sum_ordmats-matnr
**                                wa_sum_ordmats-menge
**                                wa_sum_ordmats-amein
**                                l_aqty.
*** do std/zloss conversion
**      PERFORM uom_convert USING wa_ordmats-matnr
**                                wa_ordmats-stdqy
**                                wa_ordmats-meins
**                                l_sqty.
**    ENDIF.
**
**    PERFORM std_percentage_calc USING l_aqty l_sqty l_pcent.
**
*** Fiscal or quantity
**    IF rb_fiscl IS INITIAL.
**      MOVE l_aqty TO wa_nodestab-text2(20). " Actual Usage
**      wa_nodestab-tlength2 = c_20.
**      wa_nodestab-tcolor2  = c_3.
**
**      MOVE l_sqty TO wa_nodestab-text3(20). " Standard Usage
**      wa_nodestab-tlength3 = c_20.
**      wa_nodestab-tcolor3  = c_3.
**
**    ELSE.
**      IF NOT wa_sum_ordmats-peinh IS INITIAL.
**        CLEAR l_cost.
**        l_cost = ( wa_sum_ordmats-stprs * wa_sum_ordmats-menge )
**                                   / wa_sum_ordmats-peinh.
**        MOVE l_cost TO wa_nodestab-text2(20). " Acutal Usage
**        wa_nodestab-tlength2 = c_20.
**        wa_nodestab-tcolor2  = c_3.
**
**        l_act_total = l_act_total + l_cost. " Subtotal of actual
**
**      ENDIF.
**      IF NOT wa_sum_ordmats-peinh IS INITIAL.
**        CLEAR l_cost.
**        l_cost = ( wa_sum_ordmats-stprs * wa_sum_ordmats-stdqy )
**                                  / wa_sum_ordmats-peinh.
**        MOVE l_cost TO wa_nodestab-text3(20). " Standard Usage
**        wa_nodestab-tlength3 = c_20.
**        wa_nodestab-tcolor3  = c_3.
**
**        l_std_total = l_std_total + l_cost. " Subtotal of standard
**
**      ENDIF.
**    ENDIF.
**
**    MOVE l_pcent TO wa_nodestab-text4(18). " Variance Percentage
**    CONCATENATE wa_nodestab-text4(18) c_perc "'%'
**    INTO wa_nodestab-text4(20) SEPARATED BY space.
**    wa_nodestab-tlength4 = c_20.                            "c_19.
**    wa_nodestab-tcolor4  = c_3.
**
**    CLEAR: l_diff, l_cost.
**    l_diff = wa_sum_ordmats-menge - wa_sum_ordmats-stdqy.
**    IF NOT wa_sum_ordmats-peinh IS INITIAL.
**l_cost = ( wa_sum_ordmats-stprs * l_diff ) / wa_sum_ordmats-peinh.
**      l_cost = l_cost * -1.
**    ENDIF.
**
**    MOVE l_cost TO wa_nodestab-text5(20). " Variance  "15
**    wa_nodestab-tlength5 = c_20.                            "c_15
**    wa_nodestab-tcolor5  = c_3.
**
**    l_var_total = l_var_total + l_cost. " Subtotal of Variance
**
**    APPEND wa_nodestab TO i_nodestab.
**    CLEAR : wa_nodestab, wa_sum_ordmats.
**  ENDLOOP.
*** Displaying Subtotals
**  IF NOT ( rb_fiscl IS INITIAL ).
**
**    CLEAR  wa_nodestab.
**    wa_nodestab-id     = c_4_1.
**    wa_nodestab-tlevel =  c_4.
**    wa_nodestab-parent = c_3_2.
**
**    IF rb_fiscl = c_x.
**      CONCATENATE 'Fiscal quantity Totals:'(054) v_waers
**      INTO wa_nodestab-text SEPARATED BY space.
**    ELSE.
**      wa_nodestab-text = 'Fiscal quantity Totals:'(054).
**    ENDIF.
**    wa_nodestab-tlength = c_30.
**    wa_nodestab-tcolor  = c_6.
**
**    wa_nodestab-text1 = space.
**    wa_nodestab-tlength1 = c_18.
**    wa_nodestab-tcolor1  = c_6.
**
**    MOVE l_act_total TO wa_nodestab-text2(20) .
**    wa_nodestab-tlength2 = c_20.
**    wa_nodestab-tcolor2  = c_6.
**
**    MOVE l_std_total TO wa_nodestab-text3(20) .
**    wa_nodestab-tlength3 = c_20.
**    wa_nodestab-tcolor3  = c_6.
**
**    wa_nodestab-text4 = space.
**    wa_nodestab-tlength4 = c_19.
**    wa_nodestab-tcolor4  = c_6.
**
**    MOVE l_var_total TO wa_nodestab-text5(21) .
**    wa_nodestab-tlength5 = c_21. "15.
**    wa_nodestab-tcolor5  = c_6.
**
**    APPEND wa_nodestab TO i_nodestab.
**  ELSE.
**    CLEAR  wa_nodestab.
**    wa_nodestab-id     =  c_4_1.
**    wa_nodestab-tlevel =  c_4.
**    wa_nodestab-parent =  c_3_2.
**
**    IF rb_fiscl = c_x.
**      CONCATENATE 'Variance Fiscal Total:'(055) v_waers
**      INTO wa_nodestab-text SEPARATED BY space.
**    ELSE.
**      wa_nodestab-text = 'Variance Fiscal Total:'(055).
**    ENDIF.
**    wa_nodestab-tlength = c_29.
**    wa_nodestab-tcolor  = c_6.
**
**    wa_nodestab-text1 = space.
**    wa_nodestab-tlength1 = c_40.
**    wa_nodestab-tcolor1  = c_6.
**
**    wa_nodestab-text2 = space.
**    wa_nodestab-tlength2 = '41'.                            "c_40.
**    wa_nodestab-tcolor2  = c_6.
**
**    MOVE l_var_total TO wa_nodestab-text3(20) .
**    wa_nodestab-tlength3 = c_20.                            "c_15.
**    wa_nodestab-tcolor3  = c_6.
**
**    APPEND wa_nodestab TO i_nodestab.
**  ENDIF.
**ENDFORM.                    " DISPLAY_SUMMARY_REPORT
***&--------------------------------------------------------------------
***
***&      Form  DISPLAY_PHASE_REPORT
***&--------------------------------------------------------------------
***
***       text
***---------------------------------------------------------------------
***
***---------------------------------------------------------------------
***
**FORM display_phase_report.
**
**  DATA: l_date_low(10)  TYPE c,
**        l_date_high(10) TYPE c,
**        l_diff          TYPE menge_d,
***        l_plan_effic(3) TYPE c,
**        l_plan_effic    TYPE char05,                        "MOD-001++
**        l_plant_effic   TYPE char05,                        "MOD-001++
**        l_gamng         TYPE menge_d,
**        l_gamng1(20)    TYPE c,
**        l_gmein         TYPE meins,
**
**        l_qty    TYPE menge_d,
**        l_prdqty TYPE menge_d,
**        l_conv   TYPE menge_d,
**        l_aqty   TYPE menge_d,
**        l_sqty   TYPE menge_d,
**
**        l_pcent(3)  TYPE p DECIMALS 2,
**        l_cost(8)   TYPE p DECIMALS 2,
**
**        l_act_total(8) TYPE p DECIMALS 2,
**        l_std_total(8) TYPE p DECIMALS 2,
**        l_var_total(8) TYPE p DECIMALS 2,
**
**        l_fromuom TYPE meins,
**        l_cfuom   TYPE meins,
**
**        l_ph_bmsch TYPE i.
***- Begin of MOD-001
**  DATA: l_value TYPE char16,
**        l_tmp TYPE lmnga,
**        l_tmp1 TYPE lmnga,
**        l_effic TYPE p DECIMALS 1,
**        l_uom   TYPE char03.
***- End of MOD-001
**
**
**  PERFORM pfstatus.
**  SET PF-STATUS 'MAIN' EXCLUDING i_fcode.
**  SET TITLEBAR 'VARI' WITH text-068.
**
**  CLEAR wa_nodestab.
**  REFRESH i_nodestab.
**
**  MOVE 'Display Phase Report'(030) TO v_output_text.
**  PERFORM inform_user_of_progress.
**
**  CLEAR wa_nodestab.
**  wa_nodestab-id = c_1_1.
**  wa_nodestab-tlevel = c_1.
**  wa_nodestab-text = 'Production Variances'(031).
**  wa_nodestab-tlength = c_20.
**  wa_nodestab-compress = c_x.
**  APPEND wa_nodestab TO i_nodestab.
**
**  LOOP AT i_pro_orders INTO wa_pro_orders.
**
**    CLEAR: wa_nodestab, l_date_low, l_date_high, l_gamng,
**           wa_material_des.
**
**    l_gamng = wa_pro_orders-gamng.
**    l_gmein = wa_pro_orders-gmein.
**    wa_nodestab-id     = c_2_1.
**    wa_nodestab-tlevel =  c_2.
**    wa_nodestab-parent = c_1_1.
**
*** Order Number text
**    wa_nodestab-text    = 'Order Num:'(032).
**    wa_nodestab-tlength = c_12.
**    wa_nodestab-tcolor  = c_1.
*** Order number
**    WRITE wa_pro_orders-aufnr TO wa_nodestab-text1 NO-ZERO.
**    wa_nodestab-tlength1 = c_12.
**    wa_nodestab-tcolor1  = c_1.
**    wa_nodestab-hotspot1 = c_x.
**
*** Date Range
**    WRITE wa_pro_orders-wdate TO l_date_low.
**    WRITE wa_pro_orders-gltrp TO l_date_high.
**    CONCATENATE l_date_low c_hyp l_date_high
**    INTO wa_nodestab-text2 SEPARATED BY space.
**    wa_nodestab-tlength2 = c_25.
**    wa_nodestab-tcolor2  = c_1.
**
*** Material Number
**    WRITE wa_pro_orders-plnbez TO wa_nodestab-text3 NO-ZERO.
**    wa_nodestab-tlength3 = c_18.
**    wa_nodestab-tcolor3  = c_1.
**
*** Material Description
**    READ TABLE i_material_des INTO wa_material_des
**        WITH KEY matnr = wa_pro_orders-plnbez.
**    wa_nodestab-text4 = wa_material_des-maktx.
**    wa_nodestab-tlength4 = c_33.
**    wa_nodestab-tcolor4  = c_1.
**
**    APPEND wa_nodestab TO i_nodestab.
**
**    LOOP AT i_ordops INTO wa_ordops
**             WHERE aufnr = wa_pro_orders-aufnr.
**      PERFORM get_confirmation_qty USING wa_ordops-rueck
**                                         l_prdqty l_cfuom.
**      IF rb_kgm = c_x.
**        IF rb_conf IS INITIAL.
**          l_prdqty  = wa_pro_orders-menge.
**          l_fromuom = wa_pro_orders-gruom.
**        ELSE.
**          l_fromuom = l_cfuom.
**        ENDIF.
*** do gr/conf conversion
**        PERFORM uom_convert USING wa_pro_orders-plnbez l_prdqty
**                                  l_fromuom l_conv.
**        l_prdqty = l_conv.
**        l_qty = l_prdqty.
*** do planned conversion
*********mod-002*******************************
***       l_fromuom = wa_pro_orders-gmein.
**        l_fromuom = 'KG'.
********MOD-002********************************
**
**        PERFORM uom_convert USING wa_pro_orders-plnbez
**                                  wa_pro_orders-gamng
**                                  l_fromuom l_conv.
**        l_gamng = l_conv.
**      ELSE.
*** Get Standard Numbers from the phase
**        READ TABLE i_plpo INTO wa_plpo
**                          WITH KEY plnty = wa_pro_orders-plnty
**                                   plnnr = wa_pro_orders-plnnr
**                                   plnkn = wa_pro_orders-plnkn
**                                   zaehl = wa_pro_orders-zaehl.
**        PERFORM get_stds USING wa_ordops-plnty wa_ordops-plnnr
**                               wa_ordops-plnkn wa_ordops-zaehl.
*** Factor in any differences in uoms (plpo selected in get_stds form)
**        l_ph_bmsch = wa_plpo-bmsch / ( wa_plpo-umrez / wa_plpo-umren )
.
*** calculate planned phase qty as planned order qty / final phase std
**qty
*** current phase std qty
**        l_gamng = ( wa_pro_orders-gamng / wa_plpo-bmsch ) * l_ph_bmsch
.
*** Get actual produced Qty (from order) or use Confirm Qty (from phase)
**        IF rb_conf IS INITIAL.
*** Factor in any differences in uoms (plpo
**  selected in plant_effic form)
**          l_qty = ( wa_pro_orders-menge / wa_plpo-bmsch ) * l_ph_bmsch
.
**          l_prdqty = wa_pro_orders-menge.
**          l_fromuom = wa_pro_orders-gruom.
**        ELSE.
**          l_qty = ( l_prdqty / wa_plpo-bmsch ) * l_ph_bmsch.
**          l_fromuom = l_cfuom.
**        ENDIF.
**      ENDIF.
**
***- begin of MOD-001
*** Calculate Plan effic.
***      CLEAR l_plan_effic.
***
***      IF l_gamng > 0.
***        l_diff = ABS( l_gamng - l_qty ).
***        l_plan_effic = c_100 - c_100 * ( l_diff / l_gamng ).
***      ELSE.
***        CLEAR l_plan_effic.
***      ENDIF.
**
**      LOOP AT i_plpo1 INTO wa_plpo1
**              WHERE plnty = wa_pro_orders-plnty
**                AND plnnr = wa_pro_orders-plnnr
**                AND steus = 'YBN1'.
**        IF wa_plpo1-vgw02 IS NOT INITIAL.
**          MOVE wa_plpo1-usr04 TO l_effic. "L_VALUE.
**          WRITE l_effic TO l_plan_effic.
**          wa_plpo2 = wa_plpo1.
**          APPEND wa_plpo2 TO i_plpo2.
***********MOD-002*******************************
***        ELSE.
***          CLEAR l_plan_effic.
**        ENDIF.
**********MOD-002********************************
**      ENDLOOP.
**
**
***- End of MOD-001
*** Resource Information
**      CLEAR  wa_nodestab.
**      wa_nodestab-id     =  c_2_2.
**      wa_nodestab-tlevel =  c_3.
**      wa_nodestab-parent = c_1_1.
**
**      CONCATENATE 'Resource:'(056) wa_pro_orders-arbpl
**      INTO wa_nodestab-text SEPARATED BY space.
**      wa_nodestab-tlength = c_25.
**      wa_nodestab-tcolor  = c_4.
**
**      READ TABLE i_wc_text INTO wa_wc_text
**             WITH KEY objid = wa_pro_orders-arbid.
**      wa_nodestab-text1 = wa_wc_text-ktext.
**      wa_nodestab-tlength1 = c_30.
**      wa_nodestab-tcolor1  = c_4.
**
*************MOD-002*********************************
**      wa_nodestab-text2 = wa_ordops-vornr.
**      wa_nodestab-tlength2 = c_4.
**      wa_nodestab-tcolor2  = c_4.
**
**********mod-002************************************
**
*** Produced Quantity / Confirmed Quantity
**      MOVE l_prdqty TO wa_nodestab-text3(20).
**      MOVE l_fromuom TO l_uom.                              "
** MOD-001++
**      IF NOT ( rb_prod IS INITIAL ).
***        CONCATENATE 'Prod Qty: '(033) wa_nodestab-text2 "MOD-001-
**        CONCATENATE 'Prod Qty: '(033) wa_nodestab-text3 l_uom"MOD-001+
**       INTO wa_nodestab-text3 SEPARATED BY space.
**      ELSE.
***        CONCATENATE 'Conf Qty: '(034) wa_nodestab-text2 "MOD-001-
**        CONCATENATE 'Conf Qty: '(034) wa_nodestab-text3 l_uom"MOD-001+
**        INTO wa_nodestab-text3 SEPARATED BY space.
**      ENDIF.
**
***      wa_nodestab-tlength2 = c_30. "MOD-001-
**      wa_nodestab-tlength3 = c_35_1.                        "MOD-001+
**      wa_nodestab-tcolor3 = c_1.
**
***    CONCATENATE 'Plan Effic:'(036) l_plan_effic c_perc "'%'
**      CONCATENATE 'Exp. Line Eff.'(036) l_plan_effic c_perc "'%'
**        INTO wa_nodestab-text4 SEPARATED BY space.
**      wa_nodestab-tlength4 = c_25.
**      wa_nodestab-tcolor4  = c_4.
**
***      CLEAR v_plant_effic.
***      PERFORM plant_effic USING wa_ordops-plnty
***                                wa_ordops-plnnr
***                                wa_ordops-plnkn
***                                wa_ordops-zaehl
***                       CHANGING v_plant_effic.
**      CLEAR l_effic.
***************mod-002**************************
***    READ TABLE I_AFVC INTO WA_AFVC
***         WITH KEY PLNTY = WA_PLPO1-PLNTY
***                  PLNNR = WA_PLPO1-PLNNR
***                  ZAEHL = WA_PLPO1-ZAEHL.
**** Mod-002***********************************
**
*****************MOD-008************************
***      LOOP AT I_ORDOPS INTO WA_ORDOPS.
***        READ TABLE I_PRO_ORDERS INTO WA_PRO_ORDERS WITH KEY
***                                      AUFNR = WA_ORDOPS-AUFNR
***                                                BINARY SEARCH.
***        IF SY-SUBRC = 0.
***          READ table i_afvc1 into wa_afvc1 with key
***                        plnty = wa_ORDOPS-plnty
***                        plnnr = wa_ORDOPS-plnnr
***                        plnkn = wa_ORDOPS-plnkn
***                        zaehl = wa_ORDOPS-zaehl
***                        aufpl = wa_pro_orders-aufpl.
***          IF SY-SUBRC = 0.
***            READ TABLE I_AFVV1 into wa_afvv1 with key
***                   aufpl = wa_afvc1-aufpl
***                   aplzl = wa_afvc1-aplzl binary search.
***            IF SY-SUBRC = 0.
***              CHECK WA_AFVV1-VGW02 NE 0.
***              l_tmp = wa_afvv1-bmsch * wa_afvv1-ism02.
***              IF l_tmp IS NOT INITIAL.
***
***                l_tmp1 = ( wa_afvv1-lmnga * wa_afvv1-vgw02 ) / l_tmp.
***
***                l_tmp1 = l_tmp1 * 100.
***
***                MOVE l_tmp1 TO l_effic.
***
***              ENDIF.
***            ENDIF.
***          ENDIF.
***        ENDIF.
***      ENDLOOP.
***
***************MOD-008***************************
**
**      LOOP AT i_plpo2 INTO wa_plpo2.
**        READ TABLE i_afvc INTO wa_afvc
**           WITH KEY plnty = wa_plpo2-plnty
**                    plnnr = wa_plpo2-plnnr
**                    plnkn = wa_plpo2-plnkn
**                    zaehl = wa_plpo2-zaehl
**                    aufpl = wa_pro_orders-aufpl.
**
**
**
**** Mod-002***********************************
**
**        IF sy-subrc IS INITIAL.
**          READ TABLE i_afvv INTO wa_afvv
**               WITH KEY aufpl = wa_afvc-aufpl
**                        aplzl = wa_afvc-aplzl.
**
**          l_tmp = wa_afvv-bmsch * wa_afvv-ism02.
**          IF l_tmp IS NOT INITIAL.
**
**            l_tmp1 = ( wa_afvv-lmnga * wa_afvv-vgw02 ) / l_tmp.
**
**            l_tmp1 = l_tmp1 * 100.
**
**            MOVE l_tmp1 TO l_effic.
**
**          ENDIF.
**
**        ENDIF.
**      ENDLOOP.
**
**      WRITE l_effic TO l_plant_effic.
**
***    CONCATENATE 'Plant Effic:'(037) v_plant_effic c_perc "'%'
**      CONCATENATE 'Act. Line Eff.'(037) l_plant_effic c_perc "'%'
**                                                            " MOD-001+
**        INTO wa_nodestab-text5 SEPARATED BY space.
**      wa_nodestab-tlength5 = c_25.
**      wa_nodestab-tcolor5 = c_4.
**
**      APPEND wa_nodestab TO i_nodestab.
**
*** Phase Information
**      CLEAR  wa_nodestab.
**      wa_nodestab-id     = c_3_3.
**      wa_nodestab-tlevel =  c_3.
**      wa_nodestab-parent = c_1_1.
**
**      wa_nodestab-text    = 'Phase'(038).
**      wa_nodestab-tlength =  c_10.
**      wa_nodestab-tcolor  =  c_4.
**
**      MOVE l_gamng TO l_gamng1.
**      CONCATENATE 'Activity (Std Plan:'(039) l_gamng1 c_brac "')'
**      INTO wa_nodestab-text1 SEPARATED BY space.
**      wa_nodestab-tlength1 = c_42.
**      wa_nodestab-tcolor1  = c_4.
**
**      IF rb_fiscl = c_x.
**        CONCATENATE 'Actual Usage'(040) v_waers
**        INTO wa_nodestab-text2 SEPARATED BY space.
**      ELSE.
**        wa_nodestab-text2 = 'Actual Usage'(040).
**      ENDIF.
**      wa_nodestab-tlength2 = c_20.
**      wa_nodestab-tcolor2  = c_4.
**
**      IF rb_fiscl = c_x.
**        CONCATENATE 'Standard Usage'(041) v_waers
**        INTO wa_nodestab-text3 SEPARATED BY space.
**      ELSE.
**        wa_nodestab-text3 = 'Standard Usage'(041).
**      ENDIF.
**      wa_nodestab-tlength3 = c_20.
**      wa_nodestab-tcolor3  = c_4.
**
**      IF rb_fiscl = c_x.
**        CONCATENATE 'Activity Variance'(042) v_waers
**        INTO wa_nodestab-text4 SEPARATED BY space.
**      ELSE.
**        wa_nodestab-text4 = 'Activity Variance'(042).
**      ENDIF.
**      wa_nodestab-tlength4 = c_35.
**      wa_nodestab-tcolor4  = c_4.
**
**      APPEND wa_nodestab TO i_nodestab.
**
*** Display acitivity report
**      PERFORM activity_report USING l_prdqty l_gamng l_uom l_gmein.
**
*** Material Information
**      CLEAR: wa_nodestab, l_act_total, l_std_total, l_var_total.
**      wa_nodestab-id = c_3_4.
**      wa_nodestab-tlevel = c_3.
**      wa_nodestab-parent = c_1_1.
**
**      PERFORM material_header.
**
*** Individual material details
**      LOOP AT i_ordmats INTO wa_ordmats
**           WHERE aufnr = wa_pro_orders-aufnr
**             AND vornr = wa_ordops-vornr.
**
**        CLEAR: wa_nodestab.
**        wa_nodestab-id     = c_4_1.
**        wa_nodestab-tlevel =  c_4.
**        wa_nodestab-parent = c_3_2.
**
*** Material Number
**        WRITE wa_ordmats-matnr TO wa_nodestab-text NO-ZERO.
**        wa_nodestab-tlength = c_18.
**        wa_nodestab-tcolor  = c_3.
**
*** Material Description
**        CLEAR wa_material_des.
**        READ TABLE i_material_des INTO wa_material_des
**              WITH KEY matnr = wa_ordmats-matnr.
**        wa_nodestab-text1 = wa_material_des-maktx.
**        wa_nodestab-tlength1 = c_30.
**        wa_nodestab-tcolor1  = c_3.
**
*** Standard planned or zero loss planned
**
**        IF rb_zloss IS INITIAL.
**          l_qty = wa_ordmats-stdqy.
**        ELSE.
**          l_qty = wa_ordmats-zloss.
**        ENDIF.
**
*** Order uom or kgm
**        IF rb_kgm IS INITIAL.
**          l_aqty = wa_ordmats-menge.
**          l_sqty = l_qty.
**        ELSE.
*** do actual conversion
**          PERFORM uom_convert USING wa_ordmats-matnr
**                                    wa_ordmats-menge
**                                    wa_ordmats-amein
**                                    l_aqty.
*** do std/zloss conversion
**          PERFORM uom_convert USING wa_ordmats-matnr
**                                    wa_ordmats-stdqy
**                                    wa_ordmats-meins
**                                    l_sqty.
**        ENDIF.
**
**        PERFORM std_percentage_calc USING l_aqty l_sqty l_pcent.
**
*** Fiscal or quantity
**        IF rb_fiscl IS INITIAL.
**          MOVE l_aqty TO wa_nodestab-text2(20). " Actual Usage
**          wa_nodestab-tlength2 = c_20.
**          wa_nodestab-tcolor2 = c_3.
**
**          MOVE l_sqty TO wa_nodestab-text3(20). " Standard Usage
**          wa_nodestab-tlength3 = c_20.
**          wa_nodestab-tcolor3 = c_3.
**
**        ELSE.
**          IF NOT wa_ordmats-peinh IS INITIAL.
**            CLEAR l_cost.
**            l_cost = ( wa_ordmats-stprs * wa_ordmats-menge )
**                                       / wa_ordmats-peinh.
**            MOVE l_cost TO wa_nodestab-text2(20). " Acutal Usage
**            wa_nodestab-tlength2 = c_20.
**            wa_nodestab-tcolor2 = c_3.
**
**            l_act_total = l_act_total + l_cost. " Subtotal of actual
**          ENDIF.
**          IF NOT wa_ordmats-peinh IS INITIAL.
**            CLEAR l_cost.
**            l_cost = ( wa_ordmats-stprs * wa_ordmats-stdqy )
**                                      / wa_ordmats-peinh.
**            MOVE l_cost TO wa_nodestab-text3(20). " Standard Usage
**            wa_nodestab-tlength3 = c_20.
**            wa_nodestab-tcolor3 = c_3.
**
**            l_std_total = l_std_total + l_cost. " Subtotal of standard
**          ENDIF.
**
**        ENDIF.
**
**        MOVE l_pcent TO wa_nodestab-text4(17). " Variance Percentage
**        CONCATENATE wa_nodestab-text4(17) c_perc "'%'
**        INTO wa_nodestab-text4(19) SEPARATED BY space.
**        wa_nodestab-tlength4 = 19.
**        wa_nodestab-tcolor4 = c_3.
**
**        CLEAR: l_diff, l_cost.
**        l_diff = wa_ordmats-menge - wa_ordmats-stdqy.
**        IF NOT wa_ordmats-peinh IS INITIAL.
**          l_cost = ( wa_ordmats-stprs * l_diff ) / wa_ordmats-peinh.
**          l_cost = l_cost * -1.
**        ENDIF.
**
**        MOVE l_cost TO wa_nodestab-text5(15). " Variance
**        wa_nodestab-tlength5 = c_15.
**        wa_nodestab-tcolor5 = c_3.
**
**        l_var_total = l_var_total + l_cost. " Subtotal of Variance
**
**        APPEND wa_nodestab TO i_nodestab.
**
**      ENDLOOP.
**
*** Displaying Subtotals
**      CHECK sy-subrc IS INITIAL.
**      CLEAR  wa_nodestab.
**      wa_nodestab-id     = c_4_1.
**      wa_nodestab-tlevel =  c_4.
**      wa_nodestab-parent = c_3_2.
**
**      wa_nodestab-text    = 'Material Totals'(043).
**      wa_nodestab-tlength = c_18.
**      wa_nodestab-tcolor  = c_6.
**
**      wa_nodestab-text1    = space.
**      wa_nodestab-tlength1 = c_30.
**      wa_nodestab-tcolor1  = c_6.
**
**      MOVE l_act_total TO wa_nodestab-text2(20) .
**      wa_nodestab-tlength2 = c_20.
**      wa_nodestab-tcolor2  = c_6.
**
**      MOVE l_std_total TO wa_nodestab-text3(20) .
**      wa_nodestab-tlength3 = c_20.
**      wa_nodestab-tcolor3  = c_6.
**
**      wa_nodestab-text4 = space.
**      wa_nodestab-tlength4 = c_19.
**      wa_nodestab-tcolor4  = c_6.
**
**      MOVE l_var_total TO wa_nodestab-text5(15) .
**      wa_nodestab-tlength5 = c_15.
**      wa_nodestab-tcolor5  = c_6.
**
**      APPEND wa_nodestab TO i_nodestab.
**
**    ENDLOOP.
*** Output the materials which were issued to order but aren't on bom
**    READ TABLE i_issued_mat INTO wa_issued_mat
**        WITH KEY aufnr = wa_pro_orders-aufnr.
**    IF sy-subrc = 0.
**
**      CLEAR  wa_nodestab.
**      wa_nodestab-id     = c_3_5.
**      wa_nodestab-tlevel =  c_3 .
**      wa_nodestab-parent = c_1_1.
**
**      wa_nodestab-text =
**      'Materials issued to order but not in Recipe'(057).
**      wa_nodestab-tlength = c_45.
**      wa_nodestab-tcolor  = c_6.
**
**      APPEND wa_nodestab TO i_nodestab.
**
*** Material Information
**      CLEAR  wa_nodestab.
**      wa_nodestab-id     = c_3_6.
**      wa_nodestab-tlevel =  c_3.
**      wa_nodestab-parent = c_3_5.
**
**      PERFORM material_header.
*** now write the components
**
**      CLEAR: l_pcent, l_act_total, l_std_total, l_var_total.
**
**      LOOP AT i_issued_mat INTO wa_issued_mat
**               WHERE aufnr = wa_pro_orders-aufnr.
**
**        CLEAR: wa_nodestab, l_aqty, l_sqty, l_cost, wa_material_des.
**        wa_nodestab-id     = c_6_1.
**        wa_nodestab-tlevel =  c_6.
**        wa_nodestab-parent = c_3_6.
**
*** Material Number
**        WRITE wa_issued_mat-matnr TO wa_nodestab-text NO-ZERO.
**        wa_nodestab-tlength = c_18.
**        wa_nodestab-tcolor  = c_3.
**
*** Material Description
**        READ TABLE i_material_des INTO wa_material_des
**             WITH KEY matnr = wa_issued_mat-matnr.
**        wa_nodestab-text1 = wa_material_des-maktx.
**        wa_nodestab-tlength1 = c_30.
**        wa_nodestab-tcolor1  = c_3.
**
**        IF rb_fiscl IS INITIAL.
*** Actual Usage
**          l_aqty = wa_issued_mat-menge.
**          MOVE l_aqty TO wa_nodestab-text2(20). " Actual Usage
**          wa_nodestab-tlength2 = c_20.
**          wa_nodestab-tcolor2  = c_3.
**
*** Standard Usage
**          MOVE l_sqty TO wa_nodestab-text3(20). " Standard Usage
**          wa_nodestab-tlength3 = c_20.
**          wa_nodestab-tcolor3  = c_3.
**
**        ELSE.
**          IF NOT wa_issued_mat-peinh IS INITIAL.
**            l_cost =  ( wa_issued_mat-stprs * wa_issued_mat-menge )
**                                            / wa_issued_mat-peinh.
**          ENDIF.
**          l_act_total = l_act_total + l_cost. " Subtotal of actual
**
**          MOVE l_cost TO wa_nodestab-text2(20). " Acutal Usage
**          wa_nodestab-tlength2 = c_20.
**          wa_nodestab-tcolor2  = c_3.
**
**          CLEAR l_cost.
**          MOVE l_cost TO wa_nodestab-text3(20). " Standard Usage
**          wa_nodestab-tlength3 = c_20.
**          wa_nodestab-tcolor3  = c_3.
**
**        ENDIF.
*** Variance percentage
**        l_pcent = 100.
**        MOVE l_pcent TO wa_nodestab-text4(17). " Variance Percentage
**        CONCATENATE wa_nodestab-text4(17) c_perc "'%'
**        INTO wa_nodestab-text4(19) SEPARATED BY space.
**        wa_nodestab-tlength4 = c_19.
**        wa_nodestab-tcolor4  = c_3.
*** Variance
**        CLEAR l_cost.
**        IF NOT wa_issued_mat-peinh IS INITIAL.
**          l_cost =  ( wa_issued_mat-stprs * wa_issued_mat-menge )
**                                          / wa_issued_mat-peinh.
**          l_cost = l_cost * -1.
**        ENDIF.
**        l_var_total = l_var_total + l_cost. " Subtotal of Variance
**
**        MOVE l_cost TO wa_nodestab-text5(15). " Variance
**        wa_nodestab-tlength5 = c_15.
**        wa_nodestab-tcolor5  = c_3.
**
**        APPEND wa_nodestab TO i_nodestab.
**
**      ENDLOOP.
**
*** Displaying Subtotals of material recipe
**
**      CLEAR  wa_nodestab.
**      wa_nodestab-id     = c_6_1.
**      wa_nodestab-tlevel =  c_6.
**      wa_nodestab-parent = c_3_5.
**
**      wa_nodestab-text = 'Material Totals'(043).
**      wa_nodestab-tlength = c_18.
**      wa_nodestab-tcolor  = c_6.
**
**      wa_nodestab-text1 = space.
**      wa_nodestab-tlength1 = c_30.
**      wa_nodestab-tcolor1  = c_6.
**
**      MOVE l_act_total TO wa_nodestab-text2(20) .
**      wa_nodestab-tlength2 = c_20.
**      wa_nodestab-tcolor2  = c_6.
**
**      MOVE l_std_total TO wa_nodestab-text3(20) .
**      wa_nodestab-tlength3 = c_20.
**      wa_nodestab-tcolor3  = c_6.
**
**      wa_nodestab-text4 = space.
**      wa_nodestab-tlength4 = c_19.
**      wa_nodestab-tcolor4  = c_6.
**
**      MOVE l_var_total TO wa_nodestab-text5(15) .
**      wa_nodestab-tlength5 = c_15.
**      wa_nodestab-tcolor5  = c_6.
**
**      APPEND wa_nodestab TO i_nodestab.
**
**    ENDIF.
**
**  ENDLOOP.
**
**ENDFORM.                    " DISPLAY_PHASE_REPORT
***&--------------------------------------------------------------------
***
***&      Form  ACTIVITY_REPORT
***&--------------------------------------------------------------------
***
***       text
***---------------------------------------------------------------------
***
***---------------------------------------------------------------------
***
**FORM activity_report USING fp_l_prdqty TYPE menge_d
**                           fp_l_gamng  TYPE menge_d
**                           fp_l_uom    TYPE meins
**                           fp_l_gmein  TYPE meins.
**  DATA: l_value TYPE gamng,
**        l_ism01_var TYPE ru_ismng,
**        l_ism02_var TYPE ru_ismng,
**        l_ism03_var TYPE ru_ismng,
**        l_ism04_var TYPE ru_ismng,
**        l_ism05_var TYPE ru_ismng,
**        l_ism06_var TYPE ru_ismng.
**  DATA: struct_afvgd TYPE afvgd.
**  DATA: struct_mara TYPE mara,
**        struct_marc TYPE marc.
**  DATA: v_menge TYPE menge_d.
**
*** Get Standard Numbers from the phase
**  PERFORM get_stds USING wa_ordops-plnty wa_ordops-plnnr
**                         wa_ordops-plnkn wa_ordops-zaehl.
**
*** Calculate Standard Labour/Fitter/Machine Hours.
**  CLEAR struct_activity.
**  MOVE-CORRESPONDING wa_plpo1 TO struct_afvgd.              "#EC ENHOK
**  MOVE: wa_ordops-arbid TO struct_afvgd-arbid,
**        wa_ordops-ssavd TO struct_afvgd-ssavd.
**  MOVE wa_plpo1-vge01 TO v_msehi.
**
**  IF rb_actl IS INITIAL.
*** Planned qty
**    l_value = fp_l_gamng.
**  ELSE.
*** Actual qty
**    l_value = fp_l_prdqty.
**  ENDIF.
**
**  CALL FUNCTION 'CO_R0_DET_TOTAL_ACTIVITY'
**    EXPORTING
**      act_afvgd             = struct_afvgd
**      act_quantity          = l_value
**      act_flg_consider_conf = space
**      act_unit_of_time      = v_msehi
**    IMPORTING
**      exp_activities        = struct_activity.
**
*** Now get the confirmed values
**  PERFORM get_confirmation_details.
**
*** Get Activity 1
**  l_ism01_var = struct_activity-acti1 - wa_ord_conf1-ism01.
*** Get Activity 2
**  l_ism02_var = struct_activity-acti2 - wa_ord_conf1-ism02.
*** Get Activity 3
**  l_ism03_var = struct_activity-acti3 - wa_ord_conf1-ism03.
*** Get Activity 4
**  l_ism04_var = struct_activity-acti4 - wa_ord_conf1-ism04.
*** Get Activity 5
**  l_ism05_var = struct_activity-acti5 - wa_ord_conf1-ism05.
*** Get Activity 6
**  l_ism06_var = struct_activity-acti6 - wa_ord_conf1-ism06.
**
**  IF rb_summ IS INITIAL.
*** Now output the activities for each phase
**    IF NOT ( wa_plpo1-lar01 IS INITIAL ).
**      PERFORM activity_cost_report USING wa_plpo1-lar01
**                                         wa_ord_conf1-ism01
**                                         struct_activity-acti1
**                                         l_ism01_var.
**    ENDIF.
**    IF NOT ( wa_plpo1-lar02 IS INITIAL ).
**      PERFORM activity_cost_report USING wa_plpo1-lar02
**                                         wa_ord_conf1-ism02
**                                         struct_activity-acti2
**                                         l_ism02_var.
**    ENDIF.
**    IF NOT ( wa_plpo1-lar03 IS INITIAL ).
**      PERFORM activity_cost_report USING wa_plpo1-lar03
**                                         wa_ord_conf1-ism03
**                                         struct_activity-acti3
**                                         l_ism03_var.
**    ENDIF.
**    IF NOT ( wa_plpo1-lar04 IS INITIAL ).
**      PERFORM activity_cost_report USING wa_plpo1-lar04
**                                         wa_ord_conf1-ism04
**                                         struct_activity-acti4
**                                         l_ism04_var.
**    ENDIF.
**    IF NOT ( wa_plpo1-lar05 IS INITIAL ).
**      PERFORM activity_cost_report USING wa_plpo1-lar05
**                                         wa_ord_conf1-ism05
**                                         struct_activity-acti5
**                                         l_ism05_var.
**    ENDIF.
**    IF NOT ( wa_plpo1-lar06 IS INITIAL ).
**      PERFORM activity_cost_report USING wa_plpo1-lar06
**                                         wa_ord_conf1-ism06
**                                         struct_activity-acti6
**                                         l_ism06_var.
**    ENDIF.
**  ELSEIF rb_summ = c_x.
**    IF NOT ( wa_plpo1-lar01 IS INITIAL ).
**      PERFORM sum_activity_costs USING   wa_plpo1-lar01
**                                         wa_ord_conf1-ism01
**                                         struct_activity-acti1
**                                         l_ism01_var.
**    ENDIF.
**    IF NOT ( wa_plpo1-lar02 IS INITIAL ).
**      PERFORM sum_activity_costs USING   wa_plpo1-lar02
**                                         wa_ord_conf1-ism02
**                                         struct_activity-acti2
**                                         l_ism02_var.
**    ENDIF.
**    IF NOT ( wa_plpo1-lar03 IS INITIAL ).
**      PERFORM sum_activity_costs USING   wa_plpo1-lar03
**                                         wa_ord_conf1-ism03
**                                         struct_activity-acti3
**                                         l_ism03_var.
**    ENDIF.
**    IF NOT ( wa_plpo1-lar04 IS INITIAL ).
**      PERFORM sum_activity_costs USING   wa_plpo1-lar04
**                                         wa_ord_conf1-ism04
**                                         struct_activity-acti4
**                                         l_ism04_var.
**    ENDIF.
**    IF NOT ( wa_plpo1-lar05 IS INITIAL ).
**      PERFORM sum_activity_costs USING   wa_plpo1-lar05
**                                         wa_ord_conf1-ism05
**                                         struct_activity-acti5
**                                         l_ism05_var.
**    ENDIF.
**    IF NOT ( wa_plpo1-lar06 IS INITIAL ).
**      PERFORM sum_activity_costs USING   wa_plpo1-lar06
**                                         wa_ord_conf1-ism06
**                                         struct_activity-acti6
**                                         l_ism06_var.
**    ENDIF.
**
**  ENDIF.
**
**ENDFORM.                    " ACTIVITY_REPORT
***&--------------------------------------------------------------------
***
***&      Form  GET_STDS
***&--------------------------------------------------------------------
***
***       text
***---------------------------------------------------------------------
***
***  -->  p1        text
***  <--  p2        text
***---------------------------------------------------------------------
***
**FORM get_stds USING fp_p_plnty TYPE plnty
**                    fp_p_plnnr TYPE plnnr
**                    fp_p_plnkn TYPE plnkn
**                    fp_p_zaehl TYPE cim_count.
**
**  TYPES:   BEGIN OF ty_crco_info,
**    objty     TYPE cr_objty,
**    objid     TYPE cr_objid,
**    laset     TYPE cr_laset,
**    endda     TYPE enddatum,
**    lanum     TYPE cr_lanum,
**    begda     TYPE begdatum,
**    lstar_ref TYPE ap_kzref,
**    lstar     TYPE lstar,
**  END OF ty_crco_info.
**
**  DATA : i_crco_info TYPE STANDARD TABLE OF ty_crco_info,
**         wa_crco_info TYPE ty_crco_info.
**
**
**  DATA: l_wcinfo TYPE c,
**        l_datuv TYPE plpo-datuv,
**        lc_objty TYPE plpo-objty VALUE 'A'.
**
**  READ TABLE i_plpo1 INTO wa_plpo1 WITH KEY plnty = fp_p_plnty
**                              plnnr = fp_p_plnnr
**                              plnkn = fp_p_plnkn
**                              zaehl = fp_p_zaehl.
**  IF sy-subrc = 0.
**
**    IF ( wa_plpo1-lar01 IS INITIAL AND NOT ( wa_plpo1-vgw01 = 0 ) ) OR
**       ( wa_plpo1-lar02 IS INITIAL AND NOT ( wa_plpo1-vgw02 = 0 ) ) OR
**       ( wa_plpo1-lar03 IS INITIAL AND NOT ( wa_plpo1-vgw03 = 0 ) ) OR
**       ( wa_plpo1-lar04 IS INITIAL AND NOT ( wa_plpo1-vgw04 = 0 ) ) OR
**       ( wa_plpo1-lar05 IS INITIAL AND NOT ( wa_plpo1-vgw05 = 0 ) ) OR
**       ( wa_plpo1-lar06 IS INITIAL AND NOT ( wa_plpo1-vgw06 = 0 ) ).
**      REFRESH: i_crco_info.
*** Check the work centre is on the phase, if not go to the operation
**      IF wa_plpo1-arbid IS INITIAL.
**        SELECT datuv arbid objty
**          INTO (l_datuv,wa_plpo1-arbid,wa_plpo1-objty)
**          FROM plpo
**         WHERE plnty = wa_pro_orders-plnty
**           AND plnnr = wa_pro_orders-plnnr
**           AND plnkn = wa_plpo1-pvzkn
**           AND datuv <= sy-datum
**          ORDER BY datuv DESCENDING.
**          EXIT.
**        ENDSELECT.
**      ENDIF.
*** Default to work centre object if it's blank
**      IF wa_plpo1-objty IS INITIAL.
**        wa_plpo1-objty = lc_objty.
**      ENDIF.
*** Get the work centre activity info
**      SELECT objty objid laset endda lanum begda lstar_ref lstar
**      INTO TABLE i_crco_info
**        FROM crco
**       WHERE objty = wa_plpo1-objty
**         AND objid = wa_plpo1-arbid
**         AND laset = 1.
***     order by primary key.
**
**      IF sy-subrc = 0.
***Not required to handle
**      ENDIF.
**
**      l_wcinfo = c_y.
**    ENDIF.
**    IF l_wcinfo = c_y.
*** Use work centre info.
**      LOOP AT i_crco_info INTO wa_crco_info
**         WHERE begda <= wa_plpo1-datuv AND
**               endda >= wa_plpo1-datuv.
**        CHECK NOT wa_crco_info-lstar_ref IS INITIAL.
**        CASE wa_crco_info-lanum.
*** Only put the activity type in if there is a std value entered
**          WHEN 1.
**            IF wa_plpo1-vgw01 NE 0.
**              wa_plpo1-lar01 = wa_crco_info-lstar.
**            ENDIF.
**          WHEN 2.
**            IF wa_plpo1-vgw02 NE 0.
**              wa_plpo1-lar02 = wa_crco_info-lstar.
**            ENDIF.
**          WHEN 3.
**            IF wa_plpo1-vgw03 NE 0.
**              wa_plpo1-lar03 = wa_crco_info-lstar.
**            ENDIF.
**          WHEN 4.
**            IF wa_plpo1-vgw04 NE 0.
**              wa_plpo1-lar04 = wa_crco_info-lstar.
**            ENDIF.
**          WHEN 5.
**            IF wa_plpo1-vgw05 NE 0.
**              wa_plpo1-lar05 = wa_crco_info-lstar.
**            ENDIF.
**          WHEN 6.
**            IF wa_plpo1-vgw06 NE 0.
**              wa_plpo1-lar06 = wa_crco_info-lstar.
**            ENDIF.
**        ENDCASE.
**      ENDLOOP.
**    ENDIF.
**
**  ENDIF.
**
**ENDFORM.                    " GET_STDS
***&--------------------------------------------------------------------
**
***&      Form  get_confirmation_details
***&--------------------------------------------------------------------
***
***       text
***---------------------------------------------------------------------
***
***---------------------------------------------------------------------
***
**FORM get_confirmation_details.
**
**  DATA:  l_last_ism01 TYPE ru_ismng,
**         l_last_ism02 TYPE ru_ismng,
**         l_last_ism03 TYPE ru_ismng,
**         l_last_ism04 TYPE ru_ismng,
**         l_last_ism05 TYPE ru_ismng,
**         l_last_ism06 TYPE ru_ismng.
**
**  LOOP AT i_ord_conf1 INTO wa_ord_conf1
**             WHERE rueck = wa_ordops-rueck.
**    IF wa_ord_conf1-stokz IS INITIAL.
**      l_last_ism01 = l_last_ism01 + wa_ord_conf1-ism01.
**      l_last_ism02 = l_last_ism02 + wa_ord_conf1-ism02.
**      l_last_ism03 = l_last_ism03 + wa_ord_conf1-ism03.
**      l_last_ism04 = l_last_ism04 + wa_ord_conf1-ism04.
**      l_last_ism05 = l_last_ism05 + wa_ord_conf1-ism05.
**      l_last_ism06 = l_last_ism06 + wa_ord_conf1-ism06.
**    ELSE.
**      l_last_ism01 = l_last_ism01 - wa_ord_conf1-ism01.
**      l_last_ism02 = l_last_ism02 - wa_ord_conf1-ism02.
**      l_last_ism03 = l_last_ism03 - wa_ord_conf1-ism03.
**      l_last_ism04 = l_last_ism04 - wa_ord_conf1-ism04.
**      l_last_ism05 = l_last_ism05 - wa_ord_conf1-ism05.
**      l_last_ism06 = l_last_ism06 - wa_ord_conf1-ism06.
**    ENDIF.
**    CLEAR : wa_ord_conf1.
**  ENDLOOP.
**
**  MOVE l_last_ism01 TO wa_ord_conf1-ism01.
**  MOVE l_last_ism02 TO wa_ord_conf1-ism02.
**  MOVE l_last_ism03 TO wa_ord_conf1-ism03.
**  MOVE l_last_ism04 TO wa_ord_conf1-ism04.
**  MOVE l_last_ism05 TO wa_ord_conf1-ism05.
**  MOVE l_last_ism06 TO wa_ord_conf1-ism06.
**
**
**ENDFORM.                    " get_confirmation_details
***&--------------------------------------------------------------------
***
***&      Form  activity_cost_report
***&--------------------------------------------------------------------
***
***       text
***---------------------------------------------------------------------
***
***      -->P_I_PLPO1_LAR01  text
***      -->P_I_ORD_CONF1_ISM01  text
***      -->P_struct_activity_ACTI1  text
***      -->P_ISM01_VAR  text
***---------------------------------------------------------------------
***
**FORM activity_cost_report USING fp_p_i_plpo1_lar01     TYPE lstar
**                                fp_p_i_ord_conf1_ism01 TYPE ru_ismng
**                             fp_p_struct_activity_acti1 TYPE co_smng13
**                                fp_p_ism01_var TYPE ru_ismng.
**  DATA: l_ltext TYPE ktext,
**        l_kokrs TYPE kokrs,
**        l_kostl TYPE kostl,
**        l_objnr TYPE j_objnr,
**        l_tkg001 TYPE tkgxxx,
**        l_tke001 TYPE tkexxx,
**        l_std(8) TYPE p DECIMALS 2,
**        l_act(8) TYPE p DECIMALS 2,
**        l_var(8) TYPE p DECIMALS 2.
**
**  SELECT ltext FROM  cslt INTO l_ltext
**     WHERE  spras       = sy-langu
**     AND    kokrs       = p_kokrs
**     AND    lstar       = fp_p_i_plpo1_lar01.
**  ENDSELECT.
**
**  IF sy-subrc = 0.
***Not required to handle
**  ENDIF.
**
**  IF rb_fiscl IS INITIAL.
**
**    CLEAR  wa_nodestab.
**    wa_nodestab-id     = c_3_1.
**    wa_nodestab-tlevel =  c_4.
**    wa_nodestab-parent = c_3_2.
**
**    wa_nodestab-text    = wa_ordops-vornr.
**    wa_nodestab-tlength = c_4.
**
**    wa_nodestab-text1    = l_ltext.
**    wa_nodestab-tlength1 = c_44.
**
**    MOVE fp_p_i_ord_conf1_ism01 TO wa_nodestab-text2(20).
**    wa_nodestab-tlength2 = c_20.
**
**    MOVE fp_p_struct_activity_acti1 TO wa_nodestab-text3(20).
**    wa_nodestab-tlength3 = c_20.
**
**    MOVE fp_p_ism01_var TO wa_nodestab-text4(20).
**    wa_nodestab-tlength4 = c_20.
**
**  ELSE.
**
**    SELECT kokrs kostl
**    FROM crco UP TO 1 ROWS
**    INTO (l_kokrs, l_kostl)
**    WHERE objty = c_a
**      AND objid = wa_ordops-arbid
**      AND lstar = fp_p_i_plpo1_lar01.
**    ENDSELECT.
**
**    IF sy-subrc = 0.
***Not required to handle
**    ENDIF.
**
**    SELECT SINGLE objnr INTO l_objnr
**    FROM cssl
**    WHERE kokrs = l_kokrs
**      AND kostl = l_kostl
**      AND lstar = fp_p_i_plpo1_lar01
**      AND gjahr = sy-datum+0(4).
**
**    IF sy-subrc = 0.
***Not required to handle
**    ENDIF.
**
**    SELECT tkg001 tke001 INTO (l_tkg001, l_tke001)
**    FROM cost
**    WHERE objnr = l_objnr
**      AND gjahr = sy-datum+0(4)
**      AND versn = c_000.
**    ENDSELECT.
**
**    IF sy-subrc = 0.
***Not required to handle
**    ENDIF.
**
**    CLEAR: l_act, l_std, l_var.
**** The following were changed to take into account the unit
**** price factor.
**    l_act = ( fp_p_i_ord_conf1_ism01 * l_tkg001 ) / l_tke001.
**    l_std = ( fp_p_struct_activity_acti1 * l_tkg001 ) / l_tke001.
**    l_var = ( fp_p_ism01_var * l_tkg001 ) / l_tke001.
**
**    CLEAR  wa_nodestab.
**    wa_nodestab-id     = c_3_1.
**    wa_nodestab-tlevel =  c_4.
**    wa_nodestab-parent = c_3_2.
**
**    wa_nodestab-text    = wa_ordops-vornr.
**    wa_nodestab-tlength = c_4.
**
**    wa_nodestab-text1    = l_ltext.
**    wa_nodestab-tlength1 = c_44.
**
**    MOVE l_act TO wa_nodestab-text2(20).
**    wa_nodestab-tlength2 = c_20.
**
**    MOVE l_std TO wa_nodestab-text3(20).
**    wa_nodestab-tlength3 = c_20.
**
**    MOVE l_var TO wa_nodestab-text4(20).
**    wa_nodestab-tlength4 = c_20.
**
**  ENDIF.
**
**  IF flg_color = c_x.
**    CLEAR flg_color.
**    wa_nodestab-tcolor  = c_3.
**    wa_nodestab-tcolor1 = c_3.
**    wa_nodestab-tcolor2 = c_3.
**    wa_nodestab-tcolor3 = c_3.
**    wa_nodestab-tcolor4 = c_3.
**  ELSE.
**    flg_color = c_x.
**    wa_nodestab-tcolor  = c_2.
**    wa_nodestab-tcolor1 = c_2.
**    wa_nodestab-tcolor2 = c_2.
**    wa_nodestab-tcolor3 = c_2.
**    wa_nodestab-tcolor4 = c_2.
**  ENDIF.
**
**  APPEND wa_nodestab TO i_nodestab.
**
**
**ENDFORM.                    " activity_cost_report
***&--------------------------------------------------------------------
**
***&      Form  uom_convert
***&--------------------------------------------------------------------
***
***       text
***---------------------------------------------------------------------
***
***      -->P_I_ORDMATS_MATNR  text
***      -->P_I_ORDMATS_MENGE  text
***      -->P_I_ORDMATS_AMEIN  text
***      -->P_L_AQTY  text
***---------------------------------------------------------------------
**** FORM uom_convert USING    fp_p_i_ordmats_matnr TYPE matnr
**                          fp_p_i_ordmats_menge TYPE menge_d
**                          fp_p_i_ordmats_amein TYPE meins
**                          fp_p_l_aqty          TYPE menge_d.
**
***Added for WIRR
**  DATA : struct_mara TYPE mara,
**         struct_t006 TYPE t006.
**  DATA: v_menge TYPE menge_d.
**
**  CONSTANTS : c_halb TYPE mtart VALUE 'HALB',
**              c_fert TYPE mtart VALUE 'FERT',
**              c_kgm  TYPE msehi VALUE 'KGM'.
**
******************************************
*** Need some clarification on this form *
******************************************
**
*** If the material is type FERT or HALB then use the net weight field
*** from the material master. Otherwise use the alt uom for KG.
**  SELECT SINGLE * FROM mara
***Added for WIRR
**   INTO struct_mara
***Added for WIRR
**
**   WHERE matnr = fp_p_i_ordmats_matnr.
**
**  IF ( struct_mara-mtart = c_fert
**             OR struct_mara-mtart = c_halb )
**     AND NOT ( struct_mara-ntgew IS INITIAL ).
***************MOD-002************************************************
*
***
**    CLEAR: v_menge.
**    IF struct_mara-gewei NE 'KG'.
**      IF struct_mara-gewei = 'G'.
**        CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
**          EXPORTING
**            i_matnr              = fp_p_i_ordmats_matnr
**            i_in_me              = fp_p_i_ordmats_amein
**            i_out_me             = struct_mara-meins
**            i_menge              = fp_p_i_ordmats_menge
**          IMPORTING
**            e_menge              = v_menge
**          EXCEPTIONS
**            error_in_application = 1
**            error                = 2
**            OTHERS               = 3.
**        IF sy-subrc = 0.
**          fp_p_l_aqty =
**              v_menge * ( struct_mara-ntgew / 1000 ).
**        ENDIF.
**      ENDIF.
**    ELSE.
**************MOD-002*************************************************
*
***
**************MOD-003*************************************************
*
**      IF struct_mara-meins NE fp_p_i_ordmats_amein.
**        CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
**          EXPORTING
**            i_matnr              = fp_p_i_ordmats_matnr
**            i_in_me              = fp_p_i_ordmats_amein
**            i_out_me             = struct_mara-meins
**            i_menge              = fp_p_i_ordmats_menge
**          IMPORTING
**            e_menge              = fp_p_i_ordmats_menge
**          EXCEPTIONS
**            error_in_application = 1
**            error                = 2
**            OTHERS               = 3.
**        IF sy-subrc = 0.
**          fp_p_l_aqty = fp_p_i_ordmats_menge * struct_mara-ntgew.
**        ENDIF.
**      ELSE.
**        fp_p_l_aqty = fp_p_i_ordmats_menge * struct_mara-ntgew.
**      ENDIF.
*************MOD-003**************************************************
*
**    ENDIF.
**  ELSE.
*** Get the isocode for kgm
**    SELECT SINGLE * FROM t006
**     INTO struct_t006
**     WHERE msehi = c_kgm.
**
**    IF fp_p_i_ordmats_amein = struct_t006-msehi.
**      MOVE fp_p_i_ordmats_menge TO fp_p_l_aqty.
**    ELSE.
**      CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'
**        EXPORTING
**          kzmeinh              = c_x
**          input                = fp_p_i_ordmats_menge
**          matnr                = fp_p_i_ordmats_matnr
**          meinh                = struct_t006-msehi
**        IMPORTING
**          output               = fp_p_l_aqty
**        EXCEPTIONS
**          conversion_not_found = 1
**          input_invalid        = 2
**          material_not_found   = 3
**          meinh_not_found      = 4
**          meins_missing        = 5
**          no_meinh             = 6
**          output_invalid       = 7
**          overflow             = 8
**          OTHERS               = 9.
**
*******************
**      IF sy-subrc NE 0.
**        fp_p_l_aqty = 0.
**      ENDIF.
**
**
*******************
**    ENDIF.
**  ENDIF.
**
**ENDFORM.                    " uom_convert
***&--------------------------------------------------------------------
***
***&      Form  STD_PERCENTAGE_CALC
***&--------------------------------------------------------------------
***
***       text
***---------------------------------------------------------------------
***
***      -->P_L_AQTY  text
***      -->P_L_SQTY  text
***      -->P_L_PCENT  text
***---------------------------------------------------------------------
***
**FORM std_percentage_calc USING    fp_l_aqty  TYPE menge_d
**                                  fp_l_sqty  TYPE menge_d
**                                  fp_l_pcent TYPE any.
**
**  CONSTANTS: c_percent_p TYPE stprs VALUE '999.99',
**             c_percent_n TYPE stprs VALUE '-999.99'.
**
**  DATA: l_tcent(10) TYPE p DECIMALS 5,
**        l_pecent(3) TYPE p DECIMALS 2.
**
**  CLEAR: l_tcent, l_pecent.
**  IF fp_l_aqty NE 0 AND fp_l_sqty NE 0.
**    l_tcent = ( ( fp_l_sqty - fp_l_aqty ) / fp_l_sqty ) * c_100.
**  ELSEIF fp_l_aqty EQ 0 AND fp_l_sqty EQ 0.
**    l_tcent = 0.
**  ELSE.
**    MOVE c_100 TO l_tcent.
**  ENDIF.
**  IF l_tcent GT c_percent_p.
**    MOVE c_percent_p TO l_pecent.
**  ELSEIF l_tcent LT c_percent_n.
**    MOVE c_percent_n TO l_pecent.
**  ELSE.
**    MOVE l_tcent TO l_pecent.
**  ENDIF.
**** Add a calculation to convert by-product percentages to the correct
**** sign.
**  IF fp_l_sqty < 0.
**    l_pecent = l_pecent * -1.
**  ENDIF.
**  fp_l_pcent = l_pecent.
**
**ENDFORM.                    " STD_PERCENTAGE_CALC
**
***&--------------------------------------------------------------------
***
***&      Form  DISPLAY
***&--------------------------------------------------------------------
***
***       text
***---------------------------------------------------------------------
***
***---------------------------------------------------------------------
***
**FORM display.
**
**  CASE c_x.
**    WHEN rb_summ.
**      PERFORM display_summary_report.
**    WHEN rb_detl.
**      PERFORM display_detail_report.
**    WHEN rb_phase.
**      PERFORM display_phase_report.
**  ENDCASE.
**  PERFORM list_display.
**
**ENDFORM.                    " DISPLAY
***&--------------------------------------------------------------------
***
***&      Form  plant_effic
***&--------------------------------------------------------------------
***
***       text
***---------------------------------------------------------------------
***
***      -->P_I_PRO_ORDERS_RUECK  text
***      -->P_I_PRO_ORDERS_PLNTY  text
***      -->P_I_PRO_ORDERS_PLNNR  text
***      -->P_I_PRO_ORDERS_PLNKN  text
***      -->P_I_PRO_ORDERS_ZAEHL  text
***      <--P_V_plant_effic  text
***---------------------------------------------------------------------
***
**FORM plant_effic USING    fp_p_plnty          TYPE plnty
**                          fp_p_plnnr          TYPE plnnr
**                          fp_p_plnkn          TYPE plnkn
**                          fp_p_zaehl          TYPE cim_count
**                 CHANGING fp_v_plant_effic    TYPE any.
**
**  FIELD-SYMBOLS: <fs_ism> TYPE ANY,
**                 <fs_vgw> TYPE ANY.
**
**  DATA:  l_last_ism01 TYPE ru_ismng,
**         l_last_ism02 TYPE ru_ismng,
**         l_last_ism03 TYPE ru_ismng,
**         l_last_ism04 TYPE ru_ismng,
**         l_last_ism05 TYPE ru_ismng,
**         l_last_ism06 TYPE ru_ismng,
**         l_pqty       TYPE menge_d,
**         l_real_effic(8)   TYPE p DECIMALS 4,
**         l_should_effic(8) TYPE p DECIMALS 4.
**
**  PERFORM get_stds_main USING fp_p_plnty fp_p_plnnr fp_p_plnkn
**                              fp_p_zaehl.
**
**
**  LOOP AT i_ord_conf INTO wa_ord_conf
**          WHERE rueck = wa_ordops-rueck.
**    IF wa_ord_conf1-stokz IS INITIAL.
**      l_last_ism01 = l_last_ism01 + wa_ord_conf-ism01.
**      l_last_ism02 = l_last_ism02 + wa_ord_conf-ism02.
**      l_last_ism03 = l_last_ism03 + wa_ord_conf-ism03.
**      l_last_ism04 = l_last_ism04 + wa_ord_conf-ism04.
**      l_last_ism05 = l_last_ism05 + wa_ord_conf-ism05.
**      l_last_ism06 = l_last_ism06 + wa_ord_conf-ism06.
**    ELSE.
**      l_last_ism01 = l_last_ism01 - wa_ord_conf-ism01.
**      l_last_ism02 = l_last_ism02 - wa_ord_conf-ism02.
**      l_last_ism03 = l_last_ism03 - wa_ord_conf-ism03.
**      l_last_ism04 = l_last_ism04 - wa_ord_conf-ism04.
**      l_last_ism05 = l_last_ism05 - wa_ord_conf-ism05.
**      l_last_ism06 = l_last_ism06 - wa_ord_conf-ism06.
**    ENDIF.
**
**    CLEAR : wa_ord_conf.
**  ENDLOOP.
**
**  MOVE l_last_ism01 TO wa_ord_conf-ism01.
**  MOVE l_last_ism02 TO wa_ord_conf-ism02.
**  MOVE l_last_ism03 TO wa_ord_conf-ism03.
**  MOVE l_last_ism04 TO wa_ord_conf-ism04.
**  MOVE l_last_ism05 TO wa_ord_conf-ism05.
**  MOVE l_last_ism06 TO wa_ord_conf-ism06.
**
**  ASSIGN c_0 TO <fs_ism>.
**  ASSIGN c_0 TO <fs_vgw>.
**
**  IF wa_plpo-lar01 EQ p_machs.
**    ASSIGN wa_ord_conf-ism01 TO <fs_ism>.
**    ASSIGN wa_plpo-vgw01 TO <fs_vgw>.
**  ENDIF.
**  IF wa_plpo-lar02 EQ p_machs.
**    ASSIGN wa_ord_conf-ism02 TO <fs_ism>.
**    ASSIGN wa_plpo-vgw02 TO <fs_vgw>.
**  ENDIF.
**  IF wa_plpo-lar03 EQ p_machs.
**    ASSIGN wa_ord_conf-ism03 TO <fs_ism>.
**    ASSIGN wa_plpo-vgw03 TO <fs_vgw>.
**  ENDIF.
**  IF wa_plpo-lar04 EQ p_machs.
**    ASSIGN wa_ord_conf-ism04 TO <fs_ism>.
**    ASSIGN wa_plpo-vgw04 TO <fs_vgw>.
**  ENDIF.
**  IF wa_plpo-lar05 EQ p_machs.
**    ASSIGN wa_ord_conf-ism05 TO <fs_ism>.
**    ASSIGN wa_plpo-vgw05 TO <fs_vgw>.
**  ENDIF.
**  IF wa_plpo-lar06 EQ p_machs.
**    ASSIGN wa_ord_conf-ism06 TO <fs_ism>.
**    ASSIGN wa_plpo-vgw06 TO <fs_vgw>.
**  ENDIF.
**
**  CLEAR l_pqty.
**  IF NOT ( rb_prod IS INITIAL ).
**    l_pqty = wa_pro_orders-menge.
**  ELSE.
**    l_pqty = wa_pro_orders-lmnga.
**  ENDIF.
**
**  IF <fs_ism> GT c_0.
***  IF NOT <FS_ISM> IS INITIAL.
**    l_real_effic = ( l_pqty / <fs_ism> ).
**  ELSE.
**    MOVE 0 TO l_real_effic.
**  ENDIF.
**  IF <fs_vgw> GT c_0.
***  IF NOT <FS_VGW> IS INITIAL.
**    l_should_effic = ( wa_plpo-bmsch / <fs_vgw> ).
**  ELSE.
**    MOVE 0 TO l_should_effic.
**  ENDIF.
**  IF l_should_effic GT c_0.
**    v_plant_effic = ( l_real_effic / l_should_effic ) * c_100.
**  ELSE.
**    MOVE 0 TO fp_v_plant_effic.
**  ENDIF.
**
**ENDFORM.                    " plant_effic
***&--------------------------------------------------------------------
***
***&      Form  get_stds_main
***&--------------------------------------------------------------------
***
***       text
***---------------------------------------------------------------------
***
***      -->P_PLNTY  text
***      -->P_PLNNR  text
***      -->P_PLNKN  text
***      -->P_ZAEHL  text
***---------------------------------------------------------------------
***
**FORM get_stds_main USING    fp_p_plnty TYPE plnty
**                            fp_p_plnnr TYPE plnnr
**                            fp_p_plnkn TYPE plnkn
**                            fp_p_zaehl TYPE cim_count.
**  TYPES:   BEGIN OF ty_crco_info,
**    objty     TYPE cr_objty,
**    objid     TYPE cr_objid,
**    laset     TYPE cr_laset,
**    endda     TYPE enddatum,
**    lanum     TYPE cr_lanum,
**    begda     TYPE begdatum,
**    lstar_ref TYPE ap_kzref,
**    lstar     TYPE lstar,
**  END OF ty_crco_info.
**
**  DATA : i_crco_info TYPE STANDARD TABLE OF ty_crco_info,
**         wa_crco_info TYPE ty_crco_info.
**  DATA: l_wcinfo TYPE c,
**        l_datuv TYPE plpo-datuv,
**        lc_objty TYPE plpo-objty VALUE 'A'.
**
**  READ TABLE i_plpo INTO wa_plpo WITH KEY plnty = fp_p_plnty
**                             plnnr = fp_p_plnnr
**                             plnkn = fp_p_plnkn
**                             zaehl = fp_p_zaehl.
**  IF sy-subrc = 0.
**
**    IF ( wa_plpo-lar01 IS INITIAL AND NOT ( wa_plpo-vgw01 = 0 ) ) OR
**       ( wa_plpo-lar02 IS INITIAL AND NOT ( wa_plpo-vgw02 = 0 ) ) OR
**       ( wa_plpo-lar03 IS INITIAL AND NOT ( wa_plpo-vgw03 = 0 ) ) OR
**       ( wa_plpo-lar04 IS INITIAL AND NOT ( wa_plpo-vgw04 = 0 ) ) OR
**       ( wa_plpo-lar05 IS INITIAL AND NOT ( wa_plpo-vgw05 = 0 ) ) OR
**       ( wa_plpo-lar06 IS INITIAL AND NOT ( wa_plpo-vgw06 = 0 ) ).
**      REFRESH: i_crco_info.
*** Check the work centre is on the phase, if not go to the operation
**      IF wa_plpo-arbid IS INITIAL.
**        SELECT datuv arbid objty
**          INTO (l_datuv,wa_plpo-arbid,wa_plpo-objty)
**          FROM plpo
**         WHERE plnty = fp_p_plnty
**           AND plnnr = fp_p_plnnr
**           AND plnkn = wa_plpo-pvzkn
**           AND datuv <= sy-datum
**          ORDER BY datuv DESCENDING.
**          EXIT.
**        ENDSELECT.
**
**        IF sy-subrc = 0.
***Not required to handle
**        ENDIF.
**
**      ENDIF.
*** Default to work centre object if it's blank
**      IF wa_plpo-objty IS INITIAL.
**        wa_plpo-objty = lc_objty.
**      ENDIF.
*** Get the work centre activity info
**      SELECT objty objid laset endda lanum begda lstar_ref lstar
**      INTO TABLE i_crco_info
**        FROM crco
**       WHERE objty = wa_plpo-objty
**         AND objid = wa_plpo-arbid
**         AND laset = 1.
***     order by primary key.
**
**      IF sy-subrc = 0.
***Not required to handle
**      ENDIF.
**
**      l_wcinfo = c_y.
**    ENDIF.
**    IF l_wcinfo = c_y.
*** Use work centre info.
**      LOOP AT i_crco_info INTO wa_crco_info
**         WHERE begda <= wa_plpo-datuv AND
**               endda >= wa_plpo-datuv.
**        CHECK NOT wa_crco_info-lstar_ref IS INITIAL.
**        CASE wa_crco_info-lanum.
*** Only put the activity type in if there is a std value entered
**          WHEN 1.
**            IF wa_plpo-vgw01 NE 0.
**              wa_plpo-lar01 = wa_crco_info-lstar.
**            ENDIF.
**          WHEN 2.
**            IF wa_plpo-vgw02 NE 0.
**              wa_plpo-lar02 = wa_crco_info-lstar.
**            ENDIF.
**          WHEN 3.
**            IF wa_plpo-vgw03 NE 0.
**              wa_plpo-lar03 = wa_crco_info-lstar.
**            ENDIF.
**          WHEN 4.
**            IF wa_plpo-vgw04 NE 0.
**              wa_plpo-lar04 = wa_crco_info-lstar.
**            ENDIF.
**          WHEN 5.
**            IF wa_plpo-vgw05 NE 0.
**              wa_plpo-lar05 = wa_crco_info-lstar.
**            ENDIF.
**          WHEN 6.
**            IF wa_plpo-vgw06 NE 0.
**              wa_plpo-lar06 = wa_crco_info-lstar.
**            ENDIF.
**        ENDCASE.
**      ENDLOOP.
**    ENDIF.
**
**  ENDIF.
**
**ENDFORM.                    " get_stds_main
***&--------------------------------------------------------------------
***
***&      Form  get_confirmation_qty
***&--------------------------------------------------------------------
***
***       text
***---------------------------------------------------------------------
**
***      -->P_I_ORDOPS_RUECK  text
***      -->P_I_PRO_ORDERS_PLNBEZ  text
***      -->P_L_PRDQTY  text
***      -->P_L_CFUOM  text
***---------------------------------------------------------------------
***
**FORM get_confirmation_qty USING    fp_p_i_ordops_rueck TYPE co_rueck
**                                   fp_p_l_prdqty       TYPE menge_d
**                                   fp_p_l_cfuom        TYPE meins.
**  DATA: l_lmnga TYPE ru_lmnga,
**        l_gmnga TYPE ru_gmnga.
**
************MOD-002**************************************
**  SELECT aufnr rueck gmnga lmnga gmein meinh
**      meilr stokz rueck_mst
**  FROM afru INTO TABLE itab_afru
**  FOR ALL ENTRIES IN i_pro_orders
**  WHERE aufnr = i_pro_orders-aufnr.
**
**  SORT itab_afru BY aufnr rueck .
************MOD-002***************************************
**  IF NOT itab_afru[] IS INITIAL.
**    CLEAR: l_lmnga, l_gmnga.
**    LOOP AT itab_afru INTO wa_afru WHERE rueck = fp_p_i_ordops_rueck.
***       IF  ( wa_afru-rueck_mst IS INITIAL ) AND
***            ( wa_afru-lmnga NE 0           ) AND
***        NOT ( wa_afru-meilr IS INITIAL     ).
**      IF wa_afru-stokz IS INITIAL.
**        l_lmnga = l_lmnga + wa_afru-lmnga.
**        l_gmnga = l_gmnga + wa_afru-gmnga.
**      ELSE.
**        l_lmnga = l_lmnga - wa_afru-lmnga.
**        l_gmnga = l_gmnga - wa_afru-gmnga.
**      ENDIF.
***        ENDIF.
**    ENDLOOP.
**    IF wa_afru-meinh NE wa_afru-gmein.
**      fp_p_l_prdqty = l_lmnga.
**      fp_p_l_cfuom  = wa_afru-gmein.
**    ELSE.
**      fp_p_l_prdqty = l_gmnga.
**      fp_p_l_cfuom  = wa_afru-meinh.
**    ENDIF.
**  ENDIF.
**ENDFORM.                    " get_confirmation_qty
***&--------------------------------------------------------------------
***
***&      Form  MATERIAL_HEADER
***&--------------------------------------------------------------------
***
***       text
***---------------------------------------------------------------------
***
***  -->  p1        text
***  <--  p2        text
***---------------------------------------------------------------------
***
**FORM material_header.
**
**  wa_nodestab-text    = 'Material'(058).
**  wa_nodestab-tlength = c_22.
**  wa_nodestab-tcolor  = c_4.
**  wa_nodestab-propfaw = c_x.
**
**  wa_nodestab-text1    = 'Description'(059).
**  wa_nodestab-tlength1 = c_30.
**  wa_nodestab-tcolor1  = c_4.
**
**  IF rb_fiscl = c_x.
**    CONCATENATE 'Actual Usage'(040) v_waers
**    INTO wa_nodestab-text2 SEPARATED BY space.
**  ELSE.
**    wa_nodestab-text2  = 'Actual Usage'(040).
**  ENDIF.
**  wa_nodestab-tlength2 = c_20.
**  wa_nodestab-tcolor2  = c_4.
**
**  IF rb_fiscl = c_x.
**    CONCATENATE 'Standard Usage'(041) v_waers
**    INTO wa_nodestab-text3 SEPARATED BY space.
**  ELSE.
**    wa_nodestab-text3  = 'Standard Usage'(041).
**  ENDIF.
**  wa_nodestab-tlength3 = c_20.
**  wa_nodestab-tcolor3  = c_4.
**
**  wa_nodestab-text4    = 'Var'(060).
**  wa_nodestab-tlength4 = c_19.
**  wa_nodestab-tcolor4  = c_4.
**
***  IF rb_fiscl = c_x.
**  CONCATENATE 'Variance'(061) v_waers
**  INTO wa_nodestab-text5 SEPARATED BY space.
***  ELSE.
***    wa_nodestab-text5  = 'Variance'(061).
***  ENDIF.
**  wa_nodestab-tlength5 = c_15.
**  wa_nodestab-tcolor5  = c_4.
**
**  APPEND wa_nodestab TO i_nodestab.
**  CLEAR : wa_nodestab.
**ENDFORM.                    " MATERIAL_HEADER
***&--------------------------------------------------------------------
***
***&      Form  sum_activity_costs
***&--------------------------------------------------------------------
***
***       text
***---------------------------------------------------------------------
***
***      -->P_I_PLPO1_LAR01  text
***      -->P_I_ORD_CONF1_ISM01  text
***      -->P_struct_activity_ACTI1  text
***      -->P_ISM01_VAR  text
***---------------------------------------------------------------------
***
**FORM sum_activity_costs USING  fp_p_i_plpo1_lar01         TYPE lstar
**                  fp_p_i_ord_conf1_ism01     TYPE  ru_ismng
**fp_p_struct_activity_acti1 TYPE co_smng13
**fp_p_ism01_var             TYPE ru_ismng.
**  DATA: l_kokrs TYPE kokrs,
**        l_kostl TYPE kostl,
**        l_objnr TYPE j_objnr,
**        l_tkg001 TYPE tkgxxx,
**        l_tke001 TYPE tkexxx,
**        l_std(8) TYPE p DECIMALS 2,
**        l_act(8) TYPE p DECIMALS 2,
**        l_var(8) TYPE p DECIMALS 2.
**
**  SELECT kokrs kostl
**  FROM crco UP TO 1 ROWS
**  INTO (l_kokrs, l_kostl)
**  WHERE objty = c_objtyp
**    AND objid = wa_ordops-arbid
**    AND lstar = fp_p_i_plpo1_lar01.
**  ENDSELECT.
**
**  IF sy-subrc = 0.
***Not required to handle
**  ENDIF.
**
**  SELECT SINGLE objnr INTO l_objnr
**  FROM cssl
**  WHERE kokrs = l_kokrs
**    AND kostl = l_kostl
**    AND lstar = fp_p_i_plpo1_lar01
**    AND gjahr = sy-datum+0(4).
**
**  IF sy-subrc = 0.
***Not required to handle
**  ENDIF.
**
**  SELECT tkg001 tke001 INTO (l_tkg001, l_tke001)
**  FROM cost
**  WHERE objnr = l_objnr
**    AND gjahr = sy-datum+0(4)
**    AND versn = c_000.
**  ENDSELECT.
**
**  IF sy-subrc = 0.
***Not required to handle
**  ENDIF.
**
**  CLEAR: l_act, l_std, l_var.
**  l_act = ( fp_p_i_ord_conf1_ism01 * l_tkg001 ) / l_tke001.
**  l_std = ( fp_p_struct_activity_acti1 * l_tkg001 ) / l_tke001.
**  l_var = ( fp_p_ism01_var * l_tkg001 ) / l_tke001.
**
**  CLEAR wa_sum_activity.
**
**  LOOP AT i_sum_activity INTO wa_sum_activity
**        WHERE lar = fp_p_i_plpo1_lar01.
**    wa_sum_activity-afru_ism = wa_sum_activity-afru_ism
**                            + fp_p_i_ord_conf1_ism01.
**    wa_sum_activity-ism_should = wa_sum_activity-ism_should
**                              + fp_p_struct_activity_acti1.
**    wa_sum_activity-ism_var = wa_sum_activity-ism_var
**                           + fp_p_ism01_var.
**    wa_sum_activity-coact = wa_sum_activity-coact + l_act.
**    wa_sum_activity-costd = wa_sum_activity-costd + l_std.
**    wa_sum_activity-covar = wa_sum_activity-covar + l_var.
**    MODIFY i_sum_activity FROM wa_sum_activity.
**    CLEAR : wa_sum_activity.
**  ENDLOOP.
**
**  IF sy-subrc NE 0.
**    MOVE fp_p_i_plpo1_lar01      TO wa_sum_activity-lar.
**    MOVE fp_p_i_ord_conf1_ism01  TO wa_sum_activity-afru_ism.
**    MOVE fp_p_struct_activity_acti1 TO wa_sum_activity-ism_should.
**    MOVE fp_p_ism01_var          TO wa_sum_activity-ism_var.
**    wa_sum_activity-coact = l_act.
**    wa_sum_activity-costd = l_std.
**    wa_sum_activity-covar = l_var.
**    APPEND wa_sum_activity TO i_sum_activity.
**    CLEAR : wa_sum_activity.
**  ENDIF.
**
**ENDFORM.                    " sum_activity_costs
***&--------------------------------------------------------------------
***
***&      Form  SUMMARY_MATERIALS
***&--------------------------------------------------------------------
***
***       text
***---------------------------------------------------------------------
***
***---------------------------------------------------------------------
***
**FORM summary_materials.
**
*** Sum Ingredient Tots
**  CLEAR wa_sum_ordmats.
**  LOOP AT i_sum_ordmats INTO wa_sum_ordmats
**          WHERE matnr = wa_ordmats-matnr.
**    wa_sum_ordmats-num    = wa_sum_ordmats-num + c_1.
**    wa_sum_ordmats-menge  = wa_sum_ordmats-menge + wa_ordmats-menge.
**    wa_sum_ordmats-stdqy   = wa_sum_ordmats-stdqy + wa_ordmats-stdqy.
**    wa_sum_ordmats-zloss  = wa_sum_ordmats-zloss + wa_ordmats-zloss.
**    wa_sum_ordmats-amein  = wa_ordmats-amein.
**    wa_sum_ordmats-meins  = wa_ordmats-meins.
**    wa_sum_ordmats-stprs  = wa_ordmats-stprs.
**    wa_sum_ordmats-peinh  = wa_ordmats-peinh.
**    MODIFY i_sum_ordmats FROM wa_sum_ordmats.
**    CLEAR : wa_sum_ordmats.
**  ENDLOOP.
**  IF sy-subrc NE 0.
**    MOVE wa_ordmats-matnr TO wa_sum_ordmats-matnr.
**    MOVE 1               TO wa_sum_ordmats-num.
**    MOVE wa_ordmats-menge TO wa_sum_ordmats-menge.
**    MOVE wa_ordmats-stdqy TO wa_sum_ordmats-stdqy.
**    MOVE wa_ordmats-zloss TO wa_sum_ordmats-zloss.
**    wa_sum_ordmats-amein  = wa_ordmats-amein.
**    wa_sum_ordmats-meins  = wa_ordmats-meins.
**    wa_sum_ordmats-stprs  = wa_ordmats-stprs.
**    wa_sum_ordmats-peinh  = wa_ordmats-peinh.
**    APPEND wa_sum_ordmats TO i_sum_ordmats.
**    CLEAR : wa_sum_ordmats.
**  ENDIF.
**
**ENDFORM.                    " SUMMARY_MATERIALS
***&--------------------------------------------------------------------
***
***&      Form  get_confirmation_qty_new
***&--------------------------------------------------------------------
***
***       text
***---------------------------------------------------------------------
***
***      -->P_WA_PRO_ORDERS_RUECK  text
***      -->P_WA_PRO_ORDERS_PLNBEZ  text
***      -->P_WA_PRO_ORDERS_LMNGA  text
***      -->P_WA_PRO_ORDERS_CFUOM  text
***---------------------------------------------------------------------
***
**FORM get_confirmation_qty_new USING p_lmnga TYPE ru_lmnga
**                                    p_cfuom TYPE meins.
**
*****************************************************
***USING
***                  P_RUECK TYPE CO_RUECK
***                  p_aufnr type aufnr
***                  P_LMNGA TYPE RU_LMNGA
***                  P_CFUOM TYPE MEINS
***                  p_aufpl type CO_AUFPL
***                  p_vornr type vornr
***                  p_aplzl type CO_APLZL.
*****************************************************
**  DATA: last_lmnga LIKE afru-lmnga,
**        last_gmnga TYPE afru-gmnga.
**
**  CLEAR: last_lmnga, last_gmnga.
**  CLEAR:i_afru, wa_afru.
**
**
**
**
*** Check this record. If there is no link to another confirmation and
***     a quantity has been confirmed and it is a milestone
**      confirmation
***               then we want to select all of the confirmations for .
**  LOOP AT i_afru1 INTO wa_afru1.
***                   check WA_afru-rueck_mst is initial.
**    CHECK wa_afru1-lmnga NE 0.
***                    check not ( WA_afru-meilr is initial ).
**    IF wa_afru1-stokz IS INITIAL.
**      last_lmnga = last_lmnga + wa_afru1-lmnga.
**      last_gmnga = last_gmnga + wa_afru1-gmnga.
**    ELSE.
**      last_lmnga = last_lmnga - wa_afru1-lmnga.
**      last_gmnga = last_gmnga - wa_afru1-gmnga.
**    ENDIF.
**  ENDLOOP.
**
***  use order unit quantity if necessary
**  IF wa_afru1-meinh NE wa_afru1-gmein.
***  afru-gmein is order unit of measure
**    MOVE last_gmnga TO p_lmnga.
**    p_cfuom = wa_afru1-gmein.
**  ELSE.
***  use normal quantity
**    MOVE last_lmnga TO p_lmnga.
**    p_cfuom = wa_afru1-meinh.
**  ENDIF.
**
**ENDFORM.                    " get_confirmation_qty_new
*****
***** END OF MOD-101
*****
*
**&---------------------------------------------------------------------
*
**&      Form  USER_COMMNAD
**&---------------------------------------------------------------------
*
**       text
**----------------------------------------------------------------------
*
*FORM user_command TABLES fp_i_nodestab     STRUCTURE snodetext"#EC *
*                   USING fp_l_ucomm        TYPE any
*                CHANGING fp_l_exit         TYPE any
*                         fp_l_list_refresh TYPE any.        "#EC *
*
*  DATA : v_aufnr   TYPE aufnr,
*         l_arbpl   TYPE arbpl,                              "MOD-101+
*         l_txt(14) TYPE c.                                  "MOD-101+
*
*  DATA: PROGNAME          LIKE SY-REPID,
*        SELECTED          TYPE C,
*        EXIT_SAV          TYPE C,
*        LIST_REFRESH_SAV  TYPE C.
*
*
*  fp_l_list_refresh = c_m.
*
*  CASE fp_l_ucomm.
****
**** BEGIN OF MOD-101
****
*    WHEN c_trpi.
*      CLEAR : v_aufnr , l_txt.
*      GET CURSOR FIELD fp_i_nodestab-text1 VALUE l_txt.
*
*      IF fp_i_nodestab-text1  = c_text1 AND NOT l_txt IS INITIAL.
*        CASE fp_i_nodestab-tlevel.
*          WHEN c_tlevel_2.
*            v_aufnr = l_txt(12).
*            SUBMIT zprocessord WITH s_aufnr-low = v_aufnr
*            AND RETURN.
**           SUBMIT zprocessord WITH p_aufnr = v_aufnr
**           AND RETURN.
*
*          WHEN c_tlevel_3.
*            l_arbpl = l_txt(8).
*
*            SET PARAMETER ID 'WRK' FIELD p_werks.
*            SET PARAMETER ID 'AGR' FIELD l_arbpl.
*
*            CALL TRANSACTION 'CRC3' AND SKIP FIRST SCREEN.
*          WHEN c_tlevel_4.
*            l_arbpl = l_txt+6(8).
*
*            SET PARAMETER ID 'WRK' FIELD p_werks.
*            SET PARAMETER ID 'AGR' FIELD l_arbpl.
*
*            CALL TRANSACTION 'CRC3' AND SKIP FIRST SCREEN.
*        ENDCASE.
*
*      ELSEIF fp_i_nodestab-text1 <> c_plus AND fp_i_nodestab-text1 <>
*      c_minus AND
*             sy-title <> 'Process Order Variance - Summary Report'(069)
.
**Please select order number!
*        MESSAGE s063.
*      ENDIF.
*
**** TRSL
**      CLEAR : v_aufnr , l_txt.
**      GET CURSOR FIELD fp_i_nodestab-text1 VALUE l_txt.
**      IF fp_i_nodestab-text1  = c_text1 AND NOT l_txt IS INITIAL.
**      CASE fp_i_nodestab-tlevel.
**          WHEN c_tlevel_2.
**            v_aufnr = l_txt.
**            call function 'RS_TREE_EXPAND'
**                 exporting
**                      node_id     = nodelist-id
**                      list_scroll = 'X'
**                 exceptions
**                      others.
**          WHEN c_tlevel_3.
**            l_arbpl = l_txt(8).
**            call function 'RS_TREE_EXPAND'
**                 exporting
**                      node_id     = nodelist-id
**                      list_scroll = 'X'
**                 exceptions
**                      others.
**
**          WHEN c_tlevel_4.
**            l_arbpl = l_txt+5(8).
**             call function 'RS_TREE_EXPAND'
**                 exporting
**                      node_id     = nodelist-id
**                      list_scroll = 'X'
**                 exceptions
**                      others.
**
**       ENDCASE.
**
**      when 'NODE'.
**          if selname = 'MINUS' or selname = 'MINUSLINE'.
**            call function 'RS_TREE_COMPRESS'
**                 exporting
**                      node_id = nodelist-id
**                 exceptions
**                      others.
**          elseif selname = 'PLUS' or selname = 'PLUSLINE'.
**            call function 'RS_TREE_EXPAND'
**                 exporting
**                      node_id     = nodelist-id
**                      list_scroll = 'X'
**                 exceptions
**                      others.
**          else.
**            perform uc_prepare_nodetab.
**            perform uc_user_callback.
**            if exit ne space.
**              exit_from_screen.
**            endif.
**          endif.
**      ENDCASE.
**
**      ELSEIF fp_i_nodestab-text1 <> c_plus AND fp_i_nodestab-text1 <>
**      c_minus AND
**      sy-title <> 'Process Order Variance - Summary Report'(069).
***Please select order number!
**        MESSAGE s063.
**      ENDIF.
*
*    WHEN c_trde.
*      CLEAR : v_aufnr , l_txt.
*      GET CURSOR FIELD fp_i_nodestab-text1 VALUE l_txt.
*
*      IF fp_i_nodestab-text1 = c_text1 AND NOT l_txt IS INITIAL.
*        CASE fp_i_nodestab-tlevel.
*          WHEN c_tlevel_2.
*            v_aufnr = l_txt(12).
**           SUBMIT zprocessord WITH p_aufnr = v_aufnr
**           AND RETURN.
*            SUBMIT zprocessord WITH s_aufnr-low = v_aufnr
*            AND RETURN.
*
*          WHEN c_tlevel_3.
*            l_arbpl = l_txt(8).
*
*            SET PARAMETER ID 'WRK' FIELD p_werks.
*            SET PARAMETER ID 'AGR' FIELD l_arbpl.
*
*            CALL TRANSACTION 'CRC3' AND SKIP FIRST SCREEN.
*          WHEN c_tlevel_4.
*            l_arbpl = l_txt+5(8).
*
*            SET PARAMETER ID 'WRK' FIELD p_werks.
*            SET PARAMETER ID 'AGR' FIELD l_arbpl.
*
*            CALL TRANSACTION 'CRC3' AND SKIP FIRST SCREEN.
*        ENDCASE.
*
*      ELSEIF fp_i_nodestab-text1 <> c_plus AND fp_i_nodestab-text1 <>
*      c_minus.
**Please select order number!
*        MESSAGE s063.
*      ENDIF.
*
*    WHEN c_trpi.
*      CLEAR : v_aufnr , l_txt.
*      GET CURSOR FIELD fp_i_nodestab-text1 VALUE l_txt.
*
*      CLEAR v_aufnr.
*      GET CURSOR FIELD fp_i_nodestab-text1 VALUE v_aufnr.
*
*      IF fp_i_nodestab-text1 = c_text1 "'NODELIST-TEXT1'
*          AND NOT v_aufnr IS INITIAL
*          AND fp_i_nodestab-tlevel = c_tlevel_2.
*        SUBMIT /eur/rgbptr_order_vari_detail
*        WITH p_aufnr = v_aufnr AND RETURN.
*      ELSEIF fp_i_nodestab-text1 <> c_plus
*        AND fp_i_nodestab-text1 <> c_minus
*        AND sy-title <> 'Process Order Variance - Summary Report'(069).
**Please select order number!
*        MESSAGE s063.
*      ENDIF.
*
*    WHEN c_trde.
*      CLEAR v_aufnr.
*      GET CURSOR FIELD fp_i_nodestab-text1 VALUE v_aufnr.
*      IF fp_i_nodestab-text1 = c_text1  "'NODELIST-TEXT1'
*          AND NOT v_aufnr IS INITIAL
*          AND fp_i_nodestab-tlevel = c_tlevel_2.
*        SUBMIT /eur/rgbptr_order_vari_detail
*        WITH p_aufnr = v_aufnr AND RETURN.
*      ELSEIF fp_i_nodestab-text1 <> c_plus
*        AND fp_i_nodestab-text1 <> c_minus.
**Please select order number!
*        MESSAGE s063.
*      ENDIF.
*
*    WHEN c_detl.
*      CLEAR: rb_summ, rb_phase.
*      rb_detl = c_x.
*      PERFORM output.
*
*    WHEN c_phas.
*      CLEAR: rb_detl, rb_summ.
*      rb_phase = c_x.
*      PERFORM output.
*
****
**** END OF MOD-101
****
*    WHEN c_sums.
*      CLEAR: rb_detl, rb_phase.
*      rb_summ = c_x.
**      fp_l_exit = c_x.  "MOD-101-
**      PERFORM display.  "MOD-101-
*      PERFORM output.                                       "MOD-101+
*
*    WHEN c_qty.
** Display quantities
*      rb_quant = c_x.
*      rb_fiscl = space.
*
**      fp_l_exit = c_x.  "MOD-101-
**      PERFORM display.  "MOD-101-
*      PERFORM output.                                       "MOD-101+
*
*    WHEN c_fisc.
** Display fiscal values
*      rb_quant = space.
*      rb_fiscl = c_x.
*
**      fp_l_exit = c_x.  "MOD-101-
**      PERFORM display.  "MOD-101-
*      PERFORM output.                                       "MOD-101+
*
*    WHEN c_kgm.
** Display in KGMs
*      rb_order = space.
*      rb_kgm = c_x.
*
**      fp_l_exit = c_x.  "MOD-101-
**      PERFORM display.  "MOD-101-
*      PERFORM output.                                       "MOD-101+
*
*    WHEN c_ordu.
** Display order units
*      rb_kgm = space.
*      rb_order = c_x.
*
**      fp_l_exit = c_x.  "MOD-101-
**      PERFORM display.  "MOD-101-
*      PERFORM output.                                       "MOD-101+
*
*    WHEN c_zero.
** Display zero loss values
*      rb_stdpl = space.
*      rb_zloss = c_x.
*
**      fp_l_exit = c_x.  "MOD-101-
**      PERFORM display.  "MOD-101-
*      PERFORM output.                                       "MOD-101+
*
*    WHEN c_std.
** Display standard recipe values
*      rb_zloss = space.
*      rb_stdpl = c_x.
*
**      fp_l_exit = c_x.  "MOD-101-
**      PERFORM display.  "MOD-101-
*      PERFORM output.                                       "MOD-101+
*
*    WHEN c_trep.
*      IF fp_i_nodestab-child IS INITIAL.
**Invalid row selected!
*        MESSAGE s064.
*      ENDIF.
*
*    WHEN c_trcm.
*      IF fp_i_nodestab-child IS INITIAL.
**Invalid row selected!
*        MESSAGE s064.
*      ENDIF.
*
*    WHEN 'AUAN'.
*            SET PARAMETER ID 'ANR' FIELD s_aufnr.
*            CALL TRANSACTION 'COR3' AND SKIP FIRST SCREEN.
*    WHEN 'AUAE'.
*            SET PARAMETER ID 'ANR' FIELD s_aufnr.
*            CALL TRANSACTION 'COR2' AND SKIP FIRST SCREEN.
*    WHEN c_exit.
*      LEAVE PROGRAM.
*  ENDCASE.
*
***"BEGIN OF MOD-101
**  IF sy-ucomm = c_back AND fp_l_ucomm = c_sums.
**    CLEAR: rb_summ, rb_phase.
**    rb_detl = c_x.
**    fp_l_list_refresh = c_m.
**    PERFORM list_display.
**    fp_l_exit = c_x.
**  ENDIF.
***"END OF MOD-101
*ENDFORM.                    "user_command
*
**&---------------------------------------------------------------------
*
**&      Form  LIST_DISPLAY
**&---------------------------------------------------------------------
*
**       text
**----------------------------------------------------------------------
*
*FORM list_display.
**" >>> MOD-101-
*  CALL FUNCTION 'RS_TREE_CONSTRUCT'
*    TABLES
*      nodetab            = i_nodestab
*    EXCEPTIONS
*      tree_failure       = 1
*      id_not_found       = 2
*      wrong_relationship = 3
*      OTHERS             = 4.
*  IF sy-subrc <> 0.
*    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
*            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
*  ENDIF.
**" <<< MOD-101-
*
*  CALL FUNCTION 'RS_TREE_LIST_DISPLAY'
*    EXPORTING
**      callback_program      = c_prog          "MOD-101-
*      callback_program      = sy-repid                      "MOD-101+
*      callback_user_command = 'USER_COMMAND'.
*ENDFORM.                    " LIST_DISPLAY
*
**&---------------------------------------------------------------------
*
**&      Form  inform_user_of_progress
**&---------------------------------------------------------------------
*
**       text
**----------------------------------------------------------------------
*
*FORM inform_user_of_progress.
** Update Gui
*  CONDENSE v_output_text.
*  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
*    EXPORTING
*      text = v_output_text.
*ENDFORM.                    " inform_user_of_progress
*
**&---------------------------------------------------------------------
*
**&      Form  pfstatus
**&---------------------------------------------------------------------
*
**       text
**----------------------------------------------------------------------
*
*FORM pfstatus.
*
** Build table of excluded functions for buttons in report
*  REFRESH i_fcode.
*
** Not summary report
*  IF NOT ( rb_summ IS INITIAL ).                            " MOD-101-
*    MOVE c_trde TO wa_fcode-fcode.
*    APPEND wa_fcode TO i_fcode. CLEAR  wa_fcode.
*    MOVE c_sums TO wa_fcode-fcode.
*    APPEND wa_fcode TO i_fcode.
*    CLEAR  wa_fcode.
**** BEGIN OF MOD-101
*  ELSEIF rb_detl = c_x.
*    MOVE c_trde TO wa_fcode-fcode.
*    APPEND wa_fcode TO i_fcode. CLEAR  wa_fcode.
*
*    MOVE c_detl TO wa_fcode-fcode.
*    APPEND wa_fcode TO i_fcode.
*
*    CLEAR  wa_fcode.
*
*  ELSEIF rb_phase = c_x.
*    MOVE c_trde TO wa_fcode-fcode.
*    APPEND wa_fcode TO i_fcode. CLEAR  wa_fcode.
*
*    MOVE c_phas TO wa_fcode-fcode.
*    APPEND wa_fcode TO i_fcode.
*
*    CLEAR  wa_fcode.
**** END OF MOD-101
*  ENDIF.
*
** Fiscal / quantity
*  IF rb_fiscl IS INITIAL.
*    MOVE c_qty TO wa_fcode-fcode.
*    APPEND wa_fcode TO i_fcode.
*    CLEAR  wa_fcode.
*  ELSE.
*    MOVE c_fisc TO wa_fcode-fcode.
*    APPEND wa_fcode TO i_fcode.
*    CLEAR  wa_fcode.
*
*****Begin of MOD-001
**    MOVE c_ordu TO wa_fcode-fcode.
**    APPEND wa_fcode TO i_fcode.
**    CLEAR  wa_fcode.
**    MOVE c_kgm TO wa_fcode-fcode.
**    APPEND wa_fcode TO i_fcode.
**    CLEAR  wa_fcode.
*****End of MOD-001
*  ENDIF.
*
** KGM / Order uom
*  IF rb_kgm IS INITIAL.
*    MOVE c_ordu TO wa_fcode-fcode.
*    APPEND wa_fcode TO i_fcode.
*    CLEAR  wa_fcode.
*  ELSE.
*    MOVE c_kgm TO wa_fcode-fcode.
*    APPEND wa_fcode TO i_fcode.
*    CLEAR  wa_fcode.
*  ENDIF.
*
** Zero loss / std values
*  IF rb_zloss IS INITIAL.
*    MOVE c_std TO wa_fcode-fcode.
*    APPEND wa_fcode TO i_fcode.
*    CLEAR  wa_fcode.
*  ELSE.
*    MOVE c_zero TO wa_fcode-fcode.
*    APPEND wa_fcode TO i_fcode. CLEAR  wa_fcode.
*  ENDIF.
*ENDFORM.                    " pfstatus
*
**=========================================================*
******BEGIN OF MOD-003.
**&---------------------------------------------------------------------
*
**&      Form  validate_stlan
**&---------------------------------------------------------------------
*
**    subroutine to validate BOM usage
**----------------------------------------------------------------------
*
*FORM validate_stlan .
*  DATA: l_usage TYPE stlan.
**  IF p_usage IS INITIAL.                        "MOD-101-
**    MESSAGE e030. "Plese enter BOM usage        "MOD-101-
**  ELSE.                                         "MOD-101-
*  SELECT stlan INTO l_usage  "get BOM usage
*  FROM t416 UP TO 1 ROWS
*  WHERE stlan = p_usage.
*  ENDSELECT.
*
*  IF sy-subrc NE 0.
**      MESSAGE  e030.  "BOM usage doesn't exist. "MOD-101-
*    MESSAGE  e030 WITH p_usage.                             "MOD-101+
*  ENDIF.
**  ENDIF.                                        "MOD-101-
*ENDFORM.                    " validate_stlan
*
**&---------------------------------------------------------------------
*
**&      Form  validate_steus
**&---------------------------------------------------------------------
*
**    subroutine to validate control key
**----------------------------------------------------------------------
*
*FORM validate_steus .
**** BEGIN OF MOD-101
*  r_steus = s_steus[].
**"Get control key from T430
*  SELECT plnaw
*         steus
*         kalkz
*    FROM t430
*    INTO TABLE i_ckey
*  WHERE steus IN s_steus
*    AND kalkz EQ c_x.
*  IF sy-subrc NE 0.
*    MESSAGE e054.   "enter valid control key.
*  ENDIF.
*
***"Get control key from T430
**  DATA: l_steus TYPE steus.
**
***"if control key is not entered
**  IF s_steus[] IS INITIAL.
**    MESSAGE e071. "Please enter control key.
**  ELSE.
***"get control key
**    SELECT steus INTO l_steus
**    FROM t430
**    UP TO 1 ROWS
**    WHERE steus IN s_steus.
**    ENDSELECT.
**    IF sy-subrc NE 0.
**      MESSAGE e054.   "enter valid control key.
**    ENDIF.
**  ENDIF.
**** END OF MOD-101
*ENDFORM.                    " validate_steus
*
**&---------------------------------------------------------------------
*
**&      Form  validate_lstar
**&---------------------------------------------------------------------
*
**  subroutine to validate machine hours indicator
**----------------------------------------------------------------------
*
**form validate_lstar .
**data:l_lstar tyep lstar.
**
**endform.                    " validate_lstar
******END OF MOD-003.
*
**** BEGIN OF MOD-101
**&--------------------------------------------------------------------*
**&      Form  tree_rebuild
**&--------------------------------------------------------------------*
**   build / rebuild tree
**---------------------------------------------------------------------*
*FORM tree_rebuild.
*  CALL FUNCTION 'RS_TREE_CONSTRUCT'
*    TABLES
*      nodetab            = i_nodestab
*    EXCEPTIONS
*      tree_failure       = 1
*      id_not_found       = 2
*      wrong_relationship = 3
*      OTHERS             = 4.
*
*  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.                    "tree_rebuild
*
**&--------------------------------------------------------------------*
**&      Form  conv_to_from_base
**&--------------------------------------------------------------------*
**       text
**---------------------------------------------------------------------*
*FORM conv_to_from_base USING fp_kzmeinh
*                             fp_matnr
*                             fp_input
*                             fp_meinh
*                             fp_meins
*                    CHANGING fp_output
*                             fp_rc.
*  CLEAR : fp_rc , fp_output.
*  CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'
*    EXPORTING
*      input                        = fp_input
*      kzmeinh                      = fp_kzmeinh
*      matnr                        = fp_matnr
*      meinh                        = fp_meinh
*      meins                        = fp_meins
**   CHARGE                       =
**   WERKS                        =
*    IMPORTING
*      output                       = fp_output
**   UMREN                        =
**   UMREZ                        =
*    EXCEPTIONS
*      conversion_not_found         = 1
*      input_invalid                = 2
*      material_not_found           = 3
*      meinh_not_found              = 4
*      meins_missing                = 5
*      no_meinh                     = 6
*      output_invalid               = 7
*      overflow                     = 8
*      OTHERS                       = 9.
*  IF sy-subrc <> 0.
*    fp_rc = 'X'.
*  ENDIF.
*ENDFORM.                    "conv_to_from_base
*
**&--------------------------------------------------------------------*
**&      Form  convert_to_kg
**&--------------------------------------------------------------------*
**       text
**---------------------------------------------------------------------*
*FORM convert_to_kg USING    fp_matnr TYPE matnr
*                            fp_bsuom TYPE meins
*                            fp_gewei TYPE gewei
*                            fp_ntgew TYPE ntgew
*                            fp_qtyin TYPE menge_d
*                   CHANGING fp_qtout TYPE menge_d
*                            fp_rc.
*  DATA : l_out TYPE menge_d.
*
*  CLEAR : fp_rc , fp_qtout.
*
*  l_out = fp_qtyin * fp_ntgew.
*
*  IF fp_gewei <> 'KG'.
*    CALL FUNCTION 'UNIT_CONVERSION_SIMPLE'
*      EXPORTING
*        input                = l_out
*        unit_in              = fp_gewei
*        unit_out             = 'KG'
*      IMPORTING
*        output               = fp_qtout
*      EXCEPTIONS
*        conversion_not_found = 1
*        division_by_zero     = 2
*        input_invalid        = 3
*        output_invalid       = 4
*        overflow             = 5
*        type_invalid         = 6
*        units_missing        = 7
*        unit_in_not_found    = 8
*        unit_out_not_found   = 9
*        OTHERS               = 10.
*    IF sy-subrc <> 0.
*      fp_rc = 'X'.
*    ENDIF.
*
*  ELSE.
*    fp_qtout = l_out.
*  ENDIF.
*ENDFORM.                    "convert_to_kg
*
**&--------------------------------------------------------------------*
**&      Form  do_mat_calc
**&--------------------------------------------------------------------*
**       text
**---------------------------------------------------------------------*
*FORM do_mat_calc CHANGING fp_h_mat  TYPE ty_hier_mat
*                          fp_aqty   TYPE char18
*                          fp_matuom TYPE meins
*                          fp_sqty   TYPE char18
*                          fp_stduom TYPE meins
*                          fp_svar   TYPE char18
*                          fp_varuom TYPE meins
*                          fp_svarp  TYPE char18
*                          fp_amenge TYPE menge_d
*                          fp_smenge TYPE menge_d
*                          fp_astprs TYPE ty_stprs
*                          fp_sstprs TYPE ty_stprs.
*
*  DATA :   l_aqty TYPE char18,
*           l_sqty TYPE char18,
*           l_svar TYPE char18,
*           l_svarp  TYPE char18,
*
*           l_matuom TYPE meins,
*           l_stduom TYPE meins,
*           l_varuom TYPE meins,
*
*           l_amenge TYPE menge_d,
*           l_smenge TYPE menge_d,
*           l_menge  TYPE menge_d,
*           l_mvar   TYPE menge_d,
*
*           l_astprs TYPE ty_stprs,
*           l_sstprs TYPE ty_stprs,
*           l_vstprs TYPE ty_stprs,
*
*           l_wa_h_mat  TYPE ty_hier_mat,
*
*           l_fact_a TYPE menge_d VALUE 1,
*           l_fact_s TYPE menge_d VALUE 1.
*
*  CLEAR : l_smenge, l_amenge, l_astprs, l_sstprs, l_stduom, l_matuom,
*          l_varuom, l_aqty  , l_sqty  , l_svar  , l_svarp .
*
*  l_wa_h_mat = fp_h_mat.
** Standard planned or zero loss planned
*  IF rb_zloss IS INITIAL.
*    l_wa_h_mat-stdusg = l_wa_h_mat-stdusgs.
*
*  ELSE.
*    l_wa_h_mat-stdusg = l_wa_h_mat-stdusgz.
*  ENDIF.
*
*  l_smenge = fp_smenge + l_wa_h_mat-stdusg.
*  l_amenge = l_wa_h_mat-actusg.
*
*  IF l_wa_h_mat-bsuom = 'EA' OR l_wa_h_mat-bsuom = 'CS'.
** Begin of MOD-002++
**    l_smenge = CEIL( l_wa_h_mat-stdusg ).
**    l_amenge = CEIL( l_wa_h_mat-actusg ).
** End of MOD-002++
*
*    l_wa_h_mat-stdusg = l_smenge.
*    l_wa_h_mat-actusg = l_amenge.
*  ENDIF.
*
** Order UoM or KG
**  IF rb_quant EQ c_x AND rb_kgm IS INITIAL.
*  IF rb_kgm IS INITIAL.
*    l_matuom = l_wa_h_mat-gruom.
*    l_stduom = l_wa_h_mat-bomuom.
*
*    IF l_wa_h_mat-gruom <> l_wa_h_mat-bsuom.
*      PERFORM conv_to_from_base USING ' '
*                                      l_wa_h_mat-matnr
*                                      l_amenge
*                                      l_wa_h_mat-gruom
*                                      l_wa_h_mat-bsuom
*                             CHANGING l_menge
*                                      v_conv_rc.
*      IF v_conv_rc <> c_x.
*        l_amenge = l_menge.
*        PERFORM convert_unit USING l_wa_h_mat-matnr
*                                   1
*                                   l_wa_h_mat-gruom
*                                   l_wa_h_mat-bsuom
*                          CHANGING l_fact_a.
*        IF l_fact_a = 0.
*          l_fact_a = 1.
*        ENDIF.
*      ENDIF.
*    ENDIF.
*
*    IF l_wa_h_mat-bsuom <> l_wa_h_mat-bomuom.
*      PERFORM conv_to_from_base USING ' '
*                                      l_wa_h_mat-matnr
*                                      l_smenge
*                                      l_wa_h_mat-bomuom
*                                      l_wa_h_mat-bsuom
*                             CHANGING l_menge
*                                      v_conv_rc.
*      IF v_conv_rc <> c_x.
*        l_smenge = l_menge.
*        PERFORM convert_unit USING l_wa_h_mat-matnr
*                                   1
*                                   l_wa_h_mat-bomuom
*                                   l_wa_h_mat-bsuom
*                          CHANGING l_fact_s.
*        IF l_fact_s = 0.
*          l_fact_s = 1.
*        ENDIF.
*      ENDIF.
*    ENDIF.
*
*  ELSE.
*    l_matuom = l_wa_h_mat-bsuom.
*    l_stduom = l_wa_h_mat-bsuom.
*
*    IF l_wa_h_mat-bsuom <> 'KG'.
*      PERFORM convert_to_kg USING   l_wa_h_mat-matnr l_wa_h_mat-bsuom
*                                    l_wa_h_mat-gewei l_wa_h_mat-ntgew
*                                    l_amenge
*                           CHANGING l_menge
*                                    v_conv_rc.
*      IF v_conv_rc = 'X'.
*        CLEAR : l_amenge , l_matuom.
*
*      ELSE.
*        l_amenge = l_menge.
*        l_matuom = 'KG'.
*        PERFORM convert_to_kg USING   l_wa_h_mat-matnr l_wa_h_mat-bsuom
*                                      l_wa_h_mat-gewei l_wa_h_mat-ntgew
*                                      1
*                             CHANGING l_fact_a
*                                      v_conv_rc.
*        IF l_fact_a = 0.
*          l_fact_a = 1.
*        ENDIF.
*        l_fact_a = 1 / l_fact_a.
*      ENDIF.
*
*      PERFORM convert_to_kg USING   l_wa_h_mat-matnr l_wa_h_mat-bsuom
*                                    l_wa_h_mat-gewei l_wa_h_mat-ntgew
*                                    l_smenge
*                           CHANGING l_menge
*                                    v_conv_rc.
*      IF v_conv_rc = 'X'.
*        CLEAR : l_smenge , l_stduom.
*
*      ELSE.
*        l_smenge = l_menge.
*        l_stduom = 'KG'.
*        PERFORM convert_to_kg USING   l_wa_h_mat-matnr l_wa_h_mat-bsuom
*                                      l_wa_h_mat-gewei l_wa_h_mat-ntgew
*                                      1
*                             CHANGING l_fact_s
*                                      v_conv_rc.
*        IF l_fact_s = 0.
*          l_fact_s = 1.
*        ENDIF.
*        l_fact_s = 1 / l_fact_s.
*      ENDIF.
*    ENDIF.
*  ENDIF.
*
** Fiscal or quantity
*  CLEAR : l_sqty , l_aqty, l_svar, l_svarp, l_mvar, l_vstprs.
*  IF rb_quant EQ c_x.
*    IF l_wa_h_mat-bsuom = 'EA' OR l_wa_h_mat-bsuom = 'CS'.
** Begin of MOD-002++
**      l_smenge = CEIL( l_smenge ).
**      l_amenge = CEIL( l_amenge ).
** End of MOD-002++
*      IF l_wa_h_mat-peinh <> 0.
*        l_astprs = l_amenge * l_fact_a *
*                 ( l_wa_h_mat-stprs / l_wa_h_mat-peinh ).
*        l_sstprs = fp_sstprs + l_smenge * l_fact_s *
*                 ( l_wa_h_mat-stprs / l_wa_h_mat-peinh ).
*      ENDIF.
*    ELSE.
*      IF l_wa_h_mat-peinh <> 0.
*        l_astprs = l_wa_h_mat-actusg *
*                 ( l_wa_h_mat-stprs / l_wa_h_mat-peinh ).
*        l_sstprs = fp_sstprs + l_wa_h_mat-stdusg *
*                 ( l_wa_h_mat-stprs / l_wa_h_mat-peinh ).
*      ENDIF.
*    ENDIF.
*    l_vstprs =  l_sstprs - l_astprs.
*
*    WRITE : l_amenge TO l_aqty UNIT l_matuom NO-GROUPING.
*    WRITE : l_smenge TO l_sqty UNIT l_stduom NO-GROUPING.
*
*    IF l_matuom IS INITIAL OR l_matuom EQ l_stduom.
*      l_mvar = l_smenge - l_amenge.
*
*      IF l_smenge <> 0.
*        l_wa_h_mat-varper = ( l_mvar / l_smenge ) * 100.
*      ELSE.
*        l_wa_h_mat-varper = 0.
*      ENDIF.
*    ENDIF.
*
*    WRITE : l_mvar            TO l_svar  UNIT l_stduom NO-GROUPING.
*    WRITE : l_wa_h_mat-varper TO l_svarp NO-GROUPING DECIMALS 2.
*    l_varuom = l_stduom.
*
*  ELSE.
*    l_matuom = v_waers.
*    l_stduom = v_waers.
*    l_varuom = v_waers.
*
*    IF l_wa_h_mat-bsuom = 'EA' OR l_wa_h_mat-bsuom = 'CS'.
** Begin of MOD-002++
**      l_smenge = CEIL( l_smenge ).
**      l_amenge = CEIL( l_amenge ).
** End of MOD-002++
*      IF l_wa_h_mat-peinh <> 0.
*        l_astprs = l_amenge * l_fact_a *
*                 ( l_wa_h_mat-stprs / l_wa_h_mat-peinh ).
*        l_sstprs = fp_sstprs + l_smenge * l_fact_s *
*                 ( l_wa_h_mat-stprs / l_wa_h_mat-peinh ).
*      ENDIF.
*    ELSE.
*      IF l_wa_h_mat-peinh <> 0.
*        l_astprs = l_wa_h_mat-actusg *
*                 ( l_wa_h_mat-stprs / l_wa_h_mat-peinh ).
*        l_sstprs = fp_sstprs + l_wa_h_mat-stdusg *
*                 ( l_wa_h_mat-stprs / l_wa_h_mat-peinh ).
*      ENDIF.
*    ENDIF.
*
*    l_vstprs =  l_sstprs - l_astprs.
*
*    IF l_sstprs <> 0.
*      l_wa_h_mat-varper = ( l_vstprs / l_sstprs ) * 100.
*    ELSE.
*      l_wa_h_mat-varper = 0.
*    ENDIF.
*
*    v_prs = l_astprs.
*    WRITE : v_prs TO l_aqty CURRENCY v_waers NO-GROUPING.
*
*    v_prs = l_sstprs.
*    WRITE : v_prs TO l_sqty CURRENCY v_waers NO-GROUPING.
*
*    v_prs = l_vstprs.
*    WRITE : v_prs TO l_svar CURRENCY v_waers NO-GROUPING.
*
*    WRITE : l_wa_h_mat-varper TO l_svarp NO-GROUPING DECIMALS 2.
*  ENDIF.
*
*  l_wa_h_mat-stdvar = l_mvar.
*  l_wa_h_mat-vstprs = l_vstprs.
*
*  fp_aqty = l_aqty.
*  fp_matuom = l_matuom.
*
*  fp_sqty = l_sqty.
*  fp_stduom = l_stduom.
*
*  fp_svar = l_svar.
*  fp_varuom = l_varuom.
*
*  fp_svarp = l_svarp.
*
*  fp_amenge = l_amenge.
*  fp_astprs = l_astprs.
*
*  fp_smenge = l_smenge.
*  fp_sstprs = l_sstprs.
*
*  fp_h_mat  = l_wa_h_mat.
*ENDFORM.                    "do_mat_calc
*
**&---------------------------------------------------------------------
*
**&      Form  convert_unit
**&---------------------------------------------------------------------
*
**       Convert UoM
**----------------------------------------------------------------------
*
**      -->fp_matnr   Material
**      -->fp_in_qty  In Qty
**      -->fp_in_uom  In UoM
**      -->fp_out_uom Out UoM
**      <--fp_out_qty Out Qty
**----------------------------------------------------------------------
*
*FORM convert_unit  USING    fp_matnr TYPE matnr
*                            fp_in_qty TYPE bstmg
*                            fp_in_uom TYPE meins
*                            fp_out_uom TYPE meins
*                   CHANGING fp_out_qty TYPE bstmg.
*
*  IF fp_in_uom = fp_out_uom.
*    fp_out_qty = fp_in_qty.
*    EXIT.
*  ENDIF.
*
*  CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
*    EXPORTING
*      i_matnr              = fp_matnr
*      i_in_me              = fp_in_uom
*      i_out_me             = fp_out_uom
*      i_menge              = fp_in_qty
*    IMPORTING
*      e_menge              = fp_out_qty
*    EXCEPTIONS
*      error_in_application = 1
*      error                = 2
*      OTHERS               = 3.
*  IF sy-subrc <> 0.
*    fp_out_qty = 0.
*  ENDIF.
*
*ENDFORM.                    " convert_unit

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

*&---------------------------------------------------------------------*
*&  Include           ZPROCESSORDVARF01                                *
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
* Report:              : ZPROCESSORD
* AUTHOR               : Aveek Ghose                                   *
* SUPPLIER             : IBM                                           *
*======================================================================*
* CHANGE HISTORY LOG                                                   *
*----------------------------------------------------------------------*
* MOD. NO.|  DATE   | NAME   | CORRECTION NUMBER | CHANGE REFERENCE   #*
*----------------------------------------------------------------------*
* MOD-001 |DD/MM/YYYY| XXXXXX | XXXXXXXXXX       | XXXXXXXXX           *
* DESCRIPTION:                                                         *
*----------------------------------------------------------------------*
* MOD-002 |DD/MM/YYYY| XXXXXX | XXXXXXXXXX       | XXXXXXXXX           *
* DESCRIPTION:                                                         *
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&  Include           ZPROCESSORDVARF01
*&---------------------------------------------------------------------*

FORM fill_movement_types .

  REFRESH i_r_bwart.

*  wa_bwart-sign   = c_sign.
*  wa_bwart-option = c_option.
*  wa_bwart-low    = '101'.
*  APPEND wa_bwart TO i_r_bwart.
*  CLEAR wa_bwart.
*
*  wa_bwart-sign   = c_sign.
*  wa_bwart-option = c_option.
*  wa_bwart-low    = '102'.
*  APPEND wa_bwart TO i_r_bwart.
*  CLEAR wa_bwart.

  wa_bwart-sign   = c_sign.
  wa_bwart-option = c_option.
  wa_bwart-low    = c_movm_low_261.
  APPEND wa_bwart TO i_r_bwart.
  CLEAR wa_bwart.

  wa_bwart-sign   = c_sign.
  wa_bwart-option = c_option.
  wa_bwart-low    = c_movm_low_262.
  APPEND wa_bwart TO i_r_bwart.
  CLEAR wa_bwart.

  wa_bwart-sign   = c_sign.
  wa_bwart-option = c_option.
  wa_bwart-low    = c_movm_low_531.
  APPEND wa_bwart TO i_r_bwart.
  CLEAR wa_bwart.

  wa_bwart-sign   = c_sign.
  wa_bwart-option = c_option.
  wa_bwart-low    = c_movm_low_532.
  APPEND wa_bwart TO i_r_bwart.
  CLEAR wa_bwart.
ENDFORM.                    " fill_movement_types

*&---------------------------------------------------------------------*
*&      Form  get_currency
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM get_currency.

****Begin of MOD-001
  DATA :  l_bukrs TYPE bukrs,
          l_waers TYPE waers.

  CLEAR : v_waers.

  IF NOT p_werks IS INITIAL.
    SELECT SINGLE werks FROM t001w INTO v_werks
    WHERE werks = p_werks.
    IF sy-subrc <> 0.
      MESSAGE e001 WITH p_werks. " Invalid Plant
    ENDIF.
  ENDIF.
*
*Retrieve the company code
  SELECT SINGLE bukrs
    FROM t001k
    INTO l_bukrs
   WHERE bwkey = p_werks.

  IF sy-subrc = 0.

*Get the currence at company
    SELECT SINGLE waers
      FROM t001
      INTO v_waers
     WHERE bukrs = l_bukrs.

  ENDIF.
******************MOD-004******************************
*  SELECT SINGLE waers
*  FROM tka01 INTO l_waers
*  WHERE kokrs = p_kokrs.
*
*  IF sy-subrc <> 0.
*    MESSAGE e046. " Invalid Controlling area entered.
*
*  ELSEIF v_waers IS INITIAL.
** If the currency is not maintained at companmy level
*    v_waers = l_waers.
*  ENDIF.
*****************MOD-004******************************
*  AUTHORITY-CHECK OBJECT 'C_AFKO_AWK'
*           ID 'WERKS' FIELD p_werks
*           ID 'AUFART' DUMMY.
*  IF sy-subrc <> 0.
*    MESSAGE e000 WITH
*     'You do not have authorisation to display report'(070).
*  ENDIF.
***************MOD-004************************************

*  IF NOT p_werks IS INITIAL.
*    SELECT SINGLE werks FROM t001w INTO v_werks
*    WHERE werks = p_werks.
*    IF sy-subrc <> 0.
*      MESSAGE e001 WITH p_werks. " Invalid Plant
*    ENDIF.
*  ENDIF.
**********End of MOD-001.
ENDFORM.                    " get_currency

*&---------------------------------------------------------------------*
*&      Form  check_materials
*&---------------------------------------------------------------------*
*       text - Checking material number and material type values
*----------------------------------------------------------------------*
FORM check_materials.
  DATA : l_matnr TYPE matnr,                                "#EC NEEDED
         l_mtart TYPE mtart.                                "#EC NEEDED

* Checking material(s) valid or not
  IF NOT ( s_matnr[] IS INITIAL ).
* Checking at leaset one material is valid for select-options material.
    SELECT SINGLE matnr
    FROM mara
    INTO l_matnr
    WHERE matnr IN s_matnr.                                 "#EC *
    IF sy-subrc <> 0.
      MESSAGE e000 WITH 'Material(s) not found for this selection'(062).
    ENDIF.
  ENDIF.

* Checking material type valid or not
  IF NOT ( p_mtart IS INITIAL ).
    SELECT SINGLE mtart
    FROM t134 INTO l_mtart  "MOD IB mara-mtart
    WHERE mtart = p_mtart.
    IF sy-subrc <> 0.
      MESSAGE e000 WITH 'Incorrect Material Type'(063).
    ENDIF.
  ENDIF.

* Checking material number and type valid or not.
  IF NOT ( s_matnr[] IS INITIAL ) AND
     NOT ( p_mtart   IS INITIAL ).
* Checking at leaset one material is valid for select-options material
* and for material type

    CLEAR l_matnr.
    SELECT SINGLE matnr
    FROM mara
    INTO l_matnr
    WHERE matnr IN s_matnr AND
          mtart = p_mtart.                                  "#EC *
    IF sy-subrc <> 0.
      MESSAGE e000
      WITH 'Incorrect material number & type combination'(064).
    ENDIF.
  ENDIF.
ENDFORM.                    " check_materials

*&---------------------------------------------------------------------*
*&      Form  get_status
*&---------------------------------------------------------------------*
*       text -- Retreving System status texts from table TJ02T
*----------------------------------------------------------------------*
FORM get_status USING    fp_txt04 TYPE j_txt04
                CHANGING fp_stat  TYPE j_istat.
** >>>> MOD-101+
  CLEAR : fp_stat.
  SELECT SINGLE istat
    FROM tj02t
    INTO fp_stat
   WHERE txt04 = fp_txt04
     AND spras = sy-langu.                            "#EC CI_SGLSELECT
*** if select fails stat is returned empty, so no check required.

** <<<< MOD-101+
*  REFRESH i_tj02t.
*  CLEAR   wa_tj02t.
*  IF NOT ( s_stats[] IS INITIAL ).
*    SELECT txt04
*    FROM tj02t INTO TABLE i_tj02t
*    WHERE txt04 IN s_stats
*    AND   spras =  sy-langu.                          "#EC CI_SGLSELECT
**    IF sy-subrc = 0.
*** The check is not required here since the
*** system status text is not  mandatory
**    ENDIF.
*  ENDIF.
*
*  IF rb_ezero = c_x.
*    IF rb_prod = c_x.
*      wa_tj02t-txt04 = c_txt_dlv.
*    ENDIF.
*
*    IF rb_conf = c_x.
*      wa_tj02t-txt04 = c_txt_cnf.
*    ENDIF.
*    APPEND wa_tj02t TO i_tj02t.
*    CLEAR  wa_tj02t.
*  ENDIF.
*  SORT i_tj02t BY txt04 AS TEXT.  " MOD IB (SORT i_tj02t)
*  DELETE ADJACENT DUPLICATES FROM i_tj02t.
ENDFORM.                    " get_status

*&---------------------------------------------------------------------*
*&      Form  get_status_info
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM get_status_info USING    fp_l_orders_objnr TYPE j_objnr
                              fp_l_sttxt        TYPE any.

  DATA: l_text(4) TYPE c,
        l_stsma   TYPE j_stsma,

* START MOD IB
        i_status  TYPE STANDARD TABLE OF jstat INITIAL SIZE 0,
        wa_status TYPE jstat.
* END MOD IB
  REFRESH i_status.

* Get all active statuses for the order
  CALL FUNCTION 'STATUS_READ'
    EXPORTING
      objnr       = fp_l_orders_objnr
      only_active = c_x
    IMPORTING
      stsma       = l_stsma
    TABLES
      status      = i_status.

  CLEAR: fp_l_sttxt.

  LOOP AT i_status INTO wa_status.
* Get the text for each status
    CALL FUNCTION 'STATUS_NUMBER_CONVERSION'
      EXPORTING
        language      = sy-langu
        status_number = wa_status-stat
        stsma         = l_stsma
      IMPORTING
        txt04         = l_text.
* Add status text found to current list
    CONCATENATE fp_l_sttxt l_text INTO fp_l_sttxt.
    CLEAR : wa_status.
  ENDLOOP.
ENDFORM.                    " get_status_info

*&---------------------------------------------------------------------*
*&      Form  get_work_center
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM get_work_center.
  CLEAR:   wa_crhd.
  REFRESH: i_crhd.

  SELECT objid
         arbpl
  FROM crhd INTO TABLE i_crhd
  WHERE objty = c_objtyp
    AND werks = p_werks
    AND arbpl IN s_arbpl.
*  IF sy-subrc = 0.
** sy-subrc check is not required, there must be atleast one record for
** this selection.
*  ENDIF.
ENDFORM.                    " get_work_center

*&---------------------------------------------------------------------*
*&      Form  get_cost_center
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM get_cost_center.
  IF NOT ( s_kostl[] IS INITIAL ).
    CLEAR : i_csks.
    SELECT kokrs kostl
      FROM csks
      INTO TABLE i_csks
     WHERE kokrs = p_kokrs
       AND kostl IN s_kostl.
    IF sy-subrc = 0.
      SORT i_csks BY kokrs kostl.
    ENDIF.
  ENDIF.
ENDFORM.                    " get_cost_center

****
**** BEGIN OF MOD-101
****
*&---------------------------------------------------------------------*
*&      Form  get_orders
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM get_orders.

  DATA: l_sttxt(100)  TYPE c,
        flg_status(1) TYPE c.
  FIELD-SYMBOLS : <fs_orders> TYPE ty_orders.

  MOVE 'Extracting Process Orders'(022) TO v_output_text.
  PERFORM inform_user_of_progress.

  IF NOT p_mtart IS INITIAL.
*"selection filter on material type
    SELECT matnr     "material number
           mtart     "material type
      INTO TABLE i_mtart
      FROM mara
     WHERE matnr IN s_matnr
       AND mtart  = p_mtart.
    IF sy-subrc = c_0.
* refill S_MATNR with I_MTART values
      REFRESH : s_matnr.

      s_matnr-sign   = c_sign.
      s_matnr-option = c_option.
      LOOP AT i_mtart INTO wa_mtart.
        s_matnr-low = wa_mtart-matnr.
        APPEND s_matnr.
      ENDLOOP.

    ELSE.
* No data was selected for material type
      MESSAGE i072 WITH p_mtart.
      LEAVE LIST-PROCESSING.
    ENDIF.
  ENDIF.

  SELECT aufnr

         werks
         kokrs
         objnr

         gltrp
         gstrp

         rsnum

         gamng
         gmein
         plnbez

         plnty
         plnnr
         plnal

         stlst
         stlty
         stlnr
         sdatv
         stlal
         stlan

         aufpl
         zaehl
         rueck

         auart

         aufld                                              "31-05-2005

    INTO TABLE i_orders FROM caufv
   WHERE aufnr  IN s_aufnr
     AND werks   = p_werks
*    AND kokrs   = p_kokrs
     AND fevor   IN s_fevor
     AND plnbez  IN s_matnr
     AND stlan   = p_usage
     AND ( gstrp IN s_datuv OR
           gltrp IN s_datuv ).
  IF sy-subrc <> 0.
    MESSAGE s007.
    LEAVE LIST-PROCESSING.
  ENDIF.

  SORT i_orders BY aufnr.

* Take status txt from sel screen and get status number
  IF NOT p_stats1 IS INITIAL.
    PERFORM get_status USING p_stats1 CHANGING v_stat1.
  ENDIF.

  IF NOT p_stats2 IS INITIAL.
    PERFORM get_status USING p_stats2 CHANGING v_stat2.
  ENDIF.

* get object numbers and statuses for orders
  CLEAR : i_obj_stat.
  SELECT objnr
         stat
    FROM jest
    INTO TABLE i_obj_stat
     FOR ALL ENTRIES IN i_orders
   WHERE objnr = i_orders-objnr
     AND stat  IN (v_stat1,v_stat2).

* cull orders
  LOOP AT i_orders ASSIGNING <fs_orders>.
    IF NOT v_stat1 IS INITIAL.
      READ TABLE i_obj_stat INTO wa_obj_stat
                            WITH KEY objnr = <fs_orders>-objnr
                                     stat  = v_stat1.
      IF sy-subrc = 0 AND p_s1_chk EQ c_x.
        <fs_orders>-del = c_x.
      ELSEIF sy-subrc NE 0 AND p_s1_chk NE c_x.
        <fs_orders>-del = c_x.
      ENDIF.
    ENDIF.

    IF NOT v_stat2 IS INITIAL.
      READ TABLE i_obj_stat INTO wa_obj_stat
                            WITH KEY objnr = <fs_orders>-objnr
                                     stat  = v_stat2.
      IF sy-subrc = 0 AND p_s2_chk EQ c_x.
        <fs_orders>-del = c_x.
      ELSEIF sy-subrc NE 0 AND p_s2_chk NE c_x.
        <fs_orders>-del = c_x.
      ENDIF.
    ENDIF.
  ENDLOOP.

*  DELETE i_orders WHERE del = c_x.
*  LOOP AT i_orders INTO wa_orders.
*    IF NOT i_tj02t[] IS INITIAL .
*      PERFORM get_status_info USING wa_orders-objnr l_sttxt.
*
*      CLEAR: flg_status, wa_tj02t.
*      LOOP AT i_tj02t INTO wa_tj02t.
*        IF l_sttxt NS wa_tj02t-txt04.
*          CLEAR flg_status.
*          EXIT.
*        ELSE.
*          flg_status = c_x.
*          CONTINUE.
*        ENDIF.
*        CLEAR : wa_tj02t.
*      ENDLOOP.
*
*      IF flg_status <> c_x.
*        DELETE i_orders.
*        CONTINUE.
*      ENDIF.
*    ENDIF.
*  ENDLOOP.
ENDFORM.                    " get_orders

*&---------------------------------------------------------------------*
*&      Form  get_operations
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM get_operations.

  DATA l_tabix TYPE sytabix.

* Let the user know whats up
  MOVE 'Extracting Phase Information'(023) TO v_output_text.
  PERFORM inform_user_of_progress.

* select process order item lines
  SELECT aufpl
         aplzl

         ltxa1

         plnkn
         plnty
         plnnr
         zaehl

         vornr
         steus
         arbid
         rueck

         phflg
         sumnr
         vgwts

         lar01
         lar02
         lar03
         lar04
         lar05
         lar06
    INTO TABLE i_afvc
    FROM afvc
     FOR ALL ENTRIES IN i_orders
   WHERE aufpl = i_orders-aufpl
     AND steus IN s_steus.
***********MOD-004*****************************
*    AND phflg = c_x.
***********MOD-004*****************************

  IF sy-subrc = 0.
* select process order item values
    SELECT aufpl
           aplzl

           meinh
           bmsch

           umren
           umrez

           vge01
           vgw01
           vge02
           vgw02
           vge03
           vgw03
           vge04
           vgw04
           vge05
           vgw05
           vge06
           vgw06

           mgvrg
           lmnga
           gmnga

           ism01
           ism02
           ism03
           ism04
           ism05
           ism06

           ssavd
      FROM afvv INTO TABLE i_afvv
       FOR ALL ENTRIES IN i_afvc
     WHERE aufpl  = i_afvc-aufpl
       AND aplzl  = i_afvc-aplzl
       AND ssavd IN s_datuv.
    IF sy-subrc = 0.
      SORT i_afvv BY aufpl aplzl.
    ENDIF.

* select process order related work centre data
    SELECT objty
           objid
           kokrs
           kostl
           lstar
      FROM crco
      INTO TABLE i_crco
       FOR ALL ENTRIES IN i_afvc
     WHERE objty = c_objtyp
       AND objid = i_afvc-arbid
       AND kostl IN s_kostl.
    IF sy-subrc = 0.
      SORT i_crco BY objty objid kostl.
    ENDIF.

* Retrieve work center details
    SELECT objid
           arbpl
           vgwts
      FROM crhd
 APPENDING TABLE i_crhd
       FOR ALL ENTRIES IN i_afvc
     WHERE objty = c_objtyp
       AND objid = i_afvc-arbid
       AND werks = p_werks
       AND arbpl IN s_arbpl.

    SORT i_crhd   BY objid.
    SORT i_orders BY aufpl.
    SORT i_afvc BY aufpl vornr DESCENDING.

    LOOP AT i_afvc INTO wa_afvc.
      l_tabix = sy-tabix.

*** link PrO number to phase through the routing number
      CLEAR : wa_orders.
      READ TABLE i_orders INTO wa_orders WITH KEY aufpl = wa_afvc-aufpl.
      IF sy-subrc = 0.
        wa_afvc-aufnr = wa_orders-aufnr.
        MODIFY i_afvc FROM wa_afvc INDEX l_tabix TRANSPORTING aufnr.

*** check cost centre of phase
        IF NOT ( s_kostl[] IS INITIAL ).
          READ TABLE i_crco INTO wa_crco WITH KEY objty = c_objtyp
                                                  objid = wa_afvc-arbid
                                              BINARY SEARCH.
          IF sy-subrc = 0.
*** see if cost centre of phase is valid
            READ TABLE i_csks INTO wa_csks
                              WITH KEY kostl = wa_crco-kostl.
            IF sy-subrc <> 0.
*** delete invalid phases
              DELETE i_afvv WHERE aufpl = wa_afvc-aufpl
                              AND aplzl = wa_afvc-aplzl.
              DELETE i_afvc INDEX l_tabix.
              CONTINUE.
            ENDIF.
          ENDIF.
        ENDIF.

*** Check work centre details with resource
        IF NOT ( s_arbpl[] IS INITIAL ).
          READ TABLE i_crhd INTO wa_crhd
                            WITH KEY objid = wa_afvc-arbid.
          IF sy-subrc <> 0.
            DELETE i_afvv WHERE aufpl = wa_afvc-aufpl
                            AND aplzl = wa_afvc-aplzl.
            DELETE i_afvc INDEX l_tabix.
            CONTINUE.
          ENDIF.

        ENDIF.
        CLEAR: wa_crco, wa_crhd, l_tabix.

      ELSE.
*** if routing number is not linked to any valid order
*** delete phase
        DELETE i_afvc INDEX l_tabix.
      ENDIF.
    ENDLOOP.
  ENDIF.

* Begin of MOD-002++
  LOOP AT i_orders INTO wa_orders.
    CLEAR: wa_afvc, l_tabix.
    l_tabix = sy-tabix.
    READ TABLE i_afvc INTO wa_afvc WITH KEY aufpl = wa_orders-aufpl.
    IF sy-subrc NE 0.
      DELETE i_orders INDEX l_tabix.
    ENDIF.
  ENDLOOP.
* End of MOD-002++

ENDFORM.                    " get_operations

*&--------------------------------------------------------------------*
*&      Form  get_order_mats
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM get_order_mats.

  DATA : l_v_erfme TYPE erfme,
         l_v_chec  TYPE char1,
         l_bwart   TYPE bwart.

* get materials issued/receipt against order
  SELECT aufnr aufpl aplzl matnr mblnr mjahr zeile bwart
         werks lgort charg
         menge meins erfmg erfme
         rsnum rspos rsart
    FROM aufm
    INTO TABLE i_mseg1
     FOR ALL ENTRIES IN i_orders
   WHERE aufnr = i_orders-aufnr.
  IF sy-subrc = 0.

*** get base UoM for all materials
    CLEAR: i_mara.
    SELECT matnr
           mtart
           meins
           gewei
           ntgew
      FROM mara
 APPENDING TABLE i_mara
       FOR ALL ENTRIES IN i_mseg1
     WHERE matnr = i_mseg1-matnr.

    SORT i_mseg1 BY aufnr aufpl aplzl matnr.
*** get material qty in base UoM and summarize material data
    LOOP AT i_mseg1 INTO wa_mseg.
      CLEAR : wa_mara.
*** read material master for base UoM
      READ TABLE i_mara INTO wa_mara WITH KEY matnr = wa_mseg-matnr.
      IF sy-subrc = 0.
        IF wa_mseg-meins <> wa_mara-meins.
          CLEAR : wa_mseg-bmenge.
*** convert GR quant into base units
          PERFORM conv_to_from_base USING 'X'
                                          wa_mseg-matnr
                                          wa_mseg-menge
                                          wa_mseg-meins
                                          wa_mara-meins
                                 CHANGING wa_mseg-bmenge
                                          v_conv_rc.
        ELSE.
          wa_mseg-bmenge = wa_mseg-menge.
        ENDIF.

        wa_mseg-bmeins = wa_mara-meins.
        wa_mseg-gewei  = wa_mara-gewei.
        wa_mseg-ntgew  = wa_mara-ntgew.
        MODIFY i_mseg1 FROM wa_mseg TRANSPORTING bmenge bmeins.
      ENDIF.

      wa_msegs-aufnr  = wa_mseg-aufnr.
      wa_msegs-aufpl  = wa_mseg-aufpl.
      wa_msegs-aplzl  = wa_mseg-aplzl.
      wa_msegs-matnr  = wa_mseg-matnr.
      wa_msegs-meins  = wa_mseg-meins.
      wa_msegs-bmeins = wa_mseg-bmeins.
      wa_msegs-gewei  = wa_mseg-gewei.
* Begin of MOD-002++
      IF ( wa_mseg-bwart <> 'ZU1' ) AND ( wa_mseg-bwart <> 'ZU2' ).
        wa_msegs-erfme  = wa_mseg-erfme.
      ENDIF.
* End of MOD-002++

      AT NEW matnr.
        l_v_erfme = wa_msegs-erfme.
        CLEAR : l_v_chec.
      ENDAT.

      IF l_v_erfme <> wa_mseg-erfme.
*** set flag if different GR mvts have diff. GR UoM
        l_v_chec = c_x.
      ENDIF.

*** Sum up material qtys based on movement
      CASE wa_mseg-bwart.
        WHEN '101'.
*** GR of material
          wa_msegs-bmenge1 = wa_msegs-bmenge1 + wa_mseg-bmenge.
          wa_msegs-erfmg1  = wa_msegs-erfmg1  + wa_mseg-erfmg.
          wa_msegs-erfme   = wa_mseg-erfme.
          l_bwart    = '101'.                               "23-05-2005

        WHEN '261'.
*** Consumption of material
          wa_msegs-bmenge2 = wa_msegs-bmenge2 + wa_mseg-bmenge.
          wa_msegs-erfmg2  = wa_msegs-erfmg2  + wa_mseg-erfmg.
          l_bwart    = '261'.                               "23-05-2005

        WHEN '532'.
*** reversal of 531
          wa_msegs-bmenge5 = wa_msegs-bmenge5 + wa_mseg-bmenge.
          wa_msegs-erfmg5  = wa_msegs-erfmg5  + wa_mseg-erfmg.

        WHEN '102'.
*** reversal of 101
          wa_msegs-bmenge1 = wa_msegs-bmenge1 - wa_mseg-bmenge.
          wa_msegs-erfmg1  = wa_msegs-erfmg1  + wa_mseg-erfmg.

        WHEN '262'.
*** reversal of 261
          wa_msegs-bmenge2 = wa_msegs-bmenge2 - wa_mseg-bmenge.
          wa_msegs-erfmg2  = wa_msegs-erfmg2  + wa_mseg-erfmg.

        WHEN '531'.
*** By-product material mvt
          wa_msegs-bmenge5 = wa_msegs-bmenge5 - wa_mseg-bmenge.
          wa_msegs-erfmg5  = wa_msegs-erfmg5  + wa_mseg-erfmg.
          l_bwart    = '531'.                               "23-05-2005

      ENDCASE.

*** If the diff. GR qtys have different UoM then do not cumulate
*** actual qty values
      IF l_v_chec = c_x.
        CLEAR : wa_msegs-erfmg1, wa_msegs-erfmg2 , wa_msegs-erfmg5.
      ENDIF.

      AT END OF matnr.
        wa_msegs-bmenge = wa_msegs-bmenge1 + wa_msegs-bmenge2 +
                          wa_msegs-bmenge5.
        wa_msegs-erfmg  = wa_msegs-erfmg1  + wa_msegs-erfmg2 +
                          wa_msegs-erfmg5.
        wa_msegs-bwart  = l_bwart .

        APPEND wa_msegs TO i_msegs.
        CLEAR : wa_msegs,
                l_bwart.
      ENDAT.
    ENDLOOP.
  ENDIF.
ENDFORM.                    "get_order_mats

*&---------------------------------------------------------------------*
*&      Form  get_mat_segment
*&---------------------------------------------------------------------*
FORM get_mat_segment.
  DATA: l_tabix  TYPE sytabix.

  FIELD-SYMBOLS : <l_fs_orders> TYPE ty_orders,
                  <l_fs_afvc>   TYPE ty_afvc.

  IF NOT ( i_orders[] IS INITIAL ).
*** get material master data for PO materials
    CLEAR: i_mara , i_mseg , i_mseg1 , i_msegs , i_msegs1.
    SELECT matnr
           mtart
           meins
           gewei
           ntgew
      FROM mara
      INTO TABLE i_mara
       FOR ALL ENTRIES IN i_orders
     WHERE matnr = i_orders-plnbez.

    IF NOT ( rb_prod IS INITIAL ).
*** Tell user we are Extracting goods receipt information
      MOVE 'Extracting Goods Receipt Information'(024) TO v_output_text.
      PERFORM inform_user_of_progress.

*** get the materials to process
      PERFORM get_order_mats.

*** create alternate working tables for mat. mvts
      i_mseg   = i_mseg1.
      i_msegs1 = i_msegs.

*** retain only order material in internal table and get order qty in
*** base UoM
      LOOP AT i_orders ASSIGNING <l_fs_orders>.

*** retain mat. mvts only for the main material of the PrO
        DELETE i_mseg WHERE aufnr =  <l_fs_orders>-aufnr
                        AND matnr <> <l_fs_orders>-plnbez.

        DELETE i_msegs1 WHERE aufnr =  <l_fs_orders>-aufnr
                          AND matnr <> <l_fs_orders>-plnbez.

*** read material master for base UoM of material
        CLEAR : wa_mara.
        READ TABLE i_mara INTO wa_mara
                          WITH KEY matnr = <l_fs_orders>-plnbez.
        IF sy-subrc = 0.
          IF wa_mara-meins <> <l_fs_orders>-gmein.
*** convert order quantity to base UoM
            PERFORM conv_to_from_base USING 'X'
                                            <l_fs_orders>-plnbez
                                            <l_fs_orders>-gamng
                                            <l_fs_orders>-gmein
                                            wa_mara-meins
                                   CHANGING <l_fs_orders>-bgamng
                                            v_conv_rc.
          ELSE.
            <l_fs_orders>-bgamng = wa_orders-gamng.
          ENDIF.

          <l_fs_orders>-bsuom  = wa_mara-meins.
          <l_fs_orders>-gewei  = wa_mara-gewei.
          <l_fs_orders>-ntgew  = wa_mara-ntgew.
        ENDIF.
      ENDLOOP.

      SORT i_mseg   BY aufnr.
      SORT i_msegs1 BY aufnr.
      SORT i_orders BY aufnr.

*** Calculatin the quantity according to the movement type and
*** assign the value to i_orders internal table
      LOOP AT i_orders ASSIGNING <l_fs_orders>.
        CLEAR : wa_msegs.
        READ TABLE i_msegs1 INTO wa_msegs
                            WITH KEY aufnr = <l_fs_orders>-aufnr
                                     matnr = <l_fs_orders>-plnbez.
        IF rb_ezero EQ c_x AND wa_msegs-bmenge1 = 0.
*** Don't want zero production orders
          DELETE i_afvc   WHERE aufnr = <l_fs_orders>-aufnr.
*         DELETE i_orders WHERE aufnr = <l_fs_orders>-aufnr.
          CONTINUE.
        ENDIF.

        <l_fs_orders>-erfmg  = wa_msegs-erfmg1.
        <l_fs_orders>-bmenge = wa_msegs-bmenge1.
        <l_fs_orders>-gruom  = wa_msegs-erfme.
      ENDLOOP.

    ELSE.
*** Here we're Extracting confirmation information
      MOVE 'Extracting Confirmation Information'(025) TO v_output_text.
      PERFORM inform_user_of_progress.

*** get order qty in base UoM and get base UoM and weight UoM
      LOOP AT i_orders ASSIGNING <l_fs_orders>.

        CLEAR : wa_mara.
        READ TABLE i_mara INTO wa_mara
                          WITH KEY matnr = <l_fs_orders>-plnbez.

        IF sy-subrc = 0.
          IF wa_mara-meins <> wa_orders-gmein.
*** convert order quantity to base UoM
            PERFORM conv_to_from_base USING 'X'
                                            <l_fs_orders>-plnbez
                                            <l_fs_orders>-gamng
                                            <l_fs_orders>-gmein
                                            wa_mara-meins
                                   CHANGING <l_fs_orders>-bgamng
                                            v_conv_rc.
          ELSE.
            <l_fs_orders>-bgamng = <l_fs_orders>-gamng.
          ENDIF.

          <l_fs_orders>-bsuom  = wa_mara-meins.
          <l_fs_orders>-gewei  = wa_mara-gewei.
          <l_fs_orders>-ntgew  = wa_mara-ntgew.
        ENDIF.
      ENDLOOP.

*** Select confirmations using operation confirmation number instead of
*** order number
      CLEAR : i_afvv1 , i_afvc1 , i_afru , i_afru1.
*** get 'bottleneck' phases
      LOOP AT i_afvc INTO wa_afvc WHERE steus = 'YBN1'
                                    AND phflg = c_x.
        APPEND wa_afvc TO i_afvc1.
*** get 'bottleneck' phase values
        LOOP AT i_afvv INTO wa_afvv WHERE aufpl = wa_afvc-aufpl
                                      AND aplzl = wa_afvc-aplzl.
          APPEND wa_afvv TO i_afvv1.
        ENDLOOP.
      ENDLOOP.

      IF NOT i_afvc1 IS INITIAL.
        SORT i_afvc1 BY aufpl aplzl plnkn plnty plnnr.
*** get confirmations for the various phases
        SELECT aufnr
               rueck
               gmnga
               lmnga
               gmein
               meinh
               meilr
               stokz
               rueck_mst
               aufpl
               aplzl
          INTO TABLE i_afru
          FROM afru
           FOR ALL ENTRIES IN i_afvc
         WHERE rueck = i_afvc-rueck
           AND werks = p_werks
           AND aufpl = i_afvc-aufpl
           AND aplzl = i_afvc-aplzl.

        SORT i_afru BY aufnr rueck aufpl aplzl.

        LOOP AT i_afvc1 INTO wa_afvc.
          LOOP AT i_afru INTO wa_afru
                         WHERE aufnr = wa_afvc-aufnr
                           AND rueck = wa_afvc-rueck
                           AND aufpl = wa_afvc-aufpl
                           AND aplzl = wa_afvc-aplzl.
*** get 'bottleneck' related confirmations
            APPEND wa_afru TO i_afru1.
          ENDLOOP.
        ENDLOOP.

        IF NOT i_afvv1 IS INITIAL.
          SORT i_afvv1 BY aufpl aplzl.

*** get total confirmation on order for 'bottleneck' phases,
*** this will be the confirmed qty for whole order
          LOOP AT i_afvc ASSIGNING <l_fs_afvc>.

            wa_afvc = <l_fs_afvc>.
*** ensuring the phase is related to a valid PrO
            CLEAR : wa_orders.
            READ TABLE i_orders INTO wa_orders
                                WITH KEY aufnr = wa_afvc-aufnr.
            IF sy-subrc = 0.
*** is it a bottleneck phase?
              READ TABLE i_afvc1 INTO wa_afvc1
                                 WITH KEY aufpl = wa_orders-aufpl
                                          plnty = wa_afvc-plnty
                                          plnnr = wa_afvc-plnnr
                                          plnkn = wa_afvc-plnkn
                                          zaehl = wa_afvc-zaehl.
              IF sy-subrc = 0.
*** get phase operation values
                READ TABLE i_afvv1 INTO wa_afvv1
                                   WITH KEY aufpl = wa_afvc1-aufpl
                                            aplzl = wa_afvc1-aplzl
                                   BINARY SEARCH.
                IF sy-subrc = 0.
*** does the phase have any std runtime m/c confirmations
                  CHECK wa_afvv1-vgw02 NE 0.

*** get actual bottleneck phase confirmations
                  PERFORM get_confirmation_qty_new
                                             USING wa_orders-aufnr
                                                   wa_afvc1-rueck
                                                   wa_afvc1-aufpl
                                                   wa_afvc1-aplzl
                                             CHANGING
                                                   wa_afvc-lmnga
                                                   wa_afvc-cfuom.
*** save confirmation values against phase
                  <l_fs_afvc>-lmnga = wa_afvc-lmnga.
                  <l_fs_afvc>-cfuom = wa_afvc-cfuom.
                ENDIF.
              ENDIF.
            ENDIF.
          ENDLOOP.
        ENDIF.
      ENDIF.

*** retain only bottleneck related confirmation phases,
*** as this gives confirmation qty for order
      i_afvc2 = i_afvc.
*      IF rb_ezero = c_x.
**** no zero confirmation qty phases wanted
*        DELETE i_afvc2 WHERE lmnga EQ 0.
*      ENDIF.
      DELETE ADJACENT DUPLICATES FROM i_afvc2
                                 COMPARING aufnr
                                           aufpl
                                           aplzl
                                           plnkn
                                           plnty
                                           plnnr
                                           zaehl
                                           vornr.

*** get order qty in base UoM and get base UoM and weight UoM
      LOOP AT i_orders ASSIGNING <l_fs_orders>.

*** get confirmed qty
        READ TABLE i_afvc2 INTO wa_afvc
                           WITH KEY aufnr = <l_fs_orders>-aufnr.
        IF sy-subrc = 0.
          <l_fs_orders>-lmnga = wa_afvc-lmnga.
          <l_fs_orders>-cfuom = wa_afvc-cfuom.

          IF <l_fs_orders>-cfuom <> <l_fs_orders>-bsuom.
*** convert confirmation quantity to base UoM
            PERFORM conv_to_from_base USING 'X'
                                            <l_fs_orders>-plnbez
                                            <l_fs_orders>-lmnga
                                            <l_fs_orders>-cfuom
                                            <l_fs_orders>-bsuom
                                   CHANGING <l_fs_orders>-blmnga
                                            v_conv_rc.
          ELSE.
            <l_fs_orders>-blmnga = <l_fs_orders>-lmnga.
          ENDIF.

        ELSE.
*** if the order has no confirmed qty against it, remove it
*** from further processing
          <l_fs_orders>-del = c_x.
        ENDIF.
      ENDLOOP.

*     DELETE i_orders WHERE del = c_x.
    ENDIF.
  ENDIF.
ENDFORM.                    " get_mat_segment

*&---------------------------------------------------------------------*
*&      Form  get_confirmation_qty_new
*&---------------------------------------------------------------------*
FORM get_confirmation_qty_new USING    fp_aufnr TYPE aufnr
                                       fp_rueck TYPE co_rueck
                                       fp_aufpl TYPE co_aufpl
                                       fp_aplzl TYPE co_aplzl
                              CHANGING fp_lmnga TYPE ru_lmnga
                                       fp_cfuom TYPE meins.

  DATA: last_lmnga  TYPE ru_lmnga,
        last_lmnga1 TYPE ru_lmnga,
        last_lmnga2 TYPE ru_lmnga,

        l_v_meinh   TYPE ru_vorme.

  CLEAR: last_lmnga.

* Check this record. If there is no link to another confirmation and
* a quantity has been confirmed and it is a milestone confirmation
* then we want to select all of the confirmations for it.
  LOOP AT i_afru1 INTO wa_afru1 WHERE aufnr = fp_aufnr
                                  AND rueck = fp_rueck
                                  AND aufpl = fp_aufpl
                                  AND aplzl = fp_aplzl.
    CHECK wa_afru1-lmnga NE 0.

    IF l_v_meinh IS INITIAL.
      l_v_meinh = wa_afru1-meinh.
    ENDIF.

    last_lmnga1 = wa_afru1-lmnga.

    IF l_v_meinh <> wa_afru1-meinh.
      CLEAR : last_lmnga2.
      PERFORM conv_to_from_base USING 'X'
                                      wa_orders-plnbez
                                      wa_afru1-lmnga
                                      wa_afru1-meinh
                                      wa_orders-bsuom
                             CHANGING last_lmnga2
                                      v_conv_rc.

      PERFORM conv_to_from_base USING ' '
                                      wa_orders-plnbez
                                      last_lmnga2
                                      l_v_meinh
                                      wa_orders-bsuom
                             CHANGING last_lmnga1
                                      v_conv_rc.

    ENDIF.

    IF wa_afru1-stokz IS INITIAL.
      last_lmnga = last_lmnga + last_lmnga1.
    ELSE.
      last_lmnga = last_lmnga - last_lmnga1.
    ENDIF.
  ENDLOOP.

  MOVE last_lmnga TO fp_lmnga.
  fp_cfuom = l_v_meinh.

ENDFORM.                    " get_confirmation_qty_new

*&---------------------------------------------------------------------*
*&      Form  get_bom_info
*&---------------------------------------------------------------------*
FORM get_bom_info.
  DATA: l_tabix TYPE sytabix,

        l_v_kausf TYPE kausf,

        l_v_dmeng  TYPE ty_menge,
        l_v_dmengs TYPE ty_menge,
        l_v_dmengz TYPE ty_menge,

        l_v_menge TYPE kmpmg,

        l_v_mnglg  TYPE cs_e_mnglg,
        l_v_mnglgs TYPE cs_e_mnglg,
        l_v_mnglgz TYPE cs_e_mnglg,

        l_i_bomapp  TYPE STANDARD TABLE OF ty_bomapp,
        l_wa_bomapp TYPE ty_bomapp,

        l_idx TYPE ttidx.            "NEEL 4/6/2005

  FIELD-SYMBOLS : <l_fs_orders>  TYPE ty_orders,
                  <l_fs_ordmats> TYPE ty_ordmats.

  IF NOT i_orders[] IS INITIAL.
* this tells users whats happening
    MOVE 'Extracting BOM Information'(026) TO v_output_text.
    PERFORM inform_user_of_progress.

* Get order related bom appln
    CLEAR : l_i_bomapp.

    SELECT werks
           auart
           capid
      FROM t399x
      INTO TABLE l_i_bomapp
       FOR ALL ENTRIES IN i_orders
     WHERE werks = i_orders-werks
       AND auart = i_orders-auart.

    SORT l_i_bomapp BY werks auart.

* Get issued materials for all process orders
    IF i_mseg1 IS INITIAL.
* get materials to process
      PERFORM get_order_mats.

      i_mseg   = i_mseg1.
      i_msegs1 = i_msegs.
    ENDIF.

    LOOP AT i_orders ASSIGNING <l_fs_orders>.
      DELETE i_mseg WHERE aufnr =  <l_fs_orders>-aufnr
                      AND matnr <> <l_fs_orders>-plnbez.

      DELETE i_msegs1 WHERE aufnr =  <l_fs_orders>-aufnr
                        AND matnr <> <l_fs_orders>-plnbez.

      CLEAR : l_wa_bomapp.
*** Assign a default in case read fails
      l_wa_bomapp-capid = 'PI01'.
      READ TABLE l_i_bomapp INTO l_wa_bomapp
                            WITH KEY werks = <l_fs_orders>-werks
                                     auart = <l_fs_orders>-auart
                            BINARY SEARCH.
*** Get BOM application id
      <l_fs_orders>-capid = l_wa_bomapp-capid.

*** Get list of materials that have been issued
      LOOP AT i_mseg1 INTO wa_issued_mat
                      WHERE aufnr = <l_fs_orders>-aufnr
                        AND bwart IN i_r_bwart.
        APPEND wa_issued_mat TO i_issued_mat.
      ENDLOOP.
    ENDLOOP.

    CLEAR : i_bomdat.
* do BOM explosion and get related BOM data for the materials
    LOOP AT i_orders ASSIGNING <l_fs_orders>.
*** build key table for later selection from table PLPO,
*** the master recipe table
      wa_plpo_sel-plnty = <l_fs_orders>-plnty.
      wa_plpo_sel-plnnr = <l_fs_orders>-plnnr.
      wa_plpo_sel-zaehl = <l_fs_orders>-zaehl.
      APPEND wa_plpo_sel TO i_plpo_sel.

*** build key table for later selection from table AFRU,
*** the confirmations table
      wa_afru_sel-rueck = <l_fs_orders>-rueck.
      APPEND wa_afru_sel TO i_afru_sel.

      l_tabix = sy-tabix.

      CLEAR : wa_tmat , i_stbtmp , wa_bomdat.
*** check if same BOM has been retrieved before
      READ TABLE i_bomdat INTO wa_bomdat
                          WITH KEY capid = <l_fs_orders>-capid
                                   datuv = <l_fs_orders>-sdatv
                                   mtnrv = <l_fs_orders>-plnbez
                                   stlal = <l_fs_orders>-stlal
                                   stlan = <l_fs_orders>-stlan
                                   werks = <l_fs_orders>-werks.
      IF sy-subrc = 0.
*** if yes then use it
        wa_tmat  = wa_bomdat-tmat.
        i_stbtmp = wa_bomdat-stb.

      ELSE.
*** if no then get BOM explosion
        CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'
          EXPORTING
            aumgb                       = 'X'
            capid                       = <l_fs_orders>-capid
*            datuv                       = <l_fs_orders>-sdatv
*** Begin of change on 31-05-2005
            datuv                       = <l_fs_orders>-aufld
            " 31-05-2005
*** End of change on 31-05-2005
            mbwls                       = 'X'
            mehrs                       = 'X'
            mtnrv                       = <l_fs_orders>-plnbez
            stlal                       = <l_fs_orders>-stlal
            stlan                       = <l_fs_orders>-stlan
            werks                       = <l_fs_orders>-werks
          IMPORTING
            topmat                      = wa_tmat
          TABLES
            stb                         = i_stbtmp
*          matcat                      = i_cmat
          EXCEPTIONS
            alt_not_found               = 1
            call_invalid                = 2
            material_not_found          = 3
            missing_authorization       = 4
            no_bom_found                = 5
            no_plant_data               = 6
            no_suitable_bom_found       = 7
            conversion_error            = 8
            OTHERS                      = 9.
        IF sy-subrc = 0.
*** add to BOM buffer table
          wa_bomdat-capid = <l_fs_orders>-capid.
          wa_bomdat-datuv = <l_fs_orders>-sdatv.
          wa_bomdat-mtnrv = <l_fs_orders>-plnbez.
          wa_bomdat-stlal = <l_fs_orders>-stlal.
          wa_bomdat-stlan = <l_fs_orders>-stlan.
          wa_bomdat-werks = <l_fs_orders>-werks.
          wa_bomdat-tmat  = wa_tmat.
          wa_bomdat-stb   = i_stbtmp.

          INSERT wa_bomdat INTO TABLE i_bomdat.

          DELETE i_stbtmp WHERE schgt = c_x.
        ENDIF.
      ENDIF.

      IF NOT i_stbtmp IS INITIAL.
*** First get the primary level values from the exploded BOM
        LOOP AT i_stbtmp INTO wa_stb WHERE stlal = <l_fs_orders>-stlal
                                       AND stlan = <l_fs_orders>-stlan
                                       AND stlty = <l_fs_orders>-stlty
                                       AND stlnr = <l_fs_orders>-stlnr.

          CHECK wa_stb-postp <> 'N'.

          CLEAR : wa_ordmats.
          wa_ordmats-aufnr = <l_fs_orders>-aufnr.
          wa_ordmats-matnr = wa_stb-idnrk.
          wa_ordmats-mtart = wa_stb-mtart.
          wa_ordmats-stufe = wa_stb-stufe.
*>>NEEL 4/6/2005
          wa_ordmats-wegxx = wa_stb-wegxx.
          wa_ordmats-ttidx = wa_stb-ttidx.
          wa_ordmats-vwegx = wa_stb-vwegx.
*<<NEEL 4/6/2005
          wa_ordmats-ojtxb = wa_stb-ojtxb.
          wa_ordmats-ojtxp = wa_stb-ojtxp.

          wa_ordmats-ausch  = wa_stb-ausch.
*         wa_ordmats-yyzero = wa_stb-yyzero.

          IF NOT wa_stb-ausch IS INITIAL.
            l_v_kausf = 1 + ( wa_stb-ausch / 100 ).
          ELSE.
            l_v_kausf = 1 + ( wa_stb-kausf / 100 ).
          ENDIF.

          wa_ordmats-kausf  = l_v_kausf.

          wa_ordmats-menge  = wa_stb-menge.
          wa_ordmats-menges = wa_stb-menge * wa_ordmats-kausf.
*          wa_ordmats-mengez = wa_stb-menge * wa_ordmats-yyzero.
          wa_ordmats-meins  = wa_stb-meins.

          wa_ordmats-xmeng  = wa_stb-xmeng.
          wa_ordmats-xmengs = wa_stb-xmeng * wa_ordmats-kausf.
*         wa_ordmats-xmengz = wa_stb-xmeng * wa_ordmats-yyzero.

          wa_ordmats-xmein  = wa_stb-xmein.

          wa_ordmats-mnglg  = wa_stb-mnglg.
          wa_ordmats-mnglgs = wa_stb-mnglg.
          wa_ordmats-mnglgz = wa_stb-mnglg.
          wa_ordmats-mmein  = wa_stb-mmein.
          wa_ordmats-msign  = wa_stb-msign.
          wa_ordmats-postp  = wa_stb-postp.

          IF wa_stb-kzkup = space AND wa_stb-msign = '-'.
            wa_ordmats-byprod = c_x.
          ENDIF.

          wa_ordmats-stprs = wa_stb-stprs.
          wa_ordmats-peinh = wa_stb-preih.

          wa_ordmats-bom    = c_x.

          wa_ordmats-stlty = wa_stb-stlty.
          wa_ordmats-stlnr = wa_stb-stlnr.
          wa_ordmats-stlkn = wa_stb-stlkn.
          wa_ordmats-stpoz = wa_stb-stpoz.

          APPEND wa_ordmats TO i_ordmats.
        ENDLOOP.

*** now recurse into exploded BOM to get lower level details
        LOOP AT i_ordmats ASSIGNING <l_fs_ordmats> WHERE bomd <> c_x.

          IF <l_fs_ordmats>-xmeng > 0.
            l_v_dmeng  = <l_fs_ordmats>-menge  / <l_fs_ordmats>-xmeng.
            l_v_dmengs = <l_fs_ordmats>-menges / <l_fs_ordmats>-xmeng.
            l_v_dmengz = <l_fs_ordmats>-mengez / <l_fs_ordmats>-xmeng.

          ELSE.
            l_v_dmeng  = 1.
            l_v_dmengs = 1.
            l_v_dmengz = 1.
          ENDIF.

          l_idx = <l_fs_ordmats>-stufe + 1.      "NEEL 4/6/2005++
          LOOP AT i_stbtmp INTO wa_stb
*                           WHERE ojtxb = <l_fs_ordmats>ojtxp. NEEL-
                      WHERE ttidx = l_idx               "NEEL 4/6/2005
                        AND vwegx = <l_fs_ordmats>-wegxx.
            CLEAR : wa_ordmats.
            wa_ordmats-aufnr = <l_fs_orders>-aufnr.
            wa_ordmats-matnr = wa_stb-idnrk.
            wa_ordmats-mtart = wa_stb-mtart.
            wa_ordmats-stufe = wa_stb-stufe.
*>>NEEL 4/6/2005
            wa_ordmats-wegxx = wa_stb-wegxx.
            wa_ordmats-ttidx = wa_stb-ttidx.
            wa_ordmats-vwegx = wa_stb-vwegx.
*<<NEEL 4/6/2005
            wa_ordmats-ojtxb = wa_stb-ojtxb.
            wa_ordmats-ojtxp = wa_stb-ojtxp.

            wa_ordmats-ausch  = wa_stb-ausch.
*           wa_ordmats-yyzero = wa_stb-yyzero.

            IF NOT wa_stb-ausch IS INITIAL.
              l_v_kausf = 1 + ( wa_stb-ausch / 100 ).
            ELSE.
              l_v_kausf = 1 + ( wa_stb-kausf / 100 ).
            ENDIF.
            wa_ordmats-kausf  = l_v_kausf.

            l_v_menge = wa_stb-menge * l_v_dmengs.
            wa_ordmats-menges = l_v_menge * wa_ordmats-kausf.

            l_v_menge = wa_stb-menge * l_v_dmengz.
*           wa_ordmats-mengez = l_v_menge * wa_ordmats-yyzero.

            l_v_menge = wa_stb-menge * l_v_dmeng.
            wa_ordmats-menge = l_v_menge.

            wa_ordmats-meins = wa_stb-meins.

            l_v_mnglg  = wa_ordmats-menge.
            l_v_mnglgs = wa_ordmats-menges.
            l_v_mnglgz = wa_ordmats-mengez.

            IF wa_stb-meins = wa_stb-mmein.
              wa_ordmats-mnglg  = l_v_mnglg.
              wa_ordmats-mnglgs = l_v_mnglgs.
              wa_ordmats-mnglgz = l_v_mnglgz.

            ELSE.
* convert BOM quantity to base UoM
              PERFORM conv_to_from_base USING 'X'
                                              wa_ordmats-matnr
                                              l_v_mnglg
                                              wa_ordmats-meins
                                              wa_ordmats-mmein
                                     CHANGING wa_ordmats-mnglg
                                              v_conv_rc.

              PERFORM conv_to_from_base USING 'X'
                                              wa_ordmats-matnr
                                              l_v_mnglgs
                                              wa_ordmats-meins
                                              wa_ordmats-mmein
                                     CHANGING wa_ordmats-mnglgs
                                              v_conv_rc.

              PERFORM conv_to_from_base USING 'X'
                                              wa_ordmats-matnr
                                              l_v_mnglgz
                                              wa_ordmats-meins
                                              wa_ordmats-mmein
                                     CHANGING wa_ordmats-mnglgz
                                              v_conv_rc.
            ENDIF.
            wa_ordmats-mmein = wa_stb-mmein.
            wa_ordmats-msign = wa_stb-msign.

            wa_ordmats-xmeng  = wa_stb-xmeng.
            wa_ordmats-xmengs = wa_stb-xmeng * wa_ordmats-kausf.
*           wa_ordmats-xmengz = wa_stb-xmeng * wa_ordmats-yyzero.

            wa_ordmats-xmein = wa_stb-xmein.

            wa_ordmats-stprs = wa_stb-stprs.
            wa_ordmats-peinh = wa_stb-preih.
*           wa_ordmats-yyzero = wa_stb-yyzero.
            wa_ordmats-bom    = c_x.

            wa_ordmats-stlty = wa_stb-stlty.
            wa_ordmats-stlnr = wa_stb-stlnr.
            wa_ordmats-stlkn = wa_stb-stlkn.
            wa_ordmats-stpoz = wa_stb-stpoz.

            APPEND wa_ordmats TO i_ordmats.
          ENDLOOP.

          <l_fs_ordmats>-bomd = c_x.
        ENDLOOP.

        <l_fs_orders>-maktx = wa_tmat-maktx.
        <l_fs_orders>-bmeng = wa_tmat-bmeng.
        <l_fs_orders>-bmein = wa_tmat-bmein.
        <l_fs_orders>-kausf = wa_tmat-kausf.

        IF <l_fs_orders>-bmein <> <l_fs_orders>-bsuom.
* convert BOM base quantity to base UoM
          PERFORM conv_to_from_base USING 'X'
                                          <l_fs_orders>-plnbez
                                          <l_fs_orders>-bmeng
                                          <l_fs_orders>-bmein
                                          <l_fs_orders>-bsuom
                                 CHANGING <l_fs_orders>-bbmeng
                                          v_conv_rc.
        ELSE.
          <l_fs_orders>-bbmeng = <l_fs_orders>-bmeng.
        ENDIF.
      ENDIF.
    ENDLOOP.

    SORT i_ordmats BY aufnr matnr.

* Selecting reservations for order
    SELECT rsnum rspos rsart xloek matnr werks bdmng meins shkzg
           aufnr dumps aufpl vornr aplzl
           postp kzkup rgekz ausch
           stlty stlnr stlkn stpoz bwart
      FROM resb INTO TABLE i_resb
       FOR ALL ENTRIES IN i_orders
     WHERE rsnum = i_orders-rsnum
*       AND xloek = ' '
       AND aufnr = i_orders-aufnr
       AND bdmng > 0
       AND dumps = space
       AND postp <> 'N'
       AND schgt = space.

    LOOP AT i_resb INTO wa_resb.
      READ TABLE i_issued_mat INTO wa_issued_mat
                              WITH KEY matnr = wa_resb-matnr.
      CHECK sy-subrc <> 0.
*** If a material was issued but is not part of the PrO
*** reservations, add it to list
      CLEAR : wa_issued_mat.
      wa_issued_mat-matnr = wa_resb-matnr.
      wa_issued_mat-werks = wa_resb-werks.
      APPEND wa_issued_mat TO i_issued_mat.
    ENDLOOP.

* we just need the issued mat numbers not captured by BOM explosion
    SORT i_issued_mat BY matnr.
    DELETE ADJACENT DUPLICATES FROM i_issued_mat COMPARING matnr.

    IF NOT i_issued_mat IS INITIAL.
* get material master data
      SELECT matnr
             mtart
             meins
             gewei
        FROM mara
   APPENDING TABLE i_mara
         FOR ALL ENTRIES IN i_issued_mat
       WHERE matnr = i_issued_mat-matnr.

* getting pricing data
      CLEAR : i_mbew1 , i_material_des.
      SELECT matnr bwkey stprs peinh
        FROM mbew
        INTO TABLE i_mbew1
         FOR ALL ENTRIES IN i_issued_mat
       WHERE matnr = i_issued_mat-matnr
         AND bwkey = i_issued_mat-werks.

* Selecting material descriptions
      SELECT matnr maktx
        FROM makt
        INTO TABLE i_material_des
         FOR ALL ENTRIES IN i_issued_mat
       WHERE spras = sy-langu
         AND matnr = i_issued_mat-matnr.
    ENDIF.

* prepare selection table for selecting from AFRU
    LOOP AT i_afvc INTO wa_afvc.
      wa_plpo_sel-plnty = wa_afvc-plnty.
      wa_plpo_sel-plnnr = wa_afvc-plnnr.
      wa_plpo_sel-plnkn = wa_afvc-plnkn.
      wa_plpo_sel-zaehl = wa_afvc-zaehl.
      APPEND wa_plpo_sel TO i_plpo_sel.

      wa_afru_sel-rueck = wa_afvc-rueck.
      APPEND wa_afru_sel TO i_afru_sel.
    ENDLOOP.

    SORT : i_plpo_sel , i_afru_sel.

    DELETE ADJACENT DUPLICATES FROM i_plpo_sel.
    DELETE ADJACENT DUPLICATES FROM i_afru_sel.

* Retrieve task list information of operations/activity from PLPO table
    SELECT *
      FROM plpo
      INTO TABLE i_plpo
       FOR ALL ENTRIES IN i_plpo_sel
     WHERE plnty = i_plpo_sel-plnty
       AND plnnr = i_plpo_sel-plnnr
       AND zaehl = i_plpo_sel-zaehl.
    IF sy-subrc = 0.
      SORT i_plpo BY plnty plnnr plnkn datuv DESCENDING.
    ENDIF.
* get confirmation data for order and its items
    SELECT rueck
           rmzhl
           ism01
           ile01
           ism02
           ile02
           ism03
           ile03
           ism04
           ile04
           ism05
           ile05
           ism06
           ile06
           stokz
      FROM afru
      INTO TABLE i_ord_conf
       FOR ALL ENTRIES IN i_afru_sel
     WHERE rueck = i_afru_sel-rueck.
  ENDIF.

  IF NOT i_afvc IS INITIAL.
    LOOP AT i_afvc INTO wa_afvc.
*** get master recipe records for selected phases
      LOOP AT i_plpo INTO wa_plpo WHERE plnty = wa_afvc-plnty
                                    AND plnnr = wa_afvc-plnnr
                                    AND plnkn = wa_afvc-plnkn
                                    AND zaehl = wa_afvc-zaehl.
        APPEND wa_plpo TO i_plpo1.
      ENDLOOP.

*** get confirmation records for selected phases
      LOOP AT i_ord_conf INTO wa_ord_conf WHERE rueck = wa_afvc-rueck.
        APPEND wa_ord_conf TO i_ord_conf1.
      ENDLOOP.
    ENDLOOP.

    SORT i_plpo1 BY plnty plnnr plnkn zaehl datuv DESCENDING.
  ENDIF.

  UNASSIGN : <l_fs_orders>.
ENDFORM.                    " get_bom_info

*&--------------------------------------------------------------------*
*&      Form  build_output_tabs
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM build_output_tabs.
  DATA : l_qty   TYPE gamng,
         l_effic TYPE vgwrt,
         l_tmp   TYPE vgwrt,
         l_tmp1  TYPE vgwrt,

         l_lmnga  TYPE lmnga,

         l_v_rc    TYPE char1,
         l_v_kausf TYPE kausf,
         l_v_sumi  TYPE char1,

         l_v_smeng  TYPE ty_menge,
         l_v_smengs TYPE ty_menge,
         l_v_smengz TYPE ty_menge,

         l_wa_afvv  TYPE ty_afvv.

  FIELD-SYMBOLS : <l_fs_resb> TYPE ty_resb.

  MOVE 'Formatting Output'(027) TO v_output_text.
  PERFORM inform_user_of_progress.

  CLEAR: i_marc1.
  SELECT matnr
         werks
         frtme
    FROM marc
    INTO TABLE i_marc1
     FOR ALL ENTRIES IN i_orders
   WHERE matnr = i_orders-plnbez
     AND werks = i_orders-werks.
* Not required to handle, ok if prod unit not found

* get parameter IDs
  SELECT vgwts
         par01
         par02
         par03
         par04
         par05
         par06
    FROM tc21
    INTO TABLE i_param
     FOR ALL ENTRIES IN i_afvc
   WHERE vgwts = i_afvc-vgwts.

  IF sy-subrc = 0.
* get parameter ID texts
    SELECT parid
           txtlg
      FROM tc20t
      INTO TABLE i_param_key
       FOR ALL ENTRIES IN i_param
     WHERE spras = sy-langu
       AND ( parid = i_param-par01
          OR parid = i_param-par02
          OR parid = i_param-par03
          OR parid = i_param-par04
          OR parid = i_param-par05
          OR parid = i_param-par06 ).
  ENDIF.

* Selecting Work centers descriptions
  SELECT objid ktext
    FROM crtx
    INTO TABLE i_wc_text
     FOR ALL ENTRIES IN i_afvc
   WHERE objty = c_objtyp
     AND objid = i_afvc-arbid
     AND spras = sy-langu.
*Work centers descriptions are optional

  SELECT matnr bwkey stprs peinh
    FROM mbew
    APPENDING TABLE i_mbew1
     FOR ALL ENTRIES IN i_orders
   WHERE matnr = i_orders-plnbez
     AND bwkey = i_orders-werks.

  LOOP AT i_orders INTO wa_orders.
***
*** Build Order Table
***
    wa_h_ord-aufnr = wa_orders-aufnr.

    wa_h_ord-gltrp = wa_orders-gltrp.
    wa_h_ord-gstrp = wa_orders-gstrp.

    wa_h_ord-plnbez = wa_orders-plnbez.
    wa_h_ord-maktx  = wa_orders-maktx.

    wa_h_ord-lmnga  = wa_orders-lmnga.
    wa_h_ord-blmnga = wa_orders-blmnga.
    wa_h_ord-bmenge = wa_orders-bmenge.
    wa_h_ord-bgamng = wa_orders-bgamng.
    wa_h_ord-bbmeng = wa_orders-bbmeng.

    wa_h_ord-gruom = wa_orders-gruom.
    wa_h_ord-cfuom = wa_orders-cfuom.
    wa_h_ord-bsuom = wa_orders-bsuom.

    CLEAR : wa_marc1.
    READ TABLE i_marc1 INTO wa_marc1 WITH KEY matnr = wa_orders-plnbez
                                              werks = wa_orders-werks.
    wa_h_ord-frtme = wa_marc1-frtme.
    wa_h_ord-gewei = wa_orders-gewei.
    wa_h_ord-ntgew = wa_orders-ntgew.

    IF rb_pland = c_x.
* Planned Production Quantities
      wa_h_ord-prduom = wa_h_ord-frtme.
      wa_h_ord-prdqty = wa_h_ord-bgamng.
    ELSE.
* Actual Production Quantities
      IF rb_prod = c_x.
*** Produced Qty
        wa_h_ord-prdqty = wa_h_ord-bmenge.
        wa_h_ord-prduom = wa_h_ord-gruom.
      ELSE.
*** Confirmed Qty
        wa_h_ord-prdqty = wa_h_ord-blmnga.
        wa_h_ord-prduom = wa_h_ord-cfuom.
      ENDIF.
    ENDIF.

    wa_h_ord-bprdqty = wa_h_ord-prdqty.

    IF wa_h_ord-prduom <> wa_h_ord-bsuom.
      l_qty = wa_h_ord-prdqty.
      PERFORM conv_to_from_base USING ' '
                                      wa_h_ord-plnbez
                                      l_qty
                                      wa_h_ord-prduom
                                      wa_h_ord-bsuom
                             CHANGING wa_h_ord-prdqty
                                      v_conv_rc.
      IF v_conv_rc = 'X'.
        wa_h_ord-prdqty = l_qty.
        wa_h_ord-prduom = wa_h_ord-bsuom.
      ENDIF.
    ENDIF.

* Resource Information
    CLEAR : wa_afvc , wa_crhd , wa_wc_text.
    READ TABLE i_afvc INTO wa_afvc WITH KEY aufpl = wa_orders-aufpl
                                            steus = 'YBN1'.
    IF sy-subrc = 0.
      READ TABLE i_crhd INTO wa_crhd WITH KEY objid = wa_afvc-arbid.
      READ TABLE i_wc_text INTO wa_wc_text WITH KEY objid =
      wa_afvc-arbid.
    ENDIF.

    wa_h_ord-botlnck = wa_crhd-arbpl.
    wa_h_ord-resdesc = wa_wc_text-ktext.

* Expected Line Efficiency
    CLEAR : i_plpo2 , l_effic.
    LOOP AT i_plpo1 INTO wa_plpo WHERE plnty = wa_orders-plnty
                                   AND plnnr = wa_orders-plnnr
                                   AND steus = 'YBN1'.
      IF NOT wa_plpo-vgw02 IS INITIAL.
        l_effic = wa_plpo-usr04.

        wa_plpo2 = wa_plpo.
        APPEND wa_plpo2 TO i_plpo2.
      ENDIF.
    ENDLOOP.

    wa_h_ord-el_effc = l_effic.

* Actual Line Efficiency
    CLEAR : l_tmp , l_tmp1 , l_effic.
    LOOP AT i_plpo2 INTO wa_plpo2.
      CLEAR: wa_afvc, wa_afvv , l_effic.
      READ TABLE i_afvc INTO wa_afvc WITH KEY plnty = wa_plpo2-plnty
                                              plnnr = wa_plpo2-plnnr
                                              plnkn = wa_plpo2-plnkn
                                              zaehl = wa_plpo2-zaehl
                                              aufpl = wa_orders-aufpl.
      IF sy-subrc = 0.
        READ TABLE i_afvv INTO wa_afvv WITH KEY aufpl = wa_afvc-aufpl
                                                aplzl = wa_afvc-aplzl.
        IF wa_plpo2-vgw02 <> 0.
          l_tmp = wa_plpo2-bmsch / wa_plpo2-vgw02.

          IF l_tmp <> 0.
            l_tmp1 = wa_afvv-lmnga / l_tmp.

            IF wa_afvv-ism02 <> 0.
              l_tmp1 = ( l_tmp1 / wa_afvv-ism02 ) * 100.
              MOVE l_tmp1 TO l_effic.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDLOOP.

    wa_h_ord-ac_effc = l_effic.

    CLEAR : wa_mbew1.
    READ TABLE i_mbew1 INTO wa_mbew1 WITH KEY matnr = wa_orders-plnbez
                                              bwkey = wa_orders-werks.
    wa_h_ord-stprs = wa_mbew1-stprs.
    wa_h_ord-peinh = wa_mbew1-peinh.

    APPEND wa_h_ord TO i_h_ord.

***
*** Build Phase Table
***
    LOOP AT i_afvc INTO wa_afvc WHERE aufnr = wa_orders-aufnr
                                  AND aufpl = wa_orders-aufpl.
      CLEAR : wa_h_phs.

      wa_h_phs-aufnr = wa_afvc-aufnr.
      wa_h_phs-aufpl = wa_afvc-aufpl.
      wa_h_phs-aplzl = wa_afvc-aplzl.
      wa_h_phs-vornr = wa_afvc-vornr.

      wa_h_phs-steus = wa_afvc-steus.
      wa_h_phs-rueck = wa_afvc-rueck.
      wa_h_phs-vgwts = wa_afvc-vgwts.
      wa_h_phs-ltxa1 = wa_afvc-ltxa1.

      IF wa_afvc-cfuom IS INITIAL.
        CLEAR : wa_afvv, l_lmnga.
        LOOP AT i_afvv INTO l_wa_afvv WHERE aufpl = wa_afvc-aufpl
                                        AND aplzl = wa_afvc-aplzl.
          wa_h_phs-lmnga = wa_h_phs-lmnga + l_wa_afvv-lmnga.
        ENDLOOP.
        wa_h_phs-cfuom = l_wa_afvv-meinh.

      ELSE.
        wa_h_phs-lmnga = wa_afvc-lmnga.
        wa_h_phs-cfuom = wa_afvc-cfuom.

* afvv contains std vals for operation qty
        CLEAR : l_wa_afvv.
        READ TABLE i_afvv INTO l_wa_afvv
                          WITH KEY aufpl = wa_afvc-aufpl
                                   aplzl = wa_afvc-aplzl.
      ENDIF.

      wa_h_phs-bsuom = wa_h_ord-bsuom.
      wa_h_phs-gewei = wa_h_ord-gewei.
      wa_h_phs-ntgew = wa_h_ord-ntgew.

      IF wa_h_phs-cfuom <> wa_h_phs-bsuom.
        l_lmnga = wa_h_phs-lmnga.
        PERFORM conv_to_from_base USING 'X'
                                        wa_h_ord-plnbez
                                        l_lmnga
                                        wa_h_phs-cfuom
                                        wa_h_phs-bsuom
                               CHANGING wa_h_phs-blmnga
                                        v_conv_rc.
        IF v_conv_rc = 'X'.
          CLEAR : wa_h_phs-blmnga.
        ENDIF.

      ELSE.
        wa_h_phs-blmnga = wa_h_phs-lmnga.
      ENDIF.

      IF rb_actl = c_x AND rb_conf = c_x.
        wa_h_phs-prduom  = wa_h_ord-cfuom.
        wa_h_phs-prdqty  = wa_h_ord-lmnga.
        wa_h_phs-bprdqty = wa_h_ord-blmnga.

      ELSE.
        wa_h_phs-prduom  = wa_h_ord-prduom.
        wa_h_phs-prdqty  = wa_h_ord-prdqty.
        wa_h_phs-bprdqty = wa_h_ord-bprdqty.
      ENDIF.

      wa_h_phs-arbid = wa_afvc-arbid.

      CLEAR : wa_crhd , wa_wc_text.
      READ TABLE i_crhd INTO wa_crhd WITH KEY objid = wa_afvc-arbid.

      READ TABLE i_wc_text INTO wa_wc_text
                           WITH KEY objid = wa_afvc-arbid.

      wa_h_phs-arbpl = wa_crhd-arbpl.
      wa_h_phs-ktext = wa_wc_text-ktext.

      IF wa_h_phs-steus = 'YBN1'.
* Expected Line Efficiency
        CLEAR : i_plpo2 , l_effic.
        LOOP AT i_plpo1 INTO wa_plpo WHERE plnty = wa_afvc-plnty
                                       AND plnnr = wa_afvc-plnnr
                                       AND plnkn = wa_afvc-plnkn
                                       AND zaehl = wa_afvc-zaehl
                                       AND steus = 'YBN1'.
          IF NOT wa_plpo-vgw02 IS INITIAL.
            l_effic = wa_plpo-usr04.

            wa_plpo2 = wa_plpo.
            APPEND wa_plpo2 TO i_plpo2.
          ENDIF.
        ENDLOOP.

        wa_h_phs-el_effc = l_effic.

* Actual Line Efficiency
        CLEAR : l_tmp , l_tmp1 , l_effic.
        LOOP AT i_plpo2 INTO wa_plpo2.
          CLEAR: l_effic.
          IF wa_plpo2-vgw02 <> 0.
            l_tmp = wa_plpo2-bmsch / wa_plpo2-vgw02.

            IF l_tmp <> 0.
              l_tmp1 = l_wa_afvv-lmnga / l_tmp.

              IF l_wa_afvv-ism02 <> 0.
                l_tmp1 = ( l_tmp1 / l_wa_afvv-ism02 ) * 100.
                MOVE l_tmp1 TO l_effic.

                wa_h_phs-runtime = c_x.
              ENDIF.
            ENDIF.
          ENDIF.
        ENDLOOP.

        wa_h_phs-ac_effc = l_effic.
      ENDIF.
***
*** Build Phase-Activity Table
***
      CLEAR : l_v_rc.
      PERFORM build_act_tab USING    wa_orders-aufnr  wa_orders-plnbez
                                     wa_h_phs-bprdqty wa_h_phs-bsuom
                                     wa_orders-gmein
                                     wa_h_phs-el_effc wa_afvc
                                     l_wa_afvv
                            CHANGING l_v_rc.
      IF l_v_rc = c_x.
        APPEND wa_h_phs TO i_h_phs.
      ENDIF.
***
*** Build Material-Phase Table
***
      LOOP AT i_resb ASSIGNING <l_fs_resb>
                         WHERE aufnr = wa_orders-aufnr.

        IF <l_fs_resb>-aufpl = wa_afvc-aufpl AND
           <l_fs_resb>-vornr = wa_afvc-vornr AND
           <l_fs_resb>-aplzl = wa_afvc-aplzl.

          CLEAR : wa_resb.
          PERFORM build_mat_tab USING <l_fs_resb>.
          <l_fs_resb>-flagp = c_y.

        ELSEIF <l_fs_resb>-flagp IS INITIAL.
          <l_fs_resb>-flagp = 'N'.
        ENDIF.
      ENDLOOP.
    ENDLOOP.

****
**** Add Extra Materials to Material-Phase Table
****
    LOOP AT i_resb ASSIGNING <l_fs_resb>
                       WHERE aufnr = wa_orders-aufnr
                         AND flagp = 'N'.
      CLEAR : wa_resb.
      PERFORM build_mat_tab USING <l_fs_resb>.
    ENDLOOP.
  ENDLOOP.

  SORT i_h_ord BY aufnr.
  SORT i_h_mat BY aufnr aufpl aplzl matnr byprod.

  SORT i_h_phs BY aufnr vornr.
  SORT i_h_act BY aufnr vornr.

  LOOP AT i_h_mat INTO wa_h_mat.
    CLEAR : l_v_sumi.

    AT END OF byprod.
      l_v_sumi = c_x.
    ENDAT.

    wa_h_mat-sumi = l_v_sumi.

    MODIFY i_h_mat FROM wa_h_mat TRANSPORTING sumi.
  ENDLOOP.

ENDFORM.                    "build_output_tabs

*&--------------------------------------------------------------------*
*&      Form  build_mat_tab
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM build_mat_tab USING fp_resb TYPE ty_resb.

  DATA : l_v_kausf TYPE kausf,

         l_v_smeng  TYPE ty_menge,
         l_v_smengs TYPE ty_menge,
         l_v_smengz TYPE ty_menge.

  wa_resb = fp_resb.

  CLEAR : wa_h_mat , l_v_smeng , l_v_smengs ,
          l_v_smengz.

  CHECK wa_resb-postp <> 'N' AND
        NOT ( wa_resb-kzkup = c_x AND
              wa_resb-matnr = wa_h_ord-plnbez ).

  wa_h_mat-aufnr = wa_resb-aufnr.
  wa_h_mat-aufpl = wa_resb-aufpl.
  wa_h_mat-aplzl = wa_resb-aplzl.
  wa_h_mat-vornr = wa_resb-vornr.

  wa_h_mat-matnr = wa_resb-matnr.

  CLEAR : wa_mara.
  READ TABLE i_mara INTO wa_mara WITH KEY matnr = wa_h_mat-matnr.

  CLEAR : wa_msegs.
  READ TABLE i_msegs INTO wa_msegs WITH KEY aufnr = wa_h_mat-aufnr
                                            matnr = wa_h_mat-matnr
                                            bwart = wa_resb-bwart.
  IF sy-subrc <> 0.
    READ TABLE i_msegs INTO wa_msegs WITH KEY aufnr = wa_h_mat-aufnr
                                              matnr = wa_h_mat-matnr.
  ENDIF.

  CLEAR : wa_ordmats.
  READ TABLE i_ordmats INTO wa_ordmats
                       WITH KEY aufnr = wa_resb-aufnr
                                matnr = wa_resb-matnr
                                stlty = wa_resb-stlty
                                stlnr = wa_resb-stlnr
                                stlkn = wa_resb-stlkn
                                stpoz = wa_resb-stpoz.
  IF sy-subrc = 0.
    wa_h_mat-maktx = wa_ordmats-ojtxp.

    wa_h_mat-stprs = wa_ordmats-stprs.
    wa_h_mat-peinh = wa_ordmats-peinh.

    wa_h_mat-bomuom = wa_ordmats-meins.

    IF wa_orders-bbmeng <> 0.
      l_v_smeng  = wa_ordmats-mnglg  / wa_orders-bbmeng.
      l_v_smengs = wa_ordmats-mnglgs / wa_orders-bbmeng.
      l_v_smengz = wa_ordmats-mnglgz / wa_orders-bbmeng.
    ENDIF.

    wa_h_mat-byprod = wa_ordmats-byprod.
  ELSE.
    CLEAR : wa_mbew1.
    READ TABLE i_mbew1 INTO wa_mbew1
                       WITH KEY matnr = wa_h_mat-matnr
                                bwkey = p_werks.
    CLEAR : wa_material_des.
    READ TABLE i_material_des INTO wa_material_des
                              WITH KEY matnr = wa_h_mat-matnr.

    wa_h_mat-maktx = wa_material_des-maktx.

    wa_h_mat-stprs = wa_mbew1-stprs.
    wa_h_mat-peinh = wa_mbew1-peinh.

    wa_h_mat-bomuom = wa_resb-meins.

    wa_resb-bmeins = wa_mara-meins.
    IF wa_mara-meins <> wa_resb-meins.
      PERFORM conv_to_from_base USING 'X'
                                      wa_resb-matnr
                                      wa_resb-bdmng
                                      wa_resb-meins
                                      wa_mara-meins
                             CHANGING wa_resb-bbdmng
                                      v_conv_rc.
      IF v_conv_rc = 'X'.
        CLEAR : wa_resb-bbdmng.
      ENDIF.

    ELSE.
      wa_resb-bbdmng = wa_resb-bdmng.
    ENDIF.

    wa_ordmats-rgekz = wa_resb-rgekz.
  ENDIF.

  IF rb_nflsh <> c_x OR wa_ordmats-rgekz EQ c_x.
    wa_h_mat-stdusg  = l_v_smeng  * wa_h_ord-bprdqty.
    wa_h_mat-stdusgs = l_v_smengs * wa_h_ord-bprdqty.
    wa_h_mat-stdusgz = l_v_smengz * wa_h_ord-bprdqty.
  ELSE.
    CLEAR : wa_h_mat-stdusg.
  ENDIF.

  IF wa_h_mat-byprod = c_x.
    wa_h_mat-actusg = wa_msegs-bmenge5.

  ELSEIF wa_resb-kzkup = c_x.
    wa_h_mat-actusg = 0 - wa_msegs-bmenge1.

  ELSE.
    wa_h_mat-actusg = wa_msegs-bmenge2.
  ENDIF.

  wa_h_mat-bsuom = wa_mara-meins.
  wa_h_mat-gewei = wa_mara-gewei.
  wa_h_mat-ntgew = wa_mara-ntgew.

  IF wa_h_mat-actusg <> 0.
    wa_h_mat-gruom = wa_msegs-erfme.
  ENDIF.

  wa_h_mat-bwart = wa_resb-bwart.                     "NEEL 30/06/2005

  APPEND wa_h_mat TO i_h_mat.

  wa_matn-matnr = wa_h_mat-matnr.
  wa_matn-bwart = wa_h_mat-bwart.                           "23-06-2005

  COLLECT wa_matn INTO i_matn.

ENDFORM.                    "build_mat_tab

*&--------------------------------------------------------------------*
*&      Form  build_act_tab
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM build_act_tab USING    fp_aufnr TYPE aufnr
                            fp_matnr TYPE matnr
                            fp_bqty  TYPE gamng
                            fp_buom  TYPE meins
                            fp_gmein TYPE meins
                            fp_effic TYPE vgwrt
                            fp_afvc  TYPE ty_afvc
                            fp_afvv  TYPE ty_afvv
                   CHANGING fp_rc    TYPE char1.

  DATA : l_ism01 TYPE ru_ismng,
         l_ile01 TYPE co_ismngeh,
         l_ism02 TYPE ru_ismng,
         l_ile02 TYPE co_ismngeh,
         l_ism03 TYPE ru_ismng,
         l_ile03 TYPE co_ismngeh,
         l_ism04 TYPE ru_ismng,
         l_ile04 TYPE co_ismngeh,
         l_ism05 TYPE ru_ismng,
         l_ile05 TYPE co_ismngeh,
         l_ism06 TYPE ru_ismng,
         l_ile06 TYPE co_ismngeh,

         l_effic TYPE vgwrt,

         l_v_bmsch TYPE bmsch,
         l_pqty    TYPE gamng.

  DATA: l_vgw01 TYPE vgwrt,
        l_vgw02 TYPE vgwrt,
        l_vgw03 TYPE vgwrt,
        l_vgw04 TYPE vgwrt,
        l_vgw05 TYPE vgwrt,
        l_vgw06 TYPE vgwrt.

  CLEAR : wa_h_act.

  wa_h_act-aufnr = fp_aufnr.
  wa_h_act-aufpl = fp_afvc-aufpl.
  wa_h_act-aplzl = fp_afvc-aplzl.
  wa_h_act-vornr = fp_afvc-vornr.

  wa_h_act-vgwts = fp_afvc-vgwts.

  l_effic = fp_effic / 100.
  IF l_effic = 0.
    l_effic = 1.
  ENDIF.

  wa_afvv = fp_afvv.
  CHECK NOT wa_afvv IS INITIAL.

  wa_h_act-mgvrg = wa_afvv-mgvrg.
  wa_h_act-meinh = wa_afvv-meinh.
  wa_h_act-bmsch = wa_afvv-bmsch.

  CLEAR : wa_param.
  READ TABLE i_param INTO wa_param WITH KEY vgwts = wa_h_act-vgwts.

* Actual Usage
  CLEAR : wa_ord_conf1.
  LOOP AT i_ord_conf1 INTO wa_ord_conf1 WHERE rueck = fp_afvc-rueck.
    IF wa_ord_conf1-stokz IS INITIAL.
      l_ism01 = l_ism01 + wa_ord_conf1-ism01.
      l_ism02 = l_ism02 + wa_ord_conf1-ism02.
      l_ism03 = l_ism03 + wa_ord_conf1-ism03.
      l_ism04 = l_ism04 + wa_ord_conf1-ism04.
      l_ism05 = l_ism05 + wa_ord_conf1-ism05.
      l_ism06 = l_ism06 + wa_ord_conf1-ism06.
    ELSE.
      l_ism01 = l_ism01 - wa_ord_conf1-ism01.
      l_ism02 = l_ism02 - wa_ord_conf1-ism02.
      l_ism03 = l_ism03 - wa_ord_conf1-ism03.
      l_ism04 = l_ism04 - wa_ord_conf1-ism04.
      l_ism05 = l_ism05 - wa_ord_conf1-ism05.
      l_ism06 = l_ism06 - wa_ord_conf1-ism06.
    ENDIF.
  ENDLOOP.

  l_ile01 = wa_ord_conf1-ile01.
  l_ile02 = wa_ord_conf1-ile02.
  l_ile03 = wa_ord_conf1-ile03.
  l_ile04 = wa_ord_conf1-ile04.
  l_ile05 = wa_ord_conf1-ile05.
  l_ile06 = wa_ord_conf1-ile06.

  CLEAR : fp_rc , l_pqty.

  l_pqty    = fp_bqty.
  l_v_bmsch = wa_afvv-bmsch.

  IF wa_afvv-umren > 0.
    l_v_bmsch = l_v_bmsch * ( wa_afvv-umrez / wa_afvv-umren ).
  ENDIF.

  IF wa_afvv-meinh <> fp_buom.
    PERFORM conv_to_from_base USING 'X'
                                    fp_matnr
                                    l_v_bmsch
                                    wa_afvv-meinh
                                    fp_buom
                           CHANGING wa_afvv-bmsch
                                    v_conv_rc.
    IF v_conv_rc = 'X'.
      wa_afvv-bmsch = l_v_bmsch.
    ENDIF.

*** Begin of Change on 25-05-2005

    IF fp_afvc-vgwts+0(3) = 'YGE'.
      PERFORM conv_to_from_base USING 'X'
                                      fp_matnr
                                      wa_afvv-vgw01
                                      wa_afvv-meinh
                                      fp_buom
                             CHANGING l_vgw01
                                      v_conv_rc.
      IF v_conv_rc = space.
        wa_afvv-vgw01 = l_vgw01.
      ENDIF.
    ENDIF.

    PERFORM conv_to_from_base USING 'X'
                                     fp_matnr
                                     wa_afvv-vgw02
                                     wa_afvv-meinh
                                     fp_buom
                            CHANGING l_vgw02
                                     v_conv_rc.
    IF v_conv_rc = space.
      wa_afvv-vgw02 = l_vgw02.
    ENDIF.

    IF fp_afvc-vgwts+0(3) = 'YGE'.
      PERFORM conv_to_from_base USING 'X'
                                       fp_matnr
                                       wa_afvv-vgw03
                                       wa_afvv-meinh
                                       fp_buom
                              CHANGING l_vgw03
                                       v_conv_rc.
      IF v_conv_rc = space.
        wa_afvv-vgw03 = l_vgw03.
      ENDIF.
    ENDIF.

    PERFORM conv_to_from_base USING 'X'
                                     fp_matnr
                                     wa_afvv-vgw04
                                     wa_afvv-meinh
                                     fp_buom
                            CHANGING l_vgw04
                                     v_conv_rc.
    IF v_conv_rc = space.
      wa_afvv-vgw04 = l_vgw04.
    ENDIF.

    PERFORM conv_to_from_base USING 'X'
                                     fp_matnr
                                     wa_afvv-vgw05
                                     wa_afvv-meinh
                                     fp_buom
                            CHANGING l_vgw05
                                     v_conv_rc.
    IF v_conv_rc = space.
      wa_afvv-vgw05 = l_vgw05.
    ENDIF.

    PERFORM conv_to_from_base USING 'X'
                                     fp_matnr
                                     wa_afvv-vgw06
                                     wa_afvv-meinh
                                     fp_buom
                            CHANGING l_vgw06
                                     v_conv_rc.
    IF v_conv_rc = space.
      wa_afvv-vgw06 = l_vgw06.
    ENDIF.
*** End of Change on 25-05-2005

  ENDIF.

  IF NOT fp_afvc-lar01 IS INITIAL OR NOT fp_afvc-lar02 IS INITIAL OR
     NOT fp_afvc-lar03 IS INITIAL OR NOT fp_afvc-lar04 IS INITIAL OR
     NOT fp_afvc-lar05 IS INITIAL OR NOT fp_afvc-lar06 IS INITIAL.

    IF NOT fp_afvc-lar01 IS INITIAL OR
       NOT wa_afvv-vgw01 IS INITIAL.
      CLEAR : wa_param_key.
      READ TABLE i_param_key INTO wa_param_key
                             WITH KEY parid = wa_param-par01.

      wa_h_act-parxx = wa_param-par01.
      wa_h_act-txtxx = wa_param_key-txtlg.
      wa_h_act-ismxx = l_ism01.
      wa_h_act-ilexx = l_ile01.

      IF fp_afvc-sumnr = 0.
        wa_h_act-vgwxx = wa_afvv-vgw01.
        wa_h_act-vgexx = wa_afvv-vge01.
      ELSE.
        wa_h_act-vgwxx = wa_afvv-vgw01 * ( l_pqty / wa_afvv-bmsch ).
        wa_h_act-vgexx = wa_afvv-vge01.
      ENDIF.

      wa_h_act-stdvar = wa_h_act-vgwxx - wa_h_act-ismxx.

      PERFORM get_act_cost USING    fp_afvc-arbid
                                    fp_afvc-lar01
                           CHANGING wa_h_act-togxx
                                    wa_h_act-toexx.
      APPEND wa_h_act TO i_h_act.

      wa_parn-parxx = wa_h_act-parxx.
      COLLECT wa_parn INTO i_parn.

      fp_rc = c_x.
    ENDIF.

    IF NOT fp_afvc-lar02 IS INITIAL OR
       NOT wa_afvv-vgw02 IS INITIAL.
      CLEAR : wa_param_key.
      READ TABLE i_param_key INTO wa_param_key
                             WITH KEY parid = wa_param-par02.

      wa_h_act-parxx = wa_param-par02.
      wa_h_act-txtxx = wa_param_key-txtlg.
      wa_h_act-ismxx = l_ism02.
      wa_h_act-ilexx = l_ile02.
* Begin of MOD-002++
*      wa_h_act-vgwxx = wa_afvv-vgw02 * ( l_pqty / wa_afvv-bmsch ).
*      wa_h_act-vgwxx = wa_h_act-vgwxx / l_effic.
      wa_h_act-vgwxx = ( wa_afvv-vgw02 *  l_pqty / wa_afvv-bmsch  ) /
      l_effic.
* End of MOD-002++
      wa_h_act-vgexx = wa_afvv-vge02.

      wa_h_act-stdvar = wa_h_act-vgwxx - wa_h_act-ismxx.

      PERFORM get_act_cost USING    fp_afvc-arbid
                                    fp_afvc-lar02
                           CHANGING wa_h_act-togxx
                                    wa_h_act-toexx.

      APPEND wa_h_act TO i_h_act.

      wa_parn-parxx = wa_h_act-parxx.
      COLLECT wa_parn INTO i_parn.

      fp_rc = c_x.
    ENDIF.

    IF NOT fp_afvc-lar03 IS INITIAL OR
       NOT wa_afvv-vgw03 IS INITIAL.
      CLEAR : wa_param_key.
      READ TABLE i_param_key INTO wa_param_key
                             WITH KEY parid = wa_param-par03.

      wa_h_act-parxx = wa_param-par03.
      wa_h_act-txtxx = wa_param_key-txtlg.
      wa_h_act-ismxx = l_ism03.
      wa_h_act-ilexx = l_ile03.

      IF fp_afvc-sumnr = 0.
        wa_h_act-vgwxx = wa_afvv-vgw03.
        wa_h_act-vgexx = wa_afvv-vge03.
      ELSE.
        wa_h_act-vgwxx = wa_afvv-vgw03 * ( l_pqty / wa_afvv-bmsch ).
        wa_h_act-vgexx = wa_afvv-vge03.
      ENDIF.

      wa_h_act-stdvar = wa_h_act-vgwxx - wa_h_act-ismxx.

      PERFORM get_act_cost USING    fp_afvc-arbid
                                    fp_afvc-lar03
                           CHANGING wa_h_act-togxx
                                    wa_h_act-toexx.

      APPEND wa_h_act TO i_h_act.

      wa_parn-parxx = wa_h_act-parxx.
      COLLECT wa_parn INTO i_parn.

      fp_rc = c_x.
    ENDIF.

    IF NOT fp_afvc-lar04 IS INITIAL OR
       NOT wa_afvv-vgw04 IS INITIAL.
      CLEAR : wa_param_key.
      READ TABLE i_param_key INTO wa_param_key
                             WITH KEY parid = wa_param-par04.

      wa_h_act-parxx = wa_param-par04.
      wa_h_act-txtxx = wa_param_key-txtlg.
      wa_h_act-ismxx = l_ism04.
      wa_h_act-ilexx = l_ile04.
* Begin of MOD-002++
*      wa_h_act-vgwxx = wa_afvv-vgw04 * ( l_pqty / wa_afvv-bmsch ).
*      wa_h_act-vgwxx = wa_h_act-vgwxx / l_effic.
      wa_h_act-vgwxx = ( wa_afvv-vgw04 * l_pqty / wa_afvv-bmsch ) /
      l_effic.
* End of MOD-002++

      wa_h_act-vgexx = wa_afvv-vge04.

      wa_h_act-stdvar = wa_h_act-vgwxx - wa_h_act-ismxx.

      PERFORM get_act_cost USING    fp_afvc-arbid
                                    fp_afvc-lar04
                           CHANGING wa_h_act-togxx
                                    wa_h_act-toexx.

      APPEND wa_h_act TO i_h_act.

      wa_parn-parxx = wa_h_act-parxx.
      COLLECT wa_parn INTO i_parn.

      fp_rc = c_x.
    ENDIF.

    IF NOT fp_afvc-lar05 IS INITIAL OR
       NOT wa_afvv-vgw05 IS INITIAL.
      CLEAR : wa_param_key.
      READ TABLE i_param_key INTO wa_param_key
                             WITH KEY parid = wa_param-par05.

      wa_h_act-parxx = wa_param-par05.
      wa_h_act-txtxx = wa_param_key-txtlg.
      wa_h_act-ismxx = l_ism05.
      wa_h_act-ilexx = l_ile05.
      wa_h_act-vgwxx = wa_afvv-vgw05 * ( l_pqty / wa_afvv-bmsch ).
      wa_h_act-vgexx = wa_afvv-vge05.

      wa_h_act-stdvar = wa_h_act-vgwxx - wa_h_act-ismxx.

      PERFORM get_act_cost USING    fp_afvc-arbid
                                    fp_afvc-lar05
                           CHANGING wa_h_act-togxx
                                    wa_h_act-toexx.

      APPEND wa_h_act TO i_h_act.

      wa_parn-parxx = wa_h_act-parxx.
      COLLECT wa_parn INTO i_parn.

      fp_rc = c_x.
    ENDIF.

    IF NOT fp_afvc-lar06 IS INITIAL OR
       NOT wa_afvv-vgw06 IS INITIAL.
      CLEAR : wa_param_key.
      READ TABLE i_param_key INTO wa_param_key
                             WITH KEY parid = wa_param-par06.

      wa_h_act-parxx = wa_param-par06.
      wa_h_act-txtxx = wa_param_key-txtlg.
      wa_h_act-ismxx = l_ism06.
      wa_h_act-ilexx = l_ile06.
      wa_h_act-vgwxx = wa_afvv-vgw06 * ( l_pqty / wa_afvv-bmsch ).
      wa_h_act-vgexx = wa_afvv-vge06.

      wa_h_act-stdvar = wa_h_act-vgwxx - wa_h_act-ismxx.

      PERFORM get_act_cost USING    fp_afvc-arbid
                                    fp_afvc-lar06
                           CHANGING wa_h_act-togxx
                                    wa_h_act-toexx.

      APPEND wa_h_act TO i_h_act.

      wa_parn-parxx = wa_h_act-parxx.
      COLLECT wa_parn INTO i_parn.

      fp_rc = c_x.
    ENDIF.
  ENDIF.
ENDFORM.                    "build_act_tab

*&--------------------------------------------------------------------*
*&      Form  get_act_cost
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM get_act_cost  USING   fp_arbid  TYPE cr_objid
                           fp_larxx  TYPE lstar
                  CHANGING fp_tog001 TYPE togxxx
                           fp_toe001 TYPE toexxx.
  DATA: l_kokrs TYPE kokrs,
        l_kostl TYPE kostl,
        l_objnr TYPE j_objnr.

  CLEAR: l_kokrs, l_kostl, l_objnr,
         fp_tog001.

  fp_toe001 = 1.

  SELECT SINGLE kokrs kostl
    FROM crco
    INTO (l_kokrs, l_kostl)
   WHERE objty = c_a
     AND objid = fp_arbid
     AND lstar = fp_larxx.
  IF sy-subrc = 0.

    SELECT SINGLE objnr
      FROM cssl
      INTO l_objnr
     WHERE kokrs = l_kokrs
       AND kostl = l_kostl
       AND lstar = fp_larxx
       AND gjahr = sy-datum(4).
    IF sy-subrc = 0.

      SELECT SINGLE tog001 toe001
        FROM cost
        INTO (fp_tog001, fp_toe001)
       WHERE objnr = l_objnr
         AND gjahr = sy-datum(4)
         AND versn = c_000.

      fp_tog001 = fp_tog001 / 10.
      fp_toe001 = fp_toe001 / 10.

      IF fp_toe001 = 0.
        fp_toe001 = 1.
      ENDIF.

    ENDIF.
  ENDIF.
ENDFORM.                    "get_act_cost

*&---------------------------------------------------------------------*
*&      Form  output
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM output.
  CASE c_x.
    WHEN rb_detl.
      v_rep = c_detl.
      PERFORM display_detail_report.

    WHEN rb_summ.
      v_rep = c_sums.
      PERFORM display_summary_report.

    WHEN rb_phase.
      v_rep = c_phas.
      PERFORM display_phase_report.
  ENDCASE.

  PERFORM tree_rebuild.
ENDFORM.                    " output

*&--------------------------------------------------------------------*
*&      Form  display_detail_report
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM display_detail_report.
  DATA : l_date_low  TYPE char10,
         l_date_high TYPE char10,

         l_prdqty  TYPE gamng,
         l_wprdqty TYPE menge_d,

         l_prduom  TYPE meins,
         l_uom     TYPE meins,
         l_prdq(20),

         l_effic  TYPE char16,

         l_act    TYPE char16,
         l_std    TYPE char16,

         l_amenge TYPE menge_d,
         l_smenge TYPE menge_d,
         l_menge  TYPE menge_d,

         l_aqty TYPE char18,
         l_sqty TYPE char18,
         l_svar TYPE char18,
         l_svarp  TYPE char18,

         l_aqtys TYPE char18,
         l_sqtys TYPE char18,
         l_svars TYPE char18,

         l_aqtyg TYPE char18,
         l_sqtyg TYPE char18,
         l_svarg TYPE char18,

         l_matuom TYPE meins,
         l_stduom TYPE meins,
         l_varuom TYPE meins,

         l_astprs    TYPE ty_stprs,
         l_sstprs    TYPE ty_stprs,
         l_stprs     TYPE ty_stprs,

         l_total1  TYPE char1,
         l_total2  TYPE char1,
         l_total3  TYPE char1,

         l_totalg1  TYPE char1,
         l_totalg2  TYPE char1,
         l_totalg3  TYPE char1,

         l_aplzl    TYPE co_aplzl,

         l_wa_act  TYPE ty_hier_act,
         l_wa_mat  TYPE ty_hier_mat_sum,
         l_wa_matg TYPE ty_hier_mat_sum.

  PERFORM pfstatus.
  SET PF-STATUS 'MAIN' EXCLUDING i_fcode.
  SET TITLEBAR 'VARI' WITH text-066.

  MOVE 'Display Detail Report'(028) TO v_output_text.
  PERFORM inform_user_of_progress.

* Clearing local variables
  CLEAR wa_nodestab.
  REFRESH i_nodestab.

  wa_nodestab-id = c_1_1.
  wa_nodestab-tlevel = c_1.
  wa_nodestab-text = 'Production Variances'(031).
  wa_nodestab-tlength = c_20.
  wa_nodestab-compress = c_x.
  APPEND wa_nodestab TO i_nodestab.

  CLEAR : l_wa_matg , l_sqtyg   , l_aqtyg  , l_svarg,
          l_totalg1 , l_totalg2 , l_totalg3.
  LOOP AT i_h_ord INTO wa_h_ord.
    CLEAR: wa_nodestab, l_date_low, l_date_high, l_prdqty, l_prduom.

    wa_nodestab-id = c_2_1.
    wa_nodestab-tlevel = c_2.
    wa_nodestab-parent = c_1_1.

* Order Number text
    wa_nodestab-text = 'Order Num:'(032).
    wa_nodestab-tlength = c_12.
    wa_nodestab-tcolor = c_1.

* Order number
    WRITE wa_h_ord-aufnr TO wa_nodestab-text1 NO-ZERO.
    wa_nodestab-tlength1 = c_12.
    wa_nodestab-tcolor1 = c_1.

* Date Range
    WRITE wa_h_ord-gstrp TO l_date_low.
    WRITE wa_h_ord-gltrp TO l_date_high.
    CONCATENATE l_date_low c_hyp l_date_high INTO wa_nodestab-text2
                                             SEPARATED BY space.
    wa_nodestab-tlength2 = c_25.
    wa_nodestab-tcolor2 = c_1.

* Material Number
    WRITE wa_h_ord-plnbez TO wa_nodestab-text3 NO-ZERO.
    wa_nodestab-tlength3 = c_18.
    wa_nodestab-tcolor3 = c_1.

* Material Description
    wa_nodestab-text4 = wa_h_ord-maktx.
    wa_nodestab-tlength4 = c_33.
    wa_nodestab-tcolor4 = c_1.

* Produced Quantity / Confirmed Quantity
    l_prdqty = wa_h_ord-prdqty.
    l_prduom = wa_h_ord-prduom.

* convert to KG?
    IF rb_kgm = c_x AND l_prduom <> 'KG'.
      IF wa_h_ord-bsuom <> 'KG'.
        PERFORM convert_to_kg USING   wa_h_ord-plnbez wa_h_ord-bsuom
                                      wa_h_ord-gewei  wa_h_ord-ntgew
                                      wa_h_ord-bprdqty
                             CHANGING l_wprdqty
                                      v_conv_rc.
        IF v_conv_rc <> 'X'.
          l_prdqty = l_wprdqty.
          l_prduom = 'KG'.
        ENDIF.

      ELSE.
        l_prdqty = wa_h_ord-bprdqty.
        l_prduom = 'KG'.
      ENDIF.
    ENDIF.

    WRITE l_prdqty TO l_prdq UNIT l_prduom.
    WRITE l_prduom TO l_uom.

*** text for Order Qty
    IF rb_pland = c_x.
** Planned Production
      CONCATENATE 'Plan Qty:'(076) l_prdq l_uom
             INTO wa_nodestab-text5 SEPARATED BY space.
    ELSE.
** Actual Production
      IF rb_prod = c_x.
* Produced
        CONCATENATE 'Prod Qty:'(033) l_prdq l_uom
               INTO wa_nodestab-text5 SEPARATED BY space.
      ELSE.
* Confirmed
        CONCATENATE 'Conf Qty:'(034) l_prdq l_uom
               INTO wa_nodestab-text5 SEPARATED BY space.
      ENDIF.
    ENDIF.

    CONDENSE : wa_nodestab-text5.

    wa_nodestab-tlength5 = c_35.
    wa_nodestab-tcolor5  = c_1.

    APPEND wa_nodestab TO i_nodestab.

* Resource Information
    CLEAR : wa_nodestab , l_effic.
    wa_nodestab-id     = c_3_1.
    wa_nodestab-tlevel = c_3.
    wa_nodestab-parent = c_2_1.

    wa_nodestab-text = 'Resource:'(035).
    wa_nodestab-tlength = c_14.
    wa_nodestab-tcolor  = c_4.

    wa_nodestab-text1    = wa_h_ord-botlnck.
    wa_nodestab-tlength1 = c_8.
    wa_nodestab-tcolor1  = c_4.

    wa_nodestab-text2    = wa_h_ord-resdesc.
    wa_nodestab-tlength2 = c_37.
    wa_nodestab-tcolor2  = c_4.

    l_effic = wa_h_ord-el_effc.
    CONCATENATE 'Exp. Line Eff.'(036) l_effic c_perc
           INTO wa_nodestab-text3 SEPARATED BY space.
    CONDENSE wa_nodestab-text3.
    wa_nodestab-tlength3 = c_30.
    wa_nodestab-tcolor3  = c_4.

    l_effic = wa_h_ord-ac_effc.
    CONCATENATE 'Act. Line Eff.'(037) l_effic c_perc
           INTO wa_nodestab-text4 SEPARATED BY space.
    CONDENSE wa_nodestab-text4.
    wa_nodestab-tlength4 = c_30.
    wa_nodestab-tcolor4  = c_4.

    APPEND wa_nodestab TO i_nodestab.

* Phase Information
    READ TABLE i_h_act INTO wa_h_act WITH KEY aufnr = wa_h_ord-aufnr.
    IF sy-subrc = 0.
      CLEAR : wa_nodestab.

      wa_nodestab-id     = c_3_2.
      wa_nodestab-tlevel = c_3.
      wa_nodestab-parent = c_2_1.

      wa_nodestab-text = 'Phase'(038).
      wa_nodestab-tlength = c_8.
      wa_nodestab-tcolor  = c_4.

      wa_nodestab-tlength1 = c_42.
*    wa_nodestab-tcolor1  = c_4.

      IF rb_fiscl = c_x.
        CONCATENATE 'Actual Usage'(040) v_waers
               INTO wa_nodestab-text2 SEPARATED BY space.
      ELSE.
        CONCATENATE 'Actual Usage'(040) 'UoM'
               INTO wa_nodestab-text2 SEPARATED BY space.
      ENDIF.
      wa_nodestab-tlength2 = c_20.
      wa_nodestab-tcolor2  = c_4.

      IF rb_fiscl = c_x.
        CONCATENATE 'Standard Usage'(041) v_waers
               INTO wa_nodestab-text3 SEPARATED BY space.
      ELSE.
        CONCATENATE 'Standard Usage'(041) 'UoM'
               INTO wa_nodestab-text3 SEPARATED BY space.
      ENDIF.
      wa_nodestab-tlength3 = c_20.
      wa_nodestab-tcolor3  = c_4.

      IF rb_fiscl = c_x.
        CONCATENATE 'Standard Usage Var'(042) v_waers
               INTO wa_nodestab-text4 SEPARATED BY space.
      ELSE.
        CONCATENATE 'Standard Usage Var'(042) 'UoM'
               INTO wa_nodestab-text4 SEPARATED BY space.
      ENDIF.
      wa_nodestab-tlength4 = c_24.
      wa_nodestab-tcolor4  = c_4.

      CONCATENATE 'Standard Usage Var'(042) c_perc
             INTO wa_nodestab-text5 SEPARATED BY space.
      wa_nodestab-tlength5 = c_20.
      wa_nodestab-tcolor5  = c_4.

      APPEND wa_nodestab TO i_nodestab.

*** Activities
      CLEAR : flg_color, l_act    , l_std    , l_svar , l_svarp ,
              l_wa_act , l_total1 , l_total2 , l_aplzl.
      LOOP AT i_h_act INTO wa_h_act WHERE aufnr = wa_h_ord-aufnr.

        IF l_aplzl <> wa_h_act-aplzl.
          CLEAR : wa_afvc.
          READ TABLE i_h_phs INTO wa_h_phs WITH KEY aufnr =
          wa_h_act-aufnr
                                                    aufpl =
                                                    wa_h_act-aufpl
                                                    aplzl =
                                                    wa_h_act-aplzl.
          l_aplzl = wa_h_act-aplzl.
        ENDIF.

        CLEAR  wa_nodestab.
        wa_nodestab-id     = c_4_1.
        wa_nodestab-tlevel = c_4.
        wa_nodestab-parent = c_3_2.

        wa_nodestab-text    = wa_h_act-vornr.
        wa_nodestab-tlength = c_4.

        CONCATENATE wa_h_phs-steus wa_h_phs-arbpl
                    wa_h_act-txtxx INTO wa_nodestab-text1
                                   SEPARATED BY '  '.
        wa_nodestab-tlength1 = c_42.

        IF rb_quant = c_x.
          WRITE : wa_h_act-ismxx TO l_act UNIT wa_h_act-ilexx
          NO-GROUPING,
                  wa_h_act-ilexx TO l_uom.
          CONCATENATE l_act l_uom INTO wa_nodestab-text2
                                  SEPARATED BY space.
          wa_nodestab-tlength2 = c_20.

          WRITE : wa_h_act-vgwxx TO l_std UNIT wa_h_act-vgexx
          NO-GROUPING,
                  wa_h_act-vgexx TO l_uom.
          CONCATENATE l_std l_uom INTO wa_nodestab-text3
                                  SEPARATED BY space.
          wa_nodestab-tlength3 = c_20.

          WRITE : wa_h_act-stdvar TO l_svar UNIT wa_h_act-vgexx
          NO-GROUPING,
                  wa_h_act-vgexx TO l_uom.
          CONCATENATE l_svar l_uom INTO wa_nodestab-text4
                                   SEPARATED BY space.
          wa_nodestab-tlength4 = c_24.

          IF wa_h_act-ismxx <> 0.
            IF l_total2 <> c_x.
              l_total2 = c_x.
              l_wa_act-ilexx = wa_h_act-ilexx.
            ENDIF.

            IF l_wa_act-ilexx = wa_h_act-ilexx.

              l_wa_act-ismxx = l_wa_act-ismxx + wa_h_act-ismxx.
              l_wa_act-ilexx = wa_h_act-ilexx.

            ELSEIF wa_h_act-ismxx <> 0.
              CLEAR : l_wa_act-ismxx , l_wa_act-ilexx.
            ENDIF.
          ENDIF.

          IF wa_h_act-vgwxx <> 0.
            IF l_total1 <> c_x.
              l_total1 = c_x.
              l_wa_act-vgexx = wa_h_act-vgexx.
            ENDIF.

            IF l_wa_act-vgexx = wa_h_act-vgexx.
              l_wa_act-vgwxx  = l_wa_act-vgwxx  + wa_h_act-vgwxx.
              l_wa_act-stdvar = l_wa_act-stdvar + wa_h_act-stdvar.
              l_wa_act-vgexx = wa_h_act-vgexx.

            ELSEIF wa_h_act-vgwxx <> 0.
              CLEAR : l_wa_act-vgwxx , l_wa_act-vgexx, l_wa_act-stdvar.
            ENDIF.
          ENDIF.

          IF wa_h_act-vgwxx <> 0.
            wa_h_act-varper = ( wa_h_act-stdvar / wa_h_act-vgwxx ) * 100
            .
          ENDIF.

        ELSE.
          wa_h_act-actu = wa_h_act-ismxx *
                        ( wa_h_act-togxx / wa_h_act-toexx ).

          WRITE : wa_h_act-actu TO l_act CURRENCY v_waers NO-GROUPING,
                  v_waers TO l_uom.
          CONCATENATE l_act l_uom INTO wa_nodestab-text2
                                  SEPARATED BY space.
          wa_nodestab-tlength2 = c_20.

          wa_h_act-stdu = wa_h_act-vgwxx *
                        ( wa_h_act-togxx / wa_h_act-toexx ).

          WRITE : wa_h_act-stdu TO l_std CURRENCY v_waers NO-GROUPING.
          CONCATENATE l_std l_uom INTO wa_nodestab-text3
                                  SEPARATED BY space.
          wa_nodestab-tlength3 = c_20.

          wa_h_act-varu = wa_h_act-stdvar *
                        ( wa_h_act-togxx / wa_h_act-toexx ).

          WRITE wa_h_act-varu TO l_svar CURRENCY v_waers NO-GROUPING.
          CONCATENATE l_svar l_uom INTO wa_nodestab-text4
                                   SEPARATED BY space.
          wa_nodestab-tlength4 = c_24.

          l_wa_act-actu = l_wa_act-actu + wa_h_act-actu.
          l_wa_act-stdu = l_wa_act-stdu + wa_h_act-stdu.
          l_wa_act-varu = l_wa_act-varu + wa_h_act-varu.

          IF wa_h_act-stdu <> 0.
            wa_h_act-varper = ( wa_h_act-varu / wa_h_act-stdu ) * 100.
          ENDIF.
        ENDIF.

        WRITE wa_h_act-varper TO l_svarp NO-GROUPING DECIMALS 2.
        CONCATENATE l_svarp c_perc INTO wa_nodestab-text5
                                   SEPARATED BY space.
        wa_nodestab-tlength5 = c_20.

        IF flg_color = c_x.
          CLEAR flg_color.
          wa_nodestab-tcolor  = c_3.
          wa_nodestab-tcolor1 = c_3.
          wa_nodestab-tcolor2 = c_3.
          wa_nodestab-tcolor3 = c_3.
          wa_nodestab-tcolor4 = c_3.
          wa_nodestab-tcolor5 = c_3.
          wa_nodestab-tcolor6 = c_3.
          wa_nodestab-tcolor7 = c_3.
          wa_nodestab-tcolor8 = c_3.
        ELSE.
          flg_color = c_x.
          wa_nodestab-tcolor  = c_2.
          wa_nodestab-tcolor1 = c_2.
          wa_nodestab-tcolor2 = c_2.
          wa_nodestab-tcolor3 = c_2.
          wa_nodestab-tcolor4 = c_2.
          wa_nodestab-tcolor5 = c_2.
          wa_nodestab-tcolor6 = c_2.
          wa_nodestab-tcolor7 = c_2.
          wa_nodestab-tcolor8 = c_2.
        ENDIF.
        APPEND wa_nodestab TO i_nodestab.
      ENDLOOP.
*** Displaying Activity Subtotals
      CLEAR  wa_nodestab.
      wa_nodestab-id     = c_4_1.
      wa_nodestab-tlevel = c_4.
      wa_nodestab-parent = c_3_2.

      wa_nodestab-text    = 'Activity Totals'(074).
      wa_nodestab-tlength =  c_20.
      wa_nodestab-tcolor  =  c_6.

      wa_nodestab-text1 = space.
      wa_nodestab-tlength1 = c_26.
      wa_nodestab-tcolor1  = c_6.

      IF rb_quant = c_x.
        WRITE : l_wa_act-ismxx  TO l_act  UNIT l_wa_act-ilexx
        NO-GROUPING,
                l_wa_act-vgwxx  TO l_std  UNIT l_wa_act-vgexx
                NO-GROUPING,
                l_wa_act-stdvar TO l_svar UNIT l_wa_act-vgexx
                NO-GROUPING,
                wa_h_act-ilexx TO l_uom.

        CONCATENATE l_act  l_uom INTO wa_nodestab-text2
                                 SEPARATED BY space.
        WRITE : wa_h_act-vgexx TO l_uom.
        CONCATENATE l_std  l_uom INTO wa_nodestab-text3
                                      SEPARATED BY space.
        CONCATENATE l_svar l_uom INTO wa_nodestab-text4
                                      SEPARATED BY space.
      ELSE.
        WRITE : l_wa_act-actu TO l_act  CURRENCY v_waers NO-GROUPING,
                l_wa_act-stdu TO l_std  CURRENCY v_waers NO-GROUPING,
                l_wa_act-varu TO l_svar CURRENCY v_waers NO-GROUPING,
                v_waers TO l_uom.

        CONCATENATE l_act  l_uom INTO wa_nodestab-text2
                                 SEPARATED BY space.
        CONCATENATE l_std  l_uom INTO wa_nodestab-text3
                                 SEPARATED BY space.
        CONCATENATE l_svar l_uom INTO wa_nodestab-text4
                                 SEPARATED BY space.
      ENDIF.
      wa_nodestab-tlength2 = c_20.
      wa_nodestab-tcolor2  = c_6.

      wa_nodestab-tlength3 = c_20.
      wa_nodestab-tcolor3  = c_6.

      wa_nodestab-tlength4 = c_24.
      wa_nodestab-tcolor4  = c_6.

      APPEND wa_nodestab TO i_nodestab.
      CLEAR : wa_nodestab.
    ENDIF.

* Material Information
    READ TABLE i_h_mat INTO wa_h_mat WITH KEY aufnr = wa_h_ord-aufnr.
    CHECK sy-subrc = 0.

    CLEAR : wa_nodestab.
    wa_nodestab-id      = c_3_3.
    wa_nodestab-tlevel  = c_3.
    wa_nodestab-parent  = c_2_1.
    PERFORM material_header USING wa_nodestab.

    APPEND wa_nodestab TO i_nodestab.

    CLEAR : wa_nodestab , l_menge  , l_stprs  ,
            l_wa_mat    ,
            l_total1    , l_total2 , l_total3 ,
            l_aqtys     , l_sqtys  , l_svars  .
    LOOP AT i_h_mat INTO wa_h_mat WHERE aufnr = wa_h_ord-aufnr.

      l_smenge = l_menge.
      l_sstprs = l_stprs.
      PERFORM do_mat_calc CHANGING wa_h_mat
                                   l_aqty    l_matuom
                                   l_sqty    l_stduom
                                   l_svar    l_varuom
                                   l_svarp
                                   l_amenge  l_smenge
                                   l_astprs  l_sstprs.
      l_menge = l_menge + l_smenge.
      l_stprs = l_stprs + l_sstprs.

      CHECK wa_h_mat-sumi = c_x.

      CLEAR: wa_nodestab , l_menge , l_stprs.
      wa_nodestab-id     = c_4_2.
      wa_nodestab-tlevel = c_4.
      wa_nodestab-parent = c_3_3.

* Material Number
      WRITE wa_h_mat-matnr TO wa_nodestab-text NO-ZERO.
* Material Description
      wa_nodestab-text1 = wa_h_mat-maktx.

      wa_nodestab-tlength  = c_18.
      wa_nodestab-tlength1 = c_30.
      wa_nodestab-tlength2 = c_22.
      wa_nodestab-tlength3 = c_22.
      wa_nodestab-tlength4 = c_24.
      wa_nodestab-tlength5 = c_20.

      IF l_matuom <> v_waers.
        WRITE : l_matuom TO l_uom.
      ELSE.
        WRITE : v_waers TO l_uom.
      ENDIF.
      CONCATENATE l_aqty l_uom INTO wa_nodestab-text2
                               SEPARATED BY space.
      IF l_stduom <> v_waers.
        WRITE : l_stduom TO l_uom.
      ELSE.
        WRITE : v_waers TO l_uom.
      ENDIF.
      CONCATENATE l_sqty l_uom INTO wa_nodestab-text3
                               SEPARATED BY space.
      IF l_varuom <> v_waers.
        WRITE : l_varuom TO l_uom.
      ELSE.
        WRITE : v_waers TO l_uom.
      ENDIF.
      CONCATENATE l_svar l_uom INTO wa_nodestab-text4
                               SEPARATED BY space.

      CONCATENATE l_svarp c_perc INTO wa_nodestab-text5
                                 SEPARATED BY space.

      wa_nodestab-tcolor   = c_3.
      wa_nodestab-tcolor1  = c_3.
      wa_nodestab-tcolor2  = c_3.
      wa_nodestab-tcolor3  = c_3.
      wa_nodestab-tcolor4  = c_3.
      wa_nodestab-tcolor5  = c_3.

      APPEND wa_nodestab TO i_nodestab.
      CLEAR : wa_nodestab.

      IF l_aqty CA '123456789'.
        IF l_total1 <> c_x.
          l_total1 = c_x.
          l_wa_mat-actuom = l_matuom.
        ENDIF.

        IF l_wa_mat-actuom <> l_matuom.
          CLEAR : l_wa_mat-actusg, l_wa_mat-astprs, l_wa_mat-actuom,
                  l_aqtys, l_amenge,
                  l_wa_matg-actusg, l_wa_matg-astprs, l_wa_matg-actuom,
                  l_aqtyg, l_astprs.
        ENDIF.
      ENDIF.

      IF l_sqty CA '123456789'.
        IF l_total2 <> c_x.
          l_total2 = c_x.
          l_wa_mat-stduom  = l_stduom.
        ENDIF.

        IF l_wa_mat-stduom <> l_stduom.
          CLEAR : l_wa_mat-stdusg, l_wa_mat-sstprs, l_wa_mat-stduom,
                  l_sqtys,         l_smenge,       l_wa_matg-stdusg,
                  l_wa_matg-sstprs, l_wa_matg-stduom,
                  l_sqtyg, l_sstprs.
        ENDIF.
      ENDIF.

      IF l_svar CA '123456789'.
        IF l_total3 <> c_x.
          l_total3 = c_x.
          l_wa_mat-varuom  = l_varuom.
        ENDIF.

        IF l_wa_mat-varuom <> l_varuom.
          CLEAR : l_wa_mat-stdvar , l_wa_mat-varprs  , l_wa_mat-varuom ,
                  l_svars, wa_h_mat-stdvar,
                  l_wa_matg-stdvar, l_wa_matg-varprs , l_wa_matg-varuom,
                  l_svarg, wa_h_mat-vstprs.
        ENDIF.
      ENDIF.

      CASE c_x.
        WHEN rb_quant.
          l_wa_mat-actusg  = l_wa_mat-actusg  + l_amenge.
          WRITE l_wa_mat-actusg TO l_aqtys UNIT l_wa_mat-actuom
          NO-GROUPING.

          l_wa_mat-stdusg  = l_wa_mat-stdusg  + l_smenge.
          WRITE l_wa_mat-stdusg TO l_sqtys UNIT l_wa_mat-stduom
          NO-GROUPING.

          l_wa_mat-stdvar  = l_wa_mat-stdvar  + wa_h_mat-stdvar.
          WRITE : l_wa_mat-stdvar TO l_svars UNIT l_wa_mat-stduom
          NO-GROUPING.

        WHEN rb_fiscl.
          l_wa_mat-astprs  = l_wa_mat-astprs  + l_astprs.
          v_prs = l_wa_mat-astprs.
          WRITE v_prs TO l_aqtys CURRENCY v_waers NO-GROUPING.

          l_wa_mat-varprs  = l_wa_mat-varprs  + wa_h_mat-vstprs.
          v_prs = l_wa_mat-varprs.
          WRITE v_prs TO l_svars CURRENCY v_waers NO-GROUPING.

          l_wa_mat-sstprs  = l_wa_mat-sstprs  + l_sstprs.
          v_prs = l_wa_mat-sstprs.
          WRITE v_prs TO l_sqtys CURRENCY v_waers NO-GROUPING.
      ENDCASE.
    ENDLOOP.

*** Displaying Material Subtotals
    CLEAR  wa_nodestab.
    wa_nodestab-id     = c_4_2.
    wa_nodestab-tlevel = c_4.
    wa_nodestab-parent = c_3_3.

    wa_nodestab-text    = 'Material Totals'(043).
    wa_nodestab-text1   = space.

    wa_nodestab-tlength  =  c_18.
    wa_nodestab-tlength1 = c_30.
    wa_nodestab-tlength2 = c_22.
    wa_nodestab-tlength3 = c_22.
    wa_nodestab-tlength4 = c_24.

    IF l_wa_mat-actuom <> v_waers.
      WRITE : l_wa_mat-actuom TO l_uom.
    ELSE.
      WRITE : v_waers TO l_uom.
    ENDIF.
    CONCATENATE l_aqtys l_uom INTO wa_nodestab-text2
                              SEPARATED BY space.
    IF l_wa_mat-stduom <> v_waers.
      WRITE : l_wa_mat-stduom TO l_uom.
    ELSE.
      WRITE : v_waers TO l_uom.
    ENDIF.
    CONCATENATE l_sqtys l_uom INTO wa_nodestab-text3
                              SEPARATED BY space.

    IF l_wa_mat-varuom <> v_waers.
      WRITE : l_wa_mat-varuom TO l_uom.
    ELSE.
      WRITE : v_waers TO l_uom.
    ENDIF.
    CONCATENATE l_svars l_uom INTO wa_nodestab-text4
                              SEPARATED BY space.
    wa_nodestab-tcolor  =  c_6.
    wa_nodestab-tcolor1  = c_6.
    wa_nodestab-tcolor2  = c_6.
    wa_nodestab-tcolor3  = c_6.
    wa_nodestab-tcolor4  = c_6.

    APPEND wa_nodestab TO i_nodestab.
    CLEAR : wa_nodestab.

    IF l_aqtys CA '123456789'.
      IF l_totalg1 <> c_x.
        l_totalg1 = c_x.
        l_wa_matg-actuom = l_wa_mat-actuom.
      ENDIF.

      IF l_wa_matg-actuom <> l_wa_mat-actuom.
        CLEAR : l_wa_matg-actusg , l_wa_matg-astprs , l_wa_matg-actuom,
                l_aqtyg, l_wa_mat-actusg, l_wa_mat-astprs.
      ENDIF.
    ENDIF.

    IF l_sqtys CA '123456789'.
      IF l_totalg2 <> c_x.
        l_totalg2 = c_x.
        l_wa_matg-stduom = l_wa_mat-stduom.
      ENDIF.

      IF l_wa_matg-stduom <> l_wa_mat-stduom.
        CLEAR : l_wa_matg-stdusg , l_wa_matg-stduom , l_wa_matg-sstprs ,
                l_sqtyg, l_wa_mat-stdusg, l_wa_mat-sstprs.
      ENDIF.
    ENDIF.

    IF l_svars CA '123456789'.
      IF l_totalg3 <> c_x.
        l_totalg3 = c_x.
        l_wa_matg-varuom  = l_wa_mat-varuom.
      ENDIF.

      IF l_wa_matg-varuom  <> l_wa_mat-varuom.
        CLEAR : l_wa_matg-stdvar, l_wa_matg-varprs , l_wa_matg-varuom,
                l_svarg, l_wa_mat-stdvar, l_wa_mat-varprs.
      ENDIF.
    ENDIF.

    CASE c_x.
      WHEN rb_quant.
        l_wa_matg-actusg  = l_wa_matg-actusg  + l_wa_mat-actusg.
        WRITE : l_wa_matg-actusg TO l_aqtyg UNIT l_wa_mat-actuom
        NO-GROUPING.

        l_wa_matg-stdusg  = l_wa_matg-stdusg  + l_wa_mat-stdusg.
        WRITE : l_wa_matg-stdusg TO l_sqtyg UNIT l_wa_mat-stduom
        NO-GROUPING.

        l_wa_matg-stdvar  = l_wa_matg-stdvar  + l_wa_mat-stdvar.
        WRITE : l_wa_matg-stdvar TO l_svarg UNIT l_wa_mat-varuom
        NO-GROUPING.

      WHEN rb_fiscl.
        l_wa_matg-astprs  = l_wa_matg-astprs  + l_wa_mat-astprs
                            + l_wa_act-actu.
*                           + l_wa_act-actu * 10. "NEEL++ 13/07/2005++
        v_prs = l_wa_matg-astprs.
        WRITE v_prs TO l_aqtyg CURRENCY v_waers NO-GROUPING.

        l_wa_matg-sstprs  = l_wa_matg-sstprs  + l_wa_mat-sstprs
                            + l_wa_act-stdu.
*                           + l_wa_act-stdu * 10. "NEEL++ 13/07/2005++

        v_prs = l_wa_matg-sstprs.
        WRITE v_prs TO l_sqtyg CURRENCY v_waers NO-GROUPING.

        l_wa_matg-varprs  = l_wa_matg-varprs  + l_wa_mat-varprs
                            + l_wa_act-varu.
*                            + l_wa_act-varu * 10. "NEEL++ 13/07/2005++

        v_prs = l_wa_matg-varprs.
        WRITE v_prs TO l_svarg CURRENCY v_waers NO-GROUPING.
    ENDCASE.

    CLEAR : l_sqtys , l_aqtys , l_svars.

*** Displaying Grand Total
    AT LAST.
      CLEAR wa_nodestab.
      wa_nodestab-id     = c_2_2.
      wa_nodestab-tlevel = c_2.
      wa_nodestab-parent = c_1_1.

      wa_nodestab-text   = 'Process Order Totals'(044).
      wa_nodestab-text1  = space.

      wa_nodestab-tlength  = c_26.
      wa_nodestab-tlength1 = c_30.
      wa_nodestab-tlength2 = c_22.
      wa_nodestab-tlength3 = c_22.
      wa_nodestab-tlength4 = c_24.

      IF l_wa_matg-actuom <> v_waers.
        WRITE : l_wa_matg-actuom TO l_uom.
      ELSE.
        WRITE : v_waers TO l_uom.
      ENDIF.
      CONCATENATE l_aqtyg l_uom INTO wa_nodestab-text2
                                SEPARATED BY space.

      IF l_wa_matg-stduom <> v_waers.
        WRITE : l_wa_matg-stduom TO l_uom.
      ELSE.
        WRITE : v_waers TO l_uom.
      ENDIF.
      CONCATENATE l_sqtyg l_uom INTO wa_nodestab-text3
                                SEPARATED BY space.

      IF l_wa_matg-varuom <> v_waers.
        WRITE : l_wa_matg-varuom TO l_uom.
      ELSE.
        WRITE : v_waers TO l_uom.
      ENDIF.
      CONCATENATE l_svarg l_uom INTO wa_nodestab-text4
                                SEPARATED BY space.
      wa_nodestab-tcolor   = c_5.
      wa_nodestab-tcolor1  = c_5.
      wa_nodestab-tcolor2  = c_5.
      wa_nodestab-tcolor3  = c_5.
      wa_nodestab-tcolor4  = c_5.

      APPEND wa_nodestab TO i_nodestab.
    ENDAT.
  ENDLOOP.
ENDFORM.                    " DISPLAY_DETAIL_REPORT

*&--------------------------------------------------------------------*
*&      Form  display_phase_report
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM display_phase_report.

  DATA: l_date_low(10)  TYPE c,
        l_date_high(10) TYPE c,

        l_effic  TYPE char16,
        l_arbpl  TYPE arbpl,

        l_prdqty  TYPE gamng,
        l_prdq    TYPE char18,
        l_wprdqty TYPE menge_d,
        l_prduom  TYPE meins,

        l_act    TYPE char16,
        l_std    TYPE char16,

        l_amenge TYPE menge_d,
        l_smenge TYPE menge_d,
        l_menge  TYPE menge_d,

        l_aqty TYPE char18,
        l_sqty TYPE char18,
        l_svar TYPE char18,
        l_svarp  TYPE char18,

        l_aqtys TYPE char18,
        l_sqtys TYPE char18,
        l_svars TYPE char18,

        l_matuom TYPE meins,
        l_stduom TYPE meins,
        l_varuom TYPE meins,
        l_uom    TYPE meins,

        l_astprs TYPE ty_stprs,
        l_sstprs TYPE ty_stprs,
        l_stprs  TYPE ty_stprs,

        l_total1  TYPE char1,
        l_total2  TYPE char1,
        l_total3  TYPE char1,

        l_wa_act  TYPE ty_hier_act,
        l_wa_mat  TYPE ty_hier_mat_sum,
        l_wa_phs  TYPE ty_hier_phase,
        l_i_phs   TYPE STANDARD TABLE OF ty_hier_phase.

  PERFORM pfstatus.
  SET PF-STATUS 'MAIN' EXCLUDING i_fcode.
  SET TITLEBAR 'VARI' WITH text-068.

  l_i_phs = i_h_phs.

  SORT i_h_phs BY aufnr arbpl vornr.

  CLEAR wa_nodestab.
  REFRESH i_nodestab.

  MOVE 'Display Phase Report'(030) TO v_output_text.
  PERFORM inform_user_of_progress.

  CLEAR wa_nodestab.
  wa_nodestab-id = c_1_1.
  wa_nodestab-tlevel = c_1.
  wa_nodestab-text = 'Production Variances'(031).
  wa_nodestab-tlength = c_20.
  wa_nodestab-compress = c_x.
  APPEND wa_nodestab TO i_nodestab.

  LOOP AT i_h_ord INTO wa_h_ord.

    CLEAR: wa_nodestab, l_date_low, l_date_high.

    wa_nodestab-id     = c_2_1.
    wa_nodestab-tlevel = c_2.
    wa_nodestab-parent = c_1_1.

* Order Number text
    wa_nodestab-text    = 'Order Num:'(032).
    wa_nodestab-tlength = c_12.
    wa_nodestab-tcolor  = c_1.

* Order number
    WRITE wa_h_ord-aufnr TO wa_nodestab-text1 NO-ZERO.
    wa_nodestab-tlength1 = c_12.
    wa_nodestab-tcolor1  = c_1.

* Date Range
    WRITE wa_h_ord-gstrp TO l_date_low.
    WRITE wa_h_ord-gltrp TO l_date_high.
    CONCATENATE l_date_low c_hyp l_date_high INTO wa_nodestab-text2
                                             SEPARATED BY space.
    wa_nodestab-tlength2 = c_25.
    wa_nodestab-tcolor2  = c_1.

* Material Number
    WRITE wa_h_ord-plnbez TO wa_nodestab-text3 NO-ZERO.
    wa_nodestab-tlength3 = c_18.
    wa_nodestab-tcolor3  = c_1.

* Material Description
    wa_nodestab-text4    = wa_h_ord-maktx.
    wa_nodestab-tlength4 = c_33.
    wa_nodestab-tcolor4  = c_1.

    APPEND wa_nodestab TO i_nodestab.

    CLEAR :  l_aqtys, l_sqtys, l_svars, l_arbpl.
    LOOP AT i_h_phs INTO wa_h_phs WHERE aufnr = wa_h_ord-aufnr.
      l_wa_phs = wa_h_phs.

      IF l_arbpl <> wa_h_phs-arbpl.
        CLEAR : wa_h_phs.
        READ TABLE i_h_phs INTO wa_h_phs WITH KEY aufnr = wa_h_ord-aufnr
                                                  arbpl = l_wa_phs-arbpl
                                                  steus = 'YBN1'
                                                  runtime = c_x.
* Resource Information
        CLEAR : wa_nodestab.
        wa_nodestab-id     = c_3_1.
        wa_nodestab-tlevel = c_3.
        wa_nodestab-parent = c_2_1.

        wa_nodestab-text = 'Resource:'(035).
        wa_nodestab-tlength = c_14.
        wa_nodestab-tcolor  = c_4.

        wa_nodestab-text1    = l_wa_phs-arbpl.
        wa_nodestab-tlength1 = c_8.
        wa_nodestab-tcolor1  = c_4.

        wa_nodestab-text2    = l_wa_phs-ktext.
        wa_nodestab-tlength2 = c_37.
        wa_nodestab-tcolor2  = c_4.

        IF l_wa_phs-steus = 'YBN1'.
          l_effic = wa_h_phs-el_effc.
          CONCATENATE 'Exp. Line Eff.'(036) l_effic c_perc
                 INTO wa_nodestab-text3 SEPARATED BY space.
          CONDENSE wa_nodestab-text3.
          wa_nodestab-tlength3 = c_30.
          wa_nodestab-tcolor3  = c_4.

          l_effic = wa_h_phs-ac_effc.
          CONCATENATE 'Act. Line Eff.'(037) l_effic c_perc
                 INTO wa_nodestab-text4 SEPARATED BY space.
          CONDENSE wa_nodestab-text4.
          wa_nodestab-tlength4 = c_30.
          wa_nodestab-tcolor4  = c_4.
        ENDIF.
        APPEND wa_nodestab TO i_nodestab.

        l_arbpl = l_wa_phs-arbpl.
        wa_h_phs = l_wa_phs.
      ENDIF.

      CLEAR : wa_nodestab.
      wa_nodestab-id     = c_4_1.
      wa_nodestab-tlevel = c_4.
      wa_nodestab-parent = c_3_1.
** Phase Number
      wa_nodestab-text    = 'Phase'(038).
      wa_nodestab-tlength =  c_10.
      wa_nodestab-tcolor  =  c_4.

      CONCATENATE wa_h_phs-vornr wa_h_phs-steus
                  wa_h_phs-ltxa1
             INTO wa_nodestab-text1
             SEPARATED BY space.
      wa_nodestab-tlength1 =  c_40.
      wa_nodestab-tcolor1  =  c_4.

** PO Quantity
*      l_prdqty = wa_h_phs-lmnga.
      l_prdqty = wa_h_phs-prdqty.
      l_prduom = wa_h_phs-prduom.

      IF rb_kgm = c_x AND l_prduom <> 'KG'.
        IF wa_h_phs-bsuom <> 'KG'.
          PERFORM convert_to_kg USING   wa_h_ord-plnbez wa_h_phs-bsuom
                                        wa_h_phs-gewei  wa_h_phs-ntgew
                                        wa_h_phs-bprdqty
                               CHANGING l_wprdqty
                                        v_conv_rc.
          IF v_conv_rc <> 'X'.
            l_prdqty = l_wprdqty.
            l_prduom = 'KG'.
          ENDIF.

        ELSE.
          l_prdqty = wa_h_phs-bprdqty.
          l_prduom = 'KG'.
        ENDIF.
      ENDIF.

      WRITE : l_prdqty TO l_prdq UNIT l_prduom NO-GROUPING,
              l_prduom TO l_uom.

*** text for Order Qty
      IF rb_pland = c_x.
** Planned Production
        CONCATENATE 'Plan Qty:'(076) l_prdq l_uom
               INTO wa_nodestab-text2 SEPARATED BY space.
      ELSE.
** Actual Production
        IF rb_prod = c_x.
* Produced
          CONCATENATE 'Prod Qty:'(033) l_prdq l_uom
                 INTO wa_nodestab-text2 SEPARATED BY space.
        ELSE.
* Confirmed
          CONCATENATE 'Conf Qty:'(034) l_prdq l_uom
                 INTO wa_nodestab-text2 SEPARATED BY space.
        ENDIF.
      ENDIF.

      CONDENSE : wa_nodestab-text2.

      wa_nodestab-tlength2 =  32.
      wa_nodestab-tcolor2  =  c_4.
      APPEND wa_nodestab TO i_nodestab.
***
*** Activity Information
***
      CLEAR  wa_nodestab.
      wa_nodestab-id     = c_5_1.
      wa_nodestab-tlevel = c_5.
      wa_nodestab-parent = c_4_1.

      wa_nodestab-text    = 'Activity'(052).
      wa_nodestab-tlength = 34.

      wa_nodestab-text1    = 'Actual Usage'(040).
      wa_nodestab-tlength1 = c_20.

      wa_nodestab-text2    = 'Standard Usage'(041).
      wa_nodestab-tlength2 = c_20.

      IF rb_fiscl = c_x.
        CONCATENATE 'Standard Usage Var'(042) v_waers
               INTO wa_nodestab-text3 SEPARATED BY space.
      ELSE.
        CONCATENATE 'Standard Usage Var'(042) 'UoM'
               INTO wa_nodestab-text3 SEPARATED BY space.
      ENDIF.
      wa_nodestab-tlength3 = c_24.

      CONCATENATE 'Standard Usage Var'(042) c_perc
             INTO wa_nodestab-text4 SEPARATED BY space.
      wa_nodestab-tlength4 = c_20.

      wa_nodestab-tcolor  = c_4.
      wa_nodestab-tcolor1 = c_4.
      wa_nodestab-tcolor2 = c_4.
      wa_nodestab-tcolor3 = c_4.
      wa_nodestab-tcolor4 = c_4.

      APPEND wa_nodestab TO i_nodestab.

      CLEAR : flg_color , l_act , l_std , l_svar , l_svarp , l_wa_act,
              l_total1  , l_total2.
      LOOP AT i_h_act INTO wa_h_act WHERE aufnr = wa_h_phs-aufnr
                                      AND aufpl = wa_h_phs-aufpl
                                      AND aplzl = wa_h_phs-aplzl
                                      AND vornr = wa_h_phs-vornr.
        CLEAR : wa_nodestab.
        wa_nodestab-id     = c_6_1.
        wa_nodestab-tlevel = c_6.
        wa_nodestab-parent = c_5_1.

        wa_nodestab-text    = wa_h_act-txtxx.
        wa_nodestab-tlength = c_30.
        wa_nodestab-tlength1 = c_20.
        wa_nodestab-tlength2 = c_20.
        wa_nodestab-tlength3 = c_24.
        wa_nodestab-tlength4 = c_20.

        IF rb_quant = c_x.
          WRITE : wa_h_act-ismxx TO l_act UNIT wa_h_act-ilexx
          NO-GROUPING,
                  wa_h_act-ilexx TO l_uom.
          CONCATENATE l_act l_uom INTO wa_nodestab-text1
                                  SEPARATED BY space.

          WRITE : wa_h_act-vgwxx TO l_std UNIT wa_h_act-vgexx
          NO-GROUPING,
                  wa_h_act-vgexx TO l_uom.
          CONCATENATE l_std l_uom INTO wa_nodestab-text2
                                  SEPARATED BY space.

          WRITE wa_h_act-stdvar TO l_svar UNIT wa_h_act-vgexx
          NO-GROUPING.
          CONCATENATE l_svar l_uom INTO wa_nodestab-text3
                                   SEPARATED BY space.
          IF wa_h_act-ismxx <> 0.
            IF l_total2 <> c_x.
              l_total2 = c_x.
              l_wa_act-ilexx = wa_h_act-ilexx.
            ENDIF.

            IF l_wa_act-ilexx = wa_h_act-ilexx.
              l_wa_act-ismxx = l_wa_act-ismxx + wa_h_act-ismxx.
              l_wa_act-ilexx = wa_h_act-ilexx.

            ELSEIF wa_h_act-ismxx <> 0.
              CLEAR : l_wa_act-ismxx , l_wa_act-ilexx.
            ENDIF.
          ENDIF.

          IF wa_h_act-vgwxx <> 0.
            IF l_total1 <> c_x.
              l_total1 = c_x.
              l_wa_act-vgexx = wa_h_act-vgexx.
            ENDIF.

            IF l_wa_act-vgexx = wa_h_act-vgexx.
              l_wa_act-vgwxx  = l_wa_act-vgwxx  + wa_h_act-vgwxx.
              l_wa_act-stdvar = l_wa_act-stdvar + wa_h_act-stdvar.
              l_wa_act-vgexx = wa_h_act-vgexx.

            ELSEIF wa_h_act-vgwxx <> 0.
              CLEAR : l_wa_act-vgwxx , l_wa_act-vgexx, l_wa_act-stdvar.
            ENDIF.
          ENDIF.

          IF wa_h_act-vgwxx <> 0.
            wa_h_act-varper = ( wa_h_act-stdvar / wa_h_act-vgwxx ) * 100
            .
          ENDIF.

        ELSE.

          wa_h_act-actu = wa_h_act-ismxx * ( wa_h_act-togxx /
                wa_h_act-toexx ).

          WRITE : wa_h_act-actu TO l_act CURRENCY v_waers NO-GROUPING,
                  v_waers TO l_uom.
          CONCATENATE l_act l_uom INTO wa_nodestab-text1
                                  SEPARATED BY space.

          wa_h_act-stdu = wa_h_act-vgwxx *
                        ( wa_h_act-togxx / wa_h_act-toexx ).

          WRITE wa_h_act-stdu TO l_std CURRENCY v_waers NO-GROUPING.
          CONCATENATE l_std l_uom INTO wa_nodestab-text2
                                  SEPARATED BY space.

          wa_h_act-varu = wa_h_act-stdvar *
                        ( wa_h_act-togxx / wa_h_act-toexx ).

          WRITE wa_h_act-varu TO l_svar CURRENCY v_waers NO-GROUPING.
          CONCATENATE l_svar l_uom INTO wa_nodestab-text3
                                   SEPARATED BY space.
          IF wa_h_act-stdu <> 0.
            wa_h_act-varper = ( wa_h_act-varu / wa_h_act-stdu ) * 100.
          ENDIF.

          l_wa_act-actu = l_wa_act-actu + wa_h_act-actu.
          l_wa_act-stdu = l_wa_act-stdu + wa_h_act-stdu.
          l_wa_act-varu = l_wa_act-varu + wa_h_act-varu.
        ENDIF.

        WRITE wa_h_act-varper TO l_svarp NO-GROUPING DECIMALS 2.
        CONCATENATE l_svarp c_perc INTO wa_nodestab-text4
                                   SEPARATED BY space.
        IF flg_color = c_x.
          CLEAR flg_color.
          wa_nodestab-tcolor  = c_3.
          wa_nodestab-tcolor1 = c_3.
          wa_nodestab-tcolor2 = c_3.
          wa_nodestab-tcolor3 = c_3.
          wa_nodestab-tcolor4 = c_3.
          wa_nodestab-tcolor5 = c_3.
          wa_nodestab-tcolor6 = c_3.
          wa_nodestab-tcolor7 = c_3.
          wa_nodestab-tcolor8 = c_3.
        ELSE.
          flg_color = c_x.
          wa_nodestab-tcolor  = c_2.
          wa_nodestab-tcolor1 = c_2.
          wa_nodestab-tcolor2 = c_2.
          wa_nodestab-tcolor3 = c_2.
          wa_nodestab-tcolor4 = c_2.
          wa_nodestab-tcolor5 = c_2.
          wa_nodestab-tcolor6 = c_2.
          wa_nodestab-tcolor7 = c_2.
          wa_nodestab-tcolor8 = c_2.
        ENDIF.

        APPEND wa_nodestab TO i_nodestab.
      ENDLOOP.
*** Displaying Activity Subtotals
      CLEAR  wa_nodestab.
      wa_nodestab-id     = c_6_1.
      wa_nodestab-tlevel = c_6.
      wa_nodestab-parent = c_5_1.

      wa_nodestab-text    = 'Activity Totals'(074).
      wa_nodestab-tlength =  c_30.
      wa_nodestab-tcolor  =  c_6.

      IF rb_quant = c_x.
        WRITE : l_wa_act-ismxx TO l_act UNIT l_wa_act-ilexx NO-GROUPING,
                l_wa_act-ilexx TO l_uom.
        CONCATENATE l_act l_uom INTO wa_nodestab-text1
                                SEPARATED BY space.

        WRITE : l_wa_act-vgwxx TO l_std UNIT l_wa_act-vgexx NO-GROUPING,
                l_wa_act-vgexx TO l_uom.
        CONCATENATE l_std l_uom INTO wa_nodestab-text2
                                SEPARATED BY space.

        WRITE : l_wa_act-stdvar TO l_svar UNIT l_wa_act-vgexx
        NO-GROUPING.
        CONCATENATE l_svar l_uom INTO wa_nodestab-text3
                                 SEPARATED BY space.

      ELSE.
        WRITE : l_wa_act-actu TO l_act CURRENCY v_waers NO-GROUPING,
                v_waers TO l_uom.
        CONCATENATE l_act l_uom INTO wa_nodestab-text1
                                SEPARATED BY space.

        WRITE : l_wa_act-stdu TO l_std CURRENCY v_waers NO-GROUPING.
        CONCATENATE l_std l_uom INTO wa_nodestab-text2
                                SEPARATED BY space.

        WRITE : l_wa_act-varu TO l_svar UNIT l_wa_act-vgexx NO-GROUPING.
        CONCATENATE l_svar l_uom INTO wa_nodestab-text3
                                 SEPARATED BY space.
      ENDIF.

      wa_nodestab-tlength1 = c_20.
      wa_nodestab-tlength2 = c_20.
      wa_nodestab-tlength3 = c_24.

      wa_nodestab-tcolor1  = c_6.
      wa_nodestab-tcolor2  = c_6.
      wa_nodestab-tcolor3  = c_6.
      APPEND wa_nodestab TO i_nodestab.
      CLEAR : wa_nodestab.

***
*** Material Information
***
      READ TABLE i_h_mat INTO wa_h_mat WITH KEY aufnr = wa_h_phs-aufnr
                                                aufpl = wa_h_phs-aufpl
                                                aplzl = wa_h_phs-aplzl
                                                vornr = wa_h_phs-vornr.
      CHECK sy-subrc = 0.

      CLEAR : wa_nodestab.
      wa_nodestab-id      = c_5_2.
      wa_nodestab-tlevel  = c_5.
      wa_nodestab-parent  = c_4_1.
      PERFORM material_header USING wa_nodestab.

      APPEND wa_nodestab TO i_nodestab.

      CLEAR : wa_nodestab , l_menge  , l_stprs  ,
              l_total1    , l_total2 , l_total3 ,
              l_wa_mat    , l_aqtys  , l_sqtys  , l_svars.
      LOOP AT i_h_mat INTO wa_h_mat WHERE aufnr = wa_h_phs-aufnr
                                      AND aufpl = wa_h_phs-aufpl
                                      AND aplzl = wa_h_phs-aplzl
                                      AND vornr = wa_h_phs-vornr.
        l_smenge = l_menge.
        l_sstprs = l_stprs.
        PERFORM do_mat_calc CHANGING wa_h_mat
                                     l_aqty    l_matuom
                                     l_sqty    l_stduom
                                     l_svar    l_varuom
                                     l_svarp
                                     l_amenge  l_smenge
                                     l_astprs  l_sstprs.
        l_menge = l_menge + l_smenge.
        l_stprs = l_stprs + l_sstprs.

        CHECK wa_h_mat-sumi = c_x.

        CLEAR: wa_nodestab , l_menge , l_stprs.
        wa_nodestab-id     = c_6_2.
        wa_nodestab-tlevel = c_6.
        wa_nodestab-parent = c_5_2.
* Material Number
        WRITE wa_h_mat-matnr TO wa_nodestab-text NO-ZERO.
* Material Description
        wa_nodestab-text1 = wa_h_mat-maktx.

        wa_nodestab-tlength  = c_18.
        wa_nodestab-tlength1 = c_30.
        wa_nodestab-tlength2 = c_22.
        wa_nodestab-tlength3 = c_22.
        wa_nodestab-tlength4 = c_24.
        wa_nodestab-tlength5 = c_20.

        IF l_matuom <> v_waers.
          WRITE : l_matuom TO l_uom.
        ELSE.
          WRITE : v_waers TO l_uom.
        ENDIF.
        CONCATENATE l_aqty l_uom INTO wa_nodestab-text2
                                 SEPARATED BY space.

        IF l_stduom <> v_waers.
          WRITE : l_stduom TO l_uom.
        ELSE.
          WRITE : v_waers TO l_uom.
        ENDIF.
        CONCATENATE l_sqty l_uom INTO wa_nodestab-text3
                                 SEPARATED BY space.

        IF l_varuom <> v_waers.
          WRITE : l_varuom TO l_uom.
        ELSE.
          WRITE : v_waers TO l_uom.
        ENDIF.
        CONCATENATE l_svar l_uom INTO wa_nodestab-text4
                                 SEPARATED BY space.

        CONCATENATE l_svarp c_perc INTO wa_nodestab-text5
                                   SEPARATED BY space.
        wa_nodestab-tcolor   = c_3.
        wa_nodestab-tcolor1  = c_3.
        wa_nodestab-tcolor2  = c_3.
        wa_nodestab-tcolor3  = c_3.
        wa_nodestab-tcolor4  = c_3.
        wa_nodestab-tcolor5  = c_3.

        APPEND wa_nodestab TO i_nodestab.

        IF l_aqty CA '123456789'.
          IF l_total1 <> c_x.
            l_total1 = c_x.
            l_wa_mat-actuom = l_matuom.
          ENDIF.

          IF l_wa_mat-actuom <> l_matuom.
            CLEAR : l_wa_mat-actusg , l_wa_mat-astprs , l_wa_mat-actuom,
                    l_aqtys, l_amenge , l_astprs.
          ENDIF.
        ENDIF.

        IF l_sqty CA '123456789'.
          IF l_total2 <> c_x.
            l_total2 = c_x.
            l_wa_mat-stduom  = l_stduom.
          ENDIF.

          IF l_wa_mat-stduom <> l_stduom.
            CLEAR : l_wa_mat-stdusg , l_wa_mat-sstprs ,
                    l_wa_mat-stduom ,
                    l_sqtys, l_smenge , l_sstprs.
          ENDIF.
        ENDIF.

        IF l_svar CA '123456789'.
          IF l_total3 <> c_x.
            l_total3 = c_x.
            l_wa_mat-varuom  = l_varuom.
          ENDIF.

          IF l_wa_mat-varuom  <> l_varuom.
            CLEAR : l_wa_mat-stdvar, l_wa_mat-varprs , l_wa_mat-varuom,
                    l_svars, wa_h_mat-vstprs , wa_h_mat-stdvar.
          ENDIF.
        ENDIF.

        CASE c_x.
          WHEN rb_quant.
            l_wa_mat-actusg  = l_wa_mat-actusg  + l_amenge.
            WRITE l_wa_mat-actusg TO l_aqtys UNIT l_wa_mat-actuom
            NO-GROUPING.

            l_wa_mat-stdusg  = l_wa_mat-stdusg  + l_smenge.
            WRITE l_wa_mat-stdusg TO l_sqtys UNIT l_wa_mat-stduom
            NO-GROUPING.

            l_wa_mat-stdvar  = l_wa_mat-stdvar  + wa_h_mat-stdvar.
            WRITE : l_wa_mat-stdvar TO l_svars UNIT l_wa_mat-stduom
            NO-GROUPING.

          WHEN rb_fiscl.
            l_wa_mat-astprs  = l_wa_mat-astprs  + l_astprs.
            v_prs = l_wa_mat-astprs.
            WRITE v_prs TO l_aqtys CURRENCY v_waers NO-GROUPING.

            l_wa_mat-sstprs  = l_wa_mat-sstprs  + l_sstprs.
            v_prs = l_wa_mat-sstprs.
            WRITE v_prs TO l_sqtys CURRENCY v_waers NO-GROUPING.

            l_wa_mat-varprs  = l_wa_mat-varprs  + wa_h_mat-vstprs.
            v_prs = l_wa_mat-varprs.
            WRITE v_prs TO l_svars CURRENCY v_waers NO-GROUPING.
        ENDCASE.
      ENDLOOP.
*** Displaying Material Subtotals
      CLEAR  wa_nodestab.
      wa_nodestab-id     = c_6_2.
      wa_nodestab-tlevel = c_6.
      wa_nodestab-parent = c_5_2.

      wa_nodestab-text  = 'Material Totals'(043).
      wa_nodestab-text1 = space.

      wa_nodestab-tlength  = c_18.
      wa_nodestab-tlength1 = c_30.
      wa_nodestab-tlength2 = c_22.
      wa_nodestab-tlength3 = c_22.
      wa_nodestab-tlength4 = c_24.

      IF l_wa_mat-actuom <> v_waers.
        WRITE : l_wa_mat-actuom TO l_uom.
      ELSE.
        WRITE : v_waers TO l_uom.
      ENDIF.
      CONCATENATE l_aqtys l_uom INTO wa_nodestab-text2
                                SEPARATED BY space.

      IF l_wa_mat-stduom <> v_waers.
        WRITE : l_wa_mat-stduom TO l_uom.
      ELSE.
        WRITE : v_waers TO l_uom.
      ENDIF.
      CONCATENATE l_sqtys l_uom INTO wa_nodestab-text3
                                SEPARATED BY space.

      IF l_wa_mat-varuom <> v_waers.
        WRITE : l_wa_mat-varuom TO l_uom.
      ELSE.
        WRITE : v_waers TO l_uom.
      ENDIF.
      CONCATENATE l_svars l_uom INTO wa_nodestab-text4
                                SEPARATED BY space.
      wa_nodestab-tcolor   = c_6.
      wa_nodestab-tcolor1  = c_6.
      wa_nodestab-tcolor2  = c_6.
      wa_nodestab-tcolor3  = c_6.
      wa_nodestab-tcolor4  = c_6.

      APPEND wa_nodestab TO i_nodestab.
      CLEAR : wa_nodestab, l_aqtys, l_sqtys, l_svars.
    ENDLOOP.
  ENDLOOP.

  i_h_phs = l_i_phs.
ENDFORM.                    " DISPLAY_PHASE_REPORT

*&--------------------------------------------------------------------*
*&      Form  display_summary_report
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM display_summary_report.

  DATA: l_prdqty  TYPE gamng,
        l_prdq    TYPE char18,
        l_wprdqty TYPE menge_d,
        l_tprdqty TYPE menge_d,
        l_prduom  TYPE meins,

        l_act    TYPE char16,
        l_std    TYPE char16,

        l_actt   TYPE char16,
        l_stdt   TYPE char16,
        l_svart  TYPE char18,

        l_amenge TYPE menge_d,
        l_smenge TYPE menge_d,
        l_menge  TYPE menge_d,

        l_astprs  TYPE ty_stprs,
        l_sstprs  TYPE ty_stprs,
        l_stprs   TYPE ty_stprs,
        l_stprsq  TYPE ty_stprs,
        l_varprsq TYPE ty_stprs,

        l_matuom TYPE meins,
        l_stduom TYPE meins,
        l_varuom TYPE meins,
        l_uom    TYPE meins,

        l_aqty   TYPE char18,
        l_sqty   TYPE char18,
        l_svar   TYPE char18,
        l_svarp  TYPE char18,
        l_svarq  TYPE char18,

        l_aqtyv  TYPE char18,
        l_sqtyv  TYPE char18,
        l_svarv  TYPE char18,
        l_svarpv TYPE char18,

        l_aqtyg  TYPE char18,
        l_sqtyg  TYPE char18,
        l_svarg  TYPE char18,
        l_svargq TYPE char18,

        l_aqtys  TYPE char18,
        l_sqtys  TYPE char18,
        l_svars  TYPE char18,

        l_total1  TYPE char1,
        l_total2  TYPE char1,
        l_total3  TYPE char1,

        l_totalg1 TYPE char1,
        l_totalg2 TYPE char1,
        l_totalg3 TYPE char1,

        l_wa_acts TYPE ty_hier_act_sum,
        l_wa_mats TYPE ty_hier_mat_sum.

  PERFORM pfstatus.
  SET PF-STATUS 'MAIN' EXCLUDING i_fcode.
  SET TITLEBAR 'VARI' WITH text-067.

  REFRESH : i_nodestab.

  MOVE 'Display Summary Report'(029) TO v_output_text.
  PERFORM inform_user_of_progress.

  CLEAR wa_nodestab.
  wa_nodestab-id = c_1_1.
  wa_nodestab-tlevel = c_1.
  wa_nodestab-text = 'Production Variances'(031).
  wa_nodestab-tlength = c_20.
  wa_nodestab-compress = c_x.
  APPEND wa_nodestab TO i_nodestab.

  CLEAR: wa_nodestab.
  wa_nodestab-id     = c_2_1.
  wa_nodestab-tlevel = c_2.
  wa_nodestab-parent = c_1_1.

  CONCATENATE 'Summary of Orders for'(046) 'Plant:'(047) p_werks
         INTO wa_nodestab-text SEPARATED BY space.
  wa_nodestab-tlength = c_45.
  wa_nodestab-tcolor  = c_1.

  IF r_steus IS INITIAL.
    wa_nodestab-text1 = 'Control Key : ALL'(075).
  ELSE.
    CLEAR : wa_steus.
    READ TABLE r_steus INTO wa_steus INDEX 1.
    CONCATENATE 'Control Key:'(048) wa_steus-low 'TO' wa_steus-high
           INTO wa_nodestab-text1 SEPARATED BY space.
  ENDIF.
  wa_nodestab-tlength1 = c_25.
  wa_nodestab-tcolor1  = c_1.

  IF s_arbpl[] IS INITIAL.
    wa_nodestab-text2 = 'Resources: All'(049).
  ELSE.
    CONCATENATE 'Resources:'(065) s_arbpl-low c_hyp s_arbpl-high
           INTO wa_nodestab-text2 SEPARATED BY space.
  ENDIF.
  wa_nodestab-tlength2 = c_25.
  wa_nodestab-tcolor2  = c_1.

  APPEND wa_nodestab TO i_nodestab.

  CLEAR : l_tprdqty.
  LOOP AT i_h_ord INTO wa_h_ord.
* convert to KG
    CLEAR : l_wprdqty.
    IF wa_h_ord-bsuom <> 'KG'.
      PERFORM convert_to_kg USING   wa_h_ord-plnbez wa_h_ord-bsuom
                                    wa_h_ord-gewei  wa_h_ord-ntgew
                                    wa_h_ord-bprdqty
                           CHANGING l_wprdqty
                                    v_conv_rc.
      IF v_conv_rc <> 'X'.
        l_prdqty = l_wprdqty.
        l_prduom = 'KG'.
      ELSE.
        CLEAR : l_wprdqty.
      ENDIF.

    ELSE.
      l_prdqty = wa_h_ord-bprdqty.
      l_prduom = 'KG'.
    ENDIF.

    l_tprdqty = l_tprdqty + l_prdqty.
  ENDLOOP.

  WRITE : l_tprdqty TO l_prdq UNIT 'KG' NO-GROUPING.

  CLEAR : wa_nodestab.
  wa_nodestab-id     = c_3_1.
  wa_nodestab-tlevel = c_3.
  wa_nodestab-parent = c_2_1.

*** text for Order Qty
  IF rb_pland = c_x.
** Planned Production
    CONCATENATE 'Plan Qty:'(076) l_prdq 'KG'
           INTO wa_nodestab-text SEPARATED BY space.
  ELSE.
** Actual Production
    IF rb_prod = c_x.
* Produced
      CONCATENATE 'Prod Qty:'(033) l_prdq 'KG'
             INTO wa_nodestab-text SEPARATED BY space.
    ELSE.
* Confirmed
      CONCATENATE 'Conf Qty:'(034) l_prdq 'KG'
             INTO wa_nodestab-text SEPARATED BY space.
    ENDIF.
  ENDIF.

  CONDENSE : wa_nodestab-text.

  wa_nodestab-tlength = c_35.
  wa_nodestab-tcolor  = c_1.

  APPEND wa_nodestab TO i_nodestab.

***
*** Activity Summary
***
  CLEAR : wa_nodestab.
  wa_nodestab-id     = c_3_2.
  wa_nodestab-tlevel = c_3.
  wa_nodestab-parent = c_2_1.

  wa_nodestab-text    = 'Activity'(052).
  wa_nodestab-tlength = 34.

  wa_nodestab-tlength1 = c_20.
  wa_nodestab-tlength2 = c_20.
  wa_nodestab-tlength3 = c_24.
  wa_nodestab-tlength4 = c_20.

  IF rb_fiscl = c_x.
    CONCATENATE 'Actual Usage'(040) v_waers
           INTO wa_nodestab-text1 SEPARATED BY space.

    CONCATENATE 'Standard Usage'(041) v_waers
           INTO wa_nodestab-text2 SEPARATED BY space.

    CONCATENATE 'Standard Usage Var'(042) v_waers
           INTO wa_nodestab-text3 SEPARATED BY space.

  ELSE.
    CONCATENATE 'Actual Usage'(040) 'UoM'
           INTO wa_nodestab-text1 SEPARATED BY space.

    CONCATENATE 'Standard Usage'(041) 'UoM'
           INTO wa_nodestab-text2 SEPARATED BY space.

    CONCATENATE 'Standard Usage Var'(042) 'UoM'
           INTO wa_nodestab-text3 SEPARATED BY space.

  ENDIF.

  CONCATENATE 'Standard Usage Var'(042) c_perc
         INTO wa_nodestab-text4 SEPARATED BY space.

  wa_nodestab-tcolor  = c_4.
  wa_nodestab-tcolor1 = c_4.
  wa_nodestab-tcolor2 = c_4.
  wa_nodestab-tcolor3 = c_4.
  wa_nodestab-tcolor4 = c_4.
  APPEND wa_nodestab TO i_nodestab.

  CLEAR : flg_color , l_actt , l_stdt , l_svart , l_svarp,
          l_wa_acts.
  LOOP AT i_parn INTO wa_parn.
    CLEAR : wa_acts, flg_color , l_act , l_std , l_svar , l_svarp.
    LOOP AT i_h_act INTO wa_h_act WHERE parxx = wa_parn-parxx.
      wa_acts-parxx = wa_h_act-parxx.
      wa_acts-txtxx = wa_h_act-txtxx.

      IF rb_quant EQ c_x.
        wa_acts-ilexx  = wa_h_act-ilexx.
        wa_acts-ismxx  = wa_acts-ismxx  + wa_h_act-ismxx.
        wa_acts-vgexx  = wa_h_act-vgexx.
        wa_acts-vgwxx  = wa_acts-vgwxx  + wa_h_act-vgwxx.
        wa_acts-stdvar = wa_acts-stdvar + wa_h_act-stdvar.

        IF wa_acts-ilexx IS INITIAL AND NOT wa_acts-vgexx IS INITIAL.
          wa_acts-ilexx = wa_acts-vgexx.

        ELSEIF NOT wa_acts-ilexx IS INITIAL AND
                   wa_acts-vgexx IS INITIAL.
          wa_acts-vgexx = wa_acts-ilexx.
        ENDIF.

      ELSE.

        IF wa_h_act-toexx <> 0.
          wa_acts-actu = wa_acts-actu + wa_h_act-ismxx  *
                       ( wa_h_act-togxx / wa_h_act-toexx ).
          wa_acts-stdu = wa_acts-stdu + wa_h_act-vgwxx  *
                       ( wa_h_act-togxx / wa_h_act-toexx ).
          wa_acts-varu = wa_acts-varu + wa_h_act-stdvar *
                       ( wa_h_act-togxx / wa_h_act-toexx ).
        ENDIF.
      ENDIF.
    ENDLOOP.

    CLEAR : wa_nodestab.
    wa_nodestab-id     = c_4_1.
    wa_nodestab-tlevel = c_4.
    wa_nodestab-parent = c_3_2.

    wa_nodestab-text    = wa_acts-txtxx.
    wa_nodestab-tlength = c_30.
    wa_nodestab-tlength1 = c_20.
    wa_nodestab-tlength2 = c_20.
    wa_nodestab-tlength3 = c_24.
    wa_nodestab-tlength4 = c_20.

    IF rb_quant = c_x.
      WRITE : wa_acts-ismxx TO l_act UNIT wa_acts-ilexx NO-GROUPING,
              wa_acts-ilexx TO l_uom.
      CONCATENATE l_act l_uom INTO wa_nodestab-text1
                              SEPARATED BY space.

      WRITE : wa_acts-vgwxx TO l_std UNIT wa_acts-vgexx NO-GROUPING,
              wa_acts-vgexx TO l_uom.
      CONCATENATE l_std l_uom INTO wa_nodestab-text2
                              SEPARATED BY space.

      WRITE : wa_acts-stdvar TO l_svar UNIT wa_acts-vgexx NO-GROUPING.
      CONCATENATE l_svar l_uom INTO wa_nodestab-text3
                               SEPARATED BY space.
      IF wa_acts-vgwxx <> 0.
        wa_acts-varper = ( wa_acts-stdvar / wa_acts-vgwxx ) * 100.
      ENDIF.

      WRITE wa_acts-varper TO l_svarp DECIMALS 2 NO-GROUPING.
      CONCATENATE l_svarp c_perc INTO wa_nodestab-text4
                                 SEPARATED BY space.
      IF wa_acts-ismxx <> 0.
        IF l_total2 <> c_x.
          l_total2 = c_x.
          l_wa_acts-ilexx = wa_acts-ilexx.
        ENDIF.

        IF l_wa_acts-ilexx = wa_acts-ilexx AND NOT l_wa_acts-ilexx IS
        INITIAL.
          l_wa_acts-ismxx = l_wa_acts-ismxx + wa_acts-ismxx.
          l_wa_acts-ilexx = wa_acts-ilexx.

        ELSEIF wa_acts-ismxx <> 0.
          CLEAR : l_wa_acts-ismxx , l_wa_acts-ilexx, l_actt.
        ENDIF.
      ENDIF.

      IF wa_acts-vgwxx <> 0.
        IF l_total1 <> c_x.
          l_total1 = c_x.
          l_wa_acts-vgexx = wa_acts-vgexx.
        ENDIF.

        IF l_wa_acts-vgexx = wa_acts-vgexx AND NOT l_wa_acts-vgexx IS
        INITIAL.
          l_wa_acts-vgwxx  = l_wa_acts-vgwxx  + wa_acts-vgwxx.
          l_wa_acts-stdvar = l_wa_acts-stdvar + wa_acts-stdvar.
          l_wa_acts-vgexx = wa_acts-vgexx.

        ELSEIF wa_acts-vgwxx <> 0.
          CLEAR : l_wa_acts-vgwxx , l_wa_acts-vgexx, l_wa_acts-stdvar,
                  l_stdt, l_svart.
        ENDIF.
      ENDIF.

      WRITE l_wa_acts-ismxx  TO l_actt  UNIT l_wa_acts-ilexx NO-GROUPING
      .
      WRITE l_wa_acts-vgwxx  TO l_stdt  UNIT l_wa_acts-vgexx NO-GROUPING
      .
      WRITE l_wa_acts-stdvar TO l_svart UNIT l_wa_acts-vgexx NO-GROUPING
      .

    ELSE.
      WRITE : wa_acts-actu TO l_act CURRENCY v_waers NO-GROUPING.
*      l_act = wa_acts-actu.
      CONCATENATE l_act v_waers INTO wa_nodestab-text1
                                SEPARATED BY space.

      WRITE : wa_acts-stdu TO l_std CURRENCY v_waers NO-GROUPING.
*      l_std = wa_acts-stdu.
      CONCATENATE l_std v_waers INTO wa_nodestab-text2
                                SEPARATED BY space.

      WRITE : wa_acts-varu TO l_svar CURRENCY v_waers NO-GROUPING.
*      l_svar = wa_acts-varu.
      CONCATENATE l_svar v_waers INTO wa_nodestab-text3
                                 SEPARATED BY space.

      IF wa_acts-stdu <> 0.
        wa_acts-varper = ( wa_acts-varu / wa_acts-stdu ) * 100.
      ENDIF.
      l_svarp = wa_acts-varper.
      CONCATENATE l_svarp c_perc INTO wa_nodestab-text4
                                 SEPARATED BY space.

      l_wa_acts-actu = l_wa_acts-actu + wa_acts-actu.
      l_wa_acts-stdu = l_wa_acts-stdu + wa_acts-stdu.
      l_wa_acts-varu = l_wa_acts-varu + wa_acts-varu.

      WRITE l_wa_acts-actu TO l_actt CURRENCY v_waers NO-GROUPING.
      WRITE l_wa_acts-stdu TO l_stdt CURRENCY v_waers NO-GROUPING.
      WRITE l_wa_acts-varu TO l_svart CURRENCY v_waers NO-GROUPING.
      l_wa_acts-ilexx = v_waers.
      l_wa_acts-vgexx = v_waers.
    ENDIF.

    IF flg_color = c_x.
      CLEAR flg_color.
      wa_nodestab-tcolor  = c_3.
      wa_nodestab-tcolor1 = c_3.
      wa_nodestab-tcolor2 = c_3.
      wa_nodestab-tcolor3 = c_3.
      wa_nodestab-tcolor4 = c_3.
    ELSE.
      flg_color = c_x.
      wa_nodestab-tcolor  = c_2.
      wa_nodestab-tcolor1 = c_2.
      wa_nodestab-tcolor2 = c_2.
      wa_nodestab-tcolor3 = c_2.
      wa_nodestab-tcolor4 = c_2.
    ENDIF.
    APPEND wa_nodestab TO i_nodestab.
  ENDLOOP.
* Displaying Activity Subtotals
  CLEAR  wa_nodestab.
  wa_nodestab-id     = c_4_1.
  wa_nodestab-tlevel = c_4.
  wa_nodestab-parent = c_3_2.

  wa_nodestab-text     = 'Activity Totals'(074).
  wa_nodestab-tlength  = c_30.
  wa_nodestab-tlength1 = c_20.
  wa_nodestab-tlength2 = c_20.
  wa_nodestab-tlength3 = c_24.

  IF l_wa_acts-ilexx <> v_waers.
    WRITE : l_wa_acts-ilexx TO l_uom.
  ELSE.
    WRITE : v_waers TO l_uom.
  ENDIF.
  CONCATENATE l_actt  l_uom INTO wa_nodestab-text1
                            SEPARATED BY space.

  IF l_wa_acts-vgexx <> v_waers.
    WRITE : l_wa_acts-vgexx TO l_uom.
  ELSE.
    WRITE : v_waers TO l_uom.
  ENDIF.
  CONCATENATE l_stdt  l_uom INTO wa_nodestab-text2
                            SEPARATED BY space.

  CONCATENATE l_svart l_uom INTO wa_nodestab-text3
                            SEPARATED BY space.

  wa_nodestab-tcolor  =  c_6.
  wa_nodestab-tcolor1  = c_6.
  wa_nodestab-tcolor2  = c_6.
  wa_nodestab-tcolor3  = c_6.

  APPEND wa_nodestab TO i_nodestab.
  CLEAR : wa_nodestab.

***
*** Material Information
***
  READ TABLE i_h_mat INTO wa_h_mat INDEX 1.
  IF sy-subrc = 0.

    CLEAR : wa_nodestab.
    wa_nodestab-id      = c_3_3.
    wa_nodestab-tlevel  = c_3.
    wa_nodestab-parent  = c_2_1.
    PERFORM material_header USING wa_nodestab.

    APPEND wa_nodestab TO i_nodestab.

    CLEAR : wa_nodestab , l_amenge  , l_smenge  , l_wa_mats,
            l_totalg1   , l_totalg2 , l_totalg3 ,
            l_sqtyg     , l_aqtyg   , l_svarg ,
            l_svargq    , l_stprsq.

    LOOP AT i_matn INTO wa_matn.
      CLEAR : wa_mats  , l_sqty   , l_aqty  , l_svar  , l_svarp,
              l_svarq  , l_varprsq,
              l_total1 , l_total2 , l_total3, l_menge , l_stprs.

      LOOP AT i_h_mat INTO wa_h_mat WHERE matnr = wa_matn-matnr
                                      AND bwart = wa_matn-bwart.
        "28/06/2005++
        CLEAR : l_amenge , l_astprs , l_smenge , l_sstprs.

        l_sstprs = l_stprs.
        l_smenge = l_menge.
        PERFORM do_mat_calc CHANGING wa_h_mat
                                     l_aqtyv   l_matuom
                                     l_sqtyv   l_stduom
                                     l_svarv   l_varuom
                                     l_svarpv
                                     l_amenge  l_smenge
                                     l_astprs  l_sstprs.
        l_stprs = l_stprs + l_sstprs.
        l_menge = l_menge + l_smenge.

        CHECK wa_h_mat-sumi = c_x.
        CLEAR : l_menge , l_stprs.

        IF rb_quant EQ c_x.
          IF l_matuom IS INITIAL OR l_matuom EQ l_stduom.
            wa_h_mat-stdvar = l_smenge - l_amenge.
          ENDIF.

          IF l_amenge <> 0.
            IF l_total1 <> c_x.
              l_total1 = c_x.
              wa_mats-actuom = l_matuom.
            ENDIF.

            IF wa_mats-actuom = l_matuom.
              wa_mats-actusg = wa_mats-actusg + l_amenge.
            ELSE.
              CLEAR : wa_mats-actusg , wa_mats-actuom, l_aqty ,
                      wa_mats-actuom.
            ENDIF.
          ENDIF.

          IF l_smenge <> 0.
            IF l_total2 <> c_x.
              l_total2 = c_x.
              wa_mats-stduom = l_stduom.
            ENDIF.

            IF wa_mats-stduom = l_stduom.
              wa_mats-stdusg = wa_mats-stdusg + l_smenge.
            ELSE.
              CLEAR : wa_mats-stdusg , wa_mats-stduom, l_sqty ,
                      wa_mats-stduom.
            ENDIF.
          ENDIF.

          IF wa_h_mat-stdvar <> 0.
            IF l_total3 <> c_x.
              l_total3 = c_x.
              wa_mats-varuom = l_stduom.
            ENDIF.

            IF wa_mats-varuom = l_stduom.
              wa_mats-stdvar = wa_mats-stdvar + wa_h_mat-stdvar.
            ELSE.
              CLEAR : wa_mats-stdvar, wa_mats-varuom, l_svar.
            ENDIF.
          ENDIF.

          WRITE : wa_mats-actusg TO l_aqty UNIT wa_mats-actuom
                                           NO-GROUPING.
          WRITE : wa_mats-stdusg TO l_sqty UNIT wa_mats-stduom
                                           NO-GROUPING.
          WRITE : wa_mats-stdvar TO l_svar UNIT wa_mats-stduom
                                           NO-GROUPING.

          wa_mats-astprs = wa_mats-astprs + l_astprs.
          wa_mats-sstprs = wa_mats-sstprs + l_sstprs.
          wa_mats-varprs = wa_mats-varprs + l_sstprs - l_astprs.

          v_prs = wa_mats-varprs.
          WRITE : v_prs TO l_svarq CURRENCY v_waers NO-GROUPING.
        ELSE.

          wa_mats-astprs = wa_mats-astprs + l_astprs.
          wa_mats-sstprs = wa_mats-sstprs + l_sstprs.
          wa_mats-varprs = wa_mats-varprs + l_sstprs - l_astprs.

          wa_mats-actuom = v_waers.
          wa_mats-stduom = v_waers.
          wa_mats-varuom = v_waers.

          v_prs = wa_mats-astprs.
          WRITE : v_prs TO l_aqty CURRENCY v_waers NO-GROUPING.
          v_prs = wa_mats-sstprs.
          WRITE : v_prs TO l_sqty CURRENCY v_waers NO-GROUPING.
          v_prs = wa_mats-varprs.
          WRITE : v_prs TO l_svar CURRENCY v_waers NO-GROUPING.
        ENDIF.

        wa_mats-matnr  = wa_h_mat-matnr.
        wa_mats-maktx  = wa_h_mat-maktx.

        l_varprsq = wa_mats-varprs.
      ENDLOOP.

      IF wa_mats-stduom  = wa_mats-actuom OR wa_mats-actuom IS INITIAL.
        CASE c_x.
          WHEN rb_quant.
            IF wa_mats-stdusg > 0.
              wa_mats-varper = ( wa_mats-stdvar / wa_mats-stdusg ) *
                                 100.
            ELSE.
              wa_mats-varper = 0.
            ENDIF.

          WHEN rb_fiscl.
            IF wa_mats-sstprs > 0.
              wa_mats-varper = ( wa_mats-varprs / wa_mats-sstprs ) *
                                 100.
            ELSE.
              wa_mats-varper = 0.
            ENDIF.
        ENDCASE.
      ENDIF.
      WRITE wa_mats-varper TO l_svarp DECIMALS 2 NO-GROUPING.

      IF l_aqty CA '123456789'.
        IF l_totalg1 <> c_x.
          l_totalg1 = c_x.
          l_wa_mats-actuom = wa_mats-actuom.
        ENDIF.

        IF l_wa_mats-actuom <> wa_mats-actuom.
          CLEAR : l_wa_mats-actusg , l_wa_mats-astprs , l_aqtyg ,
                  l_wa_mats-actuom , wa_mats-actusg , wa_mats-astprs.
        ENDIF.
      ENDIF.

      IF l_sqty CA '123456789'.
        IF l_totalg2 <> c_x.
          l_totalg2 = c_x.
          l_wa_mats-stduom  = wa_mats-stduom.
        ENDIF.

        IF l_wa_mats-stduom <> wa_mats-stduom.
          CLEAR : l_wa_mats-stdusg , l_wa_mats-sstprs , l_sqtyg ,
                  l_wa_mats-stduom , wa_mats-stdusg , wa_mats-sstprs .
        ENDIF.
      ENDIF.

      IF l_svar CA '123456789'.
        IF l_totalg3 <> c_x.
          l_totalg3 = c_x.
          l_wa_mats-varuom  = wa_mats-varuom.
        ENDIF.

        IF l_wa_mats-varuom  <> wa_mats-varuom.
          CLEAR : l_wa_mats-stdvar, l_wa_mats-varprs , l_svarg ,
                  l_wa_mats-varuom, wa_mats-stdvar , wa_mats-varprs.
        ENDIF.
      ENDIF.

      CASE c_x.
        WHEN rb_quant.
          l_wa_mats-actusg  = l_wa_mats-actusg  + wa_mats-actusg.
          WRITE : l_wa_mats-actusg TO l_aqtyg UNIT l_wa_mats-actuom
          NO-GROUPING.

          l_wa_mats-stdusg  = l_wa_mats-stdusg  + wa_mats-stdusg.
          WRITE : l_wa_mats-stdusg TO l_sqtyg UNIT l_wa_mats-stduom
          NO-GROUPING.

          l_wa_mats-stdvar  = l_wa_mats-stdvar  + wa_mats-stdvar.
          WRITE : l_wa_mats-stdvar TO l_svarg UNIT l_wa_mats-varuom
          NO-GROUPING.

          l_stprsq  = l_stprsq  + l_varprsq.
          v_prs = l_stprsq.
          WRITE : v_prs TO l_svargq CURRENCY v_waers NO-GROUPING.

        WHEN rb_fiscl.
          l_wa_mats-astprs  = l_wa_mats-astprs  + wa_mats-astprs.
          v_prs = l_wa_mats-astprs.
          WRITE : v_prs TO l_aqtyg CURRENCY v_waers NO-GROUPING.

          l_wa_mats-sstprs  = l_wa_mats-sstprs  + wa_mats-sstprs.
          v_prs = l_wa_mats-sstprs.
          WRITE : v_prs TO l_sqtyg CURRENCY v_waers NO-GROUPING.

          l_wa_mats-varprs  = l_wa_mats-varprs  + wa_mats-varprs.
          v_prs = l_wa_mats-varprs.
          WRITE : v_prs TO l_svarg CURRENCY v_waers NO-GROUPING.
      ENDCASE.

      CLEAR: wa_nodestab.
      wa_nodestab-id     = c_4_2.
      wa_nodestab-tlevel = c_4.
      wa_nodestab-parent = c_3_3.

      wa_nodestab-tcolor   = c_3.
      wa_nodestab-tcolor1  = c_3.
      wa_nodestab-tcolor2  = c_3.
      wa_nodestab-tcolor3  = c_3.
      wa_nodestab-tcolor4  = c_3.
      wa_nodestab-tcolor5  = c_3.

      wa_nodestab-tlength  = c_18.
      wa_nodestab-tlength1 = c_30.
      wa_nodestab-tlength2 = c_22.
      wa_nodestab-tlength3 = c_22.
      wa_nodestab-tlength4 = c_24.
      wa_nodestab-tlength5 = c_20.

* Material Number
      WRITE wa_mats-matnr TO wa_nodestab-text NO-ZERO.
* Material Description
      wa_nodestab-text1 = wa_mats-maktx.

      IF wa_mats-actuom <> v_waers.
        WRITE : wa_mats-actuom TO l_uom.
      ELSE.
        WRITE : v_waers TO l_uom.
      ENDIF.
      CONCATENATE l_aqty l_uom INTO wa_nodestab-text2
                               SEPARATED BY space.

      IF wa_mats-stduom <> v_waers.
        WRITE : wa_mats-stduom TO l_uom.
      ELSE.
        WRITE : v_waers TO l_uom.
      ENDIF.
      CONCATENATE l_sqty l_uom INTO wa_nodestab-text3
                               SEPARATED BY space.

      IF wa_mats-varuom <> v_waers.
        WRITE : wa_mats-varuom TO l_uom.
      ELSE.
        WRITE : v_waers TO l_uom.
      ENDIF.
      CONCATENATE l_svar l_uom INTO wa_nodestab-text4
                               SEPARATED BY space.

      CONCATENATE l_svarp c_perc INTO wa_nodestab-text5
                                 SEPARATED BY space.

      IF rb_quant = c_x.
        wa_nodestab-tcolor6   = c_3.
        wa_nodestab-tlength6  = c_24.
        CONCATENATE l_svarq v_waers INTO wa_nodestab-text6
                                    SEPARATED BY space.
      ENDIF.

      APPEND wa_nodestab TO i_nodestab.
      CLEAR : wa_nodestab.
    ENDLOOP.

*** Displaying Material Subtotals
    CLEAR  wa_nodestab.
    wa_nodestab-id     = c_4_2.
    wa_nodestab-tlevel = c_4.
    wa_nodestab-parent = c_3_3.

    wa_nodestab-text    = 'Material Totals'(043).
    wa_nodestab-text1 = space.

    wa_nodestab-tlength =  c_18.
    wa_nodestab-tlength2 = c_22.
    wa_nodestab-tlength1 = c_30.
    wa_nodestab-tlength3 = c_22.
    wa_nodestab-tlength4 = c_24.
    wa_nodestab-tlength5 = c_20.

    IF l_wa_mats-actuom <> v_waers.
      WRITE : l_wa_mats-actuom TO l_uom.
    ELSE.
      WRITE : v_waers TO l_uom.
    ENDIF.
    CONCATENATE l_aqtyg l_uom INTO wa_nodestab-text2
                              SEPARATED BY space.

    IF l_wa_mats-stduom <> v_waers.
      WRITE : l_wa_mats-stduom TO l_uom.
    ELSE.
      WRITE : v_waers TO l_uom.
    ENDIF.
    CONCATENATE l_sqtyg l_uom INTO wa_nodestab-text3
                              SEPARATED BY space.

    IF l_wa_mats-varuom <> v_waers.
      WRITE : l_wa_mats-varuom TO l_uom.
    ELSE.
      WRITE : v_waers TO l_uom.
    ENDIF.
    CONCATENATE l_svarg l_uom INTO wa_nodestab-text4
                              SEPARATED BY space.

    IF rb_quant = c_x.
      wa_nodestab-tcolor6   = c_6.
      wa_nodestab-tlength6  = c_24.
      CONCATENATE l_svargq v_waers INTO wa_nodestab-text6
                                  SEPARATED BY space.
    ENDIF.

    wa_nodestab-tcolor  =  c_6.
    wa_nodestab-tcolor2  = c_6.
    wa_nodestab-tcolor3  = c_6.
    wa_nodestab-tcolor4  = c_6.

    APPEND wa_nodestab TO i_nodestab.
    CLEAR : wa_nodestab.
  ENDIF.

*** Displaying Summary totals
  IF rb_fiscl = c_x.
*    l_astprs = l_wa_acts-actu * 10 + l_wa_mats-astprs.
*    l_sstprs = l_wa_acts-stdu * 10 + l_wa_mats-sstprs.
    l_astprs = l_wa_acts-actu + l_wa_mats-astprs.
    l_sstprs = l_wa_acts-stdu + l_wa_mats-sstprs.

    l_stprs  = l_sstprs - l_astprs.

    v_prs = l_astprs.
    WRITE : v_prs TO l_aqtys CURRENCY v_waers NO-GROUPING.
    v_prs = l_sstprs.
    WRITE : v_prs TO l_sqtys CURRENCY v_waers NO-GROUPING.
    v_prs = l_stprs.
    WRITE : v_prs TO l_svars CURRENCY v_waers NO-GROUPING.

    CLEAR  wa_nodestab.
    wa_nodestab-id     = c_3_4.
    wa_nodestab-tlevel = c_3.
    wa_nodestab-parent = c_2_1.

    wa_nodestab-text    = 'Summary Totals'.
    wa_nodestab-text1 = space.

    wa_nodestab-tlength =  c_18.
    wa_nodestab-tlength2 = c_22.
    wa_nodestab-tlength1 = c_30.
    wa_nodestab-tlength3 = c_22.
    wa_nodestab-tlength4 = c_24.

    WRITE : v_waers TO l_uom.
    CONCATENATE l_aqtys l_uom INTO wa_nodestab-text2
                              SEPARATED BY space.

    CONCATENATE l_sqtys l_uom INTO wa_nodestab-text3
                              SEPARATED BY space.

    CONCATENATE l_svars l_uom INTO wa_nodestab-text4
                              SEPARATED BY space.
    wa_nodestab-tcolor  =  c_5.
    wa_nodestab-tcolor1  = c_5.
    wa_nodestab-tcolor2  = c_5.
    wa_nodestab-tcolor3  = c_5.
    wa_nodestab-tcolor4  = c_5.

    APPEND wa_nodestab TO i_nodestab.
    CLEAR : wa_nodestab.
  ENDIF.

ENDFORM.                    " DISPLAY_SUMMARY_REPORT

*&--------------------------------------------------------------------*
*&      Form  material_header
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM material_header USING fp_nodestab TYPE snodetext.

  fp_nodestab-text    = 'Material'(058).
  fp_nodestab-tlength = c_22.
  fp_nodestab-tcolor  = c_4.
  fp_nodestab-propfaw = c_x.

  fp_nodestab-text1    = 'Description'(059).
  fp_nodestab-tlength1 = c_30.
  fp_nodestab-tcolor1  = c_4.

  IF rb_fiscl = c_x.
    CONCATENATE 'Actual Usage'(040) v_waers INTO fp_nodestab-text2
                                            SEPARATED BY space.
  ELSE.
    CONCATENATE 'Actual Usage'(040) 'UoM' INTO fp_nodestab-text2
                                          SEPARATED BY space.
  ENDIF.
  fp_nodestab-tlength2 = c_22.
  fp_nodestab-tcolor2  = c_4.

  IF rb_fiscl = c_x.
    CONCATENATE 'Standard Usage'(041) v_waers INTO fp_nodestab-text3
                                              SEPARATED BY space.
  ELSE.
    CONCATENATE 'Standard Usage'(041) 'UoM' INTO fp_nodestab-text3
                                            SEPARATED BY space.
  ENDIF.
  fp_nodestab-tlength3 = c_22.
  fp_nodestab-tcolor3  = c_4.

  IF rb_fiscl = c_x.
    CONCATENATE 'Standard Usage Var'(042) v_waers INTO fp_nodestab-text4
                                                  SEPARATED BY space.
  ELSE.
    CONCATENATE 'Standard Usage Var'(042) 'UoM' INTO fp_nodestab-text4
                                                SEPARATED BY space.
  ENDIF.
  fp_nodestab-tlength4 = c_24.
  fp_nodestab-tcolor4  = c_4.

  CONCATENATE 'Standard Usage Var'(042) c_perc INTO fp_nodestab-text5
                                               SEPARATED BY space.
  fp_nodestab-tlength5 = c_20.
  fp_nodestab-tcolor5  = c_4.

  IF rb_summ = c_x AND rb_quant = c_x.
    CONCATENATE 'Standard Usage Var'(042) v_waers INTO fp_nodestab-text6
                                                  SEPARATED BY space.
    fp_nodestab-tlength6 = c_24.
    fp_nodestab-tcolor6  = c_4.
  ENDIF.

ENDFORM.                    " MATERIAL_HEADER

**&---------------------------------------------------------------------
**
**&      Form  get_orders
**&---------------------------------------------------------------------
**
**       text
**----------------------------------------------------------------------
**
*FORM get_orders.
*
*  DATA: l_sttxt(100)  TYPE c,
*        flg_status(1) TYPE c.
*
*
*  MOVE 'Extracting Process Orders'(022) TO v_output_text.
*
*  PERFORM inform_user_of_progress.
*
*
***START OF MOD-003.
*  IF NOT p_mtart IS INITIAL.
**"selection filter on material type
*    SELECT matnr     "material number
*           mtart     "material type
*    INTO  TABLE i_mtart
*    FROM mara
*    WHERE matnr IN  s_matnr
*    AND   mtart = p_mtart.
*
*    IF sy-subrc <> 0. " if no corresponding data is found
*
*      MESSAGE i072 WITH p_mtart.
*      "No data was selected for  material type
*      LEAVE LIST-PROCESSING.
*
*    ENDIF.
*  ENDIF.
*
*
*  IF NOT i_mtart IS INITIAL.
*    SELECT aufnr
*           werks
*           kokrs
*           objnr
*           gltrp
*           rsnum
*           gamng
*           gmein
*           plnbez
*           plnty
*           plnnr
*           plnal
*           stlst                                            "mod-001
*           stlty
*           stlnr
*           stlal
*           aufpl
*           zaehl
*           rueck
*           INTO TABLE i_orders FROM caufv
*           FOR ALL ENTRIES IN i_mtart          "*----MOD-003
*           WHERE aufnr  IN s_aufnr  AND
*                 werks   = p_werks  AND
*                 kokrs   = p_kokrs  AND
*                 stlan   = p_usage   AND
*                 plnbez  = i_mtart-matnr AND       "*----MOD-003
*               ( gstrp IN s_datuv OR gltrp IN s_datuv ).
***END OF MOD-003.
*
*  ELSE.  "----MOD-003
*    SELECT aufnr
*          werks
*          kokrs
*          objnr
*          gltrp
*          rsnum
*          gamng
*          gmein
*          plnbez
*          plnty
*          plnnr
*          plnal
*          stlst                                             " MOD-001
*          stlty
*          stlnr
*          stlal
*          aufpl
*          zaehl
*          rueck
*          INTO TABLE i_orders FROM caufv
*          WHERE aufnr  IN s_aufnr  AND
*                werks   = p_werks  AND
*                kokrs   = p_kokrs  AND
*                plnbez  IN s_matnr AND
*                stlan   = p_usage   AND
*               ( gstrp IN s_datuv OR gltrp IN s_datuv ).
*
*  ENDIF. "----MOD-003
*
*
*  IF sy-subrc <> 0.
*    MESSAGE s007.
*    LEAVE LIST-PROCESSING.
*  ENDIF.
*
*  SORT i_orders BY aufnr.
*
*  LOOP AT i_orders INTO wa_orders.
*
*    IF NOT i_tj02t[] IS INITIAL .
*      PERFORM get_status_info USING wa_orders-objnr l_sttxt.
*
*      CLEAR: flg_status, wa_tj02t.
*      LOOP AT i_tj02t INTO wa_tj02t.
*        IF l_sttxt NS wa_tj02t-txt04.
*          CLEAR flg_status.
*          EXIT.
*        ELSE.
*          flg_status = c_x.
*          CONTINUE.
*        ENDIF.
*        CLEAR : wa_tj02t.
*      ENDLOOP.
*
*      IF flg_status <> c_x.
*        DELETE i_orders.
*        CONTINUE.
*      ENDIF.
*
*      wa_order_status_text-aufnr = wa_orders-aufnr.
*      wa_order_status_text-sttxt = l_sttxt.
*      APPEND wa_order_status_text TO i_order_status_text.
*      CLEAR  wa_order_status_text.
*    ENDIF.
*
*    CLEAR : wa_orders.
*
*  ENDLOOP.
*
**  ENDIF.
*
*ENDFORM.                    " get_orders
**&---------------------------------------------------------------------
**
**&      Form  get_operations
**&---------------------------------------------------------------------
**
**       text
**----------------------------------------------------------------------
**
**----------------------------------------------------------------------
**
*FORM get_operations.
*
*  DATA l_tabix TYPE sytabix.
*
*  MOVE 'Extracting Phase Information'(023) TO v_output_text.
*  PERFORM inform_user_of_progress.
*
*  SELECT aufpl
*         aplzl
*         plnkn
*         plnty
*         plnnr
*         zaehl
*         vornr
*         arbid
*         rueck
*         steus
*         phflg
*         INTO TABLE i_afvc
*         FROM afvc
*         FOR ALL ENTRIES IN i_orders
*         WHERE aufpl = i_orders-aufpl AND
*               steus IN s_steus       AND
*               phflg = c_x.
*
*  IF sy-subrc = 0.
*    SELECT aufpl
*           aplzl
*           bmsch
*           vgw02
*           lmnga
*           ism02
*           ssavd
*           FROM afvv INTO TABLE i_afvv
*           FOR ALL ENTRIES IN i_afvc
*           WHERE aufpl = i_afvc-aufpl AND
*                 aplzl = i_afvc-aplzl AND
*                 ssavd IN s_datuv.
*
*    IF sy-subrc = 0.
*      SORT i_afvv BY aufpl aplzl.
*    ENDIF.
*    IF NOT ( s_kostl[] IS INITIAL ).
*
*      SELECT objty objid kokrs kostl
*      FROM crco INTO TABLE i_crco
*      FOR ALL ENTRIES IN i_afvc
*      WHERE objty = c_objtyp
*        AND objid = i_afvc-arbid.
*      IF sy-subrc = 0.
*        SORT i_crco BY kostl.
*      ENDIF.
*    ENDIF.
*
*    SORT i_crhd   BY objid.
*    SORT i_orders BY aufpl.
*
*    SORT i_afvc BY aufpl vornr DESCENDING.
*
*    LOOP AT i_afvc INTO wa_afvc.
*
*      l_tabix = sy-tabix.
*
*      IF NOT ( s_kostl[] IS INITIAL ).
*        READ TABLE i_crco INTO wa_crco
*              WITH KEY objty = c_objtyp
*                       objid = wa_afvc-arbid
*                       BINARY SEARCH.
*        IF sy-subrc = 0.
*          READ TABLE i_csks INTO wa_csks
*                WITH KEY kostl = wa_crco-kostl.
*          IF sy-subrc <> 0.
*            DELETE i_afvv   WHERE aufpl = wa_afvc-aufpl
*                              AND aplzl = wa_afvc-aplzl.
*            DELETE i_afvc INDEX l_tabix.
*            CONTINUE.
*          ENDIF.
*        ENDIF.
*      ENDIF.
*
** Check work centre details with resource
*      IF NOT ( s_arbpl[] IS INITIAL ).
*        READ TABLE i_crhd INTO wa_crhd
*              WITH KEY objid = wa_afvc-arbid BINARY SEARCH.
*        IF sy-subrc <> 0.
*          DELETE i_afvv   WHERE aufpl = wa_afvc-aufpl
*                            AND aplzl = wa_afvc-aplzl.
*          DELETE i_afvc INDEX l_tabix.
*          CONTINUE.
*        ELSE.
*          PERFORM move_data2_ordops.
*        ENDIF.
*      ELSE.
*        READ TABLE i_crhd INTO wa_crhd
*            WITH KEY objid = wa_afvc-arbid BINARY SEARCH.
*        PERFORM move_data2_ordops.
*      ENDIF.
*      CLEAR: wa_crco, wa_crhd, l_tabix, wa_afvc.
*    ENDLOOP.
*
*  ENDIF.
*
*ENDFORM.                    " get_operations
**&---------------------------------------------------------------------
**
**&      Form  get_mat_segment
**&---------------------------------------------------------------------
**
**       text
**----------------------------------------------------------------------
**
**----------------------------------------------------------------------
**
*FORM get_mat_segment.
*  DATA: l_menge TYPE menge_d,
*        l_gamng type menge_d,
*        v_menge type menge_d,
*        l_meins TYPE meins,
*        struct_mara type mara,
*        struct_marc type marc.
*  DATA: l_lmnga  TYPE LMNGA,
*        L_CFUOM type meins.
*
*  IF NOT ( i_pro_orders[] IS INITIAL ).
*    IF NOT ( rb_prod IS INITIAL ).
*
** Extracting goods receipt information
*MOVE 'Extracting Goods Receipt Information'(024) TO v_output_text.
*      PERFORM inform_user_of_progress.
****** Mod-002******************************************************
*      SELECT aufnr mblnr mjahr zeile matnr bwart menge meins
*                                         " sjahr smbln smblp
*             rsnum rspos rsart erfmg erfme
*        FROM aufm               "Table : Goods movements for order
*        INTO TABLE i_mseg1
*         FOR ALL ENTRIES IN i_pro_orders
*       WHERE aufnr = i_pro_orders-aufnr.
**         AND matnr = i_pro_orders-plnbez.
******Mod-002********************************************************
*      IF sy-subrc = 0.
*
**Addition
*        i_mseg =  i_mseg1.
*        LOOP AT i_pro_orders INTO wa_pro_orders.
*          DELETE i_mseg WHERE aufnr = wa_pro_orders-aufnr
*                          AND matnr <> wa_pro_orders-plnbez.
*        ENDLOOP.
**End of addition
***********************Mod-002****************************************
*
*        clear: struct_marc.
*        select single *
*        into struct_marc
*        from marc
*        where matnr = wa_pro_orders-plnbez and
*              werks = wa_pro_orders-werks.
*
*        clear: struct_mara.
*        select single *
*        into struct_mara
*        from mara
*        where matnr = wa_pro_orders-plnbez.
*
**************MOD-002*************************************************
*
*        SORT i_mseg BY aufnr.
*        SORT i_pro_orders BY aufnr.
** Calculatin the quantity according to the movement type and
** assign the value to i_pro_orders internal table
*
*        LOOP AT i_mseg INTO wa_mseg.
*          AT NEW aufnr.
*            CLEAR: l_menge, l_meins, v_menge.
*          ENDAT.
*          IF wa_mseg-bwart = c_101.
*            if struct_marc-frtme is initial.
**              l_menge = l_menge + wa_mseg-menge.
**              l_meins = wa_mseg-erfme.
*              if wa_mseg-erfme = struct_mara-meins.
*                l_menge = l_menge + wa_mseg-erfmg.
*                l_meins = wa_mseg-erfme.
*              else.
*                CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
*                  EXPORTING
*                    i_matnr              = wa_pro_orders-plnbez
*                    i_in_me              = wa_mseg-erfme
*                    i_out_me             = struct_mara-meins
*                    i_menge              = wa_mseg-erfmg
*                  IMPORTING
*                    e_menge              = v_menge
*                  EXCEPTIONS
*                    error_in_application = 1
*                    error                = 2
*                    OTHERS               = 3.
*                IF sy-subrc = 0.
*                  wa_mseg-erfmg = v_menge.
*                ENDIF.
*                l_menge = l_menge + wa_mseg-erfmg.
*                l_meins = wa_mseg-erfme.
*              endif.
*            ELSEIF struct_marc-frtme is not initial.
*              if ( struct_marc-frtme = struct_mara-meins ) and
*                 ( wa_mseg-erfme = struct_marc-frtme ).
*                l_menge = l_menge + wa_mseg-erfmg.
*                l_meins = wa_mseg-erfme.
*              elseif ( struct_marc-frtme = struct_mara-meins ) and
*                     ( wa_mseg-erfme ne struct_marc-frtme ).
*                CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
*                  EXPORTING
*                    i_matnr              = wa_pro_orders-plnbez
*                    i_in_me              = wa_mseg-erfme
*                    i_out_me             = struct_marc-frtme
*                    i_menge              = wa_mseg-erfmg
*                  IMPORTING
*                    e_menge              = v_menge
*                  EXCEPTIONS
*                    error_in_application = 1
*                    error                = 2
*                    OTHERS               = 3.
*                IF sy-subrc = 0.
*                  wa_mseg-erfmg = v_menge.
*                ENDIF.
*                l_menge = l_menge + wa_mseg-erfmg.
*                l_meins = wa_mseg-erfme.
*              elseif ( struct_marc-frtme ne struct_mara-meins ) and
*                     ( wa_mseg-erfme ne struct_marc-frtme ).
*                CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
*                  EXPORTING
*                    i_matnr              = wa_pro_orders-plnbez
*                    i_in_me              = wa_mseg-erfme
*                    i_out_me             = struct_marc-frtme
*                    i_menge              = wa_mseg-erfmg
*                  IMPORTING
*                    e_menge              = v_menge
*                  EXCEPTIONS
*                    error_in_application = 1
*                    error                = 2
*                    OTHERS               = 3.
*                IF sy-subrc = 0.
*                  wa_mseg-erfmg = v_menge.
*                ENDIF.
*                l_menge = l_menge + wa_mseg-erfmg.
*                l_meins = wa_mseg-erfme.
*              else.
*                CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
*                  EXPORTING
*                    i_matnr              = wa_pro_orders-plnbez
*                    i_in_me              = wa_mseg-erfme
*                    i_out_me             = struct_marc-frtme
*                    i_menge              = wa_mseg-erfmg
*                  IMPORTING
*                    e_menge              = v_menge
*                  EXCEPTIONS
*                    error_in_application = 1
*                    error                = 2
*                    OTHERS               = 3.
*                IF sy-subrc = 0.
*                  wa_mseg-erfmg = v_menge.
*                ENDIF.
*                l_menge = l_menge + wa_mseg-erfmg.
*                l_meins = wa_mseg-erfme.
*
*              endif.
*            endif.
*          ELSEIF wa_mseg-bwart = c_102.
*            if struct_marc-frtme is initial.
**              l_menge = l_menge - wa_mseg-menge.
**              l_meins = wa_mseg-erfme.
*
*              if wa_mseg-erfme = struct_mara-meins.
*                l_menge = l_menge - wa_mseg-erfmg.
*                l_meins = wa_mseg-erfme.
*              else.
*                CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
*                  EXPORTING
*                    i_matnr              = wa_pro_orders-plnbez
*                    i_in_me              = wa_mseg-erfme
*                    i_out_me             = struct_mara-meins
*                    i_menge              = wa_mseg-erfmg
*                  IMPORTING
*                    e_menge              = v_menge
*                  EXCEPTIONS
*                    error_in_application = 1
*                    error                = 2
*                    OTHERS               = 3.
*                IF sy-subrc = 0.
*                  wa_mseg-erfmg = v_menge.
*                ENDIF.
*                l_menge = l_menge - wa_mseg-erfmg.
*                l_meins = wa_mseg-erfme.
*              endif.
*            ELSEIF struct_marc-frtme is not initial.
*              if ( struct_marc-frtme = struct_mara-meins ) and
*                 ( wa_mseg-erfme = struct_marc-frtme ).
*                l_menge = l_menge - wa_mseg-erfmg.
*                l_meins = wa_mseg-erfme.
*              elseif ( struct_marc-frtme = struct_mara-meins ) and
*                     ( wa_mseg-erfme ne struct_marc-frtme ).
*                CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
*                  EXPORTING
*                    i_matnr              = wa_pro_orders-plnbez
*                    i_in_me              = wa_mseg-erfme
*                    i_out_me             = struct_marc-frtme
*                    i_menge              = wa_mseg-erfmg
*                  IMPORTING
*                    e_menge              = v_menge
*                  EXCEPTIONS
*                    error_in_application = 1
*                    error                = 2
*                    OTHERS               = 3.
*                IF sy-subrc = 0.
*                  wa_mseg-erfmg = v_menge.
*                ENDIF.
*                l_menge = l_menge - wa_mseg-erfmg.
*                l_meins = wa_mseg-erfme.
*              elseif ( struct_marc-frtme ne struct_mara-meins ) and
*                     ( wa_mseg-erfme ne struct_marc-frtme ).
*                CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
*                  EXPORTING
*                    i_matnr              = wa_pro_orders-plnbez
*                    i_in_me              = wa_mseg-erfme
*                    i_out_me             = struct_marc-frtme
*                    i_menge              = wa_mseg-erfmg
*                  IMPORTING
*                    e_menge              = v_menge
*                  EXCEPTIONS
*                    error_in_application = 1
*                    error                = 2
*                    OTHERS               = 3.
*                IF sy-subrc = 0.
*                  wa_mseg-erfmg = v_menge.
*                ENDIF.
*                l_menge = l_menge - wa_mseg-erfmg.
*                l_meins = wa_mseg-erfme.
*              else.
*                CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
*                  EXPORTING
*                    i_matnr              = wa_pro_orders-plnbez
*                    i_in_me              = wa_mseg-erfme
*                    i_out_me             = struct_marc-frtme
*                    i_menge              = wa_mseg-erfmg
*                  IMPORTING
*                    e_menge              = v_menge
*                  EXCEPTIONS
*                    error_in_application = 1
*                    error                = 2
*                    OTHERS               = 3.
*                IF sy-subrc = 0.
*                  wa_mseg-erfmg = v_menge.
*                ENDIF.
*                l_menge = l_menge - wa_mseg-erfmg.
*                l_meins = wa_mseg-erfme.
*              endif.
*            endif.
**          l_menge = l_menge - wa_mseg-menge.*
*          ENDIF.
**          l_meins = wa_mseg-meins.
*
****** End of MOD-002***************************************
*
*          AT END OF aufnr.
*********Mod-002********************************************
** Don't want zero production orders
*            IF NOT ( rb_ezero IS INITIAL ) AND l_menge = 0.
*              DELETE i_ordops WHERE aufnr = wa_mseg-aufnr.
*              DELETE i_pro_orders WHERE aufnr = wa_mseg-aufnr.
*              CONTINUE.
*            ENDIF.
*            READ TABLE i_pro_orders INTO wa_pro_orders
*              WITH KEY aufnr = wa_mseg-aufnr.
*            wa_pro_orders-menge = l_menge.
*            wa_pro_orders-gruom = l_meins.
*            IF wa_pro_orders-gruom NE wa_pro_orders-gmein.
*              CLEAR l_menge.
*
** If no conversion possible just use gr qty
*              CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'
*                EXPORTING
*                  kzmeinh              = c_x
*                  input                = wa_pro_orders-menge
*                  matnr                = wa_pro_orders-plnbez
*                  meinh                = wa_pro_orders-gmein
*                  meins                = wa_pro_orders-gruom
*                IMPORTING
*                  output               = l_menge
*                EXCEPTIONS
*                  conversion_not_found = 1
*                  input_invalid        = 2
*                  material_not_found   = 3
*                  meinh_not_found      = 4
*                  meins_missing        = 5
*                  no_meinh             = 6
*                  output_invalid       = 7
*                  overflow             = 8
*                  OTHERS               = 9.
*              IF sy-subrc = 0.
*                wa_pro_orders-menge = l_menge.
*              ENDIF.
***********************MOD-003**************************************
*              clear: l_gamng.
*
*              CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'
*                EXPORTING
*                  kzmeinh              = c_x
*                  input                = wa_pro_orders-gamng
*                  matnr                = wa_pro_orders-plnbez
*                  meinh                = wa_pro_orders-gmein
*                  meins                = wa_pro_orders-gruom
*                IMPORTING
*                  output               = l_gamng
*                EXCEPTIONS
*                  conversion_not_found = 1
*                  input_invalid        = 2
*                  material_not_found   = 3
*                  meinh_not_found      = 4
*                  meins_missing        = 5
*                  no_meinh             = 6
*                  output_invalid       = 7
*                  overflow             = 8
*                  OTHERS               = 9.
*              IF sy-subrc = 0.
*                wa_pro_orders-gamng = l_gamng.
*              ENDIF.
*************************MOD-003**************************************
**
*            ENDIF.
*            MODIFY i_pro_orders FROM wa_pro_orders
*            TRANSPORTING menge gruom gamng
*            WHERE aufnr = wa_mseg-aufnr.
*          ENDAT.
************************MOD-003**************************************
*          CLEAR : wa_mseg.
************************MOD-003**************************************
*
*        ENDLOOP.
*      ENDIF.
********************MOD-008******************************************
**** Select confirmations using operation confirmation number instead of
**** order number
**      SELECT aufpl
**            aplzl
**            plnkn
**            plnty
**            plnnr
**            zaehl
**            vornr
**            arbid
**            rueck
**            steus
**            phflg
**            INTO TABLE i_afvc1
**            FROM afvc
**            FOR ALL ENTRIES IN i_ordops
**            WHERE aufpl = I_ORDOPS-aufpl AND
**                  steus = 'YBN1' AND
**                  phflg = c_x.
**
**      IF sy-subrc = 0.
**        SORT I_AFVC1 BY aufpl
**                        aplzl
**                        plnkn
**                        plnty
**                        plnnr.
**
**        SELECT aufpl
**               aplzl
**               bmsch
**               vgw02
**               lmnga
**               ism02
**               ssavd
**               FROM afvv INTO TABLE i_afvv1
**               FOR ALL ENTRIES IN i_afvc1
**               WHERE aufpl = i_afvc1-aufpl AND
**                     aplzl = i_afvc1-aplzl.
**
**        IF SY-SUBRC = 0.
**          SORT I_AFVV1 BY AUFPL APLZL.
**        ENDIF.
**      ENDIF.
*
********************MOD-008******************************************
*      ELSE.
** Extracting confirmation information
*MOVE 'Extracting Confirmation Information'(025) TO v_output_text.
*        PERFORM inform_user_of_progress.
*
**      SELECT aufnr rueck gmnga lmnga gmein meinh
**             meilr stokz rueck_mst
**       FROM afru INTO TABLE i_afru
**       FOR ALL ENTRIES IN i_pro_orders
**       WHERE rueck = i_pro_orders-rueck AND
*** MOD-001- Begin of change
**             lmnga NE c_0. "    AND
***            meilr NE space.
*** MOD-001- End of change
**      IF sy-subrc = 0.
**        SORT i_afru BY aufnr .
************MOD-002************************************************
*
*
*****************MOD-004*********************************************
**
**      LOOP AT I_ORDOPS INTO WA_ORDOPS.
**        SELECT SINGLE *
**        INTO WA_PLPO3
**        FROM plpo
**        WHERE plnty = WA_ordops-plnty and
**              plnnr = wa_ordops-plnnr and
**              PLNKN = wa_ordops-plnkn and
**              ZAEHL = wa_ordops-zaehl.
**        IF SY-SUBRC = 0.
**          APPEND WA_PLPO3 TO I_PLPO3.
**        ENDIF.
**      ENDLOOP.
***             and   steus = 'YBN1'.
**
*****************MOD-005**********************************************
***        LOOP AT I_PRO_ORDERS into WA_PRO_ORDERS.
**********************mod-004****************************************
***          READ TABLE I_PLPO3 INTO WA_PLPO3 WITH KEY
***               plnty = wa_pro_orders-plnty
***               plnnr = wa_pro_orders-plnnr
***               plnkn = wa_pro_orders-plnkn
***               zaehl = wa_pro_orders-zaehl.
****              steus = 'YBN1'.
********************MOD-004*******************************************
**
**
*****************************MOD-005*******************************
**      LOOP AT I_ORDOPS INTO WA_ORDOPS.
*****************************MOD-005******************************
***        READ table i_afvc into wa_afvc with key
****             aufpl = wa_pro_orders-aufpl
***              aufpl = wa_ordops-aufpl binary search.
***              steus = 'YBN1'
***              phflg = c_x binary search.
**
**********************MOD-005*************************************
**
*********************MOD-006*************************************
**        CLEAR: WA_PLPO3.
**        READ TABLE I_PLPO3 INTO WA_PLPO3 WITH KEY
**               plnty = wa_ordops-plnty
**               plnnr = wa_ordops-plnnr
***               plnkn = wa_ordops-plnkn
***               zaehl = wa_ordops-zaehl
**               steus = 'YBN1' binary search.
***               vornr = wa_ordops-vornr
***               werks = p_werks binary search.
**
*********************MOD-006*************************************
**        IF SY-SUBRC = 0.
***         READ table i_afvc into wa_afvc with key
***              aufpl = wa_ordops-aufpl
***              aplzl = wa_ordops-aplzl
***              plnkn = wa_ordops-plnkn
***              plnty = wa_ordops-plnty
***              plnnr = wa_ordops-plnnr
***              zaehl = wa_ordops-zaehl BINARY SEARCH.
******************mod-006*******************************************
**          check wa_plpo3-vgw02 IS NOT INITIAL.
**          clear: wa_afvc.
**          READ TABLE i_afvc INTO wa_afvc
**             WITH KEY plnty = wa_plpo3-plnty
**                      plnnr = wa_plpo3-plnnr
**                      plnkn = wa_plpo3-plnkn
**                      zaehl = wa_plpo3-zaehl
**                      aufpl = wa_ordops-aufpl.
**********************MOD-006*************************************
**          if sy-subrc = 0.
*******************mod-004********************************************
**
**            CLEAR: WA_AFVV.
**            READ TABLE I_AFVV into wa_afvv with key
**                 aufpl = wa_afvc-aufpl
**                 aplzl = wa_afvc-aplzl binary search.
**            if sy-subrc = 0.
**              CLEAR: I_AFRU.
**              SELECT aufnr rueck gmnga lmnga gmein meinh
**                     meilr stokz rueck_mst
**               FROM afru INTO TABLE i_afru
**               WHERE rueck = wa_afvc-rueck AND
***                WHERE rueck = wa_ordops-rueck AND
***                      aufnr = wa_pro_orders-aufnr.
**                     aufnr = wa_ordops-aufnr.
**
**              if sy-subrc = 0.
**                SORT i_afru BY aufnr RUECK.
**                LOOP AT i_afru INTO wa_afru.
***                          READ TABLE i_pro_orders INTO wa_pro_orders
***                          WITH KEY aufnr = wa_afru-aufnr.
**                  IF sy-subrc = 0.
**                    l_lmnga = l_lmnga + wa_afru-lmnga.
**                    l_cfuom = wa_afru-gmein.
***                            wa_pro_orders-lmnga = wa_afru-lmnga.
***                            wa_pro_orders-cfuom = wa_afru-gmein.
***                            MODIFY i_pro_orders FROM wa_pro_orders
***                            TRANSPORTING lmnga cfuom
***                             WHERE aufnr = wa_afru-aufnr.
**                  ENDIF.
**                ENDLOOP.
**              endif.
************************MOD-005**************************************
**              wa_ordops-lmnga = l_lmnga.
**              wa_ordops-cfuom = l_cfuom.
**              MODIFY i_ordops FROM wa_ordops
**                  TRANSPORTING lmnga cfuom
*****************************MOD-006********************************
**                  where plnty = wa_ordops-plnty and
**                        plnnr = wa_ordops-plnnr and
***                         plnkn = wa_ordops-plnkn and
***                         zaehl = wa_ordops-zaehl and
**                        aufpl = wa_ordops-aufpl.
***************************MOD-006*********************************
**
******************MOD-003******************************************
**              clear: l_lmnga, l_cfuom.
******************mod-003**************************************
**            ENDIF.
**          ENDIF.
***           clear: wa_pro_orders.
****************************mod-004********************************
**        ENDIF.
**        clear: wa_ordops.
**      ENDLOOP.
*************************MOD-005*************************************
**
**      i_ordops1[] = i_ordops[].
**      delete i_ordops1 where lmnga eq 0.
**
**      LOOP AT I_PRO_ORDERS INTO WA_PRO_ORDERS.
**        read table i_ordops1 into wa_ordops1 with key
**                  aufnr = wa_pro_orders-aufnr binary search.
**        IF SY-SUBRC = 0.
**          wa_pro_orders-lmnga = wa_ordops1-lmnga.
**          wa_pro_orders-cfuom = wa_ordops1-cfuom.
**          if wa_pro_orders-menge is initial.
**            wa_pro_orders-menge = wa_pro_orders-gamng.
**          endif.
**          MODIFY i_pro_orders FROM wa_pro_orders
**              TRANSPORTING lmnga cfuom menge
**              where aufnr = wa_ordops1-aufnr.
**        ENDIF.
**      ENDLOOP.
**    endif.
********************************MOD-007******************************
*
*** Select confirmations using operation confirmation number instead of
*** order number
*        SELECT aufpl
*              aplzl
*              plnkn
*              plnty
*              plnnr
*              zaehl
*              vornr
*              arbid
*              rueck
*              steus
*              phflg
*              INTO TABLE i_afvc1
*              FROM afvc
*              FOR ALL ENTRIES IN i_ordops
*              WHERE aufpl = I_ORDOPS-aufpl AND
*                    steus = 'YBN1' AND
*                    phflg = c_x.
*
*        IF sy-subrc = 0.
*          SORT I_AFVC1 BY aufpl
*                          aplzl
*                          plnkn
*                          plnty
*                          plnnr.
*
*          SELECT aufpl
*                 aplzl
*                 bmsch
*                 vgw02
*                 lmnga
*                 ism02
*                 ssavd
*                 FROM afvv INTO TABLE i_afvv1
*                 FOR ALL ENTRIES IN i_afvc1
*                 WHERE aufpl = i_afvc1-aufpl AND
*                       aplzl = i_afvc1-aplzl.
*
*          IF SY-SUBRC = 0.
*            SORT I_AFVV1 BY AUFPL APLZL.
*
*            LOOP AT I_ORDOPS INTO WA_ORDOPS.
*              READ TABLE I_PRO_ORDERS INTO WA_PRO_ORDERS WITH KEY
*                                            AUFNR = WA_ORDOPS-AUFNR
*                                                      BINARY SEARCH.
*              IF SY-SUBRC = 0.
*                READ table i_afvc1 into wa_afvc1 with key
*                              plnty = wa_ORDOPS-plnty
*                              plnnr = wa_ORDOPS-plnnr
*                              plnkn = wa_ORDOPS-plnkn
*                              zaehl = wa_ORDOPS-zaehl
*                              aufpl = wa_pro_orders-aufpl.
*                IF SY-SUBRC = 0.
*                  READ TABLE I_AFVV1 into wa_afvv1 with key
*                         aufpl = wa_afvc1-aufpl
*                         aplzl = wa_afvc1-aplzl binary search.
*                  IF SY-SUBRC = 0.
*                    CHECK WA_AFVV1-VGW02 NE 0.
*                    select  aufnr
*                            rueck
*                            gmnga
*                            lmnga
*                            gmein
*                            meinh
*                            meilr
*                            stokz
*                            rueck_mst
*                      INTO TABLE I_AFRU1
*                      from afru
*                      where rueck = wa_afvc1-rueck AND
*                            werks = p_werks and
*                            aufnr = WA_PRO_ORDERS-aufnr and
*                            AUFPL = WA_AFVC1-AUFPL AND
*                            APLZL = WA_AFVC1-APLZL.
*
*                    IF SY-SUBRC = 0.
*
*                      perform get_confirmation_qty_new using
*                                                  wa_ordops-lmnga
*                                                  wa_ordops-cfuom.
*
*                      MODIFY i_ordops FROM wa_ordops
*                              TRANSPORTING lmnga cfuom.
*                    ENDIF.
*                  ENDIF.
*                ENDIF.
*              ENDIF.
*
*            ENDLOOP.
*          ENDIF.
*        ENDIF.
*
*        i_ordops1[] = i_ordops[].
*        delete i_ordops1 where lmnga eq 0.
*        delete adjacent duplicates from i_ordops1 comparing
*                                                    aufnr
*                                                    aufpl
*                                                    aplzl
*                                                    plnkn
*                                                    plnty
*                                                    plnnr
*                                                    zaehl
*                                                    vornr.
*
*
*        LOOP AT I_PRO_ORDERS INTO WA_PRO_ORDERS.
*          read table i_ordops1 into wa_ordops1 with key
*                    aufnr = wa_pro_orders-aufnr binary search.
*          IF SY-SUBRC = 0.
*            wa_pro_orders-lmnga = wa_ordops1-lmnga.
*            wa_pro_orders-cfuom = wa_ordops1-cfuom.
*            if wa_pro_orders-menge is initial.
*              wa_pro_orders-menge = wa_pro_orders-gamng.
*            endif.
*            MODIFY i_pro_orders FROM wa_pro_orders
*                TRANSPORTING lmnga cfuom menge
*                where aufnr = wa_ordops1-aufnr.
*          ENDIF.
*        ENDLOOP.
*      endif.
*  endif.
********MOD-007******************************************************
*
*
*ENDFORM.                    " get_mat_segment
**&---------------------------------------------------------------------
**
**&      Form  get_bom_info
**&---------------------------------------------------------------------
**
**       text
**----------------------------------------------------------------------
**
**----------------------------------------------------------------------
**
*FORM get_bom_info.
*  DATA: wa_doc_segment1 TYPE ty_doc_segment,
*        l_qty TYPE bdmng,
*        l_per TYPE p DECIMALS 3,
*        l_tabix TYPE sytabix,
*        v_menge like ekpo-menge.
*  DATA: STRUCT_MARC TYPE MARC,
*        STRUCT_MARA TYPE MARA.
*
**- Begin of MOD-001
*
*  TYPES: BEGIN OF l_ty_bom_header,
*            stlty TYPE stlty, " BOM category
*            stlnr TYPE stnum, " Bill of material
*            stlal TYPE stalt, " Alternative BOM
*            bmein TYPE basme, " Base unit of measure for BOM
*            bmeng TYPE basmn, " Base Quantity
*          END OF l_ty_bom_header.
*
*  DATA: l_i_bom_header TYPE STANDARD TABLE OF l_ty_bom_header
*        INITIAL SIZE 0,
*
*        l_wa_bom_header TYPE l_ty_bom_header.
*
**- End of MOD-001
*
*  IF NOT i_pro_orders[] IS INITIAL.
*    MOVE 'Extracting BOM Information'(026) TO v_output_text.
*    PERFORM inform_user_of_progress.
*
** Get issued materials for all process orders
*
**Begin of addition
*
*    IF i_mseg1 IS INITIAL.
*** Mod-002*******************************************************
*      SELECT aufnr mblnr mjahr zeile matnr bwart menge meins
*             rsnum rspos rsart erfmg erfme
*         FROM aufm               "Table : Goods movements for order
*         INTO TABLE i_mseg1
*          FOR ALL ENTRIES IN i_pro_orders
*        WHERE aufnr = i_pro_orders-aufnr.
**          AND matnr = i_pro_orders-plnbez.
***** Mod-002***************************************************
*    ENDIF.
*
*    LOOP AT i_pro_orders INTO wa_pro_orders.
*
*      LOOP AT i_mseg1 INTO wa_doc_segment
*                    WHERE mjahr = wa_pro_orders-wdate+0(4)
*                      AND bwart IN i_r_bwart
*                      AND aufnr = wa_pro_orders-aufnr.
*
*        APPEND wa_doc_segment TO i_doc_segment.
*
*        CLEAR : wa_doc_segment.
*      ENDLOOP.
*      CLEAR : wa_pro_orders.
*    ENDLOOP.
*
*    IF NOT i_doc_segment IS INITIAL.
*
*      SELECT mblnr mjahr zeile sjahr smbln smblp rsnum rspos rsart
*        FROM mseg INTO TABLE i_prev_doc
*         FOR ALL ENTRIES IN i_doc_segment
*       WHERE mblnr = i_doc_segment-mblnr
*         AND mjahr = i_doc_segment-mjahr
*         AND zeile = i_doc_segment-zeile.
*
*    ENDIF.
*
*    IF NOT i_doc_segment IS INITIAL.
*
**End of addition
*
*      SORT i_doc_segment BY aufnr.
*
*      LOOP AT i_doc_segment INTO wa_doc_segment1.
*
*        wa_issued_mat-aufnr = wa_doc_segment1-aufnr.
*
** No reservation number so see if any other link exists
*
*        IF wa_doc_segment1-rsnum IS INITIAL.
*
** Try to find any linked previous movements
*          READ TABLE i_prev_doc INTO wa_prev_doc
*          WITH KEY mblnr = wa_doc_segment1-mblnr
*                   mjahr = wa_doc_segment1-mjahr
*                   zeile = wa_doc_segment1-zeile.
*        ENDIF.
*
*        IF wa_doc_segment1-rsnum IS INITIAL AND
*           wa_prev_doc-smbln NE space.
*
*          READ TABLE i_prev_doc INTO wa_prev_doc
*          WITH KEY mblnr = wa_prev_doc-smbln
*                   mjahr = wa_prev_doc-sjahr
*                   zeile = wa_prev_doc-smblp.
*
*          IF sy-subrc = 0 AND NOT ( wa_doc_segment1-rsnum IS INITIAL ).
**   found a previous record
*            wa_issued_mat-rsnum = wa_prev_doc-rsnum.
*            wa_issued_mat-rspos = wa_prev_doc-rspos.
*            wa_issued_mat-rsart = wa_prev_doc-rsart.
*          ENDIF.
*
*        ELSE.
*          wa_issued_mat-rsnum = wa_doc_segment1-rsnum.
*          wa_issued_mat-rspos = wa_doc_segment1-rspos.
*          wa_issued_mat-rsart = wa_doc_segment1-rsart.
*        ENDIF.
*        wa_issued_mat-matnr = wa_doc_segment1-matnr.
*        IF wa_doc_segment1-bwart = c_movm_low_262
*            OR wa_doc_segment1-bwart = c_movm_low_531.
*          wa_issued_mat-menge = wa_doc_segment1-menge * -1.
*        ELSE.
*          wa_issued_mat-menge = wa_doc_segment1-menge.
*        ENDIF.
*        wa_issued_mat-meins = wa_doc_segment1-meins.
*        COLLECT wa_issued_mat INTO i_issued_mat.
*        CLEAR : wa_doc_segment1, wa_prev_doc.
*      ENDLOOP.
*    ENDIF.
*
** Selecting reservations
*    SELECT rsnum rspos rsart xloek matnr werks bdmng
*           meins shkzg aufnr dumps vornr rgekz
*           stlty stlnr stlkn stpoz
*           FROM resb INTO TABLE i_reservations
*           FOR ALL ENTRIES IN i_pro_orders
*           WHERE  rsnum = i_pro_orders-rsnum AND
*           aufnr = i_pro_orders-aufnr
*           AND   bdmng > 0
*           AND   dumps = space.
*    IF sy-subrc = 0.
*      SORT i_reservations.
** Selecting material standard price and price unit
**      SELECT stlty stlnr stlkn stpoz ausch " MOD-001 --
*      SELECT stlty stlnr stlkn stpoz meins menge ausch yyzero"MOD-001++
*              FROM stpo INTO TABLE i_stpo
*              FOR ALL ENTRIES IN i_reservations
*              WHERE stlty = i_reservations-stlty
*              AND   stlnr = i_reservations-stlnr
*              AND   stlkn = i_reservations-stlkn
*              AND   stpoz = i_reservations-stpoz.
*
*      IF sy-subrc = 0.
**Not required to handle as Component scrap in percent is optional
*      ENDIF.
*
*      SELECT matnr werks kausf
*             FROM marc INTO TABLE i_marc
*             FOR ALL ENTRIES IN i_reservations
*             WHERE matnr = i_reservations-matnr
*             AND   werks = i_reservations-werks.
*
*      IF sy-subrc = 0.
**Not required to handle as Component scrap in percent (plant level) is
**optional
*      ENDIF.
*
*      SELECT matnr bwkey stprs peinh
*             FROM mbew INTO TABLE i_mat_valuation
*             FOR ALL ENTRIES IN i_reservations
*             WHERE matnr = i_reservations-matnr
*             AND   bwkey = i_reservations-werks.
*
*      IF sy-subrc = 0.
**Not required to handle Standard Price and Price Unit are not mandatory
*      ENDIF.
**- Begin of MOD-001
*      SELECT stlty stlnr stlal bmein bmeng
*             INTO TABLE l_i_bom_header
*             FROM stko
*             FOR ALL ENTRIES IN i_pro_orders
*             WHERE stlty = i_pro_orders-stlty
*               AND stlnr = i_pro_orders-stlnr
*               AND stlal = i_pro_orders-stlal.
*
*      IF sy-subrc = 0.
** There must be at least one record for process order.
*      ENDIF.
*
**- End of MOD-001
*
*      LOOP AT i_reservations INTO wa_reservations.
*        CLEAR: wa_order_status_text.
*        l_tabix = sy-tabix.
*
*        IF wa_reservations-xloek NE space.
*          READ TABLE i_order_status_text INTO wa_order_status_text
*          WITH KEY aufnr = wa_reservations-aufnr.
*          IF sy-subrc = 0
*            AND wa_order_status_text-sttxt NS c_teco.
*            DELETE i_issued_mat WHERE rsnum = wa_reservations-rsnum
*                                  AND rspos = wa_reservations-rspos
*                                  AND rsart = wa_reservations-rsart.
*            DELETE i_reservations INDEX l_tabix.
*            CONTINUE.
*          ENDIF.
*        ENDIF.
*
*        IF NOT ( rb_nflsh IS INITIAL )
*           AND wa_reservations-rgekz NE space.
*          DELETE i_issued_mat WHERE rsnum = wa_reservations-rsnum
*                                AND rspos = wa_reservations-rspos
*                                AND rsart = wa_reservations-rsart.
*          DELETE i_reservations INDEX l_tabix.
*          CONTINUE.
*        ENDIF.
*        wa_ordmats-aufnr = wa_reservations-aufnr.
*        wa_ordmats-matnr = wa_reservations-matnr.
*        wa_ordmats-vornr = wa_reservations-vornr.
*        wa_ordmats-rsnum = wa_reservations-rsnum.
*        wa_ordmats-rspos = wa_reservations-rspos.
*        wa_ordmats-rsart = wa_reservations-rsart.
*        wa_ordmats-bdmng = wa_reservations-bdmng.
*        wa_ordmats-meins = wa_reservations-meins.
*
*        READ TABLE i_issued_mat INTO wa_issued_mat
*        WITH KEY rsnum = wa_reservations-rsnum
*                 rspos = wa_reservations-rspos
*                 rsart = wa_reservations-rsart.
*        IF sy-subrc = 0.
*          wa_ordmats-menge = wa_ordmats-menge + wa_issued_mat-menge.
*          wa_ordmats-amein = wa_issued_mat-meins.
*        ELSE.
*          wa_ordmats-amein = wa_reservations-meins.
*        ENDIF.
**     Use the reservation quantity as the standard planned quantity
**     If material is by-product need to turn it into a negative number.
*        IF wa_reservations-shkzg = c_s.
*          wa_ordmats-bdmng = wa_ordmats-bdmng * -1.
*        ENDIF.
*
*        READ TABLE i_pro_orders INTO wa_pro_orders
*        WITH KEY aufnr = wa_reservations-aufnr.
**************MOD-003*************************************
*        clear: l_qty.
**************MOD-003*************************************
*        IF rb_prod IS INITIAL.
*          l_qty = wa_pro_orders-lmnga.  "confirmed qty
***************MOD-003************************************
*        ELSEIF ( rb_prod is not initial ) and ( rb_actl is initial ).
*          l_qty = wa_pro_orders-gamng.
*        ELSEIF ( RB_PROD IS NOT INITIAL ) and
*               ( RB_ACTL is not initial ).
*          l_qty = wa_pro_orders-menge.  "goods receipt qty
*        ENDIF.
*
** Calculate the standard quantity
*******************MOD-003****************************
**      IF NOT rb_actl IS INITIAL.
*******************MOD-003****************************
*
********************mod-007*****************************
*        IF L_QTY IS INITIAL.
*          SELECT aufnr rueck gmnga lmnga gmein meinh
*                 meilr stokz rueck_mst
*           FROM afru INTO TABLE i_afru
*           FOR ALL ENTRIES IN i_pro_orders
*           WHERE rueck = i_pro_orders-rueck AND
*                 lmnga NE c_0.
*
*          READ TABLE i_pro_orders INTO wa_pro_orders
*            WITH KEY aufnr = wa_reservations-aufnr.
*          IF SY-SUBRC = 0.
*            READ table i_afvc into wa_afvc with key
*                  aufpl = wa_pro_orders-aufpl
*                  steus = 'YBN1'
*                  phflg = c_x binary search.
*            IF SY-SUBRC = 0.
*              READ TABLE I_AFVV into wa_afvv with key
*                     aufpl = wa_afvc-aufpl
*                     aplzl = wa_afvc-aplzl binary search.
*              if sy-subrc = 0.
*                SORT i_afru BY aufnr RUECK.
*                LOOP AT i_afru INTO wa_afru
*                  WHERE  AUFNR = WA_PRO_ORDERS-AUFNR AND
*                         RUECK = WA_AFVC-RUECK.
*                  IF sy-subrc = 0.
*                    l_QTY = l_QTY + wa_afru-lmnga.
*                  ENDIF.
*                ENDLOOP.
*                check wa_pro_orders-gamng ne 0.
*                clear: wa_ordmats-stdqy.
*                wa_ordmats-stdqy = ( l_qty / wa_pro_orders-gamng ) *
*                                                      wa_ordmats-bdmng.
*              endif.
*            ENDIF.
*          ENDIF.
*********************************MOD-007*****************************
*        ELSE.
*          check wa_pro_orders-gamng ne 0.
*          clear: wa_ordmats-stdqy.
*          wa_ordmats-stdqy = ( l_qty / wa_pro_orders-gamng ) *
*                                                wa_ordmats-bdmng.
*        ENDIF.
*******************MOD-006***********************
*
**        check wa_pro_orders-gamng ne 0.
**        clear: wa_ordmats-stdqy.
**        wa_ordmats-stdqy = ( l_qty / wa_pro_orders-gamng ) *
**                                        wa_ordmats-bdmng.
*******************mod-006************************
**        ELSE.
********MOD-002****************************************
***          check wa_pro_orders-menge ne 0.
***          wa_ordmats-stdqy = ( l_qty / wa_pro_orders-menge ) *
***                              wa_ordmats-bdmng.
**          check wa_pro_orders-gamng ne 0.
**          wa_ordmats-stdqy = ( l_qty / wa_pro_orders-gamng ) *
**                                          wa_ordmats-bdmng.
**      ENDIF.
*******MOD-002*******************************************
*********************MOD-003*******************************
*
*
** gets the zero loss figure from the bom
*
**- Begin of MOD-001
*
**        READ TABLE i_stpo INTO wa_stpo
**        WITH KEY stlty = wa_reservations-stlty
**                 stlnr = wa_reservations-stlnr
**                 stlkn = wa_reservations-stlkn
**                 stpoz = wa_reservations-stpoz.
**        IF sy-subrc = 0 AND NOT ( wa_stpo-ausch IS INITIAL ).
**          l_per = ( wa_stpo-ausch / c_100 ) * wa_ordmats-stdqy.
**        ELSE.
**          READ TABLE i_marc INTO wa_marc
**          WITH KEY matnr = wa_reservations-matnr
**                   werks = wa_reservations-werks.
**          IF sy-subrc = 0 AND NOT ( wa_marc-kausf IS INITIAL ).
**            l_per = ( wa_marc-kausf / c_100 ) * wa_ordmats-stdqy.
**          ELSE.
**            MOVE c_0 TO l_per.
**          ENDIF.
**        ENDIF.
*
**        wa_ordmats-zloss = wa_ordmats-stdqy - l_per.
*
*        CLEAR l_qty.
*        IF rb_actl IS INITIAL.
*          l_qty = wa_pro_orders-gamng.
*        ELSEIF rb_pland IS INITIAL.
*          l_qty = wa_pro_orders-menge.
*        ENDIF.
*
*        READ TABLE l_i_bom_header INTO l_wa_bom_header
*             WITH KEY stlty = wa_pro_orders-stlty
*                      stlnr = wa_pro_orders-stlnr
*                      stlal = wa_pro_orders-stlal.
*
*        IF sy-subrc IS INITIAL.
**************mod-002**************************************
*          IF L_WA_BOM_HEADER-BMEIN NE WA_PRO_ORDERS-GMEIN.
*            CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
*              EXPORTING
*                i_matnr              = wa_pro_orders-PLNBEZ
*                i_in_me              = wa_pro_orders-gmein
*                i_out_me             = l_wa_bom_header-bmein
*                i_menge              = l_qty
*              IMPORTING
*                e_menge              = v_menge
*              EXCEPTIONS
*                error_in_application = 1
*                error                = 2
*                OTHERS               = 3.
*            IF sy-subrc = 0.
*              l_qty = v_menge.
*            ENDIF.
*          ENDIF.
*
*
************mod-002*****************************************
*          IF l_wa_bom_header-bmeng IS NOT INITIAL.
*
*            READ TABLE i_stpo INTO wa_stpo
*            WITH KEY stlty = wa_reservations-stlty
*                     stlnr = wa_reservations-stlnr
*                     stlkn = wa_reservations-stlkn
*                     stpoz = wa_reservations-stpoz.
*
*            l_per = wa_stpo-menge *
*                    ( l_qty / l_wa_bom_header-bmeng ).
*
*            wa_ordmats-zloss = l_per * wa_stpo-yyzero.
*
*          ENDIF.
*
*        ENDIF.
*
**- End of MOD-001
*        READ TABLE i_mat_valuation INTO wa_mat_valuation
*        WITH KEY matnr = wa_reservations-matnr
*                 bwkey = wa_reservations-werks.
*        IF sy-subrc = 0.
*          wa_ordmats-stprs = wa_mat_valuation-stprs.
*          wa_ordmats-peinh = wa_mat_valuation-peinh.
*        ENDIF.
*
** Adding material number to I_MATERIAL_NO internal table
*        wa_material_no-matnr = wa_reservations-matnr.
*
*        APPEND: wa_ordmats TO i_ordmats,
*                wa_material_no TO i_material_no.
*        CLEAR:  wa_ordmats, l_qty, l_per, wa_stpo, wa_marc,
*                wa_issued_mat, wa_pro_orders, wa_mat_valuation,
*                wa_material_no, l_tabix, wa_reservations.
*
*      ENDLOOP.
** Now we need to see if any of the materials issued to the order
** are not on the BOM (ie replacement materials)
** First summarise the data
*      SORT i_ordmats BY aufnr matnr rsnum.
*      LOOP AT i_issued_mat INTO wa_issued_mat.
*        READ TABLE i_ordmats INTO wa_ordmats
*         WITH KEY aufnr = wa_issued_mat-aufnr
*                  matnr = wa_issued_mat-matnr
*                  rsnum = wa_issued_mat-rsnum
*                  BINARY SEARCH.
*        IF sy-subrc GE 4.
** material not on bom table so add it
*          CLEAR: wa_ordmats.
** Get the standard price info for costing purposes in output
*          READ TABLE i_mat_valuation INTO wa_mat_valuation
*          WITH KEY matnr = wa_issued_mat-matnr
*                   bwkey = p_werks.
*          wa_issued_mat-stprs = wa_mat_valuation-stprs.
*          wa_issued_mat-peinh = wa_mat_valuation-peinh.
*          MODIFY i_issued_mat FROM wa_issued_mat.
*          wa_ordmats-stprs = wa_mat_valuation-stprs.
*          wa_ordmats-peinh = wa_mat_valuation-peinh.
*          MOVE: wa_issued_mat-aufnr TO wa_ordmats-aufnr,
*                wa_issued_mat-matnr TO wa_ordmats-matnr,
*                wa_issued_mat-menge TO wa_ordmats-menge,
*                wa_issued_mat-meins TO wa_ordmats-meins,
*                wa_issued_mat-meins TO wa_ordmats-amein.
*          COLLECT wa_ordmats INTO i_ordmats.
*
*        ELSE.
** material is on bom table so delete from sum_msegi
*          DELETE i_issued_mat. " FROM wa_issued_mat.
*        ENDIF.
*        CLEAR : wa_issued_mat.
*      ENDLOOP.
*
*      CLEAR wa_issued_mat.
*
** Retrieve task list information of operations/activity from PLPO table
*      SELECT * FROM plpo INTO TABLE i_plpo
*            FOR ALL ENTRIES IN i_pro_orders
*            WHERE plnty = i_pro_orders-plnty
*            AND   plnnr = i_pro_orders-plnnr
*            AND   plnkn = i_pro_orders-plnkn
*            AND   zaehl = i_pro_orders-zaehl.
*
*      IF sy-subrc = 0.
**Not required to handle
**Task list - operation/activity information is optional
*      ENDIF.
*
*      SELECT rueck rmzhl ism01 ism02 ism03 ism04 ism05 ism06 stokz
*             FROM afru INTO TABLE i_ord_conf
*             FOR ALL ENTRIES IN i_pro_orders
*             WHERE rueck = i_pro_orders-rueck.
*
*
*      IF sy-subrc = 0.
**Not required to handle
**Order Confirmations information is not mandatiory
*      ENDIF.
*    ENDIF.
*
*    IF NOT i_ordops[] IS INITIAL.
*
*      SELECT * FROM plpo INTO TABLE i_plpo1
*            FOR ALL ENTRIES IN i_ordops
*            WHERE plnty = i_ordops-plnty
*            AND   plnnr = i_ordops-plnnr
*            AND   plnkn = i_ordops-plnkn
*            AND   zaehl = i_ordops-zaehl.
*
*      IF sy-subrc = 0.
**Not required to handle
**operations information is optional.
*      ENDIF.
*
*      SELECT rueck rmzhl ism01 ism02 ism03 ism04 ism05 ism06 stokz
*             FROM afru INTO TABLE i_ord_conf1
*             FOR ALL ENTRIES IN i_ordops
*             WHERE rueck = i_ordops-rueck.
*
*      IF sy-subrc = 0.
**Not required to handle
**Order Confirmations information is not mandatiory
*      ENDIF.
*
*    ENDIF.
*  ENDIF.
*ENDFORM.                    " get_bom_info
*
**&---------------------------------------------------------------------
**
**&      Form  output
**&---------------------------------------------------------------------
**
**       text
**----------------------------------------------------------------------
**
**----------------------------------------------------------------------
**
*FORM output.
*
*  MOVE 'Formatting Output'(027) TO v_output_text.
*  PERFORM inform_user_of_progress.
*
** Selecting material descriptions
*  SELECT matnr maktx
*         FROM makt INTO TABLE i_material_des
*         FOR ALL ENTRIES IN i_material_no
*         WHERE spras = sy-langu
*         AND   matnr = i_material_no-matnr.
*
*  IF sy-subrc = 0.
**Not required to handle
**Material desc is optinal
*  ENDIF.
*
*
** Selecting Work centers descriptions
*  SELECT objid ktext
*         FROM crtx INTO TABLE i_wc_text
*         FOR ALL ENTRIES IN i_pro_orders
*         WHERE objty = c_objtyp
*         AND   objid = i_pro_orders-arbid
*         AND   spras = sy-langu.
*
*  IF sy-subrc = 0.
**Not required to handle
**Work centers descriptions are optional
*  ENDIF.
*
*  CASE c_x.
*    WHEN rb_detl.
*      PERFORM display_detail_report.
*    WHEN rb_summ.
*      PERFORM display_summary_report.
*    WHEN rb_phase.
*      PERFORM display_phase_report.
*  ENDCASE.
*
*
*ENDFORM.                    " output
*
**&---------------------------------------------------------------------
**
**&      Form  move_data2_ordops
**&---------------------------------------------------------------------
**
**       text
**----------------------------------------------------------------------
**
**----------------------------------------------------------------------
**
*FORM move_data2_ordops.
*
*  READ TABLE i_afvv INTO wa_afvv WITH KEY aufpl = wa_afvc-aufpl
*                               aplzl = wa_afvc-aplzl BINARY SEARCH.
*  READ TABLE i_orders INTO wa_orders WITH KEY aufpl = wa_afvc-aufpl.
*  " BINRAY SEARCH.
*  IF sy-subrc = 0.
******************
*
*READ TABLE i_ordops INTO wa_ordops WITH KEY aufnr = wa_orders-aufnr.
******************
*    IF sy-subrc <> 0.
*      MOVE-CORRESPONDING wa_orders TO wa_pro_orders.
*      wa_pro_orders-wdate = wa_afvv-ssavd.
*      wa_pro_orders-zaehl = wa_afvc-zaehl.
*      wa_pro_orders-arbpl = wa_crhd-arbpl.
*      wa_pro_orders-arbid = wa_afvc-arbid.
*      wa_pro_orders-plnnr = wa_afvc-plnnr.
*      wa_pro_orders-plnkn = wa_afvc-plnkn.
********MOD-002*****************************
**     wa_pro_orders-rueck = wa_afvc-rueck.
*******MOD-002*******************************
*      IF wa_pro_orders-rueck IS INITIAL.
*        wa_pro_orders-rueck = wa_afvc-rueck.
*      ENDIF.
*
*      wa_material_no-matnr = wa_orders-plnbez.
*
*      APPEND: wa_pro_orders TO i_pro_orders,
*              wa_material_no TO i_material_no.
*      CLEAR:  wa_pro_orders, wa_material_no.
*    ENDIF.
*
*    wa_ordops-aufnr = wa_orders-aufnr.
*    wa_ordops-aufpl = wa_afvc-aufpl.
*    wa_ordops-aplzl = wa_afvc-aplzl.
*    wa_ordops-plnty = wa_afvc-plnty.
*    wa_ordops-plnkn = wa_afvc-plnkn.
*    wa_ordops-plnnr = wa_afvc-plnnr.
*    wa_ordops-zaehl = wa_afvc-zaehl.
*    wa_ordops-vornr = wa_afvc-vornr.
*    wa_ordops-arbid = wa_afvc-arbid.
*    wa_ordops-rueck = wa_afvc-rueck.
*    wa_ordops-ssavd = wa_afvv-ssavd.
*    wa_ordops-arbpl = wa_crhd-arbpl.
*
*    APPEND wa_ordops TO i_ordops.
*    CLEAR  wa_ordops.
*  ENDIF.
*  CLEAR: wa_afvv, wa_orders.
*
*ENDFORM.                    " move_data2_ordops
**&---------------------------------------------------------------------
**
**&      Form  DISPLAY_DETAIL_REPORT
**&---------------------------------------------------------------------
**
**       text
**----------------------------------------------------------------------
**
**----------------------------------------------------------------------
**
*FORM display_detail_report.
*
*  DATA: l_date_low(10)  TYPE c,
*        l_date_high(10) TYPE c,
*        l_diff          TYPE menge_d,
*        l_plan_effic    TYPE char05,                        "MOD-001++
*        l_plant_effic   TYPE char05,                        "MOD-001++
*        l_gamng         TYPE menge_d,
*        l_gamng1(20)    TYPE c,
*        l_qty    TYPE menge_d,
*        l_prdqty TYPE menge_d,
*        l_conv   TYPE menge_d,
*        l_aqty   TYPE menge_d,
*        l_sqty   TYPE menge_d,
*        l_gmein  TYPE meins,
*
*        l_pcent(3)  TYPE p DECIMALS 2,
*        l_cost(8)   TYPE p DECIMALS 2,
*
*        l_act_total(8) TYPE p DECIMALS 2,
*        l_std_total(8) TYPE p DECIMALS 2,
*        l_var_total(8) TYPE p DECIMALS 2,
*
*        l_act_gtot(8)  TYPE p DECIMALS 2,
*        l_std_gtot(8)  TYPE p DECIMALS 2,
*        l_var_gtot(8)  TYPE p DECIMALS 2,
*
*        l_fromuom TYPE meins.
**- Begin of MOD-001
*  DATA: l_value TYPE char16,
*        l_tmp TYPE lmnga,
*        l_tmp1 TYPE lmnga,
*        l_effic TYPE p DECIMALS 1,
*        l_uom   TYPE char03.
**- End of MOD-001
*
*  PERFORM pfstatus.
*  SET PF-STATUS 'MAIN' EXCLUDING i_fcode.
*  SET TITLEBAR 'VARI' WITH text-066.
*  MOVE 'Display Detail Report'(028) TO v_output_text.
*  PERFORM inform_user_of_progress.
*
** Clearing local variables
*  CLEAR: l_cost, l_pcent, l_qty, l_conv, l_aqty, l_sqty,
*         l_diff, l_plan_effic, l_gamng, l_date_low,l_date_high,
*         l_act_gtot, l_std_gtot, l_var_gtot.
*  CLEAR wa_nodestab.
*  REFRESH i_nodestab.
*
****Begin of MOD-001
*  IF sy-ucomm = c_zero OR rb_zloss IS NOT INITIAL.
*
*    v_ucomm = c_zero.
*
*  ELSEIF sy-ucomm = c_std OR rb_stdpl IS NOT INITIAL.
*
*    CLEAR : v_ucomm.
*
*  ENDIF.
*
*  IF sy-ucomm = c_fisc.
*
*    v_ucomm1 = c_fisc.
*
*  ELSEIF sy-ucomm = c_qty.
*
*    v_ucomm1 = c_qty.
*
*  ENDIF.
****End of MOD-001
*
*  wa_nodestab-id = c_1_1.
*  wa_nodestab-tlevel = c_1.
*  wa_nodestab-text = 'Production Variances'(031).
*  wa_nodestab-tlength = c_20.
*  wa_nodestab-compress = c_x.
*  APPEND wa_nodestab TO i_nodestab.
*
*  LOOP AT i_pro_orders INTO wa_pro_orders.
*
*    CLEAR: wa_nodestab, l_date_low, l_date_high, l_gamng,
*           wa_material_des.
*
*    l_gamng = wa_pro_orders-gamng.
*************MOD-002************************
*    l_gmein = wa_pro_orders-gmein.
*************MOD-002***********************
*    wa_nodestab-id = c_2_1.
*    wa_nodestab-tlevel = c_2.
*    wa_nodestab-parent = c_1_1.
*
** Order Number text
*    wa_nodestab-text = 'Order Num:'(032).
*    wa_nodestab-tlength = c_12.
*    wa_nodestab-tcolor = c_1.
** Order number
*    WRITE wa_pro_orders-aufnr TO wa_nodestab-text1 NO-ZERO.
*    wa_nodestab-tlength1 = c_12.
*    wa_nodestab-tcolor1 = c_1.
*
** Date Range
*    WRITE wa_pro_orders-wdate TO l_date_low.
*    WRITE wa_pro_orders-gltrp TO l_date_high.
*    CONCATENATE l_date_low c_hyp l_date_high
*    INTO wa_nodestab-text2 SEPARATED BY space.
*    wa_nodestab-tlength2 = c_25.
*    wa_nodestab-tcolor2 = c_1.
*
** Material Number
*    WRITE wa_pro_orders-plnbez TO wa_nodestab-text3 NO-ZERO.
*    wa_nodestab-tlength3 = c_18.
*    wa_nodestab-tcolor3 = c_1.
*
** Material Description
*    READ TABLE i_material_des INTO wa_material_des
*                WITH KEY matnr = wa_pro_orders-plnbez.
*    wa_nodestab-text4 = wa_material_des-maktx.
*    wa_nodestab-tlength4 = c_33.
*    wa_nodestab-tcolor4 = c_1.
*
** Get actual produced Quantity or Confirm Quantity
*    IF NOT ( rb_prod IS INITIAL ).
*      l_prdqty  = wa_pro_orders-menge.
*      l_fromuom = wa_pro_orders-gruom.
*    ELSE.
**********MOD-002***************************************
*      LOOP AT i_plpo1 INTO wa_plpo1
*                WHERE plnty = wa_pro_orders-plnty
*                AND plnnr = wa_pro_orders-plnnr
*                AND steus = 'YBN1'.
*        IF wa_plpo1-vgw02 IS NOT INITIAL.
************MOD-005****************************
**          wa_plpo2 = wa_plpo1.
**          append wa_plpo2 to i_plpo2.
**        ENDIF.
**      ENDLOOP.
************mod-005***************************
*          CLEAR: wa_afvc, wa_afvv.
*          READ TABLE i_afvc INTO wa_afvc
*               WITH KEY plnty = wa_plpo1-plnty
*                        plnnr = wa_plpo1-plnnr
*                        plnkn = wa_plpo1-plnkn
*                        zaehl = wa_plpo1-zaehl
*                        aufpl = wa_pro_orders-aufpl.
*
*
*          IF sy-subrc IS INITIAL.
*            READ TABLE i_afvv INTO wa_afvv
*                 WITH KEY aufpl = wa_afvc-aufpl
*                          aplzl = wa_afvc-aplzl.
*
**      READ table i_afvc into wa_afvc with key
**            aufpl = wa_pro_orders-aufpl binary search.
**      if sy-subrc = 0.
**        READ TABLE I_AFVV into wa_afvv with key
**             aufpl = wa_afvc-aufpl
**             aplzl = wa_afvc-aplzl binary search.
*            IF sy-subrc = 0.
*              l_prdqty  = wa_afvv-lmnga.
********************MOD-006**********************
*              IF wa_pro_orders-cfuom IS INITIAL.
*                SELECT aufnr rueck gmnga lmnga gmein meinh
*                        meilr stokz rueck_mst
*                FROM afru INTO TABLE i_afru
*                WHERE rueck = wa_afvc-rueck AND
*                      aufnr = wa_pro_orders-aufnr.
*                IF NOT i_afru[] IS INITIAL.
*                  READ TABLE i_afru INTO wa_afru INDEX 1.
*                  IF sy-subrc = 0.
*                    l_fromuom = wa_afru-gmein.
*                  ENDIF.
*                ENDIF.
*              ELSE.
*                l_fromuom = wa_pro_orders-cfuom.
*              ENDIF.
*******************MOD-006***********************
*            ENDIF.
*          ENDIF.
**********MOD-002***************************************
**      l_prdqty  = wa_pro_orders-lmnga.
**      l_fromuom = wa_pro_orders-cfuom.
*        ENDIF.
*      ENDLOOP.
*    ENDIF.
*
************mod-003**********************
*    IF NOT rb_pland IS INITIAL.
*      IF rb_conf IS INITIAL.
*        l_prdqty  = wa_pro_orders-gamng.
*      ELSE.
*        l_prdqty = wa_afvv-lmnga.
*      ENDIF.
*    ENDIF.
***********mod-003***********************
*    IF rb_kgm = c_x.
** do actual conversion
*      PERFORM uom_convert USING wa_pro_orders-plnbez
*                                l_prdqty
*                                l_fromuom
*                                l_conv.
*      l_prdqty = l_conv.
** do planned conversion
*********MOD-002*************************
**     l_fromuom = wa_pro_orders-gmein.
*      l_fromuom = 'KG'.
*
*      PERFORM uom_convert USING wa_pro_orders-plnbez
*                                wa_pro_orders-gamng
*                                l_fromuom
*                                l_conv.
*
*      l_gamng = l_conv.
*    ENDIF.
*
** Produced Quantity / Confirmed Quantity
*    MOVE l_prdqty TO wa_nodestab-text5(20).
*    MOVE l_fromuom TO l_uom.                                "MOD-001++
**    WRITE l_prdqty TO i_nodestab-text5(20).
*
*    IF NOT ( rb_prod IS INITIAL ).
**      CONCATENATE 'Prod Qty: '(033) wa_nodestab-text5 "MOD-001-
*      CONCATENATE 'Prod Qty: '(033) wa_nodestab-text5 l_uom "MOD-001+
*        INTO wa_nodestab-text5 SEPARATED BY space.
*
*    ELSE.
**      CONCATENATE 'Conf Qty: '(034) wa_nodestab-text5 "MOD-001-
*      CONCATENATE 'Conf Qty: '(034) wa_nodestab-text5 l_uom "MOD-001+
*       INTO wa_nodestab-text5 SEPARATED BY space.
*    ENDIF.
*
*
**    wa_nodestab-tlength5 = c_30.  "MOD-001-
*    wa_nodestab-tlength5 = c_35_1.                          "MOD-001+
*    wa_nodestab-tcolor5  = c_1.
*
*    APPEND wa_nodestab TO i_nodestab.
*
** Resource Information
*    CLEAR  wa_nodestab.
*    wa_nodestab-id     = c_2_2.
*    wa_nodestab-tlevel = c_3.
*    wa_nodestab-parent = c_1_1.
*
*    CONCATENATE 'Resource:'(035) wa_pro_orders-arbpl
*    INTO wa_nodestab-text SEPARATED BY space.
*    wa_nodestab-tlength = c_25.
*    wa_nodestab-tcolor  = c_4.
*
*    READ TABLE i_wc_text INTO wa_wc_text
*             WITH KEY objid = wa_pro_orders-arbid.
*    wa_nodestab-text1 = wa_wc_text-ktext.
*    wa_nodestab-tlength1 = c_37.
*    wa_nodestab-tcolor1  = c_4.
*
** Calculating Plan Effic value
**- Begin of MOD-001
**    IF l_gamng GT 0.
**      l_diff = l_gamng - l_prdqty.
**      l_plan_effic = c_100 - c_100 * ( l_diff / l_gamng ).
**    ELSE.
**      CLEAR l_plan_effic.
**    ENDIF.
*
**** Mod-002*********************
*    CLEAR: wa_plpo1.
*****mOD-002*********************
*    LOOP AT i_plpo1 INTO wa_plpo1
*            WHERE plnty = wa_pro_orders-plnty
*              AND plnnr = wa_pro_orders-plnnr
*              AND steus = 'YBN1'.
*      IF wa_plpo1-vgw02 IS NOT INITIAL.
*        MOVE wa_plpo1-usr04 TO l_effic. "L_VALUE.
*        WRITE l_effic TO l_plan_effic.
*        wa_plpo2 = wa_plpo1.
*        APPEND wa_plpo2 TO i_plpo2.
*
**       L_PLAN_EFFIC = floor( L_VALUE )
**************MOD-002**************************
**      ELSE.
**        CLEAR l_plan_effic.
*      ENDIF.
*************MOD-002***************************
*    ENDLOOP.
*
*
**    CONCATENATE 'Plan Effic:'(036) l_plan_effic c_perc "'%'
*    CONCATENATE 'Exp. Line Eff.'(036) l_plan_effic c_perc "'%'
*    INTO wa_nodestab-text2 SEPARATED BY space.
*    wa_nodestab-tlength2 = c_25.
*    wa_nodestab-tcolor2  = c_4.
*
*    CLEAR l_effic.
*** Mod-002***************
*
*
**    READ TABLE i_afvc INTO wa_afvc
**         WITH KEY plnty = wa_plpo1-plnty
**                  plnnr = wa_plpo1-plnnr
**                  zaehl = wa_plpo1-zaehl.
*
***************MOD-008***********************
**    LOOP AT I_ORDOPS INTO WA_ORDOPS.
**      READ TABLE I_PRO_ORDERS INTO WA_PRO_ORDERS WITH KEY
**                                    AUFNR = WA_ORDOPS-AUFNR
**                                              BINARY SEARCH.
**      IF SY-SUBRC = 0.
**        READ table i_afvc1 into wa_afvc1 with key
**                      plnty = wa_ORDOPS-plnty
**                      plnnr = wa_ORDOPS-plnnr
**                      plnkn = wa_ORDOPS-plnkn
**                      zaehl = wa_ORDOPS-zaehl
**                      aufpl = wa_pro_orders-aufpl.
**        IF SY-SUBRC = 0.
**          READ TABLE I_AFVV1 into wa_afvv1 with key
**                 aufpl = wa_afvc1-aufpl
**                 aplzl = wa_afvc1-aplzl binary search.
**          IF SY-SUBRC = 0.
**            CHECK WA_AFVV1-VGW02 NE 0.
**            l_tmp = wa_afvv1-bmsch * wa_afvv1-ism02.
**            IF l_tmp IS NOT INITIAL.
**
**              l_tmp1 = ( wa_afvv1-lmnga * wa_afvv1-vgw02 ) / l_tmp.
**
**              l_tmp1 = l_tmp1 * 100.
**
**              MOVE l_tmp1 TO l_effic.
**
**            ENDIF.
**          ENDIF.
**        ENDIF.
**      ENDIF.
**    ENDLOOP.
*
**************MOD-008************************
*    CLEAR: wa_afvc, wa_afvv.
*    LOOP AT i_plpo2 INTO wa_plpo2.
*      READ TABLE i_afvc INTO wa_afvc
*           WITH KEY plnty = wa_plpo2-plnty
*                    plnnr = wa_plpo2-plnnr
*                    plnkn = wa_plpo2-plnkn
*                    zaehl = wa_plpo2-zaehl
*                    aufpl = wa_pro_orders-aufpl.
*
*      IF sy-subrc IS INITIAL.
*        READ TABLE i_afvv INTO wa_afvv
*             WITH KEY aufpl = wa_afvc-aufpl
*                      aplzl = wa_afvc-aplzl.
*
*        l_tmp = wa_afvv-bmsch * wa_afvv-ism02.
*        IF l_tmp IS NOT INITIAL.
*
*          l_tmp1 = ( wa_afvv-lmnga * wa_afvv-vgw02 ) / l_tmp.
*
*          l_tmp1 = l_tmp1 * 100.
*
*          MOVE l_tmp1 TO l_effic.
*
*        ENDIF.
*      ENDIF.
*    ENDLOOP.
*
*    WRITE l_effic TO l_plant_effic.
*
**    CLEAR v_plant_effic.
**    PERFORM plant_effic USING wa_pro_orders-plnty
**                            wa_pro_orders-plnnr
**                            wa_pro_orders-plnkn
**                            wa_pro_orders-zaehl
**                      CHANGING v_plant_effic.
*
**    CONCATENATE 'Plant Effic:'(037) v_plant_effic c_perc "'%'
*    CONCATENATE 'Act. Line Eff.'(037) l_plant_effic c_perc "'%'
*                                                            " MOD-001+
*    INTO wa_nodestab-text3 SEPARATED BY space.
*    wa_nodestab-tlength3 = c_25.
*    wa_nodestab-tcolor3  = c_4.
**- End of MOD-001
*
*    APPEND wa_nodestab TO i_nodestab.
*
** Phase Information
*    CLEAR  wa_nodestab.
*    wa_nodestab-id     = c_3_3.
*    wa_nodestab-tlevel =  c_3.
*    wa_nodestab-parent = c_1_1.
*
*    wa_nodestab-text = 'Phase'(038).
*    wa_nodestab-tlength = c_10.
*    wa_nodestab-tcolor  = c_4.
*
*    MOVE l_gamng TO l_gamng1.
*    CONCATENATE 'Activity (Std Plan:'(039) l_gamng1 c_brac " ')'
*    INTO wa_nodestab-text1 SEPARATED BY space.
*    wa_nodestab-tlength1 = c_42.
*    wa_nodestab-tcolor1  = c_4.
*
*    IF rb_fiscl = c_x.
*      CONCATENATE 'Actual Usage'(040) v_waers
*      INTO wa_nodestab-text2 SEPARATED BY space.
*    ELSE.
*      wa_nodestab-text2 = 'Actual Usage'(040).
*    ENDIF.
*    wa_nodestab-tlength2 = c_20.
*    wa_nodestab-tcolor2  = c_4.
*
*    IF rb_fiscl = c_x.
*      CONCATENATE 'Standard Usage'(041) v_waers
*      INTO wa_nodestab-text3 SEPARATED BY space.
*    ELSE.
*      wa_nodestab-text3 = 'Standard Usage'(041).
*    ENDIF.
*    wa_nodestab-tlength3 = c_20.
*    wa_nodestab-tcolor3  = c_4.
*
*    IF rb_fiscl = c_x.
*      CONCATENATE 'Activity Variance'(042) v_waers
*      INTO wa_nodestab-text4 SEPARATED BY space.
*    ELSE.
*      wa_nodestab-text4 = 'Activity Variance'(042).
*    ENDIF.
*    wa_nodestab-tlength4 = c_35.
*    wa_nodestab-tcolor4  = c_4.
*
*    APPEND wa_nodestab TO i_nodestab.
*
** Display acitivity report
*    CLEAR flg_color.
*    LOOP AT i_ordops INTO wa_ordops
*             WHERE aufnr = wa_pro_orders-aufnr.
*      IF flg_color IS INITIAL.
*        flg_color = c_x.
*      ELSE.
*        CLEAR flg_color.
*      ENDIF.
*      PERFORM activity_report USING l_prdqty l_gamng l_uom l_gmein.
*    ENDLOOP.
*
** Material Information
*    CLEAR  wa_nodestab.
*    wa_nodestab-id     = c_3_4.
*    wa_nodestab-tlevel =  c_3.
*    wa_nodestab-parent = c_1_1.
*
*    PERFORM material_header.
*
*    CLEAR: l_act_total, l_std_total, l_var_total.
** Individual material details
*    LOOP AT i_ordmats INTO wa_ordmats
*              WHERE aufnr = wa_pro_orders-aufnr.
*
*****************mod-003************************
*      CLEAR: l_aqty, l_sqty, l_qty.
****************mod-003*************************
*
*      CLEAR: wa_nodestab.
*      wa_nodestab-id     = c_4_1.
*      wa_nodestab-tlevel =  c_4.
*      wa_nodestab-parent = c_3_2.
*
** Material Number
*      WRITE wa_ordmats-matnr TO wa_nodestab-text NO-ZERO.
*      wa_nodestab-tlength = c_18.
*      wa_nodestab-tcolor  = c_3.
*
** Material Description
*      CLEAR wa_material_des.
*      READ TABLE i_material_des INTO wa_material_des
*           WITH KEY matnr = wa_ordmats-matnr.
*      wa_nodestab-text1 = wa_material_des-maktx.
*      wa_nodestab-tlength1 = c_30.
*      wa_nodestab-tcolor1  = c_3.
*
** Standard planned or zero loss planned
*
*      IF rb_zloss IS INITIAL.
*        l_qty = wa_ordmats-stdqy.
***************MOD-004***********************
*
*************MOD-004************************
*      ELSE.
*        l_qty = wa_ordmats-zloss.
*      ENDIF.
*
** Order uom or kgm
*      IF rb_kgm IS INITIAL.
*        l_aqty = wa_ordmats-menge.
*        l_sqty = l_qty.
*      ELSE.
** do actual conversion
*        PERFORM uom_convert USING wa_ordmats-matnr
*                                  wa_ordmats-menge
*                                  wa_ordmats-amein
*                                  l_aqty.
** do std/zloss conversion
*        PERFORM uom_convert USING wa_ordmats-matnr
*                                  wa_ordmats-stdqy
*                                  wa_ordmats-meins
*                                  l_sqty.
*      ENDIF.
*******************MOD-003**********************************
*      IF wa_ordmats-meins = 'EA' OR
*        wa_ordmats-meins = 'CS'.
*        l_sqty = CEIL( l_sqty ).
*      ENDIF.
*******************MOD-003**********************************
*
*      PERFORM std_percentage_calc USING l_aqty l_sqty l_pcent.
*
** Fiscal or quantity
*      IF rb_fiscl IS INITIAL.
*        MOVE l_aqty TO wa_nodestab-text2(20). " Actual Usage
*        wa_nodestab-tlength2 = c_20.
*        wa_nodestab-tcolor2  = c_3.
*        MOVE l_sqty TO wa_nodestab-text3(20). " Standard Usage
*        wa_nodestab-tlength3 = c_20.
*        wa_nodestab-tcolor3  = c_3.
*
*      ELSE.
*        IF NOT wa_ordmats-peinh IS INITIAL.
*          CLEAR l_cost.
*          l_cost = ( wa_ordmats-stprs * wa_ordmats-menge )
*                                     / wa_ordmats-peinh.
*          MOVE l_cost TO wa_nodestab-text2(20). " Acutal Usage
*          wa_nodestab-tlength2 = c_20.
*          wa_nodestab-tcolor2  = c_3.
*
*          l_act_total = l_act_total + l_cost. " Subtotal of actual
*          l_act_gtot  = l_act_gtot  + l_cost. " Grand total
*
*        ENDIF.
*        IF NOT wa_ordmats-peinh IS INITIAL.
*          CLEAR l_cost.
****Begin of MOD-001
*          IF v_ucomm = c_zero.
***************************MOD-003*******************************
*            IF wa_ordmats-meins = 'EA' OR
*               wa_ordmats-meins = 'CS'.
*              l_qty = CEIL( l_qty ).
*            ENDIF.
***************************MOD-003*******************************
*            l_cost = ( wa_ordmats-stprs * l_qty ) "wa_ordmats-stdqy )
*                                      / wa_ordmats-peinh.
*
*
*          ELSE.
***************************MOD-003*******************************
*            IF wa_ordmats-meins = 'EA' OR
*               wa_ordmats-meins = 'CS'.
*              wa_ordmats-stdqy = CEIL( wa_ordmats-stdqy ).
*            ENDIF.
***************************MOD-003*******************************
*
*            l_cost = ( wa_ordmats-stprs * wa_ordmats-stdqy )
*                                      / wa_ordmats-peinh.
*
*
*          ENDIF.
****End of MOD-001
*
*          MOVE l_cost TO wa_nodestab-text3(20). " Standard Usage
*          wa_nodestab-tlength3 = c_20.
*          wa_nodestab-tcolor3 = c_3.
*
*          l_std_total = l_std_total + l_cost. " Subtotal of standard
*          l_std_gtot  = l_std_gtot  + l_cost. " Grand Total
*
*        ENDIF.
*      ENDIF.
*
*      MOVE l_pcent TO wa_nodestab-text4(17). " Variance Percentage
*      CONCATENATE wa_nodestab-text4(17) c_perc "'%'
*      INTO wa_nodestab-text4(19) SEPARATED BY space.
*      wa_nodestab-tlength4 = c_19.
*      wa_nodestab-tcolor4  = c_3.
*      CLEAR: l_diff, l_cost.
*
******Begin of MOD-001
*      IF ( v_ucomm = c_zero ).
*
*        l_diff = wa_ordmats-menge - l_qty.
*
*      ELSE.
*
*        l_diff = wa_ordmats-menge - wa_ordmats-stdqy.
*
*      ENDIF.
******End of MOD-001
*
*      IF NOT wa_ordmats-peinh IS INITIAL.
*        l_cost = ( wa_ordmats-stprs * l_diff ) / wa_ordmats-peinh.
*        l_cost = l_cost * -1.
*      ENDIF.
*
******Begin of MOD-001
**      IF v_ucomm1 = c_qty.
**
**        MOVE l_diff TO wa_nodestab-text5(15). " Variance
**
**      ELSE.
*
*      MOVE l_cost TO wa_nodestab-text5(15). " Variance
*
**      ENDIF.
*******End of MOD-001
*
*      wa_nodestab-tlength5 = c_15.
*      wa_nodestab-tcolor5  = c_3.
*
*      l_var_total = l_var_total + l_cost. " Subtotal of Variance
*      l_var_gtot  = l_var_gtot  + l_cost. " Grand total
*
*      APPEND wa_nodestab TO i_nodestab.
****************MOD-003*********************
*      CLEAR: wa_ordmats.
***************mod-003**********************
*
*    ENDLOOP.
*
** Displaying Subtotals
*
*    CLEAR  wa_nodestab.
*    wa_nodestab-id     = c_4_1.
*    wa_nodestab-tlevel =  c_4.
*    wa_nodestab-parent = c_3_2.
*
*    wa_nodestab-text    = 'Material Totals'(043).
*    wa_nodestab-tlength =  c_18.
*    wa_nodestab-tcolor  =  c_6.
*
*    wa_nodestab-text1 = space.
*    wa_nodestab-tlength1 = c_30.
*    wa_nodestab-tcolor1  = c_6.
*
*    MOVE l_act_total TO wa_nodestab-text2(20) .
*    wa_nodestab-tlength2 = c_20.
*    wa_nodestab-tcolor2  = c_6.
*
*    MOVE l_std_total TO wa_nodestab-text3(20) .
*    wa_nodestab-tlength3 = c_20.
*    wa_nodestab-tcolor3  = c_6.
*
*    wa_nodestab-text4 = space.
*    wa_nodestab-tlength4 = c_19.
*    wa_nodestab-tcolor4  = c_6.
*
*    MOVE l_var_total TO wa_nodestab-text5(15) .
*    wa_nodestab-tlength5 = c_15.
*    wa_nodestab-tcolor5  = c_6.
*
*    APPEND wa_nodestab TO i_nodestab.
*    CLEAR : wa_pro_orders, wa_nodestab.
*
*  ENDLOOP.
*
** Displaying Grand total
*  CLEAR wa_nodestab.
*  wa_nodestab-id     = c_2_1.
*  wa_nodestab-tlevel =  c_2.
*  wa_nodestab-parent = c_1_1.
*
*  wa_nodestab-text = 'Process Order Totals'(044).
*  wa_nodestab-tlength = c_26.
*  wa_nodestab-tcolor  = c_5.
*
*  wa_nodestab-text1    = space.
*  wa_nodestab-tlength1 = c_30.
*  wa_nodestab-tcolor1  = c_5.
*
*  MOVE l_act_gtot TO wa_nodestab-text2(20) .
*  wa_nodestab-tlength2 = c_20.
*  wa_nodestab-tcolor2  = c_5.
*
*  MOVE l_std_gtot TO wa_nodestab-text3(20) .
*  wa_nodestab-tlength3 = c_20.
*  wa_nodestab-tcolor3  = c_5.
*
*  wa_nodestab-text4 = space.
*  wa_nodestab-tlength4 = c_19.
*  wa_nodestab-tcolor4  = c_5.
*
*  MOVE l_var_gtot TO wa_nodestab-text5(15) .
*  wa_nodestab-tlength5 = c_15.
*  wa_nodestab-tcolor5  = c_5 .
*
*  APPEND wa_nodestab TO i_nodestab.
*
*  CLEAR : wa_nodestab.
*
*ENDFORM.                    " DISPLAY_DETAIL_REPORT
**&---------------------------------------------------------------------
**
**&      Form  DISPLAY_SUMMARY_REPORT
**&---------------------------------------------------------------------
**
**       text
**----------------------------------------------------------------------
**
**----------------------------------------------------------------------
**
*FORM display_summary_report.
*  DATA: l_diff          TYPE menge_d,
*        l_gamng         TYPE menge_d,
*        l_gmein         TYPE meins,
*
*        l_ltext         TYPE ktext,
*
*        l_tot_orders    TYPE i,
*
*        l_effic              TYPE p DECIMALS 1,             " MOD-001++
*        l_effic1             TYPE p DECIMALS 1,             " MOD-001++
*        l_plan_effic         TYPE char05,                   " MOD-001++
*        l_plant_effic        TYPE char05,                   " MOD-001++
*        l_sum_plan_effic TYPE p DECIMALS 1,
*        l_sum_plant_effic TYPE p DECIMALS 1,
*
*        l_qty    TYPE menge_d,
*        l_conv   TYPE menge_d,
*        l_aqty   TYPE menge_d,
*        l_sqty   TYPE menge_d,
*
*        l_prdqty     TYPE menge_d,
*        l_sum_prdqty TYPE menge_d,
*
*        l_pcent(3)  TYPE p DECIMALS 2,
*        l_cost(8)   TYPE p DECIMALS 2,
*
*        l_act_total(8) TYPE p DECIMALS 2,
*        l_std_total(8) TYPE p DECIMALS 2,
*        l_var_total(8) TYPE p DECIMALS 2,
*
*        l_fromuom TYPE meins.
*
**- Begin of MOD-001
*  DATA: l_value TYPE char16,
*        l_tmp TYPE lmnga,
*        l_tmp1 TYPE lmnga.
**- End of MOD-001
*
*  PERFORM pfstatus.
*  SET PF-STATUS 'MAIN' EXCLUDING i_fcode.
*  SET TITLEBAR 'VARI' WITH text-067.
*
*  CLEAR wa_nodestab.
*  REFRESH i_nodestab.
*
*  MOVE 'Display summary Report'(029) TO v_output_text.
*  PERFORM inform_user_of_progress.
*
*  CLEAR wa_nodestab.
*  wa_nodestab-id     = c_1.
*  wa_nodestab-tlevel = c_1.
*  wa_nodestab-text = 'Production Variances (Summary Report)'(045).
*  wa_nodestab-tlength = c_40.
*  wa_nodestab-compress = c_x.
*  APPEND wa_nodestab TO  i_nodestab.
*
*  CLEAR wa_nodestab.
*  wa_nodestab-id     =  c_2_1.
*  wa_nodestab-tlevel =  c_2.
*  wa_nodestab-parent =  c_1_1.
*
*  wa_nodestab-text = 'Summary of Orders for'(046).
*  wa_nodestab-tlength = c_22.
*  wa_nodestab-tcolor  = c_1.
*
*  CONCATENATE 'Plant:'(047) p_werks
*  INTO wa_nodestab-text1 SEPARATED BY space.
*  wa_nodestab-tlength1 = c_15.
*  wa_nodestab-tcolor1  = c_1.
*
*  CONCATENATE 'Phase Key:'(048) s_steus-low s_steus-high
*  INTO wa_nodestab-text2 SEPARATED BY space.
*  wa_nodestab-tlength2 = c_25.
*  wa_nodestab-tcolor2  = c_1.
*
*  IF s_arbpl[] IS INITIAL.
*    wa_nodestab-text3 = 'Resources: All'(049).
*  ELSE.
*    CONCATENATE 'Resources:'(065) s_arbpl-low c_hyp s_arbpl-high
*    INTO wa_nodestab-text3 SEPARATED BY space.
*  ENDIF.
*  wa_nodestab-tlength3 = c_20.
*  wa_nodestab-tcolor3  = c_1.
*
*  APPEND wa_nodestab TO i_nodestab.
*
*****Begin of MOD-001
*  CLEAR: l_sum_plan_effic, i_sum_ordmats, i_sum_activity.
*****End of MOD-001
*
*  LOOP AT i_pro_orders INTO wa_pro_orders.
*
*    l_gamng = wa_pro_orders-gamng.
*    l_gmein = wa_pro_orders-gmein.
*
** Get actual produced Quantity or Confirm Quantity
*    IF NOT ( rb_prod IS INITIAL ).
*      l_prdqty  = wa_pro_orders-menge.
*      l_fromuom = wa_pro_orders-gruom.
*    ELSE.
*      l_prdqty  = wa_pro_orders-lmnga.
*
*************************MOD-006**********************
**     l_fromuom = wa_pro_orders-cfuom.
*      IF wa_pro_orders-cfuom IS INITIAL.
*        SELECT aufnr rueck gmnga lmnga gmein meinh
*                meilr stokz rueck_mst
*        FROM afru INTO TABLE i_afru
*        WHERE aufnr = wa_pro_orders-aufnr.
*        IF NOT i_afru[] IS INITIAL.
*          READ TABLE i_afru INTO wa_afru INDEX 1.
*          IF sy-subrc = 0.
*            l_fromuom = wa_afru-gmein.
*          ENDIF.
*        ENDIF.
*      ELSE.
*        l_fromuom = wa_pro_orders-cfuom.
*      ENDIF.
*************************MOD-006*********************
*    ENDIF.
*    IF rb_kgm = c_x.
** do actual conversion
*      PERFORM uom_convert USING wa_pro_orders-plnbez
*                                l_prdqty
*                                l_fromuom
*                                l_conv.
*      l_prdqty = l_conv.
** do planned conversion
********MOD-002********************************
**      l_fromuom = wa_pro_orders-gmein.
*      l_fromuom = 'KG'.
********Mod-002********************************
*      PERFORM uom_convert USING wa_pro_orders-plnbez
*                                wa_pro_orders-gamng
*                                l_fromuom
*                                l_conv.
*      l_gamng = l_conv.
*    ENDIF.
** Calculating Plan Effic value
*    CLEAR l_plan_effic.
**- Begin of MOD-001
**    IF l_gamng GT 0.
**      l_diff = l_gamng - l_prdqty.
**      l_plan_effic = 100 - 100 * ( l_diff / l_gamng ).
**    ELSE.
**      CLEAR l_plan_effic.
**    ENDIF.
*
*    LOOP AT i_plpo1 INTO wa_plpo1
*            WHERE plnty = wa_pro_orders-plnty
*              AND plnnr = wa_pro_orders-plnnr
*              AND steus = 'YBN1'.
*      IF wa_plpo1-vgw02 IS NOT INITIAL.
*        MOVE wa_plpo1-usr04 TO l_effic. "L_VALUE.
*        wa_plpo2 = wa_plpo1.
*        APPEND wa_plpo2 TO i_plpo2.
*****************mod-002************************
**    CONDENSE L_VALUE.
**    write l_effic to l_plan_effic.
**    L_PLAN_EFFIC = floor( L_VALUE ).
*****************mod-002************************
*      ELSE.
*        CLEAR l_plan_effic.
*      ENDIF.
*
*    ENDLOOP.
*
*********************MOD-008**************************************
**    LOOP AT I_ORDOPS INTO WA_ORDOPS.
**      READ TABLE I_PRO_ORDERS INTO WA_PRO_ORDERS WITH KEY
**                                    AUFNR = WA_ORDOPS-AUFNR
**                                              BINARY SEARCH.
**      IF SY-SUBRC = 0.
**        READ table i_afvc1 into wa_afvc1 with key
**                      plnty = wa_ORDOPS-plnty
**                      plnnr = wa_ORDOPS-plnnr
**                      plnkn = wa_ORDOPS-plnkn
**                      zaehl = wa_ORDOPS-zaehl
**                      aufpl = wa_pro_orders-aufpl.
**        IF SY-SUBRC = 0.
**          READ TABLE I_AFVV1 into wa_afvv1 with key
**                 aufpl = wa_afvc1-aufpl
**                 aplzl = wa_afvc1-aplzl binary search.
**          IF SY-SUBRC = 0.
**            CHECK WA_AFVV1-VGW02 NE 0.
**            l_tmp = wa_afvv1-bmsch * wa_afvv1-ism02.
**            IF l_tmp IS NOT INITIAL.
**
**              l_tmp1 = ( wa_afvv1-lmnga * wa_afvv1-vgw02 ) / l_tmp.
**
**              l_tmp1 = l_tmp1 * 100.
**
**              MOVE l_tmp1 TO l_effic.
**
**            ENDIF.
**          ENDIF.
**        ENDIF.
**      ENDIF.
**    ENDLOOP.
*******************MOD-008********************************************
*
******Mod-002*******************************
**    READ TABLE i_afvc INTO wa_afvc
**         WITH KEY plnty = wa_plpo1-plnty
**                  plnnr = wa_plpo1-plnnr
**                  zaehl = wa_plpo1-zaehl.
*
*    LOOP AT i_plpo2 INTO wa_plpo2..
*      CLEAR: wa_afvc, wa_afvv.
*      READ TABLE i_afvc INTO wa_afvc
*           WITH KEY plnty = wa_plpo2-plnty
*                    plnnr = wa_plpo2-plnnr
*                    plnkn = wa_plpo2-plnkn
*                    zaehl = wa_plpo2-zaehl
*                    aufpl = wa_pro_orders-aufpl.
*
**Mod-002*************************************
*
*      IF sy-subrc IS INITIAL.
*        READ TABLE i_afvv INTO wa_afvv
*             WITH KEY aufpl = wa_afvc-aufpl
*                      aplzl = wa_afvc-aplzl.
*
*        l_tmp = wa_afvv-bmsch * wa_afvv-ism02.
*        IF l_tmp IS NOT INITIAL.
*
*          l_tmp1 = ( wa_afvv-lmnga * wa_afvv-vgw02 ) / l_tmp.
*
*          l_tmp1 = l_tmp1 * 100.
*
*          MOVE l_tmp1 TO l_effic1.
*
*        ENDIF.
*
*      ENDIF.
*    ENDLOOP.
*
**    CLEAR v_plant_effic.
**    PERFORM plant_effic USING wa_pro_orders-plnty
**                            wa_pro_orders-plnnr wa_pro_orders-plnkn
**                            wa_pro_orders-zaehl
**                      CHANGING v_plant_effic.
**    l_sum_plan_effic  = l_sum_plan_effic  + l_plan_effic.
*    l_sum_plan_effic  = l_sum_plan_effic  + l_effic.
**    l_sum_plant_effic = l_sum_plant_effic + v_plant_effic.
*    l_sum_plant_effic = l_sum_plant_effic + l_effic1.
**- End of MOD-001
*    l_sum_prdqty      = l_sum_prdqty  + l_prdqty.
*
****Begin of MOD-001
**    CLEAR: i_sum_activity. "l_prdqty
****End of MOD-001
*    LOOP AT i_ordops INTO wa_ordops
*           WHERE aufnr = wa_pro_orders-aufnr.
*      PERFORM activity_report USING l_prdqty l_gamng l_fromuom l_gmein.
*      CLEAR : wa_ordops.
*    ENDLOOP.
*
*LOOP AT i_ordmats INTO wa_ordmats WHERE aufnr = wa_pro_orders-aufnr.
*      PERFORM summary_materials.
*      CLEAR : wa_ordmats.
*    ENDLOOP.
*    CLEAR : wa_pro_orders.
*  ENDLOOP.
*  CLEAR: l_plan_effic, v_plant_effic, l_prdqty, l_tot_orders.
*
** Passing summraised data to internal table for printing.
*  DESCRIBE TABLE i_pro_orders LINES l_tot_orders.
*  IF l_tot_orders > 0.
**    l_plan_effic = l_sum_plan_effic / l_tot_orders. " MOD-001--
*    l_effic = l_sum_plan_effic / l_tot_orders.              " MOD-001++
**    v_plant_effic = l_sum_plant_effic / l_tot_orders." MOD-001--
*    l_effic1 = l_sum_plant_effic / l_tot_orders.            " MOD-001++
*  ENDIF.
*  CLEAR  wa_nodestab.
*  wa_nodestab-id     = c_2_2.
*  wa_nodestab-tlevel = c_3.
*  wa_nodestab-parent = c_1_1.
*
*  IF NOT ( rb_prod IS INITIAL ).
*    wa_nodestab-text = 'Produced Qty:'(050).
*  ELSE.
*    wa_nodestab-text = 'Confirmed Qty:'(051).
*  ENDIF.
*  wa_nodestab-tlength = c_15.
*  wa_nodestab-tcolor  = c_4.
*
*  MOVE l_sum_prdqty TO wa_nodestab-text1(20).
*  wa_nodestab-tlength1 = c_20.
*  wa_nodestab-tcolor1  = c_4.
*
**  CONCATENATE 'Plan Effic:'(036) l_plan_effic c_perc "'%'
*  WRITE l_effic TO l_plan_effic.
*  CONCATENATE 'Exp. Line Eff.'(036) l_plan_effic c_perc "'%'
*  INTO wa_nodestab-text2 SEPARATED BY space.
*  wa_nodestab-tlength2 = c_25.
*  wa_nodestab-tcolor2  = c_4.
*
**  CONCATENATE 'Plant Effic:'(037) v_plant_effic c_perc "'%'
*  WRITE l_effic1 TO l_plant_effic.
*  CONCATENATE 'Act. Line Eff.'(037) l_plant_effic c_perc "'%'
*  INTO wa_nodestab-text3 SEPARATED BY space.
*  wa_nodestab-tlength3 = c_25.
*  wa_nodestab-tcolor3  = c_4.
*
*  APPEND wa_nodestab TO i_nodestab.
*
** Summarised Phase Information
*  CLEAR  wa_nodestab.
*  wa_nodestab-id     = c_3_3.
*  wa_nodestab-tlevel = c_3.
*  wa_nodestab-parent = c_1_1.
*
*  wa_nodestab-text = 'Activity'(052).
*  wa_nodestab-tlength = c_40.
*  wa_nodestab-tcolor  = c_4.
*
*  IF rb_fiscl = c_x.
*    CONCATENATE 'Actual Usage'(040) v_waers
*    INTO wa_nodestab-text1 SEPARATED BY space.
*  ELSE.
*    wa_nodestab-text1 = 'Actual Usage'(040).
*  ENDIF.
*  wa_nodestab-tlength1 = c_20.
*  wa_nodestab-tcolor1  = c_4.
*
*  IF rb_fiscl = c_x.
*    CONCATENATE 'Standard Usage'(041) v_waers
*    INTO wa_nodestab-text2 SEPARATED BY space.
*  ELSE.
*    wa_nodestab-text2 = 'Standard Usage'(041).
*  ENDIF.
*  wa_nodestab-tlength2 = c_20.
*  wa_nodestab-tcolor2  = c_4.
*
*  IF rb_fiscl = c_x.
*    CONCATENATE 'Activity Variance'(042) v_waers
*    INTO wa_nodestab-text3 SEPARATED BY space.
*  ELSE.
*    wa_nodestab-text3 = 'Activity Variance'(042).
*  ENDIF.
*  wa_nodestab-tlength3 = c_35.
*  wa_nodestab-tcolor3  = c_4.
*
*  APPEND wa_nodestab TO i_nodestab.
*
** Summarized activities
*  CLEAR: l_act_total, l_std_total, l_var_total.
*  SORT i_sum_activity BY lar.
*  LOOP AT i_sum_activity INTO wa_sum_activity.
*
*    SELECT ltext FROM  cslt INTO l_ltext
*       WHERE  spras       = sy-langu
*       AND    kokrs       = p_kokrs
*       AND    lstar       = wa_sum_activity-lar.
*    ENDSELECT.
*
*
*    IF sy-subrc = 0.
**Not required to handle
*    ENDIF.
*
*
*    CLEAR  wa_nodestab.
*    wa_nodestab-id     =  c_3_4.
*    wa_nodestab-tlevel =  c_4.
*    wa_nodestab-parent =  c_3_3.
*
*    wa_nodestab-text1 = l_ltext.
*    wa_nodestab-tlength1 = c_36.
*    wa_nodestab-tcolor1  = c_3.
*
*    IF rb_fiscl IS INITIAL.
*      MOVE wa_sum_activity-afru_ism TO wa_nodestab-text2(20).
*      wa_nodestab-tlength2 = c_20.
*      wa_nodestab-tcolor2  = c_3.
*
*      MOVE wa_sum_activity-ism_should TO wa_nodestab-text3(20).
*      wa_nodestab-tlength3 = c_20.
*      wa_nodestab-tcolor3  = c_3.
*
*      MOVE wa_sum_activity-ism_var TO wa_nodestab-text4(20).
*      wa_nodestab-tlength4 = c_20.
*      wa_nodestab-tcolor4  = c_3.
*
*    ELSE.
*      MOVE wa_sum_activity-coact TO wa_nodestab-text2(20).
*      wa_nodestab-tlength2 = c_20.
*      wa_nodestab-tcolor2  = c_3.
*
*      MOVE wa_sum_activity-costd TO wa_nodestab-text3(20).
*      wa_nodestab-tlength3 = c_20.
*      wa_nodestab-tcolor3  = c_3.
*
*      MOVE wa_sum_activity-covar TO wa_nodestab-text4(20).
*      wa_nodestab-tlength4 = c_20.
*      wa_nodestab-tcolor4  = c_3.
*
*      l_act_total = l_act_total + wa_sum_activity-coact.
*      l_std_total = l_std_total + wa_sum_activity-costd.
*      l_var_total = l_var_total + wa_sum_activity-covar.
*    ENDIF.
*    APPEND wa_nodestab TO i_nodestab.
*    CLEAR : wa_nodestab, wa_sum_activity.
*  ENDLOOP.
*  IF NOT ( rb_fiscl IS INITIAL ).
*
** Display sub-total of Activities.
*    CLEAR  wa_nodestab.
*    wa_nodestab-id     = c_3_4.
*    wa_nodestab-tlevel =  c_4.
*    wa_nodestab-parent = c_3_3.
*
*    IF rb_fiscl = c_x.
*      CONCATENATE 'Fiscal Activity Totals:'(053) v_waers
*      INTO wa_nodestab-text1 SEPARATED BY space.
*    ELSE.
*      wa_nodestab-text1 = 'Fiscal Activity Totals:'(053).
*    ENDIF.
*    wa_nodestab-tlength1 = c_36.
*    wa_nodestab-tcolor1  = c_2.
*
*    MOVE l_act_total TO wa_nodestab-text2(20).
*    wa_nodestab-tlength2 = c_20.
*    wa_nodestab-tcolor2  = c_2.
*
*    MOVE l_std_total TO wa_nodestab-text3(20).
*    wa_nodestab-tlength3 = c_20.
*    wa_nodestab-tcolor3  = c_2.
*
*    MOVE l_var_total TO wa_nodestab-text4(20).
*    wa_nodestab-tlength4 = c_20.
*    wa_nodestab-tcolor4  = c_2.
*
*    APPEND wa_nodestab TO i_nodestab.
*  ENDIF.
** Summarized Material Information
*  CLEAR  wa_nodestab.
*  wa_nodestab-id     = c_6_1.
*  wa_nodestab-tlevel =  c_3.
*  wa_nodestab-parent = c_2_2.
*
*  PERFORM material_header.
*
*  CLEAR: l_act_total, l_std_total, l_var_total.
*  SORT i_sum_ordmats BY matnr.
*  LOOP AT i_sum_ordmats INTO wa_sum_ordmats .
*    CLEAR: wa_nodestab.
*    wa_nodestab-id     = c_4_1.
*    wa_nodestab-tlevel = c_4.
*    wa_nodestab-parent = c_3_2.
*
** Material Number
*    WRITE wa_sum_ordmats-matnr TO wa_nodestab-text NO-ZERO.
*    wa_nodestab-tlength = c_18.
*    wa_nodestab-tcolor  = c_3.
*
** Material Description
*    CLEAR wa_material_des.
*    READ TABLE i_material_des INTO wa_material_des
*       WITH KEY matnr = wa_sum_ordmats-matnr.
*    wa_nodestab-text1 = wa_material_des-maktx.
*    wa_nodestab-tlength1 = c_30.
*    wa_nodestab-tcolor1  = c_3.
*
** Standard planned or zero loss planned
*
*    IF rb_zloss IS INITIAL.
*      l_qty = wa_sum_ordmats-stdqy.
*    ELSE.
*      l_qty = wa_sum_ordmats-zloss.
*    ENDIF.
*
** Order uom or kgm
*    IF rb_kgm IS INITIAL.
*      l_aqty = wa_sum_ordmats-menge.
*      l_sqty = l_qty.
*    ELSE.
** do actual conversion
*      PERFORM uom_convert USING wa_sum_ordmats-matnr
*                                wa_sum_ordmats-menge
*                                wa_sum_ordmats-amein
*                                l_aqty.
** do std/zloss conversion
*      PERFORM uom_convert USING wa_ordmats-matnr
*                                wa_ordmats-stdqy
*                                wa_ordmats-meins
*                                l_sqty.
*    ENDIF.
*
*    PERFORM std_percentage_calc USING l_aqty l_sqty l_pcent.
*
** Fiscal or quantity
*    IF rb_fiscl IS INITIAL.
*      MOVE l_aqty TO wa_nodestab-text2(20). " Actual Usage
*      wa_nodestab-tlength2 = c_20.
*      wa_nodestab-tcolor2  = c_3.
*
*      MOVE l_sqty TO wa_nodestab-text3(20). " Standard Usage
*      wa_nodestab-tlength3 = c_20.
*      wa_nodestab-tcolor3  = c_3.
*
*    ELSE.
*      IF NOT wa_sum_ordmats-peinh IS INITIAL.
*        CLEAR l_cost.
*        l_cost = ( wa_sum_ordmats-stprs * wa_sum_ordmats-menge )
*                                   / wa_sum_ordmats-peinh.
*        MOVE l_cost TO wa_nodestab-text2(20). " Acutal Usage
*        wa_nodestab-tlength2 = c_20.
*        wa_nodestab-tcolor2  = c_3.
*
*        l_act_total = l_act_total + l_cost. " Subtotal of actual
*
*      ENDIF.
*      IF NOT wa_sum_ordmats-peinh IS INITIAL.
*        CLEAR l_cost.
*        l_cost = ( wa_sum_ordmats-stprs * wa_sum_ordmats-stdqy )
*                                  / wa_sum_ordmats-peinh.
*        MOVE l_cost TO wa_nodestab-text3(20). " Standard Usage
*        wa_nodestab-tlength3 = c_20.
*        wa_nodestab-tcolor3  = c_3.
*
*        l_std_total = l_std_total + l_cost. " Subtotal of standard
*
*      ENDIF.
*    ENDIF.
*
*    MOVE l_pcent TO wa_nodestab-text4(18). " Variance Percentage
*    CONCATENATE wa_nodestab-text4(18) c_perc "'%'
*    INTO wa_nodestab-text4(20) SEPARATED BY space.
*    wa_nodestab-tlength4 = c_20.                            "c_19.
*    wa_nodestab-tcolor4  = c_3.
*
*    CLEAR: l_diff, l_cost.
*    l_diff = wa_sum_ordmats-menge - wa_sum_ordmats-stdqy.
*    IF NOT wa_sum_ordmats-peinh IS INITIAL.
*l_cost = ( wa_sum_ordmats-stprs * l_diff ) / wa_sum_ordmats-peinh.
*      l_cost = l_cost * -1.
*    ENDIF.
*
*    MOVE l_cost TO wa_nodestab-text5(20). " Variance  "15
*    wa_nodestab-tlength5 = c_20.                            "c_15
*    wa_nodestab-tcolor5  = c_3.
*
*    l_var_total = l_var_total + l_cost. " Subtotal of Variance
*
*    APPEND wa_nodestab TO i_nodestab.
*    CLEAR : wa_nodestab, wa_sum_ordmats.
*  ENDLOOP.
** Displaying Subtotals
*  IF NOT ( rb_fiscl IS INITIAL ).
*
*    CLEAR  wa_nodestab.
*    wa_nodestab-id     = c_4_1.
*    wa_nodestab-tlevel =  c_4.
*    wa_nodestab-parent = c_3_2.
*
*    IF rb_fiscl = c_x.
*      CONCATENATE 'Fiscal quantity Totals:'(054) v_waers
*      INTO wa_nodestab-text SEPARATED BY space.
*    ELSE.
*      wa_nodestab-text = 'Fiscal quantity Totals:'(054).
*    ENDIF.
*    wa_nodestab-tlength = c_30.
*    wa_nodestab-tcolor  = c_6.
*
*    wa_nodestab-text1 = space.
*    wa_nodestab-tlength1 = c_18.
*    wa_nodestab-tcolor1  = c_6.
*
*    MOVE l_act_total TO wa_nodestab-text2(20) .
*    wa_nodestab-tlength2 = c_20.
*    wa_nodestab-tcolor2  = c_6.
*
*    MOVE l_std_total TO wa_nodestab-text3(20) .
*    wa_nodestab-tlength3 = c_20.
*    wa_nodestab-tcolor3  = c_6.
*
*    wa_nodestab-text4 = space.
*    wa_nodestab-tlength4 = c_19.
*    wa_nodestab-tcolor4  = c_6.
*
*    MOVE l_var_total TO wa_nodestab-text5(21) .
*    wa_nodestab-tlength5 = c_21. "15.
*    wa_nodestab-tcolor5  = c_6.
*
*    APPEND wa_nodestab TO i_nodestab.
*  ELSE.
*    CLEAR  wa_nodestab.
*    wa_nodestab-id     =  c_4_1.
*    wa_nodestab-tlevel =  c_4.
*    wa_nodestab-parent =  c_3_2.
*
*    IF rb_fiscl = c_x.
*      CONCATENATE 'Variance Fiscal Total:'(055) v_waers
*      INTO wa_nodestab-text SEPARATED BY space.
*    ELSE.
*      wa_nodestab-text = 'Variance Fiscal Total:'(055).
*    ENDIF.
*    wa_nodestab-tlength = c_29.
*    wa_nodestab-tcolor  = c_6.
*
*    wa_nodestab-text1 = space.
*    wa_nodestab-tlength1 = c_40.
*    wa_nodestab-tcolor1  = c_6.
*
*    wa_nodestab-text2 = space.
*    wa_nodestab-tlength2 = '41'.                            "c_40.
*    wa_nodestab-tcolor2  = c_6.
*
*    MOVE l_var_total TO wa_nodestab-text3(20) .
*    wa_nodestab-tlength3 = c_20.                            "c_15.
*    wa_nodestab-tcolor3  = c_6.
*
*    APPEND wa_nodestab TO i_nodestab.
*  ENDIF.
*ENDFORM.                    " DISPLAY_SUMMARY_REPORT
**&---------------------------------------------------------------------
**
**&      Form  DISPLAY_PHASE_REPORT
**&---------------------------------------------------------------------
**
**       text
**----------------------------------------------------------------------
**
**----------------------------------------------------------------------
**
*FORM display_phase_report.
*
*  DATA: l_date_low(10)  TYPE c,
*        l_date_high(10) TYPE c,
*        l_diff          TYPE menge_d,
**        l_plan_effic(3) TYPE c,
*        l_plan_effic    TYPE char05,                        "MOD-001++
*        l_plant_effic   TYPE char05,                        "MOD-001++
*        l_gamng         TYPE menge_d,
*        l_gamng1(20)    TYPE c,
*        l_gmein         TYPE meins,
*
*        l_qty    TYPE menge_d,
*        l_prdqty TYPE menge_d,
*        l_conv   TYPE menge_d,
*        l_aqty   TYPE menge_d,
*        l_sqty   TYPE menge_d,
*
*        l_pcent(3)  TYPE p DECIMALS 2,
*        l_cost(8)   TYPE p DECIMALS 2,
*
*        l_act_total(8) TYPE p DECIMALS 2,
*        l_std_total(8) TYPE p DECIMALS 2,
*        l_var_total(8) TYPE p DECIMALS 2,
*
*        l_fromuom TYPE meins,
*        l_cfuom   TYPE meins,
*
*        l_ph_bmsch TYPE i.
**- Begin of MOD-001
*  DATA: l_value TYPE char16,
*        l_tmp TYPE lmnga,
*        l_tmp1 TYPE lmnga,
*        l_effic TYPE p DECIMALS 1,
*        l_uom   TYPE char03.
**- End of MOD-001
*
*
*  PERFORM pfstatus.
*  SET PF-STATUS 'MAIN' EXCLUDING i_fcode.
*  SET TITLEBAR 'VARI' WITH text-068.
*
*  CLEAR wa_nodestab.
*  REFRESH i_nodestab.
*
*  MOVE 'Display Phase Report'(030) TO v_output_text.
*  PERFORM inform_user_of_progress.
*
*  CLEAR wa_nodestab.
*  wa_nodestab-id = c_1_1.
*  wa_nodestab-tlevel = c_1.
*  wa_nodestab-text = 'Production Variances'(031).
*  wa_nodestab-tlength = c_20.
*  wa_nodestab-compress = c_x.
*  APPEND wa_nodestab TO i_nodestab.
*
*  LOOP AT i_pro_orders INTO wa_pro_orders.
*
*    CLEAR: wa_nodestab, l_date_low, l_date_high, l_gamng,
*           wa_material_des.
*
*    l_gamng = wa_pro_orders-gamng.
*    l_gmein = wa_pro_orders-gmein.
*    wa_nodestab-id     = c_2_1.
*    wa_nodestab-tlevel =  c_2.
*    wa_nodestab-parent = c_1_1.
*
** Order Number text
*    wa_nodestab-text    = 'Order Num:'(032).
*    wa_nodestab-tlength = c_12.
*    wa_nodestab-tcolor  = c_1.
** Order number
*    WRITE wa_pro_orders-aufnr TO wa_nodestab-text1 NO-ZERO.
*    wa_nodestab-tlength1 = c_12.
*    wa_nodestab-tcolor1  = c_1.
*    wa_nodestab-hotspot1 = c_x.
*
** Date Range
*    WRITE wa_pro_orders-wdate TO l_date_low.
*    WRITE wa_pro_orders-gltrp TO l_date_high.
*    CONCATENATE l_date_low c_hyp l_date_high
*    INTO wa_nodestab-text2 SEPARATED BY space.
*    wa_nodestab-tlength2 = c_25.
*    wa_nodestab-tcolor2  = c_1.
*
** Material Number
*    WRITE wa_pro_orders-plnbez TO wa_nodestab-text3 NO-ZERO.
*    wa_nodestab-tlength3 = c_18.
*    wa_nodestab-tcolor3  = c_1.
*
** Material Description
*    READ TABLE i_material_des INTO wa_material_des
*        WITH KEY matnr = wa_pro_orders-plnbez.
*    wa_nodestab-text4 = wa_material_des-maktx.
*    wa_nodestab-tlength4 = c_33.
*    wa_nodestab-tcolor4  = c_1.
*
*    APPEND wa_nodestab TO i_nodestab.
*
*    LOOP AT i_ordops INTO wa_ordops
*             WHERE aufnr = wa_pro_orders-aufnr.
*      PERFORM get_confirmation_qty USING wa_ordops-rueck
*                                         l_prdqty l_cfuom.
*      IF rb_kgm = c_x.
*        IF rb_conf IS INITIAL.
*          l_prdqty  = wa_pro_orders-menge.
*          l_fromuom = wa_pro_orders-gruom.
*        ELSE.
*          l_fromuom = l_cfuom.
*        ENDIF.
** do gr/conf conversion
*        PERFORM uom_convert USING wa_pro_orders-plnbez l_prdqty
*                                  l_fromuom l_conv.
*        l_prdqty = l_conv.
*        l_qty = l_prdqty.
** do planned conversion
********mod-002*******************************
**       l_fromuom = wa_pro_orders-gmein.
*        l_fromuom = 'KG'.
*******MOD-002********************************
*
*        PERFORM uom_convert USING wa_pro_orders-plnbez
*                                  wa_pro_orders-gamng
*                                  l_fromuom l_conv.
*        l_gamng = l_conv.
*      ELSE.
** Get Standard Numbers from the phase
*        READ TABLE i_plpo INTO wa_plpo
*                          WITH KEY plnty = wa_pro_orders-plnty
*                                   plnnr = wa_pro_orders-plnnr
*                                   plnkn = wa_pro_orders-plnkn
*                                   zaehl = wa_pro_orders-zaehl.
*        PERFORM get_stds USING wa_ordops-plnty wa_ordops-plnnr
*                               wa_ordops-plnkn wa_ordops-zaehl.
** Factor in any differences in uoms (plpo selected in get_stds form)
*        l_ph_bmsch = wa_plpo-bmsch / ( wa_plpo-umrez / wa_plpo-umren ).
** calculate planned phase qty as planned order qty / final phase std
*qty
** current phase std qty
*        l_gamng = ( wa_pro_orders-gamng / wa_plpo-bmsch ) * l_ph_bmsch.
** Get actual produced Qty (from order) or use Confirm Qty (from phase)
*        IF rb_conf IS INITIAL.
** Factor in any differences in uoms (plpo selected in plant_effic form)
*          l_qty = ( wa_pro_orders-menge / wa_plpo-bmsch ) * l_ph_bmsch.
*          l_prdqty = wa_pro_orders-menge.
*          l_fromuom = wa_pro_orders-gruom.
*        ELSE.
*          l_qty = ( l_prdqty / wa_plpo-bmsch ) * l_ph_bmsch.
*          l_fromuom = l_cfuom.
*        ENDIF.
*      ENDIF.
*
**- begin of MOD-001
** Calculate Plan effic.
**      CLEAR l_plan_effic.
**
**      IF l_gamng > 0.
**        l_diff = ABS( l_gamng - l_qty ).
**        l_plan_effic = c_100 - c_100 * ( l_diff / l_gamng ).
**      ELSE.
**        CLEAR l_plan_effic.
**      ENDIF.
*
*      LOOP AT i_plpo1 INTO wa_plpo1
*              WHERE plnty = wa_pro_orders-plnty
*                AND plnnr = wa_pro_orders-plnnr
*                AND steus = 'YBN1'.
*        IF wa_plpo1-vgw02 IS NOT INITIAL.
*          MOVE wa_plpo1-usr04 TO l_effic. "L_VALUE.
*          WRITE l_effic TO l_plan_effic.
*          wa_plpo2 = wa_plpo1.
*          APPEND wa_plpo2 TO i_plpo2.
**********MOD-002*******************************
**        ELSE.
**          CLEAR l_plan_effic.
*        ENDIF.
*********MOD-002********************************
*      ENDLOOP.
*
*
**- End of MOD-001
** Resource Information
*      CLEAR  wa_nodestab.
*      wa_nodestab-id     =  c_2_2.
*      wa_nodestab-tlevel =  c_3.
*      wa_nodestab-parent = c_1_1.
*
*      CONCATENATE 'Resource:'(056) wa_pro_orders-arbpl
*      INTO wa_nodestab-text SEPARATED BY space.
*      wa_nodestab-tlength = c_25.
*      wa_nodestab-tcolor  = c_4.
*
*      READ TABLE i_wc_text INTO wa_wc_text
*             WITH KEY objid = wa_pro_orders-arbid.
*      wa_nodestab-text1 = wa_wc_text-ktext.
*      wa_nodestab-tlength1 = c_30.
*      wa_nodestab-tcolor1  = c_4.
*
************MOD-002*********************************
*      wa_nodestab-text2 = wa_ordops-vornr.
*      wa_nodestab-tlength2 = c_4.
*      wa_nodestab-tcolor2  = c_4.
*
*********mod-002************************************
*
** Produced Quantity / Confirmed Quantity
*      MOVE l_prdqty TO wa_nodestab-text3(20).
*      MOVE l_fromuom TO l_uom.                              " MOD-001++
*      IF NOT ( rb_prod IS INITIAL ).
**        CONCATENATE 'Prod Qty: '(033) wa_nodestab-text2 "MOD-001-
*        CONCATENATE 'Prod Qty: '(033) wa_nodestab-text3 l_uom"MOD-001+
*       INTO wa_nodestab-text3 SEPARATED BY space.
*      ELSE.
**        CONCATENATE 'Conf Qty: '(034) wa_nodestab-text2 "MOD-001-
*        CONCATENATE 'Conf Qty: '(034) wa_nodestab-text3 l_uom"MOD-001+
*        INTO wa_nodestab-text3 SEPARATED BY space.
*      ENDIF.
*
**      wa_nodestab-tlength2 = c_30. "MOD-001-
*      wa_nodestab-tlength3 = c_35_1.                        "MOD-001+
*      wa_nodestab-tcolor3 = c_1.
*
**    CONCATENATE 'Plan Effic:'(036) l_plan_effic c_perc "'%'
*      CONCATENATE 'Exp. Line Eff.'(036) l_plan_effic c_perc "'%'
*        INTO wa_nodestab-text4 SEPARATED BY space.
*      wa_nodestab-tlength4 = c_25.
*      wa_nodestab-tcolor4  = c_4.
*
**      CLEAR v_plant_effic.
**      PERFORM plant_effic USING wa_ordops-plnty
**                                wa_ordops-plnnr
**                                wa_ordops-plnkn
**                                wa_ordops-zaehl
**                       CHANGING v_plant_effic.
*      CLEAR l_effic.
**************mod-002**************************
**    READ TABLE I_AFVC INTO WA_AFVC
**         WITH KEY PLNTY = WA_PLPO1-PLNTY
**                  PLNNR = WA_PLPO1-PLNNR
**                  ZAEHL = WA_PLPO1-ZAEHL.
*** Mod-002***********************************
*
****************MOD-008************************
**      LOOP AT I_ORDOPS INTO WA_ORDOPS.
**        READ TABLE I_PRO_ORDERS INTO WA_PRO_ORDERS WITH KEY
**                                      AUFNR = WA_ORDOPS-AUFNR
**                                                BINARY SEARCH.
**        IF SY-SUBRC = 0.
**          READ table i_afvc1 into wa_afvc1 with key
**                        plnty = wa_ORDOPS-plnty
**                        plnnr = wa_ORDOPS-plnnr
**                        plnkn = wa_ORDOPS-plnkn
**                        zaehl = wa_ORDOPS-zaehl
**                        aufpl = wa_pro_orders-aufpl.
**          IF SY-SUBRC = 0.
**            READ TABLE I_AFVV1 into wa_afvv1 with key
**                   aufpl = wa_afvc1-aufpl
**                   aplzl = wa_afvc1-aplzl binary search.
**            IF SY-SUBRC = 0.
**              CHECK WA_AFVV1-VGW02 NE 0.
**              l_tmp = wa_afvv1-bmsch * wa_afvv1-ism02.
**              IF l_tmp IS NOT INITIAL.
**
**                l_tmp1 = ( wa_afvv1-lmnga * wa_afvv1-vgw02 ) / l_tmp.
**
**                l_tmp1 = l_tmp1 * 100.
**
**                MOVE l_tmp1 TO l_effic.
**
**              ENDIF.
**            ENDIF.
**          ENDIF.
**        ENDIF.
**      ENDLOOP.
**
**************MOD-008***************************
*
*      LOOP AT i_plpo2 INTO wa_plpo2.
*        READ TABLE i_afvc INTO wa_afvc
*           WITH KEY plnty = wa_plpo2-plnty
*                    plnnr = wa_plpo2-plnnr
*                    plnkn = wa_plpo2-plnkn
*                    zaehl = wa_plpo2-zaehl
*                    aufpl = wa_pro_orders-aufpl.
*
*
*
*** Mod-002***********************************
*
*        IF sy-subrc IS INITIAL.
*          READ TABLE i_afvv INTO wa_afvv
*               WITH KEY aufpl = wa_afvc-aufpl
*                        aplzl = wa_afvc-aplzl.
*
*          l_tmp = wa_afvv-bmsch * wa_afvv-ism02.
*          IF l_tmp IS NOT INITIAL.
*
*            l_tmp1 = ( wa_afvv-lmnga * wa_afvv-vgw02 ) / l_tmp.
*
*            l_tmp1 = l_tmp1 * 100.
*
*            MOVE l_tmp1 TO l_effic.
*
*          ENDIF.
*
*        ENDIF.
*      ENDLOOP.
*
*      WRITE l_effic TO l_plant_effic.
*
**    CONCATENATE 'Plant Effic:'(037) v_plant_effic c_perc "'%'
*      CONCATENATE 'Act. Line Eff.'(037) l_plant_effic c_perc "'%'
*                                                            " MOD-001+
*        INTO wa_nodestab-text5 SEPARATED BY space.
*      wa_nodestab-tlength5 = c_25.
*      wa_nodestab-tcolor5 = c_4.
*
*      APPEND wa_nodestab TO i_nodestab.
*
** Phase Information
*      CLEAR  wa_nodestab.
*      wa_nodestab-id     = c_3_3.
*      wa_nodestab-tlevel =  c_3.
*      wa_nodestab-parent = c_1_1.
*
*      wa_nodestab-text    = 'Phase'(038).
*      wa_nodestab-tlength =  c_10.
*      wa_nodestab-tcolor  =  c_4.
*
*      MOVE l_gamng TO l_gamng1.
*      CONCATENATE 'Activity (Std Plan:'(039) l_gamng1 c_brac "')'
*      INTO wa_nodestab-text1 SEPARATED BY space.
*      wa_nodestab-tlength1 = c_42.
*      wa_nodestab-tcolor1  = c_4.
*
*      IF rb_fiscl = c_x.
*        CONCATENATE 'Actual Usage'(040) v_waers
*        INTO wa_nodestab-text2 SEPARATED BY space.
*      ELSE.
*        wa_nodestab-text2 = 'Actual Usage'(040).
*      ENDIF.
*      wa_nodestab-tlength2 = c_20.
*      wa_nodestab-tcolor2  = c_4.
*
*      IF rb_fiscl = c_x.
*        CONCATENATE 'Standard Usage'(041) v_waers
*        INTO wa_nodestab-text3 SEPARATED BY space.
*      ELSE.
*        wa_nodestab-text3 = 'Standard Usage'(041).
*      ENDIF.
*      wa_nodestab-tlength3 = c_20.
*      wa_nodestab-tcolor3  = c_4.
*
*      IF rb_fiscl = c_x.
*        CONCATENATE 'Activity Variance'(042) v_waers
*        INTO wa_nodestab-text4 SEPARATED BY space.
*      ELSE.
*        wa_nodestab-text4 = 'Activity Variance'(042).
*      ENDIF.
*      wa_nodestab-tlength4 = c_35.
*      wa_nodestab-tcolor4  = c_4.
*
*      APPEND wa_nodestab TO i_nodestab.
*
** Display acitivity report
*      PERFORM activity_report USING l_prdqty l_gamng l_uom l_gmein.
*
** Material Information
*      CLEAR: wa_nodestab, l_act_total, l_std_total, l_var_total.
*      wa_nodestab-id = c_3_4.
*      wa_nodestab-tlevel = c_3.
*      wa_nodestab-parent = c_1_1.
*
*      PERFORM material_header.
*
** Individual material details
*      LOOP AT i_ordmats INTO wa_ordmats
*           WHERE aufnr = wa_pro_orders-aufnr
*             AND vornr = wa_ordops-vornr.
*
*        CLEAR: wa_nodestab.
*        wa_nodestab-id     = c_4_1.
*        wa_nodestab-tlevel =  c_4.
*        wa_nodestab-parent = c_3_2.
*
** Material Number
*        WRITE wa_ordmats-matnr TO wa_nodestab-text NO-ZERO.
*        wa_nodestab-tlength = c_18.
*        wa_nodestab-tcolor  = c_3.
*
** Material Description
*        CLEAR wa_material_des.
*        READ TABLE i_material_des INTO wa_material_des
*              WITH KEY matnr = wa_ordmats-matnr.
*        wa_nodestab-text1 = wa_material_des-maktx.
*        wa_nodestab-tlength1 = c_30.
*        wa_nodestab-tcolor1  = c_3.
*
** Standard planned or zero loss planned
*
*        IF rb_zloss IS INITIAL.
*          l_qty = wa_ordmats-stdqy.
*        ELSE.
*          l_qty = wa_ordmats-zloss.
*        ENDIF.
*
** Order uom or kgm
*        IF rb_kgm IS INITIAL.
*          l_aqty = wa_ordmats-menge.
*          l_sqty = l_qty.
*        ELSE.
** do actual conversion
*          PERFORM uom_convert USING wa_ordmats-matnr
*                                    wa_ordmats-menge
*                                    wa_ordmats-amein
*                                    l_aqty.
** do std/zloss conversion
*          PERFORM uom_convert USING wa_ordmats-matnr
*                                    wa_ordmats-stdqy
*                                    wa_ordmats-meins
*                                    l_sqty.
*        ENDIF.
*
*        PERFORM std_percentage_calc USING l_aqty l_sqty l_pcent.
*
** Fiscal or quantity
*        IF rb_fiscl IS INITIAL.
*          MOVE l_aqty TO wa_nodestab-text2(20). " Actual Usage
*          wa_nodestab-tlength2 = c_20.
*          wa_nodestab-tcolor2 = c_3.
*
*          MOVE l_sqty TO wa_nodestab-text3(20). " Standard Usage
*          wa_nodestab-tlength3 = c_20.
*          wa_nodestab-tcolor3 = c_3.
*
*        ELSE.
*          IF NOT wa_ordmats-peinh IS INITIAL.
*            CLEAR l_cost.
*            l_cost = ( wa_ordmats-stprs * wa_ordmats-menge )
*                                       / wa_ordmats-peinh.
*            MOVE l_cost TO wa_nodestab-text2(20). " Acutal Usage
*            wa_nodestab-tlength2 = c_20.
*            wa_nodestab-tcolor2 = c_3.
*
*            l_act_total = l_act_total + l_cost. " Subtotal of actual
*          ENDIF.
*          IF NOT wa_ordmats-peinh IS INITIAL.
*            CLEAR l_cost.
*            l_cost = ( wa_ordmats-stprs * wa_ordmats-stdqy )
*                                      / wa_ordmats-peinh.
*            MOVE l_cost TO wa_nodestab-text3(20). " Standard Usage
*            wa_nodestab-tlength3 = c_20.
*            wa_nodestab-tcolor3 = c_3.
*
*            l_std_total = l_std_total + l_cost. " Subtotal of standard
*          ENDIF.
*
*        ENDIF.
*
*        MOVE l_pcent TO wa_nodestab-text4(17). " Variance Percentage
*        CONCATENATE wa_nodestab-text4(17) c_perc "'%'
*        INTO wa_nodestab-text4(19) SEPARATED BY space.
*        wa_nodestab-tlength4 = 19.
*        wa_nodestab-tcolor4 = c_3.
*
*        CLEAR: l_diff, l_cost.
*        l_diff = wa_ordmats-menge - wa_ordmats-stdqy.
*        IF NOT wa_ordmats-peinh IS INITIAL.
*          l_cost = ( wa_ordmats-stprs * l_diff ) / wa_ordmats-peinh.
*          l_cost = l_cost * -1.
*        ENDIF.
*
*        MOVE l_cost TO wa_nodestab-text5(15). " Variance
*        wa_nodestab-tlength5 = c_15.
*        wa_nodestab-tcolor5 = c_3.
*
*        l_var_total = l_var_total + l_cost. " Subtotal of Variance
*
*        APPEND wa_nodestab TO i_nodestab.
*
*      ENDLOOP.
*
** Displaying Subtotals
*      CHECK sy-subrc IS INITIAL.
*      CLEAR  wa_nodestab.
*      wa_nodestab-id     = c_4_1.
*      wa_nodestab-tlevel =  c_4.
*      wa_nodestab-parent = c_3_2.
*
*      wa_nodestab-text    = 'Material Totals'(043).
*      wa_nodestab-tlength = c_18.
*      wa_nodestab-tcolor  = c_6.
*
*      wa_nodestab-text1    = space.
*      wa_nodestab-tlength1 = c_30.
*      wa_nodestab-tcolor1  = c_6.
*
*      MOVE l_act_total TO wa_nodestab-text2(20) .
*      wa_nodestab-tlength2 = c_20.
*      wa_nodestab-tcolor2  = c_6.
*
*      MOVE l_std_total TO wa_nodestab-text3(20) .
*      wa_nodestab-tlength3 = c_20.
*      wa_nodestab-tcolor3  = c_6.
*
*      wa_nodestab-text4 = space.
*      wa_nodestab-tlength4 = c_19.
*      wa_nodestab-tcolor4  = c_6.
*
*      MOVE l_var_total TO wa_nodestab-text5(15) .
*      wa_nodestab-tlength5 = c_15.
*      wa_nodestab-tcolor5  = c_6.
*
*      APPEND wa_nodestab TO i_nodestab.
*
*    ENDLOOP.
** Output the materials which were issued to order but aren't on bom
*    READ TABLE i_issued_mat INTO wa_issued_mat
*        WITH KEY aufnr = wa_pro_orders-aufnr.
*    IF sy-subrc = 0.
*
*      CLEAR  wa_nodestab.
*      wa_nodestab-id     = c_3_5.
*      wa_nodestab-tlevel =  c_3 .
*      wa_nodestab-parent = c_1_1.
*
*      wa_nodestab-text =
*      'Materials issued to order but not in Recipe'(057).
*      wa_nodestab-tlength = c_45.
*      wa_nodestab-tcolor  = c_6.
*
*      APPEND wa_nodestab TO i_nodestab.
*
** Material Information
*      CLEAR  wa_nodestab.
*      wa_nodestab-id     = c_3_6.
*      wa_nodestab-tlevel =  c_3.
*      wa_nodestab-parent = c_3_5.
*
*      PERFORM material_header.
** now write the components
*
*      CLEAR: l_pcent, l_act_total, l_std_total, l_var_total.
*
*      LOOP AT i_issued_mat INTO wa_issued_mat
*               WHERE aufnr = wa_pro_orders-aufnr.
*
*        CLEAR: wa_nodestab, l_aqty, l_sqty, l_cost, wa_material_des.
*        wa_nodestab-id     = c_6_1.
*        wa_nodestab-tlevel =  c_6.
*        wa_nodestab-parent = c_3_6.
*
** Material Number
*        WRITE wa_issued_mat-matnr TO wa_nodestab-text NO-ZERO.
*        wa_nodestab-tlength = c_18.
*        wa_nodestab-tcolor  = c_3.
*
** Material Description
*        READ TABLE i_material_des INTO wa_material_des
*             WITH KEY matnr = wa_issued_mat-matnr.
*        wa_nodestab-text1 = wa_material_des-maktx.
*        wa_nodestab-tlength1 = c_30.
*        wa_nodestab-tcolor1  = c_3.
*
*        IF rb_fiscl IS INITIAL.
** Actual Usage
*          l_aqty = wa_issued_mat-menge.
*          MOVE l_aqty TO wa_nodestab-text2(20). " Actual Usage
*          wa_nodestab-tlength2 = c_20.
*          wa_nodestab-tcolor2  = c_3.
*
** Standard Usage
*          MOVE l_sqty TO wa_nodestab-text3(20). " Standard Usage
*          wa_nodestab-tlength3 = c_20.
*          wa_nodestab-tcolor3  = c_3.
*
*        ELSE.
*          IF NOT wa_issued_mat-peinh IS INITIAL.
*            l_cost =  ( wa_issued_mat-stprs * wa_issued_mat-menge )
*                                            / wa_issued_mat-peinh.
*          ENDIF.
*          l_act_total = l_act_total + l_cost. " Subtotal of actual
*
*          MOVE l_cost TO wa_nodestab-text2(20). " Acutal Usage
*          wa_nodestab-tlength2 = c_20.
*          wa_nodestab-tcolor2  = c_3.
*
*          CLEAR l_cost.
*          MOVE l_cost TO wa_nodestab-text3(20). " Standard Usage
*          wa_nodestab-tlength3 = c_20.
*          wa_nodestab-tcolor3  = c_3.
*
*        ENDIF.
** Variance percentage
*        l_pcent = 100.
*        MOVE l_pcent TO wa_nodestab-text4(17). " Variance Percentage
*        CONCATENATE wa_nodestab-text4(17) c_perc "'%'
*        INTO wa_nodestab-text4(19) SEPARATED BY space.
*        wa_nodestab-tlength4 = c_19.
*        wa_nodestab-tcolor4  = c_3.
** Variance
*        CLEAR l_cost.
*        IF NOT wa_issued_mat-peinh IS INITIAL.
*          l_cost =  ( wa_issued_mat-stprs * wa_issued_mat-menge )
*                                          / wa_issued_mat-peinh.
*          l_cost = l_cost * -1.
*        ENDIF.
*        l_var_total = l_var_total + l_cost. " Subtotal of Variance
*
*        MOVE l_cost TO wa_nodestab-text5(15). " Variance
*        wa_nodestab-tlength5 = c_15.
*        wa_nodestab-tcolor5  = c_3.
*
*        APPEND wa_nodestab TO i_nodestab.
*
*      ENDLOOP.
*
** Displaying Subtotals of material recipe
*
*      CLEAR  wa_nodestab.
*      wa_nodestab-id     = c_6_1.
*      wa_nodestab-tlevel =  c_6.
*      wa_nodestab-parent = c_3_5.
*
*      wa_nodestab-text = 'Material Totals'(043).
*      wa_nodestab-tlength = c_18.
*      wa_nodestab-tcolor  = c_6.
*
*      wa_nodestab-text1 = space.
*      wa_nodestab-tlength1 = c_30.
*      wa_nodestab-tcolor1  = c_6.
*
*      MOVE l_act_total TO wa_nodestab-text2(20) .
*      wa_nodestab-tlength2 = c_20.
*      wa_nodestab-tcolor2  = c_6.
*
*      MOVE l_std_total TO wa_nodestab-text3(20) .
*      wa_nodestab-tlength3 = c_20.
*      wa_nodestab-tcolor3  = c_6.
*
*      wa_nodestab-text4 = space.
*      wa_nodestab-tlength4 = c_19.
*      wa_nodestab-tcolor4  = c_6.
*
*      MOVE l_var_total TO wa_nodestab-text5(15) .
*      wa_nodestab-tlength5 = c_15.
*      wa_nodestab-tcolor5  = c_6.
*
*      APPEND wa_nodestab TO i_nodestab.
*
*    ENDIF.
*
*  ENDLOOP.
*
*ENDFORM.                    " DISPLAY_PHASE_REPORT
**&---------------------------------------------------------------------
**
**&      Form  ACTIVITY_REPORT
**&---------------------------------------------------------------------
**
**       text
**----------------------------------------------------------------------
**
**----------------------------------------------------------------------
**
*FORM activity_report USING fp_l_prdqty TYPE menge_d
*                           fp_l_gamng  TYPE menge_d
*                           fp_l_uom    TYPE meins
*                           fp_l_gmein  TYPE meins.
*  DATA: l_value TYPE gamng,
*        l_ism01_var TYPE ru_ismng,
*        l_ism02_var TYPE ru_ismng,
*        l_ism03_var TYPE ru_ismng,
*        l_ism04_var TYPE ru_ismng,
*        l_ism05_var TYPE ru_ismng,
*        l_ism06_var TYPE ru_ismng.
*  DATA: struct_afvgd TYPE afvgd.
*  DATA: struct_mara TYPE mara,
*        struct_marc TYPE marc.
*  DATA: v_menge TYPE menge_d.
*
** Get Standard Numbers from the phase
*  PERFORM get_stds USING wa_ordops-plnty wa_ordops-plnnr
*                         wa_ordops-plnkn wa_ordops-zaehl.
*
** Calculate Standard Labour/Fitter/Machine Hours.
*  CLEAR struct_activity.
*  MOVE-CORRESPONDING wa_plpo1 TO struct_afvgd.              "#EC ENHOK
*  MOVE: wa_ordops-arbid TO struct_afvgd-arbid,
*        wa_ordops-ssavd TO struct_afvgd-ssavd.
*  MOVE wa_plpo1-vge01 TO v_msehi.
*
*  IF rb_actl IS INITIAL.
** Planned qty
*    l_value = fp_l_gamng.
*  ELSE.
** Actual qty
*    l_value = fp_l_prdqty.
*  ENDIF.
*
*  CALL FUNCTION 'CO_R0_DET_TOTAL_ACTIVITY'
*    EXPORTING
*      act_afvgd             = struct_afvgd
*      act_quantity          = l_value
*      act_flg_consider_conf = space
*      act_unit_of_time      = v_msehi
*    IMPORTING
*      exp_activities        = struct_activity.
*
** Now get the confirmed values
*  PERFORM get_confirmation_details.
*
** Get Activity 1
*  l_ism01_var = struct_activity-acti1 - wa_ord_conf1-ism01.
** Get Activity 2
*  l_ism02_var = struct_activity-acti2 - wa_ord_conf1-ism02.
** Get Activity 3
*  l_ism03_var = struct_activity-acti3 - wa_ord_conf1-ism03.
** Get Activity 4
*  l_ism04_var = struct_activity-acti4 - wa_ord_conf1-ism04.
** Get Activity 5
*  l_ism05_var = struct_activity-acti5 - wa_ord_conf1-ism05.
** Get Activity 6
*  l_ism06_var = struct_activity-acti6 - wa_ord_conf1-ism06.
*
*  IF rb_summ IS INITIAL.
** Now output the activities for each phase
*    IF NOT ( wa_plpo1-lar01 IS INITIAL ).
*      PERFORM activity_cost_report USING wa_plpo1-lar01
*                                         wa_ord_conf1-ism01
*                                         struct_activity-acti1
*                                         l_ism01_var.
*    ENDIF.
*    IF NOT ( wa_plpo1-lar02 IS INITIAL ).
*      PERFORM activity_cost_report USING wa_plpo1-lar02
*                                         wa_ord_conf1-ism02
*                                         struct_activity-acti2
*                                         l_ism02_var.
*    ENDIF.
*    IF NOT ( wa_plpo1-lar03 IS INITIAL ).
*      PERFORM activity_cost_report USING wa_plpo1-lar03
*                                         wa_ord_conf1-ism03
*                                         struct_activity-acti3
*                                         l_ism03_var.
*    ENDIF.
*    IF NOT ( wa_plpo1-lar04 IS INITIAL ).
*      PERFORM activity_cost_report USING wa_plpo1-lar04
*                                         wa_ord_conf1-ism04
*                                         struct_activity-acti4
*                                         l_ism04_var.
*    ENDIF.
*    IF NOT ( wa_plpo1-lar05 IS INITIAL ).
*      PERFORM activity_cost_report USING wa_plpo1-lar05
*                                         wa_ord_conf1-ism05
*                                         struct_activity-acti5
*                                         l_ism05_var.
*    ENDIF.
*    IF NOT ( wa_plpo1-lar06 IS INITIAL ).
*      PERFORM activity_cost_report USING wa_plpo1-lar06
*                                         wa_ord_conf1-ism06
*                                         struct_activity-acti6
*                                         l_ism06_var.
*    ENDIF.
*  ELSEIF rb_summ = c_x.
*    IF NOT ( wa_plpo1-lar01 IS INITIAL ).
*      PERFORM sum_activity_costs USING   wa_plpo1-lar01
*                                         wa_ord_conf1-ism01
*                                         struct_activity-acti1
*                                         l_ism01_var.
*    ENDIF.
*    IF NOT ( wa_plpo1-lar02 IS INITIAL ).
*      PERFORM sum_activity_costs USING   wa_plpo1-lar02
*                                         wa_ord_conf1-ism02
*                                         struct_activity-acti2
*                                         l_ism02_var.
*    ENDIF.
*    IF NOT ( wa_plpo1-lar03 IS INITIAL ).
*      PERFORM sum_activity_costs USING   wa_plpo1-lar03
*                                         wa_ord_conf1-ism03
*                                         struct_activity-acti3
*                                         l_ism03_var.
*    ENDIF.
*    IF NOT ( wa_plpo1-lar04 IS INITIAL ).
*      PERFORM sum_activity_costs USING   wa_plpo1-lar04
*                                         wa_ord_conf1-ism04
*                                         struct_activity-acti4
*                                         l_ism04_var.
*    ENDIF.
*    IF NOT ( wa_plpo1-lar05 IS INITIAL ).
*      PERFORM sum_activity_costs USING   wa_plpo1-lar05
*                                         wa_ord_conf1-ism05
*                                         struct_activity-acti5
*                                         l_ism05_var.
*    ENDIF.
*    IF NOT ( wa_plpo1-lar06 IS INITIAL ).
*      PERFORM sum_activity_costs USING   wa_plpo1-lar06
*                                         wa_ord_conf1-ism06
*                                         struct_activity-acti6
*                                         l_ism06_var.
*    ENDIF.
*
*  ENDIF.
*
*ENDFORM.                    " ACTIVITY_REPORT
**&---------------------------------------------------------------------
**
**&      Form  GET_STDS
**&---------------------------------------------------------------------
**
**       text
**----------------------------------------------------------------------
**
**  -->  p1        text
**  <--  p2        text
**----------------------------------------------------------------------
**
*FORM get_stds USING fp_p_plnty TYPE plnty
*                    fp_p_plnnr TYPE plnnr
*                    fp_p_plnkn TYPE plnkn
*                    fp_p_zaehl TYPE cim_count.
*
*  TYPES:   BEGIN OF ty_crco_info,
*    objty     TYPE cr_objty,
*    objid     TYPE cr_objid,
*    laset     TYPE cr_laset,
*    endda     TYPE enddatum,
*    lanum     TYPE cr_lanum,
*    begda     TYPE begdatum,
*    lstar_ref TYPE ap_kzref,
*    lstar     TYPE lstar,
*  END OF ty_crco_info.
*
*  DATA : i_crco_info TYPE STANDARD TABLE OF ty_crco_info,
*         wa_crco_info TYPE ty_crco_info.
*
*
*  DATA: l_wcinfo TYPE c,
*        l_datuv TYPE plpo-datuv,
*        lc_objty TYPE plpo-objty VALUE 'A'.
*
*  READ TABLE i_plpo1 INTO wa_plpo1 WITH KEY plnty = fp_p_plnty
*                              plnnr = fp_p_plnnr
*                              plnkn = fp_p_plnkn
*                              zaehl = fp_p_zaehl.
*  IF sy-subrc = 0.
*
*    IF ( wa_plpo1-lar01 IS INITIAL AND NOT ( wa_plpo1-vgw01 = 0 ) ) OR
*       ( wa_plpo1-lar02 IS INITIAL AND NOT ( wa_plpo1-vgw02 = 0 ) ) OR
*       ( wa_plpo1-lar03 IS INITIAL AND NOT ( wa_plpo1-vgw03 = 0 ) ) OR
*       ( wa_plpo1-lar04 IS INITIAL AND NOT ( wa_plpo1-vgw04 = 0 ) ) OR
*       ( wa_plpo1-lar05 IS INITIAL AND NOT ( wa_plpo1-vgw05 = 0 ) ) OR
*       ( wa_plpo1-lar06 IS INITIAL AND NOT ( wa_plpo1-vgw06 = 0 ) ).
*      REFRESH: i_crco_info.
** Check the work centre is on the phase, if not go to the operation
*      IF wa_plpo1-arbid IS INITIAL.
*        SELECT datuv arbid objty
*          INTO (l_datuv,wa_plpo1-arbid,wa_plpo1-objty)
*          FROM plpo
*         WHERE plnty = wa_pro_orders-plnty
*           AND plnnr = wa_pro_orders-plnnr
*           AND plnkn = wa_plpo1-pvzkn
*           AND datuv <= sy-datum
*          ORDER BY datuv DESCENDING.
*          EXIT.
*        ENDSELECT.
*      ENDIF.
** Default to work centre object if it's blank
*      IF wa_plpo1-objty IS INITIAL.
*        wa_plpo1-objty = lc_objty.
*      ENDIF.
** Get the work centre activity info
*      SELECT objty objid laset endda lanum begda lstar_ref lstar
*      INTO TABLE i_crco_info
*        FROM crco
*       WHERE objty = wa_plpo1-objty
*         AND objid = wa_plpo1-arbid
*         AND laset = 1.
**     order by primary key.
*
*      IF sy-subrc = 0.
**Not required to handle
*      ENDIF.
*
*      l_wcinfo = c_y.
*    ENDIF.
*    IF l_wcinfo = c_y.
** Use work centre info.
*      LOOP AT i_crco_info INTO wa_crco_info
*         WHERE begda <= wa_plpo1-datuv AND
*               endda >= wa_plpo1-datuv.
*        CHECK NOT wa_crco_info-lstar_ref IS INITIAL.
*        CASE wa_crco_info-lanum.
** Only put the activity type in if there is a std value entered
*          WHEN 1.
*            IF wa_plpo1-vgw01 NE 0.
*              wa_plpo1-lar01 = wa_crco_info-lstar.
*            ENDIF.
*          WHEN 2.
*            IF wa_plpo1-vgw02 NE 0.
*              wa_plpo1-lar02 = wa_crco_info-lstar.
*            ENDIF.
*          WHEN 3.
*            IF wa_plpo1-vgw03 NE 0.
*              wa_plpo1-lar03 = wa_crco_info-lstar.
*            ENDIF.
*          WHEN 4.
*            IF wa_plpo1-vgw04 NE 0.
*              wa_plpo1-lar04 = wa_crco_info-lstar.
*            ENDIF.
*          WHEN 5.
*            IF wa_plpo1-vgw05 NE 0.
*              wa_plpo1-lar05 = wa_crco_info-lstar.
*            ENDIF.
*          WHEN 6.
*            IF wa_plpo1-vgw06 NE 0.
*              wa_plpo1-lar06 = wa_crco_info-lstar.
*            ENDIF.
*        ENDCASE.
*      ENDLOOP.
*    ENDIF.
*
*  ENDIF.
*
*ENDFORM.                    " GET_STDS
**&---------------------------------------------------------------------
**
**&      Form  get_confirmation_details
**&---------------------------------------------------------------------
**
**       text
**----------------------------------------------------------------------
**
**----------------------------------------------------------------------
**
*FORM get_confirmation_details.
*
*  DATA:  l_last_ism01 TYPE ru_ismng,
*         l_last_ism02 TYPE ru_ismng,
*         l_last_ism03 TYPE ru_ismng,
*         l_last_ism04 TYPE ru_ismng,
*         l_last_ism05 TYPE ru_ismng,
*         l_last_ism06 TYPE ru_ismng.
*
*  LOOP AT i_ord_conf1 INTO wa_ord_conf1
*             WHERE rueck = wa_ordops-rueck.
*    IF wa_ord_conf1-stokz IS INITIAL.
*      l_last_ism01 = l_last_ism01 + wa_ord_conf1-ism01.
*      l_last_ism02 = l_last_ism02 + wa_ord_conf1-ism02.
*      l_last_ism03 = l_last_ism03 + wa_ord_conf1-ism03.
*      l_last_ism04 = l_last_ism04 + wa_ord_conf1-ism04.
*      l_last_ism05 = l_last_ism05 + wa_ord_conf1-ism05.
*      l_last_ism06 = l_last_ism06 + wa_ord_conf1-ism06.
*    ELSE.
*      l_last_ism01 = l_last_ism01 - wa_ord_conf1-ism01.
*      l_last_ism02 = l_last_ism02 - wa_ord_conf1-ism02.
*      l_last_ism03 = l_last_ism03 - wa_ord_conf1-ism03.
*      l_last_ism04 = l_last_ism04 - wa_ord_conf1-ism04.
*      l_last_ism05 = l_last_ism05 - wa_ord_conf1-ism05.
*      l_last_ism06 = l_last_ism06 - wa_ord_conf1-ism06.
*    ENDIF.
*    CLEAR : wa_ord_conf1.
*  ENDLOOP.
*
*  MOVE l_last_ism01 TO wa_ord_conf1-ism01.
*  MOVE l_last_ism02 TO wa_ord_conf1-ism02.
*  MOVE l_last_ism03 TO wa_ord_conf1-ism03.
*  MOVE l_last_ism04 TO wa_ord_conf1-ism04.
*  MOVE l_last_ism05 TO wa_ord_conf1-ism05.
*  MOVE l_last_ism06 TO wa_ord_conf1-ism06.
*
*
*ENDFORM.                    " get_confirmation_details
**&---------------------------------------------------------------------
**
**&      Form  activity_cost_report
**&---------------------------------------------------------------------
**
**       text
**----------------------------------------------------------------------
**
**      -->P_I_PLPO1_LAR01  text
**      -->P_I_ORD_CONF1_ISM01  text
**      -->P_struct_activity_ACTI1  text
**      -->P_ISM01_VAR  text
**----------------------------------------------------------------------
**
*FORM activity_cost_report USING fp_p_i_plpo1_lar01     TYPE lstar
*                                fp_p_i_ord_conf1_ism01 TYPE ru_ismng
*                             fp_p_struct_activity_acti1 TYPE co_smng13
*                                fp_p_ism01_var TYPE ru_ismng.
*  DATA: l_ltext TYPE ktext,
*        l_kokrs TYPE kokrs,
*        l_kostl TYPE kostl,
*        l_objnr TYPE j_objnr,
*        l_tkg001 TYPE tkgxxx,
*        l_tke001 TYPE tkexxx,
*        l_std(8) TYPE p DECIMALS 2,
*        l_act(8) TYPE p DECIMALS 2,
*        l_var(8) TYPE p DECIMALS 2.
*
*  SELECT ltext FROM  cslt INTO l_ltext
*     WHERE  spras       = sy-langu
*     AND    kokrs       = p_kokrs
*     AND    lstar       = fp_p_i_plpo1_lar01.
*  ENDSELECT.
*
*  IF sy-subrc = 0.
**Not required to handle
*  ENDIF.
*
*  IF rb_fiscl IS INITIAL.
*
*    CLEAR  wa_nodestab.
*    wa_nodestab-id     = c_3_1.
*    wa_nodestab-tlevel =  c_4.
*    wa_nodestab-parent = c_3_2.
*
*    wa_nodestab-text    = wa_ordops-vornr.
*    wa_nodestab-tlength = c_4.
*
*    wa_nodestab-text1    = l_ltext.
*    wa_nodestab-tlength1 = c_44.
*
*    MOVE fp_p_i_ord_conf1_ism01 TO wa_nodestab-text2(20).
*    wa_nodestab-tlength2 = c_20.
*
*    MOVE fp_p_struct_activity_acti1 TO wa_nodestab-text3(20).
*    wa_nodestab-tlength3 = c_20.
*
*    MOVE fp_p_ism01_var TO wa_nodestab-text4(20).
*    wa_nodestab-tlength4 = c_20.
*
*  ELSE.
*
*    SELECT kokrs kostl
*    FROM crco UP TO 1 ROWS
*    INTO (l_kokrs, l_kostl)
*    WHERE objty = c_a
*      AND objid = wa_ordops-arbid
*      AND lstar = fp_p_i_plpo1_lar01.
*    ENDSELECT.
*
*    IF sy-subrc = 0.
**Not required to handle
*    ENDIF.
*
*    SELECT SINGLE objnr INTO l_objnr
*    FROM cssl
*    WHERE kokrs = l_kokrs
*      AND kostl = l_kostl
*      AND lstar = fp_p_i_plpo1_lar01
*      AND gjahr = sy-datum+0(4).
*
*    IF sy-subrc = 0.
**Not required to handle
*    ENDIF.
*
*    SELECT tkg001 tke001 INTO (l_tkg001, l_tke001)
*    FROM cost
*    WHERE objnr = l_objnr
*      AND gjahr = sy-datum+0(4)
*      AND versn = c_000.
*    ENDSELECT.
*
*    IF sy-subrc = 0.
**Not required to handle
*    ENDIF.
*
*    CLEAR: l_act, l_std, l_var.
*** The following were changed to take into account the unit
*** price factor.
*    l_act = ( fp_p_i_ord_conf1_ism01 * l_tkg001 ) / l_tke001.
*    l_std = ( fp_p_struct_activity_acti1 * l_tkg001 ) / l_tke001.
*    l_var = ( fp_p_ism01_var * l_tkg001 ) / l_tke001.
*
*    CLEAR  wa_nodestab.
*    wa_nodestab-id     = c_3_1.
*    wa_nodestab-tlevel =  c_4.
*    wa_nodestab-parent = c_3_2.
*
*    wa_nodestab-text    = wa_ordops-vornr.
*    wa_nodestab-tlength = c_4.
*
*    wa_nodestab-text1    = l_ltext.
*    wa_nodestab-tlength1 = c_44.
*
*    MOVE l_act TO wa_nodestab-text2(20).
*    wa_nodestab-tlength2 = c_20.
*
*    MOVE l_std TO wa_nodestab-text3(20).
*    wa_nodestab-tlength3 = c_20.
*
*    MOVE l_var TO wa_nodestab-text4(20).
*    wa_nodestab-tlength4 = c_20.
*
*  ENDIF.
*
*  IF flg_color = c_x.
*    CLEAR flg_color.
*    wa_nodestab-tcolor  = c_3.
*    wa_nodestab-tcolor1 = c_3.
*    wa_nodestab-tcolor2 = c_3.
*    wa_nodestab-tcolor3 = c_3.
*    wa_nodestab-tcolor4 = c_3.
*  ELSE.
*    flg_color = c_x.
*    wa_nodestab-tcolor  = c_2.
*    wa_nodestab-tcolor1 = c_2.
*    wa_nodestab-tcolor2 = c_2.
*    wa_nodestab-tcolor3 = c_2.
*    wa_nodestab-tcolor4 = c_2.
*  ENDIF.
*
*  APPEND wa_nodestab TO i_nodestab.
*
*
*ENDFORM.                    " activity_cost_report
**&---------------------------------------------------------------------
**
**&      Form  uom_convert
**&---------------------------------------------------------------------
**
**       text
**----------------------------------------------------------------------
**
**      -->P_I_ORDMATS_MATNR  text
**      -->P_I_ORDMATS_MENGE  text
**      -->P_I_ORDMATS_AMEIN  text
**      -->P_L_AQTY  text
**----------------------------------------------------------------------
**
*FORM uom_convert USING    fp_p_i_ordmats_matnr TYPE matnr
*                          fp_p_i_ordmats_menge TYPE menge_d
*                          fp_p_i_ordmats_amein TYPE meins
*                          fp_p_l_aqty          TYPE menge_d.
*
**Added for WIRR
*  DATA : struct_mara TYPE mara,
*         struct_t006 TYPE t006.
*  DATA: v_menge TYPE menge_d.
*
*  CONSTANTS : c_halb TYPE mtart VALUE 'HALB',
*              c_fert TYPE mtart VALUE 'FERT',
*              c_kgm  TYPE msehi VALUE 'KGM'.
*
*****************************************
** Need some clarification on this form *
*****************************************
*
** If the material is type FERT or HALB then use the net weight field
** from the material master. Otherwise use the alt uom for KG.
*  SELECT SINGLE * FROM mara
**Added for WIRR
*   INTO struct_mara
**Added for WIRR
*
*   WHERE matnr = fp_p_i_ordmats_matnr.
*
*  IF ( struct_mara-mtart = c_fert
*             OR struct_mara-mtart = c_halb )
*     AND NOT ( struct_mara-ntgew IS INITIAL ).
**************MOD-002*************************************************
**
*    CLEAR: v_menge.
*    IF struct_mara-gewei NE 'KG'.
*      IF struct_mara-gewei = 'G'.
*        CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
*          EXPORTING
*            i_matnr              = fp_p_i_ordmats_matnr
*            i_in_me              = fp_p_i_ordmats_amein
*            i_out_me             = struct_mara-meins
*            i_menge              = fp_p_i_ordmats_menge
*          IMPORTING
*            e_menge              = v_menge
*          EXCEPTIONS
*            error_in_application = 1
*            error                = 2
*            OTHERS               = 3.
*        IF sy-subrc = 0.
*          fp_p_l_aqty =
*              v_menge * ( struct_mara-ntgew / 1000 ).
*        ENDIF.
*      ENDIF.
*    ELSE.
*************MOD-002**************************************************
**
*************MOD-003**************************************************
*      IF struct_mara-meins NE fp_p_i_ordmats_amein.
*        CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
*          EXPORTING
*            i_matnr              = fp_p_i_ordmats_matnr
*            i_in_me              = fp_p_i_ordmats_amein
*            i_out_me             = struct_mara-meins
*            i_menge              = fp_p_i_ordmats_menge
*          IMPORTING
*            e_menge              = fp_p_i_ordmats_menge
*          EXCEPTIONS
*            error_in_application = 1
*            error                = 2
*            OTHERS               = 3.
*        IF sy-subrc = 0.
*          fp_p_l_aqty = fp_p_i_ordmats_menge * struct_mara-ntgew.
*        ENDIF.
*      ELSE.
*        fp_p_l_aqty = fp_p_i_ordmats_menge * struct_mara-ntgew.
*      ENDIF.
************MOD-003***************************************************
*    ENDIF.
*  ELSE.
** Get the isocode for kgm
*    SELECT SINGLE * FROM t006
*     INTO struct_t006
*     WHERE msehi = c_kgm.
*
*    IF fp_p_i_ordmats_amein = struct_t006-msehi.
*      MOVE fp_p_i_ordmats_menge TO fp_p_l_aqty.
*    ELSE.
*      CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'
*        EXPORTING
*          kzmeinh              = c_x
*          input                = fp_p_i_ordmats_menge
*          matnr                = fp_p_i_ordmats_matnr
*          meinh                = struct_t006-msehi
*        IMPORTING
*          output               = fp_p_l_aqty
*        EXCEPTIONS
*          conversion_not_found = 1
*          input_invalid        = 2
*          material_not_found   = 3
*          meinh_not_found      = 4
*          meins_missing        = 5
*          no_meinh             = 6
*          output_invalid       = 7
*          overflow             = 8
*          OTHERS               = 9.
*
******************
*      IF sy-subrc NE 0.
*        fp_p_l_aqty = 0.
*      ENDIF.
*
*
******************
*    ENDIF.
*  ENDIF.
*
*ENDFORM.                    " uom_convert
**&---------------------------------------------------------------------
**
**&      Form  STD_PERCENTAGE_CALC
**&---------------------------------------------------------------------
**
**       text
**----------------------------------------------------------------------
**
**      -->P_L_AQTY  text
**      -->P_L_SQTY  text
**      -->P_L_PCENT  text
**----------------------------------------------------------------------
**
*FORM std_percentage_calc USING    fp_l_aqty  TYPE menge_d
*                                  fp_l_sqty  TYPE menge_d
*                                  fp_l_pcent TYPE any.
*
*  CONSTANTS: c_percent_p TYPE stprs VALUE '999.99',
*             c_percent_n TYPE stprs VALUE '-999.99'.
*
*  DATA: l_tcent(10) TYPE p DECIMALS 5,
*        l_pecent(3) TYPE p DECIMALS 2.
*
*  CLEAR: l_tcent, l_pecent.
*  IF fp_l_aqty NE 0 AND fp_l_sqty NE 0.
*    l_tcent = ( ( fp_l_sqty - fp_l_aqty ) / fp_l_sqty ) * c_100.
*  ELSEIF fp_l_aqty EQ 0 AND fp_l_sqty EQ 0.
*    l_tcent = 0.
*  ELSE.
*    MOVE c_100 TO l_tcent.
*  ENDIF.
*  IF l_tcent GT c_percent_p.
*    MOVE c_percent_p TO l_pecent.
*  ELSEIF l_tcent LT c_percent_n.
*    MOVE c_percent_n TO l_pecent.
*  ELSE.
*    MOVE l_tcent TO l_pecent.
*  ENDIF.
*** Add a calculation to convert by-product percentages to the correct
*** sign.
*  IF fp_l_sqty < 0.
*    l_pecent = l_pecent * -1.
*  ENDIF.
*  fp_l_pcent = l_pecent.
*
*ENDFORM.                    " STD_PERCENTAGE_CALC
*
**&---------------------------------------------------------------------
**
**&      Form  DISPLAY
**&---------------------------------------------------------------------
**
**       text
**----------------------------------------------------------------------
**
**----------------------------------------------------------------------
**
*FORM display.
*
*  CASE c_x.
*    WHEN rb_summ.
*      PERFORM display_summary_report.
*    WHEN rb_detl.
*      PERFORM display_detail_report.
*    WHEN rb_phase.
*      PERFORM display_phase_report.
*  ENDCASE.
*  PERFORM list_display.
*
*ENDFORM.                    " DISPLAY
**&---------------------------------------------------------------------
**
**&      Form  plant_effic
**&---------------------------------------------------------------------
**
**       text
**----------------------------------------------------------------------
**
**      -->P_I_PRO_ORDERS_RUECK  text
**      -->P_I_PRO_ORDERS_PLNTY  text
**      -->P_I_PRO_ORDERS_PLNNR  text
**      -->P_I_PRO_ORDERS_PLNKN  text
**      -->P_I_PRO_ORDERS_ZAEHL  text
**      <--P_V_plant_effic  text
**----------------------------------------------------------------------
**
*FORM plant_effic USING    fp_p_plnty          TYPE plnty
*                          fp_p_plnnr          TYPE plnnr
*                          fp_p_plnkn          TYPE plnkn
*                          fp_p_zaehl          TYPE cim_count
*                 CHANGING fp_v_plant_effic    TYPE any.
*
*  FIELD-SYMBOLS: <fs_ism> TYPE ANY,
*                 <fs_vgw> TYPE ANY.
*
*  DATA:  l_last_ism01 TYPE ru_ismng,
*         l_last_ism02 TYPE ru_ismng,
*         l_last_ism03 TYPE ru_ismng,
*         l_last_ism04 TYPE ru_ismng,
*         l_last_ism05 TYPE ru_ismng,
*         l_last_ism06 TYPE ru_ismng,
*         l_pqty       TYPE menge_d,
*         l_real_effic(8)   TYPE p DECIMALS 4,
*         l_should_effic(8) TYPE p DECIMALS 4.
*
*  PERFORM get_stds_main USING fp_p_plnty fp_p_plnnr fp_p_plnkn
*                              fp_p_zaehl.
*
*
*  LOOP AT i_ord_conf INTO wa_ord_conf
*          WHERE rueck = wa_ordops-rueck.
*    IF wa_ord_conf1-stokz IS INITIAL.
*      l_last_ism01 = l_last_ism01 + wa_ord_conf-ism01.
*      l_last_ism02 = l_last_ism02 + wa_ord_conf-ism02.
*      l_last_ism03 = l_last_ism03 + wa_ord_conf-ism03.
*      l_last_ism04 = l_last_ism04 + wa_ord_conf-ism04.
*      l_last_ism05 = l_last_ism05 + wa_ord_conf-ism05.
*      l_last_ism06 = l_last_ism06 + wa_ord_conf-ism06.
*    ELSE.
*      l_last_ism01 = l_last_ism01 - wa_ord_conf-ism01.
*      l_last_ism02 = l_last_ism02 - wa_ord_conf-ism02.
*      l_last_ism03 = l_last_ism03 - wa_ord_conf-ism03.
*      l_last_ism04 = l_last_ism04 - wa_ord_conf-ism04.
*      l_last_ism05 = l_last_ism05 - wa_ord_conf-ism05.
*      l_last_ism06 = l_last_ism06 - wa_ord_conf-ism06.
*    ENDIF.
*
*    CLEAR : wa_ord_conf.
*  ENDLOOP.
*
*  MOVE l_last_ism01 TO wa_ord_conf-ism01.
*  MOVE l_last_ism02 TO wa_ord_conf-ism02.
*  MOVE l_last_ism03 TO wa_ord_conf-ism03.
*  MOVE l_last_ism04 TO wa_ord_conf-ism04.
*  MOVE l_last_ism05 TO wa_ord_conf-ism05.
*  MOVE l_last_ism06 TO wa_ord_conf-ism06.
*
*  ASSIGN c_0 TO <fs_ism>.
*  ASSIGN c_0 TO <fs_vgw>.
*
*  IF wa_plpo-lar01 EQ p_machs.
*    ASSIGN wa_ord_conf-ism01 TO <fs_ism>.
*    ASSIGN wa_plpo-vgw01 TO <fs_vgw>.
*  ENDIF.
*  IF wa_plpo-lar02 EQ p_machs.
*    ASSIGN wa_ord_conf-ism02 TO <fs_ism>.
*    ASSIGN wa_plpo-vgw02 TO <fs_vgw>.
*  ENDIF.
*  IF wa_plpo-lar03 EQ p_machs.
*    ASSIGN wa_ord_conf-ism03 TO <fs_ism>.
*    ASSIGN wa_plpo-vgw03 TO <fs_vgw>.
*  ENDIF.
*  IF wa_plpo-lar04 EQ p_machs.
*    ASSIGN wa_ord_conf-ism04 TO <fs_ism>.
*    ASSIGN wa_plpo-vgw04 TO <fs_vgw>.
*  ENDIF.
*  IF wa_plpo-lar05 EQ p_machs.
*    ASSIGN wa_ord_conf-ism05 TO <fs_ism>.
*    ASSIGN wa_plpo-vgw05 TO <fs_vgw>.
*  ENDIF.
*  IF wa_plpo-lar06 EQ p_machs.
*    ASSIGN wa_ord_conf-ism06 TO <fs_ism>.
*    ASSIGN wa_plpo-vgw06 TO <fs_vgw>.
*  ENDIF.
*
*  CLEAR l_pqty.
*  IF NOT ( rb_prod IS INITIAL ).
*    l_pqty = wa_pro_orders-menge.
*  ELSE.
*    l_pqty = wa_pro_orders-lmnga.
*  ENDIF.
*
*  IF <fs_ism> GT c_0.
**  IF NOT <FS_ISM> IS INITIAL.
*    l_real_effic = ( l_pqty / <fs_ism> ).
*  ELSE.
*    MOVE 0 TO l_real_effic.
*  ENDIF.
*  IF <fs_vgw> GT c_0.
**  IF NOT <FS_VGW> IS INITIAL.
*    l_should_effic = ( wa_plpo-bmsch / <fs_vgw> ).
*  ELSE.
*    MOVE 0 TO l_should_effic.
*  ENDIF.
*  IF l_should_effic GT c_0.
*    v_plant_effic = ( l_real_effic / l_should_effic ) * c_100.
*  ELSE.
*    MOVE 0 TO fp_v_plant_effic.
*  ENDIF.
*
*ENDFORM.                    " plant_effic
**&---------------------------------------------------------------------
**
**&      Form  get_stds_main
**&---------------------------------------------------------------------
**
**       text
**----------------------------------------------------------------------
**
**      -->P_PLNTY  text
**      -->P_PLNNR  text
**      -->P_PLNKN  text
**      -->P_ZAEHL  text
**----------------------------------------------------------------------
**
*FORM get_stds_main USING    fp_p_plnty TYPE plnty
*                            fp_p_plnnr TYPE plnnr
*                            fp_p_plnkn TYPE plnkn
*                            fp_p_zaehl TYPE cim_count.
*  TYPES:   BEGIN OF ty_crco_info,
*    objty     TYPE cr_objty,
*    objid     TYPE cr_objid,
*    laset     TYPE cr_laset,
*    endda     TYPE enddatum,
*    lanum     TYPE cr_lanum,
*    begda     TYPE begdatum,
*    lstar_ref TYPE ap_kzref,
*    lstar     TYPE lstar,
*  END OF ty_crco_info.
*
*  DATA : i_crco_info TYPE STANDARD TABLE OF ty_crco_info,
*         wa_crco_info TYPE ty_crco_info.
*  DATA: l_wcinfo TYPE c,
*        l_datuv TYPE plpo-datuv,
*        lc_objty TYPE plpo-objty VALUE 'A'.
*
*  READ TABLE i_plpo INTO wa_plpo WITH KEY plnty = fp_p_plnty
*                             plnnr = fp_p_plnnr
*                             plnkn = fp_p_plnkn
*                             zaehl = fp_p_zaehl.
*  IF sy-subrc = 0.
*
*    IF ( wa_plpo-lar01 IS INITIAL AND NOT ( wa_plpo-vgw01 = 0 ) ) OR
*       ( wa_plpo-lar02 IS INITIAL AND NOT ( wa_plpo-vgw02 = 0 ) ) OR
*       ( wa_plpo-lar03 IS INITIAL AND NOT ( wa_plpo-vgw03 = 0 ) ) OR
*       ( wa_plpo-lar04 IS INITIAL AND NOT ( wa_plpo-vgw04 = 0 ) ) OR
*       ( wa_plpo-lar05 IS INITIAL AND NOT ( wa_plpo-vgw05 = 0 ) ) OR
*       ( wa_plpo-lar06 IS INITIAL AND NOT ( wa_plpo-vgw06 = 0 ) ).
*      REFRESH: i_crco_info.
** Check the work centre is on the phase, if not go to the operation
*      IF wa_plpo-arbid IS INITIAL.
*        SELECT datuv arbid objty
*          INTO (l_datuv,wa_plpo-arbid,wa_plpo-objty)
*          FROM plpo
*         WHERE plnty = fp_p_plnty
*           AND plnnr = fp_p_plnnr
*           AND plnkn = wa_plpo-pvzkn
*           AND datuv <= sy-datum
*          ORDER BY datuv DESCENDING.
*          EXIT.
*        ENDSELECT.
*
*        IF sy-subrc = 0.
**Not required to handle
*        ENDIF.
*
*      ENDIF.
** Default to work centre object if it's blank
*      IF wa_plpo-objty IS INITIAL.
*        wa_plpo-objty = lc_objty.
*      ENDIF.
** Get the work centre activity info
*      SELECT objty objid laset endda lanum begda lstar_ref lstar
*      INTO TABLE i_crco_info
*        FROM crco
*       WHERE objty = wa_plpo-objty
*         AND objid = wa_plpo-arbid
*         AND laset = 1.
**     order by primary key.
*
*      IF sy-subrc = 0.
**Not required to handle
*      ENDIF.
*
*      l_wcinfo = c_y.
*    ENDIF.
*    IF l_wcinfo = c_y.
** Use work centre info.
*      LOOP AT i_crco_info INTO wa_crco_info
*         WHERE begda <= wa_plpo-datuv AND
*               endda >= wa_plpo-datuv.
*        CHECK NOT wa_crco_info-lstar_ref IS INITIAL.
*        CASE wa_crco_info-lanum.
** Only put the activity type in if there is a std value entered
*          WHEN 1.
*            IF wa_plpo-vgw01 NE 0.
*              wa_plpo-lar01 = wa_crco_info-lstar.
*            ENDIF.
*          WHEN 2.
*            IF wa_plpo-vgw02 NE 0.
*              wa_plpo-lar02 = wa_crco_info-lstar.
*            ENDIF.
*          WHEN 3.
*            IF wa_plpo-vgw03 NE 0.
*              wa_plpo-lar03 = wa_crco_info-lstar.
*            ENDIF.
*          WHEN 4.
*            IF wa_plpo-vgw04 NE 0.
*              wa_plpo-lar04 = wa_crco_info-lstar.
*            ENDIF.
*          WHEN 5.
*            IF wa_plpo-vgw05 NE 0.
*              wa_plpo-lar05 = wa_crco_info-lstar.
*            ENDIF.
*          WHEN 6.
*            IF wa_plpo-vgw06 NE 0.
*              wa_plpo-lar06 = wa_crco_info-lstar.
*            ENDIF.
*        ENDCASE.
*      ENDLOOP.
*    ENDIF.
*
*  ENDIF.
*
*ENDFORM.                    " get_stds_main
**&---------------------------------------------------------------------
**
**&      Form  get_confirmation_qty
**&---------------------------------------------------------------------
**
**       text
**----------------------------------------------------------------------
**
**      -->P_I_ORDOPS_RUECK  text
**      -->P_I_PRO_ORDERS_PLNBEZ  text
**      -->P_L_PRDQTY  text
**      -->P_L_CFUOM  text
**----------------------------------------------------------------------
**
*FORM get_confirmation_qty USING    fp_p_i_ordops_rueck TYPE co_rueck
*                                   fp_p_l_prdqty       TYPE menge_d
*                                   fp_p_l_cfuom        TYPE meins.
*  DATA: l_lmnga TYPE ru_lmnga,
*        l_gmnga TYPE ru_gmnga.
*
***********MOD-002**************************************
*  SELECT aufnr rueck gmnga lmnga gmein meinh
*      meilr stokz rueck_mst
*  FROM afru INTO TABLE itab_afru
*  FOR ALL ENTRIES IN i_pro_orders
*  WHERE aufnr = i_pro_orders-aufnr.
*
*  SORT itab_afru BY aufnr rueck .
***********MOD-002***************************************
*  IF NOT itab_afru[] IS INITIAL.
*    CLEAR: l_lmnga, l_gmnga.
*    LOOP AT itab_afru INTO wa_afru WHERE rueck = fp_p_i_ordops_rueck.
**       IF  ( wa_afru-rueck_mst IS INITIAL ) AND
**            ( wa_afru-lmnga NE 0           ) AND
**        NOT ( wa_afru-meilr IS INITIAL     ).
*      IF wa_afru-stokz IS INITIAL.
*        l_lmnga = l_lmnga + wa_afru-lmnga.
*        l_gmnga = l_gmnga + wa_afru-gmnga.
*      ELSE.
*        l_lmnga = l_lmnga - wa_afru-lmnga.
*        l_gmnga = l_gmnga - wa_afru-gmnga.
*      ENDIF.
**        ENDIF.
*    ENDLOOP.
*    IF wa_afru-meinh NE wa_afru-gmein.
*      fp_p_l_prdqty = l_lmnga.
*      fp_p_l_cfuom  = wa_afru-gmein.
*    ELSE.
*      fp_p_l_prdqty = l_gmnga.
*      fp_p_l_cfuom  = wa_afru-meinh.
*    ENDIF.
*  ENDIF.
*ENDFORM.                    " get_confirmation_qty
**&---------------------------------------------------------------------
**
**&      Form  MATERIAL_HEADER
**&---------------------------------------------------------------------
**
**       text
**----------------------------------------------------------------------
**
**  -->  p1        text
**  <--  p2        text
**----------------------------------------------------------------------
**
*FORM material_header.
*
*  wa_nodestab-text    = 'Material'(058).
*  wa_nodestab-tlength = c_22.
*  wa_nodestab-tcolor  = c_4.
*  wa_nodestab-propfaw = c_x.
*
*  wa_nodestab-text1    = 'Description'(059).
*  wa_nodestab-tlength1 = c_30.
*  wa_nodestab-tcolor1  = c_4.
*
*  IF rb_fiscl = c_x.
*    CONCATENATE 'Actual Usage'(040) v_waers
*    INTO wa_nodestab-text2 SEPARATED BY space.
*  ELSE.
*    wa_nodestab-text2  = 'Actual Usage'(040).
*  ENDIF.
*  wa_nodestab-tlength2 = c_20.
*  wa_nodestab-tcolor2  = c_4.
*
*  IF rb_fiscl = c_x.
*    CONCATENATE 'Standard Usage'(041) v_waers
*    INTO wa_nodestab-text3 SEPARATED BY space.
*  ELSE.
*    wa_nodestab-text3  = 'Standard Usage'(041).
*  ENDIF.
*  wa_nodestab-tlength3 = c_20.
*  wa_nodestab-tcolor3  = c_4.
*
*  wa_nodestab-text4    = 'Var'(060).
*  wa_nodestab-tlength4 = c_19.
*  wa_nodestab-tcolor4  = c_4.
*
**  IF rb_fiscl = c_x.
*  CONCATENATE 'Variance'(061) v_waers
*  INTO wa_nodestab-text5 SEPARATED BY space.
**  ELSE.
**    wa_nodestab-text5  = 'Variance'(061).
**  ENDIF.
*  wa_nodestab-tlength5 = c_15.
*  wa_nodestab-tcolor5  = c_4.
*
*  APPEND wa_nodestab TO i_nodestab.
*  CLEAR : wa_nodestab.
*ENDFORM.                    " MATERIAL_HEADER
**&---------------------------------------------------------------------
**
**&      Form  sum_activity_costs
**&---------------------------------------------------------------------
**
**       text
**----------------------------------------------------------------------
**
**      -->P_I_PLPO1_LAR01  text
**      -->P_I_ORD_CONF1_ISM01  text
**      -->P_struct_activity_ACTI1  text
**      -->P_ISM01_VAR  text
**----------------------------------------------------------------------
**
*FORM sum_activity_costs USING  fp_p_i_plpo1_lar01         TYPE lstar
*                               fp_p_i_ord_conf1_ism01     TYPE ru_ismng
*fp_p_struct_activity_acti1 TYPE co_smng13
*fp_p_ism01_var             TYPE ru_ismng.
*  DATA: l_kokrs TYPE kokrs,
*        l_kostl TYPE kostl,
*        l_objnr TYPE j_objnr,
*        l_tkg001 TYPE tkgxxx,
*        l_tke001 TYPE tkexxx,
*        l_std(8) TYPE p DECIMALS 2,
*        l_act(8) TYPE p DECIMALS 2,
*        l_var(8) TYPE p DECIMALS 2.
*
*  SELECT kokrs kostl
*  FROM crco UP TO 1 ROWS
*  INTO (l_kokrs, l_kostl)
*  WHERE objty = c_objtyp
*    AND objid = wa_ordops-arbid
*    AND lstar = fp_p_i_plpo1_lar01.
*  ENDSELECT.
*
*  IF sy-subrc = 0.
**Not required to handle
*  ENDIF.
*
*  SELECT SINGLE objnr INTO l_objnr
*  FROM cssl
*  WHERE kokrs = l_kokrs
*    AND kostl = l_kostl
*    AND lstar = fp_p_i_plpo1_lar01
*    AND gjahr = sy-datum+0(4).
*
*  IF sy-subrc = 0.
**Not required to handle
*  ENDIF.
*
*  SELECT tkg001 tke001 INTO (l_tkg001, l_tke001)
*  FROM cost
*  WHERE objnr = l_objnr
*    AND gjahr = sy-datum+0(4)
*    AND versn = c_000.
*  ENDSELECT.
*
*  IF sy-subrc = 0.
**Not required to handle
*  ENDIF.
*
*  CLEAR: l_act, l_std, l_var.
*  l_act = ( fp_p_i_ord_conf1_ism01 * l_tkg001 ) / l_tke001.
*  l_std = ( fp_p_struct_activity_acti1 * l_tkg001 ) / l_tke001.
*  l_var = ( fp_p_ism01_var * l_tkg001 ) / l_tke001.
*
*  CLEAR wa_sum_activity.
*
*  LOOP AT i_sum_activity INTO wa_sum_activity
*        WHERE lar = fp_p_i_plpo1_lar01.
*    wa_sum_activity-afru_ism = wa_sum_activity-afru_ism
*                            + fp_p_i_ord_conf1_ism01.
*    wa_sum_activity-ism_should = wa_sum_activity-ism_should
*                              + fp_p_struct_activity_acti1.
*    wa_sum_activity-ism_var = wa_sum_activity-ism_var
*                           + fp_p_ism01_var.
*    wa_sum_activity-coact = wa_sum_activity-coact + l_act.
*    wa_sum_activity-costd = wa_sum_activity-costd + l_std.
*    wa_sum_activity-covar = wa_sum_activity-covar + l_var.
*    MODIFY i_sum_activity FROM wa_sum_activity.
*    CLEAR : wa_sum_activity.
*  ENDLOOP.
*
*  IF sy-subrc NE 0.
*    MOVE fp_p_i_plpo1_lar01      TO wa_sum_activity-lar.
*    MOVE fp_p_i_ord_conf1_ism01  TO wa_sum_activity-afru_ism.
*    MOVE fp_p_struct_activity_acti1 TO wa_sum_activity-ism_should.
*    MOVE fp_p_ism01_var          TO wa_sum_activity-ism_var.
*    wa_sum_activity-coact = l_act.
*    wa_sum_activity-costd = l_std.
*    wa_sum_activity-covar = l_var.
*    APPEND wa_sum_activity TO i_sum_activity.
*    CLEAR : wa_sum_activity.
*  ENDIF.
*
*ENDFORM.                    " sum_activity_costs
**&---------------------------------------------------------------------
**
**&      Form  SUMMARY_MATERIALS
**&---------------------------------------------------------------------
**
**       text
**----------------------------------------------------------------------
**
**----------------------------------------------------------------------
**
*FORM summary_materials.
*
** Sum Ingredient Tots
*  CLEAR wa_sum_ordmats.
*  LOOP AT i_sum_ordmats INTO wa_sum_ordmats
*          WHERE matnr = wa_ordmats-matnr.
*    wa_sum_ordmats-num    = wa_sum_ordmats-num + c_1.
*    wa_sum_ordmats-menge  = wa_sum_ordmats-menge + wa_ordmats-menge.
*    wa_sum_ordmats-stdqy   = wa_sum_ordmats-stdqy + wa_ordmats-stdqy.
*    wa_sum_ordmats-zloss  = wa_sum_ordmats-zloss + wa_ordmats-zloss.
*    wa_sum_ordmats-amein  = wa_ordmats-amein.
*    wa_sum_ordmats-meins  = wa_ordmats-meins.
*    wa_sum_ordmats-stprs  = wa_ordmats-stprs.
*    wa_sum_ordmats-peinh  = wa_ordmats-peinh.
*    MODIFY i_sum_ordmats FROM wa_sum_ordmats.
*    CLEAR : wa_sum_ordmats.
*  ENDLOOP.
*  IF sy-subrc NE 0.
*    MOVE wa_ordmats-matnr TO wa_sum_ordmats-matnr.
*    MOVE 1               TO wa_sum_ordmats-num.
*    MOVE wa_ordmats-menge TO wa_sum_ordmats-menge.
*    MOVE wa_ordmats-stdqy TO wa_sum_ordmats-stdqy.
*    MOVE wa_ordmats-zloss TO wa_sum_ordmats-zloss.
*    wa_sum_ordmats-amein  = wa_ordmats-amein.
*    wa_sum_ordmats-meins  = wa_ordmats-meins.
*    wa_sum_ordmats-stprs  = wa_ordmats-stprs.
*    wa_sum_ordmats-peinh  = wa_ordmats-peinh.
*    APPEND wa_sum_ordmats TO i_sum_ordmats.
*    CLEAR : wa_sum_ordmats.
*  ENDIF.
*
*ENDFORM.                    " SUMMARY_MATERIALS
**&---------------------------------------------------------------------
**
**&      Form  get_confirmation_qty_new
**&---------------------------------------------------------------------
**
**       text
**----------------------------------------------------------------------
**
**      -->P_WA_PRO_ORDERS_RUECK  text
**      -->P_WA_PRO_ORDERS_PLNBEZ  text
**      -->P_WA_PRO_ORDERS_LMNGA  text
**      -->P_WA_PRO_ORDERS_CFUOM  text
**----------------------------------------------------------------------
**
*FORM get_confirmation_qty_new USING p_lmnga TYPE ru_lmnga
*                                    p_cfuom TYPE meins.
*
****************************************************
**USING
**                  P_RUECK TYPE CO_RUECK
**                  p_aufnr type aufnr
**                  P_LMNGA TYPE RU_LMNGA
**                  P_CFUOM TYPE MEINS
**                  p_aufpl type CO_AUFPL
**                  p_vornr type vornr
**                  p_aplzl type CO_APLZL.
****************************************************
*  DATA: last_lmnga LIKE afru-lmnga,
*        last_gmnga TYPE afru-gmnga.
*
*  CLEAR: last_lmnga, last_gmnga.
*  CLEAR:i_afru, wa_afru.
*
*
*
*
**    Check this record. If there is no link to another confirmation and
**      a quantity has been confirmed and it is a milestone confirmation
**               then we want to select all of the confirmations for it.
*  LOOP AT i_afru1 INTO wa_afru1.
**                   check WA_afru-rueck_mst is initial.
*    CHECK wa_afru1-lmnga NE 0.
**                    check not ( WA_afru-meilr is initial ).
*    IF wa_afru1-stokz IS INITIAL.
*      last_lmnga = last_lmnga + wa_afru1-lmnga.
*      last_gmnga = last_gmnga + wa_afru1-gmnga.
*    ELSE.
*      last_lmnga = last_lmnga - wa_afru1-lmnga.
*      last_gmnga = last_gmnga - wa_afru1-gmnga.
*    ENDIF.
*  ENDLOOP.
*
**  use order unit quantity if necessary
*  IF wa_afru1-meinh NE wa_afru1-gmein.
**  afru-gmein is order unit of measure
*    MOVE last_gmnga TO p_lmnga.
*    p_cfuom = wa_afru1-gmein.
*  ELSE.
**  use normal quantity
*    MOVE last_lmnga TO p_lmnga.
*    p_cfuom = wa_afru1-meinh.
*  ENDIF.
*
*ENDFORM.                    " get_confirmation_qty_new
****
**** END OF MOD-101
****

*&---------------------------------------------------------------------*
*&      Form  USER_COMMNAD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM user_command TABLES fp_i_nodestab     STRUCTURE snodetext"#EC *
                   USING fp_l_ucomm        TYPE any
                CHANGING fp_l_exit         TYPE any
                         fp_l_list_refresh TYPE any.        "#EC *

  DATA : v_aufnr   TYPE aufnr,
         l_arbpl   TYPE arbpl,                              "MOD-101+
         l_txt(14) TYPE c.                                  "MOD-101+

  DATA: PROGNAME          LIKE SY-REPID,
        SELECTED          TYPE C,
        EXIT_SAV          TYPE C,
        LIST_REFRESH_SAV  TYPE C.

  fp_l_list_refresh = c_m.

  CASE fp_l_ucomm.
***
*** BEGIN OF MOD-101
***
    WHEN c_trpi.
      CLEAR : v_aufnr , l_txt.
      GET CURSOR FIELD fp_i_nodestab-text1 VALUE l_txt.

      IF fp_i_nodestab-text1  = c_text1 AND NOT l_txt IS INITIAL.
        CASE fp_i_nodestab-tlevel.
          WHEN c_tlevel_2.
            v_aufnr = l_txt(12).
            SUBMIT zprocessord WITH s_aufnr-low = v_aufnr
            AND RETURN.
*           SUBMIT zprocessord WITH p_aufnr = v_aufnr
*           AND RETURN.

          WHEN c_tlevel_3.
            l_arbpl = l_txt(8).

            SET PARAMETER ID 'WRK' FIELD p_werks.
            SET PARAMETER ID 'AGR' FIELD l_arbpl.

            CALL TRANSACTION 'CRC3' AND SKIP FIRST SCREEN.
          WHEN c_tlevel_4.
            l_arbpl = l_txt+6(8).

            SET PARAMETER ID 'WRK' FIELD p_werks.
            SET PARAMETER ID 'AGR' FIELD l_arbpl.

            CALL TRANSACTION 'CRC3' AND SKIP FIRST SCREEN.
        ENDCASE.

      ELSEIF fp_i_nodestab-text1 <> c_plus AND fp_i_nodestab-text1 <>
      c_minus AND
             sy-title <> 'Process Order Variance - Summary Report'(069).
*Please select order number!
        MESSAGE s063.
      ENDIF.

** TRSL
*      CLEAR : v_aufnr , l_txt.
*      GET CURSOR FIELD fp_i_nodestab-text1 VALUE l_txt.
*      IF fp_i_nodestab-text1  = c_text1 AND NOT l_txt IS INITIAL.
*      CASE fp_i_nodestab-tlevel.
*          WHEN c_tlevel_2.
*            v_aufnr = l_txt.
*            call function 'RS_TREE_EXPAND'
*                 exporting
*                      node_id     = nodelist-id
*                      list_scroll = 'X'
*                 exceptions
*                      others.
*          WHEN c_tlevel_3.
*            l_arbpl = l_txt(8).
*            call function 'RS_TREE_EXPAND'
*                 exporting
*                      node_id     = nodelist-id
*                      list_scroll = 'X'
*                 exceptions
*                      others.
*
*          WHEN c_tlevel_4.
*            l_arbpl = l_txt+5(8).
*             call function 'RS_TREE_EXPAND'
*                 exporting
*                      node_id     = nodelist-id
*                      list_scroll = 'X'
*                 exceptions
*                      others.
*
*       ENDCASE.
*
**      when 'NODE'.
**          if selname = 'MINUS' or selname = 'MINUSLINE'.
**            call function 'RS_TREE_COMPRESS'
**                 exporting
**                      node_id = nodelist-id
**                 exceptions
**                      others.
**          elseif selname = 'PLUS' or selname = 'PLUSLINE'.
**            call function 'RS_TREE_EXPAND'
**                 exporting
**                      node_id     = nodelist-id
**                      list_scroll = 'X'
**                 exceptions
**                      others.
**          else.
**            perform uc_prepare_nodetab.
**            perform uc_user_callback.
**            if exit ne space.
**              exit_from_screen.
**            endif.
**          endif.
**      ENDCASE.
*
*      ELSEIF fp_i_nodestab-text1 <> c_plus AND fp_i_nodestab-text1 <>
*      c_minus AND
*sy-title <> 'Process Order Variance - Summary Report'(069).
**Please select order number!
*        MESSAGE s063.
*      ENDIF.

    WHEN c_trde.
      CLEAR : v_aufnr , l_txt.
      GET CURSOR FIELD fp_i_nodestab-text1 VALUE l_txt.

      IF fp_i_nodestab-text1 = c_text1 AND NOT l_txt IS INITIAL.
        CASE fp_i_nodestab-tlevel.
          WHEN c_tlevel_2.
            v_aufnr = l_txt(12).
*           SUBMIT zprocessord WITH p_aufnr = v_aufnr
*           AND RETURN.
            SUBMIT zprocessord WITH s_aufnr-low = v_aufnr
            AND RETURN.

          WHEN c_tlevel_3.
            l_arbpl = l_txt(8).

            SET PARAMETER ID 'WRK' FIELD p_werks.
            SET PARAMETER ID 'AGR' FIELD l_arbpl.

            CALL TRANSACTION 'CRC3' AND SKIP FIRST SCREEN.
          WHEN c_tlevel_4.
            l_arbpl = l_txt+5(8).

            SET PARAMETER ID 'WRK' FIELD p_werks.
            SET PARAMETER ID 'AGR' FIELD l_arbpl.

            CALL TRANSACTION 'CRC3' AND SKIP FIRST SCREEN.
        ENDCASE.

      ELSEIF fp_i_nodestab-text1 <> c_plus AND fp_i_nodestab-text1 <>
      c_minus.
*Please select order number!
        MESSAGE s063.
      ENDIF.

*    WHEN c_trpi.
*      CLEAR : v_aufnr , l_txt.
*      GET CURSOR FIELD fp_i_nodestab-text1 VALUE l_txt.
*
*      CLEAR v_aufnr.
*      GET CURSOR FIELD fp_i_nodestab-text1 VALUE v_aufnr.
*
*      IF fp_i_nodestab-text1 = c_text1 "'NODELIST-TEXT1'
*          AND NOT v_aufnr IS INITIAL
*          AND fp_i_nodestab-tlevel = c_tlevel_2.
*        SUBMIT /eur/rgbptr_order_vari_detail
*        WITH p_aufnr = v_aufnr AND RETURN.
*      ELSEIF fp_i_nodestab-text1 <> c_plus
*        AND fp_i_nodestab-text1 <> c_minus
*        AND sy-title <> 'Process Order Variance - Summary Report'(069).
**Please select order number!
*        MESSAGE s063.
*      ENDIF.
*
*    WHEN c_trde.
*      CLEAR v_aufnr.
*      GET CURSOR FIELD fp_i_nodestab-text1 VALUE v_aufnr.
*      IF fp_i_nodestab-text1 = c_text1  "'NODELIST-TEXT1'
*          AND NOT v_aufnr IS INITIAL
*          AND fp_i_nodestab-tlevel = c_tlevel_2.
*        SUBMIT /eur/rgbptr_order_vari_detail
*        WITH p_aufnr = v_aufnr AND RETURN.
*      ELSEIF fp_i_nodestab-text1 <> c_plus
*        AND fp_i_nodestab-text1 <> c_minus.
**Please select order number!
*        MESSAGE s063.
*      ENDIF.

    WHEN c_detl.
      CLEAR: rb_summ, rb_phase.
      rb_detl = c_x.
      PERFORM output.

    WHEN c_phas.
      CLEAR: rb_detl, rb_summ.
      rb_phase = c_x.
      PERFORM output.

***
*** END OF MOD-101
***
    WHEN c_sums.
      CLEAR: rb_detl, rb_phase.
      rb_summ = c_x.
*      fp_l_exit = c_x.  "MOD-101-
*      PERFORM display.  "MOD-101-
      PERFORM output.                                       "MOD-101+

    WHEN c_qty.
* Display quantities
      rb_quant = c_x.
      rb_fiscl = space.

*      fp_l_exit = c_x.  "MOD-101-
*      PERFORM display.  "MOD-101-
      PERFORM output.                                       "MOD-101+

    WHEN c_fisc.
* Display fiscal values
      rb_quant = space.
      rb_fiscl = c_x.

*      fp_l_exit = c_x.  "MOD-101-
*      PERFORM display.  "MOD-101-
      PERFORM output.                                       "MOD-101+

    WHEN c_kgm.
* Display in KGMs
      rb_order = space.
      rb_kgm = c_x.

*      fp_l_exit = c_x.  "MOD-101-
*      PERFORM display.  "MOD-101-
      PERFORM output.                                       "MOD-101+

    WHEN c_ordu.
* Display order units
      rb_kgm = space.
      rb_order = c_x.

*      fp_l_exit = c_x.  "MOD-101-
*      PERFORM display.  "MOD-101-
      PERFORM output.                                       "MOD-101+

    WHEN c_zero.
* Display zero loss values
      rb_stdpl = space.
      rb_zloss = c_x.

*      fp_l_exit = c_x.  "MOD-101-
*      PERFORM display.  "MOD-101-
      PERFORM output.                                       "MOD-101+

    WHEN c_std.
* Display standard recipe values
      rb_zloss = space.
      rb_stdpl = c_x.

*      fp_l_exit = c_x.  "MOD-101-
*      PERFORM display.  "MOD-101-
      PERFORM output.                                       "MOD-101+

    WHEN c_trep.
      IF fp_i_nodestab-child IS INITIAL.
*Invalid row selected!
        MESSAGE s064.
      ENDIF.

    WHEN c_trcm.
      IF fp_i_nodestab-child IS INITIAL.
*Invalid row selected!
        MESSAGE s064.
      ENDIF.

    WHEN 'AUAN'.
            SET PARAMETER ID 'ANR' FIELD s_aufnr.
            CALL TRANSACTION 'COR3' AND SKIP FIRST SCREEN.
    WHEN 'AUAE'.
            SET PARAMETER ID 'ANR' FIELD s_aufnr.
            CALL TRANSACTION 'COR2' AND SKIP FIRST SCREEN.
    WHEN c_exit.
      LEAVE PROGRAM.
  ENDCASE.

**"BEGIN OF MOD-101
*  IF sy-ucomm = c_back AND fp_l_ucomm = c_sums.
*    CLEAR: rb_summ, rb_phase.
*    rb_detl = c_x.
*    fp_l_list_refresh = c_m.
*    PERFORM list_display.
*    fp_l_exit = c_x.
*  ENDIF.
**"END OF MOD-101
ENDFORM.                    "user_command

*&---------------------------------------------------------------------*
*&      Form  LIST_DISPLAY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM list_display.
*" >>> MOD-101-
  CALL FUNCTION 'RS_TREE_CONSTRUCT'
    TABLES
      nodetab            = i_nodestab
    EXCEPTIONS
      tree_failure       = 1
      id_not_found       = 2
      wrong_relationship = 3
      OTHERS             = 4.
  IF sy-subrc <> 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
*" <<< MOD-101-

  CALL FUNCTION 'RS_TREE_LIST_DISPLAY'
    EXPORTING
*      callback_program      = c_prog          "MOD-101-
      callback_program      = sy-repid                      "MOD-101+
      callback_user_command = 'USER_COMMAND'.
ENDFORM.                    " LIST_DISPLAY

*&---------------------------------------------------------------------*
*&      Form  inform_user_of_progress
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM inform_user_of_progress.
* Update Gui
  CONDENSE v_output_text.
  CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
    EXPORTING
      text = v_output_text.
ENDFORM.                    " inform_user_of_progress

*&---------------------------------------------------------------------*
*&      Form  pfstatus
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM pfstatus.

* Build table of excluded functions for buttons in report
  REFRESH i_fcode.

* Not summary report
  IF NOT ( rb_summ IS INITIAL ).                            " MOD-101-
    MOVE c_trde TO wa_fcode-fcode.
    APPEND wa_fcode TO i_fcode. CLEAR  wa_fcode.
    MOVE c_sums TO wa_fcode-fcode.
    APPEND wa_fcode TO i_fcode.
    CLEAR  wa_fcode.
*** BEGIN OF MOD-101
  ELSEIF rb_detl = c_x.
    MOVE c_trde TO wa_fcode-fcode.
    APPEND wa_fcode TO i_fcode. CLEAR  wa_fcode.

    MOVE c_detl TO wa_fcode-fcode.
    APPEND wa_fcode TO i_fcode.

    CLEAR  wa_fcode.

  ELSEIF rb_phase = c_x.
    MOVE c_trde TO wa_fcode-fcode.
    APPEND wa_fcode TO i_fcode. CLEAR  wa_fcode.

    MOVE c_phas TO wa_fcode-fcode.
    APPEND wa_fcode TO i_fcode.

    CLEAR  wa_fcode.
*** END OF MOD-101
  ENDIF.

* Fiscal / quantity
  IF rb_fiscl IS INITIAL.
    MOVE c_qty TO wa_fcode-fcode.
    APPEND wa_fcode TO i_fcode.
    CLEAR  wa_fcode.
  ELSE.
    MOVE c_fisc TO wa_fcode-fcode.
    APPEND wa_fcode TO i_fcode.
    CLEAR  wa_fcode.

****Begin of MOD-001
*    MOVE c_ordu TO wa_fcode-fcode.
*    APPEND wa_fcode TO i_fcod