Top n analysis using hierarchial queries

hi all,
can we do top n analysis in hierarchial queries using level pseudo columns. if so please give an example.
thanks and regards,
sri ram.

Hi,
Analytic functions (such as RANK) often interfere with CONNECT BY queries. Do one of them in a sub-query, and the other in a super-query, as shown below.
If you do the CONNECT BY first, use ROWNUM (which is assigned after ORDER SIBLINGS BY is applied) to preserve the order of the CONNECT BY query.
WITH     connect_by_results     AS
     SELECT     LPAD ( ' '
               , 3 * (LEVEL - 1)
               ) || ename          AS iname
     ,     sal
     ,     ROWNUM               AS r_num
     FROM     scott.emp
     START WITH     mgr     IS NULL
     CONNECT BY     mgr     = PRIOR empno
     ORDER SIBLINGS BY     ename
SELECT       iname
,       sal
,       RANK () OVER (ORDER BY sal DESC)     AS sal_rank
FROM       connect_by_results
ORDER BY  r_num
;Output:
INAME                  SAL   SAL_RANK
KING                  5000          1
   BLAKE              2850          5
      ALLEN           1600          7
      JAMES            950         13
      MARTIN          1250         10
      TURNER          1500          8
      WARD            1250         10
   CLARK              2450          6
      MILLER          1300          9
   JONES              2975          4
      FORD            3000          2
         SMITH         800         14
      SCOTT           3000          2
         ADAMS        1100         12 
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and the results you want from that data. If you use only commonly available tables (such as those in the scott or hr schemas), then you don't have to post any sample data; just post the results.
Explain how you get those results from that data.
Always say what version of oracle you're using.

Similar Messages

  • Top n Analysis using correlated subquery

    Please explain this query. It is doing top n analysis using correlated subquery. I need explaination of execution of this query.
    Select distinct a.sal
    From emp a
    where 1=(select count ( distinct b.sal) from emp b
         where a.sal <=b.sal)
    Thanks in advance

    Try breaking the query down and rewriting it in order to follow the logic;
    SQL> --
    SQL> -- Start by getting each salary from emp along with a count of all salaries in emp
    SQL> --
    SQL> select   a.sal,
            (select count (distinct b.sal) from scott.emp b ) count_sal
    from scott.emp a
    order by 1 desc
           SAL  COUNT_SAL
          5000         12
          3000         12
          3000         12
          2975         12
          2850         12
          2450         12
          1600         12
          1500         12
          1300         12
          1250         12
          1250         12
          1100         12
           950         12
           800         12
    14 rows selected.
    SQL> --
    SQL> --Add a condition to the count for only salaries below or equal to the current salarySQL> --
    SQL> select   a.sal,
            (select count (distinct b.sal) from scott.emp b where a.sal <=b.sal) rank_sal
    from scott.emp a
    order by 1 desc
           SAL   RANK_SAL
          5000          1
          3000          2
          3000          2
          2975          3
          2850          4
          2450          5
          1600          6
          1500          7
          1300          8
          1250          9
          1250          9
          1100         10
           950         11
           800         12
    14 rows selected.
    SQL> --
    SQL> -- Add a condition to only pick the nth highest salary
    SQL> --
    SQL> select    a.sal,
             (select count (distinct b.sal) from scott.emp b where a.sal <=b.sal) rank_sal
    from scott.emp a
    where (select count (distinct b.sal) from scott.emp b where a.sal <=b.sal) = 4
           SAL   RANK_SAL
          2850          4
    1 row selected.Hope this helps.

  • Finding hierarchy use in queries

    Hi BWExperts,
    We have Four Hiearchies on one Infoobject and the Infoobject is using several Queries.The requirement is, we would like to know which hiearchy is using in which query.Please advice is there any program or backend table exists for this.
    Thanks in advance.
    Regards,
    Preetham

    Hello,
    Have a look at this
    Identifying where a hierarchy is used
    Also
    https://wiki.sdn.sap.com/wiki/display/BI/ImportantTablesinSAPBI%28NW2004%29
    https://wiki.sdn.sap.com/wiki/pages/viewpage.action?pageId=35458&focusedCommentId=45993#comment-45993

  • Top-n analysis in oracle 8i

    How to use top-n analysis in oracle 8i?
    I mean,take a example.
    I am maintaining a database of a 1000 employees.I want to display the names of the employees who are getting top 10 salaries(more further top 100 salaries) using a SQL query in oracle 8i only.Please answer my problem.

    Sorry, my suggestion will return 10 emp with highest salaries, not all employees with 10 highest salaries. To get all employees with 10 highest salaries in 8i:
    SQL> SELECT  ename,
      2          sal
      3    FROM  emp
      4    WHERE sal IN (
      5                  SELECT  sal
      6                    FROM  (
      7                           SELECT  sal
      8                             FROM  emp
      9                             GROUP BY sal
    10                             ORDER BY sal DESC
    11                          )
    12                    WHERE rownum <= 10
    13                 )
    14  /
    ENAME             SAL
    KING             5000
    FORD             3000
    SCOTT            3000
    JONES            2975
    BLAKE            2850
    CLARK            2450
    ALLEN            1600
    TURNER           1500
    MILLER           1300
    MARTIN           1250
    WARD             1250
    ENAME             SAL
    ADAMS            1100
    12 rows selected.
    SQL> SY.

  • BOM Performance Analysis using SAT or SE30 t-code?

    Hi,
        Currently I'm doing performance analysis of BOM to find out the bottlenecks. I'm doing the analysis using SAT or SE30 t-code.
    From my understanding, BOM performance depends upon
    1. no. of BOM items
    2. BOM Level
    3. BOM Evolution over time
    Can anyone provide me a hint to find out the bottlenecks in BOM performance. Thanks!!
    Regards,
    Saravana

    I have done the BOM Performance Analysis. Based on the most execution time and top performance consumers, please find my observations…
    Functionally, Performance of BOM execution depends upon
    Number of BOM items available in the BOM
    Number of Assemblies present in the BOM
    BOM Levels
    BOM Evolution over time
    Technically, BOM execution time is purely depends upon
    fetching the data from the SAP tables
    hitting the same table again and again when goes down the level
    loop at the tables / Nested functions used in SAP Program
    Hence, I'm closing this thread.....

  • TOP N analysis with same values

    Dear Members,
    Suppose we have the following data in the table Student.
    Sname GPA
    Jack 4.0
    Smith 3.7
    Rose 3.5
    Rachel 3.5
    Ram 2.8
    I have seen many questions in this forum which gives good queries for TOP N analysis. But in my case those are not working.
    There are total 5 students. I should write a query which should take an input and should give the students with top gpa as output in desc order.
    Suppose if i give 4 as input i must get 4,3.7,3.5,3.5,2.8Gpa's since we have 2 gpa's which are same. Suppose i give 3 as the input i must get 4,3.7,3.5 and 3.5 GPA's.
    The query must consider the GPA's which are same as one not different. How can we achive this. i.e the top three students (suppose input is 3) must be
    Jack 4.0
    Smith 3.7
    Rose 3.5
    Rachel 3.5
    It must also include Rachel.
    Any help is greatly appreciated.
    Thanks
    Sandeep

    SQL> select * from test;
    NAME                        GPA
    Jack                          4
    Smith                       3.7
    Rose                        3.5
    Rachel                      3.5
    Ram                         2.8
    SQL> select name,gpa
      2  from
      3    (select name,gpa,dense_rank() over(order by gpa desc) rn
      4     from test)
    5 where rn <= 3
      6  order by rn;
    NAME                        GPA
    Jack                          4
    Smith                       3.7
    Rose                        3.5
    Rachel                      3.5                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • I am using media queries and div will not centre on desktop version

    Hi,
    I am building a site for the first time using media queries. My problem is that I cannot get the header div (#layoutDiv1) to centre on the desktop version.
    I have pasted my code below, am I missing something?
    Any help would be great.
    Thanks, Alex.
    /* Mobile Layout: 480px and below. */
    .gridContainer {
      margin-left: auto;
      margin-right: auto;
      width: 100%;
      color: #FFF;
      background-color: #000;
    #LayoutDiv1 {
      clear: both;
      float: left;
      margin-left: 0;
      width: 90%;
      display: block;
      padding-top: 20px;
      padding-left: 20px;
      padding-right: 20px;
      padding-bottom: 20px;
    /* Tablet Layout: 481px to 768px. Inherits styles from: Mobile Layout. */
    @media only screen and (min-width: 481px) {
    .gridContainer {
      width: 100%;
    #LayoutDiv1 {
      clear: both;
      float: left;
      margin-left: 0;
      width: 90%;
      display: block;
      padding-top: 20px;
      padding-left: 20px;
      padding-right: 20px;
      padding-bottom: 20px;
    /* Desktop Layout: 769px to a max of 1232px.  Inherits styles from: Mobile Layout and Tablet Layout. */
    @media only screen and (min-width: 769px) {
    .gridContainer {
      width: 100%;
      text-align: left;
    #LayoutDiv1 {
      width: 1000px;
      padding: 20px;
      margin-right: auto;
      margin-left: auto;

    Because you don't have max-width to constrain the responsive design attributes from the tablet and phone are also then applied to the desktop because they are true.  Have you tried either setting a max-width or setting the clear and float to none in the desktop CSS?

  • What is the role of PRIOR in hierarchial queries

    hi all,
    what is the role of prior operator in CONNECT BY Clause of the hierarchial queries, what is the effect when it is used on the right side or left side of the condition ? almost all the queries contains this clause, if it is omitted the child values are not coming. what is the reason. plz explain.
    please check the following outputs:
    SQL> select ename,sys_connect_by_path(ename,'\') hierarchy from emp start with ename='KING' connect by empno = mgr;
    ENAME HIERARCHY
    KING \KING
    Elapsed: 00:00:00.04
    SQL> select ename,sys_connect_by_path(ename,'\') hierarchy from emp start with ename='KING' connect by prior empno = mgr;
    ENAME HIERARCHY
    KING \KING
    JONES \KING\JONES
    SCOTT \KING\JONES\SCOTT
    ADAMS \KING\JONES\SCOTT\ADAMS
    FORD \KING\JONES\FORD
    SMITH \KING\JONES\FORD\SMITH
    BLAKE \KING\BLAKE
    ALLEN \KING\BLAKE\ALLEN
    WARD \KING\BLAKE\WARD
    MARTIN \KING\BLAKE\MARTIN
    TURNER \KING\BLAKE\TURNER
    JAMES \KING\BLAKE\JAMES
    CLARK \KING\CLARK
    MILLER \KING\CLARK\MILLER
    14 rows selected.
    Elapsed: 00:00:00.09
    SQL> select ename,sys_connect_by_path(ename,'\') hierarchy from emp start with ename='KING' connect by empno = prior mgr;
    ENAME HIERARCHY
    KING \KING
    Elapsed: 00:00:00.06
    SQL>
    thanks and regards,
    sri ram.

    Hi, Sri Ram,
    Sri Ram wrote:
    hi all,
    what is the role of prior operator in CONNECT BY Clause of the hierarchial queries, "PRIOR x" means a value of x from one of the rows that were added to the result set at the previous level.
    what is the effect when it is used on the right side or left side of the condition ? There is no difference between
    CONNECT BY  PRIOR  x  = yand
    CONNECT BY  y  = PRIOR  xjust like there is no difference between
    WHERE  x  = yand
    WHERE  y  = x
    almost all the queries contains this clause, No, most queries do not contain a CONNECT BY clause.
    Most queries that have a CONNECT BY clause do use a PRIOR operator.
    if it is omitted the child values are not coming. what is the reason. plz explain.No, that's not true. A common example is a Counter Table :
    SELECT  SYSDATE + LEVEL - 1
    FROM    dual
    CONNECT BY  LEVEL  <= 7;
    please check the following outputs:
    SQL> select ename,sys_connect_by_path(ename,'\') hierarchy from emp start with ename='KING' connect by empno = mgr;
    ENAME HIERARCHY
    KING \KING
    Elapsed: 00:00:00.04
    SQL> select ename,sys_connect_by_path(ename,'\') hierarchy from emp start with ename='KING' connect by prior empno = mgr;
    ENAME HIERARCHY
    KING \KING
    JONES \KING\JONES
    SCOTT \KING\JONES\SCOTT
    ADAMS \KING\JONES\SCOTT\ADAMS
    FORD \KING\JONES\FORD
    SMITH \KING\JONES\FORD\SMITH
    BLAKE \KING\BLAKE
    ALLEN \KING\BLAKE\ALLEN
    WARD \KING\BLAKE\WARD
    MARTIN \KING\BLAKE\MARTIN
    TURNER \KING\BLAKE\TURNER
    JAMES \KING\BLAKE\JAMES
    CLARK \KING\CLARK
    MILLER \KING\CLARK\MILLER
    14 rows selected.
    Elapsed: 00:00:00.09
    SQL> select ename,sys_connect_by_path(ename,'\') hierarchy from emp start with ename='KING' connect by empno = prior mgr;
    ENAME HIERARCHY
    KING \KINGOkay, I checked them. I get the same results. Did you have a question about them?

  • Top Of Page in ABAP Queries

    Hello everyone,
        I want to write some text in theTop-of-page event of Queries.
        I am trying to print the text by using a write statement.But I am not succesful.
        Let me know how to use top-of-page in ABAP Queries.
       Regards,
       Najam

    Hi,
    you need to write the desired code in the top of page event....
    here is the piece of code ..just go through this... and call top of page before start of selection.
    TOP OF PAGE
    TOP-OF-PAGE .
    To Write the header of the Report
      PERFORM write_header .
    *&      Form  WRITE_HEADER
          text :Subroutine to write header
    FORM write_header .
      DATA: v_date(10),
            v_start(10),
            v_end(10) .
      WRITE : sy-datum  TO v_date  MM/DD/YYYY,
              p_prcdte  TO v_start MM/DD/YYYY.
      WRITE   5 '|'  .  ULINE AT 5(95)  .  WRITE 100 '|'    .
      WRITE /30  text-028 INVERSE COLOR 7  .  WRITE 100'|'  .
      WRITE   5 '|'  .  ULINE AT /5(95)  .  WRITE 100 '|'   .
      WRITE:  /7 'Date/Time        :', v_date, ' / ' , sy-uzeit   .WRITE 100 '|'  .
      WRITE   5 '|'  .  ULINE AT /5(95) .WRITE 100 '|'  .
      WRITE: /7 'Processing Month :', v_start   .  WRITE 100 '|'  .
      WRITE   5 '|'  .  ULINE AT /5(95).WRITE 100 '|'   .
      SKIP 2 .
    ENDFORM.                    " WRITE_HEADER
    if u wanna to do for alv then the piece of code provided by Nick will be helpful..
    Thanks & Regards

  • Doubt's regarding the Hierarchial Queries in Oracle

    Hi,
    i have a doubt regarding the Hierarchial Queries in Oracle.
    SELECT * FROM TMP_TEST;
    ID     NUMVAL     STRVAL
    1     100     Hello
    1     -100     World
    2     1     Concatenate
    2     2     In String
    2     3     using Connect By
    2     4     Using SYS_CONNECT_BY_PATH
    i am clear with my execution of IN_Line view (mechanism how it work's) .
    But i have also read about the Hierarchial queries in the Oracle product documentation's. i am also aware of the
    SYS_CONNECT_BY_PATH , LEVEL & START WITH , CONNECT BY Keywords.
    But i couldnot able to Manually work out as how this below Query works.
    Can you please explain me how this Hieracial query works ?
    SELECT ID, (SYS_CONNECT_BY_PATH(STRVAL,',')),LEVEL
    FROM
    SELECT ID,STRVAL,ROW_NUMBER() OVER(PARTITION BY ID ORDER BY ID) RNUM,
    COUNT(*) OVER(PARTITION BY ID ORDER BY ID) CNT,NUMVAL
    FROM TMP_TEST
    START WITH RNUM = 1
    CONNECT BY PRIOR RNUM = RNUM - 1
    Many Thanks,
    Rajesh.

    Hi, Rajesh,
    My first message was in response to your first message.
    In your latest message, the query is:
    SELECT  ID, (SYS_CONNECT_BY_PATH(STRVAL,',')),LEVEL
    FROM    (
            SELECT  ID,STRVAL,ROW_NUMBER() OVER(PARTITION BY ID ORDER BY ID) RNUM,
                    COUNT(*) OVER(PARTITION BY ID ORDER BY ID) CNT,NUMVAL
            FROM TMP_TEST
    WHERE   RNUM = CNT
    START WITH  RNUM = 1
    CONNECT BY  PRIOR RNUM = RNUM - 1;It looks like you lost the second CONNECT BY condition:
    AND PRIOR ID = IDPut it back: it's important.
    Now you're confused about the output row:
    2    ,Hello,World,using Connect By,Using SYS_CONNECT_BY_PATH   4It doesn't seem to correspond to anything results that you got when you ran the sub-query alone.
    That's because the resutls from your sub-query may change every time you run it, even though the data doesn't change. The ORDER BY clauses in both of the analytic functions do not result in a complete ordering. In fact, they're completely meaningless. It never makes any sense to PARTITON BY and ORDER BY the same value; "PARTITION BY id" means that only rows with the same id will be compared to each other; you might as well say "ORDER BY 0" or "ORDER BY dmbs_random.value".
    The ORDER BY clause of ROW_NUMBER whould reflect that way in which you want the results to appear within each id, for example:
    ROW_NUMBER () OVER (PARTITION BY id ORDER BY UPPER (strval))Note that this is very similar to what was in my first reply.
    In the COUNT function, why do you want an ORDER BY clause at all? Just say:
    COUNT (*) OVER (PARTITION BY id)

  • Generated a report which gives PR(Purchase Requisition) analysis using ALV.

    hi experts,
    please give me tables and fields for following report, and also exlain me briefly,
    Generated a report which gives PR(Purchase Requisition) analysis using ALV.
    thanks in advance,
    radhakrishna

    Hi
    please find this report which link SO PO PR and Prd Ord and there status.
    >
    REPORT z_so_info.
    TABLES: vbak, vbap, afko, afpo.
    *Field catalog
    TYPE-POOLS: slis.
    DATA: lv_repid TYPE sy-repid VALUE sy-repid,
    xfield TYPE slis_t_fieldcat_alv,
    afield TYPE slis_fieldcat_alv.
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 1(25) text-002.
    SELECT-OPTIONS: so_so FOR vbak-vbeln OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN END OF BLOCK b1.
    SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-003.
    PARAMETERS:
    p_kunnr LIKE vbak-kunnr, " sold-to
    p_kunwe LIKE vbak-kunnr. " ship-to
    SELECTION-SCREEN END OF BLOCK b2.
    *Constants
    CONSTANTS: c_zor TYPE vbak-auart VALUE 'ZOR',
    c_we TYPE vbpa-parvw VALUE 'WE',
    c_ag TYPE vbpa-parvw VALUE 'AG'.
    c_space TYPE space.
    *Ranges
    RANGES: ra_parvw FOR vbpa-parvw,
    ra_kunnr FOR vbpa-kunnr.
    *Tables
    DATA: BEGIN OF gt_output OCCURS 0,
    vbeln LIKE vbak-vbeln, " sales order number
    posnr LIKE vbap-posnr, " SO item number
    matnr LIKE vbap-matnr, " material number
    sh LIKE vbpa-kunnr, " Ship-to
    sp LIKE vbpa-kunnr, " Sold-to
    lifnr LIKE ekko-lifnr, " Vendor
    bstnk LIKE vbak-bstnk, " PO number
    banfn LIKE vbep-banfn, " Purchase requi
    po_st TYPE char30, " PO status text
    pstyv TYPE vbap-pstyv, " Item catagory
    aufnr LIKE afpo-aufnr, " Production Order
    prd_stat TYPE string, " Prd order status
    END OF gt_output.
    DATA: wa_output LIKE gt_output.
    FIELD-SYMBOLS: <fs_output> LIKE gt_output.
    *Table for sales order and PO
    TYPES : BEGIN OF gs_data,
    vbeln TYPE vbak-vbeln,
    posnr TYPE vbap-posnr,
    pstyv TYPE vbap-pstyv,
    matnr TYPE vbap-matnr,
    END OF gs_data.
    DATA: gt_data TYPE STANDARD TABLE OF gs_data,
    wa_data TYPE gs_data.
    *Table for Production Orders
    TYPES: BEGIN OF gs_prd,
    aufnr TYPE afpo-aufnr,
    posnr TYPE afpo-posnr,
    kdauf TYPE afpo-kdauf,
    kdpos TYPE afpo-kdpos,
    wepos TYPE afpo-wepos, "Goods Receipt Indicator
    elikz TYPE afpo-elikz, "Delivery Completed Indicator
    objnr TYPE aufk-objnr, "Object number
    getri TYPE afko-getri, "Confirmed Order Finish Date
    gltri TYPE afko-gltri, "Actual finish date
    END OF gs_prd.
    DATA: gt_prd TYPE STANDARD TABLE OF gs_prd,
    wa_prd TYPE gs_prd.
    *Table for partner data
    TYPES: BEGIN OF gs_partner,
    vbeln TYPE vbak-vbeln,
    posnr TYPE vbap-posnr,
    parvw TYPE vbpa-parvw,
    kunnr TYPE vbpa-kunnr,
    END OF gs_partner.
    DATA: gt_partner TYPE STANDARD TABLE OF gs_partner,
    wa_partner TYPE gs_partner.
    TYPES: BEGIN OF gs_po,
    ebeln TYPE ekkn-ebeln,
    ebelp TYPE ekkn-ebelp,
    vbeln TYPE ekkn-vbeln,
    vbelp TYPE ekkn-vbelp,
    END OF gs_po.
    DATA: gt_po TYPE STANDARD TABLE OF gs_po,
    wa_po TYPE gs_po.
    TYPES: BEGIN OF gs_preq,
    vbeln TYPE vbep-vbeln,
    posnr TYPE vbep-posnr,
    banfn TYPE vbep-banfn,
    END OF gs_preq.
    DATA: gt_preq TYPE STANDARD TABLE OF gs_preq,
    wa_preq TYPE gs_preq.
    TYPES: BEGIN OF gs_po_stat,
    ebeln TYPE ekko-ebeln,
    procstat TYPE ekko-procstat,
    lifnr TYPE ekko-lifnr,
    END OF gs_po_stat.
    DATA: gt_po_stat TYPE STANDARD TABLE OF gs_po_stat,
    wa_po_stat TYPE gs_po_stat.
    *Field symbols
    FIELD-SYMBOLS: <fs> TYPE tj02t-txt04,
    <fs_temp> TYPE tj02t-txt04,
    <fs_stat> TYPE char30.
    START-OF-SELECTION.
    PERFORM fr_build_range.
    PERFORM fr_get_data.
    PERFORM fr_build_fc.
    PERFORM fr_output.
    *& Form fr_get_data
    text
    --> p1 text
    <-- p2 text
    FORM fr_get_data.
    *Get SO
    SELECT avbeln aposnr apstyv amatnr
    FROM vbap AS a
    JOIN vbak AS b
    ON avbeln = bvbeln
    JOIN vbpa AS c
    ON bvbeln = cvbeln
    INTO TABLE gt_data
    WHERE b~vbeln IN so_so
    AND b~auart EQ c_zor "Only Sales Orders
    AND c~kunnr IN ra_kunnr. "from selection screen
    DELETE ADJACENT DUPLICATES FROM gt_data COMPARING vbeln posnr.
    *get data of the production order
    IF NOT gt_data[] IS INITIAL.
    SELECT aaufnr aposnr akdauf akdpos awepos aelikz
    b~objnr
    FROM afpo AS a
    JOIN aufk AS b
    ON aaufnr = baufnr
    INTO TABLE gt_prd
    FOR ALL ENTRIES IN gt_data
    WHERE a~kdauf EQ gt_data-vbeln
    AND a~kdpos EQ gt_data-posnr.
    ENDIF.
    *Get partner data
    IF NOT gt_data[] IS INITIAL.
    SELECT vbeln posnr parvw kunnr
    FROM vbpa
    INTO TABLE gt_partner
    FOR ALL ENTRIES IN gt_data
    WHERE vbeln EQ gt_data-vbeln.
    ENDIF.
    *Get Purchase Order
    IF NOT gt_data[] IS INITIAL.
    SELECT ebeln ebelp vbeln vbelp
    FROM ekkn
    INTO TABLE gt_po
    FOR ALL ENTRIES IN gt_data
    WHERE vbeln EQ gt_data-vbeln
    AND vbelp EQ gt_data-posnr.
    SELECT vbeln posnr banfn
    FROM vbep
    INTO TABLE gt_preq
    FOR ALL ENTRIES IN gt_data
    WHERE vbeln EQ gt_data-vbeln
    AND posnr EQ gt_data-posnr.
    ENDIF.
    IF NOT gt_po[] IS INITIAL.
    SELECT aebeln aprocstat a~lifnr
    FROM ekko AS a
    JOIN ekpo AS b
    ON aebeln = bebeln
    INTO TABLE gt_po_stat
    FOR ALL ENTRIES IN gt_po
    WHERE b~ebeln EQ gt_po-ebeln
    AND b~ebelp EQ gt_po-ebelp.
    ENDIF.
    *Move data to output table
    LOOP AT gt_data INTO wa_data.
    wa_output-vbeln = wa_data-vbeln.
    wa_output-posnr = wa_data-posnr.
    wa_output-pstyv = wa_data-pstyv.
    wa_output-matnr = wa_data-matnr.
    READ TABLE gt_po INTO wa_po WITH KEY vbeln = wa_data-vbeln
    vbelp = wa_data-posnr.
    IF sy-subrc EQ 0.
    wa_output-bstnk = wa_po-ebeln.
    READ TABLE gt_po_stat INTO wa_po_stat WITH KEY ebeln = wa_po-ebeln.
    IF sy-subrc EQ 0.
    wa_output-lifnr = wa_po_stat-lifnr.
    CASE wa_po_stat-procstat.
    WHEN '01'.
    wa_output-po_st = 'Version in process'.
    WHEN '02'.
    wa_output-po_st = 'Active'.
    WHEN '03'.
    wa_output-po_st = 'In release'.
    WHEN '04'.
    wa_output-po_st = 'Partially released'.
    WHEN '05'.
    wa_output-po_st = 'Released Completely'.
    WHEN '08'.
    wa_output-po_st = 'Rejected'.
    ENDCASE.
    ENDIF. "inner read subrc
    ENDIF. "outer read subrc
    READ TABLE gt_preq INTO wa_preq WITH KEY vbeln = wa_data-vbeln
    posnr = wa_data-posnr.
    IF sy-subrc EQ 0.
    wa_output-banfn = wa_preq-banfn.
    ENDIF.
    READ TABLE gt_prd INTO wa_prd WITH KEY kdauf = wa_data-vbeln
    kdpos = wa_data-posnr.
    IF sy-subrc EQ 0.
    wa_output-aufnr = wa_prd-aufnr.
    *get the purchase requisition for production order as well
    SELECT SINGLE banfn
    FROM ebkn
    INTO wa_output-banfn
    WHERE aufnr EQ wa_prd-aufnr.
    *Get the status of the production order
    PERFORM fr_get_prd_stat USING wa_prd-objnr
    CHANGING wa_output-prd_stat.
    ENDIF. " sy-subrc
    READ TABLE gt_partner INTO wa_partner WITH KEY vbeln = wa_data-vbeln
    parvw = c_we.
    IF sy-subrc EQ 0.
    wa_output-sh = wa_partner-kunnr.
    ENDIF.
    READ TABLE gt_partner INTO wa_partner WITH KEY vbeln = wa_data-vbeln
    parvw = c_ag.
    IF sy-subrc EQ 0.
    wa_output-sp = wa_partner-kunnr.
    ENDIF.
    APPEND wa_output TO gt_output.
    CLEAR: wa_data, wa_prd,wa_partner,wa_output.
    ENDLOOP.
    ENDFORM. " fr_get_data
    *& Form fr_build_range
    text
    --> p1 text
    <-- p2 text
    FORM fr_build_range .
    *Range for partner function
    MOVE 'I' TO ra_parvw-sign.
    MOVE 'EQ' TO ra_parvw-option.
    MOVE 'SH' TO ra_parvw-low. " we
    APPEND ra_parvw.
    CLEAR ra_parvw.
    MOVE 'I' TO ra_parvw-sign.
    MOVE 'EQ' TO ra_parvw-option.
    MOVE 'SP' TO ra_parvw-low. " ag
    APPEND ra_parvw.
    CLEAR ra_parvw.
    *Range for ship-to and sold-to
    MOVE 'I' TO ra_kunnr-sign.
    MOVE 'EQ' TO ra_kunnr-option.
    MOVE p_kunnr TO ra_kunnr-low.
    APPEND ra_kunnr.
    CLEAR ra_kunnr.
    MOVE 'I' TO ra_kunnr-sign.
    MOVE 'EQ' TO ra_kunnr-option.
    MOVE p_kunwe TO ra_kunnr-low.
    APPEND ra_kunnr.
    CLEAR ra_kunnr.
    ENDFORM. " fr_build_range
    *& Form fr_build_fc
    text
    --> p1 text
    <-- p2 text
    FORM fr_build_fc .
    sales order number
    afield-fieldname = 'VBELN'.
    afield-seltext_s = 'Sales #'.
    afield-ref_tabname = 'VBAK'.
    APPEND afield TO xfield. CLEAR afield.
    sales ITEM number
    afield-fieldname = 'POSNR'.
    afield-seltext_s = 'Item #'.
    afield-ref_tabname = 'VBAP'.
    APPEND afield TO xfield. CLEAR afield.
    Material Number
    afield-fieldname = 'MATNR'.
    afield-seltext_s = 'Material #'.
    afield-ref_tabname = 'VBAP'.
    afield-outputlen = 10.
    APPEND afield TO xfield. CLEAR afield.
    *Vendor Number
    afield-fieldname = 'LIFNR'.
    afield-seltext_s = 'Vendor Num.'.
    afield-ref_tabname = 'EKKO'.
    APPEND afield TO xfield. CLEAR afield.
    ship-to-party
    afield-fieldname = 'SH'.
    afield-seltext_s = 'Ship-to'.
    afield-ref_tabname = 'VBPA'.
    APPEND afield TO xfield. CLEAR afield.
    sold-to-party
    afield-fieldname = 'SP'.
    afield-seltext_s = 'Sold-to'.
    afield-ref_tabname = 'VBPA'.
    APPEND afield TO xfield. CLEAR afield.
    *PO number
    afield-fieldname = 'BSTNK'.
    afield-seltext_s = 'PO NUM'.
    afield-ref_tabname = 'EKKO'.
    APPEND afield TO xfield. CLEAR afield.
    *PO status
    afield-fieldname = 'PO_STAT'.
    afield-seltext_s = 'Step'.
    afield-ref_tabname = 'zbacklog_v2'.
    APPEND afield TO xfield. CLEAR afield.
    *PO step status
    afield-fieldname = 'PO_ST'.
    afield-seltext_s = 'PO.Status'.
    afield-ref_tabname = 'zbacklog_v2'.
    APPEND afield TO xfield. CLEAR afield.
    *Purchase requisition
    afield-fieldname = 'BANFN'.
    afield-seltext_s = 'Pur. Req.'.
    afield-ref_tabname = 'VBEP'.
    APPEND afield TO xfield. CLEAR afield.
    *Item catagory
    afield-fieldname = 'PSTYV'.
    afield-seltext_s = 'Itm. Catg'.
    afield-ref_tabname = 'VBAP'.
    APPEND afield TO xfield. CLEAR afield.
    *Prodcution Order number
    afield-fieldname = 'AUFNR'.
    afield-seltext_m = 'Prod.Order'.
    afield-ref_tabname = 'AFKO'.
    APPEND afield TO xfield. CLEAR afield.
    *PRODCUTION status
    afield-fieldname = 'PRD_STAT'.
    afield-seltext_s = 'Prd. Step'.
    afield-ref_tabname = 'zbacklog_v2'.
    afield-outputlen = 20.
    APPEND afield TO xfield. CLEAR afield.
    *PRODUCTION step status
    afield-fieldname = 'PRD_ST'.
    afield-seltext_s = 'Prd. Status'.
    afield-ref_tabname = 'zbacklog_v2'.
    APPEND afield TO xfield. CLEAR afield.
    ENDFORM. " fr_build_fc
    *& Form fr_output
    text
    --> p1 text
    <-- p2 text
    FORM fr_output .
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
    i_callback_program = sy-repid
    I_CALLBACK_PF_STATUS_SET = ' '
    I_CALLBACK_USER_COMMAND = ' '
    I_STRUCTURE_NAME =
    IS_LAYOUT =
    it_fieldcat = xfield[]
    i_default = 'X'
    i_save = 'A'
    TABLES
    t_outtab = gt_output
    EXCEPTIONS
    program_error = 1
    OTHERS = 2.
    ENDFORM. " fr_output
    *& Form fr_get_prd_stat
    text
    -->P_WA_PRD_OBJNR text
    FORM fr_get_prd_stat USING p_objnr CHANGING p_prd_stat.
    DATA: lt_status TYPE STANDARD TABLE OF jstat,
    wa_status TYPE jstat,
    lv_status TYPE tj02t-txt04,
    lv_temp2 TYPE char5,
    lv_buff TYPE string.
    CALL FUNCTION 'STATUS_READ'
    EXPORTING
    client = sy-mandt
    objnr = p_objnr
    only_active = 'X'
    TABLES
    status = lt_status
    EXCEPTIONS
    object_not_found = 1
    OTHERS = 2.
    LOOP AT lt_status INTO wa_status.
    IF wa_status-stat(1) EQ 'I'.
    SELECT txt04 FROM tj02t
    INTO lv_status
    WHERE istat EQ wa_status-stat
    AND spras EQ 'E'.
    ENDSELECT.
    lv_temp2 = lv_status.
    CONCATENATE lv_temp2 p_prd_stat INTO p_prd_stat
    SEPARATED BY ','.
    ENDIF.
    CLEAR: wa_status, lv_status, lv_temp2.
    ENDLOOP.
    lv_buff = p_prd_stat.
    *Status of Production Order
    IF lv_buff CS 'CRTD'.
    p_prd_stat = 'Not Active'.
    ENDIF.
    IF lv_buff CS 'REL'.
    IF lv_buff CS 'GMPS'.
    p_prd_stat = 'Printed In Prod'.
    ELSE.
    p_prd_stat = 'Printed'.
    ENDIF.
    ENDIF.
    IF lv_buff CS 'TECO'.
    p_prd_stat = 'Technically Compt.'.
    ENDIF.
    ENDFORM. " fr_get_prd_stat
    >

  • Allignment in ALV top of page using oops

    I am displaying some fields with their values on top of page using Classes.but i am not able to get a proper alignment.
    i want the field and their respective values one-below the other with once the field description and the values below after the description. eg...
      field : 0125465
               0123654
               23654100
    sales : au01
               sd02
               GH26
    org    : 101
               102
               103

    Check this sample..
    Take the code from the HTML_TOP_OF_PAGE from the below report.
    REPORT  ztest_page.
    DATA : it_flight TYPE TABLE OF sflight WITH HEADER LINE.
    data: t type x.
    START-OF-SELECTION.
      SELECT * FROM sflight INTO TABLE it_flight.
    END-OF-SELECTION.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program          = sy-repid
          i_callback_html_top_of_page = 'HTML_TOP_OF_PAGE'
          i_callback_top_of_page      = 'TOP_OF_PAGE'
          i_structure_name            = 'SFLIGHT'
        TABLES
          t_outtab                    = it_flight
        EXCEPTIONS
          program_error               = 1
          OTHERS                      = 2.
    *&      Form  TOP_OF_PAGE
    *       text
    FORM top_of_page.
      WRITE 'This is the Top of page which triggers in print'.
    ENDFORM.                    "TOP_OF_PAGE
    *&      Form  html_top_of_page
    FORM html_top_of_page USING document TYPE REF TO cl_dd_document.
      DATA : dl_text(255) TYPE c.  "Text
    * Add new-line
      CALL METHOD document->new_line.
      CALL METHOD document->new_line.
      CLEAR : dl_text.
    * program ID
      dl_text = 'Program Name :'.
      CALL METHOD document->add_gap.
      CALL METHOD document->add_text
        EXPORTING
          text         = dl_text
          sap_emphasis = cl_dd_area=>heading
          sap_color    = cl_dd_area=>list_heading_int.
      CLEAR dl_text.
      dl_text = sy-repid.
      CALL METHOD document->add_text
        EXPORTING
          text         = dl_text
          sap_emphasis = cl_dd_area=>heading
          sap_color    = cl_dd_area=>list_negative_inv.
    * Add new-line
      CALL METHOD document->new_line.
      CLEAR : dl_text.
      dl_text = sy-uname.
      CALL METHOD document->add_gap
        EXPORTING
          width = 34.
      CALL METHOD document->add_text
        EXPORTING
          text         = dl_text
          sap_emphasis = cl_dd_area=>heading
          sap_color    = cl_dd_area=>list_negative_inv.
    * Add new-line
      CALL METHOD document->new_line.
      CLEAR : dl_text.
      CALL METHOD document->add_gap
        EXPORTING
          width = 34.
    * Move date
      WRITE sy-datum TO dl_text.
      CALL METHOD document->add_text
        EXPORTING
          text         = dl_text
          sap_emphasis = cl_dd_area=>heading
          sap_color    = cl_dd_area=>list_negative_inv.
    * Add new-line
      CALL METHOD document->new_line.
      CLEAR : dl_text.
    * Move time
      WRITE sy-uzeit TO dl_text.
      CALL METHOD document->add_gap
        EXPORTING
          width = 34.
      CALL METHOD document->add_text
        EXPORTING
          text         = dl_text
          sap_emphasis = cl_dd_area=>heading
          sap_color    = cl_dd_area=>list_negative_inv.
    * Add new-line
      CALL METHOD document->new_line.
    ENDFORM.                    "HTML_TOP_OF_PAGE
    same Code can be used in the class. you take the above code and see..

  • Can we use multiple queries on one template

    Can we use multiple queries on one template

    Hi,
    if you're using data templates for your data set, you
    can put multiple queries in the XML data template.
    The queries may then be linked (or not) by the "link
    name" tag ...
    Grtz.Following you answer here...do you know eventually how/if possible to preview a report (with XMLP Desktop) that is using data templates for the data set?
    Thanks,
    Liviu

  • Assertion failure error while using hierarchy column in 11.1.1.7.1

    Hi all,
    I have done In-place upgrade of OBIEE from 11.1.1.5 to 11.1.1.7. Afterthat installed 11.1.1.7.1 patchset also.
    Dashboard prompts were created by using hierarchy column. While applying hierarchy prompt i am getting below error
    Assertion failure: levels.size() > start_pos at line 843 of project/weblayoutbuilder/viewlayoutbuilderutil.cpp
      Error Details
    Error Codes: ACIOA5LN
    Some times presentation services will restarted automatically.
    Kindly give a solution regarding this.
    Thanks in advance

    This is occuring due to Bug 17334677 in 11.1.1.7.0. It has been fixed in future versions and backported to SOA BPM 11.1.1.7.0 Apply Patch 17334677

  • Use hierarchy in report

    hi guys,
    I want to make a financial report using hierarchy from R/3.
    but there are some missing node from R/3 and I want to add it in BW
    Exp :
    Hierarchy at my R/3 is like this :
    revenue
    cogs
    operating expenses
    etc...
    where I want to have report like this :
    revenue
    cogs
    --gross profit ( revenue - cogs )
    operating expenses
    etc...
    please advice on how to add --gross profit in my BW report
    regards,
    -dedys

    Hi,
    If you want to use hierarcy and hierarchy properties in your query it is impossible to add these kind of calculations in hierarchy.
    But if this hierarcy is just for classification and your nodes are fixed, then you can create restricted key figures for each node coming from hierarchy and you can create formulas with using this key restricted keyfigures.
    Creating Restricted Key Figures:
    1. In the InfoProvider screen area, select the Key Figures entry and choose New Restricted Key Figure from the context menu (secondary mouse button).
    If a restricted key figure has already been defined for this InfoProvider, you can also select the Restricted Key Figures entry and then choose New Restricted Key Figure from the context menu.
    The entry New Restricted Key Figure is inserted and the properties for the restricted key figure are displayed in the Properties screen area.
    2. Select the New Restricted Key Figure entry and choose Edit from the context menu (secondary mouse button).
    The Change Restricted Key Figure dialog box appears.
    You can also call the Change Restricted Key Figure dialog box from the Properties screen area by choosing the Edit pushbutton.
    You make the basic settings on the General tab page.
    Underneath the text field, to the left of the Detail View area, the directory of all objects available in the InfoProvider is displayed. The empty field for defining the restricted key figure (Details of the Selection) is on the right-hand side of the screen.
    3. Using drag and drop, choose a key figure from the InfoProvider and restrict it by selecting one or more characteristic values. YOU WILL SELECT YOUR HIERARCHY FOR YOUR CHARACTERISTIC HERE
    4. Make any necessary settings for the properties of the restricted key figure on the other tab pages.
    5. Choose OK. The new restricted key figure is defined for the InfoProvider.
    Creating Calculated Key Figures:
    http://help.sap.com/saphelp_nw04/helpdata/EN/13/e072abaddb574284d22361f0b824bf/content.htm
    This is a way to include calculations and hierarchy nodes coming from R/3 together.
    Hope this helps...

Maybe you are looking for

  • Advice needed: decent field recording mic...

    Hi Been trying to record some beautiful natural sounds with a "good for it's price" small mini-disc stereo mic. unfortunately sounds too tinny and it just is far too sensitive to wind (yes, i've tried simulating a nice wind shield - even used my sock

  • Treeview, keep focus on clicked node ?

    First post here, hope I am in the right location. I am using Visual Studio Express 2103 for web. On my asp page I have a Treeview with 4 Levels. From sql server I load the hierarchy as TopLevel-->                   Product-->                         

  • Premire Pro CS6 crashes every time I multitask away from it

    Just like the topic says, every time I swtich to another application besides Premire Pro CS6, the application freezes/crashes. I get the following error message: Adobe Premire Pro CS6 has stopped working. A problem caused the program to stop working

  • Error when trying to unarchive a program

    Hey everyone, I have another question and I hope somebody can solve my problem. I downloaded Propellerhead's Reason 3.0 from an unnamed p2p site and I am trying to install it and when I click on it to open it I get a message saying "Unable to unarchi

  • TV@nywhere Master

    During startup static starts coming from TV@nywhere Master sounding like radio off station). After Win2k has finished loading, I can start either MSI Radio or MSIPVS and it will stop. The radio will also come on sounding normal (on previous station)