Commented Example Program
Use
The commented source code below demonstrates the application of the virus scan interface for scanning files that are uploaded from a workstation.
The output of the result is performed in the simplest way. The report RSVSCANTEST contained in the system performs this task in an appropriate form and can also be used as a demonstration object.
************************************************************************ * Minimal demo report for Virus Scan Interface. * For a functionally more complete example see report RSVSCANTEST. ************************************************************************ REPORT zvscandemo. ************************************************************************ * Selection screen PARAMETERS: profile TYPE vscan_prof-profile, file TYPE localfile. ************************************************************************ * Events ************************************************************************ AT SELECTION-SCREEN ON VALUE-REQUEST FOR file. PERFORM file_f4. START-OF-SELECTION. PERFORM main. ************************************************************************ * Main program ************************************************************************ FORM main. IF file IS INITIAL. MESSAGE s058(vscan) DISPLAY LIKE 'E'. EXIT. " =================== EXIT ===================== ENDIF. * Access file and create XSTRING TYPES: ty_xline(1024) TYPE x. DATA: lf_file TYPE string, lf_filelength TYPE i, lt_datatab TYPE STANDARD TABLE OF ty_xline. lf_file = file. CALL METHOD cl_gui_frontend_services=>gui_upload EXPORTING filename = lf_file filetype = 'BIN' IMPORTING filelength = lf_filelength CHANGING data_tab = lt_datatab EXCEPTIONS OTHERS = 1. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno DISPLAY LIKE 'E' WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. EXIT. " =================== EXIT ===================== ENDIF. * Recombine binary data DATA: lf_tabline TYPE ty_xline, lf_data TYPE xstring. LOOP AT lt_datatab INTO lf_tabline. CONCATENATE lf_data lf_tabline INTO lf_data IN BYTE MODE. ENDLOOP. lf_data = lf_data(lf_filelength). * Get scanner instance DATA: lo_vsi TYPE REF TO cl_vsi. CALL METHOD cl_vsi=>get_instance EXPORTING if_profile = profile IMPORTING eo_instance = lo_vsi EXCEPTIONS configuration_error = 1 profile_not_active = 2 internal_error = 3 OTHERS = 4. CASE sy-subrc. * No error. WHEN 0. " Nothing to do * Profile not active. For this report, this is an information message. WHEN 2. MESSAGE ID sy-msgid TYPE 'I' NUMBER sy-msgno DISPLAY LIKE 'I' WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. EXIT. " =================== EXIT ===================== * All other exceptions are issued as errors. WHEN OTHERS. MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno DISPLAY LIKE 'E' WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. EXIT. " =================== EXIT ===================== ENDCASE. * Perform virus scan DATA: lf_scanrc TYPE vscan_scanrc. CALL METHOD lo_vsi->scan_bytes EXPORTING if_data = lf_data IMPORTING ef_scanrc = lf_scanrc EXCEPTIONS not_available = 1 configuration_error = 2 internal_error = 3 OTHERS = 4. * All exceptions here are errors IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno DISPLAY LIKE 'E' WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. EXIT. " =================== EXIT ===================== ENDIF. * Print return code and text DATA: lf_text TYPE string. lf_text = cl_vsi=>get_scanrc_text( lf_scanrc ). WRITE: / 'Result of virus scan: ', lf_scanrc, '(', lf_text, ')'. IF lf_scanrc = cl_vsi=>con_scanrc_ok. WRITE: / 'File is clean'. ELSE. WRITE: / 'File was either infected', 'or could not be scanned', 'or was ignored'. 'Or another problem occurred'. ENDIF. ENDFORM. ************************************************************************ * F4-help for filename ************************************************************************ FORM file_f4. DATA: lt_filetable TYPE filetable, lf_rc TYPE i. CALL METHOD cl_gui_frontend_services=>file_open_dialog EXPORTING multiselection = abap_false CHANGING file_table = lt_filetable rc = lf_rc EXCEPTIONS file_open_dialog_failed = 1 cntl_error = 2 error_no_gui = 3 not_supported_by_gui = 4 OTHERS = 5. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE 'S' NUMBER sy-msgno DISPLAY LIKE 'E' WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. EXIT. ENDIF. * Number of selected filed must be equal to one. CHECK lf_rc = 1. * Access selected file DATA: ls_file TYPE file_table. READ TABLE lt_filetable INTO ls_file INDEX 1. CHECK sy-subrc = 0. file = ls_file-filename. ENDFORM.