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

Combining Internal tables

Former Member
0 Likes
591

Hello, have 2 internal tables. both have different structures but there is one field in both tables which is the same but it is named differently in both internal tables.

internal table 1 has a lot of fields but i only want these fieldS:


MATNR
BUKRS
BELNR

Internal table 2 has a lot of fields but i only want these fields:

PartNumber
Store

What I did is this.
I created one final internal table and declared it as this.

TYPES: BEGIN OF s_fin,
MATNR type MARA-MATNR,
BUKRS type BSEG-BUKRS,
BELNR type BSEG_BELNR,
Part  type MATNR-MATNR,
Store type Zext-Store,
END OF s_fin.  

DATA: int_fin type standard table of s_fin,
      wa_int_fin type s_fin.

LOOP AT IT_TAB1 INTO WA_TAB1.
wa_int_fin-MATNR = WA_IT_TAB1-MATNR.
.
.
.
wa_int_fin-PART = WA_IT_TAB2-PART.
wa_int_fin-store= WA_IT_TAB2-STORE.

APPEND WA_itab_final to itab_final.

ENDLOOP.

The problem is that data in my first internal table is coming in my final table fine but, second internal table keeps sending one store number to my final table. somehow i need to refresh the work area of my second table as well and also match Material number to part number. I am not sure how to do that. Please help.

Thanks.


Thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
551

Hi Venkat,

How do you select the correct values for your workarea of table 2? Is it somewhere replaced by the three dots?

wa_int_fin-MATNR = WA_IT_TAB1-MATNR.

.

.

.

wa_int_fin-PART = WA_IT_TAB2-PART.

What is the cardinality between table 1 and 2?

If there's a 1-on-1 relationship and the common field is TAB1-MATNR = TAB2-Partnumber, you could use a READ TABLE statement.

If there's a 1-on-n or vice versa, you should use a LOOP through TAB2 with a WHERE condition for Partnumber = TAB1-MATNR.

I've added a few lines for the 1-on-1 case. It all boils down to matching a line(s) from TAB1 to TAB2 using a READ or LOOP of TAB2.

TYPES: BEGIN OF s_fin,
MATNR type MARA-MATNR,
BUKRS type BSEG-BUKRS,
BELNR type BSEG_BELNR,
Part  type MATNR-MATNR,
Store type Zext-Store,
END OF s_fin. 

DATA: int_fin type standard table of s_fin,
      wa_int_fin type s_fin.

LOOP AT IT_TAB1 INTO WA_TAB1.
wa_int_fin-MATNR = WA_IT_TAB1-MATNR.
.
.
.

READ TABLE it_itab2 into WA_IT_TAB2 with key Partnumber = WA_TAB1-MATNR.

IF sy-subrc = 0.
wa_int_fin-PART = WA_IT_TAB2-PART.
wa_int_fin-store= WA_IT_TAB2-STORE.

ENDIF. <= Depends on whether you want to add the line regardless of a matching entry TAB2

APPEND WA_itab_final to itab_final.

"or here: ENDIF. <= Depends on whether you want to add the line regardless of a matching entry TAB2

ENDLOOP.

2 REPLIES 2
Read only

Former Member
0 Likes
552

Hi Venkat,

How do you select the correct values for your workarea of table 2? Is it somewhere replaced by the three dots?

wa_int_fin-MATNR = WA_IT_TAB1-MATNR.

.

.

.

wa_int_fin-PART = WA_IT_TAB2-PART.

What is the cardinality between table 1 and 2?

If there's a 1-on-1 relationship and the common field is TAB1-MATNR = TAB2-Partnumber, you could use a READ TABLE statement.

If there's a 1-on-n or vice versa, you should use a LOOP through TAB2 with a WHERE condition for Partnumber = TAB1-MATNR.

I've added a few lines for the 1-on-1 case. It all boils down to matching a line(s) from TAB1 to TAB2 using a READ or LOOP of TAB2.

TYPES: BEGIN OF s_fin,
MATNR type MARA-MATNR,
BUKRS type BSEG-BUKRS,
BELNR type BSEG_BELNR,
Part  type MATNR-MATNR,
Store type Zext-Store,
END OF s_fin. 

DATA: int_fin type standard table of s_fin,
      wa_int_fin type s_fin.

LOOP AT IT_TAB1 INTO WA_TAB1.
wa_int_fin-MATNR = WA_IT_TAB1-MATNR.
.
.
.

READ TABLE it_itab2 into WA_IT_TAB2 with key Partnumber = WA_TAB1-MATNR.

IF sy-subrc = 0.
wa_int_fin-PART = WA_IT_TAB2-PART.
wa_int_fin-store= WA_IT_TAB2-STORE.

ENDIF. <= Depends on whether you want to add the line regardless of a matching entry TAB2

APPEND WA_itab_final to itab_final.

"or here: ENDIF. <= Depends on whether you want to add the line regardless of a matching entry TAB2

ENDLOOP.

Read only

0 Likes
551

Hi Zhou,

I Hope the below piece of code will help you,

Loop at IT_TAB1 into WA_TAB1.

wa_int_fin-part = wa_it_tab1-matnr.

**** Pass the values from int table one to the final table

Read table it_tab2 into wa_it_tab2 with key partnumber = wa_tab1-matnr.

*** Read the values from table 2 based on the value in work area of table 1.

wa_int_fin-part = wa_it_tab2-part.

***No pass the values from internal table 2 to final table.

Append wa_int_fin to itab_final.

clear wa_int_fin. (Don not forget to clear all the work areas of all internal table after each append)

endloop.

Regards,

Satish