Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Getting data without using joins from database

former_member435556
Participant
0 Kudos

HI,

I have almost 4 table in use which is ekko, ekkn,rseg, ekpo, from this get I differents  fields according to my requirement by using of purchasing document no and joins, which is common field in all of 4 tables,I have made a structure in my code, which like :

tables:begin of purchase_order

ebeln like ekko-ebeln,

neptr like ekkn-neptr,

belnr like rseg-belnr,

--- like ekpo-

-

-

-

-

-

-

end of purchase_order.

itb type purchase_order,

wtb like table of itb,

and get data by making joins on these 3 tables like:

Select a~ebeln ...... b~neptr........ c~belnr into corresponding fields of wtb from ekko as a inner join ekkn as b on b~ebeln = a~ebeln  inner join rseg as c on

c~eblen = a~ebeln,-------------------------------------- where a~ebeln = ebeln-ekko,

Well this code works fine but  now my problem is that my supervisor told me to do this work by without using joins,, by using loop at itb or like that, I have googled it to find the solution or answer , spent hell of my time in net searching but couldn't fine satisfactory solution, please help me to find  the solution to solve this problem as I am newbie in sap abap.

1 ACCEPTED SOLUTION

philipdavy
Contributor
0 Kudos
  • Without the Joins, you can use FOR ALL ENTRIES statement.
  • But bear in mind that JOINS is performance wise better than FOR ALL ENTRIES IN. Particularly when your internal table size grows.
  • 
    

    Well this code works fine but  now my problem is that my supervisor told me to do this work by without using joins,, by using loop at itb or like that,

  • If you want to fetch data from data base table, how can you omit the SELECT statement ?
  • If your code runs fine with one single select join, convince your supervisor with enough links and documents posted in the SCN. (Just like one I have given above )

Regards,

Philip.

10 REPLIES 10

philipdavy
Contributor
0 Kudos
  • Without the Joins, you can use FOR ALL ENTRIES statement.
  • But bear in mind that JOINS is performance wise better than FOR ALL ENTRIES IN. Particularly when your internal table size grows.
  • 
    

    Well this code works fine but  now my problem is that my supervisor told me to do this work by without using joins,, by using loop at itb or like that,

  • If you want to fetch data from data base table, how can you omit the SELECT statement ?
  • If your code runs fine with one single select join, convince your supervisor with enough links and documents posted in the SCN. (Just like one I have given above )

Regards,

Philip.

matt
Active Contributor
0 Kudos

I concur with what Philip says. Please do inform your supervisor that the correct approach is using INNER JOIN. If he disagrees, then respectfully point him in my direction and I'll be happy to re-educate him based on 17 years of commercial ABAP programming experience. This myth about FAE has been around way way too long. If supervisors and teachers are perpetuating then they're the ones who need to move away from 15 year old technology.

To repeat. Use of FOR ALL ENTRIES is in most cases not the best approach.

Looping and selecting within loops is an even worse approach - so I really hope your supervisor is seeking only hypothetical solutions...

0 Kudos

Thanks Davy  for you reply, I agree what you  have said, but I used more then one join in my code It might be 4 joins i have used in it, it just past the code which is not complete just to give you guys idea,supervisor  told me to use select statements but not use joins, actually that want to give me an idea that how things works when we have nothing on to make joins,, or please tell me can I use selcet statement with in loop, like this

loop at itb into wa,

select .....from ekko into itb2,

select  from ekkn into itb3,

--

---

---

then merge all of the internal table in single master itb which have all of the corrospinding field.

endloop.

matt
Active Contributor
0 Kudos

Tell your supervisor he/she is wrong and you insist, as a matter of principle and conscience, on doing things according to best practice.

Former Member
0 Kudos

Hi Amir,

Select inside a loop is a worst programming practice.Yes i agree we can still see int in our codes.

But i really wonder why you have to go for that provided you can use joins/For all entries as you have key fileds readily available.

Note:As Mathew and Davy said go for Joins rather than For all entries.Please convince your supervisor and no material available will tell you to go for select inside loops in this scenario.

Always update yourself for the best coding practises and enjoy coding in ABAP

Regards,

Kannan

matt
Active Contributor
0 Kudos

There's an additional myth that you shouldn't use inner join on more than 3 (or some other arbitary number) tables. This is complete twaddle.

0 Kudos

Hi Mathew,

For more than 3 tables i prefer to go for For all entries as am afraid joins will complicate the selects.

You thoughts on it ?


Regards,

Kannnan

matt
Active Contributor
0 Kudos

Myth. There's no need to be afraid.

I've written BW extractors on HR appraisal data that join 5 tables perfectly happily. You may have to play around a bit to get the most efficient joins, but usually it's pretty obvious.

0 Kudos

I don't want to rub it in, but I have recently created a join of about 20 tables and aliases (some tables appearing multiple times), combining shopping cart and purchase order information in SRM for a simple ALV overview. Not all at once, it was rather growing and growing...

You need to understand the links between the involved tables (database model), and make sure that all ON- and WHERE-conditions can work with available indexes and that the ON-conditions are complete in a sense that the result set does not "explode". For example, when omitting the SPRAS field when joining text tables, you end up with one line per maintained language, whereas you usually only want to see the logon language.

For me the biggest advantage of joins are the flexibility of applying selection criteria at runtime (based on user input) and that the result is in one internal table straight away.


Thomas

0 Kudos

Hi Thomas,

That was a good shot..

Regards,

Kannan