0% found this document useful (0 votes)
85 views131 pages

JK Notes

Uploaded by

sunindfra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views131 pages

JK Notes

Uploaded by

sunindfra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

SAP-ABAP

SAP - ABAP Jaya Kumar


(9246661213)
--------------------------------------------------------------------------------------------------------------------------------------------------------

SYSTEMS,APPLICATIONS & PRODUCTS in Data Processing

Functional Technical
consultants Consultants

MM,SD,PP,HR,FI,CO,QM..... BASIS & ABAP

-------------------------------------------------------------------------------------------------------------

NOTE: Performance or efficiency of an application depends on load on Data Base. To get


Maximum Efficiency SAP architecture is maintained in 3 TIER(layers) as follows.

SAP R/3 Architecture.(REAL TIME 3 TIER)

PS PRESENTATION LAYER SAP GUI

APS / AS APPLICATION LAYER ABAP PROCESSOR

DATA BASE
DBS BACKEND

Procedure to execute an object(table/program/transaction)

1.CREATE AN OBJECT (program/table/transaction)

2.SAVE (CTRL+S)-saving into a Package

3.CHECK (CTRL+F2)- syntax errors


4.ACTIVATE (CTRL+F3)-READY TO BE EXECUTED-saved into APS/AS

SAP OBJECTS:
1.STANDARD : Developed by SAP,

● DISPLAY MODE ONLY(read only),

● ACCESS KEY IS REQUIRED TO CHANGE,

● NAMES SHOULD STARTS WITH ’A’-‘X’.


EX: KNA1,XD01

2.CUSTOM:Developed by ABAP consultants

● DISPLAY & CHANGE MODES

● ACCESS KEY IS NOT REQUIRED

● NAMES SHOULD STARTS WITH Y / Z only


EX: ZEMPS,ZSCHOOL

TRANSACTION CODE(T-CODE) short cut to execute a program.

EX:

1.DATA DICTIONARY : SE11 to create data base tables

2.ABAP EDITOR : SE38 to create a program

3.PACKAGE BUILDER : SE21 to create a package

Note : TSTCT table for all available Tcodes in our SAP server.

LOGON DETAILS:

CLIENT : The highest node of a business hierarchy. it is a range between


000 to 999. 000 is default client(GOLDEN CLIENT).

800 is reserved for training purpose. i.e IDES system.

Project Landscape:

1.DEV(development) - implement/ coding

DEV QAS PRD


2.QAS(quality) - integration testing
3.PRD(production) - live server<---- end users

20e0a925

Package(Development class) used to store developed objects

1.Transportable : Package Builder (tcode:SE21). ZRAJESH

2.Non Transportable: Local object ( $TMP) $TMP

Note : BASIS consultants transports activated objects from one server to


another server using TR numbers.

Types of TR numbers(Transport Request number)

1.Workbench TR : Used by ABAP consultants

2.Customizing TR : Used by Functional consultants

Ex: B72K900061

NOTE : Only active objects can be transported

Note : TDEVC is a data base table maintains all available pakages

********************************************************

Advanced Business Application Programming


Language:
********************************************************

Programming in ABAP : ( ABAP 4 G/L) SE38(ABAP EDITOR)


ABAP is not case sensitive.

Each instruction must ends with dot (.) ----period


Each mathematical operator (+ - * ? =...)must contain one space on its both sides.

Ex: a = b.

Comments:

A line starts with ' * ' is a comment.

To comment sub line use ".

Ex:

*ADDING NUMBERS

Z = X + Y. " sum of x & y posted into z

Program Flow :

Header DEFINE X , Y ,Z
Declarations

Logic
Body LOGIC Z = X + Y.

Footer OUTPUT DISPLAY Z Output Statements

VARIABLE --->(TYPE OF DATA, SIZE OF DATA) } DATA TYPE

Variable is instance of a data type. Variable can holds the data(memory)

Data type is blue print of variables. Data type cannot holds data.
Data Types :(Elementary data types)

CHAR - C (ALPHANUMERIC) --any size----------DEFAULT

NUMC - N(0..9)----any size

INT - I (0..9)-------------------4 BYTES

DATS -----D YYYYMMDD (8 bytes)

STRING-------DYNAMIC MEMORY(@ run time)

FLOAT -----exponential values

PACKED------decimal values

STRUCTUREd DATA TYPES : 1. DATA ELEMENT 2.STRUCTURE 3.TABLE TYPE

NOTE : Default data type in ABAP is CHAR...Default size is 1


Initial value for integer variable is '0'.

Initial value for Character variable is ' '.(SPACE)

KEYWORDS(standard ABAP statements)


**********************************

1.DATA to define internal variable

2.PARAMETERS to define external variable

3.TYPES to create new data type

4.TYPE to copy properties from data type

5.LIKE to copy properties from variable

6.WRITE to display data on output screen (CONSOLE)

CHAIN OPERATOR( : ). used to link multiple statements with same keyword.

NEW LINE OPERATOR( / ) used to print data on next line.

IN SAP WE WRITE PROGRAMs IN ABAP EDITOR (SE38)


EXAMPLE :

REPORT ZUMA_PROG1 NO STANDARD PAGE HEADING.

DATA V1 TYPE I.
DATA V2 TYPE I.
DATA V3 TYPE I.

V1 = 90.
V2 = 80.

V3 = V1 + V2.

WRITE 'THE RESULT IS'.


WRITE V3.

***********************************************************

REPORT ZUMA_PROG1 NO STANDARD PAGE HEADING.

DATA :V1 TYPE I, V2 TYPE I, V3 TYPE I.

V1 = 90.
V2 = 80.

V3 = V1 + V2.

WRITE :'THE RESULT IS',/ V3.

************************************

REPORT ZUMA_PROG1 NO STANDARD PAGE HEADING.

PARAMETERS :V1 TYPE I OBLIGATORY,


V2 TYPE I DEFAULT 10.
DATA V3 TYPE I.

V3 = V1 + V2.

WRITE :'THE RESULT IS',/ V3.

System variables/ fields (SYST) SYST-XXXX / SY-XXXX

These are global and standard variables.

1.SY-DATUM : CURRENT DATE

2.SY-UZEIT :CURRENT TIME


3.SY-UNAME :CURRENT USER NAME

4.SY-MANDT : CURRENT LOG ON CLIENT

5.SY-DBSYS : CURRENT DATA BASE

6.SY-PAGNO : CURRENT PAGE NUMBER

7.SY-CPROG: CURRENT PROGRAM NAME

8.SY-SUBRC : returns ' 0 ' for successful execution any logic.

Returns Non 0(1,2,3,4…) for failure of an operation.

9.SY-DBCNT : returns number of records affected in db due to an sql statement

10.SY-INDEX : to generate index for normal loops like DO & WHILE.

11.SY-TABIX :to generate index for internal table loop.

*************************************************************************

CONTROLLING TECHNIQUES (Branching & Looping techniques)

1.Branching techs: (used to execute only one logic among multiple options)

IF , CASE

*********************IF***********************

IF condition.

----

ELSEIF condition.

---

ELSEIF condition.

-----

ELSE.

-----

ENDIF.

*******************CASE****************************

CASE parametername.

WHEN option1.
-----

WHEN option2.

-----

WHEN OTHERS.

-----

ENDCASE.

2.Looping techs:(one logic is executed for multiple times) DO & WHILE

1).Unconditional Looping: DO

DO n TIMES.

-----------------------

ENDDO.

2).Conditional Looping : WHILE

WHILE condition.

-----------------

ENDWHILE.

Note : SY-INDEX is called normal loop index can be used within the DO & WHILE loops
only

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

REPORT ZUMA_CNTL_TECHS NO STANDARD PAGE HEADING.

PARAMETERS GENDER.

IF GENDER = 'M'.
WRITE 'MALE'.
ELSEIF GENDER = 'F'.
WRITE 'FEMALE'.
ELSE.
WRITE 'INVALID INPUT'.
ENDIF.

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
PARAMETERS GENDER.

CASE GENDER.
WHEN 'M'.
WRITE 'MALE'.
WHEN 'F'.
WRITE 'FEMALE'.
WHEN OTHERS.
WRITE 'INVALID INPUT'.
ENDCASE.

######################################################################

DO 10 TIMES.
WRITE :/ SY-INDEX,'ABAP'.
ENDDO.

WHILE SY-INDEX < 6.


WRITE / SY-INDEX.
ENDWHILE.

STRING OPERATIONS

STRING is group of characters. Memory is allocated for strings dynamically.

DATA S1 TYPE STRING.

S1 = 'india'.

TRANSLATE S1 TO UPPER CASE.

WRITE S1.
ULINE.
DATA S2 TYPE STRING.
S2 = 'UMA SANKAR'.
CONDENSE S2 NO-GAPS.
WRITE S2.
ULINE.
DATA S3 TYPE STRING VALUE 'SAP-ABAP'.
DATA N1 TYPE I.
N1 = STRLEN( S3 ).

WRITE N1.
ULINE.
DATA S4 TYPE STRING.

CONCATENATE SY-DATUM SY-UNAME SY-DBSYS INTO S4 SEPARATED BY ','.

WRITE S4.
ULINE.
DATA S5 TYPE STRING VALUE '1234,UMA,HYD'.
DATA : EID TYPE STRING,
ENAME TYPE STRING,
CITY TYPE STRING.
SPLIT S5 AT ',' INTO EID ENAME CITY.
WRITE :/ EID,/ ENAME,/ CITY.
ULINE.

DATA S5 TYPE STRING VALUE '1234,UMA,HYD'.

DATA SNAME TYPE STRING.

SNAME = S5+5(3).

WRITE SNAME.
ULINE.

PARAMETERS PHONE(10).

IF PHONE CA 'ABCDEFGHIJKLMNOPQRSTUVWYZ'. WRITE 'INVALID INPUT'.


ELSE.
WRITE 'VALID INPUT'.
ENDIF.
ULINE.

PARAMETERS FILE(50).

SEARCH FILE FOR '.TXT'.

IF SY-SUBRC EQ 0.
WRITE 'VALID FILE'.
ELSE.
WRITE 'PLZ SELECT TEXT FILES'.
ENDIF.

PARAMETERS stdid(10) type n.


write stdid.
uline.
shift stdid left DELETING LEADING '0'.
write stdid.
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&

DATA DICTIONARY /
ABAP DICTIONARY(SE11)-DDic
DDic is a tool used to create data base objects.

1.data base table :

FIELDS

datatype

Sno SNAME QUAL ----->STRUCTURE

data record------> 1 RAM M.SC BODY TABLE


variable
2 RAJIV M.SC

3 JAY B.TECH

4 RAGHAV M.TECH
FIELD

BASIC DATATYPE DOMAIN


SIZE DATA ELEMENT
DESCRIPTIONS

FIELD :-------->(BASIC DATA TYPE , SIZE , DESCRIPTION)

DOMAIN -------> Technical properties like data type , size ,sign ,lower case, fixed values & ranges

DATA ELEMENT ------------> ALL PROPERTIES OF A FIELD----> DOMAIN + DESCRIPTIONS(schematic props)

TABLE

STRUCTURE BODY(data)

F1 F2 F3

DE1 DE2 DE3

DOMAIN + DESC

DTYPE+SIZE

domain (basic data type +


size)

DATA ELEMENT FIELD


+
Schematic Properties(Descriptions)

Standard Data Elements:


Ex:

1.KUNNR - Customer number

2.LIFNR - Vendor number

3.MATNR - Material number

4.ADRNR - Address number

5.NAME1 - name

6.ORT01 - city

7.LAND1 - country

8.TELF1 - telephone

9.STRAS - street number

10.BUKRS - company code

11.BUTXT - company name

12.NETPR - net price

******************************************************************************

TYPES OF DATA:

1.Organizational data : Company code T001

2.Master Data : Customer master data KNA1

3.Transactional Data : Sales items data VBAP

*****************************************************************************

DD01L : table for all domains

DD02L: table for all TABLES

DD03L:table for all fields

DD04L:table for all data elements


ex:

MANDT with data element MANDT( CLIENT DEPENDENT)

Functional Specification (F.S)

1.Table with student number, name & phone

2.It should be client specific( Client Dependent)

3.It should be application table

4. Student number should be unique and not null

5.It should hold master data only

6.Maintenance should be allowed

7.Enhancement should be allowed

8.Phone number must not be initial

Technical Specification:(T.S)

Table : Zstudents

Delivery Class : A

Data Class : APPL0( Master Data)


Maintenance : Allowed

Enhancement : Char & Numc are Allowed

Structure

Field key no initial DataElement Description

MANDT ' ' MANDT Client

Sno ' ' ZSTDNO Student Number

Sname NAME1 Name

Phone ' TELF1 Telephone


DATA BASE TABLE CREATION:

1.Delivery class : It defines type of data to be stored in this DB table

Ex: A - Application Table

C - Customizing Table

L - To store temporary data

2.Maintenance Allowed / Allowed with Restrictions : Changes in table data allowed or not

3.Data Class : It defines specific space for this table in DB

Ex : APPL0 : Master Data

APPL1 : Transactional Data

APPL2 : Organizational Dara

4.Size Category : It defines number of records to be stored in this table. It is a scale from 0-9

5.Buffering : Temporary memory storage. We can Buffer a DB table which with frequently read
operations.

6.FIELDS with Data Elements

7.Primary Key : To avoid duplicates & Null values. First field of a table must be a primary key.
One table can has up to 16 primary keys( Must be in sequential order)
STANDARD DATABASE TABLES:

CUSTOMER : KNA1 , KNB1, KNBK, KNB5,KNVV,....

VENDOR: LFA1,LFB1,LFMH,LFBK.......

MATERIAL: MARA,MARC,MARD,MAKT,....

SALES: VBAK,VBAP,VBUK,VBUP,VBRK,VBRP...

PURCHASE: EKKO,EKPO,....

DATA BROWSER:(SE16): It allows to display or change data records of a table directly ( No structure is visible)

*********************************************************************

Table Maintenance Generator(T.M.G) To maintain multiple records of a db table at a time

Authorization Group : The group of users who can maintain the table

Function Group : Provide table name as Function Group

1.ONE STEP : uses only one screen OVERVIEW SCREEN to maintain data.

2.TWO STEP : uses two screens SINGLE SCREEN & OVERVIEW SCREEN to maintain data.

NOTE : SM30 tcode to maintain data through TMG

**********************************************************************************

TO ADD NEW FIELDS TO EXISTING TABLES( Standard & Custom tables)

1.Include Structure : adding structure at any position(except primary keys)----> custom tables

STEP1 : To create a structure

STEP2 : Include the above structure to custom table at any position.

Note : Include structure can be added into multiple custom DB tables.

Newly added field of a DB table will not be added into TMG of that DB table automatically.

2.Append Structure : adding structure at only last position------> standard tables

---------------------------------------------------------------------------------------------------------------------------------------------------
FOREIGN KEY RELATIONSHIP : TO validate values being entered in child table with values set of check table /
parent table f.key relation
ZRESULTS

Sno Marks Rank

8
e
3

F.Key Table

1. Two fields to be linked must have same domain


Sno Sname Dob
2.Check table field must be primary key
1

2
VALUE TABLE : This info maintained in DOMAIN. While trying to maintain
Foreign key relation this value table will be proposed as parent table. we can 3
override this proposal. After Foreign key relationship only value table
4
becomes CHECK TABLE.

*********************************************************************************************

VIEWS : Copy of Data base tables. These are virtual tables. Views have no physical existence
in DB.

1.Projection view

2.Database View

3.Maintenance View

4.Help View

1.Projection view Projects required fields from a single DB table.

Note: Changes in Projection view updated into its basis table.

2.Database View Projects fields from multiple tables based on a joining condition( common
field)

Joining Condition ( KNA1 - KUNNR = KNBK - KUNNR )


KNA1 KNBK

KUNNR NAME1 ORT01 BANKS BANKL BANKN

ZCUST_BANKS ( DataBase View )

Note: Maintenance is not possible with Data Base views. It supports only inner join.

3.Maintanance view

4.Help view

*******************************************************************

Search Help : to provide list of possible entries for a screen element.


A search help can be linked to Data Elements , Table Fields , Parameters and Screen Elements.

We have 2 types of search helps.

1. Elementary Search Help

2. Collective Search Help (combination of multiple elementary search helps)

Note : HOT KEY is used to select a specific elementary search help from a collective search
help

*****************************************************************************************

Currency / Quantity fields : Expects reference field and table.

Currency Field must be defined with CURR data type. Its reference
field must be defined with CUKY data type.
Quantity Field must be defined with QUAN data type. Its reference
field must be defined with UNIT data type.

********************************************************
Indexes( primary & secondary) :
These are used to maintain data records of a table in sequential format. Data accessing time
reduces by extracting records using INDEXES.

We have 2 types of Indexes.

1.Primary Index: It is default and mandatory. It is automatically created by using primary key
fields.

2.Secondary Indexes : These can be created by using non key fields. We can create up to 6
secondary indexes for a DBTable.

****************************************************************************

Lock Objects :
It is used to lock or release a data base table data from other users.

Name of a lock object must starts with 'EZ' or 'EY'.

Lock mode is used to synchronize data access among all users.

1.WRITE /EXCLUSIVE LOCK MODE ( E ) : Only one user at a time can access table

2.READ / SHARED LOCK MODE( S ) : Multiple users can access at a time, but only one can edit

3.EXCLUSIVE BUT NOT CUMULATIVE LOCK MODE : One user can lock for only one time during a transaction

By activating a lock object 2 FMs are created.

1.' ENQUEUE_XXXX' - To lock the table

2.' DEQUEUE_XXXX' - To release the table

Note : SM12 - To view all locked entries.

Flow logic of program with LOCK OBJECT Functions

REPORT ZDEMO.
Call Function 'ENQUEUE_XXXX'. " to lock table access

DB operations.

--------------------

----------------------

Call Function 'DEQUEUE_XXXX'. " to unlock table

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

TYPES OF DATABASE TABLES

1.TRANSPARENT TABLE : Its default type of a database table. For each


transparent table of DDic , there will be one physical table in actual DB.

DDIC DB

Transparent table Physical Table

2.POOLED TABLE: Multiple pooled tables of DDic grouped into only one physical
table called TABLE POOL in actual DB.

pooled table1

Table Pool
Pooled Table2
Pooled Table 3

3.CLUSTER TABLE: Multiple cluster tables of DDic grouped into only one
physical table called TABLE CLUSTER in actual DB. Generally HR data maintained
in cluster tables. All cluster tables of a group must be having one common field.

Cluster Table1

Common P.key
Cluster Table 2 TABLE CLUSTER
Field

Cluster Table 3

Assignment
1.ZDOCTORS

DOCID ( 01 - 25 )-------key

DNAME

SPEC (C - CARDIO , O - ORTHO , G - GENERAL )

EXP

HNAME

ZADDRESS

STREET

CITY

PHONE

NOTE : Enter 10 entries thru TMG (Tcode)

2.ZPHARMA
MEDID ( 0001 - 5999)-------key

MNAME

MTYPE ( C - CAPSULE , I - INJECTION , S - SYRUP)

PRICE

QUANTITY

REF_DOC ( must be validated from ZDOCTORS)

DOE(DATE OF EXPIRY)

BNO(BATCH NUMBER)

NOte : enter 20 entries thru TMG

NOte : Both Tables must be client specific

3.ZMED_DOCS

Medid MNAME MTYPE PRICE DOE REF_DOC DNAME HNAME PHONE

1. DATA TYPE vs VARIABLE

2. DATA ELEMENT vs FIELD

3. STRUCTURE vs TABLE

1.ZCUSTOMERS(CUSTNR,NAME,CITY,COUNTRY,PHONE,EMAILID).

2.ZITEMS(ITEMID,INAME,ITYPE,MFGDATE,EXPDATE,MCOMP_NAME,PRICE).
3.ZSALES(SONR,SITEM,CR_DATE,CUSTNR,ITEMID,QNTY,NETPR)

INTERNAL TABLES(ITAB)

Sno Sname City Phone

1 Jay Delhi 98989898

2 Sandeep Dddf 44545

3 Manu Nj 98080

SELECT OPEN SQL

SNO SNAME CITY

SNO SNAME CITY


1.data base table

2.internal table creation,select data from dbt into itab

3.internal table operations

4.open sql(push data from itab into dbt)

Internal Table is runtime instance of Database Table.

Structure of Internal Table and DB table must be same.

Memory should be allocated to Itab dynamically.

The scope of Itab is within the program only(Temporary).

We can access data into Itab only through its Work area(Header Line).

ABAPer------->WA------->ITAB

ABAPer<-------WA<-------ITAB

ABAP

single row
work area

dbt internal table

multiple rows

1.Write a program to display Company Codes, Company Names and their


country codes of given Country
Technical spec:

Table : T001 (company codes)

Input : COUNTRY ( P_CNTRY TYPE LAND1)

FIELD D.E DESCRIPTION

BUKRS BUKRS COMPANY CODE

BUTXT BUTXT COMPANY NAME

LAND1 LAND1 COUNTRY

*&---------------------------------------------------------------------*
*& Report ZDEMO_ITAB1
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZDEMO_ITAB1 NO STANDARD PAGE HEADING.


*****************define structrue***********************
types begin of s1.
TYPES BUKRS type bukrs.
types butxt type butxt.
types land1 type land1.
types end of s1.
**************define wwork area***********************
data wa type s1.
************define itab*****************************
data it type table of s1.
******************fetch dbt---> itab******************
select bukrs butxt land1 from t001 into table it where land1 = 'IN'.
write :/ 'records fetched',sy-dbcnt.
uline.
***************display itab******************************
loop at it into wa.
write :/ sy-tabix,wa-bukrs,wa-butxt,wa-land1.
endloop.

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

*&---------------------------------------------------------------------*
*& Report ZDEMO_WA
*& KNA1
*&---------------------------------------------------------------------*
*&KUNNR
*&NAME1 ORT01 LAND1
*&---------------------------------------------------------------------*

WAP to display required customer's number,name,city and country.

If input is wrong throw error mesasage that 'No Data Found'.

Technical Info:

Table : KNA1( customer master general data)

Fields Descriprions

KUNNR Customer Number

NAME1 Customer Name

ORT01 City

LAND1 Country

Input : customer Number i.e KUNNR

SELECT STATEMENT WITH WORK AREA MUST BE CONCLUDED BY ENDSELECT.

IT CAN BE REPLACED BY SELECT SINGLE.

REPORT ZDEMO_WA NO STANDARD PAGE HEADING.

PARAMETERS CNO TYPE KNA1-KUNNR.


*****************DEFINE STRUCTURE******************
TYPES :BEGIN OF TY_KNA1,
KUNNR TYPE KNA1-KUNNR,
NAME1 TYPE KNA1-NAME1,
ORT01 TYPE KNA1-ORT01,
LAND1 TYPE KNA1-LAND1,
END OF TY_KNA1.
************DEFINE WORK AREA*************************
DATA WA TYPE TY_KNA1.
**************FETCH DBT---> WA*******************
SELECT SINGLE KUNNR NAME1 ORT01 LAND1 FROM KNA1 INTO WA WHERE KUNNR EQ CNO.
****************DISPLAY WA*********************
IF SY-SUBRC EQ 0.
WRITE : WA-KUNNR,WA-NAME1,WA-ORT01,WA-LAND1.
ELSE.
WRITE : 'NO DATA FOUND FOR',CNO.
ENDIF.
*ENDSELECT.
&*****************************************************************
REPORT ZDEMO_ITAB1 NO STANDARD PAGE HEADING.
*****************define structrue***********************
*types begin of s1.
* TYPES BUKRS type bukrs.
* types butxt type butxt.
* types land1 type land1.
*types end of s1.
TYPES S1 TYPE T001.
**************define wwork area***********************
data wa type s1.
************define itab*****************************
data it type table of s1.
******************fetch dbt---> itab******************
select bukrs butxt land1 from t001 into CORRESPONDING FIELDS OF table it where land1 = 'IN'.
*select * from t001 into table it where land1 = 'IN'.
write :/ 'records fetched',sy-dbcnt.
uline.
***************display itab******************************
loop at it into wa.
write :/ sy-tabix,wa-bukrs COLOR 3,wa-butxt COLOR 4,wa-land1 COLOR 5.
endloop.

***********************************************************************

TABLES : This keyword is used to define a work area with same name and structure of given
data base table.

Ex: TABLES KNA1.

******************************************************************************

1.WAP to display purchase order number , item ,material number and net prices of purchase
order numbers between '3000000000' and '400000000'.

2.WAP to display given material's Number , Language and descriptions.(Only English).

3.WAP to display all vendors numbers, names, cities, and countries details based on given city.
ITABS WITH ------

1.IMPLICIT WA (itab and wa defined with same names)


workarea

internal table
2.EXPLICIT WA ( itab & wa defined with different names)

**********************************************************
Standard Itab
TYPES OF INTERNAL TABLES
Indexed Itabs
Sorted Itab

Internal tables
Non Indexed Itab Hashed Itab

1.Standard itab:
It is default type of itab.

It is Indexed internal Table i.e index can be generated for this itab.

The data accessing time is varied with index of the record.

This must be defined with non unique field only.

Syntax:

DATA itabname TYPE STANDARD TABLE OF struturename WITH NON UNIQUE fieldname.
2.Sorted Itab:
It is indexed itab.

Data access time changes with index of the record.

It is sorted at the time of declaration only in default.

It cannot be sorted further.

It can be defined using unique or non unique field.

Syntax

DATA itabname TYPE SORTED TABLE OF structurename WITH UNIQUE / NON UNIQUE
fieldname.

3.Hashed Itab:
It is non indexed itab i.e index cannot be generated for records of itab i.e SY-TABIX is always 0
for Hashed Itabs.

Data access time is same for all records.

It must be defined using unique field only.

Syntax

DATA itabname TYPE HASHED TABLE OF structurename WITH UNIQUE fieldname.

DATA V1 TYPE I.

DATA V2 LIKE V1.

TYPE <existing data type name>.

LIKE <existing variable name>.

TYPES <new data type name>.

DATA <new internal variable name>.

PARAMETERS <new dynamic variable name>.


Internal Table Operations (WA<-------->ITAB)
DATA

work area
Append READ
internal table
insert,

collect

Modify,Delete,Sort,Describe,Delete Adjacent Duplicates

1.APPEND : Used to add a record from WA into ITAB at last position.

APPEND waname TO itabname.

2.INSERT : Used to add a record from WA into ITAB at required position.

INSERT waname INTO itabname INDEX position.

3.SORT : Used to arrange records of ITAB in ascending(DEFAULT) or descending order.

SORT itabname BY fieldname.

4.DELETE ADJACENT DUPLICATES FROM itabname COMPARING fieldname.

5.DESCRIBE : to get properties of an ITAB like type of itab, initial memory of itab and number
of records of itab.

DESCRIBE TABLE itabname LINES variablename.

6.MODIFY : to change values of itab records from work area

MODIFY itab FROM wa TRANSPORTING fieldnames WHERE condition.

7.READ : used to extract a specific single record from itab into wa.

READ TABLE itabname INTO waname INDEX position.

READ TABLE itabname INTO waname WITH KEY condition BINARY SEARCH.

*********************************************************************

COLLECT: used to add numeric values of similar character fields of an ITAB


SYNTAX: COLLECT waname INTO itabname.

***********************************************************************

REPORT ZWDEMO_COLLECT NO STANDARD PAGE HEADING.

types : begin of s1,


ename(10),
sal type i,
end of s1.

data wa type s1.


data it type table of s1.

wa-ename = 'RAM'.
WA-SAL = 1000.
*APPEND WA TO IT.
COLLECT WA INTO IT.

wa-ename = 'SYAM'.
WA-SAL = 2000.
*APPEND WA TO IT.
COLLECT WA INTO IT.

wa-ename = 'RAM'.
WA-SAL = 3000.
*APPEND WA TO IT.
COLLECT WA INTO IT.

wa-ename = 'SYAM'.
WA-SAL = 4000.
*APPEND WA TO IT.
COLLECT WA INTO IT.

LOOP AT IT INTO WA.


WRITE :/ WA-ENAME,WA-SAL.
ENDLOOP.

*&---------------------------------------------------------------------*
*& Report ZDEMO_ITAB1
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZDEMO_ITAB_OPERS NO STANDARD PAGE HEADING.

******************define structrue***********************
types begin of s1.
TYPES BUKRS type bukrs.
types butxt type butxt.
types land1 type land1.
types end of s1.
**************define wwork area***********************
data wa type s1.
************define itab*****************************
data it type table of s1.
******************fetch dbt---> itab******************
select bukrs butxt land1 from t001 into table it up to 5 rows.

**************display itab******************************
loop at it into wa.
write :/ sy-tabix,wa-bukrs COLOR 3,wa-butxt COLOR 4,wa-land1 COLOR 5.
endloop.
uline.
* *****************append******************
wa-bukrs = '1000'.
wa-butxt = 'igrow soft'.
wa-land1 = 'IN'.

append wa to it.

**************display itab******************************
loop at it into wa.
write :/ sy-tabix,wa-bukrs COLOR 3,wa-butxt COLOR 4,wa-land1 COLOR 5.
endloop.
uline.
******************insert********************
wa-bukrs = '2000'.
wa-butxt = 'micro soft'.
wa-land1 = 'US'.

insert wa into it index 2.


insert wa into it index 4.
insert wa into it index 6.

**************display itab******************************
loop at it into wa.
write :/ sy-tabix,wa-bukrs COLOR 3,wa-butxt COLOR 4,wa-land1 COLOR 5.
endloop.
uline.
***************sort*********************
sort it by bukrs.
**************display itab******************************
loop at it into wa.
write :/ sy-tabix,wa-bukrs COLOR 3,wa-butxt COLOR 4,wa-land1 COLOR 5.
endloop.
uline.
*************d a d************************
delete adjacent duplicates from it COMPARING bukrs.

**************display itab******************************
loop at it into wa.
write :/ sy-tabix,wa-bukrs COLOR 3,wa-butxt COLOR 4,wa-land1 COLOR 5.
endloop.
uline.
******************describe*************************
data n1 type i.
describe table it lines n1.

write :/ 'rows of itab',n1.


uline.
******************modify********************
wa-butxt = 'igrow soft pvt ltd'.

modify it from wa TRANSPORTING butxt where bukrs = '1000'.

**************display itab******************************
loop at it into wa.
write :/ sy-tabix,wa-bukrs COLOR 3,wa-butxt COLOR 4,wa-land1 COLOR 5.
endloop.
uline.
******************read***********************
* read table it into wa index 4.
read table it into wa with key bukrs = '1000' BINARY SEARCH.

write :/ wa-bukrs COLOR 3,wa-butxt COLOR 4,wa-land1 COLOR 5.

CLEAR / REFRESH / FREE :


CLEAR : It clears contents of all types of variables and sets initial values.

V1 = 100. --> CLEAR V1 .--> V1 = 0.

V2 = 'SAP'.--> CLEAR V2. --> V2 = ' '.

CLEAR variablename.

CLEAR waname.
CLEAR itabname.

wa & itab --------> DEMO.

CLEAR DEMO. " clear work area.

CLEAR DEMO[ ]. " clear itab body

REFRESH : can clears contents of internal table only

REFRESH itabname.

FREE : it clears memory (de allocates memory)

FREE variablename.

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

OPEN SQL : These are used to access data base tables. It supports DB portability.
WA------> DBT or ITAB---------------->DBT

Note : At the time of execution all Open SQL commands converted into corresponding Native
SQL commands by ABAP ENGINE.

ABAP
ABAP er
Consultant

WA INSERT(NEW)

UPDATE(OLD)
OPEN SQL
SY-DBCNT
MODIFY(NEW &
ITAB OLD)

DELETE(OLD)
SAP DB

insert(new),update(old),modify(new&old),delete(old)------>SY-DBCNT
INSERT: to insert only new records into data base table.

INSERT dbtname FROM waname. " single record

INSERT dbtname FROM TABLE itabname. " multiple records

INSERT dbtname FROM TABLE itabname ACCEPTING DUPLICATE KEYS.

UPDATE: to change existing records in data base table

UPDATE dbtname SET new values WHERE condition.

MODIFY : it acts as INSERT for new records and UPDATE for existing records.

MODIFY dbtname FROM waname.

MODIFY dntname FROM TABLE itabname.

Note : ' SY-SUBRC is always ZERO for MODIFY '.

DELETE: to delete existing records from data base table

DELETE dbtname FROM waname.

DELETE dbtname FROM TABLE itabname.

DELETE FROM dbtname WHERE condition.

*&---------------------------------------------------------------------*
*& Report ZDEMO_OPENSQL
*&

REPORT ZDEMO_OPENSQL NO STANDARD PAGE HEADING.

DATA wa type t001.


data it type table of t001.

wa-bukrs = '1510'.
wa-butxt = 'igrow soft'.
wa-land1 = 'in'.

append wa to it.

wa-bukrs = '1511'.
wa-butxt = 'Micro soft'.
wa-land1 = 'in'.

append wa to it.
insert t001 from table it ACCEPTING DUPLICATE KEYS.

write / sy-subrc.
write / sy-dbcnt.
uline.

update t001 set ort01 = 'Hyderabad' where bukrs = '1513'.

write / sy-subrc.
write / sy-dbcnt.
uline.

modify t001 from table it.

write / sy-subrc.
write / sy-dbcnt.
uline.

*delete dbtname from waname.


*delete dbtname from table itabname.
*delete from dbtname where condition.

CONTROL BREAK STATEMENTS : These are used to control loop of an internal table. These
statements must be used within the loop only. It is better to sort ITAB before using these statements.

1.AT FIRST : Executed only for once before processing first record of itab.

2.AT NEW fieldname : Executed before processing each new value of given field.

NOTE : The above 2 statements must be used before main write statement of loop.

3.AT END OF fieldname: Executed after processing all similar values of given field.

4.AT LAST: Executed after processing all records of itab.

Note : ON CHANGE OF fieldname


SUM : It is a function used to add all values of numeric fields of itab.
*****************************************************************************

JOINS: This concept is used to club multiple data base tables data into only one internal table ,based on a given
joining condition.

Generally we can use only 2 types of joins here.

1.INNER JOIN
2.LEFT OUTER JOIN

****************************************************************************

FOR ALL ENTRIES: It is similar to inner joins concept. It gives better performance than joins.

->It is mandatory to check whether it1 is initial or not before writing second Select statement.

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&

*& Report ZDEMO_FOR_ALL_ENTRIES1

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&
REPORT ZDEMO_FOR_ALL_ENTRIES1 NO STANDARD PAGE HEADING line-SIZE 1000.

types : begin of ty_kna1,


kunnr type kunnr,
name1 type name1,
ort01 type ort01,
land1 type land1,
end of ty_kna1.

data it_kna1 type table of ty_kna1.


data wa_kna1 type ty_kna1.

types : begin of ty_knbk,


kunnr type kunnr,
banks type banks,
bankl type bankl,
bankn type bankn,
end of ty_knbk.

data it_knbk type table of ty_knbk.


data wa_knbk type ty_knbk.

types:begin of ty_final,
kunnr type kunnr,
name1 type name1,
ort01 type ort01,
land1 type land1,
banks type banks,
bankl type bankl,
bankn type bankn,
end of ty_final.
data it_final type table of ty_final.
data wa_final type ty_final.

PARAMETERS p_land1 type kna1-land1.

select kunnr
name1
ort01
land1
from kna1
into table it_kna1
where land1 = p_land1.

if it_kna1 is not initial. " this condition is mandatory with F.A.E


select kunnr
banks
bankl
bankn
from knbk
into table it_knbk
FOR ALL ENTRIES IN it_kna1
where kunnr = it_kna1-kunnr.
endif.

loop at it_knbk into wa_knbk.


read table it_kna1 into wa_kna1 with key kunnr = wa_knbk-kunnr.

wa_final-kunnr = wa_kna1-kunnr.
wa_final-name1 = wa_kna1-name1.
wa_final-ort01 = wa_kna1-ort01.
wa_final-land1 = wa_kna1-land1.
wa_final-banks = wa_knbk-banks.
wa_final-bankl = wa_knbk-bankl.
wa_final-bankn = wa_knbk-bankn.

append wa_final to it_final.


clear :wa_final,wa_kna1,wa_knbk.
endloop.

*******************display final data*****************************


loop at it_final into wa_final.

write :/ sy-tabix,wa_final-kunnr, wa_final-name1,wa_final-ort01,wa_final-land1,


wa_final-banks,wa_final-bankl, wa_final-bankn.

endloop.

*******************************************************************

TABLE TYPE: It is a data type , to define internal table directly( with out TABLE OF
keyword).

SYNTAX 1: TYPES tabletypename TYPE TABLE OF structurename.

DATA itabname TYPE tabletypename.

Ex : TYPES tabtype1 TYPE TABLE OF strname.

DATA itabname TYPE tabtype1.

SYNTAX 2: TYPES tabletypename TYPE structurename OCCURS n.

DATA itabname TYPE tabletypename.

**********************************************
DATA A TYPE B.
**********************************************
*
CASE 1. If B is a basic data type (C/I/D/N...) or a data element
(KUNNR/ BUKRS/EBELN....)......

Then A acts as single variable ...i.e

CASE 2. If B is a structure

Then A acts as field string or work area .


CASE 3. If B is a table type

Then A acts as an internal table..

All possible operations in ABAP program:

data base
SELECT SINGLE

OPEN SQL
OPEN SQL

work area

SELECT INSERT
READ
APPEND
COLLECT Internal
MODIFY
table

SORT , DELETE ADJACENT


DUPLICATES, DECRIBE...

PROGRAM

Modularization Techniques(Subprograms)
---Reusability

SUBPROGRAM ---------------- Definition & Calling

Definition SUB1

Z = X + Y.
Formal Parameters

Calling 50 60 ting

call sub1

exp x = 50,y = 60

imp z.
50 60 Actual Parameters

Note :

1.actual & formal parameters must have same properties

2.number of formal & actual parameters must be same.

Types of sub programs:

1.Include programs

2.Macros

3.Subroutines(Forms)

4.Function Modules(FM)

5.Methods (OBJECT ORIENTED)

NOTE : Purpose of subprograms is REUSABILITY

Include programs : Can be included into all types of programs.


Syntax : INCLUDE inclprogname.

Note : Include programs allows no formal parameters

Example:

REPORT Z5PMS_ITAB1 NO STANDARD PAGE HEADING.

include z5pms_decls.

include z5pms_display.

**************************************************************

Macros : Generally used for arithmetic operations


In a main program, definition of a macro first and called next.

Can use up to 9 formal parameters only (&1,&2,&3......&9).

Can be called within the program only.

Macro cannot be called from one program to another.

*&---------------------------------------------------------------------*
*& Report ZDEMO_MACROS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZDEMO_MACROS NO STANDARD PAGE HEADING.

*****************definition*****************
define adds.
&3 = &1 + &2.
write &3.
uline.
end-of-DEFINITION.

****************calling*************************
data v1 type i.
adds 10 30 v1.
adds 37 39 v1.
adds 44 87 v1.

*****************************************************************************

REPORT Z5PMS_MACROS_TEST NO STANDARD PAGE HEADING.

**************to display 10 records of itab***************


include zdisplay_10rows.
uline.
******************macro definition***************
define get_row.
read table it into wa index &1 .
write : wa-bukrs,wa-butxt,wa-land1.
uline.
end-of-DEFINITION.

*************call macro***************************
get_row 2.
get_row 4.

get_row 6.

************************** Subroutines(FORMS)*************************
FORM ---- definition

PERFORM ------ CALLING subroutine

Note : In a main program it should be called first and defined next.

It Can be called from one program to other programs.

we can pass parameters by following key words:

1.USING : to pass input variables

2.CHANGING : to pass output variables

3.TABLES : to pass only internal tables

EXAMPLE 1

REPORT ZDEMO_SUBS NO STANDARD PAGE HEADING.


PARAMETERS p1 type kunnr.
data wa1 type kna1.

************calling*******************
perform get_cust using p1 changing wa1.
write : wa1-kunnr,wa1-name1,wa1-land1.

************definition******************
form get_cust using cno type kunnr
changing wa type kna1.
select single * from kna1 into wa where kunnr = cno.
endform.

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&

EXAMPLE 2

REPORT ZDEMO_SUBS_EXT NO STANDARD PAGE HEADING.

parameters p_kunnr type kunnr.


data ls_kna1 type kna1.
PERFORM GET_CUST IN PROGRAM zdemo_subs USING P_KUNNR CHANGING LS_KNA1.

write : ls_kna1-kunnr,ls_kna1-name1,ls_kna1-ort01.

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&

REPORT ZDEMO_SUBS_TABLES NO STANDARD PAGE HEADING.


PARAMETERS p1 type ebeln.
data it1 type table of ekpo.
data wa type ekpo.
perform get_pos tables it1 using p1.

loop at it1 into wa.


write :/ wa-ebeln,wa-ebelp,wa-matnr,wa-netpr.
endloop.

form get_pos tables it STRUCTURE ekpo using pono type ebeln.


select * from ekpo into table it where ebeln = pono.
endform.

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&

NOte :Subroutines cannot be called across servers.

Subroutines cannot handles exceptions.

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&

FUNCTION MODULES:(FM)
->global sub programs

->can be called across servers

->can handle exceptions


FMs should be saved into function groups only

Function Groups must be activated.

Function Builder(SE37).

IMPORTING : To pass input variables

EXPORTING : To pass output variables

TABLES : To pass internal Tables (with implicit work area)

CHANGING : To pass a variable which can acts as input & output variable

EXCEPTIONS : To define custom exceptions

REPORT ZDEMO_CALL_FM NO STANDARD PAGE HEADING.

PARAMETERS p1 type kunnr.


data wa1 type kna1.

formal parameters
CALL FUNCTION 'ZGET_CUST'
EXPORTING
CNO = p1
IMPORTING actual parameters
WA = wa1
.

write : wa1-kunnr,wa1-name1,wa1-land1.

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&

REPORT ZDEMO_DLOAD NO STANDARD PAGE HEADING.

data it type table of kna1.

select * from kna1 into table it up to 10 rows.

CALL FUNCTION 'GUI_DOWNLOAD'


EXPORTING
FILENAME = 'D:\CUSTOMERS.TXT'
APPEND = 'X'
WRITE_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = IT
.
IF SY-SUBRC EQ 0.
WRITE :/ 'FILE DOWNLOADED SUCCESSFULLY'.
ENDIF.

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

MESSAGES : to display text on current screen


Message types :

1.i information

2.w warning

3.a abort

4.s success

5.e error

6.x exit
Local & Global messages:(Based on scope of a message)

local messages can be used within the program only

Syntax:

MESSAGE 'text to be displayed' TYPE 'msgtype'. " msgtype must be in upper case

Global Messages:

These can be called into all programs.

Global messages can be defined in a Message Class(SE91).

One message class can contains up to 1000 messages(000 - 999).

Syntax to call a global message

MESSAGE e002(Z8AM).
REPORT ZDEMO_MESSAGES NO STANDARD PAGE HEADING.

PARAMETERS cname(10).

AT SELECTION-SCREEN.
if cname = 'SAP'.
message 'WELCOME TO SAP' TYPE 'I'.
ELSE.
MESSAGE 'INVALID COURSE NAME' TYPE 'E'.
ENDIF.

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@

T100 Table with standard messages

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&

Global messages: can be created in message class(SE91).

one message class can've up to 1000 messages(000 - 999).

These can be called into all programs.


REPORT ZDEMO_MESSAGES NO STANDARD PAGE HEADING.

PARAMETERS cname(10).

AT SELECTION-SCREEN.
if cname = 'SAP'.
message i001(zsankar).
ELSE.
MESSAGE e002(zsankar) with cname.
ENDIF.

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&

REPORT ZDEMO_MESSAGES NO STANDARD PAGE HEADING MESSAGE-ID zsankar.

PARAMETERS cname(10).

AT SELECTION-SCREEN.
if cname = 'SAP'.
message i001.
ELSE.
MESSAGE e002 with cname.
ENDIF.

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
BUSINESS DOCUMENTS

1.REPORTS(LISTS)======> ALV REPORTS


* Internal use documents

* Display data on console

* Printing is optional

2.FORMS(scripts)======>SMARTFORMS
* External use documents

* Display data on printed pages

* Printing page is mandatory

REPORT with recent OLTP (ONLINE TRANSACTIONAL


transactional data PROCESS)
SAP R/3 DB

REPORT WITH HISTORICAL


WAREHOUSING(BI) DATA

(DATA CUBES)
OLAP(ONLINE ANALYTICAL PROCESS)

***********************************************************************

REPORTS(Lists)
*These are Business docs for internal purpose of an org

* Analyze our business transactions

* used to display SUMMARIZED DATA based on user requirement

Report flow logic:

source code selection output screen

-------- screen/ input report screen

---------- screen
SELECTION SCREEN (NUMBER 1000)

* PARAMETERS

*SELECT OPTIONS(Ranges)

*CHECK BOXES

*RADIO BUTTONs

NOTE : TEXT ELEMENTS supports language conversions

REPORT ZDEMO_SSCREEN NO STANDARD PAGE HEADING.

SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.


PARAMETERS C1 AS CHECKBOX.
PARAMETERS C2 AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE TEXT-002.
PARAMETERS R1 RADIOBUTTON GROUP Z1.
PARAMETERS R2 RADIOBUTTON GROUP Z1.
SELECTION-SCREEN END OF BLOCK B2.

IF C1 = 'X'.
WRITE :/ 'COURSE IS ABAP'.
ENDIF.

IF C2 = 'X'.
WRITE :/ 'COURSE IS SD'.
ENDIF.

IF R1 = 'X'.
WRITE :/ 'MODE IS CLASS ROOM TRAINING'.
ELSE.
WRITE :/ TEXT-003.
ENDIF.

select - options: it can take range or multiple input values.

TO TO
It is an internal table with implicit work area.(Internally)

Select options structure

1.LOW

2.HIGH

3.SIGN (Include / Exclude) :default = I

4.OPTION (BT/NB/EQ/NE/...) :default = BT

Select options can be defined using existing variable only.

syntax:

SELECT-OPTIONS name FOR existing variablename.

case1 : DATA V1 TYPE I.

SELECT-OPTIONS S1 FOR V1.

case2 : DATA WA TYPE T001.

SELECT-OPTIONS S2 FOR WA-BUKRS.

case3 : TABLES KNA1. "CREATES ONLY WORKAREA with given DBtable name

SELECT-OPTIONS S3 FOR KNA1-KUNNR.

NOTE: If select options is initial ,then all records will be fetched thru select statement.

***********************************************************************

ATTRIBUTES OF SELECT-OPTIONS :

1.NO-EXTENSION : To remove multiple selection property

2.NO INTERVALS : To avoid ranges property

*************************************************************************

REPORT ZDEMO_SOPTIONS NO STANDARD PAGE HEADING.

data wa type t001.


data it type table of t001.

*PARAMETERS p1 type bukrs.


select-options s1 for wa-bukrs no-extension no intervals.
select * from t001 into table it where bukrs in s1.
loop at it into wa.
write :/ wa-bukrs,wa-butxt,wa-land1.
endloop.

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

EVENTS : Events are executed based on priority order or action. Starting of an event is
ending of previous event.

Types of Reports:(output screens)


1.Classical Report

2.Interactive Report (drill down reports)

sourcecode selection screen report


1 2 3 4 5 6 7 8 9 10

Classical reports: Total data displays in single report

LOAD OF PROGRAM (internal event)

1.INITIALIZATION (bfore selection screen)

2.AT SELECTION-SCREEN OUTPUT

3.AT SELECTION-SCREEN ON field with in i/p screen

4.AT SELECTION-SCREEN

5.AT SELECTION-SCREEN ON VALUE-REQUEST FOR field

6.AT SELECTION-SCREEN ON HELP-REQUEST FOR field

7.START-OF-SELECTION (after selection screen)

8.END-OF-SELECTION (to display output)

9.TOP-OF-PAGE (to print header)

10.END-OF-PAGE (to print footer)

#############################################################################

REPORT ZDEMO_CREPORTS NO STANDARD PAGE HEADING LINE-COUNT 10(1).

selection-screen begin of block b1 with frame.


PARAMETERS p1 type bukrs.
PARAMETERS p2 type butxt.
selection-screen skip 2.
select-options s1 for p1.
selection-screen end of block b1 .

data wa type t001.


data it type table of t001.

INITIALIZATION.

select single bukrs into p1 from t001 where butxt = 'SAP A.G.'.

S1-LOW = '0001'.
S1-HIGH = '6000'.
S1-SIGN = 'I'.
S1-OPTION = 'BT'.
APPEND S1 TO S1.

AT SELECTION-SCREEN ON P1.

SELECT SINGLE BUKRS INTO P1 FROM T001 WHERE BUKRS = P1.

IF SY-SUBRC NE 0.
MESSAGE 'INVALID COMPANY CODE' TYPE 'E'.
ENDIF.

AT SELECTION-SCREEN .

IF P2 <> 'SAP'.
MESSAGE 'INVALID COMPANY NAME' TYPE 'E'.
ENDIF.

START-OF-SELECTION.

SELECT * FROM T001 INTO TABLE IT WHERE BUKRS IN S1.

END-OF-SELECTION.

LOOP AT IT INTO WA.


WRITE :/ WA-BUKRS,WA-BUTXT,WA-LAND1.
ENDLOOP.
TOP-OF-PAGE.
WRITE :/ 'COMPANY CODES DETAILS' COLOR 3.
ULINE.

END-OF-PAGE.
WRITE :/ 'END OF PAGE ' COLOR 5,SY-PAGNO COLOR 5.

***********************************************************

DATA IT TYPE TABLE OF LFA1.


PARAMETERS FILE TYPE STRING.
DATA F1 TYPE IBIPPARMS-PATH.

AT SELECTION-SCREEN ON HELP-REQUEST FOR FILE.


MESSAGE 'CLICK F4 TO VIEW ALL FILES' TYPE 'I'.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR FILE.


CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = 'FILE'
IMPORTING
FILE_NAME = F1
.

FILE = F1.
START-OF-SELECTION.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = FILE
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = IT
.
IF SY-SUBRC EQ 0.
WRITE 'FILE UPLOADED SUCCESSFULLY'.
ENDIF.

VARIANT: IT IS set of frequently used input values of one screen. For one screen we can create multiple
variants.

NOTE : SE93 IS USED TO CREATE OR VIEW A TRANSACTION CODE.

AT SELECTION-SCREEN OUTPUT: It is used to modify screen elements properties at runtime. By clicking


enter or execute button on current screen this event is executed. For the first time INITIALIZATION & AT
SELECTION-SCREEN OUTPUT are executed at a time.

A selection-screen or dynamic screen's elements and their properties are maintains in a standard internal table '
SCREEN '. It is an itab with implicit work area.

STRUCTURE OF INTERNAL TABLE SCREEN

field description

NAME parameter name

GROUP1 group name

REQUIRED mandatory

INPUT to make input possible

OUTPUT read only

INVISIBLE encrypted data( ******)

ACTIVE to show / hide

PROCEDURE:

STEP1. AT SELECTION-SCREEN OUTPUT.

STEP2. LOOP AT SCREEN.


STEP3. CHANGE REQUIRED SCREEN ELEMENT PROPERTIES in workarea (SCREEN).

STEP4. MODIFY SCREEN. " update above changes from wa(screen) into
itab(screen)

STEP5. ENDLOOP.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.


PARAMETERS: a AS CHECKBOX,
"USER-COMMAND flag,
b AS CHECKBOX.
"USER-COMMAND flag.
SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME .


PARAMETERS: test1(10) TYPE c MODIF ID sc1,
test2(10) TYPE c MODIF ID sc2,
test3(10) TYPE c MODIF ID sc1,
test4(10) TYPE c MODIF ID sc2.
SELECTION-SCREEN END OF BLOCK b2.

at SELECTION-SCREEN output. " step1


*
if a = 'X'.
loop at screen . " step2
if screen-group1 = 'SC1'. " step3
screen-active = 0.
endif.
modify screen. " step 4
endloop. " step 5
endif.

if b = 'X'.
loop at screen.
if screen-group1 = 'SC2'.
screen-active = 0.
endif.
modify screen.
endloop.
endif.

%%%%%%%%%%%%&&&&&&&&&&&&&&%%%%%%%%%
%%%%%%%%%%%%%%%%%%%

Interactive reports : a chain of linked reports from one program.


program SY-LSIND

0 1 2 3 20

BASIS 1 s.l ------------2 s.l 3 s.L 20 s.l


LIST

SECONDARY REPORTS

Events in Interactive reports:

1.AT LINE-SELECTION (DOUBLE CLICK ON ANY LINE OF OUT PUT SCREEN)

2.AT USER-COMMAND (BY CLICKING ON PUSH BUTTONS OR MENU ITEM)

3.TOP-OF-PAGE DURING LINE-SELECTION ( TO GIVE HEADER FOR SECONDARY


REPORTS)

FLOW LOGIC OF INTERACTIVE REPORT PROGRAM

KNA1 Double click KNBK

A
b--sbi
B
b--ab
C

D
1.at line-selection ( to generate next report)

2.HIDE / GET CURSOR.(to pass selected line information)

WAP to display customers general data(KNA1) in one report and selected customers banks details (KNBK) in next
report

HIDE:

Hide collects double clicked line information. This info can be used in further reports logic. HIDE keyword must be
used within the LOOP and only after main write statement of LOOP.

Hide can converts data from external format into internal format automatically.

NOTE : HIDE is line specific technique. That is any where we click on the line secondary report is generated.

REPORT Z6PMS_IREPORTS_HIDE NO STANDARD PAGE HEADING.

data wa_kna1 type kna1.


data it_kna1 type table of kna1.
data wa_knbk type knbk.
data it_knbk type table of knbk.
data wa_t001 type t001.
data it_t001 type table of t001.

select-options s_kunnr for wa_kna1-kunnr.

select * from kna1 into table it_kna1 where kunnr in s_kunnr.

loop at it_kna1 into wa_kna1.


write :/ wa_kna1-kunnr,wa_kna1-name1,wa_kna1-ort01,wa_kna1-land1.
hide wa_kna1-kunnr.
endloop.

at LINE-SELECTION.

case sy-lsind.

when 1. " logic of first secondary report


select * from knbk into table it_knbk where kunnr eq wa_kna1-kunnr.

if sy-subrc eq 0.
loop at it_knbk into wa_knbk.
write :/ wa_knbk-kunnr,wa_knbk-banks,wa_knbk-bankl,wa_knbk-bankn.
hide wa_knbk-banks.
endloop.
else.
message 'No banks found for selected customer' type 'I'.
endif.

when 2.
select * from t001 into table it_t001 where land1 = wa_knbk-banks.

if sy-subrc eq 0.
loop at it_t001 into wa_t001.
write :/ wa_t001-bukrs,wa_t001-butxt,wa_t001-land1.
endloop.
else .
message 'no company codes for selected country' type 'I'.
ENDIF.
ENDCASE.

top-of-page.
write :/30 'Customer General Details' color 3.
uline.

top-of-page DURING LINE-SELECTION.


case sy-lsind.
when 1.
write :/30 'Customer Banks Details' color 3 .
uline.
when 2.
write :/30 'Company codes details' color 3 .
uline.
endcase.
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&
GET CURSOR: It is field specific technique ,i.e next report can be generated by clicking on a specific field only.

GET CURSOR FIELD f1 VALUE v1.

F1 - selected field name

V1 - double clicked value

NOTE: Get Cursor cannot converts data from external format into internal format.

'CONVERSION_EXIT_ALPHA_INPUT'
*&---------------------------------------------------------------------*
*& Report ZDEMO_IREPORT_HIDE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZDEMO_IREPORT_GC NO STANDARD PAGE HEADING.

data wa1 type lfa1.


data it1 type table of lfa1.

data wa2 type lfbk.


data it2 type table of lfbk.

data f1 type string.


data v1 type lifnr.

select-options s1 for wa1-lifnr.

select * from lfa1 into table it1 where lifnr in s1.

loop at it1 into wa1.


write :/ wa1-lifnr,wa1-name1,wa1-ort01,wa1-land1.
endloop.

at LINE-SELECTION.
get cursor field f1 value v1.

if f1 = 'WA1-LIFNR'.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'


EXPORTING
INPUT = v1 " external format 1000
IMPORTING
OUTPUT = v1 " internal format 0000001000
.

select * from lfbk into table it2 where lifnr = v1.

if sy-subrc eq 0.
loop at it2 into wa2.
write :/ wa2-lifnr,wa2-banks,wa2-bankl,wa2-bankn.
endloop.
else.
message 'no banks found' type 'I'.
ENDIF.
ELSE.
MESSAGE 'pls click on vendor number to view banks details' type 'I'.
endif.

SET PARAMETER: Used to transfer data from one transaction to another transaction.

SYNTAX : Set PARAMETER ID parid FIELD fieldname.

CALL TRANSACTION 'tcode'.

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
&*&&&&&&&&&&&&&&&

AT USER-COMMAND :
It is triggered by clicking on push buttons and menu items.

f1 f2 f3 f4 )function codes(ok codes)

P1 P2 P3 P4 )push buttons

SY-UCOMM : holds function code of clicked push button / menu item.

We can design menus in SE41(Menu Painter).

We can include a menu painter into our program using

SET PF-STATUS 'name of gui status'.


REPORT ZDEMO_IREPORT_UCOMM NO STANDARD PAGE HEADING.
data wa type t001.
data it type table of t001.
data v1.

set pf-status 'ZSANKAR'.

select * from t001 into table it up to 10 rows.

loop at it into wa.


write :/ v1 as checkbox,wa-bukrs,wa-butxt,wa-land1.
endloop.

AT USER-COMMAND.

CASE SY-UCOMM.
when 'ZCODE1'.
CALL TRANSACTION 'FI01'.
WHEN 'ZCODE2'.
CALL TRANSACTION 'MK03'.
WHEN 'ZSALL'.
V1 = 'X'.
loop at it into wa.
write :/ v1 as checkbox,wa-bukrs,wa-butxt,wa-land1.
endloop.
WHEN 'ZDALL'.
V1 = ' '.
loop at it into wa.
write :/ v1 as checkbox,wa-bukrs,wa-butxt,wa-land1.
endloop.
ENDCASE.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%

DEBUGGING
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%

DEBUGGING : to analyze internal logic of program while its executing.

To open debugger,

1.break points

2./h (run time debugging)

Break point : to stop execution and to start debugging


1.static break point : ' BREAK-POINT '(keyword)

NOTE: BREAK username -----> specific to particular user

2.dynamic break point : for all types of active programs

We can control execution process by using following buttons

F5(STEP INTO): it is used to execute one line at a time.

F6(EXECUTE): It is used to execute one line at a time. It cannot steps into sub program's logic..It executes
subprogram logic as single statement.

F7(STEP OUT): It is used comes out of subprogram to main program.

F8(RUN): To execute entire program at a time and to exit from the debugger.

Note : We can set multiple break points within a program.

WATCH POINT: It is a logical break point with condition. We can set up to 10 watch points within a program.

/hx in debugging process if we click F8 ,still debugging continues internally...To off debugging need to click
'/HX'

*****************************************************************************

MAIN PROGRAM

B.P--> F5 F8 ------------------------ SUBPROGRAM

F5 ------------------------ --------------- F5

F5 F6 call subprogram ----------------F5 F7

F6 --------------------------- -----------------F5

B.P--> -----------------------------

----------------------------
SAP-SCRIPTS(forms):
Scripts are client dependent. A script designed in 100 client will not be visible in 200 client.

By activating script layout , it is converted into text format. In SAP, text documents are client
dependent ..so Scripts are client dependent.

Scripts are Language dependent. A script designed in DE language cannot be changed in EN


language.

Scripts can be designed in FORM PAINTER(SE71).

Scripts layouts can be driven to generate their print output by driver programs(SE38).

Scripts needs program for testing purpose.


Main window is mandatory for each page in Scripts.

SMARTFORMS:
It is word / text processing tool for making External Business documents, to interact with
business trade partners(customers & vendors etc). output of forms must be in printed format.
(LP01 used for demo printing purpose).

ex: Sales order, P.O, Bills, Flight tickets...

Smart forms are Client Independent where as Scripts are Client Dependent.

Note: By Activating a smartform layout it generates a function module,which is client


independent. So Smartform is client Independent.

logo adrs
Driver
activate
Program
print FM
main se38

sign

SMARTFORMS LAYOUT (SMARTFORMS)

FORM INTERFACE : Here we can define all types of variables through which we can transfer data
from driver program into smartform layout.
GLOBAL DEFINITIONS : Here we can define all types of variables which can be used within the
layout only.

Main Window : Data beyond the size of main window is not truncated, it extends to next page
automatically.

Secondary Window / Var Window : This is used to display fixed size data.

INITIALIZATION : The logic of this section is executed first.

SE78 to upload our images from presentation server into application server.

SFSY All standard smart form variables are listed in this structure.

In forms text can be displayed through text editors only. On text editor variable has to be used
as a symbol.

Ex : &variablename& . &v1&

We can set conditions for all types windows.

WINDOWS : 1. ADDRESS WINDOW : to display addresses from ADRC table of given address
number

2.COPIES WINDOW : works with copies of a document

Note : SFSY-COPYCOUNT(1,2,3..) / SFSY-COPYCOUNT0(0,1,2,3.....)

3.GRAPHICS WINDOW : used to display only images (bmp)

Note : The logic of FINAL WINDOW is executed just before leaving the smart form .

In Smart forms layouts we can write all types logic in PROGRAM LINES.

DRIVER PROGRAM :

We can generate a print out based on smart form layout name by using a standard function
module 'SSF_FUNCTION_MODULE_NAME'.

TABLE PAINTER is used to display internal table data in table format on form page. Table should
be designed on MAIN WINDOW only. Table size should not exceeds window size. Each Table
comes with a default loop.

NOTE : In forms currency and quantity fields must be assigned with reference fields. They have
to be defined in GLOBAL DEFINITIONS on smart form layout.
TABLE TYPE : 1.HEADER (field names)

2.MAIN AREA(data records)

3.FOOTER(optional)

LINE TYPE : defines number of cells per one row L1

L2

TEMPLATE : Used to display fixed number of records.

RSTXPDFT4 : Standard program to convert form output from OTF format into PDF format.

Step 1: Execute driver program. Select New Spool Request & click on PRINT.

Step 2: Go to SP01 , Execute, Copy required Spool Request number.

Step 3: Execute RSTXPDFT4 and provide above spool request number.

SMART STYLES are global , can be used in all smart form layouts. Whereas Paragraph &
Character display formats are local in SCRIPTS.

SE73 used to create Bar Codes

To print Barcode..

1.Select Smart style on output options

2.On Text editor..

<C1> field to be printed in barcode </>

Main programs:
1.Executable programs :

Type 1.

Can be executed directly(F8)...No Tcode is required.

Source code starts with 'REPORT ' keyword.

2.Module Pool Program:(MPP)

Type M.

Must be executed through an unique tcode.

Source code starts with "PROGRAM' keyword.

MODULE POOL PROGRAM / TRANSACTION PROGRAM/


DIALOG PROGRAM:(MPP)
designs GUI for ABAP applications - dynamic screens (0001 - 9999)

TCODE

2000 3000 4000 5000


Main Program

FLE- FLOW LOGIC EDITOR L - LAYOUT

SE38 (main progrm) - MODULE

FLE: screen specific editor which allows very limited keywords and logic. This un allowed logic
of FLE can be written in main program in terms of MODULE.

EVENTS OF F.L.E

1.P B O: Process Before Output : executes before generating the screen

2.P A I :Process After Input : executes just before leaving the screen

3.POV :Process On Value request : by clicking on f4 button

4.POH :Process On Help request : by clicking on f1 button

SCREEN 3000(SE51) Main Program(SE38)

define screen
elements.
LAYOUT FLE
MODULE M1.

DATE = SY-DATUM.

ENDMODULE.
DATE: PBO.

UN: MODULE M1.

PW: PAI.

MODULE M2.

Note : All screen elements must be defined in main program(SE38) with same names and
properties.

To develop an MPP:

1.ABAP EDITOR -SE38.

2.SCREEN PAINTER -SE51. ABAP DEVELOPMENT WORK


BENCH (SE80).
3.MENU PAINTER -SE41.
(Object Navigator)
4.MESSAGE CLASS -SE91.

5.TCODE BUILDER -SE93.

1.LEAVE TO SCREEN 0 : to go to previous screen.

2.LEAVE PROGRAM : to exit the program.

3.CALL SCREEN scrnumber. : to call a specific screen.

4.LEAVE TO LIST-PROCESSING : to go to console.

NOTE : To design screen with data base table fields we can use F6 button. Through F6 button
all screen elements are created with DBT fields properties. Also these fields acts as a work area
with DBT name.

NOTE: Corresponding to the above screen work area we must have to define another work
area with same name by using a keyword TABLES.
TABLE CONTROL : Used to display data of internal table on screen in table format.

The screen with table control must contains LOOP in PBO and PAI.

In PBO loop data can be transferred from itab into table control.

In PAI loop data can be transferred from table control into itab.

VALIDATIONS:

SYNTAX: PAI.

FIELD fieldname MODULE modulename.

Fieldname : to be validated

modulename : validation logic

NOTE: To enable screen fields after throwing error message use CHAIN and ENDCHAIN.

Procedure To exit screen bypassing all screen validations :

1.Maintian function type E for exit button

2.Define a module in PAI with AT EXIT-COMMAND

3. Provide LEAVE PROGRAM in the above module.

TABSTRIP CONTROL : Used to handle multiple sub screens in a main screen

subscreen 6100
subscreen 6200

main screen 6000

tab1 tab2

SUBSCREEN subscreen tabstrip control (TABS)


area SA2
AREA sa1
EX: XD01 - to create customer

MK01 - to create vendor

MM01 - to create material

FI01 - to create banks

VA01 - to create sales order

ME21N - to create purchase order

REPORT ZJAY_UPLOAD_EXCEL NO STANDARD PAGE HEADING.


PARAMETERS: p_file TYPE rlgrap-filename.
PARAMETERS: p_head TYPE char01 DEFAULT 'X'.

TYPES: BEGIN OF t_datatab,


col1(30) TYPE c,
col2(30) TYPE c,
col3(30) TYPE c,
END OF t_datatab.
DATA: it_datatab TYPE STANDARD TABLE OF t_datatab,
wa_datatab TYPE t_datatab.
DATA: it_raw TYPE truxs_t_text_data.

* At selection screen
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
field_name = 'P_FILE'
IMPORTING
file_name = p_file.

START-OF-SELECTION.
" Convert Excel Data to SAP internal Table Data
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
i_line_header = p_head
i_tab_raw_data = it_raw " WORK TABLE
i_filename = p_file
TABLES
i_tab_converted_data = it_datatab[] "ACTUAL DATA
EXCEPTIONS
conversion_failed =1
OTHERS = 2.

IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

***********************************************************************
* END-OF-SELECTION.
END-OF-SELECTION.
" For sample, Excel Data transfered to internal table is displayed with write
LOOP AT it_datatab INTO wa_datatab.
WRITE:/ wa_datatab-col1,
wa_datatab-col2,
wa_datatab-col3.
ENDLOOP.

Batch Data Communication / Conversion (BDC)

SAP FILE

BDC PROGRAM
NON SAP SAP DB

BDC is Inbound Technique

Always used to migrate or upload or transfer large amount of data from legacy system into
SAP data base.

In BDC always data has to be transferred through screen sequences(MPP).

MPP s were developed with validations like mandatory checks , date format checks and foreign
key checks etc.

File

upload Loop
ITAB wa

SQL X validations(MPP)

Requirement: WAP to upload multiple banks through an MPP FI0

1. Flow
SAP Logic
DB of BDC Program:

**************************************************************************

Write a program to upload multiple banks details into SAP database.

File name : D:\banks.txt

Transaction Program to upload Banks : FI01

**************************************************************************
File upload IT LOOP AT IT INTO WA

BDC METHODS(CALL TRANSACTION / SESSION)

IT1(BDCDATA)

screenplay of one data record


SAP DB
ENDLOOP

Procedure:

1. Prepare input file.

2.Record the transaction(MPP) in SHDB to collect technical information like program names,
field names, screen numbers and function codes.

3.IN BDC program(SE38),

A).Define IT & IT1.

Note :IT must be defined with FILE structure.IT1 must be defined with BDCDATA structure.

B).Upload data from input file into IT

C).LOOP AT IT INTO WA.

D).Prepare IT1 with screenplay of one data record through screens using recorded information.

E).Execute CALL TRANSACTION / SESSION method using IT1.

F).REFRESH IT1.

G).ENDLOOP.

The structure of BDCDATA:

1.PROGRAM - Module pool program name

2.DYNPRO - Screen number


3.DYNBEGIN - Screen start

4.FNAM - Field Name

5.FVAL - Field value

RECORDING (SHDB) : we record a transaction in SHDB to get technical info like Program
names, Field Names, Screen Numbers & Function Codes , which are useful to write a BDC
program.

BDC METHODS :

1.DIRECT INPUT METHOD : we use standard programs and function modules to transfer data

2.CALL TRANSACTION:

. Inserts each data record individually into data base immediately.

. For each transaction it returns SY-SUBRC. Hence error handling is possible.

.But it can't return log file.

.It can update data synchronously and asynchronously(default).

.It can process data synchronously.

syntax: CALL TRANSACTION 'tcode' USING IT1

UPDATE 'A' / 'S'

MODE 'A' / 'E' / 'N'

MESSAGES INTO IT2.

NOTE: Update : 'A' - asynchronous (default) . 'S' - synchronous

Mode : 'A' - All screens(default) . 'E' - Error screens . 'N' - No screens

IT2 can be defined using BDCMSGCOLL.

3.SESSION METHOD / BATCH INPUT METHOD :

. It can transfer all records into data base at a time.

. It can return complete log file.


. It can't return SY-SUBRC. Hence error handling is not possible.

. It can update data base synchronously.

. It can process data asynchronously.

syntax : Each session has 3 stages.

1. Create or open a session or group.

'BDC_OPEN_GROUP' -------->before LOOP

2.To fill all transactions into the above session

'BDC_INSERT'.--------------------->with in the loop

3.To close the above session

'BDC_CLOSE_GROUP'.---------->after loop

NOTE: we can get all sessions in SM35

1.UPDATE : ASYNC 2.PROCESS : SYNC

One by one record into DB, Returns SY-


1.Call transaction: se38 SUBRC, No LOG file

BDC
file
PROGRA
SAP DB
M(C.T)

******************************************************************************

1.UPDATE : SYNC 2.PROCESS : ASYNC

All records thru a session into DB

No SY-SUBRC, Complete LOG file


2.Batch input / Session Method: se38 S1

BDC S2
file SAP DB
program(s
S3
ession)
S4
SM35

**********************************************************

FILES ON APPLICATION SERVER( SEQUENTIAL FILES / DATA SETS)

Tcode : AL11 ( to view all data set directories)


Default directory is ‘ . ‘ / DIR_TEMP
1.OPEN DATASET to open a data set
OPEN DATASET 'ZJDEMO.TXT' FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.(to dload)

OPEN DATASET 'ZJDEMO.TXT' FOR INPUT IN TEXT MODE ENCODING DEFAULT.(to upload)

2.CLOSE DATASET to close a data set


CLOSE DATASET 'ZJDEMO.TXT'.

3.TRANSFER to copy data from work area into data set


LOOP AT IT INTO WA.
TRANSFER WA TO 'ZJDEMO.TXT'.
ENDLOOP.

4.READ to copy data from data set into work area


DO.
READ DATASET 'ZJDEMO.TXT' INTO WA.
IF SY-SUBRC NE 0.
EXIT.
ELSE.
APPEND WA TO IT.
ENDIF.
ENDDO.

5.DELETE to delete a data set


DELETE DATASET ‘ZJDEMO.TXT’.

**********************************************************

Legacy System Migration Workbench (LSMW):


Tcode : LSMW

LSMW is a tool for BDC data transfer .

Generally it is used by Functional Consultants to transfer Master data.

In LSMW we can transfer data by using STANDARD INPUT METHOD , BATCH INPUT METHOD
(SESSION),BAPI and IDOC.

NOTE : In LSMW , Call Transaction method cannot be used.

SAP DBT
IT(ZSRC) IT1(ZREC)
i/p file

1. BDC with SESSION method

2.BDC with CALL TRANSACTION method

3.BDC with LSMW.

4.Data Transfer using BAPI


ALV REPORTS:(ABAP LIST VIEWER):

To display data of an internal table with additional display properties as in SE11.

Note : No work area and LOOP are required to display ALV report.

To generate an ALV reports need standard data types and standard function modules.

ALV related data types are available in a type group called SLIS.

TYPE-GROUP: Is group of data types. Names of all data types of a type group has to start with
type group name.

To use data type of group we must have to link it in our program as follows.

syntax : TYPE-POOLS typegroupname. Ex : type-pools : SLIS,ICON,VRM....

ALV reports can be displayed in 2 modes.

1.GRID MODE: FM 'REUSE_ALV_GRID_DISPLAY'.

2.LIST MODE : FM 'REUSE_ALV_LIST_DISPLAY'.

Above FMs need 1. What to display ? ( itab with data)

2. How to display? (FIELD CATALOG)

FIELD CATALOG:

It is set of displaying properties of itab fields which are to displayed on output screen

Field catalog can be created in following 3 ways.

1.STANDARD FIELDCATALOG : EX: KNA1,MARA,EKPO...

2.CUSTOM FIELDCATALOG : PREPARE FIELDS PROPERTIES -------> IT_FCAT


3.FIELD CATALOG MERGE :

STANDARD FCAT ----->'REUSE_ALV_FIELDCATALOG_MERGE'------->IT_FCAT

change required fields properties ------> it_fcat

HIERARCHICAL ALV : To display two internal tables data in hierarchical format i.e, header data
from IT1 and corresponding items details from IT2.

Procedure:

step1 : Define IT1 & IT2.

step2 :Extract data from two data base tables using FOR ALL ENTRIES concept.

step3 :Prepare field catalog for IT1 and IT2 fields.

step4 :Provide common key field information from IT1 & IT2.

step5 :Display Hierarchical ALV using a standard FM

'REUSE_ALV_HIERSEQ_LIST_DISPLAY'.

ALV WITH EVENTS :

' REUSE_ALV_EVENTS_GET ' : Function Module to get all available events in ALV reports

Ex: ' TOP_OF_PAGE'.

'END_OF_PAGE'.

'TOP_OF_LIST'.

'END_OF_LIST'.

' USER_COMMAND'.

NOTE : Events logic can be handled by using subroutines only.

'OAER' / ‘OAOR’ - Tcode to upload bit map images into document server

Interactive ALV report :


We can generate secondary report by using an event 'USER_COMMAND'.

The subroutine of USER_COMMAND must contains 2 parameters.

1. V1 LIKE SY-UCOMM. " collects function code

EX : '&IC1' is function code for DOUBLE CLICK

2.V2 TYPE SLIS_SELFIELD.

Note : V2 holds selected line information like clicked column name, clicked value and
clicked line number ..etc.

Object (OO-ABAP):
Object Oriented ABAP Oriented ABAP

1.ENCAPSULATION : Binding (logic + parameters) ----> CLASS(BLUEPRINT OF LOGIC)

METHODS (PROPERTIES)

C1(M1,M2)----------------> O1(M1,M2) objects

2.DATA ABSTRACTION : hiding properties : ACCESS MODIFIERS/VISIBILITY SECTION

A)Public B)Protected C)Private

Note : In ABAP access modifiers have to be defined in the above order only.

Note : A class can access private properties of its FRIEND CLASS.

3.INHERITANCE : C1(super cls)------->C2(sub cls) ----- reusability & redefinition

Note : In ABAP multiple inheritance is not possible. Multi level inheritance is possible.
4.POLYMORPHISM : many forms of one method--->

Interface group of only abstract methods.

Note : Method over loading is not possible in ABAP.

Types of methods : Instance(OBJECT) & Static (CLASS):

Instance : Object based , can be called using objects.

DATA : V1,V2.

METHODS : M1,M2

EVENTS : E1,E2.

CALL METHOD objectname->instancemethodname.

Static : Class based , can be called using classes

CLASS-DATA : V1,V2.

CLASS-METHODS : M1,M2

CLASS-EVENTS : E1,E2.

CALL METHOD classname=>staticmethodname.

******************************************************************************

Static methods & variables can be accessed by Class & Object as well.

Static variables can be used in Static methods only.

Instance Methods can have Instance & Static variables.

Instance methods can be accessed by objects only.

Importing , Exporting and Changing parameters can be passed by value as well reference also.

ONE METHOD CAN HAS ONLY ONE RETURNING PARAMETER(MAX).It can be called by value
only.

CLASS : LOCAL CLASS (SE38) & GLOBAL CLASS(SE24)

LOCAL CLASS : (SE38) scope is within the program.

Procedure:
1.Define class with method names " class definition

2. Implement methods " class implementation

3.Create object

4.Call methods

********************************************************************

PROCEDURE (Local Class):

SE38 :

1.DEFINE CLASS NAME & METHODS

2.Implement methods of the class

3.Create Object

4.Call method

PROCEDURE (Global Class):

SE24: (CLASS BUILDER / CLASS POOL)

1.DEFINE CLASS NAME & METHODS

2.Implement methods of the class

SE38 :

1.Create Object

2.Call method

Note : syntax to create object using NEW operator.

DATA(objectname) = NEW classname( ).

***********************************************************************

ME : to call one method into another method of same class

SUPER : to call one method from parent class into its sub class method
Land _vehicle Truck
-Max_speed inheritance -Max_speed
-No_wheels -No_wheels
-No_plate -No_plate
-Capacity

Narrow Casting

Land_veh_obj Truck_obj

Wide Casting
Between these two objects, you can assign one to the other and at this point casting
occurs.
*If you assign truck_obj to land_vehicle_obj you lose the special attribute load_capacity
since you go from the specialized on to the general one. Thus, this is a narrowing cast.
* If you assign land_vehicle_obj and truck_obj you do not lose any attribute,
nevertheless you add a new one. Thus this is a widening cast.
Demo on "Narrow Casting"

Definition: The assignment of a subclass instance to a reference variable of the type "reference
to super class" is described as a narrowing cast, because you are switching from a more
detailed view to a one with less detail. It is also called as up-casting.

Use of narrowing casting:

A user who is not interested in the finer points of cars, trucks, and busses (but only, for
example, in the fuel consumption and tank gauge) does not need to know about them. This user
only wants and needs to work with (references to) the lcl_vehicle(super class) class. However,
in order to allow the user to work with cars, busses, or trucks, you generally need a narrowing
cast.

Principle of narrowing casting:

1. In narrowing casting the object which is created with reference to the sub class is
assigned to the reference of type super class.
2. Using the super class reference it is possible to access the methods from the object
which are only defined at the super class.
3. This access is also called as generic access as super class is normally called as
general class.

Example:

Super class: vehicle (contains general methods)

Sub class: truck (contains more specific


methods)

Here method4 is the specific for the sub class and remaining methods are inherited from the
super class.

Now create the object with reference to the subclass.

1. Declare a variable with reference to the subclass.

DATA: REF_TRUCK TYPE REF TO TRUCK.

2. Create object with this reference.

CREATE OBJECT REF_TRUCK.

Narrowing cast:

1. Declare a variable with reference to the super class.

DATA: REF_VEHICLE TYPE REF TO VEHICLE.

2. Assign the object reference (REF_TRUCK) to REF_VEHICLE.


REF_VEHICLE = REF_TRUCK.

Accessing methods using super class reference.

1. By the super class reference (REF_VEHICLE) it is possible to access all the methods which
are defined at the super class but the implementations are taken from the sub class.

2. If any method is redefined at the sub class then that method’s implementation which exist at
the sub class is taken in to consideration.

E.g. assume that ‘method2’ is redefined at the sub class.

When this method is accessed using the super class reference

Like:

Call method REF_VEHICLE->method2.

Here we can access the implementation which exists at the sub class but not from the super
class.

3. It is not possible to access the methods which only defined in the sub class using the super
class reference.

E.g. Method4 is not accessed using reference REF_VEHICLE.

Call method REF_VEHICLE-> Method4.

This is wrong convention.

Demo for narrowing casting:

Go to transaction SE38.
Now execute (F8):

Result:
Constructors:
special methods of a class are used to initialize the objects

1.Instance constructor: Object based, CONSTRUCTOR ,only inputs, executed for each object

2.Static Constructor : Class based, CLASS_CONSTRUCTOR, no parameters, executed only once


for all objects of a class.

NOTE : Among all methods of a class , static constructor is executed first.

EVENT HANDLING:

1.define event EVENTS E1.

2.define event handler method.( it contains event related logic)

3.implement Event Handler Method

4.raise event eventname.( execute a required event)

5.register event handler method for an object using SET HANLDER.

Use of static event


Static methods can only raise static events. The FOR…addition is not required to register for
static
Class-events e1.

Set handler obj->event_method. “ for a specific object is not required

Note : Event with export parameters.


Events can have export parameters, which it passes to its event handler method. The triggering
method must pass values for all the exporting parameters of the event while raising the event
using RAISE EVENT statement. The interface of an event handler method consists of a list of
IMPORTING parameters, whose names are identical with those in the EXPORTING list and
which
are automatically created from the interface of the event. Each handler method can however
specify which event parameters it wants to handle and which it does not.

Exception Handling:
If Exception is not handled properly, then programs execution will be terminated.

Each exception class name starts with 'CX_xxxx'.

All exception classes inherited from the super class 'CX_ROOT'.

Here we can handle exceptions as follows.

1.Keep main logic in TRY & ENDTRY block.

2.Handle exception by using keyword CATCH....Ex : CATCH CX_SY_ZERODIVIDE


&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

Example:

DATA: result TYPE p LENGTH 10 DECIMALS 3,


ex_ref TYPE REF TO cx_root,
msg_text TYPE string.
PARAMETERS: value1 TYPE char40,
value2 TYPE char40.
TRY .
* divide v1 by v2
result = value1 / value2.

CATCH cx_sy_zerodivide INTO ex_ref.


msg_text = ex_ref->get_text( ).
CATCH cx_sy_conversion_no_number INTO ex_ref.
msg_text = ex_ref->get_text( ).
CATCH cx_root INTO ex_ref.

msg_text = ex_ref->get_text( ).
ENDTRY.
IF NOT msg_text IS INITIAL.
WRITE / msg_text.
ELSE.
WRITE: / 'Result :', result.
ENDIF.

&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

Global classes: Can be defined and implemented globally in class builder(SE24). These
can be called into all programs.

step1: Go to SE24 ---> Define and implement a class with methods

step2: Go to SE38 -----> Create an object and call required methods.

Note : Final classes cannot be inherited.

ex: GUI_DOWNLOAD CL_GUI_FRONTEND_SERVICES

We can Redefine Super class methods logic in Sub classes using INHERITANCE concept.

zcl_5pm1(SUPER CLS) zcl_5pm2(SUB CLS)

m1 m1

se38

obj1 OBJ2
******************************************************************************

Enhancements
******************************************************************************

Enhancements: To add extra custom logic for standard applications without disturbing
them. SAP provide enhancement provisions(EXITS) in standard programs where ABAP
consultants can add extra logic.

Enhancement provisions(Exits) : SAP provide exits in terms of empty sub programs.

1.Empty subroutines(USER EXITS)

2.Empty FM(CUSTOMER EXITS)

3.Empty Methods(BAdIs)

Types of Exits:

1.function exit ( adding extra program lines)

2.menu exit (adding custom menu items to a standard menu bar)

3.screen exit ( adding a custom sub screen to a standard main screen)

4.custom includes & append structures(Custom Includes starts with ' CI_XXXXX' )

Note : Custom Includes are provided by SAP for few standard tables through which we can add
new fields to them at mean position.

EX: EKKO, EKPO.

1.USER EXITS:

Uses empty subroutines.

Used in SD module only

need ACCESS KEY to implement

list of user exits --- VMOD package


2.CUSTOMER EXITS:

uses empty FMs(Procedural type )

No access key required

MODSAP - table for all customer exits

procedure 1.

1.open source code of program to be enhanced

2.search for a string CALL CUSTOMER-FUNCTION '001'. double click on FM

3.FM opens in SE37. go to source code. find out include program.

4.double click on include program starts with 'ZX.....'.

5.provide custom logic. ACTIVATE

procedure 2.(******)

1. find out package of program to be enhanced

2. go to a transaction code SMOD to search for enhancements of a package

3. go to a transaction code CMOD to implement enhancement in our project

Ex1. Implement Function exit for XD01 using CUSTOMER EXITS to download given customers
details into a local text file.

Ex2.Implement Menu exit for MC94 using CUSTOMER EXITs to add custom menu items to
standard menu bar.

Ex3.Implement Screen exit for VX11 using CUSTOMER EXITs to add a custom sub screen to its
standard screen

NOTE: Multiple implementations are not possible with customer exits.


Screen exit : MM06E005( me21N )

EXIT_SAPMM06E_006 ( PBO)

EXIT_SAPMM06E_012 logic to post data from custom subscreen into database table

PBO logic as follows.

PAI logic as follows.


BAdIs (BUSINESS ADD-INs) :

BAdI uses abstract methods as enhancement provisions. These are object oriented approach
for enhancements. Multiple implementations are possible with BAdIs.

CL_EXITHANDLER : It is a standard global class handles all implementations of a BAdI.

TYPES OF BAdIs

1.Multiple use BAdI : All implementations of this type BAdI executed one by one in alphabetical
order(Generally)

2.FilterBAdI: Among All implementations of this type BAdI ,only few will be executed which
satisfies given condition.

PROCEDURE TO IMPLEMENT A BAdI METHOD :


1.Find out package of the program to be enhanced.

2.Goto SE80 , to search for available BAdIs from the above package.

3.Goto SE18 ,to search for available methods of above BAdI.

Note : SE18 is also useful to search for available implementations of a BAdI.

4.Goto SE19, to implement a required method in our own implementation class.

Ex:

1.Implement function exit for XD01 using BAdI

2.Implement Menu Exit for FBL3N using BAdI

TO SEARCH FOR AVAILABLE BAdIs USING CL_EXITHANDLER

1.GOTO SE24 ..open the class CL_EXITHANDLER..

double click on method GET_INSTANCE...set a break point at 14th line.

2.open another transaction and run it.

3.then for each BAdI occurrence ...debugger is opened.

click on EXIT_NAME to view current BAdI name.


ENHANCEMENT FRAMEWORK

1.Source code enhancement

2.Function Group enhancement(extend FM parameters)

3.Class enhancement(extend Method parameters)

4.Kernel BAdI enhancement(implemented at kernel level..hence faster than classic BAdI)

SOURCE CODE Enhancement:( (stored in separate includes)

It directly enhance in ABAP source code.

1.Implicit enhancement option : these are provided at the end of programs , end of FM , end of
subroutines. Provided by SAP inside the program.

2.Explicit enhancement option:

These are provided by SAP at specific positions of a program explicitly. BAdI is also one kind of
explicitly provided enhancement option
1.Enhancement point (provided places) can' ve multiple active implementations

NOTE : Enhancement point STATIC contains one INCLUDE program for declarations

Enhancement point DYNAMIC is used to write enhancement logic

2.Enhancement Section (replace set of standard statements)

NOTE : Enhancement points and sections cannot be controlled where as BAdI can be controlled

NOTE: Kernel BAdI is faster than Classic BAdI .

KERNEL BADI (New BAdI) – GET BADI & CALL BADI

Classical BAdI called by using CL_EXITHANDLER (proxy class) class and will take time

Kernel BAdI instances can be called by just Get BAdI ( a single step). Hence Kernel BADi is faster
than Classical BADi.

Kernel BAdIs cannot be created without enhancement spots.

Enhancement spot is container of new BAdIs , Enhancement points & Enhancement sections.

To find Kernel BAdIs put break-point at GET BADI & CALL BADI statements.

GET BADI badiname 🡪 Creates Object for BADI class

Example : Hide unwanted tabs from MM01 using Kernel BAdIs.

BADI_MATERIAL_OD is enhancement spot.

Classical Badi:
1.'Fall back class'(If there is no active implementation present in badi, by default this class
implementation will be trigger) is not there.
2. By default interface and class will be generate(no need to mention it explicitly).
3. Syntax for calling classic badi is 'Call method'.
4. It is Slow(bcz by using cl_exithandler~get_instance we will instantiate the object for the badi).

Kernal Badi(Filter Badi):


1. 'Fall back class' is present, it will avoid the program from Dumping if there no active implementation
present in the class.
2. We have to Mention Interface, Class Manually.
3. Syntax for calling Kernal badi is 'Get Badi and call Badi' key word .
4. It is Fast(bcoz by using get_badi key word we will instantiate the object for the badi).

Example on Implicit Enhancement Option:


1. Restrict the access of other users to change another's Sales order.

Include program is : MV45AFZB

2. To make DP95 selection screen fields as mandatory .(to make SO_VBELN-LOW as


obligatory)

QUESTIONS

1.What is the concept of Enhancements.

2.Differences B/W User Exits and Customer Exits.

3.Differences B/W Customer Exits and BAdIs.

4.Diff B/W Classic BAdI and Kernel BAdI.

5.Diff B/W Enhancement point and Enhancement Section

CROSS APPLICATIONS (CA) : (ALE-IDOCS, RFC, BAPI)

partner1 partner2

Cross Applications

Synchronous Asynchronous

RFC ALE- IDOCS

BAPI
EDI :(Electronic Data Interchange): It is non SAP technology. It uses EDI Subsystem to transfer
data between partner systems. It can convert data into different technologies. It converts data
from SAP format into FILE format.

ALE - IDOCS: (APPLICATION LINK & ENABLE)

ALE is SAP s own integrated technology. It can perform communication between SAP systems.

It transfers data in terms of messages. ALE uses IDoc as container to transfer data.

IDoc (Intermediate Document): IDoc is an interface to transfer data Asynchronously.

It transfers data internally in string format. IDoc maintained in ASCII format.

IDoc is a variable which can be prepared by using a data type 'IDOC TYPE'.

IDOCTYPE : It is used to prepare IDocs. It is group of segments. Each Segment is group of fields.

Generally a segment corresponds to a data base table.

NOTE : One segment can carry maximum 1000 bytes(characters)

In SAP we have so many standard IDOCTYPEs.

Example:

1.DEBMAS01,02,03........ CUSTOMER MASTER DATA

2.CREMAS01,02,03........VENDORS MASTER DATA

3.MATMAS01,02,03.......MATERIAL MASTER DATA

4.ORDERS01,02,03..........SALES/PURCHASE ORDERS DETAILS

5.COSMAS01,02,03.........COST CENTER DATA.

NOTE: WE30 to define & view an IDOCTYPE


MESSAGE TYPE: It defines type of data to be transferred through an IDoc. In ALE IDoc can be
requested, generated, processed, received and posted by using a message type only.

In SAP we have so many standard MESSAGETYPEs

Example:

1.DEBMAS ........ CUSTOMER MASTER DATA

2.CREMAS ........VENDORS MASTER DATA

3.MATMAS .......MATERIAL MASTER DATA

4.ORDERS ..........SALES/PURCHASE ORDERS DETAILS

5.COSMAS .........COST CENTER DATA.

NOTE: Each IDOCTYPE must be linked with any one of the MESSAGE TYPE.

WE81 : TCODE to create and view MESSAGE TYPES.

WE82 : TCODE to view all linked IDOCTYPEs and MESSAGE TYPEs.

EDMSG : Data Base table for all message types

EDIMSG : Data Base table for all linked idoc types and message types.

Note:

1.MESSAGE TYPE is meaning of an IDoc

2.IDOCTYPE is structure of an IDoc.

In ALE we can transfer data always at application server level i.e across clients.

Each client must be assigned with an alias name called LOGICAL SYSTEM.

100 300

200 800

300 900
APS1 APS2

LS1 LS2 (Logical Systems)

IDOC STRUCTURE / RUN TIME COMPONENTS OF AN IDoc

Each IDoc is assigned with an unique 16 digit IDOC NUMBER.

Each IDoc contains 3 types records.

1.DATA RECORDS

2.CONTROL RECORD

3.STATUS RECORDS

1.DATA RECORDS.(WHAT TO TRANSFER?)

A. These maintains segments details i.e data details to be transferred.

B. EDIDD is the structure of data records.

C. One IDoc can has multiple data records.

DOCNUM(16) SEGNAME SDATA(1000)

12345 S1 FIRST DATA RECORD


100IGHYD

12345 S2 100IN
SECOND DATA RECORD

2.CONTROL RECORD.(WHOM TO TRANSFER?)

A. It maintains partners address details.

B. EDIDC is the structure of Control records.

C. One IDoc can has only one control record.

3.STATUS RECORDS.(STATUS OF IDOC)

A. It maintains status of an IDoc at different stages.


B. EDIDS is the structure of status records.

C. One IDoc can has multiple status records.

NOTE: ALE maintains status records in terms of status codes(message texts).

TEDS2 : table to view all status codes(01 - 75)

01 to 49 are used for sent IDocs.(outbound)

50 to 75 are used for received IDoc.(inbound)

FLOW LOGIC OF AN IDOC IN BOTH SIDES:

IDOC IDOC

PROG TO EXTRACT PROG TO EXTRACT


O/B PROG DATA FROM DBTs DATA FROM I/B PROG(FM)
INTO SEGMENTS RECVD IDOC &
(REPORT) OF IDOC POST INTO
CORSPNDNG DBTS

100 200
KNA1,KNBK KNA1,KNBK

SENDOR LS1 LS2 RRECEIVER

OUTBOUND PROCESS INBOUND PROCESS

NOTE : WE02 / WE05 TO VIEW SENT OR RECEIVED IDOCS( INBOX & OUTBOX OF IDOCS)

Create one customer 0000009045 in XD01 with in a client 800.

Transfer customer details of 0000009045 from 800 client to 810 client.

Sender : 800 ( DPKCLNT800 ) ---OUTBOUND PROCESS

Receiver : 810 ( DPKCLNT810)---INBOUND PROCESS

Message Type : DEBMAS (Customer general details)

Idoc Type : DEBMAS07

OUTBOUND :(800):

1.SALE(to define and assign logical systems)

Note : Naming convention of logical system : 'server id' + 'CLNT' + client number.

Ex: ABCCLNT800

NOTE : SALE must be repeated in both clients if they exists in different servers.

2.SM59(RFC Destination) To maintain partners contacts details

3.WE21(Port Creation) The exit through which we can transfer IDoc to a specific partner

4.BD64(Distribution Model) : To maintain list of interested partners for a specific MESSAGE


TYPE.

Model View(800) BD64 Communication


IDoc
Master IDoc
Partner Message type
(DEBMAS)
LS2(810) Debmas,Cremas Communication
IDoc
LS3(820) Debmas,Cosmas

5.To Generate an IDoc with required data : Outbound Program

ex: BD10( to send Materials),

BD12(to send Customers),

BD14(to send Vendors)...

6.WE05/WE02 (to check status of sent IDocs)

STATUS CODE CONVERSION PROGRAM (BD75): to add extra status code 12 to successfully sent
IDocs.

This program works only for IDoc which has final status code 3.It also displays not sent IDocs.

SM58 : TO CHECK FAILED TRFC CONNECTIONS

NOTE: EDID4 IS A DATABASE TABLE HOLDS ALL IDOCS DETAILS.

FLOW LOGIC OF O/B PROGRAM

OUTBOUND PROGRAM EX: BD12

DB

It is Original Idoc with only data


Master Idoc
records

ALE SERVICE LAYER

Sr Rr Msg BD64

Ls1 Ls2 D.M,


DISTRIBUTION LAYER
Ls1 Ls3 D.M

LS1 LS4 D.M


COMMUNICATION
C1 C2 C3 IDOCS

IDOCS
PORT1 PORT2 PORT3

to receiver1 to recvr2 to receiver 3

INBOUND(810):

1.WE20(Partner Profile) - maintained I/B process code EX: DEBM (IDOC_INPUT_DEBITOR)

2.WE05 ( To check received IDocs in INBOX)

BDM2 (IDOC TRACING) : TO check I/B & O/B idoc details from sender system directly.This
option is possible due to a dummy message type SYNCH & idoc type SYNCHRON.

WE19 : Testing tool for reprocessing a received IDoc. And also used to change received
segments details and can reprocess that IDoc. Debugging of I/B IDoc process can be possible
with WE19.

******************************************************************************

CHANGE POINTERS:( to share only changed segments)


1.BD61(to activate general change pointers)

2.BD50( to activate change pointers for a specific message type)

3.CHANGE MASTER DATA(ex: XD02 to change customer)

4.BD21(to generate IDoc with changed segments)

5.WE05

NOTE : No Idocs will be generated by BD21 for no changes in master data in our system.

If changes made in child segment, then BD21 generates IDoc with Changed child segment and
mandatory Parent segment.

NOTE: Tables with change pointers CDHDR,CDPOS,BDCP,BDCPS

******************************************************************************

IDOC FILTERING: We can set Conditions @ BD64(distribution model)

Transfer Customer master data whose company code is 3000.

Note: If condition failed by mandatory segment then total IDoc can be dropped. Hence it was
named as IDOC FILTERING.

SEGMENT FILTERING: BD56: To remove unwanted segments for a specific partner from a
message type.

NOte : To hide unwanted segments like E1KNA11 & E1KNB5M from DEBMAS for 810 client

Note : we can't configure mandatory segment in BD56)

REDUCED MESSAGE TYPE: BD53(creating a new message type with required segments and
fields from a standard message type).This must be defined and configured in partner system
too with same name and properties.

Note : We have to configure reduced message type in BD64(sender system) and WE20 (receiver
system)

***************************************************************************

RSEOUT00 : to dispatch all collected IDocs

*********************************************************
CUSTOM IDOC:
Outbound Process:

1.Create Data Base Table SE11 Ex : ZSTDS

2.Create a segment type WE31 Ex:Z1STDTS

3.Create Idoc type WE30 Ex:ZSTDS04

4.Create Message type WE81 Ex:ZSTDts

5.Link message type and idoc type WE82 Ex: ZSTDS->ZSTDS01

6.Configure new message type in BD64 and generate partner profiles.

7.Develop custom outbound program.

Custom outbound program( SE38)

We can generate an IDoc by using an FM 'MASTER_IDOC_DISTRIBUTE'.

Inbound Process:(810)
1.Create Data Base Table SE11 Ex : ZADMS

2.Create a segment type WE31 Ex:Z1ADMS

3.Create Idoc type WE30 Ex:Zadms01

4.Create Message type WE81 Ex:ZADMS

5.Link message type and idoc type WE82 Ex: ZADMS-->ZADMS01

6.Develop a function module(INBOUND FM).

ex: IDOC_INPUT_DEBITOR to post customers for DEBMAS

IDOC_INPUT_CREDITOR to post vendors for CREMAS

IDOC_INPUT_MATCOR to post materials for MATMAS

7.Assign input characteristics for FM in BD51


8.Link FM to message type and idoc type WE57

9.Create inbound process code WE42

10.Configure partner profiles in WE20

Extended Idoc: standard idoc type with custom segment ex: DEBMAS07 with
Z1STDS

OUT BOUND PROCESS(800)

1.Create a segment type WE31

2.Create Extended Idoc type WE30

3.Link Extended idoc type with message type in WE82

4.link extended idoc type in partner profile WE20

5.implement customer exit for outbound program(BD12).

IN BOUND PROCESS(810)

1.Create a segment type WE31

2.Create Extended Idoc type WE30

3.Link Extended idoctype with message type in WE82

4.link extended idoc type in partner profile WE20

5.Implement customer exit for inbound program. "IDOC_INPUT_DEBITOR

NOTE: VSV00001 is a customer exit where we can enhance customer outbound and inbound
programs.

EXIT_SAPLVV01_001 : to add custom logic for standard outbound program(BD12)

EXIT_SAPLVV02_001 : to add custom logic for standard inbound


program(IDOC_INPUT_DEBITOR).
RFC &BAPI
RFC & BAPI: SYNCHROUNOUS data transfer across distributed partner systems

RFC : SAP to SAP

BAPI : SAP to Non-SAP


Program
FM
CALL Fn
DB
(SAP)APS1

RFC BAPI(FM------
interface
>METHOD)

APS2(SAP) JAVA(NONSAP)

CALL FUNCTION 'FM' DESTINATION 'APS1' OBJECT.METHOD

partner1 (SAP)-I/P--------> SAP (Program+ DBT)------RFC

partner1 (NONSAP)-I/P--------> SAP (Program+ DBT)------BAPI

normal FM ------> Remote FM (RFC)------->BAPI(FM--->METHOD)

RFC(Remote Function Call):

An SAP partner can use data of another SAP partner system thru a remote FM.

This FM must be remote enabled and released. It supports SYNCHROUNOUS data transfer.

Ex: 800--->t001--->186 records 810-->t001-->5 records

BUSINESS APPLICATION PROGRAMMING INTERFACE


:(BAPI) (FM --------> METHOD).
BAPI is an interface to transfer data between partner systems synchronously.

All technologies can support BAPIs which supports RFC protocols.

RFC FM SAP
BAPI
SAP FM FM-->METHOD

NONSAP

METHOD

ENDUSER ENDUSER

SAP GUI NON SAP GUI (JAVA)


APS2

BAPI(SAP-NONSAP)
RFC(SAP-SAP)

APPLICATION SERVER

(ABAP PROCESSOR)
APS1(SAP SERVER1)

SAP DB

BAPI = REMOTE FUNCTION MODULE + METHOD CONVERSION


normal
can be called with in SAP server
FM
Remote FM
can be called across SAP servers

can be called across SAP and


NONSAP partners

BAPI(BAPI explorer)---list of properly generated BAPIs.

CUSTOM BAPI:

A BAPI FM has to satisfy the following conditions.

1.All BAPI related objects have to be saved in to transportable package only

2.BAPI FM must be remote enabled and released

3.BAPI FM better to be saved into an exclusive function group.

4.All BAPI related object names have to start with 'ZBAPI_XXXXXXXX'.

5.In BAPI FM(SE37).

TABLES :

IT LIKE KNA1 (WRONG)

NOTE : we cannot use DDIC structures which has include and append structures as associated
types. Hence we must have to define a BAPI structure without includes and appends in SE11.

ex: ZBAPIKNA1.

IT LIKE ZBAPIKNA1 (right)


Source code :

SELECT * FROM KNA1 INTO TABLE IT.

6.All parameters of BAPI FM must passed by values only.

7.BAPI FM must not contains exceptions.

8.Hence each BAPI FM must contains one mandatory export parameter RETURN of

type BAPIRET1 / BAPIRET2/ BAPIRETURN.

9.RETURN collects all types of messages from BAPI FM.

10.We can convert the above FM into method in Business Object Builder(SWO1).

NOTE :ALL BDC programs depends on screen recordings. But few transactions are not handled
properly in recording. Hence we use BAPI as alternative concept for BDC to transfer data for
those transactions : ex: MM01,MIGO,MIRO...

EX: BAPI_MATERIAL_SAVEDATA. (To SAVE material data).

In BAPI FM program we cannot use open SQL statements like 'COMMIT WORK' and 'ROLL
BACK'.

Then we use following FMs as alternative for above statements

1.commit work ---'BAPI_TRANSACTION_COMMIT'.

2.roll back --- 'BAPI_TRANSACTION_ROLLBACK'.

Flow logic of a program with BAPI FM.

FILE---> ITAB

LOOP AT ITAB INTO WA.

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA' DESTINATION 'LS810'

exporting ......

........ .

importing

RETURN = RETURN.
IF RETURN-TYPE = 'S'. " success

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

ELSEIF RETURN-TYPE = 'E'. " ERROR

CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

WRITE :/ RETURN-MESSAGE.

ENDIF.

ENDLOOP.

SWO1 : Business Object Builder

WAP TO UPLOAD MATERIALS DATA USING A STANDARD BAPI

FLAT FILE FIELDS ARE GIVEN BELOW :


BC77 P FERT LCDTV KGS

BC78 P FERT LEDTV KGS

BC79 P FERT TV KGS

BC80 P FERT PLTV KGS

BC81 P FERT MOB KGS

BC82 P FERT DESKTOPCOMPUTER KGS

*&---------------------------------------------------------------------*
*& Report ZBAPI_UPLOAD
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZBAPI_UPLOAD.
TYPES : BEGIN OF TY_FILE,
MATNR TYPE MARA-MATNR,
MTART TYPE MARA-MTART,
MBRSH TYPE MARA-MBRSH,
MAKTX TYPE MAKT-MAKTX,
MEINS TYPE MARA-MEINS,
END OF TY_FILE.
DATA : I_FILE TYPE TABLE OF TY_FILE .
DATA : WA_FILE TYPE TY_FILE .
********BAPI VARIBALES
DATA : WA_HEADDATA TYPE BAPIMATHEAD,
WA_CLIENTDATA TYPE BAPI_MARA,
WA_CLIENTDATAX TYPE BAPI_MARAX,
I_MAKTX TYPE TABLE OF BAPI_MAKT,
WA_MAKTX TYPE BAPI_MAKT ,
I_RETURNMSGS TYPE TABLE OF BAPI_MATRETURN2,
WA_RETURNMSGS TYPE BAPI_MATRETURN2,
WA_RETURN TYPE BAPIRET2.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'C:\MARA.TXT'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = I_FILE.

LOOP AT I_FILE INTO WA_FILE .


******MOVE HEADER DATA
WA_HEADDATA-MATERIAL = WA_FILE-MATNR .
WA_HEADDATA-MATL_TYPE = WA_FILE-MTART .
WA_HEADDATA-IND_SECTOR = WA_FILE-MBRSH .
WA_HEADDATA-BASIC_VIEW = 'X' .
*********MOVE CLINET DATA
WA_CLIENTDATA-BASE_UOM = WA_FILE-MEINS.
*********MOVE CLINET DATAX
WA_CLIENTDATAX-BASE_UOM = 'X'.
* ***** MOVE MATERIAL DESC DATA
WA_MAKTX-LANGU = 'EN' .
WA_MAKTX-MATL_DESC = WA_FILE-MAKTX .
APPEND WA_MAKTX TO I_MAKTX .

CALL FUNCTION 'BAPI_MATERIAL_SAVEDATA' destination 'ETSCLNT900'


EXPORTING
HEADDATA = WA_HEADDATA
CLIENTDATA = WA_CLIENTDATA
CLIENTDATAX = WA_CLIENTDATAX
IMPORTING
RETURN = WA_RETURN
TABLES
MATERIALDESCRIPTION = I_MAKTX
RETURNMESSAGES = I_RETURNMSGS.

IF WA_RETURN-TYPE = 'S'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
WRITE : / WA_RETURN-MESSAGE .
ELSEIF WA_RETURN-TYPE = 'E'.
LOOP AT I_RETURNMSGS INTO WA_RETURNMSGS WHERE TYPE = 'E'.
WRITE : / WA_RETURNMSGS-MESSAGE COLOR 6 .
ENDLOOP.
ENDIF .
CLEAR : WA_FILE,
WA_HEADDATA,
WA_CLIENTDATA,
WA_CLIENTDATAX,
WA_MAKTX,
WA_RETURNMSGS,
WA_RETURN .
REFRESH : I_MAKTX , I_RETURNMSGS .
ENDLOOP .

WAP TO CREATE A SALES ORDER USING A STANDARD BAPI


*&---------------------------------------------------------------------*
*& Report ZBAPI_SALEORDER
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZBAPI_SALEORDER.

DATA : HEADER LIKE BAPISDHD1 .


DATA : HEADERX LIKE BAPISDHD1X .
DATA : I_PARTNERS TYPE TABLE OF BAPIPARNR .
DATA : WA_PARTNERS TYPE BAPIPARNR .
DATA : V_VBELN TYPE VBAK-VBELN .
DATA : I_RETURN TYPE TABLE OF BAPIRET2 .
DATA : WA_RETURN TYPE BAPIRET2 .

*********HRADER INFORMATION
HEADER-DOC_TYPE = 'TA'.
HEADER-SALES_ORG = '1000'.
HEADER-DISTR_CHAN = '12'.
HEADER-DIVISION = '00' .

HEADERX-DOC_TYPE = 'X'.
HEADERX-SALES_ORG = 'X'.
HEADERX-DISTR_CHAN = 'X'.
HEADERX-DIVISION = 'X' .
**************PARTNER INFORMATION
WA_PARTNERS-PARTN_ROLE = 'AG' .
WA_PARTNERS-PARTN_NUMB = '0000001175' .
APPEND WA_PARTNERS TO I_PARTNERS .

CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2' " create a sales order


EXPORTING

ORDER_HEADER_IN = HEADER
ORDER_HEADER_INX = HEADERX

IMPORTING
SALESDOCUMENT = V_VBELN
TABLES
RETURN = I_RETURN

ORDER_PARTNERS = I_PARTNERS .

IF V_VBELN IS NOT INITIAL .


WRITE : / V_VBELN , 'IS CREATED ' .
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.

ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
* IMPORTING
* RETURN =
.

LOOP AT I_RETURN INTO WA_RETURN .


WRITE : / WA_RETURN-MESSAGE .
ENDLOOP .
ENDIF .
ALV REPORTS WITH METHODS

By using methods ALV reports can be displayed on dynamic screens along with additional
screen elements.

Procedure:

1.Design a screen(SE51) with CUSTOM CONTROL and name it.

2.Initialize the above custom control using a standard class


CL_GUI_CUSTOM_CONTAINER.

3.Initialize ALV GRID on the above container using a standard class


CL_GUI_ALV_GRID.

4.We can display data of an internal table using a method


SET_TABLE_FOR_FIRST_DISPLAY.
FILE HANDLING :
We can handle files from Presentation server & Application server.

PRESENTATION SERVER:

* These files are called flat files

* These are available on Our system (C / D / E drives)

* We can Handle them using FMs 'GUI_DOWNLOAD' & 'GUI_UPLOAD'.

APPLICATION SERVER:

* These files are called Sequential files or data sets.

* These are available on AL11

* We can handle them using 'OPEN DATASET' , 'CLOSE DATASET',

'DELETE DATASET' , 'TRANSFER' , 'READ'.

NOTE : Default directory for data sets is ' . ' (DIR_TEMP).


TYPES OF PROJECTS

You might also like