创建全局ABAP类

You will learn

  • How to create a global class that retrieves data from the back end
  • How to use an internal table
  • How to use an ABAP structure as a type for the returning parameter
  • How to display data in a SAP List Viewer (“ALV Grid”)

Step 1: Open your ABAP program and remove the WRITE statement

  1. First, open your ABAP program, ZSO_INVOICE_ITEMS_EURO which you created in the previous tutorial, Create and run an ABAP application.

    Image depicting step1-open-abap-program
  2. Remove the existing method implementation for the run method.

    Image depicting step2-delete-write

完成

Step 2: Create an instance of a new global class

Now you will create the an object with the type of a new global class, for retrieving backend data.

  1. In the run method, create an instance of class zcl_invoice_retrieval using the new operator:

ABAP

Copy

data(invoices) = new ZCL_INVOICE_RETRIEVAL( ).
  1. Since this class does not yet exist, you will get a syntax error. To create the class, place the cursor on the class name and open the Quick Assist by choosing Ctrl+1. In the Quick Assist menu, double-click on Create global class zcl_invoice_retrieval:

    Image depicting step3-create-class_2
  2. A wizard will appear to create a new ABAP class. Enter:

    • a name ZCL_INVOICE_RETRIEVAL
    • a description invoice Retrieval
  3. Choose Finish:

    Image depicting step3a-create-class-finish

A new editor will be opened showing the class you have created, ZCL_INVOICE_RETRIEVAL.

Since release 7.40, ABAP permits inline declarations. For more information, see: - Old and new ABAP syntax – overview sheet - 7.4 Release News - Inline Declaration I

完成

Step 3: Check the syntax

If necessary, go back to your program and trigger the syntax check using the keyboard shortcut Ctrl+F2.

The syntax error should no longer occur.

完成

Step 4: Create a method to get the database records

To read the records from the database, you need to call a method get_items_from_db.This method does not yet exist so we will create it with a Quick Assist as follows:

  1. Still in your program, enter an instance method call:

    ABAP

    Copy

    data(invoice_items) = invoices->get_items_from_db( ).
    
    
  1.  
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值