⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch09.htm

📁 这个是sap开发语言abap的教育文档
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>

<HEAD>
<SCRIPT LANGUAGE="JavaScript">


<!--

function popUp(pPage) {
 popUpWin = window.open('','popWin','resizable=yes,scrollbars=no,width=525,height=394');
 figDoc= popUpWin.document;
 zhtm= '<HTML><HEAD><TITLE>' + pPage + '</TITLE>';
 zhtm += '</head>';
 zhtm += '<BODY bgcolor="#FFFFFF">';
 zhtm += '<IMG SRC="' + pPage + '">';
 zhtm += '<P><B>' + pPage + '</B>';
 zhtm += '</BODY></HTML>';
 figDoc.write(zhtm);
 figDoc.close();
 popUpWin.focus();
 }

//-->


</SCRIPT>

        <META NAME="GENERATOR" Content="Symantec Visual Page 1.0.1">
        <META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1">
        <TITLE>Sams Teach Yourself ABAP/4&reg; in 21 Days -- Day 9- Assignments, Conversions, and Calculations</TITLE>
</HEAD>

<BODY TEXT="#000000" BGCOLOR="#FFFFFF">

<CENTER>
<H1><IMG SRC="../button/sams.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/sams.gif" BORDER="0"></H1>
</CENTER>
<CENTER>
<P><A HREF="../ch08/ch08.htm" tppabs="http://pbs.mcp.com/ebooks/0672312174/ch08/ch08.htm"><IMG SRC="../button/previous.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/previous.gif" BORDER="0"></A>
<A HREF="../index.htm" tppabs="http://pbs.mcp.com/ebooks/0672312174/index.htm"><IMG SRC="../button/contents.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/contents.gif" BORDER="0"></A> 
<A HREF="../ch10/ch10.htm" tppabs="http://pbs.mcp.com/ebooks/0672312174/ch10/ch10.htm"><IMG SRC="../button/next.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/next.gif" BORDER="0"></A> 

<H1>Sams Teach Yourself ABAP/4<sup>&reg;</sup> in 21 Days</H1></CENTER>
<HR SIZE=4>




<H1>Day&nbsp;9</H1>
<H1>Assignments, Conversions, and Calculations</H1>


<UL>
<LI><A HREF="#ChapterObjectives">
Chapter Objectives</A>
<LI><A HREF="#BeforeProceeding">
Before Proceeding</A>
<LI><A HREF="#WorkingwithSystemVariables">
Working with System Variables</A>
<LI><A HREF="#FindingSystemVariables">
Finding System Variables</A>
<LI><A HREF="#AssignmentStatements">
Assignment Statements</A>
<UL>
<LI><A HREF="#UsingtheTTFONTSIZEclearFONTTTFONTSIZEStatementFONT">
Using the <TT>clear</TT>
Statement</A>
<LI><A HREF="#UsingtheTTFONTSIZEmoveFONTTTFONTSIZEStatementFONT">
Using the <TT>move</TT> Statement
</A>
<LI><A HREF="#UsingtheTTFONTSIZEmovecorrespondingFONTTTFONTSIZEStatementFONT">
Using the <TT>move-corresponding</TT>
Statement</A>
<LI><A HREF="#PerformingCalculations">
Performing Calculations</A>
</UL>
<LI><A HREF="#DynamicAssignment">
Dynamic Assignment</A>
<LI><A HREF="#Summary">
Summary</A>
<LI><A HREF="#QampA">
Q&amp;A</A>
<LI><A HREF="#Workshop">
Workshop</A>
<UL>
<LI><A HREF="#Quiz">
Quiz</A>
<LI><A HREF="#Exercise">
Exercise 1</A>
</UL></UL>

<HR>
<H2><A NAME="ChapterObjectives"><FONT SIZE=5 COLOR=#FF0000>
Chapter Objectives</FONT></A></H2>
<P>
After you complete this chapter, you will be able to:
<UL>
<LI>Use common system variables and be able to display or find
any system variable
<LI>Use the <TT>clear</TT> statement and understand its effect
on variables and field strings
<LI>Perform assignments using the <TT>move</TT> and <TT>move-corresponding</TT>
statements
<LI>Predict and perform data conversions using assignment statements
<LI>Code mathematical expressions
</UL>
<H2><A NAME="BeforeProceeding"><FONT SIZE=5 COLOR=#FF0000>
Before Proceeding</FONT></A></H2>
<P>
Programs in this and the following chapters use input and output
formats that are set in the user defaults and can be different
for each user. Before proceeding, it is a good idea to set your
user defaults to match those in this book so that your output
matches the output listings in this book.
<P>
Please set your user defaults now by following this procedure:
<OL>
<LI>If you are currently in the R/3 system, save all your work
now.
<LI>From any screen, choose the menu path System-&gt;User Profile-&gt;User
Defaults. The <TT>Maintain User: Defaults</TT> screen is displayed.
<LI>In the <TT>Date Format</TT> group box, choose the YYYY/MM/DD
radio button.
<LI>In the Decimal<B> </B>Notation<B> </B>group box, choose the
Period radio button.
<LI>Press the Save button on the Application toolbar. At the bottom
of the window, the message <TT>Values for user <I>xxxxx</I>
saved</TT> is displayed. Changes to your user profile are not
effective until the next time you log on.
<LI>Choose the menu path System-&gt;Log Off. The Log Off dialog
box is displayed.
<LI>Press the Yes button. You are logged off of the system.
</OL>
<P>
Your new user defaults will be in effect the next time you log
on.
<H2><A NAME="WorkingwithSystemVariables"><FONT SIZE=5 COLOR=#FF0000>
Working with System Variables</FONT></A></H2>
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/newterm.gif">
<P>
There are 176<I> system variables</I> available within every ABAP/4
program. You do not have to define them; they are automatically
defined and are always available.
<P>
To display a list of system variables, display the DDIC structure
<TT>syst</TT>. You can display it by using the Dictionary: Initial
Screen, or by double-clicking on the name of any system variable
in your program. The first page of <TT>syst</TT> is shown in Figure
9.1.
<P>
<A HREF="javascript:popUp('f9-1.gif')"><B>Figure 9.1 :</B> <I>This is the structure syst. It contains
the definitions for all system variables. The Column Right; Next
. . . button scrolls right one column at a time, causing the entire
length of the Short Text to scroll into view</I>.</A>
<P>
In Figure 9.1, the field names appear in the first column and
the descriptions are on the right in the Short Text column. To
view the entire description, scroll to the right by clicking on
the Column Right; Next . . . button at the bottom of the screen.
<P>
To find a field by name, press the Find button on the Standard
toolbar. The Find Field screen will appear, asking for the name
of the field that you want to find.
<P>
The alias for <TT>syst</TT> is <TT>sy</TT> (pronounced <I>sigh</I>).
In your code, you can use either name. For example, you can code
either <TT>sy-datum</TT> or <TT>syst-datum</TT>; they are exactly
equivalent. Most programmers use <TT>sy</TT>. Table 9.1 contains
a short list of commonly used system variables. Additional variables
are introduced throughout the book.<BR>
<P>
<CENTER><B>Table 9.1&nbsp;&nbsp;Commonly Used System Variables</B></CENTER><CENTER>
<TABLE BORDERCOLOR=#000000 BORDER=1>
<TR VALIGN=TOP><TD WIDTH=96><CENTER><B>Name</B></CENTER></TD><TD WIDTH=288><CENTER><B>Description</B></CENTER>
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=96><CENTER><TT>sy-datum</TT></CENTER></TD><TD WIDTH=288>Current date
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=96><CENTER><TT>sy-uzeit</TT></CENTER></TD><TD WIDTH=288>Current time
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=96><CENTER><TT>sy-uname</TT></CENTER></TD><TD WIDTH=288>Current user id
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=96><CENTER><TT>sy-subrc</TT></CENTER></TD><TD WIDTH=288>Last return code
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=96><CENTER><TT>sy-mandt</TT></CENTER></TD><TD WIDTH=288>Logon client
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=96><CENTER><TT>sy-pagno</TT></CENTER></TD><TD WIDTH=288>Current output page number
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=96><CENTER><TT>sy-colno</TT></CENTER></TD><TD WIDTH=288>Current output column number
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=96><CENTER><TT>sy-linno</TT></CENTER></TD><TD WIDTH=288>Current output list line number
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=96><CENTER><TT>sy-vline</TT></CENTER></TD><TD WIDTH=288>Vertical line
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=96><CENTER><TT>sy-uline</TT></CENTER></TD><TD WIDTH=288>Horizontal line
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=96><CENTER><TT>sy-repid</TT></CENTER></TD><TD WIDTH=288>Current report name
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=96><CENTER><TT>sy-cprog</TT></CENTER></TD><TD WIDTH=288>Main program name
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=96><CENTER><TT>sy-tcode</TT></CENTER></TD><TD WIDTH=288>Current transaction code
</TD></TR>
<TR VALIGN=TOP><TD WIDTH=96><CENTER><TT>sy-dbcnt</TT></CENTER></TD><TD WIDTH=288>Within a <TT>select</TT>, contains the current iteration counter. After the <TT>endselect</TT>, contains number of rows that match the <TT>where</TT> clause.
</TD></TR>
</TABLE>
</CENTER>
<P>
Listing 9.1 shows a sample program that uses system variables.
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 9.1&nbsp;&nbsp;Using Basic System Variables<BR>
</B>
<BLOCKQUOTE>
<PRE>
 1 report ztx0901.
 2 tables ztxlfa1.
 3 parameters `land1 like ztxlfa1-land1 obligatory default 'US'.
 4 write: / 'Current date:', sy-datum,
 5        / 'Current time:', sy-uzeit,
 6        / 'Current user:', sy-uname,
 7        / 'Vendors having country code', `land1,
 8        /.
 9 select * from ztxlfa1
10     where land1 = `land1
11     order by lifnr.
12     write: / sy-dbcnt, ztxlfa1-lifnr.
13     endselect.
14 write: / sy-dbcnt, 'records found'.
15 if sy-subrc &lt;&gt; 0.
16     write: / 'No vendors exist for country', 'land1.
17     endif.
</PRE>
</BLOCKQUOTE>
<HR>
<P>
<IMG SRC="../button/output.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/output.gif">
<P>
The code in Listing 9.1 produces this output:
<BLOCKQUOTE>
<PRE>
Current date: 1998/02/22
Current time: 14:38:24
Current user: KENGREENWOOD
Vendors having country code US

         1  1040
         2  1080
         3  1090
         4  2000
         5  V1
         6  V2
         7  V3
         8  V4
         9  V5
        10  V7
        10  records found
</PRE>
</BLOCKQUOTE>
<P>
<IMG SRC="../button/analysis.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/analysis.gif">
<UL>
<LI>Line 2 defines a field string <TT>ztxlfa1</TT> exactly like
the table of the same name.
<LI>Line 3 defines a single input parameter <TT>`land1</TT>.
<LI>On lines 4 through 6, the current date, time, and user id
are written out from system variables <TT>sy-datum</TT>, <TT>sy-uzeit</TT>,
and <TT>sy-uname</TT>.
<LI>Line 7 writes out the country code that was entered in the
parameter input field <TT>`land1</TT> on the selection screen.
<LI>Line 8 writes out a blank line.
<LI>Line 9 selects records from table <TT>ztxlfa1</TT> and places
them one at a time into field string <TT>ztxlfa1</TT>.
<LI>Line 10 restricts the selection of records to only those having
a country code equal to the one entered on the selection screen.
<LI>Line 11 causes the records to be sorted in ascending order
by <TT>lifnr</TT> (vendor number).
<LI>Line 12 writes out the current iteration number from system
variable <BR>
<TT>sy-dbcnt</TT> and a vendor number from each record.
<LI>Line 13 marks the end of the <TT>select</TT>/<TT>endselect</TT>
loop.
<LI>Line 14 writes out the total number of iterations of the <TT>select</TT>
loop. This is the same as the number of records that matched the
<TT>where</TT> clause using system variable <TT>sy-dbcnt</TT>.
<LI>On line 15, the return code from the <TT>select</TT>, contained
in system variable <TT>sy-subrc</TT>, is tested. If it is zero,
records were found. If it is non-zero, no records were found and
a message is written out on line 16.
</UL>
<H2><A NAME="FindingSystemVariables"><FONT SIZE=5 COLOR=#FF0000>
Finding System Variables</FONT></A></H2>
<P>
Suppose you need to write a program that, given a country code
as an input parameter, writes out the country description from
table <TT>ztxt005t</TT> in the user's current logon language.
As you might recall, <TT>ztxt005t</TT> is a text table containing
country code descriptions in multiple languages. The primary key
is <TT>mandt</TT>, <TT>spras</TT> (language), and <TT>land1</TT>.
A sample solution is shown in Listing 9.2, but it is missing one
crucial piece of information on line 5: the value of the current
logon language.
<P>
Listing 9.2 is missing a variable at the position indicated by
the question mark. When working with ABAP/4, you are often faced
with the challenge of finding variables containing the information
you need.
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 9.2&nbsp;&nbsp;A Sample Program with a sy Variable
Missing<BR>
</B>
<BLOCKQUOTE>
<PRE>
 1 report ztx0902.
 2 tables ztxt005t.
 3 parameters `land1 like ztxlfa1-land1 obligatory default 'US'.
 4 select single * from ztxt005t
 5     where spras = ?             &quot;current logon language
 6     and   land1 = `land1.
 7 if sy-subrc = 0.
 8     write: 'Description:', ztxt005t-landx.
 9 else.
10     write: 'No description exists for', `land1.
11     endif.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -