Você está na página 1de 84

SAP-ABAP

SAP System Applications and Products in data processing Categories of SAP: TECHNICAL FUNCTIONAL NEW DIMENSIONAL PRODUCTS

TECHNICAL: ABAP: Advance business application programming. ABAP is a programming language of SAP. BASIS: Business application software integrated solution. Their job is concerned in administration. NETWEAVER: XI Exchange infrastructure / PI Process integration Interfaces EP Enterprise portal

BI

Business intelligence It is a reporting and analysis tool.

FUNCTIONAL: SD MM PP Fi CO PS WF Sales and distribution. Materials and management. Production and planning. Financial accounting. Controlling. Project Systems Work Flow Modules

NEW DIMENSIONAL PRODUCTS: CRM Customer Relationship Management.

1 Kiran

SAP-ABAP
SRM SEM SCM APO **NOTE:SAP is an ERP ERP means Ready to use Sap is one of the leading ERP *Abapers customize the Standard SAP DD, Programmes, Function Modules,.......etc. based on the CLIENT Requirements. The Version using SAP isecc6.00 *ecc erp central componenT. Supply Relationship Management. Strategy Enterprise Management. Supply Chain Management. Advanced Planner Optimizer.

6.00 is the version SAP Releases TWO systems 1.IDES. 2.PRODUCTION SYSTEMS. 1.IDES:International Demonstration Education System. This system is for learning.

2.PRODUCTION SYSTEMS:
This system is for Real time server (companies). *NOTE: Production system contains live data where as IDES contains Dummy data.

**R/3 ARCHITECTURE:
R/3 is an integrated suite of applications designed to handle the data processing for large corporations. R 3 Real time. type of the architecture called three tier architecture.

*NOTE: 1.abap code runs on the application server(AS). 2.To overcome the load of the application server(AS), that has been shared with many application servers(AS1,AS2,AS3,.......,).

2 Kiran

SAP-ABAP

Fig:R/3 architecture

Types of work processes: D(Dialog) B(Background) S(Spool) V(Update) E(Enqueue) Dialog requests. Background jobs. Print spool requests. requests to update data in the database Logical lock requests

Dialog Work Process Dialog work processes deal with requests from an active user to execute dialog steps. Update Work Process Update work processes execute database update requests. Update requests are part of an SAP LUW that bundle the database operations resulting from the dialog in a database LUW for processing in the background.

3 Kiran

SAP-ABAP
Background Work Process Background work processes process programs that can be executed without user interaction (background jobs). Enqueue Work Process The enqueue work process administers a lock table in the shared memory area. The lock table contains the logical database locks for the R/3 System and is an important part of the SAP LUW concept. In an R/3 System, you may only have one lock table. You may therefore also only have one application server with enqueue work processes. Spool Work Process The spool work process passes sequential datasets to a printer or to optical archiving. Each application server may contain only one spool work process. The services offered by an application server are determined by the types of its work processes. One application server may, of course, have more than one function. For example, it may be both a dialog server and the enqueue server, if it has several dialog work processes and an enqueue work process. You can use the system administration functions to switch a work process between dialog and background modes while the system is still running. This allows you, for example, to switch an R/3 System between day and night operation, where you have more dialog than background work processes during the day, and the other way around during the night.

ABAP WORK BENCH:


Abap work bench is a set of executables to develop ERM(enterprise report management) and applications that runs on R/3 system. It is a tool to develop ABAP objects

SE System Engineering: usually indicates some kind of development tool - e.g. ABAP Editor SE38, Class Browser SE24.

4 Kiran

SAP-ABAP
Development Tools / Components in ABAP Work Bench:
Development tools of Abap work bench are ABAP Dictionary. ABAP Editor. Function Builder. Class Builder. Screen Painter. Menu Painter.

ABAP Dictionary:
Through ABAP dictionary we can create data base tables, structures, domains, views, data elements, lock objects, search help, etc...., Transaction code (T.code) is SE11. NOTE:SE-system engineering. ABAP Editor: It is used to write program. T.code is SE38. Function Builder: Through function builder we can create Function groups and Function Modules. T.code is SE37.

Class Builder: Through Class Builder we can create global classes and methods. T.code is SE24.

Screen Painter: Through screen painter we can create / customize screens. T.code is SE51.

5 Kiran

SAP-ABAP
Menu Painter:
Through the menu painter we can create menus in the reports (or) in the standard applications. T.code is SE41.

TYPES OF DATE BASE TABLES: Transparent table Cluster table. Pooled table. Client: A client is organizational and legal entity in the SAP system. The main objective of the client
is to keep the data isolated. The data in a client can be only visible within that client; it can not be displayed or changed from another client. In a physical SAP system there can be multiple clients(Ex: Development, Quality and Production). Each of these clients can have different objective or each client represents a unique work environment.

Transaction Code (TCode): A Transaction code is command that tells the system location of
Task. Each and every screen is having different Transaction codes.

Transparent table:
Transparent table stores master data as well as transaction data. master data:-master data is the data which is does not changes frequently. Ex:-id, bank account no, etc.., transaction data:-Transaction data is the data which changes frequently The client (mandt) and the next field should be the primary key of the transparent table. When we create a transparent table in dictionary system automatically creates table in a data base after activation. *These tables have one-to-one relation. Both tables have same names, same number of fields, same data types, same length and same field names. Table pools (pools) and table clusters (clusters) are special table types in the ABAP Dictionary. The data from several different tables can be stored together in a table pool or table cluster. Tables assigned to a table pool or table cluster are referred to as pooled tables or cluster tables. A table pool or table cluster should be used exclusively for storing internal control information (screen sequences, program parameters, temporary data, continuous texts such as documentation). Data of commercial relevance is usually stored in transparent tables.

6 Kiran

SAP-ABAP
Cluster table:
Several logical data records from different cluster tables can be stored together in one physical record in a table cluster. Cluster table stores continuous text. EX: Paragraphs , etc..., The client(mandt) and the next field should be the primary key of the cluster table. These are many so, they have many-to-one relation with the data base table . All the clustered table united together to form a table cluster.

Pooled table:
A table in the database in which all records from the pooled tables assigned to the table pool are stored corresponds to a table pool. It stores the program parameter, screen numbers and temporary data. It has also many so they have manyto-one relationship with the database. All the pool tables united together to form pool table. The first field may or may not be the primary key.

DATA TYPES IN ABAP DICTIONARY:


CHAR NUMC FLTP INT1 INT2 INT4 DATS TIMS CLNT LANG DEC Access Characters, Numeric, Alphanumeric. Character String. Floating Point. 1 Byte Integer. 2 Bytes Integer. 4Byes Integer. For Date. For Time. Client. Language. Decimals to Store symbols and negative values.

7 Kiran

SAP-ABAP
CURR Currency. Both have to use. CUKY Currency key.

QUAN

Quantity. Both have to use.

UNIT

Unit

DOMAIN:
Domain consists of a technical characteristics of the field. Technical characteristics are Data Type of the field. Length of the field. Value table and Value range. ** Domains are reusable in the same table as well as in the different table.

DATA ELEMENT:
Data Element consists of Field labels. Field documentation. Parameter id. ***Data elements should not reusable in the Same table. **Data elements are reusable in Different table. ****NOTE: Table name should start with Y(or)Z.

8 Kiran

SAP-ABAP
EX: CREATION OF A EMPLOYEE TABLE: TABLE: ZTHILAK_EMP Emp_no 5 Emp_name 15 Emp_city 15

DATA ELEMENT: FL: Emp_no DOMAIN: DT: CHAR ZDM1 LEN:5 ZDM2 LEN:15 ZDE1 FL: Emp_nam e ZDE2 DT:CHAR FL: Emp_city ZDE3

**NOTE: DT-Data type. LEN-Length FL-Field label

FIG: CREATION OF EMP TABLE There are two types to create a Table 1.Bottom-up-approach. 2.Top-down-approach. BOTTOM-UP-APPROACH: CREATION OF DOMAIN. CREATION OF DATA ELEMENT. CREATION OF A TABLE.

9 Kiran

SAP-ABAP
CREATION OF DOMAIN: Goto T.code SE11. Select domain. Provide domain name. EX:ZDOM_EMPLNO. Create Then we will enter into DICTIONARY MAINTAIN DOMAIN Provide the information. save in Local object.(ctrl+s). Check.(ctrl+f2). Activate.(ctrl+f3). **NOTE: The same process will repeat for the other DOMAINS also.

CREATION OF DATA ELEMENT: Goto T.code SE11. Select Data type. Provide Data elemenT. EX:ZDE_EMPLNO. create Then we will enter into the DATA ELEMENT Domain(which we have given previous EX: ZDOM_EMPLNO). Click on FIELD LABEL. And provide the field label. Save+local object+check+activate. 10 Kiran

SAP-ABAP

CREATION OF TABLE : Goto T.code SE11.

Select database table and provide database table name EX:ZTHILAK_EMP.

create Provide the short description of your table. Provide Delivery class A . A Application table.

11 Kiran

SAP-ABAP
DELIVERY CLASS: Delivery class controls the transport of the table data, when installing or upgrading in a client copy between the customer systems. Data browser/table view maintenance allowed. Save + local object. Click on technical settings: Data class APPL0. DATA CLASS: Data class defines the physical area of the database in which the table is logically sorted. APPL0 APPL1 APPL2 Master data only. Transaction data only. organisation and customizing.

Buffering should not allowed.

SIZE CATEGORY: Size category provides the number of data records that can be stored in table based on the number of fields. Mean time give 0. Save. Back. Click on fields tab and provide the field name. 12 Kiran

SAP-ABAP

After creating table: go to extras and select enhancement.

Select the category from the list

Save + check + activate. TO enter data after creating table Utilities. Table contents. 13 Kiran

SAP-ABAP
Create entries. Save. Execute.

**NOTE: click on reset to give data to the next record. To provide the salary to the record first create the salary field and create another field for the currency key . To assign the currency key to the salary, double click on the field name (EMP_SAL). You will get the another window, provide TABLE NAME and FIELD NAME where ref.field appears.

14 Kiran

SAP-ABAP
NOTE: **Normally we will use TOP-DOWN-APPROACH to create Tables.

**LINKING TWO TABLES: To link two different tables, there should be common field in in both tables. That common field should be the primary key in one of the table. Ie in another table that is called foreign key. Assume that you have two (employee and department) tables. Go to employee table and provide the primary key of department table (d.no) And its data element. Select d.no in the employee table and click on foreign key. Check table is a table which you are going to link. It is used to check whether the input values are valid or not. Click on general proposal. Click on copy. Save + check + activate. Step-1:

15 Kiran

SAP-ABAP
Step2:

**TABLE MAINTENANCE GENERATOR: Through table maintenance generator the end user can enter the data into a table. When we create a table maintenance generator, the table control, from there the end user can edit, enter and display the data. CREATION OF THE TABLE MAINTANANCE GENERATOR: Utilities + table maintenance generator. Authorisation group: &NC&. Function group: Table name (ex:ZTHILAK_EMP). Maintenance type: select one step. Screen number: ex:10. Click on create. Go to: SE93. Provide transaction code: give the name for the end user (ex: ZTHILAK). Select transaction with parameter Transaction--SM30 Select skip initial screen. NAME OF THE SCREEN FIELD VIEWNAME VALUE TABLE NAME (ex:ZTILAK)

16 Kiran

SAP-ABAP
UPDATE OR SHOW STEP-1: X

STEP-2:

STEP-3:

17 Kiran

SAP-ABAP
STEP-4:

OUTPUT:

[**NOTE: End user can access the data by using Transaction code (ex:ZTHILAK).]

18 Kiran

SAP-ABAP
VIEWS: View is an imaginary table. View does not hold data permanently. It holds data only at run time. Views fetches data from database tables only. TYPES OF VIEWS: Database view. Projection view. Maintenance view. Help view. Database view: Through database view, we can retrieve data from one or more tables at a time. To retrieve data from two different tables, there should be a common field in both tables(primary key and foreign key). **If it retrieves data from more than once table, maintenance of data is not possible. Data base view follows inner join. Projection view: Through projection view, we can retrieve data from only one table. **Maintenance of data is possible ie write, read and change. Maintenance view: Through maintenance view, we can retrieve data from two or more tables at a time. To retrieve data from two different tables there should be a common field in both Tables(primary key and foreign key). ie we can Read only. Read and change. Read, change, insert and delete.

*After creating maintenance view we need to create table maintenance generator. 19 Kiran

SAP-ABAP
*T.code to generate table maintenance SE54. *Maintenance view follows left outer join. HELP VIEW: Through help view we can retrieve data from two or more tables at a time. It is mainly used in search help. CREATION OF DATABASE VIEW: Goto SE11. Select view and provide view name. Click on copy. Give the table names which you gonna to join. Under table field give the common field. save click on view fields tab click on table fields. Double click on table(which you have provided). Select the fields which you want and click on copy. Double click on another table(which you have provided). Select the fields which you want and click on copy. Save+check+activate. **To see the output click on utilities + contents + execute.

20 Kiran

SAP-ABAP

21 Kiran

SAP-ABAP

Projection view: Go to SE11. Select view and provide view name. Click on create. Select projection view. Click on copy. Give the basis table name. Click on table fields. Select the fields which you want and click on copy. Click on maintenance status. save+check+activate. **To see the output click on utilities +contents+execute. NOTE: data gets stored in database table only.

22 Kiran

SAP-ABAP

CREATION OF MAINTENANACE VIEW: Go to SE11. Select view and provide view name. Click on create. Select maintenance view. Click on copy. provide table name. Click on symbol. 23 Kiran

SAP-ABAP
Relationship + save. Again click on relationship. Select checkbox and copy. click on view fields tab. Click on table fields. Double click on table name and select the fields which you want. Double click on the another table and select the fields which you want. Click on maintenance status. save+check+activate. Goto SE54(table maintenance generator). Provide view name and create Utilities + table maintenance generator. Authorisation group: &NC&. Function group: Table name (ex:ZTHILAK_EMP). Maintenance type: select one step. Screen number: ex:10. Click on create. Go to: SE93. Provide transaction code: give the name for the end user (ex: ZTHILAK). Select transaction with parameter Transaction--SM30 Select skip initial screen. NAME OF THE SCREEN FIELD VIEWNAME UPDATE OR SHOW VALUE TABLE NAME (ex:ZTILAK) X

24 Kiran

SAP-ABAP

25 Kiran

SAP-ABAP

STRUCTURE: Structure is like a table having fields but the structures do not hold data permanently. It holds data only at run time (or) it can hold the data once it is linked to a table. ie when it is independent, it does not hold data. Structures are of two types. External structure. Append(internal) structure. External structure: Structure, which is created outside the table is called external structure. External structures are reusable. The keyword to add external structure to the table is .include APPEND STRUCTURE: Structure, which is created inside the table is called append(internal) structure. Append structures are not reusable. The keyword to add append structure to a table using .append **NOTE: **we can add append structures to a table only via menu. **we can create a structure in another structure is called nested structure. **we can add maximum of 9 structures to a table. Creation of external structure: Goto SE11. Select data type and provide structure name (same as creation of table). Create. 26 Kiran

SAP-ABAP
Select structure *component is nothing but the field. *component type is nothing but the data elemenT. Double click on data elemenT.

After creating structure save and activate. Go back to the table and include this structure. *.include should be placed under the field and provide structure name under Data Element.

Save+check+activate.

27 Kiran

SAP-ABAP

CREATION OF APPEND(or)INTERNAL STRUCTURE: Go to (ex:ZTHILAK_EMP) table. Go with the menu and go to append structure. Give the internal (or) append structure name Give the component and component type.

28 Kiran

SAP-ABAP

29 Kiran

SAP-ABAP

NOTE: **APPEND structures are mainly used to add new fields to a standard table. INDEX: Through index, we can search records faster or easier, When you create a table, the system automatically creates primary index. ie we cannot create the primary index. We can only create the secondary index. We can create maximum of 16-primary keys in a table. NOTE: *SAP recommends to give maximum of 16 indexes only, but if we want we can give more than that. Index is like a table but having minimized fields of table. The data in the index always gets sorted. SAP recommends dont create more indexes because that consumes lots of memory. CREATION OF INDEX: Go to table and click on index. Provide index name.

30 Kiran

SAP-ABAP
Provide short description. Click on table fields and select the fields which you want.

Creation of Search Helps:


Two types of Search Helps are available in SAP-ABAP. 1. Elementary Search Help : Elementary search helps describe a search path. The elementary search help 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 search help) and how the online input help should be defined (online behaviour of the search help). Collective Search Help : Collective search helps combine several elementary search helps. Collective search help thus can offer several alternative search paths.

2.

Elementary Search Help: Table Name is : ZTEST_03.

Go with create option

31 Kiran

SAP-ABAP

Select Elementary Search help and Continue

Save and Activate it. Execute : F8.

32 Kiran

SAP-ABAP

Now you can select the values from Search Help.

33 Kiran

SAP-ABAP
Description of fields: Selection method: name of table or view where the data is stored. Text table: Filled in by system, if a text table is attached to the selection method. Dialog type: Determines whether the user is presented with a selection screen before the hit list is displayed. Possible values: A Dialog depends on set of values. If there are more than 100 hits, a selection screen is displayed. Otherwise, the hit list is displayed immediately. D - Display values immediately. C Dialog with value restriction. A selection screen is always displayed. Hot key: allows user to type a shortcut into the field to bypass selection of elementary search help. Search help exit: - specify the name of a function module to be called during the search help process (more later). Search help parameters: Specify the names of parameters to be passed in / out, or additional fields to be used as filters for data. IMP: Check this box to indicate that the field is an input field, that is, to be passed to the search help. EXP: Check this box to indicate that the field is an output field, that is, to be passed from the search help to the screen. LPOS: The position of the as it appears in the hit list. SPOS: The position of the field as it appears in the selection screen. SDIS: Causes the field to be display only in the selection screen. Data element: Sets the attributes of the search help parameter. Normally filled in by the system. MOD: Check this box to assign a different data element than the one supplied by the system. Default value: Specify the default value in one of 3 ways: a literal(in quotes), a parameter ID(ZRD), or a system field (SY-UNAME).

34 Kiran

SAP-ABAP

Assign ZTEST_01 search help to field:

Put the cursor on which you are gonna to assign the Search Help and Go with Srch Help Push button.

Provide the Search Help Name which we created (ZTEST_01).

35 Kiran

SAP-ABAP

Go with Continue.

And go with Copy option. U can find the below message on Status Bar.

Check and Activate it. Go with Contents Button (Cntrl+Shift+F10).

36 Kiran

SAP-ABAP

U can find Search Help Switch now. Just select that using F4 key. U can find the below screen.

Create another Elementary Search Help i.e ZTEST_02.

Creation of Collective Search Help:

37 Kiran

SAP-ABAP

Continue.

Provide the Short Description and Fields with data elements. Go with the TAB : Included Search Helps.

Provide two Elementary Search Helps which we created now. 38 Kiran

SAP-ABAP
Save and Activate it. Now go with F8(Execute).

U can find 2 Tabs each one is Elementary Search Help (ZTEST_01, ZTEST_02).

In the same you can assign this Collective Search help to required field as Elementary Search Help(As above).
Diff Between Elementary search helps & Collective search helps 1) Elementary search helps describe a search path. The elementary search help 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 search help) and how the online input help should be defined (online behavior of the search help). 2) Collective search helps combine several elementary search helps. Collective search help thus can offer several alternative search paths. 3) An elementary search help defines the standard flow of an input help. 4) A collective search help combines several elementary search helps. The user can thus choose one of several alternative search paths with collective search help. 5) A collective search help comprises several elementary search helps. It combines all the search paths that are meaningful for a field. 6) Both elementary search helps and other search helps can be included in a collective search help. If other collective search helps are contained in collective search help, they are expanded to the level of the elementary search helps when the input help is called.

39 Kiran

SAP-ABAP
PROGRAMMING We write programs in ABAP Editor. t.code for ABAP editor is SE38. ABAP editor is not a case sensitive. The statement ends with . *in the extreme left indicates the comment line. ABAP editor is a line editor and it executes line by line. The output of ABAP program is called LIST or SCREEN.

TYPES OF PROGRAMS: Executable program. Include program. Sub-routine pool program. Function group/function module. Module pool program. Class pool program. **NOTE: WRITE is the output statement. WRITE statement display the output on the LIST but not on the SCREEN.

CREATION OF A PROGRAM: Goto SE38. Provide program name. Create. Provide the title of the program. Type execute program. Status PSAP standard production program. Save + localobject

40 Kiran

SAP-ABAP

USE OF WRITE STATEMENT: Report ZPRG_WRITE. WRITE 'NEERAJ'. OUTPUT: Program on write statement

{Standard page heading} NEERAJ To remove standard page heading: REPORT ZPRG_WRITE NO STANDARD PAGE HEADING. WRITE 'NEERAJ'. NOTE: *To go to the next line provide /. *When we put , we should put column (:). EX: WRITE:/ 'AMIT',/ 'SUBRA PRAKASH'. OUTPUT: AMIT SUBRA PRAKASH NOTE: : chain operator. To get the spaces between two lines SKIPNO (ex-skip3) have to use. EX: WRITE / 'TILAK'. SKIP 3. WRITE:/ 'AMIT',/ 'SUBRA PRAKASH'. OUTPUT: Tilak OUTPUT: NEERAJ

AMIT SUBRA PRAKASH

To provide the spaces in the same line / no(ex:/ 50).

41 Kiran

SAP-ABAP
EX: WRITE:/50 'MOHIT'. OUTPUT: Mohit To provide the one name under another name then the keyword UNDER have to use. EX: WRITE:/ 'PRAVENDRA' UNDER 'MOHIT'.

OUTPUT :

Mohit Pravendra To provide the colour to text. EX : WRITE:/30 'SRINIVASAN' COLOR 1. Output :

WRITE:/30 'SRINIVASAN' COLOR 1 INTENSIFIED OFF. OUTPUT:

WRITE:/30 'SRINIVASAN' COLOR 1 INVERSE. OUTPUT:

**HOTSPOT: HOTSPOT is the keyword is used to change the symbol like hand symbol. EX: WRITE:/20 'ANANYA' COLOR 6 HOTSPOT.

42 Kiran

SAP-ABAP
OUTPUT

NOTE: When you take your curser to ANANYA that curser symbol will change to HAND symbol. QUICK INFO: Quick info is used to give the quotation. EX: WRITE:/50 'SWATI' COLOR 7 QUICKINFO 'Hi...How are you'. OUTPUT:

NOTE: When you take your cursor to swati that will display the quotation what we have given (ex:hi...how are you). *To provide the underline, the keyword ULINE has to use. EX: ULINE. ULINE /20(30). OUTPUT:

To change the input on the OUTPUT screen: EX: WRITE:/ 'YOUR INPUT HERE' INPUT. OUTPUT:

** here we can give any input here. When we scroll the page also if we dont want to scroll anything we have to use the NEW_LINE NO SCROLLING. EX: NEW-LINE NO-SCROLLING. WRITE:/20 'ANANYA' COLOR 6. NOTE: *If we scroll the page also ANANYA wont scroll. To get the SCROLLBAR we have to initialise the screen at the beginning of the program.

43 Kiran

SAP-ABAP
EX: LINE-SIZE 255. To give the check box the command checkbox have to use. EX: WRITE:/40 'INDIAN', 'ABC' AS CHECKBOX. ABC is the name of the checkbox. OUTPUT:

To disable the checkbox the keyword checkbox INPUT OFF have to use. WRITE:/40 'INDIAN', 'ABC' AS CHECKBOX INPUT OFF. OUTPUT:

NOTE: To see the ICONS available in SAP, go to initial screen and enter the ICON in the COMMAND FIELD. To get the icons on the output screen: INCLUDE <ICON>. WRITE:/50 ICON_RED_LIGHT AS ICON. WRITE: 60 ICON_GREEN_LIGHT AS ICON. WRITE: 70 ICON_CLOSED_FOLDER AS ICON. WRITE: 80 ICON_SYSTEM_CUT AS ICON. WRITE: 90 ICON_DELETE AS ICON.

OUTPUT:

44 Kiran

SAP-ABAP
PROGRAMS on WRITE statement: 1.Program on WRITE *&---------------------------------------------------------------------* *& Report ZPRG_WRITE *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------* REPORT ZPRG_WRITE NO STANDARD PAGE HEADING LINE-SIZE 255. WRITE 'NEERAJ'. WRITE / 'TILAK'. SKIP 3. WRITE:/ 'AMIT',/ 'SUBRA PRAKASH'. WRITE:/50 'MOHIT'. WRITE:/ 'PRAVENDRA' UNDER 'MOHIT'. WRITE:/30 'SRINIVASAN' COLOR 1. WRITE:/30 'SRINIVASAN' COLOR 1 INTENSIFIED OFF. WRITE:/30 'SRINIVASAN' COLOR 1 INVERSE. NEW-LINE NO-SCROLLING. WRITE:/20 'ANANYA' COLOR 6 HOTSPOT. WRITE:/50 'SWATI' COLOR 7 QUICKINFO 'Hi...How are you'. ULINE. ULINE /20(30). WRITE:/ 'YOUR INPUT HERE' INPUT. WRITE:/40 'INDIAN', 'ABC' AS CHECKBOX. WRITE:/40 'INDIAN', 'ABC' AS CHECKBOX INPUT OFF. INCLUDE <ICON>. WRITE:/50 ICON_RED_LIGHT AS ICON. WRITE: 60 ICON_GREEN_LIGHT AS ICON. WRITE: 70 ICON_CLOSED_FOLDER AS ICON. WRITE: 80 ICON_SYSTEM_CUT AS ICON. WRITE: 90 ICON_DELETE AS ICON.

45 Kiran

SAP-ABAP
OUTPUT:

DATA TYPES IN PROGRAMING: CHARECTER data type. NUMERIC data type. CHARECTER DATA TYPE: DATA TYPE C D T X DESCRIPTION character date time hexadecimal LENGTH IN BYTES 1 8 6 1 INITIAL VALUE Blank 00000000 000000 ------

46 Kiran

SAP-ABAP
NUMERIC DATA TYPE: DATA TYPE N I P F DESCRIPTION Numeric Integer Packed decimal Floating point LENGTH IN BYTES 1 4 8 8 INITIAL VALUE 0 0 0 0.0

The maximum DECIMAL places in the PACKED DECIMAL is 14. STRING XSTRING holds for bigger characters. holds for graphics.

We can defined a variables in TWO different ways. TYPES. DATA. ** If we define the variable as TYPE, no memory gets allocate to variable. ** If we define the variable as DATA ,the memory gets allocate to variable. SYNTAX for TYPES : TYPES <VARIABLE NAME> TYPE <DATA TYPE>. EX: TYPES A TYPE I. HERE: A I variable name. integer type.

NOTE: Memory doesnt allocate to the variable A.

47 Kiran

SAP-ABAP
SYNTAX for DATA : DATA <VARIABLE NAME> TYPE <DATA TYPE>. EX: DATA B TYPE I. HERE: B variable name. I integer type.

NOTE: Memory gets allocate to the variable B.

To initialise multiple variables with the same data types we can use chain operator(:). EX: DATA : A TYPE I, B TYPE I, C TYPE I. EX: DATA : NAME (30) TYPE C, CITY LIKE NAME. NAME(30) indicates that 30 characters gets allocate to NAME. When we give LIKE that also gets allocate the same size.

PROGRAMS ON DATA and TYPE:


REPORT ZPRG_VAR1 NO STANDARD PAGE HEADING.

DATA: A TYPE I, B TYPE I, C TYPE I. A = 100. B = 60. C = A + B. WRITE / c.

OUTPUT
160

48 Kiran

SAP-ABAP
To ASSIGNIING the VALUES directly to the VARIABLES: EX 1:
REPORT ZPRG_VAR1 NO STANDARD PAGE HEADING.

DATA: A TYPE I VALUE 100, B TYPE I VALUE 60, C TYPE I.

OUTPUT
160

C = A + B. WRITE / c.

EX 2:
REPORT ZPRG_VAR1 NO STANDARD PAGE HEADING.

DATA: A TYPE I VALUE 100, B TYPE I VALUE 60, C TYPE I.

OUTPUT
100 + 60=160

C = A + B. WRITE / A + B = c.

EX:
REPORT ZPRG_VAR1 NO STANDARD PAGE HEADING.

DATA: A TYPE I VALUE 100, B TYPE I VALUE 60, C TYPE I.

OUTPUT
100+60=160

C = A + B. WRITE / A color 1 '+' B color 2 '=' c color 3.

49 Kiran

SAP-ABAP
TO GIVE THE DECIMALS:
EX: REPORT ZPRG_VAR1 NO STANDARD PAGE HEADING.

DATA: A TYPE I VALUE 25, B TYPE I VALUE 3, C TYPE P DECIMALS 4.

OUTPUT
8.3333

C = A / B. WRITE /c.

STRING OPERATIONS: EX1:


REPORT ZPRG_VAR1 NO STANDARD PAGE HEADING.

OUTPUT
THILAK

DATA: name(30) TYPE c VALUE 'THILAK'. WRITE:/ name.

EX2:
REPORT ZPRG_VAR1 NO STANDARD PAGE HEADING.

OUTPUT
THI

DATA: name(30) TYPE c VALUE 'THILAK'. WRITE:/50(3) name.

NOTE: 50 is the spaces and 3 is the characters size.

EX 3:
REPORT ZPRG_VAR1 NO STANDARD PAGE HEADING.

OUTPUT
THILAK

DATA: name(30) TYPE c VALUE 'THILAK'. WRITE:/ name RIGHT-JUSTIFIED.

50 Kiran

SAP-ABAP
EX 3:
REPORT ZPRG_VAR1 NO STANDARD PAGE HEADING.

OUTPUT
THILAK

DATA: name(30) TYPE c VALUE 'THILAK'. WRITE:/ name CENTERED.

Concatenation: EX:
REPORT ZPRG_VAR1 NO STANDARD PAGE HEADING.

DATA: name1(30) TYPE c VALUE 'THILAK', name2(30) TYPE c VALUE 'KORLEPARA', name3(60) type c. CONCATENATE name1(6) name2(9) INTO name3. WRITE name3.

OUTPUT
THILAKKORLEPARA

TRANSLATE: EX:
REPORT ZPRG_VAR1 NO STANDARD PAGE HEADING.

OUTPUT thilak

DATA: name(10) type c VALUE 'THILAK'. TRANSLATE name to LOWER CASE. write: / name.

RETRIEVEING DATA FROM DATA BASE: We retrieve data from data base tables by SELECT statement. ABAP supports two kinds of statements those are NATIVE SQL statements. OPEN SQL statements.

51 Kiran

SAP-ABAP
**Even if you change the data in the data base, OPEN SQL statements runs without any problem.

Comparison Operators in Where Condition with Select Statement: operator EQ = NE <> LT < LE <= GT > GE >= Meaning Equals Equals Does not equal Does not equal less than less than Less than or equal to Less than or equal to greater than greater than Greater than or equal to Greater than or equal to

Values in Intervals:
To find out whether the value of a column lies within a particular interval, use: SELECT... WHERE s NOT BETWEEN f1 AND f2...

Comparing Strings
To find out whether the value of a column matches a pattern, use: SELECT... WHERE s NOT LIKE f . The condition is true if the value of the column s matches [does not match] the pattern in the data object f. You can only use this test for text fields. The data type of the column must be alphanumeric. f must have data type c. You can use the following wildcard characters in f: % for a sequence of any characters (including spaces). _ for a single character.

Checking Lists of Values


To find out whether the value of a column is contained in a list of values, use: SELECT... WHERE s NOT IN (f1,......, fn)... The condition is true if the value of column s is [not] in the list f1 fn .

Checking Selection Tables


To find out whether the value of a column satisfies the conditions in a 52 Kiran
selection table, use:

SAP-ABAP
SELECT... WHERE s NOT IN seltab... The condition is true if the value of s [does not] satisfy the conditions stored in seltab. seltab can be either a real selection table or a RANGES table. You cannot check a selection table in the ON condition of the FROM clause.

Checking for Null Values


To find out whether the value of a column is null, use: SELECT... WHERE s IS NOT NULL... The condition is true if the value of s is [not] null.

Tabular Conditions
The WHERE clause of the SELECT statement has a special variant that allows you to derive conditions from the lines and columns of an internal table: This variant is as follows: SELECT... FOR ALL ENTRIES IN itab WHERE cond...
WORK AREA: WORK AREA is a small memory created inside the RAM in the APPLICATION SERVER. The data in the WORK AREA is not permanent. The data in the WORK AREA gets overwrite. WORK AREA can hold only one record at a time. WORK AREA is also called as FIELD STRING. EX:

ENO 100

ENAME ABC

ECITY Bang Fig: ZEMP (WA) ENO ENAME ECITY OUTPUT 100 ABC BANG 101 CDE HYD 102 DEF CHE

101 102

CDE DEF

HYD CHE

fig: ZEMPX1

53 Kiran

SAP-ABAP
EX: Data:gt_itab type standard table of ZEMPX1, Gwa_itab type ZEMPX1. SELECT * from ZEMPX1 into table gt_itab. Loop at gt_itab into gwa_zemp. Write: / gt_itab-ENO, gt_itab -ENAME, gt_itab -ECITY. Endloop. NOTE: transaction code is nothing but interface. To see the person from particular city then we can use where condition. SELECT * from zempx1 into gt_itab where ECITY = bang. Loop at gt_itab into gwa_zemp. Write: / gt_itab-ENO, gt_itab -ENAME, gt_itab -ECITY. Endloop. OUTPUT: 100 ABC BANG To see the records between the range: SELECT * from ZEMPX1 into gt_itab WHERE ENO BETWEEN 100 AND 102. Loop at gt_itab into gwa_zemp. Write: / gt_itab-ENO, gt_itab -ENAME, gt_itab -ECITY. Endloop. OUTPUT: 100 ABC BANG 101 CDE HYD 102 DEF CHE CORRESPONDING FIELDS OF: When the number of fields retrieved by the SELECT statement and the number of fields of WORK AREA are not same, then we have to use the CORRESPONDING FIELDS OF key word in the SELECT statement. When we use CORRESPONDING FIELDS OF key word in the SELECT statement, the table FIELD NAMES and the WORK AREA FIELD NAMES should be the same.

54 Kiran

SAP-ABAP
EX :
SELECT * FROM ZEMPX1 INTO CORRESPONDING FIELDS OF table gWA_itab. Loop at gt_itab into gwa_itab. WRITE:/ gWA-Eno, gWA-ENAME, gWA-ECITY, gWA-PHONE. Clear:gwa_itab. Endloop.

PROVIDING THE VALUES AT RUN TIME: PARAMETERS. SELECT-OPTIONS. PARAMETERS: PARAMETERS allows the user to provide single input value at runtime on a SELECTION SCREEN. SYNTAX: Parameters <variable-name> TYPE <data type>.

TO ACCESS THE TABLE FIELDS: SYNTAX: Parameters <variable-name> LIKE <database/ structure field name>.

SELECT-OPTIONS: SELECT-OPTIONS allows the user to provide two input value at runtime on a SELECTION SCREEN (range of values). The left value is called LOW value. The RIGHT value is called HIGH value. When we use SELECT-OPTIONS in the program, system automatically creates an internal table with four fields. LOW. HIGH. SIGN. OPTION.

55 Kiran

SAP-ABAP
SYNTAX: SELECT-OPTIONS <field-name> for <database table/ structure field name>. PARAMETERS: A TYPE I, B TYPE I, C TYPE I. C = A + B. WRITE / C. OUTPUT On the selection screen A B 50 50 execute(F8).

On the list 100. NOTE: The name of the parameter and select-option should not cross 8-characters. PARAMETERS EMP_NO TYPE ZEMPX1-ENO. DATA:gwa_itab type zempx1. SELECT single * FROM ZEMPX1 INTO CORRESPONDING FIELDS OF WA WHERE ENO = EMP_NO. WRITE: / GWA_ITAB-ENO, GWA_ITAB-ENAME, GWA_ITAB-ECITY. EX-2: SELECT-OPTIONS EMP_NO FOR ZEMPX1-ENO. DATA: GT_ITAB TYPE TABLE OF ZEMPX1. SELECT * FROM ZEMPX1 INTO CORRESPONDING FIELDS OF WA WHERE ENO IN EMP_NO. LOOP AT GT_ITAB INTO GWA_ITAB. WRITE: / GWA_ITAB-ENO, GWA_ITAB-ENAME, GWA_ITAB-ECITY. CLEAR:GWA_ITAB. ENDLOOP

**INTERNAL TABLE Internal tables provide a means of taking data from a fixed structure and storing it in working memory in ABAP. The data is stored line by line in memory, and each line has the same structure. In ABAP, internal tables fulfill the function of arrays. Internal tables are advanced than field strings(WA). It can hold multiple records at a time.

56 Kiran

SAP-ABAP
*When we use ITAB that indicates that header of the internal table. *When we use ITAB[ ] indicates that body of the internal table. Internal table has BODY and HEADER. Internal table header is also called work area. Internal table header can hold only one record at a time. The data in the internal table header always gets overwrite. We can pass data to the output from internal table through header only. We can create internal table without header also. When the internal table does not have header, we need to create header explicitly (or) assign the field symbol. TYPES OF INTERNAL TABLES: STANDARD. SORTED. HASHED.

STANDARD INTERNAL TABLE: STANDARD INTERNAL TABLE records have index numbers, so index assigning is possible. This internal table also have key access. Key access is not unique default. Standard internal table follows linear-search.

Standard This is the most appropriate type if you are going to address the individual table entries
using the index. Index access is the quickest possible access. You should fill a standard table by appending lines (ABAP APPEND statement), and read, modify and delete entries by specifying the index (INDEX option with the relevant ABAP command). The access time for a standard table increases in a linear relationship with the number of table entries. If you need key access, standard tables are particularly useful if you can fill and process the table in separate steps. For example, you could fill the table by appending entries, and then sort it. If you use the binary search option (BINARY) with key access, the response time is logarithmically proportional to the number of table entries. SORTED INTERNAL TABLE: SORTED INTERNAL TABLE records have index numbers, so index assigning is possible. This internal table also have key access. Key access is Unique Key or Non-Unique Key. Sorted internal table follows binary-search.

57 Kiran

SAP-ABAP
The data in the internal table gets automatically gets sorted in the ascending order based on the key-field name. This is faster than standard internal table in searching. This is the most appropriate type if you need a table which is sorted as you fill it. You fill sorted tables using the INSERT statement. Entries are inserted according to the sort sequence defined through the table key. Any illegal entries are recognized as soon as you try to add them to the table. The response time for key access is logarithmically proportional to the number of table entries, since the system always uses a binary search. Sorted tables are particularly useful for partially sequential processing in a LOOP if you specify the beginning of the table key in the WHERE condition.

HASHED INTERNAL TABLE: HASHED INTERNAL TABLE records does not have index numbers, so index assigning is not possible. This internal table also have key access. Key access is always Unique.. hashed internal table is faster than the sorted internal table. This is the most appropriate type for any table where the main operation is key access. You cannot access a hashed table using its index. The response time for key access remains constant, regardless of the number of table entries. Like database tables, hashed tables always have a unique key. Hashed tables are useful if you want to construct and use an internal table which resembles a database table or for processing large amounts of data.

SYNTAX TO CREATE STANDARD INTERNAL TABLE: TYPES: BEGIN OF <Structure Name>,

END OF <Structure Name>. DATA:<INTERNAL TABLE NAME> TYPE STANDARD TABLE OF <Structure Name>, <Work Area Name> TYPE <Structure Name>. NOTE: APPEND is used to fetch the data from header to body. LOOPAT is used to fetch the data from body to header. Declaration: CREATING A STRUCTURE: TYPES:BEGIN OF TP_ITAB , ENO LIKE ZEMPX1-ENO, ENAME LIKE ZEMPX1-ENAME, structure

58 Kiran

SAP-ABAP
ECITY LIKE ZEMPX1-ECITY, END OF TP_ITAB. DATA:ITAB TYPE STANDARD TABLE OF TP_ITAB, WA_ITAB TYPE TP_ITAB. SELECT eno ename ecity FROM zempx1 INTO TABLE itab. LOOP AT itab INTO wa_itab. WRITE: / wa_itab-eno, wa_itab-ename, wa_itab-ecity. CLEAR:wa_itab. ENDLOOP.

TABLE KEYWORD IN THE SELECT STATEMENT: When we use TABLE keyword in the select statement, all the required data from database will be retrieved into the ITAB body with the SINGLE hit in the database. By this we can avoid the load in the database.

SYNTAX TO CREATE SORTED INTERNAL TABLE: DATA <INTERNAL TABLE NAME> LIKE SORTED TABLE OF <DATABASE TABLE/STRUCTURE> WITH UNIQUE/ NON-UNIQUE KEY <KEY FIELD NAME> WITH HEADERLINE.

SYNTAX TO CREATE HASHED INTERNAL TABLE: DATA <INTERNAL TABLE NAME> LIKE STANDARD TABLE OF <DATABASE TABLE/STRUCTURE> WITH UNIQUE KEY <KEY FIELD NAME> WITH HEADERLINE. ANOTHERWAY: TYPES: BEGIN OF TY_ITAB, INCLUDE STRUCTURE ZEMPX1, END OF TY_ITAB.

INTERNAL TABLE COMMANDS: CLEAR. REFRESH. FREE.

COLLECT

59 Kiran

SAP-ABAP
APPEND.

INSERT. DELETE.

MODIFY SORT. READTABLE. LOOPAT. CLEAR: It removes the data present in the internal table header. REFRESH: It removes the data present in the internal table body and the memory allocates remains same. FREE: It removes the data present in the internal table body and the memory allocated to it gets free. APPEND: It is used to copy the data from internal table header to body generically. COLLECT: It copies the data from internal table header to the body generically, when the similar record is processed again it over writes the character values and integer values gets added. INSERT: Insert the record from header to body between the existing records based on the index number. DELETE; It is used to delete the existing record from internal table body based on the index number. MODIFY: It is used to modify the existing record present in the internal table body based on index number. If there is no record, modify wont work. SORT: It is used to sort the internal table in ascending order by default based on the field name. To change it to descending order just add a keyword descending.

60 Kiran

SAP-ABAP
SOME STANDARD TABLES: KNA1 Customer master table. LFAI vendor master table. VBAK sales document header table. VBAP sales document item table. MARA material master table. MAKT material description table. MARC plant data for material. MARD storage location data for material. EKKO purchasing document header table. EKPO purchasing document item table. VBUP sales document item status. VBUK sales document header status. VBEP sales document scheduling data. BNKA bank master table. LNBK customer bank details. LFBK vendor master bank details. T001 company codes. T002 language keys. T005 countrys. SBOOK single flight booking. SFLIGHT flight details table. SPFLI flight schedule table.

TRANSACTION CODES related to END-USERS and FUNCTIONALS: MM01 Create material. MM02 Change material. MM03 Display material. XD01 Create customer. XD02 Change customer.

61 Kiran

SAP-ABAP
XD03 Display customer. XK01 Create vendor. XK 02 Change vendor. XK 03 Display vendor. MES1N Create purchase requisition. MES2N Change purchase requisition. MES3N Display purchase requisition. ME21N Create purchase order. ME22N Change purchase order. ME23N Display purchase order. VA11 Create enquiry. VA12 Change enquiry. VA13Display enquiry. VA21 Create quotation. VA22 Change quotation. VA23 Display quotation. VA01 Create sales order. VA02 Change sales order. VA03 Display sales order. VF01 Create delivery. VF02 Change delivery. VF03 Display delivery. VL01 Create bill. VL02 Change bill. VL03 Display bill.

62 Kiran

SAP-ABAP
ABAP SYSTEM FIELDS: These are the pre-defined fields provided by SAP for developer to decrease the complexity of programs and these fields helps a lot while coding. ABAP system fields holds data at run time. All ABAP System field name starts with SY-

SY-MANDT holds CLIENT NUMBER.. SY-UNAME holds CURRENT USER NAME. SY-LANGU HOLDS LOG-IN LANGUAGE. SY-DATUM HOLDS SERVER DATE. SY-UZEIT HOLDS CURRENT SERVER TIME. SY-PAGNO PAGE NUMBER. SY-REPID PROGRAM NAME. SY-TCODE TRANSACTON CODE. SY-DBCNT NUMBER OF RECORDS RETRIEVED FROM THE DATABASE BY THESELECT STATEMENT (it automatically RESETS to 1 after the execution of other events). SY-DBSYS DATABASE NAME. SY-TFILL NUMBER OF ROWS OF THE INTERNAL TABLE. SY-INDEX LOOP INDEX NUMBER. SY-TABIX CURRENT INTERNAL TABLE INDEX NUMBER. SY-DYNNR CURRENT SCREEN NUMBER. SY-CPAGE CURRENT PAGE NUMBER OF THE LIST. SY-LSIND LIST INDEX NUMBER. SY-UCOMM USER COMMANDS OR FUNCTIONAL CODES. SY-SUBRC: If SY-SUBRC is equal to0, then the condition is TRUE. If SY-SUBRC is not equal to 0, then the condition is FALSE. *All the SYSTEM FIELDS are available in the structure called SYST.

63 Kiran

SAP-ABAP
VARIANTS: VARIANT is the PRE-DEFINED INPUT value. VARIANTS plays very important role in the BACKGROUND JOB SCHEDULING. After creating a variant system creates a button in the APPLICATION TOOL BAR at SELECTION SCREEN called GET VARIENT BUTTON.

NOTE: before creating VARIANT, the program should be in ACTIVE. CREATION OF VARIANT: Provide program name. Create Click on attributes. Provide Meaning ex: customers from 1000 to 1500. Save. ONLY FOR BACKGROUND PROCESS: It is used in the BACK GROUND PROCESSING not in the FORE GROUND (this is not displayed in the VARIANT CATALOGUE ). ATTRIBUTES: The ATTRIBUTES of a program provides PROGRAM TITLE. ORIGINAL LANGUAGE. DATE OF CREATION. CHANGE USER NAME WHO HAS CREATED. CHANGE PROGRAM STATUS. PROGRAM TYPE. AUTHORISATION GROUP. PACKAGE NAME. LOGICAL DATABASE NAME,etc...., EDITOR LOCK ANOTHER USERS CAN NOT EDIT THE PROGRAM.

64 Kiran

SAP-ABAP
DOCUMENTATION: Documentation provides the some information about the report. When we create the documentation for a PROGRAM, system creates the button in the application toolbar at the SELECTION SCREEN called PROGRAM DOCUMENTATION button. When user click on the button, the system opens the window called PERFORMANCE ASSISTANCE WINDOW. TEXT ELEMENTS: Text elements provides TEXT SYMBOLS. SELECTION TEXTS. LIST HEADINGS. COLUMN HEADINGS. to provide UNDERLINE in the selection screen just provide the UNDERLINE in the SELECTION SCREEN. ex: SELECTION-SCREEN ULINE. JOINS: Through JOINS we can retrieve data from two or more tables at a time. To retrieve data from two or more tables, there should be a common field in both tables. Joins are TWO TYPES: INNER JOIN. LEFT OUTER JOIN. INNER JOIN: Inner join retrieves data from two different tables when there is a common record in the common field.

EX:
REPORT ZPROG_JOINS.

TABLES kna1. SELECT-OPTIONS cust FOR kna1-kunnr DEFAULT 1000 TO 2000. TYPES: BEGIN OF itab , kunnr LIKE kna1-kunnr, land1 LIKE kna1-land1, name1 LIKE kna1-name1,

65 Kiran

SAP-ABAP
vbeln erdat netwr waerk LIKE LIKE LIKE LIKE vbak-vbeln, vbak-erdat, vbak-netwr, vbak-waerk,

END OF itab. DATA:i_itab TYPE TABLE OF itab, wa_itab TYPE itab. SELECT kna1~kunnr kna1~land1 kna1~name1 vbak~vbeln vbak~erdat vbak~netwr vbak~waerk INTO TABLE i_itab FROM kna1 LEFT OUTER JOIN vbak ON kna1~kunnr = vbak~kunnr WHERE kna1~kunnr IN cust ORDER BY kna1~kunnr. FORMAT COLOR 2. LOOP AT i_itab INTO wa_itab. WRITE:/ wa_itab-kunnr COLOR 4, wa_itab-land1, wa_itab-name1, wa_itab-vbeln COLOR 7, wa_itab-erdat, wa_itab-netwr, wa_itabwaerk COLOR 3. CLEAR:wa_itab. ENDLOOP. ULINE. WRITE:/ sy-dbcnt.

LEFT OUTER JOIN:


When there is a common record in the common field and also all the left table records even though there is no common record in the right table so it put NULL values in the RIGHT SIDE. CONTROL BREAKS(internal table events): It controls the flow of execution of program in an internal table loop.

66 Kiran

SAP-ABAP
STATEMENTS: AT FIRST.

ENDAT. AT LAST.

ENDAT.

AT NEW <FIELD NAME>.

ENDAT.

AT END OF <FIELD NAME>.

ENDAT.

ON CHANGE OF <internal table-field name>.

ENDON.

SUM. AT FIRST: AT FIRST event executes before processing the first record from internal table. AT LAST: AT LAST event executes after processing last record from the internal table. AT NEW<FIELD NAME>. This event executes when ever new record is gonna to process AT END OF <FIELD NAME>. This event executes after group of similar group records.

67 Kiran

SAP-ABAP
ON CHANGE OF <ITAB-FIELD NAME> This event executes when ever change occurs. SUM This event is used to add integer values inside the internal table. NOTE: LOOP executes based on the number of RECORDS. REPORT zss_test LINE-SIZE 255 NO STANDARD PAGE HEADING.

TABLES kna1. SELECT-OPTIONS cust FOR kna1-kunnr DEFAULT 1000 TO 1003. TYPES: BEGIN OF itab , kunnr LIKE kna1-kunnr, land1 LIKE kna1-land1, name1 LIKE kna1-name1, vbeln erdat netwr waerk LIKE LIKE LIKE LIKE vbak-vbeln, vbak-erdat, vbak-netwr, vbak-waerk,

END OF itab. DATA: i_itab TYPE TABLE OF itab, wa_itab TYPE itab. SELECT kna1~kunnr kna1~land1 kna1~name1 vbak~vbeln vbak~erdat vbak~netwr vbak~waerk INTO TABLE i_itab FROM kna1 JOIN vbak ON kna1~kunnr = vbak~kunnr WHERE kna1~kunnr IN cust ORDER BY kna1~kunnr.

LOOP AT i_itab INTO wa_itab. AT FIRST. FORMAT COLOR 1. WRITE:/ 'Customer and their Sales Report'. ENDAT. AT NEW kunnr. WRITE:/ wa_itab-kunnr COLOR 2. ENDAT. FORMAT COLOR 4. WRITE:/15 wa_itab-land1, wa_itab-name1, wa_itab-vbeln, wa_itab-

68 Kiran

SAP-ABAP
erdat, wa_itab-netwr, wa_itab-waerk COLOR 3. AT END OF kunnr. ULINE. SKIP. SUM. FORMAT COLOR 5. WRITE:/55 'Net Value of Customer', wa_itab-netwr. ENDAT. AT LAST. FORMAT COLOR 6. SUM. WRITE:/55 'Grand Total of Customer', wa_itab-netwr. ENDAT. CLEAR:wa_itab. ENDLOOP.

MESSAGE CLASS: Message class is a dictionary of messages. Message class can store 1000 messages and it starts from ooo to 999. We can give messages in different languages also. Messages are REUSABLE. We call message class is the program by using a keyword MESSAGE-ID <message class name>.

TYPES OF MESSAGES: I INFORMATION MESSAGE.

E ERROR MESSAGE. W WARNING MESSAGE. S A STATUS MESSAGE. ABEND MESSAGE.

69 Kiran

SAP-ABAP
X EXIT MESSAGE.

INFORMATION MESSAGE: Information message displays in dialogue box. When this message is active, the program stops execution by pressing ENTER key, program starts execution. ERROR MESSAGE Error message displays in status bar in the RED color. When this message is active, the program stops execution by pressing ENTER key , program will not continue its execution. WARNING MESSAGE: Warning message also displays in status bar in YELLOW color. When this message is active, the program stops execution by pressing ENTER key , program continue its execution. STATUS MESSAGE: Statusmessage also displays in status bar in GREEN color. When this message is active, the program will not stops execution . ABEND MESSAGE: Abend message displays in DIALOGUE BOX. When this message is active, the user have only one option to EXIT (un saved data will be lost). EXIT MESSAGE: Exit message is for error analysis, when it is active program control goes to ABAP run time error also called dump analysis. T.CODE is ST22 for ABAP run time errors, we can go to debugging also. This message provides information lines WHAT HAPPENED. WHAT CAN WE DO. MESSAGE. MESSAGE CLASS NAME. MESSAGE NUMBER. PROGRAM NAME. TRANSACTION CODE.

70 Kiran

SAP-ABAP
CLIENT NUMBER. USER NAME. LANGUAGE. OPERATING SYSTEMS NAME. DATABASE NAME. IP ADDRESS. WORK PROCESS NAME etc..., CREATION OF MESSAGE CLASS (SE91) Goto SE91. Provide the message class name.

Provide short text. Save+local object. Click on message tab. EX:

Program on message classes


REPORT
ZPRG_MESS_CLASS NO STANDARD PAGE HEADING MESSAGE-ID ZMSCL1.

TABLES kna1. SELECT-OPTIONS cust FOR kna1-kunnr. TYPES: BEGIN OF itab , kunnr LIKE kna1-kunnr, land1 LIKE kna1-land1, name1 LIKE kna1-name1, END OF itab.

71 Kiran

SAP-ABAP
DATA: i_itab TYPE TABLE OF itab, wa_itab TYPE itab. AT SELECTION-SCREEN. IF cust-low IS INITIAL AND cust-high IS INITIAL. MESSAGE e000. ELSEIF cust-low IS INITIAL OR cust-high IS INITIAL. MESSAGE w001. ELSEIF cust-low < 1000 OR cust-high > 2000. MESSAGE x002. ENDIF. START-OF-SELECTION. SELECT kunnr land1 name1 FROM kna1 INTO TABLE i_itab WHERE kunnr IN cus t. IF sy-subrc = 0. MESSAGE i003 WITH sy-dbcnt. ELSE. MESSAGE s004. ENDIF. FORMAT COLOR 3 INTENSIFIED OFF. LOOP AT i_itab INTO wa_itab. WRITE:/ wa_itab-kunnr COLOR 3 INTENSIFIED ON, wa_itab-land1, wa_itabname1. CLEAR:wa_itab. ENDLOOP.

72 Kiran

SAP-ABAP
Modularization: Dividing the complexity of the program into number of sub-units is called Modularization. Advantages of Modularization: Easy error handling . Reusability of code. Performance of the program increases. Modularization Techniques: Include Program. Sub-routine pool Program. Functional Group/Module. Classes & Methods. Include Program: Include program is the one of the programming type. Include programs do not execute, when they are independent. To execute the include program, we need to call it from the MAIN PROGRAM. Include programs are REUSABLE. We can call one include program into another include program. SYNTAX to call one include program into another include program is INCLUDE <INCLUDE PROGRAM NAME>. CREATION OF INCLUDE PROGRAM: Goto SE38. Provide name Select INCLUDE PROGRAM.

Ex:
TABLES lfa1. SELECT-OPTIONS vendor FOR lfa1-lifnr. TYPES: BEGIN OF itab , lifnr LIKE lfa1-lifnr, land1 LIKE lfa1-land1, name1 LIKE lfa1-name1, END OF itab.

73 Kiran

SAP-ABAP
DATA: i_itab TYPE TABLE OF itab, wa_itab TYPE itab. SELECT lifnr land1 name1 FROM lfa1 INTO TABLE i_itab WHERE lifnr IN ven dor. Sub Routine pool: Sub Routine pool is also one of the program type. Sub routine pool programs do not execute when they are independent. Sub routine pool program is a mini program which we define at the end of the main program. A subroutine is an internal modularization unit within a program, to which you can pass data using an interface. You use subroutines to encapsulate parts of your program, either to make the program easier to understand, or because a particular section of coding is used at several points in the program. Your program thus becomes more function-oriented, with its task split into different constituent functions, and a different subroutine responsible for each one.

SYNTAX to CREATE SUB ROUTINE: FORM<SUBROUTINE NAME>.

ENDFORM. PERFORM is the KEYWORD to call the SUB ROUTINE from MAIN PROGRAM.

SYNTAX to call the SUB ROUTINE from MAIN program: PERFORM <SUB ROUTINE NAME>. The variables defined in the sub routines are local variables, their visibility exists only with subroutine. These VARIABLES can not access out side the Subroutine. Hence, sub routines are LOCAL UNITS. NOTE: The name of the subroutine should not cross 30 characters. We can not create a sub routine in another sub routines, but we can call sub routine from another sub routine. The statements after the sub routines can not be accessible.

74 Kiran

SAP-ABAP
If we want to still access those statements then we need to use an event called START-OF SELECTION. TYPES OF SUB ROUTINES: SUB ROUTINES are of TWO TYPES. INTERNAL SUBROUTINES. EXTERNAL SUBROUTINES. INTERNAL SUB ROUTINES. Sub routines and its perform statements are in the same program, then the sub routines are called INTERNAL SUBROUTINES. EXTERNAL SUB ROUTINES: Sub routines and its perform statements are in the different program, then the sub routines are called EXTERNAL SUBROUTINES. SYNTAX: PERFORM <SUBROUTINE NAME> (PROGRAM NAME). EXECUTION SEQUENCE: 1 2 3 PERFORM SUB1. 4 5 6 FORM SUB1. 7 8 9 END FORM.

THE EXECUTION WILL BE 1 2 3 6 7 8 9 4 5 Ex: program on subroutine.


WRITE / 'PEPSI'. PERFORM sub1. WRITE / 'SPRITE'. *&---------------------------------------------------------------------* *& Form SUB1

75 Kiran

SAP-ABAP
*&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM sub1. PERFORM sub2. WRITE:/ 'MAAZA'. ENDFORM. "SUB1 *&---------------------------------------------------------------------* *& Form SUB2 *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM sub2. WRITE:/ 'SLICE'. ENDFORM. "SUB2 START-OF-SELECTION. WRITE / 'THUMS UP'.

Ex-2: Program on nested sub routine.


REPORT ZPRG_SUB2.

WRITE / 'NIMBOOZ'. PERFORM SUB1(ZPRG_SUB1). PERFORM SUB2 IN PROGRAM ZPRG_SUB1. WRITE / 'TRIPICANA LEECHI'.

76 Kiran

SAP-ABAP
NOTE:
We can terminate the sub routine by using CHECK. EXIT. PASSING VARIABLES THROUGH SUBROUTINE: USING is the keyword to pass variables through subroutine. SYNTAX: PERFORM <SUBROUTINE NAME> USING< ACTUAL PARAMETERS>. FORM <SUBROUTINE NAME> USING <FORMAL PARAMETERS>.

ENDFORM. Parameters with PERFORM statement are called ACTUAL PARAMETERS. Parameters with SUBROUTINE are called FORMAL PARAMETERS.(OR) Parameters with FORM statement are called FORMAL PARAMETERS. ACTUAL PARAMETERS have DEFAULT MEMORY and also ACTION. Where as FORMAL PARAMETERS do not have MEMORY BY DEFAULT. The number of actual parameters should be same as the number of formal parameters.

CALL BY VALUE:
Calling by value: During a subroutine call, the formal parameters are created as copies of the actual parameters. The formal parameters have memory of their own. Changes to the formal parameters have no effect on the actual parameters. REPORT ZPRG_SUB3.

DATA: a TYPE i VALUE 100, b TYPE i VALUE 200, c TYPE i. PERFORM sub1 USING a b. c = a + b. WRITE / c. *&---------------------------------------------------------------------* *& Form SUB1 *&---------------------------------------------------------------------*

77 Kiran

SAP-ABAP
FORM sub1 USING value(e) TYPE i value(f) TYPE i. DATA g TYPE i. e = e / 2. f = f / 2. g = e + f. WRITE / g. ENDFORM.

"SUB1

CALL BY REFERENCE:
Calling by reference: During a subroutine call, only the address of the actual parameter is transferred to the formal parameters. The formal parameter has no memory of its own, and we work with the field of the calling program within the subroutine. If we change the formal parameter, the field contents in the calling program also changes.

EX: program on call by reference.


REPORT ZPRG_SUB3TIL.

DATA: a TYPE i VALUE 100, b TYPE i VALUE 200, c TYPE i. PERFORM sub1 USING a b. c = a + b. WRITE / c. *&---------------------------------------------------------------------* *& Form SUB1 *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->E text * -->F text *----------------------------------------------------------------------* FORM sub1 USING e f. DATA g TYPE i. e = e / 2. f = f / 2. g = e + f. WRITE / g. ENDFORM. "SUB1

78 Kiran

SAP-ABAP
CALL- BY-VALUE-RESULT:
Calling by value and result: During a subroutine call, the formal parameters are created as copies of the actual parameters. The formal parameters have their own memory space. Changes to the formal parameters are copied to the actual parameters at the end of the subroutine. CHANGING is the keyword to return the values for the subroutine to the main program. SYNTAX: PERFORM <SUBROUTINE NAME> CHANGING< ACTUAL PARAMETERS>. FORM <SUBROUTINE NAME> CHANGING<FORMAL PARAMETERS>.

ENDFORM. EX:
REPORT ZPRG_SUB4.

DATA a TYPE i VALUE 100. PERFORM sub1 CHANGING a. WRITE / a. *&---------------------------------------------------------------------* *& Form SUB1 *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->VALUE(B) text *----------------------------------------------------------------------* FORM sub1 CHANGING value(b). b = b / 2. WRITE / b. ENDFORM. "SUB1

NOTE:
CALL-BY-VALUE RESULT will not gets change until the system finishes the execution of the subroutine. HOW TO TERMINATE: DATA: a TYPE i, b TYPE i. a = 25. b = 3. PERFORM sub1 USING a b. a = 45. b = 0.

79 Kiran

SAP-ABAP
PERFORM sub1 USING a b. a = 33. b = 6. PERFORM sub1 USING a b. *&---------------------------------------------------------------------* *& Form SUB1 *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->E text * -->F text *----------------------------------------------------------------------* FORM sub1 USING e f. IF f = 0. EXIT. ENDIF. DATA c TYPE p DECIMALS 2. c = e / f. WRITE / c. ENDFORM. PASSING INTERNAL TABLES THROUGH SUBROUTINE: We can pass internal tables to subroutines through call by reference only. SYNTAX: PERFORM <SUBROUTINE NAME> TABLES <INTERNAL TABLE NAME USING < PARAMETERS>. ACTUAL

FORM <SUBROUTINE NAME> TABLES<INTERNAL TABLE NAME USING<FORMAL PARAMETERS>.

ENDFORM. NOTE: While creating EXTERNAL SUBROUTINE, we have to select SUBROUTINEPOOL. Function Group : A function group is a collection of logically related modules that share global data with each other. All the modules in the group are included in the same main program. When an ABAP/4 program contains a CALL FUNCTION statement, the system loads the entire function group in with the program code at runtime. Every function module belongs to a function group.

Function Modules: Function modules are advanced than subroutines. T.CODE for function builder is SE37. Before creating a function builder, first we need to create a function group.

80 Kiran

SAP-ABAP
All the related function modules will stores in a functional group. Function module name is reserved for SAP. All the function modules of functional groups can access the data. Function module is a block of code can import data from main program, Process that imported data and can export the result back to the main program.

Function Modules have: IMPORT. EXPORT. CHANGING. TABLES. EXCEPTION. PARAMETERS. EXCEPTION HANDLING is possible through FUNCTION MODULE. **RAISE is the key word to handle EXCEPTIONS through the FUNCTION MODULE. Function modules are 3 Types: NORMAL Function Module. REMOTE ENABLED Function Module. UPDATE Function Module. Normal function module works with in the system. Remote enabled function module works across the system(Land Scape). Update Function Module: The system performs the module processing asynchronously. Instead of carrying out the call immediately, the system waits until the next database update is triggered with the COMMIT WORK command. There is a difference between a Subroutine and Function Module. 1. Subroutines have no Exceptions Parameters. FM have Exceptions parameters to catch the exceptions. 2. Subroutines can be accessed locally i.e. local Modularization Unit. FM have Global Access i.e. they are Global Modularization Unit. 3. Subroutines can not be tested independently. FM can be tested independently. 4. Subroutines Explicitly wont return any values. FM explicitly returns values.

81 Kiran

SAP-ABAP
5. Subroutines is not remote Enables. FM can be made Remote Enables and can be called from non-SAP systems. 6. Optional parameters cannot be in Subroutines. FM can be defined with optional Parameters. they can both return values. FMs are mainly used when a routine is to be performed by many programs. Subroutines (forms) are generally only executed within one program. You can perform routines from other programs, but it's not often done. both forms and FMs are reusable modularization units. To distinguish we generally say that forms are used for internal modularization and FMs are used for external modularization. To decide on which to implement, consider whether you need the content to be used just for a limited program or whether it can be called from many independent programs. For the first purpose it is better to implement a form whereas for the second we implement an FM. However, ABAP does not isolate the usage context. That is; you can call a form from another program within whose code the form is not actually implemented. However, this requires attention since the form may utilize global variables. The same issue holds for FMs. FMs are encapsulated in function groups and function groups may have global variables that can be globally used by all FMs inside it. Types of Reports in ABAP: 1. 2. 3. 4. 5. 6. Classical Reports Interactive Reports ALV Reports(Noraml/Interactive) Logical Database Reports(LDB Reports) ABAP Query Reports (For Functionals) Report Painter/Writer(For FI Functionals)

Events in an ABAP/4 Report Program Events are actually used to organize the statements and control the flow of the program. If the program contains no explicitly defined event blocks, all the statements in the program form the entire event block START-OF-SELECTION. ABAP runtime environment automatically introduces a STARTOF-SELECTION at the first execution line. ABAP/4 report programs are event driven programs. Following events are triggered in a report.

82 Kiran

SAP-ABAP
LOAD OF PROGRAM. - If propgram is of type Executable, M, F, or S; then LOAD-OF-PROGRAM is trigerred first and then INITIALIZATION. The purpose of load of program is to load the program into system memory so that the program can be executed. INITIALIZATION. - just once. AT SELECTION-SCREEN OUTPUT. - when there is selection-screen AT SELECTION-SCREEN. - when user interacts. START-OF-SELECTION. - when F8.This is the default event in ABAP. END-OF-SELECTION. - At the end EVENTS IN A CLASSICAL REPORT: 1. INITIALIZATION: This is triggered when the report is loaded in memory. 2. AT SELECTION-SCREEN OUTPUT: This is triggered when the selection screen is loaded in memory before being displayed. 3. AT SELECTION-SCREEN/<field> : This event is triggered before leaving the selection screen. 4. START-OF-SELECTION: This is the the first and default event for displaying the report. Data retrieval logic is written under this event. OUTPUT EVENT(5, 6): 5. TOP-OF-PAGE: This event is triggered every time a new page is started in the list. 6. END-OF-PAGE : This event is triggered every time the list data reaches the footer region of the page. 7. END-OF-SELECTION: This event is triggered after the START-OF-SELECTION is completed. This event is used when there is use of logical data base in the report. It is triggered in type Executable programs once the logical database completes reading all data i.e. all the selection is finished and before the list processor is started. This statement tells the server that all the database reading is completed and no more data reading is going to take place. END-OF-SELECTION is generally used for the summary/results of reports. In an executable program without logical data base, there is no need to implement the event block END-OF-SELECTION. After a program is executed by the user, the database is locked when it encounters a START-OFSELECTION statement and the lock is released when an END-OF-SELECTION statement is encountered (to maintain the consistency). Data selection is done between START-OF-SELECTION and END-OF-SELECTION. Now if we dont write the END-OF-SELECTION statement, the database will remain locked till the programs get terminated. Hence, the performance will be reduced. So it is always good practice to write END-OF-SELECTION statement after finishing the data selection from database. EVENTS IN AN INTERACTIVE REPORT: In addition of the above, the following events are possible in case of Interactive Reports. 1. Top of page during line selection : top of page event for secondary list. 2. At line-selection : every time user dbl-clicks(F2) on the list data.

83 Kiran

SAP-ABAP
3. At pF<key> : function key from F5 to F12 to perform interactive action on the list. 4. At user-command. ================================================== If you debug your report program from the ABAP editor screen then it triggers from

1. Initialization, 2.At Selection-screen, 3.Start-of Selection, 4.End-of Selection, 5.Top-of-page, 6.End-of-page. But if you debug from the selection-screen then it triggers from

1.At Selection-Screen, 2.Start-of-selection, 3.Top-of-page, 4.End-of-page. TYPES------------- USER DEFINED DATATYPES ARE DECLARED WITH TYPES STATEMENT TYPE-POOL-------------- IT IS A PROGRAM WITH A COLLECTION OF TYPES STATEMENTS. CAN BE CREATED IN DICTIONARY TYPE-POOLS-----------IT IS A COLLECTION OF TYPE-POOL s. I_SAVE = SPACE I_SAVE = 'U' I_SAVE = 'X' I_SAVE = 'A' Layouts cannot be saved. Only user-defined layouts can be saved. Only global layouts can be saved. Both user-defined and global layouts can be saved.

84 Kiran

Você também pode gostar