Search code examples
dynamicabapinternal-tablessap-query

How to loop at Table only having ref to data


I am using the function Module RSAQ_QUERY_CALL, getting back a table:

DATA: gr_data TYPE REF TO data.

CALL FUNCTION 'RSAQ_QUERY_CALL'
     EXPORTING
       query          = 'ZXXXXXXXX'
       usergroup      = 'XXX'
       VARIANT        = 'TEST'
       SKIP_SELSCREEN = 'X'
       DATA_TO_MEMORY = 'X'
     IMPORTING
       ref_to_ldata   = gr_data
     EXCEPTIONS
       OTHERS         = 11.

Now how can I loop at that table?

What I tried:

  • assign to a field symbol
  • passing a field symbol instead of dref

Both did not work.


Solution

  • I found the solution (after asking the senior dev..)

    FIELD-SYMBOLS: <gt_data> type table,
                   <row>     type any.
    
    ASSIGN gr_data->* to <gt_data>.
    
    LOOP AT <gt_data> ASSIGNING <row>.
    
      DO.
        ASSIGN COMPONENT sy-index OF STRUCTURE <row> TO <field>.
        IF sy-subrc <> 0.
          EXIT. " last field of row
        ENDIF.
    
        WRITE : / 'Field', sy-index, ':', <field>.
    
      ENDDO.
        
    ENDLOOP.