SELECT DFA_PREVIOUSWO as PREVIOUSWO,DFA_PREVIOUSACT as PREVIOUSACT,DFA_ORIGACT as ORIGINALACT,DFA_DESC as ACTIVITYNOTE,DFA_TRADE as TRADE,DFA_QTY as TASKQTY, DFA_PERSONS as PEOPLEREQUIRED,DFA_DURATION as DURATION,
    DFA_EST as ESTIMATEDHOURS,DFA_MATLIST as MATLIST, DFA_DEFERRED as deferreddate,
DFA_ORIGWO as originalwo,DFA_WO as WORKORDER, DFA_MRC as DEPARTMENT, DFA_CODE as DEFCODE, DFA_ORG as ORGANIZATION,

DFA_RSTATUS as DEFRSTATUS,DFA_STATUS as DEFSTATUS, DFA_OBJECT as DEFOBJECT, DFA_OBJECT_ORG as DEFOBJECTORG, DFA_TASK as DEFTASK,DFA_MATLREV as DEFMATREV,DFA_MANUFACT as DEFMANFACT,

DFA_SYSLEVEL as DEFSYSLVL,DFA_ASMLEVEL as DEFASMLVL, DFA_COMPLEVEL as DEFCOMPLVL, DFA_FROMPOINT as DEFFRMPT, DFA_FROMREFDESC as DEFFRMDESC,DFA_COMPONENTLOCATION as DEFCOMPLOC,DFA_FROMGEOREF as DEFFRMGEOREF,

DFA_TOPOINT as DEFTOPT,DFA_TOREFDESC as DEFTOREFDESC, DFA_TOGEOREF as DEFTODEOREF, DFA_HIRE as DEFHIRE, DFA_DEFERREDBY as DEFBY,

DFA_RPC as DEFRPC, DFA_WAP as DEFWAP, DFA_TPF as DEFTPF


FROM r5deferredact , r5events
WHERE evt_code = <parameter.inputwo>
AND dfa_object = evt_object
AND dfa_object_org = evt_object_org
AND dfa_rstatus = 'U'
AND (<parameter.bypassdeptsecurity> = 'true' OR (<parameter.deptsec> ='OFF' OR
(dfa_mrc IN( SELECT dse_mrc FROM r5departmentsecurity WHERE dse_user =<parameter.r5user> AND dse_mrc = dfa_mrc AND coalesce(dse_readonly, '-') = '-'))))

