0% found this document useful (0 votes)
6 views5 pages

Table Function in CDS Views

The document provides a guide for creating a CDS Table Function in ABAP, including the definition of the function and the implementation of an AMDP method. It details the steps to create a simple ABAP program that selects data from the CDS Table Function and displays the output. The implementation ensures that data retrieval occurs at runtime through the defined methods and classes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views5 pages

Table Function in CDS Views

The document provides a guide for creating a CDS Table Function in ABAP, including the definition of the function and the implementation of an AMDP method. It details the steps to create a simple ABAP program that selects data from the CDS Table Function and displays the output. The implementation ensures that data retrieval occurs at runtime through the defined methods and classes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

SAP ABAP Guide

ABAP – CDS Table Function


CDS Table Function

Problem Statement: Demonstration of usage of CDS Table Function

1. Create a CDS Table Function as below


Just write a class zamdp_deli and method get_b_qty which will be
implemented in Step 2 (AMDP)
@EndUserText.label: 'CDS Table function'
define table function ZCDS_TBL1
returns {
mandt : abap.clnt;
vbeln : vbeln_va;
posnr : posnr_va;
matnr : matnr;
arktx : arktx; o_qty
: wmeng; d_qty :
wmeng; b_qty :
wmeng;

}
implemented by method zamdp_deli=>get_b_qty;

2. Create AMDP
Use class-METHODS <method> for the table function after the
amdp_marker Implement the Method
CLASS zamdp_deli DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .

PUBLIC SECTION.
INTERFACES : if_amdp_marker_hdb.
class-METHODS get_b_qty for table FUNCTION ZCDS_TBL1.

PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.

CLASS zamdp_deli IMPLEMENTATION.


METHOD get_b_qty BY DATABASE FUNCTION FOR HDB LANGUAGE SQLSCRIPT OPTIONS
READ-ONLY
USING vbap vbak likp lips.
itab1 = select vbak.mandt,
vbak.vbeln,
vbap.posnr,
vbap.matnr,
vbap.arktx, vbap.kwmeng
from vbak as vbak inner join vbap as vbap on
vbak.vbeln = vbap.vbeln;
itab2 = select lips.mandt,
lips.vgbel as vbeln,
lips.vgpos as posnr, sum
( lfimg ) as d_qty
from lips as lips INNER join likp
on lips.mandt = likp.mandt
and lips.vbeln = likp.vbeln INNER
JOIN :itab1
on lips.mandt = :itab1.mandt
and lips.vgbel = :itab1.vbeln
and lips.vgpos = :itab1.posnr
group by lips.mandt, lips.vgbel, lips.vgpos;
return select :itab1.mandt,
:itab1.vbeln,
:itab1.posnr,
:itab1.matnr,
:itab1.arktx,
:itab1.kwmeng as o_qty,
:itab2.d_qty,
( :itab1.kwmeng - :itab2.d_qty ) as b_qty from
:itab1 left OUTER JOIN :itab2
on :itab1.vbeln = :itab2.vbeln and
:itab2.posnr = :itab2.posnr;
ENDMETHOD.
ENDCLASS.

3. Create a simple ABAP Pgm to select from the CDS Table.

*&
*& Report zamdp_cds_tbl_fun_rtp
*&
*&
*&
REPORT zamdp_cds_tbl_fun_rtp.
select * from ZCDS_TBL1 into TABLE @data(gt_so). cl_demo_output=>display( gt_so ).

4. Output
The ABAP pgm uses a select statement to fetch records from CDS Table function.

The AMDP class via the implemented method takes care of creation of rows in the
table.
Everything happens in the run time.

You might also like