Monday, 22 September 2025

SAP ABAP CDS View - Batch Characteristic Value

SAP ABAP CDS View - Batch Characteristic Value

SAP ABAP CDS View: Batch Characteristic Value

In modern SAP development, Core Data Services (CDS View) play a vital role in building reusable and optimized data models. This article demonstrates how to create a CDS View to retrieve Batch Characteristic Values from SAP standard tables.

Objective

The purpose of this CDS View is to extract batch characteristic data from standard SAP tables such as INOB, AUSP, CABN, and related tables. The result can be leveraged for reporting, analytics, or Fiori applications.

CDS View Script


@AbapCatalog.sqlViewName: 'ZV_BATCHCHAR'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'CDS View Batch Characteristic Value'
define view ZCDS_BATCH_CHARACTERISTIC as select from inob as a 
inner join ausp as b on a.cuobj = b.objek 
left outer join cabnt as c on c.atinn = b.atinn
left outer join cabn  as f on f.atinn = b.atinn
left outer join cawnt as d on b.atinn = d.atinn and b.atzhl = right(d.atzhl, 3) {
    b.objek as auspObjek,
    a.objek as obj,
    a.obtab,
    b.klart,
    cast(substring(a.objek, 1, 40) as char40 ) as Material,
    cast(substring(a.objek, 41, 50) as char10 ) as Batch,
    b.atinn,
    f.atnam,
    c.atbez,
    b.atzhl,
    b.atwrt,
    d.atwtb,
    b.atflv,
    b.date_from,
    b.dec_value_from
} where a.obtab = 'MCH1' and a.klart = '023' and c.spras = 'E'
    

Sample Output

Below is an example of the result set when running this CDS View in SAP HANA:

Material Batch Characteristic Description Value (Technical) Value (Text) Valid From
MAT-1001 BATCH001 COLOR Batch Color RED Red 2025-01-01
MAT-1001 BATCH001 EXP_DATE Expiration Date 20251231 31-Dec-2025 2025-01-01
MAT-1002 BATCH005 PURITY Purity Level 99.8 99.8 % 2025-02-15

Consuming CDS View in ABAP

To consume the CDS View in an ABAP program, you can use a simple SELECT statement referencing the CDS View entity name:


REPORT ztest_batchchar.

TYPES: BEGIN OF ty_batchchar,
         material     TYPE char40,
         batch        TYPE char10,
         atnam        TYPE char30,
         atbez        TYPE char60,
         atwrt        TYPE char30,
         atwtb        TYPE char60,
         date_from    TYPE dats,
       END OF ty_batchchar.

DATA lt_batchchar TYPE TABLE OF ty_batchchar.
DATA ls_batchchar TYPE ty_batchchar.

SELECT material,
       batch,
       atnam,
       atbez,
       atwrt,
       atwtb,
       date_from
  FROM zcds_batch_characteristic
  INTO TABLE @lt_batchchar
  UP TO 20 ROWS.

LOOP AT lt_batchchar INTO ls_batchchar.
  WRITE: / ls_batchchar-material,
           ls_batchchar-batch,
           ls_batchchar-atnam,
           ls_batchchar-atwrt.
ENDLOOP.
    

Field Explanation

  • Material → extracted from the object key (first 40 characters).
  • Batch → extracted from the object key (characters 41–50).
  • atnam → technical name of the characteristic.
  • atbez → description of the characteristic.
  • atwrt / atwtb → technical and descriptive values of the characteristic.
  • date_from → start of validity period.

Key Benefits

- Simplifies batch characteristic reporting without complex queries.
- Enables seamless integration with SAP Fiori apps and HANA analytics.
- Provides a reusable data model for multiple business scenarios.

Conclusion

This CDS View provides a clean and efficient way to retrieve batch and characteristic information in SAP ABAP. With this approach, reporting and analytics become much easier and faster to implement.

Feel free to adapt this CDS View and ABAP snippet for your own SAP implementation!

No comments:

Post a Comment

Belajar SAP ABAP RAP

  Belajar SAP ABAP RAP: Pengenalan dan Konsep Dasar Restful ABAP Programming Model Kalau kamu seorang ABAPer yang mulai terjun ke dunia SAP...