You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

运行Simple Transformation时出现CX_ST_REF_ACCESS引用节点错误

解决CX_ST_REF_ACCESS异常:Simple Transformation引用节点错误

问题根源分析

触发CX_ST_REF_ACCESS异常的核心原因是Simple Transformation(ST)代码中对根节点的无效循环操作,以及多处引用路径与ABAP数据结构不匹配:

  • 根节点循环错误:ST中<tt:loop name="PurchaseOrder" ref="PurchaseOrder">试图循环遍历根结构PurchaseOrder,但该节点对应ABAP中的单个结构体(而非内表),循环操作无效。
  • 引用路径不匹配:ST中多处引用的字段名与ABAP结构体中的字段名不一致(如PurchaseOrder.Address vs ABAP中的addresses)。
  • DeliveryNotes引用错误:直接引用根节点而非具体字段deliverynotes。
  • Items循环引用错误:循环根节点而非内表items。

修正后的Simple Transformation代码

<?sap.transform simple?>
<tt:transform xmlns:tt="http://www.sap.com/transformation-templates">
  <tt:root name="PurchaseOrder"/>

  <!-- Root element: PurchaseOrder -->
  <tt:template>
    <PurchaseOrder>

      <!-- Address Elements -->
      <Address>
        <tt:loop name="address" ref="PurchaseOrder.addresses">
          <Name>
            <tt:value ref="name"/>
          </Name>
          <Street>
            <tt:value ref="street"/>
          </Street>
          <City>
            <tt:value ref="city"/>
          </City>
          <State>
            <tt:value ref="state"/>
          </State>
          <Zip>
            <tt:value ref="zip"/>
          </Zip>
          <Country>
            <tt:value ref="country"/>
          </Country>
        </tt:loop>
      </Address>

      <!-- DeliveryNotes Element -->
      <DeliveryNotes>
        <tt:value ref="PurchaseOrder.deliverynotes"/>
      </DeliveryNotes>

      <!-- Items Section -->
      <Items>
        <tt:loop name="item" ref="PurchaseOrder.items">
          <Item>
            <ProductName>
              <tt:value ref="productname"/>
            </ProductName>
            <Quantity>
              <tt:value ref="quantity"/>
            </Quantity>
            <USPrice>
              <tt:value ref="usprice"/>
            </USPrice>
            <tt:cond>
              <Comment>
                <tt:value ref="comment"/>
              </Comment>
            </tt:cond>
            <tt:cond>
              <ShipDate>
                <tt:value ref="shipdate"/>
              </ShipDate>
            </tt:cond>
          </Item>
        </tt:loop>
      </Items>
    </PurchaseOrder>
  </tt:template>
</tt:transform>

关键修正点说明

  1. 移除根节点循环:删除包裹<PurchaseOrder>的<tt:loop>,因为根节点对应单个ABAP结构体,无需循环。
  2. 修正Address循环引用:将ref="PurchaseOrder.Address"改为ref="PurchaseOrder.addresses",匹配ABAP结构体中的内表字段名;同时修正循环名称的拼写错误(Adress→address)。
  3. 修正DeliveryNotes引用:将ref="PurchaseOrder"改为ref="PurchaseOrder.deliverynotes",指向结构体中的具体字段。
  4. 修正Items循环引用:将ref="PurchaseOrder"改为ref="PurchaseOrder.items",循环遍历ABAP中的items内表。

ABAP代码优化建议(非错误但最佳实践)

将结构体定义为类型而非直接声明数据对象,提升代码可读性和复用性:

TYPES: BEGIN OF ty_purchase_order,
         addresses     TYPE TABLE OF ty_address,
         deliverynotes TYPE string,
         items         TYPE TABLE OF ty_item,
       END OF ty_purchase_order.

DATA: gs_purchase_order TYPE ty_purchase_order.

CALL TRANSFORMATION ZJB_TRAN0
SOURCE XML gv_xml_string
RESULT PurchaseOrder = gs_purchase_order.

内容的提问来源于stack exchange,提问作者Julian Baltzer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 09:10:56