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

regarding internal table

Former Member
0 Likes
823

hi gurus

i have datas in three int. tables.

i want to make one final int. table , that will contain all 3 int. table datas..how to do it...

please help.

regards

subhasis

9 REPLIES 9
Read only

Former Member
0 Likes
794

Hi,

Use like:

Append lines of itab1 to itab4.

Append lines of itab2 to itab4.

Append lines of itab3 to itab4.

Regards,

Renjith Michael..

Read only

Former Member
0 Likes
794

Hi,

Try this. I guess this will help you

select k~kunnr,

k~name1,

k~ort01,

k~land1,

v~vbeln,

v~erdat,

v~netwr,

a~posnr,

a~arktx,

a~werks,

INTO CORRESPONDING FIELDS OF TABLE t_orders from

(kna1 as k inner join vbak as v

on kkunnr = vkunnr)

inner join vbap as a

on vvbeln = avbeln

where k~kunnr in s_custno

and v~vbeln in s_orderno.

This is one more Report... go through this it will b helpful

TABLES: vbak,kna1.

DATA: BEGIN OF t_table OCCURS 0,

kunnr LIKE kna1-kunnr,

name1 LIKE kna1-name1,

ort01 LIKE kna1-ort01,

land1 LIKE kna1-ort01,

vbeln LIKE vbak-vbeln,

erdat LIKE vbak-erdat,

netwr LIKE vbak-netwr,

posnr LIKE vbap-posnr,

arktx LIKE vbap-arktx,

werks LIKE vbap-werks,

END OF t_table.

SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-001.

SELECT-OPTIONS: s_kunnr for kna1-kunnr ,

s_vbeln for vbak-vbeln .

SELECTION-SCREEN END OF BLOCK b.

START-OF-SELECTION.

SELECT kkunnr kname1 kort01 kland1 vvbeln verdat v~netwr

aposnr aarktx a~werks INTO CORRESPONDING FIELDS OF TABLE t_table

FROM ( kna1 as k INNER JOIN vbak as v ON kkunnr = vkunnr ) INNER JOIN

vbap as a on vvbeln = avbeln WHERE kkunnr in s_kunnr AND vvbeln in

s_vbeln.

IF sy-subrc = 0.

SORT t_table BY kunnr vbeln.

ELSE.

MESSAGE i000(zsa) WITH 'NO DATA FOUND'.

ENDIF.

LOOP AT t_table.

WRITE:/ t_table-kunnr,

t_table-name1,

t_table-ort01,

t_table-land1,

t_table-vbeln,

t_table-erdat,

t_table-netwr,

t_table-posnr,

t_table-arktx,

t_table-werks.

ENDLOOP.

Regards.

Read only

Former Member
0 Likes
794

Hi,

If the structure of all 3 internal tables are same then you can use append lines of statement to append to one table one by on.

regards

kamath

Read only

Former Member
0 Likes
794

Hi Subhasis,

You can do this in many ways.

Some of them are as follows.

But the prerequisite is that u need to have a relation between the internal tables.

1) Using join statements in the select query u first join 2 tables

then use the joined table with other internal table to obtain the final internal table.

2) Using FOR ALL ENTRIES.

3)Using Views.

In this u create a view using all the tables that u have used in the internal tables.And then write a select query on that view to extract the required data.

Now i am providing a sample code to retrieve using For all entries.

tables : mara,

marc,

mard.

types : begin of ty_mara,

matnr like mara-matnr,

meins like mara-meins,

ersda like mara-ersda,

end of ty_mara,

begin of ty_marc,

matnr like marc-matnr,

werks like marc-werks,

end of ty_marc,

begin of ty_mard,

matnr like mard-matnr,

lgort like mard-lgort,

end of ty_mard,

begin of ty_final,

matnr like mara-matnr,

meins like mara-meins,

ersda like mara-ersda,

werks like marc-werks,

lgort like mard-lgort,

end of ty_final.

data : i_mara type standard table of ty_mara with header line,

i_marc type standard table of ty_marc with header line,

i_mard type standard table of ty_mard with header line,

i_final type standard table of ty_mard with header line.

start-of-selection.

select matnr meins ersda from mara into table i_mara.

if sy-subrc <> 0.

message 000.

endif.

if i_mara[] is not initial.

select matnr werks

from marc

into table i_marc

for all entries in i_mara

where matnr = i_mara-matnr.

if sy-subrc <> 0.

message 000.

endif.

endif.

if i_marc[] is not initial.

select matnr werks logrt

from mard into table i_mard

for all entries in i_marc

where matnr = i_marc-matnr.

if sy-subrc <> 0.

message 000.

endif.

endif.

loop at i_mara.

move : i_mara-matnr to i_final-matnr,

i_mara-meins to i_final-meins,

i_mara-ersda to i_final-ersda.

read table i_marc with key i_mara-matnr.

move : i_marc-werks to i_final-werks.

read table mard with key i_mara-matnr.

move : i_mard-logrt to i_final-logrt.

append i_mara.

endloop.

now loop at final table and do wat ever u want.

Hope this answers ur query.

Reward points if useful.

Thanks And Regards,

Chaitanya.

Read only

Former Member
0 Likes
794

1) Using join statements in the select query u first join 2 tables

then use the joined table with other internal table to obtain the final internal table.

2) Using FOR ALL ENTRIES.

3)Using Views.

In this u create a view using all the tables that u have used in the internal tables.And then write a select query on that view to extract the required data.

Now i am providing a sample code to retrieve using For all entries.

tables : mara,

marc,

mard.

types : begin of ty_mara,

matnr like mara-matnr,

meins like mara-meins,

ersda like mara-ersda,

end of ty_mara,

begin of ty_marc,

matnr like marc-matnr,

werks like marc-werks,

end of ty_marc,

begin of ty_mard,

matnr like mard-matnr,

lgort like mard-lgort,

end of ty_mard,

begin of ty_final,

matnr like mara-matnr,

meins like mara-meins,

ersda like mara-ersda,

werks like marc-werks,

lgort like mard-lgort,

end of ty_final.

data : i_mara type standard table of ty_mara with header line,

i_marc type standard table of ty_marc with header line,

i_mard type standard table of ty_mard with header line,

i_final type standard table of ty_mard with header line.

start-of-selection.

select matnr meins ersda from mara into table i_mara.

if sy-subrc 0.

message 000.

endif.

if i_mara[] is not initial.

select matnr werks

from marc

into table i_marc

for all entries in i_mara

where matnr = i_mara-matnr.

if sy-subrc 0.

message 000.

endif.

endif.

if i_marc[] is not initial.

select matnr werks logrt

from mard into table i_mard

for all entries in i_marc

where matnr = i_marc-matnr.

if sy-subrc 0.

message 000.

endif.

endif.

loop at i_mara.

move : i_mara-matnr to i_final-matnr,

i_mara-meins to i_final-meins,

i_mara-ersda to i_final-ersda.

read table i_marc with key i_mara-matnr.

move : i_marc-werks to i_final-werks.

read table mard with key i_mara-matnr.

move : i_mard-logrt to i_final-logrt.

append i_mara.

endloop.

now loop at final table and do wat ever u want.

Read only

Former Member
0 Likes
794

Append lines of itab A to itabZ.

Append lines of itab B to itabZ.

Append lines of itab C to itabZ

DO REWARD IF USEFUL.

Read only

Former Member
0 Likes
794

Hi,

If u want to copy data from itab1 to itab2 then you can use,

itab2] = itab1[.

If u want to copy only few lines(say from 1 to 3) of itab1 to itab2 then yo can use,

append lines of itab1 from 1 to 3 to itab2.

If both the internal tables are not of the same structure,

say only fields f1 and f2 are common,then ypu have to copy the data in the following way,

loop at itab1.

itab2-f1 = itab1-f1.

itab2-f2 = itab1-f2.

append itab2.

clear itab2.

endloop.

if there are many common fields then...

loop at itab1.

move-corresponding itab1 to itab2.

append itab2.

clear itab2.

endloop.

If the internal tables are not of the same structure, you'll need to loop through itab1 and write the corresponding fields to itab2.

If the internal table contains fields with character types and if the tables are of different structures,then you will have to copy from the first internal table to the sesond internal table using the offset of the first internal table.

itab2-f1 = itab1-f1 + O(index)

Reward points if usefull

Reward if found helpfull,

Cheers,

Chaitanya.

Read only

RoySayak
Active Participant
0 Likes
794

Hi Subhasis,

You can try it... using your logic i think its work...

>>

SELECT f1 f2 f3 f4 f5

FROM main1 INTO TABLE it_main1

WHERE f1 IN <S1>.

SORT it_main1 BY f1.

IF it_main1[] IS NOT INITIAL.

SELECT a1 a2 a3 a4 a5

FROM table1 INTO TABLE it_table1

FOR ALL ENTRIES IN it_main1

WHERE a1 = it_main1-f1.

SELECT ******

******

******

SELECT******

*****

******

ENDIF.

LOOP AT it_table1 INTO wa_table1.

READ TABLE it_main1 INTO wa_main1 WITH KEY f1 = wa_table1-a1.

READ TABLE it_main2 INTO wa_main2 WITH KEY ********************.

READ TABLE it_main3 INTO wa_main3 WITH KEY ********************.

wa_final-x1 = wa_table1-a1.

wa_final-x2 = wa_table1-a2.

wa_final-x3 = wa_main1-f2.

wa_final-x4 = wa_main1-f3.

wa_final-x5 = wa_main1-f5.

wa_final-x6 = wa_table2-p1.

wa_final-x7 = wa_table2-p6.

.

.

.

APPEND wa_final TO it_final.

ENDLOOP.

*********************************************************************reward points if it is useful***********************

thanks,

SAYAK..

Read only

Former Member
0 Likes
794

hi,

U have already got the best solutions for what u have asked.....

Try n work on them......if possible close this query.

Regards.