Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Clearing rows with empty value in one column

    DATA:
      dy_table          TYPE REF TO data.


    FIELD-SYMBOLS:

      <dyn_table>  TYPE STANDARD TABLE,
      <fs_segment> TYPE any.

    IF ID  = '1234'.


      me->method_that_import_desired_table( IMPORTING et_table = dy_table ).
      ASSIGN dy_table->* TO <dyn_table>.
      DATA(ls_dyn_table) = dy_table.
      LOOP AT <dyn_table> ASSIGNING FIELD-SYMBOL(<fs_row>).
        
        IF ls_dyn_table-segment IS INITIAL.
          CONTINUE.
        ENDIF.
      ENDLOOP.
    ENDIF.

I am trying to remove rows that has empty values in one column -segment. The table is declared dynamically so it does not have a standard type that i can use in DATA decleration like i used to do (DATA table_x TYPE BSEG).
I tried to create structure based of the imported table but I receive an error: "The data object "LS_DYN_TABLE" does not have a structure and therefore does not have a component called "SEGMENT".
Is there any way to declare dynamically a structure so i can loop through a table, remove rows and pass filtered table further?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

When you loop the internal table, you have to assign the field segment dynamically and check if it has a value:

LOOP AT <dyn_table>
     ASSIGNING FIELD-SYMBOL(<fs_row>).
  DATA(tabix) = sy-tabix. "note row index in internal table
  ASSIGN COMPONENT 'SEGMENT'
         OF STRUCTURE <fs_row>
         TO FIELD-SYMBOL(<segment>). 
  IF sy-subrc EQ 0 AND
     <segment> IS INITIAL.
    DELETE <dyn_table> INDEX tabix. "delete by row index
  ENDIF.
ENDLOOP.
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading