0% found this document useful (0 votes)
140 views9 pages

Classical Way To ABAP OO Style of Coding - SCN

This document discusses different ways to code in an object-oriented style in ABAP, including traditionally, using only static methods, using only instance methods, and the author's ideal way. It provides examples of each approach and encourages experienced developers familiar with OO concepts to try implementing these styles in their own work to get more comfortable with OO coding in ABAP.

Uploaded by

baskar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
140 views9 pages

Classical Way To ABAP OO Style of Coding - SCN

This document discusses different ways to code in an object-oriented style in ABAP, including traditionally, using only static methods, using only instance methods, and the author's ideal way. It provides examples of each approach and encourages experienced developers familiar with OO concepts to try implementing these styles in their own work to get more comfortable with OO coding in ABAP.

Uploaded by

baskar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

9/14/2016

ClassicalwaytoABAPOOstyleofcoding|SCN

GettingStarted Newsletters

Hi,Guest

LogOn

JoinUs

Store

SearchtheCommunity

Products

Services&Support

AboutSCN

Downloads

Industries

Training&Education

Partnership

DeveloperCenter

Activity

LinesofBusiness

UniversityAlliances

Events&Webinars

Innovation

Browse

Communications

Actions

ABAPDevelopment

ClassicalwaytoABAPOOstyleofcoding
PostedbySumanthKristaminABAPDevelopmentonJan9,201410:54:43AM
Share

Tweet

Like 3

ObjectOrientedABAPistakingslowphaseinadoptionforPureABAPers(NotworkinginWebdynproorother
objectorientedspace)evenItookayearlongtocompletelydomyworkinOO.

EvenIwasinasituationwhenoneofmyclientsquestioned,whyyoucodeinOOashewasnotableto
understand.Iwasdumbstruckandthethoughtprovokedmetowritethisforguyswhoareindilemmaonhow
tomovetoOO.

IhaveseenmanyblogsonABAPOOwhichwillbeagoodstartforlearning(explainingconceptsand
examples)butstillfacedfewchallengesinmovingtoABAPOOlikewhereandhowtostart,justputtingdown
mythoughtsabouttheproblemswhichfacedlittlelongerandwaysIovercame
FewroadblocksinusingABAPOO
oUnderstandingconceptsofOOwhohasnopreviousknowledgeonOO
oHowtoimplementthesameinourregularworkinRICEFobjects.
oHowtousemajoradvantagesofOO

Thisblogisforexperienceddevelopers,whoarefamiliarwithOOconceptsbutlazyinimplementingthesame
inABAP.BeforeItalkaboutanyofthesestuff,Iwouldliketotellhowtogetfamiliarizewithclasses.(Note:
Thisblogonlyprovidesapproachandnotanyexamples)
FornewbiestoABAPOO,cangetfamiliarizewiththeselinks?

http://help.sap.com/saphelp_nw2004s/helpdata/en/c3/225b5654f411d194a60000e8353423/frameset.htm
http://wiki.scn.sap.com/wiki/display/ABAP/ABAP+Objects+Getting+Started

IwillshowasmallexamplereportgettingsomeentriesfromMARAandusingCL_SALV_TABLEtodisplaythesamein
ALVinfourwayshere
Traditionalwayofwriting
OOway(onlyusingStaticmethods)Togetthehangofclassandmethodconcept
OOway(OnlyInstancemethods)Togetthehangofclassandmethodconcept
MyIDEALwayinOO
NewTrendofandcompletelymovingyourreporttoOO.

Traditionalwayofwritingthecode:

REPORTysdnblog_classic.
PARAMETERS:p_rowsTYPEcountDEFAULT'100'.
STARTOFSELECTION.
DATA:it_maraTYPESTANDARDTABLEOFmara.
PERFORMget_dataCHANGINGit_mara.
PERFORMdisplayUSINGit_mara.
*&*
*&FormGET_DATA
*&*
FORMget_dataCHANGINGch_maraTYPEmara_tt.
SELECT*FROMmaraINTOTABLEch_maraUPTOp_rowsROWS.
ENDFORM."GET_DATA
*&*
*&FormDISPLAY
*&*
FORMdisplayUSINGi_maraTYPEmara_tt.
DATA:lr_tableTYPEREFTOcl_salv_table.
cl_salv_table=>factory(IMPORTINGr_salv_table=lr_table
CHANGINGt_table=i_mara).
lr_table>display().
ENDFORM."DISPLAY

OOway(onlyusingStaticmethods)Togetthehangofclassand
methodconcept

http://scn.sap.com/community/abap/blog/2014/01/09/classicalwaytoabapoostyleofcoding

1/9

9/14/2016

ClassicalwaytoABAPOOstyleofcoding|SCN

LetsstartwithclassesanddontgointoboringpartofexplainingwhatisaSTATICorINSTANCEmethod(Please
googleorgothroughaboutthisstuff).MajordeveloperswhoarenewtoOO,firstquestioniswhethermymethod
shouldbeINSTANCEorSTATIC?Letssavethisquestiontothelast.
FirsttogetthehangoftheOOABAPfromtraditionalABAPusingSTATICmethodsonlyandabovereportlookslike
this:(suggestcontinuingwritingcoupleofreports/objects)

REPORTysdnblog_class_static.
PARAMETERS:p_rowsTYPEcountDEFAULT'100'.
**
*CLASSlcl_mainDEFINITION
**
*
**
CLASSlcl_mainDEFINITION.
PUBLICSECTION.
CLASSMETHODS:get_data,
display.
PRIVATESECTION.
CLASSDATAit_maraTYPEmara_tt.
ENDCLASS."lcl_mainDEFINITION
**
*CLASSlcl_mainIMPLEMENTATION
**
*
**
CLASSlcl_mainIMPLEMENTATION.
METHODget_data.
SELECT*FROMmaraINTOTABLElcl_main=>it_maraUPTOp_rowsROWS.
ENDMETHOD."GET_DATA
METHODdisplay.
DATA:lr_tableTYPEREFTOcl_salv_table.
cl_salv_table=>factory(IMPORTINGr_salv_table=lr_table
CHANGINGt_table=lcl_main=>it_mara
).
lr_table>display().
ENDMETHOD."display
ENDCLASS."lcl_mainIMPLEMENTATION
STARTOFSELECTION.
lcl_main=>get_data().
lcl_main=>display().

OK...IhopebynowyougothangofwhatatraditionalreportlooksinCLASS/METHODS.

OOway(OnlyInstancemethods)Togetthehangofclassandmethodconcept

Whatsnext?Letsseethesameprogramwithinstancemethods.Additionalstepswouldbedeclarationofanobject
andinstantiateittouseinyourprogram.

REPORTysdnblog_class_instance.
PARAMETERS:p_rowsTYPEcountDEFAULT'100'.
**
*CLASSlcl_mainDEFINITION
**
CLASSlcl_mainDEFINITION.
PUBLICSECTION.
METHODS:get_data,
display.
PRIVATESECTION.
DATAit_maraTYPEmara_tt.
ENDCLASS."lcl_mainDEFINITION
**
*CLASSlcl_mainIMPLEMENTATION
**
CLASSlcl_mainIMPLEMENTATION.
METHODget_data.
SELECT*FROMmaraINTOTABLEme>it_maraUPTOP_rowsROWS.
ENDMETHOD."GET_DATA
METHODdisplay.
DATA:lr_tableTYPEREFTOcl_salv_table.
cl_salv_table=>factory(IMPORTINGr_salv_table=lr_table
CHANGINGt_table=me>it_mara).
lr_table>display().
ENDMETHOD."display
ENDCLASS."lcl_mainIMPLEMENTATION

http://scn.sap.com/community/abap/blog/2014/01/09/classicalwaytoabapoostyleofcoding

2/9

9/14/2016

ClassicalwaytoABAPOOstyleofcoding|SCN

STARTOFSELECTION.
data:lr_mainTYPEREFTOlcl_main.
createOBJECTlr_main.
lr_main>get_data().
lr_main>display().

IntheaboveexamplewedeclareanobjectreferenceoftypeLCL_MAINandhavetocommandCREATEOBJECTto
createareferenceforfurtherusageofthesameinprogram.(ThesameLCL_MAINcanbedeclaredwithdifferent
names(manyreferences)andinitiatedbasedontherequirementneeds)
PleasedosomeliveprogramseitherusingwithanyoftheabovewaystoreallygetinitialkickstartofOO.

MyIDEALwayinOO
MYIDEALwayofwritingtheaboveprogramwouldbeasbelow.
REPORTysdnblog_class_ideal.
parameters:p_rowstypecountdefault'100'.
**
*CLASSlcl_mainDEFINITION
**
CLASSlcl_mainDEFINITION.
PUBLICSECTION.
CLASSMETHODS:start.
PRIVATESECTION.
METHODS:get_data,
display.
CLASSDATA:lr_mainTYPEREFTOlcl_main.
DATAit_maraTYPEmara_tt.
ENDCLASS."lcl_mainDEFINITION
**
*CLASSlcl_mainIMPLEMENTATION
**
CLASSlcl_mainIMPLEMENTATION.
METHODstart.
CREATEOBJECTlr_main.
lr_main>get_data().
lr_main>display().
ENDMETHOD."start
METHODget_data.
SELECT*FROMmaraINTOTABLEme>it_maraUPTOP_rowsROWS.
ENDMETHOD."GET_DATA
METHODdisplay.
DATA:lr_tableTYPEREFTOcl_salv_table.
cl_salv_table=>factory(IMPORTINGr_salv_table=lr_table
CHANGINGt_table=me>it_mara).
lr_table>display().
ENDMETHOD."display
ENDCLASS."lcl_mainIMPLEMENTATION

STARTOFSELECTION.

lcl_main=>start().

HerewecalltheSTARTmethodonlyonceforaprogramandsoImadeitasastaticmethodandonestaticobject
(LR_MAINreferencingthesameclass)fordealingwithrestofthebusinesslogic.(Therecanbemanybetterwaysas
well..)

NewTrendofandcompletelymovingyourreporttoOO:

Thenewwayofwritingthereportsincludestcodetolaunchyourreport.LetsstartwithTcodecreationasbelowand
select3rdoptionMETHODOFACLASS(OOTRANSACTION).

NextstepnavigatestobelowscreenandunchecktheboxOOTRANSACTIONMODELenablinganotherfieldLOCAL
INPROGRAM

Nowprovideyourprogramnameandlocalclassnameandmethodforthebelowprogram.Programlookslikebelow
REPORTysdnblog_class_new.

SELECTIONSCREEN:BEGINOFSCREEN200.
PARAMETERSp_rowsTYPEcountDEFAULT'100'.
SELECTIONSCREEN:ENDOFSCREEN200.

**
*CLASSlcl_mainDEFINITION
**
CLASSlcl_mainDEFINITION.

http://scn.sap.com/community/abap/blog/2014/01/09/classicalwaytoabapoostyleofcoding

3/9

9/14/2016

ClassicalwaytoABAPOOstyleofcoding|SCN

PUBLICSECTION.
CLASSMETHODS:start.

PRIVATESECTION.
METHODS:get_data,
display.
CLASSDATA:lr_mainTYPEREFTOlcl_main.
DATAit_maraTYPEmara_tt.
ENDCLASS."lcl_mainDEFINITION
**
*CLASSlcl_mainIMPLEMENTATION
**
CLASSlcl_mainIMPLEMENTATION.
METHODstart.
BREAKPOINT.
CALLSELECTIONSCREEN200.
IFsysubrcISINITIAL.

CREATEOBJECTlr_main.
lr_main>get_data().
lr_main>display().
ENDIF.

ENDMETHOD."start
METHODget_data.
SELECT*FROMmaraINTOTABLEme>it_maraUPTOp_rowsROWS.
ENDMETHOD."GET_DATA
METHODdisplay.
DATA:lr_tableTYPEREFTOcl_salv_table.
cl_salv_table=>factory(IMPORTINGr_salv_table=lr_table
CHANGINGt_table=me>it_mara).
lr_table>display().
ENDMETHOD."display
ENDCLASS."lcl_mainIMPLEMENTATION

STARTOFSELECTION.

lcl_main=>start().

Hereyouaretakingcontrolonwhenyourselectionscreenshouldtrigger.Thingsyouneedtoobserveinabove
program
Yourselectionscreenisdefinedasascreenwithadifferentnumber,whichis200
Youareexplicitlytriggeringyourselectionscreen200intheSTARTmethodratherthangivingcontroltoframework.
(NotetheothereventsATSELECTIONSCREENwillworkasusual.)
Whenthetransactionisexecutedfirstittriggersthemethodspecifiedinthetransaction

ByslowlyadaptingtoaboveapproachedyoucanchangeyourcodingstyletoOO.

Therecanbemanyotherwaysandthisisjustlittleknowledgesharingbasedonmyexperience.Commentsand
suggestionsarewelcome.

21603Views

Categories:ABAPDevelopment

Topics:abapTags:beginner,code,abap_objects,abap_oo

AverageUserRating
(25ratings)

Share

Tweet

Like 3

294Comments
1 2 3 12

JelenaPerfiljevaJan9,20149:27PM

Youmightwanttotakealookat thisblog,aswellasotherblogsby PaulHardy.

PersonallyIdon'tdenyatalltheadvantagesofOOP,butseenopointinusingobjectsjustforthe
sakeofobjectsin,say,astandaloneABAPreport.Yourfirstexampleisshortandreadableanditjust
getslongerandmoreconvolutedfromthere.Maybeit'sjustabadexample,butthenwhat'sthepoint
ofpreachingforOOPifwedon'tdemonstratetheactualadvantage?
Like(13)

SumanthKristamJan10,20144:26AM(inresponsetoJelenaPerfiljeva)

HelloJelena,

Thanksforyourcomment.Myintentionofthisblogwasnottopreachadvantages/disadvantagesof
OOP,butforspecificsetofdeveloperswhoneverwanttomovetoOOmodel.

http://scn.sap.com/community/abap/blog/2014/01/09/classicalwaytoabapoostyleofcoding

4/9

9/14/2016

ClassicalwaytoABAPOOstyleofcoding|SCN

Ithoughtofusingasimpleexample,butcouldhaveendedupasabadone.ProbablyYourcomment
inspiresmetowriteanotherblogandwillpostitsoonwithyoursuggestion...

thanks.
Sumanth
Like(1)

MahadeoKedariJan10,20147:14AM

hii SumanthKristam,

VeryGoodDocument,

ItsReallyhelpful...

Thanksalot

keepitup....
Like(1)

AshishTrivediJan10,20147:21AM

GoodSK.Keepupthegoodwork
Like(1)

KesavadasThekkillathJan10,20149:53AM(inresponsetoSumanthKristam)

Pleasekeepupthegoodwork,keepyourblogscoming:)

IgenerallyusetheMVCarchitectureforclassicreportsandscreenprogramming.Thewayyou
implementitchangesbasedontherequirements.

Youmightwanttohavealookatthisblogtoo GlobalDatainABAPOOPrograms

Kesav
Like(3)

PaulHardyJan10,201410:39AM

Hello,

Firtsofall,welldoenfortheideaoftryingtoconvincepeoplethatOOisgood.Weinstantlycoemto
whatIcallthe"solutionmanager"problem,whichisifsomethingisreallygood,fantasticallygood,
thebestthingsinceslicedbread,andhasbeenaroundfortenyearsplus,thenwhydopeopleonly
useitifyourforcethemtoatgunpoint?

IhavebeenexperimentingwithABAPOOforyearsnow.Myhearttellsmeit'sthewayforwardbutitis
sodifficulttoproveittopeople.YouwouldthinktheinternetwouldbefullofABAPexamplessaying
look,it'seasiertodosuchandsuchinOOratherthanproceduralprogramming,andhere'swhy,and
hereareexamplesforsomecommonprogrammingtasks.DoyouknowforsomereasonIamfinding
itdifficulttofindtheseexamplesontheweb.

ThisiswhyIamtryingtoplugthisgapmyselfIwanttocomeupwithexamplesthatscreamoutin
lettersoffireathousandmileshighthatOOisobviouslybetterandeveryoneshouldmakethejump.I
haven'tmanagedthisyet.Ican'tevenconvincemycolleaguesatwork.

IagreewithJelenathattherearesomethingsinABAPwhereOOisnotsuited,itseemstomethatis
becauseSAPhasjustnotbuiltthesystemthisway.

ALVreportsareanobviousexamplewhereOOisofverydubiousbenefit.Ascanbeseeninyour
blogyouendupwithalotmorecodefornoobviousbenefit.

FormorecomplicatedprogramsIagreewithputtingDYNPROscreensintofunctionmodulesto
abstracttheUIlayer,soyoucanswopinfutureUItechnolgiesatalaterdate,butthenpeoplego
absoluetlyfreeenergycrazy,andreplacethebuiltinSAPDYNPROfunctionse.g.ONCHAININPUT
withworkaroundcodeoftheirowntoaddloadsofextracodetotryandalmostachievewhatwas
alreadythereforyouinthefirstplace.

Thisjustaddsahugeoverheadfortheprogrammer,andwhenitcomestomaintenanceitmakesthe
thinganightmaretodebugalaME21N.(PopIn/PopOut/Shakeitallabout/Nocodethatactually
seemstodoanything).

WouldIbeburnedatthestakeasawicthifIsuggestthatalotoftheMVCforDYNPROframeworksI
haveseenarejustpeopletryingtowrite"pure"codeforthesakeofwriting"pure"code,ratherthan
tryingtoachieveanysortofbenefit?

Forexample,doesputtingaSELECTIONSCREENforanALVreportinafunctionmodule,andthen
extractingoutalltheSELECTOPTIONSandpassingthembackintoaclassreallygiveyouany
benefit?"Oh,thentheselectionscreenisreusable"really?Ichallengeanyonetolookatthereown
systemandseealltheZALVreports,howmanyhavetheexactsameselectionscreen,andcanyou
besurethattheuserswillnotdayrequireonemoreextraselectionoptiononjustonereport?

TosummarisetherighttoolfortherightjobOOdoeshavewonderfuladvantages,itisdifficultto
convincepeople,Iamtryingmybest,asaredozensofothers,thebestexamplesinSAPGUI
programmingseemtobeinthebusinesslogicanddatabaselayersasfarasIcansee.

ExampleswhereyoutrytoramasquarepegintoaroundholeasinthemyriadofMVCforDYNPRO
examplesIhaveseendon'tseemtobeconvincinganybody,infactIfeartheyhavetheexact
oppositeeffect.

CheersyCheers

Paul
Like(28)

http://scn.sap.com/community/abap/blog/2014/01/09/classicalwaytoabapoostyleofcoding

5/9

9/14/2016

ClassicalwaytoABAPOOstyleofcoding|SCN
RonitGeorgeJan10,201411:34AM(inresponsetoMahadeoKedari)

ItsBlog

.
Like(0)

SuhasSahaJan10,20141:41PM(inresponsetoPaulHardy)

HelloPaul,

IalwayshavethesamepredicamentwhethertouseMVCforclassicalscreenprogramming?

Yourcommentdoesputthingsintoperspective,butformethedilemmawillcontinueuntilABAP
classesbuilttobeMVCfriendly.

BR,
Suhas

PSIdon'tthinkSAPisinvestingdollarsonclassicalscreenprogramminganymore&wemight
neverseeMVCfriendlyclass
Like(1)

SuhasSahaJan10,20142:08PM

HelloSumanth,

TbhABAPclassesarejustnotdesignedtobeMVCcompatible,youhavetodoalotofworkaroundto
achievethesameusingABAPclasses.

Thisisdefinitelyanoverkillifyouaredoingitforasingleprogram.Butifyouarebuildinga
standaloneapplicationwithlotsofscreensthenmaybeitmakesensetohavetheMVCarchitecture.

Ifyouwanttoknowthecomplexityinvolvedin"truly"decouplingscreenlogicfrombusinesslogic
justcheckthetransactionBPwhichisBDTcompatible.Youcanenhancethescreensinanypossible
way&theyarewaytooflexiblebuttheyarewaytoodifficulttodebugunlessyouunderstandthe
BDTframework

IamalwayshavingthedilemmawhentousepureOOforABAPscreenprogramming&whentokeep
itsimple.Tillnow,ihavenotfoundanysolutiontothat.

BR,
Suhas
Like(2)

BrunoEsperanaJan10,20142:10PM(inresponsetoPaulHardy)

"anightmaretodebugalaME21N.(PopIn/PopOut/Shakeitallabout/Nocodethatactually
seemstodoanything)."
Ismiled
Like(3)

MatthewBillinghamJan10,20143:50PM(inresponsetoPaulHardy)

TheproblemisthattherearenoreallysimpleexamplesthatshowthatOOisbetter.ImovedtoanOO
paradigmabouteightyearsago,whenIstartedwithanewclient,who'dletmedothingsmyway.

Withasimplereport,itseemsthere'snopoint.However,mosttimesonceyou'vedevelopedasimple
report,theuserscomebackandaskforenhancements.(It'sabitlikeworldcreatorstheysaythat
theywantasimplemargarita,butactuallywhattheyneedisafulldiscworld).

That'swhenOOshowsitspower.ItissimplyeasiertoenhanceanOOprogram(assumingitiswell
written!).Onoccasion,inamomentofweakness,I'vethough"oh,thisissosimple,I'lljustdoa
STARTOFSELECTIONENDOFSELECTIONreport,withoutanymodularisationatall.Ormaybejust
useafewforms.I'vealwaysregretteditbecauseevenawellwrittenclassicalprogramissomuch
morepainfultochangethanawellwrittenobjectorientedprogram.

WhatI'vediscoveredmorerecently,isthatifI'veareasonablesizedapplicationtodevelop,Icanjust
workoutonapieceofpaperthevariousobjects(classes!)involved,andhowtheyrelatetoeach
other,andgetmostofthedesignsortedoutbeforeIgetnearacomputer.Ithinkit'scalledUMLor
something...

Theonlywayyou'llfindouthowabsolutelyincredibleprogramminginOOisyouhavetodoit.No
oneI'vemetwho'smadetheconversionhaseverregrettedit.Justlikenoonewhowasforcedto
learnpianoasakid,regretsitasanadult.

So,comeonabappersleavethechildishworldofformsandfunctionmodulesbehind,andembrace
thedarkside...Imean"growup".
Like(17)

WouterPeetersJan11,201412:37PM

Greatread.MyjourneytoOOwasasfollows:
Traditional
OOw.localclasses(notafan)
OOGlobalstatic,aka'wannabeoo'?
OOGlobalinstance
OOGlobalinstancewithinterfaces
tobecontinued...

Buttocometothepoint,somenotes/opinions:
Localclasses:Idon'tfindthemveryreadableorreusableinareport,isthereanyonethatdevelops
likethis,ifyeswhy?(exceptioneventhandlerclass)

http://scn.sap.com/community/abap/blog/2014/01/09/classicalwaytoabapoostyleofcoding

6/9

9/14/2016

ClassicalwaytoABAPOOstyleofcoding|SCN
WhyintegratetheALVlogicintheclasstogetherwithdataretrieval?Doesthisviolateseperationof
concerns?

WhenIdevelopareportIalwaysaskmyselfwhenwilltherebeaneedtodifferentiatesomethingorto
reusethelogicIdevelopnow.CurrentlyIprefertodevelopaglobalinstanceclassw.interface,write
allthelogicanddataretrievalinit,andkeeptheALV/displayspecificlogicinthereport.
ThiswiththeintentionwhenaneedarrivestobringthisreporttoWebDynproorsomewhereelseI
canreusetheobjecttherewithoutanyneedtoadjust.

Greets,
Wouter
Like(4)

SumanthKristamJan16,20147:05AM(inresponsetoWouterPeeters)

HelloWouter,

Thanksforthesuggestion.

IalwaysnotabletoconvicefellowClassicalabaperstomovetoOOandnotexactlyexplainthe
advantagesofOOABAP.

Theonlywaytheyunderstandtheadvantagesisunlesstheydoit.

TosimplystuffIprovidedexampleoflocalclasses..andtherearesomeinstanceswhereifelttouse
localclassesratherthansuchasinterfaceswherevalidationsaresospecifictointerfaces.

YesGlobalinstancewithIntefacesisgoingwaytogetmajoradvantageofOO..

thanks,
Sumanth

Like(1)

AbhijitMoholkarJan16,20147:30AM

IwillpreferusingABAPObjectsifIhavetodesignanyfunctionalityfromscratchandthereisastrong
possibilitythat,itscomponentswillbereused.Iwouldalsoavoidusingcallingtraditionalfunction
modulecallsinmyobject.IthastobefullyOOP.

Itwillbeinterestingtoseewhetherprojectshaveavisibilityof%repetitivequeries/processing/logic
theywilldoanddecidetobuildreusableclasslibraries.Isitpossibleinpractice?Willsuchan
approach,getsupportfromthestakeholders?
Ireallydon'tseemuchpointinwritingOOcodeforthesakeofit.Instead,firstthefocusshouldbeon
identifyingtherightcandidatesforOOPanddevelopingthemusingpropermethodology.
Like(1)

MatthewBillinghamJan16,20147:52AM(inresponsetoAbhijitMoholkar)

AlldevelopmentsaregoodcandidatesforOOP.That'smyexperience.Alldevelopmentshavethe
potentialforreuse.Thereforeit'ssensibletowritetheminawaythatallowsforreuse.

Thatdoesn'tmeanthatyouhavetoobjectifytothenth,butatleastuselayeringanddividethe
frontendfromthebusinesslogic.Itcertainlydoesn'tmeanthatyoucan'tusefunctionmodulesor
developyourown(kindofdifficulttoimplementparallelprocessing,oruseBAPIs,withoutfunction
modules).

IwriteOOcodeallthetime.Notforthesakeofit,butbecauseevenforthesimplestprogram,it
makesitquickerandeasiertoenhanceandmaintain.Itmaytakealittlelongertodevelop,butthe
majorityofthecostofaprogramliesinmaintenancenotindevelopment.

Icannotthinkofasingledevelopment(frombasicreportstoentireapplications)overthelast17years
thatwouldhavebeenbestwrittennonOO.

Sothere'sachallenge:nameonedevelopmentthatitwouldbebesttowriteprocedurally.
Like(6)

AbhijitMoholkarJan16,20148:21AM(inresponsetoMatthewBillingham)

HiMatthew,

Iunderstandyourpoint.AsImentioned,itmakessensetounderstandthereusabilitylikelihoodand
developaccordingly.Personally,IwillnotpreferspendingtimeinwritingasimplereportusingOOP.I
willuseOOP,ifIamcertainthattherequirementwillbefrequentlyenhanced,borrowedORaltered,
butthenthat'smypreference.

MystillholdtheviewofusingOOP"Ifneeded".
Like(0)

MatthewBillinghamJan16,20149:26AM(inresponsetoAbhijitMoholkar)

Idevelopedasimplereportprocedurally,andthenhadtoenhanceit."HowIwishI'ddevelopeditin
objects"Isaidtomyself.

Thesecondtimethishappened,IdecidedthatImightaswelldevelopthereportinobjectstostart
with.Thepointisthatifanenhancementisrequired,it'llbequickerwithadecentlywrittenobject
orientedprogram.

I'vealsolostcountofthenumberoftimesthatacomponentthatwillprobablynotbereused(butI'll
writeitthatwayanyway)hasendedupbeingreused.

Tomymindsayingthat"oh,it'sjustsomethingsimple,Imightaswelldoitprocedurally"isn'tfarfrom
"ohit'sjustsomethingsimple,Iwon'tbotherwithencapsulation,meaningfulvariablenames,

http://scn.sap.com/community/abap/blog/2014/01/09/classicalwaytoabapoostyleofcoding

7/9

9/14/2016

ClassicalwaytoABAPOOstyleofcoding|SCN
modularisation...".Bywritingasimpleprogramprocedurally,youarecreatingunnecessaryworkfor
thepersonwhomaintains.If90%ofthecostofaprogramisinmaintenance,thentowriteaprogram
inanunoptimalway,justontheoffchancethatitwon'teverbechanged,couldbeseenas
irresponsible!Programmersingeneralneedtogettheirmindsoftheeffortofdevelopmentand
concentrateonmakingtheirprogramsasmaintainableaspossible.Againthatiswherethecost
lies.

Youdon'tonlyusegoodcodingtechniquesonly"ifneeded".Youdon'twriteprogramusing"OOP"
only"ifneeded".
Like(2)

SuhasSahaJan16,201410:19AM(inresponsetoMatthewBillingham)

HelloMatt,

Icouldnotagreemore.Butihaveacommenttomakeonthe"reusability".

Imhotherehastobesufficienteffortfromthedeveloperstoseeifthereareanyclasses/interfaces
whichcanbereused.Fore.g.,ihaveseendifferentprojectteamshavebuiltdifferentclassesto
accesstheBusinessPartnerdetails.Oneteammighthavecomeupwiththisnovelideatowrapthe
BPBAPIsinmethods,createaclasshierarchybasedontheBPtype,roleetc.Buttheniftheother
teamstartsbuildingit'sownOOmodel,thewholepointofreusablecodeislost.

IseethesameinstandardSAPaswell,justdoasearchfortabletypesdefinedusingBAPIRET2

Idon'tknowhowtotacklethisproblem.Isitsomethingingrainedinthedeveloper'smind(i'mnot
sure)?Ithinkyourideaofbrainstormingbeforeevenwritingalineofcodeshouldpluginthegap.

BR,
Suhas
Like(0)

MatthewBillinghamJan16,201410:29AM(inresponsetoSuhasSaha)

Itisadifficultissue.I'minthewonderfulpositionofbeingthemainprogrammer.However,oneofthe
other(ratherbigger)teamsmanagesthisbyhavingtightcontrolonthecreationofnewclasses,good
communicationswithintheteam,andacleardevelopmentstrategyandframework.
Like(0)

SuhasSahaJan16,20146:33PM(inresponsetoAbhijitMoholkar)

MystillholdtheviewofusingOOP"Ifneeded".
Itisneeded,therearenosecondthoughtsaboutit.
http://help.sap.com/abapdocu_740/en/abenobsolete_modularization.htm

Themainhatepointformeinproceduralprogrammingareglobalvariables.Idon'tthinkprocedural
programmingcanprovideencapsulation.Youcanmessaroundwithglobalvariableseasilyandthe
personmaintainingthecodewillbecursingyoulikeanything.

IamnotsayingthatyouuseOOforeverysinglething.IfindPersistenceclasses,SHMclassestoo
hardtodigest&tbhi'venotusedtheminproductivecodeever.Maybeifigetachancetodevelopan
standaloneapplicationimightusethem

BR,
Suhas
Like(2)

MatthewBillinghamJan16,20142:15PM(inresponsetoSuhasSaha)

Persistenceclassesarefineforwhenyou'rereading/writingsinglerecords.Forbulkdata,they're
totallyuseless.However,youcanstilluseOOwithSELECTSyoujustputtheselectsintothe
methodsdirectly.Solongasyoulayertheapplication,youretaintheflexibility.

IdidoneapplicationusingpersistenceclasseswrappingtheclassesinBusinessObjectclasses,
comprisingUpdate,Read,CreateandDeletemethods.Theapplicationonlyaccessthedatathrough
theBusinessObjectclasses(whichthenusethepersistenceclasses).Whatwasgoodaboutdoing
thisway,isthatalotofprogrammingbecamejustfollowingthesamepattern.Andonceyougoit
working,itwasverystable.

SharedmemoryI'veneverfoundarequirementfor.
Like(0)

SuhasSahaJan16,20146:32PM(inresponsetoMatthewBillingham)

However,youcanstilluseOOwithSELECTSyoujustputtheselectsintothemethods
directly.Solongasyoulayertheapplication,youretaintheflexibility.
That'swhatihavebeendoing

Butitdoesn'tgiveyoutherealOOflavourthatpersistenceclasses

give
Like(0)

MatthewBillinghamJan16,20147:12PM(inresponsetoSuhasSaha)

IjustthinkofthemasbasicelementsofABAPObjects.Justlikethe"for"statementinJava.
Like(0)

http://scn.sap.com/community/abap/blog/2014/01/09/classicalwaytoabapoostyleofcoding

8/9

9/14/2016

ClassicalwaytoABAPOOstyleofcoding|SCN

JelenaPerfiljevaJan16,201410:02PM(inresponsetoMatthewBillingham)

MatthewBillinghamwrote:

Sothere'sachallenge:nameonedevelopmentthatitwouldbebesttowriteprocedurally.
Haha,nicetry.Thethingisnooneiswritingblogstoconvinceanyonethatproceduraldevelopment
isbetter.ThesestatementsarealwaysmadeaboutOOP.Buttherearemanycaseswhereitactually
seemsmoreofa"potatopotahto"situation.

Let'ssayIcreateasimpleALVreportusing3routinesgetdata,getfieldcatalog,displayALV.InitI
use2wellknownstandardFMs.It'sastandalonereport,so"reusability"isreally0,otherthanusing
thesameFMsinotherreports.An"enhancement"wouldverylikelybejustaddinganewfieldi.e.
changeSELECTstatementandchangeALVstructuredefinition(ItrytodefineitinDictionary).Ifyou
dothesamethingwithclasses/methods,you'dstillneedtodothesameexactchanges.Exceptthe
programwillbelike2timeslonger(weseeitinthissameblogthecodejustgetslongerasitgets
"better")andyouwoulddealwiththecustomscreenandacontainerandabunchofincludes.Idon't
knowifallofthiswasactuallya"must"butsomeobjecthappyconsultantwroteareportlikethatin
oneofoursystems.Andthe"OOPversion"looksuglierbecausethecontainerisnotmaximizedand
hastwoannoyingscrollbarsevenonmywidescreen.Howtheheckisthatanybetter?

I'dhavetodisagreewithablanketstatementthatOOPis"better"andthereforeeveryonewhochoses
nottouseitreligiouslyis"lazy".Ifyouaskme,I'lltakeawellwrittenproceduralprogramovera
poorlywrittenOOprogramanytime.Inmy(totallyunqualified)opinionOOPismucheasiertomess
upandlessforgiving.Ontopofthat,theSAP'seffortstopushformoreuseofobjects(notsureifitwas
evenanorganizedeffortandnotjustaploytolureinthedeveloperswhoaremorecomfortablewith
OOthanprocedurallanguages)havebeen,well,ratherweak.EncapsulatinganFMinamethodand
sellingitasOOPyeah,right,thatwillconvinceeveryone.
Like(8)

SuhasSahaJan16,201410:57PM(inresponsetoJelenaPerfiljeva)

HelloJelena,
Andthe"OOPversion"looksuglierbecausethecontainerisnotmaximizedandhastwo
annoyingscrollbarsevenonmywidescreen.Howtheheckisthatanybetter?
Tbhi'veneverbeenafanofthecontrolframeworkelementsmyself(CL_GUI*),andusethemonlyif
there'san'editablefield'mentionedinthespecs

OnthecontraryifyouusetheSALVOMinsteadoftheREUSE_ALV*functions,youhavetobuildjust
2procedures
1.getdata(),
2.displayALV().

Nowwhetheryoumodulariseyourprogramsusinglocalclassesorsubroutinesthat'sentirelyyour
choice.

Amajorirritationihavewithsubroutinesareyouhavetopassactualparametersagainsteveryformal
parameter(eventheCHANGINGones),thats**ksbigtime Thereisnowayyoucanmarkaformal
paramasoptional.AndnottomentionsomegreatmindschangetheUSINGparamsinsidethe
subroutinestoo

BR,
Suhas

PSABAPistheonlyprogramminglanguageiknow,ihadthechoicetochoosebetweenOOand
procedural(4.5yrsago)andthankfullyichosetheformer
Like(3)

1 2 3 12

SiteIndex
Privacy

ContactUs
TermsofUse

SAPHelpPortal
LegalDisclosure

Copyright

http://scn.sap.com/community/abap/blog/2014/01/09/classicalwaytoabapoostyleofcoding

FollowSCN

9/9

You might also like