Combine two select query
Hi All,
Many thanks for all kind support so far.
I have two report (sql query)
I want to add both the sql query
1st sql query
select distinct(a.item_number)
,a.quantity - b.quantity
from QUANTITY_ONHAND_ATP a,BACKLOG_ATP_LT_CW b
where a.item_number = b.item_number
order by item_number2nd sql query
select distinct(wb.item_number)
,wb.quantity - be.quantity
,a.quantity - b.quantity
from BACKLOG_WEEK_BEFORE_ATP wb
,BACKLOG_ATP_ET_CW be
,BACKLOG_WEEK_AFTER_ATP a
,BACKLOG_ATP_GT_CW b
where wb.item_number = be.item_number
and a.item_number = b.item_number
and wb.item_number = a.item_number
and be.item_number = a.item_number
and wb.item_number = b.item_number
and be.item_number = b.item_number
order by wb.ITEM_NUMBERIn 1st sql query i have 129 records and in 2nd sql query i have 14 records. I want to combine these two sql query. If the item_number of 1st sql query is not there in 2nd one then display it as it is in 1st sql only.
Any help how to do that.
Regards
Hi,
the gerenal approach to combine the results of two or more SQL queries would be the
UNION / UNION ALL
INTERSECT
MINUS
SQL clauses. Union just combines the results; INTERSECT will return the rows which are present
in both result sets and MINUS will reduce the first result set by the rows of the second.
Basically it works like this
select * from emp where deptno = 10
union all(
select * from empo where deptno = 20
All the queries must have identical columns in the result set - same number of columns
and the same data types. So you would have to add a column to your first SQL query ...
select distinct(a.item_number) item_number,
to_number(*,null*) first_value
,a.quantity - b.quantity second_value
from QUANTITY_ONHAND_ATP a,BACKLOG_ATP_LT_CW b
where a.item_number = b.item_number
order by item_number
and in the second query I'd recommend to use the same aliases ....
Does this help
-Carsten
Deutschsprachige APEX-Community: Tipps, Tricks, Best Practice
http://tinyurl.com/apexcommunity
SQL und PL/SQL: Tipps, Tricks & Best Practice
http://sql-plsql-de.blogspot.com
Twitter: @cczarski
Similar Messages
-
Combine two select statements in one SQL statements
I have the following two queries that I need to combine into one query, where it updates a single row at the same time.
SELECT count(*) FROM database.USAGE WHERE SERVICE_TYPE = 'C' AND ACCOUNT = "4837"
SELECT sum(minutes) FROM database.USAGE WHERE SERVICE_TYPE = 'DA' AND ACCOUNT = "4837"
I want to insert the values of each select statement into two columns of the same row, as well as insert the account number from the select statement.
After the query has been executed, the database row will look like this:
ACCOUNT COUNT SUM
4837 354 1039202
I am looking for suggestions on how to:
- either combine the two into one query
- simply update each column with the value from each query by updating the row with the account value
I am a SQL newbie - so I appreciate any assistance.
Thanks,
TonyHi, Tony,
When you're talking about changing the data in tables, "INSERT" means to add a new row, and you'll cause a lot of confusion if you use it to mean something else. So don't say
"I want to insert the values of each select statement into two columns..."; use some other word, like:
"I want to put the values of each select statement into two columns ..."
If you happened to know that those two numbers were 354 and 1039202, you might say:
UPDATE table_x
SET a_count = 354
, a_sum = 1039202
WHERE account = 4837;But you don't know the numbers; you want to have the query figure out what they are.
In most places where you can use a literal (like 354 or 1039202), you can also use a scalar sub-query, a SELECT statement, enclosed in parentheses, that produces one column and (at most) one row.
In your case, you can say:
UPDATE table_x
SET a_count = (SELECT count(*) FROM database.USAGE WHERE SERVICE_TYPE = 'C' AND ACCOUNT = 4837)
, a_sum = (SELECT sum(minutes) FROM database.USAGE WHERE SERVICE_TYPE = 'DA' AND ACCOUNT = 4837
WHERE account = 4837;or, to make it more readable:
UPDATE table_x
SET a_count =
( SELECT count (*)
FROM database.USAGE
WHERE SERVICE_TYPE = 'C'
AND ACCOUNT = 4837
, a_sum =
( SELECT sum (minutes)
FROM database.USAGE
WHERE SERVICE_TYPE = 'DA'
AND ACCOUNT = 4837
WHERE account = 4837;By the way, why are you using double-quotes around 4837? If it's a string, enclose it in single quotes. If it's a number (which I'm assuming in my code), don't enclose it in anything.
WARNING: scalar sub-queries are somewhat like duct tape: they're extremely useful in certain places, and those places account for about 1% of their use. The other 99% of the time, there's a better way to do things, though the better way may require more expertise. -
Two select query in sender JDBC adaptor
Hi
We are doing JDFC-RFC scenario, in which i need to fetch the data from two tables (header and item table) whch correspondes to the 2 table parameter of RFC .
Any clues how to configure sender jdbc CC having 2 select query ??????
Regards
VijaySwatantra,
You can have a look at the below URL for more info on JOIN.
http://www.w3schools.com/sql/sql_join.asp
Best regards,
raj. -
Hi ABAPers,
Can you please tell me how to concatenate this two select qureies.
select ebeln knumv from ekko INTO
TABLE tt_knumv
where ebeln = p_ebeln.
select ebeln knumv from eslh INTO TABLE
tt_knumv FOR ALL ENTRIES IN tt_esll
where packno = tt_esll-sub_packno.
Regards
Abhinab MishraHi,
I dont think inner join is possible in this case since you are selecting the same fields from the two different tables into the single internal table vertically. It can be used to collect the data into the internal table horizontally but that would make no sense in this case. May be you can try something like this
data: t_temp type table of tt_knumv.
select ebeln knumv
from eslh
INTO TABLE tt_knumv
FOR ALL ENTRIES IN tt_esll
where packno = tt_esll-sub_packno.
select ebeln knumv
from ekko
INTO TABLE t_temp
where ebeln = p_ebeln.
loop at t_temp.
move-corresponding t_temp to tt_knumv.
append tt_knumv.
endloop.
Regards,
Vik -
How to combine my select query
Hi guys,
I want to check record is exist in the test_table with where condition is different.
if found then
check test_table with where condition is different.
if found then
check test_table with where condition is different.
can any one give me suggestion.
thanks.Hi,
Your code...
select * from test_table where col1 = condition1 and col4 = condition5; -----SELECT 1
if record found
select * from test_table where col2 = condition2 and col6 = condition6; -----SELECT 2
if record found
select * from test_table where col2 = condition3 and col3 = condition4; -----SELECT 3I hope the following code should give you the expected results....
SELECT *
FROM test_table
WHERE col2 = condition3
AND col3 = condition4
AND col2 = condition2
AND col6 = condition6
AND col1 = condition1
AND col4 = condition5Regards,
Rakesh -
Combine two resultset sidebyside in coulmn using mdx
hi i am new to mdx,
i want to combine two select statement resultset (side by side like union) using mdx query,please any body help me to solve this query
first query:
SELECT
{ [Last Year] }
ON COLUMNS,
{ {[Location].[Location].&[7], [Location].[Location].&[12], [Location].[Location].&[11],
[Location].[Location].&[19], [Location].[Location].&[17], [Location].[Location].&[16],
[Location].[Location].&[9], [Location].[Location].&[18] },{[Location].[Location].[All]}}
ON ROWS
FROM [Cube1]
WHERE ( [Measures].[Labour %] )
here [Last Year] is a calculated set
{STRTOMEMBER("[Date].[Month].&["+ cstr(year(now())-2) +"-11-01T00:00:00]"):
(STRTOMEMBER("[Date].[Month].&["+ cstr(year(now())-1) +"-10-01T00:00:00]"))}
2nd query:
WITH MEMBER [Measures].[Budget ] AS IIF(avg([Last Year],IIF(([Measures].[Budget]>0),[Measures].[Budget],null)),
avg([Last Year],IIF(([Measures].[Budget]>0),[Measures].[Budget],null)),0.00),
MEMBER [Measures].[YTD] AS IIF(avg([Last Year], IIF(([Measures].[Labour %]>0),[Measures].[Labour %],null))<>null,
avg([Last Year], IIF(([Measures].[Labour %]>0),[Measures].[Labour %],null)),0.00),
FORMAT_STRING = "Standard",
BACK_COLOR = CASE WHEN [YTD] = 0 THEN /*White*/16777215 /*White*/
WHEN [YTD] <= [Measures].[Budget ] THEN 65408
WHEN [YTD]<= [Measures].[Budget ] +5 THEN 65535
WHEN [YTD]> [Measures].[Budget ] +5 THEN 255
END,
VISIBLE = 1
SELECT
{ [Measures].[YTD], [Measures].[Budget ] }
ON COLUMNS,
{ { [Location].[Location].&[7], [Location].[Location].&[12], [Location].[Location].&[11], [Location].[Location].&[19], [Location].[Location].&[17], [Location].[Location].&[16], [Location].[Location].&[9], [Location].[Location].&[18]
},{[Location].[Location].[All]} }
ON ROWS
FROM [Cube1]
here ==> [Measures].[YTD], [Measures].[Budget ] are calculated member
i want result like in
coulmns===> ytd,budget,nov,dec,jan,feb.,,,,,,,,,,out
rows ====> are only locations and total(average of all locations)
please guide me to get solution like mdx queryHi Vsp,
According to your description, you want to create a calculated member to combine two members, and then set it as Default member, right?
In SQL Server Analysis Services, we can use the script below to create a calculated members.
create member currentcube.[Date].[Day of Week].[weekend]
as
{[Date].[Day of Week].&[6],[Date].[Day of Week].&[7]
Every attribute in a dimension in Microsoft SQL Server Analysis Services has a default member, which you can specify by using the
DefaultMember property for an attribute. This setting is used to evaluate expressions if an attribute is not included in a query. Please refer to the link below to see the detail information about specify a default member.
http://technet.microsoft.com/en-us/library/ms174822(v=sql.105).aspx
Regards,
Charlie Liao
TechNet Community Support -
How can i use index in select query.. facing problem with the select query.
Hi Friends,
I am facing a serious problem in one of the select query. It is taking a lot of time to fetch data in Production Scenario.
Here is the query:
SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
FROM ztftelat LEFT JOIN ztfzberep
ON ztfzberep~gjahr = st_input-gjahr
AND ztfzberep~poper = st_input-poper
AND ztfzberepcntr = ztftelatrprctr
WHERE rldnr = c_telstra_accounting
AND rrcty = c_actual
AND rvers = c_ver_001
AND rbukrs = st_input-bukrs
AND racct = st_input-saknr
AND ryear = st_input-gjahr
And rzzlstar in r_lstar
AND rpmax = c_max_period.
There are 5 indices present for Table ZTFTELAT.
Indices of ZTFTELAT:
Name Description
0 Primary key( RCLNT,RLDNR,RRCTY,RVERS,RYEAR,ROBJNR,SOBJNR,RTCUR,RUNIT,DRCRK,RPMAX)
005 Profit (RCLNT,RPRCTR)
1 Ledger, company code, account (RLDNR,RBUKRS, RACCT)
2 Ledger, company code, cost center (RLDNR, RBUKRS,RCNTR)
3 Account, cost center (RACCT,RCNTR)
4 RCLNT/RLDNR/RRCTY/RVERS/RYEAR/RZZAUFNR
Z01 Activity Type, Account (RZZLSTAR,RACCT)
Z02 RYEAR-RBUKRS- RZZZBER-RLDNR
Can anyone help me out why it is taking so much time and how we can reduce it ? and also tell me if I want to use index number 1 then how can I use?
Thanks in advance.Hi Shiva,
I am using two more select queries with the same manner ....
here are the other two select query :
***************1************************
SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
FROM ztftelpt LEFT JOIN ztfzberep
ON ztfzberep~gjahr = st_input-gjahr
AND ztfzberep~poper = st_input-poper
AND ztfzberepcntr = ztftelptrprctr
WHERE rldnr = c_telstra_projects
AND rrcty = c_actual
AND rvers = c_ver_001
AND rbukrs = st_input-bukrs
AND racct = st_input-saknr
AND ryear = st_input-gjahr
and rzzlstar in r_lstar
AND rpmax = c_max_period.
and the second one is
*************************2************************
SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
FROM ztftelnt LEFT JOIN ztfzberep
ON ztfzberep~gjahr = st_input-gjahr
AND ztfzberep~poper = st_input-poper
AND ztfzberepcntr = ztftelntrprctr
WHERE rldnr = c_telstra_networks
AND rrcty = c_actual
AND rvers = c_ver_001
AND rbukrs = st_input-bukrs
AND racct = st_input-saknr
AND ryear = st_input-gjahr
and rzzlstar in r_lstar
AND rpmax = c_max_period.
for both the above table program is taking very less time .... although both the table used in above queries have similar amount of data. And i can not remove the APPENDING CORRESPONDING. because i have to append the data after fetching from the tables. if i will not use it will delete all the data fetched earlier.
Thanks on advanced......
Sourabh -
Select query is taking lot of time to fetch data.....
Select query is taking lot of time to fetch data.
SELECT algnum atanum abdatu abzeit abname abenum bmatnr bmaktx bqdatu bqzeit bvlenr bnlenr bvltyp bvlber b~vlpla
bnltyp bnlber bnlpla bvsola b~vorga INTO TABLE it_final FROM ltak AS a
INNER JOIN ltap AS b ON btanum EQ atanum AND algnum EQ blgnum
WHERE a~lgnum = p_whno
AND a~tanum IN s_tono
AND a~bdatu IN s_tocd
AND a~bzeit IN s_bzeit
AND a~bname IN s_uname
AND a~betyp = 'P'
AND b~matnr IN s_mno
AND b~vorga <> 'ST'.
Moderator message: Please Read before Posting in the Performance and Tuning Forum
Edited by: Thomas Zloch on Mar 27, 2011 12:05 PMHi Shiva,
I am using two more select queries with the same manner ....
here are the other two select query :
***************1************************
SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
FROM ztftelpt LEFT JOIN ztfzberep
ON ztfzberep~gjahr = st_input-gjahr
AND ztfzberep~poper = st_input-poper
AND ztfzberepcntr = ztftelptrprctr
WHERE rldnr = c_telstra_projects
AND rrcty = c_actual
AND rvers = c_ver_001
AND rbukrs = st_input-bukrs
AND racct = st_input-saknr
AND ryear = st_input-gjahr
and rzzlstar in r_lstar
AND rpmax = c_max_period.
and the second one is
*************************2************************
SELECT * APPENDING CORRESPONDING FIELDS OF TABLE tbl_summary
FROM ztftelnt LEFT JOIN ztfzberep
ON ztfzberep~gjahr = st_input-gjahr
AND ztfzberep~poper = st_input-poper
AND ztfzberepcntr = ztftelntrprctr
WHERE rldnr = c_telstra_networks
AND rrcty = c_actual
AND rvers = c_ver_001
AND rbukrs = st_input-bukrs
AND racct = st_input-saknr
AND ryear = st_input-gjahr
and rzzlstar in r_lstar
AND rpmax = c_max_period.
for both the above table program is taking very less time .... although both the table used in above queries have similar amount of data. And i can not remove the APPENDING CORRESPONDING. because i have to append the data after fetching from the tables. if i will not use it will delete all the data fetched earlier.
Thanks on advanced......
Sourabh -
Questions on the most efficient select query..
What is the difference between the two select query & please explain y is the 2nd select query more efficient??
DATA: MAX_MSGNR type t100-msgnr.
MAX_MSGNR = '000'.
SELECT * FROM T100 INTO T100_WA
WHERE SPRSL = 'D' AND
ARBGB = '00'.
CHECK: T100_WA-MSGNR > MAX_MSGNR.
MAX_MSGNR = T100_WA-MSGNR.
ENDSELECT.
DATA: MAX_MSGNR type t100-msgnr.
SELECT MAX( MSGNR ) FROM T100 INTO max_msgnr
WHERE SPRSL = 'D' AND
ARBGB = '00'.Hi,
First never use Check statement in the Select.
Next thing Select ... end select.
Coming to ur question In case of first select it will fetch each record from the data base and compares that record value with the variable(MAX_MSGNR) and assigns the value to the variable. And this process will continue till the select reads all the records of the data base. Also these operations happens on the data base server. SO this query not only affect ur program but also others who is accessing the same data base.
Second query is most efficient because of the aggregate function MAX. Here it will fetch all the records in single go and checks the max value for that column using
optimising algorithm. So number of checks, assignments(single assignment) and fetches will be less compared to first select. This is the main reason. Hope this clarified ur doubt.
Another thing is in first query we are selecting all the fields where as in second we are selecting only one field(required)
Thanks,
Vinod.
Edited by: Vinod Kumar Vemuru on Mar 13, 2008 4:55 PM -
Select query in materialized view with two dblinks
Hi All,
We have oracle 10g On windows.
We are trying to create materialized view. Scenario is we have base table on other database and we are creating mview on different database.
Basa database have two schema's and i am selecting records from that two schema's using two private db links.
But when i am tryin gto create mview its not getting created. After 15 hrs. its still showing creation command and not finished.
Query is :-
Is it good practice to have two db links in select query of materialized view.Billy Verreynne wrote:
Chanchal Wankhade wrote:
Is it good practice to have two db links in select query of materialized view.Same db link being used twice, or two different db links?
If the former, you ideally want the local Oracle db to send the join to the remote database, and for the remote database to drive the join between those 2 tables. There is a hint (<i>driving_site</i>) that can be used - or the join query can be defined on the remote database as a view, and the local materialised view can then use that remote view.
If you have 2 different db links and joining across these - usually a bad idea to perform distributed database joins. There are lots of limitations as to how the tables can be joined. Worse case, full table scans of both remote tables, pulling all the rows from the 2 remote database tables to the local database, and joining these on the local database.
I have seen some severe performance issues in the past as a result of distributed joins. I'll rather use 2 materialised views for pulling both distributed tables's data locally, and then do the join on local data (using indexes, partition pruning, etc)Hi Billy,
My scenario is i have two database database A and database B. Database A is having two schema's SCOTT AND HR. SCOTT schema have select privileges on HR schema.
DB LINK is between Database B to Database A. name is db.link.B.A.oracle.com.
What if i priovide while creating materialized view, the schema name before the table name in database B for this particuler table so it will pick up the table from that schema using same DB LINK(db.link.B.A.oracle.com.) that i am using to fetch records from SCOTT schema.
Above schnario is like two base schema's and one db link using two schema. -
Combine two reports in query designer using key figure with sap exit
Hi experts,
i want to combine two reports in query designer using key figure with sap exit
in the report 1 key figure calculation based on the open on key date(0P_DATE_OPEN)
to calculate due and not due in two columns
in report 2 key figure calculate in the time zones using given in variable Grid Width (0DPM_BV0) like due in 1 to 30 days, 31 to 60 days...the due amount based on the open on key date(0P_DATE_OPEN)
to calculate in 1-30, 31-60, 61-90, 91-120, 121-150 and >150 days in 6 columns
now i have requirement like this
not due, 1-30, 31-60, >60, due,1-30, 31-60, >60 in 8 columns
or
not due, due, 1-30, 31-60, 61-90, 91-120, 121-150 and >150 in 8 col
thank youHi Dirk,
you perhaps know my requirement,
for the management to make used in one report,
we have in reporting finacials Ehp3.
Vendor Due Date Analysis - which show due, not due
Vendor Overdue Analysis - show only due and analysis in time grid frame
i want to combine in one report that show NOT DUE, DUE, DUE time frames in grid.
krish... -
Select Query...... Combinations
Hi Experts,
I have a Custom table for finding approver which looks like the below data. If no data is entered in the highlighted fields it means " * " which is applicable for all.
Appl Type
Appl Subtype
Pers Area
Pers SubArea
Emp Grp
Emp Subgrp
End Date
Appr Level
Begin Date
Approver
CLAIM
1111
31.12.9999
3
01.01.2010
XXX
CLAIM
1111
PA
31.12.9999
3
01.01.2010
YYY
I am trying to write Select Query on this table as below.
DATA: t_appl_subty TYPE RANGE OF zzp_appl_sub,
w_appl_subty-sign = |I|.
w_appl_subty-option = |EQ|.
w_appl_subty-low = i_appl_subty.
APPEND w_appl_subty TO t_appl_subty.
CLEAR w_appl_subty.
w_appl_subty-sign = |I|.
w_appl_subty-option = |EQ|.
w_appl_subty-low = ''.
APPEND w_appl_subty TO t_appl_subty.
CLEAR w_appl_subty.
w_persa-sign = |I|.
w_persa-option = |EQ|.
w_persa-low = i_persa.
APPEND w_persa TO t_persa.
CLEAR w_persa.
w_persa-sign = |I|.
w_persa-option = |EQ|.
w_persa-low = ''.
APPEND w_persa TO t_persa.
CLEAR w_persa.
w_btrtl-sign = |I|.
w_btrtl-option = |EQ|.
w_btrtl-low = i_btrtl.
APPEND w_btrtl TO t_btrtl.
CLEAR w_btrtl.
w_btrtl-sign = |I|.
w_btrtl-option = |EQ|.
w_btrtl-low = ''.
APPEND w_btrtl TO t_btrtl.
CLEAR w_btrtl.
w_persg-sign = |I|.
w_persg-option = |EQ|.
w_persg-low = i_persg.
APPEND w_persg TO t_persg.
CLEAR w_persg.
w_persg-sign = |I|.
w_persg-option = |EQ|.
w_persg-low = ''.
APPEND w_persg TO t_persg.
CLEAR w_persg.
w_persk-sign = |I|.
w_persk-option = |EQ|.
w_persk-low = i_persk.
APPEND w_persk TO t_persk.
CLEAR w_persk.
w_persk-sign = |I|.
w_persk-option = |EQ|.
w_persk-low = ''.
APPEND w_persk TO t_persk.
CLEAR w_persk.
SELECT SINGLE * FROM zapprover
INTO wa_approver
WHERE appl_typ = i_appl_typ
AND appl_subty IN t_appl_subty
AND persa IN t_persa
AND btrtl IN t_btrtl
AND persg IN t_persg
AND persk IN t_persk
AND appr_lvl = i_appr_lvl
AND endda GE sy-datum.
I am passing data as
i_appl_typ = 'CLAIM'
i_appl_subty = '1111'
i_persa = 'PA'
i_btrtl = ' '
i_persg = ' '
i_persk = ' '
i_appr_lvl = 3
It is picking the First record, but as per my requirement if no data available with data “PA” then it has to fetch first record. I am not sure,It seems to be leading to combinations.
How can I write Select Query?
Please help me.Hi Jozef,
Initially i tried like this,
GET RUN TIME FIELD DATA(t1).
DATA: it_approver TYPE STANDARD TABLE OF zapprover,
lv_subrc TYPE sy-subrc.
DATA: lv_appl_typ TYPE zzp_appl_typ,
lv_appl_subty TYPE zzp_appl_sub,
lv_persa TYPE persa,
lv_btrtl TYPE btrtl,
lv_persg TYPE persg,
lv_persk TYPE persk,
lv_appr_lvl TYPE zzp_appr_lvl.
REFRESH it_approver[].
CLEAR: wa_approver,lv_appl_typ,lv_appl_subty,lv_persa,lv_btrtl,lv_persg,lv_persk,lv_appr_lvl,lv_subrc.
PERFORM fill_local_values USING i_appl_typ
i_appl_subty
i_persa
i_btrtl
i_persg
i_persk
i_appr_lvl
CHANGING lv_appl_typ
lv_appl_subty
lv_persa
lv_btrtl
lv_persg
lv_persk
lv_appr_lvl.
SELECT * FROM zapprover
INTO TABLE it_approver
WHERE appl_typ = i_appl_typ
AND endda GT sy-datum.
IF 0 = sy-subrc.
SORT it_approver.
IF i_appl_typ = 'CLAIM'.
PERFORM read_appr TABLES it_approver
USING lv_appl_subty
lv_persa
lv_btrtl
lv_persg
lv_persk
lv_appr_lvl
CHANGING lv_subrc
wa_approver.
IF NOT lv_subrc IS INITIAL AND wa_approver IS INITIAL.
DO 4 TIMES.
CLEAR lv_subrc.
PERFORM fill_local_values USING i_appl_typ
i_appl_subty
i_persa
i_btrtl
i_persg
i_persk
i_appr_lvl
CHANGING lv_appl_typ
lv_appl_subty
lv_persa
lv_btrtl
lv_persg
lv_persk
lv_appr_lvl.
CASE sy-index.
WHEN 1.
CLEAR: lv_persk.
WHEN 2.
CLEAR: lv_persg.
WHEN 3.
CLEAR: lv_btrtl.
WHEN 4.
CLEAR: lv_persa.
WHEN OTHERS.
ENDCASE.
PERFORM read_appr TABLES it_approver
USING lv_appl_subty
lv_persa
lv_btrtl
lv_persg
lv_persk
lv_appr_lvl
CHANGING lv_subrc
wa_approver.
IF lv_subrc IS INITIAL.
EXIT.
ENDIF.
ENDDO.
IF NOT lv_subrc IS INITIAL AND wa_approver IS INITIAL.
DO 6 TIMES.
CLEAR lv_subrc.
PERFORM fill_local_values USING i_appl_typ
i_appl_subty
i_persa
i_btrtl
i_persg
i_persk
i_appr_lvl
CHANGING lv_appl_typ
lv_appl_subty
lv_persa
lv_btrtl
lv_persg
lv_persk
lv_appr_lvl.
CASE sy-index.
WHEN 1.
CLEAR: lv_persa,lv_btrtl.
WHEN 2.
CLEAR: lv_persa,lv_persg.
WHEN 3.
CLEAR: lv_persa,lv_persk.
WHEN 4.
CLEAR: lv_persg,lv_btrtl.
WHEN 5.
CLEAR: lv_persg,lv_persk.
WHEN 6.
CLEAR: lv_persk,lv_btrtl.
WHEN OTHERS.
ENDCASE.
PERFORM read_appr TABLES it_approver
USING lv_appl_subty
lv_persa
lv_btrtl
lv_persg
lv_persk
lv_appr_lvl
CHANGING lv_subrc
wa_approver.
IF lv_subrc IS INITIAL.
EXIT.
ENDIF.
ENDDO.
ELSE.
EXIT.
ENDIF.
IF NOT lv_subrc IS INITIAL AND wa_approver IS INITIAL.
DO 4 TIMES.
CLEAR lv_subrc.
PERFORM fill_local_values USING i_appl_typ
i_appl_subty
i_persa
i_btrtl
i_persg
i_persk
i_appr_lvl
CHANGING lv_appl_typ
lv_appl_subty
lv_persa
lv_btrtl
lv_persg
lv_persk
lv_appr_lvl.
CASE sy-index.
WHEN 1.
CLEAR: lv_persa,lv_btrtl,lv_persg.
WHEN 2.
CLEAR: lv_persa,lv_persg,lv_persk.
WHEN 3.
CLEAR: lv_persa,lv_persk,lv_btrtl.
WHEN 4.
CLEAR: lv_btrtl,lv_persg,lv_persk.
WHEN OTHERS.
ENDCASE.
PERFORM read_appr TABLES it_approver
USING lv_appl_subty
lv_persa
lv_btrtl
lv_persg
lv_persk
lv_appr_lvl
CHANGING lv_subrc
wa_approver.
IF lv_subrc IS INITIAL.
EXIT.
ENDIF.
ENDDO.
ELSE.
EXIT.
ENDIF.
IF NOT lv_subrc IS INITIAL AND wa_approver IS INITIAL.
CLEAR: lv_persa,lv_btrtl,lv_persg,lv_persk.
PERFORM read_appr TABLES it_approver
USING lv_appl_subty
lv_persa
lv_btrtl
lv_persg
lv_persk
lv_appr_lvl
CHANGING lv_subrc
wa_approver.
ELSE.
EXIT.
ENDIF.
ENDIF.
ENDIF.
ELSE.
" Error Handling
ENDIF.
GET RUN TIME FIELD DATA(t2).
DATA(t3) = t2 - t1.
FORM fill_local_values USING VALUE(p_0135) TYPE zzp_appl_typ
VALUE(p_0136) TYPE zzp_appl_sub
VALUE(p_0137) TYPE persa
VALUE(p_0138) TYPE btrtl
VALUE(p_0139) TYPE persg
VALUE(p_0140) TYPE persk
VALUE(p_0141) TYPE zzp_appr_lvl
CHANGING p_appl_typ TYPE zzp_appl_typ
p_appl_sub TYPE zzp_appl_sub
p_persa TYPE persa
p_btrtl TYPE btrtl
p_persg TYPE persg
p_persk TYPE persk
p_appr_lvl TYPE zzp_appr_lvl.
p_appl_typ = p_0135.
p_appl_sub = p_0136.
p_persa = p_0137.
p_btrtl = p_0138.
p_persg = p_0139.
p_persk = p_0140.
p_appr_lvl = p_0141.ENDFORM. " FILL_LOCAL_VALUES
FORM read_appr TABLES p_table STRUCTURE ztinp_approver
USING VALUE(p_0050) TYPE zzp_appl_sub
VALUE(p_0051) TYPE persa
VALUE(p_0052) TYPE btrtl
VALUE(p_0053) TYPE persg
VALUE(p_0054) TYPE persk
VALUE(p_0055) TYPE zzp_appr_lvl
CHANGING p_subrc TYPE sy-subrc
p_result TYPE ztinp_approver.
READ TABLE p_table INTO p_result
WITH KEY appl_subty = p_0050
persa = p_0051
btrtl = p_0052
persg = p_0053
persk = p_0054
appr_lvl = p_0055 BINARY SEARCH.
p_subrc = sy-subrc.
ENDFORM. " READ_APPR
I don't know whether this a best method or not, but working perfectly as i wanted. T3 is getting around 600 - 800ms. I don't how much time it could be for best execution. And i am feeling guilty to write this much code for single record. Please suggest me the simple and best way. -
Select query on two Database views
Hi all,
Can i fetch the data by writing a select query on two DATABASE VIEWS
Because i am able to fetch data by writing a selct query on ONE DATABASE VIEW and ON TRANSPARANT TABLE
but i am not able to fetch data by writing a query on TWO DATABASE VIEWS
Query which i am able to fetch data is
select * from CSKS where OBJNR = COVJ-OBJNR
Query which i am NOT able to fetch data is
Select * from COAS where OBJNR = COVJ-OBJNR
Here
COVJ is a DATABASE VIEW
CSKS is a Transparant Table
COAS is a DATABASE VIEW
Thanks in advance
Regards
AjayHi
I tried with code and I am able to fetch data from view COAS
DATA:it_coas TYPE STANDARD TABLE OF coas.
SELECT * FROM coas INTO TABLE it_coas.
IF sy-subrc IS INITIAL.
WRITE:/ 'Sucess'.
ENDIF.
I think in your case COAS view does not have a value for COVJ-OBJNR.
Regards
Srilaxmi -
Friends,
I need to select some fields from two different tables which doesnot contain any field in common.How to Get this using a select query..
But there is a field X in table 1 which is equalient to eight char of another field y in table 2.I tried using offset but it is giving error.
Thanks in Advance
Regards
YaminiHello,
You can use a subquery
SELECT * FROM SFLIGHT AS F INTO WA_SFLIGHT
WHERE SEATSOCC < F~SEATSMAX
AND EXISTS ( SELECT * FROM SPFLI
WHERE CARRID = F~CARRID
AND CONNID = F~CONNID
AND CITYFROM = 'FRANKFURT'
AND CITYTO = 'NEW YORK' )
AND FLDATE BETWEEN '19990101' AND '19990331'.
WRITE: / WA_SFLIGHT-CARRID, WA_SFLIGHT-CONNID,
WA_SFLIGHT-FLDATE.
ENDSELECT.
or simply query the first table and then the second table with select endselect.
select * from table a.
select * from table b into output_table
where b-field1 eq a-field2.
endselect.
or read the data into one internal table loop at it and then query the other table.
Regards,
Shekhar Kulkarni -
Select Query Between two dates...
Hi Guru's,
I need a Select Query between two dates, also if the record not found for any in between date then it should return NULL or 0 ...
for Example
1. I am having two records in DB for date 2-10-2008 & 4-10-2008
2. Now suppose I have given Query for date between 1-10-2008 to 5-10-2008
Then it should return me 5 records with valid values for 2 & 4 and NULL for other 1,3,5
Thanks.Try like this:
with
t as
select date '2008-10-02' as dt, 'Record #1 (in DB)' as str from dual union all
select date '2008-10-04' as dt, 'Record #2 (in DB)' as str from dual
select v.dt, t.str
from (
select date '2008-10-01' + level - 1 as dt
from dual
connect by level <= (date '2008-10-05' - date '2008-10-01') + 1
) v
left join t
on v.dt = t.dt
order by 1
Maybe you are looking for
-
RAW files in Photos with iOS 8
Has anyone found a solution to the way iOS 8 has slowed down the rendering of RAW files in Photos? This used to be one of the main ways in which I used my iPad and on photo shoots it was very impressive. Now I cannot use it to any effect. I've tried
-
Were can I buy parts to fix my own computer (2006 MacBook Pro)
My MacBook Pro is out of warrantee. I know how to replace the fan that has gone bad, but I am looking for the best resource for purchasing parts.
-
Hi, when create organization data for the support desk of your company form tcode ppoma_crm, there is bp number assinged to this new organization unit. But when i delete organization unit from tcode ppoma_crm, there is still exist in tcode bp.
-
Is it possible to create a dolby 5.1 video with HDV clips in Premiere Elements 9
I am trying to take the stereo input of the HDV clips and use those for Front Left and Front Right. I would like to add some stereo music in the two back channels and add a narrative for the center channel. Is this possible in Premier Elements 9? T
-
Office 2010 crashing when in offline mode
I have a strange one here.I have a laptop that was just sent to a user as a replacement laptop. It is running Windows 7 (x64) and Office Suite 2010.When this user opens Outlook while connected to the network (including VPN) everything is happy panda