![]() |
Powered by QM on a Rpi server |
|
KnowledgeBase 00048: User Written Conversion CodesThis article was originally published as a Tip of the Week. QM provides the ability for developers to add new conversion codes that can then be used in all situations where the standard built-in codes can be used. The Conversion SubroutineA user written conversion code is a subroutine declared as SUBROUTINE NAME(RESULT, SRC, STATE, IS.OCONV)where
The subroutine must be catalogued in a mode that makes it available to all accounts in which it is to be used. ExampleThe example below is a base 36 encoding where a non-negative numeric value is encoded to a series of alphanumeric characters in the minimum possible space. subroutine b36(result, (src), state, is.oconv) $catalogue b36 global if is.oconv then result = '' if src matches '1N0N' then loop result = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'[rem(src, 36)+1, 1] : result src = idiv(src, 36) while src repeat state = 0 end else state = 1 end end else result = 0 for i = 1 to len(src) j = index('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ', upcase(src[i,1]), 1) - 1 if j < 0 then state = 1 result = '' return end result = result * 36 + j next i state = 0 end return end Using the New CodeThe user written conversion code can be used in all places where a built-in code can be used. The conversion name is the same as the catalogue name of the conversion subroutine with a U prefix added. For example, the base 36 encoding shown above could be used as ENCODED.CLIENT.NO = OCONV(CLIENT.NO, "UB36") Related ArticlesNone. |