3

Consume CDS View inside AMDP Procedure

 1 year ago
source link: https://blogs.sap.com/2022/12/03/consume-cds-view-inside-amdp-procedure/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
December 3, 2022 1 minute read

Consume CDS View inside AMDP Procedure

In previous article, we have experienced by using CDS View inside CDS Table function. And now, we will try with AMDP procedure

Like as CDS table function, with AMDP Procedure, we will also catch an error

CDS_001.png

Because this CDS View which we used in this article is a client specific. But AMDP is not. Basically, AMDP will get all data of all client (assume your system have several clients), that is a reason why you catch this error when working with CDS view.

So, how to resolve it? Please read this article with me.

Prerequisites:

A little bit CDS View and AMDP. If you don’t have any experience, please follow link

Solution

We will create Global Class and handle method to get data from CDS View, both standard CDS View and Customized CDS View are good

CLASS zcl_demo_amdp DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .
  PUBLIC SECTION.
    INTERFACES if_amdp_marker_hdb .
    TYPES: BEGIN OF ty_test,
             mandt TYPE mandt,
             bukrs TYPE bukrs,
             belnr TYPE belnr_d,
             gjahr TYPE gjahr,
             docln TYPE docln,
           END OF   ty_test.
    TYPES: tt_test TYPE STANDARD TABLE OF ty_test.

    CLASS-METHODS:
      get_CDS  AMDP OPTIONS CDS SESSION CLIENT current
               EXPORTING VALUE(tt_return) TYPE tt_test .


  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.



CLASS zcl_demo_amdp IMPLEMENTATION.
  METHOD get_CDS BY DATABASE PROCEDURE
                 FOR HDB LANGUAGE SQLSCRIPT
                 OPTIONS READ-ONLY  USING i_journalentryitem .

    TT_RETURN = SELECT MANDT                    AS MANDT,
                       CompanyCode              AS BUKRS,
                       AccountingDocument       AS BELNR,
                       FiscalYear               AS GJAHR,
                       LedgerGLLineItem         AS DOCLN
            FROM I_JournalEntryItem;
  ENDMETHOD.


ENDCLASS.

AMDP OPTIONS CDS SESSION CLIENT current is very important, With this statement, the system will only get the correct data of the current client

Yeah, we have successfully used CDS view inside AMDP Procedure, I hope it can help you!!!

If this blog is good, please like and share it. If you don’t understand something, please leave a comment in the article.

Thanks so much.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK