SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Время выполнения заданного программного кода.



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Performance tuning | Производительность
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Wed Sep 05, 2007 1:01 pm    Post subject: Время выполнения заданного программного кода. Reply with quote

Author: Narendran Muthukumaran

Description
This is a program to get the run time for the given code in the selection screen. In the selection screen you can press the "Check syntax" button to do the syntax check of the code before running to get the run time.

Code:
REPORT z_run_time_analysis.

* Data declarations.
TABLES: sscrfields.
DATA: t_code    TYPE STANDARD TABLE OF char72.
DATA: v_line    TYPE i.
DATA: s_message TYPE trmsg.
DATA: v_word    TYPE char72.
DATA: v_report  TYPE syrepid VALUE 'Z_TEST_REPORT_11'.
DATA: v_time1   TYPE i.
DATA: v_time2   TYPE i.
DATA: v_repid   TYPE syrepid.

* Container and editor.
DATA: x_docking TYPE REF TO cl_gui_docking_container,
      x_editor  TYPE REF TO cl_gui_textedit.

* Selection screen.
PARAMETERS:report(72) DEFAULT 'REPORT z_test_report_11.'.
SELECTION-SCREEN SKIP 2.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(60) v_text.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN SKIP 2.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(60) v_text1.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(60) v_text2.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN FUNCTION KEY 1.

INITIALIZATION.
* Set the report name.
  v_repid = sy-repid.
  v_text  = 'Report Z_TEST_REPORT_11 will be generated'.
  v_text1 = 'This is a small utility program to get the run time'.
  v_text2 = 'for the given code'.
  sscrfields-functxt_01 = 'Check syntax'.


AT SELECTION-SCREEN OUTPUT.

* Disable the report line
  LOOP AT SCREEN.
    IF screen-name = 'REPORT'.
      screen-input = 0.
      MODIFY SCREEN.
    ENDIF.
  ENDLOOP.

* Check if the docking is not initial.
  IF x_docking IS INITIAL .
    CREATE OBJECT x_docking
    EXPORTING
         repid = v_repid
         dynnr = sy-dynnr
         side = cl_gui_docking_container=>dock_at_bottom
         extension = '200'
    EXCEPTIONS
         cntl_error                  = 1
         cntl_system_error           = 2
         create_error                = 3
         lifetime_error              = 4
         lifetime_dynpro_dynpro_link = 5.
  ENDIF .

* Create th editor
  IF x_editor IS INITIAL.
    CREATE OBJECT x_editor
      EXPORTING
             parent            = x_docking
             wordwrap_mode = cl_gui_textedit=>wordwrap_at_fixed_position
             wordwrap_position = 72
             max_number_chars  = 100000.

  ENDIF .

AT SELECTION-SCREEN.

  CHECK sy-ucomm = 'FC01'.

* Get the code and check the syntax.
  PERFORM code_and_syntax_check.

START-OF-SELECTION.

* Get the code and check the syntax.
  PERFORM code_and_syntax_check.

* Insert the report.
  INSERT REPORT 'Z_TEST_REPORT_11' FROM t_code.
  IF sy-subrc <> 0.
    MESSAGE i398(00) WITH 'Errors in generating'.
    LEAVE LIST-PROCESSING.
  ENDIF.

* Generate the report.
  GENERATE REPORT 'Z_TEST_REPORT_11'.
  IF sy-subrc <> 0.
    MESSAGE i398(00) WITH 'Errors in generating'.
    LEAVE LIST-PROCESSING.
  ELSE.
    MESSAGE s398(00) WITH 'Code generated successfully'.
  ENDIF.

* Submit the report.
  GET RUN TIME FIELD v_time1.

  SUBMIT (v_report) AND RETURN.

  GET RUN TIME FIELD v_time2.


* Calculate the difference.
  v_time2 = v_time2 - v_time1.

* Display the run time.
  WRITE: / 'Run time in micro seconds = ', v_time2.


*&---------------------------------------------------------------------*
*&      Form  code_and_syntax_check
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM code_and_syntax_check.

* Refresh the internal table.
  REFRESH: t_code.

* Get the code from the editor.
  CALL METHOD x_editor->get_text_as_r3table
    IMPORTING
      table                  = t_code
    EXCEPTIONS
      error_dp               = 1
      error_cntl_call_method = 2
      error_dp_create        = 3
      potential_data_loss    = 4
      OTHERS                 = 5
          .
  IF sy-subrc <> 0.
    MESSAGE i398(00) WITH 'Error in getting the code'.
    LEAVE PROGRAM.
  ENDIF.

* Insert the report.
  INSERT report INTO t_code INDEX 1.

* Check the syntax
  SYNTAX-CHECK FOR t_code MESSAGE s_message LINE v_line WORD v_word.

* Check the return code.
  IF sy-subrc <> 0.
    MESSAGE i398(00) WITH s_message-msgtext 'Line' v_line.
    LEAVE LIST-PROCESSING.
  ELSE.
    MESSAGE s398(00) WITH 'No syntax errors'.
  ENDIF.

ENDFORM.                    " code_and_syntax_check
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Performance tuning | Производительность All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.