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

Delete lines from a dynamic internal table

Former Member
0 Likes
5,824

Hi,

Can anyone give me a code example of deleteing a line form a dynamic internal table (not by index).

Thanks.

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
1,887

Hello

Let us assume that your dynamic itab contains a field VKORG (sales organisation) and you want to delete all entries where VKORG = '1100'.


FIELD-SYMBOLS:
  <ls_record>   TYPE any.
  <ld_fld>         TYPE any.

  LOOP AT <lt_itab> ASSIGNING <ls_record>.
    UNASSIGN <ld_fld>.

    ASSIGN COMPONENT 'VKORG' OF STRUCTURE <ls_record> TO <ld_fld>.
    IF ( <ld_fld> IS BOUND ).
      IF ( <ld_fld> = '1100' ).
         DELETE <lt_itab> INDEX syst-tabix.
      ENDIF.
    ENDIF.

  ENDLOOP.

Regards

Uwe

5 REPLIES 5
Read only

uwe_schieferstein
Active Contributor
0 Likes
1,888

Hello

Let us assume that your dynamic itab contains a field VKORG (sales organisation) and you want to delete all entries where VKORG = '1100'.


FIELD-SYMBOLS:
  <ls_record>   TYPE any.
  <ld_fld>         TYPE any.

  LOOP AT <lt_itab> ASSIGNING <ls_record>.
    UNASSIGN <ld_fld>.

    ASSIGN COMPONENT 'VKORG' OF STRUCTURE <ls_record> TO <ld_fld>.
    IF ( <ld_fld> IS BOUND ).
      IF ( <ld_fld> = '1100' ).
         DELETE <lt_itab> INDEX syst-tabix.
      ENDIF.
    ENDIF.

  ENDLOOP.

Regards

Uwe

Read only

Former Member
0 Likes
1,887

Is there another way to delete the record, without using the record index ?

Read only

0 Likes
1,887

Hello

You may try the following variant which - at the end of the day - uses the INDEX internally.


FIELD-SYMBOLS:
  <ls_record>   TYPE any.
  <ld_fld>         TYPE any.
 
  LOOP AT <lt_itab> ASSIGNING <ls_record>.
    UNASSIGN <ld_fld>.
 
    ASSIGN COMPONENT 'VKORG' OF STRUCTURE <ls_record> TO <ld_fld>.
    IF ( <ld_fld> IS BOUND ).
      IF ( <ld_fld> = '1100' ).
         DELETE <lt_itab> FROM <ld_record>.  " not sure if this works
      ENDIF.
    ENDIF.
 
  ENDLOOP.
 

Regards

Uwe

Read only

Former Member
1,887

Yes, It doesn't work.

Read only

dhirendra_pandit
Active Participant
0 Likes
1,887

Thy following step.

1. Create a work area from dynamic table.

create data dyn_line like line of <fs_table>.

  assign dyn_line->* to <fs_wa_tmp>.

2. Loop your internal table to work area and build one temp work area and then delete the record from your new work area.

LOOP at <fs_table> assigning <fs_wa>.

clear <fs_wa_tmp>.

Do.

Assign component sy-tabix of structure <fs_wa> to <fs_val>. <<<<<<<<<<<<< Assign value

if sy-subrc ne 0.

EXIT.

else.

Assign component sy-tabix of structure <fs_wa_tmp> to <fs_val1>. <<<<<<<<<<<<< Assign value

<fs_val1> = <fs_val>.

enddo.

delete <fs_table> from <fs_wa_tmp>.

ENDLOOP.

Try this logic according to your requirement.

Regards,

Dhirendra Pandit