Advance Alv

  • View
    104

  • Download
    12

Embed Size (px)

Text of Advance Alv

AB1004 - Advanced ALV using OO v1.0

India SAP CoE, Slide 1

AB1004 - Advanced ALV using OO v1.01 2

Introduction Syntax Description3

DemonstrationExercises HelpMe

4

5India SAP CoE, Slide 2

AB1004 - Advanced ALV using OO v1.01 2

Introduction Syntax Description3

DemonstrationExercises HelpMe

4

5India SAP CoE, Slide 3

IntroductionALV: Object Oriented way CL_GUI_ALV_GRIDPurposeUse

Challenges

India SAP CoE, Slide 4

IntroductionPurpose The ALV Grid control is a flexible tool for displaying lists & provides common list operations as generic functions and can be enhanced by selfdefined options. Purpose of this Tutorial is to demonstrate how to implement ALV using Classes CL_GUI_ALV_GRID and CL_GUI_CUSTOM_CONTAINER

India SAP CoE, Slide 5

IntroductionUse used to build non-hierarchical, interactive, and modern-design lists. provides typical list functions as sorting, filtering, summing, while also gives the opportunity to develop user functions where needed. It presents numerous interfaces like Excel Inplace and Crystal Reports.

India SAP CoE, Slide 6

IntroductionChallenges To use ALV Grid Control in a simple manner, sufficient just having experience on dialog programming. However, to make use of more capabilities, it is required some knowledge on object-oriented perspective of ABAP programming & control framework

India SAP CoE, Slide 7

AB1004 - Advanced ALV using OO v1.01 2

Introduction Syntax description3

DemonstrationExercises HelpMe

4

5India SAP CoE, Slide 8

SAP Control Framework

India SAP CoE, Slide 9

Custom ControlsCustom control is: an area on a screen used to embed controls are software components of the presentation server control is driven by the application logic, which still runs on the application server have a wrapper class in ABAP Objects

India SAP CoE, Slide 10

Control Framework

The controls on the presentation server and the ABAP application programs on the application server communicate using the SAP Control FrameworkIndia SAP CoE, Slide 11

Container Controls

Before you can work with a custom control on a screen, you must assign a Container Control to it. Container controls are instances of special global classes (global class for custom controls is called CL_GUI_CUSTOM_CONTAINER). To link a custom control to a container control, pass the custom control name to the constructor of the container control when you instantiate it using CREATE OBJECT.India SAP CoE, Slide 12

ALV Grid Control ComponentsWrapper class implemented to encapsulate ALV Grid functionality is CL_GUI_ALV_GRID Building Blocks of ALV Grid Control: List data: data in an internal table to be listed. Field Catalog: specify how fields of list will be displayed (type LVC_T_FCAT) Layout Structure: set general display options, grid customizing, totals options, color adjustments (type LVC_S_LAYO) Event Handler: define and implement an event handler class if we want to handle events triggered by the ALV Grid instance.

India SAP CoE, Slide 13

Grid Control Inheritance Hierarchy

CL_GUI_ALV_GRID class encapsulates communication

with the instance on the presentation server, along with many other functions. For this reason, you should instantiate this class, not its super class.India SAP CoE, Slide 14

Wrapper Class for ALV Grid

CL_GUI_ALV_GRID class provides various methods. Go to SE24 and explore the various methods provided by this class.India SAP CoE, Slide 15

Wrapper Class for ALV Grid

CL_GUI_ALV_GRID class provides various events. All the supported events can be viewed under Events Tab

India SAP CoE, Slide 16

Steps for ALV Grid Step 1 Add a custom control on the screen which will be related to the custom container. Lets give it the name CC_ALV. Step 2 Declare global variables to be used for ALV Grid. Step 3 Declare your internal table which is supposed to hold the list data. Step 4 Flow Logic for the Screen which comprises the ALV Grid control. Step 5 Create Custom Container instance, ALV Grid instance Step 6 Populate the list data to be displayed & prepare field catalog, Layout Step 7 Call the appropriate method SET_TABLE_FOR_FIRST_DISPLAY / REFRESH_TABLE_DISPLAYIndia SAP CoE, Slide 17

AB1004 - Advanced ALV using OO v1.01 2

Introduction Syntax Description3

DemonstrationExercises HelpMe

4

5India SAP CoE, Slide 18

Step 1 Create Custom Control

Create a screen. Go to Screen Layout & Add a custom control on the screen. Give it a name say CC_ALV

India SAP CoE, Slide 19

Step 2 & 3 - Global data definition

1. Create instance reference for creating instances of class CL_GUI_ALV_GRID and Custom Container CL_GUI_CUSTOM_CONTAINER. 2. Field Catalog Internal Table will of type LVC_T_FCAT 3. Layout will be of type LVC_S_LAYO 4. Internal Table to hold List Data that is to be displayed as ALVIndia SAP CoE, Slide 20

Step 4 Screen Flow Logic

We will now add a PBO Module Display_alv. This routine will have the code for: Instantiating the Custom Control & ALV Grid Populating the Field Catalog & Layout Calling the appropriate method of class CL_GUI_ALV_GRID to display the ALV Grid outputIndia SAP CoE, Slide 21

Step 5 Creating Custom Container Instance

Instantiate the Container. Pass the name of the Custom Control we defined in the Screen 9000 above

As we are using the concept of Classes, we will now create instance of the Custom Container. Use the Pattern > ABAP Objects > Create Object > Specify the Instance name as the one we specified in the Data Definition Step.India SAP CoE, Slide 22

Step 5 Creating ALV Grid Instance

Instantiate the ALV Grid. Pass the Container (instance of which we created in the previous slide)

We will now create instance of the ALV Grid. Again use the Pattern > ABAP Objects > Create Object > Specify the Instance name as the one we specified in the Definition Step (type ref to CL_GUI_ALV_GRID) Class Name: CL_GUI_ALV_GRIDIndia SAP CoE, Slide 23

Step 6 - Building Field CatalogWe will now prepare the Field Catalog. There are 3 methods for doing this: Automatic generation Semi-automatic generation Manual generation Please refer to the attached document for all the options provided by Field Catalog

India SAP CoE, Slide 24

Step 6 - Building Field CatalogStructure of Field Catalog (LVC_T_FCAT)FIELDNAMEREF_FIELD

Assign a field name of your output table to a row of field catalogMust specify this if field name in the output table is not identical to the field name of the field in Data Dictionary Must fill this field only if the output table described by the current entry in the field catalog has a corresponding entry in the DDIC Sequence of the fields Desired width of the field in output Field Labels

REF_TABLE

COL_POS OUTPUTLEN SCRTEXT_L/M/S

India SAP CoE, Slide 25

Building Field Catalog Manually

The work in this procedure is just filling the internal table for the field catalog. We have already seen the structure of a field catalog. To achieve filling the field catalog correctly, one must at least fill the above fields of the field catalog structure for each column of the list.

India SAP CoE, Slide 26

Building Field Catalog ManuallyDATA ls_fcat type lvc_s_fcat . ls_fcat-fieldname = 'CARRID. ls_fcat-inttype = 'C'. ls_fcat-outputlen = '3'. ls_fcat-coltext = 'Carrier ID'. ls_fcat-seltext = 'Carrier ID'. APPEND ls_fcat to pt_fieldcat. CLEAR ls_fcat. ls_fcat-fieldname = 'CONNID'. ls_fcat-ref_table = 'SFLIGHT'. ls_fcat-ref_table = 'CONNID'. ls_fcat-outputlen = '3'. ls_fcat-coltext = 'Connection ID'. ls_fcat-seltext = 'Connection ID'. APPEND ls_fcat to pt_fieldcat . . And so on for all the fields to be displayed in the ALV outputIndia SAP CoE, Slide 27

Building Field Catalog Semi-automaticallyIt is a boring work to fill and append rows for all columns of our list. And it is not flexible to proceed with automatically generating of the field catalog. Fortunately, there is a middle ground as generating the field catalog semi-automatically. This procedure requires a function module to call. We pass the name of the structure to be the template and the function module generates a field catalog for us. After getting the generated field catalog, we loop at it and change whatever we want. The name of the function module is LVC_FIELDCATALOG_MERGE. We will now look at how to use this FM in the next slide

India SAP CoE, Slide 28

Building Field Catalog Semi-automaticallyDATA ls_fcat type lvc_s_fcat . CALL FUNCTION 'LVC_FIELDCATALOG_MERGE' EXPORTING i_structure_name = 'SFLIGHT' CHANGING ct_fieldcat = pt_fieldcat[] EXCEPTIONS inconsistent_interface = 1 program_error = 2 OTHERS = 3. IF sy-subrc 0. *--Exception handling ENDIF. LOOP AT pt_fieldcat INTO ls_fcat . CASE pt_fieldcat-fieldname . WHEN 'CARRID' . ls_fcat-outpulen = '10'. ls_fcat-coltext = 'Airline Carrier ID'. MODIFY pt_fieldcat FROM ls_fcat. WHEN 'PAYMENTSUM'. ls_fcat-no_out = 'X' . MODIFY pt_fieldcat FROM ls_fcat. ENDCASE. ENDLOOP.

India SAP CoE, Slide 29

Step 6 Layout AdjustmentsIt comes now painting our ALV Grid in a general aspect. To define general appearance of our ALV Grid we fill a structure of type LVC_S_LAYO. This table contains fields and functionalities serviced by this adjustment. Some of the generally used options are as below:ZEBRA SMALLTITLE If this field is set, the list shows a striped pattern in the print preview and when it is printed (SPACE, 'X) If this field is set, the title size in the grid co