CONV ABAP operator in new syntax ABAP for conversion types. CONV ABAP help with task to compare two variables with different types or the need to save a value in a variable of a certain type for further use. Sometimes there is a need to explicitly show the conversion of one field to another in the code. The new construction of the new ABAP syntax will help us with all these tasks.
Examples CONV ABAP for conversion types
I found examples in my ABAP code where I used CONV ABAP.
Get variable inline with new type with CONV ABAP
When you get some variable from method, but you need variable in different type for future using. For example, you need variable cost with correct type from quantity and price:
1 |
DATA(lv_netwr) = CONV netwr( lv_volume * lv_netpr ). |
Or when you need to get data in function module ABAP for search help and conversion to correct to correct type for using
1 2 3 4 |
LOOP AT shlp-selopt REFERENCE INTO lr_selopt. CASE lr_selopt->shlpfield. WHEN 'WERKS'. DATA(lv_werks) = CONV werks_d( lr_selopt->low ). |
Or example when we want create email in ABAP program in SAP.
1 2 3 4 5 6 7 8 9 10 |
"Title DATA(lv_title) = CONV so_obj_des( |{ lv_user } canceled order { lv_order }| ). DATA(lo_mime_helper) = NEW cl_gbt_multirelated_service( ). lo_mime_helper->set_main_html( content = lt_text filename = 'sapwebform.htm' "filename for HMTL form description = lv_title ). ........ |
ABAP conversion CONV without explicit type specification
When you send to method variable with different type, but you don’t want create new temporary variable for conversion type you can use new syntax construction CONV. In this example I show conversion ABAP type MATNR(CHAR 18) which use in SAP ERP and PRODUCT(CHAR54) which use in SAP CRM.
1 2 3 4 5 6 7 8 |
zcl_conv_api=>convert_unit( EXPORTING i_product = CONV #( ls_position-matnr ) i_vrkme = 'ST' i_meinh = 'TO' i_input = lv_input IMPORTING e_output = lv_output ). |
Program ABAP in this case understand type field i_product and conversion value ls_position-matnr to this type.
Or using when you append new row to internal table ABAP with addition add lidding zeros with new ABAP syntax
1 2 3 |
APPEND VALUE #( product_id = CONV #( |{ ls_item-matnr ALPHA = IN }| ) price = lv_netpr count = lv_volume ) TO lt_position. |
Restrictions CONV ABAP
But you cannot use CONV in function modules the same like in methods. If we try to use this code, we didn’t get ABAP error on compellation step but get dump in execution process.
1 2 3 4 5 6 7 8 9 10 |
DATA lv_new_date TYPE datum. DATA(lv_wfcid) = 1. DATA(lv_str) = '20241011'. CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE' EXPORTING date = CONV #( lv_str ) factory_calendar_id = CONV #( lv_wfcid ) IMPORTING date = lv_new_date. |
Because type lv_wfcid not the same with factory_calendar_id

How CONV in new syntax SAP can help with this problem? We can try the same like in method, but get error:

Because program ABAP cannot get type from function module ABAP. But you can use code:
1 2 3 4 5 6 7 8 9 10 |
DATA lv_new_date TYPE datum. DATA(lv_wfcid) = 1. DATA(lv_str) = '20241011'. CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE' EXPORTING date = CONV datum( lv_str ) factory_calendar_id = CONV wfcid( |{ CONV wfcid( lv_wfcid ) ALPHA = IN }| ) IMPORTING date = lv_new_date. |
Not simple for understanding because in my case I also need to add lidding zeros. ( 1 -> 01). But easer code ABAP for understanding:

But in this case not necessary conversion for lv_wfcid as result code:
1 2 3 4 5 6 7 8 9 10 |
DATA lv_new_date TYPE datum. DATA(lv_wfcid) = '01'. DATA(lv_str) = '20241011'. CALL FUNCTION 'DATE_CONVERT_TO_FACTORYDATE' EXPORTING date = CONV datum( lv_str ) factory_calendar_id = lv_wfcid IMPORTING date = lv_new_date. |
I hope I haven’t confused you even more! Write your questions in the comments! I will think about ABAP CONV and add more examples to this article.