Is max function will carry sort operation..?
Hi friends,
Is the max function will perform sort operation in temporary
segments..? Please list the set of operations that will take
place for the following Query (Apart from Syntax & Fetching the
data).
Ex:
delete from tab1 p1
where p1.rowid < (select max(p2.rowid)
from tab1 p2 where
p1.c1 = p2.c2);
Regards,
G. Rajakumar.
you can get that information using explain plan command.
DELETE STATEMENT
DELETE TAB1
FILTER
TABLE ACCESS FULL TAB1
SORT AGGREGATE TAB1
TABLE ACCESS FULL TAB1
Similar Messages
-
I have apple 4s and the operating system is iOS 5.1.1 got the update message of iOS 6. if update the iOS 6, other functions will work unchanging?
What other functions?
There have been some wifi related issues reported with the 4S being updated to IOS 6. There is no turning back once you update so keep that in mind.
I recommend updating via iTunes so that you make a backup of all your data. You may want to make an iCloud backup as well.
Other than that, I don't understand what other functions you are concerned about? -
Please review following SQL and it's execution plan. Why am I seeing 2 WINDOW SORT operations even though in sql . analytic function "row_number" has been used only once?
Also, In step 3 of the plan, why "bytes" goes from 35 GB(4th step) to 88GB when row count remains the same. In fact , since I'm selecting just 1st row , both row count as well as "bytes" should have gone down. Shouldn't it?
SELECT orddtl.ord_dtl_key, orddtl.ld_nbr, orddtl.actv_flg,
orddtl.ord_nbr
FROM (SELECT /*+ parallel(od, 8) parallel(sc,8) */ od.ord_dtl_key, od.ld_nbr, od.actv_flg,
od.ord_nbr,
ROW_NUMBER () OVER (PARTITION BY od.ord_dtl_key, od.START_TS ORDER BY sc.START_TS DESC)
rownbr
FROM edw.order_detail od LEFT OUTER JOIN edw.srvc_code sc
ON ( sc.srvc_cd_key = od.srvc_cd_key
AND od.part_nbr = sc.part_nbr
AND od.item_cre_dt >= sc.START_TS
AND od.item_cre_dt < sc.END_TS
WHERE od.part_nbr = 11 ) orddtl
WHERE orddtl.rownbr = 1;Execution Plan
| Id | Operation | Name | Rows | Bytes |TempSpc| Cost (%CPU)| Time | Pstart| Pstop | TQ |IN-OUT| PQ Distrib |
| 0 | SELECT STATEMENT | | 88M| 121G| | 2353K (65)| 00:33:07 | | | | | |
| 1 | PX COORDINATOR | | | | | | | | | | | |
| 2 | PX SEND QC (RANDOM) | :TQ10002 | 88M| 121G| | 2353K (65)| 00:33:07 | | | Q1,02 | P->S | QC (RAND) |
|* 3 | VIEW | | 88M| 121G| | 2353K (65)| 00:33:07 | | | Q1,02 | PCWP | |
|* 4 | WINDOW SORT PUSHED RANK | | 88M| 35G| 75G| 2353K (65)| 00:33:07 | | | Q1,02 | PCWP | |
| 5 | PX RECEIVE | | 88M| 35G| | 2353K (65)| 00:33:07 | | | Q1,02 | PCWP | |
| 6 | PX SEND HASH | :TQ10001 | 88M| 35G| | 2353K (65)| 00:33:07 | | | Q1,01 | P->P | HASH |
|* 7 | WINDOW CHILD PUSHED RANK| | 88M| 35G| | 2353K (65)| 00:33:07 | | | Q1,01 | PCWP | |
|* 8 | HASH JOIN RIGHT OUTER | | 88M| 35G| | 1610K (92)| 00:22:39 | | | Q1,01 | PCWP | |
| 9 | PX RECEIVE | | 1133K| 32M| | 1197 (20)| 00:00:02 | | | Q1,01 | PCWP | |
| 10 | PX SEND BROADCAST | :TQ10000 | 1133K| 32M| | 1197 (20)| 00:00:02 | | | Q1,00 | P->P | BROADCAST |
| 11 | PX BLOCK ITERATOR | | 1133K| 32M| | 1197 (20)| 00:00:02 | KEY | KEY | Q1,00 | PCWC | |
| 12 | TABLE ACCESS FULL | SRVC_CODE | 1133K| 32M| | 1197 (20)| 00:00:02 | 1 | 1 | Q1,00 | PCWP | |
| 13 | PX BLOCK ITERATOR | | 88M| 32G| | 188K (27)| 00:02:39 | KEY | KEY | Q1,01 | PCWC | |
| 14 | TABLE ACCESS FULL | ORDER_DETAIL | 88M| 32G| | 188K (27)| 00:02:39 | 1 | 1 | Q1,01 | PCWP | |
Predicate Information (identified by operation id):
3 - filter("orddtl"."rownbr"=1)
4 - filter(ROW_NUMBER() OVER ( PARTITION BY "od"."ORD_DTL_KEY","od"."START_TS" ORDER BY INTERNAL_FUNCTION("SC"."START_TS"(+))
DESC )<=1)
7 - filter(ROW_NUMBER() OVER ( PARTITION BY "od"."ORD_DTL_KEY","od"."START_TS" ORDER BY INTERNAL_FUNCTION("SC"."START_TS"(+))
DESC )<=1)
8 - access("od"."part_nbr"="SC"."part_nbr"(+) AND "SC"."SRVC_CD_KEY"(+)="od"."SRVC_CD_KEY")
filter("od"."ITEM_CRE_DT"<"SC"."END_TS"(+) AND "od"."ITEM_CRE_DT">="SC"."START_TS"(+))Thanks Jonathan for your reply.
This type of pattern happens quite frequently in parallel execution with aggregation. A layer of slave processes can do partial aggregation before passing a reduced result set to the query co-ordinator to finish the job.
I wouldn't be 100% sure without building a model to check, but I think the logic of your quer allows the eight slaves to identify each "rownumber() = 1" for the data set they have collected, and the allows the query coordinator to do the window sort on the eight incoming rows (for each key) and determine which one of the eight is ultimate the highest date.So is it a normal pattern? Will step#7 & #4 do the same amount work as stated in PREDICATE information part of execution plan.?
You’re correct! There are 8 slave processes appears to be performing WINDOW PUSHED RANK ( Step#7 in Execution Plan ) as you see in following output. Per execution plan and your comment, each one appears to be finding partial set of rows row_num <= 1. It’s apparently doing lots of work and very slow even with 8 processes. So not sure , how slow would be QC doing the same work just by itself.
And as you see below , it’s [Step#7 ] very slow and half of the slaves performing multi pass sort operation. Even though , it was estimated 35GB for that operation, why it’s estimating work area size of only 6-14MB only? Also, It’s allocating so low amount of PGA than expected. P_A_T was set to approx 11 GB. Currently this was the only query/operation on the Instance.
Why it’s not allocating more PGA for that operation? [My apologies for diverting from my original question ].
I have included PGA stats as well here which was taken 5-10 minutes later than other PQ session information. It’s still shows that there is no shortage of PGA.
Moreover, I have observed this behavior (under allocation of PGA) especially for WINDOWS SORT operations for other SQLs too. Is it normal behavior ? I’m on 10.2.0.4.
select
decode(px.qcinst_id,NULL,username,
' - '||lower(substr(pp.SERVER_NAME,
length(pp.SERVER_NAME)-4,4) ) )"Username",
decode(px.qcinst_id,NULL, 'QC', '(Slave)') "QC/Slave" ,
to_char( px.server_set) "SlaveSet",
to_char(s.sid) "SID",
to_char(px.inst_id) "Slave INST",
decode(sw.state,'WAITING', 'WAIT', 'NOT WAIT' ) as STATE,
case sw.state WHEN 'WAITING' THEN substr(sw.event,1,30) ELSE NULL end as wait_event ,
to_char(s.ROW_WAIT_OBJ#) wait_OBID,
decode(px.qcinst_id, NULL ,to_char(s.sid) ,px.qcsid) "QC SID",
to_char(px.qcinst_id) "QC INST",
px.req_degree "Req. DOP",
px.degree "Actual DOP"
from gv$px_session px,
gv$session s ,
gv$px_process pp,
gv$session_wait sw
where px.sid=s.sid (+)
and px.serial#=s.serial#(+)
and px.inst_id = s.inst_id(+)
and px.sid = pp.sid (+)
and px.serial#=pp.serial#(+)
and sw.sid = s.sid
and sw.inst_id = s.inst_id
order by
decode(px.QCINST_ID, NULL, px.INST_ID, px.QCINST_ID),
px.QCSID,
decode(px.SERVER_GROUP, NULL, 0, px.SERVER_GROUP),
px.SERVER_SET,
px.INST_ID
UNAME QC/Slave SlaveSet SID Slave INS STATE WAIT_EVENT WAIT_OBID QC SID QC INS Req. DOP Actual DOP
APPS_ORD QC 1936 2 WAIT PX Deq: Execute Reply 71031 1936
- p006 (Slave) 1 1731 2 WAIT PX Deq: Execution Msg 71021 1936 2 8 8
- p007 (Slave) 1 2159 2 WAIT PX Deq: Execution Msg 71021 1936 2 8 8
- p002 (Slave) 1 2090 2 WAIT PX Deq: Execution Msg 71021 1936 2 8 8
- p005 (Slave) 1 1965 2 WAIT PX Deq: Execution Msg 71021 1936 2 8 8
- p001 (Slave) 1 1934 2 WAIT PX Deq: Execution Msg 71021 1936 2 8 8
- p004 (Slave) 1 1843 2 WAIT PX Deq: Execution Msg 71021 1936 2 8 8
- p000 (Slave) 1 1778 2 WAIT PX Deq: Execution Msg 71021 1936 2 8 8
- p003 (Slave) 1 1751 2 WAIT PX Deq: Execution Msg 71021 1936 2 8 8
- p009 (Slave) 2 2138 2 NOT WAIT 71031 1936 2 8 8
- p012 (Slave) 2 1902 2 NOT WAIT 71031 1936 2 8 8
- p008 (Slave) 2 1921 2 NOT WAIT 71031 1936 2 8 8
- p013 (Slave) 2 2142 2 NOT WAIT 71031 1936 2 8 8
- p015 (Slave) 2 2091 2 NOT WAIT 71031 1936 2 8 8
- p014 (Slave) 2 2122 2 NOT WAIT 71031 1936 2 8 8
- p010 (Slave) 2 2146 2 NOT WAIT 71031 1936 2 8 8
- p011 (Slave) 2 1754 2 NOT WAIT 71031 1936 2 8 8
SELECT operation_type AS type ,
workarea_address WADDR,
operation_id as OP_ID,
policy ,
vwa.sql_id,
vwa.inst_id i#,
vwa.sid ,
vwa.qcsid QCsID,
vwa.QCINST_ID QC_I#,
s.username uname,
ROUND(active_time /1000000,2) AS a_sec ,
ROUND(work_area_size /1024/1024,2) AS wsize ,
ROUND(expected_size /1024/1024,2) AS exp ,
ROUND(actual_mem_used/1024/1024,2) AS act ,
ROUND(max_mem_used /1024/1024,2) AS MAX ,
number_passes AS p#,
ROUND(tempseg_size/1024/1024,2) AS temp
FROM gv$sql_workarea_active vwa ,
gv$session s
where vwa.sid = s.sid
and vwa.inst_id = s.inst_id
order by vwa.sql_id, operation_id, vwa.inst_id, username, vwa.qcsid
TYPE WADDR OP_ID POLI SQL_ID I# SID QCSID QC_I# UNAME A_SEC WSIZE EXP ACT MAX P# TEMP
WINDOW (SORT) 07000003D2B03F90 7 AUTO 8z5s5wdy94ty3 2 2146 1936 2 APPS_ORD 1181.22 13.59 13.59 7.46 90.98 1 320
WINDOW (SORT) 07000003D2B03F90 7 AUTO 8z5s5wdy94ty3 2142 1936 2 APPS_ORD 1181.07 7.03 7.03 4.02 90.98 0 288
WINDOW (SORT) 07000003D2B03F90 7 AUTO 8z5s5wdy94ty3 2091 1936 2 APPS_ORD 1181.06 7.03 7.03 4.5 90.98 0 288
WINDOW (SORT) 07000003D2B03F90 7 AUTO 8z5s5wdy94ty3 1921 1936 2 APPS_ORD 1181.09 13.59 13.59 2.24 90.98 1 320
WINDOW (SORT) 07000003D2B03F90 7 AUTO 8z5s5wdy94ty3 2138 1936 2 APPS_ORD 1181.16 7.03 7.03 1.34 90.98 0 288
WINDOW (SORT) 07000003D2B03F90 7 AUTO 8z5s5wdy94ty3 1754 1936 2 APPS_ORD 1181.09 14.06 14.06 5.77 90.98 1 320
WINDOW (SORT) 07000003D2B03F90 7 AUTO 8z5s5wdy94ty3 2122 1936 2 APPS_ORD 1181.15 6.56 6.56 .24 90.98 0 288
WINDOW (SORT) 07000003D2B03F90 7 AUTO 8z5s5wdy94ty3 1902 1936 2 APPS_ORD 1181.12 14.06 14.06 9.12 90.98 1 320
HASH-JOIN 07000003D2B03F28 8 AUTO 8z5s5wdy94ty3 2142 1936 2 APPS_ORD 1183.24 98.64 98.64 100.44 100.44 0
HASH-JOIN 07000003D2B03F28 8 AUTO 8z5s5wdy94ty3 2138 1936 2 APPS_ORD 1183.24 98.64 98.64 100.44 100.44 0
HASH-JOIN 07000003D2B03F28 8 AUTO 8z5s5wdy94ty3 2122 1936 2 APPS_ORD 1183.24 98.64 98.64 100.44 100.44 0
HASH-JOIN 07000003D2B03F28 8 AUTO 8z5s5wdy94ty3 2091 1936 2 APPS_ORD 1183.24 98.64 98.64 100.44 100.44 0
HASH-JOIN 07000003D2B03F28 8 AUTO 8z5s5wdy94ty3 1921 1936 2 APPS_ORD 1183.24 98.64 98.64 100.44 100.44 0
HASH-JOIN 07000003D2B03F28 8 AUTO 8z5s5wdy94ty3 1902 1936 2 APPS_ORD 1183.24 98.64 98.64 100.44 100.44 0
HASH-JOIN 07000003D2B03F28 8 AUTO 8z5s5wdy94ty3 2146 1936 2 APPS_ORD 1183.24 98.64 98.64 100.44 100.44 0
HASH-JOIN 07000003D2B03F28 8 AUTO 8z5s5wdy94ty3 1754 1936 2 APPS_ORD 1183.24 98.64 98.64 100.44 100.44 0
sum 872.07 838.21
PGA Stats – taken 5-10 minutes later than above.
select name, decode(unit,'bytes',round(value/1048576,2)||' MB', value) value from v$pgastat
NAME VALUE
aggregate PGA target parameter 11264 MB
aggregate PGA auto target 9554.7 MB
global memory bound 1024 MB
total PGA inuse 902.21 MB
total PGA allocated 3449.64 MB
maximum PGA allocated 29155.44 MB
total freeable PGA memory 2140.56 MB
process count 107
max processes count 379
PGA memory freed back to OS 77240169.56 MB
total PGA used for auto workareas 254.14 MB
maximum PGA used for auto workareas 22797.02 MB
total PGA used for manual workareas 0 MB
maximum PGA used for manual workareas 16.41 MB
over allocation count 0
bytes processed 323796668.77 MB
extra bytes read/written 183362312.02 MB
cache hit percentage 63.84
recompute count (total) 2054320
SELECT
PGA_TARGET_FOR_ESTIMATE/1048576 ESTMTD_PGA_MB,
PGA_TARGET_FACTOR PGA_TGT_FCTR,
ADVICE_STATUS ADV_STS,
BYTES_PROCESSED/1048576 ESTMTD_MB_PRCD,
ESTD_EXTRA_BYTES_RW/1048576 ESTMTD_XTRA_MB,
ESTD_PGA_CACHE_HIT_PERCENTAGE ESTMTD_CHIT_PCT,
ESTD_OVERALLOC_COUNT O_ALOC_CNT
FROM V$PGA_TARGET_ADVICE
ESTMTD_PGA_MB PGA_TGT_FCTR ADV ESTMTD_MB_PRCD ESTMTD_XTRA_MB ESTMTD_CHIT_PCT O_ALOC_CNT
1,408 .125 ON 362,905,053 774,927,577 32 19973
2,816 .25 ON 362,905,053 571,453,995 39 709
5,632 .5 ON 362,905,053 249,201,001 59 5
8,448 .75 ON 362,905,053 216,717,381 63 0
11,264 1 ON 362,905,053 158,762,256 70 0
13,517 1.2 ON 362,905,053 153,025,642 70 0
15,770 1.4 ON 362,905,053 153,022,337 70 0
18,022 1.6 ON 362,905,053 153,022,337 70 0
20,275 1.8 ON 362,905,053 153,022,337 70 0
22,528 2 ON 362,905,053 153,022,337 70 0
33,792 3 ON 362,905,053 153,022,337 70 0
45,056 4 ON 362,905,053 153,022,337 70 0
67,584 6 ON 362,905,053 153,022,337 70 0
90,112 8 ON 362,905,053 153,022,337 70 0 -
Hi Everyone,
Am aware of the following flavors of MAX function
1) choose MAX from the folders/fields list (selected items tab)
2) create calculation using: MAX keep dense
3) create calculation using: MAX analytic function
questions, pls:
===========
a) with MAX regular, MAX keep dense, MAX - analytic function
is it necessary to sort it using tools/sort - choose fields to sort by?
or does the data get sorted due to the ORDER BY clause in MAX used in a calculation
b) how to understand the diff. bet. MAX keep dense and MAX - analytic function
1) i understand that analytic functions are applied after detail row processing
does MAX keep dense calculation happen during detail row processing?
2) how did you know to advise when to use MAX keep dense, and when to use MAX - analytic function?
tx for your ideas and assistance, sandraHi,
a) with MAX regular, MAX keep dense, MAX - analytic function is it necessary to sort it using tools/sort - choose fields to sort by? or does the data get sorted due to the ORDER BY clause in MAX used in a calculationIt is only necessary to use a sort if you want to have the rows returned in a specific order. The order by in the max calculation defines the maximum within the group or window. It may affect the order the rows are returned, but if it does this is not guaranteed and you should use a sort on the main query.
b) how to understand the diff. bet. MAX keep dense and MAX - analytic function
1) i understand that analytic functions are applied after detail row processing does MAX keep dense calculation happen during detail row processing?Yes
2) how did you know to advise when to use MAX keep dense, and when to use MAX - analytic function?In general, if you want the result on a single row, so you have one row for each group then you should use the aggregate max. If you want to use the same max on all the rows in the window (defined by the partition) then use the analytic max.
Rod West -
Regarding MAX() function
Hi,
I am having table A. I have few records in the table A. Database version : 9.2
ID name deleted
2 XYZ N
3 ABD N
4 GJK N
5 GJK N
6 HGY N
7 YJG N
8 PIN N
9 BMF N
10 OLG N
I used the following query...
SELECT MAX(ID) FROM A WHERE DELETED='N';
It was worked fine until now....
Now i used the same query...
But the result is
MAX(ID)
9
Please help me... What is the reason?
I want the correct result...
Thanks in advance....Kamran Agayev A. wrote:
Yes you can use TO_NUMBER inside MAX function and it will not give any error in the futureHave you tested it?
SQL> create table a (id,name,deleted)
2 as
3 select '2', 'XYZ', 'N' from dual union all
4 select '3', 'ABD', 'N' from dual union all
5 select '4', 'GJK', 'N' from dual union all
6 select '5', 'GJK', 'N' from dual union all
7 select '6', 'HGY', 'N' from dual union all
8 select '7', 'YJG', 'N' from dual union all
9 select '8', 'PIN', 'N' from dual union all
10 select '9', 'BMF', 'N' from dual union all
11 select '10', 'OLG', 'N' from dual
12 /
Tabel is aangemaakt.
SQL> select max(id)
2 from a
3 where deleted = 'N'
4 /
MA
9
1 rij is geselecteerd.
SQL> select max(to_number(id))
2 from a
3 where deleted = 'N'
4 /
MAX(TO_NUMBER(ID))
10
1 rij is geselecteerd.
SQL> insert into a values ('2A', 'ABC', 'N')
2 /
1 rij is aangemaakt.
SQL> select max(to_number(id))
2 from a
3 where deleted = 'N'
4 /
select max(to_number(id))
FOUT in regel 1:
.ORA-01722: invalid numberRegards,
Rob. -
Setting to prevent "Function will be started in new session"
Hi all,
I'm focusing following problem / request.
User A is doubleclicking on a Inforecord number inside a puchase order position (ME23N). Now SAP is showing message MEPO014 (Function will be started in new session) and displaying master data of this inforecord in a new "window" (ME13). If the user has already 6 sessions open, he will get a error message "max. sessions ...!". So far so well.
Now the problem:
User B is doing the same, having already 6 sessions open and ME13 will be displayed in same session (window) where he doubleclicked the inforrecord (ME23N).
question:
is there a setting where i can influence the "new session" behaviour of SAP Gui?
plea:
do not post hints like "have you checked User parameters" etc. --- of course i have
If you can simulate what i described on your system you're my "expert"
kind regards
Jörg
26/01/2011
help? anyone ?
Edited by: Jörg Sauterleute on Jan 26, 2011 10:53 PMHi Jorg,
Have you checked the following setting?
ME23N-Personal SettingsBasic settings Tab-Envir.info in new session.
Please remove the check mark and save.
Hope it helps. -
How to use MAX() function with date field
Hi Frzz,
I have created a Graphical calculation view in which i have multiple records for each employee with different dates. But my requirement is to take the records which have maximum date.
I have converted the date into Integer and applied the MAX() function. But still am getting multiple records.
Is there is any other way we can achieve this requirement in Graphical Calculation view?? Your suggestion will really help me.
Thank you.
Krishna.Hmm... what have you tried out so far?
Look, I took the effort and created a little example, just for you
Assume we have a table that contains the logon dates of users.
Every line contains the logon date and some info on the user.
Very much like a not-normalized log file could look like.
Now, the output we want is: one line per user with the most current logon time.
Not too difficult:
1. Have a aggregation node that gives you the distinct user details - one line for every user:
2. Have another aggregation node that gives you the last (MAX) logon date per user:
Finally you do a 1:1 join on the USER_ID and map the result to the output.
Easy as pie
- Lars -
Is it possible to use extension functions in the select attribute of xsl:sort? This way I could sort the nodes based on a computed value.
e.g. <xsl:sort select="myns:myextfunc(ELEM1, ELEM2)">
I tried using a standard XSL function like
<xsl:sort select="concat(ELEM1, ELEM2)"/> and it seems to work but when I try to use an extension function it fails.
TIA
nullWith XML Parser 9.0.1 Production, this works for me:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ext="http://www.oracle.com/XSL/Transform/java/Ext">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:for-each select="/Employees/Emp">
<!--
| Due to a bug, need to declare the extension namespace on
| the <xsl:sort> element itself.
+-->
<xsl:sort data-type="number" order="descending" select="ext:max(Salary,Bonus)"
xmlns:ext="http://www.oracle.com/XSL/Transform/java/Ext"/>
<xsl:value-of select="Name"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
public class Ext
public static double max( double n, double m ) {
return n > m ? n : m;
<Employees>
<Emp>
<Name>B</Name>
<Salary>10</Salary>
<Bonus>12</Bonus>
</Emp>
<Emp>
<Name>C</Name>
<Salary>25</Salary>
<Bonus>12</Bonus>
</Emp>
<Emp>
<Name>A</Name>
<Salary>10</Salary>
<Bonus>2</Bonus>
</Emp>
</Employees>If I make sure Ext.class is in my CLASSPATH, and transform the above XML by the above stylesheet, I get:
CBA
which is the reverse-numerically-sorted list of max() calculations. -
Hotspot-clicking (Insert function) plus ALV Sorting
Hi,
I have a requirement where the ALV display has to be SORTED based on values entered/changed on a certain column. The sort works ok when used with a custom APPEND button for new records (always inserted at the bottom of the list).
However, it does not work correctly when used with the Hotspot-click (INSERT functionality). It looks like if you CLICK on a particular record onscreen, you are actually addressing the original record in that position before the SORT was effected.
Is the Hotspot-clicking (Insert functionality) possible with ALV sorting? The ideal solution would be to have the ALV sorted at PBO and also at PAI so that the user can change existing records and add new ones with the sorting being updated everytime ON_DATA_CHANGED is triggered.
Will appreciate any help on this.
Thanks!
MichaelHello Michael
Thanks for further specifying your requirements. I have created the sample variant ZUS_SDN_ALVGRID_HOTSPOT_SORT_1 which contains two differences as compared to its template:
Replace table VBAK with VBAP (so we have two levels of sorting: VBELN, POSNR)
Move SET_TABLE_FOR_FIRST_DISPLAY method call into PBO
When I click on the hotspot (VBELN) a new row entry for the order number is created. The sorting (VBELN, POSNR) is kept even though the new row has been appended to the itab.
*& Report ZUS_SDN_ALVGRID_HOTSPOT_SORT
*& Thread: Hotspot-clicking (Insert function) plus ALV Sorting
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1159431"></a>
REPORT zus_sdn_alvgrid_hotspot_sort.
TYPES: BEGIN OF ty_s_outtab.
INCLUDE TYPE vbap.
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab TYPE STANDARD TABLE OF ty_s_outtab
WITH DEFAULT KEY.
DATA: gt_outtab TYPE ty_t_outtab.
DATA:
gd_okcode TYPE ui_func,
gd_repid TYPE syrepid,
gt_sort TYPE lvc_t_sort,
gt_fcat TYPE lvc_t_fcat,
gs_layout TYPE lvc_s_layo,
gs_variant TYPE disvariant,
go_docking TYPE REF TO cl_gui_docking_container,
go_grid TYPE REF TO cl_gui_alv_grid.
* CLASS lcl_eventhandler DEFINITION
CLASS lcl_eventhandler DEFINITION.
PUBLIC SECTION.
CLASS-DATA:
ms_sel_row TYPE lvc_s_row. " selected row
CLASS-METHODS:
handle_data_changed FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING
er_data_changed
e_onf4
e_onf4_before
e_onf4_after
sender,
handle_hotspot_click FOR EVENT hotspot_click OF cl_gui_alv_grid
IMPORTING
e_row_id
e_column_id
es_row_no
sender.
ENDCLASS. "lcl_eventhandler DEFINITION
* CLASS lcl_eventhandler IMPLEMENTATION
CLASS lcl_eventhandler IMPLEMENTATION.
METHOD handle_data_changed.
FIELD-SYMBOLS: <lt_outtab> TYPE ty_t_outtab.
BREAK-POINT.
ENDMETHOD. "handle_data_changed
METHOD handle_hotspot_click.
" define local data
DATA: ls_outtab TYPE ty_s_outtab,
ld_msg TYPE bapi_msg.
BREAK-POINT.
CLEAR: lcl_eventhandler=>ms_sel_row.
ms_sel_row = e_row_id.
READ TABLE gt_outtab INTO ls_outtab INDEX e_row_id-index.
CONCATENATE 'Selected Sales Order = ' ls_outtab-vbeln ' / '
ls_outtab-posnr
INTO ld_msg.
message i398(00) with ld_msg.
" Trigger PAI
CALL METHOD cl_gui_cfw=>set_new_ok_code
EXPORTING
new_code = 'INSERT'
* IMPORTING
* rc =
ENDMETHOD. "handle_hotspot_click
ENDCLASS. "lcl_eventhandler IMPLEMENTATION
PARAMETERS:
p_vkorg TYPE vkorg DEFAULT '0001' OBLIGATORY.
START-OF-SELECTION.
** SELECT * FROM vbak INTO CORRESPONDING FIELDS OF TABLE gt_outtab
** UP TO 200 ROWS
** WHERE vkorg = p_vkorg.
SELECT * FROM vbap INTO CORRESPONDING FIELDS OF TABLE gt_outtab
UP TO 100 ROWS.
PERFORM init_controls.
* Build fieldcatalog and set hotspot for field KUNNR
PERFORM build_fieldcatalog.
PERFORM set_layout_and_variant.
PERFORM set_sorting.
" Register EDIT event
CALL METHOD go_grid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter
EXCEPTIONS
error = 1
OTHERS = 2.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
SET HANDLER:
lcl_eventhandler=>handle_data_changed FOR go_grid,
lcl_eventhandler=>handle_hotspot_click FOR go_grid.
* Link the docking container to the target dynpro
gd_repid = syst-repid.
CALL METHOD go_docking->link
EXPORTING
repid = gd_repid
dynnr = '0100'
* CONTAINER =
EXCEPTIONS
OTHERS = 4.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* ok-code field = GD_OKCODE
CALL SCREEN '0100'.
END-OF-SELECTION.
*& Module STATUS_0100 OUTPUT
* text
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS_0100'.
* SET TITLEBAR 'xxx'.
* Display data
CALL METHOD go_grid->set_table_for_first_display
EXPORTING
i_bypassing_buffer = abap_true
is_variant = gs_variant
i_save = 'A'
* i_default = 'X'
is_layout = gs_layout
* is_print =
* it_special_groups =
* it_toolbar_excluding =
* it_hyperlink =
* it_alv_graphics =
* it_except_qinfo =
* ir_salv_adapter =
CHANGING
it_outtab = gt_outtab
it_fieldcatalog = gt_fcat
it_sort = gt_sort
* it_filter =
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
** CALL METHOD go_grid->refresh_table_display
*** EXPORTING
*** IS_STABLE =
*** I_SOFT_REFRESH =
** EXCEPTIONS
** finished = 1
** OTHERS = 2.
** IF sy-subrc ne 0.
*** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*** WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
** ENDIF.
ENDMODULE. " STATUS_0100 OUTPUT
*& Module USER_COMMAND_0100 INPUT
* text
MODULE user_command_0100 INPUT.
CASE gd_okcode.
WHEN 'BACK' OR
'EXIT' OR
'CANC'.
SET SCREEN 0. LEAVE SCREEN.
WHEN 'INSERT'.
PERFORM insert_row.
WHEN OTHERS.
" Check for changed data at the frontend (= grid control)
CALL METHOD go_grid->check_changed_data( ).
ENDCASE.
CALL METHOD go_grid->refresh_table_display
* EXPORTING
* IS_STABLE =
* I_SOFT_REFRESH =
EXCEPTIONS
finished = 1
OTHERS = 2.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CLEAR: gd_okcode.
ENDMODULE. " USER_COMMAND_0100 INPUT
*& Form INIT_CONTROLS
* text
* --> p1 text
* <-- p2 text
FORM init_controls .
* Create docking container
CREATE OBJECT go_docking
EXPORTING
parent = cl_gui_container=>screen0
ratio = 90
EXCEPTIONS
others = 6.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL METHOD go_docking->set_extension
EXPORTING
extension = 99999
EXCEPTIONS
cntl_error = 1
OTHERS = 2.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* Create ALV grid
CREATE OBJECT go_grid
EXPORTING
i_parent = go_docking
EXCEPTIONS
others = 5.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " INIT_CONTROLS
*& Form BUILD_FIELDCATALOG
* text
* --> p1 text
* <-- p2 text
FORM build_fieldcatalog.
* define local data
DATA:
ls_fcat TYPE lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
* I_BUFFER_ACTIVE =
i_structure_name = 'VBAP' " 'VBAK'
* I_CLIENT_NEVER_DISPLAY = 'X'
* I_BYPASSING_BUFFER =
* I_INTERNAL_TABNAME =
CHANGING
ct_fieldcat = gt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
** LOOP AT gt_fcat INTO ls_fcat.
** CASE ls_fcat-fieldname.
** WHEN 'VBELN' OR
** 'ERDAT' OR
** 'ERZET' OR
** 'ERNAM' OR
** 'AUART' OR
** 'NETWR' OR
** 'WAERK'.
** CONTINUE.
** WHEN OTHERS.
** ls_fcat-no_out = abap_true.
** ENDCASE.
** MODIFY gt_fcat FROM ls_fcat INDEX syst-tabix.
** ENDLOOP.
* Only non-key fields are editable
** ls_fcat-edit = 'X'.
** MODIFY gt_fcat FROM ls_fcat
** TRANSPORTING edit
** WHERE ( fieldname NE space ).
ls_fcat-hotspot = abap_true.
MODIFY gt_fcat FROM ls_fcat
TRANSPORTING hotspot
WHERE ( fieldname = 'AUART' OR
fieldname = 'VBELN' ).
** DELETE gt_fcat FROM 15 TO 99.
ENDFORM. " BUILD_FIELDCATALOG_KNB1
*& Form SET_LAYOUT_AND_VARIANT
* text
* --> p1 text
* <-- p2 text
FORM set_layout_and_variant .
CLEAR: gs_layout,
gs_variant.
gs_layout-cwidth_opt = abap_true.
gs_variant-report = syst-repid.
gs_variant-handle = 'GRID'.
ENDFORM. " SET_LAYOUT_AND_VARIANT
*& Form SET_SORTING
* text
* --> p1 text
* <-- p2 text
FORM set_sorting .
* define local data
DATA: ls_sort TYPE lvc_s_sort.
REFRESH: gt_sort.
CLEAR: ls_sort.
ls_sort-spos = 1.
ls_sort-fieldname = 'VBELN'.
ls_sort-up = abap_true.
APPEND ls_sort TO gt_sort.
CLEAR: ls_sort.
ls_sort-spos = 1.
ls_sort-fieldname = 'POSNR'.
ls_sort-up = abap_true.
APPEND ls_sort TO gt_sort.
ENDFORM. " SET_SORTING
*& Form INSERT_ROW
* text
* --> p1 text
* <-- p2 text
FORM insert_row .
* define local data
DATA: ls_outtab TYPE ty_s_outtab,
ld_order TYPE vbeln.
READ TABLE gt_outtab INTO ls_outtab
INDEX lcl_eventhandler=>ms_sel_row-index.
ld_order = ls_outtab-vbeln.
" Find last item of sales order
LOOP AT gt_outtab INTO ls_outtab
WHERE ( vbeln = ld_order ).
ENDLOOP.
" Create next item:
add 10 to ls_outtab-posnr.
" NOTE: added at the end of the list
APPEND ls_outtab TO gt_outtab.
" NOTE: insert new row AFTER selected row => works, too
** INSERT ls_outtab INTO gt_outtab
** INDEX lcl_eventhandler=>ms_sel_row-index.
ENDFORM. " INSERT_ROW -
Buffer(sort) operator
Hi,
i'm trying to understand what "buffer sort" operation is in the following explain plan:
0 SELECT STATEMENT
-1 MERGE JOIN CARTESIAN
--2 TABLE ACCESS FULL PLAYS
--3 BUFFER SORT
---4 TABLE ACCESS FULL MOVIE
In Oracle 9i DataBase Performance Guide and Reference, "buffer sort" is not mentioned although all other explain plan's operations are.
What does it mean? Does it take place in main memory or is it an external sort?
Thank you.A BUFFER SORT typically means that Oracle reads data blocks into private memory,because the block will be accessed multiple times in the context of the SQL statement execution. in other words, Oracle sacrifies some extra memory to
reduce the overhead of accessing blocks multiple times in shared memory.
Hope this will clear your doubts.
Thanks. -
Reorganize function will not allow "select rows that match"
I'm trying to sort data in a sheet the same way excel lets you sort by using "filter"
I'm told that using the Reorganize function will allow me to do this especially if I select the "select rows that match" options.
The only problem is that that options is grayed out and I can't use it.
Anybody else have any suggestions or instructions>?
ThanksMake sure you have selected a table
-
Using Max Function in View Criteria
Hi
I am having a requirement where by i need to make use of max function in view criteria but not able to see any such option. Can someone please help me over it. Here is the requirement.
In table i will be having multiple rows for an employee and i need to pick latest row based on a column say request_id For e.g.
Emp RequestId
A 1
A 2
A 3
A 4
So if i pass the employee id i should get Row Number 4. In simple SQL language I want something like this
select * from emp where empid=A and requestid=( select max(requestid) from emp where empid=A)
Just wanted to know is there any approach that i can use to do all this as part of View Criteria or any other way.
Any help is appreciated!!!
Thanks
AJOne way is this -
1)https://blogs.oracle.com/adf/entry/using_groovy_aggregate_functions_in (You might need to create a self-referencing VL for this , try if it works using a ViewAccessor too)
OR
Order by RequestId descending in your SQL for the VO if thats ok , then have the ViewCriteria for the EmpId and programmatically pickup the first row... -
I have the following tables along with their attributes(the
stared fields show the primary key:
Agent(AgentPhoneNo*, NameOfAgent)
Constituency(ConstituencyNo*,
ConstituencyName,District,RegionCode)
PollingStation(StationNo*,ConstituencyNo*,AgentPhoneNo,
StationName)
VoteResults(Party*, ResultsCategory*,Votes, AgentPhoneNo*)
Results category has two values (S,L) and the number of
parties is variable
My issue is this, below is my code that returns the total
votes received by each party with each constituency. This
query works fine.
<cfquery name="WinningPartyinConstituency"
datasource="#request.datasource#">
SELECT c.ConstituencyName, s.ConstituencyNo, v.Party,
Sum(v.Votes) AS TotalVotes
From (Constituency c
INNER JOIN PollingStation s ON c.ConstituencyNo =
s.ConstituencyNo)
INNER JOIN VoteResults v ON s.AgentPhoneNo = v.AgentPhoneNo
WHERE v.ResultCategory = 'L' AND s.ConstituencyNo IN (Select
ConstituencyNo From Constituency)
Group By c.ConstituencyName, s.ConstituencyNo, v.Party
Order By c.ConstituencyName
</cfquery>
Now I want to check and return the name and total votes of
the party with the maximum votes within each constituency. And but
I can't seem to figure out how to do that, especially because the
max() function takes only to
values.
I will appreciate any guidance on how to write a query that
returns the the party with the maximum votes in each constituency
and the votes it got. TIAMy approach would be to do 2 or 3 Q of Qs to get the numbers
I need. -
Improve built in SQL MAX function
Hi
I am trying to improve the performance of the built in SQL max function. right now searching through over 500,000 rows takes lot of time which can be reduced. Can anyone suggest me something which would be helpful in this or may be give me a link if it has been discussed before?
Anything is appreciated.
ThanksTolls wrote:
Um...considering you were planning on improving on the MAX function, I sort of thought you might actually know how to use it. Otherwise how would you know it was running slowly?thanks Tolls i'd figured it out right after i posted it. i guess i was too excited after reading (you got it in milliseconds) that posted right away without doing anything myself..but yeah it did make it super fast..thanks a lot for your help and time..
cotton.m wrote:
d_khakh wrote:
hi tolls thanks for getting back
could u explain how did u do that? i found out how to create index..i have the following statement:
create index col on table2 (col2);
cud u tell me how to go from here and find the max in col2..thanks again for ur help?
sigh
Where to go from here? Just execute your damn query. If you really did create the index on the right column and your database isn't stupid and there isn't a lot more to this problem then you told us about like some where clauses then that's it. She's as fast as she's going to get.
And remember, it's impolite to converse in a public forum while chewing your cud. Unless of course you actually meant "could" but were just too lazy to type it. Don't be lazy, use full words. Thanks.like i said above..i figured it out after some time.
i wasn't being lazy ..thats msn talk..i thought people understood that..anyways your point noted too. -
Can I use Count, Max function in PLSQL BLOCK.
Can U help me to use count, max function in PLSQL BLOCK.
Because it is giving me error "It is a SQL function"SELECT COUNT(*)
INTO l_variable
FROM dual;
Will work inside PL/SQL
Maybe you are looking for
-
500 Internal error observed while accessing a Static Web based course
Hi Experts When I try to start a static web-based course in portal, a 500 Internal server error comes up on the screen and the course not played at all. Please suggest. Regards Shaily
-
Black screen with "Insert boot disk"
Hi, there everyone! So here's the epilogue to my story. I wanted to install Windows 7 on my late 2011 MBP running Lion. Went to Bootcamp to get the process done, as I get there I see that I'm lacking the option to make a start up disk on a usb, so I
-
TS2771 reset my ipod touch and it wont turn on
??????????????
-
I need info about CL_XML_DOCUMENT
Hi to all, I need info about the class CL_XML_DOCUMENT and his methods. I only have seen information of a few methods. Where can I find more information and examples of use about this class?
-
Questionnaire for rollout project
Hi, I need to prepare SD questionnaire for roll out project. Please help me regarding this. urgent. Regards Prabudh