Top Banner

of 72

ABAP Sample Document

Oct 12, 2015

Download

Documents

Omkar Desai

SAP ABAP Sample document containing some basic elements of SAP ABAP programming.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript

Abap Class Notes

Abap Class Notes

ABAP CLASS NOTES.Topics Covered In The Document:

1.DataDictionary.

2.InternalTables.

3.Modularization Techniques.

4.Reports

5.MPP

6.OOPS

7.BDC

8.SapScripts

9.SmartForms.

10.Enhancements.

11.CrossApplications.

12.RFC.

13.BAPI.

14.GeneralTopics.

ABAP- Advance Business Application Programing. Coding language for SAP. ABAP is a Space sensitive not case sensitive.

Every ABAP statement must be terminated with a period (.).

Messages in ABAP must be enclosed with in single quotations.

Write statement is output statement in ABAP. Write is the statement to print messages or values in LPS (List processing screen).

Syntax:-

Write message/.

Ex:-

Write Welcome.

O/P:-

Welcome.

How to create a program.

Go to SE38.

Give report name

Name should start with Z or Y.

Report [ ztest ].

Click on create button.

It will show a popup. Fill the entries in that popup.

Title [report program for test purpose]

[Executable program].

Click on save.

It will give a standard line.

Report Ztest.

After this line we can write the code.

No Standard page heading is the syntax to remove the standard heading of report.

Syntax:- Report No standard page heading.

Ex:- Report ztest .

Write Welcome.

O/P:- Report program for test purpose.

Welcome.

EX:- Report Ztest no standard page heading.

Write Welcome.

O/P:-Welcome.

Line-Size is the option to control LPS line width.

.Maximum line-size can be applied as 1023.

.minimum line size can be applied as 1.

.negative numbers cannot be used as line-size.

Syntax:-

Report Line-Size [n].

Ex:- Report ztest line-size 3.

Write welcome.

O/P:-

Wel

: indicates if it has more than one line. : is the key word use instead of multiple statements like write, data, tables, constants.But the statement should be separated by , (comma).

Syntax:- write: message/, message/, message/.

Data: type , type .

EX:- Write: Welcome, India, or, UK.

O/P:- Welcome India or UK.

/ is the key word to print the messages or variable in next line.

Syntax:- Write /message/.

Ex:- write welcome.

Write India.

O/P:- welcome India.

Ex:- write: welcome,

/India.

O/P:- welcome

India.

Position is the number by which you can control the LPS form where you need to start printing the message or variable. Position is always from beginning of the line.Syntax:- write 5message/.

In LPS it will leave 5 places and start printing the message or variable.

Ex:- write 5welcome.

O/P:- -----Welcome.

Width is the number by which you can control the message or variable how many characters you need to print. Controlling width of a variable or messages.Syntax:-

Write (width) message/.

Ex:- Write (5) Welcome.

O/P:-

Welco.

/Pos(width) option must be used togetherSyntax:- write[/][pos][(width)] message/.

Ex:- write: welcome,

/7(10) india.

O/P:- welcome

------india.

In ABAP * and are called comment characters.

By using * the entire line became a comment. The line wont execute at the time of execution.

Double quotes () we can use to comment the line between line. Keep the double quotes form where you want to comment and place period before your double quotes.Ex:-

Write: welcome,

/ india,

/ always.

O/P:-

Welcome

India

Always.

EX:- Write: welcome,

* / india,

/ always.

O/P:-

Welcome

Always.

EX:- Write: welcome. / india, / always.

O/P:- welcome.

Ctrl + :- sets selected block as un comment.

Customized objects in sap must starts with Z or Y.

To print blank lines in SAP.Syntax:- set blank lines .

Is the statement in abap controls the blank lines can be printed or not in LPS. By default this statement is off.

EX:-

Set blank lines on.

Write welcome.

Write / .

Write / .

Write /india.

O/P:-

Welcome

India.

SKIP:- Skip is the statement to generate multiples blank lines.

Syntax:- skip [n].

Where n is number of lines to skip.

EX:-

Write welcome.

Skip 2.

Write india.

O/P:-

Welcome

India.

COLOR:- color is the option to applies color for the text. For text background we use inverse option.

Syntax:-

Write: message/ color [id] [inverse].

Here id are from 1 to 7.

Ex:- write welcome color 5.

Ex:- write welcome color 5 inverse.

Sy-uline:- is the option to print horizontal line in lps.

Syntax:- write sy-uline.

Ex:-

Write: welcome,

/ sy-uline.

O/P:-

Welcome

Sy-vline:- is the option to print horizontal line in LPS.Syntax:-

Write sy-vline.

Ex:-

Write: welcome, sy-vline, india.

O/P:-

Welcome | india.

No-Gap:- No-Gap is the option to avoid single character gap between multiple messages.Syntax:- wite message/ no-gap message/.

Ex:- Write: welcome no-gap, india.

O/P:-

Welcomeindia.

No-Sign:- Is the option in ABAP used for numeric variables to avoid sign symbol in LPS output.

Syntax:-

Write no-sign.

Ex:-

Data a type i.

A = -1.

Write a.

O/P:-

1-.

Ex:- write a no-sign.

O/P:-

1.

Con trolling alignment modes in write statement.

Syntax:-

Write: message/ [alignment-mode].

Where alignment-mode is left-justified, right-justified, centered.

Ex:-

Write 10(25) welcome color 5 centered.

O/P:-

Welcome.

Sy-datum:- system variable to print date.

Ex:- write sy-datum.

O/P:-

10/26/2013.

Sy-uzeit:- system variable to print time.

Ex:- write sy-uzeit.

O/P:-

5.13.

HOT SPOT ON:- is used to add single click event functionality of the data in LPS.

Syn:-write message/ hotspoton.

Ex:- write welcome hotspoton.

HOW TO CREATE PACKAGE.

Go to se21 or se80.

Give package name [zotc].

Click on create.

Provide short description.

A popup message will displayed for TR.

Click on create TR request. Provide short description.

Press enter.

1.Data Dictionary.

->Table: Table is a collection of Rows and Columns means fields and records.

NOTE:-We will create all the required Domains and Data Elements first so that we can simply provide the same while creating the Table.

We can create Data Element in Two ways

i. Create the Domain-> Data element (Bottom Top).

ii. Start with Data element creation then Domain from there.(Top Bottom).

Creating domain (Bottom Up Approach).

Go to SE11. Select the radio button Domain.Domain [zempno].

Click on create. Enter the short description [employee number]. Click on Definition tab and provide Data type and No of characters.Data type [CHAR].

No characters [5].

Save check and activate. Creating Data element (Bottom up approach). Got SE11. Select the radio button Data Type.Data type [zempno].

Click on create. A pop up window will open with 3 radio buttons.Select radio button Data element.

Click on continue. Give short description [data element for employee number]. Click on Definition tab and provide the Domain.Domain [Zempno].

Click on Field label tab and provide the description of the field.Medium 10 empnum.

Long 15 empnumber.

NOTE:- This label will be displayed when we refer the same while designing the screen in MPP[Module pool programing]. Save check and activate.

Repeat the same procedure to create all the Domains and attach Domain to the corresponding Data Element while creating the Data Elements.-> Creating a simple customizing table.

-> Go to SE11.-> select Radio button Data base table.

Data base table [zemp_info].

Click on create button.

Give short description [Table for employee information].

Click on Delivery and maintenance tab.

Fill the details.

Delivery class [A].

Table view maintenance [maintenance allowed].

Click on Fields tab.

Give the field name and corresponding data element which we created already.

Empno zempno.Press the enter after the data element so that we get all the information attached to it.

Check the key field and intial key .

Give the second field name and we create the other Data element and Domains by top- down approach.

Empname zempname.

Here the Zempname is not yet created .To creates it double click on the field type (zempname).

It will show a popup message which is asking to save the existing table click on yes.

It will show another popup message asking to create Data element click on yes.

Provide short description [employee name].

Provide the domain name

Domain [zempname].

Double click on the domain to create it. It will show a popup message which is asking to save the existing data element click on yes.

It will show another popup message asking to create Domain click on yes. Provide short description [employee name].

Provide Data type and No characteristics.

Data type [char].

No characteristics [30].

Save, check and activate.

Provide all the fields in the same manner.

Click on Technical settings on the toolbar.

Enter Data class and size category.

Data class [APPL0].

Size category [0].

Save, Back.

Goto Extras -> Enhancement category.

A pop up screen will appear choose the radio button can be enhanced.

Check and activate.

How to create entries.

Go to SE11. Give the table name and display. Go to utilities -> table contents -> new entries. Provide the entries and click on save. Click on reset and give the next entries repeat the same for all the entries. OR

Go to SE16. Give the table name. Click on create entries button in the tool bar. Give the entries and click on save. Click on reset the give the remaining entries repeat the same procedure for entering all the records.How to Display entries.

Go to SE11. Give the table name and display. Go to utilities -> table contents -> display. Execute. We can see all the entries. OR

Go to SE16. Give the table name. Click on execute button. It will show all the entries.Delivery and Maintenance:-

Delivery class:-

It defines which type of table it is and which type of data stored in it.

A Application table (Master and Transaction data).

C Customizing table maintains only by cust, not SAP import.

L Table for storing temporary data, delivered empty.

G Customizing table, protected against SAP upload, only INSTALL (SAP may insert new data records but may not overwrite or delete existing ones).

E Control table, SAP and customer have separate key areas.

S System table, maintenance only by SAP, change = modification. (Data changes have the status of program changes).

W System table, contents transportable via separate TR objects.

Table view maintenance:-

Table view maintenance has three options.1. Maintenance allowed:- SAP will create tow screens one for to insert records and another to display records.

2. Maintenance allowed with restriction:-SAP will create only one screen that is to display data or records.

3. Maintenance not allowed:- SAP doesnt create any screens .

FIELDS:- Fields are the names.

To create a field Data element and Domain required.

Data Element:- Description of the field along with data type and number of characters.

Domain:- Domain defines which type of data and how much size need for a field.

Note:-1. We can reuse Domain in several Data elements.

2. We can reuse Data element in several fields.

3. We can reuse the fields in several tables.

Primary key:-

Primary key defines mainly 3 steps.

1. Unique (Duplicates are not allowed).

2. Not null (Null values are not allowed).

3. Relationship property.

Currency / Quantity fields:- For currency and quantity fields (CURR, QUTY) we need to mention the reference table and reference field in the currency / quantity fields tab.

Technical settings:- Technical settings defines in which place of Data base it has to store and how much space it has to occupy.

Data Class:- Defines where it needs to place in Data base.

APPL0:- master data, transparent tables.

APPL1:- Transaction data, transparent tables.

APPL2:- Organization and customizing.

DDIM:- Dimension table in BW.

DFACT:- Facts table in BW.

DODS:- ODS table in BW.

Size category:- How much space needs to be leave in Database in ranges from 0 8.

0 0 to 330,1 330 to 1,330,

8 690,000 to 1,300,000.

Buffering:- The tables which is stored in Application server is called Buffering.

There are 3 types of Buffering.

1. Buffering.

2. Buffering switch off.

3. Buffering not allowed.

In Buffering allowed there are 3 types they are.

1. Single record buffering.

2. Generic buffering.

3. Fully buffering.

1. Single record buffering:- Only the records of a table which are actually accessed are loaded into the buffer.

For large tables where there are frequent single record accesses.

2. Generic buffering:- All the records in the buffer whose generic key fields match this record are loaded when one record of the table accessed.

3. Fully buffering:- The entire table will store in application server.

NOTE:- Without Data element and Domain also we can create fields by clicking Predefine types.

Domain:- Domain defines which type of data and how much size need for a field.

Data type [ char ].

No char [ 10 ].

Decimal places:- we can fill if you are giving packed data type.

Output length:- It automatically fills by system.

Conversion Routine:- Conversion takes place when converting the contents of a screen field from display format to sap internal format and vice versa.

A conversion routine is identified by its five place name and is stored as a group of two function modules (FM).Conversion_Exit_XXXXX_input:- it is the function module or conversion routine which is used to convert external format to internal format.Conversion_Exit_XXXXX_output:- it is the function module or conversion routine which is used to convert a value from internal to external format.Sign:- If you flag then you can enter negative values DEC, FLTP, QUAN & CURR.

Lower case:- If you flag then it will distinguish small & capital letters which you entered otherwise it will convert all the letter to upper case.Value Range:- you can enter fixed values with description or you can also give range of values in this. We can define a list of fixed values for a domain. So that it will accept only those values. Any other values stored as error

The use of fixed values is for validation

Validation for a field can be done through foreing key relation or fixed values in the domain.

You can also provide value table in this tab.

Value table:- Value table is maintained at domain level . So, that all table fields referring to domain will be validate against a single table.

Whenever we maintain check table or master data name of domain level the system will propose a foreign key relation automatically by making the value table as a check table.

Creating Value table:-

Go to SE11.

Give the data base table name [ ].

Click on change

Select the field and respective data element and double click on the data element and double click on domain and go to value range table and provide value table.

Back, back. Keep the cursor on the field and select the foreign key. It will show a popup message and click on yes.

The value table is connected as a check table

Copy proposal

If click on No, no proposal will be generated. So always click yes.

Save and activate.

Foreign keys:- It is used to define relationship between tables in the ABAP Dictionary. Create value checks for input fields and link several tables in a view or lock object.

Field Assignment in the foreign key:- A foreign key links two tables T1 and T2 by assigning fields of T1 to the primary key fields of table T2.

Table T1 is called foreign key table (dependent table). And table T2 is the check table (reference table).

The pair of fields for the two tables must have same data type and length.

Input valid because the entered value exist in the check table.

Technical Requirements to create a Foreign key:-1. The Domain names of the field in the foreign key table and for the field in the check table should be same.

2. The field in the check table should be primary key.

Creating a Check table:-

Go to SE11.

Select data base table [ ].

Select change.

Select the field for which we need to create check table. Click on foreign key.

Give the details.

Provide the check table name, short text and click on Generate Proposal button.

The system Generates a proposal with the foreign key and the entire primary key field from check table whose domain name are same with the foreign key Domain.

Check table [ T005 ].

T005 mandt kna1 mandt

T005 land1 kna1 land1.

Select radio button non key-fields / candidates.

Give the cardinality as C: CN.

Press enter or copy button foreign key relation is established between two tables. Save activate.

Difference between check table and value table:-

Check table

value table.

It defines at field level it defines at domain level by giving

By using foreign key fixed values.

Table maintenance generator:- it is used to maintain the bulk amount of data. Maintenance means creation, deletion, modification of the records. It is also used for validating the table records by using the events. Go to SE11 or SM30.

Select data base table [ ].

Click on change.

Click on utilities -> table maintenance generator.

Provide the details

Authorization group [ &NC&].

Function group [same table name you can give].

Maintenance table Select the radio button one step.

Maintenance screen no.

Click on propose screen number it will create automatically by sap.

Save.

Back.

Activate the table.

Validations with TMG:-

By using the events available in TMG we can write the validation

Totally there are around 35 to 45 events are available

To check the events fallow the below steps

Go to SE11.

Give the table name zxxx and click on change

Click on utilities-> TMG

Click on environment-> modification-> events

Click on the button new entries

In the first column of the table click on search help button

All the events will be displayed

Event name

text

01 before saving the data in database

02 after saving the data in database

03 before deleting the data displayed

04 after deleting the datat displayed

05 creating new entry

.

Business requirement:-

Raise an error message when ever the customer number is entered and customer name is blank

Steps:-

go to utilities-> table maintenance generator

click on environment-> modification -> events

click on the new entries

create the element 05 i.e, create a new entry

give the form routine name as create_new_rec press enter

click on the code to display the abap editor and write the below code

form create_new_rec.

if zcust-table-name1 = .

Messae please enter customer name type E.

Endif.

Endform.

Save and activate Click on back and click on save

Click on back and click on save

Click on back

A message will be displayed as function group cant be processed

Now go to SE80 and active the function group

Now test the table by entering customer number and leaving customer name as blank.

Properties of TMG:-

Authorization group:-

It specifies the group of users who have the access to maintain the table data

Authorization group is given by basis consultant

Function group:-

It is a container of function modules which are generated by SAP when creating TMG

These function modules will contain the ABAP code for TMG.Maintenance type:-

It specifies whether one screen / two screens to be displayed for maintaining the data.

One step:-

If this option is selected only one single screen is displayed for maintaining the table data.

Two step:-

If this option is selected only two screens are displayed for maintaining the table data.

Recording routine:-

It is a routine which is used to read the table changes

If standard record routine is selected, all the changes are recorded by standard routine.

If no record routine is selected no changes are recorded.

If user recording routine is available then those changes are recorded by user routine

Creation of TCODE to TABLE or TMG:- Go to SE93.

Enter transaction code [ZXXXXx].

Click on create.

Give description [ ].

Select last radio button.

Transaction with parameters (parameter transaction).

Enter values.

Transaction [SM30].

Click all the check boxes in the GUI Support.

Provide the details below.

Name of Screen fields value.

VIEWNAM

ztable name.

Update

X.

Save.

Structure:- structure is nothing but collection of fields.Creating structure.-

Go to SE11.

Select data type [zstr].

Click on create.

Pop up will show in that select the radio button structure.

Give the description [ ].

Click on components tab.

Create fields.

Field name dataelement.

Save and activate.

Adding fields to a table:-

By using Append or Include statement we can add fields to table.

.APPEND

.INCLUDE

1. By using append structure

By using Include structure we can add the

We can add the fields at the

fields where ever we need in the middle

Last of the table.

Also.

2. Append structure is not reusable

Include structure is reusable across the

Table and in the table also.

3. Naming convention of the fields

No restriction.

Should start with ZZ.Adding fields to a table by using .Append:- Go to SE11.

Select Data base table [zXXXx].

Click on change.

Click on Append Structure push button.

Click on create append.

Give the append name [zXXXXXx].

Continue Give short description [ ].

Click on components tab.

Give the field details which need to append.

Save activate.

Back.

Save and activate.

Adding fields to table by using .Include:-

Go to SE11.

Select data base table [zxxxx].

Click on change.

Place the cursor where you need to insert fields press plus symbol.

It will show a blank line.

In that line write.

.include zxxx.

Give the structure name which we already created. Save and activate.

Indexes:- There are two types of indexes are there. these are used to read the data from database table with less spoon of time.

1. Primary index

2. Secondary index.

The primary index is created by sap with all key fields when we create table itself.

The secondary index created by user to their own requirements.

Note:- Maximum we can create 9 indexes.

A per the best programming technique every select statement must contain all the key fields in the where condition.

If non key fields are used in the where condition then it will take long time for execution.

So to improve the performance of the above statement creates an index on the above non-key field called as secondary index.

Creating secondary index:-

Go to SE11.

Select data base table [zxxxx].

Click on change.

Click on indexes push button.

Click on create index.

Give index name [xxx] only three letters and short description.

Select radio button index on all database systems.

Give the field name for which you need to create index.

Mandt

Vbeln

Erdat

Save and activate.

NOTE:-After saving and activating the index it wont available in database. To do that we need to adjust the database by using SE14 tcode.Adjusting the database tables:-

Go to SE14.

Enter object name [ vbak].

Click on Edit button.

Select save data.

Click on Activate and adjust the data base.

Save.

Search help:-providing a help for the list of the values to be selected on input field is called search help.

Giving F4 functionality to a field is called search help. There are two types of search helps.

1 Elementary search help:- A single search help for an input field is called elementary search help.2 Collective search help:- group of elementary search helps for a single input field is called collective search help.Creating Elementary Search help:-

Go to SE11.

Select search help [zxxxx].

Click on create.

Select elementary search help.

Give short description [ ].

Provide the fields.

Search help method [ lfa1].Search helps parameterimpexplposspos

Mandt

//11

Lifnr

/22

Landt

/33

Save and activate.

Creating collective search help:-

Go to SE11.

Select search help [ ].

Click on create.

Select collective search help

Give short description [ ].

Provide the values

In definition tab

Lifnr / / lifnr

Land1 / / land1

Select include search help tab.

Provide the search help name which we create in elementary search help.

zXXXx.

Save and activate.

Assign search helps:-

We can assign search help at the table level and program level.Assign search help at program level:-

Match code object:-

It is a statement use to assign custom search help by replacing the standard search help if it is available.

If standard search help is not available, it will display the custom search help directly

Parameters: type match code object .

Ex:-

Report zxxxx.

Parameters: p_matnr type mara-matnr matchcode object zxxxx.

Assign search help at table level:-

There are 3 steps to be fallowed

Step1:- create a table.

Step2:- create a search help

Step3:- assign the search help to the table field.Step1:- create a table as below fields.

Matnr-zmatnr(de)

Mtart-zmtart (de)

Mbrsh-zmbrsh (de)

Meins-zmeins (de)

Create some few records

Step2:- create a search help as below

Search help name : ze_zmara

Selection method : zmara

SH parameters are : MATNR, MTART

Assign the SH to the table fields as below

Step3:- open the table zmara

Select matnr field

Click on search help button

Give sh name as ze_zmara

Click on generate proposal

Click on copy

Save activate and test it.

Search help properties:-

Selection method:- it specifies either the table name or view name so that the values can be selected for search help.LPOS:- It specifies the list position on the screen

SPOS:- It specifies the selection screen position of the field

Importing:- if this check box is selected, the value is imported by list screen from the selection screen.

Exporting:- If this check box is selected, the selected value by the user will be exported form list screen to the selection screen.

Dialog type:- we have 3 options available here

Note:- dialog means screen in sap.

Display values immediately:- the values are immediately displayed as soon as we click on the search help button

Dialog with value restriction:- the values are not displayed immediately but instead a screen is displayed where you can put a filter value.

Dialog depends on set of values:-

It is the combination of above two options, i.e, if the set of values are less than 500, the values are immediately displayed.

If the set of values are more than 500 a dialog screen is displayed.

Using help view in search helps:-

Step1:- create a help view with the fields MATNR, MTART, SPRAS, MAKTX save and activate

Step2:- create an elementary search help by the name zxxxx.

Step3:- provide the selection method as zxxxxx (view_name).

Step4:- provide the search help parameter as below, matnr, mtart, spras, makts.Step5:- save activate and test it

Step6:- assign the search help at global level or field level.

Difference between Elementary and Collective search help:-1. Elementary SH describe a search path. The elementary SH must define where the data of the hit list should be read from (selection method). How the exchange of values between the screen template and selection method is implemented (interface of the SH) and how the online input help should be defined (online behavior of the search help).

2. Collective SH combine several elementary search helps. CSH thus can offer several alternative search paths.

3. An elementary SH defines the standard flow of an input help.

4. A CSH combines several ESH. The user can thus choose one of several alternative search paths with collective SH.

5. A collective SH comprises several elementary SH. It combines all the search paths that are meaningful for a field.

6. Both elementary SH and other SH can be included in a collective SH. If the collective SH are contained in collective SH, they are expanded to the level of the elementary search help when the input help is called.Note:- we can add search helps in Data element and also in table and also in programs means reports by using Match code object.

Type Groups:-

If we want to use same custom types (like tables , variables, constants) in various programs then we can create a type group and declare the custom types in that type group and use it where ever required.

Several type groups are available in SAP for example ABAP, SLIS. To use this in program we use the keyword Type-pools.Ex:- Type-pools SLIS.

Creating type group:-

Go to SE11.

Select type group [zxxxxx] (5 letters).

Click on create.

Give the short description [ ].

Check Unicode conversion.

Click on save button.

In the source code tab.

We can declare the variables, constants, types etc.

Save and activate.

Note:-Every type group structure, variable, constants start with name of the type group.

Syntax:- _XXXX.

Views:- View acts like database table only, but it wont occupy storage space. There are 4 types of views.

1. Data base view.

2. Projection view.

3. Maintenance view.

4. Help view.

Database view:- These are implemented with an equivalent view of the database view.

A view created on two or more tables data base tables using inner join is called as data base view. Using data base view we can only read the data We cant do any maintenance These views are used to generate simple reportsProjection view:- These are used to hide fields (only projection)

Help view:- These can be used as a selection method in search help.

Maintenance view:- Allows you to maintain the data distributed to several tables for one application object at a time.

Creating a Database view:- Data base view is created only with one table, then you can make changes to the view. If it is with several tables, only read access are allowed. You can use both open sql and native sql to access this view.

Go to SE11.

Select Views radio button and give the name [Zotc_prc].

Click on create.

A popup will open choose Database View.

Enter short description [ ].

Enter the tables in the tables columnA503

KONP

Keep the cursor on the table name and click the button Relationship

Popup comes where linked tables are present.Select the table and press Copy.

Join conditions.

A503 KNUMH = KONP KNUMH

A503 MANDT= KONP MANDT.

In the View fields tab, we want to enter all the fields which we need in view. We can enter directly or we can copy from DB. Click on Table Fields button it will show the above table select the table and enter it will show all the fields from that table.

Select fields which you want and click on copy.

Dont repeat the fields which are common in both.

We can also formulate the selection by selecting Selection conditions tab.

Give table, field and value.

Save and activate.

Checking the definition of view:-

Click on utilities-> data base object-> display

It will display the SQL statements.

Creating projection view:- This is used to mask out (hide) the fields from table. We can use only one table to create projection view. We can use this to read and write access with open sql. Go to SE11.

Select view [zotc_pv_son].

Click on create.

Select projection view.

Give the description [ ].

Give base table [zotc_t_sonerpro].

Click on Table fields button to choose fields.

Select required fields copy.

Save and activate.

Maintenance View:-It permits a business view on data and enables maintenance of this data. You can change it either with the table maintenance transaction SM30 or SE54. Mainly we use this view in module pool programming.

It is a view which is created on multiple database tables using inner join concept We can read the data and we can maintain the data Maintenance view are specially designed for sap We dont use maintenance views in real time because; maintenance should be done through the sap screens or transaction codes, to maintain data integrity or data consistency. As per the best programming standards maintenance should be done through views, as it involves updating multiple data base tables, but in stand use sap transaction codes

Steps to create maintenance view:-

Go to SE11.

Select views [zotc_kotg502]. Select create.

Select Maintenance view.

Enter description

Provide the following.In table/joins tab

KOTG502

In view fields tab

KAPPL

KOTG502

KAPPL.

Save and activate.

Help view:-

It is a special type of view which is designed only for search helps It is a view created on two or more tables using outer join concept

We cant execute this view directly because it is only used with search helps.

We can only read the data.

Steps to create help view:-

Go to SE11.

Give the view name zxxxx

Click on create, provide the description, give the table name as MAKT, click on relation ships.

Select MAKT-MARA

Click on copy

Click on view fields tab.

Select the below fields

Viewfields

table

MATNR

MARA

MTART

MARA

MBRSH

MARA

SPRAS

MAKT

MAKTX

MAKT

Provide the selection condition if any

Save and activate

Note:- we cant use this view directly as it is used only with search helps.Table type:-It is nothing but internal table which creates in data dictionary. Go to SE11.

Select Data type [zxxxxxx].

Click on create.

Give short description [ ].

Select the line type tab.

Select line type raiobutton [zotc_s_subitem].

Line type is nothing but description.

Save and activate.

Lock objects:- Sap system will synchronizes several users simultaneously access to the same data records with lock mechanism.

Lock objects generate two function modules.

Enqueue_, DEqueue_. Lock objects name should start with EZ or EY only.

Go to SE11.

Select lock object [EZXXXXXX].

Give short description [ ].

Select Tables tab.

Provide detailsName [zotc_i_t2_pland].

Lock mode [exclusive not cumulative].

Select lock parameters tab.

Mandt

zotc_i_t2_plamd.

Vbeln

zotc_i_t2_pland.

How to use the lock objects in program:-

Call function ENQUEUE_EZOTC_T_I2_PLAND.

Delete, Modify, Insert, etc.

Commit work.

Call function DEQUEUE_EZOTC_T_I2_PLAND.

Lock modes:-

1. Exclusive locks:- The locked data can be displayed or edited by one user only. Request for any other lock is rejected.

2. Shared locks:- Several users have simultaneous read access to the same data. Request for exclusive lock is rejected and shared lock accepted.

3. Exclusive but not cumulative:- It can be requested once by the same transaction. Each further lock request will be rejected.

Types of Tables:- There are 3 types of tables.

1. Transparent table.

2. Pool table.

3. Cluster table.

Pool table:-

The tables are used to store the system data such as screen sequence, statistical data, hierarchal data etc.

This tables will have many-to-one relation ship between a table created in data dictionary and a table in data base The name of the table which is created in data base is called table pool

The structure of table pool is as below

1. Table name - this field stores the name of pooled table ex: PT1.

2. Varkey - this field stores the keyfields of pooled table ex: KF1

3. Dataln this field stored the length of pooled table ex: 650 kb

4. Vardata this field stores the data of pooled table ex: zabcd.

Examples:- m_mtvma, m_mtvmb, m_mverb, m_mverc.

Cluster table:-

These tables are also used to store the system data

These tables are same as pooled tables but the structure of cluster table is different from pooled table

These tables also have many-to-one relationship.

The structure of table cluster will contain below fields

1. Tabname

2. Varkey

3. Dataln

4. Vardata

5. Pageno this field stores the page no of data

6. Time stamp this field stores the date, time, user name of person created the data.Examples:- BSEG, BSES, BSEC, AUAY, AUAA.

Difference between transparent pool and cluster tables:-

Transparent table:-

1. Contain a single table used to store master data.

2. It has one-to-one relationship with a table in the database.

3. For each transparent table there is a one associated table in the data base.

4. The database table has the same name, same number of fields and the fields have the same names.

5. They is only single table.

6. Single table can have one or more primary key.

7. Secondary indexes can be created (max 9).

8. They can be accessed using open or native SQL.

9. USE:- they are used to hold master data.

10. EX:- table vendors or table for customers example of transaction data is orders placed by customers.

Pool table:-

1. They are used to hold a large number of very small tables (stores customizing data or system data).

2. It has many-to-one relationship with a table in the database.

3. It is stored with other pooled tables in a single table called table pool in the database.4. The database table has different name and different number of fields and fields has different names.

5. Table pool contains more tables than table cluster.

6. Primary key of each table does not begin with same fields or fields

7. Secondary indexes cannot be created.

8. They can be accessed using open SQL only.

9. USE:- They reduce the amount of database resources needed when many small tables have to be opened at the same time.

Cluster table:-

1. They are used to hold data from a few numbers of large tables (stores system data).

2. It has many-to-one relationship with a table in the database.

3. Many cluster tables are stored in a single table in the database called table cluster.

4. The database table has different name, different number of fields and fields have different names.

5. Contains less tables than pools.

6. Primary key of each table begins with same fields or fields.

7. Secondary indexes cannot be created.

8. They can be accessed using open SQL only.

9. USE:- they would be used when the tables have primary key in common and data in this tables are all access simultaneously.

Creating a table pool:-

Go to se11.

Select the radio button database table.

Select the utilities and other dictionary objects from the menu bar.

Select the radio button table pool or cluster and provide the name.

Click on create.

It shows a pop up box with two options choose table pool radio button.

Click on continue.

Give the short description.

Modify the length of the fields if you want.

Go to -> technical setting in the menu bar and provide the size category.

Save check and activate.Note:- Same steps we need to fallow to create table cluster. Fallow the below steps to create cluster table.

Creating a pool table:-

Go to se11.

Select the radio button and create a table how you are creating a database table then

Select Extras-> Change table category in the menu bar.

Choose pooled table radio button.

Click on delivery and maintenance tab and provide the table pool name which we created earlier.

Save check and activate.

Data types of ABAP:-

Syntax of Integer:-

Data type I.

Ex:-

Data A type i.

The initial value of integer is 0.

Syntax of Packed decimal:-

Data type p decimals .

EX:- Data A(5) type p decimals 2.

The initial value of packed decimal is .00.

Syntax of Float:-

Data type f.

EX:-

Data A type F. The initial value of float is 0.00.

Syntax of char:-

Data type c.

EX:-

Data A(10) type c.

The initial value of char is space.

Syntax for numeric char N:-

Data type N.

Ex:-

Data A type N.

The initial value of N is 0.Syntax of Date:-

Data type D.

Ex:-

Data A type D.

The initial value of Date is 00000000.

The initial format is yyyy mm dd.

Syntax of Time:-

Data type T.

Ex:-

Data A type T.

The initial value of time is 000000.

The initial format is hh mm ss.

Difference between packed decimal and Float:-

Packed decimal:-

Packed data types will round off the value to its nearest value.

Packed data types supports the selection screen.

Float:-

Float data types doesnt round off the value.

Float data types doesnt support the selection screen.

Conditional Statements:-

1. If..Endif/if ..else..endif / if .elseifelseendif.

2. Case.when..endcase.

Syntax:-

1.If .

.

Endif.

Ex:-

If p_day = 1.

Write Sunday.

Endif.

3. if .

.

Else.

.

Endif.

Ex:-

If p_day = 1.

Write Sunday.

Else.

Write Monday.

Endif.

4. If .

.

Elseif .

.

Else.

.

Endif.

Ex:-

If p_day = 1.

Write Sunday.

Elseif p_day = 2.

Write Monday.

Else.

Write Tuesday.

Endif.

5. Case

When .

.

When .

.

When others.

.

Endcase.

Ex:-

Case p_day.

When 1.

Write Sunday.

When 2.

Write Monday.

.

.

.

When others

Write invalied input.

Endcase.

Looping:-

1. conditional (Do-Enddo).

2. Un conditional (While-Endwhile).

Syntax:-

1 DO statement:-

Do times.

Enddo.

Ex:-data count type i.

Do 10 times.

Count = count + 1.

Write count.

Enddo.

O/P:-

1 2 3 4 5 6 7 8 9 10.

3. While statement:-

While .

endwhile.

Ex:-data count type i.

Count = 1.

While count text elements-> selection texts

Step3:- in this we provide our own text or we can copy the text from data dictionary.

Name

text

data dictionary

P_land1country

P_mtartmaterial type

check the box.

Step4:- save activate and text the program.

2.Internal tables:-

It is an instance of data base table. It is temporary memory location which is used to store the data of data base table. By default 8kb size will be allocated to internal table and if will increase dynamically based on the data. Internal table store multiple records. Pushing data to the internal table or reading the data from the internal table is always record by record i.e, through work area:- It is also a temporary memory location which can store a single recordVariable:- it is also a temporary memory location which stores a single value.

Difference between internal table and data base table:-

Data base table

internal table1. Data base table are permanent

1.internal tables are temporary storage

Memory location.

Location.

2. Scope is global that means we

2. The scope of the internal table is upto

Can access the DB table from

the program.

Any where in the abap.

3. We must provide the size category

3. We no need to provide size category to

The internal table.

Syntax for declaring the internal table and work area:-

1. Data type standard table of .Data type .

Ex:- data it_vbak type standard table of vbak.

Data wa_vbak type vbak.

In this case the internal table will have all the fields of standard table vbak.

2. Data type table of .

Data type .

Here user define type can be defined by types key word.

Syntax:- types: begin of ,

< Field> type ,

type ,

End of .

Ex:- types: begin of ty_vbak,

Vbeln type vbeln_da,

Erdat type vbak-erdat,

End of ty_vbak.

Data: it_vbak type table of ty_vbak.

Data wa_vbak type ty_vbak.

In this example the internal table and the work area consist of only two fields by name vbeln and erdat.

3. Data type occurs 0 with header line.Ex:- data it_vbak type vbak occurs 0 with header line.

In this case no need to create work area internal table implicitly creates a header line which acts like work area.

4. Data type occurs 0 with header line.Select the data from database table into internal table:-

We can pull the records of data base table in to internal table by using select statements.

Syntax:-

1. Select * from into .

Append to .

Endselect.

Ex:- select *

From vbak

Into wa_vbak.

Append wa_vbak to it_vbak.

Endselect.

In this example it will pull all the records one by one places into work area and it is add the records to internal table by using append statement.

2. Select

.

.

.

From

Into .

Append to .

Endselect.

Ex:- select vbeln

Erdat

From vbak

Into wa_vbak.

Append wa_vbak to it_vbak.

End select.

In this example it will pull all the records of vbeln and erdat into work area and add this to internal table by using append statement.

3. Select *

From

Into table .

Ex:- select * from vbak into table it_vbak.

In this example it will pull all the records into internal table in one iteration.4. Select *

From

Into

Up to rows.

Ex:- select * from vbak into table it_vbak up to 10 rows.

In this example it will pull first 10 records from the data base table to internal table.

5. Select *

From

Into table

Where .

Ex:- select * from vbak into table it_vbak where vbeln = 12232.

In this example it will check the condition and according to the condition it will pull the records from data base table into internal table.

6. Select *

From

Into corresponding fields of table

Where .

Ex:- select * from vbak into corresponding fields of table it_vbak where vbeln = 1234.

In this case if the structure of internal table and data base are different then also it is also fill the corresponding fields.

7. Select single

Into

From

Where .

Ex:- select single vbeln erdat into wa_vbak from vbak where vbeln = 123.

It will pull the exact maching single record from the data base table.

8. Select

Into

Up to 1 row

From

Where .

Endselect.

Ex:- select vbeln erdat into wa_vbak up to 1 row from vbak.

Endselect.

In this example it will pull the first matching record.

Note:-

If all the key fields are available in your program then use select single. It is very fast.

If only some key fields are available then use the selected up to one row. it is slow.

Working with joins:-

In relational database, you normally need to read data simultaneously from more than one database table into an application program. You can read from more than one table in a single select statement via joins.There are two types of joins.

1. Inner join.

2. Left outer join.

Syntax:- select ~

~

~

~

Into table

From inner join/left outer join

On ~ = ~

Where .

Inner join:-

The join expression links each line of with the lines in that meet the join condition . This means that there is always one or more lines from the right hand table that is linked to each line from the left hand table by the join. If does not contain any lines that meet the join conditions , the line from is not included in the selection.

Left outer join:-In an inner join, a line from the left-hand database table or join is only included in the selection if there is one or more lines in the right-hand database table that meet the on condition . The left outer join, on the other hand reads lines from the left-hand database table or join even if there is no corresponding line in the right-handle table.

Ex:-select vbak~vbeln

Vbak~erdat

Vbap~posnr

Vbap~matnr

Into table it_vbakp

From vbak inner join vbap

On vbak~vbeln = vbap~vbeln

Where vbak~vbeln in s_kunnr.

For all entries:-This statement is used to replace inner joins or select with joins it is used to read the data from one or more than 3 tables, it can be used to read the data from 2,3,4 etc. it doesnt put any load on the data base.

Syntax:- select *

From

Into table

Where .

If not is initial.

Select *

From

Into table

For all entries in

Where = -.

Endif.

Ex:- select bukrs

Belnr

Xblnr

Budat from bkpf

Into table it_bkpf

Where belnr in s_belnr.

If not it_bkpf is initial.

Select bukrs

Belnr

Gsber

Kunnr from bseg

Into table it_bseg

For all entries in it_bkpf

Where belnr = it_bkpf-belnr.

Endif.

Prerequisite for for all entries is to check the base table is initial or not.

Types of internal tables:-

There are 3 types of internal tables they are.

1. standard table

2. sorted table

3. Hashed table.

1. standard table:- These are the default internal tbale. The key of a standard table is always non-unique so duplicates are allowed.

Syntax:- data type standared table of .

Records can be accessed through both index and condition.we can sort the table n number of times.

Ex:- data it_vbak type standared table of vbak.

2. Sorted table:- In the sorted internal table records are always in sorted order.Records can be accessed through both index and with key (condition).Sorted internal tables cannot be sorted again.Sorted internal tables are always, either unique / non unique.

Syntax:- data type sorted table of with unique / non unique key

3. Hashed tables:- Hashed tables are non index tables hashed table always have a unique key. You can not access a hashed table using its INDEX.

Syntax:- data type hashed table of with unique / non unique key ..

List of the internal table operations:- 1. Append

2. Insert

3. Sort

4. Describe table

5. Read table

6. Loop at

7. Modify

8. Delete

9. clear

10. refresh

11. free

12. collect

13. move-corresponding

14. append lines of

15. insert lines of

Append:- this statement is used to add a single record form work area to internal table.

Syntax:- append to .

Ex:- wa_kna1-kunnr = 123.

Wa_kna1-land1 = DE.

Wa_kna1-name1 = ramesh.

Append wa_kna1 to it_kna1.

Note:- the record will always added at the bottom of the internal table.

Insert:- this statement is used to insert the record form work area into internal table at specified location.

Syntax:- insert into index .

Ex:- wa_kna1-kunnr = 123.

Wa_kna1-land1 = DE.

Wa_kna1-name1 = ramesh.

Insert wa_kna1 into it_kna1 index 3.

Sort:- this statement is used to sort the internal table data either in ascending order or descending order.

Syntax:- sort by .. .Ex:- sort i_kna1.

Sort i_kna1 by name1.

Sort i_kna1 by land1 descending.

Note:- the sort statement sorts the data by acceding order by default.

It will sort based on the order of the fields i.e, F1,F2,F3.

Describe table:- this statement is used to find the total number of records in the internal table.Syntax:- describe table lines .Ex:- data v_lines type i.

Describe table i_kna1 lines v_lines.

Write:/ total number of lines, v_lines.

Read table:- this statement is used to read a single record from internal table into work area.

There are two forms of read statements.

1. Read table with index.

2. Read table with key.

1. Read table with index:-

This statement will read the record specified by the index no into work area.

Syntax:- read table into index .

Ex:- read table it_kna1 into wa_kna1 index 3.

2. Read table with key:-This statement will read single record from internal table into work area one which is specified by the field values.

Syntax:- read table into with key =

= Binary search.

Note:-The prerequisite for the above statement is, the internal table should be sorted.

Ex:- sort i_kna1.

Read table i_kna1 into wa_kna1 with key kunnr = vinay

Binary search.

Search:- we are having two types of search

1. Linear search.

2. Binary search.

1. Linear search:- in linear search the search will be happen line by line so it will take more time while searching the record.

2. Binary search:- the binary search will divide the entire internal table into tow halfs. Then it will search for the record roughly either in first half or in the second half.

It the record is available in the first half then it will again divide the first half into two parts by deleting the second half.

Again it will search roughly either in first half or second half. The procedure will continuous until it finds the exact record.

So it is faster than linear search and it will improve the performance of the read statement.

Loop and Endloop:- this statement is used to read multiple records from internal table into work area one by one.

Syntax:- loop at into .

..

,

Endloop.

Ex:- loop at it_kna1 into wa_kna1.

Write:\ wa_kna1-kunnr, wa_kna1-land1.

Endloop.

Syntax:- loop at into from to .

.

Endloop.

Where n1 and n2 are the index numbers.

Ex:- loop at it_kna1 into wa_kna1 from 1 to 10.

Write:\ wa_kna1-kunnr, wa_kna1-land1.

Endloop.

Syntax:- loop at into where =

= .

.

Endloop.

Ex:- loop at it_kna1 into wa_kna1 where land1 = US.

Write:\ wa_kna1-kunnr, wa_kna1-land1.

Endloop.

Modify:- this statement is used to modify a single record or multiple records based on the condition.

Syntax:- modify from index transporting ..

Ex:- sort it_kna1 by kunnr.

Read table it_kna1 into wa_kna1 with key kunnr = 123

Binary search.

Wa_kna1-name1 = sony.

Wa_kna1-land1 = IN.

Modify it_kna1 from wa_kna1 index sy-tabix transporting name1 and land1.

Sy-tabix:- it is a system variable which holds the index number of the internal table which is currently process.

Delete:- this statement is used to delete the data from internal table .

Syntax:-

delete from .

Delete index .

Delete where = value

= value..

Delete adjacent duplicates:- this statement is used to delete the duplicate records which one adjacent is, side by side to each other.

The prerequisite to this statement is the internal table should be sorted.

Syntax:- delete adjacent duplicates from comparing .all fields.

Ex:- delete i_kna1 index 3.

Ex:- delete i_kna1 where kunnr = 123.

Ex:- sort i_kna1.

Delete adjacent duplicates from it_kna1 comparing all fields.

Clear:- this statement is used to delete the data from a variable or work area or internal table.

Syntax:- clear .

Clear .

Clear [].

Ex:- clear v_name.

Ex:- clear wa_kna1.

Ex:- clear it_kna1[].

It will clear the body of internal table it_kna1.

Refresh:- this statement is used to delete the data from internal table only.

Syntax:- refresh .

Ex:- refresh it_kna1.

Free:- this statement is similar to clear and refresh. i.e, it will also delete the data from a variable, work area and internal table.

The difference is , with the clear and refresh statement the data will be deleted but not he memory. With the free statement the data will be deleted and memory also deleted.Syntax:- free

Free .

Free .

Ex:- free v_name.

Ex:- free wa_kna1.

Ex:- free it_kna1.

Collect:-

It similar to append statement The difference between append and collect is, the collect statement checks whether the work area record already exits in the internal table or not.

If it exits it will add the numerical field.

If it doesnt exits it will add new record to the internal table. That is similar to append.

Syntax:- collect into .

Ex:- collect wa_kna1 into it_kna1.

Append lines of :- this statement is used to add multiple records from one internal table to another internal table.

Syntax:- append lines of from to to .

Ex:- append lines of it_kna1 from 3 to 6 to it_kna2.

Insert lines of :- this statement is used to add the data from one internal table to another internal table at a specified index number.

Syntax:- insert lines of from to into index .

Ex:- insert lines of it_kna1 from 6 to 8 into it_kna2 index 3.Moving data from one internal table to another internal table:-

1. Itab2[] = itab1[]. (best processing).

2. Loop at itab1 into wa_itab.

Wa_itab2-f1 = wa_itab1-f1.

Wa_itab2-f2 = wa_itab2-f2.

Append wa_itab2 to itab2.

Endloop. (bad processing).

Move corresponding:-

This statement is used to move the data for corresponding fields from one work area to another work area.

Syntax:- move corresponding to .

Ex:- loop at it_kna1 into wa_kna1.

Move corresponding wa_kna1 to wa_kna2.

Append wa_kna2 to it_kna2.

Endloop.

This statement is not advisable because it need to compare each field from source work area to target work area.

Move:-

This statement is used to move the data from source to target individual fields.

Syntax:- move to .Ex:- loop at it_kna1 into wa_kna1.

Move Wa_kna1-kunnr to wa_kna2-kunnr.

..

Append wa_kna2 to it_kna2.

Endloop.Statements deals with database:-

The statements are used to update data base are.

1. Insert

2. Modify

3. Update

4. Delete

Insert:-

It is used to insert a single or multiple records from internal table to data base table.

Sy-subrc = 0, means all the records where successfully inserted.

Sy-subrc NE 0, means only few records are inserted or no records are inserted.

There are two forms of insert statement.

1. Insert from table

2. Insert from table accepting duplicate keys.

Insert from table:-

This statement will insert the records into database tables.

Suppose if there are only duplicate records in the internal table it will through the an runtime error.

Insert from table accepting duplicate keys:-

If we use this statement it will not through any runtime error even through it has duplicate records.

It is just to use runtime error.

Syntax:-

Insert from .

Insert from table .

Ex:- insert t001w from wa_t001w.

Ex:- insert t001w from table it_t001w.

Modify:-

This statement is used either to modify a record i.e, update or insert a new record.

It will modify if the matching record found other wise insert the record.

Sy-subrc is always 0 because it may modify or insert a new record.

Syntax:-

Modify form .

Modify from table .

Ex:- modify vbak from wa_vbak.

Ex:- modify vbak from table it_vbak.

Update:-

This statement will update the record which is available in the data base table.

Sy-subrc = 0. Means if at least one record is updated.

Sy-subrc NE 0, means none of the records are updated.

There are two forms for update statement.

Syntax:-

Update from .

Update from table .

Ex:- update vbap from wa_vbap.

Ex:- update vbap from table it_vbap.

Delete:-

This statement is used to delete either a single record or multiple records from data base table.

Sy-subrc = 0 means all records are successfully deleted.

Sy-subrc NE 0 means no records are deleted.

Syntax:-

Delete from .

Delete form table .

Ex:- delete mara from wa_mara.

Ex:- delete mara from table it_mara.

Prerequisites for above statements:-

Always work with internal tables rather than work areas to insert/update/modify data into database table.

The structure of internal table / work area must be same as data base table.

Ex:- data: i_kna1 type standard table of kna1.

System variables:-

There are two system variables which are update automatic for each open sql operations.

1. Sy-subrc.

2. Sy-dbcnt.

Sy-subrc:-

It is a system variable which stores the return code of an open sql operation.

If sy-subrc = 0. It menas the operation is successfully executed.

If sy-subrc NE 0. It means the operation is failed.

Sy-dbcnt:-

It is a system variable which stores the number of records successfully processed.Note:- apart form these two we are having so many system variables which we can see in syst table.

3.Modularization.

Modularization is a better technique of dividing a main program in sub programs for a better readability and reusability is called modularization. Modularization is achived using the fallowing technique.

1. Include programs

2. Function modules

3. Subroutines

4. Macros (used in HR-ABAP module).

5. Class methods (used in OOABAP).

Include programs:-

These programs contain a set of reusable statements.

These can not be executed independently.

These must be inserted in the main program for execution

These programs are called as type I programs.

It does not contain any parameters interfaces i.e, no importing no exporting parameters.

Ex:- SAPMV45A is the standard program for sales order which contains n number of include programs.

Include zmain_prog_top.

Creating a include and calling the include in the executable program:- Go to SE38 and provide the progam name [zxxxxxxxxx].

Click on create.

Give the description and in the program type select the type as include program.

Click on create

It will create a program with the statement include zxxxx.

Write the code which you want to reuse.

Save check and activate.

Go to se38 and provide the program name zxxxxxxxx

Click on create

Give the description and in the program select the type as executable program.

Click on create

It will create a program with the statement report zxxxx.

Now in that program where ever you want write the code as

Include zxxxx.

So that It will call the code at that position.

Save check and activate.

Function modules:-

It is a repository objects which contain ABAP logic or statements for doing a specific task or functionality.

Function modules contain parameters interfaces i.e, import, export, changing, tables etc. These are mainly used for global modularization.

Function modules can be remote enable. i.e, they can access remote servers to fetch the data.

Function modules contain exceptions to catch certain type of errors.

Function group:-

It is a group or container of function modules.

Every function module must be inserted in a function group.

Function module parameter interface (se37 ro SE80):-

Import:- input variables to function modules are called importing parameters.

Export:- output variables from function modules are called as exporting parameters.

Changing:- variables which acts as importing and exporting are called as changing parameters.

Tables:- internal tables which acts as importing and exporting are called as tables parameters.

Exceptions:- these are used to catch certain types of errors . Exceptions are returns in sy-subrc variable.

Source code:- it consist of ABAP code for doing a specific task.

Steps to create a function group:-

We can create function group either in SE37/SE80.

Go to SE80

Select function group.

Give the name as zxxxx.

Press enter

Click on yes

Provide the short description.

Click on save

Activate the function group immediately.

Steps to create function module:-

Business requirement:- develop a function module which displays customer details.

Go to SE37.

Give the name as zxxxxxx.

Click on create Give function group, description, click on save

Provide the importing parameters as shown

Im_kunnr type kna1-kunnr.

Provide the exporting parameters as shown.

Ex_kna1 type kna1.

Provide the exception as shown.

No_kunnrtype no_kunnr.

Invalid_kunnr type invalid_kunnr.

Write the below source code.

If im_kunnr is initial.

Raise no_kunnr.

Else.

Select single * form kna1 into ek_kna1

Wehere kunnr = im_kunnr.

If sy-subrc = 0.

Raise invalid_kunnr.

Endif.

Endif.

Save, activate and test it.

Using function module in program:-

Data: wa_kna1 type kna1.

Parameters: p_kunnr type kna1-kunnr.

Call function zxxxx

Exporting

Im_kunnr = p_kunnr

Importing

Ex_kna1 = wa_kna1

Exceptions

No-kunnr = 1

Invalid-kunnr = 2

Others = 3.

If sy-subrc = 1.

Message:please enter customer no, type I.

Elseif sy-subrc = 2.

Message please enter valied cust no, type I.

Elseif sy-subrc = 3.

Message unprdictable error type I.

Endif.

Write:/ wa_kna1-kunnr, wa_kna1-name1.

Subroutines:-

Subroutines contains piece of ABAP code which one mainly used for readability and reusability.

These one also used for local modularization.

Syntax:- subroutines contains two steps.

1. Subroutine definition.

2. Subroutine implementation.

Syntax for subroutine definition:-

Perform using

Changing

Tbale .

Syntax for subroutine implementation:-

Form using

Changing

Table .

.

.

Endform.

Types of subroutines:-

There are two types of subroutines.

1. Local subroutine

2. Global subroutine

Local subroutine:- if subroutine definition and implementation i.e, perform and form..endform are available in same program then it is called as local sub routine.

Global subroutine:- if subroutine definition is available in one program and subroutine implementation is available in another program then it is called as global subroutine or external subroutines.

Syntax for global subroutine:-

Perform program

using

Changing

Tbale .

Form using

Changing

Table .

.

.

Endform.

Parameters interface or subroutines:-

Using:- Importing variables to sub routines one defined with using.

Changing:- exporting variables are, defined with changing.

Tables:- internal tables for importing and exporting one definition with tables.

Types of passing values:-

There are 3 types to send the values form subroutine definition to subroutine implementation.

1. Pass by value or call by value

2. Pass by reference

3. Pass by value and return.

Pass by reference:-

In this type, the actual and formal parameters will be referring to the same location.

If any changes made to the formal parameters the actual parameters will also effected.

Pass by value:-

In this type the actual and formal parameters will be referring to separate memory locations.

If any changes are made to the formal parameters it will not affect the actual parameters.

Pass by value and return:-

In this type the actual and formal parameters will be referring to separate memory locations.

If any changes made to the formal parameters, the actual parameters will be changed only when the last statement in the subroutine implementation or the entire subroutine is executed.

Example on subroutine:-

Data a type i.

A = 10.

Write :/ before subroutine call , A.

Perform pass_by_ref using A.

Perform pass_by_value using A.

Perform pass_by_value_return changing A.

Write:/ after subroutine call, A.

Form pass_by_ref using f_a.

F_a = f_a + 10.

Endform.

Form pass_by_ref using value (f_a).

F_a = f_a + 10.

Endform.

Form pass_by_value_return changing value (f_a).

F_a = f_a + 10.

Endform.

Note:- creation for class and method are in the ooabap material.

Messages:-

All the messages are stored in a class called as message class.

SE19 is the tcode for creating message class.

Generally there will be a single message class for entire project.

Message-id:-

It is the keyword which is used to assign the message class to our report so that, our report can access all the messages in the message class.

Type of messages:-

Type

description

E

error message

S

success

W

warning

I

information

A

abort

Substutional parameters:-

& is the symbol use to substitute a variable or parameter in to the message.

We can substitute a maximum of 4 substitution parameters.

Syntax:-

1. Message type .

2. Message

3. Message with

Steps to create message class:-

Go to SE91.

Give the name as zxxxx.

Click on create.

Give description.

Click on message tab.

Define the message as below.

Message

message short text.

00

material does not exit.

001

material number & does not exit.

002

& & & &

-> click on save.

Using message class in report:-

Report zxxxxxx message-id zxxxxx.

Data wa_mara type mara.

Parameters: p_matnr type mara-matnr.

Select single * from mara

Into wa_mara

Where matnr = p_matnr.

If sy-subrc = 0.

Write:/ wa_mara-matnr.

Eelse.

Message material does not exit type E.

Message I000.

Message I001 with p_matnr.

Message I002 with material does not exit.

Endif.

Difference between include function module and subroutine:-

Include

function module

subroutineCan not be executed

can be executed

can not be executed

No parameter interfaceparameter interface

parameter interface

No exception

exception

no exception

No RFC

RFC

no RFC.

ABAPPage 1