Create and Run an ABAP Application

这篇教程详细介绍了如何基于SAP NetWeaver演示样本EPM模型创建和运行ABAP应用程序。内容包括创建新的ABAP程序,创建本地类,实现CREATE和RUN方法,使程序可运行,保存并激活程序,以及在程序中输出系统变量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ou will learn


Step 1: Create New ABAP Program

In the toolbar, choose New > ABAP Program…:

Image depicting step1-new-program

A wizard appears to create a new ABAP Program. Enter z_invoice_items_euro in the name field. Enter a meaningful text in the description field. Choose Finish to create the report.Afterwards an editor will be opened which shows the empty report.

Image depicting step1b-program-properties

完成

Log on to answer question

Step 2: Create ABAP local class

  1. Type lcl and choose Ctrl+Space to get code completion proposals. Select the code template for the insertion of a local class by choosing lcl - Local class or choose Enter if the right entry is already selected.

    Image depicting step2-local-class-quick-fix
  2. Adjust the name of the local class to lcl_main using inline editing.

    Image depicting step2-local-class

完成

Log on to answer question

Step 3: Create CREATE method

Position the cursor in the class definition statement and choose Ctrl+1 to open the Quick Fix menu. Choose Generate factory method create to create a static factory method.

Image depicting step3-create-method

完成

Log on to answer question

Step 4: Implement RUN method

  1. Add the definition of an additional instance method run by entering methods run. in the public section.

  2. Then position the cursor on the method name and choose Ctrl+1 to open the Quick-Fix menu. Choose Add implementation for run.

    Image depicting step4-run-method
  3. Implement a simple WRITE statement in the method run.

    Image depicting step4b-write-statement

完成

Log on to answer question

Step 5: Make ABAP program runnable

  1. Add a START-OF-SELECTION event to your report

  2. Create an instance of the local class lcl_main.

  3. Call the run method.That is, enter the following code:

    ABAP

    Copy

    START-OF-SELECTION.
        lcl_main=>create( )->run( ).
    
  1. Image depicting step5-create-run-statement

Class methods are called using => ; instance methods are called using ->.

完成

Log on to answer question

Step 6: Save and Activate ABAP Program

Save and activate your program by choosing Save and Activate in the toolbar.

Image depicting step6-save-and-activate-program

完成

Log on to answer question

Step 7: Run the ABAP Program

Choose F8 to run your program. An embedded SAP GUI will open inside an Eclipse editor. After checking the output of the report choose Close.

Image depicting step7-run-program

完成

Log on to answer question

Step 8: Output system variables in your program

You will now enhance the program to output your user name and today’s date. Change the WRITE statement to:

WRITE: 'Welcome, ', sy-uname, / 'Today is the', sy-datum.

Image depicting step8-enhance-write

sy- is the table containing all the system fields. For the complete list, see the ABAP keyword documentation: ABAP System Fields.

/ is simply the new line character. (See also ABAP keyword documentation: WRITE.)

完成

Log on to answer question

Step 9: Run the ABAP Program

Again, choose F8 to run your program. Your output should now look something like this:

Image depicting step9-run-program-2

完成

Log on to answer question

Step 10: Check your code

Your code should look like this:

ABAP

Copy

*&---------------------------------------------------------------------*
*& Report zjp_basic_app
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT z_invoice_items_euro.

class lcl_main definition create private.

  public section.
    methods run.
    CLASS-METHODS create
      RETURNING
        value(r_result) TYPE REF TO lcl_main.

  protected section.
  private section.

endclass.

class lcl_main implementation.

  method create.
    create object r_result.
  endmethod.

  method run.
    WRITE: 'Welcome, ', sy-uname, / 'Today is the', sy-datum.

  endmethod.

endclass.

START-OF-SELECTION.
    lcl_main=>create( )->run( ).

完成

Log on to answer question

Step 11: Test yourself

Add the event keyword that turns a report into an executable program, then directly call the class method Main of the class Demo. (Don’t indent your lines of code; pay attention to space characters.) Enter the code in the box below and choose Validate:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值