zoukankan      html  css  js  c++  java
  • 如何在SAP云平台ABAP编程环境里创建自己的Z表

    选中ABAP包,右键创建一个新的Database Table:

    clipboard1,1
    clipboard2,2

    维护表名为ZBOOKING:

    clipboard3,3

    表实现的源代码:

    @EndUserText.label : 'Jerry''s booking'
    @AbapCatalog.enhancementCategory : #NOT_EXTENSIBLE
    @AbapCatalog.tableCategory : #TRANSPARENT
    @AbapCatalog.deliveryClass : #A
    @AbapCatalog.dataMaintenance : #LIMITED
    define table zbooking {
      key client         : abap.clnt not null;
      key booking        : abap.int4 not null;
      customername       : abap.char(50);
      numberofpassengers : abap.int2;
      emailaddress       : abap.char(50);
      country            : abap.char(50);
      dateofbooking      : timestampl;
      dateoftravel       : timestampl;
      @Semantics.amount.currencyCode : 'zbooking.currencycode'
      cost               : abap.curr(15,2);
      currencycode       : abap.cuky;
      lastchangedat      : timestampl;
    
    }
    

    激活:

    clipboard4,4

    下一步,创建一个ABAP类,以代码的方式往Z表里插入数据。

    这个ABAP类要实现if_oo_adt_classrun接口,类似Java里的console应用:

    clipboard5,5

    完整代码:

    clipboard6,6

    CLASS zcl_data_generator DEFINITION
      PUBLIC
      FINAL
      CREATE PUBLIC .
    
      PUBLIC SECTION.
        INTERFACES if_oo_adt_classrun.
      PROTECTED SECTION.
      PRIVATE SECTION.
    ENDCLASS.
    
    
    CLASS zcl_data_generator IMPLEMENTATION.
    
      METHOD if_oo_adt_classrun~main.
        DATA:it_bookings TYPE TABLE OF zbooking.
    
    *    read current timestamp
        GET TIME STAMP FIELD DATA(zv_tsl).
    *   fill internal table (itab)
        it_bookings = VALUE #(
            ( booking  = '1' customername = 'Jerry' numberofpassengers = '3'
              emailaddress = 'jerry@sap.com'
              country = 'China' dateofbooking ='20190213125959' dateoftravel ='20190213125959'
              cost = '546' currencycode = 'EUR' )
            ( booking  = '2' customername = 'Tom' numberofpassengers = '1'
              emailaddress = 'tom@sap.com'
              country = 'USA' dateofbooking ='20190313125959' dateoftravel ='20190313125959' cost = '1373' currencycode = 'USD' lastchangedat = zv_tsl )
         ).
    
        DELETE FROM zbooking.
    
        INSERT zbooking FROM TABLE @it_bookings.
    
        SELECT * FROM zbooking INTO TABLE @it_bookings.
        out->write( sy-dbcnt ).
        out->write( 'data inserted successfully!').
    
      ENDMETHOD.
    
    ENDCLASS.
    

    执行这个console应用:

    clipboard7,7

    成功插入两条数据:

    clipboard8,8

    选中Z表,选择Open with Data Preview:

    clipboard9,9

    看到了成功插入的两条数据:

    clipboard10,10

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

  • 相关阅读:
    wpf 控件回车事件中调用tab实现方法
    C#中M的N次方显示
    新概念英语第三册单词
    新概念英语第二册单词
    手把手教你搭建一个vue项目
    Vuex里的module选项和移动端布局
    Vuex与axios的封装和调用
    Vue路由
    Vue脚手架的搭建和路由配置
    Vue全家桶之一Vue(基础知识篇)
  • 原文地址:https://www.cnblogs.com/sap-jerry/p/11604128.html
Copyright © 2011-2022 走看看