Open SQL Examples in ABAP – Part 1

TABLES SCARR.
UPDATE SCARR.
SET CARRNAME = 'india' WHERE CARRID = 'MP'.
IF SY-SUBRC = 0.
MESSAGE 'record is updated successfully' TYPE I.
ELSE.
MESSAGE 'record is not updated' TYPE 'I'.
ENDIF.

Continue reading “Open SQL Examples in ABAP – Part 1”

OPEN SQL in ABAP

OPEN SQL commands that are used on database tables are

  1. SELECT
  2. INSERT
  3. UPDATE
  4. MODIFY
  5. DELETE
  6. COMMIT WORK

SELECT is used for getting records from dbtable.

  • SELECT….

ENDSELECT.

  • SELECT….  FROM TABLE INTO ITAB.

Continue reading “OPEN SQL in ABAP”

Views

VIEW is a DDIC object. It is used to join several tables to extract data from them with a common field relation.

A view is a pseudo table which doesn’t occupy any space in the database. It is stored in database as a PL/SQL statement.

There are FOUR types of views.

  1. Database Views
  2. Projection View
  3. Maintenance View
  4. Help View

We rarely create views. In some situations we create only database views. Instead of views we can use SELECT statements with JOINS  in the program itself.

Database View Continue reading “Views”

Table Types and Type Groups in ABAP

Table Types

Table types are type definitions for Internal tables. By using them you can declare internal tables in your program.

Creating a table type
  • Go to SE11, select Data type Radio button, provide a name for table type, and click Create button. Ex. ZTSCARR

typegr1

  • Select Table type radio button and click Continue.

typegr2

  • In the maintenance screen provide short text
  • Provide an existing DDIC structure name as line type. Ex. SCARR

Continue reading “Table Types and Type Groups in ABAP”

Domains and Data Elements

Domains

A domain provided Technical attributes (type, length and possible values) for a field. The definition of domain in ABAP is same as that in Mathematics.

In the world of Mathematics, a domain is defined as the set of input values that are valid for a given function. The same holds true for domains in ABAP. To understand this, let us first see what is the role of domains in ABAP data dictionary.

Domains -> Data Elements -> (Structures, DB tables, program references etc.) Continue reading “Domains and Data Elements”

Parameters in ABAP

  • Parameters keyword allows the user to provide values for variables through the input screen.
  • The input screen can be generated by the keywords Parameters or Select-options.
  • Technically input screen is known as Selection Screen. It’s screen number is standard and is 1000.
Ex. PARAMETERS A TYPE I.
PARAMETERS file_name(40) TYPE C DEFAULT 'c:\sample.txt'.
  • The data types F(Float), STRING and XSTRING are not allowed with parameters.

Parameters keyword can be used to generate Check boxes and Radio buttons on the selection screen. Continue reading “Parameters in ABAP”

Chained Statements in ABAP

The ABAP Programming language allows you to concatenate consecutive statements with an identical left part into a chain statement.

Chain statement:

WRITE: spfli-cityfrom, spfli-cityto, spfli-airpto.

Statement Sequence:

WRITE spfli-cityfrom.
WRITE spfli-cityto.
WRITE spfli-airpto.

You could for example, write the same statement like this:

WRITE: spfli-cityfrom,
       spfli-cityto,
       spfli-airpto.

Statement Sequence:

sum = sum + 1.
sum = sum + 2.
sum = sum + 3.
sum = sum + 4.

Chain Statement:

sum = sum + : 1, 2, 3, 4.

 

Mathematical Functions in ABAP

When library functions are used in calculations, at least one SPACE must be provided after the 1st bracket and before the last bracket of the function.

maths

Example:

K = SQRT (16).       Now K contains a value 4

P = trunc( ‘34.567’).    Now P contains a value 34

 

Control Statements in ABAP

To execute different program parts in connection with certain conditions or to combine recurring statement sequences as  loops, you can use standard keywords like IF, CASE, DO, and WHILE in the flow control of a program.

IF condition.
......
ELSE.
......
ENDIF.
IF condition-1.
......
ELSEIF condition-2.
.....
ELSEIF condition-3.
.....
ELSEIF condition-n.
....
ELSE.
ENDIF.
CASE variable.
WHEN value-1.
.....
WHEN value-2.
.....
WHEN value-3.
.....
WHEN OTHERS.
.....
ENDCASE.
DO n TIMES.
  statement_block.
ENDDO.
WHILE log_exp.
   statement_block.
ENDWHILE.

Statements which can be used optionally in loops…

  1. EXIT.                to come out of a loop suddenly
  2. CONTINUE.   to start the next iteration from middle of the loop
  3. CHECK.           to start the next iteration when condition fails.

Operators in ABAP

Operators are symbols used to perform some operations on Data Objects. In ABAP language, at least one SPACE must be provided in both sides of every operator.

Arithmetic Operators

operatorsoperator1

 

 

 

 

 

 

 

 

 

Statements also can be used instead of operators

operator2

Relational Operators

These are for comparing the item. Their result is always either True or False.

=, <>, <,  >, <=, >= or their equivalents

EQ, NE, LT, GT, LE, GE

and a special operator BETWEEN AND for range checking

Example:

5 < 3         is false.

5 GT 3      is True.

5 = 5         is True.

operator3

 

Logical Operators

For combining two or more conditions into a single condition.

AND      OR       NOT

 

String Comparison Operators

CO      Contains Only

CA      Contains any

CS       Contains String

CP      Suits Pattern

wildcard characters

‘*’ stands for no. of chars

‘+’ denotes any character

They are usually used along with IF statement.

Ex. IF ‘ABAP’ CO ‘AB’.   //Condition is False because there is P.

Ex. IF ‘ABAP’ CA ‘AB’.  //Condition is TRUE.

Ex. IF ‘ABAP’ CP  ‘+B’   //Condition is TRUE because 2nd character is B