技术开发 频道

来自SAP的样例:Field Symbol 的Example

Assigning a structure by component

 

REPORT demo_field_symbols_assign_comp .

DATA: BEGIN OF line,
        col1 TYPE i VALUE
'11',
        col2 TYPE i VALUE
'22',
        col3 TYPE i VALUE
'33',
      END OF line.

DATA comp(
5) TYPE c VALUE 'COL3'.

FIELD
-SYMBOLS: <f1> TYPE ANY, <f2> TYPE ANY, <f3> TYPE ANY.

ASSIGN line TO
<f1>.
ASSIGN comp TO
<f2>.

DO
3 TIMES.
  ASSIGN COMPONENT sy
-index OF STRUCTURE <f1> TO <f3>.
  WRITE
<f3>.
ENDDO.

ASSIGN COMPONENT
<f2> OF STRUCTURE <f1> TO <f3>.
WRITE
/ <f3>.


--------------------------------------------------------------------------------

Casting with field symbol type

 

REPORT demo_field_symbols_casting.

TYPES: BEGIN OF t_date,
          year(
4)  TYPE n,
          month(
2) TYPE n,
          day(
2)   TYPE n,
       END OF t_date.

FIELD
-SYMBOLS <fs> TYPE t_date.

ASSIGN sy
-datum TO <fs> CASTING.

WRITE
/ sy-datum.
SKIP.
WRITE:
/ <fs>-year , / <fs>-month, / <fs>-day.


--------------------------------------------------------------------------------

Casting with explicit type

 

REPORT demo_field_symbols_casting_typ.

TYPES: BEGIN OF t_date,
          year(
4)  TYPE n,
          month(
2) TYPE n,
          day(
2)   TYPE n,
       END OF t_date.

FIELD
-SYMBOLS: <fs> TYPE ANY,
              
<f>  TYPE n.

ASSIGN sy
-datum TO <fs> CASTING TYPE t_date.

WRITE
/ sy-datum.

SKIP.

DO.
  ASSIGN COMPONENT sy
-index OF STRUCTURE <fs> TO <f>.
  IF sy
-subrc <> 0.
    EXIT.
  ENDIF.
  WRITE
/ <f>.
ENDDO.

0
相关文章