SQL STATEMENT
INCLUDING UPDATE STRATEGIES
Open SQL & Native
SQL
Whenever a
transparent table is activated in the ABAP dictionary, a table of the same name
is automatically created within the database.
The key field in table is also called the primary key.
Every
relational database system has its own native
SQL, which is unfortunately database-specific.
Open SQL is database-independent SQL standard for ABAP.
Open SQL is database-independent SQL standard for ABAP.
All Open
SQL statements fill the following two system fields with return codes:
- SY-SUBRC
After every Open SQL statement, the system field SY-SUBRC contains 0 if the operation was successful, a value other than 0 if not. - SY-DBCNT
After an OPEN SQL statement, the system field SY-DBCNT contains the number of database lines processed.
Open SQL
contains the following keywords:
- SELECT - Reads data from database tables.
- INSERT - Adds lines to database tables.
- UPDATE - Changes the contents of lines of database tables.
- MODIFY - Inserts lines into database tables or changes the contents of existing lines.
- DELETE - Delete lines from database tables.
- OPEN CURSOR, FETCH, CLOSE CURSOR - Reads lines of database tables using the cursor.
Open SQL
statement do not perform any authorization checks automatically.
You must execute this explicitly in your program.
You must execute this explicitly in your program.
A SELECT statement is a loop. Except SELECT SINGLE & using the addition INTO TABLE or APPENDING TABLE.
It is important
to remember that you cannot specify a client MANDT in the WHERE clause unless
you provide the addition CLIENT
SPECIFIED
SELECT * FROM mara CLIENT SPECIFIED into TABLE itab WHERE mandt = 110 .
SELECT * FROM mara CLIENT SPECIFIED into TABLE itab WHERE mandt = 110 .
There are
two ways of causing a database rollback.
1. Sending a
termination dialog message ( a message with type A)
different message type: A(abend), E(error), I(Information), S(Status), W(Warning),X(Exit).
The transmission of an A type message cause a database rollback and terminates the programme.
different message type: A(abend), E(error), I(Information), S(Status), W(Warning),X(Exit).
The transmission of an A type message cause a database rollback and terminates the programme.
2. Using the ABAP statement ROLLBACK WORK
This statement ROLLBACK WORK cause a database rollback but does not terminate the programme.
LOGICAL UNIT OF WORKS
With LUW
changes are carried out together or not made at all.
When we use ABAP statement ROLLBACK WORK or COMMIT WORK, you explicitly implement a database rollback or database commit.
When we use ABAP statement ROLLBACK WORK or COMMIT WORK, you explicitly implement a database rollback or database commit.
LOCK OBJECT
We maintain lock object in the ABAP dictionary .
We maintain lock object in the ABAP dictionary .
The customer name space for lock object is EZ or EY.
When LOCK
object is successfully activated the system generate 2 function module.
DEQUEUE_EZDEMO
CALL FUNCTION 'DEQUEUE_EZASD'
* EXPORTING
* MODE_MARA = 'S'
* MANDT = SY-MANDT
* MATNR =
* X_MATNR = ' '
* _SCOPE = '3'
* _SYNCHRON = ' '
* _COLLECT = ' '
ENQUEUE_EZDEM
* EXPORTING
* MODE_MARA = 'S'
* MANDT = SY-MANDT
* MATNR =
* X_MATNR = ' '
* _SCOPE = '3'
* _SYNCHRON = ' '
* _COLLECT = ' '
ENQUEUE_EZDEM
CALL FUNCTION 'ENQUEUE_EZASD'
* EXPORTING
* MODE_MARA = 'S'
* MANDT = SY-MANDT
* MATNR =
* X_MATNR = ' '
* _SCOPE = '2'
* _WAIT = ' '
* _COLLECT = ' '
* EXCEPTIONS
* FOREIGN_LOCK = 1
* SYSTEM_FAILURE = 2
* OTHERS = 3
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
* EXPORTING
* MODE_MARA = 'S'
* MANDT = SY-MANDT
* MATNR =
* X_MATNR = ' '
* _SCOPE = '2'
* _WAIT = ' '
* _COLLECT = ' '
* EXCEPTIONS
* FOREIGN_LOCK = 1
* SYSTEM_FAILURE = 2
* OTHERS = 3
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
The lock
module created by the system automatically contains input parameters for the
lock parameters.
The lock module consists of the key fields of the primary table.
The lock module consists of the key fields of the primary table.
The lock module
ENQUEUE produces an exception if the
lock cannot be obtained.
Unlike ENQUEUE functional module, the DEQUEUE functional module do not trigger any exceptions
If you want to release all locks, you can use the functional module DEQUEUE_ALL.
Unlike ENQUEUE functional module, the DEQUEUE functional module do not trigger any exceptions
If you want to release all locks, you can use the functional module DEQUEUE_ALL.
If client is
not provided when the ENQUEUE function is called, the lock only applies to the
current execution client
If client is specified the lock only applies to that client.
If client is specified as space, the lock applies to all clients.
If client is specified the lock only applies to that client.
If client is specified as space, the lock applies to all clients.
We can override
the default lock module in the lock object by using the parameter MODE_.
The parameter X_
allows u to lock record that contains an initial value in the corresponding
parameter.
The parameter _SCOPE defines the validity area of the lock.
The parameter X_
The parameter _SCOPE defines the validity area of the lock.
The
parameter _WAIT defines whether the
lock request should be repeated if the first lock attempt fails.
The
parameter _COLLECT to store the lock
request in a local lock container.
To send the
content of the lock container with the
FM: FLUSH_ENQUEUE
Lock Mode:
E-Write Lock-(allow accumulation of locks)
S-Read Lock
X-Exclusive, (not allow accumulation of locks)
E-Write Lock-(allow accumulation of locks)
S-Read Lock
X-Exclusive, (not allow accumulation of locks)
BASIC ABAP PROGRAMS
& INTERFACE CREATION
Type group
also known as type pool are standalone program they do not contain any
executable code but only contain TYPE definition & CONSTANT definition.
Function
modules are always defined globally, whereas method is defined either globally
or locally.
Function modules do not provide returning values.
Function modules do not provide returning values.
Subroutines
do not provide input or output parameters directly because both USING &
CHANGING are treated as type of changing parameter; they do not provide for
returning values.
Pass by
reference is always preferable when performance is an issue, whereas pass by value
is more suitable for situation where robustness and data consistency are
important.
ABAP EVENT BLOCKS
Within event
blocks you cannot declare local data
type or data objects.
The event AT SELECTION-SCREEN & GET can contain local data type or data objects
The event AT SELECTION-SCREEN & GET can contain local data type or data objects
1
.LOAD-OF-PROGRAM - This event is only triggered once
2 .INITIALIZATION -
3 .AT-SELECTION-SCREEN-OUTPUT
4. AT SELECTION-SCREEN
5. START-OF-SELECTION
6.GET node
7.END-OF-SELECTION
2 .INITIALIZATION -
3 .AT-SELECTION-SCREEN-OUTPUT
4. AT SELECTION-SCREEN
5. START-OF-SELECTION
6.GET node
7.END-OF-SELECTION
The Events in
ABAP are,
Classical Events.
1) Initialization
2) Load of Program
3) At selection-screen output
4) At Selection-Screen of Field
5) At Selection-Screen on Value-Request
6) At Selection-Screen on Help-Request
7) At Selection-Screen
8) Start of Selection
9) End of Selection
10) Top of Page
11) End of Page
Interactive Events
12) At Line-Selection.
13) At PF key
14) At User-Command
15) Top-of-page During Line-Selection.
Module pool Programming events are
1) PAI - Process After Input
2) PBO - Process Before Output
3) POV - Process On Value Request (F1 HELP)
IS REQUESTED and IS SUPPLIED are the two
special keywords supplied by SAP for use in function modules. Classical Events.
1) Initialization
2) Load of Program
3) At selection-screen output
4) At Selection-Screen of Field
5) At Selection-Screen on Value-Request
6) At Selection-Screen on Help-Request
7) At Selection-Screen
8) Start of Selection
9) End of Selection
10) Top of Page
11) End of Page
Interactive Events
12) At Line-Selection.
13) At PF key
14) At User-Command
15) Top-of-page During Line-Selection.
Module pool Programming events are
1) PAI - Process After Input
2) PBO - Process Before Output
3) POV - Process On Value Request (F1 HELP)
IS REQUESTED:
Consider the following code in a function module:
If CARRNAME is requested.
Select single CARRNAME from SCARR
Where carrid eq I_carrid.
Endif.
The statement “If CARRNAME is requested” is true if the actual parameter was specified for the formal parameter CARRID, when the function module call was made. IS REQUESTED is allowed only in a function module and not even in a subroutine called by the function module. Suppose the call to the above function module in the program is as follows:
CALL FUNCTION 'ZSURESH_TEST1'
EXPORTING
CARRID = 'AA'
IMPORTING
CONNID = connid
* FLDATE =
* CARRNAME = carrname .
Since CARRNAME value is not requested in the program, the statement “If CARRNAME is requested” fails, thus avoiding unnecessary expensive database operation.
IS SUPPLIED:
This checks whether the parameter was passed during runtime (IMPORTING). For this the parameter should be optional, else the system raises an error. This statement can be used in function modules and methods.
AUTHORIZATION CHECKS
AUTHORITY-CHECK OBJECT 'M_EINF_WRK'
ID 'WERKS' FIELD '0002'
ID 'ACTVT' FIELD '02'.
AUTHORITY-CHECK OBJECT 'M_EINF_WRK'
ID 'WERKS' DUMMY
ID 'ACTVT' FIELD '01':
authority-check object 'Z_TCODE'
id 'ACTVT' field '03' " read access
id 'ZTCODE' field p_tcode. " actual value
id 'ACTVT' field '03' " read access
id 'ZTCODE' field p_tcode. " actual value
ABAP DICTIONARY
In ABAP
dictionary we create data types such as
1: data element
2.structures
3.table type
1: data element
2.structures
3.table type
The ABAP
Dictionary has 24 predefined data types.
The
conversion routine for the domain is identified as a five-character name, and
it generate two-function module for the conversion routine.
1. The
CONVERSION_EXIT_XXXXX_INPUT
2. The CONVERSION_EXIT_XXXXX_OUTPUT
2. The CONVERSION_EXIT_XXXXX_OUTPUT
To create
data elements in the ABAP dictionary you have to define data type.
The data type for the data element could be Elementary Type or Reference Type.
For Elementary data type you have to option to assign domain or predefined.
The data type for the data element could be Elementary Type or Reference Type.
For Elementary data type you have to option to assign domain or predefined.
Structures.
In ABAP dictionary we can define flat, nested or deep structure.
In ABAP dictionary we can define flat, nested or deep structure.
Table Types
1. Line type
2.Access Mode
3.Key
1. Line type
2.Access Mode
3.Key
UNICODE
From Release 6.10 onward, the SAP NetWeaver Application Server supports both Unicode & non-Unicode systems.
Non-Unicode
systems are conventional ABAP system, in which one character is usually
represented by one byte.
Unicode systems are ABAP system that are based on Unicode character set and that have corresponding underlying operating system & database.
Unicode systems are ABAP system that are based on Unicode character set and that have corresponding underlying operating system & database.
In Unicode
programs, only the following elementary data objects are now character-type:
Data type
|
Meaning
|
C
|
Text
field
|
D
|
Date
field
|
N
|
Numerical
text
|
T
|
Time
field
|
String
|
Text
string
|
In Unicode
programs, elementary data objects of types X and XSTRING are byte-type.
In Unicode,
an offset and/or length specification for a structure is only permitted if the
structure is
a) Character Type
b) Flat
a) Character Type
b) Flat
In addition,
structures are
character-type if they contain only flat character-type components (only
components from the above table with the exception of text strings).
Two
structures in Unicode programs are only compatible when all alignment
gaps are identical
on all platforms.
SAP supports the representations UTF-8, UTF-16, and UTF-32, and the byte order can be platform-dependent.
When opening
a file in TEXT MODE, the ENCODING
addition must be used to specify the character representation.
When opening a file in LEGACY MODE, the byte order (endian) and a non-Unicode code page must be specified.
When opening a file in LEGACY MODE, the byte order (endian) and a non-Unicode code page must be specified.
CLASSICAL SCREENS
Selection screen are created for an executable program and screen flow logic is required for dialog screens.
For screen in a module pool program type M, the start screen is specified in the transaction code you assign to the module pool.
CLEAR : It
will clear only Header of the internal Table.
Clear[]: it will
clear the content of the internal table
Refresh :
It will clear the Data in that internal table,but allocated memory will
remain.
Free
: It will clear the data as well as allocated memory for that internal
table.
The default
next screen is defined in the Screen Painter
The next screen number can be changed dynamically in the PAI flow logic by the ABAP statement SET SCREEN
The screen
flow logic consists of
1. Process Before Output (PBO)
2.Process After Input(PAI)
3.Process On Help-Request(POH)
4.Process On Value-Request(POV)
1. Process Before Output (PBO)
2.Process After Input(PAI)
3.Process On Help-Request(POH)
4.Process On Value-Request(POV)
The screen
flow logic must contain at least PBO and PAI events.
The screen
type can be normal screen, sub screen, or dialog box.
The
graphical layout editor has three buttons
1.Maintain Element Attributes
2.Get Dictionary/Program Fields
3.Show element List
1.Maintain Element Attributes
2.Get Dictionary/Program Fields
3.Show element List
Each screen has a 20-charcter OK field which is not displayed in the screen and which you must
name. The OK field is also referred to as the function code.
You also need to declare a data variable with exactly the same name of type SY-UCOMM.
You also need to declare a data variable with exactly the same name of type SY-UCOMM.
The field SY-DYNNR refer to current screen number.
Screen Numbers:
1000 – Selection Screen
>= 9000 – Custom Screen
9000-9500 – SAP Partners
>9500 – Customer
Screen
The FIELD statement is used in PAI, POH & POV.
The GUI
status & GUI title together make up the user interface for the screen.
The GUI status
consists of menu bar, standard tool bar, application toolbar &function key
& GUI TITLE
A menu bar
is made up of individual menus and can have up to EIGHT menus including the SYSTEM & HELP menu.
Each menu
can have up 15 entries or function
Functions
within the menu or toolbars are identified by function codes
The attributes FUNCTION TYPE is also sometimes referred to as functional type.
The attributes FUNCTION TYPE is also sometimes referred to as functional type.
The Function
Text is displayed as quick info for the icon or button.
The function
key assignment consist of reserved
function key, recommended function key & freely assigned function key.
No comments:
Post a Comment