33
10/5/2015 ALV TUTOTIAL FOR BEGINERS WITH EXAMPLES ABAP Development SCN Wiki http://wiki.scn.sap.com/wiki/display/ABAP/ALV+TUTOTIAL+FOR+BEGINERS+WITH+EXAMPLES 1/33 Getting Started Newsletters Store Search the Community Welcome, Guest Login Register Products Services & Support About SCN Downloads Industries Training & Education Partnership Developer Center Lines of Business University Alliances Events & Webinars Innovation Added by Fareeda Tabassum S, last edited by Fareeda Tabassum S on Apr 15, 2008 ABAP Development / ABAP Development ALV TUTOTIAL FOR BEGINERS WITH EXAMPLES Author: fareedas Date: 15/04/2008 Introduction This is a discussion on ALV reportinga step by step operation manual about creating an ALV report of medium complexity. This documentation will not make you an expert in ALV. But, definitely, it will come handy at the time of need. It refers an example report YSUBALV, as a reference and will represent relevant blocks of the code at different areas of discussion. Contents ALV (ABAP LIST VIEWER) Step 1: DATA DECLARATION Example: Step 2: Selecting the variants(Optional) Step 3: (Defining Output Characteristics) Step 4: (Build up events table) Step 5: (Report Output list description) Step 6: (Pass Selectionscreen Information) Step 7: (Deciding Sort Criteria) Step 8: (Final Step) Step 9: (Display Internal Output Table) Sample code. Description:Sap provides a set of ALV (ABAP LIST VIEWER) function modules, which can be put into use to embellish the output of a report. This set of ALV functions is used to enhance the readability and functionality of any report output. Cases arise in sap when the output of a report contains columns extending more than 255 characters in length. In such cases, this set of ALV functions can help choose selected columns and arrange the different columns from a report output and also save different variants for report display. This is a very efficient tool for dynamically sorting and arranging the columns from a report output. The report output can contain up to 90 columns in the display with the wide array of display options. The commonly used ALV functions used for this purpose are; 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 The different steps used for getting the above function modules into use are described below. Step 1: DATA DECLARATION Sap standard type pools: SLIS, KKBLO. Sap standard tables types taken from the type pools are: SLIS_LAYOUT_ALV, SLIS_T_FIELDCAT_ALV SLIS_T_LISTHEADER, SLIS_T_EVENT, SLIS_SELFIELD. Internal tables to be used in the program declared based on the above table types DATA: I_LAYOUT TYPE SLIS_LAYOUT_ALV,

Alv Tutotial for Beginers With Examples - Abap Development - Scn Wiki

Tags:

Embed Size (px)

DESCRIPTION

Uso de ALV para principiantes con ejemplos

Citation preview

  • 10/5/2015 ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

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

    GettingStarted Newsletters Store

    SearchtheCommunity

    Welcome,Guest Login Register

    Products Services&Support AboutSCN Downloads

    Industries Training&Education Partnership DeveloperCenter

    LinesofBusiness UniversityAlliances Events&Webinars Innovation

    AddedbyFareedaTabassumS,lasteditedbyFareedaTabassumSonApr15,2008

    ABAPDevelopment / ABAPDevelopment

    ALVTUTOTIALFORBEGINERSWITHEXAMPLES

    Author:fareedas

    Date:15/04/2008IntroductionThisisadiscussiononALVreportingastepbystepoperationmanualaboutcreatinganALVreportofmediumcomplexity.ThisdocumentationwillnotmakeyouanexpertinALV.But,definitely,itwillcomehandyatthetimeofneed.ItrefersanexamplereportYSUBALV,asareferenceandwillrepresentrelevantblocksofthecodeatdifferentareasofdiscussion.ContentsALV(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.ThissetofALVfunctionsisusedtoenhancethereadabilityandfunctionalityofanyreportoutput.Casesariseinsapwhentheoutputofareportcontainscolumnsextendingmorethan255charactersinlength.Insuchcases,thissetofALVfunctionscanhelpchooseselectedcolumnsandarrangethedifferentcolumnsfromareportoutputandalsosavedifferentvariantsforreportdisplay.Thisisaveryefficienttoolfordynamicallysortingandarrangingthecolumnsfromareportoutput.Thereportoutputcancontainupto90columnsinthedisplaywiththewidearrayofdisplayoptions.ThecommonlyusedALVfunctionsusedforthispurposeare1.REUSE_ALV_VARIANT_DEFAULT_GET2.REUSE_ALV_VARIANT_F43.REUSE_ALV_VARIANT_EXISTENCE4.REUSE_ALV_EVENTS_GET5.REUSE_ALV_COMMENTARY_WRITE6.REUSE_ALV_FIELDCATALOG_MERGE7.REUSE_ALV_LIST_DISPLAY8.REUSE_ALV_GRID_DISPLAY9.REUSE_ALV_POPUP_TO_SELECTThedifferentstepsusedforgettingtheabovefunctionmodulesintousearedescribedbelow.

    Step1:DATADECLARATIONSapstandardtypepools:SLIS,KKBLO.Sapstandardtablestypestakenfromthetypepoolsare:SLIS_LAYOUT_ALV,SLIS_T_FIELDCAT_ALVSLIS_T_LISTHEADER,SLIS_T_EVENT,SLIS_SELFIELD.InternaltablestobeusedintheprogramdeclaredbasedontheabovetabletypesDATA:I_LAYOUTTYPESLIS_LAYOUT_ALV,

  • 10/5/2015 ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

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

    I_FIELDTABTYPESLIS_T_FIELDCAT_ALV,I_HEADINGTYPESLIS_T_LISTHEADER,I_EVENTSTYPESLIS_T_EVENT.TYPES:KKBLO_SELFIELDTYPESLIS_SELFIELD.

    Example:REPORTYSUBALV.*Declarationofvariables*TYPEPOOLS:SLIS.*TopassnameofthereportinfunctionmoduleforALVData:V_REPIDLIKESYREPID.*TopasstheoverallstructureoftheALVreportData:STRUCT_LAYOUTTYPESLIS_LAYOUT_ALV.Data:STRUCT_LAYOUT1TYPESLIS_LAYOUT_ALV.*InternaltabletocapturevariouseventsinALVData:I_EVENTSTYPESLIS_T_EVENT.*TableforcatalogofthefieldstobedisplayedData:I_FIELDCATTYPESLIS_T_FIELDCAT_ALV.Data:X_FIELDCATTYPESLIS_FIELDCAT_ALV.Data:I_FIELDCAT1TYPESLIS_T_FIELDCAT_ALV.Data:X_FIELDCAT1TYPESLIS_FIELDCAT_ALV.*InternaltabletomentionthesortsequenceData:IT_SORTTYPESLIS_T_SORTINFO_ALV.Data:X_SORTTYPESLIS_SORTINFO_ALV.*InternaltabletodisplaytopofpageData:i_list_top_of_pagetypeslis_t_listheader.*StructuretodisplayvariantsData:i_variantlikedisvariant,I_variant1likedisvariant.*InternaltabletopassdataDATA: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.*EJECTData: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'EXPORTINGi_save=variantsavecondition(A=all,U=userspecific)CHANGINGcs_variant=internaltablecontainingtheprogramname(andthedefaultvariantoptional)EXCEPTIONSnot_found=2.

    Theusercanalsochoosefromthelistofexistingvariantsusingthefunctionmodule'REUSE_ALV_VARIANT_F4'.Example:Initialization.v_repid=syrepid.*DisplaydefaultvariantPERFORMSUB_VARIANT_INIT.ATSELECTIONSCREENONP_VAR.*Oncetheuserhasenteredvariant,checkaboutitsexistence

  • 10/5/2015 ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

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

    PERFORMSUB_CHECK_PVAR.ATSELECTIONSCREENONVALUEREQUESTFORP_VAR.*DisplayalistofvariousvariantsofthereportwhentheUserpressesF4keyinthevariantfieldPERFORMSUB_VARIANT_F4.*&**&FormSUB_VARIANT_INIT*&**Displaydefaultvariant*&*FormSUB_VARIANT_INIT.I_VARIANT1REPORT=SYREPID.*SearchdefaultvariantforthereportCALLFUNCTION'REUSE_ALV_VARIANT_DEFAULT_GET'EXPORTINGi_save='A'CHANGINGcs_variant=i_variant1EXCEPTIONSnot_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,checkaboutitsexistenceifnotp_varisinitial.cleari_variant.i_variantreport=syrepid.i_variantvariant=p_var.CALLFUNCTION'REUSE_ALV_VARIANT_EXISTENCE'EXPORTINGI_SAVE='A'CHANGINGCS_VARIANT=I_VARIANT.*Ifnosuchvariantfound,flasherrormessageIfsysubrcne0.Messagee398(00)with'Nosuchvariantexists'.Else.*Ifvariantexists,usethevariantnametopopulatestructure*I_VARIANT1whichwillbeusedforexportparameter:IS_VARIANT*inthefunctionmodule:REUSE_ALV_GRID_DISPLAYCleari_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*variantsandwillfetchtheselectedoneintotheparameterfieldforvariantsCALLFUNCTION'REUSE_ALV_VARIANT_F4'EXPORTINGIS_VARIANT=I_VARIANTI_SAVE='A'I_DISPLAY_VIA_GRID='X'IMPORTINGES_VARIANT=I_VARIANT1EXCEPTIONSNOT_FOUND=1

  • 10/5/2015 ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

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

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

    Step3(DefiningOutputCharacteristics)

    DEFINININGOUTPUTCHARACTERISTICS:PREPARINGDISPLAYFIELDSCATALOG

    Afieldcatalogispreparedusingtheinternaltable(I_FIELDCAT)oftypeSLIS_T_FIELDCAT_ALV.Fieldcatalogcontainingdescriptionsofthelistoutputfields(usuallyasubsetoftheinternaloutputtablefields).AfieldcatalogisrequiredforeveryALVlistoutputtoadddesiredfunctionality(i.e.Key,Hotspot,Specificheadings,Justify,Col.positionetc)tocertainfieldsoftheoutput.Ifnotmentionedspecifically,thenthedefaultsaretaken.Thepossiblevaluesanddefaultsarelistedbelow.Thefieldcatalogfortheoutputtableisbuiltupinthecaller'scoding.ThebuildupcanbecompletelyorpartiallyautomatedbycallingtheREUSE_ALV_FIELDCATALOG_MERGEmodule.Theminimalfieldcatalogisdocumentedbelow.Thiscanbedoneinaroutineusingalocalvariable.Theusercanusetheotheroptionalparameterstoassignoutputattributestodifferentfieldsintheoutput,whichdifferfromthedefault.Afieldcatalogneednotbebuiltupandpassedexplicitlyonlyunderthefollowingconditions:1.TheinternaltabletobeoutputhasthesamestructureasaDataDictionarystructurewhichisreferredtointheinternaltabledeclarationusingLIKEorINCLUDESTRUCTURE.Inthiscasetheattributesofthedifferentfieldsistakendirectlyfromthetableandtheattributes(keyfields,length,textsetc)needtostateexplicitly.2.Allfieldsinthisstructurearetobeoutput3.ThestructurenameispassedtoALVintheparameterI_STRUCTURE_NAMEofthefunctionmoduleREUSE_ALV_LIST_DISPLAY.AllthevaluesenteredinthecatalogarespecifictotheparticularfieldwhosenameisenteredinthefieldnameFIELDNAMEofthefieldcatstructure.Thenameofthetableisalsoenteredinthecorr.FieldnameTABNAMEofthestructure.

    Thedifferentpossibleattributesare:Row_pos(rowposition):Onlyrelevantifthelistoutputistobemultiline(twoorthreelines)bydefault.So,thisattributecanbeusedmaintaincertainlevelofalignmentintheoutput.Valueset:0,13Col_pos(columnposition):Thisparameterisrelevantwhenthefieldsintheoutputaretobedifferentfromthesequenceofthefieldsintheinternaltableusedfordisplay.Theparameterspecifiestherelativecolumnpositionofthefieldinthelistoutput.Thecolumnordercanbechangedinteractivelybytheuser.Ifthisparameterisinitialforallfieldcatalogentries,columnsappearintheinternaltablefieldsequence.Valueset:0,160Fieldname(fieldname):Thisisthenameoftheinternaltablefieldforwhichtheparametersarepassedinthecatalog.Valueset:internaloutputtablefieldname(requiredparameter)Tabname(internaloutputtable):NameoftheinternaloutputtablethatcontainsthefieldFIELDCATFIELDNAMEabove.Valueset:SPACE,internaloutputtablename.Ref_fieldname(referencefieldname):NameoftheDataDictionaryfieldreferredto.ThisparameterisonlyusedwhentheinternaloutputtablefielddescribedbythecurrentfieldcatalogentryhasareferencetotheDataDictionary(notaprogramfield),andthefieldnameintheinternaloutputtableisdifferentfromthenameofthefieldintheDataDictionary.Ifthefieldnamesareidentical,namingtheDataDictionarystructureortableintheFIELDCATREF_TABNAMEparameterissufficient.Valueset:SPACE,DataDictionaryfieldname.Ref_tabname(referencetable/structurefieldname):StructureortablenameofthereferredDataDictionaryfield.ThisparameterisonlyusedwhentheinternaloutputtablefielddescribedbythecurrentfieldcatalogentryhasaDataDictionaryreference(notaprogramfield).Valueset:SPACE,nameofaDataDictionarystructureortable

    Linktocurrencyunit

    Cfieldname(currencyunitfieldname):Thisisusedforcurrencyfieldsthathaveareferencetoanyunitfield.Thisisonlyrelevantforamountcolumnswithassociatedunit.ThisparametercontainstheNameoftheinternaloutputtablefieldcontainingthecurrencyunitassociatedwiththeamountfieldFIELDCATFIELDNAME.ThefieldinFIELDCATCFIELDNAMEmusthaveitsownfieldcatalogentry.Valueset:SPACE,outputtablefieldname.Ctabname(internalcurrencyunitfieldoutputtable):NameoftheinternaloutputtablecontainingtheFIELDCATCFIELDNAMEfield.Valueset:SPACE,outputtablefieldname.LinktomeasurementunitQfieldname(measurementunitfieldname):Onlyrelevantforquantitycolumnswithunitlink.NameoftheinternaloutputtablefieldcontainingthemeasurementunitassociatedwiththequantityfieldFIELDCATFIELDNAME.ThefieldinFIELDCATQFIELDNAMEmusthaveitsownfieldcatalogentry.Valueset:SPACE,outputtablefieldname.Qtabname(internalmeasurementunitfieldoutputtable):NameoftheinternaloutputtablecontainingtheFIELDCATQFIELDNAMEfield.Valueset:SPACE,outputtablefieldname.Outputlen(columnwidth):Thisparameterisusedifthedesiredoutputlengthforafieldisdesiredtobedifferentfromtheinternaloutputtablefield.ForfieldswithaDataDictionarylinkthisparametercanbeleftinitial.ForfieldswithoutaDataDictionarylink(programfield)theparametermustbegiventhevalueofthedesiredfieldlistoutputlength(columnwidth).Initial=columnwidthistheoutputlengthofthereferredDataDictionaryfield(domain).N=columnwidthisncharacters.Valueset:0(initial),n.Key(keycolumn):Bydefault,thesystemmakessomefieldsintheoutputaskeyfields,providedthefieldsarekeyfieldsintheirreferencingtable.Usingthisparameter,fieldsotherthankeyfieldsofthereferencingtablecanbemadekeyfield.Thisparameterismostimportantiftheoutputneedstocontainsomefield,whicharenotscrollableorcannotbehidden.Iftheinternaloutputtablecontainsfieldsthatarekeyfieldsfromdifferenttables,thenallthosefieldsinthereportoutputbecomesunscrollableandcannotbehidden.So,thefieldsintheoutputinternaltableshouldnotbereferencedfromtablesinwhichtheyarekeyfields.Instead,theyshouldbereferencedtothetablesinwhichtheyarenotkeyfields,incasetheyarenotdesiredaskeyfieldintheoutput.'X'=keyfield(keyfieldoutputincolor)andKeyfieldscannotbeinteractivelyhidden.ParameterFIELDCATNO_OUTmustbeleftinitial.

  • 10/5/2015 ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

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

    Valueset:SPACE,'X'.Key_sel(hideablekeycolumn):ThisparameterisonlyrelevantforthefieldswhicharemadekeyfieldsusingFIELDCATKEY='X'.UsingthisparametertheKeyfieldcanbehiddeninteractively.Thekeycolumnsequencecannotbechangedinteractivelybytheuser.TheoutputiscontrolledbytheFIELDCATNO_OUTparameteranalogouslytononkeyfields.Valueset:SPACE,'X'.No_out(fieldinfieldlist):Thisparameterisusedtoremovecertainfieldsfromtheoutputduringinitialdisplay.Theusercanhoweverinteractivelychoosethefieldforoutputfromthefieldlistinthedisplayvariant.'X'=fieldisnotdisplayedinthecurrentlist.Valueset:SPACE,'X'.Tech(technicalfield):Thisparameterisusedtomakecertainfielddisplayonlyinthefieldcatalog.Thefieldswiththisparametersetcannotbeoutputinthelistnorcantheybedisplayedinteractivelyfromthecatalog.'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:colornumberY:boldZ:inverseHotspot(columnashotspot):Thisparameterisusedtomakecertainfieldappearashotspoti.e.ahandisdisplayedifthecursorispositionedonthefieldvalue.SingleclickonsuchfieldscausethePICKORF2eventstohappen.Valueset:SPACE,'X'.'X'=columncellsareoutputashotspots.Fix_column(fixcolumn):Thisparameterisusedtofixcertaincolumnsintheoutput.Allcolumnstobefixedmusthavethisflag,startingfromtheleft.Ifacolumnwithoutthisflagisoutput,onlythecolumnstotheleftofthiscolumnarefixed.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.Thejustificationofthecolumnheaderalwaysfollowsthejustificationofthecolumns.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.Ifthisisnotdesired,thetextparameterscanalsobespecified.TheDataDictionarytextsarethenignored.Iftheuserchangesthecolumnwidthinteractively,thecolumnheadertextwiththeappropriatelengthisalwaysused.Theinteractivefunction'Optimizecolumnwidth'takesaccountofboththefieldcontentsandthecolumnheaders:ifallfieldcontentsareshorterthantheshortestcolumnheader,thecolumnwidthdependsonthecolumnheader.The'longfieldlabel'isalsousedindisplayvariantdefinition,Sort,etc.Popup.seltext_l(longfieldlabel)seltext_m(mediumfieldlabel)seltext_s(shortfieldlabel)reptext_ddic(header)AnalogoustotheDataelementmainheaderDdictxt(specifytext):Youcanspecifywithvalues'L','M',and'S',thekeywordthatshouldalwaysbeusedascolumnheader.Ifthecolumnwidthchanges,noattemptismadeinthiscasetofindanappropriateheaderforthenewoutputwidth.Valueset:SPACE,'L','M',and'S'.Samplecode:*&**&FormSUB_PREPARE_FIELDCATALOG

  • 10/5/2015 ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

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

    *&**Preparefieldcatalogforthemainreport.Statethenameofthefield,nameofinternaltable,variousformattingoptionsetc**FormSUB_PREPARE_FIELDCATALOG.X_FIELDCATCOL_POS=1.*FirstfieldtoappearinALVlistX_FIELDCATFIELDNAME='SYM'.*NameoftheinternaltablefieldX_FIELDCATTABNAME='I_TAB'.*NameoftheinternaltableX_FIELDCATSELTEXT_M='Stat'.*HeadingforthefieldX_FIELDCATSYMBOL='X'.*Thefieldisgoingtocontainasymbol*Appendthespecificationstotheinternaltableforfieldcatalog.APPENDX_FIELDCATTOI_FIELDCAT.CLEARX_FIELDCAT.X_FIELDCATCOL_POS=2.*SecondfieldtoappearinALVlistX_FIELDCATFIELDNAME='MATNR'.*NameofthefieldintheinternaltableX_FIELDCATTABNAME='I_TAB'.*NameoftheinternaltableX_FIELDCATSELTEXT_M='MatItem'.*Headingforthecolumn*Itisgoingtobethekeyfield.ThecolorforthisfieldisgoingtobedifferentX_FIELDCATKEY='X'.X_FIELDCATKEY_SEL='X'.*Singleclickonthefieldwilltriggerdoubleclickevent.Also,ahandwillappearwhenthecursornavigatestothefieldX_FIELDCATHOTSPOT='X'.X_FIELDCATFIX_COLUMN='X'.*ThecolumnandthoselefttoitwillnotscrollX_FIELDCATREF_TABNAME='MSEG'.*F1helpwillcomeasitisreferencedtoDDICtableAPPENDX_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)justifiedX_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'.*InitiallythefieldwillbehiddenAPPENDX_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.

  • 10/5/2015 ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

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

    *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'.*SummationisallowedforthisfieldX_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.Thereturntablefromthisfunctionmodulecontainsallthepossibleevents.

    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)foraheaderrecordthatwasexpandedinteractivelybytheuser.2.Slis_ev_reprep_sel_modifyTYPEslis_formnameVALUE'REPREP_SEL_MODIFY'.RS_SELFIELDTABINDEXcontainstheheadertableindexforwhichtheitementriesaretobeputintheglobalitemoutputtable(T_OUTTAB_SLAVE).TheCallbackisonlycalledifALVhasnoitemsforaheaderthatistobeexpanded.

    RFLG_ALLispassedwith'X'iftheusershowsallitems.Theapplicationmustensurethatentriesarenotrepeatedintheitemtable.

    RS_SELFIELDisinitialinthiscase.3.Slis_ev_caller_exit_at_startTYPEslis_formnameVALUE'CALLER_EXIT'.

  • 10/5/2015 ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

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

    Iscalledatthebeginningofthefunctionmoduletomakespecialsettings.Itisnotusuallyused.4.Slis_ev_user_commandTYPEslis_formnameVALUE'USER_COMMAND'.AsthisisafrequentlyusedCallbackevent,theformroutinecanalsobepasseddirectlyintheinterfacebypassingtheusercommandintheIMPORTINGparameterI_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)onaseparatepagebydefault7.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,processesabranchlistwhichwasnotformattedbyALV(e.g.apopupwithadditionalinformationaboutthelistrecordselectedanddisplayedbyALV).

    Inthiscase,topofpagecannotbeformattedbyALVanalogouslytothebasiclist,itmustbehandledcompletelybythecaller.TheeventtopofpagestilloccursinALV.WhenALVnoticesatopofpagewhichwasnotcausedbyanALVoutput,theformroutineinFOREIGN_TOP_OF_PAGEiscalled.9.Slis_ev_foreign_end_of_pageTYPEslis_formnameVALUE'FOREIGN_END_OF_PAGE'.TheeventendofpageisalwaysprocessedinALVandonlypassedtothecallerviacallback.Thisisstillthecase,e.g.whenthecallerprocessesadetailslistwhichwasnotformattedbyALV(e.g.apopupwithfurtherinformationaboutselectedlistrecordswhichweredisplayedbyALV).Inthiscase,endofpagecannotbeformattedbyALVanalogouslytothebasiclist,itmustbehandledcompletelybythecaller.TheeventendofpagestilloccursinALV.WhenALVnoticesanendofpagethatwasnotcausedbyanALVoutput,theformroutineinFOREIGN_END_OF_PAGEiscalled.10.Slis_ev_pf_status_setTYPEslis_formnameVALUE'PF_STATUS_SET'.Ifauserliststatusistobeset,itmustbedoneintheformroutineassignedtothisevent.TheALVfunctioncodes,whichmustnotbeactive,areintheParameterRT_EXTAB.ThistablemustbepassedwiththeSETPFSTATUScommand(withinactiveuserfunctioncodesaswell,ifnecessary).

    TheSTANDARDstatusofthefunctiongroupSALVshouldbeusedasatemplateforauserspecificstatus.AsthisisafrequentlyusedCallbackevent,itsformroutinecanalsobepasseddirectlyintheinterfaceintheIMPORTINGparameterI_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'.Informationoutputattheendofthelist15.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,thenthecorrespondingfieldfortheFORMNAMEispopulatedwiththenameoftheroutinecontainingthecorrespondingevent.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'EXPORTINGI_LIST_TYPE=0IMPORTINGET_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.headeretcUsingthefunctionmodule'REUSE_ALV_COMMENTARY_WRITE',theinternaltablecontainingtheheadingsfortopofpageeventcanbepassedtothelistoutput.Also,anylogospecifictothereportcanbepassedtothefunctionmodule.2.FORMEND_OF_PAGE:Thisformwillcontaintheendofpageeventforthereporti.e.footeretc3.FORMUSER_COMMAND:Thisformwillcontainthedesiredusercommandi.e.pick/lineselection

    Step5(ReportOutputlistdescription)

  • 10/5/2015 ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

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

    AlayoutisbuildforthereportoutputlistdescriptionUSINGtheinternaltabledeclaredabove(I_LAYOUT).Outputlistdescriptionstructure.Theparametersaredescribedunderthefollowingheads:DisplayoptionsExceptionsTotalsInteractionDetailscreenDisplayvariants(onlyforhierarchicalsequentiallists)ColorOtherThelayouttableisoftypeslis_layout_alv_specandhasthefollowingfields:Displayoptions1.Colwidth_optimize(1)TYPEc:Thisparameteroptimizesthelengthofthedifferentcolumnsintheoutput.Thewidthofthedifferentcol.nowdependsonthemax.Lengthofthedatainthecolumn.Valueset:SPACE,'X''X'=optimizesthecolumnwidthsothatallcontentsaredisplayedcompletely.2.No_colhead(1)TYPEc:ThisparametersuppressesthecolumnheadingsValueset:SPACE,'X'.'X'=columnheadersarenotoutput3*.No_hotspot*(1)TYPEc:Theheadingsofthereportoutputarenotoutputashotspot.Valueset:SPACE,'X'.'X'=columnheadersarenotoutputashotspot4*.Zebra*(1)TYPEc:Thereportisoutputinthestripedpattern.Valueset:SPACE,'X'.'X'=stripedpattern(e.g.forwidelists)5.No_vline(1)TYPEc:Thereportoutputcontainscolumnsonlyseparatedbyspaceandnolines.Itisnotrelevantfor:hierarchicalsequentiallistsandmultiplelinelists.Valueset:SPACE,'X'.'X'=columnsseparatedbySPACE6.No_min_linesize(1)TYPEc:Thereportlinesizeisequaltothewidthofthelist.Itisnotrelevantforblocklists.Valueset:SPACE,'X'.'X'=linesizedependsonlistwidth''=Linesizeissetto80orMIN_LINESIZE(if>0).7.Min_linesizeLIKEsylinsz:Thereportoutputcontainsaminimumpossiblelengthofline.Ifinitialmin_linesizeissetto80bydefault,thenthisparameterisusedtocustomizeit.Theprerequisiteforthisisthattheparameterno_min_linesizeshouldbe''.Valueset:0,10250Ifthelistiswider,theformatusesthelistwidth(maximum250orMAX_LINESIZE(if>0)).8.Max_linesizeLIKEsylinsz:Thedefaultmax.Linesizeis250.Tochangethisdefaultvalue,thisparametercaninteractivelydefinethemaximumlistwidthsetting.Valueset:0,8010209.Window_titlebarLIKErsmpetittext:Tosetthetitlebaronthereportoutput.10.No_uline_hs(1)TYPEc.Exceptions11.Lights_fieldnameTYPEslis_fieldname:Internaloutputtablefieldcontainingthecodesofexceptionstobeoutput.Outputtablefieldcode:'1'=redtrafficlight'2'=yellowtrafficlight'3'=greentrafficlightFieldnameforexceptionValueset:SPACE,internaloutputtablefieldname.12.Lights_tabnameTYPEslis_tabname:NameoftheinternaloutputtablethatcontainsthefieldintheparameterLIGHTS_FIELDNAME.IfLIGHTS_FIELDNAMEisnotempty,thisfieldmustalsobefilledforhierarchicalsequentiallists.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.Sums15*.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:NosubtotalspossibleValueset:SPACE,'X''X'=nosubtotals.19*.Numc_sum*(1)TYPEc:TotalsonlypossibleforNUMCFields.20.No_unit_splittingTYPEc:Noseparatetotallinesbyinh.units21.totals_before_itemsTYPEc:Displaytotalsbeforetheitems22.Totals_only(1)TYPEc:ShowonlytotalsValueset:SPACE,'X''X'=onlytotalrecordsareoutput.

  • 10/5/2015 ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

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

    23.Totals_text(60)TYPEc:Textfor1stcol.intotalsValueset:SPACE,string(max.60)''=Thefirstcolumninthetotalrecordcontainsanappropriatenumberof'*'stoindicatethetotalbydefault.Ifthefirstcolumniswideenough,thestring'Total'isoutputaftertheasterisks.'String'=Thestringpassedisoutputafterthetotalindicatedby'*',ifthecolumniswideenough.24.Subtotals_text(60)TYPEc:TextsforsubtotalsValueset:SPACE,string(max.60)''=Inthefirstcolumnofsubtotalrecords,thesubtotalisindicatedbyanappropriatenumberof'*'bydefault.Ifthefirstcolumnisnotasubtotalcriterion,thestring'Total'isoutputaftertheasterisks,ifthecolumniswideenough.'String'=thestringpassedisoutputafterthesubtotalindicatedby'*',ifthecolumniswideenoughandthefirstcolumnisnotasubtotalcriterion.Ifitisasubtotalcriterion,itsvalueisrepeatedafterthetotal,ifthecolumniswideenough.Interaction25.Box_fieldnameTYPEslis_fieldname:Fieldnameforcheckboxinthereportoutput.Ifthelisthascheckboxesatthestartofrecords(forselectingseveralrecords),thisparametercontainstheinternaloutputtablefieldnameindicatedbythecheckboxselectioncolumn.Thefieldisacheckboxatthestartoflistrecordswithoutalistheader.Valueset:SPACE,internaloutputtablefieldname26.Box_tabnameTYPEslis_tabname:NameoftheinternaloutputtablethatcontainsthefieldintheparameterBOX_FIELDNAME.IfBOX_FIELDNAMEisnotempty,thisfieldmustalsobefilledforhierarchicalsequentiallists.Valueset:SPACE,internaloutputtablename.27.Box_rollnameLIKEdd03prollname:rollnameforcheckbox28.Expand_fieldnameTYPEslis_fieldname:fieldnameflag'expand'.Theusercanshoworhidetheitemsbyclickingonthefoldersymbol(hotspot).IftheitemsforaheaderentryareonlytobereadbythecallingprogramandpassedtoALVwhenaheaderhasbeenexpandedinteractively,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,functioncode32.Confirmation_prompt:confirm.PromptwhenleavingValueset: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,andpassthegroupnametothelistmoduleintheinterfaceparameterIT_SPECIAL_GROUPS.Valueset:SPACE,'X'.36.No_keyfix(1)TYPEc:Usedtomakethekeyfieldsscrollable.Valueset:SPACE,'X'.''=ThekeycolumnsdefinedinthefieldcatalogbyFIELDCATKEY='X'arefixedinthelistoutput.Thesecolumnsdonotscrollhorizontally.Theitemtablekeycolumnsarefixedinhierarchicalsequentiallists.Theheadertablekeyfieldsarenotconsideredhere.'X'=keycolumnsnotfixed37.Get_selinfos(1)TYPEc:Toreadselectionscreen.Valueset:SPACE,'X'.IfthecallingprogramisareportwithanABAP/4selectionscreen,settingthisparametermakesALVreadtheselectionscreenagain.Iftheselectionsarereadsuccessfully,apushbutton,viawhichtheusercancallapopupwhichliststhereportselectionsinasimpleform,becomesactiveontheresultslistoutputbyALV.38.group_change_edit(1)TYPEc:SettingsbyuserfornewgroupValueset:SPACE,'X''X'=theusercanenteraformatoptionforeachsortcriterioninthesort/subtotalpopup,forthelistformatwhenthisvaluechanges(e.g.newpageorunderline).39.No_scrolling(1)TYPEc:Doesnotallowscrollingofthelisttotheright.Valueset:SPACE,'X'.40.Expand_all(1)TYPEc:ExpandallpositionsDetailedscreen40.Detail_popup(1)TYPEc:showdetailinpopup.Valueset:SPACE,'X'''=Listrecorddetaildisplayinfullscreenmode,withtopofpage.'X'=listrecorddetaildisplayinpopup(withouttopofpage).41.Detail_initial_lines(1)TYPEc:showalsoinitiallinesValueset:SPACE,'X'''=Onlyfieldswhosecontentsarenotinitialareoutputinthedetailview.'X'=initialfieldcontentsarealsooutputindetail.41.detail_titlebar(30)typec:TitlebarfordetailscreenValueset:SPACE,string(max.30)''='Detail:Display'isoutputasthetitleofthedetailwindow.'String'=thestringpassedisoutputasthetitleofthedetailwindow.Displayvariants42.Header_text(20)TYPEc:Textforheaderbutton.Onlyrelevantforhierarchicalsequentiallists.Youcantogglebetweendisplayfieldandfieldlistviewsviapushbuttonsinthedisplayvariantdefinitionpopupforhierarchicalsequentiallists.Theviewsrefertothehierarchylevelofthefields.Thisistechnicallyatogglebetweentheheadertableanditemtablefields.Valueset:SPACE,CHAR(20)''=Theheadertablefieldpushbuttontextis'Header'bydefault.CHAR(20)=headertablefieldpushbuttontext.43.item_text(20)TYPEc:Textforitembutton.Onlyrelevantforhierarchicalsequentiallists.Youcantoggletheviewbetweenthedisplayfieldsandthefieldlistviapushbuttonsinthedisplayvariantdefinitionpopupforhierarchicalsequentiallists.Theviewsrefertothehierarchylevelofthefields.Thisistechnicallyatogglebetweentheheadertableanditemtablefields.Valueset:SPACE,CHAR(20)

  • 10/5/2015 ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

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

    ''=Thepushbuttontextfortheitemtablefieldsis'Item'bydefault.CHAR(20)=itemtablefieldpushbuttontext.44.default_item(1)TYPEc:Itemsasdefault.Onlyrelevantforhierarchicalsequentiallists.Valueset:SPACE,'X'''=Theheadertablefieldsaredisplayedbydefaultinthedisplayvariantdefinitionpopup.Theusercanswitchtotheitemtablefieldsinteractively.'X'=theitemtablefieldsaredisplayedbydefaultinthedisplayvariantDefinitionPopup.Theusercanswitchtotheheadertablefieldsinteractively.Colour45.Info_fieldnameTYPEslis_fieldname:infofieldforlistoutput.Awholelistrecordcanbecoloredindividuallyusingacolorcodeinacolumnoftheinternaloutputtablefortherecord.Assignthenameofthefieldcontainingthecolorcodetothisparameter.Valueset:SPACE,internaloutputtablefieldnameTheinternaloutputtablefieldmustbeoftypeCHAR(3).Thecodemusthavethefollowingsyntax:'Cxy':C=color(allcodesmuststartwith'C')X=colornumber('1''9')Y=bold('0'=off,'1'=on)46.Coltab_fieldnameTYPEslis_fieldname:Cellscanbecoloredindividuallyusingacolorcodewhichiscontainedinacolumnoftheinternaloutputtablefortherecordcontainingthecell.Assignthenameofthefieldtothisparameter.Others47.List_append(1)TYPEc:nocallscreen.Itisonlyusefultooutputblocklistswithoutspecifyingtheabovemodulesifthenumberoflistblocksexceeds,ormayexceed,themaximumnumberspecifiedintheblockmoduledocumentation.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:Selectioninfotablevt_entriesmode:'A'=outputtheselectioninfoforthecurrenttablerecordintheinfopopup.

    'D'=donotoutputselectoptionorSELNAMEparameterselectioninfointhepopup.vt_entriesselname:(onlyusedint_entriesmode='D'):Nameoftheselectoptionorparameter.Thefollowingtablefieldsareonlyusedint_entriesmode='A'.Theycontaintheselectioninformationtobeadded.

    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.

  • 10/5/2015 ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

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

    Step7(DecidingSortCriteria)TheTableIT_SORTispopulatedwiththesortcriteriaforthedifferentfields.Thecallerspecifiesthesortingand/orsubtotalingofthebasiclistintheinternaltableIT_SORT.Thisinternaltablehasthefollowingfields:spos:Sortsequencefieldname:Internaloutputtablefieldnametabname:Onlyrelevantforhierarchicalsequentiallists.Nameoftheinternaloutputtable.up:'X'=sortinascendingorderdown:'X'=sortindescendingordersubtot:'X'=subtotalatgroupvaluechangegroup:'*'=newpageatgroupvaluechange,'UL'=underlineatgroupvaluechange

    Step8(FinalStep)ThefinalstepintheoutputofthereportistheuseoftwoALVfunctionsmodules.1.REUSE_ALV_FIELDCATALOG_MERGE2.REUSE_ALV_LIST_DISPLAYThefirstfunctionmoduleisusedtopassthefieldcatalogtothereportoutputandmergeitwiththeinternaloutputtable.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:FieldcatalogwithfielddescriptionsThevariantbasedonaprograminternaltableshouldonlybeusedforrapidprototypingsincethefollowingrestrictionsapply:

    1.Performanceisaffectedsincethecodeofthetabledefinitionmustalwaysbereadandinterpretedatruntime.

  • 10/5/2015 ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

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

    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

  • 10/5/2015 ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

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

    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_DISPLAYThefunctionmoduleoutputsaninternaltablewithwhateverstructureintheformofaformattedsingleormultilinelist.Process:Passinganinternaltablewiththesetofinformationtobeoutput

    Passingastructurewithgenerallayoutspecificationsforlistlayout

    PassingafieldcatalogintheformofaninternaltableThefieldcatalogdescribesthefieldstobeoutputinthelist.

    NotesvAllinteractionsperformedonthelistreferdirectlytotheinternaloutputtable.Sortingthelist,forexample,alsoinvolvesaresortingoftheinternaloutputtablepassed(sinceitwaspassedbyreference).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

  • 10/5/2015 ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

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

    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:NameofthecallingprogramProgramfromwhichthefunctionmoduleiscalledandthatcontainstheexitroutines.Theprogramshouldalwaysbeareport,functiongroup,modulepoolorformroutinepool(itshouldnotbeaninclude).Caution:NeverpassSYREPIDdirectlyattheinterface.IffieldSYREPIDcontainsthedesiredprogramname,youmustabsolutelyassignthisnametoanauxiliaryvariableandpassthisvariabletotheinterface.

    I_CALLBACK_PF_STATUS_SET:SetEXITruntimetostatus

    PassinganEXITroutineindicatestotheALVthatthecallerwantstosetaselfdefineduserstatus.Asaresult,thedefaultstatusoftheALVisnotset.Theinterfaceoftheformroutinespecifiedmustbedefinedasfollows:FORMset_pf_statusUSINGrt_extabTYPEslis_t_extabTableRT_EXTABcontainsthefunctioncodesthatwouldbehiddenonthestandarduserinterface.Ifthecallerwantstouseaselfdefineduserinterface(forexample,inordertoprovideadditionallistfunctionsoruseexistingfunctions),werecommendthatyoucopystandardstatusSTANDARDfromfunctiongroupSALVandmodifyitaccordingly.ALVstandardfunctioncodesalwaysstartwith'&'.SeealsothedocumentationonparameterI_CALLBACK_USER_COMMAND.Ifaselfdefineduserinterfaceisusedthatincludesfunctioncodesofthestandarduserinterface,thefunctioncodesoftheexcludingtablepassedshouldbetakenintoaccount.Thismeansthattheuserstatusshouldgenerallybesetasfollows:

    SETPFSTATUSuserstatusEXCLUDINGrt_extab.

    Applicationfunctionscanbeaddedtoexcludingtablert_extabiftheyaretobedisabled.

    TheroutineiscalledwheneverthestandarduserinterfacewouldbesetwithSETPFSTATUS.

    Default

    IfnoEXITroutineisspecified,theALVsetsastatusthatcorrespondstostatusSTANDARDoffunctiongroupSALV.

    I_CALLBACK_USER_COMMAND:EXITroutineforcommandhandling

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

  • 10/5/2015 ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

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

    StructureRS_SELFIELDcontainsthefollowinginformation:

    otabname:Nameoftheinternaloutputtableotabindex:Indexoftheinternaloutputtableofieldname:Fieldnameoendsum:Cursorislocatedonthetotalslineosumindex:If>0,thecursorislocatedonasubtotalslineovalue:Valueofthefieldonthelistorefresh:(Exporting)Listshouldbesetupagainocol_stable:(Exporting)Keepcolumnpositionwhenlistissetupagainorow_stable:(Exporting)Keeprowpositionwhenlistissetupagainoexit:(Exporting)Exitlist(andALV)obefore_action:Callbeforestandardactionexecutionoafter_action:Callafterstandardactionexecution,beforelistsetupoignore_multi:Internaluseosel_tab_field:InternaluseTheEXITroutineiscalledwheneverafunctionunknowntotheALVistriggeredoriftheroutinecallbefore/aftertheexecutionofastandardfunctioncodehasbeendefinedbyinterfaceparameter

    IT_EVENT_EXIT.SeealsothedocumentationonparameterIT_EVENT_EXIT.ThefunctioncodeandthecurrentcursorpositionarethenpassedontothecallingprogramthroughtheEXITroutine.Iftheuserhasselectedmultiplerowsbyselectingcheckboxes,theoutputtablefielddesignatedasthecheckboxcontainsthecurrentstateofthecheckboxinthelist.I_CALLBACK_TOP_OF_PAGEEXITroutineforhandlingTOPOFPAGEDescriptionIfthecallerspecifiesanEXITroutine,thisroutinemusthavethefollowingform:FORMtop_of_page.ModuleREUSE_ALV_COMMENTARY_WRITEcanthenbecalledwithintheEXITroutine.ThismoduleisresponsibleforformattingtheheaderinformationandalsoensuresonlineHTMLformatting.Intheprintprevieworinbatchmode,thetextpassedisthenoutputinthenormalformat.IfmoduleREUSE_ALV_COMMENTARY_WRITEcannotbeused,youmustusetwoparametersinstead.InI_CALLBACK_TOP_OF_PAGEyoupasstheformroutinethatisresponsiblefornormalformattinginbatchmodeorintheprintpreviewmode.Theformroutinethatisresponsibleforonlineformatting,ispassedinparameterI_CALLBACK_HTML_TOP_OF_PAGE.Ifoneoftheseparametersisnotfilled,topofpageisnotoutputintherespectivemode.

    I_CALLBACK_HTML_TOP_OF_PAGE

    EXITroutineforHTMLTOPOFPAGEDescriptionIffunctionmoduleREUSE_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_LISTEXITroutineforHTMLENDOFLISTDescriptionInthisparameter,youcanpassaformfortheonlinehandlingofendoflist.Theformmusthavethefollowiongformat:

    FormEnd_of_ListusingCl_ddtypereftocl_dd_document.I_STRUCTURE_NAMEInternaloutputtablestructurenameDescriptionIftheinternaloutputtableisdefinedthroughanABAPDictionarystructure(INCLUDESTRUCTUREstructorLIKEstruct),youcanautomaticallysetupthefieldcatalogbypassingthestructurename.Thefieldcatalogistheninternallysetupforthisstructureasfollows:oAllfieldsareonthelist(NO_OUT=SPACE)exceptfieldsofdatatypeCLNT.oThekeyfieldsoftheDictionarystructureareadoptedinthefieldcatalogaskeyfields.oReferencestounitfieldsstoredintheDictionaryareadoptedprovidedthatthereferencefieldsarecontainedinthestructure.oIfyouadditionallypassafieldcatalogasparameter,thestructureinformationismergedwiththisfieldcatalog.Formoreinformationonhowtosetupthefieldcatalogautomatically,seethedocumentationonfunctionmoduleREUSE_ALV_FIELDCATALOG_MERGE.I_GRID_TITLEControltitleDescription:Specifiesthetitleofthecontrol.Thistextisdisplayedabovethegrid.I_GRID_SETTINGSGridsettingsDescriptionIfTopofPageorEndofListareoutputonline,theseareasaredisplayedinasplitteraboveorbelowthelist.UsingI_GRID_SETTINGSyoucanreducethedefaultsizeto0%.Todothis,youusetwofields:COLL_TOP_P:SetsTopofPageto0%COLL_END_L:SetsEndofListto0%IS_LAYOUTListlayoutspecifications

  • 10/5/2015 ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

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

    DescriptionStructurefordescribingthelisttobeoutput.Theparametersaredescribedandgroupedbasedonthefollowing

    categories:

    DisplayoptionsExceptionsTotalsInteractionDetailscreenColorOtherNotethesectiononpredefinedsettings.Displayoptionscolwidth_optimizeValuerange:SPACE,'X'X'=Optimizesthecolumnwidthtoensurethatthecontentisdisplayedcompletely.no_colheadValuerange:SPACE,'X''X'=Donotoutputcolumnheadings.zebraValuerange:SPACE,'X''X'=Stripedpattern(forwidelists,forexample)no_vlineValuerange:SPACE,'X''X'=SeparatecolumnsbySPACE.

    Exceptionslights_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

  • 10/5/2015 ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

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

    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.Ifthecolumnwidthisnotsufficient,onlytheasterisksaredisplayed.'string'=Afterthetotalslevelindicatedvisuallybymeansof'*',thesystemdisplaysthestringpassedprovidedthatthecolumnwidthissufficientandthecharacteristicofthefirstcolumnisnotasubtotalcriterion.Ifthecharacteristicisasubtotalcriterion,thesystemrepeatsthecharacteristicvalueforwhichsubtotalswerecalculatedafterthetotalslevelprovidedthatthecolumnwidthissufficient.

    numc_sum

    Valuerange:SPACE,'X'

    ''=Inthestandardsystem,itisnotpossibletocalculatetotalsforNUMCfields.

    'X'=ItisgenerallypossibletocalculatetotalsforNUMCfields.Ifthisindicatorisset,youcanuseparameterFIELDCATNO_SUMtocontrolforeachNUMCcolumnwhethertotalscanbecalculatedornot.Interactionbox_fieldname

    Valuerange:SPACE,fieldnameoftheinternaloutputtable.Ifthelistshouldhavecheckboxesatthebeginningofeachlistrow(toallowtheusertoselectmultiplerowsatonce),youmustfillthisparameterwiththefieldnameoftheinternaloutputtablethatrepresentstheselectioncolumnforselectingrowswiththehelpofcheckboxes.Thefieldisalwaysdisplayedasacheckboxatthebeginningofeachlistrowwithoutalistheading.

    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)triggersthefunctionassignedtoF2.

    reprep

    Valuerange:SPACE,'X'

    'X'=Enablereport/reportinterface

    Prerequisite:Applicationsystem(=>reportRKKBRSTIexists).

    Thelistmoduleactsasapotentialsenderinthereport/reportinterface(interfaceinitialization,ifrequired).Thecallingreport/modulepoolenteredinI_CALLBACK_PROGRAMisdeclaredtothereport/reportinterfaceasthesenderreportwithtypeRT=Report.IfthesenderreportisassignedtoreceiverreportsintableTRSTI,functioncodeBEBxissettoactive.(x=functioncodeclass)Example:

    IfsenderRKTFGS15hasareceiverassignmentforReportWriterreportgroup7KOIwithfunctioncodeclass'3'(SAPsetting),thisreceiverreportgroupiscalledthroughthereport/reportinterface

    atfunctioncode'BEB3'.Theselectionspassedtothereport/reportinterfacearethereportselectionsandthekeyinformationoftheselectedrow.Formoreinformationonthereport/reportinterface,seethedocumentationonfunctiongroup'RSTI'.Detailscreen

    detail_initial_lines

  • 10/5/2015 ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

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

    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.Youmustassignthefieldnameofthefieldwiththecolorcodetothisparameter.ThefieldoftheinternaloutputtablemustbeoftypeSLIS_T_SPECIALCOL_ALV.

    Principle:Thefieldforthecolorcodeisfilledintherowinwhichthecellstobecoloredarelocated.Thefieldthencontainsaninternaltableoftheabovestructurethatincludesthefieldnamesofthecellstobecoloredwiththecolorcode.Thecellcoordinatesarethereforederivedfromtherowpositioninwhichthecolorcodeiswrittenandthecolumninformationcontainedinthecolortable.TherowstructureoftheinternalcolortableoftypeSLIS_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.DefaultInmanycases,thedefaultlayoutsettingscanbekeptsothatyoufrequentlydonotneedtopassthisstructurewithmodifiedflags.IT_FIELDCAT

    FieldcatalogwithfielddescriptionsDescriptionFieldcatalogcontainingthefielddescriptionsofthefieldstobeconsideredforthelistoutput(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.Positioningcol_pos(columnposition)Valuerange:0,160Onlyrelevantiftherelativecolumnpositionsshouldbydefaultnotbeidenticaltothesequenceofthefieldsinthefieldcatalog.Theparameterdeterminestherelativecolumnpositionofthefieldinthelistoutput.Thecolumnsequencecaninteractivelybechangedbytheuser.Ifthisparameterissettoitsinitialvalueforeachfieldcatalogentry,thecolumnsarearrangedintheorderofthefieldsinthefieldcatalog.Identificationfieldname(fieldname)

    Valuerange:Fieldnameoftheinternaloutputtable(requiredparameter)

  • 10/5/2015 ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

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

    Fieldnameofthefieldintheinternaloutputtablethatisdescribedbythisfieldcatalogentry.ReferencetotheDataDictionaryref_fieldname(fieldnameofthereferencefield)Valuerange:SPACE,nameofafieldintheDataDictionaryNameofthereferencedfieldintheDataDictionary.ThisparameterisonlyrequiredifthefieldintheinternaloutputtablethatisdescribedbythecurrententryinthefieldcataloghasareferencetotheDataDictionary(thatis,isnotaprogramfield)andifthefieldnameintheinternaloutputtableisnotidenticaltothefieldnameofthefieldintheDataDictionary.Ifbothfieldnamesareidentical,itissufficienttospecifytheDataDictionarystructureortableinparameterFIELDCATREF_TABNAME.ref_tabname(fieldnameofthereferencetable/structure)Valuerange:SPACE,nameofastructureortableintheDataDictionaryStructureortablenameofthereferencedfieldintheDataDictionary.ThisparameterisonlyrequiredifthefieldintheinternaloutputtablethatisdescribedbythecurrententryinthefieldcataloghasareferencetotheDataDictionary(thatis,isnotaprogramfield).Referencetofieldswithcurrencyunits/unitsofmeasureEachamountorquantityfieldoftheinternaloutputtablewhosedecimalplacesaretobedisplayedwiththeproperunitinthelistoutput,mustcomplywiththefollowingconventions:ThefieldisofdatatypeQUANorCURR(internaltypeP).(Physically,thefieldmustactuallybelongtothisdatatype.OverridingthephysicaldatatypewithparameterFIELDCATDATATYPEhasnoeffect.)Thereisonefieldintheinternaloutputtablethatcontainstherelevantunit.Thereisalsoanentryfortheunitfieldinthefieldcatalog.(Iftheunitshouldnotbedisplayedasacolumninthelistandtheusershouldnotbeabletoshowtheunitinteractively,forexample,becausetheunitisalwaysuniqueandthereforeexplicitlyoutputbythecallerinthelistheader,thenyoucanassignparameterFIELDCATTECH='X'tothefieldcatalogentryfortheunitfield.Ifavaluefieldhasareferencetoaunit,thishasthefollowingeffectswhenthelistisoutput:Thedecimalplacesaredisplayedwiththeproperunit.Aninitialvaluefieldwithreferencetoanoninitialunitisdisplayedas'0'(providedthatFIELDCATNO_ZEROisinitial).Ifunitspecifictotalsarecalculatedforthisvaluefield,theunitisconsideredintheanalysisofwhetherhomogeneousunitsexist.AninitialvaluefieldwithreferencetoaninitialunitisdisplayedasSPACE.Ifunitspecifictotalsarecalculatedforthisvaluefield,theunitSPACEhasnoeffectonthehomogeneityoftheunitifthevaluefieldisinitial.Fornoninitialvaluefieldswithinitialunit,theunitSPACEisconsideredasaunitwhenunitspecifictotalsarecalculated.Referencetothecurrencyunitcfieldname(fieldnameofthecurrencyunitfield)Valuerange:SPACE,nameofafieldoftheoutputtableOnlyrelevanttoamountcolumnswithunitreference.FieldnameofthefieldintheinternaloutputtablethatcontainsthecurrencyunitfortheamountfieldFIELDCATFIELDNAME.TheremustbeaseparatefieldcatalogentryforthefieldspecifiedinFIELDCATCFIELDNAME.Referencetotheunitofmeasureqfieldname(fieldnameoftheunitofmeasurefield)Valuerange:SPACE,nameofafieldoftheoutputtableOnlyrelevanttoquantitycolumnswithunitreference.FieldnameofthefieldintheinternaloutputtablethatcontainstheunitofmeasurefortheamountfieldFIELDCATFIELDNAME.TheremustbeaseparatefieldcatalogentryforthefieldspecifiedinFIELDCATQFIELDNAME.Outputoptionsforacolumnoutputlen(columnwidth)Valuerange:0(initial),nForfieldswithreferencetotheDataDictionaryyoucanleavethisparametersettoinitial.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'=TechnicalfieldThefieldcannotbeoutputonthelistandcannotbeshowninteractivelybytheuser.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:Colornumbery:Intensifiedz:Inversehotspot(columnashotspot)Valuerange:SPACE,'X''X'=Thecellsofthecolumnareoutputasahotspot.

  • 10/5/2015 ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

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

    do_sum(calculatetotalsforcolumn)Valuerange:SPACE,'X''X'=Totalsarecalculatedforthisfieldoftheinternaloutputtable.Thisfunctioncanalsobeusedinteractivelybytheuser.no_sum(totalscalculationnotallowed)Valuerange:SPACE,'X''X'=Nototalsmaybecalculatedforthisfieldalthoughthedatatypeofthefieldallowstotalling.Formattingcolumncontentsicon(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'=CenteredoutputThejustificationofthecolumnheaderdependsonthejustificationofthecolumncontents.Youcannotjustifythecolumnheaderindependentlyofthecolumncontents.lzero(leadingzeros)Valuerange:SPACE,'X'OnlyrelevanttofieldsofdatatypeNUMCBydefault,NUMCfieldsareoutputintheALVrightjustifiedwithoutleadingzeros.'X'=Outputwithleadingzerosno_sign(no+/sign)Valuerange:SPACE,'X'Onlyrelevanttovaluefields'X'=Valueoutputwithout+/signs.no_zero(suppresszeros)Valuerange:SPACE,'X'Onlyrelevanttovaluefields'X'=Supresszerosedit_mask(fieldformatting)Valuerange:SPACE,maskmask=SeedocumentationontheWRITEformattingoptionUSINGEDITMASKmaskUsingmask='==conv'youcanforceanoutputconversionconv.TextsThefollowingparametersfortextsarealwaysrequiredforprogramfieldswithoutreferencetotheDataDictionary.ForfieldswithreferencetotheDataDictionary,thetextsareretrievedfromtheDataDictionary.Ifyoudonotwantthis,youcanfillthetextparametersalsoforfieldswithreferencetotheDataDictionary.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,thesystemtriestofindaheadingthatfitsthenewoutputwidth.ParameterforprogramfieldswithoutreferencetotheDataDictionarySeealsotheparameterinthe'Texts'section.datatype(datatype)Valuerange:SPACE,datatypefromtheDataDictionary(CHAR,NUMC,...)OnlyrelevanttofieldswithoutreferencetotheDataDictionary.Datatypeofprogramfieldddic_outputlen(externaloutputlength)Valuerange:0(initial),nOnlyrelevanttofieldswithoutreferencetotheDataDictionarywhoseoutputshouldneverthelessbemodifiedusingaconversionexit.Prerequisites:FIELDCATEDIT_MASK='==conv'SeealsothedocumentationonparameterFIELDCATEDIT_MASKFIELDCATINTLEN=nSeedocumentationonparameterFIELDCATINTLENn=Fieldoutputlengthoftheexternaldisplay

  • 10/5/2015 ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

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

    ThecolumnwidthFIELDCATOUTPUTLENmustnotbeequivalenttotheoutputlengthoftheexternaldisplay(FIELDCATDDIC_OUTPUTLEN).ointlen(internaloutputlength)Valuerange:0(initial),nOnlyrelevanttofieldswithoutreferencetotheDataDictionarywhoseoutputshouldneverthelessbemodifiedusingaconversionexit.Prerequisites:FIELDCATEDIT_MASK='==conv'SeealsothedocumentationonparameterFIELDCATEDIT_MASKFIELDCATDDIC_OUTPUTLEN=nSeealsothedocumentationonparameterFIELDCATDDIC_OUTPUTLENn=Fieldoutputlengthoftheinternaldisplayorollname(dataelement)Valuerange:SPACE,nameofadataelementfromtheDataDictionaryYoucanusethisparametertoprovideanF1helpforaprogramfieldwithoutreferencetotheDataDictionaryortoprovideanF1helpotherthanthatoftheDataDictionaryforafieldwithreferencetotheDataDictionary.WhentheF1helpiscalledforthisfield,thedocumentationforthedataelementassignedisdisplayed.If,forfieldswithreferencetotheDataDictionary,FIELDCATROLLNAMEisinitial,thedocumentationforthedataelementofthereferencedfieldintheDataDictionaryisdisplayed.Otherosp_group(fieldgroupkey)Valuerange:SPACE,CHAR(1)KeyforgroupingfieldsYouassignthekeytothegroupdescriptionusingparameterIT_SPECIAL_GROUPS(seealsothedocumentationonparameterIT_SPECIAL_GROUPS).IfyoudefinesuchanassignmentinthefieldcatalogusingIT_SPECIAL_GROUPS,thefieldsinthefieldlistofthedisplayvariantdialogboxaregroupedaccordingly.oreprep(selectioncriterionofthereport/reportinterface)Valuerange:SPACE,'X'Prerequisites:Thereport/reportinterfaceexistsinthesystem.(functiongroupRSTI,tableTRSTI)ParameterLAYOUTREPREP='X'(SeealsothedocumentationonparameterLAYOUTREPREPofIMPORTINGparameterIS_LAYOUT)'X'=Ifthereport/reportinterfaceiscalled,thevalueofthisfieldispassedasaselectioncriterionintheselectedbranchlineoftheinterface.DefaultoForinternaltablefieldswithreferencetoafielddefinedinthe

    DataDictionary,itisnormallysufficienttomakethefollowingspecifications:fieldnameref_tabnameNote:Allfieldsnotexplicitlymentionedhereareeithernotrelevantinthiscontextorarenotreleased!AllotherinformationisretrievedbytheALVfromtheDataDictionary.Ifyoudonotspecifytherelativecolumnposition(COL_POS),thefieldsareoutputinthelistintheorderinwhichtheywereaddedtothefieldcatalog.REF_FIELDNAMEmustonlybespecifiedifthefieldnameoftheinternaltablefieldisnotidenticaltothefieldnameofthereferencedfieldintheDataDictionary.Priorityrule:SpecificationsmadeinthefieldcatalogtakepriorityoverspecificationsintheDataDictionary.

    ForinternaltablefieldswithoutreferencetotheDataDictionary(programfields),itisnormallysufficienttomakethefollowingspecifications:fieldnameoutputlendatatype(withoutdatatype,characteristhedefault)seltext_sseltext_lNote:IfyouassignadataelementtoparameterROLLNAME,youcan,forexample,implementanF1helpforprogramfields.IT_EXCLUDINGTableofinactivefunctioncodesDescriptionOptionalIMPORTINGparameterIT_EXCLUDINGisaninternaltable.Youmustonlyfillthistableifthecallerusesthestandardinterfaceofthelisttoolbutdoesnotneedcertaininterfacefunctionsandthereforewantstodisablethem.Inthiscase,youmustenterthefunctioncodesofthesestandardfunctionsintothetable.IT_SORTSortcriteriaforfirstlistdisplayDescriptionUsinginternaltableIT_SORT,thecallerdeterminesthesortorderand/orthesubtotallingofthebasiclist.Thefollowingfieldsofthisinternaltablemustbefilled:ospos:Sortorderofieldname:Fieldnameintheinternaloutputtableoup:'X'=Sortedinascendingorderodown:'X'=Sortedindescendingorderosubtot:'X'=Subtotalsforcontrollevelchangesocomp(INTERNALUSEONLY)oexpaPerquisites:IT_SORTSUBTOT='X',thatis,thesortcriterionisalsothesubtotalscriterion.Ifnocompletebreakdownbutonlyabreakdowntototalslevelnthatcanbefurtherexpandedbytheusershouldbedisplayedwhenthelistisoutputforthefirsttime,youmustsettheindicatorforthetotalslevelcriterionofleveln.

  • 10/5/2015 ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

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

    IT_FILTERFiltercriteriaforfirstlistoutputDescriptionTablewithfiltercriteriaUsingthisparameter,youcanpassonfiltercriteriaresultingfromexplicitlyloadingadisplayvariantinadvance,forexample,tolistoutput.Thistableshouldneverbesetup'manually'.

    IS_SEL_HIDESelectioninformationmodificationDescriptionThisparameteriscurrentlynotsupported!OnlyrelevantiflayoutparameterLAYOUTGET_SELINFOSofIMPORTINGstructureIS_LAYOUTisset.Complextypeformodifyinginformationdisplayedontheselectiondialogbox:omode:'R'=OnlyentriespassedininternaltableIS_SEL_HIDET_ENTRIESareoutputonthedialogbox.Selectioninformationobtainedbythelisttoolbyreadingtheselectionscreenagain(onlyifthereportiscalledwithselectionscreen)arereplacedbytheentriespassed.'S'=Theselectioninformationobtainedbythelisttoolbyreadingtheselectionscreenofthecallingreportagain,aremodifiedbytheentriesoftableIS_SEL_HIDET_ENTRIES.ot_entries:Tablewithselectioninformationot_entriesmode:'A'=Displayselectioninformationofthecurrenttablerowontheinformationdialogbox.'D'=DonotdisplayselectioninformationoftheSelectoptionorofparameterSELNAMEonthedialogbox.ot_entriesselname:(requiredonlyift_entriesmode='D')nameofSelectoptionorparameterThefollowingtablefieldsareonlyrequiredift_entriesmode='A'.Theycontaintheselectioninformationtobeadded.ot_entriesfield:DDICfieldnameofthefieldforwhichselectioninformationistobedisplayedot_entriestable:DDICtablenameoft_entriesfield.ot_entriesstext:Fielddescriptionontheinformationdialogbox.Ift_entriesfieldandt_entriestablewerefilled,thistextistakenfromtheDDIC.ot_entriesvaluf:Selectionconditionfromvalue(externalformat)ot_entriesvalut:Selectionconditiontovalue(externalformat)ot_entriessign0:(I)nclusive(E)xclusiveot_entriesoptio:AllvaluesoftheoptionfieldoftheSelectoptionareallowed.Theremainingfieldsareusedinternallyandareirrelevanttothecaller.

    I_DEFAULTInitialvariantactive/inactivelogicDescriptionInitialvariantmaintenanceactive/inactive..Prerequisite:ParameterIS_VARIANTisfilledaccordingly.SeealsothedocumentationontheIMPORTINGparameterIS_VARIANT.ValueRangeSPACE=Definitionofinitialvariantsnotallowed'X'=DefinitionofinitialvariantsallowedDefault:SPACEI_SAVEVariantscanbesavedDescriptionControlsthesavemodePrerequisite:ParameterIS_VARIANTisfilledaccordingly.SeealsothedocumentationonIMPORTINGparameterIS_VARIANT.ValueRangeo''=DisplayvariantscannotbesavedDefineddisplayvariants(suchasdelivereddisplayvariants)canbeselectedforpresentationregardlessofthisindicator.However,changescannotbesaved.o'X'=StandardsavemodeDisplayvariantscanbesavedasstandarddisplayvariants.Savingdisplayvariantsasuserspecificisnotpossible.o'U'=UserspecificsavemodeDisplayvariantscanonlybesavedasuserspecific.o'A'=StandardanduserspecificsavemodeDisplayvariantscanbesavedbothasuserspecificandasstandardvariants.Usersmaketheirchoiceonthedialogboxforsavingthedisplayvariant.Default:SPACE.IS_VARIANTVariantinformationDescriptionThisstructureisonlyrelevantifdisplayvariantsaretobesavedand/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.

  • 10/5/2015 ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

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

    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.ValueRangeTocallalistwithavariant,youmustspecifytheabovefields.DefaultIfthestructureisinitial,butsavingisactive(I_SAVEisnotinitial),thenIS_VARIANTREPORT=I_CALLBACK_PROGRAMisset.Forapossibleentrieshelpforvariants,functionmoduleREUSE_ALV_VARIANT_F4isavailable.

    Onlyrequiredifthelististobeoutputinadialogbox. I_SCREEN_START_COLUMNI_SCREEN_START_LINEI_SCREEN_END_COLUMNI_SCREEN_END_LINE

    ExampleCodeWS_REPNAME=SYREPID.CALLFUNCTION'REUSE_ALV_FIELDCATALOG_MERGE'EXPORTINGI_PROGRAM_NAME=WS_REPNAMEI_INTERNAL_TABNAME=InternaloutputtablefieldnameI_INCLNAME=WS_REPNAMECHANGINGCT_FIELDCAT=I_FIELDTAB.IFSYSUBRC0.WRITE:'SYSUBRC:',SYSUBRC,'REUSE_ALV_FIELDCATALOG_MERGE'.ENDIF.CALLFUNCTION'REUSE_ALV_LIST_DISPLAY'EXPORTINGI_CALLBACK_PROGRAM=WS_REPNAMEI_STRUCTURE_NAME=InternaloutputtablefieldnameIS_LAYOUT=I_LAYOUTIT_FIELDCAT=I_FIELDTABI_DEFAULT='A'I_SAVE='A'IS_VARIANT='X'IT_EVENTS=I_EVENTS[]IT_SORT=I_SORTIS_SEL_HIDE=I_SELINFOTABLEST_OUTTAB=Internaloutputtablefieldname.IFSYSUBRC0.WRITE:'SYSUBRC:',SYSUBRC,'REUSE_ALV_LIST_DISPLAY'.ENDIFUsingotherfunctionmodule'REUSE_ALV_GRID_DISPLAY'canhelpusgetlistoutputintheformofagridandalsoattachlogostothereportoutput.

    Samplecode1Simplelistoutput:REPORTY_DEMO_ALVNOSTANDARDPAGEHEADING.*DatatobedisplayedDATA:I_SFLIGHTTYPETABLEOFSFLIGHT.***SelectionSELECT*FROMSFLIGHTINTOTABLEI_SFLIGHT.*CallABAPListViewer(ALV)CALLFUNCTION'REUSE_ALV_LIST_DISPLAY'EXPORTINGI_STRUCTURE_NAME='SFLIGHT'TABLES

  • 10/5/2015 ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

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

    T_OUTTAB=I_SFLIGHT.2.Simplegridoutput:REPORTY_DEMO_ALV_1.**DatatobedisplayedDATA:I_SFLIGHTTYPETABLEOFSFLIGHT.***SelectionSELECT*FROMSFLIGHTINTOTABLEI_SFLIGHT.*CallABAPListViewer(ALV)CALLFUNCTION'REUSE_ALV_GRID_DISPLAY'EXPORTINGI_STRUCTURE_NAME='SFLIGHT'TABLEST_OUTTAB=I_SFLIGHT.3.Demofor'REUSE_ALV_POPUP_TO_SELECT'REPORTy_demo_alv_3.TYPEPOOLS:slis.DATA:BEGINOFi_outtabOCCURS0.INCLUDESTRUCTUREsflight.DATA:w_chkTYPEc."FormultipleselectionDATA: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'EXPORTINGi_title=p_titlei_selection='X'i_zebra='X'*I_SCREEN_START_COLUMN=0*I_SCREEN_START_LINE=0*I_SCREEN_END_COLUMN=0*I_SCREEN_END_LINE=0i_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_PRIVATEIMPORTINGes_selfield=i_selfielde_exit=w_exitTABLESt_outtab=i_outtabEXCEPTIONSprogram_error=1OTHERS=2.IFsysubrc0.*MESSAGEi000(0k)WITHsysubrc.ENDIF.*****theinternaltableismodifiedwithacrosssignformarkingtherowsselectedLOOPATi_outtabWHEREw_chk='X'.WRITE:/i_outtabcarrid,i_outtabprice.ENDLOOP.

    5.WholeSampleCodeREPORTYSUBALV.*Declarationofvariables*TYPEPOOLS:SLIS.*TopassnameofthereportinfunctionmoduleforALVDATA:V_REPIDLIKESYREPID.*TopasstheoverallstructureoftheALVreportDATA:STRUCT_LAYOUTTYPESLIS_LAYOUT_ALV.DATA:STRUCT_LAYOUT1TYPESLIS_LAYOUT_ALV.*InternaltabletocapturevariouseventsinALVDATA:I_EVENTSTYPESLIS_T_EVENT.

  • 10/5/2015 ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

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

    *TableforcatalogofthefieldstobedisplayedDATA:I_FIELDCATTYPESLIS_T_FIELDCAT_ALV.data:x_fieldcatTYPESLIS_FIELDCAT_ALV.DATA:I_FIELDCAT1TYPESLIS_T_FIELDCAT_ALV.data:x_fieldcat1TYPESLIS_FIELDCAT_ALV.*InternaltabletomentionthesortsequenceDATA:IT_SORTTYPESLIS_T_SORTINFO_ALV.DATA:X_SORTTYPESLIS_SORTINFO_ALV.*Internaltabletodisplaytopofpagedata:i_list_top_of_pagetypeslis_t_listheader.*Structuretodisplayvariantsdata:i_variantlikedisvariant,i_variant1likedisvariant.*InternaltabletopassdataDATA: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.*EJECTDATA:beginofi_dococcurs0.INCLUDESTRUCTUREMSEG.DATA:endofi_doc.*EndofDataDeclaration*PARAMETERS:P_VARLIKEDISVARIANTVARIANT.initialization.v_repid=syrepid.*DisplaydefaultvariantPERFORMSUB_VARIANT_INIT.ATSELECTIONSCREENONP_VAR.*Oncetheuserhasenteredvariant,checkaboutitsexistencePERFORMSUB_CHECK_PVAR.ATSELECTIONSCREENONVALUEREQUESTFORP_VAR.*DisplayalistofvariousvariantsofthereportwhentheuserpressesF4keyinthevariantfieldPERFORMSUB_VARIANT_F4.STARTOFSELECTION.*Preparefieldcatalogforthemainreport.Statethenameofthefield,nameofinternaltable,variousformattingoptionsetcPERFORMSUB_PREPARE_FIELDCATALOG.*Fetchesrecordsfromdatabaseintotablei_tabtobepassedasexport*parametert_outtabinfunctionmodule:REUSE_ALV_GRID_DISPLAYPERFORMSUB_SELECT_RECORD.*Populatestatandiconcolumnsofinternaltablei_tabwithspecific*columnsandsymbolsbasedonsomelogicforquantityandvaluefields.PERFORMSUB_MODIFY_RECORDS.*DefinestheoveralllayoutofthereportPERFORMSUB_DETERMINE_ALV_LAYOUT.*DefinesthesortsequenceofthereportPERFORMSUB_DETERMINE_SORT_SEQUENCE.*DefinestheeventtablePERFORMSUB_EVENTTAB_BUILDUSINGI_EVENTS.*ThingstobewrittenatthetopofthepagePERFORMSUB_COMMENT_BUILDUSINGi_list_top_of_page.*DisplaytheALVlistPERFORMSUB_SHOW_ALV_LIST.*struct_layouthotspot_fieldname='X'.ATLINESELECTION.PERFORMSUB_HOTSPOT.*&**&FormSUB_VARIANT_INIT*&**Displaydefaultvariant**formSUB_VARIANT_INIT.I_VARIANT1REPORT=SYREPID.*SearchdefaultvariantforthereportCALLFUNCTION'REUSE_ALV_VARIANT_DEFAULT_GET'

  • 10/5/2015 ALVTUTOTIALFORBEGINERSWITHEXAMPLESABAPDevelopmentSCNWiki

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

    EXPORTINGi_save='A'CHANGINGcs_variant=i_variant1EXCEPTIONSnot_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,checkaboutitsexistenceifnotp_varisinitial.cleari_variant.i_variantreport=syrepid.i_variantvariant=p_var.CALLFUNCTION'REUSE_ALV_VARIANT_EXISTENCE'EXPORTINGI_SAVE='A'CHANGINGCS_VARIANT=I_VARIANT.*Ifnosuchvariantfound,flasherrormessageifsysubrcne0.messagee398(00)with'Nosuchvariantexists'.else.*Ifvariantexists,usethevariantnametopopulatestructure*I_VARIANT1whichwillbeusedforexportparameter:IS_VARIANT*inthefunctionmodule:REUSE_ALV_GRID_DISPLAYcleari_variant1.movep_vartoi_variant1variant.movesyrepidtoi_variant1report.endif.else.cleari_variant.endif.ENDFORM."SUB_CHECK_PVAR*&**&Fo