You are on page 1of 15

Introduction: Conversion takes place when converting the contents of a screen field from display format to SAP-internal format

and vice versa and when outputting with the ABAP statement WRITE, depending on the data type of the field. If standard conversion is not suitable, it can be overridden by specifying a conversion routine in the underlying domain. A conversion routine is identified by its five-place name and is stored as a group of two function modules. The function modules have a fixed naming convention. The following function modules are assigned to conversion routine xxxxx: CONVERSION_EXIT_xxxxx_INPUT CONVERSION_EXIT_xxxxx_OUTPUT The INPUT module performs the conversion from display format to internal format. The OUTPUT module performs the conversion from internal format to display format. If a screen field refers to a domain with a conversion routine, this conversion routine is executed automatically each time an entry is made in this screen field or when values are displayed with this screen field. Let say there is a date field and we want to display the date field 20121203 as 12/2012. Here are the steps how this can be achieved. Steps: 1. Assume that we have created domain for the date field ZCRDAT and we need to assign the custom conversion routine to this particular domain.

2.

Go to the transaction code SE37, enter the function module name CONVERSION_EXIT_ZDATE_INPUT and click create.

3.

Below screen will appear. Enter the function group, short text and click save.

4.

Below screen will appear. Click continue.

5.

Enter the import parameter INPUT.

6.

Go to export tab and enter export parameter OUTPUT as below.

7. 8.

Save and activate the function module. Similarly, create the function module CONVERSION_EXIT_ZDATE_OUTPUT.

9.

Enter the function group, short text and click save.

10. Below pop up will appear.

11. Enter the INPUT import parameter.

12. Enter the OUTPUT export parameter.

13. Now go to the source code tab, enter appropriate code here and activate the function module.

14. Now go to the transaction SE11, enter domain name and click on Change button.

15. Enter the conversion routine ZDATE and activate the domain. 16. If you double click on conversion routine ZDATE, it will present you with two FMs, we created earlier, as below.

Output: Go to the table contents.

Go to Settings->User Parameters.

Check the conversion exits check box, as below.

The table contents would look like:

So this way, we can create custom conversion routine and assign it to the domain.

Write this simple code. REPORT ZFIELDCONV. data: d_auart LIKE vbak-auart. d_auart = 'TA'. WRITE d_auart. What the result output on screen do you expect, "TA"? No, the result will be "OR". The result comes from conversion routine of its domain. In SE11 open table VBAK, find field AUART, double click to go to data element AUART, then double click to open domain AUART. You will see its conversion routine, named AUART. Double click the conversion routine, you got at least two conversion routine conversion routine input & output. They are function module, you can test them in SE37. The INPUT routine performs the conversion from display format to internal format. The OUTPUT routine performs the conversion from internal format to display format. Take attention when we hard code value as a condition value in "WHERE condition", you must convert its value into internal format. Other commonly used conversion routine is ALPHA. It is conversion used to insert leading zero for document number. For example, in sales order (VBAK-VBELN length 10), when we key in order no, for example we key in '4302', conversion routine input will automatically add leading zero, so it will become '0000004302', this is real value stored in table VBAK. On conversion routine output, it will delete leading zero. In SE16, we can view the data wheather in internal format or display format, to toggle format, in display list, go to Setting->User Parameter, in tab strip "Data browser" choose "format, field conversion exit".

Conversion Routines in SAP CONVERSION ROUTINES are also called as CONVERSION EXITS. In some cases SAP displays values differently then they the way they are stored. For example while creating a Sales order the input value for the filed Order Type VBAK-AUART is actually 'OR' that is on the screen. Similarly for Partner functions like Sold-to Party the value is (SP) and for Ship-to Party it is (SH). These are basically the screen values. These values are stored differently internally. This can be easily seen while creating a sales order using a BAPI. If you use the BAPI BAPI_SALESORDER_CREATEFROMDAT1 and try to pass OR for the field VBAK-AUART ie order type or pass SP and SH to Sold-to Party and Ship-to party respectively then you will get an error message. Please note that this happens only when you are trying to pass the values for your code. If you test the BAPI using a transaction SE37 then an automatic conversion takes place and you can pass the screen values. This is basically the CONVERSION ROUTINE. We will now see the way of finding the conversion routines in SAP. Also in some scenarios for custom development you may have to write your own conversion routines. Conversion routines are identified by a five-place name and are stored as a group of two function modules. The function modules have a fixed naming convention. The following function modules are assigned to conversion routine xxxxx:

CONVERSION_EXIT_xxxxx_INPUT CONVERSION_EXIT_xxxxx_OUTPUT

The conversion routine is usually associated with a Domain for that field. So when you enter values on the screen, and save the values the conversion exit is triggered. Similarly, while displaying the values on the screen another conversion routine gets triggered. The conversion routine associated with the domain also triggers when outputting the data on the screen with the WRITE statement. A conversion routine can also be triggered by specifying its five-place name in the attributes of a field in the Screen Painter or with the addition USING EDIT MASK <Name of conversion routine> in the WRITE command in the program. With the USING NO EDIT MASK addition in the WRITE statement, you can skip a conversion routine defined for a domain when outputting.

As mentioned earlier for every field that needs conversion there will be 2 conversion routines. For example for the Partner Function filed KNVP-PARVW there are 2 conversion routines associated with it namely CONVERSION_EXIT_PARVW_INPUT CONVERSION_EXIT_PARVW_OUTPUT One of the ways to find a conversion routine is as follows. Run transaction SE11 give the table name eg. KNVP.

Once the table fields are displayed double click on the filed for which you need to find the conversion exit eg. KNVP-PARVW.

Once the data element is displayed double click on the data-element to display the domain.

You will find the Conversion Exit under output characteristics double click on the conversion exit to display the function modules.

The conversion exit function modules have 2 Parameters one for INPUT and the other for OUTPUT. The INPUT parameter in the INPUT conversion and the OUTPUT parameter in the OUTPUT conversion should not have any reference fields because the value passed in the call could have a different length than that expected. ABAP statements that result in an interruption of processing (such as CALL SCREEN, CALL DIALOG, CALL TRANSACTION, SUBMIT, COMMIT WORK, ROLLBACK WORK, MESSAGE I, MESSAGE W) are not allowed in conversion routines.

You might also like