GATHER_STATS job collect stats for 'static' tables

Oracle version: 10gR2
If a business table hasn't changed (No DML) in the last 10 days, will oracle's default stats collection job
DBMS_STATS.GATHER_DATABASE_STATS_JOB_PROCstill collect stats of this table?

The answer is no, unless you have modified the default optimizer stats collecting statistics, as about 10% of the data must have undergone change before the table is elgible for new statistics.
See the following int he Performance and Tuning manual section 14.2.1 GATHER_STATS_JOB:
http://download.oracle.com/docs/cd/B19306_01/server.102/b14211/stats.htm#sthref1068
HTH -- Mark D Powell --

Similar Messages

  • Two collect statement from internal table

    Dear Experts,
    I want populate values to two internal tables from a internal table.
    can i use two collect statement for different internal table from a single internal table.
    advise please.
    Thanks in advance.
    R.Rajendran

    hi there....
    well u can very well use this thing.....
    use the two colect statements inside the loop which u will use  to read the records of the input table.
    hope it helps.
    do reward if it does.

  • Scheduled Job to gather stats for multiple tables - Oracle 11.2.0.1.0

    Hi,
    My Oracle DB Version is:
    BANNER Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    PL/SQL Release 11.2.0.1.0 - Production
    CORE 11.2.0.1.0 Production
    TNS for Linux: Version 11.2.0.1.0 - Production
    NLSRTL Version 11.2.0.1.0 - Production
    In our application, we have users uploading files resulting in insert of records into a table. file could contain records ranging from 10000 to 1 million records.
    I have written a procedure to bulk insert these records into this table using limit clause. After the insert, i noticed my queries run slow against these tables if huge files are uploaded simultaneously. After gathering stats, the cost reduces and the queries executed faster.
    We have 2 such tables which grow based on user file uploads. I would like to schedule a job to gather stats during a non peak hour apart from the nightly automated oracle job for these two tables.
    Is there a better way to do this?
    I plan to execute the below procedure as a scheduled job using DBMS_SCHEDULER.
    --Procedure
    create or replace
    PROCEDURE p_manual_gather_table_stats AS
    TYPE ttab
    IS
        TABLE OF VARCHAR2(30) INDEX BY PLS_INTEGER;
        ltab ttab;
    BEGIN
        ltab(1) := 'TAB1';
        ltab(2) := 'TAB2';
        FOR i IN ltab.first .. ltab.last
        LOOP
            dbms_stats.gather_table_stats(ownname => USER, tabname => ltab(i) , estimate_percent => dbms_stats.auto_sample_size,
            method_opt => 'for all indexed columns size auto', degree =>
            dbms_stats.auto_degree ,CASCADE => TRUE );
        END LOOP;
    END p_manual_gather_table_stats;
    --Scheduled Job
    BEGIN
        -- Job defined entirely by the CREATE JOB procedure.
        DBMS_SCHEDULER.create_job ( job_name => 'MANUAL_GATHER_TABLE_STATS',
        job_type => 'PLSQL_BLOCK',
        job_action => 'BEGIN p_manual_gather_table_stats; END;',
        start_date => SYSTIMESTAMP,
        repeat_interval => 'FREQ=DAILY; BYHOUR=12;BYMINUTE=45;BYSECOND=0',
        end_date => NULL,
        enabled => TRUE,
        comments => 'Job to manually gather stats for tables: TAB1,TAB2. Runs at 12:45 Daily.');
    END;Thanks,
    Somiya

    The question was, is there a better way, and you partly answered it.
    Somiya, you have to be sure the queries have appropriate statistics when the queries are being run. In addition, if the queries are being run while data is being loaded, that is going to slow things down regardless, for several possible reasons, such as resource contention, inappropriate statistics, and having to maintain a read consistent view for each query.
    The default collection job decides for each table based on changes it perceives in the data. You probably don't want the default collection job to deal with those tables. You probably do want to do what Dan suggested with the statistics. But it's hard to tell from your description. Is the data volume and distribution volatile? You surely want representative statistics available when each query is started. You may want to use all the plan stability features available to tell the optimizer to do the right thing (see for example http://jonathanlewis.wordpress.com/2011/01/12/fake-baselines/ ). You may want to just give up and use dynamic sampling, I don't know, entire books, blogs and papers have been written on the subject. It's sufficiently advanced technology to appear as magic.

  • Help,why brconnect do not collect statistics for mseg table?

    I found "MSEG" table`s statistics is too old.
    so i check logs in db13,and the schedule job do not collect statistics for "MSEG".
    Then i execute manually: brconnect -c -u system/system -f stats -t mseg  -p 4
    this command still do not collect for mseg.
    KS1DSDB1:oraprd 2> brconnect -c -u system/system -f stats -t mseg u2013f collect -p 4
    BR0801I BRCONNECT 7.00 (46)
    BR0154E Unexpected option value 'u2013f' found at position 8
    BR0154E Unexpected option value 'collect' found at position 9
    BR0806I End of BRCONNECT processing: ceenwjre.log 2010-11-12 08.41.38
    BR0280I BRCONNECT time stamp: 2010-11-12 08.41.38
    BR0804I BRCONNECT terminated with errors
    KS1DSDB1:oraprd 3> brconnect -c -u system/system -f stats -t mseg -p 4
    BR0801I BRCONNECT 7.00 (46)
    BR0805I Start of BRCONNECT processing: ceenwjse.sta 2010-11-12 08.42.04
    BR0484I BRCONNECT log file: /oracle/PRD/sapcheck/ceenwjse.sta
    BR0280I BRCONNECT time stamp: 2010-11-12 08.42.11
    BR0813I Schema owners found in database PRD: SAPPRD*, SAPPRDSHD+
    BR0280I BRCONNECT time stamp: 2010-11-12 08.42.12
    BR0807I Name of database instance: PRD
    BR0808I BRCONNECT action ID: ceenwjse
    BR0809I BRCONNECT function ID: sta
    BR0810I BRCONNECT function: stats
    BR0812I Database objects for processing: MSEG
    BR0851I Number of tables with missing statistics: 0
    BR0852I Number of tables to delete statistics: 0
    BR0854I Number of tables to collect statistics without checking: 0
    BR0855I Number of indexes with missing statistics: 0
    BR0856I Number of indexes to delete statistics: 0
    BR0857I Number of indexes to collect statistics: 0
    BR0853I Number of tables to check (and collect if needed) statistics: 1
    Owner SAPPRD: 1
    MSEG     
    BR0846I Number of threads that will be started in parallel to the main thread: 4
    BR0126I Unattended mode active - no operator confirmation required
    BR0280I BRCONNECT time stamp: 2010-11-12 08.42.16
    BR0817I Number of monitored/modified tables in schema of owner SAPPRD: 1/1
    BR0280I BRCONNECT time stamp: 2010-11-12 08.42.16
    BR0877I Checking and collecting table and index statistics...
    BR0280I BRCONNECT time stamp: 2010-11-12 08.42.16
    BR0879I Statistics checked for 1 table
    BR0878I Number of tables selected to collect statistics after check: 0
    BR0880I Statistics collected for 0/0 tables/indexes
    BR0806I End of BRCONNECT processing: ceenwjse.sta 2010-11-12 08.42.16
    BR0280I BRCONNECT time stamp: 2010-11-12 08.42.17
    BR0802I BRCONNECT completed successfully
    the log says:
    Number of tables selected to collect statistics after check: 0
    Could you give some advices?  thanks a lot.

    Hello,
    If you would like to force the creation of that stats for table MSEG you need to use the -f (force) switch.
    If you leave out the -f switch the parameter from stats_change_threshold is taken like you said correctly:
    [http://help.sap.com/saphelp_nw70ehp1/helpdata/EN/02/0ae0c6395911d5992200508b6b8b11/content.htm|http://help.sap.com/saphelp_nw70ehp1/helpdata/EN/02/0ae0c6395911d5992200508b6b8b11/content.htm]
    [http://help.sap.com/saphelp_nw70ehp1/helpdata/EN/cb/f1e33a5bd8e934e10000000a114084/content.htm|http://help.sap.com/saphelp_nw70ehp1/helpdata/EN/cb/f1e33a5bd8e934e10000000a114084/content.htm]
    You have tried to do this in your second example :
    ==> brconnect -c -u system/system -f stats -t mseg u2013f collect -p 4
    Therefore you received:
    BR0154E Unexpected option value 'u2013f' found at position 8
    BR0154E Unexpected option value 'collect' found at position 9
    This is the correct statement, however the hyphen in front of the f switch is not correct.
    Try again with the following statement (-f in stead of u2013f) you will see that it will work:
    ==> brconnect -c -u system/system -f stats -t mseg -f collect -p 4
    I hope this can help you.
    Regards.
    Wim

  • Reg: Collect statement in internal table

    Hi,
       Can any one tell me wether we can use the collect statement in an internal table which has no header line
    if it can be used can anyone please send me a sample snippet
    Thanks In ADVANCE
    Guhapriyan Subrahmanyam

    Hi Guhapriyan,
    I have used the collect statement in the way as shown..
    DATA : BEGIN of I_ALLOCATIONS OCCURS 0,
            PSPNR LIKE PRPS-PSPNR,
            PSPID LIKE PROJ-PSPID,
            PSPHI LIKE PRPS-PSPHI,
            POST1 LIKE PROJ-POST1,
            ZZLOB LIKE PROJ-ZZLOB,
            WERKS LIKE PROJ-WERKS,
            SOBID LIKE HRP1001-SOBID,
            OBJID LIKE HRP1001-OBJID,
            BEGDA LIKE HRP1001-BEGDA,
            ENDDA LIKE HRP1001-ENDDA,
            PROZT LIKE HRP1001-PROZT,
            LOB   LIKE HRP1000-STEXT,
            TEMP  TYPE P decimals 2,
            TYPE(3),
            ZROLE LIKE PA0001-ZROLE,
            HOLID TYPE P decimals 2,
            LEAVE TYPE P decimals 2,
            DAYS  TYPE P decimals 2,
           END of I_ALLOCATIONS.
    DATA:  I_ALLOCATION LIKE I_ALLOCATIONS OCCURS 0 WITH HEADER LINE.
    ************Populate I_ALLOCATIONS **************
    LOOP AT I_ALLOCATIONS.
        COLLECT I_ALLOCATIONS INTO I_ALLOCATION.
    ENDLOOP.
    Actually i had requirement like u, but this one is rather simple...
    Get the required data in an I_Table which dont require Header line..
    Later on collect this particular I_Table in other I_Table1 with the Header Line...
    Regards,
    Abhishek

  • Query statement for internal table

    is it possible to use a select statement to select data from an internal table? if yes, can anyone show me the codes to it? thx

    Hi Daphne,
    You use SELECT statement to read data from database table but not from Internal table.
    For reading data from Internal table, you have to use READ statement.
    Syntax:
    READ TABLE itab { table_key
                    | free_key
                    | index } result.
    Effect of using read statement:
    This statement reads a row from internal table itab. You have to specify the row by either naming values table_key for the table key, a free condition free_key or an index index. The latter choice is possible only for index tables. The output result result determines when and where the row contents are read.
    If the row to be read is not uniquely specified, the first suitable row is read. In the case of index tables, this row has the lowest table index of all matching rows.
    Reward if usefull
    thanks
    swaroop

  • How to use collect statement for below

    data : begin of itab,
             n(3) type c,
          n1 type n,
          k(5) type c,
          end of itab.
    select n n1 from into itab table /zteest.
    *internal table has
    n      n1    k
    gar    100  uji
    hae    90   iou
    gar    90   uji
    hae    87   iou
    I want
    gar 190
    hae 177
    How to use collect statement as n1 is n ..?
    let me know..
    Thanks

    try this..
    DATA : BEGIN OF itab OCCURS 0,
    n(3) TYPE c,
    n1(3) TYPE p DECIMALS 2,
    k(5) TYPE c,
    END OF itab.
    itab-n = 'gar'.
    itab-n1 = 100.
    itab-k = 'uji'.
    COLLECT itab .CLEAR itab.
    itab-n = 'hae'.
    itab-n1 = 90.
    itab-k = 'iou'.
    COLLECT itab .CLEAR itab.
    itab-n = 'gar'.
    itab-n1 = 90.
    itab-k = 'uji'.
    COLLECT itab .CLEAR itab.
    itab-n = 'hae'.
    itab-n1 = 87.
    itab-k = 'iou'.
    COLLECT itab .CLEAR itab.

  • Update statement for object table.

    Hi,
    I have created one type as
    Create type test as object(
    ins_by varchar2(30),
    ins_on date,
    upd_by varchar2( 30),
    upd_on date);
    and then created an object table as
    create table imst(
    i_code number(5),
    i_desc varchar2(35),
    i_op test);
    now i am able to insert record in this table as
    insert into imst values(1,'Hawkins cooker',test(user,sysdate,'',''));
    Above works fine.
    But I would also like to update the record with i_op.upd_by,i_op.upd_on with some other values.
    Can any body help me specifying how to write a plain update statement for the same.
    Regards.
    Soumen

    Check it out:
    SQL> Create type myTest as object(
      2  ins_by varchar2(30),
      3  ins_on date,
      4  upd_by varchar2( 30),
      5  upd_on date);
      6  /
    Type created.
    SQL> create table imst(
      2  i_code number(5),
      3  i_desc varchar2(35),
      4  i_op myTest);
    Table created.
    SQL> insert into imst values(1,'Hawkins cooker', mytest(user,sysdate,'',''));
    1 row created.
    SQL> select * from imst;
        I_CODE I_DESC
    I_OP(INS_BY, INS_ON, UPD_BY, UPD_ON)
             1 Hawkins cooker
    MYTEST('APC_LOAD', '12-JUL-04', NULL, NULL)
    SQL> update imst i set i.i_op.upd_by = USER, i.i_op.upd_on = add_months(sysdate, 1);
    1 row updated.
    SQL> select * from imst;
        I_CODE I_DESC
    I_OP(INS_BY, INS_ON, UPD_BY, UPD_ON)
             1 Hawkins cooker
    MYTEST('APC_LOAD', '12-JUL-04', 'APC_LOAD', '12-AUG-04')
    SQL> Smoke me a kipper I'll be back before breakfast.
    Cheers, APC

  • Sql statement for join tables

    hi there..i need ur helps
    Here are my tables n column name for each tables
    a) rep_arrngt
    Name
    REP_ARRNGT_ID
    REP_ARRNGT_DESC
    REP_ARRNGT_TYPE
    ACCT_CAT
    DEF_INDUSTRY_CODE
    MEDIA_ID
    LANGUAGE_ID
    CURRENCY
    PAGE_ID
    b) bci_rep_arrng
    Name
    REP_ARRNGT_ID
    BCI
    SUB_SUM_CODE
    DP_SUB_SUM_CODE
    c) acct_rep_arrngt_link
    Name
    ACCT_NO
    REP_ARRNGT_ID
    DOC_TYPE
    LAST_BILL_DATE
    BILL_FREQUENCY
    SCALING
    EFF_FROM_DATE
    EFF_TO_DATE
    MEDIA_ID
    Actually, i want to get the unique value for sub_sum_code according to the bci..
    i already use join tables n here is my sql statement :
    SELECT T1.SUB_SUM_CODE,T1.BCI,T1.REP_ARRNGT_ID,T2.REP_ARRNGT_ID,T3.REP_ARRNGT_ID FROM BCI_REP_ARRNG T1, REP_ARRNGT T2, ACCT_REP_ARRNGT_LINK T3 WHERE T1.REP_ARRNGT_ID=T2.REP_ARRNGT_ID AND T2.REP_ARRNGT_ID=T3.REP_ARRNGT_ID AND BCI='TTA00F06'
    n my results is :
    SUB_SUM_CODE BCI REP_ARRNGT_ID
    TBGSR TTA00F06 R1
    TBGSR TTA00F06 R1
    TBGSR TTA00F06 R1
    TBGSR TTA00F06 R1
    I get the repeated results for sub_sum_code..
    so, what i need to do if i want only 1 row results like this :
    [u]SUB_SUM_CODE BCI REP_ARRNGT_ID
    TBGSR TTA00F06 R1
    i try to use group by, but i get the error..plz help me

    If you only want "to get the unique value for sub_sum_code according to the bci" then why are you joining the tables in the first place? Not knowing PKs etc you could just use DISTINCT in your select statement.
    SELECT DISTINCT T1.SUB_SUM_CODE,
                    T1.BCI
    FROM BCI_REP_ARRNG T1
    AND BCI='TTA00F06'

  • Sql statement for a table name with a space in between

    Hi,
    I just noticed that one of my tables for Access is consisted of two word. It is called "CURRENT CPL". How would I put this table name into an sql statement. When I did what I normally do, it only reads the CURRENT and thinks that's the table name.
    Thanks
    Feng

    I just noticed that one of my tables for Access is
    consisted of two word. It is called "CURRENT CPL".
    How would I put this table name into an sql
    statement. When I did what I normally do, it only
    reads the CURRENT and thinks that's the table name.That is called a quoted identifier. The SQL (not java) for this would look like this....
    select "my field" from "CURRENT CPL"
    The double quote is the correct character to use. Note that quoted identifiers are case sensitive, normal SQL is not.

  • Update stats for table in dbstatc

    Hello all,
        I am very new to administrating SAP on Oracle.  My question is.  There are some tables in dbstatc with ignore flag.  I ran the below query to get that...
    select COUNT(*) from sapsr3.dbstatc
    where ACTIV = 'I';
    Now from my understanding the I flag means...do not update stats for that table...
    So i first ran below...which runs the full stats and it did not update or touched those table in dbstats with I flag
    brconnect -c -u / -f stats -t all -f collect -p 8
    so after researching i found we can update those stats with below .... even after running the below, stats still do not show up as update.... how can i update (forcefully if required) to update stats for a particular table....
    brconnect -u / -c -f stats -t SAPSR3.table_name -f allsel -p 4          
    i query dba_tables at DB level to see if that specific table was analyzed or not.  I am on 11.2 oracle version...and this is a BW SAP system....

    New User:
    1)  Which objects do you have the INACTIVE flag set for:
    col dbobj format a20
    select dbobj, activ from sapsr3.dbstatc where activ = 'I' order by 1;
    2)  Check that you have the correct DBSTATC settings per SAP Note 403704.
    If you do not, then I would suggest you update the DBSTATC table following SAP Note 403704, but before you do take a copy of the dbstatc table:
    sqlplus sapsr3/<pass.
    create table dbstatc_old as select * from dbstatc;
    3)  To check to see if you have stats on a table:
    select table_name, partitioned, last_analyzed, num_rows from dba_tables where table_name = 'TBTCO';
    TABLE_NAME                     PAR LAST_ANALYZED     NUM_ROWS
    TBTCO                          NO  19-MAY-11           163030
    If the LAST_ANALYZED shows up with NO values, then there are NO stats on the table.
    HOWEVER, be careful for partitioned tables in BW because there are stats at the partition level as well:
    select TABLE_NAME, PARTITION_NAME, LAST_ANALYZED, NUM_ROWS from dba_tab_partitions where table_name = '<table>';
    4)  To collect the statistics on a table
    brconnect -c -u / -f stats -t <TABLE> -f allsel,collect -g 4 -p 16
    5)  If the stats are still not collected with the brconnect command, it may be because the stats are locked at the table level from SAP Note 1020260:
    SELECT stattype_locked FROM dba_tab_statistics WHERE table_name = '<TABLE>';
    If the value is ALL, then the stats may be locked at the table level and may require to unlock the stats before updating.
    Good Luck,
    Mike Kennedy

  • How to gather table stats for tables in a different schema

    Hi All,
    I have a table present in one schema and I want to gather stats for the table in a different schema.
    I gave GRANT ALL ON SCHEMA1.T1 TO SCHEMA2;
    And when I tried to execute the command to gather stats using
    DBMS_STATS.GATHER_TABLE_STATS (OWNNAME=>'SCHMEA1',TABNAME=>'T1');
    The function is failing.
    Is there any way we can gather table stats for tables in one schema in an another schema.
    Thanks,
    MK.

    You need to grant analyze any to schema2.
    SY.

  • How to use collect statement properly

    In PBID table , i will get 4 rows for a material . I will get the corresponding values of bdzei from the same table . Now i will pass this bdzei into pbhi table. then i will get some 200 rows of data. I have to sum up the field plnmg , by grouping the laeda field of pbhi. In short, i need to know the sum of pbhi-plnmg for a particular pbhi-laeda . I know a way to do it. But i want to know how to use the COLLECT statement for this purpose. My output should contain oly 1 line for 1 material ..
    PBID table                      
    Matnr   BDZEI
    p4471   457
            1002
            2309
            2493
    PBHI table
    BDZEI     LAEDA         PLNMG
    1002     06.08.2004     0.000          
    1002     06.08.2004     83.000
    457      07.08.2004     12.000          
    457     07.08.2004     24.000
    Reqd O/p
    MATNR   LAEDA        PLNMG
    p4471  06.08.2004    83
    p4471  07.08.2004    36
    Hope u understood my situation .please help me out ...
    Thanking you in advance ..
    Shankar

    REPORT zppr_zpipr NO STANDARD PAGE HEADING LINE-SIZE 150 LINE-COUNT 63.
    TABLES: pbid,
            pbhi,
            makt,
            mseg,
            mkpf.
    DATA: BEGIN OF it_pbid OCCURS 0,
          matnr LIKE pbid-matnr,        " Material
          status TYPE c LENGTH 4,       " For distinguishing materials from pbid and pbim .. will contain space for PBID and 'PBIM' for PBIM
          bdzei LIKE pbid-bdzei,
          laeda LIKE pbhi-laeda,
    end of it_pbid.
    DATA: BEGIN OF it_pbim OCCURS 0,
          matnr LIKE pbid-matnr,        " Material
          status TYPE c LENGTH 4,       " For distinguishing materials from pbid and pbim .. will contain space for PBID and 'PBIM' for PBIM
          bdzei LIKE pbim-bdzei,
          laeda LIKE pbhi-laeda,
    end of it_pbim.
    DATA: BEGIN OF it_pbid_pbim OCCURS 0,
          matnr LIKE pbid-matnr,        " Material
          laeda LIKE pbhi-laeda,        " Reduction Date
          dbmng LIKE pbhi-dbmng,        " Planned quantity in the data base
          plnmg LIKE pbhi-plnmg,        " Planned quantity
          status TYPE c LENGTH 4,       " For distinguishing materials from pbid and pbim .. will contain space for PBID and 'PBIM' for PBIM
          mblnr LIKE mseg-mblnr,        " Material Doc Number
          pbfnr LIKE pbid-pbdnr,        " Plan Number
          maktx LIKE makt-maktx,         " Matl Desc
          aenam LIKE pbhi-aenam,        " User Changed
          erfmg LIKE mseg-erfmg,        " Qty Invoiced
          budat LIKE mkpf-budat,        " Invoice date
          bdzei LIKE pbid-bdzei,        " Independent requirements pointer
          werks LIKE pbid-werks,        " plant
          pirrednqty TYPE i,            " PIR Reduction Quantity        = pbih-plnmg - pbih-dbmng
          diff TYPE i,                  " Difference
          slno TYPE i,                  " Sl No
    END OF it_pbid_pbim.
    DATA: BEGIN OF it_allrows OCCURS 0.
            INCLUDE STRUCTURE it_pbid_pbim.
    DATA: END OF it_allrows.
    *DATA: BEGIN OF it_final OCCURS 0.
           INCLUDE STRUCTURE it_pbid_pbim.
    *DATA: END OF it_final.
    DATA: BEGIN OF line,
          matnr LIKE pbid-matnr,        " Material
          laeda LIKE pbhi-laeda,        " Reduction Date
          plnmg LIKE pbhi-plnmg,        " Planned quantity
          maktx LIKE makt-maktx,        " Matl Desc
          dbmng LIKE pbhi-dbmng,        " Planned quantity in the data base
          mblnr LIKE mseg-mblnr,        " Material Doc Number
          pbfnr LIKE pbid-pbdnr,        " Plan Number
          aenam LIKE pbhi-aenam,        " User Changed
          erfmg LIKE mseg-erfmg,        " Qty Invoiced
          budat LIKE mkpf-budat,        " Invoice date
          bdzei LIKE pbid-bdzei,        " Independent requirements pointer
          werks LIKE pbid-werks,        " plant
          pirrednqty TYPE i,            " PIR Reduction Quantity        = pbih-plnmg - pbih-dbmng
          diff TYPE i,                  " Difference
          slno TYPE i,                  " Sl No
          status TYPE c LENGTH 4,       " For distinguishing materials from pbid and pbim .. will contain space for PBID and 'PBIM' for PBIM
    END OF line.
    DATA Itfinal1 LIKE STANDARD TABLE
                OF LINE
              WITH DEFAULT KEY.
    DATA ITfinal LIKE ITfinal1.
    DATA: BEGIN OF it_dates OCCURS 0,
          date TYPE sy-datum,
    END OF it_dates.
    DATA: l_slno TYPE i.
    DATA: l_zebra TYPE c.
    SELECT-OPTIONS:
          s_werks FOR pbid-werks obligatory.
    SELECT-OPTIONS:
          s_matnr FOR pbid-matnr.
    SELECT-OPTIONS:
          s_pbdnr FOR pbid-pbdnr.
    SELECT-OPTIONS:
          s_laeda FOR pbhi-laeda obligatory.
    parameter:
          c_print type checkbox.
    SELECT matnr bdzei FROM pbid INTO (it_pbid-matnr, it_pbid-bdzei) WHERE werks IN s_werks AND matnr IN s_matnr AND pbdnr IN s_pbdnr.
      it_pbid-status = 'PBID'.
      APPEND it_pbid.
    move-corresponding it_pbid to it_pbid_pbim.
    Append it_pbid_pbim.
    ENDSELECT.
    SELECT matnr bdzei FROM pbim INTO  (it_pbim-matnr,it_pbim-bdzei) WHERE werks IN s_werks AND matnr IN s_matnr AND pbdnr IN s_pbdnr.
      APPEND it_pbim.
    Append it_pbid_pbim.
    ENDSELECT.
    *break-point.
    START-OF-SELECTION.
      LOOP AT s_laeda.
        it_dates-date = s_laeda-low.
        APPEND it_dates.
      ENDLOOP.
      DATA: l_startdate LIKE sy-datum.
      IF s_laeda-high EQ space.
      ELSE.
        l_startdate = s_laeda-low + 1.
        DO.
          IF l_startdate <= s_laeda-high.
            it_dates-date = l_startdate.
            APPEND it_dates.
          ELSE.
            it_dates-date = sy-datum.
            EXIT.
          ENDIF.
          l_startdate = l_startdate + 1.
        ENDDO.
      ENDIF.
    *break-point.
      LOOP AT it_pbim.
        LOOP AT it_dates.
          it_pbim-laeda = it_dates-date.
          it_pbim-status = 'PBIM'.
          MODIFY it_pbim TRANSPORTING laeda status.
          MOVE-CORRESPONDING it_pbim TO it_pbid_pbim.
          APPEND it_pbid_pbim.
        ENDLOOP.
      ENDLOOP.
    break-point.
      l_zebra = 'X'.
      DATA: l_toterfmg LIKE mseg-erfmg.
      DATA: l_erfmg LIKE mseg-erfmg.
      data: l_totpir type i.
    **************************************PBID*************************************
      LOOP AT it_pbid.
        move-corresponding it_pbid to it_pbid_pbim.
           append it_pbid_pbim.
        SELECT SINGLE maktx FROM makt INTO (it_pbid_pbim-maktx) WHERE matnr = it_pbid-matnr.
        MODIFY table it_pbid_pbim TRANSPORTING maktx.
        SELECT aenam laeda FROM pbhi INTO (it_pbid_pbim-aenam,it_pbid_pbim-laeda) WHERE bdzei = it_pbid-bdzei AND aenam = 'Abbau-'.
           MODIFY TABLE it_pbid_pbim TRANSPORTING aenam laeda. " debug here
        select single sum( dbmng )  sum( plnmg ) FROM pbhi INTO (it_pbid_pbim-dbmng,it_pbid_pbim-plnmg) WHERE bdzei = it_pbid-bdzei AND aenam = 'Abbau-' and laeda = it_pbid_pbim-laeda..
           MODIFY TABLE it_pbid_pbim TRANSPORTING dbmng plnmg. " debug here
       endselect.
        it_pbid_pbim-pirrednqty = it_pbid_pbim-dbmng - it_pbid_pbim-plnmg.
           MODIFY table it_pbid_pbim TRANSPORTING pirrednqty.
        IF ( it_pbid_pbim-laeda IN s_laeda AND it_pbid_pbim-aenam EQ 'Abbau-' ).
          MOVE-CORRESPONDING it_pbid_pbim TO it_allrows.
          append it_allrows.
        ELSEIF NOT it_pbid_pbim-laeda IN s_laeda.
              delete it_pbid_pbim index sy-tabix.           " debug here
        ENDIF.
        ENDSELECT.
      ENDLOOP.
    **************************************PBIM*************************************
      LOOP AT it_pbim.
        move-corresponding it_pbim to it_pbid_pbim.
           append it_pbid_pbim.
        SELECT SINGLE maktx FROM makt INTO (it_pbid_pbim-maktx) WHERE matnr = it_pbim-matnr.
           MODIFY table it_pbid_pbim TRANSPORTING maktx.
        SELECT aenam laeda FROM pbhi INTO (it_pbid_pbim-aenam,it_pbid_pbim-laeda) WHERE bdzei = it_pbim-bdzei AND aenam = 'Abbau-'.
           MODIFY TABLE it_pbid_pbim TRANSPORTING aenam laeda. " debug here
        select single sum( dbmng )  sum( plnmg ) FROM pbhi INTO (it_pbid_pbim-dbmng,it_pbid_pbim-plnmg) WHERE bdzei = it_pbim-bdzei AND aenam = 'Abbau-' and laeda = it_pbid_pbim-laeda..
           MODIFY TABLE it_pbid_pbim TRANSPORTING dbmng plnmg. " debug here
        it_pbid_pbim-pirrednqty = it_pbid_pbim-dbmng - it_pbid_pbim-plnmg.
           MODIFY table it_pbid_pbim TRANSPORTING pirrednqty.
        IF ( it_pbid_pbim-laeda IN s_laeda AND it_pbid_pbim-aenam EQ 'Abbau-' ).
          MOVE-CORRESPONDING it_pbid_pbim TO it_allrows.
          append it_allrows.
        ELSEIF NOT it_pbid_pbim-laeda IN s_laeda.
              delete it_pbid_pbim index sy-tabix.           " debug here
        ENDIF.
        ENDSELECT.
      ENDLOOP.
    sort it_allrows by matnr laeda status.
    **********************************ALL ROWS************************
    loop at it_allrows.
      line-matnr = it_allrows-matnr.
      line-laeda = it_allrows-laeda.
      line-plnmg = it_allrows-plnmg.
      line-dbmng = it_allrows-dbmng.
    line-mblnr = it_allrows-mblnr.
    line-pbfnr = it_allrows-pbfnr.
      line-maktx = it_allrows-maktx.
    line-aenam = it_allrows-aenam.
    line-erfmg = it_allrows-erfmg.
    line-budat = it_allrows-budat.
      line-bdzei = it_allrows-bdzei.
    line-werks = it_allrows-werks.
      line-pirrednqty = it_allrows-pirrednqty.
      line-diff = it_allrows-diff.
      line-slno = it_allrows-slno.
      line-status = it_allrows-status.
      collect line into itfinal1.
    endloop.
    loop at itfinal1 into line.
      collect line into itfinal.
        write: / line-matnr, line-plnmg, line-dbmng,line-laeda,line-status..
    endloop.
    skip 4.
    loop at itfinal into line.
      write: / line-matnr, line-plnmg, line-dbmng,line-laeda,line-status..
    endloop.
    break-point.

  • Collect statement with index

    Hi
    can anyone give me some idea  how to use collect statement with index
    here in the below syntax i want to use collect instead of insert.
    INSERT WA_ALVDISPLAY   INTO IT_ALVDISPLAY  index  3 .
    thanks.
    vivekk

    hi
    my scenario is like this
    i need an yearly report of a examination held in a school based on month,each month they need report for girls and boys separately
    the output format should be like this
    month:marks( boys)  marks( girls )
    so i have created 3 internal tables suppose itab ,itab1,itab2.
    itab1-month1
    itab1-boy_sub1
    itab1-boy_sub2
    itab2-month2
    itab2-girl_sub1
    itab2-girl_sub2
    itab -month1
    itab -boy_sub1
    itab -boy_sub2
    itab -girl_sub1
    itab -girl_sub2
    first i am looping in itab1 and using COLLECT statement i am inserting data to itab (bez in a month more than one exam can happen)
    i got boys mark in itab,then i need to put girls mark on the same row based on month
    based on particular index i need to insert data, moreover i need to use COLLECT statement for getting the total of particular month
    thanks
    vivek

  • Collect statement error

    Hi all,
    i have the fallowing problem.
    I'm trying to do a collect statement as fallow:
    SORT i_tran BY cuenta ASCENDING.
    LOOP AT i_tran.            
    AT NEW cuenta.             
    COLLECT i_tran INTO i_tran2.
    APPEND i_tran2.            
    CLEAR i_tran.              
    CLEAR i_tran2.             
    ENDAT.                     
    endloop.
    where i_tran is a collect internal table and i_tran2 is another internal table.
    when I execute the collect statement all the fields are fill with asterics and the field that Im interested in is set to zero.
    another problem is that is not doing the collect per cuenta. (is doing it per record, ex. if cuenta 123 has three records it executes at the collect statement for each one of them. 
    this is the structure of i_tran:
    * Registro de Transacciones
    TYPES: BEGIN OF E_TRAN,
          RECTYPE TYPE C,             "Tipo Registro N
          CCODE(15) TYPE C,           "Id Empresa (RNC)
          SEQNR(7) TYPE C,            "Secuencia Header
          SECTR(7) TYPE C,            "Secuencia Transaccion
          CUENTA(20) TYPE C,          "Cuenta Suplidor
          MONTRN TYPE I,              "Montro Transaccion (13)
          TIPCTA TYPE C,              "Tipo de Cuenta
          WAERS(3) TYPE C,            "Moneda
          CODBAN(8) TYPE C,           "Banco Destino (No. Cuenta Banco)
          DIGVER TYPE C,              "Digito Verificacion
          CODOPR(2) TYPE C,           "Codigo Operacion
          TIPIDN(2) TYPE C,           "Tipo de Identificacion
          IDENTF(15) TYPE C,          "Identificacion
          NOMBRE(35) TYPE C,          "Nombre Beneficiario
          REFERN(12) TYPE C,          "Referencia
          DESCRED(40) TYPE C,         "Descripcion Estado Destino
          FECVEN(4) TYPE C,           "Fecha Vencimiento
          FCONTC TYPE C,              "Forma de Contacto
          EMAIL(40) TYPE C,           "E-mail Beneficiario
          NUMFAX(12) TYPE C,          "Numero de Fax
          RESERV(2) TYPE C,           "Reservado para uso futuro
          NUMAUT(15) TYPE C,          "Numero Autorizacion
          CODRET(3) TYPE C,           "Codigo Retorno Remoto
          CODRZR(3) TYPE C,           "Codigo Razon Remoto
          CODRZI(3) TYPE C,           "Codigo Razon Interno
          PROCTR TYPE C,              "Procesador Transaccion
          STATS(2) TYPE C,            "Status Transaccion
          FILLER(52),                 "En blanco
    END OF E_TRAN.
    DATA: IT_TRAN TYPE  E_TRAN.
    DATA: I_TRAN TYPE STANDARD TABLE OF E_TRAN WITH HEADER LINE,
          I_TRAN2 TYPE STANDARD TABLE OF E_TRAN WITH HEADER LINE.
    if anyone can help me I'll appreciated.
    thanks in advanced,
    Gregorio.

    Hi Gergorio,
    1. I think that the way you have used COLLECT
       is incorrect.
       (There is no need to use AT NEW for collect)
       (only Loop, Collect will do the work)
    2. U have said that :
       tran is a collect internal table and i_tran2 is  
       another internal table.
    3. Meaning, that,
       i_trans2 has many records
       tran  is the SUMMARY table (to gather totals)
    4. Now, on what base,
       do u want to do summary ?
       ie. What will be the key/main/criteria fields?
       (all char fields of your internal table,
        or some of them)
       (If only some are required, then your logic won't work)
    5. Moreover, we should have numeric/integer
       fields in our internal table so that 
       summation is done automatically.
    6. The simple logic is like this.
       LOOP AT DETAILITAB.
       COLLECT DETAILTAB INTO SUMMARYTAB.
       ENDLOOP.
    7. The above will take care of
       all summations
       (with respect to DISTINCT COMBAINATION
        of ALL CHAR FIELDS)
    8. If your criteria for summation is
        less fields then some little more work
        is required. If this is so, let me know.
    I hope it helps.
    Regards,
    Amit M.

Maybe you are looking for

  • No Wi-fi after IoS 6 update (iPod Touch 4th gen)

    As it seems to be normal on these forums to make new topics whenever a subject doesn't perfectly fit your own question, I figured I'd do the same. See, in the other topics, apparntly, resetting the iPod works and solves the problem. However, in my ca

  • Apple TV box in portrait mode

    Hello, Is it possible to connect the Apple TV box on a screen fixed vertical (portrait mode)? Is it possible to rotate the image 90 ° directly from the Apple TV?

  • How to Replace Playbook Charger?

    Dear Admin, I had brought Blackberry Playbook 16 Gb 3.5 months ago i.e. on 25 May 2012 from flipkart. From Past few days playbook charger won't work properly, I also tried to charge it via USB cable to connect it with my PC, it shows that your pc is

  • New Cone(radius, height, flag, X, Y, Appearance) problem?

    hi all, i try to add a cone object to my BranchGroup.But at compile-time it said that it couldn't identify the Cone constructor as Cone (float, float, int, int, int, Appearance)...In documentation it is indicated that the arguments are true. So code

  • IMEI number made public

    No, I haven't gone and done that because it's meant to be a bad idea. My question is, why? What can someone do with the IMEI number of your phone? What financial risks does the real owner of the phone run as long s/he still has the SIM? Was this post