📄 ch02.htm
字号:
<P>
<A HREF="javascript:popUp('f2-2.gif')"><B>Figure 2.2.</B><I>The components of an ABAP/4 program</I>.</A>
<UL>
<LI>Source code
<LI>Attributes
<LI>Text elements
<LI>Documentation
<LI>Variants
</UL>
<P>
Only the source code and program attribute components are required.
The rest of the components are optional.
<P>
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 <TT>dd010s</TT>.
<H3><A NAME="DiscoveringtheProgramRuntimeObject">
Discovering the Program Runtime Object</A></H3>
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://ebooks.cs.biu.ac.il/0672312174/button/newterm.gif">
<P>
ABAP/4 programs are interpreted; they are not compiled. The first
time you execute a program, the system automatically generates
a <I>runtime object</I>. 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 requires
the R/3 system to interpret it. The runtime object is also known
as the <I>generated form</I> of the program.
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://ebooks.cs.biu.ac.il/0672312174/button/newterm.gif">
<P>
If you change the source code, the runtime object is automatically
regenerated the next time you execute the program.
<H3><A NAME="IntroducingProgramNamingConventions">
Introducing Program Naming Conventions</A></H3>
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://ebooks.cs.biu.ac.il/0672312174/button/newterm.gif">
<P>
The company you work for is a customer of SAP. Therefore, programs
that you create at your company are called <I>customer</I> <I>programs</I>.
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://ebooks.cs.biu.ac.il/0672312174/button/newterm.gif">
<P>
Customer development objects must follow naming conventions that
are predefined by SAP. These conventions are called the <I>customer
name range</I>. For programs, the customer name range is two to
eight characters long and the program name must start with the
letter <TT>y</TT> or <TT>z</TT>. SAP reserves the letters <TT>a</TT>
through <TT>x</TT> for their own programs.
<P>
Please take a moment now to choose a unique 3-character identifier
for your programs. Within this book, I'll refer to this identifier
as your <I>handle</I>. It must begin with a <TT>y</TT> or <TT>z</TT>.
For example, you might use the letter <TT>z</TT> followed by your
two initials. The notation will indicate where you should
use your handle. For example, if you chose <TT>zkg</TT> and you
see the direction "Enter a program name of <TT>abc</TT>,"
you would enter <TT>zkgabc</TT>. I recommend that as you go through
this book, you should use 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.
<P>
The program naming conventions adopted for this book are as follows:
<UL>
<LI>Sample programs from the text of chapters follow the convention
<TT>ztx<I>ccnn</I></TT><B>,</B>
where <TT><I>cc</I></TT> is the
chapter number and <TT><I>nn</I></TT>
is a sequential number from 01 to 99.
<LI>Program names used in exercises follow the convention <TT>zty<I>ccnn</I></TT><B>,</B>
where <TT><I>cc</I></TT> is the
chapter number and <TT><I>nn</I></TT>
is a sequential number. The program name for the solution will
be <TT>ztzccnn</TT>.
<LI>Utility programs provided on the CD-ROM follow the naming
convention <TT>y-<I>xxxxxx</I></TT>,
where <I>xxxxxx</I> is the name of the utility.
</UL>
<P>
The setup program that creates development objects and loads them
with data for the exercises is called <TT>y-setup</TT><B>.</B>
If necessary, it can be re-run at any time to restore the exercise
data to its original condition. To remove all the development
objects and data created by the setup program from the system,
run <TT>y-uninst</TT>. See the <TT>readme.txt</TT> file on the
CD-ROM for more information.
<H2><A NAME="CreatingYourFirstProgram"><FONT SIZE=5 COLOR=#FF0000>
Creating Your First Program</FONT></A></H2>
<P>
What follows is a description of the process you will follow to
create a program.
<P>
When you sign on to R/3 to create your first ABAP/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 attributes and save them. You will
then be allowed to proceed to the source code editor. In the source
code editor, you'll enter source code, save it, and then execute
the program.
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://ebooks.cs.biu.ac.il/0672312174/button/newterm.gif">
<P>
Start the ScreenCam "How to Create Your First Program"
now.
<P>
Follow this procedure to create your first program. Help with
common problems is given in the Troubleshooter that follows it.
If you have trouble with any one of the steps, don't forget to
consult the Troubleshooter.
<OL>
<LI>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.
<LI>Press the ABAP/4 Editor button on the application toolbar.
The ABAP/4 Editor: Initial Screen is displayed.
<LI>In the Program field, type the program name <TT>0201</TT>.
<LI>Press the Create button. The ABAP/4: Program Attributes screen
is displayed. The fields containing question marks are required.
<LI>Type <TT>My First ABAP/4 Program</TT> in the Title field.
By default, the contents of this field will appear at the top
of the list.
<LI>Type <TT>1</TT> in the Type field. A <TT>1</TT> indicates
the program is a report.
<LI>Type an asterisk (<TT>*</TT>) in the Application field. The
value in the Application field indicates to which application
area 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 program, I have used an asterisk
to indicate that this program does not belong to any particular
application area.
<LI>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 programs
from accidental modification by others. However, you should <I>not</I>
use this to lock actual development programs. It will prevent
other programmers from maintaining them later.
<LI>To save the program attributes, press the Save button on the
Standard toolbar. The Create Object Catalog Entry screen is displayed.
<LI>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 user, 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.)
<LI>Press the Source Code button on the application toolbar. The
ABAP/4 Editor: Edit Program screen is displayed.
<LI>Choose the menu path Settings->Editor Mode. The Editor:
Settings screen is displayed.
<LI>Choose the radio button PC Mode With Line Numbering.
<LI>Choose the radio button Lower Case.
<LI>Press the Copy button (the green check mark). You have now
saved your editor settings. (Editor settings only need to be set
once.)
<LI>Look at line 1. If it does not contain the statement <TT>report
</TT> <TT>0201.</TT>, type it now, as shown in Listing 2.1.
<LI>On line 2, type <TT>write 'Hello SAP world'.</TT> Use single
quotes and put a period at the end of the line.
<LI>Press the Save button on the Standard toolbar.
<LI>To execute your program, choose the menu path Program->Execute.
A screen with the title My First ABAP/4 Program is displayed,
and the words <TT>Hello SAP world</TT> are written below it. This
is the output of the report, also known as the <I>list</I>.
</OL>
<P>
<P>
<IMG SRC="../button/input.gif" tppabs="http://ebooks.cs.biu.ac.il/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 2.1 Your First ABAP/4 Program <BR>
</B>
<BLOCKQUOTE>
<PRE>
1 report ztx0201.
2 write 'Hello SAP World'.
</PRE>
</BLOCKQUOTE>
<HR>
<P>
<IMG SRC="../button/output.gif" tppabs="http://ebooks.cs.biu.ac.il/0672312174/button/output.gif">
<P>
The code in Listing 2.1 produces this output:
<BLOCKQUOTE>
<PRE>
Hello SAP World
</PRE>
</BLOCKQUOTE>
<P>
Congratulations, 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).
<P>
<CENTER><B>These are the Common Problems Encountered While Creating
a Program and Their Solutions</B></CENTER><CENTER>
<TABLE BORDERCOLOR=#000000 BORDER=1>
<TR VALIGN=TOP><TD WIDTH=240><CENTER><B>Trouble</B></CENTER></TD><TD WIDTH=288><CENTER><B>Solution</B></CENTER>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=240>When you press the Create button, you get a dialog box saying Do Not Create Objects in the SAP Name Range.
</TD><TD WIDTH=288>You have entered the wrong program name. Your program names must start with <TT>y</TT> or <TT>z</TT>. Press the Cancel button (the red X) to return and enter a new program name.
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=240>When you press the Create button, you get a dialog box with an input field asking for a key.
</TD><TD WIDTH=288>You have entered the wrong program name. Your program names must start with <TT>y</TT> or <TT>z</TT>. Press the Cancel button (the red X) to return and enter a new program name.
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=240>You are getting a Change Request Query screen asking for a Request Number.
</TD><TD WIDTH=288>On the Create Object Catalog Entry screen, do not enter a value in the Development class field.
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=240> </TD><TD WIDTH=288>Press the Local Object button instead.
</TD></TR>
</TABLE>
</CENTER>
<P>
<H2><A NAME="ExploringtheSourceCodeEditor"><FONT SIZE=5 COLOR=#FF0000>
Exploring the Source Code Editor</FONT></A></H2>
<P>
In 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:
<UL>
<LI>ABAP/4 Editor: Initial Screen
<LI>ABAP/4 Editor: Edit Program screen
</UL>
<H3><A NAME="UsingtheEditorInitialScreen">
Using the Editor: Initial Screen</A></H3>
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://ebooks.cs.biu.ac.il/0672312174/button/newterm.gif">
<P>
The 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 the Change button. Or, to display the attributes
component, choose the Attributes radio button and then press the
Display button.
<P>
<A HREF="javascript:popUp('f2-3.gif')"><B>Figure 2.3.</B><I>From the ABAP/4 Editor: Initial Screen you can display or change program com-ponents</I>.</A>
<P>
<CENTER>
<TABLE BORDERCOLOR=#000000 BORDER=1>
<TR VALIGN=TOP><TD WIDTH=600><B>TIP</B></TD></TR>
<TR VALIGN=TOP><TD WIDTH=600>
<BLOCKQUOTE>
In 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 radio buttons deter-mine the component acted upon by the enclosed pushbuttons. The effect of the radio buttons is limited by the group box; they have no effect on push-buttons outside the box.</BLOCKQUOTE>
</TD></TR>
</TABLE>
</CENTER>
<P>
<P>
Pressing the Change button displays the selected component in
<I>change mode</I>, which enables you to change the component.
<H3><A NAME="ExploringtheFunctionalityoftheSourceCodeEditor">
Exploring the Functionality of the Source Code Editor</A></H3>
<P>
From the ABAP/4 Editor: Initial Screen, choose the Source Code
radio button and press the Change button. The ABAP/4 Editor: Edit
Program screen is shown, as in Figure 2.4.<BR>
<BR>
<P>
<A HREF="javascript:popUp('f2-4.gif')"><B>Figure 2.4.</B><I>Use the ABAP/4 Editor: Edit Program screen to change com-ponent functionality</I>.</A>
<p>
<CENTER>
<TABLE BORDERCOLOR=#000000 BORDER=1>
<TR VALIGN=TOP><TD WIDTH=600><B>TIP</B></TD></TR>
<TR VALIGN=TOP><TD WIDTH=600>
<BLOCKQUOTE>
Many developers find the R/3 user interface complex and therefore difficult to learn. I suggest that you adopt a methodical approach that enables you to become comfortable with each new screen. Whenever you come across a new screen, slowly scan the menu items and buttons. Begin at the top left corner of the screen and work down and to the right. Hold your cursor over each item long enough to read it and its accompanying ToolTip. Taking a few minutes on each new screen will help you become familiar with the functions available.</BLOCKQUOTE>
</TD></TR>
</TABLE>
</CENTER>
<P>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -