‎2006 Dec 04 7:11 AM
Hi everyone,
Consider the two fields person and ssn.For a particular ssn value if exists two or more different person values,then i want to put that details as a duplicate records to the internal table.Kindly help me in making this.Thanx in advance.
‎2006 Dec 04 8:37 AM
Hi,
find duplicates by inserting into table with unique key. Something like that:
data:
* define unstructured hashed tables to check duplicates
lt_ssn type hashed table of ssn
with unique key table_line,
lt_ssn_dup type hashed table of ssn
with unique key table_line.
loop at itab.
insert itab-ssn into table lt_ssn.
if sy-subrc <> 0.
* insert fails because ssn already exists -> duplicate
insert itab-ssn into table lt_ssn_dup.
endif.
endloop.
* now all duplicates are in lt_ssn_dup.
loop at itab.
read table lt_ssn_dup transporting no fields
with key table_line = itab-ssn.
if sy-subrc = 0.
* process duplicate ssn here...
else.
* process unique ssn here...
endif.
endloop.
I would prefer to use LOOP AT itab ASSIGNING <field-symbol> but many colleagues are just frightened by field-symbols - you must get used to the performance gain...
Instead of TYPE ssn use the data element linked to field ssn.
Regards,
Clemens
‎2006 Dec 04 7:15 AM
Hi,
select * from PA0002 into table itab where perid = <var>
begda <= sy-datum
endda >= sy-datum.
endselect.
this will call all values in table itab now you can get your pernr there.
Regards,
Amit
‎2006 Dec 04 7:19 AM
Hi Satheesh,
Plz use the following code.
Lets assume you have the data in LT_DATA.
Sort WA_DATA by SSN.
loop at LT_DATA into WA_DATA.
if lv_ssn equals to WA_DATA-SSN.
lv_flag = 1.
endif.
lv_ssn = WA_DATA-ssn.
At new ssn.
if lv_flag = 1.
* --> Please place your duplicate related code here
endif.
endat.
clear lv_flag.
endloop.Regards
Bhupal Reddy
‎2006 Dec 04 8:05 AM
Hi everyone,
Thanx for ur comments. one small correction there will be more ssn values in the table and for each entry i have to validate if there are more persons assigned an d there by i have to send the duplicate records for the single SSN value .In that case i can't assign the local variable as you all mentioned.Thanks.
‎2006 Dec 04 8:37 AM
Hi,
find duplicates by inserting into table with unique key. Something like that:
data:
* define unstructured hashed tables to check duplicates
lt_ssn type hashed table of ssn
with unique key table_line,
lt_ssn_dup type hashed table of ssn
with unique key table_line.
loop at itab.
insert itab-ssn into table lt_ssn.
if sy-subrc <> 0.
* insert fails because ssn already exists -> duplicate
insert itab-ssn into table lt_ssn_dup.
endif.
endloop.
* now all duplicates are in lt_ssn_dup.
loop at itab.
read table lt_ssn_dup transporting no fields
with key table_line = itab-ssn.
if sy-subrc = 0.
* process duplicate ssn here...
else.
* process unique ssn here...
endif.
endloop.
I would prefer to use LOOP AT itab ASSIGNING <field-symbol> but many colleagues are just frightened by field-symbols - you must get used to the performance gain...
Instead of TYPE ssn use the data element linked to field ssn.
Regards,
Clemens
‎2006 Dec 04 9:11 AM
Hi Li,
Thanx for valuable information.Can i able to do the same with field symbols..I am new to this..just gimme the same example in terms of the field symbols please.Thanks in advance.
‎2006 Dec 04 1:22 PM
Hi Satheesh,
just a slight difference. Looping tables usually means a copy of the table record to the header line for each loop, using field-symbols just puts an address pointer to the actual record. Then you can access it directly. If (not here!) you modify a table, changing the field-symbols content means changing the table record - so no modify is will be used.
Now the code:
field-symbols:
<itab> like itab.
loop at itab assigning <itab>.
insert <itab>-ssn into table lt_ssn.
if sy-subrc <> 0.
* insert fails because ssn already exists -> duplicate
insert <itab>-ssn into table lt_ssn_dup.
endif.
endloop.
* now all duplicates are in lt_ssn_dup.
loop at itab assigning <itab>.
read table lt_ssn_dup transporting no fields
with key table_line = <itab>-ssn.
if sy-subrc = 0.
* process duplicate ssn here...
else.
* process unique ssn here...
endif.
endloop.
Note: If you use field-symbol looping at hashed or sorted table, you can not change the key fields - in debugger they are greyed out.
Have fun with field-symbols!
Regards
Clemens
[Li is the family name, so please Clemens or Mr. Li)
‎2006 Dec 05 9:44 AM
Hi Clemens,
Thank you for ur valuable information.sorry for the mistake.:).I am using the internal with work area is it possible to assign the field symbol to a work area for the same example you gave me...
‎2006 Dec 05 10:19 AM
Hi Satheesh,
you can assign the field-symbol to any data area. It does not matter if you declared your internal table with or without header line. I think you mean header line when you say work area. A work area usually is declared separately:
data:
itab1 type table of whatever,
itab_wa type whatever,
itab2 type table of whatever with header line.
field-symbols:
<whatever> type whatever.
* internal table without header line using work area
loop at itab1 into itab_wa.
itab_wa-field1 = 'XYZ'.
modify itab1 from itab_wa.
endloop.
* internal table with header line (implicit work area)
loop at itab2.
itab2-field1 = 'XYZ'.
modify itab2.
endloop.
* internal table without header line using field-symbol
loop at itab1[] assigning <whatever>.
<whatever>-field1 = 'XYZ'.
endloop.
* internal table with header line using field-symbol
loop at itab2 assigning <whatever>.
<whatever>-field1 = 'XYZ'.
endloop.
This is all the same. Internal tables with header line are not allowed in object-oriented context, i.e. declared within classes because the internal table has the same name as the header line. in non-OO-context you can distinguish between table body and headerline with the addition of square brackets [] for table body.
The field-symbols alternative is a lot faster. Using explicit (work area) or implicit header line means to copy all fields from body to header line/work area for each loop and copy all fields from header line/work area back to the boy using the modify statement.
Using the field symbols with LOOP...ASSIGNING means to have direct access to the actual record in table body.
Regards,
Clemens