Query: Assign Cycle Id
Hello every one,
I need help in the query
WITH T AS
(SELECT 2006 ID,
1 st,
11 num
FROM DUAL
UNION ALL
SELECT 2006,
2,
12
FROM DUAL
UNION ALL
SELECT 2006,
5,
13
FROM DUAL
UNION ALL
SELECT 2006,
1,
14
FROM DUAL
UNION ALL
SELECT 2006,
2,
15
FROM DUAL
UNION ALL
SELECT 2008,
1,
11
FROM DUAL
UNION ALL
SELECT 2007,
5,
11
FROM DUAL
UNION ALL
SELECT 2007,
2,
12
FROM DUAL
UNION ALL
SELECT 2007,
3,
13
FROM DUAL
UNION ALL
SELECT 2007,
5,
14
FROM DUAL
UNION ALL
SELECT 2007,
2,
15
FROM DUAL)
SELECT *
FROM T
ORDER BY 1,
3
ID ST NUM
2006 1 11
2006 2 12
2006 5 13
2006 1 14
2006 2 15
2007 5 11
2007 2 12
2007 3 13
2007 5 14
2007 2 15
2008 1 11
Assign cycle id group by id order by num, assing new cycle per group after every occurance of 5 in st column. Measn rows before 5 and should get same cyple id
the data should look like this.
ID ST NUM Cycle id
2006 1 11 1 ^
2006 2 12 1 ^
2006 5 13 1 ^ <<- cycle 1
2006 1 14 2
2006 2 15 2 <<- cycle 2
2007 5 11 1
2007 2 12 2
2007 3 13 2
2007 5 14 2
2007 2 15 3
2008 1 11 1
Thank you
Hi,
With 10g
Regards Salim.
SELECT id,st,num, cycle_id
FROM T
model
partition by (id)
dimension by (row_number()over(partition by id order by num)rn)
measures( st,num, 1 cycle_id)
rules
(cycle_id[rn] order by rn asc= case when st[cv()-1] is null then 1
when st[cv()-1]=5 then cycle_id[cv()-1]+1
else cycle_id[cv()-1]
end )
order by id,num;
WITH T AS
(SELECT 2006 ID,
1 st,
11 num
FROM DUAL
UNION ALL
SELECT 2006,
2,
12
FROM DUAL
UNION ALL
SELECT 2006,
5,
13
FROM DUAL
UNION ALL
SELECT 2006,
1,
14
FROM DUAL
UNION ALL
SELECT 2006,
2,
15
FROM DUAL
UNION ALL
SELECT 2008,
1,
11
FROM DUAL
UNION ALL
SELECT 2007,
5,
11
FROM DUAL
UNION ALL
SELECT 2007,
2,
12
FROM DUAL
UNION ALL
SELECT 2007,
3,
13
FROM DUAL
UNION ALL
SELECT 2007,
5,
14
FROM DUAL
UNION ALL
SELECT 2007,
2,
15
FROM DUAL)
SELECT id,st,num, cycle_id
FROM T
model
partition by (id)
dimension by (row_number()over(partition by id order by num)rn)
measures( st,num, 1 cycle_id)
rules
(cycle_id[rn] order by rn asc= case when st[cv()-1] is null then 1
when st[cv()-1]=5 then cycle_id[cv()-1]+1
else cycle_id[cv()-1]
end )
order by id,num;
ID ST NUM CYCLE_ID
2006 1 11 1
2006 2 12 1
2006 5 13 1
2006 1 14 2
2006 2 15 2
2007 5 11 1
2007 2 12 2
2007 3 13 2
2007 5 14 2
2007 2 15 3
2008 1 11 1
11 rows selected.Edited by: Salim Chelabi on 2009-06-19 11:29
Similar Messages
-
RSBBS Jump Query -- Assignment Details
Hi , I went RSBBS Jump Query --> Assignment Details --> InfoObject is Company Code so I (select type "Variable") --> Field Name I tried both Info Object Name("0comp_code")and Variable of Infoobject "0comp_code" is "ZS_CC" Manual entry variable for choosing NYLP OR NYPLP So i tired putting that in Field Name --> Selection Type (E Single Value). But it did not work and reciever query still show me the both NYLP AND NYPLP COMPANY CODE. reason I think of is use of Structure Company code in Receiver query and not the same Variable ("0comp_code")ZS_CC which is used in Sender query. I cannot change the same beacuse of reconicillation issue between two report
Please let me know if I am doing any thing wrong or is there any other way to resolve this quick.
thanks
soniyaI didn't understand your question, i think you can do this way.
RSBBS Assign your Sender Query and receiver query. In Receiver query i think you have company code then create a variable and should be replacement path and specify the sender query In the next screen in the query option. Then you should be getting only those values for that company code. When u drill down. It should work, wait for others opnion.
Regards
Kunal -
Create record variable that refers dynamic query assigned to a ref cursor?
Hi ,
Just explaining what I am trying to achieve:
1) i have a hr.departments table that was loaded in hr schema on 1st oct 2012 with 4 columns(department_id, department_name, manager_id, location_id)
2) now I have a new schema by my name 'rahul' and I have loaded departments table but now an additional column has come into picture,ie created_date, this table got loaded on 1st-Nov-2012
3) Now going forward my columns could be dropped from the departments table (it can be a case), for example might be my departments table in my schema 'rahul' one day could comprise of only 3 columns(department_id,department_name,manager_id)
4) Now in the next step, I have managed to extract common column names(in a single line where columns are delimited using a comma) from both the tables(hr.departments and rahul.departments) which are (department_id, department_name, manager_id, location_id) using all_tab_cols table and I have written a function for it which i will be pasting below.
5) now going forward, using the above column names line with column names delimited using comma, I have used a ref cursor and assigned a query to it using the line of columns that I have extracted from the above point
6) Now I want to create a record variable which refers to my ref cursor, something like we do when we create a record variable by reffering to an explicit cursor defination that we give in the declaration block.
PS:
1) I have been out of touch with plsql for a long time so I have lost a lot of mmeory regarding plsql.
2) basically I need to compare data in hr.departments table with rahul.departments table for only columns that are common to both the tables, rest new or discarded columns information will go in one of the log tables that I have created(this is done already)
Please help me, I did try searching on google for the same but it really confused me very badly, any kind of help is appreciated, please find my code below:
Regards
Rahul
Code :
===================================================================================================
create or replace procedure p_compare_data(fp_old_table_name in varchar2, fp_new_table_name in varchar2)
is
type ref_cursor_old_table is ref cursor;
v_ref_cursor_old_table ref_cursor_old_table;
--record_v_ref_cursor_old_table v_ref_cursor_old_table;
--record_ref_cursor_old_table v_ref_cursor_old_table%ROWTYPE;
Lv_all_column_names varchar2(2000);
function f_fetch_common_column_names(fp_old_table_name in varchar2, fp_new_table_name in varchar2)
return varchar2
is
Lv_all_column_names varchar2(2000);
begin
execute immediate 'select ltrim(all_column_names,'','') all_column_names_in_line from (select * from (select sys_connect_by_path(hr_e_column_name,'','') all_column_names from (select hr_e_column_name, rownum curr, rownum - 1 prev from (select hr_e.* , rahul_e.* , case when (hr_e_column_name = rahul_e_column_name) then 1 when (rahul_e_column_name is NULL) then 2 when (hr_e_column_name is NULL) then 3 end decision from (select column_name hr_e_column_name from all_tab_cols where owner ='''||substr(fp_old_table_name,1,instr(fp_old_table_name,'.',1,1)-1)||''' and table_name = '''||substr(fp_old_table_name,instr(fp_old_table_name,'.',1,1)+1)||''') hr_e full outer join (select column_name rahul_e_column_name from all_tab_cols where owner = '''||substr(fp_new_table_name,1,instr(fp_new_table_name,'.',1,1)-1)||''' and table_name = '''||substr(fp_new_table_name,instr(fp_new_table_name,'.',1,1)+1)||''') rahul_e on hr_e.hr_e_column_name = rahul_e.rahul_e_column_name) decision_table where decision = 1) a start with a.curr = 1 connect by prior curr = prev) b order by length(b.all_column_names) desc) all_column_names_in_line where rownum = 1' into Lv_all_column_names;
return (Lv_all_column_names);
end;
begin
Lv_all_column_names := f_fetch_common_column_names(fp_old_table_name, fp_new_table_name);
--dbms_output.put_line(Lv_all_column_names);
open v_ref_cursor_old_table for ('select '||Lv_all_column_names||' from '||fp_old_table_name);
end;
=====================================================================================================>
6) Now I want to create a record variable which refers to my ref cursor, something like we do when we create a record variable by reffering to an explicit cursor defination that we give in the declaration block.
>
This thread is basically nothing more than a continuation of your original thread except now you are finally explaining what you are really trying to do.
Re: passing table name to a procedure and then need to open a cursor ..
In that original thread you said you found the solution
>
Well Mate thanks for your suggestion but I got it working through ref cusror, thanks for your time.
>
So I ask you to post your 'solution' and when you finally did it was clear that you hadn't solved anything at all. Your solution used a ref cursor all right but the code relied on a record ('record_employees') that was based on a table name ('employees') that was declared within the procedure. There isn't much point in passing in a table name if you have to hard-code the table name in the procedure.
create or replace procedure p_ref_cursor(fp_old_table in varchar2)
is
type ref_cursor is REF CURSOR;
v_ref_cursor ref_cursor;
record_employees hr.employees%ROWTYPE;
begin
open v_ref_cursor for 'select * from '||fp_old_table;
loop
fetch v_ref_cursor into record_employees;
exit when v_ref_cursor%NOTFOUND;
dbms_output.put_line(record_employees.employee_id);
end loop;
end;Then sb92075 ask you the question that illustrates what I just said
>
what happens when you pass in "HR.DEPARTMENTS" ; besides throwing errors?
>
And you blew him off with this
>
Mate, departments never came in my context, in my prior message I explained what I was trying to achieve ... so I dont know what problem you are understanding reading my posts.
>
And now here you are asking how to get this to work for the departments table.
It is very difficult to help someone that won't tell us what it is they are really trying to do so we can try to suggest some better ways of doing it. Hopefully, in the future, you wil start by explaining your problems instead of focusing on the solution you think you should use.
Back to the issue -
The first thing you should do is finish defining the requirements. Assuming the above actually works to identify columns that have different data what are you going to do with that information?
1. Do you need to save that different data from TABLE1 somewhere?
2. If you don't save it how will anyone look at it to decide which table has the correct data?
3. If you do save it how will you save it 'generically' since other tables will have different columns and datatypes?
4. What about the data from the same record in TABLE2; do you need to save that data somewhere?
5. Will these two tables have primary keys? Are they on the same columns in each table? If not what if TABLE1 has one record but there are TWO records in TABLE2 that are identical. Is that a match? Or is that a problem because TABLE2 has an extra record even though the record is identical?
In short detecting the differences is just one small part of the entire problem. You also need to save those differences somewhere so someone can examine the data and decide what action to take. That is the more difficult part of trying to implement a 'generic' solution.
But now that we know what you are really trying to do take a read through this thread from 6 years ago. It has three different ways to pass a query to a procedure and get different output. You may want to save a copy of the thread since it has some very advanced techniques in it.
How to pipeline a function with a dynamic number of columns?
See ascheffer's reply Posted: May 9, 2006 4:53 AM for using data cartridge functionality with a pipelined function.
See Kamal's reply Posted: May 10, 2006 4:49 AM - it shows how to get XML output.
See BluShadow's reply Posted: Mar 27, 2009 1:50 AM - for using dynamic sql -
Hello everybody
I am relatively new here; I have to calculate po cycle time(srm application) in my query and also report some other stuff. Question is how to calculate date feilds like difference of date feilds. And then i am having big issue with finding these date fields like po approval date, req id date and shopping cart approval date. Also i am not sure how these dates are coming in bw like mapping wise. Do they have to be mapped to infoobjects like themselves or could be mapped to standard time charachterstics.
Any help is appreciated. I really need to get this thing working soon
THanks
MarkHi Mark
I don't know the DS name in R/3 bcoz i have pulled the data from ARIBA system...you can chk with R/3 guys, they will be able to help you in finding tables and then you can find DS or create it on the tables...
For the calculation of PO cycle time..you have two option
1. In the report create a formula variable and put the two KF like
req-date - po-approve_date it will give you the difference of these two dates in no. of days
2. Create a infoObject of type date...and populate it with these two dates...write a routine in update rule...pass these two dates and use any function module
FIMA_DAYS_BETWEEN_TWO_DATES
DAYS_BETWEEN_TWO_DATES
It will give you the difference in year month and day...
Choose whatever option suits you
Thanks
Tripple k -
Hi all,
I have a problem with Jump query. I have Posting Date (variable of type range) in Source Query. Target Query has Invoice Date (variable of type range). Both Posting and Invoice dates variables are identical. In RSBBS setting in the assignment details I assigned Posting Date variable to Invoice date variable. When I try to jump from source to target it is still asking for the Invoice date. Tried different options in the RSBBS assignment but still no luck.
Any ideas as to how to send Posting Date variable values to Invoice date values.
Thanks,
Ram.Bhanu,
Both posting date and Invoice date are part of selection screen entries in both the queries. I cannot remove it. -
Query assigned to role. Doesnt execute when try to execute from under role
Hi Experts,
We have some queries assigned to a role in PFCG.
Now the anomaly is as follows:
some of the queries that are assigned, do not show any technical names in the Bex role window. When we click on these queries under this role, nothing happens. no execution, nothing.
The same queries if executed from under the Infoareas->infoprovider->query path, execute correctly.
This would point to incorrect assignments in PFCG, BUT thats not the case.
<bsp_protcl>://<bsp_server>/sap/bw/BEx?sap-language=<language>&bsplanguage=EN&cmd=ldoc&INFOCUBE=Z1&QUERY=ZQ1
<bsp_protcl>://<bsp_server>/sap/bw/BEx?sap-language=<language>&bsplanguage=EN&cmd=ldoc&INFOCUBE=Z2&QUERY=ZQ2
The details of the query assignments to the role are as above.
Query ZQ1 shows in Bex role with a technical name and executes properly.
Query ZQ2 doesn't show a technical name under that role in Bex and doesnt execute.
Also if I execute ZQ2 from the PFCG, it executes correctly.
What are we missing here?
All help appreciated!The query name is correct. The assignment seems to be correct too.
But for this particular assignment, the bex role doesnt show a technical name for the query. neither does the query execute.
Why don't the assignment via PFCG work?
Edited by: CC on May 22, 2008 6:04 PM -
Hello Gurus,
I have created a query and wish to assign it to a role. For eg:
Role YYBBW_GL_TEST is a role I wish to assign the same query to.
This role is assigned to my profile, but when I try to assign this query to a role,,, I am unable to see this role in my list of ROLES..
Why is this happening.?
Kindly help.
Regards,
KPI guess it's because the role is empty.
Try to insert a dummy transaction to the role in the PFCG menu entry (example : RRMX), and you'll see the role in the Query Designer. -
Hi all....
I am using oracle 10g........
The following query is a union of two queries....The second query is a subset of the first meaning that it has fewer tables and fewer select columns as well....(I have to use union on the two queries....for a gud reason) .What i want is that the union return only the superset records from result of the union of the two queries when i pass a parameter at runtime like supplier_name as mentioned in the the query below .......
/* Formatted on 2012/05/14 16:49 (Formatter Plus v4.8.8) */
SELECT * FROM(SELECT DISTINCT reql.unit_meas_lookup_code "UNIT",
reqh.type_lookup_code "PR_TYPE",
reql.document_type_code "SUBTYPE",
reqh.segment1 "PR_NO", reqh.creation_date "PR DATE",
mtb.segment1 "ITEM_CODE",
pol.item_description "DESCRIPTION",
mcb.segment1 "INVENTORY_CATEGORY",
reql.manufacturer_part_number "MFG NO/DRG NO",
poh.authorization_status "AUTHORIZATION STATUS",
papf.full_name "BUYER", NULL "CUSTOMER",
DECODE (poh.type_lookup_code,
'RFQ', poh.segment1
) "RFQ NO",
DECODE (poh.type_lookup_code,
'RFQ', poh.creation_date
) "RFQ DATE",
NULL "RFQ SUPPLIER",
DECODE (poh.type_lookup_code,
'QUOTATION', poh.segment1
) "QTN NO",
DECODE (poh.type_lookup_code,
'QUOTATION', poh.reply_date
) "QTN DATE",
DECODE (poh.type_lookup_code,
'STANDARD', poh.segment1,
'BLANKET', poh.segment1,
'PLANNED', poh.segment1
) "PO_NO",
DECODE (poh.type_lookup_code,
'STANDARD', poh.creation_date,
'BLANKET', poh.creation_date,
'PLANNED', poh.creation_date
) "PO DATE",
pv.vendor_name "SUPPLIER",
NULL "SUPPLIER ACKNOWLEDGMENT DATE",
TRUNC
(reqh.creation_date
- TRUNC (poh.creation_date)
"NO OF DAYS TAKEN FROM PR TO PO",
DECODE (rcvh.asn_type,
'ASBN', rcvh.shipment_num
) "ASBN NO",
rcvh.receipt_num "RECEIPT NO",
rcvh.creation_date "RECEIPT DATE",
apia.invoice_num "INVOICE_NO",
NULL "QUALITY INSPECTION DATE",
rcvt.inspection_status_code "INSPECTION RESULT",
NULL "STOCKING DATE",
TRUNC (poh.creation_date)
- TRUNC (reqh.creation_date) "NO OF DAYS TAKEN FROM",
NULL "PV NO", NULL "PV DATE",
apc.amount "PAYMENT RELEASE AMOUNT",
apc.released_date "PAYMENT RELEASE DATE",
apc.payment_method_code "PAYMENT RELEASE MODE",
NULL "NO OF DAYS TAKEN FROM RECEIPT"
FROM po_requisition_headers_all reqh,
po_requisition_lines_all reql,
po_req_distributions_all reqd,
po_distributions_all pod,
po_headers_all poh,
po_lines_all pol,
po_line_locations_all poll,
rcv_shipment_headers rcvh,
rcv_shipment_lines rcvl,
rcv_transactions rcvt,
ap_invoice_distributions_all apid,
ap_invoices_all apia,
ap_payment_schedules_all aps,
ap_invoice_payments_all app,
ap_checks_all apc,
per_all_people_f papf,
po_vendors pv,
mtl_system_items_b mtb,
mtl_categories_b mcb,
mtl_item_categories mic
WHERE reqh.requisition_header_id =
reql.requisition_header_id
AND reql.requisition_line_id = reqd.requisition_line_id
AND pod.req_distribution_id = reqd.distribution_id
AND pol.po_line_id = pod.po_line_id
AND poh.po_header_id = pol.po_header_id
AND pol.po_line_id = poll.po_line_id
AND pod.po_distribution_id = apid.po_distribution_id
AND pod.po_distribution_id = rcvt.po_distribution_id
AND rcvl.shipment_header_id = rcvh.shipment_header_id
AND rcvh.shipment_header_id = rcvt.shipment_header_id
AND rcvt.po_distribution_id = apid.po_distribution_id
AND app.check_id = apc.check_id
AND apid.invoice_id = apia.invoice_id
AND apia.invoice_id = app.invoice_id
AND app.invoice_id = aps.invoice_id
AND poh.agent_id = papf.person_id
AND poh.vendor_id = pv.vendor_id
AND pol.item_id = mtb.inventory_item_id
AND mic.inventory_item_id = pol.item_id
AND poh.authorization_status = 'APPROVED'
AND mcb.category_id = mic.category_id
UNION
SELECT DISTINCT NULL "UNIT", NULL "PR_TYPE", NULL "SUBTYPE",
NULL "PR_NO", NULL "PR DATE",
mtb.segment1 "ITEM_CODE",
pol.item_description "DESCRIPTION",
mcb.segment1 "INVENTORY_CATEGORY", NULL,
poh.authorization_status "AUTHORIZATION STATUS",
papf.full_name "BUYER", NULL "CUSTOMER",
DECODE (poh.type_lookup_code,
'RFQ', poh.segment1
) "RFQ NO",
DECODE (poh.type_lookup_code,
'RFQ', poh.creation_date
) "RFQ DATE",
NULL "RFQ SUPPLIER",
DECODE (poh.type_lookup_code,
'QUOTATION', poh.segment1
) "QTN NO",
DECODE (poh.type_lookup_code,
'QUOTATION', poh.reply_date
) "QTN DATE",
DECODE (poh.type_lookup_code,
'STANDARD', poh.segment1,
'BLANKET', poh.segment1,
'PLANNED', poh.segment1
) "PO_NO",
DECODE (poh.type_lookup_code,
'STANDARD', poh.creation_date,
'BLANKET', poh.creation_date,
'PLANNED', poh.creation_date
) "PO DATE",
pv.vendor_name "SUPPLIER",
NULL "SUPPLIER ACKNOWLEDGMENT DATE", NULL,
DECODE (rcvh.asn_type,
'ASBN', rcvh.shipment_num
) "ASBN NO",
rcvh.receipt_num "RECEIPT NO",
rcvh.creation_date "RECEIPT DATE",
apia.invoice_num "INVOICE_NO",
NULL "QUALITY INSPECTION DATE",
rcvt.inspection_status_code "INSPECTION RESULT",
NULL "STOCKING DATE", NULL, NULL "PV NO",
NULL "PV DATE", apc.amount "PAYMENT RELEASE AMOUNT",
apc.released_date "PAYMENT RELEASE DATE",
apc.payment_method_code "PAYMENT RELEASE MODE",
NULL "NO OF DAYS TAKEN FROM RECEIPT"
FROM po_distributions_all pod,
po_headers_all poh,
po_lines_all pol,
rcv_shipment_headers rcvh,
rcv_shipment_lines rcvl,
rcv_transactions rcvt,
ap_invoice_distributions_all apid,
ap_invoices_all apia,
ap_payment_schedules_all aps,
ap_invoice_payments_all app,
ap_checks_all apc,
per_all_people_f papf,
po_vendors pv,
mtl_system_items_b mtb,
mtl_categories_b mcb,
mtl_item_categories mic
WHERE pol.po_line_id = pod.po_line_id
AND poh.po_header_id = pol.po_header_id
AND pod.po_distribution_id = apid.po_distribution_id
AND pod.po_distribution_id = rcvt.po_distribution_id
AND rcvl.shipment_header_id = rcvh.shipment_header_id
AND rcvh.shipment_header_id = rcvt.shipment_header_id
AND rcvt.po_distribution_id = apid.po_distribution_id
AND app.check_id = apc.check_id
AND apid.invoice_id = apia.invoice_id
AND apia.invoice_id = app.invoice_id
AND app.invoice_id = aps.invoice_id
AND poh.agent_id = papf.person_id
AND poh.vendor_id = pv.vendor_id
AND pol.item_id = mtb.inventory_item_id
AND mic.inventory_item_id = pol.item_id
AND poh.authorization_status = 'APPROVED'
AND mcb.category_id = mic.category_id) a
WHERE 1 = 1
AND ( a.pr_type = NVL (:pr_type, a.pr_type)
OR (:pr_type IS NULL AND a.pr_type IS NULL)
AND ( a.pr_no = NVL (:pr_no, a.pr_no)
OR (:pr_no IS NULL AND a.pr_no IS NULL)
AND ( a.unit = NVL (:unit_lookup_code, a.unit)
OR (:unit_lookup_code IS NULL AND a.unit IS NULL)
AND a.supplier = NVL (:supplier_name, a.supplier)
AND a.inventory_category = NVL (:inventory_category, a.inventory_category)
AND a.buyer = NVL (:buyer_name, a.buyer)
AND a.invoice_no = NVL (:invoice_no, a.invoice_no)
AND a.item_code = NVL (:item_code, a.item_code)
Edited by: Dave on May 14, 2012 5:08 AM
Edited by: Dave on May 14, 2012 5:14 AMDave wrote:
What i want is that the union return only the superset records from result of the union of the two queriesThat is what Union does.
If it doesn't, then it means it's not real duplicates.
For example :Scott@my11g SQL>with
2 table_A(val) as (
3 select 'This is a duplicate' from dual
4 union all select 'This is another' from dual
5 union all select 'This is not' from dual
6 )
7 ,table_B(val) as (
8 select 'This is a duplicate' from dual
9 union all select 'This is another' from dual
10 )
11 ------ end of sample data ------
12 select val from table_A
13 union
14 select val from table_B ;
Scott@my11g SQL>/
VAL
This is a duplicate
This is another
This is notSee ? only 3 rows from the 5 (3+2) originals.
But if I add some pseudo columns Which_table with different values for each table, then :Scott@my11g SQL>with
2 table_A(val) as (
3 select 'This is a duplicate' from dual
4 union all select 'This is another' from dual
5 union all select 'This is not' from dual
6 )
7 ,table_B(val) as (
8 select 'This is a duplicate' from dual
9 union all select 'This is another' from dual
10 )
11 ------ end of sample data ------
12 select val, 'from table_A' which_table from table_A
13 union
14 select val, 'from table_B' from table_B ;
VAL WHICH_TABLE
This is a duplicate from table_A
This is a duplicate from table_B
This is another from table_A
This is another from table_B
This is not from table_AThere is now 5 rows, they are no longer duplicates. -
Assigning a query dynamically to a cursor based on IF ELSE condotion
hello guys,
we are facing a problem while creating a procedure.
The procedure has been recreated in ORACLE from SQL SERVER 2005.
the problem is that in SQL server we can assign a query dynamically to a cursor so that it will be called at execution time.But this is not the case in oracle, i.e in Oracle its not allowed to assign a query to a cursor dynamically(OR IS IT...!!!)
the code is
vr_SQL varchar2(400);
declare
cursor ord_cur ; <-----cursor declaration
begin
If v_pIsScrutiny = 0 then +<--------------second condition+
vr_SQL:='Select NVL(ServiceID,0) ServiceID,OrdQty,+<-------query assignment to a variable+
NVL(DrugID,0) DrugID,NVL(ServiceAmount,0) Rate,OrdDtlID
from Orderdtl inner join ordermst on Orderdtl.OrdID = ordermst.OrdID
Where Orderdtl.OrdID in (Select OrdID From Ordermst Where OrdVisitID = vr_visitid
and TO_CHAR(ordermst.OrdDate,''DD-MON-YYYY'')
Between TO_CHAR(vr_pActivationDate,''DD-MON-YYYY'')
and TO_CHAR(vr_pExpiryDate,''DD-MON-YYYY'')
) And NVL(Orderdtl.Cancelled,0) = 0 And NVL(Orderdtl.PackageID,0) = 0
and NVL(Orderdtl.DrugID,0) = 0;';
Else +<--------------first condition+
Update OrderDtl Set PackageID = 0 , AllocationID = 0 , ConsumptionID = 0
Where OrdID in (Select OrdID From Ordermst Where OrdVisitID = vr_visitid)
And AllocationID = v_pHCPAllocationID;
vr_SQL:= 'Select NVL(ServiceID,0) ServiceID, +<-------query assignment to a variable+
OrdQty,NVL(DrugID,0) DrugID,NVL(ServiceAmount,0)
Rate,OrdDtlID
from Orderdtl inner join ordermst on Orderdtl.OrdID = ordermst.OrdID
Where Orderdtl.OrdID in (Select OrdID From Ordermst Where OrdVisitID = vr_visitid
and TO_CHAR(ordermst.OrdDate,''DD-MON-YYYY'')
Between TO_CHAR(vr_pActivationDate,''DD-MON-YYYY'')
and TO_CHAR(vr_pExpiryDate,''DD-MON-YYYY'')
) And NVL(Orderdtl.Cancelled,0) = 0 And NVL(Orderdtl.PackageID,0) = 0;';
end if;
ord_cur is vr_SQL; +<----------query assigned to a cursor variable+
ord_rec ord_cur%ROWTYPE;
if not ord_cur%ISOPEN then
open ord_cur;
end if;
loop
fetch ord_cur into ord_rec;
exit when ord_cur%NOTFOUND;So currently we are stuck with this problem.
Any solution would be of great help..
thank you841363 wrote:
hello guys,
we are facing a problem while creating a procedure.
The procedure has been recreated in ORACLE from SQL SERVER 2005.
the problem is that in SQL server we can assign a query dynamically to a cursor so that it will be called at execution time.But this is not the case in oracle, i.e in Oracle its not allowed to assign a query to a cursor dynamically(OR IS IT...!!!)The problem is that you are thinking in SQL Server terms and Oracle just isn't SQL Server.
You need to consider using ref cursors for such things (sys_refcursor) e.g.
SQL> CREATE OR REPLACE PACKAGE reftest IS
2 PROCEDURE test(P_no in number, cur_o OUT sys_refcursor);
3 end;
4 /
Package created.
SQL>
SQL> CREATE OR REPLACE PACKAGE body reftest as
2 PROCEDURE test(P_no in number, cur_o OUT sys_refcursor) as
3 myexc exception;
4 BEGIN
5 if P_no = 1 then
6 open cur_o for select empno, ename from emp;
7 elsif p_no =2 then
8 open cur_o for select deptno, dname from dept;
9 else
10 RAISE myexc;
11 END IF;
12 exception
13 when myexc then
14 raise_application_error(20991,'input must be 1 or 2');
15 end ;
16 end reftest;
17 /
Package body created.
SQL> var x refcursor;
SQL> exec reftest.test(1,:x);
PL/SQL procedure successfully completed.
SQL> print x;
EMPNO ENAME
7369 SMITH
7499 ALLEN
7521 WARD
7566 JONES
7654 MARTIN
7698 BLAKE
7782 CLARK
7788 SCOTT
7839 KING
7844 TURNER
7876 ADAMS
7900 JAMES
7902 FORD
7934 MILLER
14 rows selected.
SQL> exec reftest.test(2,:x);
PL/SQL procedure successfully completed.
SQL> print x;
DEPTNO DNAME
10 ACCOUNTING
20 RESEARCH
30 SALES
40 OPERATIONS
SQL> -
Use condition for assigning query to data provider with Javascript
Hi gurus,
I want to assign a query dynamically to a data provider when the user activated a Tab Panel in a Web Template (BI7).
I can do that easily with the standard function SET_DATA_PROVIDER_PARAMETERS but this action is do each time of the activation of the Tab Panel.
So I try to make a javascript for assign the query to the data provider only one time.
My problem is I havenu2019t found a solution to get the default query assigning to the data provider.
Itu2019s an example of what I try to do with javascipt :
function Load_Query()
var r=GET_DATA_PROVIDER PARAMETER ("QUERYVIEW_DATA_PROVIDER")
if (r <>empty)
executeJS_SET_DATA_PROVIDER_PARAMETERS_R()
Thank you for help,
FranckHi Janice,
You can check the Option Display Variable values only once.
Thie you will the variables being displayed only once eventhough they are used in Multiple Data provider.
If you want som variable to be data provider specific, then , you can create a new variable and add it int eh query.
For example in your case let us say COMP1 is the variable for company code used in DP1 and DP2.
If you want a different values to be selected for company code in DP1 and DP2 just replce the variable in DP2 with a new variabel COMP2.
Hope this helps.
Regards.
Shafi. -
Can we assign Transaction code to created ABAP Query of SQ01
Hi ,
Friends I want to run the abap query assigning t.code to it .. i will be thankfull if any body give me the steps or remedy .
thanksHi you there.... you can try this
1) create an abap report with the following source code
REPORT ZRUN_QUERY .
DECLARACIÓNES *
DATA:
REPORTNAME LIKE AQADEF-PGNAME.
PANTALLA DE SELECCION *
SELECTION-SCREEN BEGIN OF BLOCK B0 WITH FRAME TITLE TEXT-001.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
PARAMETERS: P_BGNAME LIKE AQADEF-BGNAME OBLIGATORY,
P_QUNAME LIKE AQADEF-QUNAME OBLIGATORY.
SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN END OF BLOCK B0.
CUERPO DEL PROGRAMA *
CALL FUNCTION 'RSAQ_REPORT_NAME'
EXPORTING
WORKSPACE = SPACE
USERGROUP = P_BGNAME
QUERY = P_QUNAME
IMPORTING
REPORTNAME = REPORTNAME.
CALL FUNCTION 'RSAQ_SUBMIT_QUERY_REPORT'
EXPORTING
QUERYREPORT = REPORTNAME
VARIANTE = SPACE
EXCEPTIONS
ONLY_WITH_VARIANT = 1
VARIANT_NOT_EXIST = 2
OTHERS = 3
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
2) Create a transaction for this program
3) Create a parameter transaction and execute this report passing by parameter the usergroup and Query, then, the program will automatically solve the program name and execute it.
Regards,
Daniel -
Which authorizations are required for assigning a query to a role?
Hi everybody,
we try to set up some roles for "reporting power users". These guys should be alble to define new queries using BEx (works fine) and also should be able to assign these new defined queries to a role, so other users can use these roles.
The idea is simple, but we're searching for the right authorization object (or - as i suppose - set of authorization objects) that enables the user to assign a query to a role (using that "enter to a role" button in the open / save dialog).
At the moment, the user can user that button, and the role, he should the query assigned to is shown. After selecting the role and clicking button "create" it take some seconds and a message "error when saving. entry has not been created" is shown.
Obviously, there is a problem with writing the role (or adding the new information to that role).
So, could anyone help me and provide me with a list of authorization objects that are required.
Thanks in advance,
AlfredS_RFC
S_TCODE
S_USER_GRP
S_BDS_D
S_OD_SEND
S_RS_AUTH
S_RS_BCS
S_RS_COMP
S_RS_COMP1
S_RS_FOLD
S_RS_ICUBE
S_RS_MPRO
The above mentioned authorization objects are enough to add in the role and required for the accessing a query.
particularly, S_RS_COMP, S_RS_COMP1, S_RS_MPRO, S_RS_ICUBE are the most important auth objects which are directly getting involved in authorization of a query in a role.
SO, you have to assign the respective info area, info cube and info providers names in these auth objects.
The same scenario , i am using in my project to give access to the queries in all the areas for my end users.
The values and access/authorizations restrictions is up to your project requirement.
Hope this would help you. -
Hello all, i need to assign a transaction code to a query, but there's already an assignment of a query to this tcode, i want to use the same tcode for my new query, and it doesn't matter if after this, the other one has no tcode left. Please, tell me how to do this.
And one more thing, while creating the query, when I click on basic list, there's a box with title "sort fields" but i cannot drop and drag any fields in there, i don't know how to do this (neither I know what is serves for)
Thanks!
Matiasuse se93 ,Enter name for Tcode you want to create -ztest for example .then choose parameter transaction and OK,choose START_REPORT for transaction value in 'Default value for' section and CHECK 'skip initial screen' check box .
at buttom of screen you must select this options:
D_SREPOVARI-REPORTTYPE : enter this value : AQ
D_SREPOVARI-REPORT :name of usergroup which query assigned to it,notice that you must enter this name with 12 character then if your user group name is ZREZA you have to enter 7 space after this name and at 13th poistion enter G.
> ZREZA G
D_SREPOVARI-EXTDREPORT : name of sap query report.report created with sq01(zqu_materila for example)
save you work and you can execute tcode. -
COPA Assessment Cycle using KEU5 for multiple controlling areas
Hello All,
There is an organization with operations in several countries. There is a separate controlling area for each country. There is one controlling area, for instance, for Germany and another for Netherlands.
A problem is encountered while executing transaction KEU5 for multiple controlling areas in parallel. For instance, when one user from Germany executes KEU5 for an assessment cycle for Germany controlling area and at the same time another user from Netherlands tries to execute KEU5 for a cycle for NL controlling area, the user from Netherlands encounters an error message u201C'Cycle XXXX 01.02.2008 cannot be started because run group 0000 is locked'.
Apparently SAP allows assessment cycles for exactly one controlling area to be executed together. This poses a problem since the organization plans to implement SAP in several other countries (There will be one separate controlling area for each country as per the organization structure adopted by the company).
Any ideas, views or suggestions on the aforesaid issue would be highly appreciated.
Regards,
SoumyaHi Soumya,
Did you find any text in SAP Documentation saying that "SAP does not allow cycles belonging to different controlling areas to be executed at the same time"...?
Pls find the following text from SAP Help...
Parallel Processing of Cycles of an Allocation Type
Use
Parallel processing of cycles results in considerable time savings. To process cycles of one allocation type in parallel, they must be assigned to different cycle run groups.
You define the cycle run groups in the cycle header data. You also assign cycles to the cycle run groups in the header data.
To process the cycles of a cycle run group in parallel, start the cycles one after the other, if required, in different sessions.
You are carrying out a cross-company code cost accounting and want to perform the actual assessment in the individual company codes in parallel. Create a cycle run group for each company code and assign the appropriate cycles to these groups. You can then carry out the actual assessment in the individual company codes in parallel.
When you execute a cycle, you can start a consistency check. The system checks whether you are allowed to execute the selected cycles in parallel.
Though I didn't come across such requirement, I feel, my earlier suggestion will work out...
Srikanth Munnaluri -
Dynamic change in the query name based on user input
Hi Gurus,
In a scenario, country appears as a user input variable.When the user specifies his country, the same query displays <b>Business trends</b>' data pertaining to his own country and rest of the world(international) in two tables.The reports are developed using Web application designer.
Can the name(description) of the query be changed so that the user input value for country gets dynamically reflected in the query name like <b>Business trends:Selected country vs International</b>?
Regards,
BalajiHi Bala,
ya this can be done by text variables. create a text variable( replacement path on the country infoobject) by going to the query properties on the description.
if the user enters country value then it will be displaed on the description of the query .
assign points if useful .
regards
santosh
Maybe you are looking for
-
Pls help if anybody can... I've lost my camera photos, even though I backed it up...
-
My i pod 2 gen is disabled due to incorrect password how do i fix this?
my i pod 2 gen is disabled due to incorrect password how do i fix this?
-
Display Images using READ_IMAGE_FILE in 10g forms
Hello all, i have a simple question that I'm trying to resolve really quick. I've created a field on a form in 10g forms that is of IMAGE type. I've given it a name and has given it a FILE_TYPE of GIF. I've put some code in a POST-QUERY trigger of a
-
Is it possible to open gerber files in Illustrator and save them as .eps?
Well? //ekmanch
-
Can't copy pictures to a portable HDD
Hi, I am trying to select multiple pictures to copy across to a portable HDD. It will let me copy single pics, but when I want to copy multiple pics it won't let me do it because it says 'MyPicture.jpg' is busy. Well, I have thrown that file into the