6.4Bloom · AnNot started

AMDP write paths

Reading depth

What you'll learn

An AMDP procedure can do set-based DML on HANA — list every table in USING, filter the client yourself, and never put options read-only on a method that writes.

  • AMDP write: `by database procedure for hdb language sqlscript using ...`.
  • Use set-based DML only when it beats an ABAP loop (bulk closes, mass updates).
  • List ALL referenced tables in USING — a missing one errors at first execution.

Sometimes you must write, not just read, on the database side. An AMDP procedure implemented `by database procedure for hdb language sqlscript using ...` can execute DML — UPDATE, INSERT, DELETE — in SQLScript. This is the rare, careful case: use set-based DML only when it genuinely beats an ABAP loop, for example closing tens of thousands of stale orders in one statement instead of one round trip per row.

Two rules keep an AMDP write method safe and analyzable. First, the `using` clause must list *all* referenced database objects — every table the SQLScript reads or writes — because the dependency analyzer relies on it; a missing entry activates fine but errors at first execution. Second, client handling is again explicit: filter `where mandt = :iv_client` yourself since there is no implicit MANDT. The example sets `status = 'CLOSED'` and a timestamp for open orders older than 90 days, then reads the affected count from `::rowcount`.

Note what is and is not present: a write procedure uses `by database procedure` (not `by database function`), and it does *not* carry `options read-only` precisely because it writes. Reserve `options read-only` for read-only methods — putting it on a method that issues DML is contradictory and wrong. Keep these procedures small, well-bounded, and reach for them only when the set-based win is real.

Key points

  • AMDP write: `by database procedure for hdb language sqlscript using ...`.
  • Use set-based DML only when it beats an ABAP loop (bulk closes, mass updates).
  • List ALL referenced tables in USING — a missing one errors at first execution.
  • Handle the client explicitly with `where mandt = :iv_client`; there is no implicit MANDT.
  • `options read-only` is for read-only methods only — never on a procedure that writes.

Examples

BeforeRow-by-row close in ABAP

One database round trip per row — fine for a handful, ruinous for tens of thousands.

ABAPloop at lt_open assigning field-symbol(<o>).
  update zorder_hdr
     set status = 'CLOSED'
   where mandt    = @sy-mandt
     and order_id = @<o>-order_id.
endloop.
AfterSet-based bulk close as an AMDP procedure

One statement closes every qualifying row; using lists the table, the client is filtered explicitly, no read-only because it writes, and ::rowcount returns the count.

ABAPclass zcl_bulk_close definition public.
  public section.
    methods run
      importing iv_client type mandt
      exporting ev_rows   type int4.
endclass.

class zcl_bulk_close implementation.
  method run by database procedure for hdb
            language sqlscript
            using zorder_hdr.
    update zorder_hdr
       set status = 'CLOSED',
           local_last_changed_at = current_utctimestamp
     where mandt = :iv_client
       and status = 'OPEN'
       and order_date < add_days( current_date, -90 );
    ev_rows = ::rowcount;
  endmethod.
endclass.

Source notes: clean-core-curriculum §6.4

Ask Claude

Build a prompt from this lesson + your question and open a fresh Claude chat with it pre-filled — handy for adapting a before/after pattern to your own object.