Chapter 12 - ABAP List Viewer Outputs-Part 1 - SAP ABAP - Hands-On Test Projects With Business Scenarios
Chapter 12 - ABAP List Viewer Outputs-Part 1 - SAP ABAP - Hands-On Test Projects With Business Scenarios
Chapter 12 - ABAP List Viewer Outputs-Part 1 - SAP ABAP - Hands-On Test Projects With Business Scenarios
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
Recent
Topics
Tutorials
NEXT
PREV
Highlights
Chapter 13: ABAP List Viewer
OutputPart 2
CHAPTER12
Settings
Feedback
ABAPListViewerOutputsPart1
Sign Out
Inalloftheprecedingeightchapters(Chapter4toChapter11),you
producedoutputbyusingtheWRITEstatement.Youhavelearnedabout
thefeaturesoftheWRITEstatement,includinginteractivelists.Butthe
outputgeneratedbytheWRITEstatementisstatic.Theendusercannot
manipulatethatoutputanyfurther.
Incontrast,theoutputgeneratedbytheABAPListViewer(ALV)canbe
Settings
10 days left in your trial. Subscribe.
Feedback
manipulatedbyendusers.TheALVgeneratedoutput,calledanALV
report(orsometimescalledanALVgridreport),isclassbased.Inthis
chapterandthenext,youwillusetwoALVreportclasses:
Sign Out
CL_GUI_ALV_GRIDandCL_SALV_TABLE.
TheendusercanmanipulateALVreportsinthefollowingways:
ReorderorshufflethefieldpositionsofALVreports.
OmitordropfieldsfromALVreports.
Reorder,orsortandresortALVreports.
FilterdatabyusingSELECTOPTIONSforanyfieldintheALV
reports.
Generatetotalsandsubtotalsfornumericfields.Theendusercan
Enjoy Safari? Subscribe Today
obtainotheraggregatevaluesoffieldssuchascount,maximum,
minimum,andaverage(onlyfornumericfields).
Groupfields.
GenerategraphsfromALVreports.
Freezefields.
PerformABCanalysis.
SaveandmaintainlayoutsofALVreports.
Youwillgainabetterunderstandingoftheselistedfeaturesasyou
performhandsonexercisesinthischapter.
TheALVreports,liketheoutputfromWRITEstatements,canbe
downloadedtofilesonthepresentationserverinvariousfileformats
suchastext,richtext,Excelspreadsheet,HTML,andXML.TheALV
reports,liketheoutputfromWRITEstatements,canbedownloadedtothe
reportingtreeandSAPofficefolder.TheALVreportsalsocanbe
dispatchedtoaprintspool.
ALVOutputArchitecture
AbriefconsiderationofALVarchitectureisrequiredbeforeyougettothe
nittygrittyofALVclassesandtheirapplication.
GeneratingALVreportsbyusingthebuiltinclasses(especiallytheclass
CL_GUI_ALV_GRID)requiresscreenprogramming.Youwilllearnthe
detailsofscreenprogramminginChapter14.Butyouwillgetapreview
inthischapterinordertounderstandALVreportgeneration.
First,youwillusethebuiltinclassCL_GUI_ALV_GRIDtogenerateALV
reports.Thesereportshavetobelocatedinsidecontainerclasses,and
thesecontainerclasseshavetobepositionedonscreens.Asmentioned
inChapter9,screensintheABAPdevelopmentenvironmentare
identifiedbyfourdigitnumbers.Asyoumayrecall,thedefaultselection
screenisidentifiedasscreennumber1000.Duringthedeclarationof
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
1/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
userdefinedselectionscreens,youspecifiedanumbertodefinethem
(SELECTIONSCREENBEGINOFSCREEN...).
Someofthebuiltincontainerclassesareasfollows:
CL_GUI_CUSTOM_CONTAINER
CL_GUI_DIALOGBOX_CONTAINER
CL_GUI_SPLIT_CONTAINER
CL_GUI_DOCKING_CONTAINER
YouwillusethecontainerclassCL_GUI_CUSTOM_CONTAINERtolocateyour
ALVreport,whichwillusetheclassCL_GUI_ALV_GRID.
ThecontainerclassCL_GUI_CUSTOM_CONTAINERhastobeplacedinsidea
customcontrol.Acustomcontrolisascreenelementthatcanbedragged
fromtheElementpaletteoftheScreenPainterLayoutEditoranddropped
onthescreensurface.Acustomcontrolisareservedphysicalareaonthe
screen,whichallowsruntimeobjectstobelocatedinsideit.
So,tostart,youwillhaveacustomcontrol,whichisareservedphysical
areaonthescreen.Inthiscustomcontrol,youwilllocateaninstanceof
thebuiltinclassCL_GUI_CUSTOM_CONTAINER.Insidetheinstanceofthe
classCL_GUI_CUSTOM_CONTAINER,youwilllocateaninstanceofthebuilt
inclassCL_GUI_ALV_GRID.Finally,youhavetopopulatethisinstanceof
thebuiltinclassCL_GUI_ALV_GRIDwithdatafromaninternaltableby
usingtheinstancemethodSET_TABLE_FOR_FIRST_DISPLAY.This
layeringisrepresentedinFigure121.
Figure121.ArchitectureofALVreportusingclass
CL_GUI_ALV_GRID
Normally,screenprogrammingisemployedtoinputdata.Butinthecase
ofALVreports,screenprogrammingisbeingemployedtooutputdata.
ScreenProgrammingBasics
ThemainconstituentofscreenprogrammingistheScreenPainter.You
accesstheABAPScreenPainterbyusingthetransactioncodeSE51.
ScreensdonotexistindependentofABAPprogramstheyareattachedto
ABAPprograms(justasstatusesareattachedintheMenuPainter).To
create,display,orchangeascreen,youmustenteranABAPprogram
andascreennumberontheopeningscreenoftheScreenPainter.The
ScreenPainterhasthefollowingcomponents:
Attributes
LayoutEditor
ElementList
FlowLogic
Attributes
IntheAttributessection,youhavetospecifythefollowing:
Shortdescriptionofthescreen
Screentype(normalscreen,subscreen,modaldialogbox,or
selectionscreen)
Settings
Otherattributes
Theseareattributesoftheoverallscreen,whicharedifferentfrom
attributesofparticularscreenelements.Otherinformation(forexample,
thedatethescreenwaslastchanged)ismaintainedbythesystem.
Figure122showstheScreenPaintersAttributestab.
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
2/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
Figure122.UsingtheScreenPaintertosetscreenattributes
LayoutEditor
ScreenlayoutismaintainedwithagraphicalornongraphicalLayout
Editor.Inthischapterandthenext,onlythegraphicaleditorisused.
YouopentheLayoutEditorbyclickingthe
buttonontheapplicationtoolbaroftheScreenPainter.Figure123shows
theLayoutEditorwithablankscreen.
Figure123.TheScreenPaintersLayoutEditor
AslongastheLayoutEditorisopen,youcannotusethemainScreen
Painterscreen(thatis,thescreenwiththeFlowLogic,ElementList,and
Attributestabs).
Youcan,however,draganddropelementsfromtheElementpaletteonto
thescreensurface,andyoucanpositionthemonscreenandsizeand
resizethem.
Figure124showsacustomcontrolthathasbeendraggedanddroppedfor
illustrativepurposes.Ifyoudoubleclickthedraggedelement,adialog
boxappears,displayingthatelementsattributes.Thefirstattribute
indicatestheelementsname.
Figure124.PositioningandsizingacustomcontrolintheLayout
Editor
ElementList
AftersavingyourworkintheLayoutEditorandthenclosingit,you
returntotheScreenPainterYoucanthenclicktheElementListtabto
seeanongraphicalrepresentationofthescreen.Alltheelementsthat
youpositionedonscreenintheLayoutEditornowappearasalist,along
withtheirproperties.Inourexample,thecustomcontrolelement
CUST_CONTTappearsasthefirstentryintheelementlist.Thevarious
columnsindicatetheattributesofthatelement.Forinstance,theType
columnspecifiesthetypeofelement(inthiscase,thetypeisCCtrl,
indicatingcustomcontrol).
LineandColspecifythestartingpositionoftheelementintermsofthe
rowandcolumn.Inthisexample,theentries2and3representthe
secondrowandthirdcolumn,respectively.IntheABAPscreen
environment,youworkwithrowsandcolumnsandnotwithphysical
dimensionssuchasmillimeters,centimeters,orinches.
TheDeflgentry(82,inthisexample)indicatestheelementsdefined
lengthincolumns.Vislgindicatesvisiblelengthincolumns(82).Height
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
3/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
indicatestheelementsheight,intermsofrows(18).
Inthisexample,entriesforotherelementattributesareblank.Figure
125showstheelementlist.
Figure125.TheScreenPainterselementlist
Thoughonlyoneelementwasdraggedanddroppedonthescreen,there
aretworowsintheelementlist.Thesecondrowcontainstheelement
OK_CODE,withitsTypelistedasOK.Initially,thisrownamewouldappear
blank,andyoucanassignanynametoanelement.However,inthis
case,thenamehasbeenenteredasOK_CODEbecausethatisthe
convention.ThiselementisrelatedtothesystemfieldSYUCOMM.
OK_CODEisnotanormalscreenelement,inthatitdoesnotoccupyany
screenspace.ItisavariableoftypeCandlength20,thesameasthe
systemfieldSYUCOMM.TheOK_CODEenteredintheelementlistisa
variableonthepresentationserver.
Asyoumayrecall,whenyouareworkingwithselectionscreensand
interactivelistsandyouclickabuttonormakeamenuselection,the
systemfieldSYUCOMMisfilledwiththefunctioncodeofthebuttonor
menuselection.Withintheprogram,youcanthendeterminewhich
buttonwaspressedorwhichmenuselectionwasmadebyinterrogating
thecontentsofSYUCOMMandtakingtheappropriateaction.Inthescreen
programmingenvironment(andespeciallyinamultiplescreen
programmingenvironment),theconventionistonotusethesystemfield
SYUCOMMdirectly.Instead,theruntimesystemofthescreenprocessor
automaticallytransfersthecontentsofthesystemfieldSYUCOMMintothe
variableyouenterintheelementlistentryasanelementoftypeOK.
CorrespondingtotheOK_CODEvariableonthepresentationserverside,
thereshouldbeanOK_CODEvariableontheapplicationserverside(that
is,theABAPprogramtowhichthescreenisattached).Soyouneedto
declareinthatABAPprogramavariablethatisidenticalinnameandof
thetypeOK,asspecifiedintheelementlist.Byconvention,thisis
OK_CODE.InthePAIevent,thecontentsofOK_CODEoftheelementlist
(presentationserver)aretransferredtothefieldOK_CODEdeclaredinthe
program(applicationserver).Datatransferstoandfromthe
presentationservertotheapplicationserveraredescribedinChapter14.
FlowLogic
Inthescreenprogrammingenvironment,therearetwomainevents:
PROCESSAFTERINPUT(PAI)andPROCESSBEFOREOUTPUT(PBO).These
eventscanbeviewedasanalogoustotheselectionscreeneventsAT
SELECTIONSCREENandATSELECTIONSCREENOUTPUT.
RecallthatthefollowingactionstriggertheselectionscreeneventAT
SELECTIONSCREEN:
PressingtheEnterkey
Clickingaselectionscreenpushbutton
Clickingaselectionscreenradiobutton(withaUSERCOMMAND
clausefortheradiobuttongroup)
ClickingaselectionscreencheckboxwithaUSERCOMMANDclause
Clickingabuttonontheapplicationtoolbarorstandardtoolbar,or
makingamenuselection
ThePAIeventisalsotriggeredunderidenticalcircumstances.
TheselectionscreeneventATSELECTIONSCREENOUTPUTistriggeredin
twosituations:
Once,beforetheselectionscreenappearstotheuserforthefirst
timebetweentheuserpressingtheexecutebuttonandthe
appearanceofthescreen,followingtheeventINITIALIZATION
FollowingtheeventATSELECTIONSCREEN
ThePBOeventistriggeredinanidenticalmanner.PBOistriggeredin
twosituations:
Once,beforethescreenappearstotheuserforthefirsttime.
EverytimethePAIeventistriggered,itisfollowedbythe
triggeringoftheeventPBO.
YoucanchangetheelementsattributesorpropertiesinthePBOeventby
manipulatingtheinternaltableSCREEN,inwhichthesystemmaintains
theattributesofthescreenelements(LOOPATSCREEN,andsoforth).The
FlowLogicareaoftheScreenPaintersupportsonlyafewofthestandard
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
4/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
ABAPstatementsandsomespecialstatementsofitsown.TheFlowLogic
tabisshowninFigure126.
Figure126.ScreenPaintersFlowLogictab
IntheFlowLogicarea,thefirsttwolinescontainthekeyphrasePROCESS
BEFOREOUTPUT(PBO)followedbyacomment.Next,thekeyphrase
PROCESSAFTERINPUT(PAI),followedbyacommentedline,appearas
thebottomtwolines.
WheneverthePBOeventistriggered,controljumpstothestatement
followingthekeyphrasePROCESSBEFOREOUTPUT.InthePBOevent,you
would,forexample,liketochangesomepropertiesofsomeelements
(thatis,executethecodeforit).ThisisdonethroughtheABAPstatement
MODULE.TheMODULEstatementofflowlogicisnotacceptedinthenormal
ABAPprogram.ItisacceptableonlyintheFlowLogicareaoftheScreen
Painter.Itoperatesinamannersimilartoasubroutineinvocation
(PERFORM),exceptthatthereisnoparameterorinterfaceconcept.The
syntaxofasimpleMODULEstatementisasfollows:
MODULE<modulename>.
Suchastatementwillmakethecontroljumptoastatementfollowingthe
statementMODULE<modulename>OUTPUTinthemainABAPprogramor
anincludeprogram.TheMODULE<modulename>OUTPUTstatementin
anABAPprogramissimilartothesubroutineFORMstatement.Justasa
subroutineisexitedwithanENDFORMstatement,aMODULE<module
name>OUTPUTstatementinanABAPprogramisexitedwithan
ENDMODULEstatement.Anycodetobeexecutedmustbelocatedbetween
thestatementsMODULE<modulename>OUTPUTandENDMODULE.
Tosumup,theMODULE<modulename>statementislikeaPERFORM
statementandisallowedonlyintheFlowLogicareaoftheScreen
Painter.Thestatementmakesthecontroljumptothemodulelocatedin
anABAPprogram,executesthecodelinesbetweenMODULE<module
name>OUTPUTandENDMODULEstatementsintheABAPprogram,andthen
returns.
Similarly,whenthePAIeventistriggered,controljumpstothe
statementfollowingthekeyphrasePROCESSAFTERINPUT.InthePAI
event,youcheckthecontentsofthesystemfieldSYUCOMM(thatis,the
variableOK_CODE).Abasicfunctionyouwillperformisexitingthe
program,asshownhere:
CASEOK_CODE.
WHEN'EXIT'.
LEAVEPROGRAM.
...
ENDCASE.
Again,thisisimplementedthroughtheMODULE<modulename>
statementinPAIoftheFlowLogicarea.IntheABAPprogram,youlocate
theprecedingstatementsbetweenthestatementsMODULE<module
name>INPUTandENDMODULE.
Figure127showsthestructureofcodeforPBOandPAIintheFlowLogic
area.
Figure127.PBOandPAImodules
ThemodulestatementsfollowingthekeyphrasePROCESSBEFORE
OUTPUTarecalledPBOmodules,andthemodulestatementsfollowingthe
keyphrasePROCESSAFTERINPUTarecalledPAImodules.
YoucanexecuteanynumberofPBOandPAImoduleswiththestatements
MODULE<modulename>,dependingonyourrequirements.
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
5/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
Nowthatyouvehadabriefintroductiontoscreenprogramming,youre
readytocontinuewiththischaptersmaintopicofALVoutput.
TheClassesCL_GUI_CUSTOM_CONTAINERand
CL_GUI_ALV_GRID
YouwillbeusingtheCL_GUI_CUSTOM_CONTAINERandCL_GUI_ALV_GRID
classesinthehandsonexerciseslaterinthischapter.Soletsviewthe
relevantmethodsandparametersofthesemethodsintheClassBuilder.
CL_GUI_CUSTOM_CONTAINER
Laterinthischapter,youwilluseaninstanceofthe
CL_GUI_CUSTOM_CONTAINERclasstolocateyourALVreport.Youwillnot
beusinganyothermethodofthisclassotherthanCONSTRUCTORtocreate
aninstanceofthisclass.
Followthesestepsto[dowhat?]:
1. NavigatetotheClassBuilderopeningscreen(viatransactioncode
SE24).
2. Enterthenameoftheclass,CL_GUI_CUSTOM_CONTAINER.
3. ClickthedisplaybuttonorpressthefunctionkeyF7.Thescreenin
Figure128appears.
Figure128.TheclassCL_GUI_CUSTOM_CONTAINER
4. YouhavetolocatetheCONSTRUCTORmethodintheclass,soclickthe
Findbutton,asshowninFigure128.Apopupdialogboxappears,
promptingyoufortheFindstring.
5. EnterthewordCONSTRUCTOR,asshowninFigure129.
Figure129.Findingamethodoftheclass
CL_GUI_CUSTOM_CONTAINER
6. IfitdoesnotlocatetheCONSTRUCTORmethod,butstopsatalocation
wherethestringCONSTRUCTORisoccurring,clicktheFindNext
buttonuntiltheCONSTRUCTORmethodislocated.Whenthemethod
islocated,thescreenwilllooklikeFigure1210.
Figure1210.TheCONSTRUCTORmethodofthe
CL_GUI_CUSTOM_CONTAINERclass
7. ClicktheParametersbutton,andFigure1211appears.
Figure1211.ParametersoftheCONSTRUCTORmethod
8. Thereisonlyonemandatoryparameter:CONTAINER_NAME.To
createaninstanceofthisclass,CL_GUI_CUSTOM_CONTAINER,you
needtoprovidethenameofacustomcontrolforthisparameter.
Theinstancewillbeplacedinthecustomcontrolspecified.
ThatisallthereistotheclassCL_GUI_CUSTOM_CONTAINER.
CL_GUI_ALV_GRID
Youneedtolookuptwomethodsofthisclass:CONSTRUCTORand
SET_TABLE_FOR_FIRST_DISPLAY.Followthesesteps:
9. NavigatetotheClassBuilderopeningscreenandenterthename
oftheclass:CL_GUI_ALV_GRID.
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
6/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
10. ClickthedisplaybuttonorpressF7toaccessthescreenshownin
Figure1212.LocatetheCONSTRUCTORmethod,asdescribedforthe
precedingclass.
Figure1212.LocatingtheCONSTRUCTORmethodofthe
CL_GUI_ALV_GRIDclass
11. ClicktheParametersbuttontodisplaytheparametersofthe
CONSTRUCTORmethod,showninFigure1213.
Figure1213.ParametersoftheCONSTRUCTORmethod
Onlyoneparameter,I_PARENT,ismandatory.Theobject
referencevariableoftheinstanceofCL_GUI_CUSTOM_CONTAINERis
tobeprovidedtothisI_PARENTparameter.
12. ClicktheMethodsbuttontoreturntothemethodslist.Scrolltothe
topofthelisttofindthemethodSET_TABLE_FOR_FIRST_DISPLAY.
Thismethodwillbeusedtopopulatetheinstanceoftheclass
CL_GUI_ALV_GRIDwithdatafromaninternaltable.Figure1214
showsthelocationofthemethod.
Figure1214.Locatingthemethod
SET_TABLE_FOR_FIRST_DISPLAY
13. ClicktheParametersbutton,andthescreenshowninFigure1215
appears.
Figure1215.Parametersofthemethod
SET_TABLE_FOR_FIRST_DISPLAY
Thismethodhasonemandatoryparameter,IT_OUTTAB(achanging
parameter),forprovidingthedatatobeoutputthroughaninternal
table.
Fortheoutputtoappear,themethod,attheleast,requiresone
moreparameter.Itcouldbeeithertheimportingparameter
I_STRUCTURE_NAMEorthechangingparameterIT_FIELDCATALOG.
IfyouprovidetheimportingparameterI_STRUCTURE_NAME,you
cannotmanipulatetheoutputfieldpropertiesintheprogram.If
youprovidethechangingparameterIT_FIELDCATALOG,youcan
manipulatethem.
Forthefirsthandsonexerciselaterinthischapter,youwill
providetheimportingparameterI_STRUCTURE_NAME.Thevalue
providedtothisimportingparameteriscommonlyaDDIC
structure.TheoutputwillbeasperthefieldsintheDDICstructure
andnotasperthefieldsinthestructureoftheinternaltable
providedtothechangingparameterIT_OUTTAB.Ideally,these
structuresshouldbeidentical.ThefieldsintheDDICstructuremay
belessthanthefieldsinthestructureoftheinternaltableprovided
tothechangingparameterIT_OUTTAB.Thefieldtitles,output
lengths,andsoforth,arederived(pickedup)fromdataelements
anddomainsassociatedwiththefieldsoftheDDICstructure.
YouwillprovidethechangingparameterFIELD_CATALOGinthe
subsequenthandsonexercises.Thisparameterenablesyouto
controltheoutputfieldattributesintheprogram.Whenyou
performthehandsonexerciseprovidingthechangingparameter
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
7/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
FIELD_CATALOG,therewillbemoredetailedcoverage.
Youwillusefourmoreparametersofthemethod
SET_TABLE_FOR_FIRST_DISPLAYinthefollowinghandson
exercises.
ALVMiscellaneousTopics
YouwillbeusingtheclassCL_GUI_ALV_GRIDallthroughthischapterand
theclassCL_SALV_TABLEinthenextchaptertoproduceALVoutput.
AninternaltablepassedtotheformalparameterIT_OUTTABisa
changingparameter.ThoughtheALVisanoutput,youcanchangethe
displayeddataonthescreen,whichwillchangethedatainthe
underlyinginternaltablepassedtoIT_OUTTAB.AnALVcanactasoutput
aswellasinputifyouareusingtheclassCL_GUI_ALV_GRID.Ifyouare
usingtheclassCL_SALV_TABLE,youcannotusetheALVtoinput.
ThefieldcatalogparameterisalsoachangingparameterasanALV
outputlayoutcanbechanged,thefieldcatalogwillchange.
TheinputaspectofALVwhenusingtheclassCL_GUI_ALV_GRIDisnot
covered.ThedraganddropaspectsofALVarenotcovered.The
selectionaspects(selectionofALVrows,columns,andcells)arealsonot
covered.ThesearelessfrequentlyusedfeaturesofALV.
MoredetailsaboutALVdocumentationarepresentedintheresource
sectionofthisbook.
TheALVoutputgeneratedbytheclassCL_GUI_ALV_GRIDhasathree
dimensionalvisualeffectandisoftenreferredtoasanALVgrid.
Loosely,ALVoutputisreferredtoasanALVgrid.Whenyouusetheclass
CL_SALV_TABLE,thereisanoptiontogeneratefullscreenALVoutput
withtwodimensionalvisualeffects,whichisreferredtoasanALVlistor
ALVclassicallist.
HandsonExercise:CustomerwiseSalesSummaryofa
SpecifiedCompanyCodeasALVOutput:UseClass
CL_GUI_ALV_GRID
ParametersforthemethodSET_TABLE_FOR_FIRST_DISPLAY:
Importingparameter:I_STRUCTURE_NAME
Changingparameter:IT_OUTTAB
Inthisexercise,youwilldothefollowing:
1. Decidetheinitialoutputlayoutandinput(databaseview).
2. Performallthedevelopmentaltaskstocreatevariousobjectsi.e.
DDICstructure,menupainterinterface,ABAPprogram,screen
etc.
3. Executetheprogramtoproducetheoutput.
4. ChangetheALVoutputlayoutinvariouswaysasanenduserwill.
5. PerformABCanalysisandproducegraphicsfromtheALVoutput.
InitialOutputLayout
ThisisthesamereportthatyougeneratedinChapter6andextendedin
subsequentchapters.YouwillnowgenerateitbyusingtheALVclass
CL_GUI_ALV_GRID.YoumustlocateaninstanceofthisALVclassinan
instanceofthecontainerclassCL_GUI_CUSTOM_CONTAINER.Theinstance
ofthiscontainerclasshastobeplacedinacustomcontrolonthescreen.
Thisarchitecturewasdescribedearlier,inFigure121.
Table121indicatesthefieldstoappearinthereportandtheir
originatingtables.
Table121.FieldstoAppearintheALVReport
Field
Table
Description
KUNNR
KNA1
Customercode
NAME1
KNA1
Customername
ORT01
KNA1
City
NETWR
VBRK
TotalofconvertedNETWRforthecustomer
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
8/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
YouusedthedatabaseviewYCL_CH05_VBRKKNAtoretrievedata.Youused
theCOLLECTstatementtogeneratecustomerwisesummarizeddatainan
internaltable.Withthisinternaltableofsummarizeddata,yousetupa
LOOP...ENDLOOPconstructtooutputwiththeWRITEstatement.Thislast
stageofLOOP...ENDLOOPhastochange.Nowyouwanttooutputthe
summarizedinternaltabledataasanALVreport.Aroughlayoutofthe
proposedALVreportisshowninFigure1216.
Figure1216.Roughlayoutofcustomerwisesalesofspecified
companycodeasanALVreport
Theprogramwillacceptthecompanycodeforwhichacustomerwise
salessummaryistobegeneratedthroughtheselectionscreen
PARAMETERSstatement.
Thewindowtitleoftheoutputwillcarrythecompanycode,companycode
text,andcurrency.YouwillimpartthewindowtitlethroughtheTitles
featureoftheMenuPainter.ThepageheaderandfooterfortheALV
outputarenotcovered.
Youwillplaceasinglebuttonontheapplicationtoolbarfornavigating
fromtheALVoutputbacktotheselectionscreenandpromptingforthe
companycodeforwhichthecustomersalessummaryistobeoutput.You
willcreateastatusintheMenuPainter.
TheALVoutputwillhaveitsowntoolbar,distinctfromthestandardand
applicationtoolbars.TheALVoutputtoolbarenablesthemanipulationof
theALVoutput.
Thefieldorcolumnheadingswillautomaticallyoutput,basedonthe
Headingtextfromthefieldorcolumnassociateddataelement.
PerformingTasksforALVOutput
YouhavetoperformthefollowingtaskstogenerateALVoutput:
1. CreateanewDDICstructureconsistingonlyoffieldsthatwill
appearintheALVoutput.
IfyouhaveaDDICdatatypeCURRfieldinthestructureofthe
internaltablethatyouwillpasstothechangingformalparameter
IT_OUTTABofthemethodSET_TABLE_FOR_FIRST_DISPLAY,itwill
insistthataDDICdatatypeCUKYfieldbespecified.Inyour
scenario,youareconvertingindividualbillingdocumentamounts
indifferentcurrenciestoasinglecurrencyofthecompanycodefor
whichthesalessummaryisbeinggenerated.Thecurrencycodehas
toappearinthewindowtitle,notinthereportbody.Besides,inthe
ALVoutput,whenyougeneratetotalsandsubtotals,theALV
systemautomaticallygeneratescurrencywisetotalsandsubtotals.
Toavoidtheseissues,thefieldNETWRshouldnotbeDDICdatatype
CURRinthestructure.SoyoucopythedataelementNETWRinto
YCL_CH12_NETWR,towhichyouhaveassignedthepreexisting
domainDEC15_2,whichisofDDICdatatypeDECandlength15,2.
YoucopiedfromdataelementNETWRtogetthetexts.
Figure1217showstheactivatedDDICstructure
YCL_CH12_SALES_SUM_STRU.
Figure1217.DDICstructureYCL_CH12_SALES_SUM_STRU
Thisstructureconsistsonlyoffieldsappearingintheoutput(thatis,
KUNNR,NAME1,ORT01,andNETWR).
2. CreateanABAPprogramYCL_CH12_01_SIMPLE_ALV,intowhich
youcancopylinesfromyourChapter6programYCL_CH06_ITAB05,
excludingthelinesstartingfromLOOPATSALES_TABINTO
SALES_STRU.SavetheABAPprogram.
3. IntheMenuPainter(SE41),createastatusSTAT1withjustone
Backbutton,asshowninFigure1218.
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
9/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
Figure1218.InterfaceofYCL_CH12_01_SIMPLE_ALVwith
statusSTAT1
4. Inthisinterface,createawindowtitleTITLE1bynavigatingfrom
thestatus,asshowninFigure1219.
Figure1219.Navigatingtothetitlelist
ThescreenshowninFigure1220appears.
Figure1220.Thetitlelistfortheinterface
YCL_CH12_01_SIMPLE_ALV
5. ClicktheCreatebutton.EnterthenameofthetitleasTITLE1.
EnterthetextasCustomerWiseSalesSummaryCompany
Code:&1/&2Curr:&3.Save,performaconsistencycheck,and
activatetheinterface.ThescreenwilllooklikethatinFigure1221.
Figure1221.AddingTITLE1tothetitlelist
6. Youneedtworeferencevariablestorefertoaninstanceofthe
customcontainerandaninstanceoftheALVgrid,respectively.
YoualsoneedtodeclaretheOK_CODEvariable.InyourABAP
program,makethefollowingdatadeclarations:
DATA:
......
OK_CODETYPESYUCOMM,
CCONTRTYPEREFTOCL_GUI_CUSTOM_CONTAINER,
ALV_GRIDTYPEREFTOCL_GUI_ALV_GRID.
7. Youhavetocreateascreen,placeacustomcontrolonthescreen,
createPBOandPAImodules,andsoforth.NavigatetotheScreen
Painter(viatransactioncodeSE51).Entertheprogramnameas
YCL_CH12_01_SIMPLE_ALVandthescreennumberas100,asshown
inFigure1222.
Figure1222.CreatingprogramYCL_CH12_01_SIMPLE_ALV
onscreen100
8. ClicktheCreatebuttonorpressF5.Inthescreenattributes,entera
shortdescription,asshowninFigure1223.
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
10/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
Figure1223.Addingscreenattributes
9. ClicktheLayoutbutton.Dragthecustomcontrolelementfromthe
Elementpalette.ThescreenlookslikeFigure1224.
Figure1224.Dragginganddroppingacustomcontrol
10. Stretchandsizethecustomcontrol,andthendoubleclickitto
accesstheElementAttributesdialogbox.Enterthenameofthe
customcontrolasCUST_CONTT.Saveyourwork.Thescreenlooks
likeFigure1225.
Figure1225.NamingthecustomcontrolintheElement
Attributesdialogbox
11. ClosetheLayoutEditor.ClicktheElementListtab.EnterOK_CODE
intherowwithtypeOK.ThescreeninFigure1226appears.
Figure1226.Addingtotheelementlist
12. ClicktheFlowLogictab.YouhavetocreatethePBOandPAI
modules.RemovethecommentsofthePBOandPAImodule
invokingstatements.Youcanretainthemodulenamesproposed
bythesystemorchangeandspecifyyourown.Inthisexample,
accepttheproposednames(thatis,STATUS_0100and
USER_COMMAND_0100).TheFlowLogictabafterremoving
commentsforthemoduleinvokingstatementsisshowninFigure
1227.
Figure1227.RemovingstatementsfromtheFlowLogictab
InthePBOmodule,youwillsetthestatus.Youalsowillsetthe
windowtitle,createaninstanceoftheCL_GUI_CUSTOM_CONTAINER
andaninstanceoftheCL_GUI_ALV_GRID,andcallthemethod
SET_TABLE_FOR_FIRST_DISPLAY.
YouwilllocatethePBOandPAImodulesinyourprogram
YCL_CH12_01_SIMPLE_ALV(mainprogram).Thereisanoptionto
locatemodule/sinseparateincludeprograms.Therearemultiple
waystocreatethecodeformodules.Youwilladoptthemethodof
doubleclickingthemoduleinvocationstatementsintheFlow
Logicarea.Asthemodulesdonotexist,thesystempromptswitha
messagesuchasPBOModuleSTATUS_0100doesnotexist.
CreateObject?ClicktheYesbutton.Thesystemthenprompts
further,whethertolocatethemoduleinthemainprogramoran
includeprogram.Optforthemoduletobelocatedinthemain
program(YCL_CH12_01_SIMPLE_ALV).Youshouldensurethatthis
programisnotopenineditorchangemode.
DoubleclickthePBOmoduleinvokingstatementMODULE
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
11/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
STATUS_0100.ThesuccessivescreensareshowninFigure1228
andFigure1229.
Figure1228.CreatingthePBOmodule
Figure1229.Locatingthemoduleinthemainprogram
YouhavetolocateyourcodebetweenthelinesMODULE
STATUS_0100OUTPUTandENDMODULE,asshowninFigure1230.
Figure1230.Changingthemodulecode
Removethecommentsfromthetwolines,andchangethemas
follows:
SETPFSTATUS'STAT1'.
SETTITLEBAR'TITLE1'WITHCCODEBUTXTWAERS.
Next,youhavetocreateaninstanceoftheclass
CL_GUI_CUSTOMER_CONTAINER.YoucouldusethePatternbuttonto
generatetemplatecodeforcreatinganinstance.Figure1231
showsthedialogboxwithenteredvaluesforgeneratingtemplate
codetocreateaninstanceofaglobalclass.
Figure1231.Creatinganinstanceoftheclass
CL_GUI_CUSTOM_CONTAINER
Thegenerated,refinedcode(alllinesforoptionalparameters
deleted)isasfollows:
CREATEOBJECTCCONTR
EXPORTING
CONTAINER_NAME='CUST_CONTT'
EXCEPTIONS
CNTL_ERROR=1
CNTL_SYSTEM_ERROR=2
CREATE_ERROR=3
LIFETIME_ERROR=4
LIFETIME_DYNPRO_DYNPRO_LINK=5
others=6
.
IFSYSUBRC<>0.
MESSAGEIDSYMSGIDTYPESYMSGTYNUMBERSYMSGNO
WITHSYMSGV1SYMSGV2SYMSGV3SYMSGV4.
ENDIF.
Similarly,tocreateaninstanceoftheclassCL_GUI_ALV_GRID,use
thevaluesshowninFigure1232.
Figure1232.Creatinganinstanceoftheclass
CL_GUI_ALV_GRID
Thegenerated,refinedcode(alllinesforoptionalparameters
deleted)isasfollows:
CREATEOBJECTALV_GRID
EXPORTING
I_PARENT=CCONTR
EXCEPTIONS
ERROR_CNTL_CREATE=1
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
12/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
ERROR_CNTL_INIT=2
ERROR_CNTL_LINK=3
ERROR_DP_CREATE=4
others=5
.
IFSYSUBRC<>0.
MESSAGEIDSYMSGIDTYPESYMSGTYNUMBERSYMSGNO
WITHSYMSGV1SYMSGV2SYMSGV3SYMSGV4.
ENDIF.
TocalltheinstancemethodSET_TABLE_FOR_FIRST_DISPLAY,set
thevaluesshowninFigure1233.
Figure1233.Callingthemethod
SET_TABLE_FOR_FIRST_DISPLAY
Thegenerated,refinedcode(alllinesforoptionalparameters
deleted)isasfollows:
CALLMETHODALV_GRID>SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_STRUCTURE_NAME='YCL_CH12_SALES_SUM_STRU'
CHANGING
IT_OUTTAB=SALES_TAB
EXCEPTIONS
INVALID_PARAMETER_COMBINATION=1
PROGRAM_ERROR=2
TOO_MANY_LINES=3
others=4
.
IFSYSUBRC<>0.
MESSAGEIDSYMSGIDTYPESYMSGTYNUMBERSYMSGNO
WITHSYMSGV1SYMSGV2SYMSGV3SYMSGV4.
ENDIF.
YourcodinginthePBOmoduleisover.Tosummarize,yousetup
thestatus,setthewindowtitle,createdaninstanceofthecustom
container,createdaninstanceofALVgrid,calledtheinstance
methodSET_TABLE_FOR_FIRST_DISPLAY,savedtheprogram,and
clickedtheBackbuttontoreturntotheScreenPaintersFlowLogic
area.
YouhavetocreateaPAImodule.DoubleclickthePAImodule
invokingstatement,MODULEUSER_COMMAND_0100.Thesystemwill
promptwithamessagesuchasPAIModule
USER_COMMAND_0100doesnotexist.CreateObject?Clickthe
Yesbutton.Thesystemthenpromptsfurther,whethertolocatethe
moduleinthemainprogramoranincludeprogram.Optforthe
moduletobelocatedinmainprogram.Asyouarelocatingthe
modulesintheprogramYCL_CH12_01_SIMPLE_ALV(themain
program),youshouldensurethatthisprogramisnotopenineditor
changemode.
ThesuccessivescreenslooklikeFigure1234andFigure1235.
Figure1234.CreatingthePAImodule
Figure1235.LocatingthePAImoduleinthemainscreen
EnterthefollowingcodeinthePAImodule:
*&*
*&ModuleUSER_COMMAND_0100INPUT
*&*
*text
**
MODULEUSER_COMMAND_0100INPUT.
IFOK_CODE='BACK'.
SETSCREEN0.
LEAVESCREEN.
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
13/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
ENDIF.
ENDMODULE."USER_COMMAND_0100INPUT
ThestatementsSETSCREEN0andLEAVESCREENwillmakethe
programexitscreen100anddisplaythepromptforcompanycode.
SavetheprogramandthenreturntotheScreenPainterbyclicking
theBackbutton.YouhavecompletedalltasksintheScreen
Painter.Performaconsistencycheckandactivatescreen100in
theScreenPainter.Thescreenafteractivationshouldlooklike
Figure1236.
Figure1236.Theactivatedscreen100
13. GobacktotheABAPprogramYCL_CH12_01_SIMPLE_ALVandopen
itineditmode.Youneedtoaddastatementtoloadscreen100.
Youcanpositionthisstatementasthelaststatementintheevent
STARTOFSELECTION.Inthisevent,youfirstretrievethedatafrom
thedatabasetableT001SELECTSINGLE.Nextyouhavetoseta
SELECT...ENDSELECTconstructwithaCOLLECTstatement.This
producestheinternaltablewithcustomerwisesummarizeddata
fortheinputcompanycode.FollowingtheENDSELECTstatement,
youcodetheSORTstatementtoorderthedatacustomercodewise
ascending.YouarecodingthestatementCALLSCREEN100after
theSORTstatementtoloadscreen100.
Theprogramflowisasfollows:
Whentheprogramisexecuted(viathefunctionkeyF8),thepromptto
inputcompanycodeappears.
1. EnteringthecompanycodeandclickingtheExecutebuttonor
pressingF8startsexecutionofthestatementsfollowingtheSTART
OFSELECTIONevent.DatafromdatabasetableT001isretrieved.
Thecustomerwisesummarizedsalesinternaltableiscreated.The
internaltableissortedonKUNNRascending.ThestatementCALL
SCREEN100isexecuted.
2. TheCALLSCREEN100statementtriggersthePBOevent.The
moduleSTATUS_0100isexecuted.Aninstanceofthecustomer
containeriscreatedaninstanceoftheALVgridiscreated.The
methodSET_TABLE_FOR_FIRST_DISPLAYpopulatestheinstanceof
theALVgridwiththecustomerwisesummarizedsalesdataofthe
internaltable,andtheALVoutputappearsonthescreen.
3. ClickingtheBackbuttonontheapplicationtoolbartriggersPAI,
andthePAImoduleUSER_COMMAND_0100executes.Thecodeinthe
PAImodulebringsyoubacktothecompanycodeprompt.
TheentirecodeoftheprogramYCL_CH12_01_SIMPLE_ALVisavailablein
thesourcecoderesource.TheoutputlookslikethatinFigure1237.
Figure1237.OutputoftheprogramYCL_CH12_01_SIMPLE_ALV
ClickingthebuttonsoftheALVoutputtoolbardoesnottriggerthePAI
event.ClickingtheALVoutputtoolbarbuttontriggerstheclassevent
USER_COMMAND.Incomplexprogramming,therecouldbeaconflict
betweenthePAIeventandtheeventstriggeredbyclasses.TheControl
FrameWork(CFW)providesguidelinestoresolvetheseconflicts.
Thewayyouhaveconfiguredthisprogram,thePBOeventistriggered
onlyonceaftertheExecutebuttonisclickedortheF8keyispressedon
theselectionscreenandbeforethescreennumber100appearswiththe
ALVreport.WhentheALVreportappears,youhaveonlyonebuttonon
theapplicationtoolbar,whichwhenclickedwilltakeyoubacktothe
selectionscreen.
ChangingLayout
ClicktheChangeLayoutbuttonontheALVtoolbar(thethirdbuttonfrom
theright).Adialogboxwithfivetabsappears,asshowninFigure1238.
Figure1238.Shufflingoromittingfields
Youareonthefirsttab,DisplayedColu.Fieldsorcolumnsyouwantto
omitfromtheoutputcanbeshiftedfromtheleftsidetotherightside.By
shiftingfieldsorcolumnstotherightandthentotheleft,youcan
rearrangetheorderofthefieldsorcolumnsintheoutput.Figure1239
showsthisshufflingcompleted.
Figure1239.Shuffledfields
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
14/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
Figure1240showstheALVoutputwiththefieldsshuffled.
Figure1240.Outputwithshuffledfields
ClicktheChangeLayoutbuttonagain.ThenclicktheSortOrdertab.The
fieldsyouwanttosortonshouldbeshiftedfromrighttoleft.Ifyouwant
theoutputtoappearnamewiseascending,youshifttheNAME1fieldfrom
righttoleftandenabletheradiobuttonforascendingorder.Bydefault,
thedescendingradiobuttonisenabled.Figure1241showstheSortOrder
tab.
Figure1241.Settingupthesortcriteria
Figure1242showstheoutputwiththesortsetting.
Figure1242.OuputofprogramYCL_CH12_01_SIMPLE_ALVwith
fieldsshuffledandsortsetup
ThesortinghasbeenperformedontheNAME1contentstranslatedto
uppercase.HenceAircraftProductsappearsbeforeALANFAITH.Thatis
howitis.IfyouusetheChangeLayoutdialogboxtosetthesortingof
fields,thesortingfortextfieldsisbeingperformedonthetexttranslated
touppercase.Butifyouselectafield(singlefieldsorting)andthesort
buttons
,thesortingisaspercharacter(nonUnicode:ASCII)code
order.Ananomaly!
ClicktheChangeLayoutbuttonagain.OmitthefieldCustomer(customer
codeorKUNNR).Figure1243showstheomittedfield.
Figure1243.OmittingtheCustomerfield
Figure1244showstheoutputasperthesettings.
Figure1244.OutputofprogramYCL_CH12_01_SIMPLE_ALV,with
fieldsShuffled,sorted,andtheCustomerfieldomitted
Changetheoriginallayout(thelayoutprevailingwhenyouclickthe
Executebuttonontheselectionscreen)perthefollowingspecifications:
Fieldorder:
City(ORT01)
Customer(KUNNR)
Name1(NAME1)
NetValue(NETWR)
Total:NetValue
Sorting:
Sort:City(Ascending)
Group:City(Subtotals)
Filterfields/columns:
Filtervaluesforcity:A*,B*,C*,M*,S*,T*(citiesstarting
withA,B,C,M,S,andT)
NetValue:>=500
Figures1245through1250depictthestepsforcarryingouttheselayout
changes.
Figure1245.Changinglayoutoffields
Figure1246.Settingsortcriteria
Figure1247.Filteringthefields
Figure1248.ProgramYCL_CH12_01_SIMPLE_ALV:Change
LayoutFilterFieldsSELECTOPTIONS
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
15/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
Figure1249.Settingcityvalues
Figure1250.Settingnetvalue
Theoutputoftheprecedingstepsasperthelayoutsettingsisshownin
Figure1251andFigure1252.
Figure1251.Resultingoutputforprogram
YCL_CH12_01_SIMPLE_ALV
Figure1252.ProgramYCL_CH12_01_SIMPLE_ALV:Outputas
perLayoutSettingsincludingtheTotal
Observethatthesubtotalsforeachcityandthegrandtotalappearas
separaterows.
SelecttheNetValuecolumnbyclickingthecolumnheading.Clickthe
fourthbuttonfromtheright,andoptionsappear,asshowninFigure12
53.SelecttheABCAnalysisoption.
Figure1253.SelectingtheABCAnalysisoption
TheABCAnalysisscreenappears.YouaregoingtodoABCanalysis
basedonthecustomer.AccepttheAnalysisTypeasKeyFigure
Percentage(thedefault).FortheASegmentoption,typein80%.Setthe
BSegmentoptionto15%,andCSegmentto5%.Youareindicatingthat
thecustomerscontributing80%oftotalsalesareA,thecustomers
contributingthenext15%oftotalsalesareB,andthecustomers
contributingtotheresidual5%oftotalsalesareC.
TheABCanalysislistappearsbelowthesesettings,asshowninFigure
1254.Thecustomersappearindescendingorderofsales(fieldNETWR)
thatis,thecustomerhavingthehighestsalesappearsfirst,andthe
customerhavingthelowestsalesappearslast.Youcanobservethat5
customersoutofatotalof36contributeto80%oftotalsales(thatis,
customerscategorizedasA),1customercontributestothenext15%of
totalsales(thecustomercategorizedasB),and30oddcustomers
contributetonext5%oftotalsales(customerscategorizedasC).
Figure1254.ABCanalysis
TheABCanalysisisemployedtypicallyininventoryormaterialcost
control,whenthisphenomenonoccursthatafewnumberofmaterials
contributetoalargeproportionofthetotalinventoryormaterialcost.
Controllingthesefewcostlymaterialswouldsubstantiallycontributeto
overallinventorycostcontrol.
IfyouclicktheListbutton,afullscreenlistoftheABCanalysisappears,
asshowninFigure1255(withatwodimensionalvisualeffect).
Figure1255.ThefullscreenABCanalysislist
NowitstimetoproducetheALVgraphics.Youhavetousethesecond
buttonfromtherightontheALVtoolbar.
Youwillproduceapiechartofcustomerwisesales.Togeneratethe
graphics,youhavetooutputtheALVreportwithcompanycodeR300and
thefilterconditionNETWR>=5000.Thisistoensureafewerlarge
sectorsinthepiechart.SelecttheCustomerfield,asshowninFigure12
56.
Figure1256.SelectingtheCustomerfieldforthepiechart
ClicktheGraphicsbutton.Thenclicktherightmousebutton(or
Shift+F10)toselecttheChartTypeoption,asshowninFigure1257.
Figure1257.Selectingthecharttype
Figure1258showsthepiechartofcustomerwisesalesforthecompany
codeR300andthefiltersettingofnetvalue>=5000.
Figure1258.Piechartofcustomerwisesales
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
16/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
Graphoptionshavebeenusedtogiveatitletothechartandtohavethe
customercodeswiththesalespercentagesinsidethepiechartsectors.
Youcantryoutthevariouscheckboxoptionsinthedisplaytabofthe
ChangeLayoutALVtoolbarbutton.YoucantrytheoptionOptimize
Columns.ThiswillautomaticallyadjusttheALVfieldoutputwidthtothe
maximumwidthofoutputdata.Inotherwords,ifthelengthoffieldNAME1
is35characters,butthemaximumNAME1contentfromtheoutputdatais
only30characters,thefieldNAME1willadjustto30characters.
IfyouhaveanExcelspreadsheettemplate,youcandisplayALVoutputin
anExcelspreadsheetfromtheViewtabbyclickingtheChangeLayout
ALVtoolbarbutton.
YoucantryotherALVtoolbarbuttonsandobservetheresults.
ThiswasademonstrationofasimpleALVoutput,showinghowendusers
canmanipulatetheoutputinvariousways,similartothewayyoucanin
anExcelspreadsheet.Inthisexercise,youchangedtheALVoutputlayout
anumberoftimes.Butyoucouldnotsavethelayouts.Inthenexthands
onexercise,youwilladdmoresophisticationtotheALVoutput.
HandsonExercise:CustomerwiseSalesSummaryofa
SpecifiedCompanyCodeasALVOutput,Version2:UseClass
CL_GUI_ALV_GRID
UsetheFieldCatalogandProvideSaveLayoutsFacility,Etc.
Parametersforthemethod:SET_TABLE_FOR_FIRST_DISPLAY:
Importingparameters:IS_VARIANT,I_SAVE,IS_LAYOUT
Changingparameters:IT_OUTTAB,IT_FIELDCATALOG
YouwillcreatemoresophisticatedfunctionalityintheALVreportyou
generatedintheprevioushandsonexercisebyaddingthree
enhancements:
Theuseofafieldcatalog.Withtheuseofafieldcatalog,youcan
controltheproperties,formatting,orappearanceoftheindividual
fieldsoftheALVreport.
Controlovertheoverallappearanceofthegrid.
ThecapabilitytosaveandmaintainALVreportlayouts.
Thesethreeenhancementsrequirepassingextraparameterstothe
methodSET_TABLE_FOR_FIRST_DISPLAY.
CreatingaFieldCatalog
WhenusingthemethodSET_TABLE_FOR_FIRST_DISPLAYoftheclass
CL_GUI_ALV_GRID,youcangiveeitheroneoftheparameters:
I_STRUCTURE_NAME
IT_FIELDCATALOG
YouhaveworkedwiththeI_STRUCTURE_NAMEparameter.Themethod
automaticallyfetchedtheheadingtextfromtheassociateddataelement
ofthefield,theoutputlength,theformatfromtheassociateddomainof
thefield,andsoforth.ThecustomercodefieldKUNNRwasoutputwiththe
leadingzerossuppressed(thatis,theALPHAconversionroutinewas
referredtointhedomainofthefieldandisgettingexecutedbydefault).
IfyouwanttosuppresstheexecutionoftheconversionroutineALPHA(as
youweredoingwiththeWRITEstatementUSINGNOEDITMASK),youhad
nomeansofdoingitintheprecedinghandsonexercise.Thisiswhere
thefieldcatalogcanbeused.Throughthefieldcatalog,youcancontrol
theappearanceofeachfieldappearingintheALVreport.
Thefieldcatalogisaninternaltable,containingonerowforeachfieldof
theALVreport.Thedifferentfieldsofthefieldcatalogstructure
constitutethedifferentpropertiesoftheALVreportfield.
ThefieldcatalogDDICinternaltabletypedefinitionisLVC_T_FCAT,and
theDDICstructureofthisinternaltableisLVC_S_FCAT.
Thereare96fieldsinthefieldcatalogstructureLVC_S_FCAT.Thethird
fieldinthisstructureisFIELDNAME,containingthenameoftheALV
reportfield.Table122providesapartiallistofthefieldsoffieldcatalog
structureLVC_S_FCAT.
Table122.AFewFieldsofFieldCatalogDDICStructure
LVC_S_FCAT
Field
Description
Name
FIELDNAME
NameoftheALVoutputfield(example:KUNNR).
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
17/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
TABNAME
NameoftheALVoutputfieldstructure
(example:SALES_STRU).
CURRENCY
Currencycode.
QUANTITY
Unitofmeasurecode.
JUST
Outputjustification(Lleft,Rright,and
Ccentered).
LZERO
Outputleadingzerosfornumericfields.
NO_SIGN
Suppresssign.
NO_ZERO
Suppressoutputofzero.
NO_CONVEXT
Value=X,suppressexecutionofconversion
exitroutine.
Value=space,executeconversionexitroutine.
EDIT_MASK
Editmaskincludingconversionexitroutineto
beexecuted.
EMPHASIZE
Colorcontrolofoutputfields.
FIX_COLUMN
Freezecolumn.
NO_SUM
Disabletotalingofthefield(numericfields).
NO_OUT
Omitoutputofthisfield.
TECH
Value=X,fieldistechnical.TheDDICdata
typeCLNT(client)istreatedasatechnicalfield.
Technicalfieldsbydefaultdonotoutput.They
donotappearinthefieldlistofChangeLayout
dialogboxes.Ifyouwantthemtobeoutput,set
thevalueto.
OUTPUTLEN
Outputlength.
CONVEXIT
Nameofconversionexitroutine.
HOTSPOT
Makethefieldhotspot.
COL_OPT
Columnwidthoptimization.
REF_FIELD
NameoftheDDICfieldtowhichthisfieldis
referring.
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
18/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
REF_TABLE
NameoftheDDICtablestructure/structureto
whichthisfieldisreferringisresiding.
Adetaileddescriptionofallthefieldcatalogfieldscanbefoundinthe
manualALVGridControl(BCSRVALV),frompage129onward.
Youcandirectlymanipulatethefieldcatalogandthenpassthe
manipulatedfieldcataloginternaltabletothemethod
SET_TABLE_FOR_FIRST_DISPLAY,andtheALVoutputwillappearasper
thefieldcatalogentriesforthedifferentfieldsoutputbytheALV.
Afieldcataloginternaltablecanbebuiltfromscratch,assigningallthe
myriadfieldsvaluesandthenappendingrows.Butitisseldomdonethis
way.Normally,thefunctionmoduleLVC_FIELDCATALOG_MERGEis
invokedtogenerateaninitialdefaultfieldcatalog.Thisfunctionmodule
takesaDDICstructureasanimportingparameterandreturnsafield
cataloginaninternaltableofDDICtypeLVC_T_FCAT.Inthepreceding
exercise,youpassedastructuredirectlytothemethod
SET_TABLE_FOR_FIRST_DISPLAY.Themethodgeneratedafieldcatalog
internallytowhichyouhadnoaccess,overwhichyouhadnocontrol,and
ALVoutputappearedwiththedefaultformatting.Inthisexercise,you
willcallthefunctionmoduleLVC_FIELDCATALOG_MERGE.Youwillpassto
thisfunctionmodulethesamestructurethatyoupassedtothemethod
SET_TABLE_FOR_FIRST_DISPLAY(thatis,YCL_CH12_SALES_SUM_STRUin
theprecedingexercise).Thefunctionmodulewillgenerateandreturna
defaultfieldcatalogintheinternaltable.Youwillmanipulatethis
internaltableandpassittothemethodSET_TABLE_FOR_FIRST_DISPLAY
astheformalchangingparameterIT_FIELDCATALOG.
Inthisexercise,youwilldothefollowing:
ImpartdifferentcolorstodifferentfieldsofALVoutput(byusing
thefieldcatalogcolumnnameEMPHASIZE).
SuppresstheexecutionoftheconversionexitroutineALPHAforthe
fieldKUNNR(byassigningthevalueXtothefieldcatalogcolumn
nameNO_CONVEXT,andassigningthevalueSPACEtoCONVEXIT).
Optimizeallcolumnwidths(byassigningthevalueXtothefield
catalogcolumnnameCOL_OPT).
ThefieldcatalogfieldEMPHASIZEthatisusedtoimpartcolortotheALV
outputcolumnsisoftypeCandlength4.Thecolorsyoucanimpartare
thesameasintheWRITEstatement,withthesamecolorcodes.Youcan
havecolorineitherthebackground(InverseOff)orforeground(Inverse
On).Colorinthebackgroundcanbesharp(IntensifiedOn)orfaint
(IntensifiedOff).
ThecolorfieldEMPHASIZEoperatesasfollows:
ThefirstcharacterhastobeC.
Thesecondcharactersignifiesthecolorcode(07).
ThethirdcharactersignifiesIntensifiedOn/Off(thatis,avalueof0
isIntensifiedOff,andavalueof1isIntensifiedOn).Intensified
Onworksforbackgroundcolorsonly.
ThefourthcharactersignifiesInverseOn/Off(thatis,avalueof0is
InverseOff,andavalueof1isInverseOn).
Youwilldefineacolorcountertocontainthecolorcodestartingfrom1,
andincrementitforeveryoutputfield(KUNNR,NAME1,ORT01,andNETWR).
YouwilloutputinbackgroundcolorwithIntensifiedOff.Soyourfield
EMPHASIZEmustassumethevaluesC100,C200,C300,andC400.
Thecoderelatedtothefieldcatalogmanipulationfollows.
Datadeclarations:
DATA:FCATTYPELVC_T_FCAT"fieldcatalogue
WITHHEADERLINE,
CLR(1)TYPENVALUE1,"forcolorcode
CodebeforecallingthemethodSET_TABLE_FOR_FIRST_DISPLAY:
CALLFUNCTION'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME='YCL_CH12_SALES_SUM_STRU'
CHANGING
CT_FIELDCAT=FCAT[]
EXCEPTIONS
INCONSISTENT_INTERFACE=1
PROGRAM_ERROR=2
OTHERS=3
.
IFSYSUBRC<>0.
MESSAGEIDSYMSGIDTYPESYMSGTYNUMBERSYMSGNO
WITHSYMSGV1SYMSGV2SYMSGV3SYMSGV4.
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
19/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
ENDIF.
LOOPATFCAT.
CLR=CLR+1."colorcodes1234
CONCATENATE'C'CLR'00'INTOFCATEMPHASIZE.
FCATCOL_OPT='X'."columnwidthoptimization
IFFCATFIELDNAME='KUNNR'."outputleadingzeroes
FCATNO_CONVEXT='X'.
FCATCONVEXIT=''.
ENDIF.
MODIFYFCAT.
ENDLOOP.
ControllingOverallAppearanceofALVOutput
YoucanestablishcontroloftheoverallappearanceoftheALVoutputby
fillinginappropriatefieldsofthestructurereferringtotheDDIC
structureLVC_S_LAYO.Thestructureistobepassedtotheformal
exportingparameterIS_LAYOUT.Table123providesapartiallistof
fieldsofthisDDICstructureLVC_S_LAYO.
Table123.AFewFieldsoftheDDICStructureLVC_S_LAYO
Field
Description
Name
CWIDTH_OPT
Optimizeallcolumnwidths.(Optimizationat
theoutputlevelisdistinctfromoptimizationat
thefieldlevelinthefieldcatalog.)
GRID_TITLE
Atitleforthegrid.Inenlargedfont,maximum
of70columns.
NO_HEADERS
Hidefieldorcolumnheaders.
NO_HGRIDLN
Hidehorizontalgridlines.
NO_VGRIDLN
Hideverticalgridlines.
NO_TOOLBAR
HideALVtoolbar.
ZEBRA
Alternatingcolorforfields.
Youcanfindafulllistwithexplanationsstartingonpage157ofthe
manualALVGridControl(BCSRVALV).
YouareusingthefieldGRID_TITLEofthisstructuretooutputanALV
reportwithatitle.
Thesourcecoderelatedtothecontrolofgridappearancefollows.
Datadeclaration:
LAYOUTTYPELVC_S_LAYO,"overallgridappearance
CodebeforecallingthemethodSET_TABLE_FOR_FIRST_DISPLAY:
CONCATENATETEXT001CCODE'/'BUTXT''
TEXT002INTOLAYOUTGRID_TITLE.
Thevaluesofthetextsymbolsareasfollows:
[TEXT001:'SalesSummaryCompanyCode:'
TEXT002:'Curr.']
SaveandManageALVOutputLayouts
ForsavingandmanagingALVoutputlayouts,youneedtopassvaluesto
twoformalexportingparameters,IS_VARIANTandI_SAVE,ofthemethod
SET_TABLE_FOR_FIRST_DISPLAY.TheformalparameterIS_VARIANTis
typedtotheDDICstructureDISVARIANT.Youneedonlytoassignthe
nameoftheABAPprogramtothefieldREPORTofthisstructure.The
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
20/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
formalparameterI_SAVE(ABAPtypeCandlength1)isassignedvalues
asfollows:
I_SAVE=U:Userdefinedlayoutscanbesaved.
I_SAVE=X:Globallayoutscanbesaved.
I_SAVE=A:Userdefinedandgloballayoutscanbesaved.
I_SAVE=:Layoutscannotbesaved.(Thisisthedefault.)
Thesourcecoderelatedtoprovidingthecapabilitytosaveandretrieve
layoutsincludesthefollowing.
Datadeclaration:
DVARIANTTYPEDISVARIANT."forsavinglayouts
CodebeforecallingthemethodSET_TABLE_FOR_FIRST_DISPLAY:
DVARIANTREPORT='YCL_CH12_02_ALV_FCAT_ETC'.
CallingmethodSET_TABLE_FOR_FIRST_DISPLAYwithadditional
parameters:
CALLMETHODALV_GRID>SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_VARIANT=DVARIANT"change,savelayouts
I_SAVE='U'"change,savelayouts
IS_LAYOUT=LAYOUT"change,savelayouts
*I_STRUCTURE_NAME='YCL_CH12_SALES_SUM_STRU'
CHANGING
IT_OUTTAB=SALES_TAB
IT_FIELDCATALOG=FCAT[]"fieldcatalogue
EXCEPTIONS
INVALID_PARAMETER_COMBINATION=1
PROGRAM_ERROR=2
TOO_MANY_LINES=3
others=4
.
TheprogramisYCL_CH12_02_ALV_FCAT_ETC,andthefullcodecanbe
foundinthesourcecoderesource.
TheoutputappearsasshowninFigure1259.
Figure1259.OutputoftheprogramYCL_CH12_02_ALV_FCAT_ETC
Intheoutput:
Fieldsareoutputindifferentcolors.
Customercodeisoutputwithleadingzeros.
Columnwidthsareoptimized.
AtitleappearsintheALVgrid.
Whenyouclickthethirdbuttonfromtheright(earlier,theChangeLayout
button)ontheALVtoolbar,amenuappearswithSelectLayout,Change
Layout,SaveLayout,andManageLayoutsoptions.
SelecttheSaveLayoutoption.ThescreenshowninFigure1260
appears.
Figure1260.SavingthelayoutforYCL_CH12_02_ALV_FCAT_ETC
Enterthelayoutnameandshorttext,andthenclicktheContinuebutton.
Youhavecreatedalayoutoftheoutputasitappearsoriginally,without
anycolumnshuffling,sorting,filtering,andsoforth.
Nowyouwillcreateonemorelayoutwithcolumnshuffling,sorting,and
filtering.Changethelayoutexactlyasyoudidintheprecedingexercise:
Fieldorder:
City(ORT01)
Customer(KUNNR)
Name1(NAME1)
NetValue(NETWR)
Total:NetValue
Sorting:
Sort:City(Ascending)
Group:City(Subtotals)
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
21/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
Filterfields/columns:
Filtervaluesforcity:A*,B*,C*,M*,S*,T*(citiesstarting
withA,B,C,M,S,andT)
NetValue:>=500
Savethislayout,asshowninFigure1261.
Figure1261.Savinganotherlayout,LAYOUT2
WhenyouclicktheSelectLayoutmenuoption(thefirstoption),the
dialogboxinFigure1262appears,enablingyoutomakeaselection
fromthesavedlayouts.TheALVoutputwillappearaspertheselected
layout.
Figure1262.Choosingalayout
Aftersavinglayouts,ifyouchooseasavedlayoutorloadtheprogram
withadefaultlayout,thecustomercodeisoutputwithouttheleading
zeros.Thishappenseventhoughyousuppressedtheexecutionofthe
ALPHAroutinewhenmanipulatingthefieldcataloginitially.Youwillfix
thisprobleminthenexthandsonexercise.
YoucanclicktheMaintainLayoutsmenuoptiontosetadefaultlayout,
deletelayouts,andsoforth.
HandsonExercise:CustomerwiseSalesSummaryandDetailof
aSpecifiedCompanyCodeasALVOutput:UseClass
CL_GUI_ALV_GRID
TriggerCL_GUI_ALV_GRIDEvents:TOOLBAR,
USER_COMMAND,AFTER_USER_COMMAND,
DOUBLE_CLICK,andCL_GUI_DIALOGBOX_CONTAINER
Event:CLOSE
Youwillstartthisexercisewiththecustomerwisesalessummaryofa
specificcompanycodeasALVoutput.Youwillimpartadditional
functionalitiesandfeaturestothisinitialALVoutputbytriggeringevents
ofclasses.
Inthisexercise,youaregoingtodothefollowing:
Generateadetailedlistofcustomerbillingdocumentsbydouble
clickingalineofthecustomerwisesalessummaryofaspecific
companycode.
PlaceacustombuttonontheALVtoolbarandmakeitoperational.
Outputaserialnumberandthenadjustitbasedonachangeinthe
ALVlayout(thatis,regeneratetheserialnumbereverytimea
changeoccursintheALVlayout).RecallthesystemfieldsSYDBCNT
orSYTABIXyouwereusingmostofthetimetooutputtheserial
numberviatheWRITEstatement.Theoutputoftheserialnumberis
beingimplementedforthefirstALVoutputonly.Theserial
numberintheALVoutputhastobedynamicbecausetheALV
outputcanbemanipulated.Regeneratingtheserialnumberagain
andagaineverytimetheALVoutputischangedmakestheissue
complex.
GeneratingaDetailedListofCustomerBillingDocuments
EventDOUBLE_CLICKofclassCL_GUI_ALV_GRID,eventCLOSEof
classCL_GUI_DIALOGBOX_CONTAINER
Inthisexercise,youarerecreatingtheinteractivelistsintheALV
paradigm.Tostartwith,youwillhavethecustomerwisesalessummary
foraspecifiedcompanycodeinaninstanceoftheclassCL_GUI_ALV_GRID
(acarryforwardfromtheprecedingexercise).Doubleclickinga
customerinthisoutputwillbegetasecondALVoutput,listingallthe
billingdocumentsofthatcustomer.Youwerereferringtothissecond
ALVlistasthefirstsecondarylistintheinteractivelistsparadigm.
YouwilltriggertheDOUBLE_CLICKeventoftheclassCL_GUI_ALV_GRID.
Thiseventhastwoimportingparameters(eventshaveonlyimporting
parameters):E_ROWandE_COL,therowandcolumnnumberthatwere
doubleclicked.UsingE_ROWINDEX,youcanfetchthecorrespondingrow
fromtheinternaltablecontainingthesalessummarydata(READTABLE
SALES_TABINTO...INDEXE_ROWINDEX).Youcanthanknowthe
customercodeoftherowthatwasdoubleclicked.Usingthiscustomer
code,youcanfetchthebillingdocumentsbelongingtothiscustomer.You
canlookupthiseventintheClassBuilderbyusingtransactioncode
SE24.
YouwillneedasecondinstanceoftheclassCL_GUI_ALV_GRID,inwhich
youwilloutputthebillingdocumentsofaspecificcustomer.Youwill
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
22/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
locatethissecondinstanceoftheclassCL_GUI_ALV_GRIDinadialogbox
containerCL_GUI_DIALOGBOX_CONTAINERinsteadofthe
CL_GUI_CUSTOM_CONTAINER.Thedialogboxcontainer,unlikeacustom
container,isnotplacedinsideacustomcontrol.Itcanbelocated
anywhereonthescreenbyspecifyingthescreencoordinatesandthesize
atruntime.Soyouhavetocreateaninstanceofthisclass
CL_GUI_DIALOGBOX_CONTAINERthencreateasecondinstanceoftheclass
CL_GUI_ALV_GRID,callthemethodSET_TABLE_FOR_FIRST_DISPLAYfor
thissecondinstance,andpassitthedataofbillingdocumentsofthe
specificcustomer.ThisisrepresentedinFigure1263.
Figure1263.InteractivereportsintheALVparadigm
Withaneventofaclass,whenyoutriggertheevent,amethodinaclass
isexecuted.WhenyoutriggertheeventDOUBLE_CLICKforthefirst
instanceoftheclassCL_GUI_ALV_GRID,youwanttocreateaninstanceof
theclassCL_GUI_DIALOGBOX_CONTAINER,createasecondinstanceofthe
classCL_GUI_ALV_GRID,createadefaultfieldcatalog,manipulatethis
defaultfieldcatalog,andexecutethemethod
SET_TABLE_FOR_FIRST_DISPLAYforthesecondinstanceoftheclass
CL_GUI_ALV_GRID.Allthiscodefortheprecedingdescribedprocesseswill
havetoresideinamethodofaclass.So,youwilldefineandimplementa
localclass,inwhichyouwilllocatethemethodtobeexecutedwhenyou
doubleclickalineofthecustomerwisesalessummaryofaspecific
companycode.
Themethodsthatareexecutedwheneventsofclassesaretriggeredare
calledtheeventhandlermethodsorhandlermethods.Evenasyoursecond
ALVoutputispresentedonthescreen,youmustensurethatthefirstALV
outputisdisabled.Forthis,youareusingtheENABLEmethodoftheclass
CL_GUI_ALV_GRID.Whencallingthismethod,youhavetopassan
exportingparameter.WhenthisparameterhasavalueX,theALVoutput
isenabled,andwhenthisparameterhasavalue,theALVoutputis
disabled.WhenaninstanceoftheALVoutputisdisabled,itis
inaccessibletoclickingandotheractions.
WhenyouareonthesecondALVoutputlocatedinthedialogbox
container,youwouldliketohavethecapabilitytoclosethatcontainer
andnavigatebacktothefirstALVoutput.Theclosingofthedialogbox
containerisimplementedthroughtheeventCLOSEoftheclass
CL_GUI_DIALOGBOX_CONTAINER.Youwilltriggerthiseventlocatethe
methodtobeexecutedwhenthiseventistriggeredinthesamelocalclass
youareusingtolocatethemethodtobeexecutedfortheevent:
DOUBLE_CLICKoftheclassCL_GUI_ALV_GRID.Infact,youaregoingto
locateallthemethodstobeexecutedwhenvariouseventsaretriggered
inthissamelocalclassthatis,alltheeventhandlermethodsinthis
programarebeinglocatedinthelocalclassnamedLCLASS.
InthemethodtobeexecutedwheneventCLOSEistriggeredfortheclass
CL_GUI_DIA:OGBOX_CONTAINER,youaregoingtousethedestructor
methodFREEtoclosethedialogboxcontaineranditsembeddedsecond
instanceofCL_GUI_ALV_GRID.
Theeventhandlermethods,whentheyaredeclaredintheclass(class
definition)arerelatedtotheeventandtheclass.Thisisonepartofco
relatinganeventhandlermethod.Thesecondpartofcorelatingan
eventhandlermethodistheregistrationoftheeventhandlermethod.In
theregistrationoftheeventhandlermethod,themethodisrelatedtothe
instanceoftheclass.
Forexample,inthisprogram,youhavetwoinstancesofclass
CL_GUI_ALV_GRID.Thefirstinstanceoutputsthecustomerwisesales
summaryofaspecificcompany.OndoubleclickingalineofthisALV
output,youarecreatingasecondinstanceoftheclassandgeneratingthe
billingdocumentsofthedoubleclickedcustomer.Inthecurrentexercise,
youaresupportingtheDOUBLE_CLICKeventofclassCL_GUI_ALV_GRID
onlyforthefirstinstance,notthesecondinstance.Ifdoubleclickingis
doneonthebillingdocumentsofacustomer,nothingshouldhappenthe
eventhandlermethodinthelocalclassfordoubleclickshouldnotget
executed.Thisismanagedthroughtheconceptoftheregistrationofthe
event.YouwillregistertheDOUBLE_CLICKeventhandlermethodonlyfor
thefirstinstanceoftheclassCL_GUI_ALV_GRID.
Theaptplaceofregistrationofaneventhandlermethodisjustafter
creationoftheinstanceoftheclasstowhichyouarecorelatingtheevent
handlermethod.Forexample:
CREATEOBJECTALV_GRID1EXPORTING...
SETHANDLERLREF>DB_CLICKFORALV_GRID1.
Perusethesourcecodewithitscomments.
Theextracodeisrequiredtoimplementthehandlermethodsforevents
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
23/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
DOUBLE_CLICKofclassCL_GUI_ALV_GRIDandCLOSEofclass
CL_GUI_DIALOGBOX_CONTAINER.
Codeinthedeclarationpart:
CLASSLCLASSDEFINITIONDEFERRED.
DATA:LREFTYPEREFTOLCLASS,
......
Codeforthelocalclass:
*****classdefinition*****
CLASSLCLASSDEFINITION.
PUBLICSECTION.
METHODS:DB_CLICKFOREVENTDOUBLE_CLICKOFCL_GUI_ALV_GRID
IMPORTINGE_ROW,
CLOSE_DBOXFOREVENTCLOSEOFCL_GUI_DIALOGBOX_CONTAINER,
....
PRIVATESECTION.
DATA:BILLS_STRUTYPEYCL_CH12_BILLS_STRU,
BILLS_TABTYPESTANDARDTABLEOFYCL_CH12_BILLS_STRU,
DCONTTYPEREFTOCL_GUI_DIALOGBOX_CONTAINER,
ALV_GRID2TYPEREFTOCL_GUI_ALV_GRID,
CAPTON(70)TYPEC,
FCAT2TYPELVC_T_FCAT,
FSTRUTYPELVC_S_FCAT,
......
ENDCLASS.
*****classimplementation*****
CLASSLCLASSIMPLEMENTATION.
******DB_CLICK*****
METHODDB_CLICK.
CHECKE_ROWROWTYPEISINITIAL."doubleclickingisonacustomer
"line,notsubtotal/totalline
READTABLESALES_TABINTOSALES_STRUINDEXE_ROWINDEX.
SELECTVBELNFKDATWAERKKURRFNETWRFROMVBRK
INTOTABLEBILLS_TABWHEREKUNAG=SALES_STRUKUNNR
ANDBUKRS=CCODE.
LOOPATBILLS_TABINTOBILLS_STRU.
BILLS_STRUNETWR=BILLS_STRUNETWR*BILLS_STRUKURRF.
MODIFYBILLS_TABFROMBILLS_STRU.
ENDLOOP.
CALLFUNCTION'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME='YCL_CH12_BILLS_STRU'
CHANGING
CT_FIELDCAT=FCAT2
EXCEPTIONS
INCONSISTENT_INTERFACE=1
PROGRAM_ERROR=2
OTHERS=3
.
IFSYSUBRC<>0.
MESSAGEIDSYMSGIDTYPESYMSGTYNUMBERSYMSGNO
WITHSYMSGV1SYMSGV2SYMSGV3SYMSGV4.
ENDIF.
LOOPATFCAT2INTOFSTRU.
FSTRUCOL_OPT='X'.
IFFSTRUFIELDNAME='KURRF'.
FSTRUNO_SUM='X'."nosumforKURRF
ENDIF.
MODIFYFCAT2FROMFSTRU.
ENDLOOP.
CONCATENATETEXT001SALES_STRUKUNNR'/'SALES_STRUNAME1INTOCAPTON.
CREATEOBJECTDCONT
EXPORTING
WIDTH=420"dimensionispoints
HEIGHT=200""apoint=1/72ofinch
TOP=35
LEFT=550
CAPTION=CAPTON
EXCEPTIONS
CNTL_ERROR=1
CNTL_SYSTEM_ERROR=2
CREATE_ERROR=3
LIFETIME_ERROR=4
LIFETIME_DYNPRO_DYNPRO_LINK=5
EVENT_ALREADY_REGISTERED=6
ERROR_REGIST_EVENT=7
others=8
.
IFSYSUBRC<>0.
MESSAGEIDSYMSGIDTYPESYMSGTYNUMBERSYMSGNO
WITHSYMSGV1SYMSGV2SYMSGV3SYMSGV4.
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
24/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
ENDIF.
SETHANDLERLREF>CLOSE_DBOXFORDCONT.
"registrationof'CLOSE_DBOXhandlermethodforinstanceDCONT
CREATEOBJECTALV_GRID2
EXPORTING
I_PARENT=DCONT.
CALLMETHODALV_GRID2>SET_TABLE_FOR_FIRST_DISPLAY
CHANGING
IT_OUTTAB=BILLS_TAB
IT_FIELDCATALOG=FCAT2.
CALLMETHODALV_GRID1>SET_ENABLE
EXPORTING
ENABLE=''.
ENDMETHOD.
**********************
METHODCLOSE_DBOX.
CALLMETHODDCONT>FREE().
CALLMETHODALV_GRID1>SET_ENABLE
EXPORTING
ENABLE='X'.
ENDMETHOD.
***********************
DDICstructureYCL_CH12_BILLS_STRUhasbeencreatedwiththefields
VBELN,FKDAT,WAERS,KURRF,andNETWR.
Thevalueofthetextsymbolisasfollows:
[TEXT001:'BillsofCustomer:']
CodeforregistrationofhandlermethodDB_CLICKforinstance
ALV_GRID1:
CREATEOBJECTALV_GRID1.....
.....
CREATEOBJECTLREF.
*****registrationofhandlermethods****
SETHANDLERLREF>DB_CLICKFORALV_GRID1.
......
ThiscodeenablesthegenerationofthedetailedsecondALVoutput:
billingdocumentsofacustomer.Itenablesclosingofthissecondoutput
andnavigatingbacktothefirstALVoutput:thecustomerwisesales
summaryofaspecificcompanycode.
Toensurethatdoubleclickingasubtotalortotallinedoesnotgenerate
thedetailedALVreport,youcheckthecontentsoftheimporting
parameterE_ROWROWTYPE.Ifitsvalueisblankoraninitialvalue,
doubleclickinghasbeendoneonaregularrow.Otherwise,double
clickinghasbeendoneonasubtotalortotalrow.
PlacingaCustomButtonontheALVToolbarandMakingItOperative
EventsTOOLBARandUSER_COMMANDofclassCL_GUI_ALV_GRID
Inthispartoftheexercise,youwillincorporateacustombuttononthe
ALVtoolbarandthenreacttotheclickingofthatbutton.Youwilldothis
byshiftingtheBackbuttonfromtheapplicationtoolbar(usedinthis
chaptersprecedinghandsonexercises)totheALVtoolbar.Thenyoudo
nothavetocodeinthePAIevent.
HavingacustombuttonontheALVtoolbarrequirestwomainsteps:
LocatingthecustombuttonontheALVtoolbar
Makingthecustombuttonoperational
YouincorporateacustombuttonontheALVtoolbarbyusingtheevent
TOOLBARoftheALVclassCL_GUI_ALV_GRID.Thiseventistriggeredeach
timethetoolbarofthecontrol(ALVgrid)needstoberegenerated.Itis
alsotriggeredbythemethodSET_TOOLBAR_INTERACTIVEoftheclass
CL_GU_ALV_GRID.
TheeventTOOLBARhastwoimportingparameters(E_OBJECToftype
CL_ALV_EVENT_TOOLBAR_SETandE_INTERACTIVE).Youwillusethefirst
importingparameter,E_OBJECT.IfyoulookuptheTOOLBAReventofthe
classCL_GUI_ALV_GRIDintheClassBuilder,andthenlookuptheclass
CL_ALV_EVENT_TOOLBAR_SETandclicktheattributesofthatclass,the
DDICtablehasanattributeMT_TOOLBARoftypeTTB_BUTTON.The
structureoftheDDICtable(internaltable)typeisSTB_BUTTON.Youhave
tofillinthefourfields(FUNCTION,ICON,QUICKINFO,andTEXT)ofthe
structureSTB_BUTTONandthenappendthesebuttonparticularstothe
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
25/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
internaltableE_OBJECT>MT_TOOLBARforyourbuttontoappearonthe
ALVtoolbar.Youcancreateagapbetweenbuttonsbyassigningthefield
BUTN_TYPEofstructureSTB_BUTTONavalueof3andappendingittothe
internaltableE_OBJECT>MT_TOOLBAR.Youalsocancreatemenuand
menuentries.RefertothesinglevaluesofthedomainTB_BTYPE
associatedwiththefieldBUTN_TYPEofstructureSTB_BUTTON.Youare
placingtheextracustombuttononlyonfirstinstanceoftheclass
CL_GUI_ALV_GRID.
YoucanusetheeventUSER_COMMANDtoexecuteactionsfollowingthe
clickingofALVtoolbarbuttons.Youhavetolocatethesameprogram
codethatwasinthePAIeventofthischaptersprecedingexercisesinthe
eventhandlermethodoftheeventUSER_COMMAND.Again,youwantthis
methodtobeexecutedforthefirstinstanceoftheclassCL_GUI_ALV_GRID,
notthesecondinstance.TheeventUSER_COMMANDhasoneimporting
parameter,E_UCOMM,containingthefunctioncodeofthebuttonpressed.
Theextracoderequiredtoimplementthehandlermethodsfortheevents
TOOLBARandUSER_COMMANDfollows.
Perusethecodewithitscomments.
Sourcecodeinthelocalclass:
PUBLICSECTION.
......
METHODS:TOOL_BARFOREVENTTOOLBAROFCL_GUI_ALV_GRID
IMPORTINGE_OBJECTE_INTERACTIVE,
GO_BACKFOREVENTUSER_COMMANDOFCL_GUI_ALV_GRID
IMPORTINGE_UCOMM.
.........
PRIVATESECTION.
DATA:TOOL_STRUTYPESTB_BUTTON,"struforALVtoolbar
...
METHODTOOL_BAR.
CLEARTOOL_STRU.
TOOL_STRUBUTN_TYPE=3.
"creategaplastexistingbutton&ownbutton
APPENDTOOL_STRUTOE_OBJECT>MT_TOOLBAR.
CLEARTOOL_STRU.
TOOL_STRUFUNCTION='BACK'."functioncode
TOOL_STRUICON='@CF@'."iconcode
TOOL_STRUQUICKINFO='Back'(002)."buttontooltip
TOOL_STRUTEXT='Back'(002)."buttontext
APPENDTOOL_STRUTOE_OBJECT>MT_TOOLBAR.
ENDMETHOD.
************************
METHODGO_BACK.
IFE_UCOMM='BACK'.
SETSCREEN0."thesetwostatementsreturn
LEAVESCREEN."controltoPARAMETERSprompt
ENDIF.
ENDMETHOD.
****************************
Thevaluesoftextsymbols:
[TEXT002:'Back']
CodeforregistrationofhandlermethodsTOOL_BARANDGO_BACK
forinstanceALV_GRID1:
CREATEOBJECTALV_GRID1.....
.....
CREATEOBJECTLREF.
......
SETHANDLERLREF>TOOL_BARFORALV_GRID1.
SETHANDLERLREF>GO_BACKFORALV_GRID1.
OutputtingaSerialNumberandAdjustingItwiththeChangeinALV
Layout
EventAFTER_USER_COMMANDofclassCL_GUI_ALV_GRID
YouareusingtheDDICstructureYCL_CH12_SALES_SUM_STRU1to
generatethedefaultfieldcatalogforthefirstinstanceALVgrid.Itisa
modifiedversionoftheDDICstructureYCL_CH12_SALES_SUM_STRUyou
usedforyourearlierALVexercises.Itcontainstheadditionalfield
SRL_NOasthefirstfieldofthestructure.
ThefieldSRL_NO(serialnumber)appearinginyourALVoutputhastobe
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
26/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
adjustedregeneratedeverytimetheuserchangestheoutputlayoutby
eitheromittingrowsorincludingpreviouslyomittedrows(thatis,a
changeinfiltersettingsand/oreverytimethedataisreorderedviaa
changeinsortsettings).
Inyourpreviousexercise,youdidnotresortthecustomerwisesales
summaryinternaltableintheprogram.Thefilterandsortsettingswere
appliedtothecopyofthesummarizedsalesdatainternaltableonthe
presentationserver.Nowyouneedtoresortthesummarizedsalesdata
internaltableintheprogram(applicationserver)tobeableto
regeneratetheserialnumbers.
Youcanregeneratetheserialnumbersinaneventhandlermethodof
eventAFTER_USER_COMMAND.Thiseventistriggeredaftertheenduser
selectsafunctionontheALVtoolbarandthisfunctionhasbeenexecuted.
Incaseadefaultlayoutisoperating(thatis,adefaultlayouthasbeen
set),whentheALVoutputisbeingproducedforthefirsttimeviathe
Execute/F8buttonontheselectionscreenpromptingforcompanycode,
theserialnumbershavetobegeneratedasperfilterandsortsettingsin
thedefaultlayout.Fortheserialnumberstobegeneratedcorrectlyfor
thedefaultlayout,youexecutetheeventhandlermethodfortheevent
AFTER_USER_COMMANDexplicitly,justaftercallingthemethod
SET_TABLE_FOR_FIRST_DISPLAY.
Thefilterandsortsettingsaremaintainedatthepresentationserver
level.Soyouhavetoretrievethesesettingswiththemethods
GET_FILTER_CRITERIAandGET_SORT_CRITERIA.Thesemethodsretrieve
andreturnthepresentationserverfilterandsortsettingstotheprogram
inthespecificformatofinternaltables.Thereisanothermethod,
GET_FILTERED_ENTRIES.Thismethodreturnsinahashedinternaltable,
therownumbersoffilteredoutdata.Inthepresentexercise,youwilluse
thismethodtoretrievethefilteredoutoromittedrowsreturnedinterms
ofrownumbersinahashedinternaltable.
Therownumbersreturnedinahashedinternaltablearetherow
numbersofthesummarizedsalesdatainternaltableasitexistedbefore
newsortcriterionwasapplied.Referringtothishashedinternaltable,
youcanmarktherowsinthesummarizedsalesdatainternaltablefor
whichaserialnumberistobegenerated.(Foromittedrownumbers,no
serialnumberistobegenerated.)
Thesortcriterionisreturnedinaninternaltablewhosestructure(DDIC
typeLVC_S_SORT)isasfollows:
SPOS:Indicatesthesortsequence.Ifthefieldisfirstinthesort
sequence,thevalue=1ifitissecond,thevalue=2.
FIELDNAME:Indicatesthefieldname
UP:Value=Xifascending
DOWN:Value=Xifdescending
Youneedtosortthesummarizedsalesdatainternaltableaspernewsort
criteriontobeabletogeneratethenewserialnumbers.
Aninternaltablecanbesortedbyprovidingthesortspecificationsinan
internaltablesimilartotheruntimesortspecificationyouprovideina
SELECTstatement.Thesyntaxforthisisasfollows:
SORT<internaltable>BY(<internaltablewithsortspecifications>).
The<internaltablewithsortspecifications>hastheDDIC
structuretypeABAP_SORTORDERwiththefollowingfields:
NAMEFieldname
DESCENDING='X',ifdescending
ASTEXT='X',iftextsort
SoyouhavetoconvertthesortcriterioninternaltablereturnedasDDIC
structuretypeLVC_S_SORTintoaninternaltableofDDICstructuretype
ABAP_SORTORDER.
Tosumup,youhavetoperformthefollowingtohaveserialnumbers
regeneratedasperalteredfilterand/orsortsettingsintheeventhandler
methodofAFTER_USER_COMMAND:
Reset/initializeserialnumbersinthesummarizedsalesdata
internaltable.
Retrievethefilteredoutoromittedrowsatthepresentation
server/frontend.
Usingthisinformationoffilteredoutrows,markinthe
summarizedsalesdatainternaltable,therowsforwhichserial
numbersaretobegenerated.
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
27/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
Retrievethesortsettings.
Convertthesortsettings.
Sortthesummarizedsalesdatainternaltablewiththeconverted
sortsettings.
Generatetheserialnumbersforthemarkedrowsofthesorted
summarizedsalesdatainternaltable.
Wheneveryouareselectingsavedlayoutsoroperatingthedefault
layout,thefieldcatalogatthefrontendorpresentationserverisnotin
syncwiththebackendfieldcatalog.(Thesuppressionofleadingzeros
occurringincustomercodeoutput,andsoforth.)Torectifythis,youdo
thefollowing:
Retrievethefrontendorpresentationserverfieldcatalog.
Manipulatethisfieldcatalogfortheappearanceofleadingzerosin
thecustomercode.SuppressthetotalingoffieldSRL_NO(serial
number).DeterminethemaximumwidthsofthefieldsNAME1and
ORT01.Settheoutputlengthsofthesefields(fieldcatalogfield
OUTPUTLEN)tothedeterminedwidths.
SettheALVoutputfrontendfieldcatalogwiththemanipulated
fieldcatalog.
Youmaketheleadingzerosappearinthecustomercodebyusingthe
functionmoduleCONVERSION_EXIT_ALZSN_OUTPUTinthefieldEDIT_MASK
ofthefieldcatalog.Youassignthisfieldthevalue==ALZSN.Notethatthe
functionmoduleCONVERSION_EXIT_ALPHA_OUTPUTsuppresseszerosin
theoutput.
TomakefunctionmoduleCONVERSION_EXIT_ALZSN_OUTPUToperative,
youhavetoinsertarowinthedatabasetableADLZSNwiththefollowing
codesnippet:
TABLESADLZSN.
ADLZSNSETON='X'.
INSERTADLZSN.
TheoptimizingofcolumnwidthswiththefieldcatalogfieldCOL_WIDTHset
tovalueXisnotworkingwiththeinitialloadingoftheALVoutputwitha
defaultlayout,especiallywiththefieldsNAME1andORT01.Thatiswhyyou
aredeterminingthemaximumwidthsforthesefieldswhilegenerating
theserialnumbers,byassigningthefieldcatalogfieldOUTPUTLENwith
determinedwidths.
Themethodshouldbeexecutedonlyifthereischangeinthesortand
filtersettings.Butfornow,youareexecutingthismethodonoperationof
anyoftheALVtoolbaroptions.Inthenextversionofthisprogramusing
theALVclassCL_SALV_TABLE,youwillimplementthis.
Theextracoderequiredtoimplementthehandlermethodforevent
AFTER_USER_COMMAND(toregenerateserialnumber,andsoforth)follows.
Perusethesourcecodewithitscomments.
Sourcecodeinthedeclarationpart:
"internaltableforsortruntimespec
SORT_TABTYPELVC_T_SORTWITHHEADERLINE,"ALVsortentries
BYSTYPEABAP_SORTORDER_TABWITHHEADERLINE.
Sourcecodeinthelocalclass:
METHODS:
.........
ADJUST_SRL_NOFOREVENTAFTER_USER_COMMANDOFCL_GUI_ALV_GRID
IMPORTINGE_UCOMME_SAVEDE_NOT_PROCESSED.
PRIVATESECTION.
DATA:
........
NAME1_LENTYPEI,"maxlengthNAME1
ORT01_LENTYPEI,"maxlengthORT01
TFCATTYPELVC_T_FCAT,
FL_ENTSTYPELVC_T_FIDX,"rowsfilteredout
INDEXTYPEYCL_CH12_SRL_NO."togenerateserialno.
METHODADJUST_SRL_NO.
REFRESH:FL_ENTS,SORT_TAB,BYS.
ALV_GRID1>REFRESH_TABLE_DISPLAY().
*****rowstobefilteredout*****
CALLMETHODALV_GRID1>GET_FILTERED_ENTRIES
IMPORTING
ET_FILTERED_ENTRIES=FL_ENTS
.
*****rowstobefilteredoutover*****
CALLMETHODALV_GRID1>GET_SORT_CRITERIA
IMPORTING
ET_SORT=SORT_TAB[].
*****convertsortspecs*****
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
28/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
SORTSORT_TABBYSPOS."sortinorderofsortsequence
LOOPATSORT_TABINTOSORT_TAB.
BYSNAME=SORT_TABFIELDNAME.
IFSORT_TABDOWNISNOTINITIAL.
BYSDESCENDING='X'.
ELSE.
BYSDESCENDING=''.
ENDIF.
APPENDBYSTOBYS.
ENDLOOP.
*****convertsortspecsover*****
*****markrowsforwhichserialnumberstobegenerated*****
**rowsforwhichserialnumberstobegeneratedassignednonzero**
INDEX=0.
CLEARSALES_STRUSRL_NO.
MODIFYSALES_TABFROMSALES_STRUTRANSPORTINGSRL_NO
WHERESRL_NO<>0.
LOOPATSALES_TABINTOSALES_STRU.
READTABLEFL_ENTSFROMSYTABIXTRANSPORTINGNOFIELDS.
IFSYSUBRC=0."ifrowisintobefilteredoutinternal
CONTINUE."table,bypassforserialnumbergeneration
ENDIF.
INDEX=INDEX+1.
SALES_STRUSRL_NO=INDEX.
MODIFYSALES_TABFROMSALES_STRUTRANSPORTINGSRL_NO.
ENDLOOP.
SORTSALES_TABBY(BYS)."BYScontainsruntimesortspecs
INDEX=0.
*****generateserialnumbers**
NAME1_LEN=0.
ORT01_LEN=0.
LOOPATSALES_TABINTOSALES_STRU.
IFSALES_STRUSRL_NO=0.
CONTINUE.
ENDIF.
INDEX=INDEX+1.
SALES_STRUSRL_NO=INDEX.
MODIFYSALES_TABFROMSALES_STRU.
"obtainingthemaximumwidthofoutput:NAME1&ORT01
IFSTRLEN(SALES_STRUNAME1)>NAME1_LEN.
NAME1_LEN=STRLEN(SALES_STRUNAME1).
ENDIF.
IFSTRLEN(SALES_STRUORT01)>ORT01_LEN.
ORT01_LEN=STRLEN(SALES_STRUORT01).
ENDIF.
ENDLOOP.
*****adjustfrontendfieldcatalogue*****
ALV_GRID1>GET_FRONTEND_FIELDCATALOG(
IMPORTINGET_FIELDCATALOG=TFCAT).
"get/retrievefrontendfieldcatalogue
LOOPATTFCATINTOFSTRU.
CASEFSTRUFIELDNAME.
WHEN'KUNNR'.
FSTRUEDIT_MASK='==ALZSN'.
FSTRUCONVEXIT=''.
FSTRUNO_CONVEXT='X'.
FSTRUCOL_OPT='X'.
WHEN'NAME1'.
FSTRUOUTPUTLEN=NAME1_LEN.
WHEN'ORT01'.
FSTRUOUTPUTLEN=ORT01_LEN.
WHENOTHERS.
FSTRUCOL_OPT='X'.
ENDCASE.
IFFSTRUFIELDNAME='SRL_NO'.
FSTRUNO_SUM='X'."nototalingforserialnos.
ENDIF.
MODIFYTFCATFROMFSTRU.
ENDLOOP.
ALV_GRID1>SET_FRONTEND_FIELDCATALOG(IT_FIELDCATALOG=TFCAT[]).
"setfrontendfieldcatalogue
ENDMETHOD.
SourcecodeforregistrationofhandlermethodADJUST_SRL_NO
forinstanceALV_GRID1:
SETHANDLERLREF>ADJUST_SRL_NOFORALV_GRID1.
.....
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
29/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
LREF>ADJUST_SRL_NO().
ALV_GRID1>REFRESH_TABLE_DISPLAY().
TheprogramisYCL_CH12_03_ALV_EVENTS,andthefullcodecanbe
foundinsourcecoderesource.
TheoutputappearsasshowninFigure1264.
Figure1264.OutputofprogramYCL_CH12_03_ALV_EVENTS
Intheoutput:
Theserialnumbersappear.
TheBackbuttonappearsontheALVtoolbar.
Changethelayout.Inthechangedlayout,theorderoffieldsisSRL_NO,
NAME1,KUNNR,ORT01,andNETWR.MakethesortsettingasNAME1
ascending.Theserialnumbershavebeenregeneratedforthechanged
layout.TheoutputforthischangedlayoutlookslikeFigure1265.
Figure1265.Outputshowingthechangedlayout
ofYCL_CH12_03_ALV_EVENTS
Loadtheoriginallayoutwithnoneofthefilterandsortsettings,andthe
dataappearinginorderofcustomercode.Scrolldowntothecustomer
code0000003271(serialnumber31).Doubleclickthiscustomerline.
ThisproducesthedetailedALVoutput,whichlookslikeFigure1266.
Figure1266.Summaryanddetailoutput
ThebillingdocumentsofaspecifiedcustomerappearasdetailedALV
outputinthesecondinstanceoftheALVgrid,inadialogboxcontainer.
YoucanoperatetheCloseoptionofthedialogboxcontainerandtestthe
executionoftheeventhandlermethod.YoucanclicktheBackbuttonon
theALVtoolbarofthefirstinstanceoftheALVgridandtesttheevent
handlermethod.
Asintheprecedingexercise,createandsaveafewlayouts.Oneofthese
isLAYOUT2,thesamelayoutusedintheprecedingexercise.Thislayoutis
asfollows:
Fieldorder:
Srl.No.(SRL_NO)
City(ORT01)
Customer(KUNNR)
Name1(NAME1)
NetValue(NETWR)
Total:NetValue
Sorting
Sort:City(Ascending)
Group:City(Subtotals)
Filterfields/columns
Filtervaluesforcity:A*,B*,C*,M*,S*,T*(citiesstarting
withA,B,C,M,S,andT)
NetValue:>=500
Forthislayout,theoutputappearsasshowninFigure1267andFigure
1268.
Figure1267.Outputwithsubtotals
Figure1268.ProgramYCL_CH12_03_ALV_EVENTS:Output
withSubtotals
TheoutputhastestedtheeventhandlermethodsofeventsDOUBLE_CLICK,
CLOSE,andAFTER_USER_COMMAND.TheappearanceoftheBackbuttonon
theALVtoolbaranditsoperationhastestedtheeventhandlermethodsof
eventsTOOLBARandUSER_COMMAND.Thepowerofeventshasbeen
demonstratedinthisexercise.
Conclusion
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
30/31
1/5/2016
Chapter12:ABAPListViewerOutputsPart1SAPABAP:HandsOnTestProjectswithBusinessScenarios
YouhavecreatedALVoutputbyusingthebuiltinclass
CL_GUI_ALV_GRID.Youhavemanipulatedthisoutputasanenduser
wouldforinstance,shufflingfields,omittingfields,sorting,filtering,
performingABCanalysis,and[verbhere]graphics.Youhavecontrolled
theALVoutputfieldattributesandtheoverallappearanceofthegrid,and
youhaveenabledsavingandmanagingofALVlayouts.Youtriggered
eventstoaddsophisticationandenhancethefunctionalityoftheALV
output.
Inthenextchapter,youwilluseamoremodernbuiltinclass,
CL_SALV_TABLE,andimplementthesamefunctionalitiesyou
implementedwhenusingthebuiltinclassCL_GUI_ALV_GRID.
PREV
Recommended
/ Queue
Chapter 11: ABAP
OOP/ Recent / Topics / Tutorials / Settings / Blog / Feedback / Sign Out
2016 Safari.
Terms of Service / Privacy Policy
NEXT
https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch12.xhtml
31/31