Application Development and Automation 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: 
Read only

Internal Table Problem

Former Member
0 Likes
1,213

HI again now i have a problem in Internal table, hope u can help.... this is my code:

  • Get Total Line Internal Table GL Account 1

DESCRIBE TABLE i_gl1 LINES l_line1.

  • Get Total Line Internal Table GL Account 2

DESCRIBE TABLE i_gl2 LINES l_line2.

IF l_line1 GT l_line2.

  • Create Internal Table G/L Account Final

LOOP AT i_gl1.

IF sy-subrc = 0.

i_glfindet-hkont1 = i_gl1-hkont.

i_glfindet-belnr1 = i_gl1-belnr.

i_glfindet-bldat1 = i_gl1-bldat.

i_glfindet-wrbtr1 = i_gl1-wrbtr.

i_glfindet-vbund1 = i_gl1-vbund.

i_glfindet-spc = ''.

APPEND i_glfindet.

ENDIF.

ENDLOOP.

LOOP AT i_glfindet.

l_flag = l_flag + 1.

READ TABLE i_gl2

WITH KEY bukrs = i_glfindet-vbund1.

IF sy-subrc EQ 0.

i_glfindet-hkont2 = i_gl2-hkont.

i_glfindet-belnr2 = i_gl2-belnr.

i_glfindet-bldat2 = i_gl2-bldat.

i_glfindet-wrbtr2 = i_gl2-wrbtr.

i_glfindet-vbund2 = i_gl2-vbund.

ENDIF.

MODIFY i_glfindet.

IF l_flag GE l_line2.

EXIT.

ENDIF.

ENDLOOP.

ELSE.

LOOP AT i_gl2.

IF sy-subrc = 0.

i_glfindet-spc = ''.

i_glfindet-hkont2 = i_gl2-hkont.

i_glfindet-belnr2 = i_gl2-belnr.

i_glfindet-bldat2 = i_gl2-bldat.

i_glfindet-wrbtr2 = i_gl2-wrbtr.

i_glfindet-vbund2 = i_gl2-vbund.

APPEND i_glfindet.

ENDIF.

ENDLOOP.

LOOP AT i_glfindet.

l_flag = l_flag + 1.

READ TABLE i_gl1

WITH KEY bukrs = i_glfindet-vbund2.

IF sy-subrc EQ 0.

i_glfindet-hkont1 = i_gl1-hkont.

i_glfindet-belnr1 = i_gl1-belnr.

i_glfindet-bldat1 = i_gl1-bldat.

i_glfindet-wrbtr1 = i_gl1-wrbtr.

i_glfindet-vbund1 = i_gl1-vbund.

ENDIF.

MODIFY i_glfindet.

IF l_flag GE l_line1.

EXIT.

ENDIF.

ENDLOOP.

ENDIF.

I want to combine 2 different internal table into 1 combined internal table, but each internal table, has different lines, so it doesn't have the same line...

With my logic above, i manage to combined it, but there is some line which is duplicated from internal table 1 or 2.

What i want to do is... I want to combine from internal table 1 the column is hkont belnr wrbtr bldat vbund, and from internal table 2 the same which is hkont belnr wrbtr bldat vbund

the value i get from selection screen put it in internal table 1 is 7, and for internal table 2 is 5, now i want to combine 2 internal table without changing each internal table...

so the combined internal table consist of 7 lines... but there is 2 blank line for internal table 1 that doesn't have a value, while internal table 2 has 7 line..

Can u solve my problem, by adding some logic and code in here??? Thank u very much

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,190

Hi julius,

Just copy paste the code.


data: begin of itab1 occurs 4,
str1(10),
str2(10),
str3(10),
end of itab1.

data: begin of itab2 occurs 4,
str4(10),
str5(10),
str6(10),
end of itab2.

data: begin of itab3 occurs 4,
s1(10),
s2(10),
s3(10),
s4(10),
s5(10),
s6(10),
end of itab3.

itab1-str1 = 'apple'.
itab1-str2 = 'gundam'.
itab1-str3 = 'rock'.
append itab1.

itab1-str1 = 'oranges'.
itab1-str2 = 'robot'.
itab1-str3 = 'leaf'.
append itab1.

itab2-str4 = 'grape'.
itab2-str5 = 'book'.
itab2-str6 = 'siccors'.
append itab2.

if itab1 > itab2.
    loop at itab1.
       write sy-tabix.
       read table itab1 index sy-tabix.
       if sy-subrc = 0.
          read table itab2 index sy-tabix.
           if sy-subrc = 0.
             itab3-s1 = itab1-str1.
             itab3-s2 = itab1-str2.
             itab3-s3 = itab1-str3.
             itab3-s4 = itab2-str4.
             itab3-s5 = itab2-str5.
             itab3-s6 = itab2-str6. 
             append itab3.
           else.
             itab3-s1 = itab1-str1.
             itab3-s2 = itab1-str2.
             itab3-s3 = itab1-str3.
             itab3-s4 = ' '.
             itab3-s5 = ' '.
             itab3-s6 = ' '. 
             append itab3.
           endif.
       endif.
    endloop.
else.
loop at itab2.
       write sy-tabix.
       read table itab2 index sy-tabix.
       if sy-subrc = 0.
          read table itab1 index sy-tabix.
           if sy-subrc = 0.
             itab3-s1 = itab1-str1.
             itab3-s2 = itab1-str2.
             itab3-s3 = itab1-str3.
             itab3-s4 = itab2-str4.
             itab3-s5 = itab2-str5.
             itab3-s6 = itab2-str6. 
             append itab3.
           else.
             itab3-s1 = itab1-str1.
             itab3-s2 = itab1-str2.
             itab3-s3 = itab1-str3.
             itab3-s4 = ' '.
             itab3-s5 = ' '.
             itab3-s6 = ' '. 
             append itab3.
           endif.
       endif.
    endloop.

endif.

loop at itab3.
  write: / itab3.
endloop.

Hope it helps you.

regards,

Maheswaran.B

10 REPLIES 10
Read only

Former Member
0 Likes
1,190

Hi julius,

I don't know whether i understood ur question properly or not.

1 I assume you have two internal tables.

2. U want to combine them so that duplciates are not there.

3. If this is so,

4. U can declare another third table.

5. With loop or append statement

populate the 3rd table with all records

of 1 and 2.

6. Then u can use DELETE ADJACENT DUPLICATES

(see help on this command)

to remove duplicate records.

I hope it helps.

Regards,

Amit M.

regards,

amit m.

Read only

0 Likes
1,190

Yup I have 2 Internal Tables, I want to combine it

But side by side... so it's just like this:

For Example:

Internal table 1:

Apple Gundam Rock

Oranges Robot Leaf

Internal Table 2

Grape Book Siccors

The Final Internal Table should be like this:

Apple Gundam Rock Grape Book Siccors

Oranges Robot Leaf [Blank] [Blank] [Blank]

I want it like this.... not just append the internal table.... the 3rd internal table has the structure for all internal table 1 and internal table 2. So can u correct my program, or have another solution.

Regards,

Julius

Read only

0 Likes
1,190

Yup I have 2 Internal Tables, I want to combine it

But side by side... so it's just like this:

For Example:

Internal table 1:

Apple Gundam Rock

Oranges Robot Leaf

Internal Table 2

Grape Book Siccors

The Final Internal Table should be like this:

Apple Gundam Rock Grape Book Siccors

Oranges Robot Leaf [Blank] [Blank] [Blank]

I want it like this.... not just append the internal table.... the 3rd internal table has the structure for all internal table 1 and internal table 2. So can u correct my program, or have another solution.

Regards,

Julius

Read only

0 Likes
1,190

Yup I have 2 Internal Tables, I want to combine it

But side by side... so it's just like this:

For Example:

Internal table 1:

Apple Gundam Rock

Oranges Robot Leaf

Internal Table 2

Grape Book Siccors

The Final Internal Table should be like this:

Apple Gundam Rock Grape Book Siccors

Oranges Robot Leaf [Blank] [Blank] [Blank]

I want it like this.... not just append the internal table.... the 3rd internal table has the structure for all internal table 1 and internal table 2. So can u correct my program, or have another solution.

Regards,

Julius

Read only

0 Likes
1,190

Hi,

Loop at your first Internal table.

read the second Table.

If sy-subrc = 0.

fill the 3rd internal table with both 1st & 2nd

internal tables

else

file the 3rd with only 1st internal table

endif.

Hope this works.

GSR.

Read only

Former Member
0 Likes
1,190

If the 2 internal tables' structure is practically the same, you could just loop at each internal table, dump it into a final internal table then sort them, then delete adjacent duplicates...


loop at i_gl1.
  i_glfindent-hkont1 = i_gl1-hkont.
  i_glfindet-belnr1 = i_gl1-belnr.
  i_glfindet-bldat1 = i_gl1-bldat.
  i_glfindet-wrbtr1 = i_gl1-wrbtr.
  i_glfindet-vbund1 = i_gl1-vbund.
  i_glfindet-spc = ''.
  append i_glfindet.
endloop.

loop at i_gl2.
  i_glfindent-hkont1 = i_gl2-hkont.
  i_glfindet-belnr1 = i_gl2-belnr.
  i_glfindet-bldat1 = i_gl2-bldat.
  i_glfindet-wrbtr1 = i_gl2-wrbtr.
  i_glfindet-vbund1 = i_gl2-vbund.
  i_glfindet-spc = ''.
  append i_glfindet.
endloop.

sort i_glfindet by hkont1 belnr1 wrbtr1 bldat1 vbund1.

delete adjacent duplicates from i_glfindet.

hope this helps somehow...

Read only

Former Member
0 Likes
1,190

Hi,

If Iam not wrong , change the coding below.(In BOLD)

LOOP AT i_glfindet.

l_flag = l_flag + 1.

READ TABLE i_gl1

WITH KEY bukrs = i_glfindet-vbund2.

IF sy-subrc EQ 0.

i_glfindet-hkont1 = i_gl1-hkont.

i_glfindet-belnr1 = i_gl1-belnr.

i_glfindet-bldat1 = i_gl1-bldat.

i_glfindet-wrbtr1 = i_gl1-wrbtr.

i_glfindet-vbund1 = i_gl1-vbund.

<b>else.</b>

<b>i_glfindet-hkont1 = i_glfindet-hkont.

i_glfindet-belnr1 = i_glfindet-belnr.

i_glfindet-bldat1 = i_glfindet-bldat.

i_glfindet-wrbtr1 = i_glfindet-wrbtr.

i_glfindet-vbund1 = i_glfindet-vbund.</b>

ENDIF.

MODIFY i_glfindet.

IF l_flag GE l_line1.

EXIT.

ENDIF.

ENDLOOP.

This should work.

Regards,

GSR.

Read only

Former Member
0 Likes
1,191

Hi julius,

Just copy paste the code.


data: begin of itab1 occurs 4,
str1(10),
str2(10),
str3(10),
end of itab1.

data: begin of itab2 occurs 4,
str4(10),
str5(10),
str6(10),
end of itab2.

data: begin of itab3 occurs 4,
s1(10),
s2(10),
s3(10),
s4(10),
s5(10),
s6(10),
end of itab3.

itab1-str1 = 'apple'.
itab1-str2 = 'gundam'.
itab1-str3 = 'rock'.
append itab1.

itab1-str1 = 'oranges'.
itab1-str2 = 'robot'.
itab1-str3 = 'leaf'.
append itab1.

itab2-str4 = 'grape'.
itab2-str5 = 'book'.
itab2-str6 = 'siccors'.
append itab2.

if itab1 > itab2.
    loop at itab1.
       write sy-tabix.
       read table itab1 index sy-tabix.
       if sy-subrc = 0.
          read table itab2 index sy-tabix.
           if sy-subrc = 0.
             itab3-s1 = itab1-str1.
             itab3-s2 = itab1-str2.
             itab3-s3 = itab1-str3.
             itab3-s4 = itab2-str4.
             itab3-s5 = itab2-str5.
             itab3-s6 = itab2-str6. 
             append itab3.
           else.
             itab3-s1 = itab1-str1.
             itab3-s2 = itab1-str2.
             itab3-s3 = itab1-str3.
             itab3-s4 = ' '.
             itab3-s5 = ' '.
             itab3-s6 = ' '. 
             append itab3.
           endif.
       endif.
    endloop.
else.
loop at itab2.
       write sy-tabix.
       read table itab2 index sy-tabix.
       if sy-subrc = 0.
          read table itab1 index sy-tabix.
           if sy-subrc = 0.
             itab3-s1 = itab1-str1.
             itab3-s2 = itab1-str2.
             itab3-s3 = itab1-str3.
             itab3-s4 = itab2-str4.
             itab3-s5 = itab2-str5.
             itab3-s6 = itab2-str6. 
             append itab3.
           else.
             itab3-s1 = itab1-str1.
             itab3-s2 = itab1-str2.
             itab3-s3 = itab1-str3.
             itab3-s4 = ' '.
             itab3-s5 = ' '.
             itab3-s6 = ' '. 
             append itab3.
           endif.
       endif.
    endloop.

endif.

loop at itab3.
  write: / itab3.
endloop.

Hope it helps you.

regards,

Maheswaran.B

Read only

Former Member
0 Likes
1,190

Hello all, actually i have solved the problem, like the last post wrote... Thanks for ur time for hekping my problem

Regards,

Julius

Read only

0 Likes
1,190

Can U award points to the Useful answer and close this ..