Documente Academic
Documente Profesional
Documente Cultură
Spring 2011
Enterprise Programming
1/23/2011
1/23/2011
Variable Declarations
DATA varname TYPE [type specification]
DATA age TYPE i. "complete data type DATA siblings TYPE i VALUE 7. "w/ initialization DATA state TYPE c LENGTH 2 VALUE 'TN'. "incomplete
Other variations (considered obsolete) exist. LIKE can be used to declare a variable based on a prior declaration
DATA state2 LIKE state. "only data type 'copied'
When specifying default values for numeric data with decimals, the value must be placed within single quotes.
TYPES cannot have a user-specified default value. TYPES declarations are local to program. Global type declarations are possible through use of the ABAP Dictionary, allowing type management across entire system.
1/23/2011
Quick Practice
1/23/2011
Constants
CONSTANTS allows specification of fixed data objects. CONSTANTS name TYPE type VALUE value.
CONSTANTS a_const TYPE d VALUE '19681214'. CONSTANTS b_con TYPE p LENGTH 3 DECIMALS 2 VALUE '37.46'.
A number of system-maintained constants exists. These are all within structure SYST. Can see list through dictionary, data type SYST.
Reference values by using the identifier SY-COMPONENT. For example, SY-MANDT will display the current client number.
1/23/2011
Writing output
WRITE is used for basic output. WRITE 10 'Output'. Output is written beginning in column 10. WRITE (3) 'Output'. Output is written in field of size 3. * used to show number truncation (if any). String truncation note noted. WRITE (*) 'Output' Output is written in field of sufficient size, without extra spacing. WRITE 10(3) 'Output'. Combination of above techniques. WRITE / 'Output'. Output written on the next line WRITE /10(3) 'Output'. Combination of above techniques.
Parameters
PARAMETERS prompts the user for runtime value at program start. (Called a selection screen.) Syntax is the same as DATA.
PARAMETERS age TYPE i. PARAMETERS: var1 TYPE c LENGTH 8, var2 TYPE i.
Parameter name must be 8 characters or less. User is prompted with the parameter name. DEFAULT can be used to specify a default value in the field.
PARAMETERS var1 TYPE c LENGTH 8 DEFAULT 'NONE'.
1/23/2011
Quick Practice
Literal text
ABAP is multilingual. Coding in string literals (prompting, etc.) defeats language independence and should only be done in testing. The solution for this is text symbols. Text symbols belong to each program in the text pool for that program. The various texts are placed in the text pool and assigned a 3-character alphanumeric code (xxx). This code is then used by specifying either TEXT-xxx instead of the literal. literal(xxx) where literal is the message in the native language. Access the text pool to define text symbols by either: From editor select Goto Text Elements Text Symbols Using the syntax above to reference a text symbol in coding. Then double click on the text symbol entered. Goto Translation will translate the text symbols.
1/23/2011
Logical Expressions
Logical expressions evaluate to true or false. In ABAP, logical expression cannot be assigned to variables (no boolean data type). Logical expressions are used in conditional code sequences.
Relational Operators Operator =, EQ <>, NE <, LT Operation Is equal to Is not equal to Is less than Operator AND OR NOT Boolean Operators Operation Logical and Logical or Logical not
>, GT
<=, LE >=, GE
Is greater than
Is less than or equal to Is greater than or equal to
NOT is placed before an expression to negate its result. NOT var_a LT var_b.
1/23/2011
ENDCASE.
ENDCASE.
Quick Practice
1/23/2011
Looping
ABAP supports definite iteration, pre-test iteration, and post-test iteration.
DO value TIMES. 1 or more statements. ENDDO. WHILE condition. 1 or more statements. ENDWHILE. DO. 1 or more statements. IF abort_condition. EXIT. ENDIF. ENDDO. DO var_a TIMES. WRITE / 'Hi'. ENDDO. WHILE var_a < 10. var_a = var_a * 2. ENDWHILE. DO. var_a = var_a * 2. IF var_a > 200. EXIT. ENDIF. ENDDO.
10
1/23/2011
Exiting Loops
EXIT: Loop exits immediately. Jump to statement that follows loop block. CONTINUE: Restart next loop iteration.
WHILE sy-index < 10. WRITE / sy-index. IF sy-index < 3. CONTINUE. ENDIF. WRITE 'After ENDIF'. ENDWHILE.
Quick Practice
11
1/23/2011
Copyrights
Presentation prepared by and copyright of Dr. Tony Pittarese, East Tennessee State University, Computer and Information Sciences Dept. (pittares@etsu.edu) Podcast lecture related to this presentation available via ETSU iTunesU.
Microsoft, Windows, Excel, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation. IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System z10, System z9, z10, z9, iSeries, pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390 Parallel Enterprise Server, PowerVM, Power Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER, OpenPower, PowerPC, BatchPipes, BladeCenter, System Storage, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex, MVS/ESA, AIX, Intelligent Miner, WebSphere, Netfinity, Tivoli and Informix are trademarks or registered trademarks of IBM Corporation. Linux is the registered trademark of Linus Torvalds in the U.S. and other countries. Oracle is a registered trademark of Oracle Corporation. HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C, World Wide Web Consortium, Massachusetts Institute of Technology. Java is a registered trademark of Sun Microsystems, Inc. JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape. SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP Business ByDesign, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and other countries. Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and other Business Objects products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of Business Objects S.A. in the United States and in other countries. Business Objects is an SAP company. Other products mentioned in this presentation are trademarks of their respective owners.
12