Purpose
Add leading zeros to a string if it is numeric, e.g. a customer number

For particular key fields SAP uses the "alpha" conversion exit; it adds leading zeros if the value is numeric, leaving the value unchanged if not.

Solution

GuiXT
//sample value
Set V[kunnr] "A1240"   // or "1240"

if V[kunnr]

  // numeric? then add zeros
  Set V[x] "&V[kunnr]" regex="^\d+$"

  If Q[ok]
    Set V[kunnr](1-10) "0000000000&V[kunnr]" -alignRight
  endif

endif

Explanation: The regular expression passed to regex= consists of the following components:
^ asserts the start of the string.
\d+ matches 1 or more digits (\d is shorthand for any digit, and + specifies that this pattern may occur 1 or more times).
$ asserts the end of the string.

Components
InputAssistant