Hi need help in abap query

hello friends,
i am doing abap query,
i created the
user group in sq03
infoset in sq02
query in sq01
it looks ok,
but it is picking all the items from the table1,
i want it to pick only those data which satisfy one specific condition,
like
vkorg = 'A123' or 'B456'.
audat = anything after feb 04.
likie that.
can some one help.

Check with below Link :
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/40bec8da-4cd8-2910-27a9-81f5ce10676c
Pls go through the below link.
http://www.sappoint.com/abap/ab4query.pdf
Thanks
Seshu

Similar Messages

  • Need help with SQL Query with Inline View + Group by

    Hello Gurus,
    I would really appreciate your time and effort regarding this query. I have the following data set.
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*20.00*-------------19
    1234567----------11223--------------7/5/2008-----------Adjustment for bad quality---------44345563------------------A-----------------10.00------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765--------------------I---------------------30.00-------------19
    Please Ignore '----', added it for clarity
    I am trying to write a query to aggregate paid_amount based on Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number and display description with Invoice_type 'I' when there are multiple records with the same Reference_No, Check_Number, Payment_Date, Invoice_Number, Invoice_Type, Vendor_Number. When there are no multiple records I want to display the respective Description.
    The query should return the following data set
    Reference_No---Check_Number---Check_Date--------Description-------------------------------Invoice_Number----------Invoice_Type---Paid_Amount-----Vendor_Number
    1234567----------11223-------------- 7/5/2008----------paid for cleaning----------------------44345563------------------I-----------------*10.00*------------19
    7654321----------11223--------------7/5/2008-----------Adjustment from last billing cycle-----23543556-------------------A--------------------50.00--------------19
    4653456----------11223--------------7/5/2008-----------paid for cleaning------------------------35654765-------------------I---------------------30.00--------------19
    The following is my query. I am kind of lost.
    select B.Description, A.sequence_id,A.check_date, A.check_number, A.invoice_number, A.amount, A.vendor_number
    from (
    select sequence_id,check_date, check_number, invoice_number, sum(paid_amount) amount, vendor_number
    from INVOICE
    group by sequence_id,check_date, check_number, invoice_number, vendor_number
    ) A, INVOICE B
    where A.sequence_id = B.sequence_id
    Thanks,
    Nick

    It looks like it is a duplicate thread - correct me if i'm wrong in this case ->
    Need help with SQL Query with Inline View + Group by
    Regards.
    Satyaki De.

  • Need Help on below Query.

    Hi All,
    Need Help on below Query.
    Consider,
    "test9" Table Data in COLUMN "Name" AS
    Name
    =====
    'a'
    'b'
    'c'
    'd'
    'e'
    I am writing a query as :
    SELECT * FROM test9 WHERE Name IN ('a','b','c','d','e','f','g')
    I want result set as , It should show data as -
    'f'
    'g'
    i.e. data which does not exists in the table and which is give in in clause
    Is it possible in a single query.

    You can put the data that is to be checked for into a table instead or an inline view, for example:
    with t as
    (select 'a' as c1 from dual
    union all
    select 'b' from dual
    union all
    select 'c' from dual
    union all
    select 'd' from dual
    union all
    select 'e' from dual)
    select c1 from (select 'a' as c1 from dual
    union all
    select 'b' from dual
    union all
    select 'c' from dual
    union all
    select 'd' from dual
    union all
    select 'e' from dual
    union all
    select 'f' from dual
    union all
    select 'g' from dual)
    minus
    select c1 from t
    C
    f
    g
    2 rows selected.

  • Please, need help with a query

    Hi !
    Please need help with this query:
    Needs to show (in cases of more than 1 loan offer) the latest create_date one time.
    Meaning, In cases the USER_ID, LOAN_ID, CREATE_DATE are the same need to show only the latest, Thanks!!!
    select distinct a.id,
    create_date,
    a.loanid,
    a.rate,
    a.pays,
    a.gracetime,
    a.emailtosend,
    d.first_name,
    d.last_name,
    a.user_id
    from CLAL_LOANCALC_DET a,
    loan_Calculator b,
    bv_user_profile c,
    bv_mr_user_profile d
    where b.loanid = a.loanid
    and c.NET_USER_NO = a.resp_id
    and d.user_id = c.user_id
    and a.is_partner is null
    and a.create_date between
    TO_DATE('6/3/2008 01:00:00', 'DD/MM/YY HH24:MI:SS') and
    TO_DATE('27/3/2008 23:59:00', 'DD/MM/YY HH24:MI:SS')
    order by a.create_date

    Take a look on the syntax :
    max(...) keep (dense_rank last order by ...)
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions056.htm#i1000901
    Nicolas.

  • Please need help with this query

    Hi !
    Please need help with this query:
    Needs to show (in cases of more than 1 loan offer) the latest create_date one time.
    Meaning, In cases the USER_ID, LOAN_ID, CREATE_DATE are the same need to show only the latest, Thanks!!!
    select distinct a.id,
    create_date,
    a.loanid,
    a.rate,
    a.pays,
    a.gracetime,
    a.emailtosend,
    d.first_name,
    d.last_name,
    a.user_id
    from CLAL_LOANCALC_DET a,
    loan_Calculator b,
    bv_user_profile c,
    bv_mr_user_profile d
    where b.loanid = a.loanid
    and c.NET_USER_NO = a.resp_id
    and d.user_id = c.user_id
    and a.is_partner is null
    and a.create_date between
    TO_DATE('6/3/2008 01:00:00', 'DD/MM/YY HH24:MI:SS') and
    TO_DATE('27/3/2008 23:59:00', 'DD/MM/YY HH24:MI:SS')
    order by a.create_date

    Perhaps something like this...
    select id, create_date, loanid, rate, pays, gracetime, emailtosend, first_name, last_name, user_id
    from (
          select distinct a.id,
                          create_date,
                          a.loanid,
                          a.rate,
                          a.pays,
                          a.gracetime,
                          a.emailtosend,
                          d.first_name,
                          d.last_name,
                          a.user_id,
                          max(create_date) over (partition by a.user_id, a.loadid) as max_create_date
          from CLAL_LOANCALC_DET a,
               loan_Calculator b,
               bv_user_profile c,
               bv_mr_user_profile d
          where b.loanid = a.loanid
          and   c.NET_USER_NO = a.resp_id
          and   d.user_id = c.user_id
          and   a.is_partner is null
          and   a.create_date between
                TO_DATE('6/3/2008 01:00:00', 'DD/MM/YY HH24:MI:SS') and
                TO_DATE('27/3/2008 23:59:00', 'DD/MM/YY HH24:MI:SS')
    where create_date = max_create_date
    order by create_date

  • Need help defining a query

    Hi everyone...
    I need help with this query. The table 'cobros' has a primary key defined by id_cliente + id_cobro. I pretend to classify rows by COUNT(id_cobro) which are between a date range.
    A client could have 1 or 2 or 3 rows per day, no more for a specific date. I would like to get first, all clients with COUNT(id_cobro) = 1, all clients with COUNT(id_cobro) = 2, and finally all clients with COUNT(id_cobro) = 3.
    Something similar to:
    1 SELECT id_cliente, COUNT(id_cobro) FROM cobros
    2 WHERE fecha_proximo_cobro >= '2011-05-30 00:00'
    3 AND fecha_proximo_cobro <= '2011-05-30 23:59'
    4 AND COUNT(id_cobro) = 1
    5 GROUP BY id_cliente
    The fourth line is the problem. It doesn't work.
    Thanks in advance!!!
    Mario

    Maybe you are looking for something like this?
    SELECT id_cliente
         , COUNT(*)   AS cnt
    FROM   cobros
    WHERE  fecha_promixo_cobro BETWEEN TO_DATE('2011-05-30 00:00','YYYY-MM-DD HH24:MI') AND TO_DATE('2011-05-30 23:59','YYYY-MM-DD HH24:MI')
    GROUP BY id_cliente
    ORDER BY 2
           , 1Also, NEVER rely on implicit data type conversion as you have (you provide a STRING not a DATE).
    Edited by: Centinul on Jun 2, 2011 12:36 PM
    Fixed syntax error.

  • Need help with conditional query

    guys this is just an extension of this post that Frank was helping me with. im reposting because my requirements have changes slightly and im having a hell of a time trying to modify the query.
    here is the previous post.
    need help with query that can look data back please help.
    CREATE TABLE "FGL"
        "FGL_GRNT_CODE" VARCHAR2(60),
        "FGL_FUND_CODE" VARCHAR2(60),
        "FGL_ACCT_CODE" VARCHAR2(60),
        "FGL_ORGN_CODE" VARCHAR2(60),
        "FGL_PROG_CODE" VARCHAR2(60),
        "FGL_GRNT_YEAR" VARCHAR2(60),
        "FGL_PERIOD"    VARCHAR2(60),
        "FGL_BUDGET"    VARCHAR2(60)
      )data
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','00','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','1','0');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','11','1','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('360055','360055','7200','4730','02','10','1','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('360055','360055','7600','4730','02','10','1','400');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7600','4730','02','10','14','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','14','200');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','10','2','100');
    Insert into FGL (FGL_GRNT_CODE,FGL_FUND_CODE,FGL_ACCT_CODE,FGL_ORGN_CODE,FGL_PROG_CODE,FGL_GRNT_YEAR,FGL_PERIOD,FGL_BUDGET) values ('240055','240055','7240','4730','02','11','2','600');
    I need to find the greatest grant year for the grant by a period parameter.
    once i find the greatest year i need to check the value of period 14 for that grant for the previous year and add it to the budget amount for that grant. however if their is an entry in the greatest year for period 00 then i need to ignore the period 14 of previous year and do this calculation current period +(current period - greatest year 00)
    hope that makes sense so in other words with the new data above. if i was querying period two of grant year 11. i would end up with $800
    because the greatest year is 11 it contains a period 0 with amount of $400 so my total should be
    period 2 amount $ 600
    period 0 amount $ 400 - period 2 amount of $600 = 200
    600+200 = $800
    if i query period 1 of grant 360055 i would just end up with 800 of grnt year 10.
    i have tried to modify that query you supplied to me with no luck. I have tried for several day but im embarrased to say i just can get it to do what im trying to do .
    can you please help me out.
    here is the query supplied by frank kulash who gracefully put this together for me.
    WITH     got_greatest_year     AS
         SELECT     fgl.*     -- or whatever columns are needed
         ,     MAX ( CASE
                     WHEN  fgl_period = :given_period
                     THEN  fgl_grnt_year
                    END
                  ) OVER ()     AS greatest_year
         FROM     fgl
    SELECT     SUM (fgl_budget)     AS total_budget     -- or SELECT *
    FROM     got_greatest_year
    WHERE     (     fgl_grnt_year     = greatest_year
         AND     fgl_period     = :given_period
    OR     (     fgl_grnt_year     = greatest_year - 1
         AND     fgl_period     = 14
    ;Miguel

    Hi, Miguel,
    Are you waying that, when the greatest year that has :given_period also has period='00' (or '0', or whatever you want to use), then you want to double the budget from the given_period (as well as subtract the budget from the '00', and not count the pevious year's '14')? If so, add another condition to the CASE statement which decides what you're SUMming:
    WITH     got_greatest_year     AS
         SELECT       TO_NUMBER (fgl_grnt_year)     AS grnt_year
         ,       fgl_period
         ,       TO_NUMBER (fgl_budget)     AS budget
         ,       MAX ( CASE
                       WHEN  fgl_period = :given_period
                       THEN  TO_NUMBER (fgl_grnt_year)
                      END
                    ) OVER ()     AS greatest_year
         FROM       fgl
    ,     got_cnt_00     AS
         SELECT     grnt_year
         ,     fgl_period
         ,     budget
         ,     greatest_year
         ,     COUNT ( CASE
                       WHEN  grnt_year     = greatest_year
                       AND       fgl_period     = '00'
                       THEN  1
                         END
                    ) OVER ()          AS cnt_00
         FROM    got_greatest_year
    SELECT       SUM ( CASE
                        WHEN  grnt_year     = greatest_year                    -- New
                  AND       fgl_period     = :given_period                    -- New
                  AND       cnt_00     > 0            THEN  budget * 2     -- New
                        WHEN  grnt_year     = greatest_year
                  AND       fgl_period     = :given_period       THEN  budget
                        WHEN  grnt_year     = greatest_year
                  AND       fgl_period     = '00'            THEN -budget
                        WHEN  grnt_year     = greatest_year - 1
                  AND       fgl_period     = '14'     
                  AND       cnt_00     = 0            THEN  budget
                    END
               )          AS total_budget
    FROM       got_cnt_00
    ;You'll notice this is the same as the previous query I posted, except for 3 lines maked "New".

  • Need help in ABAP.

    HI gurus,
    I AM KISHORE i am SD consultant.here my client is asking to create some programmes. i need help in simple programmes so that as per that i can change the fiels as per my requirement.
          i am in real big problem now .i know these are very simple programmes but i don't know ABC of programming.
    can some one help me in this regard.  this ABAP help is needed for me only for some time.
    the requirement:  
    create program which will produce list with:
       Materia number; Material description ; Valuation class, Standard price with curency and unit.
    Select conditions:
       Material number,
       Plant,
       Material type                                as mandatory
       Material Group                              as mandatory,
       LP/KD/MIP  (LABOR)                    as mandatory,
       Replenishment strategy (TEMPB)   as mandatory,
       Valuation class,
       Flag for deletion-Client Level  with initial value <> ‘X’  (only materials without flag for deletion)
    Simple List is enough
    reagrds
    kishore

    Hi
    Eventhough i cant fullfill your complete requirement. I'm giving u a report performed by me in which most of the fields are covered ask any of abaper to make modifications in this report and change it to accordingly ur requirement. I think it will solve 80% of ur work
    * tables
    TABLES: ekko,ekbe,ekpo,ekkn,konh,konv,esll,ekbz,rseg,lfa1,j_1ipart1,
    j_1igrxref.
    TYPE-POOLS: slis.
    *data definituon
    DATA:
          wa_ekko LIKE ekko,
          wa_ekbe LIKE ekbe,
          wa_ekkn LIKE ekkn,
          wa_konp LIKE konp,
          wa_ekpo LIKE ekpo,
          wa_rbkp LIKE rbkp,
          wa_j_1ipart1 LIKE j_1ipart1,
          wa_j_1igrxref LIKE j_1igrxref,
          wa_rseg LIKE rseg OCCURS 0 WITH HEADER LINE.
    DATA: ws_vakey LIKE konh-vakey,
          ws_kbetr LIKE konp-kbetr,
          ws_kbetr1 LIKE konp-kbetr,
          ws_kbetr2 LIKE konp-kbetr,
          ws_ecs LIKE j_1igrxref-ecs,
          ws_ebelp LIKE ekbz-ebelp,
          ws_ebeln LIKE ekko-ebeln,
          ws_belnr LIKE ekbe-belnr,
          ws_beznk LIKE  rbkp-beznk,
          ws_wrbtr_f LIKE ekbz-wrbtr,
          ws_rmwwr LIKE rbkp-rmwwr,
          ws_rbkp_benz.
    *internal tables
    DATA: BEGIN OF int_outtab OCCURS 0,
          lifnr      LIKE ekko-lifnr,               " vend no
          name1      LIKE lfa1-name1,               " vend name
          werks      LIKE ekpo-werks,               "  plant
          ebeln      LIKE ekko-ebeln,               " po no
          knumv      LIKE ekko-knumv,
          ebelp      LIKE ekbe-ebelp,
          matnr      LIKE ekpo-matnr,               " mat no
          txz01      LIKE ekpo-txz01,               " mat desceiption
          kostl      LIKE ekkn-kostl,               " cost center
          ps_psp_pnr LIKE ekkn-ps_psp_pnr,          " WBS element
          netwr      LIKE ekpo-netwr,
          " basic value           (po)
          kbetr      LIKE konp-kbetr,
          " excise value          (po)
          kwert_i    LIKE konv-kwert,
          " insurance value       (po)
          kwert_f    LIKE konv-kwert,
          " frieght value         (po)
          kwert_t    LIKE konv-kwert,
          " vat/tax value         (po)
          kwert_o    LIKE konv-kwert,
          " others                (po)
          kwert_total LIKE konv-kwert,
          " total                 (po)
          ecs        LIKE j_1igrxref-ecs,
          " excise                (ap)
          wmwst1     LIKE   rbkp-wmwst1,
          " tax amount            (ap)
          wrbtr_f       TYPE ekbz-wrbtr,
          " freight               (ap)
          wrbtr       TYPE ekbz-wrbtr,
          beznk      LIKE    rbkp-beznk,
          " Unplanned cost        (ap)
          refwr_g    TYPE  ekbe-refwr,
          " gross                 (ap)
          rmwwr   LIKE  rbkp-rmwwr,
          "  Actual Invoice Total (ap)
          buzei      LIKE ekbz-buzei,               "item for material doc
          gjahr      LIKE ekbe-gjahr,
          tax        LIKE ekbe-wrbtr,                " tax (ap)
          actual_total LIKE ekbe-wrbtr,
    *      belnr      LIKE rseg-belnr,
           belnr     LIKE ekbe-belnr,
          vakey      LIKE konh-vakey,
          cpudt      LIKE ekbe-cpudt,
          budat      LIKE ekbz-budat,
          belnr_ekbz LIKE ekbz-belnr,              "to get excise value
    *      aedat     LIKE ekpo-aedat,
          bedat   LIKE ekko-bedat,
          waers     LIKE lfm1-waers,               " currency
          END OF int_outtab.
    DATA:   int_konv LIKE konv OCCURS 0 WITH HEADER LINE,
    *        int_ekbe LIKE ekbe OCCURS 0 WITH HEADER LINE,
            int_ekbz LIKE ekbz OCCURS 0 WITH HEADER LINE.
    DATA: BEGIN OF int_konh OCCURS 0,
          knumh LIKE konh-knumh,
          kschl LIKE konh-kschl,
          vakey LIKE konh-vakey,
          END OF int_konh.
    DATA: BEGIN OF int_konp OCCURS 0,
          knumh LIKE konp-knumh,
          kschl LIKE konp-kschl,
          kbetr LIKE konp-kbetr,
          END OF int_konp.
    DATA: BEGIN OF int_ekkn OCCURS 0,
          ebeln      LIKE ekkn-ebeln,
          ebelp      LIKE ekkn-ebelp,
          kostl      LIKE ekkn-kostl,
          ps_psp_pnr LIKE ekkn-ps_psp_pnr,
          END OF int_ekkn.
    DATA: BEGIN OF int_outtab1 OCCURS 0,
          exbed      LIKE j_1igrxref-exbed,
          ecs        LIKE j_1igrxref-ecs,
          END OF int_outtab1.
    DATA: BEGIN OF int_ekbe OCCURS 0,
          ebelp LIKE ekbe-ebelp,
          refwr LIKE ekbe-refwr,
          wrbtr LIKE ekbe-wrbtr,
          shkzg LIKE ekbe-shkzg,
          END OF int_ekbe.
    DATA: BEGIN OF int_total OCCURS 0,
          ebeln LIKE ekko-ebeln,
          ebelp LIKE ekbe-ebelp,
          actual_total LIKE ekbe-wrbtr,
          END OF int_total.
    DATA: BEGIN OF int_excise OCCURS 0,
          ebeln      LIKE ekko-ebeln,
          kbetr      LIKE konp-kbetr,
          END OF int_excise.
    DATA: BEGIN OF int_rseg OCCURS 0,
          ebeln LIKE rseg-ebeln,
          ebelp LIKE rseg-ebelp,
          lfbnr LIKE rseg-lfbnr,
          matnr LIKE rseg-matnr,
          lfgja LIKE rseg-lfgja,
          belnr LIKE rseg-belnr,
          ecs LIKE j_1igrxref-ecs,
          beznk      LIKE    rbkp-beznk,
          wrbtr_f    LIKE  ekbz-wrbtr,
          rmwwr LIKE rbkp-rmwwr,
          END OF int_rseg.
    DATA: BEGIN OF int_rbkp OCCURS 0,
          belnr LIKE  rbkp-belnr,
          beznk      LIKE    rbkp-beznk,
          rmwwr      LIKE    rbkp-rmwwr,
          tcode  LIKE rbkp-tcode,
          END OF int_rbkp.
    ****ALV list definintion
    DATA: ws_cat TYPE slis_t_fieldcat_alv ,
          int_cat TYPE slis_t_fieldcat_alv WITH HEADER LINE.
    DATA: g_container TYPE scrfname VALUE 'BCALV_GRID_DEMO_0100_CONT1',
          g_custom_container TYPE REF TO cl_gui_custom_container.
    *selection-screen
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
    SELECTION-SCREEN SKIP 2.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 19(23) text-002.
    SELECT-OPTIONS: s_lifnr FOR ekko-lifnr obligatory.
    *PARAMETERS:p_lifnr LIKE ekko-lifnr  .
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 25(17) text-006.
    *PARAMETERS:p_ebeln LIKE ekko-ebeln obligatory.
    SELECT-OPTIONS:s_ebeln FOR ekko-ebeln .
    SELECTION-SCREEN END OF LINE.
    *SELECTION-SCREEN BEGIN OF LINE.
    *SELECTION-SCREEN COMMENT 25(23) text-003.
    *PARAMETERS:p_ekorg LIKE ekko-ekorg.
    *SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    *SELECTION-SCREEN COMMENT 25(20) text-004.
    *PARAMETERS:p_werks LIKE ekpo-werks obligatory.
    *SELECT-OPTIONS: S_werks FOR ekpo-werks obligatory.
    SELECTION-SCREEN END OF LINE.
    *SELECTION-SCREEN BEGIN OF LINE.
    *SELECTION-SCREEN COMMENT 25(23) text-005.
    *SELECT-OPTIONS:s_bedat FOR ekko-bedat.
    *SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN END OF BLOCK b1.
    START-OF-SELECTION.
      PERFORM get_data.
      PERFORM field_catalog.
      PERFORM display_data.
    END-OF-SELECTION.
    *&      Form  get_data
    *       text
    FORM get_data.
    * start of Vender details
    ***vender no, vender name, po no,service/mat no, service/mat description
      SELECT  ekko~lifnr ekko~ebeln ekko~knumv ekko~bedat
              ekpo~werks ekpo~matnr ekpo~txz01 ekpo~werks
              ekpo~netwr
    *          ekpo~aedat
              ekbe~ebelp  ekbe~belnr
              lfa1~name1
      INTO    CORRESPONDING   FIELDS OF  TABLE int_outtab
      FROM ( ( ( ekko
               JOIN ekbe ON  ekbe~ebeln = ekko~ebeln AND
                             ekbe~vgabe = '2'       )
               JOIN ekpo ON ekpo~ebeln = ekko~ebeln   AND
                            ekpo~ebelp = ekbe~ebelp )
               JOIN lfa1 ON lfa1~lifnr = ekko~lifnr )
      WHERE
    *  ekko~lifnr  =  P_lifnr  AND
    *         ekko~ebeln IN  S_ebeln  AND
    **         ekpo~werks IN  S_werks AND
             ekbe~vgabe = '2'.
    ***WBS/Cost center
      SELECT  ebeln ebelp kostl ps_psp_pnr  FROM ekkn INTO int_ekkn
      FOR ALL ENTRIES IN int_outtab
      WHERE ebeln = int_outtab-ebeln AND
            ebelp = int_outtab-ebelp.
        APPEND int_ekkn.
      ENDSELECT.
      LOOP AT int_outtab.
        ON CHANGE OF int_outtab-ebeln OR int_outtab-ebelp.
          LOOP AT int_ekkn WHERE ebeln = int_outtab-ebeln AND
                                 ebelp = int_outtab-ebelp.
            IF  int_ekkn-kostl <> ' '.
              MOVE int_ekkn-kostl TO int_outtab-kostl.
            ELSE.
              MOVE int_ekkn-ps_psp_pnr TO int_outtab-kostl.
              " int_outtab-ps_psp_pnr.
            ENDIF.
          ENDLOOP.
          MODIFY int_outtab.
        ENDON.
      ENDLOOP.
    *end of Vender details*****
    *******Start of calculation of PO
    *****Excise calculation of po
      LOOP AT int_outtab.
        CONCATENATE int_outtab-werks int_outtab-lifnr int_outtab-matnr INTO
        ws_vakey.
        MOVE ws_vakey TO int_outtab-vakey.
        MODIFY int_outtab.
      ENDLOOP.
      LOOP AT int_outtab.
    *    ON CHANGE OF int_outtab-ebeln OR int_outtab-vakey.
        ON CHANGE OF int_outtab-ebelp.
          SELECT knumh kschl vakey FROM konh INTO int_konh
    *        FOR ALL ENTRIES IN int_outtab
            WHERE vakey = int_outtab-vakey AND
                  datab <= int_outtab-bedat AND
                  datbi > int_outtab-bedat AND
                 ( kschl = 'JMOP' OR kschl = 'JEC1' ).
            SELECT knumh kschl kbetr FROM konp INTO int_konp
            WHERE  knumh = int_konh-knumh .
              IF  int_konp-kschl = 'JMOP'.
                ws_kbetr = int_konp-kbetr / 1000 * int_outtab-netwr.
                ws_kbetr1 = ws_kbetr.
              ENDIF.
              IF int_konp-kschl = 'JEC1'.
                ws_kbetr2 = int_konp-kbetr / 1000 * ws_kbetr1.
              ENDIF.
              ws_kbetr = ws_kbetr + ws_kbetr2.
            ENDSELECT.
          ENDSELECT.
        ENDON.
    *    ENDON.
        MOVE ws_kbetr TO int_outtab-kbetr.
        MODIFY int_outtab.
        CLEAR: ws_kbetr, ws_kbetr1, ws_kbetr2.
      ENDLOOP.
      LOOP AT int_outtab.
    *    ON CHANGE OF int_outtab-ebeln OR int_outtab-vakey.
        int_excise-kbetr =  int_outtab-kbetr.
        int_excise-ebeln =  int_outtab-ebeln.
        APPEND int_excise.
    *    ENDON.
      ENDLOOP.
      LOOP AT int_outtab.
        ON CHANGE OF int_outtab-ebeln.
          LOOP AT int_excise WHERE ebeln = int_outtab-ebeln.
            ws_kbetr = ws_kbetr + int_excise-kbetr.
          ENDLOOP.
        ENDON.
        int_outtab-kbetr = ws_kbetr.
        MODIFY int_outtab.
        CLEAR ws_kbetr.
      ENDLOOP.
    ***** Insurance, Freight,Vat/ST, Other, Total***********
      LOOP AT int_outtab.
        ON CHANGE OF int_outtab-ebelp OR int_outtab-ebeln.
          CLEAR int_konv.
          SELECT * FROM konv INTO CORRESPONDING FIELDS OF int_konv
          WHERE knumv = int_outtab-knumv AND
                kposn = int_outtab-ebelp AND
              ( ( kschl <> 'RA00' )
                 AND ( kschl <> 'RA01' ) AND ( kschl <>  'RB00' )
                 AND ( kschl <> 'PBXX' ) AND ( kschl <>  'PB00' )
                 AND ( kschl <> 'RC00' ) AND ( kschl <>  'RL01' )
                 AND ( kschl <> 'ZC00' ) AND ( kschl <>  'ZA00' )
                 AND ( kschl <> 'ZA01' ) AND ( kschl <>  'HB01' )
                 AND ( kschl <> 'ZBED' ) AND ( kschl <>  'ZAED' )
                 AND ( kschl <> 'ZSED' ) AND ( kschl <>  'ZAE1' )
                 AND ( kschl <> 'ZSE1' ) AND ( kschl <>  'ZCEX' )
                 AND ( kschl <> 'ZPRO' ) AND ( kschl <>  'ZTRD' )
                 AND ( kschl <> 'ZPK4' ) AND ( kschl <>  'ZSTX' )
                 AND ( kschl <> 'ZASS' ) AND ( kschl <>  'ZJCD' )
                 AND ( kschl <>  'HB00') ).
            APPEND int_konv.
          ENDSELECT.
        ENDON.
      ENDLOOP.
      LOOP AT int_outtab.
        ON CHANGE OF int_outtab-ebelp OR int_outtab-knumv.
          LOOP AT int_konv WHERE kposn = int_outtab-ebelp AND
                                 knumv = int_outtab-knumv.
    *                             lifnr = int_outtab-lifnr.
    ***** tax
            IF  ( ( int_konv-kschl = 'NAVS' ) OR ( int_konv-kschl = 'NAVM' )
              int_outtab-kwert_t = int_outtab-kwert_t + int_konv-kwert.
            ELSE.
    *****freight
              IF ( ( int_konv-kschl = 'FRA1' ) OR ( int_konv-kschl = 'FRB1'
                                              OR  ( int_konv-kschl = 'FRC1'
                int_outtab-kwert_f = int_outtab-kwert_f + int_konv-kwert.
              ELSE.
    *****insurance
                IF ( ( int_konv-kschl = 'ZGIN' )  OR ( int_konv-kschl =
                'ZIN2' ) ).
                  int_outtab-kwert_i =  int_outtab-kwert_i + int_konv-kwert.
                ELSE.
    ****others
                  IF NOT (    ( int_konv-kschl = 'NAVS' ) OR (
                  int_konv-kschl = 'NAVM' )
                           OR ( int_konv-kschl = 'FRA1' ) OR (
                           int_konv-kschl = 'FRB1' )
                           OR ( int_konv-kschl = 'FRC1' ) OR (
                           int_konv-kschl = 'ZGIN' )
                           OR ( int_konv-kschl = 'ZIN2' ) OR (
                           int_konv-kschl = 'RA00' )
                           OR ( int_konv-kschl = 'RA01' ) OR (
                           int_konv-kschl = 'RB00' )
                           OR ( int_konv-kschl = 'PBXX' ) OR (
                           int_konv-kschl = 'PB00' )
                           OR ( int_konv-kschl = 'RC00' ) OR (
                           int_konv-kschl = 'RL01' ) ).
                    int_outtab-kwert_o =   int_outtab-kwert_o  +
                    int_konv-kwert.
                  ENDIF.
                ENDIF.
              ENDIF.
            ENDIF.
          ENDLOOP.
    ****total
          int_outtab-kwert_total =  int_outtab-kwert_t
                                    + int_outtab-kwert_f
                                    + int_outtab-kwert_i
                                    + int_outtab-kwert_o
                                  + int_outtab-netwr.
        ENDON.
        MODIFY int_outtab.
      ENDLOOP.
    ******End of calculation of PO
    *start of calculation for actual payment
    *****Excise
    sort int_outtab by ebelp ebeln.
      LOOP AT int_outtab.
        ON CHANGE OF int_outtab-ebelp OR int_outtab-ebeln.
          SELECT * FROM rseg INTO CORRESPONDING FIELDS OF int_rseg
    *          FOR ALL ENTRIES IN int_outtab
                 WHERE ebeln = int_outtab-ebeln AND
                       ebelp = int_outtab-ebelp.
            APPEND int_rseg.
          ENDSELECT.
        ENDON.
      ENDLOOP.
      sort int_rseg by ebelp lfbnr matnr.
      LOOP AT int_rseg.
        ON CHANGE OF int_outtab-ebelp OR int_rseg-lfbnr OR int_rseg-matnr OR
        int_rseg-lfgja.
          SELECT * FROM j_1ipart1 INTO wa_j_1ipart1
          WHERE mblnr = int_rseg-lfbnr AND
                mjahr = int_rseg-lfgja AND
                matnr = int_rseg-matnr.
            ON CHANGE OF wa_j_1ipart1-mblnr OR wa_j_1ipart1-zeile.
              SELECT * FROM j_1igrxref INTO wa_j_1igrxref
               WHERE mblnr = wa_j_1ipart1-mblnr AND
                     zeile = wa_j_1ipart1-zeile.
                IF sy-subrc EQ 0.
                  ws_ecs = ws_ecs + wa_j_1igrxref-exbed + wa_j_1igrxref-ecs.
                ENDIF.
              ENDSELECT.
            ENDON.
          ENDSELECT.
        ENDON.
        MOVE ws_ecs TO int_rseg-ecs.
        MODIFY int_rseg TRANSPORTING ecs.
        CLEAR: ws_ecs.
      ENDLOOP.
      LOOP AT int_outtab.
        ON CHANGE OF int_outtab-ebeln.
          LOOP AT int_rseg WHERE ebeln = int_outtab-ebeln.
            ws_ecs = ws_ecs + int_rseg-ecs.
          ENDLOOP.
        ENDON.
        MOVE ws_ecs TO int_outtab-ecs.
        MODIFY int_outtab TRANSPORTING ecs.
        CLEAR ws_ecs.
      ENDLOOP.
    ******unplanned costs and actual_invoice_total
      SORT int_rseg BY belnr.
      LOOP AT int_rseg .
        ON CHANGE OF int_rseg-belnr.
          SELECT  belnr beznk rmwwr tcode FROM rbkp INTO int_rbkp
          WHERE   belnr  = int_rseg-belnr .
            APPEND int_rbkp.
          ENDSELECT.
        ENDON.
      ENDLOOP.
      SORT int_rseg BY belnr.
      SORT int_rbkp BY belnr.
      LOOP AT int_rseg.
        ON CHANGE OF int_rseg-ebeln OR int_rseg-belnr.
          LOOP AT int_rbkp WHERE belnr = int_rseg-belnr.
            IF int_rbkp-tcode = 'MR8M'.
              int_rbkp-rmwwr = int_rbkp-rmwwr * ( - 1 ).
              int_rbkp-beznk = int_rbkp-beznk * ( - 1 ).
            ENDIF.
            ws_beznk =  ws_beznk + int_rbkp-beznk.
            ws_rmwwr =  ws_rmwwr + int_rbkp-rmwwr.
          ENDLOOP.
        ENDON.
        MOVE ws_beznk TO int_rseg-beznk.
        MOVE ws_rmwwr TO int_rseg-rmwwr.
        MODIFY int_rseg.
        CLEAR: ws_rmwwr, ws_beznk.
      ENDLOOP.
      LOOP AT int_outtab.
        ON CHANGE OF int_outtab-ebeln.
          LOOP AT int_rseg WHERE ebeln = int_rseg-ebeln.
            ws_beznk =  ws_beznk + int_rseg-beznk.
            ws_rmwwr =  ws_rmwwr + int_rseg-rmwwr.
          ENDLOOP.
        ENDON.
        MOVE ws_beznk TO int_outtab-beznk.
        MOVE ws_rmwwr TO int_outtab-rmwwr.
        MODIFY int_outtab.
        CLEAR: ws_rmwwr, ws_beznk.
      ENDLOOP.
    *freight of actual payment
      sort int_rseg by belnr ebelp.
      LOOP AT int_rseg.
        ON CHANGE OF  int_rseg-belnr or int_rseg-ebelp..
          SELECT * FROM ekbz INTO CORRESPONDING FIELDS OF int_ekbz
          WHERE ebeln = int_rseg-ebeln AND
                belnr = int_rseg-belnr AND
                ebelp = int_rseg-ebelp AND
                vgabe = '2' .
            IF int_ekbz-shkzg = 'H'.
              int_ekbz-wrbtr = int_ekbz-wrbtr  * ( - 1 ).
            ENDIF.
            int_rseg-wrbtr_f = int_rseg-wrbtr_f + int_ekbz-wrbtr.
          ENDSELECT.
        ENDON.
        MODIFY int_rseg.
        CLEAR int_rseg-wrbtr_f.
      ENDLOOP.
      sort int_rseg by ebelp.
      LOOP AT int_outtab.
        ON CHANGE OF int_outtab-ebeln OR int_outtab-ebelp.
          LOOP AT int_rseg WHERE ebeln = int_outtab-ebeln AND
                                 ebelp = int_outtab-ebelp.
            ws_wrbtr_f = ws_wrbtr_f + int_rseg-wrbtr_f.
          ENDLOOP.
        ENDON.
        MOVE ws_wrbtr_f TO int_outtab-wrbtr_f.
        MODIFY int_outtab TRANSPORTING wrbtr_f.
        CLEAR ws_wrbtr_f.
      ENDLOOP.
    **tax and gross amt of actual payment
      LOOP AT int_outtab.
        ON CHANGE OF int_outtab-ebelp OR int_outtab-ebeln.
        " or int_outtab-belnr.
          SELECT ebelp refwr wrbtr shkzg FROM ekbe INTO int_ekbe
          WHERE ebelp = int_outtab-ebelp AND
                ebeln = int_outtab-ebeln AND
                vgabe = '2' .
            IF int_ekbe-shkzg = 'H'.
              int_ekbe-refwr  = int_ekbe-refwr * ( - 1 ).
              int_ekbe-wrbtr  = int_ekbe-wrbtr * ( - 1 ).
            ENDIF.
            int_outtab-refwr_g = int_outtab-refwr_g +  int_ekbe-refwr.
            int_outtab-tax =  int_outtab-tax + ( int_ekbe-wrbtr -
            int_ekbe-refwr ).
          ENDSELECT.
        ENDON.
        MODIFY int_outtab.
        CLEAR int_outtab-refwr_g.
        CLEAR int_outtab-tax.
      ENDLOOP.
    ****total
      LOOP AT int_outtab.
        ON CHANGE OF int_outtab-ebelp  OR int_outtab-ebeln.
          int_outtab-actual_total =  int_outtab-actual_total
                                     + int_outtab-ecs
                                     + int_outtab-wrbtr_f
                                     + int_outtab-tax
                                     + int_outtab-beznk
                                     + int_outtab-refwr_g.
          int_total-actual_total =  int_outtab-actual_total.
          int_total-ebelp        = int_outtab-ebelp.
          int_total-ebeln        = int_outtab-ebeln.
          APPEND int_total.
        ENDON.
      ENDLOOP.
    *end of calculation for actaul payment
    *************Modification in internal table*****
      LOOP AT int_outtab.
        IF int_outtab-ebelp = ws_ebelp AND
           int_outtab-ebeln = ws_ebeln.
          int_outtab-netwr = 0.
          MODIFY int_outtab.
        ENDIF.
        ws_ebelp = int_outtab-ebelp.
        ws_ebeln = int_outtab-ebeln.
      ENDLOOP.
      LOOP AT int_outtab.
        IF int_outtab-netwr IS INITIAL.
          DELETE int_outtab INDEX sy-tabix.
        ENDIF.
      ENDLOOP.
      LOOP AT int_outtab.
        ON CHANGE OF int_outtab-ebeln.
          LOOP AT int_total WHERE ebeln = int_outtab-ebeln.
            int_outtab-actual_total =  int_outtab-actual_total
                                       + int_total-actual_total.
          ENDLOOP.
        ENDON.
        MODIFY int_outtab.
      ENDLOOP.
      LOOP AT int_outtab.
        SELECT SINGLE * FROM lfm1 INTO CORRESPONDING FIELDS OF int_outtab
        WHERE lifnr = int_outtab-lifnr.
        MODIFY int_outtab.
      ENDLOOP.
    ********** end of modification*********
    ENDFORM.                    "get_data
    *&      Form  field_catalog
    *       text
    FORM field_catalog.
    ***vender no
      int_cat-tabname       = 'INT_OUTTAB'.
      int_cat-fieldname     = 'LIFNR'.
      int_cat-reptext_ddic  = 'Vender No'.
      APPEND int_cat TO ws_cat.
    *vender name
      int_cat-tabname       = 'INT_OUTTAB'.
      int_cat-fieldname     = 'NAME1'.
      int_cat-reptext_ddic  = 'Vender Name'.
      APPEND int_cat TO ws_cat.
    ** PO No
      int_cat-tabname       = 'INT_OUTTAB'.
      int_cat-fieldname     = 'EBELN'.
      int_cat-reptext_ddic  = 'PO No'.
      APPEND int_cat TO ws_cat.
    ** Mat No
      int_cat-tabname       = 'INT_OUTTAB'.
      int_cat-fieldname     = 'MATNR'.
      int_cat-reptext_ddic  = 'Mat No'.
      APPEND int_cat TO ws_cat.
    ** Matdescription
      int_cat-tabname       = 'INT_OUTTAB'.
      int_cat-fieldname     = 'TXZ01'.
      int_cat-reptext_ddic  = 'Mat description'.
      APPEND int_cat TO ws_cat.
    **WBS/Cost center
      int_cat-tabname       = 'INT_OUTTAB'.
      int_cat-fieldname     = 'KOSTL'.
      int_cat-reptext_ddic  = 'WBS/Cost center'.
      APPEND int_cat TO ws_cat.
    **Currency
      int_cat-tabname       = 'INT_OUTTAB'.
      int_cat-fieldname     = 'WAERS'.
      int_cat-reptext_ddic  = 'Currency'.
      APPEND int_cat TO ws_cat.
    **Basic
      int_cat-tabname       = 'INT_OUTTAB'.
      int_cat-fieldname     = 'NETWR'.
      int_cat-reptext_ddic  = 'Basic'.
      APPEND int_cat TO ws_cat.
    **Excise
      int_cat-tabname       = 'INT_OUTTAB'.
      int_cat-fieldname     = 'KBETR'.
      int_cat-reptext_ddic  = 'Excise'.
      APPEND int_cat TO ws_cat.
    **Insurance
      int_cat-tabname       = 'INT_OUTTAB'.
      int_cat-fieldname     = 'KWERT_I'.
      int_cat-reptext_ddic  = 'Insurance'.
      APPEND int_cat TO ws_cat.
    **Frieght
      int_cat-tabname       = 'INT_OUTTAB'.
      int_cat-fieldname     = 'KWERT_F'.
      int_cat-reptext_ddic  = 'Frieght'.
      APPEND int_cat TO ws_cat.
    **VAT/ST
      int_cat-tabname       = 'INT_OUTTAB'.
      int_cat-fieldname     = 'KWERT_T'.
      int_cat-reptext_ddic  = 'VAT/ST'.
      APPEND int_cat TO ws_cat.
    **Other
      int_cat-tabname       = 'INT_OUTTAB'.
      int_cat-fieldname     = 'KWERT_O'.
      int_cat-reptext_ddic  = 'Others'.
      APPEND int_cat TO ws_cat.
    **Total
      int_cat-tabname       = 'INT_OUTTAB'.
      int_cat-fieldname     = 'KWERT_TOTAL'.
      int_cat-reptext_ddic  = 'Total'.
      APPEND int_cat TO ws_cat.
    ***Excise
      int_cat-tabname       = 'INT_OUTTAB'.
      int_cat-fieldname     = 'ECS'.
      int_cat-reptext_ddic  = 'Excise'.
      APPEND int_cat TO ws_cat.
    *****Freight
      int_cat-tabname       = 'INT_OUTTAB'.
      int_cat-fieldname     = 'WRBTR_F'.
      int_cat-reptext_ddic  = 'Freight'.
      APPEND int_cat TO ws_cat.
    *****Tax
      int_cat-tabname       = 'INT_OUTTAB'.
      int_cat-fieldname     =  'TAX'.
      int_cat-reptext_ddic  =  'Tax'.
      APPEND int_cat TO ws_cat.
    ***Unplanned Del Cost
      int_cat-tabname       = 'INT_OUTTAB'.
      int_cat-fieldname     = 'BEZNK'.
      int_cat-reptext_ddic  = 'Unplanned Del Cost'.
      APPEND int_cat TO ws_cat.
    ****Gross
      int_cat-tabname       = 'INT_OUTTAB'.
      int_cat-fieldname     = 'REFWR_G'.
      int_cat-reptext_ddic  = 'Gross'.
      APPEND int_cat TO ws_cat.
    **Total
      int_cat-tabname       = 'INT_OUTTAB'.
      int_cat-fieldname     = 'ACTUAL_TOTAL'.
      int_cat-reptext_ddic  = 'Total'.
      APPEND int_cat TO ws_cat.
    **Actual Invoice Total
      int_cat-tabname       = 'INT_OUTTAB'.
      int_cat-fieldname     = 'RMWWR'.
      int_cat-reptext_ddic  = 'Actual Invoice Total'.
      APPEND int_cat TO ws_cat.
    ENDFORM.                    "field_catalog
    *&      Form  display_data
    *       text
    FORM display_data.
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
        EXPORTING
          i_callback_program = 'Z_MM_TEST1'
          it_fieldcat        = ws_cat[]
        TABLES
          t_outtab           = int_outtab
        EXCEPTIONS
          program_error      = 1
          OTHERS             = 2.
    ENDFORM.                    "display_data
    Reward for all helpfull answers
    Regards
    Pavan

  • Need help with a query

    Hi,
    I need help with the following query. I want the balance (bal) with the latest exchange rate available.
    Sample table & data
    with
    FX_RATE as
    select 11 as id_date, 1 as id_curr, 47 as EXCH_rate from dual union
    select 12, 1, 48 from dual union
    select 13, 2, 54 from dual union
    select 14, 2, 55 from dual union
    select 15, 3, 56 from dual union
    select 15, 2, 49 from dual),
    TBL_NM as
    select 13 as p_date, 2 as p_curr, 200 as bal from dual union
    select 14, 2, 200 from dual union
    select 15, 2, 200 from dual union
    select 16, 2, 200 from dual union
    select 17, 2, 200 from dual union
    select 11, 5, 100 from dual
    select p_date, p_curr, bal * nvl(exch_rate,1) from TBL_NM T LEFT OUTER JOIN FX_RATE F1 on (id_curr = p_curr and F1.id_date = T.p_Date)In the above query for p_date 16 & 17 and p_curr 2 it returns just balance multiplied by exchange rate 1"default". But i want the balance to have data as per latest exchange rate which is of exchange rate 15.
    I tried this but returns error ORA-01799: a column may not be outer joined to a subquery ..
    with
    FX_RATE as
    select 11 as id_date, 1 as id_curr, 47 as EXCH_rate from dual union
    select 12, 1, 48 from dual union
    select 13, 2, 54 from dual union
    select 14, 2, 55 from dual union
    select 15, 3, 56 from dual union
    select 15, 2, 49 from dual),
    TBL_NM as
    select 13 as p_date, 2 as p_curr, 200 as bal from dual union
    select 14, 2, 200 from dual union
    select 15, 2, 200 from dual union
    select 16, 2, 200 from dual union
    select 17, 2, 200 from dual union
    select 11, 5, 100 from dual
    select p_date, p_curr, bal * nvl(exch_rate,1) from TBL_NM T LEFT OUTER JOIN FX_RATE F1
    on (id_curr = p_curr and F1.id_date = (select max(F2.id_date) from FX_RATE F2 where F2.id_curr = T.p_curr and F2.id_Date <=  T.p_date))Please advice on how i can achieve this ..

    The entire query wud be like this .. I've to incorporate in here
    CREATE MATERIALIZED VIEW MV_DUMMY
    BUILD IMMEDIATE
    REFRESH FORCE ON DEMAND
    AS
        SELECT T.ID_TSACTION_RELEASED                                                                                
        BAL.ID_CONTRACT_BALANCE                                                                                                                                                                                                                                                                           AS ID_CONTRACT_BALANCE,   
        T.N_REFERENCE_NUMBER                                                                                          
        T.INSTRUMENT_N_REFERENCE                                                                                      
        T.ITEM_NUMBER                                                                                                   
        T.EXTERNAL_SYSTEM_ID                                                                                            
        T.SEQUENCE_NUMBER                                                                                               
        T.ID_RELEASED_DATE                                                                                              
       ROUND(BAL.LC_AVAILABLE_BALANCE * NVL(FX1.EXCHANGE_RATE,1) / NVL(FX2.EXCHANGE_RATE,1) , 4)                           
        BAL.LIABILITY_BALANCE                                                                                              
        BAL.LIABILITY_BALANCE * NVL(FX3.EXCHANGE_RATE,1)                                                                   
        BAL.LIABILITY_CHANGE_USD                                                                                           
        BAL.MEMO_LIABILITY_BALANCE                                                                                         
        BAL.MEMO_LIABILITY_BALANCE * NVL(FX3.EXCHANGE_RATE,1)                                                              
        BAL.MEMO_LIABILITY_CHANGE_USD                                                                                      
        BAL.ORIGINAL_FACE_AMOUNT                                                                                           
        decode(T.TENOR_CODE,'Time','T','Sight','S','Split Sight Time','SST','Split Multiple Time','SMT',T.TENOR_CODE)
        CASE
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('ILC','IB','AIR','STG','NLC','NP')
          THEN T.ID_LIABILITY_CIF
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('ELC','EB','XLC','XP','EC','LN','SCF-AR')
          THEN T.Id_Beneficiary
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('TLC','IC','OA','SCF-AP')
          THEN T.ID_Applicant
        END PRIMARY_CUSTOMER_ID,
        CASE
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('ILC','IB','AIR','STG','NLC','NP')
          THEN plbcif.EXTERNAL_SYSTEM_ID
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('ELC','EB','XLC','XP','EC','LN','SCF-AR')
          THEN PBCIF.EXTERNAL_SYSTEM_ID
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('TLC','IC','OA','SCF-AP')
          THEN pappcif.EXTERNAL_SYSTEM_ID
        END PRIMARY_CUSTOMER_EXT_SYS_ID,
        CASE
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('ILC','IB','AIR','STG','NLC','NP')
          THEN plbcif.CIF_NAME
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('ELC','EB','XLC','XP','EC','LN','SCF-AR')
          THEN PBCIF.CIF_NAME
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('TLC','IC','OA','SCF-AP')
          THEN pappcif.CIF_NAME
        END PRIMARY_CUSTOMER_NAME,
        CASE
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('ILC','IB','AIR','STG','NLC','NP')
          THEN plbbac.BAC
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('ELC','EB','XLC','XP','EC','LN','SCF-AR')
          THEN pbbac.BAC
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('TLC','IC','OA','SCF-AP')
          THEN pappbac.BAC
        END PRIMARY_CUST_BAC_CODE,
        CASE
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('ILC','IB','AIR','STG','NLC','NP')
          THEN nvl(plbmg.MARKET,'NOT APPLICABLE')
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('ELC','EB','XLC','XP','EC','LN','SCF-AR')
          THEN nvl(pbmg.MARKET,'NOT APPLICABLE')
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('TLC','IC','OA','SCF-AP')
          THEN nvl(pappmg.MARKET,'NOT APPLICABLE')
        END PRIMARY_CUST_MARKET,
        CASE
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('ILC','IB','AIR','STG','NLC','NP')
          THEN nvl(plbmg.SUB_MARKET,'NOT APPLICABLE')
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('ELC','EB','XLC','XP','EC','LN','SCF-AR')
          THEN nvl(pbmg.SUB_MARKET,'NOT APPLICABLE')
          WHEN GTSPROD.PRODUCT_CATEGORY IN ('TLC','IC','OA','SCF-AP')
          THEN nvl(pappmg.SUB_MARKET,'NOT APPLICABLE')
        END PRIMARY_CUST_SUB_MARKET
      FROM F_TSACTION_RELEASED T
      LEFT OUTER JOIN D_BAC_CODE BAC
      ON (T.BAC_CODE_LIABILITY = BAC.BAC_CODE)
      LEFT OUTER JOIN REF_BAC_SORT_CODE REF_BAC
      ON (T.BAC_CODE_LIABILITY = REF_BAC.BAC)
      LEFT OUTER JOIN F_CONTRACT_BALANCE BAL
      ON (T.ID_TSACTION_RELEASED = BAL.ID_TSACTION_RELEASED)
      LEFT OUTER JOIN D_MARKET_SEGMENT MG
      ON (T.ID_MARKET_SEGMENT = MG.ID_MARKET_SEGMENT)
      LEFT OUTER JOIN D_DATE DT
      ON (DT.ID_DATE = T.ID_RELEASED_DATE)
      LEFT OUTER JOIN D_DATE DB
      ON (DB.ID_DATE = BAL.ID_RELEASED_DATE)
      LEFT OUTER JOIN D_PROCESSING_UNIT PU
      ON (PU.ID_PROCESSING_UNIT = T.ID_PROCESSING_UNIT)
      LEFT OUTER JOIN D_BIR_PRODUCT BIRPROD
      ON (BIRPROD.ID_BIR_PRODUCT=T.ID_BIR_PRODUCT)
      LEFT OUTER JOIN D_GTS_PRODUCT_TYPE GTSPROD
      ON (GTSPROD.ID_GTS_PRODUCT_TYPE= T.ID_GTS_PRODUCT_TYPE)
      LEFT OUTER JOIN D_GTS_TSACTION_TYPE GTST
      ON (GTST.ID_GTS_TSACTION_TYPE = T.ID_GTS_TSACTION_TYPE)
      LEFT OUTER JOIN D_CURRENCY CCYT
      ON (CCYT.ID_CURRENCY = T.ID_TSACTION_CURRENCY)
      LEFT OUTER JOIN d_cif lcif
      ON (lcif.id_cif = T.id_liability_cif)
      LEFT OUTER JOIN d_cif lbcif
      ON (lbcif.id_cif = bal.id_liability_cif)
      LEFT OUTER JOIN d_cif bcif
      ON (bcif.id_cif = T.id_BENEFICIARY)
      LEFT OUTER JOIN d_cif icif
      ON (icif.id_cif = T.id_ISSUING_BANK)
      LEFT OUTER JOIN d_cif acif
      ON (acif.id_cif = T.id_ADVISING_BANK)
      LEFT OUTER JOIN d_cif appcif
      ON (appcif.id_cif = T.id_applicant)
      LEFT OUTER JOIN d_state astate
      ON (astate.id_state = acif.id_state)
      LEFT OUTER JOIN d_state bstate
      ON (bstate.id_state = bcif.id_state)
      LEFT OUTER JOIN d_state lstate
      ON (lstate.id_state = lcif.id_state)
      LEFT OUTER JOIN d_state lbstate
      ON (lbstate.id_state = lbcif.id_state)
      LEFT OUTER JOIN d_state istate
      ON (istate.id_state = icif.id_state)
      LEFT OUTER JOIN d_state appstate
      ON (appstate.id_state = appcif.id_state)
      LEFT OUTER JOIN D_TSACTION_SOURCE TSrc
      ON (T.ID_TSACTION_SOURCE = TSrc.ID_TSACTION_SOURCE)
      LEFT OUTER JOIN D_COUNTRY LCTRY
      ON (LCTRY.ID_COUNTRY = lcif.ID_COUNTRY)
      LEFT OUTER JOIN D_COUNTRY LBCTRY
      ON (LBCTRY.ID_COUNTRY = lbcif.ID_COUNTRY)
      LEFT OUTER JOIN D_COUNTRY BCTRY
      ON (BCTRY.ID_COUNTRY = bcif.ID_COUNTRY)
      LEFT OUTER JOIN D_COUNTRY ICTRY
      ON (ICTRY.ID_COUNTRY = icif.ID_COUNTRY)
      LEFT OUTER JOIN D_COUNTRY ACTRY
      ON (ACTRY.ID_COUNTRY = acif.ID_COUNTRY)
      LEFT OUTER JOIN D_COUNTRY APPCTRY
      ON (APPCTRY.ID_COUNTRY = appcif.ID_COUNTRY)
      LEFT OUTER JOIN D_COUNTRY PCTRY
      ON (PCTRY.ID_COUNTRY = T.ID_PRESENTER_COUNTRY)
      LEFT OUTER JOIN D_LOCATION LOC
      ON (LOC.ID_LOCATION = T.ID_PROCESSING_LOCATION)
      LEFT OUTER JOIN D_CURRENCY BCCYT
      ON (BCCYT.ID_CURRENCY = BAL.ID_LIABILITY_CURRENCY)
      LEFT OUTER JOIN D_CURRENCY BALCYT
      ON (BALCYT.ID_CURRENCY = BAL.ID_BALANCE_CURRENCY)
      LEFT OUTER JOIN d_liability_type li
      ON (li.id_liability_type = BAL.id_liability_type)
      LEFT OUTER JOIN d_cif plbcif
      ON (plbcif.id_cif = T.id_liability_cif)
      LEFT OUTER JOIN REF_BAC_SORT_CODE plbbac
      ON (plbcif.bac_code=plbbac.bac)
      LEFT OUTER JOIN D_MARKET_SEGMENT plbmg
      ON (plbbac.SORT_CODE=plbmg.MARKET_SEGMENT)
      LEFT OUTER JOIN d_cif pbcif
      ON (pbcif.id_cif = T.id_BENEFICIARY)
      LEFT OUTER JOIN REF_BAC_SORT_CODE pbbac
      ON (pbcif.bac_code=pbbac.bac)
      LEFT OUTER JOIN D_MARKET_SEGMENT pbmg
      ON (pbbac.SORT_CODE=pbmg.MARKET_SEGMENT)
      LEFT OUTER JOIN d_cif pappcif
      ON (pappcif.id_cif = T.id_applicant)
      LEFT OUTER JOIN REF_BAC_SORT_CODE pappbac
      ON (pappcif.bac_code=pappbac.bac)
      LEFT OUTER JOIN D_MARKET_SEGMENT pappmg
      ON (pappbac.SORT_CODE=pappmg.MARKET_SEGMENT)
      LEFT OUTER JOIN D_CURRENCY LOCALCYT
      ON (LOCALCYT.alpha_code = PU.local_ccy)
      LEFT OUTER JOIN D_BRANCH Branch              
      ON (T.ID_BRANCH  = Branch.ID_BRANCH )
      LEFT OUTER JOIN F_USD_FX_RATE_HISTORY FX1
      ON (BAL.ID_BALANCE_CURRENCY = FX1.ID_CURRENCY and FX1.ID_DATE = (select max(FX11.ID_DATE) from F_USD_FX_RATE_HISTORY FX11 where BAL.ID_BALANCE_CURRENCY = FX11.ID_CURRENCY and FX11.ID_DATE <= BAL.id_released_date))
      LEFT OUTER JOIN F_USD_FX_RATE_HISTORY FX2
      ON (LOCALCYT.ID_CURRENCY = FX2.ID_CURRENCY and FX2.ID_DATE = (select max(FX22.ID_DATE) from F_USD_FX_RATE_HISTORY FX22 where LOCALCYT.ID_CURRENCY = FX22.ID_CURRENCY and FX22.ID_DATE <= BAL.id_released_date))
      LEFT OUTER JOIN F_USD_FX_RATE_HISTORY FX3
      ON (BAL.ID_LIABILITY_CURRENCY = FX3.ID_CURRENCY and FX3.ID_DATE = (select max(FX33.ID_DATE) from F_USD_FX_RATE_HISTORY FX33 where BAL.ID_LIABILITY_CURRENCY = FX33.ID_CURRENCY and FX33.ID_DATE <= BAL.id_released_date))Note the lines
    ROUND(BAL.MN_AVAILABLE_BALANCE * NVL(FX1.EXCHANGE_RATE,1) / NVL(FX2.EXCHANGE_RATE,1) , 4)                           
    BAL.LIABILITY_BALANCE * NVL(FX3.EXCHANGE_RATE,1)                                                                   
    BAL.MEMO_LIABILITY_BALANCE * NVL(FX3.EXCHANGE_RATE,1)                 
    And
    LEFT OUTER JOIN F_USD_FX_RATE_HISTORY FX1
      ON (BAL.ID_BALANCE_CURRENCY = FX1.ID_CURRENCY and FX1.ID_DATE = (select max(FX11.ID_DATE) from F_USD_FX_RATE_HISTORY FX11 where BAL.ID_BALANCE_CURRENCY = FX11.ID_CURRENCY and FX11.ID_DATE <= BAL.id_released_date))
      LEFT OUTER JOIN F_USD_FX_RATE_HISTORY FX2
      ON (LOCAMNYT.ID_CURRENCY = FX2.ID_CURRENCY and FX2.ID_DATE = (select max(FX22.ID_DATE) from F_USD_FX_RATE_HISTORY FX22 where LOCAMNYT.ID_CURRENCY = FX22.ID_CURRENCY and FX22.ID_DATE <= BAL.id_released_date))
      LEFT OUTER JOIN F_USD_FX_RATE_HISTORY FX3
      ON (BAL.ID_LIABILITY_CURRENCY = FX3.ID_CURRENCY and FX3.ID_DATE = (select max(FX33.ID_DATE) from F_USD_FX_RATE_HISTORY FX33 where BAL.ID_LIABILITY_CURRENCY = FX33.ID_CURRENCY and FX33.ID_DATE <= BAL.id_released_date))Thsi is where I need to incorporate the change

  • Need help with SQL Query

    I am trying to build a query that sums up 12 columns depending on some accounting variables.
    example:
    SELECT gbmcu, gbco, gbfy,'',SUM(gban01 gban02 gban03 gban04 gban05+gban06+gban07+gban08+gban09+gban10+gban11+gban12) AS Oil_Volumes
    FROM PRODDTA.F0902
    WHERE GBCO = '00099'
    AND GBFY = 5
    AND GBLT = 'QU' AND GBOBJ = 5015 AND GBSUB = '105'
    GROUP BY gbmcu, gbco, gbfy
    The condition that changes is :AND GBLT = 'QU' AND GBOBJ = 5015 AND GBSUB = '105'
    I need to do this for 17 different conditions - I need to make the query as optimized as possible.
    I tried using a case statement but that takes forever (the table is over 4 million records to scan through).
    Please let me know if anyone has any suggestions on how to create something to perform these calculations.
    thanks,
    Pam

    I think I would tend to write that query as:
    SELECT gbmcu, gbco, gbfy,
           SUM(CASE WHEN gblt = 'QA' AND gbobj = 5015 AND gbsub = '105' THEN
                    gban01+gban02+gban03+gban04+gban05+gban06+gban07+gban08+gban09+gban10+gban11+gban12 END) Oil_Sales
           SUM(CASE WHEN gblt = 'QU' AND gbobj = 5015 AND gbsub = '105' THEN
                    gban01+gban02+gban03+gban04+gban05+gban06+gban07+gban08+gban09+gban10+gban11+gban12 END) Oil_Volumes
    FROM proddta.f0902
    WHERE gbco = '00099' and
          gbfy = 5 and
          gblt IN ('QA', 'QU') and
          gbpbj = 5015 and
          gbsub = '105'
    GROUP BY gbmcu, gbco, gbfySUM the CASE rather than CASE SUM. Also, as written, your query will look at all of the records in f0902 whether or not they meet one of the Case criteria, so I would put the required values in the WHERE clause as well. Your samples only show gblt changing, so you may need to make the gbpbj and gbsub predicates IN lists as well.
    If the query runs in 1.5 hours calculating one value, I would expect it to be about the same calculating 17 values, since I would bet that most of the run time is accessing the table rather than doing the math. It would almost certainly be faster than running essentially the same query 17 times.
    Indexes on some or all of the columns in the WHERE clause may help, depending on how selective the columns are. At a guess, I would suggest that gbco and gbfy would be good candidates.
    Finally, are you sure that gbsub is a character field? The only example we have is a number.
    HTH
    John

  • Need helping in writing query for finding percentage of duration

    Can any one please help in writing query for this.
    The table is like this :-
    ID     Region     Month     Duration
    I1 R1     Jan     80
    I2     R2     Jan     70
    I3     R1     Jan     70
    I4     R3     Jan     40
    I5     R1     Feb     80
    I6     R2     Feb     30
    I7     R3     Mar     100
    I want to write a query to find
    % of duration for each and every region against each and every month.
    Please help in solving this query. I am in urgent need of this.
    Thanks in advance.

    I also have to do in MS Access 2003You also have to ask into an other forum since here it's an Oracle forum, to try to find Oracle solution.
    Nicolas.

  • F4 Help in ABAP QUERY

    Hi,
    Can we provide F4 help to  fields in Dynamic selections in an ABAP Query?
    Thanks
    Chandra

    Hi,
    Can we provide F4 help to  fields in Dynamic selections in an ABAP Query?
    Thanks
    Chandra

  • Need help writing a query for following scenario

    Hi all, I need some help writing a query for the following case:
    One Table : My_Table
    Row Count: App 5000
    Columns of Interest: AA and BB
    Scenario: AA contains some names of which BB contains the corresponding ID. Some
    names are appearing more than once with different IDs. For example,
    AA BB
    Dummy 10
    Me 20
    Me 30
    Me 40
    You 70
    Me 50
    Output needed: I need to write a query that will display only all the repeating names with their corresponding IDs excluding all other records.
    I would appreciate any input. Thanks

    Is it possible to have a records with the same values for AA and BB? Are you interested in these rows or do you only care about rows with the same value of AA and different BB?
    With a slight modification of a previous posting you can only select those rows that have distinct values of BB for the same value of AA
    WITH t AS (
    SELECT 'me' aa, 10 bb FROM dual
    UNION ALL
    SELECT 'me' aa, 20 bb FROM dual
    UNION ALL
    SELECT 'you' aa, 30 bb FROM dual
    UNION ALL
    SELECT 'you' aa, 30 bb FROM dual
    SELECT DISTINCT aa, bb
      FROM (SELECT aa, bb, COUNT(DISTINCT bb) OVER(PARTITION BY aa) cnt FROM t)
    WHERE cnt > 1;

  • Need help on join query

    Hi All,
    Please help me on the below join condition,
    >SELECT * FROM ESTIMATE_LINE WHERE JOB_ID = '214582' AND ESTIMATE_ID = 2;
    Output : Returns 1 row,
    >SELECT * FROM ESTIMATE_ACCOUNTING_LINE WHERE JOB_ID = '214582' AND ESTIMATE_ID = 2;
    Output : Returns 3 rows,
    I would like to add these two outputs as on, Finally i've to get 4 rows in the output,
    For that am writing the query like this,
    SELECT EL.*,EAL.*
    FROM ESTIMATE_LINE EL,
    ESTIMATE_ACCOUNTING_LINE EAL
    WHERE EL.JOB_ID = EAL.JOB_ID (+)
    AND EL.ESTIMATE_ID = EAL.ESTIMATE_ID (+)
    AND EAL.JOB_ID = '214582'
    AND EL.ESTIMATE_ID = 2,
    It is not giving the exact output, the common fields are there in the join condition,
    Can some one please re write the query for expected output..
    I am trying it but not getting the exact output,Unable to find out where the mistake is ...
    Thanks,
    gra

    Hi,
    First, let me make sure I undersatnd the problem.
    You have a query that lookas for information about a given job_id and estimate_id the estimate_line table. This query produces X rows.
    You have another query that lookas for information about the same job_id and estimate_id the estimate_accounting__line table. This query produces Y rows.
    You want to get the same results in one query that produces X+Y rows.
    That sounds like a job for UNION, not a join.
    If the two queries produces the same number of columns, and the data types of the columns are similiar, then you can just write the two queries together. Instead of a semicolon at the end of the first query, you'll say UNION (or UNION ALL):
    SELECT * FROM ESTIMATE_LINE            WHERE JOB_ID = '214582' AND ESTIMATE_ID = 2
    UNION ALL
    SELECT * FROM ESTIMATE_ACCOUNTING_LINE WHERE JOB_ID = '214582' AND ESTIMATE_ID = 2;If the columns are not the same, you'll need to call some conversion functions, or add literal columns (such as NULL) to the queries.
    If you need help, post a little sampe data (CREATE TABLE and INSERT statements) and the results you want from that data.

  • Need help on af:query, accessing bind variable.

    Hi All,
    Im working on Jdev 11.3. I need some help on af:Query UI component. I have a View Criteria defined on my VO and I am using this as <af:Query> in my .jsff. My View Criteria has 2 Bind Variables (Emp. Id, Emp Division). Emp Division is an LOV on the jsff.
    My requirement is to refresh the Results table when user changes the division LOV(and not when he clicks on Search button in the Query component).
    Is there a way to do this in backing bean? Something like a valuechangelistener on a LOV? How can I get from af:query component?
    Thanks.

    Hi,
    You can find some related info here..
    Can I achive valueChangeListener in af:query?
    and
    http://jobinesh.blogspot.com/2011/03/retrieving-viewcriteria-from-custom.html
    Thanks,
    TK

Maybe you are looking for