0006 - Conversion Exits

Moderators: Snowy, thx4allthefish, Rich, ilya

Post Reply
Rich
Posts: 7116
Joined: Thu Oct 31, 2002 4:47 pm
Location: Liverpool
Contact:

0006 - Conversion Exits

Post by Rich » Thu Mar 26, 2009 11:50 am

Conversion Exits.

What are conversion exits ?? Conversion exits are the method by which SAP uses to normalise the data held in the various tables. As a good example, have a look at material numbers.

If the material number contains all numeric characters (ie the characters 0-9), then SAP prepends leading zeroes onto the string so that 12345 becomes 000000000000012345.

The reason for this is so that the numbers are sorted correctly by the database. If for example you had the numbers 1,2,3,4,5, 10, 200, 1000 as material numbers and asked SAP to sort them by material number you would end up with the sequence: 1,10,1000, 2, 200, 3, 4 and 5. However by prepending zeroes to the material number to bring it to some standard length, then the material numbers will sort in the order that you think they should be.

This also explains why, when you search for a material number, even though the user says it's '1234' and you search the database for '1234' you will not find it. Stick a bunch of zeroes on the front and you will find it!!

As another quick example, have a look at WBS elements. I'll defy you to find a WBS element in the database which has a name the same as you type in to access them. SAP converts these names into six (or is it 8 ??) digit numbers prefixed by zeroes. This is then what is used in the tables to identify each WBS element or project:

So what is a conversion exit ?

A conversion exit consists of two function modules. One module converts incoming data into the representation that will be used internally. The second is a module that converts internally represented data to that which is displayable and user friendly.

Conversion exits are called automatically whenever a variable (who'se domain has a conversion exit defined) is either input via a selection screen or output via a write statement.

How do I find a conversion exit.

Conversion exits are defined at a domain level and therefore apply to all data elements and fields that belong to that domain.

Taking the second example above, a data element for a WBS element is PS_POSNR. If we look at the data element screen for PS_POSNR we can see that the domain is PS_POSNR. Displaying the details for that domain shows us the following screen:

Image

In the field titled 'Convers. Routine', we can see the text 'ABPSP'. The conversion exits for this type of data then are : CONVERSION_EXIT_ABPSP_INPUT (called by Parameter statements etc) and CONVERSION_EXIT_ABPSP_OUTPUT which is for output statements.

Now I've Found It How Do I Use It ?

Conversion exits are used in exactly the same way as functions (well... They are functions). You provide the input parameters and the function then provides the answers:

Code: Select all

*
*          Valid settlement profile ?
*
           Call Function 'CONVERSION_EXIT_ABPSP_INPUT'
                Exporting
                   Input         = w_pspnr_out
                Importing
                   Output        = w_pspnr.
           Read Table t_elements with key pspnr = w_pspnr.
           Select single aprof
                    into w_aprof
                    from cobra
                   where objnr = t_elements-objnr.
For input parameters, as long as you define the parameter as a member to the same domain, the conversion exit input function will be called automatically so that the variable then contains the internal representation of the value.

Likewise, using the WRITE command will also use the correct conversion exit output function if the variable is defined with the correct domain.

How Do I Create my Own Conversion Exits ?

Write your two conversion exits in the same manner that SAP does - with an input and output parameter only.

Make sure that they conform to the naming convention CONVERSION_EXIT_XXXXX_INPUT and CONVERSION_EXIT_XXXXX_OUTPUT.

Activate and test them.

Then, create a domain that reflects the characteristics of the data you are processing, and in the Conversion exit field enter XXXXX.

You then need to define a data type to be able to use this.
Regards

Rich

Image
Abap KC:http://www.richard-harper.me.uk/Kb
SFMDR:http://www.se37.com

Post Reply