Skip to Content
Previous

Display a CDS view using ALV with IDA

By Julie Plummer

Display a CDS view in the SAP List Viewer with Integrated Data Access (IDA)

Details

You will learn

In this tutorial, you will learn how to consume the CDS view in the SAP List Viewer with Integrated Data Access (ALV with IDA). ALV with IDA lets you display views and tables that contain very large quantities of data.
Optional: You can also improve the appearance of your SAP List Viewer by adding a CAST statement to the CDS view.


Step 1: Open the ABAP program

Open the ABAP program you created in the previous tutorial, Create and run an ABAP program.

  • Either choose Programs > Z_INVOICE_ITEMS_EURO:
    Image depicting step1-open-program

  • Or choose Open ABAP Development Object (Ctrl+Shift+A) and enter the program name, Z_INVOICE_ITEMS_EURO:
    Image depicting step-1-ctrl-shift-a

Step 2: Add ALV grid to method implementation

You will now replace the implementation of the RUN method with a new implementation:

  1. Delete the WRITE statement: Delete the whole line, by placing the cursor somewhere in the WRITE statement and choosing Ctrl+D:
    Image depicting step2-delete-write
  2. Now create an ALV with IDA for your CDS view Z_Invoice_Items and display the ALV in full screen:
    cl_salv_gui_table_ida=>create_for_cds_view( 'Z_Invoice_Items' )->fullscreen( )->display( ).
    Image depicting step2a-add-ida
  3. Choose Save (Ctrl+S) and Activate (Ctrl+F3).
  4. Execute your program by choosing Execute (F8).

The invoice items are displayed in ALV with IDA.

Step 3: Set the tooltip information with an annotation

Try to display the tooltip information for the Paid column by positioning the cursor on the column heading.
Notice that, in our case, the information is either missing or incorrect (depending on your version).
We will change this information in the CDS view using an annotation. (For more information, see Create a CDS view )

NOTE: Write the annotation before the CASE statement.

  1. In the CDS view, Z_Invoice_Items set the tooltip information for the payment_status to:
    @EndUserText.quickInfo: 'Paid'

  2. Choose Save (Ctrl+S) and Activate (Ctrl+F3).

  3. Run the program again. The SAP List Viewer should look like this:
    Image depicting step-5-mouse-over-paid
Step 4: optional: Create a data element

You have created a tooltip for the column “Paid” but there is no column header for it. You will now resolve this by casting the type of the transformed payment_status to a data element - zso_invoice_payment_status - by using a CAST statement. (Ignore the warning).
If you have already created a data element in the tutorial Create a data element, then use this and go to step 5. Otherwise proceed as follows:

  1. Create the data element zso_invoice_payment_status: Choose File > New… > Other… > Data… > Dictionary > Data element: and enter the following:
    • Package, e.g., Zxx_Tutorial (where xx = your initials)
    • Name = zso_invoice_payment_status
    • Description
  2. Choose Finish.
  3. Enter the following values:
    • Type Name = Flag
    • Field labels: Short = Paid
    • Field labels, others = Invoice Paid
      Image depicting step-5-data-element
Step 5: optional: Add a CAST statement
  1. Now add the CAST statement. (Ignore the warning):
    cast(
        case header.payment_status
            when 'P' then 'X'
            else ' '
        end
    as zso_invoice_payment_status )
    
    as payment_status,
    
  2. Save and activate the CDS view (Ctrl+S, Ctrl+F3). If you run the program now, your SAP List Viewer should look like this:
    Image depicting step-6-column-header-paid

Note: You can open the online help for the CAST statement by positioning the cursor on the cast keyword and choosing F1

Step 6: Check the code and execute the program

Your program code should look like this:

*&---------------------------------------------------------------------*
*& Report zjp_cds_inv_items_test
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zjp_cds_inv_items_test.

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.

cl_salv_gui_table_ida=>create_for_cds_view(`Z_Invoice_Items`)->fullscreen( )->display( ).
  endmethod.
endclass.

start-of-selection.

lcl_main=>create( )->run( ).

Your CDS view should look like this:

@AbapCatalog.sqlViewName: 'ZINVOICEITEMS'
@AbapCatalog.compiler.compareFilter: true
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: 'CDS View for "Use-cds-view" tutorial'
define view Z_Invoice_Items
  as select from sepm_sddl_so_invoice_item
{
  //sepm_sddl_so_invoice_item

  header.buyer.company_name,
  sepm_sddl_so_invoice_item.sales_order_invoice_key,
  sepm_sddl_so_invoice_item.currency_code,
  sepm_sddl_so_invoice_item.gross_amount,

@EndUserText.quickInfo: 'Paid'  
cast(
    case header.payment_status
        when 'P' then 'X'
        else ' '
    end
as zso_invoice_payment_status )

as payment_status,

//* Associations *//
  header
}

Execute ZCDS_INVOICE_ITEMS_EURO again by choosing Execute (F8).

The mouse-over information for the Paid column has been changed:

Image depicting step-5-mouse-over-paid

Next Steps

Updated 03/13/2018

Time to Complete

15 Min

Beginner

Tags

Prerequisites

Next Steps

Next
Back to top