Sunday 25 March 2018

Code Inspector


The Code Inspector tests single objects or object sets (programs, function groups, classes, interfaces, Dictionary objects) for performance, security, serviceability, error proneness, and statistical information.

You can call the Code Inspector for the relevant single objects directly from the ABAP Editor (SE38), the Function Builder (SE37), or the Class Builder (SE24) (Object->Check->Code Inspector). The system then checks using a default check variant.

Object sets, check variants, and inspections are created using transaction SCI.

Object Set:
An object set consists of one or more of the following objects:
•Class/interface
•Function group
•Program
•Dictionary type
•Type group
•Any other TADIR type

Check Variant:
A check variant consists of one or more single checks. After the start of an inspection, these single checks inspect the Object Set elements for errors, warnings, and information.
The single checks are assigned to different categories, such as:
• Performance
• Security
• Syntax Check
• General Checks


Execute Transaction SCI.
























Check variant can be standard check variant , further custom check variant can also be defined.
we define number of objects for inspection in object set.
Create inspection after entering inspection name , after that click create button, then select object set name and check variant name. click on execute button. we can see inspection resluts by clicking on log results button.





 

Saturday 24 March 2018

Runtime Analysis

ABAP runtime analysis tool is executed by transaction code SAT. Runtime Analysis tool assists in analyzing the execution of program parts or individual statements , as well as measuring their runtime.
Measurement times can be determined by using default setting i.e entering default in variant, furhter custom variant can also be created for measurement.

We can specify transaction code / Program / Function module for analyzing, we can also determine names of internal table, further analysis tool can also be executed immediately.

For instance, analyze trasnaction XK03 for vendor display.

Execute transaction SAT, also make sure short description is DEFAULT , Variant is DEFAULT. Enter trnsaction XK03 then click on execute button.


 
Enter vendor number in display vendor screen and press enter. click on exit after navigating to vendor adress screen.





























Runtime analysis display measurement screen will appear.












Runtime analysis tool assists in analyzing measurement,determining database table and time.
 

Thursday 22 March 2018

Classic ALV report with Header and Logo

Follow below steps to disply ALV Report with Header and Logo.

1.      create an executable ABAP program YUA_ALV_REPORT using transaction SE38.

2.      create local class demo

3.      declare TYPES in private section of class definition

4.      declare static internal table in private section of class definition

5.      declare main method in public section of class definition

6.      implement main method of demo class

7.      retrieve data into internal table inside main method

8.      create alv object for class cl_salv_table

9.      Set ALV header with logo 

10.    display ALV report using clv object

 
 ABAP code:

REPORT yua_alv_report.

CLASS demo DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS main.
  PRIVATE SECTION.
    TYPESBEGIN OF ty_data,
            carrid  TYPE  s_carr_id,
            carrname  TYPE    s_carrname,
            currcode  TYPE  s_currcode,
            connid TYPE  s_conn_id,
            fldate  TYPE  s_date,
            price    TYPE s_price,
            currency  TYPE  s_currcode,
            planetype TYPE  s_planetye,
            seatsmax  TYPE  s_seatsmax,
            seatsocc  TYPE  s_seatsocc,
            paymentsum TYPE  s_sum,
            seatsmax_b   TYPE  s_smax_b,
            seatsocc_b  TYPE  s_socc_b,
            seatsmax_f TYPE  s_smax_f,
            seatsocc_f TYPE  s_socc_f,
            url TYPE   s_carrurl,
           END OF ty_data.
    CLASS-DATA  t_data TYPE TABLE OF ty_data.

ENDCLASS.

CLASS demo IMPLEMENTATION.
  METHOD main.


    SELECT  b~carrid
            b~carrname
            b~currcode
            a~connid
            a~fldate
            a~price
            a~currency
            a~planetype
            a~seatsmax
            a~seatsocc
            a~paymentsum
            a~seatsmax_b
            a~seatsocc_b
            a~seatsmax_f
            a~seatsocc_f
            b~url
           FROM sflight as  a
             INNER JOIN scarr as  b
            ON a~carrid b~carrid
           INTO TABLE t_data.
    TRY.
        cl_salv_table=>factory(
          IMPORTING r_salv_table DATA(alv)
          CHANGING  t_table t_data ).

        DATA(columnsalv->get_columns).
        DATA(col_tabcolumns->get).
        LOOP AT col_tab ASSIGNING FIELD-SYMBOL(<column>).
          <column>-r_column->set_output_length40 ).
          IF <column>-columnname EQ 'CARRID' OR <column>-columnname 'CARRNAME' OR
             <column>-columnname 'URL'.
            <column>-r_column->set_visible'X' ).
          ELSE.
            <column>-r_column->set_visible' ' ).
          ENDIF.
        ENDLOOP.


******** Alv Header **************
        DATAlr_grid  TYPE REF TO cl_salv_form_layout_grid,
        lr_logo  TYPE REF TO cl_salv_form_layout_logo,
        lr_label TYPE REF TO cl_salv_form_label,
        lr_text  TYPE REF TO cl_salv_form_text.

        DATA(lv_lineslines(  col_tab ).
        CREATE OBJECT lr_grid.

        DATA(lv_msg=  sy-title  &&   | Report Title  |.

        lr_grid->create_header_informationrow 1  column 2
                                            text lv_msg
                                            tooltip lv_msg ).
        DATA(lr_gridxlr_grid->create_gridrow 6  column 1  ).
*
*        lr_label = lr_gridx->create_label( row = 3 column = 1
*                                          text = lv_msg tooltip = lv_msg ).

        lr_label lr_gridx->create_labelrow column 1
                                           text 'Run Date:' tooltip 'Run Date' ).
        lr_text  lr_gridx->create_text(  row column 2
                                           text sy-datum  tooltip sy-datum ).
        lr_label lr_gridx->create_labelrow column 1
                                           text 'Run Time:' tooltip 'Run Time' ).
        lr_text  lr_gridx->create_text(  row column 2
                                           text sy-uzeit tooltip sy-uzeit ).
        lr_label lr_gridx->create_labelrow column 1
                                           text 'Total Records:' tooltip 'Total Records' ).
        lr_text  lr_gridx->create_text(  row column 2
                                           text lv_lines tooltip lv_lines ).

*       Create logo layout, set grid content on left and logo image on right
        CREATE OBJECT lr_logo.
        lr_logo->set_left_contentlr_grid ).
*      *****
        lr_logo->set_right_logo'ENJOYSAP_LOGO' ).

*       Set element top_of_list
        alv->set_top_of_listlr_logo ).



        alv->display).
      CATCH cx_salv_msg.
        MESSAGE 'ALV display not possible' TYPE 'I'
                DISPLAY LIKE 'E'.
    ENDTRY.
  ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.
  demo=>main).



Output:


 
 


Wednesday 21 March 2018

Selection Screen as dynpros

Selection Screen as dynpros
Selection screens are special dynpros that can be defined in executable programs, function groups, and module pools. Selection screens are defined in the global declaration section of the mentioned ABAP programs with the statements SELECT-OPTIONS, SELECTION-SCREEN and PARAMETERS without using Screen Painter. The screens of selection screens can contain a subset of the screen elements of general dynpros.

Selection screens lie in the same namespace as the dynpros of the program. Additionally, dynpro number 1000 is reserved for a standard selection screen. Apart from the standard selection screen, standalone selection screens can also be defined. Standalone selection screens can only be defined in function groups and module pools.

Following example illustrate SELECTION SCREENS.

 
REPORT YUA_SELSCREEN.


************ Selection Screen 100 *********************

SELECTION-SCREEN BEGIN OF SCREEN 100.
SELECTION-SCREEN BEGIN OF BLOCK sel1 WITH FRAME TITLE tit1.
PARAMETERScityfr TYPE spfli-cityfrom,
            cityto 
TYPE spfli-cityto.
SELECTION-SCREEN END OF BLOCK sel1.
SELECTION-SCREEN END OF SCREEN 100.

************ Selection Screen 200 *********************
SELECTION-SCREEN BEGIN OF SCREEN 200 AS WINDOW.
SELECTION-SCREEN INCLUDE BLOCKS sel1.
SELECTION-SCREEN BEGIN OF BLOCK sel2
                          
WITH FRAME TITLE tit2.
PARAMETERSairpfr TYPE spfli-airpfrom,
            airpto 
TYPE spfli-airpto.
SELECTION-SCREEN END OF BLOCK sel2.
SELECTION-SCREEN END OF SCREEN 200.


CLASS start DEFINITION.
  
PUBLIC SECTION.
    
CLASS-METHODS main.
ENDCLASS.

CLASS start IMPLEMENTATION.
  
METHOD main.
    tit1 
'Cities ( selection-screen 100 )'.
    
CALL SELECTION-SCREEN 100 STARTING AT 10 10.
    tit1 
'Cities for Airports ( selection-screen 200 )'.
    tit2 
'Airports'.
    
CALL SELECTION-SCREEN 200 STARTING AT 10 10.
    tit1 
'Cities again ( selection-screen 100 ) '.
    
CALL SELECTION-SCREEN 100 STARTING AT 10 10.
    
ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  start
=>main( ).


 

Output of above ABAP Program is generated as below














Wednesday 14 March 2018

Trigger ALV Event


Event Class: CL_SALV_EVENTS_TABLE

Following steps are important for ALV event to trigger.

  1. Create  a method for ALV Event to start for instance method double click is used.
  2. Defind double click method for double click event of class cl_salv_events_table, also we need to mention the method which will be called at time of double click i.e detail method.        CLASS-METHODShandle_double_click        FOR EVENT double_click                   OF cl_salv_events_table        IMPORTING row column,        detail            IMPORTING matnr TYPE matnr. 
     
  3. Register event handler method for the events of alv SET HANDLER handle_double_click FOR events.
  4. also defind and impliment detail method.

 Following sample code demonstrates ALV event.
 
  REPORT yua_alv_event.

CLASS demo DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS main.
  PRIVATE SECTION.
    TYPESBEGIN OF ty_data,
             banfn TYPE  banfn,
             matnr TYPE  matnr,
           END OF ty_data.
    CLASS-DATA  t_data TYPE TABLE OF ty_data.
    CLASS-METHODShandle_double_click
      FOR EVENT double_click
                  OF cl_salv_events_table
      IMPORTING row column,
      detail
        IMPORTING matnr TYPE matnr.

ENDCLASS.

CLASS demo IMPLEMENTATION.
  METHOD main.

    SELECT  banfn matnr
           FROM eban
           INTO TABLE t_data.
    TRY.
        cl_salv_table=>factory(
          IMPORTING r_salv_table DATA(alv)
          CHANGING  t_table t_data ).

        DATA(eventsalv->get_event).
        SET HANDLER handle_double_click FOR events.

        alv->display).
      CATCH cx_salv_msg.
        MESSAGE 'ALV display not possible' TYPE 'I'
                DISPLAY LIKE 'E'.
    ENDTRY.
  ENDMETHOD.

  METHOD detail.
    TYPESBEGIN OF alv_line,
             matnr   TYPE matnr,
             maktx   TYPE maktx,
           END OF alv_line.
    DATA   alv_tab    TYPE TABLE OF alv_line.
    SELECT matnr maktx
           FROM MAKT
           WHERE  matnr @matnr
           INTO CORRESPONDING FIELDS OF TABLE @alv_tab.
    IF sy-subrc <> 0.
      MESSAGE e007(sabapdemos).
    ENDIF.
    TRY.
        cl_salv_table=>factory(
          IMPORTING r_salv_table DATA(alv)
          CHANGING  t_table alv_tab ).
        alv->set_screen_popupstart_column 1
                               end_column   60
                               start_line   1
                               end_line     12 ).
        alv->display).
      CATCH cx_salv_msg.
        MESSAGE 'ALV display not possible' TYPE 'I'
                DISPLAY LIKE 'E'.
    ENDTRY.
  ENDMETHOD.

  METHOD handle_double_click.
    READ TABLE t_data INDEX row ASSIGNING FIELD-SYMBOL(<s_data>).
    IF sy-subrc <> 0.
      RETURN.
    ENDIF.
    IF column 'MATNR'.
      demo=>detail<s_data>-matnr ).
    ENDIF.

  ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.
  demo=>main).

 Below is the output of above ABAP code.




    

Classic ALV ( Set Column Hide / Visible )




 Set column ( Hide / Visible)  classic ALV Report.

  Steps to create classic ALV report are below.

1.      create an executable ABAP program YUA_ALV_REPORT using transaction SE38.

2.      create local class demo

3.      declare TYPES in private section of class definition

4.      declare static internal table in private section of class definition

5.      declare main method in public section of class definition

6.      implement main method of demo class

7.      retrieve data into internal table inside main method

8.      create alv object for class cl_salv_table

9.      display ALV report using clv object

 

Sample code demonstarates how to hide colums in classic ALV report 
 

 



 
REPORT yua_alv_report.

CLASS demo DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS main.
  PRIVATE SECTION.
    TYPESBEGIN OF ty_data,
            carrid  TYPE  s_carr_id,
            carrname  TYPE    s_carrname,
            currcode  TYPE  s_currcode,
            connid TYPE  s_conn_id,
            fldate  TYPE  s_date,
            price    TYPE s_price,
            currency  TYPE  s_currcode,
            planetype TYPE  s_planetye,
            seatsmax  TYPE  s_seatsmax,
            seatsocc  TYPE  s_seatsocc,
            paymentsum TYPE  s_sum,
            seatsmax_b   TYPE  s_smax_b,
            seatsocc_b  TYPE  s_socc_b,
            seatsmax_f TYPE  s_smax_f,
            seatsocc_f TYPE  s_socc_f,
            url TYPE   s_carrurl,
           END OF ty_data.
    CLASS-DATA  t_data TYPE TABLE OF ty_data.

ENDCLASS.

CLASS demo IMPLEMENTATION.
  METHOD main.

    SELECT  b~carrid
            b~carrname
            b~currcode
            a~connid
            a~fldate
            a~price
            a~currency
            a~planetype
            a~seatsmax
            a~seatsocc
            a~paymentsum
            a~seatsmax_b
            a~seatsocc_b
            a~seatsmax_f
            a~seatsocc_f
            b~url
           FROM sflight as  a
             INNER JOIN scarr as  b
            ON a~carrid b~carrid
           INTO TABLE t_data.
    TRY.
        cl_salv_table=>factory(
          IMPORTING r_salv_table DATA(alv)
          CHANGING  t_table t_data ).

        DATA(columnsalv->get_columns).
        DATA(col_tabcolumns->get).
        LOOP AT col_tab ASSIGNING FIELD-SYMBOL(<column>).
          <column>-r_column->set_output_length40 ).
          IF <column>-columnname EQ 'CARRID' OR <column>-columnname 'CARRNAME' OR
             <column>-columnname 'URL'.
            <column>-r_column->set_visible'X' ).
          ELSE.
            <column>-r_column->set_visible' ' ).
          ENDIF.
        ENDLOOP.


        alv->display).
      CATCH cx_salv_msg.
        MESSAGE 'ALV display not possible' TYPE 'I'
                DISPLAY LIKE 'E'.
    ENDTRY.
  ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.
  demo=>main).
 
 




Output generated as below:

 

Code Inspector

The Code Inspector tests single objects or object sets (programs, function groups, classes, interfaces, Dictionary objects) for performanc...