Monday, September 12, 2011

ABAP Field Symbol Usage


Here is a short sample which illustrates the usage of field symbols with work areas (headers) . Even though we don't know the number or the name of elements in a work area , we can dynamically get them like below. Field symbols are indispensable for complicated applications or reports. Also they could provide a solution for performance issues in some cases. Beside the usage below there are much more ways to use it. For more information just check out the documentation in sdn.




FIELD-SYMBOLS  TYPE ANY ,
                 TYPE ANY .

DATA t_table TYPE TABLE OF pa0001 WITH HEADER LINE.

SELECT FROM pa0001 INTO TABLE t_table UP TO 100 ROWS.

LOOP AT t_table ASSIGNING  .
WRITE /.
  " Loop at fields
  DO.
    ASSIGN COMPONENT sy-index OF STRUCTURE  TO .
    IF sy-subrc EQ 0.
      WRITE .
    ELSE.
      EXIT.
    ENDIF.
  ENDDO.

ENDLOOP.

No comments:

Post a Comment