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

Logic for Select

Former Member
0 Likes
1,136

Hi,

I have two internal tables.

Table 1:

Shipment Reason Codes Delivery Number

D1 77789

D2 77789

Table 2:

Shipment Delivery Number

120 77789

121 77789

122 77790

One of the table is in vertical and the other table is in horizontal records. I need to loop table 2 in table 1 where I am expecting my records to be as

120 D1 77789

121 D2 77789

Let me know the logic of achieving this.

Edited by: Krish on Mar 9, 2010 9:58 AM

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,070

hi,

Put the INNER JOIN on the table 1 and table 2.

hope this helps

Regards

Ritesh

10 REPLIES 10
Read only

Former Member
0 Likes
1,071

hi,

Put the INNER JOIN on the table 1 and table 2.

hope this helps

Regards

Ritesh

Read only

0 Likes
1,070

Hi,

I was not clear about the requirement.

Table 1 would be

Shipment 1 Shipment 2 Shipment 3 Shipment 4 Delivery Number

Table 2 would be

Delivery Number Shipment Number

11000 101

11000 102

11000 103

11090 104

Based on the delivery number, I need my table 1 to be

Shipment 1 Shipment 2 Shipment 3 Shipment 4 Delivery Number

101 102 103 11000

104 11090

Let me know the code for the same.

Regards

Krish

Read only

0 Likes
1,070

Hi,

Are you getting values in both the internal tables.... aslo the shipment 1 to 4 is this constant??

Regards,

Nagaraj

Read only

0 Likes
1,070

Yes, it is always constant.

Read only

0 Likes
1,070

Hello,

We are assuming that the connecting field between the two tables is delivery number. now based on the delivery number you need to populate the table1 with values of shipment number from table2 into shipment1,shipment2 etc.

maybe try something like


data: itabix type sy-tabix,
         otabix type sy-tabix.
loop at table1.
 otabix = sy-tabix
 loop at table 2 where delverynumber = table1-deliverynumber.
 itabix = sy-tabix.  
 case itabix.
  when 1.
    table1-shipment1 = table2-shipment number
  when 2.
    table1-shipment2 = table2-shipment number
  when 3.
    table1-shipment3 = table2-shipment number
  when 4.
    table1-shipment4 = table2-shipment number
  endcase.
 endloop.
 modify table1 index otabix.
endloop

Hope this helps.

Regards

Sachin

Read only

0 Likes
1,070

Hello,

Try this sample code


data: begin of itab1 OCCURS 0,
      s1(10) type c,
      s2(10) type c,
      s3(10) type c,
      s4(10) type c,
      dn(10) type c,
     end of itab1.

data: begin of itab2 occurs 0,
      dn(10) type c,
      s1(10) type c,
     end of itab2.

FIELD-SYMBOLS: <wa> like LINE OF itab2,
               <comp> type any.


itab1-dn = '11000'.
append itab1.


itab1-dn = '11090'.
append itab1.


itab2-dn = '11000'.
itab2-s1 = '101'.
append itab2.

itab2-dn = '11000'.
itab2-s1 = '102'.
append itab2.

itab2-dn = '11000'.
itab2-s1 = '103'.
append itab2.

itab2-dn = '11090'.
itab2-s1 = '104'.
append itab2.

data: i type c,
      temp type string.


loop at itab1.
do 4 times.
  i = i + 1.
CONCATENATE 's' i into temp.
CONCATENATE 'itab1-' temp INTO temp.
assign (temp) to <comp>.
read TABLE itab2 INDEX i.
  ASSIGN itab2 to <wa>.
  <comp> = <wa>-s1.
ENDDO.

modify itab1.
endloop.

Vikranth

Read only

0 Likes
1,070

Hi,

Table 1 would be

Shipment 1 Shipment 2 Shipment 3 Shipment 4 Delivery Number

data: begin of itab1 occurs 0,

shipment1,

shipment2

shipment3

shipment4,

delivery number,

end of itab1.

Table 2 would be

Delivery Number Shipment Number

11000 101

11000 102

11000 103

11090 104

data: begin of itab2 occurs 0,

delivery number,

shipment number,

end of itab2.

data: itab3 like itab2 occurs 0 with header line.

itab3[] = itab2[].

sort itab3 by delivery number.

delete adjucent duplicates from table itab3 comparing delivery number.

loop at itab3.

loop at itab2 where delivery number = itab3-delivery number.

case itab2-shipment number.

when '101'.

itab1-shipment number1 = itab2-shipment number.

when '102'.

itab1-shipment number2 = itab2-shipment number.

when '103'.

itab1-shipment number3 = itab2-shipment number.

when '104'.

itab1-shipment number4 = itab2-shipment number.

endloop.

itab1-delivery number = itab3-delivery number.

append itab1.

clear itab1.

endloop.

Regards,

ashok

Read only

0 Likes
1,070

hi Krish,

According to my understanding you can achieve your query result by this method.


types: begin of ty_table1,
          ship type char255,
         delivery type delivery " your delivery dataelement.
           end of ty_table1,

          begin of ty_table2,
         delivery type delivery " your delivery dataelement.
         shipmentnumber      type shipment number"your shipment data element
           end of ty_table1,

data: wa_table2 type ty_table2,
        wa_table1 type ty_table1,
       i_table2 type table of ty_table2,
      i_table1 type table of ty_table1, 
     con_tab                TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.
       ship                        type char255.
loop at i_table2 into wa_table2.
 CONCATENATE: wa_table2-shipmentnumber
                          into ship
                          SEPARATED BY con_tab.
at end of delivery.
wa_table1-ship = ship.
wa_table1-delivery = wa_table2-delivery.
append wa_table2 to i_table2. 
ship = space.
clear wa_table1.
endat.
endloop.

i think this should help you since you have many shipment numebr for a single delivery you can concatenate it in string.

thanks

tanmaya

Read only

former_member404244
Active Contributor
0 Likes
1,070

Hi,

As you have delivery number in common you can loop the two tables and then modify the second table..... is this what you want??

Regards,

Nagaraj

Read only

Former Member
0 Likes
1,070

Please try this code

loop at it_tab1 into wa_tab1.

read table it_tab2 into wa_tab2 with key fld1 = wa_tab1-fld1

fld2 = wa_tab1-fld2

BINARY SEARCH.

if sy-subrc = 0.

move-corresponding fields wa_tab1 to wa_tab.

move-corresponding fields wa_tab2 to wa_tab.

append wa_tab to it_tab.

endif.

endloop.