《sap学习资料badg.docx》由会员分享,可在线阅读,更多相关《sap学习资料badg.docx(27页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、Day2Your First ABAP/4 Program Before Proceeding Exploring the Development Environment Discovering Program Types o Defining Reports o Defining Dialog Programs Discovering Report Components o Discovering the Program Runtime Object o Introducing Program Naming Conventions Creating Your First Program Ex
2、ploring the Source Code Editor o Using the Editor: Initial Screen o Exploring the Functionality of the Source Code Editor Getting Help o Obtaining F1 Help o Obtaining R3 Library Help Finding Your Development Objects Introducing the R/3 Data Dictionary o Exploring Tables and Structures o Displaying a
3、 Table or Structure Definition o Displaying Data in the Table o Determining Displayed Fields Understanding ABAP/4 Syntax o Introducing the select Statement o Understanding Table Work Areas o Introducing the where Clause o Working with System Variables o Using the Chain Operator o Using the select si
4、ngle Statement o Commenting Code and Formal Documentation Summary Q&A Workshop o Quiz o Editor Exercises o Programming Exercises After you complete this chapter, you should be able to: Create and modify simple ABAP/4 programs. Use standard functions in the ABAP/4 editor. Use F1 and R/3 Library help
5、functions. Find your programs using the Object Browser and the editor. Display a table and its contents using the Data Dictionary. Use the tables and select statements. Chain statements together using the chain operator. Add comments and documentation to your programs. Before ProceedingBefore procee
6、ding, you should: Be comfortable with a programming language such as C, COBOL, or Visual Basic. To obtain the full benefit from this and all following chapters, you should also have two or more years of previous development experience. Set up your interface as recommended in Day 1 in the section The
7、 Interface Menu, if you have not done so already. Perform the install procedure for the ScreenCams on the CD-ROM. The install procedure is described in the readme.txt file found in the root directory of the CD-ROM. Many of the procedures in this book are demonstrated using ScreenCams. ScreenCams are
8、 like movies; they show a series of screens, including keystrokes and mouse movements, with a descriptive voiceover. They can be found on the CD-ROM that comes with this book. See the readme.txt file found in the root directory of the CD-ROM for more information. Exploring the Development Environmen
9、tA development object is anything created by a developer. Examples of development objects are programs, screens, tables, views, structures, data models, messages, and includes. The R/3 system contains tools for creating and testing development objects. These tools are located in the R/3 Development
10、Workbench. To access any development tool, you go to the workbench. The workbench contains these tools to help you create development objects: The ABAP/4 program editor where you can create and modify ABAP/4 source code and other program components The Data Dictionary where you can create tables, st
11、ructures, and views The Data modeler where you can document the relationships between tables The Function library where you can create global ABAP/4 function modules The screen and menu painters where you can create a user interface for your programs The following testing and search tools are also a
12、vailable: the ABAP/4 Debugger the SQL trace tool used to tune SQL statements the runtime analyzer for optimizing your programs performance a where-used tool for impact analysis a computer-aided test tool for regression testing a repository search tool for finding development objects the Workbench Or
13、ganizer for recording changes to objects and promoting them into production All development objects are portable, meaning that you can copy them from one R/3 system to another. This is usually done to move your development objects from the development system to the production system. If the source a
14、nd target systems are on different operating systems or use different database systems, your development objects will run as-is and without any modification. This is true for all platforms supported by R/3. (For a list of supported hardware and operating systems, refer to Table 1.1.) Discovering Pro
15、gram TypesThere are two main types of ABAP/4 programs: reports dialog programs Defining ReportsThe purpose of a report is to read data from the database and write it out. It consists of only two screens (see Figure 2.1). Figure 2.1:The selection screen and the output screen. The first screen is call
16、ed the selection screen. It contains input fields allowing the user to enter criteria for the report. For example, the report may produce a list of sales for a given date range, so the date range input fields would appear on the reports selection screen. The second screen is the output screen. It co
17、ntains the list. The list is the output from the report, and usually does not have any input fields. In our example, it would contain a list of the sales that occurred within the specified date range. The selection screen is optional. Not all reports have one. However, all reports generate a list. I
18、n this book, you will learn how to create report programs. Defining Dialog ProgramsDialog programs are more flexible than reports, and so are more complex at the program level. They can contain any number of screens, and the screen sequence can be changed dynamically at run time. On each screen, you
19、 can have input fields, output fields, pushbuttons, and more than one scrollable area. Discovering Report ComponentsABAP/4 reports consist of five components (shown in Figure 2.2): Figure 2.2.The components of an ABAP/4 program. Source code Attributes Text elements Documentation Variants Only the so
20、urce code and program attribute components are required. The rest of the components are optional. All development objects and their components are stored in the R/3 database. For example, the source code for a report is stored in database table dd010s. Discovering the Program Runtime ObjectABAP/4 pr
21、ograms are interpreted; they are not compiled. The first time you execute a program, the system automatically generates a runtime object. The runtime object is a pre-processed form of the source code. However, it is not an executable that you can run at the operating system level. Instead, it requir
22、es the R/3 system to interpret it. The runtime object is also known as the generated form of the program. If you change the source code, the runtime object is automatically regenerated the next time you execute the program. Introducing Program Naming ConventionsThe company you work for is a customer
23、 of SAP. Therefore, programs that you create at your company are called customer programs. Customer development objects must follow naming conventions that are predefined by SAP. These conventions are called the customer name range. For programs, the customer name range is two to eight characters lo
24、ng and the program name must start with the letter y or z. SAP reserves the letters a through x for their own programs. Please take a moment now to choose a unique 3-character identifier for your programs. Within this book, Ill refer to this identifier as your handle. It must begin with a y or z. Fo
25、r example, you might use the letter z followed by your two initials. The notation will indicate where you should use your handle. For example, if you chose zkg and you see the direction Enter a program name of abc, you would enter zkgabc. I recommend that as you go through this book, you should use
26、your handle as the first three characters of all development objects you create. If you do, they will be easy to recognize later, and easy to find. The program naming conventions adopted for this book are as follows: Sample programs from the text of chapters follow the convention ztxccnn, where cc i
27、s the chapter number and nn is a sequential number from 01 to 99. Program names used in exercises follow the convention ztyccnn, where cc is the chapter number and nn is a sequential number. The program name for the solution will be ztzccnn. Utility programs provided on the CD-ROM follow the naming
28、convention y-xxxxxx, where xxxxxx is the name of the utility. The setup program that creates development objects and loads them with data for the exercises is called y-setup. If necessary, it can be re-run at any time to restore the exercise data to its original condition. To remove all the developm
29、ent objects and data created by the setup program from the system, run y-uninst. See the readme.txt file on the CD-ROM for more information. Creating Your First ProgramWhat follows is a description of the process you will follow to create a program. When you sign on to R/3 to create your first ABAP/
30、4 program, the first screen you see will be the SAP main menu. From there, you will go to the Development Workbench, and then to the editor. You will enter a program name, and create the program. The first screen you will see will be the Program Attributes screen. There, you must enter the program a
31、ttributes and save them. You will then be allowed to proceed to the source code editor. In the source code editor, youll enter source code, save it, and then execute the program. Start the ScreenCam How to Create Your First Program now. Follow this procedure to create your first program. Help with c
32、ommon problems is given in the Troubleshooter that follows it. If you have trouble with any one of the steps, dont forget to consult the Troubleshooter. 1. From the R/3 main menu, select the menu path Tools-ABAP/4 Workbench. A screen with the title ABAP/4 Development Workbench is displayed. 2. Press
33、 the ABAP/4 Editor button on the application toolbar. The ABAP/4 Editor: Initial Screen is displayed. 3. In the Program field, type the program name 0201. 4. Press the Create button. The ABAP/4: Program Attributes screen is displayed. The fields containing question marks are required. 5. Type My Fir
34、st ABAP/4 Program in the Title field. By default, the contents of this field will appear at the top of the list. 6. Type 1 in the Type field. A 1 indicates the program is a report. 7. Type an asterisk (*) in the Application field. The value in the Application field indicates to which application are
35、a this program belongs. The complete list of values can be obtained by positioning your cursor on this field and then clicking on the down-arrow to the right of it. For example, if this program belongs to Inventory management, you would put an L in the Application field. Since this is a simple test
36、program, I have used an asterisk to indicate that this program does not belong to any particular application area. 8. Tickmark the Editor Lock check box. Enabling Editor lock will prevent changes to the program by anyone other than the creator. For your exercises, tickmark this box to safeguard your
37、 programs from accidental modification by others. However, you should not use this to lock actual development programs. It will prevent other programmers from maintaining them later. 9. To save the program attributes, press the Save button on the Standard toolbar. The Create Object Catalog Entry scr
38、een is displayed. 10. Press the Local Object button. The program attributes screen is redisplayed. In the status bar at the bottom of the screen, the message Attributes for program saved appears. (Note: the message you see will contain the program name too, but since this name will vary for each use
39、r, it is left out of the text in the book. This convention of leaving the development object name out of the message will be carried throughout the book.) 11. Press the Source Code button on the application toolbar. The ABAP/4 Editor: Edit Program screen is displayed. 12. Choose the menu path Settin
40、gs-Editor Mode. The Editor: Settings screen is displayed. 13. Choose the radio button PC Mode With Line Numbering. 14. Choose the radio button Lower Case. 15. Press the Copy button (the green check mark). You have now saved your editor settings. (Editor settings only need to be set once.) 16. Look a
41、t line 1. If it does not contain the statement report 0201., type it now, as shown in Listing 2.1. 17. On line 2, type write Hello SAP world. Use single quotes and put a period at the end of the line. 18. Press the Save button on the Standard toolbar. 19. To execute your program, choose the menu pat
42、h Program-Execute. A screen with the title My First ABAP/4 Program is displayed, and the words Hello SAP world are written below it. This is the output of the report, also known as the list. Listing 2.1Your First ABAP/4 Program 1 report ztx0201.2 write Hello SAP World.The code in Listing 2.1 produce
43、s this output: Hello SAP WorldCongratulations, you have just written your first ABAP/4 program! To return to the editor, press the green arrow button on the standard toolbar (or the F3 key). These are the Common Problems Encountered While Creating a Program and Their SolutionsTroubleSolutionWhen you
44、 press the Create button, you get a dialog box saying Do Not Create Objects in the SAP Name Range. You have entered the wrong program name. Your program names must start with y or z. Press the Cancel button (the red X) to return and enter a new program name. When you press the Create button, you get
45、 a dialog box with an input field asking for a key. You have entered the wrong program name. Your program names must start with y or z. Press the Cancel button (the red X) to return and enter a new program name. You are getting a Change Request Query screen asking for a Request Number. On the Create
46、 Object Catalog Entry screen, do not enter a value in the Development class field. Press the Local Object button instead. Exploring the Source Code EditorIn this section you will learn how to harness the power of the ABAP/4 editor. You will learn to use two screens in this section: ABAP/4 Editor: In
47、itial Screen ABAP/4 Editor: Edit Program screen Using the Editor: Initial ScreenThe ABAP/4 Editor: Initial Screen is shown in Figure 2.3. From there, you can display or change all program components. For example, to change the source code component, choose the Source Code radio button and then press
48、 the Change button. Or, to display the attributes component, choose the Attributes radio button and then press the Display button. Figure 2.3.From the ABAP/4 Editor: Initial Screen you can display or change program com-ponents.TIPIn Figure 2.3, notice that the Object Components group box encloses radio buttons, the Display button, and the Change button. When you see a group box enclosing both radio buttons and pushbuttons, the ra