ABAP Programming Language

Ace your homework & exams now with Quizwiz!

SELECTION-SCREEN - Parameters

* DATA declaration DATA s_scarr TYPE scarr. * Selection Screen PARAMETERS p_carrid TYPE scarr-carrid DEFAULT 'LH' OBLIGATORY. * Start of Processing SELECT SINGLE * INTO CORRESPONDING FIELDS OF s_scarr FROM scarr WHERE carrid = p_carrid. IF sy-subrc = 0. WRITE: s_scarr-carrname. ENDIF.

Local TYPES in ABAP Programs

-You define local data types in a program using the TYPES <t> ... TYPE <type> ... [LENGTH len] [DECIMALS dec] statement. The type name <t> may be up to 30 characters long. You can use any letters, digits, and the underscore character. -Do not create a name consisting entirely of numeric characters. qYou cannot use the special characters + . , : ( ) - < >. Other special characters are reserved for internal use. -You cannot use the names of the predefined ABAP types (C, D, F, I, N, P, T, X,STRING, XSTRING) or the name of the generic type TABLE. You should not use names that are the same as an ABAP keyword or addition. qYou should: • Use names that explain the meaning of the type without the need for further comments • Use the underscore character to separate compound words • Always use a letter as the first character of a variable name. qYou declare local data types in a program either by referring to an existing data type or constructing a new type.

Development of programming language is entirely dependent on the kind of problem and requirement. However, development of a programming language normally includes the following steps.

1. Defining the Problem 2. Analysis of Task and Methods 3. Development of Algorithm 4. Verification of Algorithm 5. Coding 6. Testing of Program 7. Documentation 8. Implementation

Accepted operators

<f> IS INITIAL compares f with its initial value, which depends on the type involved

SELECTION-SCREEN - Parameters

PARAMETERS p_int TYPE i OBLIGATORY. PARAMETERS: p_val TYPE c LENGTH 10 DEFAULT 'ABC'. PARAMETERS: p_num TYPE n, p_date TYPE d DEFAULT sy-datum. WRITE: p_int, p_val, p_num, p_date.

Initializing DATA objects

CLEAR structure. All fields of the structure will have the initial value. REFRESH itab. Deletes all rows of the internal table.

Constants

CONSTANTS: c_pi TYPE P DECIMALS 10 VALUE '3.1415926536'. CONSTANTS c_error TYPE c LENGTH 5 VALUE 'ERROR'. Cannot be type STRING of XSTRING.

SELECTION-SCREEN - Select-options

Checking Selection Criteria Use the following logical expression to check whether the contents of a field satisfy the criteria in a selection table: ... <f> IN <seltab> ....

Time to Practice - Exercise

Create a new program ZZuser_C3. Your program should determine sum of the even numbers from range [1, n] For example, if n=10 => the multiplication will be 2+4+6+8+10 = 30 Solve the requirement using DO statement and WHILE statement. Display the method used.

What is a Database

Database is a collection of related data and data is a collection of facts and figures that can be processed to produce information. Mostly data represents recordable facts. Data aids in producing information, which is based on facts. For example, if we have data about marks obtained by all students, we can then conclude about toppers and average marks. A database management system(DBMS) stores data in such a way that it becomes easier to retrieve, manipulate, and produce information.

CASE

Depending on the current contents of a field, this statement executes one of several alternative processing branches. The field whose contents determine how the subsequent processing is specified after CASE; the individual processing branches are introduced by WHEN, followed by the value to be tested. The entire block is concluded by ENDCASE. CASE f. WHEN f11 OR f12 ... OR f1n. ... WHEN f21 OR f22 ... OR f2m. ... WHEN OTHERS.... ENDCASE.

DO n TIMES

Repeats the processing enclosed by the DO and ENDDO statements n times. If n changes within the loop, this has no effect on loop passes. Example: DATA v_count TYPE I. DO 10 TIMES. ADD SY-INDEX TO v_count.ENDDO.

Algorithm Analysis

Efficiency of an algorithm can be analyzed at two different stages, before implementation and after implementation. They are the following : •A Priori Analysis − This is a theoretical analysis of an algorithm. Efficiency of an algorithm is measured by assuming that all other factors, for example, processor speed, are constant and have no effect on the implementation. •A Posterior Analysis − This is an empirical analysis of an algorithm. The selected algorithm is implemented using programming language. This is then executed on target computer machine. In this analysis, actual statistics like running time and space required, are collected. In an industry, we cannot perform A Posterior analysis as the software is generally made for an anonymous user, which runs it on a system different from those present in the industry. In A Priori, it is the reason that we use asymptotic notations to determine time and space complexity as they change from computer to computer; however, asymptotically they are the same.

ER Model - Basic Concepts

Entity-Set and Keys Key is an attribute or collection of attributes that uniquely identifies an entity among entity set. For example, the roll_number of a student makes him/her identifiable among students. •Super Key − A set of attributes (one or more) that collectively identifies an entity in an entity set. •Candidate Key − A minimal super key is called a candidate key. An entity set may have more than one candidate key. •Primary Key − A primary key is one of the candidate keys chosen by the database designer to uniquely identify the entity set.

Assigning structures

Example: DATA: v_date TYPE d. DATA: BEGIN OF s_str, year TYPE n LENGTH 4, month TYPE n LENGTH 2, day TYPE n LENGTH 2, END OF s_str. s_str-year = '2010'. v_date = s_str.-> v_date = '20100000'.

DO

Example: DO. WRITE: / 'SY-INDEX - Begin:',SY-INDEX. IF SY-INDEX = 10. EXIT. ENDIF. WRITE: 'End:', SY-INDEX. ENDDO.

Local TYPES in ABAP Programs

Examples of Elementary Local Data TYPES TYPES: ty_num TYPE p DECIMALS 2. TYPES ty_char03 TYPE c LENGTH 3. TYPES ty_char03(3) TYPE c. TYPES ty_numc05 TYPE n LENGTH 5. TYPES ty_numc05(5) TYPE n.

DO: Exit

Exiting a loop - with EXIT DO 4 TIMES. IF SY-INDEX = 2. EXIT. ENDIF. WRITE SY-INDEX. ENDDO.

Defining Tables in ABAP - Internal Tables

In ABAP, the tables defined locally (at program level) are called Internal Tables. qExample: TYPES: BEGIN OF ty_student, name TYPE c LENGTH 20, stud_id TYPE n LENGTH 13, address TYPE string, END OF ty_student. DATA: t_student TYPE TABLE OF ty_student. -> Internal Table Definition DATA: s_student TYPE ty_student. -> Structure Definition OBS: s_student and t_student have the same structure.

Algorithm Analysis

Generally, we perform the following types of analysis • •Best case − The minimum number of steps taken on any instance of size a. •Average case − An average number of steps taken on any instance of size a. •Worst case − The maximum number of steps taken on any instance of size a.

Numeric Types: f - Float

Initial value = 0 The value range of type F numbers is 1x10**-307 to 1x10**308 for positive and negative numbers, including 0 (zero). The accuracy range is approximately 15 decimals, depending on the floating point arithmetic of the hardware platform. Since type F data is internally converted to a binary system, rounding errors can occur. Although the ABAP processor tries to minimize these effects, you should not use type F data if high accuracy is required. Instead, use type P data. You use type F fields when you need to cope with very large value ranges and rounding errors are not critical. You should therefore only use floating-point numbers for approximations. Default length = 8 Maximum length = 8

Numeric Types: i - Integer

Initial value = 0 The value range of type I numbers is -2**31 to 2**31-1 and includes only whole numbers. Non-integer results of arithmetic operations (e.g. fractions) are rounded, not truncated. You can use type I data for counters, numbers of items, indexes, time periods, and so on. Default field length = 4 bytes Maximum field length = 4 bytes

LOOP

LOOP statement is used to iterate on Internal Tables. LOOP AT itab INTO struc. processing_bloc. ENDLOOP.

Benefits of Flowchart

Let us now discuss the benefits of a flowchart. §Simplify the Logic §As it provides the pictorial representation of the steps; therefore, it simplifies the logic and subsequent steps. §Makes Communication Better §Because of having easily understandable pictorial logic and steps, it is a better and simple way of representation. §Effective Analysis §Once the flow-chart is prepared, it becomes very simple to analyze the problem in an effective way. §Useful in Coding §The flow-chart also helps in coding process efficiently, as it gives directions on what to do, when to do, and where to do. It makes the work easier. §Proper Testing §Further, flowchart also helps in finding the error (if any) in program §Applicable Documentation §Last but not the least, a flowchart also helps in preparing the proper document (once the codes are written).

Logical expressions

NOT takes priority over AND, while AND in turn takes priority over OR: NOT f1 = f2 OR f3 = f4 AND f5 = f6 thus corresponds to ( NOT ( f1 = f2 ) ) OR ( f3 = f4 AND f5 = f6 ) The selection criteria comparisons or checks are processed from left to right. If evaluation of a comparison or check proves part of an expression to be true or false, the remaining comparisons or checks in the expression are not performed.

Variables

Numeric Variable declaration using Elementary Predefined TYPES DATA v_number TYPE i VALUE -1234. WRITE 6789. MOVE 100 TO v_number. DATA v_dec TYPE p DECIMALS 2. Text Variable declaration using Elementary Predefined TYPES DATA v_text TYPE c LENGTH 10 VALUE 'ABCD'. WRITE 'End of story'. MOVE 'XYZ' TO v_text.

Variables

Numeric Variable declaration using Elementary Predefined TYPES DATA v_number TYPE i. v_number = 4 / 10. "result: 0 WRITE v_number. v_number = 5 / 10. "result: 1 Text Variable declaration using Elementary Local TYPES TYPES: ty_name TYPE c LENGTH 10, ty_id TYPE n LENGTH 7. DATA v_name TYPE ty_name VALUE 'TEst 1'. DATA: v_id1 TYPE ty_id VALUE '01234', v_id2 TYPE ty_id. WRITE: v_id1, v_id2. "result: 0001234 and 0000000 OBS: Main purpose of Local Types is reutilization.

Predefined ABAP Types:

Numeric types: i = integer f = Floating point number p = packed number Character types: n = Sequence of digits c = Sequence of characters d = date t = time Hexadecimal: x = Hexadecimal code String/hexadecimal: string = Sequence of characters xstring = Hexadecimal code

Implementation

Once the above steps are executed successfully, the developed codes (programming language) are installed in the computer system for the end users. The users are also manuals - explaining how to run the respective programs.

Verification of Algorithm

Once the algorithm is developed, it cannot be applied directly rather primarily it needs to be tested specially for the accuracy. If there is any error, it is rectified and solved in the beginning itself. The verification process saves time, money, and energy.

Coding

Once the basic processes and steps are completed successfully, then the actual coding of a program starts in the given programming language.

DO

Repeats the processing enclosed by the DO and ENDDO statements until the loop is terminated by EXIT, STOP or REJECT. You can use the CONTINUE statement to end the current loop pass prematurely and continue with the next loop pass. The system field SY-INDEX counts the number of loop passes, starting from 1. You can nest DO loops. When the processing leaves an inner DO loop, the value of SY-INDEX belonging to the outer DO loop is restored.

Processing Single Records - SELECT into Structure

Requirement: Display the Airline Name for Carrier 'LH'. DATA: s_scarr TYPE scarr. SELECT SINGLE * FROM scar INTO s_scarr WHERE carrid = 'LH'. IF sy-subrc = 0. WRITE : s_scarr-carrid, s_scarr-carrname. ENDIF. OBS: DB Table structures can be used as Global Types. S_SCARR structure will have the same fields as DB Table SCARR. OBS: SY-SUBRC = 0 means that SELECT was operated with success and at least one record was selected

Processing Multiple Records - SELECT into ITab

Requirement: Display the Price of all flights operated by LH on 17.03.2018. DATA: t_sflight TYPE TABLE OF sflight, s_sflight TYPE sflight, v_carrid TYPE sflight-carrid VALUE 'LH'. SELECT * FROM sflight INTO TABLE t_sflight WHERE carrid = v_carrid AND fldate = '20180317'. LOOP AT t_sflight INTO s_sflight. WRITE : / s_sflight-carrid, s_sflight-connid, s_sflight-price. ENDLOOP.

SELECT statement

SELECT, FROM and INTO are mandatory elements of a Select statement in ABAP. WHERE conditions are optional, but they are used in most cases as only partial information is retrieved at program level. SELECT * means that all columns from a DB table will be selected.

What is SQL?

SQL is Structured Query Language, which is a computer language for storing, manipulating and retrieving data stored in a relational database. SQL is the standard language for Relational Database System. All the Relational Database Management Systems (RDMS) like MySQL, MS Access, Oracle, Sybase, Informix, Postgres and SQL Server use SQL as their standard database language. Also, they are using different dialects, such as: •MS SQL Server using T-SQL, •Oracle using PL/SQL, MS Access version of SQL is called JET SQL (native format) etc.

Relationship

The association among entities is called a relationship. For example, an employee works_at a department, a student enrolls in a course. Here, Works_at and Enrolls are called relationships. Relationship Set: A set of relationships of similar type is called a relationship set. Like entities, a relationship too can have attributes. These attributes are called descriptive attributes. Degree of Relationship: The number of participating entities in a relationship defines the degree of the relationship. Binary = degree 2 Ternary = degree 3 n-ary = degree Mapping Cardinalities: Cardinality defines the number of entities in one entity set, which can be associated with the number of entities of other set via relationship set.

SELECTION-SCREEN - Select-options

TABLES: scarr. * DATA declaration DATA v_carrid TYPE scarr-carrid. * Selection Screen SELECT-OPTIONS so_cid FOR scarr-carrid. * Start of Processing v_carrid = 'LH'. IF v_carrid IN so_cid. WRITE : 'Valoarea se afla in SELECT-OPTION'. ENDIF.

DATA object with same structure type

TYPES: BEGIN OF ty_scarr, carrid TYPE scarr-carrid, carrname TYPE scarr-carrname, url TYPE c LENGTH 50, END OF ty_scarr. DATA: s_scarr TYPE ty_scarr, t_scarr TYPE TABLE OF ty_scarr. SELECT SINGLE carrid carrname url FROM scarr INTO s_scarr WHERE carrid = 'LH'. SELECT carrid carrname url FROM scarr INTO TABLE t_scarr.

LOOP - example

TYPES: BEGIN OF ty_student, name TYPE c LENGTH 20, stud_id TYPE n LENGTH 13, address TYPE string, END OF ty_student. DATA: t_student TYPE TABLE OF ty_student. DATA: s_student TYPE ty_student. LOOP AT t_student INTO s_student. WRITE: / s_student-name, s_student-stud_id, s_student-address. ENDLOOP. OBS: Internal Tables can't be directly displayed. Only an Elementary Object can be displayed at time.

DO: Continue

Terminate current loop - with CONTINUE DO 4 TIMES. IF SY-INDEX = 2. CONTINUE. ENDIF. WRITE SY-INDEX. ENDDO.

Testing of Program

Testing of the development of program code is another essential feature, as it is bound with errors; hence, testing makes it error free. The developer keeps testing and correcting the coding until he/she develops it finally.

Algorithm Design

The important aspects of algorithm design include creating an efficient algorithm to solve a problem in an efficient way using minimum time and space. To solve a problem, different approaches can be followed. Some of them can be efficient with respect to time consumption, whereas other approaches may be memory efficient. However, one has to keep in mind that both time consumption and memory usage cannot be optimized simultaneously. If we require an algorithm to run in lesser time, we have to invest in more memory and if we require an algorithm to run with lesser memory, we need to have more time.

SELECT-OPTIONS structure

The row type of a selection table is a structure that consists of the following four components: SIGN, OPTION, LOW and HIGH. • SIGN - Type C length 1 Possible values are I and E. - I stands for "inclusive" (inclusion criterion - operators are not inverted) - E stands for "exclusive" (exclusion criterion - operators are inverted) • OPTION - Type C with length 2. Possible values: - If HIGH is empty, you can use EQ, NE, GT, LE, LT,CP, and NP. These operators are the same as those that are used for logical expressions. - If HIGH is filled, you can use BT (BeTween) and NB (Not Between).

Defining the Problem

This the first step, wherein the problem has to be defined.

Database Characteristics

Traditionally, data was organized in file formats. DBMS was a new concept then, and all the research was done to make it overcome the deficiencies in traditional style of data management.

SELECTION-SCREEN - Select-options

Used for complex selections from database (SELECT) Can have multiple values (single values or intervals) SELECT-OPTIONS <seltab> FOR <f>. <f> can be a column of a database table, or an internal <f> field in the program. A selection table is an internal table object of the standard DB table type that has a standard key and a header line. Selection tables are used to store complex selections using a standardized procedure.

Algorithm Complexity

Usually, the efficiency or running time of an algorithm is stated as a function relating to : •Time complexity − Represents the amount of time required by the algorithm to run to completion. •Space complexity − Represents the amount of memory space required by the algorithm in its life cycle.

Program structure

When a program is written in ABAP the following sections need to be identified (OBS: the order matters!) REPORT... -> Program start (default syntax during program creation) TYPES:... -> Type declaration (all TYPES should be declared in a single unified section at the beginning of the program) DATA:... -> Data declaration (all DATA should be declared in a single unified section at the beginning of the program, after TYPES as they may need local defined types) SELECTION-SCREEN -> Parameters and select-options ... -> Start of processing (Select, Process and Display information)

Database Access - SELECT statement

When you want to extract specific data from one or more sources, you can use a select query. A select query helps you retrieve only the data that you want (not the entire information stored in Database), and also helps you combine data from several data sources. SELECT statement is used to read/access data from DATABASE tables.

Assigning structures

You address components of structures using: structure_name-comp_name. For this reason, you should not use hyphens in variable names. ex: s_name-prename = 'Smith' s_name-surname = 'John'.

Assigning structures

You can copy the contents of a source structure to a target structure component by component, using a MOVE-CORRESPONDING statement. The system then copies each source field to the target field with the same name. The conversion rules for elementary data objects then apply. Note that the system does not check that identically named components have the same type. This can be useful, but there are dangers involved.

Defining structures

You can define structures in two ways: qFirst, define a structure type explicitly using the TYPES statement. To do this, enter the name of the structure after BEGIN OF and then list the definitions of all the components. End the definition of the structure type using END OF.You then define the structured data object with the DATA statement, using your own user-defined structure type. qDefine the data object directly using the DATA statement. The syntax is similar to the definition of a structure type. If you use this option, the corresponding structure type is defined implicitly at the same time.

Data Types

are used to describe the technical characteristics of the DATA (the shape of DATA).

Accepted operators: Character operators

•CO (Contains Only) • c1 contains only characters from the string c2. • •CN (Contains Not only): "c1 CN c2" is equivalent to " NOT ( c1 CO c2 )". • •CA (Contains Any) • c1 contains at least one character from the string c2. • •NA (contains Not Any): "c1 NA c2" is equivalent to "NOT ( c1 CA c2 )". • •CS (Contains String): c1 contains the character string c2. • •NS (contains No String): "c1 NS c2" is equivalent to " NOT ( c1 CS c2 )".

What are the characteristics of Algorithms

•Precise: Algorithm should be clear and precise. Each of its steps (or phases), and their inputs/outputs should be clear and must lead to only one meaning. •Input and Output : An algorithm should have 0 or more well-defined inputs and should have 1 or more well-defined outputs. •Finiteness: Algorithms must terminate after a finite number of steps.

Variable Length Types

•STRING and xSTRING: •STRING = sequence of characters (variable length) •XSTRING = hexadecimal code •The length is adjusted automatically by the system at runtime

•Predefined Types

•already defined by the language in which you're coding (ready to use) •available in the entire system

Algorithm Flowchart

A flowchart is a blueprint that pictorially represents the algorithm and its steps. The steps of a flowchart do not have a specific size and shape rather it is designed in different shapes and sizes (see the image given below). As shown in the above image, the boxes in different shapes and interconnected with arrows, are logically making a flow chart. A flow-chart represents the general steps in a process.

Logical expressions

A logical expression consists of comparisons using the operators AND, OR and NOT , as well as the parentheses " (" and ")". The individual operators, parentheses, values and fields must be separated by blanks. Incorrect: f1 = f2 AND (f3 = f4). Correct: f1 = f2 AND ( f3 = f4 ).

Logical Expression

A logical expression formulates a condition for operands. The result of a logical expression is a truth value and can therefore be true or false. We can combine 2 or more logical expressions using Boolean operators. This produces a single output for the expression.

What is a programming language?

A programming language is a formal language, which comprises a set of instructions that produce various kinds of output. Programming languages are used in computer programming to implement algorithms.

What is ABAP?

ABAP is a high-level programming language created by SAP, which joins multiple programming concepts, like Algorithms and Databases.

ABAP

Advanced Business Application Programming

Development of Algorithm

Algorithm is a proper technique that illustrates the right solution in logical and feasible steps. Algorithm is normally done in the form of flowcharts and pseudo codes.

What is an Algorithm?

Algorithm is a step-by-step procedure, which defines a set of instructions to be executed in a certain order to resolve a problem. Algorithms are generally independent from any programming languages, so an algorithm can be implemented in more than one programming language.

Algorithm Analysis

Algorithms are often quite different from one another, though the objective of these algorithms are the same. For example, we know that a set of numbers can be sorted using different algorithms. Number of comparisons performed by one algorithm may vary with others for the same input. Hence, time complexity of those algorithms may differ. At the same time, we need to calculate the memory space required by each algorithm. Analysis of algorithm is the process of analyzing the problem-solving capability of the algorithm in terms of the time and size required (the size of memory for storage while implementation). However, the main concern of analysis of algorithms is the required time or performance.

IF - basic forms

All IF statements must be concluded in the same processing block by ENDIF. 1. IF logexp. processing1. ENDIF. 2. IF logexp. processing1 ELSE. processing2 ENDIF. 3. IF logexp1. processing1 ELSEIF logexp2. processing2 ELSEIF ... ... ELSE. Processing. ENDIF.

Difference between Algorithm and Pseudocode

An algorithm is a formal definition with some specific characteristics that describes a process, which could be executed by a computer machine to perform a specific task. Generally, the word "algorithm" can be used to describe any high level task in computer science. On the other hand, pseudocode is an informal and (often rudimentary) human readable description of an algorithm leaving many granular details of it. Writing a pseudocode has no restriction of styles and its only objective is to describe the high level steps of algorithm in a much realistic manner in natural language.

DATA Declaration

DATA declaration refers to Data Objects which means that memory location is allocated during program execution for processing. DATA <d> ... TYPE <type> ... [LENGTH len] [DECIMALS dec] [VALUE v]

IF - examples

DATA v_result TYPE I. ... IF v_result < 0. WRITE / 'Result less than zero'. ELSEIF v_result = 0. WRITE / 'Result equal zero'. ELSE. WRITE / 'Result greater than zero'. ENDIF. ---------------------------- IF v_result IS INITIAL. WRITE / 'Result equal zero'. ENDIF.

Assigning structures

DATA: BEGIN OF s_resident, name TYPE c LENGTH 20, cnp TYPE n LENGTH 13, address TYPE c LENGTH 25, age TYPE i, END OF s_resident. s_resident-name = 'Resident 1'. s_resident-cnp = '1234567890123'. s_resident-address = 'ABC'. s_resident-age = 24. TYPES: BEGIN OF ty_student, name TYPE c LENGTH 20, stud_id TYPE n LENGTH 13, address TYPE string, END OF ty_student. DATA: s_student TYPE ty_student. MOVE-CORRESPONDING s_resident TO s_student.

WHILE - example

DATA: SEARCH_ME TYPE I, MIN TYPE I VALUE 0, MAX TYPE I VALUE 1000, TRIES TYPE I, NUMBER TYPE I. SEARCH_ME = 23. WHILE NUMBER <> SEARCH_ME. ADD 1 TO TRIES. NUMBER = ( MIN + MAX ) / 2. IF NUMBER > SEARCH_ME. MAX = NUMBER - 1. ELSE. MIN = NUMBER + 1. ENDIF. ENDWHILE. The above code performs a (binary) search for the "unknown" number SEARCH_ME which lies between MIN and MAX. TRIES contains the number of attempts needed to find it.

Processing Single Information - SELECT into Variable

DATA: v_carrid TYPE scarr-carrid, v_carrname TYPE scarr-carrname. SELECT SINGLE carrid carrname INTO (v_carrid, v_carrname) FROM scarr WHERE carrid = 'LH'. WRITE : v_carrid, v_carrname.

CASE - example

DATA: v_val TYPE I VALUE 3. CASE v_val. WHEN 1 OR 2. WRITE 'Value is 1 or 2'.WHEN 3 OR 4. WRITE 'Value is 3 or 4' .WHEN OTHERS. WRITE 'Other Value'.ENDCASE.

Numeric Types: p - Packed

Initial value = 0 Type P data allows digits after the decimal point. The number of decimal places is generic, and is determined in the program. The value range of type P data depends on its size and the number of digits after the decimal point. The valid size can be any value from 1 to 16 bytes. Two decimal digits are packed into one byte, while the last byte contains one digit and the sign. Up to 14 digits are allowed after the decimal point. The initial value is zero. When working with type P data, it is a good idea to set the program attribute Fixed point arithmetic. Otherwise, type P numbers are treated as integers. You can use type P data for such values as distances, weights, amounts of money, and so on. Default length = 8 Maximum length 16

Internal tables - definition

Internal tables provide a means of taking data from a fixed structure and storing it in working memory in ABAP. qThe data is stored line by line in memory, and each line has the same structure. In ABAP, internal tables fulfill the function of arrays. Since they are dynamic data objects, they save the programmer the task of dynamic memory management in his or her programs. You should use internal tables whenever you want to process a dataset with a fixed structure within a program. A particularly important use for internal tables is for storing and formatting data from a database table within a program. They are also a good way of including very complicated data structures in an ABAP program

Documentation

Once the coding and programming is done successfully, it is the job of the developer to document all these features and steps. The documented program instructs users on how to run and operate the respective program.

Analysis of Task and Methods

Once the problem is defined, the developer analyzes and develops various solutions in order to solve the problem and finally, the best feasible solution is developed.

Processing Multiple Records - SELECT into ITab

TYPES: BEGIN of ty_flight, connid TYPE connid, carrname TYPE carrname, END OF ty_flight. DATA: t_flight TYPE TABLE OF ty_flight. SELECTcarridconnidUP TO 10 ROWSFROM spfliINTO TABLE gt_spfliWHEREconnid = p_connid.

Simple Algorithm Example

Problem: I'm working on my laptop in the office and I want to make a coffee. Algorithm: Step 1: Stand up from your chair. Step 2: Take my mug. Step 3: Go to coffee machine Step 4: Put the mug; Step 5: Press on the button on desired type of coffee Step 6 : Take my coffee Step 7: Go back to my place Step 8: Drink coffee

WHILE

Repeats the processing enclosed between the WHILE and ENDWHILE statements as long as the logical expression logexp is true. Checks the condition before each loop pass. If it is no longer true, processing resumes after ENDWHILE . You can use the CONTINUE statement to leave the current loop pass prematurely and skip to the next loop pass.

Standard tables

Standard tables have an internal linear index. From a particular size upwards, the indexes of internal tables are administered as trees. In this case, the index administration overhead increases in logarithmic and not linear relation to the number of lines. The system can access records either by using the table index or the key. The response time for key access is proportional to the number of entries in the table. The key of a standard table is always non-unique. You cannot specify a unique key. This means that standard tables can always be filled very quickly, since the system does not have to check whether there are already existing entries. This is the most appropriate type if you are going to address the individual table entries using the index. Index access is the quickest possible access. You should fill a standard table by appending lines (ABAP APPEND statement), and read, modify and delete entries by specifying the index (INDEX option with the relevant ABAP command). The access time for a standard table increases in a linear relationship with the number of table entries. If you need key access, standard tables are particularly useful if you can fill and process the table in separate steps. For example, you could fill the table by appending entries, and then sort it. If you use the binary search option with key access, the response time is logarithmically proportional to the number of table entries.

ER Model - Basic Concepts

The ER model defines the conceptual view of a database. It works around real-world entities and the associations among them. At view level, the ER model is considered a good option for designing databases. Entity: An entity can be a real-world object, either animate or inanimate, that can be easily identifiable. For example, in a school database, students, teachers, classes, and courses offered can be considered as entities. All these entities have some attributes or properties that give them their identity. Attributes: Entities are represented by means of their properties, called attributes. All attributes have values. For example, a student entity may have name, class, and age as attributes. There exists a domain or range of values that can be assigned to attributes. For example, a student's name cannot be a numeric value. It has to be alphabetic. A student's age cannot be negative, etc.

SELECTION-SCREEN - Parameters

You use the PARAMETERS statement to declare variables, similarly to the DATA statement. Variables declared with the PARAMETERS statement are called parameters. For each parameter declared, an input field appears on the corresponding selection screen. PARAMETERS <p> TYPE <type> [LENGTH len] [DECIMALS dec] To assign a default value to a parameter, you use the following syntax: PARAMETERS <p> ...... DEFAULT <f> ...... To make a parameter obligatory : PARAMETERS <p> ...... OBLIGATORY.

•Local Types

•specific types, defined by user •available only at specific levels (eg: program level, class level)

Numeric Types:

i = integer: - Initial value = 0 - No decimals - Used for counters, number of items, indexes, etc p = packed: - Initial value = 0 - Decimal for business calculations - Very precise f = float: - Initial value = 0 - Decimal for rough calculations - Used for approximations

Tables

qEach table is made of columns and rows. qTables contain series of lines which are repeated from a single line. qOne line may contain single element (equivalent of vectors) or multiple elements of same or different types. qTables have a line type used to identify the table rows using unique or non-unique key.

Assigning structures

qIf all the components of a structure are of a string type, of fixed length, you can assign components with different properties to them. Each character is then copied byte-by-byte without being converted. This approach is used, for example, to extract the day or month from a date field. qThat is, a structure is created, such that the first four characters of a variable specify the year, the next two specify the month, and the last two the day. If a date is assigned to this structure using the MOVE statement, the characters are then copied left aligned. You can then determine the year, month, and day directly using the variables, without having to use offsets. qFor compatibility, assignments between incompatible structures are also allowed, if they contain numeric or hexadecimal components. The structure is then technically considered to be a string (that is, casting of the structure occurs). The contents are not converted. Between the structures, the same conversion rules apply as for strings: the bytes are copied, left aligned. If the target structure is longer than the source structure, the target structure is filled with spaces, regardless of the component type of the target structure. qIn conclusion, avoid assigning incompatible structures wherever possible, except where both structures consist entirely of fixed-length string-type fields.

SELECTION-SCREEN - specific Parameters

qSpecific types of PARAMETERS are Check Boxes and Radio Buttons. qCheck Boxes and Radio Buttons are specific parameters of type C, and can take only 2 values: •Space - if the parameter is not marked •'X' or 'x' - if the parameter is marked PARAMETERS <p> AS CHECKBOX. • PARAMETERS: <p1> RADIOBUTTON GROUP <group>, <p2> RADIOBUTTON GROUP <group> [DEFAULT 'X']. OBS: At least two Radio Buttons must be part of a Group and one Radio Button must always be selected. If not specified, the first radio button is selected by default.

Value Assignment

qThere are three possible outcomes of assigning <f1> to <f2>: 1. The data objects <f1> and <f2> are fully compatible , •that is, their data types, field length, and number of decimal places are identical. The contents of source field<f1> are transferred byte by byte into the target field <f2> without any further manipulation. The MOVE statement is most efficient when this is the case. 2. The data objects <f1> and <f2> are incompatible. qThis is the case, for example, if the two fields have the same type, but different lengths. The contents of the source field <f1> are converted so that they are compatible with the data type of <f2>, and are then transferred. This procedure only works if a conversion rule exists between the data types of <f1> and <f2>. Type conversions make the MOVE statement less efficient. How much less efficient depends on the individual conversion. 3. The data objects <f1> and <f2> are incompatible, and no conversion is possible. The assignment is not possible. If this can be recognized statically, a syntax error occurs. If it is not recognized before the program is run, a runtime error occurs.

Value Assignment

qTo assign the value of a data object <f1> to a variable <f2>, use the following statement: MOVE <f1> TO <f2>. or the equivalent statement <f2> = <f1>. qThe contents of <f1> remain unchanged. <f1> does not have to be a variable - it can also be a literal, a text symbol, or a constant. You must always specify decimal points with a period (.), regardless of the user's personal settings. Multiple value assignments in the form <f4> = <f3> = <f2> = <f1>. are also possible. ABAP processes them from right to left as follows: MOVE <f1> TO <f2>. MOVE <f2> TO <f3>. MOVE <f3> TO <f4>.

Defining nested structures

qYou can define nested structures by assigning a structure type to a component within a structure type. qYou can address this sub-structure as a whole using the component name: structure_name-substructure_name. qYou can also address individual components in the sub-structure: structure_name-substructure_name-comp_name. qStructures can be nested to any depth. qYou can also integrate components of a dynamic type in a structure. This can either be an elementary data object of variable length (string or xstring) or an internal table. These structures are known as deep structures.

Hexadecimal Types

•x - HEXA: •Initial value = x00 •Initial length = 1 •Maximum length = 65535 •One byte is represented by a two-digit hexadecimal display. The fields with this type are called hexadecimal fields.

Local TYPES in ABAP Programs

qYou define local data types in a program using the TYPES <t> ... TYPE <type> ... [LENGTH len] [DECIMALS dec] statement. The type name <t> may be up to 30 characters long. You can use any letters, digits, and the underscore character. -Do not create a name consisting entirely of numeric characters. -You cannot use the special characters + . , : ( ) - < >. Other special characters are reserved for internal use. -You cannot use the names of the predefined ABAP types (C, D, F, I, N, P, T, X,STRING, XSTRING) or the name of the generic type TABLE. You should not use names that are the same as an ABAP keyword or addition. -You should: • Use names that explain the meaning of the type without the need for further comments • Use the underscore character to separate compound words • Always use a letter as the first character of a variable name. -You declare local data types in a program either by referring to an existing data type or constructing a new type.

SELECT-OPTIONS structure

• LOW The data type of LOW is the same as the column type of the database table, to which the selection criterion is linked. • HIGH The data type of HIGH is the same as the column type of the database table, to which the selection criterion is linked.

Character Types

•c - CHAR: - Initial value = SPACE - Initial length = 1 - maximum length = 65535 n = NUMC: - Initial value = '0' - Initial length = 1 - Maximum length = 65535 - Can contain only digits: '0' .. '9' d = DATE: - Initialvalue = '000000' - Length = 8 - Format : 'YYYYMMDD' t = TIME: - Initial value = '00000' - Length = 6 - Format 'HHMMSS'

•Global Types

•specific types, defined by user •available at a general (global) level (eg: ABAP Dictionary)


Related study sets

Mental Health Nursing Chapter 14 Depressive Disorders

View Set

Sem 3 - Unit 5 - Miscarriage/Fertility - NCO

View Set

Brainstem: Topography and Levels

View Set

Chapter 5 Part 1- Finger, Hand, and Wrist

View Set

Macro Test 35 Influence of monetary and fiscal policy on agg demand

View Set

Chapter 12 - Supply Chain management in the service industry

View Set