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(15TYPE c,
       END OF ty_stu.
DATA: it_stu TYPE TABLE OF ty_stu,
      wa_stu TYPE ty_stu.
DATAlv_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(15TYPE c,
       END OF ty_stu.
DATA: it_stu TYPE TABLE OF ty_stu,
      wa_stu TYPE ty_stu.
DATAlv_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 stringp_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

Popular posts from this blog

New syntax for append- VALUE (new syntax 7.4+) in ABAP

Read statement new syntax in ABAP. (7.4+).

Concatenation new syntax( 7.4+ ).