Monday, 18 August 2014

HOTSPOT/SINGLE CLICK AREA IN Object Oriented ALV ( OO ALV ) IN SAP ABAP .

In this SAP ABAP tutorial I will show you how to make hospot or single click area in Object Oriented ALV ( OO ALV ) using CL_SALV_TABLE.

To achieve this functionality you need to call the method set_cell_type of class cl_salv_column_table and
 pass the value as if_salv_c_cell_type=>hotspot . Now clicking on the checkbox will trigger the
 event LINK_CLICK , so we need to declare and event handler class here lcl_event_handler and declare
 a method m_link_click to handle the action . The LINK_CLICK event will give us the row and column value
 of the selected row , so that we can do further process based on the value of that field.
NB : Hotspot coding is similar to the checkbox one of.my previous tutorials except instead ofif_salv_c_cell_type=>checkbox_hotspot we need to pass if_salv_c_cell_type=>hotspot .
At the end we need to call the REFRESH( ) method of class CL_SALV_TABLE .
In this SAP ABAP tutorial example we are making the column vbeln values as hotspot so that when the user
 single click on the value it will lead us to the transaction ‘VL03N’ with the corresponding VBELN value.
Please refer to the following source codes :
*******************************************************************
*& Author      : Roushan Kumar
*& Data        : 15/06/2014
*& Description : Hotspot in OO ALV
*******************************************************************
REPORT  ztestr_alv_10.
TYPES : BEGIN OF gy_vbap,
          vbeln TYPE vbeln_va,
          posnr TYPE posnr_va,
          matnr TYPE matnr,
END OF   gy_vbap.
DATA : gt_vbap TYPE STANDARD TABLE OF gy_vbap INITIAL SIZE 1.
DATA : lo_alv TYPE REF TO cl_salv_table.
REFRESH : gt_vbap[].
*----------------------------------------------------------------------*
*       CLASS lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
METHODS:
      m_link_click FOR EVENT link_click OF cl_salv_events_table
IMPORTING row column.
ENDCLASS.                    "lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
*       CLASS lcl_event_handler IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.
METHOD m_link_click.
FIELD-SYMBOLS : <lfs_vbap> TYPE gy_vbap.
READ TABLE gt_vbap ASSIGNING <lfs_vbap> INDEX row.
IF sy-subrc IS INITIAL.
SET PARAMETER ID 'VL' FIELD <lfs_vbap>-vbeln.
CALL TRANSACTION 'VL03N'.
ENDIF.
    lo_alv->refresh( ).
ENDMETHOD.                    "m_link_click
"m_link_click
ENDCLASS.                    "lcl_event_handler IMPLEMENTATION
START-OF-SELECTION.
SELECT vbeln posnr matnr
FROM vbap
INTO TABLE gt_vbap
UP TO 10 ROWS.
IF sy-subrc IS INITIAL.
SORT gt_vbap BY vbeln posnr matnr  .
ENDIF.
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
          r_salv_table = lo_alv
CHANGING
          t_table      = gt_vbap.
CATCH cx_salv_msg .
ENDTRY.
*-- Checkbox logic starts
DATA : lo_columns TYPE REF TO cl_salv_columns_table.
  lo_columns = lo_alv->get_columns( ).
  lo_columns->set_optimize( 'X' ).
DATA : lo_column TYPE REF TO cl_salv_column_table.
TRY.
      lo_column ?= lo_columns->get_column( 'VBELN' ).
      lo_column->set_cell_type( if_salv_c_cell_type=>hotspot ).
      lo_column->set_output_length( 10 ).
CATCH cx_salv_not_found.
ENDTRY.
DATA: lo_events TYPE REF TO cl_salv_events_table.
  lo_events = lo_alv->get_event( ).
DATA: lo_event_handler TYPE REF TO lcl_event_handler.
CREATE OBJECT lo_event_handler.
SET HANDLER lo_event_handler->m_link_click FOR lo_events.
*-- Checkbox logic end
  lo_alv->display( ).
OUTPUT :
clip_image001
clip_image003
clip_image004

CHECKBOX IN Object Oriented ALV ( OO ALV ) IN SAP ABAP .

In this SAP ABAP tutorial I will show you how to make editable checkbox in Object Oriented 

 ALV ( OO ALV ) using CL_SALV_TABLE.

To achieve this functionality you need to call the method set_cell_type of class cl_salv_column_table and
 pass the value as if_salv_c_cell_type=>checkbox_hotspot . Now clicking on the checkbox will trigger the event LINK_CLICK , so we need to declare and event handler class here lcl_event_handler and declare a method m_link_click to handle the action . The LINK_CLICK event will give us the row and column value of the selected checkbox row , to we need to change the value to ‘X’ or 1 to mark it as checked .
At the end we need to call the REFRESH( ) method of class CL_SALV_TABLE .
We cannot activate the checkbox in classic ABAP list as in this case we cannot change the value of the
 checkbox.
Please refer to the following source codes :
*******************************************************************
*& Author      : Roushan Kumar
*& Data        : 14/06/2014
*& Description : Checkbox in OO ALV
*******************************************************************
REPORT  ztestr_alv_10.

TYPES : BEGIN OF gy_bseg,
          check TYPE xfeld,
          bukrs  TYPE bukrs,
          belnr  TYPE belnr_d,
          gjahr  TYPE gjahr,
          buzei  TYPE buzei,
          wrbtr TYPE wrbtr,
END OF gy_bseg.

DATA : gt_bseg TYPE STANDARD TABLE OF gy_bseg INITIAL SIZE 1.
DATA : lo_alv TYPE REF TO cl_salv_table.

REFRESH : gt_bseg[].

*----------------------------------------------------------------------*
*       CLASS lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
METHODS:
      m_link_click FOR EVENT link_click OF cl_salv_events_table
IMPORTING row column.
ENDCLASS.                    "lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
*       CLASS lcl_event_handler IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.

METHOD m_link_click.
FIELD-SYMBOLS : <lfs_bseg> TYPE gy_bseg.
READ TABLE gt_bseg ASSIGNING <lfs_bseg> INDEX row.
IF sy-subrc IS INITIAL.
IF <lfs_bseg>-check IS INITIAL.
        <lfs_bseg>-check = 'X'.
ELSE.
CLEAR <lfs_bseg>-check.
ENDIF.
ENDIF.
    lo_alv->refresh( ).
ENDMETHOD.
"m_link_click
ENDCLASS.                    "lcl_event_handler IMPLEMENTATION
START-OF-SELECTION.
SELECT bukrs belnr gjahr buzei wrbtr
FROM bseg
INTO CORRESPONDING FIELDS OF TABLE gt_bseg
UP TO 10 ROWS.
IF sy-subrc IS INITIAL.
SORT gt_bseg BY bukrs belnr gjahr buzei .
ENDIF.
TRY.
CALL METHOD cl_salv_table=>factory
IMPORTING
          r_salv_table = lo_alv
CHANGING
          t_table      = gt_bseg.
CATCH cx_salv_msg .
ENDTRY.
*-- Checkbox logic starts
DATA : lo_columns TYPE REF TO cl_salv_columns_table.
  lo_columns = lo_alv->get_columns( ).
  lo_columns->set_optimize( 'X' ).
DATA : lo_column TYPE REF TO cl_salv_column_table.
TRY.
      lo_column ?= lo_columns->get_column( 'CHECK' ).
      lo_column->set_cell_type( if_salv_c_cell_type=>checkbox_hotspot ).
      lo_column->set_output_length( 10 ).
CATCH cx_salv_not_found.
ENDTRY.
DATA: lo_events TYPE REF TO cl_salv_events_table.
  lo_events = lo_alv->get_event( ).
DATA: lo_event_handler TYPE REF TO lcl_event_handler.
CREATE OBJECT lo_event_handler.
SET HANDLER lo_event_handler->m_link_click FOR lo_events.
*-- Checkbox logic end
  lo_alv->display( ).
OUTPUT :
CHECKBOX IN Object Oriented ALV ( OO ALV ) IN SAP ABAP
CHECKBOX IN Object Oriented ALV ( OO ALV ) IN SAP ABAP 

CHECKBOX IN Object Oriented ALV ( OO ALV ) IN SAP ABAP
CHECKBOX IN Object Oriented ALV ( OO ALV ) IN SAP ABAP 








































SELECTION SCREEN IN SAP ABAP


In this SAP ABAP tutorial I will show you what selection screen actually means 
 and there related ABAP statements . Selection screen refers to special type of
 screen which takes input from the user . These screen allows the user to
 enter either a single value or multiple values for one or more fields . In simple
 terms , selection screen is the interface between the user and the program .

Selection screen are generated programmatically using ABAP statements ( like parameters , select options ) and has screen number 1000 .

There are three ABAP statements for defining selection screen :

1.   Parameters

2.   Select-options

3.   Selection-screen

Please refer to the following diagram :


Selection Screen in SAP ABAP
Selection Screen in SAP ABAP




  

 
1.Parameters : Parameters refers to the variable which takes single value as input from the selection screen.
 
For example : Parameters : p_matnr type lips-matnr.
 
2.Select-options : Select-options refers to the variable which takes single or
 multiple values as input from the selection screen . Select-options is basically an internal table with the following fields :
 
Sign , Option , Low and High.
 
For example :
 
SELECT-OPTIONS : so_werks FOR likp-werks.
 
3. Selection-screen : This statement is used for two purpose
 
a. Formatting the selection screen.
 
For example suppose the user wants two radio button in the same line or the user wants the text name to be much bigger .
 
SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 1(31) text-099 FOR FIELD p_o_n_rt.
PARAMETERS : p_o_n_rt RADIOBUTTON GROUP rad1 DEFAULT 'X' .
SELECTION-SCREEN COMMENT 40(11) text-101 FOR FIELD p_ooh_p.
PARAMETERS : p_ooh_p RADIOBUTTON GROUP rad1. 

SELECTION-SCREEN COMMENT 59(13) text-102 FOR FIELD p_ret_p.
PARAMETERS : p_ret_p RADIOBUTTON GROUP rad1 .
SELECTION-SCREEN END OF LINE.
 
b. Defining user specific selection-screen.
 
SELECTION-SCREEN BEGIN OF SCREEN <numb> [TITLE <title>] [AS WINDOW].
 
“Your codes
 
SELECTION-SCREEN END OF SCREEN <numb>.

Selection screen : Parameter statement in SAP ABAP in detail.


In this SAP ABAP tutorial I will explain you Selection screen : Parameter statement in SAP ABAP in detail.
Parameters Statement : Parameters statement is used to declare parameter . Parameters are variable
 which takes single value as input from the selection screen . 
For example :
Parameters : p_matnr type lips-matnr.
Once we write the above line of codes , one input field will appear in the selection screen , on the left side
 of the input field , the name of the parameter will be displayed as shown in the following figure.
Selection screen : Parameter statement in SAP ABAP
Selection screen : Parameter statement in SAP ABAP







Now at the back end , one variable is declared with name p_matnr which is known as parameter ,
 which is of type lips-matnr . So p_matnr will take the attributes from the dictionary i.e the type of
 lips-matnr which is char18 .Once you enter some value into the input field say 20 then the value of
 p_matnr will become 20 that we can use in our program.

SYNTAX :
PARAMETERS <parameter_name> [(<length>)] [TYPE <type>|LIKE <data_object>]     [DECIMALS <d>].
NB : 1.The clauses which are inside <> are mandatory clauses and which are inside square bracket [] are
 optional clauses.
2.The maximum length to name a parameter will be 8 . In our case length of p_matnr is 7 as number
 of characters are 7.
3. <type> valid for parameters will be predefined ABAP type ( eg : i , d , string , xstring etc) or ABAP
 dictionary data type ( eg : lips-matnr) except data type F.

4.If the parameter refers to the data types from the dictionary , it will adopt all the attributes of the dictionary
 field like field help ( F1 ) , search help ( F4 ).
5. <d> signifies the number of decimal places for numeric values .
Example :
REPORT  ztestr_22.
DATA lv_matnr TYPE matnr.
PARAMETERS p_par1     LIKE lv_matnr,
             p_par2     
LIKE lips-matnr,
             p_par3
(10TYPE c,
             p_par4
(10TYPE i,
             p_par5     
TYPE DECIMALS 4,
             p_par6     
TYPE lips-matnr,
             p_par7     
.
Output :


Selection screen : Parameter statement in SAP ABAP
Selection screen : Parameter statement in SAP ABAP

















In the above example seven parameters are declared and displayed in the selection screen.
  
1.   P_par1 : it is declared using the like clause and data object lv_matnr is given which is declared above  , 
so p_par1 will adopt all the attributes of lv_matnr which is of type matnr i.e. character type of length 18 ,
 field help ( F1 ) and search help ( F4 ) of data element matnr.

2.   P_par2 : it will adopt all the attributes of lips-matnr i.e. character type of length 18, field help ( F1 ) 
and search help ( F4 ) of data element matnr.

3.   P_par3 : it will be declared as character type of length 10.

4.   P_par4 : it will be declared as integer type of length 10.

5.   P_par5 : it will be declared as packed type with values upto 4 decimal places.

6.   P_par6 : it will adopt all the attributes of lips-matnr i.e. character type of length 18, field help ( F1 )
 and search help ( F4 ) of data element matnr.

7.   P_par7 : it will be declared as character type of default length 1.
  

Object Oriented ALV (OO ALV) tutorials in detail using CL_SALV_TABLE class

Following are the tutorials relating to  Object Oriented ALV (OO ALV) using CL_SALV_TABLE class .  CL_SALV_TABLE  provides very powerful methods that will do magic just by calling those methods.

1.Object Oriented ALV (OO ALV) using simple report
To display ALV using OO , you just need to do two things :
1.One prepare the final internal table that you want to display.
2.Call two methods factory and display of class cl_salv_table ...

2.Activate All Generic ALV Functions(Sort , total , subtotal , excel etc) in
 application toolbar using Object Oriented ALV(OO ALV) in SAP ABAP 
The purpose of ALV(SAP List Viewer) is that it offer the following functionalities as standard in the application
 toolbar, so that you do not need to implement them yourself :
• 1.Details: Displays the data for the selected row in a dialog box.
• 2.Sort ascending/descending: Displays the selected column or columns in a sorted way.
• 3.Search: Users can specify search terms and search order (columns or rows).
• 4.Set filter: Restricts the display based on any filter criteria the user chooses...

3.Adding user-defined button in PF status in Object oriented ALV (OO ALV) 
Many times in ALV it is required that after the ALV is displayed we need to do some user defined
 functionality for example on of my client requirement was to make the delivery quantity field editable
 in the ALV and after user update the delivery quantity value and click the user defined button ,
 it should save the delivery quantity against that particular delivery...

4.Display custom column name in Object Oriented ALV (OO ALV) in SAP ABAP 
Many time it is required to display custom column name , for example the user wants to display 
a table in the ALV whose structure has some field of elementary type i.e. data element is not maintained
 for these fields . For example the structure of the table is as follows :..

5.How to remove functions or icons in ALV toolbar in CL_SALV_TABLE using
 factory method in SAP ABAP. 
In my previous posts , we have shown you how to activate all generic ALV functionality Activate all generic 
functionalities in OO ALV . Today , I will show you how to add / remove functions / icons in ALV toolbar ,
 suppose the output of the ALV is something like that , see the previous link...
6.Add header / top of page in Object Oriented ALV (OO ALV) using cl_salv_table in SAP ABAP 
Many time we come across a requirement where we have to display message logs and along with it we also need
 to display the top of page / header . Please refer to the below source codes ...

7.Set title and zebra/stripped pattern in Object Oriented ALV ( OO ALV ) 

8.Optimize column width in Object Oriented ALV ( OO ALV ) 

9.Fix / Freeze the key fields in Object Oriented ALV ( OO ALV )

10.Hide / visible a particular column / columns in Object Oriented ALV ( OO ALV ) 
Many time it is required to show or hide particular column / columns , depending upon the display requirement
 or layout. Class cl_salv_column_table provides a powerful methodset_visible , which can make column visble
 is value is true and invisible if value is set to false.
By default value is set to true.
In this example , we are hiding the column 'MATNR' ...

11.Add save layout / change layout / choose layout button in 
Object Oriented ALV ( OO alv ) 
The developer who like to develop ALV using cl_salv_table might have notice that the Select layout and
 Save layout buttons are not visible even by using the set_all( ) method of class cl_salv_functions_list as
 shown in the below image...

12.Color the particular column / columns in Object Oriented ALV ( OO alv )
Many time it is required to color the entire column to highlight the informartion.
Color is one of the property of column , you can call the set_color( ) method of class cl_salv_column_table 
to change the color of the column . The value to pass in the set_color( ) method will be a work area 'ls_color' of type lvc_s_colo ...

13.Color the entire row / rows in Object Oriented ALV ( OO alv )
Many time it is required to color the entire row to highlight the informartion.For example one of our client was 
having the requirement to display the particular rows in red , yellow and green if no of days delayed in delivery
 fields value is greater then equal to 15 , less then 15 and greater then 0 , less then equal to 0...

14.F4 help for layout in selection screen in Object Oriented ALV ( OO ALV ) using CL_SALV_TABLE class
In this tutorial I will show you how you can choose the layout from your selection screen and display the output accordingly . Layout or layout variant helps the user to display the output in a particular format such as sorted ,
 total , filter structure , column arrangement etc , layout stores these informations ...

15.Display traffic light ( Red , Green and Yellow ) in 
Object Oriented ALV ( OO ALV) using CL_SLAV_TABLE 
Many time it is required to display the output in such a way that the user can identify the particular records is
 having errors , warning or success. One of our client have the requirement to upload the values from 
a file and do the processing , those records which satisfies all the conditions will be displayed as
 Green (Success)  , those you partially meet the condition will be displayed as Yellow (Warning) and those
 records which does not satisfies any of the conditions will be displayed as red(Fail)...

16.Applying AGGREGATIONS in Object Oriented ALV ( OO ALV ) 
Aggregations are nothing but combinations of values of multiple rows in an ALV , where these multiple values
 are grouped together as input based on certain conditions to form a single value of more significant value. 
For example : Average value, sum value , count , minimum value , maximum value , median , mode etc. 
Similar to sorting , the user can do aggregations programmatically as well as using the ALV application toolbar functionality ...

18.Applying FILTERING in Object Oriented ALV ( OO ALV ) 
Filtering is very important functionality while reporting . Similar to sorting , the user can do aggregations
 programmatically as well as using the ALV application toolbar functionality .
Filtering in OO ALV will work similarly as putting the select-option or range in your final output table to display on a particular column or group of columns...

19.Enabling Selection Mode in Object Oriented ALV ( OO ALV ) : 
Object Oriented ALV using CL_SALV_TABLE also provide the factility to the programmer to determine whether and
 in which situation the user can select areas of the ALV output .it is possible to programmatically determine which
 area needs to be selected and which areas are not required to select. The user can select multiple columns and
 multiple rows in an Object Oriented ALV . ..

20.CHECKBOX IN Object Oriented ALV ( OO ALV ) IN SAP ABAP . 
In this SAP ABAP tutorial I will show you how to make editable checkbox in Object Oriented ALV ( OO ALV )
 using CL_SALV_TABLE.To achieve this functionality you need to call the method set_cell_type of classcl_salv_column_table and pass the value as if_salv_c_cell_type=>checkbox_hotspot .
 Now clicking on the checkbox will trigger the event LINK_CLICK , so we need to declare and event handler
 class here lcl_event_handler and declare a method m_link_click to handle the action . The LINK_CLICK
 event will give us the row and column value of the selected checkbox row , to we need to change the
value to ‘X’ or 1 to mark it as checked ...

20.HOTSPOT/SINGLE CLICK AREA IN Object Oriented ALV ( OO ALV ) 
IN SAP ABAP

In this SAP ABAP tutorial I will show you how to make hospot or single click area in Object Oriented ALV ( OO ALV ) using CL_SALV_TABLE.

To achieve this functionality you need to call the method set_cell_type of class cl_salv_column_table and
 pass the value as if_salv_c_cell_type=>hotspot . Now clicking on the checkbox will trigger the
 event LINK_CLICK , so we need to declare and event handler class here lcl_event_handler and declare 
a method m_link_click to handle the action . The LINK_CLICK event will give us the row and column value of the selected row , so that we can do further process based on the value of that field.

21.CHANGE TEXT ALIGNMENT OF COLUMN IN Object Oriented ALV ( OO ALV ) 
In this SAP ABAP tutorial I will show you how to  change the alignment of text of particular column or
 columns in Object Oriented ALV ( OO ALV ) .
Programmatically now you can change the text alignment on three possibilities :
1.Left aligned.
2.Centered.
3.Right aligned.
N.B : By default numericals values are right aligned and words are left aligned.Now , we can change
 this according to our own taste.

Internal Table in SAP ABAP


Internal Table:
 
In real time different modules e.g. MM , FI , CO , SD etc. hits the database to
 update the values so that they want to see the values in particular way such as
 for SD – Sales related details, for FI – Financial related details etc. that may
 change the database value.


SAP ABAP
SAP ABAP

So, instead of hitting the database and changing the values at the database level
 SAP come up with a concept known as internal table.

Internal table is a variable which is used to extract the records from the database
 table and process the records. Internal table is like temporary table.

So, now different departments can make a copy of the database table , process 
them according to their requirements by using internal table without changing the database table.
sap abap
SAP ABAP
 

Properties of internal table:

1. The data that is copied from database table is copied record by record and in
 the same sequence. So accessing data from internal table will also be done
 record by record and in the same sequence.

2. Internal table is a collection of group of structures and structure is a group 
of fields.

3. Internal table stores the records, manipulate and format the records according
 to user requirement.

4. Memory allocation of internal table is done at runtime as internal tables can 
store any number of records (may be 1 million or 1 billion).

5. The line type of an internal table can be any ABAP data types – elementary, structured or internal tables.

Steps to declare internal table:

1.Declare the structure of the internal table.

TYPES BEGIN OF ty_mara_t,
         matnr 
TYPE mtart,
         maktx 
TYPE maktx,
         matkl 
TYPE matkl,
        
END OF   ty_mara_t.
DATA BEGIN OF ls_mara_d,
         matnr 
TYPE mtart,
         maktx 
TYPE maktx,
         matkl 
TYPE matkl,
      
END OF    ls_mara_d.
DATA ls_mara_3 TYPE ty_mara_t.
DATA ls_mara_4 LIKE ls_mara_d.

Types – it is used to define user defined data types.
Data   - it is used to defined user defined data objects. 

2.Declare internal table using the structure.

DATA lt_mara_1 TYPE TABLE OF ty_mara_t,
       lt_mara_2 
LIKE TABLE OF ls_mara_d,
       lt_mara_3 
LIKE TABLE OF ls_mara_3,
       lt_mara_4 
LIKE TABLE OF ls_mara_4.