Skip to Content

Cartesian product of 2 internal tables


Hi All,

I have two selection option Company Code(BUKRS) and G/L Account(HKONT) as my selection screen fields.

Now I have to validate the combination of BUKRS + HKONT against a custom table (i.e I need to check whether the combination of BUKRS + HKONT

entered is the same as the one present in the custom table or not)

My Solution: I thought of storing all enter BUKRS and HKONT for selection screen into 2 diff internal tables. Then do a Cartesian product

of these two itabs to get all possible combination,(using nested LOOP which is a bad practice)

And then validate it with the ones maintained in Custom table.

Is there any other better way of doing this As I don't prefer using LOOP within LOOP ?

Thanks,

Faiz

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jan 23, 2014 at 11:48 AM

    Hi Faiz!

    I suggest, doing it the other way round. Create two tables containing you select options. Then iterate through your custom table and split BUKRS and HKONT, which, I assume, are used as key in your custom table (as you know the field length, splitting should be no problem. If these fields are seperate fields in your custom table, skip this step)

    Pseudo code of my approach:

    custom_table is your custom table

    itab1 is the internal table holding BUKRS of select options

    itab2 is the internal table holding HKONT of select options

    loop at custom_table assigning <cus_tab>.

    split BUKRS and HKONT (if neccessary)

    read itab1 with key bukrs = <cus_tab>-bukrs transporting no fields.

    if sy-subrc is initial.

    read itab2 with key hkont = <cus_tab>-hkont transporting no fields.

    if sy-subrc is initial.

    " Combination of values is already in CUSTOM_TAB

    endif.

    endif.

    endloop.

    This way you only have 1 loop, read table with "transporting no fields" is quite fast as well.

    I hope, this helps!

    Regards

    Florian

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 23, 2014 at 11:46 AM

    What i would have done is first fetch valid combination for SKB1 and then compare them with your custom table mapping. Since SKB1 will have account/company code combination. So i will have valid combinations based on selection criteria and then reduce them via custom table next

    Nabheet

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 23, 2014 at 12:12 PM

    Hi All,

    I'm testing this scenario and from the results that I've got , it seems that my query

    SELECT * from <table>

    where <col 1> in <Select_option 1>

    and <col 2> in <Select_opt 2>

    works like a Cartesian product in itself so probably there is no need to handle

    the combinations explicitly.

    Pls let me know your thoughts on this 😊

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jan 23, 2014 at 12:25 PM

    Hi Faizur,

    What if the user enters complex selection criteria? For example he can enter G/L account range 40000001 to 40000011 to be included and 30000001 to 30000011 to be excluded? What would be the expected result from Cartesian then?

    Also when you say you wan to validate combination from custom table, do you mean to say that if any one of the valid combination on entered criteria exists in custom table , the program should proceed further else it should give error to user on selection screen?

    Did you try SELECT .. FROM ZTABLE WHERE HKONT IN S_HKONT AND BUKRS IN S_BUKRS ?i

    When you try it, use all possible combination positive, negative , range, include, exclude, multiple selection for both select-option. 😊

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.