Anda di halaman 1dari 40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

SAP ABAP: Hands-On Test Projects with Business Scenarios

Recent

Topics
Tutorials

NEXT

PREV

Chapter 8: Open SQL Data Retrieval

CHAPTER9

Highlights
Chapter 10:
Interactive Lists

Settings
Feedback

SELECTIONSCREENS

Sign Out

ABAPprogramsthataregeneratingoutputsorreportsuseselection
screensforsimpleinputs.Forfullfledged,multiplescreendatainput
anddatacapturing,theABAPWorkbenchprovidesascreenpainterwith
draganddropandalltheotherfacilitiesassociatedwithcreatinginput
screensandprogramsinagraphicalenvironment.
Youhaveusedsomeformsoftheselectionscreenstatement

Settings
10 days left in your trial. Subscribe.

Feedback

PARAMETERSinyourhandsonexercises.Youuseditintheprogram
demonstratingtheCOLLECTstatementtoinputthecompanycodefor
whichthecustomerwisesalessummaryreportwastobegenerated.

Sign Out

Inenterpriseenvironments,theoutputtobegeneratedwill,forthemost
part,beoffiltereddata:ofspecifiedcompanycodes,plantcodes,etc.The
basisoffilteringdataistobedecidedatruntime.Sotheappropriate
valuesfordatafiltrationareinputthroughtheselectionscreen.
ThePARAMETERSstatementenabledinputofsinglevalues.TheABAP
selectionscreenprovidesformultiple,complexinputsthroughthe
SELECTOPTIONSstatementtobecoveredlaterinthischapter.
ThePARAMETERSandSELECTOPTIONSvariablesbelongtothe
categoryofspecialdataobjects.InChapter4,ABAPprogramdataobjects
Enjoy Safari? Subscribe Today

werecategorizedasthefollowing:
Internaldataobjects(throughdeclarativestatements:DATA,TABLES,
andCONSTANTS,etc.)
Externaldataobjects(referencestoDDICtables,structures,tableor
structurefields,internaltables,anddataelements)
Specialdataobjects(selectionscreenPARAMETERSandSELECT
OPTIONSvariables)
Systemdataobjects(theSYseriesvariables:SYDATUM,SYMANDT,
etc.)
Theselectionscreendoesnotprovideforpositioningofscreenelements
throughdraganddropfacility.Withtheselectionscreen,youhaveto
writeABAPcodetocreateandpositionscreenelements.TheABAP
runtimesystemautomaticallygeneratesthescreensfromtheselection
screencode.
IntheABAPWorkbenchenvironment,screensarenumberedfrom1
9999foridentification.Theselectionscreenscanbestandardwitha
preassignedscreennumber1000.Theselectionscreenscanbeuser
definedwiththescreennumberassignedduringtheselectionscreen
definition.Withtheuserdefinedselectionscreens,theyneedtobecalled
afterthedefinition.
WithanexecutableABAPprogram,youcanhaveonestandardselection
screen(screennumber1000)andanynumberofuserdefinedselection
screens.Withmodulepoolprogramsandfunctionmodules,youcanhave
onlyuserdefinedselectionscreens.
Youcancreatethefollowingscreenelementsontheselectionscreens:
Labelsortexts
Textboxesorinputfields

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

1/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

Radiobuttons
Checkboxes
Multiplecomplexselections(SELECTOPTIONS)
Pushbuttons
Blanklines
Blocks
Horizontallines
Subscreens
Tabstripcontrols
Inthehandsonexercisesinthischapter,themajorscreenelementsare
goingtobecovered.Thescreenelementssubscreensandtabstrip
controlswillbecoveredinChapter14.
Theselectionscreenwillbecoveredintwoseparatestages:(a)thelayout
howtocreatepositionscreenelementsontheselectionscreen,and(b)
theselectionscreeneventsandothersubtopics.
Allselectionscreenstatementsstartwithoneofthekeyphrases:
1. SELECTIONSCREEN
2. PARAMETERS
3. SELECTOPTIONS
RecapitulationPARAMETERSStatement
Beforeahandsonexercise,letthefeaturesofPARAMETERSstatement
thatyouhaveuseduntilnowberecapitulatedformally.Thesyntaxof
PARAMETERSstatement:

PARAMETERS:<variablename>{TYPE|LIKE}
<ABAPelementaryTYPEorreferencetolocalorglobalTYPEorlocalorglobaldataobject>
LOWERCASE
DEFAULT<defaultvalue>
VALUECHECK
MATCHCODEOBJECT<searchhelpname>.

<variablename>Canbeamaximumofeightcharacters,muststart
withanalphabetletter,andtherestcanbealphanumericwithembedded
underscores(_).
{TYPE|LIKE}YoucanusethekeywordTYPE/LIKE.Referto
SummaryofDataDeclarationbyReferencetoOtherDataObjects,
TypesavailableintheEResourceofChapter6.
<ABAPelementarypredefinedTYPES>TYPESC,D,I,N,P,T,X,
STRING.TYPEFandTYPEXSTRINGarenotsupported.
<referencetolocalorglobalTYPES>Referencecanbetolocally
declaredtypeswiththekeywordTYPES.Oritcanbeareferencetoa
DDICdataelementoraDDICTYPEGROUP.
<referencetolocalorglobaldataobject>Referencecanbetoalocally
declareddataobjectoritcanbeareferencetoaDDICdataobject.
LOWERCASECasesensitivityforTYPECandTYPESTRING(by
default,caseinsensitive).
DEFAULT<defaultvalue>Toassignaninitialorstartingvaluetothe
inputfield.
VALUECHECKTohavetheenteredvaluecheckedagainstvaluesina
checktable.ThePARAMETERSvariableshouldbedeclaredbyreference
toaforeignkeyfieldinasecondarytable.
MATCHCODEOBJECT<searchhelpname>Attachasearchhelp.
Therearesomemoreclausesoradditionsavailablewiththe
PARAMETERSstatement.Theywillbecoveredascontextsarise.
Byconvention,theselectionscreenstatementsarelocatedinanABAP
programafterthedatadeclarations.AnABAPprogramshouldhavethe
programsglobaldatadeclaredintheverybeginningfollowedbythe
selectionscreenstatements.
Byconvention,theselectionscreeneventsfollowtheselectionscreen
statements.WhenanABAPprogramisexecuted,theselectionscreen
statementsgetexecutedwithinputpromptsthatappear.Whenthe
executebutton/F8ispressedontheselectionscreen,thenonselection
screenstatementsgetexecuted.Theprogramaftertheendofexecution
ofnonselectionscreenstatementsreturnstotheselectionscreeninput
prompt.
YoucancheckthisoutexecutingtheABAPprogramwiththeCOLLECT
statement(YCL_CH06_ITAB05).Initiallythesystempromptsforthe
companycode.Inputofavalidcompanycodeandpressingtheexecute

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

2/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

button/F8generatesthesalessummarylistorreportfortheinput
companycode.Pressingthebackbutton/F3onthelisttakesyoubackto
theselectionscreenpromptingyouforthecompanycode.
SelectionScreen:LayoutandPositioningofScreenElements
Insteadofcoveringeachoftheselectionscreenelementscreationand
positioninginisolation,ahandsonexercisewillbeundertakenandthe
creationandpositioningofselectionscreenelementswillbeintroduced
inthecontextofthehandsonexercise.
YourexerciseistoreproduceinappearanceandlookstheABAPEditor
openingscreenusingtheselectionscreenstatements.
AscreenshotoftheSE38ABAPEditoropeningscreenisshowninFigure
91.

Figure91.SE38ABAPEditorOpeningScreen

Theselectionscreenthatyouaregoingtoproducewillresemblethe
SE38ABAPEditoropeningscreenonlyintermsoflookandappearance
notthefunctionality.
TheSE38ABAPEditoropeningscreenlayoutconsistsandinvolvesthe
following:
1. Agapoftwolinesatthetopgeneratesblanklinesonthe
selectionscreen
2. Alabel,aninputfield,andapushbuttononasinglelineplace
multipleselectionscreenelementsonasingleline
3. Createalabelortext(Program)ontheSelectionScreen
4. Createaninputfieldforenteringtheprogramnameoracceptingit
fromaselectionlist(searchhelp,F4,etc.)ontheselectionscreen
5. Createapushbuttonwithaniconandtextontheselectionscreen
6. Agapofonelinegeneratesablanklineonselectionscreen
7. Commencementofashadedareawithatitle(Subobjects)
extendingtoalittlemorethanhalfthewidthofthescreenbegins
aselectionscreenblock
8. Withintheshadedareaarefiveradiobuttons.Eachradiobutton
withitslabelortextappearsinoneline.createsfiveradio
buttons(oneineachline)withlabelsontheselectscreen
9. Agapofonelineafterthefiveradiobuttons.generateablank
lineonselectionscreen
10. Twopushbuttonswithiconandtext.Thetwopushbuttonsareon
thesamelineandintheshadedareacreatetwopushbuttonson
thesamelineontheselectionscreen
11. Conclusionoftheshadedareaendsaselectionscreenblock
Astepbystepprocedureisdescribedtocreatetheselectionscreen,which
resemblestheSE38ABAPEditoropeningscreeninappearance.Evenas
astatementisrequired,itssyntaxisintroducedandexplained.Atthe
endofthesyntaxexplanation,theexactstatementtocreatethescreen
elementsfollows.
GenerateBlankLines
Togenerateblanklinesontheselectionscreen,youusethestatement:
SELECTIONSCREENSKIP[<numberoflines>].

SKIPKeyword.
<numberoflines>Aliteraltospecifythenumberoflinestoskip(09
only).
Ifyouomit<numberoflines>,itwillskiponelinebydefault.
Statement
SELECTIONSCREENSKIP2.
MultipleElementsonaSingleLine

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

3/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

Bydefault,eachscreenelementontheselectionscreenoccupiesonefull
line.Topositionmultiplescreenelementsinthesamelineonthe
selectionscreen,youusethestatements:

SELECTIONSCREENBEGINOFLINE.
..........
SELECTIONSCREENENDOFLINE.

Youlocatethestatementstocreatethethreescreenelements:thatis,a
labelortext,aninputfield,andapushbuttononthesameselection
screenlinebetweenthefollowing:
Statements
SELECTIONSCREENBEGINOFLINE.&SELECTIONSCREENEND
OFLINE.
CreateLabelorText
Tocreatelabelortextontheselectionscreen,youusethestatement:

SELECTIONSCREENCOMMENT[/]<colposition>(<widthincolumns/characters>){<textsymbolid>|<commentid>}.

COMMENTKeyword.
[/](Optional)tostartthelabelortextonanewline.
<colposition>Thestartingcolumnpositionfromwheretostartthe
labelortext.Itcanbealiteralintherange183.
(<widthincolumns/characters>)Thewidthofthelabelortextin
characters.Itcanbealiteralintherange183.
{<textsymbolid>|<commentid>}Youcaneithergivea<textsymbol
id.>ora<commentid.>.The<commentid.>canbeamaximumofeight
characters,startingwithanalphabet,andtherestalphanumericwith
embeddedunderscores(_).
The<commentid.>mustbeassignedtextatanappropriateevent:
INITIALIZATION,ATSELECTIONSCREENOUTPUT.
Statement
SELECTIONSCREENCOMMENT1(15)TEXT001.
ThetextsymbolTEXT001willcontain:Program.
InputField
Toinputvalueinafield,youusethefamiliarPARAMETERSstatement.
PARAMETERS<variablename>MATCHCODEOBJECT<searchhelp>
VISIBLELENGTH<visiblecolumns>

YouareusinganadditionalclauseVISIBLELENGTH.Thelengthoffield
TRDIRTNAMEis40characters.IntheSE38screen,youareableto
viewonly30charactersofaprogramname.ThenamespaceofanABAP
programnameis30characters.ThenamespaceofSAPdelivered
programnamescanbe40characters.HenceintheSE38screen,after30
columns,thereishorizontalscrolling(checkthisout).Throughtheclause
VISIBLELENGTH,youcanreducevisiblecolumnsofanyselection
screenelement.
Statement
PARAMETERSPROGRAMTYPETRDIRTNAME
MATCHCODE.OBJECTYCL_CH09_TRDIRT
VISIBLELENGTH30.

TheSE38screenfunctionalityhasbeencreatedusingthefullfledged
screenprogrammingfeaturesoftheABAPWorkbench.Whenyoupress
F4intheprogramfieldofABAPEditoropeningscreen,thereisnosearch
helpoperating:thereisacomplexcodethatpresentstheuserwithavery
sophisticateddialogbox.Youcantbedoingthiswithyourlimitedfirst
formalexposuretoaselectionscreen.
SoyouarecreatingasimplesearchhelpusingthetableTRDIRT.This
tablecontainsonlythreefields:theABAPprogramname,languagecode,
andthetitleorshorttextthatyouenterontheattributesscreenof
programcreation.AscreenshotofthesearchhelpYCL_CH09_TRDIRT
isshowninFigure92.

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

4/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

Figure92.SearchHelp:YCL_CH09_TRDIRT

CreateaPushButtonwithIconandText
ApushbuttoniscreatedandlocatedontheSelectionScreenwiththe
statement:

SELECTIONSCREENPUSHBUTTON[/]<colposition>
(<widthincolumns/characters>)
{<textsymbolid>|<pushbuttonname>}
USERCOMMAND<usercommand>.

PUSHBUTTONKeyword.
[/](Optional)topositionthepushbuttononanewline.
<colposition>Isstartingcolumnfromwheretopositionthepush
button.Itcanbealiteralintherange183.
(<widthincolumns/characters>)Thewidthofthepushbuttonin
characters.Itcanbealiteralintherange183.
{<textsymbolid>|<pushbuttonname>}Youcaneithergivea<text
symbolid.>ora<pushbuttonname>.The<pushbuttonname>canbea
maximumofeightcharacters,startingwithaletterofthealphabet,and
therestalphanumericwithembeddedunderscores(_).
The<pushbuttonname>mustbeassignedtextatanappropriateevent:
INITIALIZATION,ATSELECTIONSCREENOUTPUT.
USERCOMMAND<usercommand>
Apushbuttonmandatorilyshouldbeassigneda<usercommand>.Itis
throughthis<usercommand>thatyouwillknowintheprogramwhich
pushbuttonwaspressedandtaketheappropriateaction.The<user
command>canstartwithspecialcharacterssuchas*_=etc.,butitisa
goodconventiontostartthemwithanalphabetletterandstickto
alphanumericcombinationswithembeddedunderscores(_).The<user
command>canbeamaximumof20characters.ThesystemfieldSY
UCOMMisloadedwithassigned<usercommand>whenthepushbutton
ispressed.TheeventATSELECTIONSCREENistriggeredwhenauser
clicksonapushbutton.Whichpushbuttonispressedisascertainedby
interrogatingthecontentsofthesystemfieldSYUCOMMintheevent
ATSELECTIONSCREEN.Caution:the<usercommand>iscase
insensitive.SynonymoustermsforUSERCOMMAND:functioncode
andfcode.
Statement
SELECTIONSCREENPUSHBUTTON53(15)TEXT002

USERCOMMANDCREAT.

ThetextsymbolTEXT002willcontain@0Y@Create.
Youraimistoputtheiconpictureandtextonthepushbuttonface.The
contentsoftextsymbolid.TEXT002couldbelike@0Y@Create.Ifyou
wantthecreateiconfollowedbythetextCreateinthepushbutton,you
havetoenclosetheiconcode0Ywiththecharacter@'followedbythe
textCreate.
Foralistoficoncodesandnames,executetheChapter7program:
YCL_CH07_05_OUTPUT_INBOX_MACRO.YoucanlocatetheCreate
iconinthelistbypressing<Ctrl>Fandenteringcreateinthedialog
box.Thefindresultwilllistoutalliconsnamescontainingthestring
create.Youcanselecttheappropriateiconandlookuptheiconcodefor
theicon.Whenevertheiconcodeisenclosedinthecharacter@and
presentedonscreen,itwillautomaticallyoutputaniconpictureor
image.
Thereisanotherelaboratewayofplacinganiconpictureandtextona
SelectionScreenpushbutton.Thisinvolvestheusageoffunctionmodule:
ICON_CREATEdemonstratedinprogram:
YCL_CH09_SELECTION_SCREEN01VR.Thefunctionmoduletakesas
oneoftheinputstheiconnameanddoesthesamething,getstheicon
code,andenclosesitlike@<iconcode>@Thefunctionmodulealso
returnstheinfotextortooltip.Theprogram:

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

5/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

YCL_CH09_SELECTION_SCREEN01VRisnotlistedhere.Butitis
availableintheEResource.Uploadit,peruseitscode,andtryitout.
Generateablanklinethroughthealreadycoveredstatement
Statement:SELECTIONSCREENSKIP.
SelectionScreenBlock,BEGINOFBLOCK
Createashadedareawithatitle:Subobjects.Thiscanbeproducedwith
theselectionscreenelement:block.Thesyntaxforcreatingaselection
screenblock:
SELECTIONSCREENBEGINOFBLOCK<nameofblock>
[TITLE{<textsymbolid.>|<titlename>}]
[WITHFRAME]
[NOINTERVALS].

SELECTIONSCREENENDOFBLOCK<nameofblock>.

BEGINOFBLOCKKeyphrasetocommenceablock.
<nameofblock>Ablocknamecanbeamaximumof20characters,
shouldstartwithaletterofthealphabet,buttherestcanbealphanumeric
withembeddedunderscores(_).
TITLEKeyword.
{<textsymbolid>|<titlename>}Youcaneithergivea<textsymbol
id.>ora<titlename>.The<titlename>canbeamaximumofeight
characters,startingwithanalphabetletter,withtherestbeing
alphanumericwithembeddedunderscores(_).
WITHFRAMEKeyphrase.Ifyouprovidethisoptionalkeyphrase,the
shadingeffectiscreated.
NOINTERVALSKeyphrase.Thishasrelevanceonlyifyouhave
specifiedthekeyphraseWITHFRAME.Ifyouprovidethisoptionalkey
phrase,theshadingwillextendtohalfthewidthofthescreen.Ifyouomit
thiskeyphrase,shadingwillextendtotheendofthescreen.
ENDOFBLOCKKeyphrasetoendablock.
Youlocatealltheselectionscreenelementswithinablockbyenclosing
theselectionscreenelementscreationstatementswithinSELECTION
SCREENBEGINOFBLOCK&SELECTIONSCREENENDOFBLOCK.
Youcannestblocks(i.e.,blockswithinblocks).Thenestingcanbeupto
fivelevels.
Statements:

SELECTIONSCREENBEGINOFBLOCKBL1
WITHFRAMETITLETEXT003NOINTERVALS.
.
SELECTIONSCREENENDOFBLOCKBL1.

ThetextsymbolTEXT003willcontainSubobjects.
Selectionscreenradiobuttons
Createradiobuttonswithlabelsortexts.Aseachradiobuttonwithits
correspondinglabelortexthastobepositionedinasingleline,youhave
toenclosethelabelortextandradiobuttoncreationstatementswithin
SELECTIONSCREENBEGINOFLINEandSELECTIONSCREENENDOF
LINE.
Tocreatearadiobuttononaselectionscreen,youuseavariationofthe
PARAMETERSstatement:

PARAMETERS:<variablename>RADIOBUTTON
GROUP<radiobuttongroupname>[USERCOMMAND<usercommand>].

PARAMETERS:Keyword.
<variablename>Maximumofeightcharacters,muststartwithaletter
ofthealphabet,buttherestcanbealphanumericwithembedded
underscores.(_)
RADIOBUTTONGROUPKeyphrase.
<radiobuttongroupname>Aradiobuttonhastobeassignedtoaradio
buttongroup.Aradiobuttongroupmustconsistofaminimumoftwo
radiobuttons.Withinaradiobuttongroup,ifyouclick/enableone,all
othersinthegroupgetdisabled.TheTYPEandlengthofradiobutton
variablesisCand1.Ifaradiobuttonisenabled,itassumesthevalueX
andwhendisabledassumesavalueblankor.Aradiobuttongroup
namecanbeamaximumoffourcharacters.Otherrulesapplicabletouser
definedABAPvariablesapplytotheradiobuttongroupname.
Bydefault,thefirstradiobuttoninthegroupisenabledwhenthe

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

6/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

selectionscreenappears.Ifyouwantotherthanthefirstradiobuttonina
grouptobeenabledinitiallywhentheselectionscreenappears,youcan
dothisbyassigningaDEFAULTXtotheradiobuttonvariableyouwant
asenabledinitially.
USERCOMMANDKeyphrase.
<usercommand>Sameasdescribedinthecontextofpushbutton.
Youcanassigna<usercommand>toaradiobuttongroup.Thisis
optional.Ifyouassigna<usercommand>toaradiobuttongroup,
clickingonanyoftheradiobuttonsinthegroupwilltriggertheevents
ATSELECTIONSCREEN,ATSELECTIONSCREENON
RADIOBUTTONGROUP<radiobuttongroupname>,etc.Toassigna
<usercommand>toaradiobuttongroup,usetheclauseUSER
COMMAND<usercommand>forthefirstradiobuttoninthegrouponly.
Statements:
SELECTIONSCREENBEGINOFBLOCKBL1
WITHFRAMETITLETEXT003NOINTERVALS.
SELECTIONSCREENBEGINOFLINE.
PARAMETERSSRCERADIOBUTTONGROUPGRP."radiobuttonSource
SELECTIONSCREENCOMMENT2(20)TEXT004.
SELECTIONSCREENENDOFLINE.
SELECTIONSCREENBEGINOFLINE.
PARAMETERSVARARADIOBUTTONGROUPGRP."radiobuttonVariants
SELECTIONSCREENCOMMENT2(20)TEXT005.
SELECTIONSCREENENDOFLINE.
.
SELECTIONSCREENENDOFBLOCKBL1.

ThetextsymbolsTEXT004willcontainSourceandTEXT005will
containVariants.Inalikemanneryouwillcodefortheremaining
threeradiobuttons.
TwoPushButtonsonaLine
Atthelast,youhavetocreatetwopushbuttons(Display,Change)ona
singleline.Soyouhavetoenclosethepushbuttoncreationstatements
withinSELECTIONSCREENBEGINOFLINE.&SELECTIONSCREEN
ENDOFLINE.
Statements:
SELECTIONSCREENBEGINOFLINE.
SELECTIONSCREENPUSHBUTTON1(15)TEXT009
USERCOMMANDDISPL.
SELECTIONSCREENPUSHBUTTON19(15)TEXT010
USERCOMMANDCHANG.
SELECTIONSCREENENDOFLINE.

Generateablanklinethroughthealreadycoveredstatement
Statement:SELECTIONSCREENSKIP.
ENDOFBLOCK
Theshadedareablockhastobeconcludedwiththisstatement:
Statement:SELECTIONSCREENENDOFBLOCK.
ATSELECTIONSCREENevent
Intheprogram,youhavetriggeredtheselectionscreeneventAT
SELECTIONSCREEN.Thiseventistriggeredwhenuserinteractswith
theselectionscreen,suchaswhen:
The<Enter>keyispressed.
Aselectionscreenpushbuttonisclicked.
AselectionscreenradiobuttonisclickedandtheoptionalUSER
COMMANDclausewasusedforthisradiobuttongroup.
AselectionscreencheckboxisclickedandtheoptionalUSER
COMMANDclausewasusedforthischeckbox.
Applicationtoolbarorstandardtoolbarbuttonisclicked,anda
menuselectionismade.
Youhaveimpartedaverylimitedfunctionalitytothisprogramthrough
thisATSELECTIONSCREENevent.
Youarecheckingwhichoftheselectionscreenpushbutton(Create,
Display,orChange)ispressedandissuingamessagetothiseffectwith
theMESSAGEstatement.Youaredeterminingwhichofthepushbuttons
ispressedbycheckingthecontentsofthesystemfieldSYUCOMM

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

7/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

againsttheUSERCOMMANDstringassignedtoeachofthethreepush
buttons.PleasekeepinmindthatthesystemfieldSYUCOMMiscase
insensitive.DonotassignlowercaseUSERCOMMANDstrings.They
willbeconvertedtouppercase.
Thecompletesourceprogram:
REPORTYCL_CH09_SELECTION_SCREEN01
MESSAGEIDYCL_CH07_MCLASS01.
****************************************************
*SLECTIONSCREENCreateSE38LookAlikeScreen**
*PutIcon&TextOnSLECTIONSCREENPushButtons**
*WithoutUsageOfFunctionModule'ICON_CREATE'**
****************************************************
*********************************************************
*generate2blanklines:**
*SELECTIONSCREENSKIP2.**
***
*threeelementsonthesameline:**
*(1)alabel'Program'forfield**
*(2)afield(oftypetextbox)**
*toinputtheprogramname**
*(3)a'Create'pushbutton**
***
*SELECTIONSCREENBEGINOFLINE.**
*SELECTIONSCREENCOMMENT1(20)TEXT001.**
*PARAMETERSPROGRAMTYPETRDIRTNAMEMATCHCODEOBJECT**
*......VISIBLELENGTH30.**
*SELECTIONSCREENPUSHBUTTON53(15)TEXT002**
*USERCOMMANDCREAT.**
*SELECTIONSCREENENDOFLINE.**
***
*agapofonelinei.e.**
*SELECTIONSCREENSKIP1.**
***
*STARTblockwithtitle'Subobjects'&shadedeffect**
*extendingtohalfthescreenwidth:**
***
*SELECTIONSCREENBEGINOFBLOCKBL1WITHFRAME**
*TITLETEXT003NOINTERVALS.**
***
*fiveradiobuttons.eachradiobuttonwith**
*labelonthesameline:**
***
*SELECTIONSCREENBEGINOFLINE.**
*PARAMETERS:SRCERADIOBUTTONGROUPGRP.**
*SELECTIONSCREENCOMMENT2(20)TEXT004.**
*SELECTIONSCREENENDOFLINE.**
*........**
*........**
*agapofonelineafter5radiobuttonsi.e.**
*SELECTIONSCREENSKIP1.**
***
*twopushbuttons('Display'&'Change')onsameline**
***
*SELECTIONSCREENBEGINOFLINE.**
*SELECTIONSCREENPUSHBUTTON1(15)TEXT009...**
*.....**
*......**
*SELECTIONSCREENENDOFLINE.**
***
*SELECTIONSCREENENDOFBLOCKBL1**
***
*********************************************************
SELECTIONSCREENSKIP2."2blanklinesattop
SELECTIONSCREENBEGINOFLINE.
SELECTIONSCREENCOMMENT1(15)TEXT001."label'Program'
PARAMETERSPROGRAMTYPETRDIRTNAMEMATCHCODEOBJECT
YCL_CH09_TRDIRTVISIBLELENGTH30."inputprogramname
SELECTIONSCREENPUSHBUTTON53(15)TEXT002
USERCOMMANDCREAT."pushbutton'Create'
SELECTIONSCREENENDOFLINE.
SELECTIONSCREENSKIP1."ablankline
SELECTIONSCREENBEGINOFBLOCKBL1WITHFRAMETITLE
TEXT003NOINTERVALS."blockBL1commencement
SELECTIONSCREENBEGINOFLINE.
PARAMETERSSRCERADIOBUTTONGROUPGRP."radiobuttonSource
SELECTIONSCREENCOMMENT2(20)TEXT004.
SELECTIONSCREENENDOFLINE.
SELECTIONSCREENBEGINOFLINE.
PARAMETERSVARARADIOBUTTONGROUPGRP."radiobuttonVariants
SELECTIONSCREENCOMMENT2(20)TEXT005.
SELECTIONSCREENENDOFLINE.
SELECTIONSCREENBEGINOFLINE.
PARAMETERSATTRRADIOBUTTONGROUPGRP."radiobuttonAttributes
SELECTIONSCREENCOMMENT2(20)TEXT006.
SELECTIONSCREENENDOFLINE.
SELECTIONSCREENBEGINOFLINE.
PARAMETERSDOCURADIOBUTTONGROUPGRP."radiobuttonDocumentation
SELECTIONSCREENCOMMENT2(20)TEXT007.
SELECTIONSCREENENDOFLINE.
SELECTIONSCREENBEGINOFLINE.
PARAMETERSTXELRADIOBUTTONGROUPGRP."radiobuttonTextelements
SELECTIONSCREENCOMMENT2(20)TEXT008.

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

8/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

SELECTIONSCREENENDOFLINE.
SELECTIONSCREENSKIP1."ablankline
SELECTIONSCREENBEGINOFLINE.
SELECTIONSCREENPUSHBUTTON01(15)TEXT009"@10@Display
USERCOMMANDDISPL."pushbutton'Display'
SELECTIONSCREENPUSHBUTTON19(15)TEXT010"@0Z@Change
USERCOMMANDCHANG."pushbutton'Change'
SELECTIONSCREENENDOFLINE.
SELECTIONSCREENENDOFBLOCKBL1.
*********************************************************
ATSELECTIONSCREEN."triggeredwhenuserinteractswith
"theSelectionScreen
CASESYUCOMM.
WHEN'CREAT'.
MESSAGEI011WITH'Create'.
WHEN'DISPL'.
MESSAGEI011WITH'Display'.
WHEN'CHANG'.
MESSAGEI011WITH'Change'.
ENDCASE.

ThetextsymbolsscreenisshowninFigure93.

Figure93.Program:YCL_CH09_SELECTION_SCREEN01
TextSymbols

YouhaveusedthemessageclasscreatedinChapter7.Youareusinga
singlemessage(messagenumber011)totakecareofthethreesituations
withaplaceholder.Theplaceholderisreceivingthebuttonpressedinfo.
AscreenshotofSE91messagesisshowninFigure94.

Figure94.MessageClass:YCL_CH07_MCLASS01Messages

WhentheprogramYCL_CH09_SELECTION_SCREEN01isexecuted,
thescreenwilllooklikeFigure95.

Figure95.Program:YCL_CH09_SELECTION_SCREEN01
ReproducedSE38Screen

Whenoneoftheselectionscreenpushbuttonisclicked,aninformation
message(popup)willbeissuedlikeFigure96.

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

9/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

Figure96.Program:YCL_CH09_SELECTION_SCREEN01
MessageonButtonClick

WhenF4ispressedonthefieldPROGRAMwithapatternYCL_CH07*
enteredinthefilterdialogbox,thesearchhelpselectionlistwillappear
likeFigure97.

Figure97.Program:YCL_CH09_SELECTION_SCREEN01
SelectionListonFieldPROGRAM

TheoriginalABAPEditoropeningscreenhasbeencreatedusingthe
screenpainter,etc.,whereyouhavealargerdegreeofcontrolthanwhen
creatingscreensthroughselectionscreenstatements.Thatiswhythe
widthoftheshadedarea(blockframe)mightdifferintheoutputofyour
programfromtheoriginalofwhichyouhavetriedtocreateareplica.For
mostpart,thescreenofyourprogramresemblestheSE38ABAPEditor
openingscreen.
TrytorecreatesomeoftheotherABAPWorkbenchscreens:SE11,SE91,
SE32,etc.,togetproficientinlayingtheselectionscreenelements.
Takecarenottooverlapscreenelements.Ifscreenelementsare
overlapped,theABAPruntimewillbeunabletogenerateascreenand
willresultinadumpifyouareexecutinganinactiveversionofthe
program.Ifyouhaveoverlappingscreenelementsandareactivatingthe
program,theABAPruntimewillalertwitherrorwhengenerating
selectionscreen...
Aselectionscreenmusthaveaminimumofoneinputelementforitto
appear.Aselectionscreenconsistingonlyoflabelortext,(COMMENT)
blockswillnotappear.
EventINITIALIZATION,SelectionScreenEventAT
SELECTIONSCREENOUTPUT
ChangingScreenPropertiesEvents
Inscreenprogrammingenvironmentsacommon,basicrequirementis
changingthepropertiesofscreenelementsatruntime.Thiscould
involveenabling/disablingafieldforinputormakingafield
appear/disappear,etc.Intheselectionscreenenvironment,the
propertiescanonlybechangedthroughtheevents:ATSELECTION
SCREENOUTPUTorINITIALIZATION.
TheeventINITIALIZATIONisnotaselectionscreenevent.Itis
triggeredonlyoncewhentheuserpressestheexecutebutton,etc.If
screenattributesneedtobechangedonlyoncebeforethescreenappears
totheuserforthefirsttime,theINITIALIZATIONeventcanbeopted
for.
TheeventATSELECTIONSCREENOUTPUTistriggeredontwo
occasions:
1. Beforetheselectionscreenappearstotheuserforthefirsttime.
Betweentheuserpressingtheexecutebuttonandtheappearance
ofthescreen.AftertheINITIALIZATIONevent.
2. ItsucceedstheeventATSELECTIONSCREEN.Thatis,everytime
theeventATSELECTIONSCREENistriggered,itisfollowedby
thetriggeringoftheeventATSELECTIONSCREENOUTPUT.
Ifscreenattributesneedtobechangedeverytimeauserinteractswith
thescreen(eventATSELECTIONSCREEN),theeventATSELECTION
SCREENOUTPUTcanbeoptedfor.
ChangingScreenPropertiesDataObjectsSCREEN
IntheABAPscreenprogrammingenvironment,theruntimescreen
propertiesaremaintainedbythesysteminaninternaltableofname
SCREEN.Thereisaninternaltableandalsoastructurewiththesame
name:(headerline)SCREEN.
ThestructurefieldsoftheinternaltableSCREENcanbefoundinthe

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

10/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

PDFdocumentABAPProgramming(BCABA)undertheheadingSetting
AttributesDynamically.ThetableinthisPDFdocumentlistsallthe
fieldsoftheinternaltableSCREEN.Alternatively,youcanlocateitin
theABAPonlinedocumentationunderUserDialogs
ABAPStatementsforScreens

Screens

LOOPATSCREEN.(Makeahabitof

visitingtheABAPonlinehelpF1asfrequentlyasyoucan.)Thisinternal
tablewillcontainonerowforeachofthescreenelements.Thefirstfield
inthestructureNAMEcontainsthescreenelementnameasidentifier,
andtherestofthe14(veryfewcomparedtootherplatforms)fieldsarethe
variousattributesofascreenelement.Here,apartiallistofthesefields
ofstructureSCREENisreproduced:
Table91.FewFieldsofInternalTableStructureSCREEN

Field

Type,

Name

Length

NAME

C,30

Description

Nameofthescreenelement.Like
whenyoucreatedaPARAMETER
variableofnamePROGRAM,this
nameofthescreen
element/variablewillbestoredin
thisfield.

GROUP1

C,3

ModificationGroupI(willbe
explainedsubsequentlyinthis
chapter).

INPUT

C,1

Whetherthescreenfieldisenabled
/disabledforinput.Aflagvariable:
assumes1/0values.Bydefaultis
setto1.

OUTPUT

C,1

Whetherthescreenfieldis
displayedornot.Aflagvariable:
assumes1/0values.Bydefaultis
setto1.

INVISIBLE

C,1

Whetherthescreenfieldis
invisible/visible.Aflagvariable:
assumes1/0values.Bydefaultis
setto0.

ACTIVE

C,1

Whetherthescreenfieldisactive
ornot.Aflagvariable:assumes1/0
values.Bydefaultissetto1.

ChangingScreenPropertiesOperationsonDataObjectsSCREEN
Youcanperformlimitedoperationsonthesesystemmaintaineddata
objectsSCREEN.Youcan:
1. SetupLOOPATSCREENENDLOOP.
2. AssignvaluestothedifferentfieldsofthestructureSCREEN.
AssigningvaluestothefieldSCREENNAMEisnotadvisable.
3. PerformMODIFY(updateinternaltable)statementonthe
internaltableSCREEN.
Apartfromthese,youcannotperformanyotheroperationsonthe
internaltableSCREEN.YoucannotperformREAD,INSERT,APPEND,
DELETE,CLEAR,REFRESH,FREE,etc.YoucannothaveLOOPAT
ASSIGNINGENDLOOP.
ThepermittedoperationsontheinternaltableSCREENaresufficientto
beabletochangetheattributesofscreenelements.
LetaverysimpleexercisebeperformedtodemonstratetheeventAT
SELECTIONSCREENOUTPUTalongwiththemanipulationofthe
internaltableSCREENtochangepropertiesofscreenelements.
InthePDFdocumentABAPProgramming(BCABA),undertheheading
SettingAttributesDynamically,thereisatablelistingoutthescreen
behaviorfordifferentvaluesofthescreenattributefieldsACTIVE,
INPUT,OUTPUT,INVISIBLE.BydefaultthefieldsACTIVE,INPUT,
OUTPUTaresetto1andINVISIBLEissetto0.Ifallthefourfields

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

11/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

ACTIVE,INPUT,OUTPUT,INVISIBLEaresetto1,thefieldassumesthe
passwordmodeandenteredvaluesareinvisible.
SoinanABAPprogramwithasingleinputfield,lettheevent
INITIALIZATIONbetriggered.Inthiseventfortheinputfieldscreen
element,letthefieldattributeINVISIBLEbesetto1andusethe
MODIFYstatementtoaltertheinternaltablerow.Thisshouldsetthe
inputfieldtopasswordmode.
Thesourceprogram:

REPORTYCL_CH09_SELECTION_SCREEN02.
***************************************************
*DemoINITIALIZATIONevent,LOOPATSCREENEtc.**
*tochangescreenelementproperties**
***************************************************
SELECTIONSCREENSKIP5.
SELECTIONSCREENBEGINOFLINE.
SELECTIONSCREENCOMMENT1(12)COMMENT1."label
PARAMETERS:PASS_WRD(10)TYPEC."inputfield
SELECTIONSCREENENDOFLINE.
**********************************************
INITIALIZATION.
COMMENT1='Password:'(001)."thisnotationmeansusetextsymbol
"TEXT001ifitexists.ifitdoesnot
"exist,usetheliteraltext
LOOPATSCREEN.
IFSCREENNAME='PASS_WRD'."therearetwoscreenelements
"COMMENT1&PASS_WRD.weareinterested
"tochangepropertiesofPASS_WRDonly
SCREENINVISIBLE='1'.
MODIFYSCREEN.
ENDIF.
ENDLOOP.

AnewnotationhasbeenusedforassignmentoftexttoCOMMENT1:

COMMENT1='Password:'(001).

(SeethecodeintheINITIALIZATIONevent)
Thisnotationmeans,usethetextoftextsymbolid.TEXT001ifitexists.
Ifthetextsymbolid.doesnotexist,usetheliteraltext.Itensuresthata
textisalwaysassignedtoanelement.
Whenyouexecutethisprogram,thescreenwilllooklikeFigure98.

Figure98.Program:YCL_CH09_SELECTION_SCREEN02
Screen

ThiswasademonstrationoftheeventINITIALIZATION.
Whenyouareontheselectionscreenofthiscode,ifyoupress<Enter>
key,theINVISIBLEpropertyofthescreenelementPASS_WRDgets
setto0andtheenteredvaluedinthefieldbecomevisible.The
INVISIBLEpropertyhastobesetto1intheeventATSELECTION
SCREENOUTPUTtoensuretheenteredvaluesinthefieldPASS_WRD
remainsinvisible.Thisisimplementedintheprogram
YCL_CH09_SELECTION_SCREEN02_VR.Theprogramisnotlisted
herebutisavailableintheEResource.
ChangingScreenPropertiesUsingEventATSELECTION
SCREENOUTPUT(ASimplePaymentModeScenario)
AdemonstrationofchangingthescreenattributesusingtheeventAT
SELECTIONSCREENOUTPUTwithascenario:
Scenario
Youwanttorepresentamodeofpaymentontheselectionscreen.The
modeofpaymentscanbeeitherby(a)Cash,(b)Check,or(c)CreditCard.
Thiscanberepresentedonthescreenbythreeradiobuttonswithlabels
likeFigure99.

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

12/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

Figure99.AScreenforModeofPayment

Ifthemodeofpaymentisbycheck,youwantafurtherinputfieldforthe
checknumber.Thechecknumberinputfieldshouldbeenabledforinput
onlyiftheradiobuttoncorrespondingtothemodeofpaymentbycheckis
enabled.Ifthemodeofpaymentbycheckradiobuttonisdisabled,the
inputfieldforchecknumbershouldbedisabled.
Similarly,ifthemodeofpaymentisbycreditcard,youwantafurther
inputfieldforthecreditcardnumber.Thecreditcardnumberinputfield
shouldbeenabledforinputonlyiftheradiobuttoncorrespondingtothe
modeofpaymentbycreditcardisenabled.Ifthemodeofpaymentby
creditcardradiobuttonisdisabled,theinputfieldforcreditcardnumber
shouldbedisabled.
Ifthemodeofpaymentisbycash,boththeinputfieldschecknumberand
creditcardnumbershouldbedisabledforinput.
Sinceyouwanttheselectionscreentointeractwhenradiobuttonsare
clicked,youshouldusetheoptionalreservedphraseUSERCOMMAND
andassign<usercommand>totheradiobuttongroup.
ThescreencouldlooklikeFigure910.

Figure910.ModeofPayment,ProposedScreen

ThepropertiesshouldbechangedintheeventATSELECTIONSCREEN
OUTPUT.Thisisbecausepropertiesneedtobechangedeverytimea
userinteractswiththeselectionscreenbyclickingononeoftheradio
buttons.TheeventINITIALIZATIONwillnothelp.
Sincetheradiobuttongrouphasbeenassigned<usercommand>,
clickingoneoftheminthegroupwilltriggertheeventATSELECTION
SCREEN.Youdontwanttohaveanyaction/codeforthisevent.This
eventissucceededbytheeventATSELECTIONSCREENOUTPUT.You
needtomanipulatethepropertiesoftheselectionscreenelementsinthis
event.Ineffect,thisisamanipulationoftheinternaltableSCREENwith
LOOPATSCREEN.andMODIFYstatements.
Weareinterestedinchangingthepropertiesofonlytwoselectionscreen
elements:thechecknumberandthecreditcardnumber.Youhaveto
enable/disabletheseelementsdependingonthevaluesofthethreeradio
buttonscorrespondingtocash,check,andcreditcard.The
enabling/disablingofinputiscarriedbyassigningvalues1/0tothefield
INPUToftheinternaltableSCREEN.
Ifthecashradiobuttonisenabled,boththefieldschecknumberand
creditcardnumbershouldbedisabledforinput.
Ifthecheckradiobuttonisenabled,thefieldchecknumbershouldbe
enabledforinputandthefieldcreditcardnumbershouldbedisabledfor
input.
Ifthecreditcardradiobuttonisenabled,thefieldcreditcardnumber
shouldbeenabledforinputandthefieldchecknumbershouldbedisabled
forinput.
YourpseudocodeintheselectionscreeneventatSELECTIONSCREEN
OUTPUTshouldlooklike:

LOOPATSCREEN.
IFSCREENNAME<><chequeno>ANDSCREENNAME<><creditcardno>.
CONTINUE."propertiesof<chequeno>,<creditcardno>onlytobechanged
ENDIF.
IF<cashradiobutton>='X'."<cashradiobutton>enabled
SCREENINPUT=0.
<chequeno>=''.
<creditcardno>=''.
ELSEIF<chequeradiobutton>='X'ANDSCREENNAME=<chequeno>.
SCREENINPUT=1.
<creditcardno>=''.
ELSEIF<chequeradiobutton>='X'ANDSCREENNAME=<creditcardno>.

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

13/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

SCREENINPUT=0.
ELSEIF<creditcardradiobutton>='X'ANDSCREENNAME=<creditcardno>.
SCREENINPUT=1.
<chequeno>=''.
ELSEIF<creditcardradiobutton>='X'ANDSCREENNAME=<chequeno>.
SCREENINPUT=0.
ENDIF.
MODIFYSCREEN.
ENDLOOP.

Youarealreadyfamiliarwithselectionscreenlayoutstatements,so
therewillbenoexplanationsofthelayoutstatementshere.Youhave
locatedalltheelementswithinaselectionscreenblocktoenhancethe
screenappearance.
YouhaveassignedexplicitlyDEFAULTXtothecashradiobutton
variableCASH_RB.InSAPR/3earlierversions,ifyoudonotdoso,the
initialappearanceofselectionscreenisnotproper.Atthetimetheevent
ATSELECTIONSCREENOUTPUTistriggeredforthefirsttime,before
thescreenappearstotheuserforthefirsttime,thevaluesofalltheradio
buttonsareindeterminateifnoexplicitDEFAULThasbeenassigned.
TheimplicitDEFAULTXisassignedonlyaftertheeventAT
SELECTIONSCREENOUTPUT.Toensurethattheradiobuttonsdonot
haveindeterminatevaluesatthetimeoffirsttriggeringoftheeventAT
SELECTIONSCREENOUTPUT,youhaveaddedtheDEFAULTXclause
forcashradiobuttonvariableCASH_RB.
Thesourcecode:

REPORTYCL_CH09_SELECTION_SCREEN03.
*********************************************************
*DemoATSELECTIONSCREENOUTPUTToChangeProperties**
*OfScreenElements**
*********************************************************
SELECTIONSCREENSKIP2.
SELECTIONSCREENBEGINOFBLOCKBLK1WITHFRAMETITLE
TEXT001NOINTERVALS.
SELECTIONSCREENBEGINOFLINE.
PARAMETERSCASH_RBRADIOBUTTONGROUPMOPDEFAULT'X'
USERCOMMANDRBCLICK.
SELECTIONSCREENCOMMENT3(20)TEXT002.
SELECTIONSCREENENDOFLINE.
SELECTIONSCREENBEGINOFLINE.
PARAMETERSCHEQ_RBRADIOBUTTONGROUPMOP.
SELECTIONSCREENCOMMENT3(15)TEXT003.
SELECTIONSCREENCOMMENT20(15)TEXT004.
PARAMETERSCHQNO(12)TYPEC.
SELECTIONSCREENENDOFLINE.
SELECTIONSCREENBEGINOFLINE.
PARAMETERSCCRDRADIOBUTTONGROUPMOP.
SELECTIONSCREENCOMMENT3(15)TEXT005.
SELECTIONSCREENCOMMENT20(15)TEXT006.
PARAMETERSCCRDNO(16)TYPEC.
SELECTIONSCREENENDOFLINE.
SELECTIONSCREENENDOFBLOCKBLK1.
******************************************************
ATSELECTIONSCREENOUTPUT.
LOOPATSCREEN.
IFSCREENNAME<>'CHQNO'ANDSCREENNAME<>'CCRDNO'.
CONTINUE."changingpropertiesofonly'CHQNO'&'CCRDNO'
ENDIF.
IFCASH_RB='X'.
SCREENINPUT=0.
MOVE''TOCCRDNO.
MOVE''TOCHQNO.
ELSEIFSCREENNAME='CHQNO'ANDCHEQ_RB='X'.
SCREENINPUT=1.
MOVE''TOCCRDNO.
ELSEIFSCREENNAME='CHQNO'ANDCHEQ_RB=''.
SCREENINPUT=0.
ELSEIFSCREENNAME='CCRDNO'ANDCCRD='X'.
SCREENINPUT=1.
MOVE''TOCHQNO.
ELSEIFSCREENNAME='CCRDNO'ANDCCRD=''.
SCREENINPUT=0.
ENDIF.

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

14/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

MODIFYSCREEN.
ENDLOOP.

ThetextsymbolscreenisshowninFigure911.

Figure911.Program:YCL_CH09_SELECTION_SCREEN03
TextSymbols

Whenthecheck/creditcardradiobuttonsareenabledinturn,thescreens
willlooklikeFigure912and913.

Figure912.Program:YCL_CH09_SELECTION_SCREEN03
RadioButtonCheckEnabled

Figure913.Program:YCL_CH09_SELECTION_SCREEN03
RadioButtonCreditCardEnabled

ThisconcludesthedemonstrationoftheselectionscreeneventAT
SELECTIONSCREENOUTPUT.
SelectionScreenEventATSELECTIONSCREENONVALUE
REQUESTFOR<field>
Wheneveryouwantedtoprovidetheuser,forascreenfield,thefacility
ofmakingaselectionfromapopuplistinsteadofmanuallyenteringa
valueforthefield,youhaveattachedsearchhelptothefield
(MATCHCODEOBJECTetc.).Often,whenyouaredeclaringscreen
fieldsbyreferringtoDDICtablefields,searchhelpshavebeeninherited
fromtheoriginalDDICfields(KNA1KUNNRisonesuchinstance).You
areabletoprovideapopupselectionlistbycreatingfixedvaluesinthe
DDICdomain.(Anoptionyoushouldexerciseonlyifthesevaluesare
few:maximumof2530,andthesevaluesdonotchangeovertime,so
thereisnonecessityformaintenanceofthesevalues.)
YoumustrememberthatsearchhelpsderivetheirlistdatafromtheSAP
database:tablesandviews.TheDDICdomainfixedvaluesarealsopart
oftheSAPdatabase.Ifyouwanttopresenttheuserwithalistwhosedata
isnotderivedfromtheSAPdatabase,obviouslythesearchhelpswillnot
berelevant.AnexampleofpresentingtheuserwithnonSAPdatabase
data:presenttheuserwithadialogboxformakingaselectionofafolder
onpresentationserver.
Theremightbescenarioswhereyouwanttopresenttheuserwithamuch
moresophisticatedfilterdialogboxthansearchhelpscanprovide.You
willwritecomplexsophisticatedcodingtoprovidethesophisticatedfilter
dialogboxes.
Itisinthesecontextsintheselectionscreenenvironment,thatyouwill
triggertheeventATSELECTIONSCREENONVALUEREQUESTFOR
<field>.
Thiseventisdemonstratedtomakeafolderselectionfromthe
presentationserver.Theeventistriggeredforaspecificselectionscreen
field,whichyouindicatefollowingthekeywordFOR.
Youinputafolderfield(PARAMETERSFOLDER(50)TYPEC).
YouaretriggeringtheATSELECTIONSCREENONVALUEREQUEST
FORthescreenfieldFOLDER.
InthetriggeredeventATSELECTIONSCREENONVALUEREQUEST
FORFOLDER,youarecallingthefunctionmodule:
TMP_GUI_BROWSE_FOR_FOLDER.Thisfunctionmodulepresents
theuser(onpressingF4inthefieldFOLDER)withpresentationserver

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

15/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

folderselectiondialogboxandreturnstothecallingprogramthe
selectedfoldername.
Thefunctionmoduleacceptstwooptionalimportparameters:
WINDOW_TITLE
INITIAL_FOLDER
Thefunctionmodulereturnsoneexportparameter:
SELECTED_FOLDER.
Onsuccessfulreturnfromfunctionmodule,(SYSUBRC=0)youare
issuingamessageofwhatfolderwasselected.Youareusingthemessage
number012ofmessageclassYCL_CH07_MCLASS01createdinChapter
7.
Thesourcecodeofprogramtriggering,usingtheevent:ATSELECTION
SCREENONVALUEREQUESTFOR<field>.

REPORTYCL_CH09_SELECTION_SCREEN04.
****************************************************************
*DemoATSELECTIONSCREENONVALUEREQUESTFOR<field>Event**
****************************************************************
SELECTIONSCREENBEGINOFBLOCKBL1WITHFRAMETITLE
TEXT001.
SELECTIONSCREENSKIP2.
PARAMETERSFOLDER(50)TYPEC.
SELECTIONSCREENSKIP2.
SELECTIONSCREENENDOFBLOCKBL1.
************************************************
ATSELECTIONSCREENONVALUEREQUESTFORFOLDER.
CALLFUNCTION'TMP_GUI_BROWSE_FOR_FOLDER'
EXPORTING
WINDOW_TITLE='SelectFolder'
*INITIAL_FOLDER=
IMPORTING
SELECTED_FOLDER=FOLDER
EXCEPTIONS
CNTL_ERROR=1
OTHERS=2
.
IFSYSUBRC<>0.
MESSAGEIDSYMSGIDTYPESYMSGTYNUMBERSYMSGNO
WITHSYMSGV1SYMSGV2SYMSGV3SYMSGV4.
ELSE.
MESSAGES012(YCL_CH07_MCLASS01)WITHFOLDER.
ENDIF.
***********************************

TheinitialselectionscreenwilllooklikeFigure914.

Figure914.Program:YCL_CH09_SELECTION_SCREEN04
InitialSelectionScreen

OnpressingF4intheselectionscreenfieldFOLDER,thescreenwill
appearlikeFigure915.

Figure915.Program:YCL_CH09_SELECTION_SCREEN04
F4onFieldFOLDER

Aftermakingafolderselection,thescreenwilllooklikeFigure916.

Figure916.Program:YCL_CH09_SELECTION_SCREEN04
FolderSelection

ThiswasademonstrationoftheSELECTIONSCREENevent:AT
SELECTIONSCREENOUTPUT.

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

16/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

SelectionScreenEventATSELECTIONSCREENONHELP
REQUESTFOR<field>
TheOriginsofF1HelponaScreenField
WhenyoupressthefunctionkeyF1onanyscreenfieldintheSAP
environment,ascreenorwindowtitledPerformanceAssistantpopsup.
Thisisthedocumentationofthefield.Normally,ascreenfieldintheSAP
environmentisassociatedwithDDICdataelementanddomain.This
documentationisnormallyfetchedfromthedocumentationcreatedin
DDICdataelement.
Toknowthedataelementofascreenfield,pressfunctionkeyF1.The
PerformanceAssistantscreenappears.OnthePerformanceAssistant
screen,clickonthebutton

,andawindowentitledTechnical

Informationappears.Thedataelementofthescreenfieldisavailable
onthisTechnicalInformationwindow.
YouhavedonethisexerciseforthefieldDatabasetableontheSE11
openingscreen.YoupositionedthecursoronthefieldDatabasetableon
theSE11openingscreenandpressedthefunctionkeyF1.The
PerformanceAssistantscreenasshowninFigure917.

Figure917.ScreenPerformanceAssistantOnPressingF1onField
DatabaseTableofSE11OpeningScreen

Clickingthebutton

onthescreenwillmakeTechnical

InformationwindowappearasshowninFigure918.

Figure918.TechnicalInformationofFieldDatabaseTableofSE11
OpeningScreen

ThedataelementforthefieldDatabasetableontheSE11opening
screenisTABNAME16highlightedinFigure918.
IfyouopenthescreenforthedataelementTABNAME16,itwilllook
likeFigure919.

Figure919.DataElement:TABNAME16Goto
Documentation

Onthedataelementscreen,ifyouselectthemenuoption:Goto
Documentation

DisplayasshowninFigure919,youwillhavethe

samescreenasinFigure917,thescreenthatappearedwhenyou
pressedfunctionkeyF1onthefieldDatabasetableoftheSE11opening
screen.Inthedataelement,thereisprovisiontocreatedocumentation.
Thisdocumentationappearsbydefaultwhentheuserpressesthe

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

17/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

functionkeyF1onascreenfieldassignedtothedataelement.
SituationfortheEvent:ATSELECTIONSCREENONHELPREQUEST
FOR<field>
YouwilltriggertheeventATSELECTIONSCRRENONHELP
REQUESTFOR<field>foraspecificselectionscreenfield,whereyoudo
notwantthedefaultdocumentationcreatedindataelementassociated
withthescreenfieldtobedisplayed.Youwantsomealternativetexttobe
displayed.Youwillfetchthetextfromitsoriginandcreatetherequisite
codingtodisplaythecustomtextwhentheuserpressesthefunctionkey
F1onthespecifiedselectionscreenfield.
Thereisnohandsonexerciseforthisevent.Thebasicconcepthasbeen
describedhere.
SelectionScreenEventATSELECTIONSCREENON<field>
Youcanvalidateaselectionscreenfieldandreporterrorofinvalidfield
valuebytriggeringtheeventATSELECTIONSCREENOn<field
name>.Whenreportingtheerror,theselectionscreendisablesallthe
fieldsforinputexceptthefieldwiththeinvalidvalue.Ifvalidationis
beingperformedonmorethanoneselectionscreenfield,thephysical
orderoffieldsontheselectionscreenwilldeterminetheorderoferror
reporting.Atthistime,errorforonlyonefieldwillbereported.On
correctionofthevalueoferrorfield,errorofsubsequentfield/s,ifany,
willbereported.
ThisisbeingdemonstratedwiththeprogramYCL_CH09_SELECTION
SCREEN05.
Inthisprogram,theselectionscreenhasthreefields:NAME1,KUNNR,
andORT01inthisorder(throughthePARAMETERSstatement).Youare
triggeringtheeventATSELECTIONSCREENon<fieldname>forthe
fieldsKUNNRandORT01.YouarecheckingforINITIALvalueinthese
fieldsandissuingerrormessage(messagetypeE).
ThesystemwillissueerrormessageifKUNNRcontainsINITIALvalue.
ThefieldKUNNRwillbeenabledforinput,andtheothertwofields
NAME1andORT01aredisabledforinput.
OnenteringavalueinthefieldKUNNR,withINITIALvalueinthefield
ORT01,theeventATSELECTIONSCREENONORT01willbetriggered.
Anerrormessagewillbeissued,thefieldORT01willbeenabledfor
input,andotherfieldsNAME1andKUNNRwillbedisabledforinput.
Thesourceprogram:
REPORTYCL_CH09_SELECTION_SCREEN05.
*********************************************
*DemoATSELECTIONSCREENON<fieldname>**
*********************************************
********************************************************************
*youaretriggeringtheeventATSELECTIONSCREENON<fieldname>**
*fortwofields:(1)KUNNR(2)ORT01.theeventforORT01is**
*positionedfirstandtheneventforKUNNR.thispositioningof**
*eventsisimmaterial.sinceKUNNRispositionedontheselection**
*first,theeventATSELECTIONSCREENONKUNNRwillbetriggered**
*firstfollowedbytheeventATSELECTIONSCREENONORT01**
***
*whichevervalidatingfirstfieldtriggerserrorwillbe**
*reported.oncorrectionofthisfield'serror,errorof**
*subsequentfieldifanywillbereported.atanytimeonly**
*onefield'serrorwillbereported**
********************************************************************
PARAMETERS:NAME1TYPEKNA1NAME1,
KUNNRTYPEKNA1KUNNR,
ORT01TYPEKNA1ORT01.
*****************************************
ATSELECTIONSCREENONORT01.
IFORT01ISINITIAL.
MESSAGEE013(YCL_CH07_MCLASS01).
ENDIF.
******************************************
ATSELECTIONSCREENONKUNNR.
IFKUNNRISINITIAL.
MESSAGEE013(YCL_CH07_MCLASS01).
ENDIF.

WithINITIALvalueinfieldKUNNR,pressingthe<Enter>keywillhave
thescreenlooklikeFigure920.

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

18/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

Figure920.Program:YCL_CH09_SELECTION_SCREEN05
FieldKUNNRBlank

WithanonblankvaluethefieldKUNNRandINITIALvalueinfield
ORT01,pressingthe<Enter>keywillhavethescreenlooklikeFigure9
21.

Figure921.Program:YCL_CH09_SELECTION_SCREEN05
FieldORT01Blank

ThisprogramiscontrivedtodemonstratetheeventATSELECTION
SCREENon<fieldname>.Thereisasimplerwaytocheckforblank
fields.YoucanusetheadditionclauseOBLIGATORYwiththe
PARAMETERSstatement.(Itisobligatoryormandatorytoentervalues
inthefieldshavingtheadditionclauseOBLIGATORY.)Thesystemwill
checkforINITIALvaluesinthefieldsandreportINITIALvalueerror.
Thesyntax:
PARAMETERS<fieldname>{TYPE|LIKE}{<ABAPelementaryTYPE>|
<TYPEordataobject>}OBLIGATORY.

Example:PARAMETERSKUNNRTYPEKUNNROBLIGATORY.
ButthischeckbytheABAPruntimesystemwillnotdisableotherfieldsfor
inputaftertheerror.Andifyouwantcustommessagetobeissued,you
willoptforthetriggeringofeventATSELECTIONSCREENON<field
name>.Moreover,youconfinedyourselvestovalidatingthefieldsnot
containingINITIALvalues.Validationwouldinreallifeconsistof
checkingagainstasetofvalues(inachecktable,etc.)andmore.Inthe
presentprogram,theobjectivewastohighlightedinasimpleway:the
eventATSELECTIONSCREENON<fieldname>.
TheprogramYCL_CH09_SELECTION_SCREEN05VRdemonstratesthe
additionOBLIGATORY.Theprogramisnotlistedherebutcanbefound
intheEResource.
AnobligatoryormandatoryfieldintheSAPenvironmentissignifiedby
.
SelectionScreenEventATSELECTIONSCREENONBLOCK
<blockname>
Ifontheselectionscreen,youwantvalidationtoapplyonmultiple
fields,youcanlocatethesefieldsinablockandtriggertheeventAT
SELECTIONSCREENONBLOCK<blockname>.
ConsiderthecustomerinfodatabasetableKNB1.Thistablestoresthe
companycodeofcustomers.Ifyoulookuptheprimarykeyfieldsofthis
table,theyareMANDT,KUNNR,andBUKRS.Thesamecustomer
codecanexistformultiplecompanycodes.
IfyouwanttovalidatetheexistenceoffieldvaluesinthetableKNB1,you
havetoprovidethevaluesofthetwoprimarykeyfields:KUNNRand
BUKRS(thefieldMANDTvalueisimplicitlythevalueoftheloggedin
client).
Thehandsonexerciseisdoingexactlythis.Ontheselectionscreen,you
havethetwofieldsKUNNRandBUKRSlocatedinsidetheblockBLK1.
YouaretriggeringtheeventATSELECTIONSCREENONBLOCKBLK1.
Inthisevent,youareusingtheSELECTSINGLEstatementto
ascertainwhetherthecombinationofthetwofieldvaluesenteredonthe
selectionscreenexistsinthedatabasetableKNB1.Incasethe
combinationofselectionscreenfieldvaluesdonotexistinthedatabase
tableKNB1,(SYSUBRC<>0),youareissuinganerrormessage.This
willenableonlythetwofieldsinsidetheblockBLK1forinputallother
fieldsoutsidetheblockontheselectionscreenaredisabledforinput.
YouarereferringtotheDDICstructurefields:RF02DKUNNRand
RF02DBUKRSwhendefiningtheselectionscreenfieldsKUNNRand
BUKRS.ThesearchhelpDEBIisattachedtothestructurefield:
RF02DKUNNR.(RecallthecollectivesearchhelpDEBIyoureviewed
inChapter3.)Thedefinitionofselectionscreenfieldsbyreferencetothe
structureRF02Dfieldsisenablingyoutohaveaselectionpopupliston
theselectionscreenfieldKUNNR.Itisalsoenablingtheexportof
multiplefields[KUNNRandBUKRSforcollectivesearchhelptab
Customers(bycompanycode)]fromthesearchhelptotheselection
screenfields.ForsomereasonthefieldKUNNRinthestructure
RF02DisDDICTYPECHARandlength16,whereasinthedatabase

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

19/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

tablesKNA1andKNB1,thefieldKUNNRisDDICTYPECHARand
length10.ThisisbeingtakencarebeforetheSELECTstatementisissued
intheeventATSELECTIONSCREENONBLOCKBLK1.
Thesourceprogram:
REPORTYCL_CH09_SELECTION_SCREEN06.
***************************************************
*DemoATSELECTIONSCREENONBLOCK<blockname>**
***************************************************
DATA:KEY_KUNNRTYPEKUNNR.
PARAMETERS:NAME1TYPEKNA1NAME1.
SELECTIONSCREENBEGINOFBLOCKBLK1WITHFRAME.
PARAMETERS:KUNNRTYPERF02DKUNNR,"combinationofthesetwofields
BUKRSTYPERF02DBUKRS."checkedforinthetableKNB1
SELECTIONSCREENENDOFBLOCKBLK1.
SELECTIONSCREENBEGINOFBLOCKBLK2WITHFRAME.
PARAMETERS:STRASTYPEKNA1STRAS,
ORT01TYPEKNA1ORT01.
SELECTIONSCREENENDOFBLOCKBLK2.
*****************************************
ATSELECTIONSCREENONBLOCKBLK1.
KEY_KUNNR=KUNNR+6(10)."adjustforKUNNRlengthbeing16
SELECTSINGLEKUNNRBUKRSFROMKNB1INTO(KUNNR,BUKRS)
WHEREKUNNR=KEY_KUNNRANDBUKRS=BUKRS.
IFSYSUBRC<>0.
MESSAGEE014(YCL_CH07_MCLASS01)WITHKUNNRBUKRS.
ENDIF.

WhentheuserpressesF4onthefieldKUNNR,thescreenwillappear
likeFigure922.

Figure922.Program:YCL_CH09_SELECTION_SCREEN06
F4onFieldKUNNR

Onpressing<Enter>keyonthisdialogbox,thescreenwillappearlike
Figure923.

Figure923.Program:YCL_CH09_SELECTION_SCREEN06
F4CustomerList

Aftermakingaselection,(theveryfirsthighlightedentryinthelist
customercode484,companycode3000),thevaluesofcustomercodeand
companycodearetransferredfromlisttothescreenfields.Thescreen
afterselectionwilllooklikeFigure924.

Figure924.Program:YCL_CH09_SELECTION_SCREEN06
SelectionScreenafterMakingSelectionfromList

Ifyoudeliberatelychangetheselectionscreenfieldvaluesastobe
invalidandpress<enter>key,theeventATSELECTIONSCREENON
BLOCKBLK1istriggered,andthevaluesdonotexistinthedatabase
tableKNB1theerrormessageisissuedandonlythefieldswithinthe
blockBLK1areenabledforinput.ThescreenwilllooklikeFigure925.

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

20/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

Figure925.Program:YCL_CH09_SELECTION_SCREEN06
InvalidValuesinBlockFields

ThisconcludesthecoverageofeventATSELECTIONSCREENON
BLOCK<blockname>.
SELECTIONSCREENComplexandMultipleSelections
SELECTOPTIONS
ThePARAMETERSstatementenablesausertoentersinglevalues.On
thebasisofthissinglevalue,youcanintheSELECTstatementusethe
operatorsEQ,NE,GT,LT,GE,andLE(ortheirequivalentmathematical
operators)tofilteroutdata.Ofcourseyoucanhavemultiple
PARAMETERSinputpromptstatements/variablesthatyoucanuseto
filterdatawithSELECTstatement.
Withtheselectionscreenstatement:SELECTOPTIONS,ausercan
makecomplexmultiplevalueselectionsforavariable.
SELECTOPTIONSSyntax
ThesyntaxoftheSELECTOPTIONSstatement

SELECTOPTIONS<variablename>FOR
{<localdataobject>|(<dataobject>)}
[OBLIGATORY]
[VISIBLELENGTH]
[NOINTERVALS]
[NOEXTENSION]
[DEFAULT<defaultvalue>]
[LOWERCASE]
[MATCHCODEOBJECT<searchhelpname>]
[<moreadditionclauses>]...

SELECTOPTIONSKeyphrase.
<variablename>Avariablenamecanbemaximumofeightcharacters,
hastostartwithanalphabetletter,buttherestcanbealphanumericwith
embeddedunderscores(_).
FORKeyword.
<localdataobject>Afieldoranelementarydataobjectdefinedinthe
ABAPprogram.
<dataobject>AfieldoranelementarydataobjectinABAPprogram
(TYPE:C/STRING)thathasbeenassignedthenameofaglobal/DDIC
fieldlikeLFA1LIFNR.This<dataobject>istobeenclosedin
parenthesesaspartofthesyntax.
TheadditionclausesOBLIGATORY,VISIBLELENGTH,DEFAULT,
LOWERCASE,MATCHCODEOBJECT<searchhelpname>havebeen
introducedinthecontextofthePARAMETERSstatementandcarrythe
samemeaninghereexceptDEFAULThassomemoreadditionsor
optionshereandwillbeexplainedinsubsequentTEXT.
TheadditionsNOINTERVALS,NOEXTENSIONwillbeexplained,
alongwith<moreadditionclauses>
LettheSELECTOPTIONSbeelaboratedwithasimpleexample:
SELECTOPTIONSDataobjects
Considerthefollowingcode:
DATA:KUNNRTYPEKUNNR.
SELECTOPTIONS:CUST_CD1FORKUNNR.

WhenaselectionscreenstatementSELECTOPTIONSismadeinthe
mannerasintheprecedingcodelines,thesysteminternallycreatestwo
dataobjectsofthesamenameCUST_CD1:
1. CUST_CD1astructure.
2. CUST_CD1aninternaltablecalledtheselectiontable.
ThestructureCUST_CD1containsthefollowingfourfieldswiththeir
TYPESandlengths:

SIGN(1)TYPEC,"thisfieldcantaketwovalues:
"'I'forinclude
"'E'forexclude
OPTION(2)TYPEC,"thisfieldcantakethefollowingvalues:

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

21/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

"'EQ','NE','GT','GE','LT','LE','CP','NP'&'BT','NB'
LOWLIKEKUNNR,
HIGHLIKEKUNNR.

1. ThefirstfieldSIGNofstructureCUST_CD1isTYPECandlength
1.Itcanassumeonlytwovalues:Iforinclusionofvalues,Efor
exclusionofvalues.
2. ThesecondfieldOPTIONofstructureCUST_CD1isTYPEC,
length2.Itcanassumeavaluefromeitheroneofthetwosetsof
valuesdependingonwhetherthefourthfieldHIGHhasINITIAL
valueorNONINITIALvalue.
IfthefieldHIGHhasINITIALvalue,thesecondfieldOPTION
canassumeoneofthefollowingvalues:
1. EQEqualTo
2. NENotEqualTo
3. GTGreaterThan
4. LTLessThan
5. GEGreaterThanorEqualTo
6. LELessThanorEqualTo
7. CPContainsPattern
8. NPDoesNotContainPattern
IfthefieldHIGHhasNONINITIALvalue,thesecondfield
OPTIONcanassumeoneofthefollowingvalues:
1. BTBetween
2. NBNotBetween
3. ThethirdfieldLOWofstructureCUST_CD1derivesitattributes
fromthefieldordataobjectspecifiedafterthekeywordFOR.In
thepresentexample,youhavespecifiedtheABAPprogram
field/dataobjectKUNNRTheABAPfieldKUNNRhasbeen
declaredreferringtotheDDICdataelementKUNNR.Hence,the
fieldLOWofstructureCUST_CD1hasalltheattributesofthedata
elementKUNNRincludingtheattachedsearchhelpC_KUNNR
(refertodataelementKUNNR,tab:FurtherCharacteristics).
4. LikethethirdfieldLOW,thefourthfieldHIGHofstructure
CUST_CD1derivesitsattributesfromthefieldordataobject
specifiedafterthekeywordFOR.
IfforarowintheselectiontableCUST_CD1,thefieldsLOWand
HIGHhavevalues,itservesasarangeofvalueselection:theLOW
fieldhavingthestartvalueoftherange,theHIGHfieldhavingtheend
valueoftherange.Inthiscase,thefieldHIGHmustcontainvalue
greaterthanorequaltothevalueinthefieldLOW.
IfforarowintheselectiontableCUST_CD1,thefieldLOWhasavalue
andthefieldHIGHhasINITIALvalue,thisservesasasinglevalue
selection.
Havingdescribedthedataobjectaspectoftheselectionscreen
statement:SELECTOPTIONS,lettheselectionscreeninputprompts
andtheassociateddialogboxesaspectbedescribednext.
SELECTOPTIONSScreens,PromptsAndDialogBoxes
Whenthesimplecodelinesintroducedintheprecedinghead:
SELECT_OPTIONSDataObjectsisexecuted,ascreenappearsasin
Figure926.

Figure926.SELECTOPTIONS:CUST_CD1OpeningScreen

ThescreenhasinputpromptsforthefieldsLOWandHIGH.Onthe
extremerightithastheMultipleselectionbutton.Clickingonthis
Multipleselectionbutton,thedialogboxasinFigure927willappear.

Figure927.SELECTOPTIONS:CUST_CD1MultipleSelection
DialogBox,SelectSingleValuestab

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

22/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

Tabs:Themultipleselectiondialogboxhasfourtabs:
1. SelectSingleValues:Ifyouentervalues(onevalueineachrow),
eachvaluewillbeenteredasonerowintheselectiontable
CUST_CD1.ThevaluewillmaptothefieldLOW.ThefieldHIGH
willcontainINITIALvalue.ThefieldSIGNwillassumeavalueI
(Include).ThefieldOPTIONwillassumeadefaultvalueofEQ.If
youwantotherofthevaluessuchasNE,GT,LT,GE,orLEto

beassigned,youhavetoclickonthe

buttonMaintain

SelectOptions(functionkeyF2)tomakeaselection.Youcanuse
theoperatorsCP,NP(containspattern,etc.)ifyouendarowvalue
with*or+.SeeFigure928.

Figure928.SELECTOPTIONS:CUST_CD1Select
SingleValuestab,MaintainSelectOptionsDialogBox

2. SelectIntervals:Ifyouclickonthistab,youcanenterrangeof
values(Figure929).Eachrangeofvalueswillbeenteredasone
rowintheselectiontableCUST_CD1.Thevalueenteredontheleft
sidefieldwillmaptothefieldLOW,thevalueenteredontheright
sidefieldwillmaptothefieldHIGH.ThefieldHIGHonanyrow
shouldcontainavaluegreaterthanorequaltothevalueonthe
correspondingleftsidefield:thatis,LOW.(CUST_CD1HIGHGE
CUST_CD1LOWonanyrow.)ThefieldSIGNwillassumeavalue
I(Include).ThefieldOPTIONwillassumeadefaultvalueofBT
(Between).IfyouwantotherofthevaluessuchasNB(not

between)tobeassigned,youhavetoclickonthe

button

MaintainSelectionOptions(functionkeyF2)tomakeaselection.
SeeFigure930.

Figure929.SELECTOPTIONS:CUST_CD1Multiple
SelectionDialogBox,tabSelectIntervals

Figure930.SELECTOPTIONS:CUST_CD1tabSelect
Intervals,MaintainSelectOptionsDialogBox

3. And4.aresimilarto1.and2.,respectively,exceptthatthefield
SIGNwilltakeavalueofE(Exclude).Forthefirsttwotabsthe
fieldSIGNwillhavevalueIandforthelasttwotabsthefield
SIGNwillhavevalueE.
ButtonsattheBottomoftheDialogBox:Abriefonthe
buttonsatthebottomofthemultipleselectiondialogbox:

1.

Acceptenteredvalues,closethemultipleselection
dialogbox,andgobacktoselectionscreen.

2.

Checkorvalidateenteredvalues(valuesarevalidated.
HIGHLOW,etc.)

3.

MaintainSelectOptions.Youcanselectanoperator
fromalist(EQ,NE).

4.

Insert/Deleterows.

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

23/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

5.

Deleteallvalues.

6.

Help.

7.

Clickingonthebuttonwillbringup
thevalueselection/filterdialogboxofasearchhelp,ifany.

8.

Importvaluesfromatextfileonpresentationserver.

9.

Pastefromclipboard.

10.

Cancel,closethemultipleselectiondialogbox.

ThisisabouttheSELECTOPTIONSinputpromptsanddialog
boxes.
SELECTOPTIONSSelectionTableInWHEREConditionofSELECT
Statement
HowtheSELECTOPTIONSvariableselectiontablesoperateswiththe
SELECTstatementbedescribed.
Lettherebeasimplescenario.Letitbeassumedthatyouarelistingyour
customers:customercode,customername,customercity,etc.,fromthe
databasetableKNA1.Youwilloutputonlythecustomersselectedthrough
thecomplexmultipleselectionsofSELECTOPTIONSCUST_CD1.
Supposeyouwanttolistonlythefollowingindividualandrangeof
customercodes:
Include255
Include260
Include470
Include1001to7000
Include300001to399999
Exclude3201to3300
Ineffect,youhavethreeincludesinglevaluestwoincluderangevalues
andoneexcluderangevalue.Includesinglevalueswillbeenteredinthe
tabSelectSingleValues,andincluderangeofvalueswillbeenteredin
thetabSelectIntervals.Theexcluderangevaluewillbeenteredinthe
tabExcludeIntervals.Thethreetabsofthemultipleselectiondialogbox
withtheenteredvalueswillappearlikeFigure931,932,and933.

Figure931.SELECTOPTIONS:CUST_CD1EnteredInclude
SingleValues

Figure932.SELECTOPTIONS:CUST_CD1EnteredInclude
RangeofValues

Figure933.SELECTOPTIONS:CUST_CD1EnteredExclude
RangeofValues

TherewillatotalofsixrowsintheselectiontableCUST_CD1with
followingfieldvalues:
Table92.ContentsofSelectionTableCUST_CD1asPerEntries
inFigures931,932,and933

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

24/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

TheOpenSQLSELECTstatementtofilteroutcustomercodeswiththe
SELECTOPTIONSselectiontableusingtheINoperatorwillbe:
SELECT<result>fromKNA1INTO<destinationitab>
WHEREKUNNRINCUST_CD1.

ThisOpenSQLstatementimplicitlyoperatestheORlogicbetweenthe
individualCUST_CD1rowcontentswithSIGN=I.TheOpenSQL
statementoperatestheANDNOTlogicbetweentheindividualrow
contentswithSIGN=E.Foryoursetofvalues,itisequivalentto
writing:

SELECT<result>fromKNA1INTOTABLE<destinationitab>
WHERE(KUNNR='0000000255'
ORKUNNR='0000000260'
ORKUNNR='0000000470'
OR(KUNNRBETWEEN'0000001001'AND'0000007000')
OR(KUNNRBETWEEN'0000300001'AND'0000399999'))
ANDNOT(KUNNRBETWEEN'0000003201'AND'0000003300').

Youhavetoprovidetheleadingzeroeswiththeliteralstheliteralsare
notassociatedwiththedomainKUNNRhavingtheconversionroutine
ALPHA,whichautomaticallyinsertsleadingzeroestoinputfields.The
fieldsCUST_CD1LOWandCUST_CD1HIGHareassociatedwiththe
domainKUNNR,andtheconversionroutineALPHAisoperativeon
them.
IngeneraltherowswithSIGN=IandrowswithSIGN=Ewillbe
operateduponasfollows:
1. IfalltherowsoftheselectiontablecontainonlyIintheSIGN
field,thelogicaloperatorORwillbeoperativebetweenthe
individualselectiontablerows.
Example:
Supposeyouwantthefollowingvaluesofcustomercodes:

Include255
Include4001between7000
Include3201notbetween3300

Forthissetofvalues,itisequivalenttowriting:

SELECT<result>fromKNA1INTOTABLE<destinationitab>
WHERE
KUNNR='0000000255'OR(KUNNRBETWEEN'0000004001'AND'0000007000')
OR(KUNNRNOTBETWEEN'0000003201'AND'0000003300').

2. IfalltherowsoftheselectiontablecontainonlyEintheSIGN
field,thelogicaloperatorANDNOTwillbeoperativebetweenthe
individualselectiontablerowsandthelogicaloperatorNOTwill
operateonthefirstrow.
Example:
Supposeyouwantthefollowingvaluesofcustomercodestobe
output:

Exclude1000
Exclude1001between7000

Forthissetofvalues,itisequivalenttowriting:

SELECT<result>fromKNA1INTOTABLE<destinationitab>
WHERE
NOTKUNNR='0000001000'
ANDNOT(KUNNRBETWEEN'0000001001'AND'0000007000').

3. IftherowsoftheselectiontablecontainIandEintheSIGN
field,thelogicaloperatorORwillbeoperativebetweentherows
withSIGN=I,thelogicaloperatorANDNOTbetweentherows
withSIGN=EandthelogicaloperatorANDNOTwilloperate
betweentherowswithSIGN=IandtherowswithSIGN=E.
Example:

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

25/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

Supposeyouwantthefollowingvaluesofcustomercodestobeoutput:

Include255
Include1001between7000
Exclude3001between4000

Forthissetofvalues,itisequivalenttowriting:
SELECT<result>fromKNA1INTOTABLE<destinationitab>
WHERE
(KUNNR='0000000255'ORKUNNRBETWEEN'0000001001'AND'0000007000')
ANDNOT(KUNNRBETWEEN'0000003001'AND'0000004000').

TheprogramYCL_CH09_SELECTION_SCREEN07isnotbeinglisted
here.ItisavailableinEResource.YoucantryoutthevariousSELECT
OPTIONSvalueswiththeSELECTstatementwithselectiontableinthe
WHEREconditionwiththeINoperator.Youcancomparethiswiththe
equivalentSELECTstatementswithlogicaloperatorsandliteralsvalues.
TheprogramYCL_CH09_SELECTION_SCREEN08islisted.Itisa
modifiedversionoftheChapter6programYCL_CH06_ITAB05.You
weresummarizingthesalesdatacustomerwiseforaspecifiedcompany
codeinputthroughthePARAMETERSstatement.Youwereusingthe
COLLECTstatementtogeneratesummarizeddata.Inthepresent
programyouhaveaddedtheSELECTOPTIONSstatementforcustomer
code,sothatyoucanreportthesummarizedcustomerwisesalesfora
specifiedcompanycodeforspecifiedcustomers.Youcancopythetext
symbols(usedinthenonstandardheader)fromtheprogram
YCL_CH06_ITAB05usingtransactioncodeSE32.
Attheverybeginningofthelist,youwilloutputthecontentsofthe
selectiontable.Itservesasarecord,astothegeneratedreportbasedon
whatvaluesintheselectiontable.
Thesource:

REPORTYCL_CH09_SELECTION_SCREEN08NOSTANDARDPAGEHEADING
LINESIZE120LINECOUNT60.
*************************************************
*DemoSELECTOPTIONS:CustomerSalesSummary**
*************************************************
DATA:SALES_TABTYPEYCL_CH06_SALES_SUM_TAB,
SALES_STRULIKELINEOFSALES_TAB,
TOTALTYPEVBRKNETWR,
BUTXTTYPET001BUTXT,
WAERSTYPET001WAERS,
BUTXTSTYPESTRING.
PARAMETERS:CCODETYPEVBRKBUKRSDEFAULT3000VALUECHECK.
SELECTOPTIONSCUST_CD1FORSALES_STRUKUNNR.
"dataobject/fieldafterkeyword
"FORhastobealocaldataobject
********************************************
TOPOFPAGE.
WRITE:/5TEXT001,CCODENOGAP,'/'NOGAP,BUTXTS,102TEXT003,
107(3)SYPAGNO.
WRITE:/40TEXT002,WAERS.
SKIP1.
WRITE:/5(104)SYULINE.
WRITE:/5TEXT004,11TEXT005,23TEXT006,60TEXT007,91(17)
TEXT008RIGHTJUSTIFIED.
WRITE:/5TEXT009,13TEXT010.
WRITE:/5(104)SYULINE.
**********************************************
STARTOFSELECTION.
SELECTSINGLEBUTXTWAERSFROMT001INTO(BUTXT,WAERS)WHERE
BUKRS=CCODE.
BUTXTS=BUTXT.
SELECTKUNNRNAME1ORT01NETWRKURRFFROMYCL_CH05_VBRKKNAINTO
CORRESPONDINGFIELDSOFSALES_STRU
WHEREBUKRS=CCODE
ANDKUNNRINCUST_CD1."INoperatorwithSELECTOPTIONS
"variable
SALES_STRUNETWR=SALES_STRUNETWR*SALES_STRUKURRF.
SALES_STRUKURRF=0."topreventoverflow
COLLECTSALES_STRUINTOSALES_TAB.
ENDSELECT.
SORTSALES_TABBYKUNNR.
LOOPATCUST_CD1.
WRITE:/5(2)SYTABIX,CUST_CD1SIGN,CUST_CD1OPTION,CUST_CD1LOW,
CUST_CD1HIGH.
ENDLOOP.
SKIP4."agapof4linesbetweenCUST_CD1data&
"customerdata.

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

26/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

LOOPATSALES_TABINTOSALES_STRU.
WRITE:/5(4)SYTABIX,SALES_STRUKUNNRUSINGNOEDITMASK,
SALES_STRUNAME1,SALES_STRUORT01,(17)SALES_STRUNETWR.
TOTAL=TOTAL+SALES_STRUNETWR.
ENDLOOP.
SKIP1.
WRITE:/(17)TOTALUNDERSALES_STRUNETWR.

TheoutputwilllooklikeFigures934and935.

Figure934.Program:YCL_CH09_SELECTION_SCREEN08
Output

Figure935.Program:YCL_CH09_SELECTION_SCREEN08
OutputWithTotal

ThethreeaspectsoftheSELECTOPTIONSweredescribed:the
internallycreateddataobjects,(selectiontableandstructure)thescreen
promptsanddialogboxesandtheuseoftheSELECTOPTIONSvariable
intheSELECTstatementwiththeINoperatortofilterdata.The
SELECTOPTIONSdataobjectprovidesasophisticatedmeansoffiltering
databasedonruntimevalues.Thisconcludesthecoverageofthe
SELECTOPTIONS.
ABAPProgramVariants
AnABAPprogrammayhaveanumberofSELECTOPTIONSvariablesas
wellasanumberofPARAMETERSvariablestoentervaluesandfilter
outdatabasedonthesevaluesforoutput.Themultipleselectionvaluesof
SELECTOPTIONSvariablesaswellasthesinglevaluesof
PARAMETERSvariablesmaybefixed.Thatis,thesamesetofvaluesis
beingusedagainandagain(everyweekoreverymonth).Inthis
situation,itcouldbeagoodideatobeabletosaveandretrievethese
valuesbeingusedagainandagain.
ThevariantsfeatureofABAPprogramenablesyoutodothis.Youcan
saveanynumberofsetofvaluesfortheSELECTOPTIONSand
PARAMETERSvariables.Youcanretrieveanyofthestoredsetofvalues
beforeexecutingaprogram.
YoucanstoreasetofSELECTOPTIONSandPARAMETERSvalues
underavariantname.Thenamespaceofavariantisamaximumof14
characters.Avariantnamecancontainspecialcharactersexcept&and
%.Butitisbettertosticktotheconventionofstartingavariantname
withanalphabetletter,andtherestofthecharactersasalphanumeric
withembeddedunderscores.(_)
Thevariantslikethetextelements,etc.,donothaveanindependent
existence.TheyareattachedtoaprogramandarepartofanABAP
program.
YoucancreatevariantsfromtheABAPeditoropeningscreen.Itis
assumedthatyouhavealreadycreatedthesourcecode.EntertheABAP
sourceprogramnameintheprogramfield,selecttheradiobutton
Variants,andclickonthechangebutton.Youarenowcreatingvariants
fortheprogramYCL_CH09_SELECTION_SCREEN07.Theselection
screenofthisprogramconsistsofasingleSELECTOPTIONSvariable
CUST_CD1referringtoalocaldataobjectKUNNR,which,inturn,is
referringtothedataelementKUNNR.Thevariantmaintenancescreen
willlooklikeFigure936.

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

27/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

Figure936.Program:YCL_CH09_SELECTION_SCREEN07
MaintainVariants

EnteravariantnameVAR1,andclickontheCreatebutton.(Ifvariants
alreadyexist,youcanselectfromaselectionlist:F4,etc.).Thefamiliar
SELECTOPTIONSpromptwillappearwithMultipleSelectionbutton
ontheextremeright.ClickontheMultipleSelectionbutton.Enterthe
valuesinthetabs:SelectSingleValues,SelectIntervals,Exclude
SingleValues,andExcludeIntervals.Youenteredthefollowingvalues
fortheselectiontableCUST_CD1:
SelectSingleValues:
250
260
470
SelectIntervals
1001to7000
300001to399999
ExcludeSingleValues
1031
ExcludeIntervals
3201to3300
4001to4500
Clickonthecopybutton(firstbuttonfromtheleft)ofthemultiple
selectiondialogbox.Thescreenafterreturningfromthemultiple
selectiondialogboxwilllooklikeFigure937.

Figure937.Program:YCL_CH09_SELECTION_SCREEN07
CreateVariant:AfterEntryofValues

Thereisonlyonepromptvariable:CUST_CD1ifmoreSELECT
OPTIONSandPARAMETERSstatementsweregivenintheprogram,
morepromptswillappearontheselectionscreen.Youcanentervalues
forasmanyselectionscreenvariablesasyouwant.
Themultipleselectionscreenhasbeenskippednowasyouarealready
familiarwithit,beingexposedtoitintheprevioustopic:SELECTION
SCREENComplexandMultipleSelections:SELECTOPTIONS.
Youcanoptionallyenterattributesforthevariantsbyclickingonthe
attributesbuttonontheapplicationtoolbar.Thevariantsattributes
screenwillbelikeFigure938.

Figure938.Program:YCL_CH09_SELECTION_SCREEN07
CreateVariant:Attributes

YouenteredMeaningorShortText.
Thereareotherattributes:OnlyforBackgroundProcessing,Protect
Variant,andOnlyDisplayinCatalog.
IftheattributeOnlyforBackgroundProcessingcheckboxisenabled,
thevariantisoperativeonlyiftheABAPprogramisruninthe
background.Theverybasicsofabackgroundjobareconveyedinthe
courseofoneoftheforthcominghandsonexercises.Bydefaultavariant
canbeoperativewhenanABAPprogramisruninthebackgroundaswell
asonline/foregroundmode.
IfyouenablethecheckboxfortheattributeProtectVariant,onlythe

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

28/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

userwhocreateditcanchangethevariant.
IfyouenablethecheckboxOnlyDisplayinCatalog,thevariantis
inoperative.Itwillappearonlyinthelist/catalogoftheABAPprograms
variants.Toviewthelist/catalogofanABAPprogramsvariants,inthe
ABAP:VariantsInitialScreen(Figure936),selectthemenuoption:
Variants

Catalog.Youcanmakeacatalogued,inoperativevariant

operativebydisablingthischeckbox.
Theseattributesaretheattributesofallthevariables/objectsofavariant.
InyourprogramYCL_CH09_SELECTION_SCREEN07,youhavea
singleselectionscreenvariable,CUST_CD1.Intheotherprogram
YCL_CH09_SELECTION_SCREEN08,youhavetwoselectionscreen
variables,CCODEandCUSTCD1.Therecananynumberofselection
screenvariables.Thesetofvaluesstoredasavariantwillcoverall
selectionscreenvariables.Thereareattributespertainingtoeach
selectionscreenvariable.YoucanseethisinFigure938underObjects
forselectionscreen.Theseattributesofindividualselectionscreen
variablesarenotdiscussed.
Variantscanbecreatedinoneotherway.Whenyouexecutethe
program,theselectionscreenpromptswillappear.Youcanenterthe
values.SinglevaluesareenteredforPARAMETERSstatement/s,and
singleand/ormultiplevaluesareenteredforSELECTOPTIONS
statement/s.Afterenteringallthedesiredvalues,youcanclickonthe
menuoption:Goto

Variants

SaveAsVariant.Themenuonthe

selectionscreenwilllooklikeFigure939.

Figure939.VariantCreationafterSelectionScreenVariables
Entry

TheclickingonthemenuoptionGoto

Variants

SaveAsVariant

willbringupthevariantattributesscreen.Youcanenterthenameofthe
variantandoptionalMeaning/ShortTextandsave.Theenteredvalues
willbesavedunderthisvariantname.
IfvariantsexistforanABAPprogramandtheprogramisexecuted,the
selectionscreenpromptswillappear.Ontheapplicationtoolbar,theget
variantbuttonwillappear

.IfanABAPprogramhasnovariants,

thisbuttonwillnotappearontheapplicationtoolbar.Youcanretrievea
variant(havethesavedvaluesloadedintotheselectionscreenvariables)
byclickingonthisbutton.Thevariantsoftheprogramwillbelisted.You
canmakeavariantselectionfromthelist.
TheoptionsGet,Display,andDeleteunderthemainmenuoption
GotoareinadisabledstateifvariantsdonotexistforanABAP
program,andinanenabledstateforanABAPprogramhavingvariants.
Variantscanbedeleted,modified,andsavedunderthesameoranother
name.Theycanalsoberenamed.TheycanbecopiedinthesameABAP
programtoanothername.Theycanbetransported.(Packageshouldnot
be$TMP/local.)AllthesefacilitiesareavailableontheABAP:Variants
InitialScreen.SeeFigure936.
Tocopyvariantsfromoneprogramtoanother,youcanusethefunction
module:RS_COPY_SELECTION_SETS.Thisfunctionmodulecopiesall
variantsfromasourceABAPprogramtoadestinationABAPprogram.
Youcannotcopyspecificvariantsfromoneprogramtoanotherlikeyou
candowithtextelementswithtransactioncodeSE32.
SELECTOPTIONSAdditionsNOINTERVALS,NO
EXTENSION
YoucangivetheadditionsNOINTERVALSandNOEXTENSIONwith
theSELECTOPTIONSstatement.Youhaveseentheeffectofthephrase
NOINTERVALSalongwiththeadditionWITHFRAMEinthecontextof
ablockontheselectionscreen.Itcreatedashadedareathatextended
onlytohalfthescreenwidthwiththeadditionNOINTERVALS.
Inthefollowinghandsonexercise,youobservetheeffectoftheNO
INTERVALSinthecontextoftheSELECTOPTIONSstatement.Withthis
additionontheselectionscreen,onlytheLOWfieldwillappear.The
HIGHfieldwillnotappearontheselectionscreen.Themultiple
selectionbuttonappearsontheextremeright.Multipleselectionsare
available.SeeFigure940.

Figure940.Program:YCL_CH09_SELECTION_SCREEN09
NOINTERVALS,NOEXTENSION

WiththeadditionNOEXTENSIONtotheSELECTOPTIONSstatement,
themultipleselectionbuttondisappears,andmultipleselectionsarenot
available.Youcanthenentereitherasinglevalueoronerangeof
values.
WiththeadditionsNOINTERVALSandNOEXTENSION,theHIGH
fieldwillnotappearontheselectionscreen,andthemultipleselection

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

29/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

buttondisappears.Youcanenteronlyonesinglevalue.
InthefollowingABAPsourceprogram,fourSELECTOPTIONS
statementshavebeenissued:
1. SELECTOPTIONSstatementwithoutanyadditionalclause
2. SELECTOPTIONSstatementwiththeadditionclauseNO
INTERVALS
3. SELECTOPTIONSstatementwiththeadditionclauseNO
EXTENSION
4. SELECTOPTIONSstatementwithadditionclausesNO
INTERVALSandNOEXTENSION
UntilnowyouhaveissuedaSELECTOPTIONSstatementbyreference
toanABAPlocaldataobject(avariablenamefollowingthekeyword
FOR)InthefollowingABAPprogram,youhaveissuedaSELECT
OPTIONSstatementbyreferencetoaDDICtablefield.Thenameofthe
DDICtablefield(KNA1KUNNR)hasbeenstoredinalocaldataobject.
(STRNG)WhenissuingtheSELECTOPTIONSstatement,thislocaldata
objectcontainingtheDDICtablefieldnameisgivenwithinparenthesis
(avariablenamefollowingthekeywordFOR).Thisisthewaytoissuea
SELECTOPTIONSstatementreferringtoDDICtable/structurefield.
Thesourceprogram:

REPORTYCL_CH09_SELECTION_SCREEN09.
*************************************************
*SELECTOPTIONS:NOINTERVALS,NOEXTENSION**
*SELECTOPTIONSDeclarationByReferenceTo**
*DDICFieldStoredInAnInternalDataObject**
*************************************************
DATA:STRNGTYPESTRINGVALUE'KNA1KUNNR'.
SELECTOPTIONS:CUST_CD1FOR(STRNG),"referencetoDDICfield/notlocalfield
CUST_CD2FOR(STRNG)NOINTERVALS,
CUST_CD3FOR(STRNG)NOEXTENSION,
CUST_CD4FOR(STRNG)NOINTERVALSNOEXTENSION.

Whenthisprogramisexecuted,thescreenwilllooklikethis:
CodinganABAPProgramtoBeAbletoRunItinBackground
BackgroundJobs
Untilnow,youhavebeenrunningandtestingyourABAPprogramsin
theonlineorforegroundmode.Youwillcontinuetodoso:testandrun
yourprogramsintheonlineorforegroundmode.
InSAPrealtimeenvironment,mostreportingoroutputjobsarerunin
background.MostERPsoftwarehasthefeatureofbackgroundjobs.A
backgroundjobisatopicinitself.Thisisnottheplacetocover
backgroundjobsasatopic.Averybasicideaofbackgroundjobsis
described.
Backgroundjobsarecharacterizedbytheabsenceofuserinteractionand
interventionduringitsexecution(responsetimesarenotrelevantand
uncritical).Theoutputofabackgroundjobisnotlistedontothescreen
butsenttotheprinterspoolfileonthedisk.Inasubsequentprocessof
despooling,thespoolfilesonthediskaredumpedontotheprinters
attachedtoapplicationservers.
Therearemanyotherfacilitiesinbackgroundjobs.Onespecificfacility
istheabilitytoschedulejobs.Schedulingcanbeonthebasisofspecific
dateandtime.Backgroundjobscanalsobescheduledonaperiodical
basis,triggeringeveryfirstworkingdayofaweek,month,etc.
ANewVersionoftheProgramYCL_CH09_SELECTION_SCREEN08
EnablingittoRunintheBackground
Scenario:
Letitbeassumedthatanewversionofyourprogram
YCL_CH09_SELECTION_SCREEN08(customerwisesalessummaryfor
aspecifiedcompanycodeandspecificcustomercodesinputthrough
PARAMETERSandSELECTOPTIONSstatements)needstoberunin
thebackground.Thefirstrequirementofabackgroundjobistheabsence
ofuserinteraction.Youcannothavetheinputpromptswaitingforthe
endusertoinputvalues(i.e.,noPARAMETERS,SELECTOPTIONS
statements).Thenewversionofprogram
YCL_CH09_SELECTION_SCREEN08shouldnothaveanyselection
screen.But,itshouldstillhavethefacilitytofilterdataofaspecific
companycodeandspecificcustomercodes(filterandselectionvalues).
Theprogramhastobefedthefilter,selectionvaluessomeotherwaythan
throughaselectionscreen.RecallthedataobjectaspectoftheSELECT
OPTIONSstatement(i.e.,theselectiontablewithitsfourfields:SIGN,
OPTION,LOW,andHIGH).

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

30/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

DeclaringanInternalTableHavingStructureofSelectionTable
Inyournewversionoftheprogram
YCL_CH09_SELECTION_SCREEN08,youcanhaveaninternaltable
declaredwithadatadeclarativestatementhavingthestructurelikethe
selectiontable.Youcanhavethisinternaltablehavingthestructureofa
selectiontablefilledwiththerequisitefiltervaluesfromthevariantof
anotherABAPprogram.YoucanthenusethisinternaltablewiththeIN
operatorintheSELECTstatementtofilterdata.Therestofthenew
versionofprogramcanremainthesameastheoriginal
YCL_CH09_SELECTION_SCREEN08.
Youcandeclareaninternaltablehavingthestructureofselectiontable
fortheDDICfieldKNA1KUNNRinthefollowingmanner:

TYPES:BEGINOFSEL_TABLE_TP,
SIGN(1)TYPEC,
OPTION(2)TYPEC,
LOWTYPEKNA1KUNNR,
HIGHTYPEKNA1KUNNR,
ENDOFSEL_TABLE_TP.
DATA:CUST_CDTYPESTANDARDTABLEOFSEL_TABLE_TP
WITHHEADERLINE.

ABAPlanguageprovidesfordeclarationofinternaltablehaving
structureofselectiontableinasimplerwaywiththefollowingsyntax:

DATA:<itabname>TYPE|LIKERANGEOF<field>[WITHHEADERLINE].

<itabname>Nameoftheinternaltabledataobject
RANGEOFKeyphrasetodeclareaninternaltablehavingstructureof
selectiontable
<field>Anylocal/globalelementarydataobject,anyelementaryfield
declaredlocallywithTYPESstatementoringlobalTypeGroups.The
attributesofthefieldsLOWandHIGHarederivedfromthis<field>.
So,theprecedingdeclarationissimplifiedto:
DATA:CUST_CDTYPERANGEOFKNA1KUNNRWITHHEADERLINE.

Fillingtheinternaltablehavingthestructureofselectiontable
withrequiredfiltervalues
LetanABAPprogramyouwanttoruninthebackground(newversionof
program:YCL_CH09_SELECTION_SCREEN08)bedesignatedas
ProgramA.ThisProgramAneedstoretrievevariantvaluesfrom
anotherABAPprogramandloadthevariantvaluesintotheinternal
tablewiththestructureoftheselectiontable.LetthisABAPprogramwith
variantsbedesignatedasProgramB.TheProgramBhastheselection
screenwiththePARAMETERSandSELECTOPTIONSstatement.You
willmaintainvariantsinProgramBrunninginonline/foreground
mode.ThevariantsinProgramBcanmodifiedbeforeProgramAis
submittedforexecutionortriggeredinthebackground.Usingafunction
moduleyoucanretrievethevariantvaluesofProgramBandloadthem
intotheinternaltablehavingstructureofselectiontableinProgramA.
Thefunctionmoduletoretrievevariantsis
RS_VARIANT_VALUES_TECH_DATA.Ittakestwoimportparameters:
thenameoftheABAPprogramandthenameofthevariant.Itreturns
variantvaluesinaninternaltablehavingastructureliketheDDIC
structureRSPARMS.TheDDICstructureRSPARMShasthefollowing
fields:
Table93.DDICStructureRSPARMSFields

Field

Data

Name

Type&

Description

Length

SELNAME

CHAR

NameoftheSELECTIONSCREEN

/8

dataobject/variable:i.e.,
PARAMETERS/SELECT
OPTIONSvariablename

KIND

CHAR

KindofSELECTIONSCREEN

/1

variable:
SforSELECTOPTIONS
PforPARAMETERS

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

31/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

SIGN

CHAR

Iforinclude,Eforexclude

/1

OPTION

LOW

CHAR

EQ,NE,GT,LT,GE,LE,CP,

/2

NP,BT,NB

CHAR

Startvalueofrange

/45

HIGH

CHAR

Endvalueofrange

/45

AfterthefunctionmoduleRS_VARIANT_VALUES_TECH_DATAhas
retrievedthevariantvaluesintoaninternaltableofstructure
RSPARMS,youcansetupLOOPENDLOOPofthisinternaltableand
buildyourselectiontablelikeaninternaltable.
ThevariantstoragesystemstoresthevaluesinthefieldsLOWand
HIGHwithouttheleadingzeroes.Youareinsertingleadingzeroes
usingtheconversionroutineCONVERSION_EXIT_ALPHA_INPUT
(canbeusedforvariablesoflength10only).
Programthatcanberuninbackground
InyourcaseyouhavechosentheABAPprogram
YCL_CH09_SELECTIONSCREEN08asProgramB(theprogram
wherevariantvaluesaretoberetrieved).YourProgramAis
YCL_CH09_SELECTION_SCREEN10(theprogramthatcanberunin
thebackground).
TheProgramAsource:
REPORTYCL_CH09_SELECTION_SCREEN10NOSTANDARDPAGEHEADING
LINESIZE120LINECOUNT60.
******************************************************
*UseF.M.RS_VARIANT_VALUES_TECH_DATAToRetrieve**
*VariantValuesIntoInternalDataObject**
*UseInternalDataObjectInSELECTStatementTo**
*FilterData.**
*ProgramSubmitableINBACKGROUND**
******************************************************
*********************************************************
*I.declareselectiontablelikedataobjectwithout**
*usingselectionscreenstatementSELECTOPTIONS**
***
*youcandeclareaninternaltabledataobjectlike**
*theselectiontableinternaltablehavingthe**
*fourfields:SIGN,OPTION,LOW,HIGHusingthe**
*DATAstatementwiththekeyphraseRANGEOF..**
***
*DATA:CUST_CDTYPERANGEOFKNA1KUNNR.**
***
***
*II.retrievevariantvaluesintointernaltable**
***
*thevariantsarestoredintheDDICstructureform**
*RSPARAMS.thefieldswithTYPES,lengthsofDDIC**
*structureRSPARAMS:**
***
*SELNAME(8)TYPECselectionscreenvariablename**
*KIND(1)TYPEC'S'forSELECTOPTIONSvariable**
*'P'forPARAMETERSvariable**
*SIGN(1)TYPEC**
*OPTION(2)TYPEC**
*LOW(45)TYPEC**
*HIGH(45)TYPEC**
***
*thisisthewaythevariantdataisstored.(source)**
*itisretrievedintotheprogramdeclaredinternal**
*tableVAR_VALUESusingthefunctionmodule:**
*RS_VARIANT_VALUES_TECH_DATA.thisfunctionmodule**
*takestwoimportparametersi.e.programnameand**
*variantname.itreturnsthevariantvaluesinthe**
*internaltableofstructureRSPARAMS.**
***
*yourimportparameterstothefunctionmodule:**
*programname:YCL_CH08_SELECTION_SCREEN08**
*variantname:VARIANT_I**
***
*thevariantvalueswillberetrievedfortwo**
*selectionscreenvariablesdefined/declaredin**
*programYCL_CH09_SELECTION_SCREEN08:**
*(1)CCODE:thruPARAMETERSforcompanycode**
*(2)CUST_CD1:thruSELECTOPTIONSforcustomercode**
***
*III.transfervariantvaluesfrominternaltable**
*VAR_VALUESintoselectiontableCUST_CDdeclared**
*withTYPERANGEOF..etc.andCCODE.**
***
*setupLOOPATVAR_VALUES.**
***

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

32/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

*checkVAR_VALUESSELNAME='CUST_CD1'and**
*VAR_VALUESKIND='S'**
***
*thenuseMOVECORRESPONDINGtomovedatafrom**
*structureVAR_VALUEStostructureCUST_CD.**
*variantvaluesarenotsaved/storedwithleading**
*zeroes.useconversionexitroutine**
*'CONVERSION_EXIT_ALPHA_INPUT'toinsertleading**
*zeroestoCUST_CDLOW,CUST_CDHIGHfields.**
*APPENDtoselectiontablelikeinternaltable**
*CUST_CD.**
***
*checkifVAR_VALUESSELNAME='CCODE'and**
*KIND='P'thenCCODE=VAR_VALUESLOW.**
***
*ENDLOOP.**
***
***
*IV.usethevariablesCCODEandCUST_CDinthe**
*SELECTstatementtofilterdataaspervariant**
*values**
***
*restofprogramsameasYCL_CH09_SELECTION_SCREEN08**
*********************************************************
DATA:SALES_TABTYPEYCL_CH06_SALES_SUM_TAB,
SALES_STRULIKELINEOFSALES_TAB,
TOTALTYPEVBRKNETWR,
BUTXTTYPET001BUTXT,
WAERSTYPET001WAERS,
BUTXTSTYPESTRING,
CCODETYPEVBRKBUKRS,
CUST_CDTYPERANGEOFKNA1KUNNRWITHHEADERLINE,
"createinternaltableofstruSIGN,OPTION,LOW,HIGH
VAR_VALUESTYPESTANDARDTABLEOFRSPARAMSWITHHEADERLINE.
"functionmoduleformalparameterVARIANT_VALUES
"isTYPERSPARAMS
****************************************************************************
TOPOFPAGE.
WRITE:/5TEXT001,CCODENOGAP,'/'NOGAP,BUTXTS,102TEXT003,
107(3)SYPAGNO.
WRITE:/40TEXT002,WAERS.
SKIP1.
WRITE:/5(104)SYULINE.
WRITE:/5TEXT004,11TEXT005,23TEXT006,60TEXT007,91(17)
TEXT008RIGHTJUSTIFIED.
WRITE:/5TEXT009,13TEXT010.
WRITE:/5(104)SYULINE.
****************************************************************************
STARTOFSELECTION.
CALLFUNCTION'RS_VARIANT_VALUES_TECH_DATA'
EXPORTING
REPORT='YCL_CH09_SELECTION_SCREEN08'
VARIANT='VARIANT_I'
*SEL_TEXT=''
*MOVE_OR_WRITE='W'
*SORTED=''
*EXECUTE_DIRECT=
*IMPORTING
*TECHN_DATA=
TABLES
VARIANT_VALUES=VAR_VALUES[]
*VARIANT_TEXT=
EXCEPTIONS
VARIANT_NON_EXISTENT=1
VARIANT_OBSOLETE=2
OTHERS=3
.
IFSYSUBRC<>0.
MESSAGEIDSYMSGIDTYPESYMSGTYNUMBERSYMSGNOWITHSYMSGV1SYMSGV2
SYMSGV3SYMSGV4.
EXIT.
ENDIF.
*************************
LOOPATVAR_VALUES.
IFVAR_VALUESSELNAME='CUST_CD1'ANDVAR_VALUESKIND='S'.
"='S'SELECTOPTIONSvariable
MOVECORRESPONDINGVAR_VALUESTOCUST_CD."MOVEtoselectiontablestru
CALLFUNCTION'CONVERSION_EXIT_ALPHA_INPUT'"insertleadingzeroesinto
"CUST_CDLOW
EXPORTING
INPUT=CUST_CDLOW
IMPORTING
OUTPUT=CUST_CDLOW
.
CALLFUNCTION'CONVERSION_EXIT_ALPHA_INPUT'"insertleadingzeroesinto
"CUST_CDHIGH
EXPORTING
INPUT=CUST_CDHIGH
IMPORTING
OUTPUT=CUST_CDHIGH
.
APPENDCUST_CD.
ELSEIFVAR_VALUESSELNAME='CCODE'ANDVAR_VALUESKIND='P'.
"='P'PARAMETERSvariable
CCODE=VAR_VALUESLOW.
ENDIF.
ENDLOOP.

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

33/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

************************************
SELECTSINGLEBUTXTWAERSFROMT001INTO(BUTXT,WAERS)WHERE
BUKRS=CCODE.
BUTXTS=BUTXT.
SELECTKUNNRNAME1ORT01NETWRKURRFFROMYCL_CH05_VBRKKNAINTO
CORRESPONDINGFIELDSOFSALES_STRU
WHEREBUKRS=CCODE
ANDKUNNRINCUST_CD."INoperatorwithselectiontable
"typevariable
SALES_STRUNETWR=SALES_STRUNETWR*SALES_STRUKURRF.
SALES_STRUKURRF=0."topreventoverflow
COLLECTSALES_STRUINTOSALES_TAB.
ENDSELECT.
SORTSALES_TABBYKUNNR.
LOOPATCUST_CD."outputselectiontable
WRITE:/5(2)SYTABIX,CUST_CDSIGN,CUST_CDOPTION,CUST_CDLOW,
CUST_CDHIGH.
ENDLOOP.
SKIP4."agapof4linesbetweenCUST_CDdata&
"customerdata.
LOOPATSALES_TABINTOSALES_STRU.
WRITE:/5(4)SYTABIX,SALES_STRUKUNNRUSINGNOEDITMASK,
SALES_STRUNAME1,SALES_STRUORT01,(17)SALES_STRUNETWR.
TOTAL=TOTAL+SALES_STRUNETWR.
ENDLOOP.
SKIP1.
WRITE:/(17)TOTALUNDERSALES_STRUNETWR.

Youareexecutingtheprogramintheoline/foregroundmodeonlyto
demonstratetheresults(listonscreen).
TheoutputwillappearlikeFigure941and942.

Figure941.Program:YCL_CH09_SELECTION_SCREEN10
Output

Figure942.Program:YCL_CH09_SELECTION_SCREEN10
Output

Theoutputisidenticaltotheoutputofprogram
YCL_CH09_SELECTION_SCREEN08,butthisprogramhavingno
selectionscreencanberuninthebackground.
SELECTOPTIONSMiscellanea
SELECTOPTIONSEvents
TherearetwoeventsrelatedtoSELECTOPTIONSstatement:
1. ATSELECTIONSCREENON<selectoptionvariable>
ThisisofthesamecategoryastheATSELECTIONSCREENON
<parametersvariable>insomeaspectsbecauseoftheSELECT
OPTIONSvariablebeingcomplex.Itistriggeredinthefollowing
contexts:
1. Whenthe<Enter>key,executebutton/F8etc.(screen
processingisover)ispressedontheselectionscreen.
2. Whenthemultipleselectionbuttonispressedonthe
selectionscreen.
3. Ifvalueshavebeenenteredinmultipleselectiondialog
box/window,thiseventistriggeredforallbuttonsexceptfor
thefollowingbuttons:

2. ATSELECTIONSCREENONENDOF<selectoptionvariable>
Thiseventistriggeredwhenyoupressanyofthebuttonsatthebottomof
multipleselectiondialogbox/windowexceptthebuttons:

YoucantriggertheeventsATSELECTIONSCREENONVALUE
REQUESTFOR<field>andATSELECTIONSCREENONHELP
REQUESTforSELECTOPTIONSLOWandHIGHvariableslike:

DATA:KUNNRTYPEKUNNR.
SELECTOPTIONSCUST_CDFORKUNNR.

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

34/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

........
ATSELECTIONSCREENONVALUEREQUESTFORCUST_CDLOW.
......
.......
ATSELECTIONSCREENONVALUEREQUESTFORCUST_CDHIGH.
.....
......
ATSELECTIONSCREENONHELPREQUESTFORCUST_CDHIGH.
.....

SELECTOPTIONSwithDEFAULTAddition
YoucanusetheDEFAULTclausewiththeSELECTOPTIONSstatement
thewayyouuseditwiththePARAMETERSstatementtoassignastarting
valuetothevariable.WiththeSELECTOPTIONSvariablebeinga
complexvariable,someadditionsgowiththeDEFAULTclause.The
syntax:

SELECTOPTIONS<variable>FOR<field>DEFAULT<lowvalue>
[TO<highvalue>][SIGN<signvalue>][OPTION<optionvalue>].

<signvalue>CanbeeitherIorE(shouldnotbeenclosedwithinsingle
quotes)
Bydefault,<signvalue>willassumeIvalue
<optionvalue>CanbeEQ,NE,GT,LT,GE,LE,BT,NB,CP,NP
(Shouldnotbeenclosedwithinsinglequotes)
Bydefault,<optionvalue>willassumevalueEQifthereisno<high
value>
Bydefault,<optionvalue>willassumevalueBTifthereisa<high
value>
Example:

DATA:KUNNRTYPEKUNNR.
SELECTOPTIONSCUST_CDFORKUNNRDEFAULT1TO1000SIGNEOPTIONBT.

SELECTOPTIONSOtherAdditions
ThefollowingadditionsyouusedwithPARAMETERSstatementalso
applytoSELECTOPTIONSstatement.
OBLIGATORY(mandatoryinput)
VISIBLELENGTH<lengthincolumns>(reducethevisiblelength
ofscreenelement)
LOWERCASE(inputwithcasesensitivity)
MATCHCODEOBJECT<searchhelpname>(attachsearchhelp)
NODISPLAY(makeselementdisappear,setspropertyINVISIBLE
=1.CanberesetintheATSELECTIONSCREENOUTPUTevent:
i.e.,setpropertySCREENINVISIBLE=0)
SelectionTexts
WhenyouissuePARAMETERS/SELECTOPTIONSstatementswithout
COMMENTS,withoutlocatinganyotherscreenelementsonthesame
line,theABAPruntimesystemusesthenameoftheselectionscreen
variableasalabelortext.
Example:

PARAMETERS:CUST_CDTYPEKNA1KUNNR.

Theselectionscreenforthisstatement:

Figure943.VariableNameasLabelorText

IfyouissuePARAMETERS/SELECTOPTIONSstatementswithout
COMMENTSandlocateotherscreenelementsonthesameline,the
ABAPruntimesystemassignsblanklabelortext.
Example:

SELECTIONSCREENBEGINOFLINE.
PARAMETERS:CUST_CD1TYPEKNA1KUNNR.
SELECTIONSCREENPUSHBUTTON25(15)BUTTON1USERCOMMANDABC.
SELECTIONSCREENENDOFLINE.
**********************************
INITIALIZATION.
BUTTON1='ButtonI'.

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

35/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

TheselectionscreenforthestatementsisshowninFigure944.

Figure944.BlankLabelorText

ThereisanotherwayofassigninglabelortexttothePARAMETERS/
SELECTOPTIONSvariables.ThisisthroughtheSelectiontexts
componentofABAPprogramTextelements.Youhavealreadyusedtwo
oftheTextelementscomponents:ListHeading(standardheaders)and
theTextsymbols.
ForeachPARAMETERS/SELECTOPTIONSstatement,theSelection
textscreatesarow/entrywithablanklabel.
Considerthesourcelinesoftheprogram
YCL_CH09_SELECTION_SCREEN11:

REPORTYCL_CH09_SELECTION_SCREEN11.
********************
*SelectionTexts**
********************
PARAMETERS:CUST_CD1TYPEKNA1KUNNR."nameofvariablewillappear
"aslabelbydefault
SELECTIONSCREENSKIP2.
SELECTIONSCREENBEGINOFLINE.
PARAMETERS:CUST_CD2TYPEKNA1KUNNR."blanklabelbydefault
SELECTIONSCREENENDOFLINE.
SELECTIONSCREENSKIP2.
PARAMETERS:CUST_CD3TYPEKNA1KUNNR."labelfromselectiontext
"selectiontextfromdataelement
"label

Inthisprogram,whenyouopentheSelectiontextstaboftextelement
screen,thescreenwillappearlikeFigure945.

Figure945.ProgramYCL_CH09_SELECTIONSCREEN11
SelectiontextsScreen:Initially

Youcanenterselectiontextsforvariables.Theselectiontextsentered
forthevariableswillappearaslabelortextontheselectionscreen.If
youenablecheckboxontheextremerightandsave,itwillfetchtextfrom
thedataelementassociatedwiththefield.(Inyourpresentprogram,the
dataelementisKUNNR.)ItfetchestheMediumfieldlabel.Recallthat
inthedataelement,fieldlabelsareShort,Medium,Long,and
Heading.
ThescreenwiththeMediumfieldlabeltextfetchedfromdataelement
willlooklikeFigure946.

Figure946.ProgramYCL_CH09_SELECTION_SCREEN11
SelectiontextsScreen:LabelsorTextsfromDataElement

Theselectionscreenoftheprogram
YCL_CH09_SELECTION_SCREEN11nowwillbelike947.

Figure947.Program:YCL_CH09_SELECTION_SCREEN11
SelectionScreen

Whenusingselectiontexts,youmustrememberthatyoucannot
control/formattheline(SELECTIONSCREENBEGINOFLINE,etc.).
Thereisafunctionmodule:MG_FIELDNAME_TEXT
retrievestheshort,medium,long,andheadingtextsfromdataelement.
Thefunctionmodulehastwoimportparameters:DDICtable/structure
nameandfieldname.Thefunctionmodulereturnstextsintheloggedin
language.Italsoreturnsshorttextofthedataelement.Youcanretrieve
thedataelementtextsforDDICfieldsinthismanneranduseitaslabel
ontheselectionscreen.Thisisdemonstratedinprogram:
YCL_CH09_SELECTION_SCREEN13.Theprogramisnotlistedhere.It
isavailableintheEResource.
SELECTIONSCREENMiscellanea
CheckBoxonaSelectionScreen
Youcanlocateacheckboxonselectionscreenwiththefollowingsyntax
ofPARAMETERSstatement:

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

36/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

PARAMETERS:<variablename>[{TYPEC|TYPE<dataelement>}]
ASCHECKBOX[USERCOMMAND<usercommand>][DEFAULTX].

<variablename>TheusualnamingrulesforPARAMETERSvariables
apply.Thelengthofthevariableshouldnotbespecified[like
PARAMETERS:VAR(2)].Thelengthofcheckboxvariableisfixedas1.
TheTYPEisimplicitlyCandcanbespecifiedexplicitlyasTYPEConly.
Thecheckboxvariableassumesonlytwovalues:Xwhenthecheckbox
isenabledandwhenthecheckboxisdisabled.
<dataelement>Thisdataelementshouldhavebeenassignedadomain
wheretheDataTypeisCHARandlengthis1.Furtherinthefixed
valuesofthisdomain,therecanbetworowsofvalues:Xand.
ASCHECKBOXKeyphrasetodefineacheckbox.Thiskeyphrasecan
beomittedwhenyouarereferringtoadataelementthathasbeen
assignedadomainwheretheDataTypeisCHARandlengthis1.
Furtherinthefixedvaluesofthisdomain,thereshouldbetworowsof
values:Xand.
TheUSERCOMMAND<usercommand>Likeinthecaseoftheradio
buttons,thiscanbeoptionallyspecified.WhenITisspecified,clickingon
thecheckboxwilltriggertheeventsATSELECTIONSCREENandAT
SELECTIONSCREENON<field>,etc.
Therestofthetermscarrythesamemeaningasexplainedinearlier
syntaxdescriptionsofthePARAMETERSstatement.
Anexample:

PARAMETERS:VL_ONOFFTYPERUNSIMUL,"referencetodataelementassigned
"todomain:DataTypeCHAR,length1
"fixedvalues:tworows:'X'&''
"domain:'CHCKBX'
IN_ONOFFTYPERUNSIMULNODISPLAY,"canuseNODISPLAY
"additionwhenreferring
"todataelement
BL_ONOFFTYPECASCHECKBOXDEFAULT'X',
GR_ONOFFASCHECKBOX,
YL_ONOFFTYPECHAR1ASCHECKBOX."referencetodataelement
"assignedtodomain:Data
"TypeCHAR,length1butno
"fixedvalues.

HorizontalLineonaSelectionScreen
Youcandrawahorizontallineonselectionscreenwiththefollowing
syntax:
SELECTIONSCREENULINE[/]<colposition>(<widthincolumns/characters>).

ULINEKeywordtodrawahorizontallineonaselectionscreen
Othertermsareobviousandwereexplainedearlier.
Example:
SELECTIONSCREENULINE/5(15).

AdditionMODIFIDwithSelectionScreenElements
TheadditionMODIFIDcanbeusedwithmostoftheselectionscreen
elementscovered:
COMMENT(ForLabelsorTexts)
TextBoxes/InputFields(PARAMETERSstatement)
RadioButtons(PARAMETERSstatement)
CheckBoxes(PARAMETERSstatement)
MultipleComplexSelections(SELECTOPTIONSstatement)
PushButtons
HorizontalLines
ExamplefortheadditionMODIFID:
PARAMETERS:CHQNO(12)TYPECMODIFIDGP1,
CCRDNO(16)TYPECMODIFIDGP1.

TheadditionMODIFIDisbeingexplainedinthecontextofthischapters
programYCL_CH09_SELECTION_SCREEN03.Inthisprogramyou
usedtheeventATSELECTIONSCREENOUTPUTtochangescreen
properties.
MODIFIDisakeyphrase.Itistobefollowedbyathreecharacterstring
liketheoneyouhavegivenintheexampleaboveGP1.Inthisexample,

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

37/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

basically,youareassigningselectionscreenelementsCHQNOand
CCRDNO(checknumberandcreditcardnumber)toagroupwith
identificationGP1.Inthismanner,youcanassigntwoormorescreen
elementstoagroup.Youcanhaveanynumberofgroupidentifications
assignedtovariousselectionscreenelements.
Inthecurrentchapter,whiledealingwiththeeventsINITIALIZATION,
andATSELECTIONSCREENOUTPUT,youwereintroducedtothe
structureofsystemmaintainedinternaltableSCREEN.Thesecondfield
inthisstructureisGROUP1TYPEC,length3.RefertoTable91.
TheMODIFIDisathreecharacterstring(groupidentifications)
assignedtotheselectionscreenelementsandwillbestoredinthefield
GROUP1fortheselectionscreenelementswithMODIFIDaddition.
InsideLOOPATSCREENENDLOOPyouhadthestatement:

IFSCREENNAME<>'CHQNO'ANDSCREENNAME<>'CCRDNO'.
CONTINUE."changingpropertiesofonly'CHQNO'&'CCRDNO'
ENDIF.

YouwantedtochangethepropertiesofonlyCHQNOandCCRDNO.
Youwantedtobypassallotherrows(intheinternaltableSCREEN)
correspondingtoselectionscreenelementsotherthanCHQNOand
CCRDNO.
AsyouhaveassignedboththeselectionscreenelementsCHQNOand
CCRDNOtoGP1,youcansimplifytheaboveIFstatementto:

IFSCREENGROUP1<>'GP1'.
CONTINUE."changingpropertiesofonly'CHQNO'&'CCRDNO'
ENDIF.

WhenyouhavealongstringoflogicaloperatorsANDandORbeing
usedinsidetheexecutionoftheLOOPATSCREENENDLOOP
construct,youcanassigntheselectionscreenelementstogroupsand
simplifyyourcode,avoidingthelogicaloperators.
ThisisthepurposeandfunctionoftheadditionMODIFID.
EventATSELECTIONSCREENONEXITCOMMAND
Whenyoupressonthesystemtoolbaranyofthebuttons:
(Exit),or

(Back),

(Cancel),thiseventistriggered.Cleanup

operationscanbeperformedinthisevent.
DefineandCallUserDefinedSELECTIONSCREEN
Theselectionscreensyouhavecreatedanduseduntilnowarethe
standardselectionscreens.TheABAPruntimesystemgeneratesscreen
number1000forthestandardselectionscreens.Inadditiontothis
standardselectionscreen,youcanhaveuserdefinedselectionscreens.
Theuserdefinedselectionscreensneedtobedefinedandthencalled.
Thesyntaxforuserdefinedselectionscreens:

SELECTIONSCREENBEGINOFSCREEN<screennumber>
[TITLE<title>][ASWINDOW].
...
......
SELECTIONSCREENENDOFSCREEN<screennumber>.

SELECTIONSCREENBEGINOFSCREENKeyphrasetostart
selectionscreenDefinition
<screennumber>Anynumber19999excluding1000reservedfor
standardselectionscreen
TITLEKeyword
<title>YoucanspecifyeitheratextsymbolidwiththeprefixTEXT
likeTEXT001oraname(namecanbemaximumofeightcharacters
long,startingwithanalphabeticcharacter,andtherestofcharacterscan
bealphanumericwithembeddedunderscores(_).Thenameshouldbe
assignedtextinanINITIALIZATION/ATSELECTIONSCREEN
OUTPUTevent.Thiswillappearasawindowtitle.Ifno<title>is
specified,theprogramtitle/shorttextwillappearasawindowtitle.
ASWINDOWThisadditionwillmaketheselectionscreenamodal
window.
SELECTIONSCREENENDOFSCREENKeyphrasetoendselection
screenDefinition
Alltheselectionscreenstatementstocreatetheelements:
PARAMETERS,SELECTOPTIONS,SELECTIONSCREENfortheuser
definedselectionscreenmustbeenclosedwithintheSELECTION
SCREENBEGINOFSCREENandtheSELECTIONSCREENENDOF
SCREENstatements.

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

38/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

Afterthedefinitionofuserdefinedselectionscreens,theyneedtobe
called.Thesyntaxforcallingauserdefinedselectionscreen:

CALLSELECTIONSCREEN<screennumber>
[STARTINGAT<startcolumnnumber><startlinenumber>
[ENDINGAT<endcolumnnumber><endlinenumber>]]
[USINGSELECTIONSET<variantname>].

CALLSELECTIONSCREENKeyphrasetocalluserdefinedselection
screen
<screennumber>Theselectionscreennumberdefinedearlier
STARTINGATKeyphrasetoindicatethestartingcoordinatesofthe
userdefinedselectionscreenintermsofcolumnandrownumber
<startcolumnnumber>Startingcolumnnumber
<startrownumber>Startingrownumber
ENDINGATKeyphrasetoindicatetheendingcoordinatesoftheuser
definedselectionscreenintermsofcolumnandrownumber
<endcolumnnumber>Endingcolumnnumber
<endrownumber>Endingrownumber
USINGSELECTIONSETKeyphrasetoloadvariantvaluesinto
selectionscreenvariables
<variantname>Variantname.TheVariantmustexistinthesame
program
AhandsonexerciseprogramYCL_CH09_SELECTION_SCREEN12
demonstratesthedefinitionandcallingofauserdefinedselection
screen.Inthisprogram,somerandomvariantvalueshavebeencreated
fortheSELECTOPTIONS(customers)andPARAMETERS(company
code)underthenameVAR1.
Thesourceprogram:

REPORTYCL_CH09_SELECTION_SCREEN12.
**********************************
*UserDefinedSELECTIONSCREEN**
**********************************
DATA:KUNNRTYPEKUNNR.
SELECTIONSCREENBEGINOFSCREEN500.
SELECTOPTIONSCUST_CDFORKUNNR.
SELECTIONSCREENSKIP2.
PARAMETERS:CCODETYPET001BUKRSDEFAULT1000.
SELECTIONSCREENENDOFSCREEN500.
CALLSELECTIONSCREEN500STARTINGAT51
ENDINGAT8515USINGSELECTIONSET'VAR1'.
"startrow&column,endrow&column

TheselectionscreendisplayedasamodalwindowwilllooklikeFigure9
48.

Figure948.Program:YCL_CH09_SELECTION_SCREEN12
SelectionScreen

Whenmultipleselectionscreensareusedinaprogram,youcan
determinethecurrentselectionscreenbyinterrogatingthecontentsof
thesystemfieldSYDYNNR.ThesystemfieldSYDYNNRcontainsthe
currentscreennumber.
Withthedefinition,callingofuserdefinedselectionscreenthechapter
onSELECTIONSCREENisbeingconcluded.
Conclusion
Theselectionscreenswillbepartofreportprograms(programs
producingoutputs)executedinforegroundmodetomakedataselections.
Theselectionscreenswillbeusedindirectlytoprovideselections
throughvariantsofreportprogramsexecutedinbackgroundmode.The
useofaselectionscreentoprovideselectionsthroughvariantswas
demonstratedintheprogramYCL_CH09_SELECTION_SCREEN10.
Theselectionscreenscanbedeployedforsimpleinputs.

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

39/40

1/5/2016

Chapter9:SELECTIONSCREENSSAPABAP:HandsOnTestProjectswithBusinessScenarios

PREV

Chapter 8: Open SQL Data Retrieval

NEXT

Chapter 10: Interactive Lists

Recommended / Queue / Recent / Topics / Tutorials / Settings / Blog / Feedback / Sign Out
2016 Safari.
Terms of Service / Privacy Policy

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

40/40

Anda mungkin juga menyukai