Monday, 22 September 2025

Belajar ABAP Part 2: Dasar-Dasar Pemrograman ABAP

Belajar ABAP Part 2: Dasar-Dasar Pemrograman ABAP

Belajar ABAP Part 2: Dasar-Dasar Pemrograman ABAP

Setelah pada Part 1: Pengenalan ABAP kita mengenal apa itu ABAP dan membuat program pertama, sekarang kita akan masuk lebih dalam ke dasar pemrograman ABAP. Materi ini meliputi:

  • Deklarasi variabel
  • Tipe data di ABAP
  • Penggunaan WRITE statement

Deklarasi Variabel

Variabel digunakan untuk menyimpan data. Di ABAP, variabel biasanya dideklarasikan menggunakan keyword DATA.


REPORT zvariable_example.

DATA: gv_name TYPE string,
      gv_age  TYPE i.

gv_name = 'Andi'.
gv_age  = 25.

WRITE: / 'Nama :', gv_name,
       / 'Umur :', gv_age.

Pada contoh di atas:

  • gv_name adalah variabel bertipe string.
  • gv_age adalah variabel integer (bilangan bulat).
  • Keyword WRITE digunakan untuk menampilkan output.

Tipe Data di ABAP

ABAP memiliki berbagai tipe data yang bisa digunakan. Berikut beberapa tipe dasar:

Tipe Data Keterangan Contoh
C (Character) Teks dengan panjang tetap DATA gv_text TYPE c LENGTH 10.
N (Numeric) Angka dalam bentuk teks DATA gv_num TYPE n LENGTH 5.
I (Integer) Bilangan bulat DATA gv_int TYPE i.
D (Date) Tanggal (YYYYMMDD) DATA gv_date TYPE d.
F (Float) Bilangan desimal DATA gv_float TYPE f.
STRING Teks dengan panjang dinamis DATA gv_string TYPE string.

WRITE Statement

Perintah WRITE digunakan untuk menampilkan data ke layar. Contoh sederhana:


REPORT zwrite_example.

DATA gv_total TYPE i.

gv_total = 100 + 50.

WRITE: 'Total nilai adalah:', gv_total.

Output yang muncul di layar SAP adalah:

Total nilai adalah: 150

Kesimpulan

Di Part 2 ini kita sudah mempelajari dasar penting dalam ABAP yaitu cara mendeklarasikan variabel, mengenal tipe data, dan menampilkan data dengan WRITE. Pemahaman ini sangat penting karena akan menjadi dasar untuk materi berikutnya.

👉 Lanjut ke: Belajar ABAP Part 3: Control Statements (IF, CASE, LOOP)

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.

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...