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

📄 ch09.htm

📁 这个是sap开发语言abap的教育文档
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<P>
<IMG SRC="../button/screencam.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/screencam.gif">
<P>
Start the ScreenCam &quot;How to Display the Conversion Rules
in the ABAP/4 Keyword Documentation&quot; now.
<P>
To display the conversion rules in the ABAP/4 keyword documentation:
<OL>
<LI>Begin at the ABAP/4 Editor: Initial Screen.
<LI>Choose the menu path Utilities-&gt;ABAP/4 Key Word doc<I>.</I>
The Display Structure: ABAP/4 SAP's 4GL Programming Language screen
is displayed.
<LI>Press the Find button on the Application toolbar. The Search
Titles dialog box is displayed.
<LI>In the Find field, type <TT>move</TT>.
<LI>In the Type of Search group box, choose the From Struct. Start
radio button.
<LI>Press the Continue button. The dialog box disappears and the
<TT>move</TT> line is highlighted.
<LI>Double-click on the highlighted line. The Display Hypertext:
screen is displayed.
<LI>Press the Page Down key twice. The beginning of the conversion
table is displayed.
</OL>
<H4>Subfields</H4>
<P>
The portion of a field referenced by the specification of an offset
and/or length is called a <I>subfield</I>.
<H5>Syntax for a Subfield</H5>
<BLOCKQUOTE>
<PRE>
<I>v1</I>[+<I>o</I>][(<I>L</I>)] = <I>v2</I>[+<I>o</I>][(<I>L</I>)].
</PRE>
</BLOCKQUOTE>
<BLOCKQUOTE>
where:

<UL>
<LI><TT><I>v1</I></TT> and <TT><I>v2</I></TT>
are variable or field string names.
<LI><TT><I>o</I></TT> is a zero-based
offset from the beginning of the field.
<LI><TT><I>L</I></TT> is a length
in bytes.
</UL>

The following points apply:

<UL>
<LI>A subfield can be specified for either the sending or receiving
fields or both.
<LI>Either the offset or length is optional. Both can be present.
<LI>If the offset is not specified, the subfield starts at the
beginning of the field.
<LI>If the length is not specified, the subfield extends to the
end of the field.
<LI>No spaces can be used within the specification of the subfield.
<LI>The offset, when present, is always preceded by a plus (<TT>+</TT>)
sign.
</UL>

The length, when present, is always surrounded by parentheses.

<p>
Listing 9.7 shows a sample program that performs assignments and
uses subfields.
</BLOCKQUOTE>
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 9.7&nbsp;&nbsp;Moving a Portion of a Field Using a
Subfield Assignment<BR>
</B>
<BLOCKQUOTE>
<PRE>
 1 report ztx0907.
 2 data: f1(7),
 3       f2(7).
 4 f1      = 'BOY'.     &quot;same as: move 'BOY' to f1.
 5 f2      = 'BIG'.     &quot;same as: move 'BIG' to f2.
 6 f1+0(1) = 'T'.       &quot;f1 now contains 'TOY    '.

 7 write / f1.
 8 f1(1)   = 'J'.       &quot;same as: f1+0(1) = 'J'.
 9 write / f1.          &quot;f1 now contains 'JOY    '.
10 f1(1)   = f2.        &quot;same as: f1(1) = f2(1).
11 write / f1.          &quot;f1 now contains 'BOY    '.
12 f1+4    = f1.        &quot;same as: f1+4(3) = f1(3).
13 write / f1.          &quot;f1 now contains 'BOY BOY'.
14 f1(3)   = f2(3).     &quot;same as: f1+0(3) = f2+0(3).
15 write / f1.          &quot;f1 now contains 'BIG BOY'.
</PRE>
</BLOCKQUOTE>
<HR>
<P>
<IMG SRC="../button/output.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/output.gif">
<BLOCKQUOTE>
The code in Listing 9.7 produces this output:
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>
TOY
JOY
BOY
BOY BOY
BIG BOY
</PRE>
</BLOCKQUOTE>
<P>
<IMG SRC="../button/analysis.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/analysis.gif">
<UL>
<LI>On line 6, an offset of <TT>0</TT> and a length of <TT>1</TT>
is used to specify a subfield consisting of only the first byte
of <TT>f1</TT>. Assigning the letter <TT>'T'</TT> therefore fills
only the first byte of <TT>f1</TT>.
<UL>
<LI>On line 8, the offset of <TT>0</TT> is left out. <TT>0</TT>
is the default, so the subfield is the same as the one on line
6.
<LI>On line 10, the same subfield is used, but this time the assignment
is from <TT>f2</TT>. Only the first byte is transferred from <TT>f2</TT>
because the receiving subfield is only a single byte long.
<LI>On line 12, an offset of <TT>4</TT> specifies that the subfield
in <TT>f1</TT> begins at the fifth byte and continues to the end
of <TT>f1</TT>, making it three bytes long. The sending field
is <TT>f1</TT>, causing the first three bytes of <TT>f1</TT> to
be duplicated in positions 4 through 6.
<LI>On line 14, the first three bytes of <TT>f2</TT> replace the
first three bytes of <TT>f1</TT>.
</UL>
</UL>
<H4>Using <TT>move</TT> with Field Strings</H4>
<P>
With <TT>move</TT>, a field string name specified without a component
name is treated as if it were a variable of type <TT>c</TT>. Figure
9.2 and Listing 9.8 illustrate this point.
<P>
<A HREF="javascript:popUp('f9-2.gif')"><B>Figure 9.2 :</B> <I>Using move on a field string without using
a component name causes it to be treated as a variable of type
c</I>.</A><BR>
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 9.8&nbsp;&nbsp;The </B><TT><B>MOVE</B></TT><B>
Statement Treats a Field String Name without a Component Name
like a Variable of Type </B><TT><B>C
<BR>
</B></TT>
<BLOCKQUOTE>
<PRE>
 1 report ztx0908.
 2 data: f1(4) value 'ABCD',
 3       begin of s1,
 4           c1(1),
 5           c2(2),
 6           c3(1),
 7           end of s1.
 8 s1 = f1.                         &quot;s1 is treated as a char 4 variable
 9 write: / s1,                     &quot;writes ABCD
10        / s1-c1, s1-c2, s1-c3.    &quot;writes A BC D
</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.8 produces this output:
<BLOCKQUOTE>
<PRE>
ABCD
A BC D
</PRE>
</BLOCKQUOTE>
<P>
<IMG SRC="../button/analysis.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/analysis.gif">
<UL>
<LI>Line 2 defines <TT>f1</TT> as a four-byte variable of type
<TT>c</TT>.
<LI>Lines 3 through 7 define <TT>s1</TT> as a field string having
three components: <TT>f1</TT>, <TT>f2</TT>, and <TT>f3</TT>. The
total length of <TT>s1</TT> is calculated by totaling the lengths
of its components: 1+2+1=4.
<LI>Line 8 moves the value from <TT>f1</TT> to <TT>s1</TT> byte
by byte, as if they were both variables of type <TT>c</TT>.
<LI>Line 9 writes <TT>s1</TT> out as a four-character variable.
<LI>Line 10 writes out the contents of the components of <TT>s1</TT>.
</UL>
<H5>Field String Moves Involving Numeric Fields</H5>
<BLOCKQUOTE>
If the sending field is category character (types <TT>c</TT>,
<TT>n</TT>, <TT>d</TT>, <TT>t</TT>, or <TT>x</TT>) and the target
is a field string containing a numeric field (types <TT>i</TT>,
<TT>p</TT>, or <TT>f</TT>), <I>no data conversion is performed</I>.
The move proceeds as if both were purely character. The reverse
is also true. No conversions are performed when moving a numeric
to a field string containing a character field. In both cases,
the results are invalid and are undefined.
</BLOCKQUOTE>
<BLOCKQUOTE>
Listing 9.9 shows a sample program that make an invalid conversion
of a numeric field to a character field string.
</BLOCKQUOTE>
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 9.9&nbsp;&nbsp;Moving a Numeric Field to a Character
Field String Is Invalid<BR>
</B>
<BLOCKQUOTE>
<PRE>
 1 report ztx0909.
 2 data: fc(5) type c,
 3       begin of s,
 4            fi type i,
 5            end of s.
 6
 7 fc = '1234'.
 8 s = fc.           &quot;c&lt;-c, no conversion performed
 9 write s-fi.       &quot;writes junk
10
11 s-fi = 1234.      &quot;assign a valid value
12 fc = s.           &quot;c&lt;-c, no conversion performed
13 write / fc.       &quot;writes junk
14
15 s-fi = 1234.      &quot;assign a valid value
16 fc = s-fi.        &quot;c&lt;-i conversion performed
17 write / fc.       &quot;writes 1234
</PRE>
</BLOCKQUOTE>
<HR>
<P>
<IMG SRC="../button/output.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/output.gif">
<BLOCKQUOTE>
On my machine, the code in Listing 9.9 produces the following
output. Your results might vary for the first two lines of output
due to the invalid assignments performed.
</BLOCKQUOTE>
<BLOCKQUOTE>
<PRE>
875770,417
&quot;###
1234
</PRE>
</BLOCKQUOTE>
<P>
<IMG SRC="../button/analysis.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/analysis.gif">
<UL>
<LI>On line 2, <TT>f1</TT> is defined as an integer having a value
of <TT>1234</TT>.
<LI>On lines 3 through 5, <TT>s1</TT> is defined as a single component
<TT>c1</TT> type <TT>c</TT> length <TT>12</TT>.
<LI>On line 6, <TT>f1</TT> is moved to <TT>s1</TT>. No conversion
is performed because <TT>s1</TT> is a field string, so it is treated
like type <TT>c</TT>.
<LI>On line 7, <TT>s1-c1</TT> is written out and the results are
garbage.
<LI>On line 8, <TT>s1-c1</TT> is assigned a valid character string
<TT>'1234'</TT>.
<LI>On line 9, <TT>s1</TT> is moved to <TT>f1</TT>. No conversion
is performed.
<LI>Line 10 writes out <TT>f1</TT>, and again, the results are
garbage.
<LI>On Line 11, <TT>f1</TT> is assigned a valid value of <TT>1234</TT>.
<LI>On line 12, <TT>f1</TT> is assigned to <TT>s1-c1</TT>. Because
the assignment is to the component and not to the field string,
conversion is performed and line 13 writes out a valid value.
</UL>
<P>
<CENTER>
<TABLE BORDERCOLOR=#000000 BORDER=1>
<TR VALIGN=TOP><TD WIDTH=600><B>CAUTION</B></TD></TR>
<TR VALIGN=TOP><TD WIDTH=600>
<BLOCKQUOTE>
You should not move a type <TT>c </TT>variable to or from a field string containing a numeric type. The results are machine-dependent and therefore undefined.
</BLOCKQUOTE>

</TD></TR>
</TABLE>
</CENTER>
<P>
<H5>Moving from One Field String to Another Using Character Data
Types</H5>
<BLOCKQUOTE>
You can use the <TT>move</TT> statement on two field strings if
both strings contain components of only character data types (<TT>c</TT>,
<TT>n</TT>, <TT>d</TT>, <TT>t</TT>, and <TT>x</TT>). Listing 9.10
illustrates this concept.<BR>
</BLOCKQUOTE>
<P>
<IMG SRC="../button/input.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/input.gif">
<HR>
<P>
<B>Listing 9.10&nbsp;&nbsp;Using </B><TT><B>MOVE</B></TT><B>
with Two Field Strings Composed Entirely of Valid Character Data
Types<BR>
</B>
<BLOCKQUOTE>
<PRE>
 1 report ztx0910.
 2 data: begin of s1,
 3           d1     type d value '19980217',   &quot;8 bytes
 4           n1(4)  type n value '1234',       &quot;4 bytes
 5           c1            value 'A',          &quot;1 byte
 6           c2            value 'B',          &quot;1 byte
 7           end of s1,
 8       begin of s2,
 9           y1(4)  type n,                    &quot;4 bytes
10           m1(2)  type c,                    &quot;2 bytes
11           d1(2)  type n,                    &quot;2 bytes
12           n1(2)  type c,                    &quot;2 bytes
13           c1(4)  type c,                    &quot;4 bytes
14           end of s2.
15  s2 = s1.
16  write: / s1,
17         / s2,
18         / s1-d1, s1-n1, s1-c1, s1-c2,
19         / s2-y1, s2-m1, s2-d1, s2-n1, s2-c1.
</PRE>
</BLOCKQUOTE>
<HR>
<P>
<IMG SRC="../button/output.gif" tppabs="http://pbs.mcp.com/ebooks/0672312174/button/output.gif">
<BLOCKQUOTE>
The code in Listing 9.10 produces this output:
</BLOCKQUOTE>
<BLOCKQUOTE>

⌨️ 快捷键说明

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