Modern ABAP in one sitting
The ABAP 7.4+ syntax, object orientation and ABAP Unit you will meet in every MDG enhancement written in the last ten years.
Why a functional consultant needs to read ABAP
On a technical MDG role you write the rules you used to specify. Most MDG code is small: a validation BAdI is often 40 lines, a derivation 20. What makes it look hard is the modern syntax. MDG enhancements live in the middle two layers below: classes, and the 7.4+ expression syntax.
Which syntax can you use?
NetWeaver 7.40 brought inline declarations; every S/4HANA release runs on 7.50 or later, so on S/4 MDG you can use everything here.
Reading data: one SELECT, step by step
The modern SELECT: commas between fields, @ before every ABAP variable, and @DATA(...) declaring the result table on the spot. Click through the steps.
DATA(lv_since) = CONV d( sy-datum - 365 ).
SELECT partner, bu_group, name_org1, crdat
FROM but000
WHERE type = '2' " 2 = organisation
AND crdat >= @lv_since
ORDER BY crdat DESCENDING
INTO TABLE @DATA(lt_orgs)
UP TO 500 ROWS.
IF sy-subrc <> 0.
RETURN. " nothing found
ENDIF.Try it: write the SELECT
Complete this modern SELECT and count the rows.
SELECT partner, name_org1 FROM but000 WHERE crdat >= INTO TABLE . DATA(lv_count) = ( lt_orgs ).
Classic to modern
Standard SAP is full of the left side. Read both; write the right.
Constructor expressions
They build a value in one statement, like a Data Services transform: rows in, rows out. A table expression such as lt_x[ lifnr = ... ] raises CX_SY_ITAB_LINE_NOT_FOUND when no row matches.
Match each construct to what it does.
Let the database count
A data-quality report (partners per country with an empty postal code) is one SELECT ... GROUP BY joining BUT000, BUT020 and ADRC. Counting in the database beats reading everything and counting in ABAP.
Classes and interfaces
Every MDG BAdI is a class implementing an SAP interface. Think of a class as a function group whose functions share data, and an interface as a published signature many classes can implement. Keep rules in plain classes, such as ZCL_TAX_RULE_DE implementing ZIF_TAX_RULE~IS_VALID, so they can be tested without MDG.
ABAP Unit: test the rule, not the screen
A test class is marked FOR TESTING, lives with the class it tests and never touches production data. Run it with Ctrl+Shift+F10 in ADT (the Eclipse editor; use it for all new code). Ask an AI assistant for tests too, and run them before trusting its code.
CLASS ltc_tax_rule DEFINITION FINAL FOR TESTING
DURATION SHORT RISK LEVEL HARMLESS.
PRIVATE SECTION.
METHODS short_german_id_fails FOR TESTING.
ENDCLASS.
CLASS ltc_tax_rule IMPLEMENTATION.
METHOD short_german_id_fails.
DATA lo_cut TYPE REF TO zif_tax_rule.
lo_cut = NEW zcl_tax_rule_de( ).
cl_abap_unit_assert=>assert_false(
act = lo_cut->is_valid( iv_country = 'DE' iv_tax_number = 'DE1234' )
msg = 'Short German VAT ID must fail' ).
ENDMETHOD.
ENDCLASS.Local Test Classes tab of ZCL_TAX_RULE_DE in ADT.
Try it: a short dump
Your report dumps with CX_SY_ITAB_LINE_NOT_FOUND on the line DATA(ls) = lt_suppliers[ lifnr = lv_lifnr ]. What is the right fix?
Remember
- Modern SELECT: comma-separated fields, @ for ABAP variables, @DATA(...) for an inline target table.
- VALUE, FOR, REDUCE, COND and CORRESPONDING replace most LOOP/APPEND/MOVE code; let the database count.
- BAdIs are classes implementing interfaces; keep rules in plain classes with ABAP Unit tests.