sap" certified application associate abap with ... - hservers.org

594
Puneet Asthana, David Haslam SAP" Certified Application Associate ABAP with SAP NetWeaver" 7.0

Upload: khangminh22

Post on 27-Apr-2023

2 views

Category:

Documents


0 download

TRANSCRIPT

Puneet Asthana, David Haslam

SAP" Certified Application Associate ABAP with SAP NetWeaver" 7.0

Acknowledgments

15

W e wro te this book pr imari ly as a way of teaching. W e bo th recognize that whe rea s y o u r exper ience g rows wi th every engagemen t o r project , f ew take the t ime to revisit subjects they have already mas te red . O n e of us w e n t th rough his original t ra ining wi th the "brand new" Release 2 .1 F o f SAP R/3 back in the last mi l l enn ium. W e k n o w that learning n e w techniques and n e w abilities wi th in a subject can be difficult .

SAP used to o f fe r del ta courses to ident i fy the differences , bu t these appea r to have fallen ou t of favor . Instead, the material is incorpora ted into the class mate-rial, and those w h o took the class pr ior to the change are no wiser to the change. The only place for y o u to obta in this in fo rmat ion is the release notes in the doc-umen ta t i on o r th rough w o r d of m o u t h . As the abilities wi th in ABAP con t inue to expand a n d m o r e capabili t ies a rc added , it is very easy to b e c o m e accus tomed to do ing th ings the same w a y even if the re a re be t te r ways of do ing it.

Even the t e rminology changes, somet imes faster than the capabilit ies. W e k n o w this because the re w e r e m a n y discussions f r o m o u r first chap te r to ou r last abou t the correct phrase or n a m e .

So o u r goal for this book was twofo ld . The p r imary e f for t was spen t on provid ing y o u . the developer , wi th the in fo rmat ion w e bel ieve is necessa iy to successfully b e c o m e an SAP Certified Deve lopmen t Associate — ABAP wi th SAP Ne tWeaver 7.0. Our secondary goal was to ident i fy the best t echn iques o r r e c o m m e n d a t i o n s f r o m SAP. This is no t an a l toge ther altruistic mot ive , because the cert if ication examina t ions (especially the profess ional level) becomes m o r e focused o n the best way of p e r f o r m i n g a task.

This book was much m o r e e f for t than e i ther of us though t it w o u l d be . Fortu-nately, w e had help .

W e would like to acknowledge Christ ine Arundel l and SAP Education for their invaluable assistance. Her no tes regarding the p r o p e r way of expla in ing a tech-n ique o r acting as a technical advisor w e r e very much apprec ia ted . Thank y o u for y o u r t ime and effor t .

16 Acknowledgments

W e would also like to acknowledge Stefan Proksch, ou r sen ior ed i tor at SAP PRESS. He led us th rough this very unfami l ia r wor ld of publishing, guid ing us th rough the process. As o u r guide th rough this wor ld , he kept us focused on the task at hand . His encou ragemen t and w o r d s of praise w e r e much apprec ia ted . As wi th p rogram deve lopmen t , t ime spen t u p f r o n t des igning simplif ies the end tasks and provides a much needed target. Thank y o u for y o u r assistance.

Addit ional ly David w o u l d like to thank his family for the i r suppor t and under-s tanding du r ing this endeavor . I would like to thank my grandchi ld ren , J o r d a n , Alexis, Kyle. Emily, W o o , and Tiyst in, for the i r uncondi t iona l love and under -s tanding. The w o r d s of encou rag e m e n t and suppor t f r o m o n e in par t icular w e r e most apprecia ted; y o u and I bo th k n o w w h o y o u are (and I k n o w that y o u are a ve iy special child). M o r e than any o the r , I w o u l d like to thank my wife . Patti, for unde r s t and ing my long hours and suppor t ing the project . She is my founda t ion , t he haven in my life. Wi thou t her , I would be lost. I a m forever grateful f o r meet-ing her.

Addit ional ly Puneet would like to express s incere apprecia t ion to the fol lowing individuals for the i r invaluable con t r ibu t ion t h roughou t his j o u r n e y in wr i t ing this book : I w o u l d like to thank to my dear wife , Anita, for her unf l inch ing love, suppor t , and inspira t ion. Though taken to he r wi ts ' end wi th this seemingly never -end ing book project , she not only managed o u r family s ingle-handedly for the past several m o n t h s , bu t also, she chose to smile and encouraged m e to fulfill my d r e a m of wr i t ing this book. Thanks to my lovely chi ldren, six-year-old daugh-ter Amishi and three-year-old son Anchit , for being a cons tant source of u n e n d -ing happiness and j o y a n d for the i r love and unde r s t and ing that Daddy cou ldn ' t play wi th t h e m as he had to comple te this project . Thanks to my dear parents , w h o nu r tu r ed m e and instilled in m e a s t rong sense of values and principles, and w h o have p r o f o u n d l y inf luenced w h o I have become . Thanks to my b ro the r s and sisters for providing m e a loving and encourag ing e n v i r o n m e n t dur ing my foun-dat ional yea r s . Finally, I w o u l d like to thank my co-author David Haslam. for the o p p o r t u n i t y to work toge ther on this project .

David H a s l a m

Principal Pla t inum Deve lopmen t Consul tant

P u n e e t A s t h a n a Principal Consul tant

Preface

The SAP PRESS Certif ication Scries is des igned to p rov ide a n y o n e prepar ing to take an SAP cert if ied exam with all of the review, insight, a n d practice they need to pass the exam. The series is wr i t t en in practical, easy-to-follow language that p rovides targeted con ten t focused j u s t on w h a t y o u need to k n o w to successfully take y o u r exam.

This book is specifically wr i t t en for those prepar ing to take the SAP Certified D e v e l o p m e n t Associate — ABAP with SAP Ne tWeaver 7 .0 exam, so if y o u ' v e purchased this book, y o u ' r e obviously in teres ted in learning h o w to successfully pass the cert if icat ion exam, a n d y o u ' v e c o m e to t he r ight place. This book will he lp y o u b e c o m e an SAP Certified Deve lopmen t Associate in ABAP. It is y o u r first s tep to propel y o u r career by set t ing your se l f apar t f r o m y o u r peers . The cer-tification exam verif ies y o u r knowledge of the f u n d a m e n t a l s o f Release 7 .0 o f the SAP Ne tWeaver Applicat ion Server ABAP. This includes knowledge ob ta ined f r o m a t t end ing SAP training courses in the ABAP curr iculum and project experi-ence. To help p repa re y o u to pass the exam, we'l l cover the facts and appl icat ions of each topic discussed in this book .

You'll find all of the practical, real-world in fo rmat ion y o u need to get a clear unde r s t and ing of the topics that will be covered on t he exam and insightful tips about the types of ques t ions you ' l l e n c o u n t e r and the strategies to use to answer correctly. The book is closely al igned wi th t he course syllabus and the exam structure , so all of the in fo rmat ion p rov ided is re levant and applicable to wha t y o u need to k n o w to p repa re fo r the SAP Certified Deve lopmen t Associate — ABAP with SAP Ne tWeaver 7 .0 exam. W e explain the SAP produc t s and features using practical examples and s t ra igh t forward language, so y o u can p repa re for the exam and improve y o u r skills in y o u r day-to-day work as an ABAP deve loper .

Each book in t he series has been s t ructured and des igned to highlight wha t y o u really need to k n o w . The chapters begin wi th a clear list of the learning objec-tives for the chapter such as this example :

18 Preface

What You'll Learn:

• H o w to p repa re for the exam

• Unders tand ing the general exam s t ruc ture

• Practice ques t ions and prepara t ion

From there, you ' l l d ive into the chap te r a n d get right in to the test object ive cov-erage. So let 's take a look at h o w the book is s t ruc tured .

Structure of This Book

Let's discuss h o w y o u can use this book to p r e p a r e for the exam. This book is d iv ided in to two sections:

• P a r t 1 contains the general in t roduct ion to this book and the certification ex-aminat ions . This section will p rovide y o u wi th an overv iew of the certification process and the benefi t to y o u and to y o u r cus tomer or company . We'll discuss both the pu rpose of this certification examinat ion and provide in format ion on addit ional certification examinat ions that are available b e y o n d this one .

• P a r t 2 o f this book is a b r e a k d o w n of the topics covered in t he cert if ication examina t ion fo r C_TAW12_70, t he SAP Certified Deve lopmen t Associate — ABAP with SAP Ne tWeaver 7.0. Each chap te r conta ins a similar s t ruc ture to assist wi th unde r s t and ing that por t ion of the cert if ication examina t ion .

Part 2 is the core of the book a n d discusses each exam topic and de t e rmines the key concepts . These key concepts are then expla ined a long wi th impor t an t infor-mat ion that will p rov ide the context for unde r s t and ing . Each chap te r is b roken d o w n into o n e o r m o r e subtopics according to complexi ty . I l lustrat ions and dia-g rams are inc luded t h roughou t to ensu re that y o u unde r s t and impor t an t con-cepts.

Th roughou t the book, w e ' v e also p rov ided several e l emen t s that will help y o u access useful in format ion :

• Tips call out useful in format ion abou t related ideas and p rov ide practical sug-gest ions for h o w to use a par t icular func t ion .

• Notes provide o the r resources to explore o r special tools o r services f r o m SAP that will help y o u wi th the topic u n d e r discussion. The fol lowing is an exam-ple of such a Note box.

Structure of This Book 19

Note

The content provided in each chapter and subtopic does not exhaustively cover everything that appears on the exam. In other words, the certification guide does not cover every exam question, but rather it acts as a refresher to highlight the major points for each topic. In addition, it points out areas where further review is needed.

Each chap te r that covers an exam topic is organized in a similar fashion so y o u can b e c o m e familiar wi th the s t ruc ture a n d easily f ind the in format ion y o u need . Here ' s an example of a typical chapter s t ructure :

• I n t r o d u c t o r y bu l l e t s

The beg inn ing of each chap te r discusses the t echn iques y o u mus t mas te r to be cons idered prof ic ient in the topic for t he cert if ication examina t ion .

• Topic i n t r o d u c t i o n This sect ion provides y o u wi th a genera l idea o f the topic at h a n d to f r a m e fu tu re sections. It also includes object ives for the exam topic covered .

• Real -wor ld s c e n a r i o

This par t shows a scenar io that p rovides y o u wi th a case w h e r e these skills would be beneficial to y o u o r y o u r c o m p a n y .

• Ob jec t ives

This sect ion is fo l lowed by one , bu t o f t en m o r e than one . sect ion reviewing the material the au tho r s feel p rovides y o u wi th the necessary in fo rmat ion to pass this po r t ion of the test . This sect ion provides the material y o u mus t unde r s t and to successfully pass the cert if ication examina t ion .

• Key c o n c e p t r e f r e s h e r

This sect ion is fo l lowed by a key concept r e f reshe r w h e r e the m a j o r concepts of the chapter are ident i f ied. This section ident i f ies the tasks y o u will need to be able to p e r f o r m proper ly to answer the ques t ions o n the cert if ication examina t ion .

Note

You should pay particular attention to the points raised in the key concept refresher section and those from the objectives section.

20 Preface

• M a i n p a r t

The next section provides the object ives of t he this sect ion o f the test. This in-

cludes ident i fying m a j o r points of this topic that a re discussed in the chapter .

Of ten w e ident i fy a general weight ing SAP uses for this topic. To s implify the

discussion, w e have p roduced a general g r o u p of th ree categories o r ranges

(high, average, and low weight ing) . You should use this in fo rmat ion to assist

y o u in de t e rmin ing which chapters y o u should spend y o u r t ime s tudying to

maximize y o u r score.

Those chapters that are des ignated as low have the fewes t n u m b e r o f ques-t ions on the cert if ication examina t ion . Those wi th a des ignat ion of average have an average o r m e d i u m n u m b e r o f ques t ions on the certification exami-na t ion . The chapters wi th a high weigh t ing have m o r e ques t ions than the o the r chapters .

The chap te r wi th the highest we igh t ing conta ins significantly m o r e ques t ions o n the cert if ication examina t ion than any o ther . Unsurpris ingly, Chapter 9, Basic ABAP Programs and Interface Creat ion, wh ich discusses general ABAP program design, has the highest weight ing of the examina t ion .

• I m p o r t a n t t e r m i n o l o g y

Just p r io r to the practice examina t ion , w e provide a sect ion to rev iew impor-tant t e rminology . This may be fo l lowed by def in i t ions of var ious t e rms f r o m the chapter .

• P rac t i ce q u e s t i o n s The chap te r then provides a series o f practice ques t ions related to the topic of the chapter . The ques t ions are s t ruc tu red in a similar way to the actual ques t ions on the cert if ication examina t ion (see below).

• P rac t i ce q u e s t i o n a n s w e r s a n d e x p l a n a t i o n s Following the practice exercise a re the solut ions to the practice exercise ques-t ions . As part of the answer , w e discuss w h y an answer is cons idered correct o r incorrect .

W h e r e a s s o m e of the ques t ions in the practice re fe rence actual code, y o u will find that in the actual cert if ication examina t ion there is a slightly h igher num-be r o f ques t ions related to actual code solving. However , w e feel tha t an unde r s t and ing of actual processes will a l low y o u to ident i fy and correctly solve these types of ques t ions . As a consequence , we have a t t emp ted to explain processes that occur and wha t w e cons ider the best way of solving

Glimpse into the Exam Structure 21

issues. These techniques can be useful to y o u in y o u r no rma l work in addi t ion to passing the examina t ion .

• Take a w a y

This section p rov ides a take away o r review section ident i fy ing wha t areas y o u should n o w u n d e r s t a n d . The re f reshe r sect ion identif ies t he key concepts in the chapter . W e also p rov ide s o m e tips related to the chapter .

• S u m m a r y Finally, w e conc lude wi th a s u m m a r y of the chapter , which again provides a s u m m a r y of the con ten t covered in the chapter .

Note

You should be aware that the practice exercise questions are for self-evaluation purposes only and do not appear on the actual certification examination. Answering the practice exercise questions correctly is no guarantee that you will pass the certification exam.

Glimpse into the Exam Structure

To unde r s t and the s t ruc ture of this cert if ication success guide, it is impor t an t to unde r s t and the base s t ruc ture of the exam. W e only touch u p o n the topic here because Chapter 1, ABAP Deve lopmen t Certification Track — Overv iew, covers the exam s t ruc ture in detail .

T w o basic e l emen t s de f ine the exam s t ruc ture for the associate and var ious levels of certification available. These e l emen t s a re as fol lows:

• C o m p e t e n c y level Compe tency is w h a t y o u are expected to be able to d o at a specific level descr ibed . In s imple terms, if y o u have reached a competency , then y o u can do the tasks descr ibed by that compe tency . SAP Education has deve loped a set of progress ive c o m p e t e n c y levels. As y o u become m o r e exper ienced , y o u r compe tenc ie s move in s equence f r o m level A to D. The competenc ies include:

• Accomplish de f ined tasks (level A)

• Build p roposed solut ions (level B)

• Conceptual ize complex processes (level C)

• Design integrated strategies (level D)

22 Preface

For example , a s imple def in i t ion of the level A c o m p e t e n c y is the ability to accomplish de f ined tasks du r ing sys tem implemen ta t ion . As an associate, y o u should be able to carry out de f ined tasks given to y o u w h e n little to n o ambi-guity exists. For level D. y o u m a y devise a r o a d m a p and r e c o m m e n d a t i o n to a part icular solut ion o r issue.

• Exam t o p i c

This e l emen t is much m o r e familiar . ABAP is a complex p r o g r a m m i n g lan-guage for bus iness appl icat ions wi th m a n y parts . A team of exper t s devised which topics should be tested in each exam. This al lows a target f o r the test deve lopmen t , but in addi t ion it provides y o u a list of focus areas to prepare .

Tip

The chapter that follows dives into great detail for each level of the exam, includ-ing a topic and competency breakdown. Please reference Chapter 1, A8AP Development Certification Track — Overview, for additional information.

You should unde r s t and t he concept of c o m p e t e n c y and exam topics n o w . It is impor t an t to unde r s t and that they work toge ther . The compe tency areas are appl ied to separate topics in the exam. Likewise, this book is also b r o k e n d o w n by these same topics to set the focus and align con ten t for exam prepara t ion .

The exam topics may over lap b e t w e e n the c o m p e t e n c y areas in t e rms of a subject such as objects , but they are u n i q u e in content according to t he compe tency . For example , activity at level A is cons idered m o r e of a design e lement and explores u n i q u e cons t ruc t ion of objects . Activity at level B examines a m o r e f u n d a m e n t a l u n d e r s t a n d i n g of classes and me thods . Thus, it 's possible to discuss opera t iona l solut ions for objects in o n e topic, whe rea s a separa te topic covers m o r e strategic p rob lems o r concepts . This will b e c o m e ev iden t in the chapter con ten t and prac-tice ques t ions .

Practice Questions

W e w a n t to give y o u s o m e background on the test ques t ions be fo re y o u encoun-ter the first f ew in the chapters . Jus t like the exam, each ques t ion has a basic s t ructure :

Practice Questions

Q u e s t i o n s t i m u l u s

The ques t ion s t imulus varies wi th the d i f fe ren t ques t ions , bu t its in ten t ion is

to presen t a s i tuat ion or scenar io as context for the ques t ion . The s t imulus

complexi ty d e p e n d s on the c o m p e t e n c y level.

Ac tua l q u e s t i o n

The ques t ion comes next and relates to the s t imulus . Read the ques t ion care-

fully and be su re to cons ider the details f r o m the s t imulus because they can

impact the ques t ion .

Q u e s t i o n h i n t

This is no t a formal t e rm, but w e call it a h int because it will tell y o u h o w

m a n y answers are correct . If only o n e is correct , normal ly it will tell y o u to

choose the correct answer . If m o r e than o n e is correct , like the actual certifi-

cation examina t ion , it will no t indicate t he correct n u m b e r of answers .

A n s w e r s

The answers to select f r o m d e p e n d on the ques t ion type. The fol lowing ques-

t ion types a re possible:

• M u l t i p l e r e s p o n s e

M o r e than o n e correct a n s w e r is possible .

• M u l t i p l e cho ice Only a single answer is correct .

• T r u e / f a l s e Only a single a n s w e r is correct . These should be min imal , especially as y o u exper ience the m o r e advanced exams.

• Fill in t h e b l a n k This type is o f ques t ion is nearly not f o u n d o n t he associate examina t ion , bu t is f o u n d on the professional-level exam. Al though capitalization does not mat ter , only a l imited n u m b e r of answers a re cons idered valid. You should the re fo re be careful wi th typing a n d spelling.

• S e q u e n c e / r a n k i n g This type of ques t ion will also have a single correct answer . The answers will p rovide the same op t ions in d i f fe rent o rder , and y o u mus t select the correct sequence .

24 Preface

Caution

Media can be presented in a test question as part of the stimulus. For example, a diagram or a code block can be given, followed by the question based on this enriched content. If the question does not appear to make sense by itself, you should look for an exhibit button to display the media.

Summary

With this cert if ication success gu ide you ' l l learn h o w to approach t he con ten t and key concepts highl ighted for each exam topic. In addi t ion , in each chap te r you ' l l have t he o p p o r t u n i t y to practice wi th sample test ques t ions . Af ter answer-ing the practice ques t ions , you ' l l be able to rev iew the explanat ion of the answer , which dissects the ques t ion by explaining w h y the answers a re correct o r incor-rect. The practice ques t ions give y o u insight into the types of ques t ions y o u can expect , wha t the ques t ions look like, and h o w the answers can relate to the ques-t ion. Under s t and ing the compos i t ion of the ques t ions and seeing h o w the ques-t ions and answers work toge ther is j u s t as impor t an t as unde r s t and ing the con ten t . This book gives y o u the tools and unde r s t and ing y o u need to be success-ful. A r m e d wi th these skills, you ' l l be well o n y o u r way to becoming an SAP Cer-tified Deve lopmen t Associate in ABAP.

Part I General Introduction

ABAP Development Certification Track — Overview

Techniques You'll Master:

• Understand the different levels of certification

• Identify the scoring in the exams

• Understand the portion of the certification exam associated with y o u r skills

• Learn about fur ther specifics of the ABAP Development Certification Track

28 Chapter 1 ABAP Development Certification Track — Overview

Few credent ia ls in the bus iness wor ld carry the value of SAP cert if icat ion. Those w h o hold it have h o n e d their skills t h rough r igorous s tudy or direct exper ience . They have demons t r a t ed the i r abilities by passing d e m a n d i n g , process-or iented exams. Regardless of w h e t h e r y o u ' r e an SAP par tner , cus tomer , o r user . SAP cer-tif ication can give y o u a distinct compet i t ive advantage.

Over the past two years , SAP Global Educat ion por t fo l io m a n a g e m e n t comple ted a comprehens ive rev iew of SAP's cert if icat ion strategy and created a r o a d m a p for enhanc ing the value of the cert if icat ion p rog ram as a key bus iness enabler for SAP going fo rward . This p rogram focuses on bui lding a value-add cert if ication c o m m u n i t y for SAP-certified individuals and helping SAP cus tomers and part-ners leverage certification as a benchmark for engaging, recrui t ing, o r t ra ining proper ly skilled SAP resources . The r o a d m a p out l ines the requi red steps to intro-duce mul t i t ie red career-enabl ing cert if ication tracks and advanced-level certifica-tion to be t te r address the needs of the markets .

Certification Exam Scoring Changes

To publish m o r e job- task o r ien ted cert if ication exams, and to p rov ide certifica-tion at the advanced profess ional level, SAP has m a d e several impor t an t changes to the test models . First, t he test design b luepr in t is created o n the basis of a j o b -task analysis tha t is created and validated wi th the he lp o f consul tants actively involved in re levant projects .

SAP also changed the exam scoring mode l s for all exams publ i shed a f t e r Septem-be r 2 0 0 7 to a d i c h o t o m o u s scoring model . The d i c h o t o m o u s scoring model scores mul t ip le - response ques t ions as e i ther correct o r incorrect a n d does not give partial grades fo r responses . This be t te r reflects the need for SAP cus tomers and par tners to k n o w w h e t h e r a certif ied individual can p e r f o r m a task to the comple t e satisfaction of all conce rned . The consis tency in the diff iculty level o f t he exams is re inforced by tho rough s tandard-se t t ing processes, w h e r e the test con ten t is ra ted by a panel of subject ma t t e r exper ts to d e t e r m i n e the final cut score.

Every quest ion should be answered . Leaving a quest ion blank is equivalent to a false response. All tests will be migrated over to the n e w d icho tomous scoring model by mid-2009, and the master certification is expected to be released in 2010 .

Certification Exam Scoring Changes Chapter 1 29

N o t e

For older exams, which were released prior to September , 2 0 0 7 and are no t ent i -tled, associate, professional, or master , tes t takers received points for each sec-t ion of a ques t ion answered correctly.

If a quest ion has five parts and t he test taker answers th ree parts correctly, he would ge t th ree o u t of five of t h e possible credit available for tha t ques t ion .

Certification Levels

You c a n n o w o b t a i n c e r t i f i c a t i o n s a t t h r e e l eve l s o f e x p e r t i s e - a s s o c i a t e , p r o f e s -

s i o n a l , a n d m a s t e r . T h e s e c e r t i f i c a t i o n s c a n h e l p y o u v a l i d a t e y o u r ski l ls a n d

k n o w l e d g e a n d ga in t h e e x p e r t i s e a n d c r e d e n t i a l s y o u n e e d t o l ead y o u r o r g a n i -

z a t i o n ' s e f f o r t s t o i m p l e m e n t SAP s o f t w a r e , m a t u r e i ts t e c h n o l o g i c a l c a p a b i l i t i e s ,

a n d t r a n s f o r m its IT l a n d s c a p e . F i g u r e 1 . 1 s h o w s t h e p r o g r e s s i o n o f l eve l s w i t h

r e l a t i o n t o y o u r e x p e r i e n c e .

M A S T E R /

Design integrated \ strategies to compose,

develop and roadmap solutions and architecture .

P R O F E S S I O N A L / ^

Conceptualize complex processes to blueprint,

modify and optimize integrated scenarios.. .

A S S O C I A T E /

Build proposed solutions by researching valid options to specify

and imp lement . . .

Accomplish defined tasks to perform, test

and/or customize funct ional i ty . . .

Figure 1.1 Certification Levels

30 Chapter 1 ABAP Development Certification Track — Overview

• Assoc i a t e c e r t i f i c a t i o n This cert if ication covers the f u n d a m e n t a l knowledge r equ i r emen t s for an SAP consul tant , ensur ing the successful acquisi t ion of b road SAP solut ion knowl-edge and skills. With associate-level cert if ication, y o u can:

• Gain an external ly recognized mark of excellence that clients seek

• D i f f e r en t i a t eyour sc l f in a c r o w d e d marketp lace

• Execute y o u r tasks wi th conf idence a n d skill

• Access a c o m m u n i t y of SAP associate-level certif ied peers

• P r o f e s s i o n a l c e r t i f i c a t i o n This advanced certification requi res p roven project exper ience , bus iness pro-cess knowledge , and a m o r e detai led unde r s t and ing of SAP solut ions . Wi th professional- level cert if ication, y o u can:

• Demons t r a t e both y o u r exper ience and y o u r exper t ise th rough a r igorous test ing process

• P romote a m o r e globally applicable accredi tat ion wi th h igher billable rates

• Lead and execute tasks and engagemen t s

• Access a c o m m u n i t y of SAP professional-level cert if ied peers

• M a s t e r c e r t i f i c a t i o n This cert if ication involves d e m o n s t r a t i n g expert-level unde r s t and ing of a spe-cific area of SAP so f tware a n d the ability to dr ive innova t ion and solut ion opt imiza t ion th rough in-depth knowledge and vision. Certif ication at this level requires b road projec t exper ience , comprehens ive SAP produc t knowl-edge. and the ability to create a fu tu r e IT vision wi th in complex project envi-r o n m e n t s . With master-level cert if ication, y o u can:

• Secure y o u r place in an exclusive c o m m u n i t y of vis ionary exper ts

• Pass a peer- reviewed, comprehens ive admiss ions process

• Def ine and guide long-term strategy

• Participate in master-level brief ings, co l loquiums, and indus t iy events

No course o r set o f courses is r equ i red to take a part icular cert if ication exam. SAP does p rov ide a listing o f r e c o m m e n d e d course work to help y o u p repa re (for this examina t ion , see the section Becoming an SAP Certified ABAP Deve lopmen t Associate — Overv iew in this chap te r and Chapter 2, Courses and Experience).

Certification Exam Scoring Changes Chapter 1 31

Tip

It is not necessary for you to have completed a lower-level (associate) exam to take a higher-level (professional) exam; however, many professional-level certi-fication seekers may find it valuable.

Advanced Certification Levels

SAP is mov ing toward higher-level i tem wri t ing m e t h o d s and m o r e advanced assessment t echniques to be t te r test unders t and ing , appl icat ion, and analytical skills ra ther than knowledge recall. In addi t ion , the tests for the h igher levels of cert if ication have been revised to be m o r e clearly job- task aligned and the re fo re reflective of actual exper ience .

The n e w strategy focuses o n adding value to the certif ied individual . Certified consul tants will be of fe red the o p p o r t u n i t y to j o i n the n e w cert if ication commu-nity and access a w ide range of benef i ts . The 2 0 0 6 survey of exist ing consul tants p inpo in t ed the des i re for con t inuous learning, and SAP Education will be outl in-ing clear paths , including fast tracks for exist ing consul tan ts to move u p w a r d o r across in to fu r the r levels. Existing cert i f icat ions will retain the i r validity.

You can sit for a par t icular SAP cert if ication exam a m a x i m u m of th ree t imes. You mus t wai t 30 days af ter y o u have taken an exam be fo re y o u can sit f o r it again. This is to give y o u t ime for addi t ional p repara t ion in those areas w h e r e y o u w e r e unsuccessful .

Tip

If you are unsuccessful in passing your certification exam after two attempts, and if you have not previously taken SAP training classes, we highly recommend you supplement your current knowledge by completing the training offered by SAP.

The fee for cert if ication retakes is the same as the initial exam. No candida te may sit for the same examina t ion for the same release m o r e than th ree t imes. A can-didate w h o has failed an examina t ion th ree t imes for a specific release m a y not a t t empt that examina t ion again until the next release.

32 Chapter 1 ABAP Development Certification Track — Overview

Note

On arriving at the test center, you will be required to present two valid forms of ID, of which one must be a valid photo ID, such as passport, driver's license, or government-sponsored ID card.

Becoming an SAP Certif ied ABAP Development Associate — Overview

T h e c o d e u s e d to r e f e r e n c e t h e e x a m i n a t i o n f o r th is b o o k (also k n o w n as t h e

Booking Code) is C _ T A W 1 2 _ 7 0 . T h e c u r r e n t Cer t i f ica t ion Test is en t i t l ed SAP Cer-

t i f ied D e v e l o p m e n t Assoc ia te — ABAP w i t h SAP N e t W e a v e r 7 .0 .

T h e cer t i f i ca t ion test f o r SAP Cer t i f ied D e v e l o p m e n t Associa te — ABAP w i t h SAP N e t W e a v e r 7 . 0 ver i f ies i n - d e p t h k n o w l e d g e in t h e a rea o f ABAP d e v e l o p m e n t . Th is ce r t i f i ca te p r o v e s tha t t h e c a n d i d a t e has a f u n d a m e n t a l u n d e r s t a n d i n g w i t h i n th is p ro f i l e a n d is ab le to a p p l y t h e s e skills pract ical ly u n d e r s u p e r v i s i o n in a p ro j ec t e n v i r o n m e n t .

Associate Examination Specifics

• S o f t w a r e : S o f t w a r e c o m p o n e n t s : SAP N e t W e a v e r 7 . 0

• N u m b e r o f q u e s t i o n s : 9 0

• D u r a t i o n : 1 8 0 m i n u t e s

Associa te ce r t i f i ca t ions a re ta rge ts f o r t h o s e w i t h b e t w e e n o n e a n d t h r e e y e a r s o f

k n o w l e d g e a n d e x p e r i e n c e . T h e p r i m a r y sou rce o f k n o w l e d g e a n d skills is ba sed

o n t h e c o r r e s p o n d i n g t r a in ing ma te r i a l .

Note

This certification may have a different passing score from previous or different certification exams (a passing score is calculated by experts in the field and varies between versions of the associate examination for different releases and from the professional examinations).

Remember that for multiple response items, no partial is credit given.

Becoming an SAP Certified ABAP Development Professional — Overview Chapter 1 33

Competency Areas

Table 1.1 and Table 1.2 will he lp y o u ident i fy the c o m p e t e n c y areas covered in this test . The percentage indicates the por t ion of the test dedica ted to a part icular compe tency area. The section WAYS TO ATTAIN ident i f ies s tandard SAP Education courses that cover t he material tested in the cert if ication examina t ion . The pri-mary course focuses specifically on the material in the cert if ication examina t ion , whe rea s the Alternat ive and O t h e r co lumns ident i fy o the r courses that conta in the same material .

Competency Importance

Build solutions by independently researching valid implementation options. Based on profound under-standing and deep application skills, project requirements can be trans-ferred into solid customer solutions in:

4 0 %

Ways to Attain

Topic Primary Alternative Other

Basic ABAP program and interface creation

TAW10 BC400, BC402

Class identification analysis and design

TAW12 BC401

Enhancement and modifications TAW12 BC425, BC427

Table relationships TAW10 BC430

Table 1.1 Build Proposed Solutions by Independently Researching Valid Implementation Options

21 Chapter 1 ABAP Development Certification Track — Overview

C o m p e t e n c y I m p o r t a n c e

Accomplish and identify solut ions for def ined project tasks. Based on in-dep t h knowledge and basic under -s tanding. identified tasks can be per-formed during system implementa -t ion. configurat ion, and test ing in t he areas of:

6 0 %

W a y s t o a t t a i n

Topic Pr imary Al te rna t ive O t h e r

SAP NetWeaver Overview TAW10 N W 0 0 1 SAPNV

ABAP Workbench usage TAW10 8C400. BC401

ABAP Debugger program usage TAW10 BC400. BC402

ABAP types and da ta objec ts TAW10 8C400

Internal tab le defini t ion and use TAW10 8C400

SQL s t a t emen t s including upda t e s trategies

TAW10, TAW11

8C400, BC414

ABAP Dictionary TAW10 8C430

Unicode TAW11 8C402

Classical screens (Dynpros) and selection screens

TAW10 BC400

ALV Grid Control TAW11 8 C 4 0 5

User interfaces (Web Dynpro) TAW12 NET310

Table 1.2 Accomplish Solutions for Defined Project Tasks

T o p r e p a r e f o r t h i s e x a m , r e m e m b e r t h a t t h e e x a m c o v e r s a b r o a d r a n g e o f t o p i c s

a n d s u b j e c t s , a n d it is n o t t h e r e f o r e p o s s i b l e t o a s k m a n y q u e s t i o n s o n a n y o n e

t o p i c . C e r t a i n t o p i c s , s u c h as Basic A B A P p r o g r a m a n d i n t e r f a c e c r e a t i o n , c lass

i d e n t i f i c a t i o n a n a l y s i s a n d d e s i g n , e n h a n c e m e n t s a n d m o d i f i c a t i o n s . A B A P t y p e s

a n d d a t a o b j e c t s , a n d t h e A B A P D i c t i o n a i y r e c e i v e m o r e e m p h a s i s t h a n t o p i c s

s u c h as A B A P d e b u g g e r p r o g r a m u s a g e , U n i c o d e , a n d ALV G r i d C o n t r o l .

Becoming an SAP Certified ABAP Development Professional — Overview Chapter 1 35

Tip

You should use the percentage guides from Table 1.1 and Table 1.2 to guide the allocation of your preparation time.

As y o u will see in the practice exam ques t ions , a good unde r s t and ing of var ious p r o g r a m m i n g t echn iques and the system archi tecture is helpful w h e n choosing the best a n s w e r f r o m a list of possible approaches . R e m e m b e r that y o u must average t w o minu te s per ques t ion ( there a rc 9 0 ques t ions a n d a t ime limit o f 180 minutes) , so arriving at the correct answer quickly is essential to comple t ing the examina t ion .

For these types of ques t ions w h e r e mult iple answers are correct , it may be help-ful to use a selection and e l iminat ion strategy. You can possibly e l iminate answers that a re factually w r o n g whi le selecting answers that a re clearly correct . This leaves f ewer answers y o u migh t no t be sure of, t hus speed ing u p the selec-t ion process. Chapter 2, Courses and Experience, p rovides several t echniques to he lp y o u n a r r o w d o w n the op t ions to ques t ions .

For most ques t ions in this examina t ion , the answers can be f o u n d in the course material listed for that area (see the ways to at tain co lumns above). Al though sev-eral answers may be very similar, take suff icient t ime to clearly unde r s t and the mean ing of each a n s w e r ra ther than rushing. That will help y o u dist inguish which answers arc correct .

Normally, the m o r e ABAP exper ience y o u have, the easier y o u will f ind the examina t ion . Be conscious that t he examina t ion is based on SAP Ne tWeaver 7 .0 and not on prev ious releases. In places w h e r e the re a re d i f fe rences b e t w e e n Release 7 .0 a n d prev ious releases, the examina t ion will normal ly focus on Release 7.0, a l though in several cases the way the ques t ion is phrased will indi-cate that it refers to a previous release.

Wherea s the re are no "trick" ques t ions o r answers , y o u should th ink th rough the choices to m a k e sure y o u unde r s t and the exact mean ing and impact of each op t ion before making y o u r select ion. Some of the p rog ramming ques t ions can involve a significant a m o u n t of code or p rov ided detail . It can be t ime-consum-ing to ident i fy wha t is actually being asked. It is impor t an t to unde r s t and the ques t ion be fo re a t t empt ing to a n s w e r it.

All of the ques t ions in this exam prov ide mult iple answers . Some of these r equ i re y o u to select t he single correct op t ion , whe rea s o the r s have mul t ip le correct

23 Chapter 1 ABAP Development Certification Track — Overview

responses . In the Preface of this book , w e discussed the var ious types o f ques-t ions y o u can expect . R e m e m b e r that the re is no partial scoring, a n d mult iple-response ques t ions a re scored as e i ther correct o r incorrect .

Note

You are not allowed to use any reference materials during the certification test (no access to online documentation or to any SAP system). You will require a Photo ID to be allowed to take the test.

As the cert if ication process is ever evolving, y o u should always check the certifi-cation site for changes to the above in fo rma t ion . The cert if ication site can be f o u n d on the SAP w e b site at http://www.sap.com. From there , go to SAP ECOSYS-TEM A N D PARTNERS • SERVICES • EDUCATION • CERTIFICATION. T h e n u s e t h e c e r t i f i -

c a t i o n finder f o r S A P N E T W E A V E R • D E V E L O P M E N T • D E V E L O P E R / D E V E L O P M E N T

CONSULTANT.

Becoming an SAP Certified ABAP Development Professional — Overview

The professional-level exam provides two d i f ferent tests: P_ABAP_SI_70 and P_ABAP_GUI70. There is an over lap of the knowledge of P_ABAP_GUI70 and P_ABAP_SI_70. You will find all the topics of P_ABAP_GUI70 in P_ABAP_SI_70, but s o m e topics in P_ABAP_SI_70 will not be f o u n d in P_ABAP_GUI70.

S A P C e r t i f i e d D e v e l o p m e n t P r o f e s s i o n a l — A B A P S y s t e m I n t e g r a t i o n — S A P N e t W e a v e r 7 . 0

The book ing code fo r this examina t ion is P_ABAP_SI_70. The cur ren t certifica-tion test is enti t led SAP Certified Deve lopmen t Professional — ABAP System Integrat ion - SAP Ne tWeaver 7.0.

The cert if ication test for SAP Certified Deve lopmen t Professional — ABAP Sys-tem Integrat ion — SAP Ne tWeaver 7 .0 verifies in-depth knowledge in the area of ABAP system interfaces. The d i f fe rence b e t w e e n the associate and t he Profes-sional is that m o r e skills are included. W here a s a cert if ied associate is expected to comple t e tasks, a cert if ied profess ional is m o r e self-sufficient and deals wi th m o r e uncer ta in ty and design decisions. This certificate proves that t he candidate

Becoming an SAP Certified ABAP Development Professional — Overview Chapter 1 37

has an advanced unde r s t and ing wi th in this prof i le and is able to apply these skills practically a n d provide gu idance in pro jec t imp lemen ta t ion .

Professional Examination Specifics

• S o f t w a r e Sof tware c o m p o n e n t s : SAP Ne tWeaver 7 .0

• N u m b e r o f q u e s t i o n s

9 0

• D u r a t i o n

180 minu te s

Professional cert if ications a re targeting prof i les wi th a m i n i m u m of fou r to seven yea r s of exper ience . Besides the r e c o m m e n d e d educa t ion courses, practical j o b exper ience is also requi red and tes ted.

Competency Areas

Table 1.3, Table 1.4, and Table 1.5 will h e l p y o u to ident i fy the c o m p e t e n c y areas covered in this test . The percentage indicates the por t ion of t he test dedica ted to a part icular compe tency area. The section WAYS TO ATTAIN ident i f ies s tandard SAP Educat ion courses that cover the material be ing tested in the cert if ication examina t ion . The p r ima iy course focuses specifically on the material in the cer-tification examinat ion , and the Alternat ive a n d O the r c o l u m n s ident i fy o the r courses tha t conta in the same material .

Competency Importance

Conceptualize complex processes 4 0 % into customer-prominent solutions. Based on professional application and advanced analysis qualification, customer business requirements can be recognized and transferred into concepts and blueprints of promi-nent customer solutions in:

Table 1.3 Conceptualize Complex Processes into Customer-Prominent Solutions

38 Chapter 1 ABAP Development Certification Track — Overview

W a y s t o At ta in

Topic Pr imary Al te rna t ive O t h e r

W e b services BC416

Data Transfer W o r k b e n c h and Legacy System Migration Workbench

BC420

Enhancement f ramework (BAdls,

user exits)

BC425, BC427

Communicat ion interfaces (ALE, IDoc. RFC. etc.)

BC415

Creating and customizing BAPIs for interfaces

BC417

Leveraging ALE technology BIT300 BIT350

Table 1.3 Conceptual ize Complex Processes into Cus tomer-Prominent Solutions (cont.)

C o m p e t e n c y I m p o r t a n c e

Build solut ions by independen t ly researching valid implementa t ion opt ions . Based on profound under -s tanding and d e e p applicat ion skills, project r equ i rements can be t rans-ferred into solid cus tomer solutions in:

4 0 %

W a y s t o At ta in

Topic Pr imary Al te rna t ive O t h e r

ABAP Objects 8C401

Advanced programming BC402

SQL/database BC400, BC430

Table 1.4 Build Proposed Solutions by Independent ly Researching Valid Implementa t ion Opt ions

Becoming an SAP Certified ABAP Development Professional — Overview Chapter 1 39

Performance analysis of programs BC490

Change and t ranspor t system (Work- A D M 3 2 5 bench/Customizing, t ranspor t tools,

TMS)

SAP Notes Assistant BC425

Internet Control Framework NET900

Table 1.4 Build Proposed Solutions by Independent ly Researching Valid Implementa t ion Opt ions (cont.)

C o m p e t e n c y I m p o r t a n c e

Accomplish and identify solut ions for def ined project tasks. Based on pro-found knowledge and basic under -standing. identified tasks can be per-formed during system implementa-tion, configurat ion, and test ing in t he areas of:

2 0 %

W a y s t o At ta in

Topic Pr imary Al t e rna t ive O t h e r

Componen t s of SAP NetWeaver (PI, Portal, M D M , etc.)

SAPTEC NW001, SAPNW

SOA basic knowledge SO A100

Composi te Application Framework, Composi te Applications

SAP Solution Manage r SM001

Table 1.5 Accomplish Solutions for Defined Project Tasks

40 Chapter 1 ABAP Development Certification Track — Overview

SAP Certified Development Professional — ABAP User Interfaces — SAP NetWeaver 7.0

The book ing code for this examina t ion is P_ABAP_GUI70. The cu r ren t certifica-tion test is ent i t led SAP Certified Deve lopmen t Professional — ABAP User Inter-faces — SAP Ne tWeaver 7 .0 .

The cert if ication test for SAP Certified Deve lopmen t Professional - ABAP User Interfaces — SAP Ne tWeaver 7 .0 verifies in-depth knowledge in the area o f ABAP user interfaces. This certificate proves that the candida te has an advanced unde r s t and ing wi th in this prof i le and is able to apply these skills practically and p rov ide gu idance in pro jec t imp lemen ta t ion .

Professional Examination Specifics

• S o f t w a r e

Sof tware c o m p o n e n t s : SAP Ne tWeaver 7 .0

• N u m b e r o f q u e s t i o n s 9 0

• D u r a t i o n 180 minu te s

Professional cert if icat ions are target ing profi les wi th a m i n i m u m of four to seven yea r s o f exper ience . Besides the r e c o m m e n d e d educa t ion courses, practical j o b exper ience is also requ i red and tested.

Competency Areas

Table 1.6. Table 1.7. a n d Table 1.8 will help y o u to ident i fy the c o m p e t e n c y areas covered in this test. The percentage indicates the por t ion of the test dedica ted to a part icular c o m p e t e n c y area. The section WAYS TO ATTAIN ident i f ies s tandard SAP Education courses tha t cover the material be ing tested in the cert if ication examina t ion . The p r ima iy course focuses specifically o n the material in the cer-t if ication examina t ion , and the Alternat ive and O the r co lumns ident i fy o the r courses that contain the same material .

Becoming an SAP Certified ABAP Development Professional — Overview Chapter 1 41

C o m p e t e n c y

Conceptual ize complex processes into cus-tomer -p rominen t solutions. Based on profes-sional applicat ion and advanced analysis quali-fication, cus tomer business requi rements can b e recognized and transferred into concep t s and blueprints of p rominen t cus tomer solu-tions in:

Topic

Classic Dynpros

W e b Dynpro ABAP

Controls

Customer e n h a n c e m e n t s

I m p o r t a n c e

4 0 %

W a y s t o At ta in

Pr imary Al te rna t ive O t h e r

8C410

NET310

BC412

BC425 and BC427

Table 1.6 Conceptual ize Complex Processes into Cus tomer-Prominent

Solutions

C o m p e t e n c y I m p o r t a n c e

Build solutions by independent ly researching 4 0 % valid implementa t ion opt ions . Based on in-dep th unders tanding and d e e p application

skills, project requi rements can b e transferred into solid cus tomer solut ions in:

W a y s t o At ta in

Topic Pr imary Al te rna t ive O t h e r

ABAP Objec t s BC401

Advanced programming BC402

Table 1.7 Build Proposed Solutions by Independent ly Researching Valid

Implementa t ion Opt ions

Summary Chapter 1 43

As the cert if ication process is ever evolving, y o u should always check the certifi-cation site for changes to the above in fo rma t ion . The cert if icat ion site can be f o u n d o n t he SAP w e b site at http://mvw.sap.com. From there , go to SAP ECOSYS-TEM A N D PARTNERS • SERVICES • EDUCATION • CERTIFICATION. T h e n u s e t h e c e r t i f i -

c a t i o n finder f o r S A P N E T W E A V E R • DEVELOPMENT • D E V E L O P E R / D E V E L O P M E N T

CONSULTANT.

Summary

You n o w have an unde r s t and ing of the d i f fe rences b e t w e e n the var ious certifica-t ion examina t ions for ABAP. This knowledge will al low y o u to ident i fy which cert if icat ion examina t ion is mos t appropr ia t e for y o u r knowledge level a n d will al low y o u to focus y o u r s tudy o n areas w h e r e y o u r knowledge may need s o m e assistance. Your unde r s t and ing of w h e r e y o u need to s tudy will m a k e the use of y o u r t ime m o r e produc t ive .

Courses and Experience

Techniques You'll Master:

• Learn about additional sources of information

• Structure y o u r understanding and thinking

• Explore the SAP test design

• Access and use general test taking help

32 Chapter 2 Courses and Experience

This book is no t a subs t i tu te for SAP courses o r exper ience . Wher ea s w e would like to provide all of the in fo rmat ion y o u need , it is s imply no t practical. As a result , we will ident i fy which t ra ining p rov ided by SAP Education is necessary and provide general ly available in fo rma t ion . SAP provides access to the docu-menta t ion , and w e f ind the in fo rmat ion in the SAP Developer Network (SDN) to be ex t remely beneficial .

Training Courses for ABAP

The courses available for ABAP are d iv ided into two cur r icu lum tracks: o n e focused on the cert if ication examina t ion (see Table 2.1) and o n e organized by topic (see Table 2.2).

Course Description Length

TAW10 ABAP basics 10 days

TAW11 ABAP details eLearning (~20 hours)

TAW12 ABAP Objects and how to use it 10 days

Table 2.1 Minimum Certification Training

Course Description Length

8C400 ABAP Workbench foundations 5 days

8C401 ABAP Objects 5 days

BC402 Advanced ABAP 5 days

8C405 Programming ABAP reports 5 days

8C414 Programming database changes 2 days

8C425 Enhancements and modifications 3 days

BC427 Enhancement Framework 2 days

BC430 ABAP Dictionary 3 days

Table 2.2 Topic Courses for Certification Training

Sources of Information Chapter 2 47

Course Description

NET310 Fundamentals of Web Dynpro ABAP

NW001 Technology solutions powered by SAP

Length

5 days

eLearning ( -8 hours) NetWeaver

Table 2.2 Topic Courses for Certification Training (cont.)

Sources of Information

In addi t ion to the course material , y o u may find addi t ional in fo rmat ion on the SAP Developer Ne twork (SDN) at http://sdn.sap.com. Select the path SAP N E T W E A V E R CAPABILITIES • DEVELOPMENT AND COMPOSITION • A B A P t o find a v e i y

useful site conta in ing in fo rmat ion in the fo rm of whi t epapers , articles, blogs, wikis, and eLearning material .

O n e area wi th in SDN that is o f t en over looked and that w e have f o u n d to be ve iy useful for p repara t ion is trial vers ions . On http://sdn.sap.com, navigate to DOWN-LOADS • SAP NETWEAVER MAIN RELEASES, which con ta ins trial vers ions of SAP Ne tWeaver tha t y o u can install and explore for bo th W i n d o w s and Linux. Several of the screen shots in this book w e r e taken f r o m these trial vers ions . I f y o u r com-pany or cus tomer is no t y e t r u n n i n g SAP Ne tWeave r 7.0, this mini version will al low y o u to explore the n e w features of the release including the ABAP Debug-ger and W e b Dynpro ABAP.

The mini vers ion, a l though not a comple te copy of an SAP Enterpr ise Core Com-p o n e n t s (ECC) sys tem, docs p rov ide a funct ional sys tem. Also included are all of the examples f r o m the s tandard p r o g r a m m i n g book by Horst Keller: ABAP Objects - ABAP Programming in SAP NetWeaver (SAP PRESS 2007) .

If you have questions about the installation process, a search on SDN for "How to install SAP NetWeaver" will provide blogs, forums, PDFs. and even eLearning to be successful.

A n o t h e r o f t en over looked area is the SAP Help Portal (ht tp: / /he lp . sap .com ) . I f y o u go to SAP NF.TWF.AVER • SAP NETWEAVER 7.0 (2004s), y o u will find a n u m b e r of useful areas that d o c u m e n t changes and funct ional i ty of ABAP:

Note

34 Chapter 2 Courses and Experience

• Release O v e r v i e w Find ou t wha t ' s n e w and wha t ' s changed since the previous release.

• W h a t ' s New — Release N o t e s A star t ing poin t to use SAP so f tware and changes to SAP Ne tWeaver 7.0.

• SAP N e t W e a v e r a t a G lance An overv iew of available IT scenarios.

• Sys t em A d m i n i s t r a t i o n An overv iew of h o w SAP Ne tWeaver is main ta ined and conf igured .

• I n s t a l l a t i o n , C o n f i g u r a t i o n , U p g r a d e In fo rmat ion related to p lanning, installing, upgrading, and main ta in ing IT scenarios.

• D e v e l o p m e n t Developers guides, presenta t ions , and f o r u m s of in fo rmat ion abou t d i f fe ren t technologies including ABAP, Java, and .NET.

• P o w e r User I n f o r m a t i o n

Inst ruct ions on specialized func t ions fo r advanced users .

• F u n c t i o n a l View The documen ta t i on for SAP Ne tWeaver 7.0.

• S u p p l e m e n t a l ^ I n f o r m a t i o n

How-to guides, SAP notes , learning maps, and best practices.

A n o t h e r useful w e b site is the SAP PRESS w e b site: http://www.sap-press.com. There y o u can f ind a n u m b e r of o the r books that can be ex t remely useful .

A name we especially look for regarding books is Horst Keller — always timely information with the latest capabilities of ABAP.

Strategic Understanding

Structur ing y o u r th ink ing is o n e of the main ways to build an effect ive m e m o i y . Those wi th a perfect m e m o i y can s imply review the material and pass the test, but for t he rest of us, o u r success is l inked to o u r unde r s t and ing . As y o u go th rough this book, t ry to keep t he fol lowing though ts in m i n d . R e m e m b e r that in m a n y cases an unde r s t and ing of w h y someth ing occurs will p rov ide y o u the

Strategic Understanding Chapter 2

correct answer even i f y o u do not k n o w the answer . The fol lowing is the w i s d o m gleaned f r o m m a n y sources.

• M o n i t o r y o u r c o m p r e h e n s i o n

You can only r e m e m b e r and fully use ideas that y o u u n d e r s t a n d . Find ways to m o n i t o r y o u r c o m p r e h e n s i o n . Get in the habi t of saying to yourse l f , "Do 1 unde r s t and this?"

• A lways check t h e logic b e h i n d t h e i dea s For example , do things h a p p e n in a way that y o u would predict? If y o u can see the logic in someth ing , y o u are much m o r e likely to be able to reconst ruct that idea even if y o u cannot immedia te ly recall it.

• W a t c h o u t f o r a n y t h i n g t h a t s e e m s c o u n t e r i n t u i t i v e You are less likely to r e m e m b e r some th ing that does not seem logical o r that y o u d o not agree wi th .

• Tes t y o u r o w n u n d e r s t a n d i n g You can do this by discussing y o u r though ts abou t a topic wi th colleagues to see if they see th ings the same way as y o u . Listen to the i r input and evaluate y o u r c o m p r e h e n s i o n .

• G e n e r a t e y o u r o w n e x a m p l e s Use y o u r general k n o w l e d g e a n d exper ience to relate ideas to w h a t y o u a l ready k n o w . Then , br ing y o u r examples into a context y o u are a l ready famil iar wi th .

• Th ink in p i c tu r e s , s h a p e s , a n d c o l o r s

Concre te images are easier to r e m e m b e r than abstract ideas.

• Whi le s tudying, cons ider making no tes wi th pictures, shapes , and colors, and then review y o u r no tes o f t en to sol idify the images in y o u r m e m o r y .

• Use shapes such as f low charts, triangles, boxes, and circles to organize ideas.

• Build a p ic ture o r play (set of actions) a r o u n d an idea a n d re run it in y o u r head.

• Use m n e m o n i c s f o r i m p o r t a n t i dea s M n e m o n i c s are memory- t r a in ing devices o r ways of making associat ions to aid in recall. There are several kinds y o u may be familiar wi th already:

• Rhymes

• Acronyms to collapse the beg inn ing letters of a set of in format ion into o n e o r a f ew w o r d s to help y o u r e m e m b e r all of the c o m p o n e n t s

36 Chapter 2 Courses and Experience

• Building the beg inn ing let ters of a set of i n fo rma t ion in to a sen tence , which usually results in a s o m e w h a t whimsical sen tence that is easily r e m e m b e r e d

• R e p e t i t i o n The m o r e t imes y o u review someth ing , the be t te r y o u will be able to recall that i n fo rma t ion . To e n h a n c e this effect, w h e n e v e r y o u go th rough some-thing, t ry to find a d i f fe ren t angle so that y o u are not j u s t repea t ing exactly the same activity. By va iy ing y o u r approach , y o u will create m o r e connec-tions in long-term m e m o i y .

SAP Examination Strategies

As the scheduled date of y o u r examina t ion comes closer, the fol lowing points should be rev iewed. Wherea s these po in t s will not help wi th y o u r unde r s t and-ing, they may assist y o u if y o u b e c o m e stuck whi le taking the examina t ion . The points y o u should keep in mind whi le p repar ing to take the examina t ion are:

• SAP exams are given onl ine . This is an advantage because y o u can mark ques-t ions y o u are u n s u r e of and re turn to t h e m i f y o u have t ime remain ing .

• The ques t ions are g r o u p e d in sect ions by topic. Therefore , Section 2 of this book covers a chap te r to each of these topics.

• The exam has several exam vers ions . This means that y o u may no t receive the same ques t ions on a re t iy .

• No exam ques t ions concern m e n u pa ths o r t ransact ion codes.

• Concent ra te on the concepts and reasoning used wi th in a topic.

• Learn the me thodo logy beh ind a topic. You will be asked the "why of do ing someth ing . " For example , "Why doesn ' t this line o f code work as expected?"

• Think of scanning the exam first to get a feel for the types o f ques t ions and cons ider do ing the easy ones first to boost se l f -confidence.

• Answer all of t he ques t ions (unanswered ques t ions are w o r t h zero). If y o u do not k n o w the answer and cannot reason it out , at least guess . You may not get it right, bu t i f y o u skip it y o u are guaran teed to get it w r o n g .

• I f y o u get stuck o n a ques t ion , mark it and move on . All ques t ions marked can be r e tu rned to be fo re comple t ing the examina t ion .

SAP Examination Strategies Chapter 2

Stay "w i th in t h e box . " C o n s i d e r t h e top ic sec t ion in w h i c h y o u a re c u r r e n t l y

w o r k i n g . An a n s w e r u n r e l a t e d to th is t op ic is p r o b a b l y incor rec t .

Read y o u ' r e t h e q u e s t i o n s s lowly a n d d o no t m a k e a s s u m p t i o n s .

W h e n r e v i e w i n g SAP mate r i a l , b e a w a r e o f ce r ta in w o r d s a n d ph ra se s . Con-

d i t iona l w o r d s such as or o r can in r e la t ion to SAP a re m o r e l ikely to b e t rue

t h a n "ha rd" w o r d s such as cannot.

A l t h o u g h t h e e x a m is a i m e d at u n d e r s t a n d i n g r a t h e r t han n i e m o i y , memori-

zation is no t a d i r t y w o r d . F r e q u e n t , t h o r o u g h r e v i e w will resul t in m e m o r i z -

ing m a n y facts a n d will h e l p t r e m e n d o u s l y in e l i m i n a t i n g s o m e incor rec t

r e s p o n s e s i m m e d i a t e l y .

T h i n k a n d u s e t e r m s t h e w a y SAP uses t h e m . It will h e l p in t h e e x a m e n v i r o n -

m e n t .

Be r e a s o n a b l e . Recogn ize c o m m o n sense v e r s u s n o n s e n s e . If an a n s w e r s e e m s

s t r ange , it l ikely is.

T h e q u e s t i o n s wil l b e ba sed o n an u n d e r s t a n d i n g w h e n SAP N e t W e a v e r 7 . 0 w a s or ig ina l ly r e l eased . C h a n g e s to f u n c t i o n a l i t y ba sed o n back p o r t s f r o m f u t u r e re leases will n o t b e o n t h e e x a m i n a t i o n . An e x a m p l e is tha t t h e types d e c f l o a t l 6 a n d d e c f 1 o a t 3 4 will e v e n t u a l l y b e par t o f SAP N e t W e a v e r 7 . 0 t h r o u g h s u p p o r t packages , b u t t h e r e will n o t b e q u e s t i o n s re la ted to t h e m o n th is e x a m .

Rest is i m p o r t a n t . T i y to ge t a g o o d n i g h t ' s s leep . S tud ies ind ica te tha t lack o f

s leep a f fec ts c o n c e n t r a t i o n , a m a j o r i n g r e d i e n t in a mu l t i p l e - cho ice e x a m .

Note

You may or may not get your results immediately after the exam is completed.

• If you do receive your results right away:

You will not get specific details on what questions were correct or incorrect and why.

You will receive the percentage of correct answers you achieved for each topic section presented.

• If you do not receive your results right away:

Your results will be mailed to you.

52 Chapter 2 Courses and Experience

General Examination Strategies

This examina t ion is mult iple choice and mul t ip le response . W e p rov ide s o m e guidel ines that will he lp y o u correctly answer mult iple-choice ques t ions on exams:

• Not ice i m p o r t a n t w o r d s in t h e i t e m This will help y o u focus on the in format ion most needed to ident i fy the cor-rect answer choice.

• Read all o f t h e a n s w e r cho ices b e f o r e se l ec t ing o n e The last answer choice could be j u s t as correct as the first.

• E l i m i n a t e a n s w e r cho ices y o u a r e c e r t a i n a r e n o t c o r r e c t This will he lp y o u n a r r o w d o w n the correct a n s w e r choice a n d focus m o r e accurately.

• Are t h e r e t w o a n s w e r cho ices t h a t a r e o p p o s i t e s

O n e of these t w o a n s w e r choices is likely to be correct .

• Look f o r h i n t s a b o u t t h e c o r r e c t a n s w e r cho ice in o t h e r q u e s t i o n s o n t h e t e s t The correct a n s w e r choice may be part of a n o t h e r ques t ion s o m e w h e r e else on t he test.

• Look f o r a n s w e r cho ices t h a t c o n t a i n l a n g u a g e a n d t e r m i n o l o g y used b y y o u r i n s t r u c t o r o r f o u n d in t h i s b o o k An answer choice that conta ins such language is usually correct .

• Stick w i t h y o u r in i t ia l a n s w e r u n l e s s y o u a r e s u r e a n o t h e r a n s w e r cho ice is c o r r e c t Mos t of ten , y o u r first choice is correct .

Knowing h o w mult iple-choice i tems are cons t ruc ted and using these guidel ines will he lp y o u improve y o u r score o n a mult iple-choice test.

Summary

You n o w have addi t ional sources o f in fo rmat ion that can be useful for the certi-f ication examina t ion . You can n o w s t ruc ture y o u r th inking, and this will increase both y o u r unde r s t and ing of t he subject and provide y o u wi th mechan i sms to work th rough ques t ions on the examina t ion . Your unde r s t and ing of h o w SAP designs the test will a l low y o u to e l iminate incorrect answers .

Part II Exam Preparation

SAP NetWeaver — Overview

Techniques You'll Master:

• Explain the d i f fe rence b e t w e e n the classic SAP Application Server and t he SAP Ne tWeaver Applicat ion Server

• Under s t and the SAP Business Suite

• Describe the p u r p o s e o f kernel and adminis t ra t ion services

• Recognize the s t ruc ture of an ABAP applicat ion server

• De te rmine t he s t ruc ture of a work process

42 Chapter 3 SAP NetWeaver — Overview

The SAP Ne tWeaver Applicat ion Server is the cur ren t technical p la t fo rm o n which ABAP runs . It can be used for a n u m b e r of bus iness applicat ions. In this chap te r y o u will be provided wi th a basic unde r s t and ing of h o w an ABAP appli-cation server func t ions . W e will discuss the evolut ion of the classic SAP Applica-t ion Server into the SAP Ne tWeaver Application Server, and y o u will learn abou t t he c o m p o n e n t s r u n n i n g o n SAP Ne tWeaver and h o w it can be conf igured . W e will also delve into t he s t ruc ture and use of work processes o n an ABAP applica-t ion server .

Real-World Scenario

You have been asked to lead a n e w project installing a n e w implemen ta t ion of an SAP sys tem. It is y o u r responsibi l i ty to put toge ther a p resen ta t ion explaining to m a n a g e m e n t the basics o f h o w an SAP Ne tWeaver Applica-t ion Server w o r k s a n d provides scalability, data integri ty, and h a r d w a r e and da tabase i ndependence .

Objectives of this Portion of the Test

The pu rpose of this por t ion of the cert if ication examina t ion is to ver i fy that y o u have genera l knowledge of the SAP Ne tWeaver Applicat ion Server ABAP (AS ABAP) and h o w the d i f fe ren t processes work together . This po r t ion of the exam-inat ion will test y o u r knowledge of a n a r r o w range of topics. The points y o u will need to unde r s t and f rom this sect ion include:

• W h a t c o m p o n e n t s a re a par t of the SAP Ne tWeaver Applicat ion Server

• W h a t c o m p o n e n t s a re a par t of the SAP Ne tWeaver Applicat ion Server ABAP

• The use o f a dialog s tep in a work process

• How par ts of the kernel and adminis t ra t ion services m a k e the SAP Ne tWeaver Applicat ion Server both database and p la t form i n d e p e n d e n t

Key Concepts Refresher

If y o u are n e w to ABAP deve lopmen t , y o u may w a n t to re turn to this chap te r a f te r y o u read Chapter 8. SQL Sta tements Including Update Strategies, including u p d a t e strategies. In m a n y ways these two chapters a re closely related. You will

Key Concepts Refresher Chapter 3 57

find the technical reasons here in this chap te r for logical uni ts o f work a n d the SAP lock objects.

SAP Products in a Nutshell

SAP offers a n u m b e r o f products for compan ies of all sizes. The p roduc t s are scal-able, to ensu re that they can be ad jus ted to any size organizat ion, and are adapt-able to a company ' s constant ly changing processes.

• SAP Business One is des igned for small c o m p a n i e s wi th f ewer than 1 0 0 emp loyees and 30 users, and it covers their core processes (such as finance, sales, cus tomer service, and opera t ions) .

• SAP Business ByDesign is des igned fo r small and midsize compan i e s wi th b e t w e e n 100 and 500 employees that wan t to use an o n - d e m a n d solut ion to improve the i r core processes .

• SAP Business All-in-One is des igned for small and midsize compan ies wi th very industry-specif ic r equ i r emen t s that have several divisions and a ma tu re IT inf ras t ruc ture .

• SAP Business Suite is an ex tended family o f business appl icat ions that enables compan i e s to manage the i r en t i re business .

The SAP Business Suite consists of a n u m b e r of modu la r en te rp r i se so f tware p roduc t s that suppor t end- to-end c o m p a n y processes. The SAP Business Suite is par t of the Business Process Pla t form. The Business Process Pla t form (BPP) is a prerequis i te for the d e p l o y m e n t of a service-or iented archi tec ture (SOA) for busi-ness appl icat ions. It is composed of the fol lowing parts:

• The SAP Business Suite, which provides ready-to-execute so f tware for busi-ness processes.

• Reusable en te rpr i se services for use in compos i t e applicat ions.

• SAP NetWeaver , which is an o p e n integrat ion and applicat ion p la t form fo r all SAP appl icat ions and certain SAP pa r tne r appl icat ions. It suppor t s o p e n stan-dards . SAP Ne tWeaver is in te roperab le wi th the mos t impor t an t t echnology s t anda rds such as Java 2 Pla t form, Java Enterpr ise Edition (Java EE) and Mic rosof t .NET.

44 Chapter 3 SAP NetWeaver — Overview

Some of the appl icat ions included in the SAP Business Suite are:

• SAP Enterpr ise Resource Planning (SAP ERP)

• SAP ERP H u m a n Capital M a n a g e m e n t (SAP ERP HCM)

• SAP ERP Financials

• SAP ERP Opera t ions

• SAP Cus tomer Relat ionship M a n a g e m e n t (SAP CRM)

• SAP Suppl ier Relat ionship M a n a g e m e n t (SAP SRM)

• SAP Supply Chain M a n a g e m e n t (SAP SCM)

• SAP Product Lifecycle M a n a g e m e n t (SAP PLM)

• SAP ERP Corpora te Services

Product Evolution

Through the 1990s . SAP prov ided t w o basic products : SAP R/2 (ma in f r ame based) and SAP R/3 (which is c l ient /server based). They prov ided similar func-tionality. and R/3 is o f t en referred to as a successor to R/2. The d e v e l o p m e n t o f t he under ly ing technical p la t form was closely l inked to the applicat ion develop-m e n t . For example , the release n a m e s of the SAP technical p la t form corre-s p o n d e d to the vers ions of the applicat ion themselves . They w e r e t he re fo re re fer red to as, f o r example , SAP Basis 4.0B ( the technical p la t form) and SAP R/3 4.0B (the applicat ion). Most j u s t used t he t e rm 4.0B to re fer to bo th .

In t he late 1990s, the n u m b e r of SAP produc t s g r e w significantly, and n e w prod-ucts requi red f r e q u e n t changes and e n h a n c e m e n t s to the SAP technical p la t form m o r e than to SAP R/3. This shift in d e v e l o p m e n t began t he t ransi t ion o f t he tech-nical p la t form f r o m the classical SAP Basis to SAP W e b Application Server (SAP W e b AS), pr imari ly to a l low direct access to HTTP requests .

This t ransi t ion also p roduced a naming change to the products . Table 3.1 shows the evolut ion of the names and the gradual separa t ion of the Basis and the appli-cat ion. As s h o w n in Table 3.1, the technical basis and applicat ion d e v e l o p m e n t w e r e l inked, u p to and including SAP R/3 4.6C. The concept o f SAP R/3 Enter-prise Extensions was in t roduced star t ing wi th SAP R/3 Enterpr ise (4.7), which is based on SAP W e b Applicat ion Server 6 .20 (the technical p la t form af ter evolving into a w e b server). The in t roduc t ion of Enterpr ise Extensions a l lowed the core applicat ion to remain stable a n d prov ided n e w business funct ional i ty .

Key Concepts Refresher Chapter 3 45

Part of SAP Basis Business Business Part of NetWeaver Functionality Functionality Extension Set SAP ERP

3.11 3.11

4.0B 4.0B

4.58 4.58

4.68 4.68

4.6C 4.6C

4.6D

6.10

6.20 4.7 1.10 (2003)

(2003) 6.30 4.7 2.00 (2003)

2004 ('04) 6.40 5.0 5.00 2004

7.0 (2004s) 7.00 6.0 6.00 6.0(2005)

7.1 7.10 -

Table 3.1 Evolution from SAP R/3 to SAP ECC

A central application o f the SAP Business Suite is SAP ERP (Enterprise Resource Planning). The central sof tware c o m p o n e n t of SAP ERP is SAP ERP Central Com-p o n e n t (SAP ECC). SAP ECC 5.0 can thus be considered the successor of SAP R/3 Enterprise and operates on the basis o f SAP NetWeaver Application Server 6.40. At the t ime of this wri t ing, the current version is SAP ERP 6 .0 (previously SAP ERP 2005), which includes SAP ECC 6 .0 and o the r c o m p o n e n t s and opera tes on the basis of SAP NetWeaver AS 7.00.

The technical p la t fo rm dur ing this s ame t i m e f r a m e also w e n t th rough several n a m e changes as the p la t form evolved. Up th rough Release 4.6, the technical p la t form was re fer red to as SAP Basis. Wi th the in t roduct ion of In terne t capabil-ity in Release 6 .20, the technical p la t form was re fer red to as SAP Web Application Server, and wi th t he abili ty to include both t he ABAP da tabase and the Java data-base in o n e system wi th Release 6 .40 , the n a m e became SAP NetWeaver Applica-tion Server.

46 Chapter 3 SAP NetWeaver — Overview

The ABAP Release is current ly still l inked to the technical p la t form funct ional i ty release and is the reason this cert if icat ion examina t ion specifies SAP Ne tWeave r 7.0.

Note

SAP NetWeaver AS 7.10 (or SAP NetWeaver 7.1) is not currently used as the technical basis for an SAP ECC system. However, other SAP NetWeaver compo-nents. such as SAP NetWeaver Process Integration (PI) and SAP NetWeaver Composition Environment (CE), already require this SAP NetWeaver release level.

With SAP W e b AS 6.10, n e w technologies based o n highly scalable in f ras t ruc ture w e r e imp lemen ted to process HTTP reques ts directly f r o m the In terne t o r to send t h e m as HTTP client reques ts to the In ternet . Before this an Internet Transaction Server was requi red to deal wi th these requests . The SAP kernel was enhanced to include a process k n o w n as the In terne t Communica t ion M a n a g e r (ICM) to achieve this funct ional i ty . The kernel uses the ICM to directly handle HTTP requests , a l lowing for n e w web-based applicat ions, for example , Business Server Pages (BSPs). Incoming w e b reques ts a rc received by the ICM, wh ich uses the URL to decide w h e r e to fo rward the reques t .

Figure 3.1 shows the basic archi tec ture of an SAP Ne tWeaver server . An SAP Ne tWeaver server is a fu r the r evolu t ion of the technical p la t form. This p la t fo rm al lows bo th ABAP and Java to exist and func t ion wi th in the same sys tem. You will not ice similar func t ions o n bo th the ABAP and Java stacks in the f igure. Sim-ilar func t ions are p e r f o r m e d by the d ispatcher a n d the Java d ispatcher to connec t a work process to a c o n s u m e r o r user o f the process. The ABAP W o r k Processes and the Java Server Work Processes p e r f o r m processing and database access. On the ABAP side, the ga teway communica t e s wi th external servers, and as men-t ioned above, the ICM processes all HTTP requests . The SDM (Software Deploy-m e n t Manager ) is a s tandard tool used to install J2EE c o m p o n e n t s on the Java applicat ion server .

These w e b technologies w e r e first used wi th Business Server Pages (BSP) in SAP W e b Applicat ion Server 6 .20 . BSP appl icat ions are sel f -contained appl icat ions similar to an SAP transact ion. Unlike an SAP t ransact ion, the presen ta t ion layer is no t the SAP GUI, bu t a w e b b rowse r . The BSP dynamical ly genera tes HTML pages to provide the presen ta t ion . It de f ines the e l emen t s for user interact ion, in o the r w o r d s , input fields and pushbu t tons . These are created using server-side

Key Concepts Refresher Chapter 3 61

sc r ip t ing in ABAP. T h e app l i ca t ion logic is p r o v i d e d t h r o u g h the e v e n t h a n d l i n g

o f a Bus iness Server Page. Beg inn ing w i t h SAP N e t W e a v e r 7 .0 , W e b D y n p r o

ABAP is also poss ib l e — it has b e e n poss ib l e to c r ea t e W e b D y n p r o Java appl ica-

t i ons s ince SAP N e t W e a v e r AS 6 . 4 0 (see C h a p t e r 16, Use r In te r faces ( W e b Dyn-

pro) , f o r de ta i l s o n W e b D y n p r o ) .

Client (SAP G U I )

Message Server

Client (SAP G U I )

Client ( W e b 8rowser)

Central Services

_ [ Dispatcher L O i s p a t c h e r L 1 — ' Q u e u e

W o \BA 1

Pro

M e m o r y _ Pipes

ABAP

ICM

Java Dispatcher

Java >ervir ocesi

Java

SAP N e t W e a v e r App l ica t ion Server

S D M

Database Database

Figure 3.1 Components of SAP NetWeaver Application Server with the ABAP and Java Stacks

SAP W e b App l i ca t ion Se rve r 6 . 2 0 a lso p r o v i d e d a Java a n d an ABAP stack. SAP N e t W e a v e r App l i ca t ion Se rve r Java f e a t u r e s t h e Java d i s p a t c h e r a n d Java se rve r p roces s c o m p o n e n t s , w h i c h p e r f o r m tasks s imi la r to t h e ABAP d i s p a t c h e r s a n d w o r k p rocesses . Release 6 . 4 0 p r o v i d e d t h e d a t a b a s e w i t h t w o s c h e m a s : o n e f o r t h e ABAP da t a a n d o n e f o r t h e Java da ta , in o t h e r w o r d s , o n e set o f ABAP tables a n d o n e set o f Java tab les d e p e n d i n g o n t h e SAP p r o d u c t s y o u use . Th is w a s t h e f irst r e lease that p e r m i t t e d b o t h ABAP a n d Java to r u n t o g e t h e r o n t h e s a m e se rve r , o r y o u c o u l d h a v e j u s t o n e o r t h e o t h e r . As t h e da t a in t h e d a t a b a s e is sep-a ra ted , access o f da ta f r o m o n e s tack to t h e o t h e r is a c c o m p l i s h e d t h r o u g h t h e Java C o n n e c t o r (JCo).

48 Chapter 3 SAP NetWeaver — Overview

SAP NetWeaver Architecture

T h i s e v o l u t i o n o f t h e t e c h n i c a l p l a t f o r m i n t o SAP N e t W e a v e r p r o v i d e s u s w i t h

s e v e r a l d i f f e r e n t w a y s t o ins ta l l a n d u s e t h e SAP N e t W e a v e r p l a t f o r m . T h e ins ta l -

l a t i o n o p t i o n s f o r SAP N e t W e a v e r A p p l i c a t i o n S e r v e r a r e as f o l l o w s :

• SAP N e t W e a v e r A p p l i c a t i o n S e r v e r A B A P S y s t e m

• SAP N e t W e a v e r A p p l i c a t i o n S e r v e r J a v a S y s t e m

• SAP N e t W e a v e r A p p l i c a t i o n S e r v e r A B A P + J a v a S y s t e m

D i f f e r e n t SAP N e t W e a v e r c o m p o n e n t s r e q u i r e t h e SAP N e t W e a v e r A p p l i c a t i o n

S e r v e r t o b e r u n w i t h c e r t a i n s t acks c o n f i g u r e d . SAP N e t W e a v e r P r o c e s s I n t e g r a -

t i o n , f o r e x a m p l e , r e q u i r e s b o t h t h e A B A P a n d J a v a s t acks . D e p e n d i n g o n t h e u s e

o f t h e s e r v e r , it is p o s s i b l e t o u s e j u s t A B A P o r j u s t J a v a .

N o t e

W h e n talking abou t an SAP NetWeaver Application Server, the te rm instance is o f t en used . An instance:

• Always has exactly o n e d ispatcher (see t he User View section be low for its use).

• Starts when t he dispatcher starts.

Requires a t least t w o dialog work processes (see t he Structure of a Work Pro-cess section be low for details), bu t has a t least a minimum n u m b e r of work processes def ined by t he system.

• Is also called t he application server in t he sof tware-or ien ted view of t he client-server model ( the next no te discusses t he differences b e t w e e n t he sof tware-or iented and hardware-or ien ted views). From a sof tware-or ien ted view, t he collection of services shown in Figure 3.1 is an application server, but f rom a p la t form-or iented view it 's an instance.

An instance is an administrat ive unit tha t combines SAP system c o m p o n e n t s tha t provide o n e or more services. The services provided by an instance are s tar ted or s topped toge ther . Each instance has its own memory buffer areas. An instance runs on one physical server, bu t t h e r e can b e mult iple instances on o n e physical server. An instance is identified by t he system ID (SID) and t he instance n u m b e r .

W h e n y o u ins ta l l a n SAP s y s t e m , y o u h a v e t h e o p t i o n o f s e p a r a t i n g t h e p r o c e s s e s

a t t h e a p p l i c a t i o n l eve l f r o m t h o s e a t t h e d a t a b a s e l eve l . T h i s m e a n s t h a t t h e d a t a -

b a s e f o r an SAP s y s t e m c a n b e i n s t a l l e d a n d o p e r a t e d o n a s e p a r a t e p h y s i c a l

Key Concepts Refresher Chapter 3 49

s e r v e r f r o m t h e i n s t a n c e s o f t h e SAP s y s t e m , a n d in f ac t t h i s is u s u a l l y t h e case .

T h e r e is e x a c t l y o n e d a t a b a s e f o r e a c h SAP s y s t e m .

T h e c e n t r a l i n s t a n c e o f t h e SAP s y s t e m is d i s t i n g u i s h e d b y t h e f ac t t h a t it o f f e r s

s e r v i c e s t h a t n o o t h e r i n s t a n c e o f t h e s y s t e m o f f e r s . F o r t h e AS ABAP, t h e s e a r e

t h e m e s s a g e s e r v e r a n d t h e e n q u e u e w o r k p r o c e s s . T h e o t h e r i n s t a n c e s o f t h e sys-

t e m a r e t yp i ca l l y ca l l ed d i a l o g i n s t a n c e s .

N o t e

Before we discuss various client-server configurat ions in t h e context of SAP sys-tems, w e need t o def ine t he concep t s of client and server. There a re basically t w o ways to d o this:

• In t he hardware-or ien ted view, t h e te rm server means t he central server in a network that provides data, memory, and resources for t h e worksta t ions or cli-ents .

• The o the r way is a sof tware-or ien ted view. A service that is provided is called a server, and a service tha t consumes or uses that service is called a client. At t he same t ime, clients can also be servers for o t h e r specific services (as you will see below).

Because this book is abou t p rogramming certification, the rest of the chapter will use terminology f rom this sof tware perspective. It is impor tan t to unders tand that our use of t he te rm system relates to t he who le technical platform and appli-cation server or server refers t o a server running in a system, no t t he actual phys-ical hardware . It is possible to implement an ent i re application on a single hard-ware system (for example , t he trial version men t ioned in Chapter 2, Courses and Experience, allows you to have a working system on your o w n PC). In most cus-tomer si tuat ions t he deve lopmen t and sandbox (if one exists) a re typically a sin-gle physical system running a single server. A single physical system can also sup-port mult iple servers or you can have mult iple physical systems each running as a single server.

Kernel and Administration Services

T h e k e r n e l a n d a d m i n i s t r a t i o n s e r v i c e s c o m p o n e n t is a r u n t i m e e n v i r o n m e n t f o r

all A B A P a p p l i c a t i o n s t h a t is h a r d w a r e i n d e p e n d e n t , o p e r a t i n g s y s t e m i n d e p e n -

d e n t , a n d d a t a b a s e i n d e p e n d e n t . T h e k e r n e l a n d a d m i n i s t r a t i v e s e r v i c e s a r e

a n o t h e r w a y o f l o o k i n g a t t h e SAP N e t W e a v e r s y s t e m . T h e t a s k s o f t h e k e r n e l a n d

a d m i n i s t r a t i o n s e r v i c e s c o m p o n e n t a r e :

50 Chapter 3 SAP NetWeaver — Overview

• R u n n i n g a p p l i c a t i o n s All ABAP appl icat ions run o n so f tware processes (virtual machines) wi th in this c o m p o n e n t .

• Use r a n d p r o c e s s a d m i n i s t r a t i o n The c o m p o n e n t is respons ib le for the tasks that usually be long to an operat-ing sys tem. Users log o n t o the SAP Ne tWeave r Applicat ion Server a n d run ABAP appl icat ions wi th in it. They d o not have direct contact wi th the actual opera t ing sys tem of the host . AS ABAP is the only user of the host opera t ing sys tem.

• D a t a b a s e access Each AS ABAP is l inked to a database sys tem, consist ing of a database man-agemen t sys tem (DBMS) and the da tabase itself. The ABAP appl icat ions d o not c o m m u n i c a t e directly wi th the database . Instead, they use adminis t ra t ion services.

These services handle , as we will discuss short ly, the SAP table bu f fe r ing o n the applicat ion server, the t ranslat ion f r o m O p e n SQL to Native SQL for the database, and the handl ing of SAP-specific concepts , for example , the client n u m b e r o r the s t ruc ture o f a cluster table.

• C o m m u n i c a t i o n ABAP appl icat ions can c o m m u n i c a t e bo th wi th o the r SAP systems and wi th external systems. It is also possible to access ABAP appl icat ions f r o m external sys tems using a Business Applicat ion P rog ramming Interface (BAPI) o r j u s t a Remote Funct ion Call (RFC). The services requ i red for communica t i on are all par t of the kernel and adminis t ra t ion services c o m p o n e n t .

• Con t ro l a n d a d m i n i s t r a t i o n o f AS ABAP This c o m p o n e n t conta ins p rograms that al low y o u to mon i to r and control the SAP Ne tWeaver Applicat ion Server whi le it is runn ing and to change its runt-ime paramete rs .

Software-Oriented View

Figure 3.2 represen ts the sof tware-or ien ted v iew of an SAP sys tem. In an ABAP-based SAP sys tem, the AS ABAP consists of all SAP GUI (graphical user interface) c o m p o n e n t s and the ABAP applicat ion servers . In this s implif ied version, be aware that the SAP GUI can be replaced by a w e b b r o w s e r in the presen ta t ion layer (see below); in o the r words , users can access t he SAP system th rough a w e b

Key Concepts Refresher Chapter 3 51

b r o w s e r instead of the tradit ional SAP GUI (this is s h o w n only once, bu t is not restr icted to the single occurrence) .

F i g u r e 3 .2 Components of SAP NetWeaver Application Server

An SAP system is a mul t i t ier cl ient-server sys tem. The individual so f tware com-p o n e n t s are a r ranged in tiers a n d func t ion , d e p e n d i n g on their posi t ion, as cli-en ts for the c o m p o n e n t s be low t h e m or servers for the c o m p o n e n t s above t h e m . The classic conf igura t ion of an SAP system conta ins t he fol lowing th ree so f tware layers:

• D a t a b a s e l aye r The da tabase layer, which is accessed by the SAP Ne tWeaver Applicat ion Server, consists of a central database sys tem. This central da tabase sys tem is m a d e up of the da tabase m a n a g e m e n t sys tem (DBMS) and the database itself. The da tabase conta ins the mas te r data and transact ion data for y o u r ABAP applicat ion p rograms . It also contains the control and cus tomizing data for the application and the SAP Ne tWeaver Applicat ion Server and the ABAP appl icat ion p rog rams themselves . The d e v e l o p m e n t objects (programs, screen def in i t ions , menus , func t ion modules , and so on) a re all s to red in a special par t o f the da tabase k n o w n as the Reposi tory. These objects a re there-fore also re fer red to as Repository objects. The ABAP W o r k b e n c h allows y o u to work wi th these objects .

52 Chapter 3 SAP NetWeaver — Overview

• A p p l i c a t i o n l aye r The so f tware c o m p o n e n t s of the applicat ion layer of AS ABAP consist of one o r m o r e ABAP applicat ion servers and a message server . Each applicat ion server conta ins a set o f services used to run the SAP Ne tWeaver Applicat ion Server.

Theoretically, y o u on ly need one application server to run an SAP Ne tWeaver Applicat ion Server. In reality, the services a re normal ly d i s t r ibu ted across m o r e than o n e applicat ion server . This m e a n s that no t all applicat ion servers provide the full range of services. The message server provides for c o m m u n i -cation b e t w e e n the applicat ion servers. It passes requests b e t w e e n o n e appli-cation server and a n o t h e r wi th in an SAP Ne tWeaver Applicat ion Server. It also con ta ins in fo rmat ion abou t appl icat ion server g roups and the c u r r e n t load balancing wi th in t h e m . W h e n a user logs on to the system, this in forma-tion is used to choose an app rop r i a t e server .

• P r e s e n t a t i o n l a y e r This layer is the interface b e t w e e n t he SAP system and its users . It is possible to use its so f tware c o m p o n e n t s re fer red to as the SAP GUI (graphical user interface) in this layer for en te r ing and displaying data. A n o t h e r op t ion is th rough a w e b b r o w s e r that also can be used in the presen ta t ion layer. The p resen ta t ion layer sends the user ' s input to the applicat ion server, and receives data for display f r o m it. Whi le a SAP GUI c o m p o n e n t is runn ing , it r emains l inked to a user ' s te rminal session in the AS ABAP.

There a re a n u m b e r of benef i ts to the dis t r ibut ion of the SAP system over three layers. It d is t r ibutes the sys tem load, leading to be t te r system per fo rmance . It pro-vides high scalability because the so f tware c o m p o n e n t s can be dis t r ibuted a m o n g d i f ferent h a r d w a r e virtually wi thou t restrict ion. In the applicat ion layer, y o u can mee t increasing d e m a n d by installing addi t ional ABAP application servers.

User-Oriented View

From a user ' s perspect ive, the SAP system is no t seen as sys tems o r servers , bu t as c o m p o n e n t s that appea r as a w i n d o w on a screen (on e i ther a PC, a w e b browser , o r o the r device). The presen ta t ion layer of the AS ABAP creates these w i n d o w s .

To connec t o r log o n to the SAP system, a user mus t start an SAP GUI utility called SAP Logon. The user chooses one of the available SAP systems listed in SAP

Key Concepts Refresher Chapter 3 53

Logon, and the p rogram connects to the message server o f the AS ABAP in the selected SAP sys tem. The message server obta ins the address o f a sui table (one wi th the most unused capability) ABAP applicat ion server . SAP Logon starts an SAP GUI connec ted to that application server, and then SAP Logon is then no longer requi red for this connec t ion . The SAP GUI initially displays the logon screen. The process is s imilar for W e b Dynpro , but instead of s tar t ing a prein-stalled applicat ion, y o u use a w e b b rowse r and begin wi th a URL that launches a logon screen i f y o u are not already logged on .

After the user successfully logs on , the SAP GUI displays the initial screen of the SAP system in a w i n d o w on the screen. Each w i n d o w wi th in the SAP GUI repre-sents a session. Af te r y o u log on, y o u can o p e n addi t ional sessions ( the exact n u m b e r is d e t e r m i n e d by a sys tem paramete r , though the defaul t is six sessions) wi th in the single SAP GUI. These w i n d o w s , o r sessions, behave almost like inde-p e n d e n t SAP applicat ions. They a l low y o u to run d i f fe ren t appl icat ions indepen-dent ly of o n e a n o t h e r f r o m d i f fe ren t sessions.

As y o u run appl icat ions in a session, they may call or tr igger m o r e w i n d o w s (such as dialog boxes and graphic w indows) . These addi t ional w i n d o w s are not inde-p e n d e n t ; they be long to the session f r o m which they w e r e called. These win-d o w s can be e i ther modal ( the original w i n d o w is no t ready for input) o r amodal (both w i n d o w s are ready for input and interact wi th each other) .

You can o p e n o the r SAP GUIs, by using SAP Logon. To log o n t o a n o t h e r SAP sys-tem, each SAP GUI is totally i n d e p e n d e n t f r o m others . This means that y o u can have SAP GUIs represen t ing the presen ta t ion layers of several SAP sys tems o p e n s imul taneous ly on y o u r personal c o m p u t e r .

All ABAP programs run o n the ABAP applicat ion servers o f AS ABAP, in o the r words , in the instance o f the AS ABAP stack. The appl icat ion layer of the multi t-ier archi tec ture o f an ABAP-based SAP system is m a d e up of all o f the ABAP appli-cation servers . These appl icat ion servers execute ABAP appl icat ions and communica t e wi th the presen ta t ion c o m p o n e n t s , t he database, and each o the r th rough the message server .

Figure 3.3 shows the s t ruc ture of an ABAP applicat ion server: The n u m b e r of work processes and the i r types a re d e t e r m i n e d at the s ta r tup of the AS ABAP: each ABAP applicat ion server also con ta ins a d ispatcher , a ga teway, and shared m e m o i y . The tasks o f these c o m p o n e n t s a re briefly descr ibed be low.

54 Chapter 3 SAP NetWeaver — Overview

SAP GUI ^ M SAP GUI

ICM Dispatcher

W o r k Process

1 i

W o r k Process

2 g

Gateway

W o r k Process,,

3 ^

CL <

Database management server

X 3 : Database

Figure 3.3 ABAP Application Server

• W o r k p r o c e s s

W o r k p roces se s a re c o m p o n e n t s tha t e x e c u t e an app l i ca t ion . For a d ia log w o r k p rocess , each execu t e s o n e d ia log s t ep ( for t h e d e f i n i t i o n o f a d ia log s t ep see t h e D e f i n i t i o n s to R e m e m b e r sec t ion b e l o w ) . Each w o r k p roces s is l inked to a m e m o r y a r ea tha t c o n t a i n s t h e c o n t e x t o f t h e e x e c u t i n g app l i ca t ion . Th is c o n t e x t c o n t a i n s t h e da t a fo r t h e app l i ca t ion . A f t e r t h e w o r k p rocess c o m -p le tes the d ia log s tep , t h e l ink to t h e use r a n d t h e p r o g r a m c o n t e x t is r e m o v e d , w h i c h f r ee s it fo r a n o t h e r use r .

• D i s p a t c h e r

T h e d i s p a t c h e r p r o v i d e s t h e l ink b e t w e e n t h e w o r k p roces s a n d t h e u s e r logged o n t o t h e app l i ca t i on s e r v e r (or m o r e accura te ly , t h e u s e r ' s SAP GUIs o r w e b b r o w s e r ) . It rece ives r e q u e s t s f r o m an SAP GUI o r w e b b r o w s e r a n d d i r ec t s t h e r e q u e s t t o a f r e e w o r k p roces s . O n c e t h e w o r k p roces s c o m p l e t e s t h e d ia log s tep , t h e r e su l t i ng sc reen o u t p u t is r e t u r n e d to t h e a p p r o p r i a t e u s e r b e f o r e t h e l ink is r e leased .

• G a t e w a y

The g a t e w a y is t h e i n t e r f a c e f o r the c o m m u n i c a t i o n p r o t o c o l s o f AS ABAP

(RFC a n d CPI/C). Its p u r p o s e is t o c o m m u n i c a t e w i t h o t h e r ABAP app l i ca t ion

Key Concepts Refresher Chapter 3 55

servers wi th in this sys tem (internally), external ly wi th o the r SAP systems, o r external ly wi th non-SAP systems.

In an ABAP applicat ion server all work processes use a c o m m o n main m e m o r y area called shared memory to save contexts o r to locally bu f fe r cons tant data. Resources that work processes share o r use, for example , p rograms and buf fe red table contents , a rc placed in sha red m e m o r y .

Local buf fe r ing of data in the shared m e m o r y of the ABAP applicat ion server reduces the n u m b e r of database reads requ i red (see Chapter 8, SQL Sta tements Including Update Strategies, for details), considerably reducing t he access t imes for ABAP applicat ion programs .

W h e n y o u start an AS ABAP. each ABAP application se rver registers its work pro-cesses wi th the da tabase layer and receives a single dedicated channel (some-t imes re fer red to as a database work process) for each work process . Whi le the SAP Ne tWeaver Applicat ion Server is running , each work process is a user (act-ing as a client) o f the da tabase sys tem (acting as a server) . It is no t possible to change the work process registrat ion whi le the system is r u n n i n g o r to reassign a database channel f r o m o n e work process to ano the r . Therefore , a work process can only make da tabase changes wi th in a single da tabase logical uni t of work (LUW). For m o r e o n a da tabase logical uni t o f work see Chapter 8, SQL State-m e n t s Including Update Strategies.

Structure of a Work Process

There is a d i f fe rence b e t w e e n user interact ion a n d processing logic in ABAP pro-g ramming . This separat ion is discussed in m o r e detail in Chapter 12, Classical Screens, and Chapter 16, User Interfaces (Web Dynpro) . F rom a p r o g r a m m i n g perspect ive, user interact ion is control led by screens (at least for appl icat ions in the SAP GUI). A screen consists of two parts: the actual input mask and the f low logic, which controls a large part of the user in teract ion. The AS ABAP conta ins a special language fo r p r o g r a m m i n g screen f low logic. Wi th in a work process (Figure 3 .4 s h o w s the c o m p o n e n t s of a work process), t he screen processor exe-cutes the screen f low logic. Through the dispatcher , it takes over the responsibil-ity for communica t ion be tween the work process and the SAP GUI. calls modu le s in the f low logic, and ensu res that t he field con ten ts are t ransfe r red f r o m the screen to the flow logic (see Chapter 12, Classical Screens, for details).

70 Chapter 3 SAP NetWeaver — Overview

Figure 3-4 Components of a Work Process

The actual processing logic of an applicat ion p rog ram is wr i t t en in ABAP. The ABAP processor wi th in the work process executes the processing logic of the applicat ion p rogram and communica t e s wi th the da tabase interface. The screen processor tells the ABAP processor which m o d u l e o f the screen f low logic should be processed next .

The fol lowing services are p rov ided by the da tabase interface:

• Establishing and t e rmina t ing connec t ions b e t w e e n the work process and the da tabase

• Access to t he da tabase tables

• Access to Reposi to iy objects

• Access to catalog in fo rmat ion (ABAP Dict ionaiy)

• Control l ing t ransact ions (commit and rollback handl ing)

• Table bu f fe r adminis t ra t ion on the ABAP applicat ion server

Figure 3.5 shows that there are two dif ferent ways of accessing SAP database ta-bles: Native SQL and Open SQL using ABAP. Open SQL s ta tements are a subset o f s tandard SQL that is fully integrated in ABAP. These s ta tements al low y o u to ac-cess data irrespective of the database system. Open SQL consists o f the Data Ma-nipulat ion Language (DML) part of s tandard SQL. It there fore allows y o u to read (SELECT) and change (INSERT, MODIFY, UPDATE, and OELETE) data. The tasks of the Data Definit ion Language (DDL) and Data Control Language (DCL) parts of stan-dard SQL are p e r f o r m e d in the AS ABAP by the ABAP Dict ionaiy and the autho-

Key Concepts Refresher Chapter 3 71

rization system. These provide a unif ied range of funct ions , regardless of database, and contain funct ions beyond those of fe red by the various database systems.

Database Interface

Database maga^cmcnt s

Database

F i g u r e 3.5 Components of the Database Interface

O p e n SQL goes beyond s tandard SQL to p rov ide s t a t emen t s that in con junc t ion wi th o the r ABAP cons t ruc t ions can s impl i fy o r speed u p database access. It al lows y o u to bu f fe r certain tables on the ABAP applicat ion server, saving exces-sive database access. The database interface is responsible for managing the bu f fe r wi th the database. Database table buf fe r s are partly s to red in the work ing m e m o r y of the cur ren t work process and partly in the shared m e m o r y for all work processes on an ABAP appl icat ion server . In cases w h e r e the AS ABAP is d is t r ibuted across m o r e than one ABAP applicat ion server, the data in the var ious buf fe r s is synchron ized at set intervals by the bu f fe r m a n a g e m e n t . W h e n y o u bu f fe r a database table, y o u mus t r e m e m b e r that the data in t he bu f fe r may not always be u p to date . As a result , y o u should on ly use the b u f f e r for data that does not change o f t en o r w h e r e the data does not need to be cur ren t .

Native SQL is only loosely integrated into ABAP and allows access to all of the func t ions conta ined in the p r o g r a m m i n g interface of the respect ive da tabase sys-t em. In Native SQL, y o u can pr imari ly use the database-specif ic SQL s ta tements . The Native SQL interface sends t h e m as is to the da tabase sys tem w h e r e they are executed . You can use the full SQL language scope of the respect ive database, which makes all p rograms using Native SQL specific f o r the da tabase sys tem

72 Chapter 3 SAP NetWeaver — Overview

installed. A small set o f SAP-specific Native SQL s t a t emen t s are hand led in a spe-cial way by the Native SQL interface. SAP r e c o m m e n d s that ABAP appl icat ions should conta in as little Native SQL as possible, because it reduces the portabi l i ty and maintainabi l i ty o f y o u r code. Only a f ew SAP s tandard c o m p o n e n t s actually conta in Native SQL, fo r example , to create o r change table def in i t ions in t he ABAP Dict ionaiy.

The database-dependent layer in Figure 3.5 hides the d i f ferences b e t w e e n data-base sys tems f r o m the rest of the da tabase interface. Owing to the standardiza-t ion of SQL, the d i f fe rences in the syntax of the s t a t emen t s a re very slight. W h e n y o u use Native SQL, the func t ion of the da t abase -dependen t layer is min imal (see Chapter 8, SQL Sta tements Including Update Strategies, for addi t ional details).

Before y o u start the AS ABAP, y o u d e t e r m i n e h o w m a n y work processes each ABAP appl icat ion server will have and wha t their types will be . Because all work processes have the same s t ructure , the type of work process does no t d e t e r m i n e t he technical a t t r ibutes of the ABAP applicat ion server, bu t instead de t e rmines the type of tasks that can be p e r f o r m e d on it. The d ispatcher starts the work pro-cesses and only assigns them tasks that co r re spond to the i r type. This a l lows y o u to d is t r ibute work process types to op t imize the use of resources o n y o u r ABAP applicat ion server .

Figure 3 .6 again shows the s t ruc ture of an ABAP applicat ion server, bu t this t ime includes var ious possible work process types: Dialog work processes process reques ts f r o m an active user to execute dialog s teps. Update work processes exe-cute da tabase upda te requests . Update requests are part o f an SAP LUW that bun-dle the database opera t ions resul t ing f r o m the dialog in a da tabase LUW fo r processing in the background . Background work processes run p rograms that can be executed wi thou t user interact ion (background jobs ) .

The e n q u e u e work process admin is te r s a logical lock table in the shared m e m o r y area. This single lock table conta ins all of the logical da tabase locks for an AS ABAP and is an impor t an t par t of the SAP LUW process. There is the re fo re only o n e ABAP applicat ion server wi th e n q u e u e work processes. It is normal ly suffi-cient for a single e n q u e u e w o r k process to p e r f o r m the requ i red tasks.

The spool work process passes sequent ia l datasets to a pr in te r o r to optical archiving. Each ABAP applicat ion server may conta in only o n e spool w o r k pro-cess. The last two types o f processes a re the message server and the ga teway: The message server routes messages b e t w e e n applicat ion servers, a n d the ga teway routes messages in and out of the system to external systems.

Important Terminology Chapter 3 73

AS ABAP

Dispatcher

Dialog Work

Processes

Update Work

Processes

Background Work

Processes

Enqueue Work

Process

Spool Work

Process

Database management s

Database

Figure 3 6 ABAP Application Server

Important Terminology

A dialog s tep is the p rog ram processing that occurs af ter a screen is released by a user or, put a n o t h e r way, the processing that occurs du r ing a screen change (even if the same screen is being redisplayed). Af ter the comple t ion o f a dialog step, the work process is released whi le the next screen is processed by the user on the presen ta t ion server .

A Reposi to iy object is o n e of the c o m p o n e n t s (program, screen def ini t ions , menus , func t ion modules , and so on) s tored in a special part of the database k n o w n as the Reposi toiy .

% Practice Questions

The practice ques t ions be low will he lp y o u evaluate y o u r unde r s t and ing of t he topic. The ques t ions s h o w n are similar in na tu re to those f o u n d on the certifica-t ion examina t ion . Wherea s n o n e of these ques t ions will be f o u n d on the exam itself, they a l low y o u to review y o u r knowledge of the subject . Select the correct answers and then check t he comple t eness o f y o u r answers in the fol lowing solu-

74 Chapter 3 SAP NetWeaver — Overview

tion section. R e m e m b e r that y o u must select all correct answers and on ly correct answers to receive credi t for the ques t ion .

1. The In terne t Communica t ion M a n a g e r (ICM):

• A. Replaced SAP ITS

• B. Allows SAP Ne tWeaver Applicat ion Server to process HTTP reques ts

• C. Allows the ABAP stack and the Java stack to exchange data

2. The Java stack and the ABAP stack of an SAP Ne tWeaver Applicat ion Server mus t always be installed together .

• A. True

• B. False

3. A work process:

• A. Stays l inked to a screen th rough the d ispatcher

• B. Becomes inactive whi le wai t ing for a user

• C. Uses a c o m m o n m e m o i y area called sha red m e m o r y

4. Each w o r k process:

• A. Is i n d e p e n d e n t of o the r work processes

• B. Uses a pool o f database connec t ions established w h e n the SAP Ne tWeave r Application Server ABAP star ted

• C. Uses a database work process es tabl ished w h e n the SAP Ne tWeaver Applicat ion Server ABAP star ted

• D. Can only make database changes wi th in a single da tabase LUW

• E. Can make da tabase changes spann ing mult iple database LUW

5. Each work process is assigned a type of task that can be p e r f o r m e d . Which s t a t emen t s a re t rue related to this?

• A. To switch a work process type requi res a restart of the SAP Ne tWeave r Applicat ion Server ABAP.

• B. All work processes have the same s t ruc ture .

• C. All work processes c o m m u n i c a t e wi th the database .

Practice Question Answers and Explanations Chapter 3 75

• D. All work processes communica t e wi th the d ispatcher .

• E. A work process can c o m m u n i c a t e direct ly wi th an external sys tem through a Remote Funct ion Call.

• F. It is possible to have mul t ip le e n q u e u e work processes o n an SAP Ne tWeaver Applicat ion Server.

• G. It is possible to have mul t ip le spool work processes on an ABAP applica-t ion server .

Practice Question Answers and Explanations

1. Correct answer : B

Beginning wi th SAP Ne tWeaver 6 .10. n e w technologies based on highly scal-able inf ras t ruc ture w e r e i m p l e m e n t e d to process HTTP reques ts directly f r o m the In terne t o r to send t h e m as HTTP client reques ts to t he In ternet . The SAP kernel was enhanced to include a process k n o w n as the In terne t Communica -t ion M a n a g e r (ICM) to achieve this funct ional i ty .

2 . Correct answer : B

Dif ferent SAP Ne tWeaver c o m p o n e n t s requi re the SAP Ne tWeaver Applica-t ion Server to be run wi th certain stacks conf igured . It is possible to install bo th the ABAP and Java stacks, but d e p e n d i n g on the use of the server, it is possible to use j u s t ABAP or j u s t Java.

3. Correct answer : C

All of the work processes of an ABAP applicat ion server use a c o m m o n main m e m o r y area called sha red m e m o i y to save contexts or to bu f fe r cons tant data locally. The resources that all work processes use, for example p rograms and table contents , are conta ined in shared m e m o r y . M e m o r y m a n a g e m e n t in the AS ABAP ensures that the work processes a lways address the correct context .

4 . Correct answers : A, D

Each individual w o r k process w o r k s independen t ly , which makes t h e m suit-able for a mul t iprocessor archi tecture .

W h e n y o u start up an AS ABAP, each ABAP applicat ion server registers its work processes wi th the database layer and receives a single dedicated chan-nel for each. Whi le the SAP Ne tWeaver Applicat ion Server is runn ing , each work process is a user (acting as a client) o f the database sys tem (acting as a

62 Chapter 3 SAP NetWeaver — Overview

server). You cannot change the work process registrat ion whi le the sys tem is runn ing . It is also not possible to reassign a da tabase channe l f r o m o n e work process to ano the r . For this reason, a work process can only make database changes wi thin a single database logical uni t o f work (LUW). A work process must o p e n a separa te database LUW for each dialog s tep . The work process sends a commi t c o m m a n d (database commi t ) to the da tabase at the e n d o f each dialog s tep in which it makes da tabase changes. These c o m m i t com-m a n d s are called implicit da tabase commits , because they are not explicitly wr i t t en into the applicat ion p rogram.

5. Correct answers : B, D, F

You can use the sys tem adminis t ra t ion func t ions to switch a work process whi le the sys tem is runn ing . Because each work process has the same struc-ture, they are in terchangeable . All work processes must c o m m u n i c a t e wi th the d i spa tcher (which assigns the user to a work process), but e n q u e u e work processes and spool work processes do not c o m m u n i c a t e wi th t he database . All communica t ion for a work process occurs wi th e i ther the d ispatcher o r the database .

Wherea s it is no rma l to only have o n e e n q u e u e work process (a single e n q u e u e work process is normal ly suff icient to p e r f o r m the requi red tasks), it is possible to have mult iple e n q u e u e w o r k processes runn ing . In SAP Ne tWeaver Applicat ion S e r v e r y o u can on ly have one lock table, but mul t ip le e n q u e u e work processes, runn ing . Each ABAP applicat ion server can conta in only one spool work process.

Take Away

N o w that y o u have learned h o w an ABAP application server operates , y o u can take away the d i f ferences be tween an SAP NetWeaver Application Server and a classic SAP Application Server. You have also learned the c o m p o n e n t s of a work process and h o w they work wi th o the r c o m p o n e n t s of an ABAP application server o r o the r layers, for example , the presenta t ion server and the database server .

R e f r e s h e r

You must unde r s t and the pu rpose o f the d i f fe rent layers o r tiers of an SAP Ne tWeaver Applicat ion Server. It is impor t an t to unde r s t and t he archi tec ture

Take Away Chapter 3

a n d w h y it is b o t h e f f i c i e n t a n d s ca l ab l e . You m u s t u n d e r s t a n d h o w t h i s s y s t e m

d e s i g n h a n d l e s b o t h t h e d a t a b a s e (SAP L U W ) a n d e x e c u t i o n o f p r o g r a m s (d i a log

s t eps ) .

T a b l e 3 . 2 s h o w s t h e k e y c o n c e p t s f o r t h e SAP N e t W e a v e r O v e r v i e w .

Key C o n c e p t Def in i t ion

SAP NetWeaver The application platform of SAP NetWeaver .

Application Server

SAP NetWeaver The stack within SAP NetWeaver Application Server used to Application Server execute ABAP applicat ions ABAP

ABAP application A sof tware c o m p o n e n t of t he SAP NetWeaver Application server Server ABAP tha t runs all ABAP programs. This is t he applica-

tion layer of the multi-t ier archi tecture of an ABAP-based SAP

system.

Work process A c o m p o n e n t that is able to execute an applicat ion. It executes a single dialog s tep .

Dispatcher Establishes t he link b e t w e e n t h e user logged on and a work

process.

Gateway The interface for communica t ion b e t w e e n t he SAP NetWeaver Application Server A8AP and ano the r system (either ano the r A8AP Application Server, a n o t h e r SAP NetWeaver Application Server, or an external non-SAP system.)

Screen Processor A c o m p o n e n t of a work process that executes t he screen f low logic

ABAP Processor A c o m p o n e n t of a work process tha t execu tes t he processing logic of the applicat ion program and communica tes with t he da tabase interface

Database Interface A c o m p o n e n t of a work process establishes a connect ion b e t w e e n t he work process and t he da tabase , provides access to t he da tabase tables and Repository objects , controls transac-tion processing (commit and rollback), and provides table buff-ering on t he ABAP application server

Table 3.2 Key Concepts Refresher

64 Chapter 3 SAP NetWeaver — Overview

Tips

An unde r s t and ing of the under ly ing archi tec ture of the sys tem and servers will m a k e y o u a be t te r deve loper and h e l p y o u unde r s t and t he reasoning fo r selecting be t te r o r m o r e eff icient t echniques . This topic, however , is o n e mos t deve lopers d o no t unde r s t and , and they are the re fo re unab le to take advan tage of the s t rengths of SAP NetWeaver .

Summary

You should n o w have a basic unde r s t and ing of h o w an ABAP appl icat ion server opera tes . You should k n o w w h y an SAP Ne tWeaver Applicat ion Server is differ-ent than a classic SAP Applicat ion Server. You should unde r s t and which compo-nents run on SAP Ne tWeaver and wha t genera l conf igura t ion is possible for an SAP Ne tWeaver Applicat ion Server. You should also k n o w the c o m p o n e n t s of a work process and h o w they work wi th o the r c o m p o n e n t s o f the ABAP applica-t ion server o r o the r layers (presenta t ion server and database server). An under -s tanding of the SAP Ne tWeaver archi tec ture will give y o u a solid founda t ion , and y o u will be successful in this and o t h e r sect ions of the exam.

ABAP Workbench Usage

Techniques You'll Master:

• Describe the features and capabili t ies of the ABAP W o r k b e n c h

• Explain t he s t ruc ture o f the Object Navigator

• Use the Reposi to iy Browser to edit r epos i to iy objects

• Access the Reposi to iy In fo rmat ion System to search for repos-i tory objects

• Unders tand the E n h a n c e m e n t In format ion System and its use

• Work wi th the ABAP W o r k b e n c h tools

• Ident i fy the n e w Front-End Editor and the var ious set t ings to improve product iv i ty

• De te rmine the concept of the Deve lopment Package and the Transpor t Organizer

ioo Chapter 4 ABAP Workbench Usage

The ABAP W o r k b e n c h is the d e v e l o p m e n t e n v i r o n m e n t for the SAP Ne tWeaver Applicat ion Server ABAP and is available in eve iy ABAP-based SAP system. The ABAP W o r k b e n c h provides the d e v e l o p m e n t tool needed for application devel-o p m e n t . The Object Navigator, the central en t ry poin t into t he ABAP Work-bench, conta ins t he most c o m m o n l y used d e v e l o p m e n t tools a n d is the r e c o m m e n d e d d e v e l o p m e n t e n v i r o n m e n t .

In this chap te r w e will cover in detail the ABAP W o r k b e n c h tool and the Object Navigator. W e will cover features and capabili t ies o f the ABAP W o r k b e n c h , dis-cuss the s t ruc ture o f the Object Navigator, and discuss in detail the var ious b rowse r s available in the Object Navigator . W e will cover in detail the n e w Front-End Editor, the Reposi tory In fo rmat ion System, and the E n h a n c e m e n t In fo rmat ion System. W e will also cover ABAP W o r k b e n c h tools such as the ABAP Editor, Screen Painter, M e n u Painter, ABAP Dictionary. Class Builder, Funct ion Builder, and W e b Application Builder. Finally, w e will discuss packages and their a t t r ibutes and the Transpor t Organizer .

Real-World Scenario

You have s tar ted o n a cus tomer project as an SAP d e v e l o p m e n t lead a n d have been asked to explain to the project team abou t the ABAP Work-bench . You have to explain to the project team abou t the SAP d e v e l o p m e n t tools and the var ious fea tures o f the ABAP W o r k b e n c h and the Transpor t Organizer .

As a d e v e l o p m e n t lead, y o u have to organize the technical d e v e l o p m e n t for the project . Your j o b is to de f ine the d e v e l o p m e n t s tandard and the tools to be used for the var ious deve lopmen t s . You also have to de f ine the devel-o p m e n t project , package, sys tem landscape, and t r anspor t s t rategy for all of the d e v e l o p m e n t s in the projec t .

Objectives of this Portion of the Test

O n e of the object ives of the ABAP cert if ication examina t ion is to veri ly y o u r knowledge of the ABAP W o r k b e n c h and the var ious tools associated wi th it. You need to unde r s t and the fol lowing to be a successful ABAP deve loper :

Key Concepts Refresher Chapter 4 81

• ABAP W o r k b e n c h and d e v e l o p m e n t tools

• ABAP W o r k b e n c h set t ings

• The use of var ious b rowsers in the ABAP W o r k b e n c h

• The n e w Front-End Editor and the sett ings to improve product iv i ty

• Deve lopmen t Packages and Transpor t Organizer

Key Concepts Refresher

The ABAP W o r k b e n c h is the integrated d e v e l o p m e n t e n v i r o n m e n t for the appli-cation deve loper . The W o r k b e n c h has mos t of the tools a deve loper needs to deve lop an appl icat ion. Some of the mos t c o m m o n l y used w o r k b e n c h tools are:

• ABAP Editor

• Screen Painter

• M e n u Painter

• ABAP Dict ionary

• W e b D y n p r o d e v e l o p m e n t tools

• Package Builder and Transpor t Organizer

• Reposi to iy Browser

• Reposi tory In fo rmat ion System

• Enhancemen t In format ion System

ABAP Workbench

ABAP stands for Advanced Business Application Programming and is the language in which most o f the SAP business appl icat ions are wr i t t en . The ABAP Work-bench is the deve lopmen t e n v i r o n m e n t for the ABAP deve loper . The ABAP W o r k b e n c h consists of the d e v e l o p m e n t tools requi red for creat ing repos i to iy objects . The ABAP W o r k b e n c h can be s tar ted via Transact ion SE80. The Object Navigator can be accessed f r o m the m e n u path OVERVIEW • OBJECT NAVIGATOR and is t he main en t ry poin t to ABAP W o r k b e n c h .

The main screen of the ABAP W o r k b e n c h is d iv ided into the navigat ion area and the tool area (see Figure 4.1) . The navigat ion area displays the object list as a hier-archy t ree . The object list consists o f all of the objects wi th in an applicat ion area.

ioo Chapter 4 ABAP Workbench Usage

p a c k a g e , p r o g r a m , g l o b a l c lass , m o d u l e p o o l , f u n c t i o n g r o u p , a n d s o o n . T h e b e n -

e f i t o f e d i t i n g o r d i s p l a y i n g t h e o b j e c t w i t h i n t h e O b j e c t N a v i g a t o r is t h a t y o u c a n

v i e w all o f t h e r e l a t e d o b j e c t s f o r t h e p r o g r a m , class , m o d u l e p o o l , o r p a c k a g e as

a t r e e s t r u c t u r e a n d c a n a c c e s s t h e m f r o m t h e n a v i g a t i o n a r e a b y j u s t d o u b l e -

c l i ck ing o n t h e o b j e c t . I f y o u w o r k w i t h t h e r e p o s i t o i y o b j e c t w i t h t h e i n d i v i d u a l

t o o l , t h e n y o u o n l y h a v e t h e o p t i o n to w o r k w i t h o n e t y p e o f o b j e c t a t a t i m e

w i t h o n e t o o l .

Full Screen On/Off Menu

Tool Area

Object List Selector

Tool Area Context Menu

Navigation Area

Navigation Area

Context Menu

Worklist

Navigation Stack

Figure 4-1 ABAP W o r k b e n c h Screen

T h e t o o l a r e a is u s e d to d i s p l a y o r e d i t t h e r e p o s i t o r y o b j e c t u s i n g t h e r e l e v a n t

too l e d i t o r . T h e n a v i g a t i o n a r e a o r t h e too l a r e a c a n b e r e s i z e d . You c a n h i d e t h e

n a v i g a t i o n a r e a b y c l i c k i n g o n t h e FULL SCREEN ON/OFF i con ( O ) o n t h e a p p l i c a -

t i o n t o o l b a r . T h e o b j e c t n a v i g a t i o n h i s t o i y w i t h t h e A B A P w o r k b e n c h is s t o r e d

in t h e n a v i g a t i o n s t ack . T h e O b j e c t N a v i g a t o r h a s a m e n u o p t i o n t o d i s p l a y t h e

n a v i g a t i o n h i s t o i y . Y o u c a n d i s p l a y t h e n a v i g a t i o n w i n d o w f r o m t h e m e n u

o p t i o n U T I L I T I E S • D I S P L A Y N A V I G A T I O N W I N D O W , a n d a n a d d i t i o n a l w i n d o w f o r

t h e n a v i g a t i o n s t a c k wi l l b e d i s p l a y e d u n d e r t h e t o o l a r e a o f t h e w o r k b e n c h . You

c a n a l so d i s p l a y t h e n a v i g a t i o n w i n d o w b y c l i ck ing o n t h e DISPLAY NAVIGATION

WINDOW icon ( a ) o n t h e a p p l i c a t i o n t o o l b a r . You c a n sc ro l l b a c k t h r o u g h t h e

n a v i g a t i o n s t ack b y c l i ck ing o n t h e b l u e l e f t a r r o w o r f o r w a r d b y c l i ck ing o n t h e

Key Concepts Refresher Chapter 4 69

right a r r o w icon in the navigat ion stack w i n d o w . This tool helps y o u scroll t h rough the objects y o u have v iewed dur ing the logon session.

You can create y o u r o w n workl is t wi th in the ABAP W o r k b e n c h . A workl is t is useful to help y o u manage the d e v e l o p m e n t objects on which y o u need to work . To create y o u r workl is t y o u need to display o r edit the repos i tory objec t first in the tool area o f the ABAP W o r k b e n c h and then f r o m the m e n u op t ion select UTILITIES • WORKLIST • INSERT CURRENT OBJECT. T h i s i n s e r t s t h e o b j e c t i n t h e

worklis t . You can display the workl is t via the m e n u path UTILITIES • WORKLIST • DISPLAY, and an addi t ional w i n d o w for the workl is t will be displayed u n d e r the tool area of the ABAP w o r k b e n c h .

You can access the Reuse Libraiy f rom the W o r k b e n c h m e n u path ENVIRONMENT • REUSE LIBRARY. The Reuse Libraiy provides y o u wi th a set of reusable objects wi th example code and documenta t ion . You can execute the code to display the result and copy the reusable code for y o u r application deve lopmen t . The Reuse Libraiy is displayed in the b rowser , and y o u can display the individual deve lopmen t objects wi th in the Reuse Libraiy by double-clicking on the p roduc t and reading the example code. You can also access the Reuse Libraiy via Transact ion SE83.

Similar to the Reuse Library, y o u can access the ABAP examples via the m e n u path ENVIRONMENT • EXAMPLE • ABAP EXAMPLE. The ABAP example p rograms are displayed in the b rowser , a n d y o u can display individual p rograms by double -clicking on the example p rog ram in the navigat ion area. The actual p rog ram is displayed in the tool area of the Object Navigator. ABAP examples provide exam-ples o f most of the keywords and syntax based on the ABAP documen ta t i on . You can also access the ABAP documen ta t i on f r o m the ABAP examples screen. ABAP examples can also be displayed by execut ing Transact ion ABAPDOCU.

You can display the context m e n u for an objec t wi th in bo th the navigat ion area and the tool area by right-clicking o n the object . The context m e n u of fers on ly the func t ions that are relevant for t he selected repos i to iy objects . You have the op t ion to add y o u r d e v e l o p m e n t objects to y o u r favori tes list wi th in the Object Navigator by clicking on the FAVORITES icon ( 0 ) in t he navigat ion w i n d o w .

You can access the individual tools to create the reposi to iy objects using individ-ual transaction codes o r access the most c o m m o n l y used tools f rom the Object Navigator. The initial screen of the Object Navigator displays the Browser list on the top-left section of the screen. The Object Navigator has several b rowsers that y o u can use for various deve lopmen t needs . You have the opt ion to navigate to

ioo Chapter 4 ABAP Workbench Usage

the re levant tool based on the selected b r o w s e r f r o m the b r o w s e r list (see Figure 4.2). You can add o r r emove b rowsers f rom the list via the m e n u path UTILITIES • S E T T I N G S .

Object Navigator S D EdtObtect

o>Wet> D>npf o Tea Browser &MME Repository •"Sooositcxy Erc«$ef ^Repository Mormaaoci System g)Tag Browser ftTranspoitOrganger ^Enhancement Info System ©Enterprise Services Brc«sc<

Figure 4.2 Object Navigator

The Object Navigator list has the fol lowing b r o w s e r selection op t ions in the objec t navigat ion:

• W e b D y n p r o Text B r o w s e r

You use the W e b D y n p r o Text Browser to edit t he text o f the W e b D y n p r o UI e l emen t s that are created or managed in the Onl ine Text Repository (OTR). This tool al lows y o u to change the only texts for the W e b Dynpro views that have been s tored in the OTR or inser ted f r o m the OTR in the W e b D y n p r o appl icat ion.

• MIME R e p o s i t o r y B r o w s e r You use the M I M E Reposi tory Browser (Mul t ipurpose In te rne t Mai l Exten-sions) to b r o w s e o r impor t MIME objects such as style sheets , icons, graphics , and so on f r o m the ABAP W o r k b e n c h . The MIME Reposi toiy s tores these M I M E objects in t he SAP sys tem. The MIME Reposi to iy Browser automat i -cally creates a fo lder for Business Server Pages (BSP) applicat ions. You can impor t MIME objects f rom the Reposi toiy Browser o r v iew the M I M E objects by double-cl icking on t h e m .

• Tag B r o w s e r The Tag Browser provides the documen ta t i on o f the user in terface e l emen t s that can be used for w e b page d e v e l o p m e n t for BSP appl icat ions a n d In terne t Transact ion Server (ITS) templates . You have t he op t ion to filter the tags for the BSP applicat ion o r the tags for the ITS templates . The Tag Browser pro-vides documen ta t i on for HTMLB, BSP extens ion, BSP Directives, HTML, WML, and XHTML.

Key Concepts Refresher Chapter 4 71

• Test R e p o s i t o r y B r o w s e r You use the Test Reposi to iy Browser to manage test cases. You can display eCATT test scripts, manua l test cases, and external test cases. You also have the op t ion to create test cases wi th in the Test Reposi to iy Browser. It 's a good tool for y o u to manage the test cases wi th in the Test Reposi toiy .

O the r b rowse r s such as the Reposi to iy Browser, the Reposi tory In fo rmat ion Sys-tem, the Enhancemen t In format ion System, and the Transpor t Organizer are dis-cussed in detail in the fol lowing.

Repository Browser

The Reposi tory Browser is o n e o f the m e n u op t ions in the Object Navigator and is s tar ted by defaul t w h e n y o u execute the Object Navigator (Transaction SE80). You can create and edit repos i to iy objects in the Reposi to iy Browser . The Repos-i to iy Browser is the central tool for managing y o u r d e v e l o p m e n t objects wi th in the Object Navigator and is the most c o m m o n l y used tool.

W h e n we talk about reposi tory objects , w e mean all of the SAP-delivered objects and cus tomer -deve loped objects . These repos i to iy objects consist o f programs, classes, ABAP Dict ionary objects , func t ions modules , screens, menus , and so on .

The objec t list d isplayed in the Reposi to iy Browser is a hierarchical t ree struc-ture . You can navigate to a repos i to iy objec t by the applicat ion hierarchy, w h e r e b y y o u can list the objects wi th in each of the SAP applicat ion c o m p o n e n t s . The objects can also be listed in a hierarchical t ree s t ruc ture wi th in a package, p rogram, class o r interface. BSP applicat ion, W e b Dynpro applicat ion, local object , and so on .

You can display the object f r o m the navigat ion area by double-clicking on it. The object will be displayed in the tool area of the object b r o w s e r in the ed i tor that has been used to create the object . The ABAP d e v e l o p m e n t objects are displayed in the ABAP Editor, whe rea s the Dict ionaiy objects are displayed in the ABAP Dict ionaiy tool. Similarly, y o u display the screens and the m e n u s in the tool area in the Screen Painter or M e n u Painter by double-cl icking o n the screen o r m e n u in the navigat ion area. You can use the context m e n u s in the navigat ion area to create o r edit the objec t in the applicat ion area o r package (see Figure 4.3).

You can create or edit r epos i to iy objects on ly if y o u have the app rop r i a t e devel-ope r author iza t ion and y o u r user ID has been registered in the SAP Service Mar-

ioo Chapter 4 ABAP Workbench Usage

ketplace as a developer. You need to provide the developer access key for the first time you create any repositoiy object. You only have to provide the access key once because the system stores it for you in the table OEVACCESS.

Navigate History

Higher level Hierarchy object

Add/Edit Favorites

Refresh Object List

Package

A * ffl a Name

G V F I CJ Dctooary Ct>>e is " CJ Class LIBTOV

11 tl

Descni*oo Aocacaeon dovotoomw* Rf3 irvcxco

C3 CL_EX_SOj N LV iO.BAd class CL EX SO C N LV60AI WA F ^ B A d Class CL f x VOf? WA FAKP

d trip VOft_WA_F/ k B I no Accord nq

• t A 1

: asssE' _—_ — . Cre—, a s o f r CONSI c r a r »

I' G Programs Ci FuxBon Groups

!• OhcWes • CJ Transactions i OOioiog Modules I O SET/GET Parameti I CJ MESSAGE CLASSES I' G Ar«fl M*<vt • a T * « o t # c t * T' CJ AUMCOZATIO«OE>JS !• CJ Enhancements • CJ ITS Services

Display Check Actvaee Test CcK* Rename geite VWiere^AedLta Find Otfwc Functic*»s

Application Hierarchy Packagc Program Function Croup Class/Interface Internet Services BSP Application Local Objects inactive Objects

Context M e n u

Figure 4-3 Repository Browser Navigation Area

Some of the common context menu functions for repositoiy objects are to check repositoiy objects, activate an object, copy or rename objects, and change the package assignment of an object or write the object to the change request. You also have the where-used list function of the object from the context menu.

Repository Information System

The Repositoiy Information System Browser is used to search for repositoiy objects in the SAP system. The initial screen of the Repositoiy Information Sys-tem displays a hierarchical list of the categories of repositoiy objects in the SAP System (see Figure 4.4).

The Repository Information System has a selection screen to provide the search criteria for the repositoiy objects. You can search for repositoiy objects within a package or search for ABAP Dictionaiy objects or programs by specifying the search criteria on the selection screen. Figure 4.5 displays the Repository selec-tion screen for database tables within ABAP Dictionary objects.

Key Concepts Refresher Chapter 4 87

• R«oosflo»v rtormaoon Svswm _J Dwvntoixrwrt Coofdrvsdcn

B Packages B Pact-age rtertaces [3 ReauesH/Tasks

'-• 3 Business Enoi»««ing t> £1 Data t/oaoioj 0 C3 Process MoOrt no • CJBwnessOtwctBrowef U ASAP Dictonarv

B Database Tawes D Views B Tabto Types B Smxtures B Data Elements B Doners B Search Hdp? B Lock Objects B TvueOroccs

• CJOT« Object* f c3F.e«s

• CI Program library v 3 Ctass library • aweoCVnpro «• CJ BSP Library »• Erc&Tyvse Services t• a Etfvmcecnerts * QToaOCricts • aoowrotiects

Figure 4 .4 Repository Information System

Standard st*xt>ons Tat*>N*r» • SJKrt devcncOco •

Patkaje *

A«4ca>0ri CompCrtSft • j

•* Transpa-ert iC vkws Sa-uctures V Pool - Cluster

Poc*»ov:»/Kert0t4« • j Rtferenced Eroty Type

• At JO IA>itMunc« d Msrtonnnce not nio

last changed by • j Changed on •

DthtryCWJ 3

• Al 1 <. Cl«*-specific 1 Crosvcl«t

S«Dngs Msonjn no o»HB 200

Figure 4-5 Repository Selection Screen for ABAP Dictionary Objects

ioo Chapter 4 ABAP Workbench Usage

You can access the selection screen for the repos i tory objec t by double-cl icking o n the type o f reposi tory object in the object navigat ion area; the selection screen relevant for the object will t hen be displayed in the tool area o f the Object Nav-igator.

You can cus tomize the selection screen of the Reposi tory In fo rmat ion System. To cus tomize the selection screen select EDIT* SETTINGS f r o m the initial screen of the Reposi to iy In fo rmat ion System browser . You can specify in the cus tomizat ion if y o u w a n t to see the defaul t selection screen o r the screen wi th all o f the available selection criteria. You can also display all o f the selection criteria for the objec t by clicking o n the app rop r i a t e icon ) on t he applicat ion toolbar .

You can specify the search criteria for the repos i to iy object in the selection screen and execute . The system displays the search results in the tool area o f the Object Navigator. You can also select the objec t f r o m the search result a n d dis-play the where -used list o f the object if required, a n d y o u can double-click on it to look at the objec t itself in the appropr ia t e tool.

The Reposi tory In fo rmat ion System is a useful tool to display the available e n h a n c e m e n t s wi th in the SAP sys tem. You can search for bo th the def in i t ion and the implemen ta t ions of the e n h a n c e m e n t wi th this tool. You can filteryour selec-t ion of e n h a n c e m e n t s by appl icat ion c o m p o n e n t or package. You can search for Business Add-Ins, cus tomer exits, e n h a n c e m e n t implementa t ions , and enhance -m e n t def in i t ions . For a detai led explanat ion of e n h a n c e m e n t s and modif ica t ions re fer to Chapter 18, Enhancemen t s and Modi f ica t ions .

Workbench Settings

You can conf igure the ABAP W o r k b e n c h to change its look and funct ional i ty . The w o r k b e n c h is conf igured f r o m the m e n u path UTILITIES • SETTINGS (see Figure 4.6). The W o r k b e n c h set t ings are user specific a n d the re fo re d o not affect a n y o n e else in the sys tem.

The Object Navigator can display only eight b r o w s e r lists at a t ime. You can unse-lect the b r o w s e r selection checkbox for the b rowsers that y o u are not go ing to use very o f t en .

Wi th in the W o r k b e n c h sett ings y o u also have the op t ion to conf igure the ABAP Editor set t ings. You can select the n e w Front-End Editor, the old Front-End Edi-tor, or the s tandard Back-End Editor and cus tomize its settings. You have the

Key Concepts Refresher Chapter 4 75

o p t i o n to set y o u r de fau l t ABAP D e b u g g e r to e i t h e r t h e classic o r n e w ABAP D e b u g g e r . You can c h a n g e y o u r P re t ty P r in t e r se t t ings , Split Screen se t t ings , a n d t h e Pa t t e rn se t t ings . You can m a i n t a i n the se t t i ngs f o r t h e Class Bui lder , Screen Painter , M e n u Painter , Func t ion Bui lder , R e p o s i t o i y I n f o r m a t i o n S y s t e m , Data Browser , I n t e r n e t T ransac t i on Server , Bus iness Se rve r Pages, W e b D y n p r o . T r a n s p o r t Organ ize r , SAPscript , eCATT, a n d p r o x y g e n e r a t i o n f r o m t h e W o r k -b e n c h se t t ings as wel l .

Workbench (General) , ABAPEdtor , Class BwWer , Screen Painter , MenuPanter Ih Q Q 3

htial Screen : 1 Dispte/ Bkground Picture

Browser Selection V Repository Browser " Repository Irformaoon System V Transport Or panzer v M M E Repository y Tag Browser • T e s t Repository

/ Enterpnse Service Browser •* Web Dyr*>ro Text Browser * Enhancement Information System

Figure 4 6 A8AP Workbench Customization Screen

New ABAP Editor and Workbench Settings

T h e r e a re t h r e e d i f f e r e n t m o d e s f o r t h e ABAP Edi tor :

• F ron t -End Edi tor ( sou rce c o d e m o d e — n e w )

• F ron t -End Edi tor (pla in text m o d e - o ld)

• Back-End Ed i to r ( l ine-based m o d e )

T h e t h r e e e d i t o r s a re ful ly c o m p a t i b l e a n d i n t e r c h a n g e a b l e . T h e s o u r c e c o d e cre-

a t ed in o n e e d i t o r can b e v i e w e d b y all o t h e r m o d e s .

ioo Chapter 4 ABAP Workbench Usage

T h e c h o i c e o f t h e e d i t o r is b a s e d o n t h e u s e r - s p e c i f i c s e t t i n g s m a d e in t h e A B A P

W o r k b e n c h . T h e e d i t o r c a n b e c o n f i g u r e d w i t h i n t h e A B A P E d i t o r via t h e m e n u

p a t h U T I L I T I E S • S E T T I N G S • A B A P E D I T O R ( s e e F i g u r e 4 . 7 ) .

Workbench (General) ABAP Editor , Class Butdw , Screen Pawer [ Menu P a n t * n. r P T i l

Editor , PreCy Pnrter , Spttscreen , Debug? ng , Pattm , WorVJst

[•Front-End Editor (New) " : Frort-Er-d Editor (Old) Back-End Editor

Mjrrfcenng Compression

* vwo compression logic

Patfifcf local editirvj C\D0CUME~1V80488N.0CALS>1\Teme

Upper-A.ow«rces« Conversion in Disp Mode Display al svntax errors Downwards-Comp Line Lngth(72)

• X

Figure 4.7 ABAP Editor Customization Screen

T h e FRONT-END EDITOR (NEW) o p t i o n p r o v i d e s t h e l a t e s t e d i t o r a n d c o m e s w i t h

SAP G U I f o r W i n d o w s 7 . 0 . T h e n e w e d i t o r is a n Ac t iveX c o n t r o l a n d is f u l l y i n t e -

g r a t e d i n t o t h e SAP N e t W e a v e r 7 . 0 e n v i r o n m e n t .

T h e n e w e d i t o r h a s all o f t h e m o d e r n c o d e e d i t i n g f e a t u r e s :

• T h e l e f t m a r g i n o f t h e m a i n s c r e e n o f t h e e d i t o r d i s p l a y s a n y b o o k m a r k s a n d

b r e a k p o i n t s . B r e a k p o i n t s a r e d i s p l a y e d w i t h a r e d s t o p s ign , a n d b o o k m a r k s

a r e d i s p l a y e d as a b l u e f lag in t h e e d i t o r m a r g i n . You c a n se t u p t o n i n e b o o k -

m a r k s a n d a n u n l i m i t e d n u m b e r o f b o o k m a r k s t h a t a r e n o t n u m b e r e d o n t h e

e d i t o r f o r fas t n a v i g a t i o n w i t h i n t h e c o d e .

• T h e e d i t o r h a s a l i n e n u m b e r m a r g i n n e x t t o t h e e d i t o r m a r g i n , w h e r e t h e l i n e

n u m b e r is d i s p l a y e d .

• T h e c o d e c h a n g e s a r e m a r k e d w i t h a r e d t r i a n g l e a g a i n s t t h e l i ne n u m b e r .

• T h e s t a t u s b a r d i s p l a y s t h e c u r r e n t s t a t u s o f t h e c o d e .

Key Concepts Refresher Chapter 4 91

• The vertical scroll t ip provides in fo rmat ion abou t t he cur ren t scroll posi t ion wi th in the code, cur ren t func t ion , class, o r m e t h o d .

• You can split the code ed i tor screen horizontal ly by double-clicking on the spli t ter l ine on the vertical scroll bar . You can also j u s t drag the spl i t ter l ine to split the ed i tor screen horizontal ly .

• You can collapse or expand blocks of code such as 1F-ENDIF o r CASE-ENDCASE.

• The status bar of the ed i tor displays the cur ren t s tatus o f the Caps Lock and N u m Lock, and the line n u m b e r of the cursor posi t ion. The Caps Lock and the N u m Lock can be changed by double-cl icking o n t h e m . Double-clicking on the line n u m b e r displays the G o TO LINE dialog.

• The Front-End Editor has two types of context m e n u ; the context m e n u op t ions d e p e n d on the area selected for the context . The margin context m e n u is displayed by right-clicking on the left margin and has the op t ion to set b reakpoin ts , de le te breakpoin ts , set bookmarks , clear bookmarks , o r nav-igate to a bookmark (see Figure 4.8).

1 • Bookmarks

us abhob u»\t>eln

Goto Bookmark More Se< Session Breakpoint Sot External Breakpcm*

9 1alt1*1 and vtoa* abfeod

label aapiv451 a i v j i

Del«e Session Breakpoint Delete External Breakpoint

rv«St Bsovs

vtoak abhod ua_abhod space

Figure 4.8 Margin Context Menu

The context m e n u in the edi t ing area displays the m e n u op t ions for the ABAP code. The edi t ing area context m e n u has var ious format t ing , edi t ing, a n d nav-igation op t ions (see Figure 4.9).

• The ed i tor provides code hints at r un t ime as y o u type by suggest ing keyword hints , block templates , and so on . You can accept the code hint by pressing the 1 I key o r insert a block t empla te by selecting I C t r l l + f ^ l . Further-more , the ed i tor suppor t s WYSIWYG expor t funct ional i ty . It suppor t s expor t to HTML, PDF, and RTF formats .

• The n e w ABAP Editor is a fully integrated d e v e l o p m e n t e n v i r o n m e n t (IDE) for ABAP p rog ramming . It suppo r t s syntax highlight ing, out l in ing language s t ructures , real- t ime code hints, and au to comple t ion o f language s t ructures .

ioo C h a p t e r 4 A B A P W o r k b e n c h Usage

I T T 154 155 15< 15" 150 15» 1*0 1«1 1(3 1*3 U-t H5 l « l«" HO 149 n o

1?: \T\

m I H

n o

ICO I f ] I P : i n

' 1 1 1 '

• CLASS el m m IltPL*

KTKOC o*»_»il»n«

DATA : I JI I«n« MOW

It p_logi IS NO f i n J CALL r»!CTlC«

ixronTme Find Incremental Replace

Col • F Ctrl* I

Ctrl • H iogic«i_t More

. ' Format

• i x c r m c K j

CTHIP3

M«vig«in Outlining Next identical structure level Previous identical structure level Go to Start of Unt Go to End ct Unit BlockBiffer Enhancements

Figure 4 - 9 C o n t e x t M e n u for Text F o r m a t t i n g

• With the n e w code ed i to r y o u can cus tomize the highlighting for the key-word , strings, and c o m m e n t s . You can cus tomize the font , color, and size for ABAP keywords and c o m m e n t s . Similarly, y o u can cus tomize font , color, and size for strings, breakpoints , and o the r display i tems in the code ed i to r (see Figure 4.10) .

Cwttoy fot*% andColort Cod? Co^^ttyi CodeTencfete*

re>t)Mf<J frrt

Font S o .

T Cour ie r Ne» ft 10 Si •f Shcwr<n^m0n0cp*c4dlcr<i

Dncfayliwra li*m la tv tml node

r p n r t t • Si Hen b«c* grord

N r t o s Cvcalf i SWIJ) S)T<«t<jl ercr

Otaieewi A

I | Manxx Si

GBdd ; Undwtne C1K*:

ImtU

AsBbCc

5 M He*.

Figure 4 - i o C o d e Edi tor C u s t o m i z a t i o n for Color Schemas

Key Concepts Refresher Chapter 4 93

• You can cus tomize the display set t ings of y o u r edi tor . Figure 4 .11 shows the display cus tomizat ion screen. The display and the word w r a p op t ions can be swi tched o n o r of f according to y o u pre fe rence .

Q223T Fcfltf mj Cctoi Code CwtWw Code Template*

• »wrottng keyboard f»rt

Oiplay * Inlcelct margri

Inentrtxf! * Cher d lr*t v EneUeCckpsfcieBlocki •/ PtytVMth v SuucHieseparator

•Wh»e -.wee: Vtrtc at tool tv»

v Honroriai toolbar * Swutbar * cure* Ine •/ Use smooth sooftng

• DitaMevwdwrap Wrap by wndow edge Wrap by page »•«#> Wrap by page w«*h twertng herd bie«*.

255 ; 3

He*

Figure 4.11 Display Customization for the Editor

• Lastly, y o u can customize the code comple t ion op t ions fo r the edi tor . This op-t ion al lows y o u to comple te the available keyword f r o m the dict ionary o r comple te the class, me thod , o r variable n a m e within the scope of the visibility.

ABAP Workbench Tools in Detail

With t he Object Navigator y o u w o r k direct ly wi th the repos i tory object . The rel-evant tool for the repos i tory object is automatical ly selected w h e n y o u double -click on the repos i tory object . The SAPscript Editor, Smart Forms Editor, and Cus tomer Enhancemen t Projects are s o m e of the d e v e l o p m e n t tools that are not available wi th in the Object Navigator . Following are the most c o m m o n l y used ABAP W o r k b e n c h d e v e l o p m e n t tools.

• ABAP Ed i to r

The ABAP Editor is used to deve lop p rog rams and can be executed via Trans-action SE38. You use t he ed i tor to wri te ABAP programs .

• Class Bui lder The Class Builder allows y o u to create ABAP classes within the ABAP Work-bench. You can create ABAP classes and interfaces, implement inheri tance rela-

ioo Chapter 4 ABAP Workbench Usage

t ionships , a n d c rea te a t t r ibutes , m e t h o d s , a n d e v e n t s fo r t h e global classes a n d

in ter faces that y o u bui ld . You can access t h e Class Builder via Transac t ion SE24.

• F u n c t i o n B u i l d e r

You u s e t h e F u n c t i o n Bui lder to w r i t e f u n c t i o n m o d u l e s a n d d e f i n e f u n c t i o n

g r o u p s w i t h i n t h e ABAP W o r k b e n c h . You u s e t h e F u n c t i o n Bui lder to c rea te ,

c h a n g e , d i sp lay , a n d tes t f u n c t i o n m o d u l e s . You can access t h e F u n c t i o n

Bui lder d i rec t ly via T ransac t i on SE37.

• S c r e e n P a i n t e r

T h e Screen Pa in t e r is an ABAP W o r k b e n c h tool u s e d to c r ea t e s c r e e n s f o r SAP

GUI t r ansac t ions . You use t h e Screen Pa in te r to c r ea t e s c r e e n s a n d w r i t e t h e

f l o w logic f o r sc reens . You can access the Screen Pa in te r via T ransac t i on SE51.

T h e Screen Pa in t e r l ayout e d i t o r to des ign t h e sc reen has t w o ve r s ions : t h e

a l p h a n u m e r i c l ayout e d i t o r a n d t h e g r a p h i c l ayout e d i t o r . By de fau l t , t h e

Screen Pa in te r l ayout e d i t o r is a l p h a n u m e r i c , b u t t h e m o d e can b e c h a n g e d to

g raph ica l l ayou t e d i t o r b y c h a n g i n g t h e Screen Pa in t e r se t t ing via t h e m e n u

p a t h UTILITIES • SCREEN P A I N T E R a n d s e l e c t i n g G R A P H I C A L LAYOUT E D I T O R .

You d e f i n e t h e sc reen a t t r i b u t e s a n d t h e sc reen field a t t r i b u t e s f o r t h e sc reen

fields a n d t h e f l o w logic u s ing t h e Screen Pa in te r . You can c rea te T a b Str ips .

Tab le Con t ro l s . S u b s c r e e n s , a n d C u s t o m C o n t a i n e r s u s ing t h e Screen Pa in te r ,

a m o n g o t h e r s c reen e l e m e n t s .

• M e n u P a i n t e r

T h e M e n u Pa in t e r is an ABAP W o r k b e n c h tool to c r ea t e t h e u s e r i n t e r f a c e f o r

y o u r p r o g r a m o r t r a n s a c t i o n . This cons i s t s o f the M e n u Bar, S t a n d a r d t oo lba r ,

app l i ca t ion too lba r , a n d GUI Tit le u s ing the M e n u Pa in te r . You also assign t h e

f u n c t i o n keys to t h e f u n c t i o n s y o u c rea t e in t h e M e n u Pa in te r . You can exe-

c u t e t h e M e n u Pa in t e r o u t s i d e the ABAP W o r k b e n c h via T ransac t i on SE41.

• ABAP D i c t i o n a r y

T h e ABAP D i c t i o n a i y tool is an in tegra l p a r t o f t h e ABAP W o r k b e n c h . T h e ABAP Dic t iona ry is u s e d to c rea te , c h a n g e , a n d d i sp lay t r a n s p a r e n t tables , p o o l e d a n d c lus te r tables , v iews , types , d o m a i n s , da ta e l e m e n t s , s t ruc tu re s , t ab le types , sea rch he lps , a n d lock ob jec t s . T h e d a t a b a s e ut i l i ty is a l so an in te-gral pa r t o f the ABAP Dic t i ona ry too l . You can d i rec t ly access the ABAP Dic-t i o n a i y tool o u t s i d e t h e ABAP W o r k b e n c h via Transac t ion SE11.

• W e b A p p l i c a t i o n B u i l d e r

You can build W e b Appl ica t ions wi th in t h e ABAP W o r k b e n c h . The ABAP W o r k -

bench del ivers the tool to d e v e l o p ITS w e b appl ica t ions o r BSP appl icat ions .

Key Concepts Refresher Chapter 4 81

• ITS was the first approach by SAP to ex t end business appl icat ions to w e b b rowse r s by conver t ing the SAP D y n p r o screen in to HTML format , making it possible to access SAP t ransact ions via w e b b rowsers . For ITS applica-t ions y o u can create In terne t services for existing SAP transact ions, HTML templa tes fo r the t ransact ion screens, and MIME objects to add icons and graphics to the w e b screen layout .

• You can also deve lop Business Server Pages (BSP) appl icat ions wi th t he W e b Applicat ion Builder. You can design y o u r w e b page for the BSP appli-cation using HTML and ABAP or Java Scripting language. You can de f ine the page f low and i m p l e m e n t the even t handle r wi th ABAP with the W e b Applicat ion Builder for BSP. The W e b Applicat ion Builder also al lows y o u to de f ine the t h e m e for y o u r layout and integrate the M I M E objects into the w e b appl icat ion.

• W e b D y n p r o Exp lo re r

The W o r k b e n c h has a tool f o r d e v e l o p m e n t o f W e b D y n p r o ABAP applica-t ions (as of SAP Ne tWeaver 7.0). The tool consists o f the r u n t i m e envi ron-m e n t a n d the graphical tool to design the W e b D y n p r o views wi th in t he ABAP d e v e l o p m e n t e n v i r o n m e n t .

Enhancement Information System

The E n h a n c e m e n t In fo rmat ion System provides an overv iew of the de f ined e n h a n c e m e n t s and the e n h a n c e m e n t imp lemen ta t ions wi th in the E n h a n c e m e n t F r amework . The E n h a n c e m e n t F ramework is the technical basis for SAP's n e w e n h a n c e m e n t concept ; for deta i led i n fo rma t ion refer to Chapter 18, Enhance-m e n t s and Modif ica t ions . It enables y o u to see the e n h a n c e m e n t def in i t ions and implemen ta t ions in the system.

The E n h a n c e m e n t In format ion System is a t ree display s t ruc ture for enhance-m e n t def in i t ions a n d e n h a n c e m e n t imp lemen ta t ions . The e n h a n c e m e n t e lement def in i t ion is displayed u n d e r t he e n h a n c e m e n t spot def in i t ion , wh ich in tu rn is displayed unde r the compos i te e n h a n c e m e n t spot . Similarly, the e n h a n c e m e n t e l emen t imp lemen ta t ion is displayed u n d e r t he s imple e n h a n c e m e n t implemen-tat ion. which in tu rn is displayed u n d e r the compos i t e e n h a n c e m e n t implemen-tat ion. The e n h a n c e m e n t imp lemen ta t ion n o d e is no t displayed if the e n h a n c e m e n t has not been imp lemen ted . Also, it is no t necessary that all e n h a n c e m e n t spot def in i t ions o r imp lemen ta t ions are assigned to a compos i t e

ioo Chapter 4 ABAP Workbench Usage

enhancement definition. Enhancement definitions and implementations are dis-cussed in detail in Chapter 18. Enhancements and Modifications.

You can filter the display of the enhancements within the Enhancement Informa-tion System. You have the option to display the composite enhancement, or enhancement spot, enhancement implementation, or composite enhancement implementation within the Enhancement Information System (see Figure 4.12).

Object Name . J C<*noleteVie« Enhancements v • Composite Enh Imtf Parents

Descnpti

• RE RE-FX (Fie I " • R E X C lo<«*z<»<x

• RE X C AJ Rent Adust ' • E C I S H M E D i shmo<JEi

3 El I S H V € D MAIN Upgrete of v • E C I S « ^ E D BO BOSK Data

0 E tSHMED CASE i s h m e T m — t D E C tSHMED BO B.Base items!

f • E C J S H M E D . G t . Pafrrwa/sE f D E C ISHMED S C I S H M E D f Q E C J S H tS-HEnhan-3 E C BADI P R O C U R E M E r B A d l s i n W

f • « 8 V 1 / N E l E M P T E S _ M A f E V f > ' n E S K t' • Composite Enh i r p l Wo F I Q E r i i I m d e n w * W/oP«ren

Soot Cwnoosite Parents " S O C O N D

O S D REBATES Enhancermr O S D _ C O N D LOAD MV.ESfCctOW O C A C S C O N D VERSJCSpotforBA

^ •»• S C BAC* PROCUREMEf " S C BAD! M M SRV

O S C BAO< MM SRV M M SRV • «C*SC BAOI M M PUR

• « ? R E , R ^ ( F l e

Enhancement

Enhancement Implementation

Composite Enhancement Implementation

Enhancement Spot

Composite Enhancement Spot

Composite Enhancement Implementation

Enhancement Spot Implementation

Composite Enhancement Definition Enhancement Spot Definition

F igure 4.12 E n h a n c e m e n t In fo rma t ion Sys tem Navigat ion Screen

The enhancement spot definition can be displayed in the ABAP Workbench tool area by double-clicking on the enhancement spot definition in the navigation area. Figure 4.13 displays the Enhancement Spot definition screen in the tool area. Similarly, you can display the Enhancement Implementation screen in the tool area of the ABAP Workbench by double-clicking on the enhancement spot implementation (see Figure 4.14).

Key Concepts Refresher Chapter 4 97

E r t a r c w r w f S{M SD_COND_LOAO_KVA

A M a t o s , Erftancwn trpk<T»a«B<xn , TechnctlOeUils Erfi Spot Etoncrt Dotations

* C M

^ L a> t JBA4C*»<»oni ~ * S 0 COND LOAD MVA

© lrt>l««riift«DOfr»

BAdCWnoco S0_C0Nt>_L0AD_KVA • • KKfi q ^ Dostnptwi SO_CCND.LOAD.MVA C€»l Lc^r>g MuBpt^V«u» AtrCu^t

SD < lf_Ei«LS&_CQSO_LOAI>_rVA Mgr«Md t-om ctesuc BAiJ SO.CONDJLOAD JfVA UMblty

fotanco Crotoon Mode

FofcocVOess

trpt«<r«rttOon E.amf*» Cttssos

Figure 4 1 3 Enhancement Spot Definition Screen

EI.ISHKEO.CASE_REVISION Actvt

Prc**t>»» , H » w y , T « f n K « H X 4 h Enh mc*-iw<tti>:o Efcc-om

L • B A 3 TVVTMTFTLTXRI

*• rS»^CD SHPT MED O t t M f f t t W T O C t K S

nx tonwofv j C a v . m r t m h**»o>««ng Clots

More} o]f .E \ . tSM.SHfT.Pf tCPMED*S6LECT.0ATA O f _EXJSH_SHFT_FfK#>MED-MCC*Y_OATA O F_EX_tSM_SHFT_C«CPMEl>6U.D_T=£E O F_EXJSH_S»*T_P«CFMED-a€CK_DATA O F . E X J S H . S ^ . P f t C f W E D - C l E A M J j P O F_EX_ISH_SHFT.F15CPMED-TREE.rF0

I f EX ISti SMIfT f l t t f f l t t g . M . I S > 1 1 E E . S H I f T J 1 £ E

Shc«i49«<nreoo C o h j R<Mvc<i • Data S « » K 9 o n

" C«v»G*«£on-F , io<»»CWd C ® » on • BuH T f « fix DrtpW* C » » R+vifrCO • Cr*ck R«<*s C » w Ronton • PlCKOiV'} (ft<* CCMMT C » » Ronton - Trantfw r i t imtbcn » « r Tf

Figure 4.14 Enhancement Spot implementation Screen

Packages and their Attr ibutes

Prior to Release 4.6C all ABAP deve lopment objects were assigned to develop-

ment classes that were used to g roup related deve lopment objects. Packages

were assigned to the appl icat ion components . There can be mu l t i p l e packages fo r

ioo Chapter 4 ABAP Workbench Usage

an applicat ion c o m p o n e n t . As of Release 4.6C and beyond , all ABAP develop-m e n t objects are to be assigned to the package. Packages are conta iners for the d e v e l o p m e n t objects wi th in the t ranspor t layer that al low the objects to be trans-por ted . You can create o r edit packages in the Package Builder in t he Reposi to iy Browser . You can display all of the objects assigned to the package in the Repos-i toiy Browser by selecting a package for the object list type. The SAP system has a p rede f ined package. STMP, to which all of the local d e v e l o p m e n t objects a re assigned. Local objects assigned to the STMP package cannot be t r anspor ted . Non-t ranspor tab le package names start wi th $.

The Package Builder can also be accessed via Transact ion SE21 o r SPACKAGE. The Package Builder is used to create and assign at t r ibutes to packages.

To create a package for y o u r d e v e l o p m e n t project , y o u can create a main package and the subpackage. specify the package hierarchy, de f ine the package interface, add e l emen t s to the package interface, and then de f ine the use access fo r the package user . You create main packages on ly i f y o u w a n t to create a package hier-archy. Normal ly y o u create a package and specify the package type as NOT A MAIN PACKAGE. YOU create the package f r o m the Reposi to iy Browser (see Figure 4.15).

Package Snort Descnpoon Appkc Component Software Component Transport Layer Package Type

• K •

Figure 4.15 Create Package Screen

You specify the package name , shor t descr ipt ion, applicat ion c o m p o n e n t , soft-w a r e c o m p o n e n t , t ranspor t layer, and package type and then click on the CREATE PACKAGE icon. Cus tomer package names should start wi th the let ter I o r Y. The so f tware c o m p o n e n t for a cus tomer package is a lways HOME. The t ranspor t layer de t e rmines if the object assigned to the package is local o r t ranspor tab le . Nor-mally y o u car iy out all of y o u r deve lopmen t activity in the deve lopmen t sys tem and then move y o u r objects to the quali ty assurance system and the p roduc t ion sys tem. Your system adminis t ra t ion team will set up a t ranspor t layer for y o u r d e v e l o p m e n t sys tem for which the t ranspor t r ou t e is de f ined to move the objec t

Key Concepts Refresher Chapter 4 99

f r o m one sys tem to ano the r . Based on the t ranspor t layer, the objects ass igned to the package are m o v e d to the d i f f e ren t systems de f ined in t he t ranspor t rou te for the t ranspor t layer.

You can specify the package proper t ies , use access, interface, and package hier-archy in the Package Builder screen in change m o d e . However , y o u are no t requ i red to specify the package in terface o r use access unless y o u w a n t to pro tec t the object assigned to the package f r o m being used arbitrari ly by o the r packages. Figure 4 . 1 6 displays the Package Builder screen w h e r e y o u can specify the pack-age a t t r ibutes .

P*kafle ZS0001 Sar*d

Properties I use access , Package interfaces • Packages inc»*>e<J , Packagj Herarcny

Short Oescnpewi Custom SO App*ca»ori Oewiopmsrt Pagkag* Person r»sp<x»siNe BCUSER Created By 6C0SER Created co 05 /12 /2009 Lmt changed by BCUSER Changed On 05 /12 /2009 Apple Component SO Sales and Oitnbueci Package Propertes

Summing package AJcwved object M»es No restneoons *

Transport Am Botes Transport lay»r ZFIC Transport layer ZFLC Software Componett HOME

F i g u r e 416 Package Builder Screen for Package Attributes

Packages have a t t r ibutes such as nest ing, package interfaces, visibility, and use access.

• Nest ing al lows y o u to e m b e d packages in o the r packages, thus a l lowing y o u to split larger un i t s o f r epos i to iy objects a n d s t ruc ture t h e m in a h ierarchy.

• Visibility is a p rope r ty of the package e l emen t . Elements wi thin the package are visible to all o the r e l emen t s wi th in the same package and are a lways invis-ible to the e l emen t s outs ide of t he subpackage.

• E lements wi th in a package can be m a d e visible ou t s ide the package by def in-ing a package interface.

• Use access is t he right of o n e package to use the visible e l emen t s of the o the r package interface.

i oo Chapter 4 ABAP Workbench Usage

Packages use interfaces and visibility to make their elements visible to other packages. All visible elements of a package can be used by the other package. Use access restricts the use of the visible elements of the package. The visible ele-ments of the provider package can only be used by the package if the use access of the interface has been created in the package (sec Figure 4.17).

OfcjectName " O ABA AP

" CJ PdCkdQO WOftdCOS _A8A_AP_DEFAU.T

ABA AP_FLTER Filter-Merle ABA AP VKTUAL DEFAl Virtual D*tg

" U Embedded Packaoes CJ ABA TOCtS Cross-Ape* (• CJ Dictionary Onsets P cJ Programs

CJ Furc&on Grocps t- CJ Transactions

P CJ AP AKH fcCHtu Ap. P CJAP'SJCF P CJBDT DC t> OBON& P CJBPF t- CJBRF EXAMPLES t> tJBSV P • BSV.GUO P CJBTFW P CJBTFW U P CJBUCC" t> CJBUPA t- CJBUPA BP P CJBUPA BKU t> CJBUPAlCLEARWG P CJBUPA DIALOG

Package

Package Interface

Embedded Package

Figure 4.17 Package S t ruc tu re in O b j e c t Naviga tor of ABAP W o r k b e n c h

Package interface and visibility are useful i fyou want to make an element of your subpackage visible to the higher-level package or main package.

The system checks that your package complies to the above rules based on the entry in the table PAKPARAM. The package check is switched off by default in the customer system. The entry GLOBAl_SWITCH for the key field NAME in the table PAKPARAM controls the behavior of the package check. By default, the G10BAL_ SWITCH key is set to OFF in the table PARPARAM. To switch on package check, set the GLOBAL_SWITCH key to RESTRICTED or R3ENTERPRISE.

Table 4.1 displays the values for GLOBAl_SWITCH and their effects on package check.

Key Concepts Refresher Chapter 4 101

V a l u e Behav ior

RESTRICTED The package check is only performed if you have selected the PACKAGE CHECK as client or PACKAGE CHECK as SERVER ATTRIBUTE in the package.

R3ENTERPRISE The same checks that are performed for entry RESTRICTED are per-formed here. With objects belonging to structure packages, an additional check is performed to determine whether use access has been defined between them.

Note that in this case an additional entry has to be made in the table PAKPARAM with the key field NAME equal to SAP_OEV_SYSTEM a n d V A L U E s e t t o X .

OFF Switches off package check.

Table 4.1 Valid Values for Package Check

Transport Organizer

The Change and Transpor t System (CTS) provides y o u wi th a tool to organize y o u r ABAP W o r k b e n c h , cross-client cus tomizat ion, and cus tomiza t ion work and then t ranspor t the changes th rough y o u r system landscape. The CTS records all o f t he changes in the change request . The change reques t is also re fer red to as the t ranspor t reques t . You can release y o u r task and the change request o n c e y o u have comple ted and tested y o u r deve lopmen t . You have to ensu re tha t y o u r d e v e l o p m e n t object is syntactically correct and active be fo re y o u release the change reques t . The change reques t is then used to t ranspor t the changes to o the r sys tems o r clients based o n the t ranspor t route .

Reposi tory objects and cross-client cus tomizat ions are ass igned to a w o r k b e n c h reques t , whe rea s t he client-specific cus tomiza t ion objects are assigned to a Cus-tomizing reques t . Each change request can have o n e o r mul t ip le tasks, and the repos i to iy objects o r the cus tomizat ion objects a re assigned to o n e of these tasks. The task is assigned to a user, and only the o w n e r of the task can record his changes to the task.

There a re two types of w o r k b e n c h tasks: deve lopmen t / co r rec t ion and repair tasks. The repos i tory object changes are recorded in t he deve lopmen t / co r rec t ion task if the cu r ren t system is the original sys tem of t he object . The objec t is

ioo Chapter 4 ABAP Workbench Usage

recorded in the repair task if the current system is not the original system of the object. All SAP standard object modifications are recorded in the repair task of the workbench request. Figure 4 .18 displays the change request structure. The top level is the change request, and the lower-level number is the task of the change request.

l—GJ M o d i f i a b l e

U E60K9OO7SO BCUSER M a t e r i a l Management Report

I — E6CK900761 BCUSER Development/Correct ion

Figure 4.18 Transport Request Structure

Each repository object is assigned to a package, and the package is assigned to the transport layer. If the route for the transport layer is defined in the Transport Management System, then the object recorded in the transport task is transport-able; otherwise, the task belongs to the local change request.

The system administration team creates the transport layer in the Transport Management System (TMS) to transport the objects in y o u r system landscape. The transport layer is assigned to the development system. The admin team needs to set up a transport route after creating the transport layer.

There are two types of transport routes: Your admin team will set up the consol-idation route for each transport layer and then the delivery route. The develop-ment system is the source system for the consolidation route and the quality assurance system is the target system. You define the delivery route to transport the objects f rom the quality system to the other target system, which can be pro-duction and other training systems. So once the object is imported to the quality sys temyou, need delivery routes to transport the objects f rom the quality system to other systems.

The Transport Organizer is integrated with the Object Navigator or can be accessed via Transaction SE10. You can display the transport request and the associated tasks of the request from the workbench by double-clicking the request in the navigation area of the workbench. The request will be displayed in the tool area, whereby you can display the properties, objects, and documen-tation of the request. The request edi tor displays all of the recorded changes within the request (see Figure 4.19).

Key Concepts Refresher Chapter 4 103

Display request/task E60K900591 ^ A . " . f i o o

foWeto OiTipfQ Text Browser

BMtVE Repository ARepositoryBrower depository information System SJTajBrcwser^ (^Transport Organizer <&Enhancomort irfo System

Services Browser

A imodifiabte requests from user *

Modftabte Requests from User 180488? (180481 _ Workbench request ~ CD Modtoabte

" E60K900591 1804887 v E6CK900592 1804887

i Proaram t> E60K900572 1804887

g * » » ® ® B S k E60K900591

Properties , Cfcjects , Docomentatco

Workbench request

Snort Descnpoon Project

Target System

Source chert Owner

Status Last changed

Annbute

Custom SO report Oevetpment

800 1804887 Modi f i a b l e 12/06/2008 12 37 02

Short Oescnpoon value

Figure 4.19 Request Editor in ABAP Workbench

You can create change requests by creating the repository object. A dialog win-dow appears when you are creating the repository object to allow you to create a new request or assign the object to an existing request. The transport attributes are populated automatically based on the attributes of the repository object. Fig-ure 4.20 displays the initial transport request screen.

Program ZSDRPT001

Request • ce0K»Q.602 I workbench request Short Description BC400 SO Custom Report

• 3 D Own Requests x

Figure 4 20 Transport Request Screen

You can also create the transport request from the transport organizer, but you have to populate the transport attributes on your own. You release all of the tasks within the change request and then the change request itself to transport the objects through your system landscape. The system administrator imports the objects to the target system. You can display the transport log by selecting the transport log menu option.

ioo Chapter 4 ABAP Workbench Usage

The Transpor t Organizer tools are integrated wi th the Transpor t Organizer . They are a set of p rograms that help y o u work wi th the Transpor t Organizer . You can start the tool f rom the initial screen of the Transpor t Organizer via the m e n u path G O T O • TRANSPORT ORGANIZER TOOLS ( s e e F i g u r e 4 . 2 1 ) .

Transport Organizer Tools & OD

u Transport Organizer Tools ~ • Otxects in Requests

00 Search lor Objects in Requests/Tasks <5. Anatyze Objects in Requests/I"asks w Include Obiects in a Transport Request

' • Objects B Modification Browser & Objects in Customer Namespace S Namespace Information System <$r Display/Change Maintenance Objects cb Display Repaired Objects

^ • Object Directory ? Change Object Directory Entries 0 Change Object Directory Entnes of Objects in a Request ft) Change Person Responsible for Objects

- C3 Requestsflasks M Find Requests

Merge Object Lists <$> Cancel Relocation Transport

Figure 4-21 Transport Organizer Tools

The tools can be used to search fo r objects in t r anspor t requests o r include objects in t he t ranspor t requests . You can search the reques t o r task based on dif-ferent search criteria. Similarly, y o u can display all of the modif ica t ions in the cus tomer sys tem using the modif ica t ion b rowser .

% Pract ice Q u e s t i o n s

The practice ques t ions be low will he lp y o u evaluate y o u r unde r s t and ing of the topic. The ques t ions s h o w n are s imilar in na tu re to those f o u n d on the certifica-t ion examina t ion , bu t whe rea s n o n e of these ques t ions will be f o u n d on the exam itself, they al low y o u to rev iew y o u r knowledge of the subject . Select the correct answers a n d then check the comple teness of y o u r a n s w e r s in t he follow-ing solut ion section. R e m e m b e r that y o u mus t select all correct answers and only correct answers to receive credi t for the ques t ion .

Practice Questions Chapter 4

1. The Object Navigator incorpora tes a total of 10 b rowsers .

• A. True

• B. False

2 . The Reposi to iy Browser is s tar ted by defaul t w h e n y o u execute Transact ion SE80 for the Object Navigator .

• A. True

• B. False

3. You can list a m a x i m u m of six b rowse r s in the Object Navigator .

• A. True

• B. False

4 . You can mainta in SAPscript f o r m s and SAP Smart Forms wi th in t he ABAP W o r k b e n c h .

• A. True

• B. False

5. Which of the fol lowing about the Object Navigator a re t rue s t a t ements?

• A. ABAP programs can be displayed and edi ted in the Object Navigator.

• B. Screens can be displayed and edi ted in the Object Navigator.

• C. M e n u s can be displayed a n d ed i ted in the Object Navigator .

• D. You can create BAdI imp lemen ta t ions in the Object Navigator .

• E. You can create cus tomer projec ts (Transaction CMOD) in the Object Nav-igator.

• F. The ABAP Dict ionary can be main ta ined in the Object Navigator .

6 . The Reposi to iy In fo rmat ion System is a useful tool to search for cus tomer ex i t s / func t ion exits and BAdls in the SAP sys tem.

• A. True

• B. False

ioo Chapter 4 ABAP Workbench Usage

7. E n h a n c e m e n t def in i t ions and imp lemen ta t ions can be displayed in the E n h a n c e m e n t In fo rmat ion System.

• A. True

• B. False

8. Which of the fol lowing is a t rue s t a t ement? There can be m o r e than o n e cor-rect answer .

• A. All cus tomer repos i tory objects have to be assigned to a package.

• B. Packages use interfaces a n d visibility to m a k e their e l emen t s visible to o the r packages.

• C. The t ranspor t layer is a m a n d a t o r y inpu t field fo r the package.

• D. A package can be nes ted .

9. The so f tware c o m p o n e n t for a cus tomer package can be

• A. HOME

• B. Any SAP so f tware c o m p o n e n t (i.e., SAP_APPL, SAP_8ASIS, SAP_HR, etc.).

10. Which of the fo l lowing is a t rue s t a t ement? There can be m o r e than o n e cor-rect answer .

• A. All t ranspor tab le objects have to be assigned to a package.

• B. Local repos i tory objects can be t r anspor ted .

• C. Repository objects and cross-client cus tomizat ion objects are assigned to the w o r k b e n c h request .

• D. Client-specific cus tomizat ion objects a re assigned to t he cus tomizing request .

• E. Inactive objects can be t ranspor ted .

11. Which of the fol lowing is t rue? There can be m o r e than o n e correct answer .

• A. The repos i tory objects and cross-client cus tomiza t ion objects a re recorded in a task be long ing to a local change reques t if the re is no consoli-dat ion rou te leading f r o m the cu r ren t system de f ined in the Transpor t Man-agemen t System for the t ranspor t layer.

Practice Question Answers and Explanations Chapter 4

• B. The reposi tory objects and the cross-client cus tomizat ion a rc recorded in a task be longing to the t ranspor tab le reques t if the consol idat ion rou te is de f ined in the Transpor t M a n a g e m e n t System.

12. There a re vers ions o f the ABAP Editor.

• A. 3

• B. 4

• C. 2

Practice Question Answers and Explanations

1. Correct answer : B

The Object Navigator has a total o f n ine browsers , and in earlier releases it

was less than nine. The fol lowing are the objec t b rowsers available in t he

ABAP W o r k b e n c h :

»• Reposi tory Browser

• Reposi tory In format ion System

• Transpor t Organizer

• M I M E Reposi tory

• Tag Browser

• Test Reposi to iy

Enterpr ise Service Browser

• W e b Dynpro Text Browser

• Enhancemen t In fo rmat ion System

2 . Correct answer : A

The Reposi tory Browser is the defaul t b r o w s e r for t he ABAP W o r k b e n c h .

3. Correct answer : B

You can display up to eight b rowse r s in the ABAP w o r k b e n c h

4 . Correct answer : B

You cannot mainta in SAPscript fo rms o r SAP Smart Forms in the ABAP Work-

bench .

ioo Chapter 4 ABAP Workbench Usage

5. Correct answer : A

You can search for e n h a n c e m e n t s including Business Add- lns and cus tomer exits wi th the Reposi to iy In format ion System.

6. Correct answers : A, B, C. F

You can edit o r display ABAP programs in the ABAP W o r k b e n c h in the ABAP Editor. You can display or edit screens wi th in the ABAP w o r k b e n c h in the screen painter . You can display and edit m e n u s wi th in t he ABAP w o r k b e n c h in the M e n u Painter . The BAdI imp lemen ta t ion tool is no t in tegra ted wi th in the Object Navigator, so it 's no t possible to create BAdI imp lemen ta t ions in the Object Navigator . The cus tomer project (CMOD) is not integrated wi th in the ABAP W o r k b e n c h , so it 's no t possible to create cus tomer projec ts wi th the ABAP W o r k b e n c h . The ABAP Dict ionaiy is integrated wi th in t he ABAP W o r k b e n c h , so it can be main ta ined in ABAP W o r k b e n c h .

7. Correct answer : A

Enhancemen t def in i t ions and imp lemen ta t ions can be displayed in the E n h a n c e m e n t In format ion System.

8. Correct answers : B, D

You can create a local object , bu t y o u have to assign the objec t to a package if y o u w a n t to t ranspor t t he object f rom o n e sys tem to o the r . A package has to de f ine a package in terface and visibility to make its e l emen t s visible to o the r packages. The t ranspor t layer is not a m a n d a t o r y input field for the package. The t ranspor t layer is assigned to the package if it is de f ined for the system. A package can be nes ted .

9. Correct answer : A

The so f tware c o m p o n e n t of the cus tomer package should a lways be HOME.

10. Correct answers : A, C, D

The reposi tory objec t has to be assigned to the package to t ranspor t the object to a n o t h e r sys tem wi th in the sys tem landscape. You canno t t ranspor t a local r epos i to iy object . Reposi to iy objects and cross-client cus tomizat ion objects a re assigned to a w o r k b e n c h reques t . Client-specific cus tomizat ion objects arc ass igned to the cus tomizat ion request and arc not ass igned to the package. Inactive objects can be t r anspor ted .

11. Correct answers : A. B

A local change request is created if the consol idat ion rou te is no t de f ined ; o therwise , a t ranspor tab le change reques t is created if the consol idat ion rou te for the t ranspor t layer is de f ined .

Take Away Chapter 95

12. Correct answer : C

There a re th ree m o d e s of ABAP Editor: the n e w Front-End Editor, the old Front-End Editor, and the Back-End Editor.

Take Away

You should n o w unde r s t and the ABAP W o r k b e n c h features and be able to navi-gate wi thin it. You should be able to use the available b rowsers wi th in the ABAP W o r k b e n c h and comple te y o u r d e v e l o p m e n t in an eff icient m a n n e r . You should k n o w h o w to conf igure the ABAP w o r k b e n c h and the var ious d e v e l o p m e n t tools.

To be a successful deve loper y o u should k n o w a b o u t all the available develop-m e n t tools a n d their uses. It is impor t an t to unde r s t and the features of the n e w ABAP Editor because it will be ve iy helpful for y o u r appl icat ion d e v e l o p m e n t and will increase the product iv i ty of y o u r d e v e l o p m e n t team.

Finally, y o u should unde r s t and the package concept and the use of the Transpor t Organizer . You should unde r s t and the concep t of the t ranspor t reques t and t he d i f fe ren t types o f t ranspor t reques t a n d its use for the migrat ion of d e v e l o p m e n t objects f r o m the d e v e l o p m e n t e n v i r o n m e n t to the p roduc t ion e n v i r o n m e n t .

Refresher

Table 4 .2 s h o w s key concep ts abou t the ABAP W o r k b e n c h .

Key Concept Definition

ABAP Workbench The ABAP Workbench is an integrated development environment for the ABAP developer.

Repository Browser The Repository Browser is a tool within the Object Navigator and is used by the developer to access the repository objects and workbench tools to create repository objects.

Repository Information The Repository Information System Browser is a System search tool to search for repository objects.

Table 4-2 Key Concept Refresher

ioo Chapter 4 ABAP Workbench Usage

Key Concept Definition

Enhancement Information The Enhancement Information System is a tool to System search for Enhancement definitions and implementa-

tions in the SAP system.

Transport Organizer The Transport Organizer is a tool to work with the change request and the objects within the change request. Using this tool, you can view the objects assigned to the change request and the transport log of the request.

Table 4.2 Key Concept Refresher (cont.)

Summary

In this chap te r w e have covered the ABAP W o r k b e n c h and its use in detail . W e have covered s o m e of the mos t c o m m o n l y used b rowsers such as the Reposi to iy Browser , Reposi tory In fo rmat ion System. E n h a n c e m e n t In fo rmat ion System, and Transpor t Organizer . Fur the rmore , w e have covered in detail the ABAP W o r k b e n c h , the n e w ABAP Editor, and the concep ts of package and t ranspor t reques t . This knowledge will a l low y o u to easily pass this topic on t he certifica-t ion examina t ion .

ABAP Debugger Program Usage

Techniques You'll Master:

• Examine the r u n t i m e behavior of ABAP programs using the ABAP Debugger

• Use the ABAP Debugger to systematically test ABAP p rog rams

• Plan correc tness of y o u r ABAP programs

• Use watchpoin ts , breakpoints , asser t ions, a n d checkpoin t g roups effect ively

• Unders tand the design d i f fe rences b e t w e e n the two vers ions of the Debugger

112 Chapter 5 ABAP Debugger Program Usage

A debugger is typically a m a j o r c o m p o n e n t of every d e v e l o p m e n t e n v i r o n m e n t . Dur ing the d e v e l o p m e n t of applicat ions, e i ther s imple o r complex , the Debugger is a valuable tool in de tec t ing and analyzing e r ro r s i tuat ions. You need to be famil iar wi th the funct ional scope of the ABAP Debugger , and this chap te r covers t he mos t impor t an t concepts of this very useful tool. It is a tool used du r ing deve lopmen t , dur ing testing, and w h e n a t t empt ing to analyze p rob lems in the p roduc t ion sys tem.

W e will cover the p r imary d i f fe rences b e t w e e n the old "classic" Debugger that has existed since SAP R/3 and the n e w Debugger , first available in a l imited fo rm in version 6 .40 and then comple te ly in SAP Ne tWeaver 7 .0 . W e will also cover a n u m b e r of the tools available in the n e w Debugger and the user interface. Also covered will be cus tomizing the Debugger to meet y o u r needs and prefe rences , assert ions, wa tchpo in t s . and breakpoin ts . Each of these topics will be covered separately and will be fo l lowed by the practice exercise a n d the solut ion to the exercise.

Real-World Scenario

A repor t current ly in use in p roduc t ion docs not p r o d u c e correct results. This p rogram was deve loped by a p r o g r a m m e r w h o is no longer wi th the company , and the re is n o documen ta t i on .

Somet imes an e r ro r message is p r o d u c e d in p roduc t ion that cannot be r ep roduced in any of the o the r systems in the landscape, and no o n e is su re wha t is causing the message. You have been told to ident i fy w h y the mes-sage is being p roduced and to correct the repor t .

Af ter examin ing the p rogram in the ABAP Editor, y o u are still unab le to d e t e r m i n e the cause of t he p rob lem. The repor t does a n u m b e r o f dynamic calls based o n values read f r o m database tables and p e r f o r m s s o m e rout ines based o n the user ' s au thor iza t ion checks.

The solut ion to quickly ident i fy wha t the p rogram is do ing is to use the ABAP Debugger in the p roduc t ion sys tem. To ident i fy w h e r e the e r ro r mes-sage is being p roduced , y o u create b reakpo in t s on the s t a tement MESSAGE. Once the message s t a tement that is p roduc ing the u n k n o w n e r ro r is iden-tified, t he cause of the e r ro r can be easily deduced . It is also possible to examine variables to d e t e r m i n e the actual flow of the p rogram and then ident i fy w h y the results are incorrect .

Objectives of this Portion of the Test Chapter 5

Objectives of this Portion of the Test

The p u r p o s e of this por t ion of the cert if ication examina t ion is to verify that y o u have detai led knowledge of the ABAP Debugger , which is a m a j o r c o m p o n e n t of the e n v i r o n m e n t . By ver i fying that y o u have the appropr ia t e knowledge to use the Debugger efficiently, y o u will b e c o m e a m o r e effect ive and eff icient pro-g r a m m e r .

This por t ion o f the examina t ion will test y o u r knowledge of the Debugger . The po in t s that y o u need to unde r s t and f r o m this section include:

• Various ways to start the Debugger

• Breakpoints

• Watchpo in t s

• Asser t ions

• Viewing and modi fy ing data objects

• Unders tand ing the archi tec ture of the Debugger

Key Concepts Refresher

The ABAP Debugger is part of the ABAP W o r k b e n c h that y o u use e i ther as an integrated test ing tool o r to ident i fy issues wi th code execut ion . The Debugger al lows y o u to execute ABAP programs, by line o r by sect ion. With this tool, y o u can display data objects and check the f low logic of p rograms . The r u n n i n g pro-gram is in t e r rup ted af ter each step, a l lowing y o u to check its processing logic and the results of individual s ta tements .

You typically use the Debugger as a way of ident i fy ing er rors in ABAP programs . It conta ins the fo l lowing funct ions :

• Different ways o f s tar t ing the Debugger

• Different v iews of con ten t s of data objects

• Dif ferent execut ion op t ions

• Displaying source code in the Debugger

• Setting and delet ing breakpoin t s

• Sett ing and dele t ing wa tchpo in t s

• Setting and dele t ing database locks

• Stopping code execut ion at a part icular s t a t emen t o r event

100 Chapter 5 ABAP Debugger Program Usage

• Displaying and changing field con ten t s at r u n t i m e

• Displaying objects and references

• Displaying and posi t ioning str ings

• O p e n i n g the code in t he ABAP Editor o r Objec t Navigator

New and Classic Debugger

Current ly, y o u have access to two vers ions of the ABAP Debugger . The o lde r ver-sion ( commonly called the classic Debugger) , which has existed since the begin-ning of SAP R/3, has always had the major i ty o f the func t ions listed above . As the language has evolved, the Debugger has also evolved, for example , the inclu-sion of objects in bo th ABAP and the Debugger . Figure 5.1 shows the f low con-trol area, and Figure 5.2 shows the variable display area of the classic Debugger .

ABAP Debugger

B E S S

F**ds Table | Breakpoints wa*K>oints | C a H [ overview Sen* f ls |

M» n Program Z.TEST _PR0C-RM1 < • N Source code or z test proc-pan - *> H O I

Figure 5-1 Standard Flow Control of the Classic Debugger

JJ] Field names 1 - 4 0 0 Field contents t)v_str 1 2 ljv_vari 12

sr-sue«c 0 SV.TA8U 1 ST-D8CMT 0 Sr-OYMHR 1000

Figure 5 2 Variable Display of the Classic Debugger

The original Debugger has always had certain l imitat ions: The layout is most ly fixed, and there w e r e restr ict ions on the a m o u n t of data that could be displayed at one t ime. For example , a m a x i m u m of eight data objects could be displayed, and of those, only four at a t ime. Only o n e internal table could be displayed, and table scrolling, especially horizontal ly, was o f t en tedious . Wher ea s it is possible to r eo rde r co lumns , knowledge of the fields of the internal table was necessary to comple te it. O t h e r areas also requi red detailed knowledge of the executing code. There is no way, f r o m wi th in the Debugger , to look up wi th in the reposi-to ry a func t ion modu le , me thod , o r sub rou t ine n a m e to set a b reakpo in t .

Key Concepts Refresher Chapter 4 5

This Debugger shared the same external m o d e roll area of the code being debugged . This external m o d e co r re sponds to the session w i n d o w in which y o u are r u n n i n g the code. This restr icted the a m o u n t of interact ion the Debugger had wi th t he repos i to iy o r the system as a w h o l e wi thou t impact ing t he code being debugged . Each of the Debugger ' s act ions could inf luence the p rogram f low of the applicat ion and was limited as a result .

Also with the classic Debugger, it is generally not possible to analyze programs in debugging m o d e that run in an ABAP processor unit and are called recursively f rom a subordinate unit . For example, a conversion exit cannot be analyzed using this Debugger if it runs within a WRITE s ta tement . A conversion exit executes wheneve r is sent to the presentat ion or retrieved f rom the presentat ion layer. If called f rom a WRITE sta tement , the Debugger is called recursively f rom within itself.

Starting wi th SAP Ne tWeaver 6 .40, SAP released a n e w vers ion of the Debugger . The Debugger available in Release 6 .40 was no t cons idered comple t e (and was not the defaul t debugger as a result); it did e l iminate the above restr ict ions.

The reason for this is that the n e w Debugger executes in its o w n external m o d e . This al lows t he code to be analyzed to r u n wi th virtually no impact f r o m the Debugger . This separat ion of funct ional i ty a l lows for much grea ter interact ion wi th the system, a l lowing search he lp use, the display of m o r e than one internal table s imul taneously , and an unl imi ted n u m b e r of data objects .

The Debugger specified as the defaul t s tarts w h e n needed . You can change the default , in e i ther the ABAP Editor (Transaction SE38) o r the Object Navigator (Transaction SE80), by fol lowing the m e n u path UTILITIES • SETTINGS • ABAP EDI-TOR • DEBUGGING. Figure 5 .3 a n d Figure 5.4 s h o w the m e n u and resul t ing dialog box. Both Debuggers a re s tar ted in exactly the same way.

Ero9'*n £dn fiooo WIIMS Entfronmer* Syswm H * p

© Seftoos .

DrtpUrQbfcMjtt CW»SM1»F5 WOlMlil A B A P Editor: Di

Seftoos .

DrtpUrQbfcMjtt CW»SM1»F5 WOlMlil

H E ft «8 ® OipltY N w a « « l Wn«r»< C»t>ShN*F4 H E ft «8 ® Update Navvjatton Index BetpOn... Ctrt«F8 Breakpoints E"iem»l Breakpoint* BlacMBufler More UtllMS

Q'WIME Repotfcy Update Navvjatton Index BetpOn... Ctrt«F8 Breakpoints E"iem»l Breakpoint* BlacMBufler More UtllMS

0°0fi«CO'.*«y Biow.«<

Update Navvjatton Index BetpOn... Ctrt«F8 Breakpoints E"iem»l Breakpoint* BlacMBufler More UtllMS

^R i^o iWy Ir/OfinWA Syifil

Update Navvjatton Index BetpOn... Ctrt«F8 Breakpoints E"iem»l Breakpoint* BlacMBufler More UtllMS

0Teg8ro-t««

Update Navvjatton Index BetpOn... Ctrt«F8 Breakpoints E"iem»l Breakpoint* BlacMBufler More UtllMS @)Tiar>:pc>t 0>>yc«

Update Navvjatton Index BetpOn... Ctrt«F8 Breakpoints E"iem»l Breakpoint* BlacMBufler More UtllMS

QTetfReporfor/ Wier*UseflUs» Ct1*8Mt*F3 V«18I0«»* •

Figure 5.3 Menu Path To Set the Default Debugger

102 Chapter 5 ABAP Debugger Program Usage

K g U M f - S p M H k Sennflt

WpcMxfKh (Oanarat) Class BuMer Screen Paw

PrePr Printer SaOTscraan ^ E T T f f f f l f f l P a l m « >

Eawnai Debjgging

Users BCUSCR

• «» Matching

A & A P D e b i i - j j e i

O Classic Debugger

®NtwOet« jgget

Figure 5 .4 Dialog t o Set t h e Defaul t D e b u g g e r

N o t e

Primary m e t h o d s of s ta r t ing t h e D e b u g g e r :

1. In t h e naviga t ion a rea , se lec t t h e m e n u pa th Execute N D e b u g g i n g for t h e s e l ec t ed p r o g r a m . This is s h o w n in Figure 5 .5 .

2 . In t h e ed i t i ng a rea , se lec t t h e des i red p r o g r a m line a n d select S e t / D e l e t e

Breakpoin t . Then s tar t t h e p r o g r a m by se lec t ing (Execute) Direct Process ing

o r f~F8l.

3 . Select System • Utili t ies • D e b u g ABAP or System • Utilities • D e b u g Screen .

4 . Enter " / h " in t h e c o m m a n d field in t h e s t a n d a r d t o o l b a r a n d press C*3<>r use a s h o r t c u t t o p rov ide t h e c o m m a n d to t h e sess ion .

Ob)e«t Nam* p e t c n p i o o

^ Uzjis-r S ' T y p t- O F *

Create •

Change

Program Z_Tl

CJE«> P CD 8ut

CJE«> P CD 8ut

£heck •

ftctwa)»

£wtu ia Cyect Processing

In a (Jew Window

Rename !Jn«Test

D e i f * Debugging •

whfiie-usea LHI Background ^

EICW Runlm» Anafrtis

fitiwFuncicrts • II

Figure 5.5 Navigat ion Start of t h e D e b u g g e r

Key Concepts Refresher Chapter 4 103

However , each t ime the n e w Debugger is s tar ted, a n e w m o d e is s tar ted au tomat -ically. You have a m a x i m u m of six external m o d e s available as a default , t hough y o u r sys tem may be conf igured d i f ferent ly . If no f u r t h e r external m o d e is avail-able w h e n the n e w Debugger is s tarted, the message "No addi t ional external m o d e for n e w ABAP debugger available" is displayed, the n e w Debugger start is cancelled, and the classic Debugger is s tar ted in its place. In this case, y o u should close m o d e s that are no longer r equ i red .

In the n e w Debugger , control can be passed f r o m the applicat ion to the n e w Debugger at any t ime using the func t ion code /h , even if the Debugger was already s tar ted.

You can exit the n e w Debugger wi th o n e o f several me thods :

• If the Debugger is ready for input (active) and the applicat ion is wait ing, y o u can select DEBUGGER • EXIT DEBUGGER, which closes j u s t the Debugger , and the applicat ion con t inues to run .

• Y o u c a n s e l e c t DEBUGGER • EXIT APPLICATION AND DEBUGGER, w h i c h c l o s e s

both the Debugger and the appl icat ion.

• The third op t ion is if the applicat ion is ready for input and the Debugger is wait ing, in which case y o u can e n t e r " /hx" in the c o m m a n d field and press I I. which closes j u s t the Debugger and allows t he applicat ion to con t inue to run .

It is possible to switch b e t w e e n the classic Debugger a n d the n e w Debugger by s e l e c t i n g DEBUGGER • SWITCH TO N E W A B A P DEBUGGER o r DEBUGGER • SWITCH TO

CLASSIC ABAP DEBUGGER. YOU must be aware , h o w e v e r , if y o u switch f r o m the n e w Debugger to t he classic Debugger w h e n the ABAP code is called f r o m the kernel of t he applicat ion server (primari ly convers ion and field exits), that the r u n t i m e e r r o r RPERF_I LLEGAL_STATEMENT will be tr iggered as a result of the recursive call.

You will find the func t ions for analyzing source code similar b e t w e e n vers ions of t he Debugger . It is possible to navigate f r o m the variable overv iew to the detailed v iew of the data object s imply by double-cl icking. The d i f fe rence wi th the n e w Debugger is s imply that y o u can process an unl imi ted n u m b e r o f data objects s imul taneously , and the n u m b e r visible at a single t ime d e p e n d s on the size o f the w i n d o w and t he fon t size. You also need to double-click o n t he CHANGE icon ( the pencil icon) to o p e n u p the data object for change and then press 1 *-* | to con f i rm the change, unl ike the classic Debugger , w h e r e t he field

104 Chapter 5 ABAP Debugger Program Usage

was always o p e n and y o u needed to click on the CHANGE icon to accept the change.

N e w D e b u g g e r T o o l s a n d Ul

As soon as y o u start the n e w Debugger , using o n e o f the m e t h o d s s h o w n in t he prev ious no te ( f rom a m e n u , wi th a breakpoin t , o r the c o m m a n d 7 h " ) , y o u will see the message "Session "x" connec ted to Debugger" in the status l ine of the applicat ion, "x" is the n u m b e r of the cur ren t external m o d e . W h e n the Debugger starts, y o u will see the w i n d o w title (x) - ABAP DEBUGGER CONTROLS SESSION x (EXCLUSIVE), w h e r e again "x" is the external m o d e of t he appl icat ion. This pro-vides a visible link b e t w e e n applicat ion and Debugger m o d e at all t imes. If it is not possible to achieve an exclusive mode , the title will be (x) - ABAP DEBUGGER C O N T R O L S S E S S I O N x ( N O T E X C L U S I V E ) .

If the Debugger obta ins an exclusive m o d e , it means that t he application to be analyzed exclusively occupies a w o r k process o f the applicat ion server du r ing debugging . If all exclusive d e b u g work processes are occupied, the Debugger is swi tched to non-exclusive m o d e . In this state, y o u can a t t empt to occupy a work p r o c e s s e x c l u s i v e l y b y s e l e c t i n g D E B U G G E R • E X C L U S I V E D E B U G G I N G M O D E O N

( shown in Figure 5.6). However , this is only possible if a n o t h e r exclusive debug work process has b e c o m e available in the m e a n t i m e .

& !

J J :

E

Debugger =drt goto Breakpoints Se

Single Step F5

Exeiute F6 "

Return F7 '

CfinSnue F8

Confrnue to Cursor Shift»F8

Solo statement Shirt«F12 '

Debugger Session

Exclusive Debugging Mode On

Sv*Hch lo Classic Debugger E»i debugger Exit Application and Debugger

Figure 5.6 Menu to Turn Exclusive Mode On

Key Concepts Refresher Chapter 4 105

T i p

The difference b e t w e e n exclusive and non-exclusive m o d e s is tha t you will find t he Debugger funct ion limited in non-exclusive m o d e . The limitations a re mostly d u e t o t he fact tha t a roll-out is forced in t he applicat ion af ter each Debugger view while in non-exclusive m o d e . Therefore, a da tabase commit must b e exe-cu ted . This has t he following consequences :

• It is no t possible for you to d e b u g b e t w e e n t he s t a t emen t s SELECT and END SELECT because t he da tabase cursor needs to be closed using a commi t . In this case, program execut ion is t e rmina ted .

• Debugging m o d e is no t possible for conversion or field exits.

• Owing t o t h e commit , inconsistent da tase t s can occur in t he da tabase .

Because inconsistent da tase t s in the da tabase are possible, t he non-exclusive

m o d e is impossible in product ive systems. If t he n u m b e r of exclusive debugging

work processes is occupied, t he runt ime error OEBUGGING_NOT_POSSIBLE is trig-

gered wheneve r you a t t e m p t to start ano the r Debugger .

The n u m b e r of work processes tha t a re available exclusively for debugging is

def ined by t he profile pa ramete r r d i s p / w p d b u g _ m a x _ n o . In d e v e l o p m e n t sys-

tems, this should b e approximately half t he n u m b e r of dialog work processes .

The special requi rements d e m a n d e d of debugging in a product ion client are t he

same for t he n e w and t he classic Debugger . Therefore, they are processed

exactly t he same as in t he classic Debugger .

You wil l find 11 work areas or desktops when the new Debugger starts. This is

an increase from the previous version in SAP NetWeaver 6 .40 because not all o f

the tools were complete. You can customize the first three desktops so that they

wil l start w i th the Debugger to satisfy your o w n preferences and eight "pre-

defined" desktops. You can modify each of these desktops at any time.

Each desktop can hold from one to four tools. The tools displayed on a desktop can be the same or different based on your needs at the time. You can change the size or location of any of these tools while in the Debugger. For example, for tools placed horizontally, the right or left tool can be either made wider or nar-rower. You can make tools wi th a vertical alignment longer or shorter. Tools can be swapped vertically, horizontally, or diagonally. You can replace any tool w i th any other by simply clicking on the R E P L A C E button. An individual tool can be maximized to fill the entire desktop. You can undo any layout change wi th the B A C K button (or (73)) .

120 Chapter 5 ABAP Debugger Program Usage

At this time you can create 15 tools. The tools are grouped into three categories: S T A N D A R D T O O L S , D A T A O B J E C T S , and S P E C I A L T O O L S (see Figure 5 . 7 ) .

[ & N e w T o o i Ely

<=• CJ Tooi-, " L i Standard Tools

SoorceCode fi Can Stack

< 0 vanatne Fast Display O Breakporti ' • : Sourc* Cod* (Edit Control)

^ CJ Data Objects 9 Obiect [ffl Table auu Structure 0 Single Field

Data Explorer ^ CJ Special Tools

<£ Web DincfO

B Loaded Programs <oiobai Data) S ) Memory Analysis

3 Screen M a l y s n &OITT001

System Areas (Menial)

" J [ « •

Figure 5.7 N e w Tool Dialog

You will see differences between the two source code displays. The S O U R C E C O D E

shows the code as with the "old front-end editor." The S O U R C E C O D E ( E D I T C O N -

TROL) uses the "new front-end editor," which displays additional formatting and provides information regarding data objects when you hover over the name with the mouse.

Table 5.1 shows where the tools can be found in the new Debugger when started before modification; Figure 5.8 and Figure 5.9 show the desktops.

Tool Ini t ial ly F o u n d o n D e s k t o p

Source Code (Not initially f o u n d on a de sk top )

Call Stack D e s k t o p 2 and Standard

Variable Fast Display D e s k t o p 1 and Standard

Breakpoints Break. AA/atch poin ts

Source Code (Edit Control) D e s k t o p 1. D e s k t o p 2, Desk top 3, and Standard

Table 5-1 Debugge r Tools

Key Concepts Refresher Chapter 4 121

Tool Initially Found on D e s k t o p

Objec t Objec t s

Table Tables

Structure Structures

Single Field Detail Displs

Data Explorer Data Explorer

W e b Dynpro Desktop 3

Loaded Programs (Global Data) (Not initially found on a desktop)

Memory Analysis (Not initially found on a desktop)

Screen Analysis (Not initially found on a desktop)

Diff Tool Diff

System Areas (Internal) (Not initially found on a desktop)

Table 5.1 Debugger Tools (cont.)

Desktop 2 Desktop3 Standard Structures Tables

Figure 5.8 First Six Desktops

Objects Detail Displs Data Explorer 8reak/Watchpoints Diff |

Figure 5.9 Last Five Desktops

Most o f the tools also provide additional services. You wi l l always be able to access the tool services by clicking on the S E R V I C E S O F T H E T O O L button as shown in the Figure 5 .10 or through the context menu of the tool.

I

of the Tool %

Seivice:

Figure 5.10 Services of t he Tool

122 Chapter 5 ABAP Debugger Program Usage

The services p rov ided va iy d e p e n d i n g on the tool. For example , the SOURCE CODE tool only al lows y o u to navigate to t he cur ren t ly execut ing l ine o r to open t he edi tor . Mos t p rov ide the ability to save t he con ten ts of the tool to a local file o r to search. The Variable Fast Display provides op t ions for sor t ing the local o r global data objects o r saving the data as test data in Transact ion SE37, whe rea s the internal table services p rov ide the ability to append , insert , o r de le te r o w s in the table. You have the op t ion to change the s equence o f the fields th rough the service o r j u s t drag t h e m as y o u w o u l d in an ALV (the ABAP List Viewer or . as it has been r e n a m e d , the SAP List Viewer is discussed in Chapter 15. ALV Grid Control) o r table control .

All of the tools except the s tandard tools provide a his tory of all objects displayed in the tool, and any pr ior one can be re t r ieved s imply by selecting it f r o m the list.

The table tool has m a n y m o r e capabilit ies than the classic Debugger p rov ided . Whereas y o u could handle s tandard internal tables th rough the use of t he CHANGE, INSERT, APPEND, and DELETE bu t tons be low the table display, keyed tables (sorted or hashed) w e r e m o r e restr icted. With those y o u only had access to the CHANGE and DELETE bu t tons to mod i fy the con ten t s of non-key fields o r to r emove the record . The n e w Debugger of fers m a n y m o r e op t ions (sec Figure 5.11 and Figure 5.12).

Save to Local File

Search £ind Next

fioto Row

Edrt Order of Columns

Original Column Order

Column width Optimized (Without Header)

Qo Not Optimize Column Width

Change Row Content

[nsert Row (Index)

insert Row (K«y)

Qetete Rows

Qeiete Table (FREE)

Layout Changes

Service Menu of the Tool

Figure 5.11 Context Menu of the Table Tool

Key Concepts Refresher Chapter 4 109

| [E-Tat ) i® So ivnes

^ C J S e w e s

^ C J Standard Sim» 10 Local F a *

(}(] search

Q g Find Ne>l

CD T o o t S p e c i f c

L}Q Goto ROW

" G Co lumn CorrV jura lon

0 Edrt Order of C o l u m n s

t f t t Onginai Co lumn Order

# Co lumn Wkjtn OpOmcod (A'thout Header )

Do No» Optimize C o l u m n wid th

^ G Change T a f e Cor tent

0 C h a r g e R c w Content

S insert R w (indeiO

[ 3 Insert R o w (Key) Q Delete R o w s

0 Delete T a t i e ( F R E E )

@I"J

F i g u r e 5.12 T a b l e Se rv i ce M e n u

You have multiple ways of modifying the internal table through either the con-

text menu (right mouse-click while over a row containing data) or the servicc

menu of the tool. The same options exist for a standard internal table, whereas a

hashed internal table does not allow you to insert using an index. I f you use the

INSERT ROW (KEY) option, regardless o f where you attempt to insert the record for

sorted or hashed internal tables, the row wil l be inserted in the correct location.

The dialog presented (shown in Figure 5.13) allows you to copy the contents o f

an existing row to use a template. The new row is indicated without a numerical

line number (there is an icon in its place) until you press the | i key to accept

the row into the internal table.

F i g u r e 5.13 I n s e r t Us ing Key

110 Chapter 5 ABAP Debugger Program Usage

Using SOURCE CODE (EDIT CONTROL) p r o v i d e s severa l a d v a n t a g e s o v e r t h e o l d e r

SOURCE CODE. First, as in t h e n e w e d i t o r , y o u h a v e t h e s a m e flexibility w i t h set-

t ings. You can d e f i n e d i f f e r e n t f o n t s a n d co lors f o r k e y w o r d s , c o m m e n t s , a n d

o t h e r t y p e s o f i t ems . The d i sp l ay a l lows f o r co l laps ib le b locks , w o r d w r a p , a n d

o t h e r visual f e e d b a c k .

F igure 5 . 1 4 s h o w s severa l o f the m o r e i m p o r t a n t f ea tu re s :

• T h e a r r o w h e a d s in t h e top- le f t c o r n e r , as w i t h all too ls , a l lows y o u to res ize

t h e tool to d i f f e r e n t w i d t h s o r he igh t s .

• O n the r ight s ide o f t h e tool , t h e th i rd , f o u r t h , a n d fifth b u t t o n s f r o m t h e t o p

a l l o w y o u to m a x i m i z e t h e tool to fill t h e d e s k t o p , m a x i m i z e t h e tool to u s e

the e n t i r e h e i g h t o f t h e d e s k t o p , a n d m a x i m i z e t h e w i d t h o f t h e tool to t h e

e n t i r e d e s k t o p .

• T h e s ta tus b a r at t h e b o t t o m of t h e tool s h o w s t h e s c o p e o f t h e l ine se lec ted , in th i s case w i t h i n a f u n c t i o n a n d w i t h i n an IF.

• T h e closest s c o p e to the cursor , in th is case , t h e IF k e y w o r d s , a re a lso m a d e

b o l d .

• T h e s t a tus b a r also s h o w s t h e l ine a n d c o l u m n of t h e cursor , a n d double-c l ick-

ing o n th is b o x p r o d u c e s t h e go to l ine d ia log b o x .

• T h e l ine to b e e x e c u t e d is i nd i ca t ed w i t h a y e l l o w a r r o w , a n d h o v e r i n g o v e r

var iab les w i t h t h e m o u s e p r o d u c e s qu ick i n f o r m a t i o n ( tool t ip) s h o w i n g t h e

va r iab le n a m e , value , a n d t ype .

n n . V T S W SET EDITOR HANDLE. 3 [ST

: ; ; V " ; ; a ® n®

I - VALVZdDZTORI Tltl KEF TO CL MB ZDZTOK 00 - f=

I DATA: 30CRCE_INSTANCE TYPE P E r TO CL_IIB_SCCRCE. Q A B A P Z D I T O ? - EDITOR. ^

j EDITOR_C - E D I T H J u x T O A ^ s a x . , IDLE. : ri.snf \ t I tDiTOW -«i)

AXD EDITOR J SIDE -EDITOR C - EDITOR CCWTROL KA.KM.tl

I S I N I T I A L )

CCHTADfEP NEW - EDITOR CCWTRC4. CCWTAIKER1. 0 J « > [ - i - « »:u Scope f'.NOTION S£T_EOITC«_ AW Ui 11 > ' jJ

Figure 5.14 Source Code (Edit Control) Tool

You can n o w ins t ruc t a b r e a k p o i n t to skip a n u m b e r o f o c c u r r e n c e s b e f o r e s top-

p ing . You s i m p l y e n t e r t h e n u m b e r o f sk ips in t h e sk ip c o l u m n (any pos i t i ve

n u m b e r b e t w e e n 0 a n d 4 , 2 9 4 . 9 6 7 . 2 9 6 [232] can b e u s e d ) to p r e v e n t t h e break-

Key Concepts Refresher Chapter 4 5

point f r o m s topping. You can change a b reakpo in t to active o r inactive o r de le te the breakpoin t . In addi t ion , y o u can edit condi t ional and uncondi t iona l check-poin t s using the Breakpoint tool. You first set condi t ional checkpoin ts in the source code using the ASSERT s ta tement ; uncondi t iona l checkpoin ts are set using the BREAK-POINT s ta tement . These have the effect that p rograms will be cont in-ued on ly if a preset condi t ion is fulfi l led. These checkpoin ts can be searched for, activated, o r deact ivated.

As wi th a breakpoin t , wa tchpo in t s are places in the p rogram that ins t ruct the ABAP r u n t i m e processor to in te r rup t the p rogram execut ion at a part icular point . In contras t to b reakpoin t s , however , wa tchpo in t s do not activate debugging m o d e until the con ten t s of a specified field change. You can de f ine wa tchpo in t s only wi th in the Debugger ( shown in Figure 5.15).

• • i Monjor variable during program How

and Hop if the value of the variable changes

Watchpoint

variable

Jy-Program Name 2_TEST_PR06R*n

Only for local Variables

® All Module ir.stncs

O On if Current Module Instance

y No Additional Condition

Con aeon

Free ConWon Endry » 50

• fr ZZ X

Figure 5.15 Creating a Conditional Watchpoint

Watchpoin t s , like breakpoin ts , are user specific and do not affect o the r users run-ning the same p rogram. Unlike the classic Debugger , which has a limit of 10 watchpoin t s , the re is no limit on the n u m b e r o f wa tchpo in t s at o n e t ime in the n e w Debugger . I f y o u set a wa tchpo in t for a field wi thou t specifying a relat ional ope ra to r o r compar i son value, p rogram execut ion con t inues unti l the con ten t s of the field change. If y o u specify a relational ope ra to r a n d compar i son value w h e n y o u de f ine a wa tchpoin t , p rogram execut ion con t inues unti l the specif ied condi t ion is met . You can use wa tchpo in t s to display changes to re ferences of strings, data, o r objects , as well as internal tables.

112 Chapter 5 ABAP Debugger Program Usage

The ABAP Debugger differentiates between the breakpoint variants shown in

Table 5.2.

Type of Breakpo in t Behavior

Static breakpoints Keyword BREAK-POINT inserts a user-

independen t breakpoint as an ABAP s t a t emen t in t h e source text . Related is t he s t a t e m e n t BREAK <user_name>, which sets a u se r -dependen t breakpoint in t he source text .

Directly se t dynamic breakpoints These are se t in t he ABAP Editor or t he Debugger (by ei ther double-clicking before t he line n u m b e r i f y o u are using the o lder source code display or single-clicking before t he line n u m b e r i f y o u are using t he newer source code with edi t control) . Dynamic breakpoints a re always user specific and are de le ted w h e n you log off f rom the SAP system.

Breakpoints for s ta tements , subrout ines , The Debugger interrupts t he program funct ion modules , o r m e t h o d s directly before t he specified s t a t emen t is

execu ted .

Breakpoints for except ions and system The Debugger interrupts t he program except ions directly af ter a run t ime error is raised.

Table 5.2 Types of Breakpoints

Assertions and Breakpoints

Checkpoints define places in a program where the program state can be tested during execution. A B R E A K P O I N T statement represents an unconditional check-point. In this case, the program execution is unconditionally interrupted at this point in the program, and the Debugger is started. Assertions are another form of checkpoint, which y o u use to implement condi-tional checkpoints wi th in your program. An assertion checks whether a defined condition is satisfied. An assertion is defined by an ASSERT statement as a condi-tional checkpoint.

Key Concepts Refresher Chap te r 4 113

Assertions and BREAK-POINT statements are either always active or can be acti-

vated by assigning them to a checkpoint group (shown in Figure 5.16).

Checkpoint Oroup 2nv_CH£CKP0INl

Descnpcon [ty c h e c k p o i n t group

Personal Actuation

Breakpoints Assertions (Foreground)

I O t a a c S v *

® Break

Olnactwe

@ Break

O L o g

Backgrourd Proc

® L 0 f l

O Abort

Olnactwe

@ Break

O L o g

Backgrourd Proc

® L 0 f l

O Abort

L o g p o M t

f O m a c S v e

® L o g

1

OAPor t L o g p o M t

f O m a c S v e

® L o g

1

Figu re 5.16 C h e c k p o i n t G r o u p

W h e n the program reaches an active assertion, it evaluates the corresponding

condition or logical expression. I f no checkpoint group is assigned to a failed

assertion, the default behavior is for a runtime error to be produced. I f the con-

dition is violated, the program terminates with a runtime error, accesses the

ABAP Debugger, or creates a log entiy; otherwise, the program continues wi th

the next statement. I f you assign the assertion to a checkpoint group, the pro-

gram behavior is controlled by the corresponding activation settings o f the

checkpoint group.

You can also edit the conditional and unconditional checkpoints using the Break-

point tool in the Debugger as shown in Figure 5.17.

W s J M - H l i ' M J ^ T i W T B y cneocoiniAcwjiw.s

S I H J S 6 r o u p - S p e c i f i c A c t i v a t i o n

M B R E A K - P O U T ) LOO-PCHNTI

^ C3 1 Group-Soecrtc

O ^ . C H E C K P O I N T s t o p

£hangeActva»on • E R E A K P O N T

Add Ac trot on 1 . 0 C - P 0 W T

Beactvaw ASSERT

A S S E R T

Log LOO

Inactr/e

Cancel S t o p p e d Stopa.05

F igu re 5.17 C h a n g i n g t h e Ac t iva t ion in t h e D e b u g g e r

114 Chapter 5 ABAP Debugger Program Usage

New Debugger Customization and Settings

O n e of the main benef i ts of the Debugger interface redesign is to have the op t ion of making it conf igurable for y o u r use. This provides y o u wi th the op t ion o f being able to set the v iews and the i r sizes as requi red . You also have the ability to g r o u p certain views toge ther and have t h e m available at each restar t of the n e w Debugger .

In its cur ren t fo rm, the Debugger provides y o u wi th a flexible and designable interface wi th a total o f 11 work areas o r desktops . D e p e n d i n g on y o u r select ion, y o u can have up to fou r tools s imul taneous ly in each of these work areas. Their sizes can be set individually. The first th ree desk tops al low y o u to specify indi-vidual set t ings using the SAVE LAYOUT func t ion (see Figure 5.18). The Debugger will use y o u r last saved sett ings t he next t ime y o u start the Debugger .

pebugger Controls Session 1 (Exc

Figure 5.18 Save Layout 8utton

W h e n y o u start the Debugger , be low the title bar in the applicat ion tool bar y o u will f ind the s tandard f low control bu t tons (see Figure 5.19). These f low control bu t tons remain unchanged f r o m the classic vers ion of the Debugger .

| (1) • ABAP Debugger Control!!

Q • Watchpoint

Figure 5.19 Flow buttons

The first bu t ton provides a single-step func t ion , the second an execute func t ion , t he third a re turn func t ion , and the last con t inues execut ion . The b u t t o n s also provide a way to set a b reakpoin t o r create a wa tchpoin t , o r as m e n t i o n e d above, save the layout conf igura t ion .

Below the applicat ion t o o l b a r y o u will find the in format ion regarding the cur ren t code being executed (see Figure 5.20). You will see t he p rogram and the n a m e o f the Include o r p rog ram of the source current ly executing, and b e l o w that, the p rogram event and the n a m e of the event cur ren t ly execut ing. To the right of the Include o r p rogram n a m e is the cur ren t l ine that will execute . The bu t ton direct ly be low this l ine n u m b e r posi t ions the screen to s h o w this l ine in the source code

Key Concepts Refresher Chapter 4 115

tool. The blue i b u t t o n displays the p rogram at t r ibutes of the source code. The bu t tons displayed be fo re the p rog ram n a m e o r event , if clicked, o p e n a n e w win-d o w with the source code displayed. The same bu t ton is available w h e n viewing the ABAP call stack tool for each call. Again, clicking on the b u t t o n o p e n s t he source code at that poin t in t he p rogram.

" Z_TEST_PR06RAH / Z_TEST_PR06RAH 1 38

% FORM / F I R S T . S U B R O U T I N E Q Q

OesMoo 1 Desktop 2 Deskioo3 dHHiTHTB Structures Tables

Figure 5.20 Program Information

To the right o f the p rogram in format ion y o u will f ind t w o system variables and the i r con ten t s displayed. The defaul t is SY -SUBRC (the sys tem variable conta in ing the s t a tement re turn code) and SY-TABIX ( the sys tem variable conta in ing t he internal table r o w last accessed), but y o u can over r ide e i ther o r bo th s imply by typing ove r their names .

Mos t o f the screen is used to display the desktops o r tool area. Unlike the classic Debugger , the larger y o u r screen o r the h igher y o u r screen resolut ion, the m o r e data can be displayed.

The Variable Fast Display tool current ly has fou r tabs (see Figure 5.21). The first t w o are p rov ided empty , a n d y o u can e i ther type o r d o u b l e click a n a m e in the source code to add it to the list. The third tab (LOCALS) shows all local variables for the cur ren t p rogram modular iza t ion unit , and the four th (GLOBALS) shows all global variables in the cur ren t p rog ram.

-AWiPVM^M variables 2 Locals Globals

& Q 0 m 1st [variable (Va |Val.

6T.STAN0ARD Standard Table[5x3(36) ST.SORTEO 6T_HASHED

Sorted Table[5x3(36)] Hashed Table[6x3(36)]

Figure 5.21 Variable Fast Display

The Variable Fast Display on the first two tabs also provides a bu t ton to select t w o objects displayed and do a compar i son . Alternatively, y o u can navigate to the DIFFERENCE tab and specify the variables direct ly (see Figure 5.22 for the Diff tool).

116 Chapter 5 ABAP Debugger Program Usage

Variable 1 6T.5CRTE0 Val. Sorted Table[5i3<3«))

variable 2 6TJMSW0 Val Hashed Table(6>3(36)|

iSSttrtCflffiMfliffi " MaiNOOfHt t 100

!*je* !dit [o [oesenpoon |to<a8on [ot SCRTEO [OT HASHED DO OT.SORTEO Soiled Tatte Hashed Table

I CD 0«»»»MN^DerMR0W» OT.SORTEO 5 6 3 The elements ra¥e drffcrent cert#nts OT_SOfiTEOflH»TA_riD«16<3) 3 109 4 The elements nave a®#rem cc*«nts OT_SOKTEO(3HMT_FIO 3 67

Figure 5.22 Diff Tool

Finally, it is possible to change h o w secondary tools, for example , the edi tor , a re o p e n e d : e i ther in a n e w parallel w i n d o w or in the cur ren t w i n d o w . It is also pos-sible to cus tomize t he behav ior of the navigat ion to Detail Views and w h e r e the variable will be displayed w h e n clicked on f rom the source code tool.

Important Terminology

You will need to unde r s t and the d i f fe rence b e t w e e n a b reakpo in t and a watch-point for effect ive use of the Debugger . R e m e m b e r that a b reakpo in t relates to the actual code, e i ther a s t a t emen t o r poin t w i th in the code, whe rea s a watch-point is related to the value o f a data object . It is also impor t an t to unde r s t and h o w checkpoin t g r o u p s can mod i fy the behav ior of b reakpoin t s .

A n o t h e r possible cause of confus ion is the d i f fe rence b e t w e e n an external m o d e and an exclusive m o d e . R e m e m b e r that an external m o d e describes the n u m b e r of sessions o p e n e d wi th in a login session, whe rea s an exclusive m o d e is w h a t keeps the Debugger in o n e work process wi th in the server . R e m e m b e r that a non-exclusive m o d e will be rolled out b e t w e e n s teps in the Debugger and may switch work processes.

% Practice Questions

The practice ques t ions be low will he lp y o u evaluate y o u r unde r s t and ing of the topic. The ques t ions s h o w n are similar in na tu re to those f o u n d o n the certifica-tion examina t ion , but a l though n o n e of these ques t ions will be on the exam itself, they al low y o u to review y o u r knowledge of the subject . Select the correct answers and then check the comple teness of y o u r answers in the fol lowing solu-

Practice Questions Chapter 4

t ion sect ion. R e m e m b e r that y o u mus t select all correct answers and only correct a n s w e r s to receive credi t for the ques t ion .

1. The Debugger displays a m a x i m u m of eight data objects at o n e t ime.

• A. True

• B. False

2 . A wa tchpo in t s tops p rog ram execut ion eve iy t ime the condi t ion specified is me t .

• A. True

• B. False

3. Both the classical Debugger and t he n e w Debugger can be used o n all ABAP code wi thou t restr ict ion.

• A. True

• B. False

4 . U n d e r wh ich c i rcumstances will the classical Debugger start as the Debug-ger? (Select all tha t apply.)

• A. None . The n e w Debugger will a lways start as the Debugger .

• B. W h e n five m o d e s already exist for this logon session.

• C. W h e n the n u m b e r o f debugging sessions exceeds half the n u m b e r of dia-log sessions.

• D. W h e n y o u specify the defaul t as the classical Debugger in the set t ings of the Object Navigator.

• E. If y o u manual ly swi tched to the classical Debugger du r ing y o u r last ses-

sion.

5. A non-exclusive debugging m o d e means? (Select all that apply.)

• A. A roll-out is forced in t he applicat ion a f t e r each Debugger view.

• B. Someone else is debugging the same source code.

• C. Debugging is no t possible b e t w e e n the s t a t emen t s SELECT and ENOSELECT because the da tabase cursor needs to be closed using a COMMIT.

118 Chapter 5 ABAP Debugger Program Usage

• D. D e b u g g i n g is n o t poss ib le f o r c o n v e r s i o n o r field exi ts .

• E. O w i n g to t h e c o m m i t , i ncons i s t en t da tase t s can occu r in the d a t a b a s e .

• F. It m a y b e u s e d a n y w h e r e in t h e l andscape .

6 . W h a t is the m a x i m u m n u m b e r o f w a t c h p o i n t s tha t can exis t a t o n e t ime?

• A. 8

• B. 1 0

• C. 1 6

• D. N o l imit

7. Set t ing b r e a k p o i n t s f o r a m e t h o d o r f u n c t i o n m o d u l e w i t h i n the D e b u g g e r

a l lows t h e use o f I H | (va lue he lp) to find t h e co r r ec t n a m e .

• A. T r u e

• B. False

8. All b r e a k p o i n t s a re valid f o r t h e e n t i r e D e b u g g e r sess ion , a n d all can b e

c h a n g e d b y t h e D e b u g g e r .

• A. T r u e

• B. False

9 . It is poss ib le to m a k e mu l t i p l e c h a n g e s to da t a o b j e c t s at t h e s a m e t i m e in

t h e D e b u g g e r .

• A. T r u e

• B. False

10 . W h e n s t a r t ing t h e D e b u g g e r , w h a t c i r c u m s t a n c e causes t h e r u n t i m e e r r o r

D E B U G G I N G _ N 0 T _ P 0 S S I B L E ?

• A. S tar t ing a non-exc lus ive m o d e in a p r o d u c t i v e s y s t e m .

• B. W h e n m o r e t h a n five se s s ions a re a l r eady assoc ia ted w i t h th is login use r .

• C. W h e n t h e n u m b e r o f d e b u g g i n g se s s ions o n t h e s e r v e r e x c e e d s t h e va lue d e f i n e d b y t h e p ro f i l e p a r a m e t e r r d i s p / w p d b u g _ m a x _ n o .

Practice Question Answers and Explanations Chapter 5

11. There a re work areas available in the Debugger .

• A. 7

• B. 9

• C. 11

• D. 15

12. W h a t b u t t o n u n d o e s layout changes to the Debugger? (Fill in the blank.)

Practice Question Answers and Explanations

1. Correct answer : A

The classic Debugger only a l lowed a m a x i m u m of eight data objects . The n e w Debugger al lows an unl imi ted n u m b e r (restricted only by fon t and w i n d o w size) to be displayed at t he same t ime.

If y o u e n c o u n t e r a ques t ion discussing an ability o r l imitation o f the classic Debugger , y o u should a s s u m e that the ques t ion refers to the classic Debugger a n d a n s w e r accordingly. If the ques t ion re fe rences the n e w Debugger , t he a n s w e r w o u l d be false.

2 . Correct answer : B

Wherea s it is t rue that if a condi t ion is specif ied, t he wa tchpo in t will no t s top unti l the condi t ion is t rue, the wa tchpo in t will no t be tr iggered unti l the vari-able con ten t s change. The re fo re if y o u set a wa tchpo in t that is a lready true, the wa tchpo in t will no t be t r iggered.

3. Correct answer : B

The classic Debugger canno t analyze convers ion exits o r field exits. It also has s ide effects wi th search help (Fl), value help (F4), and list o u t p u t .

4. Correct answers : B, D

W h e n y o u already have five external m o d e s in use (or m o r e accurately w h e n y o u only have one external m o d e remaining) , t he classic Debugger is auto-matically s tar ted w h e n star t ing a n o t h e r external m o d e would p reven t fu r the r sessions f r o m being created. I f y o u have t he defaul t Debugger specified as t he classic, it will a lways start wi th this vers ion.

120 Chapter 5 ABAP Debugger Program Usage

5. Cor rec t a n s w e r s : A. C, D t E

A non -exc lu s ive m o d e m e a n s t h e sess ion is n o t locked i n t o a w o r k p r o c e s s a n d will b e ro l led o u t a n d ro l led in b e t w e e n s teps . T h e ro l l -out fo rces a COM M I T WORK b e t w e e n s t eps , w h i c h m e a n s t h e d a t a b a s e c u r s o r will b e lost , caus-ing a s h o r t d u m p if it occu r s b e t w e e n a S E L E C T a n d E N D S E L E C T . Because data-base c o m m i t s o c c u r w i t h o u t r ega rd to logical un i t s o f w o r k , t h e d a t a b a s e m a y b e c o m e i n c o n s i s t e n t . T h e D e b u g g e r p r e v e n t s th is i ncons i s t ency in a p r o d u c t i o n e n v i r o n m e n t .

6 . Cor rec t a n s w e r : B

O n l y 1 0 w a t c h p o i n t s can exis t at o n e t i m e w i t h t h e classic D e b u g g e r . T h e n e w D e b u g g e r has n o l imi t .

If y o u e n c o u n t e r a q u e s t i o n d i scuss ing a n abi l i ty o r l imi ta t ion o f the classic D e b u g g e r , y o u s h o u l d a s s u m e t h a t t h e q u e s t i o n r e fe r s to t h e classic Debug-g e r a n d a n s w e r accord ing ly . If t h e q u e s t i o n r e f e r e n c e s t h e n e w D e b u g g e r t h e a n s w e r w o u l d b e o p t i o n D.

7. Cor rec t a n s w e r : A

W i t h t h e n e w D e b u g g e r e x e c u t i n g in a s e p a r a t e m o d e , it h a s access to s ea rch

h e l p s tha t m a y b e u s e d f o r se t t ing b r e a k p o i n t s .

I f y o u e n c o u n t e r a q u e s t i o n d i scuss ing the a b s e n c e o f an abi l i ty o f t h e classic D e b u g g e r , y o u s h o u l d a s s u m e tha t t h e q u e s t i o n r e f e r s to t h e n e w D e b u g g e r a n d a n s w e r accord ing ly .

8 . Cor rec t a n s w e r : A

B r e a k p o i n t s se t in t h e e d i t o r can b e c h a n g e d in t h e D e b u g g e r . Local break-

p o i n t s can b e c o n v e r t e d to e i t h e r sess ion o r ex te rna l b r e a k p o i n t s .

9 . Cor rec t a n s w e r : A

If y o u o p e n u p m u l t i p l e da ta o b j e c t s f o r c h a n g e , t h e I I key will accept all c h a n g e s to all ob jec t s .

10 . Cor rec t a n s w e r : A

I f y o u a t t e m p t to s tar t t h e D e b u g g e r o n a p r o d u c t i o n s y s t e m a n d an exc lus ive m o d e is n o t avai lable , t h e sys t em wil l p r o d u c e t h e r u n t i m e e r r o r OEBUGGI NG_ N 0 T _ P 0 S S I 8 L E . O n a n o n - p r o d u c t i v e s y s t e m y o u w o u l d rece ive t h e indica-t ion o f a non -exc lu s ive m o d e in t h e t i t le, bu t o w i n g to t h e po t en t i a l f o r i n c o n s i s t e n t da ta , th is m o d e is n o t a l l owed o n p r o d u c t i o n sy s t ems .

11 . Cor rec t a n s w e r : C

T h e r e a re 11 d e s k t o p a reas c u r r e n t l y avai lable f o r use .

Take Away Chapter 5

12. Correct answer : Back

The BACK bu t ton u n d o e s the layout changes y o u have m a d e to each desk top . Using the BACK bu t ton mul t ip le t imes will u n d o each layout change.

Take Away

You should n o w be able to examine the r u n t i m e behavior of ABAP programs using the ABAP Debugger . By examin ing data objects wi th in the Debugger , it is possible to d e t e r m i n e w h y a p rogram behaves correctly o r incorrect ly. If y o u d e t e r m i n e the cause o f a p rob lem in the p rogram, it is easier to provide a correc-t ion o r a solut ion to t he issue.

I f y o u design p rograms wi th an eye to ident i fy ing issues du r ing test ing th rough the use o f asser t ions and checkpoin t g roups , y o u r p rograms will be easier to main ta in and p r o d u c e f ewer issues once they are in p roduc t ion .

Refresher

You must unde r s t and wa tchpo in t s and breakpoin t s — bo th the i r use and h o w to def ine t h e m . You need to unde r s t and h o w to de f ine and use asser t ions and checkpoint g r o u p s in y o u r p rogram.

The final th ing y o u should take away f r o m this uni t is the d i f fe rences b e t w e e n the classical Debugger and the n e w Debugger . You should unde r s t and the archi-tecture of each, wha t l imitat ions exist, and w h y the l imitat ions exist . It is also impor t an t to unde r s t and the tools and wha t op t ions exist wi th in the d i f fe ren t tools.

Table 5 .3 shows the key concepts o f the Debugger .

Key Concept Definit ion

Architecture of the The classic Debugger shared the same external mode roll Debugger area as the executing program, whereas the new Debug-

ger runs in its own external mode.

Desktops and their tools The desktops in the Debugger and how the various tools function in the Debugger.

Table 5.3 Key Concepts Refresher

122 Chapter 5 ABAP Debugger Program Usage

Key Concept

Checkpoint groups

Definition

Breakpoints

Watchpoints

Used to define and use assertions and checkpoint groups and their behavior during program execution.

Used to define various types of breakpoints.

Used to define a watchpoint.

Table 5-3 Key Concepts Refresher (cont.)

Tips

As you take the examination, read the questions carefully. If a question or answers are valid for only one of the two Debuggers, you should answer the question assuming that the question refers to that Debugger. The majority of the questions can be answered for either Debugger because both contain veiy simi-lar functionality. If the question specifies a specific Debugger, answer the ques-tion as it pertains to that specific Debugger.

As with the majority of the subjects in the certification examination, it is impor-tant to have as much practical experience with the subject as possible. Unlike the majority of subjects in the certification examination, you typically will learn more using the Debugger than jus t reading about it.

S u m m a r y

You should now be able to examine the runt ime behavior of an ABAP program using the ABAP Debugger to identify issues with the program and to systemati-cally test the program. You should be able to identify and create watchpoints and breakpoints and know the various types of breakpoints. Lastly, you should unders tand the differences between the two versions of the Debugger. These abilities will enable you to pass this section in the certification exam easily.

ABAP Types and Data Objects

Techniques You'll Master:

• Describe ABAP data types and data objects

• Def ine data objects using p rede f ined a n d gener ic data types

• Unders tand the local data types

• Under s t and the global data types

• Unders tand the visibility o f data objects

• Under s t and flat s t ruc tures and d e e p s t ruc tures and different i-ate b e t w e e n t he two

124 Chapter 6 ABAP Types and Data Objects

Data types a re requi red to de f ine the technical a t t r ibu te of a data object . Depend-ing on the data type, y o u migh t have to de f ine the length and n u m b e r of decimal places to fully de f ine a data object in the p rogram. You can use p rede f ined o r ABAP Dict ionaiy data types to de f ine a data object . You can also de f ine local data types wi th the p rog ram and use t h e m to de f ine data objects in the p rog ram. Data objects a re t e m p o r a r y s torage in the p rogram and occupy m e m o i y ; they exist f o r the dura t ion of t he p rogram.

In this chapter y o u will learn abou t data types a n d data objects and the d i f fe rence b e t w e e n t h e m . You will learn abou t e l e m e n t a i y data types, local data types, and global data types. You will learn h o w to de f ine data types and data objects and use t h e m in the p rogram. Finally, y o u will learn abou t the visibility o f the data objects wi th in ABAP programs .

Real-World Scenario

You have s tar ted on a n e w projec t and have to deve lop an applicat ion for the projec t . To deve lop an applicat ion y o u have to unde r s t and the data types and data objects available wi th in the ABAP p r o g r a m m i n g language and which ones to use in the applicat ion because to process data such as reading f r o m a database table o r sequent ia l file and displaying t h e m o n the screen, y o u mus t read and s tore the data temporar i ly in a data object .

Data objects conta in data wi th which p rog rams work at run t ime , and they exist for the dura t ion of the p rog ram. To de f ine a data object y o u requi re a data type, which can be a local o r global data type. So to wr i te any applica-tion in a system, y o u need the def in i t ion of a data type and objec t to read and process the data in the appl icat ion.

You need to k n o w the p r ede f ined and gener ic data types y o u can use a n d the valid ope ra t ions on the var ious data types, as well as the d i f fe rence b e t w e e n local and global data types. You also need to k n o w the syntax fo r data declara t ions a n d their usage in the p rog ram in o rde r to wr i te robus t applicat ions.

Objectives of this Portion of the Test Chapter 6

Objectives of this Portion of the Test

The object ive o f this por t ion of t he ABAP cert if ication is to test y o u r knowledge about the basic unde r s t and ing of the ABAP data types and data objects in t he ABAP p r o g r a m m i n g language. The cert if ication exam expects a good under s t and-ing of the fol lowing f r o m the applicat ion developer :

• Concept o f data types and data objects

• Predef ined and gener ic data types

• Valid opera t ions o n the var ious data objects and their usage in p rograms

• Concept o f local data types and t he global data types

• St ructure declarat ions and the d i f ferences b e t w e e n flat, nes ted , and d e e p s t ruc tures

Key Concepts Refresher

Programming languages requi re variables o r fields to s tore data locally in t he p rogram. A data objec t is also re fer red to as variable and is the t e m p o r a r y inter-nal s torage wi th in the appl icat ion. The type o f opera t ion that can be p e r f o r m e d on the variable o r data object d e p e n d s o n its data type. The ABAP language has p rede f ined and gener ic data types, and t he syntax fo r the data declarat ion for the data objects is d e p e n d e n t on the data types y o u use.

Like any p r o g r a m m i n g language the data declara t ions wi th in the ABAP p rog ram can be local o r global. The scope and the validity of the data objec t d e p e n d on the def in i t ion of the data objec t wi th in the p rogram. Therefore , y o u should have a good unde r s t and ing of the fol lowing to wr i te a robust bus iness appl icat ion:

• Different ia te b e t w e e n the p redef ined and gener ic data types and the i r usage wi th in the p rogram

• Syntax of the data declarat ion

• Describe the valid opera t ions of the data objects

ABAP Types and Data Objects

Programs in any p r o g r a m m i n g language work wi th local data, and this data is s tored in the p rogram variables. Variables have names and type a t t r ibutes , which

140 Chapter 6 ABAP Types and Data Objects

can b e n u m e r i c , cha rac te r , o r s t r ing d e p e n d i n g o n t h e da ta t y p e s u p p o r t e d by t h e

l anguage .

In t h e ABAP l anguage t h e va r iab le is cal led a data object a n d it is d e f i n e d c o n -cre te ly by a da t a t ype . Data o b j e c t s a r e a l w a y s d e f i n e d w i t h t h e d a t a k e y w o r d . You can use ABAP type , local type , a n d g lobal t y p e to t y p e da t a ob jec t s .

D a t a T y p e s

T h e da t a t y p e i s j u s t a d e s c r i p t i o n a n d d o e s n o t o c c u p y m e m o i y ; it can b e d e f i n e d in t h e p r o g r a m i n d e p e n d e n t l y . You can d e f i n e y o u r o w n da ta t y p e based o n t h e p r e d e f i n e d da ta types o r g lobal da ta types . Local da ta types a re d e f i n e d in t h e p r o g r a m , w h e r e a s g lobal da t a types a re d e f i n e d in t h e ABAP Dic t iona iy . Local da t a types a re d e f i n e d us ing t h e t y p e s s t a t e m e n t , w h e r e a s g lobal da t a types a r e d e f i n e d in t h e ABAP D i c t i o n a i y u s ing da t a e l e m e n t s , t y p e poo l s o r t y p e g r o u p s , table types , s t ruc tu re s , a n d tables . ABAP Dic t i ona ry o b j e c t s such as tab les a n d s t r u c t u r e s a n d t h e i r c o m p o n e n t s can a lso b e u s e d to d e f i n e da t a types . Local da ta types a r e avai lable to t h e p r o g r a m in w h i c h t h e y a re dec l a red , w h e r e a s t h e g lobal da t a types a re avai lable to all p r o g r a m s in t h e SAP sys t em.

• Data t y p e s a r e u s e d f o r t h e d e f i n i t i o n of da t a ob jec t s . T h e y d e f i n e t h e t echn i -cal a t t r i b u t e s o f t h e da t a ob jec t s , h o w t h e da ta ob jec t is s t o r e d in m e m o i y , a n d w h a t o p e r a t i o n s a r e poss ib l e o n t h e da ta o b j e c t ba sed o n the da t a t ype .

• Data types a re a lso u s e d f o r t h e d e f i n i t i o n o f i n t e r f a c e p a r a m e t e r s . T h e t y p e

o f t h e in t e r f ace p a r a m e t e r d e t e r m i n e s t h e t y p e o f t h e actual p a r a m e t e r s o r val-

ues tha t a r e t r a n s f e r r e d w h e n a m o d u l a r un i t is cal led. T h e m o d u l a r un i t can

b e a s u b r o u t i n e , f u n c t i o n m o d u l e , o r m e t h o d .

• T h e y can also b e u s e d f o r t h e d e f i n i t i o n o f t h e i n p u t / o u t p u t fields in t h e ABAP p r o g r a m . T h e y a r e u s e d to dec la re p a r a m e t e r s a n d s e l e c t o p t i o n s f o r p r o -g r a m se lec t ion s c r e e n s a n d d y n p r o s c r e e n f ie lds c r ea t ed in t h e Screen Pa in te r . For de ta i l s r e g a r d i n g p a r a m e t e r s a n d s e l e c t o p t i o n s r e f e r to C h a p t e r 13 , Selec t ion Screens , a n d f o r d y n p r o sc reen r e fe r to C h a p t e r 12 , Classical Screens .

T h e ABAP data t y p e s can b e c lass i f ied in to p r e d e f i n e d o r s t a n d a r d ABAP t y p e s a n d local a n d g lobal da ta t y p e s (see Figure 6 .1) . T h e s e da ta t y p e s a re d i scussed in de ta i l in t h e s u b s e q u e n t sec t ions .

Key Concepts Refresher Chapter 6 127

Figure 6.1 ABAP Data Types

Data Objects

Data objects are t e m p o r a r y s torage in the p rogram and occupy m e m o r y to s tore data. Data objects conta in data for t he p rog ram, and they exist for the dura t ion of t he p rogram. The technical a t t r ibutes of a data object a re its length, n u m b e r of decimal places, and the data type, if it is de f ined us ing the e l emen ta ry data type. For the data objects de f ined wi th re fe rence to the ABAP Dict ionary object , the technical a t t r ibutes such as length, n u m b e r of decimals, and data type are der ived f r o m the ABAP Dict ionary object .

ABAP programs work wi th the con ten t s of the data objects and in te rpre t them according to their data type. You declare the data objects statically in the ABAP program or dynamical ly at run t ime . You can create the data objec t dynamical ly w h e n y o u call the p rocedure wi th a parameter , such as w h e n y o u call f r o m rou-t ine wi th pa ramete rs in the p rogram. The p rogram treats literals like data objects , bu t literals are data objects wi th a fixed value.

Data objects can be declared wi th t he p rede f ined data types, local data types, o r global data types. Data objects are de f i ned in the p rogram by using t he DATA s ta tement and can be assigned a start ing value wi th the VALUE s ta t ement . ABAP contains the fol lowing types of data objects:

• L i te ra ls Literals are u n n a m e d data objects wi th fixed values and are created in the source code of the p rog ram. The literal value cannot be changed, and they have fixed a t t r ibutes such the data type and length and n u m b e r of decimal

128 Chapter 6 ABAP Types and Data Objects

places. Three types o f literal a re de f ined in the ABAP run t ime e n v i r o n m e n t : numer ic literals, text field literals, and s t r ing literals.

• N u m e r i c l i t e ra l s

You def ine numer i c literals wi th a sequence of digits that may conta in a plus o r m i n u s sign; that is, the sign is no t m a n d a t o i y . The numer i c literals represen t the valid n u m b e r ranges de f ined wi th in the p rede f ined data types. The numer i c in teger literal has a value range f r o m -2**31+1 to 2**31 -1, that is, the value range f r o m 2 . 1 4 7 , 4 8 3 , 6 4 8 to + 2 . 1 4 7 , 4 8 3 . 6 4 7 . To assign a numer i c literal to a variable, y o u d o not r equ i re inver ted com-mas (single quo ta t ion marks) a r o u n d the numer i c literal. Following is the syntax f r o m the numer ic literal def in i t ion : OATA: v a r l TYPE I VALUE 12345.

• Text f ie ld l i t e ra l s

The text field literals a re de f ined in the p rogram with a s equence of char-

acters wi th in single inver ted c o m m a s ( ' ) . The text literal can be f r o m 1 to

2 5 5 characters in length and is of data type c. Trailing spaces in the text

field literal arc ignored. Following is the syntax for text literal def in i t ion :

OATA: c _ v a r l ( 3 ) TYPE C VALUE ' a b c ' .

• S t r ing l i t e ra l s The str ing literal is def ined as a s equence o f characters enclosed wi th back quo tes ( ' ) . The length of the str ing literal can be up to 2 5 5 characters and is of data type STRING. Trailing blanks in the s t r ing literal a re not ignored , unl ike wi th the text literals. Following is the syntax to de f ine a STRING data object :

DATA: s t r _ v a r TYPE STRING VALUE 'TEXT'.

• C o n s t a n t s Constants a re n a m e d data objects tha t have fixed values a n d are de f ined stat-ically using a declarative s t a t ement . You def ine cons tan ts wi th the CONSTANTS keyword and assign the value to the data objec t wi th the VALUE s t a t emen t addi t ion . The value of cons tants cannot be changed dur ing the execut ion o f the p rogram. If y o u t iy to change the value of the cons tan t , a r u n t i m e e r r o r occurs.

It is r e c o m m e n d e d that y o u use cons tants instead of literals in the p rog ram. You declare cons tan ts using the fol lowing syntax:

CONSTANTS: c_nump TYPE P DECIMALS 3 VALUE ' 1 2 3 . 6 5 7 ' . C_C1ty TYPE C LENGTH 10 VALUE 'BERLIN'.

Key Concepts Refresher Chapter 6 129

Text s y m b o l s Text symbols are a n o t h e r kind of n a m e d data objec t and be long to a specific p rogram. Text symbols are genera ted f r o m the text pool in the ABAP p rog ram w h e n y o u start the p rogram. Program titles, such as head ings and the selec-t ion texts, a rc text e l emen t s of the p rogram. The text e l emen t s of the p rogram are s to red as text symbol data objects .

Text symbols a re s tored outs ide the source code in the text pool repos i tory objec t for the p rogram. Text symbols can be t ranslated in d i f f e ren t languages and s tored in the text pool wi th the language indicator . The p rogram or selec-t ion screen uses the text symbol to display the text, a n d text can be displayed in the logon language automatical ly if the text symbol is main ta ined for t he logon language. Text symbols are o f data type C and are accessed by a three-character a lphanumer i c ID.

To access the text symbol in the p rog ram y o u need to address it as TEXT-XXX, w h e r e XXX is the text ID for the text symbol main ta ined in the text pool repos-i tory for the p rogram. You mainta in the text symbol f r o m the ABAP Editor f r o m t h e m e n u p a t h G O T O • TEXT ELEMENTS • TEXT SYMBOLS. YOU c a n a l s o

access the text symbol f r o m the ABAP p rog ram by double-clicking o n the text symbol in the p rogram, as s h o w n in the fol lowing s t a tement : WRITE t e x t - 0 0 1 .

WRITE 'THIS i s an Eng l i sh t e x t ' ( 002 ) .

P r e d e f i n e d d a t a o b j e c t s

Predef ined data objects a re the ones that are a lways available du r ing the runt-ime of the p rogram and are not requi red to be declared in the p rogram. Pre-de f ined data objects are also called system variables. The sys tem fields SY is a s t ruc ture wi th the ABAP Dict ionaiy data type SYST. The sys tem fields SY are automatical ly filled and upda t ed by t he r u n t i m e e n v i r o n m e n t . System fields a re variables and can be changed dur ing t he execut ion of the p rogram, but this is no t r e c o m m e n d e d . Figure 6.2 displays the s t ruc ture of the ABAP Dic-t iona iy SYST. Va r i ab l e s Variables are called data objects , and are e i ther declared statically in the pro-gram or created dynamical ly du r ing the execut ion o f the p rogram. Variables a l low y o u to s tore data locally for the p rogram in m e m o i y , and the i r value can be changed dur ing the execut ion of the p rogram. You can statically declare variables wi th the fo l lowing declarat ive s ta tements :

144 Chapter 6 ABAP Types and Data Objects

D i c t i o n a r y : D i sp lay S t r u c t u r e

Slructrt SftolOKnplxr

SYST ASAP Syst tmFi t t»

A«V»

INDEX PAGHO TAB IX ff ILL HOPC JIWL

UA&C TST1S TT«BI DtCNT Fi'Pp; COLHO UNCI LIKWO LLHS2 PAQCT IUC0L W W TLEMG Sf Off irflLLI

III

»-| • ] A RTy C o n w w i y p t OauTjpe

SVIN&EX SYPAGKO SVTAEIX SYTflLL SYTLOPC

SYTOCCU SYUABC SYTSI1S SVTTABI SYDBtMT svFC'po; S-VC PL HO SYLIHCI SXL.MQ SYL1HS2 SYPACCT SYHACOt SYHAROV SVTLEH6 SYSfOff SYWILLI <vi n n

2NT4 •NT4 1NT4 I N I 4 INT4 2NT4 INT4 INT4 INT4 INT4 2NT4 INT4 !NT4 INT4 1NT4 2NT4 INT4 2NT4 INT4 1NT4 2NT4 INT4

-J.tLU_

1 ] _ 171 L«n(pi OMma $wt Dtscnfoco

10 0L«pMw 10 OCurMUtfPag* 10 OWt*0<M*m«(TaM« 10 ORo»vHLrtw»«W«fndToMw 10 OWtmaAEAPSywnF'eM 10 OOOiokW A8AP Syskci Pitts

10 OOMO*»A8APSy!K«*Fl«tS 10 OOMottWAeAPSyskcnFittJ 10 OWtmjl AGAPSyatmFitM 10 OOMCtKt A8AP Fi« 10 OProctsiodDatatostTabtoRonw 10 OF«rd locaooo in EM* or Character S»ing 10 0CmflU«Ce*/m 10 OP*j*Ler»^ho»lia 10 OCirMUntinliM 10 OL.now<»oM« 10 OOMOtKtAeAPSyswnPittj 10 OM*rt*<c«C<*rmsonLt«Mar0ne<PrrtUH

10 0 HrrCtt d CoU-rt « T«. Moi r o<« Pn-< U« 10 ORcw l«ogpi or wemai Tabtt 10 Ortornd A&*PSya«nFi«tj 10 OOWdKtA8APSys»«nFiatj

_LQ nratfi-lfrth iflrr,

Figure 6.2 ABAP Dictionary Structure SYST

• The DATA keyword is used to declare the data in the program whose life-time and visibility are dependent on the context of the declaration. If the variable is defined in a subroutine, then it is valid for the lifetime of the subroutine and only in the subroutine. Otherwise, if it is defined at the top of the program, it is globally available in the program. You provide the ini-tial value to the data object using the VALUE keyword:

OATA: count TYPE I . count2 TYPE I value 10.

• The STATICS keyword is used to declare the data with the static validity within the procedure. Variables declared with the DATA statement exist as long as the context in which they are defined. Variables defined in the ABAP main program exist until the runtime of the program and the local variables defined in procedure are only available inside the procedure as long as the procedure is running. You can declare a variable using the STATICS keyword to retain a local variable (defined inside the procedure) beyond the runtime of the procedure. The declared variable within the

Key Concepts Refresher Chapter 6 145

procedure will exist for the l i fet ime of the main p rog ram but is available wi th in the p rocedure . Hence, i f y o u w a n t to keep the value of the local data objec t beyond the r u n t i m e of the subrou t ine , t hen y o u should use t he STATICS keyword to declare the variable. The fol lowing example displays t he use o f the STAT IC keyword : REPORT DEMO_STATIC_DATA_OBJECT. 00 5 TIMES. PERFORM d a t a o b j e c t _ e x a m p l e . ENDDO. FORM d a t a o b j e c t _ e x a m p l e . DATA coun t l TYPE I .

STATICS count2 TYPE I . c o u n t l - coun t l + 1. countZ - count2 + 1. WRITE: / ' C o u n t l : c o u n t l . 'Count2 : coun t2 . ENDFORM.

W h e n y o u execute the p rogram, the fol lowing is displayed:

C o u n t l : 1 Count2: 1 C o u n t l : 1 Count2: 2 C o u n t l : 1 Count2: 3 C o u n t l : 1 Count2: 4 C o u n t l : 1 Count2: 5

In the above example the variable c o u n t l does not retain the value because it is declared wi th the OATA keyword , whe rea s the variable coun t2 , declared wi th t he STATICS keyword , retains the value fo r t he r u n t i m e of the p rogram. The variable c o u n t l is initialized again w h e n the s u b r o u t i n e is called t he next t ime, whereas the variable coun t2 is initialized only dur ing the first call and keeps inc rement ing the value dur ing the subsequen t call.

• CLASS-DATA The CLASS-DATA k e y w o r d is used to declare a static a t t r ibu te for the class and is valid for all o f the instances o f the class wi th in the p rogram.

• PARAMETERS

The PARAMETERS keyword is used to declare an e l e m e n t a i y data object that is also displayed as an inpu t field on the selection screen.

• SELECT-OPTIONS

The SELECT-OPTIONS k e y w o r d is used to declare an internal table that is

also displayed as an inpu t field on the selection screen.

You declare variables wi th the OATA keyword wi th the fol lowing syntax:

132 Chapter 6 ABAP Types and Data Objects

DATA: v a r l TYPE I . DATA: var2 LIKE v a r l . DATA: va r3 TYPE STRING VALUE ' H e l l o ' .

The variable n a m e <VAR1> can be up to 30 characters long. You def ine the technical a t t r ibutes of the data objec t du r ing the declara t ion. You de f ine the data type, length, and n u m b e r o f decimal places, a l though for s o m e types the length and n u m b e r o f decimal places a re f ixed (for example , type d, type t , etc.) o r c o m e f rom the Dict ionary. The variable is declared using the ABAP Dict ionaiy type.

I f y o u are using the TYPE keyword to declare the data, t hen the <type> could be a p rede f ined ABAP data type, exist ing local data type wi th in t he p rog ram, o r ABAP Dict ionaiy data type. If y o u are using the L IKE keyword to declare the data object , then the <obj> mus t be an existing data object in the p rogram that has already been declared, o r it can be a da tabase table, view, o r s t ruc ture o r a c o m p o n e n t of the table or s t ruc ture .

The VALUE k e y w o r d is used to de f ine a s tar t ing <val> value for the variable. The LIKE s ta tement is a l lowed in ABAP objects on ly to declare local data objects o r SY fields such as SY - UNAME, SY - OATUH, and so on .

ABAP Data Types

ABAP data types are the p rede f ined data types p rov ided by the ABAP r u n t i m e e n v i r o n m e n t . The p rede f ined data types can be used in all ABAP programs . You use p rede f ined data types to de f ine local data types and data objects in y o u r pro-g r a m .

ABAP data types can be used to descr ibe a single variable a n d e l emen ta ry data objects . They can be used to descr ibe the c o m p o n e n t s of the s t ruc tured data objects as well. O n e way of classifying the p rede f ined e lementa ry data types is fixed length versus variable length.

There are a total of 10 p rede f ined e l e m e n t a i y data types. There a re eight fixed-length p rede f ined e l emen ta ry data types and two variable-length data types. Fol-lowing arc the eight p rede f ined fixed-length data types.

• The four character types are numer i c text (N), character text (C), da te type (D), and t ime type (T). Fields of these types arc k n o w n as character fields. Each posi t ion in these fields takes e n o u g h space fo r the code of t he o n e character . Wi th the adop t ion of Unicode, each character occupies two to fou r bytes.

Key Concepts Refresher Chapter 6 133

• The th ree numeric types are integer ( i) , floating poin t n u m b e r ( f ) , and packed n u m b e r (p), which are used in ABAP to display and calculate n u m b e r s . The numer i c data types ( i . f , and p) d i f fe r in the inner represen ta t ion o f values, value ranges, and t he ar i thmet ic used in the calculation.

• The in teger type represen ts a w h o l e n u m b e r . The value range for a type I n u m b e r is - 2 . 1 4 7 . 4 8 3 . 6 4 8 to + 2 . 1 4 7 . 4 8 3 . 6 4 7 . Non- in teger results of arith-met ic ope ra t ion are rounded , no t t runca ted . The fol lowing example displays the result o f integer opera t ion :

DATA: numl TYPE 1 VALUE 5. num2 TYPE I VALUE 2 . Resul t TYPE I . Resu l t - numl / num2.

The result he r e would be 3.

The value range of type r n u m b e r s is 1*10** 307 to 1*10**308 fo r posit ive and negat ive n u m b e r s including zero; that is, valid values o f type r n u m b e r s are -1.7976931348623157EE+308 to -2 .2250738585072014EE-308 for the negat ive area, the value z e r o ( 0 ) . and +2.2250738585072014EE-308 to +1.7976931348623157EE+308 for the posit ive area. The accuracy range is approx-imately 15 decimals . You should not use floating poin t n u m b e r s if high accuracy is requ i red ; o therwise , use type P data.

Data objects of type P can have decimal values. The n u m b e r of decimal places can be specified in the def in i t ion of the data object . The value range of type P data d e p e n d s on its length and the n u m b e r of digits a f te r t he decimal po in t . The valid length can be f r o m 1 to 16 bytes. Data objects of type P can have a m a x i m u m of 14 decimal places. The initial value of type P data is zero. W h e n work ing wi th type P data , it is impor t an t to set the p rogram a t t r ibu te to FIXED POINT ARITH-METIC; o therwise , type n u m b e r s are t reated as integers. The data objects of type P a re also called packed data objects . Fol lowing is the syntax for the data objec t of type P :

OATA: pack.numl TYPE P LENGTH 8 DECIMALS 2 . pack_num2 TYPE P LENGTH 8 DECIMALS 2 VALUE ' 2 . 5 5 ' .

The length o f 8 bytes in the above data objec t def in i t ion co r re sponds to 2*8-1 n u m b e r s including the decimals places.

The hexadecimal type, type X. is a data type used to de f ine a byte in m e m o i y . O n e byte is r ep resen ted by two-digit hexadecimal display. The syntax to declare a data objec t of type X is as fol lows:

134 Chapter 6 ABAP Types and Data Objects

DATA: h e x ( l ) TYPE X VALUE ' 0 9 ' .

The two e l emen ta ry data types of variable length are STRING and X ST RING:

• The STRING data type is a variable-length character s tr ing. A s t r ing can conta in any n u m b e r o f a lphanumer i c characters . No m e m o i y is allocated to the s t r ing unti l a value is assigned to it, because w e w o u l d n ' t k n o w h o w much m e m o i y to allocate. The m e m o i y is assigned dynamical ly w h e n w e k n o w w h a t the value will be . There is technically no m a x i m u m length for t he s t r ing data type. The m a x i m u m a m o u n t o f m e m o r y that can be assigned to the str ing is d e p e n -d e n t o n the prof i le p a r a m e t e r ztta/max_memreq_M8.

• The type XSTRING is a variable-length hexadecimal byte sequence . It can con-tain any n u m b e r of bytes. The length o f the by te str ing is t he same as the n u m b e r of bytes. Similar to the type STRING, the m e m o i y is allocated dynam-ically at r u n t i m e w h e n a value is assigned to a data object of this type.

The p rede f ine data types can be f u r t h e r categorized as comple t e data types and incomple te data types. For the comple t e data types, w e d o n ' t specify the length, e i ther because they have a fixed length such as data type D (we w o u l d n ' t eve r need a d i f fe rent length o the r than 8 characters for a date) o r because it is a vari-able-length s t r ing and the re fo re w e d o n ' t specify the length because the m e m o i y is allocated dynamical ly at r un t ime w h e n w e assign a value to it. Hence, the data objec t def in i t ion does not requi re an addi t ional length specification w h e n using comple t e data types.

Table 6.1 specifies the p rede f ined e l emen ta iy data types that do not requi re a length specification for the def in i t ion w h e n def in ing data objects .

Data Type Length Init ial Value M e a n i n g

4 0 Integer data type

8 0 Floating point number

D 8 1 0 0 0 0 0 0 0 0 1 Date field in the format 'YYYYMMDD'

6 ' 0 0 0 0 0 0 1 Time field in the format 'HHMHSS'

S T R I N G Dynamic Dynamic-length character string

X S T R I N G Dynamic Dynamic-length byte sequence (hexa-

decimal string)

Table 6.1 Standard Fixed-Length Data Types

Key Concepts Refresher Chapter 6 135

Data types that requi re the length specif icat ion to de f ine the data object are called the incomple te data types. If y o u d o not specify the length, t hen the defaul t length for the data type will be used. Table 6 .2 lists the incomple te data types.

Data Type Default Length Init ial Value M e a n i n g

c 1 • • Text field, alpha numeric characters

N 1 • 0 . . 0 ' Numeric text field

P 8 0 Packed number

X 1 • X 0 . . . 0 - Hexadecimal byte sequence

Table 6.2 Incomplete A8AP Data Types

Following is the syntax to declare incomple te data types:

OATA v a r l TYPE C. " c h a r a c t e r v a r i a b l e of l e n g t h 1 OATA: v a r 2 ( 3 ) TYPE C. " c h a r a c t e r v a r i a b l e of l eng th 3 OATA: var3 TYPE C LENGTH 3 . " c h a r a c t e r v a r i a b l e of l e n g t h 3

The comple te data types 0, F, I, and T de f ine the data objec t fully. The data types C, N, P, and X are gener ic and requ i re a length specification to de f ine the data object fully. Following is the syntax for the data type a n d data objects:

TYPES: v _ c h a r l ( 2 ) TYPE C. Types: v_char2 TYPE C LENGTH 10. TYPES: numl TYPE P DECIMALS 2 . Oata : name(20) TYPE C. OATA: p r i c e TYPE P DECIMALS 2 .

Local Data Types

Local da ta types a re de f ined inside the ABAP p rog ram and are visible to that pro-gram only. You can use p rede f ined , local, o r global types to de f ine t h e m wi th in the p rogram. You def ine local data types using the TYPES s ta tement :

TYPES: <type_name> . . . [TYPE <ABAP-Type> | LIKE <obj>] .

The type n a m e can be up to 30 characters and can use letters, digits, and under -scores. <ABAP-Type> could be a p r ede f ined e l emen ta ry data type, a n o t h e r local data type de f ined in the p rogram, o r a Dict ionary type. You can use the LIKE

136 Chapter 6 ABAP Types and Data Objects

s t a t emen t to re fer to a database table o r ABAP Dict ionaiy s t ructure , bu t it is rec-o m m e n d e d that y o u use TYPE as ABAP objec t -or ien ted p rog ramming ; y o u can use the LIKE s ta tement only of local a t t r ibutes o r SY fields.

The local data types are declared using the TYPES keyword :

TYPES: c h a r l TYPE C LENGTH 8 . numl TYPE N LENGTH 6 . packl TYPE P LENGTH 3 DECIMALS 2 .

The complex types consist of a sequence of e l e m e n t a i y data types, complex data types, o r re fe rence types. You can also use ABAP Dict ionary objects such as data e lements , s t ructures , tables, and c o m p o n e n t s of s t ruc tures o r tables to de f ine the individual c o m p o n e n t o f the complex type.

Complex data types consist of s t ruc ture types and table types. Structure data types can be m a d e up of c o m p o n e n t s of any data types. The c o m p o n e n t s of the s t ruc ture data type can be a s equence o f related e l e m e n t a i y data types, complex data types, o r re fe rence data types. Depend ing on the type of c o m p o n e n t , the s t ruc ture type can be a flat s t ructure , nes ted s t ructure , o r d e e p nes ted s t ruc ture .

A flat s t ruc ture type conta ins f ixed-length c o m p o n e n t s , whe rea s a nested struc-tu re type conta ins a subs t ruc ture wi th in the s t ruc ture type; that is, c o m p o n e n t s which are not e lementary . A flat s t ruc ture can also be nes ted . A s t ruc ture type is called d e e p w h e n it conta ins an internal table o r variable-length c o m p o n e n t . The individual c o m p o n e n t s o f the s t ruc ture a re accessed wi th in the p rog ram by using a h y p h e n b e t w e e n the s t ruc ture n a m e a n d the c o m p o n e n t .

Following is t he syntax to de f ine the s t ruc ture data type in an ABAP program:

TYPES: 8EGIN OF a d d r e s s _ t y . f i r s t n a m e TYPE C LENGTH 20. l as tname TYPE C LENGTH 20. s t r e e t TYPE C LENGTH 30. c i t y TYPE C LENGTH 20.

END OF a d d r e s s _ t y .

You can use the above TYPES def in i t ion to declare the data objec t and then access the individual c o m p o n e n t in the p rogram to assign value. The fol lowing example code displays the syntax to access individual c o m p o n e n t s of the s t ruc ture data type in the p rogram:

DATA: addr s TYPE a d d r e s s _ t y . a d d r s - f i r s t n a m e - ' B o b ' , a d d r s - l a s t n a m e - ' J o h n s o n '

Key Concepts Refresher Chapter 6 137

a d d r s - s t r e e t - * 123 Adam L a n e ' . WRITE: a d d r s - f 1 r s t n a m e . a d d r s - l a s t n a m e . a d d r s - s t r e e t .

Following is an example code to define a nested structure type locally in an ABAP program:

TYPES: 8EGIN OF s t r u l .

f l d l TYPE I . BEGIN OF s t r u 2 .

f l d 2 TYPE C. f l d 3 TYPE I .

END OF s t r u 2 . END o f S t r u l .

TYPES: BEGIN o f a d d r l .

s t r e e t _ n o TYPE C LENGTH 3 0 . C i t y TYPE C LENGTH 2 0 .

s t a t e TYPE C LENGTH 3 0 . c o u n t r y TYPE C LENGTH 2 0 .

END o f a d d r l . TYPES: BEGIN OF c o n t a c t _ d e t .

f i r s t n a m e TYPE C LENGTH 2 0 . l a s t n a m e TYPE C LENGTH 2 0 . a d d r e s s TYPE a d d r l . p h o n e n o TYPE C l e n g t h 1 5 .

END OF c o n t a c t . d e t .

Table types consist of any number of lines of the same data type, and are used to describe internal tables. This topic is discussed in more detail in Chapter 7. Inter-nal Table Definition and Use. The table line can have an elementaiy data type or a complex data type. The local table for the ABAP program is called an internal table. We use the following syntax to create a table type:

TYPES: < T a b l e _ t y p e > TYPE < t a b l e k i n d > OF < 1 1 n e t y p e > [WITH < k e y > ] .

The TYPES statement can define a table type with access type < t a b l e k i n d > , line type < l i n e t y p e > , and key <key>. The < l i n e t y p e > is a known data type in the program. The following is an example code for table type definition:

TYPES: BEGIN o f f l i g h t i n f o .

c a r r l d TYPE s _ c a r r _ 1 d . c a r r n a m e TYPE s _ c a r r n a m e . c o n n i d TYPE s _ c o n n _ i d . f l d a t e TYPE s y - d a t u m . f l t i m e TYPE s _ f l t i m e ,

138 Chapter 6 ABAP Types and Data Objects

END OF f 1 i g h t i n f o . TYPES: 1 t a b TYPE SORTED TABLE OF f l i g h t i n f o

WITH UNIQUE KEY c a r r i d .

The above p rog ram s t a t emen t s de f ine t he table type i t a b wi th a line type of s t ruc ture f 1 i g h t i n f o a n d u n i q u e key of s t ruc ture c o m p o n e n t NAME. Please re fer to Chapter 7. Internal Table Def in i t ion and Use. for detai led in fo rmat ion abou t internal tables and the i r use in ABAP programs .

Global Data Types

Data types de f ined in the ABAP Dict ionary a re called global data types and are available sys tem-wide . Global data types consist of data e lements , s t ructures , and table types:

• Data e l emen t s re fer to the p rede f ined Dict ionary types which largely corre-s p o n d to t he p rede f ined ABAP types.

• Structures consist of sequences o f data e l emen t s o r even a n o t h e r s t ruc ture data type as o n e o f the c o m p o n e n t s .

• Table types are internal tables de f ined in t he ABAP Dictionary.

You can use exist ing ABAP Dict ionary data types o r create n e w data types in t he ABAP Dictionary. The fol lowing ABAP Dict ionaiy objects are used to de f ine the global data types:

• Database tables o r v iews are used to de f ine a flat s t ruc ture data type. The indi-vidual fields of the da tabase table a re the c o m p o n e n t s of the flat s t ruc ture data type. You can also de f ine a type using the individual c o m p o n e n t s o r fields o f the database table o r v iew. The syntax for the type declarat ion wi th the data-base table is:

TYPES: <db_type> TYPE <dbtab>. TYPES: mara_ty TYPE mara. TYPES: <t> TYPE <bdtab>-<c>. TYPES: ma tn r_ ty TYPE mara-matnr .

You can also use the da tabase table to de f ine data objects o r a work area wi th y o u r p rogram. The syntax to de f ine the data objec t wi th re fe rence to a data-base table is:

DATA : mara_ l s TYPE mara.

• You can def ine e l e m e n t a i y types, r e fe rence types, and complex types in the ABAP Dict ionaiy. Data e lements , table types, and s t ruc tures are t he ABAP

Key Concepts Refresher Chapter 6 139

Dict ionaiy global data types . You can refer to these data types in the p rog ram to def ine a local data type o r data object . The data e l emen t def ines an individ-ual field in the ABAP Dict ionaiy o r an e l emen ta ry data objec t or variable in y o u r p rogram.

Data e l emen t s a l low y o u to de f ine e lementa ry types, r e fe rence types, and complex type Dict ionary objects . Data e l emen t s al low y o u to de f ine complex types if they are used to type o n o n e of t he c o m p o n e n t s of t he complex type. O n their o w n they are e l emen ta ry types that a re visible globally. You can def ine data types locally by refer r ing to a data e l emen t in the ABAP program as fol lows:

TYPES: <t> TYPE <data e lement> . TYPES: s i t e . t y TYPE w e r k s . d . DATA : w a _ s i t e TYPE s i t e _ t y .

You can de f ine s t ruc ture types in the ABAP Dict ionaiy. The s t ruc ture type can be a flat s t ructure , d e e p s t ructure , o r nes ted s t ruc ture . You can refer to the ABAP Dict ionaiy s t ruc ture to declare a local s t ruc ture data type. A local com-plex data type wi th re ference to the global s t ruc ture is declared as fol lows:

TYPES: <t> TYPE < s t r u c t u r e > . TYPES: marc_ty TYPE dmarc. DATA: wa_marc TYPE marc_ ty .

You can also de f ine a local s t ruc ture o r a work area direct ly using the follow-ing syntax:

DATA: wa_marc TYPE dmarc

Table types is are an internal table templa te s tored in t he ABAP Dictionary. You specify the line type, access type, and key dur ing the creat ion of the table type in the ABAP Dictionary. For m o r e about the table type refer to Chapter 7. Internal Table Defini t ion and Use. The syntax to de f ine an internal table locally in the ABAP program with re ference to the table type is as follows: DATA: MARMJt TYPE marm_ty.

Type g roups are ABAP Dict ionary types w h e r e b y y o u can s tore any type def-ini t ion globally in the ABAP Dict ionary and use t h e m in y o u r p rogram locally. You have to declare the type g r o u p in the p rog ram be fo re y o u can refer to the data types in the type g roup . The syntax to declare type g roups in ABAP pro-gram is as fol lows: TYPE-P001S: <type poo l s> .

140 Chapter 6 ABAP Types and Data Objects

The fol lowing example displays the syntax to use the data type s l i s _ t _

f 1 e 1 d c a t _ a l v def ined in a type g r o u p . To de f ine a data objec t tha t refers to

a data type de f ined in the type g r o u p Si IS. y o u have to declare the type g r o u p

in ABAP p rog ram with the syntax TYPE-POOLS: SL1S and then de f ine the data

object wi th re fe rence to the data type de f ined in the type g roup .

TYPE POOLS: SLIS. DATA: f i e l d c a t TYPE s i i s _ t _ f i e l d c a t _ a l v .

The type s i i s _ t _ f i e l d c a t _ a 1 v is a de f i ned as a global data type in the TYPE GROUP SLIS.

Data Object Visibility

The visibility o f the data object is d e p e n d e n t on the context o f the variable. The fol lowing rules apply for data objects declared locally wi th in the p rogram:

• If the variable is de f ined wi th a DATA s ta tement wi th in a subrou t ine b e t w e e n FORM and ENDFORM. then it 's a local data fo r the subrou t ine . Hence, the data is no t visible and is no t accessible outs ide the subrou t ine .

• If the data objec t is declared wi th in a func t ion modu le , then it is a local data objec t for the func t ion modu le . The func t ion g r o u p itself may have variables, and these will be in the Top Include o f the func t ion g r o u p and will be acces-sible to all func t ion modu le s wi th in the g roup .

• Data objects declared at t he start o f the p rogram with t he DATA. PARAMETERS, o r SELECT-OPT IONS keywords are visible to the en t i re p rog ram and are global data objects .

• If t he data objec t is declared b e t w e e n the MODULE a n d ENDMODULE of a PAI o r PBO m o d u l e for a screen, then it is visible to the en t i r e p rog ram. Similarly, any data objects declared in an ABAP event block, for example START-OF -SELECTION, are visible to the en t i r e p rogram.

• Data objects de f ined wi th the TABLES s t a t emen t are visible to the en t i re pro-gram even if the TABLES s ta tement is declared in an ABAP subrou t ine .

Important Terminology Chapter 6

Caution

Be aware of the visibility declared locally within the program:

• Data objects declared between KODUL F and ENDHODULF are visible to the entire program.

• Data objects declared in an ABAP event block are visible to the entire program. »• Data objects declared with the TABLES statement are visible to the entire pro-

gram even if the TABLES statement appears in a subroutine within the FORM and ENDFORM.

Important Terminology

You should n o w unde r s t and the d i f fe rence b e t w e e n the data type and data object and the i r use in ABAP programs .

Data types are used for the def in i t ion of data objects . They def ine the technical a t t r ibutes o f the data object , h o w the data objec t is s tored in m e m o i y , and wha t opera t ions a re possible on the data object based o n the data type. You can use bo th p rede f ined data types and global data types to de f ine technical a t t r ibutes of the data object . D e p e n d i n g o n t he data type, y o u might have to de f ine t he length and the n u m b e r o f decimal places to fully de f ine the technical a t t r ibu te of t he data object . For a data object de f ined wi th re fe rence to the ABAP Dict ionaiy object , the technical a t t r ibutes such as length, n u m b e r of decimal places, and the data type are der ived f rom ABAP Dict ionaiy objects .

Data objects are t e m p o r a r y s torage in the p rog ram and occupy m e m o i y to s tore the data. Data objects conta in data for the p rogram, and they exist for the dura-t ion o f the p rog ram.

% Practice Questions

The practice ques t ions be low will help y o u evaluate y o u r u n d e r s t a n d i n g of the topic. The ques t ions s h o w n are similar in na tu re to those f o u n d on the certifica-t ion examina t ion , bu t whe rea s n o n e of these ques t ions will be f o u n d o n the exam itself, t hey a l low y o u to review y o u r knowledge of the subject . Select the correct answers and then check the comple teness of y o u r answers in the follow-ing solut ion sect ion. R e m e m b e r tha t y o u must select all correct answers and only correct answers to receive credit for the ques t ion .

142 Chapter 6 ABAP Types and Data Objects

1. Data types s tore data and occupy m e m o i y .

• A. True

• B. False

2. A data objec t is concrete ly de f ined by means of data type and occupies m e m -oiy . It conta ins data wi th which ABAP programs work at run t ime .

• A. True

• B. False

3. The p rede f ined data types a re def ined locally in the ABAP program.

• A. True

• B. False

4. The defaul t length of the type C data type is:

• A. 1

• B. 10

• C. 1 - 6 5 5 3 5

5. If data objects of type I a re being used to s tore the result of a calculation, the decimals will be t runca ted .

• A. True

• B. False

6. The defaul t length of the type P data type is:

• A. 8

• B. 1

• C. 1 - 1 6

7. A variable-length s t ruc ture is called:

• A. Nested s t ruc ture

• B. Deep s t ruc ture

• C. Flat s t ruc ture

Practice Questions Chapter 6

8. Local data objccts can be defined using ABAP Dictionary types.

• A. True

• B. False

9. Global data types defined in SAP systems are:

• A. Data defined in the program that is visible to the all the routines/state-ments within the ABAP program

• B. ABAP Dictionaiy types

• C. Date types defined in the program using ABAP Dictionary types

10. Which of the following are incorrect statements:

• A. TYPES: carrid_ty LIKE spf l i -s -car r_ id .

• B. TYPES: werks TYPE C LENGTH 4.

• C. TYPES: date.ty TYPE 0 LENGTH 10.

• D. TYPES: Str TYPE STRING LENGTH 20.

11. What is the result of the following arithmetic operation.

DATA: int TYPE I . Int - 5 * ( 3 / 10 ) .

• A. 1

• B. 2

• C. 1.5

• D.O

12. What is the result of the following arithmetic operation:

DATA : 1nt TYPE I int - 5 / 10.

• A. 1

• B. .5

• C . O

144 Chapter 6 ABAP Types and Data Objects

Practice Quest ion Answers and Explanations

1. Cor rec t a n s w e r : B

A da ta t y p e is j u s t t h e de sc r ip t i on a n d d o e s n o t o c c u p y m e m o r y .

2 . Cor rec t a n s w e r : A

A da ta ob jec t is an in s t ance o f t h e da ta t y p e a n d d o e s o c c u p y m e m o i y . Data

t y p e s d e f i n e t h e technica l a t t r i b u t e s of t h e da ta o b j e c t .

3. Cor rec t a n s w e r : B

P r e d e f i n e d da t a t y p e s a re p r o v i d e d b y t h e ABAP r u n t i m e e n v i r o n m e n t a n d

a r e ava i lab le s y s t e m - w i d e .

4 . Cor rec t a n s w e r : A

T h e d e f a u l t l eng th o f t h e cha rac t e r da t a t y p e C is o n e . If y o u w a n t the da ta

o b j e c t t o b e m o r e t h e n o n e cha rac t e r , t h e n y o u h a v e to spec i fy t h e l eng th .

TYPES: v a r l TYPE C. " i s a c h a r a c t e r d a t a t y p e "of l e n g t h 1 .

TYPES: v a r 2 ( 1 0 ) TYPE C. " i s a c h a r a c t e r d a t a t y p e "of l e n g t h 10.

TYPES: v a r 2 TYPE C LENGTH 15. " i s a c h a r a c t e r d a t a t y p e "of l e n g t h 15.

5. Cor rec t a n s w e r : B

T h e t y p e i da t a o b j e c t s r o u n d the va lue a n d d o n o t t r u n c a t e .

OATA: i n t l TYPE I . i n t 2 TYPE I . i n t 3 TYPE I .

i n t l - 4 / 1 0 . " v a l u e of 1 n t l - 0 i n t 2 - 5 / 1 0 " v a l u e of i n t 2 - 1 i n t 3 - 1 6 / 1 0 . " v a l u e on i n t 3 - 2

6 . Cor rec t a n s w e r : A

T h e d e f a u l t l eng th o f t h e t y p e P da t a t y p e is e igh t . If y o u w a n t to h a v e m o r e

o r less t h a n e ight , t h e n y o u can spec i fy t h e l eng th w i t h the l eng th k e y w o r d

o r in p a r e n t h e s e s a f t e r t h e n a m e o f t h e da t a o b j e c t o r da t a t ype .

7. Cor rec t a n s w e r : B

T h e va r i ab le - l eng th s t r u c t u r e is cal led a d e e p s t r u c t u r e . A n y s t r u c t u r e tha t h a s a va r iab le - leng th c o m p o n e n t is called a d e e p s t r u c t u r e . For e x a m p l e , a s t ruc-tu re w i t h an in te rna l table as o n e o f its c o m p o n e n t s is a d e e p s t ruc tu re , as is a s t r u c t u r e w i t h a c o m p o n e n t o f t y p e STRING.

Take Away Chapter 6

8. Correct answer : A

Local data objects can be def ined using ABAP Dict ionary objects .

9. Correct answer : B

Global data types a re ABAP Dict ionary objects , like data e lements . Dictio-nary s t ructures , tables, table types, and type pools.

10. Correct answers : C, D

Data type D is a fixed-length p rede f ined data type a n d docs not r equ i re a length specif icat ion. The data type STRING is a dynamic- length data type and docs no t requi re a length specif icat ion.

11. Correct answer : D

The correct a n s w e r is 0:

i n t l - 5 * ( 3 / 1 0 ) . i n t l - 5 * ( 0 ) "because 3/10 - 0 . due t o I n t e g e r rounding i n t l - 0.

12. Correct answer : A

The correct answer is 1 because the integer data type I r o u n d s the n u m b e r du r ing the ar i thmet ic ope ra t ion .

Take Away

You should unde r s t and the ABAP data types and data objects . You should under -stand t he mean ing of ABAP predef ined s tandard data types, local data types, and global data types. It is impor t an t that y o u k n o w the d i f fe rences b e t w e e n local data types and global data types, and b e t w e e n flat s t ructures , nes ted s t ructures , and d e e p s t ructures . All this will help y o u wr i te m o r e efficient code. Finally, y o u should unde r s t and the scope and validity of the data objects wi th in the ABAP p rog ram.

Refresher

Table 6 .3 repeats the key concepts of this chap te r in shor t f o r m .

160 Chapter 6 ABAP Types and Data Objects

Key C o n c e p t Def in i t ion

ABAP da ta types Predefined e lementary da ta types provided by the ABAP runt -ime env i ronmen t a re also called ABAP da ta types.

Data type A da t a type is a descript ion and is no t al located any memory .

Data types a re used t o de f ine da ta objec ts .

Data objec ts Data objec ts a re instances of t he da ta types and occupy m e m -ory. They s tore da ta temporari ly tha t is used in t he program.

Local da ta type Local da ta types are def ined using t he TYPES s t a t emen t in t he ABAP program. They can refer to predef ined da ta types or glo-bal da ta types f rom the ABAP Dictionary.

Global da ta types Global da ta types are def ined in t he ABAP Dictionary.

Flat s t ructures . Flat s t ructures conta in f ixed-length c o m p o n e n t s . A s tructure is nes ted structures. nes ted if it conta ins ano the r s t ructure as its c o m p o n e n t . A and d e e p s t ructures s t ructure is called a d e e p s t ructure if it contains an internal

tab le or a variable-length c o m p o n e n t .

Table 6.3 Key Concept Refresher

S u m m a r y

In this chapter you have learned about ABAP data types and data objects, includ-ing local data types, predefined data type, global data types, and their uses in pro-grams. You have also learned the syntax to define data objects using the ABAP Dictionaiy data type and local and predefined data types. This knowledge wi l l al low you to easily pass this topic on the certification examination.

Internal Table Definition and Use

Techniques You'll Master:

• Def ine internal tables

• Categorize d i f fe ren t types of internal tables and the i r uses

• Def ine internal table type and internal table data objec t in the p rog ram

• Unders tand ope ra t ions o n internal tables

• Def ine ABAP Dict ionaiy table types and the syntax to use t h e m in p rograms

148 Chapter 7 Internal Table Definition and Use

Internal tables are p rogram variables and s tore mul t ip le identical s t ruc tured data records in the ABAP run t ime m e m o r y . They arc used to process large data sets in a s t ructured m a n n e r . They are beneficial for improv ing data processing in the p rog ram if used correctly.

In this chap te r y o u will learn abou t the var ious e l emen t s o f internal tables. You will learn abou t var ious kind of internal tables and the syntax to create and use t h e m in programs . You will learn to de f ine internal tables, access internal table records, modi fy , delete, and p e r f o r m var ious o the r ope ra t ions on the internal table records in p rograms .

Real-World Scenario

Imagine y o u have to wr i te an applicat ion that reads data f r o m a n u m b e r o f SAP da tabase tables and p e r f o r m s s o m e compar i sons and calculations a n d displays the result . For example , y o u have to display the details o f the open purchase o r d e r in the SAP system along wi th the material details such as descr ip t ion and material type and v e n d o r details.

To wr i te such an applicat ion, it wou ld be a good idea to read all o p e n pur-chase o rde r s f rom the database and s tore the purchase o rde r details in an internal tabic and then loop th rough the internal table, read the material and v e n d o r in fo rmat ion for each purchase o rder , and display the result on t he screen. You may also w a n t to s tore t he material and v e n d o r details in an internal table so that y o u d o n ' t have to read the details f rom the data-base table again if the s a m e material and v e n d o r exists in m o r e than o n e purchase o rde r .

To wr i te this applicat ion, y o u need to unde r s t and the concept of internal tables, including h o w to s tore and access t he data f r o m the internal table. You also need to unde r s t and t he var ious types of in ternal tables in o rde r to wr i te an eff icient p rogram.

Objectives of this Portion of the Test

The object ive o f this por t ion of the cert if ication exam is to ver i fy y o u r knowledge abou t the concept of in ternal tables and the i r use in ABAP p rog rams or applica-t ions. You are expected to unde r s t and h o w to de f ine the internal table, access the internal table, and k n o w abou t the var ious types of internal table.

Key Concepts Refresher Chapter 6 149

The exam will test y o u r knowledge abou t the benef i t o f using d i f fe ren t types of in ternal tables in an appl icat ion and abou t the syntax used to de f ine the internal table, create the internal table, and access d i f fe ren t types of the internal table.

Key C o n c e p t s Refresher

An internal table is a p rog ram variable used to s tore mul t ip le identically struc-tured records in the m e m o i y of an appl icat ion. This chap te r provides a comple t e descr ipt ion o f h o w to work wi th internal tables. It descr ibes the use of in ternal tables, def in i t ion of internal tables, var ious ope ra t ions on them, a n d d i f fe ren t kinds of tables. Af te r comple t ing this chapter y o u should be able to do the fol-lowing:

• Def ine d i f fe ren t types of in ternal tables

• Popula te an internal table

• Access the data in an internal table

• Unders tand the p e r f o r m a n c e cons idera t ions dur ing table def in i t ion a n d pro-cessing

Internal Table Definition and Use

Internal tables are s t ruc tured data objects and are de f ined in the ABAP p rog ram locally. They al low y o u to s tore variable a m o u n t s o f s t ruc tured data records in m e m o i y . They s tore any n u m b e r of identical s t ruc tured records wi th in the ABAP m e m o r y . An internal table is like an array f o u n d in o the r p r o g r a m m i n g lan-guages. Internal tables a re dynamic data objects and save the p r o g r a m m e r the task of d y n a m i c m e m o r y m a n a g e m e n t . The ABAP r u n t i m e sys tem dynamical ly manages the size of an internal table. The m a x i m u m n u m b e r of data records in an internal table is restricted u p o n installation o f the h a r d w a r e a n d the opera t ing system. ABAP r u n t i m e dynamical ly manages the size o f the internal table. As a deve loper y o u d o not have to d o any work concern ing m e m o i y m a n a g e m e n t .

Fol lowing are s o m e of the features of an internal table:

• It is used for processing large data sets in a s t ructured m a n n e r . Typical use of in ternal tables could be to read and s tore data f r o m da tabase tables o r a sequent ia l file and then fo rmat t ing the data to be displayed on screen o r

150 Chapter 7 Internal Table Definition and Use

repor t ou tpu t . You can also s tore data in an internal table to pass it to a func-tion modu le , m e t h o d , o r sub rou t ine for fu r the r processing.

• Processing a large vo lume of data in an internal table is beneficial for perfor-mance improvemen t , if used correctly in the p rogram, compared to accessing the data sequential ly f r o m the da tabase table. Processing an internal table is fast because the data is s tored in the m e m o i y .

• Internal tables a re de f ined w h e n y o u start the p rogram, and data is popula ted , modi f ied , o r processed whi le y o u are processing the p rogram. The data defi-ni t ion and the con ten t exist only for the r u n t i m e of the p rogram. You lose the table con ten t once the p rogram ends .

• Internal tables can conta in c o m p o n e n t s , co lumns , a n d fields der ived f r o m dif-ferent da tabase tables, o r y o u can de f ine an internal table based o n local vari-ables o r s t ruc ture def in i t ions in y o u r p rogram. You can include fields f r o m several database tables as fields in y o u r internal tables i f y o u plan on work ing wi th data f rom mult iple da tabase tables, for example , if y o u w a n t to display the con ten t of those tables in repor ts .

• An internal table has a table body, and the table b o d y conta ins the identical s t ruc tured data records . Individual data records in an internal table a re called a table row o r table entry. Individual c o m p o n e n t s of a table r o w are called the columns o r fields. The r o w type of an internal table is specif ied th rough any data type and descr ibes the r o w s t ruc ture of the table entr ies . Each table r o w has the same s t ruc ture .

Figure 7.1 displays the individual c o m p o n e n t s of an internal table.

carrid connid cityfrom cityto — W o r k Area II II — W o r k Area

- Internal Table

- Table Row

- Internal Table

- Table Row

- Internal Table

- Table Row

- Internal Table

- Table Row

- Internal Table

- Table Row

- Internal Table

- Table Row

- Internal Table

- Table Row

- Internal Table

- Table Row

1 T Table Column or Fields

I

Figure 7.1 Individual Elements of an Internal Table

Listing 7.1 displays the internal table def in i t ion in an ABAP program. The sample code refers to the ABAP Dict ionaiy data type used in flight table SPFLI to de f ine

Key Concepts Refresher Chapter 6 151

the s t ruc ture data type (line type). The local data type is used to de f ine an internal table data object . The internal table data objec t a n d the work area are de f ined using the OATA s ta t ement .

TYPES: BEGIN OF l i n e _ t y p e . a i r l i n e _ c o d e TYPE s _ c a r r _ 1 d , connec t ion_no TYPE s_conn_ id . f r o m _ c i t y TYPE s _ f r o m _ c i t . t o _ c 1 t y TYPE s _ t o _ c i t y .

ENO OF l i n e . t y p e OATA: i t a b TYPE STANDARD TABLE OF l i n e _ t y p e . OATA: wa TYPE 11ne_type .

Listing 7.1 Internal Table Definition in an ABAP Program

The data type of an internal table is specif ied by the fol lowing at t r ibutes:

• Line t y p e The line type descr ibes the r o w s t ruc ture of the table entr ies, and def ines t he a t t r ibutes of the individual c o m p o n e n t s of the table row. The l ine type is gen-erally de f ined as s t ruc ture type, bu t a lmost any data type can be used for the l ine type def in i t ion .

• Table key The table key consists of key fields and the i r order , ident i fying a table r o w similar to the key of the da tabase table. An internal table can have a u n i q u e key o r a non -un ique key. An internal table wi th u n i q u e key cannot conta in duplicate entr ies . Entries in the table mus t d i f fe r by at least o n e key field. The n o n - u n i q u e key means the table can have dupl icate entr ies , and this is per-fectly legit imate because this is an internal table, ra ther than a da tabase table.

Fu r the rmore , the table can have a s tandard key and user -def ined key. If t he l ine type of an internal table is a s t ructure , then the defaul t s tandard key consists of all n o n - n u m e r i c fields of the s t ruc ture . A user -def ined key is any subset of the s t ruc ture fields that a re not re fe rences o r themselves an internal table.

You can de f ine an internal table wi th a heade r l ine o r wi thou t a heade r line. Header lines arc the old way of de f in ing internal tables and are still valid, a l though i f y o u are de f in ing an internal table, it is r e c o m m e n d e d that y o u def ine one wi th a separa te work area. The work area is a n e w s tandard o f de f in ing t he work area of the internal table and is explicitly de f ined in the p rogram. The heade r line for an internal table is the same n a m e as the internal table, w h e r e a s

166 Chapter 7 Internal Table Definition and Use

t h e w o r k a r ea has d i f f e r e n t n a m e . In te rna l tab les w i t h h e a d e r l ine d e f i n i t i o n s a re

no t s u p p o r t e d in o b j e c t - o r i e n t e d ABAP p r o g r a m m i n g .

T h e h e a d e r l ine o r t h e w o r k area is u s e d to t r a n s f e r da ta r e c o r d s f r o m t h e tab le f o r f u r t h e r p roces s ing . You p o p u l a t e t h e h e a d e r l ine o r t h e w o r k a r ea w i t h the da t a a n d t h e n t r a n s f e r t h e r e c o r d to c r ea t e t h e tab le e n t r y . Similar ly, y o u read t h e da t a f r o m an i n t e rna l t ab le i n to t h e h e a d e r l ine o r w o r k area f o r p r o c e s s i n g an ex i s t ing table r o w . An in te rna l t ab le d e f i n i t i o n w i t h a s e p a r a t e w o r k a r ea can have a l ine t y p e tha t is i tself a d e e p s t ruc tu re , w h e r e a s an i n t e rna l t ab le w i t h a h e a d e r l ine can o n l y h a v e a l ine t y p e tha t is a f lat s t r u c t u r e .

In te rna l tab les can b e o f d i f f e r e n t types d e p e n d i n g o n t h e w a y t h e y access t h e

ind iv idua l en t r i e s in t h e t ab le . T h e r e a re t h r e e t y p e s o f in te rna l tables :

• S t a n d a r d t a b l e s

W i t h s t a n d a r d tables , r o w n u m b e r i n g ( index) is m a i n t a i n e d in te rna l ly , a n d

they can b e accessed us ing t h e key o r a n i n d e x . This t y p e o f t ab le c a n n o t have

a u n i q u e key a n d can t h e r e f o r e h a v e d u p l i c a t e en t r i e s . T h e r e s p o n s e t i m e o f

a s t a n d a r d tab le is b e t t e r if accessed w i t h i ndex . Key access f o r t h e s t a n d a r d

t ab l e is n o t o p t i m i z e d b e c a u s e s equen t i a l sea rch across all r o w s is ca r r i ed o u t .

A s t a n d a r d tab le is dec la red us ing t h e s t a n d a r d t a b l e a d d i t i o n . T h e tab le

i n d e x i n g is m a n a g e d in t e rna l ly . W h e n a r e c o r d is d e l e t e d o r i n se r t ed t h e

i n d e x i n g is r e o r g a n i z e d . You can a d d a n e w r e c o r d to a s t a n d a r d tab le by

us ing t h e a p p e n d s t a t e m e n t .

• S o r t e d t a b l e s

Sor ted t ab les a re d e f i n e d us ing t h e s o r t e d t a b l e a d d i t i o n . Table r e c o r d s a re s t o r e d in s o r t e d o r d e r a c c o r d i n g to t h e tab le keys, a n d t h e tab le is so r t ed in a s c e n d i n g o r d e r b y de fau l t . T h e index o f t h e s o r t e d in te rna l t ab le is ma in -t a i n e d in te rna l ly .

A s o r t e d tab le can h a v e a u n i q u e o r n o n - u n i q u e key . You s i m p l y s t a te th is w h e n d e f i n i n g t h e in te rna l table . T h e s o r t e d i n t e rna l t ab le can b e accessed w i t h the tab le key o r i ndex . T h e s y s t e m a lways uses t h e b i n a i y search algo-r i t h m for t h e so r t ed table w h e n y o u access it u s ing t h e tab le key (or pa r t o f t h e k e y f r o m lef t t o r ight) . You fill a s o r t e d tab le u s ing t h e i n s e r t s t a t e m e n t . The tab le en t r i e s a r e i n se r t ed a c c o r d i n g to t h e d e f i n e d sor t s e q u e n c e . Both s o r t e d a n d s t a n d a r d tab les a re also called index tables b e c a u s e t h e y can b e accessed us ing an index .

• H a s h e d t a b l e s

Hashed tables a re d e f i n e d us ing the h a s h e d t a b l e a d d i t i o n . T h e y d o no t h a v e

Key Concepts Refresher Chapter 6 7

indexes, and hence they cannot be accessed using an index; only key access can be used . The sequence of the entr ies is managed by hash a lgor i thm. A hash table mus t have a u n i q u e key because it can only be accessed using the key. Hashed internal tables are ideal for storing large n u m b e r s of entries, w h e r e y o u need to read those entr ies using the key, because the response t ime is not de-penden t upon the n u m b e r of entries. The hash algori thm is used to find the ap-propr ia te record. Standard tables and sorted tables can be accessed with the in-dex o r key, bu t hashed tables can only be accessed wi th a un ique key. Key ac-cess wi th the s tandard table is a linear search; for the sorted table key access is a b inary search, and for the hashed table the key access uses the hash algori thm.

As already stated, s tandard tables and sor ted tables can be accessed using the index o r using the key, bu t hashed tables can on ly be accessed wi th the key. Key access to a s tandard table results in a sequent ia l search; for a sor ted table key access results in a b inary search, a n d for a hashed table key access uses the hash a lgor i thm to find the appropr ia t e record .

Table 7.1 displays the possible table access and the characterist ics fo r the differ-ent kinds of table.

Index Tables Hashed Table

Table Kind Standard Table Sorted Table Hashed Table

Index access Index possible Index possible Not possible

Key access Can be accessed Can be accessed Can be accessed

Uniqueness of key Non-unique Unique and non-unique Unique

Access Primarily using index

Should be primarily accessed using key. not index

Only using key

Table 7.1 Access Options for Different Kinds of Table

Defining ABAP Internal tables

Internal tables a re data objects and are de f ined using t he DATA s t a t emen t . To fully de f ine an internal table, y o u mus t de f ine the line type, key, a n d table type. Line types can be de f ined locally in the p rog ram or globally as a data type in the ABAP

168 Chapter 7 Internal Table Definition and Use

Dic t ionary . You can d e f i n e i n t e rna l t ab les locally o r d e f i n e t h e m in t h e ABAP Dic-

t i ona ry as t ab le t ype .

You can d e f i n e g lobal t ab le t y p e in t h e ABAP Dic t iona ry o r u s e t h e ex i s t ing o n e ( p r e d e f i n e d b y SAP) in y o u r p r o g r a m . Global t ab le t y p e s a r e valid s y s t e m - w i d e a n d can b e u s e d in a n y p r o g r a m in t h e s y s t e m . Table t y p e d e s c r i b e s t h e s t r u c t u r e a n d t h e a t t r i b u t e o f an i n t e rna l table .

You can r e f e r e n c e a t ab le t y p e d e f i n e d in t h e ABAP Dic t iona ry in y o u r p r o g r a m us ing t h e f o l l o w i n g syn tax :

OATA m a r a _ l t TYPE m a r a _ t a b .

This syn tax c rea tes an in te rna l t ab le m a r a _ l t w i t h t h e s t r u c t u r e a n d a t t r i b u t e

d e f i n e d fo r t ab le t y p e m a r a _ t a b in t h e ABAP Dic t iona iy .

T h e tab le t y p e is an ABAP Dic t iona ry da ta t y p e a n d is d e f i n e d by spec i fy ing t h e l ine type , access, a n d key o f t h e i n t e rna l table . T h e l ine t y p e d e f i n e s t h e s t r u c t u r e o f a n i n t e rna l table . Line t y p e can b e a flat s t r u c t u r e , d e e p s t r u c t u r e , o r n e s t e d s t r u c t u r e . Line t y p e d e f i n e s the r o w . a n d t h e ind iv idua l c o m p o n e n t o f t h e l ine t y p e d e f i n e s t h e c o l u m n of t h e i n t e rna l table .

F igure 7 .2 d i sp lays t h e l ine t y p e f o r t h e ABAP D i c t i o n a i y tab le type . In F igure

7 .2 , ABAP Dic t iona ry tab le MARM is u s e d to d e f i n e the l ine t y p e f o r t h e tab le t y p e

marm_tab. You can u s e an ABAP D i c t i o n a i y tab le o r s t r u c t u r e to d e f i n e l ine t ype .

Dictionary: Display Table Type y <8 o'r o" 11 O HerarctyOispty

( i S i O S S K KARH_TA8 ACtJVO

Short te« MARM Tab*

A t t n t a « lirw Tyt*' *-iOO»MOan and Acc«tt , Key

• LkWTtf * MARH

DataTyc* to ct Characters 0 Decimal Places M

Data Type

1003th 0 Decimal Ptxoc 0

Figure 7 2 Line Type Definition in ABAP Dictionary Table Type

Key Concepts Refresher Chapter 6 155

You can specify the access m o d e for the table type. Access m o d e def ines h o w to access the data in the internal table w h e n p e r f o r m i n g key ope ra t ions on the internal table such as READ TABLE, INSERT TABLE. MODI FY TABLE, and so on . Figure 7 .3 displays t he possible access m o d e for the table type.

I Dictionary: Display Table Type + y "ti & H • Hierarchy Osjtfay

Table Type HARM_TAB Acove Short tea MARM Taw® |

Attn betes , Line Type taiDakzaoon and Access Key

WiaiLineNjnOer 0

Access

Figure 7.3 Table Access Definition in ABAP Dictionary Table Type

You can have fo l lowing access m o d e s for the table type:

• S T A N D A R D T A B L E

The key access for the s tandard table uses a sequent ia l search, a n d perfor-m a n c e d e p e n d s on the n u m b e r o f entr ies in t he table.

• S O R T E D T A B L E

The internal table is s tored internal ly sor ted by key. You should a lways access the sor ted internal table by key. The key access for a sor ted internal table uses b inary search to access table records .

• H A S H E D T A B L E

The table is internal ly managed using hash procedures . All en t r ies in the table should have a u n i q u e key.

• I N D E X T A B L E

The table can be a s tandard o r sor ted table. Index access is a l lowed for index tables.

• N O T S P E C I F I E D

The table can be a s tandard table, a sor ted table, or a hash table. The valid ope ra t ions o n such a table are the intersect ion of t he valid opera t ions o n stan-

156 Chapter 7 Internal Table Definition and Use

dard , sor ted, and hash tables. You cannot access tables of this type wi th index opera t ions .

You can specify the table key and def ine the key ca tegoiy for table type. You have three op t ions to specify the key categoiy:

• U N I Q U E

With the UNIQUE key categoiy. the table can conta in records wi th u n i q u e keys.

• N O N - U N I Q U E

With the NON-UNIQUE key categoiy, the table can conta in records wi th dupli-cate keys.

• N O T S P E C I F I E D

The key categoiy NOT SPECIFIED def ines a gener ic table type. A gener ic table type does not de f ine all o f the a t t r ibutes of t he table type in the ABAP Dictio-naiy; it leaves s o m e of the a t t r ibu tes u n d e f i n e d .

Figure 7 .4 displays the var ious op t ions for the table key def in i t ions .

Dictionary: Display Table Type <ti ^ • o°o £ • Hierarchy Display

Table Type MARM_TAB Active

Start text MARM Table

Attributes , Line Type mtialzation and Access Key

Key definition Key category

• Non-unique

Not specified

H Key components

Name

Figure 7.4 Table Key Definition in ABAP Dictionary Table Type Definition

You can de f ine an internal table locally if y o u d o not use the table type de f ined in the ABAP Dict ionary o r if the o n e de f ined in the ABAP Dict ionary does not s a t i s f y y o u d e v e l o p m e n t r equ i r emen t . You can use the IYPES and DATA state-

Key Concepts Refresher Chapter 6 157

m e n t s to d e c l a r e a n i n t e rna l table . T h e l ine t y p e fo r t h e i n t e rna l t ab le is d e f i n e d

us ing t h e TYPES s t a t e m e n t , a n d t h e i n t e rna l t ab le da t a ob jec t is d e f i n e d us ing t h e

OATA s t a t e m e n t .

List ing 7 .2 , Listing 7 .3 , a n d List ing 7 .4 s h o w t h e syn tax to d e f i n e an in te rna l t ab le in t h e p r o g r a m . T h e e x a m p l e uses ABAP Dic t i ona ry da t a t y p e s such as m a t n r a n d werks to d e f i n e t h e l ine t y p e f o r t h e in te rna l t ab le s t r u c t u r e . T h e first s t a t e m e n t in List ing 7 . 4 uses t h e t ab le t y p e i t a b _ t y p e d e f i n e d in t h e p r o g r a m to d e f i n e t h e i n t e rna l t ab le 1 t a b _ l t , a n d in t h e s e c o n d s t a t e m e n t t h e i n t e rna l t ab le is d e f i n e d w i t h r e f e r e n c e to t h e l ine t y p e d e f i n e d in t h e p r o g r a m .

TYPES: BEGIN OF m a t _ t y p e . m a t e r i a l TYPE m a t n r . p l a n t TYPE w e r k s _ d . q t y TYPE P DECIMALS 2 .

ENO OF m a t _ t y p e . Listing 7.2 Line Type Definition for Internal Table

TYPES: 1 t a b _ t y p e TYPE STANDARO TABLE OF m a t _ t y p e WITH NON-UNIQUE KEY m a t e r i a l .

Listing 7.3 Standard Table Type Definition with Reference to Line Type

Defined Above

OATA: 1 t a b . l t TYPE i t a b . t y p e .

OATA: i t a b j t TYPE STANDARD TABLE OF m a t . t y p e .

Listing 7.4 Standard Internal Table Definition with Reference to Local Table Type Defined Above

T h e l ine t y p e can b e a local t y p e dec l a r a t i on o r a g lobal t y p e f r o m t h e ABAP Dic-t i o n a i y , such as a s t r u c t u r e , a d a t a b a s e tab le , o r da ta e l e m e n t s . Local t y p e s a re d e f i n e d in t h e ABAP p r o g r a m , a n d t h e dec la ra t ion is val id f o r that specif ic p ro -g r a m . For t h e local type , the table s t r u c t u r e is d e f i n e d us ing t h e TYPES s t a t e m e n t . In a local t y p e d e f i n i t i o n , y o u can d e f i n e an ind iv idua l c o m p o n e n t o f t h e t ab le r e c o r d s t r u c t u r e o r inc lude t h e ABAP D i c t i o n a i y s t r u c t u r e a l o n g w i t h y o u r local field d e c l a r a t i o n . An ABAP Dic t iona ry s t r u c t u r e is i nc luded in t h e t y p e d e f i n i t i o n by us ing t h e INCLUDL s t a t e m e n t .

Listing 7 .5 d i sp lays t h e syn tax to d e c l a r e an in te rna l t ab le l ine t y p e u s ing t h e ABAP D i c t i o n a i y s t r u c t u r e .

158 Chapter 7 Internal Table Definition and Use

TYPES: BEGIN OF ma t_ ty . INCLUDE STRUCTURE mara.

END OF ma t_ ty .

Listing 7.5 Line Type Definition with Reference to ABAP Dictionary Structure

An internal table line type can be a flat s t ructure , d e e p s t ructure , o r nes ted struc-ture . You mus t de f ine a separate work area to work wi th the internal table. List-ing 7 .6 displays the syntax to de f ine an internal table wi th re ference to the ABAP Dict ionary table. The line type of the internal table in this example co r r e sponds to the MARA structure , w h e r e MARA is an ABAP Dict ionaiy table.

OATA: i t a b j t TYPE STANOARO TABLE OF mara WITH NON-UNIOUE KEY m a t n r .

OATA: i t a b . w a LIKE LINE OF i t a b j t .

Listing 7.6 Internal Table Definition with Reference to ABAP Dictionary Table

+ Tip

The line type for an internal table with a header line must be a flat structure, whereas the line type for an internal table without a header line can be flat struc-ture, deep structure, or nested structure.

The STANDARD addi t ion is opt ional for the declarat ion of the s tandard table. I f y o u d o not p rov ide t he table type, the defaul t table type is a s tandard internal table. For a s tandard table, i f y o u d o not specify a key. t he sys tem automatical ly adopts a defau l t key as the table key. The defaul t key for a s tandard table consists of all of the non -numer i c fields, in the s equence in wh ich they appea r in the l ine type.

Following is the syntax to de f ine a s tandard table wi th a defaul t key:

OATA: i t a b TYPE TABLE OF mara.

The add i t ions INITIAL SIZE and WITH HEADER LINE are also possible for the data type o r data objec t declarat ion. The INITIAL SIZE <n> addi t ion enables the sys-tem to reserve the first block of m e m o i y for the internal table; any subsequen t m e m o i y r equ i r emen t is managed by the system dynamical ly .

The syntax to de f ine an internal table wi th initial size is as fol lows:

OATA: i t a b TYPE TABLE OF mara INITIAL SIZE 4 .

Key Concepts Refresher Chapter 6 159

ABAP r u n t i m e dynamical ly manages the m e m o i y if the initial size for the inter-nal table is no t specif ied dur ing the internal table def in i t ion . W h e n the initial size is full, the system makes twice as m u c h extra space available up to a limit o f 8KB. and the rea f t e r each subsequen t addi t ion is created wi th 12KB. It makes sense to specify the initial size on ly i f y o u are su re abou t the n u m b e r o f l ines in the inter-nal table. Otherwise , it is r e c o m m e n d e d that y o u leave ou t this addi t ion and let the sys tem manage the m e m o i y for internal tables.

Listing 7 .7 shows the syntax to de f ine a sor ted and a hashed internal table. In this example we have de f ined the l ine type for the internal table, table type, a n d sorted and hashed internal table data object .

TYPES: BEGIN OF l i n e . t y p e . m a t e r i a l TYPE m a t n r . p l a n t TYPE werks_d. po_numb TYPE e b e l n ,

ENO OF l i n e . t y p e . TYPES: i t abOl TYPE SORTED TABLE OF l i n e . t y p e

WITH UNIQUE KEY m a t e r i a l p l a n t . TYPES: i t a b 0 2 TYPE HASHED TABLE OF l l n e . t y p e

WITH UNIQUE KEY m a t e r i a l p l a n t . Listing 7.7 Syntax for Sorted and Hashed Table Types

Listing 7 .8 shows two possibilit ies to create a sor ted use the ABAP Dict ionaiy s t ruc ture o r table to de f ine in Listing 7.9 .

OATA: i t a b 0 1 . l t TYPE I t a b O l .

o r

OATA: i t a b O l J t TYPE SORTED TABLE OF l l n e . t y p e WITH UNIQUE KEY m a t e r i a l p l a n t .

Listing 7.8 Sorted Internal Table Data Objects

OATA: i t a b TYPE SORTED TABLE OF marc WITH UNIOUE KEY matnr werks .

Listing 7.9 Define Internal Table

Finally, Listing 7 .10 shows the possible syntax to de f ine a hashed internal table. A u n i q u e key a t t r ibu te is r equ i red for the hashed table and should be specified dur ing t he def in i t ion o f the table. The sorted table can have a u n i q u e o r a non-

internal table. You can also an internal table, as s h o w n

160 Chapter 7 Internal Table Definit ion and Use

u n i q u e k e y ; t h e d a t a is i n s e r t e d in a s o r t e d o r d e r in t h e s o r t e d t a b l e a c c o r d i n g t o

i ts k e y .

DATA: i t a b 0 2 _ l t TYPE i t a b 0 2 .

DATA: i t a b 0 2 _ 1 1 TYPE HASHED TABLE OF l i n e j y p e WITH UNIQUE KEY m a t e r i a l p l a n t .

DATA: i t a b 0 3 TYPE HASHED TABLE OF marc

WITH UNIQUE KEY m a t n r w e r k s .

Listing 7.10 Hashed Internal Table Data Objects

I n t e r n a l T a b l e w i t h H e a d e r L i n e

You c o u l d d e c l a r e a n i n t e r n a l t a b l e w i t h a h e a d e r l i n e u s i n g t h e DATA s t a t e m e n t

w i t h t h e a d d i t i o n o f OCCURS f o l l o w e d b y t h e d e c l a r a t i o n o f a f la t s t r u c t u r e .

O b j e c t - o r i e n t e d p r o g r a m m i n g d o c s n o t s u p p o r t i n t e r n a l t a b l e s w i t h h e a d e r l ines ,

s o y o u s h o u l d n ' t u s e t h i s s y n t a x a n y m o r e w i t h o b j e c t - o r i e n t e d p r o g r a m m i n g .

Also , t h e l i n e t y p e f o r t h e i n t e r n a l t a b l e w i t h a h e a d e r l i ne s u p p o r t s o n l y a f l a t

s t r u c t u r e . T h e l i ne t y p e o f a n i n t e r n a l t a b l e w i t h a h e a d e r l i n e c a n n o t b e a n e s t e d

s t r u c t u r e o r d e e p s t r u c t u r e .

L i s t ing 7 . 1 1 d i s p l a y s a n e x a m p l e c o d e t o d e f i n e a n i n t e r n a l t a b l e w i t h a h e a d e r

l ine .

DATA: BEGIN OF i t a b j t OCCURS 0 . m a t e r i a l LIKE m a r d - m a t n r . p l a n t LIKE m a r d - w e r k s m a t _ d e s c LIKE m a k t - m a k t x , s t o c k LIKE m a r d - l a b s t .

END OF i t a b . l t .

DATA: BEGIN OF i t a b j t OCCURS 0 . m a t e r i a l TYPE m a t n r . p l a n t TYPE w e r k s _ d m a t _ d e s c TYPE m a k t x . s t o c k TYPE l a b s t .

END OF i t a b j t .

Listing 7.11 Definition of Internal Table with Header Line

Key Concepts Refresher Chapter 6 161

You de f ine the internal table s t ruc ture wi th in t he OATA: BEGIN OF C i n t e r n a l t a b l e name> and END OF < 1 n t e r n a l t a b l e name> s ta tement . You can use the LIKE s ta tement o r TYPE s t a t emen t to de f ine the individual c o m p o n e n t of the s t ruc ture as s h o w n in the example above . The OCCURS addi t ion def ines the expected n u m -ber of lines for an internal table. I f y o u d o not specify t he OCCURS addi t ion , t hen the data object def in i t ion is s imply a s t ruc ture o r a work area. So w i t h o u t the addi t ion OCCURS in the above example , the data objec t is no t an internal table. With the addi t ion OCCURS the sys tem creates a s tandard internal table wi th a heade r line.

You specify the initial size of the internal table wi th OCCURS <no of 1 ine>, and the sys tem reserves the m e m o r y for the internal table. The ABAP r u n t i m e dynamical ly manages t he size of t he internal table, so unless y o u k n o w the n u m -ber of rows of t he internal table, it does not m a k e sense to specify t he n u m b e r of lines. You can s imply specify OCCURS 0 and let t he sys tem manage t he m e m o i y for an internal table. As m e n t i o n e d earlier, OCCURS addi t ions w e r e used in old releases, a n d it not r e c o m m e n d e d that y o u use internal tables wi th OCCURS clauses in n e w releases; this is no t s u p p o r t e d in objec t -or ien ted p rog ramming .

Listing 7 .12 displays a n o t h e r example code to de f ine an internal table wi th a heade r line.

TYPES: BEGIN OF i t a b _ t y . matnr TYPE m a t n r . werks TYPE werks . maktx TYPE maktx, l a b s t TYPE l a b s t .

END OF i t a b . t y . OATA: f t a b j t TYPE i t a b _ t y OCCURS 0 WITH HEADER LINE. Listing 7.12 Definition of Internal Table with Header Line

The opt ional addi t ion HEADER LINE creates an addi t ion data object wi th the same n a m e and the line type of an internal table. The header line is not an internal table, but it 's a s t ruc ture that can hold a single table record .

Caution

Internal tables with header lines are not supported in object-oriented program-ming.

162 Chapter 7 Internal Table Definition and Use

Using ABAP Internal Tables

In t h e p r e v i o u s sec t ion w e d i scussed t h e syn tax f o r d e f i n i n g in te rna l tables . In th is sec t ion w e wil l d i scuss h o w to p o p u l a t e an i n t e rna l t ab le a n d h o w to access an i n t e rna l table , i nc lud ing so r t ing a n d t h e v a r i o u s o t h e r i n t e rna l t ab le o p e r a -t i ons . W e will a s s u m e in th is sec t ion tha t t h e i n t e rna l t ab l e d o e s no t h a v e a h e a d e r l ine, a n d a t ab l e - l i ne -compa t ib l e w o r k area is d e f i n e d f o r t h e v a r i o u s o p e r a t i o n s b e c a u s e in n e w e r re lease it is n o t r e c o m m e n d e d tha t y o u d e f i n e in ter -nal t ab les w i t h a h e a d e r l ine .

A p p e n d i n g L i n e s t o I n t e r n a l T a b l e s

As a d e v e l o p e r , y o u r f irst task in t h e p r o g r a m is to fill t he i n t e rna l t ab le o n c e y o u have d e f i n e d it. To a d d n e w r e c o r d s to an i n t e rna l t ab le y o u u s e t h e a p p e n d o r i n s e r r s t a t e m e n t . You can also use t h e s e l e c t s t a t e m e n t to p o p u l a t e t h e m f r o m t h e d a t a b a s e tab le (see C h a p t e r 9, Basic ABAP P r o g r a m s a n d In t e r f ace Crea t ion , f o r s y n t a x a n d deta i l ) .

Fo l lowing is t h e syn tax to p o p u l a t e a n in te rna l t ab le w i t h a select c lause:

OATA: m a r a j t TYPE STANDARD TABLE OF mara . SELECT * FROM mara INTO TABLE m a r a j t .

H e r e MARA is a d a t a b a s e tab le in SAP s y s t e m , a n d ma r a j t is an i n t e rna l t ab le . T h e SELECT s t a t e m e n t p o p u l a t e s t h e c o n t e n t o f t h e MARA tab le i n to t h e i n t e rna l t ab le mara J t .

T h e APPENO s t a t e m e n t is n o r m a l l y u s e d o n l y f o r t h e s t a n d a r d i n t e rna l table . H o w -eve r , it can a lso b e u s e d to a p p e n d to a s o r t e d tab le if t h e l ine to b e a p p e n d e d m a i n t a i n s t h e so r t o r d e r , b u t b e c a u s e it w o u l d b e d i f f icu l t t o k n o w if th is w o u l d b e t h e case, it is r e c o m m e n d e d tha t y o u d o n o t u s e APPEND w i t h t h e s o r t e d in ter -nal table . T h e APPEND s t a t e m e n t can b e used to a p p e n d e i t h e r o n e o r severa l t ab le l ines to s t a n d a r d i n t e rna l tab les . You p o p u l a t e t h e w o r k a r ea a n d t h e n t r a n s f e r t h e w o r k a r ea c o n t e n t to t h e s t a n d a r d in te rna l table .

T h e s y n t a x to a p p e n d in te rna l t ab les is as fo l lows :

OATA: i t a b . w a TYPE mara . DATA: i t a b j t TYPE STANOARD TABLE OF mara . APPENO i t ab_wa TO I t a b j t .

i tab_wa is the w o r k area o f t h e table , a n d 1 t a b j t is t h e i n t e rna l table i tself. You

w o u l d h a v e to p o p u l a t e t h e w o r k area in t h e p r o g r a m a n d t h e n u s e t h e a b o v e

Key Concepts Refresher Chapter 6 7

APPEND s ta tement to a p p e n d a single l ine into the internal table. The APPEND state-m e n t a p p e n d s the l ine as the last l ine in the internal table. You could use the fol-lowing syntax to a p p e n d mul t ip le lines to an internal table.

APPEND l i n e s OF i t a b l TO i t a b 2 . APPEND l i n e s OF i t a b l FROM 1 TO 50 TO 1 tab2 .

The above APPEND s ta tement a p p e n d s the lines of in ternal table 1 t a b l to internal table i t a b ? . If the addi t ion FROM < idx l> TO <idx2> is specif ied in t he APPEND s ta tement , then only t he r o w s f r o m < idx l> to <idx2> will be t ransfe r red f r o m i t a b l t o i t a b 2 .

I n s e r t i n g Lines in a n I n t e r n a l Tab le

The INSERT s ta tement is also used to insert l ines into an internal table and is gen-erally used to fill so r ted and hashed tables. Unlike the APPEND s ta tement , which only a p p e n d s lines at the end of the internal table, y o u can inser t l ines a n y w h e r e in the internal table using INSERT. For sor ted internal tables the n e w line is inser ted according to the sor t sequence as specified by t he table key def in i t ion of the internal table; dupl icate lines a re inser ted above the exist ing l ine wi th the same key. Duplicated records can be inser ted for sor ted internal tables wi th non-u n i q u e keys, but they cannot be inser ted for an internal table wi th a u n i q u e key. With a hashed internal table the lines are inser ted in the hash m a n a g e m e n t table according to its table key.

Listing 7 .13 displays the syntax for the INSERT s ta t ement .

TVPES: BEGIN OF l i n e . m a t e r i a l TYPE m a t n r . p l a n t TYPE werks_d. q u a n t i t y TYPE menge.

ENO OF l i n e . DATA: I tabOl TYPE SORTED TA8LE OF l i n e

WITH UNIQUE KEY m a t e r i a l . OATA: 1tab_wa TYPE l i n e . I t a b . w a - m a t e r i a l - 'M2 ' . i t a b _ w a - p l a n t - '1000*. 1 t a b _ w a - q u a n t i t y - 100. INSERT itab_wa INTO TABLE i t a b O l .

i t ab_wa-mate r1a l - ' M l ' . i t a b _ w a - p l a n t - ' 1 0 0 0 ' .

164 Chapter 7 Internal Table Definition and Use

i t a b _ w a - q u a n t i t y - 200 . INSERT 1tab_wa INTO TABLE i t a b O l .

i t a b _ w a - m a t e r i a l - ' M 3 ' . i t a b _ w a - p l a n t - ' 1 0 0 0 ' . i t a b _ w a - q u a n t i t y - 100. INSERT i tab_wa INTO TABLE I t a b O l . Listing 7.13 Code for the INSERT Statement

T h e a b o v e s t a t e m e n t inse r t s t h e c o n t e n t o f t h e w o r k a rea i tab_wa in to an in ter -nal t ab le i t a b l in t h e so r t s e q u e n c e as spec i f i ed b y t h e key d e f i n i t i o n . T h e w o r k a rea has to b e p o p u l a t e d in t h e p r o g r a m b e f o r e t r a n s f e r r i n g t h e l ines i n to t h e in te rna l table .

Fo l lowing is t h e syn tax to inser t mu l t i p l e l ines i n to an in te rna l t ab le f r o m

a n o t h e r in t e rna l t ab le :

INSERT LINES OF i t a b l [FROM < i d x l > ] [TO < idx2>] INTO TABLE 1 t a b 2 .

T h e a b o v e s t a t e m e n t in se r t s l ines f r o m in t e rna l t ab le i t a b l i n to t ab le i t a b 2 . It

inse r t s t h e l ines f r o m <1dxl> to < idx2> o f t ab l e 1 t a b l i n t o t ab le i t a b 2 if t h e FROM

< i d x l > a n d TO <idx2> a d d i t i o n is spec i f i ed in t h e INSERT s t a t e m e n t ; o t h e r w i s e ,

all r e c o r d s a re t r a n s f e r r e d . T h e mu l t i p l e l ines inser t s t a t e m e n t f o l l o w s t h e ru les

o f i n se r t i ng t h e s ingle t ab le l ines f o r t h e v a r i o u s k i n d s o f i n t e rna l table; f o r e x a m -

ple. f o r a s o r t e d in te rna l t ab le t h e so r t o r d e r will b e m a i n t a i n e d .

A p p e n d i n g S u m m a r i z e d L i n e s i n t o a n I n t e r n a l T a b l e

T h e COLLECT s t a t e m e n t can a lso b e u s e d to inser t l ines i n to an i n t e rna l table . T h e COLLECT s t a t e m e n t w o r k s o n l y w i t h i n t e rna l t ab les tha t h a v e a f lat s t r u c t u r e a n d is u s e d to s u m o r a d d u p the n u m e r i c t ab le f ie lds . F o r a s t a n d a r d i n t e rna l t ab le t h e COLLECT s t a t e m e n t s u m s t h e n u m e r i c f ield va lues if a l ine w i t h t h e k e y va lues a l r eady exists ; o t h e r w i s e , it a p p e n d s t h e l ine to t h e e n d o f t h e i n t e rna l table . Sim-ilarly, f o r s o r t e d a n d h a s h e d tab les t h e COLLECT s t a t e m e n t s u m s u p t h e n u m e r i c f ie ld va lues if a l ine w i t h t h e s a m e key va lue a l r e a d y exists ; o t h e r w i s e , it i n se r t s t h e l ine in to t h e i n t e rna l table . T h e s y s t e m field s y - t a b i x c o n t a i n s t h e i n d e x o f t h e l ine i n se r t ed o r m o d i f i e d in t h e collect s t a t e m e n t .

Listing 7 . 1 4 d i sp lays t h e s y n t a x a n d usage o f t h e COLLECT s t a t e m e n t . T h e e x a m -

ple c o d e uses t h e COLLECT s t a t e m e n t to p o p u l a t e an i n t e rna l table . COLLECl s u m s

Key Concepts Refresher Chapter 6 165

up the numeric value if the line already exists in the internal table. In this exam-ple it will sum up the quantity if the table record for material already exists.

TYPES: BEGIN OF l i n e . matnr TYPE matnr. q t y l TYPE i .

END OF l i n e . DATA: itab_wa TYPE l i n e . OATA: i tabOl TYPE STANDARD TABLE OF TYPE l i n e .

itab_wa-matnr - ' H I ' . i tab_wa-qty l - 10.

COLLECT itab_wa INTO i tabOl . WRITE: / " Index of inser ted /mod i f ied l i n e ' WRITE s y - t a b i x .

itab_wa-matnr - 'M2 ' . i tab_wa-q ty l - 20.

COLLECT i tab.wa INTO i t abO l . WRITE: / s y - t a b i x .

itab_wa-matnr - ' H I * . i tab_wa-qty l - 10.

COLLECT itab_wa INTO i t abO l . WRITE: / s y - t a b i x .

itab_wa-matnr - 'H2 ' . i tab_wa-q ty l - 40.

COLLECT i tab.wa INTO i tabOl . WRITE: / s y - t a b i x .

Clear i tab_wa. LOOP AT I tabOl i n to itab_wa.

WRITE: / i tab_wa-matnr. i tab_wa-qty . ENOLOOP.

List ing 7.14 Syntax of COLLECT S t a t e m e n t for Internal Table

The output of Listing 7.14 is:

Index of inser ted /mod i f ied l i n e : 1 2 1 2 Ml. 20 M2. 60

Reading Internal Table Lines

You use the READ TA8LE statement to read individual lines from the internal table. To use the read statement you have to provide either the key or the index of the internal table line you want to read. The READ TA8LE statement processes one

166 Chapter 7 Internal Table Definit ion and Use

record at a time, but you should use the LOOP statement if you want to process multiple lines from the internal table. The LOOP statement is discussed in detail later in this chapter.

The simplest syntax to read based on the table index is as follows:

OATA: 1tdb_wa TYPE marc. itab_.lt TYPE STANDARD TABLE OF marc.

FIELD-SYMBOLS: <fs> TYPE marc REAO TABLE itab INDEX 10 INTO itab_wa

This READ TABLE statement reads the internal table line with the INDEX 10 and transfers the content to the work area i tab_wa. The result of the REAO statement is transferred to i tab_wa only if the REAO statement successfully finds a line with the INDEX 10 in the internal table itab. SY-SUBRC is set to 4 if no record corre-sponding to the above REAO statement is found in the internal table: otherwise, it is set to 0.

This following statement reads the table line and assigns it the field symbol. The result of the READ TABLE statement is transferred to the work area or field symbol only if the READ TABLE statement successfully finds a line corresponding to con-ditions specified for the REAO statement. SY - SUBRC is set to 4 if no record is found for the READ statement; otherwise, it is set to 0.

REAO TA8LE itab WITH KEY matnr - 'Ml' ASSIGNING <fs>. READ TA8LE 1tab INDEX 10 ASSIGNING <FS>.

The data type of the work area should be compatible with the line type of the internal table. An easy way to define a work area for the internal table is as fol-lows:

OATA: wa LIKE LINE OF itab.

You can use the TRANSPORTING addition after the INTO wa statement. With this option you can select the components or fields that you want to be transferred to the work area:

DATA: idx TYPE syindex. idx - 10. REAO TABLE itab IN0EX idx INTO wa

TRANSPORTING compl comp3.

This statement reads the internal table itab with the INDEX idx and copies the content of the components or fields compl and comp3 from the table line to the work area wa.

Key Concepts Refresher Chap te r 6 167

Ifyou specify the ASSIGNING <fs> addition, then the table line with the index idx is assigned to the field symbol < f s >. This addition is helpful if you want to mod-ify the selected line after the READ statement. You can modify the table line directly by using the field symbol; otherwise,you have to use the MODIFY state-ment to modify the table line.

N o t e

It is i m p o r t a n t t o n o t e t h a t t h e field symbol p o i n t s t o t h e t ab le line in t h e m e m -

ory, so you can mod i fy t h e t a b l e l ine direct ly via t h e field symbol , a n d t h e r e f o r e

p e r f o r m a n c e is b e t t e r .

Listing 7.15 displays the example code to modify a table record.

TYPES: BEGIN OF l ine. matnr TYPE matnr. qtyl TYPE I ,

END OF l ine. OATA: itab.wa TYPE l ine. OATA: 1tab. l t TYPE STANDARD TABLE OF TYPE l ine,

itab.wa-matnr - 'Ml*. itab.wa-qtyl - 10.

APPEND itab_wa to f tab.1t . itab.wa matnr - 'M2*. itab.wa-qtyl - 20.

APPEND itab.wa to i t a b . l t . itab.wa-matnr - 'M3'. itab.wa-qtyl - 30.

APPEND itab.wa to 1tab. l t . LOOP AT i t a b . l t WHERE matnr - 'Ml' INTO itab.wa.

itab.wa-qtyl - 100. MODIFY 1tab. l t FROM itab.wa TRANSPORTING qtyl .

ENDLOOP. List ing 7.15 C o d e t o APPEND a n d MODIFY an Internal Table

However, with the READ TABLE statement the above code could also be imple-mented as follows:

READ TABLE 1tab.lt key matnr - 'Ml' ASSIGNING <fs>. <fs>-qtyl - 100.

You can also read the internal table record based on any field in the table record. Following is the example code for the r e a d statement with the w i t h k e y addition:

168 Chapter 7 Internal Table Definition and Use

TYPES: BEGIN OF l i n e . kunnr TYPE k u n n r . "Cus tomer no . l and TYPE l a n d l _ g p . "Coun t ry namel TYPE namel_gp . "Name o r t O l TYPE o r t 0 1 _ g p . " C i t y p s t l z TYPE p s t l z . "ZIP code

ENO OF l i n e . OATA: i t a b 0 2 TYPE STANDARD TABLE of l i n e . DATA: wa LIKE LINE OF i t a b 0 2 .

SELECT * f rom KNA1 INTO CORRESPONDING FIELDS OF TABLE i t a b 0 2 . SORT i t a b 0 2 by k u n n r . REAO TABLE 1 tab02 WITH KEY kunnr - - 12345 '

INTO wa BINARY SEARCH.

W i t h t h e a b o v e READ s t a t e m e n t y o u spec i fy t h e search k e y to r ead t h e l ine f r o m t h e in te rna l t ab le . You cou ld u s e a n y c o m p o n e n t o r f ield o f the tab le l ine to search t h e table . T h e c o n t e n t o f t h e f irst f o u n d l ine o f t h e in te rna l t ab le tha t m a t c h e s t h e search key is t r a n s f e r r e d to t h e w o r k area . T h e a b o v e READ s t a t e m e n t p r o v i d e s y o u w i t h o n l y o n e r e c o r d e v e n if m o r e t h a n o n e r eco rd m a t c h e s t h e search key . You h a v e to u s e t h e LOOP s t a t e m e n t if y o u w a n t all o f t h e r e c o r d s m a t c h i n g t h e sea rch key .

S t anda rd in te rna l tab les a re s u b j e c t to s e q u e n t i a l s ea rch w i t h t h e a b o v e r e a o s t a t e m e n t . W i t h t h e a d d i t i o n b i n a r y s e a r c h t h e sea rch is b i n a i y ins tead o f s equen t i a l , w h i c h c o n s i d e r a b l y i m p r o v e s search p e r f o r m a n c e a t r u n t i m e . F o r b i n a i y search t h e s t a n d a r d in te rna l t ab le m u s t b e s o r t e d by t h e sea rch k e y in a s c e n d i n g o r d e r ; o t h e r w i s e , t h e search resu l t wil l n o t f i n d t h e co r rec t r o w o r r e c o r d . T h e search a l g o r i t h m d e p e n d s o n t h e tab le t y p e i f y o u d o n o t spec i fy t h e b i n a r y s e a r c h a d d i t i o n .

• For s o r t e d in te rna l t ab les t h e search is a lways b ina ry , a n d t h e a d d i t i o n BI NARY

SEARCH h a s n o e f f ec t .

• For a h a s h e d in te rna l t ab le t h e h a s h a l g o r i t h m is u s e d to sea rch if t h e spec i f i ed k e y is t h e i n t e rna l t ab le key; o t h e r w i s e , t h e search is s equen t i a l . T h e a d d i t i o n b i n a r y s e a r c h is n o t p e r m i t t e d f o r h a s h e d in te rna l tab les .

Key Concepts Refresher Chapter 6 169

Tips

The BINARY SEARCH addi t ion is valid for s tandard internal tables only. The s tan-dard internal table should be sorted to use t he BINARY SEARCH addi t ion:

• The addi t ion BINARY SEARCH d o e s not have any effect on t he READ s t a t e m e n t for sorted internal tables.

• The BINARY SEARCH addi t ion is no t permi t ted with t he READ s t a t emen t for

hashed internal tables.

T h e o t h e r v a r i a n t s o f t h e READ s t a t e m e n t s a r e :

READ TABLE i t a b 0 2 FROM wa ASSIGNING < f s >

a n d

READ TABLE 1 t a b 0 2 WITH TABLE KEY k u n n r - ' 1 2 3 4 5 ' p s t l z - ' 9 5 1 1 8 ' .

F o r t h e f i r s t v a r i a n t t h e w o r k a r e a m u s t b e a d a t a o b j e c t t h a t is c o m p a t i b l e w i t h

t h e l i n e t y p e o f t h e i n t e r n a l t a b l e . T h e s e a r c h is p e r f o r m e d b a s e d o n t h e c o n t e n t

o f t h e w o r k a r e a wa. T h e r e s u l t o f t h e REAO TABLE s t a t e m e n t f o r w h i c h t h e v a l u e s

in t h e c o l u m n s o f t h e t a b l e m a t c h e s t h e v a l u e s o f t h e c o r r e s p o n d i n g c o m p o n e n t s

o f t h e w o r k a r e a is a s s i g n e d t o t h e f i e l d s y m b o l .

F o r t h e s e c o n d READ s t a t e m e n t v a r i a n t y o u h a v e t o s p e c i f y t h e foil t a b l e k e y t o

r e a d t h e l i ne o f t h e i n t e r n a l t a b l e . If y o u c a n n o t p r o v i d e t h e fu l l k e y , t h e n y o u

s h o u l d u s e WITH KEY a n d n o t WITH TABLE KEY. S t a n d a r d t a b l e s a r e r e a d u s i n g a

s e q u e n t i a l s e a r c h , s o r t e d i n t e r n a l t a b l e s a r e s e a r c h e d u s i n g t h e b i n a r y s e a r c h , a n d

f o r h a s h e d i n t e r n a l t a b l e s t h e h a s h a l g o r i t h m is u s e d t o s e a r c h f o r t h e t a b l e l i ne .

P r o c e s s i n g M u l t i p l e L i n e s o f a n I n t e r n a l T a b l e

Y o u p r o c e s s i n t e r n a l t a b l e l i n e s s e q u e n t i a l l y b y u s i n g t h e LOOP a n d ENDLOOP s t a t e -

m e n t s . T h i s a l l o w s y o u to p r o c e s s m u l t i p l e l i n e s in t h e i n t e r n a l t a b l e s e q u e n t i a l l y

o n e a f t e r t h e o t h e r . L i s t ing 7 . 1 6 is a n e x a m p l e c o d e f o r t h e LOOP s t a t e m e n t :

TYPES: BEGIN OF i t a b . t y , m a t n r TYPE m a t n r . w e r k s TYPE w e r k s _ d .

END OF i t a b . t y . OATA: i t a b j t TYPE STANDARD TABLE OF i t a b _ t y . OATA: wa LIKE LINE OF 1 t a b _ l t .

170 Chapter 7 Internal Table Definition and Use

SELECT matnr werks FROM marc INTO TABLE i t a b j t . LOOP a t i t a b j t i n t o wa.

WRITE: / wa-matnr . wa-werks. ENDLOOP.

Listing 7.16 Syntax for the LOOP Statement

The above LOOP s ta tement reads each line one at a t ime and t ransfers that table line to the work area. The work area wa data object shou ld be compat ib le wi th t he line type of the internal table. You can use t he addi t ion TRANSPORTING to specify the fields to be t ransfe r red to the work area. The internal table lines a re available wi th in t he LOOP block, and y o u can p e r f o r m opera t ions o n t he individ-ual lines wi th in the loop s ta tement .

O the r var iants of the LOOP s ta tement are:

LOOP AT i t a b j t WHERE matnr - •12345' INTO wa. WRITE: / wa-matnr . wa-werks.

ENDLOOP.

and

LOOP AT i t a b j t FROM 1 TO 10 INTO wa. WRITE: / wa-matnr . wa-werks.

ENDLOOP

In the first syntax variant y o u have the op t ion to specify t he condi t ional selection of t he table lines f rom the internal table by specifying the WHERE condi t ion fo r the LOOP s ta t ement . This s t a tement sequent ia l ly searches each l ine o f the table fo r the condi t ion specified wi th the WHERE condi t ion . Wi th the second var iant o f the LOOP s t a t emen t m e n t i o n e d above, y o u can limit the n u m b e r o f table lines to be processed by specifying the FROM i d x l o r TO idx2 for the LOOP s ta tement .

You can also p e r f o r m control-level processing wi th in the s t a tement block of the loop s ta tement . The control s t a t emen t s for the control-level processing are wi th in the AT and ENDAT s ta tements . The s t a t emen t block wi th in the AT and ENDAT s ta tements is executed at the cont ro l break. The control break h a p p e n s w h e n the control s t ruc ture for the internal table changes .

The syntax be low displays cont ro l break s t a t emen t s w h e n looping th rough the internal table.

LOOP a t i t a b INTO wa. AT FIRST.

Key Concepts Refresher Chapter 6 171

ENOAT.

AT NEW compl.

ENOAT. AT ENO Of compl.

ENOAT. AT LAST.

ENOAT. ENOLOOP.

For control-level processing to work proper ly , t he fol lowing rules mus t be fol-lowed:

• The internal table should be sor ted in the s equence o f t he c o m p o n e n t o f the l ine type.

• The internal table cannot be modi f i ed wi th in the LOOP s t a t ement .

• The condi t ional selection of the internal table lines should not be specified for the LOOP s ta tement ; that is. y o u canno t use the WHERE addi t ion to the LOOP s ta tement .

M o d i f y i n g t h e I n t e r n a l Tab le Lines

You use the MODIFY s ta tement to change the con ten t of the lines of the internal table. You can also mod i fy the internal table l ine by mod i fy ing the field symbol <f s> o r re ference variable <dref >, which is l inked to t he l ine of the internal table as a result of the READ s ta t ement .

The syntax to mod i fy the internal table using the MODI FY s ta tement is:

TYPES: BEGIN OF l i n e . m a t e r i a l TYPE m a t n r . p l a n t TYPE werks_d f l d l TYPE I . f l d 2 TYPE I .

ENO OF l i n e . OATA: i t a b TYPE STANDARD TABLE OF l i n e . OATA: wa TYPE l i n e . MODIFY TABLE i t a b FROM wa. MODIFY TABLE i t a b FROM wa TRANSPORTING f l d l f1d2.

186 Chapter 7 Internal Table Definit ion and Use

T h i s c o d e s e a r c h e s f o r t h e i n t e r n a l t a b l e l i n e w h o s e k e y c o m p o n e n t s m a t c h t h e

k e y v a l u e s o f t h e w o r k a r e a a n d t h e n m o d i f i e s t h e s e l e c t e d i n t e r n a l t a b l e l i ne .

W i t h t h e a d d i t i o n TRANSPORTING, o n l y t h e fields s p e c i f i e d a f t e r t h e TRANSPORT-

ING s t a t e m e n t a r e m o d i f i e d .

You c a n m o d i f y m u l t i p l e l i n e s o f t h e i n t e r n a l t a b l e w i t h t h e f o l l o w i n g s y n t a x :

MODIFY I t a b FROM wa TRANSPORTING f l d s l f l d 2 WHERE m a t e r i a l - 1 1 2 3 4 5 ' .

T h i s m o d i f i e s all o f t h e t a b l e l i n e s t h a t s a t i s f y t h e logical WHERE c o n d i t i o n . W i t h

t h e TRANSPORTING a d d i t i o n o n l y t h e c o m p o n e n t s o r fields s p e c i f i e d a f t e r t h e

TRANSPORTING s t a t e m e n t a r e m o d i f i e d .

T h e f o l l o w i n g MODIFY s t a t e m e n t m o d i f i e s t h e i n t e r n a l t a b l e l i ne w i t h t h e INDEX

i d x u s i n g t h e c o n t e n t s o f t h e w o r k a r e a wa. T h e w o r k a r e a wa s h o u l d b e c o m p a t -

ib l e w i t h t h e l i ne t y p e o f t h e i n t e r n a l t a b l e .

MODIFY i t a b FROM wa INDEX i d x .

L i s t ing 7 . 1 7 d i s p l a y s t h e u s e o f t h e MOO I FY s t a t e m e n t w i t h i n t h e LOOP b l o c k . T h e

MODIFY s t a t e m e n t m o d i f i e s t h e c u r r e n t i n t e r n a l t a b l e l i n e w i t h i n t h e LOOP s t a t e -

m e n t w i t h t h e c o n t e n t s o f t h e w o r k a r e a wa.

TYPES: BEGIN OF l i n e . m a t e r i a l TYPE m a t n r . p l a n t TYPE w e r k s _ d f l d l TYPE I . f l d 2 TYPE I .

END OF l i n e . DATA: i t a b TYPE STANDARO TABLE OF l i n e . OATA: wa TYPE l i n e . LOOP AT i t a b INTO wa.

w a - f l d l - 100 . w a - f l d 2 - 2 0 0 . MODIFY i t a b FROM wa.

ENDLOOP.

LOOP AT i t a b INTO wa. w a • f l d l - 100 . w a - f l d 2 - 2 0 0 .

Key Concepts Refresher Chapter 6 7

MODIFY i t a b FROM wa TRANSPORTING f l d l f l d 2 . ENDLOOP.

Listing 7 1 7 Use of Modify S ta tement within t he LOOP S ta tement

Deleting Internal Table Lines

You u s e t h e DELETE s t a t e m e n t t o d e l e t e l i nes f r o m a n i n t e r n a l t a b l e . F o l l o w i n g is

t h e s y n t a x o f t h e d e l e t e s t a t e m e n t : OELETE i t a b INDEX i d x .

T h i s s t a t e m e n t d e l e t e s t h e t a b l e l i n e w i t h t h e INDEX i d x .

T h e f o l l o w i n g s y n t a x d e l e t e s m u l t i p l e l i n e s o f t h e i n t e r n a l t a b l e s p e c i f i e d b y t h e

i n d e x r a n g e o r t h e logical e x p r e s s i o n s p e c i f i e d b y t h e WHERE a d d i t i o n :

OELETE i t a b FROM i d x l TO i d x 2 .

OELETE i t a b FROM WHERE m a t e r i a l - ' 1 2 3 4 5 ' .

T h e f o l l o w i n g s t a t e m e n t d e l e t e s m u l t i p l e l i n e s f r o m t h e i n t e r n a l t a b l e t h a t is

s o r t e d . T h i s s t a t e m e n t c o m p a r e s t h e t a b l e c o m p o n e n t s a n d d e l e t e s t h e a d j a c e n t

d u p l i c a t e s . It m a k e s s e n s e t o u s e t h e f o l l o w i n g s t a t e m e n t as l o n g as t h e c o n t e n t s

o f t h e i n t e r n a l t a b l e a r e s o r t e d :

OELETE ADJACENT DUPLICATES FROM TABLE i t a b COMPARING m a t e r i a l p l a n t .

OELETE ADJACENT DUPLICATES FROM TABLE i t a b .

T h e f o l l o w i n g d e l e t e s y n t a x d e l e t e s t h e i n t e r n a l t a b l e l i n e s b a s e d o n t h e t a b l e

k e y :

OELETE TABLE i t a b WITH TABLE KEY m a t e r i a l - ' 1 2 3 4 5 ' p l a n t - ' a b e d ' .

Sorting Internal Tables

You u s e t h e SORT s t a t e m e n t t o s o r t t h e i n t e r n a l t a b l e . You c a n o n l y s o r t a s t a n d a r d

o r a h a s h e d t a b l e u s i n g t h e SORT s t a t e m e n t . You c a n n o t u s e t h e SORT s t a t e m e n t

f o r a s o r t e d i n t e r n a l t a b l e b e c a u s e , b y d e f i n i t i o n , it is a l r e a d y s o r t e d .

188 Chapter 7 Internal Table Definition and Use

Following is the syntax for the SORT s ta tement :

SORT i t a b . SORT i t a b ASCENDING. SORT I t a b DESCENDING.

The above s t a t emen t sorts the internal table in ascending o rde r by its key. By defaul t , the sys tem sor ts the internal table in ASCENDING o rde r i f y o u d o not spec-ify the addi t ion ASCENDING or OESCENOING. O t h e r var iants of SORT s t a t emen t are:

SORT TABLE i t a b BY m a t e r i a l p l a n t DESCENDING. SORT TA8LE i t a b AS TEXT.

The first s t a tement sor ts the internal table by the f ield 's m a t e r i a l a n d p l a n t in descend ing o rde r . The second SORT s ta tement wi th t he addi t ion AS TEXT sorts the character type c o m p o n e n t s according to the cur ren t text e n v i r o n m e n t set t ing specified in the user mas te r record . W i t h o u t the AS TEXT addi t ion the internal table is sor ted according to the encoding specified by the h a r d w a r e p la t form.

E m p t y i n g t h e I n t e r n a l Tab le

Depend ing on the table def in i t ion , y o u can e m p t y the internal table by using the CLEAR or REFRESH s ta tement . You can clear an internal table wi th a header l ine wi th the fol lowing s t a tement :

CLEAR 1tabC 3.

o r

REFRESH i t a b .

The above CLEAR and REFRESH s ta t emen t s de le te the table body lines only, bu t y o u can use the fol lowing syntax to clear the header l ine a n d the body of the internal table:

CLEAR: i t a b . i t a b t ] .

o r

CLEAR: i t a b . REFRESH i t a b .

The CLEAR s t a t emen t wi th square brackets a r o u n d i t a b [ ] o r REFRESH i t a b deletes o r initializes the internal table body lines, whe rea s the CLEAR i t a b state-m e n t clears the heade r line.

Important Terminology Chapter 6

You can use t h e CLEAR s t a t e m e n t to d e l e t e o r ini t ial ize the b o d y l ines o f t h e in ter -

nal t ab le w i t h o u t a h e a d e r l ine . T h e f o l l o w i n g s t a t e m e n t d e l e t e s o r ini t ial izes t h e

b o d y l ines o f t h e i n t e rna l t ab le w i t h o u t h e a d e r l ines:

CLEAR i t a b .

T h e FREE s t a t e m e n t w o r k s l ike t h e REFRESH s t a t e m e n t , b u t in a d d i t i o n it re leases t h e m e m o i y area o f t h e in te rna l t ab le . W i t h t h e FRE r s t a t e m e n t t h e tab le b o d y is d e l e t e d a n d t h e m e m o r y area r e s e r v e d f o r t h e i n t e rna l t ab le is r e leased . T h e syn-tax f o r t h e FREE s t a t e m e n t as fo l lows :

FREE i t a b .

Important Terminology

You s h o u l d k n o w h o w to d e f i n e in te rna l tab les in t h e p r o g r a m a n d b e a w a r e o f

d i f f e r e n t k i n d s o f i n t e rna l t ab le such as s t a n d a r d , so r t ed , a n d h a s h e d in t e rna l

tab les .

• T h e APPEND a n d I N S E R T s t a t e m e n t s a re u s e d to p o p u l a t e t h e i n t e rna l table .

• You u s e t h e READ T A B L E s t a t e m e n t to r ead ind iv idua l r e c o r d s o f a n i n t e rna l

table . You can a lso use t h e a d d i t i o n INDEX o r KEY w i t h t h e READ T A B L E s tate-

m e n t to r ead ind iv idua l r e c o r d s f r o m t h e i n t e rna l table .

• T h e LOOP s t a t e m e n t is u s e d to p roces s ind iv idua l i n t e rna l t ab le l ines . Th is s t a t e m e n t l oops t h r o u g h t h e i n t e rna l t ab le a n d places t h e ind iv idua l t ab le r e c o r d s in t h e w o r k area o f t h e i n t e rna l table .

• T h e MODI FY s t a t e m e n t is u s e d to m o d i f y ex i s t ing r e c o r d s o f t h e i n t e rna l table .

If t h e M O D I F Y c o m m a n d is u s e d in a LOOP s t a t e m e n t to m o d i f y t h e i n t e rna l

table , t h e n t h e c u r r e n t l ine o f t h e in te rna l t ab le is c h a n g e d .

• T h e DELETE s t a t e m e n t is u s e d to d e l e t e a r eco rd o f an i n t e rna l table . You can a lso u s e t h e D E L E T E s t a t e m e n t w i t h t h e a d d i t i o n W I T H T A B L E KEY to d e l e t e r e c o r d s f r o m t h e i n t e rna l t ab le f o r t h e spec i f i ed key in t h e D E L E T E s t a t e m e n t .

• T h e SORT s t a t e m e n t is u s e d to s o r t the in te rna l table .

% Practice Questions

T h e p rac t i ce q u e s t i o n s b e l o w will h e l p y o u eva lua t e y o u r u n d e r s t a n d i n g o f t h e

top ic . T h e q u e s t i o n s s h o w n a r e s imi la r in n a t u r e to t h o s e f o u n d o n t h e cer t i f ica-

176 Chapter 7 Internal Table Definition and Use

t ion e x a m i n a t i o n , b u t w h e r e a s n o n e o f t h e s e q u e s t i o n s will b e f o u n d o n t h e

e x a m itself, t h e y a l low y o u to r e v i e w y o u r k n o w l e d g e o f t h e sub jec t . Select the

co r rec t a n s w e r s a n d t h e n check the c o m p l e t e n e s s o f y o u r a n s w e r s in t h e fo l low-

ing so lu t ion sec t ion . R e m e m b e r tha t y o u m u s t select all co r rec t a n s w e r s a n d o n l y

co r rec t a n s w e r s to r ece ive c red i t f o r t h e q u e s t i o n .

1. H o w m a n y k inds o f in te rna l t ab le a r e s u p p o r t e d in t h e ABAP l anguage?

• A. 2

• B.3 • C. 1

2 . W h i c h o f t h e f o l l o w i n g s t a t e m e n t s a r e t r ue? T h e r e can b e m o r e than o n e

t r u e s t a t e m e n t .

• A. S t a n d a r d tab les can b e accessed by i n d e x .

• B. S t a n d a r d tab les c a n n o t b e accessed b y index .

• C. A s o r t e d t ab l e is a l w a y s accessed by a u n i q u e key .

• D. Hashed tables a re a lways accessed b y index .

• E. H a s h e d t ab les a r c accessed b y a u n i q u e key .

3. T h e OCCURS s t a t e m e n t is r e q u i r e d to d e f i n e a n in te rna l t ab le w i t h a h e a d e r

l ine .

• A. T r u e

• B. False

4 . You can u s e t h e APPENO s t a t e m e n t to fill a s o r t e d in te rna l table .

• A. T r u e

• B. False

5 . You c a n n o t use t h e I N S E R T s t a t e m e n t to inser t l ines i n t o a s t a n d a r d i n t e rna l

t ab le .

• A. T r u e

• B. False

Practice Questions Chapter 6

6 . You can use a t ab le w i t h a h e a d e r l ine f o r o b j e c t - o r i e n t e d p r o g r a m m i n g .

• A. T r u e

• B. False

7 . An in t e rna l t ab le l ine t y p e w i t h a d e e p o r n e s t e d s t r u c t u r e can b e d e f i n e d f o r i n t e rna l tab les w i t h a h e a d e r l ine .

• A. T r u e

• B. False

8 . In te rna l t ab les c a n n o t h a v e a d e e p o r n e s t e d s t r u c t u r e in the i r l ine t ype .

• A. T r u e

• B. False

9 . T h e READ s t a t e m e n t w i t h t h e a d d i t i o n B I N A R Y SEARCH f o r a s o r t e d i n t e rna l t ab le is b e t t e r fo r p e r f o r m a n c e .

• A. T r u e

• B. False

10. T h e READ s t a t e m e n t w i t h t h e B I N A R Y SEARCH a d d i t i o n c a n n o t b e u s e d f o r a s o r t e d i n t e rna l table .

• A. T r u e

• B. False

1 1 . T h e B I NARY SEARCH a d d i t i o n c a n n o t b e u s e d w i t h t h e READ s t a t e m e n t f o r t h e HASHED tab le .

• A. T r u e

• B. False

12 . W h i c h o f t h e f o l l o w i n g is a t r u e s t a t e m e n t :

• A. A s o r t e d tab le can h a v e a u n i q u e o r a n o n - u n i q u e key .

• B. A s t a n d a r d tab le s h o u l d a lways h a v e a u n i q u e key .

• C. A h a s h e d tab le s h o u l d a l w a y s h a v e a u n i q u e tab le key .

178 Chapter 7 Internal Table Definition and Use

13 . You can e m p t y t h e b o d y o f t h e in te rna l table f t a b w i t h a h e a d e r l ine u s ing

t h e CLEAR 1 t a b s t a t e m e n t .

• A. T rue

• B. False

14 . You can m o d i f y an i n t e rna l t ab le b y us ing t h e UPDATE s t a t e m e n t .

• A. T r u e

• B. False

15 . In te rna l t ab les can a lso b e m o d i f i e d a f t e r e x e c u t i n g t h e REAO s t a t e m e n t w i t h

t h e a d d i t i o n A S S I G N I N G .

• A. T r u e

• B. False

16 . You c a n n o t u s e a SORT s t a t e m e n t f o r a s o r t e d in te rna l t ab le .

• A. T r u e

• B. False

Practice Question Answers and Explanations

1. Cor rec t a n s w e r : B

T h e r e a r e t h r e e t y p e s o f i n t e rna l tables : s t a n d a r d , so r t ed , a n d h a s h e d .

2 . Cor rec t a n s w e r s : A, E

A s t a n d a r d tab le can b e accessed by t h e index o r t h e key . A h a s h e d tab le is accessed by t h e u n i q u e key, a n d it u s e d to hash a l g o r i t h m s to access t h e t ab l e r eco rd . A s o r t e d tab le can b e accessed by t h e i n d e x o r t h e key . A so r t ed tab le can h a v e a u n i q u e o r a n o n - u n i q u e key.

3. Cor rec t a n s w e r : B

You r e q u i r e an OCCURS a d d i t i o n to dec la re a in te rna l t ab le w i t h a h e a d e r l ine,

b u t y o u can d e f i n e an i n t e rna l t ab le w i t h h e a d e r l ine u s ing t h e W I T H HEADER

L I N E a d d i t i o n .

Practice Question Answers and Explanations Chapter 7

4. Correct answer : B

Sorted tables shou ld not be filled using the APPEND s t a t ement . Instead, they should be filled wi th the INSERT s t a t ement . You canno t use the APPEND state-m e n t because the table is s tored in a sor ted order . APPEND a lways adds the record as the last e n t i y in the table, so sor ted tables use t he 1NSERT s t a t emen t to insert table records in the internal table.

5. Correct answer : B

You can use the INSERT s t a t emen t to inser t records in a s t andard internal table, the record will be added to the end of the table.

6 . Correct answer : B

You cannot use an internal table wi th a heade r l ine in objec t -or ien ted pro-g ramming .

7. Correct answer : B

You cannot de f ine an internal table wi th a heade r line that has a d e e p o r nes ted s t ructure .

8 . Correct answer : B

You can de f ine internal tables wi th d e e p o r nes ted s t ruc ture l ine types, bu t the internal table mus t be o n e w i t h o u t a heade r line.

9 . Correct answer : B

BINARY SEARCH does not have any effect o n the sorted internal table. Sorted internal tables always use a b inary search to read the table records wi th the READ s t a t ement .

10. Correct answer : B

You can use the B I NARY SEARCH w i th the READ s t a t emen t fo r sor ted tables, bu t it does not have any effect .

11. Correct answer : A

You cannot use BINARY SEARCH w i th the READ s t a t ement to read hashed inter-nal tables. Hashed internal tables requi re a u n i q u e key to read the internal table record, and they use a hash a lgor i thm to f ind t he table record .

12. Correct answers : A, C

The s tandard internal table can have a non -un ique key, and the hashed inter-

nal table must a lways have a u n i q u e key.

The sorted table can have a u n i q u e o r a non -un ique key.

180 Chapter 7 Internal Table Definition and Use

13. Correct answer : B

You cannot clear an internal table wi th a heade r line wi th t he CLEAR i t a b s ta tement . To e m p t y the table b o d y y o u have to use t he CLEAR i t a b [ ] state-m e n t .

14. Correct answer : B

The UPDATE s t a t emen t canno t be used to mod i fy the internal table. You use the MODIFY s t a t emen t to mod i fy the internal tabic.

15. Correct answer : A

You can mod i fy internal tables using the ASSIGINING s t a t emen t because the ASS I GIN ING poin t s to the m e m o r y address o f the table record or field.

16. Correct answer : A

A sor ted internal table is sor ted by defaul t , and hence y o u canno t use the SORT s t a t emen t to sor t a sor ted internal table.

Take Away

You need to unde r s t and the syntax to create internal tables, be able to de f ine a data type, a n d use it to de f ine an internal table in t he p rogram. You need to unde r s t and the d i f fe rence b e t w e e n internal tables wi th heade r lines and w i t h o u t heade r lines, and y o u should k n o w h o w to de f ine such a table in the p rogram. You also must be aware that the internal table wi th heade r l ine is not suppor ted in ABAP Objects p rog ramming . You should be able to d i f fe ren t ia te b e t w e e n the d i f fe ren t k inds of internal table such as s tandard , sor ted, and hashed and be able to use t h e m in a p rog ram. You should also be able to popu la te internal tables wi th the APPEND and INSERT s ta t emen t s and be able to p e r f o r m var ious opera-t ions on the internal table. You should k n o w the syntax to update , modi fy , delete , and read individual records f r o m the internal table.

Refresher

You should n o w be able to descr ibe internal tables a n d their use in the ABAP pro-g r a m m i n g language. You should k n o w the keywords and the syntax to de f ine and access the internal table. You should be able to use internal tables in a pro-gram to s tore data temporar i ly and be able to process the data in the table.

Table 7.2 repeats the key concepts of this chap te r in shor t f o r m .

Summary Chapter 7

Key C o n c e p t Def in i t ion

Internal tab le An internal tab le is a local program variable-data objec t and is

used to s tore multiple s t ructured da ta records temporari ly in memory .

Kinds of internal There are th ree kinds of internal tables: s tandard table, sor ted table table, and hashed table .

Standard internal Standard tables can have a unique or a non-un ique key and

table can b e accessed with t he key or an index. They can be filled with t he APPEND or INSERT s t a t ement , or you can use t he select

s t a t emen t to popu la te t h e m from the da tabase (see Chapter 9 . Basic ABAP Programs and Interface Creation)

Sorted internal Sorted tables can have a un ique or a non-un ique key. The table table records a re s tored in a sor ted order , and by defaul t a re sorted

in ascending order . You fill t h e sorted internal table with the INSERT s t a t e m e n t .

Hashed internal Hashed internal tables must have a un ique key that you mus t

table use to access the table record. A hash algorithm is used to read t he hashed internal table .

Table 7-2 Key Concept Refresher

S u m m a r y

You have learned in detail the concepts of" internal tables, the different kinds of internal table, and the valid operations on each kind of internal table. You should know the syntax to define internal tables, access internal tables and process the table records in the internal table. This knowledge wil l al low you to easily pass this topic on the certification examination.

SQL Statements Including Update Strategies

Techniques You'll Master:

• Under s t and the pu rpose a n d benef i t s of using a data mode l in appl icat ion d e v e l o p m e n t

• Access specific co lumns and rows wi thin a par t icular da tabase table o r tables

• Explain the t e rms da tabase LUW and SAP LUW and the differ-ences b e t w e e n them

• Bundle changes to da tabase tables in the cl ient-server architec-ture of an SAP system

• Unders tand t he role of lock objects and h o w to set a n d release SAP locks

• Per form da tabase changes using various upda te t echniques

184 Chapter 8 SQL Statements Including Update Strategies

The three-t ier a rchi tec ture used by SAP provides for the user w h o interacts wi th the presen ta t ion layer. This in tu rn controls the bus iness logic runn ing on an applicat ion server, which may re t r ieve and s tore data in the database server . The sys tem is des igned as da tabase neutra l , mean ing that it w o r k s wi th a n u m b e r o f databases . Normal ly f r o m y o u r perspect ive, t he under ly ing da tabase is no t a p r i m e concern .

In this chapter , w e will touch brief ly on data model ing , o r table design. W e fol-low this wi th m e t h o d s of re t r ieving data f r o m the da tabase and eff icient use o f the database (using SQL). Lastly, the chap te r covers logical un i t s of work (LUW), lock objects , and u p d a t e tasks.

Each of these topics is covered separately and is fo l lowed by the practice exercise and the solut ion to the exercise.

Real-World Scenario

Imagine y o u w a n t to deve lop a n e w transact ion that uses da tabase tables p rov ided by SAP and n e w database tables u n i q u e to y o u r process. This n e w transact ion will access data f r o m s tandard SAP database tables and upda te the n e w da tabase tables based on user interact ion th rough mul t ip le dialog steps. The t ransact ion will be used by mult iple users s imul taneous ly and needs to provide a consis tent s ta te w h e n commi t t i ng changes to the data-base.

The t ransact ion will p rov ide access to the records being upda t ed for a sin-gle user, but the database tables not being upda t ed will al low mult iple users to see the data s imul taneous ly . O w i n g to the complexi ty o f the pro-cess, it requi res mult iple dialog screens to ga the r the data for eventual upda te across mul t ip le database tables.

The n u m b e r o f records that actually a rc upda t ed o r pos ted du r ing the pro-cess may vary a n y w h e r e f r o m zero to several t housand at a t ime. You w e r e tasked wi th providing a quickly r e spond ing t ransact ion for t he user and mainta in ing a consis tent da tabase state. This means that if any u p d a t e fails, y o u are able to re turn to the last consis tent s tate be fo re any change was made .

Objectives of this Portion of the Test Chapter 8

Objectives of this Portion of the Test

The p u r p o s e of this por t ion of the cert if ication examina t ion is to verify that y o u have detai led knowledge of h o w to re t r ieve data f rom the database and h o w to m a k e changes to da tabase tables in a m a n n e r in which the data remains consis-tent whi le a l lowing the user to con t inue to work as eff iciently as possible.

This por t ion of the examina t ion will test y o u r knowledge of O p e n SQL and dif-fe ren t mechan i sms for making changes . The points that y o u will need to under -stand f r o m this sect ion include:

• Data selection techniques f rom the da tabase

• Update strategies for the database

• Bundling changes to the database

Key Concepts Refresher

Typically, y o u need to access and change data wi th in the database . As a conse-quence , y o u need to unde r s t and and be able to p e r f o r m the fol lowing types of tasks w h e n deve lop ing ABAP programs, so y o u should be able to do the follow-ing func t ions o r processes:

• Design tables for eff icient use

• Read data f r o m a single o r mul t ip le database tables

• Create and using lock objects

• Select the mos t app rop r i a t e type of upda te

• Describe a logical uni t of w o r k f r o m bo th a database and appl icat ion perspec-tive

Data Modeling

W h e n y o u deve lop bus iness applicat ions, parts of the real wor ld mus t be repre-sen ted as data. A business uni t r ep resen t s an enti ty, and these ent i t ies exist in re la t ionship wi th each o the r a n d a r e fixed in the under ly ing data model . This is re fer red to as an entity relationship model (fcRM).

You use this data model to i m p l e m e n t appropr ia t e table def in i t ions including the i r re la t ionships wi th each o the r in t he ABAP Dict ionaiy. Activating the table

200 Chapter 8 SQL Statements Including Update Strategies

def in i t ions in the ABAP Dict ionaiy, automatical ly creates the co r r e spond ing da tabase tables in the database .

Note

SAP uses the so-called flight model throughout its training materials, online doc-umentation, and ABAP keyword documentation. We use the same model during our explanation in this section because it is well known and easy to understand from both a business perspective and a user perspective.

Imagine a s imple example f r o m the SAP flight model : If cus tomers of a travel agency w a n t to travel f r o m one place to ano ther , they requi re the travel agency to find out :

• Which connec t ion of fers the flight tha t is mos t direct?

• O n the day of travel which flights p rov ide acceptable flight t imes?

• Dependen t on individual ' s needs, which is the cheapes t flight, t he fastest con-nect ion, o r a connec t ion wi th a par t icular arrival t ime?

This perspect ive di f fers f r o m that of a travel agency. The data is s tored according to technical criteria in a central da tabase wi th in the data model that manages this requi red data. The a m o u n t of data s tored far exceeds the r equ i r emen t s of a spe-cific cus tomer . The travel agency needs to be able to access the data to mee t the individual r equ i r emen t s o f the cus tomer using appl icat ion programs .

The flight data model conta ins ent i t ies for all bus iness in fo rmat ion that is logi-cally connec ted , such as cities, a i rpor ts , airl ines, flight routes , flights, and so on . These enti t ies all relate to each o the r in certain ways:

• Each flight schedule conta ins exactly o n e airline, o n e d e p a r t u r e a i rpor t , and o n e des t ina t ion a i rpor t .

• Each bookable flight a lways be longs to exactly o n e existing flight schedule .

You manage the data, w i t h o u t redundanc ies , using these relat ionships. The travel agency can p rov ide any data reques ted by the cus tomer .

For each ent i ty in the data model , the deve loper creates a t ransparen t table in the ABAP Dict ionaiy. The ABAP Dict ionaiy is a p l a t fo rm- independen t descr ip t ion o f a database table, not actually the da tabase table itself. However , w h e n a t ranspar-ent table is activated in the ABAP Dict ionaiy, a table o f the same n a m e is auto-matically created wi th in t he database .

Key Concepts Refresher Chapter 6 201

A t ransparen t table conta ins fields that al low y o u to s tore data records in a struc-tured way. You declare s o m e of the table fields as key f ields w h e n they are to be used fo r the u n i q u e ident if icat ion o f data records wi thin the database table. The field o r fields used for this u n i q u e ident if icat ion are also called the p r imary key. You cannot have data records in the same table wi th t he same p r imary key; they each mus t have a u n i q u e p r ima iy key.

In the ABAP Dictionary, a t r ansparen t table is an i m p l e m e n t e d descr ip t ion of the co r respond ing da tabase table that conta ins the actual appl icat ion data. The fields of the t ransparen t table f o rm the identically n a m e d co lumns of t he cor respond-ing da tabase table. Data e l emen t s a re normal ly used to descr ibe the individual fields. The data e l emen t s themselves de f ine keywords and headers and refer to doma ins for their technical proper t ies , thus provid ing t he link b e t w e e n the data object and the d o m a i n .

Wi th in the ABAP Dictionary, a t r ansparen t table is a descr ip t ion of the corre-spond ing da tabase table that conta ins the actual data. The fields of the t ranspar-ent table in the ABAP Dict ionaiy match the identically n a m e d co lumns of the co r respond ing da tabase table. Data e l emen t s a re normal ly used to descr ibe the individual fields. The data e l emen t s themse lves de f ine the semant ic use and refer to d o m a i n s for the i r technical a t t r ibutes , p rov id ing the link b e t w e e n the data object and t he d o m a i n . Programmatical ly, y o u address data e l emen t s in ABAP p rog rams wi th the TYPF s t a t ement . This a l lows y o u to de f ine e l emen ta ry types that have the type a t t r ibutes of a par t icular data e l emen t . These type a t t r ibutes include one of the recognized ABAP Dict ionary data types, the field length, and, w h e r e appropr ia te , the n u m b e r o f decimal places. M o r e in fo rmat ion regarding the ABAP Dict ionary can be f o u n d in Chapter 10.

As well as the list of fields, the t ransparen t tables conta in o the r a t t r ibutes that are requ i red to create a table of t he same n a m e in the da tabase and descr ibe its p rop-ert ies in full:

• The pr imary key fo r the da tabase table (key fields)

• The technical proper t ies requ i red by the database to create the da tabase table (the expected size and expected f r equency of access)

• Settings for technologies that can i m p r o v e p e r f o r m a n c e w h e n accessing the da tabase table (this includes s cconda iy indexes and types o f buf fe r ing)

The def in i t ion of a t r ansparen t table appears to be very similar to t he def in i t ion of a global s t ruc ture type. Transparen t tables can be used in p r o g r a m m i n g in the

202 Chapter 8 SQL Statements Including Update Strategies

same way as s t ruc ture types. For example , they can be used to de f ine a s t ruc tured data object o r a s t ruc ture variable, to type an interface pa ramete r , o r as a l ine type of a global o r local table type. W h e n used this way only the list of fields is impor tan t . The o the r p roper t i es of the t r ansparen t table a re irrelevant w h e n using it as a data type.

O n e o the r d i f fe rence b e t w e e n using a t ransparen t table and s t ruc ture type is that a t ransparen t table only conta ins a list of c l c m e n t a i y fields, bu t the c o m p o n e n t s of a s t ruc ture type can themselves be s t ructured again, p roduc ing nested struc-tures . A c o m p o n e n t o f a s t ruc ture can even be typed wi th a table type, p roduc ing a d e e p s t ruc ture .

In older versions of code (prior to Release 4.0), transparent tables were often

used as data types. It is currently recommended that they only be used directly

in connection with access to the database. It is not recommended that transpar-

ent tables be used in defining user interfaces.

The problem is in the unwanted dependency between the definition of database

objects or interfaces and the user interface.

You can call up detai led in fo rmat ion o n the SAP data mode l (graphical display, data records, and fields) wi th in the SAP d e v e l o p m e n t e n v i r o n m e n t using the SAP Transact ion SD11.

Data Retrieval

Eveiy relational database sys tem has its o w n nat ive SQL. This nat ive SQL is unfo r tuna te ly da tabase specific. Therefore , if y o u wr i te an ABAP program using nat ive SQL, y o u lose much of the s tandard funct ional i ty of an SAP sys tem, for example , access to data being buf fe red on applicat ion servers , the use of the data-base interface, syntax checking, and a n u m b e r of the p e r f o r m a n c e tools.

SAP, to ove rcome this restrict ion provides Open SQL, which is an SAP-defined da tabase - independen t SQL s tandard for ABAP. The O p e n SQL s ta t emen t s a re dynamical ly conver ted to the co r respond ing nat ive SQL s ta tements of the cur-rent da tabase sys tem and are the re fo re i n d e p e n d e n t of the database. They a l low y o u u n i f o r m access to the data, regardless o f the database sys tem installed.

Key Concepts Refresher Chapter 6 189

Before p r o g r a m m i n g direct access to database tables, y o u should look for reuse c o m p o n e n t s that p rov ide a read process . Four types o f reuse c o m p o n e n t s encap-sulate da tabase access:

• Logical databases

• Funct ion modu le s

• BAPIs

• M e t h o d s of global classes

If n o reuse are c o m p o n e n t s available o r usable for y o u r data select ion, y o u have to i m p l e m e n t t he read process yourse l f . It is r e c o m m e n d e d that y o u encapsula te the access in a reuse c o m p o n e n t , that is, c rea te a func t ion m o d u l e o r m e t h o d wi thin a global class.

You use the O p e n SQL s ta tement SELECT to read records f r o m the database . The SELECT s ta tement conta ins a series o f clauses, each of which has a d i f fe ren t task (an example o f the clauses is s h o w n in Listing 8.1):

• The SELECT clause describes which fields o r co lumns of the da tabase t a b l e y o u w a n t to retr ieve.

• The FROM clause ident i f ies the source , e i ther a database table o r view, f r o m which the data is selected.

• The INTO clause de t e rmines the target into which the selected data is placed.

• The WHERE clause specifies the condi t ion that ident i f ies which record o r records y o u will re t reve.

SELECT f l d a t e p l a n e t y p e s e a t s o c c seatsmax FROM s f l i g h t INTO ( f l d a t e . p l a n e t y p e . s e a t s o c c . s e a t s m a x ) WHERE c a r r i d - f l i g h t - c a r r i d ANO connid - f l i g h t - c o n n i d .

ENDSELECT.

List ing 8.1 SELECT Example

A SELECT s ta tement is a loop. However , the re are t w o variat ions that do not behave as a loop: a SELECT SINGLE and an array fetch (using e i ther the addi t ions

INTO TABLE or APPENDING TABLE).

You use the first var iat ion, the SELECT SINGLE s ta tement , to read a single record. Correct usage requi res y o u to provide a u n i q u e access to the record; u n i q u e access requi res y o u to specify all key fields in the WHERE clause. The except ion to

204 Chapter 8 SQL Statements Including Update Strategies

this is the client field, which you do not normally specify because the database interpreter automatically supplies your current client.

! Cau t ion

It is impor tant t o r emember tha t you canno t specify a client in t h e WHERE clause

unless you provide t he clause CLIENT SPECIFIED.

You specify a field list of an asterisk (*) to indicate that all fields of the table row should be read. Ifyou only want specific columns, you list the required fields for the field list. You use the INTO clause to identify the target data object where the read data is placed. The data object you specify in the INTO clause should have the same structure as the field list. As an alternative to specifying a single data object as the target, you can also specify a list of target fields with the INTO clause.

N o t e

Only t h e field types have to match t he target . The names of t he target s t ructure

are no t taken into accoun t . If you w a n t to use a s t ructure variable as a target tha t

has t he s a m e names as t he target list, but has a different s t ructure (additional

fields or a different o rder of fields), you would use t he addi t ion CORRESPONDING

FIELDS OF. This only fills t he fields of t h e same n a m e in t he target area . Again t he

cor responding field types mus t b e the same; otherwise, a conversion takes place,

and it is possible tha t incomple te da ta can be t ranspor ted to t he target field.

The advantages of this variation are:

• The target s t ructure d o e s not have to be left-justified or in the same order as t he field list.

• It is easy to maintain, because extending t he field list or target s t ructure d o e s no t require any o the r changes to be m a d e to t he program, as long as the re is a field in t he s t ructure tha t has t he s a m e n a m e (and preferably t he same type).

The d isadvantage of this variation is that it requires more work f rom the system, and it therefore d o e s no t perform as quickly.

You use a SELECT loop to read several rows of a database table into the program. You use the WHERE clause to determine which rows are read into the target struc-ture and processed using the statement block within the loop body. You can also connect multiple logical conditions within the WHERE clause through the use of AND or OR.

Key Concepts Refresher Chapter 6 205

The da tabase provides the data to the da tabase in terface o f the applicat ion server in blocks called packages. The data is then copied into the target area r o w by r o w for processing.

You use the INTO TABLE addi t ion to copy the data in to an internal table direct ly instead of r o w by row. Pe r fo rmance on this is faster than processing r o w by r o w because the internal table is filled in blocks, no t by rows . Also, because this Array Fetch fills the en t i re internal table in o n e pass, the SELECT is no longer a loop (the second variat ion that is no t a loop) and does not requi re an ENDSELECT. Finally, the Array Fetch replaces the con ten t s of the internal table. I f y o u w a n t to a p p e n d r o w s i n s t e a d . y o u use the APPENDING TABLE add i t ion .

Performance of Database Access

In m a n y cases, the da tabase accesses occupy the major i ty of r u n t i m e of an ABAP appl icat ion. To not over load the sys tem and to keep the wai t t ime for a user to a m i n i m u m , y o u should pay special a t ten t ion to run t ime r e q u i r e m e n t s wi th data-base access in particular. A n u m b e r of technologies are available in Open SQL that enab le y o u to op t imize the r u n t i m e .

Each da tabase manages data records wi th in a da tabase table based o n the con-tents o f key fields. I f y o u r access to the database table is restr icted to all o r at least the first f ew key fields th rough the use of the WHERE clause, the database can re t r ieve the requ i red data very quickly and efficiently. However , should y o u try to access data in a table wi th fields that a re not part of the table key (non-key fields), the da tabase cannot use its indexing of the records for rapid access. In the worse case, the en t i re database table has to be searched for the requ i red entr ies . This is re fer red to as a sequential search. This can p r o d u c e very long wait t imes for the da tabase access.

If y o u access the same non-key field search o f t en , y o u can create a secondary index def in ing the fields conta ined in this non-key field search improve perfor-mance . If the da tabase opt imizer finds a m o r e eff icient way of obta in ing the reques ted data th rough a d i f fe rent index that m o r e closely ma tches the WHERE clause, it will use this secondary index to retr ieve the data.

A secondary index is an index created in addi t ion to the p r imary index of a data-base table. It can be created o r examined by using the INDEXES... b u t t o n o n the application toolbar w h e n displaying a table in e i ther Transact ion SE11 o r SE80.

206 Chapter 8 SQL Statements Including Update Strategies

W h e t h e r an exist ing s cconda iy index is used in a database, access d e p e n d s o n a func t ion in the da tabase sys tem k n o w n as the Database Opt imizer . In O p e n SQL, it is no t possible o r necessa iy to explicitly specify the use of a secondary index i n t h e S E L E C T s t a t e m e n t .

Tip

With selections from client-specified database tables, the client is always trans-

mitted to the database. It therefore makes sense to include the client field as the

first field when you define an index for such tables.

With data retrieval, a m a j o r p ropo r t i on of the r u n t i m e is needed to t ransfe r the data f r o m the da tabase server to the applicat ion server . If t he data is read fre-quen t ly and se ldom changed, y o u can reduce t he r u n t i m e by buf fe r ing the data o n the applicat ion server . The decis ion to bu f fe r data m u s t be m a d e separately for each da tabase table. Because a l imited a m o u n t of bu f fe r space is available on the applicat ion server, the ideal database table is small, read f requent ly , rarely changed , and normal ly accessed directly wi th its key fields. The bu f fe r set t ings are de f ined in the t ransparen t tables in the ABAP Dict ionaiy wi th use o f the TECHNICAL SETTINGS b u t t o n .

Caution

The decision to buffer a database table is not a simple one and should be made

by an experienced ABAP developer in consultation with the system administra-

tor. Each application server contains its own SAP table buffer. If a system is com-

posed of several application servers, a special synchronization mechanism

ensures that database changes will invalidate the corresponding buffer contents.

However, this means that t ime lags in the synchronization process will, for a

short period of time, allow the buffer to be out-of-date or that invalid data could

be read from the buffer. You must take this into account when making a decision

about buffering.

If an ABAP p rog ram requests data f r o m a buf fe red table, the da tabase interface first tries to re t r ieve the data f r o m the SAP table buf fe r . If it is successful , this speeds u p y o u r access b e t w e e n 10 and 100 t imes in contras t to actually re t r ieving it f r o m the database .

The re are also addi t ions for the SELECT s t a t emen t that always cause data to be read directly f r o m the da tabase regardless of the buf fe r set t ings. You should be

Key Concepts Refresher Chapter 6 193

aware o f the possible p e r f o r m a n c e p rob lems that can result using this type of access on buf fe red tables. If y o u f ind it is necessa iy to use a s t a t emen t that bypasses the buffer , y o u should try to min imize the n u m b e r of t imes the state-m e n t is used .

Of ten y o u are requi red to read data f r o m mul t ip le da tabase tables. The use of a table j o i n usually provides the best pe r fo rmance . You mus t specify th ree things w h e n def in ing a table j o in :

• Jo in tables descr ibe wha t da tabase tables should be accessed.

• A j o i n condi t ion descr ibes h o w the records o f the t w o tables a re connec ted .

• Jo in co lumns descr ibe which co lumns f r o m the j o i n tables should be re t r ieved.

There are two op t ions for imp lemen t ing a table j o i n :

• You create a database v i ew in t he ABAP Dict ionaiy that co r r e sponds to a table j o i n and select f r o m it in y o u r p rogram.

• You can i m p l e m e n t a j o i n your se l f using the SELECT s ta tement in y o u r pro-gram (ABAPjoin) (an example is s h o w n in Listing 8.2). At run t ime , the sys tem dynamical ly genera tes an appropr ia t e da tabase que ry in the da tabase inter-face.

Tip

A database view is a view of the relevant database tables and does not contain

data redundantly.

SELECT * FROM s f l i g h t

LEFT JOIN s c a r r ON s f l I g h t - c a r r i d - s c a r r - c a r r i d

INTO CORRESPONDING FIELDS OF TABLE g t _ s f l i g h t WHERE s f l i g h t - c a r r i d IN s . c a r r i d ANO s f l i g h t ~ c o n n 1 d IN s_connid ANO s f l i g h t ~ f l d a t e IN s . f l d a t e .

List ing 8.2 An ABAP Join into a Table

In addi t ion to the SELECT s ta tement , O p e n SQL also conta ins INSERT, DELETE, UPDATE, and MODI FY s ta tements . You should only use these latter s t a t emen t s wi th

208 Chapter 8 SQL Statements Including Update Strategies

an unde r s t and ing of the SAP transact ion concept as discussed be low; o therwise , y o u may cause data inconsistencies.

O n e o r m o r e rows can be processed using an SQL c o m m a n d . C o m m a n d s that process several rows usually provide be t te r p e r f o r m a n c e than the co r r e spond ing single set vers ion. The except ion is mass data change using MOO I FY.

All O p e n SQL c o m m a n d s upda te the sys tem re tu rn code. The re turn value (SY-SUBRC) will be 0 (zero) if the c o m m a n d was successfully executed, and the sys tem field SY - DBCNT will re turn the n u m b e r of rows fo r which the c o m m a n d was car-ried out . Any re turn code o the r than zero indicates tha t the c o m m a n d was unsuc-cessful; the exact mean ing d e p e n d s on the actual c o m m a n d .

Caution

Open SQL commands do not perform any authorization checks automatically.

You must execute these explicitly in your program.

If an O p e n SQL s t a t emen t that executes a change to the database re tu rns a re turn code o the r than zero, y o u should make su re the database is r e tu rned to its orig-inal consis tent s tate be fo re y o u a t t empt to make a n o t h e r da tabase change. To achieve this y o u p e r f o r m a da tabase rollback that reverses all changes in the cur-rent database LUW.

There a re t w o ways o f causing a database rollback:

• Sending a t e rmina t ion dialog message (a message wi th type A [ terminat ion type])

• Using the ABAP s ta tement ROLLBACK WORK

The t ransmiss ion of an A type message causes a da tabase rollback and te rmina tes t he p rog ram. All o the r message types (E (error type), w (warning typel, and I ( informat ion typel) also involve a dialog, bu t do not tr igger a da tabase rollback.

The ABAP s ta tement ROLLBACK WORK causes a database rollback, but does not ter-mina te the p rogram.

Logical Units of Work

An SAP LUW (logical uni t o f work) is a g r o u p of changes that be long toge ther in t he SAP system f r o m a logical poin t of v iew. These changes a re e i ther carr ied out m a d e toge ther o r they are not m a d e at all.

Key Concepts Refresher Chapter 6 209

In gene ra l y o u will n o t n o r m a l l y f ind tha t a bus ine s s t r ansac t ion is p r o c e s s e d b y

a s ingle SAP LUW. T h e e n t i r e p roces s is split u p in to ind iv idua l , logical pa r t s .

Each o f t h e s e par t s c o r r e s p o n d s to a n SAP LUW. T h e d e f i n i t i o n o f SAP LUWs

d e p e n d s o n t h e e n t i r e p roces s a n d its m o d e l i n g .

A d a t a b a s e LUW cons is t s o f c h a n g e s tha t a r e e x e c u t e d unt i l t h e d a t a b a s e s t a tus is

"sea led ," a l so k n o w n as t h e da t a b e i n g c o m m i t t e d to t h e d a t a b a s e ( s h o w n in Fig-

u r e 8.1) . W i t h i n a d a t a b a s e LUW, it is poss ib le to d i sca rd all o f t h e c h a n g e s tha t

h a v e t aken p lace u p to tha t p o i n t t h r o u g h t h e u s e o f a d a t a b a s e ro l lback . A data-

base ro l lback rese t s t h e d a t a b a s e to t h e s t a tus it h a d b e f o r e t h e c u r r e n t d a t a b a s e

LUW. You w o u l d u s e th i s d a t a b a s e ro l lback f u n c t i o n to r e s t o r e t h e p r e v i o u s con-

s is ten t d a t a b a s e s t a tus if an e r r o r has o c c u r r e d .

D a t a b a s e L U W

Figure 8.1 SAP LUW within a Database LUW

W h e n y o u use t h e ABAP s t a t e m e n t s ROLLBACK WORK a n d COMMIT WORK, y o u explic-

itly i m p l e m e n t a d a t a b a s e rol lback o r d a t a b a s e c o m m i t . T h e r e a r e a lso in s t ances

w h e n a d a t a b a s e c o m m i t is t r igge red implic i t ly . Impl ic i t d a t a b a s e c o m m i t s a re

a lways in i t ia ted w h e n e v e r t h e p r o g r a m has to wa i t (as par t o f t h e re lease o f t h e

w o r k process) , such as in t h e f o l l o w i n g cases:

• W h e n t h e s y s t e m s e n d s an SAP sc reen to t h e p r e s e n t a t i o n layer

• W h e n t h e s y s t e m s e n d s a d ia log m e s s a g e to t h e p r e s e n t a t i o n layer

• W h e n e v e r t h e r e a r e s y n c h r o n o u s a n d a s y n c h r o n o u s RFC calls ( R e m o t e Func-

t ion Call)

• S t a t e m e n t s C A L L T R A N S A C T I O N < t c o d e > o r S U B M I T <program>

I f y o u e n c o u n t e r an e r r o r d u r i n g t h e p r o c e s s i n g o f an SAP LUW, it s h o u l d b e pos-

sible to r e t u r n to a c o n s i s t e n t d a t a b a s e s t a tus tha t ex i s t ed b e f o r e t h e b e g i n n i n g

o f t h e SAP LUW. For th is to b e poss ib le , t h e SAP L U W m u s t b e p laced w i t h i n a

d a t a b a s e LUW.

210 Chapter 8 SQL Statements Including Update Strategies

Caution

With the above implicit database commits, you cannot place changes that belong to an SAP LUW in different dialog steps (a dialog step is the program pro-cessing after a screen). This would place these steps in a separate database LUW, violating the SAP LUW.

This is not a trivial matter. Usually the SAP transaction has several screens or a sin-gle screen with multiple subscreens in the form of a tab strip, and whenever there is a screen change (a full screen or subscreen), an implicit database commit is trig-gered. You must be able to bundle the entries from the user that form the SAP LUW from different screens and make these changes within the database LUW.

The three-t ier archi tecture m e a n s that m a n y users wi th low-cost personal com-puters (with low pe r fo rmance ) can be m a p p e d to a small n u m b e r of high-perfor-mance and cons iderably m o r e expens ive work processes on applicat ion servers . Each work process on an applicat ion server is assigned a work process on a high-p e r f o r m a n c e da tabase server . Dis t r ibut ing user reques ts t o work processes means that individual cl ients at the presen ta t ion server level a re ass igned to a work process for a par t icular pe r iod . Af te r the work process has processed the user inpu t in a dialog s tep, the user a long wi th the p rog ram context is r emoved f r o m the work process, thus f ree ing it for a n o t h e r user .

With the three- t ier archi tecture , the n u m b e r of da tabase users is cons iderably lower than the n u m b e r of active users in the sys tem. This has a posit ive effect o n the behav ior of the database . Releasing the work process b e f o r e each user dialog ensu res that the user actions, normal ly longer lasting than the actual sys tem pro-cessing, d o not block any work processes o n the applicat ion server and particu-larly on the database server . This p roduces a smal ler load o n da tabase resources . Only w h e n the user has comple ted processing the screen, requi r ing the p rogram processing to cont inue , is the p rogram con tex t rolled back in.

Enqueue and Dequeue

If several users are compe t ing for access to the same table or tables, y o u need to f ind a way of synchroniz ing access to pro tec t the consistency of the data. Locks are a way of coord ina t ing compe t ing access to a resource . Each user reques ts a lock be fo re accessing critical data to p reven t o the r users f r o m mod i fy ing it be fo re this use is comple te . It is impor t an t to obta in the lock as late as possible and

Key Concepts Refresher Chapter 6 211

re lease it as qu ick ly as poss ib le so as to n o t c r ea t e a b o t t l e n e c k f o r o t h e r use r s

unneces sa r i l y .

T h e Database Management System (DBMS) physical ly locks t h e table l ines tha t a r e r ead w i t h t h e i n t e n t o f b e i n g c h a n g e d ( S E L E C T S I N G L E <f> FROM < d b t a b > FOR U P D A T E ) . This is a d a t a b a s e lock. O t h e r use r s w h o w a n t to access t h e locked r e c o r d o r r e c o r d s m u s t wa i t unt i l a f t e r t h e physica l lock is r e leased . T h e lock r e m a i n s unt i l t h e e n d o f a d a t a b a s e LUW. t r igge red by t h e d a t a b a s e c o m m i t , w h e n t h e Da tabase M a n a g e m e n t Sys tem re leases all locks tha t w e r e set d u r i n g t h e d a t a b a s e LUW.

W i t h i n t h e SAP s y s t e m , th is m e a n s each d a t a b a s e lock is re leased w h e n e v e r a s c reen is d i sp l ayed b e c a u s e t h e s c r e e n c h a n g e t r iggers an impl ic i t d a t a b a s e c o m -mi t . Da t abase locks a r e n o t su f f i c i en t if da t a is co l lec ted t h r o u g h o u t severa l s c r e e n s a n d a rc r e q u i r e d to r e m a i n locked .

To k e e p a lock t h r o u g h a ser ies o f s c reens , t h e SAP s y s t e m has a g lobal lock tab le o n o n e app l i ca t ion s e r v e r tha t is u s e d to se t logical locks f o r table en t r i e s (see Fig-u r e 8 .2) . T h e lock tab le a n d t h e e n q u e u e w o r k p roces s tha t m a n a g e s t h e lock table is o n a u n i q u e l y d e f i n e d app l i ca t ion s e r v e r o f t h e SAP sys t em. T h e s e r v e r c o n t a i n i n g th is e n q u e u e w o r k p roces s is k n o w n as t h e central instance. All o f t h e logical lock r e q u i r e m e n t s o f t h e SAP sys t em, r ega rd less o f w h i c h app l i ca t ion se rve r r e q u e s t e d t h e lock, r u n o n th is s y s t e m - w i d e , u n i q u e w o r k p rocess .

It is also p o s s i b l e to u s e logical locks to " lock" tab le e n t r i e s tha t d o n o t y e t ex is t w i t h i n t h e d a t a b a s e . This is u se fu l w h e n y o u c rea t e n e w tab le r o w s , a n d is n o t poss ib l e w i t h d a t a b a s e locks.

You set a logical lock b y cal l ing t h e lock m o d u l e . Th is special , t ab le - re la ted func -t ion m o d u l e is c r ea t ed au toma t i ca l l y w h e n y o u ac t iva te a t ab le - re la ted lock ob jec t . W h e n y o u call t h e lock m o d u l e , logical locks a r e se t f o r t h e en t r i e s in t h e r e spec t ive tab les .

You m a i n t a i n lock o b j e c t s in t h e ABAP Dic t iona iy . The c u s t o m e r n a m e s p a c e f o r lock o b j e c t s is e i t h e r EY o r EZ . W h e n y o u c rea t e a lock ob jec t , y o u spec i fy t h e tab le w h o s e en t r i e s will b e locked la ter . This is k n o w n as t h e primary o r basis table. H o w e v e r , y o u can spec i fy o t h e r tab les tha t h a v e a f o r e i g n key r e l a t i o n s h i p to the p r i m a i y table, w h i c h a re k n o w n as secondary tables.

T h e lock m o d u l e c r ea t ed b y t h e s y s t e m au toma t i ca l ly c o n t a i n s i n p u t p a r a m e t e r s

f o r the lock p a r a m e t e r s . T h e lock p a r a m e t e r s a re u s e d to c o m m u n i c a t e w i t h t h e

lock m o d u l e w h i c h r e c o r d s a re to b e logically locked a n d cons is t o f t h e key fields

212 Chapter 8 SQL Statements Including Update Strategies

of the p r i ma iy tabic. W h e n t he lock objcc t is successfully activated, the sys tem genera tes one func t ion m o d u l e for creat ing o r e n q u e u i n g a lock and o n e func t ion m o d u l e for releasing o r d e q u e u i n g a lock. The func t ion modu le s are n a m e d ENQUEUE_<1ock_object_name> and DEQUEUE_<lock_object_name>. A logical lock is set w h e n y o u call the e n q u e u e func t ion modu le , bu t y o u can only create a lock if no o the r lock e n t i y conflicts wi th it. The lock m o d u l e p roduces an excep-t ion if the lock cannot be ob ta ined .

Figure 8.2 Locking Data through Database LUWs

Depend ing on the bund le t echn ique used for da tabase updates , an applicat ion p rogram may need to delete the lock en t r ies it c reated (for an inl ine update) o r have t h e m de le ted automatical ly (dur ing the upda te task). If a p rog ram that cre-ated lock entr ies is t e rmina ted , the locks are automatical ly released (implicitly). A p rogram te rmina t ion occurs wi th the p roduc t ion of a message of e i ther type A or X, wi th the execut ion of the s t a t emen t s LEAVE PROGRAM and LEAVE TO TRANS ACTION, o r if the user en t e r s " /n" in the c o m m a n d field.

Key Concepts Refresher Chapter 6 199

At the e n d o f the d ia log p r o g r a m o r w h e n p r o c e e d i n g to a n o t h e r r eco rd , y o u call t h e DEQUEUE f u n c t i o n m o d u l e to re lease the lock e n t r i e s in t h e lock table . Unl ike t h e ENQUEUE f u n c t i o n m o d u l e , t h e DEQUEUE f u n c t i o n m o d u l e s d o n o t t r igger a n y e x c e p t i o n s . If y o u w a n t to re lease all locks, y o u can u s e t h e f u n c t i o n m o d u l e

DEQUEUE_ALL.

I f y o u call a lock m o d u l e w i t h a lock p a r a m e t e r set to its initial va lue o r n o t spec-i f ied, t h e sys t em will i n t e r p r e t th i s a s a g e n e r i c va lue a n d lock all t ab le l ines ba sed o n t h e p a r a m e t e r va lues y o u d id s u p p l y . T h e cl ient p a r a m e t e r is an e x c e p t i o n to th is ru le . If t h e c l ient is n o t p r o v i d e d w h e n t h e ENQUEUE f u n c t i o n is cal led, t h e lock o n l y app l i e s to t h e c u r r e n t e x e c u t i o n c l ien t . If t h e c l ient is spec i f i ed , t h e lock on ly app l i e s to tha t c l ient . If t h e c l ien t is spec i f i ed as a space , t h e lock app l i e s to all c l ients .

You can o v e r r i d e t h e d e f a u l t lock m o d e o f t h e lock m o d u l e spec i f i ed in t h e lock o b j e c t b y us ing t h e p a r a m e t e r o v e r r i d e MODE_<tablename>. T h e p a r a m e t e r X_ < l o c k _ p a r a m e t e r > a l lows y o u to lock table r e c o r d s tha t c o n t a i n an init ial va lue in t h e c o r r e s p o n d i n g lock p a r a m e t e r .

• T h e p a r a m e t e r _ S C 0 P E d e f i n e s t h e va l id i ty a rea o f t h e lock. T h e va lues a n d t h e i r m e a n i n g s a re s h o w n in Tab le 8 .1 .

Value Meaning

The lock remains in the program that set it and is deleted again by the program. This is for use with inline updates.

The lock is passed to the update program or called programs (this is the default). This is for updates through an update program.

Two locks are set. One stays with the program and must be deleted within the program. The other is passed to the update program. This is required whenever the update task is triggered for a partial update, but the record should remain locked in the program for further updates.

Table 8.1 Scope Parameters

• T h e _WA IT p a r a m e t e r d e f i n e s w h e t h e r a lock r e q u e s t s h o u l d b e r e p e a t e d if t h e f irst lock a t t e m p t fails.

• You u s e t h e . C O L L E C T p a r a m e t e r to s t o r e t h e lock r e q u e s t in a local lock con-t a i n e r un t i l t h e lock c o n t a i n e r is co l lec ted a n d passed o n as a un i t to the e n q u e u e se rve r .

200 Chapter 8 SQL Statements Including Update Strategies

R e q u e s t i n g a n y lock f r o m a p r o g r a m is a c o m m u n i c a t i o n s t e p w i t h lock a d m i n -i s t ra t ion . I f y o u set a lock f o r severa l ob jec ts , th is c o m m u n i c a t i o n occurs f o r each lock. If y o u u s e t h e local lock c o n t a i n e r , y o u can r e d u c e t h e technica l e f f o r t f o r th is s t e p . You se t t h e p a r a m e t e r . C O L L E C T - " X ' w h e n e v e r y o u call t h e lock m o d -ule. This collects t h e lock r e q u e s t s in t h e local lock c o n t a i n e r fo r p r o c e s s i n g t oge the r . You s e n d t h e c o n t e n t s o f t h e lock c o n t a i n e r w i t h t h e f u n c t i o n m o d u l e F L U S H _ E N Q U E U E .

If y o u a re ab le to success fu l ly o b t a i n all lock r eques t s , t h e s y s t e m de l e t e s t h e e n t i r e c o n t e n t s o f t h e local lock c o n t a i n e r . If o n e o f t h e locks in t h e c o n t a i n e r is no t success fu l a n d c a n n o t b e set , t h e f u n c t i o n m o d u l e t r iggers t h e e x c e p t i o n FORE I G N _ L 0 C K . W h e n this h a p p e n s , n o n e o f t h e locks r eg i s t e red in t h e c o n t a i n e r a re set , a n d t h e c o n t e n t s o f t h e c o n t a i n e r wil l r e m a i n in tac t f o r f u r t h e r d i spa t ch a t t e m p t s . If y o u n e e d to d e l e t e t h e c o n t e n t s o f t h e local lock c o n t a i n e r , y o u call t h e f u n c t i o n m o d u l e RESET_ENQUEUE.

Table 8 .2 s h o w s t h e e f fec t o f t h e M O D E _ < t a b l e n a m e > p a r a m e t e r .

Lock Mode Meaning

Extensible — lock for data change (accumulative exclusive lock)

x Exclusive — lock for data change (exclusive write lock)

Shared — lock for protected data display (shared lock)

Table 8.2 Lock Modes

T h e o n l y d i f f e r e n c e b e t w e e n m o d e s E a n d X is tha t F a l l ows a c c u m u l a t i o n o f locks a n d x d o e s n o t a l l o w a c c u m u l a t i o n o f locks. You i m p l e m e n t t h e m o d e S if y o u w i s h to e n s u r e tha t t h e da t a d i sp l ayed in y o u r p r o g r a m c a n n o t b e c h a n g e d b y o t h e r use r s w h i l e it is d i sp l ayed . This is a case w h e r e y o u a re n o t a t t e m p t i n g to c h a n g e t h e da ta , bu t d o no t w a n t a n y o n e e l se c h a n g i n g t h e da t a w h i l e y o u a r e u s ing it.

Exis t ing exc lus ive locks (E o r X) a lways re jec t e v e r y lock a t t e m p t o f a n o t h e r user , r ega rd less o f t h e m o d e u s e d b y the o t h e r use r . An ex i s t ing s h a r e d lock ( S ) , a l lows o t h e r s h a r e d locks f o r p r o t e c t e d d i sp lay .

Key Concepts Refresher Chapter 6 201

Caut ion

If you want to ensure tha t you are using u p - t o - d a t e da t a in your program with t he intention of changing t h e da ta and then saving it t o t h e da tabase , you mus t perform the following s teps in this o rder ( the later on fol lowing Figure 8 .3 shows these four points with the cor responding numbers) :

• Set locks for the da ta to b e processed .

• If t he lock is successfully set. read t he current data f rom the da tabase table.

• Change t he program da t a and upda t e the changes t o the da tabase .

• Release t he locks you set .

This order ensures tha t you only read da ta tha t has been changed consistently by o the r programs and tha t your changes run complete ly under t he protect ion of locks. This assumes tha t all application programs use t he SAP lock concep t and a d h e r e to t he given s t ep sequence .

If you d o no t adhe re to t he sequence , the re is t he danger tha t your program will read da ta f rom the da tabase that is currently locked by ano the r program. In this case, even if t he lock is successfully set af ter t h e read act ion, t he da ta read by your program and displayed is already ou t of da te .

L i s t ing 8 . 3 s h o w s a call t o a lock o b j e c t w i t h a M 0 0 E _ < t a b l e n a m e > p a r a m e t e r , a

_SC0PE p a r a m e t e r , a n d a _WAIT p a r a m e t e r s p e c i f i e d . Y o u s h o u l d n o t e t h e p a r a m -

e t e r n a m e d x_name. T h i s p a r a m e t e r , if s u p p l i e d w i t h an 1 X ' , p r e v e n t s t h e p a r a m -

e t e r name f r o m b e h a v i n g in a g e n e r i c m a n n e r a n d i n s t e a d l ocks a b l a n k v a l u e .

CALL FUNCTION 'ENOUEUE_ESRDIRE" EXPORTING

m o d e _ t r d 1 r - l _enq_mode name - i n c l 2 x_name - ' * _ s c o p e - ' 2* _ w a i t - ' '

EXCEPTIONS f o r e i g n _ l o c k - 01 s y s t e m _ f a i l u r e - 0 2 .

IF s y - s u b r c NE 0 AND r s 3 8 1 - e x t e r n - s p a c e . MESSAGE ID s y - m s g i d

TYPE ' E ' NUMBER s y - m s g n o WITH s y - m s g v l s y - m s g v 2 s y - m s g v 3 s y - m s g v 4 .

ENDIF.

Listing 8.3 Call t o a Lock Objec t

202 Chapter 8 SQL Statements Including Update Strategies

Inline Updates

If y o u r t r ansac t ion m a k e s d a t a b a s e u p d a t e s f r o m w i t h i n y o u r d ia log p r o g r a m ( in l ine upda te s ) , y o u m u s t b u n d l e all o f t h e d a t a b a s e c h a n g e s i n to a s ing le d ia log s tep , n o r m a l l y t h e last. Th is is t h e o n l y w a y to e n s u r e tha t all o f y o u r d a t a b a s e c h a n g e s a r e p r o c e s s e d as a s ingle un i t . To accompl i sh th i s w i t h i n y o u r d ia log p ro -g r a m , t h e c h a n g e s a re s t o r e d w i t h i n t h e g lobal da ta o f t h e p r o g r a m unt i l t h e p o i n t w h e r e t h e c h a n g e s wil l b e m a d e to t h e d a t a b a s e .

If y o u u p d a t e t h e d a t a b a s e d i rec t ly f r o m w i t h i n y o u r p r o g r a m , y o u m u s t set a n d

re lease t h e SAP locks. Use t h e s t eps in t h e p r e v i o u s cau t ion b o x a n d s h o w n in the

la ter o n f o l l o w i n g F igure 8 . 3 to e n s u r e access to c o n s i s t e n t da ta .

Tip

Remember that in this case your program must delete the lock entries. To release the lock entry you execute either the unlock function module DEOUEUE_<lock_ object>, which belongs to the lock object, or the general unlock function mod-ule DEQUEUE_ALL, which releases all lock entries.

Perform on Commit

You can b u n d l e d a t a b a s e u p d a t e s f r o m a d ia log p r o g r a m f o r e x e c u t i o n by us ing t h e special s u b r o u t i n e t e c h n i q u e PERFORM < s u b r o u t i n e > ON C O M M I T . Th is regis-ters t h e spec i f i ed s u b r o u t i n e f o r e x e c u t i o n , b u t t h e s u b r o u t i n e wil l n o t b e exe-c u t e d un t i l t h e s y s t e m r eaches t h e n e x t COMMIT WORK s t a t e m e n t . If y o u e n c a p s u l a t e t h e d a t a b a s e u p d a t e s in t h e s u b r o u t i n e s , t h e y can b e s e p a r a t e d f r o m t h e p r o g r a m logic a n d p r o c e s s e d at t h e e n d o f t h e LUW.

A s u b r o u t i n e r eg i s t e red w i t h PERFORM ON COMMIT can b e r eg i s t e red m u l t i p l e t imes , b u t o n l y e x e c u t e s o n c e p e r L U W in t h e o r d e r it w a s first r eg i s t e red . If y o u nes t PERFORM ON C O M M I I calls a f t e r Release 4 . 6 a r u n t i m e e r r o r , will b e t r i gge red . T h e COMMI T WORK s t a t e m e n t car r ies o u t all s u b r o u t i n e s r eg i s t e red to b e e x e c u t e d , in t h e reg i s t ra t ion o r d e r o n e a f t e r t h e o t h e r , a n d t h e n t r iggers a d a t a b a s e c o m m i t a f t e r p r o c e s s i n g all r eg i s t e red s u b r o u t i n e s . If y o u e n c o u n t e r an e r r o r d u r i n g the p roces s ing of a r eg i s t e red s u b r o u t i n e , y o u can t e r m i n a t e p r o c e s s i n g f r o m w i t h i n t h e s u b r o u t i n e w i t h a t y p e A message , a n d t h e p r e v i o u s cons i s t en t d a t a b a s e s ta tus will b e r e s t o r e d .

Key Concepts Refresher Chapter 6 203

T h e s u b r o u t i n e s called w i t h PERFORM ON COMMIT c a n n o t h a v e an in t e r f ace . T h e y

m u s t w o r k w i t h g lobal da t a a n d will use t h e va lues t h e da t a o b j e c t s c o n t a i n a t t h e

p o i n t w h e n t h e s u b r o u t i n e is actual ly r u n .

Update Modules

U p d a t e t e c h n i q u e s a l l o w y o u to s e p a r a t e t h e u s e r d ia log p r o g r a m used to accept

u s e r e n t r i e s a n d t h e p r o g r a m tha t u p d a t e s t h e da ta in t h e d a t a b a s e . F igure 8 .3

s h o w s t h e s t eps tha t occu r w h e n a p r o g r a m uses a n u p d a t e r e q u e s t :

1. T h e d ia log p r o g r a m rece ives t h e da ta c h a n g e d by t h e use r a n d w r i t e s it t o a special log tab le us ing an e n t r y cal led a r e q u e s t . Later t h e u p d a t e p r o g r a m w r i t e s t h e da t a c o n t a i n e d w i t h i n t h e log tab les to t h e d a t a b a s e . T h e d ia log p r o g r a m m a y w r i t e severa l e n t r i e s to t h e log table . T h e en t r i e s in t h e log tab le r e p r e s e n t t h e LUW.

2 . T h e d ia log p r o g r a m c loses t h e da ta packe t (LUW) a n d i n f o r m s t h e Basis sys-t e m tha t a packe t ex is t s f o r u p d a t e by c rea t ing a h e a d e r f o r t h e r e q u e s t r e co rds .

3 . A Basis p r o g r a m r e a d s t h e da t a assoc ia ted w i t h t h e LUW f r o m t h e log table

a n d supp l i e s it t o t h e u p d a t e p r o g r a m .

4 . T h e u p d a t e p r o g r a m accep t s t h e t r a n s f e r r e d da ta a n d u p d a t e s t h e d a t a b a s e

w i t h t h e en t r i e s in t h e r eques t .

5 . If the u p d a t e is success fu l , a Basis p r o g r a m de l e t e s all e n t r i e s f o r th is L U W f r o m t h e log table . If an e r r o r occurs , t h e en t r i e s r e m a i n in t h e log table , a l t h o u g h they a re f lagged as i nco r r ec t . T h e use r w h o t r igge red t h e u p d a t e is n o r m a l l y ( the b e h a v i o r is c o n t r o l l e d by cer ta in sys t em p a r a m e t e r s ) i n f o r m e d b y e x p r e s s mai l a b o u t t h e e r r o r .

You i m p l e m e n t t h e u p d a t e p r o g r a m as a special f u n c t i o n m o d u l e k n o w n as an

u p d a t e m o d u l e . U p d a t e m o d u l e s o n l y h a v e an i n t e r f a c e f o r t r a n s f e r r i n g da t a

t h r o u g h t h e I M P O R T I N G a n d T A B L E S p a r a m e t e r s . T h e s e m u s t b e t y p e d us ing ref-

e r e n c e f ie lds o r s t r u c t u r e s .

You c rea t e u p d a t e r e q u e s t s by cal l ing t h e r e spec t ive u p d a t e f u n c t i o n m o d u l e in a d ia log p r o g r a m us ing t h e I N UPOATE T A S K add i t i on . This a d d i t i o n w r i t e s t h e f u n c t i o n m o d u l e a n d the i n p u t da ta as an e x c e p t i o n r e q u e s t a n d d o e s no t e x e c u t e t h e f u n c t i o n m o d u l e i m m e d i a t e l y .

204 Chapter 8 SQL Statements Including Update Strategies

W o r k Process

Dialog Program Update Program

Figure 8.3 Process Flow of an Update

T h e s a m e u p d a t e key is u s e d to s to re all o f t h e u p d a t e f lags f o r an SAP I .UW. W h e n t h e s y s t e m execu te s a COMMIT WORK s t a t e m e n t , it c rea tes a h e a d e r e n t r y f o r t h e r e q u e s t en t r i e s , a n d t h e n t h e u n i t is c losed . T h e log h e a d e r c o n t a i n s i n f o r m a -t ion a b o u t t h e d ia log p r o g r a m tha t w r o t e t h e log e n t r i e s a n d the u p d a t e m o d u l e s to b e e x e c u t e d . O n c e t h e log h e a d e r is c r ea t ed , t h e s y s t e m i n f o r m s t h e d i s p a t c h e r p roces s tha t an u p d a t e package is ava i lab le f o r p roces s ing .

You m a y n e e d to d i sca rd all c h a n g e r e q u e s t s tha t w e r e w r i t t e n f o r t h e c u r r e n t SAP LUW. To d i sca rd t h e c u r r e n t SAP LUW d u r i n g the g e n e r a t i o n phase , w h i c h is b e f o r e t h e c o m m i t w o r k occurs , as y o u d o w i t h an in l ine u p d a t e , y o u use t h e ABAP s t a t e m e n t ROLLBACK WORK o r p r o d u c e a t y p e A m e s s a g e .

Both m e t h o d s de l e t e all p r e v i o u s u p d a t e flags, de l e t e all p r e v i o u s l y set locks, dis-card all u p d a t e s e x e c u t e d in t h e c u r r e n t d a t a b a s e LUW, a n d d i sca rd all f o r m rou-t i ne s r eg i s t e red u s i n g PERFORM ON C O M M I T .

If y o u n e e d to t r igger a d a t a b a s e ro l lback w i t h i n t h e u p d a t e m o d u l e , y o u i ssue a

t y p e A m e s s a g e . T h e p roces s ing o f t h e c u r r e n t SAP LUW will b e t e r m i n a t e d , a n d

t h e log e n t i y b e l o n g i n g to t h e SAP LUW is f lagged as c o n t a i n i n g a n e r r o r . T h e

t e r m i n a t i o n m e s s a g e is a l so e n t e r e d in t h e log.

Listing 1 2 . 4 s h o w s a call t o a m o d u l e f r o m an SAP N e t W e a v e r 7 . 0 s y s t e m . N o t e

t h e I N UPDATE TASK f o l l o w i n g t h e f u n c t i o n m o d u l e n a m e .

Key Concepts Refresher Chapter 6 205

CALL FUNCTION *WFRULES_WRITE_00CUHENT' IN UPDATE TASK EXPORTING

o b j e c t i d - o b j e c t i d tcode - tcode u t ime - u t ime udate - udate username - username planned_change_number - pianned_change_number upd_twfns upd_twfsa

TABLES x t w f n s y t w f n s x tw fsa y t w f s a

upd_twfns upd_twfsa

x t w f n s y t w f n s x tw fsa y t w f s a .

Listing 8 . 4 Call to an Upda te M o d u l e

Figure 8.4 shows the attributes of the called update module. Note the first three options below the UPDATE MODULE radio button. The first two, which cause an immediate start of the update module, cause the update module to run as a V1 (a primary or time-critical update), whereas the third causes the update module to run as a V2 (a secondary or non-time-critical update).

Functon module «FRUlES_«filIE_OOaiH£HT ACth*

• A ' M I I - M I M Import | Bpor t | Changing , T I M H Exceptors Source code

Classification

FuncDon Of o jp WFRC ===» Objec IV* RULES

Short Tea = » ObiettWFRULES

Processing T«ie General Data

O Normal Function Module Person R e s p o n s e SW

O Remo(e-Enaw*d Module Last Changed By SAP

® Update Module Changed on 06 /26 /1998 ]

O Start n m M Package SWfl

O Immeoate Start. No Restart Program Name SAPLYFRC

® Start Delayed WCLUOE Name LkFRCUOl

O Coll run Original Language DE

N « released

Figure 8 .4 At t r ibutes of t h e Upda te M o d u l e

220 Chapter 8 SQL Statements Including Update Strategies

Listing 8 .5 s h o w s t h e b e g i n n i n g o f t h e u p d a t e m o d u l e c o d e . N o t e tha t w h e n an

e r r o r c o n d i t i o n is f o u n d , a t y p e a m e s s a g e is u s e d to a b o r t t h e p rocess , log the

cause o f t h e e r r o r , a n d a b o r t the u p d a t e . You c a n n o t use t h e expl ic i t ABAP state-

m e n t s c o m m i t w o r k o r r o l l b a c k w o r k in an u p d a t e m o d u l e .

FUNCTION w f r u l e s . w r i t e . d o c u m e n t

CALL FUNCTION 'CHANGEOOCUMENT_OPEN' EXPORTING

o b j e c t c l a s s o b j e c t i d p ianned_change_number p i a n n e d _ o r _ r e a l _ c h a n g e s

EXCEPTIONS s e q u e n c e _ i n v a l i d OTHERS

CASE s y - s u b r c . WHEN 1. MESSAGE a600 WITH WHEN 2 . MESSAGE a600 WITH

ENDCASE.

Listing 8.5 Code of an Update Module

If y o u se t locks in t h e d ia log p r o g r a m w i t h t h e u p d a t e t e c h n i q u e w i t h _ s c o p e -

2, t h e s e a r e passed o n to t h e u p d a t e task a t COMMIT WORK. A f t e r t h e c o m m i t , t h e

locks a r e n o l o n g e r access ib le by t h e d ia log p r o g r a m . T h e s e locks a re a u t o m a t i -

cally re leased by a Basis p r o g r a m at t h e e n d o f t h e u p d a t e p roces s a n d d o no t

n e e d to b e re leased expl ici t ly in t h e u p d a t e m o d u l e . T h e re lease o f locks at the

e n d o f t h e u p d a t e task a l w a y s takes p lace rega rd less o f t h e success o f t h e task.

A s y n c h r o n o u s u p d a t e s a l low t h e d ia log p r o g r a m a n d u p d a t e p r o g r a m to r u n sep-

ara te ly . T h e d ia log p r o g r a m w r i t e s c h a n g e r e q u e s t s to t h e log tab le a n d w i t h a

COMMIT WORK c loses t h e LUW. T h e u p d a t e task is s t a r t ed by t h e COMMIT WORK a n d

p rocesses t h e c h a n g e r eques t s . Th is lets t h e d ia log p r o g r a m c o n t i n u e w i t h o u t

h a v i n g to wa i t f o r t h e u p d a t e to c o m p l e t e . A special u p d a t e w o r k p roces s r u n s

t h e u p d a t e p r o g r a m .

A s y n c h r o n o u s u p d a t e s a re use fu l in t r a n s a c t i o n s w h e r e t h e d a t a b a s e u p d a t e s can

take a l ong t ime a n d w h e r e it is i m p o r t a n t tha t t h e use r d ia log r e s p o n s e t ime , in

o t h e r w o r d s , t h e p e r c e i v e d p e r f o r m a n c e , is i m p o r t a n t . You wil l f ind tha t a syn-

c h r o n o u s u p d a t i n g is t h e s t a n d a r d t e c h n i q u e used in d ia log p r o g r a m m i n g .

- 'WFRULES - o b j e c t i d - p l anned_change_number - p l a n n e d _ o r _ r e a l _ c h a n g e s

- 1 - 2.

'SEOUENCE INVALID*. •OPEN ERROR'.

Key Concepts Refresher Chapter 6 221

A synch ronous upda te is t r iggered by the s t a t emen t COMMIT WORK AND WAIT. In this case, the dialog p rogram wai ts for the u p d a t e to end be fo re the p rog ram pro-cessing cont inues . You w o u l d use a syn c h r o nou s u p d a t e m o d e if the result of the upda te is necessary for f u r t h e r processing o r a dialog p rogram te rmina t ion . You d e t e r m i n e the processing success of a syn c h r o nou s upda te by examin ing the sys-tem field S Y - SUBRC w h e n using COMMIT WORK AND WA IT. Whi le wai t ing for the syn-c h r o n o u s upda te to comple te , the dialog p rog ram is in a rolled-out s tate . This m e a n s the dialog work process is released for f u r t h e r use . W h e n the u p d a t e com-pletes, the system assigns t he dialog p rog ram to a f ree dialog work process to con t inue processing.

With local updates , every th ing runs in a single work process. The upda te func-t ions are run in the same dialog process used by the dialog p rog ram. Processing of the dialog p rogram con t inues af ter the u p d a t e is comple te . This is a n o t h e r f o rm of synch ronous upda te . To have the upda te modu le s executed locally, y o u mus t use the s t a tement SET UPDATE TASK LOCAL be fo re y o u wr i t e the requests . W h e n t he reques ts a re closed wi th t he COMMIT WORK, these upda tes a re processed in the same dialog work process. Af te r the local upda te is successfully processed, a database commi t is initiated explicitly, and the dialog p rog ram cont inues .

If an e r ro r occurs, a n d o n e of t he u p d a t e modu le s p roduces a t e rmina t ion mes-sage, the sys tem executes an au tomat ic da tabase rollback to discard the changes in the cu r ren t LUW, a n d the dialog p rogram is t e rmina ted wi th the display of t he t e rmina t ion message.

W h e n y o u are in the local u p d a t e mode , changes a re not wr i t t en to the database table VBL06, but instead are kept in m e m o i y . This makes this upda te quicker than e i ther synch ronous o r a synch ronous upda tes ; however , because this has an exclusive use of a work process, it is only app rop r i a t e in batch m o d e . The SET UPDATE TASK LOCAL is only possible i f y o u have not created any reques ts for t he cur ren t LUW a n d is only in effect until t he next COMMIT WORK.

There are two types of upda te modules : V1 and V2. The type o f u p d a t e m o d u l e de t e rmines its processing m o d e . All V1 reques ts in the dialog p rogram are exe-cuted as i n d e p e n d e n t da tabase LUWs. Only if they are executed successfully are the V2 reques ts processed. These are also executed as i n d e p e n d e n t database LUWs.

• V2 upda te modu le s a re used for database changes that a re l inked to the VI change, bu t that are not necessa iy to have comple ted wi th the main change, for eample , t he upda t ing of statistics.

222 Chapter 8 SQL Statements Including Update Strategies

• V I modules can be either restartable or non-restartable. I f there is an update

error, you can manually restart requests that were created by restartable

update modules using Transaction S M I 3. You can always restart V2 update

modules i f there is an error.

" i " Tip

Each t ime a da ta change is m a d e to t he da tabase , t he da tabase physically locks t he record t o the end of t he current da tabase LUW. ei ther t he da tabase commit or da tabase rollback. The s a m e is t rue if you are reading with SELECT . . . FOR UPDATE. However, read accesses to a record are not al lowed for t he dura t ion of t he physical lock, and many programs execute read access wi thou t locks. You should a t t e m p t t o keep t he se da tabase locks as short as possible for per formance reasons.

You should adhe re to t h e following rules w h e n programming inline changes and

upda t e modules :

• Create n e w table entr ies first. Their da tabase locks p roduce t he least impact on

o the r users.

• You should perform table upda tes tha t a re no t critical to per formance . Gener-

ally. t he se tables a re accessed s imultaneously by relatively few users.

• You should change central resources in t h e system late, if possible, within an LUW so tha t t he da tabase locks only impact o thers for as short a t ime as pos-sible.

During t he upda te , t he goal is to execu te changes to central tables ( those tables tha t are per formance critical and of ten accessed simultaneously by several users) as late as possible in t he LUW. O n e m e t h o d to accomplish this is to use t he PER-FORM ON COMMIT techn ique within t he upda te . I f y o u encapsu la te changes to cen-tral tables as form rout ines within the appropr ia te funct ion g r o u p of t he upda t e module and then call t he rout ines f rom within t he upda t e m o d u l e using t he PER-FORM ON COHHIT. t he form routines are then no t execu ted until t he last upda t e module is processed. Remember that you must use global da ta within these form routines of t he funct ion group .

% Practice Ques t ions

The practice questions below wil l help y o u evaluate your understanding of the topic. The questions shown are similar in nature to those found on the certifica-tion examination. Whereas none of these questions wi l l be found on the exam

Practice Questions Chapter 8

i tself, t h e y a l l o w y o u to r e v i e w y o u r k n o w l e d g e o f the s u b j e c t . Select t h e co r rec t

a n s w e r s a n d t h e n check t h e c o m p l e t e n e s s o f y o u r a n s w e r s in t h e f o l l o w i n g solu-

t ion sec t ion . R e m e m b e r that y o u m u s t select all co r rec t a n s w e r s a n d o n l y co r rec t

a n s w e r s to rece ive c red i t f o r t h e q u e s t i o n .

1 . U p d a t e tasks a r e t h e o n l y m e t h o d o f m a k i n g c h a n g e s to t h e d a t a b a s e .

• A. T rue

• B. False

2 . W h i c h s t a t e m e n t is t r ue?

• A. A d a t a b a s e L U W m u s t b e p laced w i t h i n an SAP LUW.

• B. An SAP LUW m u s t b e p laced w i t h i n a d a t a b a s e LUW.

3 . W h i c h ac t ions re lease a d a t a b a s e lock?

• A. COMMIT WORK

• B. ROLLBACK WORK

• C. T h e d i sp lay o f a n SAP sc reen

• D. T h e d i sp lay o f a d ia log m e s s a g e t y p e E

• E. T h e d i sp lay o f a d ia log m e s s a g e t y p e A

• F. E N Q U E U E _ < l o c k _ o b j e c t >

• G. D E Q U E U E _ < l o c k _ o b j e c t >

• H. A call to a f u n c t i o n m o d u l e

• I. A C A L L T R A N S A C T I O N

• J . A S U B M I T

• K. An 7 n " in the c o m m a n d f ield

4 . W h i c h ac t ions re lease a lock o b j e c t (w i th a d e f a u l t va lue fo r ..SCOPE)?

• A. COMMIT WORK

• B. ROLLBACK WORK

• C. T h e d i sp lay o f a n SAP sc reen

• D. T h e d i sp lay o f a d ia log m e s s a g e t y p e E

• E. T h e d i sp lay o f a d ia log m e s s a g e t y p e A

210 Chapter 8 SQL Statements Including Update Strategies

• F. ENOUEUE_<lock_object>

• G. DEQUEUE_<lock_object>

• H. A call to a func t ion m o d u l e

• I. A CALL TRANSACTION

• J . A SU8MIT

• K. An " /n" in the c o m m a n d field

5. How can y o u i m p l e m e n t a table j o i n o the r than the using the JOIN state-m e n t ? (Fill in the blank.)

6. The data buf fe red on each applicat ion server is:

• A. Always the same

• B. Never the same

• C. Depends on the users

7. The target s t ruc ture o f a SELECT s ta tement requires the field names to match the co lumns selected and to be in t he same left-justified o r d e r .

• A. True

• B. False

8. W h e n is an ENDSELECT not requ i red for a select?

• A. W h e n the FROM is a v iew

• B. W h e n y o u specify a j o i n of tables

• C. W h e n y o u do a SELECT SINGLE

• D. W h e n y o u specify into a table

• E. W h e n y o u specify a p p e n d i n g a table

9. The database always uses t he p r imary key w h e n the WHERE clause conta ins any of the key fields.

• A. True

• B. False

Practice Questions Chapter 8

10. O p e n SQL d o e s n o t a l l o w y o u to spec i fy a s e c o n d a r y i n d e x d u r i n g a SELECT.

• A. T r u e

• B. False

11. You s h o u l d a lways b u f f e r d a t a b a s e t ab les tha t c o n t a i n f e w e r than 1 0 0

r eco rds .

• A. T r u e

• B. False

12. Buf fe r ing da t a can s p e e d u p access to da t a u p to 1 0 0 t i m e s w h e n c o m p a r e d

to r e a d i n g it f r o m t h e d a t a b a s e .

• A. T r u e

• B. False

13. All O p e n SQL c o m m a n d s a l l o w p r o c e s s i n g o n mu l t i p l e r o w s .

• A. T r u e

• B. False

14. T h e _ W A I T p a r a m e t e r o f a lock o b j e c t w a i t s fo r t h e lock to b e success fu l .

• A. T r u e

• B. False

15 . It is r e c o m m e n d e d to p lace t h e COMMIT WORK in t h e u p d a t e task.

• A. T r u e

• B. False

16 . It is poss ib l e to PERFORM < s u b r o u t i n e > ON COMMIT in an u p d a t e task.

• A. T r u e

• B. False

17 . T h e cor rec t o r d e r f o r us ing a lock o b j e c t is:

• A. Read t h e da ta , set t h e lock, c h a n g e t h e da t a , r e lease t h e lock

• B. Set t h e lock, read t h e da ta , c h a n g e t h e da ta , re lease t h e lock

• C. Set t h e lock, r ead t h e da ta , r e lease t h e lock, c h a n g e t h e da ta

212 Chapter 8 SQL Statements Including Update Strategies

18 . Local u p d a t e tasks a r e q u i c k e r b e c a u s e t h e y s tay w i t h i n t h e s a m e w o r k p ro -

cess.

• A. T r u e

• B. False

19 . V1 u p d a t e tasks a re a l w a y s n o n - r e s t a r t a b l e , w h e r e a s V2 u p d a t e tasks a r e a lways res t a r t ab le .

• A. T r u e

• B. False

Practice Question Answers and Explanations

1. Cor rec t a n s w e r : B

In a d d i t i o n to t h e v a r i o u s types o f u p d a t e tasks, it is also poss ib l e to u s e

in l ine u p d a t e s to m a k e c h a n g e s to t h e d a t a b a s e .

2 . Cor rec t a n s w e r : B

I f y o u e n c o u n t e r an e r r o r d u r i n g t h e p roces s ing o f an SAP LUW, it s h o u l d b e

poss ib l e to r e t u r n to t h e cons i s t en t d a t a b a s e s t a tus tha t ex i s t ed p r i o r to

b e g i n n i n g t h e SAP LUW. This is o n l y poss ib l e is if t h e SAP LUW is p laced

w i t h i n a d a t a b a s e LUW.

3. Cor rec t a n s w e r s : A, B, C, D, E, I, J , K

A d a t a b a s e lock is re leased w h e n t h e d a t a b a s e p e r f o r m s a rol lback o r data-base c o m m i t . W h e n y o u e x e c u t e t h e ABAP s t a t e m e n t s ROLLBACK WORK a n d COMMIT W O R K , y o u expl ic i t ly i m p l e m e n t a d a t a b a s e rol lback o r d a t a b a s e c o m -mi t . T h e r e a re also in s t ances w h e n a d a t a b a s e c o m m i t is t r igge red impl ic i t ly . Implici t d a t a b a s e c o m m i t s a r e a lways in i t ia ted w h e n e v e r t h e p r o g r a m has to wai t , s u c h as w h e n t h e sys t em s e n d s a n SAP sc reen , w h e n t h e sys t em s e n d s a d ia log message , w h e n e v e r t h e r e a re s y n c h r o n o u s a n d a s y n c h r o n o u s RFC calls ( the q u e s t i o n r e f e r e n c e d a n o r m a l f u n c t i o n call, no t a R e m o t e Func t ion Call), o r w h e n y o u u s e t h e s t a t e m e n t s C A L L T R A N S A C T I O N < t c o d e > o r S U B M I T < p r o g r a m > .

4. Correc t a n s w e r s : A. B, E, G, K

If a lock is e n q u e u e d w i t h a _ s c o p e o f 2 ( the defau l t ) , t h e lock is r e leased a f t e r

y o u e x e c u t e t h e ABAP s t a t e m e n t s ROLLBACK WORK a n d COMMIT WORK, o r a f t e r

a p r o g r a m t e r m i n a t i o n . A p r o g r a m t e r m i n a t i o n is p r o d u c e d a f t e r a m e s s a g e

Practice Question Answers and Explanations Chapter 8

w i t h t h e t y p e o f e i t h e r A o r x , w i t h t h e execu t i on o f t h e s t a t e m e n t s LEAVE

PROGRAM a n d LEAVE TO T R A N S A C T I O N , o r if t h e u s e r e n t e r s " / n " in t h e c o m -

m a n d f ie ld . T h e lock can a lso b e re leased b y cal l ing t h e DEQUEUE f u n c t i o n

m o d u l e o r t h e f u n c t i o n m o d u l e D E Q U E U E _ A L L .

5. Cor rec t a n s w e r : A d a t a b a s e v i e w

T h e r e a r c t w o w a y s to i m p l e m e n t a t ab le j o i n . O n e is to c r ea t e a d a t a b a s e

v i e w in the ABAP D i c t i o n a i y tha t c o r r e s p o n d s to t h e tab le j o i n a n d u s e th is

v i e w . T h e o t h e r is to d e f i n e t h e j o i n d i rec t ly in y o u r p r o g r a m as an ABAP

j o i n .

6 . Cor rec t a n s w e r : C

SAP table b u f f e r s exis t s epa ra t e ly f o r each app l i ca t ion se rve r , a n d t h e r e is a

l imi ted a m o u n t o f b u f f e r space o n each . As da t a is accessed by users , t h e da ta

tha t is c o n t a i n e d w i t h i n the tab le b u f f e r s c h a n g e s as m o r e r e c e n t da ta

rep laces o l d e r da ta . This m e a n s t h a t it is n o r m a l l y a ve ry r a r e o c c u r a n c c tha t

the c o n t e n t s o f t h e b u f f e r s across app l i ca t ion se rve r s m a t c h .

7 . Cor rec t a n s w e r : B

It is n o t necessa ry f o r t h e field n a m e s to m a t c h t h e c o l u m n s se lec ted . W h a t is n e c e s s a i y is fo r t h e size a n d t y p e o f t h e f ie lds to m a t c h .

8 . Cor rec t a n s w e r : C, D, E

An ENDSELECT is n o t r e q u i r e d b e c a u s e t h e s e S E L E C T s t a t e m e n t s d o n o t l oop . A S E L E C T S I N G L E s t a t e m e n t o n l y r e t u r n s o n e r eco rd , a n d b o t h t h e I N T O T A B L E a n d A P P E N D I N G T A B L E fill t h e d e s t i n a t i o n in a b lock m o d e . Because n o n e o f t h e s e s t a t e m e n t s is a S E L E C T l oop , t h e ENDSELECT is n o t n e c e s s a i y .

9 . Cor rec t a n s w e r : B

T h e d a t a b a s e o p t i m i z e r d e t e r m i n e s w h i c h i n d e x to use . U n d e r m o s t c i rcum-

s tances , it is ba sed o n t h e fields p r o v i d e d in t h e WHERE c lause, a n d w h i c h

i n d e x e s exis t f o r t h e d a t a b a s e table .

10 . Cor rec t a n s w e r : A

This is co r r ec t . O p e n SQL d o e s no t a l l o w y o u to p r o v i d e a n y d i r ec t ion

d i rec t ly to t h e u n d e r l y i n g da t abase .

11 . Cor rec t a n s w e r : B

T h e dec i s ion to b u f f e r d a t a b a s e tab les is m o r e c o m p l e x t h a n a s i m p l e de t e r -

m i n a t i o n based o n t h e e x p e c t e d s ize o f t h e table . Again t h e ideal t ab le is

smal l , r ead f r e q u e n t l y , ra re ly c h a n g e d , a n d n o r m a l l y accessed d i rec t ly w i t h

its key fields. H o w e v e r , t h e dec i s ion to b u f f e r a d a t a b a s e tab le s h o u l d b e

214 Chapter 8 SQL Statements Including Update Strategies

m a d e b y e x p e r i e n c e d ABAP d e v e l o p e r s in c o n s u l t a t i o n w i t h t h e s y s t e m

a d m i n i s t r a t o r .

12 . Cor rec t a n s w e r : A

A tab le tha t is b u f f e r e d can s p e e d u p y o u r access b e t w e e n 1 0 a n d 1 0 0 t i m e s c o m p a r e d to r e a d i n g it f r o m t h e d a t a b a s e . T h e cavea t f o r t h e s p e e d , h o w -ever , is tha t fo r t h e b u f f e r to b e used , it m u s t b e a SELECT s t a t e m e n t t h a t spec-if ics t h e full b u f f e r e d key w i t h equa l i t i e s on ly .

13 . Cor rec t a n s w e r : A

All O p e n SQL c o m m a n d s a l low p r o c e s s i n g o n mu l t i p l e r o w s .

14 . Cor rec t a n s w e r : B

T h e _WA1T p a r a m e t e r d e f i n e s w h e t h e r a lock r e q u e s t s h o u l d b e r e p e a t e d if

t h e first lock a t t e m p t fails . It d o e s n o t wa i t f o r t h e lock to b e c o m e avai lable .

15 . Cor rec t a n s w e r : B

You m u s t n o t use t h e expl ic i t ABAP s t a t e m e n t s COMMIT WORK o r ROLLBACK

WORK in t h e u p d a t e m o d u l e .

16 . Cor rec t a n s w e r : A

T h e goal in t h e u p d a t e task is to e x e c u t e c h a n g e s to cen t ra l tab les as late as poss ib l e in t h e LUW. To a c h i e v e this , y o u can u s e t h e PERFORM ON COMMIT t e c h n i q u e in t h e u p d a t e . If y o u e n c a p s u l a t e c h a n g e s to cen t ra l t ab les as f o r m r o u t i n e s w i t h i n t h e a p p r o p r i a t e f u n c t i o n g r o u p o f t h e u p d a t e m o d u l e a n d t h e n call the r o u t i n e s f r o m w i t h i n t h e u p d a t e m o d u l e u s ing t h e PERFORM ON C O M M I T , t h e f o r m r o u t i n e s will n o t b e e x e c u t e d un t i l t h e last u p d a t e m o d u l e is p r o c e s s e d .

17 . Cor rec t a n s w e r : B

This o r d e r s h o u l d b e na tu ra l . O b t a i n t h e lock so tha t y o u k n o w t h e da t a is n o t b e i n g m o d i f i e d e l s e w h e r e a n d is t h e r e f o r e cons i s t en t , r ead t h e da ta to beg in w i t h t h e c u r r e n t cons i s t en t s ta te , m a k e y o u r c h a n g e , a n d finally re lease t h e lock to m a k e t h e da ta avai lable f o r o t h e r s w h o m a y b e w a i t i n g f o r t h e da ta .

18 . Cor rec t a n s w e r : B

Local u p d a t e s a re q u i c k e r b e c a u s e t h e y d o n o t p r o v i d e u p d a t e s to the log table . Because t h e r e is less d a t a b a s e activity, the p roces s r u n s qu i cke r . H o w -ever , if t h e r e is a p r o b l e m , t h e r e is n o w a y o f k n o w i n g w h a t da ta w a s lost b e c a u s e t h e r e a r e n o r e q u e s t s in t h e log table .

Take Away Chapter 8

19. Corrcct answer : B

VI modu le s can e i ther be restar table o r non-res tar table . V2 tasks are always restar table.

Take Away

You should n o w be able access fields f r o m a database table o r tables eff icient ly. You should also be able to descr ibe t he d i f fe rence b e t w e e n an SAP LUW and a database LUW. You should also unde r s t and w h y u p d a t e tasks need to be bun-dled. You must unde r s t and the d i f fe ren t types o f O p e n SQL SELECT s ta tements and wha t improves o r decreases access pe r fo rmance .

Refresher

You will need a t h o r o u g h unde r s t and ing of the d i f fe ren t types o f upda te , com-mit , a n d rollback strategies. You mus t also unde r s t and eff icient data access. You mus t unde r s t and w h e n to choose a type of u p d a t e s trategy and w h y it is t he best solut ion. You mus t unde r s t and the concept of logical un i t s of work and h o w SAP LUWs and database LUWs w o r k together . Table 8 .3 shows t he key concepts for the SQL s ta tements and upda te strategies.

Key Concept Definition

SELECT Defines how to retrieve data from a single database table or multiple database tables efficiently

Bundling updates Defines what types of asynchronous and synchronous update tasks may be performed

Commit and rollback Defines how the commit and rollback provides a consistent database

Locks Defines how locks should be used to synchronize users' access to data

Table 8.3 Key Concepts Refresher

216 Chapter 8 SQL Statements Including Update Strategies

Tips

As a pe rcen tage o f the cert if ication test, this subject is o n e of the t op th ree wi th t he most ques t ions . An u n d e r s t a n d i n g of h o w to op t imize data access and an unde r s t and ing of upda te tasks for dialog p r o g r a m m i n g is requ i red for the por-t ion of t he test covered in this chapter .

The m o r e practical exper ience y o u have wi th this subject , the s impler y o u will find the ques t ions in this por t ion of the cert if ication examina t ion . However , inef-ficient p r o g r a m m i n g techniques inevitably lead to incorrect answers in this por-t ion o f the test. You mus t unde r s t and w h y one t echn ique should be used in place of ano the r .

Summary

You should have mas te red t he var ious types of O p e n SQL s ta tements and the i r d i f fe ren t variat ions. You should unde r s t and upda te tasks, record locks, and logi-cal un i t s o f work and h o w they interact wi th the user, applicat ion server, and database . You should unde r s t and h o w to keep data in a cons tant s tate wi th in the database . Your knowledge of these topics will a l low y o u to successfully comple t e this por t ion of the cert if ication exam.

Basic ABAP Programs and Interface Creation

Techniques You'll Master:

• Organize d e v e l o p m e n t objects

• Ident i fy d i f fe ren t types of p rog rams

• D e t e r m i n e p rog ram event blocks

• Use dynpros , selection screens, a n d modal dialog boxes

• Use author iza t ion checks

• Explain t he d i f fe ren t types o f modular iza t ion uni ts

• Ident i fy t he effect of messages on p rogram execut ion

218 Chapter 9 Basic ABAP Programs and Interface Creation

This chap te r provides y o u wi th a basic unde r s t and ing of h o w d e v e l o p m e n t objects a re organized. W e will discuss h o w these objects a re g r o u p e d into change reques ts ( commonly called t ranspor ts ) and m o v e d t h roughou t the sys tem land-scape. W e will cover the d i f fe rent types of p rograms , ident i fy ing the i r similari-ties and d i f ferences . W e will discuss the ma jo r i ty o f t he event blocks and the basics of Dynpros (often j u s t re fer red to as screens), selection screens, and modal dialog boxes (see Chap te r 12, Classical Screens, and Chapter 13, Selection Screens, as well). W e will cover t he use of au thor iza t ion checks and the d i f fe ren t types of modular iza t ion units , again ident i fying bo th the i r similari t ies and differ-ences. Lastly, we will cover the use of the MESSAGE s t a t emen t on p rogram execu-tion.

Each of these topics is covered separately, and they are fo l lowed by the practice exercise and the solut ion to the exercise.

Real-World Scenario

You have been asked to lead a n e w project imp lemen t ing a n e w g r o u p of applicat ion p rograms for use in y o u r c o m p a n y ' s SAP sys tem. It is y o u r responsibi l i ty to put toge ther a d e v e l o p m e n t team and p roduce the sub-sys tem.

In examin ing the r e q u i r e m e n t s of the subsys tem, y o u see that the re a re a n u m b e r of dialog t ransact ions and several r epor t t ransact ions. Some of the data is sensit ive, so both the dialog t ransact ions and repor t t ransact ions will r equ i re separate author iza t ion checks to d e t e r m i n e if the user is a l lowed to v iew the data. The dialog p rograms will also need to check for authoriza-tion to create o r change the data. If the user is no t au thor ized to p e r f o r m the opera t ion , a message mus t be displayed.

Once y o u have y o u r d e v e l o p m e n t team in place, y o u will be requ i red to organize the d e v e l o p m e n t so that it all reaches p roduc t ion at the same t ime for go-live. Owing to t he complexi ty of accessing the data and the n u m e r -ous types of author iza t ion checks, a decis ion was m a d e to encapsula te the tables ' access into global reuse c o m p o n e n t s . This will also p rov ide the op t ion of buf fe r ing retr ieved data du r ing dialog t ransact ions.

Objectives of this Portion of the Test Chapter 9

Objectives of this Portion of the Test

The p u r p o s e of this por t ion of the cert if ication examina t ion is to ver i fy that y o u have detai led k n o w l e d g e of the ABAP deve lopmen t e n v i r o n m e n t a n d the capa-bilities of d i f fe ren t types of p rograms . This por t ion of t he examina t ion will test y o u r knowledge of a w ide range of topics. The points y o u will need to under -s tand f r o m this sect ion include:

• W h a t types o f p rograms exist

• Event blocks

• Dynpros , selection screens, modal dialog boxes

• Dif ferent m e t h o d s of execut ing p rograms

• Author iza t ion checks

• Modular iza t ion uni ts

• The effect o f messages in a p rogram

Because this is an ABAP cert if ication examina t ion , assessing y o u r general knowl -edge of ABAP and its e n v i r o n m e n t is the mos t impor t an t object ive of the test . The cert if icat ion examina t ion will give m o r e weigh t to the material in this chap-ter than all o f the o the r topics in the examina t ion . This m e a n s the re will be a h igher percentage o f ques t ions related to this chapter than any o the r chapter .

Key Concepts Refresher

Unsurpr is ingly , y o u typically need to deve lop ABAP programs as an ABAP devel-oper . You the re fo re need to unde r s t and and be able to p e r f o r m the fol lowing types o f tasks w h e n deve lop ing ABAP programs:

• Create var ious types of p rog rams

• Test var ious types of d e v e l o p m e n t

• M o v e d e v e l o p m e n t objects f r o m y o u r d e v e l o p m e n t e n v i r o n m e n t to y o u r test a n d produc t ion sys tems

• Encapsulate data and processing

• Interact wi th users

• Verify that the user is au thor ized to p e r f o r m a specific func t ion

• Inform users abou t e r rors and p rogram status

234 Chapter 9 Basic ABAP Programs and Interface Creation

O r g a n i z i n g D e v e l o p m e n t

Development projects start out in a development system. The development objects edited or created in a project must then be transported to subsequent sys-tems when the project is complete.

At the start of a development project, normally, the project manager creates a change request, in which he identifies who will be working on the project, in either the Transport Organizer or directly in the ABAP Workbench. Then he cre-ates a task for each project employee or developer within the change request. In some cases, where the development is limited, there may be only a single task in a single change request.

As a development object is edited or created, for example, a program or data ele-ment. you assign this object to the change request. The object is thus entered into y o u r task. All repository objects that you work on during a development project are collected within y o u r task. When you complete y o u r development tasks, you perform syntax checking, activation, and testing before you release the task in the change request. Once the project development is complete and all tasks are released, the change request itself is released, but it cannot be released until all of its tasks are released (see Figure 9.1).

Locking objects against outs ide access Project Manager

End of Development

USER.GREEN — Request is released

Project Team:

USER.BIACK | I

RtD

•!«• WMITf ^ r - — Task is released All tasks released

Figure 9.1 Project Timeline of a Change Request

Key Concepts Refresher Chapter 6 221

Organizing a development project using a change request offers the following advantages:

• Each developer can track and check his project-specific activities.

• The development objects can be processed by all developers involved in the project. For developers who do not belong to the project team, the repositoiy objects remain locked until the project is completed and the change request is released.

• The jo in t transport of the development objects processed in the project at the t ime of project completion is automatically ensured by assigning the objects to the change request. The transport route of the involved packages specifies to which subsequent system they are transported.

Unlike packages that distinguish between Repository objects in a logical and functional way. change requests are project-related and therefore delimit the objects over a period of t ime. Therefore, although a program always belongs to only one package, it can, at different times, belong to different projects or change requests. It is possible for a single change request (actually, it is very likely unless the change request contains all new development for a specific purpose) to con-tain multiple development packages.

A B A P P r o g r a m m i n g O v e r v i e w

ABAP is a programming language developed by SAP for programming business applications within the SAP environment . As discussed in Chapter 3. SAP NetWeaver — Overview, and Chapter 8. SQL Statements Including Update Strat-egies. the three-tier architecture used by SAP provides for the user who interacts with the presentation layer, which controls the business logic running on an application server, which retrieves and stores data in the database server. ABAP is the language that controls the business logic running on the application server. ABAP programs are executed in the ABAP runt ime envi ronment . The main role of the ABAP program in the application layer is the processing and formatt ing of data f rom the database layer and its interaction with the user input f rom the pre-sentation layer.

ABAP provides integrated database access to multiple database systems through the use of Open SQL. It optimizes database access through the use of SAP buff-ering and provides internal tables for processing tabular data within the pro-gram. It uses the concept of online transaction processing (OLTP) integrated into

222 Chapter 9 Basic ABAP Programs and Interface Creation

the ABAP r u n t i m e e n v i r o n m e n t , enabl ing mult iple users to access t he da tabase at t he same t ime using the SAP LUW. It p rovides outs ide access to o the r program-ming e n v i r o n m e n t s wi th the Remote Funct ion Call (RFC). Also, ABAP has an integrated interface to XML.

ABAP suppor t s bo th procedura l a n d objec t -or iented p r o g r a m m i n g mode l s based on subrou t ines , func t ion modules , and m e t h o d s of classes. As appropr ia t e for a language des igned a r o u n d in terna t ional business , the textual language is hand led independen t ly of the p r o g r a m m i n g language. ABAP provides for the separat ion of language-specific p rogram c o m p o n e n t s f rom the source code, and they are loaded du r ing p rogram execut ion based on t he user ' s logon language. ABAP sup-por ts code pages, single-byte, double-byte , and a f t e r Release 6 .10, even Unicode .

Each ABAP p rog ram starts wi th an in t roduc to iy s ta tement . The func t ions of an ABAP p rog ram are i m p l e m e n t e d in processing blocks. The processing blocks a rc de f ined using modular iza t ion s ta tements . The o r d e r o f the processing blocks is i rrelevant for p rogram execut ion . Following the in t roduc to iy s t a tement , every p rogram contains a global declarat ion section w h e r e y o u i m p l e m e n t def in i t ions of data objects (for example , variables, s t ructures , and internal tables) and data declara t ions that are visible in t he en t i r e p rogram. W h e r e a s the o rde r o f individ-ual def in i t ions and declarat ions does not ma t t e r general ly, y o u must take in to account that an ABAP s ta tement can on ly refer to exist ing def in i t ions and decla-rat ions. Therefore , they mus t be de f ined be fo re they can be declared and declared be fo re they can be used . For example , a def in i t ion o f a local type mus t occur pr ior to its first use in the p rogram, normal ly e i ther as a data declarat ion o r as par t of an interface to a modular iza t ion uni t .

Because ABAP is a language that has evolved over t ime, it contains several obso-lete s ta tements o r f o r m s of s t a t emen t s that w e r e replaced wi th improved lan-guage constructs , but w e r e not e l iminated , to ensu re d o w n w a r d code compat ibi l i ty . ABAP Objects p reven t t he use of a lmost all of these obsole te addi-t ions. In general , y o u should n o longer use these addi t ions in n e w programs , bu t y o u may e n c o u n t e r t h e m in o lder p rograms .

The in t roductory s t a t emen t mus t be the first s t a tement in the p rogram af ter the include p rograms are expanded dur ing p rogram genera t ion . It can only appea r once in the p rog ram.

Key Concepts Refresher Chapter 6 223

In t roduc to iy p rogram s ta tements include:

• Executable p rograms (REPORT)

• M o d u l e pools (PROGRAM)

• Funct ion g roups (FUNCTION POOL)

• Class pools (CLASS-POOL)

• Interface pools (INTERFACE-POOL)

• Subrou t ine pools (PROGRAM), which are n o w cons idered obsole te

• Type g roups (TYPE - POOL)

All of these a re s tand-alone compi la t ion uni ts o r p rogram types. Include pro-g rams are only used in the context o f super io r p rograms . Type groups , also k n o w n as type pools (program type T), a re s tand-a lone p rograms f r o m a logical poin t of v iew. However , t hey do not conta in executable code but on ly type def-ini t ions and cons tan t def in i t ions . Therefore , type g roups have their o w n intro-duc tory p rogram s ta tement , the TYPE-POOL.

W h e n y o u create a p rogram, the ABAP W o r k b e n c h automatical ly genera tes the i n t roduc to iy s t a tement f r o m the p rogram type. If changes are necessary, only the in t roduc tory s t a t emen t ' s add i t ions should be ed i ted . An example of a n e w repor t and s o m e possible addi t ions are s h o w n in Listing 9.1 and Listing 9 .2 .

*& Report Z_NEW_REPORT *&

*t>

REPORT z_new_repor t .

Listing 9.1 A New Introductory Statement for a Report

*&

*& Report Z_NEW_REPORT *&

REPORT z_new_repor t

224 Chapter 9 Basic ABAP Programs and Interface Creation

LINE-SIZE 250 NO STANDARO PAGE HEADING MESSAGE-ID z_message_c l a s s .

Listing 9.2 A Modified Report Introductory Statement

In particular, t he keywords FUNCTION-POOL, CLASS-POOL, INTERFACE-POOL, and TYPE-POOL should only be gene ra t ed by the co r r e spond ing tools of the ABAP W o r k b e n c h . The creat ion of a func t ion g roup also automatical ly genera tes the main p rogram including the t op include conta in ing the FUNCTION-POOL state-m e n t . The comple t e n a m e of the p rogram fo r a func t ion g r o u p in the Reposi tory consists of the pref ix SAPL a n d t he n a m e of the func t ion pool ( funct ion group) . All s t a t emen t s fo l lowing the in t roduc to iy p rog ram s t a t emen t or those that a re included as include p rograms are t reated as a single uni t by the ABAP compi ler .

Each ABAP program is divided in to processing blocks. Each accessible s t a t emen t of an ABAP p rog ram that does not be long in the global declarat ion section belongs to a processing block.

The possible processing blocks are:

• P r o c e d u r e s

• M e t h o d s

• Funct ion modu le s

• Subrou t ines

• Dia log m o d u l e s (exclusively for Dynpros )

• Even t b locks

Funct ion modu le s a re always de f ined globally, whe rea s m e t h o d s can be de f ined e i ther globally o r locally wi th in the program, and sub rou t ines should only ever be de f ined locally ( subrou t ine pools n o w being cons idered obsolete) . The f low logic of D y n p r o calls dialog modu le s to p e r f o r m thei r processing. Event blocks are t r iggered by even t s in t he ABAP r u n t i m e e n v i r o n m e n t .

The pa rame te r interface o f a p r o c e d u r e consists of formal pa ramete r s a n d speci-fies the possible except ions of the p rocedure . The formal pa ramete r s are input , ou tpu t , i n p u t / o u t p u t pa ramete r s and re tu rn values. The re are also t he obsole te table paramete rs . Subrou t ines do not p rov ide input o r o u t p u t pa ramete r s direct ly because both USING and CHANGING are t reated as a type o f changing paramete r ; they d o not p rov ide for r e tu rn ing values. Funct ion modu le s d o not p rov ide r e tu rn ing values. Formal pa ramete r s a re e i ther gener ic o r comple te ly

Key Concepts Refresher Chapter 6 9

typed. You can specify e i ther pass by re fe rence o r pass by value fo r mos t formal parameters , a l though for s o m e formal parameters , pass by value is manda to ry .

The d i f fe rences and similarit ies a rc discussed in detail be low in the sect ions ABAP Subrout ine , ABAP Funct ion Modu le , and ABAP Classes and M e t h o d s .

Class-based except ions can be declared using RAISING fo r all p rocedures (meth-ods, func t ion modules , and subrou t ines ) and can then be propagated f r o m the p rocedure . Also, EXCEPTIONS can be used in m e t h o d s and func t ion modu le s to de f ine non-class-based except ions , wh ich can then be tr iggered in the p r o c e d u r e using e i ther RAISE or MESSAGE . . . RAISING.

Listing 9 .3 shows the o lde r except ions that w e r e MESSAGE based and could on ly exist in func t ion modu le s o r me thods . Listing 9 .4 shows an example of a class-based except ion . A single p r o c e d u r e can only use o n e type — not both .

MESSAGE e008(38) WITH 'FOOBAR'

RAISING t a b l e _ c a n n o t _ b e _ l o a d e d .

Listing 9.3 Example of a MESSAGE-Based Exception

RAISE EXCEPTION TYPE cx_sy_dynamic_osq l . s eman t i c s EXPORTING t e x t i d -

cx_sy_dynamic_osql_semant ics->unknown_table_name token - 'FOOBAR'.

Listing 9.4 Example of a Class-Based Exception

W h e n y o u decide w h e t h e r to use pass by re fe rence o r pass by value for a formal pa ramete r , y o u mus t c o m p a r e the relative p e r f o r m a n c e and robus tness for each type o f transfer.

• A pass by re ference p a r a m e t e r provides a po in te r to the original data object in m e m o r y , a n d the p r o c e d u r e opera tes direct ly o n the original object .

• A pass by value pa rame te r copies the value to a n e w data object , o r in the case o f a changing pa rame te r copies it once w h e n called and once again u p o n com-plet ion.

In ABAP, pass by re fe rence is a lways quicker because n o local objec t is created and no data t ranspor t is necessary w h e n calling the p rocedure . Simply for per-f o r m a n c e reasons, pass by re fe rence is usually p re fe r red unless the re is an explicit o r implicit wr i t e to an inpu t pa rame te r wi th in the p r o c e d u r e o r y o u w a n t to ensu re that an i n p u t / o u t p u t (changing) or o u t p u t pa rame te r is only r e tu rned if the p rocedure ends w i t h o u t e r ro r . In such cases pass by value is manda to ry , so

240 Chapter 9 Basic ABAP Programs and Interface Creation

that the ass igned p a r a m e t e r is no t s imul taneous ly mod i f i ed in the calling c o d e w h e n the re is a wr i t e access to a fo rmal p a r a m e t e r .

The fo l lowing e x a m p l e s h o w s a very s imple example of the behav io r d i f f e r ence of call by r e f e rence versus call by value. Not ice that the c o d e ( shown in Listing 9 .5) p rov ides f o u r var iables to the fo rmal p a r a m e t e r s of the s u b r o u t i n e . T w o a rc passed by value and t w o arc passed by re fe rence ; o n e of each pair is passed as a USING pa rame te r , and o n e of each pair is passed as a CHANGING pa rame te r . At the po in t in t h e p r o g r a m w h e n the call is m a d e (PERFORM pass_by_example) , t h e val-ues o f the variables in the calling rou t i ne are all ze ro (see Figure 9.2). At the po in t of the BREAK POINT s t a t emen t (see Figure 9.3), all o f the fo rmal p a r a m e t e r s have a va lue of o n e . However , if the d e b u g g e r po in t of v i e w is changed to the calling rou t ine , t h e original var iables passed by re fe rence have changed , w h e r e a s the var iables passed by value have no t (see Figure 9.4).

FORM p a s s _ b y . DATA:

1v_numl TYPE i . 1v_num2 TYPE f . 1v_num3 TYPE 1. 1v_num4 TYPE i .

PERFORM pass_by_example USING lv_numl lv_num2 CHANGING 1v_num3 lv_num4.

ENDFORH. "pass_by

FORM pass_by_example USING v a l u e ( p _ b y _ v a l u e l ) TYPE i P_ b y _ r e f l TYPE 1

CHANGING v a l u e ( p _ b y _ v a l u e 2 ) TYPE i p _ b y _ r e f 2 TYPE f .

ADD 1 TO: p _ b y _ v a l u e l . p _ b y _ r e f l . p_by_va lue2 . p _ b y _ r e f 2 . BREAK-POINT.

ENDFORM. "pass_by_example Listing 9.5 Example Code

IVJNMI • U J I W I 9 I V J M O • IVJHIM 9

ti r_m_Kt\ at P j r r j o i u O

Figure 9.2 At the Point of the Point of the Call

Key Concepts Refresher Chapter 6 227

LVJIUM L V_HUH? LV_RUH3 LV_RUH4 p_»Y_»M.uei 1 MT.MH 1 p_rf_vM«C2 1 p.rr.Wf? 1

Figure 9-3 At the BREAK-POINT Statement

(LVJWH1 0 LVJOtt 1 LV.MJH3 0 LV.Hjfl* 1 p.et.vAiuei P.et.REFI p_trr_muf2 P.6t_REF2

Figure 9-4 At the BREAK-POINT Statement in the Calling Routine

You should no t e the fol lowing behav ior w h e n using pass by reference:

• In subrou t ines , wr i te access can occur to an input pa rame te r de f ined wi th US ING w i t h o u t the occurrence of syntax er rors . This is no t t he case wi th meth-ods o r func t ion modu le s de f ined wi th IMPORTING.

• An ou tpu t p a r a m e t e r that is passed by reference acts like an i n p u t / o u t p u t (changing) pa ramete r . If the re is a read access to an o u t p u t p a r a m e t e r in the p rocedure before the value of the p a r a m e t e r is changed , this value is no t ini-tial, unl ike wi th pass by value, bu t is the same as the cu r ren t value of the actual pa rame te r f r o m the calling code. This also means that if t he called pro-cedure does not change an o u t p u t pa ramete r , the actual pa rame te r in t he call-ing code remains unchanged .

• If a p r o c e d u r e is s topped because o f an er ror , in o the r w o r d s s topped fo r a reason o the r than that it has reached its last s t a t emen t o r a RETURN, all param-eters retain the values they con ta ined w h e n the p r o c e d u r e was s topped .

To summar ize , pass by re fe rence is a lways preferable w h e n p e r f o r m a n c e is an issue, whe rea s pass by value is m o r e sui table for s i tuat ions w h e r e robus tness and data consis tency are impor t an t .

Only pass by re fe rence can be specified for the obsole te table pa ramete r s in e i ther subrou t ines o r func t ion modu les . As m e n t i o n e d above, pass by value is manda to ry for the re turn value of funct ional me thods , the o u t p u t pa ramete r s of

228 Chapter 9 Basic ABAP Programs and Interface Creation

events in ABAP Objects , and all formal pa ramete r s of func t ion m o d u l e s that a re e i ther RFC enabled o r are upda te modu les .

ABAP Event Blocks

Event blocks a re uni ts of code that a re executed in a s equence d e t e r m i n e d by external events : o f t en the r u n t i m e e n v i r o n m e n t for ABAP. occasionally by a user ' s act ions. The sequence in which the processing blocks occur in the p rogram is i r relevant . However , to make y o u r p rograms easier to unde r s t and , y o u should include the event blocks in y o u r p rogram in approx imate ly the same o r d e r in which they will be called by the sys tem and pr ior to sub rou t ines o r local class implementa t ions .

Event blocks are s tar ted using an event keyword and e n d e d by the next process-ing block: e i ther a n o t h e r even t block o r o the r type of procedura l block. Wi th in an event block, y o u cannot declare local data types o r data objects . All declarat ive s t a t emen t s in event blocks be long to the ABAP program and are visible globally (in all subsequen t processing blocks). There are t w o except ions: The event blocks AT SELECTION-SCREEN and GET are i m p l e m e n t e d internal ly as p rocedures and can conta in local data.

Event blocks can be g r o u p e d by type. Table 9 .1 shows the event types that exist.

Type of Event Event Occurs in Program Types

Program constructor event All program types

Reporting event Only in executable programs

Selection screen event Only during selection screen processing

List event Only during list processing

Table 9.1 Types of Events

Wi th the except ion of AT SELECT I ON-SCREEN a n d GET, event blocks can be listed mult iple t imes in a p rogram, but normal ly y o u will not see this ( the valid case w h e r e this would be used is ex t remely convolu ted , involving shar ing code b e t w e e n mul t ip le p rog rams o r include p rog rams o r w h e n the code is inadvert-ent ly included mul t ip le t imes). Event block START-OF-SELECTION can also be implicitly listed mult iple t imes. W h e n e v e r an event occurs, all associated event

Key Concepts Refresher Chapter 6 229

blocks a re executed in the o rde r of their occurrence . Again, the event blocks are t r iggered by events in the ABAP r u n t i m e e n v i r o n m e n t .

In t he fol lowing list, we list the event blocks and w h e n o r h o w they are t r iggered.

• 1 0 A D - 0 F - P R 0 G R A M

This event keyword is t r iggered w h e n the p rogram is initially loaded into m e m o r y . This p rogram cons t ruc to r event is t r iggered for all p rogram types. This can be useful to initialize o r instant ia te a data object w h e n the p rogram begins on ly o n c e o r to indicate to an external process that the p rog ram has s tar ted. The event is only tr iggered once, be fo re any o the r event of a pro-g ram.

• I N I T I A L I Z A T I O N

This repor t ing event keyword is t r iggered by the actual start of the p rog ram and b e f o r e the selection screen processing of any exist ing s tandard selection screen ( the only event that can occur be fo re this is LOAD- OF -PROGRAM). W h e n an executable p rogram def ines that a s tandard selection screen is called again by the ABAP run t ime e n v i r o n m e n t af ter an execut ion, the INITIALIZA TION event is t r iggered again. An example of this is a r epor t in which a f t e r dis-playing the repor t , the user clicks o n the BACK b u t t o n o r presses [ F3 | and r e tu rns to the selection screen to r e r u n the repor t . In this case, initializing pa ramete r s o r selection criteria o f the selection screen has n o effect because they are automatical ly suppl ied wi th the preceding user inputs f r o m the selec-t ion screen du r ing the selection screen even t AT SELECTION-SCREEN OUTPUT.

• S T A R T - O F - S E L E C T ION

In an executable p rog ram, all s t a tements that are not declara t ions and are listed be fo re the first explicit processing block, o r if the p rogram does not conta in any explicit processing blocks, t hen all funct ional s t a t emen t s of the p rog ram are assigned to an implicit even t block START-OF-SELECTION, which is inser ted be fo re any START-OF - SELECTION even t blocks. This even t k e y w o r d is t r iggered w h e n the p rogram has comple ted all selection screen events . If the p rogram is l inked to a logical database , p repa ra to ry tasks can be per-f o r m e d at START-OF-SELECT I ON be fo re the logical da tabase impor t s the data. If t he p rogram is no t l inked to a logical database, this event block becomes a type of "main p r o g r a m " f r o m which p rocedures o r screens are called. See List-ing 9 .6 for an example of an explicit example and Listing 9 .7 for an implicit example .

244 Chapter 9 Basic ABAP Programs and Interface Creation

* PA I AT S E L E C T I O N - S C R E E N .

PERFORM p a i _ o f _ s e l e c t i o n _ s c r e e n . S T A R T - O F - S E L E C T I O N .

PERFORM s e l e c t i o n . E N D - O F - S E L E C T I O N .

PERFORM e 0 5 _ l a y o u t _ b u i Id USING g s j a y o u t . ' w g . P a r a m e t e r s * C a l l ABAP/4 L i s t V i e w e r

C A L L F U N C T I O N ' R E U S E _ A L V _ H I E R S E 0 _ L I S T _ D I S P L A Y ' E X P O R T I N G

i _ c a l l b a c k _ p r o g r a m - g _ r e p i d L _ C A L L B A C K _ P F _ S T A T U S _ S E T - • '

* I _ C A L L BAC K_U S E R_C0MMA N 0 - • •

i s _ l a y o u t - g s . l a y o u t i t _ f i e l d c a t - g t _ f i e l d c a t t ]

* I T _ E X C L U O I N G -i t _ s p e c i a l _ g r o u p s - g t _ s p _ g r o u p [ ]

* I T _ S 0 R T -* I T _ F I L T E R -

* I S _ S E L _ H I O E -

* I _ S C R E E N _ S T A R T _ C O L U M N - 0 * I _ S C R E E N _ S T A R T _ L I N E - 0 * I _SCREEN_ENO_COLUMN - 0 * I _ S C R E E N _ E N O _ L I N E - 0 * i _ d e f a u l t - g _ d e f a u l t

i _ s a v e - g _ s a v e i s _ v a r i a n t - g _ v a r i a n t i t _ e v e n t s - g t _ e v e n t s [ ]

* I T _ E V E N T _ E X I T -

i _ t a b n a m e _ h e a d e r - g _ t a b n a m e _ h e a d e r i _ t a b n a m e _ i t e m - g _ t a b n a m e _ i tern i s _ k e y i n f o - g s _ k e y i n f o

* I S _ P R I N T -* I M P O R T I N G * E _ E X I T _ C A U S E D _ B Y _ C A L L E R

T A B L E S •

t _ o u t t a b _ h e a d e r - g t _ s c a r r t _ o u t t a b _ i t e m - g t . s p f l i .

Listing 9 .6 Example of Several Event Blocks

R e p o r t Z_HELLO_WORLD_SIMPLE *&

Key Concepts Refresher Chapter 6 231

* &

report z_hello_world_simple. write / 'Hello World'. Listing 9 7 Example of an Implicit START-OF-SELECTION

• GET node The reporting GET event defines an event block whose result is triggered by the ABAP runtime environment, if the logical database to which the program is linked provides data in the work area node. GET node also controls the behavior of the logical database. The event blocks after GET are implemented internally as procedures. Declarative statements in GET event blocks create local data. GET event blocks follow the START OF SELECTION event and are fol-lowed by the event block END-OF-SELECTION.

• END-OF-SELECTION In this report event block, all data read by the logical database can be pro-cessed. In an executable program without a logical data base, there is no need to implement the event block END-or -SELECT ION.

• AT SELECTION-SCREEN This statement defines event blocks that are triggered by the ABAP runtime environment during selection screen processing. The event AT SELECTION SCREEN is the basic form of a whole series of events that occur while the selec-tion screen is being processed. The standard selection screen in an executable program or in the logical database linked to it is automatically called between the INITIALIZATION and START-OF-SELECTION events. You can define event blocks for these events in your program to change the selection screen or pro-cess user input.

Selection screen events occur immediately before sending a selection screen, during the PBO of the selection screen (AT SELECTION SCREEN OUTPUT), after certain user actions on a displayed selection screen, for example, ON VALUE REQUEST or ON HELP REQUEST, or prior to proceeding to the START- OF -SELEC-TION event during execution. They assist in selection screen processing in the ABAP program or provide validations for the selection screen.

• TOP-OF-PAGE This list creation event is triggered by the ABAP runtime environment during the creation of a list. This occurs when a new page is started, that is. immedi-

232 Chapter 9 Basic ABAP Programs and Interface Creation

ate ly b e f o r e t h e first l ine in a n e w p a g e is to b e o u t p u t . All list o u t p u t s tha t

take p lace in t h e e v e n t b lock a r e p laced b e l o w t h e s t a n d a r d page h e a d e r o f

the list. You c a n n o t o u t p u t m o r e l ines t h a n a r e avai lable in t h e page w i t h i n

the e v e n t block, a n d t h e NEW-PAGE s t a t e m e n t is i gno red w i t h i n th i s e v e n t

b lock .

• END OF PAGE

This list c r ea t i on e v e n t is t r igge red b y t h e ABAP r u n t i m e e n v i r o n m e n t d u r i n g the c r ea t i on o f a bas ic list, if t h e r e is a l ine r e s e r v a t i o n in t h e a d d i t i o n LINE COUNT o f t h e in i t i a t ing s t a t e m e n t f o r a page foo t e r . A list o u t p u t tha t t akes place in t h e e v e n t b lock is p laced in th is a rea . O u t p u t s t a t e m e n t s tha t e x c e e d the r e s e r v e d a rea wil l b e i g n o r e d .

• AT L I N E - S E L E C T I O N

This d i sp lay o f a s c reen list e v e n t is t r igge red by t h e ABAP r u n t i m e e n v i r o n -m e n t , p r o v i d e d t h e sc reen c u r s o r is o n a list l ine a n d y o u select a f u n c t i o n us ing t h e f u n c t i o n c o d e P i c k (or p res s {JT\ o r double-c l ick o n a list l ine). Th is w a s o f t e n u s e d to p r o v i d e d r i l l - down capabi l i ty o r to p r o v i d e a d d i t i o n a l deta i l . D u r i n g t h e l ine se lec t ion p roces s a n y fields o u t p u t o r p laced o n t h e l ine w i t h t h e H i d e c o m m a n d a r e r e t u r n e d to t h e i r r e spec t ive g lobal da t a ob jec t s .

• AT USER-COMMAND

This d i sp lay o f a s c reen list e v e n t is t r igge red by t h e ABAP r u n t i m e e n v i r o n -

m e n t if, d u r i n g t h e d i sp lay o f a s c reen list, a f u n c t i o n w i t h a s e l f -de f ined func -

t ion c o d e w a s c h o s e n .

Basic ABAP Statements

T h e ABAP syn tax is p l a t f o r m i n d e p e n d e n t . This m e a n s tha t it a lways has the s a m e m e a n i n g o r f u n c t i o n , i r r e spec t ive o f t h e re la t iona l d a t a b a s e sys t em a n d o p e r a t i n g s y s t e m f o r t h e app l i ca t ion a n d p r e s e n t a t i o n se rve r . App l i ca t ions i m p l e m e n t e d in ABAP wil l also b e ab le to r u n in f u t u r e re leases o w i n g to t h e u p w a r d c o m p a t i b i l i t y o f t h e l anguage . T h e o n l y t y p e o f u p w a r d c o m p a t i b i l i t y issue w o u l d b e re la ted to c h a n g i n g f r o m a n o n - U n i c o d e sys t em to a U n i c o d e sys-t e m . For m o r e i n f o r m a t i o n o n th is topic , p lease see C h a p t e r 11 , U n i c o d e .

For t h e ABAP syn tax , t h e gene ra l ru les apply :

• ABAP p r o g r a m s cons is t o f ind iv idua l s e n t e n c e s ( s t a t emen t s ) .

• The f irst w o r d in a s t a t e m e n t is called t h e ABAP keyword, a l t h o u g h the key-

w o r d m a y b e o p t i o n a l — COMPUTE, f o r e x a m p l e .

Key Concepts Refresher Chapter 6 233

• Each statement ends with a period.

• Words must always be separated by at least one space.

• Statements can be indented.

• A B A P keywords, additions, and operands can be either upper- or lowercase (the ABAP runtime system does not differentiate).

• Statements can extend beyond one line.

• You can place several statements on a single line (though this is not generally recommended).

• Lines beginning with an asterisk (*) in the first column are recognized as com-ment lines and ignored.

• Double quote marks (") indicate that the remainder of the line is a comment.

N o t e

Although t he ABAP runt ime system does not different ia te b e t w e e n upper - and lowercase, it has become cus tomary t o wri te keywords and their addi t ions in uppercase letters and ope rands in lowercase. This form of representa t ion is also be used th roughou t t he book . It can b e achieved in your o w n program by using t he PRETTY PRINTER but ton and set t ing t he appropr ia te opt ion in t he set t ings (UTILITIES • SETTINGS • A B A P EDITOR • PRETTY PRINTER).

You can combine consecutive statements with an identical beginning into a chained statement:

• Write the identical beginning part of the statement followed by a colon.

• After the colon, list the end parts of the statements (separated by commas).

N o t e

This shor t form merely represents a simplified form of syntax and d o e s no t offer an improvement in per formance . The ABAP runt ime system processes each of t he individual s t a t ements . The short form makes the mos t sense with certain s t a t e m e n t s , f o r e x a m p l e , T Y P E S . D A T A , S E L E C T - O P T I O N S , P A R A M E T E R S , C L E A R , H O V E ,

ADD, o r W R I T E .

Normally, a program is not made up of a single block, but of several units. Many of these modularization units can be used in more than one program. A good program should have at least the database access encapsulated (known also as a

234 Chapter 9 Basic ABAP Programs and Interface Creation

reuse c o m p o n e n t ) . This creates a division b e t w e e n the design of the p rog ram and the da tabase accesses. It is t hen possible for y o u to use the same da tabase accesses for d i f fe ren t user dialogs o r p rograms .

As an addi t ional benef i t o f such an encapsula t ion, o f t en it is possible to b u f f e r the data wi thin t he encapsula t ion, mean ing that it only needs to be retr ieved f r o m the da tabase once . As an example , a n u m b e r of s tandard func t ion modu le s retr ieve data f r o m var ious tables and s tore it w i th in the func t ion g r o u p . Later a t t emp t s to retr ieve the same data retr ieve it f r o m the internal tables wi th in the func t ion g r o u p ra ther than retr ieve it again f r o m the database tables. A c o m m o n example of this type of buf fe r ing wi th in a database encapsula t ion is the retrieval of address data. As a result , any address retrieval for a cus tomer , vendor , o r part-ner benef i t s f r o m this op t imiza t ion . An example of this can be seen in Figure 9 .5 .

TV. Parameter Type spec Description

K) CARRID TYPE S f UGHT-CARRID ID of Carrier

K1 C O N M O TYPE SFUOHT-CONNIO Code of Connection

VALU€( FUGHT_TA8) TYPE T F U O H T T A B Connections

Method &ET_FLI$HT_TA8

1 I MKTMOD g e t _ f l l g h t _ t a b .

S E L E C T f l d a t e s e a t s m a x s e a t s o c c I N T O C O R R E S P O N D I N G F I E L D S O r TABLE f l l 0 h c _ t a b FROH atlight VHERE c a r r i d - c a r r i d AND c o n n l d - c o n n i d ORDER BY f l d a t e

EHDMETHOD

Figure 9.5 Example of Database Encapsulation

A modular iza t ion uni t is a par t of a p rog ram w h e r e a part icular func t ion is encap-sulated. You place par t of the source code in a "modu le" to improve t he t ranspar-ency of the p rogram and to use the co r r e spond ing func t ion in the p rogram several t imes (or indeed in o the r p rograms if the modular iza t ion is global) with-out having to i m p l e m e n t the en t i re source code again on each occasion. The i m p r o v e m e n t in t ransparency results f rom the p rogram becoming m o r e func t ion o r i en ted . It d ivides t he overall task into subfunc t ions , which are t he responsibil-ity of the co r r e spond ing modular iza t ion uni t .

Modular iza t ion also simplif ies bo th p rog ram ma in t enance a n d fu tu re design changes. It s implif ies ma in t enance because y o u only need to make changes to the func t ion o r correct ions to the modular iza t ion unit once and not t h roughou t the programs . If the r equ i r emen t s change, of ten it is possible to switch out the o n e

Key Concepts Refresher Chapter 6 249

m o d u l a r i z a t i o n call f o r a n o t h e r . You can also p roces s a call as a un i t in t h e D e b u g -

g e r w h e n e x e c u t i n g y o u r p r o g r a m .

It is poss ib le to p r o v i d e m o d u l a r i z a t i o n e i t h e r locally o r globally. You h a v e t w o t e c h n i q u e s f o r local p r o g r a m m o d u l a r i z a t i o n : s u b r o u t i n e s ( f o r m rou t ines ) a n d m e t h o d s w i t h i n local classes. Local m o d u l a r i z a t i o n uni ts , by de f in i t i on , a r e o n l y avai lable in the p r o g r a m in w h i c h they a re i m p l e m e n t e d . N o o t h e r p r o g r a m m u s t b e l oaded to the use r con tex t at r u n t i m e w h e n y o u use a local m o d u l a r i z a t i o n un i t .

Caution

For historical reasons, it is technically possible to call a subroutine from another program. You should not use this option, however, because this technique con-tradicts the principle of encapsulation of data and functions.

As w i t h local p r o g r a m m o d u l a r i z a t i o n , t h e r e a re t w o t e c h n i q u e s f o r global m o d -u la r iza t ion : f u n c t i o n m o d u l e s a n d m e t h o d s w i t h i n g lobal classes. Global m o d u -lar iza t ion un i t s can b e u s e d b y a n y n u m b e r o f p r o g r a m s at t h e s a m e t i m e . T h e g loba l ly d e f i n e d m o d u l a r i z a t i o n u n i t s a re s t o r e d in t h e ABAP R e p o s i t o i y a n d o n l y l oaded w h e n r e q u e s t e d b y t h e cal l ing p r o g r a m .

Ideally, t h e m o d u l a r i z a t i o n un i t s tha t a re called d o no t use t h e da t a o b j e c t s o f t h e cal l ing p r o g r a m d i rec t ly . N o r s h o u l d t h e cal l ing p r o g r a m c h a n g e t h e da ta o b j e c t s o f t h e m o d u l a r i z a t i o n un i t d i rec t ly . Th is p r inc ip l e is k n o w n as data encapsulation. This is an i m p o r t a n t t e c h n i q u e in d e v e l o p i n g t r a n s p a r e n t , m a i n t a i n a b l e s o u r c e c o d e .

P a r a m e t e r s a re used to e x c h a n g e da ta b e t w e e n t h e cal l ing c o d e a n d t h e m o d u l a r -iza t ion un i t . T h e total n u m b e r o f p a r a m e t e r s in a m o d u l a r i z a t i o n un i t is cal led t h e i n t e r f a c e o r s i gna tu r e . P a r a m e t e r s a r e d i f f e r e n t i a t e d o n w h e t h e r t h e y a re u s e d to pass da ta i n t o t h e m o d u l a r i z a t i o n un i t ( i m p o r t i n g p a r a m e t e r s ) o r r e t u r n da ta f r o m t h e m o d u l a r i z a t i o n un i t ( e x p o r t i n g p a r a m e t e r s ) o r to pass da t a i n to a n d r e t u r n f r o m the m o d u l a r i z a t i o n un i t ( chang ing p a r a m e t e r s ) .

ABAP Subroutine

A s u b r o u t i n e is:

• I n t r o d u c e d w i t h the FORM s t a t e m e n t .

• You spec i fy t h e n a m e o f t h e s u b r o u t i n e a n d t h e in t e r f ace a f t e r FORM.

250 Chapter 9 Basic ABAP Programs and Interface Creation

• T h e s t a t e m e n t s o f t h e s u b r o u t i n e f o l l o w t h e FORM s t a t e m e n t .

• T h e ENDFORM s t a t e m e n t c o n c l u d e s t h e s u b r o u t i n e .

In t h e i n t e r f a c e d e f i n i t i o n , y o u l is t t h e f o r m a l p a r a m e t e r s o f t h e s u b r o u t i n e a n d

t y p e t h e m . A f o r m a l p a r a m e t e r is h o w y o u a d d r e s s t h e d a t a o b j e c t p r o v i d e d in

t h e ca l l ing c o d e w i t h i n t h e s u b r o u t i n e . You m u s t s p e c i f y t h e p a s s t y p e f o r e a c h

p a r a m e t e r .

• Call b y v a l u e : US ING VALUE

• Call b y v a l u e a n d r e s u l t : CHANG I NG VALUE

• Call b y r e f e r e n c e : CHANGING o r USING ( a l t h o u g h CHANGING is r e c o m m e n d e d i f

t h e c o n t e n t s a r e c h a n g e d ) .

You m u s t s p e c i f y t h e a d d i t i o n s TABLES, USING, CHANGING, a n d RAISING, in t h i s

o r d e r ( see L i s t ing 9 . 8 a n d L is t ing 9 . 9 f o r a n e x a m p l e o f m u l t i p l e t y p e s ) . S p e c i f y -

i n g TABLES a f t e r USING o r CHANGING c r e a t e s a f o r m a l p a r a m e t e r c a l l ed TABLES.

L i k e w i s e , s p e c i f y i n g USING a f t e r CHANGING c r e a t e s a f o r m a l p a r a m e t e r ca l l ed

USING.

IF c u r s o r _ f i e l d - 'SOURCE_ID' ANO c u r s o r _ v a l u e NE s p a c e . PERFORM c r e a t e _ r e q u e s t

USING c u r s o r _ v a l u e a b a p _ p g e d i t o r - > a b a p _ e d i t o r - > c o n t e x t - > c o n t e x t _ t y p e

CHANGING l _ w b _ r e q u e s t . ELSE.

Listing 9-8 Call t o a Subrout ine with both USING and CHANGING

FORM c r e a t e _ r e q u e s t USING p_name TYPE progname p _ t y p e

CHANGING p _ l _ w b _ r e q u e s t . DATA: l _ s c o p e _ o b j e c t s TYPE r i n f o o b j .

l _ s c o p e _ o b j t y p e s TYPE r s e u t y p e s . l _ o b j e c t _ t y p e TYPE s e u _ o b j t y p e . l _ o b j e c t _ n a m e TYPE r s f i n d .

l _ o b j e c t _ t y p e - p _ t y p e . l _ o b j e c t _ n a m e - p_name. CALL METHOD

c 1 _ w b _ i n f o s y s t e m - > c r e a t e _ w h e r e _ u s e d _ 1 1 s t _ r e q u e s t EXPORTING

p _ o b j e c t _ t y p e - p _ o b j e c t _ t y p e p _ o b j e c t _ n a m e - 1 _ o b j e c t _ n a m e

Key Concepts Refresher Chapter 6 237

p _ s c o p e _ o b j e c t s - l _ s c o p e _ o b j e c t s p _ s c o p e _ o b j e c t _ t y p e s - 1 _ s c o p e _ o b j t y p e s

I M P O R T I N G

p_wb_request E X C E P T I O N S

e x e c u t e _ i n _ b a t c h a c t i o n _ c a n c e l l e d e r r o r _ o c c u r e d O T H E R S

p _ l _ w b _ r e q u e s t

- 1 - 2

- 3 - 4

E N D F O R M . c r e a t e _ r e q u e s t

Lis t i ng 9 . 9 The Subroutine ( F O R M Routine)

With the addi t ion o f R A I S I N G , class-based except ions can be passed, which are t r iggered in the sub rou t ine o r p ropaga ted to the sub rou t ine by the ABAP r u n t i m e e n v i r o n m e n t o r by using the s t a t emen t RAISE EXCEPTION, bu t a re not handled in a TRY block.

Internal tables shou ld be passed wi th e i ther USING o r CHANGING. The o the r advan-tage o f using o n e of these is that y o u can pass internal tables o the r than s tandard tables, for example sorted o r hashed . It is r e c o m m e n d e d that all pa ramete rs for any type of modular iza t ion un i t be typed. Typing provides addi t ional syntax checking du r ing activation a n d provides faster execut ion du r ing run t ime .

ABAP Function Module

A func t ion m o d u l e is a r ou t ine o r reuse c o m p o n e n t that is s to red centrally in the Funct ion Libraiy o f an SAP sys tem. Each func t ion m o d u l e has an interface wi th pa ramete r s for impor t ing o r expor t ing data. The main p u r p o s e o f a func t ion m o d u l e is its reusabil i ty. It t he re fo re belongs to the reuse c o m p o n e n t s . Funct ion modu le s can also be accessed f r o m outs ide the sys tem by external sys tems o r processes if they are a remote -enab led modu le .

Funct ion modu le s are assigned to a func t ion g r o u p . Each func t ion g r o u p is a col-lection o f func t ion modu le s that have similar func t ions o r process the same data. A func t ion g r o u p can conta in the same c o m p o n e n t s as an executable p rog ram ( f rom a sys tem perspect ive, they are a type of p rogram, but a re not executable directly). Table 9 .2 shows the types of c o m p o n e n t s that can be placed in a func-t ion g roup .

238 Chapter 9 Basic ABAP Programs and Interface Creation

C o m p o n e n t P u r p o s e

Data Objec t These are global in relation to t he funct ion g roup , tha t is, they are vis-ible to and can be changed by all funct ion modules within t he g roup .

Subrout ine These can be called f rom all funct ion modu le s in t he g roup .

Screens These also can be called f rom all funct ion modules within t he group .

Table 9.2 Function M o d u l e Elements

As f o r s u b r o u t i n e s , a f u n c t i o n m o d u l e c a n c o n t a i n i ts o w n local t y p e s a n d d a t a

o b j e c t d e f i n i t i o n s . T h e s e c a n o n l y b e s e e n w i t h i n t h e f u n c t i o n m o d u l e . T h e i n t e r -

f a c e o f a f u n c t i o n m o d u l e c a n c o n t a i n t h e e l e m e n t s s h o w n in T a b l e 9 . 3 . F i g u r e

9 . 6 s h o w s a f u n c t i o n m o d u l e w i t h all e l e m e n t s . Y o u s h o u l d t y p e i n t e r f a c e p a r a m -

e t e r s w i t h t y p e s f r o m t h e A B A P D i c t i o n a i y .

E lemen t P u r p o s e

Import pa rame te r Values or variables of t he calling program can be t ransferred to t h e m when calling t he funct ion module . The opt ional paramete rs d o not need to be supplied during t he call.

Export pa ramete r The calling program accepts t he o u t p u t of t he funct ion mod-ule by assigning a receiving variable to an export parameter . Export pa ramete rs a re always opt ional .

Changing pa ramete r You can transfer variables f rom the calling program to t he funct ion module , whe re they are changed and re turned to t he calling program.

Tables pa ramete r This pa ramete r is similar t o t he changing pa ramete r in tha t

(obsolete) t he table provided can b e changed . However , it can only be used for s tandard tables. The formal pa ramete r specified by this parameter within t he funct ion m o d u l e will always have a header line.

Internal tables should be passed with Import , Export, or Changing parameters . The o the r advantage of using o n e of t he se (as with subrout ines) is tha t you can pass internal tables o the r than s tandard tables, for example , sor ted or hashed tables.

Table 9.3 Function M o d u l e Elements

Key Concepts Refresher Chapter 6 239

Element Purpose

Exceptions These can be raised by the function module in error situa-tions and provide information regarding the processing error. Exceptions should always be caught and handled by the call-ing program.

Table 9.3 Function Module Elements (cont.)

FUNCTICM b p _ j o b _ s e l e c t .

"'"Global ZntccZice: " IMPORTING

VALUE (JOBSELECT_DZALOG) LIXE BTCHOOOO-CHAR1 VALVE(JOBSEL_PARAM_ IN) LIKE BTCSELECT STRUCTURE BTCSELECI

DEFAULT SPACE VALUE(ENDDATE) LIKE TBTCO-ENDDATE DEFAULT ' VALUE (ENDTIME) LIKE TSTCO -ENDTIME DEFAULT • • VALUE(SELECTION) TYPE CHAR2 DEFAULT 'AL'

" EXPORTING VALUE(JOBSELPARAMOUT) LIKE BTCSELECT STRUCTURE BTCSELECT

" TABLES JOBSELECT_JOBLIST STRUCTURE TBTCJOB JOBXAME_EXT_SEL STRUCTURE NJRANGE OPTIONAL USERNAME_EXT_SEL STRUCTURE UNRANGE OPTIONAL

- CHANGING REFERENCE(ERROR_CODE) TYPE I OPTIONAL

- EXCEPTIONS INVALID_ DIALOG_ TCPE JOBNAMEJilSSING NOJJOBSFOUND SELECTION_ CANCELED USERNAME MZSSZNG

Figure 9.6 A Function Module Interface is Documented as Comments

You can use t he logical exp res s ion IS SUPPLIED w i t h i n a f u n c t i o n m o d u l e to see if an actual p a r a m e t e r was set f o r a fo rmal p a r a m e t e r d u r i n g a call. The o lde r log-ical exp res s ion IS REQUESTEO s h o u l d n o longer be u sed . The o l d e r logical expres -s ion IS REQUESTED checked on ly t he o u t p u t p a r a m e t e r , w h e r e a s t he logical express ion IS SUPPLIED can be used wi th all op t iona l p a r a m e t e r s . The express ion IS INITIAL shou ld not be used because it d o e s n o t take in to accoun t tha t a defau l t va lue was u sed .

If a p r o g r a m calls a f u n c t i o n m o d u l e , the en t i r e c o r r e s p o n d i n g f u n c t i o n g r o u p is loaded in to t he s a m e in te rna l sess ion as t he calling p r o g r a m , a n d t he f u n c t i o n m o d u l e is execu ted . The f u n c t i o n g r o u p r e m a i n s loaded in m e m o r y unt i l t he call-

254 Chapter 9 Basic ABAP Programs and Interface Creation

ing program is dosed. When you call another function module of this group, it is processed without needing to be reloaded, and the same global data exists. Therefore, i fyou call a function module that stores values in a global data object of the function group, other function modules in the same group can access this data when they are callcd during the same program.

You should note in Figure 9 . 7 the O P T I O N A L and P A S S V A L U E checkboxes (which in the example arc shortened to OPT... and PA...), which control if the parameter is required and if it is copied (pass by value). In Figure 9 .8 , you should note that the Optional checkbox does not exist because all export parameters are optional. Figure 9 .9 shows the changing parameters. Figure 9 . 1 0 shows the table parame-ters. Note that the pass by value option does not exist. Finally, Figure 9 . 11 shows the exceptions for this function module.

Funcfcjn moijyVf BP_J08_SELECT Active 1 imooi i E*ocrt A Changing , Tattes , Exceptions Source code

r m m [Parameter Name fType [Associated Type 'default value Opt |Pa IShoitte«i

J0BSELECT_DUL06 LIKE 6TCHOOOO-CHARI Oiat©jBcnYesOO/Ne<N) JOBSEl.PmNJN LIKE 8TCSELECT SPACE Selec*on Parameters (input)

ENOOME LIKE TBTCO-ENDOME • •

EMDTWC LIKE TBTCO-ENDTIHE

SELECTION TYPE CHAR2 •AL' Smflle-Cnaractef Flag

Figure 9.7 Func t ion M o d u l e Input P a r a m e t e r s

[Func»onmod»j»e BP_JW_SaCCT AdM

ABnbute* import Clunpmfl , T«w» Eatepflorw Source tode

I L I H I <-J J IPinmmrHtnit |Typ> tpet [AstOCHted Type |P»««V»I jSftOiltH

JOBSEL_Pmn_OUT LIKE BTCSELECT 7 SelectionParameters (Ou«pjtl

Figure 9 . 8 Func t ion M o d u l e Export P a r a m e t e r s

Function module 8P_J0$_SELECI At true

A Af lnC 'Ulcs | i Tables A Exceptions Source cc<le

r m m (parameter Name |T«>esp«c [AssociatedType|Oerau* va«ue|Opt>onal |PassVai Jsnoittea ERROR_COO€ TYPE I Special Additional Error Code

Figure 9 . 9 Funct ion M o d u l e Chang ing P a r a m e t e r s

Key Concepts Refresher Chapter 6 241

[fuiictan n t i i i s i V . J N . U l K l Actt*

^ M i n w w w t fryp««p«< |M«oMM»aTyp« O J JUL

]c>K>:*ai [s fo t i tx X«nCCT.JOMit l HI TBICJM jcwuinE.Eit.aL u « NJ=.«HES USMHME.CIT.TFL LH* UMUMC

s»i«<t»a jotit &MCi *««cton rang* fce >U> nam« BiVfi s«*cton rang* ier uur n»m«

Figure 9.10 Function Module Tables Parameters

^j—iMwtf/ iwpcn Yflwii V ctwnghg Y r m w a ^ E ^ M C S w u n n n

Isrcrttud [LongM l»VAU0_0IM.06_TrPC jfle**n[_nissitiO M_joes_ra.wo SELECT !C«_CAJ»CELED USERHMtE.MSSIHS

IrwaM dtalog two Job Nam* it VHt rq (Wizards Mowed) NoJ<M roo'.J That Matth S«i»cMa cm*n CM'CarctH StIKtOn Ut«f Mar* Misting {WV.jc »"ds AIWwkJ)

o. 3.

o o o

F i g u r e 9.11 Function Module Exceptions

ABAP Classes and Methods

In the course of ex tending the ABAP language to include object-or iented concepts , global classes w e r e in t roduced that use m e t h o d s to provide funct ions . Like func-t ion modules , m e t h o d s also have an interface, k n o w n as a signature, which con-sists of import ing, export ing, changing, and re turn ing parameters and except ions.

In addi t ion to me thods , classes have o the r c o m p o n e n t s . They conta in global data objects k n o w n as attributes. In the same way that global data objects of a func t ion g r o u p can be accessed by all the func t ion modu le s in the g roup , all m e t h o d s can access t he a t t r ibutes of their classes.

With func t ion groups , the global data objects a re not visible ou t s ide the func t ion g roup . This is the encapsula t ion of data in a func t ion g roup . At t r ibutes are also normal ly encapsula ted wi th in the class and can the re fo re on ly be read o r changed using m e t h o d s of t he same class. However , in contras t to func t ion mod-ules, classes also a l low y o u to make specific a t t r ibutes visible to the users o f t he class. A dis t inct ion is the re fo re m a d e b e t w e e n public and pr ivate a t t r ibutes .

This dis t inct ion is appl ied not only to at t r ibutes , bu t also to me thods . Wher ea s all func t ion modu le s can be called f r o m ou t s ide the func t ion g roup , only publ ic m e t h o d s a re available ou t s ide the class. Private m e t h o d s can only be called by

242 Chapter 9 Basic ABAP Programs and Interface Creation

o the r m e t h o d s o f the same class and arc thus similar to sub rou t ines ( form rou-tines) wi th in a func t ion g roup .

The m a j o r d i f fe rence b e t w e e n global classes and func t ion g r o u p s is that a func-tion g r o u p wi th its global data objects can only be loaded once to the p rogram context for each main p rog ram, but the data of a global class can be loaded as m a n y t imes as y o u like. This is k n o w n as multiple instantiation of the class. In practice, it m e a n s the global data object values are the same for all func t ion mod-ule calls, because we have only o n e copy of each of the data objects o f a func t ion g r o u p . A class can have several instances, each of which is s tored separately in t he p rogram context o f the main p rog ram. Each ins tance can the re fo re have dif-fe ren t a t t r ibu te values. A m e t h o d can see d i f fe ren t values in the a t t r ibutes d e p e n d i n g on the instance f r o m which y o u called it.

At t r ibutes that can have d i f fe ren t values for each instance a re k n o w n as instance attributes to dis t inguish t h e m f r o m static attributes (or class attributes). Static a t t r ibutes exist on ly once for each p rog ram context regardless o f h o w m a n y class instances a re gene ra t ed . If instance m e t h o d s access a static a t t r ibute , all instances see the same value.

Note the PASS VALUE and OPTIONAL checkboxes (which in the example a re shor t -ened to P... and O.. . ) . wh ich control if the pa rame te r is copied (pass by value) and is requi red .

Figure 9 .12 shows the a t t r ibutes of a m e t h o d . Figure 9 .13 shows the pa ramete r s for the m e t h o d . Figure 9 .14 s h o w s the except ions for the m e t h o d . The beginning of the m e t h o d is s h o w n in Listing 9 .10.

:<iew*»r<.j cow* Ri.Mjuecp. BASE foni la.vmnr UtVO! CO«Y(*IJMW(R_MK 0**tr(«an Coamt • rwntw »*n ««• in, to

Cit'.urOffK* fv*1

Figure 9.12 Method Attributes

Key Concepts Refresher Chapter 6 243

Dj-&5pl»fM!«*iod COf*tRT_NU«fflER_8ASE

|CtMS Za_OIILIIT u tree COMM.

Oetenpbc* Corwet a number from on« bate to ano»i*r ^ Aft-AuU* E.tepbont

I * Method* I " J Exc« 1 i b 1 ir 1 1 1 PerametH |T»PO |P lo [Turn [AjOKaun |D«K"Mon SOURCE.BASE w w r t . Type I 10 Source bate of number DESTI NATI0N_BA&E rmpert. Type I Oetinabci bate for number SOURCEJtUNBER impcrt - Type C Source number (may contain ti f EST I MAT I 0N_NURBER EipoiD. iyp« C Oesinattcn rujmw* <m*y conl» SOURCE.OVCRFION.ERROR* Erporti Type I Number of o«rSow i r o n

Figure 9.13 Method Parameters

jvCttplay C0ff«€RT_NU«»ER.8ASE

z a . o i i L i i T M p r « contftt.nnesft.ejiif Oetcnptw Convert» numter from oo« ease to anorer

*n-e-Mt M J ' I g y E«ep*m

JJHIL I I I I 1 1 [Cxcepton lOetcnplon S*SE_M0T_I0ENTIF1C0 Eir*< towce or uettrtaoon tate it not tpetified BASE.NOT.SUPPORTEO £»*« touce or dettnaaon bate i» not supported (too 6<g> HUHBER_lS_MOT_$PECir IC0_0ASC TM source »cont»n« *»Yj*t not conslMtrtwf toixce bate SOURCE_*U«BER_TOO.LO*6 Number of d»grti in tource numter not supported

Figure 9.14 Method Exceptions

method conver t_number_base . d a t a :

1 v _ f a c t o r type P l e n g t h 10. 1v_converted_number type P l e n g t h 10.

1v_src_nbr type c l e n g t h 9 9 . 1 v _ i t e r a t i o n s type 1. 1 v _ p o s i t i o n type 1. 1v_max_value type i . 1 v _ d i g i t type 1 . 1v_exponent type i .

f i e l d - s y m b o l s : < d i g i t >

c o n s t a n t s : l c _ s t a r t i n g _ f a c t o r lc_number_base

type c .

type i v a l u e ' 1 9 ' . t ype c l e n g t h 36

v a l u e '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' i f source_base i s i n i t i a l or

d e s t i n a t i o n b a s e i s i n i t i a l .

244 Chapter 9 Basic ABAP Programs and Interface Creation

r a i s e b a s e _ n o t _ i d e n t i f i e d . e n d i f .

l v _ i t e r a t i o n s - s t r l e n ( lc_number_base ) .

Listing 9.10 Method Coding

Note

You should note that the terms instance and object are often used interchange-ably. Further details regarding ABAP Object-Oriented programming is discussed in Chapter 14. ABAP Object-Oriented Programming.

As w i t h f u n c t i o n m o d u l e s a n d s u b r o u t i n e s , y o u h a v e t h e capabi l i ty to i m p o r t ,

e x p o r t , c h a n g e , a n d p r o d u c e e x c e p t i o n s . M e t h o d s also p r o v i d e t h e abi l i ty to

r e t u r n a value , w h i c h a l lows the call to b e p laced w i t h i n e i t h e r a COMPUTE s tate-

m e n t o r a logical e x p r e s s i o n . A n o t h e r d i f f e r e n c e is t h a t e v e i y p a r a m e t e r is

r e q u i r e d to b e t y p e d . This is d i f f e r e n t f r o m b o t h s u b r o u t i n e s a n d f u n c t i o n m o d -

ules , w h e r e it is r e c o m m e n d e d tha t t h e p a r a m e t e r s a re t y p e d .

ABAP Selection Screen

In gene ra l , se lec t ion s c r e e n s a r e u s e d f o r e n t e r i n g se lec t ion cr i te r ia f o r da t a selec-t ion . F r o m a technica l pe r spec t ive , se lec t ion s c r e e n s a r e D y n p r o s . H o w e v e r , t h e y a r e n o t d e s i g n e d by t h e d e v e l o p e r d i rec t ly , bu t g e n e r a t e d in a c c o r d a n c e w i t h dec la ra t ive s t a t e m e n t s in t h e s o u r c e c o d e .

T h e se lec t ion sc reen has t h e f o l l o w i n g s t a n d a r d f u n c t i o n s :

• Text o n t h e se lec t ion sc reen can b e m a i n t a i n e d in severa l l anguages . At run t -

i m e t h e t ex t is au toma t i ca l l y d i sp l ayed in t h e u s e r ' s l ogon l anguage .

• T h e s y s t e m checks types au tomat i ca l ly .

• In a d d i t i o n to s ingle va lue en t r i e s ( P A R A M E T E R S ) , y o u can also i m p l e m e n t c o m -plex se lec t ions ( S E L E C T - O P T I O N S ) o n t h e se lec t ion sc reen . W i t h a c o m p l e x se lec t ion ( S E L E C T - O P T I O N S ) , t h e u s e r can e n t e r mu l t i p l e va lues , in terva ls , c o m p a r a t i v e c o n d i t i o n s , o r even p a t t e r n s as res t r i c t ions .

• If t h e i n p u t field is d e f i n e d us ing a n ABAP Dic t iona ry e l e m e n t , t h e field doc-

u m e n t a t i o n can b e d i sp layed o n t h e i n p u t field u s ing t h e (TT| f u n c t i o n key .

T h e va lue h e l p a t t a c h e d to t h e D i c t i o n a i y t y p e d i sp l ay ing poss ib l e i n p u t s can

Key Concepts Refresher Chap te r 6 259

be called up using the [?4] function key. It is also possible for the label (selec-

t ion text) to use the long text o f the data e lement .

• You can easily save the values (or calculation in the case o f a dynamic date or

t ime calculation) o f complicated selection screens as selection screen variants

for reuse or use in background processing.

Listing 9 . 1 1 shows the coding for a selection screen, and Figure 9 .15 shows the

resulting generated selection screen.

*** P a r a m e t e r s / S e l e c t - o p t i o n s s e l e c t i o n - s c r e e n b e g i n o f b l o c k cOl

w i t h f r a m e t i t l e t e x t - c O l . p a r a m e t e r s :

p _ c u s t z g a s c h e c k b o x d e f a u l t ' X * . p _ w r k b c h a s c h e c k b o x d e f a u l t ' X ' . p _ r e p a i r a s c h e c k b o x d e f a u l t ' X ' . p _ o t h e r s a s c h e c k b o x d e f a u l t ' X ' .

s e l e c t i o n - s c r e e n end o f b l o c k c O l . s e l e c t i o n - s c r e e n b e g i n o f b l o c k c 0 2

w i t h f r a m e t i t l e t e x t - c 0 2 . p a r a m e t e r s :

p _ r _ p o r a d i o b u t t o n g r o u p s o r t . p _ e _ s _ r r a d i o b u t t o n g r o u p s o r t . p _ r _ s _ d r a d i o b u t t o n g r o u p s o r t . p _ d _ s _ r r a d i o b u t t o n g r o u p s o r t . p _ r _ d _ s r a d i o b u t t o n g r o u p s o r t ,

s e l e c t i o n - s c r e e n end o f b l o c k c 0 2 . s e l e c t i o n - s c r e e n b e g i n o f b l o c k c 0 3

w i t h f r a m e t i t l e t e x t - c 0 3 . s e l e c t - o p t i o n s :

s _ t r k o r r f o r g s _ o u t t a b - t r k o r r . s e l e c t i o n - s c r e e n end o f b l o c k c 0 3 . s e l e c t i o n - s c r e e n b e g i n o f b l o c k c 0 4

w i t h f r a m e t i t l e t e x t - c 0 4 . s e l e c t - o p t i o n s :

s _ u s e r f o r g s _ o u t t a b - a s 4 u s e r m o d i f i d c 0 4 . s e l e c t i o n - s c r e e n end o f b l o c k c 0 4 .

p a r a m e t e r s : p _ r e l s e d a s c h e c k b o x d e f a u l t ' X * . p _ b y u s e r a s c h e c k b o x u s e r - c o m m a n d a c t i v a t e . p _ m i s s n g a s c h e c k b o x . p _ a p p r v l a s c h e c k b o x .

26o C h a p t e r 9 Basic A B A P P r o g r a m s a n d I n t e r f ace C r e a t i o n

p_apmiss as c h e c k b o x .

p_sumrze as checkbox d e f a u l t " X * .

L i s t i n g 9 .11 C o d i n g f o r a S e l e c t i o n S c r e e n

T r a n s p o r t Logs

Typeset transports

E Customary Transports

& System (WorVt>ench) Transports

£ Repair Transports

E Other Transports

Report m order by

© E«port Dt tn n > m i l by Seq O E«port Dt tn Sytttm by Request O Request by »m by Date O Oaie by System by Request O Request by Date trt Sysitm

Transports

RequestT*M> M JrSfK* » [<•]

user IDs 0«mer »

0 F iter with expcrte-d

• S»'«<t tasks by user ©

• Identtf supped systems

• Stivm apprcwal coVmns

• Fiber with mis wvg approvals

E Summarge win last »clon

F i g u r e 9 . 1 5 G e n e r a t e d S e l e c t i o n S c r e e n

Further details regarding selection screens are discussed in Chapter 13, Selection Screens.

Authorization Checks

Critical data and parts of the functional scope of the SAP system must be pro-tected from unauthorized access. You have to implement authorization checks in your program so that the user can only access areas for which they arc autho-rized. To code an authorization check you use the AUTHORITY -CHECK statement to check whether the current user has the authorization required for executing the function in his master record. Depending on the check result returned in the SY-SUBRC, you can continue accordingly. If the return code equals 0 (zero), the user

Key Concepts Refresher Chapter 6 247

has the required authorization. Authorization objects can also be defined in report transaction codes to provide additional restriction other than simply by transaction code.

Under normal circumstances, the definition of authorization objects is part of data modeling and the creation of database tables. Implementing the authoriza-tion check is one of the tasks of the developer who programs access to the data-base tables. The subsequent steps, such as defining the authorizations and user profiles and assigning them to the user master records, are the tasks of the administrator or security team.

Before you can implement the required authorization check in your program, you must first determine the structure (the fields) of the corresponding authori-zation object. An object usually consists of the ACTVT (activity) field and one or several other fields, which specifies the data type to be protected, for example, material number, organization unit, account number, and so on.

Tip

If you d o no t w a n t to carry ou t a check for a field, ei ther d o not en te r it in t he AUTHORITY CHECK s t a t emen t or en ter DUMMY as t h e field value. DUHMY is a pre-def ined descript ion en te red w i thou t quo ta t ion marks.

Example of a suppressed field check: W h e n a change transact ion is called, t he system should always check immediate ly w h e t h e r t he user has any change author izat ion. If t h e check fails, an appropr ia te message is to be o u t p u t to t he user immediately (see t he first AUTHORITY CHECK in Listing 9 .12 for an example of t he syntax; t he authorizat ion ob jec t can be seen in Figure 9 .16) .

I f p_s_develop-devclass - space, authority-check object 'S.DEVELOP'

id 'DEVCLASS' dummy id '080TYPE' f ie ld p_s_develop-objtype id 'OBJNAME' f ie ld p_s_developobjname id 'P_GR0UP' dummy id 'ACTVT' f ie ld l_develop_actvt.

else. authority-check object 'S_DEVEL0P'

id 'DEVCLASS' f ie ld p_s_developdevclass id '08JTYPE' f ie ld p_s_develop-objtype id '08JNAME' f ie ld p_s_develop-objname id 'P_GROUP' dummy

262 Chapter 9 Basic ABAP Programs and Interface Creation

id 'ACTVT' f ie ld l_develop.actvt. endif. List ing 9.12 Call t o an Author i za t ion Check

Display authorization object

Is®" O t # d SJCVtlOP

T M ABAP WMttMOCh

C l o t 8C_C Basis • O M M f m M t Enwonmertl Author SAP

Autr>c*aaew>f*ids Field ntm* Headrvj

KVCUSS Package OBJTTFt Otyeciw*

08JKUE Obieci name

AuftortMUA group A8APJ4 f*»gr»m ACTVT Anton,

AuftWttOC* OBIKI OOCUmeMMM*

G f OmX»y Ot<ett OocumentiQon |

f urttier aufftonzMon owed M n g t a Ptrmcofl ActvBOS | D j

Figure 9.16 Author i za t ion O b j e c t

Again to avoid spelling errors in object and field names, you can use the P A T T E R N

button to generate the appropriate AUTHORITY - CHECK statement.

ABAP Dynpros

As mentioned earlier, standard screens or Dynpros are designed by the devel-oper directly through the use of the Screen Painter. A screen consists not only of its layout with input and output fields, buttons, and other screen elements, but also a processing logic known as flow logic. The fact that the ABAP Dictionary is integrated into the system provides automatic consistency checks for screen input fields. These checks include type checks, foreign key checks, and fixed value checks.

The above checks can be complemented with other program checks. Techniques are available for screens that allow you to control the order in which checks are performed. If an error occurs, the appropriate fields are made input ready again.

Key Concepts Refresher Chapter 10 9

The layout can be des igned very flexibly, wi th input fields, o u t p u t fields, radio but tons , check fields, and b u t t o n s wi th which co r r e spond ing func t ions of the p rog ram can be executed .

Fur ther , screens have the same fo rma t t ing op t ions as lists and selection screens: Fixed poin t n u m b e r s a n d dates a rc fo rma t t ed according to the sett ings in the user mas te r record , t imes a re fo rmat ted as HH : HM: SS, cur rency a m o u n t s are fo rma t t ed according to the currency, and physical m e a s u r e m e n t s (lengths, weights , quant i -ties, etc.) are fo rmat ted according to their uni t fields.

In theory , the re a re two op t ions for s tar t ing a screen sequence :

• By calling the first screen (using the CALL SCREEN s ta tement ) f rom a processing block in y o u r p rogram

• By creat ing a dialog t ransact ion that re ferences the p rogram and the first screen

After a screen is processed, the statically o r dynamical ly de f ined screen sequence is processed. A formal next screen of 0 (zero) re tu rns processing to the poin t w h e r e the screen was called o r ends the dialog t ransact ion.

Screens can appea r in executable programs, func t ion groups , o r modu le pools:

• Execu tab l e p r o g r a m Executable p rog rams (reports) use screens to display data in addi t ion to the list ou tpu t , o r to replace the list o u t p u t display complete ly , and somet imes for t he display o f an ALV grid. You can also use screens to e n t e r and change data in t he list. For the p u r p o s e o f reusabil i ty a n d data encapsula t ion , y o u should no longer create screens direct ly in repor ts , bu t use screens in func t ion g roups instead.

• F u n c t i o n g r o u p Funct ion g r o u p s o f t en use screens to encapsula te a screen o r screen sequence for reuse. SAP provides a vast n u m b e r of such encapsula ted screens o r screen sequences . Various SAP s tandard func t ion modu le s can be f o u n d in t he Repository In fo rmat ion System s imply by looking for "popup" as part o f t he func t ion m o d u l e n a m e . These encapsula ted screens exist for displaying mes-sages, accepting values, and selecting b e t w e e n op t ions .

• M o d u l e poo l M o d u l e pools can only be s tar ted wi th a t ransact ion code: they cannot be tested as o the r types of executable p rog rams direct ly in t he ABAP W o r k b e n c h (Transaction SE80) or ABAP Editor (Transaction SE38). In contras t to screens

250 Chapter 9 Basic ABAP Programs and Interface Creation

in f u n c t i o n g r o u p s , y o u c a n n o t e n c a p s u l a t e m o d u l e poo l s o r p r o v i d e an exter -

nal i n t e r f ace .

W h e n a sc reen is d i sp l ayed f o r a user , t h e p r e s e n t a t i o n s e r v e r p e r f o r m s all in ter -ac t ions unt i l a f u n c t i o n is se lec ted . A f u n c t i o n c o r r e s p o n d s to e i t h e r a b u t t o n o n t h e app l i ca t ion too lba r , a m e n u , o n e o f t h e f u n c t i o n keys (I r i | t h r o u g h 1 r i 2 | ) , o r t h e [ 3 key . Each o f t h e s e ac t ions b y a u s e r ass igns t h e f u n c t i o n c o d c d e f i n e d b y the p r o g r a m m e r to a special field assoc ia ted w i t h e v e r y s c r een . This field is n o r m a l l y r e f e r r e d to as t h e 0 K _ C 0 D E . You n o r m a l l y n a m e this field a n d p r o v i d e a g lobal field w i t h t h e s a m e n a m e to rece ive t h e va lue in y o u r p r o g r a m . T h e field s h o u l d b e d e f i n e d to use t h e t y p e SYUCOMM. This t r a n s p o r t t o th is va r i ab l e is au to -mat ic . D u r i n g t h e PAI (p rocess a f t e r inpu t ) y o u can d e t e r m i n e w h a t ac t ion t h e u s e r p e r f o r m e d t h r o u g h t h e c o n t e n t s o f th is var iab le .

T h e s t a t e m e n t C A L L SCREEN accesses the D y n p r o s o f t h e r e l evan t m a i n p r o g r a m

of t h e c u r r e n t p r o g r a m g r o u p , a n d t h e s e u s e t h e g lobal da t a a n d d ia log m o d u l e s

o f t h e m a i n p r o g r a m . If t h e spec i f i ed D y n p r o d o e s n o t exis t in t h e m a i n p r o g r a m

of t h e p r o g r a m g r o u p , an u n t r e a t a b l e e x c e p t i o n occu r s .

You use t h e a d d i t i o n S T A R T I N G AT t o o p e n a n e w p o p u p level a n d to d isp lay all s c r e e n s o f t h e cal led D y n p r o s e q u e n c e in a m o d a l d ia log b o x r a t h e r t h a n as a full s c r een . T h e u p p e r - l e f t c o r n e r o f t h e d ia log w i n d o w is d e t e r m i n e d by t h e va lues f o l l o w i n g t h e a d d i t i o n S T A R T I N G A l f o r t h e c o l u m n a n d l ine . T h e va lues r e f e r to t h e w i n d o w w i t h p o p u p level 0 . T h e lower - r igh t c o r n e r is set au toma t i ca l l y f r o m t h e s ize o f t h e w i n d o w , o r y o u can spec i fy it a f t e r E N D I N G AT . For c o l u m n a n d l ine n u m b e r ( fo r e i t h e r t h e top- le f t o r b o t t o m - r i g h t co rne r ) , da ta o b j e c t s o f t y p e 1 a r e e x p e c t e d . T h e va lues o f t h e top- le f t c o r n e r s h o u l d b e sma l l e r t han t h o s e o f t h e b o t t o m - r i g h t c o r n e r ; o t h e r w i s e , t h e b e h a v i o r is u n d e f i n e d . T h e m a x i m u m p o p u p level is 9 .

If d u r i n g t h e p roces s ing o f a m o d a l d ia log b o x a n e w D y n p r o s e q u e n c e is cal led,

it m u s t b e s t a r t ed in a n o t h e r p o p u p level. You c a n n o t u s e t h e s t a t e m e n t C A L L

SCREEN w i t h o u t a d d i n g START I NG AT in th is case. W h e n call ing a D y n p r o in a dia-

log w i n d o w , spec i fy t h e w i n d o w as a m o d a l d ia log w i n d o w in its p r o p e r t i e s a n d

set an a p p r o p r i a t e GUI s t a tus b e f o r e h a n d . It is r e c o m m e n d e d tha t a D y n p r o

s e q u e n c e in a m o d a l d ia log w i n d o w cons is t o f o n l y o n e D y n p r o .

F u r t h e r de ta i l s r e g a r d i n g D y n p r o s c r e e n s a re d i scussed in C h a p t e r 12, Classical

Screens .

Key Concepts Refresher Chapter 10 251

Dia log Messages

You use the MESSAGE statement to send dialog messages to the users of your pro-gram. When you do this with an actual message defined from a message class, you must specify at least a three-digit message number, the message class, and the type of the message. It is also possible to provide the text of the message or just the type of the message.

Message number and message class clearly identify the message to be displayed. You use the message type (either A, E, I , S, w, or x; see Table 9.4) to define how the ABAP runtime should process the message.

Type Funct ion General Program Behavior

Termination The message appears in a dialog box, and the program terminates. When the user has confirmed the message, control returns to the next-highest area menu.

Error Depending on the program context, an error dialog appears or the program terminates.

Information The message appears in a dialog box. Once t h e user has confirmed the message, the program cont inues immedi-ately af ter the message s ta tement .

Status The program continues normally after the m e s s a g e s tate-ment , and the message is displayed in the status bar of the next screen

W Warning Depending on the program context, a warning dialog

appears or the program terminates.

x Exit No message is displayed, and the program terminates with a short d u m p . Program terminations with a short d u m p normally only occur when a runtime error occurs. Message type x allows you to force a program termina-tion. The short d u m p contains the message ID.

Table 9 .4 Message Types and their 8ehavior

I f the specified message contains placeholders (specified as cither an & or &#, where the it is 1, 2, 3, or 4), you can supply them with values from your program by using the w i t h addition. Instead of the placeholders, the transferred values then appear in the displayed message text. There can only be up to four place-holders, and if a number is part of the placeholder, it specifies the order in which

266 Chapter 9 Basic ABAP Programs and Interface Creation

t h e p l a c e h o l d e r s a r e filled. This a l l o w s f o r t ex t t r a n s l a t i o n t ha t m a y r e q u i r e t h e

p l a c e h o l d e r s in a d i f f e r e n t o r d e r (see Lis t ing 9 . 1 3 f o r a n e x a m p l e ) . M e s s a g e s can

e i t h e r b e d i s p l a y e d in m o d a l d i a l o g b o x e s o r in t h e s t a t u s b a r o f t h e s c r e e n b a s e d

o n t h e u s e r ' s se t t ings . H o w a m e s s a g e is p r o c e s s e d d e p e n d s o n its t y p e a n d o n

t h e c o n t e x t in w h i c h it is s e n t .

If t h e i n t r o d u c t o i y s t a t e m e n t o f a p r o g r a m c o n t a i n s t h e a d d i t i o n MESSAGE - 1 0 i d

a n d y o u r m e s s a g e to b e d i s p l a y e d is o f t h e s a m e class, y o u c a n u s e t h e s h o r t f o r m

o f t h e m e s s a g e s t a t e m e n t w i t h o u t s p e c i f y i n g t h e class. List ing 9 . 1 4 c o n t a i n s t w o

e x a m p l e s o f m e s s a g e s u s ing t h i s f o r m , a n d List ing 9 . 1 5 s h o w s t h e i n t r o d u c t o i y

s t a t e m e n t .

c a l l f u n c t i o n 'ENOUEUE_ESRDIRE' e x p o r t i n g

m o d e _ t r d i r - l_enq_mode name - i n c l 2 x_name - ' ' _ s c o p e - '2' _ w a i t - ' '

e x c e p t i o n s f o r e i g n _ l o c k - 01 s y s t e m _ f a i l u r e - 0 2 .

i f s y - s u b r c ne 0 and r s 3 8 1 - e x t e r n - s p a c e , message i d s y - m s g i d

t y p e ' £ ' number sy-msgno w i t h s y - m s g v l sy -msgv2 sy -msgv3 sy -msgv4 .

e n d i f .

Listing 9.13 Message Specifying All Options

c a l l f u n c t i o n 'CHANGEDOCUMENT_OPEN' e x p o r t i n g o b j e c t c l a s s - "WFRULES

o b j e c t i d - o b j e c t i d p l a n n e d _ c h a n g e _ n u m b e r - p l a n n e d _ c h a n g e _ n u m b e r p l a n n e d _ o r _ r e a l _ c h a n g e s - p i a n n e d _ o r _ r e a l _ c h a n g e s

e x c e p t i o n s s e q u e n c e _ i n v a l i d - 1 o t h e r s - 2 .

c a s e s y - s u b r c . when 1. message a600 w i t h 'SEQUENCE INVALID*. when 2 . message a600 w i t h 'OPEN ERROR',

e n d c a s e .

Listing 9.14 Two Messages in the Shortened Form

Key Concepts Refresher Chapter 10 253

f u n c t i o n - p o o l w f r c m e s s a g e - i d cd

Listing 9.15 Introductory S ta tement Specifying t he Message Class

This general behavior is ultimately driven by the context of where the call to the message statement occurs. One unique context is when you have no screen. This includes the following processing blocks; all other processing blocks are associ-ated with screen processing and are reacting to user input:

• The program constructor LOAD - OF - PROGRAM

• PBO modules (PBO of screens)

• The selection screen event AT SELECTION-SCREEN OUTPUT (PBO of a selection screen)

• The reporting events INITIALIZATION, START-OF-SELECT I ON, GET, and END OF-SELECTION

• The list events 10P-0F-PAGE and END-OF-PAGE

To make Table 9.5 more concise, the above-mentioned processing blocks are structured into two groups:

• Group 1 LOAD-OF-PROGRAM. PBO module of screens, AT SELECTION-SCREEN OUTPUT

• Group 2 Reporting and list events (INITIALIZATION, START - OF • SELECT ION, GET, END OF-SELECTION, TOP-OF-PAGE and END-OF-PAGE)

Type Display P roces s ing

Dialog box Program terminates , and control returns to last area m e n u .

Group 1: Dialog

box

Group 1: Behaves as type A.

Group 2: Program terminat ion and display of an e m p t y screen with e m p t y GUI status. After t he user act ion: Return t o t h e calling posit ion of t he program.

Group 2: Status line of current w i n d o w

Table 9-5 General Message Type Behavior

268 Chapter 9 Basic ABAP Programs and Interface Creat ion

Type Di sp l ay P r o c e s s i n g

G r o u p 1: S t a tu s

l ine of t h e next

sc reen

G r o u p 2: Dialog

box

S ta tus line of next

sc reen

G r o u p 1: S t a tu s

l ine of t h e next

sc reen

G r o u p 2: S t a tu s

l ine of t h e cu r r en t

w i n d o w

N o n e

Program c o n t i n u e s p rocess ing a f t e r t h e MESSAGE s t a t e -

m e n t .

Program c o n t i n u e s p rocess ing a f t e r t h e MESSAGE s t a t e -

m e n t .

G r o u p 1: 8 e h a v e s as t y p e S.

G r o u p 2 : P rogram t e r m i n a t i o n a n d display of an e m p t y

sc reen wi th e m p t y GUI s ta tus . Af te r t h e u se r ac t ion :

Re turn t o t h e calling pos i t ion of t h e p r o g r a m .

Triggers a r u n t i m e e r ro r w i th shor t d u m p

Tab le 9 .5 Genera l M e s s a g e Type Behavior (cont . )

Another unique context includes all situations w h e r e a screen is being processed,

that is. the program is reacting to user input. In ABAP programs, this means all PAI

(process after input) modules. Table 9 . 6 shows the message behavior during PAI.

Type Di sp l ay P r o c e s s i n g

Dialog box Program t e r m i n a t e s , a n d con t ro l r e tu rns t o last a r ea

m e n u

S ta tus line PAI p rocess ing is t e r m i n a t e d , a n d con t ro l r e tu rns t o t h e

cu r r en t s c r een . All of t h e sc reen fields for wh ich t h e r e is a

F I E L D o r CHAIN s t a t e m e n t a r e ready for inpu t . The user

m u s t e n t e r a n e w va lue . T h e sys t em t h e n res ta r t s PAI

p rocess ing for t h e s c r een us ing t h e n e w values . Error

m e s s a g e s a re no t poss ib le in POH (process o n he lp -

r eques t ) o r POV (process on v a l u e - r e q u e s t ) p rocess ing .

Ins tead , a r u n t i m e e r ro r occurs .

Dialog box Program c o n t i n u e s p rocess ing a f t e r t h e MESSAGF s t a t e -

m e n t

Tab le 9 .6 M e s s a g e Behavior Dur ing PAI

Key Concepts Refresher C h a p t e r 10 9

T y p e D i s p l a y P r o c e s s i n g

S t a t u s l ine P r o g r a m c o n t i n u e s p r o c e s s i n g a f t e r t h e MESSAGE s t a t e -

m e n t

W S t a t u s l ine Like t y p e b u t t h e u s e r c a n c o n f i r m t h e m e s s a g e by

p r e s s i n g f ^ H w i t h o u t h a v i n g t o e n t e r n e w v a l u e s . T h e

s y s t e m t h e n r e s u m e s PAI p r o c e s s i n g d i r ec t l y a f t e r t h e

MESSAGE s t a t e m e n t . W a r n i n g m e s s a g e s a r e n o t p o s s i b l e

in P O H or P O V p r o c e s s i n g . I n s t e a d , a r u n t i m e e r r o r

o c c u r s .

X N o n e Tr igge r s a r u n t i m e e r r o r w i t h s h o r t d u m p

T a b l e 9 . 6 M e s s a g e B e h a v i o r D u r i n g PAI ( con t . )

A u n i q u e context includes al l s i tuat ions w h e r e a selection screen is be ing pro-

cessed. that is, the p r o g r a m is react ing to user input . In A B A P programs, this cor-

responds to the AT SELECT ION-SCREEN processing blocks, except those w i t h the

OUTPUT a d d i t i o n . Th is is s h o w n in Tab le 9 . 7 .

T y p e D i s p l a y P r o c e s s i n g

Dia log b o x P r o g r a m t e r m i n a t e s , a n d c o n t r o l r e t u r n s t o last a r e a

m e n u .

S t a t u s l ine S e l e c t i o n s c r e e n p r o c e s s i n g t e r m i n a t e s , a n d t h e s e l e c t i o n

s c r e e n is r e d i s p l a y e d . T h e s c r e e n f i e ld s s p e c i f i e d t h r o u g h

t h e a d d i t i o n s t o t h e A T S E L E C T I O N - S C R E E N s t a t e m e n t a r e

r e a d y fo r i n p u t . If t h e r e a r e n o a d d i t i o n s t o t h e s t a t e -

m e n t . t h e n all s c r e e n f i e ld s a r e r e a d y f o r i n p u t . T h e u s e r

m u s t e n t e r a n e w v a l u e . T h e s y s t e m t h e n r e s t a r t s t h e

s e l e c t i o n s c r e e n p r o c e s s i n g u s i n g t h e n e w v a l u e s . You

c a n n o t u s e e r r o r m e s s a g e s w i t h t h e ON HE L P - R E Q U E S T , ON

V A L U E REQUEST, a n d ON E X I T a d d i t i o n s . I n s t e a d , a r u n t -

i m e e r r o r o c c u r s .

I Dia log b o x P r o g r a m c o n t i n u e s p r o c e s s i n g a f t e r t h e MESSAGE s t a t e -

m e n t .

s S t a t u s l ine P r o g r a m c o n t i n u e s p r o c e s s i n g a f t e r t h e MESSAGE s t a t e -

m e n t .

T a b l e 9 7 M e s s a g e s D u r i n g a S e l e c t i o n S c r e e n

256 Chapter 9 Basic ABAP Programs and Interface Creation

Type Di sp l ay

W Sta tus line

N o n e

P r o c e s s i n g

Like t y p e E. bu t t h e user can conf i rm t h e m e s s a g e by

press ing [«±J w i t h o u t having to e n t e r n e w values . The

sys t em t h e n r e s u m e s se lec t ion s c r een process ing direct ly

a f t e r t h e MESSAGE s t a t e m e n t . You c a n n o t u s e w a r n i n g s

w i t h t h e ON H E L P R E Q U E S T , ON V A L U E R E Q U E S T , a n d O N

E X I T a d d i t i o n s . Ins tead , a r u n t i m e e r ro r occurs .

Triggers a r u n t i m e e r ro r wi th sho r t d u m p .

Tab le 9.7 M e s s a g e s Dur ing a Select ion Screen (cont . )

A unique context includes all situations w h e r e a list is being processed, that is,

the program is reacting to user interact ion w i t h lists. In ABAP programs, this

includes the fo l lowing processing blocks:

• AT LINE-SELECTION

• AT USER-COMMAND

• AT PFnn

• TOP-OF-PAGE DURING LINE-SELECTION

Table 9 .8 shows the behavior dur ing list processing.

Type Di sp l ay P r o c e s s i n g

Dialog box Program t e r m i n a t e s , a n d con t ro l r e tu rns t o last a r ea m e n u .

S ta tus line Process ing block t e r m i n a t e s . Previous list levels remain dis-

p layed .

Dialog box Program c o n t i n u e s p rocess ing a f t e r t h e MESSAGE s t a t e m e n t .

S ta tus line Program c o n t i n u e s p rocess ing a f t e r t h e MESSAGE s t a t e m e n t ,

w S ta tus line Like t y p e E.

X N o n e Triggers a r u n t i m e e r ro r w i th sho r t d u m p .

Tab le 9 . 8 M e s s a g e s Dur ing List Process ing

Important Terminology Chapter 257

The last u n i q u e context is in func t ion modules a n d me thods . Messages have two d i f fe ren t func t ions in func t ion modu le s and me thods :

• Normal message

• Triggering an except ion

I f y o u use messages in func t ion modu le s and m e t h o d s wi thou t the RAISING addi-t ion in the MESSAGE s ta tement , the message is hand led normal ly according to the context in which it is called wi th in the func t ion modu le o r m e t h o d . In o the r words , if it is no t caught , it behaves as it wou ld f r o m o n e of the o the r contexts d e p e n d i n g on w h e r e the call for the func t ion modu le o r m e t h o d occurs .

If y o u use messages in func t ion modu le s and m e t h o d s wi th t he addi t ion RAISING exc in the MESSAGE s ta tement , the way in which the message is hand led d e p e n d s on w h e t h e r the calling p rogram catches the except ion exc o r not .

• If the calling p rogram does not catch the except ion, the message is displayed and hand led according to the context in which it occurs in the func t ion mod-ule o r m e t h o d f r o m which it was called. This again is as if the e r ro r occurred w h e r e the call to the func t ion m o d u l e o r m e t h o d was made .

• If the calling p rog ram catches the except ion, the message is no t displayed. Instead, the p rocedure is in t e r rup ted in accordance wi th the message type, a n d processing r e tu rns to the calling p rogram. The con ten t s of the message are placed in the sys tem fields SY-MSGID, SY-MDGTY, SY-MSGNO, and SY-MSGV1 th rough SY-MSGV4.

Important Terminology

For the cert if ication, y o u should k n o w that Reposi tory objects are d e v e l o p m e n t objects such as p rograms o r classes in the ABAP W o r k b e n c h . Each Repository object is assigned to a package. A change request conta ins at least o n e task for each deve loper work ing o n the change. A change reques t records and manages all changes m a d e to Reposi tory objects and Customizing sett ings du r ing a devel-o p m e n t projec t . A task is the in fo rmat ion carrier for en te r ing and managing all changes to Reposi tory objects and Customizing sett ings p e r f o r m e d by develop-ers wi th in a d e v e l o p m e n t project . Simply put, d e v e l o p m e n t is assigned to a task that is part of a change reques t .

258 Chapter 9 Basic ABAP Programs and Interface Creation

You should unde r s t and that global declarat ions appear in a sect ion a f t e r the in t roduc tory p rogram s ta tement o f an ABAP program in which the data types, classes, and data objects that are visible in the w h o l e p rogram can be declared.

A modular iza t ion uni t of an ABAP program is s o m e t h i n g that cannot be sepa-rated o r nes ted . Processing blocks are procedures , dialog modules , and event blocks. They conta in s ta tements that a re s t ruc tured using cont ro l s t ruc tures in s t a t emen t blocks. Every non-declara t ive s t a t emen t o f an ABAP program is par t o f a processing block. A p rocedure interface consists o f formal pa ramete r s and states the possible except ions of the p rocedure .

With pass by reference , y o u pass on ly the address o f the actual p a r a m e t e r to the formal pa ramete r . Formal pa ramete rs d o not occupy the i r o w n m e m o r y space. Wi th in the subrou t ine , y o u work only wi th the field f r o m the calling p rog ram. If y o u change the formal parameter , the field con ten t s in the calling p rogram change too.

In pass by value, a local data objec t is created as a copy of the actual pa ramete r , and w h e n the p r o c e d u r e is called, t he value of the actual p a r a m e t e r is passed to it. Changed formal pa ramete r s a re only passed to the actual p a r a m e t e r if t he pro-cedure e n d s w i t h o u t e r rors .

The te rm event can mean e i ther a c o m p o n e n t of a class o r interface declared using (CLASS-)EVENTS o r an event of the ABAP run t ime e n v i r o n m e n t . W e discussed the latter in this chapter . M o r e details of the fo rmer can be found in Chapter 14, ABAP Object -Oriented Programming. Events in classes trigger event handlers , and events of the ABAP run t ime e n v i r o n m e n t trigger event blocks. An event block is a processing block wi thou t a local data area that can be def ined in every ABAP program — except for subrou t ine pools, class pools, and interface pools — and is processed w h e n a specific event o f the ABAP run t ime e n v i r o n m e n t occurs. It be-gins wi th an event keyword and ends wi th the start of the next modular izat ion.

% Practice Questions

The practice ques t ions be low will he lp y o u evaluate y o u r unde r s t and ing of the topic. The ques t ions s h o w n are s imilar in na tu re to those f o u n d o n the certifica-t ion examina t ion . Wherea s n o n e of these ques t ions will be f o u n d on the exam itself, they al low y o u to review y o u r knowledge of the subject . Select the correct answers and then check the comple teness of y o u r answers in the fol lowing solu-

Practice Questions Chapter 259

tion section. Remember that you must select all correct answers and only correct answers to receive credit for the question.

1. ABAP is a programming language that:

• A. Executes on all three levels of the three-tier architecture

• B. Controls the business logic

• C. Processes and formats data

• D. Interacts with the user

• E. Separates program code from language text

2. Which events can exist in all types of programs that actually contain execut-able statements?

• A. LOAD-OF-PROGRAM

• B.INITIALIZATION

• C. START-OF-SELECTION

• D. AT LINE-SELECTION

• E. AT USER-COMMAND

• F. AT PFM

3. Dynpros can be placed in which program types?

• A. Executables

• B. Module pools

• C. Function groups

• D. Class pools

4. A change request is part of a task?

• A. True

• B. False

5. Which statements about ABAP are true?

• A. Each statement must begin with a keyword.

• B. Each statement must end with a period.

• C. ABAP keywords and additions must be in uppercase.

260 Chapter 9 Basic ABAP Programs and Interface Creation

6. A d e v e l o p m e n t o b j e c t can b e a s s igned to o n l y o n e package .

• A. T r u e

• B. False

7. A d e v e l o p m e n t o b j e c t can b e a s s igned to o n l y o n e c h a n g e r e q u e s t .

• A. T r u e

• B. False

8. Each ABAP p r o g r a m :

• A. Is d iv ided in to p roces s ing b locks

• B. Ass igns e v e r y e x e c u t a b l e s t a t e m e n t to a p r o c e s s i n g block regard less o f it

b e i n g in a p roces s ing b lock

• C. O n l y ass igns e x e c u t a b l e s t a t e m e n t s in a p r o c e s s i n g block t o a p r o c e s s i n g block

• D. Uses e v e n t b locks to t r igger e v e n t s in ABAP

• E. Has dec la ra t ive s t a t e m e n t s o u t s i d e o f p roces s ing b locks w h i c h a r e cons id-

e r e d local

• F. has dec l a r a t i ve s t a t e m e n t s i n s ide o f p r o c e s s i n g b locks w h i c h a re cons id -

e r e d local

• G. Can b e t e s t ed f r o m t h e ABAP W o r k b e n c h b y p re s s ing (Ts)

9 . W h i c h m o d u l a r i z a t i o n un i t s can ra ise an e x c e p t i o n ?

• A. Func t ion m o d u l e s

• B. M e t h o d s

• C. S u b r o u t i n e s (FORM rou t ine s )

10 . W h i c h types of p r o g r a m s o r pa r t s o f p r o g r a m s can b e t e s t ed d i rec t ly f r o m t h e ABAP W o r k b e n c h o r ABAP Ed i to r?

• A. REPORT

• B. PROGRAM

• C. F U N C T I O N POOL

• D. F U N C T I O N MOOULE

• E. C L A S S - P O O L

Practice Questions Chapter 261

• F. METHOO

• G. I N T E R F A C E POOL

• H. T Y P E - P O O L

• I . I N C L U D E

11. W h i c h m e t h o d o f pass ing p a r a m e t e r s is p r e f e r r e d f o r its p e r f o r m a n c e ?

• A. Pass by r e f e r e n c e

• B. Pass by va lue

12. W h i c h m o d u l a r i z a t i o n s un i t s a r e g loba l?

• A. F u n c t i o n m o d u l e s

• B. S u b r o u t i n e s (FORM r ou t i ne s )

• C. M e t h o d s w i t h i n a local class in the p r o g r a m

• D. M e t h o d s w i t h i n class poo l s

13 . FORM r o u t i n e s ( s u b r o u t i n e s ) can b e u s e d in w h i c h t y p e o f p r o g r a m :

• A. Execu tab les

• B. M o d u l e poo l s

• C. Func t ion g r o u p s

• D. Class p o o l s

• E. I n t e r f ace poo l s

• F. S u b r o u t i n e poo l s

• G. Type g r o u p s

14. You can u s e t h e logical e x p r e s s i o n I S S U P P L I E D fo r a n y fo rma l p a r a m e t e r

passed to w h i c h m o d u l a r i z a t i o n un i t ?

• A. S u b r o u t i n e (FORM r ou t i ne )

• B. Func t ion m o d u l e

• C. Static m e t h o d

• D. Ins t ance m e t h o d

262 Chapter 9 Basic ABAP Programs and Interface Creation

15. A selection screen can only be de f ined in an executable p rogram.

• A. True

• B. False

16. Subrou t ines provide which types of paramete rs?

• A. Input

• B. O u t p u t

• C. Inpu t /ou tpu t (changing)

• D. Return values

• E. Exceptions

17. Funct ion modules provide which types of pa ramete r s?

• A. Input

• B. O u t p u t

• C. Inpu t /ou tpu t (changing)

• D. Return values

• E. Exceptions

18. M e t h o d s p rov ide which types of pa ramete r s?

• A. Input

• B. O u t p u t

• C. Inpu t /ou tpu t (changing)

• D. Return values

• E. Exceptions

19. It is not possible to test a func t ion m o d u l e if a n o t h e r func t ion modu le of t he same func t ion g r o u p conta ins a syntax er ror .

• A. True

• B. False

Practice Question Answers and Explanations C h a p t e r 9

20 . Each bu t ton o n a D y n p r o (screen) requires the a s s ignment of a func t ion code. This func t ion code:

• A. Is used to de f ine global variables that receive a value w h e n the bu t ton is clicked

• B. Can be used to ident i fy w h e n the bu t ton is clicked by looking for the func-t ion code in the screen 's 0K_C0DE field

• C. Prevent the func t ion code f r o m be assigned to a m e n u i tem

21 . Which message types behave the same regardless of the context in which they are called?

• A. A

• B. E

• C. I

• D. s

• E. W

• F. X

Practice Question Answers and Explanations

1. Correct answers : B, C, D, E

ABAP docs not, however , execute o n the da tabase server . Al though it can be cons ide red to interact wi th the da tabase th rough the da tabase interface, it does not execute on the da tabase level. Nor does it actually execute o n the presen ta t ion server . It interacts wi th the presen ta t ion server normal ly th rough the SAP GUI, bu t the only execut ion occurs on the application serv-ers.

2 . Correct answer : A

The only event c o m m o n to all executable p rograms is LOAD-OF - PROGRAM.

3. Correct answers : A, B, C

Dynpros a re not possible in m e t h o d s o r classes.

4. Correct answer : B

A change request ho lds a task.

264 Chapter 9 Basic ABAP Programs and Interface Creation

5. Correct answer : B

All ABAP s ta t emen t s mus t end wi th a per iod . Whereas it is certainly t rue that ABAP requires the s t a tement to begin wi th a keyword , the re are cases w h e r e the k e y w o r d is opt ional . The most obv ious is the COMPUTE keyword , which w e have never seen coded in a p rogram ( though it certainly helps to k n o w the keyword exists w h e n y o u are t rying to find help on an ar i thmet ic func t ion whi le in the edi tor) . ABAP docs not care if the case of the s t a t emen t s is uppe r , lower , o r mixed .

6. Correct answer : A

A d e v e l o p m e n t object can only be assigned to a single package. It can be reas-s igned to a d i f f e ren t package, but it is only ever assigned to o n e package at a t ime.

7. Correct answer : B

A deve lopmen t object can only be assigned to mul t ip le projects o r change requests . Only o n e project o r change request can be active at a t ime, bu t over t ime, it is c o m m o n for d e v e l o p m e n t objects to be assigned to d i f fe ren t projec ts and change requests , and they are changed .

8. Correct answers : A. B, F

A p rogram is divided in to processing blocks, a n d every executable s t a tement is assigned to a processing block e i ther explicitly o r implicitly. Any s ta tement not explicitly included in a processing block is implicitly included in START OF - SELECTION. Declarative s t a t emen t s inside a modular iza t ion unit are con-s idered local, whe rea s those outs ide the modular iza t ion uni t s a re cons idered global. Event blocks are called w h e n t he ABAP r u n t i m e triggers t h e m . Wherea s almost every ABAP program can be tested s imply by press ing [?8] whi le in the edi tor , o n e type (a m o d u l e pool) cannot be s tar ted f rom the edi-tor o r ABAP W o r k b e n c h d i recdy . M o d u l e pools (dialog programs) mus t start wi th a part icular screen, and the only w a y is to run the t ransact ion code that associates the first screen to process. To be able to test in the ABAP Work-bench , y o u mus t first navigate to the t ransact ion code, which y o u can then execute by pressing [Ts l .

9. Correct answers : All o p t i o n s

It is current ly possible to raise a class-based except ion f r o m all th ree of these modular iza t ion units .

Practice Question Answers and Explanations C h a p t e r 9

10. Cor rec t a n s w e r s : A, D. E, F

Repor t s , f u n c t i o n m o d u l e s , classes, a n d m e t h o d s can all b e e x e c u t e d a n d t e s t ed d i rec t ly . P r o g r a m s ( m o d u l e pools ) can b e ind i rec t ly t e s t ed b y t e s t ing the i r c o r r e s p o n d i n g t r ansac t i on c o d e . Func t ion g r o u p s , i n t e r f a c e pools , t y p e pools , a n d inc ludes c a n n o t b e t e s t ed i n d e p e n d e n t l y .

11 . Cor rec t a n s w e r : A

Pass by r e f e r e n c e is a lways p r e f e r a b l e w h e n p e r f o r m a n c e is an issue,

w h e r e a s pass b y va lue is m o r e su i t ab le f o r s i t ua t i ons w h e r e r o b u s t n e s s a n d

da t a cons i s t ency a r e i m p o r t a n t .

12 . Cor rec t a n s w e r s : A. D

A n y m o d u l a r i z a t i o n tha t can b e r e u s e d is c o n s i d e r e d g loba l . A m e t h o d

d e f i n e d w i t h i n a p r o g r a m c a n n o t b e r e u s e d , n o r s h o u l d a s u b r o u t i n e ( f o r m

rou t ine ) . Both f u n c t i o n m o d u l e s a n d m e t h o d s d e f i n e d in a class poo l a re con-

s i d e r e d g loba l .

13 . Cor rec t a n s w e r s : A, B, C, F

S u b r o u t i n e s c a n n o t b e u s e d in classes. In t e r f ace poo l s a n d t y p e poo l s c a n n o t

h a v e a n y e x e c u t a b l e c o d e .

14 . Cor rec t a n s w e r s : B, C, D

S u b r o u t i n e s d o n o t h a v e o p t i o n a l p a r a m e t e r s , a n d t h e r e f o r e t h e logical

e x p r e s s i o n I S S U P P L I E D c a n n o t b e u s e d .

15 . Cor rec t a n s w e r : B

Selec t ion s c r e e n s can b e d e f i n e d in a n y p r o g r a m tha t a l lows sc reens . Origi-nal ly. o n l y o n e se lec t ion sc reen w a s a l l o w e d in an e x e c u t a b l e p r o g r a m (screen 1000) . bu t w i t h la ter re leases it is n o w poss ib l e to d e f i n e as m a n y as y o u w a n t . This capabi l i ty is w h y it is poss ib l e to p lace se lec t ion s c r e e n s in p r o g r a m s o t h e r t han j u s t e x e c u t a b l e p r o g r a m s .

16. Cor rec t a n s w e r s : C. E

S u b r o u t i n e s t echn ica l ly o n l y p r o v i d e i n p u t / o u t p u t ( chang ing) t y p e s o f

p a r a m e t e r s ( t h r o u g h U S I N G a n d C H A N G I N G ) a n d e x c e p t i o n s .

17 . Cor rec t a n s w e r s : A, B, C, E

F u n c t i o n m o d u l e s p r o v i d e i n p u t ( I M P O R T I N G ) , o u t p u t ( E X P O R T I N G ) , a n d

i n p u t / o u t p u t ( C H A N G I N G ) t y p e s o f p a r a m e t e r s a n d e x c e p t i o n s ( E X C E P T I O N S ) .

266 Chapter 9 Basic ABAP Programs and Interface Creation

18. Correct answers : All o p t i o n s

M e t h o d s p rov ide input (IMPORTING), ou tpu t (EXPORTING), i n p u t / o u t p u t (CHANGING), and re turn value (RETURNING) types of pa ramete r s and excep-t ions (EXCEPTIONS).

19. Correct answer : A

ABAP looks at the w h o l e p rogram dur ing bo th genera t ion and execut ion. A syntax e r ro r in any part will p reven t it f r o m execut ing.

20 . Correct answer : B

The func t ion code of any menu , bu t ton , o r Funct ion key is always placed in to the OK_COOE field associated wi th the screen. It can also be f o u n d in the system variable SY-uCOMM.

21 . Correct answers : A, F

The abor t o r t e rmina te message type a lways causes a p rog ram te rmina t ion , and cont ro l r e tu rns to last area m e n u . The exit message type always tr iggers a run t ime e r ro r wi th shor t d u m p .

Take Away

You will need to unde r s t and h o w t ranspor t s a re organized. R e m e m b e r that a change request is c o m m o n l y called a t ranspor t and conta ins tasks assigned to specific deve lopers . It is also impor t an t to recognize the var ious types o f pro-grams: Executable programs, also k n o w n as repor ts , m o d u l e pools , also k n o w n as dialog programs, func t ion groups , which conta in func t ion modules , and class pools, which conta in me thods , a re the p r imary p rog ram types y o u need to unde r s t and . Wi th in each of these, y o u need to unde r s t and the types of modular -ization and h o w events a re tr iggered.

You also need to be able to dis t inguish which types of screens, w h e n displayed, use t he SAP GUI versus a W e b b rowse r . Classical screens, o r Dynpros . and selec-t ion screens use the SAP GUI. whe rea s W e b D y n p r o and Business Server Pages, for example , use a W e b b rowse r . W e b D y n p r o is discussed in detail in Chapter 20 . User Interfaces (Web Dynpro) . You are expected to be able to ident i fy h o w a classic screen (Dynpro) handles fields and b u t t o n s and their use in func t ion mod-ules. Included wi th this classic screen handl ing are bo th selection screens and modal dialog boxes.

Take Away Chapter 9

You will need to unde r s t and the use of author iza t ion checks and modular iza t ion units . This includes h o w to call t h e m and op t ions for p rovid ing data .

Last is h o w messages work in d i f fe ren t contexts . You will need to unde r s t and w h e r e messages are displayed and the behav ior of the p rog ram fol lowing t he message p roduc t ion .

Refresher

You mus t unde r s t and var ious types of modular iza t ion blocks. Events, subrou-tines, me thods , func t ion modules , and dialog modu le s will all play a par t in the cert if ication examina t ion . You mus t k n o w h o w they a rc def ined , h o w they are called including their in terface o r s ignature , and h o w they behave wi th the pro-duct ion of a dialog message. You mus t have a tho rough under s t and ing of t he techniques of bo th pass by value a n d pass by reference .

Classical screen (Dynpro) handl ing is also essential knowledge . You must under -stand h o w screens are called, w h a t d is t inguishes a screen f r o m a modal dialog box and f r o m a selection screen. You should unde r s t and h o w to de f ine all th ree and in which types o f p rograms they can be p roduced .

Table 9 .9 shows the key concepts o f basic ABAP programs and interfaces cre-at ion.

Key Concept Definition

Modularization units The procedural modularization units of an ABAP program are its processing blocks.

Dynamic program A dynamic program consists of a screen image or layout (Dynpro) and its underlying flow logic.

The main components of a screen are:

• Attributes: such as screen number and next screen

• Layout: the arrangement of texts, fields, and other ele-ments

• Element attributes: definitions of the properties of indi-vidual elements

• Flow logic: calls of the relevant ABAP modules

Table 9.9 Key Concepts Refresher

268 Chapter 9 Basic ABAP Programs and Interface Creation

Key Concept Definition

Authorization check Check to determine whether the current program user has a certain authorization. For each authorization field of an authorization object, a value to be checked is compared with the corresponding entry in the user master record. The corresponding ABAP statement is AUTHORITY CHECK.

Table 9.9 Key Concepts Refresher (cont.)

Tips

As wi th the major i ty o f the subjects covered in the cert if icat ion examina t ion , it is impor t an t to have as much practical exper ience wi th the subject as possible. Unlike the major i ty o f subjects f o u n d in the certification examina t ion , this is an area w h e r e if y o u have been p r o g r a m m i n g in ABAP, y o u will a l ready have suffi-cient exper ience . Wherea s the vast major i ty of the concepts p resen ted in this chap te r should be second nature , it is impor t an t that y o u unde r s t and the behavior d i f fe rences o f interfaces (or s ignatures) and of message p roduc t ion .

Summary

You should n o w be able to create var ious types of ABAP programs . You should also have an unde r s t and ing of the d i f fe ren t types o f encapsula t ion that a p rogram can use a n d the interact ion b e t w e e n a user and the p rogram th rough the use o f screens and messages. These skills will al low y o u to successfully comple te this por t ion of the cert if ication exam.

ABAP Dictionary

Techniques You'll Master:

• Describe the func t ions o f the ABAP Dict ionaiy in the SAP system

• Def ine data types in t he ABAP Dict ionaiy

• Unders tand da tabase objects and the i r use in the ABAP Dict ionaiy

• Def ine and create domains , data e lements , and tables in the ABAP Dict ionaiy

• Explain tables types in the ABAP Dict ionaiy

• Def ine the technical a t t r ibutes of tables in the ABAP Dict ionary

• D e t e r m i n e da tabase views, ma in t enance views, pro jec t views, and he lp v iews in the ABAP Dict ionaiy

• Unders tand search helps and lock objects

270 Chapter 10 ABAP Dictionary

The ABAP Dict ionaiy central ly manages all o f the global data def in i t ion in the SAP sys tem. The ABAP Dict ionary helps y o u de f ine user -def ined data types, that is, data e lements , s t ructures , and table types. You can def ine the s t ruc ture o f da tabase objects such as tables and views and the index for the da tabase objects . An ABAP Dict ionary table de f ined in the ABAP Dict ionary automatical ly creates a da tabase in the under ly ing database . Search helps are an ABAP Dict ionaiy ser-vice used to display a list of possible values for screen fields. Lock objects a re a n o t h e r ABAP Dict ionaiy service, which is used to control the access of the same data, by a p rogram or user, using the logical lock mechan i sm.

In this chap te r we will cover the ABAP Dict ionary in detail . W e will discuss the technical details o f the ABAP Dict ionary doma in , data e lements , s t ruc ture and table types, tables, j o ins , and database tables. W e will also cover var ious types o f ABAP Dict ionaiy views and the i r use in SAP systems. Finally, w e will discuss ABAP Dict ionaiy services such as search help and lock objects , the i r use, and t he s teps to create cus tom search help and lock objects .

Real-World Scenario

Imagine y o u have to deve lop var ious cus tom appl icat ions on y o u r cus-t o m e r project imp lemen ta t ion .

You w o u l d need a cus tom table to s tore the appl icat ion data and w o u l d requi re a n u m b e r of s t ructures to design the screen. You have to design and create t ransparen t tables, data e lements , doma ins , search helps, a n d lock objects . To create t ransparen t tables y o u need to create d o m a i n s and data e lements . You also have to create search helps a n d lock objects f o r y o u r applicat ion that w o u l d be used in the SAP screen design and deve lopmen t .

As a d e v e l o p m e n t lead, y o u need to have a tho rough unde r s t and ing of the ABAP Dict ionary objects and be able to explain ABAP Dict ionary concepts to y o u r d e v e l o p m e n t team.

Objectives of this Portion of the Test

The object ive o f this por t ion of the test is j u d g e y o u r unde r s t and ing of the ABAP Dict ionaiy objects because t he ABAP Dict ionaiy is one o f the key c o m p o n e n t s o f the SAP system and is requi red in a lmost any applicat ion d e v e l o p m e n t . It is expected that y o u have a tho rough unde r s t and ing of ABAP Dict ionaiy objects

Key Concepts Refresher Chapter 10 271

such as domains , data e lements , s t ructures , and type groups . You should be able to d i f fe ren t ia te b e t w e e n the d i f f e ren t types of tables, that is, t r ansparen t tables, pools and clusters, in the SAP sys tem.

The cert if ication exam will test y o u r k n o w l e d g e regarding t he s teps requi red to create tables. You will be expected to descr ibe the fea tures of lock objects , search help, and database views.

Key Concepts Refresher

The ABAP Dict ionary is a key c o m p o n e n t of any applicat ion deve loped in an SAP system. You need to unde r s t and the var ious ABAP Dict ionary objects and their uses in SAP appl icat ion d e v e l o p m e n t . W i t h o u t knowledge of the ABAP Dictio-nary, it wou ld be almost impossible for y o u to deve lop y o u r cus tom appl icat ion.

You need to k n o w the fol lowing about the ABAP Dict ionaiy objects:

• Basic data types and complex data types f o u n d in t he ABAP Dict ionaiy

• ABAP Dict ionaiy objects such as d o m a i n s and data e l emen t s that can be used to create t ransparen t tables

• How to create tables wi th the correct a t t r ibu tes based on y o u applicat ion r equ i r emen t s

• H o w to p e r f o r m the tun ing of t he ABAP Dict ionaiy table to improve perfor-mance w i t h o u t mod i fy ing the applicat ion p rogram

• Database views and ma in tenance views

• The use of lock objects and search helps

O v e r v i e w

The ABAP Dict ionary is the tool used to manage all Dict ionary objects centrally in the SAP sys tem. You create ABAP Dict ionaiy data types such as data e lements , s t ructures , and table types central ly wi th in the ABAP Dict ionaiy tool. Any change to a data type def in i t ion is automatical ly p ropaga ted to all of the system c o m p o n e n t s using the data type. The data types can be used in y o u r cus tom pro-g rams and appl icat ions or o the r Dict ionaiy objects that y o u might create. ABAP Dict ionaiy data types a re also referred to as global data types and are available to all of the Reposi to iy objects wi th in t he system.

286 Chapter 10 ABAP Dictionary

There a re th ree categories of ABAP Dict ionaiy types:

• D a t a e l e m e n t s

This is an e l e m e n t a i y ABAP Dict ionaiy type and can the re fo re be used to descr ibe a single field o r data e l emen t . It descr ibes the type, length, and pos-sibly the n u m b e r of decimal places. You also def ine the field labels, o u t p u t characteristics, and d o c u m e n t a t i o n for the data e l ements .

• S t r u c t u r e s This is a complex data type that consists o f mul t ip le c o m p o n e n t s . St ructures can be used for ABAP Dict ionary table def ini t ions , func t ion m o d u l e parame-ters, object m e t h o d parameters , and for t he design and def in i t ion of ABAP screens . Any changes in the s t ruc ture o r its c o m p o n e n t a re automatical ly p ropaga ted to the repos i to iy objects w h e r e v e r the specific s t ruc ture is be ing used .

• Table t y p e s This is a comple t e descr ip t ion of an internal table. It gives us the l ine type (which co lumns internal table will have), the access type ( w h e t h e r it will be a s tandard , sor ted, o r hashed internal table), and the in format ion abou t the key.

Database objects such as tables, indexes, da tabases views, a n d ma in t enance views are de f ined in the ABAP Dict ionary. An ABAP Dict ionaiy table de f ined in the ABAP Dict ionaiy automatical ly creates a database table in the under ly ing da tabase using the s t ruc ture de f ined in the ABAP Dict ionaiy w h e n the table def-inition is activated. Changes in the def in i t ion of the table, view, o r index are automatical ly m a d e to the under ly ing database . Indexes are de f ined to speed u p da tabase access to the table. An index created in a Dic t ionaiy table also creates an index for the under ly ing database table.

The ABAP Dict ionaiy provides a n u m b e r of services for appl icat ion develop-men t . You can create lock objects in the ABAP Dictionary; the func t ion m o d u l e s to set and release locks are automatical ly genera ted in the system u p o n activation of t he lock object . You use the func t ion modu le s to lock the table o r the table records, if t he user in tends to change a record and does not w a n t a n y o n e to change it at the same t ime. You can also use lock objects to apply the read lock, w h e r e y o u are ju s t reading the data but wan t to ensu re that no one else changes t he data whi le y o u are using it. Similarly, the Dict ionaiy provides y o u wi th t he op t ion to create search helps that can be l inked to the screen fields to help t he user search for applicat ion data in the SAP sys tem. The Dict ionaiy also provides

Key Concepts Refresher Chapter 10 273

y o u wi th services for input checks against the user input . The valid values for the table field a re de f ined via the check table o r the value range for the d o m a i n of the data e l emen t . Refer to Chapter 19, Table Relationships, for m o r e detail on this topic. Figure 10.1 displays the initial screen of the ABAP Dict ionaiy tool, which is used to create the Dict ionaiy objects .

Edit Goto Utiliti€-s(M) Environment

O Q ® a t u • • <s>ca ABAP Dictionary: Initial Screen

<* ». • 0 Cj

Database table View

Datatype • Type Group

Doman Search he<p Lock object

ft* . Display • Change Create

Figure 10.1 ABAP Dictionary Tool

In s u m m a i y . y o u could create o r upda te the def in i t ion of SAP tables; views; data types including data e lements , s t ructures , and table types; domains ; search helps; lock objects; and type g r o u p s wi th the ABAP Dict ionaiy tool. W e will discuss each of these Dic t ionaiy objects and services in detail in the fol lowing sect ions.

Basic and Complex Data Types

Global data types arc de f ined in the ABAP Dict ionary. Data types de f ined in the ABAP Dict ionary can be re fe renced in an ABAP p rog ram wi th the TYPE addi t ion for the co r r e spond ing data objec t def in i t ion . You can also refer to the data types de f ined in the ABAP Dict ionaiy for the pa ramete rs of func t ion modu le s o r the m e t h o d s interface (see also Chapter 6. ABAP Types and Data Objects).

Data types created in the ABAP Dict ionary can be used by m o r e than o n e ABAP Dict ionary objec t such as a table, s t ructure , o r table type, as well as in ABAP pro-grams. screens, func t ion modu le interfaces, and so on . Data types can be main-

288 Chapter 10 ABAP Dictionary

ta ined centrally, and accordingly, all of the p rograms o r the relevant objects using the data type are ad jus ted du r ing r u n t i m e i f y o u m a k e any changes in the data type in the Dict ionaiy. You can e n t e r semant ic in fo rmat ion such as the field labels and documen ta t i on detail for the type in the data type def in i t ion in the ABAP Dict ionaiy.

There a rc three basic data types in the ABAP Dictionary, tha t is, data e lements , s t ruc ture and table types, br ief ly m e n t i o n e d earlier. W e will discuss these types in detail in this sect ion, bu t first, we need to discuss and unde r s t and the concept of a d o m a i n .

D o m a i n s

A d o m a i n is an ABAP Dict ionary object that is used to descr ibe t he technical a t t r ibutes of a data e l emen t . Domains cannot be used as a type for data objects in the p rogram directly. Domains can be assigned to any n u m b e r of data ele-ments . and any changes in the technical a t t r ibutes of the d o m a i n will automat i -cally be appl ied to all of the data e l emen t s in which it is be ing used .

A d o m a i n can be used by several data e l emen t s because t he technical a t t r ibu te o f the data e l emen t can be the same, but they can have d i f fe ren t mean ings . An example for a field wi th the same d o m a i n w o u l d be the data e l emen t s S_FR0M_ CIT and S_T0_C ITY in the table SPFLI. Both o f the data e l emen t s use the d o m a i n S_C ITY because at they are bo th city codes, bu t they have d i f fe ren t mean ings and hence the two data e l ements . Thus, we de f ine the d o m a i n and can use it for mul-tiple data e l emen t def in i t ions instead of assigning a type and length direct ly to the data c l emen t . Figure 10.2 and Figure 10.3 display the use of d o m a i n s for the def in i t ion o f data e lements . Both of the data e l emen t s use the same d o m a i n for the reason expla ined above .

Domains have the fol lowing technical a t t r ibutes:

• Domain fo rmats

• Domain ou tpu t p roper t i es

Wi th the domain format you de f ine the fo rmat for the d o m a i n . The input for the format specification is the data type, the n u m b e r o f characters, which is depen-d e n t upon the data type, and t he n u m b e r of decimal places if the data type is a numer i c data type. You can only use p rede f ined ABAP Dict ionary data types fo r a d o m a i n def in i t ion .

Key Concepts Refresher Chap te r 10 275

D i c t i o n a r y : D i s p l a y D a t a E l e m e n t

* y <8 4»! (T] [ « * « c6 Dxumertaooo &^e<r«<itarY Docunvwcaoco | |

Data Wwnert S_F ROM.C IT

Short Descnpc>on D e p a w e oty

Actr»<e

A A t s i t a w r T m f-irtwr Char«ct«*ii8cs h e w l a b *

&_CITV [>)tyname

Data Type CXAR Chordae- Smog

Leogtn 20 Decimal P » * e s 0

Data Type

Leogn 0 ) Decimal Places 0

Data Type

leogm 0 Decimal Pto:e4 0

Figu re 10.2 Da ta E l e m e n t Def in i t ion D e p a r t u r e City

Dictionary: Display Data Element I y e a - c * Documentattxi Sup<*e<r>e<taryDocuTW*abon

Drtaelemert S_T0_CtTY Acsve

Shcrt Oscnpocn Arrival city

DataTvoe r g r T ^ w n ^ C S T T O | | F . e k H .abei

• orr n S_CITY Cityrvar ne

Data Type CHAR Cnaracter Sswg

20 Deomal Places 0

DacaTyt-e

l e r t f n 0 Deomal Places ~ o l

Data Type

lertfTi 0 Doc «mol Places 0

Figu re 10.3 Da ta E l e m e n t Def in i t ion for Arrival City

The ABAP Dictionary has 24 predefined data types. ABAP Dictionary data types are mapped to the ABAP runtime data types that you can use to define your data objects, such as type I, type C, and so on. Table 10.1 lists the valid ABAP Dictio-nary data types, and Table 10.2 shows the mapping of the ABAP Dictionary data types and the ABAP runtime data types.

290 Chap te r 10 ABAP Dict ionary

D a t a Type D e s c r i p t i o n

ACCP Post ing pe r iod . The leng th is se t t o six p laces for this d a t a t ype . The for -

m a t is YYYYMH. In i npu t a n d o u t p u t , a po in t is inser ted b e t w e e n t h e year

a n d m o n t h , so t h e t e m p l a t e of th is d a t a t y p e h a s t h e f o r m YYYY.MM.

CHAR Charac te r s tr ing. Fields of t y p e CHAR can have a m a x i m u m length of 2 5 5

in t ab les .

CLNT Client f ie lds a lways have t h r e e CHAR p laces .

CUKY Currency key. Fields of th is t y p e a re r e f e r e n c e d by f ie lds of t y p e CURR.

The leng th is se t t o five p laces for th is d a t a t ype .

CURR Currency f ield. Equivalent t o an a m o u n t field D t C . A field of this t y p e

m u s t refer t o a field of t y p e CUKY ( r e f e rence field). The m a x i m u m length

for th is d a t a t y p e is 31 p laces .

DATS Date . The leng th is se t t o 8 places for th is d a t a t ype . The o u t p u t t e m -

p la t e can b e d e f i n e d wi th t h e user prof i le .

DEC C o u n t e r or a m o u n t field wi th dec ima l po in t , sign, a n d c o m m a s s e p a r a t -

ing t h o u s a n d s . A DEC field has a m a x i m u m length of 31 places .

F L T P Float ing po in t n u m b e r . The leng th ( including dec ima l places) is se t t o

1 6 p laces for th is d a t a t ype .

I N T 1 1 - b y t e in teger b e t w e e n 0 a n d 2 5 5 . The leng th is s e t t o t h r e e p laces for

th is d a t a t ype .

I N T 2 2 - b y t e in teger b e t w e e n - 3 2 7 6 7 a n d 3 2 7 6 7 . Fields of th is t y p e shou ld only be used for l eng th fields. These long f ie lds a re pos i t i oned i m m e d i -

a te ly in f ron t of a long field ( type I C H R , LRAW). W i t h I N S E R T o r UPDATE

o n t h e long field, t h e d a t a b a s e in te r face e n t e r s t h e l eng th t h a t was

actual ly used in t h e l eng th f ield. The leng th is s e t t o five p laces for th is

d a t a t ype .

I N T 4 4 - b y t e in teger b e t w e e n - 2 1 4 7 4 8 3 6 4 7 a n d 2 1 4 7 4 8 3 6 4 7 . The leng th is s e t t o 1 0 p laces for th is d a t a t ype .

Tab le 10.1 ABAP Dict ionary P r e d e f i n e d Da ta Types

Key Concepts Refresher Chapter 10 291

D a t a Type D e s c r i p t i o n

LANG Language key. Has its o w n field fo rma t for special func t ions . This da t a

type a lways has length of o n e . The language key is displayed at t h e user

interface with t w o places, bu t is s tored with only o n e place in t h e da ta -

base. The convers ion exit I SOLA conver t s t h e display at t he user inter-

face for t h e d a t a b a s e and vice versa. This convers ion exit is a u t o m a t i -

cally al located t o a d o m a i n wi th d a t a type .ANG a t ac t ivat ion.

LCHR Character string of any length, but it has to be dec lared with a mini-

m u m of 2 5 6 characters . Fields of this type mus t be loca ted at t he end

of t r anspa ren t tab les (in each table t h e r e can be only o n e such field)

and mus t be p r e c e d e d by a length field of type INT2 . If t h e r e is an

INSERT or UPOATE In ABAP programs, this length field mus t b e filled

with t h e length actually requi red . If t h e length field is not filled cor-

rectly, this may lead to a da t a loss in the LCHR field. A field of this type

canno t b e used in t h e WHERE cond i t ion of a SELECT s t a t e m e n t .

LRAW Unin te rp re ted byte string of any length, but it has t o be declared wi th a

min imum length of 2 5 6 . Fields of this type must be located a t t h e e n d

of t r anspa ren t tab les (in each table t h e r e can be only o n e such field)

and mus t be p r e c e d e d by a length field of type INT2 . If t h e r e is an

INSERT or UPOATE in A8AP programs, this length field mus t b e filled

with t h e length actually requi red . If t h e length field is no t filled cor-

rectly. this may lead t o a da t a loss in t h e LRAW field. A field of this type

canno t b e used in t h e WHERE cond i t ion of a SELECT s t a t e m e n t .

NUKC Long charac ter field in which only n u m b e r s can be e n t e r e d . The length

of this field is l imited t o a max imum of 2 5 5 places.

Accuracy of a QUAN field. The length is set to t w o places for this da t a

type .

QUAN Quant i ty . Equivalent t o an a m o u n t field DEC. A field of this t y p e mus t

always refer t o a uni ts field wi th UNIT fo rmat ( re ference field). The max-

imum length for this da t a type is 31 places.

RAW Unin te rp re ted by te string. Fields of type RAW can have only a max imum

length of 2 5 5 in tables . If longer raw fields are requi red in tables, you

should select da t a type RAW.

Table 10.1 ABAP Dictionary Predefined Data Types (cont.)

Chapter 10 ABAP Dict ionary

D a t a Type D e s c r i p t i o n

RAWSTRIMG U n i n t e r p r e t e d b y t e s t r ing of var iab le l eng th . In t h e Dic t ionary a l eng th

can b e spec i f ied for th i s type (at least 2 5 6 charac te rs ) . This d a t a t y p e

can only be used in t y p e s (da ta e l e m e n t s , s t ruc tu res , t ab l e types ) a n d

d o m a i n s . You can s to re binary d a t a of t y p e RAWSTRING in t h e d a t a b a s e .

However , t h e r e a r e res t r ic t ions; for a desc r ip t ion of t h e m , refer to t h e

d o c u m e n t a t i o n of t h e ABAP s t a t e m e n t STRING. In ABAP, this t y p e is

i m p l e m e n t e d as a r e f e r e n c e t o a s t o r a g e a r ea of var iable size. As de fau l t

for t h e o u t p u t l eng th , 1 3 2 cha rac t e r s a re p r o p o s e d . You c a n n o t a t t a c h

sea rch he lps t o c o m p o n e n t s of th i s t ype .

STRING Charac te r s tr ing w i th var iable l eng th . This d a t a t y p e can only b e used in

types (data e l e m e n t s , s t ruc tu res , t ab l e types) a n d d o m a i n s . In t h e Dic-

t iona ry a length can b e spec i f ied for this t y p e (at least 2 5 6 charac te r s ) .

It c an b e used in d a t a b a s e tab les , b u t on ly w i th res t r ic t ions . For a

desc r ip t ion of t h e s e refer to t h e d o c u m e n t a t i o n of t h e ABAP s t a t e m e n t

STRING. In ABAP, this t y p e is i m p l e m e n t e d as a r e f e r e n c e t o a s to rage

a r ea of var iable size. As de fau l t for t h e o u t p u t length , 1 3 2 cha rac t e r s

a re p r o p o s e d . You c a n n o t a t t a c h search he lps t o c o m p o n e n t s of this

t y p e .

SSTRING Shor t cha rac te r s t r ing wi th var iable l eng th . In t h e Dict ionary t h e n u m -

be r of cha rac t e r s can b e spec i f ied for this t y p e (1 -255 ) . This d a t a t y p e

can only be used in t y p e s (da ta e l e m e n t s , s t ruc tu res , t ab l e types ) a n d

d o m a i n s . It can b e used in d a t a b a s e tables ; h o w e v e r , t o d o s o refer t o

t h e d o c u m e n t a t i o n of t h e ABAP s t a t e m e n t STRING. In ABAP. th i s t y p e

is i m p l e m e n t e d as a r e f e r e n c e t o a s t o r a g e a r ea of var iable size. String

f ie lds of this t y p e can be used in indexes a n d in t h e WHERE c o n d i t i o n of

a SELEC' s t a t e m e n t . You c a n n o t use t h e m in t a b l e keys.

T I H S T ime. The l eng th is set t o six p laces for this d a t a t y p e . The f o r m a t is

HHMMSS. The t e m p l a t e for inpu t a n d o u t p u t has t h e fo rm H H . H H . S S .

UNIT Uni t . Fields of th i s t y p e a re r e f e r e n c e d by f ie lds of t y p e QUAN. T h e

l eng th of this d a t a t y p e is se t t o t w o o r t h r e e p laces .

VARC Charac te r field of var iab le l eng th . Crea t ion of n e w f ie lds of this d a t a

t y p e is n o t s u p p o r t e d as of Release 3 .0 . However , exist ing f ie lds w i th

this d a t a t y p e can still be u sed . A field of this t y p e c a n n o t b e u s e d in

t h e WHERE cond i t i on of a SELECT s t a t e m e n t .

Table 10.1 ABAP Dict ionary Predefined Data Types (cont.)

Key Concepts Refresher C h a p t e r 10 279

A B A P D i c t i o n a r y T y p e A B A P T y p e

ACCP N ( 6 )

CHAR n C ( n )

C L N T C ( 3 )

CUKY C ( 5 )

CURR n . a P ( ( n + 1 ) / 2 ) D E C I M A L m

DEC n . » P ( ( n + 1 ) / 2 ) D E C I M A L m

D A T S 0 ( 8 )

F L T P F ( 8 )

I N T 1 X ( l )

I N T 2 X ( 2 )

I N T 4 X ( 4 )

LANG C ( l )

NUMC n N ( n )

PREC X ( 2 )

OUAN n . a P ( ( n + 1 ) / 2 ) D E C I M A L m

RAH n X ( n )

T I M S T ( 6 )

U N I T C ( n )

VARC n C ( n )

LRAW X ( n )

LCHR C ( n )

S T R I N G S T R I N G

R A W S T R I N G X S T R I N G

T a b l e 10.2 M a p p i n g of ABAP D i c t i o n a r y a n d ABAP R u n t i m e D a t a T y p e s

In the domain output properties you specify the maximum field length, which includes the editing characters such as commas and periods for inputting and outputting values. The output length is populated automatically once you enter the data type and the number of characters and decimal places has been speci-

294 Chapter 10 ABAP Dictionary

f led, b u t it can b e o v e r w r i t t e n . T h e o u t p u t f o r m a t h a s an e f fec t o n t h e sc reen a n d

se lec t ion s c r een . T h e spec i f i ca t ion f r o m this a rea is u s e d w h e n t h e da t a e l e m e n t

l inked to th is d o m a i n is u s e d to de sc r i be t h e sc reen f ie ld , b u t t h e o u t p u t charac-

ter is t ic can b e m o d i f i e d in t h e Screen Pa in te r .

You can a lso spec i fy a c o n v e r s i o n r o u t i n e f o r t h e d o m a i n . T h e c o n v e r s i o n r o u t i n e

is u s e d to c o n v e r t t h e c o n t e n t s o f a s c reen f ield f r o m t h e d i sp lay f o r m a t to SAP

in t e rna l f o r m a t f o r da t a s to rage a n d v ice-versa . The c o n v e r s i o n r o u t i n e fo r the

d o m a i n is i den t i f i ed as a f ive -charac te r n a m e , a n d it g e n e r a t e s t w o f u n c t i o n m o d -

ules f o r t h e c o n v e r s i o n r o u t i n e . T h e f o l l o w i n g f u n c t i o n m o d u l e s w o u l d b e gen-

e r a t e d f o r t h e c o n v e r s i o n r o u t i n e XXXXX:

• T h e CONVERSION_EXLT_XXXXX_INPUT c o n v e r t s t h e d i sp lay f o r m a t to t h e SAP

in te rna l f o r m a t .

• T h e CONVERSION_EXIT_XXXXX_OUTPUT c o n v e r t s t h e SAP in t e rna l f o r m a t to the

d i sp lay f o r m a t .

For the n u m e r i c da t a types such as DEC, FLTP, QUAN, a n d CURR t h e c h e c k b o x f o r

t h e +/- s ign is r e a d y f o r i n p u t . If the c h e c k b o x is se lec ted , t h e n t h e first c h a r a c t e r

o f t h e field is r e s e r v e d f o r t h e + / - s ign, a n d t h e o u t p u t l eng th s h o u l d b e inc reased

b y o n e . For t h e c h a r a c t e r da t a t y p e y o u h a v e t h e o p t i o n to se lect t h e l owerca se

c h e c k b o x to a l low t h e s to rage a n d d i sp l ay o f l owerca se cha rac t e r s . If th i s check-

b o x is n o t c h e c k e d , t h e da t a is a lways s t o r e d a n d d i sp l ayed as u p p e r c a s e . F igure

1 0 . 4 d i sp lays t h e technica l a t t r i b u t e s f o r t h e d o m a i n d e f i n i t i o n .

© * C O © D H E Dictionary: Display Domain

y ^ •:- a a

Domain HENC1S_3 Actr.«

Short Description Quantity fleW.leogft 13.3 places alter decimal port

Properties Deflation , Value Range

Format Data Type QUAN Quantity fieti. potts to a unit fieW « t h format UNIT t+D Characters 15 Decimal Places 3

Output Charactensscs Cwput length 19 Cowers Routine

Figure 10.4 Domain Definition

Key Concepts Refresher Chapter 10 295

In a d d i t i o n to the a b o v e a t t r ibu te s , y o u can also d e f i n e the valid va lues f o r t h e d o m a i n . A l t h o u g h t h e t y p e o f the d o m a i n wil l d i c t a t e w h i c h va lues a r e val id , y o u can res t r ic t th is f u r t h e r o n t h e VALUE RANGE tab f o r t h e d o m a i n . T h e d o m a i n can h a v e a s ing le f ixed va lue , va lue ranges , o r a va lue t ab l e (see C h a p t e r 19. Table Re la t ionsh ips , f o r m o r e detai l on th i s topic) . D o m a i n s a re a s s igned to t h e da ta e l e m e n t , a n d the data e l e m e n t is a s s igned to f ie lds o f a table , s t r u c t u r e , o r v i e w . A n y t ab l e o r s t r u c t u r e f ield tha t uses th is da ta e l e m e n t can have t h e valid va lue d e f i n e d f o r t h e d o m a i n . T h e va lue r a n g e d e f i n i t i o n is n o t m a n d a t o i y a n d h e n c e can b e left b lank (see Figure 10 .5) .

P r o p e l s , De««t>on Va teRar^e

Sf>y* Vets

LOW >nil UPtt t f -nt .Short D»xrpc

TOOIM

Figure 10.5 Value Range Definition for Domain

D a t a E l e m e n t s

Data e l e m e n t s p r o v i d e a c o m p l e t e d e s c r i p t i o n o f a field w i t h b o t h s e m a n t i c a n d technica l i n f o r m a t i o n . Data e l e m e n t s can b e u s e d in ABAP p r o g r a m s to d e f i n e da ta ob jec t s b y us ing t h e TYPE a d d i t i o n f o r t h e da ta o b j e c t dec la ra t ion (see Figure 1 0 . 6 f o r t h e da ta e l e m e n t MATNR de f in i t i on ) .

282 Chapter 10 ABAP Dictionary

e o o o a -nn o s Dictionary: Display Domain

T « £» • : A a u CKf»n M I U A C * * S M C * x n W < o ' > > » t f , «<*! <•••* 1 J . J C M C M R F M 0 « m i p o r t

P i c c w l w 0 * M » « > V t f » R « 0 »

F o n u i D«*T |C* FECIUMOOT 0*ON«PLK*L

OWA O-tm, WJ. J IR* »*J —R Vrrvt UNT 15 1

( X W CRWKMMKF

C M N ROJVW 19

Figure 10.6 Data Type Definition for Data Element

You can use data elements to define a data object (i.e., variable) in an ABAP pro-gram. The syntax to define a data object in an ABAP program is as follows:

OATA : wa_matnr TYPE ma tn r .

You also use data elements to define view fields, structure components, or the row type of a table type. To create data elements in the ABAP Dictionaiy, you would have to define the data type for the data element. The data type for the data clement could be an clcmcntaiy data type or a reference data type. For cle-mentaiy data types you have the option to assign a domain or use a predefined ABAP Dictionary data type directly (SAP recommends using a domain where pos-sible). whereas for a reference data type you can assign another data element.

You should maintain the field labels for data elements. The field labels are auto-matically available for display with any screen field that uses the data element, and this applies to selection screens as well. You can also translate field labels into other languages. Figure 10.7 shows the field label maintenance for the data clement.

Dataeiemert HATNR Active SucflOoscnwcfl Vatwal fkrrtx*

Anntaes CWoTyp* , Further CnerocMnttcf FiekJlobel

length Fitfd let* Short 10 Mateo* Mf4um 15 Meienei Lcoj 20 Mai end KMOr.J 1$ MaMtai

1

Figure 10.7 Field Label Description for Data Element

Key Concepts Refresher Chapter 10 283

You can d e f i n e a d d i t i o n a l charac te r i s t i cs f o r t h e da t a e l e m e n t such as s ea rch

he lps , p a r a m e t e r IDs. a n d t h e English d e f a u l t n a m e f o r t h e da ta e l e m e n t . T h e

add i t i ona l charac te r i s t i c can b e m a i n t a i n e d o n t h e FURTHER CHARACTERISTICS t ab

o f t h e da t a e l e m e n t m a i n t e n a n c e sc reen (see F igure 10.8) .

• T h e SEARCH HELP (F4 va lue he lp ) can b e u s e d to p r o v i d e i n p u t h e l p fo r a

s c r e e n field ba sed o n t h e da t a e l e m e n t (see C h a p t e r 19 . Table Re la t ionsh ips ,

f o r m o r e detai l o n th is topic) .

• T h e PARAMETER ID is u s e d to s t o r e (SET) t h e sc reen field va lue in m e m o r y if t h e p a r a m e t e r ID is d e f i n e d fo r t h e sc reen field. Similar ly, t h e p a r a m e t e r ID is u s e d to ge t t h e i n p u t field va lue f r o m m e m o i y b y us ing t h e GET p a r a m e t e r s t a t e m e n t . You can also set the sc reen field a t t r i b u t e in Screen Pa in te r to au to -mat ica l ly r ead t h e va lue f r o m m e m o i y w i t h o u t u s ing t h e GET p a r a m e t e r s tate-m e n t . T h e p a r a m e t e r ID va lue is o n l y avai lable if it has b e e n set in an appl i -ca t ion a n d is avai lable in the m e m o r y . T h e p a r a m e t e r ID h o l d s t h e va lue p e r sess ion a n d p e r u s e r a n d is n o t avai lable o n c e y o u h a v e logged of f .

• T h e DEFAULT COMPONENT NAME is u s e d if th is da ta e l e m e n t is u s e d to d e s c r i b e

fields in a BAPI s t r u c t u r e f o r a BAPI d e f i n i t i o n .

O a c M A T N R ACTR*

SfotOwcneoon Material f4»rt*<

«mt< j !« , Data Type Fi*rwOaracH<*M>« , F ^ W l a t *

Search M»<p Name S HAT1 P t r a m f r s RATNft

ParamWofO HAT

M M C o f W W t fAjmo MATERIAL

6>-C»r»C6Crt»l Opfloo;

Figure 10.8 Additional Characteristic for the Data Element Definition

S t r u c t u r e s

S t ruc tu re s cons is t o f s e q u e n c e s o f c o m p o n e n t s . T h e c o m p o n e n t s o f t h e s t r u c t u r e can b e a s e q u e n c e o f e l e m e n t a r y fields, o t h e r s t ruc tu re s , o r t ab le types . Hence , y o u can d e f i n e a flat, ne s t ed , o r d e e p s t r u c t u r e in t h e ABAP Dic t i ona iy . T h e c o m -

284 Chapter 10 ABAP Dictionary

p o n e n t s o f t h e s t r u c t u r e can h a v e da t a e l e m e n t s a s s igned to t h e m o r d e f i n e d us ing t h e p r e d e f i n e d ABAP D i c t i o n a i y da ta t y p e s d i rec t ly . S t ruc tu re s can a lso b e u s e d in t ab le d e f i n i t i o n s o r t ab le t y p e d e f i n i t i o n s o r f o r s c reen d e s i g n . You can o n l y use flat s t r uc tu r e s ins ide ABAP D i c t i o n a i y tab le d e f i n i t i o n s . Data e l e m e n t s , s t ruc tu re s , a n d tab le t y p e s b e l o n g to t h e s a m e n a m e s p a c e , a n d h e n c e a da t a ele-m e n t , s t r u c t u r e , o r t ab le t y p e c a n n o t h a v e s a m e n a m e e v e n t h o u g h t h e y a r e essent ia l ly d i f f e r e n t t h ings .

T a b l e T y p e s

Tab le t y p e s d e f i n e t h e s t r u c t u r e a n d the technica l a t t r i b u t e s o f an i n t e rna l table .

You can r e f e r to the ABAP Dic t i ona ry tab le t y p e s in an ABAP p r o g r a m to d e f i n e

an i n t e rna l t ab le w i t h t h e fo l l owing s t a t e m e n t (he re f o r t h e m a r a _ t a b tab le t y p e

de f in i t i on ) :

O A T A : i t a b T Y P E m a r a _ t a b .

You d e f i n e t h e l ine type , access m o d e , a n d key f o r t h e tab le t y p e in t h e ABAP

Dic t iona iy .

• L ine t y p e

T h e l ine t y p e d e f i n e s the s t r u c t u r e a n d t h e da t a t y p e o f t h e i n t e rna l table , tha t

is, c o l u m n s .

• A c c e s s m o d e

T h e access m o d e d e f i n e s h o w y o u w a n t to access t h e da ta in t h e in te rna l t ab le .

T h e poss ib l e va lues f o r t h e access m o d e s a re s t a n d a r d table , s o r t e d table ,

h a s h e d table , i n d e x table , a n d n o t spec i f i ed . Refer to C h a p t e r 7, In te rna l Tab le

De f in i t i on a n d Use. f o r m o r e de ta i l s o n in te rna l tab les .

• Key

You can spec i fy t h e key f o r t h e i n t e rna l table . T h e key d e f i n i t i o n is m a n d a t o r y

fo r the h a s h e d table , w h e r e a s f o r t h e s t a n d a r d a n d s o r t e d tab les i t ' s o p t i o n a l .

The c a t e g o i y d e f i n e s w h e t h e r t h e k e y is u n i q u e , n o n - u n i q u e , o r n o t spec i f i ed .

The key c a t e g o i y f o r h a s h e d t ab les m u s t b e u n i q u e .

F igure 10 .9 , F igure 1 0 . 1 0 , a n d F igure 1 0 . 1 1 d i sp lay the s c r e e n s f o r t ab le t y p e

d e f i n i t i o n s .

Key Concepts Refresher Chapter 10 299

Table Type KARA.TAB Active Shwttex MARA Table

Anntues Line Type , kwaizatiooarri Access , Key

• Line Type Q A M t u t

CataType

No o( Characters 0 Oecimai Paces 0

Data Type Length 0 Decimal Ptaces 0

Figure 10.9 Line Type Definition for Table Type

T0bl9 Type NARA.TAB A(0w» Ster t tM MARA Table

Aantwtes , Line Type noawaocn arrt Access I Key

M M Ur» Nirrtoet 0

Access

Figure 10.10 Access M o d e for Table Type Definition

TaweType K A R A _ T A B

Short 60*3 MARATattO

Aaiojtes , Line Type , hoauaoon and Access

Keyoeftnoco • k w

I X a B ' 3 a I Choose c ^ j r c T Key components Name

Active

Key

Keycaiegory

Figure 10.11 Key Definition for Table Type

300 Chapter 10 ABAP Dictionary

Transparent Tables

Tables a re de f ined in the ABAP Dict ionary independen t ly of the under ly ing data-base. You de f ine tables in the ABAP Dictionary, and the da tabase table is created u p o n activation of the table def in i t ion in the SAP sys tem. The database table is created based on the table def in i t ion in the ABAP Dictionary, so the da tabase table has the same n a m e as the ABAP Dict ionary table, and the field n a m e s are also the same (al though not necessarily in the s a m e order) . You can crea te a table f rom the Reposi tory Browser in Transact ion SE80 o r Transact ion SE11.

Following are the requ i red set t ings for a table def in i t ion in the ABAP Dictionary:

• Del ive iy a n d M a i n t e n a n c e You need to specify the delivery class for the table. It can be selected f r o m a d r o p - d o w n box. You also need to specify the DATA BROWSER/TABLE VIEW AMINTENANCE for the table. The valid values can be selected f r o m a drop-d o w n list as well. For the op t ions DISPLAY/MAINTENANCE ALLOWED WITH RESTRICTION a n d D ISPLAY/A/U INTENANCE A L L O W E D y o u h a v e t h e o p t i o n t o

genera te the table ma in t enance dialog. The DISPLAY/MAINTENANCE ALLOWED opt ion also al lows table ma in t enance and display it via Transact ion SM30.

• Table Fields You mus t de f ine w h e t h e r the field n a m e is a key field o r not , field type, field length, decimal places, and shor t text for the table. The field n a m e should be u n i q u e wi th in the table. The field n a m e can be a m a x i m u m of 16 characters long and can conta in letters, digits, and underscores . The key flag for the field def ines w h e t h e r the field belongs to the table key.

The table can have o n e o r m o r e key fields. The key fields should be u n i q u e and ident i fy the record in t he table. The fields o f the table a re e i ther assigned to a data e l emen t o r m a p p e d to a p rede f ined data type. The field length, n u m -be r o f decimal places, and the field text are automatical ly der ived f r o m the data e l e m e n t / d o m a i n if the table field is assigned to a data e l emen t . You have to de f ine the technical a t t r ibutes and shor t text for the table field if y o u use a p rede f ined ABAP Dict ionary data type for the table field def in i t ion . You can also include ABAP Dict ionaiy s t ruc tures for table field def in i t ion , bu t y o u have to de f ine the individual key field o f the table. Figure 10 .12 displays the use of include s t ruc ture to de f ine an ABAP Dict ionary table.

Key Concepts Refresher Chapter 10 301

D i c t i o n a r y : D i s p l a y T a b l e

3 U K 1 T * c m c « S « a r . ^ ] [ Af£«nd S J K t U *

t<*rnf> T«1« IVM A£tV»

Sto<lOM<rptofl Centra l v j x m O j r a

A B I M M , OtfvMy and M a r E r a y h * t * r w a C J T C " m n |

I i 1 , 1 . ? ( Srcl iHM) i n 5 1 / 24J

K « y [ » M i D * i r u fSTiOrtOvrtpOOn UUBT H M P 1 CINT 3 0 C » « t

BATHE CHAR 18 O M M n d N s i f t t r lHCLUOE VU&4 STRO 0 O D a e a O w w o M A P A

* S f A L S S 2 * DATS 8 O C r M t t d O n iMAH £**AH CHAK 12 0 H * r * « P* tcn>*>o Cr««»d to C e j K t •AEPA LAfPA OATS 8 O D t M O l M l O M n p

A t W I CHAR 12 0 N u n * (f P«r*on Who CNH0O4 C * t « . fSTA V^STA CHAR 11 0 M a r M n i n c * S U M d «*rftte iracw>d

5 I A I P S I & L B CHAR I J O M a r e w u n c * aatit -VtHffl L v o n * CHAR » 0 F l « M a * - * Iw D M w « CWrt HART eim. CHAR 4 | O M j k o t f T K *

* * SH CHAR t ] O M u H y M O O * WTKL M U i CHAR 9 0Mmn<0»C>» UStlT B1S1I CHAR 18

s i n s f £ 2SS W i l l J O B t M U i t a r - t o M u * I-S1BE c j c BSl f lE LMIT > 0 Pi*ch*v« CrOtr UW c< M m m *

t>KIHW CHAR 2 2 | OOocumrt nrrt-tt doctrrMrt tyU«o> K I A R p z e i a r CHAR O D o c v n r t (Mfftca Docurtn Uon^yetnert sys*<n| re ivR DZt lvR CHAR 2] O D o c u n t i t w M n tntou O x u r * - « M j n » > y - v < i y m m ) retro o z t i r o CHAR * 0 P»>» lor- •* C Ooexr^n CwrTKa Docurwr t

•4SZH CHAR 6 0 Docuntrt <rur.j» nurt*« (nVoJi Ooomn* <mn*)»n»tt It. A T I EIA7T CHAR 0 P»>) nj-txx or OOCirrwt O x i r w * sya»r\) ?«.AHZ

• • e iAsz MMC 0 UrtM> at W » < i (mTX>j| D c x i m t r t M a r w j t r o t vysum)

Figure 10.12 Table Definition with Include Structure

Attaching a search help to the table field itself is only possible if the table field is assigned to a data e l ement . Otherwise , i f y o u arc using a p rede f ined ABAP Dictionary type, search help def ini t ion for the table field is not possible. Ref-e rence type specification for the CURR and QUAN data type fields is requi red . You must specify the reference table for the CURR and QUAN data type field. A reference table should have the CUKY (currency key) data type field for CURR data type a n d UNIT (unit of measure) data type field for QUAN data type field. A cur rency key is requi red because a price of 100 means no th ing until w e k n o w w h e t h e r it is S100 or £100. Figure 10.13 displays the reference type def in i t ion for a CURR data type field.

• Foreign Key

You de f ine the foreign key relat ionship be tween the tables in the ABAP Dic-t ionary. Using the foreign key y o u can create a value check for the table field. You can def ine the foreign key for the table by selecting the foreign keys icon (ytf; see Figure 10.14). Refer to Chapter 19, Table Relationships, for details on this topic.

C h a p t e r 1 0 ABAP Dict ionary

& O t t a • lomir t nttibutn Da taa tomt rc &PREI

S ta r t D e s c n f « c n ffcc P n c e in Purchasing Documert <»n Documem Currency) Domain VERT11 Warnalfocmi* DaiaTyp* CURR ABAP type P

No OtQvr&ctefS 11 e D d C i m ^ P t o c w 2 D ^ a d t l ^ o a m e NET.PRICE

Reference ftett fc< currencyrfamourt ft e w P d f»"4 EKKO WAERS

PossiWe ercnes C n g m d t h o i r c M h ^ to input ht ip oas t* •

S w c h H e O U a r r o

O c n w » W6RT11

Ch^CkMtM

OatatwK* ao-SK*** r KayftaW

Ertrv 2$ / 244

Figure 10.13 Reference Table and Field Assignment for Net Price Field

Dictionary: Drspby Tabh V <8 A v A l l • tiB

E m i A g "AAA A O *

? SrcftH^) - T » o « r » d j OJtthP+UoflU Ooon'^SftortDtwpMn

• O M OMaton^Um*' ODjC* Divert MARA

1 / 222

<a* t V v x W o C CI—Win emu* <* cttt&mmimi

VK*c r* Vx C**«ocr tt Q + t L«v*

j p a y w a a r C t A ^ t f & M p

irr«« V W > v r o i d O C ^ i •A* >»<MiO«vrw<MWJMWCtywn) v w w | « 9 o i r«. i/r^ f tytttffO

. c#o«utwt Coa/rart Mir*;**** C<v< Irrmft ftr.>» n i r t « d x r * < f M f t i ^ r * * 1 • I 'a?* Ttxrtmr ei W gr*ft fV.itw+1 CHAMf d ( M M Oocur** fc4ir*>rr** vytfiffO

Figure 10.14 Table Field Definition

Key Concepts Refresher Chapter 10 289

T e c h n i c a l S e t t i n g s

You m u s t m a i n t a i n t h e technica l se t t ings w h e n y o u c rea t e an ABAP Dictio-

n a r y table . S o m e of t h e technica l se t t ings a re m a n d a t o r y . T h e t echn ica l set-

t ings a r e u s e d to o p t i m i z e t h e da t a s t o r a g e a n d access f o r t h e table . You n e e d

to d e f i n e t h e da t a class, s ize ca t ego iy , a n d se t t ing r e g a r d i n g b u f f e r i n g .

• T h e da t a class d e f i n e s t h e physica l a r ea o f t h e d a t a b a s e ( tab lespace) in w h i c h t h e tab le s h o u l d b e c r ea t ed . T h e m o s t i m p o r t a n t da ta c lasses d e f i n e d in the ABAP Dic t iona ry a r e A P P L O , f o r m a s t e r da ta tha t is n o t f r e q u e n t l y m o d i f i e d c o m p a r e d to t h e t r ansac t i on da ta . A P P L 1 f o r t r ansac t i on da ta , a n d A P P L 3 fo r t h e o r g a n i z a t i o n da ta . T h e o t h e r t w o da t a classes, USR a n d USR1, a r e p r o v i d e f o r c u s t o m e r s a n d s h o u l d b e u s e d by the c u s t o m e r . A special s t o r a g e a r ea m u s t b e a l loca ted f o r the cus tomer - spec i f i c da t a classes.

• T h e size ca t egory d e f i n e s t h e s ize o f t h e e x t e n t s c r ea t ed f o r t h e table . T h e size ca t egory d e f i n e s t h e e x p e c t e d space fo r t h e d a t a b a s e . You can c h o o s e t h e s ize f o r 0 to 4, a n d each ca t egory is a s s igned a fixed m e m o i y size in t h e d a t a b a s e . W h e n y o u c rea t e a table , initial space is saved f o r it in t h e data-base . If m o r e space is r e q u i r e d la te r as a resu l t o f da t a tha t has b e e n e n t e r e d , t h e s to rage is i nc reased in a c c o r d a n c e w i t h t h e s ize c a t e g o r y se lec ted .

• Buf fe r ing se t t ings d e f i n e h o w t h e tab le s h o u l d b e b u f f e r e d . Table b u f f e r i n g i m p r o v e s t h e p e r f o r m a n c e o f t h e d a t a b a s e access. T h e c o n t e n t s o f t ab le a re b u f f e r e d o n t h e app l i ca t ion s e r v e r a n d can b e accessed f r o m t h e app l i ca t ion s e r v e r i n s t ead o f t h e d a t a b a s e se rve r . T h e b u f f e r e d tab le is i nva l ida ted if t h e e n t r i e s in t h e d a t a b a s e t ab l e c h a n g e .

You can se lect t h e BUFFERING N O T PERMITTED o p t i o n , in case the app l i ca t ion

da t a is b e i n g c h a n g e d t o o f r e q u e n t l y . In th is case t h e m o s t r e c e n t da t a is

ava i lab le f o r t h e app l i ca t ion , a n d it will a lways b e f e t c h e d f r o m t h e data-

base .

You can se lect t h e BUFFERING ACTIVATED o p t i o n if t h e da t a is no t b e i n g c h a n g e d f r e q u e n t l y . You have to spec i fy t h e b u f f e r i n g t y p e i f y o u select t h e b u f f e r i n g ac t iva ted o p t i o n .

Y o u a l s o h a v e t h e o p t i o n t o s p e c i f y BUFFERING PERMITTED B U T N O T ACTI-

VATED . In th is case b u f f e r i n g is a l l o w e d technica l ly b u t has b e e n deact i -

v a t e d b e c a u s e p e r f o r m a n c e b e h a v i o r is n o t k n o w n in t h e c u s t o m e r sy s t em.

• T h e B u f f e r i n g t y p e d e t e r m i n e s w h i c h r e c o r d s a re to b e b u f f e r e d o n t h e

app l i ca t ion se rve r . FULL BUFFERING l oads all o f t h e r e c o r d s o f t h e t ab l e i n to

304 Chapter 10 ABAP Dictionary

t h e b u f f e r even if o n l y o n e r e c o r d o f t h e tab le is accessed . T h e SINGLE-

RECORD BUFFER loads o n l y t h e r e c o r d b e i n g accessed in to the b u f f e r .

GENERIC BUFFERING loads t h e le f t - jus t i f ied gene r i c key r e c o r d in to t h e

b u f f e r .

• You also h a v e t h e o p t i o n to spec i fy w h e t h e r a n y c h a n g e s t o t h e t ab l e en t r i e s s h o u l d b e logged . If LOG DATA CHANGES is s e l ec ted , t h e n a n y c h a n g e s in t h e t ab l e r e c o r d will b e logged in t h e log tab le DBTABPRT, o r it can b e v i e w e d via T ransac t i on SCU3. Swi t ch ing th is m a y s l o w d o w n a n y u p d a t e to t h e tab le b e c a u s e t h e u p d a t e s n e e d to b e logged as we l l .

See F igure 1 0 . 1 5 f o r technica l s e t t ings f o r t h e table .

Ham* HAAA Transparent Table

Short t *4 Genera l M a t e r i a l D a t a

last Change SAP 0 1 / 1 5 / 2 0 0 9 Stilus Actr»» S u e d

Lopcal nor ago paramours Data class APPLO Master <J«a. transparent tat*w Stto category 4 Data records expected 16.000 to « . 0 0 0

BUMnng

8U»enngtft«

No oUwytet t t 0

Figure 10.15 Technical Setting for the ABAP Dictionary Table

• I n d e x

The p r i m a r y i n d e x o f t h e tab le is au toma t i ca l ly c r ea t ed based o n t h e tab le key . An i n d e x can b e c o n s i d e r e d a c o p y o f t h e d a t a b a s e tha t h a s b e e n r e d u c e d to ce r ta in fields. T h e c o p y is a l w a y s in s o r t e d o r d e r a n d p r o v i d e s fas te r access to the da t a r e c o r d in t h e table . T h e i n d e x also c o n t a i n s a p o i n t e r to t h e cor re -s p o n d i n g r e c o r d in t h e actual d a t a b a s e table . You can a lso c rea t e mu l t i p l e sec-o n d a r y i n d e x e s f o r t h e t ab le . A s e c o n d a r y i n d e x m a y b e necessa ry if t h e tab le is f r e q u e n t l y accessed in a w a y tha t d o e s no t t ake a d v a n t a g e o f t h e p r i m a r y i n d e x access. In such a case y o u can c rea t e a s e c o n d a r y i n d e x w i t h t h e fields o t h e r tha t t h e key field o f t h e t ab le .

Key Concepts Refresher Chapter 10 305

You should not crcate too many indexes for the table because it may slow down the database update. Each index has to be readjusted any time the data-base content changes, so creating too many indexes is not recommended. Fig-ure 10.16 displays the multiple secondary index for the table MARA.

I ^ M x e s for Taue MARA

o, a|?|«I -7- -I 3J0; n | S t a r t * * Isutut Urnquo [Last Ctwrood 8y Oato [c

A C4dM«r*r4f r&rrfcof Actr* SAP 0407/2009 EMA tJunto' <t tt«-.v m.<«O 4 Mastor Record Actr* SAP 0*07/3009 L MaMnaiGro* A r t * SAP 0*07/2009 M)1 >*•« SAP 0e/22/200S M K Nc« SAP 0e/22f200S M » NtW SAP 12*27/2005 Ht>U BaM r r« ,»

Man/aarorPartNi /r tor/NLrrterotaMa Actr* CcfltprettoMato-uf Actra ..—--.

SAP SAP

0*07/2009 04(07/2009 n**mnvin

Figure 10.16 Mult iple Secondary Index for t he Table MARA

Tip

You should no t crea te t oo many indexes for t he table because it may slow d o w n the da tabase upda te . For any changes in t he da tabase con ten t , each of t he indexes has to be readjus ted , which may affect t he pe r fo rmance adversely.

Search Helps

Search helps are an ABAP Dictionary service used to display a list of possible val-ues for screen fields. The value selected by the user from the selection list is cop-ied to the screen field. Search helps are one form of value help (F4 help) for the screen fields.

Not all screen fields have input help. Fields that do can be recognized by the Input help key on the right of the screen field. The Input help key appears on the screen as soon as you position the cursor on the screen field. Search helps for a screen field can be started by pressing the IF41 function key or by selecting the input help key on next to the screen field.

Normally, search helps are assigned to a data element, and the search help is available to any field that refers to the data element. The search help can also be attached directly to a field of a table or a structure, and to a check table. The def-inition of the attachment is similar to the foreign key. You can also assign search helps directly to a screen field as one of the field attributes in the Screen Painter, although this is not recommended.

306 Chapter 10 ABAP Dictionary

T h e f o l l o w i n g types o f search h e l p s can b e d e f i n e d a n d a r e c r ea t ed w i t h t h e

ABAP Dic t iona ry tool :

• E l e m e n t a i y sea rch h e l p s

• Col lec t ive sea rch h e l p s

• A p p e n d search h e l p s

E l e m e n t a i y S e a r c h H e l p s

E l e m e n t a r y search he lps a r e basic search helps , a n d d e f i n e t h e search p a t h f o r a field. T h e y m u s t d e f i n e f r o m w h e r e the da t a f o r t h e search h e l p w o u l d b e r ead . This is d e t e r m i n e d by t h e SELECTION M E T H O D i n p u t field.

T h e se lec t ion m e t h o d can b e a t r a n s p a r e n t table , d a t a b a s e v i ew , p r o j e c t i o n v i ew , o r h e l p v i e w . If t h e tab le e n t e r e d f o r t h e se lec t ion m e t h o d has a text table , t h e n t h e text table is au toma t i ca l l y p o p u l a t e d to t h e c o r r e s p o n d i n g field, a n d its fields a re also ava i lab le f o r t h e i n p u t h e l p a n d SEARCH HELP PARAMETER s e lec t ion , so u s e r s can use t h e field va lue d e s c r i p t i o n w h e n sea rch ing . T h e poss ib l e va lues f o r t h e hi t list a rc d e t e r m i n e d a t r u n t i m e b y the d a t a b a s e se lec t ion . If t h e da t a f o r t h e hi t list c o m e s f r o m m o r e t h a n o n e table , t h e n y o u m u s t d e f i n e a d a t a b a s e v i e w f o r t h e tab le a n d e n t e r t h e v i e w f o r t h e SELECTION M E T H O D (see Figure 10 .17) .

Dictionary: Display Search Help * y 13 &> 9 «c- a •

^jemwtarys/chWt. HAT1A Active

SHORT (JfrKnptoco Materiel by o*3 material number

ABnbutet Orinoco

Oata cofcKtico dialog bataeor Selection meOoO M.MAtlA OMogfype Oaiog vath value restriction i TeMtaMe Hockey A

Search help ewt

x l H I S H S Parameter [Search help paramour IMP EXP I P o t SPo$ SOis Data element M j OeCaulvaiO BISHT 1 1 BISHT > 1 HAKTG 2 2 HAKTG (SPRAS 3 3 SPRAS SPR FRATNFT 1 - 4 A MATNR

I1 I 1 1 1 1 1 1 I n l i t : 1 : 1 ! : 1 D ,

Figure 10.17 Elementary Search Help Definition

Key Concepts Refresher Chapter 10 307

You mus t specify search he lp pa ramete r s for a search help . The pa ramete r s are used for the value selection and for the hit list display. The pa ramete r s for the search he lp co r re spond to the fields of the table o r the v iew en te red for the SELECTION M E T H O D .

• The in terface o f the search he lp is de f ined by m e a n s of impor t ing (IMP) and expor t ing (EXP) paramete rs . You must specify the interface for the search help in o r d e r for it to exchange t he data f rom the screen t empla te to t he selec-t ion m e t h o d and f r o m the selection m e t h o d to the screen field. The impor t ing pa ramete r s are requi red to pass the values to t he selection m e t h o d , and the expor t ing pa ramete r s are requ i red to re turn the values to the input screen fields. You select t he IMP flag if the p a r a m e t e r is the impor t ing parameter , and EXP flag if the pa rame te r is an expor t ing pa ramete r . Search help param-eters can be impor t ing as well as expor t ing .

• The dialog for the inpu t he lp is de f i ned wi th the fields LPos, SPos, and SDis. The p a r a m e t e r posi t ion in the hit list is de f ined by LPos, and the pa rame te r posi t ion o n the dialog screen is de f ined by SPos. The pa rame te r is no t dis-played if t he value o f LPos o r SPos is initial o r 0. You set the SDis flag for the pa rame te r if the search help pa rame te r is for the value selection only.

• The dialog type def ines w h e t h e r t he dialog box for value selection is to be dis-p l a y e d o r n o t . Y o u s e l e c t SELECT V A L U E S I M M E D I A T E L Y f o r t h e D IALOG T Y P E i f

y o u do not w a n t a dialog screen for restr ict ing the search value. This op t ion is mean ingfu l if the list conta ins on ly f ew entr ies . You can select the op t ion DIALOG DEPENDING ON NUMBER OF VALUES . The search result in this case will be displayed immedia te ly if the n u m b e r of en t r ies is less than 100; o therwise , a dialog screen will be displayed to restrict the n u m b e r search result. You also h a v e t h e o p t i o n t o s e l e c t COMPLEX D I A L O G W I T H V A L U E R E S T R I C T I O N f o r t h e

DIALOG TYPE. In this case the dialog screen for value restr ict ion will be dis-played for search list display.

Col lec t ive S e a r c h H e l p s

A collective search help combines several e l e m e n t a i y search helps. Collective search helps provide several a l ternat ive search pa ths for possible entr ies . The col-lective search help exchanges data wi th t he screen wi th the EXPORT and IMPORT in terface pa ramete r . Collective search helps can be a t tached to fields, check tables, o r data e l emen t s j u s t like t he e l e m e n t a i y search help. Only one search he lp can be a t tached to a field, table, o r data e lement , bu t several search pa ths

308 Chapter 10 ABAP Dict ionary

are available w i th collective search help. Each elementary search help is repre-

sented to the user by a separate tab page.

To define the collective search help you include all of" the elementary search helps and define the search help parameters for the collective search help and thereafter assign the elementary search help parameter to the collective search help parameters (see Figure 10.18 and Figure 10.19).

Dictionary: Display Search Help y « & • <a <* «"« u u

F igu re 10.18 Col lec t ive Sea rch Help P a r a m e t e r Def in i t ion

Dictionary: Display Search Help V O

Parameter v / j y mant let Search MAT1_A

Colective srch hip MAT1 Rotoroocoparamotor Type Cotectrve search h<Hp poroms Short description Firvj VWonal Nimbor HATNR c KATKR

VERKS c WERKS Asntctes Deftmoon mcWed search he*>s MATSR_6

PLNTY c PLNTY a P & e m m a i g r m t r t PLNNR

PI NAI jC r.

PLNNR PLNAL Search HEC H<J

r * r i j \ Short t-FindM KATKR_HTN

MAT 1 KPN Searcf VKORG n U r i TR£X Cc*ect VTVEC

EANE R?G QUOTE HELP Matetta I/BEV2/ED NAT NUMBER Excise

F igu re 10.19 Col lect ive Sea rch Help P a r a m e t e r A s s i g n m e n t

Key Concepts Refresher Chapter 10 309

Append Search Helps

A p p e n d search helps can be used to enhance collective search helps del ivered by SAP fo r customer-specif ic r equ i r emen t s wi thou t modif ica t ion . You have to de f ine y o u r o w n cus tom e l e m e n t a i y search help and then attach it to the a p p e n d search help . You can a p p e n d a search he lp via the m e n u path GOTO • APPEND S E A R C H H E L P .

Lock Objects

Lock objects are requi red to protect t he consis tency of the data if several users o r p rog rams try to mod i fy o r access the same data at t he s a m e t ime. Wi th in t he SAP system y o u can control the access to the same data using the logical lock mechan i sm. A typical example would be that t w o users a re t iy ing to upda te the material mas te r at s ame t ime and y o u w a n t to ensu re that t he data is consis tent . In the SAP system y o u lock the material mas te r record so that no o the r user can change the data w h i l e y o u are work ing on the data. You release the lock once y o u are d o n e wi th y o u r changes .

You set and release locks by calling func t ion m o d u l e s for lock objects in y o u r p rogram. The lock objects created in the ABAP Dict ionaiy are not the database lock. Instead it 's a logical lock table that the SAP applicat ion uses. To lock records in y o u r appl icat ion y o u have to create a lock objec t ( for example , if y o u are upda t ing a table) o r use an existing SAP lock object . The n a m e of the lock object mus t start wi th EZ o r EY i f y o u are creat ing y o u r o w n . The func t ion modu le s fo r the lock objec t a re automatical ly genera ted w h e n y o u create a n d activate the lock objec t in the ABAP Dictionary.

The t w o func t ion modu le s genera ted du r ing the activation of the lock objec t a re ENQUEUE_<lock_object> and OEQUEUE_<lock_object>. The genera ted func t ion modu le s are automatical ly assigned to a func t ion g roup . You should never change the func t ion m o d u l e o r the func t ion g r o u p ass ignment . The func t ion g r o u p o r the m o d u l e fo r the lock object shou ld never be t r anspor ted on the i r o w n . Instead y o u t ranspor t the lock object , a n d the func t ion modu le s are gener-ated in the target sys tem dur ing the activation o f the lock objects . You call t he ENQUEUE_<lock_object> func t ion modu le to lock the table record o r table. The key of the record y o u w a n t to lock has to be passed to t he func t ion m o d u l e to lock the record . You call t he DEQUEUE_<lock_object> to release the lock o n t he table record. The lock m o d e used to lock the record can also be passed to the func t ion modu le , a l though all lock objects have a defaul t lock m o d e .

296 Chapter 10 ABAP Dictionary

T h e lock o b j e c t s a r e d e f i n e d f o r t h e tab les in w h i c h da t a r e c o r d s s h o u l d b e locked in t h e app l i ca t ion . Lock o b j e c t s can b e d e f i n e d f o r a s ingle t ab le o r f o r a set o f logically r e l a t ed tab les . Here , y o u h a v e to d e f i n e a p r i m a r y tab le a n d a n y n u m b e r o f s e c o n d a r y tab les u s ing f o r e i g n k e y r e l a t i onsh ips . T h e a r g u m e n t o f t h e lock ob jec t cons i s t s o f t h e key fields o f t h e t ab le . T h e lock a r g u m e n t fields b e c o m e s o m e o f t h e i n p u t p a r a m e t e r s f o r t h e lock o b j e c t f u n c t i o n m o d u l e s to lock o r u n l o c k t h e tab le r eco rds . T h e lock a r g u m e n t d e f i n e s t h e key f o r t h e tab le r o w to b e locked . Lock o b j e c t s can also lock a logical ob jec t , w h i c h can cons is t o f a h e a d e r r eco rd a n d t h e re la ted detai l o f t h e h e a d e r r eco rd in t h e s e c o n d a i y t ab le . F igure 1 0 . 2 0 a n d F igure 1 0 . 2 1 s h o w the s c r e e n s fo r the lock ob jec t d e f i n i t i o n . To d e f i n e a lock ob jec t y o u h a v e to d e f i n e t h e lock table , the lock m o d e as dis-p layed in F igure 10 .20 , a n d t h e lock p a r a m e t e r s as d i sp l ayed in F igure 10 .21 .

Dictionary: Display Lock Object V R] o\. A S A

L o c k o u t EHHARHE Active

Short Deicnptioo Lock B « • Unit of Measue (ExcMivo)

Attributes TeWes , Lock parameter

Primary TaM» Name Lock Mode

Lock Mode

Figure 10.20 Table Assignment for the Lock Object

Dictionary: Display Lock Object V <8 * A A a

SwDevcntoc* ENURfC ActrM LOCk BM« U>€ « M M W [E.:irfr*|

lockwrerrww

- IWOT t w t i i HATH* rvf* rAtMi « !NH M i a

Figure 10.21 Lock Parameter Assignment for the Lock Object

HARM

wnte Lock

So-:or>3.r>T9t*tt [Nam*

Key Concepts Refresher Chapter 10 10

The lock m o d e is also an inpu t pa rame te r for the func t ion modu le s o f the lock object , a n d it de f ines h o w o the r users o r appl icat ions can access t he locked record . You can assign separate lock m o d e s for individual tables in the lock object . Table 10.3 displays the lock m o d e s and their meanings .

Type of Lock Lock Mode Meaning

Shared lock/read lock S (shared) More than one application can set a shared lock on the same record. An exclusive lock cannot be set for a record with an existing shared lock.

Exclusive lock/write lock

E (exclusive) Exclusive locks protect the lock object against all types of locks from any appli-cation. Only the application that locked the object can reset the lock. Locked data can be edited or displayed by a sin-gle user.

Exclusive and non-cumulative

x (exclusive non-cumulative)

Exclusive locks can be requested several times within the same application and are processed successfully. In contrast, exclusive but non-cumulative locks can be applied only once within an applica-tion; all other lock requests are rejected.

Table 10.3 Lock Modes for Lock Objects

Locked records can be v iewed via Transact ion SM12. You can also manual ly delete the locked record f r o m this t ransact ion if the SAP dispatcher o r n e t w o r k connec t ion fails and the d i spa tcher is unable to delete the lock en t r ies (see Chap-ter 8, SQL Sta tements Including Update Strategies, for detail regarding the upda te strategies).

View Types and Maintenance

Application data is usually s tored across several database tables. By def in ing a v i ew y o u can p rov ide the m e a n s to access those tables as if they w e r e o n e table. A da tabase v iew is der ived by combin ing (JOIN) t he data f r o m one or m o r e tables and is based o n an inner j o i n . You can use a database v iew in an ABAP program for data retrieval, that is, w h e n y o u use the SELECT s ta t ement . You can mask o n e

298 Chapter 10 ABAP Dictionary

o r m o r e fields f r o m t h e ba se tab le to c r ea t e a v i e w o r i nc lude o n l y s o m e en t r i e s

f r o m t h e d a t a b a s e tab les tha t sa t i s fy ce r t a in c o n d i t i o n s .

Fo l lowing a r e t h e s t eps to d e f i n e a v i ew:

1. Select t h e ba se tab les f o r t h e v i e w .

2 . D e f i n e t h e j o i n c o n d i t i o n s to l ink t h e base tab les o f t h e v i e w .

3. Select t h e fields o f t h e ba se tab le to b e u s e d in t h e v i e w .

4 . You can also d e f i n e a se lec t ion c o n d i t i o n to res t r ic t r eco rd se lec t ion in t h e

v i ew , a l t h o u g h w e d o n o t u s e th is o p t i o n o f t e n .

T h e j o i n c o n d i t i o n s fo r t h e v i e w d e f i n e h o w t h e r e c o r d s o f t h e d i f f e r e n t t ab les

a re re la ted , tha t is, h o w y o u k n o w w h i c h r e c o r d s in o n e tab le c o r r e s p o n d to a

r e c o r d in a n o t h e r table . T h e se lec t ion o f t h e r e c o r d s f r o m t h e v i e w tables is

res t r i c ted b y t h e j o i n c o n d i t i o n .

You can d e f i n e a se lec t ion c o n d i t i o n to filter t h e tab le r e c o r d s f o r t h e v iew. You can d e f i n e severa l se lec t ion c o n d i t i o n s by us ing t h e logical o p e r a t o r s AND a n d 0 . Be a w a r e that th is wil l res t r ic t h o w m a n y app l i ca t ions can u s e t h e v iew. This is s imi la r to t h e WHERE c lause u s e d in t h e SELECT s t a t e m e n t to filter t h e r e c o r d re t r ieval f r o m t h e table .

You pick fields f r o m each o f t h e tab les tha t y o u w a n t to i nc lude in t h e v i e w . T h e set o f fields se lec ted fo r t h e v i e w is t h e cal led t h e p r o j e c t i o n . T h e da ta to b e se lec ted f o r t h e v i e w is d e p e n d e n t o n w h e t h e r t h e v i e w is i m p l e m e n t e d as an innerjoin o r an outerjoin. W i t h t h e i n n e r j o i n y o u get all o f the r e c o r d s fo r w h i c h t h e r e is an e n t r y fo r t h e j o i n c o n d i t i o n in all tab les i n c l u d e d f o r t h e v i e w . W i t h t h e o u t e r j o i n , r e c o r d s a re a lso se lec ted f o r w h i c h t h e r e is n o e n t r y in s o m e o f t h e tab les i nc luded in t h e v iew.

See Figure 1 0 . 2 2 a n d Figure 1 0 . 2 3 f o r i n n e r a n d o u t e r j o i n s , r espec t ive ly . T h e i n n e r j o i n v i e w as s h o w n in F igure 10 .22 , c o n t a i n s all r e c o r d s f r o m tab les TAB1 a n d I A B 2 , w h i c h sa t i s f ies t h e j o i n c o n d i t i o n , t h a t is. T A B 1 - F I E L 0 1 - T A B 2 f 1 E L D 3 . Similarly, t h e o u t e r j o i n v i e w as spec i f i ed in Figure 1 0 . 2 3 c o n t a i n s all o f t h e r e c o r d s f r o m TAB 1 a n d the r e c o r d s f r o m T A B 2 t h a t sa t i s fy t h e j o i n c o n d i t i o n , tha t is, T A B 1 - F I E L 0 1 - T A B 2 - F I E L 0 3 . All r e c o r d s in t h e l e f t - h a n d o r first table wil l b e i nc luded in t h e resul t set . r ega rd less o f w h e t h e r t h e o t h e r tab les h a v e a cor re -s p o n d i n g e n t r y .

Key C o n c e p t s Ref resher C h a p t e r 10 1 0

TAB1 T A B 2

Field 1 Ficld2

490001 2009

490002 2009

49000J 2009

Fldd3 Ficld4 FleW5

490001 10 AVAT1

490001 20 A\AT2

490002 10 AVAT3

490002 20 AVAT3

Fleldl F»eld2 Fleld3 F»eld4 Field5

490001 2009 49001 10 A\AT1

490001 2009 49001 20 A\AT2

490002 2009 49002 10 A\AT3

490002 2009 49002 20 A\AT3

Join C o n d i t i o n : T A B 1 - F I E L D 1 = T A B 2 - F I E L D 3

F igure 10.22 Inner Join V i e w

TAB1 T A 8 2

Field 1 Field2

49001 2009

49002 2009

49003 2009

Field3 Field4 Fields

490001 10 MAT1

490001 20 MAT2

490002 10 MAT 3

490002 20 MAT4

O u t e r Join C o n d i t i o n : T A B 1 - F I E L D 1 = T A B 2 - F I E L D 3

Field 1 Field2 Field3 Field4 Fields

49001 2009 49001 10 MAT1

49001 2009 49001 20 MAT2

49002 2009 49002 10 MAT 3

49002 2009 49002 20 MAT4

49003 2009

F igure 10.23 O u t e r Join V i e w

300 Chapter 10 ABAP Dictionary

Database views imp lemen t an inner j o i n and hence select records for which there are en t r ies in all of the tables included in the view. Help views a n d main-t enance views i m p l e m e n t ou te r jo ins . You cannot select data f r o m the mainte-nance view. If y o u w a n t to use an ou te r j o i n in y o u r applicat ion, y o u have to p rogram it yourse l f .

The ma in tenance status o f the v iew controls w h e t h e r data records in the table can be inser ted o r changed th rough the view. You have the op t ion to specify READ ONLY main tenance status for the view. With this op t ion y o u can only read data f r o m the view. I f y o u select the READ AND CHANGE status, y o u can upda te o r change the table records th rough the view. Database views pe rmi t read-only access.

The fol lowing types of v iew are possible in the ABAP Dictionary:

• D a t a b a s e v i ew

Database views are automatical ly created in the under ly ing da tabase w h e n they are activated. A database v iew should be created if y o u w a n t to access logically connec ted records f r o m d i f fe ren t tables s imul taneous ly . Selection f rom the database v iew is general ly faster than selection f rom the individual tables using a nested select. Database views can only conta in t r ansparen t tables.

• P r o j e c t i o n v i ew Project ion views are used to mask the fields of a table. A pro jec t ion v iew con-tains exactly o n e table, and y o u cannot de f ine t he selection condi t ion for the pro jec t ion view. A pro jec t ion v iew does not create a co r r e spond ing object in the under ly ing database like a da tabase v iew. Data selection f r o m the projec-tion v iew should be fast owing to a smal ler n u m b e r o f fields in the pro jec t ion view. Project ion views can be created for pooled o r cluster tables also because the pro jec t ion v iew is m a p p e d to the co r respond ing database tables of the table included in the view.

• M a i n t e n a n c e v i ew A ma in tenance v iew is i m p l e m e n t e d as an ou t e r j o i n , and all the tables included in the ma in tenance v iew mus t be l inked wi th a foreign key. The j o i n condi t ions of the ma in tenance v iew are always der ived f r o m the foreign keys. You cannot e n t e r the j o i n condi t ion for the ma in t enance v iew manual ly as y o u can for the da tabase view. Ma in t enance views al low an easy way to main-tain complex applicat ion objects .

Important Terminology Chapter 10

M a i n t e n a n c e views, as the i r n a m e suggests, al low y o u to mainta in the data for the applicat ion object together , and the data is automatical ly d is t r ibuted to all of the under ly ing da tabase tables. The ma in t enance status de t e rmines w h e t h e r a change to t he da tabase tables is a l lowed th rough t he ma in t enance view. The ma in tenance v iew is a left ou t e r j o i n , so t he first table included in the j o i n is impor t an t . All of the records of the first table are included in the ma in t enance v iew.

• Help v i ew

Help views can be used as a selection m e t h o d for a search help . Help views are i m p l e m e n t e d as an ou t e r j o in , and all tables included in the help v iew should be connec ted by foreign keys.

General ly, the selection m e t h o d for t he search he lp is a da tabase v i ew or table. However , y o u have to use a he lp v iew as a selection m e t h o d for a search help if a v iew wi th an ou te r j o i n is r equ i red for data select ion.

Important Terminology

You should n o w k n o w abou t var ious ABAP Dict ionary objects and the i r func-t ions. You should also have a g o o d unde r s t and ing of search he lp a n d lock objects .

Search helps are ABAP Dict ionary services used to display a list of possible values (value help) for screen help and are general ly associated wi th the data e lements . They can also be assigned to dialog screen, in wh ich case y o u w o u l d not have to p rog ram value help for the screen field in the screen flow logic. Otherwise , y o u would have to p rogram for value he lp for the screen field, if inpu t he lp for t he field is requi red .

Similarly, lock objects a rc requ i red to pro tec t t he consis tency of the data if sev-eral users o r p rograms try to access and mod i fy the same data at s ame t ime. You can cont ro l the access o f the same data by t w o o r m o r e users by using the logical lock mechan i sm. T w o func t ion modules , ENQUEUE_<lock_object> and DEQUEUE. <lock_object>, are gene ra t ed for each ABAP Dict ionaiy lock object . You call the ENQUEUE_<lock_object> func t ion modu le to lock a table o r a table record a n d DEOUEUE_<lock_object> func t ion m o d u l e to unlock a table o r a table record.

302 Chapter 10 ABAP Dictionary

% Practice Questions

The practice ques t ions be low will he lp y o u evaluate y o u r unde r s t and ing of the topic. The ques t ions s h o w n arc similar in na tu re to those f o u n d on the certifica-t ion examina t ion , bu t whe rea s n o n e of these ques t ions will be f o u n d o n the exam itself, they al low y o u to rev iew y o u r knowledge of the subject . Select the correct answers and then check the comple teness of y o u r answers in the follow-ing solut ion sect ion. R e m e m b e r t h a t y o u mus t select all correct a n s w e r s and only correct answers to receive credi t for the ques t ion .

1. A Transparen t table can include a deep s t ruc ture .

• A. True

• B. False

2. ABAP data types can be used for a d o m a i n def in i t ion .

• A. True

• B. False

3. Which of the fol lowing s t a t emen t s are t rue?

• A. A convers ion rou t ine can be assigned to a domain .

• B. A convers ion rout ine can be assigned to a data e l emen t .

• C. You de f ine t he value range in the data e l emen t .

• D. You can en te r documen ta t i on fo r t he data e l emen t in the ABAP Dictio-nary .

4. F l Help o n the screen field displays the da ta e l e m e n t documen ta t i on .

• A. True

• B. False

5. Which of the fol lowing are t rue s ta tements?

• A. The technical a t t r ibutes of the data e l emen t can be de f ined by a doma in , that is, the data type, t he field length, and the n u m b e r o f decimal places.

• B. You can also select p rede f ined data types to de f ine the data type o f the data c l emen t .

Practice Questions Chapter 10

• C. Reference data types can be used to de f ine the data type of the data ele-m e n t .

• D. Field labels a re de f i ned for the domain .

6 . You can de f ine search helps and p a r a m e t e r IDs for a data e l emen t .

• A. True

• B. False

7 . The l ine type for a table type can conta in a flat, nes ted , o r d e e p s t ruc ture .

• A. True

• B. False

8 . Which of the fol lowing are t rue s ta tements?

• A. Table fields can be assigned to a data e l emen t .

• B. Table fields can be assigned to an ABAP Dict ionary data type directly.

• C. Search helps can be de f ined for a table field that is assigned to a pre-de f ined data type.

• D. A re fe rence table and field a re requi red for fields wi th t he data types QUAN and CURR.

9 . Which of the fol lowing is a t rue s t a tement regarding search helps?

• A. You can use a ma in tenance v iew for the search he lp selection m e t h o d .

• B. You can use a da tabase v iew for the search help selection m e t h o d .

• C. Help views can also be used for the selection m e t h o d for search help .

• D. You can use t r ansparen t tables for the search he lp selection m e t h o d .

10. Which of the fol lowing regarding search helps is a t rue s t a t ement?

• A. The interface for the search help is de f ined by the IMP ( import ) and EXP (export) flag of the search he lp paramete r .

• B. The LPos pa rame te r de f ines the posi t ion of the search help pa rame te r in the search hit list.

• C. The SPos p a r a m e t e r de f ines the posi t ion o f the input field o n the dialog screen.

304 Chapter 10 ABAP Dictionary

• D. The text table for the selection m e t h o d is automatical ly popu la ted if the text table is a t tached to t he da tabase table being used as the selection m e t h o d .

11. Which of the fol lowing are t rue s ta tements?

• A. A da tabase v iew is i m p l e m e n t e d as an inner j o i n .

• B. A ma in tenance v iew is i m p l e m e n t e d as an ou te r j o i n .

• C. A da tabase v i ew is i m p l e m e n t e d as an ou te r j o i n .

• D. A ma in tenance v iew is i m p l e m e n t e d as an inner j o i n .

12. Which of the fol lowing arc t rue s ta tements?

• A. The tables included in the ma in tenance v iew should have foreign key re la t ionships .

• B. The tables included in t he help v iew should have a foreign key relation-ship.

• C. Project ion views can have m o r e than o n e table inc luded for the v i ew def-init ion.

• D. You canno t use a pooled o r cluster table for da tabase view.

13. You can create pro jec t ion views for pooled o r cluster tables.

• A. True

• B. False

Practice Question Answers and Explanations

1. Correct answer : B

Transparen t tables can include flat s t ructures only. A d e e p s t ruc ture is no t a l lowed.

2. Correct answer : B

You can use ABAP Dict ionary data types for d o m a i n def in i t ion . ABAP data types cannot be used fo r the d o m a i n def in i t ion .

Practice Question Answers and Explanations Chapter 10

3. Correct answers : A, D

A convers ion rou t ine can be assigned to the d o m a i n and cannot be assigned to a data e l emen t . The value range is assigned to the d o m a i n du r ing its defi-ni t ion and not to the data e l emen t . However , the data e lement inheri ts the value range if it 's assigned to a d o m a i n wi th a value range def in i t ion . You provide the d o c u m e n t a t i o n for the data e l emen t dur ing the def in i t ion .

4 . Correct answer : A

F;1 he lp displays the data e l emen t documen ta t i on .

5. Correct answers : A, B, C

The technical a t t r ibutes o f the data e l emen t a re de f ined by the d o m a i n if t he d o m a i n is used for the data type def in i t ion for the data e l emen t . The data type for the data e l emen t can be a p rede f ined ABAP Dict ionary type o r d o m a i n o r a re fe rence data type. Field labels a re de f ined for the data e l emen t only and not for d o m a i n .

6 . Correct answer : A

You can de f ine a search he lp and pa rame te r ID for the data c l emen t .

7. Correct answer : A

The l ine type for the ABAP Dict ionaiy table type can be a complex s t ruc ture . It can be a flat, deep , o r nes ted s t ruc ture .

8 . Correct answers : A, B, D

Table fields can be assigned to the data e l emen t o r the p rede f ined type directly. Search helps cannot be de f ined for a table field assigned to the pre-de f ined data types . Search helps can be de f ined for fields assigned to the data e l emen t . The re fe rence table a n d field are requ i red for t he table field assigned to data types QUAN and CURR. The re fe rence type field should be UNIT a n d CUKY.

9 . Correct answers : B, C, D

The selection m e t h o d for the search he lp can be a t ransparen t table, database view, o r he lp view. You cannot have a ma in tenance v iew as a selection m e t h o d for the search help .

10. Correct answers : A, B, C, D

The in terface for the search help is de f ined by the impor t and expor t param-e te r of the search help pa ramete r . LPos def ines the posi t ion of the pa rame te r on t he hit list, whe rea s SPos def ines the posi t ion of the p a r a m e t e r on the

306 Chapter 10 ABAP Dictionary

input screen. The text table is automatical ly assigned to the selection m e t h o d if it is assigned to the selected t ransparen t table of the selection m e t h o d .

11. Correct answers : A, B

A da tabase v iew is i m p l e m e n t e d as an inner j o in , whereas a ma in t enance v iew is i m p l e m e n t e d as an ou t e r j o i n .

12. Correct answers : A. B. D

Tables included in a ma in tenance v iew and help v iew should have a foreign key re la t ionship . You cannot use pooled and cluster tables for the da tabase view. Project ion views can include only o n e table for the v iew def in i t ion and can include pooled o r cluster tables for the view def in i t ion .

13. Correct answer : A

A project ion v iew can include pooled o r cluster tables for v iew def in i t ion .

Take Away

You should n o w under s t and the var ious ABAP Dict ionary objects and services. You should be able to explain the concep t o f domains , data e lements , table types, s t ructures , tables, indexes , and views. You should be able to dis t inguish b e t w e e n d i f fe ren t types of v iew suppor ted by the SAP system and the i r uses.

You mus t also unde r s t and the lock objec t concept and its def in i t ion and the use of search helps. It is impor t an t to k n o w which type o f object can be used for the selection m e t h o d of the search helps. You should also k n o w the d i f fe rence b e t w e e n the e l e m e n t a i y search help and collective search help and the s teps to create the search help .

Lock objects a re impor t an t for any applicat ion deve lopmen t , a n d y o u should be able to create lock objects and use them in y o u r appl icat ion.

Refresher

You must unde r s t and ABAP Dict ionaiy objects and the suppor t ed services, that is, lock objects and search helps. You should be able to de f ine domains , data ele-ments . s t ructures , table types, and t r ansparen t tables. You should k n o w the sup-por ted data types for d o m a i n and data e l emen t def in i t ion and the concept of a value table and value range and its use in the d o m a i n def in i t ions . It is impor t an t

Summary Chapter 10

to unde r s t and which Dict ionary objects can be used in the ABAP program and the i r scopes.

You also mus t unde r s t and the d i f fe rence b e t w e e n ou t e r j o i n and inner j o i n and which type of j o i n is i m p l e m e n t e d in d i f fe rent types of v iew.

Table 10 .4 shows the key concepts of the ABAP Dict ionaiy .

Key Concept Definition

Domain Domains are used to manage technical properties of the data

object centrally and cannot be used in the program directly. A domain can use an ABAP Dictionary data type only for its defi-nition.

Data elements A data element is a complete description of a field. Data ele-ments provide F1 help for the screen field and field label for the screen.

ABAP Dictionary Tables are defined in the ABAP Dictionary independently of

table the underlying database. A physical table definition is created in the database upon activation of the ABAP Dictionary table.

Table 10.4 Key Concepts Refresher

Summary

You should n o w be able to de f ine ABAP Dict ionaiy objects and use t h e m in y o u r p rogram or appl icat ion. You should also k n o w h o w to lock tables o r the table record wi th in an appl icat ion. Lastly, y o u should be able to de f ine e l e m e n t a i y search helps and collective search helps and k n o w h o w to e n h a n c e a s tandard search help . The knowledge of the ABAP Dict ionaiy and its func t ion will easily al low y o u to pass this topic on t he cert if ication examina t ion .

Unicode

Techniques You'll Master:

• Enforce Unicode checks (on a non-Unicode system)

• Explore the d i f fe rence b e t w e e n byte- type and character- type data objects

• De te rmine the f r a gm e n t v iew of s t ruc tures in Unicode

• Under s t and n e w addi t ions to s t a t emen t s

• Learn about n e w relational ope ra to r s

Chapter 11 Unicode

In this chap te r y o u will be p rov ided wi th the knowledge of h o w to m a k e y o u r ABAP programs Unicode compl ian t . Unicode is in tended to be a universal char-acter set suppor t ing eve iy wr i t t en script used on Earth. Unicode a t t empts to con-nect a rune o r glyph (a character ' s visual represen ta t ion) wi th a character — a uni t of phone t i c o r semant ic mean ing . Thus, a single character that has d i f fe ren t appearances has mul t ip le runes; for example , Arabic characters change appear-ance d e p e n d e n t on the posi t ion in a w o r d .

W e will cover h o w to enforce the Unicode checks even in a non-Unicode system. W e will discuss the d i f fe rences in the ma jo r i ty of the s t a t emen t changes regard-ing the Unicode checks. Lastly, w e will explain the Unicode f r agmen t v iew and p rov ide a brief explanat ion of h o w it works .

Each of these topics will be covered separately and will be fo l lowed by the prac-tice exercise and the solu t ion to the exercise.

Real-World Scenario

Your c o m p a n y had put of f swi tching f r o m mul t ip le code pages w h e n it last upgraded f r o m SAP R/3 4.6C to SAP Ne tWeaver 6 .40 . N o w it is forced to do so by SAP (a system with e i ther b lended code pages or m o r e than o n e code page beg inn ing wi th SAP Ne tWeaver 7 .0 is no longer suppor t ed and requi res a convers ion to Unicode) . You have been asked to ident i fy issues of upgrad ing y o u r company ' s SAP system f r o m SAP Ne tWeaver 6 .40 to SAP Ne tWeaver 7 .0 and switching to Unicode (in o the r words , changing all character-based data s tored in the da tabase f rom o n e code page to Unicode) as par t of the upgrade process .

It is y o u r responsibi l i ty to ident i fy wh ich cus tom programs have issues that need correc t ing pr ior to p e r f o r m i n g the upgrade . Once y o u have a list o f p rograms and the i r p roblems, y o u must make changes to correct the issues.

To speed u p t he correct ion process o w i n g to the expected n u m b e r of pro-g rams that may be affected, y o u have also been asked to explain the process and the types of p rogram changes necessaiy to the en t i re d e v e l o p m e n t team so all m e m b e r s can make changes and learn the rules so that n e w d e v e l o p m e n t is also Unicode compl ian t .

Objectives of this Portion of the Test Chapter 11

Objectives of this Portion of the Test

The p u r p o s e of this por t ion of the cert if ication examina t ion is to ver i fy that y o u k n o w h o w to make p rograms Unicode compl ian t bu t also to unde r s t and , f r o m a p r o g r a m m i n g perspect ive, the advantages of having a Unicode-compl iant pro-g ram. This por t ion of the examina t ion will test y o u r knowledge of a n u m b e r of topics. The points y o u will need to unde r s t and f r o m this sect ion include:

• How to enforce Unicode checks pr ior to the actual switch to Unicode

• How to ident i fy p rograms wi th issues that need correct ing, in o the r words , which p rog rams will p r o d u c e e r ro r s as a result o f the str icter e n f o r c e m e n t of syntax checking of a Unicodc sys tem

• Which ABAP s ta tements behave d i f ferent ly as a result o f byte- type versus character- type val idat ions

• How the Unicode f r agmen t v i ew is used fo r ass ignment and condi t ional state-m e n t s

• N e w addi t ions to exist ing s t a t emen t s to d i f fe ren t ia te b e t w e e n byte- type and character- type data

• New relational opera t ions for byte- type objects

The cert if ication examina t ion will give min imal weigh t to this chapter c o m p a r e d to all of the o t h e r topics in the examina t ion . Therefore , this chap te r is a m o n g those w h e r e the percentage of ques t ions related to the topic is smaller than most o the r chapters . W e suspect the reasoning for a minimal we igh t ing is that the causes of e r rors p roduced dur ing code activation related to Unicodc are si tuat ion specific. You mus t solve the issue b e f o r e y o u can p roceed wi th activation. From a practical test des ign, the re a re also only so m a n y ways to ask abou t the differ-ence b e t w e e n a character and a byte , and it is still possible to have a single-byte code page sys tem. Therefore , a l though this in fo rmat ion is impor t an t (and will he lp y o u p r o d u c e m o r e robust p rogramming) , it is not m a n d a t o r y in all env i ron-m e n t s — y e t .

Key Concepts Refresher

If y o u have deve loped on SAP Releases 6 . 2 0 or later, m u c h of this chap te r is p robab ly already k n o w n to y o u . Eventually, the expectat ion is that all SAP imple-men ta t i ons will be runn ing Unicode-compl iant systems.

312 Chapter 11 Unicode

As wi th m a n y n e w abilities, SAP provides t he tools (specifically. Transact ion UCCHECK and the p rogram a t t r ibu te for Unicode e n f o r c e m e n t ) a n d encourages y o u to use t h e m . Early acceptance of the tools and e n f o r c e m e n t o f the compli-ance rules will m a k e t he eventual convers ion run smooth ly because y o u will be able to focus on the data convers ion knowing that the p rog rams ' behav ior is a l ready correct and proper ly tes ted. You need to unde r s t and t he fo l lowing to make y o u r ABAP programs Unicode compl ian t :

• Byte-type da ta objects versus character- type data objects

• The f r agmen t v iew of a s t ruc ture

• File handl ing

• N e w addi t ions to the ABAP language

• H o w to scan p rograms for e r ro r s

Unicode Compliance

Prior to Release 6 .10, SAP suppor t ed d i f fe ren t codes for r epresen t ing characters of d i f fe ren t fonts , f o r example , ASCII, EBCDIC, and single-byte code pages o r double -by te code pages:

• ASCII (American Standard Code for In fo rmat ion Interchange) encodes every character wi th o n e byte . This means that a m a x i m u m of 2 5 6 characters can be r ep resen ted (strictly speaking, s tandard ASCII only encodes o n e character us ing 7 bits and can the re fo re only represen t 128 characters) . The extens ion to 8 bits was in t roduced wi th ISO-8859).

• EBCDIC (Extended Binaiy Coded Decimal In terchange) also encodes each character using o n e byte, and can the re fo re also represen t 2 5 6 characters .

• Double by te code pages requi re b e t w e e n 1 and 2 bytes pe r character . This enables the represen ta t ion of 6 5 , 5 3 6 characters, o f which only 10 .000 to 15 .000 characters a re normal ly used . For example , the code page SJIS is used for Japanese , and BIG5 is used for t radi t ional Chinese fonts .

Using these character sets, all languages can be hand led individually in one ABAP-based SAP sys tem. Difficulties arise if texts f r o m d i f fe ren t incompat ib le character sets are mixed in o n e central system. The diff iculty is d u e to an 8-bit r epresen ta t ion of a by te being in te rp re ted di f ferent ly based o n the code page to s h o w the data. The exchange of data b e t w e e n systems wi th incompat ib le charac-te r sets can also lead to p rob lems .

Key Concepts Refresher Chapter 12 313

The solut ion to this p r o b l e m is the use of a character set that includes all charac-ters at once . Unicode provides this ability. A variety of Unicode character repre-senta t ions a re possible for the Unicode character set, for example , UTF, in which a character can occupy b e t w e e n 1 and 4 bytes .

F rom Release 6 .10 on, the SAP Ne tWeaver Applicat ion Server suppor t s bo th Uni-code and non-Unicode systems. Non-Unicode sys tems are convent iona l ABAP systems, in which one character is usually r ep resen ted by o n e byte . Unicode sys-t ems are ABAP sys tems that a re based on a Unicode character set and that have a co r r e spond ing under ly ing opera t ing sys tem and database. To d e t e r m i n e i f y o u r sys tem is a Unicode system, select SYSTEM • STATUS and look at the SAP DATA in the cen te r o f the dialog box (see Figure 11.1).

lowimn/ k Repositoiy data SAP System data

Transaction SE80 Component version SAP ECC $ 0

Program (screen) SAPIS38E S f l Screen rvurroer 500 Inttauaion number 002021715$

Program (OUt) SWLS38E License e»p«»t>oo 12/ 31 /9999

o w s u s u s y e . y i t H . i o o i j Unicode Syslem Yes

Figure 11.1 SAP Data from the Status Dialog

Before Release 6 .10, m a n y ABAP p r o g r a m m i n g m e t h o d s w e r e based on t he fact that one character co r r e sponded to o n e byte. Before a sys tem is conver ted to Unicode, ABAP programs mus t t he re fo re be modi f i ed at all po in t s w h e r e an explicit or implicit a s sumpt ion is m a d e abou t the internal length of a character .

Unicode Tools

ABAP suppor t s this convers ion using n e w syntax rules and n e w language con-structs, by placing an emphas i s on re ta ining as much of the exist ing source code as possible . To s impl i fy p repara t ion for the convers ion to Unicode, the UNICODF. CHECKS ACTIVE checkbox can be selected in the p rogram at t r ibutes (see the exam-ple in Figure 11.2) s tar t ing f rom Release 6 .10. Program at t r ibutes a re displayed v i a G O T O • A T T R I B U T E S i n t h e A B A P e d i t o r .

Transact ion UCCHECK suppor t s the activation of this check for exist ing pro-grams. If this p r o p e r t y is set, the p rog ram is ident i f ied as a Unicode p rog ram. For a Unicode p rogram, a str icter syntax check is p e r f o r m e d than is for non -Un icode

314 Chapter 11 Unicode

p r o g r a m s . In s o m e cases, s t a t e m e n t s m u s t a l so b e e n h a n c e d b y us ing n e w addi -

t ions . A syntact ica l ly co r r ec t U n i c o d e p r o g r a m wil l n o r m a l l y r u n w i t h t h e s a m e

s e m a n t i c s a n d t h e s a m e resu l t s in U n i c o d e a n d n o n - U n i c o d e sy s t ems . (Excep-

t i ons to th is ru le a r e low-level p r o g r a m s tha t q u e r y a n d eva lua te t h e n u m b e r o f

by tes p e r charac te r . ) P r o g r a m s tha t a r e r e q u i r e d to r u n in b o t h s y s t e m s s h o u l d

t h e r e f o r e a lso b e t e s t ed o n b o t h p l a t f o r m s .

AttiDuteS

Type 1 Eiecutatxe program Ti

SUMS

Application

Authorization Group

Package $THP Tempo

Logical database

Selection screen

• Ediorlotk 0Ft«ed point anthmeic

E Urntode checks ac»ve • Start using vanant

Figure 11.2 Program Attribute for Unicode Checks

In a U n i c o d e sys t em, o n l y U n i c o d e p r o g r a m s can b e e x e c u t e d . Before c o n v e r t i n g to a U n i c o d e s y s t e m , t h e p ro f i l e p a r a m e t e r <3bap /un icode_check s h o u l d b e se t as o n . This p a r a m e t e r is avai lable s ta r t ing w i t h Release 6 . 1 0 . It can b e u s e d to e n f o r c e t h e e n h a n c e d s y n t a x check f o r all o b j e c t s in n o n - U n i c o d e sy s t ems . W h e n y o u set th i s p a r a m e t e r , o n l y U n i c o d e - e n a b l e d o b j e c t s (ob jec t s w i t h t h e U n i c o d e flag) a re execu tab l e . This p a r a m e t e r s h o u l d b e set as o n o n l y if all c u s t o m e r pro-g r a m s have b e e n e n a b l e d acco rd ing to T ransac t i on UCCHECK. N o n - U n i c o d e p ro -g r a m s can o n l y b e e x e c u t e d in n o n - U n i c o d e sy s t ems . All l anguage c o n s t r u c t s tha t have b e e n i n t r o d u c e d f o r U n i c o d e p r o g r a m s can , h o w e v e r , a l so b e u s e d in n o n -U n i c o d e p r o g r a m s .

To run T ransac t i on UCCHECK, y o u e n t e r t h e p r o g r a m s y o u w a n t to check : all o b j e c t s in t h e c u s t o m e r n a m e s p a c e , all o b j e c t s o f t y p e FUGS ( f unc t i on g r o u p w i t h c u s t o m e r inc lude) , a n d a n y SAP p r o g r a m s y o u m o d i f i e d . T h e init ial se lec t ion sc reen is s h o w n in Figure 11 .3 , a n d an e x a m p l e o f a d e t e c t e d p r o b l e m is s h o w n in F igure 11 .4 .

Because ex i s t ing p r o g r a m s tha t w e r e p r o g r a m m e d w i t h o u t e r r o r s m o s t l y fulfi l l

t h e n e w U n i c o d e rules , t h e y r e q u i r e little m o d i f i c a t i o n . Conver se ly , m o s t p ro -

g r a m s that r e q u i r e s ign i f ican t c h a n g e s a re d u e to an e r r o r - p r o n e p r o g r a m m i n g

s tyle . U n i c o d e p r o g r a m s a re p r e f e r a b l e b e c a u s e t h e y a r e m o r e eas i ly m a i n t a i n e d

a n d less p r o n e to e r r o r s . Ju s t as o u t d a t e d a n d d a n g e r o u s l anguage c o n s t r u c t s a r e

Key Concepts Refresher Chapter 11 329

dec la red obso le te a n d a r e n o longer p e r m i t t e d for use in ABAP Objects , t he rules

fo r Un icode p r o g r a m s also o f f e r increased secur i ty w h e n p r o g r a m m i n g . This

appl ies par t icular ly for t he s torage of ex te rna l da ta , in o t h e r w o r d s , in files.

W h e n c rea t ing a n e w p r o g r a m , t he r e c o m m e n d a t i o n is f o r y o u to a lways iden t i fy

t he p r o g r a m as a U n i c o d e p r o g r a m , a n d o lde r p r o g r a m s can be c o n v e r t e d in

stages.

Check a Program Set for Syntax Errors in Unicode Environment Docu lo« ABAP • Unicode UCCHECK Oocumontmc.n

Object S * o c t » i

Ot iectname > «c

0e<ectT«p« 10 < Authoi (l*Dff> to

p»ck»je to C

Org»n»i Srttem » C

0 Cnetk enff prognmj wtit-o 9i« Urwc-S* too I* unchecked

0 Inchrte on* 0t»tc1» « * > 0t»K1 RepoWaty Enfcy (TAOR)

0 Extkjde $" P K U J I I

• Check rrcctUa SAP ob|e<1» alto

ReWKtOO or Progrvr, S * » Prevent Timeout

M w m u m Number or Progr trrt 50

StttKnert* n» t cwwici be anahrteo ( tMxary

• D l t f i n l i n n m s ' i w i o l t « an»S?»iJ stale Jll»

• alto Lot i t c m HWden we i "EEC *

includes to 8eOwpiwed j J j L S V l i r to f c |

ApcacatwvspecAc Checks 0 vtcwMairDtivince

0 ObeoHtt rurxton Mx»jl«» UPt.OAO<DO«WLOAO

Figure 11.3 Selection Screen of Transaction UCCHECK

S A P

<x\ a l v l o o l F V * | ffl-I - l l u l ^ - M A ' - I O ON: a T V i < * > I s ^ ^ e ™ | Resist of Unicode SyntM Check

Q ' RowjErroi Code _ ]Message Q O NSP Z.NEW.REPORT Z.NEW.REPORT 8 3 MESSAGE O H The offset d e c i v a t o n ' S r e>ceedsr* iensff> or riccharacte

O NSP Z.NEW.REPORT Z.NEW.REPORT 8 3 MESSAOEO-H <«?1> of Me i*uctur» Tt*» is not allowed in Unicode piogran

Figure 11.4 Detected Errors of Transaction UCCHECK

O n e of the mos t i m p o r t a n t d i f f e r e n c e s b e t w e e n a U n i c o d e a n d n o n - U n i c o d e pro-

g r a m is the clear d i s t inc t ion b e t w e e n by te - type a n d cha rac te r - type data ob jec t s

316 Chapter 11 Unicode

and the restrict ion of data types w h o s e objects can be v iewed as character type. This has an inf luence o n all s t a t emen t s in which character- type o p e r a n d s a re expected and in par t icular on byte and character s t r ing processing.

In Unicode p rograms , only the e lementa ry data objects s h o w n in Table 11.1 are n o w character type. Structures a re character- type data objects if they conta in only flat character- type c o m p o n e n t s (only c o m p o n e n t s f r o m the Table 11.1 excluding text strings).

Data type Meaning

c Text field

d Date field

n Numerical text

t Time field

s t r i n g Text string

Table 11.1 Character-Type Data Objects

The Unicode f r agmen t v iew splits a s t ruc ture in to f ragments . A f r agmen t is a g roup ing of s t ruc ture c o m p o n e n t s o f the s a m e o r similar data types. In nested s t ructures , the e lementa ry c o m p o n e n t s o n the lowest nest ing d e p t h are taken into account w h e n f o r m i n g f ragments in nested s t ructures . The fol lowing par ts of a s t ruc ture a rc each g r o u p e d to f o rm f ragments :

• Consecut ive flat character-like c o m p o n e n t s of the types c, n, d, and t , be tween which the re are no a l ignment gaps, f o rm character-l ike f ragments .

• Consecut ive flat byte-like c o m p o n e n t s o f the type x, b e t w e e n which the re a re no a l ignment gaps, f o rm byte-like f ragments .

• Consecut ive numer i c c o m p o n e n t s of the types 1 and f , b e t w e e n which the re a re no a l ignment gaps, each fo rm a separate f r agmen t .

• Each individual numer i c type p c o m p o n e n t f o r m s a separa te f r agmen t . For this type of f r agmen t it is the length that is impor tan t , no t the n u m b e r o f dec-imal places.

• In d e e p s t ructures , each d e e p c o m p o n e n t ( reference) f o r m s a separa te frag-men t .

• Each a l ignment gap is regarded as a f r agment .

Key Concepts Refresher Chap te r 12 11

In Unicodc programs, a structure can now essentially only be used at an operand position that expects a single field if the structure is character type. An example of this is shown in Figure 11.5. The statement that produces the error with Uni-code checking shows a simple assignment, but the structure is not considered a character type because it contains a hexadecimal and a numeric field. The state-ment above it references a structure that is considered to be a character type. It is then handled in the same way as a data object of type c without error. In non-Unicode programs, all fiat structures and byte-type data objects are also still han-dled as character-type data objects (implicit casting).

PAT A: BEGIN OF *CrUCl ,

• (2) TYPE C, n (6 ) TYPE n, d TYPE d, C TYPE t ,

END or a c r u c l , BEGIN Or 9 t r u c 2 ,

• <2] TYPE c , b ( 2 ] TYPE c , X ( l ] TYPE X, 1 TYPE 1,

END Or s tcuc2 , l v _ s t r i n f l TYPE s t r i n g .

l v _ s t E i n g - s t r u c t . ( lv_scr ing - s t r u c 2 .

94' 95 96

99 100 101 102 103 104 10S 106 107 100; 109 110 111!

Scope »F0RM unicode2

Syntt» error

Detcri »fcon Row | TVP» O Program Z_NEW_REPORT 110 OCX)

1V_8TRMG" ana "STRUCr are not mutual* convertible in a Unicode

Figu re 11.5 A Non-F la t S t r u c t u r e

N o t e

T h e inco r rec t u s e of a s t r u c t u r e a t o p e r a n d p o s i t i o n s is g r ea t l y r e s t r i c t ed in Uni-

c o d e p r o g r a m s . For e x a m p l e , a s t r u c t u r e t h a t c o n t a i n s a n u m e r i c c o m p o n e n t can

n o l o n g e r b e u s e d a t a n u m e r i c o p e r a n d p o s i t i o n .

In Unicode programs, elementary data objects of types x and xstrlng are byte type. In non-Unicode programs, data objects of this type are generally handled as character type.

318 Chapter 11 Unicode

S o m e da t a types , s u c h as n u m e r i c da t a types , o t h e r t h a n p, a n d t h e d e e p da t a types h a v e specif ic a l i g n m e n t r e q u i r e m e n t s tha t d e p e n d o n t h e h a r d w a r e plat-f o r m . Fields in t h e m e m o i y t h a t h a v e o n e o f t h e s e t y p e s m u s t beg in at a d d r e s s e s tha t can be d iv ided b y 4, 8 . o r 16 . In U n i c o d e sys t ems , in a d d i t i o n to t h e al ign-m e n t r e q u i r e m e n t s f o r n u m e r i c da ta o b j e c t s o f types i a n d f a n d o f all d e e p da ta ob jec t s , da ta ob jec t s o f charac te r - l ike da t a t y p e s m u s t a l so b e loca ted in s t o r a g e a d d r e s s e s tha t can b e d i v i d e d by 2 o r 4, d e p e n d i n g o n t h e U n i c o d e c h a r a c t e r rep-r e s e n t a t i o n . As a c o n s e q u e n c e , in s t r u c t u r e s w i t h c o m p o n e n t s o f d i f f e r e n t da ta types , t h e a l i g n m e n t gaps in U n i c o d e s y s t e m s m a y b e d i f f e r e n t t h a n t h o s e in n o n - U n i c o d e s y s t e m s . A l i g n m e n t gaps can a lso occu r at t h e e n d o f s t r uc tu r e s b e c a u s e t h e overa l l l eng th of t h e s t r u c t u r e is d e t e r m i n e d by t h e c o m p o n e n t w i t h t h e largest a l i g n m e n t r e q u i r e m e n t .

! Caution

In Unicode programs, the storage of byte strings in character-type containers causes problems because the byte order of character-type data objects in Uni-code systems is platform dependent. In non-Unicode systems, this only applies for data objects of numeric data types. The content of the data object is inter-preted incorrectly if a container of this type is stored and then imported into an application server with a different byte sequence.

Off se t a n d leng th a r e spec i f i ed b y a p p e n d i n g r + o f f ] [ ( l e n ) ] to t h e n a m e o f a da ta ob jec t in t h e o p e r a n d pos i t ion , a n d t h e spec i f i ca t ions a r e used to access sub-a reas o f a da ta o b j e c t . This t y p e o f p r o g r a m m i n g is n o l o n g e r c o m p l e t e l y poss ib l e in U n i c o d e s y s t e m s b e c a u s e it is no t poss ib le to d e f i n e w h e t h e r o f f s e t a n d l eng th s h o u l d b e spec i f i ed in cha rac t e r s o r by t e s . Also, r e s t r i c t ions h a v e b e e n in t ro -d u c e d tha t f o r b i d access to m e m o r y a reas o u t s i d e o f flat da ta ob jec t s .

Of f s e t a n d / o r l eng th spec i f i ca t ions a re p e r m i t t e d f o r cha rac t e r - t ype a n d byte-t y p e da ta ob jec t s . T h e spec i f i ca t ion o f o f f se t a n d leng th is i n t e r p r e t e d as e i t h e r a n u m b e r o f cha rac t e r s o r as a n u m b e r o f by tes . T h e ru les tha t d e t e r m i n e w h i c h da t a o b j e c t s in U n i c o d e p r o g r a m s c o u n t as c h a r a c t e r - t y p e o r by t e - type o b j e c t s d o no t a l low f o r o f f s e t a n d leng th spec i f i ca t ions f o r da ta o b j e c t s o f n u m e r i c da ta types .

Key C o n c e p t s Ref resher C h a p t e r 12 319

N o t e

The method of using data objects of type c as containers for storing structures of different types, which often are not known until runtime, where components are accessed using offset and length is no longer possible in Unicode programs. Instead of these containers, the statement CREATE DATA can be used to generate data objects of any structure. To access existing containers, these can be assigned to a field symbol using the C A S T I N G addition of the A S S I G N statement.

In Unicode, an offset and/or length specification for a structure is only permitted i f the structure is:

• A character type (it only contains flat character-type components)

• Flat (it has a character-type initial fragment according to the Unicode frag-ment view, and the offset and/or length specification accesses this initial frag-ment)

In both cases the specification of offset and/or length is interpreted as a number of characters. Figure 11.6 shows a structure with both character-type and non-character-type components. The Unicode fragment view splits the structure into five areas as shown in Figure 11.7.

67

71

7*

DATA: BEGIN OF struc, a TYPE c LENGTH b TYPE n LENGTH C TYPE d, d TYPE C, e TYPE f, f TYPE C LENGTH <3 TYPE X LENGTH

END or acruc.

"Lertffth 3 characters "Length 4 characters "Leapth 3 characters "Leapth 6 characters "Lenffth 9 bytes "Lenffth29 characters "Leapth 2 bytes

airuc s i t u c acruc

1) • 'a* (11) " '

? 13

Syntax error

Oescripkon Row Type Program Z_NEW_REPORT The offset declaration "57" exceeds the length of the character-type start (=21) of the snuclure This is not atowed in Unkode programs

80 CCO

Figure 11.6 Invalid Offset in Unicode

320 Chapter 11 Unicode

|( a a a | b b b b I c c c c c c c c I ddd I AAA I e e e e I f f f t t f f f f f f f f | gg ] | [ Tl | F2 | F3 | F4 I TS ]|

Figure 11.7 Fragment View of a Structure

Of f se t a n d / o r l eng th access is o n l y poss ib l e f o r t h e c h a r a c t e r - t y p e init ial f r a g m e n t F l . Spec i f ica t ions such as s t r u c ( 2 1 ) o r s t r u c + 7 ( l 4 ) a r e a c c e p t e d a n d a re h a n -d l e d as a s ingle f ield o f t y p e c. An access s u c h as s t r u c + 5 7 ( 2 ) , h o w e v e r , as s h o w n in Figure 1 1 . 6 p r o d u c e s an e r r o r in a U n i c o d e p r o g r a m .

In U n i c o d e p r o g r a m s f o r actual p a r a m e t e r s spec i f i ed in a PERFORM s t a t e m e n t , it is n o t poss ib l e to spec i fy a m e m o i y area o u t s i d e o f t h e actual p a r a m e t e r u s ing o f f s e t a n d / o r l eng th spec i f i ca t ions . It is n o l o n g e r poss ib l e to spec i fy a n o f f s e t w i t h o u t a l eng th b e c a u s e th is w o u l d impl ic i t ly se t t h e l eng th o f t h e actual p a r a m -e t e r .

+ Tip

Previously, cross-field offset and/or length accesses could be usefully imple-mented in the A S S I G N s tatement for processing repeating groups in structures. To enable this in a Unicode program, the A S S I G N s tatement has been enhanced with the additions RANGE and I N C R E M E N T .

T h e m o s t i m p o r t a n t d i f f e r e n c e s b e t w e e n t h e b e h a v i o r of a U n i c o d e p r o g r a m a n d

a n o n - U n i c o d e p r o g r a m a r e t h e c h a n g e d c o n v e r s i o n ru les f o r s t r u c t u r e s , f o r

a s s i g n m e n t s , a n d f o r c o m p a r i s o n s .

Note

Two structures in Unicode programs are only compatible when all alignment gaps are identical on all platforms. This applies in particular for alignment gaps that are created by included structures.

In n o n - U n i c o d e p r o g r a m s , i n c o m p a t i b l e flat s t r u c t u r e s a r e t r ea ted as da ta o b j e c t s o f t h e t y p e c, bu t in U n i c o d e p r o g r a m s , c o n v e r s i o n ru les a p p l y that assign the U n i c o d e f r a g m e n t v i e w of t h e s t ruc tu r e s . In n o n - U n i c o d e p r o g r a m s , f lat s t ruc-t u r e s a r e t r ea ted as da ta o b j e c t s o f t h e t y p e c f o r a n a s s i g n m e n t to o r f r o m an e l e m e n t a r y da t a ob jec t . H o w e v e r , again in U n i c o d e p r o g r a m s , a c o n v e r s i o n ru le app l i e s a cco rd ing to w h i c h t h e s t r u c t u r e m u s t b e c h a r a c t e r t y p e e i t h e r c o m -ple te ly o r a t least f o r the initial f r a g m e n t .

Key Concepts Refresher Chapter 12 321

As wi th the ass ignment , compar i son of s t ruc tures is no t t reated as c fields, bu t according to the i r Unicode f r agmen t v iew (see Figure 11.5 for an example) . The same is t rue w h e n compar ing a s t ruc ture to an e l emen ta ry data object . The sys-tem again checks w h e t h e r the s t ruc ture is character type e i ther comple te ly o r at least for the initial f r agmen t .

Since Release 3.0, the ABAP Dict ionary s t ruc tures and database tables that are del ivered by SAP can be e n h a n c e d wi th cus tomer includes o r a p p e n d s t ructures . Such changes cause p rob lems in Unicode p rog rams if the e n h a n c e m e n t changes the Unicode f r agmen t view. Therefore , the op t ion to classify s t ruc tures and data-base tables was in t roduced in Release 6 .20 . which makes it possible to recognize and hand le p r o b l e m s related to s t ruc ture e n h a n c e m e n t s . This classification is used du r ing the p rogram check to create a w a r n i n g at all po in t s w h e r e it w o r k s wi th s t ructures , and w h e r e later s t ruc ture e n h a n c e m e n t s can cause syntax er rors o r changes in p rogram behavior . W h e n y o u de f ine a s t ruc ture o r a database table in the ABAP Dictionary, y o u can specify the e n h a n c e m e n t categories.

The dialog s h o w n in Figure 11.8 is f o u n d in t he m e n u EXTRAS • ENHANCEMENT CATEGORY... w h e n edi t ing a table, view, o r s t ructure . The mean ings o f the differ-ent set t ings a re s h o w n in Table 11.2.

| 3 - Maintain Enhancement Categoiy for ZTEST_TABL£

Enhancement Category for Structure

O C a n Bo Enhanced (Doep)

® Can be enhanced (charac:ef-t>t>e or numeric)

O C a n be enhanced (chvacMr type)

O Cannot Be Enhanced

O Not classified

Copy | B 1 ( x 1

Figure 11.8 Assigning an Enhancement Category

Level Category Meaning

Not classified The structure does not have an enhance-ment category.

Cannot be enhanced The structure cannot be enhanced.

Table 11.2 Enhancement Category Meanings

322 Chapter 11 Unicode

Level Ca t ego ry M e a n i n g

Can be enhanced and character- type All s t ructure c o m p o n e n t s and their

e n h a n c e m e n t s have to b e charac ter - type and flat.

Can be enhanced and character- type or All s t ructure c o m p o n e n t s and their

numeric e n h a n c e m e n t s have to be flat.

Any e n h a n c e m e n t s All s t ructure c o m p o n e n t s and their e n h a n c e m e n t s can have any da t a type; for example, you could include a table

type c o m p o n e n t .

Table 11.2 Enhancement Category Mean ings (cont.)

In Unicode programs, byte and character string processing are strictly separated. The operands of byte string processing must be byte-type data objects, and oper-ands in character string processing must be character-type data objects. In non-Unicode programs, byte strings are normally handled in the same way as charac-ter strings.

In Unicode programs, statements that can be used for byte and character string processing require that a distinction be made within the statement by the optional addition IN 8YTE MODE or IN CHARACTER MODE. In this case IN CHARACTER

MODE is the default. The same additions are also used in the statements for deter-mining length and offset (although in these statements the specifications are mandatory): DESCRIBE F I E L D . . . LENGTH and DESCRI8E DISTANCE. An example o f both modes is shown in Listing 11.1.

DATA: 1 v _ t e x t TYPE C LENGTH 1 . l v _ h e x TYPE x LENGTH 1 . 1 v _ b l e n TYPE 1 . 1 v _ c l e n TYPE i . l v _ b y t e s TYPE i .

DESCRIBE FIELD l v _ t e x t :

l v _ b y t e s - l v _ b l e n / l v

Listing 11.1 Calculating Bytes per Character

LENGTH l v _ b l e n IN BYTE MODE. LENGTH 1 v _ c l e n IN CHARACTER MODE, . c l e n .

Key Concepts Refresher Chapter 12 323

There a re relational ope ra to r s for byte s tr ings and for character str ings. In Uni-code p rograms , the latter ( for example . CO. CA, CS) can no longer be used for by te str ings. For by te strings, the re a re n e w relational ope ra to r s (for example . BYTE-CO. BYTE-CA, BYTE-CS). So y o u w o u l d use

IF l v . h e x l BYTE-CO lv_hex2

instead of

IF l v . h e x l CO lv_hex2 .

Likewise, the descr ip t ion func t ions a re divided into descr ipt ion func t ions for byte strings and descr ip t ion func t ion for character s t r ings. In particular, in a Uni-code p rogram, STRiEN can n o w only be used for character- type a rgument s , w h e r e a s XSTRLEN is available for byte- type a rgumen t s . So y o u would d o

1v_clen - STRLEN( l v _ t e x t >

for a character field and

1v_blen - XSTRlEN( lv_hex >

for a by te string.

W h e n s t ructured data objects are used in O p e n SQL s ta tements , in a non-Uni-code p rogram, their s t ruc ture is no t taken in to account; only the length and the a l ignment are checked . In a Unicodc p rogram, for s t ruc tu red work areas, the Unicode f r agmen t v i ew mus t be correct , and e l e m e n t a i y work areas mus t be character type.

Because the con ten t of files f r equen t ly reflects the s t ruc ture of data in the work-ing m e m o r y , the file in terface in a Unicode p rogram must fulfill the fol lowing r equ i r emen t s :

• It mus t be possible to exchange data b e t w e e n Unicode and non-Unicode sys-tems.

• It mus t be possible to exchange data b e t w e e n d i f fe ren t Unicode systems.

• It mus t be possible to exchange data b e t w e e n d i f ferent non-Unicode sys tems that use d i f fe ren t code pages.

Therefore , in Unicode programs, y o u must a lways def ine the code page used to encode the character- type data that is wr i t t en in text files o r that is read f r o m text files.

324 Chapter 11 Unicode

You mus t also cons ider that a Unicode p rog ram mus t be executable in a non-Uni-code sys tem as well as a Unicode system. Some of the syntax rules for the file interface have the re fo re been modi f i ed so that p rog ramming data access in Uni-code p rograms is less p rone to e r ro r s than in non-Unicode p rograms .

Before every read o r wr i te access, a file mus t be o p e n e d explicitly using OPEN DATASET. If a file is a lready open , it c anno t be o p e n e d again. In a non-Unicode p rogram, the first l ime a file is accessed it is implicitly o p e n e d using the s tandard sett ings. The s t a t emen t for open ing a file can be appl ied to an o p e n file in non-Unicode programs, a l though a file can only be o p e n e d once wi th in a p rogram. W h e n open ing the file, the access type and the type o f file s torage mus t be spec-ified explicitly using t he add i t ions INPUT | OUTPUT |APPENDING|UPDATE and [LEG ACY] BINARY | TEXT MOOE.

W h e n open ing a file in TEXT MODE, the ENCODING addi t ion mus t be used to specify the character represen ta t ion . W h e n open ing a file in LEGACY MODE, t he by te o r d e r (endian) and a non-Unicode code page must be specif ied. In non-Unicode pro-grams . if no th ing is en te red , a file is o p e n e d wi th implicit s t andard sett ings. An example using the encod ing s t a tement is:

OPEN DATASET g v . f i l e i 1s t FOR INPUT IN TEXT MODE ENCODING OEFAULT.

• If a file is o p e n e d for reading, the context can only be read. In non-Unicode programs, it is also possible to gain wr i te access to these files.

• If a file is o p e n e d as a text file, only the con ten t s of character- type data objects can be read o r wr i t t en . In non-Unicode p rograms , byte- type and numer i c data objects a re also a l lowed.

The issue wi th ABAP lists is correct co lumn a l ignment of East Asian characters: In Unicode systems, the n u m b e r o f m e m o r y cells does not match the n u m b e r o f screen co lumns if the texts contain East Asian characters (ful l-width characters) . The m e m o r y cells used fo r these characters (fields of type c wi th length 1) are 8 bits long in non-Unicode sys tems and 16 bits long in Unicode systems. In Uni-code systems, a lmost all characters ( including East Asian characters) fit in o n e m e m o r y cell. However , East Asian ful l -width characters take u p two screen col-u m n s in ABAP lists, whe rea s European characters take up on ly o n e screen col-u m n .

Important Terminology Chapter 11

Important Terminology

Elementary data objects of types x and x s t r l n g are byte type, and the fol lowing e l emen ta ry data objects a re cons idered character type: c, d. n, t , s t r i n g . Struc-tures in Unicode are g r o u p e d by c o m p o n e n t s of the same o r similar data types, which p roduces a f r agmen t view. Fragments can also be based o n a l ignment gaps.

% Practice Questions

The practice ques t ions be low will he lp y o u evaluate y o u r unde r s t and ing of t he topic. The ques t ions s h o w n are similar in na tu re to those f o u n d on the certifica-t ion examina t ion , but whereas n o n e of these ques t ions will be f o u n d o n the exam itself, they a l low y o u to review y o u r knowledge of t he subject . Select t he correct answers and then check the comple teness of y o u r answers in the follow-ing solut ion sect ion. R e m e m b e r that y o u must select all correct answers and only correct answers to receive credit for the ques t ion .

1. Unicode checks can be made:

• A. In any sys tem (after Release 6 .10) by specifying t he p rogram has Unicode checks active

• B. By runn ing Transact ion UCCHECK

• C. Only in a Unicode sys tem or as par t o f a convers ion to a Unicode sys tem

• D. Cannot be enforced

2. M e m o r y r equ i r emen t s a re identical in a non-Unicode sys tem and in a Uni-code sys tem.

• A. True

• B. False

3. A d i f fe rence b e t w e e n a Unicodc a n d non-Unicode p rog ram is:

• A. Byte-type data objects cannot be assigned to character- type data objects .

• B. Byte-type data objects canno t be c o m p a r e d to character- type data objects .

340 Chapter 11 Unicode

• C. Of f s e t p o s i t i o n i n g in a U n i c o d e s t r u c t u r e is res t r i c ted to c h a r a c t e r da ta

ob jec t s .

• D. Offse t p o s i t i o n i n g in a U n i c o d e s t r u c t u r e is res t r i c ted to flat da ta ob jec t s .

4 . T w o s t r u c t u r e s in U n i c o d e p r o g r a m s a r e o n l y c o m p a t i b l e if all a l i g n m e n t

gaps a r e ident ica l o n all p l a t f o r m s .

• A. T rue

• B. False

5. T h e e n h a n c e m e n t ca t egory fo r a d a t a b a s e tab le o r s t r u c t u r e :

• A. M a k e s a t ab le U n i c o d e c o m p l i a n t

• B. Specif ies t h e t y p e s o f c h a n g e s t h a t can b e m a d e to t h e s t r u c t u r e

• C. Can p r o d u c e w a r n i n g s at i n c o m p a t i b l e p o i n t s f o r t h e s t r u c t u r e

• D. Can i d e n t i f y w h e r e p r o g r a m b e h a v i o r m a y c h a n g e

6 . In a U n i c o d e sys t em w h e n o p e n i n g a file in TEXT MODE, y o u m u s t spec i fy :

• A. T h e ENCODING a d d i t i o n

• B. T h e b y t e o r d e r

• C. T h e c o d e p a g e

7. In a n o n - U n i c o d e s y s t e m w h e n o p e n i n g a file in TEXT M O D E , y o u s h o u l d spec-

ify:

• A. T h e ENCODING a d d i t i o n

• B. T h e b y t e o r d e r

• C. T h e c o d e p a g e

Practice Question Answers and Explanations

1. Cor rec t a n s w e r s : A, B

SAP p r o v i d e s t h e too l s to p e r f o r m or e n f o r c e t h e U n i c o d e checks p r io r to

y o u r actual c o n v e r s i o n . T h e abi l i ty to e n f o r c e U n i c o d e checks exis ts in a n y

re lease a f t e r Release 6 . 1 0 ( w h e n U n i c o d e w a s s u p p o r t e d ) w i t h o u t the n e e d to

actual ly c o n v e r t t o U n i c o d e . T h e r e c o m m e n d a t i o n is to t u r n t h e check o n as

Take Away Chapter 11

soon as possible to min imize the a m o u n t of changes to deve loped programs . It is be t t e r to deve lop n e w p rograms correctly ra ther than possibly in t roduce an issue w h e n going back to make a change to the p rog ram later.

2 . Correct answer : B

No, m e m o r y r equ i r emen t s will a lways be larger o n a Unicode sys tem owing to the increased size o f t he characters . Depend ing o n the m e t h o d of encoding, the increase may be slight, bu t it will be larger.

3. Correct answers : All o p t i o n s

Owing to the e n f o r c e m e n t o f byte- type a n d character- type rules, o n a Uni-code sys tem only byte- type fields may be assigned o r c o m p a r e d to o the r byte-type fields. The same is t rue for character- type fields. Offset pos i t ioning is restr icted to flat data objects o r a character data objects .

4 . Correct answer : A

T w o s t ruc tures in Unicode p rograms are only compat ib le w h e n all a l ignment gaps are identical on all p la t forms . This appl ies in par t icular for a l ignment gaps that a re created by included s t ructures .

5. Correct answers : B, C, D

The e n h a n c e m e n t category makes it possible to recognize and hand le prob-lems related to s t ruc ture enh a n c e m e n t s . This classification is used dur ing the p rogram check to create a wa rn ing at all po in t s w h e r e it works wi th struc-tures , and w h e r e later s t ruc ture e n h a n c e m e n t s can cause syntax e r ro r s o r changes in p rogram behavior .

6. Correct answer : A

In a Unicode sys tem y o u must specify t he ENCODING addi t ion w h e n open ing a file (dataset).

7. Correct answers : B, C

In a non-Unicode sys tem y o u mus t specify bo th the byte o r d e r and the code page w h e n open ing a file (dataset).

Take Away

You will need to unde r s t and wha t Unicode is and w h y it is necessary in a global e n v i r o n m e n t . You should have knowledge of d i f fe rences b e t w e e n data objects in a non-Unicode system and data objects in a Unicode system. You should have an

328 Chapter 11 Unicode

unde r s t and ing of wha t add i t ions to s t a t emen t s exist and w h a t changes to syntax val idat ion are en fo rced in Unicode.

Refresher

You need to unde r s t and the d i f fe ren t data object types that p r o d u c e e i ther a byte- type data object o r a character- type data objec t o r a s t ruc ture a n d h o w the f r agmen t v iew restricts certain ass ignments o r compar i sons . You will also need to unde r s t and wha t restr ict ions for file processing exist wi th Unicode.

Table 11 .3 lists the key concepts of Unicode.

Key Concept Definition

8yte type Elementary data objects of types x and xstring are byte type.

Character type The following elementary data objects are now character type: c, d. n, t , s t r i ng .

Fragment view A fragment is a grouping of structure components of the same or similar data types.

Table 11.3 Key Concepts Refresher

Tips

Whereas the vast major i ty of the concep ts p resen ted in this chap te r should be second nature , especially if y o u have p r o g r a m m e d on SAP Release 6 .20 o r later, it is impor t an t that y o u unde r s t and the behav ior d i f fe rences of ass ignments , compar isons , a n d file processing.

S u m m a r y

You should n o w be able to make an ABAP program Unicode compl ian t . You should have an unde r s t and ing of the potent ia l issues related to data objects a n d file processing. This knowledge will enab le y o u to successfully pass this por t ion of the cert if ication examina t ion .

Classical Screens

Techniques You'll Master:

• Design screens with the Screen Painter

• Design a GUI status and GUI title using the Menu Painter

• Set the GUI status and process function codes in the Process After Input (PAI) flow logic screen

• Understand screen events such as PROCESS BEFORE OUTPUT, PROCESS AFTER INPUT, PROCESS ON HELP-REQUEST, and PROCESS

ON VALUE-REOUEST

• Write dialog programs

344 Chapter 12 Classical Screens

A dialog-driven p rogram consists o f screens, the GUI status, a GUI title, and an ABAP program.

• Each dialog in the sys tem is control led by o n e o r m o r e screens . The screens have a layout tha t de t e rmines the posi t ion of i n p u t / o u t p u t fields a n d o the r graphical e l emen t s such as checkboxes and radio bu t tons . You design a screen layout using the Screen Painter in the ABAP W o r k b e n c h . Each screen has flow logic that inf luences the p rogram flow. The flow logic consists o f Process Before Ou tpu t (PBO) and Process After Input (PAI) logic, and opt ional ly. Pro-cess on Help-Request (POH) and Process on Value-Request (POV) fo r any act ions requi red .

• Each screen has a GUI status, which controls t he m e n u bars, s t andard tool-bars, and applicat ion toolbars wi th which the user chooses t he func t ion in the appl icat ion.

• The GUI title is used to de f ine the title for a screen. This is especially impor-tant if the re is m o r e than o n e screen in a sequence o f screens wi th in a GUI dialog.

• An ABAP p rog ram conta ins the dialog m o d u l e that is called by t he screen flow logic and processes the user inpu t f r o m the GUI status. Type M programs are the conta iners o f dialog modu le s a n d the re fo re a re k n o w n as m o d u l e pools and can only be s tar ted using t ransact ion codes.

In this chap te r w e will cover m o d u l e pool p r o g r a m m i n g and the var ious p rogram objects requi red to create a m o d u l e pool p rogram. W e will cover screen design using the Screen Painter, screen events , and screen flow logic. W e will cover GUI status and GUI title design and its use in dialog p r o g r a m m i n g . Finally, w e will cover screen processing, dynamical ly mod i fy ing screens, and screen design using table controls .

R e a l - W o r l d S c e n a r i o

You have to wr i te a cus tom dialog p rogram for y o u r cus tomer to al low t h e m to main ta in e m p l o y e e mas te r data and payroll i n fo rma t ion because the SAP s tandard applicat ion does not satisfy the i r bus iness r equ i r emen t .

The applicat ion should have two screens: In the first screen y o u will en te r the e m p l o y e e personal in format ion , and in the second o n e y o u will e n t e r the payroll-related data. The dialog p rogram should al low the user to e n t e r data o n the screen and save the data in the database w h e n the user clicks

Objectives of this Portion of the Test Chapter 12 345

on the Save bu t ton on the screen . The dialog p rog ram should also have the op t ion to edit and display the saved data. The t ransact ion should be user f r iendly and should validate user inpu t a n d display F1 Help for the screen fields and value help (via the IF41 key) w h e r e v e r possible.

Objectives of this Portion of the Test

The object ive of this por t ion of the exam is to verify y o u r knowledge regarding the dialog p rograms . You are expected to be able to wr i te a dialog p rog ram. You should be able to design screens using the Screen Painter , design a GUI status using the M e n u Painter, and create GUI titles for a screen. You are also expected to be aware of possible screen events such as PBO (PROCESS BEFORE OUTPUT), PAI (PROCESS AFTER INPUT), POH (PROCESS ON HELP-REQUEST), and POV (PROCESS ON VALUE REQUEST). You should be able to hand le the t ransact ion f low based on user actions.

The cert if ication examina t ion will give minimal weigh t to this chap te r c o m p a r e d to all of the o the r topics in the examina t ion . This means that this chapter is a m o n g those w h e r e the percentage of ques t ions related to the topic is smal ler than most o the r chapters . The reason it is given average weight is that the re is less of a chance that y o u would have to wr i te cus tom Dialog p rog ram in a project .

Key Concepts Refresher

You need to unde r s t and the dialog p r o g r a m m i n g concep t to create a dialog trans-action. Dialog p r o g r a m m i n g consists of screen, GUI status, GUI title, modu le pool p rogram, and t ransact ion. You have to create a m o d u l e pool p rogram, screen, GUI status. GUI title, a n d t ransact ion code to execute a dialog p rogram.

To deve lop a dialog t ransact ion y o u have to use t he Screen Painter to design the screens and popu la te the screen at t r ibutes . You also have to wr i te the screen f low logic to control the data t ransfe r f r o m the screen area to the ABAP program a n d vice versa.

In screen f low logic y o u have to wr i te code for PROCESS BEFORE OUTPUT, PROCESS AFTER INPUT, PROCESS ON HELP-REQUEST, and PROCESS ON VALUE - REQUEST. The PBO event is t r iggered be fo re t he screen is displayed, so general ly y o u popula te screen fields wi th defaul t values, and set the GUI status and screen title in the

332 Chapter 12 Classical Screens

PBO event block. The PAI event is triggered when the user performs some action on the screen such clicking on a button, selecting a menu entiy. pressing enter, or selecting a function on the screen. You write code for the PAI event block to interpret the user action, validate user entries, and control the flow of the trans-action accordingly. Similarly. POH and POV are the events that are triggered when the user selects F1 help for a screen element or requests value help via IF41 for a screen field.

Note

You can wri te code to provide your o w n F1 help and F4 help in t he POH and POV event block, but r e m e m b e r tha t t he F1 help usually comes f rom a da t a ele-men t and tha t F4 input can be provided by search helps.

Also, to write a dialog program you have to design the GUI status, which consists of menus, toolbars, and function codes, and the GUI title and be able to assign these to the screen in the screen flow logic.

Screen Design

ABAP programs or dialog transactions use screens to interact with the user. The screens for dialog programming are created with the Screen Painter. Selection screens are created for an executable ABAP program with ABAP declarative state-ments (i.e.. PARAMETERS and SELECT-OPTIONS) to obtain user input for the pro-gram. You do not have to define the screen flow logic for selection screens, whereas for dialog screens you do. Screens in module pools can only be addressed using dialog transactions.

Selection Screen

The standard selection screen for executable ABAP programs is called and con-trolled by the ABAP runtime environment; selection screens are discussed in detail in Chapter 13, Selection Screens. In this chapter we will be discussing dia-log screens, which are created with the Screen Painter. You can create screens to be used in any program of type 1 (executable program), M (module pools), and F (function groups).

A program can consist of a single screen or a sequence of screens. You can start a single screen or start a sequence of screens from an ABAP program by using the

Key Concepts Refresher Chapter 12 347

CALL SCREEN s ta t ement . For screens in a m o d u l e pool p rogram of type m, t he start screen is specif ied in the t ransact ion code y o u assign to the m o d u l e pool . A defaul t next screen is de f ined in the Screen Painter for all dialog screens, bu t this can be over r idden dynamical ly wi th in the p rogram, specifically in the PAI f low logic for the screen.

A screen is a f o rm of dialog b e t w e e n the user and the p rogram. A screen can con-tain various e l emen t s for a l lowing the user to interact wi th the p rogram or for displaying the field con ten t . A typical dialog screen consists of screen e l emen t s such as i n p u t / o u t p u t fields, bu t tons , radio but tons , checkboxes , and screen f low logic. The screen f low logic consists of PBO ( P r o c e s s B e f o r e Output) . PAI (Pro c e s s A f t e r Input ) , POH ( P r o c e s s on He lp-Reques t ) , and POV ( P r o c e s s on V a l u e - R e q u e s t ) event blocks.

The screen f low logic mus t conta in at least PBO and PAI event blocks. Each screen has its o w n f low logic that calls dialog modu le s in the ABAP p rog ram to p repa re the data for display on the screen o r to process the user ' s entr ies . Gen-erally, y o u p repa re data o r m o d i f y the screen display in the PBO event block a n d react to the user action in the PAI event block. You can de f ine the F1 he lp fo r the screen field in the POH event and value help in the POV event , bu t it is recom-m e n d e d that y o u use t he F1 help and value help (possible entr ies) f r o m the ABAP Dict ionaiy. You can wr i te y o u r o w n F1 he lp and F4 input help only i f y o u w a n t to over r ide the ABAP Dict ionary help. Hence, POH and POV event blocks are opt ional .

Sc reen P a i n t e r

Each screen has a GUI status, conta in ing the m e n u bar, the s tandard toolbar , a n d optional ly, an applicat ion toolbar . The GUI status also contains the func t ion codes for each of the func t ions in the m e n u s and toolbars . You should create a GUI title for each screen . This helps the user, especially if y o u have a sequence of several screens . You can also create a GUI title for the screen dynamical ly wi thin the p rogram. The GUI status and title are discussed in detail later in this chapter .

You design the screen layout wi th the Screen Painter . The Screen Painter has a layout ed i to r that has a graphical m o d e and an a lphanumer ic m o d e . Both edi tors of fe r the same funct ional i ty but wi th d i f fe ren t interfaces. The graphical m o d e is easy to use and uses a d rag-and-drop interface, whereas wi th the a lphanumer ic ed i tor y o u use m e n u s and the keyboard to design the screen. You can switch

348 Chapter 12 Classical Screens

between the two modes via the menu path U T I L I T I E S • S E T T I N G S • G R A P H I C A L L A Y -

O U T E D I T O R . The Screen Painter can be accessed from the ABAP Workbench or via Transaction SE51.

You define the screen attributes, screen layout, and the flow logic in the Screen Painter. The screen attributes describe the properties of the screen as a whole and its runtime behavior. Figure 12.1 displays the screen attribute in the Screen Painter.

Screen Painter: Display Screen forDEMO_DYNPRO_INPUT_OUTPUT Layout

Screen number 100 AcDve

Attributes , Element list , FkJwfcopc

Short descnpocfl Demonstration of Input and Output Fie4ds on Screens

Onginai language DE German Package SABAPDEMOS

Last changed oiVby 0 2 / 2 3 / 2 0 0 1 0 9 5 7 0 2

Last generation 11 / 0 4 / 2 0 0 8 0 6 0 5 5 9

Screen type Settings

Other annbutes Next Screen 100

Cursor position

Screen group

Lines/Columns Occupied 13 37

Marnten 21 8 3

CCrttext menu FOf lM ON C T M E N U Properties

Figure 12.1 Screen Painter — Screen Att r ibute Definition

The general screen attributes are specified on the A T T R I B U T E S tab. Following are some of the screen attributes required to create a screen:

• P R O G R A M

Each screen is associated with an A B A P program. The program type can be 1, M, or F. Ifyou create the screen from the program itself, this will be populated automatically. The name of the program appears as the screen title (see Figure 12.1).

Key Concepts Refresher Chapter 12 349

• S H O R T TEXT

A sho r t m e a n i n g f u l text f o r t h e s c r e e n .

• SCREEN N U M B E R

T h e sc reen n u m b e r can b e u p to f o u r digi ts long, a n d m u s t b e a u n i q u e n u m -

b e r w i t h i n t h e c o n t a i n e r p r o g r a m .

Caution

Selection screen numbers and Screen Painter screen numbers belong to the same namespace, so your dialog screen number cannot be 1000 if your program has a selection screen as well.

• SCREEN TYPE

T h e s c r e e n t y p e can b e a n o r m a l s c reen , s u b s c r e e n , o r d ia log b o x . A n o r m a l

s c reen occup ie s t h e w h o l e GUI w i n d o w , w h e r e a s t h e d ia log b o x occup ie s

o n l y par t o f t h e GUI w i n d o w . Subsc reens a r e d i sp layed in a s u b s c r e e n a r ea o f

a n o t h e r s c r een .

• N E X T SCREEN

This d e f i n e s t h e d e f a u l t nex t s c reen in t h e s c r e e n s e q u e n c e . T h e s c r e e n wil l call i tself if t h e n e x t s c r e e n n u m b e r is t h e s a m e as t h e c u r r e n t s c reen n u m b e r . You d e f i n e the c u r r e n t s c r e e n as t h e last s c reen in t h e cha in by leaving t h e n e x t s c r e e n field b lank o r se t t ing it t o 0 (zero) . T h e n e x t s c r e e n n u m b e r can b e d y n a m i c a l l y c h a n g e d w i t h i n t h e p r o g r a m to o v e r r i d e t h e s tat ical ly d e f i n e d sc reen n u m b e r . At r u n t i m e t h e sc reen n u m b e r is s t o r e d in t h e s y s t e m vari-a b l e . T h e n e x t s c r e e n n u m b e r can b e c h a n g e d d y n a m i c a l l y in t h e PAI f l o w logic by t h e ABAP s t a t e m e n t SET SCREEN < s c r e e n _ n o > .

• C U R S O R P O S I T I O N

This d e f i n e s t h e c u r s o r pos i t i on w h e n t h e sc reen is d i sp l ayed . By de fau l t , t h e c u r s o r is p o s i t i o n e d o n t h e first i n p u t field o n t h e s c r e e n . You can a lso d y n a m -ically spec i fy t h e c u r s o r pos i t i on w i t h i n t h e p r o g r a m .

Screen Layout

T h e n e x t s t e p w h e n c rea t ing t h e sc reen is to d e f i n e t h e sc reen layout . You can

p lace i n p u t / o u t p u t fields, texts , b u t t o n s , c h e c k b o x e s , r a d i o b u t t o n s , t ab le con-

trols , t a b s t r i p con t ro l s , a n d s o o n o n t h e s c r e e n . Sc reen e l e m e n t s can b e d e f i n e d

by a d o p t i n g t h e a t t r i b u t e s o f fields f r o m t h e ABAP Dic t i ona iy . o r y o u can use a

da ta ob jec t d e f i n e d in y o u r p r o g r a m . Genera l ly , y o u c rea t e t h e sc reen e l e m e n t s

350 Chapter 12 Classical Screens

from the ABAP Dictionary, because this way you get access to the field labels, input help, documentation, and so on. The screen layout can be designed in the Graphical Screen Painter. Figure 12.2 displays the screen layout in the Screen Painter.

Maintain attributes

• S c r e e n P a i n t e r : Disp lay S c r e e n D E M 0 _ D Y N P R 0 _ I N P U T _ 0 J U ' i t ' H 1

e M © 0 €> O t» % « • • U Rj o2» • a]- II i V 4>n»>b9c ^bMAum

Show element _ list

Get dictionary or - j Q -program field ^

B E B

D a E B

F~Radlo b u t t o n ! I f Radio bu t ton 2. | c Radio bu t ton 3j

r Cancel

r Checkbox i r Checkbox 2 T Checkbox 3

Figure 12.2 Create Screen Layout

The graphical layout editor has three buttons, as depicted in Figure 12.2:

• M A I N T A I N EI.HMF.NT A T T R I B U T E S

The M A I N T A I N E L E M E N T A T T R I B U T E S button opens a new window for you to maintain the screen element attributes. These differ depending on the type of clement you have chosen, for example, an input field or button. Figure 12.3 displays screen element attribute maintenance screen. You can define general attributes such as screen group, function code, func-tion type, search help, parameter ID. and so on. You can also specify the Dic-tionaiy attributes, program attributes, and display attributes for the screen elements.

Key Concepts Refresher Chapter 12 337

El IK* IrcufOuoui r«u a i N** fNPUI

T - | |

WJhloon r SoohWtr In. [S

CtW p Vnlcr fJ Ha*4 (l

1 | r«Co* | F«T*» | wj Ccrt»»l MKUFWJI ON.CIMEMO. |

0K« | Piopm I Ondw 1 ^J fan*

r hvT** Modly | - J Com 1* S*arehH«b fl* r«w r~ PjisneCflD

T ierPirawto rtf-IP"**" r rcff^KtvChf r w/j.s.71

• 4 • QJ

Figure 12.3 Screen Element At t r ibute

• G E T D I C T I O N A R Y / P R O G R A M F I E L D S

The G E T D I C T I O N A R Y / P R O G R A M F I E L D S button opens a new window to create the screen elements and input/output fields with reference to Dictionary and program fields (see Figure 12.4).

• S H O W E L E M E N T LIST

The S H O W E L E M E N T LIST button opens a new window to show all available screen elements belonging to the screen, including their attributes for main-tenance. Figure 12.5 displays the screen element list screen.

352 Chapter 12 Classical Screens

•JScreen Painter: Diet/Program Fields TtbituFitUNvr*

SMkh

I s W ^ i e j x j

(>«» from OttKintj I G»l bar Piogein

@ Rwcfcon [ T ] RrCOedratcn

1/OFrfd i w Cocyw Tt*|C»8|R.>3B[ T«tfcNa FieUNd N--oc| Short | Lor»j [ H t j f c .

SPFU MANOT E3Q.NI O f t Sf*u CARSIO • CHAR Arir* SPfU SWU s m i S f fU

CONN© COUNT RiTR OTVFROM AflffftOM

§ NUMC f y ^ N u i r t w CHAR Cojtoy

jCHAR 20 JCHAR CXp

s m i S P F U

SPfU

COUNTRYTO OTYTO A F L P T O

JCHAR JCHAR 20

C<mry A N V J L « Y

BCHAfl s m i A T M E E ) I N T «

SPfU s m i s m i s m i S P T U

OCPTWC ARflTIME CHSTAWCE WSTID flTYPE

B U M S

TIMS A N V J I T N E

J O U A N 1 1 Drfmce lUMT Ddmc4 r* J C H A R Ch«k« 3 O Q

s m i PEROO . B ' M T I nd^i lUKf

• | o | A | i n l r i | Q |

Figure 12.4 Select Screen Element - Get Dictionary/Program Fields

U£S ! » • » I t l W > 1 |

Figure 12.5 Screen Element List

Every screen has the 20-character OK field, which is not displayed on the screen and which you must name. The name we usually give it is 0K_C0DE. The OK field is also referred to as the function code. You need to assign a name to the OK field to use it in the program. You also need to declare a data variable w i th exactly the same name, o f type SY UCOMM. This way the contents are automatically trans-

Key Concepts Refresher Chapter 12 339

ported from the screen to the ABAP program. A user action triggers the PAI event, and the function code chosen by the user is stored in this field and is passed to the ABAP program. Based on the function code (or OK), you control the program flow and dictate what happens next.

Tip

The fo l lowing a r e r e c o m m e n d a t i o n s for s c reen layout des ign :

• It is r e c o m m e n d e d t h a t you use ABAP Dict ionary t ab l e s o r s t ruc tu re s t o d e f i n e

sc reen layout . This w a y t h e sc reen field can a d o p t t h e Dict ionary a t t r i b u t e s

such as field label, va lue he lp , a n d F1 he lp . You d o no t have t o wr i t e POH or

POV f u n c t i o n s unless you w a n t to ove r r ide ABAP Dict ionary F1 /F4 f u n c t i o n s .

• If you use t h e ABAP Dict ionary, t h e sys tem prov ides you wi th t h e a u t o m a t i c

cons i s t ency check for t h e inpu t f ie lds . These checks inc lude t y p e check , fore ign

key check , a n d fixed va lue check . All of t h e s e checks a re au tomat ica l ly sup-

plied wi th t h e in fo rmat ion in t h e ABAP Dict ionary.

• You shou ld a lso dec la re a Dict ionary s t r u c t u r e as t h e work a r ea us ing t h e

T A B L E S s t a t e m e n t in t h e ABAP p r o g r a m . This w a y t h e sc reen field c o n t e n t s a re

au toma t i ca l ly c o p i e d in t h e ABAP p r o g r a m wi th t h e m a t c h i n g field n a m e .

Screen Flow Logic

The screen flow logic is created after the screen attributes and the layout of the screen have been defined. Screen flow logic is created in the flow logic editor of the Screen Painter, and you cannot use ABAP statements directly here. Screens have their own set of keywords for use in the PBO, PAI, POH, and POV event blocks. The allowed keywords for the screen flow logic are mentioned later in this section.

You create special module calls in screen flow logic, and it is these modules that contain the ABAP statements. Modules are like subroutines for the screens. They can be created by double-clicking on the module name in the flow logic editor or by right-clicking on the program name in Transaction SE80. Modules that are called in the PBO processing block must be defined using the MODULE <name> OUTPUT statement and ENDMODULE at the end. The modules that are called in the PAI processing block must be defined using MODULE <name> INPUT in the ABAP program.

354 Chapter 12 Classical Screens

I f y o u create the module using forward navigation, then it w i l l be created w i t h

the above-ment ioned syntax. Listing 12 .1 displays the screen f low logic, and List-

ing 12 .2 displays the module def in i t ion for the ones def ined in the screen flow

logic.

PROCESS BEFORE OUTPUT. MODULE i n i t _ s c r e e n _ 1 0 0 .

PROCESS AFTER INPUT. MODULE u s e r _ c o m m a n d _ 1 0 0 .

List ing 12.1 Screen Flow Logic

* *& M o d u l e INIT_SCREEN_lOO OUTPUT *& *

MODULE 1 n 1 t _ s c r e e n _ 1 0 0 OUTPUT. CLEAR i n p u t . SET PF-STATUS 1 S T A T U S _ 1 0 0 1 .

r a d i o l - ' X ' . CLEAR: r a d i o 2 . r a d i o 3 .

ENDMOOULE. "!NIT_SCREEN_100 OUTPUT

*& *

M o d u l e USER_COMMAND_100 INPUT *

MODULE u s e r _ c o i r m a n d _ 1 0 0 INPUT, o u t p u t - i n p u t , b o x l - r a d i o l . b o x 2 - r a d i o 2 . b o x 3 - r a d i o 3 . IF e x i t NE s p a c e .

LEAVE PROGRAM. ENDIF.

ENDMODULE. "USER.COMMAND.IOO INPUT

List ing 12.2 PBO a n d PAI M o d u l e Defini t ion

The screen flow logic must contain at least the t w o statements PROCESS BEFORE

OUTPUT and PROCESS AFTER OUTPUT, and these are created automatically w h e n

y o u create the screen itself. Table 12 .1 displays the keywords y o u can use in

these event blocks.

Key Concepts Refresher Chapter 12 355

Keyword Func t ion

C A L L

M O D U L E

CHAIN

ON

V A L U E S

E N D C H A I N

F I E L D

Calls a dialog module in A8AP programs

Specifies t he point a t which t he con ten t s of t he screen field must be t ranspor ted

Used in conjunct ion with F IELD

Used in conjunct ion with F IELD

Starts a processing chain

Ends a processing chain

Calls a subscreen

E N D L O O P

L O O P Starts processing a screen table

Stops processing a screen table

Table 12.1 Keywords for Screen Flow Logic

S c r e e n P r o c e s s i n g

T h e A B A P p r o c e s s o r c o n t r o l s t h e p r o g r a m f l o w w i t h i n a m o d u l e , a n d t h e d y n -

p r o / s c r e e n p r o c e s s o r c o n t r o l s t h e flow log ic a n d p r e p a r e s d a t a t o b e d i s p l a y e d

o n t h e s c r e e n . Fo r a s c r e e n a n d its A B A P p r o g r a m t o b e a b l e t o c o m m u n i c a t e , t h e

s c r e e n a n d t h e A B A P p r o g r a m f i e ld n a m e s s h o u l d b e i d e n t i c a l . W h e n t h i s is t h e

case , t h e c o n t e n t s o f t h e s c r e e n fields a r e t r a n s p o r t e d to t h e A B A P p r o g r a m fields

w i t h t h e s a m e n a m e , a n d v ice v e r s a . You s h o u l d u s e D i c t i o n a r y s t r u c t u r e s o r p r o -

g r a m fields t o d e f i n e t h e s c r e e n e l e m e n t s a n d i n p u t / o u t p u t fields a n d d e c l a r e t h e

D i c t i o n a i y s t r u c t u r e a s a w o r k a r e a in t h e p r o g r a m b y u s i n g t h e TABLES s t a t e -

m e n t . T h i s e n s u r e s t h a t s c r e e n field c o n t e n t is c o p i e d a u t o m a t i c a l l y f r o m t h e

s c r e e n to t h e A B A P d a t a o b j e c t w i t h t h e m a t c h i n g n a m e a n d v i c e v e r s a .

T h e c o n t e n t s o f t h e A B A P w o r k a r e a a r e c o p i e d t o t h e i r c o r r e s p o n d i n g s c r e e n

fields a f t e r all o f t h e m o d u l e s d e f i n e d in t h e PBO p r o c e s s i n g b lock h a v e b e e n e x e -

c u t e d . S imi l a r ly , t h e s y s t e m c o p i e s t h e c o n t e n t s o f t h e s c r e e n fields to t h e c o r r e -

s p o n d i n g fields in t h e A B A P w o r k a r e a b e f o r e t h e first m o d u l e in t h e PAI

p r o c e s s i n g b l o c k is e x e c u t e d , u n l e s s t h i s t r a n s p o r t h a s b e e n d e l a y e d b y t h e u s e

of the F I E L D statement.

342 Chapter 12 Classical Screens

W h e n a s c r e e n is p r o c e s s e d , t h e PROCESS 8EF0RE OUTPUT e v e n t is t r i g g e r e d , t h e

c o r r e s p o n d i n g e v e n t b l o c k in t h e s c r e e n f l o w log ic is e x e c u t e d , a n d t h e n t h e

s c r e e n is d i s p l a y e d . T h e PROCESS AFTER INPUT e v e n t is t r i g g e r e d a n d t h e c o r r e -

s p o n d i n g e v e n t b l o c k is e x e c u t e d w h e n t h e u s e r s e l ec t s a f u n c t i o n c o d e o n t h e

s c r e e n , f o r e x a m p l e , c l i ck ing o n b u t t o n , s e l e c t i n g a m e n u e n t r y , p r e s s i n g a f u n c -

t i o n k e y o n t h e k e y b o a r d , o r j u s t p r e s s i n g [ «-* ]. If t h e u s e r r e q u e s t s f i e ld h e l p b y

p r e s s i n g Q T ] o r v a l u e h e l p b y p r e s s i n g ( ? £ ) . it t r i g g e r s t h e PROCESS ON HELP

REQUEST a n d PROCESS ON VALUE-REQUEST e v e n t .

P B O is a b o u t p r e p a r i n g t h e s c r e e n , p e r h a p s p r o v i d i n g d e f a u l t v a l u e s f o r t h e

s c r e e n fields t h a t m a y o r m a y n o t c o m e f r o m t h e d a t a b a s e , a n d s e t t i n g u p t h e

GUI s t a t u s a n d GUI t i t l e . T h e PAI e v e n t is t r i g g e r e d w h e n t h e u s e r i n t e r a c t s w i t h

t h e s c r e e n , p e r h a p s b y c l i ck ing o n a b u t t o n o n t h e s c r e e n ; s e l e c t i n g a f u n c t i o n

f r o m t h e m e n u , s t a n d a r d t o o l b a r , o r a p p l i c a t i o n t o o l b a r ; p r e s s i n g a f u n c t i o n k e y

o n t h e k e y b o a r d , a n d s o o n . T h e f u n c t i o n c o d e is p a s s e d t o t h e 0K_C0DE s c r e e n

field f r o m t h e e l e m e n t list a n d is p a s s e d t o t h e i d e n t i c a l l y n a m e d field in t h e

A B A P p r o g r a m .

W e h a v e a l r e a d y d i s c u s s e d t h a t y o u c a n call t h e A B A P d i a l o g m o d u l e s f r o m t h e

s c r e e n f l o w logic b y u s i n g t h e MODULE s t a t e m e n t . You c a n a l so call A B A P d i a l o g

m o d u l e s in a c o n t r o l l e d m a n n e r b y u s i n g t h e FIELD s t a t e m e n t in t h e s c r e e n f l o w

logic ( see Lis t ing 1 2 . 3 ) .

PROCESS BEFORE OUTPUT. MODULE i n i t _ s c r e e n _ 1 0 0 .

PROCESS AFTER INPUT. MODULE u s e r _ c o m m a n d _ 0 1 0 0 . MODULE m o d u l e . l . FIELD b 0 x 2 . MODULE m o d u l e _ 2 . FIELD: b o x l . b o x 3 . MODULE m o d u l e _ 3 .

Listing 12.3 Controlled ABAP Dialog

• FIELD

T h e FIELD s t a t e m e n t is u s e d in PAI, P O H , a n d P O V e v e n t b l o c k s . It d o e s n o t

h a v e a n y e f f e c t o n t h e P B O e v e n t b l o c k a n d h e n c e s h o u l d n o t b e u s e d in PBO

e v e n t b l o c k s . It c a n b e u s e d w i t h PAI m o d u l e s f o r i n p u t c h e c k s o n t h e s c r e e n

field. T h e i n p u t field a g a i n s t t h e FIELD k e y w o r d wi l l b e r e a d y f o r r e - i n p u t i f

t h e m o d u l e d e f i n e d f o r t h e FIELD s t a t e m e n t i s s u e s a n e r r o r o r w a r n i n g m e s -

Key Concepts Refresher Chapter 12 343

sage . You c a n a l s o call t h e A B A P d i a l o g m o d u l e s c o n d i t i o n a l l y b y u s i n g t h e

a d d i t i o n ON INPUT o r ON REQUEST w i t h t h e FIELD s t a t e m e n t .

• CHAIN...ENOCHAIN

T h e CHAIN a n d ENOCHAIN s t a t e m e n t s c a n b e u s e d t o v a l i d a t e u s e r i n p u t o n a

se t o f f i e l d s o n a d i a l o g s c r e e n . You c a n s e n d a n e r r o r o r w a r n i n g m e s s a g e

f r o m t h e m o d u l e t h a t is call u s i n g t h e FIELO s t a t e m e n t . All o f t h e f i e l d s t h a t

b e l o n g t o t h e p r o c e s s i n g c h a i n w i t h i n t h e CHAIN a n d ENOCHAIN s t a t e m e n t a r e

r e a d y f o r i n p u t if a n e r r o r o r a w a r n i n g m e s s a g e is s e n t f r o m t h e m o d u l e . F o r

t h e w a r n i n g m e s s a g e , all o f t h e f i e l d s w i t h i n t h e c h a i n b l o c k wi l l b e r e a d y f o r

i n p u t , b u t y o u c a n c o n t i n u e w i t h t h e t r a n s a c t i o n b y p r e s s i n g t h e [ l k e y .

H o w e v e r , f o r a n e r r o r m e s s a g e y o u h a v e t o r e s o l v e t h e e r r o r , a n d t h e n y o u

c a n p r o c e e d w i t h t h e t r a n s a c t i o n .

I f y o u u s e t h e FIELO s t a t e m e n t o u t s i d e a CHAIN s t a t e m e n t , o n l y s i n g l e f i e ld is

m a d e r e a d y f o r i n p u t w h e n a w a r n i n g o r e r r o r m e s s a g e is d i s p l a y e d , w h e r e a s

w i t h t h e CHAIN a n d ENOCHAIN s t a t e m e n t s , t h e se t o f f i e l d s w i t h t h e s t a t e m e n t

b l o c k is m a d e r e a d y f o r i n p u t if a n e r r o r o r w a r n i n g is d i s p l a y e d . Lis t ing 1 2 . 4

d i s p l a y s t h e s c r e e n f l o w log ic f o r a n i n p u t c h e c k w i t h t h e CHAIN a n d ENOCHAIN

s t a t e m e n t s , a n d L i s t ing 1 2 . 5 d i s p l a y s t h e m o d u l e f o r a n i n p u t c h e c k .

PROCESS BEFORE OUTPUT. MODULE i n i t _ s c r e e n _ 9 0 0 1 .

PROCESS AFTER INPUT. MOOULE c a n c e l AT EXIT-COMMAND. FIELD i n p u t l MODULE m o d u l e . l . FIELD i n p u t 2 MODULE m o d u l e _ 2 . FIELD i n p u t 3 MODULE m o d u l e _ 3 . CHAIN.

FIELD i n p u t 4 . MODULE c h a i n _ m o d u l e _ l . FIELD i n p u t 5 . FIELD i n p u t 6 MODULE c h a i n _ m o d u l e _ 2 .

ENOCHAIN. MODULE e x e c u t i o n .

Listing 12.4 Input Check with CHAIN and ENDCHAIN S ta temen t s

* MODULE c h a i n _ m o d u l e _ I INPUT

MOOULE c h a i n _ m o d u l e _ l INPUT. IF i n p u t 4 < 10 .

344 Chapter 12 Classical Screens

MESSAGE wOOO(fb) WITH t e x t - 0 0 3 ' 1 0 ' t e x t - 0 0 2 . ENDIF.

ENDMODULE ' CHAIN_MOOULE_1 INPUT * . . . . . . . . . . . . . . . . . . . . . . »

* MODULE c h a i n _ m o d u l e _ 2 INPUT * *

MODULE c h a i n _ m o d u l e _ 2 INPUT. CLEAR s u m . sum - i n p u t 4 + i n p u t 5 + i n p u t 6 . IF sum < - 1 0 0 .

MESSAGE e O O O ( f b ) WITH t e x t - 0 0 4 ' 1 0 0 ' t e x t - 0 0 2 . ENDIF.

ENDMOOULE. " CHAIN_M0DULE_2 INPUT

List ing 12.5 Inpu t Check M o d u l e

• O N I N P U T

T h e ON I N P U T a d d i t i o n f o r t h e F IELO s t a t e m e n t ca l l s t h e A B A P d i a l o g w h e n t h e

s c r e e n f i e l d c o n t a i n s a v a l u e o t h e r t h a n t h e i n i t i a l v a l u e f o r t h a t s c r e e n f i e l d .

T h e i n i t i a l v a l u e f o r t h e s c r e e n field is d e t e r m i n e d b y t h e d a t a t y p e o f t h e

s c r e e n field. T h e i n i t i a l v a l u e is s p a c e ( ) f o r c h a r a c t e r fields a n d 0 ( z e r o ) f o r

n u m e r i c fields.

• O N R E Q U E S T

T h e ON R E Q U E S T a d d i t i o n f o r t h e F I E L D s t a t e m e n t ca l l s t h e A B A P d i a l o g m o d -

u l e o n l y i f t h e u s e r h a s e n t e r e d s o m e t h i n g in t h e s c r e e n field. T h e m o d u l e is

e x e c u t e d e v e n i f t h e u s e r e n t e r s t h e i n i t i a l v a l u e f o r t h e d a t a t y p e o f t h e s c r e e n

field o r o v e r w r i t e s a n e x i s t i n g v a l u e w i t h t h e s a m e v a l u e .

• O N C H A I N - I N P U T a n d O N - C H A I N R E Q U E S T

T h e O N C H A I N - I N P U T a n d O N - C H A I N R E Q U E S T a d d i t i o n s w o r k t h e s a m e w a y a s

ON I N P U T a n d ON R E Q U E S T e x c e p t t h a t t h e A B A P d i a l o g m o d u l e is c a l l e d i f at

least o n e field l i s t e d i n t h e F I E L D s t a t e m e n t w i t h i n t h e C H A I N s t a t e m e n t m e e t s

t h e c o n d i t i o n . L i s t i n g 1 2 . 6 d i s p l a y s t h e c o n d i t i o n a l p r o c e s s i n g o f a n A B A P

d i a l o g .

P R O C E S S B E F O R E O U T P U T .

M O D U L E I n i t _ s c r e e n _ 9 0 0 2 . P R O C E S S A F T E R I N P U T .

M O D U L E c a n c e l A T E X I T - C O M M A N D .

C H A I N .

F I E L D : i n p u t l . i n p u t 2 . M O D U L E c h a i n _ m o d u l e _ l O N C H A I N - I N P U T .

Key Concepts Refresher Chapter 12 359

FIELD 1 n p u t 3 MODULE c h a i n _ m o d u l e _ 2 ON CHAIN-REQUEST.

ENOCHAIN.

Listing 12.6 Conditional ABAP Dialog

• AT CURSOR-SELECTION

T h e AT CURSOR - SELECTION a d d i t i o n calls t h e A B A P d i a l o g m o d u l e if t h e c u r s o r

is p o s i t i o n e d o n a p a r t i c u l a r s c r e e n e l e m e n t .

A u t o m a t i c i n p u t c h e c k s a r e p e r f o r m e d in t h e PAI e v e n t b e f o r e t h e d a t a is t r a n s -

f e r r e d t o t h e A B A P p r o g r a m . T h e a u t o m a t i c c h e c k s a r e p e r f o r m e d b a s e d o n t h e

s c r e e n e l e m e n t a t t r i b u t e s . If a s c r e e n field is m a n d a t o r y , t h e n t h e u s e r m u s t e n t e r

d a t a b e f o r e t h e PAI e v e n t b l o c k c a n s t a r t . If t h e s c r e e n i n p u t field r e f e r s t o a n

A B A P D i c t i o n a i y field, t h e n t h e field-level v a l i d a t i o n d e f i n e d in t h e A B A P Dic-

t i o n a i y s u c h as c h e c k s a g a i n s t t h e c h e c k t a l e o r d o m a i n fixed v a l u e s is p e r f o r m e d

b e f o r e t h e PAI p r o c e s s i n g c a n s t a r t .

T h e u s e r i n p u t f o r t h e field s h o u l d m a t c h t h e f o r m a t d e f i n e d f o r t h e field in t h e

S c r e e n P a i n t e r ; o t h e r w i s e , t h e u s e r g e t s a n e r r o r m e s s a g e b e f o r e t h e PAI p r o c e s s -

i n g c a n s t a r t . In s u c h a case y o u c a n e x i t t h e s c r e e n o n l y b y e n t e r i n g a va l id v a l u e

o r s e l e c t i n g t h e m e n u i t e m o f f u n c t i o n t y p e E. F o r t h e m e n u i t e m o f f u n c t i o n t y p e

t y o u h a v e t o c o d e t h e e x i t log ic w i t h i n t h e d i a l o g m o d u l e d e f i n e d w i t h t h e a d d i -

t i o n AT EXIT-COMMAND in PAI. L i s t ing 1 2 . 6 d i s p l a y s t h e u s a g e o f AT EXIT-COMMAND

in s c r e e n f l o w logic , a n d Lis t ing 1 2 . 7 d i s p l a y s t h e c o d e in t h e m o d u l e f o r AT

EXIT-COMMAND. *& *

Module CANCEL INPUT *

MODULE c a n c e l INPUT. CASE o k . c o d e .

WHEN 'BACK*. LEAVE. SET SCREEN 0 . LEAVE SCREEN.

WHEN ' E X I T ' . LEAVE. SET SCREEN 0 . LEAVE SCREEN.

WHEN 'CANCEL'. SET SCREEN 0 . LEAVE SCREEN.

346 Chapter 12 Classical Screens

ENDCASE. LEAVE PROGRAM.

ENDMOOULE. " CANCEL INPUT

List ing 12.7 M o d u l e for AT EXIT-COMMAND

Y o u c a n v a l i d a t e t h e u s e r i n p u t w i t h t h e s c r e e n f l o w l o g i c b y t h e a d d i t i o n VALUES

w i t h t h e FIELD s t a t e m e n t o r b y c h e c k i n g a g a i n s t a d a t a b a s e t a b l e . L i s t i n g 1 2 . 8

d i s p l a y s t h e u s e o f t h e FIELD a n d VALUE k e y w o r d t o v a l i d a t e t h e u s e r i n p u t .

PROCESS BEFORE OUTPUT. MODULE i n i t _ s c r e e n _ 0 1 0 0 .

PROCESS AFTER INPUT. MODULE c a n c e l AT EXIT-COMMAND.

FIELD c a r r i e r VALUES ( n o t , A A \ ' L H \ b e t w e e n 'OF* and ' U A ' ) . MODULE m o d u l e . l . FIELD c o n n e c t SELECT *

FROM s p f l i

WHERE c a r r i d - c a r r i e r AND c o n n i d - c o n n e c t WHENEVER NOT FOUND SEND ERRORMESSAGE 107

WITH c a r r i e r c o n n e c t .

MODULE m o d u l e _ 2 .

List ing 12.8 Input Check in Screen Flow Logic

I f y o u call a m o d u l e u s i n g a FIELD s t a t e m e n t , w h e n i s s u i n g a n e r r o r o r w a r n i n g

m e s s a g e a f t e r d o i n g t h e c h e c k s i n t h e m o d u l e , o n l y t h e i n p u t fields m e n t i o n e d

a g a i n s t t h e FIELD k e y w o r d w i l l b e a v a i l a b l e f o r r e - i n p u t . T h e u s e r s h o u l d b e

a l l o w e d t o c o r r e c t i n c o r r e c t e n t i y . T h i s c a n b e d o n e b y s e n d i n g a n e r r o r m e s s a g e

o r a w a r n i n g m e s s a g e ( s e e L i s t i n g 1 2 . 9 a n d L i s t i n g 1 2 . 1 0 ) . W i t h a w a r n i n g m e s -

s a g e t h e u s e r w i l l b e g i v e n a n o p t i o n t o r e - i n p u t a v a l i d v a l u e b u t c a n p r o c e e d

w i t h o u t e n t e r i n g t h e v a l u e b y p r e s s i n g t h e («-• ] k e y .

PROCESS BEFORE OUTPUT. MODULE i n i t _ s c r e e n _ 9 0 0 1 .

PROCESS AFTER INPUT. MODULE c a n c e l AT EXIT-COMMAND. FIELD i n p u t l MODULE m o d u l e _ l . FIELD i n p u t 2 MODULE m o d u l e _ 2 . FIELD i n p u t 3 MODULE m o d u l e _ 3 . CHAIN.

FIELD i n p u t 4 . MODULE c h a i n _ m o d u l e _ l . FIELD i n p u t 5 .

Key Concepts Refresher Chapter 12 361

FIELD i n p u t 6 MODULE c h a i n _ m o d u l e _ 2 . ENOCHAIN. MODULE e x e c u t i o n .

Listing 12.9 Inpu t Check in ABAP Dialog

*& *

*& M o d u l e M0DULE_1 INPUT *& *

MOOULE m o d u l e . l INPUT. IF i n p u t l < 5 0 .

MESSAGE e 0 0 0 ( f b ) WITH t e x t - 0 0 1 ' 5 0 ' t e x t - 0 0 2 . ENOIF.

ENOMODULE. " MODULE.l INPUT

* MODULE m o d u l e _ 2 INPUT

MOOULE rrodul e _ 2 INPUT. IF i n p u t 2 < 1 0 0 .

MESSAGE e 0 0 0 ( f b ) WITH t e x t - 0 0 1 ' l O O ' t e x t - 0 0 2 . ENOIF.

ENOMODULE. " MODULE.2 INPUT

* MODULE m o d u 1 e _ 3 INPUT

MOOULE m o d u l e _ 3 INPUT. IF i n p u t 3 < 1 5 0 .

MESSAGE wOOO(fb) WITH t e x t - 0 0 1 ' 1 5 0 ' t e x t - 0 0 2 . ENOIF.

ENOMODULE. " MODULE_3 INPUT

* MODULE c h a i n _ m o d u l e _ l INPUT * *

MOOULE c h a i n _ m o d u l e _ I INPUT. IF i n p u t 4 < 1 0 .

MESSAGE wOOO(fb) WITH t e x t - 0 0 3 ' l O ' t e x t - 0 0 2 . ENOIF.

ENDMODULE. " CHAIN_MODULE_l INPUT

* MODULE c h a i n _ m o d u l e _ 2 INPUT

348 Chapter 12 Classical Screens

MODULE chain_module_2 INPUT. CLEAR sum. sum - inpu t4 + i n p u t 5 + i n p u t 6 . IF sum <- 100.

MESSAGE e 0 0 0 ( f b ) WITH t e x t - 0 0 4 ' lOO' t e x t - 0 0 2 . ENDIF.

ENDMOOULE. " CHAIN_M0DULE_2 INPUT

Listing 12.10 ABAP Dialog for Input Check

In the f low logic M0DULE_1 is called using t he FIELD s ta tement for the field i npu t l . If an e r ro r message is t r iggered f r o m modul e _ l . t hen the field i nput 1 will be ready for input again, a l lowing t he user to e n t e r a n e w value.

Similarly, if an e r r o r o r wa rn ing message is sent f r o m the m o d u l e using the FIELD s t a t emen t wi th in CHAIN and ENOCHAIN. then all fields wi th in t he CHAIN and END CHAIN s ta tements are ready for input . In Listing 12.11 if the m o d u l e CHAIN_ MODUL E_2 sends an e r ro r message, then all of the fields wi th in the CHAIN and END CHAIN are ready for input again.

CHAIN. FIELD 1nput4 . MODULE cha in_modu le_ l . FIELD i n p u t s . FIELD i n p u t 6 module chain_module_2.

ENDCHAIN.

Listing 12.11 Input Field Check in ABAP Dialog

Lastly, y o u can code y o u r o w n F1 field help and value he lp func t ions for screen fields, bu t y o u should only d o this if the Dict ionaiy fields that y o u r screen fields are based u p o n d o not have F1/F4 he lp o r if y o u w a n t to over r ide it. There are three ways to provide Fl field he lp for the user .

• You can use ABAP Dict ionary fields for the screen e l e m e n t def in i t ion , in which case F1 help automatical ly displays the data e l emen t documen ta t i on .

• You can display data e l emen t s u p p l e m e n t a t y documen ta t i on for F1 he lp if the data e lement documen ta t i on is no t suff ic ient for y o u r appl icat ion. You can display o r mainta in the data e lement s u p p l e m e n t a r y documen ta t i on via the m e n u p a t h G O T O • D O C U M E N T A T I O N • SUPPLEMENTARY D O C U M E N T A T I O N . D a t a

e lement s u p p l e m e n t a i y documen ta t i on is p rogram and screen specific, and t he link is main ta ined in table THIPF. Figure 12 .6 displays the data e l emen t

Key Concepts Refresher Chapter 12 363

s u p p l e m e n t l ink f o r t h e A B A P D i c t i o n a r y d a t a e l e m e n t MATNR , a l o n g w i t h t h e

p r o g r a m a n d t h e s c r e e n s f o r w h i c h t h i s e x t r a d o c u m e n t a t i o n h a s b e e n c re -

a t e d .

rmrm ScrM« naaMr n*i« MM «*10 tUtM K SwlMMI IMC0M1 IOO© XMA-KATMI eo«o 160© MMK1M RWRM.Wt 0<01 •A* A «Hf <•310 iv.cv>e OJOI COSO

M»1 •MUMWM (OiO SAPlCVOO 02J2 NMU-IMTM VI*) VH. CY00 0101 IWU-NMM •090

Figure 12.6 Table Entry for Data Element Supplement Help

T h e s y n t a x to d i s p l a y t h e d a t a e l e m e n t s u p p l e m e n t a r y d o c u m e n t a t i o n f o r F1

h e l p is a s f o l l o w s :

PROCESS ON HELP-REOUEST. FI ELD m a r a - m a t n r MODULE f l _ h e l p _ m a t n r WITH v a r .

Y o u c a n p o p u l a t e t h e v a r in t h e m o d u l e f l _ h e l p _ m a t n r o r u s e t h e l i t e ra l

i n s t e a d o f v a r i a b l e :

PROCESS ON HELP-REOUEST. FIELD m a r a - m a t n r WITH 0 0 9 0 .

T h e a b o v e s y n t a x is o n l y va l id if t h e p r o g r a m , s c r e e n n u m b e r , field n a m e , a n d

s u p p l e m e n t d o c u m e n t a t i o n n u m b e r a r e m a i n t a i n e d in t h e t a b l e THLPF.

• If t h e a b o v e t w o m e t h o d s f o r t h e d i s p l a y o f h e l p a r e n o t s u f f i c i e n t f o r y o u r

a p p l i c a t i o n , t h e n y o u c a n d i s p l a y F1 h e l p f r o m t h e d i a l o g m o d u l e s b y w r i t i n g

y o u r o w n c o d e . G e n e r a l l y , y o u c a n u s e t h e f u n c t i o n m o d u l e HELP_OBJECT_

SHOW_FOR_FIELO o r HELP_OBJECT_SHOW to d i s p l a y h e l p i n s t e a d o f c r e a t i n g

y o u r o w n s c r e e n f r o m s c r a t c h f o r y o u r a p p l i c a t i o n to d i s p l a y h e l p . L i s t ing

1 2 . 1 2 d i s p l a y s t h e s c r e e n f l o w log ic f o r F1 h e l p , a n d L i s t ing 1 2 . 1 3 d i s p l a y s

t h e F1 h e l p i m p l e m e n t a t i o n f o r a d i a l o g m o d u l e .

PROCESS BEFORE OUTPUT. PROCESS AFTER INPUT.

MODULE c a n c e l AT EXIT-COMMAND. PROCESS ON HELP-REQUEST.

FIELD d e m o f l h e l p - f 1 e l d 2 MODULE f l _ h e l p _ f 1 e l d 2 WITH v a r . FIELD f i e l d 3 MODULE f l j i e l p_f i e l d 3 . FIELD f i e l d 4 MODULE f l j i e l p _ f i e l d 4 .

Listing 12.12 Screen Flow Logic for F1 Help with Dialog M o d u l e

350 Chapter 12 Classical Screens

MOOULE f l _ h e l p _ f i e l d 2 INPUT

MODULE f l _ h e l p _ f i e l d 2 INPUT. 1 n t - i n t + 1 . CASE i n t .

WHEN 1 . v a r - ' 0 1 0 0 ' .

WHEN 2 . v a r - ' 0 2 0 0 ' . i n t - 0 .

ENDCASE.

ENDMOOULE. " f l _ h e l p _ f 1 e l d 2 INPUT

MOOULE f l _ h e l p _ f i e l d 3 INPUT

MODULE f l _ h e l p _ f i e l d 3 INPUT. CALL FUNCTION 'HELP_OBJECT_SHOW_FOR_FIELD'

EXPORTING d o k l a n g u - s y - l a n g u

d o k t i t l e - t e x t - 0 0 2 c a l l e d _ f o r _ t a b - 'DEMOF1HELP" c a i l e d _ f o r _ f i e i d - ' F I E L O l * .

ENDMOOULE. " f l _ h e l p _ f i e l d 3 INPUT

* MOOULE f l _ h e l p _ f i e l d 4 INPUT

MODULE f l _ h e l p _ f i e l d 4 INPUT. CALL FUNCTION 'HELP.OBJECT.SHOW

EXPORTING d o k c l a s s - *TX' d o k l a n g u - s y - l a n g u dokname - 'OEMO_FOR_F1_HELP' d o k t i t l e - t e x t - 0 0 3

TABLES l i n k s - l i n k s .

ENDMOOULE. " f l _ h e l p _ f i e l d 4 INPUT

List ing 12.13 F1 Help I m p l e m e n t a t i o n for Dialog M o d u l e

S i m i l a r t o F1 h e l p , y o u c a n d i s p l a y F 4 i n p u t h e l p b a s e d o n A B A P D i c t i o n a r y

fields, b a s e d o n t h e s c r e e n field a t t r i b u t e s w h e r e y o u c a n a t t a c h a s e a r c h h e l p f o r

Key Concepts Refresher Chapter 12 351

t h e i n p u t f i e ld , o r b y w r i t i n g y o u r o w n d i a l o g m o d u l e . You u s e t h e s y n t a x in List-

i n g 1 2 . 1 4 f o r v a l u e h e l p i f y o u a r e g o i n g t o p r o g r a m i t y o u r s e l f i n t h e s c r e e n f l o w

logic :

PROCESS ON VALUE-REQUEST. FIELO c a r r i e r MOOULE v a l u e _ c a r r i e r .

FIELD c o n n e c t i o n MODULE v a l u e _ c o n n e c t i o n .

Listing 12.14 Screen Flow Logic for Value Help

C o d i n g f o r t h e F 4 h e l p is in t h e m o d u l e s v a l u e _ c a r r i e r a n d v a l u e _ c o n n e c t i o n .

L i s t ing 1 2 . 1 5 d i s p l a y s t h i s v a l u e h e l p c o d e w i t h i n t h e m o d u l e .

MOOULE v a l u e _ c a r r i e r INPUT. CALL FUNCTION 'F4IF_FIELD_VALUE_REQUEST'

EXPORTING t abname - 'DEM0F4HELP' f i e l d n a m e - 'CARRIER1* d y n p p r o g - s y - r e p i d d y n p n r - s y - d y n n r d y n p r o f i e l d - 'CARRIER' .

ENOHODULE.

MODULE v a l u e . c o n n e c t i o n INPUT. CALL FUNCTION 'DYNP_VALUES_READ'

EXPORTING dyname - s y - r e p i d dynumb - s y - d y n n r t r a n s l a t e _ t o _ u p p e r - ' X '

TA8LES d y n p f i e l d s - d y n p r o _ v a l u e s .

READ TABLE d y n p r o . v a l u e s INDEX 1 INTO f i e l d . v a l u e . SELECT c a r r i d c o n n i d

FROM s p f l i INTO CORRESPONDING FIELDS OF TABLE v a l u e s _ t a b WHERE c a r r i d - f i e l d _ v a l u e - f i e l d v a l u e .

CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST' EXPORTING

r e t f i e l d - 'CONNID' d y n p p r o g - s y - r e p i d d y n p n r - s y - d y n n r d y n p r o f i e l d - 'CONNECTION* v a l u e _ o r g - "S"

TA8LES

352 Chapter 12 Classical Screens

v a 1 u e _ t a b - v a l u e s _ t a b . E N D M O O U L E .

Listing 12.15 F4 Input Help Implementa t ion

H o w e v e r , it is r e c o m m e n d e d t h a t y o u u s e t h e i n p u t h e l p f r o m t h e A B A P Dic t io -

n a r y . You c a n a l so a t t a c h a s e a r c h h e l p in t h e s c r e e n field a t t r i b u t e s . H e n c e , it i s

r e c o m m e n d e d t h a t y o u p r o g r a m t h e i n p u t h e l p i f y o u w a n t to o v e r r i d e t h e A B A P

D i c t i o n a r y i n p u t h e l p .

GUI Status and Title Design

T h e GUI s t a t u s a n d GUI t i t le t o g e t h e r m a k e u p t h e u s e r i n t e r f a c e f o r t h e s c r e e n .

T h e GUI s t a t u s f o r a s c r e e n c o n s i s t s o f t h e m e n u b a r , a s t a n d a r d t o o l b a r , t h e

a p p l i c a t i o n t o o l b a r , a n d t h e f u n c t i o n k e y s e t t i n g s , a n d is d e s i g n e d u s i n g t h e

M e n u P a i n t e r t oo l . T h e G U I t i t le is u s e d t o d e f i n e t h e t i t l e f o r t h e s c r e e n . Each

s c r e e n s h o u l d h a v e a GUI s t a t u s a n d GUI t i t le ( see F i g u r e 1 2 . 7 ) . T h e GUI s t a t u s

c o n s i s t s o f a m e n u b a r , s t a n d a r d t o o l b a r a n d a p p l i c a t i o n t o o l b a r . Y o u c a n a l s o

a s s i g n f u n c t i o n k e y s t o t h e m e n u i t e m s .

Figure 12.7 SAP User Interface

Key Concepts Refresher Chapter 12 353

M e n u s are an e lement that provides the user with a range of funct ions that arc relevant to the screen or application. A menu bar is made up of individual menus and can have up to eight menus including the SYSTEM and HELP menus . The entries under the menu can be functions, separators, or submenus . To create a GUI status in the Menu Painter, create the status, create the menu bar, create the menu entries, def ine the funct ion key settings, def ine the s tandard toolbar and application bar, and as a final s tep activate the status.

Note

The SYSTEM and HELP menus are always present for every screen and have iden-tical functions that cannot be modified.

Once you have created the GUI status, you need to create the menu bar and then create the individual menu funct ions and entries. To create a menu bar click on the EXPAND icon (>•) of the menu bar text field and then enter the menu title (or use the predef ined standard), and replace the first menu title.

Each menu can have up 15 entries or funct ions. To add funct ions to a menu dou-ble-click on the menu bar and then add the funct ion code and funct ion text in the CODE and TEXT columns, respectively. To add submenus enter jus t the text in the TEXT column, double-dick, and then enter the code and text in the cascading menu . The funct ion within the menu can be active or inactive. You can activate or deactivate menu items via the menu path EXTRAS • FUNCTION ACTIVE<->INAC-TIVE. You can also activate or deactivate the menu item dynamically with the PBO event block. Activation and deactivation of menu items is useful when the same GUI status is being used for a n u m b e r of screens within the transaction. When you have a screen sequence in a transaction, some menu opt ions will be relevant for some screens and not for the others, bu t to maintain consistency, the same GUI status can be used for each screen, with menu funct ions switched off when they are not relevant.

Functions within the menu or toolbars are identified by funct ion codes. It doesn ' t mat ter where the funct ion appears or is triggered f rom (i.e.. menu , tool-bar or funct ion key), but the funct ion type is relevant. The at t r ibute FUNCTION TYPE determines the intended purpose of the funct ion. The funct ion type is also somet imes referred to as a functional type. The funct ion type can tell when and how to cariy out the processing of the funct ion. Table 12.2 displays the valid funct ion types for the funct ions belonging to SAP screens.

354 Chapter 12 Classical Screens

Type M e a n i n g

Blank Normal function code processing in PAI module . For normal function code you can leave the function type blank; that is, blank means normal func-tion code.

Triggers an AT EXIT-COMMAND module in the PAI processing block.

T Call ano ther transaction.

Triggers a system function and is used internally in standard SAP applica-t ion. You shouldn' t use this in your own applications.

Triggers a function defined locally at the GUI. This function does not trig-ger the PAI event; instead, it is processed at the presentat ion server level. As good example of this function type is function codes at tached to tab-strips, where the user can switch be tween tabs without any logic happen-ing in the screen flow logic.

Table 12.2 Function Types in SAP Systems

Fo r f u n c t i o n s w i t h f u n c t i o n t y p e E, t h e s y s t e m e x e c u t e s t h e d ia log m o d u l e t ha t

is cal led w i t h t h e a d d i t i o n AT EXIT-COMMAND, if o n e h a s b e e n d e f i n e d in t h e PAI

e v e n t b lock . T h e s y n t a x f o r AT EXIT COMMAND a n d t h e e x a m p l e c o d e w a s dis-

c u s s e d ea r l i e r in t h e S c r e e n P r o c e s s i n g s e c t i o n o f t h i s c h a p t e r . T h e s y s t e m exe-

c u t e s t h e MODULE xxx AT EXIT COMMAND before t h e a u t o m a t i c i n p u t checks a n d

b e f o r e a n y o t h e r m o d u l e s in t h e PAI e v e n t b lock . W h e n a f u n c t i o n o f t y p e T is

t r i gge red , t h e s y s t e m leaves t h e cal l ing p r o g r a m a n d calls t h e t r a n s a c t i o n t ha t is

to b e f o u n d in t h e f u n c t i o n c o d e . This h a s t h e s a m e e f f e c t as t h e LEAVE TO TRANS-

ACTION s t a t e m e n t . M o s t o f t h e f u n c t i o n c o d e will h a v e t h e f u n c t i o n a l t y p e b l a n k

( ' ' ) . F i g u r e 1 2 . 8 d i sp l ays t h e f u n c t i o n c o d e a t t r i b u t e s c r e e n .

A f u n c t i o n can b e c r e a t e d w i t h s ta t ic t ex t s o r d y n a m i c tex ts . A s ta t ic t ex t is o n e

t ha t is spec i f i ed w h e n y o u d e s i g n t h e f u n c t i o n , w h e r e a s w i t h d y n a m i c tex t , a

p l a c e h o l d e r is u s e d t ha t wi l l b e p o p u l a t e d a t r u n t i m e . Fo r d y n a m i c t ex t s y o u

h a v e t o ass ign a field t o t h e f u n c t i o n , a n d t h e c o n t e n t s o f t h e field a r e d i s p l a y e d

as t h e m e n u tex t at r u n t i m e . You c a n ass ign a n i con (ICON NAME a t t r i b u t e ) t o t h e

f u n c t i o n if a f u n c t i o n has a s ta t ic t ex t . A n icon is d i s p l a y e d i n s t e a d of f u n c t i o n

tex t if t h e f u n c t i o n is a s s i g n e d t o t h e b u t t o n . T h e FUNCTION TEXT is d i s p l a y e d as

q u i c k i n f o tex t f o r t h e icon o r b u t t o n . T h e c o n t e n t s o f t h e INFO TEXT a t t r i b u t e a r e

d i s p l a y e d o n t h e s t a t u s b a r o f t h e s c r e e n w h e n t h e u s e r se lec t s t h e f u n c t i o n f o r

w h i c h th i s a t t r i b u t e is p o p u l a t e d . T h e b u t t o n d i sp l ays t h e icon a n d t h e c o n t e n t

Key Concepts Refresher C h a p t e r 12 355

of the I C O N TFXT if the ICON TEXT attribute is populated. The FAST PATH attribute can be populated by specifying a single letter, which is used to select a menu function without using the mouse.

FunttonCcx* SAVE FunttonalType Aj**C0O<*)FTF*»ON

Swnch Reacoc« Ml Mttftcabon Onpnei

Static Firttton Te>K FLTCOCO Tert S a * Icon Name ICON_SYStEM_SAVE y IccnTciJ Wo Te«t Faspam S Mo<*c»on

• x

Figure 12 .8 F u n c t i o n C o d e A t t r i b u t e S c r e e n

Figure 12.9 displays the function setting for the menu Item in the GUI status along with the FAST PATH attribute.

€ Other C*?»ct Sh«*F5 e q h m 0 0 ©a O w t y <-> Change Ctf'FI Pool SAPMZDEMO Actrve <-> nactrve Sftlt«F8 Pool SAPMZDEMO Ertv5nc« $f*.F4 £1 U ©C& Pr«r/Pnt"K Check •

M Acave

I' Activate CH-F3 « Tea • 10

« Pnr* Coi'P • Eaot SfWt«F3

r r a n i m Men Mo«<•><

AKfeoaiFtfK**

1 H < ( « M T M I TTAMLTM FCA* MCIV* K (fiNm» I M U J K I M J W L M «

»*> T«« frswr MIDKAM

C

Figure 12 .9 GUI S t a t u s w i t h F u n c t i o n C o d e A t t r i b u t e

356 Chapter 12 Classical Screens

The application toolbar contains buttons for the most frequently used functions specific to the application. The application toolbar can contain up to 35 buttons, or separators. The standard toolbar is the same for every screen in the SAP sys-tem. It contains a set of buttons with a fixed assignment of a function key, such as the SAVF and PRINT functions.

The button or the function is grayed out if the particular function is not available for the screen. This is controlled in the Menu Painter by making a function inac-tive. An example of a grayed out function is the SAVE icon (JB|) if the application has the functionality to only display the data and does not allow the user to change the data on the screen.

You can also assign function keys to functions. This allows the user to select the function code by using a function key rather than a menu entry or button. The function key assignment consists of reserved function keys, recommended func-tion keys, and freely assigned function keys.

• Reserved function keys are the ones whose assigned value cannot be changed and are assigned to functions on the standard toolbar. You can activate or deactivate their functions, even though you cannot change the function key assignment. These functions appear on the standard toolbar on screens and lists.

• Recommended function keys are just a proposal by the SAP system and com-ply with the SAP system ergonomic standards; that is, the same function is represented by this function key in other screens, and therefore users expect this function to be represented by the same function key in your screen also.

• Freely assigned function keys can be used for assigning a function key to any other function code.

+ T ip

You should always define function code type F for your dialog screen and code for those functions in the dialog module that called the PAI event block with the addition AT EX IT-COMMAND. This allows users to exit the screen by selecting the function code of type E., without entering the value on mandatory input fields on the screen. These function codes are the standard one such as BACK, CANCEL, and EXIT in most of the standard S A P transactions on the standard toolbar.

Key Concepts Refresher Chapter 12 357

Creating a GUI Status and GUI Title

You create the GUI status and GUI title in the Menu Painter or with the Reposi-tory Browser. The Menu Painter can be accessed directly from ABAP Workbench or via Transaction SE41. The GUI status and title are always program specific, so the program name is required to define the GUI status. You need to specify the program name, and the GUI status name can be up to 20 characters long.

Figure 12.10 displays the Menu Painter initial screen from the ABAP Work-bench. The first screen shows the menu path from the ABAP Workbench to start the Menu Painter, and the second screen is the initial screen of the Menu Painter. Figure 12.11 displays the Menu Painter interface.

Figure 12.10 Create GUI Status f rom ABAP Workbench

You create menus bar by clicking on the E X P A N D icon of the menu bar text field. You create functions for the menu by double-clicking on the menu header. For each menu you specify the functions, which consist of a function code and text and optionally submenus and separators. The submenus can be up to three levels deep. You can also define a fast path for each menu item. A menu can have up to 15 entries.

372 C h a p t e r 12 Classical Screens

JH' |nt*rr«« 6£IO.»wrtO.OWI.JTATUS ACl'.a tar * U IwwolraiiM of cut SlatM on Scrtan

ltr»t<oat Cl't 0MO I«trai

tcoHcaticn Toolbar " U D**0">trali0a of (Ml !«*(*« oa Icraaai

IUM 1 - J a i r a

wurr a

ijfcrji FirttttOA I

ictKi.re FlftCt'Ofl I

Itaai I • 14

Itaai It • 21

Itaai 22 • 2*

Itaai 2t • »

'urctioa Kara Itan«>r4 tool to

• C*so*ttr«(ioa> of GUI Stalvt oa Scrftt

tMK © e*:t © M:HT a

JIAttN • StAttN. »

•accaaaaM f«*li«i »» Saltiiijf-S£lE IWK etui t

Cnooaa >aia<* Oalata

F i g u r e 12.11 M e n u P a i n t e r I n t e r f a c e

Most functions should appear in the menus and on the application toolbar, because some users prefer menus and some prefer buttons. The application tool-bar can be created by clicking on the E X P A N D icon ( • . ) of the application toolbar text. Each application toolbar item can be assigned an icon, info text, and fast path, or you can include separators instead of a function.

You must assign a function key to most commonly used menu functions. The standard toolbar is generated by the system on its own and always includes the same functions. Items on the standard toolbar can be deactivated if not required, but the function key assignment and other attributes cannot be changed.

Similarly, you create the GUI title with the Menu Painter. The GUI title is also program specific and is represented by a code that can be up to 20 characters long. The title text itself can be up to 60 alphanumeric characters long. The title appears as the screen heading and can have up to nine variables that can be dynamically populated in the program. The GUI title can be translated. Figure 12.12 displays the interface for the GUI title definition.

N o t e

At r u n t i m e t h e va lue of t h e s c r e e n t i t le is s t o r e d in t h e s y s t e m va r i ab le SYST - T I L E .

Key Concepts Refresher Chapter 12 359

Program DEMO DYNPRO GUI STATUS Tide Code 100 Processing Status Original Last McxMication 00 00 00

Title Demonstration of User Irterfece

• AlttJe X

Figure 12.12 GUI Title Definition

Setting the GUI Status and the GUI Title

T h e GUI s t a t u s a n d GUI t i t le a r c a s s i g n e d t o t h e s c r e e n i n s i d e a d i a l o g m o d u l e

ca l l ed in t h e P B O e v e n t b l o c k . It is r e c o m m e n d e d t h a t y o u d e f i n e t h e GUI s t a t u s

a n d G U I t i t le f o r e a c h s c r e e n . If y o u h a v e n o t a s s i g n e d t h e G U I s t a t u s a n d GUI

t i t le f o r t h e s c r e e n , t h e n it i n h e r i t s t h e m f r o m t h e p r e v i o u s s c r e e n o f t h e t r a n s -

a c t i o n .

A s c r e e n c a n h a v e m o r e t h a n o n e GUI s t a t u s . F o r e x a m p l e , t h e GUI s t a t u s f o r d i s -

p l a y m o d e m i g h t b e d i f f e r e n t t h a n t h e GUI s t a t u s f o r e d i t o r c h a n g e m o d e . T h e r e -

f o r e , t h e G U I s t a t u s c a n b e a s s i g n e d d y n a m i c a l l y t o t h e s c r e e n . T h e GUI s t a t u s

a n d GUI t i t le a r e se t in t h e P B O e v e n t b l o c k b y u s i n g t h e s t a t e m e n t s SET PF

STATUS a n d SET TITLEBAR, r e s p e c t i v e l y , i n s i d e t h e d i a l o g m o d u l e w i t h t h e P B O

e v e n t b l o c k . You c a n a l s o d e f i n e b u t t o n s in y o u r s c r e e n a n d a s s ign t h e f u n c t i o n

c o d e a n d u s e it i n s t e a d o f f u n c t i o n c o d e s o r m e n u i t e m s d e f i n e d via t h e GUI s ta-

T h e s y n t a x t o a s s i g n t h e GUI s t a t u s a n d GUI t i t l e f o r t h e s c r e e n is s h o w n in List-

i n g 1 2 . 1 6 .

MOOULE i n i t _ s c r e e n _ 0 1 0 0 o u t p u t . IF SY-TCODE-TCOOE - 'ZCHANGE'

SET PF-STATUS 'STATUS. IOO' . SET TITLEBAR ' lOO* .

ELSEIF SY-TCODE - 'ZDISPLAY' . SET PF-STATUS •STATUS_200\ SET TITLEBAR ' 2 0 0 ' .

ENDIF. ENOMODULE.

Listing 12.16 Assignment of GUI Status and GUI Title in PBO M o d u l e

374 Chapter 12 Classical Screens

T h e syn tax to set a t i t le tha t c o n t a i n s va r i ab les is as fo l lows :

SET TITLEBAR XXX WITH <&]> . . . <&9>

w h e r e XXX is t h e t i t le n a m e a n d <&1> to <49> a r e va r i ab les f r o m 1 to 9 .

T h e GUI s t a tus m i g h t h a v e m a n y m e n u i t e m s a n d f u n c t i o n s , b u t these can b e dis-ab led o r d e a c t i v a t e d dynamica l l y in t h e PBO e v e n t b lock w i t h i n the d ia log m o d -ule. o r as w e h a v e d i scussed , t h e y can b e d e a c t i v a t e d in t h e M e n u Pa in te r a lso. T h e f u n c t i o n s can b e deac t iva t ed by us ing t h e EXCLUDING < f c o d e > a d d i t i o n w i t h t h e s t a t e m e n t SET PF - STATUS. < f c o d e > can b e h a r d - c o d e d , a var iab le , o r an in ter -nal t ab l e c o n t a i n i n g m a n y f u n c t i o n c o d e s . T h e in te rna l t ab le s h o u l d have all o f t h e f u n c t i o n s tha t have to b e deac t i va t ed . T h e syn tax to deac t iva t e t h e f u n c t i o n c o d e s o f t h e GUI s t a t u s is s h o w n in Listing 1 2 . 1 7 .

MODULE s t a t u s _ 0 1 0 0 o u t p u t . APPEND 'CHANGE' TO f c o d e . APPEND 'CHANGE' TO f c o d e . SET PF-STATUS 'STATUS_100' EXCLUOING f c o d e .

ENDMOOULE.

Listing 12.17 Example Code to Deactivate Function Code

You t h e n h a v e to d e f i n e t h e i n t e rna l t ab le f c o d e in t h e m a i n p r o g r a m . T h e syn tax

o f t h e i n t e rna l t ab le s h o u l d b e as fo l lows :

DATA f c o d e TYPE TABLE OF sy-ucomm.

T h e se lec t ion o f t h e f u n c t i o n c o d e o n t h e sc reen t r iggers t h e PAI e v e n t , a n d based o n t h e f u n c t i o n c o d e y o u can c o n t r o l t h e flow of t h e p r o g r a m . T h e f u n c t i o n c o d e is p l aced in t h e s y s t e m var iab le SY-UCOMM a n d in t h e 0K_C0DE field o f t h e s c r e e n , in t h e PAI e v e n t . If y o u h a v e d e f i n e d a va r iab le w i t h t h e s a m e n a m e as t h e OK t y p e s c r e e n field, t h e f u n c t i o n c o d e will au toma t i ca l ly b e cop i ed a n d can the re -fo r e b e eva lua t ed in t h e ABAP c o d e . List ing 1 2 . 1 8 s h o w s an e x a m p l e c o d e f o r p r o c e s s i n g t h e f u n c t i o n c o d e in the PAI e v e n t b lock.

PROCESS AFTER INPUT

MODULE USER_COMMAND_9001. MODULE user_command_9001 INPUT.

save_ok - o k _ c o d e . CLEAR ok_code .

CASE s a v e _ o k . WHEN 'BACK-

SET SCREEN 9000 .

Key Concepts Refresher Chapter 12 361

WHEN ' E X I T ' o r • C A N C E L * . LEAVE PROGRAM.

WHEN OTHERS, o u t p u t - s a v e _ o k .

ENOCASE. ENDMODULE.

Listing 12.18 Code to Control Program Flow for Individual Function Code

Table Control Programming

A tab le c o n t r o l is an a rea o n t h e sc reen tha t is u s e d to d i sp lay o r e n t e r da ta in a t abu l a r f o r m . A tab le con t ro l has a t ab le h e a d e r , c o l u m n h e a d e r s , a n d c o l u m n s . At r u n t i m e , a t ab le c o n t r o l p r o v i d e s the f u n c t i o n a l i t y o f ver t ical a n d ho r i zon t a l scrol l ing, c o l u m n w i d t h a d j u s t m e n t , r o w a n d c o l u m n se lec t ion , a n d t h e abi l i ty to c h a n g e the pos i t i ons o f c o l u m n s . F igure 1 2 . 1 3 d i sp lays t h e v a r i o u s tab le con-t rol c o m p o n e n t s .

Table Line

Se lect ion C o l u m n

T i t l e Bar

Ftgrci

H e a d e r l i n e C o l u m n H e a d i n g

O Ptgrt QtMrtdly YORK

FRANCISCO

Amvrtcny

SAN FRANCISCO NEW YORK

z 555 ROME FRANKFURT

z 788 ROME TOKYO 1 .'89 TOKYO ROME 1 790 ROME OSAKA

cx 106 NEv YORK FRANKFURT

DL 1699 NEW YORK SAN FRANCISCO

DC 1984 SAN FRANCISCO NEW YORK X 407 TOKYO FRANKFURT

2- S e t t i n g B u t t o n

Ver t i ca l Scrol lbar

Hor i zon ta l Scrol lbar Leading Fixed C o l u m n

Figure 12.13 Components of Table Control

To d e f i n e a t ab le c o n t r o l y o u h a v e to d e f i n e t h e tab le c o n t r o l area , t h e t ab le con-t rol e l e m e n t s , a n d the table t i t le f o r t h e tab le c o n t r o l . All th is is d e f i n e d w i t h i n t h e Screen Pa in te r . You a lso n e e d to d e c l a r e t h e tab le c o n t r o l in t h e p r o g r a m . T h e TABLE CONTROL icon is se lec ted f r o m t h e e l e m e n t pal le t o f t h e Screen Pa in t e r to c r ea t e t h e tab le c o n t r o l a rea . Table c o l u m n s f o r t h e c o n t r o l can b e c rea t ed f r o m ABAP D i c t i o n a i y f ie lds o r p r o g r a m f ie lds . C o l u m n h e a d i n g s can b e t h e ABAP Dic-t i o n a r y text assoc ia ted w i t h t h e f ield o r can b e c u s t o m text d e f i n e d w i t h a t ex t f ield o n t h e s c r een . T h e a t t r i b u t e s o f t h e tab le c o n t r o l a n d t h e tab le c o l u m n s also h a v e to b e m a i n t a i n e d , as d o a n y o t h e r e l e m e n t s o n t h e s c r een .

362 Chapter 12 Classical Screens

You can use the Table Control Wizard to create a table control quickly. This allows you to automatically create the table control, assign ABAP Dictionary or program fields for the columns, assign the attributes for the table columns, create some of the screen flow logic, generate the relevant PBO and PAI modules for the table maintenance, and generate the data definitions for the table control in the ABAP program. Table 12.3 displays the table control attributes you will spec-ify on the Screen Painter during screen design.

A t t r i b u t e Descr ip t ion and Use

TAB T IT IE Indicates w h e t h e r table control should have title or no t .

W / C O L H E A D S Allows you t o c rea te co lumn headings for t he table control .

C O N F I G B L Allows t he user to save t he table control set t ings a t run t ime.

RESIZING Indicates tha t t he table suppor t s vertical and horizontal sizing. You set this a t t r ibu te i fyou w a n t t he table size to change with the GUI w i n d o w size.

SEPARATORS You can specify w h e t h e r you w a n t to have vertical and horizontal separa tors for t he table co lumns and lines.

LINE SEL. Allows t he user to select lines. You have t he opt ion of NONE. SINGLE, and MULTIPLE line selection for this a t t r ibu te .

C O L U M N Allows column selection. Choose NONE, SINGLE, or MULTIPLE.

W / S E L . C O L U M N Specifies w h e t h e r a line selection column should appear for t he table control . You have to specify t he n a m e of this column if you w a n t to have t he line selection co lumn.

F IXED C O L U M N Excludes o n e or more columns f rom horizontal scrolling.

Table 12.3 Table Control At t r ibutes

The syntax for the table control in the program is as follows:

CONTROLS f l i g h t s TYPE TABLEVIEW USING SCREEN 100

The table control name is f 1 ights, and it is created on screen number 100. The table control name in an ABAP program should be identical to the table control created on the screen.

Key Concepts Refresher Chapter 12 363

Screen Flow Logic for Table Control

When you process table controls, y o u must use the I OOP . . . EN0L00P s ta tement in the PBO and PAI event blocks in the screen f low logic. This s ta tement is required for each table control on y o u r screen. It is required to copy the data back and forth f rom the ABAP program to the table control fields and vice-versa.

The LOOP is required because the table control consists of several rows. You can also use the LOOP AT <INTERNAL_Table> . . . ENDLOOP s ta tement in the screen f low logic. This form of the LOOP s ta tement loops through the screen table and the internal table in parallel. Using this form of the loop s ta tement , the system trans-fers the internal table rows to the screen fields and vice versa. Figure 12.14 dis-plays the screen flow logic wi thout an internal table, and Figure 12.15 displays screen flow logic with an internal table.

S c r w i n u m W r 1 0 0 A c 0 * »

A B n b u t e s E « « T » n t l s P l o w logic

I I I Ml J . I f r ' p r o c e s s b e f o r e o u t p u t

n o d u l e s t a t u s _ 0 1 0 0 l o o p w i t h c o n t r o l f l i g h t s

• o d u l e f i l l _ t a b l * _ c o n t r o l o n d l o o p

p r o c e s s a f t e r i n p u t n o d u l e c a n c e l a t e x i t - c o n n a n d l o o p w i t h c o n t r o l f l i g h t s

n o d u l e r e a d _ t a b l e _ c o n t r o l e n d l o o p • o d u l e u s e r _ c o n n a n d _ 0 l 0 0

Figure 12.14 Flow Logic without Internal Table

S a w n r u i r t o r 1 0 0 Acsvo

A f l n t a » t B o m e t t t H t Ffcxv logic

_JU ool J »

p r o c o s s o o f o r ® o u t p u t • o d u l e i t a t u s _ 0 1 0 0

l o o p a t i t a b i n t o d e « o _ c o n n w i t h c o n t r o l f l i g h t s • n d l o o p

p r o c o s s o f t « r i n p u t • c d u l e c a n c e l a t e x i t - c o « n a n < J l o o p a t i t a o

n o d u l e r e a d _ t a b l e _ c o n t r o l e n d l o o p • o d u l o u i » r _ c o M a r x S _ 0 i 0 0

Figure 12.15 Flow Logic with Internal Table

378 Chapter 12 Classical Screens

T h e t a b l e c o n t r o l m u s t b e d e c l a r e d in t h e A B A P p r o g r a m f o r e a c h t a b l e c o n t r o l

d e f i n e d o n t h e s c r e e n . T h e c o n t r o l f l I g h t s is t h e n a m e o f t h e t a b l e c o n t r o l o n

t h e s c r e e n . T h i s s t a t e m e n t d e c l a r e s a d e e p s t r u c t u r e f o r t h e t a b l e c o n t r o l f 1 i g h t s

a n d is u s e d t o r e a d t h e t a b l e a t t r i b u t e s in t h e A B A P p r o g r a m . T h e d a t a t y p e o f

t h e d e e p s t r u c t u r e c o r r e s p o n d s to t h e t y p e C X T A 8 _ C 0 N T R 0 L d e f i n e d in t h e A B A P

D i c t i o n a r y t y p e g r o u p C X T A B .

T h e s t r u c t u r e C X T A B _ C 0 N T R 0 L is t y p e S C X T A 8 _ C 0 N T R 0 L a n d c o n t a i n s c o m p o n e n t s

t h a t r e p r e s e n t t h e a t t r i b u t e s o f t h e t a b l e c o n t r o l . T h e c o m p o n e n t C X T A B _ C O L U M N

is a t a b l e o f t y p e S C X T A B _ C O L U M N a n d c o n t a i n s t h e a t t r i b u t e s o f t h e c o l u m n s o f

t h e t a b l e c o n t r o l . I n t e r n a l t a b l e C X T A B _ C O L U M N is a c o m p o n e n t o f t h e s t r u c t u r e

C X T A B _ C 0 N T R 0 L .

F i g u r e 1 2 . 1 6 d i s p l a y s t h e s t r u c t u r e C X T A B _ C 0 N T R 0 L , a n d F i g u r e 1 2 . 1 7 d i s p l a y s

t h e s t r u c t u r e C X T A B . C O L U M N .

Structure SCXTAB.CONTROL Active

Short Descnp«>c«i TPOA Tabte Control Seangs = C X T A B _ C O N T R O L

Attntxr.es Components Ertry hep/check I CurrencvVquantity fields

. G S U I 9 * N > 1 / 1 3

Component RTy Component type Length Decima Short Descnpoon : I X E P M L S INT4 10 0 Number ot Fixed Columns

I I N E S INT4 1 0 0 Number ol Lines to Be C»sp'ayed TQP LINE INT4 10 OTop Line for Next Pictire Output PBO CURRENT LINE INT4 10 0 Current Line in LOOP Processing .6FT .C0V INT4 10 0 First ScrolaNe C < * r m After the Fixed Area

LINE SSL "CPE INT4 10 0 Line Selection None<0). Single* 1)

r Q L . S E l J I Q K INT4 10 0 column Selection Mufcpte(2) - INE SELECTOR CHAR 1 0 Indicator Vsith Une Setertcn Cof / SCRQLL CHAR 1 0 not used

i_GRID CHAR 1 0 Incfccaeor "Horizontal Gnd Lines" V (JRIP CHAR 1 0 indicator "Vertrvel Gnd Lines:

;0LS 5CXTAP.C9LV1N.JT US 0 OTaWeControl Column Tabto INV IS IBLE CHAR 1 0

-

Figure 12.16 Table Control Structure

T h e a b i l i t y t o sc ro l l u s i n g a sc ro l l b a r is a u t o m a t i c a l l y i m p l e m e n t e d a n d m a n a g e d

b y t h e s y s t e m . T h e c o n t r o l f l i g h t s -1 i n e s s h o u l d b e se t t o t h e n u m b e r o f l i n e s

in t h e i n t e r n a l t a b l e b e f o r e y o u e d i t t h e t a b l e c o n t r o l . You c a n eas i ly i m p l e m e n t

t h e c o d i n g f o r s c r o l l i n g t h e t a b l e c o n t r o l s u c h as p a g e u p , p a g e d o w n , o r g o t o

p a g e n o . b y u s i n g t h e t a b l e c o n t r o l a t t r i b u t e s .

Key Concepts Refresher Chapter 12 379

Stwcair» SCXTA8_C0tUMN Ac9v» Short Tat«Cof»ol Colrw Sxbnji

Asntaos Ccmpoo^tr, Erevh»to<cf>o<k Cirr«ncyauarovil«k)5

id « s y • * i l 1_/ 5 RTy Ceopenorttypo Oota Typo • longr. Deomo Short Doscnpacn

SCREEN au 0 OS3\KtJ"0 DfrKnceco !of tr» Sylttm Data 00>»<t SCREEN INT4 10 0 Pou&on ct Cc*jrm VWin Tab* Cortrd CHAR 1 O'Ccirm Se»cct etf Mcatoc

VISLEN6TM ICMEWTH INT1 5 Okon Output tongBi INVISIBLE CHAR 1 0'

Figure 12.17 Structure of the Table Control Column

Figure 12 .18 displays the use of the table control a t t r ibute to implemen t page up and page d o w n funct ional i ty for scrolling the table control .

•odule read_table_control input lines • sy-loopc nodify i tab fron do«o_conn index flights-currontjlm©

endnodule

•odul© us©r_co««and_0100 input save_ok « ok_code clear ok_code case save_ok

when "NEXT_LINE' flight$-top_lino - flight$-top_lmo • 1 11ait • f i l l - lines • 1. if f1ights-top_line > l i m t

flights-top_line • l i a i t endi f

whon 'PREV_IINE' fl ights-top_1i ne • flights-top_line - 1 if flights-top_line < 0

f l ights- topjm© - 0 endi f

when 'NEXT_PAGE' flights-top_line - flights-top_line • lines l i m t • fi 11 - lines « 1 if flight$-top_lino > Unit

flights-top_line • l i a i t endi f

when 'PREV_PAGE' flights-top_line • flights-top_line - lines if flights-top_line < 0

flights-top_line • 0 endi f

whon 'IAST_PAGE' flights-top_line • f i l l - lines • 1

when 'FIRST_PAGE' flights-top_line • 0

endcase ondnodul®

Figure 12.18 Implement Scroll Functionality with Table Control Attribute

366 Chapter 12 Classical Screens

Tip

See the d e m o programs deroo_dynpro_tabcont_loop and demo_dynpro_tabcont_ loop_at in t he SAP system for t h e implementa t ion of table control .

Modifying Screens Dynamically

You n o r m a l l y se t t h e a t t r i b u t e o f t h e s c r e e n e l e m e n t in t h e S c r e e n P a i n t e r , b u t it

is a l so p o s s i b l e t o o v e r r i d e t h e s c r e e n a t t r i b u t e in t h e A B A P p r o g r a m w i t h t h e

s y s t e m t a b l e SCREEN. SCREEN is a n i n t e r n a l t a b l e w i t h t h e h e a d e r l i ne , a n d y o u d o

n o t n e e d t o d e c l a r e t h i s in t h e p r o g r a m . You c a n n o t s e e t h i s t a b l e in t h e D e b u g -

g e r , a n d y o u c a n o n l y a c c e s s it t h r o u g h its h e a d e r l i ne . T a b l e 1 2 . 4 d i s p l a y s t h e

s t r u c t u r e o f t h e SCREEN t a b l e .

C o m p o n e n t Length Type M e a n i n g

NAME 132 C Name of t he screen field

GR0UP1 3 C Modif icat ion g r o u p 1

GROUP? 3 C Modif icat ion g roup 2

GR0UP3 3 C Modif icat ion g roup 3

GR0UP4 3 C Modif icat ion g roup 4

REQUIRED 1 C Field input is manda tory

INPUT 1 C Field is ready for input

OUTPUT 1 C Field is ready for o u t p u t

INTENSIED 1 C Field is highlighted

INVISIBLE 1 C Field is suppressed

LENGTH 1 X Field length

ACTIVE 1 C Field is active

DISPLAY_3D 1 C Three-dimensional box

VALUE_HELP 1 C Input help bu t ton display

REQUEST 1 C Input exists

Table 12.4 Screen Table Structure

Key Concepts Refresher Chapter 12 12

You c a n m o d i f y t h e a t t r i b u t e o f t h e s c r e e n e l e m e n t in a n A B A P p r o g r a m d u r i n g

t h e P B O e v e n t b l o c k . You h a v e a n e n t i y f o r e a c h s c r e e n e l e m e n t in t h e s y s t e m

i n t e r n a l t a b l e SCREEN. You o v e r r i d e t h e s t a t i c s c r e e n a t t r i b u t e b y m o d i f y i n g t h e

s c r e e n a t t r i b u t e in t h e PBO e v e n t b l o c k . Lis t ing 1 2 . 1 9 s h o w s t h e e x a m p l e c o d e

t o m o d i f y t h e s c r e e n a t t r i b u t e in t h e A B A P p r o g r a m .

PROCESS BEFORE OUTPUT. MOOULE modi f y _ s t a t u s _ 9 0 0 1 . MOOULE modi f y _ s t a t u s _ 9 0 0 1 OUTPUT. LOOP AT SCREEN.

IF SCREEN-GR0UP1 - ' G U I ' SCREEN-INPUT - '0'.

ELSE 1F SCREEN-GR0UP1 - ' G R 2 ' . SCREEN-REQU1RE0 - ' 1 ' .

ELSE IF SCREEN GR0UP1 - ' G R 3 ' . SCREEN-ACTIVE - ' 0 ' .

ENOIF. ENDLOOP. ENOMODULE.

Listing 12.19 Example Code to Modify Screen Att r ibute Dynamically in Program

Creating a Module Pool Program

S c r e e n s c a n b e c r e a t e d f o r a n e x e c u t a b l e p r o g r a m s , f u n c t i o n g r o u p s , a n d m o d u l e

p o o l s . Y o u c a n s t a r t a s c r e e n in a n e x e c u t a b l e p r o g r a m a n d f u n c t i o n g r o u p u s i n g

t h e CALL SCREEN s t a t e m e n t , b u t s c r e e n s in m o d u l e p o o l s c a n o n l y b e a d d r e s s e d

u s i n g d i a l o g t r a n s a c t i o n s . In t h i s s e c t i o n w e wi l l d i s c u s s t h e s t e p s t o c r e a t e a m o d -

u l e p o o l p r o g r a m , a s f o l l o w s :

1 . C r e a t e a m o d u l e p o o l p r o g r a m in t h e A B A P W o r k b e n c h .

2 . C r e a t e s c r e e n s f o r t h e m o d u l e p o o l p r o g r a m .

3 . C r e a t e t h e f l o w f o r t h e s c r e e n in t h e P B O a n d PAI e v e n t b l o c k s a n d o p t i o n a l l y

in t h e P O H o r P O V e v e n t b l o c k s if r e q u i r e d .

4 . C r e a t e P B O a n d PAI m o d u l e s as p r o c e s s i n g b l o c k s f o r t h e c o r r e s p o n d i n g

e v e n t .

5 . C r e a t e t h e G U I s t a t u s to e v a l u a t e u s e r a c t i o n s .

6 . C r e a t e t h e G U I t i t le .

7 . C r e a t e t h e d i a l o g t r a n s a c t i o n .

368 Chapter 12 Classical Screens

The program name for the module pool program should start with SAPMZ and then any meaningful name. For our example we will use the name SAPMZDEMO. You create the module pool program in the ABAP Workbench, and it proposes the top include module. You should select the proposal and continue. The top include module name for the above module pool program proposed by system is M Z D E M O T O P .

After creating the module pool program, you can create new program objects such as screens. GUI status, and GUI titles for your program from the context menu in the object navigation area. Figure 1 2 . 1 9 displays the context menu (CREATE • P R O -

GRAM) used to create the program objects from the object navigation area.

Program

I S A P M Z D E M 1

M Object Name

• f f f K ^ - M y -t UFiekJs t UPBOMCOufcS t u PAI Modules " <3 Screens

9001 9002 9003

* a Incudes MZDEMOIOI M Z D E M 0 0 0 1 MZDEMOTOP

V a <85 a : <2 a i _ Descnp

Create Change Display

Check Activate Execute Copy Rename

Where-Used List Find

Qther Functions

Program Subroutine PBO Module PAI Module Screen GUI Status GUI TOes Include Transaction Van ant

Class (Definition) Class (Implemerta&on) Interface

Figure 12.19 Con tex t M e n u t o Crea te Program O b j e c t s

You then create the screen, screen flow logic, GUI status, and GUI title for the program, followed by the dialog module in the ABAP program. You can create the dialog module by forward navigation from the screen flow logic. The system will propose the include name for the PBO and PAI event modules. The standard name proposed by the system for the above program would be MZDEM0001 for PBO modules and MZDEMOIOI for PAI modules, but you can create your own name and create a separate include for each module if you want (however, it's not recommended).

The forward navigation (by double-clicking on the module name in the screen flow logic) creates an empty module in the include program for each module

Important Terminology Chapter 11

d e f i n e d in t h e flow logic. It is y o u r task to w r i t e t h e c o d e w i t h i n t h e e m p t y m o d -ules u s ing ABAP l anguage s t a t e m e n t s . You a lso n e e d to dec la re the g lobal vari-able in t h e t o p inc lude p r o g r a m , ZDEMOTOP. This inc ludes t h e dec l a r a t i on o f t h e tab le s t r u c t u r e used to c r ea t e t h e sc reen f ie lds o r t h e u s e r - d e f i n e d sc reen e l e m e n t u s e d to c rea te t h e sc reen f ie lds . Do ing this e n s u r e s tha t t h e s c r e e n c o n t e n t is cop-ied to t h e ABAP area w i t h the m a t c h i n g f ield n a m e s .

Finally, y o u c r e a t e t h e d ia log t r ansac t i on f o r t h e m o d u l e pool p r o g r a m , w h e r e b y ,

at t h e mos t , y o u h a v e to spec i fy t h e m o d u l e pool p r o g r a m , t r ansac t i on text , a n d

start s c reen fo r t h e t r a n s a c t i o n .

Important Terminology

You will n e e d to u n d e r s t a n d t h e d i f f e r e n c e b e t w e e n t h e d ia log s c r e e n a n d t h e se lec t ion s c r een . T h e se lec t ion sc reen fo r the e x e c u t a b l e p r o g r a m is cal led a n d con t ro l l ed b y t h e ABAP r u n t i m e . W i t h t h e d ia log sc reen y o u can c o n t r o l t h e sc reen flow, a n d y o u h a v e to w r i t e t h e sc reen flow logic.

You c a n n o t u s e t h e ABAP s t a t e m e n t in the sc reen flow logic. In t h e sc reen flow

l o g i c y o u call t h e d ia log m o d u l e , a n d w i t h i n t h e d ia log m o d u l e y o u can use ABAP

s t a t e m e n t s .

T h e r e a r e f o u r e v e n t b locks in t h e d ia log sc reen : PBO, PAI. POV, a n d POH. T h e c o d e w i t h i n t h e PBO e v e n t b lock is e x e c u t e d b e f o r e t h e sc reen is d i sp l ayed , a n d t h e c o d e w i t h i n t h e PAI block is t r igge red w h e n t h e u s e r p e r f o r m s an ac t ion o n t h e sc reen such as se lec t ing t h e m e n u i t em, cl icking o n t h e b u t t o n o n t h e sc reen , p r e s s ing f ^ H , o r se lec t ing a f u n c t i o n o n a s c r een .

T h e GUI s t a tus is u s e d to set t h e s t a tus o f t h e sc reen tha t is u s e d to d i sp lay t h e m e n u bar , m e n u i t em, t oo lba r , a n d app l i ca t ion bar . T h e GUI t i t le is u s e d to assign t h e h e a d i n g to t h e s c r een . Finally, it is i m p o r t a n t to r e m e m b e r tha t t h e m o d u l e poo l p r o g r a m can o n l y b e accessed b y the t r ansac t ion code .

% Practice Questions

T h e p rac t i ce q u e s t i o n s b e l o w wil l h e l p y o u eva lua t e y o u r u n d e r s t a n d i n g o f t h e top ic . T h e q u e s t i o n s s h o w n a r e s imi la r in n a t u r e to t h o s e f o u n d o n t h e cer t i f ica-t ion e x a m i n a t i o n , b u t w h e r e a s n o n e o f t h e s e q u e s t i o n s wil l b e f o u n d o n t h e e x a m itself, t h e y a l l o w y o u to r e v i e w y o u r k n o w l e d g e o f t h e sub jec t . Select t h e

370 Chapter 12 Classical Screens

c o r r e c t a n s w e r s a n d t h e n c h e c k t h e c o m p l e t e n e s s o f y o u r a n s w e r s in t h e f o l l o w -

ing s o l u t i o n s e c t i o n . R e m e m b e r t h a t y o u m u s t se l ec t all c o r r e c t a n s w e r s a n d o n l y

c o r r e c t a n s w e r s t o r e c e i v e c r e d i t f o r t h e q u e s t i o n .

1 . W h i c h o f t h e f o l l o w i n g is c o r r e c t :

• A. T h e s c r e e n a t t r i b u t e s c a n b e m o d i f i e d in t h e PROCESS AFTER INPUT e v e n t

b l o c k .

• B. T h e s c r e e n a t t r i b u t e s c a n b e m o d i f i e d in t h e PROCESS BEFORE OUTPUT e v e n t

b l o c k .

• C. T h e s c r e e n a t t r i b u t e s c a n b e m o d i f i e d in t h e PROCESS BEFORE OUTPUT a n d

PROCESS AFTER INPUT e v e n t b l o c k s .

• D . N o n e o f t h e a b o v e

2 . T h e s ta t ic s e q u e n c e o f t h e d e f a u l t n e x t s c r e e n c a n b e e s t a b l i s h e d b y t h e v a l u e

in t h e s c r e e n a t t r i b u t e " n e x t s c r e e n . "

• A. T r u e

• B. Fa l se

3 . If y o u e n t e r t h e v a l u e "0" o r b l a n k ( " " ) a s t h e n e x t s c r e e n , t h e n t h e s y s t e m

r e s u m e s p r o c e s s i n g f r o m t h e p o i n t a t w h i c h t h e s c r e e n w a s i n i t i a t e d , a s s u m -

ing t h e n e x t s c r e e n a t t r i b u t e is o v e r r i d d e n d y n a m i c a l l y in t h e p r o g r a m .

• A. T r u e

• B. False

4 . T h e n e x t s c r e e n a t t r i b u t e c a n b e t e m p o r a r i l y o v e r w r i t t e n b y t h e se t s c r e e n

s t a t e m e n t , t h a t is, SET SCREEN 200 .

• A. T r u e

• B. False

5 . T h e FI ELD s t a t e m e n t d o e s n o t h a v e a n y e f f e c t in t h e P B O e v e n t b l o c k , a n d it

s h o u l d n o t b e u s e d in t h e P B O e v e n t b l o c k .

• A. T r u e

• B. False

Practice Questions Chapter 12

6. The FIELD statement with the ON I NPUT addition is used to conditionally call the ABAP dialog module. The ABAP dialog module is called if the value of the screen field is other than the initial value.

• A. True

• B. False

7 . The F I E L O statement with the O N R E Q U E S T addition calls the ABAP dialog module if any value is entered in the screen field.

• A. True

• B. False

8 . You can call a module for the F I E LD statement to validate user entiy on the input field. You can validate the entry on the input field and send an error or a warning message from an ABAP dialog module.

• A. True

• B. False

9. If an error or warning message is sent from the ABAP dialog module for the FIELO statement within the CHAIN and ENOCHAIN statements, then all of the fields within CHAIN and ENOCHAIN arc ready for user input again.

• A. True

• B. False

10. The user interface consists of the GUI status and GUI title.

• A. True

• B. False

11. A menu bar can have at most 10 menus.

• A. True

• B. False

12. The application toolbar can have up to _ buttons on the screen.

• A. 20

• B. 30

372 Chapter 12 Classical Screens

• C. 10

• D. 35

• E. None of the above

13. A menu can have up to _ menu items on the screen including functions, separators, and submenus.

• A. 15

• B. 10

• C. 15

• D. None of the above

Practice Q u e s t i o n Answers and Explanat ions

1. Correct answer: B

The screen attributes can be modified in the P R O C E S S B E F O R E O U T P U T event block.

2. Correct answer: A

The screen sequence can be determined from the content of the next screen attribute field, but it can be overridden.

3. Correct answer: A

If the next screen attribute is not specified, then the system will resume pro-cessing from the point at which the screen was initiated. Basically, a next screen of 0/space terminates the screen sequence. This may result in the user exiting the application.

4. Correct answer: A

The next screen attribute can be overwritten temporarily by using the SET S C R E E N statement.

5. Correct answer: A

The F I E L O statement is used in conjunction with the module statement in the PAI event block to validate user input or to delay the transport of a field value from the screen to the ABAP program. The ABAP dialog module is called only if the value of the field is changed depending on whether the addition ON I N P U T or O N R E Q U E S T is used.

Take Away Chapter 12

6. Correct a n s w e r : A

The FIELD s t a t emen t used in c o n j u n c t i o n wi th t h e m o d u l e s t a t emen t wi th the ON INPUT add i t ion is used to condi t iona l ly execu te the ABAP dialog m o d -ule if t he inpu t value of t h e field is o t h e r than the initial value accord ing to the data TYPE o f the inpu t f ield.

7. Correct a n s w e r : A

The ON REQUEST add i t ion fo r the Fl ELD s t a t e m e n t calls t h e ABAP dialog mod -u l e o n l y if a value is e n t e r e d in the screen field.

8. Correct a n s w e r : A

You call a m o d u l e fo r the FIELD s t a t e m e n t to val idate u s e r e n t i y o n the inpu t f ield. The e n t i y on the i npu t field associated wi th the FI ELD s t a t emen t is val-idated wi th the dia log m o d u l e , and accordingly, y o u can send an e r r o r o r w a r n i n g message. T h e inpu t field is ready fo r re - input if t he dialog m o d u l e s e n d s an e r r o r o r w a r n i n g message fo r the user inpu t on the screen field.

9. Correct a n s w e r : A

If an ABAP dialog m o d u l e called wi th the F I ELD s t a t e m e n t w i th in C H A I N and ENOCHAIN s e n d s an e r r o r o r w a r n i n g message , then all o f the fields w i th in the CHAIN and ENOCHAIN a r e r eady fo r use r i npu t .

10. Correct a n s w e r : A

The use r in te r face fo r a screen consists of the GUI s ta tus and the GUI title.

11. Correct a n s w e r : B

The m e n u ba r can have u p to eight m e n u s inc lud ing the sys tem and he lp m e n u , w h i c h m e a n s six can be d e f i n e d by the deve lope r .

12 . Correct a n s w e r : D

The appl ica t ion too lbar can have u p to 35 b u t t o n s p e r screen .

13. Correct a n s w e r : A

A m e n u can have u p to 15 en t r ies inc luding func t ions , separa tors , and sub-m e n u s .

Take A w a y

You shou ld be able to desc r ibe the s teps r equ i r ed t o wr i t e a dia log t ransac t ion .

You need to crea te screens , des ign the sc reen layout , c rea te screen flow logic, and

wr i t e an ABAP p r o g r a m fo r dia log p r o g r a m m i n g . You also need to crea te a GUI

374 Chapter 12 Classical Screens

s t a t u s a n d G U I t i t l e a n d a s s i g n t h e m t o e a c h s c r e e n . T h i s d i s p l a y s t h e m e n u b a r ,

m e n u i t e m s , a n d o p t i o n a l l y , t h e a p p l i c a t i o n t o o l b a r if it h a s b e e n d e f i n e d in t h e

G U I s t a t u s . Y o u s h o u l d b e a b l e t o c o d e t h e PROCESS BEFORE OUTPUT. PROCESS

AFTER INPUT, PROCESS ON HELP-REQUEST, a n d PROCESS ON VALUE-REQUEST e v e n t

b l o c k s a n d s h o u l d b e a w a r e o f t h e s c r e e n / d y n p r o k e y w o r d s t h a t c a n b e u s e d in

s c r e e n flow log ic .

Refresher

T a b l e 1 2 . 5 s h o w s t h e k e y c o n c e p t s f o r d i a l o g p r o g r a m m i n g .

Key C o n c e p t

Dialog screen

Dialog screen even ts

GUI s ta tus

PROCESS ON HELP-

REOUEST

PROCESS ON VALUE -

REQUEST

Def in i t ion

A dialog screen is des igned wi th the Screen Painter . You

set t h e genera l screen a t t r ibu tes o n the a t t r i bu t e screen,

design t h e screen layout, set t h e field a t t r ibu tes in t h e

e l e m e n t list, and wri te t h e f low logic in the f low logic edi-

tor . These s teps are required for each screen .

For each dialog screen you can have up t o four e v e n t

blocks: PROCESS BEFORE OUTPUT, PROCESS AFTER INPUT.

PROCESS ON HELP REQUEST,and PROCESS ON VALUE

REQUEST. You can wri te c o d e for t he se four even t s for a

dialog screen . The PBO and PAI even t blocks are

required, w h e r e a s t h e o t h e r two, tha t is, POH and POV,

are op t iona l .

A GUI s ta tus is c rea ted wi th t h e M e n u Painter and is

required for any screen . GUI s ta tus is ass igned t o the

screen t o de f ine the m e n u bar. m e n u items, appl ica t ion

toolbar , and so on .

You can wri te your o w n F1 help for screen fields. F1 help

for a screen field is c o d e d in t h e PROCESS ON HELP REOUEST

even t block.

You can wri te your o w n cus tom value help (F4 help) for

screen fields in t h e PROCESS ON VALUE REQUEST even t

block.

Table 12.5 Key Concep ts Refresher

Summary Chapter 13 12

Summary

We have covered screen design, various at tr ibutes of the screen, and the screen elements . We have also covered in detail the screen events PBO. PAI, POH, and POV and discussed h o w the data is t ransferred f rom the screen area to the ABAP program and vice versa. We have covered in detail the use of the GUI status and GUI title for dialog programming and the M e n u Painter tool to design the GUI status. Finally, w e have discussed how to assign a GUI status and title to the screen. This knowledge will allow y o u to easily pass this topic on the certification examinat ion.

Selection Screens

T e c h n i q u e s Y o u ' l l M a s t e r :

• Explain t h e p u r p o s e o f se lec t ion s c r e e n s

• Design a se lec t ion sc reen

• Crea te i n p u t f ie lds w i t h p a r a m e t e r s a n d s e l e c t - o p t i o n s

• D e f i n e se lec t ion s c r e e n s w i t h t abs t r ip c o n t r o l

• D e f i n e t h e se lec t ion sc reen e v e n t s a n d t h e i r p r o c e s s i n g

• I m p l e m e n t i n p u t checks o n se lec t ion s c r e e n s

378 Chapter 13 Selection Screens

Select ion s c r e e n s a r c u s e d to p r o v i d e t h e use r a n in t e r f ace to s u p p l y s t a r t ing va lue f o r a r e p o r t . T h e se lec t ion sc reen can b e d e f i n e d us ing ABAP language dec la ra t ive s t a t e m e n t s . You can d e f i n e se lec t ion s c r e e n s fo r e x e c u t a b l e r e p o r t s a n d can c o n t r o l t h e p r o g r a m flow based o n t h e u s e r i n p u t .

In th is c h a p t e r y o u will learn a b o u t se lec t ion s c r e e n s a n d t h e i r use in ABAP pro-g r a m m i n g . You wil l learn h o w to c r ea t e se lec t ion s c r e e n s u s ing p a r a m e t e r s a n d s e l e c t o p t i o n s . You will l ea rn to d e s i g n t h e s c r e e n l ayou t us ing s i m p l e ABAP s t a t e m e n t s . You will a lso l ea rn a b o u t t h e v a r i o u s se lec t ion sc reen e v e n t s a n d se lec t ion sc reen p r o c e s s i n g w i t h i n ABAP p r o g r a m s . Finally, y o u wil l learn to cre-a t e t abs t r ip c o n t r o l se lec t ion s c r eens .

R e a l - W o r l d S c e n a r i o

You have to w r i t e a use r - f r i end ly repor t wi th selection screen , w h i c h a l lows use r to e n t e r da ta o n the screen to control p r o g r a m f low. T h e r epo r t shou ld expec t i npu t f r o m the user , a n d based o n th is i npu t t h e data shou ld b e ex-tracted f r o m the da tabase fo r process ing . T h e p r o g r a m flow a n d t h e list dis-play shou ld b e based o n the use r i npu t o n t h e select ion screen . You need to coo rd ina t e wi th the bus iness a n d ga the r bus iness r e q u i r e m e n t s fo r the repor t .

To w r i t e a u se r - f r i end ly r e p o r t y o u n e e d to have a g o o d u n d e r s t a n d i n g o f t h e se lec t ion sc reen a n d the v a r i o u s p r o g r a m e v e n t s fo r t h e se lect ion sc reen . You a lso h a v e to e d u c a t e the d e v e l o p m e n t t e am a b o u t t h e c o n c e p t o f the se-lec t ion sc reen , its f ea tu res , a n d h o w to u s e it f o r p r o g r a m d e v e l o p m e n t .

Object ives of th is Por t ion of t he Test

T h e ob j ec t i ve o f this p o r t i o n o f t h e ce r t i f i ca t ion e x a m is to e x a m i n e y o u r u n d e r -

s t a n d i n g r e g a r d i n g t h e se lec t ion s c r een . T h e e x a m wil l v e r i f y y o u r k n o w l e d g e

r e g a r d i n g t h e v a r i o u s o p t i o n s ava i lab le to des ign t h e se lec t ion s c r een .

Key Concepts Refresher

Select ion s c r e e n s a r e r e q u i r e d f o r y o u r c u s t o m p r o g r a m s w h e n y o u w a n t t h e u s e r to i n p u t da t a to c o n t r o l t h e flow o f t h e p r o g r a m o r to res t r ic t da t a ex t r ac t ion f r o m the da t abase . Select ion s c r e e n s a re o f t e n u s e d w i t h an e x e c u t a b l e ABAP pro-g r a m such as ABAP r epo r t s , c o n v e r s i o n p r o g r a m s , a n d s o o n .

Key Concepts Refresher Chapter 13 379

You can d e f i n e a s t a n d a r d se lec t ion sc reen b y us ing ABAP language dec la ra t ive s t a t e m e n t s s u c h as p a r a m e t e r s a n d s e l e c t - o p t i o n s . S imple s t a t e m e n t s a l l o w y o u to c r ea t e i n p u t f ie lds , c h e c k b o x e s , a n d r ad io b u t t o n s . T h e ABAP language also p r o v i d e s y o u w i t h t h e dec la ra t ive s t a t e m e n t s e l e c t i o n - s c r e e n t o f o r m a t t h e l ayou t o f the se lec t ion sc reen w i t h o u t u s ing t h e Screen Pa in t e r o r M e n u Pain ter . You can a lso d e f i n e a u s e r - d e f i n e d se lec t ion sc reen apar t f r o m t h e d e f a u l t s t a n d a r d se lec t ion sc reen f o r t h e p r o g r a m .

S e l e c t i o n S c r e e n s

Selec t ion s c r e e n s s e r v e as an i n t e r f a c e b e t w e e n t h e u s e r a n d t h e p r o g r a m . You o f t e n u s e se lec t ion s c r e e n s t o p r o v i d e t h e u s e r w i t h an in t e r f ace t o i n p u t da t a f o r t h e p r o g r a m . This i n p u t da ta is u s e d to c o n t r o l t h e p r o g r a m f l o w o r to res t r ic t o r f i l te r t h e da ta se lec t ion f r o m t h e d a t a b a s e . Select ion s c r e e n s a re typical ly u s e d in an e x e c u t a b l e p r o g r a m . T h e use r s i m p l y has to u s e ABAP s t a t e m e n t s to c r ea t e i n p u t fields, c h e c k b o x e s , a n d r ad io b u t t o n s , w h e r e a s t h e d y n p r o s (dialog sc reens ) a re c r e a t e d us ing t h e Screen Pa in te r , a n d each d y n p r o sc reen r e q u i r e s s c reen f l o w logic. For m o r e i n f o r m a t i o n r e g a r d i n g d y n p r o sc reens , r e f e r to Chap-te r 12, Classical Screens . You can d e s i g n t h e se lec t ion sc reen to a l l o w t h e use r to e n t e r a s ingle va lue o r c o m p l e x se lec t ion cr i ter ia .

T h e ABAP l anguage dec la ra t ive s t a t e m e n t s a re u s e d to d e f i n e a se lec t ion sc reen f o r an ABAP p r o g r a m . You can des ign the sc reen layout , i n p u t fields, c h e c k b o x e s , a n d r ad io b u t t o n s u s ing t h e s e s i m p l e ABAP l anguage s t a t e m e n t s a n d d o n o t r e q u i r e t h e Screen Pa in t e r to d e f i n e t h e se lec t ion sc reen fo r ABAP p r o g r a m s .

S e l e c t i o n S c r e e n D e s i g n

T h e se lec t ion s c r e e n f o r a p r o g r a m is d e f i n e d us ing ABAP language dec la ra t ive s t a t e m e n t s , u n l i k e d ia log sc reens , w h i c h a rc d e s i g n e d us ing the Screen Pa in t e r a n d M e n u Pa in te r . T h e t w o s t a t e m e n t s to d e f i n e se lec t ion s c r e e n s a r e p a r a m e -t e r s a n d s e l e c t - o p t i o n s .

PARAMETERS

T h e p a r a m e t e r s s t a t e m e n t is u s e d to d e f i n e a s ing le i n p u t field o n t h e se lec t ion s c r een . p a r a m e t e r s a r c u s e d to c o n t r o l t h e p r o g r a m f l o w o r res t r ic t t h e d a t a b a s e access, s o typical ly w e w o u l d u s e th i s in t h e w h e r e c lause o f o u r s e l e c t s t a t e m e n t to filter w h i c h r e c o r d s w e re t r i eve .

374 Chapter 394 Classical Screens

T h e d a t a o b j e c t d e c l a r e d w i t h t h e PARAMETERS s t a t e m e n t a p p e a r s as a n i n p u t field

o n t h e s e l ec t i on s c r e e n . You d e c l a r e p a r a m e t e r s w i t h t h e TYPE o r LIKE s t a t e m e n t ,

s i m i l a r to a va r i ab l e d e c l a r a t i o n w i t h t h e DATA s t a t e m e n t . You c a n u s e ABAP

types , local d a t a types , o r g loba l d a t a t y p e s to d e f i n e t h e p a r a m e t e r s f o r y o u r p ro -

g r a m . T h e p a r a m e t e r n a m e c a n b e u p t o e igh t c h a r a c t e r s long . Un le s s y o u m a i n -

ta in t h e s e l ec t i on tex t f o r t h e p a r a m e t e r , t h e p a r a m e t e r n a m e is d i s p l a y e d as t ex t

to t h e left o f t h e i n p u t field. T h e tex t label can b e m a i n t a i n e d a s a SELECTION TEXT

b y f o l l o w i n g t h e m e n u p a t h G O T O • T E X T E L E M E N T S • S E L E C T I O N T E X T S .

T h e PARAMETERS s t a t e m e n t a d o p t s t h e a t t r i b u t e o f t h e ABAP D i c t i o n a r y field if it

r e f e r s to t h e d a t a t ype f r o m t h e ABAP D i c t i o n a r y . T h e se l ec t ion tex t f o r t h e

PARAMETERS s t a t e m e n t can b e d e r i v e d f r o m t h e D i c t i o n a i y , if t h e DICTIONARY REF-

ERENCE c h e c k b o x is s e l ec t ed o n t h e s e l ec t i on tex t s c r e e n . F igure 1 3 . 1 d i sp lays t h e

se l ec t ion text b o x w i t h t h e o p t i o n t o a d o p t t h e se l ec t ion tex t f r o m t h e ABAP Dic-

t i o n a r y .

Program ZDEH01 Actvo

Figure 13.1 Selection Text for the Selection Screen Parameters

T h e f o l l o w i n g is a n e x a m p l e t o d e f i n e f o r s e l ec t i on s c r e e n u s i n g t h e PARAMETERS

s t a t e m e n t :

REPORT ZDEM01. PARAMETERS: p . f n a m e TYPE r f p o - r f b l f 1 1 e OBLIGATORY.

p _ d a t e TYPE da tum OEFAULT s y - d a t u r a , p . p r i c e TYPE P DECIMALS 2 .

F i g u r e 1 3 . 2 d i sp l ays t h e s e l ec t i on s c r e e n f o r t h e a b o v e c o d e .

Demo program for Select ion Screen

•4am» fr«at [OioonaryrtT | • P_DATA purer* Do»9 P_FNAM£ FHepaftname P.PRICE Pnce

I I I •

File M O name

Current Dace

Pnce

0 4 / 2 6 / 2 0 0 9

Figure 13.2 Selection Screen with Parameters Statement

Key Concepts Refresher Chapter 13 395

With the DEFAULT addit ion y o u can set the default value for a parameter . The default value is displayed on the screen when the user executes the program, and he can change this default value on the selection screen if he wants . The addit ion OBLIGATORY is used to declare the input field as a required field on the selection screen. The addit ion MEMORY ID <PI0> is used to specify the value of the input field f rom the SAP m e m o i y . <PID> is the PARAMETER ID for the data e lements def ined in the ABAP Dictionaiy. SAP m e m o i y is a user-specific m e m o i y area in which the value is stored for this PARAMATER ID for the durat ion of the user ses-sion. You use SET/GET PARAMETER ID to store or retrieve value f rom memoiy .

You can also use the PARAMETERS statement to declare checkboxes or radio but-tons on the selection screen. The checkboxes are def ined by using the addit ion AS CHECKBOX, and radio but tons are def ined by using the addit ion RAOIOBUTTON GROUP <GRP>, w h e r e <GRP> is the radio but ton group.

• Checkboxes can be used for data selection or program control . Technically, a checkbox is a one-character field of type C and can have a value of ' X' or blank ( ' ' ) . You can provide a default value for the parameters object typed as a checkbox dur ing the definit ion, o r the user can check or uncheck the checkbox on the selection screen. The PARAMETER has the value 'X' if the checkbox is checked; otherwise, it has a blank value. Listing 13.1 is an exam-ple code to def ine and use a checkbox program.

REPORT ZDEMO.CHECKBOX. PARAMETERS: p _ d i s p a l l AS CHECKBOX.

P_archf l AS CHECKBOX DEFAULT ' X ' . IF d i s p a l l IS INITIAL.

WRITE: / ' D i s p l a y Er ro r Records e r r o r on ly* . ELSE.

WRITE: /'DISPLAY a l l r e c o r d s ' . ENDIF. IF a r c h f l IS NOT INITIAL.

"Archive f i l e WRITE: / ' A r c h i v e F i l e ' .

ENDIF.

Listing 13.1 Example Code to Define and Use a Checkbox in Program

• Radio but tons are always associated with a g roup in which you can select only but tons f rom the group. Technically, a radio but ton is a character field of type C and length 1. Radio but tons can have a value o f ' X' or blank ( ' ' ) . The radio but ton has a value of ' x ' if it is selected on the screen; otherwise, it has a

382 Chapter 13 Selection Screens

blank value. You can use radio but tons in y o u r program to control the f low of the program. At any t ime only one radio but ton in the g roup can have a value of 'X ' , and the rest of the radio bu t tons in the g roup will have a blank value. Listing 13.2 is an example code to def ine and use of a radio bu t ton in program.

REPORT ZDEMO_RADIOBUTTON. PARAMETERS: p_pcf1 le AS RADI08UTT0N GROUP a .

p . a p p f i l e AS RADIOBUTTON GROUP a . IF p_pc f i1e IS NOT INITIAL.

WRITE: /'READ f i l e from loca l PC*. •Read f i l e from PC

ENDIF. IF p . a p p f i l e IS NOT INITIAL.

WRITE: /'READ f i l e from a p p l i c a t i o n s e r v e r ' . "Read f i l e from a p p l i c a t i o n s e r v e r

ENDIF.

Listing 13.2 Example Code to Define and Use a Radio Button in the Program

You can validate user entries against the check table or fixed values of the domain behind the ABAP Dictionary type. The input value entered on the selection screen will not be validated if the VALUE CHECK addition is not specified for the PARAMETERS. The check is pe r fo rmed even if the value for the parameter field is empty , so y o u should only use value check on a required (mandato iy input) field. With the fol lowing parameter declaration, the user can only en te r the value def ined in the check table or the fixed value def ined in the domain of the ABAP Dictionary data e lement s _ c a r r _ i d .

PARAMETERS: p_ca r r id TYPE s_carr_1d va lue check.

S E L E C T - O P T I O N S

The SELECT-OPTIONS s ta tement is used to def ine a complex selection that allows the user to enter value ranges and complex selection criteria instead o f j u s t a sin-gle input field. The variable name for the SELECT OPTIONS input field can be u p to eight characters. The SELECT-OPT IONS keyword generates a selection table. The selection table is an internal table with a s tandard s tructure and a header line. The internal table for the select opt ion is populated automatically based on what the user en ters in the SELECT-OPTIONS input fields, so y o u do not have to fill the field in the program.

Key Concepts Refresher Chapter 13 397

T h e s t r u c t u r e o f t h e in te rna l t ab le cons i s t s o f f o u r c o m p o n e n t s :

• s i g n T h e da t a t y p e o f s i g n is c , a n d it has a l eng th o f 1 . T h e c o n t e n t o f t h e s i g n d e t e r m i n e s w h e t h e r t h e va lues a r e to b e i nc luded o r e x c l u d e d . Poss ib le va lues f o r th is field a r e ' i ' a n d ' e ' . ' i ' s t a n d s fo r inc lus ion c r i t e r i on , a n d ' e * is f o r exc lus ion c r i t e r i on .

• o p t i o n

T h e da ta t y p e f o r o p t i o n is c , a n d it h a s a l eng th o f 2 . Table 13 .1 s h o w s t h e

val id o p e r a t o r s .

Value Mean ing

EQ Equal

NE Not equal

IE Less or equal

LT Less than

GE Greater or equal

GT Greater than

BT Between

NB Not between

CP Contains pattern

NP Does not contain pattern

Table 13.1 Valid Operators for Selection Table Field OPTION

• l o w a n d h i g h

T h e da t a t y p e s f o r l o w a n d h i g h a r e t h e s a m e as t h e t y p e y o u give to t h e select-o p t i o n . l o w is t h e l o w e r l imit h i g h is t h e h i g h e r l imit f o r t h e se lec t ion cr i ter ia , a n d t h e y c o r r e s p o n d t o t h e i n p u t f i e lds o n t h e s c r een . In c o m b i n a t i o n w i t h t h e o p e r a t o r in o p t i o n , t h e r a n g e spec i f i e s t h e se lec t ion cr i ter ia f o r t h e da ta se lec t ion .

Use t h e a d d i t i o n f o r t o spec i fy t h e da t a ob jec t a l r eady d e f i n e d in y o u r p ro -

g r a m , w h i c h s h o u l d b e u s e d to type , o r d e f i n e , t h e p r o p e r t i e s o f t h e select

o p t i o n . Both t h e l imit fields l o w a n d h i g h i nhe r i t t h e a t t r i b u t e s o f th i s refer -

384 Chapter 13 Selection Screens

o n c e f i e l d . Each l i n e o f t h e s e l e c t i o n t a b l e f o r m u l a t e s a c o n d i t i o n f o r s e l e c t i o n

c r i t e r i a .

T h e s y n t a x f o r t h e SELECT-OPT IONS d e c l a r a t i o n is a s f o l l o w s :

TYPES: BEGIN OF t y _ m a r c . m a t n r TYPE m a r c - m a t n r . w e r k s TYPE m a r c - w e r k s .

ENO OF t y _ m a r c . OATA: wa_marc TYPE t y _ m a r c . SELECT-OPTIONS: s _ m a t n r FOR w a _ m a r c - m a t n r .

S _ w e r k s FOR w a _ m a r c - w e r k s .

MARC is a t a b l e , a n d m a t n r a n d w e r k s a r e t h e f i e l d s o f t h e t a b l e MARC. T h e a b o v e

d e c l a r a t i o n c r e a t e s t w o s e l e c t i o n t a b l e s , s _ m a t n r a n d s _ w e r k s , w i t h c o r r e -

s p o n d i n g i n p u t s e l e c t i o n f i e l d s o n t h e s e l e c t i o n s c r e e n . E a c h SELECT-OPTIONS

s t a t e m e n t c r e a t e s a s e l e c t i o n t a b l e . F i g u r e 1 3 . 3 d i s p l a y s t h e s e l e c t i o n s c r e e n

f o r t h e a b o v e d e c l a r a t i o n .

SELECT-OPTIONS s j M t n r FOR wa_narc-natnr . s_*erks FOR wa_narc-»erks

START-OF-SELECTION O LOOP AT s_»atnr

WRITE / s j t a t n r - l o w ENDLOOP

ttem flltabte s_natnr 3 Type STANDARD Format E • 1 SIGN OPTION LOW HIGH

a 1 2 3 4

I |BT |100-251 |1500-510 I |BT |100-251 11500-510 I |BT |1500-500 11500-700 I |BT |000000000000001157|3007-03 I |BT |000000000000001108|3007-04 -

E

Figure 13.3 Selection Table for SELECT-OPTIONS Input Field

T h e u s e r c a n s p e c i f y m u l t i p l e v a l u e s f o r e a c h o f t h e SELECT OPT IONS. F i g u r e 1 3 . 4

d i s p l a y s t h e s c r e e n t h a t s p e c i f i c s m u l t i p l e v a l u e s f o r t h e i n p u t f i e ld o n t h e se l ec -

t i o n s c r e e n .

You c a n a s s i g n a d e f a u l t v a l u e f o r SELECT-OPTIONS. Use t h e f o l l o w i n g s y n t a x t o

d e f i n e t h e d e f a u l t v a l u e .

• T o fill t h e d e f a u l t f o r t h e LOW f i e l d u s e :

SELECT-OPTIONS: s _ m a t n r FOR m a r c - m a t n r OEFAULT ' A 1 2 3 \

Key Concepts Refresher Chapter 13 399

• T o fill t h e d e f a u l t f o r t h e LOW a n d HIGH fields u s e :

SELECT-OPTIONS: s _ m a t n r FOR m a r c - m a t n r

DEFAULT ' A 1 2 3 ' TO ' B 1 2 3 ' .

• T o fill t h e d e f a u l t f o r t h e OPTION field u s e :

SELECT-OPTIONS: s . m a t n r FOR m a r c - m a t n r DEFAULT ' A 1 2 3 ' OPTION ' H E ' .

• T o fill t h e d e f a u l t f o r t h e SIGN field u s e :

SELECT-OPTIONS: s _ m a t n r FOR m a r c - m a t n r OEFAULT ' A 1 2 3 ' SIGN ' E ' .

• T o fill t h e d e f a u l t f o r all o f t h e fields o f t h e s e l e c t i o n t a b l e u s e :

SELECT-OPTIONS: s _ m a t n r FOR m a r c - m a t n r OEFAULT ' A 1 2 3 ' TO ' B 1 2 3 ' OPTION 'NB* SIGN M \

Figure 13.4 Value Range for Selection Table

You c a n p o p u l a t e d e f a u l t v a l u e s d y n a m i c a l l y in t h e s e l e c t i o n t a b l e f o r t h e

SELECT-OPTIONS fields in t h e p r o g r a m in t h e INITIALIZATION e v e n t b l o c k . F o r

d e t a i l s r e g a r d i n g t h e INITIALIZATION e v e n t b l o c k r e f e r t o C h a p t e r 9 . Basic A B A P

P r o g r a m s a n d I n t e r f a c e C r e a t i o n .

U s e t h e a d d i t i o n NO EXTENSION t o r e s t r i c t t h e u s e r t o a d d i n g o n l y o n e r a n g e in

t h e SELECT OPT IONS i n p u t fields o n t h e s e l e c t i o n s c r e e n a s f o l l o w s :

SELECT-OPTIONS: s _ m a t n r FOR m a r c - m a t n r NO-EXTENSION.

400 Chapter 13 Selection Screens

A s a resu l t , t h e p u s h b u t t o n f o r m u l t i p l e s e l ec t i ons wi l l n o t a p p e a r o n t h e selec-

t i o n s c r e e n as d i s p l a y e d in F i g u r e 1 3 . 5 .

<S>

Material Number

Figure 13.5 SELECT-OPTIONS with Addition NO-EXTENSION

You can a l so use t h e a d d i t i o n NO INTERVALS t o res t r ic t t h e u s e r t o s ing le field

e n t i y f o r t h e s e l ec t i on t ab le . T h e s y n t a x fo r s i ng l e field e n t i y is as f o l l o w s :

SELECT-OPTIONS: s . m a t n r FOR m a r c - m a t n r NO INTERVALS S_werks FOR m a r c - w e r k s .

A s a r e su l t , t h e S_MATNR-HIGH is n o t d i s p l a y e d o n t h e s e l ec t i on s c r e e n as dis-

p l a y e d in F i g u r e 1 3 . 6 .

Materia Number

Plant to

Figure 13.6 SELECT-OPTIONS with Addition NO INTERVALS

Simi lar t o t h e PARAMETERS o p t i o n , y o u u s e t h e a d d i t i o n MEMORY ID t o GET/SET

p a r a m e t e r ID f o r t h e se l ec t ion s c r e e n . T h e a d d i t i o n OBLIGATORY is u s e d to m a k e

t h e LOW field a r e q u i r e d field o n t h e s e l ec t i on s c r e e n . Also , t h e o p t i o n NO - DI SPLAY

is u s e d to h i d e t h e i n p u t field o n t h e s e l ec t i on s c r e e n .

You can a l so m o d i f y t h e a t t r i b u t e s o f t h e s c r een e l e m e n t o n t h e s e l ec t i on s c r e e n .

Th i s f e a t u r e is e spec ia l ly u s e f u l t o h i d e o r c h a n g e t h e a t t r i b u t e s o f t h e logical

d a t a b a s e s e l ec t i on s c r e e n w i t h i n y o u r c u s t o m p r o g r a m . You c a n m o d i f y t h e

a t t r i b u t e o f b o t h t h e PARAMETERS a n d SELECT-OPTIONS fields o n t h e s e l ec t i on

s c r e e n . T h e e v e n t b l o c k AT SELECT ION-SCREEN OUTPUT a l l o w s y o u t o m o d i f y t h e

s e l ec t i on s c r e e n d i r ec t l y b e f o r e it is d i s p l a y e d . In a s i m p l i f i e d f o r m List ing 1 3 . 3

d i sp l ays t h e c o d e t o m o d i f y s e l ec t i on s c r e e n a t t r i b u t e s .

REPORT ZDEMO_MODIF_SCREEN. NODES: SPFLI, SFLIGHT. AT SELECTION-SCREEN OUTPUT. LOOP AT SCREEN.

IF SCREEN NAME - 'CARRIOHIGH*.

Key Concepts Refresher Chapter 13 401

SCREEN-ACTIVE - ' 0 \ MODIFY SCREEN.

ENDIF. ENOLOOP.

Listing 13.3 Modify Selection Screen Attribute

W i t h o u t t h e c o d e w i t h i n t h e AT SELECTION-SCREEN OUTPUT e v e n t b lock , t h e selec-

t i on s c r e e n f o r t h e p r o g r a m w i t h logical d a t a b a s e a p p e a r s as d i s p l a y e d in F igure

13 .7 , a n d w i t h t h e c o d e f o r t h e AT SELECT ION SCREEN OUTPUT t h e s e l ec t i on s c r e e n

a p p e a r s as d i s p l a y e d in F igure 1 3 . 8 .

Connections Airtne Departure airport Destination airport

Figts

to 4j

s

Departure date to

Figure 13.7 Selection Screen wi thout Screen Modification

Connections Airline Departure airport Destination airport 1

•1

Figts Departure date to

Figure 13.8 Selection Screen with Screen Modification

Tex t s o n t h e s e l ec t i on s c r e e n a r e s t o r e d as s e l ec t i on tex t in t h e p r o g r a m tex t e le-

m e n t s . T h e s e s e l ec t i on s c r e e n t ex t s can t h e n b e t r a n s l a t e d i n t o o t h e r l a nguages .

T h e tex t e l e m e n t s f o r t h e p r o g r a m c a n b e acces sed f r o m t h e p r o g r a m via t h e

m e n u p a t h GOTO • TEXT ELEMENTS • SELECTION TEXTS. Se lec t ion s c r e e n tex t c a n

a lso b e d e r i v e d f r o m t h e ABAP D i c t i o n a i y if t h e s e l ec t i on s c r e e n e l e m e n t s r e f e r

t o da t a t y p e s f r o m t h e ABAP D i c t i o n a r y as d i s p l a y e d in F i g u r e 1 3 . 1 . F i g u r e 1 3 . 9

402 Chap te r 13 Select ion Screens

a n d F i g u r e 1 3 . 1 0 s h o w a s e l e c t i o n s c r e e n a n d t h e s e l e c t i o n t e x t s f o r t h e s e l e c t i o n

s c r e e n in t h e A B A P p r o g r a m .

Inventory Overview <2>ttO

Warehouse number wrm Physical imvntc«y number to

General program parameters Stwty to 0 Physical invent reference (0 0 Planned dace to 13

tweory status Not counted

• Pan at/ cointed 12 Counted : ; Cleared

• Ontynon-activated Ontyowvpnneed

F igu re 13.9 Se lec t ion Screen for t h e ABAP Re p o r t

Program RLI30010 Active

Te>J symbols Selection teas List Head ngs

|Name Text Diction* C AflGEZ Pad accounted -

AUGEB Cleared DATUM Planned date GEZAE Counted IRNUM Physical inver* reference LGTYP Storty NIAKT Only norv activated NIDRU Only non-pnnted NIGEZ Not counted

< > 1 >

F igu re 13.10 Se lec t ion Sc reen Texts

T h e u s e r c a n c r e a t e a p r o g r a m s e l e c t i o n s c r e e n v a r i a n t t o s t o r e t h e i n p u t v a l u e s

f o r t h e s e l e c t i o n s c r e e n . S e l e c t i o n s c r e e n v a r i a n t s a r e h e l p f u l if t h e u s e r r u n s t h e

Key Concepts Refresher Chapter 13 403

p r o g r a m w i t h t h e s a m e s e t s o f i n p u t v a l u e . It s a v e s t i m e a n d e f f o r t . T h e v a r i a n t

is a l s o r e q u i r e d if t h e p r o g r a m is s c h e d u l e d t o r u n in t h e b a c k g r o u n d , s o t h a t t h e

s y s t e m k n o w s w h i c h v a l u e is t o b e u s e d t o r u n t h e p r o g r a m .

T h e v a r i a n t f o r t h e s e l e c t i o n s c r e e n c a n b e c r e a t e d in t h e A B A P E d i t o r o r f r o m

t h e s e l e c t i o n s c r e e n i t se l f b y c l i c k i n g o n t h e SAVE i con (IHI) o n t h e s c r e e n o r v ia

t h e m e n u p a t h G O T O • V A R I A N T S • S A V E A S V A R I A N T . F i g u r e 1 3 . 1 1 d i s p l a y s t h e

v a r i a n t m a i n t e n a n c e s c r e e n .

V a r i a n t A t t r i b u t e s I

/ C w S o w A w m i r t D

V M d N m v t r i a i l Ml « v » ) ONTO v a w t ScnAtw j rm

Tt O M M M K K n S o n t CO*** r ^ - l j r r . r . ! f y m u - g f l & t ; f i < M t r M f l & n X v C M M y « C < U 0 9

a v » a CtfKB t y MIK»9>t KTMn

ft H I I V M V O O

1/300 H v w ^ i w W f u r t M O 0 n 0 B I 0 'COO t k > V 5 0 n n i xoo t i v i i a n w m w n 5 0 n 1X00 IMrmnf 5 0 0 1XOO P 0 0 0 0 t = 1X00 » « 1 I * > ! 0 V M p 0 0 O 1X00 Owe P • 0 0 0 1X00 OMK*4 P O 0 0 0 1000 C r * K r . v M M 4 P 0 0 0 1X00 Or*, r P 0 0 1 0 1 1X00 ISTAT S

Figure 13.11 Variant At t r ibu te Screen

Y o u c a n d e f i n e a s t a n d a r d s e l e c t i o n s c r e e n a n d a n y n u m b e r o f u s e r - d e f i n e d se lec -

t i o n s c r e e n s . T h e s t a n d a r d s e l e c t i o n s c r e e n is c a l l e d a u t o m a t i c a l l y w h e n y o u s t a r t

t h e p r o g r a m , w h e r e a s t h e u s e r - d e f i n e d s e l e c t i o n s c r e e n is ca l l ed u s i n g t h e CALL

SELECT ION-SCREEN s t a t e m e n t in t h e p r o g r a m . T h e s t a n d a r d s e l e c t i o n s c r e e n h a s

t h e d e f a u l t s c r e e n n u m b e r 1000, w h e r e a s t h e u s e r - d e f i n e d s c r e e n can h a v e a n y

s c r e e n n u m b e r e x c e p t 1000 .

Formatting the Selection Screen

T h e s e l e c t i o n s c r e e n d e f i n e d b y t h e PARAMETERS a n d SELECT-OPTIONS s t a t e m e n t s

h a s i ts o w n l a y o u t in w h i c h all o f t h e PARAMETERS o r SELECT-OPT IONS a p p e a r l i n e

b y l i n e . T h e SELECTION-SCREEN s t a t e m e n t a l l o w s y o u t o s p e c i f y y o u r o w n f o r -

m a t t i n g o p t i o n s f o r t h e s e l e c t i o n s c r e e n . You c a n d e f i n e t h e l a y o u t o f p a r a m e t e r s

a n d s e l e c t i o n c r i t e r i a a n d c a n d i s p l a y c o m m e n t s a n d u n d e r l i n e s o n t h e s e l e c t i o n

s c r e e n . In a d d i t i o n , y o u c a n p l a c e b u t t o n s o n t h e s e l e c t i o n s c r e e n o r a p p l i c a t i o n

404 Chapter 13 Selection Screens

t o o l b a r . T h e f o r m a t t i n g o p t i o n s c a n b e u s e d o n t h e s t a n d a r d se l ec t ion s c r e e n

o n l y if it ha s at least o n e i n p u t field.

U s e t h e BEGIN OF BLOCK < b l o c k > a d d i t i o n t o g r o u p t o g e t h e r logical ly r e l a t ed

s c r e e n e l e m e n t s a n d WITH FRAME to d r a w a f r a m e a r o u n d t h e logical ly r e l a t ed

fields. You can n e s t f r a m e s to a d e p t h o f five levels . You s h o u l d ass ign a h e a d i n g

to a b lock , u s i n g t h e TITLE a d d i t i o n ; t h e b lock h e a d i n g can b e a t ex t e l e m e n t o r

a field n a m e u p to e i g h t c h a r a c t e r s l ong . A n y b lock n e e d s a SELECTION-SCREEN

END OF BLOCK a d d i t i o n t o i n d i c a t e w h e r e it e n d s .

List ing 1 3 . 4 d i sp l ays t h e c o d e f o r a d e s i g n s c r e e n l ayou t :

SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME TITLE t e x t - 0 0 1 . PARAMETERS: p_pc RADIOBUTTON GROUP a . "Loca l PC F i l e

p_app RADIOBUTTON GROUP a . " S e r v e r F i l e P_1gf11e TYPE f i l e i n t e r n . " L o g i c a l F i l e P _ p h f i l e TYPE f i l e i n t e r n . " P h y s i c a l f i l e

SELECTION-SCREEN END OF BLOCK a . Listing 13.4 Code to Design Selection Screen Layout

F i g u r e 1 3 . 1 2 d i sp l ays t h e se l ec t ion s c r e e n f o r t h e a b o v e e x a m p l e .

Demo program for Selection Screen

Input File @ File on Local PC O File on Application Server Logical File Name Physical File Name

Figure 13.12 Selection Screen Formatting

You can a l so d i s p l a y m u l t i p l e p a r a m e t e r s a n d c o m m e n t s o n t h e s a m e o u t p u t l ine .

T o d o th i s y o u n e e d t o e n c l o s e t h e m b e t w e e n SELECTION-SCREEN BEGIN OF LINE

a n d SELECTION-SCREEN END OF LINE. T h e COMMENT a d d i t i o n a l l o w s y o u t o i n c l u d e

tex t in l ine . C o m m e n t text m u s t a l w a y s h a v e a p o s i t i o n a n d o u t p u t l e n g t h . You

can d e f i n e t h e p o s i t i o n u s i n g POS_LOW a n d POS_HIGH. T h e s e a r e t h e p o s i t i o n s o f

t h e u p p e r a n d l o w e r l imi ts , r e spec t ive ly , o f t h e field SELECT-OPTIONS o n t h e

se l ec t ion s c r e e n . You can u s e POSITION <POS> t o p o s i t i o n t h e c u r s o r o n a l ine f o r

t h e n e x t o u t p u t . This a d d i t i o n can o n l y b e u s e d in b e t w e e n BEGIN OF LINE a n d

END OF LINE.

Key Concepts Refresher Chapter 13 405

L i s t i n g 1 3 . 5 d i s p l a y s t h e s y n t a x t o u s e t h e BEGIN OF LINE s t a t e m e n t t o d e s i g n a

s e l e c t i o n s c r e e n l a y o u t :

SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME TITLE t e x t - 0 0 1 . PARAMETERS: p _ p c RADIOBUTTON GROUP a . " L o c a l PC F i l e

p _ a p p RADIOBUTTON GROUP a . " S e r v e r F i l e SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN POSITION 4 .

PARAMETERS p j o g i RAOIOBUTTON GROUP 0002 DEFAULT ' X ' . SELECTION-SCREEN COMMENT 7 ( 3 0 ) t e x t - 0 0 4 FOR FIELD p j o g i . PARAMETERS: p j g f i l e TYPE f i l e i n t e r n . SELECTION-SCREEN END OF LINE. SELECTION-SCREEN BEGIN OF LINE. SELECTION-SCREEN POSITION 4 . PARAMETERS p_phy RADIOBUTTON GROUP 0 0 0 2 . SELECTION-SCREEN COMMENT 7 ( 3 0 ) t e x t - 0 0 5 FOR FIELD p _ p h y . PARAMETERS: p _ p h f 1 1 e LIKE r f p d o - r f b i f i l e . SELECTION-SCREEN END OF LINE. SELECTION-SCREEN END OF BLOCK a . SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE t e x t - 0 0 3 . PARAMETERS: p _ c h e c k RADIOBUTTON GROUP c OEFAULT ' X \ " c h e c k f l

p . p r o c s RA0I08UTT0N GROUP c . " P r o c e s s t h e f i l e SELECTION-SCREEN END OF BLOCK b .

Listing 13.5 Code for Selection Screen Layout

F i g u r e 1 3 . 1 3 d i s p l a y s t h e s e l e c t i o n s c r e e n w i t h t h e f o r m a t t e d l a y o u t .

Input File ® File on Local PC O File on Application Server

® Logical File Name O Physical File Name

Processing Option <•> Check File O Process File

Figure 13.13 Format ted Selection Screen

You c a n a l s o a d d a b l a n k l ine t o t h e s e l e c t i o n s c r e e n b y u s i n g SELECT ION-SCREEN

SKIP <n> o r a n u n d e r l i n e b y s p e c i f y i n g SELECTION-SCREEN ULINE.

392 Chapter 13 Selection Screens

Selection Screen as Subscreen

It is a l s o p o s s i b l e t o d e f i n e t h e s e l e c t i o n s c r e e n as a s u b s c r e e n in y o u r A B A P p r o -

g r a m , a n d t h e n t h i s s e l e c t i o n s c r e e n c a n b e i n c l u d e d as a s u b s c r e e n o n a s c r e e n

o r a s p a r t o f a t a b s t r i p c o n t r o l o n a s e l e c t i o n s c r e e n . T h e s y s t e m p r o c e s s e s t h e

e v e n t s AT SELECTION-SCREEN OUTPUT a n d AT SELECTION-SCREEN f o r e a c h s u b -

s c r e e n in a d d i t i o n t o p r o c e s s i n g t h e s u r r o u n d i n g s e l e c t i o n s c r e e n . R e f e r t o C h a p -

t e r 9 . Basic A B A P P r o g r a m s a n d I n t e r f a c e C r e a t i o n , f o r m o r e i n f o r m a t i o n

r e g a r d i n g p r o g r a m e v e n t s . You w o r k w i t h t h e s y s t e m v a r i a b l e SYST-DYNNR t o

d e t e r m i n e w h i c h s c r e e n o r s u b s c r e e n is c u r r e n t l y b e i n g p r o c e s s e d . If y o u h a v e

m a n y i n p u t fields o n t h e s e l e c t i o n s c r e e n , it m a y b e a g o o d i d e a t o g r o u p t o g e t h e r

log ica l ly r e l a t e d s c r e e n e l e m e n t s in s e p a r a t e s u b s c r e e n s a n d d i s p l a y t h e m a s t ab -

s t r i p s .

L i s t ing 1 3 . 6 d e f i n e s t h e s e l e c t i o n s c r e e n a s a s u b s c r e e n a n d i n c l u d e s it as p a r t o f

a t a b s t r i p c o n t r o l .

SELECTION-SCREEN BEGIN OF SCREEN 110 AS SUBSCREEN. SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME TITLE t e x t - 0 1 0 . SELECT-OPTIONS: s . c a r r i d FOR s p f l 1 - c a r r i d .

s _ c o n n FOR s p f 1 i - c o n n i d . SELECTION-SCREEN END OF BLOCK a . SELECTION-SCREEN END OF SCREEN 1 1 0 . SELECTION-SCREEN BEGIN OF SCREEN 120 AS SUBSCREEN. SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE t e x t - 0 1 1 . SELECT-OPTIONS: s _ c n t r f r FOR S p f 1 1 - c o u n t r y f r .

s _ c i t y f r FOR s p f 1 i - c i t y f r o m . s _ a i r p f r FOR s p f 1 i - a f r p f r o m .

PARAMETERS: s _ d e p d t LIKE s y - d a t u m . SELECTION-SCREEN END OF BLOCK b . SELECTION-SCREEN END OF SCREEN 1 2 0 . SELECTION-SCREEN BEGIN OF SCREEN 130 AS SUBSCREEN. SELECTION-SCREEN BEGIN OF BLOCK c WITH FRAME TITLE t e x t - 0 1 2 . SELECT-OPTIONS: s . c n t r t o FOR S p f 1 1 - c o u n t r y t o .

s _ c i t y t o FOR s p f l i - c i t y t o . s _ a i r p t o FOR s p f l i - a i r p t o .

PARAMETERS: s _ r e t d t LIKE s y - d a t u m . SELECTION-SCREEN END OF BLOCK c . SELECTION-SCREEN END OF SCREEN 1 3 0 . SELECTION-SCREEN BEGIN OF TABBED BLOCK t a b . b l o c k FOR 10 LINES. SELECTION-SCREEN TAB ( 2 0 ) t a b l USER-COMMAND coirml

DEFAULT SCREEN 1 1 0 . SELECTION-SCREEN TAB ( 2 0 ) t a b 2 USER-COMMAND coirm2

Key Concepts Refresher Chapter 13 407

DEFAULT SCREEN 120. SELECTION-SCREEN TAB ( 2 0 ) t a b 3 USER-COMMAND comm3

DEFAULT SCREEN 130. SELECTION-SCREEN ENO OF BLOCK t a b _ b l o c k . INITIALIZATION,

t a b l - ' C o n n e c t i o n ' ( 0 1 0 ) . t a b 2 - ' D e p a r t u r e . C i t y ' ( O l l ) . t a b 3 - ' A r r i v a l C i t y ' ( 0 1 2 ) . t a b _ b l o c k - a c t i v e t a b - 'COMMI'. t a b _ b l o c k - d y n n r - 110.

Listing 13.6 Example Code to Define Tabstrip Control for Selection Screen

F igure 1 3 . 1 4 d i sp l ays t h e t a b s t r i p o n t h e s e l ec t i on s c r e e n f o r t h e a b o v e d e f i n i -

t i o n .

<S>

Connection , Departure City AmvalCity

Connection Airline to Connection Number to

Figure 13.14 Tabstrips on the Selection Screen

You c a n u s e t h e o p t i o n a l a d d i t i o n NEST ING LEVEL t o f u r t h e r r e d u c e t h e size o f t h e

s u b s c r e e n . You can use it t o p r e v e n t s c ro l lba r s f r o m a p p e a r i n g w h e n y o u u s e t h e

s u b s c r e e n in a t a b s t r i p c o n t r o l o n t h e s e l ec t i on s c r e e n a n d t h e t a b s t r i p a l r e a d y

has a f r a m e . U s e NESTING LEVEL 0 if t h e r e is n o f r a m e a r o u n d t h e t a b s t r i p c o n t r o l ;

o t h e r w i s e , f o r e a c h f r a m e a r o u n d t h e t a b s t r i p c o n t r o l , i n c r e a s e t h e NESTING

LEVEL b y o n e .

T h e t a b s t r i p c o n t r o l is d e f i n e d by t h e f o l l o w i n g s y n t a x :

SELECTION-SCREEN BEGIN OF TABBEO BLOCK t a b . b l o c k FOR 10 LINES. SELECTION SCREEN TAB ( 2 0 ) t a b l USER-COMMAND comml

DEFAULT SCREEN 110. SELECTION-SCREEN TAB ( 2 0 ) t a b 2 USER-COMMAND comm2

DEFAULT SCREEN 120. SELECTION-SCREEN TAB ( 2 0 ) t a b 3 USER-COMMAND comm3

DEFAULT SCREEN 130. SELECTION-SCREEN ENO OF BLOCK t a b _ b l o c k .

394 Chapter 13 Selection Screens

This def ines a tabstrip control t ab_block with a size of 10 lines, t a b l , tab2, and t ab3 are assigned to the tab area, and the length TAB (20) def ines the width o f the tab title. You must also assign a funct ion code to each of the tab titles. For each tab title the system automatically creates a character field in the ABAP pro-gram with the same name. You can assign a text to this tab title variable before the selection screen is displayed. The field can be assigned a value dur ing the INITIALIZATION event . The subscreen is assigned to each tab title, and is dis-played when the user selects the tab.

For each tab area, the system automatically creates a s t ructure in the ABAP pro-gram with the same name. This s t ructure has three components : PROG, DYNNR, and ACTIVETAB. You can assign a value to this s t ructure dynamically to control the display of the tabstrip. You can specify a value for ACTIVETAB and DYNNR to display a particular subscreen or tab by default when the selection screen is first displayed.

Select ion Screen P rocess ing

The ABAP runt ime controls the processing of the selection screen because we d o not have access to the flow logic of the selection screen. The ABAP runt ime pro-vides a n u m b e r of selection screen events before the screen is displayed and af ter the user action on the selection screen. You can wri te y o u r own code to control the display of the screen or to react to the user action on the selection screen.

Selection screen processing starts after the INITIALIZATION event . You can pop-ulate the default value for the input field on the selection screen in the INITIAL 1ZATI0N event block. The INITIALIZATION event block is executed only once, even if the selection screen is processed several t imes.

The event AT SELECTION-SCREEN OUTPUT allows you to dynamically modify the screen before it is displayed or prepare the screen. Like PBO for a classical screen, this event block is executed eveiy t ime the screen is displayed, unlike the INI TIAL1ZATION event . The at SELECTION-SCREEN OUTPUT event is triggered when y o u click on the multiple selection but ton for the SELECT-OPTIONS input field, the dynamic selection but ton, or the tabstrip screens. You modify the screen at t r ibute in this event block. This event is specifically useful to modify the logical database selection screen i f y o u want to hide or change the at t r ibute of the screen fields wi thout modifying the code of logical database selection screen.

Key Concepts Refresher Chapter 13 409

User action on the selection screen results in events that are ei ther used to vali-date field input or possible entr ies or help request or trigger PAI processing of the selection screen.

The AT SELECT ION SCREEN event is triggered by the ABAP run t ime after the user selects EXECUTE or presses | I on the selection screen. The p rogrammer can val-idate the user input or action in the AT SELECT ION-SCREEN event . You can trigger a warning message in the AT SELECTION-SCREEN event based on y o u r validation for the screen field. A warning message is displayed, and after you press of the fields will be ready for input. You can process this while the program is executing because it is jus t a warning message. Similarly, if the program has trig-gered an e r ro r message in this event block, all of the fields will be ready for input, and the program will expect you to enter a valid value on the input screen before it proceeds with the execution.

The AT SELECTION SCREEN ON <fie ld_name> event can be used to validate a spe-cific input field <f ie ld_name>, and only that field will be ready for input if an error message is triggered in the block. You can have an AT SELECTION-SCREEN ON event for each of the input fields on the selection screen if y o u want to vali-date the user input on each of the screen.

The event AT SELECTION-SCREEN ON BLOCK <block> is triggered again when the user selects Execute, and this t ime the contents of all fields of the block are passed to the ABAP program. You should use this for validating user input . All of the fields in the block are ready for input again if an er ror message is triggered. You can control the program flow or validate the user input for the input field within this block. You have the fol lowing additional selection screen events:

• AT SELECTION-SCREEN ON RADIOBUTTON GROUP <grp> This event is triggered when the user clicks on the EXECUTE but ton on the screen, and then the content of the radio bu t ton g roup is passed to the ABAP program. You can validate the whole g roup and then, based on y o u r valida-tion. send an error message. The radio but ton g roup is ready for input if an er ror message is triggered as a result of validation within the event block.

• AT SELACTION-SCREEN ON HELP-REQUEST FOR <FIELD> This event is triggered when the user calls the F1 help on the selection screen. You can develop y o u r own help rout ine for this event . The ABAP Dictionaiy help is displayed if n o corresponding event block is def ined for this event . W e normally want to see the help f rom the ABAP Dictionaiy if the input field refers to the ABAP Dictionaiy data type.

410 Chapter 13 Selection Screens

• AT SELECTION-SCREEN ON VALUE-REQUEST FOR <FIe ld> This even t is t r iggered w h e n the use r calls va lue he lp (F4) on the screen field. T h e value he lp displays t h e poss ib le values f r o m the ABAP Dic t iona iy if n o c o r r e s p o n d i n g even t block fo r this even t is deve loped ; o the rwise , it displays the poss ib le va lue f r o m the even t block. W e w a n t t o see ABAP Dict ionary he lp if t he inpu t field re fe r s to an ABAP Dic t iona iy data type.

I m p o r t a n t T e r m i n o l o g y

You will need to u n d e r s t a n d ABAP s t a t emen t s to crea te select ion screens . You shou ld have a good u n d e r s t a n d i n g of ABAP s t a t e m e n t s to crea te select ion screens and the s t a t emen t s for sc reen layout des ign .

You can use s imple ABAP declara t ive s t a t e m e n t s such as PARAMETERS and SELECT OPTIONS to crea te i npu t fields fo r select ion screens . You can also use SELECT ION-SCREEN s t a t e m e n t s to des ign select ion screen layout . The select ion screen even t s a l low y o u to con t ro l the display o f a sc reen o r react to use r ac t ions on screen . You can also p r o g r a m F1 he lp and poss ib le F4 values fo r i npu t fields on the select ion screen by p r o g r a m m i n g the F1 and va lue he lp in the even t blocks AT SELECTION-SCREEN ON VALUE - REQUEST and AT SELECTION-SCREEN ON HELP-REQUEST.

^ i c t i c e Q u e s t i o n s

T h e pract ice ques t i ons b e l o w will he lp y o u eva lua te y o u r u n d e r s t a n d i n g of the topic. The ques t i ons s h o w n are s imilar in n a t u r e to those f o u n d o n the certifica-t ion examina t ion , bu t w h e r e a s n o n e o f these ques t ions will b e f o u n d o n the e x a m itself, t hey a l low y o u to r ev i ew y o u r k n o w l e d g e of the sub jec t . Select the correct a n s w e r s and t h e n check the c o m p l e t e n e s s o f y o u r a n s w e r s in the fol low-ing so lu t ion sect ion. R e m e m b e r that y o u m u s t select all correct a n s w e r s and on ly correct a n s w e r s to receive credi t fo r the ques t i on .

1. The defau l t select ion screen n u m b e r f o r the ABAP p r o g r a m is:

• A . 1 0 0 0

• B . 1 0 0

Practice Q u e s t i o n s C h a p t e r 1 3 411

• C. 1 1 0 0

• D . N o n e o f t h e a b o v e

2 . You c a n h a v e o n l y o n e s e l e c t i o n s c r e e n f o r an A B A P p r o g r a m .

• A. T r u e

• B. Fa l se

3 . T h e d e c l a r a t i v e s t a t e m e n t s u s e d to d e f i n e t h e s e l e c t i o n s c r e e n a r e :

• A. PARAMETERS

• B. SELECT-OPTIONS

• C. SELECTION-SCREEN

• D . N o n e o f t h e a b o v e

4 . You u s e t h e a d d i t i o n OBLIGATORY to d e f i n e t h e i n p u t f i e ld o f a p a r a m e t e r a s

a r e q u i r e d f i e l d .

• A. T r u e

• B. Fa l se

5 . W h i c h o f t h e f o l l o w i n g s t a t e m e n t s a r e c o r r e c t :

• A. T h e SELECT-OPT IONS s t a t e m e n t c r e a t e s a n i n t e r n a l t a b l e w i t h a h e a d e r

l i ne . T h e i n t e r n a l t a b l e is a l s o k n o w n as t h e s e l e c t i o n t a b l e .

• B. T h e s t r u c t u r e o f t h e s e l e c t i o n t a b l e c r e a t e d w i t h SELECT OPTIONS h a s f o u r

c o m p o n e n t s : SIGN, OPTION, LOW, a n d HIGH.

• C. Y o u c a n u s e t h e a d d i t i o n NO-DISPLAY t o h i d e t h e i n p u t field o n t h e se lec -

t i o n s c r e e n .

• D . You c a n o n l y s p e c i f y d e f a u l t v a l u e s f o r t h e LOW a n d HIGH fields o f t h e

SELECT-OPTIONS i n p u t field.

6 . Y o u r s e l e c t i o n s c r e e n c a n b e m o d i f i e d a t t h e e v e n t :

• A. AT SELECTION-SCREEN OUTPUT

• B. AT SELECTION SCREEN

• C. AT SELECTION-SCREEN on < f i e l d _ n a m e >

• D . N o n e o f t h e a b o v e

398 Chapter 13 Selection Screens

7. Which of the following s ta tements is correct regarding the event AT SELEC TION-SCREEN on HELP-REQUEST FOR <FIELD>?

• A. Will display Fl help for the input field on the selection screen.

• B. This event will display self-defined Fl help for the input field pro-g rammed in the event block and will overr ide any help possibly def ined in the ABAP Dictionary for the field.

• C. None of the above

8. You can def ine multiple e lements in a single line by def ining the e lement within the block SELECTION SCREEN BEGIN OF LINE and SELECTION SCREEN END OF LINE.

• A. True

• B. False

9. The addit ion NO- EXTENSION for SELECT -OPTIONS will allow only one line in the selection table.

• A. True

• B. False

10. The addit ion NO-1NTERVALS for SELECT-OPT IONS will allow only single fields on the selection screen.

• A. True

• B. False

11. You can def ine a selection screen as a subscreen or tabstrip control .

• A. True

• B. False

Practice Ques t ion Answers and Explanat ions

1. Correct answer: A

The default selection screen n u m b e r is 1000. You can def ine any n u m b e r of user-defined screens with o ther numbers .

Practice Question Answers and Explanations Chapter 14 13

2 . C o r r e c t a n s w e r : B

You can h a v e m o r e t h a n o n e s e l ec t i on s c r e e n w i t h i n an ABAP p r o g r a m . You

c a n h a v e o n e d e f a u l t s e l ec t ion s c r e e n a n d a n y n u m b e r o f u s e r - d e f i n e d selec-

t i on s c r e e n s .

3 . C o r r e c t a n s w e r s : A, B, C

You use PARAMETERS a n d SELECT-OPTIONS t o d e f i n e t h e i n p u t fields o n t h e

s e l ec t i on s c r e e n , a n d y o u use t h e SELECTION-SCREEN s t a t e m e n t t o f o r m a t t h e

l ayou t o f t h e se l ec t ion s c r e e n .

4 . C o r r e c t a n s w e r : A

You use t h e a d d i t i o n OBLIGATORY t o d e f i n e t h e i n p u t field PARAMETERS a n d

SELECT_0PTI0NS as r e q u i r e d fields.

5 . Cor rec t a n s w e r s : A, B, C

T h e SELECT-OPTIONS s t a t e m e n t c r e a t e s a n i n t e r n a l t ab l e w i t h a h e a d e r l ine .

T h e n a m e o f t h e i n t e r n a l t ab le is t h e s a m e as t h e SELECT-OPTIONS v a r i a b l e

n a m e . T h e r o w t y p e o f t h e i n t e r n a l t ab l e is a s t r u c t u r e w i t h t h e f o u r c o m p o -

n e n t s SIGN, OPTION, LOW, a n d HIGH. You c a n h i d e t h e i n p u t field w i t h t h e add i -

t i on NO-DISPLAY, a n d y o u can d e f i n e d e f a u l t va lues f o r e a c h o f t h e s t r u c t u r e

c o m p o n e n t s o f t h e s e l ec t i on t ab le .

6 . C o r r e c t a n s w e r : A

T h e s e l ec t i on s c r e e n can b e m o d i f i e d in t h e e v e n t b lock AT SELECT ION • SCREEN

OUTPUT.

7 . C o r r e c t a n s w e r : A

T h e e v e n t AT SELECTION-SCREEN on HELP-REOUEST FOR <FIELD> d i sp l ays t h e

F t h e l p f o r t h e i n p u t field. It d i sp l ays F1 h e l p f r o m t h e ABAP D i c t i o n a i y if F1

h e l p is n o t p r o g r a m m e d in t h e e v e n t b lock .

8 . C o r r e c t a n s w e r : A

You can d e f i n e m u l t i p l e e l e m e n t s o n t h e s a m e l ine by d e f i n i n g t h e e l e m e n t s

w i t h i n t h e b locks SELECTION-SCREEN BEGIN OF LINE a n d SELECTION-SCREEN

ENO OF LINE.

9. C o r r e c t a n s w e r : A

T h e a d d i t i o n NO EXTENSION f o r t h e SELECT-OPTIONS h i d e t h e b u t t o n f o r m u l -

t ip le s e l ec t ion . As a resu l t , t h e u s e r c a n n o t s p e c i f y m o r e t h a n o n e l i ne f o r t h e

s e l ec t i on c r i te r ia .

400 Chapter 13 Selection Screens

10 . Cor rec t a n s w e r : A

T h e a d d i t i o n n o i n t e r v a l s h i d e s t h e s e c o n d i n p u t f ield ( h i g h ) f o r t h e s e l e c t - o p t i o n s s t a t e m e n t . As a resul t a u s e r can o n l y e n t e r a va lue f o r a sin-gle i n p u t f ield ( l o w ) o r r a n g e o f va lue f o r t h e s ingle i n p u t f ie ld . T h e use r will see a s ing le i n p u t f ie ld , b u t h e will ge t t h e b u t t o n f o r mu l t i p l e se lec t ion . W h e n y o u select t h e m u l t i p l e se lec t ion d ia log box , y o u can e n t e r r anges , mu l t i p l e r anges , m u l t i p l e s ingle va lues , a n d so o n .

11 . Cor rec t a n s w e r : A

You can d e f i n e t h e se lec t ion sc reen w i t h a s u b s c r e e n o r t a b s t r i p c o n t r o l us ing

t h e ABAP l anguage dec la ra t ive s t a t e m e n t .

Take Away

You s h o u l d b e a b l e to d e s c r i b e t h e u s e o f se lec t ion s c r e e n s in ABAP p r o g r a m -

m i n g . You n e e d to u n d e r s t a n d h o w to d e f i n e t h e se lec t ion sc reen a n d s h o u l d

k n o w t h e k e y w o r d s a n d t h e syn tax to d e f i n e t h e se lec t ion s c r een . It is i m p o r t a n t

to k n o w t h e f o r m a t t i n g o p t i o n s avai lable to des ign t h e se lec t ion sc reen layout

a n d to k n o w t h e v a r i o u s e v e n t s ava i lab le f o r se lec t ion s c r eens .

You s h o u l d a lso b e able to d e s i g n s t a n d a r d se lec t ion sc reens , t abs t r ip s o n selec-

t ion sc reens , a n d s u b s c r e e n s f o r u s e o n t h e s e t abs t r ip s w i t h i n t h e ABAP p r o g r a m

a n d b e a b l e to d y n a m i c a l l y m o d i f y o r va l ida te t h e u s e r i n p u t o n t h e s c r e e n o r

p r o v i d e t h e poss ib l e e n t r i e s f o r t h e fields w i t h i n t h e a p p r o p r i a t e e v e n t b locks .

Refresher

Tab le 13 .2 s h o w s t h e key c o n c e p t s f o r se lec t ion s c r een .

Key Concept Definition

Selection screen A selection screen is an interface between the user and the program. You can define a selection screen by using the ABAP language declarative statements such as PARAMETERS and SELECT-OPTIONS, and you can design the screen layout with the declarative statement SELECTION SCREEN without using the Screen Painter or Menu Painter.

Table 13.2 Key Concepts Refresher

Summary Chapter 13 415

Key Concept Definit ion

Selection screen You can dynamically modify the selection screen during the AT events SELECTION-SCREEN OUTPUT event. You can validate the user

input on the AT SELECTION-SCREEN ON <FIELD> event for each of t h e input fields on the screen, if required.

Tabstrip control You can define subscreens for use on user-defined tabstrip controls on the selection screen with the ABAP language declarative s ta tements for screen design.

Table 13.2 Key Concepts Refresher (cont.)

S u m m a r y

You s h o u l d n o w b e a b l e t o d e s i g n a n d u s e s e l ec t i on s c r e e n s in ABAP p r o g r a m -

m i n g . You s h o u l d k n o w t h e s y n t a x t o d e f i n e s t a n d a r d s e l ec t i on s c r ee ns , s u b -

sc r eens , t a b s t r i p c o n t r o l s o n t h e s e l ec t i on s c r e e n , a n d t h e v a r i o u s e v e n t s t o

v a l i d a t e u s e r i n p u t o r c o n t r o l t h e p r o g r a m f l o w . You s h o u l d a l so k n o w t h e ABAP

s t a t e m e n t s a n d s y n t a x f o r se l ec t ion s c r e e n l ayou t f o r m a t t i n g . You s h o u l d n o w b e

a b l e t o w o r k w i t h t h e s e l ec t i on s c r e e n d e s i g n a n d u s e se l ec t ion s c r e e n s in t h e

ABAP p r o g r a m . Th i s k n o w l e d g e wi l l a l l o w y o u t o eas i ly pass th i s t o p i c o n t h e cer -

t i f i ca t ion e x a m i n a t i o n .

ABAP Object-Oriented Programming

Techniques You'll Master:

• Under s t and the objec t -or iented p r o g r a m m i n g concepts

• Describe the c o m p o n e n t s of an ABAP class

• Explain t he visibility sect ions o f a class

• Unders tand the mos t impor t an t c o m p o n e n t s of a class: a t t r ibutes , me thods , and events

• Create a local class def in i t ion and implementa t ion , and a global class

• Descr ibe the d i f fe rence b e t w e e n ins tance a n d static c o m p o n e n t s

• Def ine the ins tance cons t ruc tor and the class cons t ruc tor

m e t h o d s for a class

404 Chapter 14 ABAP Object-Oriented Programming

ABAP Objects is a complete set of object-oriented s ta tements that has been intro-duced with the ABAP language. ABAP Objects suppor ts complete object-oriented programming that includes definit ion of local and global classes, creation of objects f rom classes, and specialization of classes via inheritance. A class is the basis of an object-oriented programming language. A class is a template for an object . A class describes objects, and an object is the runt ime instance of that class. You need to def ine a class to use objects in the program. You can create global and local classes in the ABAP language. Global classes are visible to eveiy program in the system and can be used by eveiy program, whereas local classes arc visible to the program in which they are def ined.

The main objective of this chapter is to provide you the concepts of ABAP object-or iented programming with ABAP Objects. We will discuss the concept of ABAP classes because it is the foundat ion of ABAP object-oriented programming. We will discuss the key componen ts of ABAP classes such as attributes, methods , and events and the concept of visibility in a class. We will cover in detail the syntax to create local classes, attributes, methods , and events and the syntax to access and use them in ABAP programs. We will also cover global classes and the steps to create them. Finally, we will discuss class instantiation, various types o f method and attributes, their visibility, and the syntax to create object access of individual class and object componen ts in the ABAP program, as well as the syn-tax to trigger events and register handler methods .

R e a l - W o r l d Scenar io

As a technical lead on a project y o u have to explain the basics of object-ori-ented programming to the developer in y o u r team. Your deve lopment team has to develop a W e b Dynpro application and reports using ALV grids and use GUI control using control f ramework and should be aware of ABAP Objects techniques.

To use the technique you should have a good unders tanding of object-ori-ented programming, ABAP class declaration, implementat ion, and the var-ious componen ts of an ABAP class. You should be aware of encapsulation, inheritance, po lymorphism, and abstraction and should be able to use these concepts effectively in custom application development .

Objectives of this Portion of the Test Chapter 14

Object ives of th i s Por t ion of t he Test

The object ive o f this por t ion of the exam is to j u d g e y o u r knowledge abou t objec t -or iented p r o g r a m m i n g concepts . You are expected to be able to crea te ABAP classes for use in y o u r programs, bo th the def in i t ion part and the imple-men ta t i on part , and to be able to use global classes for applicat ion deve lopmen t . You should be able to explain the var ious c o m p o n e n t s of an ABAP class a n d t he visibility sect ions such as public, private, and pro tec ted sections. You should be able to create ABAP Objects p rograms that conta in all useful objec t -or ien ted pro-g r a m m i n g techniques .

Key Concepts Refresher

It's impor t an t to unde r s t and the ABAP Object concepts because SAP is develop-ing n e w appl icat ions using t he objec t -or ien ted p r o g r a m m i n g techniques . This chapter will in t roduce the basics of objec t -or ien ted p r o g r a m m i n g concepts and the key c o m p o n e n t s requi red to create an ABAP class. The key c o m p o n e n t s dis-cussed in this chap te r are at t r ibutes , me thods , and events . Advanced topics wi th regard to ABAP Objects p r o g r a m m i n g are covered in Chapter 17, Class Identifi-cation Analysis and Design.

O b j e c t - O r i e n t e d P r o g r a m m i n g C o n c e p t s

Objec t -or ien ted p r o g r a m m i n g involves p r o g r a m m i n g using objects . Business objects such as cus tomers , materials , and purchase o r d e r s a re examples of real-wor ld objects . The real-world objects have states and behaviors . For example , a purchase o r d e r has states such as purchase o r d e r n u m b e r , v e n d o r n u m b e r , a n d purchas ing organizat ion and behaviors such as create purchase o rder , display purchase order , and change purchase o rde r . The goal of objec t -or ien ted pro-g r a m m i n g is to map the real-world object to a so f tware object as accurately as possible. This helps the bus iness user and the deve loper c o m m u n i c a t e m o r e effectively wi th each o the r .

The state of the real-world objec t is r ep resen ted by at t r ibutes , and the behav ior of the real-world object is r ep resen ted by me thods . A m e t h o d is a block of code, such as a func t ion m o d u l e or subrou t ine , associated wi th the object . Thus, a soft-w a r e objec t consists of a t t r ibutes and me thods .

420 Chapter 14 ABAP Object-Oriented Programming

Object-orientcd programming encapsulates at tr ibutes and methods and provides a def ined interface (Methods) to access the at tr ibutes of the object . The outside world can communica te with the object using the defined interface. If you want to access the attributes of the object, you call a method to do so, and this method has parameters that de t e rmine what data you must pass in and what data y o u get back f rom the me thod . The internal status of the object and its implementa t ion is h idden f rom the outside world and cannot be modif ied or viewed. The attr ibutes of the object can only be changed by calling public me thods of the object and cannot be changed directly. You can change the at tr ibutes directly if they are public, but usually the at tr ibutes are private, so they are usually changed by calling public methods .

The object-oriented programming model supports following characteristics:

• Abs t r ac t ion p rocess The abstraction process refers to mapping the real-world processes in a class as accurately as possible. Abstraction is an essential e lement of object-ori-ented programming and is achieved through the use of hierarchical classifica-tion. A complex object can be broken into more manageable pieces. Each object describes its own unique behavior.

• Encapsu la t ion The implementa t ion of the class is h idden and can only be accessed by means of the class interface, that is, by calling the me thods of the class. The purpose of a class is to hide complexity f rom the outside world. Each method and at t r ibute can be private or public. A public method can be accessed by an external user, for example, an ABAP program. The private at tr ibute or meth-ods can be accessed directly only f rom within the class itself and can be accessed by an external application through public me thods only.

• I nhe r i t ance Inheritance means deriving one class f rom another . The attributes and meth-ods arc inherited f rom the higher-level class, known as the superclass and can be extended: that is, the methods can be redefined, and new componen ts can be added. A class inherits the attributes and methods f rom the parent class and can def ine n e w componen ts that make it un ique within its class hierarchy.

• P o l y m o r p h i s m Polymorphism is where objects of different classes react in different ways to the same method call. It can be achieved through inheri tance or through the use of Interfaces.

Key Concepts Refresher Chapter 14

ABAP Objects

ABAP Objects is an objected-oriented extension of the ABAP language, and it is n o w also the term used to refer to the ent ire ABAP language. ABAP Objects sup-ports object-oriented programming techniques.

It basically consists of a set of ABAP s ta tements that suppor t object-oriented pro-gramming such as definit ion of classes, creation of objects f rom classes, special-ization of classes via inheritance, independent interfaces that can be used in classes, and the event concept that is integrated into the language.

A B A P Class

Classes are the foundat ion of object-oriented programming. A class is a blueprint or template for objects. A class describes an object, and the object is a run t ime instance of that class. You can create any n u m b e r of objects based on a single class, and each instance (object) of the class has its own unique identity and its own set of values for its at tr ibutes.

Classes in ABAP Objects can be declared ei ther locally within the application w h e r e they are to be used or globally as reposi toiy objects. The advantage of cre-ating global classes is that they can be reused in many different applications. Glo-bal classes are def ined in the Class Builder (Transaction SE24) in the ABAP Workbench . Global classes are stored centrally in the Repository. Global classes can be used by any program in the SAP system. Local classes are def ined locally in the ABAP program and are visible in the program in which they are def ined.

Local Classes

Local classes are def ined within an ABAP program and can be used only in the program in which they are def ined. Listing 14.1 displays the most important componen t of a local ABAP class in a code template. In the following section we will cover individual componen t s of the class including the visibility concepts.

CLASS CL1 DEFINITION. PUBLIC SECTION.

OATA: d l . d2. METHODS: Ml. EVENTS: EV1.

PROTECTED SECTION. DATA: d3. d4.

408 Chapter 14 ABAP Object-Oriented Programming

HETHOOS: M2. EVENTS: EV2.

PRIVATE SECTION. OATA: d5. d6. HETHOOS: M3. EVENTS: EV3.

ENOCLASS. CLASS CL1 IMPLEMENTATION.

METHOD Ml . ENDMETHOD. METHOD M2. ENDMETHOD. METHOO M3. ENDMETHOD.

ENDCLASS.

Listing 14.1 Template for ABAP Class

A class de f in i t i on consists o f a declarat ion part and an imp lementa t ion part. The

declarat ion part o f the class is w i t h i n the statement block CLASS.. . ENDCLASS.

Fo l low ing is the syntax for the class declarat ion:

CLASS <class_name> DEFINITION. ENDCLASS.

The declarat ion part o f the program contains the de f in i t i on o f all o f the compo-

nents o f the class. This includes attr ibutes, methods, and events. A n y methods

def ined in the DEFINITION part must be imp lemented in the imp lementa t ion sec-

t ion o f the class.

The methods o f the class are imp lemen ted in the f o l l ow ing statement block:

CLASS <class_name> IMPLEMENTATION. METHOO metha. ENDMETHOD. METHOO methb. ENDMETHOD.

ENDCLASS.

Each component o f the class must be assigned to one o f the f o l l ow ing three vis-

ib i l i t y sections. A l l o f the components are vis ible w i t h i n the class. A l l compo-

nents o f the class are in the same namespace, w h i c h means that all components

o f the class must have a un ique name.

Key Concepts Refresher Chapter 13 409

The class components can be declared in three v is ib i l i t y areas: PUBLIC, PRIVATE,

and PROTECTED. W h e n de f in ing local classes in ABAP Objects, y o u must f o l l ow

the syntactical sequence o f PUBLIC SECTION. PROTECTEO SECTION, and PRIVATE

SECTION.

Global Classes

Global classes and interfaces are stored in a class l i b ra i y and are vis ible system-

wide . Global classes can be used by eve iy program in the system. The Class

Bui lder a l lows y o u to create and mainta in global classes and interfaces. You can

use the Class Browser to display global classes, interfaces, o r business object

types f r o m the class l i b ra iy . The Class Browser is an integrated part o f Class

Bui lder and can be started via Transact ion CLABAP.

To create a new global class, enter the name o f the class o n the in i t ia l screen o f

the Class Bui lder (Transaction SE24) and select CREATE. The name o f the class

should start w i t h ZCL_<meaningful_name>. The CREATE CLASS d ia log box appears

w i t h the name o f the class. Figure 1 4 . 1 displays the Create Class dialog box.

Claw ZCl_0E10 Os(r««o lOorooGtctoaOast hsuntanco

CIOMTH* • Usual ABAP Class

EK«CACOCIO»

Pefs»s»e« class lost Cos* (ABAP Urw)

OrtyMotttt) • Saw x

Figure 14.1 Create Global Class Dialog Screen

You need to populate the f o l l ow ing detai l on the create class d ia log box.

• D E S C R I P T I O N

Enter a short text descr ib ing the class.

• I N S T A N T I A T I O N

Selects the instant iat ion op t ion . You have the op t ion to select PUBLIC, PRO-

TECTED. PRIVATE, o r ABSTRACT (see next section. Class V is ib i l i t y and Instantia-

t ion , as wel l ) :

424 Chapter 14 ABAP Object-Oriented Programming

• PUBLIC

Usually y o u select t h e publ ic ins tant ia t ion . This m e a n s the use r can crea te an ins tance of this class wi th the CREATE OBJECT s t a t emen t .

• PROTECTED

Protected ins tant ia t ion specif ies tha t o n l y inher i t ed classes o r the re levant class itself can crea te the ins tances of this class.

• PRIVATE

Private ins tan t ia t ion specif ies tha t on ly the re levan t class itself can crea te ins tances of the class using its o w n m e t h o d .

• ABSTRACT

You select the abstract ins tan t ia t ion to d e f i n e an abs t rac t class. An abs t rac t class is used as a t emp la t e to crea te a subclass. You canno t crea te an ins tance o f this class. You can access such a class w i t h the static a t t r ibu te o r wi th its subclasses.

• CLASS TYPE

Y o u h a v e t h e o p t i o n t o s e l e c t U S U A L A B A P CLASS, EXCEPTION CLASS, PERSIS-

TENT CLASS, o r TEST CLASS:

• U S U A L A B A P CLASS

This is the s t anda rd ABAP class and is discussed in this chap te r .

• PERSISTENT CLASS

The m a p p i n g of ABAP Objec t s classes to relat ional da tabase tables is r e fe r red to as object-relat ional m a p p i n g or 0 / R mapp ing . Classes wi th 0 / R m a p p i n g are re fe r red to as pers is tent classes.

• EXCEPTION CLASS

These a re special classes used fo r class-based excep t ion hand l ing .

• TEST CLASS

This is a test call and canno t b e ins tan t ia ted .

For o u r e x a m p l e w e w o u l d select USUAL ABAP CLASS rad io b u t t o n .

• F I N A L

You can d e f i n e the final class by select ing the checkbox . This m e a n s y o u can-no t c rea te the subclass fo r this class.

• O N L Y M O D E L E D

I f y o u select this op t ion , the class is no t s to red in class l ibra iy and y o u canno t add re s s it at r u n t i m e o r test it.

Key Concepts Refresher Chapter 13 425

Click o n t h e SAVE b u t t o n a f t e r y o u h a v e e n t e r e d t h e r e l evan t detai l o n t h e c r ea t e class d ia log s c r een . You have to p r o v i d e t h e package n a m e a f t e r y o u click o n t h e SAVE b u t t o n o n t h e d ia log s c r e e n . T h e n t h e class e d i t o r a p p e a r s w i t h t h e m e t h o d t ab se lec ted . F r o m h e r e o n y o u can d e f i n e ind iv idua l c o m p o n e n t s o f t h e class. F igure 14 .2 d i sp lays the class e d i t o r s c r e e n tha t is d i sp l ayed a f t e r y o u click o n SAVE o n t h e CREATE CLASS d i a l o g w i n d o w .

Class Builder: Change Class ZCL_DEMO »» « .". n t a <• l « a T ^ x , w ir-pMmMJOO* M W W O O CUKf«nUiucl.Y C.K',

Ci«s rt«f*« HLJfcltO inptomcrtcd/hxtrtc P r « * O M , W«»1*:« , FrxodS A|««Jt« M f f M i , EwfrtS , TyCW , A * « «

MMKX) lovoi v i a Mo O x n p a c i

Figure 14.2 Class Editor Screen to Create a Global Class

You can d e f i n e ind iv idua l c o m p o n e n t s o f t h e class such as a t t r ibu te s , m e t h o d s , even t s , f r i ends , a n d so o n in t h e class e d i t o r . W e will d i scuss t h e d e f i n i t i o n o f t h e ind iv idua l c o m p o n e n t s la ter in t h e r e l evan t sec t ions in th is c h a p t e r .

C l a s s V i s i b i l i t y a n d I n s t a n t i a t i o n

T h e vis ibi l i ty s ec t ions d e f i n e t h e visibi l i ty o f t h e c o m p o n e n t s o f t h e class a n d t h e r e f o r e t h e in t e r f ace o f t h e class to t h e app l i ca t ion .

• P u b l i c s e c t i o n

All c o m p o n e n t s dec la red w i t h i n t h e pub l i c sec t ion can b e accessed b y a n y use r s o f t h e class. T h e m e t h o d s o f t h e class can a lso access t h e pub l i c c o m p o -n e n t s o f t h e class a n d a n y classes tha t i nhe r i t f r o m it. T h e p u b l i c c o m p o n e n t s o f t h e class f o r m t h e in t e r f ace b e t w e e n t h e class a n d t h e use r . T h e u s e r can on ly access t h e p u b l i c c o m p o n e n t s o f t h e class.

• P r i v a t e s e c t i o n

T h e c o m p o n e n t s tha t a r e d e c l a r e d in the p r iva t e sec t ion a r e o n l y vis ib le to t h e m e t h o d o f t h e class a n d a r e o n l y access ib le f r o m ins ide t h e class i tself. You can p r o t e c t c o m p o n e n t s aga ins t access f r o m t h e o u t s i d e by cha rac te r i z ing t h e m as p r iva te a t t r i bu te s . T h e p r iva te c o m p o n e n t s a re n o t v is ib le to t h e ou t -s ide use r . Using t h e p r iva t e vis ibi l i ty sec t ion , y o u can h i d e o r e n c a p s u l a t e t h e i n f o r m a t i o n f r o m the o u t s i d e use r . C h a n g i n g t h e p r iva t e c o m p o n e n t d o e s n o t

412 Chapter 14 ABAP Object-Oriented Programming

a f fcc t t h e o u t s i d e u s e r . As l o n g as t h e c lasses i n t e r f a c e (pub l i c c o m p o n e n t s )

r e m a i n s t h e s a m e , t h e o u t s i d e u s e r d o c s n o t n o t i c e t h e c h a n g e s in t h e class.

• P ro tec ted sec t ion

All c o m p o n e n t s d e c l a r e d in th i s s e c t i o n c a n b e acces sed by t h e m e t h o d o f t h e

class a n d t h e subc la s ses . P r o t e c t e d c o m p o n e n t s r e p r e s e n t t h e i n t e r f a c e

b e t w e e n t h e class a n d its s u b c l a s s e s b u t a r e n o t t h e p a r t o f t h e i n t e r f a c e

b e t w e e n t h e class a n d t h e o u t s i d e w o r l d .

Lis t ing 1 4 . 2 d i sp l ays t h e d e c l a r a t i o n o f t h e pub l i c , p r iva t e , a n d p r o t e c t e d c o m p o -

n e n t s o f t h e class.

CLASS v e s s e l DEFINITION

S u p e r c l a s s d e f i n i t i o n

CLASS v e s s e l DEFINITION. PUBLIC SECTION.

METHODS: c o n s t r u c t o r . d r i v e IMPORTING s p e e d _ u p TYPE i . g e t _ i d RETURNING v a l u e ( i d ) TYPE i .

PROTECTED SECTION. DATA: speed TYPE i .

max_speed TYPE i VALUE 100. PRIVATE SECTION.

CLASS-DATA o b j e c t _ c o u n t TYPE i . DATA id TYPE i .

ENDCLASS.

CLASS v e s s e l IMPLEMENTATION

S u p e r c l a s s i m p l e m e n t a t i o n

CLASS v e s s e l IMPLEMENTATION. METHOD c o n s t r u c t o r .

o b j e c t _ c o u n t - o b j e c t _ c o u n t + 1 . i d - o b j e c t _ c o u n t .

ENDMETHOD. METHOS d r i v e .

s peed - speed + s p e e d _ u p . IF speed > max_speed .

speed - max_speed .

Key Concepts Refresher Chapter 13 427

ENDIF. ENDMETHOD. METHOD g e t _ i d .

id - me - > i d . ENOMETHOD.

ENOCLASS * *

Listing 14.2 Public, Private, and Protected Components in a Class

External users of the class (e.g., an execu tab le ABAP p r o g r a m ) can o n l y access the publ ic c o m p o n e n t s . The pr iva te and p ro t ec t ed c o m p o n e n t s are invisible to the external use r and a re t he r e fo r e in ternal to the class o r the class and its subclasses in the case of p ro tec ted c o m p o n e n t s . This enab les y o u to change the in ternal i m p l e m e n t a t i o n of the class w i t h o u t af fec t ing the external user . By ass igning the c o m p o n e n t s to the a p p r o p r i a t e visibility sect ion, y o u can d e t e r m i n e wh ich com-p o n e n t s shou ld b e par t o f the use r in ter face and wh ich c o m p o n e n t s shou ld be encapsu la ted .

For a global class the visibility o f individual c o m p o n e n t s is specif ied in the class ed i tor . Figure 14.3 displays the visibility op t ions in the class ed i to r fo r m e t h o d s . Similarly, y o u have the op t ion to specify visibility f o r o t h e r c o m p o n e n t s of the class.

Class Builder: Change Class ZCL_DEMO * M t c o t 0 Co f tSBto* 0 O a n « y r j r x x t Cv»t'. oocumtrt jeon

C i « s l _ | z a j c n o

PTOCXOM , , , A t r t - I M , E v f t i , , A » « «

3 C v 3 i * 0 A M t » * ( « v « r . : o H r r w o i l n« ta»vc * t t o t h o d P u b l i c PUHC M t r o d 1 METH002 l n i t s a c « Mothod P r i v a t *

HEIMCO» S t a t i c r t « t h o J P u b l i c staoc M»Cod 3

Figure 14-3 Method Definition for Global Class with Visibility

In add i t ion to t h e spec i fy ing the visibility o f t h e class c o m p o n e n t s , y o u can also specify the ins tant ia t ion type fo r the class. The ins tant ia t ion type de f ines w h o can crea te the ob jec t s o f t h e class. Fol lowing are the t h r ee types o f ins tan t ia t ion fo r the class:

• Public ins tan t ia t ion

• Protec ted ins tant ia t ion

• Private ins tant ia t ion

414 Chapter 14 ABAP Object-Oriented Programming

The syntax to control the instantiation of a local class is as follows:

CLASS <class_names> DEFINITION CREATE PUBLIC | PROTECTED | PRIVATE

ENDCLASS.

If you d o not specify the instantiation for the class, then the class is by default publicly instantiated. Only publicly instantiated classes can be used by the user to create objects for the class. Protected instantiated classes allow the creation of objects in me thods of subsclasses. A class with private instantiation can create objects within the class itself, but n o w h e r e else. Public instantiation classes nor-mally provide a static componen t that can be accessed by the outside, which will provide the reference to the object that the class itself created.

For the global class you specify the instantiation type in the create class dialog w i n d o w as shown in Listing 14.2 above.

Instance and Static Components

In addit ion to the visibility, you must def ine whe the r the componen t is an instance componen t or a static componen t . The instance componen t s exist for each instance of the class (one copy for each object), and they are independen t of each other . The static componen t s exist once per class, no mat ter h o w many instances of this class there are. and all objects of the class share this o n e copy. The instance componen t s are addressed using the reference variable point ing to the object in quest ion, whereas static componen ts are addressed using the name of the class to which they belong. You d o not need to create an instance of the class (object) to access the static components .

The syntax to def ine static componen ts and instance componen t s is the same except that static componen t defini t ions begin with the CLASS keyword . For glo-bal class def ini t ions in the Class Builder y o u mus t specify for each componen t whe the r it's a static componen t or an instance componen t . Figure 14.4 displays instance and static componen ts for a local class.

For the global class the instance and the static componen t s are def ined in the class editor . Figure 14.3 displayed the instance and static method definit ion for the global class. Figure 14.5 displays the instance and static at tr ibutes defini t ion for the global class in the class editor.

Key Concepts Refresher Chapter 14 429

CLASS c . t e a n DEFINITION PUBLIC SECTION

TYPES b i k e r . r e f TYPE REF b i k e r . r e f . t a b TYPE

TO c . b i k e r . STANDARD TABLE OF b i k e r . r e f

WITH DEFAULT KEY. BEGIN OF s t a t u s . l m e . t y p e .

r i a g ( i ) TYPE C. c. 1 . c. c. i . c. 1 .

s t a t u s . l i n e . t y p e c l a s s . c o n s t r u c t o r

t o x t l ( 5 ) i d t e x t 2 < 7 ) t e x t l < 6 ) gear t e x t 4 ( 7 ) speed

END OF CLASS-METHODS

TYPE TYPE TYPE TYPE TYPE TYPE TYPE

METHODS c o n s t r u c t o r . — c r e a t e . t o a a . s e l e c t i o n , e x e c u t i o n

PRIVATE SECTION CLASS-DATA tea«_ne«bers TYPE 1

c o u n t e r TYPE DATA i d TYPE 1.

s t a t u s . l i n e TYPE s t a t u s _ l i n e _ t y p e . s t a t u s _ l i s t TYPE SORTED TABLE OF s t a t u s . l 1 n e _ t y p e

WITH UNIQUE KEY b i k e r . t a b TYPE b i k e r . r e f . t a b . b i k o r _ $ o i e c t i o n LIKE b i k e r . t a b . b i k e r LIKE LINE OF b i k e r . t a b

METHODS » n t e . l 1 St ENOCLASS

i d .

Static Method

lni t jn<c Method

Static Attribute

Instance Attribute

Figure 14.4 Instance and Static Components Declaration

Clan Ddfcwr Chang* Class zcl_demo

y n « <> o .". H ' / U local k- u t a n O C e n w w M O O n u c m u u

ClKftCMlK* ZCL.DENO (TpkywWO I lr*ct«« (r««S4<I) , I M I C M , Fn«KSt AotU»t , M t e o J t E»«rt* , T«» i , A U w

a •:- i * y H j g 1 N 46 F*M

MA T F ft 1 A t

l ev* NATRTY \ M (

\ M c

PT-/ATF

T , AiSOOJlfl T>p» ft*****

r w i C M l N i

P L A N T

M A T E R I A L T Y T E

H M K T A M T M tntrto A » « « O

NATRTY \ M (

\ M c

PT-/ATF lyt* T y p *

W R < S _ D

H T A * 1

w fnmmtm w w r • .

• T y w B

I H D U S T R Y S E C T C R T y p e

T » f « >

H W S M • _ f i v M a y * * * *

3 h f

Figure 14.5 Instance and Static Attribute Definition for a Global Class

Objects

Objects are instances o f a class. A class contains the descr ipt ion o f the object and describes all characteristics that all objects o f the class have in common. The pro-cess o f creating a discrete object or instance o f a class in m e m o i y is called instan-t iat ion. Objects are created using the syntax C R E A T E O B J E C T r e f _ n a m e . where

430 Chapter 14 ABAP Object-Oriented Programming

r e f _ n a m e m u s t b e a s u i t a b l e t y p e o f r e f e r e n c e va r i ab le . T h e s t a t e m e n t CREATE

OBJECT c r e a t e s a n o b j e c t in t h e m e m o r y o f t h e a p p l i c a t i o n .

T h e s y n t a x t o c r e a t e t h e o b j e c t is as f o l l o w s , w h e r e CL_ARTICLE_HIERARCHY is a

g l o b a l class:

OATA: r e f _ v a r TYPE REF TO c l _ a r t 1 c l e _ h 1 e r a r c h y . START-OF-SELECT ION. CREATE OBJECT r e f . v a r .

You c a n u s e g l o b a l a n d local c lasses to c r e a t e o b j e c t s w i t h t h e CREATE OBJECT

s t a t e m e n t .

Attr ibutes

A t t r i b u t e s a r e i n t e r n a l d a t a o b j e c t s w i t h i n a class t h a t can h a v e a n y d a t a t ype , f o r

e x a m p l e . ABAP types , t y p e s f r o m t h e D i c t i o n a r y , o r r e f e r e n c e s . T h e s t a t e o f t h e

o b j e c t is d e t e r m i n e d by t h e va lues o f its a t t r i b u t e s . A t t r i b u t e s can h a v e local

t ypes , g loba l d a t a t ypes , o r r e f e r e n c e d a t a t y p e s . F i g u r e 1 4 . 6 d i sp l ays t h e

a t t r i b u t e d e c l a r a t i o n w i t h t h e class .

CLASS C_b1 kor DEFINITION PUBLIC SECTION

METHODS constructor IMPORTING toa«_i<J TYPE i «««bors TYPE i . select_action. s ta tu : J ino EXPORTING H i * TYPE c_t«a«->statu$jmo_typ«

PRIVATE SECTION CLASS-OATA countor TYPE 1 DATA Id TYPE 1 .

bifco TYPE REF TO c_McycU $*ar_status TYPE I VALUE 1 ~ 1 spood.status TYPE i VALUE 0 I

METHODS t>lk*r_act1on IMPORTING actTOn TYPE \ 6HQCLASS

Figure 14.6 Attribute Declaration in a Class

In c l a s s e s , y o u can o n l y u s e t h e TYPE a d d i t i o n w h e n d e f i n i n g a t t r i b u t e s . T h e LIKE

r e f e r e n c e is a l l o w e d o n l y f o r local d a t a t y p e s o f s y s t e m va r i ab l e s s u c h as SY -

DATUM, SY - UNAME a n d so o n . W i t h TYPE REF TO, t h e a t t r i b u t e can b e t y p e d as a ref-

e r e n c e va r i ab le . T h e r e f e r e n c e t y p e c a n b e c lasses , i n t e r f ace s , o r t y p e s .

T h e READ-ONLv a d d i t i o n m e a n s t ha t a p u b l i c a t t r i b u t e t h a t w a s d e c l a r e d w i t h t h e

OATA s t a t e m e n t c a n b e r e a d f r o m o u t s i d e b u t can o n l y b e changed by m e t h o d s o f

t h e s a m e class . T h e READ ONLY a d d i t i o n c a n o n l y b e spe c i f i ed in t h e p u b l i c visi-

bi l i ty s e c t i o n o f a class d e c l a r a t i o n o r in a n i n t e r f a c e d e f i n i t i o n . T h e READ ONLY

S t a t i c A t t r i b u t e

R e f e r e n c e V a r i a b l e /

R e f e r e n c e s C l a s s

P r i v a t e A t t r i b u t e

Key Concepts Refresher Chapter 13 417

attr ibute for the global class can be specified in the class edi tor by selecting the READ-ONLY checkbox for the attr ibute, as displayed in Figure 14.5 above.

The syntax to declare a READ ONLY attr ibute is as follows:

OATA: v a r f a b l e l TYPE I READ-ONLY. CLASS-DATA v a r i a b l e 2 TYPE I READ ONLY.

You can protect at tr ibutes against access f rom outs ide by declaring them as pri-vate at tr ibutes.

• Private attr ibutes Private at tr ibutes cannot be addressed directly f rom outs ide the class and are not visible to the outside user. The f r iendship concept is an exception to this rule. You can find more informat ion about the f r iendship concept in Chapter 17, Class Identification Analysis and Design.

• Public attr ibutes Public at tr ibutes can be accessed directly by the outside user. The public com-ponents of the class are somet imes collectively known as the class's interface. This includes the public at tr ibutes and methods .

• Instance attr ibutes Instance attr ibutes are def ined with the DATA keyword and exist once per object . The lifetime of an instance at t r ibute is linked to the lifecycle of the object .

• Static at tr ibutes Static at tr ibutes are defined with the CLASS-DATA keyword, and they exist once per class, no mat ter how many instances there are for the class. They are visible to all of the run t ime instances of the class and usually contain infor-mation, which applies to all instances of the class, for example, a counter for the total n u m b e r of objects. Static at tr ibutes are also referred to as class at tr ibutes.

In the Class Builder, y o u can simply enter the at tr ibutes and their propert ies in the ATTRIBUTES tab as displayed in Figure 14.7, which displays the at tr ibutes def-inition for a global class.

In addit ion to instance and static attributes, you can declare constant attributes, whose values arc defined during declaration and cannot be changed af terward.

The syntax to declare a constant at t r ibute in a local class is:

CONSTANTS: c o n s t l TYPE C VALUE ' A ' .

432 Chapter 14 ABAP Object-Oriented Programming

Class Builder: Change Class ZCL DEMO y tt - « . A A 7 D l o c 4 Types w tr t tanwtJbcA w M w c n • Conouctcr • CtoM ccmeucftx Ck>M •>XUT«-»tO«l

O t t f H W U c * Z C I . K M 0 tn(4Mr«nMd 1 h » M £f«v1M«3)

An-6U«S

a ® . & : » y & M l »

ASKM* R»»Or ty Tye.f»j At tOC*»d Tyt* » l t»««»» MATERIA!. V P * KATVR AMMMIMjaMf PI ANT kwurc* <Pt6t< Typ«

p y p » ' f t * f r y p *

WERXSJt • •-wt MATERIAL TYP£ * « * > : « <Prv««

Typ« p y p » ' f t * f r y p *

HTART * INOOSIRYSECTOR St tDtAaPUM

Typ« p y p » ' f t * f r y p *

HBRSH * t .Jjvjy v»<tiy CONST 1 C<oUnr* P\£>t<

Typ« p y p » ' f t * f r y p * C * A

*

Figure 14.7 Attributes Definition for a Global Class

The constant at t r ibute is accessed with the following syntax:

WRITE: / ZCl_DEMO->constl. WRITE: / c l a s s_name->cons tan t .

Methods

Methods are internal procedures in a class that def ine the behavior of an object . In o ther words , they are the blocks of code that contain the logic. Me thods can access all at tr ibutes of the class and therefore can change the values of the at tr ibutes of the object . The private at t r ibutes of the class can be changed by the method of the same class.

Me thods are declared in the DEFINITION section for the local class and in the class edi tor for the global class. Figure 14.3 displayed the method defini t ion for the global class in the class editor . All me thods declared in the declaration part must be implemented in the implementa t ion part of the class. M e t h o d s must be assigned to a visibility section, j u s t like attributes. Me thods assigned to the PUB LIC SECTION can be called f rom outside the class, whereas the me thods assigned to the PRIVATE SECTION can be called only wi thin the same class.

Like the at tr ibutes of the class, you can declare instance methods or static meth-ods. Instance methods are declared using the METHODS sta tement , whereas the static me thods are declared using the CLASS METHODS statement . Instance meth-ods can access all of the at tr ibutes of the class (i.e.. both instance and static) and can trigger all events of the class. Static me thods can access only the static at tr ibutes of the class and can trigger only static events. Static me thods can be called wi thout instantiating the class, whereas instance methods are valid for the

Key Concepts Refresher Chapter 13 419

specific instance o f the class. Hence, y o u need to instantiate the class (CREATE

OBJECT) to access the instance method.

Static methods are def ined at the class level. They can be d i rect ly accessed

th rough the class and do not need an instance. Static methods can be accessed by

al l o f the instances o f the class, and f r o m outside the class (as long as they are

publ ic). You have to create an object o f the class to call an instance method. Both

instance methods and static methods are imp lemented in the imp lemen ta t i on

part o f the class.

The instance and static methods are imp lemented between the f o l l ow ing state-

ment b lock:

CLASS 1c l_c lass IMPLEMENTATION. METHOD method_name. ENDMETHOD.

ENOCLASS.

The me thod statement does not requi re any addi t ions because the propert ies and

signature o f the me thod are def ined in the declarat ion part o f the class. List ing

14.3 and List ing 14.4 display the declarat ion and the imp lementa t ion o f the

methods.

CLASS c. team DEFINITION. PUBLIC SECTION.

TYPES: b i k e r . r e f TYPE REF TO c . b i k e r . b 1 k e r . r e f . t a b TYPE STANDARD TABLE OF b i k e r . r e f

WITH DEFAULT KEY. BEGIN OF s t a t u s . l i n e . t y p e .

f l a g ( l ) TYPE c, t e x t l ( 5 ) TYPE c i d TYPE i t e x t 2 ( 7 ) TYPE c t e x t 3 ( 6 ) TYPE c gear TYPE i t e x t 4 ( 7 ) TYPE c speed TYPE i

ENO OF s t a t u s . l i n e . t y p e . CLASS-METHOOS: c l a s s . c o n s t r u c t o r . " S t a t i c A t t r i b u t e METHOOS: c o n s t r u c t o r .

c rea te . t eam. s e l e c t i o n , execu t i on .

PRIVATE SECTION.

434 Chapter 14 ABAP Object-Or iented Programming

CLASS-OATA: t e a m . m e m b e r s TYPE i . c o u n t e r TYPE 1 .

DATA: i d TYPE i .

s t a t u s . l i n e TYPE s t a t u s . l i n e . t y p e . s t a t u s . l i s t TYPE SORTEO TABLE OF s t a t u s . l i n e . t y p e

WITH UNIQUE KEY i d . b i k e r . t a b TYPE b i k e r _ r e f _ t a b . b i k e r . s e l e c t i o n LIKE b i k e r . t a b . b i k e r LIKE LINE OF b i k e r . t a b .

METHODS: w r i t e . l i s t . ENDCLASS. - c . t e a m DEFINITION

Listing 14.3 Declaration of Method in a Local Class

CLASS c . t e a m IMPLEMENTATION.

METHOD c l a s s . c o n s t r u c t o r . t i t l - 'Team members ? ' . CALL SELECTION-SCREEN 100 STARTING AT 5 3 . IF s y - s u b r c NE 0 .

LEAVE PROGRAM. ELSE.

t e a m . m e m b e r s - m e m b e r s . ENDIF.

ENDMETHOD. " c l a s s . c o n s t r u c t o r

METHOO c o n s t r u c t o r , c o u n t e r - c o u n t e r + 1 . i d - c o u n t e r .

ENDMETHOD. " c o n s t r u c t o r

METHOD c r e a t e . t e a m . DO t e a m . m e m b e r s TIMES.

CREATE OBJECT b i k e r EXPORTING

t e a m . i d - i d members - t e a m . m e m b e r s .

APPEND b i k e r TO b i k e r . t a b . CALL METHOO b i k e r - > s t a t u s _ l i n e

IMPORTING l i n e - s t a t u s . l i n e .

APPEND s t a t u s . l i n e TO s t a t u s . l i s t . ENDOO.

ENDMETHOD. " c r e a t e . t e a m

Key Concepts Refresher Chapter 13 435

METHOO s e l e c t i o n . CLEAR b i k e r . s e l e c t i o n . 00.

REAO LINE s y - i n d e x . IF s y - s u b r c <> 0 . EXIT. ENOIF. IF s y - l i s e l + 0 ( l ) - ' X ' .

READ TABLE b i k e r . t a b INTO b i k e r INDEX s y - i n d e x . APPEND b i k e r TO b i k e r . s e l e c t i o n .

ENDIF. ENDOO.

CALL METHOD w r i t e . l i s t . ENDMETHOD. " s e l e c t i o n

METHOO e x e c u t i o n . CHECK NOT b i k e r . s e l e c t i o n IS INITIAL. LOOP AT b i k e r . s e l e c t i o n INTO b i k e r .

CALL METHOD b i k e r - > s e l e c t . a c t i o n . CALL METHOD b i k e r - > s t a t u s _ l i n e

IMPORTING 1 i n e - s t a t u s . l i n e .

MODIFY TABLE s t a t u s . l i s t FROM s t a t u s . l i n e . ENDLOOP.

CALL METHOD w r i t e . l i s t . ENDMETHOD. " e x e c u t i o n

METHOO w r i t e . l i s t . SET TITLEBAR ' T I T ' , s y - l s i n d - 0 . SKIP TO LINE 1 . POSITION 1 .

LOOP AT s t a t u s . l i s t INTO s t a t u s . l i n e . WRITE: / s t a t u s _ l i n e - f l a g AS CHECKBOX,

s t a t u s . l i n e - t e x t l . s t a t u s . l i n e - l d . s t a t u s . l i n e - t e x t 2 . s t a t u s . l i n e - t e x t 3 . s t a t u s . l i n e - g e a r . s t a t u s . l i n e - t e x t 4 . s t a t u s . l i n e - s p e e d .

ENDLOOP. ENDMETHOD. " w r i t e . l i s t

ENOCLASS. " c . t e a m IMPLEMENTATION

Listing 14.4 Implemen ta t ion of M e t h o d s in a Local Class

422 Chapter 14 ABAP Object-Oriented Programming

Methods have interface parameters, sometimes referred to as the methods ' signa-tures, that enable them to receive values when they are called and pass values back to the calling program. They can also have exceptions. Methods can have any n u m b e r of EXPORTING, IMPORTING, and CHANGING parameters, which are mutually exclusive. All parameters of these categories can be passed by value or reference.

Listing 14.5 displays the method declaration and implementa t ion with EXPORT ING and IMPORTING parameters .

CLASS counter DEFINITION. PUBLIC SECTION.

METHOOS: s e t IMPORTING v a l u e ( s e t _ v a l u e ) TYPE 1. increment , ge t EXPORTING va1ue(get_va1ue) TYPE 1.

PRIVATE SECTION. DATA count TYPE i .

ENDCLASS.

CLASS counter IMPLEMENTATION. METHOO s e t .

count - s e t _ v a l u e . ENDMETHOD. METHOO increment .

AOD 1 TO coun t . ENDMETHOD. METHOO g e t .

ge t_va lue - coun t . ENDMETHOD.

ENDCLASS.

Listing 14.5 Class Definition and Implementation

Figure 14.8 displays the method definit ion in the Class Builder, and Figure 14.9 displays the EXPORTING and IMPORTING parameters for the method in the Class Builder.

A single return value for the method can be def ined using a RETURNING parame-ter. Me thods that have RETURNING parameter are called functional methods . If a method has a RETURNING parameter , there can be n o EXPORTING or CHANGING parameters , and the method will pass back one thing and one thing only to the caller.

Key Concepts Refresher Chapter 14 437

Class Builder: Display Class CL_GUI_FRONTEND_SERVf€ES

C l t t t

O t M t t a d a c a C l M l J W t l O C J U X t l C Z Z

I? , , r i W A , J O * * * V W C O i , , T(0*i , A i a m

H © * M t f K 4 K «

I S . W l l P

t € i . p * a r e m y j g l J W W Y

C A U . H E I * X » J < £ S U . T .

lZjCKt€>Jt»

PtHCVI .CACK « T _ C A C H g _ f * Q P j g T J A C K

SVW'AI SDA'r.CACHf IS .VAi I D . H M M C CHC(K_OU: 3 - P f C f t ? < t A $ $ . C C W « I I U X T C *

( i i f e w w j i w i C U P B W f O J P P C A T

1* i t a o c o H M M

U l t a n c * W t l O J I H W K » W K I Q G

j S ^ M l M i M t a n c * * * t * o o J u t l f t C * I I K k M l M t l ( K « n a t a o e

I M l j O f — U W C # WHfcO< T I » « t a r K +

U t t i n c * M t I M i M t a n c * n « t * o o i M t t o c t ] » * t a * C * lUt&OC i M t a r c * n a t a o a

l t t 1 K » l * » t » 0 3 S t a t i c Hatrvod S t a t i c H«trvc-J S t a t i c H a t f t o d S t a t i c f l a t t e d S t a t i c Hotrvco l M t a n c * m t k o o S t a t i c Hatrvcd

P u b l i c P u b l i c P u b l i c P u b l i c P u b l i c P'Ot©Ct<«J

P r©tOCtOJ P r O t # C t # * P r o f C M d P ' O t O C t O J P r © t * C t * J P ' 0 ! * * - t « . J

P ' O t V C t a - J

P r o u c w P ' O t * C t * J P r o t e c t * !

P r i v a t a P u b l i c P u b l i c P u b l i c P u b l i c P u b l i c P u b l i c

P+a0U*<Prcca«Y

S a c a P r c o t * p t o < * f a G U . C e J C C T R K W M I a F w * r c c c * c t

S«_P<XCa«Y

A M ^ I . P l C t * ^ c « l M * c - J »c*CU.OeJECT. Yo. c a r CMcfc Ct* 6 . V A L O C ^ c ^ ' r c « l _ C e X C T . Y » Can 0 * C * * * * t5.VA4.CX F r c e « V M i r t a j t d HI C a d * ? A M rww C a t f » J FYcea*y P e r n * * *cm C « c t » P * a d V a t * c f a C a c f * P r c e « « t y W - w v * j a cf a Cacrw a * * / H t o C a c n a V M t o m s C c T C ?

O a w C c w v u x r

O t a * rt P rv r t f a O r * * * * S«*«»on v w ^ c w

Figure 14.8 Method Definition for a Global Class

Class Builder: Display Class CL__GU1_FR0NTEND„$ERV1CE$

»'• • • . £ 7 0 w w- M a : r « C l K f ( M O T W U K O

C * M K W l * a C l _ 0 U ! _ f N t t T E W _ S E R V I C € S Act**

, r a n a c a * , f f ^ , ^ O H , E v a r e , T*«a* , A I M M

M a e a j c a r a m t t o n

M t f v * * *

Pmmrn* P I

p 2 h P 4

P 5 P * P.* P S

W

no p i i P i i P I L

P 1 4

P i * p i e P?THX»

1

O X l t . C M T M S U . T > £ E P _ C A C M £

C A U J C T H C O Cacaoaom

S T T 2 E L M « A T V X O C O J T ^ VAAJA O A I O H E C *

I T * * * ?

Ut* h t *

hpo h f Ut* Ut* I r t * T i c *

h i *

A V W AM* AX<

ANY

AMY AM* AX* AX* AX* AX* AX* AX* AX* AX*

c r c AX* C H W 0 1

P v a m « t a n

P a r m c a r t P«rarr*ca*i

P a r a n j a

P«a r r«ca r t Pa ra r racaa P a r a n j a

P a r * ™ * *

P a r a r r a t a a P i r a n h a P « a r r « c w t Hurt

H j - t * t <* V a M P a r « n a o i r t ' O u i P t J X y U W O f W a x ? R x m o f C a i K C Alc -^310 D u r e C4

Figure 14.9 Exporting and Importing Parameter for a Method of the Class

424 Chapter 14 ABAP Object-Oriented Programming

The RETURNING parameter must always be passed by value, and is passed with the addit ion VALUE. M o r e information about functional me thods can be found in Chapter 17, Class Identification Analysis and Design. All input parameters such as IMPORTING and CHANGING can be def ined as optional using the OPTIONAL addi-t ion. You can also use the DEFAULT addition to assign a default value. These parameters do not necessarily have to be t ransferred when the method is called. The DEFAULT addit ion always allows you to specify a default value.

Me thods can set the system return code SY-SUBRC if they raise an exception, but only if the exceptions raised by the method are classic exceptions, as opposed to class-based exceptions. You can identify the type of exception used by the method in the Class Builder by looking at the EXCEPTION tab in the Class Builder screen. For class-based exceptions the EXCEPTION CLASSES checkbox is selected; otherwise, the exception defined for the method is a classic one . Figure 14.10 displays the exception for the classic exception for the me thod .

Class Builder: Display Class CL_GUI_FROffTEND_SERVICES V ti & 2 V • ^ fc Local Typos * «rpfcow*aoc«i w Macros Ctess OxuTWtasoo

OKSWort** Ct_CUI_FRONTEW_SERVICES »np«m9*«! / Acov» P'otwtes Hmtees . Fi«ojs Antots Mt<f>o<Js , Evens *.»««

e>xocftc<B CALLJIETKOD - -> MrtKKfc Paramrtors a E»c«fCon Dwcnpfcctf CHTL_ERROR CNR.ERRCft CHTL_SY$T6H_Eftt<* CNn._$V$TEM_EfifcOft

Figure 14.10 Classic Exception for the Method of the Global Class

Class-based exceptions are raised by either the RAISE EXCEPTION statement or the runt ime env i ronment . To propagate an exception f rom a method, y o u generally use the RAISING addition when you are def ining the method interface. You can specify the RAISING addition directly when you def ine the me thods of local classes.

The syntax to def ine a method with the RAISING addition is as follows:

METHOOS ml IMPORTING . . . EXPORTING . . . RAISING cx.excep . . .

There are two special me thods that you may find in a class: CONSTRUCTOR and CLASS.CONSTRUCTOR.

• The CONSTRUCTOR method (sometimes referred to as the instance constructor) is called automatically when y o u create an object to set a starting value for the

Key Concepts Refresher Chapter 13 439

n e w object . The instance constructor is called once per object, for every object . Each class can have no more than one CONSTRUCTOR method, and the constructor me thod must always be def ined in the public visibility section. The constructor signature can only have import ing parameters and excep-tions. The instance is not created if an exception for the constructor is raised. Usually, you set the value of the attr ibute, validations, increment ing counter for the object, and so on in the CONSTRUCTOR.

The syntax to pass parameters to the constructor is as follows, w h e r e pi and p2 are the parameters for the constructor:

DATA: r e f _ v a r TYPE REF TO zcl_demo. START-OF-SELECTION. CREATE OBJECT r e f _ v a r EXPORTING pi - 10 p2 - 20.

• The static constructor (sometimes also referred to as the class constructor) is a special method in the class and is always named CLASS.CONSTRUCTOR. Each class can have only one static constructor, and it must be assigned to the pub-lic visibility section. The static constructor cannot have any import ing param-eters or exceptions, and it cannot be called explicitly. It is called when you access the class for the first t ime. It is executed n o more than once per class. It can be triggered by creating an instance, accessing a static attr ibute, calling a static method of the class, or registering an event handler method for an event in the class.

Instance methods are called using CALL METHOD ref ->method_name, or you can d rop the CALL METHOD sta tement and call the me thod using the syntax ref •> method_name(), w h e r e ref is the name of the reference variable point ing to the object (instance of the class), and the method name is the object method sepa-rated by the instance componen t selector (• >). The reference variable ref point-ing to the object can be omit ted when calling an instance method f rom within another instance me thod .

A shorter syntax to call a method is suppor ted as of Release 6 . 1 0 . In this case c a l l METHOD is omit ted , and the parameters are listed in parentheses; for example, y o u can call an instance method using the ref - >method_name() s ta tement if the method does not have any parameters . It is important to note that there must be n o space before the parentheses .

Listing 14.6 displays the syntax to call an instance method within a program.

440 Chapter 14 ABAP Object-Or iented Programming

REPORT d e m o _ c l a s s _ c o u n t e r . «

* CLASS c o u n t e r DEFINITION

CLASS c o u n t e r DEFINITION. PUBLIC SECTION.

METHODS: s e t IMPORTING v a l u e ( s e t _ v a l u e ) TYPE i . i n c r e m e n t . g e t EXPORTING v a l u e ( g e t _ v a l u e ) TYPE i .

PRIVATE SECTION. DATA c o u n t TYPE 1 .

ENDCLASS. " c o u n t e r DEFINITION

CLASS c o u n t e r IMPLEMENTATION

CLASS c o u n t e r IMPLEMENTATION. METHOD s e t .

c o u n t - s e t _ v a l u e . ENDMETHOD. METHOD i n c r e m e n t .

AOD 1 TO c o u n t . ENDMETHOD. METHOD g e t .

g e t _ v a l u e - c o u n t . ENDMETHOD.

ENDCLASS.

' s e t

' i n c r e m e n t

" g e t c o u n t e r IMPLEMENTATION

OATA number TYPE i VALUE 5 . DATA c n t TYPE REF TO c o u n t e r . START-OF-SELECTION.

CREATE OBJECT c n t . CALL METHOO c n t - > s e t

EXPORTING s e t _ v a l u e - n u m b e r .

DO 3 TIMES.

CALL METHOO c n t - > i n c r e m e n t . ENDOO. CALL METHOO c n t - > g e t

Key Concepts Refresher Chapter 13 441

IMPORTING g e t _ v a 1 u e - number .

WRITE number . Listing 14.6 Calling Instance Me thods

Simi lar ly , s ta t ic m e t h o d s a r e ca l led u s ing t h e s y n t a x CALL METHOD c l a s s _

name->method_name. T h e s y n t a x cons i s t s o f t h e class n a m e a n d t h e n a m e o f t h e

m e t h o d s e p a r a t e d b y t h e s ta t ic c o m p o n e n t s e l ec to r ( - » . Like s ta t ic a t t r i b u t e s ,

s ta t ic m e t h o d s a r e a d d r e s s e d w i t h t h e i r class n a m e b e c a u s e t h e y d o n o t n e e d

i n s t a n c e s o f t h e class . You can o m i t t h e class n a m e w h e n ca l l ing t h e s ta t ic m e t h o d

f r o m w i t h i n t h e class, o r y o u can u s e t h e s h o r t e r s y n t a x t o call t h e m e t h o d , in

w h i c h t h e CALL METHOD p r e f i x is o m i t t e d a n d t h e p a r a m e t e r s a r e p l aced in p a r e n -

t h e s e s as m e n t i o n e d a b o v e .

T h e s y n t a x t o call a m e t h o d w i t h EXPORTING. IMPORTING, a n d CHANGING p a r a m e -

t e r s is as f o l l o w s :

CALL METHOD o r e f • > m e t h o d _ n a m e EXPORTING im_par - e x p . v a l IMPORTING e x p _ p a r - im_val CHANGING c h . p a r - c h g . v a l RECEIVING r e _ p a r - r e s . v a l EXCEPTIONS e x c e p t i o n - r e _ v a l

T h e s h o r t e r s y n t a x t o call a m e t h o d is as f o l l o w s :

o r e f - > m e t h o d _ n a m e ( EXPORTING im_par - e x p . v a l IMPORTING e x p _ p a r - im_val CHANGING c h _ p a r - chg_va l RECEIVING r e _ p a r - r e s _ v a l EXCEPTIONS e x c e p t i o n - r e . v a l

You can o m i t t h e EXPORTING p a r a m e t e r w h e n y o u call t h e m e t h o d t ha t ha s o n l y

t h e i m p o r t p a r a m e t e r s .

» Note

It is important to know that ABAP Objects does not provide a destructor method for the class, as in some other object-oriented programming languages.

442 Chapter 14 ABAP Object-Oriented Programming

Events

Even t s a r e a n o t h e r c o m p o n e n t o f t h e class, a long w i t h a t t r i b u t e s a n d m e t h o d s . Ob jec t s o r classes can t r igge r even t s , a n d o t h e r o b j e c t s o r classes can react to t h o s e e v e n t s t h r o u g h special e v e n t h a n d l e r m e t h o d s . W h e n an e v e n t is t r igge red , a n y n u m b e r o f h a n d l e r m e t h o d s can b e cal led. T h e s e m e t h o d s a r e n o t called explici t ly; in s t ead , t h e r u n t i m e s y s t e m calls t h e h a n d l e r m e t h o d s , o n e by o n e , w h e n t h e e v e n t is t r i gge red . T h e d e f i n i t i o n o f t h e h a n d l e r m e t h o d d e t e r m i n e s to w h i c h e v e n t it wil l reac t . You can dec la re h a n d l e r m e t h o d s in as m a n y d i f f e r e n t classes as n e c e s s a i y .

To t r igger an e v e n t t h e class m u s t d e c l a r e t h e e v e n t in t h e d e f i n i t i o n pa r t a n d tr ig-g e r t h e m e t h o d in o n e o f t h e m e t h o d s o f t h e s a m e class. You can d e f i n e a s tat ic e v e n t o r an in s t ance e v e n t . I n s t ance e v e n t s a re d e f i n e d us ing t h e e v e n t s s ta te-m e n t , w h e r e a s a n y stat ic e v e n t s a re d e f i n e d us ing t h e c l a s s - e v e n t s s t a t e m e n t . Even t s a r e t r igge red by us ing t h e r a i s e e v e n t s t a t e m e n t in a m e t h o d o f t h e class. T h e e v e n t can h a v e e x p o r t i n g p a r a m e t e r s tha t m u s t b e passed b y va lue o n l y . You u s e t h e s e if y o u w a n t to pass t h e h a n d l e r m e t h o d s o m e i n f o r m a t i o n tha t it m a y n e e d . W h e n a n e v e n t is t r igge red , t h e r e f e r e n c e to the t r igger ing o b j e c t is a lways avai lable t h r o u g h t h e p r e d e f i n e d i m p o r t i n g p a r a m e t e r s e n d e r . By us ing th i s p a r a m e t e r y o u can p lace a r e f e r e n c e to t h e e v e n t t r igger o b j e c t in t h e h a n d l e r m e t h o d . T h e s e n d e r p a r a m e t e r is n o t expl ici t ly d e f i n e d b u t can a lways b e i m p o r t e d by t h e h a n d l e r m e t h o d .

I n s t ance e v e n t s can b e t r igge red by an i n s t a n c e o f t h e class (objects) , w h e r e a s

s tat ic e v e n t s can b e t r igge red b y t h e class i tself. You can t r igger b o t h s tat ic e v e n t s

a n d i n s t a n c e e v e n t s f r o m ins t ance m e t h o d s , w h e r e a s o n l y s tat ic e v e n t s can b e

t r igge red f r o m stat ic m e t h o d s .

Even t s a re also sub jec t to the visibi l i ty c o n c e p t s d i s cus sed a b o v e . You can assign e v e n t s to a vis ibi l i ty sec t ion s imi la r to o t h e r c o m p o n e n t s o f t h e classes. Even t s can b e a s s igned to e i t h e r t h e publ ic , p r o t e c t e d , o r p r iva t e sec t ions . T h e visibil i ty o f t h e e v e n t s d e t e r m i n e s w h e r e the e v e n t can b e h a n d l e d . A n e v e n t d e f i n e d in t h e pub l i c sec t ion can b e h a n d l e d in t h e pub l i c m e t h o d ; an e v e n t d e f i n e d in t h e p r o t e c t e d sec t ion can b e h a n d l e d b y t h e class itself o r i ts subclasses , w h e r e a s e v e n t s d e f i n e d in t h e p r iva t e sec t ion can b e h a n d l e d o n l y w i t h i n t h e class i tself.

List ing 14 .7 d i sp lays t h e d e f i n i t i o n a n d t h e i m p l e m e n t a t i o n o f a n e v e n t .

Key Concepts Refresher Chapter 13 443

CLASS c o u n t e r DEFINITION

CLASS c o u n t e r DEFINITION. PUBLIC SECTION.

METHOOS i n c r e m e n t _ c o u n t e r . EVENTS c r i t i c a l . v a l u e EXPORTING v a l u e ( e x c e s s ) TYPE i .

PRIVATE SECTION. DATA: c o u n t TYPE i .

t h r e s h o l d TYPE i VALUE 10 . ENOCLASS. " c o u n t e r DEFINITION *

* CLASS c o u n t e r IMPLEMENTATION

CLASS c o u n t e r IMPLEMENTATION. METHOD i n c r e m e n t _ c o u n t e r .

OATA d i f f TYPE i . ADD 1 TO c o u n t . IF c o u n t > t h r e s h o l d ,

d i f f - c o u n t - t h r e s h o l d . RAISE EVENT c r i t i c a l _ v a 1 u e EXPORTING e x c e s s - d i f f .

ENDIF. ENOMETHOD. " i n c r e m e n t _ c o u n t e r

ENDCLASS. " c o u n t e r IMPLEMENTATION — . . . . *

* CLASS h a n d l e r DEFINITION * *

* *

CLASS h a n d l e r DEFINITION. PUBLIC SECTION.

METHOOS h a n d l e . e x c e s s FOR EVENT c r i t i c a l _ v a l u e OF c o u n t e r IMPORTING e x c e s s .

ENOCLASS. " h a n d l e r OEFINITION

CLASS h a n d l e r IMPLEMENTATION

444 Chapter 14 ABAP Object-Oriented Programming

CLASS h a n d l e r IMPLEMENTATION.

METHOO h a n d l e _ e x c e s s .

WRITE: / ' E x c e s s i s ' , e x c e s s .

ENDMETHOD - h a n d l e _ e x c e s $

List ing 14.7 Event Declaration and Implementat ion

For the global class the event is defined on the EVENTS tab of the class editor, and the event handler method is defined in the M E T H O D S tab, whereby you can spec-ify additional attributes for the method by selecting the DETAIL VIEW icon ([£). Figure 14.11 displays the event definition in Class Builder, and Figure 14.12 dis-plays the event handler method definition.

Class Bui/der; Change Crass ZCL_DEM02

y n n 3 & • ~ & 7 0 hi ices Ty f * * 0 CcnaMot 0 O u t c o n o u i o r C l M f o x a - - ' U t < *

h - c M n r c ^ S / h K t * 0 * 4 w J)

F v o c < o « , T W r . AJJG^&K M * V > K E * K t t , T y c ^ A

- a Q ft ft y i A JI B I 6 * * I v i a i r CEM:>_Ev£%r I n i t a f t c * E v # f f u M i c DenoBwi

Figure 14.11 Event Def in i t ion in a Global Class

I Cfess Buikhr: Chsngo Cbss ZCL_D€MO

V f i » J * • : £L V U » I C C * ? * * ' . » r x w r y q & y » V.K>M U C t w M y J C i m c w x s x a C t m a c < \ r + * * > r

, P « r » T * * r i II ft ft X I A » »

f \ M < WWT03 1 KETKO* STATIC ttltUC H U K 0 2 lfc3TAW«IVATC

t w r i r t r o ^ v - e c d

I * M f l o W o & k F Y t t t O t O | _ « r * t t n c *

* * * * * * * *

E ^ l J O f w O . g V f H T l B M C O M ] B

I M C t f r o M C y p r e )

Figure 14.12 Event Handler M e t h o d Defini t ion

Key Concepts Refresher Chapter 13 445

When the event is triggered, the handler me thods registered to this event are called in the sequence in which they were registered. Only the handler methods registered for the triggering event is started after the event is triggered. You can def ine any n u m b e r of handler methods for an event . The handler methods can be def ined in the same class o r (usually) another class. The event handler meth-ods are not called directly by the client; instead, the run t ime system call the han-dler method automatically af ter the event has been triggered. The link between the event and the handler method is established dynamically in the program by using the SET HANDLER statement . Registration is only active at program runt ime.

The syntax to register handler method is as follows:

SET HANDLER o r e f 1 - > e v e n t J i a n d l e r l .

Or y o u can register several handler methods with one s ta tement as follows:

SET HANDLER evt_hand1er l ev t_hand le r2 FOR ALL INSTANCES.

Hence, to handle an event, a method must be def ined as an event handler method and must be registered at runt ime for the event . Listing 14.8 displays the handler method definit ion and implementat ion and event handler registration at runt ime. If the event contains the export ing parameters , then the handler method signature should contain the IMPORTING parameters in the defini t ion. The handler method signature should contain IMPORTING parameters equal to the

EXPORTING parameters of the events. * *

* CLASS coun te r DEFINITION

CLASS counter DEFINITION. PUBLIC SECTION.

METHODS inc rement_coun te r . EVENTS c r i t i c a l _ v a l u e EXPORTING v a l u e ( e x c e s s ) TYPE i .

PRIVATE SECTION. OATA: count TYPE i .

t h r e s h o l d TYPE i VALUE 10. ENOCLASS. "counter DEFINITION *

* CLASS coun te r IMPLEMENTATION

446 Chapter 14 ABAP Object-Or iented Programming

* i

CLASS c o u n t e r IMPLEMENTATION. METHOD i n c r e m e n t _ c o u n t e r .

DATA d i f f TYPE i . AOD 1 TO c o u n t . IF c o u n t > t h r e s h o l d ,

d i f f - c o u n t - t h r e s h o l d . RAISE EVENT c r i t i c a l _ v a l u e EXPORTING e x c e s s - d i f f .

ENDIF. ENDMETHOD. " i n c r e m e n t _ c o u n t e r

ENDCLASS. " c o u n t e r IMPLEMENTATION * »

* CLASS h a n d l e r DEFINITION * *

CLASS h a n d l e r DEFINITION. PUBLIC SECTION.

METHODS h a n d l e _ e x c e s s FOR EVENT c r i t i c a l _ v a l u e OF c o u n t e r IMPORTING e x c e s s .

ENOCLASS. " h a n d l e r DEFINITION * *

* CLASS h a n d l e r IMPLEMENTATION

CLASS h a n d l e r IMPLEMENTATION. METHOD h a n d l e _ e x c e s s .

WRITE: / ' E x c e s s i s ' . e x c e s s . ENDMETHOD. " h a n d l e _ e x c e s s DATA: r l TYPE REF TO c o u n t e r ,

h i TYPE REF TO h a n d l e r . S T A R T - O F - S E L E C T I O N .

CREATE OBJECT: r l . h i . SET HANOLER h i - > h a n d l e _ e x c e s s FOR ALL INSTANCES. DO 20 TIMES.

CALL METHOO r l - > i n c r e m e n t _ c o u n t e r . ENOOO.

Listing 14.8 Event Handler Declarat ion, Implementa t ion , and Registration

If s e v e r a l m e t h o d s a r c r e g i s t e r e d t o o n e e v e n t , t h e y a r e c a l l e d in t h e s e q u e n c e in

w h i c h t h e y w e r e r e g i s t e r e d .

Practice Questions Chapter 14 447

Practice Questions The practice quest ions below will help you evaluate y o u r unders tanding of the topic. The quest ions shown arc similar in nature to those found on the certifica-tion examination, but whereas none of these quest ions will be found on the exam itself, they allow you to review y o u r knowledge of the subject. Select the correct answers and then check the completeness o f y o u r answers in the follow-ing solution section. Remember that you must select all correct answers and only correct answers to receive credit for the quest ion.

1. Which of the following is a t rue s tatement:

• A. Static at tr ibutes can be declared only in the private visibility section of the class.

• B. Static at tr ibutes are declared with the CLASS - DATA s ta tement .

• C. A static at t r ibute is the same across all instances of the class. There is only one static at t r ibute across all instances of the class.

• D. Static at tr ibutes cannot be changed by an object .

2. Private componen t s of the class cannot be addressed directly f rom outside the class except w h e n the f r iendship concept applies.

• A. True

• B. False

3. Subclasses can access the private componen ts of the parent class.

• A. True

• B. False

4. Subclasses inherent all the componen ts of the parent class.

• A. True

• B. False

5. Public me thods can access the private at tr ibutes of the same class.

• A. True

• B. False

434 Chapter 14 ABAP Object-Oriented Programming

6. Protected attr ibutes can be accessed by methods of the class and its sub-classes.

• A. True

• B. False

7. You cannot use the l i k e s ta tement to def ine an at t r ibute in a class.

• A. True

• B. False

8. The r e a o - o n l y addit ion for the at t r ibute declaration can be used in the pri-vate and public visibility section.

• A. True

• B. False

9 . The r e a o - o n l y a t t r ibute cannot be addressed outs ide the class.

• A. True

• B. False

10. Which of the following are correct s tatements?

• A. Class me thods assigned to the public visibility section can be accessed outside the class using the static componen t selector and the class name.

• B. Static me thods can be def ined in both the public and private visibility sec-tion of the class.

• C. Only public me thods can be addressed outside the class.

• D. You can call private me thods within the public methods wi thout refer-ence to the object or class.

• E. None of the above

11. The constructor method is called automatically when you create an instance of the class.

• A. True

• B. False

Practice Question Answers and Explanations Chapter 14 449

12. The class constructor method is called automatically when you access the class for the first time.

• A. True

• B. False

13. The constructor method is always defined in the private visibi l i ty section o f the class.

• A. True

• B. False

14. You can call the constructor method directly.

• A. True

• B. False

15. Object or class events can trigger any number o f handler methods.

• A. True

• B. False

Pract ice Ques t ion Answers and Explanat ions

1. Correct answers: B. C

Static attributes can be defined in the private and public visibi l i ty sections o f the class. Static attributes are defined w i th the CLASS-DATA statement in the def in i t ion part o f the class. Static attributes exist once per class and are the same for all o f the runt ime instances o f the class. I f you change the static attribute o f the class, this change w i l l apply for all o f the instances o f the class. Static attributes can be changed by an instance o f the class. A l l o f the objects o f the class can access the static attribute o f the class.

2. Correct answer: A

Private attributes cannot be addressed outside the class, but a class that is a fr iend overrides this principle and can access the private attributes o f the class.

450 Chapter 14 ABAP Object-Oriented Programming

3. Correct answer: B

Subclasses inherit all components o f the parent class but can only directly access public and protected components. However, the class also inherits the public methods from the superclass, which w i l l indirectly allow access to the inherited private attributes. I f a subclass inherits a private component, this private component cannot be accessed directly. Private means private; this is why we have protected sections — so that when we have a subclass, it can access inherited components.

4. Correct answer: A

The subclass inherits all components f rom the superclass, but can then add additional components or can redefine inherited methods. Refer to Chapter 17, Class Identification Analysis and Design, for more information on this.

5. Correct answer: A

Public methods can access all o f the attributes o f the class.

6. Correct answer: A

Protected components can be accessed by the class and subclass. They cannot be addressed directly outside the inheritance tree.

7. Correct answer: B

The L I K E statement is al lowed only for local data objects (for example, w i th in a method) or system variables.

8. Correct answer: B

READ-ONLY attributes are defined in the public section and can be accessed outside the class. The value o f the REAO-ONLY attributes cannot be changed.

9. Correct answers: A, B, C, D

These are correct for the fo l lowing reasons:

• Class methods or static methods assigned to the public visibi l i ty section o f the class can be accessed outside the class w i th reference to the class be-cause you do not need to instantiate the class to be able to work w i th them.

• Static methods can be defined in both the public and the private visibi l i ty section o f the class. You can access the static public methods outside the class, but not the static methods assigned to the private visibi l i ty section.

• Only the methods assigned to the public visibi l i ty section can be addressed outside the class.

• Private methods o f the class can be called w i th in the public methods o f the same class wi thout reference to the class or object.

Take Away Chapter 14

10. Correct answer: A

The constructor method is called automatically eveiy t ime you instantiate the class, that is, eveiy t ime a new object is created.

11. Correct answer: A

The class constructor method is called automatically when you access the class for the first t ime, that is, when creating an object, calling a static method, and so on.

12. Correct answer: B

The constructor method and the class constructor method are always defined in the public visibi l i ty section.

13. Correct answer: B

You cannot call the constructor method directly; it is called automatically.

14. Correct answer: A

When an instance or class event is triggered, any number o f handler meth-ods can be called. Only the handler methods registered for the triggering event are called when the event is triggered.

Take Away

You should be able to explain the basic object-oriented programming concepts. You should be able to explain the key components o f an ABAP class such as attributes, methods, and events and be able to use them for object-oriented application development. You should be able to differentiate between instance components and static components. By now you should also have a good under-standing about the visibi l i ty concepts in ABAP Objects and be able use them appropriately to create an ABAP class.

Refresher

Table 14.1 shows key concepts for ABAP Objects.

438 Chapter 14 ABAP Object-Oriented Programming

Key Concept Def in i t ion

Class A class is an abstract description of an object. A class is a template or a blueprint based on which all of the objects are created.

Attr ibute Attributes are the global data of the class. The state of the object is determined by the content of its attributes. You can have attributes assigned to the public, protected, and private visibility sections of the class. You can also define static and instance attributes for the class.

Method Methods are internal procedures that determine the internal behav-ior of the class. Methods can access all of the attributes of the class and hence can change the data content of the attributes. You can assign methods to the public, protected, and private visibility sec-tions of the class. You can also define static or instance methods for the class.

Event You can define events in the class to trigger event handler methods in other classes. Only handler methods registered for the triggering event are called when the event is triggered. Events can be assigned to the public, protected, or private visibility sections of the class. Sim-ilarly, you can define static or instance events in the class. Events are triggered using the RAISE EVENT statement, and the handler methods are registered using the SET HANDLER statement.

Object An object is an instance of a class. The class describes all of the

generic characteristics of the object. An object is created using the C R E A T E O B J E C T s t a t e m e n t .

Table 14.1 Key Concept Refresher

S u m m a r y

In this chaptcr y o u have learned basic ob jec t -o r ien ted p r o g r a m m i n g concepts.

You have learned the concepts o f the A B A P class because i t is the f ounda t i on fo r

ABAP ob jec t -o r ien ted p r o g r a m m i n g . You k n o w the basic componen ts o f ABAP

classes, b o t h local and global , and have learned about the v i s i b i l i t y concepts,

instance and static componen ts , and the i r syntax. You have also learned about

events and h o w to t r igger and h o w to register hand le r methods. You shou ld n o w

be a able to create local and g loba l classes and use t h e m to w r i t e p rograms us ing

ABAP Objects. Your know ledge about ABAP Objects w i l l enable y o u t o answer

ABAP Objects-related quest ions and successful ly pass this top ic .

ALV Grid Control

Techniques You' l l M a s t e r :

• Identify the major functions o f the ALV grid

• Understand how to produce a full-screen ALV

• Explore how to produce an ALV w i th in a container

• Handle events triggered by the ALV

454 Chapter 15 ALV Grid Control

The ABAP List Viewer (ALV) has been available since Release 4.5a. W i th Release 4.6C it was renamed the SAP List Viewer, but the acronym remained ALV. The list viewer is rendered on the presentation server, which differentiates it f rom a report you produce using WRITE statements. You a use a container control on the presentation server to produce the ALV.

In this chapter you w i l l be provided w i th a basic understanding o f how ALV Grid Controls are produced. We wi l l examine both versions o f the class-based ALV and identify major differences between them. We wi l l cover the techniques to produce a full-screen ALV and an ALV w i th in a container. We wi l l also cover how to handle events triggered by the ALV for processing w i th in our program.

Real-World Scenario

You have been asked to explain to programmers just hired, who have never used ALV grids, the way to program a report using an ALV.

It is your responsibility to explain both the old and new class-based tech-niques to create an ALV Grid. You wi l l need to provide an understanding o f the basic methods to create a full-screen display used in your company's reporting and w i th in dialog screens used in your company's programs to display mult iple lists on a single screen. To do this, y o u w i l l need to explain the two classes used to produce ALV grids and the process o f placing an ALV into a container.

Because management often wants the data to be presented in the ALV in a specific way, because they want a different column heading or an order that does not correspond to the field structure found in the ABAP Dictio-nary, you must also explain how to change the display o f an ALV program-matically.

Object ives of th is Por t ion of t he Test

The purpose o f this port ion o f the certification examination is to veri fy that y o u have an understanding o f the ALV. This port ion o f the examination w i l l test your knowledge o f a number o f topics. The points you w i l l need to understand f rom this section include:

Key Concepts Refresher Chapter 15 455

• How to handle events tr iggered f r om the ALV; what steps are necessaiy to

receive the events for processing

• The creation o f a full-screen ALV because many customers prefer ALV reports because o f their flexibility (sorting, f i l ter ing, or reorder ing columns) for the end user o f the report

• The creation o f an ALV w i t h i n a container, wh i ch is useful for dynpro display

o f data

• How to mod i f y the display o f an ALV, in o ther words, changing the in i t ia l dis-

play to match customer requirements

The cert i f icat ion examinat ion w i l l give m in ima l weight to this chapter compared to all o f the other topics i n the examinat ion. This means this chapter is among those where the percentage o f questions related to the topic is smaller than most other chapters. A n ALV can be produced s imply. It is on ly when y o u mod i f y the display o f an ALV that it becomes more complicated. We believe that ow ing to its normal ly simple product ion, it does not require as much specialized knowl -edge as other areas and is therefore not given as much weight on the examina-t ion.

Note

The ALV Object Model has been available since SAP NetWeaver 6.40, but the certification examination could include questions on the older ALV that was implemented on the basis of the global class CL_GUI_ALV_GRID. In the future the exam may change to include questions on only the newer technique, but at present you will need to be prepared for questions on both, and therefore we will discuss both in this chapter.

Key Concepts Refresher

You need to understand and be able to per fo rm the fo l l ow ing types o f tasks

w h e n developing ABAP programs:

• Producing reports that are flexible for the user

• Displaying data in a tabular format

442 Chapter 15 ALV Grid Control

Overview of ALV Programming

The graphical user interface (GUI) in the SAP system is based on SAP GUI win-dows (screens from the technical viewpoint o f the programmer). Every dialog is implemented using dynpros o f programs. Prior to Release 4.5 y o u could only use elements that were provided by the Screen Painter, for example, buttons. Start-ing w i th Release 4.5 it became possible to use controls that are stand-alone binary software components, one o f these being the ALV Grid Control. These controls communicate dif ferently than standard dynpro components. Rather than communication using the screen processor, these controls use the Control Framework (CFW).

You cannot create stand-alone instances o f a control on the presentation server. You must provide a special control known as a container control. This container control is placed in a reserved area on the screen, and the ALV grid is w i th in this container control. The steps to place a control on a screen are as follows:

1. You reserve an area in the screen for the container using a special screen ele-ment — the Custom Control Area. The process for this is similar to the way y o u reserve a subscreen area for a subscreen.

2. You create an instance o f the container control class and l ink it to the area reserved on the screen. The container control is now visualized in the reserved area.

3. You create an ALV Grid Control instance then l ink it to the container control instance. The ALV Grid Control is now visualized in the container.

To reserve an area on the screen for the control, y o u use the Graphical Layout Editor o f the Screen Painter, click on the CUSTOM CONTROL button, and "draw" the area for the container on the screen. You then need to provide a name for the created custom control area, so that you can l ink it to the container later.

ALV Grid Programming (CL_GUI_ALV_GRID)

You next need to generate an instance o f a container. In your program, you need to do this before displaying the screen where the ALV Grid Control is to appear on the presentation server. The PBO (Process Before Output) o f the screen that contains the reserved area is the usual place to create the container instance (the def ini t ion o f the reserved area is shown in Figure 15.1). This event block is always called pr ior to displaying the screen.

Key Concepts Refresher Chapter 15 457

& 8 ©<i>0 el °r 0 <

Q9Q X 3 1 • • u • F1CIO0C >

© a

H fiil Nan* SAV.CONIANER.OI l«od 1

© a

H fiil

n r T r~ |X df

• a LZJ • HQ m

Figure 15.1 Screen Container Area

T h e process t o create a c u s t o m c o n t a i n e r ins tance starts w i t h a dec la ra t i on o f t he

re fe rence va r iab le . T h e re fe rence va r i ab le needs to re fe r t o the C o n t a i n e r class,

i n th is case TYPE REF TO c 1 _ g u i _ c u s t o m _ c o n t a i n e r . You genera te a c o n t a i n e r

c o n t r o l ins tance b y u s i n g the s ta temen t CREATE OBJECT to genera te an ins tance

o f t he class c l _ g u i _ c u s t o m _ c o n t a i n e r . You l i n k t he c o n t a i n e r y o u are c rea t i ng

t o t he area y o u reserved f o r i t o n t he screen b y us ing the IMPORTING p a r a m e t e r

c o n t a i n e r _ n a m e (see L i s t i n g 15 .1 f o r an e xa m p l e ) . W e r e c o m m e n d tha t y o u use

e i t he r t he A B A P Ob jec ts p a t t e r n (o r d r a g g i n g a n d d r o p p i n g f r o m the class n a m e

i n t he Ob jec t N a v i g a t o r i n t o y o u r code t o a u t o m a t i c a l l y p r o d u c e the CREATE

OBJECT call) to insert the CREATE OBJECT statement.

OATA: g t_s f1 igh t TYPE TABLE OF s f l i g h t . gs_layout TYPE lvc_s_layo. g r_a lv_gr id TYPE REF TO c l _gu i_a l v_g r i d . gr_custom_container TYPE REF TO cl_gui_custom_container.

IF gr_custom_container IS NOT BOUND. * Create an instance of a container

CREATE OBJECT gr_custom_container EXPORTING

container.name - 'ALV_CONTAINER_01'

444 Chapter 15 ALV Grid Control

EXCEPTIONS c n t l _ e r r o r - 1 cn t l_sys tem_er ro r - 2 c rea te_e r ro r - 3 1 i f e t i m e _ e r r o r - 4 1 i fe t ime_dynpro_dynpro_ l ink - 5 OTHERS - 6.

IF sy-subrc NE 0. MESSAGE a001(z_message_class).

* Container could not be c rea ted , program terminated ENDIF.

* Create an ins tance of a lv c o n t r o l CREATE OBJECT g r _ a l v _ g r i d

EXPORTING i_paren t - g r_custom_conta iner .

ENDIF.

g s _ l a y o u t - g r i d _ t i t i e - ' F l i g h t s * ( 1 0 0 ) . CALL METHOD g r _ a l v _ g r i d - > s e t _ t a b l e _ f o r _ f i r s t _ d i s p l a y

EXPORTING i_st ructure_name - 'SFL1GHT' i s . l a y o u t - gs . l ayou t

CHANGING

i t _ o u t t a b - g t _ s f 1 i g h t .

Listing 15.1 Create ALV Grid

I f y o u create th is instance in a PBO m o d u l e , w h i c h w i l l be executed as m a n y

t imes as the screen is processed, y o u need to ensure that an instance is o n l y gen-

era ted the f i rs t t ime ; y o u o n l y w a n t one con ta ine r created, regardless o f h o w

m a n y t imes the user processes the screen. O the rw i se , y o u may generate a n e w

ob jec t eve ry t i m e the d y n p r o is processed (o r the code is recxccuted) . You can

s top u n w a n t e d instances f r o m be ing generated by o n l y creat ing o n e af ter check-

ing i f the reference var iab le is no t va l i d w i t h the c o n d i t i o n IS NOT BOUNO.

Tip

We prefer IS NOT BOUNO over the more common IS I N I T I A L because IS NOT BOUND checks to see if the reference is invalid instead of just checking that the variable is empty. Resources the control occupies on the presentation server are typically released at the end of the program. However, these resources can also be released explicitly by calling the instance method TREE.

Key Concepts Refresher Chapter 15 459

An early release of the resource by this means invalidates the reference variable. If this code does not create a new object because a value still exists, the invalid reference is supplied to the ALV. However, by using IS BOUND the reference is determined to be invalid, and a new object is created.

You must create the instance o f the A L V G r i d Con t ro l af ter the conta iner con t ro l

instance because the con ta iner instance must exist before y o u can l i nk the A L V

g r i d to i t . I t also needs to be before the SAP G U I w i n d o w is sent to the presenta-

t i o n server because the conta iner and A L V g r id must exist before its d isp lay.

Therefore , w e can again use the PBO o f the screen (see L is t ing 15.1 fo r an exam-

ple).

You declare a reference var iable typed w i t h reference to the class CL_GUI_ALV_

GRID. You then p rov ide the instance reference o f the p rev ious ly generated con-

ta iner con t ro l instance to the parameter i . p a r e n t d u r i n g the instance construc-

to r call that is t r iggered w h e n y o u call CREATE OBJECT. Supp ly ing the conta iner

d u r i n g the creat ion o f the A L V g r i d p rov ides the l i nk be tween these objects. I f

an e r ro r except ion occurs w h e n creat ing the instance, y o u shou ld react w i t h a

t e r m i n a t i o n message to abor t the p rog ram.

I f y o u w a n t to d isp lay the A L V G r i d Con t ro l i n fu l l -screen mode , w h i c h is most

o f ten used to d isp lay a repor t i n the en t i re screen body , y o u do n o t reserve a con-

t r o l area o n the screen and y o u d o n o t create a conta iner con t ro l . Instead, y o u

assign a static va lue to the expor t parameter i . p a r e n t as s h o w n i n L is t ing 15.2.

CREATE OBJECT g r _ a l v _ g r i d EXPORTING

1_parent - cl_gu1_custom_container->screen0.

Listing 15.2 Create a Full-Screen ALV Grid

As a result o f the above steps, y o u have created an A L V G r i d Con t ro l as a screen

e lement . However , y o u w i l l o n l y see a f rame i n the SAP G U I w i n d o w because

the cont ro ls do not y e t d isp lay any th ing . You st i l l need to supp ly the presenta-

t i o n server cont ro ls w i t h data that they can d isp lay.

The ca l l ing p rog ram n o w needs to p r o v i d e all o f the data fo r d isp lay and the rules

that de f ine h o w this data is to be d isp layed ( th rough the use o f the f ie ld catalog).

You must pass the data fo r d isp lay to the A L V g r i d as a s tandard in te rna l table to

the m e t h o d SET_TABLE_FOR_FIRST_DISPLAY, w h i c h y o u call f o r the A L V g r i d

instance. The A L V g r i d does no t make a copy o f the data, bu t instead manages a

446 Chapter 15 ALV Grid Control

reference o f the passed internal table. A l l actions o f the ALV instance (for exam-

ple. sort ing and filtering) are per formed by the instance on the internal table that

resides in the call ing program. This means y o u must ensure that the internal

table has existed for at least as long as the ALV gr id instance. Put another way,

do not use a local table in a modular izat ion uni t that does not out l ive the ALV

Gr id Control .

I f the user sorts the data in the ALV gr id, the contents o f the internal table in the call ing ABAP program are sorted. Therefore, the table suppl ied to the ALV gr id must be a standard table. A l l other interactions by the user on ly read the data. You use the instance method S E T _ T A B L E _ F O R _ F I R S T _ D I S P L A Y to pass the display data in the f o rm o f a standard internal table (parameter i t _ou t t ab ) , the field cat-alog. again in the f o rm o f a standard internal table (parameter i t _ f i e l d c a t a l o g ) , and other addi t ional in fo rmat ion regarding the presentation or layout o f the data to the ALV gr id.

Table 15.1 shows the p r ima i y parameters for an ALV table display.

Parameter Purpose

1 t_outtab Display data in a standard internal table.

1t_f1eldcatalog The field catalog is an internal table that contains infor-mation about the columns to be displayed

i_structure_name If provided, it allows the ALV to automatically generate the field catalog for all fields contained in the structure, which must be an object from the ABAP Dictionary.

is_var iant , i_save, and These parameters provide the user with the ability to i_defaul t change or save the display layout.

i s_l ayout This structure provides fields for setting graphical prop-erties of the grid control, displaying exceptions, calcu-lating totals, and enabling specific interaction options.

i s_pr in t The print structure contains fields for settings when the list is printed.

it_special_groups This table is used to pass texts for field groups defined in the field catalog.

Table 15.1 Primary Parameters for ALV Table Display

Key Concepts Refresher Chapter 15 447

Parameter Purpose

1t_too1ba r_exc1ud i ng The names of the standard functions you want to hide on the toolbar.

1 t _ f l i t e r Provides the initial settings for filtering.

1 t_sor t Provides the initial settings for sorting.

Table 15.1 Primary Parameters for ALV Table Display (cont.)

The data to appear i n the A L V must be supp l ied to the parameter 1 t _ o u t t a b ; al l

o the r parameters are op t iona l . I f y o u supp ly the name o f a g lobal s t ructure type

( for example, a s t ructure, table, o r v i e w f r o m the ABAP D ic t ionary ) to the param-

eter i _ s t r u c t u r e _ n a m e , the f ie ld catalog is au tomat ica l l y generated by the A L V

g r i d fo r the f ie lds i n this st ructure, table, o r v i ew . Howeve r , each c o m p o n e n t i n

the s t ructure must also exist i n the data in terna l table as a c o l u m n . This displays

all co lumns f r o m the data table w i t h the same names as those in the p r o v i d e d

s t ructure in the A L V gr id .

The m i n i m u m i n f o r m a t i o n y o u need to p rov i de is the d isp lay data ( i t _ o u t t a b )

f r o m the in terna l table, w h i c h is m a n d a t o i y , and f ie ld i n f o r m a t i o n fo r the d isp lay

data. The s implest w a y to p rov ide the f ie ld i n f o r m a t i o n about the d isp lay data is

to p rov i de an ABAP D i c t i o n a i y st ructure, table, o r v i ew , i n the parameter i _

structure_name.

You can have the list data and the add i t i ona l i n f o r m a t i o n sent to the presentat ion

server again by us ing the m e t h o d R E F R E S H _ T A B L E _ D I S P L A Y . The parameter i _

s o f t _ r e f r e s h , i f supp l ied w i t h the value ' X ' , specif ies that on l y the data con-

tents are to be passed again, w h i c h keeps the cu r ren t f i l t e r and sor t cr i ter ia. I f

y o u assign the value ' X ' to the ROW o r COL fields o f a s t ruc ture using the g lobal

type L V C _ S _ S T B L ( fo r the parameter I S _ S T A B L E ) , the scrol l pos i t ions o f the rows

and co lumns w i l l be reta ined d u r i n g ref reshing.

Tip

You cannot use the method REFRESH_TABLE_OISPLAY if you have changed the row structure of the display table. In this case you need to call the method SET_ T A B L E _ F 0 R _ F I R S T _ D I S P L A Y again to create the field catalog again.

448 Chapter 15 ALV Grid Control

Layout Variants

You use the parameters i s _ v a r i a n t and i _ s a v e to d e t e r m i n e w h a t o p t i o n s are

o f f e r e d to the user fo r layou t var ian t managemen t . Us ing d i f f e r e n t c o m b i n a t i o n s ,

y o u can p roduce o n e o f three modes us ing these t w o parameters (see Table 15.2) .

Table 15.3 shows the p e r m i t t e d values f o r i _ save .

M o d e Result Values of Parameters

Changing the cur- Users can change the current • is va r ian t is initial rent layout only layout (they can modify the • t_save = space (default set-

selection and the order of the ting) columns displayed).

t ing)

Loading delivered The user can change the cur- • t s_var ian t contains values

layouts only rent layout variant and select supplied in structure

existing variants. i . save = space (or I s . v a r l -

ant is initial and 1_save is

not equal to space)

Loading and sav- The user can change the cur- • 1s_var iant contains values

ing layouts rent layout variant and man- supplied in structure age existing variants and save » f _ s a v e = e i t h e r x> [}> o r A

new variants.

Table 15.2 Layout Options

Value Mean ing

space The user cannot save the variant.

U The user can only save user-dependent variants.

X The user can save cross-user layout variants.

The user can save both user-related and cross-user layout variants.

Table 15.3 i_save Values

User -dependent var ian ts mus t start w i t h a let ter . A cus tomer 's cross-user var iants

(also k n o w n as s tandard var iants) mus t start w i t h a slash (/) . SAP's cross-user var i -

ants start w i t h a d ig i t (0-9).

Key Concepts Refresher Chapter 15 449

Note

Only standard layout variants can be transported. If the user has the required authorization, he can transport layouts in layout management by selecting LAY-OUT • TRANSPORT... from the menu.

D i sp lay Sett ings

To change the ALV layout y o u provide a work area to the parameter i s_1ayout. This structure al lows you , for example, to supply a t i t le, create a str iped (zebra) pattern for the lines, or opt imize the co lumn w id th . You fill the structure's rele-vant fields such as g r i d _ t i t i e , zebra, or cw id th_op t . This structure must be typed as L V C _ S _ L A Y 0 .

To sort the data in a specific order in the ALV Gr id Contro l when the gr id is ini-t ial ly displayed, y o u must prov ide an internal table for the I T_S0RT parameter. You use the table type L V C _ T _ S 0 R T to declare this internal table. In this internal table, y o u create a record for each field that is part o f the sort cr i ter ion. You spec-i fy the co lumn name in the field F I E L D N A M E . I f more than one field w i l l be part o f the sort cr i ter ion, y o u ei ther enter the sequence for each field in the sort cri-ter ion in the field SPOS, o r y o u prov ide the fields in the correct sequence for the sort order. To sort in ascending order, y o u place an x in the UP field.

Field Cata log

Because the display table does not have a fixed format, in order for the ALV g r id

to be able to display the data, a descr ipt ion o f the columns o f the ALV gr id must

be prov ided. The field catalog supplies this in format ion , wh ich is then used to

display the data or when creating a pr in t list.

As ment ioned above, the simplest way to generate the field catalog is to supply the name o f a structure f r om the ABAP Dict ionary to the ALV gr id in the param-eter i_s t ruc tu re_name. I f y o u cannot prov ide all details fo r all columns via the i_s t ruc tu re_name parameter, y o u provide this in format ion to the ALV g r id through the parameter i t _ f i e l d c a t a l o g . The internal table y o u supply to the parameter i t _ f i e l d c a t a l o g should be def ined using the table type L V C _ T _ F C A T , wh ich has the l ine type L V C _ S _ F C A T .

450 Chapter 15 ALV Grid Control

Common reasons for the inclusion o f a field catalog are:

• You want to change the display o f the output , for example, a d i f ferent co lumn

posi t ion or heading.

• The internal table has columns that are not contained in the Dict ionary struc-

ture that is suppl ied for the parameter i_s t ruc tu re_name.

I f y o u supply the parameter i _s t ruc tu re_name w i t h a Dic t iona iy structure, table, or v iew, y o u need to provide a row in the field catalog for eveiy co lumn o f the display data table that ei ther di f fers f r om the under ly ing Dict ionary struc-ture or is not contained in the Dic t iona iy object y o u supplied. This r o w must contain the technical propert ies and other format t ing in fo rmat ion for the col-umn.

W h e n y o u create a field catalog in the call ing program, y o u must assign the name o f the co lumn f rom the display data internal table to the field F I E L D N A M E . This field assigns a row in the field catalog to a co lumn o f the display data table. Other fields o f the field catalog can be d iv ided in to t w o groups based on their use when creating a field catalog:

• The field references a global type in the ABAP Dic t ionaiy . This applies to the

fields R E F _ F I E L D a n d R E F _ T A B L E .

• A l l other fields o f the field catalog provide values for the display propert ies

o f the co lumn.

The field catalog row requires m in ima l in fo rmat ion to be supplied; most o f the in fo rmat ion is opt ional . There are three basic ways o f placing data in to the cata-log (each o f these three global structures referenced be low could also be ei ther a global table or v iew):

• The field exists in a global structure w i t h the same name.

• The field exists in a global structure w i t h a d i f ferent name.

• The field docs not exist in a global structure.

I f the field exists w i t h the same name in a Dic t iona iy structure, table, or v iew, it is suff icient to assign the name o f the structure, table, or v iew to the field REF_ TABLE. I t is on ly necessaiy to add the field name f rom the structure to the REF_ F I E L D field i f the co lumn name o f the display data table and D ic t iona iy structure field name are d i f ferent .

Assigning values to the fields REF_TA8LE and. i f necessaiy, R E F _ F I ELD transfers all type def in i t ions f rom the specified structure fields in the ABAP Dict ionary. To

Key Concepts Refresher Chapter 15 15

overr ide a def in i t ion f rom the ABAP Dic t iona iy , y o u assign a value to one o f the fields other than REF_F I E L D and REF_TABLE. I f the field does not exist in a global s t ruc ture ,you do not assign values to the fields R E F _ T A B I E or REF_F I E L D , and y o u instead assign values to the other fields in the field catalog.

Columns that require special handl ing based on ei ther currency or un i t o f mea-sure are def ined in a s imi lar fashion. The fields relevant for these def in i t ions are shown in Table 15.4.

Value Applies to Entire Column Column Name Containing Value for Row

CURRENCY CFIELONAHE

QUANTITY QFIELDNAHE

Table 15.4 Special Handling for Columns

I f the ent i re co lumn is to be format ted using the same value, y o u specify this

value in the field shown above. I f this field for the co lumn contains a value, the

row-specif ic value is ignored i f i t exists.

So to format an ent ire co lumn for a specific currency, y o u place the currency key in the field CURRENCY, and as a result, the contents o f CFIELDNAME are ignored. The same is true for a quant i ty field. To format the ent i re co lumn w i t h the same un i t o f measure, y o u supply the un i t o f measure to the field QUANTITY. Do ing so ignores any values in QFIELDNAME. I f the entire co lumn is not to be format ted the same, y o u specify the co lumn name in the display table that contains the cur-rency key in CFIELONAME or the quant i ty 's un i t o f measure in QFIELONAME.

A L V Event H a n d l i n g

A n object can announce that its state has changed by tr igger ing events. A com-mon example w i t h the ALV gr id is a double-d ick: When the user double-clicks on a cell, the event DOUBLE_CLICK is tr iggered. You can program y o u r o w n han-dler methods in y o u r o w n class (normal ly a local class) that w i l l react to this event when it is tr iggered.

To have the handler method " l isten" for the tr iggered event, so that it is ready to

react i f the event occurs, y o u need to register this instance. I f the event is tr ig-

gered, the registered methods are executed in the order in wh i ch they were reg-

istered.

452 Chapter 15 ALV Grid Control

Your first task in hand l i ng events o f a con t ro l is i den t i f y i ng w h a t events can be

t r iggered. Exam in ing the associated class o f the con t ro l ( fo r o u r example, the

class CL_GUI_ALV_GRIO) and l ook i ng e i ther at the EVENTS tab or in the h ierarchal

l ist in the W o r k b e n c h expand ing the node EVENTS p rov ides y o u w i t h all o f the

pub l i c events that can be t r iggered. The cur ren t vers ion o f CL_GUI_ALV_GRID has

32 pub l i c events. Some o f the mo r e c o m m o n l y used events fo r th is class are

OOUBLE_CLICK, PRINT_TOP_OF_LIST, PRINT_TOP_OF_PAGE, PRINT_END_OF_PAGE,

PRINT_ENO_OF_LI ST, TOOLBAR,and USER.COMMAND.

To speci fy an event hand ler m e t h o d i n a local class, i n the d e f i n i t i o n par t y o u use

the add i t i on 'OR EVENT <event_name> OF <c1ass_name>. Th is add i t i on specif ies

that th is m e t h o d can react to the event <event_name> o f instances o f the class

<c1 ass_name>. You s t ructure the names o f event hand le r me thods as fo l l ows : 0N_

<event_name>, w h e r e <event_name> is the name o f the event . A n example o f th is

can be seen b e l o w i n L is t ing 15.15.

O n l y f o rma l parameters that were de f ined for the event can be used i n an event

hand ler m e t h o d . The types o f the parameters are taken f r o m the event . Whereas

y o u can o n l y inc lude parameters that are de f ined w i t h i n the event , it is not nec-

essaiy to IMPORT all parameters passed f r o m the RAISE EVENT statement . L is t ing

15.3 shows the d e f i n i t i o n o f a hand le r me thod , L is t ing 15.4 shows the imp le -

men ta t i on o f the hand le r me thod , and L is t ing 15.5 shows h o w to register the

hand ler m e t h o d .

CLASS l c l _ e v e n t _ r e c e i v e r DEFINITION. PUBLIC SECTION.

METHODS: h a n d l e _ d o u b l e _ c l i c k

FOR EVENT d o u b l e . c l i c k OF c l _ g u i _ a l v _ g r i d IMPORTING e_row e_column.

ENDCLASS. " I c l _ e v e n t _ r e c e 1 v e r DEFINITION

Listing 15.3 Definition of Handler Method

CLASS l c 1 _ e v e n t _ r e c e i v e r IMPLEMENTATION. METHOD hand1e_doub le_c l i c k .

REAO TABLE g t _ s f l i g h t INDEX e_row- index INTO g s _ s f l i g h t .

ENDMETHOD. " h a n d l e _ d o u b l e _ c l i c k

ENDCLASS. " 1 c l _ e v e n t _ r e c e i v e r IMPLEMENTATION

Listing 15.4 Handler Method

Key Concepts Refresher Chapter 15 453

O A T A : g r l d l TYPE REF TO c l_gu1_a lv_gr1d. even t_ rece ive r TYPE REF TO 1c l_even t_ rece i ve r .

CREATE OBJECT even t_ rece i ve r .

SET HANDLER event_rece1ver->handle_double_cl1ck FOR g r l d l .

Listing 15.5 Registering the Handler

A n example o f the complete process for handl ing events w i t h the ALV Object M o d e l is shown at the end o f the next section (see Listing 15.14 and Listing 15.15). The di f ference between them is that y o u need to get an event object before registering the handler.

To summarize the process:

1. Def ine the local class.

2. Define the handler method using the correct syntax and impor t ing any

parameters y o u want to use.

3. Implement the handler method.

4. Register the handler method using SET HANDLER, before the event can be trig-

gered (normal ly before the ALV gr id is displayed).

ALV Object Model

The ALV Object M o d e l (ALV O M ) is a new feature available f r om SAP

NetWeaver 6.40 on. In earl ier releases the ALV gr id was based on the global class

CL_GUI_ALV_GRID, wh ich we have already discussed. ALV Object M e t h o d is sim-

pler to use. We w i l l discuss the three output formats o f the ALV: the full-screen

ALV, the classic ABAP list, and the output in a container contro l as a subarea o f

a screen.

You must call at least the fo l l ow ing t w o methods in the ALV main class CL_SALV_

TABLE to obta in the desired ALV output :

• The FACTORY static method to instantiate an object o f the ALV main class. You pass in to this method an internal table that w i l l contain the data to be dis-played (the display table) f r om wh ich data is displayed. The display type (clas-sic, full-screen, in container) is also defined. It is not necessary to actually sup-ply the data in the display table at this po in t ( in other words, the table can be empty) . Dur ing the FACTORY method a reference to the actual table is created.

454 Chapter 15 ALV Grid Control

The data w i l l need to be popu la ted , howeve r , p r i o r to ca l l ing the next

me thod .

• The 01 SPLAY m e t h o d to place the A L V ou tpu t o n the screen.

Use the FACTORY m e t h o d instead o f the usual CREATE OBJECT. The FACTORY

m e t h o d is a class m e t h o d and re turns an A L V instance. (The CREATE OBJECT state-

men t can be f o u n d i n the FACTORY m e t h o d i tself ; i t generates the instance fo r y o u

and passes back the reference so that y o u can then w o r k w i t h the A L V gr id . ) You

use th is instance d u r i n g o the r m e t h o d calls to i nd i v i dua l l y adjust the A L V . I f y o u

have m u l t i p l e A L V displays o n a single screen, each w i l l have its o w n instance o r

reference var iable.

As w i t h the o lde r ALV, y o u need to def ine a reference var iable t yped w i t h refer-

ence to the class CL_SALV_TABLE. A g a i n y o u need a standard in te rna l table fo r dis-

play. The de f i n i t i ons are s h o w n i n L is t ing 15.6 and L is t ing 15.7.

TYPES: BEGIN OF g l t . o u t t a b .

c a r r i d conn id c o u n t r y f r c l t y f r o m a i r p f r o m c o u n t r y t o c i t y t o a i r p t o f l t l m e dept ime a r r t i m e d i s t a n c e d i s t i d f l t y p e p e r i o d

i c o n _ f l t t y p e t _ c o l o r t _ c e l 1 t y p e

END OF g l t _ o u t t a b . g t t _ o u t t a b TYPE STANDARO TABLE OF g l t . o u t t a b

WITH NON UNIQUE OEFAULT KEY.

Listing 15.6 Definition of Internal Table to Pass to ALV

TYPE s _ c a r r _ i d . TYPE s_conn_ id . TYPE l a n d l . TYPE s _ f r o m _ c i t . TYPE s _ f r o m a i r p . TYPE l a n d l . TYPE s _ t o _ c i t y . TYPE s _ t o a i r p . TYPE s _ f l t 1 m e . TYPE s_dep_t ime. TYPE s _ a r r _ t i m e . TYPE s _ d i s t a n c e . TYPE s _ d i s t i d . TYPE s _ f l t y p e . TYPE s _ p e r i o d . TYPE i c o n _ d . TYPE l v c _ t _ s c o l . TYPE s a l v _ t _ i n t 4 _ c o l u m n .

Key Concepts Refresher Chapter 15 455

OATA: g t _ o u t t a b TYPE g t t _ o u t t a b .

gs_ou t t ab TYPE g l t . o u t t a b .

Listing 15.7 Declaration of Internal Table to Pass to ALV

You then create the A L V instance by ca l l ing the FACTORY m e t h o d . L is t ing 15.8

shows the w a y to p roduce a classic l ist d isp lay, and L is t ing 15.9 shows the w a y

to p roduce the standard table d isp lay. The o the r op t i ona l parameters are also

s h o w n i n the f i rs t call. These c o m m e n t e d parameters a l l o w y o u to place the A L V

i n a conta iner . Both o f these calls p roduce a ful l -screen A L V because a conta iner

is no t speci f ied. The t w o necessary parameters are r _ s a l v _ t a b l e , w h i c h re turns

a reference to the created A L V , and t _ t a b l e , w h i c h is the in te rna l table that con-

tains (or w i l l conta in) the d isp lay data fo r the A L V .

TRY. CALL METHOD c l _ s a l v . t a b l e - > f a c t o r y

EXPORTING 11s t_d isp1ay - i f _ s a l v _ c _ b o o l _ s a p - > t r u e

* r _ c o n t a i n e r * conta iner_name -

IMPORTING r _ s a l v _ t a b 1 e - g r _ t a b l e

CHANGING t _ t a b l e - g t _ o u t t a b .

CATCH cx_salv_msg INTO g r _ e r r o r . g v _ s t r _ t e x t - g r _ e r r o r - > i f _ m e s s a g e ~ g e t _ t e x t ( ) . MESSAGE g v _ s t r _ t e x t TYPE ' E ' .

ENDTRY.

Listing 15.8 FACTORY Call for a List Display

TRY. c l _ s a l v _ t a b l e - > f a c t o r y (

IMPORTING r _ s a 1 v _ t a b l e - g r_ tab1e

CHANGING t . t a b l e - g t . o u t t a b ) .

CATCH cx_sa1v_msg INTO g r _ e r r o r . g v _ s t r _ t e x t - g r _ e r r o r - > 1 f _ m e s s a g e ~ g e t _ t e x t ( ) . MESSAGE g v _ s t r _ t e x t TYPE ' E ' .

ENOTRY.

Listing 15.9 FACTORY Call for a Standard Table Display

470 Chap te r 15 ALV Grid Contro l

To actually display Che ALV. you call the appropriately named instance method 01 SPLAY. This is shown in at the end of Listing 15.10. The output of the classic list display is shown in Figure 15.2, and the standard ALV is shown in Figure 15.3.

[ r i g h t s c h e d u l e i

M r l H t t f I15M. C M U f C * * r t O t j r C o u n t r y A r r i v a l c i t f

M 1 ; u s r o t o JTK US iAA f f c u t l S C O H I M «4 (A i U f l U M C I U O vo IH « » r o m j f i « 5 % If W no t < n u i t r u i T M A « 7 M I f W fCO * TOKiO Tf©

m * T « Y O TlO IT W fC© « m I f fCO w or>A«A KKI H m US fit CC f P L t u r u C T f*A K H W * *Cv r o t * US &AA F M K I f C f f © t l \n4 DC f U K I K O S * 0 U( v c m X w # T « Y O • t T K t p . » u r u « r F « A X m X H A ^ TOKIO *4T IM c* US YOtt j n LM 4 H III n i v r a t i J f K M i M v i i u r M A IM 4 i : X r u j r f * 1 r w US * » r e m J f i IH 24$J o c MA M M A M SLF IH 2MT M M H I I f l l M f M u f U l T R«A Of 5 S4 SIM t < n u a c T W F I A V X f t U « S c * T f » A f t s i « w S * SIN US U* FRAFTCIS<0 s*© M 19 « ' > u f f t i K I K C S ' O s * $ t « W m SIM 1 0 MXtATA Ml SQ ... tf S I I M W SIM j r T<*»0 Tr© i u * 4 1 X f A A M c f * T r t A u s t U H U i C f S C O fO IM US HUMCISC© s * 0 c« I M 1u IK I t • Y0>* j r r M r u t i n * ? r«A u* » i r 0€ R I A US r e m

Figure 15.2 List Display

Fh-ght sc hedul c a A V 7 2 •0 o a Ci

Flight schedule

C3 «r«gNN0 C* 1W, IMS I7 > K US S A N » R A N C « C O E / B I

AA M U ® & A S R R A N * : R ; C O W O V S A Z W » IT F C O « » R A AZ M IT rco jr T O W T V O AZ T C ^ R O TVO IT Km F C O AZ IT rco OWA *u et I M J * K H ' R A CC •m C O H C V W O A K J T K WS S A N T R A X C ^ C O s r o tx u » K F V V R C M C / > X TC4CT0 M * T w I K W J I W ! » H A

X 4 M W F R T T + J U F T T RCA T C ^ V O hP-I X 4 0 0 C € F F R A N ^ Y O T V S Jfr I X 4 M C O revivor: J » K C€ F R A I X 4 0 J O F f R W J u O T F R A u t I X I 4 M C € FFRAVKJUOT FFTA C< I X J 4 W C « T * . M I R A c# S 90 SW C< fRA^TCWT fRA

<# I C€ I f r A ^ ^ t fRA SO & H 5 0 2 DO 5 W MS SAN 'RANCCCO V O M IS CO (ANfRANCeSCO V O so 8 0 I S * d o <» TA ^ T 5 0 t M CO S M TYO UA •41 C€ f R A M U R T IRA MS S A N f R A N C « : 0 y o UA >M4 « fRA U * M i l U l JtK C«

US fMA^yi^TT 1 HA

UA H 1 7 CC fRA C« US m w r C f l K jn

Figure 15.3 Standard ALV

Key Concepts Refresher Chapter 15 457

Note

The classic list display is stil l possible because it is the only way to display mul t i -

ple rows for a record.

CLEAR: g t _ o u t t a b . SELECT * FROM s p f l i

INTO CORRESPONDING FIELDS OF TA8LE g t _ O u t t e b WHERE c a r r i d IN s _ c a r r i d .

TRY. c l _ s a l v _ t a b l e - > f a c t o r y (

IMPORTING r _ s a 1 v _ t a b 1 e - g r _ t a b 1 e

CHANGING t _ t a b l e - g t _ o u t t a b ) .

CATCH cx_sa lv_msg INTO g r _ e r r o r . g v _ s t r _ t e x t - g r _ e r r o r - > 1 f _ m e s s a g e ~ g e t _ t e x t ( ) . MESSAGE g v _ s t r _ t e x t TYPE ' E 1 .

ENDTRY.

g r _ t a b l e - > d 1 s p l a y ( ) .

List ing 15.10 Select. Create the ALV and Display It

N o t i c e tha t t he re is n o field cata log a n d n o s t r u c t u r e n a m e p r o v i d e d . I f t he fields

r e fe renced i n the data table are d e f i n e d w i t h re fe rence t o data e l emen ts i n the

A B A P D i c t i o n a r y , y o u n e e d d o n o t h i n g else. I f y o u w a n t , h o w e v e r , t o change the

d isp lay p r o p e r t i e s o f t he A L V , m e t h o d s ex is t tha t a l l o w y o u t o change h o w the

tab le is d i sp layed .

You can, f o r examp le , d i sp lay a c o l u m n as an i c o n o r change the h e a d i n g o f a col -

u m n (shor t , m e d i u m , l ong , o r t o o l t i p ) . These m e t h o d s a l l o w y o u t o r e o r d e r co l -

u m n s . spec i fy t he so r t o r d e r , o r h i d e c o l u m n s , a m o n g o t h e r t h ings . T h e b iggest

advantage o f t he n e w t e c h n i q u e is t he speed w i t h w h i c h i t is poss ib le t o w r i t e a

p r o g r a m to p r o d u c e an A L V . Because the field i n f o r m a t i o n is a u t o m a t i c a l l y p ro -

d u c e d o r d e r i v e d , y o u o n l y n e e d t o p r o g r a m changes.

Caut ion

The classes discussed in the rest of this section are not superclasses and sub-

classes in the sense of object-or iented inheritance. This means that classes lower

in the hierarchy do not inherit properties of classes higher in the hierarchy.

458 Chapter 15 ALV Grid Control

The terms hierarchy, superobject, and subobject are used to identify the parts of an ALV and show how all objects together represent the ALV as a whole.

To change an ALV using the ALV Object Mode l , y o u jus t need to have an object-

or iented v iew o f the ALV. Simply put, the ALV i tsel f is an object, and its compo-

nents, such as columns, funct ions, sort ing, and so on are themselves objects, but

are the subobjects o f the ALV. I f y o u want to change something about the ALV,

y o u s imply need to:

• Fetch the relevant subobject responsible for the proper ty to be changed f r om

the parent object ( in this case the ALV instance), for example, columns.

• Call the method to change the status o f the subobject.

List ing 15.11 shows the two steps by setting the zebra pattern. First, the ALV

table reference is used to retr ieve the display settings, and then the result ing

object is used to call the appropriate method to change the attr ibute.

Listing 15.11 Calling a Sub-Object

No th ing else is necessaiy: the change takes effect immediate ly. For some ele-ments o f the ALV, such as columns and funct ions, there are addi t ional levels o f subobjects. The plural named superobject "columns" contains propert ies that apply to all columns or that affect the interact ion o f all columns, such as co lumn order. The singularly named subobject, for example the co lumn AIRLINE, con-tains the propert ies that are on ly val id for that one co lumn, such as the co lumn tit le. The same t w o steps are repeated for as many levels as y o u need to process; retr ieve the object reference f rom the parent object and use this object reference to call the method to make the change. Table 15.5 be low contains the most-used subobjects. the method call to the ALV to retr ieve the subobject, and the class o f the subobject. Examples o f this can be seen in List ing 15.12.

D A T A : l r . d i s p l a y TYPE REF TO c l _ s a l v _ d i s p l a y _ s e t t i n g s .

l r _ d i s p l a y - g r _ t a b l e - > g e t _ d 1 s p l a y _ s e t t i n g s ( ) . l r _ d i s p l a y - > s e t _ s t r i p e d _ p a t t e r n ( v a l u e -

i f _ s a l v _ c _ b o o l _ s a p - > t r u e ) .

D A T A : 1 v _ s h o r t 1 v _ m e d 1 u m 1 v _ l o n g l v _ t o o l t i p

TYPE s c r t e x t _ s , TYPE s c r t e x t _ m . TYPE s c r t e x t . l . TYPE 1 v c _ t i p .

Key Concepts Refresher Chapter 15 459

l r _ c o l u m n TYPE REF TO c l _ s a l v _ c o l u m n .

1 r_co lumns TYPE REF TO c l _ s a l v _ c o l u m n s _ t a b l e . i r _ c o l u m n s - g r _ t a b l e - > g e t _ c o l u m n s ( ) .

TRY. l r _ c o l u m n - i r _ c o l u m n s - > g e t _ c o l u m n ( 'FLTYPE' ) . 1 r _ c o l u m n - > s e t _ v i s i b l e ( i f _ s a l v _ c _ b o o l _ s a p - > f a l s e ) .

CATCH cx_sa 1 v _ n o t _ f o u n d . "//EC NO_HAMOLER ENDTRY.

TRY. CALL METHOD i r _ c o l u m n s • > g e t _ c o l u m n

EXPORTING columnname - 'ICON_FLTTYPE'

RECEIVING v a l u e - l r _ c o l u m n .

l v . s h o r t - ' C h a r t e r ' ( h 3 7 ) . 1 r _ c o l u m n - > s e t _ s h o r t _ t e x t ( l v _ s h o r t ) . lv_medium - ' C h a r t e r f l i g h t ' ( h 3 8 ) . l r _ c o l u m n - > s e t _ m e d i u m _ t e x t ( lv_tnedium ) . 1 v _ l o n g - ' C h a r t e r f l i g h t ' ( h 3 9 ) . l r _ c o l u m n - > s e t _ l o n g _ t e x t ( l v _ l o n g ) . 1 v _ t o o l t i p - ' C h a r t e r f l i g h t " ( h 4 0 ) . l r _ c o l u m n - > s e t _ t o o l t i p ( 1 v _ t o o l t i p ) .

CATCH c x _ s a l v _ n o t _ f o u n d . "//EC NO_HANDLER

ENDTRY.

List ing 15.12 Gett ing the Sub-Object f rom the ALV. Hiding a column, and

Add ing a Column Heading to a New Column

T h e u p p e r m o s t class o f the A I . V Ob jec t M o d e l class h i e r a r c h y is the class CL_

SALV_TABLE. I n A L V s u b o r d i n a t e classes, n a m i n g c o n v e n t i o n s can h e l p y o u iden-

t i f y t he leve l o f t he ob jec t ; i f t he n a m e is p l u r a l ( f o r e x a m p l e , CL_SALV_COLUMNS_

TABLE), i t re fers t o t he p r o p e r t i e s o f a g r o u p o f A L V e lemen ts . I f t he n a m e is s in-

gu l a r ( f o r e x a m p l e . CL_SALV_C0LUMN_TA8LE).you are dea l i ng w i t h t he p r o p e r t i e s

o f a s ing le e l e m e n t .

I n Tab le 15 .5 . each o f the GET m e t h o d s (al l are par t o f CL_SALV_TABLE) is s h o w n

w i t h t he ob jec t it de l i ve rs a n d a shor t d e s c r i p t i o n .

474 Chapter 15 ALV Grid Control

GET M e t h o d Class of the Delivered Descr ipt ion Object

GET_AGGREGATIONS CL_SALV_AGGREGATIONS Aggregated objects

GET.COLUHNS CL_SAL_COLUMNS_TABLE Columns superclass

GET_DISPLAY_SETTINGS CL_SALV_DISPLAY_SETTINGS Defining the display, i.e.,

tit le, stripe pattern, lines,

etc.

GET_EVENT CL_SALV_EVENTS_TABLE Events

GET_FI LTERS CL_SALV_FI LTERS Filter criteria

GET_FUNCTIONAL_ CL.SALV.FUNCTI0NAL_ Hyperlink and toolt ip SETTINGS SETTINGS s u p e r c | a $ s

GET_FUNCTIONS CL_SAL_FUNCTIONS_LIST Functions such as sorting.

aggregating, etc.

GET.LAYOUT CL_SALV_LAYOUT Layout variant storage.

management, etc.

GET_PRINT CL_SALV_PRINT Printer settings

GET_SELECTIONS CL_SALV_SELECTIONS Selection mode and selec-

tions

GET_S0RTS CL_SALV_SORTS Sorting criteria

Table 15.5 ALV Object Mode l Methods

The re are also GET me thods f o r subobjects o f the second leve l ( the subob jec t o f

the A L V ob jec t ) . These do no t app l y to the A L V ob jec t , bu t ra ther to the subob-

j e c t ' s subobject , f o r example , the ob jec t c o n t a i n i n g al l c o l u m n s o f the A L V (class

CL_SAL_C0LUMNS_TA8LE). Table 15 .6 shows the GET me thods f o r these subclasses

and the objects they de l i ve r .

Class Get M e t h o d Returns Object of Descr ipt ion Type

CL_SALV_ GET.AGGREGATION CL.SALV. An individual AGGREGATIONS AGGREGATION aggregation

Table 15.6 ALV Subobject Methods

Key Concepts Refresher Chap te r 15 475

Class

Cl_SAL_COLUMNS_ TABLE

Get Method

GET.COLUHN

CL_SALV_flLTERS GET_FILTER

CL_SALV_ FUNCTIONAL. SETTINGS

CL_SALV_ FUNCTIONAL. SETTINGS

CL_SALV_ FUNCTIONS_LIST

CL_SALV_SORTS

GET_HYPERLINKS

GET_T00LTIPS

GET_FUNCTIONS

GET_S0RTS

Returns Object of Type

CL_SAL_C0LUMN_ TABLE

CL_SALV_FILTER

CL_SALV_ HYPERLINKS

CL_SALV_TCOLTIPS

CL_SALV_FUNCTI0N

CL_SALV_S0RT

Description

One indiv idual col-

umn

One indiv idual f i l-

ter cr i ter ion

Superclass for all

hyperl inks

Superclass for all

too l t ips

One indiv idual

func t ion

One indiv idual

sort ing cr i ter ion

Table 15.6 ALV Subobject Me thods (cont.)

The process used to place the ALV grid in a container on the screen follows the same initial steps as the older version of the ALV Grid Control, but then provides the container instance to the FACTORY. An example is shown in Listing 15.13.

IF g r _ c o n t a i n e r _ 2 1 0 0 IS NOT BOUND. CREATE OBJECT g r _ c o n t a i n e r _ 2 1 0 0

EXPORTING c o n t a i n e r _ n a m e - 'CONTAINER_2100' .

TRY.

c l _ s a l v _ t a b l e - > f a c t o r y ( EXPORTING

r _ c o n t a i n e r - g r _ c o n t a i n e r _ 2 1 0 0 c o n t a i n e r _ n a m e - ,CONTAINER_2100'

IMPORTING

r _ s a l v _ t a b l e - g r _ t a b l e _ 2 1 0 0 CHANGING

t _ t a b l e - g t _ o u t t a b _ 2 1 0 0 ) . CATCH c x . s a l v j n s g . "//EC N0_HAN0LER

ENDTRY. PERFORM r e g i s t e r _ e v e n t s _ 2 1 0 0 USING g r _ t a b l e _ 2 1 0 0 .

462 Chapter 15 ALV Grid Control

g r_ tab1e_2100->d isp1ay( ) . ENDIF.

Listing 15.13 Producing an ALV in a Container Using ALV Object Model

Bccausc this r ou t i ne is in code that is rcexccutcd, the code is placed i n a check to

see i f the conta iner already exists. I f the conta iner does no t exist, a conta iner is

created. Once i t creates the conta iner , the FACTORY m e t h o d is cal led, p r o v i d i n g

the con ta iner name and the reference to the created con ta iner (on ly the reference

is actual ly necessaiy). Events are registered ( the sub rou t ine is s h o w n i n L is t ing

15.15) and the A L V is d isp layed. To p r o v i d e a d i s t i nc t ion be tween m u l t i p l e con-

tainers. w e have assigned a un ique n u m b e r to the var ious parts ( in this case the

screen number ) .

W e have s imp l i f i ed this example s l igh t ly fo r space rest r ic t ions. Obv ious l y , there

shou ld be e r r o r hand l i ng f o l l o w i n g the CATCH statement. A lso, calls to subrou-

t ines to m o d i f y the technical a t t r ibutes o f the d isp layed table w e r e o m i t t e d . W e

r e c o m m e n d p lac ing these (somet imes lengthy) changes to the A L V in subrou-

t ines o r o the r modu la r i za t i on un i ts to p r o v i d e c lar i ty . Especially i n the case o f

d y n p r o p r o g r a m m i n g , w h e r e y o u may be p r o v i d i n g many d i f f e ren t conta iners,

o f ten y o u may be able to reuse some o f these modu la r i za t i on uni ts .

Th is leads us to the PERFORM that remains before the actual d isp lay. This process

again is s im i la r across b o t h A L V classes (and any o the r t ype o f event hand l ing) .

L is t ing 15 .14 shows the d e f i n i t i o n and i m p l e m e n t a t i o n o f a local class to hand le

the events raised (or at least the ones this p r o g r a m is in terested i n processing)

f r o m the A L V events class. The example concerns bo th doub le cl icks and s ingle

cl icks. W h e n the event is t r iggered, ou r local class calls a sub rou t ine to process

the event .

CLASS lc)_hand1e_events_2100 DEFINITION. PUBLIC SECTION.

METHOOS: o n _ d o u b l e _ c l i c k FOR EVENT d o u b l e _ c l i c k

OF c l _ s a l v _ e v e n t s _ t a b l e IMPORTING row column.

o n _ l 1 n k _ c l i c k FOR EVENT l i n k _ c l i c k

OF c l _ s a ! v _ e v e n t s _ t a b l e IMPORTING row column.

ENDCLASS. " l c l _hand le_even ts_2100 DEFINITION

CLASS l c l _hand le_even ts_2100 IMPLEMENTATION.

Important Terminology Chapter 15 477

METHOO on_doub le_c1 i ck . PERFORM doub le_c l i c k_2100 USING row column .

ENOMETHOD. • o n _ d o u b l e _ c l i c k METHOD o n _ l i n k _ c l i c k .

PERFORM 11nk_cl1ck_2100 USING row column . ENOMETHOD. "on J i n k . c l i c k

ENOCLASS. ' l c l _hand le_even ts_2100 IMPLEMENTATION

Listing 15.14 Definit ion of Local Event Handlers

A f t e r creat ing ou r A L V reference ob ject and be fo re d isp lay ing the table, w e need

to actual ly register the events. As w i t h the o lde r A L V (or any o the r t ype o f event

processing), y o u have the hand le r m e t h o d o f the instance " l i s ten" for the t r ig-

gered event . To do this y o u need to register th is instance w i t h the ob ject that can

t r igger the event ( p roduc ing ef fect ive ly a l ist o f l isteners). A n example o f th is is

s h o w n i n L is t ing 15.15.

FORM r e g i s t e r _ e v e n t s _ 2 1 0 0 USING p _ g r _ t a b l e TYPE REF TO c l _ s a 1 v _ t a b l e .

OATA: l r _ e v e n t s TYPE REF TO c l _ s a l v _ e v e n t s _ t a b l e . IF gr_events_2100 IS NOT BOUND.

CREATE OBJECT gr_even ts_2100 . ENOIF. l r _ e v e n t s - p _ g r _ t a b l e - > g e t _ e v e n t ( ) . SET HANOLER g r_even t s_2100 ->on_doub le_c l i c k FOR l r _ e v e n t s . SET HANOLER g r _ e v e n t s _ 2 1 0 0 - > o n _ l i n k _ c l 1 c k FOR l r _ e v e n t s .

ENDFORM. " r e g i s t e r _ e v e n t s _ 2 1 0 0

Listing 15.15 Registering Events

U n l i k e the o lde r vers ion o f A L V (where i t is no t necessaiy to create an ob ject to

the event class because the events be long to the A L V class), w e create an object

o f the event class (CL_SALV_EVENTS_TABLE) i f w e do no t have a va l id reference

and then set the handlers fo r the t w o events w e are in terested in processing.

I m p o r t a n t T e r m i n o l o g y

You shou ld n o w k n o w w h a t a field catalog is and h o w to p roduce one fo r an A L V .

You shou ld also unders tand the process for p r o d u c i n g an A L V i n fu l l -screen

m o d e and i n a conta iner , i n b o t h vers ions o f the A L V .

464 Chap te r 15 ALV Gr id Cont ro l

You should also have a thorough understanding of events related to an ALV. You need to understand how to write the handler method, how to register the event handler, and where to identify what events can be triggered. Figure 15.4 shows the events for the ALV Object Model and Table 15.7 shows the events for the grid control.

C i t t t ' i m n t o c * 3

I C U _ 3 « . V . £ V 5 N T $ . T * e u • Gf

- i r o i

M f t K t N M M ] c * » < n p O o «

f ' C i C I - S A L V _ E V t N T 8 , . T A e L E

t- • S t * * r c i m * *

t' Q . M M t O M

^ Q e v w u

C W M I tn S>mpl». T w o - O n w w o n n T * M

^ C i n h w W d E « t s

^ C i I F . S A L V E V t N T S F U N C T I O N S ALV E w t t »3< Function?

Q A O O e O . F I J N C T l O N Cer t ro i Afl t f E « K U » o n c ( a « x k » o n - D « f r « ( j F i r « o n

O A F T E R . S A L V . F U N C T I O N Cor t ro l A .1« E « * : u s o n c( a 0 « n « r K ALV FurKfcxi

O B E F O R E . S A L V . F W C T I O N C c f t o l 6 * t 3 f « E n c u b o n Of a 0 » n « A L V F j K D o n

" C J I F . S A L V . E V i N T S . U S T ALV E w t 3 tot U i t S

O E N D . O F . P A G E

O T O P . O f . P A O E

Ccr t ro l a«Tlm« E N O O f PAGE ( U M P ( « c » t « i n g )

Cer t ro l at T i m « TOR-OF-PAOE { U t t P r a < * t « l n « )

" Q I F . S A J . V . E V E N T S _ A C T K > N S _ T * 0 ^ ALV E r t ^ t t Hi S « - M « n t l l U t l t

O C X X ® L E _ C U C X C & t t o l AflCf O o u M t - C M k

O U N K . C U C K C&rtrol Afl t f Click on ot BuOjn

Figure 15 4 Events for CL_SALV_EVENTS_TABLE

Event Description

AFTER.REFRESH Af ter list refresh

AF TER_USER_COMMaND Af ter user command

BEFORE_USER_C0MHAN0 Before user command

BUTTON.CLICK But ton click

CL!CK_COL_HEADER Click on co lumn header

CLICK_ROH_COL Click on cell

CONTEXT.HENU Context menu

CONTEXT_MENU_REOUEST Context menu

CONTEXT_HENU_SELECTEO Context menu entry selected

DATA_CHANGED Data was changed

Table 15.7 Events for CL_GUI_ALV_GRID

Important Terminology Chapter 15 479

Event Descr ipt ion

DATA_CHANGEO_FINISHEO Data in the output table was updated

OBLCLICK_ROW_COL Double-click on cell

DELAYED_CALLBACK Delayed callback

DELAYEO.CHANGE.SELECTION Selection has been modif ied

DELAYED_CHANGED_SEL_CALLBACK

OElAYEO_MOVE_CURRENT_CELl

OOUBLE.CLICK

DOUBLE_CLICK_COL_SEPARATOR

ENO_OF_LIST

Fl

H0TSP0T_CLICK

LEFT_CLICK_DESIGN

LEFT_CLICK_RUN

MENU_BUTTON

MOVE.CONTROL

ONORAG

0N0R0P

0N0R0PC0MPIETE

ONOROPGETFLAVOR

ONF1

0NF4

PRINT_END_OF_lI ST

The event is triggered if the user selects a row or column that has not yet been selected. The ALV Grid Control triggers this event wi th a short delay of 1.5 seconds.

Focus cell has been moved

Double click

Double-dick on column separator

End_of_list

F1 chosen

Hotspot was selected

Left mouse but ton pressed on control in design

mode

Left mouse but ton pressed on control in run

mode

Menu button

Control moved

For drag source

For drop target

For drag source in case of success

Mul t ip le flavors possible at a drop

On help request

On value request

Print mode: END_OF_LIST of classic ALV

Table 15.7 Events for CL_GUI_ALV_GRID (cont.)

466 Chap te r 15 ALV Grid Contro l

Event Description

P R I N T _ E N D _ O F _ P A G E Print mode: END_0F_PAGE in list processing

P R I N T _ T 0 P _ 0 F _ L I S T Print mode: T 0 P _ 0 F _ L I S T of classic ALV

P R I N T _ T O P _ O F _ P A G E Print mode: TOP_OF_PAGE in list processing

R I G H T _ C L I C K Right mouse but ton clicked on control

S I Z E _ C 0 N T R 0 L Control resized

S U B T O T A L . T E X T Edit subtotals text

T O O L B A R Toolbar

T O O L B A R _ B U T T O N _ C L I C K Toolbar but ton chosen

T O O L B A R _ M E N U _ S E L E C T E D Toolbar menu entry selected

T O O L B A R _ H E N U B U T T O N _ C L I C K Toolbar menu but ton chosen

T 0 P _ 0 F _ P A G E Top of page

T O T A L _ C L I C K _ R 0 H _ C 0 L Click on totals line

U S E R _ C 0 M H A N 0 User command

Table 15.7 Events for CL_GUI_ALV_GRID (cont.)

% Practice Quest ions

T h e prac t ice q u e s t i o n s b e l o w w i l l h e l p y o u eva lua te y o u r u n d e r s t a n d i n g o f t he

top i c . T h e q u e s t i o n s s h o w n are s i m i l a r i n na tu re to those f o u n d o n the cer t i f i ca-

t i o n e x a m i n a t i o n , b u t w h e r e a s n o n e o f these ques t i ons w i l l be f o u n d o n the

e x a m i tse l f , t h e y a l l o w y o u to r e v i e w y o u r k n o w l e d g e o f t he sub jec t . Select the

co r r cc t answers a n d t h e n chcck t he comp le teness o f y o u r answers i n t he f o l l o w -

i n g s o l u t i o n sec t ion . R e m e m b e r tha t y o u m u s t select a l l co r rec t a n s w e r s a n d o n l y

co r rec t answers to rece ive c red i t f o r the q u e s t i o n .

1. W h a t is the best o r d e r to p r o v i d e an e v e n t h a n d l e r f o r an A L V :

• A . Create t he A L V , w r i t e the h a n d l e r , reg is ter f o r t he even t , d i sp l ay the A L V

• B. Register f o r t h e even t , w r i t e t he h a n d l e r , create t he A L V , d i sp lay t he A L V

• C. W r i t e the hand le r , reg is te r f o r t he even t , create the A L V , d i sp l ay t he A L V

Practice Questions Chapter 16 467

• D. Wr i t e the handler, create the ALV, register for the event, display the ALV

• E. Wr i t e the handler, create the ALV, display the ALV, register for the event

2. The differences between displaying in a fu l l screen and in a container are:

• A. The fu l l screen requires dynpro programming.

• B. The container requires the use o f an addi t ional object (a container con-trol).

• C. The on ly di f ference is that the container name must be specified when creating the ALV object.

• D. On ly a full-screen ALV al lows the use o f event handl ing.

• E. On ly an ALV in a container al lows the use o f event handl ing.

• F. Any type o f ALV al lows the use o f event handl ing.

3. To reserve an area on the screen for an ALV Gr id Contro l y o u must:

• A. Create an object (instantiate the object) o f the class C L _ G U I _ C U S T O M _ C O N T A I N E R

• B. Create an object (instantiate the object) o f the class C l _ G U l _ A L V _ G R I D

• C. Create an object (instantiate the object) o f the class C L _ S A L V _ T A B L E

• D. Use the Screen Painter

4. You must call a method to actually display the contents o f the display table

after y o u create an ALV.

• A. True

• B. False

5. The field catalog al lows y o u to:

• A. To add a field to the display

• B. To specify the sort order o f the display table

• C. To produce a str iped pattern for the display lines

• D. To change the t i t le o f a co lumn

• E. To change the display order o f a co lumn

468 Chapter 15 ALV Grid Control

6. Which class is used to define a reference for an instance o f the ALV Object Model :

• A. Class CL_GUI_CUSTOM_CONTAINER

• B . Class C L _ G U I _ A L V _ G R I D

• C. Class CL_SALV_TABLE

7. You use the CREATE OBJECT statement to create both types o f ALV.

• A. True

• B. False

8. The ALV Object Model :

• A. Is a group o f classes that describe the ALV grid as a whole and inherit f rom a single class

• B. Is a group o f hierarchal classes that describe the ALV grid as a whole but do not inherit f rom a single class

P r a c t i c e Q u e s t i o n A n s w e r s a n d E x p l a n a t i o n s

1. Correct answer: D

You should wr i te the handlers, create the ALV, and then register the events o f the ALV you just created before y o u actually display the ALV.

2. Correct answers: B, F

The container requires the use o f an additional object to l ink the control that exists on the presentation server to the program running on the application server. A container control provides this function and is produced f rom the class CL_GUI_CUST0M_C0NTAINER.

3. Correct answer: D

To allocate an area on the screen y o u use the Screen Painter to "draw" the container on the screen and name it. Later when the program creates the object for the container, this name is used to assist in l inking the control in the SAP GUI w i th the application program.

4. Correct answer: A

This is true for both versions of ALV. In both cases you create the ALV and then call a display method for that object. The method for the ALV Grid Con-

Take Away Chapter 14

trol is SET_TABLE_FOR_FIRST_DISPLAV o f the class CL_GUI_ALV_GRID. and for the ALV Object Mode l the method is 01 SPLAY f rom the class Cl_SALV_TA8lE.

5. Correct answers: A, D, E

The field catalog allows you to add a column to the display, hide a column f rom the display, change the tit le o f a column, or place the columns in a dif-ferent order. The ALV Grid Control expects different parameters to provide information for sorting, f i l tering, changing the layout, or providing variants.

6. Correct answer: C

The ALV Grid Control uses the class CL_GUI_ALV_GRID, and the ALV Object Model uses the class CL_SALV_TA8LE.

7. Correct answer: B

The CREATE OBJECT statement is only used to instantiate the ALV Grid Con-trol. The FACTORY method o f the class CL_SALV_TA8LE is used to instantiate an ALV Object Model ALV grid. The CREATE OBJECT is in fact inside the FACTORY method, so an object is created for you, and then the reference is passed back out o f the method.

8. Correct answer: B

The classes o f the ALV Object Model are not superclasses and subclasses in the sense o f object-oriented ABAP; that is, the classes lower in the hierarchy here do not inherit the properties o f the classes higher in the hierarchy. The terms hierarchy, superobject, and subobject should rather illustrate how all objects together represent the ALV as a whole.

Take Away

You wi l l need to understand the field catalog: how to produce one and how to modi fy it. You need to know the process for producing an ALV in a ful l screen and in a container, in both versions o f the ALV. You also need to know about event handling for an ALV. You need to know the steps: wr i te the handler, reg-ister the event, and where to identify what events can be triggered.

Refresher

You must understand the steps necessaiy to place an ALV grid in a container: f rom allocating space in the screen using Screen Painter to creating the container

470 Chapter 15 ALV Grid Control

i n y o u r p rog ram and p lac ing the A L V in to the conta iner . Ef fect ive use i n a con-

ta iner requi res an unders tand ing o f classic d y n p r o hand l i ng (see also Chapter 9,

Basic ABAP Programs and Interface Creat ion, and Chapter 12, Classical Screens).

Table 15.8 shows the key concepts fo r A L V p r o g r a m m i n g .

Key Concept Definition

Container control The container control is used to connect the dynpro to the control. This allows the ALV grid to "sit" inside the container, which itself sits inside the reserved area on the screen.

Control Controls are stand-alone binary software components that are reusable.

Field catalog The field catalog contains the rules that describe how the data table is to be displayed.

ALV Object Model The ALV Object Model was a new feature in SAP NetWeaver 6.40. It is more modern and simpler to use than the original ALV Grid Control.

Table 15.8 Key Concepts Refresher

Tips

As w i t h the m a j o r i t y o f the subjects f o u n d i n the cer t i f i ca t ion examina t ion , i t is

i m p o r t a n t to have as m u c h pract ical exper ience w i t h the subject as possible. W e

suggest that i f y o u have not had m u c h exposure to A L V p r o g r a m m i n g , w r i t e a

coup le o f qu ick p rograms to unders tand the concepts. You shou ld use b o t h ver-

sions o f the A L V and b o t h fu l l screen and i n a conta iner . S imp ly select data f r o m

a database table and then p roduce the A L V .

S u m m a r y

You shou ld n o w be able to p roduce A L V gr ids i n a var ie ty o f ways and under -

stand h o w to interact w i t h the A L V and the user t h r o u g h events. This know ledge

w i l l a l l ow y o u to easily pass this top ic o n the cer t i f i ca t ion examina t ion .

User Interfaces (Web Dynpro)

Techniques You'll Master:

• Understand the architecture o f a Web Dynpro component

• Explore the navigation and data transfer in and between Web Dynpro components

• Identify the most important elements that are part o f a Web Dynpro application

• Name the contents o f a Web Dynpro controller

• Define the mapping between contexts o f dif ferent controllers located in the same Web Dynpro component

472 Chapter 16 User Interfaces (Web Dynpro)

Web Dynpro is a framework for SAP standard user interfaces and provides sup-port for the development o f the Web representation o f business applications. Web Dynpro is available on both the ABAP and the Java development environ-ments.

In this chapter you w i l l be provided w i th a basic understanding o f Web Dynpro ABAP. We wi l l discuss the architecture o f Web Dynpro components. We wi l l dis-cuss the Model View Controller design paradigm used in Web Dynpro ABAP and the differences between this and UI design models. We w i l l cover the different types o f controllers, ident i fy ing their differences and explaining how they are used. We wi l l also explain data exchange between the components o f a Web Dynpro application.

Real-World Scenario

You have been asked to identify what technology is best to develop ABAP-based web transactions. There are a number o f encapsulated functions developed for use in your company's SAP system that management wou ld like to make available in a web browser.

The thought is that a web-based application wou ld be simpler to rol l out to users and easier for them to learn. The fact that it is browser-based means that the SAP GUI does not need to be installed, so it would have minimal impact on both users and your IT department, and new functionali ty could be rolled out simply by providing links to this new functionality.

However, management also wants to have controls in place. They want to be able to control authorizations and j o b function access to some o f the data. O f the available web-based user interfaces.you f ind that Web Dynpro meets the entire criterion for your company. Now you need to explain the technology to the other developers.

Object ives of th is Por t ion of t he Test

The purpose o f this port ion o f the certification examination is to veri fy that y o u have an understanding o f Web Dynpro ABAP and its capabilities. Therefore, this port ion o f the examination w i l l test your knowledge o f a Web Dynpro develop-ment. The points that you w i l l need to understand f rom this section include:

Key Concepts Refresher Chapter 15 473

• The architecture o f a Web Dynpro component and how these components can be l inked

• The use o f a Web Dynpro component that is reusable and mandatory

• The contents o f a Web Dynpro controller and how they work together

The certification examination w i l l give medium weight to this chapter compared to the other topics in the examination. Because this is similar in concept to clas-sical dynpro programming, it is given a similar weighting. This means there w i l l be an average percentage o f questions when comparing this chapter than any other chapter.

Key Concepts Refresher

You need to understand and be able to perform the fo l lowing types o f tasks when developing Web Dynpro ABAP applications:

• Navigation and data transfer w i th in a Web Dynpro component and between Web Dynpro components

• Define the mapping between contexts o f different controllers located in the same Web Dynpro component

• Declare the usage o f a component in another component

Web Dynpro Design

Web Dynpro is one o f the SAP NetWeaver standard programming models for user interfaces (UIs). The Web Dynpro framework is based on the Model View Controller paradigm to ensure a clear division between the def ini t ion of the user interface and the implementation o f the application logic. It has the fo l lowing features that bui ld on the classic dynpro model:

• A clear separation between business logic and display logic.

• A uni form metamodel for all types o f user interfaces. User interface patterns normally only contain generic functions o f the user interface (for example, a search) and describe the general appearance o f the interface.

• Execution on a number o f client platforms. The metadata o f Web Dynpro is independent o f the platform where the application is executed. I f the meta-data is transferred to a different platform, new source code for that platform is generated.

474 Chapter 16 User Interfaces (Web Dynpro)

Web Dynpro is available in both the ABAP and the Java development environ-ments. It provides tools for developing a web-based business application. You use these tools to describe the properties and functions o f Web Dynpro applica-tions in the form o f Web Dynpro metadata. The user interface source code nec-essaiy for Web Dynpro is automatically generated and executed at runtime.

Each user interface in Web Dynpro is always made up o f the same basic ele-ments, for example, UI elements. These elements o f the metamodel arc declared using Web Dynpro tools. This allows y o u to define the user interfaceyou require for adding buttons, fields, and so on. The system automatically generates the nec-essaiy code for this metamodel.

Web Dynpro ABAP was released w i th SAP NetWeaver Application Server 7.0. To support this declarative concept o f a Web Dynpro application, the ABAP Work-bench (the central point o f ent iy into the ABAP Workbench is Transaction SE80, the Object Navigator) now contains a range o f Web Dynpro tools. You can gen-erate a large proport ion o f a Web Dynpro application using the tools provided, wi thout the need to create your o w n source code. This applies to the fo l lowing pans o f the application:

• Data f low between the frontend and backcnd

• Layout o f the user interface

• Properties o f user interface elements

Eveiy Web Dynpro application is structured according to the Model View Con-trol ler paradigm:

• Mode l The model is the interface to the system and enables the Web Dynpro appli-cation access to the business data.

• View The view is responsible for the presentation o f the data in the browser or other client.

• Contro l ler The controller lies between the view and the model. It is responsible for for-matting the model data for display in the view, processing the user entries made by the user, and returning them to the model; exactly as the name wou ld suggest, it controls things.

Key Concepts Refresher Chapter 15 475

A Web Dynpro component is a reusable ent i ty. The creation o f a Web Dynpro

component is always mandatory, because the existence o f the fo l l ow ing is l inked

to the existence o f the component itself:

• Web Dynpro w i n d o w

• Views

• Control lers

The component interfaces are implemented to provide communicat ion between

the elements o f two Web Dynpro components and their call by a user. Their

close relat ionship w i t h each other means it does not make sense to consider the

ind iv idua l parts o f the component separately.

A Web Dynpro component can be thought o f as the container for all o f the things

y o u need to create. It is s imi lar to a module pool being the container for screens

and code for a dialog transaction. Figure 16.1 shows an example o f a Web Dyn-

pro component .

Figure 16.1 Web Dynpro Component

A v iew represents a rectangular por t ion o f a page displayed by the cl ient. Like a normal dynpro , it contains UI elements such as input fields and buttons (see Fig-ure 16.2). The posi t ion ing o f these elements is contro l led by a proper ty called the layout (see Figure 16.3). A single web page can be composed o f a single v iew or mul t ip le views. A w i n d o w (see Figure 16.4) defines the combinat ion o f v iews

490 Chapter 16 User Interfaces (Web Dynpro)

a n d the naviga t ion b e t w e e n these v iews . A w i n d o w can con ta in an arb i t ra ry n u m b e r of v iews, a n d a v i e w can be e m b e d d e d in an a rb i t r a ry n u m b e r of win-d o w s . A W e b D y n p r o appl ica t ion mus t have at least o n e v i e w and at least o n e w i n d o w .

W e b D y n p r o con t ro l l e r s con ta in t he W e b D y n p r o sou rce code . T h e hierarchical

s to rage for the global data area of con t ro l l e r s is called the context.

A W e b D y n p r o c o m p o n e n t has a l i fe t ime that beg ins the first t i m e it is called at

r u n t i m e and e n d s wi th t he W e b D y n p r o appl ica t ion tha t called a n d ins tan t ia ted

t he c o m p o n e n t e n d s .

W-oundPlus* OoaounO Plugs Contert *t>

fietii

CtY Z_ruO»fljOATA_vtWOCou»y: Z_fUO»fl_OATA_V*WO

Cty Z.ruCMT.ftATA.VtWOCttrtrr IJUOKTJPATA.VtWp

Pen* Mint Artne

ZJUSMTJ5ATA.VtWa»MTJJSTA«jeD Z_FUOHT_PATA_V Z JUXT_PAtA_VT>Vnj3HT JJST A*1_»CC Z_fU3HT_PATA_V Z_ftl5HT_ClATA_V*WfU5HT_USTAI?lJ«> JJ\>SHT_C>ATA_V 1 _fUXT_DATA_VtWnjXT_UST AF1MX> ZJUOHTJJATA.V ZJU5HT_0A»A_V*WR»5MT_lJS!Am*O Z.ruSHtJJAtA.V

ROW I M S

Figure 16.2 View Layout

Piop^fy _jv.** [:«i<kir) P r e s e n t s a r j n s B r e r ' K o r o i e o 10 ROOTUIELEM£NTCONTAJN£R Layout riwitsyout 3 »<C9ST<tii OeSCnp60fl MfaultBuRonia 3 enables htight isL*»r>ueCont*ner PI wronngKode non* 3 tooap

Visible 3 WKffl

L«put f fKmt .wwa wrapping

Figure 16.3 RootUIEIementContainer Properties

Key Concepts Refresher Chapter 15 477

Window Z_fCRRTJMft Actve inbound Plufls Outbound Plugs ,

Wlndow-StruWi* JO»TCNP6OO

™ • i_FUGHT_DATA_VlEW Flight d»M output New search No lights found

V BACK_FROM_NO_FUOHTS 9 NO_FUOHTS_FOUNO

y NO.FUGMTSJN

" • Z_NO_FUOKT_DATA No light data found No tights found Back :o flight data

V NO.FUOHTSJN ~ © GOTO_FUGHT_DATA

.. BACK_FROM_NO_FUGHTS V DEFAULT

Figure 16.4 Window Structure

In a d d i t i o n to the v is ib le part ( the layout) , a v i e w also contains:

• A con t ro l l e r

• A contex t

The con t ro l l e r is the act ive par t o f the v i e w and is w h e r e the code re la t ing to the

v i e w is s tored. I t de te rmines h o w the user interacts w i t h the W e b D y n p r o . The

data used i n the v i e w is f o u n d i n the v i e w contex t .

Nav iga t ion be tween d i f fe ren t v iews is enabled by plugs. Plugs are y o u r en t r y and

exi t po in ts fo r v iews and are d i v i ded in to :

• I n b o u n d plugs (en t ry po in t )

• O u t b o u n d plugs (exit po in t )

The o u t b o u n d plugs o f a v i e w can be used to navigate to a subsequent v iew .

Plugs are part o f a v iew 's con t ro l le r . They are assigned to exact ly one v i e w .

There are n o r m a l l y several v iews embedded i n a W e b D y n p r o w i n d o w . I t is

there fo re necessary to speci fy one v i e w as the v i e w that is d isp layed first w h e n

a w i n d o w is cal led. This v i e w is assigned the Defaul t p rope r t y .

The first view you create is assigned this property automatically, but you can change it i f you later decide that the starting point should be a different view.

Note

Enter ing a v i e w us ing an i n b o u n d p lug always causes an event to be t r iggered.

As a resul t , an event hand le r m e t h o d (whose use is op t iona l ) is au tomat ica l ly gen-

478 Chapter 16 User Interfaces (Web Dynpro)

crated for every inbound plug. This al lows the inbound plug i tsel f to process the

event to be handled.

To navigate f rom one v iew to another, y o u establish a navigat ion l ink f rom each ou tbound plug o f the first v iew to an inbound plug o f the subsequent v iew. These navigation l inks are maintained in the w i n d o w . On ly one navigat ion l ink can or iginate f r om one ou tbound plug. In contrast, an i nbound plug can be con-tro l led by several ou tbound plugs.

A w i n d o w is used to combine several views. A v iew can on ly be displayed i f i t has been embedded in a w i n d o w . A w i n d o w always contains one or more views. These views are connected by navigation l inks as described above. One o f these views is specified as the start v iew (default) and is displayed the first t ime the w i n d o w is called. Each w i n d o w has a uniquely assigned interface v iew (this is generated automatical ly by the system whe ever y o u create a w indow) . This interface v iew represents the ou tward v iew o f the w i n d o w and is l inked w i t h a Web Dynpro appl icat ion so that the w i n d o w can be called using a URL. Each interface v iew is associated w i t h one w i n d o w , and each w i n d o w is associated w i t h one interface v iew.

A w i n d o w has one or several inbound or ou tbound plugs. Through the use o f

these plugs, y o u can include a w i n d o w in a navigat ion chain. Each w i n d o w plug

is visible w i t h i n the ent i re w i n d o w , and it can be used for navigating w i t h i n this

w i n d o w .

Note

If you add an existing plug of a window to the component interface, it becomes part of the interface view belonging to this window. This also makes them visible beyond the limits of the component. These interface plugs are required when-ever:

• You embed a component window in the window of another component

• You set a Web Dynpro application so that it can be called

• You exit a Web Dynpro application

Controllers

Control lers determine how the user can interact w i t h the appl icat ion. A Web Dynpro appl icat ion can contain d i f ferent instances o f control lers and contexts.

Key Concepts Refresher Chapter 15 493

In addit ion to v iew controllers, which control the behavior o f an individual view, there arc also global controllers that provide more general services for all views o f a component (see Figure 16.1 for the relationship o f the controllers).

At least one global controller is contained in each Web Dynpro component that is visible f rom w i th in the component for all other controllers: the component controller. The l i fetime for this component controller extends f rom creating data wi th in the controller to cover the whole period during which the component is in use. You can add additional global controllers in the form o f custom control-lers. Their lifetimes are as long as any v iew o f the component exists.

Each view has exactly one view controller and exactly one view context. This view controller processes the actions performed by the user in the view. The view context contains the data required for the view. The life o f a view controller and its corresponding context is at least as long as the view is visible in the browser. I f you replace a view w i th a successive view, the local data (context) is also no longer available.

Each Web Dynpro component contains exactly one interface controller, which is a global controller that is also visible outside the component. This makes it part o f the interface o f a Web Dynpro component. Communication f rom one control-ler to another occurs by calling methods f rom a different controller or by trigger-ing an event that other controllers have registered. You define these controller uses when y o u create a controller.

A l l controller contexts consist o f a hierarchal list o f nodes and attributes. A con-text always has a parent, known as a context root node. The context nodes are arranged in a hierarchy and can have attributes or other nodes as children. An attribute is not permitted to have children. Al l the child entries for a node are known as an element. You can think o f a collection o f elements in the same way that a table is a collection o f rows.

There are five types o f controllers in a Web Dynpro ABAP component. The dif-ferent controller types dif fer in the entities o f which they are composed:

• Component cont ro l ler A Web Dynpro component has only one component controller. This is a glo-bal controller and is therefore visible to all other controllers. The functional-i ty o f the entire component is driven by the component controller. There is no visual interface for this controller.

494 Chapter 16 User Interfaces (Web Dynpro)

• Cus tom con t ro l l e r

Custom control lers are opt ional . They can be used to encapsulate subfunc-

tions o f the component contro l ler .

• Con f i gu ra t i on con t r o l l e r

This is a special custom control ler . You on ly need it i f the corresponding com-

ponent implements special conf igurat ion and personalization funct ional i ty .

• V iew con t ro l l e r

There is exactly one v iew control ler for each v iew (which consists o f the lay-

out part and the v iew control ler) . This contro l ler processes view-specif ic f l ow

logic, for example, checking user input and handl ing user actions.

• Window controller There is exactly one w i n d o w control ler for each w i n d o w . This control ler can

be used to process the data passed via the i nbound plugs w h e n it is reused as

a ch i ld control ler . The inbound plug methods o f the w i n d o w can call methods

o f this control ler .

A l l contro l ler instances are singletons in respect to their parent component (each component has exactly one control ler) . Each contro l ler has its o w n context w i t h an exist ing context root node. You must def ine all other nodes and attr ibutes.

For all control lers, methods exist that are called by the Web Dynpro f ramework in a predef ined order. These are called hook methods. Di f ferent hook methods are available depending on the contro l ler type. A l l contro l ler types contain at least t w o hook methods. These methods are processed on ly once dur ing the l i fe t ime o f a contro l ler instance: when a contro l ler instance is created ( w d d o i n i t ) and when a control ler instance is deleted ( w d d o e x i t ) . w d d o i n i t can be used to create instances or t r igger ing author izat ion checks, where w d d o e x i t can be used to release record locks.

There are t w o predef ined control ler attr ibutes: they are used to access the func-t ional i ty o f the contro l ler ( w d _ t h i s ) and the context ( w d _ c o n t e x t ) . w d _ t h i s is a self-reference (it is not the same as ME, wh ich is used in ABAP self-reference) to the current control ler 's interface ( I F _ < c o n t r o l l e r _ n a m e > ) . It represents all func-t ional i ty implemented in the generated class. w d _ c o n t e x t is a self-reference to the control ler 's context root node.

To share in fo rmat ion between di f ferent control lers, one control ler must declare the use o f another control ler . You do this on the PROPERTIES tab o f the contro l ler that needs to access another contro l ler . You most f requent ly have a requirement

Key Concepts Refresher Chapter 15 495

for this k i nd o f data sharing when y o u want to crcatc a mapped context node or

access another control ler 's user-defined methods.

Contexts

When a node is created in the context o f a Web Dynpro component , y o u specify the cardinal i ty o f the node. The cardinal i ty defines how of ten a node w i l l be instantiated at runt ime, in other words, h o w many elements o f this node are available at runt ime. Table 16.1 shows the possible cardinali t ies o f a Web Dyn-pro component .

Cardinality Description

1 . . . 1 Only one element can be instantiated.

0 . . . 1 No more than one element can be instantiated, but it is also possible that no element is instantiated.

1... n At least one element must be instantiated.

0... n Zero or more instances of the context node can be instantiated.

Table 16.1 Cardinality of a Web Dynpro Component

W i t h i n the Web Dynpro architecture, it is possible to l ink the contexts o f the dif-ferent control lers in d i f ferent ways:

• You can l ink a UI element o f the user interface o f the v iew w i t h an element o f the v iew context. This is k n o w n as data binding.

• You can define a mapping between two global control ler contexts or f r om a v iew context to a global control ler context. This is k n o w n as context mapping, and on ly a reference to the data is made.

Events

The component control ler al lows y o u to create events that are used to provide communicat ion between control lers. This communicat ion al lows one contro l ler to trigger event handlers in d i f ferent control lers. Interface control ler 's events a l low cross-component communicat ion to be implemented. Component control-ler events are on ly visible w i t h i n the component .

482 Chapter 16 User Interfaces (Web Dynpro)

Some UI elements, for example, the But ton element, can react to a user's interac-

t ion. These events are predefined, and y o u have to l ink them w i t h an action at de-

sign t ime (see Figure 16.5). I f such an action is created, an event handler method

is automatically created for this action. You can equip a UI element event (which

may have been inserted several t imes in to a v iew) w i t h di f ferent actions. The

event handler l inked to that action w i l l then process the event (see Listing 16.1).

Piotx«ty |VdftM

Properties teuton) [ID ACTION.BUTTON

des ign standard 3

W t M M • x p U n t t o n

image f i r s t

imageSowce

text Oo"

texttwecoon innertt 0 tooltip

Mt ib le v is ib le TJ wiarn

Event*

onAtOon 0 0 T 0 OVT 01 5 [Layout Data (riowOata)

Figure 16.5 Button Properties and Event

METHOO onact fongoto_out_01 . wd_thi s -> f i re_out_01_p1g( ) .

ENDMETHOD.

Listing 16.1 Event Handler

Each component has an interface to enable communicat ion between Web Dyn-pro components and to enable a component to be called by a user. The interface consists o f two parts:

• Interface v iew

• Interface contro l ler

Web Dynpro Application

A Web Dynpro appl icat ion is an entry po int in to a Web Dynpro component and

is the on ly Web Dynpro ent i ty that can be addressed by a URL. A module pool

again provides a good comparison. A module pool must be started w i t h a trans-

Key Concepts Refresher Chapter 15 497

action code, and the Web Dynpro application provides the same starting point for Web Dynpro. The Web Dynpro application is a l ink to an interface v iew o f Web Dynpro through the use o f an inbound plug declared as a startup plug that has a default starting view. It contains no information about the elements o f the corresponding component or components behind the interface view. You must specify the fo l lowing to define a Web Dynpro application:

• The component to be called: this component is known as the root component.

• The interface view o f the root component w i l l be init ial ly used; the default v iew in this interface defines the default v iew assembly (the subset o f visible views).

• The inbound plug acts as the entry point for the interface view (the type o f this inbound plug must be Star tup) . I f y o u create a Web Dynpro application for a component that has only one w indow (and therefore only one interface view), then the starting point w i l l be determined automatically.

Graphical Elements

A UI element is any graphical entity ( input field, button, textview, etc.) that occu-pies a position w i th in a view layout. Each UI element is part o f the hierarchal list (see Figure 16.6 for an example). This docs not mean that all UI elements arc vis-ible on the screen. Some UI elements arc never visible on the screen, such as the TransparentContalner or the V1ewUIElementConta1ner. These elements struc-ture the UI wi thout being visible, but like the visible UI elements, they occupy a position in the UI element hierarchy. At runtime, all UI elements can be set to invisible wi thout freeing the space they occupy as UI elements.

Numerous UI elements are available for designing the appearance o f a Web Dyn-pro application. The UI elements are divided into categories (see the list below). These categories are displayed in the view designer when the layout preview is visible. You can drag and drop them into the layout, or alternatively, you can use the context menu o f the ROOTUI ELEMENT to create UI elements for your view lay-out. You should also be aware that the categories have changed through various support packages o f SAP NetWeaver 7.0, but these changes w i l l not be part o f the examination. Also, placement o f a UI element is only possible w i th in the lay-out property. This means that unlike a classic dynpro, it is not possible to move a UI element to a specific point in the view, but it is automatically placed based on the layout property and the preceding UI elements.

484 Chapter 16 User Interfaces (Web Dynpro)

• ROOTUIEIEMENTCONTAINER D GROUP

T CAPTION |H«aa«i) t CnV_LABEL Qcnv T COUNTR.LABEL

C 5 C 0 U N T R O GROUP. 1

T CAPTIONJ |H»*der] T CnV_L* f iEL .1

G 5 C I T Y J T CO fJNTR_LAflEL_1

C O U N T R J - BUTTON

" • TABLE

t> • TA8LE_AJRUNEID (COiumnS) t> • TABLE.AIRUNE Eoluf f l iv* ]

Figure 16.6 RootUIEIementContainer Hierarchy

Some o f the UI element categories are as fo l lows:

• The standard simple categoiy contains elements that are used f requent ly in

Web Dynpro applications. Examples are B u t t o n , L a b e l , and I n p u t F i e l d .

• The standard complex category contains elements that need to have chi ld ele-

ments to def ine a val id UI element that can be rendered. A n example is a

T a b l e , wh ich needs to have a ch i ld element o f T a b l e C o l u m n fo r each co lumn

to be displayed.

• The standard container categoiy contains elements that can have chi ld ele-

ments. Container UI elements can structure the layout either visibly or invisibly.

Other categories contain elements to display ActiveX-based diagrams (Active Component) , SAP Interactive Forms by Adobe (Adobe), or business graphics ren-dered by the Internet Graphics Server (BusinessGraphics) or to embed off ice doc-uments such as Microsof t W o r d or Excel documents (Off icelntegrat ion) and some other special UI elements.

A l l v i ew layouts are der ived f r om a hierarchy o f UI elements. The root node is always o f type T r a n s p a r e n t C o n t a i n e r (a non-visible container), and is always called R o o t U I E I e m e n t C o n t a i n e r . You cannot change this. A l l UI elements added to a v iew layout are hierarchical ly subordinate to the root node R o o t U I E l e m e n t C o n t a i n e r .

Container elements, as ment ioned above, are UI elements that can have chi ld ele-

ments. In the v iew's layout they occupy a rectangular area. A l l ch i ld UI elements

o f a container element are located w i t h i n this rectangular area. A l l container ele-

Key Concepts Refresher Chapter 15 499

ments also def ine h o w their ch i ldren w i l l be arranged using the Layout proper ty

that assigns a layout manager to the UI element. A l l o f the chi ld elements o f a UI

element container inher i t a set o f propert ies that relate to the value o f the con-

tainer's Layout proper ty section Layout Data. The Layout proper ty can have one

o f four values: FlowLayout, RowLayout, MatMxLayout , or Gr ldLayout .

• FlowLayout

The default layout manager is the FlowLayout layout manager. This layout displays all ch i ld attr ibutes o f this container in a row. I f the container UI ele-ment is too nar row for all ch i ld elements to be displayed in one row. they w i l l wrap automatical ly to the next lines. You cannot force the wrapp ing at design t ime. UI elements in d i f ferent lines are not related to each other and are not al igned in columns. You use this k ind o f container to arrange subcontainers. A n example o f FlowLayout can be seen in Figure 16.7.

Art* FLCW_LAYC<JT /UGMT <Q fyft Hjnt*> legist* narwType ra

Figure 16.7 FlowLayout

• RowLayout

I f the RowLayout layout manager is used w i t h the container UI element. A l l ch i ldren inher i t the proper ty LayoutData, wh ich can have the values RowOata and RowHeadOata. I f y o u set this proper ly to RowHeadData, a break is forced, and this and subsequent elements appear in the next row. I f y o u set the prop-erty to RowOata, this ch i ld element w i l l appear in the same l ine as the previ-ous element, even i f the r ight-hand margin is reached. UI elements located in d i f ferent rows are not related to each other and are not al igned in columns. You can set the w i d t h o f each cell by using the w i d t h at t r ibute o f each chi ld element. A n example o f RowLayout can be seen in Figure 16.8.

R o w t .»y out

Art* RCV/.LAYOUT RtOHT OQ FtgM >*jrt«» ArtonixrgltM Plane Type B

Figure 16.8 RowLayout (with RowHeadData set on Flight Number and Plane Type)

500 Chapter 16 User Interfaces (Web Dynpro)

• Ma t r i xLayou t

I f the Ma t r i xLayou t layout manager is used w i t h the container UI element,

all ch i ldren inher i t the proper ty LayoutData, wh ich can have values Max t r i x -

Data and Matr ixHeadData. I f y o u set this proper ty to Matr ixHeadOata, a l ine

break is forced. I f y o u set the proper ty to Mat r i xOata , the chi ld elements w i l l

appear in the same l ine as the previous element, even i f the r ight-hand margin

is reached. The chi ld elements in this container are arranged in columns.

W h e n y o u use this layout manager, there is not a static number o f columns,

but the number o f columns is def ined by the max imum number o f ch i ld ele-

ments in any row. You do not have to have the same number o f elements in

d i f ferent rows. It is possible to span mul t ip le cells w i t h a UI element arranged

i n a Ma t r i xLayou t by using the c o l S p a n ( p r o p e r t y ) . A n example o f M a t r i x -

Layout can be seen in Figure 16.9.

M a t r i x L a y o u t

L o b d l fcwirax J > Y O U T F t L D S L « W 2 MATrax_LAYOUTmt>S l a M 3 WATRW_L»

L « M 4 MATRK_LAYOUTFB.OS I M S MATRIX _LA Y(XIT FELOS l « M 6 MATRDCJ>

Figure 16.9 MatrixLayout

• Gr idLayout

Like the Ma t r i xLayou t . the Gr idLayout layout manager can be used i f y o u want a vertical a l ignment o f the elements. Here the number o f columns is static and is def ined w i t h the co l Count proper ty o f the container element. A single ch i ld element does not therefore contro l whether it is the first element o f a new row. A break w i l l take place once all cells o f a row are occupied. I f an element or elements are removed, the arrangement fo l l ow ing this po in t w i l l shi f t " le f t " to fill the now empty cells.

The best way to use the Gr idLayout layout manager is i f all rows occupy the

same number o f columns and on ly complete rows are ei ther inserted or

deleted. Instead o f remov ing UI elements completely, y o u can replace them

w i t h an I n v i s i b l e E l e m e n t to retain the or ig inal element arrangement. A n

example o f Gr idLayout can be seen in Figure 16.10.

You edi t a v iew layout w i t h the V iew Editor, wh ich is a Web Dynpro-specif ic

tool. The V iew Editor is on ly available for y o u to use when y o u are edi t ing a v iew

control ler . A custom contro l ler w i l l not show the V iew Editor because these con-

trol lers have no visual interface.

Key C o n c e p t s Ref resher C h a p t e r 15 487

Grid Loyout

LtMl 0«O_UkY0<JT FtlOS Al«b« 2 «?©_LAYOUT FROS A3

Label 3 Cf®_LAYOOTFCLDSAl«W4 <W_LAYOUT FB.DS Ai

LabelS C*®_LAY0UTF6LDSAl«t*l6 CtO_LAYOOT FSLDS A£

Figure 16.10 G r i d L a y o u t ( w i t h c o l C o u n t o f 4)

The PROPERTIES area displays all properties of a selected UI element (see Figure 16.5, above, for an example). The supported client-side events are listed in the EVENTS properties section if a UI element supports events. Properties related to client-side events begin with the prefix on (for example, onFl l t e r , onSort. or onAction). You must associate actions with each of these events.

Once you have bound a UI element property to a context node or attribute, the UI element property is supplied with a value from the context data. If the user can update the UI element property, the context is automatically updated with the new value during the next round trip. An example of binding is shown in Figure 16.11.

Piopeity V.*ie BlIKlUM)

Pmwt t oppuF-ew I0 INPUT_FlELD alignment auto •

enabled 0 explanation length 20 passwordField • readonly • state Normal Item texlDirection inherit 3

tooltip value STARTV1EW VIEW.OI MY_NAME & visible Visible -

width Events onEnter - Q J UYOUI Data (FlewData) cenoesign padiess vOutter none

Figure 16.11 B i n d i n g Example

502 Chapter 16 User Interfaces (Web Dynpro)

Note

You can only have a binding relationship between the context and UI elements of the same view controller. For this reason, any data that you want to bind to the view UI elements must be stored in the context, as opposed to the attributes of the controller.

It is usually possible for y o u to have fu l l contro l over the appearance o f the screen layout through the use o f the Web Dynpro v iew contro l ler w i t hou t ever needing direct access to the UI element objects. You b ind any proper ty over wh ich y o u want to have programmatic contro l to an appropr iate context node or attr ibute. Then y o u manipulate the context nodes or attr ibutes to wh ich the UI elements are bound to contro l the behavior o f the UI elements.

To display data for a UI element, y o u must b ind its value proper ty to an appro-

priate context node or attr ibute. At a m i n i m u m y o u must do the fo l l ow ing to dis-

play data in the v iew:

1. Create a node or at t r ibute in the v iew control ler 's context to contain the data.

It is not impor tan t whether this is a mapped context node or not.

2. Create the UI element in y o u r v i ew layout.

3. Properties requi r ing a context b ind ing show a but ton w i t h a ye l l ow icon and an empty circle to the r ight o f the property . You assign the required b ind ing by cl icking on this but ton. The v iew control ler 's context is displayed in a dia-log box. A l l nodes or attr ibutes o f the appropriate type to be bound to the UI element proper ty are displayed. You then select an appropr iate node or attr ibute.

Af ter y o u complete these steps, the context path to the node o r at t r ibute w i l l be displayed as the property 's value. The empty circle but ton w i l l be replaced w i t h a green check mark icon (see Figure 16.11). The context path o f the node or at t r ibute to wh ich it is bound w i l l also be displayed on the layout prev iew for the UI element.

When y o u establish a b ind ing relat ionship, this instructs the Web Dynpro screen to obtain the value for a UI element proper ty f rom the context node or at tr ibute to wh ich it is bound. You are not l im i ted w i t h context b ind ing to jus t supply ing an I n p u t F i e l d w i t h a value. The value proper ty o f a UI element is j us t one o f the propert ies that can be suppl ied w i t h data w i t h a b ind ing relat ionship. The bind-ing between a UI element and a context at t r ibute is a two-way relat ionship:

Important Terminology Chapter 15 503

• Data is transported f r om a context to the cl ient dur ing screen render ing.

• Data entered by the user is transported back to the context when the HTTP re turn t r ip is processed. This is a s imi lar concept to that used by a dynpro 's input fields.

Af ter y o u declare a b ind ing relat ionship, the data in the bound nodes and attr ibutes is transported automatical ly to the corresponding UI elements. Af ter the user has interacted w i t h the screen and in i t iated an HTTP round t r ip , the new or mod i f ied data in the UI elements is transported back to the same nodes and attr ibutes in the v iew control ler 's context. Before the Web Dynpro f ramework turns contro l over to the act ion handler, the context already contains the updated in format ion .

N o t e

There is nothing you need to do for this process. The two-way transport process is entirely automatic. You only need to declare a binding relationship.

M a n y U I elements ( T e x t V i e w s , L a b e l s , C a p t i o n s , and so on) display texts when rendered. You can obtain these texts f r om the ABAP Dic t iona iy in two ways:

• You b ind the proper ty related to the text to a context at tr ibute. This context at t r ibute is typed w i t h a data element def ined in the ABAP Dict ionary.

• The U I element is related to a second UI element, wh ich is bound to a context

element that is typed w i t h a data element. In this case, the proper ty related

to the text must be left blank in order to use the d ic t ionary text.

N o t e

A Label is related to an InputFleld. and the Text property of the Label is left blank. The label text then originates from the data element related to the Input-Field.

I m p o r t a n t Termino logy

You should be able to ident i fy what makes up a Web Dynpro application. You should k n o w the parts o f a Web Dynpro component. In addi t ion, y o u w i l l need to understand the purpose o f each part and how they exchange in format ion or events

504 Chapter 16 User Interfaces (Web Dynpro)

w i t h o ther parts o f the same o r another W e b D y n p r o componen t . You shou ld

k n o w the types o f contro l lers, the purpose o f each, and the n u m b e r possible.

Table 16.2 shows the terms used w i t h W e b Dynpros .

Term Meaning

Web Dynpro Containers for other entities related to the UI and the Web components Dynpro.

View The layout of a view represents a rectangular part of a page displayed by the client. The view contains UI elements such as input fields and buttons.

Window An entity related to the UI; it is the possible combination of

views and f low between the views.

Web Dynpro Where the Web Dynpro source code is located. controller

Context The hierarchical storage area for the global data of control-lers.

Plugs Provide navigation. Outbound plugs connect to the inbound plug or starting point for a view. Plugs are part of the con-troller of a view. They are always assigned to one view.

Interface view Each window has a uniquely assigned interface view. The interface view is linked wi th a Web Dynpro application so that the window can be called using a URL.

View controller Processes the actions performed by the user in the view. Each view only has exactly one view controller.

Interface controller A global controller that is also visible outside the compo-

nent. It is thus part of the interface of a Web Dynpro compo-nent.

Component controller Allows you to create events. Events are used to communi-cate between controllers and enable one controller to trigger event handlers in a different controller. Only one exists per component and has no visual interface. It drives the func-tionality of the component.

Table 16.2 Definitions for Web Dynpro

Practice Questions Chapter 16 505

Term Meaning

Custom controller These are optional. Can be used to encapsulate subfunctions of the component controller.

Configuration Only one configuration controller can exist in any compo-controller nent. It is only necessary if the corresponding component

implements special configuration and personalization func-tionality.

Window controller Only one per window. Can be used to process the data passed via the inbound plug when reused as a child control-ler.

Consumer component A component that uses functionality (consumes) in another component (the used component).

Used component A component that has functionality used by another compo-nent (the consumer component).

Table 16.2 Definitions for Web Dynpro (cont.)

% Practice Quest ions

The practice questions be low w i l l help y o u evaluate y o u r understanding o f the topic. The questions shown are similar in nature to those found on the certifica-t ion examinat ion, but whereas none o f these questions w i l l be found on the exam itself, they a l low y o u to review y o u r knowledge o f the subject. Select the correct answers and then check the completeness o f y o u r answers in the fo l low-ing solut ion section. Remember that y o u must select all correct answers and on ly correct answers to receive credit for the question.

1. Each component has an interface. This interface consists of:

• A. Interface v iew

• B. Interface context

• C. Interface contro l ler

492 Chapter 16 User Interfaces (Web Dynpro)

2. A plug:

• A. Can be defined as inbound, outbound, or both

• B. Forms the basis o f navigation w i th in a Web Dynpro

• C. Can be defined as default inbound

• D. Can be defined as a startup

• E. Can be defined as an exit

• F. Can be assigned to mult iple views

• G. Can be defined as outbound control l ing mult iple inbound plugs

• H. Can be defined as inbound and be controlled by mult iple outbound plugs

3. A Web Dynpro component contains:

• A. Mul t ip le views w i th in a w indow

• B. UI elements

• C. Component controller

• D. A context

• E. Exactly one interface controller

4. A v iew can:

• A. Contain other views

• B. Be contained in a w indow

• C. Contain windows

• D. I f entered by an inbound plug cause an event handler method to be called

• E. Contain a view controller

5. Identify the types o f controller:

• A. Component controller

• B. Custom controller

• C. Consumer controller

• D. Configuration controller

• E. View controller

• F. W indow controller

Practice Question Answers and Explanations Chapter 14 507

6. Ident i fy the types o f layout managers:

• A. FlowLayout

• B. RowLayout

• C.ColumnLayout

• D. Ma t r i xLayou t

• E. Gr idLayout

• F. TreeLayout

7. The b ind ing between a UI element and a context at t r ibute is a two-way rela-t ionship.

• A. True

• B. False

8. Ident i fy the ways to map context structures:

• A. Direct context mapping

• B. External context mapping

• C. Dynamic context mapping

9. The Web Dynpro programming model is based on:

• A. Classic Dynpro programming

• B. Business Server Pages (BSP)

• C. M o d e l V iew Contro l ler (MVC)

• D. Internet Transaction Server (ITS)

Pract ice Ques t ion Answers and Explanat ions

1. Correct answers: A, C

Each interface component is composed o f two parts: the interface v iew and

interface control ler .

2. Correct answers: B, D, E, H

A plug is ei ther i nbound or ou tbound; it cannot be both. The v iew is def ined

as a default, but the plug is def ined as a startup. Each plug can on ly be

494 Chapter 16 User Interfaces (Web Dynpro)

assigned to one v iew. Each ou tbound plug can on ly navigate to a single

inbound plug. However, an inbound plug can be triggered by mul t ip le out-

bound plugs.

3. Correct answers: A, C, E

UI elements are placed w i t h i n a v iew o f the component . A l though there is a

context, i t is actually part o f ei ther the component contro l ler or a v iew con-

trol ler. Therefore, the context is not direct ly part o f the component , but o f a

subcomponent.

4. Correct answers: B, C, D. E

A v iew can contain a w i n d o w , wh ich can contain another v iew, but a v iew can not be placed in to another v iew.

5. Correct answers: A, B, D, E. F

There is no consumer control ler .

6. Correct answers: A, B, D, E

C o l u m n L a y o u t and T r e e L a y o u t are not va l id layout managers.

7. Correct answer: A

It is a two-way relat ionship, wh ich is h o w data can be displayed in the

browser and be retr ieved f r om user input .

8. Correct answers: A, B

Direct context mapping and external context mapping are the on ly ways to map context structures.

9. Correct answer: C

The Web Dynpro programming model is based on the M o d e l V iew Control ler

paradigm to ensure a clear d iv is ion between the de f in i t ion o f the user inter-

face and the implementat ion o f the application logic.

Take Away

You w i l l need to understand h o w Web Dynpro functions. Remember that i t is a

paradigm shif t f r o m exist ing types o f dynpros. It is impor tan t to recognize the

M o d e l V iew Control ler paradigm and what is available in each contro l ler or

v iew. I t is impor tant to understand how plugs a l low navigat ion and the applica-

t ion to start or to exit . You w i l l need an understanding o f v iews and how they

Summary Chapter 16 509

relate to w indows and how the d i f ferent Web Dynpro components arc l inked

and exchange data. Final ly, y o u w i l l need to show y o u r knowledge o f the di f fer-

ent types o f control lers, their purposes, and their capabilit ies.

Refresher

You must understand the separation o f duties in the M o d e l V iew Control ler par-

adigm. You must understand the purpose o f each (see Table 16.3).

Key Concept Definition

Model This forms the interface to the backend system and thus enables the Web Dynpro application access to data.

View This is responsible for the representation of the data in the client.

Controller This lies between the view and the model. The controller formats the model data to be displayed in the view, processes the user en-tries made by the user, and returns them to the model.

Table 16.3 Key Concepts Refresher

Tips

It is impor tant to have as much practical experience w i t h this subject as possible. Unl ike the major i ty o f subjects found in the cert i f icat ion examinat ion, this is an area where most w i l l not have suff ic ient experience.

Whereas some o f the topics may be famil iar, for example, event handl ing, the major i ty o f the concepts presented in this chapter require a m ind shif t . It is indeed a di f ferent paradigm and introduces a number o f new terms and con-cepts. You must learn the terms and understand the concepts.

S u m m a r y

You should now understand the basics o f Web Dynpro ABAP. You should have

an understanding o f the components and how these components relate w i t h

other components. This understanding o f Web Dynpro ABAP w i l l enable y o u to

complete this por t ion o f the cert i f icat ion examinat ion successfully.

Class Identification Analysis and Design

Techniques You'll Master :

• Use functional methods

• Describe singletons

• Understand class friendship

• Identify inheritance

• Explore interfaces

498 Chapter 17 Class Identification Analysis and Design

This chaptcr expands on the material presented in Chapter 14. ABAP Object-Ori-ented Programming. The purpose of this chapter is to provide you with a basic understanding of how classes and objects can be organized, not to provide details regarding ABAP Objects. We will discuss the advantages of functional methods and the way to create a singleton class. We will cover the purpose of friendship between classes. We will also discuss inheritance including the up cast and down cast within the hierarchy of the inheritance tree. Finally, we will dis-cuss interfaces and how they can be used to simulate multiple inheritance. Each of these topics will be covered separately and will be followed by the practice exercise and the solution to the exercise.

Real-World Scenario

You have been asked to take previously developed functionality and re-design it. The application provides data based on expected inventory move-ment and is currently developed as a large single program handling all types of purchase orders and sales orders. This program was changed by several different developers over the years, each only focusing on a single part of the program.

The objective is to produce a model and eventually a series of classes that can be used to implement the process using polymorphism.

The goal is to standardize the methods and their parameters. Although some of the classes involved are not closely related to each other, in other words they are not specializations or generalizations of each other, they all share methods and parameters. To simplify the inconsistent nature of these objects, you need to standardize the naming of these components; even though these objects are not related, they do need to share the same attributes and methods.

Objectives of this Portion of the Test The purpose of this portion of the certification examination is to verily that you have sufficient knowledge to design different types of ABAP classes. This portion of the examination will test your knowledge of a narrow range of topics. The

Key Concepts Refresher Chapter 18 499

general topic is covered in Chapter 14, ABAP Object-Oriented Programming. The points that you will need to understand from this section include:

• The creation of a singleton (a class that can only be instantiated once)

• The use of functional methods and how they can simplify your programming

• Visibility of components and how different classes can interact

• Tools of the Class Builder, specifically the Rcfactoring Assistant

• Inheritance and polymorphism and how to use them correctly

• The use of interfaces to provide similar functionality to unrelated classes

The certification examination will give greater weight to this chapter compared to the other topics in the examination. This means there will be a higher percent-age of questions covering this chapter than any other chapter. The reason for this is the direction of the ABAP language. The concepts described in this chapter are critical to knowing and using ABAP effectively.

Key Concepts Refresher As development of ABAP programs leans toward object-oriented programming with ABAP Objects, you typically need to understand the advantages and restric-tions of using object-oriented programming.

Functional Methods

As a refresher, we will cover a number of points that, although they may have been mentioned in other chapters, are important for a full understanding.

In Chapter 9, Basic ABAP Programs and Interface Creation, we discussed briefly the RETURNING parameter. Methods that have a RETURNING parameter are described as functional methods. This means they cannot also have either an EXPORTING or a CHANGING parameter. In this way, we guarantee that the method passes back one thing and one thing only to the caller. The RETURNING parameter must always be passed by value. Only one RETURNING parameter can be defined for a method. An example of a simple functional method can be seen in Figure 17.1, and the use of this method can be seen in Listing 17.1.

514 Chapter 17 Class Identification Analysis and Design

Ty [Parameter [Type spec [Description

•J VALUE( AMOUNT) TYPE P Amount to round

a . VALUE(ROUNDED_AMOUNT) TYPE AMOUNTSAP Rounded amount 1 *

— | f t e t u m n q |

Method ROUND UP.

rounded amount - (CEIL amount ) ) . 4

rnibnr t hod.

Figure 17.1 Example of a Functional Method

lv_calc_amt - lv_source_amt / l v_ fac tor . IF lv_amt NE 1r_ut11->round_up( lv_calc_amt ) .

lv_amt - 1r_uti1->round_up( lv_calc_amt ) . ENDIF.

Listing 17.1 Functional Method Usage

The advantage of functional methods is that they do not require the use of tem-porary variables, because they can be used in conjunction with other statements. Prior to the introduction of functional methods, any call to any modularization unit (examples are a subroutine, a method, or a function module) always required the result to be stored in some data object. However, with functional methods they can be called directly from within various expressions, eliminating the need to temporarily store values. Functional methods can be used in:

• Logical expressions ( IF, ELSEIF, WHILE. CHECK, WAIT)

• Case conditions (CASE, WHEN)

• Arithmetic expressions and bit expressions (COMPUTE)

• Sources of values as a local copy (MOVE)

• Search clauses for internal tables, assuming that the operand is not a compo-nent of the table row (LOOP A T . . . WHERE)

Static Methods

There are two kinds of attributes, instance attributes and static attributes, which are discussed in more detail in Chapter 14, ABAP Object-Oriented Programming. A static attribute exists once for each class and is visible for all runtime instances in that class. They typically relate to all objects, not just a single object. Examples

Key Concepts Refresher Chapter 18 501

includc a countcr or global constants. Likewise, static methods arc def ined at the

class level. The restriction that on ly static components can be accessed in a static

method applies to the implementa t ion o f the method. This makes sense because

a static method can be called w i thout creating any instance o f the class. This

means that static methods do not need instances; that is, they can be accessed

directly through the class. A n example w o u l d be to retrieve the current value o f

the static counter described above.

Static methods are called using the syntax CALL METHOO c l assname->method_name

. . . or y o u can drop the CALL METHOD and put the parameters in parentheses at

the end o f the method call. Like static attributes, static methods are addressed

w i t h their class name, because they do not need instances (see Listing 17 .2 for

an example) . As w i t h instance methods, w h e n y o u are calling a static method

f rom w i t h i n the class,you can omi t the classname.

LOOP AT < tab le> ASSIGNING <wa>. MOVE-CORRESPONDING <wa> TO < s t r u c t u r e > . z c l _ u t i 1 i t y - > c r e a t e _ c s v _ f r o m _ r e c o r d (

EXPORTING separa tor - gc_comma q u o t e _ a l l _ f i e l d s - ' F ' o u t p u t _ i n i t 1 a l _ v a l u e s - ' X ' source .conten ts - < s t r u c t u r e > rcd_re f_descr - 1 r _ s t r u c t _ t y p e

IMPORTING csv_record - l s_output

EXCEPTIONS 1nval1d_structure_component - 1 unable_to_preserve_space - 2 OTHERS - 3

). ASSERT sy-subrc - 0 .

List ing 17.2 Example of a Static Me thod Call

Singletons

There are many cases in wh ich y o u need to prevent a class f rom being instanti-

ated more than once for each program context. You can do this using the single-

ton. A singleton is a class that is final (meaning it cannot have any subclasses),

has a private instantiation level (meaning only the class itself can create an

instance of itself), and is instantiated using its static constructor (which is exe-

502 C h a p t e r 17 Class Iden t i f i ca t ion Analysis and Design

cutcd only after the first time the class is accessed in an application). You can see this in Figure 17.2 and Figure 17.4. Figure 17.3 shows the static attribute used to store the singleton's reference. In this way, we ensure that only one instance of the class can be created in our application. A public static method could then make the reference to the class available to an external user as shown in Figure 17.5. The use of a singleton can be seen in Listing 17.3.

OATA: 1 v _ s 1 n g l e t o n _ r e f TYPE REF TO z c l _ s 1 n g l e t o n .

1 v _ s i n g l e t o n _ r e f - z c l _ s i n g l e t o n - > g e t _ r e f e r e n c e ( ) .

L is t ing 17.3 Instantiating and Using a Singleton

CUss interface ZCl_SIH&iETON implement

^ Superclass

Oescnpton A sir.gleton example

instantiation 0 Prrr l te * j

0 Final

Figure 17.2 Singleton Class Properties

Class Interface ZCL.SINGlETON impienj

j Properties ^ interfaces ^ F n e n d s ^ Q Methods

H l n f e J X l a l a L » i O &

Altnbute iLe^ei jvist Re [Typing [Associated Type

W.SINBLETOH Static A Pm • Type Ref TO ZCL.S1N&LET0N

Figure 17.3 Singleton Attribute

Ty | Parameter ] Type spec [ P e s t n |

Method CLASS.CONSTRUCTOR

1 ffilllOP cl«33_constcuctor.

4 CPEATE OBJECT gr_9inglcton.

4 KHPNETHOD

Figure 17.4 Singleton Class Constructor

Key Concepts Refresher Chapter 18 17

Ty |parametw | Type spec | Description a. VALU€<REFERENCE) TVPE REF TOZCL_SINOL£TON A singleton

Method $Er_ft£F£fiEHCE E j<ETHOP gut reference.

reference - gr_9ingleton.

FHDMETHOD

Figure 17-5 Returning the Singleton Reference

Friendship

In classes, normally there is a strict division between what can be accessed out-side the class itself ( P U B L I C ) and the inheritance tree (PROTECTEO) or just the class itself ( P R I V A T E ) . From outside the class you can only access the public compo-nents of a class. In rare cases, classes have to work together so closely that they need access to each others' protected or private components. This can be achieved if one class grants friendship to another.

The concept of friendship between classes prevents these components from being made available to all applications, but the friend can access the protected and private components directly. A class can grant friendship to other classes and interfaces (and through the interface to all classes that implement the interface). The primary reason for friendship is performance; i f a class can access the private attributes of another class directly, rather than having to call a public method to get hold of that data, then it will be faster because there is less overhead to obtain the data.

Note

You use the f r i e n d s addition of the c l a s s statement or the Fr iends tab in the Class Builder to grant friendship.

Granting friendship is one-sided; a class that grants friendship is not automati-cally a friend of its friends. I f the class that grants friendship wants to access non-public components of the friend, this friend must reciprocate and explicitly grant friendship back to the original class.

Typically, the friend relationship between classes occurs when methods that access the same data are distributed over several classes. The common data

504 C h a p t e r 1 7 Class I d e n t i f i c a t i o n Ana lys i s a n d Des ign

should not be accessed by classes that are not part of this relationship. In these cases you can make the class containing the data a singleton, which ensures that it can only be instantiated once in each program instance.

You should be aware that the friend attribute is inherited: Classes that inherit from friends and interfaces containing a friend (as a component interface) also become friends. You should therefore use extreme caution when granting friend-ship. The further up in the inheritance tree you make a friend, the more sub-classes can access all components of a class that granted friendship. However, granting friendship is not inherited. A friend of a superclass is not automatically a friend of its subclasses.

Inheritance

Specialization is a relationship in which one class (the subclass) inherits all of the components of another class (the superclass). It is possible for the subclass to add new components (attributes, methods, etc.) and replace the implementations o f inherited methods. This specialization emphasizes the similarities of the classes. The components they have in common are only defined and implemented in the superclass. They are inherited by all of the subclasses. You often will describe specialization as an "is a" relationship. For example, "A bus is a (specific type of) vehicle" or "A purchase order is a (specific type of) document." Reversing the point of view of specialization is referred to as generalization. Therefore:

• Common components are extracted and defined once in the superclass, allowing for central maintenance and eliminating redundant implementa-tion.

• Subclasses contain extensions (in other words, new components that are unique to the subclass) and/or changes (implementing different versions o f methods that were inherited).

• Subclasses are dependent on superclasses.

I f you use inheritance properly, it provides a significantly belter structure for your software because commonly used elements are only defined once in a cen-tral location (in the superclass) and then are automatically available to all sub-classes. I f you make changes later, they have an immediate effect on the subclasses. You therefore need to be careful i f you make changes to the super-class, because they will directly affect the subclasses inheriting from it and when using the Refactoring Assistant.

Key Concepts Refresher Chapter 18 505

Tip

A very common mistake made by those new to object-oriented design is an

overuse of inheritance. This problem can be avoided by using the test:

X should inherit from Y only ifyou can say that X is a Y.

So whereas a checkbox is a type of button, you cannot say for example that a col-

umn is a table. This is why the object model of the ALV is not a group of inher-

ited objects.

In object-oriented ABAP. you define an inheritance relationship for a subclass using the INHERITING FROM addition, followed by the superclass that is directly above the subclass. To do the same for a global class you click on the SUPERCLASS button on the class's PROPERTIES tab (shown in Figure 17.2). Because this super-class can inherit from another superclass above it, inheritance hierarchies of vaiying complexity can be produced, known as inheritance trees.

Unlike other languages, there is no multiple inheritance in ABAP Objects. You can only specify one superclass directly above a class. However, you can use interfaces in ABAP Objects to simulate multiple inheritance. Inheritance is a one-sided relationship. In other words, subclasses know their direct superclass, but a class does not know which class inherits from it.

Redefinit ion

Redefinition allows you to change the implementation of an inherited instance method in a subclass without changing the signature, in other words, without changing the parameters or adding new ones. The visibility section for the super-class must also remain the same. It is therefore not possible to use redefinition within the PRIVATE SECTION. When you use the REDEFINITION addition, you specify a new implementation for the inherited method. Because the signature cannot change, it is not necessaiy for you to define the method parameters and exceptions again. To do the same for a global class, you use the context menu of the inherited method and select REDEFINE. In this case a redefinition of the method is created (including a commented call to the superclass method). The superclass cannot be defined as F i n a l (this attribute can be seen in Figure 17.2).

Within the redefined method's implementation, you can use the prefix SUPER - > . . . to access components in the superclass directly above where you are

5 2 0 C h a p t e r 1 7 Class I d e n t i f i c a t i o n Ana lys i s a n d Des ign

working. This is often needed when you redefine a method to call the original method of the superclass.

A redefinition is not normally useful in the case of the constructor. Either the superclass's instance constructor can be used without any need to change it, or the subclass has been expanded (for example, new attributes have been added) and additional parameters are now required in the constructor's signature (per-haps to allow the values for the new attributes to be set when an instance is cre-ated). In ABAP Objects, the instance constructor can only be "overwritten" as part of inheritance. This overwriting allows both the signature and the imple-mentation to be adjusted in the subclass, and it is the only case where extra parameters can be added.

• You must call the instance constructor of the superclass within the construc-tor of the subclass. This is due to the specialization relationship: I f a construc-tor is defined in the superclass, it contains logic that must always be executed when an object is created for this superclass or its subclass. The runtime sys-tem. however, can only automatically ensure this i f the subclass's constructor was not changed.

• Unlike the instance constructor, the static constructor in the superclass is always called automatically. The runtime system automatically ensures that the static constructors of all superclasses were executed before the static con-structor in a particular class is executed.

Note

Overloading, which allows a method to have several definitions with different signatures and thus also different implementations, is not supported in ABAP Objects.

Visibil ity

When using inheritance, another visibility section can be useful, the PROTECTED SECTION. The protected component's visibility is between public and private and is visible to all subclasses and the class itself, but it still protected from outside the inheritance tree.

When you define local classes in ABAP, you must follow the syntactical sequence of PUBLIC SECTION. PROTECTED SECTION, and PRIVATE SECTION. The sequencing for a global class is handled automatically.

Key Concepts Refresher Chap te r 18 507

A subclass also inherits the private components of its superclass. You cannot, however, address them directly in the syntax of the subclass; private means pri-vate. The private components of superclasses can only be addressed indirectly by using public or protected methods from the superclass. These, in turn, can access the private attributes. The alternative is to change these private attributes to pro-tected attributes, which allows direct access in subclasses.

Using the private visibility section, you can make changes to superclasses with-out the need to know details about the subclasses. I f the changes you make do not affect the semantics, you do not need to adapt the subclasses. This is allowed because the private components of the superclass can only be indirectly accessed.

Because there is only one static component of a class exists per program context, it therefore follows that:

• All subclasses share a public or protected static attribute of the superclass.

• You cannot redefine static methods.

Casting

By assigning a subclass reference to a superclass reference, all components that can be accessed syntactically after the cast assignment are actually available in the instance. This is called either an up cast or a widening cast and can be seen in List-ing 17.4. We know the subclass always contains at least the same components as the superclass and that the name and the signature of redefined methods are identical. This means you can only address those methods and attributes that were inherited from the superclass.

DATA: 1v_name TYPE c LENGTH 30. l r .person TYPE REF TO lc l .person. lr_manager TYPE REF TO 1cl_manager. lr_employee TYPE REF TO 1c1_employee.

CREATE OBJECT lr_manager. lr_person - lr_manager. " Up cast 1v_name - 1r_person->get_name( ) .

Listing 17.4 Example of an Up Cast

You typically use an up cast assignment to prepare for generic access. When an instance receives a message to execute a particular method, the implementation of the method in the class of this instance is executed. I f the class did not redefine the method, the implementation from the superclass is executed instead.

508 Chapter 17 Class Identification Analysis and Design

Objects f r om d i f ferent classes reacting d i f ferent ly to the same method calls are k n o w n as polymorphism. Po lymorphism is one o f the main strengths o f inheri t-ance: A cl ient can handle instances o f d i f ferent classes un i fo rm ly , regardless o f their implementat ion. The run t ime system searches for the r ight implementat ion o f a method on behal f o f the cl ient.

Listing 17.5 and List ing 17.6 show the declaration and use o f po lymorph ism. Af ter creating a manager and employee, these subclass references are up cast and stored in a table o f the superclass ( in this case a table o f persons). The loop retrieves each record and obtains the name and salary. Because a manager is a employee and an employee is a person, depending on the type o f employee being processed, d i f ferent calculations could be in place to determine the salary.

TYPES: 11t_person TYPE REF TO l c l _ p e r s o n . l t t . p e r s o n TYPE STANDARD TABLE OF l l t . p e r s o n .

DATA: l v _ s a l a r y TYPE b e t r g . lv_name TYPE namel. l r . p e r s o n TYPE REF TO l c l _ p e r s o n . l t _person TYPE l t t _ p e r s o n . lr_manager TYPE REF TO lc l_manager. l r_employee TYPE REF TO lc l_employee.

FIELD-SYMBOLS:

<person> TYPE REF TO l c l _ p e r s o n .

Listing 17.5 Declarations for Generic Handling

APPEND INITIAL LINE TO l t_person ASSIGNING <person>. <person> - 1r_manager. APPENO INITIAL LINE TO l t _pe rson ASSIGNING <person>. <person> - 1r_employee. LOOP AT l t . p e r s o n ASSIGNING <person>.

lv_name - <person>->get_name( ) . l v _ s a l a r y - <person> >get_sa la ry ( ) . WRITE: / lv_name. 1v_bonus.

ENDLOOP.

Listing 17.6 Up Cast and Polymorphism Calls

Variables o f the type "reference to superclass" can also refer to subclass instances at runt ime. You may need to copy such a reference back to a suitable variable o f the type "reference to subclass." (This is a key point in that the reference variable being cast must have or ig inal ly started as a reference to the subclass: y o u are

Key Concepts Refresher Chapter 18 509

copying the reference back to reference the or ig inal class.) To assign a superclass

reference to a subclass reference, y o u must use the d o w n cast assignment oper-

ator M O V E . . . ? T 0 . . . or its short f o rm ? - (see List ing 1 7 . 7 ) . As a rule, the subclass

class contains more components than the superclass.

lr_manager ? - l r _pe rson . "Down cast

Listing 17.7 Down Cast

Af ter assigning this type o f reference back to a subclass reference to the imple-

ment ing class, cl ients are no longer l im i ted to j us t inher i ted components. A l l

methods and components o f the subclass instance can now be accessed. A d o w n

cast can on ly be per formed after first do ing an up cast. Because the target variable

can accept fewer dynamic types after the assignment, this assignment is also

called narrowing cast.

You typical ly use d o w n cast assignments when specific components o f instances

need to be addressed, and their references are kept in variables that are typed on

the superclass, for example, a generic list o f objects. You cannot use the super-

class reference for access to subclass components because it on ly al lows access to

the shared o r inher i ted components. Therefore, y o u need to do the d o w n cast to

be able to access the subclass components.

The run t ime system checks before assignment i f the current content o f the

source reference variable corresponds to the type requirements o f the target vari-

able. I f not. an except ion is tr iggered and the or ig inal value o f the target refer-

ence variable remains unchanged.

Note

In our previous example, we up cast an employee and a manager into a person table. An attempt to down cast an employee reference into a manager reference will produce this error. However, because a manager is an employee, a down cast to an employee reference will always work, as long as the reference was up cast to start with.

You can catch this exception o f the except ion class CX_SY_MOVE_CAST_ERROR by

using TRY . . . ENDTRY and the CATCH statements. Another way y o u can prevent

this run t ime er ror is to use the run t ime type ident i f icat ion (RTTI) classes. They

can be used to determine the dynamic type at run t ime and to set a cond i t ion for

the cast.

524 Chapter 17 Class Identification Analysis and Design

I n t e r f a c e s

F rom a technical po in t o f v iew , an interface can be thought o f as a l i t t le l ike a

l im i t ed part o f a superclass. However , they cannot be instant iated, do not have

an imp lemen ta t i on part , and on l y have pub l ic components . It is possible for y o u

to s imulate mu l t i p le inher i tance using interfaces. Interfaces a l low y o u to def ine

u n i f o r m interfaces (protocols) for methods. D i f fe ren t classes that inc lude the

interface can therefore i m p l e m e n t these methods in d i f fe ren t ways bu t keep the

same semantics. Interfaces therefore conta in no imp lementa t ions .

You can general ly def ine the same components in interfaces and classes, i n o ther

words , at t r ibutes, methods, and events. To recognize the semantic di f ferences

f r o m regular inher i tance, y o u shou ld focus on the f o l l o w i n g typ ica l use case: to

a l l ow the o p t i o n o f hav ing mu l t i p l e classes imp lemen t a me thod in d i f fe ren t

ways, but using the same me thod names and w i t h u n i f o r m signatures. W i t h reg-

ular inher i tance, y o u def ine this me thod in the shared superclass. I t may not be

possible fo r y o u to mode l a superclass sui tably fo r inher i tance ( remember , there

needed to be a s t rong re lat ionship: w e had to be able to say that o u r subclass "is

a type o f o u r superclass). However , y o u wan t to treat instances o f d i f fe ren t

classes in the same way. You need to def ine an interface and then def ine th is

me thod in these methods. The interface in this case can be compared w i t h a gen-

eral izat ion re lat ionship w i t h a superclass.

I f y o u compare this use o f an interface to regular inher i tance, the d i s t r i bu t i on o f

roles is somet imes d i f fe rent : Interfaces are general ly de f ined by the developer

w h o wants to use them. It is then dependent on each class to decide whe the r i t

actual ly of fers the methods de f ined there. This is s imi la r to a special izat ion rela-

t ionsh ip w i t h a subclass.

As occurs w i t h regular inher i tance, access to these methods is then usual ly

generic; i n o ther words y o u shou ld use a reference that is typed to the interface.

This means y o u can pe r f o rm p o l y m o r p h i s m w i t h interfaces. This is the on l y t ime

y o u w i l l see reference variables typed w i t h reference to an interface. Because the

interface cannot be instant iated, these reference variables w i l l on l y be used to

po in t to instances o f classes that inc lude the interface.

A l t hough the same components can be de f ined in an interface as in a class, in ter-

faces do not k n o w the v is ib i l i t y levels o f components . A l l interface components

are publ ic .

Key Concepts Refresher Chapter 18 511

Classes implement interfaces as fo l lows:

• You list the interface name in the def in i t ion part o f the class w i t h the INTER

FACES statement. This must be in the PUBLIC SECTION (interfaces can on ly be

implemented publ ic ly). Global classes def ine interfaces using the INTERFACES

tab shown in Figure 17.6.

• You must implement the interface methods in the implementat ion part o f the

class.

• You can address components def ined in the interface in the implementat ion

part o f the class.

Cuss interface Ct._6UI_Aiv_6«lD implemented/Actwe

Properties / 7 " • Friends Aflntutes Mtorads Everts Types

Bl J J [interface l A M r a t f F M I [Model [Description IF_CACHED_PftOP Access to Cached Property I t p i e i e n t a IF_6UI_DrNAMC_DATA Inter face for Processing D y n a m Con

IF_DRA60ft0P Drag and Drop Inter face for Controls

Figure 17.6 Interface Tab

You dist inguish interface components f r om other components in the implement-ing class by pref ix ing the interface name fo l lowed by a t i lde (~), wh ich is the interface resolut ion operator. The use o f the interface resolut ion operator enables y o u to access interface components using an object reference belonging to the class that implements the interface as y o u wou ld the method def ined in the implementat ion part o f the class. You can sec an example o f the use o f an interface in List ing 17.8.

l _ r_b i_que ry_ad ->1 f_ rs roa_b i_que ry~se t_ f i e l dca ta l og(

1_ t s_ f i e1dca ta log ) .

Listing 17.8 Object Reference to an Interface Component (set_fieldcatalog)

To s impl i fy access to interface components (thereby p rov id ing y o u a shorter

name to use), y o u can use alias names (see Listing 17.9). These can on ly appear

in the def in i t ion part o f a class or in the interface def in i t ion, and their use is sub-

jec t to the v is ib i l i ty restr ict ion o f the def in ing class.

ALIASES t r u e FOR i f _sa l v_c_boo l_sap~ t rue . IF l v . s t a t e EO t r u e .

Listing 17.9 ALIAS for an Interface Component

512 Chapter 17 Class Ident i f icat ion Analysis and Design

You can o n l y access in te r face c o m p o n e n t s b y us ing an ob jec t re fe rence w h o s e

class i m p l e m e n t s the in ter face. Syntac t ica l ly , th is also takes place us ing the in te r -

face r eso lu t i on o p e r a t o r (~).

A l t e r n a t i v e l y , y o u can use the alias names d e f i n e d in the i m p l e m e n t i n g class f o r

the in ter face c o m p o n e n t s . I f th is class is i m p l e m e n t e d i n a subclass, y o u d o n o t

need to change the w a y y o u access these al iased c o m p o n e n t s . H o w e v e r , the

source code w o u l d t hen be less se l f -exp lana to ry because the o r i g i n o f the c o m -

p o n e n t is no t clear. You c o u l d t he re fo re conc lude f r o m the syntax that the com-

p o n e n t s w e r e d e f i n e d i n the class ra the r t han as al iased in te r face c o m p o n e n t s .

Class Identification

O n e o f the i m p l i c a t i o n s o f us ing an o b j e c t - o r i e n t e d p r o g r a m m i n g m o d e l is that

s o m e A B A P s ta tements are n o w c o n s i d e r e d to be obso le te a n d t he re fo re canno t

be used in A B A P classes. I t is i m p o r t a n t t o p o i n t o u t t w o places f o r a d d i t i o n a l

i n f o r m a t i o n that w e w i l l n o t cover o n l y b r i e f l y o w i n g to t he i r size.

• The f i rs t is a l is t o f obso le te s ta tements o r f o r m s o f s ta tements . T h e i n f o r m a -

t i o n can be f o u n d i n the A B A P k e y w o r d d o c u m e n t a t i o n . F igure 1 7 . 7 shows

the loca t ion ( A B A P - KEYWORD DOCUMENTATION • A B A P - BY THEME • OBSO-

LETE STATEMENTS AND CONCEPTS) i n the d o c u m e n t a t i o n , a n d F igure 1 7 . 8

shows some o f the obso le te s ta tements .

Please no te that i n some o f the cases o n l y a pa r t i cu la r v a r i a t i o n o r a d d i t i o n is

obso le te . The s ta tements y o u w i l l f i n d the re are o n l y avai lab le f o r reasons o f

c o m p a t i b i l i t y w i t h releases p r i o r to 4 . 6 a n d 6 . 1 0 . M o s t o f the s ta tements

l is ted are syn tac t i ca l l y f o r b i d d e n i n A B A P Objects ( f r o m Release 4 . 6 ) o r U n i -

code (Release 6 . 1 0 ) . T h e i r res t r i c t i on in A B A P Objec ts is w h y t hey arc men-

t i o n e d i n th i s chap te r .

• The second source is a d d i t i o n a l i n f o r m a t i o n o n the Refac to r ing Ass is tant . I t

can be accessed by c l i c k i ng o n the APPLICATION HELP i con ( s h o w n in F igure

1 7 . 9 ) i n c i t h e r the Ob jec t Nav iga to r (Transact ion S E 8 0 ) o r the Class Bu i l de r

(Transact ion S E 2 4 ) a n d t h e n nav iga t i ng to CLASS BUILDER • UTILITIES OF THE

CLASS BUILDER to f i n d i n f o r m a t i o n o n the Refac tor ing Ass is tant . F igure 1 7 . 1 0

shows the i n i t i a l screen.

The Refac to r ing Ass is tant a l l o w s y o u to m o v e c o m p o n e n t s b e t w e e n super-

classes a n d subclasses o r b e t w e e n classes a n d in ter faces, f o r examp le , i f y o u

have d e f i n e d a c o m p o n e n t in a class a n d t hen real ize that c o m p o n e n t s h o u l d

b e l o n g in the superclass instead.

Key Concepts Refresher Chapter 17

• fi'^a o o GO ® a • < CD ABAP • Keyword Dccumer tabon t> ^A8AP-CW*ewA/t>cles " ^ ABAP - By Them*

I & ABAP fYT'tai I ^ Program Stnxlure I <^Bui t ln Typos. OatiCtiects. and Fur l> ^ DeciaratNe Statements I ^Create Octets i ^ call and Eat Program Units I ^ Ccrfrcfling Program f tow t» ^ Assignments I ^ Process intern* Data I Ustf Ditfog* I EdongEaem* Data fr ^ Program Parameters I ^ Program Processing I ^ ABAP Daea and Communication P ^ Extensions

i & a & * j > Sysiem Classes and interface Obsolete Stitom*-£s and Concepts

Obsolete S^taa Obsolete Declarations

^ Obsolete 0**ct Oenerabon ^ Obsolete Prcyam Calls ^ Obsolete Ert ^ Obsolete Proyam Flow Control ^Obsolete As v r m c n p

Obsolete Statements

The statements described in thrs subnode arc corrptfiWity wth releases pnor to 4 6 or 6 10 programs M yog should not use them in new

Most of the obsolete statements Isted here a B r i / j T : As a result, they can now only be i replacement cc*»slnxt<*s to all obsolete sta programs

Apart from the obsolete statements listed n tl norvot*o4ete staComerts These cannct be us detailed in the desertion of the corresponding

Figure 17.7 Obsolete Statement Location

^ O t *o * l c Statements and Concepts 4 > Obs<4«te $mtai

•=• Obsolete Oac I anions C»ATA- COMMON PART

^ T A 6 L £ 8 B

d r i f t s - o c c u r s & O T A • OCCURS & OATA. 0C<XN o r OCCV*$

^ R W O E S

* ^OCSC4«*OOte<tOen«r*on ASSIGN LOCAL CC^Y

" ^ O b t c l e t e P i c g r a m C e t * CALL OALOO

* ^OOSCteteEot

& Obtckte Prey am Flow Ccr*<4 ^ Obtokte Companion Optf *5:<s

v & Obsolete Ccn*c* SV.xSjr»» ^ ^ C*4 CHANGE Of

^ E N O O N 0 0 • var^rvg

Obsctete Ass g r a n t s

^ ^ Obsolete A$s»grmtrftt • PERCENTAGE

^ P A C K & LOCAL

^ ^ Obsolete Caicviiecn n ^ M o t ^ /CO • THEN. UNTIL & XX>COR*€$PO>CINO $ SU8TRACTCORRESROKONO

eO C*rfO€-CORRESPONC«HO ^ MT^aejM ^ M M M U N ^ S u w a w O

~ ^ Obsolete Character Sting Procossing & SEARCH $ REPLACE sub.t tmaWITH & TRANSLATE • COOC PAOC. N^HOCR FORMAT

CONVERT • IWERTED DATE ^ ^ C b t o i « t e Process*^ of w * m n T a w e s

RE/O • ^ SEARCH e»b ^VWTTETO

PRCMOC • Snort Fcr-n

Figure 17.8 Some of the Obsolete Statements

514 C h a p t e r 17 Class Iden t i f i ca t ion Analysis and Design

Class Builder: Initial Screen 11 a w e ™ * * l

Figure 17.9 App l i ca t ion Help Icon

T J T T SAP NetWeaver" l i K A L

A l ' U ' (S <1*1<«- It I f i t u 3 Ut i l i t i es of t h e C lass B u i l d e r

>Q

> Q '< ••>/:•

»Q v t v i ' . m l l m

t h t f « t M n « t J* tw C ( K t n j n M U * » i h t t l r O j ( * n t * m * r H H * to •MertKH) tuhum -yr.K} * < •Mtr^clm 4tl>)n •

M lh» [ h i ' ^ l l m*J» - « t lh» O t f t t l W } AAV l k » <rt** **nx i t n f t i M

• Q

• a K : t » 1 ' . * t M R«(KW1>] A l l l ' i ' i .|«.M not tm

r r f H t * nnl<J«»<) fey r t t t ruc l isv t t K v l H d r l-t>l<<J.«<t d « u « « t l ! W

• Q . S i . - - 1 : < A M I T M | M i l l l v i x u m ' l i M i K W t n i • ( * t c K v t l » l - r * P r l * ^ t < » c A w t i K t

Figure 17.10 Ut i l i t ies of the Class Bui lder

Impor tan t Terminology

Table 17.1 shows the important terminology for class design.

Term M e a n i n g

Inher i tance Inher i tance a l lows you t o der ive a n e w class f r om an exist-

ing class. W h e n subclasses inher i t f rom superclasses and

the superclass is itself the subclass o f another class, al l of

the classes invo lved fo rm an inher i tance tree, whose degree

of special izat ion increases w i t h each new hierarchical level

you add . Conversely, the classes become more general ized

un t i l you reach the root node of the inher i tance tree.

W i t h i n an inher i tance t ree, t w o adjacent nodes are the

d i rect superclass or d i rec t subclass of one another . O the r

related nodes are referred t o as superclasses and sub-

classes.

Table 17.1 Def in i t ions for Class Design

Practice Quest ions Chapter 17 529

Term M e a n i n g

Single inheritance A class can have more than one direct subclass, but it can

only have one direct superclass.

Mul t ip le inheritance A class inheri t ing f rom more than one superclass.

Superclass The class f rom which the specialization class inherits.

Subclass The specialization class that inherits f rom the superclass.

Interface Interfaces are extensions to class defini t ions and provide a

uni form point of contact for objects. Instances cannot be

created f rom interfaces. Instead, classes implement inter-

faces by implement ing all of their methods. You can then

address them using either class references or interface ref-

erences.

Different classes implement the same interface in dif ferent

ways by implement ing the methods dif ferently. Interfaces

therefore form the basis for polymorphism in ABAP

Objects.

Up cast An up cast assignment prepares for generic access. You are

casting a reference up the inheritance tree to a more gen-

eral object.

Down cast A d o w n cast assignment allows for more specialized access.

You are casting a reference back down the inheritance tree

to a more specific object. You cannot down cast any lower

in the inheritance tree than where the object was created.

Polymorphism Objects f rom dif ferent classes reacting differently to the

same method calls are known as polymorphism.

Table 17.1 Definit ions for Class Design (cont.)

% Practice Quest ions

The practice questions below will help you evaluate your understanding of the topic. The questions shown are similar in nature to those found on the certifica-tion examination, but whereas none of these questions will be found on the exam itself, they allow you to review your knowledge of the subject. Select the

530 Chapter 17 Class Identification Analysis and Design

correct answers and then check the completeness of your answers in the follow-ing solution section. Remember that you must select all correct answers and only correct answers to receive credit for the question.

1. Given the code in the exhibit (see Figure 17.11) and the knowledge that both l c l _ t ruck and lc l_car inherit from lc l_veh ic le . what statements are true?

[ TYPES: llt_vehicle TYPE PEr TO Icl_vehicle, ltt~vehicle TYPE STANDARD TABLE OF lit. vehicle.

DATA: lr_vehicle PEr TO lcl_vehicle. lt~vehicle TYPE ltt_vehlcle, lr_truc* PEr~TO lcl_truck. lr~c« TYPE REr TO lcl'car.

riELD-SYHBOLS: vehicle PEr TO lcl_vehicle.

CPEATE OBJECT lr_vehicl«. CPEATE OBJECT lr true*. CPEATE OBJECT lr car. APPEND INITIAL LINE TO ltvehlcle ASSIGNING vehicle . vehicle - lr_vehicle. APPEND INITIAL-LINE TO It vehicle ASSIGNING vehicle . vehicle - lr truck.

APPEND INITIAL LINE TO It vehicle ASSIGNING vehicle . vehicle - lr_car.

lr_truck 1- lr_vehicle.|

Figure 17.11 Question 1 Exhibit

• A. The code is not syntactically correct.

• B. The table 1 t_vehi c 1 e contains three vehicles.

• C. The code wi l l produce a runtime error.

• D. The codc shows three valid up casts.

• E. The codc shows two valid up casts.

• F. The code shows no valid up casts.

2. What is unique about a singleton?

• A. It must be instantiated using a private instance constructor.

• B. It must be instantiated using a public instance constructor.

Practice Questions Chapter 17 531

• C. It must be instantiated using a protected instance constructor.

• D. It must be instantiated using a static private constructor.

• E. It must be instantiated using a static publ ic constructor.

• F. It must be instantiated using a static protected constructor.

• G. It must be def ined as FI NAl.

• H. It cannot be def ined as FI NAL.

3. Wha t statements are true about a class that has granted f r iendship to another

class:

• A. The f r iend has access to private attr ibutes.

• B. The f r iend has access to protected attr ibutes.

• C. The f r iend has access to publ ic attr ibutes.

• D. A l l o f classes the f r iend has granted f r iendship access status to also have

the same access.

• E. A l l classes that inher i t f r om the f r iend (subclasses) also have the same

access.

4. There can on ly be one level in the inheritance tree.

• A. True

• B. False

5. What statements are true regarding ABAP inheritance:

• A. You can access the superclass component w i t h the pref ix SUPER >.

• B. The instance constructor can be overwr i t ten as part o f inheri tance.

• C. The static constructor can be overwr i t ten as part o f inheri tance.

• D. Over loading al lows a method to have several def in i t ions w i t h d i f ferent

signatures.

• E. Instance constructors must call the superclass's constructor.

• F. Static constructors do not need to call the superclass's constructor.

• G. Polymorphism requires the developer to specify wh ich method to use

w i t h inheritance.

518 Chapter 17 Class Ident i f icat ion Analysis and Design

6. Which statements are considered obsolete and cannot be used in ABAP Objects:

• A . TABLES

• B. D A T A . . . T Y P E . . . OCCURS

• C. DATA... BE6IN OF...OCCURS

• D . INFOTYPES

• E.RANGES

• F. LEAVE

• G. ON CHANGE OF

• H . SEARCH

• I . LOOP AT d b t a b

7. You can simulate multiple inheritance with:

• A . REDEFINITION

• B. INHERITING FROM

• C. INTERFACES

8. What is unique about a functional method?

• A. It must contain a returning parameter.

• B. It can contain an importing parameter.

• C. It can contain an exporting parameter.

• D. It can contain a changing parameter.

• E. It can be used in logical expressions.

• F. It can be used in SELECT statements.

• G. It must be a singleton.

Practice Quest ion Answers and Explanat ions

1. Correct answers: B, C, E

The table l t _ v e h i c l e does contain three vehicles: one vehicle, one truck up cast as a vehicle, and one car up cast as a vehicle. This also provides the correct number of up casts, which is two (the third is just an assignment of one vehi-

Practice Question Answers and Explanations Chapter 17

cle to another vehicle). The code w i l l produce a run t ime error (M0VE_CAST_

ERROR) on the d o w n cast. The reason for the error is simple: l r_veh1 c l e con-

tains a vehicle, not a truck, and it cannot be d o w n cast to ei ther a truck or a

car. I f we took the second record in the table, we could d o w n cast it because

it started as a truck and was up cast to a vehicle. The other t w o records in the

table wou ld produce the same error as l r _ v e h i c l e .

The code is actually syntactically correct and can be executed (up to the d o w n cast, wh ich aborts the program). As we have already discussed, t w o is the cor-rect number o f up casts — not three and not zero.

2. Correct answers: D, G

A singleton must be instantiated using a static pr ivate constructor. The rea-

sons for this combinat ion are: static so it is on ly called once and private so it

cannot be called f r om anywhere else. It must be def ined as FINAL so that it

cannot be inher i ted.

3. Correct answers: A, B, C, E

Friends have access to private, protected, and publ ic attr ibutes. The f r iend

at t r ibute is inher i ted: Classes that inher i t f rom fr iends and interfaces contain-

ing a f r iend (as a component interface) also become fr iends.

4. Correct answer: B

There can be many levels o f specialization in the inheri tance tree.

5. Correct answers: A, B, E, F

You can access the superclass by using the pref ix SUPER->. You can overr ide the instance constructor, but not a static constructor, because it is shared between all inher i ted objects. Over loading is not possible in ABAP Objects. Instance constructors need to call the superclass's constructor to make sure that eve iy th ing is created correctly. Static constructors do not need to explic-i t ly call the superclass's constructor because it is called automatical ly by the run t ime system. Polymorphism does not require the developer to do any-thing; the run t ime system automatical ly determines wh ich method to call.

6. Correct answers: A, B, C, D, E, F, G, H. I

Al l o f theses variations are obsolete.

7. Correct answer: C

Mul t i p le inheritance can be simulated w i t h interfaces.

534 Chapter 17 Class Identification Analysis and Design

8. Correct answer: A. B, E

A funct ional method must contain a re turn ing parameter (it is what makes it a funct ional method), but cannot contain either changing or expor t ing param-eters. It can contain an impor t ing parameter. The funct ional method can be used in logical expressions, such as the source in an assignment, a computa-t ion. and case statements.

Take Away You w i l l need to understand the fundamentals o f object-or iented programming. This includes the d i f ferent types o f classes and h o w the v is ib i l i ty o f components affects use outside o f the class or method. You w i l l need to understand what makes a singleton or a re turn ing method, when a class should inher i t f r om a superclass, and how to specify the inheritance. You should k n o w h o w interfaces can be used and how they can be addressed. Lastly, y o u w i l l need an understand-ing o f po lymorph ism and how both up casting and d o w n casting are used.

Refresher

You must understand inheritance and po lymorph ism. Singletons, re turn ing methods, f r iendship, and casting w i l l all play a part in the cert i f icat ion examina-t ion. You must have an understanding o f differences between instantiated objects and static objects. Also, y o u must have an understanding o f obsolete statements.

Table 17.2 shows the key concepts o f class design.

Key Concept Definition

Inheritance Inheritance allows you to derive a new class from an existing class so that one class (the subclass) adopts the structure and behavior of another class (superclass), possibly also adapting or extending it.

Polymorphism This is when instances of different classes respond differently to the same method calls.

Table 17.2 Key Concepts Refresher

Summary Chapter 17 535

Tips

W i t h this topic in part icular, i t is impor tant to have as much practical experience

w i t h the Class Bui lder as possible. It is impor tant that y o u understand the di f fer-

ences o f inheritance and interfaces.

Summary You should n o w be able to use the Class Bui lder effect ively and produce func-

t ional methods and singletons. You should k n o w the v is ib i l i ty o f attr ibutes and

methods based on both inheritance and the v is ib i l i ty section in wh ich they are

defined. You should also k n o w the reason for the use o f interfaces in ABAP

Objects. Your knowledge o f class design w i l l enable y o u to successfully pass this

topic dur ing the cert i f icat ion exam.

Enhancements and Modifications

Techniques You'll Master:

• Dcscr ibc var ious enhancement techniques avai lable in the SAP

system

• Enhance ABAP D ic t i ona i y objects w i t h o u t m o d i f y i n g t hem

• Imp lemen t enhancements to the SAP standard using user exits,

customer exits, Business Transact ion Events, and Business

Add- ins

• M o d i f y standard SAP repos i to i y objects using the Mod i f i ca -

t i on Assistant

• Describe var ious enhancement techniques f r o m the Enhance-

ment F ramework

524 Chapter 18 Enhancements and Modifications

I f y o u r development requirements cannot be fu l f i l led by customizat ion or per-sonalization, then y o u can ei ther enhance the appl icat ion, start a custom devel-opment project, or mod i f y the standard SAP appl icat ion. SAP provides various enhancement opt ions to adjust standard SAP Repositoiy objects w i t hou t actually mod i f y ing them. Some o f the techniques available for enhancements are user exits, customer exits, Business Transaction Events, BAdls, and Enhancement Framework techniques such as enhancement points, enhancement sections, and so on, wh ich can be implemented w i thou t even mod i f y ing the SAP system.

In this chapter we w i l l discuss various enhancement techniques available to

enhance the standard SAP system. We w i l l discuss h o w to implement each o f the

enhancement techniques. We w i l l also discuss how to locate the available

enhancement opt ions to adjust the standard SAP appl icat ion.

Real-World Scenario

Your customer w o u l d l ike to k n o w the various opt ions available for modi -fying and enhancing the SAP system because the SAP standard appl icat ion does not support the customer's business requirement. As an SAP devel-oper on the project y o u should be aware o f various enhancement tech-niques available in SAP so that y o u can explain about the enhancement technique, features, and benefits and so that y o u can use them.

Objectives of this Portion of the Test The object ive o f this por t ion o f the cert i f icat ion test is to judge y o u r knowledge about the enhancement techniques available for enhancing the SAP system. It is expected that y o u are aware o f user exits, customer exits, Business Transaction Events, and Business Add-Ins.

You should also be able to describe the new enhancement opt ions available in SAP NetWeaver 7.0. You should be able to explain about the enhancement tech-niques available in the Enhancement Framework such as expl ici t and impl ic i t enhancement points, expl ici t enhancement sections, and new Business Add-Ins (BAdI) technology.

Key Concepts Refresher Chapter 18 539

Key Concepts Refresher

SAP provides various techniques to adjust the SAP system o r appl ication to meet a customer's business requirements. First, the appl icat ion consultant on the project wou ld t i y to fu l f i l l the customer requirement by customizat ion or per-sonalization. I f the requirement cannot be implemented by customizat ion or per-sonalization, then y o u have to see i f the requirement can be met by enhancing the appl icat ion.

SAP provides y o u w i t h various techniques to enhance the SAP system. Some o f the techniques available fo r enhancements are user exits, customer exits. Busi-ness Transaction Events, BAdls, and Enhancement Framework techniques such as enhancement points, enhancement sections, and so on. These techniques can be implemented w i t hou t mod i f y ing the SAP system (except for user exits, wh ich is technically a modi f icat ion but docs not affect upgrade) and therefore do not require modi f icat ion adjustment at upgrade or when y o u apply support pack-ages. You should on ly mod i f y SAP objects i f the enhancement techniques men-t ioned above cannot fu l f i l l the business requirement. In this chapter we w i l l cover each o f the enhancement techniques in detail.

Enhancing SAP Applications

You can enhance SAP applications to add y o u r o w n funct ional i ty w i thou t modi -

fy ing the standard SAP system. SAP provides a number o f ways in wh ich an

appl icat ion can be enhanced w i t hou t mod i f y ing the or ig inal SAP appl icat ion or

program. SAP applications can be enhanced or adjusted using one o f the fo l low-

ing techniques:

• Customizat ion

• Personalization

• User exits

• Customer exits

• Business Transaction Event (BTE)

• Business Add- ins (BAdls)

• Table and structure enhancements

• Enhancement techniques w i t h i n the Enhancement Framework

540 Chapter 18 Enhancements and Modifications

Customizat ion is used to conf igure the SAP appl icat ion via the reference I M G

( Implementat ion Guide). Customizat ion is not y o u r responsibi l i ty, but it a l lows

y o u take the set o f SAP templates for business processes and manipulate them to

meet y o u r business requirements. You can customize some applications to def ine

the mandatory screen fields or even hide certain fields or screens f r om the appli-

cation.

Personalization is used to s impl i fy the SAP business transactions. The a im o f per-

sonalization is to adjust the SAP transaction for a specific user or user group or for

the company as a whole. Personalization includes things such as user menus, add-

ing transactions to y o u r FAVORITES menu, and shortcuts. Transaction variants are

another way to personalize; using these, y o u can switch o f f screen elements and

functions f rom the SAP transaction, thus s impl i fy ing the transaction for the user.

The funct ional consultants on a project should t i y to adjust the SAP standard

transaction via customizat ion or personalization before consider ing any develop-

ment work . You enhance the SAP appl icat ion or embark on custom development

on ly i f the customer requirement cannot be fu l f i l led through customizat ion or

personalization. Modi f icat ions can lead to compl icat ions dur ing upgrade. W h e n

SAP delivers a new version o f the object, y o u must decide whether y o u want to

keep the new version o f the object or cont inue w i t h the o ld mod i f ied version.

This process is k n o w n as modification adjustment and can s low d o w n the upgrade

process.

Enhancement Techniques

Enhancements are ways in wh ich y o u can implement customer requirements that have not been prov ided as part o f the standard SAP applications, w i t hou t mod i f y ing the SAP standard objects direct ly. SAP provides user exits, customer exits, Business Add-Ins, and so on as preplanned exit points in reposi tory objects that the customer can use to implement their o w n enhancement logic. Fo l lowing are the details regarding all o f the various enhancement techniques used in SAP applications.

User Exits

User exits are empty subroutines prov ided by SAP in wh ich y o u can add y o u r source code. This is the oldest enhancement technique to a l low y o u to insert y o u r p rogramming logic in to the SAP standard appl icat ion w i t hou t mod i f y ing it.

Key Concepts Refresher Chapter 18

SAP wil l no longer provide new user exits, but you can still implement the exist-ing ones.

User exits are implemented as subroutines and are sometimes called form exits. All user exits start wi th U S E R E X I T _ < n a m e > and are generally collected in an Include program that is attached to the standard application. SAP calls these sub-routines from the standard program. I f you implement them, your logic wil l be executed at these points. Most of the sales and distribution (SD) component still provides user exits for customer-specific enhancements. Figure 18.1 and Figure 18.2 display a standard SD component with the Include program and form sub-routines inside them.

UNC POTF SA»!F««A • i d a ^ i u u : . -a

W4il(«1 III ' U l l t t t i l l ' t i l M I S t l l M t

laClvM •«4V*tOC W M I M W I JSIM tatm'ttaJM I H t l •»_«t4«v4H i ta l ic •S'S-SUrt t«/FV4S»_o> • •M"«<M 147 • w . i u . u i m l ' . ) 'K!1(« v»riiefl •inclv4* f c t - S t * 1 3 " r w x t t O M i l to at l . i i j i ' - j S->l»'o« I K I U « * «i_»M_».«»rei

• n - t M v t ( * • c x i i s u s E » • T x I T s _ _ _ _ _ _

IMCIX4 WMUJU l l ^VMI l

IKlvJ* «v4V»'K

lac l v * n4S<r<» IK luM 1><1i-}* «v4V»f« 1*<1 v3* «»4«*fif i«<lv3* i <«o ' : { lnclvM «v4S«f*ti nwlio* I K l v M •v4V*'X4

:.ita «*riMti«oi "> MMtMW U I * r - * 0 4 u U l r » 0 Ul«r.artu1*l PAI Ul«r.ror*i < J e Uitr-fortt Ui«r* fort i « 1 <0 Ul*r.for«i > (C

» if » 10 4 <«

U •Hill OOje 91 KCM Kir-Son.ftra;:.onion

1*Clf3* »111_»»_»«4}a * H « v t u w u g i x l v M •ill_<»«_»v4ya 'CAfr l a u r f m

•MMAMMMM T J T M WHV4W.0I

• UI*R.FOR»I • Ui»r-foiai • Ui»r-fof«l • D w r f o n i • ® » r f « n

I M t l •I.IC«.4V» Italic 4 •

i .» <*raiot

Inc lude for U i« f Exits

Figure 18.1 Program Includes for User Exits

You can locate user exits within a program by searching for the word U S E R C X I T

in the main program of the application. You need to know where the user exit is called from within the program before you add your logic to the user exit to ensure that it's the right place for you to add additional logic.

You can double-click on the FORM routine o f the user exit to locate the PERFORM

statement, which calls the user exit, and then check i f it is the right place to add additional logic (see Figure 18.1). You can also find the user exits for your appli-cation from the I M G in the S Y S T F . M M O D I F I C A T I O N S folder for the specific appli-cation (see Figure 18.3).

Chapter 18 Enhancements and Modifications

••• INCLUDE MV45AF2A

• This inc lude i s reserved for user aodi f i ca t i ons

• Forns for sales docunent processing

• The natie of c o d i f i c a t i o n nodules should begin wi th '22'

FORM USEREXIT_M0VE_FIELD_TO_KOKKD

This userexi t can be used to nove sone f i e l d s i n t o the connumcation workarea for product subs t i t u t i on

This forn i s ca l led froo for® KOMKD_KOMPD_FUELLEN

forn userexit_«ove_field_to_ko«kd

• K0MK0-22 f i e l d = xxxx-22f ie ld2

endforn •e ject

Figure 18.2 Form Routine for User Exits

Investment Man»3«r>«it Enterprise Cwtrofcng PMI Estate Float* Re* Estate Manajemer* (RE-FX) Lopsacs - Geoerai Erwronmenc. Head arx) $af«ty Sotesondcistntaico

i Master Data 7 Bas»< Functions i So»s

Fc«*gn TrddeJCuuoms B i n g Sales Support (CAS) Pendutm Lilt irxjrect Sales

i Electron* Day werchange POS Menace Data Trmint trd Archrvwg

? SrttemModficaowis B Deate New Fie«s<U5tngC«x»ocm Technique) B Cfoato New* FieWs (Vrtthout Condecn Tochr»quo) B Routines Li User Eats

Ci User Eats Fof Pnce CWtermrwGcn t i <5> User Eats kx Partner Determination ft Q> User Eats For Credt Checks Ana Risk Vara»=<nent

t B User Eatsw Sales B Q> User Eats For Shpp<ng B <3> User Eats For Trarwpon.ee on Li <3> user Eats For Ring B <3> Usor Eats Fa Genwet Bifcng B <S> User Eats For Sates Support B Q> User Eats For Usts B <& User Eats «or Pa^nx** Cords

B Business Transacton Everts B Business Add-In

J. i ' • : • -nm tor sates orders

Figure 18.3 User Exits in the Reference IMG under System Modification

Key Concepts Refresher C h a p t e r 1 8 543

Most of the USEREXI TS for the SD component are in the package VMOD and can be viewed via Transaction SE80 (see Figure 18.4).

A B A P Editor: Display Inc lude FV45EFZ1

Ji- ll M " I i Und»

M W M f c i y C r o w * »Bopotiny< r t o n r M M S y w r SJlaQ Browser

WTOM Ropomay

Pack»y fvxKO

• I - i ^ u i t i B . i g i g r L CT»KIN»NE

- : :VMOO I tH><00ft»VCt»«K I CJ F l ^ J C l O^lXC^

FV4SEFZ1 FV4SVFZZ CV45VTZZ FV50CFZZ FV50UZXX FV50UZZZ FV50ST2Z MV4*AFZ4 M'/4FAFZA M V 4 W Z B M V 4 W Z C MV45ATZH MV41AFZU M V 4 W Z Z MVi'.MZZ M V 4 ^ 0 Z Z MV4SATZZ MV50AFZ1 MV5CAF73 MVICAFZK MV50AFZZ MWGFZ1 MVS0SFZ1

r c w »

L X J r

FV4i£FZl

± J t o U _ M

Actvo

Uitorrout ! non KV-Auf tragiaWrickl urg al c fotot 1 sen s o r t i o r t

U S E R E X I I S

rc«N USEREXI T_CMAX«_SAJ.ES_ORD€R

Normally. the Quanti t iy and conr i r ted date in a sales order schedule l i n e i s a u t c a t i c a l l y charged. »he' i t i s assigned to a requ is i t i on ana the requ is i t i on or purchase order i t changed i r you don' t li».o that . yo« can dorino spocial condit ions i n t h i s form t o protect yo«r orders

i r e rol lo*>ng r ie lds can be used TVTP- a l l Melds r ro• control table TVEP VBEP- a l l r i e lds rroe the schedule l i ne to be changed V8AP- a l l f i o l ds from tho i t o« l i no USJ/BCPEK- r i e lds . from tho requ is i t ion or pvrcnase ordor

Here you r ind tho quant i ty and date, which «> j ld be entered in to the schedule l i n e

Set CH_SUBftC > 0 to ind icate that the schedule l i n e should not t>o changed

forn use re * i t _change_sa les_o rde r us i ng us_vt>epek s t r u c t u r e vbet-ek

c h a r g i n g va lue<ch_subrc )

ch_subrc • 0

• Exaiple The order should bo changed only »hen the date s l ips • i r us VECEK-EiKOT < VBEP-HMAI • CH.SUBRC • 4 • ENDIF

F i g u r e 1 8 . 4 User Exits for the SD Component

User exits are called from the main program by the usual PERFORM statement within the application. Any customer enhancements made in the user exits are technically modifications because they require changes to SAP standard objects (i.e.. the Include programs you have created). However, SAP never delivers a new version of a user exit Include program, and they wil l not change these pro-grams. so the enhancements made using user exits will never impact an upgrade. If SAP has to deliver additional user exits for a new release, they wil l be placed in a new Include program.

Customer Exits

Customer exits were introduced after user exits to allow customers to enhance not only SAP standard code, but also screens and menus. The program exits are

544 Chapter 18 Enhancements and Modi f i ca t ions

implemented as function modules within the SAP standard program. These func-tion modules are delivered empty; that is. they do not contain any SAP standard code. Instead, they are provided so that the customer can insert their own logic.

You can add your own functionality to the function module without modifying the SAP standard business application (because your logic is inserted inside a spe-cial Include program in the function module that is in the customer namespace). Thus, there is no effect during a system upgrade. You define SAP enhancements and manage them via the Transaction SMOD. Customers can also view the avail-able SAP enhancements catalog via Transaction SMOD. and perhaps read the documentation about the enhancements before implementing them.

Customer exits are implemented with Transaction CMOD. Figure 18.5 displays SAP enhancement via Transaction CMOD. The screen displays program exits, menu exits, and screen exits for the SAP enhancement CNEX0003.

Components in SAP Enhancement CNEX0003 -y & <x a o Function mc j j® antt

FixictwrnoOJe EXIT_SAP1CJSS_C02 EXIT_SAPLCJSS_COJ

Short PS Qjswrw* E*t Custer** SpMifK Fn4ds PRQJS (Data PS CuSMntt E*t CuDdne* Specific FrtMs PROJS (DMA

O O

FWKDOO cooes Program SAPLCJSS

Coda Shwiows •CUD

O D

Screon areas C a i n j screw SWLCJSS

Mo Area Ca«eo screw 0205 CUSTSCRt SAPLXCH1

MO SftOrtTw 0500 Customer f * * » s M fen <M

O O

o o

Figure 18.5 SAP Enhancement Project via Transaction SMOD

If the customer wants to implement a customer exit, they must create an enhancement project in Transaction CMOD. This is a way of grouping enhance-ments together so that they can be activated together. One project could contain several enhancements, each of which could consist of several components, which could be a mixture of program exits, screen exits, and menu exits. Cus-

Key Concepts Refresher Chapter 18 545

tomer enhancement projects consist o f SAP enhancements. Each individual SAP

enhancement can be used in only one customer enhancement project.

Following are the three types o f customer exits.

Program Exits

The program exits are implemented as a function module within the SAP busi-ness application. The naming convention used for these function modules is EXIT_<Main_Program>_NNN, where NNN is a three-digit number. Program exits are also called function module exits and are called from the standard application by using the ABAP statement CALL CUSTOMER-FUNCTION 'NNN' where NNN is the three-digit number that is found at the end of the function module. Figure 18.6 displays the customer exit call w i th in the program, and Figure 18.7 displays the actual function module corresponding to the CUSTOMER-FUNCTION ' 0 0 4 ' . m<kx» KV45AFFE_FEL0AUSVAHl_L0M> Actwe i U i l S L y 00! m

perrora f i e l d a o d i f i c a t i o n _ r e v _ r e g

c a l l f u n c t i o n 'GET_HANDLE_S0_SAIES_8ASIC1

1 n p o r t i n g handle - 1_sd_sales_basic_exi t a c t i v e • a c t i v e

1 f a c t i v e » charx c a l l nethod l_sd_sa les_bas ic_ex i t ->na in ta in_sc re«n

expo r t i ng f t 180 • t180 fvbak • vbak fvbap • vbap fxvbup • xvbup(] fxvbuk • x vbuk j j fxvbap • xvbap j j fxvbpa • xvbpa j j

changing f . s c r e e n • screen

e n d i f

c a l l c u s t c a e r - f u n c t i o n '004' expo r t i ng

i_scroon_nano • scroon-naeo i_vbap • vbap i_vbup • xvbup i_screen_group4 • screen-group4 i_ t180_ak typ - t180-ak typ

changing c_screen_act ive « sc reen-ac t i ve c_$c roon_ inv i$ ib lo « screen-1 nvi s i b io c_screen_input • sc reen- input

per f o r i userexi t _ f i el d_«odi f i c a t i o n

• o d i f y screen

endfora • fe ldauswah1_lord

F i g u r e 18.6 C u s t o m e r Exit Cal l w i t h i n t h e SAP S t a n d a r d P r o g r a m

532 Chapter 18 Enhancements and Modifications

F u n c t i o n B u i l d e r : D i s p l a y E X I T _ S A P M V 4 5 A _ 0 0 4

* V « V >

Fir<t>cn mo&>* EX|T_SAPHV45A_0C4 Actr*. AWbUrt rnCKt EW1 O w < > E tvMons i ' . ' J ' t Mv ! •

n 1 i d *r 1 M 1 Q function e* i l_aai«.4!>aj»4

" L o K a l e S e n n i t t s t o i i ® irrORTIwi

VALUEi I .SCREENJWIE ) L IKE PEL0-\AME V A U * < I _ V « A R ) LIVE V?A» STRUCTURE VALUEi I _ V M » ) LIKE VBWVB STRUCTURE VW

V A L U E ) i l l 1 8 0 _ A X I Y P ) LIKE T180-AKTYR CHANGING

VALUE<C_SCREEN_ACTIVE> VAUI£(C_SCREENJ NVIS IM.E) VALUE(C_StftEEN_INPUTI

mct i -M zvtvauOd

«n<jrnnct10«

Figure 18.7 Customer Exit Implemented as a Function Module

You can search for SAP customer exit enhancements for an application via the Transaction SMOD by following the menu path U T I L I T I E S • F I N D to call the selec-tion screen. In the selection screen you can specify the application component or package to search for the SAP enhancement (see Figure 18.8). You can also search for SAP enhancements from the Repository Information System browser within the Object Navigator.

Repository Info System: Find Exits ] D D

Standard selective Eatnome ] : S*>0«tte)4 : Pocfcage Appfccxon Ccmpcocrt

AMbOnjI M*6<t)C*tt BFmodiieents SSaeenareas 0MenuErenes Component name •

Cr—dby ' 11 Created on Last changed ty Charged on

*

*

Sesnjs 7

MaarrunNo otHits 1 200 |

Figure 18.8 Selection Screen to Search for SAP Enhancements

Key Concepts Refresher Chapter 18 547

You can search i n the p r o g r a m source code ( w h i c h y o u w a n t t o enhance) f o r the

s ta tement CALL CUSTOMER-FUNCTION, a n d based o n the search resu l t dec ide i f t h e

c u s t o m e r ex i ts w i t h i n the p r o g r a m can be used to inser t a d d i t i o n a l p r o g r a m

log ic .

T o enhance a s tandard SAP app l i ca t i on tha t con ta ins a c u s t o m e r ex i t , y o u have

to create a cus tomer e n h a n c e m e n t p ro jec t t o i m p l e m e n t the c u s t o m e r ex i t . The

c u s t o m e r e n h a n c e m e n t p ro jec t can be c reated f r o m the A B A P W o r k b e n c h b y fo l -

l o w i n g the m e n u pa th UTILITIES • ENHANCEMENT • PROJECT MANAGEMENT o r v ia

the SAP Transac t ion C M O D . A f t e r y o u have created the c u s t o m e r e n h a n c e m e n t

p ro jec t , y o u assign the SAP e n h a n c e m e n t to the p ro jec t .

You can find the SAP e n h a n c e m e n t f o r the c u s t o m e r ex i ts f u n c t i o n m o d u l e b y

e n t e r i n g the f u n c t i o n m o d u l e n a m e o n the S M O D se lec t ion screen (as d i sp layed

i n F igure 18.8 above) . The search resu l t w i l l p r o v i d e y o u the SAP e n h a n c e m e n t

t o w h i c h the c u s t o m e r ex i t f u n c t i o n m o d u l e is assigned, a n d i t can be assigned

to the c u s t o m e r e n h a n c e m e n t p ro jec t .

A f t e r the ass ignment y o u can access the e n h a n c e m e n t c o m p o n e n t such as func -

t i o n m o d u l e a n d inser t code i n the I nc l ude r o u t i n e w i t h i n t h e c u s t o m e r ex i t . Y o u

can use the data s u p p l i e d i n the f u n c t i o n m o d u l e parameters f o r the enhance-

m e n t . Y o u d o n o t have access to the g loba l p r o g r a m data. You can o n l y access the

f u n c t i o n m o d u l e in te r face pa rame te r fo r e n h a n c e m e n t . Y o u dec ide w h i c h func-

t i o n m o d u l e in te r face to use.

As a final step, y o u need to act ivate the p ro j ec t a f te r i m p l e m e n t i n g the f unc t i on -

a l i t y . A c t i v a t i n g the p ro j ec t t u rns o n the n e w f u n c t i o n a l i t y i n the c u s t o m e r exi ts .

U n t i l y o u d o th is , y o u r log ic w i l l n o t be execu ted as pa r t o f the s tandard appl ica-

t i o n . You can also deact iva te the c u s t o m e r p ro j ec t to t u r n o f f y o u r f u n c t i o n a l i t y .

Th i s is use fu l because i t doesn ' t r equ i r e y o u to t o u c h the code. F igure 18.9 a n d

F igure 18 .10 d isp lay the steps to create a c u s t o m e r p ro jec t .

You can act ivate the p ro jec t b y c l i c k i ng o n the ACTIVATE PROJECT i con ( • ) o n t h e

i n i t i a l c u s t o m e r p ro jec t screen o r o n the c o m p o n e n t s screen. You can deact iva te

i t by c l i c k i ng o n t h e DEACTIVATE PROJECT i c o n (~jj~[) o n the i n i t i a l screen o r o n t h e

c o m p o n e n t s screen.

534 Chapter 18 Enhancements and Modifications

Project Management of SAP Enhancements - o n c *>

ProHCt AMPLOOOI 0 Create

OCCTptf lXU

OOoa/nexaOC*

^ Ctsptoy J • Change

MKHH i I«MIH [ I « i i l > . y i l > l l » N M

SAP Enhancements in Enhancement Project AMPL00011 "V B <5 a a EnhwxenKrt Componorts

E n n a ^ e m d Ted

ArtPLOOOl User subscreen lor M l <J«a on AMPL

Figure 18.9 Create Customer Enhancement Project

CXlT_JAfU*«>_«*

tVireAJ)

C l jWfL

j fu rvc t ion o x i t _ s a p l « b a « _ 0 0 l

• • • • L O k a l e S c h n i t t t t e i l e IW0RTIN&

VALUC(I_AWL> LIKE AWL STRUCTURE AWL OPTIOXAL

i n c l u d e 2xaapt^ l i

e m j r u n c t t o *

Sc t * * i «<i t

Function Builder: Display EXIT SAPLMBAM 001 f i r i w w g j H r l T l r * Fuv»onmo<Jii» EXIT_SAPLK8A«_001 Ac»ve

Aanuies n-oxr C M i g n o Ttbktt M M •

61J0 U»W>»I J A t V M t

C h j n g o AMPLO&Oi

W i U B O W W W m c u w i i i i j w i i i i | B O m a a w

Project

r u K t i o e ex i t

Figure 18.10 Edit Individual Enhancement Component

Key Concepts Refresher Chapter 18 549

Screen Exits

With screen exits you can insert additional screen elements (for example, an input field, a table control, or a pushbutton) to a standard SAP screen. SAP pro-vides screen exits by placing a special subscreen area on the standard SAP appli-cation screen. The customer screen is called from the standard screen flow logic and linked to the SAP standard subscreen area.

Figure 18 .11 displays the FLOW LOGIC screen for the main screen of the sub-screen that has a statement to call the subscreen in the PBO and a statement in the PAI to process the user's action on the subscreen. The statement CALL CUS-TOMER SUBSCREEN is called in the PBO and PAI for the screen exit instead of call subscreen. Also, looking at CALL CUSTOMER-SUBSCREEN,you can see that a screen exit is available for the application. The subscreen is called from the main screen, and the PBO and PAI of the subscreen are processed just like the normal screen. The PBO and PAI also have function exits inside the modules DATA_TO_FXIT0100 and DATA_rROM_TX IT0100 that can be used to transfer data from the main screen to the subscreen and vice versa.

Screen Painter: Display Screen for SAPLLMOB t f - & • a»:- . " . a n <a * Layout

Screen number 1100 Actr.« a Amtotes La Ewwi isi^aQTTI

«r % ffl » Tl- 16 f r i

process before output •odule status_screen •odule su . tex t aodulo disable_pb_save •odule set_cursor •odulo data_to_ex i t0 i00 c a l l customer-subscreen exi tOIOI

i nc lud ing 'SAPLXLRF' scrn_data-scrnd_uscrn

process a f t e r input c a l l custosier-subscreen exi tOIOI •odule data_f rc«_ex i t0 l00 •odule exi t_cow>nds at exit-con«and f i e l d ok_code nodule user_co»«ands

F igu re 18.11 Subscreen Call w i t h t h e PBO Event

For each screen exit, you also have a program exit, because of the need to trans-fer the data between the screen and the program. Figure 18.12 displays the pro-gram exits within the above-mentioned PBO and PAI modules.

550 Chapter 18 Enhancements and Modifications

»xi>» LLnoeoo2

i i i j u a m g

•4 nodule &ATA_TO_|XITOIOO CMTPUT

•odule oata_to_e*itOlOO output perform find_uter_*cr«en changing tcrn_oata

• AfTER LEAVt TO SCREEN fl

ca l l cui toaer- funct ion 'SOO' exporting

i_r l»ob • r l *sb l_currant_f i« ld - cur rant_ f io ld 1_inp_100 • inp.100 l . m . W x t • s<i_text

endiodule 1 MT*_TO_EXIT0100 OUTPUT ' I

Hodulo 0ATA_T0_EXIT0102 OUTPUT

•odule c-»ta_to_e«i 10102 output p*r for« f ind_js«r_icr«»n changing tcm_doto

• AFTER LEAVE TO SCREEN 0

ca l l customer-function 'MO' exporting

I _1 tak • I tan i_r l»ob • r l » b

i_current_f ie ld • c»rrent_fia1d

endtodule ' DATA_TO.EXIT0102 OUTPUT

Figure 18.12 Program Exits for Screen Exits with the PBO and PAI Modules

You have to implement a customer enhancement project as defined above to implement the screen exit. However, if the screen exit belongs to an enhance-ment for which you have already created a project, then you edit the existing project rather than creating a new one. You can also assign the SAP enhancement to another customer project that may contain other, related enhancements and can then work on the screen exit. Remember that you activate at project level, so i fyou want to ensure that your enhancements are "switched on" together, you should group them inside the same project.

Menu Exits Menu exits allow you to attach your own menu item in the pull-down menus of the SAP standard application. SAP creates menu exits by defining special menu items in the Menu Painter. The function code for the menu exit item starts with a plus sign (+), and you have to specify the menu text when editing the menu exit component within the customer enhancement project. The menu exit item will not be displayed until the project is activated. A function module exit is provided for the specific function code of the menu exit.

Key Concepts Refresher Chapter 18 537

You can add your own program logic for the menu item within the function module exit. Just like screen exits, menu exits go hand-in-hand with program exits. There is no point in being able to add a new entry to a menu unless you can program the logic that will be executed when the user selects this new entiy (see Figure 18.13).

Components in SAP Enhancement PCSD0001 V O I I

txlt_SAM.CSt>I_00l PCS00001 tVM.Uwr.*

2 £

factor (COM COS* MolM*

SAfi.C10J •001

Display Menu 8nr Material BOM Croup \ V . . c . O « 4 \ A N < » M

C>t'»! \ Sottiigi COM Vic AVM AMI

T«.t Micailt*«iti<« OJta

Alt' j r x ' l >iie'0( «UMt>iy

\

•OAS !jte» ciiinr-cAtien CO)K1 MMMMC'M \ >

RfA KVAJ

<Km r n i n w rrono* l»»*l

\ fct'A \ t j t i \ f»I»

Alt 1*1 or Alt Ctatf i . i !»r t ro» (<«

I f f viIm • m i ' w i W r x v » u

.COl

AU ITM mro Oiico".'i>.»no« i«ro ! IM <Mf»JOI Cultn»«r ».U TOI

F i g u r e 18.13 Menu Exit Enhancement

You have to create a customer enhancement project similar to the one created for program exits to implement menu exits. You can also add SAP enhancement for the menu exit to the existing customer enhancement project and then edit the menu exits component with the customer project.

Business Transaction Events

Business Transaction Events (BTEs) have been available as of Release 4.0 and are another technique for implementing program exits, and only program exits. Business Transaction Events are generally found in the general ledger accounting (FI-GL), accounts receivable and payable (FI-AR and FI-AP) and sales and distri-bution components.

538 Chapter 18 Enhancements and Modifications

A BTE has a predef ined interface (once again, y o u decide what this w i l l be) and

al lows y o u to attach addi t ional funct ional i ty in the f o rm o f a service funct ion

module. Unl ike customer exits, y o u create the funct ion module yoursel f , but this

funct ion module must have the parameters y o u have dictated. By l ink ing the

funct ion module to the Business Transaction Event, it w i l l be called at the appro-

priate po int in the SAP standard appl icat ion.

Business Transaction Events can have the fo l l ow ing types o f interfaces:

• Publish and subscribe

• Process interfaces

Publish and Subscribe Interfaces

These interfaces i n fo rm external software that a certain event has taken place in

the SAP standard appl icat ion and prov ide the data produced. Publish and sub-

scribe BTEs receive data f r om the SAP standard appl icat ion but don ' t pass any

data back. Therefore, there can be mul t ip le implementat ions o f these BTEs. One

use o f publ ish and subscribe BTEs is to pass data to external software, not expect-

ing any return data f r om the external software.

An event funct ion module is called in the SAP program that determines the active implementat ions for the event in question and then executes the service funct ion modules for each o f these active implementat ions o f the BTE event, one after the other. The order in wh ich the implementat ions are executed cannot be guaranteed.

The name o f the event funct ion module for publ ish and subscribe BTEs begins w i t h OPEN_FI_PERFORM_<NMNNNNNN>_E or OUTBOUND_CALl_<NNNNNNNN>_E, where <NNNNNNNN> is the eight-digi t event number . The service funct ion modules for the event (i.e., the funct ion modules that have been created and implemented) are executed as def ined in the customization. Figure 18.14 displays the customiza-t ion for the Business Transaction Event 0 0 0 0 1 0 2 5 , and Figure 18.15 displays the BTE call in the SAP program.

The customizing for BTE events is def ined by call ing the SAP Transaction FIBF. The customizing fo r publ ish and subscribe interfaces is def ined by fo l l ow ing the menu path SETTINGS • P/S MODULES and selecting the opt ion fo r customer, part-ner, or SAP enhancements (see Figure 18.16).

Key Concepts Refresher Chapter 18 553

Change View "Publish&Subscribe BTE: SAP Enhancement": Overview V NEWERAR** A O F U B O

| E W L |ctr | F I R < : 8 0 N M 0 0 I I « I • •

|

00001025 D I - W C /SAME/WC_LNTERFACE_C0001025 • •

00001025 FI-CN F0H COTL. INTERFACE 30001025 0000102$ FI-DM FDM_AR_INT£RFACE_00001025 00001025 FI-TAXCREATE_DEFTAX_ITEM

r

00001025 TS-PS FM_CHECK_FL 00001025 ISJP ISJP_BTE_00001025 00001025 RE BE EX_CALL8AC K_PAYME SIJ30001025 00001025 UKM L*N_INT£FVACE_0000102S 00001025 AR AR_PRO:ESS_OOOOIO25_NUM_CHECK 00001025 GK TURKEY_BO£_P£RFOW1_0000102S 00001025 TH TURKEY.BOE.PERFWM.00001025 >0001025. TURKEY_80£_P£RF<*TM_00001025

Figure 18.14 BTE Customization for SAP Enhancement

MF05AFF0 _FCODE_BEAftBEI TUNG Active

DH

p e r f o r a s inula te_ l&clger_v ie"* using ' C ' e n d i f

O P E N F L

1 f postab ne space r e f r e s h c l r t a b loop a t postab where x a k t p • ' X '

• o v e - c o r r e s p o n d i n g postab t o c l r t a b append c l r t a b

endloop endi f c a l l f u n c t i o n 'OPEN_FI_PERFOW1_00001025_E'

note 0561898

e x p o r t i n g 1 bkdf • bkdf

t a b l e s t_ausz1 • xausz i t_ausz2 • xausz2 t_ausz3 • xauszJ t _ b k p l a xbkpl t . b k p f • xbkpf t . b s e c • xbsec t . b s e d • xbsed t . b s e g • xbseg t _ b s e t m xbset t . b s e u m xbseu t _ r s g t a b m r s g t a b t _ r e n u » s renuit t_postab • c l r t a b

e x c e p t i o n s e r r o r nessage • 1

"note561898 • note561898 •note561898

•Note1097274 •Note1097274

Figure 18.15 BTE Function Call in SAP Program

Customers and partners have to define a product by following the menu path S E T T I N G S • P R O D U C T S • C U S T O M E R or S E T T I N G S • P R O D U C T S • P A R T N E R before they can define the customizing of the event and the function module they want to be executed.

554 Chapter 18 Enhancements and Modi f icat ions

Events Edt Goto Setangs Environment System Help © Identification • 0 © f f l

S A P B u s i n e s s Products P/S Modules

^ A * * * - - - - - Al - — r*. • - n f c of an SAP Application

•1 of a partner Process Modulos

^ A * * * - - - - - Al - — r*. • - n f c of an SAP Application

•1 of a partner of a customer

Figure 18.16 BTE Customization for SAP, Partner, or Customer

Pub l ish a n d subscr ibe in ter faces a l l o w y o u to start one o r m o r e serv ice f u n c t i o n

m o d u l e s w i t h o u t i n t e r f e r i n g w i t h each o t h e r . Cus tomer , pa r t ne r , o r SAP

enhancemen ts can d e f i n e t he i r o w n service f u n c t i o n m o d u l e i n t h e cus tomiza-

t i o n w i t h o u t i n t e r f e r i n g w i t h each o t h e r b y c rea t ing t he i r o w n p r o d u c t . Y o u can

also s w i t c h o n o r o f f each p r o d u c t as a w h o l e e n t i t y . Th is a l l ows the user t o con-

t r o l w h i c h e n h a n c e m e n t s h o u l d be processed a n d w h i c h s h o u l d n o t be p ro -

cessed. In cont ras t to c u s t o m e r exi ts , Business T ransac t ion Events a l l o w y o u to

use m u l t i p l e in ter faces f o r a d d i t i o n a l log ic .

Process Interfaces

These in ter faces are used to c o n t r o l the business process d i f f e r e n t l y t han the w a y

i t is h a n d l e d i n the s tandard SAP system. I n cont ras t t o p u b l i s h a n d subscr ibe ,

data exchange takes place i n b o t h d i r ec t i ons in process in ter faces; that is, the SAP

s tandard app l i ca t i on passes data to the f u n c t i o n m o d u l e , a n d the f u n c t i o n m o d -

ule can pass data back. A process BTE can t he re fo re have o n l y one act ive i m p l e -

m e n t a t i o n .

SAP also p rov ides y o u w i t h sample f u n c t i o n modu les fo r the BTE. w i t h a sho r t

text , in ter face (i .e.. the parameters y o u need to use fo r y o u r f u n c t i o n modu le ) , and

d o c u m e n t a t i o n that can al l be used b y the cus tomer w h e n creat ing the i r o w n func-

t i o n m o d u l e . The n a m e f o r the sample f u n c t i o n m o d u l e is SAMPlE_lNTERFACE_

<BTE -1 D>, a n d the easiest w a y to p roceed is t o c o p y i t as y o u r s ta r t ing p o i n t .

BTE Search

You can d e t e r m i n e w h e t h e r an SAP app l i ca t i on o f fe rs a Business T ransac t ion

Event by search ing f o r the character s t r i n g 0PEN_FI_PERF0RM w i t h i n the source

code o f the app l i ca t i on t ransac t ion (because, as w e ' v e seen, t h e even t f u n c t i o n

m o d u l e n a m e starts w i t h th i s s t r ing) .

Key Concepts Refresher Chapter 18 555

Y o u can also scarch f o r BTE events b y ca l l i ng the SAP Transac t ion FIBF a n d fo l -

l o w i n g the m e n u pa th ENVIRONMENT* INFO SYSTEM (P /S) o r ENVIRONMENT• INFO-

SYSTEM (PROCESS).

B u s i n e s s A d d - I n s

Business A d d - I n s (BAd ls ) are an SAP e n h a n c e m e n t t e c h n i q u e based o n ob jec t -

o r i e n t e d ABAP. Business Add - I ns , l i ke the p r e v i o u s l y d iscussed e n h a n c e m e n t

techn iques , are p r e d e f i n e d b y SAP in the s tandard app l i ca t ions . The d e f i n i t i o n o f

Business A d d - I n s can be v i e w e d in the SAP Transac t ion SE18. You use th is t rans-

ac t i on to create B A d I d e f i n i t i o n s .

You create an in ter face f o r the Business Add - I ns , w h i c h con ta ins the d e f i n i t i o n

o f the m e t h o d s that w i l l be p r o v i d e d f o r t h e cus tomer . T h e n y o u create an

adapter class that i m p l e m e n t s the in te r face a n d thus p rov i des t h e in ter face f o r

BAd I i m p l e m e n t a t i o n . In t h e SAP s tanda rd app l i ca t i on , y o u genera te an ins tance

o f the adapter class a n d cal l the c o r r e s p o n d i n g m e t h o d w i t h i n the app l i ca t i on .

Th i s is w h e r e the c u s t o m e r can a d d the i r o w n logic, b y c rea t ing t he i r o w n i m p l e -

m e n t a t i o n o f th is m e t h o d o f the BAd I .

The s t reng th o f Business A d d - I n s lies i n the fact that t hey can have m u l t i p l e

i m p l e m e n t a t i o n s i f y o u i n t e n d that . You can have several act ive B A d I i m p l e m e n -

ta t ions i f t h e MULTIPLE USE checkbox is selected (see F igure 1 8 . 1 7 ) . W h e n the

BAd I is ca l led i n the SAP s tandard app l i ca t i on , the ins tance o f the B A d I adapter

class is respons ib le f o r e n s u r i n g that al l i m p l e m e n t a t i o n s are cal led. H o w e v e r

because t hey can be ca l led i n any sequence, i t is n o t poss ib le t o guaran tee the

o rde r . I f y o u have mu l t i p l e -use B A d I d e f i n i t i o n s , the sequence m u s t n o t p lay an

i m p o r t a n t ro le . A t yp i ca l e x a m p l e is the execu t i on o f checks be fo re a d o c u m e n t

is saved.

S im i l a r l y , y o u can have several act ive B A d I i m p l e m e n t a t i o n s i f t h e FILTER-

DEPEND. checkbox is selected f o r the BAd I . The idea is t h a t y o u can have d i f f e r e n t

BAd I i m p l e m e n t a t i o n s fo r d i f f e r e n t filter values i f the FILTER-DEPEND, checkbox

is selected. A n e x a m p l e o f th is is w h e n the filter is based o n the c o u n t r y code:

The c u s t o m e r can create an i m p l e m e n t a t i o n f o r d i f f e r e n t coun t r i es based o n

the i r d i f f e r i n g legal r e q u i r e m e n t s o r pract ices. You can have o n l y one act ive B A d I

i m p l e m e n t a t i o n at a t i m e i f the MULTIPLE USE a n d FILTER-DEPEND, checkboxes are

n o t selected. Each Business A d d - I n can c o n t a i n c o m p o n e n t s f o r p r o g r a m

enhancements , m e n u enhancemen ts , a n d screen enhancemen ts , s i m i l a r t o cus-

t o m e r exi ts , descr ibed ear l ie r .

542 Chapter 18 Enhancements and Modifications

B u s i n e s s A d d - J n s : D i s p l a y D e f i n i t i o n M E _ P U R C H D O C _ P O S T E D V »" fl O Oocuittoueco OetrtbOnNarre KE_PIRCHDCC_POSTEO Oetabon Short T«rt Puchas«nj Documert Po«e3

GeowalCuta P«ci<ege ME 1*9 charged by SAP

DE G«man last Chang* 09/27/2001 16 07 48

Name <y bus oddin class G._EX_ME_PURCHOOC .POSTED

T W 7

Filer rrf*

F i g u r e 18.17 Business Add-In Attributes

Program enhancements arc defined in the form of interface methods. You define

the interface and the methods inside it, including their parameters. To imple-

ment the program enhancement, a BAdI implementation must be created, and a

class is generated automatically for you to implement the method (see Figure

18.18).

B u s i n e s s A d d - I n s : D i s p l a y D e f i n i t i o n M E _ P U R C H D O C _ P O S T E D

y & fl • Documentation

OtfcftonNtHW HE.PURCHDOC.POSTED ] DotriOco Short Tot Purchasing Document Posted

Ami b a e t ^ m f r f f i j

interface name 1 F_EX_H£_PUKCHOOC_POSTED

MNM Descnpeon POSTED Purchasing Docimert Postod

GJCDI I J.^131*

F i g u r e 18.18 Business Add-In Interface and Methods

The Business Add- In definit ion can also have function codes for menu enhance-

ments. The function codes for the menu entries are available in the GUI interface

and are visible to the user only when the Business Add- In is implemented and

activated. The function codes for BAdI menu enhancements start wi th a plus sign

(+). similar to customer exits. M e n u enhancements can have only one active

Key Concepts Refresher Chapter 18 557

implementation and are not found in multiple-use or filter-dependent Business Add-ins.

In addition to program and menu enhancements, you can also find screen enhancements in Business Add-ins. Screen enhancements, like menu enhance-ments, are not supported for multiple-use Business Add-ins. Figure 18.19 and Figure 18.20 display the interface for menu enhancement and screen enhance-ment, respectively. Menu enhancements are defined under the F C ODES tab, and screen enhancements are defined under the SUBSCREENS tab.

B u s i n e s s A d d - i n s : D i sp l ay D e f i n i t i o n C E M O N EXIT1 S " 8 & « * . ° , i i l J Docune«aico

DofiriDon Nao® CE.HON.EXITI Deflnoon Shot Te«t BArj wertace k* Customer Ertensicns Cy

A A n j i t M o r t a c e . A & t - T M Sutecreeml

p r i F i n i n |Progr«m iFuncoon code )C>escr«co CEP J*J_H0NITORINO •EXTEhSI M»nuGoOo->

^^

F i g u r e 18.19 Business A d d - i n s fo r M e n u E n h a n c e m e n t

B u s i n e s s A d d - i n s : D i s p l a y D e f i n i t i o n B A D I _ F D C B _ S U B B A S 0 1

y*s & • : • a • oxmwtaxx i

Deft noon Name Deftnoon Snot T«,i

Asnbutes we-iace FCooes^

8AD i _F DC B_SUBBAS01 Screen Ennancerrert iwiFDCS Basic Data Screen (010.510)

QH program SAPLFDC6 SAFLFDCB

ScrNo Subscreen area 10 SUB6AS01 510 SUB8AS01

Descnpeon Enhancemer* 1 Vendor Basic Data Enftancemert 1 Customer Basic Data

E S C

F i g u r e 18.20 Business A d d - i n s fo r Screen E n h a n c e m e n t

Searching Business Add-ins

There are various ways of searching for Business Add-ins in SAP standard appli-cations.

• You can search for a BAdI in the relevant application program by searching for the string CL_EX ITHANDLER. If a Business Add-In is called in the program,

544 Chapter 18 Enhancements and Modifications

then the GET_INSTANCE static method of this class is called in the program. This method returns an instance of the BAdI adapter class, and after that, you will see the BAdI method call that you can implement. Figure 18.21 displays the GET_INSTANCE method call in the program.

kxijv UH08F04 Active

: I I I _ L _ Wl . KM T O W type l tap is_ok_code type syucoaa iv_screen_type type lvs_devtyp

data lv_exit type ref to 1 f_e*_l»o6_vas_or<Jer_badi data l t j t a p tyoe l tap occurs 10.

i s j t a p l i k e l tap. l s _ t a p j t a p l i k e screonjiolds

cal l aetnod cl_exi tnandler»>get_i nstance oxporting

e x i t _ n w - •lK06_VAS_0«t>£R_eA0t' null jnstance.accepted • con_x

changing instance • lv_«xit

in case the badi is active

i f not lv_oxit is i n i t i a l

• Collect only the current processed TO i t e « loop at l t j t a p into ls_tap_ltap

whoro kzqui • con_x •ove-correspondinj ls_tap_ltap to I s j t a p append l s j t a p to l t j t a p

endioop

• cal l aethod cal l aethcd lv_exit->display_vas_order

exporting K j t a k • i s j t a k i s j t a p • i s j t a p U J t a p • l t j t a p iv_screen_button • is_ofc_code iv_scroon_typo • 1 v_scroon_type

endi f

ondfora • badi_rf_vas_order_disp

F i g u r e 18.21 G E T J N S T A N C E M e t h o d Ca l l i n S A P S t a n d a r d P r o g r a m

• You can use forward navigation to reach to the definition of the BAdI. In the above program you can double-click on the method DISPLAY_VAS_ORDER cor-responding to reference variable l v _ e x i t , which will display the interface used to define the BAdI. You can use the where-used functionality to deter-mine which BAdI the interface is used in and then create the BAdI implemen-tation.

• You can use the SAP Application Hierarchy to restrict the component in which you want to search for Business Add-Ins. The SAP Application Hierarchy dis-plays all of the standard SAP application components and the packages that have been assigned to them. You can use the Application Hierarchy with the Repository Information System to locate BAdls available for an application.

Key Concepts Refresher Chapter 18 559

To locate the BAdls available for purchasing proceed as follows: • Place the cursor on the P U R C H A S I N G branch of the Application Hierarchy

tree and click on S E L E C T S U B T R E E (+/-; see Figure 18.22) or click on the SELECT S U B T R E E +/- icon ). The P U R C H A S I N G node is under the SAP appli-cation M M .

-J3RM Local izat ion Russia MM -*EBV Purchasing/£w -«N_ING Custoaizing Mater ia ls Managoaont -*H_PRI0 DfPS R e t r o r i t Requirement P r i o r i t i z a t i o n -BO Subcontracting lnd«x l a b i a -tVCH Change tAC

Mater ia ls Management Baso data Mater ia ls Manageaont

-VWP Planning vorkbeich -20CP.01 <Jcps r i r s t MM-CBP Consuaption-Based Plannirg (See Also PP.MRP)

—OJ MM-PUR Purchasing MM-SRV External Services MM-IM Inventory Management MM - I V Invoice v e r i r i c a t i o n MM-IS In foraat ioo Systaa MM-EDI E lectronic Data Intercnarge MM-FT Foreign trade

LE l o g i s t i c s Execution QM Qual i ty Managomont PH Plant Maintenance CS Custcmer Service PP Production Planning and Control

—GJ PS Project System SCM Supply Chain Management

—Go EKS Environaent. Health and Sarety PLM Product Li recycle Management PA Porsonnal Managoaent PA-ER E-Recrui t ing PT Personnel Tine Management py Payroll PE Training and Event Management BV SAP Businoss Inroraat ion Varehc<jso

—CS KM Knowledge Manageaent BC Basis Coaponents A l l Auto-ID In f ras t ruc ture SV Service IS-MT Industry Solut ion High Tech SLL Global Trade Services IS-HER-CM Caapus Manageaent 01 Discrete I n d u s t r i a l

Figure 18.22 Application Hierarchy to Search for Exits in SAP Applications

• After selecting the A P P L I C A T I O N H I E R A R C H Y select R E P O S I T O R Y I N F O R M A T I O N

S Y S T E M by clicking on the I N F O R M A T I O N S Y S T E M button on the screen. This starts the Repository Information System browser, and the application wi l l let you search for any object within the selected application (see Figure 18 .23). Expand the E N H A N C E M E N T S subtree, select B U S I N E S S A D D - I N S . and then select D E F I N I T I O N S or I M P L E M E N T A T I O N S to search for the BADI defini-tion or implementation, respectively, within an application. The system offers you a selection screen that allows you to narrow down your search, or you can leave the fields on this screen empty i fyou want to see all of the BAdls within the component or packageyou have chosen.

546 Chapter 18 Enhancements and Modi f icat ions

R o p o i i t o r y I n f o S y * t o m : Firvd B A d t s

U 3

^ l ^ j a c t f AKtW* | o

cotteff tfct-^r Syvso 1 £ » c EV^HfrtJ » c A B / f t X t o ^ r , 1 c > t C»wK#ir r » » Q VSPUlWY » Cj * L. CttfKWTKCtt

tv.v-»M fc. I r W W O H

OCwfcnwt f lb ft B fk 1 1 .1 t*. t*c«icn

s t*-r>c*T*t»rc*e*«t*c«!i £ CCr f lW^D* ntwtJC X £ &t«X#T«r< Scott

» O > G Ce*rOto*n

8AJ Utrm

( r t m m M ^ t

#CC*C*<«Orpoa«t

L ^ c f ^ r v ^ j r v OngnJo*

O O W K P X U

A

a

x o

Figure 18.23 Repository Information System to Find BAdls

You can also use the above t e c h n i q u e to f i n d c u s t o m e r exi ts o r e n h a n c e m e n t

d e f i n i t i o n s o r i m p l e m e n t a t i o n s w i t h i n the A p p l i c a t i o n H ie ra r chy (these

enhancemen ts w i l l be discussed later i n th is chapter ) .

• Last ly, y o u can also use the re ference I M G to locate BAd I d e f i n i t i o n s f o r an

app l i ca t i on and c l ick o n the EXECUTE i con (($>) to create y o u r BAd I i m p l e m e n -

ta t i on (see F igure 18 .24) .

F M H M DwamwtOeBs M M M H M

%-jt t+ M M * UHK* tor Fwcm 4 <\»<

CrwB*

Ox t t

R T O M M

f \ f

C o f f M <3» M#rt»r N * * O o c w l i

CCrtMW

A«C*tA Htgrvr+f

$C ^ m e « > M P « c « M c t * » d tori C*»9cst*% D«*» CVol* v * » s T»c*

I H l U g l l

Sor t *

$<£*+**•< uavrwt C«KCvt» Krt j fCiKCMt « tf Oc*v* Qootfi) PifTW P w t n ; &.V*"* K V A * * D t t t T t r ^ CVrtt i«< t> Oc<u*wts PCrt* AiKrat tof l

v r v t f w w GAtf O i K l x t o X o t f f t j y U r t t c g C r y j v f v t f t f O ' S * F-M Ert«n; • PVx^vcg fH lO iM e w F W w i r t j C w m I * C u i »

Figure 18.24 BADI Implementat ion from SAP Reference IMC

Key Concepts Refresher Chapter 18 547

I m p l e m e n t i n g B u s i n e s s A d d - i n s

T o create B A d I i m p l e m e n t a t i o n s f o l l o w the m e n u pa th TOOLS • A B A P WORK-

BENCH • UTILITIES • BUSINESS ADD-INS • IMPLEMENTATION o r use T ransac t ion SE19.

As o f SAP N e t W e a v e r 7.0, the user in ter face f o r T ransac t ion SE19 has changed

because the re arc n e w BAd ls in a d d i t i o n to the o l d e r classic BAd ls ( those that w e

are d iscuss ing here ; f o r deta i ls o n n e w BAd ls , see the e n d o f th is chapter ) . Trans-

ac t i on SE19 a l l o w s y o u to create B A d I i m p l e m e n t a t i o n s f o r n e w a n d classic

B A d l s (see F igure 18 .25) .

BAdI Builder: Initial Screen (or Implementations I a c » o

EdtlaplNiiMMcn

• N w I M MKWMH<MlMMI

ocmacBM apwwatti

V CKdK J / O m

ONKIM Cnra^MSM

• CWK BM c m j n m *

Q CWklW

Figure 18.25 Implement ing 8usiness Add-Ins — Initial Screen

I f the B A d I y o u w a n t t o i m p l e m e n t is a classic BAd I , select t h e CLASSIC BADI rad io

b u t t o n , en te r the BAd I name, a n d c l ick o n the CREATE IMPL. b u t t o n . In the sub-

sequent d i a l og box en te r the BAd I i m p l e m e n t a t i o n n a m e ( w h i c h s h o u l d be in the

c u s t o m e r namespace), a n d en te r the sho r t i m p l e m e n t a t i o n tex t o n the nex t

screen (see F igure 18 .26) .

Doub le -c l i ck o n the in te r face m e t h o d that y o u w a n t t o i m p l e m e n t . Th is starts the

Class Bu i l de r ed i t o r , w h e r e y o u can inser t the des i red source code. The sys tem

au toma t i ca l l y creates a class ins ide w h i c h y o u r m e t h o d i m p l e m e n t a t i o n w i l l be

created ( you can see the class n a m e i n F igure 18.26) . A f t e r y o u have inser ted

y o u r code, y o u need to save the changes a n d act ivate the B A d I i m p l e m e n t a t i o n .

You can act ivate the B A d I i m p l e m e n t a t i o n by c l i c k i ng o n the ACTIVATE i c o n (fTD

o n the B A d I screen. Y o u r source code i n the m e t h o d w i l l be execu ted in the stan-

da rd SAP app l i ca t i on a f te r the B A D I is act ivated. Y o u can o n l y w o r k w i t h the data

supp l i ed by the m e t h o d parameters fo r e n h a n c e m e n t , w h i c h y o u de f i ne .

548 Chapter 18 Enhancements and Modifications

TpiKtwiaDon riyno KE_PURCHDOC_POSTEO m j ' i f t C M C O c ^ m i E D BAOI

Implementation Name

• x

Business Add-In Builder: Change Implementation ZME_PURCHDOC_POSTED "V £' • : ; , 2 U Of i r tKn Oocw»xU OoQtfnetaoon

knflWTMfttOcnNMne ZME_PURCHDOC_POSTEO »KSV* »iX*c*T>«ta6<o Snort Tort POBACI De*W<»N«» Kt.PURCHOOC.POSTEO

W f f f l ^ T ktwlaco

wert*enarv» IF_EX_HE_PtjRCtOOC .POSTED NafrwotifrcfenwrergclMt [ZCL.IMJIt JMRCHPQC J-QStEO '

K'«J»3 »r(4«roftit Doocntoon F l POSTEC' -i...'. • rwh.i.i-.)LV.'ir-MfUVf.vl Q .

BAOI implementing CUK

BAOI Method

Figure 18.26 BAdI Implementation

Implemen t ing M e n u E n h a n c e m e n t

You create the BAdI implementation and select the F C O D E S tab to select the menu exits. You can double-click on the button on the BAdI implementation screen and enter the function text, icon name, icon text, and info text for the function code + E X T E N S 1 as displayed in Figure 18.27.

Business Add-In Builder: Change Implementation ZCE_MON_EXIT1 I 7 9 <• 11 . " . A O CX<.r»T*.r

i t m n n a o i N n * r«J*>tl_r*ITi r « M sroi t»< M n E - ' w a ' w i ' W n ' l i K ' i

Cfn t tn Marr*

ASfjm

c t j t * _ E x m

CCPJtiJtMllOKIM •t«ie»31 UMi&*>-> t r j

BuutfA * » r u 1M v j r tearc tw f I/CITI Cco» •£AlE/fi' fn tnn, t t f ^> j t cnno«: i t c r w i a t M i • rx i fN t i

l i M c n i M [ | . . 1 ken nan*

k«»rt ^ r ^ ^ 1 T«» | •to M

• X

Figure 18.27 Menu Enhancement

Key Concepts Refresher Chapter 18 549

You have to i m p l e m e n t the a p p r o p r i a t e in ter face m e t h o d a n d p r o g r a m the ac t ion

y o u w a n t t o sys tem to p e r f o r m w h e n the m e n u i t e m is selected. F ina l l y , y o u have

to act ivate the i m p l e m e n t a t i o n . The m e n u e n h a n c e m e n t o n l y becomes v i s ib le

a f ter the B A d I i m p l e m e n t a t i o n is ac t iva ted.

I m p l e m e n t i n g S c r e e n E n h a n c e m e n t

For BAd I screen e n h a n c e m e n t y o u have to create y o u r o w n screen a n d w r i t e the

p r o g r a m f o r the screen by c rea t ing a m o d u l e p o o l o r f u n c t i o n g r o u p . You use the

BAd I in te r face m e t h o d to t rans fer the data f r o m the app l i ca t i on p r o g r a m to the

screen a n d v ice versa.

You have to create the B A d I i m p l e m e n t a t i o n f o r the screen e n h a n c e m e n t a n d

assign the cus tomer screen i n the SCR.No c o l u m n a n d the p r o g r a m n a m e u n d e r

PROGRAM CALLED c o l u m n as s h o w n i n F igure 18 .28 . Nex t , i t is i m p o r t a n t to

i m p l e m e n t the in te r face m e t h o d to t rans fe r the date b e t w e e n the app l i ca t i on a n d

the c u s t o m e r screen. F ina l l y , y o u have to act ivate the B A d I to i n c o r p o r a t e the

c u s t o m e r screen i n the SAP s tandard p r o g r a m .

Business Add-In Builder: Change Implementation ZBADI_DCC_SCREEN_151 j V fr ' 1 .*. fl U :«•'<-oiyiDOO/l*ta D«unefttK«1 nefcmwMOonMom* ZBADI_0CC_SCftEEN_151 hectr* rc4«T»rtaO on Sh*t T«4 Scr«oo Er#wr<«mo-t OtfntxoNarr* BWI.DCC.SCRf EH.151

ABibutos »WJO -A-' .'MlUiU

CUnog— ISCTWq ISXwcwoaw Owawai'ProgOTMlM jSaMo 1 SAPLLXDCC 1151 0CC_BA0I_151 A

n n

Figure 18.28 Screen Enhancement

E n h a n c i n g t h e A B A P D i c t i o n a i y

The re are t w o ways y o u can a d d ex t ra f ie lds to SAP s tandard tables w i t h o u t m o d -

i f y i n g that SAP tab le : SAP tables can be enhanced us ing e i the r an a p p e n d struc-

t u re o r a C u s t o m i z i n g Inc lude .

• Cus tomers can create an a p p e n d s t ruc tu re f o r a lmos t any SAP tab le o r struc-

t u re (see res t r i c t ions b e l o w ) . A p p e n d s t ruc tu res a l l o w y o u to enhance SAP

tables by a d d i n g cus tomer -spec i f i c f ie lds that are n o t par t o f the s tandard

app l i ca t i on , w i t h o u t m o d i f y i n g the table. A p p e n d s t ruc tu res are tab le spe-

550 Chapter 18 Enhancements and Modifications

cific; that is, one append structure can on ly belong to one table. However , a

table can have mul t ip le append structures.

Whenever a table is activated, the system searches for the active append struc-tures for that table and attaches them to the database table. Act ivat ing an append structure also activates the table to wh ich i t is assigned. You can use an append structure as a type in y o u r ABAP programs in the same way that y o u can w i t h any Dict ionary table or structure. The append structure is always added as the last fields o f the table.

The append structure is always created in the customer namespace. This pro-

tects it f r om being overwr i t ten dur ing upgrade. The field names in the

append structure must also be in the customer namespace and must begin

w i t h z z or y y . This prevents any naming confl ict w i t h the new SAP field

names that might be inserted in the future.

You cannot create append structures for pool or cluster tables. Also, y o u can-not create an append structure for a table that contains a long field such as the type l c h r o r l r a w because the long field should always be the last field in that table.

• Some o f the tables del ivered by SAP contain a special Include structure. These Includes arc called Customizing Includes, and y o u can add customer-specific fields to them. In contrast to append structures, Customizing Includes can be included in more than one table or structure, and i f y o u add a field in the include structure, i t w i l l automatical ly appear in all o f the tables or structures that have this Customizing Include. Customizing Include name begins w i t h CI. Just l ike append structures. Customizing Include field names must lie in the customer namespace, and the names must begin w i t h z z or y y .

O f course there is no point in having extra fields in y o u r SAP tables unless y o u can do something w i t h them. You have to enhance the standard SAP appl icat ion to populate the fields attached to the append structure or Customizing Include. The customer-specific fields can be populated using one o f the enhancement techniques discussed elsewhere in this chapter.

Enhancement Framework

As o f SAP NetWeaver 7.0, the Enhancement Framework al lows y o u to add func-t ional i ty to the SAP standard appl icat ion w i thou t actually changing the or ig inal reposi to iy objects. W i t h this new technology it is possible enhance global

Key Concepts Refresher Chapter 18 551

classes, funct ion modules, Web Dynpro ABAP components, and all source code

units using expl ici t enhancement opt ions and sections. You can also def ine addi-

t ional impl ic i t enhancement opt ions for source code plug-ins.

The Enhancement Framework consists of:

• Exp l ic i t enhancement po in ts

These are points that are posi t ioned in reposi tory objects in wh ich the cus-

tomer can add funct ional i ty in the f o rm o f source code w i t hou t making mod-

if ications. You define expl ici t enhancement opt ions, whereas y o u do not pre-

plan impl ic i t enhancement opt ions.

Explicit enhancement points are expl ic i t ly flagged source code points or sec-

t ions in ABAP programs and can be enhanced by the source code plug-ins.

They are implemented using the syntax ENHANCEMENT-POINTS.

• Exp l ic i t enhancement sect ion

These a l low y o u to replace source codc in SAP programs, funct ion modules,

and methods w i t hou t making modif icat ions. The replaceable SAP source code

is enclosed by the statements ENHANCEMENT SECTION and END-ENHANCEMENT

SECTION.

• I m p l i c i t enhancement po in ts

These are always available to the customer, and they can be used to insert

source code in programs, funct ion modules, and methods w i thou t making

modif icat ions. They are also available fo r SAP objects developed before SAP

NetWeaver 7.0.

• Enhancement op t i ons

These a l low y o u to enhance interface parameters for SAP funct ion modules

and class methods w i t hou t modi f icat ion. You can also add addi t ional

attr ibutes and methods to SAP classes. Enhancement opt ions are always avail-

able and can be used by customers to enhance SAP appl icat ion. They arc also

available for SAP objects developed before SAP NetWeaver 7.0.

• New BAdls

For SAP NetWeaver 7.0 SAP implemented new BAdI technology and intends to use it fo r future enhancement. The new BAdI technology works in the same way as the classical BAdI, bit the adapter call is no longer required. Instead, the new BAdI technology uses the new language elements GET BADI and CALL BADI. Similar to classical BAdls, new BAdls prov ide y o u the enhancement for program, screen, and menu exits. To use the BAdls y o u have to implement the enhancement implementat ion via Transaction SE19.

552 Chapter 18 Enhancements and Modifications

The system generates the BAdI handle in the kernel at the runt ime o f the

appl icat ion program. List ing 18.1 shows the new BAdI call in the standard

SAP appl icat ion.

DATA l f_badi_me_conf TYPE REF to /spe/cd_me_conf i rmat ion . TRY.

GET BADI 1f_bad1_me_conf. CATCH cx_badi_not_implemented.

CATCH. TRY

CALL BADI 1f_badi_me_conf->change_ibtyp EXPORTING

i t _ l i k p - x l i k p [ ] i t _ l i p s - x l i p s [ ] 1t_vbpa - xvbpa[ ]

CHANGING cv_ ib t yp - l f a r t _ b e s t t y p cv_no_po_update - l f_no_po_update.

CATCH cx_badi_ i n i t i a 1 . re fe rence . CATCH.

Listing 18.1 New BAdI Call in Standard SAP Application

The new BAdI handle is generated by the statement GET BADI by specifying

the reference variable. The exception CX_BADI_NOT_IMPLEMENTED is tr iggered

i f no active implementat ion o f the BAdI is found. The CALL BADI statement

calls the method corresponding to the BAdI handle der ived f r om the GET BADI

statement. The system triggers CX_BADI_INITIAL_REFERENCE i f the CALL BADI

statement is called w i t h an in i t ia l reference to the handle.

You can search the new BAdI de f in i t ion by searching for the GET BADI str ing

in the appl icat ion program. You can also search for new BAdls by using the

Repository In format ion System or the Appl icat ion Hierarchy w i t h the Repos-

i tory In fo rmat ion System.

• Enhancement spots These are containers for expl ic i t enhancement opt ions. Enhancement sec-tions add new BAdls and carry in fo rmat ion about the posit ions at wh ich enhancement points or BAdls were created. Enhancement spots ei ther con-tain new BAdls or expl ici t enhancement sections and enhancement sections. One enhancement op t ion can manage several enhancement opt ions or BAdls o f a reposi to iy object, or alternatively, several enhancement spots can be

Key Concepts Refresher Chapter 18 553

assigned to one enhancement opt ion. Impl ic i t enhancements do not need to

be assigned to enhancement spots.

• Composi te enhancement spots

These contain one or some simple or composite enhancements. They are used

to semantically bundle s imple or composite enhancement spots.

Modification

A n object can be or ig inal in one system on ly . For the SAP system the or iginal sys-tem is s a p itself. In customer system s a p objects are available as copies. Your development system is the or ig inal system for the objects created on it. The objects created in y o u r development system are assigned to development or cor-rect ion requests i f they are assigned to the package. The transport request is used to transport the development object f r om the development system to the subse-quent systems. Changes to the or ig inal are assigned to the correct ion change request, and the change to the copy (an object that is not developed on the sys-tem where i t is being changed) is assigned to the repair change request.

You should not change the s a p object unless the modi f ica t ion y o u want is abso-lutely necessary and cannot be implemented by the available enhancement tech-niques. When y o u upgrade y o u r system or apply a support package, confl icts can occur w i t h mod i f ied objects. These confl icts occur i f y o u have modi f ied an s a p object and SAP has del ivered a new version o f the object. The new object del iv-ered by SAP becomes an active object in y o u r system, and i f y o u want to keep y o u r changes, y o u have to carry out a modi f ica t ion adjustment for the object. The modi f icat ion adjustment should always be carried out in the development system and then transported to the subsequent systems.

To change the Sap object y o u require an access key. You have to get the access key f r om the SAP Service Marketplace (http://service.sap.com) and register the object y o u are changing. The access key is also referred to as SAP Software Change Registration (SSCR). A l l objects that arc being changed arc logged by SAP. This helps SAP support qu ick ly locate and f ix the prob lem i f i t is as a result o f modi -fication o f the Sap standard object. SAP recommends that y o u use the Modi f ica-t ion Assistant to mod i f y standard s a p objects, but y o u can switch Mod i f i ca t ion Assistant i f required. Mod i f i ca t ion Assistant makes the modi f icat ion easier and al lows y o u to reset the modi f icat ion.

554 Chapter 18 Enhancements and Modifications

Modification Browser

The Modification Browser provides you an overview of all of the changes made in the system. The Modification Browser differentiates between modifications made using the Modification Assistant and those made without it. Modification Browser can be started by calling Transaction SE95, and you can restrict object selection according to various selection criteria on the initial screen (see Figure 18.29).

I Modification Browser: Object selection I Q D

Selections Last changed by Last Transport Request Package Requesflask

J f f f l ^ f f l Reset Qtjects Display Options Options

Modified Ofcjects and Enhancements fa) Correcoons in SAP Note fa) With Modification Assistant fa) Without Modification Assistant • Translations fa) Business Add-Ins fa) Appends •Other objects

Figure 18.29 Modi f icat ion Browser

Modification Browser can also be used to reset or undo the modification made in the system.

SAP Notes Assistant

The SAP Notes Assistant is used to implement SAP Notes, which are corrections to objects in the SAP system. Before the SAP Notes Assistant was introduced, sys-tem administrators had to apply the SAP Notes manually with the help of the developer. This increases the likelihood of errors. Without the SAP Notes Assis-tant, you would have to enter a registration key for the object before you can change it.

Practice Questions Chapter 17 555

W i t h SAP Notes Assistant, y o u no longer need to enter the registrat ion key. SAP Notes Assistant automatical ly imports the correct ion w i thou t the Mod i f i ca t ion Assistant. You no longer have to maintain the source code manual ly, thereby sav-ing t ime and reducing the l ike l ihood o f errors. Notes Assistant downloads the notes automatical ly f rom the SAP Service Marketplace direct ly using an RFC con-nect ion and reads the correct ion before apply ing the notes to the system. Notes Assistant also recognizes the dependencies between di f ferent notes. The system checks for the prerequisites and dependencies for other notes. I t ascertains whether a note has a prerequisite note w i t h it, and loads the prerequisite note i f there is one. It displays the list o f prerequisites in the dialog box, and y o u imple-ment the note in the correct order as displayed in the list. You have the opt ion to implement all o f the selected notes at once, o r y o u can imp lement each note ind iv idua l ly . You also have the opt ion to undo the note implementat ion i f i t has been implemented w i t h Notes Assistant.

% Practice Questions The practice questions be low w i l l help y o u evaluate y o u r understanding o f the topic. The questions shown are simi lar in nature to those found on the certifica-t ion examinat ion, but whereas none o f these questions w i l l be found on the exam itself, they a l low y o u to review y o u r knowledge o f the subject. Select the correct answers and then check the completeness o f y o u r answers in the fo l low-ing solut ion section. Remember that y o u must select all correct answers and on ly correct answers to receive credit for the question.

1. W h i c h o f the fo l l ow ing is a true statement?

• A. A n access key is required to implement Business Add-Ins.

• B. An access key is required to mod i f y SAP reposi to iy objects.

• C. An access key is required to enhance an SAP appl icat ion using a user exit.

• D. An access key is required to implement an impl ic i t enhancement po in t .

2. SAP enhancement for customer exits are managed by transaction:

• A. Transaction S M O D

• B. Transaction C M O D

• C. None o f the above

570 Chapter 18 Enhancements and Modif icat ions

3. Customer exi ts p rov ide p rog ram exi t , screen ex i t , and menu ex i t enhance-

ment .

• A. True

• B. False

4. The CALL CUSTOMER-FUNCTION ' n n n ' s tatement , w h e r e nnn is a three-d ig i t

n u m b e r is used in SAP programs fo r one o f the f o l l o w i n g types enhance-

men t .

• A. Customer exi ts

• B. Business Add- Ins

• C. User exi ts

• D . N e w BAdls

5. H o w w o u l d y o u find ou t i f an app l ica t ion p r o g r a m of fers a p rog ram exit?

• A. Search for the character s t r ing CUSTOMER- FUNCT ION.

• B. Use the Reposi tory I n f o r m a t i o n System.

• C. Use the App l i ca t i on Hierarchy.

• D . Look fo r a cus tomer ex i t i n the SAP reference I M G w i t h i n an app l ica t ion

area.

6. A Business Add- Ins can have m u l t i p l e act ive imp lemen ta t i ons at a t ime.

• A . I t can have m u l t i p l e act ive imp lemen ta t i ons i f the MULTIPLE USE checkbox

is selected.

• B. It cannot have a mu l t i p l e act ive imp lemen ta t i on .

• C. It can have mu l t i p l e imp lemen ta t i ons i f the FILTER-DEPEND, checkbox is

selected.

7. The statement CALL BADI and GET BADI is used fo r f o l l o w i n g type o f Busi-

ness Add- Ins :

• A . Classical BAdI

• B. N e w BAdI

• C. None o f the above

Practice Questions Chapter 17 557

8. Expl ici t enhancement points and sections are def ined by the SAP appl icat ion programmer.

• A. True

• B. False

9. Code w i t h i n an expl ici t enhancement section can be replaced by the cus-

tomer.

• A. True

• B. False

10. Code w i t h i n an expl ici t enhancement po in t can be enhanced but cannot be replaced.

• A. True

• B. False

11. W h i c h o f the fo l l ow ing are correct statements:

• A. A n enhancement spot can contain expl ici t an enhancement po int and an enhancement section.

• B. A n enhancement spot can contain an expl ic i t enhancement point , expl ic i t

enhancement section, and new BAdI.

• C. A n enhancement spot can contain either an expl ici t enhancement po int and enhancement section or a new BAdI on ly , but all three cannot be in the same enhancement spot.

• D. A n enhancement spot can contain one or more simple or composite enhancements.

12. Wh ich o f the fo l l ow ing is a true statement:

• A. An impl ic i t enhancement po int can be used to insert code in an SAP pro-

gram and is always available to the customer.

• B. Impl ic i t enhancement opt ions a l low y o u to enhance interface parameters

for funct ion modules and methods w i thou t mod i f y ing the reposi to iy object.

• C. Impl ic i t enhancement can be used to enhance SAP objects developed pr io r to SAP NetWeaver 7.0.

• D. None o f the above

558 Chapter 18 Enhancements and Modifications

Practice Question Answers and Explanations 1. Correct answers: B, C

These answers are correct fo r the fo l l ow ing reasons:

• A n access key is not required to implement Business Add-Ins because y o u prov ide the Business Add- In def in i t ion for the customer or partner to insert addi t ional funct ional i ty for the appl icat ion.

• A n access key is required to mod i f y SAP reposi tory objects. You need to register the repository object in the SAP Service Marketplace to generate the object key and have to enter it to mod i f y the reposi to iy object.

• A n access key is required to enhance user exits because technically, user exit implementat ion is the system modi f icat ion. User exits are included in the special Include program that is attached to the module pool program. SAP does not del iver any new version o f Include, so user exit enhancement does not impact the upgrade even though it 's a modi f icat ion o f the SAP reposi to iy object.

• Impl ic i t enhancement does not require an access key. It 's an enhancement that does not mod i f y the SAP reposi to iy object.

2. Correct answer: A

SAP manages customer exist enhancement via Transaction SMOD. Transac-

t ion C M O D is used to manage customer enhancement projects.

3. Correct answer: A

Customer exits provide program exit, screen exit, and menu exit enhance-ment .

4. Correct answer: A

You use the CALL CUSTOMER-FUNCTION 'nnn* statement to def ine a customer

exit w i t h an SAP appl icat ion. You also create funct ion modules and groups in

the system, but y o u w o u l d have to insert addi t ional funct ional i ty w i t h i n the

funct ion module as a part o f customer exit implementat ion via SAP Transac-

t ion C M O D .

5. Correct answers: A, B, C, D

You search for a customer exit by searching for the character str ing CUSTOME R

FUNCTION or via the Repositoiy In format ion System, Appl icat ion Hierarchy,

or SAP Reference IMG.

Practice Question Answers and Explanations Chapter 17

6. Correct answers: A, C

Business Add-Ins can have mul t ip le implementat ions i f the MULTIPLE USE

checkbox is selected. A Business Add- In can have mul t ip le implementat ions.

one for each f i l ter value, i f the FILTER-DEPEND, checkbox is selected.

7. Correct answer: B

The CALL BAOI and GET BADI statements are used for new BAdI as o f SAP

NetWeaver 7.0.

8. Correct answer: A

Explici t enhancement points and sections are def ined by the SAP appl icat ion

programmer.

9. Correct answer: A

Code w i t h an expl ic i t enhancement section can be replaced by customer.

10. Correct answer: A

Code w i t h i n an expl ic i t enhancement po int can be enhanced.

11. Correct answers: A, C, D

These answers are correct for the fo l l ow ing reasons:

• Enhancement spots can contain one o r more expl ici t enhancement points

and expl ici t enhancement sections.

• Enhancement spots cannot have expl ic i t enhancement points, expl ic i t sec-tions, and new BAdls together. They can have one or more expl ic i t enhancement points and expl ic i t sections or one or more new BAdls.

• Composite enhancement spots can have one or more enhancement spots

o r composite enhancement spots.

12. Correct answers: A, B, C

These answers arc correct for the fo l l ow ing reasons:

• Impl ic i t enhancement points are used to insert addi t ional code w i t h the

SAP program w i thou t mod i f y ing the appl icat ion.

• Impl ic i t enhancement opt ions are used to enhance the interface parame-

ters for funct ion modules and methods.

• Impl ic i t enhancement points and opt ions are available for SAP objects

developed pr io r to SAP NetWeaver 7.0. Impl ic i t enhancement po int and

opt ions are always available to the customer and can be used to enhance

SAP applications w i t hou t modi f icat ion.

574 Chapter 18 Enhancements and Modifications

Take Away You should be able to explain various enhancement techniques such as user exits, customer exits, Business Add-Ins, and enhancement techniques in SAP NetWeaver 7.0. You should be able to explain the features o f each o f the above enhancement techniques and be able to use them to enhance SAP applications.

You should k n o w the tools used to implement customer exits such as program exits, menu exits, and screen exits to insert y o u r o w n funct ional i ty . You should understand the dif ference between Transactions SMOD and C M O D . Simi lar ly, y o u should be able to create BAdI enhancements, both the classical BAdls and new BAdls.

You should understand the tools and techniques to search various enhancements

for SAP applications. You should be able to use the Appl icat ion Hierarchy w i t h

the Repository In fo rmat ion System to search for customer exits, Business Add-

Ins, composite enhancements, or enhancement spots for an appl icat ion object.

Finally, y o u should be able to explain the di f ference between enhancement and

modi f icat ion. You should k n o w the tools to list the system modi f icat ion in y o u r

system and be able to use SAP Notes Assistant to apply notes to the SAP system.

Caution

You should try not to modify SAP objects unless it is absolutely required because modification can cause problems during upgrade. You should try to adjust the SAP objects by using one of the enhancement techniques and only modify the system if SAP has not provided you with one of the enhancement options to adjust the standard SAP objects.

Refresher

Table 18.1 shows the key concepts for enhancing SAP applications.

Key Concept Definit ion

Enhancement Enhancement techniques are used to insert additional customer-concepts specific functionality to SAP applications without modifying SAP

repository objects.

Table 18.1 Key Concept Refresher

Summary Chapter 17 575

Key Concept Def in i t ion

Enhancement The Appl icat ion Hierarchy too l (Transaction SE81) along w i th the

search too l Repository Informat ion System (Transaction SE85) can be used t o

search for SAP enhancement defini t ions w i t h the appl icat ion

component .

Enhancement The Enhancement Informat ion System is a too l to search for

Information Sys- enhancement defini t ions and implementat ions in the SAP system,

tem

SAP Notes Assis- SAP Notes Assistant is the too l used to implement SAP notes in

tant the system.

Modi f icat ion Modi f icat ion Browser is used to list the repository object that has

Browser been modif ied w i th the system. The too l can also be used t o reset

the modif icat ion for the repository objects.

Enhancement User exits, customer exits, classical Business Add-Ins. and BTEs

techniques are some of the enhancement techniques used prior t o SAP

NetWeaver 7.0 to enhance SAP applications w i thou t modi fy ing

SAP repository objects.

Enhancement As of SAP NetWeaver 7.0 new enhancement opt ions such as

Framework explicit enhancement points, explicit enhancement sections,

impl ic i t enhancement points and options, and new BAdls are

available t o enhance SAP applications.

Table 18.1 Key Concept Refresher (cont.)

Summary

You should know the various enhancement techniques and the steps to imple-ment enhancements. You should know the techniques and tools used to search the SAP enhancement definition for a business application. You should also know the difference between enhancement and modification. You should be aware of the tools used to modify repository objects and the procedure to modify repositoiy objects. You should be familiar with the tools used to list the modified object within the system such as the Modification Browser. Finally, you should know about SAP Notes Assistant, its use and benefits, and the ease with which it can be used to implement notes in the system. This knowledge will allow you to easily pass this topic on the certification examination.

Table Relationships

Techniques You'll Master:

• Reference data elements

• Explore search help design

• Check table en fo rcement

• Unders tand text tables

564 Chapter 19 Table Relationships

In this chapter y o u w i l l be prov ided w i t h a basic understanding o f h o w tables

relate to other objects in the ABAP Dic t ionaiy . We w i l l discuss data elements and

the capabilit ies they provide. We w i l l cover the use o f foreign keys for check

tables and text tables. We w i l l cover value help design and the mechanisms fo r

attaching a search help to d i f ferent D ic t iona iy objects.

Each o f these topics w i l l be covered separately and w i l l be fo l lowed by the prac-

tice exercise and the so lut ion to the exercise.

Real-World Scenario

Your project has a number o f issues w i t h restr ict ing the contents o f screen

fields to specific values. You need to ident i fy w h y this is happening and

how to correct the issues.

You k n o w that part o f the prob lem is that team members are not sure what

data is actually available, but some o f the prob lem is s imply that some

developers have not implemented value checks.

You w i l l need to ident i fy where help is needed in determin ing available

values and where value checks need to be implemented. In both cases y o u

w i l l need to explain to other developers the opt ions available and assist

them in imp lement ing ei ther the value check or the search help.

Objectives of this Portion of the Test The purpose o f this por t ion o f the cert i f icat ion examinat ion is to ver i l y that y o u have knowledge o f the ABAP Dic t iona iy and the relat ionships between di f ferent tables. This po r t i on o f the examinat ion w i l l test y o u r knowledge o f details related to data elements, inc lud ing how they can be used and what capabilit ies exist w i t h data elements. The points that y o u w i l l need to understand f r om this section include:

• Enforcement o f checks for screen f ie ld

• The dif ference between a value table and a check table

• Di f ferent uses o f foreign keys

• The use and design o f search helps

Key Concepts Refresher Chapter 18 579

The cert i f icat ion examinat ion w i l l give average weight to this chapter compared

to the other topics in the examinat ion. This means there w i l l be an average per-

centage o f questions related to this chapter. Understanding table relationships

makes y o u a better developer. A l though it is not necessaiy fo r all types o f devel-

opment (being strongly related to dynpros), it is nevertheless a necessaiy part o f

y o u r understanding in order to become cert i f ied.

Key Concepts Refresher You need to understand and be able to per fo rm the fo l l ow ing types o f tasks

when developing ABAP programs:

• Enforce field value checks dur ing screen processing

• L ink tables through foreign keys

• Implement search helps

Table Relationships

The ABAP Dic t iona iy supports program development w i t h a number o f services:

• Value helps (F4 help) for screen fields can be def ined w i t h search helps or by assigning fixed values to domains.

• Screen fields can have field help (F l help) assigned by creating documenta-

t ion for the data element beh ind the screen field.

• A n input check that ensures that the values entered are consistent is def ined for screen fields through the use o f foreign keys.

• The ABAP Dic t iona iy provides support for y o u to set and release locks. To do

this, y o u must create lock objects in the ABAP Dict ionary. The funct ion mod-

ules to set and release locks are automatical ly generated when the lock object

is activated. These funct ion modules can then be used in the appl icat ion pro-

gram (see Chapter 8, SQL Statements Inc luding Update Strategies, for details).

• Buffer ing settings can improve performance when accessing data in database

tables and views.

• You can enable the automatic recording o f changes to table entries to a change

log.

566 Chapter 19 Table Relationships

Data elements prov ide a complete descr ipt ion o f a field in the ABAP Dict ionary or an e lementaiy data object in y o u r ABAP applications. They provide the l ink between domains and the data objects and contain semantic and technical infor-mat ion about the data objects. The technical in fo rmat ion typical ly comes f r om a domain, i f one is def ined. However , it is possible to def ine the technical attr ibutes, such as type and length, direct ly w i t h i n the data element. Def in ing the technical attr ibutes w i t h i n the data element direct ly, instead o f using a domain, prevents the use o f fixed values or value tables for the field that can on ly be def ined at the domain level, and therefore it is recommended that a domain be used.

You can (and should) maintain the field labels for data elements y o u create. These field labels (short, med ium, long, and heading) can be displayed later on screens or selection screens to explain or describe the field's purpose. On selection screens, on ly the long version o f the field label can be d rawn f rom the ABAP Dic-t ionary, but w h e n designing y o u r o w n screens using the Screen Painter, y o u can choose. I f y o u are creating y o u r o w n data element, y o u can (and again should) also add documentat ion to the data element. This documentat ion is automati-cally displayed anyt ime a user presses the I Fl I key w i t h the cursor in a field that references the data element. Standard fields also provide the abi l i ty to add sup-plemental documentat ion i f the field is used uniquely for this customer's system.

I f the field value is prov ided in a search help list, the en t i y f r om the field label is used for the t i t le. These labels are also used in ALV displays (see Chapter 15, ALV Gr id Control) as default headings for columns. You can specify a length for the respective field label, a l though i f i t is left empty, the d ic t ionary calculates the length based on ei ther predef ined l imi ts (10, 15, and 20) or the actual length i f i t is greater than the predef ined l im i t . This length determines the max imum length for the field label. I f y o u w o r k for a global company, y o u can translate the field labels in to other languages (GOTO • TRANSLATION or Transaction SE63). When specifying the length, remember that in another language, the same term in the field label might require more letters.

A search help (value or F4 help) can be appended or attached to a data c lement.

In addi t ion, search helps can be attached to other objects such as table fields,

structure fields, or check tables (see Figure 19.7 be low for details).

In d i f ferent applications, y o u sometimes have to enter a part icular value in sev-

eral screens, for example, a company code or customer number . To save the user

having to enter the same value over and over again, it is possible to assign a

Key Concepts Refresher Chapter 18 567

parameter ID to the data element behind those screen fields (see Figure 19.1). I f a screen field is based on a data element w i t h a parameter ID. the value the user enters in this field can be transferred to the parameter ID. that is, stored in mem-o iy . when the screen is exited. I f an input field based on the same data element exists on a subsequent screen, this value can be read f r om the parameter and dis-played in the screen field automatical ly and can be changed by the user. The s e t / g e t parameters ho ld the value per user session.

D M element kuknR a i i m Short Oescrtptton Customer Number 1

Aflributes Datatype A field Label

Search Help

Name C KUNN*

Parameters KUNNR

Parameter C KJ18

Default Corr*>onenl Name CUSTOKR

8 t Directorial Opbons

Figure 19.1 Parameter ID

Af ter the user has logged of f , these values are not retained. These parameters can also have permanent values assigned through the user prof i le , so i f a user on ly deals w i t h one company code, he w o u l d never need to actually type in the com-pany codc ( in this case the value is retained between sessions). To use a s e t / g e t parameter for a field y o u created, y o u have to enter this in table t p a r a ; in other words, y o u have to create the parameter memory ID.

The technical propert ies fo r the data element are maintained on the DATA TYPE tab page. You should use main ly domains for technical typ ing, in other words, to give the data element its technical characteristics. However, y o u can also define the data element using the same integrated types that are used to define the domains. As a special case, y o u can also create a data element as a reference type. The referenced type is not restricted here to the type d a t a e l e m e n t . It can be any other reference type or even a generic reference to a n y , o b j e c t , or d a t a .

568 Chapter 19 Table Relationships

N o t e

A reference o f t h e t ype a n y can p o i n t t o b o t h ob jec ts and data. The d e f i n i t i o n as

a re ference is t h e same as t h e t ype dec la ra t ion in an ABAP p r o g r a m t y p e s t r _ d t

t y p e r e f t o da ta .

The domain describes the value range of a field by specifying its data type and field length. If only a limited set of values is allowed, these can be defined as fixed values (see Figure 19.2 for an example).

Domain KKBJttPORTYPE Aclwe

Snort Oescnptcn Report Types ftx Report Tree*

4 I I Sn»jiev»i« Fnv>i IsftOrt 0»«rtpt

Report RV Report W<er Report R£ Of Mown Repoiflng 88 Report Porttoao Report 1R Transacton AO Ooenr .$ Fc*m

Figure 19.2 Fixed Values

Specifying fixed values causes the value range of the domain to be restricted by these values. Fixed values can be immediately used as check values in screen entries and for value help. Fixed values can either be listed individually or defined as an interval.

The value range of a field can also be defined by specifying a value table (see Fig-ure 19.3) in the domain. Unlike fixed values, however, simply specifying a value table does not cause the input of a screen field with this domain behind it to be checked, and there is no value help.

N o t e

If y o u en te r a value tab le fo r a d o m a i n , t h e system can make a p roposa l fo r t h e

fo re ign key de f i n i t i on fo r any tab le f ie lds w i t h th is d o m a i n beh ind t h e m .

Key Concepts Refresher Chapter 18 569

Domtff KUHftR A c t *

SftorlOoscrtpfeon Customer numbar

Properties tXnibon

I -I I I I J

I fnVal |SftottOcscnpt

W*rta IS

Low*»im< luppertjmti [snort Oestnpl

B B I value Table I B M

Figure 19.3 Value Table

In the ABAP Dict ionary, this type o f relat ionship between two tables is called a

foreign key relat ionship, and the tables must be def ined expl ic i t ly for the field.

Foreign keys are used to ensure that the data is consistent. Data that has been

entered on a screen is checked against exist ing data in the check table to ensure

that it is consistent. This check does not prevent a program f rom direct ly updat-

ing the database table w i t h an incorrect value. The check is part o f the screen pro-

cessing. not the database interface.

Note

A value table only becomes a check table when a foreign key is defined. If you have a field based on a domain with a value table, but no foreign key was defined at the field level, there is no check for the screen field.

A combinat ion o f fields in a table is called a foreign key i f this field combinat ion

is the pr imary key o f another table. A foreign key l inks two tables. The check

table is the table whose key fields are checked. This table is also called the refer-

enced table. The example in Figure 19.4 shows the table VBRK (in abbreviated

fo rm) w i t h a foreign key relat ionship to k n a 1 .

570 Chapter 19 Table Relationships

Let's say an entry is to be wr i t t en in the foreign key table. This en t i y must be consistent w i t h the key fields o f the check table. In other words, the value y o u want to insert must exist already in the check table. The field o f the foreign key table to be checked is called the check field. Cont inu ing our current example, the cl ient and customer numbers are the check fields. Foreign keys can on ly be used in screens. You are able to either insert or change data records in the database table w i thou t this being checked using an ABAP program, in other words, i f y o u do not go through screen validations. There is no way to automatical ly enforce this check in a program. A program must implement the check table val idat ion w i t h i n the program itself.

W h e n y o u are mainta in ing foreign keys, domain equal i ty is mandatory for check table enforcement. In o ther words, the same domain is required for the check field and referenced key field o f the check table so that y o u do not compare fields w i t h d i f ferent data types or field lengths. Di f ferent data elements can be used, but they must refer to the same domain . The requirement for domain equal i ty is on ly necessaiy for the check field. For all other foreign key fields, it is suff ic ient i f the data type and the field length are equal. As a recommendat ion, y o u should always t i y for domain equal i ty because it always simpli f ies making domain changes later, for all development not j us t fo r check tables. In this case, the for-eign key w i l l remain consistent i f the field length is changed because the corre-sponding fields are both changed. I f the domains are d i f ferent , the foreign key w o u l d be inconsistent, for example, i f the field lengths were changed. This

Key Concepts Refresher Chapter 18 571

domain equal i ty also means that a check table can on ly be used fo r f ields that use

a domain to obtain their technical attr ibutes.

Note

The system can automatically propose the check table for the check field if the domain has a value table. In this case, a proposal is created for the field assign-ment in the foreign key.

The cardinality describes the foreign key relat ionship w i t h regard to the number o f possible dependent records (records o f the foreign key table) and the refer-enced records (records o f the check table). The cardinal i ty is always def ined f r om the point o f v iew o f the check table. The cardinal i ty is def ined as n :m, the left side o f the cardinal i ty describes the number o f records o f the foreign key table. v b r k in our example above, and the r ight side o f the cardinal i ty describes the number o f records o f the check table or k n a 1 .

• There are two values for the left side: ei ther 1 or C. The 1 indicates that there

must be a match in the check table o f one record, whereas the C indicates that

the match does not need to exist in the check table.

• There arc four values for the r ight side o f the cardinal i ty: 1, C, N, or CN. The 1

indicates that there must be exactly one record in the foreign key table, C indi-

cates there can be 0 or 1 records, N indicates 1 or more records, and CN indi -

cates there can be any number o f records.

The actual cardinal i ty for our example is 1 :CN, wh ich indicates that eve iy value

in v b r k must exist in k n a l once, and a value in k n a i can exist 0 or more times in

v b r k .

The types o f the foreign key fields describe what the foreign key fields in the for-

eign key table mean. The fo l l ow ing types o f foreign key f ie ld can be def ined:

• No key fields The foreign key fields are not p r ima i y key fields o f the foreign key table and they do not uniquely ident i fy a record o f the foreign key table. As a result, the foreign key fields do not ident i fy the foreign key table.

• Key f ie lds

The foreign key fields are ei ther p r imary key fields o f the foreign key table or

they already uniquely ident i fy a record o f the foreign key table. The foreign

key fields therefore ident i fy the foreign key table.

572 Chapter 19 Table Relationships

• Key fields of a text table The foreign key table is a text table for the check table. This means the key of the foreign key table differs from the key of the check table only in that it has an additional language key field. This is a special case of the type key fields.

N o t e

On ly one text table can be l inked w i t h a tab le.

If you have two tables - we will use the flight tables SMEALT and SMEAL for our example - SMEALT is a text table of SMEAL if:

• The key of SMEALT comprises the entire key of SMEAL and

• SMEALT has an additional language key field (field of data type LANG)

SMFALT can then contain text in several languages for each key entry of SMEAL.

To link the key entries with the text, the text table (SMEALT) must be linked with SMEAL using a foreign key. An example of this foreign key can be seen in Figure 19.5. Key fields of a text table must be selected here for the type of foreign key fields.

Its-Oispiay Foreign Key s w e a l t m e a l n u m b e r i

Short lei! Check tor cotrecl meatt

Check table SHEW.

Foreign Key FieUs

[Check table jcwtTabiFM SHEAL RAHDANT

:or fcev table [Foreign Key Field s h e ALT HAWDANT

Oenenc [Constant

SHEAL CARS 10 SJ1EALT C Aft ft 10 SHEAL REALNUH6ER SJ1EALT HEALHUH6ER

m m i ™ = = = |

Screen check

Error message WsgNo AArea

ScmanOc aft-ibutos

Foreign key field frpe

Cardinality 1 : CN

Figure 19.5 Linking a Text Table

Key Concepts Refresher Chapter 18 573

I f table SMEAL is the check table o f a field, the exist ing key entries o f table SMEALT w i l l be displayed as possible input values when the value help ((TT)) is selected. The explanatory text (contents o f the first character-like non-key field o f text table SMEALT) is also displayed in the user's logon language for each key value in table SMEAL. On ly one text table can be created fo r table SMEAL. The system checks this when y o u attempt to activate a table w i t h text foreign keys for table S M E A L .

Value Help

Value help ( input help or F4 help) is a standard funct ion o f an SAP system. It dis-

plays for a user the list o f possible values for a screen field. The user can select a

value f r om the list, wh ich is then copied direct ly to the input field.

The value help but ton is shown to the r ight o f fields that have value help (to see

an example o f this key, Figure 19.5 above contains one on the check table field).

The key appears when the cursor is posi t ioned w i t h i n the screen field. The help

can be started by ei ther choosing this but ton for the screen element or using the

funct ion key I F4 I.

I t is o f ten possible to fur ther filter the list o f possible entries shown through the

use o f fur ther restrictions, depending on h o w the help was def ined. The display

o f the possible entries is enhanced w i t h fur ther useful in format ion about the dis-

played values such as the descript ion. Given that the descript ion o f the value help

for a field is usually def ined by its use. the value help fo r a field is typical ly

def ined w i t h i n the ABAP Dic t ionaiy . A search help def in i t ion contains the infor-

mat ion the system needs to satisfy the described requirements.

To def ine the search help, y o u need to specify where to get the data ( f rom the

selection method), what is passed to and f r om the search help (the search help

interface), and the behavior o f the dialog. The search help interface dictates

wh ich values already entered by the user are passed to the search help and what

values are copied back to screen when a value is selected. The internal behavior

o f the search help describes the selection method, de te rmin ing wh ich values are

to be displayed and the dialog behavior w i t h the user.

A user can on ly access a search help through a screen, in other words, for one o f

the input fields on that screen. Wh ich search help is available is determined by

the search help attachment; search helps can be attached to table fields, structure

574 Chapter 19 Table Relationships

fields, data elements, or check tables. The edi tor for search helps enables y o u to

test the behavior o f a search help w i thou t assigning it to a screen field.

A selection f r om the database at run t ime determines the field's possible values for display. W h e n y o u def ine a search help, y o u must define the database object f r om wh ich the data is selected. You do this by specifying a table or a v iew as the selection method.

• I f the data to be displayed to the user in the search help is contained in j us t one table or in one table and its corresponding text table, y o u use the table as a selection method. I f the data for the search help is located in mul t ip le tables, it makes sense to use a v iew as the selection method. The system w i l l automatical ly ensure that values are restricted to the user's logon cl ient and language.

• I f a v iew does not exist contain ing the in format ion necessaiy for the value help, y o u must first create one in the ABAP Dic t iona iy . It is not possible to use maintenance views as the selection method fo r search helps. Normal ly , a database v iew is used, but w i t h i n an SAP system these are always created w i t h an inner j o i n . The value help therefore on ly offers those values w i t h an entry in each o f the tables. I f y o u need to have the possible values determined w i t h an outer j o i n , y o u should choose a help v iew as the selection method.

The possible values are presented in list format in the dialog box f r om wh i ch the

user can select the required en t i y . I f the possible values are formal keys, y o u

should prov ide fur ther in fo rmat ion in the display. For example, instead o f a list

o f customer numbers, the customer name should also be included.

I f y o u expect a ve i y large h i t l ist, y o u should a l low the user to def ine addi t ional restrictions for the attr ibutes. By a l lowing these addi t ional restrictions, the set o f data displayed is more focused and reduces the system load, in other words, we reduce the amount o f data that is fetched f r om the database by a l lowing the user to restrict wh ich entries he wants to see in the hi t list. Add i t iona l condi t ions can be entered in a dialog box for restr ict ing values. You use the dialog type o f a search help to def ine whether the dialog box for restr ict ing values is displayed before determin ing the hi t l ist.

• You def ine wh ich fields are to appear on either (or both) o f the dialog boxes

as parameters in the search help. A l l fields o f the selection method except the

cl ient field and non-key fields o f y o u r text table can be used as parameters.

Key Concepts Refresher Chapter 18 19

• You def ine wh ich parameter should appear in wh ich dialog box and the order by assigning the parameters posit ions in the t w o dialog boxes. You can use d i f ferent parameters or d i f ferent orders in the two dialog boxes. The LPos co lumn in Figure 19.6 identi f ies the order o f the parameter in the hi t l ist, and the SPos co lumn identi f ies the posi t ion o f the parameter in the dialog box for l im i t i ng the hit l ist.

Elementary srch hip DEB IA Actve

Short aescnewn Cui lomers (general^

^ w m r * ^ M n u i n n I

Data collection Dialog behandor

Selection method n CCB1A Dialog type C Dialog with value restriction "

Text table Hotkey *

Search h e * «»t

l a i I I J Parameter

r Search help parameter

r SORTL 1 1 SORTL

»StL2 2 2 PSTLZ

1C0D3 3 3 WCDC3

j WC0D1 4 4 ncooi CUHHR 5 5 KUNNR

— | 1

Figure 19.6 Elementary Search Help

You must use data elements to type the search help parameters. I f y o u don ' t spec-

i fy otherwise, the parameter uses the data element o f the corresponding f ie ld o f

the selection method, and normal ly this w o u l d be what y o u wou ld use.

When def in ing a parameter o f a search help, y o u also specify whether it is to

copy data f r om the screen to the value help (i.e., i t acts as an IMPORT parameter)

or i f it returns data f r om the value help (i.e., i t acts as an EXPORT parameter).

These IMPORT and EXPORT parameters fo r a search help def ine the interface. Af ter

y o u have def ined the search help, y o u need to attach it to the relevant object —

either to a data element, a table or structure f ield, or a check table. The search

help attachment defines where the IMPORT parameters o f the search help get their

values and wh ich screen fields to return the contents o f the EXPORT parameters.

You do not normal ly def ine the semantic and technical attr ibutes o f a screen f ie ld

(type, length, F l help, etc.) d i rect ly when y o u def ine the screen and create the

590 Chapter 19 Table Relationships

input field. Instead, y o u reference an ABAP Dic t iona iy field in the Screen

Painter. The screen field then takes on the attr ibutes o f this D ic t iona iy field. Like-

wise, y o u attach the search help to the ABAP Dict ionary search field and not to

the screen field. In this way we get consistency: Wherever an input field is based

upon a Dic t iona iy field, the same search help w i l l be available for the user.

Note

Fields that do not have a search help attachment can still have a value help because other mechanisms are also used for the value help, for example, domain fixed values.

There are three mechanisms for attaching a search help to a field o f the ABAP

Dic t ionaiy :

• You can attach a search help di rect ly to a field o f the structure or table.

• I f the field has a check table, the contents o f the check table are offered as pos-sible values in the value help. The display contains the key fields o f the check table. I f the check table has a text table, its first character-l ike non-key field is also displayed. You can attach a search help to the check table. This search help is used for all o f the fields that have this table as a check table.

• You can attach a search help to a data element. This search help is then avail-

able for all o f the fields that use this data element.

I f y o u attach a search help to a check table or a data element, y o u w i l l obtain a

high degree o f reusabil i ty.

The SAP system uses a number o f mechanisms to prov ide value help to as many screen fields as possible, not j us t search helps. I f more than one mechanism is available for a field, the system uses the hierarchy shown in Figure 19.7 to deter-mine wh ich to present.

It is also possible to define a value help for the screen field di rect ly in the Screen

Painter. This, however, docs not provide automatic reuse and therefore is not

encouraged. You can also program the value help yourse l f using the screen event

Process On Value Request (POV), but this can require a lot o f p rogramming ef for t .

Performance o f a search help, as w i t h SELECT statements, should always be o f concern. As a search help is selecting data f r om the database, it is sometimes nec-essary to search large amounts o f data. This can result in a long wait t ime for the user and increase the load on the system. When def in ing a search help, as y o u

Practice Questions Chapter 17 591

do with a SELECT,you should take measures to optimize the selection method. If you expect a large number of entries, you should restrict the hit list with addi-tional conditions. This increases the clarity of the hit list and reduces the load on the system. The additional conditions can be a result of the context or can be entered by the user in a dialog box. Options used for optimizing a database SELECT can also be used here. This includes buffering or secondary indexes.

Figure 19.7 Value Help Mechanisms

Practice Questions

The practice questions below will help you evaluate your understanding of the topic. The questions shown are similar in nature to those found on the certifica-tion examination, but whereas none of these questions will be found on the exam itself, they allow you to review your knowledge of the subject. Select the correct answers and then check the completeness ofyour answers in the follow-

592 Chapter 19 Table Relationships

ing solut ion section. Remember that y o u must select all correct answers and on ly

correct answers to receive credit for the quest ion.

1. Value help can be suppl ied f rom:

• A . Process On Value request

• B. Search help for a screen f ie ld

• C. Search help for table or structure fields

• D. Search help for a check table

• E. Search help f r om a text table

• F. Key values o f a check table

• G. Search help for a data c lement

• H. Fixed values

2. A table is a text table when:

• A. The ent ire key o f this data table is inc luded as the key to this table.

• B. This table has an addit ional language key f ield.

• C. This table on ly has one character-based data f ield.

• D. This table has a foreign key to the data table as a text table.

• E. The ABAP run t ime system determines that the relat ionship exists.

3. A foreign key must have domain equal i ty:

• A . A lways

• B. Not true

• C. For a check f ie ld

• D. For a text table

4. Where are f ixed values for fields stored?

• A. Table

• B. Structure

• C. Field

• D. Data element

• E. Domain

Practice Questions Chapter 17 593

5. On ly one text table can be l inked to a table.

• A . True

• B. False

6. What is the di f ference between a value table and a check table?

• A. No dif ference; they are the same thing.

• B. A value table is a check table after a foreign key is def ined.

• C. A value table is def ined in the domain, whereas a check table is def ined

in the data element.

• D. A check table is def ined in the domain, whereas a value table is def ined in the data element.

• E. A value table does not exist.

7. The order o f fields for a transparent table in the database:

• A. Need to match the ABAP Dic t iona iy

• B. Arc created in the order o f the ABAP Dic t iona iy

• C. Are a l lowed to be d i f ferent than the ABAP Dic t iona iy

8. A search help must:

• A. Use a table or a v iew fo r data selection

• B. Determine the values for selection by the user

• C. Have a dialog w i t h the user

• D. A l l o w the user to select a response

• E. Be used f r om a screen

9. Where should the labels for fields be stored?

• A. Table

• B. Structure

• C. Field

• D. Data element

• E. Domain

594 Chapter 19 Table Relationships

10. Wh ich type o f v i ew cannot be used in a search help?

• A. Database v iew

• B. Maintenance v iew

• C. Help v iew

11. Wh ich type o f v i ew uses an inner j o i n in a search help?

• A. Database v iew

• B. Maintenance v iew

• C. Help v iew

Practice Question Answers and Explanations 1. Correct answers: A l l op t i ons

A l l o f the answers are correct. Value help can be obtained f r om any o f these

sources (and a couple more; see Figure 19.7 for the complete list).

2. Correct answers: A , B, D

It is necessaiy for the ent i re key o f the data table plus the language key fo r the table to be considered a text table. However, it is also necessaiy for the for-eign key l ink to be specified; otherwise, they are jus t two simi lar tables. It is not necessaiy for there on ly to be one character-based f ield; there must be at least one. As ment ioned above, on ly the first one (after the key) is used for the text,

3. Correct answer: C

Domain equal i ty can exist for other foreign keys, but it is on ly necessaiy fo r

a check table. In other cases, a l ike type and length is suff ic ient.

4. Correct answer: E

Fixed values are ident i f ied at the domain level in the ABAP Dict ionary. You

can specify ind iv idua l values or intervals.

5. Correct answer: A

You can on ly associate one text table to a data table. The system checks this when y o u at tempt to activate a table w i t h text foreign keys fo r a data table.

Take Away Chapter 19 595

6. Correct answer: B

Wi thou t the foreign key association, a value table, whereas it can prov ide help assistance, w i l l not per fo rm the check val idat ion dur ing screen process-ing.

7. Correct answer: C

Since Release 3.0, SAP has a l lowed the fields to be a d i f ferent order in the

ABAP Dic t iona iy and the database table.

8. Correct answers: B, C, D, E

It is not necessaiy to use a table or a v iew (you can, but it is not the on ly way

o f selecting data).

9. Correct answer: D

Labels and documentat ion are stored at the data element level.

10. Correct answer: B

The maintenance v iew is not designed for data selection, but rather fo r main-

tenance o f business or iented views o f data.

11. Correct answer: A

A database v iew uses an inner j o i n for data selection. I f y o u need an outer

j o i n , y o u should use a Help v iew.

Take Away You w i l l need to understand the relat ionship between database tables and both text tables and check table. You w i l l need to understand the foreign key relation-ship between the tables. You also need to be able to dist inguish between di f fer-ent mechanisms for value help and how they can be used on screens. As part o f this, y o u w i l l need to understand the types o f checks that a field may have enforced f r om the ABAP Dic t iona iy .

Refresher

You w i l l need to understand how data checks can be enforced dur ing screen pro-

cessing and how value help can be provided. You w i l l need to k n o w the relation-

ship between di f ferent areas o f the ABAP Dic t iona iy (domains and data

elements) and relationships between tables w i t h the use o f foreign keys. You w i l l

582 Chapter 19 Table Relationships

need to understand h o w to specify a check table and a text table w i t h foreign

keys. You w i l l need to k n o w h o w to enforce checks for screen fields, the d i f ferent

uses o f foreign keys, and the use and design o f search helps.

Table 19.1 lists the key concepts for table relationships.

Key Concept Definition

Validation Either the use of a check table or fixed values to provide validation checks during screen processing.

Foreign keys The use of foreign keys to link two tables together and provide additional information or validation.

Search helps A means of providing value help to the user on a screen.

Table 19.1 Key Concepts Refresher

Tips

A number o f the questions in this area w i l l not be part o f the normal class mate-

rials. These questions w i l l require y o u to understand the under ly ing process to

produce the correct answer. As w i t h the major i ty o f the subjects f ound in the cer-

t i f icat ion examinat ion, it is impor tant to have as much practical experience w i t h

the subject as possible. A l though the major i ty o f the concepts presented in this

chapter should be second nature, it is impor tant that y o u understand the nuances

o f foreign keys and search helps.

Summary You should now be able to create foreign keys to prov ide check tables or text

tables. You should also be able to ident i fy the d i f ferent parts o f a search help and

understand where the search help can be used as we l l as h o w to design one.

These skills w i l l enable y o u to successfully pass this por t ion o f the cert i f icat ion

exam.

597

The Authors

Punee t A s t h a n a is a recognized exper t i n ABAP develop-

ment and has 14 years o f deve lopment exper ience, and has

been w o r k i n g fo r SAP fo r over seven years. Apar t f r o m

ABAP deve lopment , he is also an expert i n IDoc, ALE, EDI.

w o r k f l o w , and process in tegrat ion. He has w o r k e d on a

n u m b e r o f projects as a technical lead and is cu r ren t l y

w o r k i n g as a technical architect fo r a g lobal SAP Retail

imp lemen ta t i on fo r a ma jo r retai ler. He has extensive expe-

rience in in tegrat ing SAP and non-SAP systems and leverag-

ing SAP In tegrat ion Technologies inc lud ing SAP NetWeaver PI to de l iver

innova t i ve technical so lut ions.

Puneet has part ic ipated in so lu t ion reviews, customer project issue escalations,

and presales act iv i ty and conducted workshops to help his colleagues. He also

has good func t iona l knowledge and has been invo lved in a broad range o f SAP

so lu t ion imp lemen ta t i on inc lud ing SAP SRM. IS-Mil ls, IS-Retail, SAP AFS, SAP

NetWeaver Portal, and SAP NetWeaver PI.

D a v i d H a s l a m is a recognized exper t in ABAP develop-

ment , hav ing w o r k e d fo r SAP fo r over 14 years. David has

led o r par t ic ipated in over seven fu l l l i fecycle imp lementa-

t ions o f SAP, w h i c h inc lude several mul t ip le-phase projects

and fou r large deve lopment projects. He was awarded the

prest igious status o f SAP Plat inum Consul tant m o r e than

e ight years ago. and he enjoys he lp ing others th rough

workshops and wh i t e papers and shar ing his knowledge

and experience. In add i t ion , Dav id part icipates in develop-

men t rev iews, pro ject estimates, and customer project issue escalations.

He has shared his experience and knowledge, p r o v i d i n g guidance w i t h the fol-

l o w i n g SAP cer t i f icat ion examinat ions: SAP Cert i f ied Deve lopment Associate -

ABAP w i t h SAP NetWeaver 7.0, SAP Cert i f ied Deve lopment Professional - ABAP

System Integrat ion - SAP NetWeaver 7.0, and SAP Cert i f ied Deve lopment Pro-

fessional - ABAP User Interfaces - SAP NetWeaver 7.0.

599

Index

A

ABAP 8 1 , 2 3 5 , 2 3 6 . 2 4 6 Data object 139 Datatype 1 3 7 , 1 4 6 . 1 6 0 . 3 1 6 Global declaration 236. 272 Global definition 2 3 6 Procedural 2 3 6 Processing block 238

Runtime environment 235, 236. 242. 247, 5 2 2 . 5 2 3

Statement 246. 514 Text translation 2 3 6 Type 293

Type of program 2 3 6 ABAP app l i ca t ion server 56. 66 , 67. 71. 72,

202 ABAP class 421

Attribute 4 3 0 CLASS-EVENTS 442 CONSTRUCTOR 438 CREATE OBJECT 429 Event 4 4 2 Global class 423 Local class 421 Method 432 Private 4 2 3

Private instantiation 4 2 7 Private scction 425 Protected 423 Protected installation 4 2 7 Protected section 4 2 6 Public 4 2 3 Public section 425 RAISE EXCEPTION 438 READ-ONLY 4 3 0 Returning 4 3 6 Static method 441

ABAP Debugger 89. 113. 114. 122. 249 Architecture 113

Classic 1 1 4 . 1 1 5 , 1 1 7 . 1 1 9 . 1 2 2 . 1 2 5 . 128. 129

ABAP Debugger (cont.) W w 115, 117, 118, 119. 122, 125, 128,

1 2 9 . 1 3 0 5 t a r t m g 1 1 3 . 1 1 5 . 1 1 6 . 1 1 7 Stopping 117 Switching 117

ABAP D ic t i onary 7 0 . 9 4 . 2 0 0 . 2 5 2 . 258, 262 . 283. 285. 296 . 320. 335. 471 . 503. 578. 579, 587. 5 9 0 Append structure 335 C fo r * table 578. 579. 580. 583. 584. 585.

587. 588. 5 9 0 Customizing include 335 D a w element 201 . 264, 464 , 471 . 503,

578. 580. 588. 589. 590 Data type 138. 157

Domain 201. 580. 581. 582, 584. 585, 5 9 0 Fixed value 580. 582, 5 9 0 Foreign key 578. 583. 584. 585. 586. 587 Search help 578. 579. 580. 5 8 7 Service 305

Structure enhancement 335 Table 321

Text table 5 8 6 , 5 8 8 . 5 9 0 Type 293

Value table 578. 580. 582. 583. 585 View 588

A B A P Ed i to r 9 3 . 1 1 4 . 1 2 4 . 1 2 9 New ABAP Editor 79. 89. 91

ABAP List V i e w e r — A L V ABAP Objccts 114. 1 2 1 . 2 3 6 . 2 4 9 . 2 5 5 . 4 1 8 .

419. 421 . 5 1 2 . 5 1 3 Reference 114

ABAP processor 70 ABAP W o r k b e n c h 79. 81. 93. 109. 2 3 4

Settings 88 Abst rac t ion 4 2 0 Access m o d e 298 Al ias 525 A L V 4 5 4 , 5 8 0

Container 454 . 455. 456 . 457 . 458. 459 .

467. 4 7 6 Currency 465

600 Index

AI.V (corn.) Display data table 460. 4 6 9 Display variant 460 . 4 6 2 Event handling 454. 455 . 465 . 4 7 6 Event registration 465. 467 , 4 7 7 Field catalog 459 , 460. 4 6 1 , 4 6 3 . 4 6 4 . 4 7 1 ,

4 7 7

Field group 4 6 0 Filtering 461

Full screen 454 . 455. 459 . 4 6 7 Grid control 454, 456. 459. 4 6 0 l ayout 460, 463 Object model 455 . 467 . 472. 473 Print output 4 6 0 Sorting 4 6 0 . 4 6 1 . 4 6 3 . 4 7 1 Unit of measure 465

Amer i can Standard Code for I n f o r m a t i o n

In terchange ASCII APPEND 1 7 6 . 1 7 7 . 1 9 4 App l i ca t i on layer 66. 206, 210. 235 ASCII 326 Assert 1 1 3 . 1 2 5 . 1 2 6 ASSIGNING 181 Associate cer t i f i ca t ion 30 Associate exam ina t i on

Competency area 33 Specifics 32

AT E X I T - C O M M A N D 368 AT SELECTION-SCREEN 4 0 9

ON 4 0 9 ON BLOCK 4 0 9 ON HELP-REQUEST FOR 409 ON RADIOBUTTON 409 ON VALUE-REQUEST 4 1 0 OUTPUT 4 0 0

A t t r i b u t e 2 5 5 . 4 3 1 . 4 5 2 Instance 4 5 6 . 4 6 7 . 5 1 4 Static 256. 468 . 514, 521

A u t h o r i z a t i o n check 232 . 2 6 0 A u t h o r i z a t i o n ob ject 261

B

Back-End Ed i tor 89 BAdI 5 3 8 . 5 3 9 . 5 5 5

Definition 556 Filter-depend 555

BAdI (corn.) Implementation 561 Menu enhancement 562 Multiple use 555 New 565

Screen enhancement 563 Searching 557

BAPI 64

Definition 2 9 7 BEGIN OF BLOCK

Title 4 0 4 With frame 4 0 4

BINARY SEARCH 1 8 2 . 1 9 1 Breakpo in t 113. 120. 124. 125. 126. 130.

2 4 0 BSP 60 BTE 5 3 9 . 5 5 1

FIBF 552

Process interface 552 Publish and subscribe 552 Search 5 5 4

Bu f f e r i ng type 303 Business A d d - I n — BAdI Business A p p l i c a t i o n P rog ramming Inter face

— BAPI Business Process P la t fo rm 57 Business Server Pages - * BSP Business Transact ion Event - » BTE Byte type 326. 329. 330, 331. 336, 338. 3 3 9

c CALL M E T H O D 439 Card ina l i t y 585 Centra l instance 211 Cer t i f i ca t ion

Associate 30 Master 30 Professional 30

Cer t i f i ca t ion exam

Scoring 28 Cer t i f i ca t ion level 29. 31 Change request 232 . 234 . 235. 271

Task 2 3 4 . 2 7 1 Character type 146. 326. 329. 330. 331. 333.

334, 336. 339 Checkpo in t 1 2 5 . 1 2 6 . 1 2 7 . 1 3 0

Index

Class 4 5 2 FRIENDS 5 1 7 INHERITING FROM 519

Class Bu i lder 9 3 , 4 3 1 Class cons t ruc to r 4 1 7 . 4 3 9 CLASS-DATA 145 CLASS-EVENTS 4 4 2 CLASS-METHODS 4 3 2 Cluster table 3 2 0 C M O D 544

Code execut ion 1 1 3 . 1 2 8 Codc page 3 2 6 . 3 3 7 . 3 3 8 COLLECT 178 C o m p o n e n t

Lifetime 4 9 0 . 4 9 3 Compos i t e enhancement spot 5 6 7 Cons t ruc to r 520

Instance 459 . 5 2 0 Static 5 1 5 . 5 2 0

Contex t m a p p i n g 495 , 502 C o n t r o l F ramework 4 5 6 Con t ro l l e r

Component controller 493 Configuration controller 4 9 4 Context controller 4 9 0 Custom controller 4 9 4 View controller 494 Window controller 4 9 4

Convers ion rou t i ne 319 Course

BC400 4 6 BC401 46 BC402 46 BC405 46 BC414 46 BC425 46 BC427 46 BC430 46 NET310 47 NW001 47 TAW 10 46 TAW 11 46 TAW 12 46

CREATE OBJECT 4 5 2 Cus tomer exit 539, 543 C U S T O M E R F U N C T I O N 545

D

Data b i n d i n g 495 Data e lement 153, 283 . 285 . 286. 287. 295.

321

Data encapsulat ion 2 4 9 Data m o d e l i n g 198. 199, 200. 2 6 1

Data object 1 3 9 . 1 4 1 . 1 6 0

Classic 114 FORM... ENDFORM 154 Literal 141 Local 157

Modifying 1 1 3 . 1 1 4 . 1 1 7 . 1 2 3 MODULE...ENDMODULE 154 Offset 3 3 2 . 3 3 3 . 3 3 4 Predefined 143

Viewing 1 1 3 . 1 1 4 . 1 1 7 . 1 2 0 . 1 2 1 . 1 2 2 .

124. 129, 130 Visibility 154

Data re t r ieva l 198. 199. 202 Data type 139. 140. 160. 287 . 2 9 0

Basic 285

Complex 1 5 0 . 2 8 5 . 2 8 7 Elementary 1 3 8 . 1 4 8 . 1 5 2 Generic 1 3 7 . 1 3 9 Global 1 3 7 . 1 5 2 . 1 5 7 . 1 6 0 LCHR 291 Local 149. 1 6 0 l.RAW 291 PARAMETERS 140 Predefined 139 QUAN 291 RAWSTRING 2 9 2 SELECT-OPTIONS 140 SSTRING 2 9 2 STRING 1 4 8 . 2 9 2 TIMS 2 9 2 TYPES 140 VARC 292 XSTRING 148

Database inter face 70. 71. 72. 77. 202, 205.

206 . 207, 583 Database layer 6 2 . 6 4 . 6 5 . 6 9 . 1 9 8 , 2 0 6 . 210.

235

Database lock 7 2 . 1 1 3 . 2 1 1 . 2 2 2 Database update 1 9 8 . 1 9 9

Asynchronous 2 2 0

602 Index

Database update (coni . ) Bundled 2 1 0 , 2 1 2 . 2 1 6 Inline update 2 1 2 , 2 1 6 Local 221 Synchronous 2 2 1 Update task 2 1 2 , 2 1 7

Database v i e w 207 , 286 . 314 Debugger 112

Deep s t ruc ture 137, 160, 318 Defaul t c o m p o n e n t name 2 9 7 DELETE 187

De l i ve ry and main tenance 3 0 0 DEQUEUE 3 0 9 . 3 1 5 Desktop 1 1 9 , 1 2 0 , 1 2 8 . 1 2 9 D ia log p rog ram 343 D ia log screen 388

Event 388 D ia log step 6 8 , 7 3 , 2 1 0 . 2 1 6 D i c t i ona i y 351 D i c t i ona i y type

ACCP 2 9 3 CENT 293 DATS 293 Fl.TP 293 Predefined 152

Di lT too l 121 Dispatcher 68

D o m a i n 283. 285. 288 , 295. 321 Format 288

Output property 288. 2 9 3 D o w n cast 523

E

EBCDIC 326 Encapsulat ion 4 2 0 Enhancement 5 3 7

ABAP Dictionary 563 Append structure 563 BAdI 555 BTE 551 Concept 574 Customer exit 543 Customizing include 564 Explicit enhancement point 565 Implicit enhancement point 565 Menu exit 5 5 0

Enhancement (com.) Option 565 Screen exit 549 Search tool 575 Spot 566

Technique 540. 575 User exit 540

Enhancement F ramework 95 . 537. 539, 564. 575

Composite Enhancement 567 Enhancement option 565 Enhancement point 565 Enhancement spot 5 6 7 New BAdI 565

Enhancement I n f o r m a t i o n System 79, 95,

110. 575 Enhancement spot 9 6 ENQUEUE 3 0 9 . 3 1 5 Enterpr ise ex tens ion 58 Ent i ty re la t ionsh ip m o d e l E R M E R M 199 Event 452

Sender 442 Event b lock 2 3 2 . 2 4 3 . 2 7 2

AT LINE-SELECTION 2 4 6 . 2 7 0 AT SELECTION-SCREEN 242. 245, 267 .

269 AT USER-COMMAND 246, 2 7 0 END-OF-PAGE 2 4 6 . 2 6 7 END-OF-SELECTION 245, 2 6 7 GET node 2 4 2 , 2 4 5 , 2 6 7 INITIALIZATION 243. 2 6 7 LOAD-OF-PROGRAM 243 , 2 6 7 START-OF-SELECTION 242 , 243, 2 6 7 TOP-OF-PAGE 245 , 267 . 2 7 0

Examina t i on

Strategy 52 Examine

Processing logic 113 Result 113

Source code 113, 117, 120, 1 2 2 . 1 2 4 . 1 2 8 .

1 3 0 Exclusive lock 311 Exclusive m o d e 1 1 8 , 1 1 9 . 1 3 0 External m o d e 1 1 5 , 1 1 7 , 1 3 0

Index 603

F

FIBF 552 FIELD 355 Fie ld label 2 9 6 Fi le In ter face 338

OPEN DATASET 338 Fixed p o i n t a r i t hmet i c 147 Flat s t ruc ture 1 3 7 , 1 6 0 . 3 1 8

Type 1 5 0 F l o w logic 2 6 2 Fore ign key 301

Fragment v i e w 326. 330. 333. 334. 339

FREE 189

Fr iendsh ip - * Class Fron t -End Ed i to r 90

Ful l b u f f e r i n g 303 Func t ion Bu i lder 94 Func t iona l m e t h o d 513

Funct iona l t ype 367

c

Gateway 6 8 Gener ic b u f f e r i n g 304 Global class 423

Public instantiantion 4 2 7 Graphica l Screen Painter 350 GUI

Creating GUI status 371 Creating GUI title 371 Setting GUI status 373 Setting GUI title 373 Status 3 4 4 . 3 6 6 . 3 8 8 Title 3 4 4 Title design 3 6 6

H

Hashed table 166. 169, 173. 2 9 8

Internal 195 He lp v i e w 3 1 5 . 3 2 0 Hexadec imal type 1 4 7

I

I d e n t i f y i n g e r ro r 1 1 2 . 1 1 3 Index 286. 304 Index table 169

Inher i tance 4 2 0 , 4 7 1 . 5 1 8 , 5 2 4 . 5 2 8 Tree 519

I N I T I A L I Z A T I O N 399. 4 0 8 I n n e r j o i n 3 1 1 . 3 1 2 . 3 1 8 INSERT 176, 177 INSERT LINES 178 INSERT TABLE 169 Instance 62 Instance a t t r i bu te 431 Instance c o m p o n e n t 428 Integer type 147 Inter face 5 2 4 . 5 2 9 In te rna l table 162. 163. 195. 251

Access mode 169 APPEND 166 ASSIGNING 181 AT... EN DAT 184 BINARY SEARCH 182 CLEAR 188 COLLECT 178 Column 164 Define 167 DELETE 187

DELETE ADJACENT DUPLICATES 187

ENDLOOP 183 Hashed 2 5 1

Hashed table 166 Header line 165

Index access 167 INITIAL SIZE 172

INSERT 177

Key access 1 6 7

Line type 165 LOOP 183 MODIFY 185

Non-unique key 171 OCCURS 190

Populate 166

READ TABLE 179 REFRESH 188

SORT 1 8 7

Sorted 251

Index

In terna l table (cont.) Sorted table 166 Standard 2 5 1 Standard key 165 Standard table 166 Table key 165 Table row 164 Table type 168 TRANSPORTING 1 8 0 Uniqueness of key 167 User-defined key 165 WITH HEADER LINE 172. 174 WITHOUT HEADER LINE 165 Work area 165

In ternet C o m m u n i c a t i o n Manager 60 In ternet Transact ion Server 60

Java Connector 61 J O I N 311

l<

Kernel and adm in i s t r a t i on services 63 Key 298

L

Layout FlowLayout 499 GridLayout 5 0 0 MatrixLayout 5 0 0 RowLayout 499

LENGTH 1 5 0 LIKE 146 l . ine type 298 Li tera l 141

Constant 142 Numeric 142 String 142

Local class 4 1 7 . 4 2 1

Lock object 57. 7 2 . 1 9 8 . 1 9 9 . 211 . 284. 286 . 309. 579

Dequeue 210 . 212 , 216. 220 . 579 Enqueue 210. 212 . 213 . 216, 579 Local lock container 213.214

Lock object (cont.)

Lock mode 311 Lock parameter

jCOLLECT 2 1 3 . 2 1 4 JSCOPE 2 1 3 . 2 1 5 _WAIT 2 1 3 . 2 1 5 MODE 2 1 3 . 2 1 4

Log data change 304

L U W 57. 198. 199. 208. 216 . 217. 221, 222 Commit 2 0 9 . 2 1 1 . 2 1 6 . 2 2 0 . 2 2 1 . 2 2 2 Database 6 9 . 7 2 . 2 0 8 , 2 0 9 . 2 1 0 . 2 1 1 . 2 2 2 Implicit commit 209. 210 . 211 Rollback 2 0 8 , 2 0 9 . 2 1 8 . 2 2 0 , 2 2 2 SAP 7 2 , 2 0 8 . 2 1 0 , 2 1 8 , 2 3 6

M

Ma in tenance 311 Ma in tenance v i e w 286 , 314. 317. 318, 3 2 0 Mas te r cer t i f i ca t ion 30 M e m o i y analysis 121 M e n u ex i t 5 5 0 M e n u Painter 94 Message 2 3 2 . 2 3 9 . 2 6 5

Class 265 Number 265 Placeholder 265 Server 6 3 . 6 6 . 6 7 . 7 2 Type 265

M e t h o d 4 5 2 . 5 2 4 Changing 4 3 6 Default 438 Exporting 4 3 6 Importing 438 Instance 2 5 6 , 5 1 5 , 5 1 9 Optional 438 Static 5 1 5 , 5 2 1

M I M E Reposi tory Browser 84 M o d e l V i e w Con t ro l l e r - M V C M o d i f i c a t i o n 5 3 7 , 5 6 7 M o d i f i c a t i o n b rowser 568 M O D I F Y 1 8 5 , 1 8 6 , 2 0 8 M O D I F Y TABLE 169 M o d u l a r i z a t i o n un i t 232 , 236, 247, 248 ,

272 . 476. 514

Function module 236. 238, 239, 241 . 249.

2 5 1 . 2 5 5 , 2 5 8 , 2 7 1 . 5 1 4

Index

M o d u l a r i z a t i o n un i t (cont.) Method 236. 238. 239 . 241 , 249. 255 .

2 7 1 . 5 1 4

Subroutine 236. 238 . 239. 240, 241. 249. 252. 256 . 258 . 476. 5 1 4

M O D U L E 355 M o d u l e poo l p rog ram

Create 381 M u l t i p l e inher i tance 519. 524, 529 M u l t i p l e use 5 5 7 M V C 4 8 7 , 4 8 8

Controller 488 Model 488 View 488

N

N a r r o w i n g cast - • D o w n cast Nested s t ruc ture 160 Non -cumu la t i ve lock 311 N o n - U n i c o d e system 327 N u m e r i c l i teral 142 N u m e r i c type 147

o Object 4 2 9 . 4 5 2

Instantiation 2 5 6 Object Nav iga tor 82. 83 Ob jec t -o r ien ted p r o g r a m m i n g 4 1 7

Concept 4 1 9 O K . C O D E 2 6 4 O N 355

Oute r jo in 312. 318 Over load ing 5 2 0 O v e r v i e w 285

P

Package 9 7 GLOBAL JWITCH 1 0 0 Interface 100 Nesting 99 PAKPARAM 100 Visibility 99

Package Bui lder 99 PAI 3 4 7

Parameter 240. 249 Changing 238. 241 . 249 . 250. 252 . 255 .

513

Input 238, 241, 249 . 252, 255, 466 , 589 Output 238 . 241. 249 . 252. 255 . 513, 589 Pass by reference 239 . 240. 241 . 250 . 272 Pass by value 239. 240, 241 . 250. 254,

256, 272 Returning 2 3 8 , 2 5 5 , 2 5 8 , 5 1 3 Table 2 3 8 , 2 5 0 , 2 5 2

Parameter ID 2 9 7 PARAMETERS 140. 145, 393

AS CHECKBOX 395 Default 395 MEMORY ID 395 OBLIGATORY 3 9 4 , 3 9 5 PARAMETER ID 395 RADIOBUTTON GROUP 395 VALUE CHECK 3 9 6

PBO 3 4 7

Personal izat ion 539. 5 4 0 Physical lock 211 Plug 4 9 1 . 4 9 2 POH 347. 388 P o l y m o r p h i s m 4 2 0 Pooled table 3 2 0 POV 3 4 7 . 3 8 8

Presentat ion layer 66. 209, 210, 235 Pr imary i ndex 304 Private a t t r ibu te 431 Procedure 242

Exception 238. 239. 251 . 253 . 255. 523 Parameter 238

PROCESS AFTER INPUT - PAI PROCESS BEFORE OUTPUT PBO Process inter face 554 PROCESS O N HELP-REQUEST - POH PROCESS O N VALUE-REQUEST — POV Processing b lock 236. 238. 267 . 272

Dialog module 238 , 5 9 0 Event block 2 3 8 , 2 4 2 Procedure 238

Professional cer t i f i ca t ion 30 Professional exam ina t i on

Competency area 3 7 , 4 0 Specifics 3 7 . 4 0

Program 351

6o6 Index

Program a t t r i bu te 327 Program con tex t 2 1 0 Program type 2 6 6

Class 2 3 7 , 2 3 8 . 2 5 5 Executable 2 3 7 , 2 6 3 Function group 237, 238, 251, 253 , 263 Inter/ace 2 3 7 , 2 3 8 Module pool 2 3 7 , 2 6 3 Type group 237, 238

Pro ject ion v i e w 314, 318, 3 2 0 Publ ic a t t r ibu te 431

R

Read lock 311 READ TABLE 169. 179. 181, 183

REF_FIELD 4 6 4

REF_TABL0 464

Refactor ing Assistant 5 1 8 , 5 2 6

Reference data type 319 Reference table 301

Reference type 152 REFRESH 188

Relat ional opera to r 3 3 7

Remote Func t ion Call — RFC

Repos i to iy Browser 8 5 , 1 0 9 Reposi tory I n f o r m a t i o n System 79. 8 6 . 1 0 9

Repos i to iy ob ject 65. 73. 77, 234. 235

Reuse c o m p o n e n t 203. 248, 251, 4 8 9 Reuse L ib ra ry 83

RFC 6 4 . 2 0 9 , 2 3 6 . 2 5 1

Root c o m p o n e n t 4 9 7

s SAP app l ica t ion server 56, 210. 2 1 1 SAP Business A l l - i n -One 57 SAP Business ByDesign 57 SAP Business O n e 57 SAP Business Suite 57 SAP Cer t i f ied ABAP Deve lopmen t Associate

30. 32

SAP Cer t i f ied ABAP Deve lopmen t Professio-nal 36

SAP Developer N e t w o r k — S D N SAP deve lopmen t 48 SAP ERP 59

SAP examina t i on

Strategy 50 SAP GUI 6 4 . 6 6 . 6 8 . 6 9 . 4 5 6 SAP Help Portal 4 7 SAP List V i e w e r — A L V SAP Logon 6 6 SAP Ne tWeaver

Documentation 48 Release change 48

SAP Ne tWeaver App l i ca t i on Server 56. 57. 60 . 64. 327. 455 . 488 ABAP 6 1 . 6 2 . 6 4 . 6 6 , 6 7 . 6 8 . 7 1 ABAP*Java 6 0 , 6 2 Java 6 1 . 6 2

SAP Notes Assistant 568 SAP W e b App l i ca t i on Server 58, 60 Screen 66 . 252 . 262. 380. 4 5 6

CHAIN 355

Container control 456 . 457, 459, 475 Control 4 5 6 . 4 5 9 Design 3 4 6

Dynpro 69, 232. 258, 262 , 456 , 458. 476, 4 8 7

Element attribute 350 ENDCHAIN 355 ENDLOOP 355 Exit 549 FIELD 3 5 7 Field help 362 Function code 352 Function type 367 LOOP 355

Modal dialog box 2 3 2 , 2 6 4

Modifying dynamically 3 8 0 Module 353

ON CHAIN-INPUT 358

ON INPUT 358 ON REQUEST 358

PROCESS AFTER INPUT 345

PROCESS BEFORE OUTPUT 345 Processing 355

Processor 6 9

Show element list 351 Structure 3 8 0

Type 349 Value help 362

VALUES 355

Index 607

Scrccn ( l o w logic 353 AT CURSOR-SELECTION 359 AT EXIT-COMMAND 359 Keyword 355

PROCESS AFTER OUTPUT 354 PROCESS BF.FORF. OUTPUT 354

Scrccn Painter 305, 343, 347 S D N 47

Search he lp 284, 286 , 297 , 301. 305, 317, 319, 5 9 0

Append 306, 309 Attachment 587. 589. 5 9 0 Collective 3 0 6 . 3 0 7 Dialog behavior 587. 588 Elementaiy 3 0 6 Interface 5 8 7 . 5 8 9 Parameter 306. 308 Selection method 587. 588. 591 Value list 5 8 7 . 5 8 8

Secondary index 304 SELECT 2 0 3 . 2 0 6 . 2 0 7 . 5 9 1

Array fetch 205 Field list 204 FROM clause 2 0 3 INTO clause 2 0 3 . 2 0 4 . 2 0 5 Join column 2 0 7 Join condition 207 Join table 207 Loop 2 0 3 . 2 0 4 SELECT clause 203 SINGLE 2 0 3

WHERE cfou*- 203. 204. 205 Select ion m e t h o d 306, 3 0 7 Select ion screen 140, 145, 232, 258, 346,

391. 393. 396. 4 0 3 As subscreen 4 0 6 BEGIN OF BLOCK 4 0 4 BEGIN OF UNE 4 0 4 CALL SELECTION-SCREEN 403 Design 393 END OF BLOCK 404 END OF LINE 4 0 4 HIGH 3 9 7 LOW 3 9 7 MEMORY ID 4 0 0 Nesting Level 4 0 7 NO INTERVALS 4 0 0 NO-DISPLAY 4 0 0

Select ion screen (cont.) NO-EXTENSION 399 OBUGATORY 4 0 0 OPTION 397 Parameter 258 PARAMETERS 3 9 1 . 3 9 3 Processing 4 0 8 Selection text 394 SELECT-OPTIONS 2 5 8 . 3 9 1 . 3 9 3 S/GN 3 9 7 SK//> 405 Text element 394 ULINE 405 Variant 4 0 3

SET HANDLER 445 Shared lock 311 Shared m e m o r y 69 Singleton 5 1 5 . 5 1 8 S M O D 544

Sorted table 166. 169. 173. 298

Internal 195 Special izat ion 518. 524 SQL 1 9 8 . 1 9 9 . 2 0 8

Access method 205 Buffering 7 1 . 2 0 1 , 2 0 2 , 2 0 6 . 2 3 5 Key field 2 0 1 . 2 0 3 . 2 0 5 Native SQL 7 0 . 7 1 . 2 0 2 Open SQL 70. 7 1 . 1 9 9 . 202 . 203. 206, 207.

208. 2 3 5 Optimize 205 Secondary index 201 . 205

Standard table 166. 169, 298

Internal 195 Static a t t r i bu te 4 3 1 Static c o m p o n e n t 428 STRING 148 Str ing l i tera l 142 St ructure 2 0 1 . 2 0 4 . 2 8 6 . 2 8 8 . 2 9 7 Syntact ical ly f o rb idden 5 2 6

T

Table 2 6 1 . 2 8 6 DBTABPRT 304 Field 3 0 0 Join 207 Primary key 2 0 1 Secondary key 201. 205

6o8 Index

Table (cont . ) Transparent 2 0 0 , 2 0 1 . 2 0 2

Table c o n t r o l Attribute 3 7 6 Programming 375 Screen Jlow logic 3 7 7

Table type 1 5 1 . 1 6 8 . 2 8 6 . 2 9 8 Key category 170 Line type 168

TABLES 154 Tag Browser 84 Target — SELECT Technical p l a t f o r m 58. 59 Technical sett ings 303 Test Reposi tory Browser 85 Text field l i teral 142 Text s y m b o l 143

T o o l 119, 120, 122, 124, 125. 128. 1 2 9 . 1 3 0

Service 1 2 1 . 1 2 2 Transact ion

CMOD 544 FIBF 552 SMOD 544 UCCHF.CK 3 2 7 . 3 2 8

Transparent table 285, 300, 316. 317 Transpor t Managemen t System 102 Transpor t Organ izer 101. 104. 1 1 0 TRANSPORTING 184 Type 1 4 6 . 3 1 1 TYPES 140. 149

u UCCHECK 3 2 7 . 3 2 8 Unders tand ing

Comprehension 49 Effective memory 48 Mnemonics 49 Testing 49

Un icode 246, 324 Alignment 325. 330, 332, 334 Byte order 332 Character set 3 2 7 Check 3 2 4 , 3 2 5 , 3 2 6 , 3 2 7 Compliant 325 Fragment view 334, 335 Program 236, 327. 328, 329, 331. 335,

3 3 6

Un icode (cont.) Syntax 3 2 5 , 3 2 6 , 3 2 8 System 3 2 7 . 3 2 8 , 3 3 8 Tool 326, 327

Un icode Check t ransact ion - UCCHECK Upcas t 521

Update m o d u l e 72, 199, 219. 2 2 0 V1 2 1 9 , 2 2 1 V2 2 1 9 , 2 2 1

User ex i t 5 3 9 . 5 4 1 , 5 4 3

V

V A L U E 146 Var iab le 143 V i e w

Container 4 9 8 Context 4 9 1 , 4 9 3 , 5 0 2 Controller 4 9 1 . 4 9 3 , 5 0 2 Layout 4 9 7 . 4 9 8 . 5 0 2 UI element 489 . 495, 496 , 497 . 498, 501,

502

V i s i b i l i t y sect ion 5 1 9 , 5 2 4 Private 5 1 5 , 5 1 7 , 5 1 9 , 5 2 0 Protected 5 1 7 . 5 2 0 Public 5 1 6 , 5 1 7 . 5 2 0 , 5 2 4

w W a t c h p o i n t 1 1 3 . 1 2 5 . 1 3 0 W e b App l i ca t i on Bu i lder 94 W e b D y n p r o 6 1 . 6 7

Component 489 . 492, 493 Component interface 489 . 4 9 6 Controller 489. 490 , 492 , 493 Event handling 491, 495 Explorer 95 Text Browser 84 View 4 8 9 , 4 9 1 . 4 9 2 Window 4 8 9 . 4 9 2

W i d e n i n g cast - » Up cast W o r k process 63 . 68. 69. 72. 210, 2 2 1 W r i t e lock 311

X

XSTRING 148