Abap Udemy
Abap Udemy
Abap Udemy
Landscape Architecture :
Development system
Production system.
WORK PROCESSES:
Declaration section.
Processing Blocks.
Creating tables
Local object : &tmp , means this object will be in development system only, when we are
creating table in development. We do not wish to transport it any further.
Guidelines when we are creating fields in our table.
Field name should not start with Z or Y.
Names max of 16 characters.
A field At least has one key field. For searching and sorting of data, and they identify each
record as being a unique record.
You can assign a unique value to field.
You can assign a initial value to our field , But later we can change it.
Data element specifies specific attribute of each field and needs to start with Y or Z.
It’s the field that identifies the client that our records are associated with.the field name is
CLIENT and data element is MANDT.
We need to make client field as key field with in our table.
If we don’t have a data element in our system then we need to create a data element.
While creating a domain we are having domain range concept, Where we can restrict user
to enter specific values only, like single set of values, data ranges and value table.
VALUE TABLE : When we are having more number of values then we can use value table.
value table is validation at domain level. Value table is defined at the domain level and is used
to provide F4 help for all the fields which refer to that domain. Also while defining a check table
SAP proposes the value table as check table by default.
If you are using this concept then you need to use foreign key concept because to ensure the
user entries are tested against the value stored in the value table that you create.
The labels that we give in field labels will be shown in Tables.
Once you create a data fields then you need to give technical settings of the table in order
to save it in back ground data base.
Buffering not allowed : Do not load the table contents into memory for reading and this
prevents the table from being read in advance of us selecting the records in our programs.
If you are having large tables and that ae being updated infrequently then you can use
buffering is allowed.
If you want to enter data into sap then click on Utilities -> table contents -> create entries.
Then enter the data in fields and click on save.
If you want to view our data , then utilities -> Table contents ->display.
PRETTY PRINTER :
Utilities -> settings->ABAP editor -> pretty printer.
TABLE STATEMENT:
TABLES ZEMPLOYEE_LIST_01.
When program is executed. Tables statement will create a table structure in memory bases
on the structure that we defined in the ABAP dictionary of our zemployee list 01 table.
Table structure will contain all the fields that we created. this will allow us to read records
from the table and store them in this temporary structure for our program to use.
So to get these records into our table structure we are gonna use Select statement.
Difference Between Check table and value table :
Check Table : It is nothing but table it contains all valid entries of a particular foreign key table field.
Basically the check table is used for field level validation (it restricts the field value).
(or)
The check table is the table used by system to check whether the data exist or not in foreign key table field.
When ever you are trying to create the table, if you are sure the field contains some values that values only
you can use in another foreign key Data Base Table.
Value Table : The value table is maintained at domain level, it is also called as domain level validation.
(or)
It is a table which contains all valid entries of a domain, this domain can be reused in multiple tables.
The check table will carry out the check for input values for the table field being entered in any
application and value table will provide values on F4 help for that table field.
The check table defines the foreign keys and is part of the table definition.
The value table is part of the domain definition.
check table is validation at field level.
value table is validation at domain level.
Value table is defined at the domain level and is used to provide F4 help for all the fields which
refer to that domain.
Also while defining a check table SAP proposes the value table as check table by default.
Referring to the previous example if you tried to define a check table for the MATNR field SAP
would propose MARA as the check table.
Example : A foreign key links two tables T1 and T2 by assigning fields of table T1 to the primary key
fields of table T2. Table T2 is then known as the check table of the foreign key.
Steps to create :
Go to T-code se11.
Enter table name ZSI_CHECK_TABLE
Click on create
Give short description and give delivery class as ‘A’
Double click on data element, and again double click on domain the below screen will visible.
select value range tab.
provide fixed values and short description as per requirement.
Enter the value table name in domain level, the value table name is nothing but table name, that
means for which table you want to maintain the value table.
Finally activate the domain, data element and table.
Repeat the steps and create the another table called value table.
Foreign key field domain must be same as primary key domain.
After creating the check table create the value table same as for check table and click on field for
which data element in check table gave as a value table.
Then click on foreign key relationship button.
When ever you click on foreign key relationship it automatically proposed a foreign key field with
out giving any table name, that is the magic of creating value table.
Finally click on copy button the values placed which is present in check table comes into the value
table, so it restricts the values from the field.
I hope every one got understand about check table and value table.
DECLARING VARIABLES :
You cannot use special characters in the names, and reserved words.
Declaring variable
DATA packed_decimal03 type p decimal 2 value ’10.5’. It will be able to store 2 decimal places
We can use the constant statement for declaring constants instead of data statement.
Constants myconstant type p decimals 1 value ‘5.5’.
Constants myconstant type i value 6.
You cannot define constants for data types like XSTRINGS.
REFERENCE,
INTERNAL TABLES
STRUCTURES CONTAINING INTERNAL
TABLES.
Result = packed_decimal03 + packed_decima01.(similar -,*,/)
Write / result.
CONVERSION RULES :
Data a1 type p decimals 2 value ‘3.3’ .
Data result type i.
Result = a1.
Write / result.
o/p : 3
if value is 5.55 then o/p will be 6.
CONCATENATION :
Definition : concatenate f1 f2 into d1 [separated by sep]
DATA : title(15) type c value ‘mr’,
Surname(40) type c value ‘smith’,
Forename(40) type c value ‘joe’,
Sep,
Destination(200) type c.
CONCATENATE title surname forename into destintion.
Write destination.
o/p : mrjoesmith
uline.
If you are using n type of strings the o/p will be left aligned.
If you are using c type of strings o/p right aligned.
CONDENSE :
Data AB(20) type c value ‘ my joe hello’.
Condense ab.
Write ab.
o/p “my joe smith.
Condense ab No-gaps.
0/p : myjoesmith.
Length of string :
Data :len type i.
Len = strlen( surname ).
REPLACE :
SA = ‘Mr, joe, Smith’.
While sy-subrc = 0.
Replace ‘,’ with ‘.’ Into sa.
Endwhile.
Write : sa
0/p : mr.joe.smith, if you don’t use a while statement only first , will be replaced.
SHIFT STATEMENT:
Emp1_num = ‘0000654321’.
SHIFT emp1_num LEFT DELETING LEADING ‘0’.
Write emp1_num.
o/p :654321____
here emp1_num is left aligned and remaining 4 characters are blank.
Emp1_num = ‘’0000654321’.
Shift emp1_num.
Write emp1_num.
0/p :000654321_ : by default it will shift one digit and at the end one digit will be empty.
Int_telephone_num = ‘+44-(0)207-123456’.
Write int_telephone_num.
Skip. ( SKIP - To skip the current line and the next output will display from next
line.)
o/p :
--44-(0)207-123456
+44
(0)207-123456
+01
DEBUGGING :
F5 :LINE BY LINE SINGLE LINE AT A STEP.
F6 : ALLOW US TO EXECUTE INDEPENDENT SECTIONS OF CODE.EX:FUNCTION
MODULES OR FORMS.
F7 : RETURN : TO COME BACK FROM FUNCTION MODULE, BACK STEP.
F8 : executes whole program and shows us the entire output. When you click on one line and
when you press f8, it will take you to that particular line you selected, and it should wait at
that line again when you click f8 it will give you output.
When you click on display list , it will give you output screen.
We can click f3 button , to go back to the code and we start executing some more lines and
again click on display list it will again give some more o/p list up to that point.
System variables:
When program or condition executed successfully, the value of system fields like sy-subrc is
0. All system fields will be in table SYST, these will execute when program is running.
These fields are statement dependent.
Table mode :
BREAK POINT :
Break point field will allow you to see individual break points that you have put in our code.
Life time of our break point is till when our debug session is active.
If you want your break point to be there then you need to save (breakpoint -> save).
So that next time when you open your debug session it would be there.
When you want to go to manually set break points , then you need to go to utilities ->break
points -> display.
If you want to stop our program at a particular line while debugging , you can use statement
BREAK-POINT.
WATCHPOINTS :
you can give condition in watch point, like field_name = value, so when you are debugging,
program will pause at that point.
You can also compare fields using break point.
Foreign keys :
Need to see again.
APPEND STRUCTURES:
Instead of adding fields to a table always prefer appending structures because if sap has
released a new version, our added fields will be overwritten by sap added new fields, So
Appending structures will do us a great help here.
when we append structures, our existing table will remain same. which removes any risk of
our changes being overwritten.
For appending, click on append structures.
Here component means Fields.
It is nice to differentiate our newly added components in append structure with already
existing customer fields in our table.
For this, we generally use z in our namespace but for components lets use ZZ.
Then create data element. That will happen when you give same name in type and double
click on it.
Include structures.
Main difference between include structure and append structure is include structures are
reusable objects and can be linked to many other tables. Abap programs, dialog programs and
structures. they are flat structures meaning they don’t have any additional structures
and the fields within include structure have max 16 char length.
When we put cursor on one field, our include structure will be on top of it.
If you want to your include structure will be a part of table key. You have to make sure it
appears at the top of your table because all table fields used as an table key need to be
grouped together at the top of your table.
DELETING FIELDS :
Same like key fields concept, if u want to delete anyway you can use SE14 tcode.
But when you delete a key filed from the table, suppose emp id and employee surname are
two key fields In table. You are having records like emp id :1,1,2,2 and surname a,b,c,d.
If you remove surname field from table then activate it using se14 t-code then system will
keep the first record that encountered of emp id 1 and remove secpd record since it is
duplicate. So the o/p is having only two records 1,2.
Deleting tables :
you can use where used list when deleting your table, because you need to know in which
programs it is effecting and in which programs it is making inactive.
Se11 and click on delete to delete the table.
OPEN SQL STATEMENTS WE WILL USE IN ABAP no matter what the underlaying
data base is:
If you are logged in through client 100 it will filter with the client Id and give you all records
related to client 100. When we use open sql statements he system will do this for us, we don’t
need to include this field in any selection. This is a benefit.
Continue :
It will stop the remaining statements execution and come to the starting of the loop.
CHECK :
Check statement is combination of continue and if.
If condition fails it will continue from the starting of the loop. ifcheck stmt is out of the loop,
it will actually terminate our program.
EXIT :
Exit stmt will allow us to exit the loop immediately.
PARAMETERS :
Parameter field name length is of 8 characters length only. Our variable names converted into
upper case, this is default action.
Parameters : a like zemployees-a default ‘123’ OBLIGATORY .
o/p : a
we cannot use default in data statement. For the data we use the value addition, but for
parameters we use default.
My_g like zemployees2-gender value check.
The program will now check that entry against a valid value list that we have defined in the
abap dictionary.
Now if we enter wrong value as gender like k, it will give error message.
Parameters : my_sname like z-sname DEFAULT ‘BLOG’ Lowercase .
If you enter some lower case letters in selection screen filed and click on execute the values
will not be changed to upper case if we remove lowercase then the values will be changed to
upper case.
CHECK BOX :
My_b1 as checkbox.
/p : my_b1
RADIO BUTTON :
Wa_green radiobutton group g1.
Wa_blue radiobutton group g1.
Wa_yellow radiobutton group g1.
Error message :
If we use an error message outside of the event like at selection screen, this will close our
program .
Message e000(zmes1) with my_ee .
In se91 empno & is two high : o/p emno 123 is too high .
So this with addition to the msg stmt, It will allow you to enter four different parameters.
Initialization .
Com1 = ‘HELLO SAP’ .
HASHED TABLE :
One of the internal table. These are different from standard and sorted tables. In that you do
not access the records of a hash table using an index. You will only use an unique key. these
are preferred internal tables when come to the speed. Suppose if your internal table going to
get too large, a hash table gives you the best performance. No matter how many rows of data
you are having they are really fast.
Internal tables :
(Occurs clause tells sap we are declaring internal table and we are declaring an internal table
with 0 records so occurs means this table is going to be made up of a number of records but
we are going to define zero to begin with)
(Internal table with header line. Here we are crating a table and which can store multiple
records)
DATA : Begin of itab occurs 0,
surname like zemployee-surname,
dob like zemployees-dob,
End of itab .
Now we have created an structure of internal table.
Since we are using this OCCURS clause , we are telling the system we are going to cre ate
an internal table with a header record.
If we use move corresponding fields , so it will search identical field name in another table it
will transfer data.
Good thing is it does not matter if these two different tables have a different structure.
The above is old styled internal table.
A standard table can have multiple identical records. Meaning we have no unique key.
So that means we don’t have to include any unique key in this table type definition.
WORK AREA DECLARATION .
Data wa_itab1 type itab.
Append statement will tell the system that take values from the header record and add them
into the body of the internal table.
Move corresponding zemployees to itab1.
When we use above stmt you have to consider the fields of two tables have same data type
and length.
Data : Begin of itab2.
Include structure itab1.
Include structure zemployees.
Data End of itab2 .
MODIFY STATEMENT :
Data line_cnt type i.
Loop at itab1 .
If itab1-surname = ‘JONES’ .
Itab1-surname = ‘ hi ’ .
Modify itab1.
Endif.
Endloop.
Describe table itab1 LINES line_cnt.
Insert itab1 index line_cnt.
DESCRIBE STATEMENT :
Describe statement can be used to find out information about the content.
This includes the no of records the table holds, the reserve memory space used, and the type
of table.
Insert statement is used to insert records at any position. We choose inside an internal table ,
by specifying the table index number.
If we wanted to insert a record into an internal table, record number 10 for example, we will
specify index 10 . which would then insert our new record between the ninth and tenth
record.
In the above logic, suppose the table is having 10 records . the insert will insert the record
into 10 th record means before the last record of an internal table.
The new record will be inserted between 9th and 10th record.
READ statement :
the loop statement is great for looping through all the records of our table. But there is
another statement used to access records of an internal table.
Read stmt allows you to specifically read individual records from the table.
Suppose if we use header line then the record will be read into the header line of our internal
table.
Read table itab1 index 5.
This means we are reading the fifth record of our internal table into our header record.
The fastest way to access the records of an internal table is the beauty of read table and using
the index specifically is the fastest form.
This type of access is about three times faster than using a hash algorithm.
It can be 14 times faster than using a normal table key.
The problem is we don’t know what the index number of the record is that we want to read.
That’s why we will use always table keys.
The below is the table key type of statement.
Read table itab1 with key employee = 10007.
DELETE TABLE:
The fastest way of achieving this is by using index. But this only applies to standard tables
and sorted tables but not hash tables. Only these type of tables have an index.
Delete itab1 index 5.
Loop at itab1 .
If itab1-surname = ‘JONES’ .
Delete itab1 index sy-index.
Endif.
You shouldn’t use the delete statement without the index addition. If you went outside the
loop you will be given an run time error.
If you are outside the loop using index is mandatory.
Delete itab1 where surname = ‘ hi ‘.
Multiple records will be deleted if it founds the more records with surname hi.
SORT TABLE :
Sort itab01 descending as text by surname forename .
INCLUDES
Simple to design and accept no parameters.
When we want to create a include , go to see38 give include name and select attriutes and in
the type give include program.
Forward navigation is the another method to create a include.
Function modules are global and can be called from any program.
FUNCTION MODULES(SE37) :
Se80 is the object navigator.
Processing type : defines the type of the function module.
Normal function module :
Remote enabled function module : meaning it can get triggered from an external system.
Update module .
IMPORT :
Data we pass into the fm.
Optional fields means we don’t have to fill them when we call this fm from our program.
Pass value : pass value means its going to pass the actual value into the fm.
Export : the fields defined in the export tab are what get sent back to our calling program.
Changing : this just lists the fields that would be changed by the function module.
Tables : we can pass internal tables .
Exceptions : every fm has the ability to send exception information.
Every function module defines its own exceptions.
Without input there will be output with all data zero.
Coding :
Report zmod2 .
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(15) text-001.
PARAMETER mynum type i.
SELECTION- SCREEN END OF LINE.
To call fm : pattern -> call function -> function module name .
Optional fields will be automatically commented out.