ABAP 1.o PDF
ABAP 1.o PDF
ABAP 1.o PDF
i
1. Intrsducti~aato SAP 06
2. ABAB Data Dictionary 60
3. Introduction to ASAP
Programming 89
A
TG CnGf-tnj p t a p r l p ~ g r r . - e s
-== ~r -2 -6,fi =--&&= 12
5. Strings 4
7. Open SQE
8. ABAB Debugging 13
9. Reports 74
10. Pdodularizing Techniques 44
lntroduction to SAP
We Never Compromise in Quality, Would You?
:nlroduction lo SAP
1 DEMO 1
SAP was founded in 1972 in Walldorf, Germany. It stands for Systems,
Applications and Products in Data Processing. Over the years, it has grown and
evolved to become the world premier provider of clientlserver business solutions
for wllic11 it is so well known today. The SAP R13 eilterprise application suite for
open clie~lt/sel-\/el.
s!,steliis has established a new standards for providing b~lsiness
infb~.mationmanagcllienl sol~~tions.
The main advantage of ~lsiizgSAP as your coinpaily ERP system is that SAP has a
very higlz level of iiztegration alllong its individual applications, wlzich guarantee
consistency of data througlzout tlze system aizd the conlpany itself.
These applications are called the f~lnctionalareas, or application areas, 01- at tiines
the functional inodules of Rl3. All of these terms are synonymous with each
other.
Traditionally. b~~sinesses asseizible a suite of data processing applications by
evaluati~igiilcli\~icl~i~~l
procli~c~s
and bu) ing Lhese separate l~roducrsfrom multiple
software \~endors.Interfaces are then izeedecl between them. For example, tlie
materials management system will need linlts to the sales and distribution and to
the financial systems, and the worl<flow systeizi will need a feed from the HR
system. A significant amount of IS time and inoney is spent in the implenzentation
and maintenance of these interfaces.
1U3 conies prepacl<agecl with tlie core business applications needed by most large
corporations. These applications coesisl in one homogenous en\/ironmeiit. They
are designed from the ground LIP to run using a single database and one (very
large) set of tables. Current production database sizes range from 12 gigabytes to
near 3 terabytes. Around 8,000 database tables are slipped with tlze standard
delivery W3 product.
SAP W3 overview^
SAP W3 is SAP's integrated software solktion for clientlserver and distributed
open systen~s.SAP's R13 is the w-orld's most-used standard business software for
client/server computing. W3 ineets tlze needs of a customer from tlie sinall grocer
with 3 users to tlze multi-billion dollar coizzpanies The software is highly
Page 2 of 6 By Ganapati Adi~nulam
lydel-abad
eMirs ':'ec:inologics,An~eet-!)ct,I
Ph No :+91 30 -65976727, Cell No : 99484 44808,98490 34399, www.ernaxtech.com
lntroduction to SAP
We Never Compromise in Quality, Would You?
lndusfry S o/utiorrs
Cag~:lprehe,~sive
,8.
', , ,, ;
! i '5
SAP l r i ~ m r ~ e c'.,
,' "
., ,'
5
, -
__..,
i
~ .'.. . .if Calas~'
. 1
Definition
The R/3 System has a specific architecture with a specific set of logical services.
Structure
In the three-tier, clientlserver architecture of the W3 System, there are three
service layers:
IDES - the "Intenlet Denlonsti-ation and Evaluatioil System" in the R13 System,
represents a 111odel company. It consists of an iilternatioiial group with
subsidiaries in several countries. IDES contaiils application data for various
business scenarios Illat can be run in the SAP System. The business processes in
[he IDES syslem are des~gnedto retlect real-life business requirements, and liave
access to inally realistic cl~aracteristics. IDES uses easy-to-follow business
scenarios to show you the comprehensive f~~nctions of the R/3 Systen~.The focal
point of IDES, however, is not the f~~nctionalityitself, but the business processes
and their integration.
These IDES business processes are described in detail within this online
docui~~entation.The individual deillos provide you with an overvieu~of the master
data, and coiltain step-by-step instructioi~s of how to execute the individual
processes.
IDES not only covers the Logistics area, but also Fii~ancials, and Hunian
Resources. It delllollstrates how the R/3 Systein is able to support practically all
types of industries, from discrete production tl~rougl~ to process industries, from
ellgilleel-ing-to-order to repetitive manufacturing. However, IDES is not a sector-
oriented illode1 compaily. The iiidividual processes are based on practice-oriented
data for sectors such as Retailing or is managed by SAP just as any regular
business enterprise. SAP regularly updates the IDES data (master data,
transaction data, and customizing). Banking. The IDES group inanufactures
products as diverse as elevators, motorcycles, and paints.
IIIES We also carry out period-end closing aild plan with different time-horizons.
Transaction dala are ge~lzl.atedto ensure tlml Llle information systems in all areas
have access to realistic eval~~ation data. We are constantly in~plementingnew,
interesting business scenarios to highlight the very latest f~1ilctionsavailable in the
R/3 System. New fuilctioiis are represented and docunleilted by IDES scenarios.
Above all, IDES shows you the possibilities of the integrated applications in the
SAP System. It Covei-s all aspects of a business enterprise, including Human
liesources, Financial Accounting, Product Cost Planning, Overhead Management.
PI-ofitability Analysis, I'lanning? Sales and Ilistribution, Materials Management,
Production, a i d much, much more.
IDES shows you how the R13 Systeni s~lpportsproduction processes, the supply
chain, and the efficient usage of global resources. Or perhaps you would like to
increase your ~ulderstandingof just-in-time-production or the iiltegration of the
electl-onic I<ANI-i,4N s) slein in an MKP 1I en\lironment? IDES pl-ovides the ideal
%la) LO 1znr11 abo L I ~ dress such as Prociuc L C'OSL Conlrolling, Activity -Based
Costing, or integrated Service manage men^ and Plant Maintenance. How to
illanage lligll inflation is just one of tlze ever-growing iluiiiber of IDES business
scenarios that you call choose from.
a. Purpose
b. Types of Tab
c. Technical Requirements to
create the tab
d. Data Dictionary Data Types
f. Data Element
g. Steps to create the table
h. Structures
i. Foreign key Re ationship
j. Views
k. Lock Objects
ABAP Data Dictionary
We Never Compromise In Quality, Would You?
ABAP Dictionary:-
The ABAP Dictioilary ceiltrally describes and illailages all the data definitions
used in the system. The ABAP Dictionary is coillpletely integrated in the ABAP
Worl<bench. All the other coillpoilents of the Worltbeilch can actively access the
definitions stored i l l the A H A P Dictional-\..
ABAP Dicliollary supports the clefillition of user-defined types (dala
elements, structures and table types). You can also define the structure of database
objects (tables, indexes and views) in the ABAP Dictionary. These objects can be
autoinatically created in the database with this definition.
The most important object types in the ABAP Dictionary are tables, views, types
(claia elements, stn-uclut-es, 2nd table types), domains, search helps and lock
objects.
Purpose
Data defiilitioils (inetadata) are created and inanaged in the ABAP Dictionary.
The ABAP Dictioilary perinits a central description of all the data used in the
system ~ 1 i t h o ~redundancies.
t N ~ M01.J modified illformatioil is automatically
psovideii for all ~ l l e S ~ ~ L L~"oI~~i ~ ~ u l i e This
i i t s . ziisures data integrity, data
coilsisteilcy and data security.
Tables are defined ill the ABAP Dictioizary iildependeiltly of the database. A table
having the same structure is then created fiom this table defiilitioil in the
underlying database.
A table definition in the ABAP Dictioilary co~ltaiilsthe followiilg compoileilts:
a 'l'abie i'ieltls define ~ l l elield ilanles and data types of the fields contail~ed
in the table
Foreign keys define the relationsl~ipsbetween the tables.
Technical settings control how the table should be created in the
database.
Note: A Table is Simply Group of fields aiid which call store liiultiple records.
Table
1) Create the Structure of the table i.e the list of Fields and their
Technical attributes such as Data types, Lengths a n d Descriptions.
2) . , ~ IViemoi-y !'or
~ i j ~ - . . the ihe above tabie structure irr Database.
Delivery Description
Class
-- - -- - -- -- -- -
-
A
--- - - - - . - .-
Applicatioil
.- -- - --
table-
(master and transaction data) -
.
L -- -- ---
Table--
for storiiig
- -
--
temporary data, delivered
-
empty
-
Data Class: - It is the physical area or table space that the table has to be stored in
the Data Rase.
1- ELL
- -- --
USER
--
-- --
Transaction data, trailspareilt
Organizatioii and customizing
Custo~ller
- -
Data Class ---
-
tables
- -- --
ppp
Size Category- The size category defines the expected space required for the
table in the database. You call choose a size category from 0 to 4 for your table.
Each category is assigned a certain fixed ilieinory size in the database, which
depeiids on the database sj~stemused.
-- -- --
Size I Number of data records of table expected
Note: While Creating the 'l'able, We Call Provide the teclinical attributes such
as Data type, Length and Description of the Fields in 2-ways (Refer the below
diagram).
Table Table
Data Element
Data Elellleiit
b) 2"d Way is providilig the teclinical attributes tl.lrougli Data Elements and
Doniaiiis.
i.e Provide the Data type. Length and Description by grouping into Data
Zlemeuls and fion-nains.
Note : We Never Provide the Technical attributes of the field using Direct
type instead it is always through Domains and Data Elements.
Customer No
liilt;~Dictional-y i l i ~ l 'l'jrpes
i~ ileips lo CI-ewtethe Uomains:
Accouilt No
...~
~ ~ ~ ~
the Vendor
ORTO 1 C I-IA I? City
1 - - - - - ..
1
&I02
-I 35 District
:--L'
STRAS C A I 35 House
Number &
- - -- -
Street
LAND 1 CHAR 3 Country
I I Key
Domains and Data Elements Required to Create for the Above Table :
Data Elements:
Si~iccall the fields I.IFNR, NAME], OKTOI, ORT02, STRAS, LAND1 require
U n i q ~ ~Descriptions
e we need unique Data Elelllellts for each Fielcl.
-- - - --
- -~ilGl Name
- - ._-_
-r
-L..Oats Element
- - to Be Created
-
_ -
-
-- -- .-
.
-
1 ZGORTO 1(City)
~ ~ 6 k- ~ -
0-2-
-
.- - - -
- -
( l l i s t r i c t-
. - --
i
1 -
STKAS
LAhTD I _ L
ZGSTKAS(HOUS~
%GLANDI( ~ o ~ l i ~ t r ~
~urnbe& r Street) 1
em -.
DOMAINS: Since all the Below Fields have the same Teclmical Cl~aracteristics
(CHAR, 3 5 ) , One Domain is enough with the Data Type CHAR and Length 35.
NAMK5. <3il~K35
OR'l'Ol CIlAR35
ORT02 CRAR35
STRAS CHAR35
Page 7 of 60 By Ganapati Adimulam
eMas ?'echnologies,Anieel-pet,IIyde~-abacl
Ph No :+91 40 -65976727, Cell No : 99484 44808,98490 34399, \\ip.i:w.crnaxlecla.c0111
ABAP Data Dictionary
We Never Compromise In Quality, Would You?
No\$, We are ready ~ v i t lall~ the Ijomains and Data Elements Iiiforillatioli so that
\ \ e can stair crealing the ~ a b l c
Create tlze Tnble Using tlze Following Domains & Dntrr Elements:
Data
-
Element
-- ---. - Domain
-- - -- -- - - -
ZGLlFNK ZGCI-IAR1 0 - -
LGNAME 1 LC~CHLR~~
ZGCHAII35
ORT02
--
ZGORT02
STRAS
--
ZGSTRAS - ----- - --- -. - -- ----
LAND 1
-.
hotel:
We will create all the required Domains and Data Elements first so
that we can simply provide the same while creating the Table.
Character string
P.10. characters 111
D F! I:: i 1-r-I a l 111I a c F! s 0
.................................. -.................... i
3 Dala element
..................................................
Stroctur~
lP<i.,I,?ly(j,>
. . -
iklFX ( I ) <E:,30! b = ?,,,A\:at,a(j2 lI\lS ......
.., . ,
,-stJltJ 3 '3
, Y '
~ , , ~ ~ ~ ~ j t ; A~ ~ ~A P~u i c: t i o; ...... ; i - ~ . x n-t/
~ ~ ~,unt,tlod $ 3 31.18ciosoft...
- -/ .'<;c;Cji
....... ~ ~ : ~ ~ , ~ c c c c u r ~ ~ a a t . . .
.1:31 fib,
C<JI.?I,;l:#f
~..i.ngii-, 0 I I . ii
Data tgpe
Lsnytll O Decimal laces
Reierence t;pe
RcfsreiIcc t o
Enter the 'Short Text and the Domain which is already created ZGCHARIO.
Press ENTER After Dolllain is entered . So that it Copies the technical attributes
from Domain to Data element.. Save, Checlc and Active the Data Element..
Length F I ~~.ril:,cl
I ~
Sho1t
Medium
Note :
Repeat the Same Procedure to Create all the Domains and attach
the Domains to the Corresponding Data Elements while Creating
the Data Elements.
Data l y p n
Enter the fields which are mandatory like 'Short Description', Geiivei-y class as
'A' ,and Check Table Maintenance Check Box in the screen as shown below.
; fi 0i os
6.- &;':rt~ 4, ' $6 Techn~calsett~ngs 1nde::e; .A.l?l~?nd
slluctute.
. . . . .............. . . ., ., , " ,. . .
, ""
Table c a t e g u l y T r a n s p a r e n t tal:~le
Delivery class A
..........................................................
''@.TsDle rr~alntananceallowed
........................................................
i
2)c o , 12 of
n,c 60 By Ganapati Adimulam
eMas l'eclinologies,An~ee~-pet,IIyclerabacI
Ph No :+91 40 -65976727, Cell No : 99484 44808,98490 34399, ~w.emaxteeh.6c~~11~xtecb.coz11
AUAP Data Dictiotlal-y
We Never <:orn~romiseIn Oualitv. Would You?
3) Provide the Field name and the Data Eleineilt for LIFhTR i.e ZGLIFNR
.\vl~ichis already created
Press Enter after entering the Data Ellement so that we get all the
information attached to it (Data Type, Length, Description).
Observe ZGNAMEl Data element is not yet created. To create it double-Click 011
the Field tl.pe(Jlata Element).
Note: Now cve are going lo create the Data Elements using Top-Dow-11.
Provide sl~oi-ttext and domain name ZGCHAR35. Double click on the donlain to
create it.
D 111n-1a i n
Short te>$
Press F3(BACK)
Note: Malce sure that the Doinail1 is Activated Before going back.
Note: After F3 we are at Data Eleil~eiltscreen. Save, Checlc, Activate the Data
Element.
11
IL Length
<
:
3
- Ciecirn:31 place: [I
jj
Data t!ipe
Lengtl-I 13 Del;ir'r-~al ~:~lar:es 13
- Eeierenie P$:;y:~tr.
.. :..
c. .
:I L,0+.3 t 6 ,-,,-.G t,-, j !
Save , Check and Activate.( Now the Data eleinent ZGNAME1 is activated).
Press F3 to go back to the Table Screen.
Open the Database Table in Chai~geMode, i.e Execute S E l l and Provide the
Nanle ol'the 'I'able and Click on Change
Select the Row i.e where you want to JNCLUDE the Structure and tl~enclick 011
'+' or 'New Rows' button
Path to iuaiiltaiil tlie Data on the Table Utilities -> Table conteilts -> C~-entt.
Above screen is displayed. Enter the Vendors details. After eilteriilg save Ctrl + S
or Press Save Ruttoll to update the table contents.
Reset
--- - -- -- - - -- "- -
ACCOilnt 112345
Path to view the conteiits of the table. Utilities -> Table Contents ->Display.
I~:~IIII~~I,:
,.~~J,TI !
Attributes Field Gr;il,hlc
-
Press F8 for all the records or provide the Required Vendor Account No's and
then Execute(F8).
Vet-(dor A ~ ~ n u Ikiu
n t Iblarnr O f ti-IB"andnr- C i t y Dist.
- . -
1 %-
- - - - ----
S - .- -
STliAS
T
-
I
A hTni
L l Y U l
-
LAND 1
The central definition of structures that are used nlore than once iilaltes it possible
for them to be changed centrally. The active ABAP Dictionary then rnaltes this
change wherever required. ABAP programs or screen templates that use a
structure are automalically adjusted wlie~ithe structure is changed (see Runtinle
Objects). 'T'his ensures tlie greatest possible co~lsiste~lcy
of the data definition, also
for complex programs.
Eyecute Sk1 1 . C'lick on the .Data 'E').pe' o p t ~ o non the screen Enter the Name
and click on 'Create'.
Press Enter.
Dfi;li62ijn,j;,;9jj;2j&j&f;,. z;,*ur-grgre
"9q3 @ ' . 6,I ,", & i . Hierarchy display Append structure
NOTE: Here all the coinponent name start with 'ZZ' as per the SAP
Recommendation.
Please Malte use of the Data Elements which we already created for the Sanie
Save, Check, Activate Afizr Providiiig all the Coniponents and Conlponeiit
Tv~es.
Open the Database Table in Chai~geMode, i.e Execute S E l l and Provide the
Nanle ol'the 'I'able and Click on Change
Select the Row i.e where you want to JNCLUDE the Structure and tl~enclick 011
'+' or 'New Rows' button
API'I<ATI1Sfrc~cfL[I-e:-
Here as we use 'BWd'l1,1JDl3' structure fbr custoiii table or user defined
table, we use 'APPEND' Structure for adding tlie required fields for the standard
database tables.
Note : Even adding one field to the standard table also should be done via
APPEND Structure
Click on 'Display'.
@.
.............................
iryap?~?l~flt.!~!!? TCIO'I Actwe
..
.;l~urt descrlptlon c:ompany codes
,&.~:lpet-~~_l -:.ttucture .
Tl~enclick on the "-- - ---- b~~ttoll
011 the 'Applicatioi~Toolbar'. Then
follo~vinyscreen appears.
i
"&, 1'
LO
; . 6% a "" 8 Teclinical set!jngs Indeves . Append stiucture ...
TI-ilnspar~t
....... ;
:sl,,>lloe.i5c --... - - . - - .
. -.-- .. . . .
-.
1lie11 click on the 'New Appelid S L ~ L I C ~ L I I - e ' lor appeildiilg structure to the
-
standard Database table.
Enter the structure llallle slartiilg with '2'or 'Y'. Then say 'ENTER' or click on
NOTE:- When ever we are saving the 'Structure' while using APPEND
remember to save it in a transportable development class(1t will be provided
in REAL, 'rime). Do not save it in LOCAL OBJECT as it is not
'Il'ransportablefrom Development server to further.
Save the Structure, 'Check it' andl Active'. Then coiile back to tlie table screen
by pressiilg F3 or the back button.
,, . , .,,, , .
&;,,;;;sf~;;, K:?; ,, :=;,;ag ;ac;:c;;
+ t;---
I CD = &2 : +:. 3 , k@ @ @ Techn~cal.?ett~r~qs I n d u x ~ s. Append stluctuie
... , G;p
-.-. ............. ... ----.,---*--,---- ,-- . . . . .
.............................
............................tnblei
:Transparent TClCll Active
S T ~ o litl c ~ c ~ l p l i u n i'o~npalry Coclcs
....
. S ~ I I ~ - I J SFiclds
' : C~~i~cncy/z-luani
lic.lils
I
Let us analyze the situatioil where we have to create the foreign key Relationship
Elltries in
!
- .. . - . . -
-
~00002
~- ~ - ~
Clarion
... ..
Park -
Hyderabad ~
Note: This is the nlaster table for vendors i.e. these are the only vel~dorsthat we
deal always.
ViF-rLIFNR AMOUNT
-- .
Note: The system accepts this purchase order details if we don't have the Foreign
Key relatiollship between ZGPURCHASE, ZGLFAl. But in business sceileriao
it sl~ouldnot happen to lllaiiltain the purchase orders for the vendors w l ~ i c are
l ~ not
illaiiltained in the nlaster table. This should be always avoided and this oilly
possible flu-ough establisl~inga Foreign Key relationship betweell LIPNR of
ZGPIJKCllASli: ancl %GIIII'A1.
a) The Don~aillnames of the field in the Foreign Key table and for the field in
the Check table sl~ouldbe same.
Step I . Ope11 the Foreigii Key table and select the Foreign ICey field. Click on
~:>j(,;$j<>f':,*~,y: 'Ti%j,dj4.:
T r a n ~ [ 3 a r e nT
t BI~IC --
LI~PURCHASE Actl\'e
BhurL deb~rll~liiln Purcl-sass table
Short text
c.~,~cI, tirole
--- e
> L#I
,,J. - -
~ .. -l l ?I-.
Il rl lj
illoh-lie ; - f i e l d s i s a n d i d a l e s
l i e . .t~elds;cand~dzte;
Key t i e l d s of a La:L t a b l e
Provide the Check table iiaiiie, short texL and Click on 'Generate Proposal'
button.
The system Generates a Proposal with the Foreign Key and all the Primary Key
fields fsoni Check table whose Doinail1 name are same with the Foreign Key
I 1o111ail1.
Press 'Enter' or click on the 'Copy' buttoil. Foreign Key relation is established
between Z 6 1 , I ~ A Iand %CP8JR<:HASE
T ~ -- ? - - table
<rr~..jldient
- ZC;PUF.:CIIASE Active
S h o ~ descri~tior-I
t Purchase Labl~:
Att~lbutos Fields f , ~ l ~ ] ~
C~~~r~1i,:y;r~11:,~~1.
, ,
'rTiooei.;no ...,
Fon-cign Key:- This \vill be triggered Lhrougll GUI only i.e. the data
%rill be validated ibr the input provided through screens only . It will not
validate the Foreign key relation wl~enu Insert the data into Foreign ltey table
through Open SQL that is the reason SAP always suggest to update the Data Base
Tables o11ly through Trailsactioizs (Screens).
When we are worl<ing with iiiternatioilal custonlers and Veildors if you provide
only the Anlount figure i.e. 1000, but is not enough as it is not clear whether it is
1000 INR,1000 USD,1000 EUR, 1000 MYR etc. So you have to always provide
the currency ltey(IhTR,USD etc),when we are worlting with Amounts.
Note : When the Ai-nount Fields are created by using Data type CURR and the
Quantity Fields by Using QUAN. Then only the systeill expects Curreilcy
I<ey(CUKY) as reference for Amount and Units ltey(UN1T) as reference for
Quantity. This is must to create a table Currency and Quantity fields
lqield~ame ~ D ~ ~ T Reference
I
-
Data type
--- -
AMOUNT
i
1
'l'ype
- --
CUKK
--
I --
-
CUKY
UNIT
--
- I
Note : Now w-e will add Quantity Field to ZGPURCEIASE.
Operl the :.able ZGPURCI-IASE in Change h/lode and Click on New Rows to add
[he Quantity Field.
Transl:~arent t.rible
--
LI;F!JKI:I [::I Ina~:tl-eiFevisedj
Short clcsil'iption Pt~i-iii;rst?tal-iie
Create Data element ZQUAN and When you create the Domain , n~altesure that
the Data Type should be Q'EJAN as below.
And also create another field(Referei1ce field for Quantity) with Data type UNIT.
Wheil you create reference field dolllaill for Quantity , make sure that the Data
sl~ouldbe lJNIrl'as below.
TZS. r..
,&
.
.c7aiL;:sr! ~5
....-. Cc.%*&?-:,i?.--i
. . . . *_-
-r.,,.a ._,,_
--:;:
a ,.,?. iF;+?:-. . . ..lS<7^ -?.
A ~ Z ~ " r.
,
r:
-_ _
. ,. . ., ... ,..."is..- $..! _.,"F " .--
:,
,
(.
i
!-:,.
ZLJV.liT5
....... -..
Data t',,jpe UI~IIT
I l , i ~ ~ , l ~ ~: ~ I ~ ~ . , ~ I , ~ II .I . I, I. ~ ~ - ~ . n
Note : Repeat the Same for AMOUNT field it is 'CURR' and for Currency
field it is 'CUKY'.
i':':~~~rencii/quant
helijs
Now click on rlie lab
Dktj/3f223219,; #Jqaig$agx,Iz:fjfie
+ ; c-9
+ G-.
& + : 1 @ tf8 Tecl-meal settlrogs I~lde,:es..
-.
;6 ; :?.: '.:;r: ,.:
--
T r a n j p a r r n ~t a b l e LP(lF,CH-SE IUW
Slrm-s#L ,.ie::m:,.~l.,Lim:mj) Fl-~rm.I#:r.:.~
1.31.(1?
This is how 'Currency And Quantity Fields' are related to the units of the
particular fields.
Views
Views are logical views on more than one table. The structure of the view is
defined in the ABAI' Dictionary. A view oil the database call then be created from
h i s structure.
-
51 Data aboul an applicalio~lobjecl is ot~eildistributed on several tables
e By defiliing a view, you call define an application-dependent view that
combilles this data.
The structure of such a view is defined by specifying the tables and fields
used in the view.
a Fielcls that are not required can be hidden, thereby minimizing interfaces.
e A view can be used in ABAP programs for data selection.
View o n t h e t a l , l c s
The data of a view is derived fro111 one or more tables, but 11ot stored physically.
7he simplest forln of del-iving data is lo ~ ~ ~ aout
s l one
i or more fields from a base
[able (projec~ion)or to include on)) certain enlries of a base table in the view
(selection).
Four different view types are supported. These differ in the way in which the view
is iinpleilleilted and in the illethods permitted for accessiiig the view- data.
Database views are iniplen~entedwith an equivaleilt view on the database.
Data about an application ob-ject is often distributed on selfera1database tables. A
database view provides an application-specific view on such distributed data.
Database views are defined in the ABAP Dictionary. A database view is
autonlatically created in the uilderlyiilg database when it is activated.
Open SEl 1, select the option 'View' 011 the screen . Enter the name of the 'View'
to be created and click on 'Create'.
...........................................
:...................................
c G,3t~b:rc.c ule,,,:
P i o ) e c t ~ o ~w. ,e v i
liilaintel-iarlie ~ l e - . , ?
Help ,vie,$!
.g Copy X
Click on tlie Database View and say 'Enter' or click on the 'Copy' button.
Enter the Short text and table names in tlie 'Tables' for which view lias to be
created.
Select the tables ii-om \.\/here -\we derive the Vielv aiid Click on tlie
Click 011 the 'Copy' buttoil or press 'Enter'. A list of fields whicli are having
foreign ltey related fields are displayed.
1 ,p; tl I] ,:.
Then click on the lab to select Ille list of the fields from the tables
that are to be displayed along with Priillary and Foreign Key Fields.
Note: Here either we illailually enter the field names and the table naines that are
Tatile fields
l o bedispla~edor \\e can clicl; where the systeill proposes
the tables. Fro111 there we call selecl the lields fi-om each table.
.. .
". .. . -, . . .,. - .. . . -.
if??;,,:,4"-#4/,'2y,,.-e
nLz42;,, "',,'. - ~zi;r$%,Ji%,,&
/" ;&<.i:
y <0' e a=;&%
b-- " + ' & %, 'S!Em
. ., ,,,,,,..., ....... ... ...... ,.........,...."."" ... . . .. . .. .,.... ", ,,,.,,,,,, ..,,,,,.,,,,,,,,,,, ,,,,,,,,
.,',
,, ,,,, ,,,,,, " " " "" " " ", , ,
Oatabase \.(IE)!~
-. .
L~,'JEI~IL~CIR i.,Je-. - .-
,,,*.jP~e,!,>cl.
~ r , o jt te t 'V~miu'fromZ G L F A I anii ZGPl.IHCHGSE
Click on the Table, and 'Choose' button. List of fields of tlie table are displayed.
Select the fields and say 'Copy' or press 'Enter'. And again Click the buttoil
"L'wble 1;Ields' Tor selec~ingthe fields fi-om the seco~ldtable. Select the fields
iro111 the secoild table say 'Copy' same as the above.
Projection Views
Projectio~lviews are used to hide fields of a table. This can illinimize interfaces;
for example when you access the database, you oilly read and write the field
coilteilts actually needed.
A projection view coiltai~is exactly one table. You callnot define selectioil
collclitio~lsfor projectioll views.
There is no correspoizdiilg object in the database for a projectio~lview. The W3
Systein maps the access to a projectioil view to the correspo~ldiilgaccess to its
base table. You call also access pooled tables and cluster tables with a projection
view.
Table definition in
the ABAP Dictionary
Projection view
on table
: f
\ ACESS to data 3 t h
'\ datat~aseinterface
The maintenance status of the view coiitrols 11ow the data of the table call be
accessecl \\!i111 the prqjeclio~ivie\?.
Steps '1'0 create Proiection View:-
1) Execute S E l l and select the radio button View and provide the View
Name.
Dalabaae table
L' ::is\.. ZG,,!ENDORJ
t2.
Domain
S c s ~ c hi-#ell:t
1-08 k~ ob,i:cl
-
SAC'IJSER *- rlq~jnnlm?rk IF15
Click on Create and lllalte sure that you selecl l'rojection View Radio Button
,'Enter'.
IJl?llllT,,,1IIZC, .,e.::.
Help >:ir*.:
A - Advanced
f- I I
B - Business To Work With
A - Application(s)
(- P - Programming
@
,
:,
,,
,
Prr~jectiunvie\,\,
-~ c-.; v. C t ~ 0 r ) R Active
S h ~ ttext
t v e n d o r Prnlrctiun \:!e',!i
6
. . . .
3 .,; . <& (3(g> ,:
....
, UAyJQB mm Q]@g
@><; fi&g2cj<;;~~c>rv> ;;$f&rBg;#,~~f,jfj "5;$ds;fc,Tj
s *:' W .:
d P;r a. set oilists
....................................................................................................................................................................................................................................
'' -i F!!3 Piepostor>,, Information S y s
> El~l..i-- * - e t ~ i y ~ t - ~ e e ~ - l ~ t g
- I/.,E:AFI leas[lirtlonjr'?i
- 2 ti~l..ll. ,L<l:q:,
Iz'1 I ' 11,I.l.~l I 8I~~la:.
. :,;,: .
IF;*; ~
.............
@ oat3 ?lei-nents
B str-uctilies
@I
Taljla P>:pes
O Domains
Srarch r~elljs
B LOCI( oijjects
6 1Otl-lei. o b ~ e c t s
? A Flclds
. . . . .J ~ - ' ~ ~ ~ ~ I I ~ ~ I - ~ I ~ ~ I I ~ ~ I
1 j'\.r;,;p # - ) I , l WI8~,
A El~l..ilr-.
V i eiw n a l n r Sttor t t e x t
-.
.. -
....
1 ~ TC;'
; ,!EI.IDOF; i f e l - ~ d o rP r o ] ect, or-, l'i ew
Execute.
Final Output.
. . . , ,, :;, '.,,,' :
. . , .. : . . . - ...,-,.
, ,.:;:., EL:.
....... i 7 :
,
i - ' .., , , . .,
-
~
[iilsse 1 do]-f
I?IIII?AGO
H itrlburg
I;:TIIF:I?CK
E:e,. 1 iI-,
Fral-rkful-t
Eosrnl~ri,ri
St~~ttgal-t
..... W 1 Luiidond
i,lentiheini
Frankfurt:I'iain
Hannover
Lock Objects
The RJ3 System synchronizes simultaneous access of several users to the same
data records with a lock mechanism. When interactive trailsactions are
programmed, loclts are set and released by calling functioli modules. These
i i ~ ~ l c ~ lllodules
ion are au~oli~alically
generated fro111the defiiiition of lock objects
in the ABAP Dictionary.
I,ock Arguments
The loclc arguineilt of a table ill the loclc object consists of the ltey fields of the
table.
The loclc argument fields of a loclt object are used as input parameters in the
f~lnctionmodules for setting and renloving locks generated from the loclt object
cle tin~tion.14"\'1e11thesc f~tinctionmodules are called, the table rows to be loclted or
~1111ocked are specified by defining certain values 111 these fields. These values can
also be generic. The lock arguinent fields therefore define which subset of the
table rows sl~ouldbe loclted.
A loclc inode can be assigned for each table in the loclt object. This inode defines
how other users can access a loclted record of the table.
e3 Lock Mechanism
A.BRANCHING
2. CASE-WHEN -
B. LOOPING
1. Conditional (DO-
ENDDO)
2 . Un-Conditional
(WHILE-
ENDWHILE)
ABAP Data Dictionary
We Never Cornpromise In Quality, Would You?
-<.\
Lot:$: t a b l e
Ta blr T A B
1.Z.l I.:.': [:,.I
- --
I er! fields
This loclt procedure requires that all prograins involved cooperate. Iiiconsiste~icies
can occur if a prograiil reads or changes data without liaving previously loclted it.
When a loclt is set, the data records are only protected against changes by another
program if this prograni also requests a loclt before accessing the data.
Instead ofvvritiiig lock requesls or lock releases directly in [lie lock table, it is also
possible to collect tlieiii first in a local loclc container. Tlie collected loclts can be
sent at a later time as a group. A paraiiieter of the relevant fuiictioll module
controls whether a loclt request or loclt release is sent directly.
You can find further iiiibrl~iation about tlie loclt concept aiid liow loclc
management worlcs in the documentation The lU3 Lock Concept.
You call tlieli use the short text to find the lock object at a later time, for example
with the W3 Repository Iilforillatioil System.
PL,lrct
LOCI.:
511011 text
.,
I,'>
.;
... s; 0%
EZLF.GI
- .:. nag
u
Ol:~jecti c ~ r i ' e n c ~ o
LOCI< brasred
i
l.le*i(f'e~,lsed)
. -
.
Last c l i s n g e d on:by ~-
5c;PUSEF: 02 D 7 . 2 D U B
DevaluyJment class
Ol-iglnsl Isn<gl.lage Ell El-8yllsi-I
,...............tab,e7,;: ...........
;.Primar.'
............
i Name
i LOCI: mode Shared
5 . Clioose Add if you waiit to lock records in more than one table wit11 the loclc
ob-jecl.
A list ol' all Il2e tables lillhecl \ \ / i ~1l1~
1e prinlsr! table using valid foreign keys is
displayed. Select the appropriate table. T11e loclc inode of the priiilary table is
copied as lock mode. You call change this setting as required, for example you
call assign the loclc mode separately for each table.
Similarly, you can add a table linked with the secondary table just added with
fol.eign lteys. To do this, place tlie cursor oil tlie llaiiie of tlie secolldary table and
clloc~se. - ~ L / L / .
6. Save your entries.
A dialog box appears in whicl~you have to assign the lock object a developilleilt
You can lind informalion about (he acti\/alion ilo\? in the activatioil log, ~vhich
you call display \?lit11 U/~li/ies Ac/ivu/ion log. If errors occurred during
activatioiz, the activation log is displayed immediately.
Check for the Fuilctio~zModules Generated.
Goto->Lock Modules
...................
REPORT ZDEMO-CHECK-LOCK-OBJECT
:: :> *
:; :: :: ):: :ti *
::::$ >: :)I: :> : >'- :!: ::: ::::9 :;: ':: '3 :I: :> :) :; 2: :I'- :;: :) :g :; :):
.
:) ):: 2:: * >: >:
l l l l l l l . l l l l l l l l l l l . l l l l l l l l l l l l l l m l l l l l l l l l l l l .
>: ::: : : :: :: <: ;: ::: :)I: :: : :: :: :: ::::: *
:!: o
I]:? (-: 2.:4YI ZDEMO CHECK LOGIC OBJECT
*: :~[.;'~>I.J[)J< G;\iK.4PiYl'l . A l . l ! A ~ ~ ~ . . , ~ l , . ~ h ~ ~ ~
START DATE
':: 30/06/2006
:vpupgo~~ IS TO WORK WITH AL,L OPEN SQL
OP1!3KA'I'10N S
:kC:OI'.[.EDFIIOI\/l: : NA
:: :I: :: : :;: ;: >; :? ::I4; ;: >; *: :;: ):; : :;: ;: ;: :i I: :;: :; :: ;: 5:: :I: :> :) ;I: ;: ::: :I: :;: ;k :> :': :' :;: :
t , : >: $: :; I: :;: :: :> :;: 5:: $ >$I: 1: ;: :k 3: :; :;:
After tliis statemeiit, tlie loop is termiiiated, aiid processilig resumes after tlie closiiig
statement of the loop structure (ENDDO, ENDWHILE, ENDLOOP, ENDSELECT).
In nested loops. 0111)- the current loop is terminated.
110 4 TITUIES.
IF SY-INDEX = 3.
EXIT.
EIVDIF.
WRITE SY-INDEX.
ENDIIO.
In the third loop pass, the loop is terillinated before the WRITE stateinent is
~~rocessecl.
Transparent Table:-
11 is used to store application data such as Master and Trai~sactionalData. We
a1ways
create Transparent tables only.
There is a One to One relatioilsl~ip i.e. for the table in DDIC another table
with the same structure and the same ilaine and the saille fields will be created in
the original Data base.
Pooied 'I'abies:
It should be used exclusively for storiilg internal control information
(screen sequences, prograin parameters, temporary data, contilluous tests such as
documelltation).
The data from several different pooled tables call be stored together in a
table pool.
l'his is R/lany to One relatioiisliip i.e. hi-illally pooled tables in DLIIC: o n l ~ ,
one Data base table \vill be ci-ealed in the Dala Base.
/
Table Pool
created for the Table
Pooled Table.
2. Accept a string a n d number. Write the string that many number of times.
5. Accept one string with delimiter1 separator with . o r : ) a n d split it into two
sub strings.
6. Accept a string 'EMAX TKClT' and use shift <string> left, < shift> right, shift
<string> up to "H'EC:II'.
7. Accept a string like 'IMAX TECH' , Change first occurrence of 'I' to 'E'. ( Use
REPLACE command)
9. Accept two strings and compare the two strings using CB,CA,CS,CP. (output
shall be 'true' o r 'false' for each comparison).
10. Accept a string 'EMAX 'T'ECII', display the output only as 'TECI-I' using
Gi:FSErI' comurand.
Data. type
. - .- .
. Length
-- -- - - -.
Vendor Number Char 10
-
- - -
Bank Counlrv l<ev C 11ar 3
1 Bank ICev Char
Char
--
Char
holder
4. Acld the below f'icids t o the stanclal-d clatabase table '1'001 by appending
the follo~vingfields,
1 t e k
Data Element
*
CI-IAR,50
x g l e
Description --
coinpaily
CEO of the company
--
Vendor Number
--
District - --
S'l l<AS --- -- --- -- -
Create the below table to Maintain the Purchase Order Details of the
Vendors:
EBELN
- - - - -
IVETWR
CUKY,5 Currency Key
- - - -
- -.
QUAN, 13 Quantity .
Note: Mailltail1 the foreign ltey relationship between the above two tables Based
on the Vendor No.
A. ABAP Statements
A - Advanced
f- I I
B - Business To Work With
A - Application(s)
(- P - Programming
Program:
A Program Is Group Of Meaningful Instructions.
An Instruction is Group Of
Keywords + Variables + Operators + Data types.
Keywords :
Syntas : Each ABAP statellleizt Should begin with a lteyword and elids with a period
Since Each State~neiitShoi~ldStart \\(it11 a I<ey\i orcl . it is Difficult to give the exact no
Of ICeywords So that l<eywords are Ilevided illto ljiffereizt Types Depends On the
Functioilality Of the Keywords.
Types Of Keywords:
Declzrztive Key words: To Ileclare Variables.
TYPES. DATA, 1'ABLES
Syntax for Variable: DATA <Val-.Name> TYPE <Data Type>.
Calling Keywords
Are used to call Re-usable Modules(Blocl<s) that are already defined.
I'LRI~ORM to Call IWRM
CALL FUNC'L'IION to Call FUNCTION
MODULE to Call MODULE
Sample Program :
Stateliiellt A.
Statement B.
Statement C.
Statement D.
Stateinelit E. Instead Of Repeating
Statement B. Statement B.
Statement C . Statement <:.
Statemellt D. Statement D.
Statellielit F. It is Better to Group them
Statement B. As a Re-usable Module and
Statement C. Call it Any No Of Times.
Statement D.
Slatemelit G.
.k 6 f
CALL F'LJNC?'ION MOIIULE PERFORM
Nulneric types
Character(Non-Numeric) types
alphailumeric characters)
(numeric characters)
ci~al-aciers(0...9), but are riot represented incenlally as numbers. Typical type N fields
are account numbers and zip codes.
Integers - type I
The value range of type I numbers is -2:!".'31 to 2**31-1 and includes only whole
nuil~bers.Non-integer results of aritlimetic operatioils (e.g. fractions) are rounded,
not l1.uncated.
You can use type 1 data Sol-co~unlers,11umbel.sof'items, indexes, time periods, and
SO 011.
The value range of type F numbers is 1x10""-307 to lxlO""308 for positive and
negative numbers, including 0 (zero). The accuracy range is approxinlately 15
decimals, depending on the floating point aritlmetic of the hardware platform.
Since type F data is iilterilally converted to a binary system, rou~idingerrors call
occur. Although the ARAP processol- tries to minimize these effects, you
should nor use type 11' tPata if Lmigl accuracy is required. Insiead, use type P
data.
You use type F fields when you need to cope with very large value ranges and
rounding errors are not critical.
Using I and 17 fields for calculations is quicker than using P fields. Arithlnetic
operati~nsusing I and F fields are very similar to the actual macl~inecode
operations, while P fields require more support fro111 the software. Nevertheless,
you have to use type P data to meet accuracy or value range requirements.
Character(Non-Numeric) types
Of the five non-numeric types, the four types C, D, N, and T are character
types. Fields with these types are known as character fields. Each position in
011sof these fields taltes up enough space for the code of one character. C~li-rently,
ABAP only worlts wit11 single-byte codes sucli as ASCII and EHCDI. However,
an adaptation to UNICODE is in preparation. Uilder UNICODE, each character
occupies $wo or four bytes.
Header
Global Declarations
L
~ r o c e s s i n gLogic
- - -
Definition Of Subroutines
Definition Of Subroutines :
Subroutines are the reusable Co~nponeilts. We Define the reusable Components
Once and We call the saine subroutine wherever we need the saine Busii~ess
Logic.
Log on crede~ltialswill be provided by the customer , the Details are Unique for
Each Developer except Client in REAL, TIME..
The followiilg screen pops up. Select the iniddle radio button as follows.
,,.
8 IJU Sat?:
CllClll 8 CI I 1
NOTE : It is Mandatory to start Program name with 'Z' or 'Y' as 'A' to 'X' is
Reserved for SAP .
Note : In Kezd time, the C'ustom Dcvcloptirent Names Can also starts with
other than 'Y' and '%' i.e /<Any 8 Alphanumerics>l
6% @ ",. I ; ,z>
Debugging E,!ecl~te will) rrrriant @, Valiants
?togram
In Real Time We Never Select
this as this is L,ocal Object(No11
,
.
I -I-1-ansportable fi-om De\ielopment
to Quality and Quality to
Production).
l ? ~ , l , l , ~ F P , T I?l)l'~lIUL.!4Pl
./ 'PROGRAM ?EIIO_SII.~.?LC - U.::RP -~'":II:E!~,II
!i 'r,O?IEU FRlirl liA
i .PLIRFOSE TE PRI;.:T THE H I S T ~ R ' ; ' n i n:.sp
or c;fi-!+F2
REFS ZDEIIO_P.LV-DIFiU
'IIUTHOR 6~:iR
'PROGRi\li lDEll REPS ZDERO-HLY-DII,IUI 2
" C O P I E D FAOM 1.1.*, REPS LDEPIO~RLV_FURIIS
'PGRI'USE T f i I' REP9 ZDEllU-CUSTONER-DI1,IlJ
' ~ ( c I trrti,il;t IDOL> LSC~\.I
~ . . * . , . > T A . * ~ . ~ . % . - . . - . . REPS ZDEllO-lt~ICLUDE-PROo;RAI~11 2
I;;:?
'.%?
Press EN'TEK or -.
I-
IIRITE i'UELCOIIE T D T H E rE:r.F II8:IHLC,N
i n r ~D'v'.O.!~ICED E:USlME:<::
'' ! :/
;,"
llRlTE
.
! ' P 6 4 P stsnrls
-
U P P L I C U T I T J I I F'ROGRY.I~lIlll~lG'
-I.--.--.- . . . 1 iI
:.
LC'1 8.C o G J Ln 1 - Ln 23 o i 3 6 l i n e s
......... ....... . . . .. ...... ........................
I@' Objecl<sj actiratad
......... . . ....... . . :. : IhIAX ( 3 ) (800) '+I: ernaxall,?,p2
.......... 11~1s ,:
,:. . . . . . . . . . . . . . .
f t a r
................... 3 2, -
. . . . . .~. .' .b. .i .a r - s a p
. . . SAC
... ~5
ABAP ediCOr:ch... : l j j / 3 I.IIC~OSUFL
........................... OIIIC ... rl -:: ...............
""titled - p a l m ....
-. 1 ."'.:z: . 7% 2 ; 0 3a1.q
DAYJ
Working With Arithmetic Operators using I'ARAMETER:
Note : PAPUMKTEK is to accept the Input via Console (Screen) , Which Acts as
Scailf in ' C ' .
REPORT ZGDEMO-PARAMETER
OUTPUT :
OUTPUT
Note : All the Systenl Variables are Maintained in Database Structure SYST.
Accessing System Variable is SY-<Name>.
REPORT ZGDEMO-SYSTEIY-VARIABLES
REPORT ZGDEMO-CHAIN-OPERATOR
;': :T ' t i. l o u t C h a i n O p e r a t o r
WRITE / 'RESUI~.T USING CIIATN OPERATOR' .
ULlNE.
WRITE / ' He1 1 o ABAP' .
WRITE / 'Welcome t o eMAX T e c h n o l i o g i e s ' .
WRITE / ' A l l SAP Modules a r e Developed by ABAP'
WRITE / 'SAP i s f r o m SAP AG' .
SI<IP 2 .
!dlth C3ai n O p e r z t c r
W R I I I / ' l<LSUl I \dl-I IIOU I CIIAlN Ol'Ll<A I OR' .
ULlNL.
WRITE / : ' He1 1 o ABAP' ,
' We1 come t o eMAX Techno1 io g i e s ' ,
' A l l SAP Modules a r e D e v e l o p e d by ABAP' ,
'SAP i s f r o m SAP AG'.
Interactive Reports
Display the Summarized Information as the First List-And letting the USER Interact for
the Detailed Info. a
20th
Ex : Basic List 1" Secondary 2"dSecondary 3"d
f
SY-LSIND = 0
11
NOTE: We Can go up to 20 Secondary Lists.
1 1
Event: AT LINE-SELECTION AT USER-COMMAND.
Note:The List Index SY-LSIND will be incremented by 1 for each user Interaction.
By default, the basic list has a standard list status and a standard page header. The TOP-
OF-PAGE and END-OF-PAGE events can occur while the basic list is being created.
* START-OF-SELECTION. :i:
********$:**:$*:$*$:*************:$*********************
START-OF-SELECTION.
SELECT BUKRS "COMPANY CODE
BUTXT "NAME OF THE COMPAIVY
ORTOl "C&Y
a
LAND1 "COUNTRY KEY
WAERS "CURRENCY KEY
INTO TABLE IT-TOO 1
FROM TOO1
WHERE BUKRS lN S-BUKRS.
***:+*:$~:***:!::::*$:$:******~::$*#:*****:~$:***#:**;$******:~*:!::::**
* END-OF-SELECTION. *
********>k*****************$<********$<***$<***********
END-OF-SELECTION.
4.Write a Program to Print the List of your Best Friends in the Below
Format.
r
. ~ ~~ -~ -
. . ~
Name .--.... - .-.-.
Gender Date of Birth
Vijaya Female
C0ul.i
CVL.~ ~ l ~ j i Male - ' ~
~1
. .
1 - __ - .-_ - _ .- . - . -- --
I Mubeena - Female
I Kaadambari Male
I - Srinivas I Male
--
1 Nlurali
- 1 Male
If you double click on the company code a secondary list is displayed wliich
displays the coinpaliy code, customer number, Recollciliation Account.
displayed.
jpd..".,,";
,,,/,.~j!~~,
la,$..
' 9 . , ,9t2j,.,$4..*;
t,,,!{< f<j> ,.., *,,?,
<<,"*.<$,&
F? *2>,2h$j.?<.
-,,., $
.,,
( % . ~tl;,P*g
*,,~#t E~L,&+
p$
...,.. --. ..,
1.L
rlil ;iJETFEi3 05TiiTi.S FiJiJNT! FOE THE SELECTED COt!P <:ODE ..-
ivi
. .....
. .
A.BRANCHING
2. CASE-WHEN -
B. LOOPING
1. Conditional (DO-
ENDDO)
2 . Un-Conditional
(WHILE-
ENDWHILE)
Cont-1-01Sli-uctures
We Nevet- C:'omprornise in Quality, Wo~rldYou?
DAY- 1
Note: The Program execution is always Sequential. The First Statement is Executed
First and the IVth Statement will be after (N-1) the statement and Each Statement is
Executed Only Once by DEFAULT .
But Most of the tiines we need to COhTROL the traditional FLOW Of Program
Execution BY brancl~ingfrom One Block of stateineilts to another block depends on
the conditioil and have to repeat a particular block of statements THROUGH
Controlling Techniques.
You can execute difli-rent parts of programs conditionally or in loops using the
sta~ldardkey~~orcls
P1;, CL4Sk:,DO, and WBB11.k;.
Controlling techniques
Branching Looping
IF <Condition>.
Statement 1.
Slalement 2.
IF-ELSEIF-ENDIF
This co~~trolstructure is introduced wit11 the If;' statement. The IF statelllent allows
you to divert the prograni flow to a particular statelllent bloclc, depending on a
condition. The statement block concludes either with ENDIF, ELSEIF, or ELSE.
IF <conditionl>.
<statemeizt block>
ELSEIF <conditioiiz>
<statement block>.
Page 1 of 12 By Ganapati Adimulam
eMax Technologies,Ameerpei,I-Iyderabad
Ph No: +91 40 -65976727, Cell No: 99484 44808,98490 34399, ~uwvv.cmaxtecla.co~
<:,,irr-oj Sii-uciun-es
We Never Cornpr.omise in Quality, Would You?
ELSEIF <condition3>
<statement bloclt>
.....
ELSE.
<statemeill block>
EhIDIF.
If the first conditioiz is true, the system executes all tlze statements LIP to the end of tlze
first statement bloclc and then coiztiilues processiizg after the ENDIF statement. If tlze
first condition is not true, the progra111 juinps to tlze nest ELSEIF statement and
executes it like an IF statement. ELSE begins a stateilleilt block w l ~ i c isl ~processed if
lloile ofthe IF' 01. ELSEIE co~lditioilsis true. The end of the last statement block must
always be coizcluded by ENDIF.
The CASE Control Structure : This coiztrol structure is introduced with tlze CASE
statement. The CASE control structure allows you to control which stateinent bloclts
are processed based on tlze coizteilts of a data object.
CASE <f>.
WHEN <f,>.
<Statement block>
WHEN <f2>.
<Statement block>
WHEN <f;>
<slatemen1 bl och,
WHEN ...
......
WHEN OTHERS.
<statement block>
ENDCASE.
REPORT ZCDEMO-IF-ELSEIF-ENDIF
I F P-DAY = 1.
WRITE / ' SUNDAY' .
E L S E I F P-DAY = 1.
WRITE / 'MONDAY'.
E L S E I F P-DAY = 2 .
\dl<1.1 I: / ' TIJIrSDAY ' .
i I S L l.1~ l'.-llAY
-: 3.
WRITE / 'WEDNESDAY '
E L S E I F P-DAY = 4 .
WIxi-rr / 'TIIURSDAY .
!II I I - 5.
wrir-r~/ FIIDAY .
E L S E I F P-DAY = 6 .
WRITE / ' S A T U R D A Y ' .
ELSE.
WRITE / ' D A Y SHOULD BE BETWEEN 0 AND 6 O N L Y ' .
ENDIF.
CASE 2 :
PARAMETER P-DAY T Y P E I.
CASE P-DAY
WHEN 1.
WRITE / 'SLINDAY' .
WHEN 1.
WRI-TE / 'MONDAY' .
WHEN 2 .
WRITE / 'TUESDAY' .
WHEN 3 .
WRITE / 'WEDNESDAY'.
WHEN 4 .
WRITE / 'TIiURSDAY' .
WtIEN 5 .
WRI-rE / ' F R I D A Y ' .
WHEN 6 .
WRITE / 'SATURDAY'.
WHEN OTHERS.
W R I T E / ' D A Y SHOULD BE BETWEEN 0 AND 6 O N L Y '
EXECUTE PROGRAM
w,
m.
By Ganapati Adimulam
-Page 6 of 12
eMax Technologies,Ameerpet,I3yderabad
i'11 No: +91 40 -65976727, Cell 1'40: 99484 44808,98490 34399, a.i~.rw.eanaxkecb.co~pp
Control Structures
We Never Cornprornise in Quality, Would You?
EXECUTE
,=,
r J pes Of I,oopirrg :
A) Un Conditional.
B) Conditional
---
ENDDO.
Output :
I
Page 8 of 12 By Ganapati Adimulam
eMax 'l'echnologies,Ameerpe1,IIyderabad
Ph No: +9140 -65976727, Cell No: 99484 44808,98490 34399, www.cmaxtech.coan
Reports
We Never Compromise In Quality, Would You?
D) Display the List of Customers From all the Selected Company Codes.
(:~~storners
Cl~s[:~l?e
Select the Reauired C o m ~ a n vCodes and Click On
......
l 2 4 0 U I3EZ ii.il 1 . 1 :.I.,:zn.:,
:i
2500 13E5 Herllei.1 ?it:, R,:,T.~+~?<Iz~.
<<;3rDTJ LlS i l . C
1:rE::
.....i3CIL1 E l r , ;
kJeT; '.'.,,..
51US'!tic;:'i - ZeilliLI'> 3 r c . i C e l C
> ....
,
i 4Gi;rJ I j E ? C.irt:#oB Tz!'co!.o
: ; C ~ * . > C ! ,>I,, C 0 , , , 3 ~ ? , % ! 70,C i l L "
i.d...i S C l C IDES l a v h r TM;d
~ C C L ~ 1:IES
O 148.;rc, I; I . I r I: b ila:lc3 iiF
',$,'
:, i 7 C E O I 3 e S C r i ~ i l
PSiliC
: ,J7:.t4cl I!\<: ~-:~vT.,-A :!OFRO; hi lir
:_!7EDO I!)E6 [ : 3 1 ~ l i i : i a a
I:ni~in1:>1
i:?ror. i i m r zv ? t , r ~ ~ . , e i a ' I e l ? e b : l l l .d
' i : .."FC
c , 'F,') i.<:-,; PI., ii
; J;<[:vO [:,EL; :,:.:t 1,: CI,.lC
List Of Customers
Page 72 of 74 BY C a n a ~ a t Adirnularn
i
eMax Technologies,Ameerpet,Hyderabad
Ph No :+9140 -65976727, Cell No : 99484 44808,98490 34399, www.emaxtech.com
Control Structures
We Never Compromise in Quality, Would You?
Processing Block.
ENDWIIPl,E-
Example 1'1-og :
To terminate a single loop pass conditionally, use the CHECK <condition> statement
in the statement block of the loop.
If the coilditioil is iiot true, any renlaiiiiilg stateinellls in Ihe current state~ueiltblock
alter tlic CIHE('l< sl;ite~nen[are ignored. and [he 11es1loop pass starts <coiiditioi~>
call be any logical expression.
DO 4 TIMES.
CHECK SY-INISEX BETWEEN 2 and 3.
WRITE SY-INDEX.
ENIIDO.
The first and fourtli loop passes are teriliinated without the WRITE statement being
processed, because S Y - I N D E X is not bet\vee~i7_ and 3.
Exiting a Loop
After tliis statemeiit, tlie loop is termiiiated, aiid processilig resumes after tlie closiiig
statement of the loop structure (ENDDO, ENDWHILE, ENDLOOP, ENDSELECT).
In nested loops. 0111)- the current loop is terminated.
110 4 TITUIES.
IF SY-INDEX = 3.
EXIT.
EIVDIF.
WRITE SY-INDEX.
ENDIIO.
In the third loop pass, the loop is terillinated before the WRITE stateinent is
~~rocessecl.
Function Group
FM2
MAIN Program +
INCLUDE Programs
Note: All of (Only) the fuilction modules in a function group call access the global data
of the group. For this reason, you should place all function modules that use the same
data in a single function group. Example, if you have a set of filnction modules that all
use the same internal table. you could place thein in a function group containing the table
definition iln its global data.
---
LVorking with Strings
String is a variable length data type.
Dyilainic meinory management is used internally. i.e the Memory Allocated(Adjusted) at runtime
according to the current field content .
c ings
s ~: i can have any lellgth(Can Store any no of Characters).
IVO'IL'E : Since S T R N G is a dynailiic length data type, We Cannot Declare String Variables
ti~roughPARAMETER. i.e
DRAMETER P N A M E TYPE STRING. Is Not Allowed. Because the system caimot understand
how big the Input Field is.
- --
~ -~
S'I'KPNC; --
Note : Memory is Always Allocated For 100 Note : Memory is Allocated Only For eMAZ ,
Chars IrrespecitiveOf the No Of Cl~arsStored TTJhicli always depends On tlie No of Chars
Cun-entl)
- -- . - .
- - . Storecl Currently.
- . -- --
-- - - -- - -
- - -. -- -.
String Operations:
CONCATENATE : To Clilb More than One Sub String into One Main String.
S'i'N'P'AX : CONCA'TENATE <Strl> <S1r3> <Slr3> ... <Str N> IhTTO <Str>
SEPARATED BY <Separator>.
SPLB'I': '1'0 Split the Main String into Substrings at the given Seperator.
SEARCH : Search for the required Sub String in the Main String.
If the comparisoil is true, the system field SY-FDPOS contains the length of <Strl>. If It is
false, SY-FDPOS contains the offset of the first character of <Strl> that does not occur in
<Str2>.
is TRUE if <Strl> does also contains characters other than those in <Std>. The
comparison is case-sensitive. Trailing blailks are included. If the comparison is true, the
system field SY-FDPOS contains the offset of the first character of <Strl> that does 1101
also occur in <Std>. If it is false, SY-FDPOS contains the length of <Strl>.
P:~ge3 of 6 By Canapati Adimulam -
eM;is l'cchnologics, ni:?ecl-pct, tlydei-abacl
Ph No: +91 40 -65976727, <:ell No: 99484 44808, 98490 34399, w~s.w.cnsaxtclc11~~0~
Strings
-
We Never Compromise in Quality, Would You? -
-
is 'B'RUK if < S ~ r l >contains a1 least one character ii-om <Str2>. '[he compai-ison is case-
sensitive. If the coinparison is true, the systein field SY-FDPOS contains the offset of the
first character of <Strl> that also occurs in <Str2> . If it is false, SY-FDPOS contains the
length of <Strl>.
is 'l'BIIJE 11'<S~rl>does not coiltaiil any charactel- Si-om <Str3>. conlparison is case-
sensitive. If the coillparison is true, the systeim field SY-FDPOS contains the leilgth of
<fl>. If it is false, SY-FDPOS contains the offset of the first character of <fl> that occcll-s
in < S t d > .
is 'TRUE IF <Strl> coiltaiils the String <Str2>. Trailing spaces are ignored and the
coillparisoil is NOT case-seizsitive. If the comparison is true, the system field SY-FDPOS
contains the offset of <Str2> in <Strl> . If it is false, SY-FDPOS contains the length of
<Strl>.
is true iE<Strl> does not contain the String <Str2>. Trailing spaces are ignored and the
coinparisoll is not case-sensitive. If the coi-nparison is true, the system field SY-FDPOS
contains the length of <Strl>. If it is false, SY-FDPOS contains the offset of <Str2> in
<Strl>.
is 'TRUE IF <Strl> matches the pattern <StR>. If < S t d > is of type C, you can use the
following wildcards in <Str2>:
Trailing spaces are ignored and the coillparisoli is not case-sensitive. 1.f the coinparison is
true, tlze systein field SY-FDPOS contains the offset of <St$> in <Strl> . If it is false, SY-
FDPOS contains the length of <Strl>.
If you want to perform a coiiiparison on a particular character in <Std>, place the escape
character I1 in I-i-ontof it. You can use the escape character 11. to specify
is TRUE if <Strl> does not match the pattern <Str2>. 111 <Std>, you can use the saine
wildcards and escape character as for the CP.
Trailing spaces are ignored and the coilipariso~lis not case-sensitive. Jf the cornparisoil is
true, 111e system field SY-FI_>130Scoiitains [he length of <Strl>. If i t is false, SY-FDPOS
coiltaiils the offset of <St$> in <Strl> .
The following table sl~owsthe results of executing this program, depei~dingon wl;icl~
and values of Strl and Str2.
ISXAMP1,ES :
SY-
1;D P
0s
'BD ' fa1s e 2
'ABC12' CN true 3
2. Accept a string a n d number. Write the string that many number of times.
5. Accept one string with delimiter1 separator with . o r : ) a n d split it into two
sub strings.
6. Accept a string 'EMAX TKClT' and use shift <string> left, < shift> right, shift
<string> up to "H'EC:II'.
7. Accept a string like 'IMAX TECH' , Change first occurrence of 'I' to 'E'. ( Use
REPLACE command)
9. Accept two strings and compare the two strings using CB,CA,CS,CP. (output
shall be 'true' o r 'false' for each comparison).
10. Accept a string 'EMAX 'T'ECII', display the output only as 'TECI-I' using
Gi:FSErI' comurand.
Note : The Same SAP Database is Accessed by all the departments in the
Organization.
YS
SAP' Database 4 -"1
: Most Of the times, Each Department want to see the same data in a
different view and want to Manipulate according their requirements and that
Manipulated data is NOT required by the other departments So that Data in
Database(Tab1es) Should not be changed ,When the Changes a r e required by all
the Departments. Instead the Copy of the required Database Tables should be
fetched into Program and Manipulate it accordingly, Which doesn't change the
Data base.
Note: T o Maintain the Copy Of the Database Table Data in the Program, the
Program should have a variable (Temporary Table) , Which is Nothing but
Internal 'i';~ble.
So that, Internal Table is a Temporary Table ( Variable ) to Process the Data from
Database Table(s).
'I'YPll3S : B3lillGLN 0 1 7
F P 'li'YPBC <Ref. Datatype> ,
F2 TYPE <Ref. Datatype> ,
F3 TYPE <Ref. Datatype> ,
...
jIN1) <)I? <.g. y >.
Note : TYPES is to define User Defhed Datatype.
2) Declare Internal Table i.e. Array of above Structure.
DATA <][tab> TYPE TABLE OF <TY>.
Syntax to Select the Data From Database Table into Internal Table :
SELECT <F1>
<J-2>
<F3>
~.
~ . . ~ i ~ iI'rogra~ii
1
1 into IT-T001.
SEIXC'1' 8 iJ KRS
BU1'X'T
OW01
LANDl
INTO TABTIE 1'1'-'l('001
PRONI 'roo;
WI-IERE 1,ANDl = 'DE'. "Germany
Note : After the SEI,ECrT Data From Database 'Table is transferred to Internal
Table .
"Displaying Data From Internal Table
"Since Data in Internal Table is Stored record by record, Accessing/Displaying
, -.
;;V;;:a ki'i-on1 Inici-sill '1';lble is ;;!so r-econ-tl by n-ecor-d. So that 'l'here is 2; Special Loop
+Which Starts with ihe I" Record and Encls with Last Record Of <Itab> By Default.
"Keep the Internal Table in a LOOP, L O O P Points to the First record by Default
"and Collect it into <WA> and Process(Print) the Data from the <WA>.
Vdor k are a
ENDLOOP.
a&---------------------------------------------------------------------
*& Report ,/ZGDEMO-DISPLAY-COMPANIES-DE
.k PURPOSE : TO PISPLAY LIST OF GERMAN COMPANIES AND THEIR DETAILS
-, AUTHOR : GANAPATI .',ADIMULAM
" COMPANY : EMAX TECHNOLOGIES
"2,- -i
. . . .-
-. .- . - -. "" -. .--- ... - - - ... .....- - .- -. - -- -- -. -- -- - .- .
. .. - - - - - .. - - - - - - - - - - - - - - - ... - ..- -- - - - --
.... .- --
REPORT ZCDEMO-DISPLAY-COMPANIES-DE
"DECLARE t h e R e q ~recl
~ i Datatype
TYPES : BEGIN OF TY-T001,
BUI<RS TYPE BIJI(RS, "Company Code
BUTXT TYPE BUTXT, "Company Name
ORTOl TYPE ORTOl, "City
LAND1 TYPE lLAND1, " C o u n t r y Key
END OF TYKT001.
* D e c l a r e I n t e r n a l T a b l e From t h e above S t r u c t u r e
DATA IT-TO01 TYPE TABLE OF TY-T001.
DATA WA-TO01 TYPE TY-T001.
-
c c- I zLci 2 r TO,, , , L - i >L -
SELECT BUKRS
B UTXT
ORTOl
LANDl
INTO TABLE IT-TO01
FROlY TOO1
WIiERE LANDl = ' D E ' .
;.: ;-,
i,
. sp:ay
Data From IT-T001
LOOP AT IT-TO01 INTO WA-T001.
WRITE : / WA-T001-BUI<RS,
WA-T001-BUTXT,
WA-T001-ORT01,
WA-T001-LAND1.
tNOL001'.
SEARCH.
NOTE: Malte S u r e that the Internal Table is Sorted to Apply BINARY SEARCH.
Accessing Multiple Records :
I,OOP A'l' <I['17AB>BN'1'0 <MIA> 1CROM < N l > 1 ' <N2>.
' 10
s:i3~-ocess
the Data ici-om <WA>.
ENDLOOP.
OR
L O O P AT <ITAB> INTO <WA> W H E R E <Condition>
"P:-ocess the Data Ilh-om <WA>.
ENDLOOP.
DELETING Records :
Single Record : DELETE <ITAB> INDEX <N>.
M~nlltipleRecoa-ds : DEQ,E'I'K<<lrl'AB> W l l E R E <Condition>.
DEB,X'B'E <I'II'AB> 1CKOM <N1> TO <N2>.
MODIFY :
Either Single 1 Multiple Records Modification is always through <WA>.
..
.
.-
...
;:& R e p o r t ZCDEMO-DISPLAY-COMPANIES-DE
" PURPOSE : TO D I S P L A Y L I S T OF I N T E R N A L T A B L E OPERATIONS
" AUTHOR : GANAPATI.ADIMULAM
<: COMPANY : EMAX TECHNOLOGIES
"
"OI---------------------------------------------------------------------
.'.
REPORT ZCDEIYO-ITAB-OPERATIONS
"DECLARE t h e Required D a t a t y p e
TYPES : BEGIN OF TY-T001,
BUKRS TYPE BUKRS, "Company Code
BUTXT TYPE BUTXT, "Company Name
ORTOl TYPE ORTO1, "City
LANDl TYPE LAND1, " C o u n t r y Key
END OF TY-T001.
;:SORT
SORT IT-TO01 DESCENDING BY BUKRS.
WA-T001-BUTXT,
WA-T001-ORT01,
WA-T001-LAND1.
EIVDLOOP.
"INSERT
CLEAR WALT001. "CLEARS THE CONTENTS
SI<IP 2 .
WRITE : / 'DATA AFTER APPEND AND INSERT' COLOR 1.
ULINE.
"DELETE
DELETE ITLT001 FROM 4 TO 5 .
SI(IP 2 .
WRI-rE : / 'DATA AFTER DELETE' COLOR 1.
ULINE.
WA-T001-ORT01,
WA-T001- LAND1.
ENDLOOP.
"MODIFY
"SET COUNTRY KEY TO ' I N ' FOR BOTH COMPANY CODES 'E001' AND
'1001'.
CLEAR WA-T001.
WA-T001-LAND1 = ' I N ' .
MODIFY IT-TO01 FROM WA-TO01 TRANSPORTING LAND1
WHERE BUKRS = 'E001' OR
BUKRS = '1001' .
ENDLOOP.
ENDIF.
"READ
SORT IT-TO01 BY BUKRS ASCENDING.
CLEAR WA-T001.
READ TABLE IT-TO01 INTO WA-TO01 WITH KEY BUKRS = '0001'
BINARY SEARCH.
SKIP 2 .
WRITE : / 'DATA AFTER READ' COLOR 1.
ULINE.
";DELETE A D J A C E E 1 DUPLICA-[ES
" S I N C E WE D O N ' T HAVE DUPLICATES ON BUKRS, WE PREPARE
DUPLICATES
DO 3 TIIVIES.
APPEND L I N E S OF I T - T O 0 1 TO IT-T001.
ENDDO.
SI(IP 2 .
WRITE : / ' D A T A AFTER ADDING DLIPLICATE RECORDS' COLOR 1.
ULINE.
LOOP A T I T - 1 - 0 0 1 I N T O WA-T001.
i urn IT-7001
' : i 3 i s p l a g / D a ~ a '.--,-
i
WRITE : / SY-TABIX,
WA-T001-BUKRS,
WA-T001-BUTXT,
WA-T001-ORT01,
WA-T001- LAND1.
ENDLOOP.
.:,
-u~LETE
%
-' rl
ADJACENT DUPLICATES
DELETE ADJACENT DUPLICATES FROM I T - T O 0 1 COMPARING BUKRS.
SI<:CP 2 .
Wfillt : / ' D A - i A AFTER ADJACENT DUPLICA-TES' COLOR 1.
ULICNE.
LOOP A T I T - T O 0 1 I N T O WA-T001.
" D i s p l a y Data From IT-TO01
WRITE : / S Y - T A B I X ,
WA-T001-BUKRS,
WA-T001-BUTXT,
WLT001-ORT01,
WA-T001-LAND1.
ENDLOOP.
\.,dl ':,,,,'I
\,..,II:!U~ r
bit1 i : i ~ i ' i
\;a1 iilnr f
(:a i I dorl
I'lal 1da1.i
lial 1 i o r i
(,El I >l3r.l
:;~>!,! *[,r~
., . . . . . . : I : ,.-. I
I?,:
L ..>:,..,,:,
.:,
, , ..,
r , .': ~
ri.-;,: :, 7.
p.<<,:.?,: ;
.
6 > 3:t: :,.I c
.. .., . c , 1=:.5,i
!.;;,',
.-, . - L.I"
.>.
k$ 'i;L'tb.l;'
......:,
,;? .C:#W IF x A ~ C L > ~ S ~ E ~
i!l,$Y H?LkR!>,3rl;
;5 R i I 3 C I g E 5 ?<.< I :).,qH G LL.;~:~
50 RiCC I D E S Hr+.:l:l 6ri.ll: ;-es8r71
MISCELLANEOUS:
nnl5ADER I,YNE: Is the Default (Implicit) W o r k Area, Defined by the System, with
1 1 1 7
NO'T'E : <6'4'hB>s With LIEADEK T,INE :ire Not Recommended , Instead SAP
Recommends Explicit Work Areas.
I I
I I.IDEX TABLE
STANDARD TABLEs :
. Are the Default Internal 'l'able
. T h e key of a standard table is always non-unique So Duplicates a r e
Allowed.
Hashed tables :
This is the nlost appropriate type for ally table where the main operatioil is key
access.
Like database tables, hashed tables always have a unique key.
END 0 1 7 <itab>.
Page 17 0S 23 By Ganapati Adimulam
eMax 'L'echnologies, Ameel-pet, llytlerabad
Ph No :+91 40 -65976727, Cell No : 99484 44808,98490 34399, ww~~.emaxtech.conn
Internal Tables
We Never Compromise in Quality, Would You?
-.-,- .
I 111ssla~eliiell~
decinred ai-1 inlei-rial I~tble4 r a b l \\:iLh the line lype defined lollowing the
OCCURS aclditio~i.Furlheni101-e.all internal ~ztbleshad header lines.
The iluinber <n> in the OCCURS addition had the saine illeailiilg as ill the INITIAL
SIZE addition from Release 4.0. Entering '0' had the saille effect as onlitting the
INITIAL SIZE addition. In this case, the initial size of the table- is determined by the
system.
NO'E'K : OCCURS <O> : Allocales the Initial Memory 8P<B and the system keep on
aliocaies by 8JLB ,whenever it is required.
OCCURS <N> : Allocates Memory For <N> recorcls initially and Keep on allocates
for <N> records ,whenever it requires.
NO'TE: LVhenever the same Inter~lalTable is used again and again in the sarne Progranl.
it is better to JNITIALIZE (Clear the Current Current) and before we use it again.
CLEAR:
i'i.ls;iLi2<"dariabie>.
NO'I'E: 'She <Variable> C a n be a normal Variable, W o r k Area, Internal Table etc.
So that CLEAR C a n Clear the Contents Of the Corresponding Variable.
CLEAR <WA>. - Clears W o r k Area
C:T,EAR <l'TAB>. - Clears Internal Table
Noid: C'leanng the i~iter~lal
1 able means, to take to the state that it was in immediately
after it is declared it.
]Vote: If you are using internal tables with lzeader lines, remember thal the header line
and the body of the table have the same name. If you want to address the body of the
table ill a comparison, you must place two brackets ([ I) after the table name.
Page 18 of 23 By Ganapati Adimulam
eMas 'l'eclinologies, Allleerpel, llytlerabad
I'h No :+91 40 -65976727, Cell No : 99484 44808,98490 34399, y\.ti.canax8eeh.b:0~11
Modularization Techniques
We ever Compromise in Quality, Would You?
EXPORTING
, fi = a1
...
Fn = an
IMPORTING
fi = at
....
f;; = a;
[CHANGING fl = a1.... f,, = a,]
[TABLES fi = a1.... f,, = a,,]
[EXCEPTIONS el = rl .... e,, = r,,
[ERROR-MESSAGE = r ~ ]
[OTHERS = r,]
Position the cursor at the point in your coding where you want to call the function.
1. Choose Pattern. 4
called from the program in which they a r c defined. You can use subroutines to
write functions that are used repeatedly within a program. You can define
subroutines in any ABAP program.
<INPUTF2> etc
Subroutines are Called
CHANGING <OUTPUTl> Actual Parameters.
<OUTPUT2> etc 1
4
Defining Subroutines
FORM <Name> USING <FP-TNPUTl>
<FP-INPUT2> etc
3 I time
All Arguments Passed at the
of Defining the
Subroutines are Called
CHANGING <FP-OUTPUTl>
Formal Parameters.
<FP-OUTPU~~Z>etc j I
ENDFORM.
Exercise
1. Declare a n interninl table for the below fields from CSKS and display
the diitii :
C'ontrullitzgArm, Cost Centre, V[~licl-fi.olzz
(lfrte, Vf~licl-to
cklte,
Depnrtmeizt, i'erson Xespoizsible.
I Clountry
0001 I rm
- ---
. -- -- -
0002 In
- . .-
0003 Jublee Hills In
If you want to keep the value of a local data object after exiting the subroutine, you must
use the STATICS statement to declare it instead of the DATA statement. With STATICS
you declare a data object that is globally defined, but only locally visible from the
subroutine in which it is defined. 6
.',;...:,
.,.5',.. 9,.,. .'. d, .;-*:
.,..'.,.. <.....,.-5.,..'. * :# :+ * * *: *
*: .:: :$ :3 ,:: * >: :k * -::::4 * * ::: * * * * * * * *
:g * < I ? :$ $: :) *: ): :g * * ::: :s *
:$
REPORT ZDEMO-STATICS-IN-SUBROUTINES .
PERFORM increment-counter.
PERFORM increment-counter.
SKIP.
*STATICS Variable is Used in the Subro~itine
PERFORM add numnberby-one. a
FORM increment-counter.
1, counter = 1-counter + 1.
lfrite : 1 'The Value Of Counter is', 1-counter.
ENDFORM.
FORM add-number-by-one.
15 WA RNKA-BANKL,
25 W A ~ B N K A -ANKA,
B
40 WA-BNKA-STRAS,
50 WABNKA-ORTO 1.
ENDLOOP.
THE LIST OF BRIII: DET>,ILS ![,RE Here First Record from the in
the Internal Table is
AE iljii?O0l:IO C i T i ban!: F l o r i iia Z g E u e r ~ o s
OF; t i : . ~ ~ 3 i j ' j e.srlco R i g !;ai..aT erlio ~uenils- AR 2005000 CitiBank ..
h i 1091!3 De:itsrhe Bani,i l f e i - s t r ~ l ' ~ ~i sr
.W
ST 12345 E ~ I sb:3rli:,
. r; i~l:,enya:.;:~B~rsp~t;3~jt
,"I.! 123.456 ?,HZ FJanIcitig [,or
B) Processing blocks that are called using the ABAP runtime system:
Modularization at Runtime .
Event blocks Ex : INITIALIZATIION, AT SELECTION-SCREEN, START-
OF-SELECTION,END-OF- SELECTION.
Dialog modules
Stalndard SQL
SQL (Structured Query Language) is a largely standardized language for
accessing relational databases. It can be divided into three areas:
Data Manipulation Language (aDML)
Statenleilts for reading and changing data in database tables.
Data Definition Language (DDL)
Statements for creating and administering database tables.
Data Control Language (DCL)
Statements for authorization and consistency checks.
Note : The SQL is Database Dependent.
Each database has a programming interface that allows you to access the database
tables using SQL statements. The SQL statements in these programming
interfaces are not fully standardized. To access a specific database system, you
must refer to the documentation of that system for a list of the SQL
statements available and their correct syntax( Since it is Database
- * -
Pppllcatlon programs
-7
w" - - --
R E 3 S y s t e m programs
Native S O L O p e n SOL
I O p e n SOL
I.ludules
Plat!. e S I ~ L (Table module.
1 lodult!
Database interface
I S t a n d a r d S O L (d:,,.namic, e r r l b e d d e d : ~
Relational database
UPDATE)
(DCL)
COMMHT,ROLkBACH(
I
Note: Open SQk Doesn't Support DDL so that we have DATA
DILCTIONA,R~to Support the DDL Operations.
Native SQI,:
Native SQL is only loosely integrated into ABAP, and allows access to all of the
functions contained in the programming interface of the respective database
system. Unlike Open SQL statements, Native SQL statements are not checked
and converted, but instead are sent directly to the database system. When you use
Native SQL, the f~~nction of the database-dependent layer is minimal. Programs
that use Native SQL are specific to the database system for which they were
written. When writing R/3 applications, you should avoid using Native SQL
wherever possible. It is used, however, in some parts of the R/3 Basis System - for
Page 2 of 34 By Ganapati Adimulam
eMax Technologies,Ameerpet,Hyderabad
Ph No :+9140 -65976727, Cell No : 99484 44808,98490 34399, www.ernaxtech.com
Open SQL
We Never Compromise in Quality, Would You?
Return Codes
After every Open SQL statement, the system
field SY-SUBRC contains the value 0 if the
operatioil was successful, a value other than 0
--v'
After an open SQL statement, the system field
SY-DBCNT
SY-DBCNT contains the number of database
lines processed.
INSERT - SYNTAX
Note: ACCEPTING DUPLICATE KEYS Doesn't mean that it Accepts and Inserts
Duplicate Records. Instead it Ignore the records which already exists in Database and
Inserts the rest of the Records.
Note : Whenever you want to insert more than one line into a database table, it is more
efficient to work with an internal table than to insert the lines one by one.
REPORT ZDEMO-OPEN-SQL-INSERT .
** *: ,::;$ * :!. * * ,::,:::k * *: 9. * ,::
$ k (: $ :!$ *: 9: ,:k :: $: 9,: $ :> 3,: ,: :k * * -::
*: $ 3,: 2: :!$ * ,:: * ,> * ,k * <: * * * <: ;y * * *: %; *
9,: $ << 3,: 2: 4 *
':: PROGRi\M ZDEMO-OPEY-SQL_INSERT
':IZCTHOR GAKAPATI .ADIMULAM
:: s ~ , A~ R 4 ' '1~
-t; 27/01/2008
x: PPIJRI'OSE IS TO ?VORK WITH AI-I, OPEN SQI, OPETCATIONS
:c COPIED FROM : NA
:~:~$*:]:*:~*:g*:!:*.:::>;:k*:~:>:!::>:~*,::*:~~:**:~~**:~**,:::>**~~:~**:;:~:>*:>:>***:~$,:.*::k*,::::c:~*:!$:~:~*
* MODIFTCATION LOG:
$' CHANGE REQUES'I' : C11 EMAX4756
4
CLEAR WA-1'001.
IF SY-SUBRC = 0.
WRITE : 'THE NO OF RECORDS SUCCESSFULLY PROCESSED ARE',
SY-DBCNT. 1
ELSE.
WRITE : I 'NOT ALL THE RECORDS ARE SUCCESSFULLY PROCESSED'
ENDIF.
OUTPUT :
EXECUTE THE PROGRAM
Same in Database.
a
-. A
.. .....
:v~;:E
[~-.::la;sc f ~ r . - ~ i . : !: of 75 . , r a , ! rn'litrm!~; .- 1 ,,.;~- , I < ?:zri
i-/
.....,
UPDATE - Syntax
/'\
Column Update Row Update
UPDATE < D B D SET UPDATE <DBT> FROM <WA>. (Single Rec)
<Fieldl> = <Valuel> UPDATE <DBT> FROM TABLE <ITAB>.
<Field2> = <Value2>. . . (Mult.Rec)
WHERE <Condition>.
If at least one line is changed, the system sets SY-SUBRC to 0, otherwise to 4.
SY-DBCNT contains the number of lines changed.
NOTE: Updates (Overwrites) if record exists else Ignores.
;':
%:
9:
.,. .,.
p~(~("~p~%,f
:* AUTHOR
..!..'..I:
,. ..I,.*,., .,. , 9,.
5,: S ~ ~ A RI)$,'[-],<
%: PURI'OSE
*: COPIED FROh4 :
*...,,,..,...,*, ,...,.
L
. .b
J'
R401)IF1CA'l~'10lV LOG:
C I - I A N G REQUEST
'"MOD-00 1
"MOII-002
'$SUPPLIER
: :k * %:
~
$: ;k
:
*
:>
* ,,..,.*. *. ,,.,,...,
.;..'. ,. .> .', .<,
4, -1,
* :;: :k
4, J. +
r.
:$
...
.!,.I. ,,. -6 a.I.,
,,. ,. q,,.
.L
. ..,I..a. .'.
,,..,
:k $ :: 6 :k :; :I;
:3
.I,
:;: :!: 9: 5,:
Cl lEMAX4756
DETAILS OF MODIFICATIOK 00 1
DETAILS OF MODIFICA'I'IOfi 002
EMAX 'TECHWOLOGIES,AMEERPEEI-
\
-,
$
!: :$
*
Open SQL
.I.
-., .'- .....,.
+ + <',..,..
-1.
$ ::
.I? + .> -'- ..,.
.!.
4:
1
., -1.
:> :$ $:
W e Never Compromise in Quality, Would You?
+ >,.
.1,
:; ;i: ::: 5::
; :: 9,:
:i; : :I; ;$ >:
);: %
:
5,: :i;
* $: 5,: :i;
*'-
+ I
**
4,
Q
'I-
;k :I; 2:
9,: ::: ;I:
-:-
:* 2: :: :I; * 8 *
,..j.< .I-
2:
G,
- -- . -- p-p-ppp--
---
--
,l,F i l l , f
~
,\I r mi.,, ,I r L i , 8 3 ,
~
I I I L, I , ,, L<,,l
p - ~ -
, 7
~
6if
-.-."
%' I4 4 t )I B @ [j a --
Checktable
CLEAR WA-TO0 1.
WA TO01-BUKRS = 'E005'.
W A ~ T OIO-BUTXT = 'IFLEX TECHNOLOGIES'.
WA-TO0 1-0RT0 1 = 'HYDERABAD'.
ULJNE.
WRITE : 'THE NO OF RECORDS SUCCESSFULLY PROCESSED FROM
ITAB',
Page 9 of 34 By Ganapati Adimulam
eMax Technologies,Ameerpet,Hyderabad
Ph No :+9B 40 -65976727, Cell No :99484 44808,98490 34399, www.ernaxteclla.com
4
Open SQL
We Never Compromise in Quality, Would You?
SY-DBCNT.
OUTPUT : EXECUTE THE PROGRAM
-
--
%'"aI4
?-
---
-
4 b bl @I
--- -
-n"
[Ta
-r --i18 Check table
"-- ". - -
. .
ASAP TECHNOLOGIES
Open SQL
W e Never Compromise in Quality, Would You?
Deleting Lines :
DELETE <DBT> FROM <WA>. "Single Rec
DELETE <DBT> FROM TABLE <ltab>. "Multiple Rec
REPORT ZDEMO-OPEN-SQL-DELETE .
;k *:;, ;::;: * :; . .;..: .: <.....,. ."
8'. 2
. 2.-, -,.
.',9
4
. ...' * ;::* :; * * ):: :i: * *: * :) *: *: ':::k * *: *: :k * * :) :k * *: >: :I: * ;::: :I: * 4: * $ :* * <: :I: ;:<:; :I':I: * * * :::*
,$
:$ I\/IODIF'ICAcI'jO&
* .................................................................., .:. . , ,
ULNE.
WRITE : 'THE 1VO OF RECORDS SUCCESSFULLY DELETEDt,SY-DBCNT.
NOTE : EXECUTE S E l l and Check For the Contents Before AND After
Executing the Program.
BEFORE :
63, 14
"-- ------m"
4 P ,I & %
mv------ "7-n"
aa Check table
--
f ai; ' e I+;
E
L ; , F F ~3y6::: f ; 1,:~.
~ '7 ,,f 72 =.Ii:,..lil,c. 7 i?st .+.?,lit.;
0259 .-,
I /
I /
.
&- ,Z~
. I4
.--
4 b bI
....-.-.-..-------.v .
%? @
. ..
a ,--.-p,-,.--.
Cliec? table . . .
. . ,. . . . , ....
i A i
Call i ? i -7
.., .
;ls,:.~la.yarj +-s!il.;: r.?.' o i. -1-2 , .,
-,
F ? x e d :oli.:::iny 2 i; st .;!I i..i?5il I
r
'I
C 1 i ~ n Cnrnpqn\*
t Corio Corny-ny nalne
-Clty
- Con entry Cllrrency ~ a n g u :
1
:
I
I
:BOO EOUl ellAX TECHNOLOGIES HYDERAB4D I 11.
/ 1
lson EOU~ CLARION PAPK TECHNOLOGIES BRNGLOPE IIIF 8 I
eci0 ~ 0 0 3 9G TELHIIOLOGIES MUPIPBI
/
I
1
I
1 /
I /
I I
SY-SUBRC SY-SUBRC
For Single For Multiple Records
Record
INSERT 0 - For Successs 0 - For Successful
Insertion Insertion of All
4 - For Un Records.
SuEcessful 4 - When One More
Lines Cannot be
Inserted Because of the
Duplicates.
FROM <DBT>
WHERE <Condition>.
3 COUNT( "
column <C,>.
returns -thetotal number of lines in the selection.
You can exclude duplicate values from the calculation using the DISTINCT
option. The spaces between the parentheses and the arguments of the aggregate
expressions must not be left o~lt.The arithmetic operators AVG and SUM only
a
work with numeric fields.
REPORT ZDEMO-GET-COMPANY-DATA .
:: :: +: :; :;: :: :;: %: :; $ .+ :> *: >:; P:; <;: :; .+ Q .>, , .,.!,,.'.
,,. ;!., .', .'. ,.,.'..'+, ,,.
,. -.. .,..'.
.!..'. <. , .$
-8, .' : 4: :!::b :I: 2: :I :I: :: ,::;!: :: :: $: :!:;: : :; ;: :: :: 2: :i: : :;: 2: .+ :: :!: .+ .+ :!:,:;2:
*: h40DIFICATION LOG:
*: CHANGE REQUEST : C l lEMAX4756
*MOD-00 1 DEI'ATLS OF MODIFICATION 00 1
:$plOD-OO:! DETAILS OF h4ODIFICATION 003
'bSUPPLIER EMAX TECHT\IOLOGIES,AhIEERPET
SEL *
*: 11 rsw ,AY D A - L ~
LOOP AT IT TOO 1 INTO WA-TOO 1.
WRITE : 1
WA TO0 1-BUKRS,
~ ~ 3 1-BUTXT,0 0 WA-TO0 1-0RTO 1,WA-TO0 1-LAND 1,
WA-TOO1 -WAERS.
CLEAR WA-TO0 1.
EIVDLOOP.
Page 16 of 34 6 By Ganapati Adimulam
eMax Technologies,Ameerpet,Hyderabad
Ph No :+9140 -65976727, Cell No : 99484 44808,98490 34399, www.ernaxtec8r.com
Open SQL
We Never Cornpl-ornise
--
in Quality, Would YOU?
Note : This Reads all the 20 rows at a time into the internal table Rut there is
another way where you can read the data in packages of records(i.e <N> no
cf recsrds every t i ~ ).e -
REPORT ZDEMO_-GET-COMPANY-DATA.
:,: :;.C :$ 4: $ :+ :: :: ;
: :+ 6 :;: A: ;::g $: * :k ::. $ :k ::' J: 2: i;* * J: : ;!: $: z,k 8: :k $ + 2. :b :? :: ::;k .:' :': k :F ::' :: :: -> -:: >: ::.;:. ;.: :.4. ,!. ;!:<: 4: 4 >: q: 4
ET-COMPAKY-CODE
PATI..AL)IMUI..,AM
RK WITH APPENDING STATEME,NT
* COPIED FKOhl :
* *: :!: :k :> 2: :k :*
:t $: * $: +
. +; ;:
$< 8< ;k ,* * :k >; #: 2: ;k * 4: 2: >k
$: *: 4: 2: :k * $: J
.: .,..!.
;k ;> 9,.i t. ,.
1.4.., 4::k
* -6)I. .I.*+: *
'I MODIFICATION LO
* CHllNGE REQUEST : C 1 lEMAX4756
SELECT BUKRS
BUTXT
1
ORTO 1
LAND 1
WAERS
APPENDING TABLE IT TOOl
FROM TOOl UP TO 20 ROWS
PACKAGE SIZE 5 .
ENDSELECT.
"DISPI.AY T>ArlA
LOOP AT IT-TO01 INTO WA-T001.
WRITE : 1
WA TOO 1-BUKRS,WA-TO0 1-
W A T O O1-ORTO1,WA-TOO1-
WA TO0 1-WAERS.
CLEAR W A - ~ 0 01.
ENDLOOP.
Note : It Reads the 20 rows from TO01 But Every time it reads and appends
Only 5 records.
INNER JOIN: The Join Expression links each line of <DBTl> with the lines in
<DBT2> that meet the Join condition <cond>. This means that thcrc is always
one or more lines from the right-hand table that is linked to each line from the
left-hand table by the join. If <DBT2> does not contain any lines that meet the
JOIN condition <cond>, the line from <DBTl> is not included in the
selection.
<DBTl> are included in the final selection. Even <DBT2> does not contain any
lines that meet the condition <Condition>,i.e the system includes a single line
From <DBTl> in the selection whose columns from <DBT2> a r e filled with
null values.
Example :
Example for Both Inner a n d Outer Join :
Entries from K N A l Entries From KNBK(Bank Details).
'
b
r'
A
JOIN
nKUNNR
INNER J O I N ~ E JOIN(A1ways
R LEFT)
001
001
eMAX IC
eMAX SBI
AX ICICI
I 018301004245
010098236655
EXAMPLE P R O G R A M ON JOINS :
$ ;< ;I+ +I:$+. * :;: * :) 2: 2: <: 4: :g *: <: :i: :g 2: 2: :;: * 1: <: :;! >;: 9.,. .'.
6. .*. .".".,. .".'.;.
,<. . .".,.
.">,.",,.
.', ."
.,. 1,',, -I. ,;..,. 4.
.!,.'-
.!.
.,...,.!..'>. , >..".,,!...,. 9.., ,..!,4,,.. *..'. +
I.
4. .".<.,,.,.
.',,,. "..'.
$
.,
-
,. .!,.:.<..,. -k..,",.,.,.
4. <. ,
.,
'.
.
IF RB-IJOIN = 'XI.
WRITE : / 'THE RESULT 0
SELECT
VBAK-KUNNR
VBAK-VBELN
INTO TABLE IT-SALES
FROM KNAl INNER JOIN VBAK
ON KNA 1-KUNNR = VBAK-KUNNR
WHERE KNA1-KUNNR IN S-KUT\TNR.
ELSEIF RB-OJOIN = 'XI.
SELECT
VBAK-KUNNR
VBAK-VBELN
INTO TABLE IT-SALES
FROM KNAl LEFT OUTEK JOIN VBAK
ON KNA 1- K W R = VBAK-KUNNR
WHERE KNA 1-KUNNR l N S-KUNNR.
a
Page 2 1 of 34 By Ganapati Adimulam
eMax Technologies,Ameerpet,Hyderabad
Ph No :+9140 -65976727, Cell No : 99484 44808,98490 34399, ~vww.emaxtech.com
Open SQL
We Never Compromise in Quality, Would You?
IF SY-SUBRC NE 0.
WRITE : / 'NO RECORDS FOUND FOR THE GIVEN SELECTION CRITERIA'.
EXIT.
ELSE.
DA'TA V-LINES TYPE I.
SORT IT SALES BY KUNNR VBELN.
DESCRIBE TABLE IT-SALES LINES V-LIhTES.
WRITE : / 'THE lV0 OF RECORDS FROM IT-SALES', V-LINES.
ULrNE.
SAP
..,.-.
: :
---- c
CLCT3!,lEF. K L SiiLES ORCEF:
--A
:LO13 53L5
?LOO h'C4
C(,* -.I>. L C
2
>,:cu .,..#, r
r-7.
:I C O i37'1
'irju c,s:c
.:ccu ""
I,,:
:rail ;,4?x
>LO" >.;:,
i i:;,, 035"
Cl:O 591::
.1 . I.?
' <,,.I.! " , > -.'
.,.-,
?C1,,j a< L;;
!,CCC 2.5:
il'L:O .'.;;hg
;rt11 ; KT
iLijl, :,'h
:coo ..
9.0.
~?
i CC1 I.;!!
1r.1 5 62
ITCl 5'95
. .
rpt: Y F ~ L I II FI I E F T ! j i i ~ k ~ , j i t . I:; .- ..:
:
! t F iI3 Ill :!:.;oF!E:- zl(71, I1 ,:,;,l.Ec
j,12 1
.ri;i
8 i 3;:
J q.. .J ::
i'
,
Notice the Nd Of Result Records
In INNER JOIN : 147
In OUI'ER JOIN : 150
i cot 51?5
< L- G, I jlgt
i!.'lil .,.
c,,.,.
;cr;, - .,
.It ,.
< - .,.
: .I I, 53;
i CCI 53:i
./_I 53*:0
llrl -,
.,>.,
: , :.
tic; > . ;"v -
.
: IIQI 5145
The WHERE clause of the SELECT statement has a special variant that
allows you to derive conditions from the lines and columns of an internal
table:
SELECT ... FOR ALL ENTRIES IN <itab> WHERE <con& . ..
<cond> may be formulated as described above. If you specify a field of the
internal table <itab> as an operand in a condition, you address all lines of the
internal table. The comparison is then performed for each line of the internal
table. For each line, the system selects the lines from the database table that
satisfy the condition. The result set of the SELECT statement is the union of
the individual selections for each line of the internal table.
You can use the option FOR ALL ENTRIES to replace nested select loops by
operations on internal tables. This can significantly improve the performance
for large sets of selected data.
REPORT ZGDEMO-FOR-ALL-ENTRIES
DATA : V-BELNR TYPE BELNR-D.
SELECT-OPTIONS : S-BELNR FOR V BELNR. -
SELECT BUICRS
BELNR
XBLNR
a
BUDAT FROM BKPF
INTO TABLE IT-BKPF
WHERE BELNR IN S.-BELNR.
IF SY-SUBRC = 0.
MOVE : WA-BKPF-XBLNR TO WA-FINAL-XBLNR,
TO WA FINAL-BUDAT.
ULINE.
IF SY-SUBRC - 0.
LOOP AT IT-FINAL INTO WA-FINAL.
WRITE :/I SY-VLrNE,WA-FINAL-BUIW UNDER 'COM CODE1,SY-VLINE,
WA-FINAL-BELNR UNDER 'ACC DOC NO',SY-VLIhTE,
WA-FINAL-XBLhTR LWDER 'REF DOC NO1,SY-VLNE,
Page 27 of 34 By Ganapati Adimulam
eMax Technologies,Ameerpet,Hyderabad
Ph No :+91 40 -65976727, Cell No : 99484 44808,98490 34399, www.emaxlech.conm
Open SQL
We Never Compromise in Quality, Would You?
ENDIF
I-: ,I)',
> " - -
; . . .[ :.:;;;
' '
. ;
. . . .
. ' ..
.. . .. . .. . .. .. .,:.. . . .. . .. . .. .. . .. . . . . .
"
. . . . . . . . .; !~;;
..... - . ..
1 1 I
,
--.
: : I
Duplicates are removed from the answer set as if you had specified "SELECT
DISTINCT" ... So unless you intend for duplicates to be deleted include the unique key
of the detail line items in your select statement. It will only pick up one line item if
multiple line items appear with the same debitlcredit indicator, amount and GL Account.
If you want all occurrences of these you must have a select statement that includes
the table's unique key, also called primhry key.
SELECT bukrs belnr gjahr buzei shkzg wrbtr saknr "bseg unique ltey + dlc ind,
amt, GL acct from BSEG into table t-bseg for all entries in t bkpf where belnr
-. =
t-bkpf-belnr and bukrs = 'CUR '.
a
FOR ALL ENTRIES IN ...acts like a range table, so that if the "one" table is empty, all
rows in the "many" table are selected. Therefore make sure you check that the "one" table
has rows before issuing a select with the "FOR ALL ENTRIES IN ..." clause.
IVOTE : If the parent table ( i t blcpf) is very large there is performance degradation
UP TO 1 ROWS
WHERE <Condition>.
k
Include all the Primary Keys Can have the Part of the
To Identify the record Uniquely. Primary Key.
3 Prefer this to read the G t Prefer this to Validate Input
Information. as we are not Interested
with the Exact Match.
Because a record is Valid if 1
LPA--- at-least-
one-1
record found. 1
Page 30 of 34 By Ganapati Adimulam
eMax Technologies,Ameerpet,Hyderabad
Ph No :+91' 40 -65976727, Cell No : 99484 44808,98490 34399, www.ernaxtec&.com
Open SQL
We Never Compromise in Quality, Would You?
Note1 :
When we Don't Pass all the p;irnary Keys in the SELECT SINGLE , it Acts
as SELECT UP TO 1 ROWS, but doesn't throw error.
REPORT ZDEMO-SELECT-SINGLE-UPTO-1
,. ,.!.
.*, 4: :;P
,. .>,-1. . :> :;: <: k: :I :;: :; ;: :: :;: 2: ;P :g : >:::;P >: :I : Q :I j: :; :;P :; :;: 4: ;P * :I 4: ::I; :s * 2: :>MESSAGE-ID ZDEMO.
:;: 2: 2: >; >; :;: ;: * : * :; ::*: 2: :!: :g :;: 2: :t :I :;:
$
; $ ;:I; >:
": PROCR/\M ZDEMO-SELECT SINGLE-UPTO -1
* :L,I'I IOU GAI\~APATI-II
.ATI~;~/IUI.AM
:!' STA IC'1' 11A'l-E 2710 112008
':: PURPOSE IS TO WORK WITH SELECT SINGLE AND
SELECT UPTO 1 ROWS
* COPIED FROM : NA a
<: 2: * *: 2: $< :g :$ q: 4: :;P * 2: <: * *: 2: ;* 2: g: * 2: * * *: ;: :k * 2: 4: *,** <: * * * * * *
;:I; >> ;:I; :) ;P $< >: :2 *: j: ;g * 2: 9: ;!: * *: * :* * <: ;!*
j: *< <:
" MODIFICATION LOG:
": CHAXGE REQUEST : CllEMAX.1756
s,: .................................................................
S TYPE BUKRS,
ENDSELECT.
ULINE.
IF SY-SLJBRC= 0.
WRlTE : / 'Tlie Details Are', V-HUKKS,V-KUNNR.
ELSE.
WRITE : / ' It is Not a Valid Customer'.
ENDIF.
1
Tiit- :i,z,,.i:ni 1s ,;I r. F3rJI.: SELErT 5INGi.E ( f i ; S O 34E;T
Exercises
d
List all the rows from the table LAGP (Storage Bins)
List all the rows from the table EINA (Purchase Info Record) for the
given Range of Vendor.
List all the rows from the tables KNAl (Customer General Data),
KNB4 (Customer Payment History) for
Accept document no. from user and display the particulars of the
Sales Docu. No, corresponding material no. description of that
material and item category. (Table VBAP, default docu. no.
'0010000031').
ABAP Debugger:
a
Use
The ABAP Debugger is an integrated test tool within the ABAP Workbench. You
use it to trace the source code of an ABAP program. In the Debugger, you can
step through the source code of a program. The running program Can be
interrupted after each step, allowing us to check its processing logic and the
results of individual statements.
Features
The Debugger provides an efficient illeails of identifying errors in ABAP
programs.
It contains the following functions:
> Ways of starting the Debugger
P Choosing Debugger settings
P Choosing different execution options in the Debugger
> Displaying source code in the Debugger
> Setting and deleting breakpoints
> Setting and deleting watchpoints
3 Stopping a program at a particular statement. event, subroutine, or
function module
> Display d contents at runtime
Choose Debugging
screen
p,!$
:8
2. Enter the name of an internal1
$ table in the Internal table field, os,i
1:
if select <itab> by double-clicking its/
!$
jl name in the source code. ]I II
Page 3 of 13
-
By Ganapati Adimulam
eMax Technologies,Ameerpet,Hyderabad
Ph No :+91 40 -65976727, Cell No : 99484 44808,98490 34399, w1~7w.emaxteck.co1~i
ABAP Debugging
We Never Compromise in Quality, Would You? I\
Instead of starting an ABAP program directly in the Debugger, you can also
debug a program by creating one or more brealtpoints in the program. A
breakpoint is a signal at a particular point in the program that tells the
ABAP runtime processor to interrupt processing and start the Debugger.
The program runs normally until the breakpoint is reached.
Static Breakpoints :
Static breakpoints.are not normally user-specific. Once a user has inserted a
BREAK-POINT sta~e~nent in an-ABAP program, the system always interrupts
the'program at that point. You should set static breakpoints whenever more
than one programmer is:wo,rking on the same program and you always want
to stop the program in the same place. You should only use static breakpoints
during the development phase of an application.
i END OF W;i-LF.fi,1
!
. .:
ij .;rURNR
'
/' Il4TO TABLE IT-LFAI
1
I/
FROM L F A l
......
LOI:IF' AT IT-IF.&' INTO !.!A-LFA,I
l:!lRITE / I;,!P.-LFHI -1IANDT ,!JA_LFI;I LIFI.lE. WA-LFAI . ORTO1 .PI.a.-LFAI .+?DEN6 !.;
.
' - .A
i: CLE,&E IJ,~,-LFAI
..... . . . . . . .- ..........-. -
........ -..-
. . . . . . - .-
. . . . . . . .-
. ...... .- - ...............
.Li 20,Co 2 - L i 20.Co 15 L n 7 - L n 26 of 27 lines
_ ............... . . .. -_I___-- . -......... -._
. . : ,,_"_ ....... ,
:. : SAPUSER :fi/ ernax INS
.. _, ?..^
.................................................................................................................................................................................................................................................................. ' ,,,.,
This Program will be always executed for all the Users because of tlie Statenlent
- - -- --- -.--
. - ---- - -- -
,
Fl~Ids
pf ~'g13rrt
hla~l-i
Table
- - -
Rteakpo~nts
;DEt.;0-l10DIF
-.
Watchpnlnts
- -
i-DELETE-FPOtI-IT4B
-
Call:
- - -- - - -
7-
f
Ove~iievv
r >
Sett~ngs
- "--
-
-t
b BREW F i l I l l T
Dynamic breakpoints are more flexible than static breakpoints, because you
can deactivate or delete them at runtime.
Breakpoints at Subroutines
Breakpoints at Function Module Calls
Breakpoints at.System Exceptions
8ctivate:deactivati
jla.-r/,;..
@'g2gh --L,->,.-,":/ ,*, W/eIISr.*y
s-3 -,:2c
Delete all
r...
*= -s. : .= i.5 a ,~;\/~t~hDeactivate ail
-
-*
........ ........... ActCiate all
Fields
.i.- Teble
Save
- -
tvlain program
- Breakpoint
- at
Sourl-e code of , ,' ZDEM
........... Create ~ a t c h p o i n t ShiR+FE; Subroutine.
EVEIlIT STAF:T-C~F-SELE~~TI(-~,,,
..............................................................................
IIAIICIT
LIFNE
ORTO I
kOFil\lR
I l l T O T46LE IT-LFA 1
k @ FROM L F A l
Here you Select the Record, Click On ChangelInsertIDelete for the respective
Operations.
Steps to CreateISet Watch points:
If you want to interrupt a program when the contents of a field or structure
change, use a watchpoint. You can set up to five watclipoints, including
watchpoints for strings.
A watchpointm.ay be either local or global: Local watchpoints are only valid in
the specified *rograrn. Global watchpoints are valid in the specified program, and
also in all other programs that it calls.
ABAP Debugging
We Never Compromise in Quality, Would You?
-.
- -........
Greater than
6. You call use the Comparison Jield option to specify whether the
cornparisoil should be with a value that you specify or with the contents of
another field.
7. Depending on your choice from ue or a field for the
comparison.
r-
. field (Cornpat~sonvalue !I riot selected]
~-.omparlsos~
Crimp iieldivalue 3il~i1I
- -"------
. - "
27 52 -a '
i:
73 F k ~ l dr ? l m e c 3 1
loop a t I t - t o 0 1 i n t o w a _ t U O
WRITE : / 5 WA-TO01 - EUKE5,
sy-vline,
ABAP Debugging
We Never Compromise in Quality, Would You?
Single step Use this option to step through the prograin statementi
by statement. This allows you to branch into subroutines'
and function modules, and to execute these routines step'
by step as well. Once a subroutine or function module/
has been processed, control returns to the statement'
lc
following the CALL FUNCTION or PERFORM/$
statement. .I
I
Execute 'z Use this option to process a program line by line. All ofi
a. BNIrI'lAklZA'FION.
Ib. AT SE1,KCTION-SCREEN.
C. AT SELECTION-SCREEN ON.
d. START-OF-SELECTION.
C. TOP-OF-PAGE.
i: END-Q)H;-L'PaCE.
g. dl:NI[)-OF-SIII:LBi:Crr91411N.
Introduction :
Report is displaying the application data in the required foi-nlat. Technically
spealting, a report is an executable program with three stage f~~nction:
Data input -> data processing -> data output.
~ a t i n Of
~ sSAP Institutes:
Output Ratings
Selection Screen Database -----------
(Input) ~etriGva1Logic I EOOl eMAX
2 1001 iMAX
3 ZOO1 zMAX
4 YO02 yMAX
F3 Database
Purpose : It helps to analyze the current situation and also for decision Malting.
Note: The data types valid for parameters include all elementary ABAP types
except data type F.
If the parameter refers to data types from the Dictionary, it adopts all attributes of
the Dictionary field. C u ~ ~ e n t l parameters
y, can only refer to fields of database
tables, views and structures. In particular, the field help (Fl) and the possible
entries help (F4) defined for these fields in the Dictionary are available to the
user.
Note : The user cannot continue with the program without entering a value in this
field on the selectioii screen.
Defining Checkboxes:
Parameter <Name> is created with type C and length 1, and is assigned to group
<GI>. Each Radiobutton Group ];as atleast Two Radiobuttons and by default the
First Radiobutton from the group is Selected .
I
Note: The Value Of the Selected Checltbox/Radiobutton is 'X' and for the
Deselected is ' ' (SPACE).
<'
Click On , to enter Multiple Ranges, Multiple Single Values to be
INCLUDEd and to be EXCLUDed.
--
t
\
HIGH
alues are I and E.
SYNTAX :
SELECT-OPTIONS <Name> FOR <Variable>.
a
REPORT ZDEMO-SELECT-OPTION
:i:******:X:k*~:*:i:*******:i:***:i:***
.
:i:***:i:**:::****:g***:i::::*::::i::$*>>:i::i::::$::k:$*:
:* MoI>It*lC:ATIO&LOG:
*1 .Q S ' : C I I EMAX1756
'4~__----_--__-_---------------------------------------------
comparr,; c o d e
Venaor Nclrrtber
Blank Lines:
SELECTION-SCR~ENSKIP [<n>l.
tes <n> blank lines, where <n> can have a value between 1
single blank line, you can omit <n>.
Underlines
To place underlii~eson the selection screen, you use:
This stateineilt generates an underline. If you do not use the <pos(len)> addition, a
new line is generated for the underline below the cur-rent line, and the underline
has the saime length as the line. If you use the <pos(lei~)>addition, the underline
begins at position <pas> in the current line and continues for a length of
c l e w characters. With several eleil~entsin one line, you can also specify (<len>)
witl~out<POS>.A slash (I) produces a line feed.
Comments :
SELECTION-SCREEN COMMENT [/]<pos(len)> <comrn> [FOR FIELD < P I .
This statement writes the <comm> comment on the selection screen. For
<comm>, you can specify a text symbol. You must always specify the <pos(len)>
addition.
Only if there are several elements in one line, can you omit <pas>
You use FOR FIELD <D sign a field label to the comment. <f, can be the
name of a parameter or a s n criterion(SELECT-OPTION).
Blocks of Elements :
SELEC
[WITH
SELEC
' e m i F~nisl-led
#
\
PROGRAM
:: &
"&--------------- -- - -- - - - - *
REPORT ZGDEMO
v MTART= 'FERT'.
ELCEIFRB-SAMP = 'XI.
V MTART = 'AEM'.
ENDIF.
SELECT MATNR MTART INTO TABLE IT MARA
FROM MARA
WHERE MATNR IN S-MA
IF CB DISP = 'XI.
WRITE: / 'MATER
uline.
LOOP AT IT-MARA IN
WRITE : / WA MA , 2 0 WA-MARA-MTART.
ENDLOOP.
ELSEIF CB-FILE = 'XI.
AI'PEND --
-- t I
WRITE-FIELD-SEPARATOR = 1x1
TABLES
DATA-TAB = IT-MARA
IF SY-SUBRC 0.
WRITE / 'DATA IS DOWNLOADED SUCCESSFULLY'.
-
ENDIF. a
ENDIF.
RESULT :
36 HILa
56 "!EL
5= liilii
(.
-.
i rl'l?]
,4 IZFN
SF FERl
8" FEHT
22 HiiLt:
i 7lj I'JLSC.
170 llL?b
is::
,. ,.>.
:
',II
.
*
Ell *ST.
ill, i:;
(i ">,.,>'.
.... 11: t. P.
7''I l,sl:P.
,-:.3 I ~$l,
i?i barli!..
<&
Serni F i n i s h e d
OUTPUT
#jf&33qgj []jjj ~ $ gs&$jg2cfk)p
~ j @ , $ j ~ g j f ~jijxg
W,A
.
- - . . . . . ... . . . - .......................
[~00000000000000038 HALE
H I EE
H I EE
FHMI
DIEN
FERT
FERT
HALB
N LAG
N LAG
N LAG
HALB
HAWA
HAWA
HAWA
/%me
1 Event
of the
I -7
1 INITIALIZATION I This event occurs
1
Trigger~ng Purpose
I
before the standard the standard selection screen
selection screen is
I called.
I AT SELECTION- I This event is To Validate the input provided
/ SCREEN /
processe(d before .through I
Selection Screen. I
1 I leaving- the Selection I ~ o t e :If an error message 1
Screen i.e. when the occurs in t h s processing block,
selection screen has the selection screen is
been processed (at redisplayed with all of its
the end of PA1 once fields ready for input. This
the ABAP runtime allows you to check input
ellvironinent has values for consistency.
passed all of the input
data fiom the
selection screen to
the ABAP program).
To Validate 1-
I SCREEN ON <Field input provided through
Selection Screen.
Note: It re displays only the
this Particular Field if the input
is wrongly entered.
I
1 START-OF- This event occurs -:-The REPORT statement
SELECTION after the selection always executes a START-OF-
screen has been SELECTION implcitly
processed and before consequently all processing
data is read using the logic
logical database. i.e, non-declarative statenlents
that occur between the
REPORT or PROGRAM
statement and the first
processing block are also
1
processed in the START-OF-
,
SELECTION block.
TOP-OF-PAGE Tl~is is
processing
a list
event
This allows you
define output which
tC
executed before the supplements
first data is output on standard page header at
Page I 3 of 74 By Ganapati Adirnulam
e M a x Technologies,Ameerpet,Hyderabad
Ph No :+91 40 45976727, Cell NO: 99484 44808,98490 34399, wwn.emi~xtech.coun
Reports
We Never ~omp'romiseIn Quality, Would You?
r
- -- - - . --
a new page. the beginning of the
This is processed page.
only when generating
basic list.
This is only executed
before outputting the
first line using any
output statement such
as write , uline, skip
on a new page. Note:
It is not triggered by
a NEW-PAGE
statement.
.- -- .- -----
-- .- - - -- -- - - - - .- -- -- -. -
-- -
END-01'- This is the last of the Used to print the final output .
SELECTION events called by the
runtime environment Used to print Grand Totals
to occur. when working with Logical
It is triggered after all Database.
of the data has been
read from the logical
database,
and before the list
processor is started.
* h~l0DIFICAI'ION I,OG:
"CHAXGE REQCEST : C l lEMAX4756
'F--,-------------------------------------------------------
END OF TY POS.
b
* TOP-OF-PAGE
* ................................................
TOP-OF-PAGE. a
WRITE : 15 'Comp.Codel,
17 'Vendor',
28 'Pur.Orgl,
40 'Doc.Nof,
5 2 'Item',
60 'Mat.Nol,
80 'Price'.
ULINE.
INITIALIZATION
:k 8 * 3: >: * :i:& 4: k: :* ::;* * :i: : * * :; ::; 2: * :k * :* + :* * * * :k * ::* :I * k: * * *
:
: :$
INITIALIZATION.
S-BUKRS-LOW = '1000'.
SBUKRS-HIGH = '5000'.
SBUKRS-SIGN = '1'. a
S-BUKRS-OPTION = 'BT'.
APPEND S-BUKRS.
AT SELECTION-SCREEN ON SBUKRS.
SELECT BUKRS INTO V-BUKRS FROM TO01 WHERE BUKRS IN
S BUKRS.
ENDSELECT.
IF SY-SUBRC <> 0.
WRITE ; / 'INVALID COMPANY CODE'.
ENDIF.
AT SELECTION-SCREEN ON S-EKORG.
SELECT EKORG INTO V-EKORG FROM EKKO WHERE EKORG IN
S EKORG. a
ENDSELECT.
IF SY-SUBRC 00.
WRITE : / 'INVALID PURCHASING ORGANIZATION'.
ENDIF.
START-OF-SELECTION.
SELECT EKKO-EBELN
EKKO-LIFhTR a
EKKO-BUKRS
EKKO-EKORG
EKPO-EBELP
EKPO-MATNR
EICPO-MENGE
EICPO-NETPR
INTO TABLE IT-POS
FROM EKKO INNER JOIN EKPO
ON EKKO -EBELN = EKPO-EBELN
WHERE EKKO-BUKRS IN S-BUKRS
AND EKKO-EKORG IN S-EKORG.
:+*:!:***:!::$:$:+:$******:$********:k****:~:~****$:*>k:*:$
END-OF-SELECTION.
;~**!:**:*:~:*:::::**:::$::+************~:****~:***:::****
a
END-OF-SELECTION.
IF NOT IT-POS IS INITIL.
LOOP AT IT-POS INTO WA-POS.
WFUTE : I5 WA-POS-BUKRS,
17 WA POS-LIFNR,
28 WA-POS-EKORG,
40WA-POS-EBELN,
* END-OF-PAGE
$: $ * $ :!: :+ * * * * +: * 2: :+ * 2:
$ $: >$ $ :+ $ $ $ :$ *
y 4: $ :!:$ ,:!$ :!: 4: 4: :g : $ :$
$: :k
END-OF-PAGE.
IJLIhTE.
WRITE : I30 'eMAX Technologies,Ameerpet,Ph-66972767'.
ULINE.
Page 17 of 74 By Canapati Adimulam
eMax Technologies,Ameerpet,Hyderabad
Ph No :+91 40 -65976727, Cell No : 99484 44808,98490 34399, www.emaxtech.co1111.coi11
Reports
We Never Compromise In Quality, Worlld Yon?
------- -" " *- ---7""""-7m---- -- ---- "-" " " * - "- ---- ---*
1080
7 il00
.1000
'irJgu
1(1 I3rj
I gfiu
1 ':I80
.I rJ[iU
1 illjlj
l 080
1058
., - ,.
I l11,8
.1 onu
1 UIjO
1080
<Statement Block>.
ENDAT.
You can react to the following control level changes:
l<level> Meaning. 1
P T FIRST First line of the internal table
AT LAST Last line of the internal table I
/ATNEW
A T END Of
<f>/ Beginning of a group of lines with the same contents
in the field 4 6 and in the fields left of <D
End of a group of lines with the same contents in the
<f> field <6and in the fields left of <f,
You can use control level statements to react to control breaks in internal lables
instead of programming them yourself with logical expressions. Within the loop,
you must order the AT-ENDAT statenlent blocl<s accordi~lgto the hierarchy of
the control levels. If the internal table has the columns <fl>, <f 2>, ...., and if it is
sorted by these columns, you must program the loop as follows:
a
Page 19 of 74 By Ganapati Adirnulam
eMax Technologies,Amecrpet,Hyderabad
P h No :+91 40 -65976727, Cell No : 99484 44808,98490 34399, www.emaxtech.co~~~
Reports
We Never Compromise In Quality, Would You?
LOOP AT <itab>.
AT FIRST. ...ENDAT.
AT NEW <fl>. ...... ENDAT. a
EXAMPLE PROGRAM
REPORT ZDEMO-CONTROL-BREAK-EVENTS line-size 200.
:k **
::: :$ ,:: :!: * ::.: :::* ::: ::. * :i:>: ,::* :k >: * * ::.* * * * * * * * >: * :$ +: :$ :!: :) :;: * >: * :!: $ :;: :) $!: * :i: >: :b <: :!: * :) :\
* P.ROGKAM ZDEMO-CONTROL-BREAKEVENTS
:k A UTI..IOR GANAPA'I'I .ADIMULAM
" START DATE 2710 1i2008
* PT_;RPOSE CTRL BREAK STATEMENTS
'"pERA'.I'ION.'S
*: COl-'IEI> FROh4 : NA
:k :: :I 4: * :: :; 2: * :> :;: ;: ;) :;: :: ;: :g ;!.,..'.
.,. + 1. ."
.'--,,. .,...'.,...
,,.". .".',,.. .,. ,,!...,.
.I. . .
,. ,.',. .'.
.;.4: ;) :$ * :: :) :: :I: :: ;!: >: ::: :: :\ ::: ::: :\ :: :: :: : :':, :!:, 2: ;) :':, :!-
,..'.
.P
ON EKKO-EBELN =
WHERE EKKO-BUKRS
4 'PO', 35 'ITEM1,50'AMOLThTT'.
AT END OF EBELN.
SUM.
ULINE.
WRITE : 140 'SUM OF EACH PO' ,WA-EKKO-EBELN, WA-EKKO-NETWR.
ULllTE.
ENDAT.
AT END OF EICORG.
SUM.
SICIP.
WRITE : 140 'SUM OF EACH EI<ORG',WA-EKKO-BUKRS,
WA-EKKO-EKORG,WA-EKKO-NETWK.
SKIP.
ENDAT.
AT END OF BUKRS.
SUM.
SKIP.
WRITE : I40 'SUM OF EACH BUKRSf,WA-EKKO-BUKKS,WA-EKKO-
hTETWR.
SKIP. s
ENDAT.
CLEAR : WA-EKKO.
ENDLOOP.
ELSE.
WRITE : 1 'NO RECORDS FOUND FOR THE GIVEN SELECTION'.
EMDIF.
i GOO
~-11-)1:,
: ., . 2
'! ..jii!.;
:: ,]F,p
.,
:00i:i
"300
.q 7 -
c. LI12
.;nno
< 300
':1' 01]
.,
!
.- .. -
iluu
f .!
Sum Of Each PO 414-6100 21 ,521.
UO < !
Interactive Reports
Display the Summarized Information as the First List-And letting the USER Interact for
the Detailed Info. a
20th
Ex : Basic List 1" Secondary 2"dSecondary 3"d
f
SY-LSIND = 0
11
NOTE: We Can go up to 20 Secondary Lists.
1 1
Event: AT LINE-SELECTION AT USER-COMMAND.
Note:The List Index SY-LSIND will be incremented by 1 for each user Interaction.
By default, the basic list has a standard list status and a standard page header. The TOP-
OF-PAGE and END-OF-PAGE events can occur while the basic list is being created.
Note : Each 2"" ry List is a normal output list Only. But the Next Level Data
depends on the Selected Line and Contents from the Previous List. So it is
enough to know the way to find out the Selected Line Details of the Previous
List.
a
Ways to Find out the Selected Line Details from the Previous List (OR)
GET CURSOR : Use the stateme FIELD and GET CURSOR LINE
ursor was positioned during the
interactive event t
Program Heading
.I.
,. .~,, _,.,, _.__._
,, ...
...,, ,. _,. _,__I.
,, ,, ...
,. ,, _,_ _I_ _I. _I. _I. .
I .
I
.
,..~,, ,. ,, _._
,. ,~,, ....
,. ., ,~,, ,. .~,. ,. ., ,, _._ i.
_I. _.__I.
,. .. ,. ,~.~,~.. ,. .. ,.,, _..
.. ...._ _I. .I, I.
., .. ., '~,. .*I
_I. _#. _I_
.. ,. ,, .. .. ,, _._
.. ., _.._I. _I.
.~.. .._
_I. .I.
.~,. ,. .. _._
., ...
-1.
<.
_I. _I. _ I _ _I. _I. _I. .
I
. _I. _t. .I. _I. .C _.._,..I. .I. _I. .I. I.
"MODIFICATION LOG :
"MOD-0001 : D E T A I L S ABOUT THE F I R S T CHANGE I N THE PROG
"IvlOD-002 : D E T A I L S ABOUT THE,ZND CHANGE I N THE PROC
"TRANSPORT REQ. NO : C l l D E V 1 2 3 5 4
_I. .I.
,. ,. .. ,. ,. ,~_._
,, ,* ,....
,, ,, .,_ _>_ _(. .I_
.~_,_,._._
,. .._
_I. _I_ _._
,, ,~ .C ...,. ,, ., ..._
., ,, .~ ,, ,~,, ..I .._
_I.
.. ,. .. ,. .~_,_
_I. -1. _I. -8. I.
,._..
_..
,, <.,. ,, .~,, ,~ ,, ., ., .._
_I.
.> ,, ,, .....
.. .._ ,. .. ...,, ,, ,. ,. ., ...,, ,. ,. ,....,. ,~., ...,,
_a_ _1_ -7. _I. 7-. .
I. _I. _I. .L _I_ .I.
.\
<._ .1_ .I._,...
%
.
_I. .I. -1. .1_ J. .1_ 2
. .I. _1_ .C
* START-OF-SELECTION. :i:
********$:**:$*:$*$:*************:$*********************
START-OF-SELECTION.
SELECT BUKRS "COMPANY CODE
BUTXT "NAME OF THE COMPAIVY
ORTOl "C&Y
a
LAND1 "COUNTRY KEY
WAERS "CURRENCY KEY
INTO TABLE IT-TOO 1
FROM TOO1
WHERE BUKRS lN S-BUKRS.
***:+*:$~:***:!::::*$:$:******~::$*#:*****:~$:***#:**;$******:~*:!::::**
* END-OF-SELECTION. *
********>k*****************$<********$<***$<***********
END-OF-SELECTION.
ELSE.
WRI1'E :I 'NO FURTHER DETAILS FOUND FOR THE SELECTED
COMP.CODE1.
ENDIF.
ENDCASE.
EXECUTE
-pI-_l____rr_)-- - ..--
You use the HIDE teclinique while creating a list level to store line-specific information
for later use.
Actual List
From WRITE
K'
\
Copy in HIDE Area
From HIDE
NOTE: HIDE should be always a utput (write) statement.. Hide maintains the
REPORT ZDEMO-INTERACTIVE-HIDE.
;,: 2: :) :;: :i <: ;I: * *: :;: :{; :) :;: 4: :{: %: :;: 2: ;$ :) I: * * & :;: * ,k :> * * :!: *
$: :$ $: 9: $
, <: :I :* :;: * ;:;>: :; : :: ;+ :;; 2: ;) ;: $< << *
;:: :;: 2: :!; * 2: 2: >$
P Prograin Heading
: $ * ~ : ~ * ~ ~ : ~ : ~ ~ ~ & : ; : ~ ~ : ~ ~ ~ ~ : ~ : $ ~ ~ ~ : k * , : : ~ : : i : * ~ : p ~ ~ < : ~ : $ i : ~ ~ : ) ~ 9 , : ~ : ~ ~ ~ ~ : ! : ~ g $ r : i :
':'AI.J?'I-IOR : GANAPA1'I.ADIMULAM
*PROGRAM : ZDErVIO-INTERACTIVE-HIDE
"'COPIED FROM : NA
*:PU'RPOSl:.: : DISPLAY THE COMPANY DG'I-AIJ,S O N BASIC LIST
:k
AN11 CIJSTOMER DETATLS AND Reconciliation
Account: IS DEVELOPED USING HIDE
*
*KEFE.RENCE DOCS : DEVWR0065
*: ;k * * 8: >k *
j: 9,: *
8: ;i: 8: 4: :k * *: 4: :k * *: 8: * * * 4: * * 2: * * :* 8: * :g * *: 8: * 8: :k * *: * :k * 2:
:) j: $: :i: :$ 8: j: :) * * :k * 2: 4:
*: :$
'%IODIFICATION LOG :
" ' ~ O ~ - 010 0 : DETAILS ABOUT THE F1KST CHANGE IN THE PROG
*:h/IO1>-002 : 1)ETAII.S ,4130111' 'Sl---IT:2ND CIIANG113 I:N ']:'I--11; PROG
+'CUSTOMERMASTER DATA
TYPES : BEGIN OF TY-CUSTOMER,
ICUNNR TYPE KUNNR, "CUSTOMER NO
BII'KRS TYPE BUKRS, "COMPANY CODE
AKONT TYPE AICONT, "RECONCILIATION ACCOUNT
END OF TY-CUSTOMER.
* -START-OF-SELECTION.
****:g**********************$*********g*:g*******:g***
START-OF-SELECTION.
SELECT BUKRS "COMPANY CODE
BUTXT "NAME OF THE COMPANY
'ORTO 1 "CITY
LANDl "COUNTRY KEY
WAERS "CURRENCY KEY
INTO TABLE IT-TOO1
FROM TOO 1
WHERE BUKRS IN S-BUKRS.
q ,,,<,*********<:*************************+**********
.a.
* END-OF-SELECTION. *
q**q*;g******q*****q*******:>*:~****<:$;**>.*:~<.*<:*.:~.~..~..t..~..~..t..!..~. T -? * q. <. .> + <.
END-OF-SELECTION.
:$*:>*;$****:**:***;;:~:;:*:~::****;:*:~:.*::**:~:*~:*******::****~:~:.****:*::*
;:
;: :k : ;: :> :> >: >!<: * :: *: AT
* .",. ."LINE-SELECTION.
,i.9.' ."
<. <. <. . ., .'..' * ::* .;.
...,.,.
,;.,.';..." .".,.
"C + .$ 1I.. ?.. .*.+. ::* * +, ::* >: :: :::4: :I: * * :l: 2: >: ::
.*..,. a. ,r.,;.<.
.;.+
.t. ..4.
?
AT LINE-SELECTION.
CASE SY-LSIIVD.
WHEN 1.
""RETRTEI'E ALL THE C'I_:STOL'lGRS FOR THE SELECTED COMPANY
COI>I'
CLEAR WA-CUSTOMER.
ENDLOOP.
ELSE.
WRITE :I 'NO FURTHER DETAILS FOUND FOR THE SELECTED
COMP.CODEf.
ENDIF.
ENDCASE.
. .-p---..-p
OUTPUT:
q
. -- . . . . .......
Dint+ ~ r ' lI n t e r + : ~1 4 1 cc
ac-c:,,,e ~ : ~ ~ ) o l -D,-: ,I;.:. -...,:"
......
,-.+vtr~
. forfr. Text Cl -ty ~ C o v n tyr ,
.
1
:
:~u,.>< SAI' A G
7 0130 I D E S AG
1010 w 7 p,-0
1-1 0 1 LJIPEI, T e c h n o 1 n g i e s hydel-alld I N
? 818 emz!r t e c h n o ! o g y a hyd
.I m.7
,,.iD r~nar amp
ZGO~I IDES Oli Lonclon G E:
21 Dl3 IClES Por-t8.ig;il L i shon PT
--
7 7 ~ 0 I D E S I-rsi-lcr Par ,is rR
23012 I l>E5 Esaaiia Earcel o n a ES
2400 IClES 1 t : a l - i a i.!ilarlcl I T
2500 1l)LS. Nc;t:l?ri-; +nd,6. ~(GT:~~I-cJ~II) I<L
.::;I~I.J!.I rr~r?.;us .rrk, Idoitc Y o r k ;')I
r100 U I D E S ,;s!-,s,d.:: To?-onta .,e!
,..,
;I
If you double click on the company code a secondary list is displayed wliich
displays the coinpaliy code, customer number, Recollciliation Account.
displayed.
jpd..".,,";
,,,/,.~j!~~,
la,$..
' 9 . , ,9t2j,.,$4..*;
t,,,!{< f<j> ,.., *,,?,
<<,"*.<$,&
F? *2>,2h$j.?<.
-,,., $
.,,
( % . ~tl;,P*g
*,,~#t E~L,&+
p$
...,.. --. ..,
1.L
rlil ;iJETFEi3 05TiiTi.S FiJiJNT! FOE THE SELECTED COt!P <:ODE ..-
ivi
. .....
. .
Program I-Ieading
> * : ::; , *,.. ..,, , 9,,. ..,.. .<. ..> . * >.:. .I. .,....
, ,. .
; ; : * ......
: , <.
3, + .> ?. .,.-1.: * * ):: :k *
.$ ,, .I 1
. :k * 2: >:::I: * d.:: :I: * 4: :: :k * 4: :: :: 5:: :1: :I * $:
.I. :)i
$:A[~ ~ r 1 . 1 0 ~ : GANAPAT1,ADrMULAM
'!'PROGRAM : ZDEMO-INTERACTIVE-HIDE-COMPLEX
'$COPIED FROM : NA *
+'PURPQIS1'7 : I>ISPI.,AY TI-3E VENDOR T)I':1'I-AII,S ON I3ASIC L,IS'I'
9s
AI4D PURCI-IASINC; I-IEAlIEII IIt.:I'AIi..,S FOR ?'I 11%
2:
SELECTED VENDOR IN THE NEXT SECONDARY
LIST*
:$
AND DISPLAY THE PUKCI-IASING ITEMS FOR. TIlE
*:
SLECTED PIJRCI-IASE DOC. IN NEXT I,IS?I' AND
:I-
DISPLAY THE MATERIAL DETAILS FOR THE
* SELECTED MATERIAL IN NEXT LIST.
$:
REFERENCE DOCS : DEVWR0065
:$ :$ $: $: ::: * * :!: *: * :;::!: * * :i:* * * * :'.: *
$: :$ $: Q $: $: $: ::::g * :i: * :$ $: $: :1: ::: :> :;: :$ * ., * * * * * :* :> :;: * :: 4: ;k
90-. * i;* :$ 1: 4: :) **
, ...
.
*MODIFICATION LOG : ,
eMax Technologies,Ameerpet,Hyderabad
Ph No :+9140 45976727, Cell No : 99484 44808,98490 34399, www.emaxlech.com
Reports
We Never Compromise In Quality, Would You?
AT, SELECTION-SCREEN.
SELECT SINGLE LIFNR INTO S-LIFNR
FROM LFAl
WHERE LIFNK IN S-LIFNR.
IF SY-SUBRC NE 0. 4
START-OF-SELECTION.
SELECT LIFNR
NAME1
ILAND1
ORTO 1
ANRED INTO TABLE IT-LFAl
FROM LFAl
4
* END-OF-SELECTION. *
* * C * * * * * : g : l : * * * * : k * * * * * : k * * * * * Y * * * * * : f : : i : : k * * ; I : *,; i : * ,4 ; ; k * * * * * : k * * * * * : ) * * * * * * * * * *
END-OF-SELECTION.
* TOP-OF-PAGE *
::*$:A*$::#************** **********************4:*Q+****;#*****
TOP-OF-PAGE.
FORMAT COLOR 3.
WRITE : 13 'VENDOR FA1 TABLE '.
FORMAT COLOR OFF.
ULINE.
E1,52'COUNTRY',62 'CITY', 95 'TITLE'
AT LINE-SELECTION.
CASE SY-LSIND.
WHEN 1.
::' DISPLAY PUR.DOC.NO I N 1ST SECONDRY LIST
SELECT LIFNR "VENDOR
EBELN "PUR.DOC
BSTYP "DOC.TYPE
EKORG "PUR.DOC
INTO TABLE IT-EKKO
FROM EKKO
WHERE LIFNR = WA-LFAI-LIFIVR.
IF NOT IT-EI<I<O IS INITIAL.
= %'A EKKO-EBELN.
LREADY HIDDEN AT PREVIOUS LIST
0 IS INITIAL.
LOOP ATIT -EKPO WTO WA-EIWO.
AT FIRST. a
FORMAT COLOR 5.
WRITE : I3 'ITEM NO OF PURCHASE DOCUMENT FROM EKPO
TABLE'.
FORMAT COLOR OFF.
ULINE.
WKITE : 13 'PU.DOC.NO1,15 'ITEIVI.I\J0',25'MATEKIAL.NO1,
45 'QUANTITY', 65 'NET.PRICE1.
ULINE.
Page 39 of 74 By Ganapati Adimulam
eMax Technologies,Ameerpet,Hyderabad
Ph No :-t9140 -65976727, Cell No : 99484 44808,98490 34399, w~vw~.emaxtech.com
Reports
We Never Compromise 111 Quality, Would You?
ENDAl .
WRITE : 13 WA-EKPO-EBELN,
15 WAEKPO-EBELP,
25 WA EKPO-MATNR,
45 WA-EKPO-MENGE LEFT-JUSTIFIED,
65 WA-EKPO-NETPR LEFI -JUSTIFIED.
*HIDE THE MATERIAL NUMBER, TO QUERRY THE MORE ABOUT
MATERIALS
HIDE :WA EKPO-MATNR.
CLEAR : wA-EKPO.
ENDLOOP. a
ELSE.
WMTE : 13 'NO RECORD(S) FOUIVD FOR THE SELECTED RECORD'.
ENDIF.
WHEN 3.
* DISPLAY MATERIALS DETAILS IN 3RD SECONDRY LIST
SELECT MATNR
MAKTX
INTO TABLE IT MAK
FROM MAKT
WHERE MATNR = 0-MATNR AND
SPRAS = SY-LA
IF NOT IT-MAKT IS
LOOP AT IT-MAKT I
PTION DETAILS'.
.NOt,15 'MAT.DESCt.
ENDAT.
WRITE : 13 WA MAKT-MATNR,
15 WA MAKT-MAKTX.
CLEAR W A ~ M A K T .
ENDLOOP.
ELSE.
WRITE : I3 'NO RECORD FOUIVD FOR THE SELECTED RECORD'.
,ENDIF.
ENDCASE.
.L1
~......
PIJRCHASE OOCIIPIE1~IT NIJFIBEF: D E T A I L S FROi-l EKKO r_/
3
I T E M NO OF PURCH4SE DOCUMAENT FROM EKPO T4BLE - -I
MQI E R I A L I J O 6 D E S C R I P T I O N D E T A I L S
-
Note : When the User is Interested with Selected Field Details, i.e when the
User Interactio~ldepends on the Selected Field Name and Field Value , Both
the above techniques : SY-LISEL and HIDE are not enough because they Can
return only the Contents but the Selected Field Names. So in this Case it is
Mandatory to go for GET CURSOR Technique, Which gives both Selected
Field Name and Value.
I
: Program Heading
: :g *: ,:::: :g $ :;: :$ y $
:, * :2 y ,:: $ :!: :+ * * * * :k * ,:: ,::* * 1: * :: * *: * :k * *: :!:*
:$ $: y *: 9: y * *: :I: :!: ,:: * %: * ,::<: * *:
$ :$ >> :$ y $:
4:~iy~\1-101? : GANAPATI.AD1MGLAM
*PROGRAM : ZDEMO-fiTTERhCTIVE-GET-CURSOR
*'COPIED FROM : NA
*:PURPOSE? : DiSPI.,AY THE COMPANY DETAI[.,S ON R4SIC: LIST
AND CUSTOMER DETAILS AND Reconciliation
::
Account
: IS DEVELCIPED USING GET CURSOR TECHNIQUE
'"Rf31:1-3RENCI:::, DOCS : 1)1113V\VRO065
,::$< :: : ,:: *: :f * 9 *: :k $ 3,: *: :k :g $: ,::;i: * * 4: ::::g $ *: :$ * * <: :$ :k $: *: ;f y $ $: :f :f 3,: <: ;.I- $: 2: *: :$ * $: $: :$ :g ,::::: :I: :g 1: ,:::g y :;: 4: :;:
~>YlODIFICiZTION LO<; :
:3~IOD-000 1 : DETAILS ABOUT THE FIRST CHANGE IN THE PPROG
"MMOII-002 : DE'I'AI1,S A13OG'I' TI-IF'2ND CI--lAh'C;I3IN 'TI-11: PKC)G
' ! ' ~ ' [ < i ~ ~ ~ \ J SRF.:().NO l ' ( ~ ) R ~ : C 1 1 DEV] 2354
:; $< ;: :;: :;: 2: $; :i: :;: * :! :: 2: :;: :; * :$ : * $: ;k +; 4: 4: >: $; ,::;k :g >: >',.. ,::;g ;t
;!< , >",.,
,. ,..' 'h., <. ,*.."
." 4. q, 'I,
'1, ,,, .<.
,;..,. 9,,.,* ',.
.!. " ."."
," . ,*.
-.'.,.'.. .",,. .' <. .",."
,;.
.4,'"" ">:. ,,..,
,. .,~
'9' .), 8' . "' 7',
REPORT ZDEMO-INTERACTIVE-GET-CUSR
TYPES : BEGTN OF TY T001,
BUKRS TYPE BUKRS, "COMPANY CODE
BUTXT TYPE BUTXT, "NAME OF THE CO
ORTO 1 TYPE ORTO 1, "CITY
LAND1 TYPE LAND1 , "COUNTRY KEY
WAERS TYPE WAERS, "CURREIVCY KEY
END OF TY-TO0 1.
START-OF-SELECTION.
SELECT BUKRS "COMPANY CODE
BUTXT "NAME OF THE COMPANY
ORTOl "CITY
LAND1 "COUhTTRY KEY
WAERS "CURRENCY KEY
INTO TABLE IT-TO01
FROM TOOl
WHERE BUKRS IN SBUKRS.
".
.I..* "....-;. ".". ~ + i .", ." ". ." - + ?.
* -2-. > . ", . + , " -,.
~.'.
- ..i,--a
!. -- .'- END-OF-SELECTION, . -4 :$ '-"+
+ . "" ';'-';I A
.I .!,
T1- .L <. .!.
.'.
-E. -?,I-
.b .b A, -47.
T1- + I. .
.b .t. .#-
1. T .
. .L -!- b ".
1-
END-OF-SELECTION.
AT LINE-SELECT10
-.
Cotnpany Code DO01 tu 90001 5".
TF.,+ C i :y
- " ,.
>.'<?
,,
,,, ,.- W-? 1 d n r f
~LIE; I,>[ Fr inl<f:irt
'">,,pr,
l,,lIiPRO i';.rhr-r? " a i r -
~:,.>: I.%:-; ,fit.;; <.,L,.;
e,<\< /
T D E
in.<.- L- , L?t~.~,:31
i D E S Fr-anco
E s - c e 1 cna
1.1 I Ini-,a
R u i:i.rr n:~tn
3i11213 ICIE'Z IJC I I K h b w 't fi? t~
4 0 12'3 I D E S r;sn;,dsi To:.unrs
<?,,Q> ibnodi or, Co::,pa!?y Tnrar~to
(:>I.Jl:>.:! 1,l:t:'; .!5;33n i'o;.yo
If you double click on the company code a secondary list is displayed which
displays the company code, customer
:./
number, Reconciliation Account.
.> .. -
.-,l.!L;rl
30EU
301313
.3hClli
3DUIJ
31~~i!~
snoo
.313i l
:nue
'3000
.3llCIU
SU@O
If 110 further selected details of the company code are present then this screen is
displayed.
Dety,.:; (,>j-j ~ p ~ ; j . :O
:r>e.pi.ac~jy+ ~ rf ir(2E'';T
~ CUR.E<;'R
tg
--.-. -
--
-?-
-, ..-- .....-.- "..,- ",-.w--.
*:AUTHOR : GANAPATI.ADTMIJ1,AM
;':PROC;RAM ZDEMO-GET-CURSOR-CO~IPLEX
'?COPIED FROM : NA
':PURPOSE : DISP1,AY TI-JE VEKDOR DI~I'AIJ,SON BASIC 1.1S'17
.k
AhrD PURCHASING HEADER DEI AI1,S FOR '[TIE
SELECTED VENDOR IN THE NEXT SECOYDARY
LISTx'
.k
AN11 DISPLAY THG PURCHASlNG ITEMS I'OK '1-1-1 E
SLECTED PURCHASE DOC. J N NEXT LIST AND
:$
DISPLAY THE h4ATERIAL DETAILS FOR THE
SELECTED MATERIAL IN NEXT LIST.
* : 1S l>f'VI'I.OPED USIKG GET CURSOR I 1 XI IT\'IQ1113
'"KEFEREhCE DOCS : DEV\NR0065
l l l ~ l ~ l ~ B l ~ ~ l l l l l l l l l l l H B l l l H l ~ l H l l l l l ~ l l l ~ l ~ l l ~ l l l ~ B l ~ H ~ B l ~ B m B
--
MESSAGE E000. "NOT VALID VENDOR(S).
ENDIF.
*****<:*<:<:*****:*+
START-OF-SELECTION ***$*$*$:**:*:::**:******
START-OF-SELECTION.
SELECT LIFNR
NAME1
LAND1
ORTO 1
ANRED INTO TABLE IT-LFAl
FROM LFAl
WHERE LIFNR IN S-LIFNR.
* * * **:I: * :* * * * * 4 * END-OF-SELECTION :k * :::
$: $ 3',
."
+ . .9.' r - 5i' : + L+ . F9. & , > . + + . ;L, *' C. +9.' . . .".'. .".,..*
", .!.
9.'
END-OF-SELECTION.
*DISPLAY VENDOR DETAILS BASIC LI
LOOP AT IT-LFA1 INTO WA'LFAl.
WRITE : I3 WA-LFA1-LIFNR,
15 WA LFA1-NAME1,
WAILFA
52 I -LANDI ,
62 WA-LFA 1-0RTO 1,
95 WA-LFA 1-ANRED.
CLEAR : TVA-LFA 1.
ENDLOOP.
$***:**:)*******:k***# TOP-OF-PAGE **+~***:$:>*****:k**
TOP-OF-PAGE.
FORMAT COLOR 3.
WRITE : 13 'VENDOR DETAILS FROM LFAl TABLE '.
WHEN 1.
GET CURSOR FIELD V FNAM VALUE V FVAL LIFNR.
* CONVERTS FROM EXTERNAL TO INTERNAL FORMAT
CALL FUNCTION 'CONVERSION EXIT ALPHA INPUT'
EXPORTING
INPUT = V-FVAL-LIFNR
IMPORTING Which Converts Extesnal(Disp1ay)
OUTPUT = V-FVAL-LIFNR. Format to Internal(Database Format).
IF V-FNAM = 'WA-LFA1 -LIFNR1.
'k DISPLAY PUR.DOC.NO IN 1ST SECONDRY LIST
WI-IEN 2.
CLEAR V-FNAM.
GET CURSOR FIEL;D V-FNAM VALUE V-FVAL-EBELN.
IF V FNAM = 'WA EKKO-EBELN'.
:!: CONVERTSFROM EXTERNAL TO INTERNAL FORMAT
CALL FUNCTION
EXPORTING
IhTPUT = V-FVAL-EPELN
INIPORTING
OUTPUT = V FVAL EBELN.
* DISPLAY LINE I T E M ~ N ~ S E C O N D R Y
SELECT EBELlV '\
FROM EICPO
WHERE EBELN = V FVAL EBELN.
IF NOT IT-EKPO IS INITIAL:
LOOP AT IT-EKPO INTO WA-EKPO.
, AT FIRST.
FORMAT COLOR 5 .
WRITE : 13 'ITEM NO OF PURCHASE DOCUMENT FROM EKPO
TABLE'.
FORMAT COLOR OFF.'
ULINE.
WRITE : I3 'PU.DOC.NO', 15 'ITEM.NOf,25'MATERIAL.NOV,
45 'QUANTITY', 65 'NET.PRICE1.
ULINE.
ENDAT.
WRITE : 13 WA EKPO-EBELN,
15 WA-EKPO-EBELP,
25 WA-EKPO-MATNR,
45 WA EKPO-MENGE LEFT-JUSTIFIED,
65 WA-EKPO-~TETPRLEFT-JUSTIFIED.
CLEAR : W ~ E K P O .
ENDLOOP.
ELSE.
WRITE : 13 'NO RECORD(S) FOUND FOR THE SELECTED RECORD'.
ENDIF.
ENDIF. n ~ ~ - ~ ~ c ~ ~ - ~ ~ ~ ~ f l
WHEN 3.
WISPLAY MATERIALS DETAILS IN 3RD SECONDRY LIST
CLEAR V-FNAM.
GET CURSOR FIELD V-FIVAM VALUE V-FVAL-MATNR.
IF V FNAM = 'WA-EKPO-MATNR'.
* CONVERTS FROM EXTERNAL TO INTERNAL FORMAT
CALL FUNCTION 'CONVERSION-EXIT-ALPHA-INPUT'
EXPORTING
INPUT = V-FVAL-MATNR
IMPORTING Which Collverts External(Disp1ay)
OUTPUT = V-
' SELECT MAThTR
MAKTX
INTO TABLE IT-MAKT
FROM MAKT a
WRITE : 13 WAMAKT-MATNR,
15 WA MAKT-MAKTX.
CLEAR WA~MAKT.
ENDLOOP.
ELSE.
WRITE : 13 'NO RECORD ~ O U I V D
FOR THE SELECTED RECORD'.
ENDIF.
ENDIF . "WA-EKPO-MATNR
ENDCASE.
B
- - ..-- .
- - - -- - - -.. - -- - --
A
Ican 45gwocrn8 F
,!ZOO 45130!3:2835 F
i '13:3 4:30033!3~,~. K
113GO 4?;00013;300< K
'I 000 4fig0000~02 E
10013 :4EOOflC0003 K
1no0 4600000022 K
1G00 45U0094365 F
qnoo ~JXI~UU!IR~~ F
'I :on 451j000513s F
,ICGCI 450@!105140 F
,I 000 4500005354 F
100U 458000585'; F
.I:l7',-1;i,,- ~~,Jo~c,z,--:.:
Lr.to,+ i
1O 0 l j 453CI0k5126 F
6
Page 55 of 74 By Ganapati Adimulam
eMax Technologies,Ameerpet,Hyderabad
Ph N o :+9140 -65976727, Cell N o : 99484 44808,98490 34399, www.emaxtecln.com
Reports
We Never Compromise In Quality, Would You?
a Y
... ...
;-J
.ITEM NO OF 'PURCHASE DGCllMENT FROM EKPO TABLE , ..
:-,
. M A T E R I 4 L NO 8 D E S C R I P T I O N U E T P L S
NOTE: Adding the Custom Function keys to the Output list is always through the
Custom GUI Status and the Same has t'o be Created foi. the Pi-ogram and attached
to the required Output List Of the Program.
NOTE : Each Function Code is Identified Uniquely, and it is Collected into System
Variable SY-UCOMM automatically, Each time the User Interacts with the
Function Key.
Flow Of AT USER-COMMAND :
AT USER-COMMAND.
CASE SY-UCOMM.
' WHEN 'FCODE1'. /'
--
--
WHEN 'FCODE2'
--
ENDCASE.
Example Screen :
......
I.: EI0ol
<
SAP A . G . ~ a1 dot-.T
l DE
I::!<""..! ,
I-
0 111 0
, Ict E S ..I; DE
: ., ,QBO
-.... I D E S UK LorllJutl ;I B
i,...... i 2.1 1110 IDES por-tuyal
i::I,,-,i2 2 0 EI I D E S F I--a n c E! I Pa ,
L i sbon
.3
FT
FR
i . 1 2 3 0 8 ILIES Espar'in Barcelona ES
,,..2. 4 1 3 1 3 IDES I t a l i a
$-.'-
I'l i1 n n 111 I T
-.........1 2 5 11113 I [:I E :S fa) e t h e t-. 7 :3t-I ~:js
i.. ,
Ratter-darn trl L
i . ,. f, 313BB IJS I N K ; I.1 e (v .'; 111 r.b;. 1-1 S
~
.......
Subs, di:st-.v -
... ..... 1301rJ
i
, .
E e l g i urn Kt-uc.stz~~l s BE
i . . ....! 4(3Bl_f I D E E ; C;ar-!ada 1-oronto :
i $8,
,i...............j 4.5 11
1B C: a r-I a d ia r~:I 13rn p a r~ y 7-oronto 11
$1,
1.........
-
j5BQ0 I D E S Japan Tok y i t JP
F kei, S B ~ I T I ~ P
.: .' Function list
Tltle lisl
CREATE.
Shutt text D e m o On - -~
13-. I rr ~ t e t i a c c -
ENTER
Reports
We Never Compromise In Quality, Would You?
. .. . ,. "....--,T,....., ..-"
: A
...,..... .,,.,..,,.7,-. ." ....,-,.-n. ,
CLICK ON Application Toolbar & Enter the Function Code DOWNLOAD, Which
is the Unique Identification for the Punction ~ e ~ .
.t9 x- f
i
- * -
ENTER 6
DIIWWLI:IP,[j
Dos~nLoad
i s n o t ass7 gned t o a f u r l c t i on k e y
Choose a f u t - ~ c t i o nk e y
Ed FF2
r,F5
@ FG
@ F7
r F8
m Stiift-FJ
ra S h i f t - F 5
o Shift-FG
@ Shi f t - F ?
r St-li f t - F C
r Shift-FS
er Shi i t - C t r - , l - fl
@ Shift-F1.1
User I n t e r r a c e ZGDENU-USER-CflMbIHNDI
-
Click On Functio
V ~ O L Ib a r 7
. & a:!,,r, o:, I::-.. :qA-r--,ce
Standard T o o l u a a i /
ehCKl :
8 B 0 Q el Q M ~8 a TI a a m i
Provide the Function Code as BACK For BACK and this function works
automatically.
SAVE,CHECK and ACTIVATE.
Note : Creating the GUI STATUS for the Program is not enough, It has to
be Linked to the Output List v b SET PF-STATUS <Status Name> for the
required Output List.
*&--------------------------------------------------------------------- X
X
*& Report ZGDEMO-USER-COMMAND1
*&
*
"&--------------------------------------------------------------------- *
REPORT ZGDEMO-USER-COMMAND1
*****************************X***Jr*********************************
*** a
x START-OF-SELECTION. *
START-OF-SELECTION.
x END-OF-SELECTION. *
...................................................................
***
END-OF-SELECTION.
I F NOT IT-TO01 I S I N I T I A L .
LOOP AT IT-TO01 I N T O WA-TBO1.
WRITE : /5 V-BOX AS CHECKBOX,
WA-T001-BUKRS,
WA-T0O.l-BUTXT,
WA-~001-0~~01,
WA-TOO1-LANDI.
CLEAR WA-T001.
ENDLOOP.
ENDIF.
* A T USER-COMMAND. ' *
...................................................................
A T USER-COMMAND.
CASE SY-UCOMM.
WHEN 'SALL'. "Select All
V-BOX = ' X ' . "SELECT AND DISPLAY THE RECORDS
LOOP AT IT-TO01 I N T O WA-T001.
WRITE : / 5 V-BOX AS CHECKBOX,
WA-T001-BUKRS,
' WA-T001-BUTXT,
WA-7-001-ORT01,
WA-7-001-LAND1.
6
CLEAR WA-T001.
ENDLOOP.
WHEN 'DALL'. "Deselect All
V-BOX = SPACE. "SELECT AND DISPLAY THE RECORDS
LOOP A T IT-TO01 I N T O WA-T001.
WRITE : /5 V-BOX AS CHECKBOX,
WA-T001-BUKRS,
WA-T001-BUTXT,
WA-T001-ORT01,
REFRESH IT-SELECTED-T001.
DO V-LINES TIMES.
READ L I N E SY-INDEX FIELD VALUE V-BOX
WA-T001-BUKRS
WA-T001-BUTXT
Page 65 of 74 By Ganapati Adimulam
eMax Technologies,Ameerpet,Hyderabad
Ph No :+9140 -65976727, Cell No : 99484 44808,98490 34399, wvvv+7.emaxteclh.com
I
Reports
We Never Compromise In Quality, Would You?
WA-TOO1-ORTO1
WA-T001-LAND1
WA-T001-WAERS.
I F V-BOX = ' X ' .
APPEND WA-TO01 TO IT-SELECTED-T001.
1
ENDIF.
ENDDO.
I F IT-SELECTED-TO01 I S I N I T I A L .
WRITE / ' N O RECORDS Selected t o DownLoad'
ELSE.
WA-TOO1-WAERS.
I F V-BOX = ' X ' .
APPEND WA-TO01 TO IT-SELECTED-T001.
ENDIF.
ENDDO.
I F IT-SELECTED-TO01 I S I N I T I A L .
WRITE / 'NO Company Codes are Selected'.
a
ELSE.
SELECT BUKRS KUNNR ZTERM I N T O TABLE IT-KNB1
FROM KNBl
FOR ALL ENTRIES :CN IT-SELECTED-TO01
WHERE BUKRS = IT-SELECTED-T001-BUKRS.
I F IT-SELECTED-TO01 I S I N I T I A L .
WRITE / ' N O CUSTOMERS FOUND'.
ELSE.
LOOP AT IT-KNB1 I N T O WA-KNB1.
WRITE : / WA-KNB1-BUKRS,WA-KN A-KNB1-ZTERM.
ENDLOOP.
ENDIF.
ENDIF.
ENDCASE.
INPUT SCREEN
..;..
:-J:JI;~? sap 8 . ; . lia: ids;-'
.'".
!?!:
.. 606
,:*.; IacS ,As Frankfort
2[>[iU 10ES I?< cot?en~
:,,j~?1:i'JIOEC' P>i'a:~i3! c: st,:# 8
:jzano 1:)~s F. 2 1 ~ C ~ :'nu 1 5
/Z:([lU I:IC6 E:.i>lih,~ 23rL@lOn.i
: ! 2 i C U i:IES i f 2 i l a ili :a110
,2500 [:>k? ~,?:~,,:1-12!,~s sottc-I(>r
:?.: j t l j h !:JE: jt,,, :lev, Y:,! r
., ..;.,i 3L!G L:ir,u Eui!:.;uii!r: c,: (1, ,.:I,, ~ , % s s ?I L
[. -iocou I:,KC' ~ 3 i l ; ~ ~ : i ~ ror.ci1to
;,I
..... .!EUlj 281186i2!1 C U ~ I C I ~ . , ~ TDi'CtltO
i:.:jGUO
. .. iSE5 J2rldfi roily*
.[d'dO'JB
.
: i;C[iT;
iSE5 l!S7icu, S !I
;[#ES B r a z i l
Cs? C 'I ? I e i l ~ eDF
..:.
r d O P:,LI:L
(7500 ijEC P,ig~r.tl.ill 8UC.1;03 i r 2;
i,,i --
7600 15E5 C S l 1 1 6 b l a ;,
20; ,!>3,5<'1
-..:
, I I , U U I S E C V?nerr!ela
;..
'/e,:P?.l,?? .'
; ! , 6UU iDES P ? r u Peri;
IBLOQ 1jEC i':,??i. ~;lillP
. .
//
! I
j
1 1
j
! I
/
u. / I -..jmaDo~q5
,; , '
I 1..JSAPnrt ORACLE IKEKNEL ~ i lF
e Q I ~ ~ 1!5!2013 2 : O i Pfil C i
I + .> Apel,cu,.. Flld Fddel l!20!2013 I I . 3 i Af,l i
:.) Cooker <, ,-ivrmpub 6 File Folder 1
i
tt ;
lFavorites i '
:*: -:j Loo1 scttmgr f1 _
London
i N e w York
! Toronto
IES Japan Tokyo
!ES M e x i c o , 5 . + . . rlc <.\I. M e x i c c DF
- ., 8 e n . !!
*.JFri ..),6 v l i I; . .
i
IT
.. . ...,
ll
7 -.'
: DOWNLOAD
; ... D :;' @'*I
2 : s PM
Di
DE
bS
?:
i R
cn
:a
/,/
!ill
.>..
.,r.
;, i
C?.
11,
. ... 9R
: C C S !:rE: '4-nl.1 LI:,;, :<,i,.w " ri.> 1R
! ? ? C C !:>E:
. ,,&,, , . l:,E:. ?~ilc:,:l:', ;, c . , ~ , -,I,,l a::, ;,:
~,>?,,22,.:&<,:, ';I',:eL:,,.. :YE
i ,,j?BOC !:,E:. Fe;-l; ?.:r,.i .
7 <
L
; ~ C C O UI>€$ C m i ~ illlle .:i
SR? s! Z
i i 8 r C R::
i t 5 Ui:
DeSrlerti;'l
C) Check for the Functionality Of DALL(Dese1ect All)
From the Current Output Screen
;4:>13;
:><?,>><a 2 0 vf<>j-j< '*~ )$
:,;f't:. t.; < > j g ~ & 4 < f ~ j , j
@jDo-r.11L0ad Selectil!
.......- ...* ................. .............. ........"
< "
'm ' .~ .i ?. ~. .r l. e. c. t .'i l l
.......... ......... .............
" "
Dlsplsi.Cuslorners
...........,.. "."..........,*.....*...-"......"......
ifigco s . 3 , ~ p, 3 I~eselect[S~IR+FI)\
:+:.coo 1 x 5 ;.!r F,YFL?~,!.?
;+;:COL~ ~ D C SUi: inrdun
y j 2 l O C 13FS P.irtl:?al I iFI?~:~?
:+::;Or, I>ES Franr.i. Pii'ix
!4j?;UC I j E S EbndEe Sur'r'ul un-
i":2.:OC IiE? It:,: !,: ?liidrl>
i"l2EGi ISEC I ~ l i ; l , ~ r l a n d s Roti~^rJ:~r
jji.i(.CCi ISEF 115 1I.C :leh YSl"i
i<i311,> .I <.,'
& > U r ,d , a ? y . g" i,? il", Brii6csl:
jf, ~ L U Cli!iS i:a~aca ii)rol#i~~
/ p j J5I:II' C ~ l i i O i ~ Cl:m3iln.
!? i .
7 vi-o,ii'l
:wj7i.j?~? ::x,; J~&>zr 101 : i t
:d;src,? I:IE!; I~A~.,.,.. ,: > ,I> i ,'; I.I~:,.~,-~,rnr
4, pcri [ ? f 3 E;:-7:.1 ..
.,A,',
.< Fh:,.,:
:<;?:.GI? j3E; )8,:..;c~r.t.,:,., Q,.,<~.C!?.
.
,\; 8.e:~
'V :FUI; i:iCb Lo1 ~ i i l l l l :. ,j
~
, #.:;,,:>I :,
;.; i j i 5 :!s)~u:,:c.;:, 483iCZ.1C'i.
r<,.'$cc igc:; !!2!.,! !',?rl.'i
j<:::COi. i ?T.: r,m i c i.I,?le
D) Display the List of Customers From all the Selected Company Codes.
(:~~storners
Cl~s[:~l?e
Select the Reauired C o m ~ a n vCodes and Click On
......
l 2 4 0 U I3EZ ii.il 1 . 1 :.I.,:zn.:,
:i
2500 13E5 Herllei.1 ?it:, R,:,T.~+~?<Iz~.
<<;3rDTJ LlS i l . C
1:rE::
.....i3CIL1 E l r , ;
kJeT; '.'.,,..
51US'!tic;:'i - ZeilliLI'> 3 r c . i C e l C
> ....
,
i 4Gi;rJ I j E ? C.irt:#oB Tz!'co!.o
: ; C ~ * . > C ! ,>I,, C 0 , , , 3 ~ ? , % ! 70,C i l L "
i.d...i S C l C IDES l a v h r TM;d
~ C C L ~ 1:IES
O 148.;rc, I; I . I r I: b ila:lc3 iiF
',$,'
:, i 7 C E O I 3 e S C r i ~ i l
PSiliC
: ,J7:.t4cl I!\<: ~-:~vT.,-A :!OFRO; hi lir
:_!7EDO I!)E6 [ : 3 1 ~ l i i : i a a
I:ni~in1:>1
i:?ror. i i m r zv ? t , r ~ ~ . , e i a ' I e l ? e b : l l l .d
' i : .."FC
c , 'F,') i.<:-,; PI., ii
; J;<[:vO [:,EL; :,:.:t 1,: CI,.lC
List Of Customers
Page 72 of 74 BY C a n a ~ a t Adirnularn
i
eMax Technologies,Ameerpet,Hyderabad
Ph No :+9140 -65976727, Cell No : 99484 44808,98490 34399, www.emaxtech.com
Reports
We Never Compromise In Quality, Would You?
b
Exercises
I. Display the list of Monthly Sales orders and the Total Value of the
Sales for each Sales Organization and Under each Company Code
and the Grand Total. (Use Control Break Statements ).
Input : Select-Options for Sales Organization,
Select-Options for Date
(Default Dates : Begin and End Dates of Current month).
11. Display the list of Monthly Purchase orders and the Total Value of
'
the Purchase orders for each Purchasing Organ
each Company Code and the Grand Total. (U
Statements ).
Input : Select-Options for Purchasing Org
Select-Options for Date
(Default Dates : Begin and End Dates of C
VI. Create interacti rt.to list all the sales that took place during the
month for par aterial.
XII. Create an interactive report that list out all the materials for a given
plant. Secondary list contains vendor details who supplies the chosen
material.
XIII. Create a report to get list of Sales orders created only On Saturdays
and Sundays during the particular period.
a. Introduction
b. INCLUDE
--
Programs
c. MACROS
d. Subroutines
e. Function Modules
Modularization Techniques
We ever Compromise in Quality, N w l U a &
DAY-1
L
Statement A. statement A.
Statement B. Call Module M.
(Statement C. Stateinent E.
Statement D.
Statement E.
Statement B.
Statement C.
-
-- MODULE M.
Statement B.
Statement C.
stAtement D.
Call Module M.
Statement F.
Call Module M.
Statement G.
Statement D. - ENDMODULE.
Statement F.
Statement B.
Statement C.
Statement D.
Statement G.
Modularization Techniques : *
If you create an include program you must assign it the Program type I in its
prograin attributes. You call also create or change an include program by double-clicking
on the name of the program after the INCLUDE statement in your ABAP program. If the
program exists, the ABAP Workbench navigates to it. If it does not exist, the system
creates it for you.
Ail include program cannot run independently, but Can be Included into other programs.
Include programs can contain other includes.
Note : For the syntax check to produce valid results, you must check the program in
which the include occurs.
tising 11nciudePrograms
The INCLUDE statement has the same effect as copying the source code of the include
program <incl> into the program. The INCLUDE statement must be the only statement
on a line and cannot extend over several lines.
"& R e p o r t ZCDEMO-INCLUDES
"&
REPORT ZGDEMO-INCLUDES
I N C L U D E ZGDEMO-TOP.
EXECUTE
Function modules are for global modularization, that is, they are always called
from a different program. Function modules contain functions that are used by
many different programs.
Notes:
Function groups are contained for function modules. You cannot execute
a function group. When you call a function module, the system loads the
whole of its function Modules into the internal session of the calling
program So that it is Better to group Only the related Function Modules.
When the function group is Created, The main program and include
programs are generated automatically.
The main program SAPL<fgrp> contains nothing but the INCLUDE statements for the
following include programs:
Function Group
FM2
MAIN Program +
INCLUDE Programs
Note: All of (Only) the fuilction modules in a function group call access the global data
of the group. For this reason, you should place all function modules that use the same
data in a single function group. Example, if you have a set of filnction modules that all
use the same internal table. you could place thein in a function group containing the table
definition iln its global data.
2. Choose Suve.
3. Activate the Function Group.
Note: Except in 4.7EE, Function Group Activation is Not Default. Instead it has
to be activated explicitly using the below Procedure.
To Activate it , Open the Function Group in SE80 so that we can check all the MAIN
and INCLUDE Programs and then Activate it.
Execute SE80 and Enter the Function Group Name ZDEMO and it Displays all the
Programs Included .
;;::gj :
. .
:
'
t r t t r * t * t r * t * * * t , a i t r t t ~ , k t ~ r , t t t * , i r t ~ t . . * ? ~ ~ , . t t * ~ ~ * r t t t r i . ~ . ~ ~ ~ ~ ~ : ~
;, ~ ? b ~ ename
ct .Descrlptlon i InCLlJDE LZDEVIOTOP " 61ubal Data .
:
:
.
:
:: - ~~:',fi,) Funltion Oro If,lCLUDE LZDE1,ITJLI;): " F u n ~ t i o nl l o t l u l e s j
j .. ..
'7 . IlicIl~lJes
/ ~ t i~
.. .
~ . ~ + . ~ t * ~ t ~ + + t * t t r * t t ~ * * * t t n : * t ~ t t t ~ t t t , t , t , . ~ ~ ~ . ~ + ~ r * * , ~ i t t ~ . ~ . ~ ~ ~ . ~ :
,
-
:
U@EUOTCIP ,
.....-....*.... * . ...,... ........
.. ..
Eh{OIJ::>;
l l s e r - d e i i ~ r e ~ :i Ir r c l u d e - ? i l es ( 1 7 n e i p s':..dl
.-..... .-..... - . ...
-- y )
; * . *, .- ..
;- i
:
.
.
..
:
The name of [he main prograin is assigned by the system. This is made up of the prefix
SAPL followed by the function group name. For example, the inail1 program for f~~nction
oroup ZDEMO is called SAPLZDEMO.
b
The names of the include files begin with L followed by the name of the function group,
and conclude with UXX ( or TOP for the TOP include). The TOP include contains
global duta declarations that are used by all of the function modules in the function
group. The other include file within the maill program is used to hold the function
modules within the group.
To Activate the Function Group , Select the Function Group, Right Click, Activate it.
ri'::/'-pi ; z d j ~zjp.rdg,13y
~~; 3cic33tpor,j
.6,.Z% q...71
I. '
/&d. . E+:<; '
% 'i,.
'-'n8>r.
--
+ : *g &: a <a - a+ : hP* & rn ljg :@ .><,!. .;..z Pre~,Plll-ltel
.-. .
.................................... - .................................................. ..... .... :..-..,
i SAPLZDEMO Irtach.
runction group P Functionpool ;.@ ..:
i ;ZDEta!IC ..
Ti.&:
,>
. - 5
.
. . . . . . . . .!
;
rFp-p.p-.-..
*j.. J 1
..........
i-.-i
:
:
. .......
.
2
-
.
J
,
>
..
................
.jQ;
....................
.- !
?:
I j
i.
. . .
. : +.$...A;i..&,..D
: :,, -."';+
. . .% % . . . ~ . ~ ~ 3 . . *. j. . ,
j 2
i ......
.1
: 7 ,,
?
k J;;&
; ,*...*..
i , Syjteiii-def~ned Inilircle-f
....:...........:. . . . . . . . . . . . . . . . . . . . . . . . . . . .*. . . . . . . . . . . . . . . . . . . . . .'
,
L * . . " ~ . . ~ , . ~ . , % * ~
I les.
~ . S ~ < ~ ~ ~ , , . ~ , Z , . *. . *% ~
* S ~~ ~~ . ~* * ~X *~ . .. t . 2. .
. .1
i
i Ol~jc?ctnarne
i 7.: .<n~b,l,>
' 1 1 NCLUDE LZDE,,IOTOP,
DehcrilltiOn " Global Dats
" F ~ ~ r l c t i l j tn. l i l J u 1 e ~ j !
I .. ,
.* :L lnrluqc Create ? & . * ..*...=, a*..., % ", ....
j
.
i
LZGCtv
LZDEIv
change
-
Disula),
....U~:r;:el:oed, In~:;~::f: 1::% $1f .K:,B::.? *, , *. , % . .., ,, , *,
;
;
:
" Sr~bDr0Ur3sS
i Chack " PFO-MoJul us .. .j.
j . .- ' P A 1 - Mndul s s
.. ::/:
:
j
. :!:
. .
:
j s
?
:
!
:
j
:. . !
. .::
trlora iunctlons .. ..
:%8 -!
..,t
. . . . . . . .. - ...... ....,-.!..
i A j
i . . . . . . ...........
....... ....
-, . . . . . -, . ........... ,
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ! I ? 9 ! n ~.?...rrf.?..?..lin*- .....
1 r-.-- r
..................................................................... .. .. .................. ..- ................. . -................ ................ - -...................... ..... ._.__:
..................... i j-ii
-, .......- .
T r a t i s j ~ o r t a t ~ iobjects
e Local objects
Documentation
The documentation describes the purpose of the function module, lists the
parameters for passing data to and from the module, and the exceptions. It tells
you how you can pass data to and from the function module, and which errors it
haiidles.
Import(1NPUT) parameters. These must be supplied with data when you call
the function module, unless they are flagged as optional. You cannot change
them in the function module.
Export(0'LTTPUT) parameters. These pass data from the function module back
to the calliilg program. Export parailleters a r e always optional. You do not have
to receive them in your program.
Changing parameters. These must be supplied with data when you call the
function module, unless they are flagged as optional. They can be changed in the
function module. The changed values are then returned to the calling program.
Tables parameters. You use these to pass internal tables. They are treated like
CHANGING parameters. However, you can also pass internal tables with other
parameters if you specify the paraineter type appropriately.
Note 1 : You call specify the types of the interface parameters, either by
refersing to ABAP Dictionary types or elementary ABAP types. When
you call a function module, you must ensure that the actual parameter
and the interface parameters a r e compatible.
Note 3 : Exceptions are used to handle enors that occur in function modules.
The calling program checks whether any errors have occui-sed and then takes
4
action accordingly.
1. Check whether a suitable function module already exists. If not, proceed to step 2.
2. Create a function group, if no appropriate group exists yet.
3. Create the function module.
4. Define the f~lnctionillodule interface by entering its parameters and exceptions.
5. Write the actual ABAP code for the function module, adding any relevant global
data to the TOP include.
6. Activate the module.
7. Test the module.
8. Document the module and its paranleters for other users.
9. Release the module for general use.
Requirement:
Create a Function Module to read the Line Items for the given Purchase Order.
Output : An Internal table with all the Line Item Details(1tem No, Material IVo,
Quantity and Net Price) for the given Purchase Order.
1) Execute SE37.
3) Choose Create.
Enter the Functioil Group Name, which we already Created and short text.
Choose SAVE.
Parameter Interface :
4
Since function modules can be used anywhere in the system, their interfaces can
only contain references to data types that are declared system wide. These are the
elementary ABAP data types, the systemwide generic types, such as ANY TABLE, and
types defined in the ABAP Dictionary. You cannot use LIKE to refer to data types
declared in the main program.
Httrrhutr: Irnflnrl ' E~pnrl . Zh?nglng , Tahles ' EIctlpt~ons Coclrce code
To pass data back to the calling program, the function module needs an EXPORT
parameter as an internal table type. For this, we define a system wide Table type
ZTT EKPO with tlie line type ZEKPO in the ABAP Dictionary.
tat:^ l p c,
Note: Iiitesnal Tables Cali be passed througl~TABLES Also. But it is not
secon~iileiidedIn Object Oriented Scenarios.
EXECUTE S E l l
ENTER NAME FOR DATATYPE
CREATE.
-
$ $ . 4 & Hieraicily Ofsplay
--
Data Type
Lengtll 0 Declmal Places 0
E:.:l:eptions
Click On Exceptioi~s
The source code of the function module occurs between the FUNCTION and
ENDFUNCTION statements. The definitions of the parameter interface and the
exceptions is displayed here in comment lines.
FUNCTION ZREAD-PO-ITEMS-INTO-TABLE.
,. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-3. II
- - -----
.-.
- - Local i n t e r f a c e :
II 1
.. 11
II
J
.
,* 1MPORT:CNG
II
1
..
"" EXPORTING
il
REFERENCE(1T-ITEMS) TYPE ZIT-EKPO
-1.
1
..
n -__________________------------------------------_-------------
II
SELECT "
IlVTO T A B L E IT-ITEIVIS
FROM EKPO a
WHERE EBELN = IM-EBELN.
I F SY-SUBRC o 0.
MESSAGE E007(ZDEMO) R A I S I N G NOT-FOUND.
EIVDIF.
ENDFWNCTION.
Raising Exceptions
There are two ABAP statements for raising exceptions. They can only be used in
function modules:
The effect of these statements depends on whether the calling progranl handles the
exception or not. If the name <except> of the exception or OTHERS occurs in the I
EXCEPTIONS addition of the CALL FUNCTION statement, the exception is handled by
the calling program.
The RAISE statement terminates the program and switches to debugging mode.
The MESSAGE ..... RAISING statement display the specified message. How the
processing continues depends on the message type.
the global data of the main program. This data is defined in the include program
L<fgrp>TOP. To open this include, choose Goto -> Global data.
We should use the test cnvironinent in the Function Builder to test new function modules
before releasing them for general use.
Execute SE3 7 and Provide tlze Function"odu1e name and click 0 1 1 !@I
;-.-......(H).
NOTE: Fill Values for the relevant import, changing, aiid tables parameters. To fill in
single-field parameters, enter the value in the displayed field. To fill in table/ structure
parameters, double-click on the parameter name.
a DeUUnnirlg C?$,
",.,
T e s t data d ~ r e c t o v
." .... .. -..... ..........."..... - - ........ -"
" ,~,m-.,,,,, ~ " "
.: - . .
T , , :.! i:,; ;.::,. .> > ,;,: ,;? ..,:,:, zr,~~:,?
-- .,- . .,
Fli ,. . : :!: t ~ . ~ : ! l ' ; , , . L . - : E ? . L J , , P ~ ,: T E l ! S , ? ~ ~ l ~ ~ ~ l , . T . ~ . ~ ~ ~ .., -
lLO,>< ir,.,,,;,:, .:,.\.
'
Choose Execute.
L Impnrt p a r a m e t e r s \la1 ue
111-EBELlI , 3000000004
I
Execution Results :
eMaxTechnologies,Ameerpet,Hydera bad
Ph N o :+9140 -65976727, Cell No : 99484 44808,98490 34399, w~wl.ernaxtech.com
Modularization Techniques
We Never Compromise in Quality, Would You?
IT-ITEM 2 Entries
-.
Euntime: -? , Microseconds
:..b . ,I.
!
I
:
: #
j
.. .
,-
e,3 ..Debugging
-- ,,-*,c7" .........
Test data dlreclory
................ ...,..7.--.r ..... .-................. ...... - "" .-
Execute it.
Page 20 of 44 By Ganapati Adimulam
eMaxTechnologies,Ameerpet,Hyderabad
Ph No :+9140 -65976727, Cell No : 99484 44808,98490 34399, w~w.emaxtech.corn
Modularization Techniques
We Never Compromise in Quality, Would You?
. .
i b. 3.., 'fr\r y.::~i:+.
I
j (jfi sr':,;J;, -.
7LIEfiO :A;
/
Fur~tinie E Y 7 l i croseconds I I j j
E x i r p t i uri i$OT-FOUM[!
Since No Records found for
K e>-,dge
----- ID: ZDEf?il the given PO Number, it
I'essage : bic Recart?:: F?und FOI ?fie h v e n S e l e c t i u n
raises the execption
Import p a r a m e t e r s Value : .
-- -- - -
It1-EE;ELl*l 51:113l:111CIQB14 .
:
.
:
--A
: j
---
Eypurt ~ ~ a r a o e t e r ? \is1ue
-~ --
I T - I TEllS @ 0 E r i t r i es
-
EXPORTING
, fi = a1
...
Fn = an
IMPORTING
fi = at
....
f;; = a;
[CHANGING fl = a1.... f,, = a,]
[TABLES fi = a1.... f,, = a,,]
[EXCEPTIONS el = rl .... e,, = r,,
[ERROR-MESSAGE = r ~ ]
[OTHERS = r,]
Position the cursor at the point in your coding where you want to call the function.
1. Choose Pattern. 4
1
I
- -- - - -. - - - - - A - - - ---- - . - - . - - - -
I*
- - - -- -
L13.Co1
- - . -- -- -- - - --
-- -
-.-- -- - - --
-
Ln 1 - L n 3 o f 3 l l n e s
1
@ Anrlbutes for ~ ~ r o n r aZDEIdO-C4LL-FUEdCTIOl\l-1~lODULE
rn sped
>" - - --
C l l (13 !;uO)
-3 -- -+--.
Qaanppatl IbIS
-
,'
.
-
i start1 L_i 3 73 SYPRIP,IC ] 42 I'~CIOC 3 SAP L .. . *
- ~d
ur,~,t~
I :r,,B@
(7 riC"j' 7 56 PM
2. In the dialog box that appears, mark the selection field in front of CALL
FUNCTION.
3. Znter the name of the function module in the input field.
SELECT- FROM
WRITE
CASE WI status
Structured data object
I ,r,!ttt Tielac 1turn b?IuCtUla
I
3 2%
6
: (1) Cd120) -
+-
"
ganapatl lids
"
-
/'
J 5 4
& -5SAPPII,TC 3 Z 1 l~cros -1 <- 2)2 Mlcros -! 'f unbtled - 1 2 or.
.
.
5 OZ PPl
4. Choose Contintle
The system inserts the function module with the interface into your coding.
The EXPORTING option passes the actual parameter ai to the formal input
par&neter.fi. The formal parameters must be declared as import parameters
in the function module.
The IMPORTING option passes the formal output parameter fi of the function
module to the actual parameter ail The formal parameters must be declared as
export parameters in the function module. The parameters may have any data
type.
The CHANGING option passes the actual parameter ai to the formal parameter fi.
After the function module has been processed, the system returns the (changed)
values of the formal parameters 6 to the actual parameters fi. The formal
parameters must be declared as CHANGING parameters in the fuilction module.
These parameters, too, nzay have ally data type.
The EXCEPTIOIVS option allows you to react to errors in the function module.
Exceptions are provided as special parameters in order to be able to react to
possible error events during processing of the function nlodule. When an
exceptioii occurs, function module processing terminates. Example: If exception
ei is triggered, the system stops p?ocessing the function module and does not pass
any values back to the program. Tlie calling prograni receives the exception ei by
assigning tlie value ri as a return code to the system field SY-SUBRC.
You can the11 evaluate tlie system lield in the calling program.
EX : CASE SY-SUBRC .
WHEN 0.
"SuccessF~l
WHEN 1.
"Exception 1
WHEN 2.
"Exception 2.
WHEN OTHERS.
"Others
ENDCASE. a
REPORT ZDEMO-CALIJ-FUNCTION-MODULE .
CASE S ~ - S U ~ S.C
WHEN 0.
LOOP AT IT-EICPO INTO WA-EKPO.
WRITE : / WA-EKPO-EBELN, "DOC NO
Page 25 of 44 By Ganapati Adimulam
eMaxTechnologies,Ameerpet,Hyderabad
Ph No :+91 40 -65976727, Cell No : 99484 44808,98490 34399, w~~w.ernaxteck.con~
Modularization Techniques
We Never Conipromise in Quality, Would You?
WA EKPO-EBELP, "ITEM NO
WA-EKPO-MATIVR, "MATERIAL NO
WAIEKPO-NETPR.
"QUANTITY
CLEAR WA-EKPO.
ENDLOOP.
WHEN 1.
WRITE I 'NO DATA FOUND'.
ENDCASE.
OUTPUT :
Execute the above Program ZDEMO-CALL-FUNCTION-MODULE.
called from the program in which they a r c defined. You can use subroutines to
write functions that are used repeatedly within a program. You can define
subroutines in any ABAP program.
<INPUTF2> etc
Subroutines are Called
CHANGING <OUTPUTl> Actual Parameters.
<OUTPUT2> etc 1
4
Defining Subroutines
FORM <Name> USING <FP-TNPUTl>
<FP-INPUT2> etc
3 I time
All Arguments Passed at the
of Defining the
Subroutines are Called
CHANGING <FP-OUTPUTl>
Formal Parameters.
<FP-OUTPU~~Z>etc j I
ENDFORM.
The USING and CHANGING additions in the FORM statenlent define thc formal
parameters of a subroutine.
The USING and CHANGING additions in the PERFORM statement define the Actual
parameters of a subroutine.
Within a s,ubroutine, The value of the Formal parameters is the value passed from
the corresponding actual parameter.
fp v-counter = fp-v-counter + 1.
YTOTE: HERE THE CHANGES TO THE FORMAL PARAMETER REFLECTS
':'TO TSE ACTUAL PARcl,WETER V-COUNTER
endfonn. " increment-cou~iter"
OUTPUT :
T11e formal parameter occupies its own memory space. When you call the subroutine, the
value of the actual parameter is passed to the formal parameter. If the value of the formal
parameter changes, this has no effect on the actual parameter.
#: * * :: *
$: *: 2: :k * *: 4: :: :+ 2: 4: * *: 4: :k *
<< *: $ :) :s *: 4; :k * *: 4 * 4 * * 4: :k * <: 4: * *: ;: :k * q: :;: ;$ * q:
$ :$ k,:
*: PROGRAM : :DEMO-SUBROUTINES-CALL-BY-VAL
* AUTHOR : GANAP~\TI. ADIMULAM
* PUKPOSI:' : WRI'I'ING SUJ3ROUTINE USING CAI.,I., 1-3Y \/AI..,L'E
* * *: 2: ;k * *: 4: *: *: 4: ;k 2: q: >k * <: 4: :k ;* *: * :k * *: ;k ;+ 2: :k * 4: 4: ;k * 2: 4: >k 4: 2: ;:* 2: 4: ;:
2: 8: ;! 2: 8: !> :$ :$ $: *: 7%
REPORT ZDEMO-SUBROUTINES-CALL-BY-VAL .
DATA V-COUNTER TYPE I.
&- - -- - -- --- -- --- ----- -- - --- --- - -- -- -- - - -- - -- --- --- ------ --- - - - ----- - - - *
%:
fp-vcoul~ter = fpv-counter + 1.
*NOTE : HERE THE CHANGES TO THE FORMAL PARAMETER DOESN'T
REFLECTS
'"TO THE ACTUAL PARAMETER V-COUNTER AS IT IS CALL BY CAL
endfom. " iiicreme~~t
-counter
OUTPUT :
r,,:<;,,,:,
IH:. C!)IJII
1)-II :>:#l!llTFI;:
~IIL
,<f,r.K.i
~ ~ ! . ) r ~ :~-:LI;
r ~ i i
,\c:
ILI? Al- l t l i
k,,
i l F l Fi<
, v, >- '2, 7 m~!
I l . l l : h t t l t t +l
INCRFIFFIdT
INCI:LIIL~IT
I,:>,
It
TC;
IS
$2,:
u
P
LI See, Here the Changes to
- : r-:{
;:-.i j
1 11
Formal parameters are not
reflected to Actual Parameter as j it
* i ij
the Parameter is Passed By j /i
:
Value :
, 11
; if
You list these parailleters after CHANGING with the VALUE addition:
The forina1 paralneter occupies its own memory space. When you call the subroutine, the
value of the actual parameter is passed to the formal parameter. If the subroutine
concludes successfully, that is, when the ENDFORM statement occurs, or when the
subroutine is terminated through a CHECK or EXIT statement, the current value of the
formal parameter is copied into the actual parameter.
Page 31 of 44 By Ganapati Adimulam
eMaxTechnologies,Ameerpet,Hyderabad
Ph No :+91 40 -65976727, Cell N o : 99484 44808,98490 34399, ~!~~~$;.eanaxteeh.cam
Modularization Techniques
We Never Compromise in Quality, Would You?
text
$:...................................................................... "'
Q
-->P-V COUNTER text
form increment-counter CHANGING VALUE(fp-v-counter) TYPE I.
fp-v-counter = fp-v-counter i- 1.
*'NOTE : 1-1 EKE THE CI--1ANGES'TO TI-IE FORMAL., PARAbII:3r1'IIIK DOESN'T
ICE ~~I.,EC:TS
"'TO THE ACTUAL PrZRilMETER V-COIJNTER AS IT IS CALL BY CAL
endform. " increment-counter
OUTOUT :
-- .- - . -
Lanm L u i;ur i\ w L i l C a l i Kg R r i e r e r l ~ e
----
Here the Counter got Incremented as it acts --
i l i E CO&l,IT;I:: itF';Ci?, ItI;:Il,E~:EI~.'i I T
: l i ~ r;o~.;p~:~i:: , 4 1 - : t ~ < l f , i : ; ~ t ~ t ; ~ bI~Si call by reference as long as the subroutine
c<ll.'p);bi:; :,k'jk:{ ],,';F!L,!L:;r 15
is successfully processed. But the Changes
Will be reflected to the Actual Parameters
Only After it Comes Out of the
Subroutine, But Not with in the
Subroutine, We Can Check the Same in
Debugging Mode
@ ip-v-counter = ip-v-counter + 1
'MOTE : tlERE THE CHHNGES T0 THE FURElP,L PARAMETER
Formal parameters can have any valid ABAP data type. You can specify the type of a
formal parameter, either generically or fully, using the TYPE or LIKE addition. If you
specify a generic type, the type of the formal parameter is either partially specified or not
specified at all. Any attributes that are not specified are inherited from the
corresponding actual parameter when the subroutine is called. If you specify the type
fully, all of the technical attributes of the formal parameter are defined with the
subroutine definition.
By specifying the type, you ensure that a subroutine always works with the correct
data type.
The following types allow you more freedom when using actual parameters. The actual
parameter need only have the selection of attributes possessed by the formal parameter.
The forinal parameter adopts its remaining unnamed attributes from the actual parameter.
When you use the followillg types, the technical attributes of the folmal parameters are
fully specified. The teclmical attrib~~tes
of the actual parameter lllust col-respond to those
of the fornlal parameter.
When you use a formal parameter that is fully typed, you can address its attributes
statically in the prograin, since they are recognized in the source code.
6
To ensure compatibility with previous releases, the following addition is still allowed
before the USING and CHANGING additions:
'The fornial parameters <itab,> are defined as standard internal tables with header lines.
If you use ail internal table without header line as the corresponding actual pal-aineterfor
a formal parameter of this type, the system creates a local header line in the subroutine
for the formal parameter. If you pass an internal table with a header line, the table body
and the table work area are passed to the subroutine. Formal parameters defined using
TABLES cannot be passed by reference. If you want to address the components of
structured lines, you must specify the type of the TABLES parameter accordingly.
From Release 3.0, you should use U S I ~ Gor CHANGING instead of the TABLES
addition for internal tables, although for performance reasons, you should not pass
them by value.
Page 35 of 44 By Ganapati Adimulam
eMaxTechnologies,Ameerpet,Hyderabad
Ph No :+91 40 -65976727, Cell No : 99484 44808,98490 34399, www.emaxfecA.coin
Modularization Techniques
6 We Nevet- Cornpl-ornisein Quality, Would You?
Note : The sequence of the actual parameters in the PERFORM statement is crucial. The
value of the first actual parameter in the list is passed to the first formal parameter, the B
second to the second, and so on. The additions USING and CHANGING have exactly the
saine n~eanil~g. You only need to use one or the other. I-Iowever, for documentary
reasons, it is a good idea to divide the parameters in the same way in which they occur in
the interface definition.
If a subroutine contains TABLES parameters in its interface, you must specify them in a
TABLES addition of the PERFORM statenieilt before the USING and CHANGING
parameters. TABLES parameters are only supported to ensure compatibility with
earlier releases, and should no longer be used.
When you call a subroutine extemally, you must know the name of the program
in which it is defined:
You specify the program name <prog> statically. You call use the IF FOUND option to
prevent a runtime error from occussing if the program <prog> does not contain a
subroutine <sub>. In this case, the system simply ignores the PERFORM statement.
6
When you call an external subroutine, the system loads the whole of the program
containing the subroutine into the internal session of the calling program
Subroutines can access all of the global data in the program in which they are defined
(main program). You therefore do not need to define a parameter interface if you do not
want to change any data in the subroutine, or if very little data is involved.
To pre\7eni the value of a global data object from being changed inside a subroutine, use
the following statement:
LOCAL <f>. 6
This stateinent may only occur between the FORM and ENDFORM statements. With
LOCAL, you call preserve the values of global data objects which callnot be hidden by a
data declaration inside the subroutine.
For example, you cannot declare a table work area that is defined by the TABLES
statement with another TABLES statement inside a subroutine. If you want to use the
table work area locally, but preserve its coiltents outside the subroutine, you must use the
LOCAL statement.
4
Local Data in the Subroutine
Data declarations in procedures create local data types and objects that are only visible
within that procedure.
If you want to keep the value of a local data object after exiting the subroutine, you must
use the STATICS statement to declare it instead of the DATA statement. With STATICS
you declare a data object that is globally defined, but only locally visible from the
subroutine in which it is defined. 6
.',;...:,
.,.5',.. 9,.,. .'. d, .;-*:
.,..'.,.. <.....,.-5.,..'. * :# :+ * * *: *
*: .:: :$ :3 ,:: * >: :k * -::::4 * * ::: * * * * * * * *
:g * < I ? :$ $: :) *: ): :g * * ::: :s *
:$
REPORT ZDEMO-STATICS-IN-SUBROUTINES .
PERFORM increment-counter.
PERFORM increment-counter.
SKIP.
*STATICS Variable is Used in the Subro~itine
PERFORM add numnberby-one. a
FORM increment-counter.
1, counter = 1-counter + 1.
lfrite : 1 'The Value Of Counter is', 1-counter.
ENDFORM.
FORM add-number-by-one.
Note : Macros Should be Defined First and Called next in the Program.
END-OF-DEFINITION
Macros do not belong to the definition part of the program. This means that the
DEFINE ...END-OF-DEFINITION block is not interpreted before the processing blocks
in the program. At the same time, however, macros are not operational statements that
are executed within a processing block at runtime. Wl~enthe program is generated, macro
definition:; are not talten into account at the point at which they are defined.
When the prograill is generated, the system replaces <macro> by the defined statements
and each placeholder &i by the parameter <p i >.
NOTE: The most essential feature of a macro definition is that it should occur before the
macro is used.
DATA: W S U L T TYPE I.
DEFINE OPERATION.
Page 40 of 44 By Ganapati Adimulam
eMaxTechnologies,Ameerpet,Hyderabad
Ph No :+91 40 -65976727, Cell No : 99484 44808,98490 34399, www.emaxleeR.com
+'
RESULT= &1 &2 853.
WRITE : / 'THE RESULT OF &1 &2 &3, IS', RESULT
END-OF-DEFrNITION.
:k
1hE F E S l I L i OF : * 3 i 5
'1Wt lK1E!Jl.7 Ill: >>
TEE RESULT OF 5
*
."
.
7 I!;
3 is
1hE F E S l i l - i U F 5 ' 3 : 5
REPORT ZDEMO-MACRO-READ-FIRST-RECORD
<<
Page 41 of 44
173
2
Example 2 : Write a Macro to read the First Record from the Given
Internal Table.
8:
Modularization Techniques
We Never Compromise in Quality, Would You?
g * ~ : * * * < : ~ : * * ~ : * : ~ * g ~ : g * * : * * g * * * * .++,~***.**gg:~~*gg:~**$::$*#:<<;~**~:;~**~:;~g+:<:
eMaxTechnologies,Ameerpet,Hyderabad
:$ $
.
<: :$ * 2: :: * :!: * :t *
:$ :$
By Ganapati Adimulam
<:
Modularization Techniques
We Never Co~npromisein Quality, Would You?
* START-OF-SELECTION. .+
* 4: g *: * *.., * %: * ,-* * * *,*,.,. < . + <.*.
$: * A0 8
,b .I.
.!,
.+4**$:4:***4:****:$*:2*****:**:**.+4:*4::!:***:
8.. -4. .t. -9
START-OF-SELECTIOIV.
* THE MACRO READS THE FIRST RECORD FROM THE INTERNAL TABLE
* PLACES THE COhTTEhTTS IhTTO WORK AREA
WRITE : 1 'THE REULT OF THE MACRO IS'.
SKIP 1.
WRITE : I5 WA BNKA-BANKS,
15 U'A BNKA-BANKL,
25 w ABNKA-B ANKA,
40 WA-BNKA-STRAS,
6
50 WA-BNKA-ORTO1.
;~*********.+g**~~.*******:~g*****~:**&~.~..'.."~~*~****&&.'."."
,.,
, ,-'I..*.,., .r..ri.<. 3 1 I , 1 ,
4:
EhTD-OF-SELECTION. *
* *.* .+ g &, -,2I;: , & ,b + + -9. -9, -7+
. 4..,. * ..',..A', *. * * * * * * * * * * * 4: * -'.
. *, ,..'*. .'. .'.,.. .'. .'.<. J..'<.. * .,..*'. .',*. .'.<, .'.,. ...-p /<. -'.
,. -" +
?j. * "-* +
-" -" "'
SKIP 2.
WRITE : / 'THE LIST OF BANK DETAILS ARE'.
ULINE.
15 WA RNKA-BANKL,
25 W A ~ B N K A -ANKA,
B
40 WA-BNKA-STRAS,
50 WABNKA-ORTO 1.
ENDLOOP.
THE LIST OF BRIII: DET>,ILS ![,RE Here First Record from the in
the Internal Table is
AE iljii?O0l:IO C i T i ban!: F l o r i iia Z g E u e r ~ o s
OF; t i : . ~ ~ 3 i j ' j e.srlco R i g !;ai..aT erlio ~uenils- AR 2005000 CitiBank ..
h i 1091!3 De:itsrhe Bani,i l f e i - s t r ~ l ' ~ ~i sr
.W
ST 12345 E ~ I sb:3rli:,
. r; i~l:,enya:.;:~B~rsp~t;3~jt
,"I.! 123.456 ?,HZ FJanIcitig [,or
B) Processing blocks that are called using the ABAP runtime system:
Modularization at Runtime .
Event blocks Ex : INITIALIZATIION, AT SELECTION-SCREEN, START-
OF-SELECTION,END-OF- SELECTION.
Dialog modules
Exercises
1) Write a Function Module to Get the List Of items and their Details for the
Given Purchasing Doc.no?
2) Write a Function Module to Get the list Of Customers that are created in
the. Given Date Range?
3) Write a Function Module to Get the list Of Vendors that are created Only
On Saturdays and Sundays in the Given Date Range?
6
4) Write a Function Module to Get the list Of Vendors that are created 8n1y
On Saturdays and Sundays in the Given Date Range?
5) Write a Function Module to Get the list materials for the Given Material
Type?
6) Write a Function Module to Get the list of Programs that are Created on
Current Date (Today)?
7) Write a Function Module to Get the list of all the Standard SAP table!; ?
8) Write a F M to Get the list of Sales Orders which Costs More than 1 lakh INR
for the Given Data Range ?
9) Write a F M to Return the list of Storage location under the Given Plant ?
10) Write a FM to Return the list of Bank Details for the Given Customer?