Workik.

SAP S/4HANA Custom Code Migration: An ABAP Developer's Guide

S/4HANA Data Model Changes: MATNR, KONV, VBUK and MATDOC

Refactor legacy code for S/4HANA data model changes including MATNR 40-character length, PRCD_ELEMENTS, VBAK status fields, and MATDOC tables.

SAP ECC stored operational data across hundreds of specialized tables, status tables, and index tables. SAP S/4HANA consolidates these structures into unified line-item tables while eliminating redundant aggregates. For an ABAP developer, these architectural updates represent the core of custom code remediation.

Previous lesson: Fixing Common S/4HANA Custom Code Findings | Next lesson: ABAP on SAP HANA: Sorting, Database Hints and Code Pushdown


Material Number Extension: Handling 40 Characters

In SAP ECC, the material number field MATNR had an output length of 18 characters. SAP S/4HANA extends this field length to 40 characters as documented in SAP Note 2215424. If your custom programs use hardcoded character lengths, string offsets, or fixed-width interfaces, they will truncate values or trigger ABAP runtime errors.

At Harbor Supply Co., the report ZMM_STOCK_MOVES defines local variables using fixed lengths instead of dictionary types.

Before (ECC):

abap
Copy

After (S/4HANA):

abap
Copy

Common Mistake: Replacing TYPE c LENGTH 18 with TYPE c LENGTH 40. Never hardcode primitive types for dictionary concepts. Always reference the standard data element matnr so changes in domain properties remain synchronized.


Pricing Conditions: Moving from KONV to PRCD_ELEMENTS

In SAP ECC, document pricing results were stored in the cluster table KONV. SAP S/4HANA replaces KONV with the transparent database table PRCD_ELEMENTS.

Direct reads on KONV in custom programs like ZSD_PRICE_EXPORT must be pointed to PRCD_ELEMENTS. While field names largely match, you must confirm each field against PRCD_ELEMENTS in your target system.

Before (ECC):

abap
Copy

After (S/4HANA):

abap
Copy

Pro Tip: Check calculation field types when migrating KONV selects. Compare the data elements of each selected field in PRCD_ELEMENTS with the local variables in your calling code, and adjust any variable that no longer matches.


Sales Status Consolidation: Eliminating VBUK and VBUP

In classic ERP, sales document header and item statuses lived separately in VBUK and VBUP. In SAP S/4HANA, these redundant header and item status tables are eliminated. Status fields now reside directly within the operational document tables: VBAK for sales order headers, VBAP for items, LIKP and LIPS for deliveries, and VBRK for billing documents.

Harbor Supply Co. runs ZSD_ORDER_STATUS to display overall processing states. The old program reads the header status from VBUK. In S/4HANA, the status field GBSTK sits directly on VBAK.

Before (ECC):

abap
Copy

After (S/4HANA):

abap
Copy

For sales document line-item status, query VBAP directly instead of reading VBUP.


Inventory Management: MATDOC Replaces MKPF and MSEG

Classic inventory management relied on MKPF for document headers, MSEG for line items, and aggregate tables like MARC, MARD, and MBEW for period stocks. SAP S/4HANA unifies goods movements into a single, high-speed line-item table named MATDOC.

SAP provides compatibility views for MKPF and MSEG. Your existing SELECT statements will still return data through these views, but with important constraints:

  • Writes (INSERT, UPDATE, DELETE) against MKPF and MSEG will fail.
  • Reads through the compatibility views can be slower than direct reads on MATDOC in heavy custom reporting.

To modernize ZMM_STOCK_MOVES, replace old joins on MKPF and MSEG with direct queries against MATDOC.

Before (ECC):

abap
Copy

After (S/4HANA):

abap
Copy

Financials and Master Data: ACDOCA and the Business Partner

Two other foundational data model changes influence custom ABAP remediation:

The Universal Journal (ACDOCA)

SAP S/4HANA merges General Ledger, Asset Accounting, Controlling, and Material Ledger line items into the universal journal table, ACDOCA. Legacy totals tables such as GLT0, KNC1, and LFC1, along with line-item tables like BSIS, BSAS, BSID, and BSIK, are replaced by compatibility views. Read operations continue to function via compatibility views, but custom programs that insert or update legacy financial tables must be redesigned to use standard posting interfaces.

Business Partner and Customer Vendor Integration (CVI)

In SAP S/4HANA, customer and vendor master records can no longer be created independently. All counterparties are maintained as Business Partners using transaction BP. Customer Vendor Integration (CVI) synchronizes the business partner master with the underlying KNA1 and LFA1 tables. Existing custom programs that read KNA1 or LFA1 continue to work, but programs that create or update records must use the Business Partner APIs rather than updating tables directly.


Try It Yourself

Identify and remediate an obsolete status read using modern ABAP syntax.

  1. Open your ABAP Development Tools (ADT) workspace.
  2. Locate a legacy report that queries table VBUK or VBUP.
  3. Replace the query with a direct read from VBAK for header status (field gbstk) or from VBAP for item status (field gbsta).
  4. Ensure your target variables use modern inline declarations (@DATA(...)) and host variable syntax (@).
  5. Run the ABAP Test Cockpit with check variant S4HANA_READINESS to confirm that all findings for VBUK are resolved.

In the next lesson, ABAP on SAP HANA: Sorting, Database Hints and Code Pushdown, you will address runtime behavioral changes on SAP HANA, fix implicit sorting dependencies, and implement code pushdown.

Was this lesson helpful?