Monday, 22 September 2025

Belajar ABAP Part 1: Pengenalan ABAP untuk Pemula

Belajar ABAP Part 1: Pengenalan ABAP untuk Pemula

Belajar ABAP Part 1: Pengenalan ABAP untuk Pemula

Selamat datang di seri Belajar ABAP dari Basic sampai Advance. Pada bagian pertama ini, kita akan membahas pengenalan dasar ABAP, sejarah singkat, dan menulis program pertama di SAP menggunakan ABAP.

Apa itu ABAP?

ABAP (Advanced Business Application Programming) adalah bahasa pemrograman yang digunakan untuk mengembangkan aplikasi pada sistem SAP. ABAP mendukung pemrograman prosedural maupun object-oriented, sehingga fleksibel digunakan untuk berbagai kebutuhan bisnis.

Sejarah Singkat ABAP

ABAP pertama kali dikembangkan oleh SAP pada tahun 1980-an untuk mendukung pembuatan laporan dan program aplikasi bisnis. Hingga saat ini, ABAP masih menjadi salah satu pilar utama dalam SAP ERP maupun SAP S/4HANA.

Kenapa Belajar ABAP?

  • Digunakan secara luas di perusahaan besar yang menggunakan SAP.
  • Mudah dipelajari bagi pemula yang sudah familiar dengan bahasa pemrograman dasar.
  • Banyak peluang karir di bidang SAP Development.
  • Mendukung integrasi dengan teknologi modern (CDS View, OData, HANA, dsb).

Tools yang Dibutuhkan

Untuk mulai belajar ABAP, ada dua tools utama yang biasanya digunakan:

  1. SAP GUI: digunakan untuk akses langsung ke sistem SAP.
  2. Eclipse dengan ABAP Development Tools (ADT): IDE modern untuk coding ABAP.

Program Pertama: Hello World

Sebagai latihan pertama, mari kita buat program sederhana di ABAP:


REPORT zhello_world.

WRITE: 'Hello, ABAP World!'.

Program di atas akan menampilkan teks sederhana Hello, ABAP World! ke layar SAP. Mudah kan? 😊

Kesimpulan

Pada artikel pertama ini, kita sudah mengenal dasar apa itu ABAP, sejarah singkatnya, alasan kenapa belajar ABAP penting, tools yang dibutuhkan, dan membuat program pertama. Di seri berikutnya, kita akan membahas lebih detail tentang dasar-dasar pemrograman ABAP seperti variabel, tipe data, dan perintah dasar.

👉 Lanjut ke: Belajar ABAP Part 2: Dasar-Dasar Pemrograman ABAP

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!

SAP Issue Unapproved Requisition could be converted to Purchase Order

Purchase Requisitions that have not been released/approved can be continued to become Purchase Order. If they have not been released/approved, they cannot be made into Purchase Order. 



If you found this Issue in your SAP S4 System try to implement this SAP Note
https://me.sap.com/notes/3300350/E

Friday, 19 September 2025

Showing Field Invoice Receipt Date in SAP MIR7/MIRO Transaction

Invoice Receipt Date in SAP MIR7 Transaction



First step Maintain Table IDFIVATV_DEF using SM30 and Edit

Add new entries if your company code not maintained yet in this table.

Next step double click on company code and tick Receipt Date Active 



Last step is Save and Open MIR7 Transaction



Thursday, 18 September 2025

Add Custom Fields AR01 Transaction Code in SAP ABAP

Add Custom File to Tcode AR01 in SAP ABAP

Add Custom File to Tcode AR01 in SAP ABAP

A step-by-step guide to extend AR01 functionality with custom fields and logic in SAP ABAP.

Introduction

In this tutorial, we will explore how to add a custom file in tcode AR01 by enhancing the program RABEST_ALV01. The approach involves using the main structure FIAA_SALVTAB_RABEST and the include structure CI_REPRABEST.

Main Structure and Include

  • Main Structure: FIAA_SALVTAB_RABEST
  • Include Structure: CI_REPRABEST

Custom Code Implementation

Below is the ABAP code snippet inserted into the program RABEST_ALV01 to fetch additional information such as cost center, profit center, asset class description, and long text:


FIELD-SYMBOLS: <ANLN1> TYPE ANY.
FIELD-SYMBOLS: <ANLKL> TYPE ANY.
FIELD-SYMBOLS: <KOSTL> TYPE ANY.
FIELD-SYMBOLS: <PRCTR> TYPE ANY.
FIELD-SYMBOLS: <LTEXT> TYPE ANY.
FIELD-SYMBOLS: <TXK50> TYPE ANY.

LOOP AT <itab_data>[] ASSIGNING FIELD-SYMBOL(<fs_csfield>).

  ASSIGN COMPONENT 'KOSTL' OF STRUCTURE <fs_csfield> TO <KOSTL>.
  ASSIGN COMPONENT 'PRCTR' OF STRUCTURE <fs_csfield> TO <PRCTR>.
  ASSIGN COMPONENT 'ANLKL' OF STRUCTURE <fs_csfield> TO <ANLKL>.
  ASSIGN COMPONENT 'TXK50' OF STRUCTURE <fs_csfield> TO <TXK50>.
  ASSIGN COMPONENT 'LTEXT' OF STRUCTURE <fs_csfield> TO <LTEXT>.

  SELECT SINGLE PRCTR FROM CSKS
    INTO <PRCTR> WHERE KOSTL = <KOSTL>.

  SELECT SINGLE LTEXT FROM CEPCT
    INTO <LTEXT> WHERE PRCTR = <PRCTR> AND SPRAS = sy-langu.

  SELECT SINGLE TXK50 FROM ANKT
    INTO <TXK50> WHERE SPRAS = sy-langu AND ANLKL = <ANLKL>.

ENDLOOP.
      

Conclusion

By adding the above logic into RABEST_ALV01, you can extend the AR01 report to include additional information like cost center descriptions, profit center texts, and asset class details. This approach provides flexibility for financial reporting in SAP.

Wednesday, 17 September 2025

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)

  1. Create an API handler class (e.g. ZCL_API_HANDLER).
  2. Register endpoint templates using cl_rest_router.
  3. Create and activate an SICF service (e.g. /sap/bc/zapi01).
  4. Implement endpoint logic in endpoint classes and test the API.

Step 1 — Create the API handler class

Create class ZCL_API_HANDLER in SE24, implement CL_REST_HTTP_HANDLER, and register endpoints.


DATA(lo_router) = NEW cl_rest_router( ).
lo_router->attach(
  EXPORTING
    iv_template      = '/ZFLIGHTLIST'
    iv_handler_class = 'ZCL_FLIGHT01' ).
ro_root_handler = lo_router.

Step 2 — Create and configure the SICF service

In SICF, create a new service node (e.g. ZAPI01) and attach your handler class ZCL_API_HANDLER. Activate the service.

Step 3 — Create endpoint class

Make class ZCL_FLIGHT01 inheriting from CL_REST_RESOURCE. Redefine GET/POST methods.


METHOD if_rest_resource~get.
  " Parse JSON request
  DATA(lo_entity) = mo_request->get_entity( ).
  DATA(lv_data)   = lo_entity->get_string_data( ).
  DATA: ls_params TYPE ty_flight.

  /ui2/cl_json=>deserialize( json = lv_data changing data = ls_params ).

  " Read SFLIGHT
  IF ls_params IS NOT INITIAL.
    SELECT * FROM sflight INTO TABLE @DATA(lt_flight)
      WHERE carrid = @ls_params-carrid
        AND connid = @ls_params-connid.
  ELSE.
    SELECT * FROM sflight INTO TABLE @lt_flight.
  ENDIF.

  " Build JSON response
  IF lt_flight IS NOT INITIAL.
    /ui2/cl_json=>serialize( data = lt_flight RECEIVING r_json = lv_result ).
    lv_result = '{"Status":"OK","Message":"SUCCESS","Data":' && lv_result && '}'.
  ELSE.
    lv_result = '{"Status":"ERROR","Message":"DATA NOT FOUND"}'.
  ENDIF.

  lo_response->set_string_data( iv_data = lv_result ).
  lo_response->set_header_field(
    EXPORTING iv_name = 'CONTENT-TYPE'
              iv_value = 'APPLICATION/JSON' ).
ENDMETHOD.

Step 4 — Test the API

Test with Postman or cURL. Example:


curl -u username:password -X GET "https://your-sap-host/sap/bc/zapi01/ZFLIGHTLIST" \
-H "Content-Type: application/json" \
-d '{"carrid":"AA","connid":"0017"}'

Security & Best Practices

  • Always use HTTPS and proper authentication.
  • Validate and sanitize inputs.
  • Return correct HTTP status codes.
  • Use pagination for large datasets.
  • Log requests and errors responsibly.

FAQ

Where do I register endpoints?

Inside cl_rest_router in the handler class.

Which transaction creates the web service?

SICF is used to create and activate the service node.

Which ABAP class handles JSON?

/UI2/CL_JSON is commonly used for JSON serialization and deserialization.

Tuesday, 16 September 2025

Custom Agent Determination in SAP Flexible Workflow for Supplier Invoice Approval

Custom Agent Determination in SAP Flexible Workflow for Supplier Invoice Approval

Custom Agent Determination in SAP Flexible Workflow for Supplier Invoice Approval

In SAP MM, supplier invoice approval is often handled using the Flexible Workflow. However, standard configuration may not fully cover complex approval requirements. In such cases, Custom Agent Determination can be implemented using BAdI MRM_WORKFLOW_AGENTS.

This blog explains how to implement a custom approval workflow for supplier invoices (MIR7), including creating custom tables, CDS views, Fiori custom logic, and defining workflow conditions.

1. Create Custom Tables

Two custom tables are required:

a. Table for Mapping User Approval

Table: ZMMT007 (Supplier Invoice Approval Agent Assignment)

  • FUNCTION – Function key
  • FUNDESC – Function description
  • APP_LVL – Approval level
  • BUS_USR – Business user

b. Table for Mapping Condition Approval

Table: ZMMT008 (Invoice Release Strategy)

  • ZREL_GROUP – Release group
  • ZREL_STRAT – Release strategy
  • ZFUNCTION – Function
  • ZSIGN – Comparison sign
  • ZCURR – Currency
  • ZAMOUNT – Amount threshold

2. Create Custom CDS Views

CDS views are required for retrieving approval mapping data. Example definitions:

@AbapCatalog.sqlViewName: 'ZIWFINVOICE'
define view ZI_SUPP_INV_WF as select from zmmt007 {
  key function as Function,
  fundesc as FuncDesc,
  app_lvl as AppLvl,
  bus_usr as BusUser
}
      
@AbapCatalog.sqlViewName: 'ZIWFINVOICEREL'
define view ZI_SUPP_INV_REL_MAP as select from zmmt008 {
  key zrel_group,
  key zrel_strat,
  zfunction,
  zsign,
  zcurr,
  zamount
}
      

Make sure to release CDS Views for usage in custom logic by setting the API State to Use System-Internally (Contract C1).

3. Implement Custom Logic in Fiori

Navigate to Custom Logic app in Fiori and create a new implementation:

  • Business Context: Procurement: Flexible Workflow
  • BAdI: Determination of Workflow Agents for Supplier Invoice
  • Implementation ID: BADI MRM_WORKFLOW_AGENTS

Sample ABAP snippet for custom agent selection:

DATA: lt_wf TYPE TABLE OF ZI_SUPP_INV_WF,
      lt_wf_rel TYPE TABLE OF zi_supp_inv_rel_map,
      ls_wf_relx TYPE zi_supp_inv_rel_map.

SELECT * FROM I_SupplierInvoiceAPI01
  WHERE SupplierInvoice = @supplierinvoice
    AND FiscalYear = @FiscalYear
  INTO TABLE @DATA(lt_SupplierInv).

IF ls_invoice-companycode = 'JSB'
   AND ls_invoice-ACCOUNTINGDOCUMENTTYPE = 'RE'
   AND ls_invoice-INVOICEGROSSAMOUNT >= 1.

  SELECT * FROM zi_supp_inv_rel_map
    WHERE zrel_group = 'WPO-GEN-WF'
      AND zrel_strat = 'ALL'
    INTO TABLE @lt_wf_rel.

ENDIF.
      

In the Filter tab, set the filter: workflowscenario = WS00800303.

4. Define Flexible Workflow Conditions

In the Fiori app Manage Workflows for Supplier Invoices, configure the workflows according to business rules. For example:

a. Invoice With PO

  • Company code = JSB
  • Invoice is based on PO
  • Steps: Level-1 and Level-2 Agent Determination via BAdI

b. Invoice Without PO < 10 Million

  • Company code = JSB
  • Amount < 10,000,000 IDR
  • Steps: Level-1, Level-2, Level-3 Agent Determination

c. Invoice Without PO ≥ 10 Million

  • Company code = JSB
  • Amount ≥ 10,000,000 IDR
  • Steps: Level-1 to Level-4 Agent Determination

Conclusion

By combining custom tables, CDS views, and Fiori custom logic, businesses can implement robust and flexible approval workflows for supplier invoices in SAP. This approach ensures compliance, supports complex approval hierarchies, and automates the agent determination process.

👉 If you’re also interested in other SAP MM workflow enhancements, check out our related article on SAP Invoice Splitting.

ABAP CDS View Part 10 : Authorization & DCL untuk ABAP CDS

Authorization & DCL di ABAP CDS | Panduan Lengkap (PFCG, @AccessControl, DCL) Authorization & DCL untuk ABAP CDS — Pandua...