Conversion Routines are used to convert the values into internal or external format. In most of the cases Conversion Routines are assigned at Domain level. In this tutorial we will see how to create a custom Conversion Routine and use it to format the ALV output using ABAP code.
Let’s say we have a field ‘Creation_Date’ which is of type DATS in our global structure which we are using for ALV field catalog. Now by default this field will pick the users external date format and output the value in the ALV. With the help of Conversion Routine let’s see how can we can alter the output format of this field
Step – 1 Create a function group in custom namespace (Ex. Z_CONVERSION_EXITS)
Step – 2 Create 2 FM’s in this function group as below. Please follow the naming convention CONVERSION_EXIT_*****_INPUT or CONVERSION_EXIT_*****_OUTPUT . You can give any 5 Char name at the place of *’s. Ex. below:
CONVERSION_EXIT_ZDATE_INPUT
CONVERSION_EXIT_ZDATE_OUTPUT
Create 1 input parameter and 1 output in both the FM’s and write the logic as per your requirement.
Here is a sample logic to convert the date into DD/MM/YYYY format.
1 2 3 4 5 6 7 8 9 |
FUNCTION CONVERSION_EXIT_ZDATE_OUTPUT. CLEAR: output. IF input IS NOT INITIAL. CONCATENATE input+6(2) input+4(2) input+0(4) INTO output SEPARATED BY '/'. ENDIF. ENDFUNCTION. |
Now we have our Conversion Exit ZDATE ready.
STEP – 3 Use this exit in ABAP code to format the output.
In the code where we are generating the field catalog, we have to change the property CONVEXIT of the field ‘CREATION_DATE’ as below
1 2 3 4 5 6 |
LOOP AT fieldcat ASSIGNING <fieldcat>. CASE <fieldcat>-fieldname. WHEN 'CREATION_DATE'. <fieldcat>-convexit = 'ZDATE'. ENDCASE. ENDLOOP. |
That’s all. You have successfully created a custom conversion routine used it in your ABAP code to format the ALV output.