CreateTableControlUsingABAPProgramming.docx

上传人:b****5 文档编号:27958851 上传时间:2023-07-06 格式:DOCX 页数:12 大小:347.15KB
下载 相关 举报
CreateTableControlUsingABAPProgramming.docx_第1页
第1页 / 共12页
CreateTableControlUsingABAPProgramming.docx_第2页
第2页 / 共12页
CreateTableControlUsingABAPProgramming.docx_第3页
第3页 / 共12页
CreateTableControlUsingABAPProgramming.docx_第4页
第4页 / 共12页
CreateTableControlUsingABAPProgramming.docx_第5页
第5页 / 共12页
点击查看更多>>
下载资源
资源描述

CreateTableControlUsingABAPProgramming.docx

《CreateTableControlUsingABAPProgramming.docx》由会员分享,可在线阅读,更多相关《CreateTableControlUsingABAPProgramming.docx(12页珍藏版)》请在冰豆网上搜索。

CreateTableControlUsingABAPProgramming.docx

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

∙Tablecontrolfieldsaretransportedrowbyrowtomodulepoolfields

∙FieldsspecifiedinFIELDstatementsaretransportedimmediatelybeforetheFIELDstatementisexecuted

Updatingdataintablecontrol

TheABAPlanguageprovidestwomechanismsforloadingthetablecontrolwithdatafromtheinternaltableandthenstoringthealteredrowsofthetablecontrolbacktotheinternaltable.

1.Method1:

 ReadtheinternaltableintotheTableControlinthescreen’sflowlogic. UsedwhenthenamesoftheTableControlfieldsarebasedonfieldsoftheinternaltable.

2.Method2:

 ReadtheinternaltableintotheTableControlinthemodulepoolcode.UsedwhenthenamesoftheTableControlfieldsarebasedonfieldsofthedatabasetable.

Method1(tablecontrolfields=itabfields)

IntheflowlogicwecanreadaninternaltableusingtheLOOPstatement.DefinethereferencetotherelevantablecontrolbyspecifyingWITHCONTROL

DeterminewhichtableentryistobereadbyspecifyingCURSOR-CURRENT_LINE.

Afterthereadoperationthefieldcontentsareplacedintheheaderlineoftheinternaltable.Ifthefieldsinthetablecontrolhavethesamenameastheinternaltheywillbefilledautomatically.Otherwiseweneedtowriteamoduletotransfertheinternaltablefieldstothescreenfields.

WemustreflectanychangestheusermakestothefieldsofthetablecontrolintheinternaltableotherwisetheywillnotappearwhenthescreenisredisplayedafterPBOprocessing,(eg,aftertheuserpressesEnterorscrolls)However,thisprocessingshouldbeperformedonlyifchangeshaveactuallybeenmadetothescreenfieldsofthetablecontrol(hencetheuseoftheONREQUEST)

PROCESSBEFOREOUTPUT.

LOOPATITAB_REGWITHCONTROLTCREG

CURSORTCREG-CURRENT_LINE.

ENDLOOP.

PROCESSAFTERINPUT.

LOOPATITAB_REG.

MODULEMODIFY_ITAB_REG.

ENDLOOP.

MODULEMODIFY_ITAB_REGINPUT.

MODIFYITAB_REGINDEXTCREG-CURRENT_LINE.

ENDMODULE.

Method2(tablecontrolfields=dict.fields)

IfusingaLOOPstatementwithoutaninternaltableintheflowlogic,wemustreadthedatainaPBOmodulewhichiscalledeachtimetheloopisprocessed.

Since,inthiscase,thesystemcannotdeterminethenumberofinternaltableentriesitself,wemustusetheEXITFROMSTEP-LOOPstatementtoensurethatnoblanklinesaredisplayedinthetablecontroliftherearenomorecorrespondingentriesintheinternaltable.

PROCESSBEFOREOUTPUT.

LOOPWITHCONTROLTCREG.

MODULEREAD_ITAB_REG.

ENDLOOP.

PROCESSAFTERINPUT.

LOOPWITHCONTROLTCREG.

CHAIN.

FIELD:

ITAB_REG-REG,

ITAB_REG-DESC.

MODULEMODIFY_ITAB_REG

ONCHAIN-REQUEST.

ENDCHAIN.

ENDLOOP.

MODULEREAD_ITAB_REGOUTPUT.

READTABLEITAB_REGINDEXTCREG-CURRENT_LINE.

IFSY-SUBRCEQ0.

MOVE-CORRESPONDINGITAB_REREGTOTCREG.

ELSE.

EXITFROMSTEP-LOOP.

ENDIF.

ENDMODULE.

MODULEMODIFY_ITAB_REGINPUT.

MOVE-CORRESPONDINGTCREGTOITAB_REG.

MODIFYITAB_REGINDEX

TCREG-CURRENT_LINE.

ENDMODULE.

Updatingtheinternaltable

Method1

PROCESSAFTERINPUT.

LOOPATITAB_REG.

CHAIN.

FIELD:

ITAB_REG-REG,

ITAB_REG-DESC.

MODULEMODIFY_ITAB_REGONCHAIN-REQUEST.

ENDCHAIN.

ENDLOOP.

MODULEMODIFY_ITAB_REGINPUT.

ITAB_REG-MARK=‘X’.

MODIFYITAB_REGINDEXTCREG-CURRENT_LINE.

ENDMODULE.

Method2

PROCESSAFTERINPUT.

LOOPWITHCONTROLTCREG.

CHAIN.

FIELD:

TCREG-REG,

TCREG-DESC.

MODULEMODIFY_ITAB_REGONCHAIN-REQUEST.

ENDCHAIN.

ENDLOOP.

MODULEMODIFY_ITAB_REGINPUT.

MOVE-CORRESPONDINGTCREGTOITAB_REG.

ITAB_REG-MARK=‘X’.

MODIFYITAB_REGINDEXTCREG-CURRENT_LINE.

ENDMODULE.

Updatingthedatabase

MODULEUSER_COMMAND_100.

CASEOK_CODE.

WHEN‘SAVE’.

LOOPATITAB-REG.

CHECKITAB_REG-MARK=‘X’.

MOVE-CORRESPONDINGITAB_REGTOTCREG.

UPDATETCREG.

ENDLOOP.

WHEN…

ENDCASE.

ENDMODULE.

Thosearethesimplestepshowtocreatetablecontrol.WhatIhavelearnedthisweekonlythebeginning.ActuallytherearemoreareasinSAPTableControlwithabapprogrammingthatcanbeexploreddeeper,butmaybenexttime.

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 人文社科 > 设计艺术

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1