Performance of the SQL

Hi ABAP Experts,
good day all,
iam working as BI consultant as per user requirement some of the fields are not there i enhanced to R/3 by using cmod . i have written some code every thing fien .but its very bad performance almost its taking more than 24 hrs taking . here i have written many SQL statement . can any one suggest me how to improve the performance of code.
Tables declaration for EMPLOYEE_ATTR
TABLES: PA0185,HRP1001,PA0001,PA0588, PA0587, PA0021, PA0006, PA0009, PA0003.
TABLES: HRMS_BIW_IO_OCCUPANCY.
TABLES: BWCO_MD_CCTR.
TABLES: BIW_KNA1_S,KNB1.
Internal table - Types -- Declaration for COSTCENTER_ATTR
TYPES : BEGIN OF T_PERNR,
         PERNR TYPE PERSNO,
        END OF T_PERNR.
DATA : IT_PERNR TYPE STANDARD TABLE OF T_PERNR.
DATA : VL_COUNT TYPE I.
data : s_area like pa0001-mstbr.
Declarations for 0EMPLOYEE_ATTR
DATA : I_W_DATA LIKE HRMS_BIW_IO_OCCUPANCY,
       I_W_DATA_KOSTL LIKE BWCO_MD_CCTR,
       L_ICNUM TYPE PA0185-ICNUM,
       L_RMBEGDA TYPE PA0185-BEGDA,
       L_RMENDDA TYPE PA0185-ENDDA,
       L_PERNR TYPE PA0001-PERNR,
       L_PERNR1 TYPE PA0001-PERNR,
       L_PLANS TYPE SOBID,
       L_PLANS2 TYPE SOBID,
       L_SUBTY TYPE PA0185-SUBTY,
       L_NAME TYPE PA0001-ENAME,
       L_NAME1 TYPE PA0001-ENAME,
       L_AMOUNT TYPE BETRG,
       L_AMOUNT_OFF TYPE BETRG,
       L_ORGUNITSVP TYPE PA0001-ORGEH,
       L_ICNUM_RM TYPE PA0185-ICNUM,
       L_ICNUM_TIER2 TYPE PA0185-ICNUM,
       L_MSTBR TYPE PA0001-MSTBR,
       L_ICNUM_21 TYPE PA0185-ICNUM,
       L_ICNUM_20 TYPE PA0185-ICNUM,
       L_ICNUM_24 TYPE PA0185-ICNUM,
       L_ICNUM_18 TYPE PA0185-ICNUM,
       L_ISSPL TYPE PA0185-ISSPL,
       L_ESINO LIKE PA0588-ESINO,
       L_EEBAS LIKE PA0587-TSTID,
       I_W_DATA1 LIKE BIW_KNA1_S,
       L_TLFXS LIKE KNB1-TLFXS,
       L_NAME4 LIKE KNA1-NAME4,
new fields added by pandu
       L_GBDAT TYPE GBDAT,
       L_FAVOR TYPE PAD_VORNA,
       L_NAME2 TYPE PAD_CONAM,
       L_STRAS TYPE PAD_STRAS,
       L_PSTLZ TYPE PSTLZ_HR,
       L_ORT01 TYPE PAD_ORT01,
       L_USRID TYPE SYSID,
       L_XMETXT TYPE     REBDXRO,
       L_BANKL TYPE BANKK,
       L_BANKN TYPE BANKN,
       L_CNAME TYPE ZCNAME,
       L_USRID1 TYPE     SYSID,
       L_MGRID TYPE SOBID,
       L_INCDAT TYPE     BEGDA,
       L_LIFNR TYPE LIFNR,
       L_RDATE TYPE BEGDA,
       L_LWDAY TYPE BEGDA,
       L_REDAT TYPE BEGDA,
       L_SCHKZ TYPE SCHKN,
       L_PRDAT TYPE PRDAT,
       L_ABRDT TYPE LABRD,
       L_ABRSP TYPE ABRSP,
       L_BANKA TYPE BANKA,
       L_SMDAT TYPE BEGDA.
      l_ctc_amt type betrg.
*endchange
DATA: BEGIN OF TP_RGDIR OCCURS 0.
        INCLUDE STRUCTURE PC261.
DATA: END OF TP_RGDIR.
*Decleration for monthly salary
DATA : L_PA0008 LIKE PA0008.
DATA : V_AMOUNT TYPE PAD_AMT7S,
       FLDNAM(30),
       NUM(2) VALUE '01'.
FIELD-SYMBOLS: <FS> TYPE ANY.
FIELD-SYMBOLS: <FS1> TYPE ANY.
CASE I_DATASOURCE.
*Getting Customer branch in 0customer_attr
    WHEN '0CUSTOMER_ATTR'.
      LOOP AT I_T_DATA.
        MOVE-CORRESPONDING I_T_DATA TO I_W_DATA1 .
*Getting Customer branch in 0customer_attr
        SELECT SINGLE TLFXS INTO L_TLFXS FROM KNB1 WHERE KUNNR EQ I_W_DATA1-KUNNR.
*Getting Customer Name4 in 0customer_attr from table KNA1
       SELECT SINGLE NAME4 INTO L_NAME4 FROM KNA1 WHERE KUNNR EQ I_W_DATA1-KUNNR.
        I_W_DATA1-ZZTLFXS = L_TLFXS.
        I_W_DATA1-ZZNAME4 = L_NAME4.
        MODIFY I_T_DATA FROM I_W_DATA1.
         CLEAR L_TLFXS.
         CLEAR L_NAME4.
      ENDLOOP.
Getting the RM for the employee and SVP using the ICNUM
  WHEN '0EMPLOYEE_ATTR'.
    LOOP AT I_T_DATA INTO I_W_DATA.
      SELECT SINGLE ICNUM INTO L_ICNUM FROM PA0185
             WHERE PERNR EQ I_W_DATA-PERNR
             AND SUBTY = '23'
             AND ENDDA GE SY-DATUM.
Getting the Joining date of RM
      SELECT SINGLE BEGDA INTO L_RMBEGDA FROM PA0000
              WHERE PERNR EQ I_W_DATA-PERNR
              AND MASSN EQ '01'.
Getting the Resignation Date of RM
      SELECT SINGLE BEGDA INTO L_RMENDDA FROM PA0000
              WHERE PERNR EQ I_W_DATA-PERNR
              AND MASSN EQ '14'.
*Getting the Tier II code and Name
      SELECT SINGLE SOBID INTO L_PLANS FROM HRP1001
              WHERE OTYPE EQ 'S'
              AND OBJID EQ I_W_DATA-PLANS
              AND RSIGN EQ 'A'
              AND RELAT EQ '002'
              AND ENDDA GE I_W_DATA-ENDDA
             AND endda GE sy-datum
              AND SCLAS EQ 'S'.
             AND sobid EQ i_w_data-plans.
      SELECT SINGLE PERNR INTO L_PERNR FROM PA0001
              WHERE ENDDA GE SY-DATUM
             WHERE endda GE i_w_data-endda
              AND PLANS EQ L_PLANS.
      SELECT SINGLE ENAME INTO L_NAME FROM PA0001
              WHERE ENDDA GE SY-DATUM
              AND PLANS EQ L_PLANS.
*Getting the TIER II branch
    SELECT SINGLE ICNUM INTO L_ICNUM_TIER2 FROM PA0185
                 WHERE ENDDA GE SY-DATUM
                 AND PERNR EQ L_PERNR
                 AND SUBTY = '05'.
*Getting the Supervisor/HOD for Employee----
SELECT SINGLE MSTBR FROM PA0001 INTO L_MSTBR  WHERE PERNR =  I_W_DATA-PERNR AND
                                               ENDDA GE SY-DATUM.
*Getting the Employee Product from infotype 185 styp 21.
   SELECT SINGLE ICNUM INTO L_ICNUM_21 FROM PA0185
               WHERE ENDDA GE SY-DATUM
               AND PERNR EQ I_W_DATA-PERNR
               AND SUBTY = '21'.
*Getting the Employee Branch Discription/Place of issue from infotype 185 styp 05.
   SELECT SINGLE ISSPL INTO L_ISSPL FROM PA0185
               WHERE ENDDA GE SY-DATUM
               AND PERNR EQ I_W_DATA-PERNR
               AND SUBTY = '05'.
*Getting the Employee Library no/business from infotype 185 styp 18.
   SELECT SINGLE ICNUM INTO L_ICNUM_18 FROM PA0185
               WHERE ENDDA GE SY-DATUM
               AND PERNR EQ I_W_DATA-PERNR
               AND SUBTY = '18'.
*Getting the Employee Department from infotype 185 styp 20.
   SELECT SINGLE ICNUM INTO L_ICNUM_20 FROM PA0185
               WHERE ENDDA GE SY-DATUM
               AND PERNR EQ I_W_DATA-PERNR
               AND SUBTY = '20'.
*Getting the Employee RBT Codefrom infotype 185 styp 24.
   SELECT SINGLE ICNUM INTO L_ICNUM_24 FROM PA0185
               WHERE ENDDA GE SY-DATUM
               AND PERNR EQ I_W_DATA-PERNR
               AND SUBTY = '24'.
*Getting the Employee ESI number from Infotype 588.
  SELECT SINGLE ESINO INTO L_ESINO FROM PA0588
             WHERE ENDDA GE SY-DATUM
             AND PERNR EQ I_W_DATA-PERNR.
*Getting the Employee PF Eligibility no from Infotype 587.
  SELECT SINGLE TSTID INTO L_EEBAS FROM PA0587
             WHERE ENDDA GE SY-DATUM
             AND PERNR EQ I_W_DATA-PERNR.
*Getting the Employee Basic salary amt from Infotype 0008.
    NUM = '01'.
    CLEAR V_AMOUNT.
    SELECT SINGLE * INTO L_PA0008 FROM PA0008 WHERE PERNR EQ I_W_DATA-PERNR
                                              AND   ENDDA EQ '99991231'.
    DO 30 TIMES.
    IF STRLEN( NUM ) = 1.
      CONCATENATE '0' NUM INTO NUM.
    ENDIF.
    CONCATENATE 'L_PA0008-LGA' NUM INTO FLDNAM.
    ASSIGN (FLDNAM) TO <FS>.
    CONCATENATE 'L_PA0008-BET' NUM INTO FLDNAM.
    ASSIGN (FLDNAM) TO <FS1>.
    IF <FS> = '1000'.
      V_AMOUNT = <FS1>.
    ENDIF.
    CLEAR :  <FS>, <FS1>.
    NUM = NUM + 1.
    ENDDO.
    I_W_DATA-ZZBASPAY  = V_AMOUNT.
   endif.
  HRMS_BIW_IO_OCCUPANCY-ZZMSTBR = s_area.
select single mstbr into l_mstbr from pa0001
                where endda GE sy-datum
                and pernr eq l_pernr.
*Bringing RM branch
   SELECT SINGLE ICNUM INTO L_ICNUM_RM FROM PA0185
                 WHERE ENDDA GE SY-DATUM
                 AND PERNR EQ I_W_DATA-PERNR
                 AND SUBTY = '05'.
new code for fields by pandu
*bringing date-of-birth
  SELECT SINGLE GBDAT INTO L_GBDAT FROM PA0002 WHERE PERNR = I_W_DATA-PERNR.
bringing fathers name
  SELECT SINGLE FAVOR INTO L_FAVOR FROM PA0021 WHERE PERNR = I_W_DATA-PERNR
                                                 AND SUBTY = '2'.
bringing address details
  SELECT SINGLE * FROM PA0006 WHERE PERNR = I_W_DATA-PERNR
                                AND SUBTY = '2'
                                AND ENDDA GE SY-DATUM.
L_NAME2 = PA0006-NAME2.
L_STRAS = PA0006-STRAS.
L_ORT01 = PA0006-ORT01.
L_PSTLZ = PA0006-PSTLZ.
bringing communication dteails
SELECT SINGLE USRID INTO L_USRID FROM PA0105 WHERE PERNR = I_W_DATA-PERNR
                                                AND SUBTY = '0010'
                                                AND ENDDA GE SY-DATUM.
bringing location details
SELECT SINGLE XMETXT INTO L_XMETXT FROM PA9005 WHERE PERNR = I_W_DATA-PERNR
                                                 AND ENDDA GE SY-DATUM.
bringing bank details
  SELECT SINGLE * FROM PA0009 WHERE  PERNR = I_W_DATA-PERNR
                                      AND ENDDA GE SY-DATUM.
  L_BANKN = PA0009-BANKN.
  L_BANKL = PA0009-BANKL.
bringing the bankname
SELECT SINGLE BANKA INTO L_BANKA FROM BNKA WHERE BANKL = L_BANKL.
bringing esop details
SELECT SINGLE CNAME INTO L_CNAME FROM PA9008 WHERE  PERNR = I_W_DATA-PERNR
                                                AND ENDDA GE SY-DATUM.
bringing vendor details
SELECT SINGLE LIFNR INTO L_LIFNR FROM LFB1 WHERE PERNR = I_W_DATA-PERNR.
SELECT SINGLE CTC_DATE  INTO L_INCDAT  FROM PB9007 WHERE REPORT = I_W_DATA-PERNR
                                                   AND ENDDA GE SY-DATUM.
*select single ctc_amt  into l_ctc_amt  from pb9007 where report = i_w_data-pernr
                                                  and endda ge sy-datum.
*l_incdat = pa9007-ctc_date.
*l_ctc_amt = pa9007-ctc_amt.
bringing resignation date
SELECT SINGLE BEGDA FROM PA0000 INTO L_RDATE WHERE PERNR = I_W_DATA-PERNR
                                                   AND ENDDA GE SY-DATUM
                                                   AND MASSN = '14'.
to get last working day
L_LWDAY = L_RDATE - 1.
to get reentry date
SELECT SINGLE BEGDA FROM PA0000 INTO L_REDAT WHERE PERNR = I_W_DATA-PERNR
                                                   AND ENDDA GE SY-DATUM
                                                   AND MASSN = '15'.
bringing workschedule details
SELECT SINGLE SCHKZ FROM PA0007 INTO L_SCHKZ WHERE PERNR =  I_W_DATA-PERNR
                                                   AND ENDDA GE SY-DATUM.
bringing payroll status details
SELECT SINGLE * FROM PA0003 WHERE PERNR = I_W_DATA-PERNR
                              AND ENDDA GE SY-DATUM.
L_PRDAT = PA0003-PRDAT.
L_ABRDT = PA0003-ABRDT.
L_ABRSP = PA0003-ABRSP.
bringing paydate
SELECT SINGLE BEGDA INTO L_SMDAT FROM PA0008 WHERE PERNR = I_W_DATA-PERNR
                                                   AND ENDDA GE SY-DATUM.
*endadd
Getting wage type for the salaries calc
      I_W_DATA-ZZRMID = L_ICNUM.
      I_W_DATA-ZZICNUM = L_ICNUM_RM.
      I_W_DATA-ZZRMBEGDA = L_RMBEGDA.
      I_W_DATA-ZZRMENDDA = L_RMENDDA.
      I_W_DATA-ZZEVPID = L_PERNR.
      I_W_DATA-ZZEVPNAME = L_NAME.
     I_W_DATA-ZZORGUTSVP = L_ICNUM_TIER2.
      I_W_DATA-ZZMSTBR = L_MSTBR.
      I_W_DATA-ZZICNUM_21 = L_ICNUM_21.
      I_W_DATA-ZZICNUM_20 = L_ICNUM_20.
      I_W_DATA-ZZICNUM_24 = L_ICNUM_24.
      I_W_DATA-ZZICNUM_18 = L_ICNUM_18.
      I_W_DATA-ZZESINO = L_ESINO.
      I_W_DATA-ZZEEPF1 = L_EEBAS.
      I_W_DATA-ZZISSPL = L_ISSPL.
code added by pandu
      I_W_DATA-ZZGBDAT = L_GBDAT.
      I_W_DATA-ZZFAVOR = L_FAVOR.
      I_W_DATA-ZZNAME2 = L_NAME2.
      I_W_DATA-ZZORT01 = L_ORT01.
      I_W_DATA-ZZSTRAS = L_STRAS.
      I_W_DATA-ZZPSTLZ = L_PSTLZ.
      I_W_DATA-ZZUSRID = L_USRID.
      I_W_DATA-ZZXMETXT = L_XMETXT.
      I_W_DATA-ZZBANKL = L_BANKL.
      I_W_DATA-ZZBANKN = L_BANKN.
      I_W_DATA-ZZCNAME = L_CNAME.
      I_W_DATA-ZZLIFNR = L_LIFNR.
      I_W_DATA-ZZINCDAT = L_INCDAT.
     i_w_data-zzctc_amt = l_ctc_amt.
      I_W_DATA-ZZRDAT = L_RDATE.
      I_W_DATA-ZZLWDAY = L_LWDAY.
      I_W_DATA-ZZRDAT = L_REDAT.
      I_W_DATA-ZZSCHKZ = L_SCHKZ.
      I_W_DATA-ZZPRDAT = L_PRDAT.
      I_W_DATA-ZZABRDT = L_ABRDT.
      I_W_DATA-ZZABRSP = L_ABRSP.
      I_W_DATA-ZZBANKA = L_BANKA.
      I_W_DATA-ZZSMDAT = L_SMDAT.
*endchange
*Getting The details for EVP
      CLEAR L_PERNR.
      CLEAR L_NAME.
      CLEAR L_ICNUM_TIER2.
      CLEAR L_ICNUM_RM.
      CLEAR L_RMBEGDA.
      CLEAR L_RMENDDA.
      CLEAR L_ESINO.
      CLEAR L_EEBAS.
      CLEAR L_ICNUM_21.
      CLEAR L_ICNUM_20.
      CLEAR L_ICNUM_24.
      CLEAR L_ICNUM_18.
      CLEAR L_MSTBR.
      CLEAR L_ISSPL.
      CLEAR L_PLANS.
*code added by pandu
      CLEAR L_GBDAT.
      CLEAR L_FAVOR.
      CLEAR L_NAME2.
      CLEAR L_ORT01.
      CLEAR L_STRAS.
      CLEAR L_PSTLZ.
      CLEAR L_USRID.
      CLEAR L_XMETXT.
      CLEAR L_BANKN.
      CLEAR L_BANKL.
      CLEAR L_CNAME.
      CLEAR L_LIFNR.
      CLEAR L_RDATE.
      CLEAR L_LWDAY.
      CLEAR L_REDAT.
      CLEAR L_PRDAT.
      CLEAR L_SCHKZ.
      CLEAR L_ABRDT.
      CLEAR L_ABRSP.
      CLEAR L_BANKA.
      CLEAR L_SMDAT.
*endcode
      SELECT SINGLE SOBID INTO L_PLANS2 FROM HRP1001
              WHERE OTYPE EQ 'S'
              AND OBJID EQ L_PLANS
              AND RSIGN EQ 'A'
              AND RELAT EQ '002'
              AND ENDDA GE SY-DATUM
              AND SCLAS EQ 'S'.
             AND sobid EQ l_plans.
      SELECT SINGLE PERNR INTO L_PERNR1 FROM PA0001
              WHERE ENDDA GE SY-DATUM
              AND PLANS EQ L_PLANS2.
      SELECT SINGLE ENAME INTO L_NAME1 FROM PA0001
              WHERE ENDDA GE SY-DATUM
              AND PLANS EQ L_PLANS2.
      I_W_DATA-ZZSRRMEVP = L_PERNR1.
      I_W_DATA-ZZSRRMEVPNAME = L_NAME1.
*Monthly salary of Rm from PA0008
NUM = '01'.
IF I_W_DATA-ENDDA EQ '99991231'.
CLEAR V_AMOUNT.
SELECT SINGLE * INTO L_PA0008
FROM PA0008
WHERE PERNR EQ I_W_DATA-PERNR
AND   ENDDA EQ '99991231'.
DO 30 TIMES.
IF STRLEN( NUM ) = 1.
CONCATENATE '0' NUM INTO NUM.
ENDIF.
CONCATENATE 'L_PA0008-BET' NUM INTO FLDNAM.
ASSIGN (FLDNAM) TO <FS>.
V_AMOUNT = V_AMOUNT + <FS>.
CLEAR <FS>.
NUM = NUM + 1.
ENDDO.
I_W_DATA-ZZMONSAL     = V_AMOUNT.
ENDIF.
Getting salary monthly information
      CLEAR : L_AMOUNT, L_AMOUNT_OFF,L_NAME1.
*CALL FUNCTION 'ZIBHR_EMP_INCENTIVE'
EXPORTING
   S_PERNR             = i_w_data-pernr
IMPORTING
  INCENTIVE           = l_amount
  INCENTIVE_OFF       = l_amount_off
     i_w_data-zzmonsal_off = l_amount_off.
      MODIFY I_T_DATA FROM I_W_DATA.
      CLEAR L_ICNUM.
      CLEAR L_PERNR.
    ENDLOOP.
COst Center Enhancement for data source
Getting the employee count for a COST CENTER
  WHEN '0COSTCENTER_ATTR'.
    CLEAR : VL_COUNT.
    LOOP AT I_T_DATA INTO I_W_DATA_KOSTL.
      SELECT PERNR INTO TABLE IT_PERNR  FROM PA0185
             WHERE ICNUM EQ I_W_DATA_KOSTL-KOSTL
             AND SUBTY = '05'
             AND ENDDA EQ '99991231'.
      DESCRIBE TABLE IT_PERNR LINES VL_COUNT.
      MOVE : VL_COUNT TO I_W_DATA_KOSTL-ZZHEADCOUNT.
      MODIFY I_T_DATA FROM I_W_DATA_KOSTL.
      REFRESH : IT_PERNR.
    ENDLOOP.

Hi Rama,
1st: improve the know-how for understanding whats going on in your source
2nd: know the slowest parts of your source (identify the "lowest hanging fruits" ) and start tune these
parts.
Tools:
Check this blog for using SE30 and ST05:
The ABAP Runtime Trace (SE30) -  Quick and Easy
Unfortunatley, I'm not able to give you an advice in terms of code - up to now we are only guessing what may slow you down.
It may be good to have a senior ABAPer on your side to help you with the tools mentioned above.
Bye
yk

Similar Messages

  • Need help in improving the performance for the sql query

    Thanks in advance for helping me.
    I was trying to improve the performance of the below query. I tried the following methods used merge instead of update, used bulk collect / Forall update, used ordered hint, created a temp table and upadated the target table using the same. The methods which I used did not improve any performance. The data count which is updated in the target table is 2 million records and the target table has 15 million records.
    Any suggestions or solutions for improving performance are appreciated
    SQL query:
    update targettable tt
    set mnop = 'G',
    where ( x,y,z ) in
    select a.x, a.y,a.z
    from table1 a
    where (a.x, a.y,a.z) not in (
    select b.x,b.y,b.z
    from table2 b
    where 'O' = b.defg
    and mnop = 'P'
    and hijkl = 'UVW';

    987981 wrote:
    I was trying to improve the performance of the below query. I tried the following methods used merge instead of update, used bulk collect / Forall update, used ordered hint, created a temp table and upadated the target table using the same. The methods which I used did not improve any performance. And that meant what? Surely if you spend all that time and effort to try various approaches, it should mean something? Failures are as important teachers as successes. You need to learn from failures too. :-)
    The data count which is updated in the target table is 2 million records and the target table has 15 million records.Tables have rows btw, not records. Database people tend to get upset when rows are called records, as records exist in files and a database is not a mere collection of records and files.
    The failure to find a single faster method with the approaches you tried, points to that you do not know what the actual performance problem is. And without knowing the problem, you still went ahead, guns blazing.
    The very first step in dealing with any software engineering problem, is to identify the problem. Seeing the symptoms (slow performance) is still a long way from problem identification.
    Part of identifying the performance problem, is understanding the workload. Just what does the code task the database to do?
    From your comments, it needs to find 2 million rows from 15 million rows. Change these rows. And then write 2 million rows back to disk.
    That is not a small workload. Simple example. Let's say that the 2 million row find is 1ms/row and the 2 million row write is also 1ms/row. This means a 66 minute workload. Due to the number of rows, an increase in time/row either way, will potentially have 2 million fold impact.
    So where is the performance problem? Time spend finding the 2 million rows (where other tables need to be read, indexes used, etc)? Time spend writing the 2 million rows (where triggers and indexes need to be fired and maintained)? Both?

  • What Indexes should be created for improve performance of the sql query

    Hello Admins
    One of my user is facing slow performance issue while running the below query. Can someone, please guide me for the same. I want to know, what indexes should be created to improve the performance of this query. Also what else can be done to achieve the same.
    SQL Query:-
    SELECT UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.PO_NUMBER))),
    CGSBI_SHIP_DIST_S_EXTRACT.PO_LINE_NUMBER,
    CGSBI_SHIP_DIST_S_EXTRACT.PO_SHIPMENT_NUMBER,
    CGSBI_SHIP_DIST_S_EXTRACT.PO_LINE_SHIP_DIST_NUMBER,
    CGSBI_SHIP_DIST_S_EXTRACT.DISTRIBUTION_DATE,
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.PO_LINE_SHIP_DIST_LINE_ID))),
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.PROJECT_ID))),
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.ACCOUNT_DISTRIBUTION_CODE))),
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.ORACLE_ACCOUNT_NUMBER))),
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.COMPONENT_CODE))),
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.TRANSACTION_CURRENCY_CODE))),
    CGSBI_SHIP_DIST_S_EXTRACT.ORDER_QUANTITY, UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.ORDER_UOM))),
    CGSBI_SHIP_DIST_S_EXTRACT.UNIT_PRICE_TRX_CURRENCY,
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.EXPENSE_TYPE_INDICATOR))),
    CGSBI_SHIP_DIST_S_EXTRACT.SOR_ID,
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.PO_LINE_ITEM_CODE))),
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.PO_LINE_ITEM_DESC))),
    CGSBI_SHIP_DIST_S_EXTRACT.PO_LINE_ITEM_LEAD_TIME,
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.UNSPSC_CODE))),
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.BUYER_ID))),
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.REQUESTOR_ID))),
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.APPROVER_ID))),
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.SUPPLIER_SITE_ID))),
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.SUPPLIER_GSL_NUMBER))),
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.SHIP_TO_LOCATION_CODE))),
    UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.TASK_ID))),
    (LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.PO_RELEASE_ID)))
    FROM
    CGSBI_SHIP_DIST_S_EXTRACT
    WHERE PO_NUMBER IS NOT NULL;
    I generated the explain plan for this query and found the following:-
    Explain Plan:-
    SQL> explain plan for SELECT UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.PO_NUMBER))),
    2 CGSBI_SHIP_DIST_S_EXTRACT.PO_LINE_NUMBER,
    3 CGSBI_SHIP_DIST_S_EXTRACT.PO_SHIPMENT_NUMBER,
    4 CGSBI_SHIP_DIST_S_EXTRACT.PO_LINE_SHIP_DIST_NUMBER,
    5 CGSBI_SHIP_DIST_S_EXTRACT.DISTRIBUTION_DATE,
    6 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.PO_LINE_SHIP_DIST_LINE_ID))),
    7 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.PROJECT_ID))),
    8 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.ACCOUNT_DISTRIBUTION_CODE))),
    9 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.ORACLE_ACCOUNT_NUMBER))),
    10 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.COMPONENT_CODE))),
    11 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.TRANSACTION_CURRENCY_CODE))),
    12 CGSBI_SHIP_DIST_S_EXTRACT.ORDER_QUANTITY, UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.ORDER_UOM))),
    13 CGSBI_SHIP_DIST_S_EXTRACT.UNIT_PRICE_TRX_CURRENCY,
    14 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.EXPENSE_TYPE_INDICATOR))),
    15 CGSBI_SHIP_DIST_S_EXTRACT.SOR_ID,
    16 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.PO_LINE_ITEM_CODE))),
    17 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.PO_LINE_ITEM_DESC))),
    18 CGSBI_SHIP_DIST_S_EXTRACT.PO_LINE_ITEM_LEAD_TIME,
    19 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.UNSPSC_CODE))),
    20 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.BUYER_ID))),
    21 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.REQUESTOR_ID))),
    22 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.APPROVER_ID))),
    23 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.SUPPLIER_SITE_ID))),
    24 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.SUPPLIER_GSL_NUMBER))),
    25 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.SHIP_TO_LOCATION_CODE))),
    26 UPPER(LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.TASK_ID))),
    27 (LTRIM(RTRIM(CGSBI_SHIP_DIST_S_EXTRACT.PO_RELEASE_ID)))
    28 FROM
    29 CGSBI_SHIP_DIST_S_EXTRACT
    30 WHERE PO_NUMBER IS NOT NULL;
    Explained.
    SQL>
    SQL>
    SQL> SELECT * FROM TABLE(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 3891180274
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | 77647 | 39M| 2006 (1)| 00:00:25 |
    |* 1 | TABLE ACCESS FULL| CGSBI_SHIP_DIST_S_EXTRACT | 77647 | 39M| 2006 (1)| 00:00:25 |
    Predicate Information (identified by operation id):
    1 - filter("PO_NUMBER" IS NOT NULL)
    13 rows selected.
    SQL>
    SQL>
    Kindly suggest on this...
    Thanks & Regards
    -Naveen Gangil
    Oracle DBA

    Rafi is correct. Since po_number is the filter column, the only chance you have for using an index to access the table is on that column. However, if there are few (or none) rows with null po_number, you will always have FTS. Does the table have a PK ( which probably consists of at least po_number, line_number )? If that is the case po_number could never be null and in which case you are dumping the whole table and no indexing scheme is going to improve the queri's performance. You might, repeat might, see performance improvement if you cleanse the data in the table ( to eliminate the need for UPPER(LTRIM)RTRIM())) ) before querying it so the the data does not have to be massaged before returning it.

  • Slow performance of the SQL statement

    Hi All,
    the verison of the db is 10.2.0.5 & the windows 2008 server OS version. Currenty we are facing the issue with a particular query which is taking a long to complete. The query is within a procedure and its consuming resources highly like RAM,CPU,etc. the present size of SGA is 8GB .
    Please let me know how to troubleshoot it. I just need to resolve it and its taking lot of time to resolve it. Please help me out.
    Regards,
    imran khan

    DB verion is 10.2.0.4.0
    OPtimizer related parameters :
    SQL> show parameter optimizer
    NAME TYPE VALUE
    optimizer_dynamic_sampling integer 2
    optimizer_features_enable string 10.2.0.4
    optimizer_index_caching integer 0
    optimizer_index_cost_adj integer 100
    optimizer_mode string ALL_ROWS
    optimizer_secure_view_merging boolean TRUE
    The job runs daily and not sure how to generate the trace file.
    Regards,
    imran khan

  • Performance issue while wrapping the sql in pl/sql block

    Hi All,
    I am facing performance issue in a query while wrapping the sql in pl/sql block.
    I have a complex view. while quering the view using
    Select * from v_csp_tabs(Name of View I am using), it is taking 10 second to fetch 50,000 records.
    But when I am using some conditions on the view, Like
    Select * from v_csp_tabs where clientid = 500006 and programid = 1 and vendorid = 1, it is taking more then 250 secs. to return the result set.
    now the weird part is this is happening only for one programID, that is 1
    I am using Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production
    Any one please suggest what are the things i need to check..
    I am sorry, I could not provide you the explain plan, because this is in production and I do not have enough prevelage.
    Thank you in advance.
    Thnx,
    Bits

    Bits wrote:
    I have a complex view. while quering the view using
    Select * from v_csp_tabs(Name of View I am using), it is taking 10 second to fetch 50,000 records.
    But when I am using some conditions on the view, Like
    Select * from v_csp_tabs where clientid = 500006 and programid = 1 and vendorid = 1, it is taking more then 250 secs. to return the result set.That's one problem with views - you never know how they will be used in the future, nor what performance implications variant uses can have.
    >
    now the weird part is this is happening only for one programID, that is 1
    Any one please suggest what are the things i need to check..
    I am sorry, I could not provide you the explain plan, because this is in production and I do not have enough prevelage.I understand what you are saying - I have worked at similar sites. HiddenName is correct in suggesting that you need to get execution plans but sometimes getting privileges from the DBA group is simply Not Going To Happen. Its wrong but that's the way it is. Follow through on HiddenName's suggested to get help from somebody who has the privleges needed
    Post the query that view view is executing. Desk checking a query is NOT ideal but is one thing we can do.
    I don't suppose you can see V$ views on production - V$SQL and V$SQL_PLAN (probably not if you can't generate plans, but its worth a thought)

  • How does Index fragmentation and statistics affect the sql query performance

    Hi,
    How does Index fragmentation and statistics affect the sql query performance
    Thanks
    Shashikala
    Shashikala

    How does Index fragmentation and statistics affect the sql query performance
    Very simple answer, outdated statistics will lead optimizer to create bad plans which in turn will require more resources and this will impact performance. If index is fragmented ( mainly clustered index,holds true for Non clustred as well) time spent in finding
    the value will be more as query would have to search fragmented index to look for data, additional spaces will increase search time.
    Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers
    My TechNet Wiki Articles

  • Checking the performance of Pl/SQL Procedure

    I have a PL/SQL procedure of 10,000 lines, & I dont have any Tool of performance checking only thing I have is SQL Client & database how whould I check the performance of the procedure

    Why do you want to check the performance? Have you indentified a specific problem?
    It is not easy to to "simply check the performance" of code. Let's say it has an elapsed execution time of 90 seconds. What does that tell you? Fast? Slow? Average? What does 90 seconds tell you about the resource utilisation? Nothing much - are resources being red lined for those 90 seconds or not?
    So unless there is a specific performance problem that has been diagnosed, e.g. the process uses too much PGA memory, you cannot really identify a performance problem.
    What you can do is use DBMS_PROFILE (Oracle supplied PL/SQL package) to profile the execution time of the code. This will tell you which pieces of the code are slower than others. This allows you to focus on area where possible optimisation can reduce overall execution time - or it could be that these areas are already optimised.
    What you can miss with this approach is a small loop that takes a few seconds to execute - less than 1% of the total elapsed execution time. But this loop can be very wrong and should have taken a few millisecs to do. A month later running against big production data volumes, this loop's runtime changes into minutes and over 50% of the overall execution time of the process.
    You may look at the FOR CURSOR FETCH loop and see that it has been optimised. Great, so you move on to look at the next piece of code. Only, there are other loop constructs that can be exponentially faster than this loop - like a bulk processing loop instead.
    You may look at a SQL that seems slow, but after investigation it seems to be optimal. And it could well be. But performance can be increased by 80% by not touching the SQL and instead changing the table's structure from a normal heap table to a ranged partitioned table.
    The bottom line is that there are no magic wands and crystal balls that can be used to check performance and tell you that "abc" is wrong. Tools can tell you what is slow, what is resource expensive - but it cannot tell you whether the code does what it is suppose to do in the best and most effective way. Only a programmer can. Which means that things like code reviews, design walk-thru's and so on, are critical pieces to ensure that the code is performant and can scale.

  • Ckeking the SQL performance

    Hello:
    For checking the performance of my sql's I use the next SELECT:
    SELECT
    AU.username,
    SA.sql_text,
    SA.executions,
    SA.LAST_LOAD_TIME,
    SA.LAST_ACTIVE_TIME,
    SA.CPU_TIME,
    SA.ELAPSED_TIME,
    SA.OPTIMIZER_COST,
    SA.PLSQL_EXEC_TIME
    FROM v$sql SA, all_users AU
    WHERE
    SA.parsing_schema_id = AU.user_id
    --and SA.LAST_ACTIVE_TIME > to_Date('20110608 12:36','YYYYMMDD HH24:MI')
    and to_DATE(SA.LAST_LOAD_TIME,'yyyy-mm-dd/hh24-mi-ss') >=to_Date('20110608 12:36','YYYYMMDD HH24:MI')
    and SA.executions >0
    ORDER BY SA.OPTIMIZER_COST desc;
    The question is:
    How can I "reset" the values of PLSQL_EXEC_TIME, executions, CPU_TIME ... etc?
    The first time i use that SELECT usually shows values of the first PLSQL_EXEC_TIME, CPU_TIME, etc not corresponding with my concrete SELECTS execution...
    PD
    In my ORACLE there are many people using the same ORACLE user (and executing the same SQL's)... I need information of "my" process (of my SID, for exemple). How can I get the SID of the SQL in this SELECT?
    Sorry for my pooooooor english.. :-)
    Edited by: pacoKAS on 21-jun-2011 0:14

    Read through the threads referenced on the following post, they will help you to identify the causes of performance issues
    {message:id=9360003}

  • To improve the system performance of the code

    Please help me to improve the system performance of the following program. its very urgent
    report zsdr0125
              no standard page heading
    *         LINE-SIZE  170                                   " SIR 061880
              line-size  210                                   " SIR 061880
              line-count 58
              message-id zz.
    ** Report header ******************************************************
    ** Report name: Activity Costing Report
    ** Report id:   RO-01148
    ** Designed/Coded. Tori Chandler. Reporting Team.
    ** Date: March 01, 2000.
    ** Original SIR:  016113
    ** Application Area: V - Sales & Distribution  (OTC)
    ** Correction/Transport:  D10K951579
    ** Description:  It is normal business practice for logistics
    **               operations to charge business units for the activity
    **               incurred on their behalf.  This is consistent with
    **               activity based costing principles between BU and
    **               shared resources.  The activities involved are picking
    **               storage, shipping and receiving.  The purpose of this
    **               report is to provide data for the first 3.
    **      QRB2 - 03/13/2000 - Tracy, Antoine, Christian, Tori
    ** History:
    * 06/14/2001 SIR 032383 CTS                             Antoine Dailly
    * A plant (WERKS) can have several Distrib points (VSTEL)
    * SIGN = 032383
    * Modification History:
    * Date       Modified by  SIR       CTS          Description
    *11/14/2001  J.CAMPION   034606   D10K979189  Logistics Activity report
    * Logistics Activity reports
    * We added fields ship to customer and country and we also make another
    * total
    * QRB2 Tracy L. Obrien
    * Modification History:
    * Date       Modified by  SIR       CTS          Description
    *11/14/2001  J.CAMPION   37838   D10K982890      Select only
    *                                                material type HALB
    *06/12/2002  T OBrien    38784   D10K988181
    *        Allow option to get material weight from Master data or
    *        from the delivery.
    *  Modified by    SIR       CTS                         Date
    *  Jim Harwood    42730     D10K993119               10 Oct 2002
    * Description:  Code amended to default the Goods Issue Date range to
    * the previous month.  Also amended to print out the Select Options.
    *  Modified by    SIR       CTS                         Date
    *  Jim Harwood    44381     D10K994598               18 Nov 2002
    * Description:  Correct date range processing.  APPEND statement added
    * so that record is added ot internal table S_WADAT.  Also S_VKORG
    * removed as it was NO DISPLAY and nothing was assigned to it. It's use
    * in an SQL call may be causing the wrong optimization.
    *  Modified by    SIR       CTS                         Date
    *  Tori Chandler  45567     D10K995875               03 Jan 2003
    * Description:  Correct reporting of weights for non-pickable items
    *    when the Material Master Data radiobutton is selected. Also found
    *    from SIR 37838, that material type is hardcoded on the LIPS.  I
    *    created a new select option and the person needing the report
    *    can control if they want only HALB or all line items.  Also,
    *    because of this the delivery weight is obtain from header,
    *    changing to accumulate from LIPS to match which lines are selected
    *  QRB2:  1/15/2003:  Eileen, Jerome and Tori
    *{   INSERT         D11K901833                                        1
    *  Modified by    Sir             CTS                    Date
    *  Sue Kastan    48712/054042    D11K901833         28 Aug, 2003
    *  Fix overcounting of records from LIPS
    *}   INSERT
    *  Modified by    SIR       CTS                         Date          *
    *  Vijay Andea   061880    D11K918628               04/20/2006        *
    *                          D11K946194                                 *
    *  Description: Enhence ZSDR0125 Activity Cost Driver Report to allow *
    *  Analysis by Product Groupings.                                     *
    *}   INSERT
    *  Modified by            SIR       CTS                    Date       *
    *  Prakash Arunachalam  091510   D11K950288             09/26/2006    *
    *  Description: Correct Activity Cost report  - material weight       *
    *  calculation                                                        *
    *  Modified by            SIR       CTS                    Date       *
    *  Murali Krishna        301978    D50K903293            01/20/2008
    *  Description: Improve the system performance of this report and
    *               clean-up of code into various form routine
    * Table declaration.
    tables: likp,    " SD Document: Delivery Header Data
            lips,    " SD document: Delivery: Item data
            vepo,    " SD Document: Shipping Unit Item (Content)
            vekp,    " SD Document: Shipping Unit Header
            knvv,    " Customer Master Sales Data
            kna1,    " General Data in Customer Master            SIR 34606
            marm,    " Units of Measure
            mara,    " Material Master: General Data              SIR 38784
            t001l,   " Stge locs
            t001k,   " Valuation area
            tvswz,   " Shipping Points per Plant
            t134,    " Material types
            z0234.   " Alternative Unit of Measure
    *** Selection screen.
    selection-screen begin of block b1 with frame title text-001.
    parameters:     p_werks  like t001l-werks obligatory memory id wrk.
    select-options: s_lgort  for  t001l-lgort,
    *               S_VKORG  FOR  TVKO-VKORG NO-DISPLAY ," SIR 34606, 42730
    *               S_WADAT  FOR  LIKP-WADAT_IST OBLIGATORY NO-EXTENSION,
                    s_wadat  for  likp-wadat_ist no-extension,  " SIR 42730
                    s_mtart  for  t134-mtart,                   " SIR 45567
                    s_lfart  for  likp-lfart no-display no intervals.
    selection-screen skip 2.
    selection-screen comment 1(21) text-002.                    " SIR 38784
    parameters:     p_delwt  radiobutton group grp1,            " SIR 38784
                    p_mstwt  radiobutton group grp1.            " SIR 38784
    *--------------------------------------------------*Start of SIR 061880
    selection-screen skip 2.
    selection-screen comment 1(21) text-006.
    parameters:     p_voldl radiobutton group 2,     " Volume from Delivery
                    p_volmd radiobutton group 2.  " Volume from Master Data
    *-----------------------------------------------------End of SIR 061880
    selection-screen end of block b1.
    *--------------------------------------------------*Start of SIR 061880
    selection-screen begin of block b2 with frame title text-007.
    select-options: s_cbuun for knvv-kvgr1 no intervals,      " Customer BU
                    s_mbuun for mara-prdha+1(2) no intervals, " Material BU
                    s_lobus for mara-prdha+3(3) no intervals,         " LOB
                    s_pac1  for mara-prdha+6(3) no intervals.   " PAC1
    selection-screen end of block b2.
    *----------------------------------------------------*End of SIR 061880
    *---Type Declaration for Internal Tables------------------------------*
    types: begin of t_likp,
              vbeln      like likp-vbeln,  " delivery
              vstel      like likp-vstel,  " shipping point
              lfart      like likp-lfart,  " delivery type
              vkorg      like likp-vkorg,  " Sales organization
              kunag      like likp-kunag,  " sold-to party
              kunnr      like likp-kunnr,  " ship to party        SIR 34606
              btgew      like likp-btgew,  " Delivery weight
              gewei      like likp-gewei,  " Unit of weight
              anzpk      like likp-anzpk,  " Number of Packages   SIR 61880
              volum      like likp-volum,  " Delivery Volume      SIR 61880
              voleh      like likp-voleh,  " Volume Unit          SIR 61880
              vtwiv      like likp-vtwiv,  " Distribution channel
              spaiv      like likp-spaiv,  " Division
              wadat_ist  like likp-wadat_ist,  " actual goods issue date
              del_flg(1) type c,                            "(+) SIR 301978
           end of t_likp.
    types: begin of t_lips,
              vbeln      like lips-vbeln,  " delivery
              posnr      like lips-posnr,  " delivery line
              matnr      like lips-matnr,  " material
              lgort      like lips-lgort,  " storage location
              prodh      like lips-prodh,  " product hierarchy
              meins      like lips-meins,  " base UoM
              brgew      like lips-brgew,  " Material weight
              gewei      like lips-gewei,  " Unit of weight
              volum      like lips-volum,  " Material Volume      SIR 61880
              voleh      like lips-voleh,  " Volume Unit          SIR 61880
              lgmng      like lips-lgmng,  " actual delivery quantity
              komkz      like lips-komkz,  " Indicator for picking control
              mtart      like lips-mtart,  " Material type      " SIR 37838
              del_flg(1) type c,                            "(+) SIR 301978
           end of t_lips.
    types: begin of t_vepo,
              venum      like vepo-venum,  " shipping unit number
              vbeln      like vepo-vbeln,  " delivery
           end of t_vepo.
    types: begin of t_vekp,
              venum      like vekp-venum,  " shipping unit number
              brgew      like vekp-brgew,  " actual weight
              gewei_max  like vekp-gewei_max,  " unit of weight
              vpobjkey   like vekp-vpobjkey,   " key for assigned object
           end of t_vekp.
    types: begin of t_knvv,
              kunnr      like knvv-kunnr,  " customer number
              ktgrd      like knvv-ktgrd,  " acct assign group
              kvgr1      like knvv-kvgr1,  " customer group 1
           end of t_knvv.
    types: begin of t_kna1,                                     " SIR 34606
              kunnr      like kna1-kunnr,  " customer number    " SIR 34606
              land1      like kna1-land1,  " contry             " SIR 34606
           end of t_kna1.                                       " SIR 34606
    types: begin of t_marm,
              matnr      like marm-matnr,  " material
              meinh      like marm-meinh,  " Alt unit of measure     032383
              umrez      like marm-umrez,  " numerator
              umren      like marm-umren,  " denominator
           end of t_marm.
    types: begin of t_mara,                                     " SIR 38784
              matnr      like mara-matnr,  " material           " SIR 38784
              prdha      like mara-prdha,  " Product Hierarchy  " SIR 61880
              brgew      like lips-brgew,  " gross weight       " SIR 38784
              gewei      like mara-gewei,  " Unit of weight     " SIR 38784
              volum      like mara-volum,  " Volume             " SIR 61880
              voleh      like mara-voleh,  " Volume Unit        " SIR 61880
              del_flg(1) type c,                            "(+) SIR 301978
           end of t_mara.                                       " SIR 38784
    types: begin of t_tvswz,
              vstel      like tvswz-vstel, " shipping point
           end of t_tvswz.
    types: begin of t_z0234,                                        "032383
              vstel      like z0234-vstel, " shipping point          032383
              zpaluom    like z0234-zpaluom," pallet unit of measure 032383
              zcsuom     like z0234-zcsuom," Case unit of measure    032383
           end of t_z0234.                                          "032383
    types: begin of t_output_dt,
              wadat_ist    like likp-wadat_ist, " Goods issue date
              ktgrd        like knvv-ktgrd," acct assign group
              bu           like knvv-kvgr1," business unit
              kunnr        like kna1-kunnr," ship to location     SIR 34606
              land1        like kna1-land1," ship to location     SIR 34606
              d_btgew      like likp-btgew," delivery weight
              m_brgew      like lips-brgew," material weight
              a_brgew      like vekp-brgew," actual weight of ship unit
              num_del      type i,         " counter of deliveries
              num_pallets  type i,         " number of pallets
              num_cases    type i,         " number of cases
              num_loose    type i,         " loose quantity
              num_delln    type i,         " counter of delivery lines
    *         packages     like likp-anzpk," Number of Packages " SIR 61880
              packages(3)  type p,         " Number of Packages " SIR 61880
              volume       like lips-volum," Volume             " SIR 61880
              lobus(3)     type c,         " Line of Business   " SIR 61880
              pac1(3)      type c,                    " PAC1    " SIR 61880
           end of t_output_dt.
    types: begin of t_output_ag,
              ktgrd        like knvv-ktgrd," acct assign group
              bu           like knvv-kvgr1," business unit
              land1        like kna1-land1," country              SIR 34606
              d_btgew      like likp-btgew," delivery weight
              m_brgew      like lips-brgew," material weight
              a_brgew      like vekp-brgew," actual weight of ship unit
              num_del      type i,         " counter of deliveries
              num_pallets  type i,         " number of pallets
              num_cases    type i,         " number of cases
              num_loose    type i,         " loose quantity
              num_delln    type i,         " counter of delivery lines
    *         packages     like likp-anzpk," Number of Packages " SIR 61880
              packages(3)  type p,         " Number of Packages " SIR 61880
              volume       like lips-volum," Volume             " SIR 61880
              lobus(3)     type c,         " Line of Business   " SIR 61880
              pac1(3)      type c,                   " PAC1     " SIR 61880
           end of t_output_ag.
    types: begin of t_output_gs,                                " SIR 34606
              ktgrd        like knvv-ktgrd," acct assign group  " SIR 34606
              bu           like knvv-kvgr1," business unit      " SIR 34606
              d_btgew      like likp-btgew," delivery weight    " SIR 34606
              m_brgew      like lips-brgew," material weight    " SIR 34606
              a_brgew      like vekp-brgew," actual weight      " SIR 34606
              num_del      type i,         " counter of deliv   " SIR 34606
              num_pallets  type i,         " number of pallets  " SIR 34606
              num_cases    type i,         " number of cases    " SIR 34606
              num_loose    type i,         " loose quantity     " SIR 34606
              num_delln    type i,         " counter of deliv   " SIR 34606
    *         packages     like likp-anzpk, " Number of Package " SIR 61880
              packages(3)  type p,          " Number of Packages" SIR 61880
              volume       like lips-volum, " Volume            " SIR 61880
              lobus(3)     type c,          " Line of Business  " SIR 61880
              pac1(3)      type c,           " PAC1             " SIR 61880
           end of t_output_gs.                                  " SIR 34606
    *-------------------------------------------------* Begin of SIR 061880
    * Material Type
    types: begin of t_mtart,
           mtart like t134-mtart,                           " Material Type
           end of t_mtart.
    * Customer Business Unit.
    types: begin of t_kvgr1,
           kvgr1 like knvv-kvgr1,                        " Customer Group 1
           end of t_kvgr1.
    * sales Organization.
    types: begin of t_lgort,
           lgort like t001l-lgort,                     " Sales Organization
           end of t_lgort.
    *                                                   Begin of SIR 301978
    *      Header: Material Document
    types: begin of t_mkpf,
             vgart    type mkpf-vgart,
             xblnr    type likp-vbeln,
           end   of t_mkpf.
    *                                                     End of SIR 301978
    *---------------------------------------------------* End of SIR 061880
    *---Internal Tables---------------------------------------------------*
    data:  i_likp        type  t_likp occurs 0 with header line,
           i_temp_likp   type  t_likp occurs 0 with header line,
           v_likp        type  t_likp,
           i_lips        type  t_lips occurs 0 with header line,
           i_temp_lips   type  t_lips occurs 0 with header line,
           v_lips        type  t_lips,
           i_vepo        type  t_vepo occurs 0,
    *      V_VEPO        TYPE  T_VEPO,
           i_vekp        type  t_vekp occurs 0,
           v_vekp        type  t_vekp,
           i_knvv        type  t_knvv occurs 0 with header line,
           v_knvv        type  t_knvv,
           i_kna1        type  t_kna1 occurs 0,                 " SIR 34606
           v_kna1        type  t_kna1,                          " SIR 34606
           i_z0234       type  t_z0234 occurs 0,                "    032383
           v_z0234       type  t_z0234,                         "    032383
           i_z0234_uom   type  t_z0234 occurs 0,                "    032383
           v_z0234_uom   type  t_z0234,                         "    032383
           i_marm        type  t_marm occurs 0 with header line," SIR 61880
           i_marm_pallet type  t_marm occurs 0 with header line,
           v_marm_pallet type  t_marm,
           i_marm_case   type  t_marm occurs 0 with header line,
           v_marm_case   type  t_marm,
    *-------------------------------------------------* Begin of SIR 061880
    *      I_MARA        TYPE  T_MARA OCCURS 0,                 " SIR 38784
           i_mara1       type  t_mara  occurs 0 with header line,
           i_mtart       type  t_mtart occurs 0 with header line,
           i_kvgr1       type  t_kvgr1 occurs 0 with header line,
           i_lgort       type  t_lgort occurs 0 with header line,
           v_kvgr1       type  t_kvgr1,
    *---------------------------------------------------* End of SIR 061880
           v_mara        type  t_mara,                          " SIR 38784
           i_tvswz       type  t_tvswz occurs 0,
           v_tvswz       type  t_tvswz,                     "(+) SIR 301978
           i_output_dt   type  t_output_dt occurs 0,
           v_output_dt   type  t_output_dt,
           i_output_ag   type  t_output_ag occurs 0,
           v_output_ag   type  t_output_ag,
           i_output_gs   type  t_output_gs occurs 0,            " SIR 34606
           v_output_gs   type  t_output_gs,                     " SIR 34606
           i_mkpf        type  table of t_mkpf with header line."SIR 301978
    *** Data Declarations *
    data:  v_page(3)        type c,                          " Page Counter
           v_comp           like t001k-bukrs,       " zbsn0001 company code
           v_title(24)      type c,                 " zbsn0001 report title
           v_rpttyp         type c,                           " report type
           v_ok             type c,             " control While... endwhile
           v_diff_date      type p,                " days between selection
           v_werks          like t001l-werks,                       " plant
    *      v_z0234_zpaluom  like z0234-zpaluom,  " Pallet Unit of Measure
    *      v_z0234_zcsuom   like z0234-zcsuom,   " Case Unit of Measure
           v_palwto         type p decimals 6,                 " SIR 091510
    *       "like likp-btgew,       " Weight after conversion
           v_vekp_tabix     like sy-tabix,                  " index on read
           v_vekp_sum_brgew like vekp-brgew,                " actual weight
           v_pallet_qty     like lips-lgmng,        " calculated pallet qty
           v_pallet_integer type i,                       " true pallet qty
           v_case_qty       like lips-lgmng,          " calculated case qty
           v_case_integer   type i,                         " true case qty
           v_qty_not_pallets like lips-lgmng,                  " calculated
           v_num_pallets    like lips-lgmng,    " calculated nbr of pallets
           v_num_pallets_int type i,                  " true nbr of pallets
           v_num_cases      like lips-lgmng,      " calculated nbr of cases
           v_num_cases_int  type i,                     " true nbr of cases
           v_total_case_qty like lips-lgmng,                " case quantity
           v_loose_qty      type i,             " calculated loose quantity
    *-------------------------------------------------* Begin of SIR 061880
           v_volume         like lips-volum,      " Volume After Convertion
           v_cbuun          like knvv-kvgr1,                  " Customer BU
           v_mbuun          like knvv-kvgr1,                  " Material BU
           v_lobus(3)       type c,                      " Line of Business
           v_pac1(3)        type c,                                  " PAC1
           v_flag           type c.            " Flag Indicator for No Data
    *---------------------------------------------------* End of SIR 061880
    *                                                   Begin of SIR 301978
    * Ranges
    ranges : r_vstel for tvswz-vstel.
    *                                                     End of SIR 301978
    * Constants
    data:  c_uom(3)        type c value 'KG'.    " Kilogram Unit of Meas.
    data : c_vom like mara-voleh value 'M3'.   " Metter Cube.  " SIR 061880
    constants : c_wl(2) type c value 'WL'.                  "(+) SIR 301978
    * Initialization.
    initialization.
      s_lfart-sign   = 'I'.
      s_lfart-option = 'EQ'.
      s_lfart-low    = 'LF  '.
      append s_lfart.
      s_lfart-low    = 'NL  '.
      append s_lfart.
      s_lfart-low    = 'NLCC'.
      append s_lfart.
      s_lfart-low    = 'ZLFI'.
      append s_lfart.
    * AT SELECTION-SCREEN.
    at selection-screen.
    * SIR 42730 - If no Goods Issue Date has been specified in the
    *             Select Options set the range to the previous month.
      if s_wadat-low is initial.
        s_wadat-sign      = 'I'.
        s_wadat-option    = 'BT'.
        s_wadat-high      = sy-datum.              " Today's date
        s_wadat-high+6(2) = '01'.                  " First of this month
        s_wadat-high      = s_wadat-high - 1.      " End of last month
        s_wadat-low       = s_wadat-high.          " End of last month
        s_wadat-low+6(2)  = '01'.                  " First of last month
        append s_wadat.
      endif.     " SIR 42730 IF S_WADAT-LOW IS INITIAL.
      clear v_werks.                                        "(+) SIR 301978
    * Validate Plant/Storage Location from selection screen
      select werks up to 1 rows into v_werks from t001l
            where werks =  p_werks  and
                  lgort in s_lgort.
      endselect.
      if sy-subrc ne 0.
        message e045 with text-e01.
      endif.
    * Validate Storage Location
      if not s_lgort[] is initial.
        select lgort from t001l into table i_lgort where lgort in s_lgort.
        if sy-subrc ne 0.
          message e045 with text-e09.
        endif.
      endif.
    * Validate date range.  do not allow more that 31 days
      if not s_wadat-high is initial.
        v_diff_date = s_wadat-high - s_wadat-low.
        if v_diff_date >= '31'.
          message e045 with text-e02.
        endif.
      endif.
    *-------------------------------------------------* Begin of SIR 061880
    * Validation for Material Type in Selection Screen
      if not s_mtart[] is initial.
        select mtart from t134 into table i_mtart where mtart in s_mtart.
        if sy-subrc ne 0.
          message e045 with text-e07.
        endif.
      endif.
    at selection-screen on block b2.
    * Validation for Material Business Unit and Customer Business Unit.
      if s_cbuun-low is not initial and s_mbuun-low is not initial.
        message e045 with text-e05.
      endif.
    * Validation for Possible combinations of Material BU, Line of Business
    * and PAC1
      if ( s_mbuun-low is not initial and s_lobus-low is not initial
                                    and s_pac1-low is not initial )
      or ( s_mbuun-low is not initial and s_lobus-low is not initial )
      or ( s_lobus-low is not initial and s_pac1-low is not initial )
      or ( s_mbuun-low is not initial and s_pac1-low is not initial ).
        message e045 with text-e06.
      endif.
    * Validation for Customer Business Unit.
      if not s_cbuun[] is initial.
        select kvgr1 from tvv1 into table i_kvgr1 where kvgr1 in s_cbuun.
        if sy-subrc ne 0.
          message e045 with text-e08.
        endif.
    *    free: i_kvgr1.
      endif.
    *---------------------------------------------------- End of SIR 061880
    * TOP-OF-PAGE
    * Top of the page routine to print the headers and columns
    top-of-page.
      format color col_heading on.
      if v_rpttyp = 'D'.
        v_title = text-h01.
      else.
        v_title = text-h02.
      endif.
      perform zbsn0001_standard_header     " Standard Report Heading Form
               using v_comp v_title 'U' v_page.
      skip.
      if v_rpttyp = 'D'.
        perform write_dtlvl_headings.
      else.
        perform write_aglvl_headings.
      endif.
    *       FORM WRITE_DTLVL_HEADINGS                                     *
    *   for date detail level, print the column headers                   *
    form write_dtlvl_headings.
      write: /001 text-h03,                " Acct
              038 text-h04,                " ------ P I C K I N G ------
              105 text-h05,                " ----- S H I P P I N G -----
             /001 text-h06,                " Group
              007 text-h07,                " Date
              017 text-h08,                " BU
              021 text-h17,                " ship to party            34606
              030 text-h18,                " country
              039 text-h09,                " Pallets
              057 text-h10,                " Cases
              075 text-h11,                " Loose
              093 text-h12,                " Lines
              105 text-h13,                " Material Kg
              124 text-h16,                " Delivery Kg
              143 text-h14,                " Actual Kg
              161 text-h15,                " Deliveries
    *----------------------------------------------------Start of SIR 61880
              173 text-h20,                " Packages
              189 text-h21,                " Volume
              201 text-h22,                " LOB
              207 text-h23.                " PAC1
    *-----------------------------------------------------*End of SIR 61880
      skip.
    endform.                               " end of write_dtlvl_headings.
    *       FORM WRITE_AGLVL_HEADINGS                                     *
    *      for account group detail level, print the column headers       *
    form write_aglvl_headings.
      write: /001 text-h03,                " Acct
              038 text-h04,                " ------ P I C K I N G ------
              105 text-h05,                " ----- S H I P P I N G -----
             /001 text-h06,                " Group
              017 text-h08,                " BU
              030 text-h18,                " country              SIR 34606
              039 text-h09,                " Pallets
              057 text-h10,                " Cases
              075 text-h11,                " Loose
              093 text-h12,                " Lines
              105 text-h13,                " Material Kg
              124 text-h16,                " Delivery Kg
              143 text-h14,                " Actual Kg
              161 text-h15,                " Deliveries
    *---------------------------------------------------*Start of SIR 61880
              173 text-h20,                " Packages
              189 text-h21,                " Volume
              201 text-h22,                " LOB
              207 text-h23.                " PAC1
    *-----------------------------------------------------*End of SIR 61880
      skip.
    endform.                               " end of write_aglvl_headings.
    *-------------------------- SUBBROUTINES -----------------------------*
    include zbsn0001.      " Include to print all Standard Report Titles
    include zsdn0004.      " Print the Select Options
    *** MAIN SELECTION.                                                   *
    start-of-selection.
      refresh:  i_likp, i_temp_likp, i_lips, i_temp_lips, i_vepo,
                i_vekp, i_knvv, i_marm_pallet, i_marm_case, i_tvswz,
                i_output_dt, i_output_ag, i_mara1.
      clear:    v_likp, v_lips, v_vekp, v_knvv, v_mara,
                v_marm_pallet, v_marm_case, v_output_dt, v_output_ag.
      v_rpttyp = 'D'.
    * SIR 42730 - Echo the Select Options to the output listing and print
    *             the Goods Issue Date range being used.
      write: /,/.     " SIR 43730 - Skip a couple of lines to centre it.
      perform zsdn0004_print_select_options using sy-cprog ' '.
      if s_wadat-high is initial.
        write: /,/, text-003, 34 s_wadat-low.
      else.
        write: /,/, text-003, 34 s_wadat-low, 44 text-004, 47 s_wadat-high.
      endif.
      new-page.
    * Main Processing.                                                    *
      perform get_data.
      if not i_lips[] is initial.
        perform create_output.
      endif.
    * END-OF-SELECTION
    end-of-selection.
    *-------------------------------------------------* Start of SIR 061880
    *   PERFORM WRITE_REPORT.
      if not i_output_dt[] is initial and not i_output_ag[] is initial and
                                          not i_output_gs[] is initial.
        perform write_report.
      else.
        skip 2.
        write:/ text-e03.
        skip 2.
        uline.
        clear: v_flag.
      endif.
    *---------------------------------------------------* End of SIR 061880
    *       FORM GET_DATA                                                 *
    * build all of the internal tables needed for the report              *
    * selects on t001k, z0234, likp, lips, vepo, vekp, knvv & marm, mara  *
    form get_data.
      perform get_data_t001k.                                  " SIR 301978
      perform get_data_tvswz.                                  " SIR 301978
      if sy-subrc = 0.                     " Build shipping point range
        perform get_data_Z0234.                                " SIR 301978
        if sy-subrc ne 0.
          v_flag = 'X'.
    *      stop.
        else.
          sort i_z0234 by vstel.                                   " 032383
        endif.
    *                                                  Begin of  SIR 301978
    *   The data retrievalfrom LIKP has been modified for performance
    *   reasons
        perform get_data_mkpf.                                 " SIR 301978
        if sy-subrc eq 0.
    *     Deleting data other than Goods issued for delivery
          delete i_mkpf where vgart ne c_wl.
          sort i_mkpf by xblnr.
        endif.
    *   Deleting the data from the internal table i_likp by comparing
    *   shipping point
        r_vstel-sign = 'I'.
        r_vstel-option = 'EQ'.
        clear : v_tvswz.
        loop at i_tvswz into v_tvswz.
          r_vstel-low = v_tvswz-vstel.
          append r_vstel.
        endloop.
        if not i_mkpf[] is initial.
          perform get_data_likp.                             " SIR 301978
        endif.
        if sy-subrc = 0.
          delete i_likp where not lfart in s_lfart.
    *                                                  End    of SIR 301978
    *     Get data for the delivery lines
          if not i_likp[] is initial.
            perform get_data_lips.                         " SIR 301978
    *                                                  Begin of SIR 301978
            if i_lips[] is initial.
              v_flag = 'X'.
              message i089 with text-i02.
              leave list-processing.
            endif.                    " Return code for LIPS select
    *                                                     End of SIR 301978
          endif.
    *-------------------------------------------------* Begin of SIR 061880
    *     Get Data From MARA (Material Master) to Read Material Weight and
    *     Material Voluem from Master Data.
          if not i_lips[] is initial.
    *                                                   Begin of SIR 301978
    *       Delete the duplicate material from delivery item table
            i_temp_lips[] = i_lips[].
            sort i_temp_lips by matnr.
            delete adjacent duplicates from i_temp_lips comparing matnr.
            perform get_data_mara.                         " SIR 301978
            if sy-subrc = 0.
              sort i_mara1 by matnr.
              clear i_temp_lips.
              refresh i_temp_lips.
    *                                                     End of SIR 301978
            else.
              v_flag = 'X'.
              message i089 with text-i01.
              leave list-processing.
            endif.
          endif.
    *     Filter I_LIPS and I_MARA1 When Either material BU or Line of
    *     Business (LOB) or PAC1 are not left Balnk
          perform filter_data_for_prdha.
    *     Get data for the sold-to customer
          perform i_knvv_fill_data.
    *    Filter I_LIKP & I_LIPS & I_MARA for Cust-BU, When Cust-Bu is not
    *    left Blank.
          perform filter_likp_lips_mara_custbu.
    *---------------------------------------------------- End of SIR 061880
    *-------------------------------------------------* Begin of SIR 034606
    *     Get data for the ship to party
          i_temp_likp[]  = i_likp[].
          sort i_temp_likp by kunnr.
          delete adjacent duplicates from i_temp_likp comparing kunnr.
          perform get_data_kna1.                             " SIR 301978
          if sy-subrc = 0.
            sort i_kna1 by kunnr.
          endif.
    *---------------------------------------------------* End of SIR 034606
        else.
          v_flag = 'X'.
          message i089 with text-i04.
          leave list-processing.
        endif.                               " return code to LIKP select
    *    endif.                                                " SIR 061880
        free: i_temp_likp.
      endif.                               " return code for TVSWZ select
    * Process table LIPS
      if not i_lips[] is initial.
        i_temp_lips[] = i_lips[].
        sort i_temp_lips by vbeln.
        delete adjacent duplicates from i_temp_lips comparing vbeln.
    *   Get actual weight
        perform get_data_vepo.                                 " SIR 301978
        if sy-subrc = 0.
          sort i_vepo by venum.
          delete adjacent duplicates from i_vepo comparing venum.
          perform get_data_vekp.                               " SIR 301978
          sort i_vekp by vpobjkey.
        endif.
        free:  i_vepo, i_temp_lips.
        i_temp_lips[] = i_lips[].
        sort i_temp_lips by matnr.
        delete adjacent duplicates from i_temp_lips comparing matnr.
    *   Get Units of Measure for Material
        perform read_data_from_marm.                           " SIR 061880
    *                                                   Begin of SIR 032383
        i_z0234_uom = i_z0234.
        sort i_z0234_uom by zpaluom.
        delete adjacent duplicates from i_z0234_uom comparing zpaluom.
    *                                                   End   of SIR 032383
        clear i_marm_pallet.                                   " SIR 061880
        refresh  i_marm_pallet.                                " SIR 061880
        loop at i_z0234_uom into v_z0234_uom.             "LOOP Z0234 032383
    *-------------------------------------------------* Begin of SIR 061880
    *     Get Alternative Unit of Measure for Pallets
          perform i_marm_pallet_fill.
        endloop.                                      "ENDLOOP Z0234 032383
    ** get alternative UoM for pallets
    *      SELECT MATNR                     " material
    *             MEINH                     " Alt unit of measure  " 032383
    *             UMREZ                     " numerator
    *             UMREN                     " denominator
    **     into table i_marm_pallet                                " 032383
    *      APPENDING TABLE I_MARM_PALLET                            "032383
    *      FROM MARM
    *      FOR ALL ENTRIES IN I_TEMP_LIPS
    *      WHERE MATNR = I_TEMP_LIPS-MATNR  AND
    **           meinh = v_z0234_zpaluom.                          " 032383
    *            MEINH = V_Z0234_UOM-ZPALUOM.                      " 032383
    *---------------------------------------------------* End of SIR 061880
        sort i_marm_pallet by matnr meinh.
        free i_z0234_uom.                                           "032383
        i_z0234_uom = i_z0234.                                      "032383
        sort i_z0234_uom by zcsuom.                                 "032383
        delete adjacent duplicates from i_z0234_uom comparing zcsuom."32383
        clear i_marm_case.                                     " SIR 061880
        refresh i_marm_case.                                   " SIR 061880
        loop at i_z0234_uom into v_z0234_uom.            "LOOP Z0234 032383
    *-------------------------------------------------* Begin of SIR 061880
    *     Get Alternative Unit of Measure for Cases
          perform i_marm_case_fill.
        endloop.                                      "ENDLOOP Z0234 032383
    *---------------------------------------------------* End of SIR 061880
        sort i_marm_case by matnr meinh.
      else.
        v_flag = 'X'.
        message i089 with text-i02.
    *      leave list-processing.
      endif.                               " table LIPS is empty
    endform.                               " get_data
    *       FORM CREATE_OUTPUT                                            *
    * process internal table LIPS, for each delivery/delivery lines create*
    * an output record and collect into i_output internal table.  Fields  *
    * used for header are goods issue date, acct assign, BU for customer, *
    * total weight, total weight for shipping unit and count of           *
    * deliveries, the remaining fields will have a value of zero for the  *
    * collect.  For each delivery line, fields used are goods issue date, *
    * acct assign, BU for material, number of pallets, number of cases,   *
    * loose quantity and number of delivery lines.  The remaining header  *
    * fiels will be zero for the collect.                                 *
    form create_output.
    *-------------------------------------------------* Begin of SIR 061880
      sort i_mara1 by matnr.
      sort i_lips by vbeln posnr matnr.
      sort i_likp by vbeln.
      sort i_z0234 by vstel.
      sort i_knvv by kunnr.
      sort i_kna1 by kunnr.
      sort i_vekp by vpobjkey.
      sort i_marm_pallet by matnr meinh.
      sort i_marm_case by matnr meinh.
    * LOOP AT I_LIPS INTO V_LIPS.
      loop at i_lips.
        clear v_lips.
        v_lips = i_lips.
    *---------------------------------------------------* End of SIR 061880
        at new vbeln.
          perform collect_header_data.
        endat.
        if not v_lips-komkz is initial.                         " SIR 45567
          perform collect_item_data.
        endif.                                                  " SIR 45567
      endloop.
    endform.                               " create_output
    *       FORM COLLECT_HEADER_DATA                                      *
    * Fields used for header are goods issue date, acct assign,           *
    * BU for customer, total weight, total weight for shipping unit       *
    * and count ofdeliveries, the remaining fields will have a value of   *
    * zero for the collect.                                               *
    form collect_header_data.
      clear:  v_likp, v_knvv, v_vekp, v_vekp_sum_brgew.
      v_ok = 'Y'.
      read table i_likp into v_likp with key vbeln = v_lips-vbeln
                                                   binary search.
      if sy-subrc = 0.                                         " SIR 061880
        clear v_z0234.                                      "(+) SIR 301978
        read table i_z0234 into v_z0234                              "32383
             with key vstel = v_likp-vstel                           "32383
             binary search.                                          "32383
        read table i_knvv into v_knvv with key kunnr = v_likp-kunag
                                                     binary search.
        if sy-subrc ne 0.
          select single ktgrd kvgr1 into (v_knvv-ktgrd, v_knvv-kvgr1)
            from knvv where kunnr = v_likp-kunag  and
                            vkorg = v_likp-vkorg  and
                           vtweg = '01' and          " intercompany values
                           spart = '01'.             " intercompany values
        endif.
        clear v_kna1.                                           " SIR 34606
        read table i_kna1 into v_kna1                           " SIR 34606
           with key kunnr = v_likp-kunnr                        " SIR 34606
           binary search.                                       " SIR 34606
        read table i_vekp into v_vekp
           with key vpobjkey(10) = v_likp-vbeln
           binary search.
        if sy-subrc = 0.
          v_vekp_tabix = sy-tabix.
          while v_ok = 'Y'.
            if v_vekp-gewei_max ne c_uom.
              perform z_unit_conversion
                using v_vekp-brgew v_vekp-gewei_max c_uom v_palwto.
              v_vekp_sum_brgew = v_vekp_sum_brgew + v_palwto.
            else.
              v_vekp_sum_brgew = v_vekp_sum_brgew + v_vekp-brgew.
            endif.
            v_vekp_tabix = v_vekp_tabix + 1.
            read table i_vekp into v_vekp
               index v_vekp_tabix.
            if sy-subrc = 0.
              if v_vekp-vpobjkey(10) ne v_likp-vbeln.
                v_ok = 'N'.
              endif.
            else.
              v_ok = 'N'.
            endif.
          endwhile.
        endif.
      endif.                                                   " SIR 061880
    * populate output tables
      clear: v_output_dt, v_output_ag,v_output_gs.              " SIR 34606
      v_output_dt-wadat_ist = v_likp-wadat_ist.
      v_output_dt-ktgrd     = v_knvv-ktgrd.
      v_output_ag-ktgrd     = v_knvv-ktgrd.
      v_output_gs-ktgrd     = v_knvv-ktgrd.                     " SIR 34606
    *-------------------------------------------------* Begin of SIR 061880
    *  V_OUTPUT_DT-BU        = V_KNVV-KVGR1.
    *  V_OUTPUT_AG-BU        = V_KNVV-KVGR1.
    *  V_OUTPUT_GS-BU        = V_KNVV-KVGR1.                    " SIR 34606
    * Populate Business Unit,Line of Busness and PAC1 Values in Header Data
      perform get_busunit_lobus_pac1_data1.
    *---------------------------------------------------* End of SIR 061880
      v_output_dt-kunnr = v_kna1-kunnr.                         " SIR 34606
    * V_OUTPUT_AG-KUNNR = V_KNA1-KUNNR.                         " SIR 34606
      v_output_dt-land1 = v_kna1-land1.                         " SIR 34606
      v_output_ag-land1 = v_kna1-land1.                         " SIR 34606
      v_output_dt-a_brgew     = v_vekp_sum_brgew.
      v_output_ag-a_brgew     = v_vekp_sum_brgew.
      v_output_gs-a_brgew     = v_vekp_sum_brgew.               " SIR 34606
      if s_mbuun[] is initial and                               " SIR 61880
         s_lobus[] is initial and                               " SIR 61880
         s_pac1[] is  initial.                                  " SIR 61880
        v_output_dt-num_del   = 1.
        v_output_ag-num_del   = 1.
        v_output_gs-num_del   = 1.                              " SIR 34606
    *-------------------------------------------------* Begin of SIR 061880
    * Number of Packages
        v_output_dt-packages   = v_likp-anzpk.
        v_output_ag-packages   = v_likp-anzpk.
        v_output_gs-packages   = v_likp-anzpk.
      else.
        clear: v_output_dt-num_del,
               v_output_ag-num_del,
               v_output_gs-num_del,
               v_output_dt-packages,
               v_output_ag-packages,
               v_output_gs-packages.
      endif.
    *---------------------------------------------------* End of SIR 061880
      collect v_output_dt into i_output_dt.
      collect v_output_ag into i_output_ag.
      collect v_output_gs into i_output_gs.                     " SIR 34606
    endform.                               " collect_header_data
    *       FORM COLLECT_ITEM_DATA                                        *
    * For each delivery line, fields used are goods issue date,           *
    * acct assign, BU for material, number of pallets, number of cases,   *
    * loose quantity and number of delivery lines.  The remaining header  *
    * fiels will be zero for the collect.                                 *
    form collect_item_data.
      clear:  v_pallet_qty,      v_pallet_integer,
              v_case_qty,        v_case_integer,
              v_num_pallets,     v_num_pallets_int,
              v_num_cases,       v_num_cases_int,
              v_qty_not_pallets, v_total_case_qty, v_loose_qty.
      read table i_marm_pallet into v_marm_pallet
                 with key matnr = v_lips-matnr
                          meinh = v_z0234-zpaluom binary search."32382
      if sy-subrc = 0.
        v_pallet_qty = v_marm_pallet-umrez / v_marm_pallet-umren.
    * round down partial pallets
        v_pallet_integer = v_pallet_qty - '.499'.
      endif.
      read table i_marm_case into v_marm_case
                  with key matnr = v_lips-matnr
                           meinh = v_z0234-zcsuom binary search."32382
      if sy-subrc = 0.
        v_case_qty = v_marm_case-umrez / v_marm_case-umren.
    * round down partial cases
        v_case_integer = v_case_qty - '.499'.
      endif.
      if v_pallet_integer > 0.
        v_num_pallets     = v_lips-lgmng / v_pallet_integer.
        v_num_pallets_int = v_num_pallets - '.499'.
      endif.
      v_qty_not_pallets = v_lips-lgmng -
                          ( v_num_pallets_int * v_pallet_integer ).
      if v_case_integer > 0.
        v_num_cases     = v_qty_not_pallets / v_case_integer.
        v_num_cases_int = v_num_cases - '.499'.
      endif.
      v_total_case_qty     = v_num_cases_int * v_case_integer.
      if v_qty_not_pallets = v_total_case_qty.
        v_loose_qty = 0.
      else.
        v_loose_qty = 1.
      endif.
    * populate output tables
      clear: v_output_dt, v_output_ag, v_output_gs.             " SIR 34606
      v_output_dt-wadat_ist   = v_likp-wadat_ist.
      v_output_dt-ktgrd       = v_knvv-ktgrd.
      v_output_ag-ktgrd       = v_knvv-ktgrd.
      v_output_gs-ktgrd       = v_knvv-ktgrd.                   " SIR 34606
      v_output_dt-kunnr = v_kna1-kunnr.                         " SIR 34606
    * V_OUTPUT_AG-KUNNR = V_KNA1-KUNNR.                         " SIR 34606
      v_output_dt-land1 = v_kna1-land1.                         " SIR 34606
      v_output_ag-land1 = v_kna1-land1.                         " SIR 34606
    *-------------------------------------------------* Begin of SIR 061880
    *  V_OUTPUT_DT-BU          = V_LIPS-PRODH+1(2).
    *  V_OUTPUT_AG-BU          = V_LIPS-PRODH+1(2).
    *  V_OUTPUT_GS-BU          = V_LIPS-PRODH+1(2).             " SIR 34606
    * Populate Business Unit,Line of Business and PAC1 Values for Item Data.
      perform get_busunit_lobus_pac1_data2.
      if V_OUTPUT_DT-BU is initial.
       clear V_OUTPUT_DT.
       exit.
      endif.
    *---------------------------------------------------* End of SIR 061880
    * get delivery weight from delivery lines instead of header " SIR 45567
      if v_lips-gewei = c_uom.
        v_output_dt-d_btgew  = v_lips-brgew.
        v_output_ag-d_btgew  = v_lips-brgew.
        v_output_gs-d_btgew  = v_lips-brgew.                    " SIR 34606
      else.
        perform z_unit_conversion
             using v_lips-brgew v_lips-gewei c_uom v_palwto.
        v_output_dt-d_btgew  = v_palwto.
        v_output_ag-d_btgew  = v_palwto.
        v_output_gs-d_btgew  = v_palwto.                        " SIR 34606
      endif.
    * Get material weight from delivery (LIPS)(IF P_DELWT = 'X')" SIR 38784
      if p_delwt = 'X'.                                         " SIR 38784
        if v_lips-gewei = c_uom.
          v_output_dt-m_brgew  = v_lips-brgew.
          v_output_ag-m_brgew  = v_lips-brgew.
          v_output_gs-m_brgew  = v_lips-brgew.                  " SIR 34606
        else.
          perform z_unit_conversion
               using v_lips-brgew v_lips-gewei c_uom v_palwto.
          v_output_dt-m_brgew  = v_palwto.
          v_output_ag-m_brgew  = v_palwto.
          v_output_gs-m_brgew  = v_palwto.                      " SIR 34606
        endif.
      else.                                                     " SIR 38784
    * Get material weight from Master data (MARA)               " SIR 38784
        read table i_mara1 into v_mara                          " SIR 38784
                               with key matnr = v_lips-matnr    " SIR 38784
                               binary search.                   " SIR 38784
        if v_mara-gewei = c_uom.                                " SIR 38784
          v_output_dt-m_brgew  = v_mara-brgew * v_lips-lgmng.   " SIR 38784
          v_output_ag-m_brgew  = v_mara-brgew * v_lips-lgmng.   " SIR 38784
          v_output_gs-m_brgew  = v_mara-brgew * v_lips-lgmng.   " SIR 38784
        else.                                                   " SIR 38784
          perform z_unit_conversion                             " SIR 38784
               using v_mara-brgew v_mara-gewei c_uom v_palwto.  " SIR 38784
          v_output_dt-m_brgew  = v_palwto * v_lips-lgmng.       " SIR 38784
          v_output_ag-m_brgew  = v_palwto * v_lips-lgmng.       " SIR 38784
          v_output_gs-m_brgew  = v_palwto * v_lips-lgmng.       " SIR 38784
        endif.                                                  " SIR 38784
      endif.                                                    " SIR 38784
    *-------------------------------------------------* Begin of SIR 061880
    * To Get the Volume Data.
      perform get_volume_data.
    *---------------------------------------------------* End of SIR 061880
      v_output_dt-num_pallets = v_num_pallets_int.
      v_output_ag-num_pallets = v_num_pallets_int.
      v_output_gs-num_pallets = v_num_pallets_int.              " SIR 34606
      v_output_dt-num_cases   = v_num_cases_int.
      v_output_ag-num_cases   = v_num_cases_int.
      v_output_gs-num_cases   = v_num_cases_int.                " SIR 34606
      v_output_dt-num_loose   = v_loose_qty.
      v_output_ag-num_loose   = v_loose_qty.
      v_output_gs-num_loose   = v_loose_qty.                    " SIR 34606
    *{   INSERT         D11K901833                                        1
    * Sir 054042/48712 insert code to put in 0 instead of 1 for collect
    * value for delivery lines
      if v_lips-lgmng = 0.
        v_output_dt-num_delln   = 0.
        v_output_ag-num_delln   = 0.
        v_output_gs-num_delln   = 0.
      else.
    * end of insert for 054042/48712
    *}   INSERT
        v_output_dt-num_delln   = 1.
        v_output_ag-num_delln   = 1.
        v_output_gs-num_delln   = 1.          

    Since this is your first post, let me clue you in. This forum is meant for asking very short and specific questions. For example, if you've asked, how could you improve a particular one SELECT statement, I'm sure many people would have helped you.
    But you cannot seriously expect someone on this forum to spend his/her time and review such a long program. For this people are normally getting paid, you know.

  • Performance of PL/SQL vs external C function.

    Do anyone know how much performance difference there is for a high computation function implemented in PL/SQL vs a external C function? I know that this is a impossible question to answer precisely. But I'm interested in peoples experiences with this.

    Depends on the processing taking place and how much you PL/SQL is using built in functionality. From 10g anything built into oracle has supposedly been rewritted by Oracle in C for performance.
    However, you can also compile your PL/SQL natively which turns it into C code and can give up to (according to Oracle training) 30% increase in speed. It does not really give any improvement on SQL statements as they are just statements handled by the SQL engine, so they can't really get any faster, but if it is computational PL/SQL then there will definitely be an improvement.
    ;)

  • Crystal Report performance - subreports or sql command?

    Hello,
    bit of quandary, I've an existing report that contains six subreports all sharing the same parameter to the main report, a 'projectID' field.
    The main report approximately returns 300 records/projects and each of the 6 subreports are passed the corresponding 'projectID' field 300 times.
    Now, I've succesfully incorporated the main report query and corresponding subreports into a TSQL command containing a number of subqueries in the Select clause:
    SELECT   PROJECT.PROJECTID, PROJECT.TITLE, PROJECT.REFERENCE, PROJECTSTATUS.PROJECTSTATUS, PROJECT.INPUT_DATE
    ,(SELECT max(INPUT_DATE) FROM V_PROJECT_NOTE AS VPN
    WHERE PROJECT.PROJECTID = VPN.PROJECTID) AS LastHeadline
    ,(SELECT
    MAX(CASE
         WHEN MODIFIED_DATE IS NULL THEN INPUT_DATE
         WHEN INPUT_DATE > MODIFIED_DATE THEN INPUT_DATE
              ELSE MODIFIED_DATE
    END) FROM ISSUE WHERE PROJECT.PROJECTID = ISSUE.PROJECTID) AS LastNewIssue
    ,(SELECT max(ISSUENOTE.INPUT_DATE) FROM ISSUE
    INNER JOIN ISSUENOTE ON ISSUE.ISSUEID = ISSUENOTE.ISSUEID
    WHERE PROJECT.PROJECTID = ISSUE.PROJECTID ) AS LastIssueNote 
    ,(SELECT max(modified_date) FROM V_PROJECT_RISK_LAST_AMMENDED AS VPR
    WHERE PROJECT.PROJECTID = VPR.PROJECTID) AS LastRiskLogUpdate
    ,(SELECT max(INPUT_DATE) FROM PROJECT_CHECKLIST AS PC
    WHERE PROJECT.PROJECTID = PC.PROJECTID) AS LastChecklistUpdate
    ,(SELECT max(input_date) FROM V_PROJECT_ACTIVITY_LAST_AMMENDED AS VPA
    WHERE PROJECT.PROJECTID = VPA.PROJECTID) AS LastGANTTUpdate 
    ,V_PROJECT_KEYCONTACT.USERNAME AS KeyContact
    ,(SELECT     USERPROFILE.USERNAME AS Supervisor
    FROM         USERPROFILE INNER JOIN
                          PROJECT_MEMBER AS SUPERVISOR ON USERPROFILE.USERID = SUPERVISOR.USERID RIGHT OUTER JOIN
                          PROJECT_MEMBER AS KEYCONTACT ON SUPERVISOR.PROJECT_MEMBERID = KEYCONTACT.PARENTID
    WHERE PROJECT.PROJECTID = KEYCONTACT.PROJECTID
    AND KEYCONTACT.KEY_CONTACT =1) AS Supervisor
    FROM         PROJECT INNER JOIN
                          PROJECTSTATUS ON PROJECT.PROJECTSTATUSID = PROJECTSTATUS.PROJECTSTATUSID LEFT OUTER JOIN
                          V_PROJECT_KEYCONTACT ON PROJECT.PROJECTID = V_PROJECT_KEYCONTACT.PROJECTID
    WHERE V_PROJECT_KEYCONTACT.USERNAME IN ('aaa','bbb','ccc')
    AND (PROJECTSTATUS.PROJECTSTATUS IN ('111', '222', '333'))
    AND ((PROJECT.TITLE NOT LIKE 'xxx%') AND (PROJECT.TITLE NOT LIKE 'yyy%') AND (PROJECT.TITLE NOT LIKE 'zzz%'))
    ORDER BY V_PROJECT_KEYCONTACT.USERNAME, PROJECT.INPUT_DATE
    Now, I've run both SQL Server Profiler and looked at the Performance Information in Crystal and the SQL command method is an order of magnitude less efficient!!
    I may have to post my query on a TSQL forum but was wondering if anyone on here can possible shed any light on it?
    Thanks in advance,
    Dom

    Dom,
    I assume that the last edit was to remove a few curse words...
    The reality is that we can give a good explanation as to why the sub-report version would execute faster that the command version w/o seeing the report (with the sub-reports included).
    Looking at the SQL, I can tell that it's a fairly expensive query, firing several sub-queries for every row returned by the outer query. That said, I sounds like the same thing is taking place with the sub-report version too... So I would think that the performance would be similar.
    The only thing that I can think of, and this is just a guess... With the sub-report version, each all queries are being run independently and then combined locally by CR, whereas the command version, everything is combined. The more complex the query, the harder the optimizer has to work to come up with the best execution plan... and the greater the likelihood that that the resulting plan isn't as optimized as it could be.
    That said, I'd still think the command version would be faster over all. Are you seeing real differences between the two reports, in the amount of time that it takes from refresh to final render?
    Either way, I think moving all of those sub-queries from the select list (where they are executing once for every row) down to the FROM area (where they only have to execute once) should increase the speed dramatically and surpass the sub-report version by a decent margin.
    Give this version of your SQL a test drive and see if it yields an improvement.
    SELECT  
    PROJECT.PROJECTID,
    PROJECT.TITLE,
    PROJECT.REFERENCE,
    PROJECTSTATUS.PROJECTSTATUS,
    PROJECT.INPUT_DATE,
    VPN.LastHeadline,
    ISSUE.LastNewIssue,
    ISSUE_NOTE.LastIssueNote,
    VPR.LastRiskLogUpdate,
    PC.LastChecklistUpdate,
    VPA.LastGANTTUpdate,
    V_PROJECT_KEYCONTACT.USERNAME AS KeyContact,
    Supervisor.Supervisor
    FROM PROJECT
    INNER JOIN PROJECTSTATUS ON PROJECT.PROJECTSTATUSID = PROJECTSTATUS.PROJECTSTATUSID
    LEFT OUTER JOIN V_PROJECT_KEYCONTACT ON PROJECT.PROJECTID = V_PROJECT_KEYCONTACT.PROJECTID
    LEFT OUTER JOIN (
         SELECT PROJECTID,
         max(INPUT_DATE) AS LastHeadline
         FROM V_PROJECT_NOTE
         GROUP BYPROJECTID) AS VPN ON PROJECT.PROJECTID = VPN.PROJECTID
    LEFT OUTER JOIN (
         SELECT PROJECTID,
         MAX(CASE
              WHEN MODIFIED_DATE IS NULL THEN INPUT_DATE
              WHEN INPUT_DATE > MODIFIED_DATE THEN INPUT_DATE
              ELSE MODIFIED_DATE END) AS LastNewIssue
         FROM ISSUE
         GROUP BY PROJECTID) AS ISSUE ON PROJECT.PROJECTID = ISSUE.PROJECTID
    LEFT OUTER JOIN (
         SELECT ISSUE.PROJECTID,
         max(ISSUENOTE.INPUT_DATE) AS LastIssueNote
         FROM ISSUE
         INNER JOIN ISSUENOTE ON ISSUE.ISSUEID = ISSUENOTE.ISSUEID
         GROUP BY ISSUE.PROJECTID) AS ISSUE_NOTE ON PROJECT.PROJECTID = ISSUE_NOTE.PROJECTID
    LEFT OUTER JOIN (
         SELECT PROJECTID,
         max(modified_date) AS LastRiskLogUpdate
         FROM V_PROJECT_RISK_LAST_AMMENDED
         GROUP BY PROJECTID) AS VPR ON PROJECT.PROJECTID = VPR.PROJECTID
    LEFT OUTER JOIN (
         SELECT PROJECTID,
         max(INPUT_DATE) AS LastChecklistUpdate
         FROM PROJECT_CHECKLIST
         GROUP BY PROJECTID) AS PC ON PROJECT.PROJECTID = PC.PROJECTID
    LEFT OUTER JOIN (
         SELECT PROJECTID,
         max(input_date) AS LastGANTTUpdate
         FROM V_PROJECT_ACTIVITY_LAST_AMMENDED
         GROUP BY PROJECTID) AS VPA ON PROJECT.PROJECTID = VPA.PROJECTID
    LEFT OUTER JOIN (
         SELECT PROJECTID,
         USERPROFILE.USERNAME AS Supervisor
         FROM USERPROFILE
         INNER JOIN PROJECT_MEMBER AS SUPERVISOR ON USERPROFILE.USERID = SUPERVISOR.USERID RIGHT
         OUTER JOIN PROJECT_MEMBER AS KEYCONTACT ON SUPERVISOR.PROJECT_MEMBERID = KEYCONTACT.PARENTID
         WHERE KEYCONTACT.KEY_CONTACT =1) AS Supervisor ON PROJECT.PROJECTID = Supervisor.PROJECTID
    WHERE V_PROJECT_KEYCONTACT.USERNAME IN ('aaa','bbb','ccc')
    AND (PROJECTSTATUS.PROJECTSTATUS IN ('111', '222', '333'))
    AND ((PROJECT.TITLE NOT LIKE 'xxx%')
    AND (PROJECT.TITLE NOT LIKE 'yyy%')
    AND (PROJECT.TITLE NOT LIKE 'zzz%'))
    ORDER BY V_PROJECT_KEYCONTACT.USERNAME, PROJECT.INPUT_DATE
    HTH,
    Jason

  • Performing backup of SQL via backup interface

    Hello all,
    First of all , let me tell you that i don't have much knowledge regarding SQL so, excuse me in advance for any stupid questions.
    Here is my situation:
    I have SQL 2005 Standolne server. On the server there are two interfaces(NICs) one is so called production(prod) and backup(bkp). 
    The PROD is for main communication and it's with assigned FQDN - XYZ. The other one is for backup traffic and it's with FQDN - XYZ-b. The IPs are , PROD - xxx.xxx.1.xxx, BKP - xxx.xxx.2.xxx
    I'm using a HP Data Protector software , version 7.03, with latest patched installed on the backup software.
    Unfortunately when i'm trying to create a backup(there are 3 ways for authentication - Integrated, Windows and SQL server)  with the BKP interface i receive following error:
    *RETVAL*8010
    The user name which is used by the bkp software is added into the SQL server as admin, also it's with local admin from OS point of view. 
    So my question is , are there any way to perform backup via XYZ-B interface ?
    Thank you in advance !!!

    Hello,
    Seems to be more a HP Data Protector issue, see
    http://h30499.www3.hp.com/t5/Data-Protector-Support-and-News/Integration-cannot-be-configured-error-on-HP-data-protector/td-p/5961279#.U89zyGeKD5w
    Olaf Helper
    [ Blog] [ Xing] [ MVP]

  • Please help me to increase the performance of the query

    Hello
    I am not an oracle expert or developer and i have a problem to resolve.
    Below is the query and explaiation plan and seeking the help to improve the performance of the query.
    Our Analysis,
    The query runs good,takes less one minute and fetches the results but during peak time it takes 8 minutes
    Require anyone suggestion's to improve the query.
    The query is generated from the Microsft dll so we dont have SQL code and require some help on tuning the tables.
    If tuning the query improves then also fine please suggest for that also.
    Enviroment: Solaris 8
    DB : oracle 9i
    (SELECT vw.dispapptobjid, vw.custsiteobjid, vw.emplastname, vw.empfirstname,
    vw.scheduledonsite AS starttime, vw.appttype, vw.latestart,
    vw.endtime, vw.typetitle, vw.empobjid, vw.latitude, vw.longitude,
    vw.workduration AS DURATION, vw.dispatchtype, vw.availability
    FROM ora_appt_disp_view vw
    WHERE ( ( vw.starttime >=
    TO_DATE ('2/12/2007 4:59 PM', 'MM/DD/YYYY HH12:MI AM')
    AND vw.starttime <
    TO_DATE ('2/21/2007 3:59 PM', 'MM/DD/YYYY HH12:MI AM')
    OR vw.endtime >
    TO_DATE ('2/12/2007 4:59 PM', 'MM/DD/YYYY HH12:MI AM')
    AND vw.endtime <=
    TO_DATE ('2/21/2007 3:59 PM', 'MM/DD/YYYY HH12:MI AM')
    OR ( vw.starttime <=
    TO_DATE ('2/12/2007 4:59 PM', 'MM/DD/YYYY HH12:MI AM')
    AND vw.endtime >=
    TO_DATE ('2/21/2007 3:59 PM', 'MM/DD/YYYY HH12:MI AM')
    UNION
    (SELECT 0 AS dispapptobjid, emp.emp_physical_site2site AS custsiteobjid,
    emp.last_name AS emplastname, emp.first_name AS empfirstname,
    TO_DATE ('1/1/3000', 'MM/DD/YYYY') AS starttime, 'E' AS appttype,
    NULL AS latestart, NULL AS endtime, '' AS typetitle,
    emp.objid AS empobjid, 0 AS latitude, 0 AS longitude, 0 AS DURATION,
    '' AS dispatchtype, 0 AS availability
    FROM table_employee emp, table_user usr
    WHERE emp.employee2user = usr.objid AND emp.field_eng = 1 AND usr.status = 1)
    ORDER BY empobjid, starttime, endtime DESC
    Operation     Object Name     Rows     Bytes     Cost     Object Node     In/Out     PStart     PStop
    SELECT STATEMENT Optimizer Mode=HINT: ALL_ROWS          23 K          11312                     
    SORT UNIQUE          23 K     3 M     11140                     
    UNION-ALL                                        
    VIEW     ORA_APPT_DISP_VIEW     17 K     3 M     10485                     
    UNION-ALL                                        
    CONCATENATION                                        
    NESTED LOOPS OUTER          68      24 K     437                     
    NESTED LOOPS          68      23 K     369                     
    NESTED LOOPS OUTER          68      25 K     505                     
    NESTED LOOPS OUTER          68      24 K     505                     
    NESTED LOOPS          68      23 K     369                     
    NESTED LOOPS          68      22 K     369                     
    NESTED LOOPS OUTER          68      22 K     369                     
    NESTED LOOPS          19      6 K     312                     
    NESTED LOOPS          19      5 K     312                     
    HASH JOIN          19      5 K     293                     
    NESTED LOOPS          19      5 K     274                     
    NESTED LOOPS          19      4 K     236                     
    NESTED LOOPS          19      4 K     198                     
    NESTED LOOPS OUTER          19      3 K     160                     
    NESTED LOOPS OUTER          19      3 K     160                     
    NESTED LOOPS OUTER          19      4 K     160                     
    NESTED LOOPS OUTER          19      1 K     103                     
    NESTED LOOPS OUTER          19      2 K     103                     
    NESTED LOOPS OUTER          19      2 K     103                     
    TABLE ACCESS BY INDEX ROWID     TABLE_DISPTCHFE     19      1 K     46                     
    INDEX RANGE SCAN     GSA_SCHED_REPAIR     44           3                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      22                          
    INDEX RANGE SCAN     GSA_COMDFE     1           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      22                          
    INDEX RANGE SCAN     GSA_COMDFE     1           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      22      3                     
    INDEX RANGE SCAN     GSA_COMDFE     1           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      28                          
    INDEX RANGE SCAN     IND_CASE_COMMIT2CASE     2           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      28                          
    INDEX RANGE SCAN     IND_CASE_COMMIT2CASE     2           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      28      3                     
    INDEX RANGE SCAN     IND_CASE_COMMIT2CASE     2           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_CASE     1      30      2                     
    INDEX UNIQUE SCAN     CASE_OBJINDEX     1           1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_SITE     1      12      2                     
    INDEX UNIQUE SCAN     SITE_OBJINDEX     1           1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_ADDRESS     1      12      2                     
    INDEX UNIQUE SCAN     ADDRESS_OBJINDEX     1           1                     
    TABLE ACCESS FULL     TABLE_EMPLOYEE     1      34      1                     
    INDEX UNIQUE SCAN     SITE_OBJINDEX     1      6      1                     
    INDEX UNIQUE SCAN     USER_OBJINDEX     1      6                          
    TABLE ACCESS BY INDEX ROWID     TABLE_X_GSA_TIME_STAMPS     4      48      3                     
    INDEX RANGE SCAN     GSAIDX_TS2DISP     1           2                     
    INDEX UNIQUE SCAN     GBST_ELM_OBJINDEX     1      6                          
    INDEX UNIQUE SCAN     GBST_ELM_OBJINDEX     1      6                          
    TABLE ACCESS BY INDEX ROWID     TABLE_MOD_LEVEL     1      12      1                     
    INDEX UNIQUE SCAN     MOD_LEVEL_OBJINDEX     1                               
    INDEX UNIQUE SCAN     PART_NUM_OBJINDEX     1      6                          
    INDEX UNIQUE SCAN     GBST_ELM_OBJINDEX     1      6                          
    INDEX UNIQUE SCAN     SUBCASE_OBJINDX     1      6      1                     
    NESTED LOOPS OUTER          68      25 K     505                     
    NESTED LOOPS OUTER          68      24 K     505                     
    NESTED LOOPS OUTER          68      24 K     437                     
    NESTED LOOPS          68      23 K     369                     
    NESTED LOOPS          68      23 K     369                     
    NESTED LOOPS          68      22 K     369                     
    NESTED LOOPS OUTER          68      22 K     369                     
    NESTED LOOPS          19      6 K     312                     
    NESTED LOOPS          19      5 K     312                     
    NESTED LOOPS          19      5 K     293                     
    NESTED LOOPS          19      5 K     274                     
    NESTED LOOPS          19      4 K     236                     
    NESTED LOOPS          19      4 K     198                     
    NESTED LOOPS OUTER          19      4 K     160                     
    NESTED LOOPS OUTER          19      3 K     160                     
    NESTED LOOPS OUTER          19      3 K     160                     
    NESTED LOOPS OUTER          19      2 K     103                     
    NESTED LOOPS OUTER          19      2 K     103                     
    NESTED LOOPS OUTER          19      1 K     103                     
    TABLE ACCESS BY INDEX ROWID     TABLE_DISPTCHFE     19      1 K     46                     
    INDEX RANGE SCAN     GSA_SCHED_REPAIR     44           3                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      22      3                     
    INDEX RANGE SCAN     GSA_COMDFE     1           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      22                          
    INDEX RANGE SCAN     GSA_COMDFE     1           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      22                          
    INDEX RANGE SCAN     GSA_COMDFE     1           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      28      3                     
    INDEX RANGE SCAN     IND_CASE_COMMIT2CASE     2           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      28                          
    INDEX RANGE SCAN     IND_CASE_COMMIT2CASE     2           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      28                          
    INDEX RANGE SCAN     IND_CASE_COMMIT2CASE     2           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_CASE     1      30      2                     
    INDEX UNIQUE SCAN     CASE_OBJINDEX     1           1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_SITE     1      12      2                     
    INDEX UNIQUE SCAN     SITE_OBJINDEX     1           1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_ADDRESS     1      12      2                     
    INDEX UNIQUE SCAN     ADDRESS_OBJINDEX     1           1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_EMPLOYEE     1      34      1                     
    INDEX UNIQUE SCAN     EMPLOYEE_OBJINDEX     1                               
    INDEX UNIQUE SCAN     SITE_OBJINDEX     1      6      1                     
    INDEX UNIQUE SCAN     USER_OBJINDEX     1      6                          
    TABLE ACCESS BY INDEX ROWID     TABLE_X_GSA_TIME_STAMPS     4      48      3                     
    INDEX RANGE SCAN     GSAIDX_TS2DISP     1           2                     
    INDEX UNIQUE SCAN     GBST_ELM_OBJINDEX     1      6                          
    INDEX UNIQUE SCAN     GBST_ELM_OBJINDEX     1      6                          
    INDEX UNIQUE SCAN     GBST_ELM_OBJINDEX     1      6                          
    INDEX UNIQUE SCAN     SUBCASE_OBJINDX     1      6      1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_MOD_LEVEL     1      12      1                     
    INDEX UNIQUE SCAN     MOD_LEVEL_OBJINDEX     1                               
    INDEX UNIQUE SCAN     PART_NUM_OBJINDEX     1      6                          
    NESTED LOOPS OUTER          68      25 K     505                     
    NESTED LOOPS OUTER          68      24 K     505                     
    NESTED LOOPS OUTER          68      24 K     437                     
    NESTED LOOPS          68      23 K     369                     
    NESTED LOOPS          68      23 K     369                     
    NESTED LOOPS          68      22 K     369                     
    NESTED LOOPS OUTER          68      22 K     369                     
    NESTED LOOPS          19      6 K     312                     
    NESTED LOOPS          19      5 K     312                     
    NESTED LOOPS          19      5 K     293                     
    NESTED LOOPS          19      5 K     274                     
    NESTED LOOPS          19      4 K     236                     
    NESTED LOOPS          19      4 K     198                     
    NESTED LOOPS OUTER          19      4 K     160                     
    NESTED LOOPS OUTER          19      3 K     160                     
    NESTED LOOPS OUTER          19      3 K     160                     
    NESTED LOOPS OUTER          19      2 K     103                     
    NESTED LOOPS OUTER          19      2 K     103                     
    NESTED LOOPS OUTER          19      1 K     103                     
    TABLE ACCESS BY INDEX ROWID     TABLE_DISPTCHFE     19      1 K     46                     
    INDEX RANGE SCAN     GSA_REQ_ETA     44           3                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      22      3                     
    INDEX RANGE SCAN     GSA_COMDFE     1           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      22                          
    INDEX RANGE SCAN     GSA_COMDFE     1           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      22                          
    INDEX RANGE SCAN     GSA_COMDFE     1           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      28      3                     
    INDEX RANGE SCAN     IND_CASE_COMMIT2CASE     2           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      28                          
    INDEX RANGE SCAN     IND_CASE_COMMIT2CASE     2           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_COMMIT_LOG     1      28                          
    INDEX RANGE SCAN     IND_CASE_COMMIT2CASE     2           2                     
    TABLE ACCESS BY INDEX ROWID     TABLE_CASE     1      30      2                     
    INDEX UNIQUE SCAN     CASE_OBJINDEX     1           1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_SITE     1      12      2                     
    INDEX UNIQUE SCAN     SITE_OBJINDEX     1           1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_ADDRESS     1      12      2                     
    INDEX UNIQUE SCAN     ADDRESS_OBJINDEX     1           1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_EMPLOYEE     1      34      1                     
    INDEX UNIQUE SCAN     EMPLOYEE_OBJINDEX     1                               
    INDEX UNIQUE SCAN     SITE_OBJINDEX     1      6      1                     
    INDEX UNIQUE SCAN     USER_OBJINDEX     1      6                          
    TABLE ACCESS BY INDEX ROWID     TABLE_X_GSA_TIME_STAMPS     4      48      3                     
    INDEX RANGE SCAN     GSAIDX_TS2DISP     1           2                     
    INDEX UNIQUE SCAN     GBST_ELM_OBJINDEX     1      6                          
    INDEX UNIQUE SCAN     GBST_ELM_OBJINDEX     1      6                          
    INDEX UNIQUE SCAN     GBST_ELM_OBJINDEX     1      6                          
    INDEX UNIQUE SCAN     SUBCASE_OBJINDX     1      6      1                     
    TABLE ACCESS BY INDEX ROWID     TABLE_MOD_LEVEL     1      12      1                     
    INDEX UNIQUE SCAN     MOD_LEVEL_OBJINDEX     1                               
    INDEX UNIQUE SCAN     PART_NUM_OBJINDEX     1      6                          
    NESTED LOOPS          16 K     2 M     5812                     
    HASH JOIN          16 K     2 M     5812                     
    HASH JOIN          16 K     2 M     5286                     
    TABLE ACCESS FULL     TABLE_EMPLOYEE     13 K     441 K     28                     
    HASH JOIN          16 K     1 M     5243                     
    TABLE ACCESS FULL     TABLE_SCHEDULE     991      11 K     2                     
    HASH JOIN OUTER          16 K     1 M     5240                     
    HASH JOIN OUTER          16 K     1 M     3866                     
    HASH JOIN OUTER          16 K     1 M     450                     
    HASH JOIN          16 K     1 M     44                     
    TABLE ACCESS FULL     TABLE_GBST_ELM     781      14 K     2                     
    TABLE ACCESS FULL     TABLE_APPOINTMENT     16 K     822 K     41                     
    INDEX FAST FULL SCAN     CASE_OBJINDEX     1 M     6 M     201                     
    TABLE ACCESS FULL     TABLE_SITE     967 K     11 M     3157                     
    TABLE ACCESS FULL     TABLE_ADDRESS     961 K     11 M     1081                     
    INDEX FAST FULL SCAN     SITE_OBJINDEX     967 K     5 M     221                     
    INDEX UNIQUE SCAN     USER_OBJINDEX     1      6                          
    HASH JOIN          6 K     272 K     51                     
    TABLE ACCESS FULL     TABLE_USER     6 K     51 K     21                     
    TABLE ACCESS FULL     TABLE_EMPLOYEE     6 K     220 K     28

    Hi,
    First-off, it appear that you are querying a view. I would redo the auery against the base table.
    Next, look at a function-based index for the DATE column. Here are my notes:
    http://www.dba-oracle.com/t_function_based_indexes.htm
    http://www.dba-oracle.com/oracle_tips_index_scan_fbi_sql.htm
    Also, make sure you are analyzed properly with dbms_stats:
    http://www.dba-oracle.com/art_builder_dbms_stats.htm
    And histograms, if appropriate:
    http://www.dba-oracle.com/art_builder_histo.htm
    Lasty, look at increasing hash_area_size or pga_aggregate_tagtet, depending on your table sizes:
    http://www.dba-oracle.com/art_so_undocumented_pga_parameters.htm
    Hope this helps. . . .
    Donald K. Burleson
    Oracle Press Author

  • How to get cm:search to use the max attribute when creating the SQL query?

    When we use the max attribute in the cm:search tag, it does not seem to honor the max attribute when creating the SQL query. However, the result returned from the tag is limited to the number specified by the max attribute. Then the tag seems to work as intended, but the performance will be sub optimal when the SQL query returns unnecessary rows to the application.
    We use the cm:search tag to list the latest news (ordered by date), and with the current implementation we have to expect a decrease in performance over time as more news is published. But we can’t live with that. We need to do the constraint in the SQL query, not in the application.
    The sortBy attribute of cm:search is translated to “order by” in the SQL query, as expected.
    Is it possible to get cm:search to generate the SQL query with an addition of “where rownum <= maxRows”?

    Hi Erik,
    The behavior of a repository in regards to the search tag's max results parameter is dependent on the underlying repository's implementation. That said, the OOTB repository in WLP does augment the generated SQL to limit the number of rows returned from the database. This is done in the parsing logic. This behavior may differ with other repository implementations.
    -Ryan

  • Welcome to the SQL Server Disaster Recovery and Availability Forum

    (Edited 8/14/2009 to correct links - Paul)
    Hello everyone and welcome to the SQL Server Disaster Recovery and Availability forum. The goal of this Forum is to offer a gathering place for SQL Server users to discuss:
    Using backup and restore
    Using DBCC, including interpreting output from CHECKDB and related commands
    Diagnosing and recovering from hardware issues
    Planning/executing a disaster recovery and/or high-availability strategy, including choosing technologies to use
    The forum will have Microsoft experts in all these areas and so we should be able to answer any question. Hopefully everyone on the forum will contribute not only questions, but opinions and answers as well. I’m looking forward to seeing this becoming a vibrant forum.
    This post has information to help you understand what questions to post here, and where to post questions about other technologies as well as some tips to help you find answers to your questions more quickly and how to ask a good question. See you in the group!
    Paul Randal
    Lead Program Manager, SQL Storage Engine and SQL Express
    Be a good citizen of the Forum
    When an answer resolves your problem, please mark the thread as Answered. This makes it easier for others to find the solution to this problem when they search for it later. If you find a post particularly helpful, click the link indicating that it was helpful
    What to post in this forum
    It seems obvious, but this forum is for discussion and questions around disaster recovery and availability using SQL Server. When you want to discuss something that is specific to those areas, this is the place to be. There are several other forums related to specific technologies you may be interested in, so if your question falls into one of these areas where there is a better batch of experts to answer your question, we’ll just move your post to that Forum so those experts can answer. Any alerts you set up will move with the post, so you’ll still get notification. Here are a few of the other forums that you might find interesting:
    SQL Server Setup & Upgrade – This is where to ask all your setup and upgrade related questions. (http://social.msdn.microsoft.com/Forums/en-US/sqlsetupandupgrade/threads)
    Database Mirroring – This is the best place to ask Database Mirroring how-to questions. (http://social.msdn.microsoft.com/Forums/en-US/sqldatabasemirroring/threads)
    SQL Server Replication – If you’ve already decided to use Replication, check out this forum. (http://social.msdn.microsoft.com/Forums/en-US/sqlreplication/threads)
    SQL Server Database Engine – Great forum for general information about engine issues such as performance, FTS, etc. (http://social.msdn.microsoft.com/Forums/en-US/sqldatabaseengine/threads)
    How to find your answer faster
    There is a wealth of information already available to help you answer your questions. Finding an answer via a few quick searches is much quicker than posting a question and waiting for an answer. Here are some great places to start your research:
    SQL Server 2005 Books Onlinne
    Search it online at http://msdn2.microsoft.com
    Download the full version of the BOL from here
    Microsoft Support Knowledge Base:
    Search it online at http://support.microsoft.com
    Search the SQL Storage Engine PM Team Blog:
    The blog is located at https://blogs.msdn.com/sqlserverstorageengine/default.aspx
    Search other SQL Forums and Web Sites:
    MSN Search: http://www.bing.com/
    Or use your favorite search engine
    How to ask a good question
    Make sure to give all the pertinent information that people will need to answer your question. Questions like “I got an IO error, any ideas?” or “What’s the best technology for me to use?” will likely go unanswered, or at best just result in a request for more information. Here are some ideas of what to include:
    For the “I got an IO error, any ideas?” scenario:
    The exact error message. (The SQL Errorlog and Windows Event Logs can be a rich source of information. See the section on error logs below.)
    What were you doing when you got the error message?
    When did this start happening?
    Any troubleshooting you’ve already done. (e.g. “I’ve already checked all the firmware and it’s up-to-date” or "I've run SQLIOStress and everything looks OK" or "I ran DBCC CHECKDB and the output is <blah>")
    Any unusual occurrences before the error occurred (e.g. someone tripped the power switch, a disk in a RAID5 array died)
    If relevant, the output from ‘DBCC CHECKDB (yourdbname) WITH ALL_ERRORMSGS, NO_INFOMSGS’
    The SQL Server version and service pack level
    For the “What’s the best technology for me to use?” scenario:
    What exactly are you trying to do? Enable local hardware redundancy? Geo-clustering? Instance-level failover? Minimize downtime during recovery from IO errors with a single-system?
    What are the SLAs (Service Level Agreements) you must meet? (e.g. an uptime percentage requirement, a minimum data-loss in the event of a disaster requirement, a maximum downtime in the event of a disaster requirement)
    What hardware restrictions do you have? (e.g. “I’m limited to a single system” or “I have several worldwide mirror sites but the size of the pipe between them is limited to X Mbps”)
    What kind of workload does you application have? (or is it a mixture of applications consolidated on a single server, each with different SLAs) How much transaction log volume is generated?
    What kind of regular maintenance does your workload demand that you perform (e.g. “the update pattern of my main table is such that fragmentation increases in the clustered index, slowing down the most common queries so there’s a need to perform some fragmentation removal regularly”)
    Finding the Logs
    You will often find more information about an error by looking in the Error and Event logs. There are two sets of logs that are interesting:
    SQL Error Log: default location: C:\Program Files\Microsoft SQL Server\MSSQL.#\MSSQL\LOG (Note: The # changes depending on the ID number for the installed Instance. This is 1 for the first installation of SQL Server, but if you have mulitple instances, you will need to determine the ID number you’re working with. See the BOL for more information about Instance ID numbers.)
    Windows Event Log: Go to the Event Viewer in the Administrative Tools section of the Start Menu. The System event log will show details of IO subsystem problems. The Application event log will show details of SQL Server problems.

    hi,I have a question on sql database high availability. I have tried using database mirroring, where I am using sql standard edition, in this database mirroring of synchronous mode is the only option available, and it is giving problem, like sql time out errors on my applicatons since i had put in the database mirroring, as asynchronous is only available on enterprise version, is there any suggestions on this. thanks ---vijay

Maybe you are looking for

  • "Edit" Functions Grayed Out and No Longer Work

    I have CS5 and have used it for several years now and it has served me well but suddenly, I find that many options (such as most "Edit" options within it are noy grayed-out and non-functional. I've uninstalled it and re-installed but the problem is s

  • Using tag OBJECT on a machine with multiple jre versions

    Dear friends, i guess that this question has been already answered, but i can't find the thread with all infos i need. So please excuse me if i'm redundant. This is my problem: i have a web application that runs an applet, embedded in an html page; b

  • How to Create SYSTEM GROUP in XI

    Hi, all My question is how to create system group in XI 3.0 I goto RZ21 then Technical Infrastructure --> Configure Central system --> Maintain system Group Then Create system Group name ExchangeInfrastructure_System After Hit enter, its not look lik

  • Purchasing Order Report

    Hi, I have a ODS which is being loaded from 2lis_o2_hdr,2lis_02_itm,2lis_02_scl. When I run report in this ods,I am getting PO#  Item#  SC# Createdby Compcode 123   10      1       NA              NA 123    10    NA    NA                 06 123    NA

  • Problem synching with MobileMe

    I made a MobileMe gallery in iPhoto '09 on my iMac and synchronized with MobileMe. This worked fine and the gallery is available on line. Then I synchronized my Macbook Air and the gallery appears, but only about a third of the pictures are downloade