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

Populating internal table

Former Member
0 Likes
1,119

hi all,

I have to populate an interbal table with the data in a source table. The tables are in the following format.

please tell me the logic, if possible give me the sample code for updating the target internal table.

Source database Table 1

Description Customer Group Price

ABC 11 XXX

ABC 12 YYY

ABC 14 ZZZ

Retailer u2013 12; Dealer u2013 11; Processor u2013 14.

Target Internal Table

Description Retailer Dealer Processor

ABC YYY XXX ZZZ

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,074

Hi,

check this code..

sort table1 by Description.

Loop at table1.

if Customer Group eq '12'.

targett-Retailer = table1-price.

endif.

if Customer Group eq '11'.

targett-Dealer = table1-price.

endif.

if Customer Group eq '14'.

targett-Processor = table1-price.

endif.

at end of Description.

targett-description = table1-description. (Corrected>>>>>>>>>)

append targett.

clear targett.

endat.

endloop.

9 REPLIES 9
Read only

Former Member
0 Likes
1,074

Hi,

Can you please specify the structures of the tables again. Are there two source tables?

Rgds,

Vartika

Read only

Former Member
0 Likes
1,074

Hi,

check this code..

sort table1 by Description.

Loop at table1.

if Customer Group eq '12'.

targett-Retailer = table1-price.

endif.

if Customer Group eq '11'.

targett-Dealer = table1-price.

endif.

if Customer Group eq '14'.

targett-Processor = table1-price.

endif.

at end of Description.

append targett.

clear targett.

endat.

endloop.

Read only

Former Member
0 Likes
1,074

Hi Rajan,

You can READ the first internal table based on Retailer (12), Dealer (11) and Processor (14).

Then based on the selected record, READ your second Internal table.

If a record is found MODIFY the existing record.

if NO record is found APPEND the selected records as per the requirement to your second internal table.

E.G.


READ ITAB1 INTO W_ITAB1 WITH KEY CUSTOMER GROUP = 12.
IF SY-SUBRC eq 0.
    " MODIFY
ELSE.
     " APPEND
ENDIF.

This you can carry on in a loop to acheive for multiple records.

Best Regards,

Ram.

Read only

Former Member
0 Likes
1,074

Suppose internal table itab(with workarea wa) has data.

ABC 11 XXX

ABC 12 YYY

ABC 14 ZZZ

and itab2 is the target table with wa2 as workarea

So

Loop at itab into wa.

wa2-description = wa-description.

if wa-custgrp = 11.

wa2-dealer = wa-price. "(XXX)

endif.

if wa-custgrp = 12.

wa2-retailer = wa-price. "(YYY)

endif.

if wa-custgrp = 14.

wa2-processor = wa-price. "(ZZZ)

endif.

ENDLOOP.

append wa2 to itab2.

itab2 will have data you want.

Regards,

Prashant

Read only

Rodrigo-Giner
Active Contributor
0 Likes
1,074

>

> hi all,

>

> I have to populate an interbal table with the data in a source table. The tables are in the following format.

>

> please tell me the logic, if possible give me the sample code for updating the target internal table.

>

> Source database Table 1

>

>

> Description Customer Group Price

>

> ABC 11 XXX

>

> ABC 12 YYY

>

> ABC 14 ZZZ

>

>

> Retailer u2013 12; Dealer u2013 11; Processor u2013 14.

>

>

>

> Target Internal Table

>

> Description Retailer Dealer Processor

> ABC YYY XXX ZZZ

Make sure that description is the first field of the it (internal table).

it is this:

Description Customer Group Price

ABC 11 XXX

ABC 12 YYY

ABC 14 ZZZ

and it_aux will be:

Description Retailer Dealer Processor

ABC YYY XXX ZZZ

*Example:*
SORT it BY description.
LOOP AT it.
  CASE it-customer.
     WHEN 11. 
         it_aux-dealer = it-GroupPrice.
     WHEN 12. 
         it_aux-retailer = it-GroupPrice.
     WHEN 14. 
         it_aux-processor = it-GroupPrice.
  ENDCASE.
AT END OF Description.
  it_aux-Description = it-description.
  APPEND it_aux.
ENDAT.
ENDLOOP.

tell me If u had any problem.

gl

Read only

Former Member
0 Likes
1,074
LOOP AT itab_source where cust_group = '11'.
  itab_target-description = itab-source-description.
  APPEND itab_target.
ENDLOOP.

LOOP AT itab_target.
  wa_tabix = sy-tabix.
  READ TABLE itab_source WITH KEY cust_group = '12'.
  IF sy-subrc = 0.
    itab-target-retailer = itab_source-price.
  ENDIF.
  READ TABLE itab_source WITH KEY cust_group = '13'.
  IF sy-subrc = 0.
    itab-target-dealer = itab_source-price.
  ENDIF.
  MODIFY itab INDEX wa_tabix TRANSPORTING retailer dealer.
ENDLOOP.

This should solve your problem

Read only

Former Member
0 Likes
1,075

Hi,

check this code..

sort table1 by Description.

Loop at table1.

if Customer Group eq '12'.

targett-Retailer = table1-price.

endif.

if Customer Group eq '11'.

targett-Dealer = table1-price.

endif.

if Customer Group eq '14'.

targett-Processor = table1-price.

endif.

at end of Description.

targett-description = table1-description. (Corrected>>>>>>>>>)

append targett.

clear targett.

endat.

endloop.

Read only

0 Likes
1,074

Thanks got the logic right!

Read only

Former Member
0 Likes
1,074

Hi Rajan,

I assume that 'Description, Customer Group and Price' are in table1 and

'Retailer, Dealer and Processor' are present in another table say table2,

then you can try the following logic,

LOOP AT it_table2 INTO wa_table2.
  READ TABLE it_table1 INTO wa1_table1
           WITH KEY custgrp = wa_table2-retailer.

  READ TABLE it_table1 INTO wa2_table1
           WITH KEY custgrp = wa_table2-dealer.

  READ TABLE it_table1 INTO wa3_table1
           WITH KEY custgrp = wa_table2-processor.
*  Checking whether decription are same
  IF wa1_table1-desc EQ wa2_table1-desc.
    IF wa1_table1-desc EQ wa3_table1-desc.

*  If they are same then fill the target table
      wa_target-desc = wa1_table1-desc.
      wa_target-retailer = wa1_table1-price.
      wa_target-dealer = wa2_table1-price.
      wa_target-processor = wa3_table1-price.

      APPEND wa_target TO it_target.

    ENDIF.
  ENDIF.
ENDLOOP.

Regards,

Manoj Kumar P

Edited by: Manoj Kumar on Dec 10, 2008 2:11 PM