• ABAP-数据引用


    *&---------------------------------------------------------------------*
    *& 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>.
  • 相关阅读:
    Java实现 蓝桥杯 算法训练 画图(暴力)
    Java实现 蓝桥杯 算法训练 画图(暴力)
    Java实现 蓝桥杯 算法训练 相邻数对(暴力)
    Java实现 蓝桥杯 算法训练 相邻数对(暴力)
    Java实现 蓝桥杯 算法训练 相邻数对(暴力)
    Java实现 蓝桥杯 算法训练 Cowboys
    Java实现 蓝桥杯 算法训练 Cowboys
    55. Jump Game
    54. Spiral Matrix
    50. Pow(x, n)
  • 原文地址:https://www.cnblogs.com/ricoo/p/10184284.html
Copyright © 2020-2023  润新知