Comparing each value of two internal tables
HI everybody,
i have two internal tables itab1 and itab2 same structure
both r having four fields each and field with values
now i need to compare the two internal tables
and if every value of itab1 matches itab2
then i have to write one select quirie for the following given description
compare past and current shipping point
compare internal_table2 and internal_table3
if entry in internal_table2 and internal table3 match
variable_tknum = internal_table2-tknum
endif.
for each entry that matches:
select vlabdata into zi_vlabdata from vlbl where vbeln = variable_tknum and vlbl-vlabtyp = 'ZIBOOKNO'.
plz give me solution for this
thanks
hridhayanjili.
sort : ITAB1 by f1,f2,f3,f4,
ITAB2 by f1,f2,f3,f4.
LOOP AT ITAB1.
READ TABLE ITAB2 WITH KEY F1 = ITAB1-F1
F2 = ITAB1-F2
F3 = ITAB1-F3
F4 = ITAB1-F4 BINARY SEARCH.
IF SY-SUBRC = 0.
*--all the fields of ITAB1 and ITAB2 are matching .
*--write your logic here
ELSE.
*--ITAB1 and ITAB2 records are not matching.
ENDIF.
ENDLOOP.
Regards
Srikanth
Message was edited by: Srikanth Kidambi
Similar Messages
-
Comparing row values in two different tables
Hello,
Does anyone know if it is possible to compare (and possibly highlight - which I know can be done) row values in two different tables?
I have a ZIP Code column in table A that I want to compare to a ZIP Code column in table B and highlight those ZIP Codes that are present in table B but not in table A etc. Is this possible?
Thanks,
KennethTo be able to apply conditional formatting, I must edit the formulas this way.
=IF(ISBLANK(B)," ",IF(ISERROR(VLOOKUP(B,Tableau 2 :: B,1,0))," ",VLOOKUP(B,Tableau 2 :: B,1,0)))
=IF(ISBLANK(B)," ",IF(ISERROR(VLOOKUP(B,Tableau 1 :: B,1,0))," ",VLOOKUP(B,Tableau 1 :: B,1,0)))
I replaces the four empty strings by strings containing one space character.
In the field supposed to contain the text which is not contained I just entered a single space character.
Yvan KOENIG (from FRANCE vendredi 12 septembre 2008 20:52:11) -
How to compare each row in an internal table
Hi,
Say I have an internal table with 3 fields in each row, num1, num2, num3, each type of integer i, now I want to get the maximum of num1, num2, num3 and put this maximum number into num4, may I know how can I do that? Also, if say I need to pull out this num4 and play around with it, sould I just loop it into my workarea of internal table and assign a variable for whatever that is in the work area? Thanks a lot!
Regards,
AnyiHi,
Inside a loop of the table compare each field like this:
loop at itab.
l_num4 = itab-num1.
if l_num4 < itab-num2. l_num4 = itab-num2. endif.
if l_num4 < itab-num3. l_num4 = itab-num3. endif.
Here you can play with the maximum number
itab-num4 = l_num4.
modify itab.
endloop.
You can also do the same using field-symbols (it's faster to assignations) :
loop at itab assigning <a>.
endloop.
Regards. -
HI all!
I have two internal tables with single field values as below :
1st Internal Table : A,B,C,D
2nd Internal Table : A,B,C,D,E,F,G,
Now I want to compare these two Int. tables and delete the second int. table with values which are not there in the first int. table.Any simple logic to get this.
Regards
PavanSort internal table 1 by A B C D.
Now ..
copy contents of 2nd table to a temp table.
loop at 2nd internal table.
read 1st internal table with key a = 2internal table a
b = 2internal table b
c = 2internal table c
d = 2internal table d.
if sy-subrc ne 0.
delete entry from temp table.
now refresh table 2.
copy contents of temp to table 2.
Guys,
I guess DELETING THE SAME TABLE WITHIN A LOOP .. ENDLOOP is not advisable.Please correct me if i m wrong.
endif.
endloop.
Message was edited by: Nishanth Bhandar
Message was edited by: Nishanth Bhandar -
Compare multiple variable selections between two internal tables
I am trying to work out the syntax for the following, however i am stumped on the 2nd part of the requirement....
I have two internal tables. and i need to compare the records.
1st, line by line, which i can do, however the 2nd requirement, i need to check a range of data against the same table...
here is an example of the tables:
Internal Table1 has the following records.
TL1
TL2
TL3
TL4
TL5
TL6
Internal table 2 has the following records...
LDOC1 TL1
LDOC1 TL2
LDOC1 TL3
LDOC1 TL7
LDOC2 TL1
LDOC2 TL5
LDOC3 TL6
LDOC3 TL7
but for the 2nd requirement, i have to group the LDOC1 (2, 3) and search for all TL* and report if they all exist, some exist or none exist within the 1st internal table.
so for requirement 1, the answer would be yes (as i can do a read table using the TL*), however i am not sure how i can check "for all entries" for TL1, Tl2, TL3, TL7 and return that only some entries exist.... LDOC1 should return "some", LDOC2 should return "all" and LDOC3 should return "none".
Hopefully that makes sense???
Can someone give me a keyword to investigate as i am not sure the At new would work.... Unless i do an at new and then loop and maybe add the record to a "range" to then compare and log the result as it runs through each result...
so if Itab1 = itab2 then variable = yes. else None.
if variable = yes, and itab1 = itab2 then variable = yes.
if variable = yes and itab1 <> itab2 then variable = some.
would that work?? i am worried about performance too as there could be 1000's of records....
and can i have an "at end" so at end, if variable = yes, then variable = all?
i have written all the rest of the report to get all the data into these tables... i am just a little baffled as to how i can validate and compare the multiple selection.... :o(Hi,
It is really confusing :-).. But i have tried to figure out.. may be this could be useful for you.
Internal Table1 has the following records.
TL1
TL2
TL3
TL4
TL5
Internal table 2 has the following records...
LDOC1 TL1
LDOC1 TL2
LDOC1 TL3
LDOC1 TL7
LDOC2 TL1
LDOC2 TL5
LDOC3 TL6
LDOC3 TL7
itab3[] = itab2[]
sort itab3 by field1.
delete adjacent duplicates from itab3 comparing field1.
itab3
LDCO1
LDCO2
LDCO3
loop at itab3.
clear: lv_flag, index, ind.
loop at itab2 where field1 = itab3-field1.
index = index + 1.
read table itab1 with key field1 = itab2-field2.
if sy-subrc NE 0.
lv_flag = 'X'.
ind = ind + 1.
endif.
endloop.
if lv_flag = 'X'.
if ind = index.
lv_val = 'NONE'.
elseif ind NE index.
lv_val = 'SOME'.
endif.
else.
lv_val = 'ALL'.
endif.
"here you can modify itab3 with lv_val in one field, so that you can figure out which is SOME, NONE, ALL
endloop.
Regards,
senthil -
Function module for comparing contents of two internal tables
Hi All,
Is there any function module to compare contents of two internal tables of same structure?
If yes please let me know.
Thanks in advance.
AmolHi
call SE16 with table TFTIT in order to get a full list (it will be long...)
A list of FMs with parameters can be found in table FUNCT.
Finally go to sm37rsdf4
that will give you all the function modules with description
Here is the list:
http://www.erpgenie.com/abap/functions.htm
hope this helps...
Regards
CSM Reddy -
hi everybody
i have two internal tables ITAB1 AND ITAB2
I WANT TO COMPARE THE CONTENTS OF THESE INTERNAL TABLES HOW TO DO THIS
REGARDS
HRIDHANJILIHello Hridhayanjili
The most detailed comparison is to use the same logic as change documents are prepared. Assuming both of your itabs are of structure struc_a. Then define the following type:
TYPES: BEGIN OF ty_s_itab_di.
INCLUDE TYPE struc_a.
TYPES: CHIND TYPE bu_chind.
TYPES: END OF ty_s_itab_di.
TYPES: ty_t_itab_di TYPE STANDARD TABLE OF ty_s_itab_di
WITH DEFAULT KEY.
DATA:
gt_itab_old TYPE ty_t_itab_di,
gt_itab_new TYPE ty_t_itab_di.
Fill itabs gt_Itab_old with the corresponding data of itab1 and gt_itab_new with the corresponding data of itab2.
Very important: sort you itabs either by all key fields or by all fields.
Call function CHANGEDOCUMENT_PREPARE_TABLES with the following parameters
- CHECK_INDICATOR = ' '
- TABLE_NEW = gt_Itab_new
- TABLE_OLD = gt_itab_old
The function module will remove identical lines from both itabs. New entries in gt_itab_New will have CHIND = 'I' and deleted entries in gt_itab_old will have CHIND = 'D'.
Read the documentation of the function module and play around with it. You will see that this a quite easy yet powerful approach for comparing itabs.
Regards
Uwe -
To compare two internal tables and delete records
Hi friends,
I have to compare two internal tables and should delete the records which is not present in both the tables. Reply me as soon as possible.
Thanks.Hi Nagarajan,
1. I don't think there is any direct (one-shot statement)
way to achieve this.
one has to do by writing some logic.
2. Loop at ITAB1.
Read table ITAB2 with key Field1 = ITAB1-Field1.
If sy-subrc <> 0.
delete ITAB1.
endif.
Endloop.
Do the same again with ITAB2.
Loop at ITAB2.
Read table ITAB1 with key Field1 = ITAB2-Field1.
If sy-subrc <> 0.
delete ITAB2.
endif.
Endloop.
3. If any better way is found, i will let u know.
Hope it helps.
Regards,
Amit M. -
Reg comparison of two internal tables
hi friends,
please help me solving this.
there are two internal tables t_zvs38 and t_value
1.t_value like seahlpres
2.t_zvs38 like zvs38.
values in t_value will be like this.
first line wil contain zmdtype(mandatory document) and second line will contain
zmdtypet (the description for zmdtype).
eg.
D001 -
-zmdtype
internal----
zmdtypet
D002
external
D003
renewal
values in t_zvs38.
for a particular sales.org the zmdtype is filled.
select vkorg zmdtype into corrsponding fields of table t_zvs38
where vkorg = p_vkorg.
Now i want to compare t_value and t_zvs38 with field zmdtype
and delete the contents of t_value which are not in t_zvs38.
i have written like this.
loop at t_value.
read table t_zvs38 with key zmdtype = t_value-string.
if sy-subrc ne 0.
delete t_value. "to delete zmdtype
sy-tabix = sy-tabix + 1.
delete t_value. " to delete zmdtypet
else.
sy-tabix = sy-tabix +2. "to go to next zmdtype.
endif.
endloop.
but it is deleting all the contents of t_value.
points are assured.CLEAR zvs32t.
SELECT zvs32tzmdtype zvs32tzmdtypet
INTO (zvs32t-zmdtype, zvs32t-zmdtypet)
FROM zvs32t
JOIN zvs32
ON zvs32tzmdtype = zvs32zmdtype
WHERE zvs32t~spras = sy-langu
AND zvs32~zfrenewal = space.
WRITE zvs32t-zmdtype TO t_value.
APPEND t_value.
WRITE zvs32t-zmdtypet TO t_value.
APPEND t_value.
ENDSELECT.
SELECT vkorg vkbur zmdtype FROM zvs38 INTO CORRESPONDING FIELDS OF TABLE t_zvs38
WHERE vkorg = p_vkorg
AND vkbur = p_vkbur.
LOOP AT t_value INTO wa_area1.
v_index = sy-tabix.
READ TABLE t_zvs38 INTO wa_area2 WITH KEY zmdtype = wa_area1-string
BINARY SEARCH.
IF sy-subrc NE 0.
IF l_flag IS INITIAL.
DELETE t_value INDEX v_index.
ELSE.
CLEAR l_flag.
ENDIF.
ELSE.
l_flag = 'X'.
ENDIF.
ENDLOOP.
Using this code ,i am unable to ge the correct output.Thank u all for ur help. -
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. -
How to join two internal table rows in alternative manner into one internal table?
How to join two internal table rows in alternative manner into one internal table?
two internal tables are suppose itab1 & itab2 & its data
Header 1
Header 2
Header 3
a
b
c
d
e
f
g
h
i
Header 1
Header 2
Header 3
1
2
3
4
5
6
7
8
9
INTO itab3 data
Header 1
Header 2
Header 3
a
b
c
1
2
3
d
e
f
4
5
6
g
h
i
7
8
9Hi Soubhik,
I have added two additional columns for each internal table.
Table_Count - It represents the Internal Table Number(ITAB1 -> 1, ITAB2 -> 2)
Row_Count - It represents the Row Count Number, increase the row count value 1 by one..
ITAB1:
Header 1
Header 2
Header 3
Table_Count
Row_Count
a
b
c
1
1
d
e
f
1
2
g
h
i
1
3
ITAB2:
Header 1
Header 2
Header 3
Table_Count
Row_Count
1
2
3
2
1
4
5
6
2
2
7
8
9
2
3
Create the Final Internal table as same as the ITAB1/ITAB2 structure.
"Data Declarations
DATA: IT_FINAL LIKE TABLE OF ITAB1. "Final Internal Table
FIELD-SYMBOLS: <FS_TAB1> TYPE TY_TAB1, "TAB1
<FS_TAB2> TYPE TY_TAB2. "TAB2
"Assign the values for the additional two column for ITAB1
LOOP AT ITAB1 ASSIGNING <FS_TAB1>.
<FS_TAB1>-TABLE_COUNT = 1. "Table value same for all row
<FS_TAB1>-ROW_COUNT = SY-TABIX. "Index value
ENDLOOP.
"Assign the values for the additional two column for ITAB2
LOOP AT ITAB2 ASSIGNING <FS_TAB2>.
<FS_TAB2>-TABLE_COUNT = 2. "Table value same for all row
<FS_TAB2>-ROW_COUNT = SY-TABIX. "Index value
ENDLOOP.
"Copy the First Internal Table 'ITAB1' to Final Table
IT_FINAL[] = ITAB1[].
"Copy the Second Internal Table 'ITAB2' to Final Table
APPEND IT
LOOP AT ITAB2 INTO WA_TAB2.
APPEND WA_TAB2 TO IT_FINAL.
ENDLOOP.
"Sort the Internal Table based on TABLE_COUNT & ROW_COUNT
SORT IT_FINAL BY ROW_COUNT TABLE_COUNT.
After sorting, check the output for IT_FINAL Table, you can find the required output as shown above.
Regards
Rajkumar Narasimman -
How to process a block for each row in an internal table....
Hi experts....
In po approval workflow the scenario is like this.... for each po there may be more than one approver. approvers list i am maintaining in the ztable. list of approvers(no of approvers) is decided by the po value. I have collected these approvers into internal table. now i have to process a block ( approving or rejecting the po... )in the workflow for each row in the internal table.
how can i do this. based on the decision of the 1st approver approves the po then it should go to next approver in the internal table...otherwise end the workflow.....
Please help me......i have created an internal table in the workflow container in which i am getting the list of approvers....
how can i loop the internal table in the workflow...?
how can i know the index of the loop in the workflow.....(will sy-index work here....? so that i can use loop until step in the main workflow to call the subworkflow..so that if sy-index is greater than no of entires in the itab then i can come out of the loop) -
Replace single values in a internal table
Hi all,
I have two internal tables.
In the first table (itab) I have some values which I have to "decode" using the second table (itabtext).
This means that I have to pick every line and replace in the itab a value like "01" with "text for 01" from itabtext.
In the itabtext "01" is the key for "text for 01".
What is the best way to handle this?
Thanks a lot,
FabianThanks for your answer but I still have the problem. The tables (two texttables instead of one what I wrote in the first message) are the following:
DATA: BEGIN OF lt_proclocktexts OCCURS 0.
DATA: lockprocid(2) TYPE c,
text(40) TYPE c.
DATA: END OF lt_proclocktexts.
DATA: BEGIN OF lt_lockreastexts OCCURS 0.
DATA: lockprocid(2) TYPE c,
lockreason(2) TYPE c,
text(40) TYPE c.
DATA: END OF lt_lockreastexts.
The table where I want to replace fields are the following:
DATA: BEGIN OF lt_proclocks OCCURS 0.
DATA: mandt type MANDT,
lockreason(40) TYPE c,
lockprocid(40) TYPE c,
GPART type GPART_KK,
LOOBJ type LOOBJ_KK.
DATA: END OF lt_proclocks.
When lt_proclocks-lockprocid similar to a lt_proclocktexts-lockprocid the lt_proclocks-lockprocid should be replaced by the lt_proclocktexts-text.
When lt_proclocks-lockreason AND lt_proclocks-lockprocid is similar to a combination in the lt_lockreastexts the ID in field lt_proclocks-lockreason should be also replaced (additionally to the lt_proclocks-lockprocid field).
Thanks,
Fabian -
Selecting values into same internal table from 2 differrnt select statement
Hi Friends,
code :
types :
begin of ty_bsad,
augbl type bsad-augbl,
end of ty_bsad.
begin of ty_bsad1,
augbl type bsad-augbl,
belnr type bsad-belnr,
end of ty_bsad1.
select augbl
from bsad
into table it_bsad
where belnr = l_vbeln and
bukrs = l_bukrs and
kunnr = l_kunrg.
if sy-subrc = 0 .
select belnr
into table lt_bsad1
from bsad
for all entries in lt_bsad
where augbl = lt_bsad-augbl and
kunnr = l_kunnr and
burks = l_bukrs and
blart = 'xy'.
now my requiremnt is i need to get both the augbl and belnr in single internal table but not in differnrnt internal table.
how can i get it.
Regards,
Priyanka.
Code Formatted by: Alvaro Tejada Galindo on Jan 8, 2009 10:53 AMHI.
No Need to create two internal table because your feyching values from same table BSAD with diffrent where condition.try this code.it s work.
select augbl
from bsad
into table it_bsad
where belnr = l_vbeln and
bukrs = l_bukrs and
kunnr = l_kunrg and
blart = 'xy'.
else Refer this code.
LOOP AT it_bill_data INTO wa_bill_data.
MOVE-CORRESPONDING wa_bill_data TO wa_final_data.
READ TABLE it_material_data INTO wa_material_data
WITH KEY matnr = wa_bill_data-matnr.
IF sy-subrc = 0.
wa_final_data-meins_mara = wa_material_data-meins.
ENDIF.
APPEND wa_final_data TO it_final_data.
ENDLOOP.
Regards.
Jay
Edited by: Jay on Jan 8, 2009 2:53 PM
Edited by: Jay on Jan 8, 2009 2:57 PM
Code Formatted by: Alvaro Tejada Galindo on Jan 8, 2009 10:56 AM -
Downloading two internal tables in same text file
I have one internal table as like below.
Data:begin of itab1 occurs 0,
rec(5),
end of itab1.
Itab1 is getting updated from input text file(Continuous text).
Here Itab1 contains one record with Indicator '01 and n number of records with indicator '02'.
This needs to be seperated in to two internal tables.
data:Begin of Itab_Head occurs 0,
Rec_ind(2) type C,
Name(3) type C,
end of itab_Head.
data:Begin of Itab_Item occurs 0,
Rec_ind(2) type C,
Id(3) type C,
Status(10,
end of itab_Item.
loop at itab1.
If itab1-Rec+0(2) = '01'.
Itab_Head-Rec_Ind = itab1-rec+0(2).
Itab_Head-Name = itab1-rec+2(3).
Append Itab_Head.
elseif itab1-rec+0(2) = '02'.
Itab_Item-Rec_Ind = itab1-rec+0(2).
Itab_Item-Id = itab1-rec+2(3).
Append Itab_Item.
endif.
endloop.
After moving to the internal tables I am doing some processing and updating the status of Itab_item.
After all these again I have to download the internal table as a text file.Now my question is.
I have values in 2 diff internal tables.How to download the two in same file.See this sample code.
data: itab1 type string occurs 0 with header line,
itab2 type string occurs 0 with header line.
itab1 = 'itab1_text'.
append itab1.
itab2 = 'itab2_text'.
append itab2.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
exporting
FILENAME = 'C:\ftext.txt'
APPEND = 'X'
changing
DATA_TAB = itab1[].
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
exporting
FILENAME = 'C:\ftext.txt'
APPEND = 'X'
changing
DATA_TAB = itab2[].
Svetlin
Maybe you are looking for
-
Is there any way that I can still back up my purchases?
I apologize if this has been asked before. I went to update my Ipod touch. There was an error (the number was a 1600 number) and then iTunes stated that I need to restore my iPod now. It will not allow me however to back up my purchases from my iPod
-
BSOD after installing Boot Camp, AMD Radeon 6630M driver issue
I have reinstalled Windows using Boot Camp twice now and get a blue screen right after installing the Boot Camp drivers and restarting. I am installing Windows 7 Ultimate 64-bit on my Mac mini 2011 edition. I created an install disk in Lion and used
-
Colored Stripes in body of e-mail
All e-mail recevied via enterprise server contains diagional colored stripes in the message body. How can I remove them. Makes it difficult to read the text. Thanks Solved! Go to Solution.
-
Hi, I have a scenario where I have input strings. Within this string there are up to 10 characters (it can be 8, 6, 4, 2, or 0), all of which are 2 character codes. So for example my string may be abcdefghij within the above the 2 character codes wou
-
Access Data from device with Broken Screen
My Storm fell and the screen cracked and now it only displays a black screen. I am able to get it recognized with the Blackberry Destop Software but in order to fully access the device I need to unlock it, which I can't because the screen is broken.