Sunteți pe pagina 1din 17

1/5/2016

Chapter13:ABAPListViewerOutputPart2SAPABAP:HandsOnTestProjectswithBusinessScenarios

SAP ABAP: Hands-On Test Projects with Business Scenarios

Recent

Topics
Tutorials

NEXT

PREV

Chapter 12: ABAP List Viewer OutputsPart 1

CHAPTER13

Highlights
Chapter 14: Screen
Programming

Settings
Feedback

ABAPListViewerOutputPart2

Sign Out

Inthischapter,youwillcontinuethegenerationofALVoutputthatyou
startedintheprecedingchapter.WhateverALVfeaturesyou
implementedbyusingtheclassCL_GUI_ALV_GRIDwillbeimplemented
againinthischapterbyusingtheclassCL_SALV_TABLE.
Thischapteralsopresentstwodatabrowserprograms:thefirstprogram
usestheclassCL_GUI_ALV_GRID,andthesecondprogramusestheclass

Settings
10 days left in your trial. Subscribe.

Feedback

CL_SALV_TABLE.ThesedatabrowsersarelikethetransactioncodeSE16
databrowser.Ontheopeningscreen,youinputatableorviewname.
Thefieldsofthattableorviewaredisplayedwithcheckboxes,enabling

Sign Out

youtoselectordeselectthem.Afterfieldselection,youclicktheOutput
buttonontheapplicationtoolbartooutputtheselectedfieldsdatainan
ALV.
ALVOutputUsingtheClassCL_SALV_TABLE
YouhaveusedvariousfeaturesoftheclassCL_GUI_ALV_GRIDtoproduce
ALVoutput.Inthissection,youlllearnaboutthedeploymentoftheALV
classCL_SALV_TABLE.
YoumusthaveobservedthattheclassCL_GUI_ALV_GRIDisamixtureof

classandprocedureorientation.Forinstance,thewayyouwereusing
Enjoy Safari? Subscribe Today

thefieldcataloginternaltabledoesnotcomplywiththeideaof

encapsulation.Whatdataobjecttheclassisusingshouldnotbeapparent
totheuseroftheclass.Ifthatuserwantstosetthepropertiesofa
subobjectorcomponentofaclass,itshouldbeintermsofGETandSET
statementsandnotintermsofdirectlyaccessingthedataobjectusedby
theclassandmanipulatingthedataobjectasyouweredoinginthe
contextoffieldcatalogmanipulation.
MainALVclass:CL_SALV_TABLE
TheclassCL_SALV_TABLEismoreclassorOOPSorientedthantheclass
CL_GUI_ALV_GRID,which,asIvepointedout,isamixtureofclassand
procedureorientation.WiththeclassCL_SALV_TABLE,youhavethe
optiontoeitherlocatetheALVoutputinacontainerorhavetheoutput
occupythefullscreenwithoutusingacontainer.
IfyouoptforALVoutputwithoutacontainerandoccupyingthefull
screen,youdonthavetodoanyscreenprogramming.Youdonthaveto
createascreen,givethestatementCALLSCREEN,orprovidePBOandPAI
coding.Thatmakesthingsrelativelysimple.
TogenerateALVoutputwiththeclassCL_SALV_TABLE,youusethestatic
methodFACTORYandtheinstancemethodDISPLAY.
FACTORYhasthefollowingparameters:
LIST_DISPLAY(importing):Theparameterisrelevantonlywhen
ALVoutputisnotinacontainer(thatis,fullscreenoutput).The
parametercanassumethevalueXorblank.WhenthevalueXis
passedtoit,theoutputdisplaysasasocalledclassicallistwitha
twodimensionalvisualeffect.Whenthedefaultvalue''is
passed,theoutputhasagridorthreedimensionalvisualeffect.You
cannotpassthisparameterthevalueXiftheALVoutputistobe
locatedinsideacontainer.IfXispassedandtheALVoutputis
locatedinsideacontainer,aruntimeerrorresults.

https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch13.xhtml

1/17

1/5/2016

Chapter13:ABAPListViewerOutputPart2SAPABAP:HandsOnTestProjectswithBusinessScenarios

R_CONTAINER(importing):Thisreferencevariablepointstothe
instanceofacontainerclass.Youusethisparameterifyouare
locatingALVoutputinsideacontainer.
CONTAINER_NAME(importing):Thisisthecontainernameasgiven
intheAttributesdialogboxforthescreenelement.Youusethis
parameterifyouarelocatingALVoutputinsideacontainer.You
shouldprovideoneofthetwoparameters:eitherR_CONTAINERor
CONTAINER_NAME.
R_SALV_TABLE(exporting):Thisreferencevariableisdeclaredwith
typereftothesameclass,CL_SALV_TABLE.TheFACTORYmethod
createsaninstanceoftheclasswiththepassedvariable.The
executionoftheCONSTRUCTORmethodCREATEOBJECTis
unnecessary.
T_TABLE(changing):Thisinternaltablecontainsthedatatobe
output.
AfterexecutingtheFACTORYmethod,youhavetoexecutetheDISPLAY
methodtocreatetheALVoutput.
Thefollowingsourcecodeillustratesthesyntax:

DATA:CURRENCY_TABTYPESTANDARDTABLEOFTCURT,
ALV_GRIDTYPEREFTOCL_SALV_TABLE.
STARTOFSELECTION.
SELECT*FROMTCURTINTOTABLECURRENCY_TABWHERESPRAS=SYLANGU.
CALLMETHODCL_SALV_TABLE=>FACTORY
EXPORTING
LIST_DISPLAY='X'
IMPORTING
R_SALV_TABLE=ALV_GRID
CHANGING
T_TABLE=CURRENCY_TAB.
ALV_GRID>DISPLAY().

Youcantestthissourcecode.
ThisoutputstheclassicalALVlist(fullscreen)withatwodimensional
visualeffect.Youdonthavetocreateascreenandprovidetheassociated
screenprogramming.IfyouomittheLIST_DISPLAYparameterorpassas
LIST_DISPLAY='',theoutputwillhaveathreedimensionalvisual
effect(grid).ForfullscreenALVoutputnotinacontainer,theALV
toolbarreplacestheapplicationtoolbar.
SubobjectsoftheClassCL_SALV_TABLE
Youneedtheprogramtohavemorecapabilities,soyoucandothe
following:changethepropertiesofthefieldsorcolumnsthatareoutput
(equivalenttothefieldcatalogcapabilities),controltheoverall
appearanceoftheoutput(forexample,thegridtitle),andenabletheend
usertosaveandretrievetheALVlayouts.
Andfinally,youwouldliketotriggereventstomodifythedefaultALV
toolbar,tocreateinteractivelists(viatheDOUBLE_CLICKevent),andto
provideaserialnumberintheALVoutputthatyoushouldbeableto
generatedynamicallyastheenduserchangeslayoutsorloadssaved
layouts.Inshort,whateveryoudidwiththeALVoutputwhenusingthe
classCL_GUI_ALV_GRID,youshouldbeabletodowhenusingtheclass
CL_SALV_TABLE.
ToprovidethesecapabilitieswiththeclassCL_SALV_TABLE,youwilluse
GETsubobjectsandSETsubobjectsstatements.
Forexample,theprecedingcodesnippettooutputALVbydefaultdoes
notprovidethefullsetofdefaultbuttonsontheALVtoolbar.Toprovide
thefullset,youhavetogetthesubobjectFUNCTIONSoftheALVobjectby
usingtheGET_FUNCTIONSmethodofthemainclassCL_SALV_TABLE.The
methodGET_FUNCTIONSwillreturnareferencetotheinstanceofthe
subobjectFUNCTIONS.Usingthisreferencevariable(refertothe
parametersofthemethodGET_FUNCTIONSoftheclassCL_SALV_TABLEin
SE24),youwillexecutethemethodSET_ALLtoplaceafullsetofdefault
buttonsontheALVtoolbar.Theextrasourcecodetoplacethefullsetof
defaultbuttonsontheALVtoolbarfollows.
Datadeclaration:
DATA:FUNCTIONSTYPEREFTOCL_SALV_FUNCTIONS_LIST.
....

SourcecodebeforetheALV_GRID>DISPLAY()statement:

FUNCTIONS=ALV_GRID>GET_FUNCTIONS().
FUNCTIONS>SET_ALL(VALUE='X').

YoucanaddbuttonstotheALVtoolbarbyusingtheADD_FUNCTION

https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch13.xhtml

2/17

1/5/2016

Chapter13:ABAPListViewerOutputPart2SAPABAP:HandsOnTestProjectswithBusinessScenarios

method.Youalsocanenableanddeletebuttons.Refertothemethodlist
oftheclassesCL_SALV_FUNCTIONS_LIST,CL_SALV_FUNCTIONS,
CL_SALV_FUNCTION,andCL_SALV_FUNCTIONAL_SETTINGS.
Inasimilarmanner,ifyouwanttomanipulatethepropertiesoftheALV
outputfieldsorcolumns,youhavetogettheappropriatesubobjectsand
settheirproperties.Ifyouwanttoimpartgreencolorinanintensified
backgroundtothefieldorcolumnLTEXT,forexample,youusethe
followingsourcecode:
Datadeclaration:

DATA:COLUMNSTYPEREFTOCL_SALV_COLUMNS_TABLE,
COLUMNTYPEREFTOCL_SALV_COLUMN_TABLE,
COL_STRUTYPELVC_S_COLO."DDICstructure

SourcecodebeforetheALV_GRID>DISPLAY()statement:

COLUMNS=ALV_GRID>GET_COLUMNS().
COLUMN?=COLUMNS>GET_COLUMN(COLUMNNAME='LTEXT').
COL_STRUCOL=5."colorcode
COL_STRUINT=1."intensifiedon
COL_STRUINV=0."inverseoff
COLUMN>SET_COLOR(VALUE=COL_STRU).

ThemethodGET_COLUMNSgetsinstancesofallthefieldsorcolumnsofthe
ALVoutput.ThemethodGET_COLUMNgetsaninstanceofaspecifiedfield
orcolumn.ThemethodSET_COLORsetsthecolorofthespecificfieldor
column.
Somepropertysettingsoperateonallfieldsorcolumns,andothers
operateonasinglefieldorcolumn.Ifyouwantallthefieldorcolumn
widthsoptimized,youuseCOLUMNS>SET_OPTIMIZE(VALUE='X').
Inthiswaywithsubobjects,youcanhavefiltersettings,sortsettings,
aggregations,selections,events,andsoforth.Table131listsclasses
usedtoaccesssubobjectsofthemainclassCL_SALV_TABLE.
Table131.ClassesUsedtoAccessSubobjectsofCL_SALV_TABLE

SerialNumber

ClassName

CL_SALV_AGGREGATIONS

CL_SALV_AGGREGATION

CL_SALV_COLUMNS_TABLE

CL_SALV_COLUMN_TABLE

CL_SALV_EVENTS_TABLE

CL_SALV_FUNCTIONS_LIST

CL_SALV_FILTERS

CL_SALV_FILTER

CL_SALV_LAYOUT

10

CL_SALV_SELECTIONS

11

CL_SALV_SELOPT

https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch13.xhtml

3/17

1/5/2016

Chapter13:ABAPListViewerOutputPart2SAPABAP:HandsOnTestProjectswithBusinessScenarios

12

CL_SALV_SORTS

13

CL_SALV_SORT

Youshouldspendsometimefamiliarizingyourselfwiththeclass
CL_SALV_TABLEanditsassociatedclassesandsubclasses.Theupcoming
exercisesfurtherillustratetheuseofCL_SALV_TABLE.
HandsonExercise:CustomerwiseSalesSummaryofa
SpecifiedCompanyCodeasALVOutput:UseClass
CL_SALV_TABLE
ChangeFieldorColumnPropertiesProvideforSaveLayoutsFacility,
Etc.
Thishandsonexerciseisequivalenttothepriorprogram,
YCL_CH12_02_ALV_FCAT_ETCthatusedtheclassCL_GUI_ALV_GRID.Inthis
program,YCL_CH13_01_USE_CL_SALV_TABLE,youcontroltheoutputfield
properties,setupaggregationfortheNETWRfield,controltheoverall
appearanceoftheALVoutput,andprovideforthesavingoflayouts.
YouwilllocateaninstanceoftheALVclassCL_SALV_TABLEinsidean
instanceofthecontainerclassCL_GUI_CUSTOM_CONTAINER.Youwill
placetheinstanceofthecontainerclassCL_GUI_CUSTOM_CONTAINERina
customcontrol.Thispartofthearchitectureisidenticaltotheoneyou
wereusingfortheALVclassCL_GUI_ALV_GRID.
Youcancopythescreen,status,andtitlefromtheearlierprogram,
YCL_CH12_02_ALV_FCAT_ETC.
Asstatedearlier,thefieldcatalogconceptintheclassCL_GUI_ALV_GRID
isimplementedintheclassCL_SALV_TABLEwithmethodsGET_COLUMNS,
GET_COLUMN,andSET_COLUMN.
TheclassbasederrorhandlingaftercallingtheclassmethodFACTORYis
throughTRY...ENDTRYandtheCATCHblock.Theerrorreportingisdone
insideastaticmethodofalocalclass.
ThiserrorreportingusesthemethodGET_MESSAGE,whichreturnsthe
valuesofthesystemfieldsSYMSGID,SYMSGNO,SYMSGV1,SYMSGV2,SY
MSGV3,andSYMSGV4intothecorrespondingfieldsofalocallydeclared
structurereferringtotheDDICstructureBAL_S_MSG.Youthenissuethe
messagebyusingthefieldsofthisstructure.Themessagecouldbe
fetchedandissuedintheCATCHblockitself.Youwilluseaclassmethodin
alocalclassforthistask.
YouwilluseaninternaltablewiththeDDICstructure
YCL_CH06_SALES_SUM_STRU(havingtheKURRFfield)forloadingthedata,
fetchingrowbyrow,andcalculatingtheamount.Butyouwillusean
internaltablewiththeDDICstructureYCL_CH12_SALES_SUM_STRU(not
havingtheKURRFfield)togeneratethefinaldatatobepassedtothe
FACTORYmethod.ThisisbecausetheFACTORYmethodbydefaultoutputs
allthefieldsoftheinternaltablepassedtoit.Youdonotwantthe
ExchangeRatefield(KURRF)tobeoutput.
Thefollowingsourceprogram,whichincludeselaboratecomments,
shouldclarifythenewmethodsandfeaturesusedintheprogram:

REPORTYCL_CH13_01_USE_CL_SALV_TABLE.
************************************************************
*ALVReportWITHclassCL_SALV_TABLE:**
*ForaSpecificCompanyCode:CustomerWiseSalesSummary**
************************************************************
********************************************************************
*youcancopyscreen100,status'STAT1'andtitle'TITLE1'from**
*program'YCL_CH12_02_ALV_FCAT_ETC'**
***
*declarations:**
*==============**
*localclassdefinitiondeferred**
***
*globaldata**
***
*1,2.internaltable,struforcustomerwisesalessummary**
*(thiscontainsthefieldKURRFtoconvertamounts.thisis**
*usedtogeneratethecustomerwisesalessummary)**
*3.internaltablecustomerwisesalessummary**
*(thisdoesnotcontainthefieldKURRF.passedasparameter**
*tothe'FACTORY'method)**
*4.referencevariableinstanceof'CL_SALV_TABLE'**
*5.instanceof'CL_GUI_CUSTOM_CONTAINER'**
*6.instanceof'CX_SALV_MSG'exception**
*7.instanceof'CL_SALV_FUNCTIONS_LIST'**
*8.instanceof'CL_SALV_COLUMNS_TABLE'**
*9.instanceof'CL_SALV_COLUMN_TABLE'**
*10.instanceof'CL_SALV_AGGREGATIONS'**
*11.instanceof'CL_SALV_AGGREGATION'**
*12.instanceof'CL_SALV_LAYOUT'**

https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch13.xhtml

4/17

1/5/2016

Chapter13:ABAPListViewerOutputPart2SAPABAP:HandsOnTestProjectswithBusinessScenarios

*13.layoutkeyequivalenttoDISVARIANTin'CL_GUI_ALV_GRID'**
*14.structuretopasscolorspecificationtocolumn**
*15.OK_CODE**
*16.companycodedescriptionfromT001**
*17.currencycodeofcompanycodefromT001**
***
*localclassforexceptionreportingof'CL_SALV_TABLE'**
*definition&implementation**
***
*PARAMETERSpromptforcompanycode**
***
*STARTOFSELECTION**
*==================**
*retrievesinglerowfromT001**
*setupSELECT..COLLECT..ENDSELECTforgeneratingsummary**
*sortcustomerwisesalessummaryinternaltablebyKUNNR**
*CALLSCREEN100.**
***
*PBOcode**
*========**
*setpfstatus,settitle**
*createinstanceofcustomcontainer**
*call'FACTORY'method**
***
*<ALVinstance>>GET_COLUNNS.**
*setcolumnpropertiesKUNNR:EDIT_MASK..**
*setcolumnpropertiesallcolumnsforcolor**
***
*<ALVinstance>>GET_AGGREGATIONS.setaggregationforNETWR**
***
*<ALVinstance>>GET_FUNCTIONS.setforallfunctions**
*setforfunctions..LAYOUT_CHANGE,..LAYOUT_MAINTAINand**
*..LAYOUT_SAVE**
***
*<ALVinstance>>GET_LAYOUT.setforlayout**
***
*<ALVinstance>>DISPLAY().**
***
*PAIcode**
*========**
*checkOK_CODE='BACK',ifsoSETSCREEN0.LEAVESCREEN.**
***
********************************************************************
CLASSLCLASSDEFINITIONDEFERRED.
DATA:
SALES_TABTYPESTANDARDTABLEOF"datasummary
YCL_CH12_SALES_SUM_STRUWITHHEADERLINE,
SALES_STRUTYPELINEOFYCL_CH06_SALES_SUM_TAB,
ALV_GRIDTYPEREFTOCL_SALV_TABLE,
CCONTTYPEREFTOCL_GUI_CUSTOM_CONTAINER,
ERRORTYPEREFTOCX_SALV_MSG,"SALVexception
FUNCTIONSTYPEREFTOCL_SALV_FUNCTIONS_LIST,"functions
COLUMNSTYPEREFTOCL_SALV_COLUMNS_TABLE,"getcolumns
COLUMNTYPEREFTOCL_SALV_COLUMN_TABLE,"getcolumn
AGGSTYPEREFTOCL_SALV_AGGREGATIONS,"getaggregations
AGGTYPEREFTOCL_SALV_AGGREGATION,"getaggregation
LAYOUT_REFTYPEREFTOCL_SALV_LAYOUT,"forlayoutmanagement
LAYOUT_KEYTYPESALV_S_LAYOUT_KEY,"forlayoutmanagement
COL_STRUTYPELVC_S_COLO,"forcolor
OK_CODETYPESYUCOMM,
BUTXTTYPET001BUTXT,
WAERSTYPET001WAERS.
**********************************************
PARAMETERS:CCODETYPEVBRKBUKRSDEFAULT3000.
*************************************************
*************************************************
CLASSLCLASSDEFINITION.
PUBLICSECTION.
CLASSMETHODS:
SALV_ERROR_MSG
IMPORTING
ERRORTYPEREFTOCX_SALV_MSG.
ENDCLASS.
CLASSLCLASSIMPLEMENTATION.
METHODSALV_ERROR_MSG."reporterrorinALV
DATA:MESSAGTYPEBAL_S_MSG,
TYPETYPECVALUE'E'.
MESSAG=ERROR>GET_MESSAGE().
MESSAGEIDMESSAGMSGID
TYPETYPE"TYPEMESSAGMSGTY
NUMBERMESSAGMSGNO
WITHMESSAGMSGV1
MESSAGMSGV2
MESSAGMSGV3
MESSAGMSGV4.
ENDMETHOD.
ENDCLASS.
*************************************************
*************************************************
STARTOFSELECTION.
SELECTSINGLEBUTXTWAERSFROMT001INTO(BUTXT,WAERS)WHERE

https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch13.xhtml

5/17

1/5/2016

Chapter13:ABAPListViewerOutputPart2SAPABAP:HandsOnTestProjectswithBusinessScenarios

BUKRS=CCODE.
SELECTKUNNRNAME1ORT01NETWRKURRFFROMYCL_CH05_VBRKKNAINTO
CORRESPONDINGFIELDSOFSALES_STRUWHEREBUKRS=CCODE.
SALES_STRUNETWR=SALES_STRUNETWR*SALES_STRUKURRF.
SALES_STRUKURRF=0."topreventoverflow
MOVECORRESPONDINGSALES_STRUTOSALES_TAB.
COLLECTSALES_TABINTOSALES_TAB.
ENDSELECT.
SORTSALES_TABBYKUNNR.
CALLSCREEN100.
*********************************************
*&*
*&ModuleSTATUS_0100OUTPUT
*&*
MODULESTATUS_0100OUTPUT.
SETPFSTATUS'STAT1'.
SETTITLEBAR'TITLE1'WITHCCODEBUTXTWAERS.
CREATEOBJECTCCONT
EXPORTING
CONTAINER_NAME='CONT'.
*****callstaticmethodFACTORY*****
TRY.
CALLMETHODCL_SALV_TABLE=>FACTORY
EXPORTING
R_CONTAINER=CCONT"referencetocontainer
*LIST_DISPLAY=''"''elseruntimeerror
IMPORTING
R_SALV_TABLE=ALV_GRID"getinstance
CHANGING
T_TABLE=SALES_TAB[]."data
CATCHCX_SALV_MSGINTOERROR.
CALLMETHODLCLASS=>SALV_ERROR_MSG
EXPORTING
ERROR=ERROR.
ENDTRY.
*******optimizecolumnwidth********
COLUMNS=ALV_GRID>GET_COLUMNS().
COLUMNS>SET_OPTIMIZE(VALUE='X').
****colortocolumns
COLUMN?=COLUMNS>GET_COLUMN(COLUMNNAME='KUNNR').
COLUMN>SET_EDIT_MASK(VALUE='').
COL_STRUCOL=1.
COLUMN>SET_COLOR(VALUE=COL_STRU).
COLUMN?=COLUMNS>GET_COLUMN(COLUMNNAME='NAME1').
COL_STRUCOL=2.
COLUMN>SET_COLOR(VALUE=COL_STRU).
COLUMN>SET_LOWERCASE().
COLUMN?=COLUMNS>GET_COLUMN(COLUMNNAME='ORT01').
COL_STRUCOL=3.
COLUMN>SET_COLOR(VALUE=COL_STRU).
COLUMN>SET_LOWERCASE().
COLUMN?=COLUMNS>GET_COLUMN(COLUMNNAME='NETWR').
COL_STRUCOL=4.
COLUMN>SET_COLOR(VALUE=COL_STRU).
****aggregationsettingforNETWR*****
AGGS=ALV_GRID>GET_AGGREGATIONS().
AGG=AGGS>ADD_AGGREGATION(COLUMNNAME='NETWR'AGGREGATION=1).
************enableall(full)defaultfunctions*********
FUNCTIONS=ALV_GRID>GET_FUNCTIONS().
*FUNCTIONS>SET_DEFAULT().
FUNCTIONS>SET_ALL()."DEFAULT().
*****setmorefunctions*****
FUNCTIONS>SET_LAYOUT_CHANGE('X').
FUNCTIONS>SET_LAYOUT_MAINTAIN('X').
FUNCTIONS>SET_LAYOUT_SAVE('X').
*****forsave,maintainlayouts*****
LAYOUT_REF=ALV_GRID>GET_LAYOUT().
LAYOUT_KEYREPORT='YCL_CH13_01_USE_CL_SALV_TABLE'.
LAYOUT_REF>SET_KEY(LAYOUT_KEY).
LAYOUT_REF>SET_SAVE_RESTRICTION('1').
"equivalenttotheI_SAVEparameterin
"themethodSET_TABLE_FOR_FIRST_DISPLAY
*
ALV_GRID>DISPLAY().
ENDMODULE."STATUS_0100OUTPUT

https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch13.xhtml

6/17

1/5/2016

Chapter13:ABAPListViewerOutputPart2SAPABAP:HandsOnTestProjectswithBusinessScenarios

*&*
*&ModuleUSER_COMMAND_0100INPUT
*&*
MODULEUSER_COMMAND_0100INPUT.
IFOK_CODE='BACK'.
SETSCREEN0.
LEAVESCREEN.
ENDIF.
ENDMODULE."USER_COMMAND_0100INPUT

Figure131and132showtheinitialoutput.

Figure131.Initialoutputoftheprogram
YCL_CH13_01_USE_CL_SALV_TABLE

Figure132.OutputofYCL_CH13_01_USE_CL_SALV_TABLE

Changethelayoutinthefollowingmanner:
Field/columnorder:
City(ORT01)
Name(NAME1)
Customer(KUNNR)
NetValue(NETWR)

Sortorder:
City(ORT01),Ascending
Name(NAME1),Ascending

Figure133showstheoutputaftermakingthesechangesinthelayout.

Figure133.Outputafterchangesinlayout

Thisclassissortingtextdataonthetextdatathatistranslatedor
convertedtouppercase.
YoucansaveandretrievelayoutsasyoudidforALVoutputwhenusing
theclassCL_GUI_ALV_GRID.YoucangenerategraphicsandperformABC
analysisaswell.
HandsonExercise:CustomerwiseSalesSummaryandDetailof
aSpecifiedCompanyCodeasALVOutput:UseClass
CL_SALV_TABLE
TriggerCL_SALV_TABLEEvents:USER_COMMAND,

https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch13.xhtml

7/17

1/5/2016

Chapter13:ABAPListViewerOutputPart2SAPABAP:HandsOnTestProjectswithBusinessScenarios

AFTER_USER_COMMAND,DOUBLE_CLICKAND
CL_GUI_DIALOGBOX_CONTAINEREvent:CLOSE
Inthisexercise,programYCL_CH13_02_SALV_EVENTSusingtheALVclass
CL_SALV_TABLE.Youwillimplementallthefeaturesthatyou
implementedearlierforYCL_CH12_03_ALV_EVENTS(whichusedtheclass
CL_GUI_ALV_GRIDanddemonstratedevents).Inthisexercise,eventsare
beingdemonstrated.Becausethisisaparalleloftheearlierexerciseand
anextensionoftheprecedingexercise,onlytheadditionalfeatures
incorporatedinthisprogramaredescribed.
EventsDOUBLE_CLICK,CLOSE,PutButtonsonALVToolbarand
USER_COMMAND
EventDOUBLE_CLICK:ThehandlingofeventDOUBLE_CLICK,which
youtriggerforthefirstinstanceoftheALVclasshere,issimilartothe
wayyouhandledthiseventwhenusingtheclassCL_GUI_ALV_GRID.The
differencesaredescribedhere.TheimportingparameterROWinthe
presentclassdoesnothaveacomponentthroughwhichyoucan
determinewhetherthedoubleclickedrowisaregularroworatotalor
subtotalrow.TheimportingparameterE_ROWoftheeventDOUBLE_CLICK
intheclassCL_GUI_ALV_GRIDhadacomponentROWTYPE.WhenROWTYPE
containsaninitialvalue,youknowthataregularrowwasdouble
clicked,notatotalorsubtotalrow.Inthepresentusageofclass
CL_SALV_TABLE,themethodGET_SELECTIONSreturnsaninstance
referencetotheclassCL_SALV_SELECTIONS.Thisclasshasamethod,
GET_CURRENT_CELL,whichreturnsvaluesintheDDICstructure
SALV_S_CELL.ThisstructurehasafieldROW,whichcontainstherow
numberforregularrows,aswellasnegativevaluesforsubtotalortotal
rows.YouwillcheckthatthevaluesofthefieldROWaregreaterthanzero
inordertoexecutelinesinthehandlermethodoftheevent
DOUBLE_CLICK.Whenyoudoubleclickasubtotalortotalline,nothing
shouldhappen.Onlywhenyoudoubleclickaregularrow(containing
customercode,name,amount,andsoforth)shouldthebillingdocuments
ofthecustomerbeoutputinthesecondinstanceoftheALVgrid.
WhenyouareonthesecondinstanceofALVoutputinadialogbox
container,youwantthefirstinstanceoftheALVoutputdisabled.Youdid
thisbyusingtheENABLEinstancemethodoftheclassCL_GUI_ALV_GRIDin
thepreviousexerciseprogramYCL_CH12_03_ALV_EVENTS.Youpassedan
exportparameter''totheENABLEmethod.ThereisnoENABLEmethod
availableintheclassCL_SALV_TABLE.SoyouwillusetheENABLEinstance
methodofthecontainerclassCL_GUI_CUSTOM_CONTAINERtodisablethe
firstALVoutputwhenyouhaveproducedthesecondALVoutput.Youwill
passanexportparameter''totheENABLEmethodoftheclass
CL_GUI_CUSTOM_CONTAINER.
EventCLOSE:TheCLOSEeventforthedialogboxcontainerisidentical
totheearlierexercisesandneedsnoelaborationhereexceptthatyou
usetheENABLEmethodofthecontainerclassCL_GUI_CUSTOM_CONTAINER,
astheALVgridclassCL_SALV_TABLEdoesnothaveasimilarmethod.
AfterexecutionoftheENABLEmethodwithanexportparameterXyou
willbeabletooperatethefirstALVoutputagainafterclosingthesecond
ALVoutput.
PlaceButtonsonALVToolbar:Withthepresentclass
CL_SALV_TABLE,youdonotneedtotriggeraneventtoplaceyourcustom
buttonsontheALVtoolbar.WhenusingtheclassCL_GUI_ALV_GRID,you
neededtotriggertheeventTOOLBARtoplaceyourcustombuttons.Inthis
exercise,youwillusethemethodADD_FUNCTIONofclass
CL_SALV_FUNCTIONS_LISTtodothesame.TheADD_FUNCTIONmethodcan
beexecutedbeforeexecutingtheDISPLAYmethod.Youwillplacea
custombuttonontheALVtoolbarwithfunctioncodeBACKtonavigate
backtotheselectionscreen.
EventUSER_COMMAND:IntheclassCL_GUI_ALV_GRID,youused
theeventUSER_COMMANDtoreacttoyourownpositionedbuttonsonthe
ALVtoolbar.YouusedthiseventtoreacttothepressingoftheBACK
buttontonavigatebacktotheselectionscreen.Whatyouweredoingin
thePAIeventforreactingtobuttonontheapplicationtoolbarinthelast
exercisehasbeenshiftedtotheeventhandlermethodofevent
USER_COMMANDofthefirstinstanceofALVoutput.
EventAFTER_USER_COMMAND:Youwillusethe
AFTER_USER_COMMANDeventtoadjusttheserialnumberfielduponchange
oflayoutorloadingoflayout.WhenusingtheclassCL_GUI_ALV_GRID,
themethodGET_FILTERED_ENTRIESretrievedthefilteredout(omitted)
rowsatthefrontend.Theavailabilityofthesefilteredoutrowssavedyou
thetaskofretrievingfiltersettingsyouretrievedonlythesortsettings.
AsimilarmethodisnotavailableinthepresentclassCL_SALV_TABLE.
Therefore,youmustretrievefiltersettingsforthevariables,andconvert
thefiltersettingstorangevaluesforthevariables(internaltableofSIGN,
OPTION,LOW,andHIGHfields).Youdeclaretherangevariables(for
example,KUNNR_SO)withtheHEADERLINEclauseintheprogramglobal

https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch13.xhtml

8/17

1/5/2016

Chapter13:ABAPListViewerOutputPart2SAPABAP:HandsOnTestProjectswithBusinessScenarios

area.TheycouldhavebeendeclaredinthePRIVATESECTIONofthelocal
class.Inthiscase,theclauseHEADERLINEwouldnothavebeenused,and
separatelynamedstructureswouldhavebeendeclaredandused.
Usingtherangevaluesofthevariables,youbuildanothercustomerwise
salessummaryinternaltablecontainingonlythedataasperthefilter
settings.Whenbuildingthissecondinternaltable,therangevaluesof
fieldsKUNNR,NAME1,andORT01areappliedintheSELECTstatements
WHEREconditionwhenretrievingdatafromthedatabaseview.Therange
valuesofthefieldNETWRareappliedinanIFstatementwhengenerating
theserialnumber.ThisisbecausetherangeconditionforNETWRhastobe
appliedtothetotal,andnottoindividualrowsretrievedfromthe
databaseview.Thissecondcustomerwisesalessummaryinternaltable
isgeneratedintheeventhandlermethodoftheevent
AFTER_USER_COMMAND.Usingthissecondinternaltableasareference,
youaregeneratingtheserialnumberfieldinyouroriginalinternaltable
ofthecustomerwisesalessummary.YouhaveomittedtheNAME1and
ORT01fieldsinthestructureofthesecondinternaltableofcustomerwise
salessummary.
Theeventshouldbeexecutedonlyiftheuserhasdoneoneofthe
following:
Changedthelayout
Selectedalayout
OpenedandoperatedtheFilterdialogbox
OpenedandoperatedtheSortAscendingdialogbox
OpenedandoperatedtheSortDescendingdialogbox
ThisiswhatyouaredoingwithaCHECKstatementatthebeginningofthe
method.
RegistrationofHandlerMethodsofClassCL_SALV_TABLE:
WhenusingtheALVclassCL_SALV_TABLEforeventhandlermethod
registration,youhavetofirstexecutetheGET_EVENTmethodofthemain
classCL_SALV_TABLE.Thismethodreturnsaninstancereferencetothe
classCL_SALV_EVENTS_TABLE.IntheSETstatement,insteadofspecifying
theinstanceoftheclassafterthekeywordFOR,youspecifythereference
variablespecifiedintheGET_EVENTmethod.Forexample:

DATA:EVENT_REFTYPEREFTOCL_SALV_EVENTS_TABLE,
LCLASS_REFTYPEREFTOLCLASS,
.......
CALLMETHODCL_SALV_TABLE=>FACTORY
EXPORTING
R_CONTAINER=CCONT
LIST_DISPLAY=''"elseruntimeerror
IMPORTING
R_SALV_TABLE=ALV_GRID1
CHANGING
T_TABLE=SALES_TAB[].
.........
EVENT_REF=ALV_GRID1>GET_EVENT().
CREATEOBJECTLCLASS_REF.
SETHANDLERLCLASS_REF>DB_CLICKFOREVENT_REF.
...

TheprogramisYCL_CH13_02_SALV_EVENTS,andthefullsourcecodecan
befoundinthesourcecoderesource.
Whenthisprogramischeckedforsyntax,itissuesawarningmessage:
TheexceptionCX_SALV_NOT_FOUNDisneithercaughtnorisitdeclared
intheRAISINGclauseofDB_CLICK.
ThiswarningarisesbecausetheTRY...ENDTRYblockwiththeCATCH
statementisinsidethemethodDB_CLICK.ThemethodDB_CLICKisan
eventhandlermethod.YoucannotspecifytheRAISINGclauseinthe
signatureofthismethod.
Youcanignorethiswarning,activatetheprogram,andexecuteit.Butif
youarefastidiousandwanttoeliminatethismessage,youcanlocateall
thesourcecoderelatingtoinvocationoftheclassmethodFACTORYinside
asubroutineandspecifytheRAISINGclauseinthesubroutineinterface.
Figure134showstheoutput.

https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch13.xhtml

9/17

1/5/2016

Chapter13:ABAPListViewerOutputPart2SAPABAP:HandsOnTestProjectswithBusinessScenarios

Figure134.OutputofYCL_CH13_02_SALV_EVENTS

Scrolldowntoserialnumber31,customercode3271.Doubleclickthis
customer,andthedetailedALVoutputappears,asshowninFigure135.

Figure135.Thecustomerssummaryanddetailedoutput

TheBackbuttonappearsontheALVtoolbar.TheDOUBLE_CLICKeventfor
thefirstinstanceoftheALVisworking.Youcantesttheexecutionofthe
othereventhandlermethodsforthefollowingevents:
CLOSE
USER_COMMAND
AFTER_USER_COMMAND
Youcancreateandsavelayoutsasyoudidintheearlierexercises.
Figure136showsthesavedlayouts.

Figure136.SavedlayoutsforYCL_CH13_02_SALV_EVENTS

Whenyouselectthelayout/LAYOUT2andscrolltothebottom,thescreen
inFigure137displays.

Figure137.Outputforthelayout/LAYOUT2

So,youhaveusedtheclassCL_SALV_TABLEandtriggeredtheevents
DOUBLE_CLICK,USER_COMMAND,andAFTER_USER_COMMANDtogeneratea
detailedsecondALVreport,reacttoyourpositionedALVtoolbarbutton,
andadjusttheserialnumberfieldinthefirstALVreporttobe
regeneratedeverytimeanALVlayoutchangeoccurs.
Youhavebeenabletoproducealmostidenticaloutputwiththeprograms
YCL_CH12_03_ALV_EVENTSandYCL_CH13_02_SALV_EVENTSbyusingthe
classesCL_GUI_ALV_GRIDandCL_SALV_TABLE,respectively.
ANoteonProblemswiththeClassCL_SALV_TABLE
Thereareacoupleofsignificantissuesyouneedtoknowaboutwhen
usingtheclassCL_SALV_TABLE.Wewilldiscussthosehere.
ProblemwithMultipleFieldsSort
IfyousetthelayoutformultiplefieldsortingintheChangeLayoutdialog
boxforexample,City(ORT01)andName1(NAME1),thiscreatesa
problem.Whenyousetsortsettingsinthismanner,youwantthedatato
besortedalphabeticallybycityandwithinthatcity,bycustomername:
first,allthecustomernamesstartingwithA,B,C..,inAtlantanext,all

https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch13.xhtml

10/17

1/5/2016

Chapter13:ABAPListViewerOutputPart2SAPABAP:HandsOnTestProjectswithBusinessScenarios

thecustomernamesstartingwithA,B,CinBerlin,andsoon.Inthe
sortsettings,Cityisthemajorfield,andName1istheminorfield.
Butatthepresentationserverlevel,theorderreverseseverytimeyou
opentheChangeLayoutdialogbox.Whenthesortsettingsareretrieved
intheeventhandlermethodAF_FNgeneratesserialnumbers,itfetches
thesettingsproperly,butatthefrontenditreversestheordereverytime
youopentheChangeLayoutdialogbox.Thishasbeentackledwithabit
oftweakedcode.ItisworkingokayexceptwhenyouentertheChange
LayoutdialogboxandusetheCancelbutton.Forsavingandloading
layouts,itworksokay.
MethodsofClassCL_SALV_SELOPT
Indoingthisexercise,whileconvertingthefiltervaluesintorange
values,youhadtousethemethodsGET_HIGH,GET_LOW,GET_OPTION,and
GET_SIGNoftheclassCL_SALV_SELOPT(referringtothemethodAF_FNin
thesourceprogram).TherewereproblemswiththemethodsGET_HIGH,
GET_LOW,andGET_OPTIONonoursystem,notrunningthelatestpatches.
NavigatetoSE24ClassBuilder,entertheclassnameCL_SALV_SELOPT,
andclickthedisplaybutton.Doubleclickanymethodtoseeitssource
code.
Thesemethodshavejustonelineofassignmentstatement.Forexample,
forGET_SIGN(whichisokay),thestatementsareasfollows:

methodget_sign.
value=me>sign.
endmethod.

HerearethestatementsforGET_OPTION:

methodget_option.
me>option=value.
endmethod.

Thisisobviouslyerroneous,astheassignmentisreversed.The
assignmentshouldhavebeenasfollows:
value=me>option.

Asimilarerrorhasbeencommittedforthetwoothermethods,GET_HIGH
andGET_LOW.Wehavemanagedtocorrectthiserroneoussituationby
usingtheimplicitenhancementoption,byinsertingsourcecodebefore
theSAPsourcecodeforthemethods.Figure138clarifiesthis.

Figure138.EnhancementcodeforthemethodGET_HIGH

Wehavealsodonesuchanenhancementforthetwoothermethods,
GET_HIGHandGET_LOW.
Ifyouarefacingthisproblem,wehopeyoumanageitwiththese
enhancements.
CreateDataBrowsersUsingtheClassesCL_GUI_ALV_GRID
andCL_SALV_TABLE
AsyoumayrecallfromChapter10,YCL_CH10_ILISTS05isageneric
programthatacceptsadatabasetableorviewthroughaPARAMETERS
statement.Thisprogramlistsallthefieldsoftheinputdatabasetable(or
view)alongwithcheckboxesthatenablefieldselections.Aftermaking
fieldselections,youpresstheOutputbuttonontheapplicationtoolbarto
retrievedatafortheselectedfieldsfromthedatabasetableorviewand
outputitbyemployingtheWRITEstatement.Thisprogramusesthe
featuresofdynamiccreationofdataobjects,fieldsymbols,andspecial
constructsoftheOpenSQLSELECTstatement.Datawasretrievedrowby
row(SELECT...ENDSELECT)intoadynamicallycreatedstructureand
outputfromthatstructure.Fieldsymbolswereemployedtoaddressthe
dynamicallycreatedstructureandthefieldsofthestructure.
ThenexttwohandsonexercisesarevariationsofthisChapter10
program.InsteadofusingtheWRITEstatementtooutput,youwilloutput
dataasALVreports.Thetwoprogramsresemblethetransactioncode
SE16databrowser.

https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch13.xhtml

11/17

1/5/2016

Chapter13:ABAPListViewerOutputPart2SAPABAP:HandsOnTestProjectswithBusinessScenarios

HandsonExercise:OutputSpecificSelectedFieldsofaSpecific
DatabaseTableorViewinALV:UseClassCL_GUI_ALV_GRID
ThecurrentYCL_CH13_03_ANY_TABLE_ALVusestheclass
CL_GUI_ALV_GRIDtooutputdata.
AsthemethodSET_TABLE_FOR_FIRST_DISPLAYofclassCL_GUI_ALV_GRID
acceptsdatatopopulatetheALVfromaninternaltable,youwillhaveto
createadynamicinternaltable,loadthisinternaltablewiththedata,
andpassittothechangingparameterIT_OUTTABofthemethod
SET_TABLE_FOR_FIRST_DISPLAY.
YouhavetohaveascreenwithacustomcontrolandanOK_CODEfieldin
theelementlist.
IntheATUSER_COMMANDarea,whenthefieldsareselected(thereare
buttonsontheapplicationtoolbartoselectordeselectallthelistedfields)
andyouclicktheOutputbutton,thestatementLEAVETOSCREEN100is
coded.Thisloadsscreen100andtriggersthePBOeventforthatscreen.
Youareswitchingfromlistmode(displayedasafieldlistwithcheck
boxesoutputfromtheWRITEstatement)toscreenmode.
InthePBOmodule,yousetastatus,setatitle,createaninternaltable
dynamically,loaddatafromthedatabasetableorviewintothe
dynamicallycreatedinternaltable,createaninstanceofcustom
container,andcreateaninstanceofanALVgrid.Youwillgeneratea
defaultfieldcatalogbyusingthedatabasetableorviewwiththefunction
moduleLVC_FIELDCATALOG_MERGE.Youwillretaininthefieldcatalog,
onlytherowsoftheselectedfields,deletingtherowsofunselectedfields.
Finally,youwillcallthemethodSET_TABLE_FOR_FIRST_DISPLAY.
InthePAImodule,youwillcheckforthefunctioncodeoftheBackbutton
andifso,youwillcallthedestructormethodforthecustomcontainer,
ALVgrid.Youwillhavetoswitchfromscreenmodetolistmodetoreturn
tothelistoffieldsofadatabasetableorview.Youareusingthe
statementLEAVETOLISTPROCESSINGtomakethisswitch.Thisisfor
navigatingbacktothelistoffieldswithcheckboxes.
Thatisall.Theextraprogramsourcecodefollows.
CopytheinterfacefromtheprogramYCL_CH10_ILISTS05andactivateit.
Perusethesourcecodewithitscomments.
Sourcecodeindeclarationpart:
DATA:
.....
******extracode*****
FCATTYPELVC_T_FCATWITHHEADERLINE,"internaltablefieldctlg.
ITABTYPEREFTODATA,"referencevariableitab
CONTTYPEREFTOCL_GUI_CUSTOM_CONTAINER,
"referencevariableccont.
ALV_GRIDTYPEREFTOCL_GUI_ALV_GRID,"referencevariableALVgrid
OK_CODETYPESYUCOMM,"OKCODE
INDXTYPEI."toaccessinternaltablerow
FIELDSYMBOLS:
...........
<iTAB>TYPEANYTABLE."fieldsymboltoaccessitab
CodeineventATUSERCOMMAND:
ATUSERCOMMAND.
.............
*****switchfromlisttoscreenmode,loadscreen100*****
LEAVETOSCREEN100.

SourcecodeinPBOmodule:

MODULESTATUS_0100OUTPUT.
*****retrievedata&loadinternaltable*****
CREATEDATAITABTYPESTANDARDTABLEOF(TAB_NAME).
ASSIGNITAB>*TO<ITAB>.
SELECT(SFIELDS_TAB)FROM(TAB_NAME)INTOCORRESPONDINGFIELDSOF
TABLE<ITAB>WHERE(CONDS_TAB)ORDERBY(ORDERBY_TAB).
*****createdefaultfieldcatalog*****
CALLFUNCTION'LVC_FIELDCATALOG_MERGE'
EXPORTING
I_STRUCTURE_NAME=TAB_NAME
CHANGING
CT_FIELDCAT=FCAT[]
EXCEPTIONS
INCONSISTENT_INTERFACE=1
PROGRAM_ERROR=2
OTHERS=3
.
IFSYSUBRC<>0.
MESSAGEIDSYMSGIDTYPESYMSGTYNUMBERSYMSGNO
WITHSYMSGV1SYMSGV2SYMSGV3SYMSGV4.
ENDIF.

https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch13.xhtml

12/17

1/5/2016

Chapter13:ABAPListViewerOutputPart2SAPABAP:HandsOnTestProjectswithBusinessScenarios

*****markrowsofunselectedfields*****
LOOPATFCATINTOFCAT.
INDX=SYTABIX.
READTABLEFIELDS_TABINTOFIELDS_STRUINDEXINDX.
IFFIELDS_STRUCBOX='X'.
FCATCOL_OPT='X'.
FCATTECH=''.
MODIFYFCAT.
CONTINUE.
ENDIF.
FCATFIELDNAME=''.
MODIFYFCAT.
ENDLOOP.
DELETEFCATWHEREFIELDNAME=''."deleterowsofunselectedfields
*****setpfstatus,title*****
SETPFSTATUS'STAT_SCR'.
SETTITLEBAR'TITLE02'WITHTAB_NAME.
****createinstancesofcustomcontainer,ALVgrid****
CREATEOBJECTCONT
EXPORTING
CONTAINER_NAME='CCONT'
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.
CREATEOBJECTALV_GRID
EXPORTING
I_PARENT=CONT
EXCEPTIONS
ERROR_CNTL_CREATE=1
ERROR_CNTL_INIT=2
ERROR_CNTL_LINK=3
ERROR_DP_CREATE=4
others=5
.
IFSYSUBRC<>0.
MESSAGEIDSYMSGIDTYPESYMSGTYNUMBERSYMSGNO
WITHSYMSGV1SYMSGV2SYMSGV3SYMSGV4.
ENDIF.
*****callmethodSET_TABLE_FOR_FIRST_DISPLAY*****
CALLMETHODALV_GRID>SET_TABLE_FOR_FIRST_DISPLAY
CHANGING
IT_OUTTAB=<ITAB>
IT_FIELDCATALOG=FCAT[]
EXCEPTIONS
INVALID_PARAMETER_COMBINATION=1
PROGRAM_ERROR=2
TOO_MANY_LINES=3
others=4
.
IFSYSUBRC<>0.
MESSAGEIDSYMSGIDTYPESYMSGTYNUMBERSYMSGNO
WITHSYMSGV1SYMSGV2SYMSGV3SYMSGV4.
ENDIF.
OK_CODE=''.
ENDMODULE."STATUS_0100OUTPUT

SourcecodeinPAImodule:
MODULEUSER_COMMAND_0100INPUT.
IFOK_CODE='BACK'."checkokcode
CALLMETHODALV_GRID>FREE."destructormethod
CALLMETHODCONT>FREE."destructormethod
*****releaseramrefvariables&internaltablesusedinPBO*****
FREECONT.
FREEALV_GRID.
FREEFCAT.
FREEITAB.
PERFORMLISTER.
LEAVETOLISTPROCESSING."getbacktoWRITEoutputmode
ENDIF.
ENDMODULE.

TheentiresourcecodeoftheprogramYCL_CH13_03_ANY_TABLE_ALVis
availableinthesourcecoderesource.
Figures139through1314showtheinputsandrespectiveoutputs.

https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch13.xhtml

13/17

1/5/2016

Chapter13:ABAPListViewerOutputPart2SAPABAP:HandsOnTestProjectswithBusinessScenarios

Figure139.InputofT001

Figure1310.SelectingfieldsfortableT001

Figure1311.OutputofselectedfieldsoftableT001

Figure1312.InputofLFA1

Figure1313.SelectingallfieldsoftableLFA1

Figure1314.OutputofallfieldsoftableLFA1

HandsonExercise:OutputSpecificSelectedFieldsofaSpecific
DatabaseTableorViewinALV:UseClassCL_SALV_TABLE
TheprograminthisexerciseYCL_CH13_04_ANY_TABLE_SALVisa
variationoftheprogramCL_CH13_03_ANY_TABLE_ALV.Insteadofusing
theALVclassCL_GUI_ALV_GRID,itusestheALVclassCL_SALV_TABLE.
Theprogramtakesasinputadatabasetableorview.Itliststhefieldsof
thisinputtableorviewwithcheckboxesthatenableyoutoselectthe
fieldstobeoutput.Aftermakingthefieldselections,youcanclickthe
Outputbuttonontheapplicationtoolbartodisplaytheselectedfieldsas
anALVreportusingtheclassYCL_SALV_TABLE.
Buttonsontheapplicationtoolbarenableyoutoselectordeselectall
fields.Theprogramdisplaysanalertifnofieldsareselectedwhenthe
Outputbuttonisclicked.Analertalsodisplaysifmorethan90fieldsare
selected,becausetheclassYCL_SALV_TABLEsupportsamaximumof90

https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch13.xhtml

14/17

1/5/2016

Chapter13:ABAPListViewerOutputPart2SAPABAP:HandsOnTestProjectswithBusinessScenarios

fieldsforoutput.
YoudonotlocatetheinstanceoftheYCL_SALV_TABLEinacontainer.The
ALVoutputinthisexerciseisfullscreen,withatwodimensionalvisual
effect(theclassicalALVlist).Youdonothavetocreateascreenyoudo
nothavetocodeforthePBOandPAImodules.
IntheversionofthisprogramusingtheALVclassCL_GUI_ALV_GRID,you
deletedtherowsinthefieldcatalogsinternaltablecorrespondingtothe
unselectedfields.ThatishowtheALVoutputappearsfortheselected
fields.AsimilarcapabilityisnotavailableintheALVclass
CL_SALV_TABLE.Tomaketheunselectedfieldsnotappearintheoutput,
youmustsetthemasTECHNICAL:

COLUMN>SET_TECHNICAL(VALUE='X')

CopytheinterfacefromtheprogramYCL_CH10_ILISTS05andactivateit.
Theextrasourcecodeindeclarations:
DATA:
.........
ITABTYPEREFTODATA,
ALV_GRIDTYPEREFTOCL_SALV_TABLE,
COLUMNSTYPEREFTOCL_SALV_COLUMNS_TABLE,
COLUMNTYPEREFTOCL_SALV_COLUMN,
LAYOUT_REFTYPEREFTOCL_SALV_LAYOUT,"forlayoutmanagement
LAYOUT_KEYTYPESALV_S_LAYOUT_KEY,"forlayoutmanagement
FUNCTIONSTYPEREFTOCL_SALV_FUNCTIONS_LIST.
FIELDSYMBOLS:........
<iTAB>TYPEANYTABLE."fieldsymboltoaccessitab

ThechangedsourcecodeintheATUSER_COMMANDevent
area,thenewsourcecodeusingtheclassCL_SALV_TABLE:

IFSYTFILL>90."nooffieldsselected>90
MESSAGES025(YCL_CH07_MCLASS01)WITH
TAB_NAMEDISPLAYLIKE'W'.
SYLSIND=SYLSIND1.
EXIT.
ENDIF.
******nopfstatus,asALVtoolbarreplacesapplicationtoolbar
SETTITLEBAR'TITLE02'WITHTAB_NAME.
**************retrievedata&output***********************
CREATEDATAITABTYPESTANDARDTABLEOF(TAB_NAME).
ASSIGNITAB>*TO<ITAB>.
SELECT(SFIELDS_TAB)FROM(TAB_NAME)INTOCORRESPONDINGFIELDSOF
TABLE<ITAB>WHERE(CONDS_TAB)ORDERBY(ORDERBY_TAB).
CALLMETHODCL_SALV_TABLE=>FACTORY
EXPORTING
LIST_DISPLAY=IF_SALV_C_BOOL_SAP=>TRUE
*R_CONTAINER=
*CONTAINER_NAME=
IMPORTING
R_SALV_TABLE=ALV_GRID
CHANGING
T_TABLE=<ITAB>
.
COLUMNS=ALV_GRID>GET_COLUMNS().
LOOPATFIELDS_TABINTOFIELDS_STRU.
IFFIELDS_STRUCBOX='X'.
CONTINUE.
ENDIF.
*****makeunselectedcolumnstechnicalcolumns*****
COLUMN=COLUMNS>GET_COLUMN(COLUMNNAME=FIELDS_STRUFIELDNAME).
COLUMN>SET_TECHNICAL(VALUE='X').
ENDLOOP.
LAYOUT_REF=ALV_GRID>GET_LAYOUT().
LAYOUT_KEYREPORT='YCL_CH13_04_ANY_TABLE_SALV'.
LAYOUT_REF>SET_KEY(LAYOUT_KEY).
LAYOUT_REF>SET_SAVE_RESTRICTION('2').
FUNCTIONS=ALV_GRID>GET_FUNCTIONS().
FUNCTIONS>SET_ALL()."DEFAULT().
FUNCTIONS>SET_LAYOUT_CHANGE('X').
FUNCTIONS>SET_LAYOUT_MAINTAIN('X').
FUNCTIONS>SET_LAYOUT_SAVE('X').
COLUMNS>SET_OPTIMIZE(VALUE='X').
ALV_GRID>DISPLAY().
FREEITAB.

ThecompletesourcecodeoftheprogramYCL_CH13_04_ANY_TABLE_SALV
isavailableinthesourcecoderesource.

https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch13.xhtml

15/17

1/5/2016

Chapter13:ABAPListViewerOutputPart2SAPABAP:HandsOnTestProjectswithBusinessScenarios

Figure1315throughFigure1318showtheinputandcorresponding
output.

Figure1315.Input

Figure1316.Errorindicatingthenumberoffieldsisgreaterthan
90

Figure1317.Selectingfields

Figure1318.Outputoftheselectedfields

TheALVtoolbarreplacestheapplicationtoolbar.
TheBackbuttonofthestandardtoolbarcanbeusedtonavigatebackto
thelistoffieldsforthetableorview.
WithaclassicalALVlist,youdonthavethecapabilitytosortandfilterin
theChangeLayoutdialogbox.Youcanonlyshuffleoromitcolumnsin
thedialogbox.YoucanperformfilteringwiththeFilterbuttonclickingit
popsupadialogbox.YoucansortwiththeSortbutton.Ifyouwantto
applymultiplefieldsorting,dontselectanycolumnwhenclickingthe
Sortbutton.TheSortdialogboxwillpopup.
TheSingleLayoutbuttonwithmenuoptionsisreplacedbythreebuttons:
ChangeLayout,SelectLayout,andSaveLayout.TheMaintainLayout
buttonisreplacedbythemenuoptionSettingsLayout
Administration.
Conclusion
YouhaveusedthemajorfeaturesoftheALVclassesCL_GUI_ALV_GRID
andCL_SALV_TABLEtoproduceoutput.Therearefunctionmodules
availabletoproduceALVoutput.RefertoChapter7(Table73)forthelist
ofthesefunctionmodules.Youshouldtryoutafewwiththescenariosyou
usedtoproduceALVoutputusingclasses.Thefunctionmodulesdonot
provideforinteractiveeventssuchasDOUBLE_CLICK,USER_COMMAND,and
AFTER_USER_COMMAND.

https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch13.xhtml

16/17

1/5/2016

Chapter13:ABAPListViewerOutputPart2SAPABAP:HandsOnTestProjectswithBusinessScenarios

PREV

Recommended
/ Queue
RecentOutputsPart
/ Topics / Tutorials
/ Settings / Blog / Feedback / Sign Out
Chapter 12: ABAP
List /Viewer
1
2016 Safari.
Terms of Service / Privacy Policy

https://www.safaribooksonline.com/library/view/sapabaphandson/9781430248040/9781430248033_Ch13.xhtml

NEXT

Chapter 14: Screen Programming

17/17

S-ar putea să vă placă și