Übung ABAP Development Tools

Aus MattWiki

Dieser Artikel enthält Quellcode für Klasse und Report, die im SAP Tutorial Get Started with ABAP Development erstellt werden.

Im Laufe dieser Übung werden einige neue Konzepte der Eclipse-Entwicklungsumgebung und der ABAP Development Tools (ADT) gezeigt:

  • Quick Fix-Menü mit Ctrl+1
  • Inline Definition von Variablen und Rückgabeparametern
  • Erstellung von Objekten mit dem Schlüsselwort NEW
  • ABAPDoc Kommentare in Klassen

Klasse ZCL_INVOICE_RETRIEVAL_MAOT

CLASS ZCL_INVOICE_RETRIEVAL_MAOT DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .

  PUBLIC SECTION.
    TYPES: ty_table_of_zso_invoice_item_m TYPE STANDARD TABLE OF zso_invoice_item_maot WITH DEFAULT KEY.

"! <p class"shorttext synchronized">Read items from DB</p>
"! Method reads invoice items from database
"! @parameter LT_RESULT | <p class"shorttext synchronized">Table of invoice items</p>
"!
    METHODS GET_ITEMS_FROM_DB
              RETURNING
                VALUE(lt_result) type ty_table_of_zso_invoice_item_m.
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.

CLASS ZCL_INVOICE_RETRIEVAL_MAOT IMPLEMENTATION.
  METHOD GET_ITEMS_FROM_DB.
    SELECT
      SNWD_BPA~COMPANY_NAME,
      SNWD_SO_INV_ITEM~GROSS_AMOUNT,
      SNWD_SO_INV_ITEM~CURRENCY_CODE,
      SNWD_SO_INV_HEAD~PAYMENT_STATUS
      FROM
       SNWD_SO_INV_ITEM
       JOIN SNWD_SO_INV_HEAD ON SNWD_SO_INV_ITEM~PARENT_KEY = SNWD_SO_INV_HEAD~NODE_KEY
       JOIN SNWD_BPA ON SNWD_SO_INV_HEAD~BUYER_GUID = SNWD_BPA~NODE_KEY
      WHERE
       SNWD_SO_INV_ITEM~CURRENCY_CODE = 'USD'
      ORDER BY  SNWD_BPA~COMPANY_NAME
      INTO TABLE @lt_result.

    " Definition des FIELD-SYMBOL <entry> inline 
    LOOP AT LT_RESULT ASSIGNING FIELD-SYMBOL(<ENTRY>).
      CASE <ENTRY>-PAYMENT_STATUS.
        WHEN 'P'.
          <ENTRY>-PAYMENT_STATUS = ABAP_TRUE.
        WHEN OTHERS.
          <ENTRY>-PAYMENT_STATUS = ABAP_FALSE.
      ENDCASE.
    ENDLOOP.
  ENDMETHOD.
ENDCLASS.

Report Z_INVOICE_ITEMS_EURO_MAOT

*&---------------------------------------------------------------------*
*& Report  z_invoice_items_euro_maot
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_INVOICE_ITEMS_EURO_MAOT.

CLASS LCL_MAIN DEFINITION CREATE PRIVATE.
  PUBLIC SECTION.
    CLASS-METHODS CREATE
      RETURNING
        VALUE(R_RESULT) TYPE REF TO LCL_MAIN.
    METHODS RUN.
  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.

CLASS LCL_MAIN IMPLEMENTATION.
  METHOD CREATE.
    CREATE OBJECT R_RESULT.
  ENDMETHOD.

  METHOD RUN.
    DATA: INVOICES TYPE REF TO ZCL_INVOICE_RETRIEVAL_MAOT.
    INVOICES = NEW ZCL_INVOICE_RETRIEVAL_MAOT( ).

    " Lokale Variable INVOICE_ITEMS inline definieren
    DATA(INVOICE_ITEMS) = INVOICES->GET_ITEMS_FROM_DB( ).

    CL_SALV_TABLE=>FACTORY(
      IMPORTING
        R_SALV_TABLE   = DATA(ALV_TABLE)    " Inline-Definition Basisklasse für einfache ALV-Tabellen
      CHANGING
        T_TABLE        = INVOICE_ITEMS
    ).

    ALV_TABLE->DISPLAY( ).
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  LCL_MAIN=>CREATE( )->RUN( ).