Populating one Internal table from two internal tables.
Hello Gurus,
iam having 3 internal table with same structure ,
1st internal table having some records
2nd internal table is also having some records
what i need to do is to populate the records to the 3rd internal table which the common records in the 1st and 2nd internal table. (common means intersection).
please explain how and using which concept and if possible code also...
Regards,
Ravi.
hi ravi,
look at the folowing code for reference
*&--mard structure
types: begin of struc_mard,
matnr type matnr, "Material Number
werks type werks_d, "Plant
lgort type lgort_d, "Storage Location
labst type labst, "Valuated stock with unrestricted use
end of struc_mard.
*&--mara structure
types: begin of struc_mara,
matnr type matnr, "material number
meins type meins, "unit of measurement
mtart type mtart, "material type
ersda type ersda, "Creation date
end of struc_mara.
*&--maktx structure
types: begin of struc_maktx,
matnr type matnr, "material number
maktx type maktx, "material description
end of struc_maktx.
*&--Final structure
types: begin of struc_final,
matnr type matnr, "Material Number
werks type werks_d, "Plant
lgort type lgort_d, "Storage Location
labst type labst, "Valuated stock with unrestricted use
meins type meins, "unit of measurement
mtart type mtart, "material type
ersda type ersda, "Creation date
maktx type maktx, "material description
v_box(1) type c, "for checkbox field
end of struc_final.
*&---work area for Internal Tables[population 1]
data: wa_mard type struc_mard,
wa_mara type struc_mara,
wa_maktx type struc_maktx,
wa_final type struc_final.
INTERNAL TABLES DECLARATION *
*&---Internal tables for storing data.[populaiton 1]
data: i_mard type standard table of struc_mard,
i_mara type standard table of struc_mara,
i_maktx type standard table of struc_maktx,
i_final type standard table of struc_final.
*&--fetching the data from table for storage
select matnr
werks
lgort
labst
into table i_mard
from mard
where matnr in r_matnr and werks in r_werks and lgort in
r_lgort
if sy-subrc <> 0. "if unsuccesful
message e004. "Error- Record does not exist
endif.
selection of material description
if i_mard[] is not initial.
*SELECT DISTINCT FOR UNIQUE ENTRIES ONLY
select distinct matnr
maktx
into table i_maktx
from makt
for all entries in i_mard
where matnr = i_mard-matnr and
spras = sy-langu.
if sy-subrc <> 0. " if unsucessful
wa_maktx-maktx = text-028. "NO DESCRIPTION
endif.
*fetching information from material master
select distinct matnr
meins
mtart
ersda
into table i_mara
from mara for all entries in i_mard
where matnr = i_mard-matnr.
if sy-subrc <> 0.
message e003.
endif.
*&--sorting the tables
sort: i_mard by matnr werks lgort,
i_mara by matnr,
i_maktx by matnr.
*&--Clearing workareas.
clear: wa_mard,
wa_mara,
wa_maktx,
wa_final.
*PROCESSING
loop at i_mard into wa_mard.
*moving values to final workarea
wa_final = wa_mard.
at new matnr.
read table i_maktx into wa_maktx
with key matnr = wa_mard-matnr binary search.
read table i_mara into wa_mara
with key matnr = wa_mard-matnr binary search.
endat.
if sy-subrc = 0.
"if succesful then move to final workarea
wa_final-maktx = wa_maktx-maktx.
*for mara values
wa_final-meins = wa_mara-meins.
wa_final-mtart = wa_mara-mtart.
wa_final-ersda = wa_mara-ersda.
endif.
*append final workarea
append wa_final to i_final.
endloop.
clearing and refreshing the table I_MARD
refresh: i_mard.
clear: wa_mard.
endif.
endform. "zf_populate_info
this will move all the data into final table you have got, with the performnce tuned way
reward point if useful
Rohan malik
Similar Messages
-
How to fetch the data into one out parameter from two different queries
Hi,
I have an a problem how to implement condition in above procedure,and scenario is
i have to get the output into one out parameter from two queries.i.e if one query data is null
then i have to pick out data from another query into same out parameter.
CREATE OR REPLACE PROCEDURE GET_POLICIESMAP_BASEDON_GHPLID(I_COMPANYID IN NUMBER,
I_CARDID IN VARCHAR2,
PR_RESULTSET OUT SYS_REFCURSOR) IS
/* LOC_INSUREDID VARCHAR2(200);
LOC_RELATIONCODE VARCHAR2(200);
LOC_CURRENTPOLICYID VARCHAR2(4000);*/
BEGIN
OPEN PR_RESULTSET FOR
WITH A AS
(SELECT DISTINCT PM.MAINPOLICYID MAINPOLICYID,
id INSUREDID,
RELATIONCODE,
CURRENTPOLICYID
from INSUREDPERSONS IP
LEFT OUTER JOIN POLICIES_RULES_MAPPING PM
ON PM.POLICYID = IP.Currentpolicyid
where EIN IN (SELECT EIN
FROM INSUREDPERSONS ipp
JOIN VW_INSUREDINFO vw
ON IPP.ID = vw.insuredid
and vw.cardid = I_CARDID)
AND IP.CURRENTPOLICYID in
(SELECT ID
from policies
where companyid = I_COMPANYID
and dead = 0
AND POLICYTO > SYSDATE - 1))
SELECT INSUREDID, RELATIONCODE, CURRENTPOLICYID
FROM A
WHERE RELATIONCODE = 0
AND (A.MAINPOLICYID is null or
RELATIONCODE = 0 AND CURRENTPOLICYID = MAINPOLICYID)
UNION
SELECT INSUREDID, RELATIONCODE, CURRENTPOLICYID
FROM A
WHERE RELATIONCODE > 0;
/* HERE I NEED TO GET THE DATA FROM THIS BELOW QUERY INTO SAME OUT PARAMETER
WHEN ABOVE QUERY DATA CONTAINS NULLS */
/* IF PR_RESULTSET IS NULL THEN*/
OPEN PR_RESULTSET FOR
WITH A AS
(SELECT DISTINCT PM.MAINPOLICYID MAINPOLICYID,
id INSUREDID,
RELATIONCODE,
CURRENTPOLICYID
from INSUREDPERSONS IP
LEFT OUTER JOIN POLICIES_RULES_MAPPING PM
ON PM.POLICYID = IP.Currentpolicyid
where FAMILYID IN (SELECT FAMILYID
FROM INSUREDPERSONS ipp
JOIN VW_INSUREDINFO vw
ON IPP.ID = vw.insuredid
and vw.cardid = I_CARDID)
AND IP.CURRENTPOLICYID in
(SELECT ID
from policies
where companyid = I_COMPANYID
and dead = 0
AND POLICYTO > SYSDATE - 1))
SELECT INSUREDID, RELATIONCODE, CURRENTPOLICYID
FROM A
WHERE RELATIONCODE = 0
AND (A.MAINPOLICYID is null or
RELATIONCODE = 0 AND CURRENTPOLICYID = MAINPOLICYID)
UNION
SELECT INSUREDID, RELATIONCODE, CURRENTPOLICYID
FROM A
WHERE RELATIONCODE > 0;
/* END IF;*/
END GET_POLICIESMAP_BASEDON_GHPLID;
Thanks in Advance,
vvr.SELECT DISTINCT PM.MAINPOLICYID MAINPOLICYID,
id INSUREDID,
RELATIONCODE,
CURRENTPOLICYID
from INSUREDPERSONS IP
LEFT OUTER JOIN POLICIES_RULES_MAPPING PM
ON PM.POLICYID = IP.Currentpolicyid
where EIN IN (SELECT EIN
FROM INSUREDPERSONS ipp
JOIN VW_INSUREDINFO vw
ON IPP.ID = vw.insuredid
and vw.cardid = I_CARDID)In this code
where EINEIN is a column in INSUREDPERSONS?
and in the sub query below
(SELECT EIN
FROM INSUREDPERSONS ipp
JOIN VW_INSUREDINFO vw
ON IPP.ID = vw.insuredid
and vw.cardid = I_CARDID)EIN belongs to INSUREDPERSONS or VW_INSUREDINFO?
Please use Alias as we dont know your table structure. -
Working one iWeb site from two Macs
I have two Macs, and use my desktop for working at home, and my laptop for working away, or when on holiday for working with photographs and, hopefully, blogs. I set up my iWeb site initially using the desktop, and then tried to edit the site using my laptop, only to find that it cannot, seemingly, be done.
Help! Does anyone know how to edit one iWeb site from two machines, or is there, perhaps, a practicable workaround?
G4 laptop +G4 desktop Mac OS X (10.4.5)
G4 laptop +G4 desktop Mac OS X (10.4.5)
G4 laptop +G4 desktop Mac OS X (10.4.5)The answer is Domain.sites (extension hidden by default). You'll find this on your desktop machine at Users/YourUserName/Library/Application Support/iWeb. Copy that file to removable media and drag it to the same location on your laptop. Launch iWeb and you'll see your desktop site structure in the Site Organizer.
Once you keep the Domain package in sync between the two machines everything will work smoothly no matter which you use. There's a neat tip here which may help in this respect:
http://discussions.apple.com/message.jspa?messageID=1525121#1525121 -
Can I make one iphoto library from two time machine back-ups?
Hi
I have recently purchased a new Mac Book. I previously had two MacBooks, which I backed up with time machine onto two separate external hard drives.
I did a straight transfer of all data from one of these time time machine back-ups to my new laptop. I'd like to migrate select data from the second time machine back-up to my new Mac Book, and I'd like to start by transferring photos.
My laptop has an iphoto library, so I would like to know if I can import select photos from this second time machine back-up, and how do I do that?
many thanks
LindaFirst you need to restore the second Library from the back up. You need to restore the whole library, you can't just gather bits of it, I'm afraid.
Once that's done you have two Libraries. The easiest way to do what you want is to merge the Libraries with the paid version ($20) of iPhoto Library Manager This can be set to avoid duplicates. See the Help on it for more.
This is the only way that will get all the versions and all the metadata.
Other than that you'll need to export from one Library and import to the other.
Regards
TD -
Select only one specific value from two values contained in an item in form
hi ,
i am newly creating a form.
in the all item i an displaying on control block,
in one item "dummy.formule" i am taking the value as '1-xyz' where 1 is nummer and xyz is naam
or '99-fgj'.
but for the next block i want to write a query in which in the where condition i need to use the nummer from dummy.formule.this query is dymannically created at run time.
i am wrting this query in the when validate of the "dummy.formule" .
how i get the specific value that i required?923315 wrote:
hi ,
i am newly creating a form.
in the all item i an displaying on control block,
in one item "dummy.formule" i am taking the value as '1-xyz' where 1 is nummer and xyz is naam
or '99-fgj'.
but for the next block i want to write a query in which in the where condition i need to use the nummer from dummy.formule.this query is dymannically created at run time.
i am wrting this query in the when validate of the "dummy.formule" .
how i get the specific value that i required?First look at it. dynamically create pop list at run time. close it.
what you mean by "naam" ?
If the value has a specific format like as you write "1-xyz,99-fgj". you can use instr function and substr function to cut it out..
Hope this helps. -
Retrive data from two tables into one internal table.
Hi SDN,
I am downloading the Assets data from two tables ANLA,ANLZ.
there is a common field ANL1in both tables and i have to retrive the data by using anl1 into the internal table.
can you please send me the SELECT Syntax for this probl.....
Thank you & Regards,
ManojHi manoj,
Please see the following sample code. But kindly don't use join as it may hamper ur performance. No trouble in using two select query.
data: begin of itab occurs 0,
BUKRS like anla-BUKRS,
ANLN1 like anla-ANLN1,
BDATU like anlz-BDATU,
end of itab.
select anlabukrs anlaANLN1 anlzBDATU into corresponding fields of table itab from anla inner join anlz on anlaanl1 eq anlz~anl1 where (logexp).
Please come back for any clarification.
Thanks and Regards,
saurabh -
Moving data from one internal table to another
Hi,
I have one internal table populated with a list of material codes and another with all the material numbers.
ITAB1: MCODE KSCHL KNUMH MATNR
ITAB2: MCODE MATNR
The matnr field in itab1 is blank initially. It needs to be populated with all the material numbers from itab2. How can I achieve this?
Thanks,
apHi
Lets say that there is only one record in itab1 and for that there is correspondingly 10 records in itab2.
that means that the one record in itab1 should be changed to the first material number in itab2 and there should be nine more records created in itab1 according to the values in itab2.
Hope this is what you mean.
If this is the logic then the following code should work
then lets have a third internal table the same type as itab1
Loop at itab1 into wa_itab1
*readt table itab2 into wa_itab2 with key mcode = wa_itab1-mcode.
*IF sy-subrc eq 0.
loop at itab2 into wa_itab2 where mcode = wa_itab1-mcode.
wa_itab1-matnr = wa_itab2-matnr
append wa_itab1 to itab3.
endloop.
*ENDIF.
*modify itab1 from wa_itab1.
endloop.
itab3 will contain all the values that you require -
How to populate one internal table from another using field symbols
Hi Gurus,
I have a problem. I have to populate one internal table (sructure t_otput) from another internal table (sructure t_from) using field symbol.
Structure for from table.
types: begin of t_from,
year(4) type c,
ww(2) type c,
site type marc-werks,
demand type i,
end of t_from.
Structure for output table.
types: begin of t_display,
title(30),
WW1(10),
WW2(10),
WW3(10),
end of t_display.
The from table looks like this:
Year | WW | Site | Demand
2005 | 1 | OR1 | 12.00
2005 | 2 | OR1 | 13.00
2005 | 3 | OR1 | 14.00
The display table which has to be populated should look like this:
Title | WW1 | WW2 | WW3
OR1 | | |
Demand | 12.00 | 13.00 | 14.00
How to populate display table using field symbol?
Please give code snippets
Thanks,
GopalGopal,
Here is the code, however I am not vary clear about the ORG1 and Demand display that you have shown in the display. I am sure with this code it should not be a big deal to tweak in whatever manner you want.
TABLES : marc.
TYPES: BEGIN OF type_display,
title(30),
ww1(10),
ww2(10),
ww3(10),
END OF type_display.
TYPES: BEGIN OF type_from,
year(4) TYPE c,
ww(2) TYPE c,
site TYPE marc-werks,
demand TYPE i,
END OF type_from.
data : t_from type table of type_from,
t_display type table of type_display.
field-symbols : <fs_from> type type_from,
<fs_display> type type_display.
data : wa_from type type_From,
wa_display type type_display.
wa_from-year = '2005'.
wa_from-ww = '1'.
wa_from-site = 'OR1'.
wa_from-demand = '12.00'.
insert wa_from into table t_from.
wa_from-year = '2005'.
wa_from-ww = '2'.
wa_from-site = 'OR1'.
wa_from-demand = '13.00'.
insert wa_from into table t_from.
wa_from-year = '2005'.
wa_from-ww = '3'.
wa_from-site = 'OR1'.
wa_from-demand = '14.00'.
insert wa_from into table t_from.
data : variable(3) type c.
field-symbols : <fs_any> type any.
break-point.
Loop at t_from assigning <fs_from>.
variable = 'WW'.
wa_display-title = <fs_from>-site.
concatenate variable <fs_from>-ww into variable.
assign component variable of structure wa_display to <fs_any>.
<fs_any> = <fs_from>-demand.
endloop.
append wa_display to t_display.
clear wa_display.
loop at t_display assigning <Fs_display>.
write :/ <fs_display>.
endloop.
Note : Please award points if this helps you.
Regards,
Ravi -
Two internal tables in to one internal table
Hi ,
I have two internal tables ITAB1 and ITAB2, i would like to put fields from two internal tables in to one internal table(ITAB3) with out using inner joint. any one of you can give the sample code for this
Thanks
Raja.Hi,
Kamesh wrote :
Read itab2 into wa_itab2 with key f2 = itab1-f1 <USe your where conditions here>.
Read statement does not have WHERE conditions.
Please be careful while posting. Your thread will be reffered by many people. Please dont mislead.
Regards,
Swapna. -
How can i add two table into one internal table
I WANT TO ADD THIS TWO DIFFERENT TABLE INTO ONE INTERNAL TABLE PLEASE HELP.
TABLES: J_1IEXCHDR, J_1IEXCDTL.
SELECT * FROM J_1IEXCHDR WHERE STATUS = 'P'.
WRITE: / J_1IEXCHDR-LIFNR,
J_1IEXCHDR-DOCNO,
J_1IEXCHDR-EXYEAR,
J_1IEXCHDR-BUDAT.
SELECT * FROM J_1IEXCDTL WHERE TRNTYP = J_1IEXCHDR-TRNTYP
AND DOCYR = J_1IEXCHDR-DOCYR
AND DOCNO = J_1IEXCHDR-DOCNO.
WRITE: / J_1IEXCDTL-EXBAS,
J_1IEXCDTL-EXBED,
J_1IEXCDTL-RDOC1,
J_1IEXCDTL-ECS.
ENDSELECT.
ENDSELECT.
THANKS IN ADVANCED.U have to link these 2 tables like this
<b>SELECT
J_1IEXCHDR~DOCNO
FROM J_1IEXCHDR inner join J_1IEXCDTL
on J_1IEXCHDRDOCYR = J_1IEXCDTLDOCYR
WHERE STATUS = 'P'.</b>
this is sample code only, and u have to check the F.key relationship.
Regards
Prabhu -
Extracting from table based on conditions from two internal tables
Hi,
i to have select few records from a table based on conditions from two different internal tables. How can I achieve this.?
ex:
select objid from HRVPAD25 into table t_pad25
where PLVAR = 01
OTYPE = E
OBJID = itab1-sobid
sobid = itab2-pernr.
How can this be written? can i use "for all entries..." addition with 2 tables?Hi Maansi_SAP,
you can use exactly one internal table in the FOR ALL ENTRIES clause. Consider this alternative:
data:
itab_sobid_hash like itab1 with unique key sobid,
ls_pad25 like line of t_pad25.
sort itab1.
delete adjacend duplicates from itab1 comparing sobid.
itab_sobid_hash = itab1.
select objid
into ls_pad25
from HRVPAD25
for all entries in itab2
where PLVAR = '01'
and OTYPE = E
and sobid = itab2-pernr..
read table itab_sobid_hash with table key sobid = ls_pad25-objid.
check sy-subrc = 0.
append ls_pad25 to t_pad25.
endselect.
You may decide if itab1 or itab2 is better used as hashed table. Make a performance test.
The critics will tell you that SELECT ... ENDSELECT is not performant. That was very true, back in last milleniums's 90ies
Regards,
Clemens -
How to scan data from one internal table to another
Hi All,
let me know how to scan all from one internal table to another internal table. Pls provide me the syntax and code.
i am very thankful to you all in advance.
Thanks & Regards,
Nagarjuna.if u want to copy data from itab1 to itab2 then use
itab2[] = itab1[].
if u want to compare whether both itab1 and itab2 are same or not,use
if itab1[] = itab2[].
*--same
else.
*--not same
endif.
if u want to compare itabs based on primary key....
loop at itab1.
read table itab2 with key f1 = itab1-f1.
if sy-subrc <> 0.
*--not same....
endif.
endloop.
if u want to copy only few lines(say from 1 to 3) of itab1 to itab2 then use...
append lines of itab1 from 1 to 3 to itab2.
if internal tables don't have same structure,
say only fields f1 and f2 are common,then
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.
Please don't forget to reward points....!!!
Regards
vasu -
How to insert select columns from one internal table to another
Hi,
How to insert select columns from one internal table to another based on condition as we do from a standart table to internal table.
regards,
SriramHi,
If your question is for copying data from 1 int table to other ;
we can use
APPEND LINES OF it_1 TO it_2.
or if they have different columns then:
loop at it_1 into wa_it1.
move wa_it1-data to wa_it2-d1.
apped wa_it2 to it_2.
clear wa_it2.
endloop.
thnxz -
Selecting from multiple tables, into one internal table
Hi,
What is the best & most efficient method of selecting from multiple table (in my case 6,) into one internal table?
Thanks,
John
Points will be rewarded and all responses will be highly appreciated.I have simple example :
First one - Join 5 tables
data : f1 type i,
f2 type i,
f3 type i.
start-of-selection.
get run time field f1.
write the query 4 or 5 tables join.
get run time field f2.
f3 = f2 - f1 ( Total time).
Second one - joins 3 table and use for all entries
data : f1 type i,
f2 type i,
f3 type i.
start-of-selection.
get run time field f1.
write the query 3 tables join and use for all entries
get run time field f2.
f3 = f2 - f1. ( Total time )
Finally you can have time diffrence between the both sql statement. -
Get the Common from Two Internal Tables with same structure
Hi ,
I need to get the Common data from Two Internal Tables with same structure with using the looping method.
For e.g.
I have two internal table say ITAB1 and ITAB2.
ITAB1 has values A,B,C,D,E,F
ITAB2 has values A,H,B,Y,O
Output at runtime should be : A,BHi mohit,
1. If u want to compare all fields,
for matching purpose,
then we can do like this.
2.
report abc.
data : a like t001 occurs 0 with header line.
data : b like t001 occurs 0 with header line.
loop at a.
LOOP AT B.
IF A = B.
WRITE :/ 'SAME'.
ENDIF.
endloop.
ENDLOOP.
regards,
amit m.
Maybe you are looking for
-
I have a HP PAVILION DV7-6108EO This question was solved. View Solution.
-
Transaction ABST2 - Asset balance sheet values not completely posted
Hi, An error message appeared when using transaction ABST2. "Asset balance sheet values are not completely posted". What can be the reason? How can I check what is missing? Thank you. Kind regards, Linda
-
Nokia 5530 XM, phone software issues/headaches
Hello, I got my 5530 XM around 2 months ago. It was my first Nokia (been a Sony Eric fan for over 5 years). Anyway i liked its touch interface and all. But then i noticed the phone would restart (reddish/grayish horizontal lines leading to a white sc
-
Is it possible to create a wip sample with inventory valdity rule in spec
Hi friends Can anyone please tell me Is it possible to create a wip sample with inventory validity rule in the item Specification? I have an item which is a wip (product) item and has validity rule defined for inventory. can i create a sample from th
-
hai , pls explain what is source list? is source list is only refer pr/ contarct .s.aggre/req ???? how is work s.list? pls give one full cycle of s.list? step by step ? ( pls dont give any link) ali