前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ABAP 7.40新的关键字BASE的用法

ABAP 7.40新的关键字BASE的用法

作者头像
Jerry Wang
发布2020-01-21 14:47:34
1.7K0
发布2020-01-21 14:47:34
举报
*&---------------------------------------------------------------------*
*& Report ZMOVE_CORRESPONDING
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT ZBASE.

DATA:
  BEGIN OF struct1,
    col1 TYPE i VALUE 11,
    col2 TYPE i VALUE 12,
  END OF struct1.

DATA:
  BEGIN OF struct2,
    col2 TYPE i VALUE 22,
    col3 TYPE i VALUE 23,
  END OF struct2.

*This is not the same as
*MOVE-CORRESPONDING struct2 TO struct1.
*Since the RHS does not know anything of the LHS, component col3 of struct2 does not
*keep its former value but is initialized.

" struct2 = CORRESPONDING #( struct1 ).

*Of course, it is a common use case to add new values to existing values. Therefore,
*with Release 740, SP08 there is a new addition BASE for constructor expressions NEW, VALUE
*and CORRESPONDING that allows you to give the expressions a start value.  Very
*often, this means to make the LHS known to a RHS. For the examples shown above,
*  this simply will look as follows:
*
*The result of the expression is initialized with struct2 and then the evaluation takes place.
* Now it works like MOVE-CORRESPONDING, col3 of struct2 keeps its former value.

struct2 = CORRESPONDING #( BASE ( struct2 ) struct1 ).

BREAK-POINT.

DATA itab TYPE TABLE OF i.

itab = VALUE #( ( 1 ) ( 2 ) ( 3 ) ).
itab = VALUE #( BASE itab ( 4 ) ( 5 ) ( 6 ) ).

"You can als construct structures using BASE:

struct2 = VALUE #( BASE struct1  col3 = 33 ).

"First, all components are taken over from struct1, then the columns specified are overwritten.
BREAK-POINT.

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-01-13 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档