‎2013 Aug 25 4:06 PM
Hi gurus,
i have 2 tables: one table has fields: field_name, from_char,str_len,str_value.
I need to delete all the records in the second table (internal table) that has the string value in the first table,
from char x (dynamic) and str_len(also dynamic)
the field name is also dynamic.
I hope that i was clear enough.
i really appreciate any help.
thanks in advanced,
Michal.
‎2013 Aug 26 4:45 AM
Thanks for getting it clarified.
Former Member , below code sample can be used as starting point. Assign Component statement is used to check and delete lt_destroy record based on data in lt_seek internal table. Run it in debug and see the value of <fs>.
TYPES:
BEGIN OF ty_seek,
field_name TYPE string,
from_char TYPE i,
str_len TYPE i,
str_value TYPE string,
END OF ty_seek,
BEGIN OF ty_destroy,
lifnr TYPE lifnr,
gjahr TYPE gjahr,
END OF ty_destroy.
DATA: lt_seek TYPE TABLE OF ty_seek,
ls_seek TYPE ty_seek,
lt_destroy TYPE TABLE OF ty_destroy,
ls_destroy TYPE ty_destroy,
lv_index TYPE i.
FIELD-SYMBOLS: <fs> TYPE any.
ls_seek-field_name = 'LIFNR'.
ls_seek-from_char = 3.
ls_seek-str_len = 2.
ls_seek-str_value = '12'.
APPEND ls_seek TO lt_seek.
ls_destroy-lifnr = '543210'.
ls_destroy-gjahr = '2011'.
APPEND ls_destroy TO lt_destroy.
ls_destroy-lifnr = '3451245'.
APPEND ls_destroy TO lt_destroy.
LOOP AT lt_seek INTO ls_seek.
LOOP AT lt_destroy INTO ls_destroy.
lv_index = sy-tabix.
ASSIGN COMPONENT ls_seek-field_name OF STRUCTURE ls_destroy TO <fs>.
IF sy-subrc EQ 0.
IF <fs>+ls_seek-from_char(ls_seek-str_len) EQ ls_seek-str_value.
DELETE lt_destroy INDEX lv_index.
ENDIF.
ENDIF.
ENDLOOP.
ENDLOOP.
‎2013 Aug 25 4:20 PM
‎2013 Aug 25 4:23 PM
Hi,
thanks for reply.
In the first table there also the name of the table because i have several tables.
Thanks,
Michal.
‎2013 Aug 25 4:50 PM
i'm asking about second table. your first table has four fields <field_name, from_char, str_len, str_value>...what are the fields in second table?
Rgds
‎2013 Aug 25 5:07 PM
In the second table there are fields:
Lifnr
Umskz
Gjahr
Belnr
Buzei
Xblnr
Blart.
‎2013 Aug 25 5:10 PM
im still not clear what you want achieve with these two tables. could you pls give an example with content of both tables and what you want to achieve.
Rgds
‎2013 Aug 25 5:17 PM
first table, the content:
Field name: xblnr
from_char: 10
str_len: 2
str_value: 12
the meaning is: search at the second table
field xblnr from char 10, 2 position search the string 12
if you find it - please delete it.
i hope that now it more clear.
thank you very much.
Michal.
‎2013 Aug 25 5:26 PM
ok. so for this particular example...look for field xblnr, if 10th & 11th character of xblnr are '12' then delete it. is this you want?
also, if table 2 has multiple records you want to delete xblnr from all the records?
Rgds
‎2013 Aug 25 5:28 PM
‎2013 Aug 25 5:29 PM
what if table 2 has multiple records...you want to check all the records and delete accordingly?
‎2013 Aug 25 5:33 PM
‎2013 Aug 26 4:45 AM
Thanks for getting it clarified.
Former Member , below code sample can be used as starting point. Assign Component statement is used to check and delete lt_destroy record based on data in lt_seek internal table. Run it in debug and see the value of <fs>.
TYPES:
BEGIN OF ty_seek,
field_name TYPE string,
from_char TYPE i,
str_len TYPE i,
str_value TYPE string,
END OF ty_seek,
BEGIN OF ty_destroy,
lifnr TYPE lifnr,
gjahr TYPE gjahr,
END OF ty_destroy.
DATA: lt_seek TYPE TABLE OF ty_seek,
ls_seek TYPE ty_seek,
lt_destroy TYPE TABLE OF ty_destroy,
ls_destroy TYPE ty_destroy,
lv_index TYPE i.
FIELD-SYMBOLS: <fs> TYPE any.
ls_seek-field_name = 'LIFNR'.
ls_seek-from_char = 3.
ls_seek-str_len = 2.
ls_seek-str_value = '12'.
APPEND ls_seek TO lt_seek.
ls_destroy-lifnr = '543210'.
ls_destroy-gjahr = '2011'.
APPEND ls_destroy TO lt_destroy.
ls_destroy-lifnr = '3451245'.
APPEND ls_destroy TO lt_destroy.
LOOP AT lt_seek INTO ls_seek.
LOOP AT lt_destroy INTO ls_destroy.
lv_index = sy-tabix.
ASSIGN COMPONENT ls_seek-field_name OF STRUCTURE ls_destroy TO <fs>.
IF sy-subrc EQ 0.
IF <fs>+ls_seek-from_char(ls_seek-str_len) EQ ls_seek-str_value.
DELETE lt_destroy INDEX lv_index.
ENDIF.
ENDIF.
ENDLOOP.
ENDLOOP.
‎2013 Aug 26 6:59 AM
Thank you very very much for your big help,
Manish Kumar and sudhanshu sharma
Its working perfectly.
Michal.
‎2013 Aug 26 7:06 AM