ABAP Material
ABAP Material
ABAP Material
Shared memory
Dispatcher
User3
Gateway
DB Interface
WPs
Components:
Presentation layer - SAP GUI (Graphical User Interface) – to connect SAP system
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
Work process: is least component in app server to process any users request.
Screen Processor
ABAP processor
DB Interface
Different WPs:
Main Package
Transport requests:
TR
Development Quality Production
Landscape:
Sandbox
Text elements
Hexa decimal - X
A B C D
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
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).
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.
DATA:
w_d type d,
w_c1 type c.
w_p = ‘3.45’.
w_d = ‘20130303’.
W_c1 = ‘X’.
W_d, “00000000
W_c1. “space
CONSTATNTS:
CONSTANTS:
c_x TYPE c VALUE 'X'.
[TYPE <t>]
[OUTPUT-LENGTH <o>]
[DECIMALS <d>]
DATA:
w_d TYPE d,
w_c(10),
w_c1(5).
w_d = '20151223'.
w_c1 = 'W_D'.
This statement will move value target field by applying user default settings and options.
DATA:
w_d TYPE d,
w_d1 TYPE sy-datum,
w_c(10),
w_c1 LIKE w_c.
w_d = '20151223'.
w_d1 = '20151223'.
MOVE:
w_d TO w_c,
w_d1 TO w_c1.
WRITE:
w_d TO w_c,
w_d1 TO 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.
W_C2(5).
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.
W_C2(5).
Convertibility:
When source and target field properties are different, while move, value will be moved after applying
conversion rule.
W_I TYPE 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.
W_I TYPE I.
W_C = ‘AB’.
DATA:
w_d TYPE d,
w_c(10).
FIELD-SYMBOLS:
<fs> LIKE w_c,
<fs1> TYPE ANY.
w_d = sy-datum.
w_c = 'Test'.
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.
WRITE w_c.
WRITE w_c.
WRITE w_c.
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.
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.
String Operations:
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.
Ex: Employee
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.
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.
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.
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.
FIELD-SYMBOLS:
<fs> TYPE any.
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>.
Using this technique, at run time, based on values, some set of statements can be executed.
IF condition:
Write ‘Failed’.
ELSE.
ENDIF.
There could be many ELSEIF but there should be only one ELSE.
Positive Negative
W_MARKS > 35 NOT ( W_MARKS > 35 )
T F
F T
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
Logical operators
= or EQ
< or LT
> or GT
<= or LE
>= or GE
<> or NE
( ( 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
NA
NS
NP
CASE Statement:
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:
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'.
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.
WRITE 'Tony'.
IF sy-index EQ 10.
EXIT.
ENDIF.
ENDDO.
Infinite loop should be end with EXIT statement other infinite loop never end.
DATA:
w_count TYPE i.
WHILE w_count LE 5.
w_count = w_count + 1.
WRITE 'Tony'.
ENDWHILE.
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.
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
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
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
Reading a record can be improved using SORT + READ USING BINARY SEARCH operations
Sorted
Hashed
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
FIELD-SYMBOLS:
<fs> LIKE wa_std.
LOOP AT it_std ASSIGNING <fs>.
<fs>-name = 'ABC'.
WRITE:/ <fs>-id.
ENDLOOP.
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:
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:
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.
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.
w_a = 123.
w_b = 134.
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.
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
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.
DML – Data Manipulation Language – SAP uses Open SQL or Native SQL
DCL – Data Control Language – SAP uses SAP Security (Roles), LOCK Mechanism
Employee:
SQL:
PS AS DB
HYD – TPTY = 10
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.
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.
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
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:
Table data:
Analyzed by Memory ID
A A001
A A003
A A005
B A002
B A004
* 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
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
.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.
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
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.
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)
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:
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.
Ex:
IN
US
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
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.
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.
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
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
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:
Pool Table 2
Cluster Table
o Cluster Table 1
Table Cluster
Cluster Table 2
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.
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
SELECT <F1><F2> / *
FROM <TABLE>/<VIEW>/<JOIN>
WHERE <COND>
GROUP BY
HAVING BY
ORDER BY
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.
Views
JOINS
FOR ALL ENTRIES
VIEWS:
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%'.
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.
Commit work: To move changes to DB, program should use COMMIT WORK. There are two types
COMMIT WORK.
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
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:
A A
B B
A A
SAP Memory
ABAP Memory
1. SUBMIT program
2. CALL TRANSACTION tcode.
To Delete memory
SAP Memory
MESSAGES:
Messages are single texts stored in table t100 using Tcode – SE91
1. Language Key
2. Message Class – contains bunch of messages
3. Message Number – is an ID for a text
4. Message text
Creation of messages: go to SE91->give message class Z o Y -> give message number and texts.
1. Message <t><nnn>(<mess class>) WITH <f1> <f2> <f3> <f4>. [Dynamic values][Max 4
values]
2. Message ‘Message Text’ type ‘I’.
Message <t><nnn> WITH <f1> <f2> <f3> <f4>. [Dynamic values][Max 4 values]
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 ID SY-MSGID
TYPE SY-MSGTY
NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
Interfaces:
Application server:
Upload:
Download:
FOR [INPUT]/[OUTPUT]/[APPENDING]
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
Presentation server
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
Initialization
At selection-screen on output
At selection-screen on <field>
At selection-screen.
Events on Execute
start-of-selection.
END-OF-SELECTION
PBO of List
TOP-OF-PAGE
END-OF-PAGE
AT PF<nn>
AT LINE-SELOECTION
AT USER-COMMAND
Push button
Check box
Radio button
User command
SSCRFIELDS
Options:
Select-option:
Select-option is like internal table with header line with below components:
Options:
Obligatory
Default
TO <to value>
OPTION <opt>
SIGN <s>].
Decimals <n>
Memory id ‘ABC’
Lower case
No-display
No-intervals
NO-Extension
Ranges:
Range is like a select option but this will not be shown on selection screen
Components:
SIGN - I or E
LOW
HIGH
Filling Ranges:
Or
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 07.07.2014
Exclude 05.04.2014
Blocks of Elements:
-------
Intialization: This event can be used to assign default values to selection screen parameters.
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.
OUTPUT
INVISIBLE
ACTIVE
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.
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.
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.
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.
To trigger at selection-screen event for check box, assign user command to check box.
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.
F1 Help
F1 help from ABAP program is the first priority and DE documentation is second priority
F4 Help
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.
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.
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.
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.
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
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)
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.
Creation of title bar: go to SE41-> give title bar starting with Z or Y for program-> give title->SAVE and
ACTIVATE.
Before list display, assign suitable title bar to a list using following statement.
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:
GET CURSOR:
[LINE <l> ]
[VALUE <v>]
[LENGTH <len>].
[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.
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
1. Create manually’
2. Create using FM REUSE_ALV_FIELDCATALOG_MERGE
Example:
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.
ENDFORM. "TOP_OF_PAGE
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:
OK CODE:
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
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.
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:
Or
9501 -> 9501 Leave screen -> 9501 Leave to screen 9503
Sub Screens
Table Control:
Table control:
Conversions or Loading data into SAP: below are the different types of data we do in SAP
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
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.
Important points:
LSMW:
FORMS
Scripts: SE71
SMART FORMS – smartforms
Adobe forms - SFP
External Documents
o Sales: Order Confirmation, Shipping documents, Invoice
o Purchase Order: PO Request, GR , Invoice
Internal Document
o Picking slip
o Packing slip
Name
Phone
Special Instructions
T&C:
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 &.
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.
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.
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.
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.
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.
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:
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.
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’.
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.
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
Searching a BADi:
Multiple: This option can be used to create more implementations. If there are more
implementations, we cannot predict sequence of the call.
Filter Type:
ENHANCEMENT 1 ZTEST231.
* Insert Logic
ENDENHANCEMENT.
Enhancement point22
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.
Material Change
Customer Delete
Go to destination system-> create a FM type RFC. Pass by reference parameters cannot be created.
ALE&IDOC: Transmission
Stand alone programs - Master Data (Ex: Vendor Master, Customer Master)
IDOC(Intermediate Document)
WF(Workflow Integration)
Basic Idoc
Extended IDOC
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:
Status Records:
03 – Idoc is processed
50 – IDOC Added
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
Inbound Process:
1. Read IDOC
2. Post IDOC data to application using a FM that was assigned process code