Вы находитесь на странице: 1из 104

Client Server Architecture

Presentation Layer Application layer DB layer

More than one app server + Message


Server
User1
App Server Comps:

Abap workbench tools


User2
Kernel & basis service

Shared memory

Dispatcher
User3
Gateway

DB Interface

WPs

Components:

Presentation layer - SAP GUI (Graphical User Interface) – to connect SAP system

Application Layer – More no of application servers + Message Server

DB layer – DB(Data Base) + DBMS(Data Base Management System)


SAP:

Transaction Code: is to open application in sap

Menu Bar

Standard toolBar

Title Bar

Application toolbar

Application Body/Details

Status

Dialog Step – process between one Active state of GUI to immediate next active state

GUI
Active Idle Active

App server Idle Active Idle

Work process: is least component in app server to process any users request.

Screen Processor

ABAP processor

DB Interface
Different WPs:

1. Dialog WP -- to execute screen requests (to process Dialog step)


2. Update WP -- Executes DB updates
3. Background WP -- This is to execute program without user interference at specific time
period(Back ground job)
4. ENQUE WPs – This locks data to secure from multiple access
5. Spool WPs – to print data
SAP req -> Spool -> Printer

ABAP Program creation: SE38 or SE80

Package/Development Class: SE21 -> Transport layer

1. To hold bunch ABAP objects


2. Types of packages:
a. Local Package ($TMP) – which cannot be moved to other system
b. Transportable Package – to move to other systems
3. Creation of package
a. SE21->Z or Y <Pack Name>->Create/Display/Change->Description, Transport layer-
>SAVE->Assign TR
b. SE80->Select Package, give Package Name-> press Enter

Main Package

Package Package Package

ABAP Obj1 ABAP Obj2 ABAP Obj3

Transport requests:

1. Workbench request – Technical Developers


2. Customizing request – Functional team

STMS (SAP Transport Management system)

Transport request – Creation/Release (SE09) , Import (STMS)


System Landscape

TR
Development Quality Production

Landscape:
Sandbox

Checks In ABAP Program:

Static Check – Ctrl+f2 – any errors in statements

EPC(Extended Program Check) – Any hidden errors -

Dynamic Runtime Check – check at runtime - ST22

Text elements

TEXT-001 or ‘Test this’(001)

Text element or translated text element -> literal in program

Translations can be maintained in SE63

Pre defined Data Types:

Data type Length max posble length intial Value comments


C – Character 1 1-65535 Space a-z A-Z 0-9
%^&*()etc…
N-Numeric 1 1-65535 0 0-9
D-Date 8 00000000 YYYYMMDD
T-Time 6 000000 HHMMSS
X- Hexa 1 1-65535 X’000’
I - Integer 4bytes 0
P – Pack 8Bytes 0
F-Float 8Bytes 0
STRING At run time based
on values
XSTRING At run time based
on values
Character Data type C, N, D and T

Hexa decimal - X

Numeric data types – I, P and F


Object: Object occupies memory to hold value. This can be created only with ref to any type to assign
properties

Creation of obejct with ref to predefined data type


data w_a type c length 10.

W_a = ‘ABCD’ . fill from left to right

A B C D

data w_a type N length 10.

0 0 0 0 0 0 0 0 0 0
W_a = ‘4567’ . fill from right to left

0 0 0 0 0 0 4 5 6 7

Data w_p type p decimals 2.

Properties of an object:

1. Type
2. Length
3. Output-length
4. Decimals

Local types:

5. Types:
t_p5 type p length 5 decimals 2.
DATA:
w_m1 TYPE t_p5,
w_m2 TYPE t_p5,
w_m3 TYPE t_p5.

Local Data Objects: This occupies memory to hold values. Object can be created with ref to predefined
types (TYPE), local types (TYPE), types from ABAP dictionary (TYPE) and local objects(LIKE).

To create object, use DATA keyword.

DATA w_a type c length 10 value ‘A’.

DATA w_a2 like w_a.


Assigning Values:

MOVE <f1> TO <F2>.

Or

F2 = F1.

Debugging:

Break Point: this will be used to stop execution of the program to check runtime behavior of program
objects/variables. F5 for single step and F8 to complete program execution.

Predefined Data Objects:

1. SPACE 2. System variables like SY-UNAME, SY-DATUM, SY-UZEIT, SY-SYSID etc…


NOTE: DO not change system variable values in the program.

Clearing Content: CLEAR keyword initializes any type of variable

DATA:

w_p(5) type p decimals 2,

w_d type d,

w_c1 type c.

w_p = ‘3.45’.

w_d = ‘20130303’.

W_c1 = ‘X’.

CLEAR: w_p, “ 0.00

W_d, “00000000

W_c1. “space

CONSTATNTS:

CONSTANTS:
c_x TYPE c VALUE 'X'.

The value must be assigned at the time of declaration

Constant cannot be modified in the program


Determining technical attributes of data object:

DESCRIBE FIELD <F> [LENGTH <l>][ IN BYTE MODE/ IN CHARACTER MODE]

[TYPE <t>]

[OUTPUT-LENGTH <o>]

[DECIMALS <d>]

Specifying Source field Dynamically:

DATA:
w_d TYPE d,
w_c(10),
w_c1(5).

w_d = '20151223'.
w_c1 = 'W_D'.

WRITE w_c1 TO w_c.


CLEAR w_c.
WRITE (w_c1) TO w_c.
WRITE w_c.

If source field is not available, it returns SY-SUBRC <> 0

Assigning values with o/p conversion:

WRITE <SF> TO <Target> <options>.

This statement will move value target field by applying user default settings and options.

<options> for character fields:

LEFT-JUSTIFIED, CENTERED, RIGHT-JUSTIFIED, NO-GAP, NO-ZERO

<options> for numeric fields:

NO-SIGN, DECIMALS <d>, CURRENCY <c>, UNIT <u>

<options> for Date fields:

DD/MM/YYYY, MM/DD/YY, DD/MM/YYYY, MM/DD/YYYY

DATA:
w_d TYPE d,
w_d1 TYPE sy-datum,
w_c(10),
w_c1 LIKE w_c.

w_d = '20151223'.
w_d1 = '20151223'.

WRITE: w_d, w_d1, sy-datum.

MOVE:
w_d TO w_c,
w_d1 TO w_c1.

WRITE:/ w_c, w_c1.

CLEAR: w_c, w_c1.

WRITE:
w_d TO w_c,
w_d1 TO w_c1.

WRITE:/ w_c, w_c1.

DATA:
w_c2(15),
w_c3(5).

w_c3 = 'AbaP'.
WRITE w_c3 TO w_c2 CENTERED.
WRITE w_c2.

Conversions:

C5 C3 N5 N3 D T I P(4) P F
C5 Normal dump
C3
N5
N3
D No of
days
T
I
P(4)
P
F
Compatibility:

When source and target field properties are same, while move, value will not be disturbed. These two
variables are called symmetric compatibility.

Ex: DATA: W_C1(5),

W_C2(5).

MOVE W_C1 to W_C2.

When source and target field properties are similar but lengths are different, while move, value will be
discarded/disturbed but MOVE is successful. These two variables are called Asymmetric compatibility.

Ex: DATA: W_C1(15),

W_C2(5).

MOVE W_C1 to W_C2.

Convertibility:

When source and target field properties are different, while move, value will be moved after applying
conversion rule.

Ex: DATA: W_D TYPE D,

W_I TYPE I.

MOVE W_D to W_I.

Note: when date is moved to integer no of days between given date and 00010101 will be moved to
target.

Non-convertibility:

When source and target field properties are different, while move, system cannot execute statement
and it leads to runtime error.

Ex: DATA: W_C(5) TYPE C,

W_I TYPE I.

W_C = ‘AB’.

MOVE W_C to W_I.


Field Symbols:

1. These can be used to mention target field dynamically.


2. These will not occupy any physical memory but will point to a memory of other variable.
3. ASSIGN can be used to point to memory location of a variable
4. UN-ASSIGN can be used to de link the point to memory location of a variable.

DATA:
w_d TYPE d,
w_c(10).

FIELD-SYMBOLS:
<fs> LIKE w_c,
<fs1> TYPE ANY.

w_d = sy-datum.
w_c = 'Test'.

* cannot assign field symbol to non compatible variable


*ASSIGN w_d TO <fs>.

ASSIGN w_c TO <fs>.

ASSIGN w_d TO <fs1>.


* if FS is changed, it would reflect to variable which is being pointed by FS because both are referencing
same memory location.
MOVE '20130302' TO <fs1>.
ASSIGN w_c TO <fs1>.

WRITE <fs1>.

Arithmetic calculations:

+ Addition
- Subtraction
* Multiplications
/ Division - including fractions
DIV Division – only Quotient
MOD Reminder
** Power
DATA:
w_a TYPE i,
w_b TYPE i,
w_c(4) TYPE p DECIMALS 2.

w_a = 7.
w_b = 3.

w_c = w_a / w_b.

WRITE w_c.

w_c = w_a DIV w_b.

WRITE w_c.

w_c = w_a MOD w_b.

WRITE w_c.

Mathematical functions: <n> = <Func>( <m> ). If <m> eq '-2.345'.


ABS Absolute. Always gives positive value 2.345
SIGN +1.00 or -1.00 -1.00
CEIL Smallest integer value which is greater than argument value -2.00
Floor Largest integer value which is smaller than argument value -3.00
TRUNC Integer part -2.00
FRAC Fraction part -0.35

DATA:
w_a(4) TYPE p DECIMALS 2,
w_c(4) TYPE p DECIMALS 2.

w_c = '-2.345'.
w_a = ABS( w_c ).
WRITE w_a.

w_a = SIGN( w_c ).


WRITE w_a.

w_a = CEIL( w_c ).


WRITE w_a.

w_a = FLOOR( w_c ).


WRITE w_a.
w_a = TRUNC( w_c ).
WRITE w_a.

w_a = FRAC( w_c ).


WRITE w_a.

Date and Time calculations:

Arithmetic calculations can be applied on Date and Time. This will be calculated based on no of days and
secs.

DATA:

W_D TYPE D,

W_D1 TYPE D,

W_I TYPE I.

W_D = SY-DATUM.

W_D1 = W_D + 2.

W_I = W_D1 - W_D.

String Operations:

SHIFT SHIFT <STR> BY <N> PLACES <mode>.

If <mode> is LEFT, contents shifts <n> places to left and it adds <n> spaces to
right. If no space is available, characters got discarded.
If <mode> is RIGHT, contents shifts <n> places to RIGHT and it adds <n> spaces
to LEFT. If no space is available, characters got discarded.
If <mode> is CIRCULAR, contents shifts <n> places to left and it adds characters
to right which were discarded from left.

To shift according to first or last chars, use below


SHIFT <str> LEFT DELETING LEADING ‘Char’.
SHIFT <str> RIGHT DELETING TRAILING ‘Char’.
SHIFT <str> UPTO <wrd> <mode>.
REPLACE To replace filed contenet.
REPLACE w_wrd WITH w_rpl INTO w_str.
If word is replaced, then SY-SUBRC = 0. Otherwise <> 0
TRANSLATE TRANSLATE w_str TO UPPER CASE.
TRANSLATE w_str TO LOWER CASE.
SEARCH SEARCH w_str FOR w_wrd.
Above statement searches for w_wrd in w_str. If it wound, then SY-SUBRC = 0.
Otherwise <> 0. SY-FDPOS contains position in the string from which word
started.
‘.’ – single character ‘*’ - any no of chars
STRLEN No of chars of a string. <n> = STRLEN( <str> ).
CONDENSE CONDENSE <str> [NO-GAPS].
This statement removes any leading blanks and any blanks between words and
fills with single space between words. [NO-GAPS] extension removes all spaces
between words.

CONCATENATE CONCATENATE W_STR1 W_STR2 W_STR3 INTO W_STR


SEPARATED BY <C>.
If result fits, SY-SUBRC eq 0, otherwise SY-SUBRC <> 0

SPLIT SPLIT w_str at space


INTO w_str1 w_str2 w_str3 .
WRITE w_str.
To put all fragments into different target fields, we must specify required no of
fields. Otherwise the last target field is filled with rest of the string and still
contains separators.

If all fragments are having sufficient length and no fragment has to be


truncated, SY-SUBRC eq 0 otherwise, SY-SUBRC <> 0
Sections of string MOVE w_str1+4(5) to w_str2+5(4).

Structures: is to hold group of fields

Ex: Employee

ID Name Phone City Sal

Declaration of structure:

Structure type:

TYPES:
BEGIN OF ty_emp,
id(5),
name(20),
phone(10),
sal(4) TYPE p DECIMALS 2,
END OF ty_emp.
Structure Object

DATA:
wa_emp TYPE ty_emp,
BEGIN OF wa_emp1,
id(5),
name(20),
phone(10),
sal(4) TYPE p DECIMALS 2,
END OF wa_emp1.

MOVE:
'100' TO wa_emp-id,
'Test01' TO wa_emp-name,
'123456789' TO wa_emp-phone,
'234.56' TO wa_emp-sal.

WRITE:
5 wa_emp-id,
15 wa_emp-name,
25 wa_emp-phone,
40 wa_emp-sal.

Moving values from one structure other structure:

MOVE - Source structure to target structure having


same components with same sequence
MOVE - Source structure to target structure
having same components with different order -
all are character types
MOVE - Source structure to target structure having
same components with different order - at least
one numeric type is in different position
MOVE-CORRESPONDING
This takes time to identify suitable field in target
structure.
MOVE component by component
DEEP Structures/Nested Structures:

Structure inside structure is called deep structure

Id Name Phone Sal Adr

City State Ctry

TYPES:
BEGIN OF ty_adr,
city(10),
state(10),
END OF ty_adr.

DATA:
BEGIN OF wa_emp,
id(5),
name(20),
phone(10),
sal(4) TYPE p DECIMALS 2,
adr type ty_adr,
END OF wa_emp.

MOVE:
'100' TO wa_emp-id,
'Test01' TO wa_emp-name,
'123456789' TO wa_emp-phone,
'234.56' TO wa_emp-sal,
'Atlanta' to wa_emp-adr-city.

INCLUDE Structure Type:


This can be used to include all components of one structure type to another structure object.

TYPES:
BEGIN OF ty_adr,
city(10),
state(10),
END OF ty_adr.

DATA:
BEGIN OF wa_emp,
id(5),
name(20),
phone(10),
sal(4) TYPE p DECIMALS 2.
INCLUDE TYPE ty_adr.
DATA END OF wa_emp.

MOVE:
'100' TO wa_emp-id,
'Test01' TO wa_emp-name,
'123456789' TO wa_emp-phone,
'234.56' TO wa_emp-sal,
'Atlanta' TO wa_emp-city.

INCLUDE Structure Object:


This can be used to include all components of one structure object to another structure object.

DATA:
BEGIN OF wa_adr,
city(10),
state(10),
END OF wa_adr.

DATA:
BEGIN OF wa_emp,
id(5),
name(20),
phone(10),
sal(4) TYPE p DECIMALS 2.
INCLUDE STRUCTURE wa_adr.
DATA END OF wa_emp.

MOVE:
'100' TO wa_emp-id,
'Test01' TO wa_emp-name,
'123456789' TO wa_emp-phone,
'234.56' TO wa_emp-sal,
'Atlanta' TO wa_emp-city.

Usage of field strings on Structures:


DATA:
BEGIN OF wa_emp,
id(5),
name(10),
sal(7) TYPE p DECIMALS 4,
END OF wa_emp,
w_fname(20).

FIELD-SYMBOLS:
<fs> TYPE any.

MOVE 'ABCDEFGHIJKLMNO' TO wa_emp.


MOVE '3.45' TO wa_emp-sal.

ASSIGN wa_emp TO <fs>.


ASSIGN wa_emp-name TO <fs>.

w_fname = 'SAL'.
ASSIGN COMPONENT w_fname OF STRUCTURE wa_emp TO <fs>.
** If w_fname contains valid component of a structure, then above statement returns SY-SUBRC eq 0
** otherwise SY-SUBRC NE 0.
<fs> = '123.45'.
WRITE <fs>.

Controlling the program flow:

Using this technique, at run time, based on values, some set of statements can be executed.

IF condition:

IF w_marks <= 35.

Write ‘Failed’.

ELSEIF W_MARKS GT 35 AND W_MARKS LE 50.

Write ‘Grade B’.

ELSEIF W_MARKS GT 50 AND W_MARKS LE 70.

WRITE ‘Grade C’.

ELSE.

WRITE ‘Grade A’.

ENDIF.

For every IF, there is ENDIF.

There could be many ELSEIF but there should be only one ELSE.

ELSEIF and ELSE are not mandatory.


LOGICAL EXPRESSION:

Simple Logical expression

Positive Negative
W_MARKS > 35 NOT ( W_MARKS > 35 )
T F
F T

Compound Logical Expression

AND

w_marks >= 35 w_marks < 50 w_marks >= 35 AND w_marks < 50.
T T T
T F F
F T F
F F F

OR

w_marks >= 35 w_marks < 50 w_marks >= 35 OR w_marks < 50.


T T T
T F T
F T T
F F F

Logical operators

= or EQ

< or LT

> or GT

<= or LE

>= or GE

<> or NE

Checking for initial Value:


W_marks IS INITIAL

W_marks IS NOT INITIAL

Check whether field value belongs to a range:

<f> BETWEEN <F1> AND <F2>

Combining several logical expressions:

( ( f1 LO f2 ) AND ( f3 LO f4 ) ) OR ( f5 LO f6 )

Comparing strings:

CO Contains only

CA Contains ANy

CP Contains Pattern

CS Contains String

CN contains not only

NA

NS

NP

CASE Statement:

This can be used to check against fixed values

DATA:
w_dep(3).

w_dep = 'ZLG'.
CASE w_dep.
WHEN 'BOT' OR 'ZLG'.
WRITE 'Science'.
WHEN 'PHY' OR 'CHM'.
WRITE 'General Science'.
WHEN 'MAT'.
WRITE 'Maths'.
WHEN OTHERS.
WRITE 'Others'.
ENDCASE.

‘OTHERS’ is not a mandatory. This gets triggered when all above conditions are failed.

LOOPS:

Using loop, a set of statements can be executed repeatedly.

 Unconditional loops using DO


 Conditional loops using WHILE
 Loops through internal tables
 Loops through DB table using SELECT…..ENDSELECT

DO loop with fixed no of iterations:

DO <n> TIMES.

Statement1

Statement2

ENDDO.

DO 10 TIMES.
IF sy-index EQ 2.
CONTINUE.
ENDIF.
CHECK sy-index NE 3.
WRITE: / sy-index, 'Rama'.
IF sy-index EQ 5.
EXIT.
ENDIF.
ENDDO.
WRITE / 'EOL'.

SY-INDEX contains iteration number within the loop.

CONTINUE When this statement is reached, further statements in the loop will not be executed
and control goes to next iteration.
CHECK If logical expression in CHECK is true, then further statements gets executed. If it is
false, control goes to next iteration.
EXIT Control will come out from loop and it goes to statement after loop.
STOP Control will come out from loop and it goes to END-OF-SELECTION.
RETURN Will directly go to START-OF-SELECTION in reports. It leaves current block in screen
programming.

DO with infinite loop:

DO.
WRITE 'Tony'.
IF sy-index EQ 10.
EXIT.
ENDIF.
ENDDO.

Infinite loop should be end with EXIT statement other infinite loop never end.

Conditional loop using WHILE;

DATA:
w_count TYPE i.

WHILE w_count LE 5.
w_count = w_count + 1.
WRITE 'Tony'.
ENDWHILE.

Loop will be end when logical expression after WHILE is false.

Reading Structure components by DO…VARYING

DATA:
BEGIN OF wa_fcast,
mm01(4) TYPE p DECIMALS 2,
mm02(4) TYPE p DECIMALS 2,
mm03(4) TYPE p DECIMALS 2,
mm04(4) TYPE p DECIMALS 2,
mm05(4) TYPE p DECIMALS 2,
mm06(4) TYPE p DECIMALS 2,
END OF wa_fcast,
w_qty(4) TYPE p DECIMALS 2.

wa_fcast-mm01 = '130.55'.
wa_fcast-mm02 = '230.55'.
wa_fcast-mm03 = '330.55'.
wa_fcast-mm04 = '430.55'.
wa_fcast-mm05 = '530.55'.
wa_fcast-mm06 = '630.55'.
DO 6 TIMES VARYING w_qty FROM wa_fcast-mm01
NEXT wa_fcast-mm02.

WRITE / w_qty.
ENDDO.

DO 3 TIMES VARYING w_qty FROM wa_fcast-mm01


NEXT wa_fcast-mm03.

WRITE / w_qty.
ENDDO.

Large Volumes of Data: To hold multiple records, there are following techniques

1. Internal tables
This technique can be used to hold multiple records of same structure
2. Extracts
This technique can be used to hold multiple records of different structure

Internal Tables

Employee

Index ID Phone Name City Salary


Header
1 100 12345 TEST HYD 200.50
2 101 32456 TEST1 HYD 12345.67
3 102 45623 Test2 hyd
4 103
5 104

Declaration of internal table

TYEPES/DATA <ITAB> TYPE/LIKE <Tab kind> OF <WA type>/<WA Obj>

WITH KEY <F1> <f2> [UNIQUE/NON-UNIQUE]

[INITIAL SIZE <n>]

[WITH HEADER LINE].


LINE TYPE (WORK AREA): this is a structure and each component of structure will be a column of
internal table.

Without header Line

 To create this, it requires a explicit work area.


 Internal table name always represents body.

it_emp LIKE STANDARD TABLE OF wa_emp

With header Line

 To create this, it requires WITH HEADER LINE addition


 At the time of declaring Internal table, it creates one header (work area) and one body. To
represent a body we should use IT_EMP1[] and to represent a header we should use IT_EMP1.

it_emp1 LIKE STANDARD TABLE OF wa_emp WITH HEADER LINE

INITIAL SIZE: at the time of declaration, system allocate some memory (8KB) by default, when more no
of records are inserted, system allocate double the size of memory for further records. INTIAL SIZE can
be used to allocate space by default for records specified after INTIAL SIZE

Key – this is to identify/represents a record.

 Standard Key – If there is no custom defined as a key, standard key will be assigned by system to
internal table as a key at runtime. Combination of Non numeric fields in the internal table is a
standard key
 User Defined Key – at the time of declaration, we can assign required fields as key using WITH
KEY addition like below.
it_emp LIKE STANDARD TABLE OF wa_emp WITH KEY id,
 Key can be two types
o Unique key: Internal tables with a unique key cannot contain duplicate records on key
fields.
o No Unique Key: this type of internal table can contain duplicate records.
Types of itabs ITAB TYPES

Index Table

Standard Table Sorted Table Hashed Table

Standard

Inserting a record is quick since it always inserts at last position

Reading a record consumes time since it searches record by record

Reading a record can be improved using SORT + READ USING BINARY SEARCH operations

Sorted

Inserting a record consumes since it searches for suitable position

Reading a record is very quick since it uses Binary search

Hashed

Inserting or reading a record uses Hashed Algorithm

Read and Insert at any position takes same time

Operations on Internal tables

WHO WH
Adding a record wa_emp-id = '100'. it_emp1-id = '100'.
---Always adds record to in last wa_emp-name = 'Test01'. it_emp1-name = 'Test01'.
position in standard table wa_emp-sal = '2003.45'. it_emp1-sal = '2003.45'.
append wa_emp to it_emp. append it_emp1 to it_emp1.
Note: will go for dump when a OR
record is added in non Append it_emp1.
sequence on SORTED table. OR
Note2: if it unique, duplicate APPEND WA_EMP to IT_EMP1.
record leads to dump
INSERT SINGLE record INSERT WA INSERT ITAB
This can be used to insert a INTO ITAB INDEX <n>
record at any position INDEX <n>
Note: if index is not available,
system returns SY-SUBRC NE 0
Adding more no of records to APPEND LINES OF ITAB1 TO SAME
target ITAB2.
Inserting no of records to INSERT LINES OF <ITAB1> SAME
target [FROM <n1>] [TO <n2>]
INTO <ITAB2>
INDEX <N>.
Note1: if only FROM is
mentioned, then inserts all lines
from FROM
Note2: if only TO is mentioned,
then inserts all lines from start to
TO line
Moving Lines MOVE ITAB1 TO ITAB2 MOVE ITAB1 TO ITAB2[]
Deletes all records from target
ITAB and moves all records of
source to target. This can be
done only on similar tables
Modify Line MODIFY ITAB MODIFY TABLE ITAB
This statement modifies all FROM WA INDEX <N>
fields from work area. If INDEX <N> TRANSPORTING f1 f2.
required, to modify only few TRANSPORTING f1 f2.
fields, use TRANSPORTING Note: if index is not correct, ?
addition.
Modify Multiple lines MODIFY ITAB MODIFY TABLE ITAB
Note: if success, SY-SUBRC = 0 FROM WA TRANSPORTING f1 f2
SY-TABIX = line TRANSPORTING f1 f2 WHERE F3 = val.
WHERE F3 = val.
Note: If no record exists for
condition, ?
Delete Line DELETE ITAB SAME
INDEX <N>.
Delete multiple lines DELETE ITAB
WHERE F3 = val.
Deleting adjacent duplicate DELETE ADJACENT DUPLICATES
lines FROM ITAB
---itab must be in sorted order COMPARING F1 f2.
on f1 and f2
Clearing header - CLEAR ITAB.
Clearing Body CLEAR ITAB. CLEAR ITAB[]
OR OR
REFRESH ITAB. REFRESH ITAB.
De allocate memory FREE ITAB FREE ITAB
--- Memory will be initialized
Initial check against itab IF ITAB IS NOT INITIAL. IF ITAB[] IS NOT INITIAL
IF ITAB IS INITIAL IF ITAB[] IS INITIAL
SORTING INTERNAL TABLE SORT ITAB SAME
[BY F1 ASCENDING
---- DEFAULT SORT IS F2 DESCENDING]
ASCENDING
---- IF NO FIELDS ARE
MENTIONED, KEY MENTIONED
IN DECLARATION WILL BE
CONSIDERED. IF NO KEY IS
MENTIONED, STANDARD KEY
WILL BE CONSIDERED

READ using INDEX READ TABLE ITAB INTO WA


INDEX <n>

READING RECORD READ TABLE ITAB READ TABLE ITAB


---- SINGLE LINE INTO WORK INTO WA WITH KEY F1 = VAL
AREA. If success, SY-SUBRC = 0 WITH KEY F1 = VAL [TRANSPORTING F1 F2]
And SY-TABIX = line index [TRANSPORTING F1 F2 / NO- [BINARY SEARCH ]
---- To improve the FIELDS]
performance, use Binary search [BINARY SEARCH ]
----if Binary search used, SORT
internal table in ascending
order on key fields mentioned
in WITH KEY of READ
---- Binary search divides itab
into 2 halfs, if search value is
less, it checks for top half,
otherwise it search for bottom
half. If internal table sorted in
descending order high values
will be in the top hence READ
will be failed.
---to Transport only required
fields use TRANSPORT option.
--- to check whether with key
condition record exist, use
TRANSPORTING NO FIELDS
To get technical attributes of DESCRIBE TABLE ITAB Same
ITAB LINES <ln>
OCCURS <n>
KIND <c>.

Summarizing lines COLLECT WA INTO ITAB COLLECT ITAB


--- if duplicate record on non
numeric fields exists, instead of
adding record, it adds numeric
field values to exiting record in
ITAB
Processing all record in internal LOOP ITAB INTO WA LOOP ITAB
table using LOOP [FROM <n>][TO <n2>] [FROM <n>][TO <n2>]
[WHERE <LE>]. [WHERE <LE>].
Statement 1 Statement 1
Statement 2 Statement 2
Etc… Etc…
ENDLOOP. ENDLOOP.
If where condition failed, sy-
subrc ne 0.
If Where condition is satisfied
then it will not touch SY-SUBRC
Control break statements Loop at ITAB into WA.
Note#1: Within the block,
values of other than hierarchy *this block execute for first
fields contains * for character record of itab
and 0 for numeric. AT FIRST …… ENDAT.
Note#2: Key word SUM, adds
all numeric fields of hierarchy
and will be placed in work area
within the control block
Note#3: Before using control
breaks ITAB must be sorted to *this block executes for new
generate hierarchies. record of combination of fields
till F1 in ITAB
AT NEW F1….. ENDAT.

*this block executes for end of


record of combination of fields
till F1 in ITAB
AT END OF F1….ENDAT.

*this block execute for last


record of itab
AT LAST…. ENDAT.
Endloop.
Exit from loop CHECK and CONTINUE to go to
next iteration

EXIT and STOP to comeout from


loop
Parallel cursors Parallel cursors can be used to
process loop within the loop
efficiently.

Within first loop, read


appropriate position of a record
in second internal table
Loop second internal table from
that position, if position is
identified.

Check if first record common


field value is equal to second
common field value. If they are
different come out from second
internal table.
Field symbol usage Field symbol will directly point to
memory of a record.

If field symbol changed in loop,


immediately it reflects change in
internal table.

FIELD-SYMBOLS:
<fs> LIKE wa_std.
LOOP AT it_std ASSIGNING <fs>.
<fs>-name = 'ABC'.
WRITE:/ <fs>-id.
ENDLOOP.

Parallel Cursors example:

DATA:
BEGIN OF wa_std,
id(3),
name(5),
END OF wa_std,
it_std LIKE TABLE OF wa_std,
BEGIN OF wa_std_marks,
id(3),
exam,
marks(3) TYPE n,
END OF wa_std_marks,
it_std_marks LIKE TABLE OF wa_std_marks.

wa_std-id = '100'.
wa_std-name = 'Test01'.
APPEND wa_std TO it_std.

wa_std-id = '101'.
wa_std-name = 'Test02'.
APPEND wa_std TO it_std.

wa_std-id = '102'.
wa_std-name = 'Test03'.
APPEND wa_std TO it_std.

wa_std-id = '103'.
wa_std-name = 'Test04'.
APPEND wa_std TO it_std.

wa_std_marks-id = '101'.
wa_std_marks-exam = 'A'.
wa_std_marks-marks = 25.
APPEND wa_std_marks TO it_std_marks.

wa_std_marks-id = '101'.
wa_std_marks-exam = 'B'.
wa_std_marks-marks = 24.
APPEND wa_std_marks TO it_std_marks.

wa_std_marks-id = '101'.
wa_std_marks-exam = 'C'.
wa_std_marks-marks = 23.
APPEND wa_std_marks TO it_std_marks.

wa_std_marks-id = '101'.
wa_std_marks-exam = 'D'.
wa_std_marks-marks = 22.
APPEND wa_std_marks TO it_std_marks.

wa_std_marks-id = '102'.
wa_std_marks-exam = 'A'.
wa_std_marks-marks = 15.
APPEND wa_std_marks TO it_std_marks.

wa_std_marks-id = '102'.
wa_std_marks-exam = 'B'.
wa_std_marks-marks = 14.
APPEND wa_std_marks TO it_std_marks.

wa_std_marks-id = '102'.
wa_std_marks-exam = 'D'.
wa_std_marks-marks = 12.
APPEND wa_std_marks TO it_std_marks.

SORT:
it_std BY id,
it_std_marks BY id.
LOOP AT it_std INTO wa_std.
WRITE:/ wa_std-id.
READ TABLE it_std_marks TRANSPORTING NO FIELDS
WITH KEY id = wa_std-id
BINARY SEARCH.
IF sy-subrc EQ 0.
LOOP AT it_std_marks INTO wa_std_marks
FROM sy-tabix.
IF wa_std-id = wa_std_marks-id.
WRITE:/ wa_std_marks-id,
wa_std_marks-exam,
wa_std_marks-marks.
ELSE.
EXIT.
ENDIF.
ENDLOOP.
ENDIF.
ENDLOOP.

Modularization Techniques: ABAP allows modularizing source code by placing ABAP statements either
locally in the program or globally. These help us to avoid repeatedly written the same set of statements
and to program easier to understand and maintain.

1. Includes
2. Macros
3. Subroutines
4. Function Modules
5. Methods – in OOABAP
6. Dialog Modules – Screen Program/Dialogue program
7. Event blocks – These will be called by runtime component

Include:

This is a global modularization technique

Go to SE38 -> give program name starting with Z or Y -> create -> select INCLUDE type->write required
statements. To call include program in a program, use INCLUDE statement like below.

INCLUDE ZABAP5_DEMO_INC_01.

- Where used list can be used to see no of programs that are using an include.
- Cannot be executed
- Reusability

Macros: This is a local modularization technique within the program. This can be used for simple
calculations or for simple set of statements. This can be make it as global by using INCLUDE
Declaration of MACRO:

DEFINE zadd.
&3 = &1 + &2.
&3 = &3 / 2.
END-OF-DEFINITION.

Calling a Macro:

ZADD &1 &2 &3.

 Macro call is Call by reference – if you change formal parameters in the macro, it would reflect
to actual parameters since formal parameters point to actual parameters memory locations.
 We can pass only 9 parameters &1 &2 &3 …. &9 to macro.

Example:

DEFINE zadd.
&3 = &1 + &2.
&3 = &3 / 2.
END-OF-DEFINITION.
Y-EHS-Nookireddy < >
DATA:
w_a TYPE i,
w_b TYPE i,
w_c TYPE i.

w_a = 23.
w_b = 45.

zadd w_a w_b w_c.

WRITE w_c.

w_a = 123.
w_b = 145.
zadd w_a w_b w_c.
WRITE w_c.
Subroutines: Local modularization technique but can be make it as global by using INCLUDE

 Call Subroutine:
PERFORM <form name> TABLES <IT1>
<IT2>
USING <var1> “ Actual parameters
<var2>
CHANGING <Chg_var1>
<chg_var2>
.
 Creation of subroutine:
FORM <form name> USING <var1> ““ Formal parameters
VALUE(<var2>)
CHANGING <CHG_VAr1>
VALUE(CHG_VAR2)
TABLES <IT1>
VALUE( IT2).
Statement1
Statement2
ENDFORM.
 Call by value: formal parameters will occupy separate memory. When subroutine is called,
USING and CHANGING actual parameters will be moved to formal parameters. At end of call,
only CHANGING formal parameters will be moved back to actual parameters but USING formal
parameters will not be moved back to actual parameters. Use VALUE addition to make a
parameter as call by value. Table parameters cannot be pass by value
 Call by reference: formal parameters will not occupy separate memory. When subroutine is
called, USING and CHANGING actual parameters will be pointed by formal parameters. If any
formal parameter changed in subroutine, it immediately reflects to actual parameter since both
points to same memory location. Hence there is no difference in between USING and
CHANGING.
 Local variables of a subroutine are not available out of subroutine. These can be used only
within the subroutine. Memories of a local variable will be deleted at the time of completion of
subroutine.
 STATIC variable values will be retained for next call of subroutine but will not be available out of
subroutine. Memories of static variable will not be deleted, but only available in the subroutine.
 If any global variable declared with LOCAL in the subroutine, global variables values will not be
reflected after subroutine call.
 CHECK, EXIT and STOP can be used to come out from subroutine.
 Subroutine of other program can be called from program using below. IF FOUND addition can
be used to avoid dump when there is no subroutine.
PERFORM <Form Name>[IN PROGRAM <PGM>] USING ….
CHANGING ….
TABLES ….
IF FOUND.
DATA:
w_a TYPE i,
w_b TYPE i,
w_c TYPE i,
w_c1 TYPE i,
w_d TYPE i,
w_d1 TYPE i.

w_a = 23.
w_b = 34.

w_d = 34.
w_d1 = 45.

PERFORM zadd USING w_a


w_b
CHANGING w_c
w_c1.
WRITE w_c.

w_a = 123.
w_b = 134.

PERFORM zadd USING w_a


w_b
CHANGING w_c
w_c1.
WRITE w_c.
FORM zadd USING pw_a
value(pw_b)
CHANGING pw_c
value(pw_c1).
DATA: lw_a TYPE i.
STATICS:
lw_a1 TYPE i.
* Global Variable W_D1 will not be affected. another memory created
* with same properties of global variable for subroutine
LOCAL w_d1.
lw_a = lw_a + 3.
lw_a1 = lw_a1 + 3.
lw_a = 34.
pw_a = 423.
pw_c = 434.
pw_b = 634.
pw_c1 = 534.
pw_c = pw_a + pw_b.
pw_c = pw_c / 2.

w_d = 12.
w_d1 = 64.
ENDFORM.
Function Modules: This is for global modularization technique. This is an independent object and this
can be called from any other ABAP objects.

Function Group: Function group is a holder to hold bunch of function modules.

 Creation of function group: go to SE80->select FG, give FG name <Z or Y> and press enter or go
to SE37->go to from menu->function groups ->Create.
 Main Program gets created by name SAPL<FG name> of type function pool program. Below is
the structure of main program.
 Global data can be defined for FG in INCLUDE L<FG>TOP FUNCTION-POOL <FG>.
This data can be accessed by any function module in
TABLES:
The FG.
TYPES

DATA:
INCLUDE L<FG>TOP
Subroutines

Macros

INCLUDE L<FG>Uxx
INCLUDE L<FG>U01 FUNCTION <FM NAME>.

INCLUDE L<FG>U02

ENDFUNCTION.

INCLUDE L<FG>Fxx
FORM

 Subroutines

ENDFORM

Creation of FM: go to SE37->give FM name start with Z or Y->Create->give FG name->Continue. This


contains following components.
 Attributes: This contains administrative data
o Function module Type:
 Normal function module: this can be called with in SAP system
 Remote enabled FM: this can be called from third party systems and within the
system.
 Update FM: this can be created to update data in database.
 Import: This can be used to get data into FM and FM uses this data for internal purpose. Pass by
reference parameters cannot be modified in the FM
 Export: this can be used to pass data from FM. Pass by value parameter will not receive data
from caller.
 Changing: this receives data into FM and pass modified value from FM.
 Tables: this receives internal table data and passes internal table data.
 Source code: this contains actual program of FM

Test FM: Execute from SE37. If required, Debug from SE37.

Call FM: go to program->click on pattern->give FM name -> Continue.

Exceptions: go to exceptions->provide exception names

 If exception is raised using below statement, further statements would not be executed in FM
and immediately control returns to program.
RAISE <Exception>.
 When FM is called, each exception would be assigned with one number, when exception is
raised, SY-SUBRC would be set with this value.

CALL FUNCTION 'ZABAP4_DEMO_FM_03'


EXPORTING
i_a = w_a
i_b = w_b
IMPORTING
e_c = w_c
EXCEPTIONS
devide_by_zero = 11
OTHERS = 2.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
DBMS – Database Management Systems

DDL – Data definition Language – SAP uses ABAP Dictionary

DML – Data Manipulation Language – SAP uses Open SQL or Native SQL

DCL – Data Control Language – SAP uses SAP Security (Roles), LOCK Mechanism

Employee:

ID NAME PHONE SAL Currency Weight UOM Memory ID


100 2000 INR 50 KG A000
101 3000 USD 45 Pound A001
102 A002

SQL:

PS AS DB

HYD – TPTY = 10

ABAP Dictionary: SE11, 12, 14, 16, 16N, SM30, SM12

TABELS

VIEWS

DATA TYPE

TYPE GROUP

DOMAIN

SEARCH HELP

LOCK OBJECT
Creation of table:

 Go to SE11->select database table-> give table name starting with Z or Y->click Create->give
short description.
 Go to delivery and maintenance tab -> Delivery class - C, Data browser - table maintenance
allowed
 Go to Fields Tab -> give field info like below
Key Initial Data element Predefined type Reference Reference
table field
MANDT X X MANDT
ID X X CHAR 5
NAME CHAR 15
PHONE NUMC 10
SAL CURR Same table CURRENCY
name
CURRENCY CUKY
WEIGHT QUAN Same table UOM
name
UOM UNIT
 Go to Extras, Enhancement->Select ‘can be enhanced’
 Go to Technical settings->select data class APPL0->size category – 0
 SAVE , Check and Activate
 After activation, table will be created in physical data base and a runtime object gets. These
properties can be seen in Utilities->Runtime Object
 Creation of table entries ->Utilities->table contents->create Entries
 To view data -> go to SE16 or SE16N->table name->execute

Client: Client is an autonomous unit in the R/3 System with regard to commercial law, organization data.

800 – Electronics, 810 – Agri Business, 820 – Petrol

100 – North America, 110 – Europe..

Client Independent If any table is not having MANDT field, which is treated as client independent
since data in one client is available for other client. Also we call it as a cross-client
Client Dependent If any table is having MANDT field, which is treated as client dependent since
data in one client is not available for other client. MANDT must be first field of a
table.

Key: Key is a combination of fields or a single field and must be defined in a table to represent a unique
record. This is called Primary index key.
Reference field and Reference Table: Currency and amount must be assigned to a currency key and
Unit.

Field Reference field


Currency (CURR) Currency Key (CUKY)
Quantity(QUAN) Unit of Measure (UNIT)

Delivery Class – Upgrade and transportation behavior

Client Copy
Upgradation behavior
Behavior during transport between customer
systems

Table Maintenance generator: This can be used to create/Maintain entries in a table from SM30

Go to SE11->Utilities->Table Maintenance generator->Auth group, Function group, Screen number->


create Entries.

Data Browser and table view maint

Entry from SE11 or SE16 Entry from SM30


Maint Allowed Maint and Display are possible Table maintenance generator (Table
maintenance generator – SE54)
is possible and data can be
maintained from SM30.
Maint Not allowed Maint and Display are not Not possible to generate
possible maintenance dialogue to create
entries from SM30

Table maintenance generator is


Maint allowed with restriction Maint is not possible but possible but maintenance in SM30 is
Display is possible not possible.

To maintain data create View maint


from SM34

Types of Data

Customizing data - APPL2 One time activity – Rarely modifies – this will be
done by functional team in SPRO transaction in
SAP
Master Data – APPL0 Rarely created and rarely updated
Transaction data – APPL1 frequently created and frequently updated
Repository data Objects which are stored in repository area of
table are called Repository Objects
Data Class: The data class defines the physical area of the database (for ORACLE the TABLESPACE) in
which your table is logically stored. APPL0-Master data, APPL1-Transactional, APPL2-Customization data,
USER* - Customer data class.

Size Category:

The size category determines the probable space requirement for a table in the database.

When you create a table, initial space is saved for it in the database. If more space is required later, the
storage space is increased in accordance with the category selected.

Buffer: This can be used to hold data temporarily to avoid unnecessary DB hits

1 AS – Buffer
User1 is accessing
1
for first for a record 4 After step 2, 2
from Table 51 data will be 1
placed here 3 A
1 6 1 B
1
If User 2 is accessing 7 8 C
same record, data 1 1
will be picked from
buffer

1. User1 reading Emp1 data from DB -> keep it in buffer -> transfer to User1 8:05 AM
2. User 2 updated Emp1 record in DB. 8:10 AM
3. Purge program will run to validate Buffer data against DB 8:12 AM
4. User 1 is trying to read Emp1 record data 8:15AM

Note: Purge Program will be executed in frequent intervals. For business critical data, avoid buffers.

Buffer Techniques:

Buffering Not allowed Data will not be put in buffer


Buffering Allowed 1. Single record will be put in buffer
1. Single record buffer 2. All records which are having same value in
2. Generic area buffer part of key fields will be put in buffer
3. Fully buffered 3. All records will be put in buffer
Buffering allowed but switched off
Indexes: Indexes are two types. Searching a record on index fields will give better performance since it
uses binary search. More no of indexes causes delay in inserting a record because system should insert a
record in all index tables.

1. Primary Index – This index table contains primary key fields


2. Secondary Index – this contains non primary key fields.

Table data:

PK1 ID PK2 Dep PK3 month Analyzed F2 attd Memory ID


by
100 MAT 01 A 20 A001
100 MAT 02 B 22 A002
100 PHY 01 A 21 A003
100 PHY 02 B 23 A004
100 PHY 03 A 22 A005

Primary Index table on PK1, PK2 and PK3 fields

PK1 PK2 PK3 Memory ID


100 MAT 01 A001
100 MAT 02 A002
100 PHY 01 A003
100 PHY 02 A004
100 PHY 03 A005

Secondary index table on Analyzed by field

Analyzed by Memory ID
A A001
A A003
A A005
B A002
B A004

Creation of object in program with ref to table field:

* to create WA with table name use below but Should not be used
TABLES: ZEMP1
DATA:
* Creation of object with ref to table field
W_name type zemp1-name
* Creation of object with ref to table field - QUAN of table -> PACK
W_weight type zemp1-weight

* WA with ref to table


Wa_emp type zemp1
* WA for only required fields of table
Begin of wa_emp,
Id type zemp1-id,
Name type zemp1-name,
End of wa_emp.

Structures:

1. Global structure types will be used to create objects in the program, FM etc..
2. This can be used to include fields in another table or structure
3. This will not hold any record directly

Creation of structure: SE11->select data type->start name with Z or Y->create->select Structure->click


create->give fields and its properties->Save, check and activate

Include Structure: go to table in SE11->EDIT-> Include-> Insert->give structure name.

 .INCLUDE will be created as a component. All fields of structure will be inserted to table or
structure.
 This can be inserted at any position in the table or another structure.
 One structure can be included to any number of tables.
 To include a structure to a standard table, it requires access key.

Append Structure: Go to SE11->append structure

 Exiting structure cannot be used as an APPEND structure.


 One structure can be appended only to one table or structure.
 Append structure will be added at last position of table.
 When it is inserted, .APPEND will be added as a component.
 This will be used to add fields to standard tables. This will not require any access key.

Adjusting table: (SE14): If a table field technical properties like length is changed (Length is reduced),
activation of table can be done only after changing the exiting data according to new technical
properties. To adjust and activate the table use DB utility (SE14)
DATA ELEMENT

Contains Application properties like Labels, Documentation for F1 help, F4 by providing search help,
Set/Get parameter

Creation of Data element:

SE11->data type->Z* or Y*->Create->select data element->Continue->Desciption->Select domain or


Predefined type.

 If predefine type is selected, give data type, length and decimals


 If domain is selected, give domain, technical properties will be copied from domain
 Give field lables
 If required, Write documentation for F1 help

Usages:

 To create a field in table or structure in SE11. Go to table field, select data element, give data
element name. one data element can be used to create any number of fields.
 To create variables in the program
 To create interface (Import/export parameters…) in FM

Domain

DE
Table field
Predefined
type
Predefined
type

Domain: Domain contains technical properties of a field like type, length, decimals, sign, lower,
conversion routine, fixed values, ranges and value table.

Creation of domain: go to SE11->Select domain->Z* or Y*->Create->give required properties->SAVE,


CHECK and Activate

 Lower check box can be used to allow user to enter lower case values in character fields.
 Sign can be used to enter negative values in numeric fields.
 Conversion routine: this is to convert data from internal (DB) format to user (Output) format.
And output (User) format to internal format. When conversion is created, two FMs gets
generated like below.
 Format or
User Conversion DB format or Input

output format routine format or internal
 format
(Material - 1)

CONVERSION_EXIT_MATN1_INPUT output to Input


CONVERSION_EXIT_MATN1_OUTPUT Input to output

Value Range: This can be used to provide F4 help and to restrict value entry.

 Fixed values: Only values that are maintained as fixed values can be entered in this field
 Ranges: This can be used to provide range of values in F4. Only values under this range can be
entered in this field.
 Value table:
o Maintain master table in domain as a value table.
o On F4, all values in master table will be shown if we maintain foreign key relationship
between transactional table and value table.
 To establish foreign key link, go to transactional table->select field name->click
on foreign key relationship.
 Foreign Key: establish a link between two tables. Transactional data table is
foreign key table and value table is a check table.
 If check required option is set, then values other than master table cannot be
used but F4 will be shown.
 If check required option is not set, then values other than master can also be
used and F4 will be shown

Domain ZZID
EMP Master
Table 1st step:
DE ZZID
Value table is
Emp Atd Table master table

2nd step:

Goto transaction table

Establish Check table link at


table field by using FK
Usage: Assign domain to data element. Go to Data element->select domain->give domain name

Table Types: this can be used to create any internal tables in program and to create table types in FM.

 Create a structure
 Create table type using above structure -> go to SE11->select data type->give table type
-> click create -> assign line type -> SAVE, check and activate.
 For testing create internal table with ref to above table type

Type Group: this is a pool with all types. This can be used to create objects in any program. Before using
in program, this must be mentioned using below statement.

TYPE-POOLS: slis.

Text Table: if we want to maintain texts in different languages, we should maintain text table for a
master table. Go to GOTO->Text table.

Text table must contain language key in part of primary key.

This can be used to create a F4 help with descriptions in login language.

Ex:

T005 -> T005T

Country Codes T005

IN

US

Country code desc T005t

EN IN India

DE IN German

VIEWS: View does not occupy any physical memory in DB. This will get data at run time.

 Type of views:
o DB View
o Projection view
o Help view
o Maintenance view
JOINS:

Table A

ID NAME PHONE
100 A 1
101 B 2
102 C 3
103 D 4

Table B

ID Weight
100 10
102 20
103 30
104 40

Table A INNER JOIN TABLE B on ID

A~ID A~NAME B~WEIGHT


100 A 10
102 C 20
103 D 40

Table A LEFT OUTER JOIN TABLE B on ID

A~ID A~NAME B~WEIGHT


100 A 10
101 B
102 C 20
103 D 30

Table A RIGHT OUTER JOIN TABLE B on ID

A~ID A~NAME B~WEIGHT


100 A 10
102 C 20
103 D 30
104 40
Table A FULL OUTER JOIN TABLE B

A~ID A~NAME B~WEIGHT


100 A 10
101 B
102 C 20
103 D 30
104 40

Projection View: this can be used to get data from table for only required fields from table.

SE11->select View-> view Name starting with Z or Y->Create->Projection View->give Basis table name->
select required fields to be used in view->save, check and activate

DB View: This can be used to get data from different tables. Tables must have at least one common
field. This uses inner join.

Required fields from different tables can be selected to get data for only those fields at runtime.

View field name can be different from table field name

Help View: This can be used to get data from different tables. Tables must have at least one common
field and must be joined with foreign key. This uses outer join.

Help view will be used to create search help to provide F4

Maintenance View: this can be used to create data in different tables by moving data into maintenance
view. Data will be distributed into underlying tables in view.

Search Helps: SHs are to be used to provide F4 help. There are two types of SHs.

 Elementary search help – in F4, one elementary search help generates one tab. Each
elementary search help contains data source, Selection parameters.
 Collective search help -> Collection of elementary search helps
 Append search help – to add elementary search help to standard SH. Go to ->Append
Search help

SH can be assigned in following places.

 Report selection screen


 Screen field
 Data element
Lock Mechanism:

PGM –
5187
User1

3 User2
1 4
2 5

6
Enque Table, Lock
table – SM12 If lock exists, ENQ
FM will return SY-
SUBRC NE 0.
Searching Lock objects:

Go to SE11->select Lock object->click F4->select All selections -> give Base Table VBAK -> check objects
EVVBAKE

Creation of Lock Object:

SE11->Select Lock object

 Give Lock object name starting with EZ or EY. If it is a standard, always starts with E
 Select lock type, Shared lock, exclusive lock and exclusive but not cumulative.
 Exclusive lock
o The locked data can be read or processed by one user only. A request for
another exclusive lock or for a shared lock is rejected.
 Shared lock
o Several users can read the same data at the same time, but as soon as a user
edits the data, a second user can no longer access this data. Requests for
further shared locks are accepted, even if they are issued by different users, but
exclusive locks are rejected.
 Exclusive but not cumulative lock
o Exclusive locks can be requested by the same transaction more than once and
handled successively, but an exclusive but not cumulative lock can only be
requested once by a given transaction. All other lock requests are rejected.
 When lock object is created, below FMs got created.
o DEQUEUE_<lock Obj Name> – lock will be deleted from lock table
o ENQUEUE_<lock Obj Name> – Lock in lock table
 SM12 can be used to see any locks
Types of Tables:

 Transparent table – normal table


 Pooled table
o Pooled tables can be used to store control data (e.g. screen sequences, program
parameters or temporary data). Several pooled tables can be combined to form a table
pool. The table pool corresponds to a physical table on the database in which all the
records of the allocated pooled tables are stored.

o Pool Table 1
Table Pool

Pool Table 2

 Cluster Table
o Cluster Table 1
Table Cluster

Cluster Table 2

DML: Data Manipulation Language.

This helps to create/change/delete/read data from DB table. This can be achieved through below
techniques.

1. Open SQL:
2. Native SQL: Directly we write DB specific command to do operation
EXEC SQL.
Native SQL statement1
Native SQL statement2
ENDEXEC.

Open SQL: SAP uses open SQL to manipulate data.

DB interface will convert SAP open SQL command to DB specific command hence no need to write DB
specific command in the program.

PS AS D
B

Open Int ID Name Phone


er 1000 Test0 123
SQL fa 1001 Test1 456
ce
ce
1002 Test2 789
e
r
Operations on table data:

1. Insert/Create data 2. Modify/Change Data 3. Delete data 4. Read data

Read Data from Table:

SELECT <F1><F2> / *

INTO <WA> / INTO TABLE <itab>

FROM <TABLE>/<VIEW>/<JOIN>

WHERE <COND>

GROUP BY

HAVING BY

ORDER BY

To restrict columns SELECT <F1> <F2>


Order of the fields in SELECT must be same as
Fields in internal table
To get all columns SELECT *
To get Single record, if primary key is mentioned in SELECT SINGLE
WHERE clause use SINGLE. <F1> <F2> / *

Example:
SELECT SINGLE
*
INTO wa_emp
FROM zabap5_emp_attnd
WHERE id = '1003'
AND zmonth = '02'.
IF sy-subrc EQ 0.
ENDIF.
To get a single record, if non primary key is used in SELECT <F1> <F2> / *
WHERE clause, use UP TO 1 ROWS… UP TO 1 ROWS…..

ENDSELECT.
Reading Multiple records directly into a itab SELECT <F1> <F2> / *
INTO TABLE <itab>
Reading Multiple records one by one into a itab SELECT <F1> <F2> / *
Note: this would cause performance Issue since it INTO <WA>
hits DB for each record. Avoid this in the programs. FROM <DB Table>
WHERE <cond>.
APPEND <WA> to <itab>.
ENDSELECT.

Reading a records in packets SELECT <F1> <F2> / *


Note: SY-DBCNT increments after each iteration APPENDING TABLE <itab>
PACKAGE SIZE <n>
FROM <DB Table>
WHERE <cond>.
Statement 1.
Statement 2.
ENDSELECT.
Reading no of records SELECT <F1> <F2> / *
INTO TABLE <itab>
UP TO <n> ROWS
Reading data from other client in the same system. FROM <DB Table>
Use CLIENT SPECIFIED addition CLIENT SPECIFIED
WHERE MANDT = <clnt>
AND <cond>.

BY PASSING BUFFER FROM <DB Table>


BYPASSING BUFFER
WHERE <Cond>
BETWEEN WHERE <F> BETWEEN <val1> AND <val2>
LIKE WHERE <F> LIKE <val%>
This can be used to write pattern search WHERE <F> LIKE <val_>
% - any no of chars
_ - Single character
In any DB query, SY-SUBRC returns and SY-DBCNT
also returns

Selecting records from more than one table:

This can be done using below:

 Views
 JOINS
 FOR ALL ENTRIES

VIEWS:

1. Check if there is any view is available on required tables.


2. Use view in select query like below

SELECT <F1> <F2> / *

INTO TABLE <itab>

FROM <VIEW>
JOINS: This can be used to get data from different tables by linking more than one table in the program
using JOIN.

SELECT a~id
a~name
b~attend
INTO TABLE it_emp
FROM zabap5_emp_mstr AS a INNER JOIN
zabap5_emp_attnd AS b
ON a~id EQ b~id
WHERE a~name LIKE 'Tes%'.

FOR ALL ENTRIES:

1. Bring data from first table into an internal table


2. Use FOR ALL ENTRIES to get data from second internal table for entries in first internal table

IF it_mstr[] IS NOT INITIAL.


SELECT id
attend
INTO TABLE it_attnd
FROM zabap5_emp_attnd
FOR ALL ENTRIES IN it_mstr
WHERE id EQ it_mstr-id.
ENDIF.

3. If internal table is empty, FOR ALL ENTRIES picks all records from table. Hence we should check
whether table contains data or not.

DB Update program:

Single Multiple
INSERT INSERT <DBTAB> FROM INSERT <DBTAB> FROM
<WA>. TABLE <ITAB> ACCEPTING
DUPLICATE KEYS.

Changing lines Column by column


UPDATE <DBTAB> FROM UPDATE <DBTAB>
<WA>. SET [<fname1> = <fval1>]
[<fname2> = <fval2>]
WHERE <Cond>.

UPDATE <DBTAB> FROM


TABLE <ITAB>
Insert or Changing lines MODIFY <DBTAB> FROM MODIFY <DBTAB> FROM
If record exists, this statement <WA>. TABLE <ITAB>
will update the record. If record
does not exist, it will insert a
record.
Deleting lines DELETE <DBTAB> FROM DELETE <DBTAB> FROM
<WA>. TABLE <ITAB>

Commit work: To move changes to DB, program should use COMMIT WORK. There are two types
COMMIT WORK.

1. Implicit Commit: This will be triggered in following cases.


 When program execution moves from one WP to other WP (Dialogue Step), an internal
commit will be triggered.
 When an error message is raised
 Call transaction
 SUBMIT
2. Explicit Commit: Use below statements in the program to trigger explicit commit
i. COMMIT WORK (Asynchronous Update)
ii. COMMIT WORK AND WAIT (Synchronous update)

Rollback work: We should use ROLLBACK WORK to revert changes to DB. All ready committed data
cannot be reverted back. There are two types of ROLL BACK WORK

 Implicit ROLLBACK WORK: This will be triggered in following cases.


o When Dump is happened in the program
o When Abort message is raised
o
 Explicit ROLLBACK WORK: Use below statement in the program to trigger ROLLBACK
o ROLLBACK WORK

DB LUW (DB Logical Unit of WORK): The changes made to DB within WP (till program is moving to other
WP) will be called as DB LUW
Stock movement – 50 PC Plant A – 70PC, Plant B – 50 PC
Stock Qty – TABLE A 70*100 = 7000 USD 50 * 150 = 7500 USD
Stock Values – TABLE B
REDUCE STOCK AND UPDATE 70 – 50 = 20
TABLE A FOR PLANT A PUSH TO TABLE A
REDUCE VALUE AND UPDATE 7000-5000 = 2000 USD
TABLE B FOR PLANT A UPDATE TABLE B
INCREASE TOCK AND UPDATE 50 + 50
TABLE A FOR PLANT B UPDATE TABLE A
INCREASE VALUE AND UPDATE 100 * 150 = 15000 usd
TABLE B FOR PLANT B UPDATE TABLE B

DB LUW

Sap luw

SAP LUW: Bunch of DB LUW will be called SAP LUW. All updates will be done on COMMIT WORK
statement.

 To group db operations in SAP LUW use following. These will be triggered at the time of
COMMIT WORK.
o Using Subroutines
1. Create subroutine….
2. Call subroutine using PERFORM ….. ON COMMIT
o Using Update FM
1. Create Update type FM……
2. Call FM in UPDATE TASK
Memory Structures of an ABAP program:

External session 1 External session 2 External session 3

A A

B B

A A

Internal Session – P Internal Session – P


MM03 XD03
M M
e e
Internal Session – m Internal Session – m
VA03 o VA03 o
r r
y y

SAP Memory

ABAP Memory

To create internal session on top of another internal session use following

1. SUBMIT program
2. CALL TRANSACTION tcode.

To save data to ABAP memory use below statement.

EXPORT <f1> FROM <g1>

<f2> FROM <g2>

TO MEMORY ID ‘MEM KEY’.

To read data from ABAP memory

IMPORT <f1> TO <g1>


<f2> TO <g2>

FROM MEMORY ID ‘MEM KEY’.

To Delete memory

FREE MEMORY ID <MEM KEY>

SAP Memory

To save data to SAP memory use following

SET PARAMETER ID ‘ABC’ FIELD <f1>.

To read data from SAP Memory

GET PARAMETER ID ‘ABC’ FIELD <f1>.

MESSAGES:

Messages are single texts stored in table t100 using Tcode – SE91

Message contains below structure:

1. Language Key
2. Message Class – contains bunch of messages
3. Message Number – is an ID for a text
4. Message text

Note: These texts can be maintained in different languages using translations

Creation of messages: go to SE91->give message class Z o Y -> give message number and texts.

Note: if required, create a long text for each message

Type Meaning Info


I Information This message appears in a dialog
box. After confirmation the
program continues after
message statement
S Status The program continues normally
and the message displays on
status bar.
W Warning Depending on program context
error dialogue appears and
program stops execution further
or upon confirmation program
executes normally
E Error Depending on program context
error dialogue appears and
program stops execution further
X Termination Program goes dump or runtime
error. See in ST22
A Abort The message appears in a dialog
box and the program terminates.
Control returns to the next
highest area menu

Triggering messages in program:

Message using static message class:

1. Message <t><nnn>(<mess class>) WITH <f1> <f2> <f3> <f4>. [Dynamic values][Max 4
values]
2. Message ‘Message Text’ type ‘I’.

Message using global message class

1. Assign message class to report like below

REPORT <Name> MESSAGE-ID <MessClass>.

2. Raise message like below.

Message <t><nnn> WITH <f1> <f2> <f3> <f4>. [Dynamic values][Max 4 values]

Messages with exceptions in FM

1. Raise message with excep using following statement. When this statement is reached control
will go to program immediately without executing further statements in the FM and exception
number will be placed in SY-SUBRC and Message details will be placed in system variables
mentioned in point# 2.

MESSAGE i000(ztest_01) RAISING max_value. (max_value Exception in FM)

2. Trigger message in program using below

MESSAGE ID SY-MSGID

TYPE SY-MSGTY

NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
Interfaces:

Application server:

Upload:

1. Prepare final itab


2. Open file using OPEN DATASET in OUTPUT
3. For each record of itab, Move data to file using TRANSFER
4. Close file using CLOSE DATASET

OPEN DATASET '.\ABC.txt' FOR OUTPUT


IN TEXT MODE
ENCODING UTF-8
MESSAGE w_msg.
IF sy-subrc EQ 0.
LOOP AT it_ord INTO wa_ord.
TRANSFER wa_ord TO '.\ABC.txt'.
ENDLOOP.
CLOSE DATASET '.\ABC.txt'.
ENDIF.

Download:

1. Open file OPEN DATASET in INPUT


2. Move record from file to itab using READ DATASET, in infinite loop
3. When read is failed, come out from infinite loop
4. Close file using CLOSE DATASET

OPEN DATASET '.\ABC.txt' FOR INPUT


IN TEXT MODE
ENCODING UTF-8
MESSAGE w_msg.
IF sy-subrc EQ 0.
DO.
READ DATASET '.\ABC.txt' INTO wa_ord.
IF sy-subrc EQ 0.
APPEND wa_ord TO it_ord.
ELSE.
EXIT.
ENDIF.
ENDDO.
CLOSE DATASET '.\ABC.txt'.
ENDIF.

Delete file from App server:

DELETE DATASET <file>.

Complete syntax of OPEN FILE:

OPEN DATASET <File Name>

FOR [INPUT]/[OUTPUT]/[APPENDING]

IN [BINARY MODE]/[TEXT MODE]

MESSAGE <Msg>.

Mode: BINARY MODE – to transfer byte byte or TEXT MODE – to transfer line by line

Operation: INPUT – to read data/OUTPUT- to transfer data/APPENDING – to add data to exiting file

MESSAGE to get message from operating system

Presentation server

Download: gui_download, ws_download

Upload: gui_upload, ws_upload

Cl_gui_fronend_services
Reports:

Tcode
Selection Basic
screen Int List
LIST
Pgm
PBO
Event
PAI PAI Event
events

PBO List
Event

EVENTS:

Load-of-program

PBO Selection screen Events:

Initialization

At selection-screen on output

PAI Selection screen Events:

At selection-screen on <field>

AT selection-screen on block <blk1>

At selection-screen.

AT SELECTION-SCREEN ON HELP-REQUEST FOR

AT SELECTION-SCREEN ON VALUE-REQUEST FOR

Events on Execute

start-of-selection.

END-OF-SELECTION
PBO of List

TOP-OF-PAGE

END-OF-PAGE

TOP-OF-PAGE DURING LINE SELECTION

PAI LIST Events

AT PF<nn>

AT LINE-SELOECTION

AT USER-COMMAND

Push button

Application tool bar buttons

Check box

Radio button

User command

SSCRFIELDS

Selection screen Design:

Parameters: This can be used to enter a single value

P_<Name> type/like type/object <options>

Options:

Obligatory – to set as a mandatory field

Default – to assign values

Decimals <n> - to set no of decimals

Memory id ‘ABC’ – to SET/GET Parameters


Lower case – to provide lower case entry

Match code object – to assign search help

No-display - will not be displayed on selection screen

Select-option:

SELECT-OPTIONS s_org FOR wa_sel-vkorg <options>. (Object ref)

Select-option is like internal table with header line with below components:

SIGN – I(Inclusive), E(Exclusive)

OPTION – EQ, LT, LE, GT, GE, BT

LOW – Low value

HIGH – High value

Options:

Obligatory

Default

SELECT-OPTIONS s_org FOR wa_sel-vkorg [DEFAULT < from value>

TO <to value>

OPTION <opt>

SIGN <s>].

Decimals <n>

Memory id ‘ABC’

Lower case

Match code object – Search Help

No-display

No-intervals

NO-Extension

Usage of select option:


 In select query --------- WEHRE VKORG IN S_VKORG. If S_VKORG is initial, it will not be
considered in filter criteria.
 In conditions -------- IF s_vkorg[] IS INITIAL.

Ranges:

Range is like a select option but this will not be shown on selection screen

Components:

SIGN - I or E

OPTION – EQ, BT, LE, GE, GT, LT, NE

LOW

HIGH

Filling Ranges:

DATA: r_vbeln TYPE/LIKE range of vbak-vbeln WITH HEADER lINE.

Or

RANGES: r_vbeln for wa_sel-vbeln.

R_vbeln-sign = ‘I’.

R_vbeln-option = ‘BT’.

R_vbeln-low = ‘4969’.

R_vbeln-high = ‘4979’

Append r_vbeln.

Clear r_vbeln.

R_vbeln-sign = ‘E’.

R_vbeln-option = ‘EQ’.

R_vbeln-low = ‘4972’.

Append r_vbeln.
Clear r_vbeln.

I 4969 4979

I 4989 4999

I 5006

E 4975

E 4992 4995

Include 01.01.2014 to 03.01.2014

Include 05.01.2014 to 07.01.2014

Include 07.07.2014

Exclude 06.10.2014 to 06.16.2014

Exclude 05.04.2014

FORMATTING Selection screen

Blank lines - SELECTION-SCREEN SKIP [N].

UNDER LINES - SELECTION-SCREEN ULINE [/ 10(2)]

COMMENTS - SELECTION-SCREEN COMMENTS [/10(2)] <COMM>.

SEVERAL ELEMENTS ON A SINGLE LINE


SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENTS 1(10) TEXT-001.

PARAMETERS: P1, P2,P3.

SELECTION-SCREEN END OF LINE.

Blocks of Elements:

SELECTION-SCREEN BEING OF BLOCK <blk1> WITH FRAME TITLE TEXT-001.

-------

SELECTION-SCREEN END OF BLOCK <blk1>.

Intialization: This event can be used to assign default values to selection screen parameters.

 This can be used when a logic is required to set default value.


 To fill select options.
 This event triggers for only one time

INTIALIZATION.

P_data = sy-datum - 7.

PBO Event:

AT SELECTION-SCREEN OUTPUT.

This event will be triggered every time before selection screen display.

Each selection screen element has properties and these properties are available at run time in the
program in SCREEN table. This event can be used to modify selection screen elements properties
dynamically by changing SCREEN table.

IF s_kunnr-low EQ '0000000123'.
LOOP AT SCREEN.
IF screen-name CP '*VKORG*' OR
screen-name CP '*VTWEG*' OR
screen-name CP '*SPART*'.
* screen-input = 0.
screen-invisible = 1.
screen-active = 0.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDIF.

SCREEN Table contains below properties:

NAME Element Name


GROUP1 To group screen elements. We can apply
properties to entire group.

For selection screen elements, Use MODIF ID


extension to set group name

In screen program, set this in screen painter

GROUP2 Only in screen program

GROUP3 Only in screen program

GROUP4 Only in screen program

REQUIRED Obligatory or Mandatory

INPUT Input option

OUTPUT

INVISIBLE

ACTIVE

User actions on selections screen: (PAI Events)

AT SELECTION-SCREEN ON <FIELD>. This can be used to validate field value.


If error message is raised, only this field is input enable, remaining all fields input disabled.

AT SELECTION-SCREEN ON p_vkorg.
IF p_vkorg IS NOT INITIAL.
SELECT SINGLE
vkorg
INTO wa_vbak-vkorg
FROM tvko
WHERE vkorg EQ p_vkorg.
IF sy-subrc NE 0.
MESSAGE 'Please enter valid org' TYPE 'E'.
ENDIF.
ENDIF.

AT SELECTION-SCREEN ON BLOCK <BLK>.

If error message is raised, only fields in this block are input enable, remaining all fields are input
disabled.

AT SELECTION-SCREEN.

If error message is raised, all fields are input enabled but execution will not go further.

User Actions: - for any action at selection-screen event gets triggered

Pushbuttons:

tables: sscrfields.

PARAMETERS:
p_a TYPE i,
p_b TYPE i,
p_c TYPE i.

SELECTION-SCREEN:
PUSHBUTTON /4(15) w_add USER-COMMAND add,
PUSHBUTTON /4(15) w_sub USER-COMMAND sub,
PUSHBUTTON /4(15) w_clr USER-COMMAND clr.

INITIALIZATION.
w_add = 'Additon'.
w_sub = 'Subtraction'.
w_clr = 'Clear'.

AT SELECTION-SCREEN.
IF sscrfields-ucomm EQ 'ADD'.
p_c = p_a + p_b.
ELSEIF sscrfields-ucomm EQ 'SUB'.
p_c = p_a - p_b.
ELSEIF sscrfields-ucomm EQ 'CLR'.
clear: p_a, p_b, p_c.
ENDIF.

Buttons on Application toolbar:

SSCRFIELDS structure – this is for selection screen fields.

UCOMM User action will be filled at


runtime
FUNCTXT_01 App toolbar button 1 text
User command - FC01
FUNCTXT_02 App toolbar button 2 text
User command - FC02
FUNCTXT_03 App toolbar button 3 text
User command - FC03
FUNCTXT_04 App toolbar button 4 text
User command - FC04
FUNCTXT_05 App toolbar button 5 text
User command - FC05

TABLES: sscrfields.

PARAMETERS:
p_a TYPE i,
p_b TYPE i,
p_c TYPE i.

SELECTION-SCREEN:
FUNCTION KEY 1,
FUNCTION KEY 2,
FUNCTION KEY 3.

INITIALIZATION.
sscrfields-functxt_01 = 'Add'.
sscrfields-functxt_02 = 'Sub'.
sscrfields-functxt_03 = 'Clear'.

AT SELECTION-SCREEN.
IF sscrfields-ucomm EQ 'FC01'.
p_c = p_a + p_b.
ELSEIF sscrfields-ucomm EQ 'FC02'.
p_c = p_a - p_b.
ELSEIF sscrfields-ucomm EQ 'FC03'.
CLEAR: p_a, p_b, p_c.
ENDIF.
User actions for check box:

Check box can be used to provide an option for selection. If check box is selected, value will be ‘X’. If
check box is not selected, value will be space.

PARAMETERS: w_c AS CHECKBOX.

To trigger at selection-screen event for check box, assign user command to check box.

PARAMETERS: w_c AS CHECKBOX USER-COMMAND chk.


if this is selected value is X otherwise it is space

User actions for radio buttons:

Radio button can be used to select one out of a group of radio buttons.

If Radio button is selected, value will be ‘X’. If Radio button is not selected, value will be space.

To trigger at selection-screen event for radio button, assign user command to radio button.

PARAMETERS: p_rad1 RADIOBUTTON GROUP abc USER-COMMAND rad,


p_rad2 RADIOBUTTON GROUP abc.

p_rad1 TYPE c RADIOBUTTON GROUP abc,


p_rad2 TYPE c RADIOBUTTON GROUP abc DEFAULT 'X',
p_rad3 TYPE c RADIOBUTTON GROUP abc,

p_rad4 TYPE c RADIOBUTTON GROUP DEF,


p_rad5 TYPE c RADIOBUTTON GROUP DEF DEFAULT 'X'.

F1 Help

AT SELECTION-SCREEN ON HELP-REQUEST FOR <fname>.

F1 help from ABAP program is the first priority and DE documentation is second priority

F4 Help

AT SELECTION-SCREEN ON VALUE-REQUEST FOR <Fname>

F4IF_INT_TABLE_VALUE_REQUEST can be used to provide values in F4 for selection.

Below is the priority for F4

1. MATCH CODE OBJECT at selection screen element/Search help on screen field


2. AT SELECTION-SCREEN ON VALUE-REQUEST in program
3. SH at table field
4. SH at DE
5. Value table at domain

START-OF-SELECTION:

1. This event gets triggered when user clicks on execute button on selection screen
2. If no events are mentioned in the program, then first executable statement would start this
event.
3. Usually we use this event for Retrieve data, processing data and display data on LIST.
4. All PAI events for validations get triggered before this event.

END-OF-SELECTION:

This event will be called after start-of-selection before list display. This event would be used normally to
display output. In LDBs, this event must be used to process data.

Leaving event blocks:

Usually, one event will be called after completion of one event. To leave event forcibly, use below.

EXIT Before and during selection screen processing, CHECK and EXIT would trigger next
event. AT SELECTION SCREEN ON OUTPUT->AT SELECTION SCREEN ON field-> AT
SELECTION SCREEN ON Block-> AT SELECTION SCREEN ON->START-OF-SELECTION-
>END-OF-SELECTION.

In INITIALIZATION, further statements will not be executed, will go to selection


screen.

If there is no selection screen, if EXIT is in INITIALIZATION, further statements will


not be executed, will go to START-OF-SELECTION

CHECK Same as EXIT

STOP Always triggers END-OF-SELECTION

RETURN Always trigger START-OF-SELECTION

If exit or Check is within loop, control will come out from loop but not from bloc.

If STOP is within loop, control will come out from event and control would go to END-OF-SELECTION.
LIST EVENTS:

Standard page heading: Contains title of the program (SY-TITLE), page no (SY-PAGNO) and underline.

Use below statement to remove standard page heading.

REPORT <REPNAME> NO STANDARD PAGE HEADING LINE-COUNT 22.

To split pages, use LINE-COUNT in REPORT statement as mentioned above.

TOP-OF-PAGE:

This event can be used to write custom page heading. This event gets triggered at first occurrence of
WRITE statement. NEW-PAGE can be used to trigger new page forcibly.

TOP-OF-PAGE.
WRITE: 5 sy-uname, 35 sy-pagno.
ULINE.

END-OF-PAGE:

This event can be used to write footer at end of page. To write end of page lines, reserve no of lines in
REPORT statement with extension LINE-COUNT 22(3). Here 3 uses for end-of-page

END-OF-PAGE.
WRITE: 5 'This is footer'.

Interactive Lists:

This technique can be used to trigger a new list from basic list. To trigger new list we can use following
events.

1. AT LINE-SELECTION
2. AT USER-COMMAND
3. AT PF<nn>

AT LINE-SELECTION

This event can be used to trigger a list on top of another list. This event gets triggered when user double
clicks on a line on the list. Program can generate 1 basic list + 20 Interactive Lists. List index is available
in SY-LSIND.

When user double clicks, PICK command will be triggered and that leads to trigger this event.

SY-LISEL contains the line value on which user double clicked.


AT LINE-SELECTION.
WRITE: sy-lsind,
/ Sy-lisel.

TOP-OF-PAGE DURING LINE SELECTION

This event can be used to write top-of-page for interactive lists.

TOP-OF-PAGE DURING LINE-SELECTION.


WRITE 'Secondary list heading'.

AT USER-COMMAND

This event can be used to trigger another list for user actions like push button, application tool bar
buttons, standard toolbar buttons, menu bar options and when double click has other than PICK user
command.

AT USER-COMMAND.
WRITE: sy-lsind.

IF SY-UCOMM EQ ‘BUT1’.

ELSEIF….

ENDIF.

GUI Status: This can be used to create custom own user Interface. Here we can design menu bar,
standard tool bar and application tool bar. SY-PFKEY contains current GUI status

Creation of GUI status: (SE41 – Menu painter)

System defined user command for double click is PICK and function key is F2

If you do not specify any user command in GUI for F2, program will not trigger any event for F2 (Double
click)

If PICK is assigned to F2, AT LINE-SELECTION will be triggered

If other than PICK is assigned to F2, AT USER-COMMAND gets triggered.

For any custom button, assign function code to button. At runtime, when user clicks on button, this
function code will be set in SY-UCOMM.

Assignment of GUI status to List or Screen:

Before list display, assign GUI status using following statement.

SET PF-STATUS ‘StatName’ EXCLUDING ‘Buttons’ [OF PROGRAM <pgm>].


Title of screen or List – SY-TITLE contains current title

Creation of title bar: go to SE41-> give title bar starting with Z or Y for program-> give title->SAVE and
ACTIVATE.

Assignment of Title bar to List or Screen

Before list display, assign suitable title bar to a list using following statement.

SET TITLEBAR ‘titleName’ [OF PROGRAM <pgm>].

Passing data of current list to interactive list:

1. Using SY-LISEL 2. HIDE Technique 3. READ LINE 4. GET CURSOR

HIDE Technique:

1. HIDE statement must be used after WRITE statement to get correct data
2. Internally, HIDE data will be stored like an internal table with LIST INDEX no, Line No, Fname,
FValue.

Read Line:

READ LINE <Lin> FIELD VALUE <f> INTO <g1>.

READ CURRENT LINE FIELD VALUE <f> INTO <g1>.

GET CURSOR:

GET CURSOR FIELD <F> [OFFSET <o>]

[LINE <l> ]

[VALUE <v>]

[LENGTH <len>].

GET CURSOR LINE <lin> [OFFSET <o>]

[VALUE <v>]

[LENGTH <len>].

Variants: This is to hold data of a selection-screen. Instead of entering data manually again and again,
we can keep this data permanently using variant.

Go to selection screen-> enter data -> SAVE -> Give variant name
If required, we can use dynamic values to set value at runtime. Example: current date to date field on
selection screen. To do this, observe selection variable for selection screen element in Variant.

Observe a variant button will be appeared on application toolbar.

Reports in Background Job execution:

Go to SM36->give Job Name->Step->program and Variant->SAVE->Start Conditions->select options,


select periodic if required->SAVE->SAVE JOB.

Go to SM37 to see job overview.

Transaction code Creation:

Go to SE93-> give t-code starting with Z or Y-> create-> select selection-screen program->give program
name & screen number 1000->SAVE

ALV reporting: ABAP List viewer. BCALV* programs can be used as reference

1. This technique can be used to display one internal table data in well defined format
2. Each field of internal table will be a column of ALV report
3. ALV can be displayed in two different ways – 1. Simple Lists 2. Grid
4. ALV can be developed using two techniques – 1. Function modules 2. Classes

ALV with function modules:

1. Create Internal table that to be displayed in ALV


2. Fill internal table with required data
3. Fill field catalogue to display required fields of internal table as a columns of ALV report
4. Prepare ALV layout if required
5. Call FM REUSE_ALV_LIST_DISPLAY to display ALV List
6. Call FM REUSE_ALV_GRID_DISPLAY to display as ALV grid

Fill Field catalogue:

1. Create manually’
2. Create using FM REUSE_ALV_FIELDCATALOG_MERGE

Example:

User Command in ALV:

1. Put subroutine name in USER_COMMAND export parameter in ALV


2. Write below logic to perform action.
FORM form_command USING p_ucomm LIKE sy-ucomm
pwa_selfld TYPE slis_selfield.
CASE p_ucomm.
WHEN '&IC1'.
SET PARAMETER ID 'AUN' FIELD pwa_selfld-value.
CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
ENDCASE.
ENDFORM. "FORM_COMMAND

Top of page in ALV:

1. Put subroutine name in TOP_OF_PAGE export parameter of ALV FM


2. Write below logic to write top of page

FORM top_of_page.
DATA:
it_lst_hdr TYPE TABLE OF slis_listheader,
wa_lst_hdr TYPE slis_listheader.

MOVE:
'H' TO wa_lst_hdr-typ,
'ABAP technologies' TO wa_lst_hdr-key.
APPEND wa_lst_hdr TO it_lst_hdr.

MOVE:
'A' TO wa_lst_hdr-typ,
'ABAP technologies' TO wa_lst_hdr-key.
APPEND wa_lst_hdr TO it_lst_hdr.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'


EXPORTING
it_list_commentary = it_lst_hdr[]
* I_LOGO =
* I_END_OF_LIST_GRID =
* I_ALV_FORM =
.

ENDFORM. "TOP_OF_PAGE

VARIANTS: to provide variant save option on ALV, use I_SAVE – X, U or A


SCREEN PROGRAMMING or Dialogue Program:

Easy
accesss T-Code
Screen - 9000 Screen Screen
9001 9002
Call screen
from program PBO
Event PAI PAI Event
9000 events for 9001
9000

PBO
Event for
9001
Steps to screen and driver program or module program:

2. Create dialogue program from SE38


a. Type module pool program
b. Declare required variables to display screen
data:
w_a type i,
w_b type i,
w_c type i.
c. First statement of module pool program is starting with PROGRAM ….
d. Save, check & activate and go to display mode
3. Go to screen painter SE51, do following
a. Give program name and screen number starting from 9500 -> create
b. Attributes:
i. Short Description
ii. Next screen – enter same screen number
c. Layout:
i. Go to layout
ii. Drag required variables from program into screen
iii. Double click on each screen element that is created for variable and set
required properties.
iv. If required add text screen element before each I/O field.
d. ELEMENT LIST:
i. All screen elements properties can be seen here
e. Flow Logic: this contains events of the screen. Below are the events.
i. Process Before output
i. This event gets triggered before screen display.
ii. Call a module under this event to trigger before screen display.
1. MODULE default_values.
iii. Double click module->create->select program
iv. PBO module will be created with extension OUTPUT
1. MODULE default_values OUTPUT.
IF w_a IS INITIAL.
w_a = 4.
ENDIF.
IF w_b IS INITIAL.
w_b = 14.
ENDIF.
ENDMODULE.
ii. Process after Input
i. This event gets triggered for any action on the screen. Ex: Enter key, push
buttons, etc…
ii. Call a module under this event to trigger any action like below.
1. MODULE user_action.
iii. Double click on Module -> create -> select Main program
iv. PAI module will be created with extension INPUT like below.
1. MODULE user_action INPUT.
CASE sy-ucomm.
WHEN 'ADD'.
w_c = w_a + w_b.
WHEN 'SUB'.
w_c = w_a - w_b.
WHEN 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. " USER_ACTION INPUT
iii. Process on Help Request – to provide F1 help
iv. Process on value request – to provide F4 help
4. SAVE, CHECK and ACTIVATE program, screen.
5. Transaction code to trigger screen:
a. Screen program cannot be executed directly
b. Go to SE93->give tcode -> create -> select program with screen -> provide program and
screen number -> SAVE.
c. Test T.code
Push Button:

1. Create Push button, provide name, and assign function code.


2. When user clicks on button, function code will be placed in SY-UCOMM and PAI event gets
triggered.

OK CODE:

1. For any screen by default, an element will be assigned i.e. OK Code


2. Assign a name to it in screen elements ex: OK_CODE
3. Declare a variable with name OK_CODE in program
4. After above steps, when user clicks any action button, that buttons function code will be set to
OK_CODE.
5. When user clicks on enter key, nothing will be moved to OK_CODE or SY-UCOMM. So they holds
previous action function code when enter key is pressed. Hence we should clear OK_CODE after
usage but should not clear SY-UCOMM since it is a system variable.
MOVE ok_code TO w_ucomm.
CLEAR ok_code.
CASE w_ucomm.
WHEN 'ADD'.
w_c = w_a + w_b.
WHEN 'SUB'.
w_c = w_a - w_b.
WHEN 'EXIT'.
LEAVE PROGRAM.
ENDCASE.

I/O Fields:

1. Create I/O field->assign technical name and this should be created in program as a variable.
2. When user performs any action, values in screen elements will be moved program variables in
PAI automatically.
3. Before screen display, values in program variables, will be moved to screen elements

BOX: this can be used for virtual grouping of screen elements

Check Box:

1. Create check box, assign name, and create a variable of same name in program of type C and
length 1.
2. If user action is required on click, assign function code. If user clicks on check box, PAI gets
triggered; function will be placed in SY-UCOMM and OK_CODE.
3. When user clicks on check box, variable in program will be filled with ‘X’. If it is uncheck, it is
filled with space.
4. Create a variable in program, save check activate->screen painter, get from program, select
variable and select as a check box->drag and drop by clicking continue.

Radio Buttons:

1. Create required variables in program. These must be of type char and length 1. Each radio
button must have one variable.
2. Go to screen painter, get from program, select required variables and select radio button
option->drag and drop by clicking continue.
3. Select required radio buttons to put under group->right click->radio button group -> Define.
5. If user action is required on click, assign function code. If user clicks on button, PAI gets
triggered; and function code will be placed in SY-UCOMM and OK_CODE.
6. When user clicks on radio button, variable in program will be filled with ‘X’. If it is not selected, it
is filled with space.

Assign GUI status:

1. Create GUI status in SE41->create required buttons->assign function codes and function keys to
buttons->SAVE, CHECK and Activate
2. Go to PBO module/PAI module which triggers before screen display, and assign GUI status as
discussed in reports
3. When user clicks on button, that function will be placed in SY-UCOMM or OK_CODE.

ASSIGN Title bar to screen: Create title bar in menu painter and assign to screen as mentioned in
reports

Validations:

On single field FIELD <f> MODULE <module name> [ON INPUT/ON REQUEST].
If an error message is raised, only this field is input enable remaining all are
input disable.
ON INPUT addition triggers only when user enters other than initial value
ON REQUEST addition triggers when user enters any value including initial
value
On Multiple fields CHAIN.
FIELD: w_a, w_b MODULE validate.
FIELD: w_a1, w_b1 MODULE validate1.
ENDCHAIN.
If an error message is raised, all fields mentioned in CHAIN and ENDCHAIN
are input enable remaining all are input disable.

If there is no CHAIN and ENDCHAIN, last variable after FIELD is input enable
remaining all on screen are input disable.
Unconditional Module calls:

1. Assign function type as ‘E’ to function code.


2. Call MODULE like below to trigger MODULE when type E button is clicked

MODULE <MOD Name> AT EXIT-COMMAND.

3. AT EXIT-COMMAND module must be defined at first statement in PAI

Interaction between screens and programs:

Calling SUBMIT <pgm> ..... AND RETURN. SUBMIT <pgm>.


program From current program, it calls another From current program, it calls another
program (it open internal session on top of program and after completion, control comes
previous internal session) and after back to not caller program but it goes to SAP
completion, control comes back to caller easy access (it kills complete external
program (called internal session will be closed session).
and it will go to previous/caller internal
session).
Calling a CALL TRANSACTION <tcode> LEAVE TO TRANSACTION <tcode>
transaction Current program will call transaction <tcode>, Current program will call transaction
after completion, it comes back to caller. <tcode>, after completion, it will not come
back to caller. But it will go to SAP easy
access (it kills complete external session).
LEAVE LEAVE PROGRAM - always kills complete
PROGRAM transaction (Kills external session)

Calling screen CALL SCREEN <nnn> (Goes to screen <NNN>)

Or

SET SCREEN <nnn>


LEAVE SCREEN
1. Leaves to screen set in above
statement (Set Screen)
2. If no SET SCREEN is mentioned, leave
screen goes to next screen mentioned
in attributes.
3. If no SET SCREEN is specified, if no
next screen defined in screen
attributes, leave screen goes to
previous screen.
Or

LEAVE TO SCREEN <nnn>.


If <nnn> is 0, this goes to previous screen
Calling screen CALL SCREEN <nnn>
in Dialogue STARTING AT <X1> <Y1>
box ENDING AT <X2> <Y2>.

SCREEN -> NEXT SCREEN:

9501 -> 9501 Leave screen -> 9501 Leave to screen 9503

9502 -> space Leave screen -> previous screen

9503 -> 9503 Leave screen -> 9503

Sub Screens

Main Screen Sub screen

Sub Screen Area

1. Create main/normal screen


a. Create sub screen area on main screen
b. Go to layout->select sub screen area-> give sub screen area name
2. Create sub screen
a. Go to SE51-> create screen of type SUBSCREEN
b. OK Code is not required for SUB Screens
3. Call sub screen in sub screen area of normal screen using below steps.
a. Go to PBO logic of normal screen and call sub screen using below
CALL SUBSCREEN sub INCLUDING sy-repid
'9504'.
b. Go to PAI logic of normal screen and call sub screen using below.
CALL SUBSCREEN sub.
4. TYPE E function codes must be handled in PAI of main screen.
5. While sub screen is processing SY-DYNNR contains, sub screen number

Tab Strips Control:

1. Create tabstrip control using wizard on layout


2. Give Tabstrip name->select required scrolling ->enter tab names->assign function code for each
tab and sub screen number that should called when tab is clicked->give program names to
generate code for tab strip->complete
3. Observe screens, flow logic and main program that got generated. And add required fields to
sub screens.
4. CONTROLS: ts TYPE TABSTRIP.

TAB SUB SCREEN NO Sub screen Area Function Code


SAP GUI Scrolling TAB1 9001 SUB1
TAB2 9002 SUB2
TAB3 9003 SUB3
Scrolling at TAB1 9001 SUB FUNC1
application server
TAB2 9002 SUB FUNC2
TAB3 9003 SUB FUNC3

Table Control:

ABAP offers two techniques to show table data on a screen

Table control:

 Create a internal table and work area in the program


 Create a screen->Go to layout, click on table control wizard->drag and drop on screen->provide
table control name->select internal table and work area->select required fields to be displayed
on table control->provide program names that should be used to generate table control logic-
>observe table control on screen
 Go to flow logic, and create method to fill data to be displayed on table control
 Observe program, a table control is declared like below
CONTROLS: tc TYPE TABLEVIEW USING SCREEN 9501.
 Observe below points in flow logic
o In PBO, we should LOOP internal table that should be displayed on table control like
below.
LOOP AT IT_ITEMS
INTO WA_ITEM
WITH CONTROL TC
CURSOR TC-CURRENT_LINE.
MODULE TC_GET_LINES.
ENDLOOP.
o In PAI, we should LOOP internal table like below.
LOOP AT IT_ITEMS.
CHAIN.
FIELD WA_ITEM-POSNR.
FIELD WA_ITEM-MATNR.
FIELD WA_ITEM-FMENG.
endchain.
ENDLOOP.
 TC at run time contains below information
o LINES – total no of records in internal table
o TOP_LINE – contains the index number which is showing in top line of table control
o CURRENT_LINE – contains the index number which processing now. Below is the logic
 SY-STEPL + (TOP_LINE - 1)
 SY-STEPL contains index of table control
 To change properties of cell, use TC-COLS[index]-SCREEN

Step loop – go through documentation and sample programs

Conversions or Loading data into SAP: below are the different types of data we do in SAP

 MASS DATA LOAD: many no of records


 Online load: only one record

Load Techniques:

 BDC – Batch data communication – Mass data load and Online load both are possible
 Direct input method – Mass load
 LSMW – Legacy System Migration Workbench – Mass load
 BAPI – Business Application Programming Interface - Mass data load and Online load both are
possible

BDC – below are the two techniques to do BDC.

 Call transaction
 Session method

Call transaction:
 Go through transaction and successfully run transaction with provided information
 Create a excel sheet with following information for each field and screen
o Program Name
o Screen Number
o New Screen
o Field Name
o Field Value
o Action
 Create an internal table with required fields that are to be passed to transaction
 Create a flat file (Text file) with required data and required columns.
 Read data from flat file to internal table
 Record transaction using SHDB
o Go to SHDB -> New Recording -> give recording name and transaction -> Click start
Recording. Observe recording and SAVE recording
o Go to Recordings List->select recording -> program-> Give program name and select
from recording
o Observe generated program
 INCLUDE bdcrecx1 - contains all subroutines for BDC and selection program.
 PERFORM bdc_dynpro used to fill BDCDATA for new screen. Use this in original
program to fill BDCDATA.
 PERFORM bdc_field used to fill BDCDATA for field and value. Use this in original
program to fill BDCDATA.
 BDCDATA contains below components
 PROGRAM – Program Name
 DYNPRO – Screen Number
 DYNBEGIN – New Screen
 FNAM – Field name
 FVAL – Field Value
 Copy subroutines generated between OPEN_GROUP and CLOSE_GROUP and use this in original
program to fill BDCDATA.
 Go to original program-> for each record of ITAB, fill BDCDATA by using above copied logic.

 After filling BDCDATA, call transaction code using BDCDATA to load data.
CALL TRANSACTION 'XK01' USING it_bdcdata
MODE 'N'
UPDATE 'S'
MESSAGES INTO it_msg.
MODE N – No Screen
E – Errors display
A – All screen display
Update S - Synchronous – during the processing, no transaction data is stored until
the previous transaction has been written DB
A – Asynchronous – During the processing, transaction will not wait for
update the data and it continues for next transaction. Here updation will be
done parallelly.
Message Declare a internal table with BDCMSGCOLL
capturing Capture messages into message internal table, by using extension
MESSAGES INTO it_msg.

Session

This method can be used to process the BDS data separately in a session.

Creation of session.

 For first record of internal table, open a session using FM BDC_OPEN_GROUP


o GROUP – is a session name
o KEEP is to hold session in SM35 after successful processing
o USER is the person who is responsible for processing session
 For each record of internal table, after filling BDCDATA, insert BDC data to session using FM
BDC_INSERT
o One transaction and its screen information and data for that screen must be passed.
o Under one session any number of transactions and screens can be passed using
BDC_INSERT.
 After processing of all records, close the session using FM BDC_CLOSE_GROUP. If session is not
closed using this FM in program, session shows as incomplete in SM35 hence cannot be
processed.
 After above step, observe a session gets created with all transactions and screens in SM35
 Analyze session, process session and analyze log

Practice BDC on table control – for customer contact persons

Important points:

Call transaction Session


Execution 1step – in program, creation of BDCDATA and 1 step – in program, creation of
processing will be in same program BDCDATA will be done and
passed to session.
2nd step - processing will be in
SM35 transaction
Processing Synchronous – records in itab will be Asynchronous – All records will
processed one after other. be passed to session.
Updating Synchronous and Asynchronous Synchronous
Type of data Online data and Mass data Mass data
Capturing Use BDCMSGCOLL to capture message SM35 Log helps to identify errors
messages
Important points Field BDC_CURSOR – Places the cursor on /n – To terminate current batch
field. and mark as incorrect
BDC_OKCODE – Action /bdel – delete current batch
input from session
/bbeg – restart a transaction
/bend – terminate batch input
session and mark as incorrect

LSMW:

1. Check transaction completely and run successfully for one record


2. Prepare flat file with required fields
3. Go to LSMW - > follow below steps
a. Create Project, Subproject and Object -> Execute
b. Maintain Object Attributes
i. Object Type: 1. Direct Input 2. Recording 3. BAPI 4. IDOC
ii. Select Batch input recording -> Click on recording overview -> create new recording ->
after recording, select default all -> SAVE -> back to attributes and provide recording name
and SAVE.
4. Maintain Source Structures – Clcik create and Give source structure name
5. Maintain Source fields: select structure and click on table maintenance -> provide fields and its
technical details
6. Maintain Structure relations -> Check target and source structures are mapped
7. Field Mapping and Rule : go to extras -> auto field mapping -> assign source field to target field
carefully
8. Maintain Fixed Values, Translations, User-Defined Routines: to maintain fixed values or
translations
9. Specify Files: Select PC, click create -> give source file path, observe other options and continue
10. Assign Files: Observe physical file is assigned to source
11. Read file: read data from file to LSMW read file
12. Convert data: for each record of source, it applies field mapping and conversion rules and it
moves to target. Converted data will be placed in converted file
13. Create Batch input
14. Execute session

FORMS

 Scripts: SE71
 SMART FORMS – smartforms
 Adobe forms - SFP

Forms will be used in following cases in business

 External Documents
o Sales: Order Confirmation, Shipping documents, Invoice
o Purchase Order: PO Request, GR , Invoice
 Internal Document
o Picking slip
o Packing slip

First Page -> Second Page(Next Page)

LOGO Company Address Page 1 of 10

Name

Phone

Special Instructions

SlNo Material Qty UoM Value Currency


Final Instructions

Second Page -> will be repeated till completion all items

LOGO Company Address PageNo


Final Instructions

T&C:

SAP SCRIPT – SE71

1. Create deriver program


2. Declare required variable, structures, internal tables to be displayed on form
3. Design form in SE71. Below are elements
a. Start with Z or Y->Create->meaning->create paragraph and Pages->assign default
paragraph and first page in Basic settings. Assign page format. These settings are
applicable for all pages.
b. Create Pages
i. Create required pages
ii. Assign next page to each page
c. Create Windows
i. Identify all required windows in all pages and create windows.
ii. MAIN window is shown by default
iii. Go to edit -> create element
i. Assign name
ii. Window type
1. Constant window – size and data is same in all pages. Editing process of
constant window is high
2. Variable window – Size and values can be different in each page
3. Main window – Width is same but height and data is different in all pages.
This is normally used to display flowed data (Internal table data). There
will be only one main window in form.
d. Assign required windows to each page (Page Windows)
i. Select page -> Go to page windows -> create element->provide window postion
details
ii. Except main window, any window can be added only once to page.
iii. 99 main windows can be added to a page
iv. If required adjust sizes of window in form painter. Go to settings-> form painter
-> select graphical form painter and uncheck PC editor
e. Create Paragraph formats
i. Go to paragraph formats
ii. Give paragraph name, margins, alignment and spacing
iii. Assign required font
iv. If required specify TAB positions
v. To create new paragraph, go to EDIT, create element
f. Character formats
i. If required, create character formats. This will be mainly used to display section
of text in different font in a paragraph.
ii. Can be used to design barcodes

g. LOGO:
i. Go to SE78-> upload logo into SAP like below
1. For testing, Click on BMAP->give logo name -> click import-> give file
name and continue
ii. Go to form -> go to logo window ->go to EDIT text elements -> go to go to ->
change editor-> go to insert -> graphics-> select logo from appropriate place->
observe a command will be generated to insert logo
/: BITMAP 'MYLOGO_4' OBJECT GRAPHICS ID BMAP TYPE BCOL
h. Inserting Text:
i. Create standard text in SO10
1. This can be maintained in different languages
2. This can be used in different forms.
ii. Go to change editor of window->put cursor on appropriate place -> go to Insert-
>text->standard text and continue. Observe below command got inserted
/: INCLUDE ZTEST_TEXT OBJECT TEXT ID ST LANGUAGE SY-
LANGU
iii. Displaying variables of program:
iv. Go to change editor of window -> select required paragraph in
tag column -> enter variable in & var &.

4. Call form from program using below steps


a. Use FM OPEN_FORM to open a spool and form (if there is only one form). This is
mandatory. Options (ITCPO structure) in this FM can be used to pass printer and spool
information.
b. Use FM START_FORM to open another form with in spool –
c. Use FM WRITE_FORM to call window/Element
d. Repeat step c for all windows
e. Use FM END_FORM to stop the form mentioned in point b
f. Use FM CLOSE_FORM to stop spool
5. Script Standard variable:
a. Go to text element->change editor->INSERT->symbols->system and standard
b. &PAGE&, &NEXT-PAGE&, &DATE&, &SY_DATUM& etc…
c. &SAPSCRIPT-FORMPAGES& - no of pages generated between START_FORM and
END_FORM.
d. &SAPSCRIPT-JOBPAGES& - no of pages generated between OPEN_FORM and
CLOSE_FORM. This for one spool.
6. Character formats use
a. Order Number: <B1>&w_ord&</>

7. Control commands:
a. /: IF
Line 1
Line 2
/: ELSEIF
/: ELSEIF
/: ELSE
/: ENDIF
b. /: SET COUNTRY
c. /: NEW-PAGE
d. To display all lines in one page without split, use PROTECT
/: PROTECT
Line1
Line 2
Line 3
/: ENDPROTECT
e. To define a variable in script, use below
/: DEFINE &SUB& = ‘TEST’
8. Drawing a box in a window –
BOX WIDTH '3.5' CM HEIGHT 1 CM FRAME 10 TW INTENSITY 15
BOX XPOS '10.0' CM WIDTH 0 TW HEIGHT '13.5' CM FRAME 10 TW
9. Display internal table data in main window.
a. Create three text elements – HEADER, BODY and FOOTER and write required text under
each element. Ideally HEADER is to put column headings, BODY to display work area of
internal table and FOOTER is to display totals of items.
/E HEADER
* Item Material
/E BODY
* &WA_ITEM-POSNR& &WA_ITEM-MATNR&
/E FOOTER
* This end of items
b. LOOP AT ITAB INTO WA.
For first record call HEADER text element. We can use AT FIRST… ENDAT.
For each record call BODY text element
For last record call FOOTER text element. We can use AT LAST … ENDAT.
10. FM CONTROL_FORM can be used to trigger control command from Program
11. Call subroutine from Script.
a. Create subroutine in the program like below.
FORM <FORM NAME> TABLES IN_TAB STRUCTURE ITCSY
OUT_TAB STRUCTURE ITCSY.

ENDFORM.
b. Call subroutine using below.
/: PERFORM <form Name> IN PROGRAM <’pgm’>
/: USING <&IN_VAR1&>
/: USING <&IN_VAR2&>
/: CHANGING <&OUT_VAR1&>
/: CHANGING <&OUT_VAR2&>
/: ENDPERFORM

Example:
In script:
/: DEFINE W_MATKL = 'TEST'
/: PERFORM GET_MATDESC IN PROGRAM 'ZABAP5_DEMO_SCRIPT_01'
/: USING &WA_ITEM-MATNR&
/: CHANGING &W_MATKL&
/: ENDPERFORM

In driver program:
FORM get_matdesc TABLES in_tab STRUCTURE itcsy
out_tab STRUCTURE itcsy.
DATA: w_matnr TYPE mara-matnr,
w_matkl TYPE mara-matkl.

READ TABLE in_tab WITH KEY name = 'WA_ITEM-MATNR'.


IF sy-subrc EQ 0.
MOVE in_tab-value TO w_matnr.
w_matkl = 'Test_mat'.
Write any ABAP logic to get data to pass to script
MOVE 'W_MATKL' TO out_tab-name.
MOVE w_matkl TO out_tab-value.
MODIFY out_tab TRANSPORTING value WHERE name = 'W_MATKL' .
ENDIF.
ENDFORM.

12. Tab positions: we should define column positions properly to display data in columns in good
format.
a. Define tab positions in paragraph formats.
b. Use ,, for a tab in script like below
IT &WA_ITEM-POSNR&,,&WA_ITEM-MATNR&,,,,&w_matkl&

13. NACE or SPRO configuration: to configure form, program to a output, create program,
subroutine and form. Entire logic to get data and call a form must be written in subroutines.
a. RETURN_CODE and US_SCREEN will declared as USING parameters to a subroutine
b. FM PROTOCOL_UPDATE can be used to log the message for application output
Example:
c. RSNAST00 is the program which will be triggered to call program and subroutine
configured when output is triggered from application.
d. NAST and TNAPR tables
14. To start script debug, activate debug in SE71->Utilities->activate debugger.

SAP Script STYLES:

1. Go to SE72 -> create style with Z or Y


2. Create Paragraph formats and Character formats
3. We can paragraphs and characters of Style in any Script
4. Assign style to script?

Script Style
To copy from one client to other RSTXFCPY RSTXSCPY
client
Down load/upload RSTXFCRP RSTXSCRP
Convert spool to pdf RSTXPDF4
Standard texts to TR RSTXR3TR

Smart forms:

1. Go to SMARTFORMS transaction.
2. Smart form contains below components.
a. Attributes: this contains general and administrative information and page format. This is
applicable to all pages.
b. Form Interface: this contains data that is to be received from program and send data
back to program. This contains Import, export and table parameters
c. Global definitions: This contains data declaration, and program logic to fill data to be
used in the smart form.
i. Global data: create required variables, work areas and internal tables to use in
smart form
ii. TYPES: create required types to create data objects in global data. Otherwise we
should use dictionary objects to create above data objects.
iii. Field symbols: if required, create field symbols
iv. Initialization: This can be used to write program logic to fill data by passing input
and output parameters.
v. Form Routines: to create subroutines within the smart form. These subroutines
can be called from INITIALIZATION.
vi. Currency and Qty fields: this can be used to display these fields as per reference
field value.
d. Pages: create required pages, provide Next page. If required, assign different page
orientation for different pages. Also assign background picture if required.
e. Window: Right click on page->select window. Create required windows for page
i. MAIN window gets create as default.
ii. Select required window type: Main window, Final window, Secondary window.
By default secondary window gets created for other than main window.
iii. Conditions in window can be used to displayed window based on condition.
f. Format windows on page using form painter
g. Display Logo:
i. Right click on window->click create->Graphic
ii. Select graphic file stored in SE78
h. Display variable in text node:
i. Right click on window->click create->text
ii. Select text type text element->Click on + symbol->enter variable in &var&.
i. Template: This can be used to divide window into different cells. We can display data in
each cell. Size is fixed.
i. Right click on window->click create->template.
ii. Create required lines and cell. Width of all cells should not be more than window
size
1. Create a text node for each cell to display data
2. To assign text node to cell, go to output option->output structure, assign
line and cell
j. System variables:
i. Click on field list and observe system fields (SFSY structure).
ii. Page no (&SFSY-PAGE&), form pages (&SFSY-FORMPAGES&) etc…
k. Long texts: This can be displayed using two techniques. 1. Text modules 2. Standard text
i. Text Modules:
1. Smart forms-> provide text module name with Z or Y->create->enter
required text and SAVE. This would create object and it would ask for
package.
2. Create a text node under window-> create text type ‘text module’->
provide text module details
ii. Include text:
1. Create include text in SO10
2. Create a text node under window-> create text type ‘Include text’->
provide include text details
l. Address node: this can be used to display address by providing address number either
through variable or hard code.
m. Table node: this can be used to display internal table data in a main window. Height
varies based on internal table data. Table node = loop + template
i. When table is created three nodes gets generated like below
1. Header: this node will be triggered for first record of internal table. This
can be used to display headings.
2. Main Area: this node will be triggered for each record of internal table.
This can be used to display all records.
3. Footer: this node will be triggered for last record of internal table. This
can be used to display final result like SUM, subtotals etc...
4. Assign internal table and work area to loop in DATA tab. This work area
can be used to display data under this node using text nodes.
5. Define line type(s) to design cells to use in table in table node under
details.
6. Right click on header->create->select table line. For each cell a node gets
generated. We can display ant data under this node.
n. Function module: when smart form is activated, a FM generated. This can be used to
call from any program.
i. Go to environment ->get function module. Call this FM and pass interface
ii. Generated FM is different from system to system; hence we should get FM to a
smart form at run time. To get this use FM SSF_FUNCTION_MODULE_NAME.
iii. DATA:
w_ssf TYPE rs38l_fnam.

CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'


EXPORTING
formname = 'ZABAP5_SF_DEMO_02'
* VARIANT =''
* DIRECT_CALL =''
IMPORTING
fm_name = w_ssf
EXCEPTIONS
no_form =1
no_function_module =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.

CALL FUNCTION w_ssf

o. Program Lines: create program lines node, pass input and output parameters. Write any
logic to change the output parameters.
p. Alternative node to put a conditions in smart form
q. Loop node to process internal table
r. Command node to trigger new page
s. Folder node can be used to put group of nodes under one bucket. If we apply
condition on this node, it is applicable to all nodes in folder.

Difference between script and smart forms

Script Smartform
Client Dependent Client Independent
 Because smart form
generates FM and FM is
client independent.
Program Logic can be added only through can be added in initialization and
PERFORM …. ENDPERFORM at any place in smart form nodes
window using program lines node
Long text can be done only using INCLUDE INCLUDE text and text modules
text
Page orientation fixed for all pages Can be different from page to
page
Paragraph and character formats Can be defined directly in script Only through smart styles.
Different styles can be used in
one smart form

Smart Styles: this can be used to design paragraph and character formats (including Bar codes). These
can be used in any smart form.

Go to smartfroms tcode->select smart style->give style name starting with Z or Y->create->define


required paragraphs and character formats.
Enhancements: This technique can be used to add any extra functionality to existing standard
functionality. Below are the enhancement techniques.

 User exits
 Customer exits
 Field Exits
 BADI
 Enhancement framework.
 Routines
 BTE
 Substitution rules

User Exits:

1. Most of the times, standard program contains subroutines starting with USEREXIT*
2. Access Key is required to change User exit
3. Go to object list of program->search for USEREXIT subroutines
4. When standard program executes, these USEREXIT will be triggered.

Customer exits:

Searching Customer function module Exits:

1. Go to Main program-> global search for CALL CUSTOMER-FUNCTION -> Observe all and identify
suitable one for your requirement.
2. Get Package of the program -> SE84 -> Enhancements-> Customer Exits -> Enhancements -> give
Package and execute -> observe all enhancements and identify suitable one.
3. Observe in SPRO in that particular module area and identify suitable enhancement.

Implementation of Customer Exit: Example: SAPMF02K (XK01)

1. Go to SMOD -> give enhancement name -> click display and observe function module
components under enhancement. Observe a function module with naming
EXIT_<ENHANCEMENT NAME>_<XXX>. This function module will be called from standard
program with statement CALL CUSTOMER-FUNCTION ‘XXX’.

2. Go to CMOD-> Give project name starting with Z or Y -> give Enhancements->SAVE->ACTIVATE


3. Go to required function module and write required logic and check.

Menu exits: This technique can be used to add custom functionality to a transaction by adding custom
menu options (Function codes).

1. Identify suitable enhancement for transaction and check function codes. Ex: MC94, MCP20003
2. Create a project-> assign enhancement->go to components -> double click on function code
(+CU1) -> Give function code details
3. Identify suitable function module exit and write logic to be triggered for function code action.
EXIT_SAPMMCP6_003
CASE i_fcode. "Sy-ucomm."
WHEN '+CU1'.
CALL TRANSACTION 'SE11'.
WHEN '+CU2'.
CALL TRANSACTION 'SE38'.
WHEN '+CU3'.
CALL TRANSACTION 'SE37'.
ENDCASE.

Screen Exits: This can be used to add customer field to a standard screen through custom sub screen.

1. Identify suitable enhancement. Example MM06E005 is for PO SAPMM06E


2. Add a custom field to provided include to add a field to main table. Example: CI_EKKODB
3. Add a field to sub screen provided in Screen exits. Example: by using EKKO_CI structure
Customer sub screen will be called using below statement in main screen
CALL CUSTOMER-SUBSCREEN CUSTSCR1 INCLUDING 'SAPLXM06' '0101'.
4. Identify suitable customer function module exit, to pass data from DB to screen in PBO.
Example: EXIT_SAPMM06E_006
EKKO_CI-ABHI = i_CI_EKKO-ABHI.
5. Identify suitable customer function module exit, to pass data from screen to DB in PAI
Example: EXIT_SAPMM06E_008.
E_CI_EKKO-ABHI = EKKO_CI-ABHI.
6. Create project->assign enhancement->activate

Field Exits: This technique can be used to validate or modify value on entering the data to a field. This
technique is not recommended. CMOD/PRFB or RSMODPRF

BADi (Business Addins):

Searching a BADi:

 Go to SPRO->go to required application area->check for BADi documentation. Example


ME_HOLD_PO for PO
 Get package name of the program -> go to SE84 -> select Business Addins -> select definitions ->
give package name->execute
 Go to SE24->CL_EXITHANDLER->Display->Double Click on GET_INSTANCE method-> put break
point after GET_CLASS_NAME_BY_REFERANCE method. Run transaction and check BADIs
triggered in Debug.
BADI Definition: go to SE18->BADI name->Display->observe Interface methods, Function codes and
Screen

 Multiple: This option can be used to create more implementations. If there are more
implementations, we cannot predict sequence of the call.
 Filter Type:

BADI Implementation: Go to SE19->create implementation->select classic BADi->give BADi name-


>Create Implementation->give impl name starting with Z or Y->go to interface->double click on required
method->write logic for the requirement by using import parameters->Activate method and
implementation

Enhancement frame work

Explicit Enhancements: Direct plug-in in standard program.

ENHANCEMENT-POINT SAPMV45A_03 SPOTS ES_SAPMV45A STATIC.

Click on Enhance(Spiral symbol)->Right click on enhancement->Go to Enhancement Implementation->


create->Click Create->give impl name->continue->select Impl name->Click continue-> observe below
code gets generated -> Activate Enhancement

ENHANCEMENT 1 ZTEST231.
* Insert Logic
ENDENHANCEMENT.

Enhancement spot ->Enhancement point1

Enhancement point22

Enhancement point1 -> Implementation1-> ENHANCEMENT …… ENDENHANCEMENT

Implementation2-> ENHANCEMENT …… ENDENHANCEMENT

Implicit Enhancements: These are provided implicitly before and end of, FM, Subroutines and Methods.
To view this, go to -> Edit-> Enhancement Operations -> Show Implicit Enhancement options-> observe a
line will be displayed at beginning and at ending.
To implement these, right click on line -> Enhancement Implementation->create implementation.

ENHANCEMENT 1 ZTEST23. "inactive version


*
ENDENHANCEMENT.

BAPI: Business Application programming Interface

Business Object – Sales Order – BUS2032

Key – Instance of object for


Unique representation

OBJECT - SALES ORDER

Attributes (Properties) Methods

Sales Org Create

Material Change

Customer Delete

Transaction code - BAPI

RFC – Remote function call

System A -Source System B – Target - WFCLNT320

FM Z_ADD Call FM Z_ADD DESTINATION System A

---System A and System B must be connected


through RFC destination
RFC Destination: SM59->ABAP Connection, provide IP, user ID and password.

Go to destination system-> create a FM type RFC. Pass by reference parameters cannot be created.

Go to source system->create program->call RFC like below

CALL FUNCTION 'Z_ADD_01' DESTINATION 'EH4CLNT800_KL'


EXPORTING
i_a = w_a
i_b = w_b
IMPORTING
e_c = w_c.

ALE&IDOC: Transmission

ALE – Application Link Enabling

DATA can be transferred using below techniques

Stand alone programs - Master Data (Ex: Vendor Master, Customer Master)

Message Control - Transactional Data(Ex: Sales Order, Purchase Order)

Change Pointers - to transfer Changes

IDOC(Intermediate Document)

EDI (Electronic Data Interchange) – SAP to Non SAP system

ALE - SAP to SAP system

WF(Workflow Integration)

IDOC Types: WE30

Basic Idoc

Extended IDOC

Steps to create Basic IDOC:

1. Created data element in SE11


2. Create Segment WE31
3. Create Basic IDOC Type WE30
4. Release IDOC & Segments
5. Create Message Type – WE81
6. Assign Message Type to Basic Idoc Type – WE82

IDOC Runtime Components:

A unique number will be generated with following structure. WE02/WE05 can be used to see runtime
IDOCs

1. Control Record
2. Data Record
3. Status Record

Control Record:

1. Provides Administrative data (Basic Types, Message Type, Who is Partner etc…)
2. This data will be stored in EDIDC

Data Records:

1. Administrative Section (IDOC Number, Segment Name etc…)


2. Data Section – Actual data of Segment
3. This data will be stored in EDDD table

Status Records:

This contains status information of IDOC at different stages.

Sender Side Messages(Outbound process) – 01- 49

01- IDOC Created

30 – Idoc Ready for Dispatch

03 – Idoc is processed

Receiver side message(Inbound Process): 50 – 75

50 – IDOC Added

51 – Application Doc could not be posted

53 – IDOC Posted
ALE Architecture:
RECEi Receiv Receiv
1. Outbound process – process to send data to receiver system ver1 er2 er3
2. Inbound process – Process to collect data and post it to application
3. Exception handling – to process/acknowledge errors

O/B Process flow:


Comm Comm Comm
Start O/B Program IDOC IDOC IDOC
(Stand alone program)

ALE Service Layer


Selection program

Master IDoc will be created and


transferred to next step
ALE Distibution Model

Inbound Process:

1. Read IDOC
2. Post IDOC data to application using a FM that was assigned process code

ALE Configuration: SALE, BALE

Receiver – EEE Sender – EH4


Logical System BD54 T90CLNT090 ECCCLNT800
<Syst>CLNT<CLNT>
Assign Logical System to Client – T90CLNT090 ECCCLNT800
SALE
RFC Destination ECCCLNT800
Distribution Model – BD64 Create Disribution model in Go to change mode->Create
Identify suitable message type – receiver system like below. Model View;
CREMAS(Vendor Master) Select model view->Add
Go to sender system->select Message Type->Give Model view
model view->Edit->model view- Name->Sender and receiver
>Distribute->Select receiver logical systems and Message
system and continue type
Partner Profiles – WE20 Check partner profile with Check partner profile with
Go to BD64->select Dist Model- senders logical system gets receiver’s logical system gets
>Environment->Generate created. If not go to BD64- created.
Partner Profiles >Select distribution model-
>generate partner profiles Message type will be added to
outbound parameters
Message type will be added to
inbound parameters
Process Code WE42->identify suitable process WE41
code and assign to message type
in partner profiles.
Test Create Vendor
Run Stand alone program
BD14 – Vendor Master -
CREAMS
BD12- Customer Master -
DEBMAS
BD10 – Material Master-
MATMAS

Вам также может понравиться