SAP QUERY(SQ03/02/02) - how to join tables
Hi MM Wizards,
I would like to know how to join tables EINE & A017 through SAP Query?
Thanks,
Kaveri
Hi Kaveri,
A017 is a pooled table. SAP Query does not support joins against Pooled tables. You should stick to transparent tables if you want to use Query.
You can do a direct read of A017, but you will just end up with a glorified SE16 display.
You could have a programmer write some ABAP and place it into the 'extras' section in SQ02 to grab the additional data that you want, but once you have decided to enlist the aid of an ABAPer, it is better just to write a custom Z program from scratch.
Regards,
DB49
Similar Messages
-
SAP Query - Additional field that collects information from table RESB
Hello gurus. I have a question.
I want to create a SAP Query that shows me the stock level of a list of materials, and also show me the total quantity of order reservations in an additional field.
I created an InfoSet with table MARD, which is the one that holds the Stock information in a plant. Then I created an additional field which would read information from table RESB, the table that holds order reservations per material.
So I wrote this piece of code:
SELECT * FROM RESB
WHERE MATNR EQ MARD-MATNR and
WERKS EQ MARD-WERKS.
ENDSELECT.
if ( sy-dbcnt NE '0').
MOVE RESB-BDMNG to ZQTY.
ELSE.
MOVE '' to ZQTY.
ENDIF.
This works fine. However, this is currently just catching the first record in table RESB that matches my condition.
What I would like is to collect every instance of RESB-BDMNG and add them to field "ZQTY", have it loop in RESB until it finishes finding every record that match the MATNR and WERKS. With this I could get the total number of order reservations that this material has in that table.
Could someone share some coding that would help me achieve this?Yes! That did it. That's what I needed to do. Thank you so much.
While I'm at it, let me ask you a related question.
When I execute the query, in the first records of the query where there's no value from RESB to transfer, the value of field ZQTY appears empty. Once it finds the first record in RESB and it populates ZQTY with a value, then the rest of the records with no hit get the proper value of 0.
Do you know why the first records in the query appear empty and not with a 0? Is there anything I should add to the coding to fix this? -
Hello,
How can I join tables in LCDS and show them in a datagrid?
I run LCDS3 and tomcat.
All help is appricitatedIf an entity has relationships, joins are implicit e.g.: A customer can have multiple orders - Having access to customer gives you access to all the orders associated with the customer. Here the joins are implicit.
However, we don’t support randomly joining tables (that don't have a relationship in the data model) in this release. You are required to create a custom data management assembler, which gives you full control over the SQL. It is likely that the next release may support joining tables directly from the data model.
-Anil -
How to join tables to show the Ship-to party of the SO...
To output a list not only show the Ship-to Party of the SO header, but also show the Ship-to party for every item of the SO.
Thanks!!!
How many tables coule get this done??
Thanks.Hi Hoo Laa,
Use Partner function WE as Ship to party ( While selecting the data use WE,do not use SH)
Check the below program :
REPORT Zxyz.
tables : vbak,
vbap,
vbpa.
data : begin of i_final occurs 0,
vbeln like vbak-vbeln,
vkorg like vbak-vkorg,
kunnr like vbak-kunnr," Sold to party
posnr like vbap-posnr,
matnr like vbap-matnr,
kwmeng like vbap-kwmeng,
netpr like vbap-netpr,
end of i_final.
data : begin of i_output occurs 0,
vbeln like vbak-vbeln,
vkorg like vbak-vkorg,
kunnr like vbpa-kunnr," Sold to party
posnr like vbap-posnr,
matnr like vbap-matnr,
kwmeng like vbap-kwmeng,
netpr like vbap-netpr,
end of i_output.
start-of-selection.
select avbeln avkorg
bposnr bmatnr bkwmeng bnetpr
into table i_final up to 100 rows
from vbak as a inner join vbap as b on bvbeln = avbeln.
loop at i_final.
select single * from vbpa into vbpa
where vbeln = i_final-vbeln
and parvw = 'WE'. -> Partner function
if sy-subrc eq 0.
i_output-kunnr = vbpa-kunnr.
endif.
i_output-vbeln = i_final-vbeln.
i_output-vkorg = i_final-vkorg.
i_output-posnr = i_final-posnr.
i_output-matnr = i_final-matnr.
i_output-kwmeng = i_final-kwmeng.
i_output-netpr = i_final-netpr.
append i_output.
endloop.
end-of-selection.
loop at i_output.
write:/ i_output-vbeln,i_output-vkorg,i_output-kunnr,i_output-posnr,
i_output-matnr,i_output-kwmeng,i_output-netpr.
endloop.
Thanks
Seshu -
Hi,
I have the following scenario
I have table A, B, C. I need to choose column X from A, Y from B, Z from C. The foreign keys are as follows.
A.id = B.id and
A.id = C.id
Tables B and C are independent of each other.
I have the following query.
select
A.X,
B.Y,
C.Z
from A, B,C
where
A.id = B.id
or
A.id = C.id
But I am not seeing the data I need. Please help me on this.it would be really helpful if you could provide sample data for each table and the resulting output that you're trying to achieve.
From what I can glean from my magic crystal ball though is that you're possibly trying to outer-join to more than one table.
here's an example using ansi syntax. in this case, t2 would represent your table A:
with t1 as (select 1 id from dual
union all
select 2 from dual
union all
select 3 from dual)
,t2 as (select 1 id, 10 t3_id, 't2 text 10' text from dual
union all
select 2 id, 12 t3_id, 't2 text 12' from dual)
,t3 as (select 10 id, 1 t1_id, 't3 text 10' text from dual
union all
select 11, 2, 't3 text 11' from dual)
select t1.id
,t2.text
,t3.text
from t1
join t3 on (t3.t1_id = t1.id)
left join t2 on (t1.id = t2.id and t2.t3_id = t3.id); -
How to join tables on different databases
In the company I work in, we've got some java applications working on two different instances which "hide" to each others (one on 10g and the other on 8i). Some decoding tables, which should common to both of them, are only present on 8i one.
I've been told that java works 'cause it allows to connect to both of databases and then report the information on front end applications.
The question is this: since we'll have to get reports on both of databases, is it possible to perform queries by using tools like oracle forms, oracle reports, sql developers, ... for joining the tables of the two different databases as java does? We have to get how to accede directly to the two instances for getting data from both of them for reporting activities. I remind you that we cannot use dblinks between the two databases for internal security reasons.
Thanks in advance!Even java can't join between tables on two databases if the db links are not created.
So it essentially works that it fetches the data from one db and then from another db ( using two different db connctions) and then you can utlize these data and perform some joining.
Coming back to database world. It can be done like the usual dw approach.
1. Connect to a third db:
2. Get data from one database
3. get data from other database.
now do all the joins that you want to do -
How to join tables from different databases (DBLink/DB connection )
Hello,
i have an issue and i hope you could help me to solve it. My problem is: I want to create native sql select which joins two tables from different DB (both of them are ORACLE, one of them internal, another one - external). I have found several notes and posts, but without any success. Db connection exists in dbcon table, so this part of my problem has been solved.
I would like something like that:
select * from table1@xxx inner join table2.
i can not split this select into two separate ones, because both tables store over 30 mln. entries and i do not want to create any copies of them.
Br,
dezHi,
you might need to create a DB-Link on DB level and use EXEC SQL.
Lots of stuff on google about this, like
Oracle DBLink ( external database )
Volker -
SAP Query for Appriasal Report
Hello Experts,
Can we use SAP Query (SQ03, SQ02, SQ01) based on Appriasal tables ( HRHAP*) to fetch records similar to tcode phap_search_pa?
I tried building an infoset making a direct read of table HRHAP and then joining tables like - HRHAP_T, HRHAP_APPEE, HRHAP_APPER, HRHAP_OTHERS and HRHAP_ACT_LOG.
Finally, created a query based on this infoset, however, it does not retreive any results. Seems, it requires more details as app templates...
Can anyone give inputs on this?
Regards,
Sarvesh HasijaHi Sarvesh
SAP Query may not work here. Because more than often, the data available in PHAP tables need to be first brought into temporary tables using a match condition and then shown on screen. There are a lot of sub queries required between PHAP and HRPnnnn tables to see some meaningful results. Imagine how many Table joins the End User needs to do.
SAP Query are ideal if we are pooling data from one or two tables using a match condition. I am not dening that InfoSet is not possible. Getting desired output from such InfoSet will be challenging.
You mentioned you supplied Doc ID/Number to PHAP_Search_PA, which is incorrect. It is a report which works on Template not Document. I hope you know the difference between Template and Document in PMS/OSA. I cannot stress enough on how much important is PHAP_Search_PA. What this standard report can do, custom designed report will take huge time to get close to it.
I am sorry, I am also going to recommend Z Reports in case desired output is not possible in PHAP_Search_PA. In one of my recent assignments we had "Trainer's Feedback Report for any training programme/programmes between any two dates" requirement, and we opted for a Z Report.
Regards
Yash -
How to edit a standard SAP Query
I need to do authority check for satndard SAP Query....How to do it
If you put code similar the following in the Infoset ---> Extras -> Code -> Start of Selection it should work
CALL FUNCTION 'SD_ORGDATA_AUTHORITY_CHECK'
EXPORTING
I_VKORG = P_VKORG
* I_VTWEG =
* I_SPART =
I_ACTVT = '01'
EXCEPTIONS
NO_AUTHORITY = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
So, if the user does not have the proper authorization, it will exit the program. You will need to check with your Security administrator to verify what value to use for the Activity Code. -
SAP Query - Need to join 3 Tables via outer join
Hi,
I need to join 3 Tables using SAP Query. I wish an OUTER JOIN to be performed for the table join.
For Example:
Table 1 has 1000 Entries Field A Field B
Table 2 has 300 Entries Field A Field C
Table 3 has 100 Entries Field A Field D
The normal Join (INNER JOIN) gives me only the records that exists in all the 3 Tables.
But what i need is:
In the above example, If one entry in Table 1 has no matching records in Table 2 / Table 3, there should be an output entry in the SAP Query like
Field A Field B Field C Field D
xxxx yyyy Blank Blank
If there is a common record that exists in the tables, that record should appear in the same entry in the Query output.
Field A Field B Field C Field D
xxxx yyyy zzzz aaaa
In this way, there should be a minimum of 1000 entries (Largest no of records in the Tables joined). More than 1000 records in the Query output depends on the number of common records.
Kindly help if you have come across such a scenario.
thanks & regds
sriramHi
Please join the outer join as below
Table1 with Field A to Table 2 Field A-----outer join
Table1 with Field A to Table 3 Field A------outer join
then you get the out put as per your requirement
Regards
Damu -
Hello ABAP Guru
I need a help here. trying to create SAP query joining three table VBAK VBAP KONV since KONV being cluster table I am not able to do that
thpough I am suceesfully establishe dthe link
VBAK-VBELN=VBAP-VBELN
VBAK-KNUMV=KONV-KNUMV & VBAP-POSNR=KONV-KPOSN
OSS msg says we have to write routine in sap query
but I never used that option
anyone has any clue on how to use cluster table in SAP query?
Thx
PraveenHi,
Inner Join can't be used for cluster tables.
Write a routine in SAP query as follows.
do inner join on vbak,vbap into internal table
itab.
select for konv for all entries itab .
Regards
Amole -
Hi Gurus,
How to get serial numbers in SAP query ?
(ii) When i'm joining certain tables to an existing set of tables, suddenly, the system becomes unable to select the records; sometimes, the number of records is reduced to the number of records available in the last table added. E.g. I have 3 tables LC request (document by which LC is applied for) / LC document (document created when LC opened by the bank is received by the user in the system) Vs PO no (ii) LC request details & (iii) LC Document details. For each LC request, LC document is created individaully at a later time. Now, in the first table, one single field is used for LC req & LC Doc which are of different types and have different number ranges. When I'm using only table , i'm getting both Req & Doc against the PO but without details as it is not available in the table, but when I join & (ii), I get only Requests with details and when I join all the three, I only get LC documents with details.
Now, my requirement is that against each PO, I want to see all the request details along with document details where available. How to get it ?
Thanks in advance.
SheejaHi Nitin,
I opened the tables mentioned. Most of them do not have any entries and the few which had entries were not relevant to my kind of requirement. What I want is the serial no. to be displayed in the first column the query output. Can i achieve it by creating any additional field and then inserting some code into it ?
Anyother options, please ?
Kind regards,
Sheeja. -
HI Team,
Can we create multiple lines in an SAP Query? If yes, how (pls explain the steps)?
Like can we have a line for the employee, next for spouse & then the next for child, so on...and then the next employee details.
Also, there might be fields which will repeat in most of these lines for each employee.
Thanks
RLHi RL:
HR module have PA0021 table (HR Master Record: Infotype 0021 (Family), with this table into TCODE: SQ02 is naturally obtain the result that you ask, or Do you are customizing "Z" program with ALV?
Regards
José Luis -
SAP Query with multiple list lines
HI Team,
Can we create multiple list lines in an SAP Query? If yes, how (pls explain the steps)?
Example of what I am looking for: can we have a line for the employee, next for spouse & then the next for child, so on...and then the next employee details.
Also, there might be fields which will repeat in most of these lines for each employee.
Ex: EE1 Pernr, PA, PSA, SAL, etc
Dependant SSN, PA, Address, PSA, etc
Dependant 2 SSN, PA, PSA, ettc
EE 2 Pernr, PA, PSA, SAL, etc
Thanks
RLHi RL,
Just using SAP Query I don't think it is possible.
SAP Query puts each and every DB record on a separate line.
You need ABAP programming for this.
Regards,
Dilek -
Is it at all possible to link SQ01/2/3 SAP Query to an external SQL source and table (MS SQL).
I have an external SQL2K database that i would like to be able to query from SAP without the requirement of complex ABAPing to create AD-Hoc reports/lookups.
Is it possible to create a link/RFC to the external SQL DB and then have the tables and Fields accesable by creating an Infoset, which i can then query.
Maybe you are looking for
-
How to create JSF application from xsd files?
Hi, We have many xsd files describing xml's which we are supposed to send to web services. Application which we are creating should allow user to fill xml documents with data and then we should send those xml files to some web service. We want to aut
-
Hi, I need to change the layout for cash receipt FBCJ. Please let me know how to change the form and how to find the form name? Thanks, Pavan. Message was edited by: Pavan Panduru
-
How to create generic master data datasource .
How to create generic master data datasource which utilises ALE change pointers for extraction of master data.
-
I wanna change my Creative Cloud single-app Sub to new Subscribtion
I wanna change my Creative Cloud single-app Subscribtion to new Subscribtion for Photoshopp CC and LightRoom at a much lower price. But it is noty possible to do - not by my self. Need help. Please
-
APEX_PLSQL_JOB: How to end/kill jobs
Hi, I'm wondering if there's a good way to kill jobs that were created using APEX_PLSQL_JOB. I have a situation where I create a job using APEX_PLSQL_JOB. The process that it is executing will take a long time to run. After a while I decide that I ne