How to generate report from two tables using DAO design pattern?
Hi,
Iam using struts with DAO pattern for my application. According to DAO design im creating model class for each table in my database with getter,setter methods. i have no problem when im generating report from one table. but if have i have to join two tables whatis the better way for doing that? is it good practise to create a new model contains properties from both the tables?
Please help me
Thanks in Advance
Rajesh
Dear Rajesh,
As per the pattern you are creating equivalent java objects for every database table under consideration in which each db field will become a private attribute and public getter and setter methods.
If you have to display data from one table the above approach is sufficient enough.
But in case your database is normalised ..lets take an example of Bank having Branch and Accounts tables. We dont need to repeat the whole information of the branch for every account in that branch. so we prefer to have a branch id in that table....this approach lot of insertion/deletion/updatation anomlies that may exists with the database...
now lets come back to our topic....we shall create two java objects 1) Branch 2) Account.....
When ever u just need to display simple report u can do it staright forward,,,,,now if u want to display branch information along with the account information....the two objects just created are not sufficient
So i suggest u the following approaches
1) Create an attribute of type Branch in the Accounts Object......
This shall serve the purpose of displaying the Btranch information
2) Create a collection object of type ( Vector or ArrayList) which can have objects of Account in the Branch Object,,,
Now its upto u how shall u fill up the objects with appropriate sql queries.
The method that i mentioned is followed by Oracle Toplink and Hibernate ....which provide Object to relation mapping layers.
Any queries ...revert back to me...
Mahesh
Similar Messages
-
How to select data from a table using a date field in the where condition?
How to select data from a table using a date field in the where condition?
For eg:
data itab like equk occurs 0 with header line.
select * from equk into table itab where werks = 'C001'
and bdatu = '31129999'.
thanks.Hi Ramesh,
Specify the date format as YYYYMMDD in where condition.
Dates are internally stored in SAP as YYYYMMDD only.
Change your date format in WHERE condition as follows.
data itab like equk occurs 0 with header line.
select * from equk into table itab where werks = 'C001'
and bdatu = <b>'99991231'.</b>
I doubt check your data base table EQUK on this date for the existince of data.
Otherwise, just change the conidition on BDATU like below to see all entries prior to this date.
data itab like equk occurs 0 with header line.
select * from equk into table itab where werks = 'C001'
and <b> bdatu <= '99991231'.</b>
Thanks,
Vinay
Thanks,
Vinay -
Dear all,
I have to develop an application in Struts by using DAO design pattern ..........
Please give an example on Struts using DAO...................
Thank you
PleaseI'm glad you asked. It means Read The Flaming Manual. That'd be the struts manual by the way.
-
Struts using DAO Design Pattern Tutorail
Can anybody give me a link for the Struts using DAO Design Pattern tutorial
sample tutorialhttp://javaboutique.internet.com/tutorials/ApacheDAOs/
Found by using google: strust dao pattern tutorial
There are more good links using that search... -
How to Select Data from different Tables Using Linq
Hi,
I have two different tables, I just want to collect data from tables using Linq to SQL Queries.
The tables looks like This
ID Name ImageUrl
Other Table is
ID EmpID CheckInTime CheckOutTime
What I want to Collect data from CheckInTime and want to place it in a that is in a list view
Same thing I want to do it for CheckOutTime And One thing I want to tell is both tables are joined by a FK EmpID with ID.
What Are the suggestions for me
I have Used this code
var data = from emp in db.Employees
join chk in db.CheckInCheckOuts on emp.ID equals chk.EmpID
select new EmployeeCheckInOut
Name = emp.Name,
ImageUrl = emp.ImageUrl,
CheckIn = emp.CheckInCheckOuts,
CheckOut = emp.CheckInCheckOuts
Here the CheckInCheckOuts is another table, I don't how do I access fields of the Other table "CheckInCheckOuts"
Thank you
AliMitja,
Kind of Tables, I don't Know but I can Tell you that these are Two table, first Table Have Data in It, Name, ImageUrl I have filled this table with names and ImageUrls And are string type.Other Table is for the CheckInTime And CheckOutTime of the employee.
What I need that when I click on the Image button it Should displays The Current Datetime into the label below the Image button.
So I have Problem accessing my CheckInCheckOut Table because I may not have Idea about.Did you understand what I need to do, if you have more question please ask to me.
Thanks
Ali -
Unable to retrive data from two tables using multiple joins
Hi,
Table: EMP mgr
eid name
eid mgrid
1
A 1
null
2
B 2
3
3
C 3
3
i need to get result as:
eid ename mgrname
thanks
AVSSai,
It would be very helpful if you could mention your table structures a bit more clearly. Would allow for effective replies from fellow users as well. :)
However, assuming that your structure would be as follows presenting the query as below:
DECLARE @Emp TABLE(Eid Int, ename Varchar(50))
DECLARE @Emp_Mgr TABLE(Eid int, mgrid int null )
INSERT INTO @Emp select 1,'Ram'
INSERT INTO @Emp select 2,'Shyam'
INSERT INTO @Emp_Mgr select 1,NULL
INSERT INTO @Emp_Mgr select 2,1
SELECT * FROM @Emp
SELECT * FROM @Emp_Mgr
Query to print results as EID, ENAME, MGRNAME
SELECT em.eid,e1.ename as ENAME,e2.ename as MGRNAME
FROM @Emp_Mgr em
JOIN @Emp e1 ON em.eid=e1.eid
JOIN @Emp e2 ON em.mgrid=e2.eid
However, as you see this approach of maintaining two tables for preserving the employee-manager data is redundant and makes the queries unnecessarily complex. So, you could opt for the widely used single table format as mentioned by Praveen as well. Check
if this helps you..
Recommended Structure
*Avoidance of redundant storage of data
*Lesser Joins in queries
DECLARE @Emp TABLE(Eid Int , Ename Varchar(50) , mgrid int null )
INSERT INTO @Emp(Eid , ename , mgrid) values(1 , 'Ram' , null) , (2 , 'Shyam' , 1)
SELECT * FROM @Emp
Query to print results as EID, ENAME, MGRNAME
SELECT e.Eid , e.Ename , m.Ename as MgrName
FROM @Emp e
JOIN @Emp m On a.mgrid = b.eid
Thanks,
Jay
<If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'> -
I have two tables - table1 and table2 - that have the exact same schema. There are three fields that can be used to compare the data of the two tables, field1, field2, and field3. When there are matching rows in the two tables (table1.field1/2/3 = table2.field1/2/3)
I want to replace table1.field4 with table2.field4 and replace table1.field5 with table2.field5.
I have worked with the query but have come up with goobly goop. I would appreciate any help. Thanks.If your field1, field2, and field3 combinations in these tables are unique, you
can do a join on them.
Select t1.field4, t2.field4 , t1.field5, t2.field5
from table1 t1 inner join table2 t2 on t1.field1 =t2.field1 and t1.field2=t2.field2 AND t1.field3=t2.field3
--You can update your table1 with following code:
Merge table1 t1
using table2 t2 on
on t1.field1 =t2.field1 and t1.field2=t2.field2 AND t3.field3=t2.field3
When matched then
Update Set
t1.field4= t2.field4
,t1.field5 = t2.field5 ; -
How to access records from two tables which have no relation
Hi,
I trying to generate a report where i need to print the company details at the top of the page and invoice details of that down the page.There is no relation between these two tables.I am not able to write two queries for one report.Pls some one assist me in getting this thing done.
Regards,
Tulacenath.Hi Tulacenath
So your invoice table does not have a reference to the customers (companys) that the invoices belong to?
Tim -
How to read records from Relationship table using ABAP API's
Hi All,
I need to retrieve the records from Relationship table. In Java API's I came to know there is an option to retrieve this. I could not find anything in ABAP API's. Is there any option in ABAP API's to do this.
Please Suggest.
Thank You,
Gajendra.Hi Gajendra,
You can mainly read records from MDM (in a DDIC structure) using ABAP API's using the following function modules/methods:
1. RETRIEVE: This is used to generically retrieve records from tables. Attributes and Values can also be retrieved.
2. RETRIEVE SIMPLE: Retrieve records from MDM in a simple way.( simple data types).
3. RETRIEVE CHECKOUT: Retrieves all checked out ID's.
4. RETRIEVE ATTRIBUTES: Retrieves attribute(s) from a Taxanomy table.
You will find all these methods in the following interface
Interface : IF_MDM_CORE_SERVICES
Hope it helps.
*Please reward points if found useful.
Thanks and Regards
Nitin Jain -
How to group data from two tables ?
Hello,
I have two tables and i want to group data from them but two table not linked.
Table TEXT_IN : ID_IN (primary_key), DATE_IN
Table TEXT_OUT : ID_OUT(primary_key),DATE_OUT
Example :
Result :Group Date and Order by IN,OUT
And It seems a bit
confusing because we do not link
.You can give me solutions.
Thank you.SELECT MAX(CASE WHEN Rn = 1 THEN [IN] END) AS [IN1],
MAX(CASE WHEN Rn = 1 THEN [OUT] END) AS [OUT1],
MAX(CASE WHEN Rn = 2 THEN [IN] END) AS [IN2],
MAX(CASE WHEN Rn = 2 THEN [OUT] END) AS [OUT2],
MAX(CASE WHEN Rn = 3 THEN [IN] END) AS [IN3],
MAX(CASE WHEN Rn = 3 THEN [OUT] END) AS [OUT3],
MAX(CASE WHEN Rn = 4 THEN [IN] END) AS [IN4],
MAX(CASE WHEN Rn = 4 THEN [OUT] END) AS [OUT4],
MAX(CASE WHEN Rn = 5 THEN [IN] END) AS [IN5],
MAX(CASE WHEN Rn = 5 THEN [OUT] END) AS [OUT5],
FROM
SELECT COALESCE(m.DATE_IN,n.DATE_IN) AS DATE_IN,
COALESCE(m.Seq,n.Seq) AS Seq,
ID_IN AS [IN],
ID_OUT AS [OUT],
ROW_NUMBER() OVER (PARTITION BY Seq ORDER BY COALESCE(m.DATE_IN,n.DATE_IN)) AS Rn
FROM
SELECT ROW_NUMBER() OVER (PARTITION BY DATE_IN ORDER BY DATE_IN) AS Seq,*
FROM TEXT_IN
)m
FULL OUTER JOIN
SELECT ROW_NUMBER() OVER (PARTITION BY DATE_IN ORDER BY DATE_IN) AS Seq,*
FROM TEXT_OUT
)n
ON n.Seq = m.Seq
AND n.DATE_IN = m.DATE_IN
)t
GROUP BY Seq
to make it dynamic see
http://sqlblogcasts.com/blogs/madhivanan/archive/2007/08/27/dynamic-crosstab-with-multiple-pivot-columns.aspx
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page -
Subject: How to do join between two tables using something like SE16
SE16, SE11 provide form based interface query information from a single table. Is there a way to do join between two tables without creating an infoset erc? I am looking for something similar to sql join but in SAP BI 7.0
Thanks.Hi
Pls look into below links. Hope this helps you.
1. http://help.sap.com/saphelp_46c/helpdata/EN/d2/cb45bf455611d189710000e8322d00/content.htm
2. http://help.sap.com/saphelp_46c/helpdata/EN/d2/cb45a5455611d189710000e8322d00/content.htm
Regards
Sirigiri -
Hey guys how to fetch data from db table using subroutine
hi guys,
I am fetching data from db table "mcha". now in the follwing code i get it in "HSDAT1_DATE."
now when i read out_tab with key "HSDAT1". it wont come in out_tab-value.plz tell me what is wrong whether some key condition in out_tab or any thing else.
and what should i write in changing && in script.
thanks in advance
FORM DATE_MGF TABLES IN_TAB STRUCTURE ITCSY
OUT_TAB STRUCTURE ITCSY.
tables :MCHA ,QALS.
DATA : WERKS1 LIKE QALS-WERK.
DATA : HSDAT1 LIKE MCHA-HSDAT.
DATA : DATE(2),
MONTH(2),
YEAR(4).
DATA : HSDAT1_DATE(10).
READ TABLE IN_TAB WITH KEY 'QALS-WERK'.
LOOP AT IN_TAB.
IF SY-TABIX EQ 1.
WERKS1 = IN_TAB-VALUE.
IF WERKS1 NE SPACE.
EXIT.
ENDIF.
ENDIF.
ENDLOOP.
SELECT SINGLE HSDAT INTO HSDAT1
FROM MCHA
WHERE WERKS = WERKS1.
DATE = HSDAT1+6(2).
MONTH = HSDAT1+4(2).
YEAR = HSDAT1+0(4).
CONCATENATE DATE '.' MONTH '.' YEAR INTO HSDAT1_DATE.
READ TABLE OUT_TAB WITH KEY 'HSDAT1' .
IF SY-SUBRC = 0.
OUT_TAB-VALUE = HSDAT1.
MODIFY OUT_TAB INDEX SY-TABIX.
ENDIF.Hi,
Let me understanf clearly what you want.
initally mine out_tab is blank
According to you, your table out_tab is blank. And you need to add out_tab-value = HSDAT1_date.
READ TABLE OUT_TAB WITH KEY 'HSDAT1' .
IF SY-SUBRC = 0.
OUT_TAB-VALUE = HSDAT1.
MODIFY OUT_TAB INDEX SY-TABIX.
ENDIF.
So, if your table is blank, then read statement will fail.
Please let me know if your table out_tab in blank when you are reading the table and if this table contains any field called HSDAT.
Basically i would like to know your internal table out_tab declaration.
Thanks,
Archana -
How can I develop a web application using EJB design pattern?
I have searched over the web and found quite a lot of tutorials on how to use the EJB design pattern.
I know that there will be a home interface, EJB object interface and a SessionBean.
But the tutorials often only cover a single class, this made me unable to get a complete picture of how EJB design pattern can be implemented into a whole system.
I am now required to devleop an online shopping web application using EJB and JSP page.
I think I will need to create a lot of classes: Member, ShoppingCart, Product...etc.
What I want to ask is that, do I need to create a home interface, EJB object interface and a SessionBean for each of these classes?
I really need some ideas on how to develop this system using EJB + JSP pages.
Many thanks to you all.For every EJB that you want to create, you will need to code a home and remote interface and a bean class.
You could start getting your ideas here
http://www.theserverside.com/books/wiley/masteringEJB/
http://www.coreservlets.com -
How to select columns from internal table using 'GUI_DOWNLOAD' ?
Hi,
i am running a report & the fields for output is saved in an internal table which has as many as 10 fields. But I want to select only a few fields for output. There is a option COL_SELECT in function 'GUI_DOWNLOAD'. How to use it. If possible with example.Hai VijayKumar
Try with the following code
tables : mara.
data : begin of it_mara occurs 0,
matnr like mara-matnr,
mbrsh like mara-mbrsh,
mtart like mara-mtart,
meins like mara-meins,
end of it_mara.
parameters : P_mtart like mara-mtart default 'ROH'.
start-of-selection.
perform select_data.
perform download_data.
*& Form select_data
text
--> p1 text
<-- p2 text
FORM select_data .
select
matnr
mbrsh
mtart
meins
from mara into table it_mara
where mtart = p_mtart.
ENDFORM. " select_data
*& Form download_data
text
--> p1 text
<-- p2 text
FORM download_data .
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = 'c:\down.txt'
FILETYPE = 'ASC'
COL_SELECT = 'X'
COL_SELECT_MASK = 'X XX'
TABLES
DATA_TAB = it_mara.
IF SY-SUBRC = 0.
SORT IT_MARA BY MATNR.
ENDIF.
ENDFORM. " download_data
Thanks & Regards
Sreenivasulu P -
How to generate XSD from simple table (e.g. emp from scott/tiger)?
Please excuse the ignorance...
I've been trying to determine if there's a simple way (i.e. using a command in sqlplus or via a GUI wizard), to point to a simple table (such as the demo 'emp' table), and have Oracle then generate an XML Schema (XSD) file that contains the representation for that table, so that I can use that XSD file with various XML-based tools.
Any help is appreciated.
Thanks,
MikeHi,
Please refer this how to guide which may give some idea for creation formula:
http://www.pioneerb1.com/wp-content/uploads/2012/04/How-to-work-with-Crystal-Reports-8.8.pdf
Thanks & Regards,
Nagarajan
Maybe you are looking for
-
Reinstalling mac os leopard on new hard drive
Hi, ive had meny problems with my macbooks hard drive failing before, infact i think its a design flaw, i wasn't forking out another 200 quid or so to get my hard drive replaced on this laptop, so i opened it up, and stuck in a hard drive from a brok
-
Issue during File to File Scenario
Hi Folks, I am doing a file to file scenario in which I'm using the Transport protocol as FILE (NFS) and the source directory I'm trying to use is on my local system which is shared. But still i'm getting an error "Configured source directory ' 1
-
Post Good Receipt without serial number
Dear Expert, My client use serial number management for good movement. But they have requirement to set serial number as blank when they perform GR non stock (GR for PO with account assignment) while serial number still mandatory for GR stock (GR for
-
1 Person, 2 Position, 2 Org Unit, 2 different CC
Hi All, Kindly tell me the answer of following doubt. 1. I have hired 1 person on 1 position with staffing percentage as 50% from 01.01.2008 to 31.12.9999. (Cost Center is PS02). 2. I have also assigned him the holder of another (new) position with t
-
AHHHHHHHHHH!!!!! I THINK ITS TOTALLY BROKEN!!!!
I left it to charge for 5 friggen hours and i wake up and i see that like ink exploded in the interior. . . i dun know what to do, i think its permanently broken and i dont have a warranty . . . any ideas? I see like a stray of ink or something in th