2012 Aug 13 8:25 PM
Hi good day, i have a question about report, I have 2 structure table, so these have differents fields and information, i need to get the information and save it into new structure table.
How can i do it? I .
I already created the structure with all fields from two tables and the same data types.
Table 1 has 5 records, Table 2 has 50 records,
I have tryed with Loop:
Loop at Table1
move Table1-field1 to New_structure-Field1
move Table1-field1 to New_structure-Field1.
.........................
ENDLOOP.
LOOP AT TABLE2
move Table2-field2 to New_structure-Field2.
move Table2-field2 to New_structure-Field2.
.............................
ENDLOOP.
It works, and retrieve records from both tables, but result set is according to first table, i mean, total rows are 5.
Thank you for all your advices!.
2012 Aug 14 7:30 AM
Hi Saul,
What you are trying to do ? From internal tabel you want to update the structure table (SE11)?
For Ex:
If you have the 2 internal tables and 2 DB tables.
1. Fetch the records from SE11 2 DB table and populate the 2 internal tables.
2. Create the SE11 structure and an internal table(FINAL) .
3. Loop the 2 internal tables and move to the final internal table(FINAL).
4. Use INSERT statement with FINAL internal table and update the structure you want to update .
INSERT Structure from FINAL(Internal table).
Thanks,
Pradeep.
2012 Aug 14 7:06 AM
2012 Aug 14 7:30 AM
Hi Saul,
What you are trying to do ? From internal tabel you want to update the structure table (SE11)?
For Ex:
If you have the 2 internal tables and 2 DB tables.
1. Fetch the records from SE11 2 DB table and populate the 2 internal tables.
2. Create the SE11 structure and an internal table(FINAL) .
3. Loop the 2 internal tables and move to the final internal table(FINAL).
4. Use INSERT statement with FINAL internal table and update the structure you want to update .
INSERT Structure from FINAL(Internal table).
Thanks,
Pradeep.
2012 Aug 14 7:48 AM
Hi,
If the table1 have header data and Tbale2 have the Item level data. Means the bussines should be Header level data(Comman for all items) and Item related data.
Ex : A single user bye the 10 no of items. So these 10 number of items have the byer details should be same (Header details).
If your bussiness requriment is like above.
there Table1 and Table2 have some relation field.
So you can Achive your requriment like below.
Loop the Item table (Table2 - 50 records)
move the fields values to final internal table.
Read the Table1 with respect to relation fields of Table2.
move the filed values of work area of Table1 to Final internal table.
Endloop.
2012 Aug 14 8:28 AM
Hi Saul,
Can you please paste the code for the two loop statements you are using?
Regards,
Gautam
2012 Aug 14 5:45 PM
Hi Gautam, this is the code of loop:
LOOP AT it1 into wa1.
clear: wa3, wa2.
move-corresponding wa1 to wa3.
read table it2 into wa2 with key BAPINOTE_elem_no = wa1-elem_no.
IF sy-subrc eq 0 .
move-corresponding wa2 to wa3.
ENDIF.
append wa3 to it_data.
ENDLOOP.
LOOP AT IT_DATA ASSIGNING <STRUCT>.
MOVE-CORRESPONDING <STRUCT> TO zstuct_ftnbapi.
ENDLOOP.
it works, but just with key tables. So the tables does not have relationship. So result set just retrieve records according the condition statement and not show all records from second table
2012 Aug 14 10:47 AM
Hi,
Looping Table 1 separately and Table 2 separately will not work in your scenarios.
That’s obvious if you are looping both tables separately then you will get only 1 tables data in your 'New_structure'.
So solution for this is if your two tables having some relation (Common key field/s) then you can loop one(Header) table and Read another(Item level).
If No relation in two tables means you can loop in side loop, But for performance constraints we should not loop in side loop.
2012 Aug 14 11:39 AM
hi saul ,
First find out the link in table1 and table2 , as you have to join them .
after finding the link surely they are the common fields in table1 & table2 :
loop at table1 / table2 .
move the field value of table1 / table2 into new structure.
read table2 / table1 with key .
move the field value of table1 / table2 into new structure.
append the new structure into new table.
endloop.
new table will contain the required data you need.
Regards ,
Yogendra Bhaskar
2012 Aug 14 5:51 PM
Hi Yogendra, the tables does not have relationship, the result is from a function, and i need to save it into a new structure.
I have did with key, but not show all records from second table, I have posted code from the loop to Gautam.
2012 Aug 16 5:41 AM
hi saul ,
did you mean for wa1-elem_no you have multiple values in it2 .
In that case , you must loop at it2 and append , rather than the read statement.
Regards ,
Yogendra Bhaskar