Wednesday, October 30, 2013

SAP ABAP how to create a custom conversion exit

Hi Folks,
creating conversion exits is quite simple. I just want to write down the procedure i use in the hope that it helps.

Suppose you have a field "NATSL" you want to create a conversion exit for.

1) Create an empty function group from se80

2) From se37 look up a couple of search exit functions that resemble what you need. In my case i find
CONVERSION_EXIT_GESCH_INPUT and CONVERSION_EXIT_GESCH_OUTPUT

3) Copy them to your function group changing the name to suite your conversion exit name. So you copy
CONVERSION_EXIT_GESCH_INPUT  to CONVERSION_EXIT_NATSL_INPUT and
 CONVERSION_EXIT_GESCH_OUTPUT to CONVERSION_EXIT_NATSL_OUTPUT

4) Adapt the coding ( you find it below). Basically the Input is always the same. The output module ( roughly speaking) receives the"code" and has to look up the "description". In this coding i do a select every time. Don't do this at home: do avoid it by buffering because these conversion exits are called very often.

One remark is that conversion exits have to be in the SAP namespace. you get a warning and you can save it.
If in the future SAP decides to release a conversion exit with the same name as yours the your work will be lost.
At the moment the only " solution " is to use really fancy names (ZZNAT? :-) )

I hope this helps.
Cheers

FUNCTION CONVERSION_EXIT_NATSL_OUTPUT .
*"--------------------------------------------------------------------
*"*"Interfaccia locale:
*"  IMPORTING
*"     VALUE(INPUT)
*"  EXPORTING
*"     VALUE(OUTPUT)
*"  EXCEPTIONS
*"      NOT_FOUND
*"--------------------------------------------------------------------

  output = input.

    data ls_t005t type t005t.
    data lv_land1 type land1.

  if input <> space.
     lv_land1 = input.
     select single * from t005t into ls_t005t
                         where spras = sy-langu AND
                               land1 = lv_land1.

    if sy-subrc <> 0.
      clear output.
    else.
      output = ls_t005t-natio.
    endif.

  endif.


endfunction.


FUNCTION CONVERSION_EXIT_NATSL_INPUT .
*"--------------------------------------------------------------------
*"*"Interfaccia locale:
*"  IMPORTING
*"     VALUE(INPUT)
*"  EXPORTING
*"     VALUE(OUTPUT)
*"--------------------------------------------------------------------

 output = input.

ENDFUNCTION.