a guide to the new alv grid control

Upload: emils

Post on 25-Feb-2018

242 views

Category:

Documents


1 download

TRANSCRIPT

  • 7/25/2019 A Guide to the New ALV Grid Control

    1/17

    A Guide to the New ALV Grid Control Part 1

    Problems with ABAP output and why the ALV Grid Control can help

    In this Blog series I will dive deeply into the ALV Grid Controland elaborate on its advantages in ABAP listprocessing. Lets begin by looking at some problems with Classical list processing

    ithin an !AP system there is a lot o" data that needs to be reviewed# maintained# and interpreted. $o% know whatI&m talking abo%t ' inventory data# controlling data# acco%nting data# employee addresses# and so on and so "orth.(he bigger a company# the greater the amo%nt o" data that needs to be o%tp%t "or review and analysis.

    ithin the conte)t o" certain applications# the terms o%tp%t and list can be synonymo%s. hen I took my very "irstABAP class at !AP *d%cation# I learned that the term list denotes an o%tp%t page that has been created %sing ABAPstatements like +I(*# P,!I(I,-# or ,+/A(# and te)t lines are b%""ered in a list b%""er be"ore a system program

    called the ABAP list processor steps in to per"orm vario%s r%n0time activities. Lists created in this way are o"tenre"erred to as classical lists 1everything in !AP that is okd is lovingly termed Classical2 and represent the standardo%tp%t method o" data.

    I" yo% have dealt with list "ormatting iss%es and3or the %se o" events "or interactive lists# yo% will "ind the "eat%res and"%nctions introd%ced by the newALV Grid Controlwill make yo%r li"e a lot simpler.

    4ranted# the e""ort to create a classical list "or 5%st simple o%tp%t o" data is minimal. B%t amass a "ew lists across a"ew applications# each created by a di""erent developer# and things get a bit more complicated. (he ABAP listprocessor lacks standard baseline list handling "%nctions like sorting# "iltering# and calc%lations# so these types o""%nctions have to be added by hand "or each new list. +esponsibility "or list layo%t and inter"ace design is also le"t tothe developer.

    (his is why yo% "ind di""erent schemes "or list handling and layo%t in di""erent applications. Lack o" standard# baselinelist processing "%nctions means that developers devise their own methods "or common list handling activities s%ch asheadings# sorting# "iltering# rendering s%btotals# and the like. (he res%lt is that end %sers who work with more thanone application may have to deal with di""erent ways to access these simple list "%nctions based on the developerwho coded the sol%tion.

    (he AL6 4rid Control solves this problem. Its %ser inter"ace provides a set o" generic "%nctions 1e.g.# sorting# "iltering2"or handling tab%lar data. It also con"ers the many bene"its o" controls technology to %sers# enabling more operationsby mo%se# and interaction with other controls# s%ch as drag0anddrop. 7evelopers simply pl%g the AL6 4rid Controlinto their applications and the tool takes care o" the rest. $o% do not need to do any "%rther programming to o""er%sers these "%nctions. 8ow yo% pl%g the control into an application is the "irst thing I will show yo% in this month&sblog. !o lets get started9

    ALV Grid Control Baseline Functionality

    (ake a look at the screen shot below: it shows a tab0strip with an AL6 4rid Control and its integrated toolbar# which#thanks to the controls technology# enables mo%se0oriented access to a variety o" list handling "%nctions.

    1

  • 7/25/2019 A Guide to the New ALV Grid Control

    2/17

    Col%mns can be selected and dragged to a di""erent col%mn position. ;sers can invoke "%nctions that re"er to aselected col%mn 1like hide# search# or "ilter2 directly via a conte)t men%. 1(he selection o" col%mns and rows complieswith the /icroso"t standard# which means that %sers can do things like %se the C(+L key to select rows or col%mnsthat are not ad5acent.2

    here the AL6 4rid Control is placed within a !AP 4;I screen is %p to yo%. $o% can# "or e)ample# dock a control to

    an arbitrary side o" a dynpro. (he ABAP orkbench %ses this techni

  • 7/25/2019 A Guide to the New ALV Grid Control

    3/17

    (he %ser can sort the list by one or more col%mns# "ilter entries 1e.g.# display only data o" one day2# and calc%latetotals and s%btotals. ;sers can determine col%mn order and col%mn length to retrieve needed in"ormation in a moreconvenient "ashion. 7evelopers can allow these settings to be saved in a display variant that can be saved as thede"a%lt setting# s%ch that the %ser&s pre"erence "or settings is loaded be"ore the list is displayed. !ome o" the"%nctions made available in the toolbar are there to provide better vis%ali=ation o" lists that either have a lot o"col%mns or a lot o" rows. (he 7etail "%nction# "or e)ample# allows %sers who are working with a list that has a lot o"col%mns to view val%es o" a line in a separate pop0%p window. or lists that are very long# a %ser can calc%lates%btotals# then collapse all s%btotal levels by clicking on the little b%ttons o" the total line. Partic%lar s%btotal lines canbe collapsed or e)panded# too. ;sers will also "ind "%nctions# like the ABC analysis tool# to "acilitate the analysis o"data. (o print a list# the AL6 4rid Control calls the !AP List 6iewer. Alternatively# %sers can e)port a list to /! ord or

    /! *)cel. or those who %s%ally work with *)cel# the AL6 4rid Control o""ers a "%nction to switch between 4rid and*)cel inline display.

    -ow that yo% have seen the standard list handling "%nctions that become available to %sers via the AL6 4rid Control#let&s talk abo%t integrating this control with yo%r applications.

    3

  • 7/25/2019 A Guide to the New ALV Grid Control

    4/17

    Interatin the ALV Grid Control

    hen yo% create lists in the classic way# the ABAP list processor is responsible "or storing# displaying# and managinga single list or m%ltiple lists. ABAP statements are %sed to temporarily store the lists on the application server whilethe program is e)ec%ted# and# with the help o" the list processor# display them on a special container screen.

    In contrast# the AL6 4rid Control %ses the !AP Controls (echnology "or displaying lists. Controls are binary re%sableso"tware components installed on the local PC. 1Please see my blo on !AP Controls "echnoloy2

    (his eliminates the need "or the system to access the application server in order to do something like move col%mnso" a table. Basically# i" yo% %se the Controls (echnology# speci"ic "%nctions are shi"ted "rom the application server1backend2 to the !AP 4;I 1"rontend2.

    Interatin the ALV Grid Control into a !creen

    In order to display the AL6 4rid Control 1or any control# "or that matter2 on a screen# yo% need a container controlinstance. A container control is responsible "or displaying or arranging one or more controls on the screen. orintegrating a control into a screen# yo% have a choice o" the "ollowing "ive di""erent container control types>

    0 CL?4;I?C;!(,/?C,-(AI-*+@ CL?4;I?7,CI-4?C,-(AI-*+@ CL?4;I?!PLI((*+?C,-(AI-*+@ CL?4;I?*A!$?!PLI((*+?C,-(AI-*+@ CL?4;I?7IAL,4B,?C,-(AI-*+

    !ince these container classes can be combined# there is a tremendo%s degree o" "le)ibility "or placing the AL6 4ridControl on the screen.

    (he container control is instantiated %sing the C+*A(* ,B*C(statement# and then linked to an area on thescreen. hen a control that is to be displayed is instantiated# yo% can speci"y the container control as its parent. (hiscreates a close connection between these two controls. It is possible to link the control together with its container

    control to another screen a"terward# which re

  • 7/25/2019 A Guide to the New ALV Grid Control

    5/17

    !o once yo% have generated an instance o" the AL6 4rid Control# integrated it into a screen# and selected the datathat is to be displayed# this one simple callis all that yo% need to provide a list with a set o" generic "%nctions.

    4enerating an instance o" the control and integrating it into a screen is not speci"ic to the AL6 4rid Control. $o% dothis the same way yo% wo%ld any control.

    hat abo%t selecting the data that is to be displayed and passed to the instance together with a description o" the"ieldsD $o% need to %nderstand that displaying data via the AL6 4rid Control re

    P+,4+A/ !I/PL*?AL6?CALL.

    7A(A> ,?C,7* LI* !$0;C,//#4?4+I7 ($P* +* (, CL?4;I?AL6?4+I7#4?C;!(,/?C,-(AI-*+ ($P* +* (, CL?4;I?C;!(,/?C,-(AI-*+#4(?!LI48( ($P* (ABL* , !LI48(. o%tp%t table

    CALL !C+**- EFF.GGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG/,7;L* PAI I-P;(.CA!* ,?C,7*.

    5

  • 7/25/2019 A Guide to the New ALV Grid Control

    6/17

    8*- H*I(&. L*A6* P+,4+A/.*-7CA!*.

    CL*A+ ,?C,7*.*-7/,7;L*.

    /,7;L* PB, ,;(P;(.!*( P0!(A(;! H/AI-EFF.G create controlsI 4?C;!(,/?C,-(AI-*+ I! I-I(IAL. C+*A(* ,B*C( 4?C;!(,/?C,-(AI-*+ *P,+(I-4 C,-(AI-*+?-A/* J H/$C,-(AI-*+&. C+*A(* ,B*C( 4?4+I7 *P,+(I-4 I?PA+*-( J 4?C;!(,/?C,-(AI-*+.G''''''''''G AL6 speci"ic part starts hereG''''''''''G data selection

    !*L*C( G +,/ !LI48( I-(, (ABL* 4(?!LI48(.G display o%tp%t table in AL6 instanceCALL /*(8,7 4?4+I70K!*(?(ABL*?,+?I+!(?7I!PLA$ *P,+(I-4 I?!(+;C(;+*?-A/* J H!LI48(& C8A-4I-4 I(?,;((AB J 4(?!LI48(.*-7I.*-7/,7;L*.

    e start by calling !C+**n EFF. (his calls mod%les PB, and PAI within its "low logic. At PB, time# we de"ine astat%s /AI-EFF to leave the program with "%nction code *I( 1this is nothing b%t classic ABAP dialog programming2.e then create an instance o" the C%stom Container Control and an instance o" the

    AL6 4rid Control. -ote that the latter is connected to the "irst by parameterI?PA+*-(and that the container controlis placed on an area that has been de"ined in the !creen Painter with the name/$C,-(AI-*+. -e)t we pass AL6the target data that is to be displayed in a list o" the "light model

    ,ne last point worth noting is that data selection is well separated "rom the call to display the data. I" this is also thecase "or old reports that %ses the ABAP list processor at yo%r company# it can be easily converted to a report basedon the AL6 4rid Control. (he more the data selection is mingled with commands to display the data# the greater theamo%nt o" e""ort re

  • 7/25/2019 A Guide to the New ALV Grid Control

    7/17

    Con$iurin the ALV Grid Control Instance

    hen we ended the last blog on the ALV Grid ControlI promised that we wo%ld cover some simple e)tensions inthis blog. !o lets begin..

    (he key to con"ig%ring theALV Grid Control"or yo%r partic%lar application is the str%ct%res that are passed by theapplication to an AL6 4rid instance be"ore or d%ring list display. or some simple e)tensions o" yo%r AL6 4ridinstance# yo% only need to set the right parameter and pass the table or str%ct%re by %singmethodset%table%$or%$irst%display&

    ,nce the AL6 4rid control has been integrated on the screen# yo% will likely want to con"ig%re it to do things like>

    0 Calc%late totals initially

    0 8ide col%mns# the toolbar# the grid title# or the col%mn headers

    0 Add# replace# or hide "%nctions "rom the toolbar

    0 +eact to a do%ble0click on a row to show a detail list

    0 Interpret val%es o" a col%mn as icons

    Like it was stated above# (he key to con"ig%ring the AL6 4rid Control "or yo%r partic%lar application is the str%ct%resthat are passed by the application to an AL6 4rid Control instance. Below is a list o" the str%ct%res that can bepassed.

    ," the seven str%ct%re3tables listed above# the "ield catalog is the most important one "or the AL6 4rid Control.

    Let&s take a look at a speci"ic e)ample. Lets say we want to provide a title to o%r AL6 4rid Control. e also wo%ld liketo hide the search capability "rom the standard toolbar so the %ser doesn&t have that ability.

    7

  • 7/25/2019 A Guide to the New ALV Grid Control

    8/17

    , ' let&s grab a code snippet "rom the previo%s BlogA Guide to the New ALV Grid Control Part 1. Look at thebold "ont lines below.

    data: gt_exclude type ui_functions.

    data: gs_exclude type ui_func.

    data: gs_layout type lvc_s_layo.

    gs_exclude = cl_gui_alv_grid=>mc_fc_find.

    append gs_exclude to gt_exclude.

    gs_layout-grid_title = 'My Grid Title'.

    CALL METHOD G_GRID->SET_TABLE_FOR_FIRST_DISPLAY

    EXPORTING I_STRUCTURE_NAME = 'SFLIGHT'

    I_!"#$%T = G_!"#$%T

    IT_T$$!&"_()*!%+I,G = GT_()*!%+(

    CHANGING IT_OUTTAB = GT_SFLIGHT.

    (he str%ct%re gs?e)cl%de o" type %i?"%nc is %sed in the internal table gt?e)cl%de o" type %i?"%nctions. (he g is "or4lobal and s and t are "or str%ct%re and table respectively. (he search "%nction is re"erenced by the class attrib%te/C?C?I-7 o" class CL?4;I?AL6?4+I7. $o% can hide other standard "%nctions or men% b%ttons as well byadding other attrib%tes with pre"i) /C?C? or /C?/B?# respectively.

    e added the title to gs?layo%t0grid?title.

    inally to get these changes to mani"est in o%r AL6 4rid Control# we added I!?LA$,;( J 4!?LA$,;( andI(?(,,LBA+?*CL;7I-4 J 4(?*CL;7* to the call statement "or the method!*(?(ABL*?,+?I+!(?7I!PLA$

    !ettin Properties 'sin the Field Catalo in the ALV Grid Control

    As mentioned earlier# the AL6 determines the o%tp%t "ormat o" val%es %sing the "ield catalog. I" yo% choose to b%ildthe "ield catalog man%ally# yo% need to know which "ields are mandatory.

    Listed below are the re

  • 7/25/2019 A Guide to the New ALV Grid Control

    9/17

    AL6 4rid +e

  • 7/25/2019 A Guide to the New ALV Grid Control

    10/17

    #$%$: ico_co*0123 %45 c.

    #$%$: # o) o*%%$&.

    ,# now lets semi0generate the ield Catalog "or the AL6 4rid Control.

    CALL FUNCTION 'L6C_FIELDCATALOG_MERGE'

    EXPORTING I_STRUCTURE_NAME = 'SFLIGHT'

    CHANGING CT_FIELDCAT = )i#c$%.

    -ow that we have a "ield catalog# lets modi"y entry o" "ield catalog "or the col%mn PLA-*($P* and stop it "romdisplaying on the AL6 4rid Control.

    +$# %$& )i#c$% i%o 7$_)i#c$% 7i%/ 84 )i#$0=9PLANETYPE9.

    i) ,4-,*&+c .

    _i#; = ,4-%$&i;.

    7$_)i#c$%-o_o*% = 'X'.

    0o#i)4 )i#c$% )+o0 7$_)i#c$% i#; _i#;.

    #i).

    -ow lets add an entry to the "ield catalog titled IC,- C,L;/-. (his is where we wo%ld p%t an IC,-. Later in thecode# we will p%t the delete icon at the end o" a data row.

    c$+ 7$_)i#c$%.

    7$_)i#c$%-)i#$0 = 'ICON_COLUMN'.

    7$_)i#c$%-o*%5*% =

  • 7/25/2019 A Guide to the New ALV Grid Control

    11/17

    CHANGING i%_)i#c$%$o( = )i#c$%

    IT_OUTTAB = o*%%$&!".

    !ome "inal tho%ghts..

    !AP developed the AL6 4rid Control %sing a contin%o%s naming convention# which helps yo% to remember str%ct%re

    or table names>

    0 L6C?!? ' str%ct%res

    0 L6C?(? ' tables: "or a table there e)ists a table type and a corresponding line type in the ABAP 7ictionary1e.g.# L6C?!?8$P* is a line type "or table L6C?(?8$P*2

    0 I?G# I!?G# or I(?G ' "or import or changing parameters 1simple type# str%ct%re# or table2 o" methods

    0 *?G# *!?G# or *(?G ' "or e)port parameters 1simple type# str%ct%re# or table2

    In the ne)t blog we will look at adding Application !peci"ic "%nctions like p%sh b%ttons or conte)t men% that providesdi""erent "%nctions to the AL6 4rid Control. e will also e)amine how we can %se Interactive +eporting with the AL64rid Control.

    A Guide to the New ALV Grid Control Part (

    Interatin )our *wn Application+!peci$ic Functions in the ALV Grid Control

    hen we ended the last blog on the ALV Grid ControlI promised that we wo%ld cover adding Application !peci"ic"%nctions like p%sh b%ttons or conte)t men% that provides di""erent "%nctions to theALV Grid Control. I also said wewo%ld learn how we can %se Interactive +eporting with the AL6 4rid Control. !o let&s get started99

    $o% can add the "ollowing 4;I elements to an AL6 4rid instance o" an !AP AL6 Class>

    11

  • 7/25/2019 A Guide to the New ALV Grid Control

    12/17

    0 P%sh b%ttons and men%s in the toolbar

    0 A conte)t men% that provides di""erent "%nctions# depending on the col%mn and row position.

    Adding new 4;I elements to an AL6 4rid instance is event0controlled and re

    #0%/o#.

    0%/o# /$#_0*_&*%%o.

    D)ii%io o) 0*, )o+ #)i# 0* &*%%o, i '/$#_%oo&$+'>

    #0%/o#.

    0%/o# /$#_co%;%_0*.

    D)ii%io o) co%;% ,,i%i? 0*>

    #0%/o#.

    0%/o# /$#_*,+_co00$#.

    12

    http://www.itpsap.com/blog/2012/04/15/sap-controls-technology-part-1/http://www.itpsap.com/blog/2012/04/15/sap-controls-technology-part-1/http://www.itpsap.com/blog/2012/04/15/sap-controls-technology-part-1/http://www.itpsap.com/blog/2012/04/15/sap-controls-technology-part-1/
  • 7/25/2019 A Guide to the New ALV Grid Control

    13/17

    *+4 $55ic$%io ,5ci)ic )*c%io co#,>

    #0%/o#.

    #c$,,.

    !..."

    MODULE PBO OUTPUT.

    IF G_CUSTOM_CONTAINER IS INITIAL.

    +(i,%+ ?%, o &$c8#:

    ,% /$#+ c_?%_+ci?+=>/$#_%oo&$+

    c_?%_+ci?+=>/$#_0*_&*%%o

    c_?%_+ci?+=>/$#_co%;%_0*

    c_?%_+ci?+=>/$#_*,+_co00$#

    c$ 0%/o# ,%_%$&_)o+_)i+,%_#i,5$4>

    ENDIF.

    ENDMODULE.

    (he de"inable 4;I elements are reb%ilt each time the corresponding event is triggered. or this p%rpose# the eventhas the *?,B*C( parameter that contains a re"erence to the toolbar# or the conte)t men%# or the toolbar men%s. Inthe event handler method# yo% can then e)tend or modi"y these ob5ects accordingly. All application0speci"ic "%nctioncodes can then be

  • 7/25/2019 A Guide to the New ALV Grid Control

    14/17

    8ere are some help"%l points to remember

    N hen de"ining elements o" the toolbar# the "ield b%tn?type determines the type o" the 4;I element. or possibleval%es# see type pool C-(B.

    N In the template# the event handler methods are declared as static methods# which means that they belong to allinstances o" the AL6 4rid Control in one internal session. hen one o" these events is raised by one instance# yo%can identi"y this instance by %sing event parameter !*-7*+# which is passed implicitly with every event.

    -ow this is great i" yo% need to add yo%r own c%stom integration. B%t what i" yo% needed to change the behavior o" astandard "%nction deliveredD ell I am glad yo% asked.

    -odi$yin the ALV Grid Control !tandard Functions

    (he standard "%nctions are not designed "or speci"ic applications. !o there may be times when yo% want to tailor ageneric "%nction ' s%ch as sorting by a speci"ic col%mn ' "or more e""icient operation with a speci"ic application.,ne way to do this is to hide the standard "%nction yo% want to modi"y and then add yo%r own implementation. hilethis approach will certainly work# b%t there is a more elegant way. ollow these M easy steps.

    14

  • 7/25/2019 A Guide to the New ALV Grid Control

    15/17

    E. 7e"ine an event handler method "or event B*,+*?;!*+?C,//A-7. (his event is triggered a"ter the %ser hasselected a "%nction. (his means that the AL6 4rid Control passes control to the application be"ore the "%nction ise)ec%ted. ;sing event parameter *?;C,//# yo% can trap and restrict the "%nction code to 5%st the "%nction yo% wantto modi"y.

    . Implement yo%r own code "or the "%nction within the event handler method. In this conte)t# yo% can even call

    methods o" the AL6 4rid Control i" yo% need too.

    M. +eset the "%nction code to ens%re that the standard "%nction is no longer e)ec%ted. $o% can %se code similar to thebelow>

    CALL METHOD i,%$c o) %/ AL6 co%+o>->,%_*,+_co00$#

    ;5o+%i( I_UCOMM = SPACE.

    Let&s end this blog series with a look at how yo% can incorporate the interactive reporting method we all have "ondmemories o" "rom o%r classical reporting days into the AL6 grid control.

    Interacti.e /eportin and the ALV Grid Control

    !o "ar o%r disc%ssions have dealt with "%nctionality provided %sing classical inter"ace elements# s%ch as p%sh b%ttons#toolbar men%s# and the conte)t men%. (here are other interaction "acilities can be integrated into an AL6 4ridinstance. (ake a look at the chart below

    As "ar as the method to integrate these "acilities is concerned# the do%ble0click and the hyperlink "acility obvio%slystand o%t a little bit. (o respond to a do%ble0click# yo% 5%st have to implement an event handler method "or eventdo%ble?click. 8yperlinks do not need any event handling# beca%se the corresponding action is always the same @open a eb browser to show the destination o" a link. (he links have to be de"ined in a table o" type L6C?(?8$P*#which is passed to the AL6 4rid instance %sing method set?table?"or?"irst?display.

    (he way to designate a "acility to all cells o" a single col%mn is controlled by the relevant "ield in the "ield catalog. Inthe case o" hotspots and p%sh b%ttons# yo% m%st set this "ield to or attrib%te cl?g%i?alv?gridJKmc?style?b%tton#

    15

  • 7/25/2019 A Guide to the New ALV Grid Control

    16/17

    respectively. In the case o" hyperlinks and drag0and0drop behaviors# a handle m%st be provided instead. By %sing thishandle# the AL6 4rid Control relates the cells o" that col%mn to a de"ined hyperlink or drag0and0drop behavior.

    B%t what i" yo%r re

  • 7/25/2019 A Guide to the New ALV Grid Control

    17/17

    (he AL6 4rid Control s%pplies a large set o" generic list "%nctions. (hese standard baseline "%nctions obviate theneed "or developers to implement the same code over and over again. As a res%lt# the AL6 4rid Control is %sedthro%gho%t the *CC system and list handling is presented in a %ni"orm way to the %ser. /oreover# the AL6 4ridControl o""ers developers great opport%nities to easily adapt this technology to s%pport application0speci"icre