Вы находитесь на странице: 1из 292

SAP-ADV ABAP

SAP-ADV ABAP

NAME : B V Ashok kumar


TOPICS : MODULE POOL PROGRAMMING
REPORTS
OOABAP

Ashok
SAP-ADV ABAP

INDEX
1 ABAP Transactions (or) Module Pool Programming (or) Dialog Programming 5
2 Events in Module Pool Programming 5
3 Sub Screen Area 11
4 Table Control 15
5 Tab Strip Control 22
6 Mail Coding 33
7 Applications 34
8 LUW Functionality 36
9 CHAIN Keyword 37
10 Table Control Wizard 38
11 Input / Output Field 49
12 Assignment Log sheet Temperature Details 54
13 Assignment Cheques Date Entry Screen 56
14 Assignment Simple calculator 60
15 Reports (Classical, Interactive, ALV, LDB (Logical Data Base) &SAP Query 61
Reports )
16 1. Classical Reports (Events in Classical Reporting) 62
17 MM - PO and Tax Details Report 67
18 KONV Table 73
19 MM - Po Delivery Status Report (Assignment) 74
20 2. Interactive Reporting ( HIDE, SY-LSIND, SY-LISEL, GET CURSOR) 75
21 SAP Memory (SET PARAMETER) 76
22 SD - Invoice Details based on Customers 77
23 VBRK, VBRP, ADRC Tables 82
24 3. ALV Reporting (Traditional ALV & ALV with OOP ) 84
25 A)Traditional ALV(Simple, Blocked & Hierarchal Sequential ALVs) 84
26 i) Simple ALV (Classical & Interactive ALV) 85
27 a) Classical ALV 85
28 MM - Open PO Details Report 85
29 REUSE_ALV_GRID_DISPLAY 90
30 MM - Restricted & Unrestricted stock details report material wise & plant wise 92
Report
31 MARD Table 95
32 SLIS_SORTINFO_ALV, SLIS_LISTHEADER, SLIS_ALV_EVENT 96
33 Monthly sales report based on customers Report (Assignment) 97
34 Sales analysis report (Assignment) 98
35 b) Interactive ALV 99
Ashok
SAP-ADV ABAP

36 Customer master details Report 99


37 PP - Movement type wise sale production consumption details for materials 108
Report
38 SD - Sales register report 120
39 SD Flow 122
40 J_1IEXCHDR, VBFA Tables 123
41 VBKD Table 124
42 Material wise Invoice & Realization details Report(Assignment) 124
43 ii) Blocked ALV 125
44 Function Modules for Blocked ALVs 125
45 SD - Invoice details Customer wise, Material wise & Segment wise Report 126
46 iii) Hierarchal Sequential ALV 128
47 MM - PO Price Change Report 128
48 FI Module 136
49 HR Module 139
50 4. Logical Database 145
51 HR - Employee Details Report 145
52 Employee Total Details Report (Assignment) 149
53 5. SAP Query 150
54 Performance Tuning 152
55 Indexing (Primary Index & Secondary Index) 153
56 SQL Tracer 155
57 Runtime Analysis 157
58 ABAP Examples & ABAP Documentation 158
59 Extended Program Check 159
60 Code Inspector 160
61 GET RUN TIME FIELD keyword 161
62 Creating Custom Logical Database 163
63 Material Ageing Report (Assignment) 165
64 Packing Cost Material Report (Assignment) 166
65 Overview of Reports 167
66 OOABAP 168
67 Section of a Class (Class Definition, Class Implementation & Class Execution) 170
68 FI - Statement of Account based on Customer Report 172
69 Local Class 178
70 BSID & BSAD Tables 178
71 Inheritance 179
72 FI - Vendor Aging Report 179
73 BSIT & BSAK Tables 186
74 Abstract Class 187

Ashok
SAP-ADV ABAP

75 Employee Family & Previous Employers Details Report (Assignment) 194


76 Employee Late Coming Report (Assignment) 195
77 Global Class 196
78 Constructor 201
79 Asset Register Report (Assignment) 202
80 PR to GR Report (Assignment) 203
81 Interface Functionality 204
82 Alias 210
83 PP Module 211
84 Event Functionality 213
85 Exception Class 220
86 B) ALV Object Oriented Programming 221
87 Custom Control 221
88 QM - Report for Quality Notifications Report 222
89 PP - Packing cost material report using interactive functionality with 2 custom 226
controls Report
90 MAST, STAS, STOP & MBEW Tables 234
91 Exception Coding 235
92 Button Functionality 236
93 Hyperlinks Functionality 243
94 Questions & Answers 244
95 Module Pool Programming 244
96 Reports 246
97 Interactive Reports 272
98 OOABAP 278

Ashok
SAP-ADV ABAP

MODULE POOL PROGRAMMING


24-09-2014
ABAP Transactions:
 It is also known as Module Pool Programming
 It is also known as Dialog Programming

Transaction:
A transaction is a series of Dialog Steps in which application will accept data from user which
is finally updated to Database

Name1

Ort01 Dialog Programming


Flow Logic
Land1

Display exit

Note:
Flow Logic (Events) acts as interface between Screen Painter & Dialog Programming

Events in Dialog Programming:


1. PAI (Process After Input)
2. PBO (Process Before Output)
3. POH (Process on Help Request)
4. POV (Process on Value Request)

PAI:
 It triggers after processing input values in a screen
 This event triggers whenever user interacts with a screen

PBO:
It triggers before screen display

Note:
1. PAI will brings the data from Screen to Program Variables
Ashok
SAP-ADV ABAP

2. PBO will brings the data from Program Variables to Screen

Ashok
SAP-ADV ABAP

POH:
It triggers whenever user select F1 Function Key. It is for help

POV:
It triggers whenever user select F4 Function Key. It is for search help

Flow of Data in Module Pool Programming:

Transfer data from Screen to Program variables


Dialog
Screen Programming

Transfer data from Program Variables to Screen

Function Control Codes:


 It is also known as FCT codes
 Using FCT codes Function Codes can be controlled (or) identified in Module Pool
Programming
SY-UCOMM
Logic Logic

FCT FCT

Display Insert

Dialog Programming

SY-UCOMM:
It returns FCT value for a function key (button) in Dialog programming selected by user

Steps:
1. Work with SE38 (create a Dialog Programming)
2. Work with SE51 (create a Screen)
3. Work with SE93 (create a T code)
Ashok
SAP-ADV ABAP

4. Run the T code

Ashok
SAP-ADV ABAP

Requirement:

Kunnar

Land1

Name1

Ort01

Pstlz

strs

Display Clear Exit

Solution:
Step-1:
 Go to SE38
 Program: ZSD_CUSTOMER_DETAILS
 Create
 Title: Customer Details
 Type: Module Pool
 Enter
 Package: ZABAP
 Save
 Create Request
 Short Description: SD/ABAP: Customer Details (25.09.2014)
 Enter
 Enter

Step-2:
 Go to SE51
 Program: ZSD_CUSTOMER_DETAILS
 Screen Number: 100
 Create
 Short Description: Screen 100
 Layout button
 Place a box (last from 6th option) on the screen
Ashok
SAP-ADV ABAP

Note:
Place the mouse pointer on the icon & click on it

 Bring mouse pointer on the screen & drag & drop it on the screen according to
requirement
 Double click on Frame of the box
 You will find an attributes pop-up
 Provide Text: Customer Details
 Close
 Select Dictionary Program Fields button (F6)
 You will find a pop-up
 Table Name: KNA1
 Enter
 You will find fields of the table
 Select Kunnr, Land1, Name1, Ort01, Pstlz, Stras
 Enter
 Place the fields with the help of mouse pointer on the box & right click
 Place 3 Push buttons (starting from 6th option) on Tool bar
 Double click on 1st Push button
 Text: Display
 FCT Code: Display
 Close
 Double click on 2nd Push button
 Text: Clear
 FCT Code: Clear
 Close
 Double click on 3rd Push button
 Text: Exit
 FCT Code: Exit
 Close
 Flow Logic button (F9)
 Remove comment for MODULE USER_COMMAND_100.
 Double click on USER_COMMAND_100
 You will find a pop-up Create Object: Yes
 By default New Include selected
 Select Main Program
 Enter
 Yes

Ashok
SAP-ADV ABAP

TABLES: KNA1.

DATA: BEGIN OF wa_kna1,


Land1 TYPE land1,
Name1 TYPE name1,
Ort01 TYPE ort01,
Pstlz TYPE pstlz,
Stras TYPE stras,
END OF wa_kna1.

 Scroll down to bottom


 Place cursor between MODULE…………ENDMODULE of USER_COMMAND_100.

CASE SY-UCOMM.
WHEN ‘Display’.
SELECT SINGLE land1 name1 ort01 pstlz stras INTO wa_kna1 FROM KNA1
WHERE kunnr EQ KNA1-kunnr.
WHEN ‘Clear’.
CLEAR: wa_kna1, KNA1-kunnr.
WHEN ‘Exit’.
LEAVE PROGRAM.
ENDCASE.

 Activate the program


 Back (F3)
 Remove comment for MODULE STATUS_100.
 Double click on STATUS_100
 Yes
 Main Program
 Enter
 Enter
 Place mouse pointer between MODULE…………ENDMODULE of STATUS_100

KNA1-land1 = wa_kna1-land1.
KNA1-name1 = wa_kna1-name1.
KNA1-ort01 = wa_kna1-ort01.
KNA1-pstlz = wa_kna1-pstlz.
KNA1-stras = wa_kna1-stras.

 Activate the program


Ashok
SAP-ADV ABAP

 Back (F3)
 Activate the screen
Step-3:
 Go to SE93
 Transaction Code: ZCUSTOMER
 Create
 Title: T code for Customer Details
 Enter
 Program: ZSD_CUSTOMER_DETAILS
 Screen Number: 100
 Save
 Enter
 Run the T code (ZCUSTOMER)

25-09-2014
Brief Flow:
1. PBO (Screen is called)
2. PAI (This event will triggers whenever you select a Button)
3. PBO (This will carry the data from Program Variables i.e. wa_kna1-kunnr = KNA1-
kunnr to screen field)

Debugging a Module Pool Program:


 Go to SE38
 Program: ZSD_CUSTOMER_DETAILS
 Change
 Place cursor at WHEN ‘DISPLAY’.
 Select Stop
 Place cursor between MODULE………..ENDMODULE of STATUS_100.
 Select Stop
 Run T code (ZCUSTOMER)
 Enter

Ashok
SAP-ADV ABAP

Sub Screen Area:


It is a location where sub screens can be called in Main screen

Note:
In SAP you can create only 1 Normal Screen in an application & remaining all are Sub screens

Requirement:

Material Code Material Type

Material Group

Gross Weight

Net Weight

Division

Display Clear Exit Material Description

Sub screen area (sub) sub screen (110)


Main screen (100)

Syntax for Calling Sub Screen in Sub screen area:


CALL SUBSCREEN <sub screen area name> INCLUDING <program name>
<sub screen number>

Example:
CALL SUBSCREEN SUB INCLUDING ‘ZMM_MATERIAL_SUB’ ‘110’

Solution:
Step-1:
 Go to SE38
 Program: ZMM_MATERIAL_SUB
 Create
 Title: Materials Details with Sub Screen
 Type: Module Pool
 Save
 Package: ZABAP
Ashok
SAP-ADV ABAP

 Enter
 Create Request
 Short Description: MM/ABAP: Materials Details with Sub Screen (26.09.2014)
 Enter
 Enter

Step-2:
 Go to SE51
 Program: ZMM_MATERIAL_SUB
 Screen: 100
 Create
 Short Description: Screen 100
 Layout
 Dictionary Program Fields (F6)
 Table Name: MARA
 Enter
 Select matnr field
 Enter
 Place the field on the top of the screen
 Place Sub Screen Area (last from 5th option) on the screen
 Double click on Sub Screen Area
 Name: SUB
 Close
 Place 3 Push Buttons (starting from 6th option) under Sub Screen Area
 Provide Text & FCT code as per requirement
 Select Flow Logic
 Remove comment for MODULE USER_COMMAND_100
 Double click on USER_COMMAND_100
 Yes
 Main Program
 Enter
 Yes

TABLES: MARA, MAKT.

 Place cursor between MODULE……….ENDMODULE of USER_COMMAND_100

CASE SY-UCOMM.
WHEN ‘DISPLAY’.
SELECT SINGLE mtart matkl brgew ntgew spart FROM MARA
INTO (MARA-mtart, MARA-matkl, MARA-brgew, MARA-ntgew, MARA-spart)
WHERE matnr = MARA-matnr.
Ashok
SAP-ADV ABAP

SELECT SINGLE maktx FROM MAKT INTO MAKT-maktx


WHERE matnr = MARA-matnr
AND spras = ‘EN’.

WHEN ‘CLEAR’.
CLEAR: MARA, MAKT.

WHEN ‘EXIT’.
LEAVE PROGRAM.
ENDCASE.

 Activate program
 Back (F3)
 Place cursor under PROCESS BEFORE OUTPUT

CALL SUBSCREEN SUB INCLUDING ‘ZMM_MATERIAL_SUB’ ‘110’.

 Activate screen
 Back (F3)
 Screen: 110
 Create
 Short Description: Sub Screen 110
 ** Screen Type: Sub Screen
 Layout
 **place a box (last from 6th option) on top left corner of the screen
 Double click on frame of the box
 Text: Material Details
 Close
 Dictionary Program Fields (F6)
 Table Name: MARA
 Enter
 Select matnr, matkl, brgew, ntgew, spart fields
 Enter
 Place the fields on the box
 Dictionary Program Fields (F6)
 Table Name: MAKT
 Enter
 Select maktx field
 Enter
 Place the field on the box
 Flow Logic
Ashok
SAP-ADV ABAP

 Activate screen

Step-3:
 Go to SE93
 Transaction Code: ZMATERIAL
 Create
 Short Text: T code for Materials Details
 Enter
 Program: ZMM_MATERIAL_SUB
 Screen Number: 100
 Save
 Enter
 Run T code (ZMATERIAL)

Ashok
SAP-ADV ABAP

27-09-2014
Table Control:
Use table control for processing multiple records

Syntax for declaring Table Control:


CONTROLS <table control name> TYPE TABLEVIEW USING SCREEN <screen no>

Object:
Truck Entry Screen

Vendor

DC DC Truck Gross Net Tare PO Vendor


Numbe Date Number weight Weight Weight Numbe number
r r

Display Insert Update Reset Exit

Screen 100

Solution:
Step-1:
 Go to SE11
 Database Table: ZMM_DEMO
 Create
 Short Description: Truck Entry Table
 Delivery Class: A
 Table View Maintenance: Table View Maintained with Restrictions
 Fields
Field key Data Element
MANDT _/ MANDT
DCNO _/ ZDCNO
DCDATE _/ ZDC_DATE
TNO ZTNO
Ashok
SAP-ADV ABAP

BRGEW BRGEW
TWT TWT
NTGEW NTGEW
EBELN EBELN
LIFNR LIFNR

 Currency Quantity Fields


Field Reference Table Reference Field
BRGEW EKPO MEINS
TWT EKPO MEINS
NTGEW EKPO MEINS

 Technical Settings
 Data Class: APPL1
 Size Category: 0
 Save
 Back (F3)
 Activate Table
 Yes

Step-2:
 Go to SE80
 Function Group: ZTCGR
 Enter
 Yes
 Short Text: Function Group for Truck Details
 Enter
 Local Object
 Under ZTCGR you will find INCLUDES, Expand it
 You will find 2 INCLUDES
 Double click on an include with TOP as suffix
 Select Display/Change option

TABLES: ZMM_DEMO, LFA1.

CONTROLS: vcontrol TYPE TABLEVIEW USING SCREEN ‘100’.


DATA: n TYPE I.
wa_demo TYPE zmm_demo.
it_demo TYPE TABLE OF zmm_demo.

 Activate
 Back (F3)
Ashok
SAP-ADV ABAP

 Right click on ZTCGR function group


 Create
 Screen
 You will find a pop-up
 Program: SAPLZTCGR
 Screen Number: 100
 Enter
 Short Description: Screen 100
 Layout
 F6
 Table Name: LFA1
 Enter
 Select Lifnr
 Enter
 Place the field on top of the screen
 Place a Box on the screen
 Double click on box frame
 Text: Truck Entry
 Close
 Place Table Control (last from 4th option) on the box
 Double click on Table Control
 At bottom under Separators check Vertical & check Horizontal
 Close
 F6
 Table Name: ZMM_DEMO
 Select all fields except MANDT
 Enter
 Place the fields on table control
 Place 5 push buttons under table control
 Provide Text & FCT code as per requirement
 Flow Logic

Step-3:
 Place cursor under PROCESS AFTER INPUT.

MODULE USER_DML.
LOOP AT it_demo.
FIELD: zmm_demo-dcno,
zmm_demo-dcdate,
zmm_demo-tno,
zmm_demo-brgew,
zmm_demo-twt
Ashok
SAP-ADV ABAP

zmm_demo-ntgew
zmm_demo-ebeln,
zmm_demo-lifnr.
ENDLOOP.

 Place cursor under PROCESS BEFORE OUTPUT.

LOOP AT it_demo INTO wa_demo WITH CONTROL vcontrol.


MODULE STATUS_100.
ENDLOOP.

 Double click on USER_DML


 Yes
 Enter
 Enter
 Yes

 Place cursor between MODULE………..ENDMODULE of USER_DML

CASE SY-UCOMM.
WHEN ‘INSERT’.
MODIFY zmm_demo FROM zmm_demo.
IF SY-SUBRC EQ 0.
MESSAGE ‘Record Inserted’ TYPE ‘S’.
ENDIF.

WHEN ‘UPDATE’.
UPDATE zmm_demo SET brgew = zmm_demo-brgew
twt = zmm_demo-twt
ntgew = zmm_demo-ntgew
WHERE dcno = zmm_demo-dcno.
IF SY-SUBRC EQ 0.
MESSAGE ‘Record Updated’ TYPE ‘S’.
ENDIF.

WHEN ‘ENTER’.
zmm_demo-ntgew = zmm_demo-brgew - zmm_demo-twt.
ENDCASE.

 Activate
 Back (F3)

Ashok
SAP-ADV ABAP

 Remove comment for MODULE USER_COMMAND_100.


 Double click on USER_COMMAND_100
 Yes
 Enter
 Enter
 Yes
 Place cursor between MODULE…………..ENDMODULE of USER_COMMAND_100

CASE SY-UCOMM.
WHEN ‘DISPLAY’.
SELECT * FROM zmm_demo INTO TABLE it_demo WHERE lifnr = lfa1-lifnr.

WHEN ‘RESET’.
REFRESH it_demo.

WHEN ‘EXIT’.
LEAVE TO SCREEN 0.
ENDCASE.

MODIFY it_demo FROM zmm_demo INDEX vcontrol-current_line.


IF SY-SUBRC NE 0.
APPEND zmm_demo TO it_demo.
ENDIF.

 Activate
 Back (F3)

 Remove comment for MODULE STATUS_100.


 Double click on STATUS_100
 Yes
 Enter
 Enter
 Yes

MOVE wa_demo-dcno TO zmm_demo-dcno.


MOVE wa_demo-dcdate TO zmm_demo-dcdate.
MOVE wa_demo-tno TO zmm_demo-tno.
MOVE wa_demo-brgew TO zmm_demo-brgew.
MOVE wa_demo-twt TO zmm_demo-twt.
MOVE wa_demo-ntgew TO zmm_demo-ntgew.
MOVE wa_demo-ebeln TO zmm_demo-ebeln.
MOVE wa_demo-lifnr TO zmm_demo-lifnr.
Ashok
SAP-ADV ABAP

DESCRIBE TABLE it_demo LINES n.


vcontrol-lines = n. //---it activates vertical scroll bar

 Back (F3)
 Activate screen

 Right click on ZTCGR function group


 Activate
 Enter
 Right click on ZTCGR
 Create
 Transaction
 Transaction Code: ZTRUCK
 Short Text: Truck Entry
 ***Program: SAPLTCGR
 ***Screen Number: 100
 Save

 Run T code (ZTRUCK)

29-09-2014
Ques-1: Suppose in table control when I entered few records then I selected ‘Enter’ option, I
found that the records are completely vanished from table control. Why it happens & What
logic you will write to avoid problem?
Ans:
 When you select ‘Enter’ control will moves from screen to program
 In program there is no logic provided for storing the table control data in internal table
 So nothing is transferred back to table control screen
 So it looks like empty
Logic:
MODIFY it_demo FROM zmm_demo INDEX vcontrol-current_line.
IF SY-SUBRC NE 0.
APPEND zmm_demo TO it_demo.
ENDIF.

Ques-2: In table control how you can perform auto calculations whenever ‘Enter’ key selected?
Ans:
 Remove comment for SET PF_STATUS.
 Under MODULE STATUS_100 ‘xxxxxxxxx’.
 Remove ‘xxxxxxxxxx’ provide ’BACK’.

Ashok
SAP-ADV ABAP

 Yes
 Yes
 Short Text: BACK
 Enter
 Expand function keys option
 _/ ENTER
 Activate
 You will find a pop-up, Enter
 Function Text: Enter
 Enter
 Back (F3)
 Activate program

Ashok
SAP-ADV ABAP

Tab Strip Control:


Syntax:
CONTROLS <strip name> TYPE TABSTRIP.

Object:
Former Loan Application

Cooperative Bank

-------- Main Screen 100

Farmer Loan Payment


- Tab Strip

Sub Screen Area

Sub Screen 110


ZFARMER TABLE
FNAME
Account fname fcountry Fcity Postal Tel address
FCOUNTRY number code
FCITY

POSTAL CODE

TEL
Automatically account number should be generated by system
ADDRESS
i.e. 90000001

SAVE

Ashok
SAP-ADV ABAP

Sub Screen 120


ZLOAN Table
A/C NUMBER
A/C FNAME LOAN APPROVE
FNAME
NUMBE AMOUNT
LOAN AMOUNT R

APPROVE

A/C
Number field is mandatory
SAVE FName field is in display mode
When you enter A/CNumber & then press Enter, FName will
display automatically

Sub Screen 130


A/C NUMBER ZPAYMENT Table

FNAME A/C FNAME LOAN LOAN INTEREST DUE


NUMBER AMOUNT PAID
LOAN AMOUNT
A/C Number field is
mandatory
LOAN PAID
FName, Loan Amount &
InterestINTEREST
fields are in display mode
DUE When you enter Loan Paid & press Calc button Interest will
generated automatically

CALC MAIL

Ashok
SAP-ADV ABAP

30-09-2014
Solution:
Step-1: Function Group Creation
 Go to SE80
 Function Group: ZFARMGR
 Enter
 Yes
 Short Text: Function Group for Farmer Loan
 Enter
 Package: ZABAP
 Enter
 Create Request Number
 Short Description: MM:ABAP/ Farmer Loan (30.09.2014)
 Enter
 Enter

Step-2: Providing Variables & Tables


 Expand Includes
 Double click on Top Include
 Display / Change

TABLES: ZFARMER, ZLOAN, ZPAYMENT.

CONTROLS STRIP TYPE TABSTRIP.

DATA: x TYPE SY-DYNNR VALUE ‘110’.

DATA: days TYPE I,


approve TYPE C.

* for mails
DATA: t_doc TYPE SODOCCHGI1,
t_receive TYPE SOMLRECI1 OCCURS 0 WITH HEADERLINE,
t_text TYPE SOLISTI1 OCCURS 0 WITH HEADERLINE.

DATA: v_interest(10) TYPE C,


v_due(10) TYPE C,
v_paid(10) TYPE C,
text(100) TYPE C.

Ashok
SAP-ADV ABAP

 Activate
 Back (F3)
Step-3:
 Right click on ZFARMER
 Create
 Screen
 Screen Number: 100
 Enter
 Short Description: Screen 100
 Layout
 Place Text Field (starting from 2nd option)
 Double click on Text Field
 Text: Cooperative Bank
 Close
 Place Tab Strip Control on screen
 Double click on Tab Strip Control
 Name: STRIP
 Tab Title: 3
 Close
 Place Sub Screen Area (last from 5th option) on tab strip control
 Double click on Sub Screen Area
 Name: SUB
 Close
 Double click on Tab1
 Text: Farmer
 FCT Code: TAB1
 Close
 Double click on Tab2
 Text: Loan
 FCT Code: TAB2
 ***Ref Field: SUB
 Close
 Double click on Tab3
 Text: Payment
 FCT Code: TAB3
 ***Ref Field: SUB
 Close
 Flow Logic

Step-4:
 Remove comment for MODULE USER_COMMAND_100
 Double click on USER_COMMAND_100
Ashok
SAP-ADV ABAP

 Yes
 Enter
 Enter
 Yes
 Place cursor between MODULE…………….ENDMODULE of
USER_COMMAND_100

CASE SY-UCOMM.
WHEN ‘TAB1’.
x = ‘110’.
STRIP-ACTIVETAB = ‘TAB1’.
WHEN ‘TAB2’.
x = ‘120’.
STRIP-ACTIVETAB = ‘TAB2’.
WHEN ‘TAB3’.
x = ‘130’.
STRIP-ACTIVETAB = ‘TAB3’.
ENDCASE.

 Activate
 Back (F3)

 Place cursor under USER_COMMAND_100


CALL SUBSCREEN SUB.

 Place cursor under PROCESS BEFORE OUTPUT


CALL SUBSCREEN SUB INCLUDING ‘SAPLZFARMGR’ x.

 Activate
 Back (F3)

Step-5:
 Right click on ZFARMGR
 Create
 Screen
 Screen Number: 110
 Enter
 Short Description: Sub Screen 110
 Screen Type: Sub Screen
 Layout
 Place a Box on top left corner of the screen
 Double click on frame of box
Ashok
SAP-ADV ABAP

 Text: Farmer Details


 Close
 F6
 Table Name: ZFARMER
 Enter
 Except Mandt & Acno select all fields
 Enter
 Place the fields on the box
 Place a Push button on the box
 Double click on push button
 Text: Save
 FCT Code: SAVE
 Close
 Flow Logic
 Remove comment for MODULE USER_COMMAND_110
 Double click on USER_COMMAND_110
 Yes
 Enter
 Enter
 Yes
 Place cursor between MODULE……….ENDMODULE of USER_COMMAND_110

CASE SY-UCOMM.
WHEN ‘SAVE’.
SELECT SINGLE MAX( acno ) FROM ZFARMER INTO zfarmer-acno.
IF zfarmer-acno EQ 0.
zfarmer-acno = ‘9000000’.
ELSE.
zfarmer-acno = zfarmer-acno + 1.
ENDIF.
INSERT ZFARMER.
IF SY-SUBRC EQ 0.
MESSAGE S000(ZMESS_CLS) WITH zfarmer-acno.
ENDIF.
ENDCASE.

 Double click on ZMESS_CLS


 Yes
 Short Text: Message Handling
 Messages tab
 Enter
 Enter
Ashok
SAP-ADV ABAP

000 Successfully generated a/c number &


 Save
 Back (F3)
 Activate
 Back (F3)
 Activate screen
 Back

Step-6:
 Right click on ZFARMGR
 Create
 Screen
 Screen Number: 120
 Enter
 Short Description: Sub Screen 120
 Screen Type: Sub Screen
 Layout
 Place a Box on top left corner of the screen
 Double click on frame of box
 Text: Farmer Loan
 Close
 F6
 Table Name: ZLOAN
 Enter
 Select Acno, Fname, Lamount fields
 Enter
 Place fields on the box
 Place a check box (starting from 4th option) on the box
 Double click on check box
 Name: APPROVE
 Text: Approve
 Close
 Place a push button on the box
 Double click on push button
 Text: Save
 FCT Code: SAVE
 Close
 Double click on Fname I/O field
 *** at bottom select Program tab
 Input: Not Possible
 Close
 Flow Logic
Ashok
SAP-ADV ABAP

 Place cursor under PROCESS AFTER INPUT

CHAIN.
FIELD: zloan-acno MODULE CHECK ON INPUT,
zloan-lamount.

 Remove comment for MODULE USER_COMMAND_120.


ENDCHAIN.

 Double click on CHECK


 Yes
 Enter
 Enter
 Yes

SELECT SINGLE acno FROM ZFARMER INTO zloan-acno WHERE acno =


zloan-acno.
IF SY-SUBRC NE 0.
MESSAGE ‘Enter Valid Account Number’ TYPE ‘E’.
ENDIF.

 Activate
 Back
 Double click on USER_COMMAND_120.
 Yes
 Enter
 Enter
 Yes
 Place cursor between MODULE……..ENDMODULE of USER_COMMAND_120

SELECT SINGLE fname FROM ZFARMER INTO zloan-fname WHERE acno =


zloan-acno.
CASE SY-UCOMM.
WHEN ‘SAVE’.
zloan-ldate = SY-DATUM.
zloan-approve = APPROVE.
INSERT ZLOAN.
IF SY-SUBRC EQ 0.
MESSAGE ‘Record inserted’ TYPE ‘S’.
ENDIF.
ENDCASE.
Ashok
SAP-ADV ABAP

 Activate
 Back
 Activate screen
 Back

Step-7:
 Right click on ZFARMGR
 Create
 Screen
 Screen Number: 130
 Enter
 Short Description: Sub Screen 130
 Screen Type: Sub Screen
 Layout
 Place a Box on top left corner
 Double click on frame of box
 Text: Payment Details
 F6
 Table Name: ZPAYMENT
 Enter
 Except Mandt select all fields
 Enter
 Place fields on box
 Double click on Fname I/O field
 At bottom select Program tab
 Input: Not Possible
 Close
 Repeat the same procedure with Lamount, Iamount & Due amount
 *** double click on Loan Paid I/O field
 At bottom select Program tab
 Input: Required
 Place a push button on the box
 Text: Calc
 FCT Code: CALC
 Place another push button
 Text: Mail
 FCT Code: MAIL
 Flow Logic
 Place cursor under PROCESS AFTER INPUT

CHAIN.
Ashok
SAP-ADV ABAP

FIELD: zpayment-acno MODULE CHECK1 ON INPUT,


zpayment-lamount.

 Remove comment for MODULE USER_COMMAND_130


ENDCHAIN.

 Double click on CHECK1


 Yes
 Enter
 Enter
 Yes
 Place cursor between MODULE…………ENDMODULE of USER_COMMAND_130

SELECT SINGLE acno FROM ZLOAN INTO zpayment-acno WHERE acno =


zpayment-acno.
IF SY-SUBRC NE 0.
MESSAGE ‘Enter valid a/c number’ TYPE ‘E’.
ENDIF.

 Activate
 Back
 Double click on USER_COMMAND_130
 Yes
 Enter
 Enter
 Yes
 Place cursor between MODULE………..ENDMODULE of USER_COMMAND_130

SELECT SINGLE fname lamount ldate approve FROM ZLOAN INTO (zpayment-
fname, zpayment-lamount, zloan-ldate, zloan-approve) WHERE acno = zpayment-acno.
CASE SY-UCOMM.
WHEN ‘CALC’.
IF zloan-approve EQ ‘x’.
CALL FUNCTION ‘HR_99S_INTERVAL_BETWEEN_DATES’.
EXPORTING
begda = zloan-ldate
endda = sy-datum
IMPORTING
days = days
zpayment-iamount = ( (zpayment-lamount * 1 * days) / (100 * 30) ).
zpayment-due = (zpayment-lamount + zpayment-iamount) - zpayment-lpaid.
UPDATE ZLOAN SET lamount = zpayment-due WHERE acno = zpayment-acno.
Ashok
SAP-ADV ABAP

INSERT ZPAYMENT.
ENDIF.
ENDCASE.
 Activate
 Back
 Activate screen

Step-8:
 Right click on ZFARMGR
 Create
 Transaction
 Transaction Code: YFARMER
 Enter
 Program: SAPLZFARMGR
 Screen Number: 100
 Save
 Back

Step-9:
 Right click on ZFARMGR
 Activate
 Run T code (YFARMER)

Ashok
SAP-ADV ABAP

01-10-2014
Mail Coding:
* for mail address
T_receiver_rec_type = ‘U’.
T_receiver_receiver = ‘satya@ibm.com’.

* fill subject
T_doc_obj_name = ‘TEXT’.
T_doc_obj_descr = ‘Payment Details’.
T_doc_obj_langu = SY-LANGU.

*fill contents
V_paid = zpayment-lpaid.
V_due = zpayment-due.
V_interest = zpayment-iamount.

CONCATENATE ‘Account Number:’ zpayment-acno INTO TEXT.


APPEND TEXT TO T_TEXT.

CONCATENATE ‘Loan Paid:’ l_paid INTO TEXT.


APPEND TEXT TO T_TEXT.

CONCATENATE ‘Loan Due:’ v_due INTO TEXT.


APPEND TEXT TO T_TEXT.

CONCATENATE ‘Interest Amount:’ v_interest INTO TEXT.


APPEND TEXT TO T_TEXT.

CALL FUNCTION ‘SO_NEW_DOCUMENT_SEND_API1’.


EXPORTING
Document_data = t_doc.
Commit_work = ‘x’.
TABLES
Object-content = t_text.
Receivers = t_receiver.
IF SY-SUBRC EQ 0.
COMMIT WORK.
* push mails to SAP inbox
SUBMIT RSLONN01 WITH MODE = ‘INT’ AND RETURN.
ENDIF.
Ashok
SAP-ADV ABAP

 Activate
Applications:
 Application is a collection of screens
 Screen is a collection of fields
 Applications are created by Technical Consultant
 Customization of data in application is done by Functional Consultant
 Applications are used by End Users

Example:
 Go to XK01
 Vendor: 9872
 Company Code: 1000
 Purchase Organization: 1000
 Account Group: 0001
 Enter
 Title: MR
 Name: Ashok
 Search Tem: Broacomm
 Street: Ameerpet
 Postal Code: 500074
 City: Hyderabad
 Country: IN
 Enter
 No data in this screen
 Enter
 Country: IN
 Bank Key: F000158
 A/C Number: 9000006
 Enter
 Enter
 Recon Account: 31000
 Cash Management Group: A1
 Enter
 No data in this screen
 Enter
 No data in this screen
 Enter
 Order Currency: INR
 Enter
 Save

Ashok
SAP-ADV ABAP

Ashok
SAP-ADV ABAP

 Go to SE11
 Database Table: LFA1
 Display
 Contents
 Lifnr: 9872
 F8

Ashok
SAP-ADV ABAP

LUW Functionality:
 Logical Unit of Work
 By default all SAP applications follows LUW functionality

Database Server

Buffer LFA1 LFAK

VENDOR: 9872 NAME RECON


C CODE: 1000 CITY CASH MANAGEMENT
P ORG: 1000 GROUP
COUNTRY
A/C NUMBER: 0001

SAVE

Screen level validation Screen level validation Screen level validation Explicit commit
Implicit commit Implicit commit Implicit commit

06-10-2014
 By default all SAP applications follows LUW functionality
 In between the Screens implicit commit will take place where implicit commit data from
Screen is transferred to Database Buffer
 Whenever user applies Save option explicit commit will take place where explicit commit
data from Database Buffer is transferred to respective Database Table

Ashok
SAP-ADV ABAP

CHAIN Keyword:
 By default standard application allows screen level validations
 If you want to perform field level validations you should write logic explicitly using
CHAIN……..ENDCHAIN

 All implicit commit as DB LUW Commit & all explicit commit as SAP LUW Commit

Advantages & Disadvantages of LUW:


Disadvantage of LUW:
If number of screens increases in an application, interaction between Presentation Server &
Database Server also increases there by reducing the performance of system

Advantage of LUW:
With LUW the data is concisely transferred to Database

Ashok
SAP-ADV ABAP

Table Control Wizard:


 It is advance to Table Control
 In Table Control Wizard most of the logic is already provided by system

Requirement:
Equipment details based on Plant

Input:

Add New Update Delete Display

Equipment Number: To

Equipment Date: To

Plant To

Material Code To

Save

Equi no Equi date Plant Material Quantity Production Dept


code order
5001 1.2.2014 1001 F001 2 3006001 M & pp

Sall dsall delete

Solution:
Step-1:
 Go to SE11
 Database Table: ZPP_EQUIPMENT
 Create
 Short Description: Equipment Details
Ashok
SAP-ADV ABAP

 Delivery Class: A
 Table View Maint: Display / Maint Allowed with Restrictions
 Field tab
Field key Data Element
Mandt _/ MANDT
Sel _/ CHAR1
Equnr _/ EQUNR
Edate _/ ZEDATE
Werks WERKS_D
Matnr MATNR
Menge MENGE_D
Aufnr AUFNR
Dept ZDEPT_DAT

 Double click on ZDEPT_DAT


 Yes
 Enter
 Yes
 Short Description: Department
 Domain: ZDEPT_DEM
 Double click on ZDEPT_DEM
 Yes
 Short Description: Domain for Department Field
 Data type: CHAR 10
 Value Range tab
Fix val short description
P & Engg Plant & Engg
Mech Mechanical
Prod Production’
Mstores Mould Stroes

 Activate domain
 Field Label
Medium 20 Department
 Activate
 Back
Field key Data Element
Erdat ERDAT
Ernam ERNAM

 Technical Settings
 Data Class: APPL1
Ashok
SAP-ADV ABAP

 Size Category: 0
 Currency Quantity Fields tab

Menge EKPO meins


 Activate

Step-2:
 Go to SE38
 Program: ZPP_EQUIPMENT_DETAILS
 Create
 Title: Equipment Details
 Type: Executable Program
 Save

TABLES: ZPP_EQUIPMENT, SSCRFIELDS.

SELECTION-SCREEN: BEGIN OF LINE.


PUSHBUTTON 10(10) BUTTON1 USER-COMMAND BUT1,
PUSHBUTTON 30(10) BUTTON2 USER-COMMAND BUT2,
PUSHBUTTON 50(10) BUTTON3 USER-COMMAND BUT3,
PUSHBUTTON 70(10) BUTTON4 USER-COMMAND BUT4.
SELECTION-SCREEN: END OF LINE.

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE screen-000.


SELECT-OPTION: s_equnr FOR zpp_equipment-equnr,
S_edate FOR zpp_equipment-edate,
S_werks FOR zpp_equipment-werks,
S_matnr FOR zpp_equipment-matnr.
SELECTION-SCREEN: END OF BLOCK b1.

INITIALIZATION.
BUTTON1 = ‘Add New’.
BUTTON2 = ‘Update’.
BUTTON3 = ‘Delete’.
BUTTON4 = ‘Display’.

DATA: wa TYPE ZPP_EQUIPMENT,


It TYPE TABLE OF ZPP_EQUIPMENT.

* validate the buttons


AT SELECTION-SCREEN.

Ashok
SAP-ADV ABAP

IF SSCRFIELDS-UCOMM EQ ‘BUT1’.
CALL SCREEN 100.
ELSEIF SSCRFIELDS-UCOMM EQ ‘BUT2’.
SELECT * FROM ZPP_EQUIPMENT INTO TABLE it
WHERE equnr IN s_equnr
AND matnr IN s_matnr
AND werks IN s_werks
AND edate IN s_edate.

LOOP AT it INTO wa.


ENDLOOP.

CALL SCREEN 100.

ELSEIF SSCRFIELDS-UCOMM EQ ‘BUT3’.


SELECT * FROM ZPP_EQUIPMENT INTO TABLE it
WHERE equnr IN s_equnr
AND matnr IN s_matnr
AND werks IN s_werks
AND edate IN s_edate.

LOOP AT it INTO wa.


ENDLOOP.

CALL SCREEN 200.

ELSEIF SSCRFIELDS-UCOMM EQ ‘BUT4’.


SELECT * FROM ZPP_EQUIPMENT INTO TABLE it
WHERE equnr IN s_equnr
AND matnr IN s_matnr
AND werks IN s_werks
AND edate IN s_edate.

LOOP AT it INTO wa.


ENDLOOP.

CALL SCREEN 100.

ENDIF.

Step-3:
 Double click on 100
Ashok
SAP-ADV ABAP

 Yes
 Yes
 Short Description: Screen 100
 Main Screen
 Layout
 Place Table Control Wizard (last from 3rd option) on the screen
 Continue
 Name of Table Control: vcontrol (any name)
 Continue
 Internal Table: it
 Table Work Area: wa
 Continue
 Select Equnr, Edate, Werks, Matnr, Menge, Aufnr, Dept fields
 Continue
 Input Control
 Continue
 Scroll
 Continue
 Continue
 Complete

Step-4:
 Double click on equnr = equipment number
 Double click on edate = eq date
 Similarly maintain labels of all the fields
 Double click under Department field
 Provide drop down list box
 Place a push button on top of table control
 Double click on push button
 Text: Save
 FCT Code: SAVE
 Flow Logic
 Search for MODULE VCONTROL_MODIFY
 Double click on VCONTROL_MODIFY
 Yes
 Place cursor after MODULE VCONTROL MODIFY INPUT
 Enter

CASE SY-UCOMM.
WHEN ‘SAVE’.
MODIFY ZPP_EQUIPMENT FROM wa.
IF SY-SUBRC EQ 0.
Ashok
SAP-ADV ABAP

MESSAGE ‘Record saved’ TYPE ‘S’.


ENDIF.
UPDATE ZPP_EQUIPMENT SET erdat = sy-datum ernam = sy-uname
WHERE equnr = wa-equnr.

 Place cursor after MODIFY it FROM wa INDEX VCONTROL-CURRENT_LINE


 Enter

IF SY-SUBRC NE 0.
APPEND wa TO it.
ENDIF.

 Activate
 During activation you will find an error---controls can only be defined globally
 Double click on Error
 Copy the lines
CONTROLS: VCONTROL TYPE TABLE VIEW………………..
DATA: G_VCONTROL_LINES LIKE SY-LOOPC
DATA: OK_CODE LIKE SY-UCOMM.

 And remove the 3 lines


 Paste the 3 lines under Declaration
 Activate
 Back

Step-5:
 Remove comment for MODULE STATUS_100
 Double click on STATUS_100
 Yes
 Main Program
 Yes
 Place cursor between MODULE……..ENDMODULE of STATUS_100

CASE SY-UCOMM.
WHEN ‘BUT2’.
LOOP AT SCREEN.
IF SCREEN-NAME EQ ‘wa-equnr’
OR SCREEN-NAME EQ ‘wa-edate’
OR SCREEN-NAME EQ ‘wa-werks’
OR SCREEN-NAME EQ ‘wa-dept’.
SCREEN-INPUT = 0.
MODIFY SCREEN.
Ashok
SAP-ADV ABAP

ENDIF.
ENDLOOP.
WHEN ‘BUT4’.
LOOP AT SCREEN.
IF SCREEN-NAME EQ ‘wa-equnr’
OR SCREEN-NAME EQ ‘wa-edate’
OR SCREEN-NAME EQ ‘wa-werks’
OR SCREEN-NAME EQ ‘wa-dept’
OR SCREEN-NAME EQ ‘wa-matnr’
OR SCREEN-NAME EQ ‘wa-menge’
OR SCREEN-NAME EQ ‘wa-aufnr’.
SCREEN-INPUT = 0.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDCASE.

Step-6:
 Remove comment for SET PF-STATUS ‘BACK’.
 Double click on BACK
 Yes
 Yes
 Short Text: Back
 Enter
 Expand Function Keys
 Provide BACK
 Activate
 Back
 Activate program
 Back

Step-7:
 Remove comment for MODULE USER_COMMAND_100
 Double click on USER_COMMAND_100
 Yes
 Main Program
 Enter
 Place cursor between MODULE……….ENDMODULE of USER_COMMAND_100

CASE SY-UCOMM.
WHEN ‘BACK’.
LEAVE TO SCREEN 0.
Ashok
SAP-ADV ABAP

ENDCASE.
 Activate
Step-8:
 Double click on 200
 Yes
 Short Description: Screen 200
 Layout
 Place Table Control With Wizard (last from 3rd option) on the screen
 Continue
 Name of Table Control: VCONTROL1
 Continue
 Internal Program Tabel: it
 Table Work Area: wa
 Continue
 Select all fields (SEL, EQUNR, ……………DEPT)
 Continue
 Input Control
 Scroll
Continue
 Continue
 Complete
 Change the Labels of fields as per requirement
 *** select under SEL field & right click
 Convert
 Check Box
 Left Button
 Double click under DEPT field
 Drop Down
 List Box
 Close
 Place 3 push buttons above Table Control
 Provide Text & FCT codes as per requirement
 Flow Logic

Step-9:
 Remove comment for MODULE STATUS_200
 Double click on STATUS_200
 Yes
 Main Program
 Enter
 Yes
 Place cursor between MODULE…………ENDMODULE of STATUS_200
Ashok
SAP-ADV ABAP

CASE SY-UCOMM.
WHEN ‘BUT3’.
LOOP AT SCREEN.
IF SCREEN-NUMBER EQ ‘wa-qunr’
OR SCREEN-NUMBER EQ ‘wa-edate’
OR SCREEN-NUMBER EQ ‘wa-matnr’
OR SCREEN-NUMBER EQ ‘wa-werks’
OR SCREEN-NUMBER EQ ‘wa-aufnr’
OR SCREEN-NUMBER EQ ‘wa-menge’
OR SCREEN-NUMBER EQ ‘wa-dept’.

SCREEN-INPUT = 0.

MODIFY SCREEN.

ENDIF.
ENDLOOP.
ENDCASE.

 Activate
 Back

Step-10:
 Remove comment for MODULE USER_COMMAND_200
 Double click on USER_COMMAND_200
 Yes
 Main Program
 Enter
 Place cursor between MODULE………ENDMODULE of USER_COMMAND_200

DATA: v_ans type C.

CASE SY-UCOMM.
WHEN ‘DELETE’.

CALL FUNCTION ‘POPUP_TO_CONFIRM’


EXPROTING
TITLEBAR = ‘Deletion Conformation’
TEXT_QUESTION = ‘Do you want to delete’
TEXT_BUTTON_1 = ‘Yes’
Ashok
SAP-ADV ABAP

TEXT_BUTTON_2 = ‘No’
IMPORTING
ANSWER = v_ans.

IF v_ans EQ 1.
LOOP AT it INTO wa.

IF wa-sel EQ ‘X’
DELETE FROM ZPP_EQUIPMENT WHERE equnr = wa-equnr.

IF SY-SUBRC EQ 0.
MESSAGE ‘Record deleted’ TYPE ‘S’.
ENDIF.

ENDIF.

ENDLOOP.

ENDIF.

WHEN ‘SALL’.
LOOP AT it INTO wa.
wa-sel = ‘X’.
MODIFY it FROM wa TRANSPORTING sel
ENDLOOP.

WHEN ‘DSALL’.
LOOP AT it INTO wa.
wa-sel = ‘ ’.
MODIFY it FROM wa TRANSPORTING sel
ENDLOOP.

WHEN ‘BACK’.
LEAVE TO SCREEN 0.

 Activate
 Back

Step-11:
 Double click on STATUS_200
 Remove comment for SET PF_STATUS ‘BACK1’
 Double click on BACK1
Ashok
SAP-ADV ABAP

 Yes
 Short Text: BACK
 Enter
 Expand Function Keys option
 Type ENTER
 Activate
 Back
 Activate
 Back
 Activate

Ques: What is the difference between SSCRFIELDS-UCOMM & SY-UCOMM?


Ans:
SSCRFIELDS is a structure for maintaining text for the buttons in SELECTION-SCREEN
SSCRFIELDS-UCOMM returns FCT code for buttons maintained in SELECTION-SCREEN
SY-UCOMM returns FCT code for buttons maintained in SCREEN
SY-UCOMM will works for both Screen & Selection-screen

Syntax for creating Push buttons on selection screen:


SELECTION-SCREEN PUSHBUTTON (size) <button name> USER-COMMAND
<FCT value>.

Example:
SELECTION-SCREEN PUSHBUTTON 10(10) button1 USER-COMMAND BUT1.

08-10-2014
Note:
SCREEN is a dynamic internal table.
It is used for modifying screen.

It is having following fields


1. Group1
2. Group2
3. Group3……………
4. Input
5. Required
6. Invisible
7. Active

Ashok
SAP-ADV ABAP

Input / Output Field:


Object: Screen Making Report
Input:

Add New Display

------Selection-Screen

P_Date 01.10.2014

When you press Add New the Date should transfer to Screen
Screen 100
Screen Making Report

Save Clear Back

Date Machine Material Code Red Blue Green Total

Average

When you press Enter Total & Average display automatically

ZPP_SCREEN Table:
Date
Machine
Matnr
Red
Ashok
SAP-ADV ABAP

Blue
Green Total
Solution:
TABLES: YMM_IOFIELDS, SSCRFIELDS

SELECTION-SCREEN: BEGIN OF LINE.


SELECTION-SCREEN:
PUSHBUTTON 10(10) button1 USER-COMMAND BUT1,
PUSHBUTTON 30(10) button2 USER-COMMAND BUT2.
SELECTION-SCREEN: END OF LINE.

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-000.


PARAMETERS p_date TYPE edate.
SELECTION-SCREEN: END OF BLOCK b1.

INITIALIZATION:
button1 = ‘Add New’.
button2 = ‘Dispay’.

DATA: v1 TYPE I,
v2 TYPE I,
v3 TYPE I,
redavg TYPE I,
blueavg TYPE I,
greenavg TYPE I.

DATA: wa1 TYPE YMM_IOFIELDS,


wa2 TYPE YMM_IOFIELDS,
wa3 TYPE YMM_IOFIELDS,
it TYPE TABLE OF YMM_IOFIELDS.

AT SELECTION-SCREEN.
IF SSCRFIELDS-UCOMM EQ ‘BUT1’.
wa1-edate = p_date.
wa2-edate = p_date.
wa3-edate = p_date.

CALL SCREEN 100.

ELSEIF SSCRFIELDS EQ ‘BUT2’.


SELECT * FROM YMM_IOFIELDS INTO TABLE it WHERE edate = p_date.

Ashok
SAP-ADV ABAP

READ TABLE it INTO wa1 INDEX 1.


READ TABLE it INTO wa2 INDEX 2.
READ TABLE it INTO wa3 INDEX 3.
ENDIF.

 Double click on 100


 Short Description: Screen 100
 Layout
 Design screen as per requirement
 Flow Logic
 Remove comment for MODULE USER_COMMAND_100
 Double click on USER_COMMAND_100
 Yes
 Enter
 Enter
 Yes
 Place cursor between MODULE…………ENDMODULE

CASE SY-UCOMM.
WHEN ‘SAVE’.
MODIFY YMM_IOFIELDS FROM wa1.
MODIFY YMM_IOFIELDS FROM wa2.
MODIFY YMM_IOFIELDS FROM wa3.

IF SY-SUBRC EQ 0.
MESSAGE ‘Record saved’ TYPE ‘S’.
ENDIF.

WHEN ‘ENTER’.
wa1-total = wa1-red + wa1-blue + wa1-green.
wa2-total = wa2-red + wa2-blue + wa2-green.
wa3-total = wa3-red + wa3-blue + wa3-green.

IF wa1-red IS INITIAL.
v1 = v1 + 1.
ENDIF.

IF wa2-red IS INITIAL.
v1 = v2 + 1.
ENDIF.

Ashok
SAP-ADV ABAP

IF wa3-red IS INITIAL.
v1 = v1 + 1.
ENDIF.
IF wa1-blue IS INITIAL.
v2 = v2 + 1.
ENDIF.

IF wa2-blue IS INITIAL.
v2 = v2 + 1.
ENDIF.

IF wa3-blue IS INITIAL.
v2 = v2 + 1.
ENDIF.

IF wa1-green IS INITIAL.
v3 = v3 + 1.
ENDIF.

IF wa2-green IS INITIAL.
v3 = v3 + 1.
ENDIF.

IF wa3-green IS INITIAL.
v3 = v3 + 1.
ENDIF.

redgavg = ( wa1-red + wa2-red + wa3-red ) / v1.


blueavg = ( wa1-blue + wa2-blue + wa3-blue ) / v2.
greenavg = ( wa1-green + wa2-green + wa3-green ) / v3.

WHEN ‘BACK’.
LEAVE TO SCREEN 0.

WHEN ‘CLEAR’.
CLEAR: wa1, wa2, wa3, redavg, blueavg, greenavg.

ENDCASE.

 Activate
Ashok
SAP-ADV ABAP

 Back
 Remove comment for MODULE STATUS_100
 Double click on STATUS_100
 Remove comment for SET PF-STATUS ‘ENTER’.
 Double click on ENTER
 Yes
 Short Text: Enter
 Enter
 Expand Function Keys
 Type ENTER
 Activate
 Back
 Activate
 Back
 Activate

Ashok
SAP-ADV ABAP

Assignments:
1. Log sheet Temperature Details
Input:

Add New Display


------ Selection-Screen

Furnance

Date

Screen 100
Log Sheet Temparature Details

Furnance Shif Date T1 T2 T3 T4 T5 T6

Average

Booster Holder Temparature Details

Furnance Shif Date E1 E2 E3 E4 E5 E6

Ashok
SAP-ADV ABAP

ZLOGSHEET Table:
Furnance
Date
Shift
T1
T2
T3
T4
T5
T6
E1
E2
E3
E4
E5
E6

Solution:

Ashok
SAP-ADV ABAP

2. Cheques Date Entry Screen

Input:

------ Selection-Screen

ZCHEQUE Table:
Cheque Number
Cheque Date
Issue Date
Deposit Date
Realization Date
Customer Number
Cheque Status
Cheque Amount

Solution:

TABLES: YMM_CHEQUE, SSCRFIELDS.

SELECTION-SCREEN: BEGIN OF LINE.


Ashok
SAP-ADV ABAP

SELECTION-SCREEN: PUSHBUTTON 10(10) button1 USER-COMMAND BUT1,


PUSHBUTTON 10(10) button2 USER-COMMAND BUT2.
SELECTION-SCREEN: END OF LINE.

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-000.


SELECT-OPTIONS: s_cheqno FOR ymm_cheque-cheqno,
s_chdate FOR ymm_cheque-cheqdate.
SELECTION-SCREEN: END OF BLOCK b1.

INITIALIZATION.

button1 = ‘Add new’.


button2 = ‘Update’.
button3 = ‘Display’.

DATA: wa TYPE YMM_CHEQUE,


it TYPE TABLE OF YMM_CHEQUE.

AT SELECTION-SCREEN.

IF SSCRFIELDS-UCOMM EQ ‘BUT1’.

CALL SCREEN 100.

ELSEIF SSCRFIELDS-UCOMM EQ ‘BUT2’.

SELECT * FROM YMM_CHEQUE INTO TABLE it


WHERE cheqno IN s_cheqno
AND cheqdate IN s_chdate.

LOOP AT it INTO wa.

ENDLOOP.

CALL SCREEN 100.

ELSEIF SSCRFIELDS-UCOMM EQ ‘BUT3’.

SELECT * FROM YMM_CHEQUE INTO TABLE it


WHERE cheqno IN s_cheqno
AND cheqdate IN s_chdate.
LOOP AT it INTO wa.
Ashok
SAP-ADV ABAP

ENDLOOP.
CALL SCREEN 100.

ENDIF.

Double click on 100


Yes
Enter
Enter
Yes
Design screen with table control with wizard as per requirement
Flow Logic
Place cursor between MODULE………..ENDMODULE of VCONTROL_MODIFY INPUT

CASE SY-UCOMM.

WHEN ‘SAVE’.

MODIFY YMM_CHEQUE FROM wa.

IF SY-SUBRC EQ 0.
MESSAGE ‘Record saved’ TYPE ‘S’.
ENDIF.

ENDCASE.

MODIFY it FROM wa INDEX VCONTROL-CURRENT_LINE.

IF SY-SUBRC NE 0.
APPEND wa TO it.
ENDIF.

Place cursor between MODULE……….ENDMODULE of STATUS_100 OUTPUT

SET PF-STATUS ‘BACK’.

CASE SY-UCOMM.
WHEN ‘BUT2’.

LOOP AT SCREEN.

Ashok
SAP-ADV ABAP

IF SCREEN-NAME EQ ‘wa-cheqno’
OR SCREEN-NAME EQ ‘wa-cheqdate’
OR SCREEN-NAME EQ ‘wa-idate’
OR SCREEN-NAME EQ ‘wa-ddate’
OR SCREEN-NAME EQ ‘wa-rdate’
OR SCREEN-NAME EQ ‘wa-custno’
OR SCREEN-NAME EQ ‘wa-cheqstatus’.

SCREEN-INPUT = 0.

MODIFY SCREEN.

ENDIF.

ENDLOOP.

WHEN ‘BUT3’.
LOOP AT SCREEN.

IF SCREEN-NAME EQ ‘wa-cheqno’
OR SCREEN-NAME EQ ‘wa-cheqdate’
OR SCREEN-NAME EQ ‘wa-idate’
OR SCREEN-NAME EQ ‘wa-ddate’
OR SCREEN-NAME EQ ‘wa-rdate’
OR SCREEN-NAME EQ ‘wa-custno’
OR SCREEN-NAME EQ ‘wa-cheqamt’
OR SCREEN-NAME EQ ‘wa-cheqstatus’.

SCREEN-INPUT = 0.

MODIFY SCREEN.

ENDIF.

ENDLOOP.

ENDCASE.

Place cursor between MODULE………..ENDMODULE of USER_COMMAND 100

CASE SY-UCOMM.
WHEN ‘BACK’.
Ashok
SAP-ADV ABAP

LEAVE TO SCREEN 0.

Ashok
SAP-ADV ABAP

ENDCASE.
3. Simple calculator

Ashok
SAP-ADV ABAP

Solution:
REPORTS
ABAP Reports:
In real time ABAP Reports are designed for analysis & based on the that analysis decision
making will done
In real time every report is designed based on certain format & every report have 3 parts
1. Input
2. Processing Logic
3. Output

The reports that will designed up to now are without a proper structured format
Design the same reports in a proper structure format (with events)

Types of Reports:
1. Classical Reports
2. Interactive Reports
3. ALV Reports (ABAP List Viewer)
4. LDB Reports (Logical Data Base) ------- for HR module only
5. SAP Query Reports

Ashok
SAP-ADV ABAP

Classical Reports:
In classical reporting the entire output is maintained in a single list called Basic list

Events in Classical Reporting:


1. INITIALIZATION
2. AT SELECTION-SCREEN
3. START-OF-SELECTION
4. END-OF-SELECTION
5. TOP-OF-PAGE
6. END-OF-PAGE

09-10-2014
INITIALIZATION:
It triggers before selection-screen display
Note:
Use this event for initializing
1. Default values in selection-screen
2. Texts on push buttons in selection-screen
3. Texts for blocks, radio buttons, check boxes…………..etc

AT SELECTION-SCREEN:
It triggers once the control leaves from selection-screen & still selection-screen is in active
mode
i.e. It triggers at end of PAI when all the values are passed from selection-screen to program
variables

It is further divided into 5 types


a) AT SELECTION-SCREEN OUTPUT
b) AT SELECTION-SCREEN ON <field name>
c) AT SELECTION-SCREEN ON VALUE-REQUEST
d) AT SELECTION-SCREEN ON HELP-REQUEST
e) AT SELECTION-SCREEN ON <radio button>

AT SELECTION-SCREEN OUTPUT:
 It triggers after initialization & before selection-screen display
 Use this event for modifying selection-screen

AT SELECTION-SCREEN ON <field name>:


It triggers once selection-screen is being processed & still the selection-screen is in active mode

Ashok
SAP-ADV ABAP

AT SELECTION-SCREEN ON VALUE-REQUEST:
 It triggers when you apply F4 function key on selection-screen fields
 Use this event for Search Help

AT SELECTION-SCREEN ON HELP-REQUEST:
 It triggers when you apply F1 function key on selection-screen fields
 Use this event for Help Documentation

AT SELECTION-SCREEN ON <radio button>:


It triggers when validating radio buttons

START-OF-SELECTION:

 This event will triggers once your selection-screen is processed


 It triggers when you select F8 function key
 It triggers before reading data from database
 It triggers for all processing blocks in a program
 It is a default event triggered before extracting data from database

Note:
In your program no need to provide this event
But when you are writing INITIALIZATION (or) AT SELECTION-SCREEN it is mandatory
to use START-OF-SELECTION

END-OF-SELECTION:
It triggers once all the data is read from logical database

Note:
Use this event in HR ABAP for displaying HR data
You can use this event for writing one time logics (Display data…………..etc)

TOP-OF-PAGE:
It triggers before 1st record is output in Output List

Note:
Use this event for maintaining headers in ABAP reports

END-OF-PAGE:
It triggers after last record is output is Output List

Note:
Ashok
SAP-ADV ABAP

Use this event for maintaining footers in ABAP reports

Ques-1: Suppose there are 20 pages in my report. How many times INITIALIZATION will
triggers & TOP-OF-PAGE will triggers?
Ans:
INITIALIZATION will triggers only 1 time
TOP-OF-PAGE will triggers 20 times

Ques-2: What is LOAD-OF-PROGRAM event?


Ans:
This event will triggers before INITIALIZATION & once your program is loaded into memory

Example:
REPORT ZEVENTS NO STANDARD PAGE HEADING LINE-COUNT 20(4).

TABLES: EKPO.

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-000.


SELECT-OPTIONS: s_matnr FOR ekpo-mantnr,
s_werks FOR ekpo-werks.
SELECTION-SCREEN: END OF BLOCK b1.

TYPES: BEGIN OF ty_ekpo,


Ebeln TYPE ebeln,
Matnr TYPE matnr,
Menge TYPE menge_D,
Netpr TYPE netpr,
END OF ty_ekpo.

TYPES: BEGIN OF ty_t001w,


Werks TYPE werks_D,
END OF ty_t001w.

TYPES: BEGIN OF ty_mara,


Matnr TYPE ty_mara,
END OF ty_mara.

DATA: wa_ekpo TYPE ty_ekpo,


Wa_mara TYPE ty_mara,
It_mara TYPE TABLE OF ty_mara,
It_ekpo TYPE TABLE OF ty_ekpo,
It_t001w TYPE TABLE OF ty_t001w.
Ashok
SAP-ADV ABAP

INITIALIZATION.
S_werks-low = ‘1000’.
S_werks-high = ‘1001’.
S_werks-sign = ‘I’.
S_werks-option = ‘BT’.
APPEND s_werks.

SELECT matnr FROM MARA INTO TABLE it_mara WHERE mtart IN (‘FERT’)

LOOP AT it_mara INTO wa_mara.


S_matnr-low = wa_mara.
S_matnr-sign = ‘I’.
S_matnr-option = ‘EQ’.
APPEND s_matnr.
ENDLOOP.

T1 = ‘Selection’.

AT SELECTION-SCREEN OUTPUT.

LOOP AT SCREEN.
IF SCREEN-NAME EQ ‘s_werks-low’
OR SCREEN-NAME EQ ‘s_werks-high’
OR SCREEN-NAME EQ ‘s_matnr-low’
OR SCREEN-NAME EQ ‘s_matnr-high’.
SCREEN-INPUT = 0.
MODIFY SCREEN.
ENDIF.
ENDLOOP.

AT SELECTION-SCREEN ON s_werks.
SELECT werks FROM T001W INTO TABLE it_t001w WHERE werks IN
s_werks.

IF SY-SUBRC NE 0.
MESSAGE ‘Enter valid plant’ TYPE ‘E’ DISPLAY LIKE ‘I’.
LEAVE LIST-PROCESSING.
ENDIF.

START-OF-SELECTION.

Ashok
SAP-ADV ABAP

SELECT ebeln matnr menge netpr FROM EKPO INTO TABLE it_ekpo WHERE
matnr IN s_matnr AND werks IN s_werks.

LOOP AT it_ekpo INTO wa_ekpo.


WRITE:/10 wa_ekpo-ebeln,
30 wa_ekpo-matnr,
50 wa_ekpo-menge,
70 wa_ekpo-netpr,
ENDLOOP.

TOP-OF-PAGE.
WRITE:/40 ‘PO Details Report’ COLOR 1.
SKIP.
ULINE.

END-OF-PAGE.
WRITE:/10 ‘page no’, SY-PAGNO.

Ques: What is the flow of events?

Ans:
INITIALIZATION
AT SELECTION-SCREEN OUTPUT
START-OF-SELECTION

Ashok
SAP-ADV ABAP

Object:
PO and Tax Details Report

Input:
S_lifnr (so)
S_werks (so)
S_mtart (so)
S_burks (so)
S_bedat (so)

Output:
Po number
Po date
Vendor name
Vendor number
Po quantity
Unit price
Total price
Unit of measurement
Material code
Material description
VAT
CST
Freight

Processing Logic:
1. Get ebeln bedat matnr menge netpr meins netwr knumv ebelp lifnr from EKKO & EKPO
using inner-joins based on input
2. Pass lifnr of EKKO to lfa1 and get name1
3. Pass matnr of EKPO to MAKT and get maktx
4. Get kumv kposn kschl kwert from KONV by passing knumv of EKKO and ebelp of
EKKO

Solution:

REPORT ZMM_PO_TAX_DETAILS_REPORT NO STANDARD PAGE HEADING


LINE-SIZE 400 LINE-COUNT 20(4).

TABLES: EKPO, MAKT, KONV, LFA1, EKKO.

Ashok
SAP-ADV ABAP

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE t1.


SELECT-OPTIONS: s_lifnr FOR ekko-lifnr,
s_werks FOR ekko-werks,
s_mtart FOR ekko-mtart,
s_bedat FOR ekko-bedat.
PARAMETERS p_bukrs TYPE bukrs.
SELECTION-SCREEN: END OF BLOCK b1.

TYPES: BEGIN OF ty_ekko,


ebeln TYPE ebeln,
bedat TYPE bedat,
knumv TYPE knumv,
lifnr TYPE lifnr,
ebelp TYPE ebelp,
menge TYPE menge_D,
netpr TYPE netpr,
netwr TYPE netwr,
meins TYPE meins,
END OF ty_ekko.

TYPES: BEGIN OF ty_makt,


matnr TYPE matnr,
maktx TYPE maktx,
END OF ty_makt.

TYPES: BEGIN OF ty_lfa1,


lifnr TYPE lifnr,
name1 TYPE name1,
END OF ty_lfa1.

TYPES: BEGIN OF ty_konv,


knumv TYPE knumv,
kposv TYPE ebelp,
kschl TYPE kschl,
kwert TYPE kwert,
END OF ty_konv.
TYPES: BEGIN OF ty_final,
ebeln TYPE ebeln,
bedat TYPE bedat,
knumv TYPE knumv,
lifnr TYPE lifnr,
matnr TYPE matnr,
Ashok
SAP-ADV ABAP

ebelp TYPE kposn,


menge TYPE menge_D,
netpr TYPE netpr,
netwr TYPE netwr,
meins TYPE meins,
name1 TYPE name1,
maktx TYPE maktx,
vat TYPE kwert,
cst TYPE kwert,
frei TYPE kwert,
END OF ty-final.

DATA: wa_lfa1 TYPE ty_lfa1,


wa_ekko TYPE ty_ekko,
wa_makt TYPE ty_makt,
wa_final TYPE ty_final,
wa_konv TYPE ty_konv,
it_ekko TYPE TABLE OF ty_ekko,
it_makt TYPE TABLE OF ty_makt,
it_final TYPE TABLE OF ty_final,
it_konv TYPE TABLE OF ty_konv.

INITIALIZATION.
t1 = ‘Selection’.
p_bukrs = ‘1000’.

AT SELECTION-SCREEN.
LOOP AT SCREEN.
IF SCREEN-NAME EQ ‘p_bukrs’.
SCREEN-INPUT = 0.
MODIFY SCREEN.
ENDIF.
ENDLOOP.

START-OF-SELECTION.
PERFORM get_ekko.
PERFORM get_lfa1.
PERFORM get_makt.
PERFORM get_konv.
PERFORM combine_data.
PERFORM display_data.

Ashok
SAP-ADV ABAP

FORM get_ekko.
SELECT ekko~ebeln ekko~bedat ekko~knumv ekko~lifnr
ekpo~matnr ekpo~ebelp ekpo~menge ekpo~netpr ekpo~netwr ekpo~meins
INTO TABLE it_ekko FROM EKKO
INNER JOIN EKPO ON ekko~ebeln = ekpo~ebeln
WHERE ekko~lifnr IN s_lifnr
AND ekko~bukrs EQ p_bukrs
AND ekpo~mtart IN s_mtart
AND ekpo~bedat IN s_bedat.

IF SY-BUBRC NE 0.
MESSAGE ‘Enter valid input’ TYPE ‘E’ DISPLAY LIKE ‘I’.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM.

FORM get_lfa1.
IF NOT it_ekko IS INITIAL.
SELECT lifnr name1 FROM LFA1 INTO TABLE it_lfa1
WHERE lifnr = it_ekko-lifnr.
ENDIF.
ENDFORM.

FORM get_makt.
IF NOT it_ekko IS INITIAL.
SELECT matnr maktx FROM MAKT INOT TABLE it_makt
FOR ALL ENTRIES IN it_ekko
WHERE matnr = it_ekko-matnr
AND spras EQ ‘EN’.
ENDIF.
ENDFORM.

FORM combine_data.
LOOP AT it_ekko INTO wa_ekko.
wa_final-ebeln = wa_ekko-ebeln.
wa_final-bedat = wa_ekko-bedat.
wa_final-matnr = wa_ekko-matnr.
wa_final-menge = wa_ekko-menge.
wa_final-meins = wa_ekko-meins.
wa_final-netpr = wa_ekko-netpr.
wa_final-netwr = wa_ekko-netwr.
wa_final-knumv = wa_ekko-knumv.
Ashok
SAP-ADV ABAP

wa_final-ebelp = wa_ekko-ebelp.
wa_final-lifnr = wa_ekko-lifnr.

READ TABLE it_lfa1 INTO wa_lfa1 WITH KEY lifnr = wa_ekko-lifnr.


wa_final-name1 = wa_lfa1-name1.

READ TABLE it_makt INTO wa_makt WITH KEY matnr = wa_ekko-matnr.


wa_final-maktx = wa_makt-maktx.

APPEND wa_final TO it_final.


ENDLOOP.
ENDFORM.

FORM get_konv.
SORT it_final BY knumv ebelp.

IF NOT it_final IS INITIAL.


SELECT knumv kposn kschl kwert FROM KNOV INTO TABLE it_knov
FOR ALL ENTRIES IN it_final
WHERE knumv = it_final-knumv
AND kposn = it_final-ebelp.
ENDIF.

LOOP AT it_final INTO wa_final.


LOOP AT it_knov INTO wa_knov WHERE knumv = wa_final-knumv AND kposn
= wa_final-ebelp.
CASE wa_konv = kschl.
WHEN ‘STKO’.
wa_final-vat = wa_konv-kwert.
WHEN ‘PBXX’.
wa_final-cst = wa_konv-kwert.
WHEN ‘PBOO’.
wa_final-frei = wa_konv-kwert.
ENDCASE.
ENDLOOP.
MODIFY it_final FROM wa_final TRANSPORTING vat cst frei.
ENDLOOP.
ENDFORM.

FORM displaly_data.
LOOP AT it_final INTO wa_final.
WRITE:/10 wa_final-ebeln,
Ashok
SAP-ADV ABAP

20 wa_final-bedat,
30 wa_final-lifnr,
40 wa_final-name1,
50 wa_final-menge,
60 wa_final-netpr,
70 wa_final-netwr,
80 wa_final-meins,
90 wa_final-matnr,
100 wa_final-maktx,
110 wa_final-vat,
120 wa_final-cst,
130 wa_final-frei.
ENDLOOP.
ENDFORM.

Ashok
SAP-ADV ABAP

10-10-2014
KONV Table:
It is a conditions table for holding tax data.

Fields:
1. KNUMV------ condition number
2. KPOSN ------- item number for condition
3. KSCHL ------- condition / tax type
4. KAWRT------ condition base value
5. KBETR ------ condition rate
6. KWERT ----- condition value

Ashok
SAP-ADV ABAP

Assignment:
Po Delivery Status Report

Input:
S_Lifnr
S_Bedat
P_bukrs

Output:
Po number
Po date
Vendor number
Vendor name
Po quantity
Delivery quantity
Open quantity
Status

Processing Logic:
1. Get ebeln, bedat, lifnr from EKKO based on input
2. Get lifnr, name1 from LFA1 by passing lifnr of EKKO
3. Get ebeln, menge, wemng from EKET by passing ebeln of EKKO

Solution:
Go to SE38
Program: YMM_PO_DELIVERY_STATUS
Create
Package: ZABAP
Enter

Ashok
SAP-ADV ABAP

Interactive Reporting:
 In Classical Reporting the entire output is maintained in a single output list called Basic
List.
 In Interactive Reporting you will find N number of output lists called Interactive Lists
(or) Secondary Lists.
 In one interactive reporting you can maintain 20 secondary lists in sequence.

AT LINE-SELECTION:
It triggers whenever user interacts with a list

HIDE Keyword:
It holds the records selected by user in interactive reporting

System Fields in Interactive Reporting:


1. SY-LSIND
2. SY-LISEL

SY-LSIND:
It returns current list index

SY-LISEL:
It returns list of contents selected by user from output list

11-10-2014
GET CURSOR keyword:
If fetches the field name & value selected by user from output list

Syntax:
GET CURSOR FIELD <field name> VALUE <value>.

Ashok
SAP-ADV ABAP

SAP Memory:
Using SAP memory concept we can transfer the data from ABAP program to standard
application

SET PARAMETER keyword:

Syntax:
SET PARAMETER ID <id> FIELD <value>.

Example:
SET PARAMETER ID ‘mat’ FIELD f001.

TOP-OF-PAGE DURING LINE-SELECTION event:


Use this event for providing Headers in interactive reporting

Ashok
SAP-ADV ABAP

Object:
Invoice Details based on Customers

Input:
S_kunrg (so) ------ customer number
S_matnr (so)
S_werks (so)
S_ekdat (so) --------- bill date

Output:
Basic list screen 0
Customer Customer Customer Customer Telephone
number name city street number
C001
C002

When you click on C001 then the control will goes to Interactive list 1
Interactive list 1
Bill number Bill date Material Bill quantity Bill amount
code
400103 01.02.2014 100-101 150 120000
400104 10.10.2014 200-201 500 9500000
When you click on 400103 then the control will goes to Interactive list 2
When you click on 200-201 then the control will goes to T code VF03
Interactive list 2
Material code Material text Material type

VF03

Ashok
SAP-ADV ABAP

Solution:
Go to SE38
Program: ZSD_CUSTOMER_INVOICE_DETAILS
Create
Title: Customer Invoice Details Report
Type: Executable Program
Enter
Packge: ZABAP
Enter

TABLES: VBRK, VBRP, ADRC, KNA1.

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-000.


SELECT-OPTIONS: s_kunrg FOR vbrk-kunrg,
s_matnr FOR vbrk-matnr,
s_werks FOR vbrk-werks,
s_fkdat FOR vbrk-fkdat.
SELECTION-SCREEN: END OF BLOCK b1.

TYPES: BEGIN OF ty_vbrk,


Vbenl TYPE vbeln_vf,
fkdat TYPE fkdat,
matnr TYPE matnr,
netwr TYPE netwr,
END OF ty_vbrk.

TYPES: BEGIN OF ty_kna1,


kunnr TYPE kunnr,
name1 TYPE name1,
city1 TYPE ort01,
street TYPE stras,
tel_number TYPE ad_tlnmbr,
END OF ty_kna1.

TYPES: BEGIN OF ty_mara,


matnr TYPE matnr,
maktx TYPE maktx,
mtart TYPE mtart,
END OF ty_mara.

Ashok
SAP-ADV ABAP

DATA: wa_mara TYPE ty_mara,


wa_vbrk TYPE ty_vbrk,
wa_kna1 TYPE ty_kna1,
it_mara TYPE TABLE OF ty_mara,
it_vbrk TYPE TABLE OF ty_vbrk,
it_kna1 TYPE TABLE OF ty_kna1.

DATA: v_kunnr TYPE kunnr,


v_matnr TYPE matnr,
v_fnam(20) TYPE C,
v_fval(20) TYPE C.

SELECT kna1~kunnr kna1~name1 adrc~city1 adrc~street adrc~tel_number INTO


TABLE it_kna1 FROM KNA1 INNER JOIN ADRC
ON kna1~adrnr = adrc~addrnumber
WHEERE kna1~kunnr IN s_kunrg.

LOOP AT it_kna1 INTO wa_kna1.


WRITE:/10 wa_kna1-kunnr HOTSPOT,
20 wa_kna1-name1,
30 wa_kna1-city1,
40 wa_kna1-street,
50 wa_kna1-tel_number.
ENDLOOP.

AT LINE-SELECTION.

CASE SY-LSIND.
WHEN 1.
GET CURSOR FIELD v_fnam VALUE v_kunnr.

IF v_fnam EQ wa_kna1-kunnr.
CALL FUNCTION ‘CONVERSION_EXIT_ALPHA_INPUT’
EXPORTING
INPUT = v_kunnr
IMPORTING
OUTPUT = v_kunnr.

SELECT vbrk~vbeln vbrk~ekdat vbrp~matnr vbrp~fkimg vbrp~netwr INTO TABLE


it_vbrk FROM VBRK INNER JOIN VBRP
ON vbrk~vbeln = vbrp~vbeln
WHERE vbrk~kunrg EQ vbrp~v_kunnr
Ashok
SAP-ADV ABAP

AND vbrk~werks IN s_werks


AND vbrk~fkdat IN s_fkdat
AND vbrk~matnr IN s_matnr.

LOOP AT it_vbrk INTO wa_vbrk.


WRITE:/10 wa_vbrk-vbeln HOTSPOT,
20 wa_vbrk-fkdat,
30 wa_vbrk-matnr HOTSPOT,
40 wa_vbrk-fkimg,
50 wa_vbrk-netwr.
ENDLOOP.

WHEN 2.
GET CURSOR FIELD v_fnam VALUE v_matnr.

IF v_fnam EQ wa_vbrk-matnr.

SELECT mara~matnr makt~maktx mara~mtart INTO TABLE it_mara FROM MARA


INNER JOIN MAKT
ON mara~matnr = makt~matnr
WHERE mara~matnr EQ v_matnr
AND makt~spras EQ ‘EN’.

LOOP AT it_mara INTO wa_mara.


WRITE:/10 wa_mara-matnr,
20 wa_mara-maktx,
30 wa_mara-mtart.
ENDLOOP.

ELSEIF v_fnam EQ ‘wa_vbrk-vbeln’.


GET CURSOR FIELD v_fnam VALUE v_fval.

SET PARAMETER ID ‘VF’ FIELD v_fval.

CALL TRANSACTION ‘VF03' AND SKIP FIRST SCREEN.

ENDIF.
ENDCASE.

TOP-OF-PAGE.

WRITE:/50 ‘Customer Details’ COLOR 1.


Ashok
SAP-ADV ABAP

SKIP.
ULINE.

TOP-OF-PAGE DURING LINE-SELECTION.

CASE SY-LSIND.
WHEN 1.
WRITE:/50 ‘Customer Invoice Details’ COLOR 1.
SKIP.
ULINE.

WHEN 2.
WRITE:/50 ‘Materials Details’ COLOR 3.
SKIP.
ULINE.
ENDCASE.

Ashok
SAP-ADV ABAP

VBRK Table:
This table holds billing document header data

Fields:
1. VBELN ------- invoice number
2. FKDAT ------- billing type (domestic / export)
3. WAERK ------ document currency
4. VKOGR ------ sales organization
5. VTWEG ------ distribution channel
6. KALSM ------ pricing procedure
7. KNUMV ----- condition number

Link:
VBRK-KNUMV
KONV-KNUMV

8. *** FKDAT -------- billing date


9. GJAHR -------- physical year
10.RFBSK -------- status of bill
11.KURRF ------- exchange rate
12.ZTERM ------- payment terms
13.BUKRS ------- company code
14. *** KUNRG ------- customer number
15.SPART ------ division
16.KDGRP ----- customer group
17. *** FKSTO ------- bill document cancelled

VBRP Table:
This table holds billing document item data

Fields:
1. VBELN -------- invoice number
Link:
VBRK-VBELN
VBRP-VBELN

2. POSNR -------- item number


3. *** FKImG -------- invoice quantity
4. MEINS -------- unit of measurement
5. NETWR ------ bill amount
6. VGBEL ------ reference document number
Ashok
SAP-ADV ABAP

Note:
VGBEL is nothing but delivery document number

7. AGBEL ---------- sales order number


8. MATNR --------- material code
9. ARKTX --------- item description
10.CHARG -------- batch number
11.MATKL -------- material group
12.SPART --------- division
13.WERKS ------- Plant
14.VKBUR ------- sales office

ADRC Table:
It holds business addresses

Fields:
1. ADDRNUMBER ---------- address number
Link:
LFA1-ADRNR
KNA1-ADRNR
ADRC-ADDRNUMBER

2. NAME1 ------- name of customer / vendor


3. NAME_CO ------ C/O name
4. CITY1 -------- city
5. STREET ----- street
6. HOUSE_NUM1 ------ house number
7. STR_SUPPL1 -------- street 2
8. STR_SUPPL2 -------- street 3
9. STR_SUPPL3 -------- street 4
10.TEL_NUMBER ----- telephone number

Navigation for identifying parameter ids:


 Go to VF01
 Apply F1 on Billing Document
 You will find a pop-up, at bottom select Technical Information
 Note down parameter id: V1

Ashok
SAP-ADV ABAP

13-10-2014
ALV Reporting:
ABAP List Viewer
ALV is advanced reporting with additional features of reporting

Types of ALVs:
1. Traditional ALV
2. ALV with OOP (Object Oriented Programming)

Traditional ALV:
These are classified into 3 categories
1. Simple ALV
2. Blocked ALV
3. Hierarchal Sequential ALV

Advantages of ALV:
1. In traditional reporting you cannot maintain logos (pictures…………etc)
With ALV reporting you can maintain logos using ALV Function Modules
2. With ALV reporting you can improve performance of programming by avoiding
LOOP…..ENDLOOP
3. Using ALV reporting you can maintain Main Headings, Sub Headings……….etc
4. The main features of reporting are
i) Exporting Data
ii) Totals
iii) Sub Totals
iv) Filtering
v) Column Alignment
vi) Sorting ……………….etc
The above features requires large amount of coding with traditional reporting
Using ALV Function Modules you can minimize such coding

5. Layout Management
With traditional reporting you cannot select output fields dynamically (no layout management)
Suppose in a company there are 10 departments & each department users requires different
fields from the same report
Using layout management you can create & save his own layout

6. Using ALV reporting you can maintain data in Tabular format

Ashok
SAP-ADV ABAP

Simple ALV:
These are classified into 2 categories
1. Classical ALV
2. Interactive ALV

Classical ALV:
Object:
Open PO Details Report

Solution:
Go to SE38
Program: ZMM_PO_STATUS_DETAILS
Create
Title: PO Status Report
Type: Executable Program
Enter
Package: ZABAP
Enter

TABLES: LFA1, EKKO, EKET.

TYPE-POOLS SLIS.

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-000.


SELECT-OPTIONS: S_lifnr FOR lfa1-lifnr,
S_bukrs FOR ekko-bukrs,
S_bedat FOR ekko-bedat.
SELECTION-SCREEN: END OF BLOCK b1.

TYPES: BEGIN OF ty_final,


Ebeln TYPE ebeln,
bedat TYPE bedat,
eindt TYPE eindt,
lifnr TYPE lifnr,
name1 TYPE name1,
menge TYPE menge_D,
wemng TYPE wemng,
open TYPE menge_D,
status TYPE maktx,
END OF ty_final.
Ashok
SAP-ADV ABAP

Ashok
SAP-ADV ABAP

TYPES: BEGIN OF ty_ekko,


Ebeln TYPE ebeln,
bedat TYPE bedat,
lifnr TYPE lifnr,
END OF ty_ekko.

TYPES: BEGIN OF ty_lfa1,


lifnr TYPE lifnr,
name1 TYPE name1,
END OF ty_lfa1.

TYPES: BEGIN OF ty_eket,


Ebeln TYPE ebeln,
eindt TYPE eindt,
menge TYPE menge_D,
wemng TYPE wemng,
END OF ty_eket.

DATA: wa_ekko TYPE ty_ekko,


wa_lfa1 TYPE ty_lfa1,
wa_eket TYPE ty_eket,
wa_final TYPE ty_final,
it_ekko TYPE TABLE OF ty_ekko,
it_lfa1 TYPE TABLE OF ty_lfa1,
it_eket TYPE TABLE OF ty_eket,
it_final TYPE TABLE OF ty_final.

* provide ALV declaration


DATA: WA_FCAT TYPE SLIS_FIELDCAT_ALV,
WA_LAYOUT TYPE SLIS_LAYOUT_ALV,
IT_FCAT TYPE SLIS_T_FIELDCAT_ALV.

PERFORM get_ekko.
PERFORM get_lfa1.
PERFORM get_eket.
PERFORM fill_cat.
PERFORM combine_data.
PERFORM layout.
PERFORM display_data.

Ashok
SAP-ADV ABAP

FORM get_ekko.
SELECT ebeln bedat lifnr FROM EKKO INTO TABLE it_ekko
WHERE lifnr IN s_lifnr
AND bukrs IN s_bukrs
AND bedat IN s_bedat.
ENDFORM.

FORM get_lfa1.
IF it_ekko IS NOT INITIAL.
SELECT lifnr name1 FROM LFA1 INTO TABLE it_lfa1
FOR ALL ENTRIES IN it_ekko
WHERE lifnr = it_ekko-lifnr.
ENDIF.
ENDFORM.

FORM get_eket.
IF it_ekko IS NOT INITIAL.
SELECT ebeln menge wemng FROM EKET INTO TABLE it_eket
FOR ALL ENTRIES IN it_ekko
WHERE ebeln = it_ekko-ebeln.
ENDIF.
ENDFORM.

FORM combine_data.
LOOP AT it_eket INTO wa_eket.
wa_final-ebeln = wa_eket-ebeln.
wa_final-eindt = wa_eket-eindt.
wa_final-menge = wa_eket-menge.
wa_final-wemng = wa_eket-wemng.
wa_final-open = wa_eket-menge - wa_eket-wemng.

IF wa_eket_menge GT wa_eket_wemng.
wa_final-status = ‘Not delivered’.
ELSE.
wa_final-status = ‘delivered’.

READ TABLE it_ekko INTO wa_ekko WITH KEY ebeln = wa_eket-ebeln.


wa_final-lifnr = wa_eket-lifnr.
wa_final-bedat = wa_eket-bedat.

Ashok
SAP-ADV ABAP

READ TABLE it_lfa1 INTO wa_lfa1 WITH KEY lifnr = wa_ekko-lifnr.


wa_final-name1 = wa_eket-name1.
APPEND wa_final TO it_final.
ENDLOOP.
ENDFORM.

FORM fill_cat.
WA_FCAT-FIELDNAME = ‘ebeln’.
WA_FCAT-SELTEXT_M = ‘PO Number’.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘eindt’.
WA_FCAT-SELTEXT_M = ‘Delivery date’.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘lifnr’.
WA_FCAT-SELTEXT_M = ‘Vendor Number’.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘name1’.
WA_FCAT-SELTEXT_M = ‘Vendor name.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘menge’.
WA_FCAT-SELTEXT_M = ‘Quantity’.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘wemng’.
WA_FCAT-SELTEXT_M = ‘Delivery Quantity’.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘open’.
WA_FCAT-SELTEXT_M = ‘Open quantity’.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘status’.
WA_FCAT-SELTEXT_M = ‘Status’.
APPEND WA_FCAT TO IT_FCAT.

ENDFORM.

Ashok
SAP-ADV ABAP

FORM layout.

WA_LAYOUT-ZEBRA = ‘X’.
WA_LAYOUT-COLWIDTH_OPTIMIZE = ‘X’.

ENDFORM.

FORM display.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID ----- it returns current program name
IS_LAYOUT = WA_LAYOUT
IT_FIELDCAT = IT_FCAT
I_SAVE = ‘X’.
TABLES.
T_OUTTAB = it_final.
ENDFORM.

Ashok
SAP-ADV ABAP

14-10-2014
Note-1:
REUSE_ALV_GRID_DISPLAY
It is for display the data in ALV grid
The parameters are
1. Current program name
It is important for activating layout management & for displaying logos & headings

2. Layout work area

3. Field catalog internal table


4. I_CALLBACK_USER_COMMAND
It is for interactive purpose

5. I_STRUCTURE_NAME
For providing structure

6. I_BACKGROUND_ID
For maintaining background pictures

7. I_GRID_TITLE
For maintaining title in ALV grid
8. IT_SORT
For sorting data & for maintaining sub totals
9. I_SAVE
For saving layouts

10.IT_EVENTS
For events internal table

11.IS_PRINT
For deactivating (or) activating the print mode for PDF formats…………etc

12.T_OUTTAB
For output internal table

Note-2:
SLIS ------- is a Type Group

Type Group:
Ashok
SAP-ADV ABAP

 A type group is a group of similar structures & table types


 It you want to use type group types in your program it is mandatory to declare respective
type group with TYPE-POOLS keyword

Note-3:
SLIS_FIELDCAT_ALV is a standard SLIS structure with following fields
1. COL_POS ----------- column position
2. FIELDNAME ------ field name of output internal table
3. TABNAME --------- internal table name
4. CHECKBOX ------- with this option you can create check box for a specific field
5. JUST ----------------- it specifies left (or) right format for a specific field
6. NO_ZERO ---------- removes zeros from output list
7. EDIT_MASK ------- it hides the field data
8. NO_OUT ------------ removes a specific field catalog from output list
9. EMPHASIZE ------- it provides a specific default color for a field in ALV grid
10.OUTPUTLEN ------ specifies length (or) size for a catalog
11.SELTEXT_M ------ provides text for a particular field
12.FIX_COLOUMN
13.DECIMALS_OUT -- it round off a particular floating value by removing decimal values
from it
14.EDIT ------------------- by default the field catalogs in a layout are in display mode. Using
this option a field should be converted into change mode
15.HOTSPOT ------------ provides hand symbol
16.DO_SUM ----------- provides totals

Note-4:
SLIS_LAYOUT_ALV is a standard SLIS structure for maintaining layout settings for ALV
reporting
It is having following fields
1. ZEBRA --------- alternate colors
2. COLWIDTH _OPTIMIZE ------- it will optimize the width of field catalog automatically
based on domain length

Ashok
SAP-ADV ABAP

Object:
Restricted & Unrestricted stock details report material wise & plant wise

Input:
S_matnr (so)
S_werks (so)

Output:
Material code
Material description
Hyd uns
Hyd res
Pune uns
Pune res
Total uns
Total res
Total stock

Tables:
MARA
MAKT
MARD

Ques-1: What do you mean by restricted & unrestricted stock?


Ans:
The stock which is produced by production department & it is in Quality check (or) it is in hold
(or) stock returns is called restricted stock
The stock which is ready for sale is called unrestricted stock

*** Ques-2: This report is already provided by SAP (MMBE). Then why you created it?

Ans:
MMBE is providing materials details plant wise & storage location wise material by material
My client gave a requirement for viewing all restricted & unrestricted stock at one time

Solution:
Go to SE38
Program: ZMM_STOCK_DETAILS_REPORT
Create
Package: ZABAP
Ashok
SAP-ADV ABAP

Enter

TABLES: MARA, MAKT, MARD.

TYPE-POOLS SLIS.

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-000.


SELECT-OPTIONS: s_matnr FOR mara-matnr,
S_werks FOR mard-werks.
SELECTION-SCREEN: END OF BLOCK b1.

TYPES: BEGIN OF ty_mara,


Matnr TYPE matnr,
END OF ty_mara.

TYPES: BEGIN OF ty_mard,


Matnr TYPE matnr,
maktx TYPE maktx,
werks TYPE werks_D,
labst TYPE labst,
insme TYPE insme,
einme TYPE einme,
retme TYPE retme,
speme TYPE speme,
END OF ty_mard.

TYPES: BEGIN OF ty_final,


Matnr TYPE matnr,
maktx TYPE maktx,
labst1 TYPE labst,
rest1 TYPE labst,
labst2 TYPE labst,
rest2 TYPE labst,
totuns TYPE labst,
totres TYPE labst,
total TYPE labst,
END OF ty_final.

DATA: wa_mara TYPE ty_mara,


Wa_mard TYPE ty_mard,
Wa_mard1 TYPE ty_mard,
Wa_final TYPE ty_final,
Ashok
SAP-ADV ABAP

It_mara TYPE TABLE OF ty_mara,


It_mard TYPE TABLE OF ty_mard INITIAL SIZE 0,
It_mard1 TYPE TABLE OF ty_mard INITIAL SIZE 0,
It_final TYPE TABLE OF ty_fina1.

Ashok
SAP-ADV ABAP

MARD Table:
It holds storage location data for materials

Fields:
1. MATNR --------- material code
2. WERKS --------- plant
3. LGORT ---------- storage location
4. *** LABST ----- unrestricted stock
5. INSME ---------- stock in quality inspection
6. EINME ---------- total stock of all restricted stock
7. SPEME ---------- blocked stock
8. RETME --------- blocked stock returns
Note:
The above 4 fields combine to form restricted stock

9. LGPBE ---------- storage bin

Ashok
SAP-ADV ABAP

15-10-2014
SLIS_SORTINFO_ALV:
It is a standard ALV structure for sorting output list
It is having following fields
1. FIELDNAME -------------- field name for sorting
2. TABNAME ---------------- internal table name
3. UP --------------------------- ascending order
4. DOWN --------------------- descending order
5. SUBTOT ------------------ performs subtotals

SLIS_LISTHEADER:
It is a standard ALV structure for maintaining headings in output list
It is having following fields
1. TYP -------------- type of heading (H, S, A)
2. KEY ------------- text for heading in 20 characters
3. INFO ------------ text for heading in 60 characters

SLIS_ALV_EVENT:
It is a standard ALV structure for maintaining events
It is having following fields
1. NAME ----------- name of event
2. FORM ----------- subroutine name

16-10-2014
Navigation for Maintaining Logos:
 Go to Paint
 Design a picture
 Save it on desktop

 Go to OAER
 Class Name: Pictures
 Class Type: OT
 Object Key: ABAP
 Execute
 At bottom expand Standard Document Types
 Double click on Screen
 Select your Logo
 Enter
 Enter

Ashok
SAP-ADV ABAP

Assignment-1:
Monthly sales report based on customers

Input:
S_kunrg -------- customer code
S_werks -------- plant
S_fkart --------- bill type
S_spart --------- division
S_fkdat --------- bill date (01.04.2006 to 30.09.2006)
S_bukrs -------- company code

Output:
Customer code (vbrk-kunrg)
Customer name (kna1-name1)
Apr 06 (vbrp-fkdat)
May 06 (vbrp-fkdat)
Jun 06 (vbrp-fkdat)
July 06 (vbrp-fkdat)
Aug 06 (vbrp-fkdat)
Sep 06 (vbrp-fkdat)
Oct 06 (vbrp-fkdat)
Nov 06 (vbrp-fkdat)
Dec 06 (vbrp-fkdat)
Total

Solution:

Ashok
SAP-ADV ABAP

Assignment-2:
Sales analysis report

Input:
S_kunrg
S_werks
S_fkart
S_bukrs
S_fkdat
S_spart

Output:
Customer name
Today sales --------------- (15.10.2014)
Yesterday sales ---------- (15.10.2013)
Growth -------------------- ((Today sales – Yesterday sales) / Yesterday sales) * 100)
Mtd sales ------------------ (01.10.2014 to 15.10.2014)
Pmtd sales ---------------- (01.10.2013 to 15.10.2013)
Growth -------------------- ((Mtd sales – Pmtd sales) / Pmtd sales) * 100)
Ytd sales ------------------ (01.04.2014 to 15.10.2014)
Pytd sales ----------------- (01.04.2013 to 15.10.2013)
Growth -------------------- ((Ytd sales – Pytd sales) / Pytd sales) * 100)

Solution:

Ashok
SAP-ADV ABAP

Interactive ALV:
Syntax:
FORM <interactive> USING <ucomm> TYPE SY-UCOMM <sel> TYPE
SLIS_SELFIELD.
-------------
-------------
ENDFORM.

Requirement:
Customer master details

Input:
S_kunnr
Customer (button)
Address (button)

Output-1:
Customer number
Customer name
Customer group
Customer group description
Region
Region description
Division
Division description

Output-2:
Customer code
Customer name
Customer city
Customer postal code
Customer Street
Customer telephone number

Interactive Logic:
If I double click on customer code switch to XD03 application

Processing Logic-1:
1. Get kunnr name1 regio from kna1 table based on input
2. Get kunnr spart kdgrp from knvv table by passing kunnr of kna1 table
Ashok
SAP-ADV ABAP

3. Get spart vtext from tspat table by passing spart of knvv table
4. Get kdgrp ktext from t151t table by passing kdgrp of knvv table
5. Get bland bezei from t005u table by passing region of kna1 table

Processing Logic-2:
1. Provide inner join between kna1 table & adrc table (kunnr, name1, city1, post_code1,
street, tel_number)

Solution:
TABLES: KNA1, ADRC.

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-000.


SELECT-OPTIONS: s_kunnr FOR kna1-kunnr.
SELECTION-SCREEN: END OF BLOCK b1.

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


PARAMETERS: customer RADIOBUTTON GROUP rg1,
address RADIOBUTTON GROUP rg1.
SELECTION-SCREEN: END OF BLOCK b2.

TYPE-POOLS SLIS.

TYPES: BEGIN OF ty_kna1,


Kunnr TYPE kunnr,
Name1 TYPE name1,
Region TYPE region,
END OF ty_kna1.

TYPES: BEGIN OF ty_knvv,


Kunnr TYPE kunnr,
spart TYPE spart,
kdgrp TYPE kdgrp,
END OF ty_knvv.

TYPES: BEGIN OF ty_tspat,


spart TYPE spart,
vtext TYPE vtext,
END OF ty_tspat.

TYPES: BEGIN OF ty_t151t,


kdgrp TYPE kdgrp,
ktext TYPE ktext,
Ashok
SAP-ADV ABAP

END OF ty_t151t.

TYPES: BEGIN OF ty_t005u,


bland TYPE regio,
bezei TYPE bezei,
END OF ty_t005u.

TYPES: BEGIN OF ty_adrc,


Kunnr TYPE kunnr,
Name1 TYPE name1,
City1 TYPE ort01,
Post_code TYPE pstlz,
Street TYPE stras,
Tel_number TYPE ad_tlnmbr1,
END OF ty_adrc.

TYPES: BEGIN OF ty_final,


Kunnr TYPE kunnr,
Name1 TYPE name1,
Kdgrp TYPE kdgrp,
Ktext TYPE ktext,
Region TYPE regio,
Bezei TYPE bezei,
Vtext TYPE vtext,
END OF ty_final.

DATA: wa_kna1 TYPE ty_kna1,


wa_knvv TYPE ty_knvv,
wa_tspat TYPE ty_tspat,
wa_t151t TYPE ty_t151t,
wa_t005u TYPE ty_t005u,
wa_adrc TYPE ty_adrc,
wa_final TYPE ty_final,
it_kna1 TYPE TABLE OF ty_kna1,
it_knvv TYPE TABLE OF ty_knvv,
it_tspat TYPE TABLE OF ty_tspat,
it_t151t TYPE TABLE OF ty_t151t,
it_t005u TYPE TABLE OF ty_t005u,
it_adrc TYPE TABLE OF ty_adrc,
it_final TYPE TABLE OF ty_final.

DATA: WA_FCAT TYPE SLIS_FIELDCAT_ALV,


Ashok
SAP-ADV ABAP

IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,


IT_FCAT1 TYPE SLIS_T_FIELDCAT_ALV,
WA_EVENT TYPE SLIS_ALV_EVENT,
WA_LAYOUT TYPE SLIS_LAYOUT_ALV,
IT_EVENT TYPE SLIS_T_EVENT.

PERFORM get_kna1.
PERFORM get_knvv.
PERFORM get_tspat.
PERFORM get_t151t.
PERFORM get_t005u.
PERFORM get_adrc.
PERFORM combine_data.
PERFORM field_cat.
PERFORM layout.
PERFORM field_event.
PERFORM display_data.

FORM get_kna1.

SELECT kunnr name1 regio FROM KNA1 INTO TABLE it_kna1


WHERE kunnr IN s_kunnr.

IF SY-SUBRC NE 0.
MESSAGE ‘Enter valid input’ TYPE ‘E’ DISPLAY LIKE ‘I’.
LEAVE LIST-PROCESSING.
ENDIF.

ENDFORM.

FORM get_knvv.

IF NOT it_kna1 IS INITIAL.


SELECT kunnr spart kdgrp FROM KNVV INTO TABLE it_knvv
FOR ALL ENTRIES IN it_kna1
WHERE kunnr = it_kna1-kunnr.
ENDIF.

ENDFORM.

FORM get_tspat.

Ashok
SAP-ADV ABAP

IF NOT it_knvv IS INITIAL.


SELECT spart vtext FROM TSPAT INTO TABLE it_tspat
FOR ALL ENTRIES IN it_knvv
WHERE spart = it_knvv-spart
AND spras EQ ‘EN’.
ENDIF.

ENDFORM.

FORM get_t151t.

IF NOT it_knvv IS INITIAL.


SELECT kdgrp ktext FROM T151T INTO TABLE it_t151t
FOR ALL ENTRIES IN it_knvv
WHERE kdgrp = it_knvv-kdgrp
AND spras EQ ‘EN’.
ENDIF.

ENDFORM.

FORM get_t005u.

IF NOT it_kna1 IS INITIAL.


SELECT bland bezei FROM T005U INTO TABLE it_t005u
FOR ALL ENTRIES IN it_kna1
WHERE bland = it_kna1-regio
AND spras EQ ‘EN’.
ENDIF.

ENDFORM.

FORM get_adrc.

SELECT kna1~kunnr kna1~name1 adrc~city1 adrc~post_code1 adrc~street


adrc~tel_number INTO TABLE it_adrc
FROM KNA1 INNER JOIN ADRC
ON kna1~adrnr = adrc~addrnumber
WHERE kna1~kunnr IN s_kunnr.

ENDFORM.

FORM combine_data.
Ashok
SAP-ADV ABAP

LOOP AT it_kna1 INTO wa_kna1.


wa_final-kunnr = wa_kna1-kunnr.
wa_final-name1 = wa_kna1-name1.
wa_final-regio = wa_kna1-regio.

READ TABLE it_knvv INTO wa_knvv WITH KEY kunnr = wa_kna1-kunnr.


wa_final-kdgrp = wa_knvv-kdgrp.
wa_final-spart = wa_knvv-spart.

READ TABLE it_tspat INTO wa_tsapt WITH KEY spart = wa_knvv-spart.


wa_final-vtext = wa_tspat-vtext.

READ TABLE it_t005u INTO wa_t005u WITH KEY bland = wa_kna1-regio.


wa_final-bezei = wa_t005u-bezei.

READ TABLE it_t151t INTO wa_t151t WITH KEY kdgrp = wa_knvv-kdgrp.


wa_final-ktext = wa_t151t-ktext.

APPEND wa_final TO it_final.

ENDLOOP.
ENDFORM.

FORM FIELD_CAT.

WA_FCAT-FIELDNAME = ‘KUNNR’.
WA_FCAT-SELTEXT_M = ‘customer code’.
WA_FCAT-TABNAME = ‘it_final’.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘NAME1’.
WA_FCAT-SELTEXT_M = ‘name’.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘KDGRP’.
WA_FCAT-SELTEXT_M = ‘customer group’.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘KTEXT’.
WA_FCAT-SELTEXT_M = ‘customer group description’.
APPEND WA_FCAT TO IT_FCAT.

Ashok
SAP-ADV ABAP

WA_FCAT-FIELDNAME = ‘REGIO’.
WA_FCAT-SELTEXT_M = ‘region’.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘BEZEI’.
WA_FCAT-SELTEXT_M = ‘region description’.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘SPART’.
WA_FCAT-SELTEXT_M = ‘division’.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘VTEXT’.
WA_FCAT-SELTEXT_M = ‘division description’.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘KUNNR’.
WA_FCAT-SELTEXT_M = ‘customer code’.
WA_FCAT-TABNAME = ‘it_adrc’
APPEND WA_FCAT TO IT_FCAT1.

WA_FCAT-FIELDNAME = ‘NAME1’.
WA_FCAT-SELTEXT_M = ‘name’.
APPEND WA_FCAT TO IT_FCAT1.

WA_FCAT-FIELDNAME = ‘CITY1’.
WA_FCAT-SELTEXT_M = ‘city’.
APPEND WA_FCAT TO IT_FCAT1.

WA_FCAT-FIELDNAME = ‘POST_CODE1’.
WA_FCAT-SELTEXT_M = ‘postal code’.
APPEND WA_FCAT TO IT_FCAT1.

WA_FCAT-FIELDNAME = ‘STREET’.
WA_FCAT-SELTEXT_M = ‘street’.
APPEND WA_FCAT TO IT_FCAT1.

WA_FCAT-FIELDNAME = ‘TEL_NUMBER’.
WA_FCAT-SELTEXT_M = ‘tel_number’.
APPEND WA_FCAT TO IT_FCAT1.

ENDFORM.
Ashok
SAP-ADV ABAP

FORM field_event.

WA_EVENT-NAME = ‘USER_COMMAND’.
WA_EVENT-FORM = ‘INTERACTIVE’.
APPEND wa_event TO it_event.

ENDFORM.

FORM layout.

WA_LAYOUT-ZEBRA = ‘X’.
WA_LAYOUT-COLWIDTH_OPTIMIZE = ‘X’.

ENDFORM.

FORM display.

IF customer EQ ‘X’.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
I_CALLBACK_PROGRAM = SY-CPROG
IS_LAYOUT = WA_LAYOUT
IT_FIELDCAT = IT_FCAT
IT_EVENTS = IT_EVENT
I_SAVE = ‘X’
TABLES
T_OUTTAB = it_final.
ELSE.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
I_CALLBACK_PROGRAM = SY-CPROG
IS_LAYOUT = WA_LAYOUT
IT_FIELDCAT = IT_FCAT1
IT_EVENTS = IT_EVENT
I_SAVE = ‘X’
TABLES
T_OUTTAB = it_adrc.
ENDIF.

ENDFORM.
Ashok
SAP-ADV ABAP

FORM INTERACTIVE USING UCOMM TYPE SY-UCOMM sel TYPE


SLIS_SELFIELD.

IF SEL-SEL_TAB_FIELD = ‘it_final-kunnr’
OR SEL-SET_TAB_FIELD = ‘it_adrc-kunnr’.
SET PARAMETER ID ‘KUN’ FIELD SEL-VALUE.
CALL TRANSACTION ‘XD03’.
ENDIF.

ENDFORM.

Ashok
SAP-ADV ABAP

17-10-2014
Object:
Movement typewise sale production consumption details for materials

Input:
S_matnr ------------ material code
S_werks ------------ plant
S_bwart ------------ movement type
S_budat ------------ posting date

Input:
Material code
Material description
Plant
Production quantity
Sale quantity
Consumption quantity
Return quantity
Plant wise (button)
Segment wise (button)
All (button)

Plant wise Output:


Material code
Plant
Production
Sale
Consumption
Return quantity

Segment wise Output:


Division
Division description
Production
Sale
Consumption
Return quantity

All Output:
Material code
Ashok
SAP-ADV ABAP

Material description
Division
Division description
Plant
Production (101, 102 movement types)
Sale (601, 602 movement types)
Consumption (261, 262 movement types)
Return quantity (651, 652 movement types)

Tables:
MAKT
MKPF
MSEG

Solution:
ZNP_STOCK_MOVEMENT_DETAILS

TABLES: MARA, MKPF, MSEG.

TYPE-POOLS SLIS.

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITEL TEXT-000.


SELECT-OPTIONS: s_matnr FOR mara-matnr,
s_werks FOR mseg-werks,
s_budat FOR mkpf-budat,
s_bwart FOR mseg-bwart.
SELECTION-SCREEN: END OF BLOCK b1.

SELECTION-SCREEN: BEGIN OF LINE.


PARAMETERS: p_rb1 RADIOBUTTON GROUP rg1.
SELECTION-SCREEN COMMIT 10(20) TEXT-001.

PARAMETERS: p_rb2 RADIOBUTTON GROUP rg1.


SELECTION-SCREEN COMMIT 40(20) TEXT-002.

PARAMETERS: p_rb3 RADIOBUTTON GROUP rg1.


SELECTION-SCREEN COMMIT 70(20) TEXT-003.

SELECTION-SCREEN: END OF LINE.

TYPES: BEGIN OF ty_mara,


matnr TYPE matnr,
Ashok
SAP-ADV ABAP

spart TYPE spart,


maktx TYPE maktx,
END OF ty_mara.

TYPES: BEGIN OF ty_mseg,


mblnr TYPE mblnr,
budat TYPE budat,
matnr TYPE matnr,
werks TYPE werks_D,
shkzg TYPE shkzg,
bwart TYPE bwart,
menge TYPE menge_D,
END OF ty_mseg.

TYPES: BEGIN OF ty_mseg,


mblnr TYPE mblnr,
budat TYPE budat,
matnr TYPE matnr,
werks TYPE werks_D,
shkzg TYPE shkzg,
bwart TYPE bwart,
menge TYPE menge_D,
END OF ty_mseg.

TYPES: BEGIN OF ty_final,


matnr TYPE matnr,
maktx TYPE maktx,
werks TYPE werks_D,
spart TYPE spart,
vtext TYPE vtext,
prod TYPE menge_D,
sale TYPE menge_D,
cons TYPE menge_D,
return TYPE menge_D,
END OF ty_mseg.

TYPES: BEGIN OF ty_tspat,


spart TYPE spart,
vtext TYPE vtext,
END OF ty_tspat.

DATA: wa_mara TYPE ty_mara,


Ashok
SAP-ADV ABAP

wa_mseg TYPE ty_mseg,


wa_mseg1 TYPE ty_mseg,
wa_out TYPE ty_final,
wa_tspat TYPE ty_tspat,
wa_final TYPE ty_final,
wa_final1 TYPE ty_final,
wa_final2 TYPE ty_final,
it_mara TYPE TABLE OF ty_mara,
it_mseg TYPE TABLE OF ty_mseg INITIAL SIZE 0,
it_mseg1 TYPE TABLE OF ty_mseg INITIAL SIZE 0,
it_final TYPE TABLE OF ty_final INITIAL SIZE 0,
it_final1 TYPE TABLE OF ty_final INITIAL SIZE 0,
it_final2 TYPE TABLE OF ty_final INITIAL SIZE 0,
it_out TYPE TABLE OF ty_final INITIAL SIZE 0,
it_tspat TYPE TABLE OF ty_tspat.

DATA: WA_FCAT TYPE SLIS_FIELDCAT_ALV,


IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,
IT_FCAT1 TYPE SLIS_T_FIELDCAT_ALV,
IT_FCAT2 TYPE SLIS_T_FIELDCAT_ALV,
WA_LAYOUT TYPE SLIS_LAYOUT_ALV,
WA_EVENT TYPE SLIS_ALV_EVENT,
IT_EVENT TYPE SLIS_T_EVENT.

START-OF-SELECTION.

PERFORM get_mara.
PERFORM get_mseg.
PERFORM get_tspat.
PERFORM combine_data.
PERFORM combine_data1.
PERFORM fill_cat.
PERFORM layout.
PERFORM fill_event.
PERFORM display_data.

FORM get_mara.

SELECT mara~matnr mara~spart makt~maktx INTO TABLE it_mara FROM MARA


INNER JOIN MAKT
ON mara~matnr = makt~matnr
WHERE mara~matnr IN s_matnr
Ashok
SAP-ADV ABAP

AND spras EQ ‘EN’.

ENDFORM.

FORM get_mseg.

SELECT mkpf~mblnr mkpf~budat mseg~matnr mseg~werks mseg~shkzg mseg~bwart


mseg~menge INTO TABLE it_mseg FROM MKPF INNER JOIN MSEG
ON mkpf~mblnr = mseg~mblnr
WHERE mkpf~budat IN s_budat
AND mseg~werks IN s_werks
AND mseg~matnr IN s_matnr
AND mseg~bwart IN s_bwart.

ENDFORM.

FORM get_tspat.

IF NOT it_mara IS INITIAL.


SELECT spart vtext FROM TSPAT INTO TABLE it_tspat
FOR ALL ENTRIES IN it_mara
WHERE spart = it_mara-spart
AND spras EQ ‘EN’.
ENDIF.

ENDFORM.

FORM combine_data.

LOOP AT it_mara INTO wa_mara.


wa_final-matnr = wa_mara-matnr.
wa_final-spart = wa_mara-spart.
wa_final-maktx = wa_mara-maktx.

READ TABLE it_tspat INTO WITH KEY spart = wa_mara-spart.


wa_final-vtext = wa_tspat-vtext.

APPEND wa_final = it_final.


ENDLOOP.

ENDFORM.

Ashok
SAP-ADV ABAP

FORM combine_data1.

SORT it_mseg BY matnr werks.

it_mseg1[ ] = it_mseg[ ].

DELETE ADJACENT DUPLICATES FROM it_mseg1 COMPARING matnr werks.

LOOP AT it_mseg1 INTO wa_mseg1.


LOOP AT it_mseg INTO wa_mseg WHERE matnr = wa_mseg1-matnr
AND werks = wa_mseg1-werks.
READ TABLE it_mara INTO wa_mara WITH KEY matnr = wa_mseg-matnr.

IF wa_mseg-bwart EQ ‘101’.
wa_final-prod = wa_mara-prod + wa_mseg-menge.
ENDIF.

IF wa_mseg-bwart EQ ‘102’.
wa_mseg-menge = (-1) * wa_mseg-menge.
wa_final-prod = wa_mara-prod + wa_mseg-menge.
ENDIF.

IF wa_mseg-bwart EQ ‘602’.
wa_final-sale = wa_mara-sale + wa_mseg-menge.
ENDIF.

IF wa_mseg-bwart EQ ‘601’.
wa_mseg-menge = (-1) * wa_mseg-menge.
wa_final-sale = wa_mara-sale + wa_mseg-menge.
ENDIF.

IF wa_mseg-bwart EQ ‘262’.
wa_final-cons = wa_mara-cons + wa_mseg-menge.
ENDIF.

IF wa_mseg-bwart EQ ‘261’.
wa_mseg-menge = (-1) * wa_mseg-menge.
wa_final-cons = wa_mara-cons + wa_mseg-menge.
ENDIF.

IF wa_mseg-bwart EQ ‘651’.
Ashok
SAP-ADV ABAP

wa_final-return = wa_mara-return + wa_mseg-menge.


ENDIF.

IF wa_mseg-bwart EQ ‘652’.
wa_mseg-menge = (-1) * wa_mseg-menge.
wa_final-return = wa_mara-return + wa_mseg-menge.
ENDIF.

ENDLOOP.

wa_final-werks = wa_mseg-werks.

MODIFY it_final FROM wa_final TRANSPORTING werks prod cons sale return
WHERE matnr = wa_mseg-matnr.

CLEAR wa_final.

ENDLOOP.

ENDFORM.

FORM fill_cat.

WA_FCAT-FIELDNAME = ‘MATNR’.
WA_FCAT-TABNAME = ‘it_final’.
WA_FCAT-SELTEXT_M = ‘Material Code’.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘MAKTX’.
WA_FCAT-TABNAME = ‘it_final’.
WA_FCAT-SELTEXT_M = ‘Material description’.
APPEND WA_FCAT TO IT_FCAT.
WA_FCAT-FIELDNAME = ‘WERKS’.
WA_FCAT-TABNAME = ‘it_final’.
WA_FCAT-SELTEXT_M = ‘Plant’.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘VTEXT’.
WA_FCAT-TABNAME = ‘it_final’.
WA_FCAT-SELTEXT_M = ‘Segment’.
APPEND WA_FCAT TO IT_FCAT.

Ashok
SAP-ADV ABAP

WA_FCAT-FIELDNAME = ‘PROD’.
WA_FCAT-TABNAME = ‘it_final’.
WA_FCAT-SELTEXT_M = ‘Production’.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘SALE’.
WA_FCAT-TABNAME = ‘it_final’.
WA_FCAT-SELTEXT_M = ‘Sale’.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘CONS’.
WA_FCAT-TABNAME = ‘it_final’.
WA_FCAT-SELTEXT_M = ‘Consumption’.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘RETURN’.
WA_FCAT-TABNAME = ‘it_final’.
WA_FCAT-SELTEXT_M = ‘Returns’.
APPEND WA_FCAT TO IT_FCAT.

* for plant wise


WA_FCAT-FIELDNAME = ‘MATNR’.
WA_FCAT-TABNAME = ‘it_final’.
WA_FCAT-SELTEXT_M = ‘Material Code’.
APPEND WA_FCAT TO IT_FCAT1.

WA_FCAT-FIELDNAME = ‘MAKTX’.
WA_FCAT-TABNAME = ‘it_final’.
WA_FCAT-SELTEXT_M = ‘Material description’.
APPEND WA_FCAT TO IT_FCAT1.
WA_FCAT-FIELDNAME = ‘WERKS’.
WA_FCAT-TABNAME = ‘it_final’.
WA_FCAT-SELTEXT_M = ‘Plant’.
APPEND WA_FCAT TO IT_FCAT1.

WA_FCAT-FIELDNAME = ‘PROD’.
WA_FCAT-TABNAME = ‘it_final’.
WA_FCAT-SELTEXT_M = ‘Production’.
APPEND WA_FCAT TO IT_FCAT1.

WA_FCAT-FIELDNAME = ‘SALE’.
WA_FCAT-TABNAME = ‘it_final’.
Ashok
SAP-ADV ABAP

WA_FCAT-SELTEXT_M = ‘Sale’.
APPEND WA_FCAT TO IT_FCAT1.

WA_FCAT-FIELDNAME = ‘CONS’.
WA_FCAT-TABNAME = ‘it_final’.
WA_FCAT-SELTEXT_M = ‘Consumption’.
APPEND WA_FCAT TO IT_FCAT1.

WA_FCAT-FIELDNAME = ‘RETURN’.
WA_FCAT-TABNAME = ‘it_final’.
WA_FCAT-SELTEXT_M = ‘Returns’.
APPEND WA_FCAT TO IT_FCAT1.

* for segment wise


WA_FCAT-FIELDNAME = ‘MATNR’.
WA_FCAT-TABNAME = ‘it_final’.
WA_FCAT-SELTEXT_M = ‘Material Code’.
APPEND WA_FCAT TO IT_FCAT2.

WA_FCAT-FIELDNAME = ‘MAKTX’.
WA_FCAT-TABNAME = ‘it_final’.
WA_FCAT-SELTEXT_M = ‘Material description’.
APPEND WA_FCAT TO IT_FCAT2.

WA_FCAT-FIELDNAME = ‘VTEXT’.
WA_FCAT-TABNAME = ‘it_final’.
WA_FCAT-SELTEXT_M = ‘Segment’.
APPEND WA_FCAT TO IT_FCAT2.

WA_FCAT-FIELDNAME = ‘PROD’.
WA_FCAT-TABNAME = ‘it_final’.
WA_FCAT-SELTEXT_M = ‘Production’.
APPEND WA_FCAT TO IT_FCAT2.

WA_FCAT-FIELDNAME = ‘SALE’.
WA_FCAT-TABNAME = ‘it_final’.
WA_FCAT-SELTEXT_M = ‘Sale’.
APPEND WA_FCAT TO IT_FCAT2.

WA_FCAT-FIELDNAME = ‘CONS’.
WA_FCAT-TABNAME = ‘it_final’.
WA_FCAT-SELTEXT_M = ‘Consumption’.
Ashok
SAP-ADV ABAP

APPEND WA_FCAT TO IT_FCAT2.

WA_FCAT-FIELDNAME = ‘RETURN’.
WA_FCAT-TABNAME = ‘it_final’.
WA_FCAT-SELTEXT_M = ‘Returns’.
APPEND WA_FCAT TO IT_FCAT2.

ENDFORM.

FORM layout.

WA_LAYOUT-ZEBRA = ‘X’.
WA_LAYOUT-COLWIDTH_OPTIMIZE = ‘X’.

ENDFORM.

FORM fill_event.

WA_EVENT-NAME = ‘USER-COMMAND’.
WA_EVENT-FORM = ‘INTERACTIVE’.
APPEND wa_event TO it_event.

ENDFORM.

FORM display_data.

IF p_rb1 EQ ‘X’.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IT_FIELDCAT = IT_FCAT1
IS_LAYOUT = WA_LAYOUT
IT_EVENTS = IT_EVENT
TABLES
T_OUTTAB = IT_FINAL.

ELSEIF p_rb2 EQ ‘X’.

SORT it_final BY matnr spart.

it_final1[ ] = it_final.

Ashok
SAP-ADV ABAP

DELETE ADJACENT DUPLICATES FROM it_final1 COMPARING matnr spart.

LOOP AT it_final1 INTO wa_final1.


LOOP AT it_final INTO wa_final WHERE matnr = wa_final1-matnr
AND spart = wa_final1-spart.
wa_out-prod = wa_out-prod + wa_final-prod.
wa_out-sale = wa_out-sale + wa_final-sale.
wa_out-cons = wa_out-cons + wa_final-cons.
wa_out-return = wa_out-return + wa_final-return.
ENDLOOP.
wa_out-matnr = wa_final-matnr.
wa_out-maktx = wa_final-maktx.
wa_out-vtext = wa_final-vtext.
APPEND wa_out TO it_out.
CLEAR wa_out.
ENDLOOP.

CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’


EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IT_FIELDCAT = IT_FCAT2
IS_LAYOUT = WA_LAYOUT
IT_EVENTS = IT_EVENT
TABLES
T_OUTTAB = IT_OUT.

ELSEIF p_rb3 EQ ‘X’.


CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IT_FIELDCAT = IT_FCAT
IS_LAYOUT = WA_LAYOUT
IT_EVENTS = IT_EVENT
TABLES
T_OUTTAB = IT_FINAL.

ENDIF.

ENDFORM.

FORM INTERACTIVE USING UCOMM TYPE SY-UCOMM


SEL TYPE SLIS_SELFIELD
Ashok
SAP-ADV ABAP

REFRESH it_final2.

IF SEL-SEL_TAB_FIELD EQ ‘it_final-matnr’.
LOOP AT it_final INTO wa_final WHERE matnr = SEL-VALUE.
APPEND wa_final TO it_final2.
ENDLOOP.
ENDIF.

CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’


EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IT_FIELDCAT = IT_FCAT
IS_LAYOUT = WA_LAYOUT
TABLES
T_OUTTAB = IT_FINAL2.

ENDFORM.

Ashok
SAP-ADV ABAP

Object:
Sales register report

Input:
S_fkart --------- billing type
S_vbeln -------- billing number
S_werks
S_matnr
S_fkdat -------- billing date
S_bukrs
S_spart

Output:
Invoice number
Bill date
Customer number
Customer name
Material number
Material description
Bill quantity
Bill amount
Customer PO number
Customer PO date
Excise number
Excise date
VAT
CST
CForm number
CForm date
Issue date
Delivery number
Sales order number

Note:
In real time vendor bill sell goods to customer to different states. To avail CST benefits
customer will provide a CForm to vendor which is entered into SAP system through report

Processing Logic:
1. Get vbeln fkdat kunrg matnr fkimg netwr knumv posnr based on input from
vbrk & vbrp tables
Ashok
SAP-ADV ABAP

2. Get kunnr name from kna1 by processing kunrg of vbrk


3. Get matnr maktx from makt by passing matnr of vbrk
4. Get exnum exdat rdoc from j_1iexchdr by passing vbeln of vbrk
5. Get vbeln vbelv from vbfa by passing vbeln of vbrk where vbtyp_v = ‘c’
6. Get bstkd bstdk from vbkd by passing vbelv of vbfa
7. Get vbelv from vbfa by passing vbeln of vbrk where vbtyp_v = ‘j’
8. Get knumv kschl kposn kwert from konv by passing knumv of vbrk and posnr of
vbrk
9. Get vbeln cno cdate idate from zsd_forms by passing vbeln of vbrk

Solution:
ZSD_SALES_REGISTER_SJU

Ashok
SAP-ADV ABAP

SD Flow:
Inquiry
Sales order
Delivery
Invoice

 If sub sequent is given (invoic) & I want preceding (sales order)


SELECT vbelv FROM VBFA INTO TABLE it WHERE vbeln = it1_vbeln AND
VBTYP_V = ‘C’.

 If sub sequent is given (invoic) & I want preceding (delivery)


SELECT vbelv FROM VBFA INTO TABLE it WHERE vbeln = it1_vbeln AND
VBTYP_V = ‘I’.

 If preceding is given (sales order) & I want sub sequent (invoice)


SELECT vbeln FROM VBFA INTO TABLE it WHERE vbelv = it1_order AND
VBTYP_N = ‘M’.

 If preceding is given (sales order) & I want sub sequent (delivery)


SELECT vbeln FROM VBFA INTO TABLE it WHERE vbelv = it1_order AND
VBTYP_N = ‘J’.

Ashok
SAP-ADV ABAP

18-10-2014
J_1IEXCHDR Table:
It is also called Excise table
It holds invoice header data

Fields:
1. DOCYR ---------- year
2. DOCNO --------- excise document number
3. BUKRS ---------- company code
4. WERKS ---------- plant
5. EXGRP ---------- excise group
6. EXNUM --------- excise number
7. EXDAT --------- excise date
8. LIFNR ----------- vendor number
9. EXBED --------- basic excise duty
10.EXSED --------- special excise duty
11.EXAED -------- additional excise duty
12.CESS ----------- cess amount
13.RDOC --------- reference document (invoice)
Link:
VBRK-vbeln
J_1IEXCHDR-rdoc

VBFA Table:
It holds sales document flow data
In sales document flow, if one document is given you can get other document details from this
table

Fields:
1. VBELN ---------- subsequent document number
2. VBELV ---------- preceding document number
3. VBTYP_N ------ document category of subsequent document
4. RFMNG --------- reference quantity
5. MEINS ---------- unit of measurement
6. RFWRT --------- reference value
7. VBTYP_V ----- document category of preceding document

Ashok
SAP-ADV ABAP

VBKD Table:
It holds sale document business data

Fields:
1. VBELN -------------- sales order number
2. KDGRP ------------- customer group
3. LCNUM ------------ letter of credit number
4. BSTKD ------------- customer PO number
5. BSTKD ------------- customer PO date

Assignment:
Material wise Invoice & Realization details

Input:
S_matnr
S_werks
S_exdat -------invoice date

Tables:
VBRK
VBRD
MAKT
TSPAT

Output:
Material number
Material description
Division description
Remarks
Jan
Feb
March
Total

Solution:

Ashok
SAP-ADV ABAP

20-10-2014
Blocked ALV:
 Using Blocked ALVs you can display multiple lists at one place
 In real time we are using blocked alvs in few scenarios such as if you want to display
production affiance of different machines of one furnace in one Output list
 If client requires invoice details based on customers, materials, segments at one place we
have to work with Blocked ALVs

Function Modules for Blocked ALVs:


1. REUSE_ALV_BLOCK_LIST_INIT
2. REUSE_ALV_BLOCK_LIST_APPEND
3. REUSE_ALV_BLOCK_LIST_DISPLAY

REUSE_ALV_BLOCK_LIST_INIT:
It initializes lists in blocked alvs

REUSE_ALV_BLOCK_LIST_APPEND:
This function module
1. Maintains field catalogs
2. Maintains data in list
3. Append field catalogs & data with layout

REUSE_ALV_BLOCK_LIST_DISPLAY:
It displays data in list in blocked alvs

Ashok
SAP-ADV ABAP

Requirement:
Invoice details Customer wise, Material wise & Segment wise

Input:
S_kunrg
S_matnr
S_werks
S_bukrs
S_fkdat

Output:
Heading
Customer number Name Total quantity Total value

Heading
Material code Material description Total quantity Total value

Heading
Segment Segment description total quantity Total value

Tables:
VBRK
VBRP
MAKT
KNA1
TSPAT

Solution:
ZSD_AUMR_SALES_CUS_MAT_DIV

Ashok
SAP-ADV ABAP

Note:
REUSE_ALV_BLOCK_LIST_ALV:
It will initialize blocks in blocked alvs
You should pass current program name to this function module

REUSE_ALV_BLOCK_LIST_APPEND:
It maintains blocks with field catalogs with data &
Append field catalog & data to layout
The parameters are
1. Layout work area
2. Field catalog internal table
3. Internal table name
4. Events internal table
5. Output internal table

REUSE_ALV_BLOCK_LIST_DISPLAY:
It will displays the data in output list
No need to pass any parameters to this function module

Note:
In layout work area you should pass INFO-FIELDNAME for displaying row with a specific
color given in output list

Ashok
SAP-ADV ABAP

*** Hierarchal Sequential ALVs:


Using hierarchal sequential alvs you can display application data in hierarchal format

Requirement:
PO Price Change Report

Input:
S_lifnr
S_matnr
S_mtart
S_werks
S_matkl
S_bedat

Output:
Material code Material description
Sno PO number PO date Vendor name Unit of measurement Quantity

Processing Logic:
1. Get matnr from MARA based on input
2. Get ebeln bedat meins menge matnr netpr lifnr by passing matnr of MARA & based
on input
3. Get lifnr name1 from LFA1 by passing lifnr of EKKO

*** Ques: Explain procedure of working with Hierarchal ALVs?


Answer:
 In Hierarchal Sequential ALVs we have to create 2 internal tables
 One for Header data (it_final1) & another for Item data (it_final)
 Both these internal tables should have a common field called KEY field
 In Header internal table the Key field should be unique
 In Item internal table the Key field should having number of items based on that unique
key
 Pass these two internal tables to a function module called
REUSE_ALV_HIERSEQ_LIST_DISPLAY

Solution:
ZMM_PO_PRICE_CHANGE_REPORT

TYPE-POOLS SLIS.

Ashok
SAP-ADV ABAP

TABLES: EKKO, EKPO, LFA1, MARA.


SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-000.
SELECT-OPTIONS: s_lifnr FOR lfa1-lifnr,
s_matnr FOR mara-matnr,
s_bukrs FOR ekko-bukrs,
s_mtart FOR ekpo-mtart,
s_werks FOR ekpo-werks,
s_matkl FOR ekpo-matkl,
s_bedat FOR ekko-bedat.
SELECTION-SCREEN:END OF BLOCK b1.

TYPES: BEGIN OF ty_mara,


matnr TYPE matnr,
maktx TYPE maktx,
END OF ty_mara.

TYPES: BEGIN OF ty_lfa1,


lifnr TYPE lifnr,
name1 TYPE name1,
END OF ty_lfa1.

TYPES: BEGIN OF ty_ekko,


ebeln TYPE ebeln,
bedat TYPE bedat,
matnr TYPE matnr,
meins TYPE meins,
menge TYPE menge_D,
netpr TYPE netpr,
lifnr TYPE lifnr,
END OF ty_ekko.
TYPES: BEGIN OF ty_final,
key TYPE I,
sno TYPE I,
matnr TYPE matnr,
maktx TYPE maktx,
ebeln TYPE ebeln,
bedat TYPE bedat,
lifnr TYPE lifnr,
name1 TYPE name1,
meins TYPE meins,
menge TYPE menge_D,
netpr TYPE netpr,
Ashok
SAP-ADV ABAP

END OF ty_final.
DATA: wa_lfa1 TYPE ty_lfa1,
wa_mara TYPE ty_mara,
wa_ekko TYPE ty_ekko,
wa_final TYPE ty_final,
it_lfa1 TYPE TABLE OF ty_lfa1,
it_mara TYPE TABLE OF ty_mara,
it_ekko TYPE TABLE OF ty_ekko,
it_final TYPE TABLE OF ty_final,
it_final1 TYPE TABLE OF ty_final.

DATA: cnt TYPE I,


count TYPE I VALUE 1.

DATA: WA_FCAT TYPE SLIS_FIELDCAT_ALV,


WA_SORT TYPE SLIS_SORTINFO_ALV,
WA_LAYOUT TYPE SLIS_LAYOUT_ALV,
WA_EVENT TYPE SLIS_ALV_EVENT,
IT_EVENT TYPE SLIS_T_EVENT,
IT_SORT TYPE SLIS_T_SORTINFO_ALV,
WA_KEY TYPE SLIS_KEYINFO_ALV,
IT_FCAT TYPE SLIS_T_FIELDCAT_ALV.

PERFORM get_mara.
PERFORM get_ekko.
PERFORM get_lfa1.
PERFORM combine_data.
PERFORM layout.
PERFORM sort.
PERFORM fill_cat.
PERFORM key.
PERFORM display_hierseq.

FORM get_mara.

SELECT mara~matnr makt~maktx INTO TABLE it_mara FROM MARA INNER


JOIN MAKT
ON mara~matnr = makt~matnr
WHERE mara~matnr IN s_matnr
AND spras EQ ‘EN’.

ENDFORM.
Ashok
SAP-ADV ABAP

FORM get_ekko.

IF NOT it_mara IS INITIAL.


SELECT ekko~ebeln ekko~bedat ekpo~matnr ekpo~meins ekpo~menge ekpo~netpr
ekpo~lifnr INTO TABLE it_ekko FROM EKKO INNER JOIN EKPO
ON ekko~ebeln = ekpo~ebeln
FOR ALL ENTRIES IN it_mara
WHERE ekpo~matnr = it_mara-matnr
AND ekpo~werks IN s_werks
AND ekpo~bukrs IN s_bukrs
AND ekpo~mtart IN s_mtart
AND ekpo~matkl IN s_matkl
AND ekko~lifnr IN s_lifnr
AND ekko~bedat IN s_bedat.
ENDIF.

ENDFORM.

FORM get_lfa1.

IF NOT it_ekko IS INITIAL.


SELECT lifnr name1 FROM LFA1 INTO TABLE it_lfa1
FOR ALL ENTRIES IN it_ekko
WHERE lifnr = it_ekko-lifnr.
ENDIF.

ENDFORM.

FORM combine_data.

LOOP AT it_mara INTO wa_mara.


LOOP AT it_ekko INTO wa_ekko WHERE matnr = wa_mara-matnr.
wa_final-matnr = wa_ekko-matnr.
wa_final-ebeln = wa_ekko-ebeln.
wa_final-bedat = wa_ekko-bedat.
wa_final-meins = wa_ekko-meins.
wa_final-menge = wa_ekko-menge.
wa_final-netpr = wa_ekko-netpr.

READ TABLE it_lfa1 INTO wa_lfa1 WITH KEY lifnr = wa_ekko-lifnr.


wa_final-name1 = wa_lfa1-name1.
Ashok
SAP-ADV ABAP

wa_final-maktx = wa_mara-maktx.
cnt = cnt + 1.
wa_final-sno = cnt.
wa_final-key = count.
APPEND wa_final TO it_final.
ENDLOOP.

CLEAR cnt.
count = count + 1.
ENDLOOP.

ENDFORM.

FORM fill_cat.

WA_FCAT-FIELDNAME = ‘MATNR’.
WA_FCAT-SELTEXT_M = ‘Material Code’.
WA_FCAT-TABNAME = ‘it_final’.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘MAKTX’.
WA_FCAT-SELTEXT_M = ‘Material Description’.
WA_FCAT-TABNAME = ‘it_final’.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘SNO’.
WA_FCAT-SELTEXT_M = ‘S.no’.
WA_FCAT-TABNAME = ‘it_final’.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘EBELN’.
WA_FCAT-SELTEXT_M = ‘PO Number’.
WA_FCAT-TABNAME = ‘it_final’.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘BEDAT’.
WA_FCAT-SELTEXT_M = ‘PO Date’.
WA_FCAT-TABNAME = ‘it_final’.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘LIFNR’.
WA_FCAT-SELTEXT_M = ‘Vendor Code’.
Ashok
SAP-ADV ABAP

WA_FCAT-TABNAME = ‘it_final’.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘NAME1’.
WA_FCAT-SELTEXT_M = ‘Name’.
WA_FCAT-TABNAME = ‘it_final’.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘MEINS’.
WA_FCAT-SELTEXT_M = ‘Unit of Measurement’.
WA_FCAT-TABNAME = ‘it_final’.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘MENGE’.
WA_FCAT-SELTEXT_M = ‘PO Quantity’.
WA_FCAT-TABNAME = ‘it_final’.
WA_FCAT-DO_SUM = ‘X’.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘NETPR’.
WA_FCAT-SELTEXT_M = ‘Unit Price’.
WA_FCAT-TABNAME = ‘it_final’.
APPEND WA_FCAT TO IT_FCAT.

ENDFORM.

FORM sort.

WA_SORT-FIELDNAME = ‘MATNR’.
WA_SORT-TABNAME = ‘it_final1’.
WA_SORT-SUBTOT = ‘X’.
WA_SORT-UP = ‘X’.
APPEND wa_sort TO it_sort.

ENDFORM.

FORM key.

WA_KEY-HEADER01 = ‘KEY’.
WA_KEY-ITEM01 = ‘KEY’.

ENDFORM.
Ashok
SAP-ADV ABAP

FORM layout.

WA_LAYOUT-ZEBRA = ‘X’.
WA_LAYOUT-COLWIDTH_OPTIMIZE = ‘X’.

ENDFORM.

FORM display-hierseq.

it_final1[ ] = it_final[ ].

DELETE ADJACENT DUPLICATES FROM it_final1 COMPARING key.

CALL FUNCTION ‘REUSE_ALV_HIERSEQ_LIST_DISPLAY’


EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT = WA_LAYOUT
IT_FIELDCAT = IT_FCAT
IT_SORT = IT_SORT
I_SAVE = ‘X’
I_TABNAME _HEADER = ‘it_final1’
I_TABNAME_ITEM = ‘it_final’
IS_KEYINFO = wa_key
TABLES
T_OUTTAB_HEADER = it_final1
T_OUTTAB_ITEM = it_final.

ENDFORM.

Ashok
SAP-ADV ABAP

21-10-2014
Note:
SLIS_KEYINFO_ALV:
It holds the Key field details of bifurcation in hierarchal sequential alvs
It is having fields such as
1. HEADER01 -------- header key field
2. ITEM01 ------------- item key field

REUSE_ALV_HIRESEQ_LIST_DISPLAY:
Using this function module you can display the in hierarchal format
The parameters are
1. Current program name
2. Layout work area
3. Field catalog internal table
4. Sorting internal table
5. Layout for sale
6. Events internal table
7. Header internal table name
8. Item internal table name
9. Key work area for bifurcation
10.Header internal table
11.Item internal table

Ashok
SAP-ADV ABAP

FI Module: FICO
 Finance & Controlling Module
 In every company vendor will sell goods & customer will purchase
 In both the cases money inflow & outflow will take place
 Then FI module comes into picture

Components in FI Module:
1. Accounting Document Number:
For every finance transaction system will creates an accounting document number

T Codes:
1. FB01
2. FB02
3. FB03

Tables:
1. BKPF
2. BSEG

Key field: BELNR

2. Account Receivable:
This document is created when vendor will receive money form customer

T Codes:
1. F-28
2. FB02
3. FB03

Tables:
1. BSID
2. BSAD

Key field: BELNR

3. Account Payable:
This document is created when customer will pay money to vendor

T Codes:
1. F-43
Ashok
SAP-ADV ABAP

2. FB02
3. FB03
Tables:
1. BSIK
2. BSAK

Key field: BELNR

4. Asset Accounting:
Every company has to purchase assets
All assets are posted to asset accounting

T Codes:
1. AB01
2. AB02
3. AB03

Tables:
1. ANEK
2. ANEP
3. ANLC
4. ANLZ
5. ANKA

Key field: ANLNR (asset number)

5. G/L Account:
 General Ledger Account
 It is heart of Finance module
 All finance transactions are ultimately posted to a specific G/L Accont
 G/L Account holds both master data & transactional data

T Codes:
1. FS01
2. FS10N
3. FAGLL03
4. FBL1N
5. FBL3N
6. FBL5N
Tables:
1. SKA1

Ashok
SAP-ADV ABAP

2. SKB1
3. BSIS
4. BSAS
Key field: HKONT, SAKNR

Other Impartment Tables:


1. FAGLFLEXT
2. FAGLFLEXA
3. GLTO

Ashok
SAP-ADV ABAP

HR Module:
Human Resource Module

Components in HR Module:
1. Personal Administration
i) Personal management
ii) Organizational structure
iii) Personality development
iv) Compensation management
v) Recruitment
2. *** Organizational Management
3. *** Payroll
4. Time Management
5. Travel Management

Info Types:
It is a set of related data fields stores information at one place in HR
Every Info type is a 4 letter word
Example:
0008 ------- basic salory
0021 ------- family
0023 ------- previous employers
0006 ------- addresses ……………….etc

Applications in HR Module:
1. PA10
2. PA20
3. *** PA30
4. PA40
5. PA60
6. PA61
7. PC00_M40_CALC
8. PAYPC_RESULTS

Ashok
SAP-ADV ABAP

Tables:
1. PA0001 Info Type:
It is an info type for organizational assignment

Fields:
1. *** PERNR ------------ employee number
2. BUKRS ----------------- company code
3. PERSG ----------------- employee group
4. PERSK ----------------- employee sub group
5. BTRTL ----------------- personal sub area (department)
6. *** ABKRS ----------- payroll area
7. KOSTL ---------------- department
8. SNAME --------------- employee full name
9. ENAME --------------- employee name

2. PA0002 Info Type:


It is an info type for employee personal data

Fields:
1. PERNR -------- employee number
2. NACHN ------- last name
3. VORNA ------- first name
4. CNAME------- complete name
5. RUFNM ------- nick name
6. ANRED ------- title
7. GESCH ------- gender
8. *** GBDAT --- date of birth
9. ANZKD -------- number of children
10.FAMST -------- material status

22-10-2014
3. PA0006 Info Type:
It is for Employee addresses

Fields:
1. PERNR ---------- employee number
2. NAME2 --------- C/O name
3. STRAS ---------- street
4. ORT01 ---------- city
5. PSTLZ ---------- postal code
Ashok
SAP-ADV ABAP

6. LAND1 --------- country

Ashok
SAP-ADV ABAP

4. PA0009 Info Type:


It is for Employee Bank details

Fields:
1. PERNR ---------- employee number
2. BANKS --------- bank country name (sbi, icici)
3. BANKL --------- bank key (fct code)
4. BANKN --------- bank account number

5. PA0040 Info Type:


It is for employee recurring payments & deduction

Fields:
1. PERNR ---------- employee number
2. BEGDA --------- start date
3. ENDDA --------- end date
4. LGORT ---------- wage type (salary type )
5. BETRG ---------- amount

6. PA0019 Info Type:


It is for maintaining dates
Retirement is stored in this info type

Fields:
1. PERNR ----------- employee number
2. BEGDA ---------- retirement date

7. PA0021 Info Type:


It is for employee family members details

Fields:
1. PERNR ------------ employee number
2. FGBAT ------------ date of birth of family members
3. FAVOR ------------ first name
4. FANAM ----------- last name
5. SUBTY ------------ sub type
6. OBJPS ------------- object identification

Ashok
SAP-ADV ABAP

Example:
Pernr Subty Objps Fanam
1000 11 (Father) -- suresh
12 (Mother) -- laxmi
1 (Wife) -- sita
2 (children) 01 chinnu
02 banti

8. PA0023 Info Type:


It is for previous employers details

Fields:
1. PERNR ---------- employee number
2. ARBGP --------- name of employer (google, tcs)
3. ORT01 ---------- city
4. BRANK -------- industry
5. TAETE --------- job of employee

9. PA0028 Info Type:


It is for internal medical service details

Fields:
1. PERNR ---------- employee number
2. NMF01 ---------- value (blood group)
3. NMF02 --------- value (height)…………..etc

10. PA0105 Info Type:


It is for communication details

Fields:
1. PERNR --------- employee number
2. USRTY --------- communication type (phone, email)
3. USRID ---------- communication number

11.PA0586 Info Type:


It is for tax rebate details
Fields:
1. PERNR --------- employee number
2. ITC01 ----------- investment code
3. PIN01 ----------- investment amount
Ashok
SAP-ADV ABAP

4. ITC02 ----------- investment code


5. PIN02 ---------- investment amount
12.PA0587 Info Type:
It is for PF contribution details

Fields:
1. PERNR ----------- employee number
2. EEPFM ----------- PF account number
3. TSTID ------------ PF trust
4. PFAMT ---------- PF amount

13.PA0588 Info Type:


It is for employee welfare schemes details

Fields:
1. PERNR ---------- employee number
2. *** ESINO ----- employee state insurance number
3. ESIDP ----------- ESI dispensary (hospital)

13. TEVEN Table:


It is for time event details

Fields:
1. PERNR ---------- employee number
2. LDATE ---------- logical date
3. LTIME ----------- logical time

14.PA2001 Info Type:


It is for absence details

Fields:
1. PERNR ---------- employee number
2. AWART -------- absence type
3. ABWTG -------- absence days
4. ** ABRTG ----- payroll days
5. ** BEGDA ----- start date
6. ENDDA -------- end date

Example:
Pernr Begda Endda Awart Abwtg Abrtg
1000 01.11.2014 04.11.2014 EL 2 Days 3 Days
(Saturday) (Tuesday)
Ashok
SAP-ADV ABAP

15.PA2002 Info Type:


It is for attendance details

Fields:
1. PERNR ----------- employee number
2. BEGDA ---------- start date
3. ENDDA ---------- end date
4. AWART ---------- attendance type
5. ABWTG ---------- attendance days
6. ABRTG ---------- payroll days

16.*** PA0008 Info Type:


It is for basic pay details

Fields:
1. PERNR ---------- employee number
2. TRFGR ---------- pay scale group
3. LGA01 ---------- wage type (salary type)---DA
4. BET01 ---------- amount for wage type (salary type)
5. LGA02 --------- wage type (salary type)---HRA
6. BET02 --------- amount for wage type (salary type)…………up to 30

Ashok
SAP-ADV ABAP

Logical Database:
 Logical database is a special type of program provided by SAP
 It collects a group of (or) a set of Related Fields together from Database & supplied it to
Application program

Note:
The T code for working with logical database is SLDB

Object:
Employee Details Report

Input:
S_pernr ---------- Employee number
S_persg --------- Employee group
S_persk --------- Employee sub group
S_abkrs --------- Payroll area

Output:
Employee number
Employee name
Date of joining
Date of birth
Department
Designation
Age

Solution:
Step-1:
Create a structure with output fields
 Go to SE11
 Structure: ZHR_EMP_STR

Step-2:
Inserting logical database in our program
 Go to SE38
 Program: ZHR_EMPLOYEE_DETAILS_REPORT
 Create
 Title: Employee Details Report
 Type: Executable Program
 *** Logical Database: PNP (It is a special type of program name)
Ashok
SAP-ADV ABAP

 Enter

TABLES: PERNR
INFOTYPES: 0001, 0002.

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-000.


SELECT-OPTIONS: s_pernr FOR pernr-pernr,
S_persg FOR pernr-persg,
S_persk FOR pernr-persk,
S_abkrs FOR pernr-abkrs,
SELECTION-SCREEN: END OF BLOCK b1.

 Activate
 Back
 Attributes
 Change
 HR Report Category
 You will find a pop-up provide Master Data: IE_P35L (for no selection screen display of
PNP program)
 Enter
 Save
 Source Code
 Change

ZHR_EMPLOYEE_DETAILS

TYPES: BEGIN OF ty_final,


Pernr TYPE zhr_emp_str-pernr,
Ename TYPE zhr_emp_str-ename,
Doj TYPE zhr_emp_str-doj,
Gbdat TYPE zhr_emp_str-gbdat,
Dept TYPE zhr_emp_str-dept,
Age TYPE zhr_emp_str-age,
END OF ty_final.

DATA: wa_final TYPE ty_final,


it_final TYPE TABLE OF ty_final.

DATA: IT_FCAT TYPE SLIS_T_FIELDCAT_ALV,


WA_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA: design(20),
Dept(20),
Ashok
SAP-ADV ABAP

Hdate TYPE DATUM,


Age TYPE I.
START-OF-SELECTION.

GET PERNR.

CHECK pernr-pernr IN s_pernr,


AND pernr-persg IN s_persg,
AND pernr-abkrs IN s_abkrs.

IF SY-SUBRC EQ 0.
PERFORM get_data.
ENDIF.

END-OF-SELECTION.

PERFORM layout.
PERFORM display_data.

FORM get_data.

SELECT SINGLE plstx FROM T528T INTO design WHERE plans = pernr-plans
AND sprsl EQ ‘EN’
AND dept EQ ‘S’.

SELECT SINGLE orgtx FROM T527X INTO dept WHERE orgeh = pernr-orgeh.

CALL FUNCTION ‘RP_GET_HIRE_DATE’


EXPORTING
PERSNR = pernr-pernr
CHECK_INFOTYPES = ‘0001’
IMPORTING
HIREDATE = hdate.

CALL FUNCTION ‘HR_RU_AGE_YEARS’


EXPORTING
PERSNR = pernr-pernr
BSDATE = SY-DATUM
IMPORTING
VALUE = age.

wa_final-pernr = p0002-pernr.
Ashok
SAP-ADV ABAP

wa_final-ename = p0002-nachn.
wa_final-doj = hdate.
wa_final-gbdat = p0002-gbdat.
wa_final-dept = dept.
wa_final-age = age.

APPEND wa_final TO it_final.

ENDFORM.

FORM display_data.

CALL FUNCTION ‘REUSE_ALV_LIST_DISPLAY’


EXPORTING
I_STRUCTURE_NAME = ‘ZHR_EMP_STR’
IT_FIELDCAT = IT_FCAT
IS_LAYOUT = WA_LAYOUT
TABLES
T_OUTTAB = IT_FINAL.

ENDFORM.

24-10-2014

Ques: What are the different ways to creating FIELD CATALOGS?


Ans : There are 3 ways to create FIELD CATALOGS
1. Manually
Ex: WA_FCAT-FIELDNAME = ‘KUNNR’.
WA_FCAT-SELTEXT_M = ‘Customer Code’.
APPEND WA_FCAT TO IT_FCAT.
2. By using REUSE_ALV_FIELDCATALOG_MERGE function module
3. By passing DDIC Structure name to REUSE_ALV_LIST_DISPLAY function module

Ashok
SAP-ADV ABAP

Assignment:
Employee Total Details Report

Input:
S_pernr --------employee number
S_persg -------- employee group
S_persk -------- employee sub group
S_abkrs -------- payroll area

Output:

Gender (0002)
Number of Children (0002)
Address (0006)
Telephone Number (0105)
Mail Id (0105)
Height (0028)
Weight (0028)
Employee group (0001)
Employee sub group (0001)
Bank account number (0009)
Employee grade (0008)

Solution:

Ashok
SAP-ADV ABAP

SAP Query:
 In real time for developing a report it will take lot of time for development
 i.e. Requirement ---- Functional Consultant-----Functional Document----Technical
Consultant-----Technical Document------Object Creation------Unit Testing-----
Functional Testing-----User Testing-----go live (transfer to Production)
 using SAP Query you can create a report immediately through navigation

Drawbacks:
1. If you want to perform calculations & other complex logics you cannot work with SAP
Query
2. The T code for working SAP Query is SQVI

Example:
Customer Details Report

Step-1: program creation


 Go to SQVI
 Quick Viewer: ZCUSTOMER
 Create
 Title: Customer Details Report
 Table Join
 Enter
 Insert Table (shift + F1)
 Table: KNA1
 Insert Table (shift + F1)
 Table: VBAK
 Enter
 Back
 Selection Fields (for input fields)
 Select Customer Number
 List Fld Select (for output fields)
 Select Customer Number
Name
Sale Document
Date on which created
 Save
 Back
 Yes
 Quick View ----- Additional Functions ----- Generate Program

Ashok
SAP-ADV ABAP

 Quick View ---- Additional Funtions -----Display Report Name (copy this name)

Step-2: T code creation


 Go to SE93
 Transaction Code: ZCUST
 Create
 Short Text: T code for customer details
 Program and Selection Screen
 Enter
 Program: paste program name
 Save
 Back
 Execute T code

Note:
1. You can create SAP Query directly in Production Server in real time
2. Selection screen number is 1000

Ashok
SAP-ADV ABAP

Performance Tuning:
In real time we should create programs according coding standards along with that our program
should show good performance as per performance standards

Topics in Performance Tuning:


1. ** Indexing (SE11)
2. Runtime Analysis (SE30)
3. SQL Tracer (ST05)
4. Extended program check (SLIN)
5. Code Inspector (SCI)
6. Get runtime field
7. Performance tips

Ashok
SAP-ADV ABAP

25-10-2014
Indexing:
 Indexing is a way of searching
 Indexing is a way of improving performance while accessing the data from database

Index:
Index is a copy of a table with reduced fields
Every index table contains
1. Primary key fields,
2. Non Primary key fields &
3. A Pointer field which always points to the position of record
 Index takes advantage of sorting using Binary search
 Every index contains pointer also
 So, that it points to the records of actual table which are not contained in the index table

Types of Indexes:
1. Primary Index
2. Secondary Index

Primary Index:
 Primary index contains primary key fields
 It always points to non primary key fields
 Primary index always take advantage of sorting

Note:
Primary Index is automatically created whenever a table is created in database

Secondary Index:
 Secondary index is applied whenever a table will not take the advantage of sorting
 Secondary index contains non primary key fields
 It always points to primary key fields
Secondary indexes are created
1. On large tables
2. Table which are frequently access
3. Tables having more coloumns

Ques: When you create index on tables?


Answer:
 I created secondary index on production efficient report
Ashok
SAP-ADV ABAP

 First I debugged the program


 I found that control is taking lot of time for program execution
 Then I will identify none primary key fields of that SELECT statement & based on that
non-primary key fields I will created a secondary index

Navigation for Creating Secondary Index:


 Go to SE38
 Debug a program there control will staying on a SELECT statement for long time
 Identify non-primary key fields

 Go to SE11
 Database Table: AFRU
 Display
 Select Indexes
 Select Create option
 Create Entries
 Provide Index: ZAP
 You will find a warning there you will find a message “make reports in foreign name
spaces”, Enter
 Again you will find a pop-up then select Maintain in Original Language
 Provide Short Description: Index for BUDAT field
 Field Name: BUDAT
 Activate (ctrl+F3)

Ashok
SAP-ADV ABAP

26-10-2014
SQL Tracer: (ST05)
It provides information on
1. SQL statements operated in a program
2. All embedded SQL operations on a table
i.e. prepare
open
cursor
fetch
reopen
3. Number of extracted by SELECT statements
4. Performance time for tables
5. Indexes associated with tables

Example:
Step-1:
 Go to ST05
 Select Activate Tracer option

Step-2:
 Program: any program name
 Execute
 Provide selection screen input
 Execute

Step-3:
 Go to ST05
 Select Performance Tracer ---------Tracer off
 Select Display Tracer option
 You will find a pop-up Enter
 Here you will find a screen with following fields
1. Duration
2. Object name
3. Operation
4. Number of records
5. Statement

Duration -------- stores the time taken by a statement


Object name --- specifies the table name
Operation ------ specifies type of operation done on a SELECT statement
Ashok
SAP-ADV ABAP

No of records-- specifies number of records


Statement ------ specifies the skeleton of SELECT statement in your program
Double click on Object Name ---------- it will show the table details specified in data dictionary
(number of records, type of table…………….etc)

Select Index Fields option ---------- here you will find indexes created in that table

Select Trace List ----- Summarized Trace by SQL Statement --------- here you will find
screen of summarized information of all executions on database table

Select Display Detailed Trace List (F7) --------- here you will find a screen of all summarized
information of all SELECT statements operated in your program

Note:
In real time SQL Tracer is used for identifying
1. The tables
2. The time taken by tables for a specific database operation, based on this we can
identifying whether a table can be Buffered (or) Not

Ashok
SAP-ADV ABAP

Runtime Analysis: SE38


 Go to SE38
 Program: any program name
 Execute
 Provide Input values
 Execute
 Back
 Back
 Scroll down to bottom select Evaluate
 You will find a graph which shows the execution of a program in Micro Seconds

 Back
 Tips & Tricks
 Expand SQL Interface option
 Double click on Select With Select List
 Select Measure Run Time option

Ashok
SAP-ADV ABAP

ABAP Examples: SE38


 Go to SE38
 Environment ----- Examples -------ABAP Examples
 Here you will find topic wise examples

ABAP Documentation: SE38


 Go to SE38
 Program: any program name
 Change
 Place Cursor on any keyword
 Press F1
 Here you will find documentation for that key word

Ashok
SAP-ADV ABAP

Extended Program Check (EPC): SLIN


It specifies Internal Errors, Warnings, Messages & Obsolete statements of a program

Example:
 Go to SLIN (or)
 Go to SE38
 Program: any program name
 Program ------ Check ------ Extended Program Check
 Select last 4 check boxes
 Select Execute (F8)

Note:
Try to maintain all options (Internal Errors, Warnings & Messages) as per as possible zeros

Ashok
SAP-ADV ABAP

Code Inspector (CI): SCI


It will inspect your code comprehensively & it will check
1. Performance Checks
2. Security Checks
3. Syntax Checks
4. User Interface
5. Programming Guidelines

Example:
 Go to SCI
 Provide Object Sel Name: ZOBJ
 Create
 Save
 Back
 Provide Check Variant Name: ZVAR
 Create
 Select General Checks, Performance Checks, Syntax Check Generation, Programming
Convention & Internal Performance Test
 Save
 Back
 Provide Inspection Name: ZINS
 Create
 Select Single: Program: ZSD_SALES_REGISTER
 Check Variant: ZVAR
 Save
 Execute (F8)
 Results (shift + F6)

Ashok
SAP-ADV ABAP

GET RUN TIME FIELD keyword:


It returns the execution time for each loop pass with in LOOP………ENDLOOP

Example:
DATA t1 TYPE I.

DO 10 TIMES.
GET RUN TIME FIELD t1.
WRITE:/ t1.
ENDDO.

 Activate
 Execute

WAIT UP TO <n> SECONDS keyword:


 It waits for ‘n’ seconds then it will perform execution
 This keyword we are using for Mail Sending Reports for wait time

Example:

Ashok
SAP-ADV ABAP

WAIT UP TO 100 SECONDS.

Performance Tuning:

Ashok
SAP-ADV ABAP

Creating Custom Logical Database:


 Go to SLDB
 Logical Database: ZLD_SD
 Create
 Short Text: Logical Database
 Enter
 Local Object
 Name of Root Node: KNA1
 Text: KNA1 Table
 Database Table: KNA1
 Enter
 Select KNA1
 Insert Node
 Node Name: VBAK
 Text: VBAK Table
Database Table: VBAK
 Execute (F5)
 Save
 Back
 Selections (radio button)
 Change
 Yes
 Enter
 Remove comment for
SELECT-OPTIONS: s_kunnr FOR kna1-kunnr.
SELECT-OPTIONS: s_vbeln FOR vbak-vbeln.

 Activate
 Back
 Database Program
 Change
 Yes
 Double click on 1st INCLUDE DBZLD_SDNXXX
 You will find 4 includes, double click on 1st include (DBZLD_SDN001)
 Remove 1st comment (SELECT * FROM KNA1)
 Remove 4th comment (WHERE kunnr IN s_kunnr)
 Remove comment for ENDSELECT
 Activate
 Back

Ashok
SAP-ADV ABAP

 Double click on 2nd INCLUDE


 You will find 4 includes, double click on 1st include (DBZLD_SDN001)
 Remove 1st comment (SELECT * FROM KNA1)
 Remove 4th comment (WHERE kunnr IN s_kunnr)
 Remove comment for ENDSELECT
 Activate

 Go to SE38
 Program: ZCALL_LDB
 Create
 Title: Calling LDB program
 Type: Executable Program
 Logical Database: ZLD_SD
 Enter

TABLES KNA1.
GET KNA1.
WRITE:/10 kna1-kunnr,
30 kna1-name1,
50 kna1-ort01.

 Activate
 Execute

Ashok
SAP-ADV ABAP

Assignment-1:
*** Material Ageing Report

Input:
S_matnr
S_werks
S_budat

Output:
Material code
Material description
Last consumption date
0 to 30 days (A30)
31 to 60 days (A60)
61 to 90 days (A90)
91 to 120 days (A120)
121 to 150 days (A150)
151 to 180 days (A180)
>180 days (A181)

Tables:
MKPF
MSEG
MARA
MAKT

Solution:

Ashok
SAP-ADV ABAP

Assignment-2:
Packing Cost Material Report

Input:
S_matnr
S_werks

Output:
Header Data:
Material code
Material description

Item Data:
Bom component
Bom component description
Unit of measurement
Price
Quantity

Tables:
MAST
STAS
MAKT
MBEW

Processing Logic:
1. Get matnr stlnr stlal from mast based on input
2. Get stlnr stlal from stas by passing stlal of mast & stlnr of mast where stlty EQ ‘m’
3. Get stlnr idnrk meins menge from stop by passing stlnr of stas & stlkn of stas where
stlty EQ ‘m’
4. Get matnr verpr from mbew by passing matnr of mast where bwkey IN s_werks
5. Get matnr maktx from makt by passing matnr of mast & spras EQ ‘EN’
6. Get matnr maktx from makt by passing idnrk of stop & spras EQ ‘EN’

Solution:

Ashok
SAP-ADV ABAP

Overview of Reports:
Interview Topics:
1. More than 50 objects
2. System landscape
3. Objects (Ex: Material Ageing Report)
3.1. Inputs
3.2. Outputs
3.3. Tables & Fields
4. Business Process Flows (Ex: MM)
5. Events
5.1. Differences between Events
5.2. Flow of Events
5.3. Usage of Events
6. ALV Reporting
6.1. Field catalogs
6.2. Export & Import parameters
6.3. Function modules
6.4. Blocked ALV
6.5. Hierarchal Sequential ALV
6.6. Interactive ALV

Flow of Events:
 Initialization
 At selection screen
 Start of selection
 End of selection
 Top of page
 Top of page during line selection
 End of page
 At user command

Ashok
SAP-ADV ABAP

Object Oriented Programming (or) Object Oriented ABAP


Difference between Structured Programming & Object Oriented Programming:
Structured Programming Object Oriented Programming
1. Not Reusable 1. Reusable
2. Not based on real life 2. Based on real life
(not user friendly)
3. No data security 3. High data security
4. No exception handling 4. Exception handling

Features of Object Oriented Programming:


1. Inheritance
2. Polymorphism
3. Abstraction
4. Encapsulation

Inheritance:
Creating new objects from existing object is called inheritance

Example:
DATA it_kna1 TYPE TABLE OF KNA1.

Polymorphism:
An identical object behaves differently in different different locations. This concept is called
polymorphism

Example:
VBAK LIKP VBRK

vbeln vbeln vbeln


(sales order) (delivery document) (invoice number)

Abstraction:
Hiding the implementation details is called abstraction
Example:
Function module, Include, Sub routine

Encapsulation:
 In real world every object acts as a capsule of data
 Every object hides the data in such a way that outside world cannot access it.
Ashok
SAP-ADV ABAP

 Encapsulation is achieved from abstraction


Class:
 Class is a template based on which objects are created
 All the features (Methods) of an object is encapsulated within a class
 As class is a template memory is not allocated by system to a class

Object:
 It is real time entity
 It is always created based on a class (object is an instance of a class)
 As object is a real time entity memory is allocated by system to an object
 Every object holds data in such a way that outside world cannot access

Access Specifiers:
1. Private
2. Protected
3. Public

Private:
Attributes declared under private access specifier can be access only by the methods of that
particular class

Protected:
Attributes declared under protected access specifier can be access by the methods of base class
as well as derived class

Public:
Attributes declared under public access specifier can be access by any object in your program

Note:
Methods should be declared under public access specifier

Types of Classes:
1. Local class
2. Global class
3. Exception class
4. Unit Test class
5. Persistent class

Ashok
SAP-ADV ABAP

Section of a Class:
1. Class Definition
2. Class Implementation
3. Class Execution
Class Definition:
Attributes & Methods are defined under this section

Syntax:
CLASS <class name> DEFINITION.

Example:
CLASS cl_abc DEFINITION.

PUBLIC SECTION.
METHOD: get_data,
combine_data,
display_data.

PRIVATE SECTION.
DATA: var1,
var2.

PROTECTED SECTION.
DATA: var3,
var4.

ENDCLASS.

Class Implementation:
Methods are implemented under this section

Syntax:
CLASS <class name> IMPLEMENTATION.

Example:
CLASS cl_abc IMPLEMENTATION.

METHOD get_data.
------------
------------
Ashok
SAP-ADV ABAP

ENDMETHOD.

METHOD combine_data.
------------
------------
ENDMETHOD.
METHOD display_data.
------------
------------
ENDMETHOD.

ENDCLASS.

Class Execution:
Under this section
1. Objects are defined
2. Objects are created
3. Methods are called

Example:
DATA obj TYPE REF TO cl_abc.

CREATE OBJECT obj.

CALL METHOD: obj->get_data,


obj->combine_data,
obje->display_data.

Ashok
SAP-ADV ABAP

Requirement:
Statement of Account based on Customer

Input:
Customer code
Company code
Special G/L indicator
Accounting document number
Posting date

Output:
Customer number
Customer name
Accounting document number
Document date
Document type
Reference document number
Debit
Credit
Over due -------- Total
Solution:
ZFI_STATEMENT_ACCOUNT

TABLES: KNA1, BSID.

TYPE-POOLS SLIS.

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-000.


SELECT-OPTIONS: s_kunnr FOR kna1-kunnr,
s_bukrs FOR bsid-bukrs,
s_umskz FOR bsid-umskz,
s_belnr FOR bsid-belnr,
s_budat FOR bsid-budat.
SELECTION-SCREE: END OF BLOCK b1.

CLASS cl_overdue DEFINITION.

PUBLIC SECTION.

METHODS: get_bsid,
Ashok
SAP-ADV ABAP

combine_data,
combine_data1,
fill_cat,
layout,
display_data.

PRIVATE SECTION.

TYPES: BEGIN OF ty_bsid,


kunnr TYPE kunnr,
name1 TYPE name1,
belnr TYPE belnr,
blart TYPE blart,
bldat TYPE bldat,
xblnr TYPE xblnr,
shkzg TYPE shkzg,
dmbtr TYPE dmbtr,
END OF ty_bsid.

TYPES: BEGIN OF ty_final,


kunnr TYPE kunnr,
name1 TYPE name1,
belnr TYPE belnr,
blart TYPE blart,
bldat TYPE bldat,
xblnr TYPE xblnr,
shkzg TYPE shkzg,
debit TYPE dmbtr,
credit TYPE dmbtr,
due TYPE dmbtr,
line_color(4),
END OF ty_final.

DATA: wa_bsid TYPE ty_bsid,


wa_final TYPE ty_final,
wa_final1 TYPE ty_final,
it_bsid TYPE TABLE OF ty_bsid,
it_final TYPE TABLE OF ty_final,
it_final1 TYPE TABLE OF ty_final.

DATA: WA_FCAT TYPE SLIS_FIELDCAT_ALV,


WA_LAYOUT TYPE SLIS_LAYOUT_ALV,
Ashok
SAP-ADV ABAP

IT_FCAT TYPE SLIS_T_FIELDCAT_ALV.

ENDCLASS.

CLASS cl_overdue IMPLEMENTATION.

METHOD get_bsid.
SELECT kna1~kunnr kna1~name1 bsid~belnr bsid~blart bsid~bldat bsid~xblnr
bsid~shkzg bsid~dmbtr INTO TABLE it_bsid FROM BSID INNER JOIN KNA1
ON bsid~kunnr = kna1~kunnr
WHERE bsid~kunnr IN s_kunnr
AND bsid~umskz IN s_umskz
AND bsid~budat IN s_budat
AND bsid~bukrs IN s_bukrs
AND bsid~belnr IN s_belnr.
ENDMETHOD.

METHOD combine_data.
SORT it_bsid BY kunnr.
LOOP AT it_bsid INTO wa_bsid.
wa_final-kunnr = wa_bsid-kunnr.
wa_final-name1 = wa_bsid-name1.
wa_final-xblnr = wa_bsid-xblnr.
wa_final-belnr = wa_bsid-belnr.
wa_final-bldat = wa_bsid-bldat.
wa_final-blart = wa_bsid-blart.

IF wa_bsid-shkzg = ‘H’.
wa_final-credit = (-1) * wa_bsid-dmbtr.
ELSE.
wa_final-debit = wa_bsid-dmbtr.
ENDIF.

wa_final-due = wa_final-debit + wa_final-credit.

APPEND wa_final TO it_final.

CLEAR wa_final.

ENDLOOP.

ENDMETHOD.
Ashok
SAP-ADV ABAP

METHOD combine_data1.
SORT it_final BY kunnnr.

LOOP AT it_final INTO wa_final.

AT NEW kunnr.
MOVE wa_final-kunnr TO wa_final1-kunnr.
APPEND wa_final1 TO it_final1.
CLEAR wa_final1.
ENDAT.

wa_final1-name1 = wa_final-name1.
wa_final1-belnr = wa_final-belnr.
wa_final1-bldat = wa_final-bldat.
wa_final1-xblnr = wa_final-xblnr.
wa_final1-blart = wa_final-blart.
wa_final1-debit = wa_final-debit.
wa_final1-credit = wa_final-credit.
wa_final1-due = wa_final-due.

APPEND wa_final1 TO it_final1.

CLEAR wa_final1.

AT END OF kunnr.
SUM.
wa_final1-due = wa_final-due.
wa_final1-kunnr = wa_final-‘Total’.
wa_final1-line_color = ‘C510’.

APPEND wa_final1 TO it_final1.

CLEAR wa_final1.
ENDAT.

AT LAST.
SUM.
wa_final1-due = wa_final-due.
wa_final1-kunnr = wa_final-‘Grand Total’.
wa_final1-line_color = ‘C510’.

Ashok
SAP-ADV ABAP

APPEND wa_final1 TO it_final1.

CLEAR wa_final1.
ENDAT.

ENDLOOP.
ENDMETHOD.

METHOD fill_cat.
wa_fcat-fieldname = ‘KUNNR’.
Wa_fcat-seltext_m = ‘Customer Code’.
APPEND wa_fcat TO it_fcat.

wa_fcat-fieldname = ‘NAME1’.
Wa_fcat-seltext_m = ‘Customer Name’.
APPEND wa_fcat TO it_fcat.

wa_fcat-fieldname = ‘BELNR’.
Wa_fcat-seltext_m = ‘Accounting Document Number’.
APPEND wa_fcat TO it_fcat.

wa_fcat-fieldname = ‘BLDAT’.
Wa_fcat-seltext_m = ‘Document Date’.
APPEND wa_fcat TO it_fcat.

wa_fcat-fieldname = ‘BLART’.
Wa_fcat-seltext_m = ‘Document Type’.
APPEND wa_fcat TO it_fcat.

wa_fcat-fieldname = ‘XBLNR’.
Wa_fcat-seltext_m = ‘Reference Document Number’.
APPEND wa_fcat TO it_fcat.

wa_fcat-fieldname = ‘DEBIT’.
Wa_fcat-seltext_m = ‘Debit’.
APPEND wa_fcat TO it_fcat.

wa_fcat-fieldname = ‘CREDIT’.
Wa_fcat-seltext_m = ‘Credit’.
APPEND wa_fcat TO it_fcat.

wa_fcat-fieldname = ‘DUE’.
Ashok
SAP-ADV ABAP

Wa_fcat-seltext_m = ‘Over Due’.


APPEND wa_fcat TO it_fcat.
ENDMETHOD.

METHOD layout.
wa_layout-zebra = ‘X’.
wa_layout-colwidth_optimize = ‘X’.
wa_layout-info_fieldname = ‘LINE_COLOR’.
ENDMETHOD.

METHOD display_data.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
IT_FIELDCAT = IT_FCAT.
IS_LAYOUT = WA_LAYOUT
I_SAVE = ‘X’
TABLES
T_OUTTAB = IT_FINAL1.
ENDMETHOD.

ENDCLASS.

START-OF-SELECTION.

DATA obj TYPE REF TO cl_overdue.

CREATE OBJECT obj.

CALL METHOD: obj->get_bsid,


obj->combine_data,
obj->combine_data1,
obj->fill_cat,
obj->layout,
obj->display_data.

Ashok
SAP-ADV ABAP

27-10-2014

Local Class:
In local class all the 3 sections of a class are maintained in ABAP Editor

BSID & BSAD Table:


BSID holds open items data & BSAD holds cleared items data. The fields will be same

Fields:
1. BUKRS ---------- company code
2. KUNNR --------- customer code
3. UMSKZ --------- special G/L indicator
4. ** ZUONR ------ assignment (or) bill number
5. GJAHR ---------- financial year
6. BELNR ---------- accounting document number
7. BUDAT --------- posting date
8. BLDAT --------- bill date
9. XBLNR --------- reference document number
10.BLART --------- document type
11.SHKZG --------- debit (s) / credit (h) indicator
12.**DMBTR ----- amount in local currency
13.HKONT -------- G/L amount
14.**ZFBDT ------ base line date for due date calculation
15.ZTERM -------- payment terms

Ashok
SAP-ADV ABAP

Inheritance:
Creating new objects from existing objects is called inheritance

Syntax for declaring Derived Class:


CLASS <cl_derived> DEFINITION INHERITING FROM <cl_base>.
-----------
-----------
ENDCLASS.

Requirement:
Vendor Aging Report
Vendor aging report is prepared by customer based on respective vendors

Input:
S_lifnr
S_prctr
S_umskz
S_bukrs

Output:
Vendor code
Vendor name
0-30 days
31-60 days
61-90 days
91-120 days
121-150 days
151-180 days
>-180 days
Total amount

Solution:
ZFI_VENDOR_AGING_REPORTS

TYPE-POOLS SLIS.

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-000.


SELECT-OPTIONS: s_lifnr FOR lfa1-lifnr,
s_prctr FOR bsik-prctr,
s_umskz FOR bsik-umskz,
Ashok
SAP-ADV ABAP

s_bukrs FOR bsik-bukrs.


SELECTION-SCREEN: END OF BLOCK b1.
SELECTION-SCREEN: BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-001.
PARAMETERS keydate TYPE budat.
SELECTION-SCREEN: END OF BLOCK b2.

INITIALIZATION.
keydate = SY-DATUM.

AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF SCREEN-NAME EQ ‘keydate’.
MODIFY SCREEN.
ENDIF.
ENDLOOP.

CLASS cl_base DEFINITION.


PUBLIC SECTION.
METHODS: get_bsik,
combine_data.

PROTECTED SECTION.
TYPES: BEGIN OF ty_bsik,
belnr TYPE belnr_d,
bldat TYPE bldat,
shkzg TYPE shkzg,
dmbtr TYPE dmbtr,
lifnr TYPE lifnr,
END OF ty_bsik.

TYPES: BEGIN OF ty_lfa1,


lifnr TYPE lifnr,
name1 TYPE name1,
END OF ty_lfa1.

TYPES: BEGIN OF ty_final,


lifnr TYPE lifnr,
name1 TYPE name1,
a30 TYPE dmbtr,
a60 TYPE dmbtr,
a90 TYPE dmbtr,
a120 TYPE dmbtr,
Ashok
SAP-ADV ABAP

a150 TYPE dmbtr,


a180 TYPE dmbtr,
ag180 TYPE dmbtr,
total TYPE dmbtr,
END OF ty_final.

DATA n TYPE I.

DATA: wa_lfa1 TYPE ty_lfa1,


wa_bsik TYPE ty_bsik,
wa_bsik1 TYPE ty_bsik,
wa_final TYPE ty_final,
it_lfa1 TYPE TABLE OF ty_lfa1,
it_bsik TYPE TABLE OF ty_bsik,
it_bsik1 TYPE TABLE OF ty_bsik,
it_final TYPE TABLE OF ty_final,
it_final1 TYPE TABLE OF ty_final.

DATA: wa_fcat TYPE SLIS_FIELDCAT_ALV,


wa_layout TYPE SLIS_LAYOUT_ALV,
it_fcat TYPE SLIS_T_FIELDCAT_ALV.

ENDCLASS.

CLASS cl_base IMPLEMENTATION.

METHOD get_bsik.
SELECT belnr bldat shkzg dmbtr lifnr FROM BSIK INTO TABLE it_bsik
WHERE lifnr IN s_lifnr
AND bukrs IN s_bukrs
AND prctr IN s_prctr
AND umskz IN s_umskz
AND bldat < keydate.

SELECT belnr bldat shkzg dmbtr lifnr FROM BSAK APPENDING TABLE it_bsik
WHERE lifnr IN s_lifnr
AND bukrs IN s_bukrs
AND prctr IN s_prctr
AND umskz IN s_umskz
AND bldat < keydate
AND augdt > keydate.

Ashok
SAP-ADV ABAP

IF NOT it_bsik IS INITIAL.


SELECT lifnr name1 FROM LFA1 INTO TABLE it_lfa1
FOR ALL ENTRIES IN it_bsik WHERE lifnr = it_bsik-lifnr.
ENDIF.
ENDMETHOD.

METHOD combine_data.
SORT it_bsik BY lifnr.
LOOP AT it_lfa1 INTO wa_lfa1.
LOOP AT it_bsik INTO wa_bsik WHERE lifnr = wa_lfa1-lifnr.

IF wa_bsik-zhkzg = ‘H’.
wa_bsik-dmbtr = (-1) * wa_bsik-dmbtr.
ENDIF.

n = keydate - wa_bsik-bldat.

IF n = 0.
CONTINUE.
ENDIF.

wa_final-a30 = wa_final-a30 + wa_bsik-dmbtr.

ELSEIF n GT 30 AND n LE 60.


wa_final-a60 = wa_final-a60 + wa_bsik-dmbtr.

ELSEIF n GT 60 AND n LE 90.


wa_final-a90 = wa_final-a90 + wa_bsik-dmbtr.

ELSEIF n GT 90 AND n LE 120.


wa_final-a120 = wa_final-a120 + wa_bsik-dmbtr.

ELSEIF n GT 120 AND n LE 150.


wa_final-a150 = wa_final-a150 + wa_bsik-dmbtr.

ELSEIF n GT 150 AND n LE 180.


wa_final-a180 = wa_final-a60 + wa_bsik-dmbtr.

ELSEIF n GT 180 .
wa_final-Ag180 = wa_final-ag180 + wa_bsik-dmbtr.

ENDIF.
Ashok
SAP-ADV ABAP

ENDLOOP.

wa_final-total = wa_final-a30 + wa_final-a60 + wa_final-a90 + wa_final-120 +


wa_final0150 + wa_final-a180 + wa_final-ag180.
wa_final-lifnr = wa_lfa1-lifnr.
wa_final-name1 = wa_lfa1-name1.

APPEND wa_final TO it_final.

CLEAR wa_final.

ENDLOOP.
ENDMETHOD.
ENDCLASS.

CLASS cl_derived DEFINITION INHERITING FROM cl_base.


PUBLIC SECTION.
METHODS: fill_cat,
layout,
display_data.
ENDCLASS.

CLASS cl_derived IMPLEMENTATION.


METHOD fill_cat.
wa_fcat-filename = ‘lifnr’.
wa_fcat-key = ‘x’.
wa_fcat-seltext_m = ‘vendor code’.
APPEND wa_fcat TO it_fcat.

wa_fcat-filename = ‘name1’.
wa_fcat-key = ‘x’.
wa_fcat-seltext_m = ‘vendor name’.
APPEND wa_fcat TO it_fcat.

wa_fcat-filename = ‘a30’.
wa_fcat-do_sum = ‘x’.
wa_fcat-seltext_m = ‘0-30 days’.
APPEND wa_fcat TO it_fcat.

wa_fcat-filename = ‘a60’.
wa_fcat-do_sum = ‘x’.
wa_fcat-seltext_m = ‘31-60 days’.
Ashok
SAP-ADV ABAP

APPEND wa_fcat TO it_fcat.

wa_fcat-filename = ‘a90’.
wa_fcat-do_sum = ‘x’.
wa_fcat-seltext_m = ‘61-90 days’.
APPEND wa_fcat TO it_fcat.

wa_fcat-filename = ‘a120’.
wa_fcat-do_sum = ‘x’.
wa_fcat-seltext_m = ‘91-120 days’.
APPEND wa_fcat TO it_fcat.

wa_fcat-filename = ‘a150’.
wa_fcat-do_sum = ‘x’.
wa_fcat-seltext_m = ‘121-150 days’.
APPEND wa_fcat TO it_fcat.

wa_fcat-filename = ‘a180’.
wa_fcat-do_sum = ‘x’.
wa_fcat-seltext_m = ‘151-180 days’.
APPEND wa_fcat TO it_fcat.

wa_fcat-filename = ‘ag180’.
wa_fcat-do_sum = ‘x’.
wa_fcat-seltext_m = ‘> 180 days’.
APPEND wa_fcat TO it_fcat.

wa_fcat-filename = ‘total’.
wa_fcat-do_sum = ‘x’.
wa_fcat-seltext_m = ‘total amount’.
APPEND wa_fcat TO it_fcat.

ENDMETHOD.

METHOD layout.
wa_layout-zebra = ‘x’.
wa_layout-colwidth_optimize = ‘x’.
ENDMETHOD.

METHOD display_data.
CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
EXPORTING
Ashok
SAP-ADV ABAP

I_CALLBACK_PROGRAM = ‘X’
IS_LAYOUT = wa_layout
IT_FIELDCAT = it_fcat
I_SAVE = ‘X’
TABLES
T_OUTTAB = it_final.
ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
DATA obj TYPE REF TO cl_derived.

CREATE OBJECT obj.

CALL METHOD: obj->get_bsik,


obj->combine_data,
obj->fill_cat,
obj->layout,
obj->display_data.

Ashok
SAP-ADV ABAP

BSIT & BSAK Tables:


BSIK holds open item data for vendor & BSAK holds cleared item data for customers

Fields:
1. LIFNR ----------- vendor code
2. BUKRS ---------- company code
3. KUNNR --------- customer code
4. UMSKZ --------- special G/L indicator
5. ** ZUONR ------ assignment (or) bill number
6. GJAHR ---------- financial year
7. BELNR ---------- accounting document number
8. BUDAT --------- posting date
9. BLDAT --------- bill date
10.XBLNR --------- reference document number
11.BLART --------- document type
12.SHKZG --------- debit (s) / credit (h) indicator
13.**DMBTR ----- amount in local currency
14.HKONT -------- G/L amount
15.**ZFBDT ------ base line date for due date calculation
16.ZTERM -------- payment terms

Ashok
SAP-ADV ABAP

28-10-2014
Abstract Class:
 Abstract classes are cannot be implemented
 Objects cannot be created for abstract classes
 Abstract class methods are also abstract in nature
 Derived class can implement abstract class methods by redefining the methods of abstract
class in derived class

Requirement:
Employee Salary & Attendance Details report

Input:
S_pernr --------- employee number
S_persg -------- employee group
S_persk -------- employee sub group
S_abkrs -------- payroll area
S_date --------- period
Attendance (radio button)
Salary (radio button)

Output:
For Attendance:
Employee number
Employee name
Present
Leaves
Rest
Holiday enjoyed

For Salary:
Employee number
Employee name
Date of birth
Basic salary
Da
Hra

Solution:
 Go to SE11
 Create structure YHR_SAL with following fields
Ashok
SAP-ADV ABAP

Pernr
Ename
Bsal
Da
Hra

 Create another structure YHR_ATTEN with following fields


Pernr
Ename
Present
El
Rest
He

 Go to SE38
 Program: ZHR_ATTEN_SAL_DETAILS
 Create
 Title: Employee salary & attendance details report
 Type: Executable Program
 Logical Database: PNP
 Enter
 Enter
 Activate program
 Back
 Attributes
 Change
 HR Report Category
 Master Data (info types): IE_P35L
 Enter
 Enter
 Source Code
 Change

TABLES: PERNR.

INFOTYPES: 0002, 0008.

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-000.


SELECT-OPTIONS: s_pernr FOR pernr-pernr,
s_date FOR pernr-dayps.
SELECTION-SCREEN: END OF BLOCK b1.

Ashok
SAP-ADV ABAP

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


PARAMETERS: p_rb1 RADIOBUTTON GROUP rg1,
p_rb2 RADIOBUTTON GROUP rg1.
SELECTION-SCREEN: END OF BLOCK b2.

DATA: p_betrg TYPE pad_amt7s,


p_lgart TYPE lgart.

CLASS cl_abstract DEFINITION ABSTRACT.

PUBLIC SECTION.
METHODS: get_emp ABSTRACT IMPORTING pernr TYPE person,
display_data ABSTRACT.

PROTECTED SECTION.
DATA: wa_sal TYPE yhr_sal,
wa_atten TYPE yhr_atten,
it_sal TYPE TABLE OF yhr_sal,
it_atten TYPE TABLE OF yhr_atten,
gwa_tim TYPE hrf_tim_b2,
wa_ph TYPE ptr_f_psp,
wa_ab TYPE ptr_f_ab,
wa_tp TYPE ptr_f_tp,
rest TYPE I,
present TYPE I,
el TYPE I,
wrk TYPE I,
he TYPE I.

ENDCLASS.

CLASS cl_atten DEFINITION INHERITING FROM cl_abstract.

PUBLIC SECTION.
METHODS: get_emp REDEFINITION,
display_data REDEFINITION.

ENDCLASS.

CLASS cl_atten IMPLEMENTATION.

METHOD get_emp.
Ashok
SAP-ADV ABAP

CALL FUNCTION ‘HR_FORMS_TIM_GET_B2_RESULTS’


EXPORTING
Pernr = pernr
Begda = s_date-low
Endda = s_date-high
IMPORTING
Tim_b2 = gwa_tim.

LOOP AT gwa_tim-ft_psp INTO wa_psp.


IF wa_psp-ftkla EQ ‘1’.
He = he + 1.
ENDIF.

Wrk = wrk + 1.

IF wa_psp-trprog = ‘OFF’.
Rest = rest + 1.
ENDIF.

ENDLOOP.

LOOP AT gwa_tim-ft_ab INTO wa_ab.


IF wa_ab-awart EQ ‘100’.
el = el + 1.
ENDIF.
ENDLOOP.

Present = wrk - (rest + el + he).


wa_atten-pernr = pernr.
wa_atten-ename = p0002-nachn.
wa_atten-present = present.
wa_atten-el = el.
wa_atten-rest = rest.
wa_atten-he = he.

APPEND wa_atten TO it_atten.

CLEAR: rest, el, present, he, wrk, wa_atten.

ENDMETHOD.

METHOD display_data.
Ashok
SAP-ADV ABAP

CALL FUNCTION ‘REUSE_ALV_LIST_DISPLAY’


EXPORTING
I_STRUCTURE_NAME = ‘YHR_ATTEN’
TABLES
T_OUTTAB = it_atten.

ENDMETHOD.
ENDCLASS.

CLASS cl_sal DEFINITION INHERITING FROM cl_abrstract.

PUBLIC SECTION.
METHODS: get_emp REDEFINITION,
display_data REDEFINITION,
calc_sal,
hold_sal.

ENDCLASS.

CLASS cl_sal IMPLEMENTATION.

METHOD get_emp.
wa_sal-pernr = pernr.
wa_sal-ename = p0002-nachn.
ENDMETHOD.

METHOD calc_sal.
CASE p_lgart.
WHEN ‘MA90’.
wa_sal-bsal = p_betrg.
WHEN ‘MA80’.
wa_sal-da = p_betrg.
WHEN ‘MA70’.
wa_sal-hra = p_betrg.
ENDCASE.
ENDMETHOD.

METHOD hold_sal.
APPEND wa_sal TO it_sal.
ENDMETHOD.

METHOD display_data.
Ashok
SAP-ADV ABAP

CALL FUNCTION ‘REUSE_ALV_LIST_DISPALY’


EXPORTING
I_STRUCTURE_NAME = ‘YHR_SAL’
TABLES
T_OUTTAB = it_sal.

ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
DATA: obj TYPE REF TO cl_atten,
obj1 TYPE REF TO cl_sal.

IF p_rb1 EQ ‘X’.
CREATE OBJECT obj.
ELSE.
CREATE OBJECT obj1.
ENDIF.

GET PERNR.
CHECK pernr-pernr IN s_pernr.

IF SY-SUBRC EQ 0.

IF p_rb1 EQ ‘X’.
CALL METHOD obj->get_emp
EXPORTING
Pernr = pernr-pernr.

RP_PROVIDE_FROM_LAST P0008 SPACE ‘18000101’ ‘99991231’.


(or)
REFRESH P0008[ ].
CALL FUNCTION ‘HR_READ_INFOTYPE’
EXPORTING
Pernr = pernr-pernr
Infty = ‘0008’
Begda = ‘20020101’
Endda = ‘99991231’
TABLES
Infty_tab = P0008[ ].

DO 30 TIMES VARING p_betrg FROM P0008-bet01 NEXT P0008-bet02


Ashok
SAP-ADV ABAP

VARING p_lgart FROM P0008-lga01 NEXT P0008-lga02.


CALL METHOD obj1->calc_sal.

ENDDO.

CALL METHOD obj1->hold_sal.

ENDIF.
ENDIF.

END-OF-SELECTION.
IF p_rb1 EQ ‘X’.
CALL METHOD obj->display_data.
ELSE.
CALL METHOD obj1->display_data.
ENDIF.

Ashok
SAP-ADV ABAP

Assignment:
Employee Family & Previous Employers Details Report

Input:
S_pernr
S_persg
S_abkrs
Experience (radio button)
Family (radio button)

Output:
Experience:
Employee number
Employee name
Date of birth
Previous experience
Current experience
Total experience

Family:
Employee number
Employee name
Father
Mather
Spouse
Child1
Child2

Solution:

Ashok
SAP-ADV ABAP

Assignment:
Employee Late Coming Report

Input:
S_pernr
S_persg
S_abkrs
S_period

Output:
Employee number
Employee name
Department
Date
In time
Late

Solution:

Ashok
SAP-ADV ABAP

29-10-2014
Global Class:
In global class CLASS DEFINITION & CLASS IMPLEMENTATION parts are maintained
in Class Builder (SE24) & Execution part is maintained in ABAP Editor (SE38)

Requirement:
Asset Acquisition Date Report

Input:
Asset number

Output:
Asset number
Sub asset number
Acquisition date

Tables:
ANLA

Solution:
Step-1: creating Structure & Table Type
 Go to SE11
 Data Type: ZFI_ASSET
 Create
 ** Structure
 Enter
 Short Description: Structure for Asset fields
Component Component Type
ANLN1 ANLN1
ANLN2 ANLN2
ZUGDT ZUGDT

 Activate
 Back
 Data Type: ZFI_TAB
 Create
 ** Table Type
 Enter
 Short Description: Table Type for Asset
 ** Line Type: ZFI_ASSET
Ashok
SAP-ADV ABAP

 Activate

Step-2: creating class definition & class implementation parts


 Go to SE24
 Object Type: ZCL_ASSET_CLASS
 Create
 Description: Asset Class
 Enter
 Enter
 Attributes tab
Attribute level visibility associated type
IT_ANLA INSTANCE PRIVATE ZFI_TAB
A_LOW INSTANCE PRIVATE ANLN1
A_HIGH INSTANCE PRIVATE ANLN1
WA_FCAT INSTANCE PRIVATE SLIS_FIELDCAT_ALV
WA_LAYOUT INSTANCE PRIVATE SLIS_LAYOUT_ALV
IT_FCAT INSTANCE PRIVATE SLIS_T_FIELDCAT_ALV

 Methods tab
Method level visibility description
CONSTRUCTOR INSTANCE PUBLIC default method

 Place cursor on constructor


 Parameters
Parameter associated type description
ASSET_LOW ANLN1 importing parameter
ASSET_HIGH ANLN1 importing parameter

 Methods
 Double click on CONSTRUCTOR
 Yes
 Place cursor between METHOD…………..ENDMETHOD
A_LOW = ASSET_LOW.
A_HIGH = ASSET_HIGH.

 Activate
 Back
Method level visibility description
GET_DATA INSTANCE PUBLIC method for getting data

 Double click on GET_DATA


 Yes
Ashok
SAP-ADV ABAP

 Place cursor between METHOD…………..ENDMETHOD

SELECT anln1 anln2 zugdt FROM ANLA INTO TABLE it_anla


WHERE anln1 BETWEEN a_low AND a_high.

 Activate
 Back
Method level visibility description
GET_DATA INSTANCE PUBLIC method for getting data

 Double click on GET_DATA


 Yes
 Place cursor between METHOD…………..ENDMETHOD

SELECT anln1 anln2 zugdt FROM ANLA INTO TABLE it_anla


WHERE anln1 BETWEEN a_low AND a_high.

 Activate
 Back
Method level visibility description
LAYOUT INSTANCE PUBLIC method for layout management

 Double click on LAYOUT


 Yes
 Place cursor between METHOD…………..ENDMETHOD

WA_LAYOUT-ZEBRA = ‘X’.
WA_LAYOUT-COLWIDTH_OPTIMIZE = ‘X’.

 Activate
 Back
Method level visibility description
FILL_CAT INSTANCE PUBLIC method for field catalogs

 Double click on FILL_CAT


 Yes
 Place cursor between METHOD…………..ENDMETHOD

WA_FCAT-FIELDNAME = ‘ANLN1’.
WA_FCAT-SELTEXT_M = ‘Asset Number’.
APPEND WA_FCAT TO IT_FCAT.

Ashok
SAP-ADV ABAP

WA_FCAT-FIELDNAME = ‘ANLN2’.
WA_FCAT-SELTEXT_M = ‘Sub Asset Number’.
APPEND WA_FCAT TO IT_FCAT.

WA_FCAT-FIELDNAME = ‘ZUGDT’.
WA_FCAT-SELTEXT_M = ‘Acquisition Date’.
APPEND WA_FCAT TO IT_FCAT.

 Activate
 Back
Method level visibility description
DISPLAY_DATA INSTANCE PUBLIC method for displaying output list

 Double click on DISPLAY_DATA


 Yes
 Place cursor between METHOD…………..ENDMETHOD

CALL FUNCTION ‘REUSE_ALV_LIST_DISPLAY’


EXPORTING
IT_FIELDCAT = IT_FCAT
IS_LAYOUT = WA_LAYOUT
TABLES
T_OUTTAB = IT_ANLA.

 Activate
 Back
 Activate

Step-3: class execution part


 Go to SE38
 Program: ZFI_ASSET_DETAILS
 Create
 Title: asset acquisition details
 Type: Executable Program
 Enter
 Enter

TABLES: ANLA.

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-000.


SELECT-OPTIONS: s_anln1 FOR anal-anln1.
SELECTION-SCREEN: END OF BLOCK b1.
Ashok
SAP-ADV ABAP

DATA obj TYPE REF TO ZCL_ASSET_CLASS.


 Pattern
 ABAP object patterns
 Enter
 Create Object
 Instance: obj
 Class: ZCL_ASSET_CLASS
 Enter

Asset_low = s_anln1-low.
Asset_high = s_anln1-high.

 Pattern
 ABAP object patterns
 Enter
 Call Method
 Instance: obj
 Class: ZCL_ASSET_CLASS
 Method: get_data
 Enter

CALL METHOD: obj->get_data,


obj->layout,
obj->fill_cat,
obj->display_data.

 Activate
 Execute
 Provide input
 Execute

Ashok
SAP-ADV ABAP

30-10-2014
Constructor:
 Constructor is a default method in Object Oriented ABAP
 It is called automatically whenever object is created
 Use this method for initializing values in Object Oriented ABAP

Ashok
SAP-ADV ABAP

Assignment:
Asset Register Report

Input:
S_anln1
S_bukrs

Output:
Asset number (anln1)
Sub asset number (anln2)
Company code (bukrs)
Plant (werks)
Capitalization date (aktlv)
Asset description (txt50)
Acquisition value (kansw)
Accumulated depreciated (knafa)
Asset location (start)
Asset class (anlkl)
Quantity (menge)
Unit of measurement (meins)
Currency (waers)

Tables:
ANLC
ANLA
ANLB
T499S
T093B

Solution:

Ashok
SAP-ADV ABAP

Assignment:
PR to GR Report

Input:
S_pr number
S_pr date

Output:
Pr number
Pr quantity
Item text
Vendor number
Vendor name
Material number
Material description
Po number
Po quantity
Gr number
Gr quantity
Pending pr
Pending po

Solution:

Ashok
SAP-ADV ABAP

Interface Functionality:
 It is a template which extends the scope of a class & implements polymorphism
 Instances cannot be created based on interface
 Interface methods are always implemented in other class

Difference between Class & Interface:


Interface Class
1. implements polymorphism 1. Cannot implement it
2. method of interface are implemented 2. Method of a class implemented in class itself
In public section of other class
3. instances cannot be create 3. Instances can be created

Requirement:
Input:
S_sales order
Deliver (radio button)
Invoice (radio button)

Solution:
Step-1: creating Structure & Table Type
 Go to SE11
 Data Type: ZSD_LIKP
 Create
 ** Structure
 Enter
 Short Description: Structure for Delivery fields
Component Component Type
VBELN VBELN_VF
LFDAT LFDAT
MATNR MATNR
LFIMG LFIMG

 Currency / Quantity Fields


Reference Table Reference Field
EKPO MEINS

 Activate
 Back
 Data Type: ZSD_LIKPTAB
 Create
Ashok
SAP-ADV ABAP

 ** Table Type
 Enter
 Short Description: Table Type for LIKP
 ** Line Type: ZSD_LIKP
 Activate

 Data Type: ZSD_VBRK


 Create
 ** Structure
 Enter
 Short Description: Structure for Invoice fields
Component Component Type
VBELN VBELN_VF
FKDAT FKDAT
MATNR MATNR
MAKTX MAKTX
FKIMG FKIMG
NETWR NETWR

 Currency / Quantity Fields


Reference Table Reference Field
VBAP VRKME
T001 WAERS

 Activate
 Back
 Data Type: ZSD_VBRKTAB
 Create
 ** Table Type
 Enter
 Short Description: Table Type for VBRK
 ** Line Type: ZSD_VBRK
 Activate

Step-2: creating class definition & class implementation parts


 Go to SE24
 Object Type: ZINT_DEL_INV
 Create
 ** Interface
 Description: interface
 Enter
 Enter
Ashok
SAP-ADV ABAP

 Attributes tab
Attribute level visibility associated type
WA_VBELN INSTANCE PUBLIC VBELN

 Methods tab
Method level visibility description
GET_DATA INSTANCE PUBLIC method for getting data
DISPLAY_DATE INSTANCE PUBLIC method for displaying data

 Place cursor on get_data


 Parameters
Parameter type associated type description
P_VBELN importing VBELN importing parameter

 Activate
 Back
 Object Type: ZCL-DEL_CLASS
 Create
 Description: Delivery class
 Enter
 Enter
 Attributes tab
Attribute level visibility associated type
IT_LIKP INSTANCE PRIVATE ZSD_LIKPTAB

 Interfaces
Interface methods description
ZINT_DEL_INV

 Methods
 Double click on GET_DATA
 Yes
 Place cursor between METHOD…………..ENDMETHOD

SELECT vbeln FROM VBFA INTO zint_del_inv~wa_vbeln


WHERE vbelv = p_vbelv
AND vbtyp_n = ‘J’.

IF zint_del_inv~wa_vbeln IS NOT INITIAL.


SELECT likp~vbeln likp~lfdat
lips~matnr lips~lfimg INTO TABLE it_likp
FROM LIKP INNER JOIN LIPS
Ashok
SAP-ADV ABAP

ON likp~vbeln = lips~vbeln
WHERE likp~vbeln = zint_del_inv~wa_vbeln.
ENDIF.

 Activate
 Back
Method level visibility description
DISPLAY_DATA INSTANCE PUBLIC method for displaying output list

 Double click on DISPLAY_DATA


 Yes
 Place cursor between METHOD…………..ENDMETHOD

CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’


EXPORTING
I_STRUCTURE_NAME = ‘ZSD_LIKP’
TABLES
T_OUTTAB = IT_LIKP.

 Activate
 Back
 Activate

 Object Type: ZCL-INV_CLASS


 Create
 Description: Invoice class
 Enter
 Enter
 Attributes tab
Attribute level visibility associated type
IT_VBRK INSTANCE PRIVATE ZSD_VBRKTAB

 Interfaces
Interface methods description
ZINT_DEL_INV

 Methods
 Double click on GET_DATA
 Yes
 Place cursor between METHOD…………..ENDMETHOD

SELECT vbeln FROM VBFA INTO zint_del_inv~wa_vbeln


Ashok
SAP-ADV ABAP

WHERE vbelv = p_vbelv


AND vbtyp_n = ‘M’.
IF zint_del_inv~wa_vbeln IS NOT INITIAL.
SELECT vbrk~vbeln vbrk~fkdat
vbrp~matnr vbrp~arktx
vbrp~fkimg vbrp~netwr INTO TABLE it_vbrk
FROM VBRK INNER JOIN VBRP
ON vbrk~vbeln = vbrp~vbeln
WHERE vbrk~vbeln = zint_del_inv~wa_vbeln.
ENDIF.

 Activate
 Back
Method level visibility description
DISPLAY_DATA INSTANCE PUBLIC method for displaying output list

 Double click on DISPLAY_DATA


 Yes
 Place cursor between METHOD…………..ENDMETHOD

CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’


EXPORTING
I_STRUCTURE_NAME = ‘ZSD_VBRK’
TABLES
T_OUTTAB = IT_VBRK.

 Activate
 Back
 Activate

Step-3: class execution part


 Go to SE38
 Program: ZSD_DEL_BILLING_DETAILS
 Create
 Title: invoice details
 Type: Executable Program
 Enter
 Enter

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-000.


PARAMETERS p_order TYPE vbeln.
SELECTION-SCREEN: END OF BLOCK b1.
Ashok
SAP-ADV ABAP

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


PARAMETERS: p_rb1 RADIOBUTTON GROUP rg1,
p_rb2 RADIOBUTTON GROUP rg1.
SELECTION-SCREEN: END OF BLOCK b2.

DATA: obj1 TYPE REF TO ZCL_DEL_CLASS,


obj2 TYPE REF TO ZCL_DEL_CLASS.

CREATE OBJECT: obj1,


obj2.

IF p_rb1 EQ ‘X’.
CALL METHOD obj1->zint_del_inv~get_data
EXPORTING
P_vbeln = p_order.

CALL METHOD obj1->zint_del_inv~display_data.

ELSE.
CALL METHOD obj2->zint_del_inv~get_data
EXPORTING
P_vbeln = p_order.

CALL METHOD obj2->zint_del_inv~display_data.


ENDIF.

 Activate
 Execute
 Provide input
 Execute

Ashok
SAP-ADV ABAP

31-10-2014
Alias:
 Go to SE24
 Object Type: ZCL_DEL_CLASS
 Change
 Aliases
Method alias name visibility
Zint_del_inv~get_data sel1 public
Zint_del_inv~display_data sel public

 Activate
 Go to SE38
 Program: ZSD_DEL_BILLING_DETAILS
 Change

Ashok
SAP-ADV ABAP

PP Module:
Production & Planning Module

Master Data for PP Module:


1. BOM (Bills of Materails)
2. Routing
3. Work Center

BOM:
 Every main material is having sub components (sub materials) called BOM
 Costing department should calculate main material cost as well as sub material cost also

T Codes:
CS01, CS02, CS03

Tables:
MAST, STOP, STKO

Key Field:
Stlnr

Routing:
These are the sequence of operations performed on a material in order to manufacture it

T Codes:
CA01, CA02, CA03

Tables:
PLKO, PLPO, PLMZ

Work Center:
It is a place where operations are carried out

T Codes:
CR01, CR02, CR03

Tables:
CRHD

Production Order:
Ashok
SAP-ADV ABAP

In order to produce finished goods sales department have to give (or) raise production order to
production department
T Codes:
CO01, CO02, CO03, COLLN

Tables:
AFKO, AFPO, AFRU

Key Field:
Aufnr

Types of Planning:
1. MRP (Material Requirement Planning)
2. Demand
3. Sales & Operations
4. Capacity

Process Flow:

Customers

Marketing

Production production inventory (or)


Planning department ware house

Vendor produce goods

Ashok
SAP-ADV ABAP

Event Functionality:
 In Object Oriented ABAP events will trigger & at the same time respective method will
be executed
 In Object Oriented ABAP every event is having Event Handler (Method) which is
executed whenever the event is fired

Syntax for Calling Event Handler:


SET HANDLER <object name>-><event handler name> FOR <object name>.

Requirement:
Production Details based on Production Order

Input:
P_furnance
P_plant
S_posting date

Output:
Purchase order number
Posting date
Production start date
Production end date
Material number
Production quantity

Solution:
Step-1: creating Structure & Table Type
 Go to SE11
 Data Type: ZPP_AFRU
 Create
 ** Structure
 Enter
 Short Description: Structure for Order fields
Component Component Type
AUFNR AUFNR
BUDAT BUDAT
LMNGA RU_LMNGA

 Currency / Quantity Fields


Reference Table Reference Field
Ashok
SAP-ADV ABAP

EKPO MEINS

 Activate
 Back
 Data Type: ZPP_AFRUTAB
 Create
 ** Table Type
 Enter
 Short Description: Table Type for AFRU
 ** Line Type: ZPP_AFRU
 Activate
 Back

 Data Type: ZPP_AFKO


 Create
 ** Structure
 Enter
 Short Description: Structure for AFKO fields
Component Component Type
AUFNR AUFNR
GSTRI CO_GSTRI
GLTRI CO_GLTRI
PLNBEZ MATNR

 Activate
 Back
 Data Type: ZPP_AFKOTAB
 Create
 ** Table Type
 Enter
 Short Description: Table Type for AFKO
 ** Line Type: ZPP_AFKO
 Activate
 Back

 Data Type: ZPP_FINAL


 Create
 ** Structure
 Enter
 Short Description: Structure for FINAL fields
Component Component Type
AUFNR AUFNR
Ashok
SAP-ADV ABAP

BUDAT BUDAT
GSTRI CO_GSTRI
GLTRI CO_GLTRI
PLNBEZ MATNR
LMNGA RU_LMNGA

 Currency / Quantity Fields


Reference Table Reference Field
EKPO MEINS

 Activate
 Back
 Data Type: ZPP_FINALTAB
 Create
 ** Table Type
 Enter
 Short Description: Table Type for FINAL
 ** Line Type: ZPP_FINAL
 Activate
 Back

Step-2: creating class definition & class implementation parts


 Go to SE24
 Object Type: ZINT_PROD_CLASS
 Create
 Description: class for production details
 Enter
 Attributes tab
Attribute level visibility associated type
WA_AFRU INSTANCE PRIVATE ZPP_AFRU
WA_AFKO INSTANCE PRIVATE ZPP_AFKO
WA_FINAL INSTANCE PRIVATE ZPP_FINAL
IT_AFRU INSTANCE PRIVATE ZPP_AFRUTAB
IT_AFKO INSTANCE PRIVATE ZPP_AFKOTAB
IT_FINAL INSTANCE PRIVATE ZPP_FINALTAB
WA_LAYOUT INSTANCE PRIVATE SLIS_LAYOUT_ALV

 Events tab
Event level visibility Description
CHECK_DATA INSTANCE PUBLIC checking data

 Methods tab
Ashok
SAP-ADV ABAP

Method level visibility description


NO_DATA INSTANCE PUBLIC method for event
 *** Detail View
 Event Handler For (check it)
 Class / Interface: ZCL_PROD_CLASS
 Event: CHECK_DATA
 Enter

Method level visibility description


GET_AFRU INSTANCE PUBLIC getting afru data

 Place cursor on GET_AFRU


 Parameters
Parameter type associated type description
P_RASCH importing RUEARSCHLU importing parameter
P_WERKS importing WERKS_D importing parameter
BUDAT_LOW importing BUDAT importing parameter
BUDAT_HIGH importing BUDAT importing parameter

 Methods
 Double click on GET_AFRU
 Yes
 Place cursor between METHOD………..ENDMETHOD

SELECT afru~aufnr afru~budat afru~lmnga INTO TABLE it_afru FROM AFRU


INNER JOIN CRHD
ON afru~arbid = crhd~objid
WHERE chrd~rasch = p_rasch
AND chrd~weks = p_werks
AND afru~budat BETWEEN budat_low AND budat_high.

IF SU-SUBRC NE 0.
RAISE EVENT CHECK_DATA.\
ENDIF.

 Activate
 Back
 Double click on NO_DATA
 Place cursor between METHOD………..ENDMETHOD

MESSAGE S000(RGS) WITH ‘No data found’.

Ashok
SAP-ADV ABAP

 Activate
 Back
Method level visibility description
GET_AFKO INSTANCE PUBLIC method for getting afko data

 Double click on GET_AFKO


 Yes
 Place cursor between METHOD…………..ENDMETHOD

IF IS NOT it_afru INITIAL.


SELECT aufnr gstri gltri plnbez INTO it_afko FROM AFKO
FOR ALL ENTRIES IN it_afru
WHERE aufnr = it_afru-aufnr.
ENDIF.

 Activate
 Back

Method level visibility description


COMBINE_DATAINSTANCE PUBLIC method for combining data

 Double click on COMBINE_DATA


 Yes
 Place cursor between METHOD…………..ENDMETHOD

LOOP AT it_afru INTO wa_afru.


wa_final-aufnr = wa_afru-aufnr.
wa_final-budat = wa_afru-budat.
wa_final-lmnga = wa_afru-lmnga.

READ TABLE it_afko INTO wa_afko WITH KEY aufnr = wa_afru-aufnr.


wa_final-gstri = wa_afko-gstri.
wa_final-gltri = wa_afko-gltri.
wa_final-plnrez = wa_afko-plnrez.

APPEND wa_final TO it_final.

ENDLOOP.

 Activate
 Back

Ashok
SAP-ADV ABAP

Method level visibility description


LAYOUT INSTANCE PUBLIC method for layout management
 Double click on LAYOUT
 Yes
 Place cursor between METHOD…………..ENDMETHOD

WA_LAYOUT-ZEBRA = ‘X’.
WA_LAYOUT-COWIDTH_OPTIMIZE = ‘X’.

 Activate
 Back

Method level visibility description


DISPLAY_DATA INSTANCE PUBLIC method for displaying data

 Double click on DISPLAY_DATA


 Yes
 Place cursor between METHOD…………..ENDMETHOD

CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’


EXPORTING
I_STRUCTURE_NAME = ‘ZPP_FINAL’
IS_LAYOUT = WA_LAYOUT
TABLES
T_OUTTAB = ZPP_FINALTAB

 Activate
 Back
 Activate

Step-3: class execution part


 Go to SE38
 Program: ZPP_PRODUCTION_DETAILS
 Create
 Title: production details
 Type: Executable Program
 Enter
 Enter

TABLES AFRU.

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-000.


Ashok
SAP-ADV ABAP

PARAMETERS: p_rasch TYPE ruearschlu,


p_werks TYPE werks_D.
SELECTION-SCREEN: END OF BLOCK b1.

DATA: obj TYPE REF TO ZCL_PROD_CLASS.

CREATE OBJECT obj.

SET HANDLER obj->no_data obj.

CALL METHOD obj->get_afru


EXPORTING
P_rasch = p_rasch
P_werks = p_werks
Budat_low = s_budat-low
Budat_high = s_budat-high.

CALL METHOD: obj->get_afko,


obj->combine_data,
obj->layout,
obj->display_data.
 Activate
 Execute
 Provide input
 Execute

Ashok
SAP-ADV ABAP

Exception Class:
In real time you will find number of exceptions (Run time errors) such as
1. Time out exception
2. SQL statement exception
3. Division by zero exception
4. No convert number exception
5. Type conflict exception
6. BCD overflow exception
7. *** Storage exception for internal table

 For all the above exceptions SAP is providing standard exception classes
 Exception class starting with prefix ‘CX’
 These exception classes should be provided with in TRY……………ENDTRY using
CATCH keyword

Example:
DATA: v1 TYPE I VALUE 0,
v2 TYPE I,
v3 TYPE I.

TRY.
v3 = v1 / v2.
CATCH CX_SY_ZERODIVIDE.
MESSAGE ‘Division by zero exception’ TYPE I.
ENDTRY.

Ashok
SAP-ADV ABAP

ALV Object Oriented Programming: SLV


 SAP List Viewer
 It is advance to ALVs
 In OOALV we should work with Custom Control (List Viewer Control)
 In ALVs you cannot perform advanced operations such as
1. Maintaining buttons
2. Exception coding
3. Hyperlinks …………………..etc

 All these features are maintained by using a control called List Viewer Control
 SLV is totally based on Object Oriented Programming

01-11-2014
Custom Control:

------------ screen 100

----------------- custom control (container)

Steps in Custom Control:


Step-1:
Identify location of control using class CL_GUI_CUSTOM_CONTAINER

Step-2:
Display control in the location identified using class CL_GUI_AVL_GRID

Step-3:
Display data in the control using method SET_TABLE_FOR_FIRST_DISPLAY of
CL_GUI_GRID class

Ashok
SAP-ADV ABAP

Requirement:
Report for Quality Notifications

Input:
S_date

Output:
Notification number
Complaint text
Date
Material code

Solution:
 Go to SE38
 Program: ZQM_QUALITY_NOTIF
 Create
 Title: Quality Notifications
 Type: Executable Program
 Enter
 Enter

TABLES QMEL.

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-000.


SELECT-OPTIONS: s_erdat FOR qmel-erdat.
SELECTION-SCREEN: END OF BLOCK b1.

TYPES: BEGIN OF ty_qmel,


qmnum TYPE qmnum,
qmtxt TYPE qmtxt,
erdat TYPE erdat,
matnr TYPE matnr,
END OF ty_qmel.

DATA: it_qmel TYPE TABLE OF ty_qmel.

DATA: wa_fcat TYPE lvc_s_fcat,


wa_layo TYPE lvc_s_layo,
it_fcat TYPE lvc_t_fcat.

Ashok
SAP-ADV ABAP

* defining objects for custom conrol


DATA: container TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
grid TYPE REF TO CL_GUI_ALV_GRID.

PERFORM get_qmel.
PERFORM layout.
PERFORM fill_cat.
CALL SCREEN 100.

FORM get_qmel.
SELECT qmnum qmtxt erdat matnr FROM QMEL INTO TABLE it_qmel
WHERE erdat IN s_erdat.
ENDFORM.

FORM layout.
WA_LAYO-ZEBRA = ‘X’.
WA_LAYO-CWIDTH_OPT = ‘X’.
ENDFORM.

FORM fill_cat.
wa_fcat-fieldname = ‘QMNUM’.
wa_fcat-scrtext_m = ‘Notification Number’.
APPEND wa_fcat TO it_fcat.

wa_fcat-fieldname = ‘QMTXT’.
wa_fcat-scrtext_m = ‘Complaint Text’.
APPEND wa_fcat TO it_fcat.

wa_fcat-fieldname = ‘ERDAT’.
wa_fcat-scrtext_m = ‘Date’.
APPEND wa_fcat TO it_fcat.

wa_fcat-fieldname = ‘MATNR’.
wa_fcat-scrtext_m = ‘Material Number’.
APPEND wa_fcat TO it_fcat.

ENDFORM.

 Activate
 Double click on 100
 Yes
 Short Description: Screen 100
Ashok
SAP-ADV ABAP

 Layout
 Place Custom Control on the screen
 Double click on Custom Control
name: container
 Close
 Flow Logic
 Remove comment for MODULE STATUS_100
 Double click on STATUS_100
 Yes
 Main Program
 Enter
 Place cursor between MODULE…………ENDMODULE of STATUS_100

CREATE OBJECT container


EXPORTING
CONTAINER_NAME = ‘container’.

IF SY-SUBRC EQ 0.
CREATE OBJECT grid
EXPORTING
I_PARENT = container.

IF SY-SUBRC EQ 0.
CALL METHOD grid->set_table_for_first_display
EXPORTING
IS_LAYOUT = wa_layo
CHANGING
IT_FIELDCATALOG = it_fcat
IT_OUTTAB = it_qmel.
ENDIF.

ENDIF.
 Activate
 Back

 Remove comment for SET PF_STATUS ‘BACK’.


 Double click on BACK
 Yes
 Expand Function Key
 Provide BACK
 Activate
 Back
Ashok
SAP-ADV ABAP

 Remove comment for MODULE USER_COMMAND_100.


 Double click on USER_COMMAND_100
 Yes
 Main Program
 Enter

CASE SY-UCOMM.
WHEN ‘BACK’.
LEAVE TO SCREEN 0.
ENDCASE.

 Activate
 Back
 Activate
 Back
 Execute
 Provide input
 Execute

Ashok
SAP-ADV ABAP

Assignment:
Packing cost material report using interactive functionality with 2 custom controls

Input:
S_matnr
S_werks

Output:
Material code
BOM component
Material description
BOM component description
BOM quantity
Amount

Interactive Logic:
If I double click on any material I should switch to MM03 along with material code

Solution:
ZPP_BOM_DETAILS

TYPE-POOLS SLIS.

TABLES: MAST, STAS, STOP, MAKT, MBEW.

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-000.


SELECT-OPTIONS: s_matnr FOR mast-matnr,
s_werks FOR mast-werks.
SELECTION-SCREEN: END OF BLOCK b1.

* declaring objects for custom control


DATA: container TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
container1 TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
l_tree TYPE REF TO CL_GUI_ALV_TREE_SIMPLE,
grid TYPE REF TO CL_GUI_ALV_GRID.

DATA: n(5) TYPE C,


header(100) TYPE C,
wa_header TYPE SLIS_LISTHEADER,
it_header TYPE SLIS_T_LISTHEADER.
Ashok
SAP-ADV ABAP

TYPES: BEGIN OF ty_mast,


matnr TYPE matnr,
stlnr TYPE stnum,
stlal TYPE stlal,
END OF ty_mast.

TYPES: BEGIN OF ty_stas,


stlnr TYPE stnum,
stlal TYPE stlal,
stlkn TYPE stlkn,
END OF ty_stas.

TYPES: BEGIN OF ty_stpo,


stlnr TYPE stnum,
idnrk TYPE idnrk,
menge TYPE menge_D,
END OF ty_stpo.

TYPES: BEGIN OF ty_makt,


matnr TYPE matnr,
maktx TYPE maktx,
END OF ty_makt.

TYPES: BEGIN OF ty_mbew,


matnr TYPE matnr,
verpr TYPE verpr,
END OF ty_mbew.

DATA: wa_mast TYPE ty_mast,


wa_makt TYPE ty_makt,
wa_makt1 TYPE ty_makt,
wa_stpo TYPE ty_stpo,
wa_mbew TYPE ty_mbew,
it_mast TYPE TABLE OF ty_mast,
it_makt TYPE TABLE OF ty_makt,
it_makt1 TYPE TABLE OF ty_makt,
it_stas TYPE TABLE OF ty_stas,
it_mbew TYPE TABLE OF ty_mbew.

TYPES: BEGIN OF ty_final,


Ashok
SAP-ADV ABAP

matnr TYPE matnr,


maktx TYPE maktx,
idnrk TYPE idnrk,
maktx1 TYPE maktx,
menge TYPE menge_D,
verpr TYPE verpr,
END OF ty_final.

DATA: wa_final TYPE ty_final,


it_final TYPE TABLE OF ty_final.

DATA: WA_FCAT TYPE LVC_S_FCAT,


WA_LAYO TYPE LVC_S_LAYO,
WA_SORT TYPE LVC_S_SORT,
IT_SORT TYPE LVC_T_SORT,
IT_FCAT TYPE LVC_T_FCAT.

CLASS cl_click DEFINITION.


PUBLIC SECTION.
METHODS: click FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
IMPORTING e_row.
ENDCLASS.

CLASS cl_click IMPLEMENTATION.


METHOD click.
READ TABLE it_final INTO wa_final INDEX e_row.

SET PARAMETER ID ‘MAT’ FIELD wa_final-idnrk.

CALL TRANSACTION ‘MM03’ AND SKIP FIRST SCREEN.

END METHOD.

END CLASS.

START-OF-SELECTION.
PERFORM get_mast.
PERFORM get_stas.
PERFORM get_stpo.
PERFORM get_makt.
PERFORM get_mbew.
PERFORM combine_data.
Ashok
SAP-ADV ABAP

PERFORM sort.
PERFORM layout.
PERFORM fill_cat.
CALL SCREEN 100.

FORM get_mast.
SELECT matnr stlnr stlal FROM MAST INTO TABLE it_mast
WHERE matnr IN s_matnr
AND werks IN s_werks.
ENDFORM.

FORM get_stas.
IF NOT it_mast IS INITIAL.
SELECT stlnr stlal stlkn FROM STAS INTO TABLE it_stas
FOR ALL ENTRIES IN it_mast
WHERE stlnr = it_mast-stlnr
AND stlty EQ ‘M’.
ENDIF.
ENDFORM.

FORM get_stpo.
IF NOT it_stas IS INITIAL.
SELECT stlnr ldnrk menge FROM STOP INTO TABLE it_stpo
FOR ALL ENTRIES IN it_stas
WHERE stlnr = it_stas-stlnr
AND stlkn = it_stas-stlkn
AND stlty EQ ‘M’.
ENDIF.
ENDFORM.

FORM get_makt.
IF NOT it_mast IS INITIAL.
SELECT matnr maktx FROM MAKT INTO TABLE it_makt
FOR ALL ENTRIES IN it_mast
WHERE matnr = it_mast-matnr
AND spras EQ ‘EN’.
ENDIF.

IF NOT it_stpo IS INITIAL.


SELECT matnr maktx FROM MAKT INTO TABLE it_makt1
FOR ALL ENTRIES IN it_stpo
WHERE matnr = it_stpo-idnrk
Ashok
SAP-ADV ABAP

AND spras EQ ‘EN’.


ENDIF.
ENDFORM.

FORM get_mbew.
IF NOT it_stpo IS INITIAL.
SELECT matnr verpr FROM MBEW INTO TABLE it_mbew
FOR ALL ENTRIES IN it_stpo
WHERE matnr = it_stpo-ldnrk.
ENDIF.
ENDFORM.

FORM combine_data.
LOOP AT it_mast INTO wa_mast.
LOOP AT it_stpo INTO wa_stpo WHERE stlnr = wa_mast-stlnr.
wa_final-matnr = wa_mast-matnr.

READ TABLE it_makt INTO wa_makt WITH KEY matnr = wa_mast-matnr.


wa_final-maktx = wa_makt-maktx.
wa_final-idnrk = wa_stpo-idnrk.

READ TABLE it_makt1 INTO wa_makt WITH KEY matnr = wa_stpo-idnrk.


wa_final-maktx1 = wa_makt-maktx.
wa_final-menge = wa_stpo-menge.

READ TABLE it_mbew INTO wa_mbew WITH KEY matnr = wa_stpo-idnrk.


wa_final-verpr = wa_mbew-verpr.

APPEND wa_final TO it_final.

ENDLOOP.

ENDFORM.

FORM fill_cat.
wa_fcat-fieldname = ‘MATNR’.
wa_fcat-seltext_m = ‘Material Code’.
APPEND wa_fcat TO it_fcat.

wa_fcat-fieldname = ‘MAKTX’.
wa_fcat-seltext_m = ‘Material Description’.
APPEND wa_fcat TO it_fcat.
Ashok
SAP-ADV ABAP

wa_fcat-fieldname = ‘IDNRK’.
wa_fcat-seltext_m = ‘BOM Component’.
APPEND wa_fcat TO it_fcat.

wa_fcat-fieldname = ‘MAKTX1’.
wa_fcat-seltext_m = ‘BOM Component Description’.
APPEND wa_fcat TO it_fcat.

wa_fcat-fieldname = ‘MENGE’.
wa_fcat-seltext_m = ‘Quantity’.
wa_fcat-do_sum = ‘X’.
APPEND wa_fcat TO it_fcat.

wa_fcat-fieldname = ‘VERPR’.
wa_fcat-seltext_m = ‘Amount’.
wa_fcat-do_sum = ‘X’.
APPEND wa_fcat TO it_fcat.

ENDFORM.

FORM sort.
wa_sort-fieldname = ‘MATNR’.
wa_sort-up = ‘X’.
wa_sort-subtot = ‘X’.
APPEND wa_sort TO it_sort.
ENDFORM.

FORM layout.
wa_layout-zebra = ‘X’.
wa_layout-colwidth_optimize = ‘X’.
ENDFORM.

 Double click 100


 Yes
 Short Description: Screen 100
 Layout
 Design screen as per requirement
 Layout
 Remove comment for MODULE STATUS_100 OUTPUT
 Double click on STATUS_100
 Yes
Ashok
SAP-ADV ABAP

 Main Program
 Enter
 Place cursor between MODULE…………..ENDMODULE

wa_header-typ = ‘H’.
wa_header-info = ‘Reddy Labs’.
APPEND wa_header TO it_header.

DESCRIBE TABLE it_final LINES n.

CONCATENATE ‘Number of Records’ n INTO header SAPARATED BY ‘:’

wa_header-typ = ‘S’.
wa_header-info = header.
APPEND wa_header TO it_header.

CREATE OBJECT container1


EXPORTING
CONTAINER_NAME = ‘container1’.

CREATE OBJECT l_tree


EXPORTING
I_PARENT = ‘container1’.

CALL METHOD l_tree->create_report_header


EXPORTING
CONTAINER_NAME = ‘container’.

IF SY-SUBRC NE 0.
CREATE OBJECT grid
EXPORTING
I_PARENT = container.

IF SY-SUBRC EQ 0.
CALL METHOD grid->set_table_for_first_display
EXPORTING
I_SAVE = ‘X’
IS_LAYOUT = wa_layout
CHANGING
IT_OUTTAB = it_final
IT_FIELDCATALOG = it_fcat
IT_SORT = it_sort.
Ashok
SAP-ADV ABAP

DATA obj TYPE REF TO CL_CLICK.


CREATE OBJECT obj.

SET HANDLER obj->click FOR grid.


ENDIF.
ENDIF.
ENDMODULE.

 Remove comment for MODULE USER_COMMAND_100 INPUT.


 Double click on COMMAND_100
 Yes
 Main Program
 Enter
 Place cursor between MODULE…………..ENDMODULE

CASE SY-UCOMM.
WHEN ‘&F03’.
LEAVE TO SCREEN 0.
ENDCASE.

Ashok
SAP-ADV ABAP

03-11-2014
MAST Table:
It holds material header data

Fields:
1. MATNR ------------ material number
2. WERKS ------------ plant
3. STLAN ------------- BOM usage
4. STLAL ------------- alternate BOM
5. STLNR ------------- BOM number

STAS Table:
It holds items in BOM

Fields:
1. STLTY ------------ BOM category
2. STLNR ------------ BOM number
3. STLAL ------------ alternate BOM
4. STLKN ----------- BOM item number

STPO Table:
It holds BOM item data

Fields:
1. STLTY ------------ BOM category
2. STLNR ------------ BOM number
3. STLKN ----------- BOM item number
4. IDNRK ----------- BOM component (MATNR)
5. MENGE --------- quantity
6. MEINS ---------- unit of measurement

MBEW Table:
It holds material valuation data

Fields:
1. MATNR ---------- material number
2. BWKEY ---------- plant
3. LBKUM ---------- total stock
4. SALK3 ----------- total value
5. VERPR ---------- moving average price
Ashok
SAP-ADV ABAP

Exception Coding:
 Using Exception coding you can display color in ALV OOPs
 For displaying color you can add a field called exception using standard field EXCP-
FNAME which is part of LVC_S_LAYO

Requirement:
Open Sales Order Report

 The sales orders for which delivery is partially done are called open sales orders
 In some companies delivery (or) invoice is done for more quantity then given in sales
order
 Such sales orders are opening nature

Input:
S_kunnr
S_vbeln ------- sales order number
P_werks
S_erdat

Output:
Sales order number
Sales order date
Customer number
Customer name
Sale order quantity
Delivery quantity
Invoice quantity
Open quantity

Solution:
ZSD_OPEN_SALESORDER_REPORT

Ashok
SAP-ADV ABAP

Button Functionality:
Using this functionality you can add additional buttons on ALV tool bar

Requirement:
Employee Allowances Report

Input:
S_pernr --------- employee number
S_persg --------- employee group
S_abkrs --------- payroll area
S_persk --------- employee sub group

Output:
Check box
Employee number
Date of birth
Date of joining
Medical allowance
CA (Canteen Allowance)
LTA (Leave Travelling Allowance)
INSERT (button)
SELECT ALL (button)
DESELECT ALL (button)

Solution:
Step-1:
 Go to SE11
 Database Table: ZHR_TAB_ALLOW
 Create
 Short Description: Table for allowances
Field Data Element
MANDT MANDT
SEL CHAR1
PERNR PERSNO
GBDAT GBDAT
DOJ ZEMPDOJ
MEDICAL ZMEDICAL
LAT ZLTA
CA ZCA

Ashok
SAP-ADV ABAP

 Activate
 Back
Step-2:
 Go to SE38
 Program: ZHR_EMPLOYEE_ALLOWANCE_REPORT
 Create
 Title: employee allowance report using button functionality
 Type: Executable Program
 Enter
 Enter

TABLES PERNR.

INFO TYPES: 0001, 0002.

SELECTION-SCREEN: BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-000.


SELECT-OPTIONS: s_pernr FOR pernr-pernr,
s_persg FOR pernr-persg,
s_abkrs FOR pernr-abkrs,
s_persk FOR pernr-persk.
SELECTION-SCREEN: END OF BLOCK b1.

DATA: container TYPE REF TO CL_GUI_CUSTOM_CONTAINER,


grid TYPE REF TO CL_GUI_ALV_GRID.

DATA: wa_button TYPE STB_BUTTON,


wa_layo TYPE LVC_S_LAYO,
wa_fcat TYPE LVC_S_FCAT,
it_fcat TYPE LVC_T_FCAT.

DATA: wa_allow TYPE ZHR_TAB_ALLOW,


it_allow TYPE TABLE OF ZHR_TAB_ALLOW.

CLASS cl_button DEFINITION.

PUBLIC SECTION.
METHODS: tool FOR EVENT TOOLBAR OF CL_GUI_ALV_GRID IMPORTING
e_object e_interactive,
command FOR EVENT USER_COMMAND OF CL_GUI_ALV_GRID
IMPORTING e_ucomm.

ENDCLASS.
Ashok
SAP-ADV ABAP

CLASS cl_button IMPLEMENTATION.

METHOD tool.
wa_button-function = ‘INSERT’.
wa_button-text = ‘Insert’.
APPEND wa_button TO e_object->mt_toolbar.

wa_button-function = ‘SAL’.
wa_button-text = ‘Select All’.
APPEND wa_button TO e_object->mt_toolbar.

wa_button-function = ‘DALL’.
wa_button-text = ‘Deselect All’.
APPEND wa_button TO e_object->mt_toolbar.

ENDMETHOD.

METHOD command.

CASE e_ucomm.
WHEN ‘INSERT’.
LOOP AT it_allow INTO wa_allow WHERE sel = ‘X’.
MODIFY ZHR_TAB_ALLOW FROM wa_allow.
ENDLOOP.

WHEN ‘SALL’.
LOOP AT it_allow INTO wa_allow.
wa_allow-sel = ‘X’.
MODIFY it_allow FROM wa_allow TRANSPORING sel.
ENDLOOP.

WHEN ‘DALL’.
LOOP AT it_allow INTO wa_allow.
wa_allow-sel = ‘ ’.
MODIFY it_allow FROM wa_allow TRANSPORING sel.
ENDLOOP.

ENDCASE.

CALL METHOD grid->refresh_table_display.


Ashok
SAP-ADV ABAP

ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
GET PERNR.
CHECK pernr-pernr IN s_pernr
AND pernr-persg IN s_persg
AND pernr-persk IN s_persk
AND pernr-abkrs IN s_abkrs.

IF SY-SUBRC EQ 0.
PERFORM get_emp.
ENDIF.

END-OF-SELECTION.
PERFORM layout.
PERFORM fill_cat.
CALL SCREEN 100.

FORM get_emp.
wa_allow-pernr = pernr-pernr.
wa_allow-gbdat = pernr-gbdat.

CALL FUNCTION ‘RP_GET_HIRE_DATE’


EXPORTING
PERSNR = pernr-pernr
CHECK_INFOTYPES = ‘0001’
IMPORTING
HIREDATE = wa_allow-doj.

APPEND wa_allow TO it_allow.

CLEAR wa_allow.

ENDFORM.

FORM layout.
wa_layo-zebra = ‘X’.
wa_layo-cwidth_opt = ‘X’.
ENDFORM.

Ashok
SAP-ADV ABAP

FORM fill_cat.
wa_fcat-fieldname = ‘SEL’.
wa_fcat-scrtext_m = ‘Check’.
wa_fcat-checkbox = ‘X’.
wa_fcat-edit = ‘X’.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = ‘PERNR’.
wa_fcat-scrtext_m = ‘Employee Number’.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = ‘GBDAT’.
wa_fcat-scrtext_m = ‘Date of Birth’.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = ‘DOJ’.
wa_fcat-scrtext_m = ‘Date of Joining’.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = ‘MEDICAL’.
wa_fcat-scrtext_m = ‘Medical Allowance’.
wa_fcat-edit = ‘X’.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = ‘LTA’.
wa_fcat-scrtext_m = ‘Leave Travelling Allowance’.
wa_fcat-edit = ‘X’.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.

wa_fcat-fieldname = ‘CA’.
wa_fcat-scrtext_m = ‘Canteen Allowance’.
wa_fcat-edit = ‘X’.
APPEND wa_fcat TO it_fcat.
CLEAR wa_fcat.
Ashok
SAP-ADV ABAP

ENDFORM.
 Double click on 100
 Yes
 Short Description: Screen 100
 Layout
 Design screen as per your requirement
 Flow Logic
 Remove comment for MODULE STATUS_100 OUTPUT.
 Double click on STATUS_100
 Place cursor between MODULE…………….ENDMODULE

SET PF_STATUS ‘BACK’.

CREATE OBJECT container


EXPORTING
CONTAINER_NAME = ‘container’.

IF SY-SUBRC EQ 0.
CREATE OBJECT grid
EXPORTING
I_PARENT = container.

IF SY-SUBRC EQ 0.
CALL METHOD grid->set_table_for_first_display
EXPORTING
IS_LAYOUT = wa_layo
CHANGING
IT_FIELDCATALOG = it_fcat
IT_OUTTAB = it_allow.

DATA obj TYPE REF TO CL_BUTTON.

CREATE OBJECT obj.

SET HANDLER: obj->tool FOR grid,


obj->command FOR grid.

CALL METHOD grid->set_toolbar_interactive.

ENDIF.
ENDIF.
Ashok
SAP-ADV ABAP

ENDMODULE.
 Remove comment for MODULE USER_COMMAND_100 INPUT.
 Double click on USER_COMMAND_100
 Place cursor between MODULE…………….ENDMODULE

CASE SY-UCOMM.
WHEN ‘BACK’.
LEAVE TO SCREEN 0.
ENDCASE.

04-11-2014
Syntax for Declaring Event Handler:
METHODS: <event handler> FOR EVENT <event name> OF <class name>
IMPORTING <param 1> <param 2>………………..

Note:
 E_object is an instance created based on standard class
CL_ALV_EVENT_TOOLBAR_SET
 The respective class is having an attribute MT_TOOLBAR (Table Type)

Ashok
SAP-ADV ABAP

Hyperlinks Functionality:
Using hyperlink functionality you can switch to respective hyperlink based on specific URL
address

SAP is providing a structure LVC_S_HYPE which is having fields


1. HANDLE (integer)
2. HREF (url)

Requirement:
Vendor hyperlinks report

Input:
S_erdat

Output:
Vendor number
Vendor name

Hyperlink Logic:
When you click on vendor number we have to switch particular web address

Solution:
ZMM_VENDOR_LINKS

Ashok
SAP-ADV ABAP

Questions & Answers:

Module Pool Programming:


Ques-1:
Suppose in table control when I entered few records then I selected ‘Enter’ option, I found that
the records are completely vanished from table control. Why it happens & What logic you will
write to avoid problem?
Ans:
 When you select ‘Enter’ control will moves from screen to program
 In program there is no logic provided for storing the table control data in internal table
 So nothing is transferred back to table control screen
 So it looks like empty
Logic:
MODIFY it_demo FROM zmm_demo INDEX vcontrol-current_line.
IF SY-SUBRC NE 0.
APPEND zmm_demo TO it_demo.
ENDIF.

Ques-2: In table control how you can perform auto calculations whenever ‘Enter’ key selected?
Ans:
 Remove comment for SET PF_STATUS.
 Under MODULE STATUS_100 ‘xxxxxxxxx’.
 Remove ‘xxxxxxxxxx’ provide ’BACK’.
 Yes
 Yes
 Short Text: BACK
 Enter
 Expand function keys option
 _/ ENTER
 Activate
 You will find a pop-up, Enter
 Function Text: Enter
 Enter
 Back (F3)
 Activate program

Ashok
SAP-ADV ABAP

Ques-3: What is the difference between SSCRFIELDS-UCOMM & SY-UCOMM?


Ans:
 SSCRFIELDS is a structure for maintaining text for the buttons in SELECTION-
SCREEN
 SSCRFIELDS-UCOMM returns FCT code for buttons maintained in SELECTION-
SCREEN
 SY-UCOMM returns FCT code for buttons maintained in SCREEN
 SY-UCOMM will works for both Screen & Selection-screen

Ashok
SAP-ADV ABAP

Reports:
Ques-1:
Suppose there are 20 pages in my report. How many times INITIALIZATION will triggers &
TOP-OF-PAGE will triggers?
Ans:
 INITIALIZATION will triggers only 1 time
 TOP-OF-PAGE will triggers 20 times

Ques-2: What is LOAD-OF-PROGRAM event?


Ans:
This event will triggers before INITIALIZATION & once your program is loaded into memory

Ques-3: What is the flow of events?

Ans:

 INITIALIZATION
 AT SELECTION-SCREEN OUTPUT
 START-OF-SELECTION
 END-OF-SELECTION
 TOP-OF-PAGE
 END-OF-PAGE

Ques-4: What do you mean by restricted & unrestricted stock?


Ans:
 The stock which is produced by production department & it is in Quality check (or) it is
in hold (or) stock returns is called restricted stock
 The stock which is ready for sale is called unrestricted stock

*** Ques-5: This report is already provided by SAP (MMB). Then why you created it?
Ans:
 MMB is providing materials details plant wise & storage location wise material by
material
 My client gave a requirement for viewing all restricted & unrestricted stock at one time

Ashok
SAP-ADV ABAP

*** Ques-6: Explain procedure of working with Hierarchal ALVs?


Answer:
 In Hierarchal Sequential ALVs we have to create 2 internal tables
 One for Header data (it_final1) & another for Item data (it_final)
 Both these internal tables should have a common field called KEY field
 In Header internal table the Key field should be unique
 In Item internal table the Key field should having number of items based on that unique
key
 Pass these two internal tables to a function module called
REUSE_ALV_HIERSEQ_LIST_DISPLAY

Ashok
SAP-ADV ABAP

FAQS IN REPORTS
1.) What is the purpose of reports in real time?
Ans:
In real time ABAP Reports are designed for analysis & based on the that analysis decision
making will done

2.) What are the three mandatory details for generating report?
Ans:
a.) Input
b.) Processing Logic
c.) Output

3.) What are the flow of events in ABAP reports?


Ans:
Flow of Events:
 Initialization
 At selection screen
 Start of selection
 End of selection
 Top of page
 Top of page during line selection
 End of page
 At user command

4.) What is the diff b/w START-OF-SELECTION & AT SELECTION-SCREEN?


Ans:
START-OF-SELECTION:
 This event will triggers once your selection-screen is processed
 It triggers when you select F8 function key
 It triggers before reading data from database
 It triggers for all processing blocks in a program
 It is a default event triggered before extracting data from database

AT SELECTION-SCREEN:
 It triggers once the control leaves from selection-screen & still selection-screen is in
active mode
 i.e. It triggers at end of PAI when all the values are passed from selection-screen to
program variables
Ashok
SAP-ADV ABAP

Ashok
SAP-ADV ABAP

5.) What is the diff b/w AT SELECTION-SCREEN & AT SELECTION-SCREEN OUTPUT?


Ans:
AT SELECTION-SCREEN:
 It triggers once the control leaves from selection-screen & still selection-screen is in
active mode
 i.e. It triggers at end of PAI when all the values are passed from selection-screen to
program variables

AT SELECTION-SCREEN OUTPUT:
 It triggers after initialization & before selection-screen display
 Use this event for modifying selection-screen

6.) What is the diff b/w INITIALIZATION & START-OF-SELECTION?


Ans:
INITIALIZATION:
It triggers before selection-screen display
Note:
Use this event for initializing
4. Default values in selection-screen
5. Texts on push buttons in selection-screen
6. Texts for blocks, radio buttons, check boxes…………..etc

START-OF-SELECTION:
 This event will triggers once your selection-screen is processed
 It triggers when you select F8 function key
 It triggers before reading data from database
 It triggers for all processing blocks in a program
 It is a default event triggered before extracting data from database

7.) Why is it mandatory to use start-of-selection when we are writing


initialization and at selection-screen?
Ans:

8.) What is LOAD-OF-PROGRAM event?


Ans:
This event will triggers before INITIALIZATION & once your program is loaded into memory

Ashok
SAP-ADV ABAP

9.) What are the events in classical reporting?


Ans:
7. INITIALIZATION
8. AT SELECTION-SCREEN
9. START-OF-SELECTION
10.END-OF-SELECTION
11.TOP-OF-PAGE
12.END-OF-PAGE

10.) What are the events in interactive reporting?


Ans:
 AT LINE-SELECTION:
 TOP-OF-PAGE DURING LINE-SELECTION

11.) What is the functionality of AT LINE-SELECTION?


Ans:
It triggers whenever user interacts with a list

12.) What is the functionality if GET CURSOR keyword?


Ans:
If fetches the field name & value selected by user from output list

Syntax:
GET CURSOR FIELD <field name> VALUE <value>.

13.) How u can transfer data b/w two reports?


Ans:

14.) What is the functionality of SY-LISEL in interactive reporting?


Ans:
It returns list of contents selected by user from output list

15.) What is the functionality of SY-LSIND in interactive reporting?


Ans:
It returns current list index

16.) How to switch from 14 to 4 list in interactive reporting?


Ans:

Ashok
SAP-ADV ABAP

17.) What is the output of following code?

INITIALIZATION.

WRITE:/ 'Hello Abap'.


Ans:

18.) What is the diff between SELECT SINGLE .... & SELECT SINGLE…. UP TO 1 ROW?
Ans:

19.) What is the functionality of SCREEN internal table in reports?


Ans:
20.) How u can create dynamic selection screens in reports?
Ans:

21.) How u make a field mandatory apart from OBLIGATORY keyword?


Ans:

22.) How u can make a selection screen field in invisible mode?


Ans:
SLIS_FIELDCAT_ALV is a standard SLIS structure with following field
EDIT_MASK ------- it hides the field data

23.) What are various events used on ALV reporting?


Ans:
WA_EVENT-NAME = ‘USER_COMMAND’.
WA_EVENT-FORM = ‘INTERACTIVE’.

24.) What are the function modules in ALV reporting?


Ans:
1. REUSE_ALV_GRID_DISPLAY
It is for display the data in ALV grid

2. REUSE_ALV_BLOCK_LIST_INIT
It initializes lists in blocked alvs

3. REUSE_ALV_BLOCK_LIST_APPEND
This function module
 Maintains field catalogs
 Maintains data in list
Ashok
SAP-ADV ABAP

 Append field catalogs & data with layout

4. REUSE_ALV_BLOCK_LIST_DISPLAY
It displays data in list in blocked alvs

5. REUSE_ALV_HIRESEQ_LIST_DISPLAY
Using this function module, you can display the in hierarchal format

25.) What is the diff b/w REUSE_ALV_LIST_DISPLAY & REUSE_ALV_GRID_DISPLAY?


Ans:

26.) How u can perform following operations in alvs:

a.) Editing field values?


Ans:
SLIS_FIELDCAT_ALV is a standard SLIS structure with following field
EDIT ------------------- by default the field catalogs in a layout are in display mode. Using
this option a field should be converted into change mode

b.) How to get hotspot on fields?


Ans:
SLIS_FIELDCAT_ALV is a standard SLIS structure with following field
HOTSPOT ------------ provides hand symbol

c.) How u can fix a column?


Ans:
SLIS_FIELDCAT_ALV is a standard SLIS structure with following field
FIX_COLOUMN ----------- you can fix a coloumn

d.) How u can color a particular field?


Ans:
SLIS_FIELDCAT_ALV is a standard SLIS structure with following field
EMPHASIZE ------- it provides a specific default color for a field in ALV grid

e.) How u can remove zeros in alv output?


Ans:
SLIS_FIELDCAT_ALV is a standard SLIS structure with following field
NO_ZERO ---------- removes zeros from output list

f.) How u can highlight a particular row in alv reporting?


Ans:

Ashok
SAP-ADV ABAP

In layout work area you should pass INFO-FIELDNAME for displaying row with a specific
color given in output list

g.) How u can create checkboxes?


Ans:
SLIS_FIELDCAT_ALV is a standard SLIS structure with following field
CHECKBOX ------- with this option you can create check box for a specific field

h.) How u can perform auto totals and subtotals?


Ans:
SLIS_FIELDCAT_ALV is a standard SLIS structure with following field
DO_SUM ----------- provides totals

27.) How to debug background jobs?


Ans:

28.) Explain the fields of SCREEN Internal table?


Ans:

29.) Explain how hierarchal alvs works?


Ans:
 In Hierarchal Sequential ALVs we have to create 2 internal tables
 One for Header data (it_final1) & another for Item data (it_final)
 Both these internal tables should have a common field called KEY field
 In Header internal table the Key field should be unique
 In Item internal table the Key field should having number of items based on that unique
key
 Pass these two internal tables to a function module called
REUSE_ALV_HIERSEQ_LIST_DISPLAY

30.) What is the function module used for printing heading and logo in alv?
Ans:
SLIS_LISTHEADER:
It is a standard ALV structure for maintaining headings in output list
It is having following fields
4. TYP -------------- type of heading (H, S, A)
5. KEY ------------- text for heading in 20 characters
6. INFO ------------ text for heading in 60 characters

Navigation for Maintaining Logos:


 Go to Paint
 Design a picture
Ashok
SAP-ADV ABAP

 Save it on desktop

 Go to OAER
 Class Name: Pictures
 Class Type: OT
 Object Key: ABAP
 Execute
 At bottom expand Standard Document Types
 Double click on Screen
 Select you Logo
 Enter
 Enter

31.) What is event internal table in ALVS?

Ans:
SLIS_ALV_EVENT:
It is a standard ALV structure for maintaining events
It is having following fields
3. NAME ----------- name of event
4. FORM ----------- subroutine name

32.) How u can work with interactive alvs?


Ans:
If I double click on customer code switch to XD03 application

Syntax:
FORM <interactive> USING <ucomm> TYPE SY-UCOMM <sel> TYPE
SLIS_SELFIELD.
-------------
-------------
ENDFORM.

33.) Explain the parameters of REUSE_ALV_GRID_DISPLAY?


Ans:
REUSE_ALV_GRID_DISPLAY
It is for display the data in ALV grid
The parameters are
13.Current program name
It is important for activating layout management & for displaying logos & headings

14.Layout work area

Ashok
SAP-ADV ABAP

15.Field catalog internal table


16.I_CALLBACK_USER_COMMAND
It is for interactive purpose

17.I_STRUCTURE_NAME
For providing structure

18.I_BACKGROUND_ID
For maintaining background pictures

19.I_GRID_TITLE
For maintaining title in ALV grid
20.IT_SORT
For sorting data & for maintaining sub totals
21.I_SAVE
For saving layouts

22.IT_EVENTS
For events internal table

23.IS_PRINT
For deactivating (or) activating the print mode for PDF formats…………etc

24.T_OUTTAB
For output internal table

34.)What are the various ways of creating FIELDCATALOGS in ALVS?Which one


u feel is the best?Why?
Ans:
There are 3 ways to create FIELD CATALOGS
4. Manually
Ex: WA_FCAT-FIELDNAME = ‘KUNNR’.
WA_FCAT-SELTEXT_M = ‘Customer Code’.
APPEND WA_FCAT TO IT_FCAT.
5. By using REUSE_ALV_FIELDCATALOG_MERGE function module
6. By passing DDIC Structure name to REUSE_ALV_LIST_DISPLAY function module

35.) What is the functionality of REUSE_ALV_FIELDCATALOG_MERGE?


Ans:

36.) What is logical database reporting?How it is useful in realtime?


Ashok
SAP-ADV ABAP

Ans:

37.) What is the Function module used for Hierarichal alvs?


Ans:
1. REUSE_ALV_HIRESEQ_LIST_DISPLAY
Using this function module, you can display the in hierarchal format

38.) Explain the function module of blocked alvs?


Ans:
1. REUSE_ALV_BLOCK_LIST_INIT
It initializes lists in blocked alvs

2. REUSE_ALV_BLOCK_LIST_APPEND
This function module
 Maintains field catalogs
 Maintains data in list
 Append field catalogs & data with layout

3. REUSE_ALV_BLOCK_LIST_DISPLAY
It displays data in list in blocked alvs

39.) Explain one requirement where u used blocked alvs in realtime?


Ans:
 Using Blocked ALVs you can display multiple lists at one place
 In real time we are using blocked alvs in few scenarios such as if you want to display
production affiance of different machines of one furnace in one Output list
 If client requires invoice details based on customers, materials, segments at one place we
have to work with Blocked ALVs

40.) How u can improve performance of programming?Give atleast 15 tips for the same?
Ans:

41.) Mention some 30 system fields that u used on realtime?


Ans:

42.) What are the system fields used on interactive reporting?


Ans:
3. SY-LSIND
4. SY-LISEL

43.) What are the pitfalls for for all entries keyword?
Ans:

Ashok
SAP-ADV ABAP

44.) How many times initialization and top-of-page triggers in report having 20 pages?
Ans:
INITIALIZATION will triggers only 1 time
TOP-OF-PAGE will triggers 20 times

45.) Why u created restricted and unrestricted stock report when already SAP is providing
such report in the form of MMBE?
Ans:
 MMBE is providing materials details plant wise & storage location wise material by
material
 My client gave a requirement for viewing all restricted & unrestricted stock at one time

46.) What is Code inspector? How it is useful in real time?


Ans:
It will inspect your code comprehensively & it will check
6. Performance Checks
7. Security Checks
8. Syntax Checks
9. User Interface
10.Programming Guidelines

47.) What is the functionality of HIDE keyword?


Ans:
It holds the records selected by user in interactive reporting

48.) How u can transfer data from alv reporting to MM01 Application?
Ans:

49.) How u can create listbox in reports?


Ans:

50.) If there are 50 records i want message at 10th record then how to do you do.
Ans:

51) Difference between sy-tabix,sy-index and sy-subrc


Ans:

52.) How you can convert alv report to oo abap report, is there any possibilities ?
Ans:

53.) Can we define select statements in end-of-selection event?


Ans:

Ashok
SAP-ADV ABAP

54.) I have internal table


a b
1 1
1 1
1 2
1 2
2 2

when does "at new" event triggers at 'a' and 'b'?


ans:

55.) In interactive reports in 20th secondary list if double click what will happen?
Ans:

56.) What are the abap runtime errors we have faced in reporting?
Ans:
In real time you will find number of exceptions (Run time errors) such as
8. Time out exception
9. SQL statement exception
10.Division by zero exception
11.No convert number exception
12.Type conflict exception
13.BCD overflow exception
14.*** Storage exception for internal table

57.) What is the use of initialization event? We can initialize the input values in selection screen
without initialization event also but why we are using initialization event?
Ans:
Initialization Event triggers before selection-screen display
Note:
Use this event for initializing
1. Default values in selection-screen
2. Texts on push buttons in selection-screen
3. Texts for blocks, radio buttons, check boxes…………..etc

58.) After developing source code in development server how many reviews we will get for our
source code.
Ans:

59.) Tell me some Table and fields that u created in reports?\


Ans:

60.) What is the toughest report u created, what difficulties u faced and how u overcome those?
Ashok
SAP-ADV ABAP

Ans:

61.) What is the use of SLIS type pool in abap reports?


Ans:

62.) What are Alv reports? How they are different from normal reports?
Ans:
ALV is advanced reporting with additional features of reporting

7. In traditional reporting you cannot maintain logos (pictures…………etc)


With ALV reporting you can maintain logos using ALV Function Modules
8. With ALV reporting you can improve performance of programming by avoiding
LOOP…..ENDLOOP
9. Using ALV reporting you can maintain Main Headings, Sub Headings……….etc

63.) What are the various ways of creating buttons in selection screens?
Ans:
Page number: 230

64.) How indexing is helpful in resolving performance issues in reports? Explain with ur
experience in real time?

Ans:
 Indexing is a way of searching
 Indexing is a way of improving performance while accessing the data from database
 I created secondary index on production efficient report
 First I debugged the program
 I found that control is taking lot of time for program execution
Then I will identify none primary key fields of that SELECT statement & based on that non-
primary key fields I will created a secondary index

65.) What is system landscape in ur company?


Ans:

Ashok
SAP-ADV ABAP

66.) What is ABAP/4 QUERY?(Sap Query).


Ans:
 In real time for developing a report it will take lot of time for development
 i.e. Requirement ---- Functional Consultant-----Functional Document----Technical
Consultant-----Technical Document------Object Creation------Unit Testing-----
Functional Testing-----User Testing-----go live (transfer to Production)
 using SAP Query you can create a report immediately through navigation

67.) How do you validate the selection criteria of report?


Ans:

68.) How SUBMIT keyword is helpful in ABAP REPORTS?


Ans:
* push mails to SAP inbox
SUBMIT RSLONN01 WITH MODE = ‘INT’ AND RETURN.

Ashok
SAP-ADV ABAP

FAQS IN REPORTS:

1 Q: What are SAP reports?


Ans:
 SAP Reports are event-driven programs using ABAP/4 programming language
 These reports are used to fetch business-specific data from SAP standard databases under
specified selection criteria
 Fetched data is processed to display result on output screen
 User develop SAP report object on ABAP editor using the standard SAP transaction SE38

2Q: What are ABAP report types?


Ans:
 ABAP report types are of 7 types
 ABAP report types are available in report’s attributes screen
They are:
1. Executable program
2. Function group (containing function modules)
3. Include
4. Interface pool
5. Class pool
6. Module pool
7. Subroutine pool

3Q: How many lists can be displayed through an interactive report?


Ans:
Maximum 21 lists can be displayed (1 basic list+ 20 secondary lists).

4Q: what is the event that will be triggered first in an ABAP report?
Ans:
 Initialization event is triggered first if user executes an ABAP report
 But if the program is of type 1, M, F, or S; then LOAD-OF-PROGRAM is triggered first
and then INITIALIZATION event.

5Q: What are the differences between simple and interactive ABAP reports?
Ans:
 A simple ABAP report allows the user to interact with the whole business-result data.
 In case of interactive reports user can interact with specific result data at a time.

Ashok
SAP-ADV ABAP

6Q: How do you read selected lines of database table into an internal table in packages of
predefined size?
Ans:
SELECT * FROM <SPFLI> INTO TABLE <ITAB> PACKAGE SIZE <N>.
Where n is variable.

7Q: How do you write a DATA object from ABAP/4 program to ABAP/4 memory and restore
the same from memory to program.
Ans:
EXPORT <f1> [FROM <g1>] <f2> [FROM <g2>]…. TO MEMORY ID <key>.
The ID <key>, which can be up to 32 characters long, identifies the data in memory.

8Q: Name the function modules to write data from an Internal Table to the Presentation Server.
Ans:
1. DOWNLOAD
2. WS_DOWNLOAD.

9Q: How to determine the attributes of an internal table?


Ans:
DESCRIBE TABLE <itab> [LINES <lin>] [OCCURS <occ>].

9Q: What is interactive reporting?


Ans:
 It helps you to create easy-to-read lists
 You can display an overview list first that contains general information and provide the
user with the possibility of choosing detailed information that you display on further lists.
10Q: What are the uses of interactive reporting?
Ans:
 The user can actively control data retrieval and display during the session
 Instead of an extensive and detailed list, you create a basic list with condensed
information from which the user can switch to detailed displays by positioning the cursor
and entering commands
 The detailed information appears in secondary lists.

Ashok
SAP-ADV ABAP

11Q; what are the event key words in interactive reporting?


Ans:
Event Keyword Event
AT LINE-SELECTION Moment at which the user selects a line by double clicking on
it or by positioning the cursor on it and pressing F2

AT USER-COMMAND Moment at which the user presses a function key

TOP-OF-PAGE DURING Moment during list processing of a

LINE-SELECTION Secondary list at which a new page starts.

12Q: What is secondary list?

Ans:
 It allows you to enhance the information presented in the basic list
 The user can, for example, select a line of the basic list for which he wants to see more
detailed information
 You display these details on a secondary list
 Secondary lists may either overlay the basic list completely or you can display them in an
extra window on the screen
 The secondary lists can themselves be interactive again.

13Q: How to select valid lines for secondary list?


Ans:
 To prevent the user from selecting invalid lines, ABAP/4 offers several possibilities.
 At the end of the processing block END-OF-SELECTION, delete the contents of one or
more fields you previously stored for valid lines using the HIDE statement.
 At the event AT LINE-SELECTION, check whether the work area is initial or whether
the HIDE statement stored field contents there.
 After processing the secondary list, clear the work area again.
 This prevents the user from trying to create further secondary lists from the secondary list
displayed.

14Q: Can we call reports and transactions from interactive reporting lists?
Ans:
 Yes,
 It also allows you to call transactions or other reports from lists
 These programs then use values displayed in the list as input values
Ashok
SAP-ADV ABAP

 The user can, for example, call a transaction from within a list of change the database
table whose data is displayed in the list
15Q: What are system fields for secondary lists?
Ans:
1. SY-LSIND Index of the list created during the current event (basic list = 0)
2. SY-LISTI Index of the list level from which the event was triggered.
3. SY-LILLI Absolute number of the line from which the event was triggered.
4. SY-LISEL Contents of the line from which the event was triggered.
5. SY-CUROW Position of the line in the window from which the event was triggered
6. SY-CUCOL Position of the column in the window from which the event was triggered
7. SY-CPAGE Page number of the first displayed page of the list from which the event
was triggered.
8. SY-STARO Number of the first line of the first page displayed of the list from which
the event was triggered (counting starts with 1). Possibly, a page header
occupies this line.
9. SY-STACO Number of the first column displayed in the list from which the event was
triggered
10.SY-UCOMM Function code that triggered the event.
11.SY-PFKEY Status of the displayed list.

16Q: What are the page headers for secondary lists?


Ans:
 On secondary lists, the system does not display a standard page header and it does not
trigger the event TOP-OF-PAGE.
 To create page headers for secondary list, you must enhance TOP-OF-PAGE: Syntax
TOP-OF-PAGE DURING LINE-SELECTION.
 The system triggers this event for each secondary list.
 If you want to create different page headers for different list levels, you must program the
processing block of this event accordingly,
 For example by using system fields such as SY-LSIND or SY-PFKEY in control
statements (IF, CASE)

17Q: What are the types of messages?


Ans:
A message can have five different types.
These message types have the following effects during list processing:
1. A (=Amend):
2. E (=Error) or W (=Warning):
3. I (=Information):
4. S (=Success):

Ashok
SAP-ADV ABAP

18Q: What are the drill-down features provided by ABAP/4 in interactive lists?
Ans:
 ABAP/4 provides some interactive events on lists such as AT LINE-SELECTION
(double click) or AT USER-COMMAND (pressing a button).
 You can use these events to move through layers of information about individual items in
a list.

19Q: What is meant by stacked list?


Ans:
A stacked list is nothing but secondary list and is displayed on a full-size screen unless you have
specified its coordinates using the window command.

19Q: Is the basic list deleted when the new list is created?
Ans:
No. It is not deleted and you can return back to it using one of the standard navigation
functions like clicking on the back button or the cancel button.

20Q: What is meant by hotspots?

Ans:
 A Hotspot is a list area where the mouse pointer appears as an upright hand symbol.
 When a user points to that area (and the hand cursor is active), a single click does the
same thing as a double-click.
 Hotspots are supported from R/3 release 3.0c.

21Q: What is the length of function code at user-command?


Ans:
Each menu function, push button, or function key has an associated function code of length
FOUR (for example, FREE), which is available in the system field SYUCOMM after the user
action.

22Q: Can we create a GUI status in a program from the object browser?
Ans:
Yes. You can create a GUI STATUS in a program using SET PF-STATUS.

23Q: In which system field does the name of current gui status is there?
Ans:
The name of the current GUI STATUS is available in the system field SY-PFKEY.

Ashok
SAP-ADV ABAP

24Q: Can we display a list in a pop-up screen other than full-size stacked list?
Ans:
Yes, we can display a list in a pop-up screen using the command WINDOW with the additions
starting at X1 Y1 and ending at X2 Y2 to set the upper-left and the lower-right corners where x1
y1 and x2 y2 are the coordinates.

25Q: What is meant by hide area?


Ans:
 The hide command temporarily stores the contents of the field at the current line in a
system-controlled memory called the HIDE AREA.
 At an interactive event, the contents of the field are restored from the HIDE AREA.

26Q: When they get cursor command used in interactive lists?


Ans:
 If the hidden information is not sufficient to uniquely identify the selected line, the
command GET CURSOR is used.
 The GET CURSOR command returns the name of the field at the cursor position in a
field specified after the addition field,
 And the value of the selected field in a field specified after value.

27Q: How can you display frames (horizontal and vertical lines) in lists?

Ans:
 You can display tabular lists with horizontal and vertical lines (FRAMES) using the
ULINE command and the system field SY-VLINE.
 The corners arising at the intersection of horizontal and vertical lines are automatically
drawn by the system.

28Q: What are the events used for page headers and footers?
Ans:
The events TOP-OF-PAGE and END-OF-PAGE are used for pager headers and footers.

29Q: How can you access the function code from menu painter?
Ans:
 From within the program, you can use the SY-UCOMM system field to access the
function code.
 You can define individual interfaces for your report and assign them in the report to any
list level.
 If you do not specify self-defined interfaces in the report but use at least one of the three
interactive event keywords.
Ashok
SAP-ADV ABAP

 AT LINE-SELECTION, AT PF<nn>, OR AT USER-COMMAND in the program, the


system automatically uses appropriate predefined standard interfaces.
 These standard interfaces provide the same functions as the standard list described under
the standard list.

30Q: How the at-user command serves mainly in lists?


Ans:
 The AT USER-COMMAND event serves mainly to handle own function codes.
 In this case, you should create an individual interface with the Menu Painter and define
such function codes.
31Q: How to pass data from list to report?
Ans:
ABAP/4 provides three ways of passing data:
1. Passing data automatically using system fields
2. Using statements in the program to fetch data
3. Passing list attributes

32Q: How can you manipulate the presentation and attributes of interactive lists?
Ans:
1. Scrolling through Interactive Lists.
2. Setting the Cursor from within the Program.
3. Modifying List Lines.

33Q: How to call other programs?

Ans:
Report Transaction
1. Call and return SUBMIT AND RETURN CALL TRANSACTION
2. Call without return SUBMIT LEAVE TO TRANSACTION
You can use these statements in any ABAP/4 program.

34Q: How many lists can a program can produce?


Ans:
 Each program can produce up to 21 lists
 One basic list and 20 secondary lists
 If the user creates a list on the next level (that is, SY-LSIND increases), the system stores
the previous list and displays the new one.
 Only one list is active, and that is always the most recently created list

Ashok
SAP-ADV ABAP

35Q: What’s ABAP dictionary and its role in SAP?


Ans:
 ABAP dictionary is the central information base for the developers.
 This manages all definitions(metadata) required for different applications in SAP.
 ABAP dictionary is completely integrated into ABAP development workbench.
 All other component of ABAP development workbench can access the data
definitions(meta data) stored in the data dictionary.

Role: ABAP data dictionary supports

 Definition of user-defined types (data elements, structures, table types).


 Structure of database objects (tables, indexes and views) can also be defined.
 These user-defined types/objects are then automatically created in the underlying
relational database using the above data definitions.
 The ABAP dictionary also provides tools for editing screen fields (e.g., for assigning a
field an input help i.e. F4 help).
 Data dictionary ensures data integrity, consistency and security.

36Q: What are the main object types of ABAP dictionary?


Ans:
Tables:
 Tables are defined in the ABAP Dictionary independently of the database.
 A table having the same structure is then created from this table definition in the
underlying database.

Views:
 Views are logical views on more than one table.
 The structure of the view is defined in the ABAP Dictionary.
 A view on the database can then be created from this structure.

Types: (elements, structures, table types)


 Types are created in ABAP programs.
 The structure of a type can be defined globally in ABAP programs.
 Changes to a type automatically take effect in all the programs using the type.

Lock objects:
 These are used to synchronize access to the same data by more than one user.
 Function modules that can be used in application programs are generated from the
definition of a lock object in the ABAP Dictionary.
Ashok
SAP-ADV ABAP

Ashok
SAP-ADV ABAP

Domains:
 Different fields having the same technical type can be combined in domains.
 Domain defines the value range of all table fields and structure components that refer to
this domain.

Data element:
 The ABAP Dictionary also contains the information displayed with the F1 and F4 help
for a field in an input template.
 The documentation about the field is created for a data element.

Input help:
 The list of possible input values that appears for the input help is created by a foreign key
or a search help.

37Q: What are the components of a table definition.


Ans:
Table fields:
For table fields, field names and data types are defined.

Foreign keys:
Relationship between the table and the other tables are defined.

Technical settings:
Data class and size category defines that what type of table to be created and how much space
required.

Indexes:
Secondary indexes are created for a table for faster data selection.

Again following are defined for a table fields:


1. Field name --------- can be of maximum 16 characters in a table and must start with a
letter.
2. Key flag ----------- determines if a field should be the table key.
3. Field type --------- depicts the data type of the field in the ABAP dictionary.
4. Field length ------ denotes the number of valid places in the field.
5. Decimal places----- Number of places after decimal point for float type value.
6. Short text ----------- describes the business meaning of the field.
7. Also fields from other structures can be added to the table definition as include.

Ashok
SAP-ADV ABAP

38Q: What are the assignment options to the field?


Ans:
1. Direct assignment of data types, field length, short text to a field
2. Data element assignment to a field
3. An input check (check table) for a field can be defined with a foreign key.
4. A search help can be assigned to a field.
5. Reference field or reference table must be specified for a table field that holds currency
or quantity type value.

39Q: What’s reference table and reference field?


Ans:
 Reference table is specified for fields containing quantities(data type QUAN) or
currency(Data type CURR).
 This reference table must contain a field with the format for the currency key (data type
CUKY) or unit of measure (data type UNIT).
 This field is called the reference field of the output field.
 The reference field can also reside in the table itself.

49Q: What is the maximum depth of nested includes in a table?


Ans:
Maximum depth is 9
i.e. maximum 9 structures can be included in a table/structure.

50Q: What are the uses of foreign keys in SAP?


Ans:
 Using foreign keys (as main table-field is linked with check table), input value check for
any input field can be done.
 Foreign keys can also be used to link several tables.

51Q: How many types of data classes are there in SAP?

Ans:
1. Choose APPL0(master data) for data that is frequently accessed but rarely
updated/changed.
2. Choose APPL1 (transaction data) for data that is frequently changed.
3. Choose APPL2 (organizational data) for customizing data that is defined/entered during
system installation and rarely changed.

Ashok
SAP-ADV ABAP

52Q: How many types of size category are there in SAP?


Ans:
 There are five size categories. Size category from 0 to 4 can be chosen for the tables.
 A certain fixed memory size is assigned to each category in the SAP database.

53Q:What is delivery class?


Ans:
 We need to insert an delivery class value while creating customized table in SAP through
the transaction code SE11.
 Delivery class is that which regulates the transport of the table’s data records (during SAP
installations, SAP software upgrade, client copies, and data transport to other SAP
system).
 SAP and its customers have different write types depending on the variety of delivery
class.
 If Delivery class is A, it depicts that the application table for master and transaction data
changes only rarely.

54Q: What is value table?


Ans:
 Value table is maintained at domain level in SAP.
 During domain creation, value range of the domain is defined by specifying value table.
 Suppose for a particular domain, its value table holds the values ‘A’, ‘B’, ‘Z’.
 So whenever the domain will be used, system will allow to use these values only.

Ashok
SAP-ADV ABAP

FAQS IN INTERACTIVE REPORTS:

1Q: What are the event key words in interactive reporting ?


Ans:
1. AT LINE-SELECTION
Moment at which the user selects a line by double-clicking on it or by positioning the cursor on
it and pressing F2

2. AT USER-COMMAND
Moment at which the user presses a function key

3. TOP-OF-PAGE DURING LINE-SELECTION


Moment during list processing of a secondary list at which a new page starts

2Q: What is secondary list ?


Ans:
 Secondary lists allow you to enhance the information presented in the basic list.
 The user can, for example, select a line of the basic list for which he wants to see more
detailed information
 You display these details on a secondary list.
 Either secondary lists may overlay the basic list completely (or) you can display them in
an extra window on the screen.
 The secondary lists can themselves be interactive again.

3Q: How to select valid lines for secondary list?


Ans:
 To prevent the user from selecting invalid lines, ABAP/4 offers several possibilities.
 At the end of the processing block END-OF-SELECTION, delete the contents of one or
more fields you previously stored for valid lines using the HIDE statement.
 At the event AT LINE-SELECTION, check whether the work area is initial or whether
the HIDE statement stored field contents there.
 In the latter case, create a secondary list, since you previously stored field contents for
valid lines only.
 After processing the secondary list, clear the work area again.
 This prevents the user from trying to create further secondary lists from the secondary list
displayed.

Ashok
SAP-ADV ABAP

4Q: How to create user interfaces for lists ?


Ans:
 The R/3 system automatically generates a graphical user interface (GUI) for your lists
that offers the basic functions for list processing, such as saving or printing the list.

 If you want to include additional functionality, such as pushbuttons, you must define your
own interface status.
 To create a new status, the Development Workbench offers the Menu Painter.
 With the Menu Painter, you can create menus and application toolbars.
 And you can assign Function keys to certain functions.
 At the beginning of the statement block of AT END-OF-SELECTION, activate the status
of the basic list using the statement: SET PF-STATUS 'STATUS'.

5Q: Can we call reports and transactions from interactive reporting lists ?
Ans:
 YES,
 Interactive reporting also allows you to call transactions or other reports from lists.
 These programs then use values displayed in the list as input values.
 The user can, for example, call a transaction from within a list to change the database
table whose data is displayed in the list.

6Q: How to maintain lists ?


Ans:
 To return from a high list level to the next-lower level (SY-LSIND), the user chooses
Back on a secondary list.
 The system then releases the currently displayed list and activates the list created one step
earlier.
 The system deletes the contents of the released list.
 To explicitly specify the list level into which you want to place output, set the SY-LSIND
field.
 The system accepts only index values which correspond to existing list levels.
 It then deletes all existing list levels whose index is greater or equal to the index you
specify.
 For example, if you set SY-LSIND to 0, the system deletes all secondary lists and
overwrites the basic list with the current secondary list.

7Q: What are the page headers for secondary lists?


Ans:

Ashok
SAP-ADV ABAP

 On secondary lists, the system does not display a standard page header and it does not
trigger the event TOP-OF-PAGE.
 To create page headers for secondary list, you must enhance TOP-OF-PAGE:
Syntax:
TOP-OF-PAGE DURING LINE-SELECTION
 The system triggers this event for each secondary list.
 If you want to create different page headers for different list levels,
 You must program the processing block of this event accordingly,
 For example by using system fields such as SY-LSIND or SY-PFKEY in control
statements (IF, CASE).

8Q:What is meant by stacked list ?


Ans:
Stacked list is nothing but secondary list and is displayed on a full-size screen unless you have
specified its coordinates using the window command.

9Q: Is the basic list deleted when the new list is created?
Ans:
No. It is not deleted and you can return back to it using one of the standard navigation functions
like clicking on the back button or the cancel button.

10Q:What is meant by hotspots ?


Ans:
 Hotspot is a list area where the mouse pointer appears as an upright hand symbol.
 When a user points to that area (and the hand cursor is active),
 A single-click does the same thing as a double-click.
 Hotspots are supported from R/3 release 3.0c.

11Q: In which system field does the name of current gui status is there ?
Ans:
The name of the current GUI STATUS is available in the system field SY-PFKEY.

12Q: What is meant by hide area ?


Ans:
 The hide command temporarily stores the contents of the field at the current line in a
system-controlled memory called the HIDE AREA.
 At an interactive event, the contents of the field is restored from the HIDE AREA.
 When calling a secondary list from a list line for which the HIDE fields are stored, the
system fills the stored values back into the variables in the program.
 In the program code, insert the HIDE statement directly after the WRITE statement for
the current line.
Ashok
SAP-ADV ABAP

Ashok
SAP-ADV ABAP

13Q: When the get cursor command used in interactive lists ?


Ans:
 If the hidden information is not sufficient to uniquely identify the selected line ,the
command GET CURSOR is used.
 The GET CURSOR command returns the name of the field at the cursor position in a
field specified after the addition field, and the value of the selected field in a field
specified after value.

14Q: How to pass data from list to report ?

Ans:

ABAP/4 provides three ways of passing data:


1. Passing data automatically using system fields
2. Using statements in the program to fetch data
3. Passing list attributes

15Q: How to call other programs ?


Ans:
Report Transaction
Call and return SUBMIT AND RETURN CALL TRANSACTION
Call without return SUBMIT LEAVE TO TRANSACTION

System fields used in interactive Reporting:


 The SY-LSIND system field contains the index of the list currently created.
 While creating a basic list, SY-LSIND equals 0.
 With each interactive event, the system automatically sets the following system fields

System field Information:


SY-LINCT --------- total line count of a list
SY-LINNO -------- current line no where cursor is placed.
SY-LSIND -------- Index of the list currently created during the current event (basic list = 0)
SY-LISTI ---------- Index of the list level from which the event was triggered
SY-LILLI ---------- Absolute number of the line from which the event was triggered
SY-LISEL --------- Contents of the line from which the event was triggered
SY-CUROW ------ Position of the line in the window from which the event was triggered
(counting starts with 1)
SY-CUCOL ------- Position of the column in the window from which the event was triggered
(counting starts with 2)
SY-UCOMM ----- Function code that triggered the event
Ashok
SAP-ADV ABAP

SY-PFKEY ------- Always contains the status of the current list.

TOP-OF-PAGE DURING LINE-SELECTION:


 The system triggers this event for each secondary list.
 If you want to create different page headers for different list levels, you must program the
processing block of this event accordingly,
 For example by using system fields such as SY-LSIND or SY-PFKEY in control
statements (IF, CASE)

Data from System Fields of Interactive Lists:


 From system fields, you retrieve the following information:
 The index of a list,
 The position of the list in the output window &
 The location of the cursor
 The only system field that contains the contents of the selected line is SY-LISEL.

Passing Data by Program Statements:


To pass individual output fields or additional information from a line to the corresponding
processing block during an interactive event, Use following statements

HIDE:
 The HIDE statement is one of the fundamental statements for interactive reporting
 Using the HIDE technique, you can at the moment you create a list level define, which
information later to pass to the subsequent secondary lists.

Example:
HIDE: SPFLI-CARRID, SPFLI-CONNID, NUM.

READ LINE:
 Use the statements READ LINE & READ CURRENT LINE to explicitly read data from
the lines of existing list levels.
 These statements are tightly connected to the HIDE technique.

Syntax:
READ LINE [INDEX ]
[FIELD VALUE [INTO ]... [INTO ]]
[OF CURRENT PAGE|OF PAGE ].

Example:
READ LINE SY-INDEX FIELD VALUE BOX.

Ashok
SAP-ADV ABAP

GET CURSOR:
Use the statements GET CURSOR FIELD & GET CURSOR LINE to pass the output field or
output line on which the cursor was positioned during the interactive event to the processing
block.

Syntax:
GET CURSOR FIELD [OFFSET ] [LINE ]
[VALUE ] [LENGTH ].

SET CURSOR:
 To set the cursor, use the SET CURSOR statement
 This statement sets the cursor in the most recently created list
 While creating the basic list, this is always the basic list itself
 While creating a secondary list, this is the previous list.

ABAP allows you to call reports as well as transactions using these statements:
Report Transaction
Call and return SUBMIT AND RETURN CALL TRANSACTION
Call without return SUBMIT LEAVE TO TRANSACTION

Typical Structure of ABAP Program:


1. Report Definitions *
2. Table and Data definitions *
3. Initialization event
4. Screen Select Options/Inputs *
5. Selection-screen event
6. Start-of-selection event
7. Performs and other Events *
Statements
8. End-of-selection event

Ashok
SAP-ADV ABAP

9. Initialization
OOABAP:
1Q: Principles of oops?
Ans:
5. Inheritance
6. Polymorphism
7. Abstraction
8. Encapsulation

2Q: What is difference between procedural & OO Programming?


Ans:
Structured Programming Object Oriented Programming
1. Not Reusable 1. Reusable
2. Not based on real life 2. Based on real life
(not user friendly)
3. No data security 3. High data security
4. No exception handling 4. Exception handling

3Q: What is class?


Ans:
 Class is a template based on which objects are created
 All the features (Methods) of an object is encapsulated within a class
 As class is a template memory is not allocated by system to a class

4Q: What is object?


Ans:
 It is real time entity
 It is always created based on a class (object is an instance of a class)
 As object is a real time entity memory is allocated by system to an object
 Every object holds data in such a way that outside world cannot access

5Q: Can we instantiate a class within implementation of other class?


Ans:

6Q: What is deferred key word?


Ans:

7Q: How we can refer to a class without defining it?


Ans:

Ashok
SAP-ADV ABAP

8Q: Can we put non declarative statement e.g. START-OF-SELECTION within a class
Ans:
9Q: What is static attribute & method?
Ans:

10Q: How to create a global class?


Ans:
In global class CLASS DEFINITION & CLASS IMPLEMENTATION parts are maintained
in Class Builder (SE24) & Execution part is maintained in ABAP Editor (SE38)

11Q: How can we pass importing parameter? Pass by value/pass by reference


Ans:

13Q: Can we changed pass by reference in any method?


Ans:

14Q: What is preferred parameter?


Ans:
More than one optional & no mandatory

15Q: Can we pass returning parameter by reference?


Ans:
No, Only pass by value

16Q: Can static method use instance attribute ?


Ans:

17Q: Can a method call itself?


Ans:

18Q: What is me variable?


Ans:

19Q: What is constructor? What are types of constructor? When it is called?


Ans:
 Constructor is a default method in Object Oriented ABAP
 It is called automatically whenever object is created
 Use this method for initializing values in Object Oriented ABAP

20Q: Can we have export parameter in Instance constructor?


Ans:

Ashok
SAP-ADV ABAP

21Q: Can instance constructor raise exception?


Ans:
22Q: When static constructor is called?
Ans:

23Q:Can we have interface for static class or constructor?


Ans:

24Q: What is abstract class?


Ans:
 Abstract classes are cannot be implemented
 Objects cannot be created for abstract classes
 Abstract class methods are also abstract in nature
 Derived class can implement abstract class methods by redefining the methods of abstract
class in derived class

25Q: Can we implement abstract method in abstract class? If not then where it can be
implemented?
Ans:

26Q: What is final class & Method?


Ans:

27Q: Can subclass call super class constructor?


Ans:

28Q: Can we call static constructor more than once in a program?


Ans:

29Q: What is method redefinition?


Ans:

30Q: What is interface?


Ans:
 It is a template which extends the scope of a class & implements polymorphism
 Instances cannot be created based on interface
 Interface methods are always implemented in other class

31Q: Can we implement interface in private section of any class?


Ans:

Ashok
SAP-ADV ABAP

32Q: Is it mandatory to implement all the methods of interface?


Ans:
33Q: What is alias? Instead of specifying full name of interface methods we can assign it a
name which can directly trigger.
Ans:

34Q: What is Friendship?


Ans:

35Q: What is event handler method?


Ans:

36Q: Can we have more than one event handler method for same event?
Ans:

37Q: Can event have import parameter?


Ans:

38Q: How you handled exception during programming?


Ans:

39Q: What is cleanup section?


Ans:

40Q: What is BADI?


Ans:

41Q: What is check box for multiple usse in BADI?


Ans:

42Q: How to search a BADI ?


Ans:

43Q: What is Value table and Check table, Difference between them?
Ans:

44Q: What are secondary index’s?


Ans:

45Q: What is the draw back of secondary index’s?


Ans:

Ashok
SAP-ADV ABAP

46Q: What are conversion routines?


Ans:
47Q: At which level are they mantained?
Ans:

48Q: what are Predeifined data types?


Ans:

49Q: Which predefined data type uses conversion routines?


Ans:

50Q: What are logical units of work?


Ans:

51Q: When is difference btw native and open sql


Ans:

52Q: Difference between Modify and Update


Ans:

53Q: Which is more efficient for all entries or joins?


Ans:

54Q: When is implicit commit triggered.


Ans:

55Q: What are RFC?


Ans:

56Q: How do u create a destination system?


Ans:

57Q: What are different types of commits used?


Ans:

58Q: What are search helps?


Ans:

59Q: Types of tables?


Ans:

Ashok
SAP-ADV ABAP

60Q: Difference between pool tables and cluster tables?


Ans:

61Q: What is a delivery class?


Ans:

62Q: What are the types of delivery class?


Ans:

63Q: Difference between System tables and control tables?


Ans:

64Q: What is normalization?


Ans:

65Q: What is BCNF?


Ans:

66Q: What is persistant class?


Ans:

Ashok

Вам также может понравиться