2012 Aug 24 1:19 PM
hi i want to create an internal table having one field from first standard table and all fields from second internal table
and then populate that internal table.
hi i want to create an internal table having one field from first standard table and all fields from second internal table
and then populate that internal table.
2012 Aug 24 1:22 PM
Hi,
Create internal table A, fetch data from Standard table A.
Create internal table B, fetch data from Standard table B, if possible using for all entries in table A.
Create internal table C having fields from both the tables A and B. Now loop at internal table A, read Internal table B inside the loop and append records to internal table C.
Hope it helps. Thank you.
Regards,
Kartik
2012 Aug 24 1:28 PM
Hi Rishabh,
With reference to Kartik's reply, if you use 'for all entries' on internal table A while selecting data from database table B, internal table B will be the table with your required structure. There is no need to loop on it any further.
@Kartik: Correct me if I am wrong, please.
Regards,
Gautam
2012 Aug 24 1:33 PM
hi kartik how can i create internal table c having one field from first standard table and all fields from another standard table.
2012 Aug 24 4:12 PM
Hi Rishabh,
Let table A have the structure:
AAAA,
BBBB,
CCCC,
DDDD.
Let table B have the structure:
AAAA
EEEE
FFFF
GGGG
Now loop at table A and read table B to create the table C as follows:
Sort ITABB by AAAA.
Loop at ITABA into WA_A.
Read table ITABB into WA_B with key AAAA = WA_A-AAAA.
If sy-subrc = 0.
Append WA_B to ITABC.
Endif.
Clear: WA_A, WA_B.
Endloop.
Regards,
Gautam
2012 Aug 24 6:43 PM
how can i create internal table c having one field from first standard table and all fields from another standard table.you can use INCLUDE b , to include all fields of b
TYPES BEGIN OF struc_type_c.
...
{TYPES dtype ...} | {INCLUDE {TYPE|STRUCTURE} ...}.
...
TYPES END OF struc_type_c.
2012 Aug 24 1:28 PM
(FAQ) What did you try before posting, do you have any problem with SORT, LOOP AT, MODIFY or READ TABLE (BINARY SEARCH) statement ?
Regards,
Raymond
2012 Aug 24 1:39 PM
hi raymond i tried loop at and read table.
may be i m not clear
2012 Aug 24 1:38 PM
hi gupta,
please do this way..
ex: 2 tables
mara, marc.
data : lt_mara like mara occurs 0 with header line.
data : lt_marc like marc occurs 0 with header line.
output table :
data :begin of output,
matnr like mara-matnr,
ernam like mara-ernam,
werks like marc-werks,
pstat like marc-pstat
end of output.
start-of selection
select * from mara into corresponding fileds of lt_mara where matnr eq p_matnr
if sy-subrc = 0.
select * from marc form all entries in lt_mara into table lt_marc where matnr eq lt_mara-matnr.
endif.
end-of selection
loop at lt_mara.
read table lt_marc with key matnr eq lt_marc-matnr
move the values to output
append output.
endloop.
hope that helps...
thank you,
kata.
2012 Aug 24 9:36 PM
2012 Aug 25 2:56 AM
Hello,
One question... Your source tables and their fields changes in runtime? if that so, you have to use RTTS. If not, just define:
TYPES: BEGIN OF t_type,
field_tab1 TYPE <data_elemnt_tab1>.
INCLUDE STRUCTURE <table_name2>.
TYPES: END OF t_type.
TYPES: tt_type TYPE TABLE OF t_type.
Regards,
John.
2012 Aug 27 3:13 PM
As what i think..
You have two internal tables and you want one field from ITAB_A and Rest all fields from ITAB_B.
Suppose your Standard tables A and B
Two methods are there :
1) Select filed1 from A into table ITAB_A where <Cond>.
if ITAB_A is not initial .
Select * from B into table ITAB_B for all entries in ITAB_A
where field1 eq ITAB_A-field1.
endif.
Loop at ITAB_B into WA_B.
<here you can pass your data to the final internal table for display >
WA_Final-field1 = WA_B-Filed1.
WA_Final-field2 = WA_B-Filed2
.
.
.
WA_Final-fieldn = WA_B-Filedn.
append wa_final to itab_final.
clear : wa_final, wa_b.
Endloop.
2) Suppose your field1 is not there in the table B.
data : n1 type i,
n2 type i.
Select field1 from A into table ITAB_A where <Condition>.
select * from B into table ITAB_B where <Condition>.
DESCRIBE TABLE itab_A LINES n1." Count the number of records available for itab_a.
DESCRIBE TABLE itab_B LINES n2." Count the number of records available for itab_b.
if (n1 ge n2).
loop at itab_a into wa_a.
wa_final-field1 = wa_b-field1.
read table itab_b into wa_b with key <condition for key field>.
wa_final-field2 = wa_b-field2.
wa_final-field3 = wa_b-field3.
.
.
.
wa_final-fieldn = wa_b-fieldn.
append wa_final to itab_final.
clear : wa_final,
wa_a, wa_b.
endloop.
else.
loop at itab_b into wa_b.
wa_final-field2 = wa_b-field2.
wa_final-field3 = wa_b-field3.
.
.
.
wa_final-fieldn = wa_b-fieldn.
read table itab_a into wa_a with key <condition for key field>.
wa_final-field1 = wa_b-field1.
append wa_final to itab_final.
clear : wa_final,
wa_a, wa_b.
endloop.
endif.
Please correct me if i am wrong anywhere.
Thanks and Regards,
Swarnadeepta.