Showing posts with label Code. Show all posts
Showing posts with label Code. Show all posts

Remove Header on Last Page in Classical Report

Posted by Krishh Webworld | 6:19 PM | , , | 1 comments »

This code provides logic to remove the Header generated by TOP-OF-PAGE from the Last Page.


CODE Snippet
*&---------------------------------------------------------------------*
*& Report ZTEST_NP_TOP_LAST *

*&---------------------------------------------------------------------*

*& Example of how to remove the header generated by TOP-OF-PAGE and *

*& Move the LIST upwards in the space of the TOP-OF-PAGE *

*& *

*&---------------------------------------------------------------------*


REPORT ZTEST_NP LINE-COUNT 10(2) NO STANDARD PAGE HEADING.


START-OF-SELECTION.
* Generating the Output
DO 30 TIMES.
WRITE: / SY-ABCDE.
ENDDO.


* Clearing the last TOP-OF-PAGE
READ LINE 1 OF PAGE SY-PAGNO.
CLEAR SY-LISEL.
MODIFY LINE 1 OF PAGE SY-PAGNO.


* Moving list upword
* Here we are moving only 2 lines, as we have only 2
* lines in our TOP-OF-PAGE
DATA: L_CNT TYPE I,
L_LINE TYPE I.
CLEAR: L_CNT, L_LINE.
L_LINE = 2.
DO.
L_CNT = L_CNT + 1.
L_LINE = L_LINE + 1.
READ LINE L_LINE OF PAGE SY-PAGNO.
IF SY-SUBRC NE 0.
EXIT.
ELSE.
MODIFY LINE L_CNT OF PAGE SY-PAGNO.
CLEAR SY-LISEL.
MODIFY LINE L_LINE OF PAGE SY-PAGNO.
ENDIF.
ENDDO.

* Top of page
TOP-OF-PAGE.
WRITE: / 'Heading from TOP OF PAGE Line 1'.
WRITE: / 'Line 2'.

Move Cursor to next Row by Pressing Enter in OO ALV

Posted by Krishh Webworld | 6:18 PM | , , | 2 comments »

I was wondering if it is possible to have the same functionality of the Excel: Press Enter and cursor will move to next row.

As OO ABAP using the class CL_GUI_ALV_GRID provides so many methods for the processing at the Cell Levels. After looking to all the methods of the CL_GUI_ALV_GRID, I found there are so many methods which can do the processing at the Cell level. I have started to give the try. After certain tries, I was able to achieve what I was looking for.


Code Snippet for the Class handler for ALV Grid Call
*&---------------------------------------------------------------------*
*& This code snippet sets the handler of the evnets for the OO ALV
*&---------------------------------------------------------------------*
* Data Declaration

DATA: g_grid type ref to cl_gui_alv_grid,
g_event_receiver type ref to lcl_event_receiver.

*
* Registering the Edit event
CALL METHOD g_grid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter.
*
* Event Handler
create object g_event_receiver.
*
* Event listner method for Edit Event
SET HANDLER g_event_receiver->handle_data_changed FOR g_grid.
*
* calling the instance of the ALV
call method g_grid->set_table_for_first_display
changing it_fieldcatalog = gt_fieldcat
it_outtab = gt_outtab[].


Code Snippet for the Class handler definition and Implementation
*&---------------------------------------------------------------------*
*& This code snippet shows the Event Handler Class's Definition
*& and implementation
*&---------------------------------------------------------------------*
* Definition

class lcl_event_receiver definition.

public section.
methods:
handle_data_changed FOR EVENT data_changed
OF cl_gui_alv_grid
IMPORTING er_data_changed.

endclass.


* Class Implementation
class lcl_event_receiver implementation.
method handle_data_changed.
*
* Local data
data: LE_ROW TYPE I,
LE_VALUE TYPE C,
LE_COL TYPE I,
LES_ROW_ID TYPE LVC_S_ROW,
LES_COL_ID TYPE LVC_S_COL,
LES_ROW_NO TYPE LVC_S_ROID.
*
* Getting Current Cell
CALL METHOD G_GRID->GET_CURRENT_CELL
IMPORTING
E_ROW = le_row
E_VALUE = le_value
E_COL = le_col
ES_ROW_ID = les_row_id
ES_COL_ID = les_col_id
ES_ROW_NO = les_row_no.
*
* Total number of tables
describe table gt_outtab lines sy-index.
*
* Getting next row
les_row_id-INDEX = les_row_id-INDEX + 1.
les_row_no-ROW_ID = les_row_no-ROW_ID + 1.
*
* Set the Next row
if les_row_id-index le sy-index.
CALL METHOD G_GRID->SET_CURRENT_CELL_VIA_ID
EXPORTING
IS_ROW_ID = les_row_id
IS_COLUMN_ID = LES_COL_ID
IS_ROW_NO = les_row_no.
endif.
endmethod.
endclass.

SAP ABAP Object Design Patterns: Singleton

Posted by Krishh Webworld | 6:13 PM | , , , | 2 comments »

Today we will try to explore the design patterns in the ABAP Objects. We will start with the Singleton design pattern, which is the simplest of its family of design patterns.


What is the concept of the Singleton design pattern?
The concpet of restricting the instantiation of the a class to only and only to one object is called Singleton. As name suggests, it will restrict to create only one instance of a class. The calss will have a logic in place which will deny if the application will ask for more than one instance.

Let's try to understand with an example:
We have an application which will bring the pay stub of an employee for current month. In a standarad system, there will be only one active salary account for the employee with the company. Because of this fact, we should only create one object of the employee's salary account. In program, we are creating this object in a loop. So, what happens if we don't have a design pattern which will restrict it to create more than one object. Application will create, rather overwrite an instance of the class.

In ABAP, generally we check if the instance is created or not, like:
Code Snippet to check instance
 
*&---------------------------------------------------------------------*
DATA: lo_application TYPE REF TO lcl_application.
IF lo_application IS INITIAL.
CREATE OBJECT lo_application.
ENDIF.

But, if we take another reference to the class and create a instance of that, it will definatly allow. So, we need to have Singleton design pattern implemented.

How to implement Singleton design Pattern in ABAP?
We can use the CLASS-DATA(static data) to save the created instance within the class and check with that instance, if application asks for a new instance.

We will look at this example.

UML diagrm for the example:



Code Snippet for Design Patterns: Singleton
  
*&---------------------------------------------------------------------*
*& Report shows how to use the static data of the class to
*& implement the design patterns.
*&---------------------------------------------------------------------*
REPORT ztest_singleton_pattern.
*
*----------------------------------------------------------------------*
* CLASS lcl_application DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_application DEFINITION.
*
PUBLIC SECTION.
* Static Method which will return us the object reference
CLASS-METHODS:
get_apps_instance
EXPORTING
eo_apps TYPE REF TO lcl_application.
*
PRIVATE SECTION.
* static class reference to hold the existing object reference
CLASS-DATA: lo_apps TYPE REF TO lcl_application.
*
ENDCLASS. "lcl_application DEFINITION
*
*
*----------------------------------------------------------------------*
* CLASS lcl_application IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_application IMPLEMENTATION.
*
* This method will return the object reference to the calling application
METHOD get_apps_instance.
IF lo_apps IS INITIAL.
* creation of the object
CREATE OBJECT lo_apps.
* assigning reference back to exporting parameter
eo_apps = lo_apps.
ENDIF.
ENDMETHOD. "get_apps_instance
ENDCLASS. "lcl_application IMPLEMENTATION
*
*
START-OF-SELECTION.
*
*.Reference: 1 .........................................
DATA: lo_application TYPE REF TO lcl_application.
WRITE: / 'LO_APPLICATION: '.
* calling the method which gets us the instance
CALL METHOD lcl_application=>get_apps_instance
IMPORTING
eo_apps = lo_application.
IF lo_application IS NOT INITIAL.
WRITE: / 'Object has been created..!'.
ELSE.
WRITE: / 'Error: Object has not been created..!'.
ENDIF.
*
*.Reference: 2............................................
DATA: lo_2nd_apps TYPE REF TO lcl_application.
SKIP 2.
WRITE: / 'LO_2ND_APPS : '.
* calling the method which gets us the instance
* Our instance will be initial here because the STATIC calss
* reference LO_APPS in the calss LCL_APPLICATION will prevent
* this call to create a new instance.
CALL METHOD lcl_application=>get_apps_instance
IMPORTING
eo_apps = lo_2nd_apps.
IF lo_2nd_apps IS NOT INITIAL.
WRITE: / 'Object has been created..!'.
ELSE.
WRITE: / 'Error: Object has not been created..!'.
ENDIF.



This will generate the output like this:

SAP Classical ALV: Change Subtotal

Posted by Krishh Webworld | 6:11 PM | , , | 1 comments »

Sometimes we need to modify the subtotals on the ALV, specially when we have to give the average of the percentages or something like that. To change the subtotal we need to follow certain steps:

1. we need to get the ALV object form the ALV function module. We can use the FM GET_GLOBALS_FROM_SLVC_FULLSCR to get the Global data of the ALV. From this FM we will get the ALV object.

2. After getting the ALV object, we need to get the subtotal using the method GET_SUBTOTALS of the ALV object. We will get the first level subtotal using the parameter EP_COLLECT01.

3. Now, we need to modify the subtotal. Here we need to take help of Field-symbols since the EP_COLLECT01 is reference to data.

4. We need to refresh the Table display. For this purpose we can use the method REFRESH_TABLE_DISPLAY.

Here is the code snippet which performs all the steps mentioned above:


Code Snippet to change the Subtotal
  
DATA: lo_grid TYPE REF TO cl_gui_alv_grid.
*
* get the global reference
CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
IMPORTING
e_grid = lo_grid.
*
* get the subtotal
DATA: it_01 TYPE REF TO data.
*
CALL METHOD lo_grid->get_subtotals
IMPORTING
ep_collect01 = it_01.
*
* change the data
FIELD-SYMBOLS: TYPE ANY TABLE,
TYPE ANY,
TYPE ANY.
ASSIGN it_01->* TO .
*
LOOP AT ASSIGNING .
ASSIGN COMPONENT 'PER' OF STRUCTURE TO .
= '100'.
ENDLOOP.
*
* Refresh the table display
CALL METHOD lo_grid->refresh_table_display
EXPORTING
i_soft_refresh = 'X'.



To be able to use the FM GET_GLOBALS_FROM_SLVC_FULLSCR, we need to find a spot in our program which is being called after the ALV's main FM e.g. REUSE_ALV_GRID_DISPLAY. For this purpose, I have implemented the TOP_OF_PAGE event because it will always be called after the FM. In the subroutine for the TOP_OF_PAGE, I used the code snippet to change the Subtotal.

You can download the entire source code of my test program from here --> http://smartform.googlecode.com/files/ZALV_SUBTOT_CHANGE.txt .

Add Custom Button on Maintianence View (SM30)

Posted by Krishh Webworld | 12:45 PM | , , | 0 comments »

Whenever we generate the table maintianence, SAP generates some new code and use the Shared code for the Table maintainence generator. Since long time, I was wondering how can I add my own custom PF buttons in the table maintainence screen which comes in SM30. Today, this discussion in the SDN form raised this point in my mind again - Adding Custon button on Maintainance View.

I have started searching the GUI status in the Function Group which I have provided in the Table maintainence generator, but I didn't find it in the object browser (SE80) of the Function group. So, I thought this must be taken care by the Events in the Table maintainence. I searched the list and I found suitable one - ST (GUI Menu Main Program Name). Follow this link for mor information on Table maintenace events - Extended Table Maintenance Events

To add a custom button we need to follow couple of steps:
1. Create Table Maintainence.
Obviously today's discussion is based on the Table maintaince, we must have that before we start it. For a information purpose, I will attach a screen shot of the Table maintaince.


2. Copy user Interface of program SAPLSVIM to our FG
We will copy all the user interface of the main table maintainence program to our Fuction Group. Table maintainence runtime uses the user interface from the program SAPLSVIM. So, we are unable to find any user interface in our FG.


There will be one popup of language compatability, which you can pass it on by pressing Enter.

3. Add Custom Button in the PF-Status
Here we need to identify the proper PF-Status from all the statues. We will use the EULG pf-status which is being called when you enter in SM30 with Change mode. We will add the button with code "0POPUP" We can simply check which pf-status is being used in the each screen of the SM30 by going System > Status > GUI status. We will activate the changed status.

4. Add Event ST in the Table modification Events
Open the table maintainence generator screen and follow: Environment -> Modification -> Events. Select ST from the values and enter the FG main program name. For this example SAPLZTEST_TABLES.


5. Add PAI module in the Screen
Now, we need to create a new PAI module in the Screen flow. We will create the module 0CUSTOM_PF_BUTTON in the Screen. We will create this module in a New Custom include by selecting it from the popup.

In this code snippet, I am showing how to handle our user command. Here I am just giving information popup when user interact with the button in the change mode.

Code Snippet for Handling custom button
  *----------------------------------------------------------------------*
***INCLUDE LZTEST_TABLESI01 .

*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Module CUSTOM_PF_BUTTON INPUT
*&---------------------------------------------------------------------*
* Custom Button Handling
* Here TOTAL table is avliable with all the data.
* User command is stored in the field FUNCTION
*----------------------------------------------------------------------*
MODULE 0custom_pf_button INPUT.
*
DATA: l_count TYPE i.
* Table of the same structure of the TOTAL which can be exported
DATA: BEGIN OF itab OCCURS 0.
INCLUDE STRUCTURE ztest_pf_status.
INCLUDE STRUCTURE vimflagtab.
DATA: END OF itab.
*
CASE function.
WHEN '0POPUP'.
itab[] = total[].
*
DELETE itab WHERE mark IS INITIAL.
DESCRIBE TABLE itab LINES l_count.

*
CALL FUNCTION 'POPUP_TO_INFORM'
EXPORTING
titel = 'Information'
txt1 = 'Selected number of entries'
txt2 = l_count.
*
CLEAR l_count.
*
ENDCASE.
*
ENDMODULE. " CUSTOM_PF_BUTTON INPUT


Don't forget to activate the Function Group, since we have created a new include in it.

6. Custom button on the SM30
Here is the screenshot of the SM30 with our new added custom button.

After pressing button, it will react like this:

ABAP Objects: Widening Cast (Down Casting)

Posted by Krishh Webworld | 11:21 AM | , , | 0 comments »

When we assign the instance of the Superclass to the Subclass, than it is called the Widening Cast, because we are moving to the "More Specific View" from the "Less specific view". Due to this reason it is also called the "Down Casting".

Everytime it is not possible to move the Superclass reference to the Subclass, because subclass will(or might) have always more functionality compare to the Superclass. So, we need to be more careful when we use the down casting.

We will use the same ANIMAL Superclass and LION subclass as per the blog post - ABAP Objects: Narrowing Cast

When this Widening Cast is used?
Widening cast can be used when we need to access the Specific functionality of the subclass from the Superclass.

In ABAP, it is necessary to catch the exception CX_SY_MOVE_CAST_ERROR while doing the widening cast to avoid the short-dump.

Code Snippet for Widening Cast (Downcasting)
  
*----------------------------------------------------------------------*
* This code shows how to use the Widening cast (downcasting)
*----------------------------------------------------------------------*
START-OF-SELECTION.
DATA: lo_animal TYPE REF TO lcl_animal,
lo_lion TYPE REF TO lcl_lion,
lo_cast_error TYPE REF TO cx_sy_move_cast_error.
*
* First We have to do Narrow casting in order to set the
* Animal reference to LION reference.

DATA: lo_tmp_lion TYPE REF TO lcl_lion.
CREATE OBJECT lo_tmp_lion.
lo_animal = lo_tmp_lion.
*
* Now, we will do the Widening cast to move the reference from the
* Animal to LION (more specific class).
TRY.
lo_lion ?= lo_animal.
CATCH cx_sy_move_cast_error INTO lo_cast_error.
WRITE: / 'Widening cast failed 1'.
ENDTRY.
IF lo_lion IS NOT INITIAL.

CALL METHOD lo_lion->hungry( ).
CALL METHOD lo_lion->fasting( ).
ENDIF.
*
* Now, we will try to do the widening cast without setting up
* the proper object reference in the Super reference.
CLEAR: lo_animal, lo_lion, lo_cast_error.
CREATE OBJECT lo_animal.
TRY.
lo_lion ?= lo_animal.
CATCH cx_sy_move_cast_error INTO lo_cast_error.
WRITE: / 'Widening cast failed 2'.

ENDTRY.
IF lo_lion IS NOT INITIAL.
CALL METHOD lo_lion->hungry( ).
CALL METHOD lo_lion->fasting( ).
ENDIF.



Output of this code snippet is:

ABAP Objects: Narrowing Cast (Upcasting)

Posted by Krishh Webworld | 11:18 AM | , , | 0 comments »

Important principal of the Inheritence is that an instance of the Subclass can be used in all the contexts where the Superclass can be used. This is possible because the Subclass contains all the attributes of the Superclass, because Subclass has been inhertied from the Super.

When we assign the instance of the Subclass back to the instance of the Superclass, than it is called the "Narrow Casting", because we are switching from a "More Specific view of an object" to "less specific view".
For example: we have a class a global class for ANIMAL. Now, we have inherited more specific class as LION from the ANIMAL. Since LION will have all the attributes from the ANIMAL, we can always refer back to ANIMAL with the reference of the LION.

When this Narrow casting is used?
An application which is interested in the details of the LION, but don't want to know about them. An application only needs to work with the ANIMAL class. In order to allow the application to access the attributes of the LION we have to do a narrow cast and assign it back to the ANIMAL, which is visible from an application.
UML diagram from the example:



Code Snippet for Class ANIMAL & LION
  
*&---------------------------------------------------------------------*
*& This code snippet implements the local calss ANIMAL and LION
*&---------------------------------------------------------------------*
REPORT ztest_narrow_casting.
*
*----------------------------------------------------------------------*
* Animal Super Class defintion
*----------------------------------------------------------------------*
CLASS lcl_animal DEFINITION.
PUBLIC SECTION.
METHODS: hungry.
ENDCLASS. "lcl_animal DEFINITION
*
*----------------------------------------------------------------------*
* Lion subclass defintion

*----------------------------------------------------------------------*
CLASS lcl_lion DEFINITION INHERITING FROM lcl_animal.
PUBLIC SECTION.
METHODS: hungry REDEFINITION,
fasting.
ENDCLASS. "lcl_lion DEFINITION
*
*
*----------------------------------------------------------------------*
* Animal Implementation
*----------------------------------------------------------------------*
CLASS lcl_animal IMPLEMENTATION.
METHOD hungry.
WRITE: / 'An animal is hungry'.
ENDMETHOD. "hungry
ENDCLASS. "lcl_animal IMPLEMENTATION
*
*----------------------------------------------------------------------*
* Lion subclass implementation
*----------------------------------------------------------------------*
CLASS lcl_lion IMPLEMENTATION.
METHOD hungry.
WRITE: / 'A Lion (King of Jungle) is hungry.',
'Run as fast as you can..!'.

ENDMETHOD. "hungry
METHOD fasting.
WRITE: / 'Stop running. Lion is on Fasting today.'.
ENDMETHOD.
ENDCLASS. "lcl_lion IMPLEMENTATION


Code Snippet
  
*----------------------------------------------------------------------*
* This code shows how to use the Narrow casting
*----------------------------------------------------------------------*
START-OF-SELECTION.
DATA: lo_animal TYPE REF TO lcl_animal,
lo_lion TYPE REF TO lcl_lion.
*
* ANIMAL object without NARROW casting
WRITE: / 'Animal - without NARROW casting'.
CREATE OBJECT lo_animal.
CALL METHOD lo_animal->hungry( ).
CLEAR lo_animal.
*
* ANIMAL object with NARROW CASTING
SKIP 2.
WRITE: / 'Animal - NARROW casting from LION'.
CREATE OBJECT lo_lion.
lo_animal = lo_lion.

CALL METHOD lo_animal->hungry( ).
*
* call the method FASTING must be a dynamic because FASTING is not
* in the Animal
CALL METHOD lo_animal->('FASTING').


Output from this code snippet:

SALV Table 7 - Changing Column settings

Posted by Krishh Webworld | 11:11 AM | , , , | 0 comments »

Today in the SALV model tutorial series, we will see how we can change the Column properites. You can find all the previous discussion in this series can be found at Tutorials > SALV Table Display.

To change the propeties of the Columns first we need to get the Column object from the SALV Object. The reference of the column object would be CL_SALV_COLUMNS. This object reference would provide us the access to the properties of all the columns. For example, if we need to set the column width optimization for the table, we can set using this columns reference.

To change the individual column properties, we need to get the individual column reference from the reference created using the CL_SALV_COLUMNS. The individual column property can be changed by the getting the reference of CL_SALV_COLUMN. Like, to change the column heading, we need to first get the column from the Columns object and than we need to set specific property.

Here is the code snippet to which provides the ADD-ON code to our Base program. The base program can be found in the SALV Model 1: Normal ALV Table Display.

UML Diagram would be like:

Code Snippet
  
*$*$*.....CODE_ADD_1 - Begin..................................1..*$*$*
*
* In this section we will define the private methods which can
* be implemented to set the properties of the ALV and can be
* called in the
*

PRIVATE SECTION.
* Set the various column properties
METHODS:
set_columns
CHANGING
co_alv TYPE REF TO cl_salv_table.
*
*$*$*.....CODE_ADD_1 - End....................................1..*$*$*
*
*
*$*$*.....CODE_ADD_2 - Begin..................................2..*$*$*

*
* In this area we will call the methods which will set the
* different properties to the ALV
*
* Setting up the Columns
CALL METHOD me->set_columns
CHANGING
co_alv = o_alv.
*$*$*.....CODE_ADD_2 - End....................................2..*$*$*
*
*
*$*$*.....CODE_ADD_3 - Begin..................................3..*$*$*

*
* In this area we will implement the methods which are defined in
* the class definition
*
METHOD set_columns.
*
*...Get all the Columns
DATA: lo_cols TYPE REF TO cl_salv_columns.
lo_cols = o_alv->get_columns( ).
*
* set the Column optimization

lo_cols->set_optimize( 'X' ).
*
*...Process individual columns
DATA: lo_column TYPE REF TO cl_salv_column.
*
* Change the properties of the Columns KUNNR
TRY.
lo_column = lo_cols->get_column( 'KUNNR' ).
lo_column->set_long_text( 'Sold-To Party' ).
lo_column->set_medium_text( 'Sold-To Party' ).
lo_column->set_short_text( 'Sold-To' ).

lo_column->set_output_length( 10 ).
CATCH cx_salv_not_found. "#EC NO_HANDLER
ENDTRY.
*
ENDMETHOD. "SET_COLUMNS
*$*$*.....CODE_ADD_3 - End....................................3..*$*$*


This code snippet will generat output like this:

SALV Table 6 - Dispaly Settings

Posted by Krishh Webworld | 11:04 AM | , , , | 1 comments »

In the series of the SALV Simple Model, we will see how we can set the Display Settings to the entire ALV. You can find the previous discussions in this blog series at Tutorials > SALV Table Display

To set the display settings, we need to use the reference of the class CL_SALV_DISPLAY_SETTINGS. We will ask the reference of the Display settings from our ALV object created using the CL_SALV_TABLE. By using the dispaly settings, we can set the Zebra style, Title of the ALV etc.

Here is the code snippet to which provides the ADD-ON code to our Base program. The base program can be found in the SALV Model 1: Normal ALV Table Display.

UML diagram for this example is like:

Code Snippet
  
*$*$*.....CODE_ADD_1 - Begin..................................1..*$*$*
*
* In this section we will define the private methods which can
* be implemented to set the properties of the ALV and can be
* called in the
*

PRIVATE SECTION.
METHODS:
set_display_setting
CHANGING
co_alv TYPE REF TO cl_salv_table.
*$*$*.....CODE_ADD_1 - End....................................1..*$*$*
*
*$*$*.....CODE_ADD_2 - Begin..................................2..*$*$*
*
* In this area we will call the methods which will set the

* different properties to the ALV
CALL METHOD set_display_setting
CHANGING
co_alv = o_alv.
*$*$*.....CODE_ADD_2 - End....................................2..*$*$*
*
*$*$*.....CODE_ADD_3 - Begin..................................3..*$*$*
*
* In this area we will implement the methods which are defined in
* the class definition
*
METHOD set_display_setting.
*
DATA: lo_display TYPE REF TO cl_salv_display_settings.
*
* get display object
lo_display = o_alv->get_display_settings( ).
*
* set ZEBRA pattern
lo_display->set_striped_pattern( 'X' ).
*
* Title to ALV
lo_display->set_list_header( 'ALV Test for Display Settings' ).
*
ENDMETHOD. "SET_DISPLAY_SETTING
*$*$*.....CODE_ADD_3 - End....................................3..*$*$*


This code will generate the output like this:

SALV Table 2 : Adding Default PF STATUS in ALV

Posted by Krishh Webworld | 10:37 AM | , , , | 0 comments »

We have discussed in post SALV Model 1: Normal ALV Table Display to generate an ALV using new the SALV Model. It is a true object oriented way to generate an ALV.

Today, we will see how to add standard PF Status (GUI Status) in this Standard ALV created using the class CL_SALV_TABLE. The object created with reference to CL_SALV_TABLE contains the method which can be helpful to add the PF-Status in the ALV.

Here is the code Snippet which provides the ADD-ON code. This ADD-ON code can be replaced with the relevent section from this code snippet in the base program. You can find the base program code snippet in the post SALV Model 1 : Normal ALV Table Display. Adding code to base program is like adding the code correction from the OSS Note.
The new UML diagram of our application is like:

Code Snippet to add Default PF Status
  
*$*$*.....CODE_ADD_1 - Begin..................................1..*$*$*
*
* In this section we will define the private methods which can
* be implemented to set the properties of the ALV and can be
* called in the
*
PRIVATE SECTION.
METHODS:

set_pf_status
CHANGING
co_alv TYPE REF TO cl_salv_table.
*$*$*.....CODE_ADD_1 - End....................................1..*$*$*
*
*
*$*$*.....CODE_ADD_2 - Begin..................................2..*$*$*

*
* In this area we will call the methods which will set the
* different properties to the ALV
*
CALL METHOD set_pf_status
CHANGING
co_alv = o_alv.
*$*$*.....CODE_ADD_2 - End....................................2..*$*$*
*
*
*$*$*.....CODE_ADD_3 - Begin..................................3..*$*$*

*
* In this area we will implement the methods which are defined in
* the class definition
*
METHOD set_pf_status.
*
DATA: lo_functions TYPE REF TO cl_salv_functions_list.
*
lo_functions = co_alv->get_functions( ).
lo_functions->set_default( abap_true ).
*
ENDMETHOD. "set_pf_status
*$*$*.....CODE_ADD_3 - End....................................3..*$*$*


This will generate the output like:

Archives

Subscribe Now: Feed Icon