CONV keyword in sap ABAP
* CONV operator is used to convert a value to specified datatype.
* Previously when we pass values to function module or class methods parameters, the variables which are used to pass the values must have the same data type as that of function module or class methods parameters.
* If the variables don't have the same data type, then we do the type casting by taking the helper variables and pass the helper variables.
* In SAP ABAP new syntax, instead of doing the type casting using helper variables and passing helper variables, we can use CONV operator to covert the value to specified data type.
Old report
REPORT zajay_rp_conv_new.
TYPES: BEGIN OF ty_stu,
st_id(2) TYPE i,
st_name(15) TYPE c,
END OF ty_stu.
DATA: it_stu TYPE TABLE OF ty_stu,
wa_stu TYPE ty_stu.
DATA: lv_file TYPE string.
PARAMETERS: p_file TYPE localfile.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = 'ST_ID'
IMPORTING
file_name = p_file.
lv_file = p_file. " Implicit type casting
START-OF-SELECTION.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = lv_file
has_field_separator = 'X'
TABLES
data_tab = it_stu.
LOOP AT it_stu INTO wa_stu.
WRITE: / wa_stu-st_id UNDER 'Student ID',
wa_stu-st_name UNDER 'Student name'.
ENDLOOP.
New report
REPORT zajay_rp_conv_new.
TYPES: BEGIN OF ty_stu,
st_id(2) TYPE i,
st_name(15) TYPE c,
END OF ty_stu.
DATA: it_stu TYPE TABLE OF ty_stu,
wa_stu TYPE ty_stu.
DATA: lv_file TYPE string.
PARAMETERS: p_file TYPE localfile.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = 'ST_ID'
IMPORTING
file_name = p_file.
* lv_file = p_file. " Implicit type casting
START-OF-SELECTION.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = CONV string( p_file ) "lv_file
has_field_separator = 'X'
TABLES
data_tab = it_stu.
LOOP AT it_stu INTO wa_stu.
WRITE: / wa_stu-st_id UNDER 'Student ID',
wa_stu-st_name UNDER 'Student name'.
ENDLOOP.
File
Input
Output
********************************Thank You*****************************
Comments
Post a Comment