Report based on selection criteria in an Apex collection

For my current page I have to deal with a horrible "EAV" (Entity-Attribute-Value) table design like this:
Employee ---< Attribute Value >-- Attribute
So you might query who works in dept 10 and earns 20000 and was hired om 01-Jan-2007 like this:
select emp.ename
from emp
join attribute_value a1 on a1.empno = emp.empno and a1.att_name = 'DEPT'
join attribute_value a2 on a2.empno = emp.empno and a2.att_name = 'SALARY'
join attribute_value a3 on a3.empno = emp.empno and a3.att_name = 'HIREDATE'
where a1.att_numeric_value = 10
and   a2.att_numeric_value = 20000
and   a3.att_date_value = date '2007-01-01';(I said it was horrible!)
But to make matters worse, the form for entering query criteria is also based on the attributes table as a tabular form:
select apex_item.display_and_save(1,att_name) att_name
,      apex_item.text(2,null) att_value
from   attributes
where  att_type = 'EMPLOYEE';The user may enter values for any number of attributes and run the query. So in my example, there maybe be 0, 1, 2 or 3 criteria to use (or more when new attributes are added to the table).
I can code the report query as a "PL/SQL body returning SQL query" and build a SQL string exactly like my example above - all literal values. Is there any way I could do it that uses bind variables? Given the variable number of bind variables I think I'd need to use DBMS_SQL, but would I be able to integrate that into an Apex report region source? Or is there another way?
I'm open to any suggestions! (Except "redesign the database": much as I'd like to, I can't.)

If you are sure of the number of attributes the user will be using as criteria is fixed and will not change, you should able to bind the literals to page items like:
select emp.ename
from emp
join attribute_value a1 on a1.empno = emp.empno and a1.att_name = 'DEPT'
join attribute_value a2 on a2.empno = emp.empno and a2.att_name = 'SALARY'
join attribute_value a3 on a3.empno = emp.empno and a3.att_name = 'HIREDATE'
where a1.att_numeric_value = :P1_dept_value
and   a2.att_numeric_value = :P1_salary_value
and   a3.att_date_value = to_date(:P1_hiredate_value,'YYYY-MM-DD');or
select emp.ename
from emp
join attribute_value a1 on a1.empno = emp.empno and a1.att_name = :P1_att1_name
join attribute_value a2 on a2.empno = emp.empno and a2.att_name = :P1_att2_name
join attribute_value a3 on a3.empno = emp.empno and a3.att_name = :P1_att3_name
where a1.att_numeric_value = :P1_att1_value
and   a2.att_numeric_value = :P1_att2_value
and   a3.att_date_value = to_date(:P1_att3_value,'DD-MM-DD');What happens when your user wants to add another attribute and use it as search criteria. You have to:
1) add a JOIN clause to the SELECT
2) add to the WHERE clause to the SELECT
Warning personal opinion to follow: I would give up binding (i.e.. skipping parsing os the SELECT statement) for the flexibility of generating the SELECT at runtime. If the user adds a new attribute, then the PL/SQL code that assembles the SELECT statement would not have to be changed. All the meta data is stored in the database as to what the new column is and which column in the attributes table to use (ATT_NUMERIC_VALUE or ATT_DATE_VALUE). If your method of displaying the attributes and receiving the user's criteria is dynamic like my example, then you would not have to change the application at all for new attributes.
Just my 2 cents worth of opinion,
Mike

Similar Messages

  • Syntax for sum in Smart Form based on Selection criteria in Program.

    Hi,
    We have created smart form for printing confirmation entries in desired format. We have given some selection criteria in the program. Now, we want to do the sum of certain fields in the smart form based on selection criteria given in program and selection screen.
    But we are getting wrong sum in the smart form than expected.
    When we debug the program during run time, we are getting correct records as per our expectations. But result of sum in the out put is not as per given selection criteria.
    Do we need to establish link between "select option" and "Smart form"? How can we use internal table created for select option in the smart form?
    Thanks & regards
    Vijay

    Hi,
    There will be no option to sum the values in smartforms, You just have to sum and append the data to internal table and display the internal table data in the form.
    Regards,
    Satish

  • How to create a report  based on selected item from Select list?

    Hi,
    I have created a tables_LOV based on:
    select table_name d, table_name r from user_tab_cols
    where column_name like '%_type%'
    Then I created a page item ListOfTables,  Display as select list and pointing to tables_LOV.
    I run the page, and i can select the table i want from the drop down list.
    How to create a report  based on the selected item? (ex: select * from selected_table)
    many thanks in advance
    Salah

    Hi Salah,
    Allright, have a look at this page: http://apex.oracle.com/pls/apex/f?p=vincentdeelen:collection_report
    I think that simulates what you're trying to accomplish. I've set up the simplest method I could think of.
    The report is based on an apex collection. If you are not familiar with that, you should study the documentation: APEX_COLLECTION
    To recreate my example you should:
    1) create an (interactive) report on your collection
    SELECT *
       FROM APEX_collections
    WHERE collection_name = 'MY_COLLECTION'
    2) create a page_item select list for the tables you want to display (in my case this is called "P38_TABLES" )
    3) create a dynamic action that triggers on change of your select list page_item. The dynamic action must be a PL/SQL procedure perfoming the following code:
    declare
      l_query varchar2(4000);
    begin
      l_query := 'select * from '||:P38_TABLES;
      if apex_collection.collection_exists
            ( p_collection_name => 'MY_COLLECTION' )
      then
        apex_collection.delete_collection
          ( p_collection_name => 'MY_COLLECTION' );
      end if;
      apex_collection.create_collection_from_query
        ( p_collection_name => 'MY_COLLECTION'
        , p_query           => l_query
    end;
    Make sure you add your page_item to the "Page Items to Submit" section.
    4) Add an extra true action that does a refresh of the report region.
    Here are two pictures describing the da:
    http://www.vincentdeelen.com/images/otn/OTN_COLLECTION_REPORT_DA1.png
    http://www.vincentdeelen.com/images/otn/OTN_COLLECTION_REPORT_DA2.png
    Good luck and regards,
    Vincent
    http://vincentdeelen.blogspot.com

  • Refresh classic report based on select list value selected

    hello,
    can anyone please help me out with this issue. I have a parameterized classic report based on a select list and I want to refresh this report whenever the select list value is changed. I am using oracle apex version 3.2. i just want to have a javascript function onchange event for the select list which refreshes my report whenever a value is selected.
    My select list item is p1_datastore
    select distinct datastore d,datastore r from my_table1 order by 1;
    My classic report query is
    select * from my_table2 where datastore = :p1_datastore order by last_updated_dt desc;
    ****************************************************thanks,
    orton

    can anyone please help me out with this issue.
    thanks,
    orton

  • OBIEE report based on same criteria but different view based on filter

    Hi,
    I am trying to create a report in OBIEE 11.1.1.5 where In the same report using the same criteria, I can have different views which applies different filter.
    Suppose, I have a report criteria as
    Dim1, Dim2, Measure1, Measure 2.
    I want to create two pivot view based on the same data.
    One view will be showing data Dim1="Value1". The other view is duplicate of this view but will show data Dim1="Value2".
    Is it possible in OBIEE?
    basically what I want is work on the same dataset but different representation and show them in the same report. Please share your opinion.
    Regards,
    Tanveer.

    Hi,
    You create a new dim dummy column in criteria and in presentation level create new pivot table view use this dummy dimension column and filter with dim1=value2.
    give updates on this.
    Mark if Helpful/correct.
    Thanks.

  • A Date prompt defaulting the data in Report based on selection

    Gurus,
    I have a requirement , where i have a (in between) date prompt set in the dashboard current defulting to Start Month date and End Month date of current month.
    What the user want is based on the selection using a drop down in dashboard which has got values Last Day, Last week, Last Month , the default values in Date filter should change in dashboard.
    For Eg. If the user select Last Week, the in between date filter show the default date value as Last Week Mon and Last Sun, and should filter out the report based on that.
    Any idea's are welcome....
    Thanks & Regards
    -Saurabh

    Try to see if you can get user to agree on something easier.
    Here are the steps to achieve what you want.
    1. Create a prompt for 1 day, 2 week, and 3 month
    2. Create three separate reports based on above selection, which has page prompt for day/week/month respectively.
    3. Create GN based on step in 1 and then let UI change between three reports you created in step 2
    I hope this helps,
    Best luck

  • Logic required for report in which selection criteria is more than one

    Hi Friends,
    I have below piece of selection-screen criteria in my report.
    1)general data
    2)all customers
    3)company code data
      a)company code
    4)sales organization data
      a)sales org.
      b)dist. channel
      c)division
      d)field group
    In above one, 1..4 are check boxes and a..d are select-options under the respective check box.
    Please provide me the sample logic which I need to maintain in my report if user selects more than 1 check box.
    Thnks in advance.

    Hai,
    Let
    1)general data
    2)all customers
    3)company code data
    4)sales organization data
    are the check box names,Then
    Just use the piece  of code below:
    <b>IF general data = 'X'.
       COUNT = COUNT + 1.
    ENDIF.
    IF all_customers = 'X'.
       COUNT = COUNT + 1.
    ENDIF.
    IF company_code_data = 'X'.
       COUNT = COUNT + 1.
    ENDIF.
    IF sales_organization_data = 'X'.
       COUNT = COUNT + 1.
    ENDIF.</b>
    Now check whether more than one Check Boxes are selected or not
    <b>IF COUNT GT 1.
    "* Do the oprations  what ever you want here  
    ENDIF.</b>
    <b>Reward points if it helps you.</b>
    Regds,
    Rama chary.Pammi

  • Key Figure based on selection criteria

    Hi SDNers,
    I have Key figures which  i would like to display based on multiple selection criteria... for this we donot have master data data restricted at the query level it should be at the key figure leve...
    Eg:
    Sales which i would like to display based on SORG,DIV,MATERIal Etc.. Kindly can anyone will help...
    Thanks
    Sonu

    You can create restricted key figures if you want to use the same selection criteria in multiple queries.  In which you can get value for key figure for selcted filters on that perticular key figure.
    If you need it for just one query  you can create a structure and in that structure you can create a new selection which has your restrictions on that key figures.
    Search on help you will get to know hot to create structures and restricted key figures.

  • Update report based on selected LOV value

    I've searched the forum but could not find the answer how to implement the following:
    I have a form with a popup LOV, element P203_LOCATION_ID, which is populated from a query. When the user picks a value from it, a report in the same page should be refreshed. The report has query "select * from distances where d < 1 AND l = :P203_LOCATION_ID " .
    I created a dynamic action which would refresh the report on change of P203_LOCATION_ID , but the report does not change.
    After looking here, I made a hidden variable P203_SEL_LOCATION which is populated by dynamic action on change, with javascript $v('P203_LOCATION_ID') , and then a second rule in the dynamic action should refresh the report. The query in the report is changed to use :P203_SEL_LOCATION as a parameter.
    Although, when made display-only, P203_SEL_LOCATION does change (and console.log shows the selected ID), the report does not see that change and remains empty. I tried both IR and classic report, same result.
    Any help would be appreciated, how to make change in Items visible to the report?

    Hi Mila,
    I assume that you have checked that the report refresh process is happening and that by "empty" you meant that the report was not fetching any records whereas it should have for the value you see in the page.
    It could be because the changed values is not is not yet set in the session for the report to see(report fetches the bind value of the item P203_SEL_LOCATION from the session).
    You will need to add the item's value to the session before firing the report refresh.
    One way to do that would be to add a PLSQL process as true action with the sequence order lesser than the refresh.
    In the items to submit_ , give P203_SEL_LOCATION
    And the process needn't do anything(what we wanted was the P203_SEL_LOCATION be set, which would be done before executing this PLSQL)
    BEGIN
    NULL;
    END;Hope that solves your problem

  • How to transfer Customers to APO based on selection criteria of Division

    Hello,
    We have to transfer Customer Master specific to one business unit to APO and we don't want to transnfer the Customers of another business units. The differentiation of customers is done at a Distribution Channel & Division level. But we don't have Dist Channel & Division as a Selection criteria in Integration Model(CFM1). 
    The other option od Sales Org. Account Grp are common to other Business units too.
    Please provide your suggestions how we can do this.
    Thanks,
    Ashish

    Ashish
    You can manipulate the CFM1 o/p list using the BadI CIF_INT_MODEL. So you actually select all customers in the integration model and add custom logic in this badI implementation to delete the customers that you dont want to transfer . The updated CFM1 output list will then contain the customers that you want .
    Actually we used this BadI for manipulating the PIR's and BOM IM's and it is working without issues
    Thanks
    Aparna

  • Generate Report based on Select List

    Hi ,
    I have a drop down list those are the column names and a corresponding value i will enter in input text . so based on these two values how can i generate a report in Apex i am using apex 4.0.2.
    Means in where clause dropdown value will become column name and input text will become value for that column;
    Thanks
    Raghav

    This gets complicated really fast.
    I'd use an Interactive Report.
    select * from emp
    where (:P5_COLUMN_NAME='deptno' and deptno= :P5_COLUMN_VALUE)
       or (:P5_COLUMN_NAME='ename' and ename= :P5_COLUMN_VALUE)

  • ALV - Automatic Adjustable Columns (based on selection criteria)

    Hi,
    I am currently in the process of building a costing report for a number of materials.
    For the output, the columns will be the months, while the rows will pertain to the specific materials (1 or 2 columns for the material text and info).
    For example, the columns of the report will look something like:
    Material  January  February  March u2026.. December
    In the selection-screen, I will have input fields, including posting period range (month) and fiscal year single value.
    If the user enters year 2008 and period 10, I only want 1 column for October, with the other columns not present
    If they enter year 2008 and period 10 to 11, then only columns October and November show be displayed.
    Is this possible in abap ALV programming? If so, how? Are there FMu2019s and object-oriented routes that I can take & if so, what do I do? Please provide code samples if possible.
    Please help.
    Thanks,
    John

    I think you can accomplish this using dynamic internal tables...
    one another alternative is to have rows of months and columns as data... ie
    jan       data1 data2....
    feb
    mar

  • Need to call a Report Painter Report with filtered selection criteria

    Hello All,
    I have created a Report through which I am calling a Report Painter Program 'Z443'  as I have to first filter out the selections and then pass it to the Report Painter Report.
    I tried the following two ways and found these problems :
    1. Submit (program) with selection-table ..... and Return.
      The output had many entries i.e the parameters were not passed correctly to the Report Painter Report.
    2. Tried using the FM ' CRIF_RW_WEB_CALL_REPORT '.
      The transaction for the Report Painter is opening but selections from the first Report is not being transferred.
    Please help if you have worked on any similar requirements .
    Thanks!

    hi
    thanx for ur reply.
    i think the select-options is the best way to get more then one currency values.
    but i need to know what code i have to write for display of this day.
    in the standard report MCTA there he is using only one currency. similarly i need to add 2 more columns for each currency in that same report o/p.
    how to do that can any body help me
    regards,
    maqsood

  • Report painter Multiple selection criteria

    Hi all,
    i am facing problem that how to provide multiple selection 'exculde' options in report painters.can anyone help me in this?
    thank you,
    Anil.

    Please search for available information before posting, do not post basic questions.
    Thread locked.
    Thomas

  • Fetch the data from the Data base based on selection criteria in ABAP

    Hi
    I am new to ABAP and working on the Screen where User Enters Company code from and to , Document no and to, I have defined as specified below
      SELECT-OPTIONS Company     FOR p_ccode.
      SELECT-OPTIONS Document    FOR p_fdocnr.
      SELECT-OPTIONS Year           FOR p_fyear.
    When I debug in the pgm I get the values as
    IBT11001100 (From and To Company Code)
    IBT23234241002323424246 (From and To doc no)
    IBT20092009 (From and To Year)
    How can write a SQL select statement to fetch the data from the Database based on the above inputs
    Thanks
    PR

    Moderator message:
    Sorry - this isn't an ABAP training forum. Please press F1 on SELECT-OPTIONS and/or SELECT.
    Thread locked.
    Rob

Maybe you are looking for