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
Similar Messages
-
DIFFERENCE BETWEEN TWO INTERNAL TABLES,THESE TABLES HAVE SAME FILEDS
TYPES: BEGIN OF
TY_AS_UP,
WERKS LIKE
MARC-WERKS,
MATNR LIKE
MARC-MATNR,
LGORT LIKE
MARD-LGORT,
LABST(13) TYPE C,
(MARD-LABST)
END OF TY_AS_UP.
TABLES:
1) FLAT FILE DATA.:
DATA: WA_FILEDATA
TYPE TY_AS_UP,
I_FILEDATA TYPE STANDARD TABLE OF TY_AS_UP INITIAL SIZE 0.
2) SAP DATA (SELECT QUREY)
DATA: WA_SAPDATA
TYPE TY_AS_UP,
I_SAPDATA TYPE STANDARD TABLE OF TY_AS_UP INITIAL SIZE 0.
NOTE:
I brought data to above table(2) from two internal tables I_MARC and I_MARD .
My requirement is to display difference between tables 1) and 2) based on quantity field(MARD-LABST)..
report layout:
top-of-page
plant diff qty distri.qty sap
01 -20 30 50
end-of-page
page no 1.
Kindly help me,it is urgenthi micky,
thanks for your solution.
another problem:
I could not understand below
requirement, could you please
explain me.
8) Format the report based on the display options specified in the selection screen.
a) Display option EQUAL IN QTY show report lines where the difference is between the distributor file quantity and the SAP quantity is 0.
b) Display option DIFFERENCE IN QTY show report lines where the difference between the distributor file quantity and the SAP quantity is not 0.
c) If both options are selected, show report lines where the difference is both 0 and not 0.
d) Display SKUs in the distributors file not found in SAP as Missing SKUs
regards,
saritha. -
Find the difference between two internal table
how can i see the difference between two interal tables?
The requirement is as follows
1. We have a transparent table, which stores the employee data with EMP ID as key.
2. We load the transp table data into a interal table (B).
3. We get data from legecy system as file and it gets loaded into another internal table (A) (this also has the same EMP ID key and this will have latest addition/update to those emplyees).
Now we need to seperate out these data into three interal table Inserted (I), Deleted (D) and Updated (U).
We want to do followign things
I = A - B
D = B - A
Both A and B will have around 40k records. Hence we are trying to avoid the looping.
Please suggest the best option for us.
Thank you in advance.
Raghavendra>
RAGHAV URAL wrote:
> how can i see the difference between two interal tables?
> The requirement is as follows
>
> 1. We have a transparent table, which stores the employee data with EMP ID as key.
> 2. We load the transp table data into a interal table (B).
> 3. We get data from legecy system as file and it gets loaded into another internal table (A) (this also has the same EMP ID key and this will have latest addition/update to those emplyees).
>
> Now we need to seperate out these data into three interal table Inserted (I), Deleted (D) and Updated (U).
>
> We want to do followign things
> I = A - B
> D = B - A
>
> Both A and B will have around 40k records. Hence we are trying to avoid the looping.
>
> Please suggest the best option for us.
>
> Thank you in advance.
> Raghavendra
Hi Raghavendra,
Currently as of my knowledge, these operations are only possible through LOOPs. But LOOPign can be really fast here if you properly utilize the SORTING, READ with BINARY SEARCH and FIELD-SYMBOLS usage. I would say:-
Steps for Insert:-
SORT: A, B.
LOOP AT A ASSIGNING <WA_A>.
READ TABLE B WITH TABLE KEY key = <WA_A>-key BINARY SEARCH.
IF SY-SUBRC NE 0.
APPEND <WA_A> TO I.
ENDIF.
ENDLOOP.
Steps for Delete:-
SORT: A, B.
LOOP AT B ASSIGNING <WA_B>.
READ TABLE A WITH TABLE KEY key = <WA_B>-key BINARY SEARCH.
IF SY-SUBRC NE 0.
APPEND <WA_B> TO D.
ENDIF.
ENDLOOP.
Regards,
Ravi. -
Data Transfer between two internal tables
Hi SDN,
If I have two internal tables itab_a and Itab_b and I want to copy a subset of itab_a to itab_b using a conditional statement, is it possible and how?
Second, what if I want to append the smaller internal table itab_b to itab_a, how would you do that.
My task is to take some of the rows from a into b, change one field and append back to a. So if a had 100 rows, now it would have 110.
Please help.
Thanks.
Saf.If I have two internal tables itab_a and Itab_b and I want to copy a subset of itab_a to itab_b using a conditional statement, is it possible and how?
LOOP AT ITAB_A.
IF ITAB_A-SOME_FIELD = SOME_VALUE.
MOVE-CORRESPONDING ITAB_A TO ITAB_B.
APPEND ITAB_B.
ENDIF.
ENDLOOP. -
Cann't move data between two internal table in Unicode program
Hello expert,
I import a program from old sap system to new system, but syntax error occurred --- ' L_T_S776[] = T_DATA_RECORDS[]. ',
it is said ' internal table L_T_S776 and T_DATA_RECORDS are not mutually convertible, in unicode program, two internal tables must have the same structure layout'.
The coding is:
DATA: L_T_S776 LIKE S776 OCCURS 0 WITH HEADER LINE.
DATA: L_T_S777 LIKE S777 OCCURS 0 WITH HEADER LINE.
FIELD-SYMBOLS: <F_S776> TYPE S776.
FIELD-SYMBOLS: <F_S777> TYPE S777.
IF NOT ZCL_USEREXIT=>IS_ACTIVE( PROJN = 11 EXITN = 34 ) IS INITIAL.
CASE I_RMCP2-SCTYP.
WHEN 'Z776'.
L_T_S776[] = T_DATA_RECORDS[].
LOOP AT L_T_S776 ASSIGNING <F_S776>.
<F_S776>-ZZCUSER = SY-UNAME.
<F_S776>-ZZCDATE = SY-DATUM.
<F_S776>-ZZCTIME = SY-TIMLO.
ENDLOOP.
T_DATA_RECORDS[] = L_T_S776[].
WHEN OTHERS.
ENDCASE.
internal table T_DATA_RECORDS is defined to like INDX.
this program is in function module EXIT_SAPMMCP6_011, it is a user_exit.
I also confuse the meaning of this part of coding, could anybody help me?
reward if got useful reply, thank you.
H.BHi,
The structure are different thats why you getting this error. But there must be some fields common to which you want to move data. So you change in that way.
And there will be no impact whatsoever because of such change.
Regards,
Atish -
Can we apply join between two internal tables?
Itab has fields A,B,C.
Data: begin of itab occurs 1,
A type I,
B type I,
C type I,
End of itab.
Jtab has fields A, I, J.
Data: begin of itab occurs 1,
A type I,
I type I,
J type I,
End of itab
The common field between itab and jtab is u201CAu201D.
Now I need to collect A,B,C,I, J in another internal table ktab.
How should I be doing this.
If I use a SELECT query with inner join between itab and jtab it says u201Citab is not a database tableu201D.
How should I get the result ktab with A B C I J fields?
Please help, nay help will be highly appreciated?a®s wrote:
>
> sort itab_all by A
> delete adjacent duplicates from itab_all comparing A.
>
>
Do you have the above code in ?
Here A is common field between both tables, first we are appending itab_1 & itab_2 into table itab_all then deleting the adjacent duplicates from itab_all. then we are reading itab_1 & itab_2 for possible matches and update the same values in itab_all
so there will NOT be a chance of duplicates in itab_all
a® -
How to append records between two internal tables
hi all,
im trying to append from an internal table to another internal table with same structure. i tried the following but it overwrites previous contents of i_dest:
move i_src to i_dest
thanks,
sidhey u try to move it record by record
<b>itab2 = itab.
append itab2.</b>
This should work I guess
just check the code below, if u want to move the whole itab into itab2 then use <b>itab2[] = itab.</b>
<b>loop at it_pgm.
read table itab with key obj_name = it_pgm-pgm_name.
if sy-subrc = 0.
itab_final-obj_name = itab-obj_name.
itab_final-func_spec = itab-func_spec.
itab_final-func_area = itab-func_area.
itab_final-dev_class = itab-dev_class.
append itab_final.
else.
itab_alt-pgm_name = it_pgm-pgm_name.
append itab_alt.
endif.</b>
please reward points if found helpful -
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 -
Using for all entries of two internal tables in where clause of the select
Hi experts,
My requirement is, need to select Marc-minbe and wrpl-sobst, for all the entries of the two internal tables it_mara , and it_t001w.
here is the select queries i have used,
select matnr normt from mara into it_mara for all entries in it_data where normt = it_data-normt.
select konnr werks from t001w into it_t001w for all entries in it_data where konnr = it_data-konnr.
now i need to select minbe of marc table and sobse of wrpl table for all the entries of above internal tables, it_mara and it_t001w, using both matnr of it_mara and werks of it_t001w in where condition.
Pls advise how i can do it.
Thanks.
Moderator message: very basic, please work on this yourself first, these forums are not a substitute for ABAP training.
Edited by: Thomas Zloch on Dec 6, 2010 9:38 AMHi
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 -
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 -
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 -
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. -
hello friends,
I have two internal tables of different structure.
i have filled those two internal tables using join statements.
But one field is common in both the tables, when i try to append both tables into another new internal table.
i cant get the value for the 2nd tables field.
EX.
vbeln is common in vbuk, vbup, vbap, vbak, likp, lips.
but its sale order number in vbak, vbap.
delivery document in likp,lips.
vbup has both sales order and delivery in the vbeln field.
so, i made a join to between vbak, vbup and lips to see the goods movement status in vbup.
for that the vbeln should be delievery number.
and in other table, i have added vbup and vbak and vbep to get the delievery status.
for that the vbeln should be sale order no.
when i append both the tables into the third internal table that has the structure of both internal tables.
i could not get the vbeln of the second table(sale order no) in the third table.
help me guys.
rewards for helpful solutions.hello,
types:
begin of str,
vbeln like vbak-vbeln,
vkorg like vbak-vkorg,
vtweg like vbak-vtweg,
end of str.
types:
begin of st1,
lfstk like vbuk-vbeln,
end of st1.
types:
begin of st2,
vbeln like vbak-vbeln,
vkorg like vbak-vkorg,
vtweg like vbak-vtweg,
lfstk like vbuk-lfstk,
end of st2.
selection-screen: s_order for vbak-vbeln,
s_div for vbak-vtweg.
data: it type table of st with header line,
it1 type table of st1 with header line,
it2 type table of st2 with header line.
select vbeln vkorg vtweg from vbak into table it
where vbeln in s_order and
vkorg in s_div.
select lfstk from vbuk into table it1 for all entries in it
where vbeln = it-vbeln.
it2[] = it[].
append it1-lfstk into it2[].
or
move-corresponding it1 to it2.
" when i execute this code with a grid or list display, i m not able to get the values or entries for the 2nd table it1.
the it2 has the lfstk cloumn blank in the final display.
help me for a remedy.
rewards for useful suggestion.
Maybe you are looking for
-
SunOne Portal integration with other application
How Sun Portal Server integration with other appliction? Where are have this topic information(pdf,html,etc) Plealse help me ! Urgency!!!!! yuan [email protected]
-
SJSAS EE 8.1_02 / Bug in jss4.jar breaks our new release
+[Full environment description below]+ Problem description: our application server contains several applications including one J2EE application made of several WARs and EJBs. One of these EJBs starts some internal services that use an open source lib
-
Command plus numbers not working?
I use the Command 1, Command 2 keys in QuickTime Pro a lot to resize windows, but all of the sudden those key combos don't function at all. All Command key shortcuts seem to have left the computer. Not reboot nor Repair Disk Permissions helps. Did I
-
What is with the new update of Safari
Why can I not go on google anymore( when it comes up now, all I see is Yahoo and 4 other stuff)
-
IPhone and Keynote remote connection issues.
I have been trying to connect my phone to my computer so that I can use to keynote remote app. Over the wifi network there is a bunch of lag while trying to control so that is not good at all. Therefore I tried to use the ad-hoc mode from my macbook