2010 May 06 5:51 AM
I have an Internal table(gi_sorted_material) with matnr as unique key but I have to insert values into it from another table(gi_material), but while inserting in loop it may be case that the gi_material may have multiple matnr with same number so i want that to be ignored while inserting , currently it gives runtime error or some syntax error.
I used this:
gi_sorted_material TYPE SORTED TABLE OF t_material WITH UNIQUE KEY matnr.
ls_sorted_material TYPE t_material.
READ TABLE gi_material INTO ls_material INDEX 1.
How to insert values from gi_material into gi_sorted_material
2010 May 06 6:19 AM
Hi,
Pls. read help for 'UNIQUE' , which says
"For a table key specified with UNIQUE,
a row with a certain key field content can only occur once in an internal table of this type" ...
So, it's not possible to insert another record with the same key.
Regards,
Srini.
I have an Internal table(gi_sorted_material) with matnr as unique key but I have to insert values into it from another table(gi_material), but while inserting in loop it may be case that the gi_material may have multiple matnr with same number so i want that to be ignored while inserting , currently it gives runtime error or some syntax error.
I used this:
gi_sorted_material TYPE SORTED TABLE OF t_material WITH UNIQUE KEY matnr.
ls_sorted_material TYPE t_material.
READ TABLE gi_material INTO ls_material INDEX 1.
How to insert values from gi_material into gi_sorted_material
2010 May 06 6:12 AM
2010 May 06 6:19 AM
Hi,
Pls. read help for 'UNIQUE' , which says
"For a table key specified with UNIQUE,
a row with a certain key field content can only occur once in an internal table of this type" ...
So, it's not possible to insert another record with the same key.
Regards,
Srini.
2010 May 06 6:25 AM
Hi,
Try below code
gi_sorted_material TYPE SORTED TABLE OF t_material WITH UNIQUE KEY matnr.
ls_sorted_material TYPE t_material.
loop at gi_maternal into ls_material.
read table gi_sorted_material into wa_sorted_material with key matnr = ls_material-matnr.
if sy-subrc eq 0.
modify gi_sorted_material from ls_material index sy-tabix.
else
append ls_material to gi_sorted_material.
endloop.Regards
Vinod
2010 May 06 6:27 AM
Hi,
Try This code,
loop at ls_sorted_material into wa.
insert wa into table gi_sorted_material."It will Not insert Duplicates of MATNR
endloop.
Regards,
Raghava Channooru
2010 May 06 6:32 AM
Hi Karan,
If you want a unique record in your gi_sorted_material table then you can do 1 thing,
Just delete the duplicate records from the internal table gi_material comparing matnr.
SORT gi_material BY matnr.
DELETE ADJACENT DUPLICATES FROM gi_material COMPARING matnr.
This will give you all unique records in gi_material itself.
Then loop into gi_material and assign the records in gi_sorted_material according to your requirement.
Hope this helps.
Regards,
Vaibhav
| User | Count |
|---|---|
| 6 | |
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |