Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Need delete dynamic record from internal table

Former Member
0 Likes
1,458

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,420

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.

13 REPLIES 13
Read only

Former Member
0 Likes
1,420

what is structure of second internal table?

Rgds

Read only

0 Likes
1,420

Hi,

thanks for reply.

In the first table there also the name of the table because i have several tables.

Thanks,

Michal.

Read only

0 Likes
1,420

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

Read only

0 Likes
1,420

In the second table there are fields:

Lifnr

Umskz

Gjahr

Belnr

Buzei

Xblnr

Blart.

Read only

0 Likes
1,420

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

Read only

0 Likes
1,420

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.

Read only

0 Likes
1,420

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

Read only

0 Likes
1,420

That right.

This is excactly what i need.

Read only

0 Likes
1,420

what if table 2 has multiple records...you want to check all the records and delete accordingly?

Read only

0 Likes
1,420

yes.

Read only

Former Member
0 Likes
1,421

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.

Read only

0 Likes
1,420

Thank you very very much for your big help,

Manish Kumar and sudhanshu sharma

Its working perfectly.

Michal.

Read only

0 Likes
1,420

wow ! Awesome Manish !!