Skip to main content

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!

Comments

Popular posts from this blog

How to Create a REST API in SAP ABAP — Step-by-step Guide

How to Create a REST API in SAP ABAP — Step-by-step Guide Summary: This tutorial shows how to build a REST API in SAP ABAP by creating a handler class, configuring SICF service, registering endpoints with cl_rest_router , implementing endpoint logic (example GET method), and testing the API. Based on an internal implementation reference. Why expose REST APIs from SAP? REST APIs allow SAP systems to integrate with web, mobile, and external services using standard HTTP and JSON payloads. Implementing REST endpoints in ABAP provides secure, reusable, and maintainable integration points for modern applications. Prerequisites Access to an SAP system with authorization to create classes (SE24) and SICF services (SICF). Familiarity with ABAP object-oriented concepts and basic SAP transaction codes. ABAP classes CL_REST_RESOURCE , CL_REST_ROUTER and utilities like /UI2/CL_JSON . High-level overview (4 steps) Create an API handler class (e.g. ZCL_API_HANDLER ). R...

SAP ABAP - User Exit Set Batch Characteristic Value In MIGO Goods Receipt

Customer Exit  :  MBCFC004 ( EXIT_SAPMM07M_004) Set Up Customer Exit for Classification of User-Defined Characteristics You use SAP enhancement MBCFC004 EXIT_SAPMM07M_004, which contains function module exit EXIT_SAPMM07M_004 to classify user-defined characteristics automatically during goods movements in Inventory Management. This is only possible for characteristics which are not assigned values during quality inspection. Requirements 1. The class of the batch to be classified must be known.  This means that a class must be assigned either to the material or at least to one batch of this material. 2. The exit call must be activated for the respective movement type in activity Activate batch classification during goods movements in IM using indicator 'Extended classification' . Open tcode OMC...

IT Asset Management Dengan PHP MySQL

Pada postingan kali saya akan share sebuah aplikasi IT Asset management yang fungsinya untuk memonitoring semua Asset khusus IT, contohnya : Laptop/komputer , Printer, Router, Hardisk, dll. Dalam aplkasi ini kita bisa mengetahui Asset IT posisinya dimana dan digunakan oleh siapa. untuk data-data yang dibutuhkan antara lain : 1. data kategori asset dalam menu ini kita bisa meng-input jenis2 kategory asset : tambah kategori asset : 2. data department 3. data karyawan 4. data department per karyawan 5. data asset location  6. data satuan asset dan untuk transaksi yang ada dalam aplikasi ini adalah,  1. create asset, pada menu create asset ini kita akan mengalokasikan sebuah asset ke karyawan/personnel tampilannya seperti berikut: setelah klik tombol save akan muncul seperti dibawah : untuk melihat detail asset yang sudah dibuat tadi, kita bisa pilih...