Google+ ABAP Statements for SAP Lesson Twenty One - SAP ABAP

ABAP Statements for SAP Lesson Twenty One

Use CLEAR to reset any variable data object to the initial value appropriate to its type .In a structure, each component is reset individually.In an internal table without a header line, all of the lines are deleted.Use MOVE to copy the contents of one data object to another variable data object.With complex objects, you can either address the components individually or use a "deep copy". If the source and target objects are compatible , the system copies the objects component by component or line by line.If they are not compatible, the system converts the objects as long as there is an appropriate conversion rule.

If you are copying between two structures, and only want to copy values between identically-named fields, you can use the MOVE-CORRESPONDING statement.The conversion mechanisms explained on the following pages apply not only to the MOVE and MOVE CORRESPONDING statements, but also to calculations and value comparisons.Unlike the MOVE statement, when you use WRITE... TO... to assign values, the target field is always regarded as a character field, irrespective of its actual type. WRITE...TO behaves in the same way as when you write output to a list. This allows you to use formatting options when you copy data objects (for example, country-specific date formatting).

If two data types are not compatible but there is a converion rule, the system converts the source object into the type of the target object when you assign values, perform calculations, or compare values.The following pages contain the basic forms of the conversion rules, and examples for the most frequent cases.

If there is no conversion rule defined for a particular assignment, the way in which the system reacts depends on the context in which you programmed the assignment.If the types of the objects involved are defined statically, a syntax error occurs.

DATA: date TYPE d VALUE '19991231', time TYPE t.
ASSIGN: date TO , time TO .
= .

If the types of the objects involved are defined dynamically, a runtime error occurs, because the system cannot tell in the syntax check whether they are convertible or not.Example (remainder as above):

In general, there is a rule for converting every predefined ABAP data type into any other predefined type.Special cases:

There are no rules for converting from type D to type T or vice versa, or for converting ABAP Objects data types (object reference to obje ct reference, object reference to interface reference). Assignments or comparisons of this type cause syntax errors (where it is possible for the system to detect them).

When you assign a type C field to a type P field, you may only use digits, spaces, a decimal point, and a plus or minus sign. The target field must also be large enough.When you convert a packed number to a type C field, the leading zeros are converted into spaces. For full information about conversion rules for elementary types, refer to the online documentation in the ABAP Editor for the MOVE statement.

Internal tables can only be converted into other internal tables. The system converts the lines types according to the relevant rule for structures.

The example above shows that copying between non-compatible types may result in the target fields containing values that cannot be interpreted properly. To avoid this problem, you should copy values field by field in these cases. This ensures that the system applies the correct conversion rule for elementary fields.

If you want to manipulate strings, it is better to use the statements expressly intended for this purpose. You can use the following statements to process strings in ABAP:

SEARCH To search in a string
REPLACE To replace the first occurrence of a string
TRANSLATE To replace all specified characters
SHIFT To shift a character at a time
CONDENSE To remove spaces
CONCATENATE To chain two or more strings together
OVERLAY To overlay two strings
SPLIT To split a string

In all string operations, the operands are treated like type C fields, regardless of their actual field type. They are not converted.All of the statements apart from TRANSLATE and CONDENSE set the system field sy-subrc. SEARCH also sets the system field sy-fdpos with the offset of the beginning of the string found.All of the statements apart from SEARCH distinguish between upper- and lowercase.

To find out the occupied length of a string, use the standard function STRLEN().
The system searches the field for the string . The search string can have the following form:

'' String (trailing blanks are ignored)
'..' Any string between the periods (spaces are included in the search.)
'*' A string beginning with and including ''
'*' A string beginning with and including ''

The offset of the found string is placed in the system field sy-fdpos If the search string is not found, sy-fdpos contains the value 0 and sy-subrc is set to 4.
You can use SEARCH instead of SEARCH . The system then searches for the search string within the internal table . In this variant, the
system also sets the system field sy-tabix to the index of the line containing the search string.

In ABAP, you can program arithmetic expressions nested to any depth. You must remember that parentheses and operators are keywords, and must therefore be preceded and followed by at least one space.
The ABAP run time environment contains a range of functions for different data types. The opening parenthesis belongs to the functions name itself (and is therefore not separated from it by a space).The remaining elements of each expression must be separated by spaces.The expressions are processed in normal algebraic sequence - parenthetical expressions, followed by functions, powers, multiplication and division, and finally, addition and subtraction. A calculation may contain any data types that are convertible into each other and into the type of the result field. The system converts all of the fields into one of the three numeric data types (I, P, or F), depending on the data types of the operands. The ABAP runtime system contains an arithmetic for each of the three data types. The system then performs the calculation and converts it into the data type of the result field.

If you do not set the fixed point arithmetic option in the program attributes, the DECIMALS addition in the DATA statement only affects the output, not the arithmetic. In this case, all numbers are interpreted internally as integers, regardless of the position of the decimal point. You would then have to calculate the number of decimal places manually and ensure that the number was displayed correctly. Otherwise, the results would be meaningless.

You should therefore only use floating point numbe rs for approximations. When you compare numbers, always used intervals, and always round at the end of your calculations.
There are four general categories of runtime error that can occur in calculations:

A field that should have been converted could not be interpreted as a number.
A number range is too small for a conversion, value assignment, or to store intermediate results.
You tried to divide by zero.
You passed an invalid argument to a built-in function
(For example: ... log( -3 ) ... ).

CO only contains characters from ;
CN contains not only characters from (corresponds to NOT CO );
CA contains at least one character from ;
NA does not contain any characters from ;
CS contains the string ;
NS does not contain the string ;
CP contains the pattern ;
NP does not contain the pattern ;

The system field sy-fdpos contains the offset of the character that satisfies the condition, or the length of .In the first four expressions, the system takes into account upper- and lowercase letters and the full length of the string (SPACE column).To specify patterns, use '*' for any string, and '+' for any character. The escape symbol is '#'.

In a CASE - ENDCASE structure, you test a data object for equality against various values. When a test succeeds, the corresponding statement block is executed. If all of the comparisons fail, the OTHERS block is executed, if you have programmed one.

In an IF - ENDIF structure, you can use any logical expressions. If the condition is met, the corresponding statements are executed. If none of the conditions is true, the ELSE block is executed, if you have programmed one.

If each condition tests the same data object for equality with another object, you should use a CASEENDCASE structure. It is simpler, and requires less runtime .There are four loop structures. The number of the current loop pass is always available from the system field sy-index. If you use nested loops, the value of sy-index refers to the current one. You can take control over loop processing using the CHECK and EXIT statements. For further information, refer to Leaving Processing Blocks. The graphic shows how you can control the further processing of a loop. Mysap web application server
SAP web application and business server pages

No comments :

Post a Comment