*&---------------------------------------------------------------------* *& Report ZRICO_TEST3 *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* report zrico_test3. data:ztb type string, zfd type string. data:gt_tab like table of mara with header line. start-of-selection. ztb = 'MARA'. zfd = 'MATNR'. field-symbols:<zs> type mara, <zl> type any, <z1> type any. data:dref type ref to data. create data dref type (ztb). assign dref->* to <zs>. assign component zfd of structure <zs> to <zl>. types:begin of t_struct, "*定義一個結構* col1 type i, col2 type i, end of t_struct. data: dref1 type ref to data, "*定義兩個數據引用* dref2 type ref to data. field-symbols: <fs1> type t_struct, "*定義兩個字段符號* <fs2> type i. create data dref1 type t_struct. "*利用數據引用,動態創建對象* assign dref1->* to <fs1>. "*因為數據引用只是地址,不能直接操作使用,需要把它分配給字段符號* <fs1>-col1 = 1. "*賦值給組件字段* <fs1>-col2 = 2. dref2 = dref1. "*把一個數據引用賦值給另一個數據引用* assign dref2->* to <fs1>. "*爲了要輸出,需要把數據應用分配給字段符號* write: / 'DREF2',<fs1>-col1, <fs1>-col2. "*可以直接輸出了* assign dref2->* to <fs2> casting. "*把結構變量分配給整形字段符號,因此要進行隱式數據類型轉換* write / <fs2>. "*輸出<FS2>字段符號變量內容* get reference of <fs1>-col2 into dref2. "*取得變量的數據應用,給DREF2* assign dref2->* to <fs2>. "*分配變量給字段符號<FS2>* write / <fs2>.