📄 ch09.htm
字号:
</PRE>
</BLOCKQUOTE>
<HR>
<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>ztxt005t</TT> exactly like
the table of the same name.
<LI>Line 3 defines a single input parameter <TT>`land1</TT>.
<LI>Lines 4 through 6 select a single record from table <TT>ztxt005t</TT>
into field string <TT>ztxt005t</TT> using the current logon language
from a yet-unknown source and the country code from parameter
<TT>`land1</TT>. There is no <TT>endselect</TT> because this is
a <TT>select single</TT> statement. It only returns a single record;
no loop is created.
<LI>Line 7 checks the return code from the <TT>select</TT> and,
if a record was found, writes out the description on line 8. If
a record was not found, line 10 writes out an appropriate message.
</UL>
<P>
The current logon language is available from a system variable.
Unfortunately, to use the Find button on the Application toolbar
you need to know the name of the field. You do not know the name
of the field, so the Find button is of little use. Instead, use
the following procedure to search the <I>descriptions</I> of the
<TT>syst</TT> structure.<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>
This procedure is very handy because it can be used to search the descrip-tions of any structure or table.</BLOCKQUOTE>
</TD></TR>
</TABLE>
</CENTER>
<P>
<P>
<IMG SRC="../button/screencam.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/screencam.gif">
<P>
Start the ScreenCam "How to Search the Descriptions of a
Structure or Table" now.
<P>
To search the descriptions of a structure or table:
<OL>
<LI>Begin at the Dictionary: Table/Structure: Display Fields screen.
<LI>Choose the menu path Table->Print. The Print Table Manual
screen is displayed. Here you specify which details you want to
see.
<LI>Tickmark all fields and press the Continue button. The Print:
screen is displayed.
<LI>If the Output Device field is blank, position your cursor
in the field, press the down arrow, and choose any output device.
(It doesn't matter which device you choose; it won't be used.)
<LI>Press the Print Preview button at the bottom of the screen.
The Print Preview for <I>xxxx</I> Page 00001 of <I>nnnnn</I> screen
is displayed.
<LI>Choose the menu path Goto->List Display. The Print Preview
for <I>xxxx</I> screen is displayed.
<LI>Type <B>%sc</B> in the Command field on the Standard toolbar.
<LI>Press the Enter key. The Find screen is displayed.
<LI>In the Search For field, type a character string to be found.
If you are searching for the current logon language, you might
type <TT>language</TT>. Wildcard characters are not permitted.
<LI>Press the Find button. A second Find screen appears showing
the lines that contain the text you typed. Matches are highlighted.
<LI>To select a match, click once on a highlighted word. You are
returned to the Print Preview for <I>xxxx</I> screen; the list
is scrolled to the line you selected and the cursor is positioned
on that line.
<LI>To search again, press the down arrow at the end of the Command
field on the Standard toolbar. A drop-down box appears containing
the most recently entered commands.
<LI>Scroll, if necessary, to the %sc command and click on it.
%sc appears in the command field.
<LI>Press the Enter key. The Find screen is redisplayed.
<LI>Press the Find button. The search is performed starting at
the current line. The second Find screen is redisplayed and the
matches are shown.
<LI>Click once on any highlighted word to display it.
</OL>
<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>
For future reference, you can save the list on the Print Preview for <I>xxxx </I>to a text file on your hard drive. To do this, from the Print Preview for <I>xxxx </I>screen, choose the menu path System->List->Save->Local File. On the Save List in File. . . screen, choose the Unconverted radio button and press the Continue button. On the Transfer List to a Local File screen, type the name of a text file, for example, <TT>c:\temp\syst.txt</TT>, and then press the OK button. This creates the file on your hard drive. You can open and search through it using WordPad at any time, without having to use the "How to Search the Descriptions of a Structure or Table" procedure shown above.
</BLOCKQUOTE>
</TD></TR>
</TABLE>
</CENTER>
<P>
<P>
By following the preceding procedure, you have found that the
current logon language is stored in <TT>sy-langu</TT>. The completed
program appears in Listing 9.3.
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 9.3 Listing 9.2 with the Missing </B><TT><B>SY</B></TT><B>
Variable Added on Line 5<BR>
</B>
<BLOCKQUOTE>
<PRE>
1 report ztx0903.
2 tables ztxt005t.
3 parameters `land1 like ztxlfa1-land1 obligatory default 'US'.
4 select single * from ztxt005t
5 where spras = sy-langu "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.
</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.3 produces this output:
<BLOCKQUOTE>
<PRE>
Description: United States
</PRE>
</BLOCKQUOTE>
<P>
<IMG SRC="../button/analysis.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/analysis.gif">
<P>
Line 5 limits the <TT>select</TT> to return only records from
<TT>ztxt005t</TT> that have a language code equal to the current
logon language. Because <TT>mandt</TT> is automatically added
at the beginning of every <TT>where</TT>, the primary key is now
fully specified and a single, unique record is returned. Notice
that the primary index supports this <TT>select</TT>, so the fields
of the <TT>where</TT> clause have been specified in the same order
as they appear in the primary index.
<H2><A NAME="AssignmentStatements"><FONT SIZE=5 COLOR=#FF0000>
Assignment Statements</FONT></A></H2>
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/newterm.gif">
<P>
An <I>assignment statement</I> assigns a value to a variable or
field string. Three assignment statements are commonly used:
<UL>
<LI><TT>clear</TT>
<LI><TT>move</TT>
<LI><TT>move-corresponding</TT>
</UL>
<H3><A NAME="UsingtheTTFONTSIZEclearFONTTTFONTSIZEStatementFONT">
Using the <TT><FONT SIZE=4>clear</FONT></TT><FONT SIZE=4>
Statement</FONT></A></H3>
<P>
<IMG SRC="../button/newterm.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/newterm.gif">
<P>
The <TT>clear</TT> statement sets the value of a variable or a
field string to zeros. If the data type is <TT>c</TT>, the value
is instead set to blanks. Blanks and zeros are known as <I>default
initial values</I>. It is often said that <TT>clear</TT> assigns
default initial values to variables.
<H4>Syntax for the <TT>clear</TT> Statement</H4>
<P>
The following is the syntax for the <TT>clear</TT> statement.
<BLOCKQUOTE>
<PRE>
clear <I>v1</I> [with <I>v2</I> | with <I>'A'</I> | with NULL]
</PRE>
</BLOCKQUOTE>
<P>
where:
<UL>
<LI><TT><I>v1</I></TT> and <TT><I>v2</I></TT>
are variable or field string names.
<LI><TT><I>'A'</I></TT> is a literal
of any length.
</UL>
<P>
The following points apply:
<UL>
<LI>If <TT><I>v1</I></TT> is a
variable of type <TT>c</TT> without any additions, it is filled
with blanks. If <TT><I>v1</I></TT>
is any other data type, it is filled with zeros. If <TT><I>v1</I></TT>
is a field string, its individual components are set to blanks
or zeros depending on their individual data types.
<LI>Using the addition <TT>with <I>v2</I></TT>,
the first byte from <TT><I>v2</I></TT>
is used to fill the entire length of <TT><I>v1</I></TT>.
If <TT><I>v1</I></TT> is a field
string, it is treated as a variable of type <TT>c</TT>.
<LI>Using the addition <TT>with <I>'A'</I></TT>,
the entire length of <TT><I>v1</I></TT>
is filled using the first byte from literal <TT><I>'A'</I></TT>.
<LI>Using the addition <TT>with NULL</TT>, the entire length of
<TT><I>v1</I></TT> is filled with
hexadecimal zeros.
</UL>
<P>
Listing 9.4 shows a sample program that clears variables and field
strings.<P>
<CENTER>
<TABLE BORDERCOLOR=#000000 BORDER=1>
<TR VALIGN=TOP><TD WIDTH=600><B>NOTE</B></TD></TR>
<TR VALIGN=TOP><TD WIDTH=600>
<BLOCKQUOTE>
Listing 9.4 uses a new addition called <TT>no-gap </TT>on the <TT>write </TT>statement. <TT>No-gap </TT>causes the next output value to be written immediately after the current one without an intervening space.
</BLOCKQUOTE>
</TD></TR>
</TABLE>
</CENTER>
<P>
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 9.4 Variables Set to Blanks or Zeros by
the </B><TT><B>CLEAR</B></TT><B>
Statement<BR>
</B>
<BLOCKQUOTE>
<PRE>
1 report ztx0904.
2 tables ztxlfa1.
3 data: f1(2) type c value 'AB',
4 f2 type i value 12345,
5 f3 type p value 12345,
6 f4 type f value '1E1',
7 f5(3) type n value '789',
8 f6 type d value '19980101',
9 f7 type t value '1201',
10 f8 type x value 'AA',
11 begin of s1,
12 f1(3) type c value 'XYZ',
13 f2 type i value 123456,
14 end of s1.
15 ztxlfa1-lifnr = 'XXX'.
16 ztxlfa1-land1 = 'CA'.
17 write: / 'f1=''' no-gap, f1 no-gap, '''',
18 / 'f2=''' no-gap, f2 no-gap, '''',
19 / 'f3=''' no-gap, f3 no-gap, '''',
20 / 'f4=''' no-gap, f4 no-gap, '''',
21 / 'f5=''' no-gap, f5 no-gap, '''',
22 / 'f6=''' no-gap, f6 no-gap, '''',
23 / 'f7=''' no-gap, f7 no-gap, '''',
24 / 'f8=''' no-gap, f8 no-gap, '''',
25 / 's1-f1=''' no-gap, s1-f1 no-gap, '''',
26 / 's1-f2=''' no-gap, s1-f2 no-gap, '''',
27 / 'ztxlfa1-lifnr=''' no-gap, ztxlfa1-lifnr no-gap, '''',
28 / 'ztxlfa1-land1=''' no-gap, ztxlfa1-land1 no-gap, ''''.
29 clear: f1, f2, f3, f4, f5, f6, f7, f8, s1, ztxlfa1.
30 write: / 'f1=''' no-gap, f1 no-gap, '''',
31 / 'f2=''' no-gap, f2 no-gap, '''',
32 / 'f3=''' no-gap, f3 no-gap, '''',
33 / 'f4=''' no-gap, f4 no-gap, '''',
34 / 'f5=''' no-gap, f5 no-gap, '''',
35 / 'f6=''' no-gap, f6 no-gap, '''',
36 / 'f7=''' no-gap, f7 no-gap, '''',
37 / 'f8=''' no-gap, f8 no-gap, '''',
38 / 's1-f1=''' no-gap, s1-f1 no-gap, '''',
39 / 's1-f2=''' no-gap, s1-f2 no-gap, '''',
40 / 'ztxlfa1-lifnr=''' no-gap, ztxlfa1-lifnr no-gap, '''',
41 / 'ztxlfa1-land1=''' no-gap, ztxlfa1-land1 no-gap, ''''.
</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.4 produces this output:
<BLOCKQUOTE>
<PRE>
f1='AB'
f2=' 12,345 '
f3=' 12,345 '
f4=' 1.000000000000000E+01'
f5='789'
f6='19980101'
f7='120100'
f8='AA'
s1-f1='XYZ'
s1-f2=' 123,456 '
ztxlfa1-lifnr='XXX '
ztxlfa1-land1='CA '
f1=' '
f2=' 0 '
f3=' 0 '
f4=' 0.000000000000000E+00'
f5='000'
f6='00000000'
f7='000000'
f8='00'
s1-f1=' '
s1-f2=' 0 '
ztxlfa1-lifnr=' '
ztxlfa1-land1=' '
</PRE>
</BLOCKQUOTE>
<P>
<IMG SRC="../button/analysis.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/analysis.gif">
<UL>
<LI>Line 2 defines field string <TT>ztxlfa1</TT>.
<LI>Lines 4 through 10 define variables of every type and give
them default values.
<LI>Another field string, <TT>s1</TT>, is defined on line 11,
with default values for each component.
<LI>Values are assigned to two of the components for field string
<TT>ztxlfa1</TT> on lines 15 and 16.
<LI>All variables and components of field strings are set to zeros
and blanks by the <TT>clear</TT> statement on line 29. It can
also be said that all variables and components are set to <I>default
initial values</I>.
<LI>The <TT>write</TT> statements beginning on line 30 write out
the cleared variables and components surrounded by single quotes
and without intervening spaces between the quotes and the values
they surround.
</UL>
<P>
Listing 9.5 shows a sample program that fills variables and components
of field strings with values other than spaces or zeros.<BR>
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 9.5 Variables Filled with Characters Other
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -