Sei sulla pagina 1di 33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

GettingStarted Newsletters

Welcome,Guest

Login

Register

SearchtheCommunity

Products

Services&Support

AboutSCN

Downloads

Industries

Training&Education

Partnership

DeveloperCenter

LinesofBusiness

UniversityAlliances

Events&Webinars

Innovation

Store

ABAPDevelopment / ABAPDevelopment

ALVTUTOTIALFORBEGINERSWITHEXAMPLES
AddedbyFareedaTabassumS,lasteditedbyFareedaTabassumSonApr15,2008
Author:fareedas
Date:15/04/2008
Introduction

ThisisadiscussiononALVreportingastepbystepoperationmanualaboutcreatinganALVreportofmediumcomplexity.ThisdocumentationwillnotmakeyouanexpertinALV.But,definitely,itwillcome
handyatthetimeofneed.ItrefersanexamplereportYSUBALV,asareferenceandwillrepresentrelevantblocksofthecodeatdifferentareasofdiscussion.
Contents
ALV(ABAPLISTVIEWER)
Step1:DATADECLARATION
Example:
Step2:Selectingthevariants(Optional)
Step3:(DefiningOutputCharacteristics)
Step4:(Buildupeventstable)
Step5:(ReportOutputlistdescription)
Step6:(PassSelectionscreenInformation)
Step7:(DecidingSortCriteria)
Step8:(FinalStep)

Step9:(DisplayInternalOutputTable)
Samplecode.
Description:SapprovidesasetofALV(ABAPLISTVIEWER)functionmodules,whichcanbeputintousetoembellishtheoutputofareport.ThissetofALVfunctionsisusedtoenhancethereadability
andfunctionalityofanyreportoutput.Casesariseinsapwhentheoutputofareportcontainscolumnsextendingmorethan255charactersinlength.Insuchcases,thissetofALVfunctionscanhelp
chooseselectedcolumnsandarrangethedifferentcolumnsfromareportoutputandalsosavedifferentvariantsforreportdisplay.Thisisaveryefficienttoolfordynamicallysortingandarrangingthe
columnsfromareportoutput.Thereportoutputcancontainupto90columnsinthedisplaywiththewidearrayofdisplayoptions.
ThecommonlyusedALVfunctionsusedforthispurposeare
1.REUSE_ALV_VARIANT_DEFAULT_GET
2.REUSE_ALV_VARIANT_F4
3.REUSE_ALV_VARIANT_EXISTENCE
4.REUSE_ALV_EVENTS_GET
5.REUSE_ALV_COMMENTARY_WRITE
6.REUSE_ALV_FIELDCATALOG_MERGE
7.REUSE_ALV_LIST_DISPLAY
8.REUSE_ALV_GRID_DISPLAY
9.REUSE_ALV_POPUP_TO_SELECT
Thedifferentstepsusedforgettingtheabovefunctionmodulesintousearedescribedbelow.

Step1:DATADECLARATION
Sapstandardtypepools:SLIS,KKBLO.
Sapstandardtablestypestakenfromthetypepoolsare:
SLIS_LAYOUT_ALV,
SLIS_T_FIELDCAT_ALV
SLIS_T_LISTHEADER,
SLIS_T_EVENT,
SLIS_SELFIELD.
Internaltablestobeusedintheprogramdeclaredbasedontheabovetabletypes
DATA:I_LAYOUTTYPESLIS_LAYOUT_ALV,

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

1/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

I_FIELDTABTYPESLIS_T_FIELDCAT_ALV,
I_HEADINGTYPESLIS_T_LISTHEADER,
I_EVENTSTYPESLIS_T_EVENT.
TYPES:KKBLO_SELFIELDTYPESLIS_SELFIELD.

Example:
REPORTYSUBALV.
*Declarationofvariables*
TYPEPOOLS:SLIS.
*TopassnameofthereportinfunctionmoduleforALV
Data:V_REPIDLIKESYREPID.
*TopasstheoverallstructureoftheALVreport
Data:STRUCT_LAYOUTTYPESLIS_LAYOUT_ALV.
Data:STRUCT_LAYOUT1TYPESLIS_LAYOUT_ALV.
*InternaltabletocapturevariouseventsinALV
Data:I_EVENTSTYPESLIS_T_EVENT.
*Tableforcatalogofthefieldstobedisplayed
Data:I_FIELDCATTYPESLIS_T_FIELDCAT_ALV.
Data:X_FIELDCATTYPESLIS_FIELDCAT_ALV.
Data:I_FIELDCAT1TYPESLIS_T_FIELDCAT_ALV.
Data:X_FIELDCAT1TYPESLIS_FIELDCAT_ALV.
*Internaltabletomentionthesortsequence
Data:IT_SORTTYPESLIS_T_SORTINFO_ALV.
Data:X_SORTTYPESLIS_SORTINFO_ALV.
*Internaltabletodisplaytopofpage
Data:i_list_top_of_pagetypeslis_t_listheader.
*Structuretodisplayvariants
Data:i_variantlikedisvariant,
I_variant1likedisvariant.
*Internaltabletopassdata
DATA:BEGINOFI_TABOCCURS0,
Mblnrlikemsegmblnr,
Matnrlikemsegmatnr,
Maktglikemaktmaktg,
Charglikemsegcharg,
Werkslikemsegwerks,
Lgortlikemseglgort,
mengelikemsegmenge,
meinslikemsegmeins,
dmbtrlikemsegdmbtr,
ebelnlikemsegebeln,
icn(4)typec,
sym(4)typec,
excpt(2)typec,
box(1),
ENDOFI_TAB.
*EJECT
Data:beginofi_dococcurs0.
INCLUDESTRUCTUREMSEG.
Data:endofi_doc.

Step2:Selectingthevariants(Optional)
SELECTINGTHEVARIANTSFORINITIALLISTDISPLAY(DEFAULTVARIANT)
Thevariantsinthelistdisplaycanbebothuserspecificandgeneral.Theusercanprogrammaticallysettheinitial(default)variantforlistdisplay.Thedefaultvariantcanbefoundusingthefunctionmodule
'REUSE_ALV_VARIANT_DEFAULT_GET'.
Samplecode:
CALLFUNCTION'REUSE_ALV_VARIANT_DEFAULT_GET'
EXPORTING
i_save=variantsavecondition(A=all,U=userspecific)
CHANGING
cs_variant=internaltablecontainingtheprogramname(andthedefaultvariantoptional)
EXCEPTIONS
not_found=2.
Theusercanalsochoosefromthelistofexistingvariantsusingthefunctionmodule'REUSE_ALV_VARIANT_F4'.Example:
Initialization.
v_repid=syrepid.
*Displaydefaultvariant
PERFORMSUB_VARIANT_INIT.
ATSELECTIONSCREENONP_VAR.
*Oncetheuserhasenteredvariant,checkaboutitsexistence

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

2/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

PERFORMSUB_CHECK_PVAR.
ATSELECTIONSCREENONVALUEREQUESTFORP_VAR.
*DisplayalistofvariousvariantsofthereportwhentheUserpressesF4keyinthevariantfield
PERFORMSUB_VARIANT_F4.

*&*
*&FormSUB_VARIANT_INIT
*&*
*Displaydefaultvariant
*&*
FormSUB_VARIANT_INIT.
I_VARIANT1REPORT=SYREPID.
*Searchdefaultvariantforthereport
CALLFUNCTION'REUSE_ALV_VARIANT_DEFAULT_GET'
EXPORTING
i_save='A'
CHANGING
cs_variant=i_variant1
EXCEPTIONS
not_found=2.
*Ifdefaultvariantisfound,useitasdefault.
*Else,usethevariantLAYOUT1.
IFsysubrc=0.
p_var=i_variant1variant.
ELSE.
p_var='LAYOUT1'.
ENDIF.
endform."SUB_VARIANT_INIT
*&*
*&FormSUB_CHECK_PVAR
*&*
*Oncetheuserhasenteredvariant,checkaboutitsexistence
*&*
FORMSUB_CHECK_PVAR.
*Ifthenameofthevariableisnotblank,checkaboutitsexistence
ifnotp_varisinitial.
cleari_variant.
i_variantreport=syrepid.
i_variantvariant=p_var.
CALLFUNCTION'REUSE_ALV_VARIANT_EXISTENCE'
EXPORTING
I_SAVE='A'
CHANGING
CS_VARIANT=I_VARIANT.
*Ifnosuchvariantfound,flasherrormessage
Ifsysubrcne0.
Messagee398(00)with'Nosuchvariantexists'.
Else.
*Ifvariantexists,usethevariantnametopopulatestructure
*I_VARIANT1whichwillbeusedforexportparameter:IS_VARIANT
*inthefunctionmodule:REUSE_ALV_GRID_DISPLAY
Cleari_variant1.
Movep_vartoi_variant1variant.
Movesyrepidtoi_variant1report.
endif.
Else.
Cleari_variant.
endif.
ENDFORM."SUB_CHECK_PVAR
*&*
*&FormSUB_VARIANT_F4
*&*
*DisplayalistofvariousvariantsofthereportwhentheUserpressesF4keyinthevariantfield
*&*
FormSUB_VARIANT_F4.
i_variantreport=syrepid.
*Utilizingthenameofthereport,thisfunctionmodulewillsearchforalistof
*variantsandwillfetchtheselectedoneintotheparameterfieldforvariants
CALLFUNCTION'REUSE_ALV_VARIANT_F4'
EXPORTING
IS_VARIANT=I_VARIANT
I_SAVE='A'
I_DISPLAY_VIA_GRID='X'
IMPORTING
ES_VARIANT=I_VARIANT1
EXCEPTIONS
NOT_FOUND=1

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

3/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

PROGRAM_ERROR=2
OTHERS=3.
IFSYSUBRC=0.
P_VAR=I_VARIANT1VARIANT.
ENDIF.
endform."SUB_VARIANT_F4

Step3(DefiningOutputCharacteristics)

DEFINININGOUTPUTCHARACTERISTICS:PREPARINGDISPLAYFIELDSCATALOG
Afieldcatalogispreparedusingtheinternaltable(I_FIELDCAT)oftypeSLIS_T_FIELDCAT_ALV.Fieldcatalogcontainingdescriptionsofthelistoutputfields(usuallyasubsetoftheinternaloutputtable
fields).
AfieldcatalogisrequiredforeveryALVlistoutputtoadddesiredfunctionality(i.e.Key,Hotspot,Specificheadings,Justify,Col.positionetc)tocertainfieldsoftheoutput.Ifnotmentionedspecifically,then
thedefaultsaretaken.Thepossiblevaluesanddefaultsarelistedbelow.
Thefieldcatalogfortheoutputtableisbuiltupinthecaller'scoding.Thebuildupcanbecompletelyorpartiallyautomatedbycallingthe
REUSE_ALV_FIELDCATALOG_MERGEmodule.
Theminimalfieldcatalogisdocumentedbelow.Thiscanbedoneinaroutineusingalocalvariable.Theusercanusetheotheroptionalparameterstoassignoutputattributestodifferentfieldsintheoutput,
whichdifferfromthedefault.
Afieldcatalogneednotbebuiltupandpassedexplicitlyonlyunderthefollowingconditions:
1.TheinternaltabletobeoutputhasthesamestructureasaDataDictionarystructurewhichisreferredtointheinternaltabledeclarationusingLIKEorINCLUDESTRUCTURE.Inthiscasethe
attributesofthedifferentfieldsistakendirectlyfromthetableandtheattributes(keyfields,length,textsetc)needtostateexplicitly.
2.Allfieldsinthisstructurearetobeoutput
3.ThestructurenameispassedtoALVintheparameterI_STRUCTURE_NAMEofthefunctionmoduleREUSE_ALV_LIST_DISPLAY.
AllthevaluesenteredinthecatalogarespecifictotheparticularfieldwhosenameisenteredinthefieldnameFIELDNAMEofthefieldcatstructure.Thenameofthetableisalsoenteredinthecorr.
FieldnameTABNAMEofthestructure.

Thedifferentpossibleattributesare:
Row_pos(rowposition):Onlyrelevantifthelistoutputistobemultiline(twoorthreelines)bydefault.So,thisattributecanbeusedmaintaincertainlevelofalignmentintheoutput.
Valueset:0,13
Col_pos(columnposition):Thisparameterisrelevantwhenthefieldsintheoutputaretobedifferentfromthesequenceofthefieldsintheinternaltableusedfordisplay.Theparameter
specifiestherelativecolumnpositionofthefieldinthelistoutput.Thecolumnordercanbechangedinteractivelybytheuser.Ifthisparameterisinitialforallfieldcatalogentries,columnsappearinthe
internaltablefieldsequence.
Valueset:0,160
Fieldname(fieldname):Thisisthenameoftheinternaltablefieldforwhichtheparametersarepassedinthecatalog.
Valueset:internaloutputtablefieldname(requiredparameter)

Tabname(internaloutputtable):NameoftheinternaloutputtablethatcontainsthefieldFIELDCATFIELDNAMEabove.
Valueset:SPACE,internaloutputtablename.
Ref_fieldname(referencefieldname):NameoftheDataDictionaryfieldreferredto.Thisparameterisonlyusedwhentheinternaloutputtablefielddescribedbythecurrentfieldcatalogentryhasa
referencetotheDataDictionary(notaprogramfield),andthefieldnameintheinternaloutputtableisdifferentfromthenameofthefieldintheDataDictionary.Ifthefieldnamesareidentical,namingthe
DataDictionarystructureortableintheFIELDCATREF_TABNAMEparameterissufficient.
Valueset:SPACE,DataDictionaryfieldname.
Ref_tabname(referencetable/structurefieldname):StructureortablenameofthereferredDataDictionaryfield.Thisparameterisonlyusedwhentheinternaloutputtablefielddescribedbythe
currentfieldcatalogentryhasaDataDictionaryreference(notaprogramfield).
Valueset:SPACE,nameofaDataDictionarystructureortable

Linktocurrencyunit
Cfieldname(currencyunitfieldname):Thisisusedforcurrencyfieldsthathaveareferencetoanyunitfield.Thisisonlyrelevantforamountcolumnswithassociatedunit.Thisparametercontains
theNameoftheinternaloutputtablefieldcontainingthecurrencyunitassociatedwiththeamountfieldFIELDCATFIELDNAME.ThefieldinFIELDCATCFIELDNAMEmusthaveitsownfieldcatalogentry.
Valueset:SPACE,outputtablefieldname.
Ctabname(internalcurrencyunitfieldoutputtable):NameoftheinternaloutputtablecontainingtheFIELDCATCFIELDNAMEfield.
Valueset:SPACE,outputtablefieldname.
Linktomeasurementunit
Qfieldname(measurementunitfieldname):Onlyrelevantforquantitycolumnswithunitlink.Nameoftheinternaloutputtablefieldcontainingthemeasurementunitassociatedwiththequantityfield
FIELDCATFIELDNAME.ThefieldinFIELDCATQFIELDNAMEmusthaveitsownfieldcatalogentry.
Valueset:SPACE,outputtablefieldname.
Qtabname(internalmeasurementunitfieldoutputtable):NameoftheinternaloutputtablecontainingtheFIELDCATQFIELDNAMEfield.
Valueset:SPACE,outputtablefieldname.
Outputlen(columnwidth):Thisparameterisusedifthedesiredoutputlengthforafieldisdesiredtobedifferentfromtheinternaloutputtablefield.ForfieldswithaDataDictionarylinkthis
parametercanbeleftinitial.ForfieldswithoutaDataDictionarylink(programfield)theparametermustbegiventhevalueofthedesiredfieldlistoutputlength(columnwidth).
Initial=columnwidthistheoutputlengthofthereferredDataDictionaryfield(domain).
N=columnwidthisncharacters.
Valueset:0(initial),n.
Key(keycolumn):Bydefault,thesystemmakessomefieldsintheoutputaskeyfields,providedthefieldsarekeyfieldsintheirreferencingtable.Usingthisparameter,fieldsotherthankeyfieldsof
thereferencingtablecanbemadekeyfield.Thisparameterismostimportantiftheoutputneedstocontainsomefield,whicharenotscrollableorcannotbehidden.
Iftheinternaloutputtablecontainsfieldsthatarekeyfieldsfromdifferenttables,thenallthosefieldsinthereportoutputbecomesunscrollableandcannotbehidden.So,thefieldsintheoutputinternaltable
shouldnotbereferencedfromtablesinwhichtheyarekeyfields.Instead,theyshouldbereferencedtothetablesinwhichtheyarenotkeyfields,incasetheyarenotdesiredaskeyfieldintheoutput.
'X'=keyfield(keyfieldoutputincolor)andKeyfieldscannotbeinteractivelyhidden.ParameterFIELDCATNO_OUTmustbeleftinitial.

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

4/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

Valueset:SPACE,'X'.
Key_sel(hideablekeycolumn):ThisparameterisonlyrelevantforthefieldswhicharemadekeyfieldsusingFIELDCATKEY='X'.UsingthisparametertheKeyfieldcanbehiddeninteractively.
Thekeycolumnsequencecannotbechangedinteractivelybytheuser.TheoutputiscontrolledbytheFIELDCATNO_OUTparameteranalogouslytononkeyfields.
Valueset:SPACE,'X'.
No_out(fieldinfieldlist):Thisparameterisusedtoremovecertainfieldsfromtheoutputduringinitialdisplay.Theusercanhoweverinteractivelychoosethefieldforoutputfromthefieldlistinthe
displayvariant.
'X'=fieldisnotdisplayedinthecurrentlist.
Valueset:SPACE,'X'.
Tech(technicalfield):Thisparameterisusedtomakecertainfielddisplayonlyinthefieldcatalog.Thefieldswiththisparametersetcannotbeoutputinthelistnorcantheybedisplayedinteractively
fromthecatalog.
'X'=technicalfield.
Valueset:SPACE,'X'.
Emphasize(highlightcolumnsincolor):Asnamesuggests,thisfieldparameterisusedtohighlightcertainfieldwithchosencolors.
Valueset:SPACE,'X'or'Cxyz'(x:'1''9'y,z:'0'=off,'1'=on).
'X'=columniscoloredwiththedefaultcolumnhighlightcolor.
'Cxyz'=columniscoloredwithacodedcolor:
C:Color(codingmustbeginwithC)
X:colornumber
Y:bold
Z:inverse
Hotspot(columnashotspot):Thisparameterisusedtomakecertainfieldappearashotspoti.e.ahandisdisplayedifthecursorispositionedonthefieldvalue.Singleclickonsuchfieldscause
thePICKORF2eventstohappen.
Valueset:SPACE,'X'.
'X'=columncellsareoutputashotspots.
Fix_column(fixcolumn):Thisparameterisusedtofixcertaincolumnsintheoutput.Allcolumnstobefixedmusthavethisflag,startingfromtheleft.Ifacolumnwithoutthisflagisoutput,onlythe
columnstotheleftofthiscolumnarefixed.Theusercanchangethecolumnfixinginteractively.
Valueset:SPACE,'X'.
'X'=columnfixed(doesnotscrollhorizontally).

Do_sum(sumovercolumn):theusercanalsocallthisfunctioninteractively.
Valueset:SPACE,'X'.
'X'=asumiscalculatedoverthisinternaloutputtablefield.
No_sum(sumsforbidden):Nosumcanbecalculatedoverthisfield,althoughthedatatypeofthefieldwouldallowsumming.
Valueset:SPACE,'X'.
Icon:Theparameterdisplayscertaincolumncontentsasicons.Theinternaloutputtablecolumncontentsmustbevalidiconstrings.
Valueset:SPACE,'X'.
'X'=columncontentstobeoutputasanicon.
Symbol:Theinternaloutputtablecolumnmustbeavalidsymbolcharacter.
Valueset:SPACE,'X'
'X'=columncontentsaretobeoutputasasymbol.
Just(justification):Thisparameterisusedforalignmentofthecontentsoftheoutputtable.ThisisonlyrelevantforCHARorNUMCfieldsintheoutputinternaltable.Thejustificationofthecolumn
headeralwaysfollowsthejustificationofthecolumns.Independentjustificationofthecolumnheaderisnotpossible.
Valueset:SPACE,'R','L',and'C'.
''=Defaultjustificationforthisdatatype
'R'=rightjustifiedoutput
'L'=leftjustifiedoutput
'C'=centeredoutput.

Lzero(leadingzeros):BydefaultALVoutputsNUMCfieldsrightjustifiedwithoutleadingzeros.UsingthisparameteronlytheNUMCfieldscanbedisplayedwithleadingzeroes.
Valueset:SPACE,'X'.
'X'=outputwithleadingzeros.
No_sign(no+/sign):Thisparameterisusedtosuppressthesignsoftheoutputfields.Itisonlyrelevantforthevaluefields.
Valueset:SPACE,'X'.
'X'=valueoutputwithout+/sign.
No_zero(suppresszeros):Onlyrelevantforvaluefields.
Valueset:SPACE,'X'.
'X'=suppresszeros.
Edit_mask(fieldformatting):ToapplythereportoutputformattingoptionssameasintheWRITEstatementinreportwriting.
Valueset:SPACE,template.

Thefollowingparametersareusedforcustomizingthetextsintheheadingoftheoutputofthecolumns.ThetextsaretakenfromtheDataDictionaryforfieldswithaDataDictionaryreference.Ifthisisnot
desired,thetextparameterscanalsobespecified.TheDataDictionarytextsarethenignored.
Iftheuserchangesthecolumnwidthinteractively,thecolumnheadertextwiththeappropriatelengthisalwaysused.
Theinteractivefunction'Optimizecolumnwidth'takesaccountofboththefieldcontentsandthecolumnheaders:ifallfieldcontentsareshorterthantheshortestcolumnheader,thecolumnwidthdepends
onthecolumnheader.
The'longfieldlabel'isalsousedindisplayvariantdefinition,
Sort,etc.Popup.
seltext_l(longfieldlabel)
seltext_m(mediumfieldlabel)
seltext_s(shortfieldlabel)
reptext_ddic(header)AnalogoustotheDataelementmainheader
Ddictxt(specifytext):Youcanspecifywithvalues'L','M',and'S',thekeywordthatshouldalwaysbeusedascolumnheader.Ifthecolumnwidthchanges,noattemptismadeinthiscasetofindan
appropriateheaderforthenewoutputwidth.
Valueset:SPACE,'L','M',and'S'.
Samplecode:
*&*
*&FormSUB_PREPARE_FIELDCATALOG

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

5/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

*&*
*Preparefieldcatalogforthemainreport.Statethenameofthefield,nameofinternaltable,variousformattingoptionsetc
**
FormSUB_PREPARE_FIELDCATALOG.
X_FIELDCATCOL_POS=1.*FirstfieldtoappearinALVlist
X_FIELDCATFIELDNAME='SYM'.*Nameoftheinternaltablefield
X_FIELDCATTABNAME='I_TAB'.*Nameoftheinternaltable
X_FIELDCATSELTEXT_M='Stat'.*Headingforthefield
X_FIELDCATSYMBOL='X'.*Thefieldisgoingtocontainasymbol
*Appendthespecificationstotheinternaltableforfieldcatalog.
APPENDX_FIELDCATTOI_FIELDCAT.
CLEARX_FIELDCAT.
X_FIELDCATCOL_POS=2.*SecondfieldtoappearinALVlist
X_FIELDCATFIELDNAME='MATNR'.*Nameofthefieldintheinternaltable
X_FIELDCATTABNAME='I_TAB'.*Nameoftheinternaltable
X_FIELDCATSELTEXT_M='MatItem'.*Headingforthecolumn
*Itisgoingtobethekeyfield.Thecolorforthisfieldisgoingtobedifferent
X_FIELDCATKEY='X'.
X_FIELDCATKEY_SEL='X'.
*Singleclickonthefieldwilltriggerdoubleclickevent.Also,ahandwillappearwhenthecursornavigatestothefield
X_FIELDCATHOTSPOT='X'.
X_FIELDCATFIX_COLUMN='X'.*Thecolumnandthoselefttoitwillnotscroll
X_FIELDCATREF_TABNAME='MSEG'.*F1helpwillcomeasitisreferencedtoDDICtable
APPENDX_FIELDCATTOI_FIELDCAT.
CLEARX_FIELDCAT.
X_FIELDCATCOL_POS=3.
X_FIELDCATFIELDNAME='MAKTG'.
X_FIELDCATTABNAME='I_TAB'.
X_FIELDCATSELTEXT_M='Description'.
*X_FIELDCATOUTPUTLEN=50.
X_FIELDCATHOTSPOT=space.
X_FIELDCATJUST='C'.*Thefieldiscentre(Cforcentre,RandLforleftandright)justified
X_FIELDCATKEY='X'.
X_FIELDCATFIX_COLUMN='X'.
*X_fieldcatno_out='X'.
X_FIELDCATFIX_COLUMN='X'.
APPENDX_FIELDCATTOI_FIELDCAT.
CLEARX_FIELDCAT.
X_FIELDCATCOL_POS=4.
X_FIELDCATFIELDNAME='CHARG'.
X_FIELDCATTABNAME='I_TAB'.
X_FIELDCATSELTEXT_M='Batch'.
*X_FIELDCATOUTPUTLEN=10.
X_FIELDCATHOTSPOT=space.
APPENDX_FIELDCATTOI_FIELDCAT.
CLEARX_FIELDCAT.
X_FIELDCATCOL_POS=5.
X_FIELDCATFIELDNAME='EBELN'.
X_FIELDCATTABNAME='I_TAB'.
X_FIELDCATSELTEXT_M='PurchaseOrder'.
*X_FIELDCATOUTPUTLEN=14.
X_FIELDCATEMPHASIZE='C511'.*Thefieldwillbecoloreddifferently(Cxyz)
X_FIELDCATNO_OUT='X'.*Initiallythefieldwillbehidden
APPENDX_FIELDCATTOI_FIELDCAT.
CLEARX_FIELDCAT.
X_FIELDCATCOL_POS=6.
X_FIELDCATFIELDNAME='MBLNR'.
X_FIELDCATTABNAME='I_TAB'.
X_FIELDCATSELTEXT_M='Documentno'.
*X_FIELDCATOUTPUTLEN=14.
X_FIELDCAT_EMPHASIZE='C711'.
X_FIELDCATNO_OUT='X'.
APPENDX_FIELDCATTOI_FIELDCAT.
CLEARX_FIELDCAT.
X_FIELDCATCOL_POS=7.
X_FIELDCATFIELDNAME='WERKS'.
X_FIELDCATTABNAME='I_TAB'.
X_FIELDCATSELTEXT_M='Plant'.
*X_FIELDCATOUTPUTLEN=5.
X_FIELDCATEMPHASIZE='C310'.
APPENDX_FIELDCATTOI_FIELDCAT.
CLEARX_FIELDCAT.
X_FIELDCATCOL_POS=8.
X_FIELDCATFIELDNAME='LGORT'.
X_FIELDCATTABNAME='I_TAB'.
X_FIELDCATSELTEXT_M='St.Loc'.
*X_FIELDCATOUTPUTLEN=7.

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

6/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

*X_FIELDCATNO_OUT='X'.
APPENDX_FIELDCATTOI_FIELDCAT.
CLEARX_FIELDCAT.
X_FIELDCATCOL_POS=9.
X_FIELDCATFIELDNAME='MENGE'.
X_FIELDCATTABNAME='I_TAB'.
X_FIELDCATSELTEXT_M='Quantity'.
X_FIELDCATOUTPUTLEN=12.
X_FIELDCATDO_SUM='X'.*Summationisallowedforthisfield
X_FIELDCATREF_TABNAME='MSEG'.
APPENDX_FIELDCATTOI_FIELDCAT.
CLEARX_FIELDCAT.
X_FIELDCATCOL_POS=10.
X_FIELDCATFIELDNAME='ICN'.
X_FIELDCATTABNAME='I_TAB'.
X_FIELDCATSELTEXT_M=''.
X_FIELDCATOUTPUTLEN=2.
X_FIELDCATICON='X'.
*X_FIELDCATNO_OUT='X'.
APPENDX_FIELDCATTOI_FIELDCAT.
CLEARX_FIELDCAT.
X_FIELDCATCOL_POS=11.
X_FIELDCATFIELDNAME='MEINS'.
X_FIELDCATTABNAME='I_TAB'.
X_FIELDCATSELTEXT_M='Unit'.
X_FIELDCATOUTPUTLEN=5.
X_FIELDCATFIELDNAME='MEINS'.
APPENDX_FIELDCATTOI_FIELDCAT.
CLEARX_FIELDCAT.
X_FIELDCATCOL_POS=12.
X_FIELDCATFIELDNAME='DMBTR'.
X_FIELDCATTABNAME='I_TAB'.
X_FIELDCATSELTEXT_M='Localcurr'.
X_FIELDCATOUTPUTLEN=12.
X_FIELDCATINTTYPE='P'.
X_FIELDCATJUST='R'.
X_FIELDCATDO_SUM='X'.
APPENDX_FIELDCATTOI_FIELDCAT.
CLEARX_FIELDCAT.
X_FIELDCATCOL_POS=13.
X_FIELDCATFIELDNAME='EXCPT'.
X_FIELDCATTABNAME='I_TAB'.
X_FIELDCATSELTEXT_M=''.
X_FIELDCATOUTPUTLEN=3.
APPENDX_FIELDCATTOI_FIELDCAT.
CLEARX_FIELDCAT.
ENDFORM."SUB_PREPARE_FIELDCATALOG

Step4(Buildupeventstable)
Thenextstepistobuildaneventtable,whichareusedforfiringbothusercommandsandthesystemdependenteventsi.e.topofpage,endofpageetc.
Alistofpossibleeventsispopulatedintoaneventtable(I_EVENTS)whenthistableispassedfromthefunctionmoduleREUSE_ALV_EVENT_NAMES_GET.Thereturntablefromthisfunctionmodule
containsallthepossibleevents.
Thefunctionmodulecontainsfollowingimportandexportparameters.
IMPORTINGPARAMETERS:I_LIST_TYPE
Thisparameterhaspossiblevaluesfrom04.
TheparameterI_LIST_TYPEisofTYPESLIS_LIST_TYPEandisDEFAULT0.
EXPORTINGPARAMETERS:I_EVENTStable.ThistableisofTYPESLIS_T_EVENTandreturnstotheprogramthenameofallthepossibleevents.
Thetablestructurecontainsthefields:
I_EVENTSNAME:NameoftheCallbackevent.
I_EVENTSFORM:Nameoftheformroutinethatshouldbecalledinthecallingprogramattheevent.
Onlyeventswithaformroutinenameareprocessed.
TheI_EVENTStablereturnswiththefollowingpossibleconstants:
1.Slis_ev_item_data_expandTYPEslis_formnameVALUE'ITEM_DATA_EXPAND'.
OnlyrelevantforhierarchicalsequentiallistsusingthelayoutparameterIS_LAYOUTEXPAND_FIELDNAMEofthestructureIS_LAYOUT.Exitforpassingitementries(ITEMtable)foraheaderrecordthat
wasexpandedinteractivelybytheuser.2.Slis_ev_reprep_sel_modifyTYPEslis_formnameVALUE'REPREP_SEL_MODIFY'.
RS_SELFIELDTABINDEXcontainstheheadertableindexforwhichtheitementriesaretobeputintheglobalitemoutputtable(T_OUTTAB_SLAVE).TheCallbackisonlycalledifALVhasnoitemsfor
aheaderthatistobeexpanded.
RFLG_ALLispassedwith'X'iftheusershowsallitems.Theapplicationmustensurethatentriesarenotrepeatedintheitemtable.
RS_SELFIELDisinitialinthiscase.3.Slis_ev_caller_exit_at_startTYPEslis_formnameVALUE'CALLER_EXIT'.

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

7/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

Iscalledatthebeginningofthefunctionmoduletomakespecialsettings.Itisnotusuallyused.4.Slis_ev_user_commandTYPEslis_formnameVALUE'USER_COMMAND'.
AsthisisafrequentlyusedCallbackevent,theformroutinecanalsobepasseddirectlyintheinterfacebypassingtheusercommandintheIMPORTINGparameter
I_CALLBACK_USER_COMMAND.
5.Slis_ev_top_of_pageTYPEslis_formnameVALUE'TOP_OF_PAGE'.
EquivalenttothelistprocessingTOPOFPAGEevent.
6.Slis_ev_top_of_coverpageTYPEslis_formnameVALUE'TOP_OF_COVERPAGE'.
Theselectioninformationandliststatusareoutputtogether(iftheyexist)onaseparatepagebydefault
7.Slis_ev_end_of_coverpageTYPEslis_formnameVALUE'END_OF_COVERPAGE'.
AnalogouslytoTOP_OF_COVERPAGEtheusercanaddotherinformation
totheinformationoutputbyALV(selectioninformation,liststatus)atthisevent.8.Slis_ev_foreign_top_of_pageTYPEslis_formnameVALUE'FOREIGN_TOP_OF_PAGE'.
TheTopofpageeventisalwaysprocessedinALVandisonlypassedtothecallerviatheCallbackmechanism.Thisisstillthecaseifthecaller,e.g.byauseraction,processesabranchlistwhichwas
notformattedbyALV(e.g.apopupwithadditionalinformationaboutthelistrecordselectedanddisplayedbyALV).
Inthiscase,topofpagecannotbeformattedbyALVanalogouslytothebasiclist,itmustbehandledcompletelybythecaller.TheeventtopofpagestilloccursinALV.WhenALVnoticesatopofpage
whichwasnotcausedbyanALVoutput,theformroutineinFOREIGN_TOP_OF_PAGEiscalled.9.Slis_ev_foreign_end_of_pageTYPEslis_formnameVALUE'FOREIGN_END_OF_PAGE'.
TheeventendofpageisalwaysprocessedinALVandonlypassedtothecallerviacallback.Thisisstillthecase,e.g.whenthecallerprocessesadetailslistwhichwasnotformattedbyALV(e.g.a
popupwithfurtherinformationaboutselectedlistrecordswhichweredisplayedbyALV).Inthiscase,endofpagecannotbeformattedbyALVanalogouslytothebasiclist,itmustbehandledcompletelyby
thecaller.TheeventendofpagestilloccursinALV.WhenALVnoticesanendofpagethatwasnotcausedbyanALVoutput,theformroutineinFOREIGN_END_OF_PAGEiscalled.
10.Slis_ev_pf_status_setTYPEslis_formnameVALUE'PF_STATUS_SET'.
Ifauserliststatusistobeset,itmustbedoneintheformroutineassignedtothisevent.TheALVfunctioncodes,whichmustnotbeactive,areintheParameterRT_EXTAB.Thistablemustbepassed
withtheSETPFSTATUScommand(withinactiveuserfunctioncodesaswell,ifnecessary).
TheSTANDARDstatusofthefunctiongroupSALVshouldbeusedasatemplateforauserspecificstatus.AsthisisafrequentlyusedCallbackevent,itsformroutinecanalsobepasseddirectlyinthe
interfaceintheIMPORTINGparameterI_CALLBACK_PF_STATUS_SET.11.Slis_ev_list_modifyTYPEslis_formnameVALUE'LIST_MODIFY'.
LIST_MODIFYUSINGR_TABNAMETYPESLIS_TABNAME
R_INDEXLIKESYTABIX
R_INDEX_ITEMLIKESYTABIX
R_INDEX_SUMLIKESYTABIX.12.Slis_ev_top_of_listTYPEslis_formnameVALUE'TOP_OF_LIST'.
Informationoutputatthestartofthelist**
13.Slis_ev_end_of_pageTYPEslis_formnameVALUE'END_OF_PAGE'.
Informationoutputattheendofapage.Thisisonlycalledforprinting.14.Slis_ev_end_of_listTYPEslis_formnameVALUE'END_OF_LIST'.
Informationoutputattheendofthelist
15.Slis_ev_after_line_outputTYPEslis_formnameVALUE'AFTER_LINE_OUTPUT'.
Outputinformationaftereachoutputline.Shouldonlybeusedinjustifiedcasesbecauseitcostsalotofperformance.
16.Slis_ev_before_line_outputTYPEslis_formnameVALUE'BEFORE_LINE_OUTPUT'.
Outputinformationbeforeeachoutputline.Shouldonlybeusedinjustifiedcasesbecauseitcostsalotofperformance.
17.Slis_ev_subtotal_textTYPEslis_formnameVALUE'SUBTOTAL_TEXT'.
Thiseventtable(I_EVENTS)isnowcheckedwiththedesiredconstants.Ifthedesiredconstantisfound,thenthecorrespondingfieldfortheFORMNAMEispopulatedwiththenameoftheroutine
containingthecorrespondingevent.Samplecode:
FORMNAME_TOP_OF_PAGETYPESLIS_FORMNAMEVALUE'TOP_OF_PAGE',
FORMNAME_END_OF_PAGETYPESLIS_FORMNAMEVALUE'END_OF_PAGE',FORMNAME_USER_COMMANDTYPESLIS_FORMNAMEVALUE'USER_COMMAND'.
DATA:L_I_EVENTTYPESLIS_ALV_EVENT.
CALLFUNCTION'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE=0
IMPORTING
ET_EVENTS=I_EVENTS.
READTABLEI_EVENTSWITHKEYNAME=SLIS_EV_TOP_OF_PAGEINTOL_I_EVENT.
IFSYSUBRC=0.
MOVEFORMNAME_TOP_OF_PAGETOL_I_EVENTFORM.
APPENDL_I_EVENTTOI_EVENTS.
ENDIF.
READTABLEI_EVENTSWITHKEYNAME=SLIS_EV_END_OF_PAGEINTOL_I_EVENT.
IFSYSUBRC=0.
MOVEFORMNAME_END_OF_PAGETOL_I_EVENTFORM.
APPENDL_I_EVENTTOI_EVENTS.
ENDIF.
CLEARL_I_EVENT.
READTABLEI_EVENTSWITHKEYNAME=SLIS_EV_USER_COMMANDINTOL_I_EVENT.
IFSYSUBRC=0.
MOVEFORMNAME_USER_COMMANDTOL_I_EVENTFORM.
APPENDL_I_EVENTTOI_EVENTS.
ENDIF.
Thiswillpreparetheeventstableforthereport.
Thereportwillcontainthreeformsfortheaboveevents:
1.FORMTOP_OF_PAGE:Thisformwillcontainthetopofpageeventforthereporti.e.headeretc
Usingthefunctionmodule'REUSE_ALV_COMMENTARY_WRITE',theinternaltablecontainingtheheadingsfortopofpageeventcanbepassedtothelistoutput.Also,anylogospecifictothereportcan
bepassedtothefunctionmodule.
2.FORMEND_OF_PAGE:Thisformwillcontaintheendofpageeventforthereporti.e.footeretc
3.FORMUSER_COMMAND:Thisformwillcontainthedesiredusercommandi.e.pick/lineselection

Step5(ReportOutputlistdescription)
http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

8/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

AlayoutisbuildforthereportoutputlistdescriptionUSINGtheinternaltabledeclaredabove(I_LAYOUT).
Outputlistdescriptionstructure.
Theparametersaredescribedunderthefollowingheads:
Displayoptions
Exceptions
Totals
Interaction
Detailscreen
Displayvariants(onlyforhierarchicalsequentiallists)
Color
Other
Thelayouttableisoftypeslis_layout_alv_specandhasthefollowingfields:

Displayoptions
1.Colwidth_optimize(1)TYPEc:Thisparameteroptimizesthelengthofthedifferentcolumnsintheoutput.Thewidthofthedifferentcol.nowdependsonthemax.Lengthofthedatainthecolumn.
Valueset:SPACE,'X'
'X'=optimizesthecolumnwidthsothatallcontentsaredisplayedcompletely.
2.No_colhead(1)TYPEc:Thisparametersuppressesthecolumnheadings
Valueset:SPACE,'X'.
'X'=columnheadersarenotoutput
3*.No_hotspot*(1)TYPEc:Theheadingsofthereportoutputarenotoutputashotspot.
Valueset:SPACE,'X'.
'X'=columnheadersarenotoutputashotspot
4*.Zebra*(1)TYPEc:Thereportisoutputinthestripedpattern.
Valueset:SPACE,'X'.
'X'=stripedpattern(e.g.forwidelists)
5.No_vline(1)TYPEc:Thereportoutputcontainscolumnsonlyseparatedbyspaceandnolines.Itisnotrelevantfor:hierarchicalsequentiallistsandmultiplelinelists.
Valueset:SPACE,'X'.
'X'=columnsseparatedbySPACE
6.No_min_linesize(1)TYPEc:Thereportlinesizeisequaltothewidthofthelist.Itisnotrelevantforblocklists.
Valueset:SPACE,'X'.
'X'=linesizedependsonlistwidth
''=Linesizeissetto80orMIN_LINESIZE(if>0).
7.Min_linesizeLIKEsylinsz:Thereportoutputcontainsaminimumpossiblelengthofline.Ifinitialmin_linesizeissetto80bydefault,thenthisparameterisusedtocustomizeit.Theprerequisiteforthisis
thattheparameterno_min_linesizeshouldbe''.
Valueset:0,10250
Ifthelistiswider,theformatusesthelistwidth(maximum250orMAX_LINESIZE(if>0)).
8.Max_linesizeLIKEsylinsz:Thedefaultmax.Linesizeis250.Tochangethisdefaultvalue,thisparametercaninteractivelydefinethemaximumlistwidthsetting.
Valueset:0,801020
9.Window_titlebarLIKErsmpetittext:Tosetthetitlebaronthereportoutput.
10.No_uline_hs(1)TYPEc.

Exceptions
11.Lights_fieldnameTYPEslis_fieldname:Internaloutputtablefieldcontainingthecodesofexceptionstobeoutput.
Outputtablefieldcode:'1'=redtrafficlight
'2'=yellowtrafficlight
'3'=greentrafficlightFieldnameforexception
Valueset:SPACE,internaloutputtablefieldname.

12.Lights_tabnameTYPEslis_tabname:NameoftheinternaloutputtablethatcontainsthefieldintheparameterLIGHTS_FIELDNAME.IfLIGHTS_FIELDNAMEisnotempty,thisfieldmustalsobefilled
forhierarchicalsequentiallists.Onlyrelevantforhierarchicalsequentiallists.
Valueset:SPACE,internaloutputtablename.
13.Lights_rollnameLIKEdfiesrollname:ThedocumentationofthisdataelementisdisplayedwhenyoucallF1helpforanexceptioncolumn.
Valueset:SPACE,dataelementname.
14.Lights_condense(1)TYPEc:Ifalistrecordisoutputwith'redtrafficlight',eachSubtotalthatincludesthisrecordisalsooutputwith'redtrafficlight'.
Valueset:SPACE,'X'
'X'=the'maximum'exceptionoftheitemsinthesubtotalisoutputatsubtotallevel.
Sums
15*.No_sumchoice*(1)TYPEc:ThisparameterallowsthechoiceforsummingupOnlybyfieldcatalog.
Valueset:SPACE,'X'
'X'=fieldswhicharetobesummed,passedbythecallingprogram(FIELDCATDO_SUM='X').Theusershouldnotbeabletochangethisvalueinteractively.
16.No_totalline(1)TYPEc:Removestheoptionofhavingtotalsaftersubtotals.
Valueset:SPACE,'X'
'X'=nototalrecordistobeoutput.Subtotalscanstillbecalculatedandoutput.ThefieldsinthesubtotalsareflaggedDO_SUM='X'inthefieldlist.
17.No_subchoice(1)TYPEc:Doesnotallowtheusertointeractivelychangethefieldchosenforsubtotals.
Valueset:SPACE,'X'
'X'=valuewhosechangetriggerssubtotals,providedbythecallingprogram.Theusershouldnotbeabletochangethisvalueinteractively.

18.No_subtotals(1)TYPEc:Nosubtotalspossible
Valueset:SPACE,'X'
'X'=nosubtotals.
19*.Numc_sum*(1)TYPEc:TotalsonlypossibleforNUMCFields.
20.No_unit_splittingTYPEc:Noseparatetotallinesbyinh.units
21.totals_before_itemsTYPEc:Displaytotalsbeforetheitems
22.Totals_only(1)TYPEc:Showonlytotals
Valueset:SPACE,'X'
'X'=onlytotalrecordsareoutput.

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

9/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

23.Totals_text(60)TYPEc:Textfor1stcol.intotals
Valueset:SPACE,string(max.60)
''=Thefirstcolumninthetotalrecordcontainsanappropriatenumberof'*'stoindicatethetotalbydefault.Ifthefirstcolumniswideenough,thestring'Total'isoutputaftertheasterisks.
'String'=Thestringpassedisoutputafterthetotalindicatedby'*',ifthecolumniswideenough.
24.Subtotals_text(60)TYPEc:Textsforsubtotals
Valueset:SPACE,string(max.60)
''=Inthefirstcolumnofsubtotalrecords,thesubtotalisindicatedbyanappropriatenumberof'*'bydefault.Ifthefirstcolumnisnotasubtotalcriterion,thestring'Total'isoutputaftertheasterisks,ifthe
columniswideenough.
'String'=thestringpassedisoutputafterthesubtotalindicatedby'*',ifthecolumniswideenoughandthefirstcolumnisnotasubtotalcriterion.Ifitisasubtotalcriterion,itsvalueisrepeatedafterthetotal,
ifthecolumniswideenough.
Interaction
25.Box_fieldnameTYPEslis_fieldname:Fieldnameforcheckboxinthereportoutput.Ifthelisthascheckboxesatthestartofrecords(forselectingseveralrecords),thisparametercontainstheinternal
outputtablefieldnameindicatedbythecheckboxselectioncolumn.Thefieldisacheckboxatthestartoflistrecordswithoutalistheader.
Valueset:SPACE,internaloutputtablefieldname

26.Box_tabnameTYPEslis_tabname:NameoftheinternaloutputtablethatcontainsthefieldintheparameterBOX_FIELDNAME.IfBOX_FIELDNAMEisnotempty,thisfieldmustalsobefilledfor
hierarchicalsequentiallists.
Valueset:SPACE,internaloutputtablename.
27.Box_rollnameLIKEdd03prollname:rollnameforcheckbox
28.Expand_fieldnameTYPEslis_fieldname:fieldnameflag'expand'.Theusercanshoworhidetheitemsbyclickingonthefoldersymbol(hotspot).Iftheitemsforaheaderentryareonlytobereadby
thecallingprogramandpassedtoALVwhenaheaderhasbeenexpandedinteractively,thiscanbecontrolledviatheCALLBACKevent'ITEM_DATA_EXPAND'.
29.Hotspot_fieldnameTYPEslis_fieldname:Usedtomakethefieldnameflaghotspot.
30.No_input(1)TYPEc:Thefieldsareonlydisplayfields.
Valueset:SPACE,'X'
'X'=allreadyforinputfieldsinalistaredisplayedasnotreadyforinput.(RecordselectioncheckboxesandfieldswhichcanbemadereadyforinputviathefieldlistparameterFIELDCATINPUT='X')
31.F2codeLIKEsyucomm:ToassignanALVstandardfunctioncodetodoubleclick(F2),assignthefunctioncodetothisparameter.Ex.:toassigntheALVstandardfunction'Detail'('&ETA')toF2.
=>LAYOUTF2CODE='&ETA'.
Valueset:SPACE,functioncode

32.Confirmation_prompt:confirm.Promptwhenleaving
Valueset:SPACE,'X'
'X'=ifoneofthefunctions'Back(F03)','Exit(F15)'or'Cancel(F12)'occurs,aconfirmationpromptappears.
33.Key_hotspot(1)TYPEc:Thekeyfieldsaredisplayedashotspot.Thecolumnsdefinedinthefieldcatalogaskeyfields(FIELDCATKEY='X')areoutputashotspots,i.e.clickingonakeycolumn
(highlightedincolorinthelist)callsthefunctionunderF2.
Valueset:SPACE,'X'.
34.Reprep(1)TYPEc:reportreportinterfaceactive.
35.Group_buttons(1)TYPEc:groupbuttonsforCOL1COL5.GroupoutputfieldsviaFIELDCATSP_GROUPinthefieldlist,andpassthegroupnametothelistmoduleintheinterfaceparameter
IT_SPECIAL_GROUPS.
Valueset:SPACE,'X'.
36.No_keyfix(1)TYPEc:Usedtomakethekeyfieldsscrollable.
Valueset:SPACE,'X'.
''=ThekeycolumnsdefinedinthefieldcatalogbyFIELDCATKEY='X'arefixedinthelistoutput.Thesecolumnsdonotscrollhorizontally.Theitemtablekeycolumnsarefixedinhierarchicalsequential
lists.Theheadertablekeyfieldsarenotconsideredhere.
'X'=keycolumnsnotfixed
37.Get_selinfos(1)TYPEc:Toreadselectionscreen.
Valueset:SPACE,'X'.
IfthecallingprogramisareportwithanABAP/4selectionscreen,settingthisparametermakesALVreadtheselectionscreenagain.Iftheselectionsarereadsuccessfully,apushbutton,viawhichthe
usercancallapopupwhichliststhereportselectionsinasimpleform,becomesactiveontheresultslistoutputbyALV.
38.group_change_edit(1)TYPEc:Settingsbyuserfornewgroup
Valueset:SPACE,'X'
'X'=theusercanenteraformatoptionforeachsortcriterioninthesort/subtotalpopup,forthelistformatwhenthisvaluechanges(e.g.newpageorunderline).
39.No_scrolling(1)TYPEc:Doesnotallowscrollingofthelisttotheright.
Valueset:SPACE,'X'.
40.Expand_all(1)TYPEc:Expandallpositions
Detailedscreen
40.Detail_popup(1)TYPEc:showdetailinpopup.
Valueset:SPACE,'X'
''=Listrecorddetaildisplayinfullscreenmode,withtopofpage.
'X'=listrecorddetaildisplayinpopup(withouttopofpage).
41.Detail_initial_lines(1)TYPEc:showalsoinitiallines
Valueset:SPACE,'X'
''=Onlyfieldswhosecontentsarenotinitialareoutputinthedetailview.
'X'=initialfieldcontentsarealsooutputindetail.
41.detail_titlebar(30)typec:Titlebarfordetailscreen
Valueset:SPACE,string(max.30)
''='Detail:Display'isoutputasthetitleofthedetailwindow.
'String'=thestringpassedisoutputasthetitleofthedetailwindow.

Displayvariants
42.Header_text(20)TYPEc:Textforheaderbutton.Onlyrelevantforhierarchicalsequentiallists.Youcantogglebetweendisplayfieldandfieldlistviewsviapushbuttonsinthedisplayvariantdefinition
popupforhierarchicalsequentiallists.Theviewsrefertothehierarchylevelofthefields.Thisistechnicallyatogglebetweentheheadertableanditemtablefields.
Valueset:SPACE,CHAR(20)
''=Theheadertablefieldpushbuttontextis'Header'bydefault.
CHAR(20)=headertablefieldpushbuttontext.
43.item_text(20)TYPEc:Textforitembutton.Onlyrelevantforhierarchicalsequentiallists.Youcantoggletheviewbetweenthedisplayfieldsandthefieldlistviapushbuttonsinthedisplayvariant
definitionpopupforhierarchicalsequentiallists.Theviewsrefertothehierarchylevelofthefields.Thisistechnicallyatogglebetweentheheadertableanditemtablefields.
Valueset:SPACE,CHAR(20)

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

10/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

''=Thepushbuttontextfortheitemtablefieldsis'Item'bydefault.
CHAR(20)=itemtablefieldpushbuttontext.
44.default_item(1)TYPEc:Itemsasdefault.Onlyrelevantforhierarchicalsequentiallists.
Valueset:SPACE,'X'
''=Theheadertablefieldsaredisplayedbydefaultinthedisplayvariantdefinitionpopup.Theusercanswitchtotheitemtablefieldsinteractively.
'X'=theitemtablefieldsaredisplayedbydefaultinthedisplayvariantDefinitionPopup.Theusercanswitchtotheheadertablefieldsinteractively.
Colour
45.Info_fieldnameTYPEslis_fieldname:infofieldforlistoutput.Awholelistrecordcanbecoloredindividuallyusingacolorcodeinacolumnoftheinternaloutputtablefortherecord.Assignthenameof
thefieldcontainingthecolorcodetothisparameter.
Valueset:SPACE,internaloutputtablefieldname
TheinternaloutputtablefieldmustbeoftypeCHAR(3).
Thecodemusthavethefollowingsyntax:'Cxy':
C=color(allcodesmuststartwith'C')
X=colornumber('1''9')
Y=bold('0'=off,'1'=on)
46.Coltab_fieldnameTYPEslis_fieldname:Cellscanbecoloredindividuallyusingacolorcodewhichiscontainedinacolumnoftheinternaloutputtablefortherecordcontainingthecell.Assignthename
ofthefieldtothisparameter.
Others
47.List_append(1)TYPEc:nocallscreen.Itisonlyusefultooutputblocklistswithoutspecifyingtheabovemodulesifthenumberoflistblocksexceeds,ormayexceed,themaximumnumberspecified
intheblockmoduledocumentation.Theseoperationsarenotpossibleforuserdefinedblocklists.
Examplecode:
I_LAYOUTf2code=ws_fcode.
I_LAYOUTzebra='X'.
I_LAYOUTcolwidth_optimize='X'.
I_LAYOUTno_keyfix='X'.
I_LAYOUTget_selinfos='X'.
I_LAYOUTno_hotspot='X'.
I_LAYOUTno_input='X'.
I_LAYOUThotspot_fieldname=FIELDNAME.
I_LAYOUTno_input='X'.
I_LAYOUTno_vline=`X'.
I_LAYOUTno_colhead=''.
I_LAYOUTlights_condense=``.
I_LAYOUTtotals_text=``.
I_LAYOUTsubtotals_text=``.
I_LAYOUTtotals_only=``.
I_LAYOUTkey_hotspot='X'.
I_LAYOUTdetail_popup='X'.
I_LAYOUTgroup_change_edit='X'.
I_LAYOUTGROUP_BUTTONS='X'.

Step6(PassSelectionscreenInformation)

Thisstepisrequiredtogettheselectionscreeninformationinthereportoutput.
TheprerequisiteforthisistosettheparameterLAYOUTGET_SELINFOSoftheIMPORTINGstructure.
TheparameterstobepassedintheIS_SEL_HIDEtableare:
omode:'R'=onlytheentriespassedintheinternaltableIS_SEL_HIDET_ENTRIES
Areoutputinthepopup.Selectioninfo,whichthelisttoolreadintheselectionscreen(whencalledbyareportwithaselectionscreen),isreplacedbythevaluespassed.
'S'=theselectioninfowhichthelisttoolreadintheselectionscreenofthecallingreportaremodifiedbytheentriesinthetableIS_SEL_HIDET_ENTRIES.
vt_entries:Selectioninfotable
vt_entriesmode:'A'=outputtheselectioninfoforthecurrenttablerecordintheinfopopup.
'D'=donotoutputselectoptionorSELNAMEparameterselectioninfointhepopup.
vt_entriesselname:(onlyusedint_entriesmode='D'):Nameoftheselectoptionorparameter.Thefollowingtablefieldsareonlyusedint_entriesmode='A'.Theycontaintheselectioninformationto
beadded.
t_entriesfield:DDICfieldnameofthefieldforwhichselectioninformationistobeoutput.
t_entriestable:DDICtablenamesoft_entriesfield.
t_entriesstext:Fieldnameininfopopup.
Ift_entriesfieldandt_entriestablehavebeenentered,thistextistakenfromDDIC.
t_entriesvaluf:Selectioncondition'from'value(externalformat)
t_entriesvalut:Selectioncondition'to'value(externalformat)
t_entriessign0:(I)nclusive(E)xclusive
t_entriesoption:AllvaluesoftheselectoptionsOptionfieldallowed.

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

11/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

Step7(DecidingSortCriteria)
TheTableIT_SORTispopulatedwiththesortcriteriaforthedifferentfields.
Thecallerspecifiesthesortingand/orsubtotalingofthebasiclistintheinternaltableIT_SORT.
Thisinternaltablehasthefollowingfields:
spos:Sortsequence
fieldname:Internaloutputtablefieldname
tabname:Onlyrelevantforhierarchicalsequentiallists.Nameoftheinternaloutputtable.
up:'X'=sortinascendingorder
down:'X'=sortindescendingorder
subtot:'X'=subtotalatgroupvaluechange
group:'*'=newpageatgroupvaluechange,'UL'=underlineatgroupvaluechange

Step8(FinalStep)

ThefinalstepintheoutputofthereportistheuseoftwoALVfunctionsmodules.1.REUSE_ALV_FIELDCATALOG_MERGE
2.REUSE_ALV_LIST_DISPLAY
Thefirstfunctionmoduleisusedtopassthefieldcatalogtothereportoutputandmergeitwiththeinternaloutputtable.

FUNCTIONreuse_alv_fieldcatalog_merge.
*"
*"*"LokaleSchnittstelle:
*"IMPORTING
*"VALUE(I_PROGRAM_NAME)LIKESYREPIDOPTIONAL
*"VALUE(I_INTERNAL_TABNAME)TYPESLIS_TABNAMEOPTIONAL
*"VALUE(I_STRUCTURE_NAME)LIKEDD02LTABNAMEOPTIONAL
*"VALUE(I_CLIENT_NEVER_DISPLAY)TYPESLIS_CHAR_1default'X'
*"VALUE(I_INCLNAME)LIKETRDIRNAMEOPTIONAL
*"CHANGING
*"VALUE(CT_FIELDCAT)TYPESLIS_T_FIELDCAT_ALV
*"EXCEPTIONS
*"INCONSISTENT_INTERFACE
*"PROGRAM_ERROR
*"
Importparameters
I_PROGRAM_NAME:Programinwhichtheinternaloutputtableisdeclaredandpopulated
I_INTERNAL_TABNAME:Internaloutputtablename
I_STRUCTURE_NAME:Structurename(structure,table,andview)
I_CLIENT_NEVER_DISPL:Hideclientfieldsdefault'X'
I_INCLNAME:DatadeclarationsincludenameCHANGINGparameter
CT_FIELDCAT:Fieldcatalogwithfielddescriptions
Thevariantbasedonaprograminternaltableshouldonlybeusedforrapidprototypingsincethefollowingrestrictionsapply:

1.Performanceisaffectedsincethecodeofthetabledefinitionmustalwaysbereadandinterpretedatruntime.

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

12/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

2.DictionaryreferenceareonlyconsideredifthekeywordsLIKEorINCLUDESTRUCTURE(notTYPE)areused.
Step8(DisplayInternalOutputTable)

Theotherfunctionmoduleisusedtodisplaytheinternaloutputtablewiththecontents
FUNCTIONreuse_alv_list_display.
*"
*"*"LokaleSchnittstelle:
"IMPORTING
*"VALUE(I_INTERFACE_CHECK)DEFAULTSPACE
*"VALUE(I_CALLBACK_PROGRAM)LIKESYREPIDDEFAULTSPACE
*"VALUE(I_CALLBACK_PF_STATUS_SET)TYPESLIS_FORMNAMEDEFAULTSPACE
*"VALUE(I_CALLBACK_USER_COMMAND)TYPESLIS_FORMNAMEDEFAULTSPACE
*"VALUE(I_STRUCTURE_NAME)LIKEDD02LTABNAMEOPTIONAL
*"VALUE(IS_LAYOUT)TYPESLIS_LAYOUT_ALVOPTIONAL
*"VALUE(IT_FIELDCAT)TYPESLIS_T_FIELDCAT_ALVOPTIONAL
*"VALUE(IT_EXCLUDING)TYPESLIS_T_EXTABOPTIONAL
*"VALUE(IT_SPECIAL_GROUPS)TYPESLIS_T_SP_GROUP_ALVOPTIONAL
*"VALUE(IT_SORT)TYPESLIS_T_SORTINFO_ALVOPTIONAL
*"VALUE(IT_FILTER)TYPESLIS_T_FILTER_ALVOPTIONAL
*"VALUE(IS_SEL_HIDE)TYPESLIS_SEL_HIDE_ALVOPTIONAL
*"VALUE(I_DEFAULT)DEFAULT'X'
*"VALUE(I_SAVE)DEFAULTSPACE
*"VALUE(IS_VARIANT)LIKEDISVARIANTSTRUCTUREDISVARIANTDEFAULTSPACE
*"VALUE(IT_EVENTS)TYPESLIS_T_EVENTOPTIONAL
*"VALUE(IT_EVENT_EXIT)TYPESLIS_T_EVENT_EXITOPTIONAL
*"VALUE(IS_PRINT)TYPESLIS_PRINT_ALVOPTIONAL
*"VALUE(IS_REPREP_ID)TYPESLIS_REPREP_IDOPTIONAL
*"VALUE(I_SCREEN_START_COLUMN)DEFAULT0
*"VALUE(I_SCREEN_START_LINE)DEFAULT0
*"VALUE(I_SCREEN_END_COLUMN)DEFAULT0
*"VALUE(I_SCREEN_END_LINE)DEFAULT0
"EXPORTING
*"VALUE(E_EXIT_CAUSED_BY_CALLER)
*"VALUE(ES_EXIT_CAUSED_BY_USER)TYPESLIS_EXIT_BY_USER
"TABLES
*"T_OUTTAB
"EXCEPTIONS
*"PROGRAM_ERRORImportparameters
I_INTERFACE_CHECK:Interfaceconsistencychecklogoutput.
I_CALLBACK_PROGRAM:Nameofthecallingprogram
I_CALLBACK_PF_STATUS_SET:SetEXITroutinetostatus.
I_CALLBACK_USER_COMMAND:EXITroutineforcommandhandling
I_STRUCTURE_NAME:Internaloutputtablestructurename
IS_LAYOUT:Listlayoutspecifications
IT_FIELDCAT:Fieldcatalogwithfielddescriptions
IT_EXCLUDING:Tableofinactivefunctioncodes
IT_SPECIAL_GROUPS:Groupingfieldsforcolumnselection
IT_SORT:Sortcriteriaforfirstlistdisplay
IT_FILTER:Filtercriteriaforfirstlistoutput
IS_SEL_HIDE:Selectioninformationmodification

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

13/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

I_DEFAULT:Initialvariantactive/inactivelogic
I_SAVE:Variantscanbesaved
IS_VARIANT:Variantinformation
IT_EVENTS:Tableofeventstoperform
IT_EVENT_EXIT:Standardfcodeexitrequeststable
IS_PRINT:Printinformation
IS_REPREP_ID:InitializationkeysforRe/Reinterface
I_SCREEN_START_COLUMN:Coordinatesforlistindialogbox
I_SCREEN_START_LINE:Coordinatesforlistindialogbox
I_SCREEN_END_COLUMN:Coordinatesforlistindialogbox
I_SCREEN_END_LINE:Coordinatesforlistindialogbox
IT_EVENT_EXIT:Standardfcodeexitrequeststable
IS_PRINT:Printinformation
IS_REPREP_ID:InitializationkeysforRe/Reinterface
I_SCREEN_START_COLUMN:Coordinatesforlistindialogbox
I_SCREEN_START_LINE:Coordinatesforlistindialogbox
I_SCREEN_END_COLUMN:Coordinatesforlistindialogbox
I_SCREEN_END_LINE:CoordinatesforlistindialogboxExportparameters
E_EXIT_CAUSED_BY_CALLER:DeletelistinCALLBACK_USER_COMMAND
ES_EXIT_CAUSED_BY_USER:HowtheuserleftthelistTables
T_OUTTAB:Tablewithdatatobedisplayedmandatory

Documentationonfunctionmodule:REUSE_ALV_GRID_DISPLAY
Thefunctionmoduleoutputsaninternaltablewithwhateverstructureintheformofaformattedsingleormultilinelist.Process:

Passinganinternaltablewiththesetofinformationtobeoutput
Passingastructurewithgenerallayoutspecificationsforlistlayout
Passingafieldcatalogintheformofaninternaltable
Thefieldcatalogdescribesthefieldstobeoutputinthelist.

Notes

vAllinteractionsperformedonthelistreferdirectlytotheinternaloutputtable.Sortingthelist,forexample,alsoinvolvesaresortingoftheinternaloutputtablepassed(sinceitwaspassedby
reference).
vAnimportantfactordeterminingtheusabilityofthetoolorofvariousgenericfunctions(totals,subtotals)istheexpectedamountofdatatobedisplayed.
Parameters:
I_INTERFACE_CHECK
I_BYPASSING_BUFFER
I_BUFFER_ACTIVE
I_CALLBACK_PROGRAM
I_CALLBACK_PF_STATUS_SET
I_CALLBACK_USER_COMMAND
I_CALLBACK_TOP_OF_PAGE
I_CALLBACK_HTML_TOP_OF_PAGE
I_CALLBACK_HTML_END_OF_LIST
I_STRUCTURE_NAME
I_BACKGROUND_ID
I_GRID_TITLE
I_GRID_SETTINGS
IS_LAYOUT

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

14/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

IT_FIELDCAT
IT_EXCLUDING
IT_SPECIAL_GROUPS
IT_SORT
IT_FILTER
IS_SEL_HIDE
I_DEFAULT
I_SAVE
IS_VARIANT
IT_EVENTS
IT_EVENT_EXIT
IS_PRINT
IS_REPREP_ID
I_SCREEN_START_COLUMN
I_SCREEN_START_LINE
I_SCREEN_END_COLUMN
I_SCREEN_END_LINE
IT_ALV_GRAPHICS
IT_ADD_FIELDCAT
IT_HYPERLINK
E_EXIT_CAUSED_BY_CALLER
ES_EXIT_CAUSED_BY_USER

I_CALLBACK_PROGRAM:Nameofthecallingprogram
Programfromwhichthefunctionmoduleiscalledandthatcontainstheexitroutines.Theprogramshouldalwaysbeareport,functiongroup,modulepoolorformroutinepool(itshouldnotbeaninclude).
Caution:NeverpassSYREPIDdirectlyattheinterface.IffieldSYREPIDcontainsthedesiredprogramname,youmustabsolutelyassignthisnametoanauxiliaryvariableandpassthisvariabletothe
interface.

I_CALLBACK_PF_STATUS_SET:SetEXITruntimetostatus

PassinganEXITroutineindicatestotheALVthatthecallerwantstosetaselfdefineduserstatus.Asaresult,thedefaultstatusoftheALVisnotset.Theinterfaceoftheformroutinespecifiedmustbe
definedasfollows:
FORMset_pf_statusUSINGrt_extabTYPEslis_t_extabTableRT_EXTABcontainsthefunctioncodesthatwouldbehiddenonthestandarduserinterface.

Ifthecallerwantstouseaselfdefineduserinterface(forexample,inordertoprovideadditionallistfunctionsoruseexistingfunctions),werecommendthatyoucopystandardstatusSTANDARDfrom
functiongroupSALVandmodifyitaccordingly.ALVstandardfunctioncodesalwaysstartwith'&'.
SeealsothedocumentationonparameterI_CALLBACK_USER_COMMAND.
Ifaselfdefineduserinterfaceisusedthatincludesfunctioncodesofthestandarduserinterface,thefunctioncodesoftheexcludingtablepassedshouldbetakenintoaccount.
Thismeansthattheuserstatusshouldgenerallybesetasfollows:
SETPFSTATUSuserstatusEXCLUDINGrt_extab.
Applicationfunctionscanbeaddedtoexcludingtablert_extabiftheyaretobedisabled.
TheroutineiscalledwheneverthestandarduserinterfacewouldbesetwithSETPFSTATUS.

Default

IfnoEXITroutineisspecified,theALVsetsastatusthatcorrespondstostatusSTANDARDoffunctiongroupSALV.

I_CALLBACK_USER_COMMAND:EXITroutineforcommandhandling

Description
PassinganEXITroutineindicatestotheALVthattheapplicationwantstorespondtocertainfunctioncodes.
Generally,thesearefunctioncodesthatareunknowntotheALV(thatis,arenotstandardALVfunctions)andthatweredefinedandsetbyauserstatus.
SeealsothedocumentationonparameterI_CALLBACK_PF_STATUS_SET.
Theinterfaceoftheformroutinespecifiedmustbedefinedasfollows:
FORMuser_commandUSINGr_ucommLIKEsyucommrs_selfieldTYPEslis_selfield.
ParameterR_UCOMMcontainsthefunctioncodetriggered.

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

15/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

StructureRS_SELFIELDcontainsthefollowinginformation:

otabname:Nameoftheinternaloutputtable
otabindex:Indexoftheinternaloutputtable
ofieldname:Fieldname
oendsum:Cursorislocatedonthetotalsline
osumindex:If>0,thecursorislocatedonasubtotalsline
ovalue:Valueofthefieldonthelist
orefresh:(Exporting)Listshouldbesetupagain
ocol_stable:(Exporting)Keepcolumnpositionwhenlistissetupagain
orow_stable:(Exporting)Keeprowpositionwhenlistissetupagain
oexit:(Exporting)Exitlist(andALV)
obefore_action:Callbeforestandardactionexecution
oafter_action:Callafterstandardactionexecution,beforelistsetup
oignore_multi:Internaluse
osel_tab_field:Internaluse
TheEXITroutineiscalledwheneverafunctionunknowntotheALVistriggeredoriftheroutinecallbefore/aftertheexecutionofastandardfunctioncodehasbeendefinedbyinterfaceparameter
IT_EVENT_EXIT.
SeealsothedocumentationonparameterIT_EVENT_EXIT.
ThefunctioncodeandthecurrentcursorpositionarethenpassedontothecallingprogramthroughtheEXITroutine.
Iftheuserhasselectedmultiplerowsbyselectingcheckboxes,theoutputtablefielddesignatedasthecheckboxcontainsthecurrentstateofthecheckboxinthelist.I_CALLBACK_TOP_OF_PAGE

EXITroutineforhandlingTOPOFPAGE
Description
IfthecallerspecifiesanEXITroutine,thisroutinemusthavethefollowingform:
FORMtop_of_page.
ModuleREUSE_ALV_COMMENTARY_WRITEcanthenbecalledwithintheEXITroutine.ThismoduleisresponsibleforformattingtheheaderinformationandalsoensuresonlineHTMLformatting.Inthe
printprevieworinbatchmode,thetextpassedisthenoutputinthenormalformat.
IfmoduleREUSE_ALV_COMMENTARY_WRITEcannotbeused,youmustusetwoparametersinstead.InI_CALLBACK_TOP_OF_PAGEyoupasstheformroutinethatisresponsiblefornormal
formattinginbatchmodeorintheprintpreviewmode.Theformroutinethatisresponsibleforonlineformatting,ispassedinparameterI_CALLBACK_HTML_TOP_OF_PAGE.Ifoneoftheseparametersis
notfilled,topofpageisnotoutputintherespectivemode.

I_CALLBACK_HTML_TOP_OF_PAGE
EXITroutineforHTMLTOPOFPAGE
Description
IffunctionmoduleREUSE_ALV_COMMENTARY_WRITEisnotusedintheformforCALLBACK_TOP_OF_PAGE,theformroutinemustbepassedinparameter
I_CALLBACK_HTML_TOP_OF_PAGEfortheonlinemode.Theformshouldthen
havethefollowingformat:
formtop_of_pageusingcl_ddtypereftocl_dd_document.
Intheform,youcan,forexample,usemethodsofclassCL_DD_DOCUMENT
todisplaytextinHTMLformat.I_CALLBACK_HTML_END_OF_LIST

EXITroutineforHTMLENDOFLIST
Description
Inthisparameter,youcanpassaformfortheonlinehandlingofendoflist.Theformmusthavethefollowiongformat:

FormEnd_of_ListusingCl_ddtypereftocl_dd_document.I_STRUCTURE_NAME

Internaloutputtablestructurename
Description
IftheinternaloutputtableisdefinedthroughanABAPDictionarystructure(INCLUDESTRUCTUREstructorLIKEstruct),youcanautomaticallysetupthefieldcatalogbypassingthestructurename.
Thefieldcatalogistheninternallysetupforthisstructureasfollows:
oAllfieldsareonthelist(NO_OUT=SPACE)exceptfieldsofdatatypeCLNT.
oThekeyfieldsoftheDictionarystructureareadoptedinthefieldcatalogaskeyfields.
oReferencestounitfieldsstoredintheDictionaryareadoptedprovidedthatthereferencefieldsarecontainedinthestructure.
oIfyouadditionallypassafieldcatalogasparameter,thestructureinformationismergedwiththisfieldcatalog.
Formoreinformationonhowtosetupthefieldcatalogautomatically,seethedocumentationonfunctionmoduleREUSE_ALV_FIELDCATALOG_MERGE.I_GRID_TITLE

Controltitle
Description:Specifiesthetitleofthecontrol.Thistextisdisplayedabovethegrid.I_GRID_SETTINGS

Gridsettings
Description
IfTopofPageorEndofListareoutputonline,theseareasaredisplayedinasplitteraboveorbelowthelist.UsingI_GRID_SETTINGSyoucanreducethedefaultsizeto0%.Todothis,youusetwo
fields:
COLL_TOP_P:SetsTopofPageto0%
COLL_END_L:SetsEndofListto0%IS_LAYOUT

Listlayoutspecifications

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

16/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

Description
Structurefordescribingthelisttobeoutput.
Theparametersaredescribedandgroupedbasedonthefollowing
categories:
Displayoptions
Exceptions
Totals
Interaction
Detailscreen
Color
Other
Notethesectiononpredefinedsettings.Displayoptions

colwidth_optimizeValuerange:SPACE,'X'
X'=Optimizesthecolumnwidthtoensurethatthecontentisdisplayedcompletely.

no_colheadValuerange:SPACE,'X'
'X'=Donotoutputcolumnheadings.

zebraValuerange:SPACE,'X'
'X'=Stripedpattern(forwidelists,forexample)

no_vlineValuerange:SPACE,'X'
'X'=SeparatecolumnsbySPACE.

Exceptions
lights_fieldname
Valuerange:SPACE,fieldnameoftheinternaloutputtablefieldoftheinternaloutputtablethatcontainsthecodingoftheexceptionstobeoutput.
Codinginthefieldoftheoutputtable:
'1'=redtrafficlight
'2'=yellowtrafficlight
'3'=greentrafficlightlights_tabname
Valuerange:SPACE,tablenameoftheinternaloutputtableTablenameoftheinternaloutputtablethatcontainsthespecifiedfieldinparameterLIGHTS_FIELDNAME.lights_rollname
Valuerange:SPACE,dataelementname
ThedocumentationdefinedforthisdataelementisdisplayedwhentheF1helpforanexceptioncolumniscalled.lights_condense
Valuerange:SPACE,'X'
'X'=Thesystemoutputsthe'maximum'exceptionoftheitemsincludedinthetotalatsubtotallevel.
Example:Ifalistrowisoutputwitha'redtrafficlight',eachsubtotalincludedinthislistrowisalsodisplayedwitha'redtrafficlight'.Totals

no_sumchoice
Valuerange:SPACE,'X'
'X'=Valuefieldsforwhichtotalsarecalculatedarecommunicatedbythecallingprogram(FIELDCATDO_SUM='X').Theusershouldnotbeallowedtochangethispredefinedsettinginteractively.
no_totalline
Valuerange:SPACE,'X'
'X'=Nooveralltotalslineshouldbedisplayed.Ifrequired,subtotalscanneverthelessbecalculatedanddisplayed.Thefieldswhichareusedforcalculatingsubtotalsaretobemarkedwith
DO_SUM='X'inthefieldcatalog.no_subchoice
Valuerange:SPACE,'X'
'X'=Characteristicsatwhosecontrollevelsubtotalsshouldbecalculatedarecommunicatedbythecallingprogram.Theusershouldnotbeallowedtochangethispredefinedsettinginteractively.
SeealsothedocumentationonIMPORTINGparameterIT_SORT.
no_subtotals
Valuerange:SPACE,'X'
'X'=Calculatingsubtotalsshouldnotbeallowed.
totals_only
Valuerange:SPACE,'X'
'X'=Dataisoutputincompressedformatonlyattotalslinelevel.
Prerequisite:IMPORTINGparameterIT_SORTisfilledaccordinglywiththesortcriteriaandthesubtotalsindicator.
SeealsothedocumentationonIMPORTINGparameterIT_SORT.
totals_text

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

17/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

Valuerange:SPACE,string(notmorethan60)
''=Inthefirstcolumn,thestandardsystemindicatesthetotalslevelbydisplayinganadequatenumberof'*'fortheoveralltotal.Aftertheasterisks,thesystemdisplaysthestring'total'provided
thatthecolumnwidthofthefirstoutputcolumnislargeenough.Ifthecolumnwidthisnotsufficient,onlytheasterisksaredisplayed.
'string'=Afterthetotalslevelindicatedvisuallybymeansof'*',thesystemdisplaysthestringpassedprovidedthatthecolumnwidthissufficient.
subtotals_text
Valuerange:SPACE,string(notmorethan60)''=Inthefirstcolumn,thestandardsystemindicatesthetotalslevelbydisplayinganadequatenumberof'*'forthesubtotalsline.Aftertheasterisks,
thesystemdisplaysthestring*total*providedthatthecolumnwidthofthefirstoutputcolumnislargeenoughandthecharacteristicofthefirstcolumnisnotasubtotalcriterion.Ifthecolumnwidthisnot
sufficient,onlytheasterisksaredisplayed.
'string'=Afterthetotalslevelindicatedvisuallybymeansof'*',thesystemdisplaysthestringpassedprovidedthatthecolumnwidthissufficientandthecharacteristicofthefirstcolumnisnotasubtotal
criterion.
Ifthecharacteristicisasubtotalcriterion,thesystemrepeatsthecharacteristicvalueforwhichsubtotalswerecalculatedafterthetotalslevelprovidedthatthecolumnwidthissufficient.
numc_sum
Valuerange:SPACE,'X'
''=Inthestandardsystem,itisnotpossibletocalculatetotalsforNUMCfields.
'X'=ItisgenerallypossibletocalculatetotalsforNUMCfields.Ifthisindicatorisset,youcanuseparameterFIELDCATNO_SUMtocontrolforeachNUMCcolumnwhethertotalscanbecalculatedor
not.Interaction
box_fieldname
Valuerange:SPACE,fieldnameoftheinternaloutputtable.Ifthelistshouldhavecheckboxesatthebeginningofeachlistrow(toallowtheusertoselectmultiplerowsatonce),youmustfillthis
parameterwiththefieldnameoftheinternaloutputtablethatrepresentstheselectioncolumnforselectingrowswiththehelpofcheckboxes.Thefieldisalwaysdisplayedasacheckboxatthebeginning
ofeachlistrowwithoutalistheading.
box_tabname
Valuerange:SPACE,tablenameoftheinternaloutputtable
f2code
Valuerange:SPACE,functioncode
MeaningwhentheALVstandardinterfaceisused:
IfyouwanttoassignastandardALVfunctioncodetoadoubleclick(F2),youmustassignthisfunctioncodetothisparameter.
Example:YouwanttoassignthestandardALVfunction'Detail'
('&ETA')toF2.
=>LAYOUTF2CODE='&ETA'
Meaningifaselfdefinedinterfaceisused:Case1:
YouleavethestandardALVfunctioncodeforF2'&IC1'inthecopiedinterfaceoftheapplication.However,youwanttohaveafunctionexecutedwithF2thatisnotassignedtoF2intheinterface
(standardALVfunctionorapplicationfunction).YoumustcommunicatethisfunctioncodetotheALVusingparameterF2CODE.Case2:
YouremovethestandardALVfunctioncodeforF2'&IC1'fromtheinterfaceoftheapplicationanduseanotherfunctioncodeinstead(standardALVfunctionorapplicationfunction).Youmust
communicatethisfunctioncodetotheALVusingparameterF2CODE.
Thisisrequiredifyouwanttoallowcolumnstobeselected.
confirmation_prompt
Valuerange:SPACE,'X'
'X'=Ifoneofthefunctions'Back(F03)','Exit(F15)'or'Cancel(F12)'istriggered,thesystemaskstheuserifhewantstoleavethelist.
key_hotspot
Valuerange:SPACE,'X'
Thecolumnsdefinedaskeyfieldsinthefieldcatalog(FIELDCATKEY='X')areoutputasahotspot.Thismeansthatsingleclickingakeyfield(highlightedincolorinthelist)triggersthefunction
assignedtoF2.
reprep
Valuerange:SPACE,'X'
'X'=Enablereport/reportinterface
Prerequisite:Applicationsystem(=>reportRKKBRSTIexists).
Thelistmoduleactsasapotentialsenderinthereport/reportinterface(interfaceinitialization,ifrequired).
Thecallingreport/modulepoolenteredinI_CALLBACK_PROGRAMisdeclaredtothereport/reportinterfaceasthesenderreportwithtypeRT=Report.Ifthesenderreportisassignedtoreceiverreports
intableTRSTI,functioncodeBEBxissettoactive.(x=functioncodeclass)Example:
IfsenderRKTFGS15hasareceiverassignmentforReportWriterreportgroup7KOIwithfunctioncodeclass'3'(SAPsetting),thisreceiverreportgroupiscalledthroughthereport/reportinterface
atfunctioncode'BEB3'.Theselectionspassedtothereport/reportinterfacearethereportselectionsandthekeyinformationoftheselectedrow.
Formoreinformationonthereport/reportinterface,seethedocumentationonfunctiongroup'RSTI'.Detailscreen
detail_initial_lines

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

18/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

Valuerange:SPACE,'X'
''=Inthedetailview,thesystemdisplaysonlyfieldswhosecontentisnotsettoinitial.
'X'=Initialfieldcontentsarealsodisplayedonthedetailscreen.
detail_titlebar
Valuerange:SPACE,string(notmorethan30)
''=Thesystemdisplays'Detail:Display'asthetitleofthedetailscreen.
'string'=Thesystemdisplaysthestringpassedasthetitleofthedetailscreen.Color
info_fieldname
Valuerange:SPACE,fieldnameoftheinternaloutputtable.
Youcancoloranentirelistrowindividuallybyusingacolorcodethatissetforeachrowinacolumnoftheinternaloutputtable.Youmustassignthefieldnameofthefieldwiththecolorcodeto
thisparameter.
ThefieldoftheinternaloutputtablemustbeoftypeCHAR(3).
Thecodemustcomplywiththefollowingsyntax:'Cxy':
C=Color(eachcodemustbeginwith'C')
x=Colornumber('1''9')
y=Intensified('0'=off,'1'=on)
Note:Thecolorofthekeycolumnisnotaffected.Ifyoualsowant
tocolorthekeycolumnatroworcelllevel,youcanusecomplex
coloringwhichisdescribedbelowforparameterCOLTAB_FIELDNAME.
Forinformationoncoloringcolumns,seethedocumentationonfieldcatalogparameterFIELDCATEMPHASIZEofIMPORTINGparameterIT_FIELDCAT.
coltab_fieldname
Valuerange:SPACE,fieldnameoftheinternaloutputtable
Youcancolorcellsindividuallybyusingacolorcodethatissetfortherowofthecellsinacolumnoftheinternaloutputtable.Youmustassignthefieldnameofthefieldwiththecolorcodetothis
parameter.
ThefieldoftheinternaloutputtablemustbeoftypeSLIS_T_SPECIALCOL_ALV.
Principle:Thefieldforthecolorcodeisfilledintherowinwhichthecellstobecoloredarelocated.Thefieldthencontainsaninternaltableoftheabovestructurethatincludesthefieldnamesofthecellsto
becoloredwiththecolorcode.Thecellcoordinatesarethereforederivedfromtherowpositioninwhichthecolorcodeiswrittenandthecolumninformationcontainedinthecolortable.Therowstructure
oftheinternalcolortableoftypeSLIS_T_SPECIALCOL_ALVisasfollows:
FarbtabelleNAME=Fieldnameofcelltobecolored
FarbtabelleCOLORCOL=Colornumber(19)
FarbtabelleCOLORINT=Intensified(0=off,1=on)
FarbtabelleCOLORINV=Inverse(0=off,1=on)
FarbtabelleNOKEYCOL=Ignorekeycoloring('X'=yes,''=no)
IfparameterFarbtabelleNAMEisnotfilled,allcolorspecificationsrefertoallfields.Asaresult,theentirerowiscolored.
Default
Inmanycases,thedefaultlayoutsettingscanbekeptsothatyoufrequentlydonotneedtopassthisstructurewithmodifiedflags.IT_FIELDCAT
FieldcatalogwithfielddescriptionsDescription

Fieldcatalogcontainingthefielddescriptionsofthefieldstobeconsideredforthelistoutput(usually,thisisasubsetofthefieldsintheinternaloutputtable).
Basically,youneedafieldcatalogforeachlistoutputthatusestheALV.
Thefieldcatalogassociatedwiththeoutputtableisgeneratedinthecodeofthecaller.Youcangeneratethefieldcatalogautomaticallyorsemiautomaticallybycallingfunctionmodule
REUSE_ALV_FIELDCATALOG_MERGE.
Seealsothedocumentationonfunctionmodule:REUSE_ALV_FIELDCATALOG_MERGE.
Theminimumvaluesrequiredforthefieldcatalogaredocumentedinthe'Default'section.Thecallercanoptionallyuseallotherparameterstoassignnonstandardoutputattributestoafield.
Itisonlyinthefollowingcasesthatyouarenotrequiredtogeneratethefieldcatalogandpassitexplicitly:
ThestructureoftheinternaltabletobeoutputcorrespondstoastructurestoredintheDataDictionaryandisreferencedwithLIKEorINCLUDESTRUCTUREinthedeclarationoftheinternaltable.
Allfieldsofthisstructureshouldbeoutputinthelist.
ThestructurenameisdeclaredtotheALVusingparameterI_STRUCTURE_NAME.
SeealsothedocumentationonIMPORTNGparameterI_STRUCTURE_NAME.Positioning
col_pos(columnposition)
Valuerange:0,160
Onlyrelevantiftherelativecolumnpositionsshouldbydefaultnotbeidenticaltothesequenceofthefieldsinthefieldcatalog.
Theparameterdeterminestherelativecolumnpositionofthefieldinthelistoutput.Thecolumnsequencecaninteractivelybechangedbytheuser.Ifthisparameterissettoitsinitialvalueforeach
fieldcatalogentry,thecolumnsarearrangedintheorderofthefieldsinthefieldcatalog.
Identification
fieldname(fieldname)
Valuerange:Fieldnameoftheinternaloutputtable(requiredparameter)

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

19/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

Fieldnameofthefieldintheinternaloutputtablethatisdescribedbythisfieldcatalogentry.
ReferencetotheDataDictionaryref_fieldname(fieldnameofthereferencefield)
Valuerange:SPACE,nameofafieldintheDataDictionaryNameofthereferencedfieldintheDataDictionary.
ThisparameterisonlyrequiredifthefieldintheinternaloutputtablethatisdescribedbythecurrententryinthefieldcataloghasareferencetotheDataDictionary(thatis,isnotaprogramfield)andif
thefieldnameintheinternaloutputtableisnotidenticaltothefieldnameofthefieldintheDataDictionary.Ifbothfieldnamesareidentical,itissufficienttospecifytheDataDictionarystructureortablein
parameterFIELDCATREF_TABNAME.
ref_tabname(fieldnameofthereferencetable/structure)
Valuerange:SPACE,nameofastructureortableintheDataDictionaryStructureortablenameofthereferencedfieldintheDataDictionary.
ThisparameterisonlyrequiredifthefieldintheinternaloutputtablethatisdescribedbythecurrententryinthefieldcataloghasareferencetotheDataDictionary(thatis,isnotaprogramfield).
Referencetofieldswithcurrencyunits/unitsofmeasure
Eachamountorquantityfieldoftheinternaloutputtablewhosedecimalplacesaretobedisplayedwiththeproperunitinthelistoutput,mustcomplywiththefollowingconventions:
ThefieldisofdatatypeQUANorCURR(internaltypeP).
(Physically,thefieldmustactuallybelongtothisdatatype.
OverridingthephysicaldatatypewithparameterFIELDCATDATATYPEhasnoeffect.)
Thereisonefieldintheinternaloutputtablethatcontainstherelevantunit.
Thereisalsoanentryfortheunitfieldinthefieldcatalog.
(Iftheunitshouldnotbedisplayedasacolumninthelistandtheusershouldnotbeabletoshowtheunitinteractively,forexample,becausetheunitisalwaysuniqueandthereforeexplicitlyoutput
bythecallerinthelistheader,thenyoucanassignparameterFIELDCATTECH='X'tothefieldcatalogentryfortheunitfield.
Ifavaluefieldhasareferencetoaunit,thishasthefollowingeffectswhenthelistisoutput:
Thedecimalplacesaredisplayedwiththeproperunit.
Aninitialvaluefieldwithreferencetoanoninitialunitisdisplayedas'0'(providedthatFIELDCATNO_ZEROisinitial).Ifunitspecifictotalsarecalculatedforthisvaluefield,theunitisconsideredin
theanalysisofwhetherhomogeneousunitsexist.
AninitialvaluefieldwithreferencetoaninitialunitisdisplayedasSPACE.Ifunitspecifictotalsarecalculatedforthisvaluefield,theunitSPACEhasnoeffectonthehomogeneityoftheunitifthe
valuefieldisinitial.
Fornoninitialvaluefieldswithinitialunit,theunitSPACEisconsideredasaunitwhenunitspecifictotalsarecalculated.
Referencetothecurrencyunit
cfieldname(fieldnameofthecurrencyunitfield)
Valuerange:SPACE,nameofafieldoftheoutputtableOnlyrelevanttoamountcolumnswithunitreference.Fieldnameofthefieldintheinternaloutputtablethatcontainsthecurrencyunitforthe
amountfieldFIELDCATFIELDNAME.
TheremustbeaseparatefieldcatalogentryforthefieldspecifiedinFIELDCATCFIELDNAME.
Referencetotheunitofmeasure
qfieldname(fieldnameoftheunitofmeasurefield)
Valuerange:SPACE,nameofafieldoftheoutputtable
Onlyrelevanttoquantitycolumnswithunitreference.
FieldnameofthefieldintheinternaloutputtablethatcontainstheunitofmeasurefortheamountfieldFIELDCATFIELDNAME.
TheremustbeaseparatefieldcatalogentryforthefieldspecifiedinFIELDCATQFIELDNAME.
Outputoptionsforacolumn
outputlen(columnwidth)
Valuerange:0(initial),n
ForfieldswithreferencetotheDataDictionaryyoucanleavethisparametersettoinitial.
ForfieldswithoutreferencetotheDataDictionary(programfields)youmustsettheparametertothedesiredfieldoutputlengthonthelist(columnwidth).
initial=Thecolumnwidthisderivedfromtheoutputlengthofthereferencedfield(domain)intheDataDictionary.
n=Thecolumnwidthisncharacters.
key(keycolumn)
Valuerange:SPACE,'X'
'X'=Keyfield(coloredoutputforkeyfields)
Keyfieldscannotbehiddeninteractivelybytheuser.
ParameterFIELDCATNO_OUTmustbeleftsettoinitial.
Forexceptions,seethedocumentationonparameterFIELDCATKEY_SEL.
key_sel(keycolumnthatcanbehidden)
Valuerange:SPACE,'X'
OnlyrelevantifFIELDCATKEY='X'
Keyfieldthatcanbehiddeninteractivelybytheuser.
Theusercannotinteractivelychangethesequenceofthekeycolumns.
Aswithnonkeyfields,outputcontrolisperformedusingparameterFIELDCATNO_OUT.
no_out(fieldintheavailablefieldslist)
Valuerange:SPACE,'X'
'X'=Fieldisnotdisplayedonthecurrentlist.
Thefieldisavailabletotheuserinthefieldlistandcanbeinteractivelyselectedasadisplayfield.
Atrowlevel,theusercanusethedetailfunctiontodisplaythecontentofthesefields.
Seealsothedocumentationonthe'Detailscreen'sectionofparameterIS_LAYOUT.
tech(technicalfield)
Valuerange:SPACE,'X'
'X'=Technicalfield
Thefieldcannotbeoutputonthelistandcannotbeshowninteractivelybytheuser.
Thefieldmayonlybeusedinthefieldcatalog(notinIT_SORT,...).
emphasize(highlightcolumnincolor)
Valuerange:SPACE,'X'or'Cxyz'(x:'1''9'y,z:'0'=off'1'=on)
'X'=Thecolumnishighlightedinthedefaultcolorforcolorhighlighting.
'Cxyz'=Thecolumnishighlightedinthecodedcolor:
C:Color(codingmuststartwithC)
x:Colornumber
y:Intensified
z:Inverse
hotspot(columnashotspot)
Valuerange:SPACE,'X'
'X'=Thecellsofthecolumnareoutputasahotspot.

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

20/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

do_sum(calculatetotalsforcolumn)
Valuerange:SPACE,'X'
'X'=Totalsarecalculatedforthisfieldoftheinternaloutputtable.
Thisfunctioncanalsobeusedinteractivelybytheuser.
no_sum(totalscalculationnotallowed)
Valuerange:SPACE,'X'
'X'=Nototalsmaybecalculatedforthisfieldalthoughthedatatypeofthefieldallowstotalling.
Formattingcolumncontents
icon(icon)
Valuerange:SPACE,'X'
'X'=Thecolumncontentsaredisplayedasanicon.
Thecolumncontentsoftheinternaloutputtablemustconsistofvalidiconstrings().
Thecallershouldconsidertheproblemofprintingicons.
symbol(symbol)
Valuerange:SPACE,'X'
'X'=Thecolumncontentsareoutputasasymbol.
Thecolumncontentsoftheinternaloutputtablemustconsistofvalidsymbolcharacters.
Thecallershouldconsidertheproblemofprintingsymbols.
Althoughsymbolscangenerallybeprinted,theyarenotalwaysshowncorrectlydependingontheprinterconfiguration.
just(justification)
Valuerange:SPACE,'R','L','C'
OnlyrelevanttofieldsofdatatypeCHARorNUMC
''=Defaultjustificationaccordingtodatatype
'R'=Rightjustifiedoutput
'L'=Leftjustifiedoutput
'C'=Centeredoutput
Thejustificationofthecolumnheaderdependsonthejustificationofthecolumncontents.Youcannotjustifythecolumnheaderindependentlyofthecolumncontents.
lzero(leadingzeros)
Valuerange:SPACE,'X'
OnlyrelevanttofieldsofdatatypeNUMC
Bydefault,NUMCfieldsareoutputintheALVrightjustifiedwithoutleadingzeros.
'X'=Outputwithleadingzeros
no_sign(no+/sign)
Valuerange:SPACE,'X'
Onlyrelevanttovaluefields
'X'=Valueoutputwithout+/signs.
no_zero(suppresszeros)
Valuerange:SPACE,'X'
Onlyrelevanttovaluefields
'X'=Supresszeros
edit_mask(fieldformatting)
Valuerange:SPACE,mask
mask=SeedocumentationontheWRITEformattingoption
USINGEDITMASKmask
Usingmask='==conv'youcanforceanoutputconversionconv.
Texts
ThefollowingparametersfortextsarealwaysrequiredforprogramfieldswithoutreferencetotheDataDictionary.
ForfieldswithreferencetotheDataDictionary,thetextsareretrievedfromtheDataDictionary.Ifyoudonotwantthis,youcanfillthetextparametersalsoforfieldswithreferencetotheData
Dictionary.Ifyoudothis,thecorrespondingtextsfromtheDataDictionarywillbeignored.
Iftheuserchangesthecolumnwidthinteractively,thetextwiththeappropriatelengthisalwaysusedasthecolumnheader.
Iftheuseroptimizesthecolumnwidthinteractively,boththefieldcontentsandthecolumnheadingsareconsideredforthelistoutput:
Ifallfieldcontentsareshorterthantheshortestcolumnheading,thecolumnwidthissetbasedonthecolumnheading.
Thelongfieldlabelisalsousedinthedialogboxesfordefiningthedisplayvariant,thesortorder,andsoon.
seltext_l(longfieldlabel)
seltext_m(mediumfieldlabel)
seltext_s(shortfieldlabel)
reptext_ddic(heading)
Sameasthe'heading'fordataelementmaintenance.
Whenthelistisoutput,thesystemdoesnotnecessarilyretrievethetextstoredhere,butusesthetextthatfitsbest.
ddictxt(determinetext)
Valuerange:SPACE,'L','M','S','R'
Usingpossiblevalues'L','M','S','R'youcanpredefinethekeywordthatshouldalwaysberetrievedasthecolumnheader.Ifthecolumnwidthischanged,thesystemtriestofindaheadingthatfitsthe
newoutputwidth.
ParameterforprogramfieldswithoutreferencetotheDataDictionary
Seealsotheparameterinthe'Texts'section.
datatype(datatype)
Valuerange:SPACE,datatypefromtheDataDictionary(CHAR,NUMC,...)
OnlyrelevanttofieldswithoutreferencetotheDataDictionary.Datatypeofprogramfield
ddic_outputlen(externaloutputlength)
Valuerange:0(initial),n
OnlyrelevanttofieldswithoutreferencetotheDataDictionarywhoseoutputshouldneverthelessbemodifiedusingaconversionexit.
Prerequisites:
FIELDCATEDIT_MASK='==conv'
SeealsothedocumentationonparameterFIELDCATEDIT_MASK
FIELDCATINTLEN=n
SeedocumentationonparameterFIELDCATINTLEN
n=Fieldoutputlengthoftheexternaldisplay

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

21/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

ThecolumnwidthFIELDCATOUTPUTLENmustnotbeequivalenttotheoutputlengthoftheexternaldisplay(FIELDCATDDIC_OUTPUTLEN).
ointlen(internaloutputlength)
Valuerange:0(initial),n
OnlyrelevanttofieldswithoutreferencetotheDataDictionarywhoseoutputshouldneverthelessbemodifiedusingaconversionexit.
Prerequisites:
FIELDCATEDIT_MASK='==conv'
SeealsothedocumentationonparameterFIELDCATEDIT_MASK
FIELDCATDDIC_OUTPUTLEN=n
SeealsothedocumentationonparameterFIELDCATDDIC_OUTPUTLEN
n=Fieldoutputlengthoftheinternaldisplay
orollname(dataelement)
Valuerange:SPACE,nameofadataelementfromtheDataDictionary
YoucanusethisparametertoprovideanF1helpforaprogramfieldwithoutreferencetotheDataDictionaryortoprovideanF1helpotherthanthatoftheDataDictionaryforafieldwithreferenceto
theDataDictionary.
WhentheF1helpiscalledforthisfield,thedocumentationforthedataelementassignedisdisplayed.
If,forfieldswithreferencetotheDataDictionary,
FIELDCATROLLNAMEisinitial,thedocumentationforthedataelementofthereferencedfieldintheDataDictionaryisdisplayed.
Other
osp_group(fieldgroupkey)
Valuerange:SPACE,CHAR(1)
Keyforgroupingfields
Youassignthekeytothegroupdescriptionusingparameter
IT_SPECIAL_GROUPS(seealsothedocumentationonparameterIT_SPECIAL_GROUPS).
Ifyoudefinesuchanassignmentinthefieldcatalogusing
IT_SPECIAL_GROUPS,thefieldsinthefieldlistofthedisplayvariantdialogboxaregroupedaccordingly.
oreprep(selectioncriterionofthereport/reportinterface)
Valuerange:SPACE,'X'
Prerequisites:
Thereport/reportinterfaceexistsinthesystem.
(functiongroupRSTI,tableTRSTI)
ParameterLAYOUTREPREP='X'
(Seealsothedocumentationonparameter
LAYOUTREPREPofIMPORTINGparameterIS_LAYOUT)
'X'=Ifthereport/reportinterfaceiscalled,thevalueofthisfieldispassedasaselectioncriterionintheselectedbranchlineoftheinterface.

Default
oForinternaltablefieldswithreferencetoafielddefinedinthe
DataDictionary,itisnormallysufficienttomakethefollowingspecifications:fieldname
ref_tabname
Note:
Allfieldsnotexplicitlymentionedhereareeithernotrelevantinthiscontextorarenotreleased!
AllotherinformationisretrievedbytheALVfromtheDataDictionary.
Ifyoudonotspecifytherelativecolumnposition(COL_POS),thefieldsareoutputinthelistintheorderinwhichtheywereaddedtothefieldcatalog.
REF_FIELDNAMEmustonlybespecifiedifthefieldnameoftheinternaltablefieldisnotidenticaltothefieldnameofthereferencedfieldintheDataDictionary.
Priorityrule:
SpecificationsmadeinthefieldcatalogtakepriorityoverspecificationsintheDataDictionary.

ForinternaltablefieldswithoutreferencetotheDataDictionary(programfields),itisnormallysufficienttomakethefollowingspecifications:fieldname
outputlen
datatype(withoutdatatype,characteristhedefault)
seltext_s
seltext_l
Note:
IfyouassignadataelementtoparameterROLLNAME,youcan,forexample,implementanF1helpforprogramfields.
IT_EXCLUDING
Tableofinactivefunctioncodes
Description
OptionalIMPORTINGparameterIT_EXCLUDINGisaninternaltable.Youmustonlyfillthistableifthecallerusesthestandardinterfaceofthelisttoolbutdoesnotneedcertaininterfacefunctionsand
thereforewantstodisablethem.
Inthiscase,youmustenterthefunctioncodesofthesestandardfunctionsintothetable.
IT_SORT
Sortcriteriaforfirstlistdisplay
Description
UsinginternaltableIT_SORT,thecallerdeterminesthesortorderand/orthesubtotallingofthebasiclist.
Thefollowingfieldsofthisinternaltablemustbefilled:
ospos:Sortorder
ofieldname:Fieldnameintheinternaloutputtable
oup:'X'=Sortedinascendingorder
odown:'X'=Sortedindescendingorder
osubtot:'X'=Subtotalsforcontrollevelchanges
ocomp(INTERNALUSEONLY)
oexpa
Perquisites:
IT_SORTSUBTOT='X',thatis,thesortcriterionisalsothesubtotalscriterion.
Ifnocompletebreakdownbutonlyabreakdowntototalslevelnthatcanbefurtherexpandedbytheusershouldbedisplayedwhenthelistisoutputforthefirsttime,youmustsettheindicatorforthe
totalslevelcriterionofleveln.

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

22/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

IT_FILTER
Filtercriteriaforfirstlistoutput
Description
Tablewithfiltercriteria
Usingthisparameter,youcanpassonfiltercriteriaresultingfromexplicitlyloadingadisplayvariantinadvance,forexample,tolistoutput.
Thistableshouldneverbesetup'manually'.

IS_SEL_HIDE
Selectioninformationmodification
Description
Thisparameteriscurrentlynotsupported!
OnlyrelevantiflayoutparameterLAYOUTGET_SELINFOSofIMPORTINGstructureIS_LAYOUTisset.
Complextypeformodifyinginformationdisplayedontheselectiondialogbox:
omode:'R'=OnlyentriespassedininternaltableIS_SEL_HIDET_ENTRIESareoutputonthedialogbox.Selectioninformationobtainedbythelisttoolbyreadingtheselectionscreenagain
(onlyifthereportiscalledwithselectionscreen)arereplacedbytheentriespassed.
'S'=Theselectioninformationobtainedbythelisttoolbyreadingtheselectionscreenofthecallingreportagain,aremodifiedbytheentriesoftableIS_SEL_HIDET_ENTRIES.
ot_entries:Tablewithselectioninformation
ot_entriesmode:'A'=Displayselectioninformationofthecurrenttablerowontheinformationdialogbox.
'D'=DonotdisplayselectioninformationoftheSelectoptionorofparameterSELNAMEonthedialogbox.
ot_entriesselname:(requiredonlyift_entriesmode='D')nameofSelectoptionorparameter
Thefollowingtablefieldsareonlyrequiredift_entriesmode='A'.
Theycontaintheselectioninformationtobeadded.
ot_entriesfield:DDICfieldnameofthefieldforwhichselectioninformationistobedisplayed
ot_entriestable:DDICtablenameoft_entriesfield.
ot_entriesstext:Fielddescriptionontheinformationdialogbox.
Ift_entriesfieldandt_entriestablewerefilled,thistextistakenfromtheDDIC.
ot_entriesvaluf:Selectionconditionfromvalue(externalformat)
ot_entriesvalut:Selectionconditiontovalue(externalformat)
ot_entriessign0:(I)nclusive(E)xclusive
ot_entriesoptio:AllvaluesoftheoptionfieldoftheSelectoptionareallowed.
Theremainingfieldsareusedinternallyandareirrelevanttothecaller.

I_DEFAULT
Initialvariantactive/inactivelogic
Description
Initialvariantmaintenanceactive/inactive..
Prerequisite:ParameterIS_VARIANTisfilledaccordingly.
SeealsothedocumentationontheIMPORTINGparameterIS_VARIANT.
ValueRange
SPACE=Definitionofinitialvariantsnotallowed
'X'=Definitionofinitialvariantsallowed
Default:SPACE
I_SAVE
Variantscanbesaved
Description
Controlsthesavemode
Prerequisite:
ParameterIS_VARIANTisfilledaccordingly.
SeealsothedocumentationonIMPORTINGparameterIS_VARIANT.
ValueRange
o''=Displayvariantscannotbesaved
Defineddisplayvariants(suchasdelivereddisplayvariants)canbeselectedforpresentationregardlessofthisindicator.However,changescannotbesaved.
o'X'=Standardsavemode
Displayvariantscanbesavedasstandarddisplayvariants.
Savingdisplayvariantsasuserspecificisnotpossible.
o'U'=Userspecificsavemode
Displayvariantscanonlybesavedasuserspecific.
o'A'=Standardanduserspecificsavemode
Displayvariantscanbesavedbothasuserspecificandasstandardvariants.Usersmaketheirchoiceonthedialogboxforsavingthedisplayvariant.
Default:SPACE.
IS_VARIANT
Variantinformation
Description
Thisstructureisonlyrelevantifdisplayvariantsaretobesavedand/orread.
Variantinformationincludingthenameofthelistvariantthatisusedtooutputthelist.
ToallowdisplayvariantstobereadwithintheALV,youmustspecifytheaccesspathusingfieldsREPORT(requiredfield),HANDLE(optionalfield)and/orLOG_GROUP(optionalfield).
Ifyoualsowanttoallowdisplayvariantstobesaved,youmustadditionallyfillparameterI_SAVEaccordingly.
SeealsothedocumentationonIMPORTINGparameterI_SAVE.
Avariantisuniquelydescribedthrough:
oTheprogramtowhichthevariantisassigned(REPORT)
oThehandle(HANDLE),if,forexample,multiplelistswithdifferentstructuresanddataarecalledinaprogram(I_CALLBACK_PROGRAM).
ThehandleisaCHAR(4)fieldthatmustbeuniquelydefinedanddescribestheassignmentofthecalltothecurrentstructureoftheinternaloutputtable.

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

23/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

Example:
Dependingontheuserinteraction,severaltypesoflistscanbeoutputinprogramx.
Theusershouldbeabletodefinedisplayvariantsforeachtypeoflist.
YouprovidethisfunctiontotheuserbyassigningaHANDLEtoeachlist.Ifvariantsfortheprogramandthehandlearesaved,thehandlemustnotbemodifiedanymore.
oThelogicalgroup,if,forexample,thesamelistiscreatedwithdifferentsettingsthroughvarioustransactions(LOG_GROUP).
ThelogicalgroupisaCHAR(4)thatmustbeuniquelydefinedandspecifiestheassignment.
Example:
ProgramxiscalledthroughtransactionsT1andT2.Dependingonthetransactioncode,thefieldsavailabletotheuserthroughthefieldcatalogdifferintheirassignmenttodifferentlogicalgroups.
Ifvariantsfortheprogramandthelogicalgrouparesaved,thelogicalgroupmustnotbemodifiedanymore.
oTheusername,ifuserspecificvariantsaresaved(USERNAME).
Youdonothavetofillthisparametermanuallysincethevariantnameisunique.
oThevariantname(VARIANT).
Youonlyhavetofillthisparameterifthisstructureistobeusedtoreadaconcretevariantandthelististobeoutputwiththisvariant.
ValueRange
Tocallalistwithavariant,youmustspecifytheabovefields.
Default
Ifthestructureisinitial,butsavingisactive(I_SAVEisnotinitial),thenIS_VARIANTREPORT=I_CALLBACK_PROGRAMisset.
Forapossibleentrieshelpforvariants,functionmoduleREUSE_ALV_VARIANT_F4isavailable.

Onlyrequiredifthelististobeoutputinadialogbox.

I_SCREEN_START_COLUMN
I_SCREEN_START_LINE
I_SCREEN_END_COLUMN
I_SCREEN_END_LINE

ExampleCode
WS_REPNAME=SYREPID.
CALLFUNCTION'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME=WS_REPNAME
I_INTERNAL_TABNAME=Internaloutputtablefieldname
I_INCLNAME=WS_REPNAME
CHANGING
CT_FIELDCAT=I_FIELDTAB.
IFSYSUBRC<>0.
WRITE:'SYSUBRC:',SYSUBRC,'REUSE_ALV_FIELDCATALOG_MERGE'.
ENDIF.
CALLFUNCTION'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM=WS_REPNAME
I_STRUCTURE_NAME=Internaloutputtablefieldname
IS_LAYOUT=I_LAYOUT
IT_FIELDCAT=I_FIELDTAB
I_DEFAULT='A'
I_SAVE='A'
IS_VARIANT='X'
IT_EVENTS=I_EVENTS[]
IT_SORT=I_SORT
IS_SEL_HIDE=I_SELINFO
TABLES
T_OUTTAB=Internaloutputtablefieldname.

IFSYSUBRC<>0.
WRITE:'SYSUBRC:',SYSUBRC,'REUSE_ALV_LIST_DISPLAY'.
ENDIF

Usingotherfunctionmodule'REUSE_ALV_GRID_DISPLAY'canhelpusgetlistoutputintheformofagridandalsoattachlogostothereportoutput.

Samplecode
1Simplelistoutput:
REPORTY_DEMO_ALVNOSTANDARDPAGEHEADING.
*Datatobedisplayed
DATA:I_SFLIGHTTYPETABLEOFSFLIGHT.
**
*Selection
SELECT*FROMSFLIGHTINTOTABLEI_SFLIGHT.
*CallABAPListViewer(ALV)
CALLFUNCTION'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_STRUCTURE_NAME='SFLIGHT'
TABLES

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

24/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

T_OUTTAB=I_SFLIGHT.
2.Simplegridoutput:
REPORTY_DEMO_ALV_1.
*
*Datatobedisplayed
DATA:I_SFLIGHTTYPETABLEOFSFLIGHT.
**
*Selection
SELECT*FROMSFLIGHTINTOTABLEI_SFLIGHT.
*CallABAPListViewer(ALV)
CALLFUNCTION'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_STRUCTURE_NAME='SFLIGHT'
TABLES
T_OUTTAB=I_SFLIGHT.
3.Demofor'REUSE_ALV_POPUP_TO_SELECT'
REPORTy_demo_alv_3.
TYPEPOOLS:slis.
DATA:BEGINOFi_outtabOCCURS0.
INCLUDESTRUCTUREsflight.
DATA:w_chkTYPEc."Formultipleselection
DATA:ENDOFi_outtab.
*I_OUTTABTYPESFLIGHTOCCURS0,
DATA:i_privateTYPEslis_data_caller_exit,
i_selfieldTYPEslis_selfield,
W_exit(1)TYPEc.
PARAMETERS:p_titleTYPEsytitle.
STARTOFSELECTION.
SELECT*FROMsflightINTOTABLEi_outtab.
CALLFUNCTION'REUSE_ALV_POPUP_TO_SELECT'
EXPORTING
i_title=p_title
i_selection='X'
i_zebra='X'
*I_SCREEN_START_COLUMN=0
*I_SCREEN_START_LINE=0
*I_SCREEN_END_COLUMN=0
*I_SCREEN_END_LINE=0
i_checkbox_fieldname='W_CHK'
*I_LINEMARK_FIELDNAME=
*I_SCROLL_TO_SEL_LINE='X'
i_tabname='I_OUTTAB'
i_structure_name='SFLIGHT'
*IT_FIELDCAT=
*IT_EXCLUDING=
*I_CALLBACK_PROGRAM=
*I_CALLBACK_USER_COMMAND=
*IS_PRIVATE=I_PRIVATE
IMPORTING
es_selfield=i_selfield
e_exit=w_exit
TABLES
t_outtab=i_outtab
EXCEPTIONS
program_error=1
OTHERS=2.
IFsysubrc<>0.
*MESSAGEi000(0k)WITHsysubrc.
ENDIF.
*****theinternaltableismodifiedwithacrosssignformarkingtherowsselected
LOOPATi_outtabWHEREw_chk='X'.
WRITE:/i_outtabcarrid,i_outtabprice.
ENDLOOP.

5.WholeSampleCode
REPORTYSUBALV.
*Declarationofvariables*
TYPEPOOLS:SLIS.
*TopassnameofthereportinfunctionmoduleforALV
DATA:V_REPIDLIKESYREPID.
*TopasstheoverallstructureoftheALVreport
DATA:STRUCT_LAYOUTTYPESLIS_LAYOUT_ALV.
DATA:STRUCT_LAYOUT1TYPESLIS_LAYOUT_ALV.
*InternaltabletocapturevariouseventsinALV
DATA:I_EVENTSTYPESLIS_T_EVENT.

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

25/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

*Tableforcatalogofthefieldstobedisplayed
DATA:I_FIELDCATTYPESLIS_T_FIELDCAT_ALV.
data:x_fieldcatTYPESLIS_FIELDCAT_ALV.
DATA:I_FIELDCAT1TYPESLIS_T_FIELDCAT_ALV.
data:x_fieldcat1TYPESLIS_FIELDCAT_ALV.
*Internaltabletomentionthesortsequence
DATA:IT_SORTTYPESLIS_T_SORTINFO_ALV.
DATA:X_SORTTYPESLIS_SORTINFO_ALV.
*Internaltabletodisplaytopofpage
data:i_list_top_of_pagetypeslis_t_listheader.
*Structuretodisplayvariants
data:i_variantlikedisvariant,
i_variant1likedisvariant.
*Internaltabletopassdata
DATA:BEGINOFI_TABOCCURS0,
mblnrlikemsegmblnr,
matnrlikemsegmatnr,
maktglikemaktmaktg,
charglikemsegcharg,
werkslikemsegwerks,
lgortlikemseglgort,
mengelikemsegmenge,
meinslikemsegmeins,
dmbtrlikemsegdmbtr,
ebelnlikemsegebeln,
icn(4)typec,
sym(4)typec,
excpt(2)typec,
box(1),
ENDOFI_TAB.
*EJECT
DATA:beginofi_dococcurs0.
INCLUDESTRUCTUREMSEG.
DATA:endofi_doc.
*EndofDataDeclaration*
PARAMETERS:P_VARLIKEDISVARIANTVARIANT.
initialization.
v_repid=syrepid.
*Displaydefaultvariant
PERFORMSUB_VARIANT_INIT.
ATSELECTIONSCREENONP_VAR.
*Oncetheuserhasenteredvariant,checkaboutitsexistence
PERFORMSUB_CHECK_PVAR.
ATSELECTIONSCREENONVALUEREQUESTFORP_VAR.
*DisplayalistofvariousvariantsofthereportwhentheuserpressesF4keyinthevariantfield
PERFORMSUB_VARIANT_F4.
STARTOFSELECTION.
*Preparefieldcatalogforthemainreport.Statethenameofthefield,nameofinternaltable,variousformattingoptionsetc
PERFORMSUB_PREPARE_FIELDCATALOG.
*Fetchesrecordsfromdatabaseintotablei_tabtobepassedasexport
*parametert_outtabinfunctionmodule:REUSE_ALV_GRID_DISPLAY
PERFORMSUB_SELECT_RECORD.
*Populatestatandiconcolumnsofinternaltablei_tabwithspecific
*columnsandsymbolsbasedonsomelogicforquantityandvaluefields.
PERFORMSUB_MODIFY_RECORDS.
*Definestheoveralllayoutofthereport
PERFORMSUB_DETERMINE_ALV_LAYOUT.
*Definesthesortsequenceofthereport
PERFORMSUB_DETERMINE_SORT_SEQUENCE.
*Definestheeventtable
PERFORMSUB_EVENTTAB_BUILDUSINGI_EVENTS.
*Thingstobewrittenatthetopofthepage
PERFORMSUB_COMMENT_BUILDUSINGi_list_top_of_page.
*DisplaytheALVlist
PERFORMSUB_SHOW_ALV_LIST.
*struct_layouthotspot_fieldname='X'.
ATLINESELECTION.
PERFORMSUB_HOTSPOT.
*&*
*&FormSUB_VARIANT_INIT
*&*
*Displaydefaultvariant
**
formSUB_VARIANT_INIT.
I_VARIANT1REPORT=SYREPID.
*Searchdefaultvariantforthereport
CALLFUNCTION'REUSE_ALV_VARIANT_DEFAULT_GET'

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

26/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

EXPORTING
i_save='A'
CHANGING
cs_variant=i_variant1
EXCEPTIONS
not_found=2.
*Ifdefaultvariantisfound,useitasdefault.
*Else,usethevariantLAYOUT1.
IFsysubrc=0.
p_var=i_variant1variant.
ELSE.
p_var='LAYOUT1'.
ENDIF.
endform."SUB_VARIANT_INIT
*&*
*&FormSUB_CHECK_PVAR
*&*
*Oncetheuserhasenteredvariant,checkaboutitsexistence
**
FORMSUB_CHECK_PVAR.
*Ifthenameofthevariableisnotblank,checkaboutitsexistence
ifnotp_varisinitial.
cleari_variant.
i_variantreport=syrepid.
i_variantvariant=p_var.
CALLFUNCTION'REUSE_ALV_VARIANT_EXISTENCE'
EXPORTING
I_SAVE='A'
CHANGING
CS_VARIANT=I_VARIANT.
*Ifnosuchvariantfound,flasherrormessage
ifsysubrcne0.
messagee398(00)with'Nosuchvariantexists'.
else.
*Ifvariantexists,usethevariantnametopopulatestructure
*I_VARIANT1whichwillbeusedforexportparameter:IS_VARIANT
*inthefunctionmodule:REUSE_ALV_GRID_DISPLAY
cleari_variant1.
movep_vartoi_variant1variant.
movesyrepidtoi_variant1report.
endif.
else.
cleari_variant.
endif.
ENDFORM."SUB_CHECK_PVAR
*&*
*&FormSUB_PREPARE_FIELDCATALOG
*&*
*Preparefieldcatalogforthemainreport.Statethenameof
*thefield,nameofinternaltable,variousformattingoptionsetc
**
formSUB_PREPARE_FIELDCATALOG.
*FirstfieldtoappearinALVlist
X_FIELDCATCOL_POS=1.
*Nameoftheinternaltablefield
X_FIELDCATFIELDNAME='SYM'.
*Nameoftheinternaltable
X_FIELDCATTABNAME='I_TAB'.
*Headingforthefield
X_FIELDCATSELTEXT_M='Stat'.
*Thefieldisgoingtocontainasymbol
x_fieldcatsymbol='X'.
*Appendthespecificationstotheinternaltableforfieldcatalog.
appendX_fieldcatTOI_FIELDCAT.
clearx_fieldcat.
*SecondfieldtoappearinALVlist
X_FIELDCATCOL_POS=2.
*Nameofthefieldintheinternaltable
X_FIELDCATFIELDNAME='MATNR'.
*Nameoftheinternaltable
X_FIELDCATTABNAME='I_TAB'.
*Headingforthecolumn
X_FIELDCATSELTEXT_M='MatItem'.
*Itisgoingtobethekeyfield.Thecolorforthisfieldisgoingto
*bedifferent
X_fieldcatkey='X'.
X_fieldcatkey_sel='X'.

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

27/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

*Singleclickonthefieldwilltriggerdoubleclickevent.Also,ahand
*willappearwhenthecursornavigatestothefield
X_fieldcathotspot='X'.
*Thecolumnandthoselefttoitwillnotscroll
X_fieldcatfix_column='X'.
*F1helpwillcomeasitisreferencedtoDDICtable
x_fieldcatref_tabname='MSEG'.
appendX_fieldcatTOI_FIELDCAT.
clearx_fieldcat.
X_FIELDCATCOL_POS=3.
X_FIELDCATFIELDNAME='MAKTG'.
X_FIELDCATTABNAME='I_TAB'.
X_FIELDCATSELTEXT_M='Description'.
*X_FIELDCATOUTPUTLEN=50.
x_fieldcathotspot=space.
*Thefieldiscentre(Cforcentre,RandLforleftand
*right)justified
x_fieldcatjust='C'.
x_fieldcatkey='X'.
x_fieldcatfix_column='X'.
*X_fieldcatno_out='X'.
X_fieldcatfix_column='X'.
appendX_fieldcatTOI_FIELDCAT.
clearx_fieldcat.
X_FIELDCATCOL_POS=4.
X_FIELDCATFIELDNAME='CHARG'.
X_FIELDCATTABNAME='I_TAB'.
X_FIELDCATSELTEXT_M='Batch'.
*X_FIELDCATOUTPUTLEN=10.
x_fieldcathotspot=space.
appendX_fieldcatTOI_FIELDCAT.
clearx_fieldcat.
X_FIELDCATCOL_POS=5.
X_FIELDCATFIELDNAME='EBELN'.
X_FIELDCATTABNAME='I_TAB'.
X_FIELDCATSELTEXT_M='PurchaseOrder'.
*X_FIELDCATOUTPUTLEN=14.
*Thefieldwillbecoloreddifferently(Cxyz)
x_fieldcatemphasize='C511'.
*Initiallythefieldwillbehidden
x_fieldcatno_out='X'.
appendX_fieldcatTOI_FIELDCAT.
clearx_fieldcat.
X_FIELDCATCOL_POS=6.
X_FIELDCATFIELDNAME='MBLNR'.
X_FIELDCATTABNAME='I_TAB'.
X_FIELDCATSELTEXT_M='Documentno'.
*X_FIELDCATOUTPUTLEN=14.
x_fieldcatemphasize='C711'.
x_fieldcatno_out='X'.
appendX_fieldcatTOI_FIELDCAT.
clearx_fieldcat.
X_FIELDCATCOL_POS=7.
X_FIELDCATFIELDNAME='WERKS'.
X_FIELDCATTABNAME='I_TAB'.
X_FIELDCATSELTEXT_M='Plant'.
*X_FIELDCATOUTPUTLEN=5.
x_fieldcatemphasize='C310'.
appendX_fieldcatTOI_FIELDCAT.
clearx_fieldcat.
X_FIELDCATCOL_POS=8.
X_FIELDCATFIELDNAME='LGORT'.
X_FIELDCATTABNAME='I_TAB'.
X_FIELDCATSELTEXT_M='St.Loc'.
*X_FIELDCATOUTPUTLEN=7.
*X_fieldcatno_out='X'.
appendX_fieldcatTOI_FIELDCAT.
clearx_fieldcat.
X_FIELDCATCOL_POS=9.
X_FIELDCATFIELDNAME='MENGE'.
X_FIELDCATTABNAME='I_TAB'.
X_FIELDCATSELTEXT_M='Quantity'.
X_FIELDCATOUTPUTLEN=12.
*Summationisallowedforthisfield
x_fieldcatdo_sum='X'.
X_FIELDCATref_tabname='MSEG'.
appendX_fieldcatTOI_FIELDCAT.

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

28/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

clearx_fieldcat.
X_FIELDCATCOL_POS=10.
X_FIELDCATFIELDNAME='ICN'.
X_FIELDCATTABNAME='I_TAB'.
X_FIELDCATSELTEXT_M=''.
X_FIELDCATOUTPUTLEN=2.
x_fieldcaticon='X'.
*X_fieldcatno_out='X'.
appendX_fieldcatTOI_FIELDCAT.
clearx_fieldcat.
X_FIELDCATCOL_POS=11.
X_FIELDCATFIELDNAME='MEINS'.
X_FIELDCATTABNAME='I_TAB'.
X_FIELDCATSELTEXT_M='Unit'.
X_FIELDCATOUTPUTLEN=5.
x_fieldcatqfieldname='MEINS'.
appendX_fieldcatTOI_FIELDCAT.
clearx_fieldcat.
X_FIELDCATCOL_POS=12.
X_FIELDCATFIELDNAME='DMBTR'.
X_FIELDCATTABNAME='I_TAB'.
X_FIELDCATSELTEXT_M='Localcurr'.
X_FIELDCATOUTPUTLEN=12.
x_fieldcatINTTYPE='P'.
x_fieldcatjust='R'.
x_fieldcatdo_sum='X'.
appendX_fieldcatTOI_FIELDCAT.
clearx_fieldcat.
X_FIELDCATCOL_POS=13.
X_FIELDCATFIELDNAME='EXCPT'.
X_FIELDCATTABNAME='I_TAB'.
X_FIELDCATSELTEXT_M=''.
X_FIELDCATOUTPUTLEN=3.
appendX_fieldcatTOI_FIELDCAT.
clearx_fieldcat.
endform."SUB_PREPARE_FIELDCATALOG
*&*
*&FormSUB_SELECT_RECORD
*&*
*Fetchesrecordsfromdatabaseintotablei_tabtobepassedasexport
*parametert_outtabinfunctionmodule:REUSE_ALV_GRID_DISPLAY
**
formSUB_SELECT_RECORD.
SELECTmblnrA~matnrA~maktgcharg
werkslgortmengemeinsdmbtrebeln
FROMmaktasajoinmsegasb
on(a~matnr=b~matnr)
INTOTABLEI_TAB
whereb~bwart='101'.
endform."SUB_SELECT_RECORD
*&*
*&FormSUB_MODIFY_RECORDS
*&*
*Populatestatandiconcolumnsofinternaltablei_tabwithspecific
*columnsandsymbolsbasedonsomelogicforquantityandvaluefields.
**
formSUB_MODIFY_RECORDS.
loopati_tab.
ifi_tabdmbtrgt10000.
*Fieldicnofinternaltableisgoingtocontainicon.Forthiscolumn
*icon_allowedissetinthefieldcatalogtable.Forvariousicons,see
*typepool<ICON>
i_tabicn=''.
modifyi_tabtransportingicn.
endif.
ifi_tabmengegt50.
*Fieldicnofinternaltableisgoingtocontainsymbol.Forthis
*columnsymbol_allowedissetinthefieldcatalogtable.Forvarious
*icons,seetypepool<SYMBOL>
i_tabsym='N'.
modifyi_tabtransportingsym.
endif.
IFI_TABWERKSNE'SDC1'.
*Thisfieldwillcontainlights,trafficsignals:red.yellow,green
*Thatthisfieldwillbeusedasalightwillbespecifiedinthe
*columnofstructureSTRUCT_LAYOUT.
I_TABEXCPT='1'.

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

29/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

MODIFYI_TABTRANSPORTINGEXCPT.
endif.
endloop.
endform."SUB_MODIFY_RECORDS
*&*
*&FormSUB_DETERMINE_ALV_LAYOUT*
*&*
*&Definestheoverallstructureofthereportlayout*
**
formSUB_DETERMINE_ALV_LAYOUT.
*FieldEXCPTwillshowthelightsignal
STRUCT_LAYOUTLIGHTS_FIELDNAME='EXCPT'.
*FieldBOSoftheinternaltablewillactaspushbuttonandwillappear
*attheleftofthegriddisplay.Userwillpressthattoselecta
*record
struct_layoutbox_fieldname='BOX'.
STRUCT_layouttotals_text='Totqty'.
STRUCT_LAYOUTZEBRA='X'.
struct_layoutconfirmation_prompt='X'.
struct_layoutdetail_titlebar='DetailsofStoring'.
struct_layoutno_sumchoice='X'.
struct_layouttotals_only='X'.
endform."SUB_DETERMINE_ALV_LAYOUT
*&*
*&FormSUB_DETERMINE_SORT_SEQUENCE
*&*
*Definesthesortsequenceofthereport
**
formSUB_DETERMINE_SORT_SEQUENCE.
X_sortspos=1."Sortorder
X_sortfieldname='MATNR'.
X_sorttabname='I_TAB'.
X_sortup='X'.
X_sortsubtot='X'."Subtotalallowed
appendX_sortTOIT_SORT.
clearX_sort.
endform."SUB_DETERMINE_SORT_SEQUENCE

*&*
*&FormSUB_SHOW_ALV_LIST
*&*
*ShowsALVlistingridform
**
formSUB_SHOW_ALV_LIST.
CALLFUNCTION'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM=V_REPID"*Nameoftheprogram
I_GRID_TITLE='DetailsofStoring'"*title
I_callback_pf_status_set='PF_STATUS_SET'"*callssubroutine:PF_STATUS_SET
i_callback_user_command='USER_COMMAND'"*Callssubroutine:user_command
IS_LAYOUT=STRUCT_LAYOUT"*Overallstructureofthereport
IT_FIELDCAT=I_FIELDCAT"*Passesthefieldcatginternaltable
IT_SORT=IT_SORT"*Passesthesortsequenceinternaltable
I_DEFAULT='X'
I_SAVE='A'
IS_VARIANT=i_variant1
*fetchesdifferenteventsintointernaltablei_events
it_events=i_events[]
TABLES
*PassesdatatableforALVdisplay
T_OUTTAB=I_TAB
EXCEPTIONS
PROGRAM_ERROR=1
OTHERS=2.
IFSYSUBRC<>0.
*MESSAGEIDSYMSGIDTYPESYMSGTYNUMBERSYMSGNO
*WITHSYMSGV1SYMSGV2SYMSGV3SYMSGV4.
ENDIF.
endform."SUB_SHOW_ALV_LIST
*&*
*&Formset_status
*&*
*FormusedtosettheCustompfstatusoftheListDisplay
**
*rt_extab:
**
FORMpf_status_setUSINGi_rt_extabTYPEslis_t_extab.

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

30/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

data:x_extabtypeslis_extab.
x_extabfcode='&LFO'.
appendx_extabtoi_rt_extab.
*PfstatusSTANDARDofprogramSAPLSALViscopiedtoZSTANDARDofthe
*currentprogramandthepushbuttonforInformation(okcode=&LFO)is
*excluded
SETPFSTATUS'ZSTANDARD'excludingi_rt_extab.
ENDFORM.

*&*
*&Formuser_command
*&*
*FormusedtohandleUSER_COMMANDevents
**
*rf_ucomm:FunctionCode
*rs:InternalTablecontainingtheselectioninformation.
**
FORMuser_commandUSINGrf_ucommLIKEsyucomm
rsTYPEslis_selfield.
data:v_mblnrlikemsegmblnr.
caserf_ucomm.
*AcustompushbuttonforrecorddeletionissetintheGUIstatus.Whenarecordisselected,thefieldBOCforthat*recordbecomes'X'.
*Therecordsaretracedanddeletedandthefieldsarerefreshed(rsoftypeslis_selfieldisrefreshed)
when'&DEL'."Printbuttonclicked.
deletei_tabwherebox='X'.
rsrefresh='X'.
*WhentheuserselectsarowandpressestheSelectpushbutton(userdefined)fromtheapplicationtoolbar,thedetails*ofthedocumentwillbeshowninanotherALVlist
when'&SEL'.
PERFORMSUB_SELECT_DOCUMENT.
*setparameterid'MBN'fieldi_tabmblnr.
*calltransaction'MB03'.
*Okcodefordoubleclickis&IC1forALVreport
when'&IC1'.
performsub_hotspot.
endcase.
ENDFORM.
*&*
*&FormSUB_HOTSPOT
*&*
*text
**
*>p1text
*<p2text
**
formSUB_HOTSPOT.
messagei398(00)with'Hello'.
endform."SUB_HOTSPOT

*&*
*&FormSUB_VARIANT_F4
*&*
*DisplayalistofvariousvariantsofthereportwhentheuserpressesF4keyinthevariantfield
**
formSUB_VARIANT_F4.
i_variantreport=syrepid.
*Utilisingthenameofthereport,thisfunctionmodulewillsearchforalistofvariantsandwillfetchtheselectedone*intotheparameterfieldforvariants
CALLFUNCTION'REUSE_ALV_VARIANT_F4'
EXPORTING
IS_VARIANT=I_VARIANT
I_SAVE='A'
I_DISPLAY_VIA_GRID='X'
IMPORTING
ES_VARIANT=I_VARIANT1
EXCEPTIONS
NOT_FOUND=1
PROGRAM_ERROR=2
OTHERS=3.
IFSYSUBRC=0.
P_VAR=I_VARIANT1VARIANT.
ENDIF.
ENDFORM."SUB_VARIANT_F4
*&*
*&FormSUB_SELECT_DOCUMENT
*&*
formSUB_SELECT_DOCUMENT.
data:v_linestypei.
readtablei_tabwithkeybox='X'.

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

31/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

Select*frommsegINTOTABLEI_DOCWHEREMBLNR=I_TABMBLNR.
IFSYSUBRCEQ0.
CALLFUNCTION'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME=V_REPID
I_INTERNAL_TABNAME='I_DOC'
I_STRUCTURE_NAME='MSEG'
CHANGING
CT_FIELDCAT=I_FIELDCAT1
EXCEPTIONS
INCONSISTENT_INTERFACE=1
PROGRAM_ERROR=2
OTHERS=3.
IFSYSUBRC<>0.
MESSAGEIDSYMSGIDTYPESYMSGTYNUMBERSYMSGNO
WITHSYMSGV1SYMSGV2SYMSGV3SYMSGV4.
ENDIF.
clearstruct_layout1.
STRUCT_layout1colwidth_optimize='X'.
refreshit_sort.
clearit_sort.

CALLFUNCTION'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM=V_REPID
I_GRID_TITLE='DetailsofDocument'
IS_LAYOUT=STRUCT_LAYOUT1
IT_FIELDCAT=I_FIELDCAT1
i_structure_name='MSEG'
I_DEFAULT='X'
I_SAVE='A'
TABLES
T_OUTTAB=I_DOC
EXCEPTIONS
PROGRAM_ERROR=1
OTHERS=2
.
IFSYSUBRC<>0.
MESSAGEIDSYMSGIDTYPESYMSGTYNUMBERSYMSGNO
WITHSYMSGV1SYMSGV2SYMSGV3SYMSGV4.
ENDIF.
ENDIF.
endform."SUB_SELECT_DOCUMENT
*&*
*&FormSUB_COMMENT_BUILD
*&*
formSUB_COMMENT_BUILDusingI_top_of_pageTYPEslis_t_listheader.
DATA:ls_lineTYPEslis_listheader.
***Header
CLEARls_line.
ls_linetyp='H'.
*LS_LINEKEY:notusedforthistype
ls_lineinfo='Headinglist'.
APPENDls_lineTOI_top_of_page.
***Selection
CLEARls_line.
ls_linetyp='S'.
ls_linekey='Key1'.
ls_lineinfo='Material'.
APPENDls_lineTOi_top_of_page.
ls_linekey='Key2'.
ls_lineinfo='Documentno'.
APPENDls_lineTOI_top_of_page.
***Action
CLEARls_line.
endform."SUB_COMMENT_BUILD

*&*
*&FormSUB_EVENTTAB_BUILD
*&*
*Definestheeventtable
*&*
FORMsub_eventtab_buildUSINGl_eventsTYPEslis_t_event.
DATA:ls_eventTYPEslis_alv_event.
*GetthedifferenteventsoftheALV
CALLFUNCTION'REUSE_ALV_EVENTS_GET'

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

32/33

10/5/2015

ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

EXPORTING
i_list_type=0
IMPORTING
et_events=l_events.
*Searchthetopofpageevents
READTABLEl_eventsWITHKEYname=slis_ev_top_of_pageINTOls_event.
IFsysubrc=0.
MOVE'TOP_OF_PAGE'TOls_eventform.
APPENDls_eventTOl_events.
ENDIF.
endform."SUB_EVENTTAB_BUILD
*&*
*FORMTOP_OF_PAGE*
*&*
*WhenTOPOFPAGEwillbefired,thiseventwillbecalledandit
*willusethecontentsofi_list_top_of_pageforoutputintheheader
*&*
FORMtop_of_page.
CALLFUNCTION'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
i_logo='ENJOYSAP_LOGO'
it_list_commentary=i_list_top_of_page.
ENDFORM.

OR
gothroughthislinkforreferenceguideshttp://www.esnips.com/_t_/alv?q=alv**\\
Regards
fareedas

Nolabels

2Comments
NAVEENMANDA

nicedocument

sriramulakishore
Thatwasawsomeman
Veryniceeffort
kudos

ContactUs
Privacy

SAPHelpPortal
TermsofUse

LegalDisclosure

Copyright

http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES

FollowSCN

33/33

Potrebbero piacerti anche