2014 Jun 07 9:53 AM
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.
2014 Jun 07 10:18 AM
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,
Regards,
Philip.
2014 Jun 07 10:18 AM
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,
Regards,
Philip.
2014 Jun 07 10:38 AM
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...
2014 Jun 07 12:01 PM
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.
2014 Jun 07 4:47 PM
Tell your supervisor he/she is wrong and you insist, as a matter of principle and conscience, on doing things according to best practice.
2014 Jun 07 12:37 PM
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
2014 Jun 07 4:46 PM
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.
2014 Jun 07 5:18 PM
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
2014 Jun 07 8:17 PM
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.
2014 Jun 07 9:30 PM
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
2014 Jun 08 8:04 AM