SAP Press - ABAP to the Future

主页 » SAP电子书 » ABAP开发/Basis

作者 SAP 2016年出版 分类:sap 1484

SAP Press - ABAP to the Future 官方出品,英文原版,文本可编辑带导航非影印版!

Contents
Foreword ......................................................................................................... 19
Acknowledgments ............................................................................................ 21
Introduction ..................................................................................................... 23
PART I Programming Tools
1 ABAP in Eclipse ......................................................................... 35
1.1 Installation .................................................................................... 37
1.1.1 Installing Eclipse ............................................................... 37
1.1.2 Installing the SAP-Specific Add-Ons ................................. 39
1.1.3 Connecting Eclipse to a Backend SAP System ................... 41
1.2 Features ........................................................................................ 42
1.2.1 Working on Multiple Objects at the Same Time ............... 47
1.2.2 Bookmarking .................................................................... 48
1.2.3 Creating a Method from the Calling Code ........................ 50
1.2.4 Extracting a Method ......................................................... 53
1.2.5 Deleting Unused Variables ............................................... 58
1.2.6 Creating Instance Attributes and Method Parameters ....... 59
1.2.7 Creating Class Constructors .............................................. 60
1.2.8 Getting New IDE Features ................................................ 61
1.3 Testing and Troubleshooting ......................................................... 63
1.3.1 Unit Testing Code Coverage ............................................. 63
1.3.2 Debugging ....................................................................... 67
1.3.3 Runtime Analysis .............................................................. 69
1.4 Customization Options with User-Defined Plug-Ins ....................... 71
1.4.1 UMAP .............................................................................. 73
1.4.2 Obeo ............................................................................... 78
1.5 Summary ....................................................................................... 79
2 New Language Features in ABAP 7.4 ........................................ 81
2.1 Database Access ............................................................................ 82
2.1.1 New Commands in OpenSQL ........................................... 82
2.1.2 Buffering Improvements ................................................... 85
2.1.3 Creating while Reading .................................................... 87
2.1.4 Inner Join Improvements .................................................. 88
www.allitebooks.com
10
Contents
2.2 Declaring and Creating Variables ................................................... 90
2.2.1 Omitting the Declaration of TYPE POOL Statements ........ 90
2.2.2 Omitting Data Type Declarations ...................................... 92
2.2.3 Creating Objects Using NEW ............................................ 92
2.2.4 Filling Structures and Internal Tables while

Creating Them Using VALUE ............................................ 93
2.2.5 Filling Internal Tables from Other Tables Using FOR ......... 94
2.2.6 Creating Short-Lived Variables Using LET ......................... 95
2.3 String Processing ........................................................................... 96
2.3.1 New String Features in Release 7.02 ................................. 96
2.3.2 New String Features in Release 7.4 ................................... 97
2.4 Calling Functions ........................................................................... 98
2.4.1 Method Chaining ............................................................. 98
2.4.2 Avoiding Type Mismatch Dumps when

Calling Functions .............................................................. 99
2.4.3 Using Constructor Operators to Convert Strings ............... 100
2.4.4 Functions That Expect TYPE REF TO DATA ....................... 101
2.5 Conditional Logic .......................................................................... 102
2.5.1 Using Functional Methods in Logical Expressions ............. 103
2.5.2 Omitting ABAP_TRUE ...................................................... 103
2.5.3 Using XSDBOOL as a Workaround for BOOLC .................. 105
2.5.4 The SWITCH Statement as a Replacement for CASE .......... 106
2.5.5 The COND Statement as a Replacement for IF/ELSE ......... 108
2.6 Internal Tables ............................................................................... 109
2.6.1 Using Secondary Keys to Access the Same Internal

Table in Different Ways .................................................... 109
2.6.2 Table Work Areas ............................................................. 112
2.6.3 Reading from a Table ....................................................... 114
2.6.4 CORRESPONDING for Normal Internal Tables .................. 115
2.6.5 MOVE-CORRESPONDING for Internal Tables

with Deep Structures ........................................................ 116
2.6.6 New Functions for Common Internal Table Tasks ............. 120
2.6.7 Internal Table Queries with REDUCE ................................ 122
2.6.8 Grouping Internal Tables .................................................. 122
2.6.9 Extracting One Table from Another .................................. 124
2.7 Object-Oriented Programming ...................................................... 126
2.7.1 Upcasting/Downcasting with CAST ................................... 126
2.7.2 CHANGING and EXPORTING Parameters ......................... 127
2.7.3 Changes to Interfaces ....................................................... 128
2.8 Search Helps .................................................................................. 129
2.8.1 Predictive Search Helps .................................................... 129
2.8.2 Search Help in SE80 ......................................................... 130
www.allitebooks.com
Contents
11
2.9 Unit Testing ................................................................................... 131
2.9.1 Creating Test Doubles Relating to Interfaces ..................... 131
2.9.2 Coding Return Values from Test Doubles ......................... 132
2.9.3 Creating Test Doubles Related to Complex Objects .......... 133
2.10 Cross-Program Communication ..................................................... 134
2.11 Summary ....................................................................................... 136
3 ABAP Unit and Test-Driven Development ................................ 137
3.1 Eliminating Dependencies ............................................................. 139
3.1.1 Identifying Dependencies ................................................. 140
3.1.2 Breaking Up Dependencies .............................................. 141
3.2 Implementing Mock Objects ......................................................... 143
3.2.1 Creating Mock Objects ..................................................... 144
3.2.2 Injection .......................................................................... 145
3.3 Writing and Implementing Unit Tests ............................................ 147
3.3.1 Defining Test Classes ........................................................ 148
3.3.2 Implementing Test Classes ............................................... 153
3.4 Automating the Test Process ......................................................... 161
3.4.1 Automating Dependency Injection ................................... 162
3.4.2 Automating Mock Object Creation via mockA .................. 167
3.4.3 Combining Dependency Injection and mockA .................. 170
3.5 Behavior-Driven Development ....................................................... 171
3.6 Summary ....................................................................................... 173
4 ABAP Test Cockpit .................................................................... 175
4.1 Automatic Run of Unit Tests .......................................................... 177
4.2 Mass Checks .................................................................................. 178
4.2.1 Setting Up Mass Checks ................................................... 180
4.2.2 Running Mass Checks ....................................................... 182
4.2.3 Reviewing Mass Checks .................................................... 185
4.2.4 Dismissing False Errors ..................................................... 188
4.3 Recent Code Inspector Enhancements ........................................... 192
4.3.1 Unsecure FOR ALL ENTRIES (12/5/2) ............................... 193
4.3.2 SELECT * Analysis (14/9/2) ............................................... 195
4.3.3 Improving FOR ALL ENTRIES (14/9/2) .............................. 196
4.3.4 SELECT with DELETE (14/9/2) .......................................... 198
4.3.5 Check on Statements Following a SELECT

without ORDER BY (14/9/3) ............................................ 199
4.3.6 SELECTs in Loops across Different Routines (14/9/3) ........ 200
4.4 Summary ....................................................................................... 202

12
Contents
5 Debugger Scripting ................................................................... 203
5.1 Script Tab Overview ...................................................................... 204
5.2 Coding the SCRIPT Method ........................................................... 209
5.3 Coding the INIT and END Methods ............................................... 215
5.4 Summary ....................................................................................... 222
6 The Enhancement Framework and New BAdIs ......................... 225
6.1 Types of Enhancements ................................................................. 227
6.1.1 Explicit Enhancements ...................................................... 227
6.1.2 Implicit Enhancements ..................................................... 228
6.2 Creating Enhancements ................................................................. 229
6.2.1 Procedural Programming .................................................. 229
6.2.2 Object-Oriented Programming ......................................... 233
6.3 Defining BAdIs .............................................................................. 235
6.3.1 Creating an Enhancement Spot ......................................... 237
6.3.2 Creating the BAdI Definition ............................................ 237
6.3.3 Creating the BAdI Interface .............................................. 244
6.4 Implementing BAdIs ...................................................................... 245
6.5 Calling BAdIs ................................................................................. 249
6.6 Summary ....................................................................................... 252
PART II Business Logic Layer
7 Exception Classes and Design by Contract ............................... 255
7.1 Types of Exception Classes ............................................................. 257
7.1.1 Static Check (Local or Nearby Handling) ........................... 258
7.1.2 Dynamic Check (Local or Nearby Handling) ...................... 260
7.1.3 No Check (Remote Handling) ........................................... 260
7.1.4 Deciding which Type of Exception Class to Use ................ 262
7.2 Designing Exception Classes .......................................................... 263
7.2.1 Creating the Exception ..................................................... 264
7.2.2 Declaring the Exception ................................................... 266
7.2.3 Raising the Exception ....................................................... 267
7.2.4 Cleaning Up after the Exception Is Raised ......................... 268
7.2.5 Error Handling with RETRY and RESUME ......................... 270
7.3 Design by Contract ........................................................................ 274
7.3.1 Preconditions and Postconditions ..................................... 276

Contents
13
7.3.2 Class Invariants ................................................................. 278
7.4 Summary ....................................................................................... 281
8 Business Object Processing Framework (BOPF) ...................... 283
8.1 Defining a Business Object ............................................................ 284
8.1.1 Creating the Object .......................................................... 285
8.1.2 Creating a Header Node ................................................... 286
8.1.3 Creating an Item Node ..................................................... 288
8.2 Using BOPF to Write a DYNPRO-Style Program ............................. 290
8.2.1 Creating Model Classes .................................................... 291
8.2.2 Creating or Changing Objects ........................................... 294
8.2.3 Locking Objects ............................................................... 304
8.2.4 Performing Authority Checks ............................................ 305
8.2.5 Setting Display Text Using Determinations ....................... 306
8.2.6 Disabling Certain Commands Using Validations ................ 316
8.2.7 Checking Data Integrity Using Validations ........................ 318
8.2.8 Responding to User Input via Actions ............................... 325
8.2.9 Saving to the Database ..................................................... 335
8.2.10 Tracking Changes in BOPF Objects ................................... 342
8.3 Custom Enhancements .................................................................. 350
8.3.1 Enhancing Standard SAP Objects ...................................... 351
8.3.2 Using a Custom Interface (Wrapper) ................................. 354
8.4 Summary ....................................................................................... 355
9 BRFplus ..................................................................................... 357
9.1 The Historic Location of Rules ....................................................... 360
9.1.1 Rules in People’s Heads .................................................... 360
9.1.2 Rules in Customizing Tables ............................................. 362
9.1.3 Rules in ABAP .................................................................. 364
9.2 Creating Rules in BRFplus: Basic Example ...................................... 365
9.2.1 Creating a BRFplus Application ........................................ 365
9.2.2 Adding Rule Logic ............................................................ 373
9.2.3 BRFplus Rules in ABAP ..................................................... 386
9.3 Creating Rules in BRFplus: Complicated Example ........................... 388
9.4 Simulations .................................................................................... 394
9.5 SAP Business Workflow Integration ............................................... 397
9.6 Options for Enhancements ............................................................ 401
9.6.1 Procedure Expressions ...................................................... 401
9.6.2 Application Exits .............................................................. 402

14
Contents
9.6.3 Custom Frontends ............................................................ 402
9.6.4 Custom Extensions ........................................................... 403
9.7 Summary ....................................................................................... 403
PART III User Interface Layer
10 ALV SALV Reporting Framework .............................................. 407
10.1 Getting Started .............................................................................. 409
10.1.1 Defining a SALV-Specific (Concrete) Class ......................... 410
10.1.2 Coding a Program to Call a Report ................................... 411
10.2 Designing a Report Interface ......................................................... 414
10.2.1 Report Flow Step 1: Creating a Container

(Generic/Optional) ........................................................... 416
10.2.2 Report Flow Step 2: Initializing a Report (Generic) ........... 416
10.2.3 Report Flow Step 3: Making Application-Specific

Changes (Specific) ............................................................ 424
10.2.4 Report Flow Step 4: Displaying the Report (Generic) ........ 435
10.3 Adding Custom Command Icons Programmatically ........................ 441
10.3.1 Creating a Method to Automatically Create a

Container ......................................................................... 442
10.3.2 Changing ZCL_BC_VIEW_SALV_TABLE to Fill

the Container ................................................................... 443
10.3.3 Changing the INITIALIZE Method ..................................... 444
10.3.4 Adding the Custom Commands to the Toolbar ................. 445
10.3.5 Sending User Commands from the Calling Program .......... 446
10.4 Editing Data .................................................................................. 447
10.4.1 Creating a Custom Class to Hold the Standard

SALV Model Class ............................................................ 448
10.4.2 Changing the Initialization Method of

ZCL_BC_VIEW_SALV_TABLE ............................................ 449
10.4.3 Adding a Method to Retrieve the Underlying

Grid Object ...................................................................... 449
10.4.4 Changing the Calling Program .......................................... 450
10.4.5 Coding User Command Handling ...................................... 451
10.5 Handling Large Internal Tables with CL_SALV_GUI_TABLE_IDA ..... 454
10.6 Summary ....................................................................................... 456
11 ABAP2XLSX ............................................................................... 457
11.1 The Basics ...................................................................................... 459
11.1.1 How XLSX Files are Stored ............................................... 459

Contents
15
11.1.2 Downloading ABAP2XLSX ................................................ 461
11.1.3 Creating XLSX Files Using ABAP ....................................... 462
11.2 Enhancing Custom Reports with ABAP2XLSX ................................ 466
11.2.1 Converting an ALV to an Excel Object .............................. 466
11.2.2 Changing Number and Text Formats ................................ 468
11.2.3 Establishing Printer Settings ............................................. 471
11.2.4 Using Conditional Formatting ........................................... 474
11.2.5 Creating Spreadsheets with Multiple Worksheets ............. 482
11.2.6 Using Graphs and Pie Charts ............................................. 484
11.2.7 Embedding Macros .......................................................... 487
11.2.8 Emailing the Result .......................................................... 493
11.2.9 Adding Hyperlinks to SAP Transactions ............................ 496
11.3 Tips and Tricks ............................................................................... 501
11.3.1 Using the Enhancement Framework for Your Own Fixes ... 501
11.3.2 Creating a Reusable Custom Framework ........................... 504
11.4 Summary ....................................................................................... 505
12 Web Dynpro ABAP and Floorplan Manager ............................. 507
12.1 The Model-View-Controller Concept ............................................. 508
12.1.1 Model .............................................................................. 508
12.1.2 View ................................................................................ 511
12.1.3 Controller ......................................................................... 514
12.2 Building the WDA Application ....................................................... 515
12.2.1 Creating a Web Dynpro Component ................................. 517
12.2.2 Declaring Data Structures for the Controller ..................... 518
12.2.3 Establishing View Settings ................................................ 522
12.2.4 Setting Up the ALV .......................................................... 529
12.2.5 Defining the Windows ..................................................... 531
12.2.6 Navigating between Views Inside the Window ................. 532
12.2.7 Enabling the Application to Be Called .............................. 535
12.2.8 Coding ............................................................................. 535
12.3 Using Floorplan Manager to Modify Existing WDA Components .... 546
12.3.1 Creating an Application Using Floorplan Manager ............ 548
12.3.2 Integrating BOPF with Floorplan Manager ........................ 556
12.4 Summary ....................................................................................... 559
13 SAPUI5 ....................................................................................... 561
13.1 Architecture .................................................................................. 563
13.1.1 Frontend: What SAPUI5 Is ............................................... 564
13.1.2 Backend: What SAP Gateway Is ........................................ 564

16
Contents
13.2 Prerequisites .................................................................................. 565
13.2.1 Requirements in SAP ........................................................ 565
13.2.2 Requirements on Your Local Machine .............................. 566
13.3 Backend Tasks: Creating the Model Using SAP Gateway ................ 567
13.3.1 Configuration ................................................................... 567
13.3.2 Coding ............................................................................. 581
13.4 Frontend Tasks: Creating the View and Controller Using SAPUI5 ... 592
13.4.1 View ................................................................................ 596
13.4.2 Controller ......................................................................... 608
13.4.3 Testing Your Application .................................................. 613
13.5 Adding Elements with OpenUI5 .................................................... 615
13.6 Importing SAPUI5 Applications to SAP ERP ................................... 620
13.6.1 Storing the Application in Releases Lower than 7.31 ........ 620
13.6.2 Storing the Application in Releases 7.31 and Above ......... 622
13.6.3 Testing the SAPUI5 Application from within SAP ERP ....... 624
13.7 SAPUI5 vs. SAP Fiori ...................................................................... 626
13.8 Summary ....................................................................................... 627
PART IV Database Layer
14 Shared Memory ......................................................................... 631
14.1 The Promises of Shared Memory ................................................... 632
14.1.1 Database Access ............................................................... 633
14.1.2 Memory Usage ................................................................. 633
14.2 Creating and Using Shared Memory Objects .................................. 634
14.2.1 Creating the Root Class .................................................... 635
14.2.2 Generating the Broker Class ............................................. 640
14.2.3 Using Shared Memory Objects in ABAP Programs ............ 643
14.3 Updating the Database and Shared Memory Together ................... 647
14.4 Troubleshooting ............................................................................ 649
14.4.1 Data Inconsistency between Application Servers .............. 649
14.4.2 Short Dumps .................................................................... 652
14.5 Summary ....................................................................................... 654
15 ABAP Programming for SAP HANA ........................................... 655
15.1 Introduction to Code Pushdown .................................................... 657
15.2 Top-Down Development ............................................................... 658
15.2.1 Building and Calling CDS Views ........................................ 659
15.2.2 Building and Calling ABAP Managed Database

Procedures ....................................................................... 671
Contents
17
15.3 Bottom-Up Development .............................................................. 677
15.3.1 Building and Calling External Views .................................. 678
15.3.2 Building and Calling Database Proxies .............................. 679
15.3.3 Transporting Changes ....................................................... 680
15.4 Locating Code that Can Be Pushed Down ...................................... 681
15.4.1 How to Find Custom Code that Needs to Be

Pushed Down ................................................................... 682
15.4.2 What Technique to Use to Push the Code Down .............. 684
15.4.3 Example ........................................................................... 684
15.5 Other Modifications to ABAP for SAP HANA ................................. 691
15.5.1 Database Table Design ..................................................... 691
15.5.2 Avoiding Database-Specific Features ................................ 695
15.5.3 Changes to Database SELECT Coding ................................ 697
15.6 Summary ....................................................................................... 700

ABAP SAP Press 英文原版
打赏5块钱,帮小编买杯咖啡吧!

如遇任何问题请联系客服微信ficodk!

下载链接:

上一本

《Kill SAP FICO》from SAP刀客

下一本

SAP Press - Sales and Inventory Planning with SAP APO