Tuesday, March 17, 2009

Substitutions: accessing values that should be out of scope

A lot of dodgy code has been written to get at required data which is not visible in user exits and substitutions. A common strategy is to EXPORT the desired value to memory in one exit, and IMPORT from memory in another. Such code is hard to write reliably, and even harder to maintain.

The trick illustrated below provides direct access to any data in any program in the global memory of a session. It is clean, reliable and easy to maintain. Go wild.


*&-----------------------------------*
*& Form u113
*&-----------------------------------*
** Customer number into assignment field
** Peter Chapman - March 2009 - Final
*------------------------------------*
FORM u113.

FIELD-SYMBOLS: <k> TYPE kunnr.

DATA:
lv_kunnr_field TYPE fieldname VALUE '(SAPMF05A)KNA1-KUNNR'.

ASSIGN (lv_kunnr_field) TO <k>.

bseg-zuonr = <k>.

ENDFORM.

No comments: