conversion-exit : to overcome the format of a particular value these r used
Eg : if a value of length 10 is stored as 12345 indatabase , and if we give the same in seletion screen sometimes it may not accept , we have to give the leading zeroes also i.e 0000012345 , to overcome that we use conversion exits for that field , there are some Function modules also for this , check in SE37 CONVERSION_EXIT* , u can find some of them
Well, everybody will be aware of the conversion exit functions available in SAP. The SAP provided conversion exit functions must be called individually in the programs to convert the field value internally and externally. Now, why can’t we do this dynamically by avoiding individual calls to the functions?
Create a function module like below:
[abap_code slider="X" title="Generalize Conversion Exit"]
FUNCTION ygeneralize_conversion.
*”———————————————————————-
*”*”Local Interface:
*” IMPORTING
*” REFERENCE(INPUT_VALUE)
*” REFERENCE(INPUT_OUTPUT) TYPE I
*” EXPORTING
*” REFERENCE(OUTPUT_VALUE)
*”———————————————————————-
FIELD-SYMBOLS:TYPE ANY.
DATA:lfd_convexit TYPE funcname,
wf_data TYPE REF TO data.
DATA:lfd_length TYPE i,
lfd_mask TYPE string.
* Determine the mask from the domain
DESCRIBE FIELD input_value OUTPUT-LENGTH lfd_length
EDIT MASK lfd_mask.
IF lfd_mask IS INITIAL.
* This statement is included because its not necessary that all field
* will be having mask associated with it, for example: ATNAM. To get the
* conversion exit of ATNAM the exporting parameter will be holding the
* respective mask
DESCRIBE FIELD output_value OUTPUT-LENGTH lfd_length
EDIT MASK lfd_mask.
IF lfd_mask IS INITIAL.
IF output_value IS INITIAL.
output_value = input_value.
ENDIF.
EXIT.
ENDIF.
ENDIF.
REPLACE ‘==’ IN lfd_mask WITH space.
CONDENSE lfd_mask NO-GAPS.
CREATE DATA wf_data TYPE c LENGTH lfd_length.
IF wf_data IS BOUND.
ASSIGN wf_data->* TO.
IF IS NOT ASSIGNED.
IF output_value IS INITIAL.
output_value = input_value.
ENDIF.
EXIT.
ENDIF.
ELSE.
IF output_value IS INITIAL.
output_value = input_value.
ENDIF.
EXIT.
ENDIF.
IF input_output = 1.
CONCATENATE ‘CONVERSION_EXIT_’ lfd_mask ‘_INPUT’ INTO lfd_convexit.
ELSEIF input_output = 2.
CONCATENATE ‘CONVERSION_EXIT_’ lfd_mask ‘_OUTPUT’ INTO lfd_convexit.
ENDIF.
CALL FUNCTION lfd_convexit
EXPORTING
input = input_value
IMPORTING
output =.
IF sy-subrc NE 0.
output_value = input_value.
ELSE.
output_value =.
ENDIF.
ENDFUNCTION.
[/abap_code]
[abap_code slider="X" title="Generalize Conversion Exit Usage"]
Report YCONVERSION.
DATA:l_atnam TYPE cabn-atnam,
l_ebeln type ekko-ebeln.
PARAMETERS:pa_ebeln TYPE ebeln,
pa_atinn TYPE atinn.
CALL FUNCTION ‘YGENERALIZE_CONVERSION’
EXPORTING
input_value = pa_atinn
input_output = 2
IMPORTING
output_value = l_atnam.
CALL FUNCTION ‘YGENERALIZE_CONVERSION’
EXPORTING
input_value = l_atnam
input_output = 1
IMPORTING
output_value = pa_atinn.
* Check the values in l_atnam , pa_atinn
break-point.
CALL FUNCTION ‘YGENERALIZE_CONVERSION’
EXPORTING
input_value = pa_ebeln
input_output = 2
IMPORTING
output_value = l_ebeln.
CALL FUNCTION ‘YGENERALIZE_CONVERSION’
EXPORTING
input_value = l_ebeln
input_output = 1
IMPORTING
output_value = pa_ebeln.
* Check the values in l_atnam , pa_atinn
break-point.
[/abap_code]
Any comments & suggestions are welcome.
Eg : if a value of length 10 is stored as 12345 in
Well, everybody will be aware of the conversion exit functions available in SAP. The SAP provided conversion exit functions must be called individually in the programs to convert the field value internally and externally. Now, why can’t we do this dynamically by avoiding individual calls to the functions?
Yes, it can be done . Many of you would have come across the statement “DESCRIBE” in ABAP which has an option called “MASK” which provides the conversion routine defined for the field in the ABAP Dictionary. Each conversion routine is linked to two function modules such as “CONVERSION_EXIT_XX_INPUT” and “CONVERSION_EXIT_XX_OUTPUT”,where the ‘XX’ is replaced by the “MASK”. SAP standard code uses the CONCATENATE statement along with the MASK to display the conversion exit functions through transaction SE11 ( available in include LSD11F01 , routine OBJ_GOTO ).
Other than using concatenate statement to build the function module name, the function name can be also be selected from DB view V_FDIR with search pattern FUNCNAME = ‘CONVERSION_EXIT**’.
So using the concatenate statement let’s generalize the call to conversion exits.This idea doesn’t include the range conversion exits functions like CONVERSION_EXIT_MATN1_RANGE_I etc.
[abap_code slider="X" title="Generalize Conversion Exit"]
FUNCTION ygeneralize_conversion.
*”———————————————————————-
*”*”Local Interface:
*” IMPORTING
*” REFERENCE(INPUT_VALUE)
*” REFERENCE(INPUT_OUTPUT) TYPE I
*” EXPORTING
*” REFERENCE(OUTPUT_VALUE)
*”———————————————————————-
FIELD-SYMBOLS:
DATA:lfd_convexit TYPE funcname,
wf_data TYPE REF TO data.
DATA:lfd_length TYPE i,
lfd_mask TYPE string.
* Determine the mask from the domain
DESCRIBE FIELD input_value OUTPUT-LENGTH lfd_length
EDIT MASK lfd_mask.
IF lfd_mask IS INITIAL.
* This statement is included because its not necessary that all field
* will be having mask associated with it, for example: ATNAM. To get the
* conversion exit of ATNAM the exporting parameter will be holding the
* respective mask
DESCRIBE FIELD output_value OUTPUT-LENGTH lfd_length
EDIT MASK lfd_mask.
IF lfd_mask IS INITIAL.
IF output_value IS INITIAL.
output_value = input_value.
ENDIF.
EXIT.
ENDIF.
ENDIF.
REPLACE ‘==’ IN lfd_mask WITH space.
CONDENSE lfd_mask NO-GAPS.
CREATE DATA wf_data TYPE c LENGTH lfd_length.
IF wf_data IS BOUND.
ASSIGN wf_data->* TO
IF IS NOT ASSIGNED.
IF output_value IS INITIAL.
output_value = input_value.
ENDIF.
EXIT.
ENDIF.
ELSE.
IF output_value IS INITIAL.
output_value = input_value.
ENDIF.
EXIT.
ENDIF.
IF input_output = 1.
CONCATENATE ‘CONVERSION_EXIT_’ lfd_mask ‘_INPUT’ INTO lfd_convexit.
ELSEIF input_output = 2.
CONCATENATE ‘CONVERSION_EXIT_’ lfd_mask ‘_OUTPUT’ INTO lfd_convexit.
ENDIF.
CALL FUNCTION lfd_convexit
EXPORTING
input = input_value
IMPORTING
output =
IF sy-subrc NE 0.
output_value = input_value.
ELSE.
output_value =
ENDIF.
ENDFUNCTION.
[/abap_code]
Generalize Conversion Exit Usage
Now, try calling this function from a program like below:[abap_code slider="X" title="Generalize Conversion Exit Usage"]
Report YCONVERSION.
DATA:l_atnam TYPE cabn-atnam,
l_ebeln type ekko-ebeln.
PARAMETERS:pa_ebeln TYPE ebeln,
pa_atinn TYPE atinn.
CALL FUNCTION ‘YGENERALIZE_CONVERSION’
EXPORTING
input_value = pa_atinn
input_output = 2
IMPORTING
output_value = l_atnam.
CALL FUNCTION ‘YGENERALIZE_CONVERSION’
EXPORTING
input_value = l_atnam
input_output = 1
IMPORTING
output_value = pa_atinn.
* Check the values in l_atnam , pa_atinn
break-point.
CALL FUNCTION ‘YGENERALIZE_CONVERSION’
EXPORTING
input_value = pa_ebeln
input_output = 2
IMPORTING
output_value = l_ebeln.
CALL FUNCTION ‘YGENERALIZE_CONVERSION’
EXPORTING
input_value = l_ebeln
input_output = 1
IMPORTING
output_value = pa_ebeln.
* Check the values in l_atnam , pa_atinn
break-point.
[/abap_code]
Any comments & suggestions are welcome.
No comments:
Post a Comment