Tải bản đầy đủ (.pdf) (917 trang)

Sams teach yourself ABAP 4 in 21 days sep 1998 ISBN 0672312174

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (2.61 MB, 917 trang )


SamsTeachYourselfABAP/4®in21
Days
Copyright©1999bySams
Allrightsreserved.Nopartofthisbookshallbe
reproduced,storedinaretrievalsystem,ortransmittedby
anymeans,electronic,mechanical,photo-copying,
recording,orotherwise,withoutwrittenpermissionfrom
thepublisher.Nopatentliabilityisassumedwithrespectto
theuseoftheinformationcontainedherein.Although
everyprecautionhasbeentakeninthepreparationofthis
book,thepublisherandauthorassumenoresponsibility
forerrorsoromissions.Neitherisanyliabilityassumedfor
damagesresultingfromtheuseoftheinformation
containedherein.
HTMLconversionby:
LEVELXL.L.C.,
Warren,NewJersey,800-422-3475.
e-mail:


©Copyright,MacmillanComputerPublishing.Allrightsreserved.



SamsTeachYourselfABAP/4®in21
Days


Chapter
1


Chapter
2
Chapter
3
Chapter
4
Chapter
5
Chapter
6
Chapter
7


Introduction

Week1ataGlance
TheDevelopmentEnvironment
YourFirstABAP/4Program
TheDataDictionary,Part1
TheDataDictionary,Part2
TheDataDictionary,Part3
TheDataDictionary,Part4
DefiningDatainABAP/4,Part1
Week1inReview

Week2ataGlance

Chapter
DefiningDatainABAP/4,Part2

8
Chapter
Assignments,Conversions,andCalculations
9
Chapter
CommonControlStatements
10
Chapter
InternalTables


11
Chapter
AdvancedInternalTables,Part1
12
Chapter
AdvancedInternalTables,Part2
13
Chapter
ThewriteStatement
14
Week2inReview


Week3ataGlance
Chapter
FormattingTechniques,Part1
15
Chapter
FormattingTechniques,Part2

16
Chapter
Modularization:EventsandSubroutines
17
Chapter
Modularization:PassingParameterstoSubroutines
18
Chapter
Modularization:FunctionModules,Part1
19
Chapter
Modularization:FunctionModules,Part2
20
Chapter
SelectionScreens
21
Week3inReview

AppendixA
AppendixB

©Copyright,SamsPublishing.Allrightsreserved.





SamsTeachYourselfABAP/4®in21
Days
Introduction

ConventionsUsedinThisBook
AbouttheAuthors
TellUsWhatYouThink!


Introduction
HavingtaughttheABAP/4certificationcoursetohundredsofbeginnersand
experienceddevelopersatbothatSAPandatotherinstitutions,Iknowthekind
ofproblemsandquestionsyouwillhavewhenlearningthispowerfullanguage.
ByincorporatingallthebesttechniquesthatIhaveencounteredintothisbook,I
hopetoimpartthatsamelearningexperiencetoyouaswell.Tothatend,this
bookischockfullofdetaileddiagrams,full-screensnapshots,workingsample
programs,narratedscreencams,andstep-by-stepprocedures.Allthesample
programsarealsosuppliedontheCD-ROMsothatyoucanuploadandrunthem
onyourownsystem.Inaddition,theutilitiesthatIsupplytoallofmyclasses
areincludedontheCD-ROM,plussomenewonesthatIhavewritten
specificallyforthebuyersofthisbook.
ABAP/4,forallofitssimplicityonthesurface,isacomplexlanguage
underneath.Becauseofthat,thebeginnerisoftenbewilderedbyitsbehavior.By
understandinghowitworksbelowthesurface,youwillbeabletomasterthis
language.Byunderstandingthehowsandwhys,youwillgainanunderstanding
fewhaveinthisexcitingfield.
ThisbookwillguideyouthroughtheintricaciesoftheABAP/4languageand
environmentonestepatatime.Afteryoucompleteeachchapter,youwillbe
presentedwithexercisestoreinforceyourlearning.Workingsolutionsare
providedforallexercisesontheCD-ROM.
Asexperiencedprogrammersknow,andbeginnerssoonfindout,creating
ABAP/4programsoftenmeanscreatingmorethanjustaprogram.Itfrequently
involvesthecreationofdevelopmentobjectstosupportit.Proceduresfor
creatingtheseobjectsareallexplainedinexquisitedetailusingalistof

numberedsteps.Eachstepcontainsthetitleofthescreensyouencounterandthe
expectedresponsestoeachcommand.Allproceduresareaccompaniedbya
screencamshowingyouexactlyhowitisdone.Now,notonlycanyoulearnby
watchingme,butyoucanfastforwardandrewindmeaswell.
ThesheervolumeofinformationneededtomasterABAPisadauntingtaskfor
most,butIhavetakenthemostvitalinformationthatyouneedandseparatedit
into21manageablebites.Withtheknowledgeyougainusingthisbook,youwill
beabletobranchouttocomplexABAP/4taskswithasolidunderstandingas


yourfoundation.
Asyougothroughthematerial,ifyouhaveproblemsorquestionspleasevisit
theInternetsite.ThereIwillpostanswerstofrequently
askedquestions,andproblemsyoumayencounterthathavenotbeencovered.If
youfindanerrorinthisbook,orsuspecttheremaybeanerror,youcanfindand
posterratathere.
IhopeyouwillfindusingthisbookasenjoyableasIhavefoundwritingit.
Cheers.Here'stoyourABAP/4in21days!

ConventionsUsedinThisBook
Textthatyoutypeandtextthatyouseeonscreenappearinmonospacetype
Itwilllooklikethis

tomimicthewaythetextlooksonyourscreen.
Variablesandplaceholders(wordsthatstandforwhatyouwillactuallytype)
appearinitalicmonospace.
Eachchapterendswithquestionspertainingtothatday'ssubjectmatter,with
answersfromtheauthor.Mostchaptersalsoincludeanexercisesectionanda
quizdesignedtoreinforcetheday'sconcepts.(TheanswersappearinAppendix
B.)

NOTE
Anotepresentsinterestinginformationrelatedtothediscussion.

TIP
Atipoffersadviceorshowsyouaneasierwayofdoingsomething.

CAUTION


Acautionalertsyoutoapossibleproblemandgivesyouadviceon
howtoavoidit.

DO
TheseDo/Don'tsidebarsgiveyou
tipsforwhattodoandwhatnotto
dowithABAP/4.

DON'T


Manyoftheproceduresinthisbookaredemonstratedusingscreencams.
Screencamsarelikemovies;theyshowaseriesofscreens,includingkeystrokes
andmousemovements,withadescriptivevoice-over.

NewtermsareintroducedusingtheNewTermicon.
TheSyntaxiconalertsyoutothepropersyntaxusageforthecode.

TheInputiconhighlightsthecodetobeinput.

TheOutputiconhighlightstheoutputproducedbyrunningthecode.


TheAnalysisicondesignatestheauthor'sline-by-lineanalysis.


AbouttheAuthors
KENGREENWOODisthePresidentofOntario,Canada-basedSAP
consultingfirmModusNovus,Inc.HeisalsoanABAPCertification
instructoratSAPAmerica'sABAP/4AcademyinBoston,LambtonCollege
inOntario,andhasrecentlytaughtABAP/4atSAPAmericainFosterCity.
JACOBJ.BOLOTINisaSAPconsultantforPricewaterhouseCoopers
LLPandhasbeeninvolvedinmanyupgradeandimplementationprojects
ontheWestCoast.InhissparetimeheenjoysworkingonhisCadillacs,
swimmingintheocean,andlisteningtoSublime.QuestionsforJacobcan
besentto


TellUsWhatYouThink!
Asthereaderofthisbook,youareourmostimportantcriticandcommentator.
Wevalueyouropinionandwanttoknowwhatwe'redoingright,whatwecould
dobetter,whatareasyou'dliketoseeuspublishin,andanyotherwordsof
wisdomyou'rewillingtopassourway.
AstheExecutiveEditorfortheClient/ServerDatabaseteamatMacmillan
ComputerPublishing,Iwelcomeyourcomments.Youcanfax,email,orwrite
medirectlytoletmeknowwhatyoudidordidn'tlikeaboutthisbook-aswellas
whatwecandotomakeourbooksstronger.
PleasenotethatIcannothelpyouwithtechnicalproblemsrelatedtothetopicof
thisbook,andthatduetothehighvolumeofmailIreceive,Imightnotbeable
toreplytoeverymessage.
Whenyouwrite,pleasebesuretoincludethisbook'stitleandauthoraswellas
yournameandphoneorfaxnumber.Iwillcarefullyreviewyourcommentsand

sharethemwiththeauthorandeditorswhoworkedonthebook.
Fax:
317-817-7070
E-mail:
BryanGambrel
ExecutiveEditorProgramming
Mail:
MacmillanComputerPublishing
201West103rdStreet
Indianapolis,IN46290USA





©Copyright,MacmillanComputerPublishing.Allrightsreserved.







SamsTeachYourselfABAP/4®in21
Days


Day1
TheDevelopmentEnvironment
ChapterObjectives

WhatisR/3?
WhatIsthePurposeofR/3?
WhyDoYouNeedtoKnowThis?
DiscoveringWhatR/3LooksLike
UsingtheR/3SystemConceptualAreas
DiscoveringtheR/3UserInterface
UnderstandingBasis
UnderstandingClient/Server
R/3SystemArchitecture
PresentationServer
ApplicationServer
DiscoveringtheDatabaseServer
ConfiguringtheServers
DefininganR/3System
DefininganR/3Instance
ApplicationServerArchitecture
UnderstandingaUserContext
UnderstandingaRollArea
UnderstandingaDialogStep
UnderstandingRoll-In/Roll-OutProcessing
DiscoveringHowtheDataIsSenttothePresentationServer
UnderstandingtheComponentsofaWorkProcess
UnderstandingtheTypesofWorkProcesses
UnderstandingtheLogonClient
UnderstandingClient-DependentandClient-IndependentTables
UsingSAP'sOpenSQL
Portability
BufferingDataontheApplicationServer
AutomaticClientHandling
Summary



Q&A
Workshop
Quiz
Exercise1


ChapterObjectives
Afteryoucompletethischapter,youshouldbeabletoanswerthefollowing
questions:
WhatisanR/3system?
WhatisanR/3instance?
WhatisBasis?
WhatplatformsdoesR/3support?
WhatarethepossibleR/3systemconfigurations?
WhatistheR/3serverarchitecture?
Whatisalogonclient?


WhatisR/3?
R/3isanintegratedsuiteofapplicationsdesignedtohandlethedataprocessing
forlargecorporations.ItwasdevelopedinGermanybythecompanynamed
SAP(anacronymforSystemsApplicationsandProductsfordataprocessing).
TIP
WhenyouseethewordSAPbyitself,itispronounced"ess-ay-pea."
Whenitiscombinedwithanotherword,itispronouncedsap,asin
"treesap."Youshouldneversay"sap"whenreferringtothecompany
SAP.Alwayspronounceitas"ess-ay-pea."Saying"sap"isthesurest
waytosay,"Idon'tknowanythingaboutSAP."

WithinR/3isaruntimeenvironmentandanintegratedsuiteofapplication
programswritteninSAP's4GL-ABAP/4.Theseapplicationprogramsare
designedtomeetthedataprocessingneedsofverylargebusinesses.R/3andits
predecessorR/2areparticularlypopularwiththemanufacturingsector.
R/3isthesysteminwhichyourABAP/4programswillrun.Logically,itlooks
likeFigure1.1.
Figure1.1:ApplicationmodulesareallwritteninABAP/4,whichisinterpreted
byBasisexecutables,whichinturn,runontheoperatingsystem.

WhatisthePurposeofR/3?
ThesolepurposeofanR/3systemistoprovideasuiteoftightlyintegrated,
large-scalebusinessapplications.AfewofthesecanbeseenatthetopofFigure
1.1.ThestandardsetofapplicationsdeliveredwitheachR/3systemarethe
following:
PP(ProductionPlanning)
MM(MaterialsManagement)
SD(SalesandDistribution)
FI(FinancialAccounting)


CO(Controlling)
AM(FixedAssetsManagement)
PS(ProjectSystem)
WF(Workflow)
IS(IndustrySolutions)
HR(HumanResources)
PM(PlantMaintenance)
QM(QualityManagement)
Theseapplicationsarecalledthefunctionalareas,orapplicationareas,orat
timesthefunctionalmodulesofR/3.Allofthesetermsaresynonymouswith

eachother.
Traditionally,businessesassembleasuiteofdataprocessingapplicationsby
evaluatingindividualproductsandbuyingtheseseparateproductsfrommultiple
softwarevendors.Interfacesarethenneededbetweenthem.Forexample,the
materialsmanagementsystemwillneedlinkstothesalesanddistributionandto
thefinancialsystems,andtheworkflowsystemwillneedafeedfromtheHR
system.AsignificantamountofIStimeandmoneyisspentinthe
implementationandmaintenanceoftheseinterfaces.
R/3comesprepackagedwiththecorebusinessapplicationsneededbymostlarge
corporations.Theseapplicationscoexistinonehomogenousenvironment.They
aredesignedfromthegrounduptorunusingasingledatabaseandone(very
large)setoftables.Currentproductiondatabasesizesrangefrom12gigabytesto
near3terabytes.Around8,000databasetablesareshippedwiththestandard
deliveryR/3product.

WhyDoYouNeedtoKnowThis?
Thisisimportantforyou,asanABAP/4programmer,toknowbecausethese
applicationsareallwrittenentirelyinABAP/4.Thesearetheapplicationsyou
mustunderstandtobeaproficientdeveloperinR/3.
Forexample,assumeyouknowABAP/4andyouhavebeenaskedtowritea
financialreportsummarizingdebitsandcreditsbyfiscalyearforeachvendorin
theenterprise.YoumightknowhowtocodeinABAP,butwouldyouknowhow
tobegintosolvesucharequest?


OrperhapsyourjobentailsnewdevelopmentinABAP/4.Youareaskedto
designasystemthatprovidesstockquotationstopotentialbuyers.Ifyoudonot
knowthefinancialandsalesanddistributionsystems,youwon'tknowifyouare
creatingsomethingthatalreadyexistsinR/3.NorcanyouknowifthereareR/3
tablesthatalreadycontaindatasimilartooridenticaltothetypeofdatayou

wanttostore.Theseapplicationsarehighlyintegrated.Adeveloperwhotakes
theapproach"I'llbuildmyowntablesandkeepmyowncopiesofthedata,"
mightsoonfindhisdataisredundantandmustberoutinelysynchronizedwith
therestofthedatabase.Hehasbuiltanapplicationthatdoesnottakeadvantage
ofthehighlyintegratednatureoftheR/3environment.
Ionlypointthisoutbecausemanydeveloperswhowishtobecomeindependent
consultantsthinkthatlearningABAP/4isalltheyneedtodevelopintheR/3
system.Itiscertainlyagreatstart,butitisonlythestart.Theimportanceof
traininginafunctionalareacanbeoverlookedorunknowntothoseinterestedin
becomingproficientABAP/4consultants.Obviously,muchofthislearningcan
andwillbedoneonthejob.However,Ihopetoillustratethepointthatlearning
theABAP/4languageisonlythebeginningofalongjourneyintoSAP.Ifyou
desiretobesuccessfulasanindependentconsultant,youwilleventuallyneedto
acquirefunctionalareaknowledge.
TIP
YoucanlearnaboutthefunctionalareasbyreadingtheR/3online
reference(R/3menupathHelp->R/3Library).Itcontainstutorials
andinformationforallofthefunctionalareas.Ifyouhaveaccesstoa
systemwithIDESdata(InternationalDemoandEducationSystem),
youcanworkthroughtheR/3Libraryexercisesaswell.For
availabilityoftrainingcourses,contactSAP()
orLambtonCollege().


DiscoveringWhatR/3LooksLike
InaWindowsenvironment,youwillsignontoR/3eitherbychoosingamenu
pathfromtheStartmenu,orbydouble-clickingonanR/3icon,suchastheone
shownbelowinFigure1.2.
Figure1.2:TheR/3icononthedesktop.
TheR/3systemwillpromptyouforauserIDandpassword.Thelogonscreen

appearsinFigure1.3.YouwillfillinthesetwofieldsandthenpressEnter.
Figure1.3:TheR/3logonscreenpromptsyouforapassword.
TheR/3systemwillthendisplayacopyrightscreen,andwhenyoupressEnter,
thesystemwilldisplaytheR/3mainmenuasshowninFigure1.4.
Figure1.4:TheR/3mainmenu.

UsingtheR/3SystemConceptualAreas
Fromthemainmenu,youcangotothreeconceptualareasintheR/3system:
theApplicationsarea
theBasisarea
theDevelopmentWorkbench
IntheApplicationsarea,youinitiatetransactionsforthefunctionalareaswithin
R/3.Toaccessthese,fromtheR/3mainmenuchooseoneofthefollowing:
Logistics,Accounting,HumanResources,orInformationSystems.
IntheBasisarea,youcanruntransactionsthatmonitortheR/3systemitself.To
accesstheBasisarea,fromthemainmenuchoosethemenupathTools>Administration.Hereyouwillfindmanyperformance,tuning,anddatabase
administrationtools.
TheDevelopmentWorkbenchisusedtocreateandtestABAP/4programs.As
anABAP/4programmer,youwillspendmostofyourtimewithinthe
Workbench.ToaccesstheDevelopmentWorkbench,choosethemenupath


Tools->DevelopmentWorkbench.However,yourcodewillmostprobablyread
orupdateapplicationdata,andsoitwillbedestinedtobecomepartofthe
applicationarea.Withthatinmind,let'shavealookwithinanApplicationsarea
first.
Forourexample,imaginethatyouareaclerkworkinginanaccountspayable
department.Avendorcallstosayhisaddresshaschanged.Youputabookmark
inthemagazinearticleyouwerereading(ACriminologist'sViewofthe
ProblemswithCreativeAccounting)andproceedtoupdatehisaddressintheR/3

system.First,youreachtheAccountsPayablemenubychoosingthemenupath
Accounting->FinancialAccounting->AccountsPayable(seeFigure1.5).
Figure1.5:Themenupathtoupdateavendormasterrecord(part1).
Youthenbringupthevendormasterrecordmaintenancetransactionbychoosing
themenupathMasterRecords->Change(seeFigure1.6).Youwillseethe
ChangeVendor:Initialscreen.
Figure1.6:Themenupathtoupdateavendormasterrecord(part2).
FromtheInitialscreenshowninFigure1.7,youtypehisvendornumber,
tickmarktheAddresscheckbox,andpresstheEnterkey.Youwillthenseethe
Addressscreen(seeFigure1.8).
Figure1.7:TheVendorMasterUpdateTransaction:InitialScreen.
Figure1.8:TheVendorMasterUpdateTransaction:AddressScreen.
YouchangehisaddressandpresstheSavebutton(seeFigure1.9).
Figure1.9:Savingchangestothevendor'saddress.
Uponsaving,thesystemreturnsyoutotheChangeVendor:InitialScreen.Italso
displaysasuccessmessagewithinthestatusbarlocatedatthebottomofthe
screen(seeFigure1.10).
Figure1.10:TheInitialScreengivesverificationthattheaddresschangewas
made.
ThistransactionisrepresentativeofmanyofthetransactionsintheR/3system.


Mostmasterdatatransactionshaveasimilarlookandfeel.

DiscoveringtheR/3UserInterface
Figure1.11showsthemainmenuagain,withtheimportantscreenareas
identified.
Figure1.11:ImportantelementsofanR/3screen.
EveryR/3screencontainstheseelements:
Titlebar:Containsthetitleofthecurrentscreen.

Menubar:Thecontentsofthemenubarchangewitheachscreen.By
browsingthemenuswithinit,youcandiscoverallfunctionsthatare
possibleonthecurrentscreen.TheSystemandHelpmenusarepresenton
everyscreenandthemenuitemstheycontainneverchange.
Commandfield:Hereyouentercommandstobeexecuted.Forexample,
youcanlogoffbytyping/nexinthisfieldandpressingtheEnterkey.The
section"UsingtheCommandField"describesthisfieldinmoredetail.
Standardtoolbar:ContainstheCommandfieldandaseriesofbuttons.
Theywillneverchangeinappearance,position,orfunction,andtheywill
bepresentoneveryscreen.Somemightbegrayedoutiftheirfunctionality
iscurrentlyunavailable.
Applicationtoolbar:Changeswitheachscreen.Displaysbuttonsthatgive
youquickaccesstomenuitemsforthatscreen.
TIP
Ifyoupositionyourmousepointeroveranybuttonandletitrest
thereforafewseconds,R/3willdisplayatooltipdescribingits
function.InR/3itiscalledquickinfo.Itcontainsabriefdescription
ofthebuttonandthefunctionkeyassignedtoit.
InterfaceMenu:Enablesyoutocustomizethecharacteristicsoftheuser
interface,accesstheWindowsclipboard,andgenerategraphics.The
followingsectionwillcovermorefeaturesoftheInterfaceMenuindepth.
Screenarea:Thisisthebigareainthemiddleofthescreenthatdisplays
thereportdataorascreenfromadialogprogram.


Statusbar:Displaysmessages,thesystemID,sessionnumber,client
number,insert/overtypemodeindicator,andthecurrenttime.
Youcanturnmostscreenelementsonandoff.Ifyourscreendoesnotlookor
behaveliketheonedescribedinthischapter,followtheinstructionsinthenext
sectiontocorrectit.

WorkingwiththeInterfaceMenu
Theiconwiththreecoloredcirclesintheupperright-handcorneroftheR/3
windowiscalledtheInterfaceMenu.Withit,youcancustomizeuserinterface
settingssuchasscreencolors,fontsizes,andcursorbehavior.Toaccomplish
this,clickonceontheiconintheupperright-handcorneroftheR/3window
(seeFigure1.12).Amenuwillappear;clickontheOptionsmenuitem.
Figure1.12:TheInterfaceMenuwiththeOptionsmenuitemhighlighted.
ClickontheGeneraltabandchangeyoursettingstomatchthoseshownin
Figure1.13.Doingsowillensurethatyouruserinterfacewilllookandbehave
asdescribedinthisbook.
Figure1.13:TheGeneralInterfaceoptions.
Turnonallofthetoolbars(tickmarkthemall)andsetQuickInfotoQuick.
Tickmarkthefirstandlastofthemessagecheckboxesasshown.ClickApply.
TIP
YoumustclicktheApplyorOKbuttonbeforechoosinganothertab.
Ifyoudonot,yourchangeswillnottakeeffect.
ClickontheColorsInListstabandtickmarktheLinesInListscheckboxas
showninFigure1.14.ClickOKtoreturn.
Figure1.14:TickmarkingtheColorsInListscheckbox.
TheLinesInListsoptionturnsonoroffthedisplayofhorizontalandvertical
linesinyourreportoutput.Itshouldbecheckedsothatyouwillseetheeffectof


thelinegraphicstatementsyouwillcodelaterinthisbook.
TIP
Displayallfunctionkey(orf-key)settingsbyright-clickinganywhere
inthescreenarea.Thisworksonallscreens.Functionkeys1through
12arethetoprowofkeysonyourkeyboard.Functionkeys13
through24arethosesamekeyswiththeShiftkeyhelddown.For
example,F13isShift+F1.Forf-keys25through36,useCtrlinstead

ofShift.For37though48,useAlt.Forf-keyshigherthan48,hold
downCtrlandtypethekeynumberonthenumerickeypad.For
example,forF50,holddownCtrlandtype50onthenumerickeypad.

UsingtheCommandField
IntheStandardtoolbarisaninputareacalledtheCommandField.Hereyoucan
entersystemcommands.Foralistofthecommandsyoucanenterhere,putyour
cursorinthecommandfieldandpresstheF1key.
Thisfieldismostoftenusedtostartanewtransaction.
NOTE
Fornow,thinkofaprogramasatransaction.Thetwoareroughly
equivalent.Whenyoustartatransaction,youarestartingaprogram.

Insteadofchoosingamenupathtostartatransaction,youcanenterits
transactioncodeintothecommandfield.Atransactioncodeisa3or4character
codeassociatedwithatransaction-youcanuseittostartthetransactionwithout
usingamenupath.Everytransactionhasatransactioncode(alsocalleda
tcode).
Tofindthetransactioncodeforanytransaction,youwouldinvokethe


×