Create Table Control Using ABAP Programming.docx
《Create Table Control Using ABAP Programming.docx》由会员分享,可在线阅读,更多相关《Create Table Control Using ABAP Programming.docx(10页珍藏版)》请在冰豆网上搜索。
![Create Table Control Using ABAP Programming.docx](https://file1.bdocx.com/fileroot1/2022-11/16/85e003c4-acb4-42f6-8655-6a6f5e2e116a/85e003c4-acb4-42f6-8655-6a6f5e2e116a1.gif)
CreateTableControlUsingABAPProgramming
CreateTableControlUsingABAPProgramming
CreateTableControlUsingABAPProgramming
Inlasttwoweeks,Ihavelearnedself-taughthowtocreate tablecontrol in SAPScreenusing ABAP4.Aftertrialanderror,finallyIhavefinishedmysmallproject.Whilelearningabouttablecontrol,Iuse SAPHelp asmainreference,somewebsitesandpresentationslidesfromMichaelAdams,QueenslandUniversityofTechnology.
ATableControlisascreen‘container’orobjectthatallowsdisplayofmultiplerowsofatable(database or internaltable)onascreen.Itisgoodfordisplayingaone-to-manyrelationshipontheonescreen.Thetablecontrolobjecthasmanyfeaturesbuiltintoenhancescreendisplayandusability.
TableControlfeaturesallow
∙horizontal&verticalscrolling
∙columnwidthresizing
∙scrollingwithinafield(wherecontentsarewiderthanthescreenfieldwidth)
∙reorderingthesequenceofcolumns
∙savingthecurrentdisplaysettingsforfutureuse
∙selectionoftablerows&columns
Formattingfeaturesinclude
∙automatictableresizingonwindowresize
∙separatorlinesbetweenrows&columns
∙columnheaderfieldsforallcolumns
Herestepstocreatetablecontrol
1.Declarethetablecontrol
Aswellasdrawingthetablecontrolonthescreenitisnecessarytodeclarethetablecontrolasadataitem(intheTOPincludeprogramforthetransaction).
CONTROLSctrlTYPETABLEVIEW USINGSCREENscr.
∙isthenameofthetablecontrolonascreenintheABAPprogram
∙correspondstoacomplextype– (CXTAB_CONTROLdefinedintheABAPdictionary)
∙isthescreenfromwhichthetablecontrolwillgetitsinitialvalues
2.Addingtablecontroltoascreen
Inthegraphicalscreeneditorchoosethetablecontrolelementbutton. Usetheleftmousebuttontopositionandsizethecontrolonthescreen.
Theninputthenameoftablecontrol.
3.AddingFieldtoatablecontrol
Toaddfieldtotablecontrol,wecanretrievefromtableorinternaltable.Clickonicon“dictionary/programfieldwindow”orfunctionkeyF6.
Theretwooptionwhileretrievefield,i.e.basedondatabasetableorinternaltable.Ifwanttoretrievefromdatabasetable,inputthenameoftablethenclickpushbutton“GetfromDictionary”.Ifwanttoretrievefrominternaltable,inputtheinternaltablenamethenclickpushbutton“Getfromprogram”.
Markthefieldtobeaddedtotablecontrol,andthenclickonpushbuttonOK.
Dragselectedfieldsintotablethenreleasethemousebutton.
Herethefieldsweselectedwillbedisplayedinreversedorder.Idonotexactlywhyithappens.Ihavetriedsomewaysandtrickstodisplayincorrectorder,butthefieldsstilldisplayedinreversedorder.Finally,togetthecorrectorderIselectedthefieldsonebyone.
4.Addinglabelforeachcolumn
Labelcolumnistextfield.Toaddit,justclickonthetextfieldicon,dragitontoheaderofthecolumnandthentypethelabel.
TableControlPrinciple
Thereareasetofprogrammingprinciplesthatshouldbeadheredtowhenusingtablecontrolsandsteploops.Datafromthedatabaseshouldbeinitiallyloadedintoaninternaltable.Thismeansthatthedatabaseisaccessedforreadpurposesonlyonceinthetransaction.Nexttherowsoftheinternaltableareloadedintothetablecontrol.Anychangesthataremadetothedataarethensavedbacktotheinternaltable.Attheendofthetransaction,thecontentsoftheinternaltablecanbewrittenbacktothedatabase,againtominimizedatabaseI/O.
PAIlogicforscreen1(seescreenbelow)loadstheinternaltablewithdatafromthedatabaseaccordingtotheentriessuppliedbytheuser.
PBOlogicforscreen2(seescreenbelow)populatesthetablecontrolfromtheinternaltable(buffer).
Useractioninscreen2triggersthePAIlogic.PAIlogicupdatestheinternaltablewithnewvaluesentered(intothetablecontrolscreenfields)bytheuser.
PAIlogicistriggeredbyactionssuchasscrollingdownasinglerowaswellasactionssuchasBACK,EXIT,etc.
Unlesstheuseractioncausesthetransactiontoleavethecurrentscreen,afterthePAImoduleshavebeenexecuted,thePBOmodulesforthescreenareexecutedagain.Thusthetablecontrolfieldsareupdatedorrefreshedaftereveryuseraction.
PBO(ProcessBeforeOutput)
InPBOprocessingfieldsaretransportedfromthemodulepooltothescreeninapredefinedorder.
∙Thetablecontrolsteploopisprocessedrowbyrow.Fieldswithcorrespondingnamesaretransportedfromthemodulepooltothescreen.
∙Afterthesteploophasbeenprocessedallremainingmodulepoolfieldsaretransportedtothescreen.
PAI(ProcessAfterInput)
∙AllscreenfieldsthatdonotbelongtoatablecontrolandarenotspecifiedinaFIELDstatementaretransportedtomodulepoolfields
∙Tabl