KEMBAR78
ABAP Tutorial (Verdy) | PDF | Relational Database | Parameter (Computer Programming)
0% found this document useful (0 votes)
260 views171 pages

ABAP Tutorial (Verdy)

Uploaded by

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

ABAP Tutorial (Verdy)

Uploaded by

vn_wdjj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 171

ABAP - Basic Knowledge

(Revision 7)

Created by :

Albertus Reinandang

Revision by:

Verdy Praseldy (swamtls@gmail.com)

Contributor

Technical Functional
Mawan Sugiyanto Dyan Pravita Sari

Danar Andri Prasetyo Robinton

Yance Ciputra Wahyu Arif Dermawan

Alfarisi

Kenindi Setawijaya

Muhammad Fajrin

Kristian Fredy

This file is generated : Thursday September 16, 2010


Go to http://www.sap-interface.com/ to get the actual version.
© 2008-2010 www.sap-interface.com
DAFTAR ISI
DAFTAR ISI ........................................................................................................................i

BAB 1. ABAP-BASIC KNOWLEDGE .............................................................................1

a. ABAP Editor .....................................................................................................1


b. ABAP Naming Convention .............................................................................6
c. ABAP Data Types .......................................................................................... 21
d. ABAP Syntax .................................................................................................37
e. ABAP Dictionary ........................................................................................... 41
f. Function Builder ............................................................................................ 52
g. Form ...............................................................................................................54
h. Enhancement ..................................................................................................56
i. Examples ........................................................................................................58

BAB 2. ABAP-REPORT ..................................................................................................66

a. Basic Knowledge ........................................................................................... 66


b. Display Output ............................................................................................... 73
c. HTML ............................................................................................................85
d. ALV ..............................................................................................................108
e. SmartForms ..................................................................................................135

i
BAB 1

ABAP-BASIC KNOWLEDGE

a. ABAP-Editor
i. Create New Program

1. Open t-code SE38

2. Insert program name initiate with letter Z or Y

4. Press Button ”Create”

5. Type Program's Tittle and Choose "Executable program" at Field 'Type'

6. Press Button ”Save”

1
7. Package is filled to make program able to transport to the other client, but if it's for
practice, you dont need to fill it.

8. Press Button if you want program able to transport to the other client. Press
Button for practice only.

9. Enter to ABAP Editor

ii. Change Program

1. Open t-code SE38

2. Fill program name want to change. if you forget it, type keyword of it, for example
"Y*". Then Press button or press F4 to open program's search menu.

3. Double Click to choose program or put kursor over list, and then klik

4. Click button

2
iii. ABAP Debugger

Menu Path SAP Menu > Tools > ABAP Workbench >
Development > ABAP Editor
Transaction code SE38 > Debugging

ABAP Debugger is one of SAP fitur which most used by ABAP'er to analize
program/report made in SAP.

Main menus in ABAP Debuger which most used are:

1. Single Step (F5), it's used to enter inside subroutine or module.


2. Execute (F8), it's used to execute line coding one by one.
3. Return (F7), it's used to exit from subroutine.
4. Run (to Cursor) (F8), it's used to execute all line code program and only stop if
there are icon" "

3
These are bassic example to debug program.

1. Open t-code SE38


2. Choose YEXAMPLES_04
3. Run Program
4. Type "/h" at "Command Field"

5. Press enter
6. Press button " "
7. It will be enter ABAP Debugger menu like picture below :

8. Click " "


9. Type "gi_itab" at Field names and press enter

4
10. Double Click at " " and will be appear "Internal Table" menu

= This is a row which define as Header Line


" DATA : gi_itab TYPE STANDARD TABLE OF ty_wa WITH HEADER LINE. "

11. Click " ", stop at coding " APPEND gi_itab."


12. Attent the Header Line, it will be filled like picture below :

Notes: Before append the data, it place temporary at header line.

13. Click " " to append data

Notes: Data at Header Line are data at active row in gi_itab.

5
14. Now, double click on " APPEND gi_itab." so it will be appear Break Point like
picture below.

15. Then Click " " once again, then cursor will jump into icon" " inside repetition
block coding.

16. Now, Double Click at " APPEND gi_itab." or icon " " to remove Break Point
17. Then Click " " to exit from ABAP Debugger
18. Finish

b. ABAP Naming Convention

In ABAP Programing, there are two type of naming convention, naming initiate by
letter "Y" and "Z".

1. Y Convention
 ABAP Dictionary.

Transparent Table Trans. Table name: YTA_XXXXXXXX

YTA_ = prefix

XXXXXXXX = self defined name

Example: YTA_FAKPJK

6
Structures Structure name: YST_XXXXXXXX

YST_ = prefix

XXXXXXXX = self defined name

Example: YST_DOLIST
Data Element Data Element name: YXXXXXX

Y = prefix

XXXXXX = self defined name

Example: YMATNR
Domain Domain name: YD_XXXXXX

YD_ = prefix

XXXXXX = self defined name

Example: YD_MATNR
Search Help Search Help name: YSH_XXXXXX

YSH_ = prefix

XXXXXX = self defined name

Example:YSH_ITEM
View Table View name: YTV_XXXXXX

YTV_ = prefix

XXXXXX = self defined name

Example:YTV_CUSTOMER

 Internal Table and Working Area

Internal tables 1. Global Internal Table: GI_XXXXX


GI_ = Prefix
XXXXX = self defined name

Example:
· GI_VBRK
GI_FAKPJK

7
2. Local Internal Table: LI_XXXXX
LI_ = Prefix
XXXXX = self defined name

Example:
· LI_VBRK
· LI_FAKPJK
Working Area 1. Global Working Area: GW_XXXXXX
GW_ = Prefix
XXXXXX = self defined name

Example:
· GW_LIKP
· GW_XTEXT

2. Local Working Area: LW_XXXXX


LW_ = Prefix
XXXXX = self defined name

Example:
 LW_LIPS
 LW_POORDER

 Program and Include

All programs, after prefix and before self defined name, are inserted with a
module code XX999. Meaning:

 For FI =FI001-FI999
 For CO =CO001-CO999
 For MM = MW001-MW999
 For WM = WM001-WM999
 For PP = PP001-PP999
 For QM = QM001-QM999
 For SD = SD001-SD999
 For HR = HR001-HR999

Driver Program name: YDR_XX999_XXXXXXXXX

YDR_ = driver prefix

XX999_ = module code

XXXXXXXXX = self defined name

8
Example:

· YDR_SD001_FAKPJKSEDERHANA
· YDR_FI002_GIRO
· YDR_MM012_PO

Report Program name: YRE_XX999_XXXXXXXXX

YRE_ = prefix

XX999_ = module code

XXXXXXXXXX = self defined name

Example:

· YRE_SD001_INVOICELIST
· YRE_FI004_TAXLIST

Interface Program name: YIF_XX999_XXXXXXXXX

YIF_ = prefix

XX999_ = module code

XXXXXXXXX = self defined name

Example:

· YIF_PP001_UPLOAD_BOM
· YIF_SD007_SALES_ORDER

Includes Data Declaration includes:


1. YIN_XX999_XXXXXXXX_TOP
YIN_ = prefix
XX999_ = module code
XXXXXXX = self defined name
TOP = suffix

Example:
· YIN_SD001_INVOICELIST_TOP
· YIN_FI004_TAXLIST_TOP

9
Subroutines includes:
2. YIN_XX999_XXXXXXXX_FXX
YIN_ = prefix
XX999_ = module code
XXXXXXXXX = self defined name
FXX = Sequence number (F01, F02, F03,
…, F99)

Example:
· YIN_SD001_INVOICELIST_F01
YIN_FI004_TAXLIST_F02
·
Process Before Output includes:
3. YIN_XX999_XXXXXXXX_PBO
YIN_ = prefix
XX999_ = module code
XXXXXXXXX = self defined name
PBO = suffix process before output

Example:
· YIN_SD001_INVOICELIST_PBO
YIN_FI004_TAXLIST_PBO
·
Process After Input includes:
4. YIN_XX999_XXXXXXXX_PAI
YIN_ = prefix
XX999_ = module code
XXXXXXXX = self defined name
PAI = suffix process after input

Example:
· YIN_SD001_INVOICELIST_PAI
· YIN_FI004_TAXLIST_PAI

 Function Builder

Function Group Trans. Table name: YFG_XXXXXXXX

YFG_ = prefix

XXXXXXXX = self defined name

Example:

· YFG_BCS
YFG_UTILITIES

10
Function Module Structure name: YFM_XXXXXXXX

YFM_ = prefix

XXXXXXXX = self defined name

Example:

· YFM_CHANGE_DATE_FORMAT

 Selection Screen

Select Options Name: SO_XXXXX

SO_ = prefix

XXXXX = self defined name

Example:

 SO_VBELN

Parameters Name: PA_XXXXX

PA_ = prefix

XXXXXXXX = self defined name

Example:

 PA_VBELN

 SmartForm and SmartStyle

Smartforms Name: YFO_XXXXXXXXX

YFO_ = prefix

XXXXXXXXX = self defined name

Example:

 YFO_DELIVERY
 YFO_INVOICE

11
Smartstyles Name: YFO_XXXXXXXX_STYLE

YFO_ = prefix

XXXXXXXX = self defined name

_STYLE = suffix

Example:

 YFO_DELIVERY_STYLE
 YFO_INVOICE_STYLE

 Subroutines

Forms Form name: FM_XXXXXXXXX

FM_ = prefix

XXXXXXXXX = self defined name

Input Parameters:

 Tables:
o FT_XXXXX
o FT_ = prefix
o XXXXX = self defined name
 Using:
o FU_XXXXX or FV_XXXXX
o FU_ = prefix
o XXXXX = self defined name
 Changing:
o FC_XXXXX or FV_XXXXX
o FC_ = prefix
o XXXXX = self defined name

Example:

Form FM_COLLECT_DATA

tables FT_VBRK
Using FU_VBELN
Changing FC_LFIMG

…………………

Endform. " fm_collect_data

12
Modules Free definition

Example:

 module PF_STATUS output


 module NEXT_SCREEN input

 Various Variable

Variables 1. Global Variables: GV_XXXXX


GV_ = Prefix
XXXXX = self defined name

Example:
· GV_KUNNR
GV_DATE
·
2. Local Variables: LV_XXXXX
LV_ = Prefix
XXXXX = self defined name

Example:
 LV_MATNR
 LV_MATERIAL

Ranges 1. Global Ranges: GR_XXXXX


GR_ = Prefix
XXXXX = self defined name

Example:
· GR_KUNNR
GR_DATE
·
2. Local Ranges: LR_XXXXX
LR_ = Prefix
XXXXXX = self defined name

Example:
 LR_MATNR
 LR_MATERIAL

2. Z Convention
 ABAP Dictionary.

Transparent Table Trans. Table name: ZTA_XXXXXXXX

13
ZTA_ = prefix

XXXXXXXX = self defined name

Example:

 ZTA_FAKPJK
Structures Structure name: ZST_XXXXXXXX

ZST_ = prefix

XXXXXXXX = self defined name

Example:

 ZST_DOLIST
Data Element Data Element name: ZXXXXXX

Z = prefix

XXXXXX = self defined name

Example:

 ZMATNR
Domain Domain name: ZD_XXXXXX

ZD_ = prefix

XXXXXX = self defined name

Example:

 ZD_MATNR
Search Help Search Help name: ZSH_XXXXXX

ZSH_ = prefix

XXXXXX = self defined name

Example:

 ZSH_ITEM
View Table View name: ZTV_XXXXXX

ZTV_ = prefix

14
XXXXXX = self defined name

Example:

 ZTV_CUSTOMER

 Internal Table and Working Area

Internal tables 1. Global Internal Table: GI_XXXXX


GI_ = Prefix
XXXXX = self defined name

Example:
· GI_VBRK
GI_FAKPJK
·
2. Local Internal Table: LI_XXXXX
LI_ = Prefix
XXXXX = self defined name

Example:
· LI_VBRK
· LI_FAKPJK
Working Area 1. Global Working Area: GW_XXXXXX
GW_ = Prefix
XXXXXX = self defined name

Example:
· GW_LIKP
· GW_XTEXT

2. Local Working Area: LW_XXXXX


LW_ = Prefix
XXXXX = self defined name

Example:
 LW_LIPS
 LW_POORDER

 Program and Include

All programs, after prefix and before self defined name, are inserted with a
module code XX999. Meaning:

 For FI =FI001-FI999
 For CO =CO001-CO999

15
 For MM = MW001-MW999
 For WM = WM001-WM999
 For PP = PP001-PP999
 For QM = QM001-QM999
 For SD = SD001-SD999
 For HR = HR001-HR999

Driver Program name: ZDR_XX999_XXXXXXXXX

ZDR_ = driver prefix

XX999_ = module code

XXXXXXXXX = self defined name

Example:

· ZDR_SD001_FAKPJKSEDERHANA
· ZDR_FI002_GIRO
· ZDR_MM012_PO

Report Program name: ZRE_XX999_XXXXXXXXX

ZRE_ = prefix

XX999_ = module code

XXXXXXXXXX = self defined name

Example:

· ZRE_SD001_INVOICELIST
· ZRE_FI004_TAXLIST
Interface Program name: ZIF_XX999_XXXXXXXXX

ZIF_ = prefix

XX999_ = module code

XXXXXXXXX = self defined name

Example:

16
· ZIF_PP001_UPLOAD_BOM
· ZIF_SD007_SALES_ORDER
Includes Data Declaration includes:
1. ZIN_XX999_XXXXXXXX_TOP
ZIN_ = prefix
XX999_ = module code
XXXXXXX = self defined name
TOP = suffix

Example:
· ZIN_SD001_INVOICELIST_TOP
ZIN_FI004_TAXLIST_TOP
·
Subroutines includes:
2. ZIN_XX999_XXXXXXXX_FXX
ZIN_ = prefix
XX999_ = module code
XXXXXXXXX = self defined name
FXX = Sequence number (F01, F02, F03,
…, F99)

Example:
· ZIN_SD001_INVOICELIST_F01
ZIN_FI004_TAXLIST_F02
·
Process Before Output includes:
3. ZIN_XX999_XXXXXXXX_PBO
ZIN_ = prefix
XX999_ = module code
XXXXXXXXX = self defined name
PBO = suffix process before output

Example:
· ZIN_SD001_INVOICELIST_PBO
· ZIN_FI004_TAXLIST_PBO

Process After Input includes:


4. ZIN_XX999_XXXXXXXX_PAI
ZIN_ = prefix
XX999_ = module code
XXXXXXXX = self defined name
PAI = suffix process after input

Example:
· ZIN_SD001_INVOICELIST_PAI
· ZIN_FI004_TAXLIST_PAI

17
 Function Builder

Function Group Trans. Table name: ZFG_XXXXXXXX

ZFG_ = prefix

XXXXXXXX = self defined name

Example:

· ZFG_BCS
· ZFG_UTILITIES
Function Module Structure name: ZFM_XXXXXXXX

ZFM_ = prefix

XXXXXXXX = self defined name

Example:

· ZFM_CHANGE_DATE_FORMAT

 Selection Screen

Select Options Name: SO_XXXXX

SO_ = prefix

XXXXX = self defined name

Example:

 SO_VBELN
Parameters Name: PA_XXXXX

PA_ = prefix

XXXXXXXX = self defined name

Example:

 PA_VBELN

 SmartForm and SmartStyle

Smartforms Name: ZFO_XXXXXXXXX

18
ZFO_ = prefix

XXXXXXXXX = self defined name

Example:

 ZFO_DELIVERY
 ZFO_INVOICE
Smartstyles Name: ZFO_XXXXXXXX_STYLE

ZFO_ = prefix

XXXXXXXX = self defined name

_STYLE = suffix

Example:

 ZFO_DELIVERY_STYLE
 ZFO_INVOICE_STYLE

 Subroutines

Forms Form name: FM_XXXXXXXXX

FM_ = prefix

XXXXXXXXX = self defined name

Input Parameters:

 Tables:
o FT_XXXXX
o FT_ = prefix
o XXXXX = self defined name
 Using:
o FU_XXXXX or FV_XXXXX
o FU_ = prefix
o XXXXX = self defined name
 Changing:
o FC_XXXXX or FV_XXXXX
o FC_ = prefix
o XXXXX = self defined name

Example:

Form FM_COLLECT_DATA

tables FT_VBRK

19
Using FU_VBELN
Changing FC_LFIMG

…………………

Endform. " fm_collect_data

Modules Free definition

Example:

 module PF_STATUS output


 module NEXT_SCREEN input

 Various Variable

Variables 1. Global Variables: GV_XXXXX


GV_ = Prefix
XXXXX = self defined name

Example:
· GV_KUNNR
· GV_DATE

2. Local Variables: LV_XXXXX


LV_ = Prefix
XXXXX = self defined name

Example:
 LV_MATNR
 LV_MATERIAL
Ranges 1. Global Ranges: GR_XXXXX
GR_ = Prefix
XXXXX = self defined name

Example:
· GR_KUNNR
· GR_DATE

2. Local Ranges: LR_XXXXX


LR_ = Prefix
XXXXXX = self defined name

Example:
 LR_MATNR
 LR_MATERIAL

20
c. ABAP Data Types

Basicly ABAP Data types are grouped into :

1. Built-in Elementary Data Types

Character (text), Numerical character (number string), Date, Time


Integer, Floating point number, Packed number, and HeX code).
Data Meaning Initial Standard Permitted
Type Value Length Length
Numeric
P Packed 0 8 1-16
Number
I Integer 0 4 4
F Floating point 0.000… 8 8
no.
Alpha-
numeric
N Numeric text 00…0 1 1-max.
C Text blank 1 1-max.
D Date 00000000 8 8
(yyyyMMdd)
T Time 000000 6 6
(hhmmss)
X Hexadecimal X'00' 1 1-max.
Max : 65,535
bytes
Example :
>> Source Code
Data : a TYPE i,
b TYPE i,
c TYPE p DECIMALS 2.

START-OF-SELECTION.
a = 10.
b = 100.
c = a / b.
WRITE : / 'Hitung : ', a, '/', b, '=', c.

21
>> Display :

2. User-Define Data Types

User-define data types are enabled to declare into specific data-type as


reqiurement.

 Elementary Types

Elementary Types are simple data type which refer to another declarated type,
not to Built-in Elementary. Elementary Types are sorted into two :

1. Local ==> declarated data type inside program.

2. Global ==> declarated data type inside Include Program or inside ABAP
Dictionay ( Domain, Data Element, etc).

Example of Domain :

22
Example :

>> Source Code


DATA : A TYPE I,
B TYPE I,
C TYPE P DECIMALS 2.

DATA : D LIKE C. " Elementary Data Type (Local)

START-OF-SELECTION.
A = 10.
B = 100.
C = A / B.
D = C.
WRITE : / 'Hitung : ', A, '/', B, '=', D.

>> Display :

 Complex Types

Complex types are data type which consist of many data types.
Example :

>> Source Code


types : begin of ty_wa,
a type i,
b type i,
hasil type p decimals 2,
end of ty_wa.

Data : l_wa1 type ty_wa. " Structure (Workarea)

 Structures

In ABAP, structure is usually called as Workarea or Header Line. In


other language program, structure is equal as one dimension array.

>> Source Code


*First Style
types : begin of ty_wa,
a type i,
b type i,
hasil type p decimals 2,
end of ty_wa.

Data : l_wa1 type ty_wa. " Sturcture (Workarea)

*Second Style
data: begin of l_wa2,
a type i,
b type i,
hasil type p decimals 2,

23
end of l_wa2. " Sturcture (Workarea)

parameter p_a like l_wa1-a default 12.


parameter p_b like l_wa1-b default 14.

START-OF-SELECTION.
l_wa1-a = p_a.
l_wa1-b = p_b.

l_wa1-hasil = l_wa1-a / l_wa1-b.

write : / 'WA dari variabel A = ', l_wa1-a,


/ 'WA dari variabel B = ', l_wa1-b,
/ 'WA dari variabel Hasil = ', l_wa1-hasil.

>> Display :

Selection Screen:

Display:

 Table

In ABAP, tables are usually called as internal table (temporary table)


or table (real). In other language program, tables are equal as multi
dimension array.

>> Source Code


TYPES : BEGIN OF ty_wa,
a TYPE i,
b TYPE i,
hasil TYPE p DECIMALS 2,
END OF ty_wa.

* Internal Tables Declaration


DATA : gi_itab TYPE STANDARD TABLE OF ty_wa WITH HEADER
LINE.

*-----------------------------*

DATA : lv_counter TYPE i,


lv_puluhan TYPE i.

PARAMETER p_a LIKE gi_itab-a DEFAULT 12.


PARAMETER p_b LIKE gi_itab-b DEFAULT 14.
PARAMETER p_n TYPE i DEFAULT 100.

24
START-OF-SELECTION.
* Insert data to itab
CLEAR lv_counter.
DO p_n TIMES.
lv_counter = lv_counter + 1.

gi_itab-a = p_a + lv_counter.

lv_puluhan = gi_itab-a MOD 10.


IF lv_puluhan <> 0.
gi_itab-b = p_b + lv_counter.
gi_itab-hasil = p_a + p_b.
APPEND gi_itab.
ENDIF.
ENDDO.

*Display itab data


LOOP AT gi_itab.
WRITE : / gi_itab-a, gi_itab-b, gi_itab-hasil.
ENDLOOP.

>> Display :
Selection Screen

Display:

25
 ABAP Keywords

ABAP is more excellent than other language programs because it have more
than 700 keyword syntax to make program or customizing.

Keywords Description
, [, ], {, } Syntax conventions, Syntax notation
*, " Comments
** Arithm. Operator: Exponentiation (COMPUTE)
+, -, *, / Arithmetical operators (COMPUTE)
->, =>, ->>, ~, ?= Operators in ABAP Objects
ABS Mathematical function: Absolute amount
COMPUTE)
ACOS Mathematical function: Cosine arc (COMPUTE)
ADD Add
ADD- Field string addition
CORRESPONDING
ADJACENT Delete duplicates from internal table (DELETE)
DUPLICATES
AND Comparison operator: and
ANY TABLE Generic table type for internal tables
APPEND Append line to internaltable
ASIN Mathematical function: Sine arc (COMPUTE)
ASSIGN Assign field symbol
AT Event, control break, field group determination
ATAN Mathematical function: Tangent arc
AUTHORITY-CHECK Check authorization
AVG Aggregate expression: Average (SELECT)
BACK Positioning in list
BETWEEN Relational operator: Between
BINARY SEARCH Binary read of internaltable (READ TABLE)
BIT-NOT Bit calculation operator: NOT (COMPUTE)
BIT-AND Bit calculation operator: AND (COMPUTE)
BIT-OR Bit calculation operator: OR (COMPUTE)
BIT-XOR Bit calculation operator: AND/OR (COMPUTE)
SET BIT Set bit of an X field
GET BIT Read bit of an X field
BLANK LINES Switch on blank lines in list
BREAK-POINT Stop processing in debug mode
C Data type for fixed-length character string
CA Contains any characters -Relational operator
forstring comparison
CALL Call external component
CASE Begin case distinction
CATCH Exception handling (catch runtime errors)
CEIL Mathematical function: Smallest whole value
CENTERED Output format: Centered(WRITE)
CHECK Check condition

26
CHECKBOX Display as checkbox
PARAMETERS ... AS on the selection screen
CHECKBOX
WRITE ... AS in a list
CHECKBOX
CLASS Definition of a class
CLASS-DATA Static attributes in classes
CLASS-METHODS Static methods in classes
CLASS-EVENTS Static events in classes
CLASS-POOL Introduction for type Kprograms
CLEAR Initialize data object
CLIENT Client handling when
DELETE ... CLIENT deleting from a database
SPECIFIED
EXPORT ... TO Storing a data cluster
DATABASE ... CLIENT
IMPORT ... FROM Reading a data cluster
DATABASE ... CLIENT
EXPORT ... TO Storing a data cluster
SHARED BUFFER ...
CLIENT
IMPORT ... FROM Reading a data cluster
SHARED BUFFER ...
CLIENT
INSERT ... CLIENT inserting into a database
SPECIFIED
MODIFY ... CLIENT Insert/Modify in database(s)
SPECIFIED
SELECT ... CLIENT reading from a database
SPECIFIED
UPDATE ... CLIENT updating a database
SPECIFIED
CLOSE Close file/cursor
CN Contains Not Only - Relational operator for
character comparison:
CNT Field groups: Number ofdifferent values
CO Contains Only - Relational operator for character
comparison:
CODE PAGE Character set
TRANSLATE ... Translate character codes
FROM/TOCODE PAGE
COLLECT Internal table: Add entries
COLOR Output format: Color (FORMAT)
COMMENT Comment on selection screen
SELECTION-SCREEN Generate comment
COMMENT
COMMIT Close processing unit
COMMUNICATION Data exchange

27
COMPUTE Perform calculations
CONCATENATE Concatenate character fields
CONDENSE Condense character fields
CONSTANTS Defing constants
CONTEXTS Communicate contexts
CONTINUE Exit current loop pass
CONTROLS Define controls for visualization
CONVERT Convert fields
COS Mathematical function: Cosine (COMPUTE)
COSH Mathematical function: Hyperbola cosine
(COMPUTE)
COUNT Aggregate expression: Count (SELECT)
COUNTRY Set country ID (SET)
CP Relational operator forcharacter comparison:
DATABASE Contains Pattern
CREATE Generate an object or data object
CS Contains character - Relational operator
forcharacter comparison
CURRENCY Output format: Correct format for currency
(WRITE)
CURSOR Cursor
CLOSE Close database cursor
FETCH NEXT CURSOR Read lines with a database cursor
GET CURSOR FIELD Get field name
OPEN CURSOR Open database cursor
SET CURSOR Position cursor
CUSTOMER- Call customer enhancement
FUNCTION
DATA Define data
DATABASE Data cluster
DELETE FROM Delete from a database table
DATABASE
EXPORT ... TO Store in a databasetable
DATABASE
IMPORT ... FROM Read from a database table
DATABASE
DATASET Sequential file
CLOSE DATASET Close file
DELETE DATASET Delete file
EXPORT ... TO Store data cluster in file
DATASET
IMPORT ... FROM Read data cluster from file
DATASET
OPEN Open file
DATASET Open file
READ DATASET Read from a file
TRANSFER Output to a file
DECIMALS Output format: Places after the decimal point -

28
(WRITE)
DEFINE Define macro
DELETE Delete from tables or from objects
DEMAND Request information from a context
DESCRIBE Determine attributes ofdata objects
DIALOG Call a dialog module (CALL)
DISTINCT Duplicates
SELECT DISTINCT Selection set without duplicates
AVG( DISTINCT ... ) Average without duplicates (SELECT)
COUNT( DISTINCT ... Sequential file
)
MAX( DISTINCT ... ) Maximum without duplicates (SELECT)
MIN( DISTINCT ... ) Minimum without duplicates (SELECT)
SUM( DISTINCT ... ) Sum without duplicates (SELECT)
DIV Arithmetic operator: Whole number division
DIVIDE Divide
DIVIDE- Field string division
CORRESPONDING
Field string division
DO Loop
DYNPRO Screen Screen
DELETE Delete
DYNPRO Delete
EXPORT Export
DYNPRO Export
GENERATE Generate
DYNPRO Generate
IMPORT Import
DYNPRO Import
SYNTAX-CHECK FOR Check
DYNPRO Check
EDITOR-CALL Call editor
ELSE Query
ELSEIF Query
END-OF-DEFINITION End of a macro definition
END-OF-PAGE Event: End of page handling in lists
END-OF-SELECTION Event: After processingof all records in a LDB
ENDAT End of an event introduced by AT
ENDCASE End of case distinction
ENDCATCH End of exception handling
ENDDO End of a DO loop
ENDEXEC End of a Native SQL statement
ENDFORM End of a subroutine
ENDFUNCTION End of a function module
ENDIF End of a query
ENDINTERFACE End of an interface definition
ENDLOOP End of a LOOP
ENDMODULE End of a module definition

29
ENDON End of a conditional statement
ENDPROVIDE End of a PROVIDE loop
ENDSELECT End of a SELECT loop
ENDWHILE End of a WHILE loop
EQ Relational operator: Equals
EXEC SQL Native SQL statement
EXIT Exit loop or terminate processing
EXP Mathematical function: Exponential function
EXPONENT Output format: Exponentdisplay (WRITE)
EXPORT Export data
EXTENDED CHECK Switch extended syntax check on/off (SET)
EXTRACT Generate extract dataset
FETCH Read line from a database table
FIELD-GROUPS Define field groups
FIELD-SYMBOLS Define field symbols
FLOOR Mathematical function:Largest whole value
FORM Define subroutine
FORMAT Output format for lists
FOR UPDATE Read database table with lock (SELECT)
FRAC Mathematical function: Fraction (COMPUTE)
FREE Release resources no longer needed
FUNCTION Define function module
CALL FUNCTION Call function module
FUNCTION-POOL Introduction for type Fprograms
GE Relational operator: Greater than or equal
GENERATE Generate a program or screen
GET Event, read settings
GT Relational operator: Greater than
HASHED TABLE Table type for internalhashed tables
HEADER LINE Define an internal table with header line (DATA)
HELP-ID Help ID for F1 help
DESCRIBE FIELD ... Determine help ID
HELP-ID
HELP-REQUEST Self-programmed help (F1)
PARAMETERS ... for parameters
HELP-REQUEST
SELECT-OPTIONS ... for selection options
HELP-REQUEST
HIDE Store line information
HOTSPOT Output format: Hotspot,interaction by simple -
mouse click (FORMAT)
ICON Icons in lists
IF Query
IMPORT Import data or a screen
IN Relational operator: Selection criterion
INCLUDE Include program components
INDEX Line index in an internal table

30
INDEX TABLE
DELETE ... INDEX Delete line
INSERT ... INDEX Insert line
MODIFY ... INDEX Modify line
READ TABLE ... INDEX Read line
INFOTYPES Declare HR info type
INITIAL Relational operator: Initial value
INITIAL SIZE Define an internal table type (TYPES)
INITIALIZATION Event: Before display of the selection screen
INPUT Output format: Ready for input (FORMAT)
INSERT Insert into tables or objects
INTENSIFIED Output format: Intensified (FORMAT)
INTERFACE Definition of an interface
INTERFACES Class component interface
INTERFACE-POOL Introduction fortype J programs
INVERSE Output format: Inverse (FORMAT)
IS Relational operator
IS ASSIGNED Relational operator: Is the field symbol assigned?
IS INITIAL Relational operator: Initial value
IS REQUESTED Relational operator: Existence of a formal
parameter
JOIN Join (SELECT)
LANGUAGE Set language for text elements (SET)
LE Relational operator: Less than or equal
LEAVE Leave processing
LEFT-JUSTIFIED Output format: Left-justified (WRITE)
LIKE Use an existing field as areference
TYPES ... LIKE Create a type
DATA ... LIKE Create a field
LINE Line in a list
MODIFY LINE Modify line
READ LINE Read line
LINE-COUNT Number of lines per page (NEW-PAGE)
LINE-SIZE Line size (NEW-PAGE)
LIST-PROCESSING List processing (LEAVE)
LOAD Load program componentsin internal table
LOAD-OF- Execution at load time
PROGRAM
LOCAL Rescue actual parameters of a subroutine
LOCAL COPY Assign local copy to a field symbol
LOCALE Set text environment (SET)
SET LOCALE Set text environment
GET LOCALE Determine text environment
LOG Mathematical function: Natural logarithm
(COMPUTE)
Logical condition
SELECT ... WHERE when reading database tables

31
UPDATE ... WHERE when changing database tables
DELETE ... WHERE when deleting fromdatabase tables
SELECT ... FROM ... when reading usinga join
ON
LOG10 Mathematical function: Base 10 logarithm
(COMPUTE)
LOOP Loop
LT Relational operator: Less than
M Relational operator: Byte contains zeros and ones
MARGIN List output: Distance from edge (SET)
MATCHCODE Matchcode handling
PARAMETERS ... for parameters
MATCHCODE
SELECT-OPTIONS ... for selection options
MATCHCODE
MAX Aggregate expression: Maximum (SELECT)
MEMORY ABAP/4 memory
EXPORT ... TO Roll out data to memory
MEMORY
IMPORT ... FROM Restore data from memory
MEMORY
MESSAGE Output message
MESSAGE-ID Specify message class (REPORT)
METHOD Definition of a method
METHODS Class component method
MIN Aggregate expression: Minimum (SELECT)
MOD Arithmetic operator: Remainder after division
(COMPUTE)
MODIFY Modify tables or objects
MODULE Flow logic: Module
MOVE Assignment
MOVE- Component-by-component assignment
CORRESPONDING
MULTIPLY Multiply
MULTIPLY- Field string multiplication
CORRESPONDING
NA Relational operator forcharacter comparison:
Contains not any characters
NE Relational operator: Not equal
NEW-LINE List processing: New line
NEW-PAGE List processing: New page
NODES Interface work area forlogical databases
NO-GAP Output format: Leave nogaps (WRITE)
NO-HEADING Display no column headers (NEW-PAGE)
NO-SCROLLING Do not scroll line (NEW-LINE)
NO-SIGN Output format: No preceding signs (WRITE)
NO-TITLE Do not display standardpage header (NEW-PAGE)
NO-ZERO Output format: No leading zeros (WRITE)

32
NON-UNIQUE Defines an
TYPES internal table type
DATA internal table object
NP Relational operator forcharacter comparison:
Does not contain pattern
NS Relational operator forcharacter comparison:
Does not contain character
O Relational operator: Byte positions occupied by1
OBJECT External object
CREATE OBJECT Generate
FREE OBJECT Release
OCCURS Defines an
TYPES internal table type
DATA internal table object
ON CHANGE Control break
OPEN Open file/cursor
OR Relational operator: OR
ORDER BY Sort table rows (SELECT)
OVERLAY Overlay character fields
PACK Conversion
PARAMETER Parameter in global SAP memory
GET Read parameter
SET Set parameter
PARAMETERS Define report parameters
PERFORM Execute subroutine
PF-STATUS Set GUI status
POSITION List processing: Defineoutput position
PRINT Print formatting (NEW-PAGE)
PRINT-CONTROL Define print format
PRIVATE Class area not visible from outside
PROGRAM Introduction for type Mand S programs
LEAVE PROGRAM Leave program
PROPERTY Object property
GET PROPERTY Get property
SET PROPERTY Set property
PROVIDE Internal tables: Interval-related processing
PUT Trigger event
RADIOBUTTON Radio button (PARAMETERS)
RAISE Raise exceptions and events
RAISING Raise error message in function module
RANGES Define internal table for selection criterion
READ Read tables or objects
RECEIVE Receive results (RFC)
REFRESH Delete internal table
REFRESH CONTROL Initialize control
REJECT Do not process current database line further
REPLACE Replace characters

33
REPORT Introduction for type 1programs
DELETE REPORT Delete program
EDITOR-CALL FOR Call ABAP program editor
REPORT
INSERT REPORT Insert program in library
READ REPORT Read program
RESERVE List processing: Conditional new page
RESET Output format: Reset all formats (FORMAT)
RIGHT-JUSTIFIED Output format: Right justified (WRITE)
ROLLBACK Roll back database changes
ROUND Output format: Scaled (WRITE)
RTTI Runtime type identification
RUN TIME ANALYZER Activate/Deactivate runtime analysis (SET)
SCAN Analyze ABAP/4 source code
SCREEN Screen
CALL SCREEN Call screen
SET SCREEN Set next screen
LEAVE SCREEN Leave screen
LEAVE TO SCREEN Branch to a screen
LOOP AT SCREEN Loop through screen fields
MODIFY SCREEN Modify screen fields
SCROLL List processing: Scroll
SCROLL- List processing: Fix lead columns (SET)
BOUNDARY
SEARCH Find character
SELECT Read database table
SELECT-OPTIONS Define selection criterion
SELECTION-SCREEN Design selection screen
AT SELECTION- After editing ofselection screen
SCREENEvent:
SHARED BUFFER Cross-transaction application buffer
DELETE FROM delete from application buffer
SHARED BUFFER
EXPORT ... TO Store data in application buffer
SHARED BUFFER
IMPORT ... FROM Read data from application buffer
SHARED BUFFER
SELECTION-TABLE Selection table (SUBMIT)
SET Set different processing parameters
SHIFT Move character
SIGN Mathematical function: Sign (COMPUTE)
SIN Mathematical function: Sine (COMPUTE)
SINGLE Select single record (SELECT)
SINH Mathematical function: Hyperbola sine
(COMPUTE)
SKIP List processing: Outputblank line
SORT Sort internal table or extract dataset
SORTED TABLE Table type for internaltables that are always kept

34
SPLIT Split character fields
SQRT Mathematical function: Square root (COMPUTE)
STANDARD TABLE Table type for standardinternal tables
START-OF- Event: Before first access to LDB
SELECTION
STATICS Define static data
STOP Stop data selection (LDB)
STRING Data type for variable-length character sequence
STRLEN Character function: Current length (COMPUTE)
STRUCTURE Data structure
INCLUDE Use structure
STRUCTURE
SUBMIT Program call
SUBTRACT Subtract
SUBTRACT- Field string subtraction
CORRESPONDING
SUM Calculate control total
SELECT ... SUM Aggregate expression: Total
SUPPLY Supply context key fields
SUPPRESS DIALOG Suppress dialog
SYMBOL Output as symbol (WRITE)
SYNTAX-CHECK Syntax check for programs and screens
SYNTAX-TRACE Syntax check log
SYSTEM-CALL Call to various system services
SYSTEM- Catch runtime errors (CATCH)
EXCEPTIONS
TABLE LINE Unstructured lines in internal tables
TABLE_LINE Unstructured lines in internal tables
TABLES Declare database table
TABLE Set or array operations for database tables
DELETE ... FROM Delete block of lines
TABLE
INSERT ... FROM Insert block of lines
TABLE
MODIFY ... FROM Insert/update block of lines
TABLE
UPDATE ... FROM Update block of lines
TABLE
SELECT ... INTO Copy block of lines to internal table
TABLE
TAN Mathematical function: Tangent (COMPUTE)
TANH Mathematical function: Hyperbola tangent
(COMPUTE)
TEXT Locale-specific
CONVERT TEXT Set format
SORT itab AS TEXT Sort an internal table
SORT AS TEXT Sort an extract dataset
TEXTPOOL Text elements

35
DELETE TEXTPOOL Delete
INSERT TEXTPOOL Insert
READ TEXTPOOL Read
TIME Time measurement
GET RUN TIME Get runtime
GET TIME Get time
SET RUN TIME Switch runtime analysison/off
ANALYZER
TIME STAMP Time stamp
GET TIME STAMP Get time stamp
CONVERT TIME Convert time stamps to date/time
STAMP
WRITE f TIME ZONE Output of time stamps to lists
TITLEBAR Set screen title (SET)
TOP-OF-PAGE Event: Top of page handling in lists
TRANSACTION SAP transaction
CALL TRANSACTION Call
LEAVE TO Leave to
TRANSACTION
TRANSFER Output to file
TRANSLATE Character conversion incharacter fields
TRANSPORTING Selective field transport
MODIFY ... Modify lines of an internal table
TRANSPORTING
READ ... Read lines of an internal table
TRANSPORTING
LOOP ... Loop through an internal table
TRANSPORTING
TRUNC Mathematical function: Whole number part
(COMPUTE)
TYPE Define a type
TYPES ... TYPE Define a type
DATA ... TYPE Define a field
TYPE-POOL Introduction for type Tprograms
TYPE-POOLS Include type group
TYPES Define types
ULINE List processing: Underscore
UNDER Output format: One under the other (WRITE)
UNIQUE Define an
TYPES internal table type
DATA internal table object
UNIT Output format: Unit (WRITE)
UNPACK Conversion
UPDATE Update database table
USER-COMMAND List processing: Execute command immediately
(SET)
USING Use parameter or format
USING Parameter of a subroutine

36
USING EDIT MASK Output format: Use template (WRITE)
VALUE-REQUEST Self-programmed value help(F4)
PARAMETERS ... for parameters
VALUE-REQUEST
SELECT-OPTIONS ... for selection options
VALUE-REQUEST
WHEN Case distinction
SELECT ... WHERE when reading from databasetables
UPDATE ... WHERE when changing database tables
DELETE ... WHERE when deleting database tables
LOOP AT ... WHERE when looping at internal tables
DELETE ... WHERE when deleting from internal tables
WHILE Loop
WINDOW List processing: Outputin window
WITH-TITLE Output standard page header (NEW-PAGE)
WORK Processing unit
COMMIT WORK Close unit
ROLLBACK WORK Close unit, but undo changes
WRITE List processing: Output
WRITE TO Correct type output in a variable
X Data type for fixed-length byte sequence
XSTRING Data type for variable-length byte sequence
Z Relational bit operator: Bit positions occupiedby

d. ABAP Syntax
Syntax at ABAP program consist of few type, these are:
1. Statement

Statement is lines of codes which instruct an order. In ABAP, every statement


always close by dot(.) at the end.

These are few examples of statements:

>> Source Code

write 'Hello, World !!'.

>> Display

Statements are always begined by ABAP Keywords (Example: TYPES , DATA , write
dst). Keyword determine statement Catagory.

These are reference of statement at ABAP Program:

1. Data Types
2. Declaration Data Types

37
This statement use to define a data type or object as variable of program.

Example :
TYPES <variable_name> TYPE <type>.
DATA <variable_name> TYPE <type>.

3. Compound Statement

Compound Statement is group of statements of a block coding. It's also called


as "Block Statement".

Example :
FORM <form_name>.
Statement 1.
Statement 2.
...
Statement n.
ENDFORM.

FUNCTION <function_name>.
Statement 1.
Statement 2.
...
Statement n.
ENDFUNCTION.

MODULE <module_name>.
Statement 1.
Statement 2.
...
Statement n.
ENDMODULE.

4. Control Statement

Control Statement is used to control statement flow according to conditions


that siutable to algoritma of program we want.

Example :
IF <condition1>.
<statement block>
ELSEIF <condition2>
<statement block>.
ELSEIF <condition3>.
<statement block>
.....
ELSE.
<statement block>
ENDIF.

5. Operator Statement

Operator Statement is keyword for doing some process of type/object that


declared in a program.

38
Example :
WRITE <statement>.
ADD <variable 1> to <variable 2>.

6. Database Statement

Database Statement is statement that used for accessing database. In ABAP,


there are 2 statement for accessing database, these are Open SQL and Native
SQL.

7. Structures
8. Internal Tables

2. Literal

Literal is the way to declare directly a value in language program.


There are 2 type of literal at ABAP, these are:

1. Numerical Literal

Example :
a = 10.
b = 100.

2. Text Literal

Text Literal initiate and close by sitation (').

Example :
write 'Hello, World !!'.

3. Chained Statement

ABAP has classical language program caracteristic, that is, in every statement in
main program or in block statement will be executed in sequence from the top to
bottom.

Example :

No. Statement
1 Data : a TYPE i,
b TYPE i,
c TYPE p DECIMALS 2.

2 START-OF-SELECTION.

3 a = 10.

4 b = 100.

5 c = a / b.

6 WRITE : / 'Hitung : ', a, '/', b, '=', c.

39
From the example above, ABAP will execute from number 1 to 6.

4. Comment

Inside the source code, comment is explanation or infomation for statement or


block statement. It's important to give explanation about steps or algoritm of
ABAP program. If someone else want edit that program, it's not difficult to study
the logic algoritm in code of program.

There are 2 kind of comment in ABAP, these are:


1. Use key star(*), and locate it in the first character at line program.

Example :
FORM fm_process_data.
*Get other requirement information
LOOP AT gi_header.
* Get Material Description
READ TABLE gi_makt WITH KEY matnr = gi_header-matnr.
IF sy-subrc = 0.
gi_header-maktx = gi_makt-maktx.
ENDIF.

* Get Measurement Text


READ TABLE gi_t006a WITH KEY msehi = gi_header-meins.
IF sy-subrc = 0.
gi_header-mseht = gi_t006a-mseht.
ENDIF.

MODIFY gi_header.
ENDLOOP.

ENDFORM.

2. Use double sitation(”), its free to located it.

Example :
FORM fm_process_data.
"Get other requirement information
LOOP AT gi_header.
"Get Material Description
READ TABLE gi_makt WITH KEY matnr = gi_header-matnr.
IF sy-subrc = 0.
gi_header-maktx = gi_makt-maktx.
ENDIF.

"Get Measurement Text


READ TABLE gi_t006a WITH KEY msehi = gi_header-meins.
IF sy-subrc = 0.
gi_header-mseht = gi_t006a-mseht.
ENDIF.

MODIFY gi_header.
ENDLOOP.

ENDFORM.

40
e. ABAP Dictionary
Menu Path SAP Menu > Tools > ABAP Workbench > Development >
ABAP Dictionary
Transaction code SE11
 Domain
Domain is a part of Elementary Types with global type, which use at all Data
Element.

Steps to make Domain

1. Open t-code SE11

2. Activate Radio Button

3. Insert Domain Name, initiate with letter Z or Y

4. Click Button

5. Fill in Short Description. Then fill in Data Type, No. Characters, Decimal
places and Output length like below.

41
6. Click button

7. Package is filled to make Transportable Domain into other client, but you
don't need to fill it if practice only.

8. Click button to make Transportable Domain into other client. Click


button for practice only.

9. Click button to activate Domain

 Data Element

42
Data Element is a part of Elementary Types with global type, which use at all
Field (in Table) and to be reference data type in ABAP program.

Steps to make Data Element

1. Open t-code SE11

2. Activate Radio Button

3. Insert Data Element Name, initiate with letter Z or Y

4. Click Button

5. Choose Data Element, then Click Button

6. Fill in Short Description. Then fill in Domain if you want to use data type
from Domain. But if you want to make data type then activate Built-int type.

43
7. Activate Field label's type then Fill in Field label as requirement, for finish
press enter.

8. Click Button

9.Package is filled to make Transportable Data Element into other client, but
you don't need to fill it if practice only.

44
10. Click button to make Transportable Data Element into other client.
Click button for practice only.

11. Click button to activate Data Element.

 Structure

Structure is a part of Complex Types with global type structures, which able to
be reference data type in all ABAP Program.

Steps to make Table

1. Open t-code SE11

2. Activate Radio Button

3. Insert Structure name, initiate with letter Z or Y

4. Click Button

5. Choose Structure, then Click button

6. Fill in Short Description.

7. Fill in fields as requirement. If fields have same data type with in Data
Element, then fill it in Data Element Coloums. If some fields have dfferent

45
data type with SAP Data Element, then click button to activate
Data Type Coloum. If you finish, click button again to activate
Data Element Coloums.

8. Click Button

9. Package is filled to make Transportable Structure into other client, but you
don't need to fill it if practice only

10. Click button to make Transportable Structure into other client. Click
button ”Local Object” for practice only.

46
11. Click button to activate Structure.

 Table

Table is a part of Complex Types with global type tables but, Table is able to
filled in and saved at server, which to be reference data type in ABAP
program

Steps to make Table

1. Open t-code SE11


2. Activate Radio Button
3. Insert Table's name, initiate with letter Z or Y

4. Click Button
5. Fill in Short Description. Then fill in Delivery Class and Data
Browser/Table View Maint. like picture below..

6. Activate tab of Fields. Then filled in Field and it's attribut like below.

Note :
" MANDT " Field have to make to differentiate data by client, If there are
more than one· client in a server.
If CheckBox Key is activated then the current field is mandatory and to be
primary key. ·
if initial CheckBox is activated, then current field have initial
value appropriate
· with it's data type when to be append and

47
inserted.

7. Fill in fields as requirement. If fields have same data type with in Data
Element, then fill it in Data Element Coloums. If some fields have dfferent
data type with SAP Data Element, then click button to
activate Data Type Coloum. If you finish, click button again
to activate Data Element Coloums.

8. Click Button
9. Package is filled to make Transportable Table into other client, but you
don't need to fill itif practice only

48
10. Click button to make Transportable Table into other client. Click button
for practice only.

11. Click button


12. Fill in Data Class and Catagory Size like picture below.

13. Click button


14. Click button , to back to main menu.
15. Click button to activate table.

49
 View
View is a part of Complex Types with global type tables with content of
collaborate of table. Beside that, it can be reference data type in all ABAP
Program.
Steps to make Table
1. Open t-code SE11
2. Activate Radio Button
3. Insert Structure name, initiate with letter Z or Y

4. Click Button
5. Choose Database view, then Click Button

6. Fill Short Description.


Important : Source are table with name's YTEST and YTEST2. Make table
YTEST2 if it's not already available yet, like picture below.

50
7. Join two table with name YTEST and YTEST2 like picture below.

8. Activate field View Fields. Then fill the coloums like below.

9. Click Button

51
10. Package is filled to make Transportable View into other client, but you
don't need to fill it if practice only.

11. Click button to make Transportable View into other client. Click button
for practice only.

12. Click Button to activate View.

a. Function Builder
 Function Group
Function group is group to cluster Function Module.
Steps to make Function Group

1. Open t-code SE37


2. Click menu "Create group"

3. Fill Function Group name and Short text, but the naming must initiate by letter
Z or Y.

4. Click button

52
5. Package is filled to make Transportable Function Group into other client, but
you don't need to fill it if practice only.

6. Click button to make Transportable Function Group into other client. Click
button for practice only.

 Function Module
Steps to make Function Module
1. Open t-code SE37
2. Fill Function Module name, initiate by letter Z or Y

3. Click Button
4. Fill in Function Group And Short Text

5. Click Button

6. Click Button .

53
g. Form

Menu Path SAP Menu > Tools > Form Printout > Smart Forms
Transaction code SMARTFORMS

 Smartform

Menu Path SAP Menu > Tools > Form Printout > Smart Forms
Transaction code SMARTFORMS

SAP Smart Forms allow you to execute simple modifications to the form and in
the form logic by using simple graphical tools; in 90% of all cases, this won't
include any programming effort. Same with ABAP Editor, SAP User must have
Developer Key to create SmartForms.

Step to Create New Form

54
1. Open t-Code SMARTFORMS

2. Insert name of program, program name must begin with the letter Z or Y

4. Click .

5. Change the world on the 'Meaning' if necessary.

6. Click .

55
7. Optional insert Package to create programs that can transport to another client,
if only for training package need not be filled.

8. Click save if you want to create a program that can be transported to


another client. or click if only for training.

9. SmartForms been made.

 Smartstyles

h. Enhancement

Jalur Menu SAP Menu > Tools > ABAP Workbench > Utilities >
Business Add-Ins > Implementation

SAP Menu > Tools > ABAP Workbench > Utilities >
Enhancements > Project Management
Kode Transaksi SE19 dan CMOD

SAP prepare space to make program appropriate with customer's requirement.


Commonly, there are 2 kind of it : user exit and Bussines Add-Ins (BADI). The detail
explanation for every program need, can be look at functional specification's
documentations.

 Commont Transaction Code

 Basis

al08 - Currently Active users


rz04 - CCMS : Operation Mode
scc3 - Monitoring Proses Copy Client
scc4 - Mantain or Change SAP Client
se01 - Transport Organizer
se10 - Display Transport Request
sgen - SAP Load Generator (Contoh : buat generate SAP GUI)
sm04 - user List
sm12 - lock/unlock table
sm51 - SAP Servers
56
smlg - buat auto balancing
spro - Execute Project (contoh : buat Settingan Help dll)
ST22 - Shortdump Analysis
STMS - Transport Management System

 Customizing and Developing

se11 - ABAP Dictionary


se16 - Open and displayTable
se18 - Create Definition untuk BADI
se19 - Maintenance Screen (Edit BADI)
se37 - Function Builder
se38 - Abap Editor
se73 - SAPscript Font Maintenance
se91 - Massage Class
se93 - Create T-Code
sm30- Maintain Table Views: Intial Screen
sqvi - Quick Viewer
sldb - Logical Database Builder
shdb - Transaction Recorder: Recording Overview (Create BDC Program)
lrfmd - Assignment User
lm00 - Configuration Screen for RF
snro - No. Range Object: Change
cmod - Project Management og SAP Enhancements
spro - Configurasi, Costumizing, Program Information dan sebagainya

 Job

sm36 - Define Background Job


sm37 - Job overview

 User and Authorization

su01 - Maintain User


su02 - Edit Profiles Manually
su03 - Edit Authorizations Manually
su21 - List of Object Classes
su53 - Object Authorization Information
pfcg - Roles

 SAP Communication

SCOT - SAPconnect: Administration (System Status)


SALE - ALE (Application Link Enabling)

 Spool Printer

spad - Spool Administration <- Printer Setting ->


sp01 - Output Controller (Spool)

57
sp02 - List of Spool Requests

 Screen SAP GUI


/n - Close transaction's Session
/i - Delete currently active session
/o - Make SAP GUI Session
/nend - Logout from SAP
/nex - Logout from SAP without any warning
/h - Debug ABAP Program

i. Examples

 Example 1 (Built-in Elementary Data Type)

Objective ▪ Creating Report

▪ Result

▪ Source Code

Transaction SE38 - ABAP Editor


Code
Tables
Support

Creating Report

1. Create New Program

Program Name : YEXAMPLES_01


Title : Built-in Elementary Data Types

2. Declare Global Variable

*--------------------------------------------------------------------*
*GLOBAL VARIABLE DECRALATION
*--------------------------------------------------------------------*
DATA : a TYPE i,
b TYPE i,
c TYPE p DECIMALS 2.

3. Create Main Program

*====================================================================*
*MAIN PROGRAM
*Execute after Input Screen
*====================================================================*
START-OF-SELECTION.

58
a = 10.
b = 100.
c = a / b.
WRITE : / 'Hitung : ', a, '/', b, '=', c.

4. Activated and Run


5. Finished

Result

Input:

None.

Output:

 Example 2 (Elementary Types)

Objective ▪ Creating Report

▪ Result

▪ Source Code

Transaction SE38 - ABAP Editor


Code
Tables
Support

Creating Report

1. Create New Program

Program Name : YEXAMPLES_02


Title : Elementary Types

2. Declare Global Variable


*----------------------------------------------------------------*
*GLOBAL VARIABLE DECRALATION
*----------------------------------------------------------------*
DATA : a TYPE i,
b TYPE i,
c TYPE p DECIMALS 2.

DATA : d LIKE c. " Elementary Data Type (Local)

3. Create Main Program

59
*================================================================*
*MAIN PROGRAM
*Execute after Input Screen
*================================================================*
START-OF-SELECTION.
a = 10.
b = 100.
c = a / b.
d = c.
WRITE : / 'Hitung : ', a, '/', b, '=', d.
4. Activated and Run
5. Finished

Result

Input:
None.

Output:

 Example 3 (Complex Types)

Objective ▪ Creating Report

▪ Result

▪ Source Code

Transaction SE38 - ABAP Editor


Code
Tables
Support

Creating Report

1. Create New Program

Program Name : YEXAMPLES_03


Title : Complex Types (Structures)

2. Declare Global Variable

*----------------------------------------------------------------*
*GLOBAL VARIABLE DECRALATION
*----------------------------------------------------------------*
*First Style
types : begin of ty_wa,
a type i,
b type i,
hasil type p decimals 2,
end of ty_wa.

60
Data : l_wa1 type ty_wa. " Sturcture (Workarea)

*Second Style
data: begin of l_wa2,
a type i,
b type i,
hasil type p decimals 2,
end of l_wa2. " Sturcture (Workarea)

3. Create Input Screen/Selector

*----------------------------------------------------------------*
*Input Screen/Selection
*----------------------------------------------------------------*
parameter p_a like l_wa1-a default 12.
parameter p_b like l_wa1-b default 14.

4. Create Main Program

*================================================================*
*MAIN PROGRAM
*Execute after Input Screen
*================================================================*
START-OF-SELECTION.
l_wa1-a = p_a.
l_wa1-b = p_b.

l_wa1-hasil = l_wa1-a / l_wa1-b.

write : / 'WA dari variabel A = ', l_wa1-a,


/ 'WA dari variabel B = ', l_wa1-b,
/ 'WA dari variabel Hasil = ', l_wa1-hasil.
5. Activated and Run
6. Finished

Result

Input Selection:

Output:

 Example 4 (Complex Types [Table])

61
Objective ▪ Creating Report

▪ Result

▪ Source Code

Transaction SE38 - ABAP Editor


Code
Tables
Support

Creating Report

1. Creating New Program

Program Name : YEXAMPLES_04


Title : Complex Types (Tables)

2. Declare Global Variable


*----------------------------------------------------------------*
*GLOBAL VARIABLE DECRALATION
*----------------------------------------------------------------*

*First Style
TYPES : BEGIN OF ty_wa,
a TYPE i,
b TYPE i,
hasil TYPE p DECIMALS 2,
END OF ty_wa.

*Internal Table Declaration


DATA : gi_itab TYPE STANDARD TABLE OF ty_wa WITH HEADER LINE.
*----------------------------------------------------------------*

DATA : lv_counter TYPE i,


lv_puluhan TYPE i.

3. Create Input Screen/Selector

*----------------------------------------------------------------*
*Input Screen/Selection
*----------------------------------------------------------------*

PARAMETER p_a LIKE gi_itab-a DEFAULT 12.


PARAMETER p_b LIKE gi_itab-b DEFAULT 14.
PARAMETER p_n TYPE i DEFAULT 100.

4. Create Main Program

*================================================================*
*MAIN PROGRAM
*Execute after Input Screen
*================================================================*
START-OF-SELECTION.

62
* insert Into itab
CLEAR lv_counter.
DO p_n TIMES.
lv_counter = lv_counter + 1.

gi_itab-a = p_a + lv_counter.

lv_puluhan = gi_itab-a MOD 10.


IF lv_puluhan <> 0.
gi_itab-b = p_b + lv_counter.
gi_itab-hasil = p_a + p_b.
APPEND gi_itab.
ENDIF.
ENDDO.

*Display itab data


LOOP AT gi_itab.
WRITE : / gi_itab-a, gi_itab-b, gi_itab-hasil.
ENDLOOP.

5. Activated and Run


6. Finished

Result

Input Selection:

Output:

 Example 5 (Select Data)

63
Objective ▪ Creating Report

▪ Result

▪ Source Code

Transaction SE38 - ABAP Editor


Code
Tables MARA - General Material Data
Support

Creating Report

1. Creating New Program

Program Name : YEXAMPLES_05


Title : Select Data

2. Declare Global Variable


*----------------------------------------------------------------*
*GLOBAL VARIABLE DECRALATION
*----------------------------------------------------------------*
TYPES: BEGIN OF ty_header,
matkl LIKE mara-matkl, " Material Group
matnr LIKE mara-matnr, " Material Number
END OF ty_header.

* Internal Table Declaration


DATA: gi_header TYPE STANDARD TABLE OF ty_header WITH HEADER LINE.
*----------------------------------------------------------------*

3. Create Input Screen/Selector

*----------------------------------------------------------------*
*Input Screen/Selection
*----------------------------------------------------------------*

parameters: pa_matkl like mara-matkl default '001'.

4. Create Main Program


*================================================================*
*MAIN PROGRAM
*Execute after Input Screen
*================================================================*

* Collect Master Material


SELECT matnr matkl bismt meins
INTO CORRESPONDING FIELDS OF TABLE gi_header
FROM mara
WHERE
matkl = pa_matkl.

* Display Data to Screen

64
LOOP AT gi_header.
write : /'|' no-gap,(9) gi_header-matkl centered,
'|' no-gap,(18) gi_header-matnr,
'|' no-gap.
ENDLOOP.

5. Activated and Run


6. Finished

Result

Input Selection:

Output:

65
BAB 2

ABAP-REPORT

a. Basic Knowledge

Objective Know how to select sap tables and display it as a report

▪ Report (101) - Create Simple Report

Support Video Report - 101

Report (101) - Create Simple Report

 Input Selection

 Output

Functional Specification (101)

I. REQUEST
Module MM (Material Date 21 April 2008
Management)
Request - Initial Name
By

66
Request ABAP Report Characteristic Display Output
Type
Printer - Reference T- MM03
Code

II. OBJECT INFO


1 Package $TMP 4 T-Code YP101
2 Program YPRACTICE_101 5 Include
Name Program
3 Function 6
Module

III. DETAIL DESCRIPTION


1 Background Display List of Master Material
2 Flow of Process Select Material Data -> Display
3 Table MARA, MAKT, T006A
4 Input Screen/Selection Material Group (MARA-
MATKL)

Material Number (MARA-


MATNR)
5 Output
Mat. Mat. No. Description Old Mat. Base Unit Measure
Group No. of
Measure
(MARA- (MARA- (MAKT-MAKTX) (MARA-BISMT) (MARA-MEINS) (T006A-
MATKL) MATNR) MSEHT)

Report (101)

Creating Report

1. Create New Program

Program Name : YPRACTICE_101 ( Functional Specification II-2 )


Title : 101 - Display List of Master Material

2. Observe about Master Material in SAP Standard Program. Asked to functional as


need.

67
Display Steps

 Open T-Code MM03 in new session (/oMM03)


 Select Material

 Press enter and *Select ”Basic Data 1” and ”Basic Data 2”. Then press

 Display Material

3. Start writing ABAP Code. First declare table ( Functional Specification III-3 )

*----------------------------------------------------------------------*

*Tables

*----------------------------------------------------------------------*

TABLES : mara, makt, t006a.

68
4. Declare Global Variable

*----------------------------------------------------------------------*

*GLOBAL VARIABLE DECRALATION

*----------------------------------------------------------------------*

DEFINE macro_data_possition.

if &1 = 'HEADER'.

write : /'|' no-gap,(9) &2 centered,

'|' no-gap,(18) &3 centered,


'|' no-gap,(40) &4 centered,
'|' no-gap,(18) &5 centered,
'|' no-gap,(5) &6 centered,
'|' no-gap,(10) &7 centered,
'|' no-gap.

else.

write :

/'|' no-gap,(9) &2 centered,


'|' no-gap,(18) &3 ,
'|' no-gap,(40) &4 ,
'|' no-gap,(18) &5 ,
'|' no-gap,(5) &6 ,
'|' no-gap,(10) &7 ,
'|' no-gap.
endif.

END-OF-DEFINITION.

TYPES: BEGIN OF ty_header,


matkl LIKE mara-matkl, " Material Group
matnr LIKE mara-matnr, " Material Number
maktx LIKE makt-maktx, " Material Description
bismt LIKE mara-bismt, " Old material number
meins LIKE mara-meins, " Base Unit of Measure
mseht LIKE t006a-mseht, " Unit of Measurement Text
END OF ty_header.

DATA: gi_header TYPE STANDARD TABLE OF ty_header WITH HEADER LINE,


gi_makt LIKE STANDARD TABLE OF makt WITH HEADER LINE,
gi_t006a LIKE STANDARD TABLE OF t006a WITH HEADER LINE.

DATA: gv_width TYPE i. " Width of list

5. Create Input Screen / Selection

*----------------------------------------------------------------------*
*Input Screen/Selection
*----------------------------------------------------------------------*
SELECT-OPTIONS so_matkl FOR mara-matkl.
SELECT-OPTIONS so_matnr FOR mara-matnr.

6. Create Main Program

69
*======================================================================*
*MAIN PROGRAM
*Execute after Input Screen
*======================================================================*
START-OF-SELECTION.
gv_width = 113.
PERFORM fm_collect_data.
PERFORM fm_process_data.
PERFORM fm_display_data.

END-OF-SELECTION.

7. Create Sub Program with 3 sub routine (fm_collect_data, fm_process_data and


fm_display_data)

Flow process : Select Material Data -> Display

*======================================================================*
*SUB PROGRAM / SUB ROUTINE
*======================================================================*
FORM fm_collect_data.

ENDFORM.

FORM fm_process_data.

ENDFORM.

FORM fm_display_data.

ENDFORM.

8. Write code for sub routine fm_collect_data


FORM fm_collect_data.
* Collect Master Material
SELECT matnr matkl bismt meins
INTO CORRESPONDING FIELDS OF TABLE gi_header
FROM mara
WHERE
matkl IN so_matkl AND
matnr IN so_matnr.

* Collect Material Decription


SELECT matnr maktx
INTO CORRESPONDING FIELDS OF TABLE gi_makt
FROM makt
FOR ALL ENTRIES IN gi_header
WHERE
matnr = gi_header-matnr AND
spras = sy-langu.

* "For SAP 4.6C


* DATA : lv_total_data type i.
* DESCRIBE TABLE gi_header LINES lv_total_data.
* IF lv_total_data > 0.

IF LINES( gi_header ) > 0." For SAP 4.7 above


* Collect Material Decription
SELECT matnr maktx
INTO CORRESPONDING FIELDS OF TABLE gi_makt
FROM makt
FOR ALL ENTRIES IN gi_header
WHERE

70
matnr = gi_header-matnr AND
spras = sy-langu.

* Collect Measurement Text


SELECT msehi mseht
INTO CORRESPONDING FIELDS OF TABLE gi_t006a
FROM t006a
FOR ALL ENTRIES IN gi_header
WHERE
msehi = gi_header-meins AND
spras = sy-langu.
ENDIF.

* Notes :
* Avoid using inner join
ENDFORM.

9. Write code for sub routine fm_process_data

FORM fm_process_data.
*Get other requirement information
LOOP AT gi_header.
* Get Material Description
READ TABLE gi_makt WITH KEY matnr = gi_header-matnr.
IF sy-subrc = 0.
gi_header-maktx = gi_makt-maktx.
ENDIF.

* Get Measurement Text


READ TABLE gi_t006a WITH KEY msehi = gi_header-meins.
IF sy-subrc = 0.
gi_header-mseht = gi_t006a-mseht.
ENDIF.

MODIFY gi_header.
ENDLOOP.
ENDFORM.

10. Write code for sub routine fm_display_data (Functional Specification III-5)

FORM fm_display_data.
* Create Header Text
ULINE AT (gv_width). " Upper frame border
FORMAT COLOR COL_HEADING INTENSIFIED. " Title color
macro_data_possition : 'HEADER' 'Mat. Group' 'Mat. No.' 'Description'
'Old Mat. No.' 'Base Unit' 'Measure'.
WRITE: AT gv_width sy-vline. " Right border
ULINE AT (gv_width). " Line below titles
FORMAT COLOR OFF.

* Display Data to Screen


LOOP AT gi_header.
macro_data_possition : 'CONTENT'
gi_header-matkl
gi_header-matnr
gi_header-maktx
gi_header-bismt
gi_header-meins
gi_header-mseht.
ENDLOOP.

* End of Line
ULINE AT (gv_width). " Line below last data

ENDFORM.

71
11. Activated and run.
12. Create T-Code ”YP101”

1) Open T-Code SE93


2) Fill Transaction Code name, ex : ”YP101”

3) Then click ” ”
4) Fill Short Text

"Program and screen" for the ABAP program with Dialog Programming
techniques.
"Program and selection screen" for the ABAP program ABAP Technical
Report (Selection Screen).

5) Click ” ”
6) Fill program name and Screen number. If you have an authorization object
of your program, then fill it.

Notes : Screen Number default for standard ABAP Program/Report (non-


Dialog Programming) is "1000".

72
7) Click ” ” and exit.
8) Test Transaction Code.
9) Finished.

13. Finished.

b. Display Output

Objective Know how to create ABAP report using Display


Output

▪ Report (201) - Create Multiple Pages

▪ Report (202) - Create Printer Setup

Report (203) - Create Asset Report using Template from


▪ Report (202)

Report (201) - Create Multiple Pages

 Input Selection

73
 Output

Report (202) - Create Printer Setup

 Input Selection

 Output

Start Printing without Preview

74
Test Printing to PDF Writer

Functional Specification (201)

I. REQUEST
Module MM (Material Management) Date 22 April 2008
Request By - Initial Name
Request ABAP Report Characteristic Display Output
Type
Printer - Reference T- MM03
Code

75
II. OBJECT INFO
1 Package $TMP 4 T-Code YP201
2 Program Name YPRACTICE_201 5 Include
Program
3 Function Module 6

III.DETAIL DESCRIPTION
1 Background Display List of Master Material
2 Flow of Process Select Material Data -> Display
3 Table MARA, MAKT, T006A
4 Input Screen/Selection Selection Parameter

Material Group (MARA-MATKL)

Material Number (MARA-MATNR)

Page Setup

Max. Width

Max. Line per page


5 Output
Every new pages have header and footer.

eg : report have 3 pages, and Report must show like this bellow

Mat. Mat. No. Description Old Mat. Base Unit of Measure


Group No. Measure
(MARA-MATKL) (MARA-MATNR) (MAKT-MAKTX) (MARA-BISMT) (MARA-MEINS) (T006A-MSEHT)

Page : 1/3

Mat. Mat. No. Description Old Mat. Base Unit of Measure


Group No. Measure
(MARA-MATKL) (MARA-MATNR) (MAKT-MAKTX) (MARA-BISMT) (MARA-MEINS) (T006A-MSEHT)

Page : 2/3

76
Mat. Mat. No. Description Old Mat. Base Unit of Measure
Group No. Measure
(MARA-MATKL) (MARA-MATNR) (MAKT-MAKTX) (MARA-BISMT) (MARA-MEINS) (T006A-MSEHT)

Page : 3/3

Report (201)

Creating Report

1) Open SE38.
2) Copy Program ”YPRACTICE_101” to ”YPRACTICE_201”.
3) Open GoTo > Attributes, and change title with ”201 – Display List of
Material”.
4) Modified Report Declaration.

Before
REPORT ypractice_101.

After
REPORT ypractice_201
NO STANDARD PAGE HEADING.

5) Remove "DATA: gv_width TYPE i. " Width of list"


6) Modified ”Input Screen Selection”
Before
*---------------------------------------------------------------------
-*
*Input Screen/Selection
*---------------------------------------------------------------------
*
SELECT-OPTIONS so_matkl FOR mara-matkl.
SELECT-OPTIONS so_matnr FOR mara-matnr.

After
*---------------------------------------------------------------------
-*
*Input Screen/Selection
*---------------------------------------------------------------------
-*
SELECTION-SCREEN BEGIN OF BLOCK groupbox1 WITH FRAME TITLE text_101.
"Declare Group Box 1

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_102 FOR FIELD so_matkl.
SELECT-OPTIONS so_matkl FOR mara-matkl.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_103 FOR FIELD so_matnr.
SELECT-OPTIONS so_matnr FOR mara-matnr.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK


groupbox1. "End Group Box 1

77
SELECTION-SCREEN BEGIN OF BLOCK groupbox2 WITH FRAME TITLE text_201.
"Declare Group Box 2

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_202 FOR FIELD p_mwidth.
PARAMETERS p_mwidth TYPE n DEFAULT 113 LENGTH 4.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_203 FOR FIELD p_mline .
PARAMETERS p_mline TYPE n DEFAULT 30 LENGTH 4.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK


groupbox2. "End Group Box 2

7) Create event and initialization code, write it after input Screen Block.

*--------------------------------------------------------------------*
*EVENT
*--------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
text_101 = 'Selection Parameter'.
text_102 = 'Material Group'.
text_103 = 'Material Number'.

text_201 = 'Page Setup'.


text_202 = 'Max. Width'.
text_203 = 'Max. Line per Page'.

*--------------------------------------------------------------------*
*INITIALIZATION
*--------------------------------------------------------------------*
INITIALIZATION.

8) Modified “Main Program”

Before
*====================================================================*
*MAIN PROGRAM
*Execute after Input Screen
*====================================================================*
START-OF-SELECTION.
gv_width = 113.
PERFORM fm_collect_data.
PERFORM fm_process_data.
PERFORM fm_display_data.

END-OF-SELECTION.

After
*====================================================================*
*MAIN PROGRAM
*Execute after Input Screen
*====================================================================*
START-OF-SELECTION.
NEW-PAGE LINE-SIZE p_mwidth.
NEW-PAGE LINE-COUNT p_mline.

PERFORM fm_collect_data.
PERFORM fm_process_data.
PERFORM fm_display_data.

END-OF-SELECTION.

78
9) Modified sub routine “fm_display_data”

Before
*&-------------------------------------------------------------------*
*& Form fm_display_data
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
FORM fm_display_data.
* Create Header Text
ULINE AT (gv_width). " Upper frame border
FORMAT COLOR COL_HEADING INTENSIFIED. " Title color
macro_data_possition : 'HEADER' 'Mat. Group' 'Mat. No.'
'Description' 'Old Mat. No.' 'Base Unit' 'Measure'.
WRITE: AT gv_width sy-vline. " Right border
ULINE AT (gv_width). " Line below titles
FORMAT COLOR OFF.

* Display Data to Screen


LOOP AT gi_header.
macro_data_possition : 'CONTENT'
gi_header-matkl
gi_header-matnr
gi_header-maktx
gi_header-bismt
gi_header-meins
gi_header-mseht.
ENDLOOP.

* End of Line
ULINE AT (gv_width). " Line below last data

ENDFORM. "fm_display_data

After
*&-------------------------------------------------------------------*
*& Form fm_display_data
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
FORM fm_display_data.
DATA: lv_total_data TYPE i,
lv_header_line TYPE i,
lv_footer_line TYPE i,
lv_max_content TYPE i,
lv_max_data TYPE i,
lv_page_count TYPE i. " LENGTH 4.

* Calculate Page Count


lv_total_data = LINES( gi_header ).
* DESCRIBE TABLE gi_header LINES lv_total_data. " For SAP 4.6C

lv_header_line = 3. "Change the value if you add a new header line


lv_footer_line = 3.
lv_max_content = p_mline - lv_header_line - lv_footer_line.
lv_max_data = p_mline - lv_footer_line.
lv_page_count = ( lv_total_data DIV lv_max_content ) + 1.

lv_max_content = lv_max_content + ( lv_header_line - 2 ).

* Display Data to Screen


LOOP AT gi_header.
macro_data_possition : 'CONTENT'
gi_header-matkl
gi_header-matnr

79
gi_header-maktx
gi_header-bismt
gi_header-meins
gi_header-mseht.
IF sy-linno = lv_max_data.
PERFORM fm_footer USING lv_page_count.

NEW-PAGE.
ENDIF.
ENDLOOP.

* Create Last Footer


IF ( sy-linno < lv_max_content ) or ( sy-linno > lv_footer_line ).
PERFORM fm_footer USING lv_page_count.
ENDIF.

ENDFORM. "fm_display_data

10) Create new sub routine “fm_footer”

*&-------------------------------------------------------------------*
*& Form fm_footer
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
* -->FV_PAGE_COUtext
*--------------------------------------------------------------------*
FORM fm_footer USING fv_page_count.
* Create Footer Text ( 3 Lines )
ULINE AT (p_mwidth). " Upper frame border
FORMAT COLOR COL_TOTAL INTENSIFIED. " Footer color
WRITE : /'|' NO-GAP, 'Page : ' NO-GAP, (4) sy-pagno NO-GAP, '/',(4)
fv_page_count NO-GAP.

WRITE: AT p_mwidth sy-vline. " Right border


ULINE AT (p_mwidth). " Line below titles
FORMAT COLOR OFF.
ENDFORM. "fm_footer

11) Create 1 Standard Event, which is “TOP - OF - PAGE”

*====================================================================*
*STANDARD EVENT
*====================================================================*

*--------------------------------------------------------------------*
*Page Header
*--------------------------------------------------------------------*

TOP-OF-PAGE.
* Create Header Text ( 3 Lines )
ULINE AT (p_mwidth). " Upper frame border
FORMAT COLOR COL_HEADING INTENSIFIED. " Title color
macro_data_possition : 'HEADER' 'Mat. Group' 'Mat. No.'
'Description' 'Old Mat. No.' 'Base Unit' 'Measure'.
ULINE AT (p_mwidth). " Line below titles
FORMAT COLOR OFF.

12) Activated and Run


13) Create t-code ”YP201”
14) Finished

80
Report (202)

Creating Report
1) Open SE38
2) Copy Program ”YPRACTICE_201” to ”YPRACTICE_202”
3) Open GoTo > Attributes and change title with ”202 – Display and Print List
of Master Material”
4) Modified Report Declaration

Before
REPORT ypractice_201
NO STANDARD PAGE HEADING.

After
REPORT ypractice_202
NO STANDARD PAGE HEADING
.
5) Add 2 Global Variable
DATA: gw_pri_params TYPE pri_params,
gv_valid TYPE c.

6) Modified ”Input Screen / Selection”

Before
*--------------------------------------------------------------------*
*Input Screen/Selection
*--------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK groupbox1 WITH FRAME TITLE text_101.
"Declare Group Box 1

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_102 FOR FIELD so_matkl.
SELECT-OPTIONS so_matkl FOR mara-matkl.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_103 FOR FIELD so_matnr.
SELECT-OPTIONS so_matnr FOR mara-matnr.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK


groupbox1. "End Group Box 1

SELECTION-SCREEN BEGIN OF BLOCK groupbox2 WITH FRAME TITLE text_201.


"Declare Group Box 2

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_202 FOR FIELD p_mwidth.
PARAMETERS p_mwidth TYPE n DEFAULT 113 LENGTH 4.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_203 FOR FIELD p_mline .
PARAMETERS p_mline TYPE n DEFAULT 30 LENGTH 4.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK


groupbox2. "End Group Box 2

81
After
*--------------------------------------------------------------------*
*Input Screen/Selection
*--------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK groupbox1 WITH FRAME TITLE text_101.
"Declare Group Box 1

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_102 FOR FIELD so_matkl.
SELECT-OPTIONS so_matkl FOR mara-matkl.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_103 FOR FIELD so_matnr.
SELECT-OPTIONS so_matnr FOR mara-matnr.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK groupbox1. "End Group Box 1

SELECTION-SCREEN BEGIN OF BLOCK groupbox2 WITH FRAME TITLE text_201.


"Declare Group Box 2

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_202 FOR FIELD p_mwidth.
PARAMETERS p_mwidth TYPE n DEFAULT 113 LENGTH 4.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_203 FOR FIELD p_mline .
PARAMETERS p_mline TYPE n DEFAULT 30 LENGTH 4.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK groupbox2 "End Group Box 2

SELECTION-SCREEN BEGIN OF BLOCK groupbox3 WITH FRAME TITLE


text_301. "Declare Group Box 3 - Print Parameter

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_311.
PARAMETERS: p_pdest LIKE pri_params-pdest DEFAULT 'LOCL'.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_312.
PARAMETERS p_paart LIKE pri_params-paart DEFAULT 'X_44_120'.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_313.
PARAMETERS p_dialog TYPE c AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN COMMENT 23(25) text_314 FOR FIELD p_dialog.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN ULINE.

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_321.

PARAMETERS p_prv RADIOBUTTON GROUP rad1 VISIBLE LENGTH 20.


SELECTION-SCREEN COMMENT 23(8) text_322 FOR FIELD p_prv.

PARAMETERS p_prt RADIOBUTTON GROUP rad1 DEFAULT 'X'.


SELECTION-SCREEN COMMENT 34(8) text_323 FOR FIELD p_prt.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK groupbox3. "End Group Box 3

82
7) Add new text in ”Event”

text_301 = 'Print Setup'.


text_311 = 'Output Device'.
text_312 = 'Printer Layout'.
text_313 = ' '.
text_314 = 'Show Printer Dialog'.

text_321 = 'Print Option'.


text_322 = 'Preview'.
text_323 = 'Print'.

8) Modified ”Main Program”

Before
*=====================================================================
=*
*MAIN PROGRAM
*Execute after Input Screen
*=====================================================================
=*
START-OF-SELECTION.
NEW-PAGE LINE-SIZE p_mwidth.
NEW-PAGE LINE-COUNT p_mline.

PERFORM fm_collect_data.
PERFORM fm_process_data.
PERFORM fm_display_data.

END-OF-SELECTION.

After
*=====================================================================
=*
*MAIN PROGRAM
*Execute after Input Screen
*=====================================================================
=*
START-OF-SELECTION.
FORMAT RESET.

NEW-PAGE LINE-SIZE p_mwidth.


NEW-PAGE LINE-COUNT p_mline.

PERFORM fm_collect_data.
PERFORM fm_process_data.

IF LINES( gi_header ) > 0.


IF p_prt = 'X'.
PERFORM fm_print_setup.
ENDIF.
PERFORM fm_display_data.
ELSE.
PERFORM fm_showmessage.
ENDIF.

END-OF-SELECTION.

9) Create new 2 sub routine, “fm_print_setup” and “fm_showmessage”

*&-------------------------------------------------------------------*
*& Form fm_print_setup
*&-------------------------------------------------------------------*
* text

83
*--------------------------------------------------------------------*
FORM fm_print_setup.
DATA: lv_dialog TYPE c.

IF p_prt = 'X'.
IF p_dialog = 'X'.
lv_dialog = ' '.
ELSE.
lv_dialog = 'X'.
ENDIF.

CALL FUNCTION 'GET_PRINT_PARAMETERS'


EXPORTING
destination = p_pdest
immediately = 'X'
draft = ' '
no_dialog = lv_dialog
release = 'X'
layout = p_paart
IMPORTING
out_parameters = gw_pri_params
valid = gv_valid
EXCEPTIONS
archive_info_not_found = 1
invalid_print_params = 2
invalid_archive_params = 3
OTHERS = 4.

* Dot Matrix Setting


* PRINT-CONTROL CPI 17. "CPI cpiLetters per inch
* PRINT-CONTROL LPI 6. "LPI lpiLines per inch
*__________________________________________________

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

CHECK gv_valid = 'X'.

NEW-PAGE PRINT ON PARAMETERS gw_pri_params NO DIALOG.

ENDIF.
ENDFORM. "fm_print_setup

*&-------------------------------------------------------------------*
*& Form fm_showmessage
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
FORM fm_showmessage.
MESSAGE 'File not found.' TYPE 'I'.
ENDFORM. "fm_showmessage

10) Activated and Run


11) Create T-Code ”YP202”
12) Finished

84
c. HTML

Report (301) - Create Simple Html Report

 Input Selection

 Output

Functional Specification

I. REQUEST
Module MM (Material Management) Date 23 April 2008

85
Request By - Initial Name
Request ABAP Report Characteristic Html - Web Page
Type
Printer - Reference T-Code MM03

II. OBJECT INFO


1 Package $TMP 4 T-Code YP301
2 Program Name YPRACTICE_301 5 Include
Program
3 Function 6
Module

III.DETAIL DESCRIPTION
1 Background Display List of Master Material
2 Flow of Process Select Material Data -> Display
3 Table MARA, MAKT, T006A
4 Input Screen/Selection Selection Parameter

Material Group (MARA-MATKL)

Material Number (MARA-MATNR)

Select Html File

File Location
5 Output
Mat. Mat. No. Description Old Mat. Base Unit of Measure
Group No. Measure
(MARA-MATKL) (MARA-MATNR) (MAKT-MAKTX) (MARA-BISMT) (MARA-MEINS) (T006A-MSEHT)

Report 301

Creating Report

1) Open SE38

86
2) Copy Program ”YPRACTICE_101” to ”YPRACTICE_301”
3) Change Program ”YPRACTICE_301”
4) Open GoTo > Attributes, and change title with ”301 – Display List of
Material”
5) Modified Report Declaration

Before
REPORT ypractice_101.

After
REPORT ypractice_301.

6) Add New Screen for displaying HTML Report.


 Click ” ” to show all object
 Right click on Object Tree

 Enter screen number ”2000” and then press ” ”

 Fill short description ”HTML Report”


 Click ” ” to start design layout.
 Click ” ” to add ”Custom Control” component to screen and fill the
Custom Control name with ”CC_REPORT_DISPLAY”.
 Select ”CC_REPORT_DISPLAY”, after that click ” ” (Atribut
Window).
 Set the component like this screen below

87
 Click ”” to save design layout.
 Close design layout and back to previous screen.
 Click ”Element List” tab.
 Fill on the blank cell with ”OK_CODE”

 Double click ” ” and back to source code.


7) Remove DEFINE macro_data_position.
8) Add new global variable.

DATA: ok_code LIKE sy-ucomm,


save_ok TYPE sy-ucomm.

* Html Report Required


TYPES: BEGIN OF gy_html_code,
line_code(1000),
END OF gy_html_code.
DATA: gi_html_code TYPE TABLE OF gy_html_code WITH HEADER LINE.

DATA: cc_report_display TYPE REF TO cl_gui_html_viewer,


web_container TYPE REF TO cl_gui_custom_container.

DEFINE write_code1.
clear gi_html_code.
gi_html_code-line_code = &1.
append gi_html_code.
END-OF-DEFINITION.

DEFINE write_code2.
clear gi_html_code.
concatenate &1 &2 into gi_html_code-line_code.
append gi_html_code.
END-OF-DEFINITION.

DEFINE write_code3.
clear gi_html_code.
concatenate &1 &2 &3 into gi_html_code-line_code.
append gi_html_code.
END-OF-DEFINITION.

9) Modified ”Input Screen / Selection”

88
Before
*--------------------------------------------------------------------*
*Input Screen/Selection
*--------------------------------------------------------------------*
SELECT-OPTIONS so_matkl FOR mara-matkl.
SELECT-OPTIONS so_matnr FOR mara-matnr.

After
*--------------------------------------------------------------------*
*Input Screen/Selection
*--------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK groupbox1 WITH FRAME TITLE text_101.
"Declare Group Box 1

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(14) text_102 FOR FIELD so_matkl.
SELECT-OPTIONS so_matkl FOR mara-matkl OBLIGATORY DEFAULT '001'.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(14) text_103 FOR FIELD so_matnr.
SELECT-OPTIONS so_matnr FOR mara-matnr.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK


groupbox1. "End Group Box 1

SELECTION-SCREEN BEGIN OF BLOCK groupbox2 WITH FRAME TITLE text_201.


"Declare Group Box 2

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_202 FOR FIELD p_fname.
PARAMETERS p_fname LIKE rlgrap-filename OBLIGATORY DEFAULT
'C:\abap_report_01.html'.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK


groupbox2. "End Group Box 2

10) Create new sub routine ”fm_initialization”

*&-------------------------------------------------------------------*
*& Form fm_initialization
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
FORM fm_initialization.
IF cc_report_display IS INITIAL.

CREATE OBJECT web_container


EXPORTING
container_name = 'CC_REPORT_DISPLAY'.

CREATE OBJECT cc_report_display


EXPORTING
parent = web_container.
IF sy-subrc NE 0.
*
ENDIF.
ENDIF.
ENDFORM. "fm_initialization

11) Create initialization code, write it after Input Screen Block.

89
*--------------------------------------------------------------------*
*INITIALIZATION
*--------------------------------------------------------------------*
INITIALIZATION.
text_101 = 'Selection Parameter'.
text_102 = 'Material Group'.
text_103 = 'Material Number'.

text_201 = 'Save Html File'.


text_202 = 'File Location'.

PERFORM fm_initialization.

12) Create new sub routine ”fm_create_css”.

*&-------------------------------------------------------------------*
*& Form fm_create_css
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
* -->FV_CSS text
*--------------------------------------------------------------------*
FORM fm_create_css.
write_code1 '<style type="text/css">'.
write_code1 '<!--'.
write_code1 '.styleHeader {'.
write_code1 ' font-family: Arial, Helvetica, sans-serif;'.
write_code1 ' font-size: 12px;'.
write_code1 ' font-weight: bold;'.
write_code1 ' text-align: center;'.
write_code1 ' }'.
write_code1 '.style1 {'.
write_code1 ' font-family: Arial, Helvetica, sans-serif;'.
write_code1 ' font-size: 12px;'.
write_code1 ' text-align: center;'.
write_code1
' }'.

write_code1 '.style2 {'.


write_code1 ' font-family: Arial, Helvetica, sans-serif;'.
write_code1 ' font-size: 12px;'.
write_code1 ' text-align: left;'.
write_code1
' }'.

write_code1 '-->'.
write_code1 '</style>'.

ENDFORM. "fm_create_css

13) Create new sub routine ”fm_create_html_file”

*&-------------------------------------------------------------------*
*& Form fm_create_temp_html
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
* -->FI_FILE text
* -->FV_URL text
*--------------------------------------------------------------------*
FORM fm_create_html_file TABLES fi_file STRUCTURE gi_html_code USING
fv_url.
CONDENSE fv_url NO-GAPS.

CALL FUNCTION 'WS_DOWNLOAD'

90
EXPORTING
filename = fv_url
filetype = 'ASC'
TABLES
data_tab = fi_file
EXCEPTIONS
file_open_error = 1
file_write_error = 2
invalid_filesize = 3
invalid_table_width = 4
invalid_type = 5
no_batch = 6
unknown_error = 7
OTHERS = 8.

ENDFORM. "fm_create_temp_html

14) Create new sub routine ”fm_load_html”

*&-------------------------------------------------------------------*
*& Form fm_load_html
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
* -->URL text
*--------------------------------------------------------------------*
FORM fm_load_html USING fv_url.
CALL METHOD cc_report_display->show_url
EXPORTING
url = fv_url.
ENDFORM. "fm_load_html

15) Modified sub routine ”fm_display_data”

Before
*&-------------------------------------------------------------------*
*& Form fm_display_data
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
FORM fm_display_data.
* Create Header Text
ULINE AT (gv_width). " Upper frame border
FORMAT COLOR COL_HEADING INTENSIFIED. " Title color
macro_data_possition : 'HEADER' 'Mat. Group' 'Mat. No.'
'Description' 'Old Mat. No.' 'Base Unit' 'Measure'.
WRITE: AT gv_width sy-vline. " Right border
ULINE AT (gv_width). " Line below titles
FORMAT COLOR OFF.

* Display Data to Screen


LOOP AT gi_header.
macro_data_possition : 'CONTENT'
gi_header-matkl
gi_header-matnr
gi_header-maktx
gi_header-bismt
gi_header-meins
gi_header-mseht.
ENDLOOP.

* End of Line
ULINE AT (gv_width). " Line below last data

ENDFORM. "fm_display_data

91
After
*&-------------------------------------------------------------------*
*& Form fm_display_data
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
FORM fm_display_data.

REFRESH gi_html_code.

PERFORM fm_create_css.
write_code1 '<body>'.
write_code1 '<table width="100%" border="0" cellspacing="2"
cellpadding="0">'.

* Create Header Text


write_code1 ' <tr bgcolor="#999999" class="styleHeader">'.
write_code1 ' <td>Mat. Group</td>'.
write_code1 ' <td>Mat. No.</td>'.
write_code1 ' <td>Description</td>'.
write_code1 ' <td>Old Mat. No.</td>'.
write_code1 ' <td>Base Unit of Measure</td>'.
write_code1 ' <td>Measure</td>'.
write_code1 ' </tr>'.

* Display Data to Screen


LOOP AT gi_header.
write_code1 ' <tr bgcolor="#EBEBEB">'.
write_code3 ' <td class="style1">' gi_header-matkl '</td>'.
write_code3 ' <td class="style1">' gi_header-matnr '</td>'.
write_code3 ' <td class="style2">' gi_header-maktx '</td>'.
write_code3 ' <td class="style2">' gi_header-bismt '</td>'.
write_code3 ' <td class="style1">' gi_header-meins '</td>'.
write_code3 ' <td class="style2">' gi_header-mseht '</td>'.
write_code1 ' </tr>'.

ENDLOOP.

* End of Line
write_code1 '</table>'.
write_code1 '</body>'.

PERFORM fm_create_html_file TABLES gi_html_code USING p_fname.


PERFORM fm_load_html USING p_fname.

CALL SCREEN 2000.

ENDFORM. "fm_display_data

16) Add new GUI status for Screen 2000

 Right click on Object Tree

92
 Fill Status with ”ST_2000” and Short Text with ”GUI Status for
Screen 2000”

 Click ” ”
 Open Function Key
 Choose Standard Toolbar and enter BACK on icon mumber 3 on the
left

 Click ” ” to save GUI Status


 Double click ” ” and back to source code

17) Double click Screen 2000 on Object Tree

93
18) Modified Screen 2000 Flow Logic

Before
PROCESS BEFORE OUTPUT.
* MODULE STATUS_2000.
*
PROCESS AFTER INPUT.
* MODULE USER_COMMAND_2000.

After
PROCESS BEFORE OUTPUT.
MODULE STATUS_2000.
*
PROCESS AFTER INPUT.
MODULE USER_COMMAND_2000.

19) Click ” ” to save Screen 2000


20) Double click on text ”STATUS_2000”
21) Select ”YPRACTICE_301” and click ” ” to create new modul
STATUS_2000

22) Modified modul ”STATUS_2000 output”

Before
*&-------------------------------------------------------------------*
*& Module STATUS_2000 OUTPUT
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
module STATUS_2000 output.
* SET PF-STATUS 'xxxxxxxx'.
* SET TITLEBAR 'xxx'.

endmodule. " STATUS_2000 OUTPUT

After
*&-------------------------------------------------------------------*
*& Module STATUS_2000 OUTPUT

94
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
module STATUS_2000 output.
SET PF-STATUS 'ST_2000'.
* SET TITLEBAR 'xxx'.

endmodule. " STATUS_2000 OUTPUT**********

23) Back to Screen 2000 Flow Logic


24) Double click on text ”USER_COMMAND_2000”
25) Select ”YPRACTICE_301” and click ”” to create new modul
USER_COMMAND_2000

26) Modified modul ”USER_COMMAND_2000 input”

Before
*&-------------------------------------------------------------------*
*& Module USER_COMMAND_2000 INPUT
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
module USER_COMMAND_2000 input.

endmodule. " USER_COMMAND_2000 INPUT

After
*&-------------------------------------------------------------------*
*& Module USER_COMMAND_2000 INPUT
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
MODULE user_command_2000 INPUT.
save_ok = ok_code.
CLEAR ok_code.

CASE save_ok.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN OTHERS.

ENDCASE.

CLEAR ok_code.
ENDMODULE. " USER_COMMAND_2000 INPUT

27) Click ” ” and Click ” ”


28) Select ”REPS”, ”CUAD” and ”DYNP”

95
29) Click ”” to active the program
30) Test and run program
31) Create T-Code ”YP301”
32) Finished

Report (302) - Create Menu Paging

 Input Selection

96
 Output

Functional Specification

I. REQUEST
Module MM (Material Management) Date 23 April 2008
Request By - Initial Name
Request ABAP Report Characteristic Html - Web Page
Type
Printer - Reference T-Code MM03

II. OBJECT INFO


1 Package $TMP 4 T-Code YP301
2 Program Name YPRACTICE_301 5 Include
Program
3 Function Module 6

97
III.DETAIL DESCRIPTION
1 Background Display List of Master Material
2 Flow of Process Select Material Data -> Display
3 Table MARA, MAKT, T006A
4 Input Screen/Selection Selection Parameter

Material Group (MARA-MATKL)

Material Number (MARA-MATNR)

Select Html File

File Location

Max. Line per page


5 Output
User can select and jump to selected page.

Mat. Mat. No. Description Old Mat. Base Unit of Measure


Group No. Measure
(MARA-MATKL) (MARA-MATNR) (MAKT-MAKTX) (MARA-BISMT) (MARA-MEINS) (T006A-MSEHT)

Report (302)

Creating Report
1) Open SE38
2) Copy Program ”YPRACTICE_301” to ”YPRACTICE_302”
3) Select all object

98
4) Change program ”YPRACTICE_302”
5) Open GoTo > Attributes and change Title with ”302 – Display List of
Material”
6) Modified Report Declaration

Before
REPORT ypractice_301.

After
REPORT ypractice_302.

7) Click ” ”
8) Add New Include Program

9) Fill Include name with ”YPRACTICE_302_CLASSES” and then click ” ”

99
10) Click ” ” to create new include

11) Save into same package with ”YPRACTICE_302” and then click ” ” to
insert the include into main program.
12) Create global variable at ”YPRACTICE_302_CLASSES”

*--------------------------------------------------------------------*
*GLOBAL VARIABLE DECRALATION
*--------------------------------------------------------------------*
DATA : gv_html_event_tab TYPE cntl_simple_events,
gv_html_event TYPE cntl_simple_event,
gv_repid LIKE sy-repid,
gv_frame(255),
gv_action(256),
gv_getdata(2048),
gv_postdataline(1024),
gi_postdata_tab TYPE cnht_post_data_tab,
gi_query_table TYPE TABLE OF w3query WITH HEADER LINE.

13) Create class definition at ”YPRACTICE_302_CLASSES”

*--------------------------------------------------------------------*
* CLASS cl_html_event_handler DEFINITION
*--------------------------------------------------------------------*
*
*--------------------------------------------------------------------*
CLASS cl_html_event_handler DEFINITION.

PUBLIC SECTION.
* Activate event
METHODS: on_sapevent
FOR EVENT sapevent OF cl_gui_html_viewer
IMPORTING action frame getdata postdata query_table.

ENDCLASS. "cl_html_event_handler DEFINITION

Data: gv_evt_receiver TYPE REF TO cl_html_event_handler.

100
14) Create class implementation ”YPRACTICE_302_CLASSES”

*--------------------------------------------------------------------*
* CLASS cl_html_event_handler IMPLEMENTATION
*--------------------------------------------------------------------*
*
*--------------------------------------------------------------------*
CLASS cl_html_event_handler IMPLEMENTATION.

* Event Procedure
METHOD on_sapevent.

CLEAR gv_action.
CLEAR gv_frame.
CLEAR gv_getdata.
CLEAR gv_postdataline.

gv_action = action.
gv_frame = frame.
gv_getdata = getdata.
gi_postdata_tab = postdata.
IF NOT gi_postdata_tab IS INITIAL.
READ TABLE gi_postdata_tab INDEX 1 INTO gv_postdataline.
ENDIF.
gi_query_table[] = query_table[].

CASE action.
* Action "OPEN_PAGE" when press a button in the html page
WHEN 'SUBMIT_PAGE_NO'.
PERFORM fm_display_data.

WHEN OTHERS.
ENDCASE.
ENDMETHOD. "on_sapevent

ENDCLASS. "cl_html_event_handler IMPLEMENTATION

15) Move include ”” to above ”Input Screen / Selection”

...
concatenate &1 &2 &3 into gi_html_code-line_code.
append gi_html_code.
END-OF-DEFINITION.

*--------------------------------------------------------------------*
*INCLUDE PROGRAM
*--------------------------------------------------------------------*
*You can put the include program at the bottom of code

INCLUDE ypractice_302_classes.

*--------------------------------------------------------------------*
*Input Screen/Selection
*--------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK groupbox1 WITH FRAME TITLE text_101.
"Declare Group Box 1
...

101
16) Modified ”Input Screen / Selection” and add new parameters

Before
...
SELECTION-SCREEN BEGIN OF BLOCK groupbox2 WITH FRAME TITLE text_201.
"Declare Group Box 2

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_202 FOR FIELD p_fname.
PARAMETERS p_fname LIKE rlgrap-filename OBLIGATORY DEFAULT
'C:\abap_report_01.html'.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK groupbox2.


...

After
...
SELECTION-SCREEN BEGIN OF BLOCK groupbox2 WITH FRAME TITLE text_201.
"Declare Group Box 2

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_202 FOR FIELD p_fname.
PARAMETERS p_fname LIKE rlgrap-filename OBLIGATORY DEFAULT
'C:\abap_report_01.html'.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_203 FOR FIELD p_mline .
PARAMETERS p_mline TYPE n DEFAULT 20 LENGTH 4.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK


groupbox2. "End Group Box 2
...

17) Add new text ”INITIALIZATION”

text_203 = 'Max. Line per Page'.

18) Create new sub routine ”fm_create_pagging_menu”


*&-------------------------------------------------------------------*
*& Form fm_create_paging_menu
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
* -->FV_TOTAL_PAtext
* -->FV_ACTIVE_PtextNO
*--------------------------------------------------------------------*
FORM fm_create_paging_menu USING fv_total_page fv_active_page_no.
DATA : lv_counter TYPE n LENGTH 4,
lv_item(256).
lv_counter = 0.

write_code1 ' <form name="form1" method="post"


action="SAPEVENT:SUBMIT_PAGE_NO">'.
write_code1 ' <tr colspan="6" class="style2">'.
write_code1 ' <td>Page : '.
write_code1 ' <select name="PAGE_NO" id="PAGE_NO">'.

WHILE fv_total_page > lv_counter.


lv_counter = lv_counter + 1.

102
IF lv_counter = fv_active_page_no.
CONCATENATE '<option value="' lv_counter '" selected>'
lv_counter '</option>' INTO lv_item.
ELSE.
CONCATENATE '<option value="' lv_counter '" >' lv_counter
'</option>' INTO lv_item.
ENDIF.
write_code1 lv_item.

ENDWHILE.

write_code3 ' </select> / ' fv_total_page ' '.


write_code1 ' <input name="Open_Submit" type="submit"
id="Open_Submit" value="Open"></td>'.
write_code1 ' </tr>'.
write_code1 ' </form>'.

ENDFORM. "fm_create_paging_menu

19) Modified subroutine ”fm_display_data”

Before
*&--------------------------------------------------------------------
*
*& Form fm_display_data
*&--------------------------------------------------------------------
*
* text
*---------------------------------------------------------------------
*
FORM fm_display_data.
REFRESH gi_html_code.

PERFORM fm_create_css.
write_code1 '<body>'.
write_code1 '<table width="100%" border="0" cellspacing="2"
cellpadding="0">'.

* Create Header Text


write_code1 ' <tr bgcolor="#999999" class="styleHeader">'.
write_code1 ' <td>Mat. Group</td>'.
write_code1 ' <td>Mat. No.</td>'.
write_code1 ' <td>Description</td>'.
write_code1 ' <td>Old Mat. No.</td>'.
write_code1 ' <td>Base Unit of Measure</td>'.
write_code1 ' <td>Measure</td>'.
write_code1 ' </tr>'.

* Display Data to Screen


LOOP AT gi_header.
write_code1 ' <tr bgcolor="#EBEBEB">'.
write_code3 ' <td class="style1">' gi_header-matkl '</td>'.
write_code3 ' <td class="style1">' gi_header-matnr '</td>'.
write_code3 ' <td class="style2">' gi_header-maktx '</td>'.
write_code3 ' <td class="style2">' gi_header-bismt '</td>'.
write_code3 ' <td class="style1">' gi_header-meins '</td>'.
write_code3 ' <td class="style2">' gi_header-mseht '</td>'.
write_code1 ' </tr>'.

ENDLOOP.

* End of Line
write_code1 '</table>'.

103
write_code1 '</body>'.

PERFORM fm_create_html_file TABLES gi_html_code USING p_fname.


PERFORM fm_load_html USING p_fname.

CALL SCREEN 2000.

ENDFORM. "fm_display_data

After
*&--------------------------------------------------------------------
*
*& Form fm_display_data
*&--------------------------------------------------------------------
*
* text
*---------------------------------------------------------------------
*
FORM fm_display_data.
DATA : lv_active_page_no TYPE n LENGTH 4,
lv_limit_top TYPE i,
lv_limit_bottom TYPE i,
lv_total_page LIKE lv_active_page_no,
lv_remainder LIKE lv_active_page_no.

* Calculate Total Page


lv_total_page = ( LINES( gi_header ) DIV p_mline ).
lv_remainder = LINES( gi_header ) MOD p_mline.

IF lv_remainder > 0.
lv_total_page = lv_total_page+1.
ENDIF.

* Calculate Page Limit


IF LINES( gi_query_table ) > 0 AND gv_action = 'SUBMIT_PAGE_NO'.
READ TABLE gi_query_table WITH KEY name = 'PAGE_NO'.
IF sy-subrc = 0.
lv_active_page_no = gi_query_table-value.

lv_limit_top = lv_active_page_no * p_mline.


ENDIF.
ELSE.
lv_active_page_no = 1.
lv_limit_top = 1.
ENDIF.

lv_limit_bottom = lv_limit_top + p_mline.

REFRESH gi_html_code.
PERFORM fm_create_css.

write_code1 '<body>'.

write_code1 '<table width="100%" border="0" cellspacing="2"


cellpadding="0">'.
PERFORM fm_create_paging_menu USING lv_total_page lv_active_page_no.

* Create Header Text


write_code1 ' <tr bgcolor="#999999" class="styleHeader">'.
write_code1 ' <td>Mat. Group</td>'.
write_code1 ' <td>Mat. No.</td>'.
write_code1 ' <td>Description</td>'.
write_code1 ' <td>Old Mat. No.</td>'.

104
write_code1 ' <td>Base Unit of Measure</td>'.
write_code1 ' <td>Measure</td>'.
write_code1 ' </tr>'.

* Display Data to Screen


LOOP AT gi_header FROM lv_limit_top TO lv_limit_bottom.
write_code1 ' <tr bgcolor="#EBEBEB">'.
write_code3 ' <td class="style1">' gi_header-matkl '</td>'.
write_code3 ' <td class="style1">' gi_header-matnr '</td>'.
write_code3 ' <td class="style2">' gi_header-maktx '</td>'.
write_code3 ' <td class="style2">' gi_header-bismt '</td>'.
write_code3 ' <td class="style1">' gi_header-meins '</td>'.
write_code3 ' <td class="style2">' gi_header-mseht '</td>'.
write_code1 ' </tr>'.

ENDLOOP.

* End of Line
write_code1 ' <td bgcolor="#999999" class="styleHeader"
colspan="6">&nbsp;</td>'.
PERFORM fm_create_paging_menu USING lv_total_page lv_active_page_no.
write_code1 '</table>'.
write_code1 '</body>'.

PERFORM fm_create_html_file TABLES gi_html_code USING p_fname.


PERFORM fm_load_html USING p_fname.

CALL SCREEN 2000.

ENDFORM. "fm_display_data

20) Modified subroutine ”fm_load_html”

Before
*&--------------------------------------------------------------------
*
*& Form fm_load_html
*&--------------------------------------------------------------------
*
* text
*---------------------------------------------------------------------
*
* -->URL text
*---------------------------------------------------------------------
*
FORM fm_load_html USING fv_url.
CALL METHOD cc_report_display->show_url
EXPORTING
url = fv_url.
ENDFORM. "fm_load_html

After
*&--------------------------------------------------------------------
*
*& Form fm_load_html
*&--------------------------------------------------------------------
*
* text
*---------------------------------------------------------------------
*
* -->URL text
*---------------------------------------------------------------------
*
FORM fm_load_html USING fv_url.

105
TRY.
CALL METHOD cc_report_display->show_url
EXPORTING
url = fv_url.
CATCH cx_sy_ref_is_initial.
LEAVE TO SCREEN 0.
ENDTRY.
ENDFORM. "fm_load_html

21) Modified module ”STATUS_2000_output”

Before
*&--------------------------------------------------------------------
-*
*& Module STATUS_2000 OUTPUT
*&--------------------------------------------------------------------
-*
* text
*---------------------------------------------------------------------
-*
MODULE status_2000 OUTPUT.
SET PF-STATUS 'ST_2000'.
* SET TITLEBAR 'xxx'.

ENDMODULE. " STATUS_2000 OUTPUT

After
*&--------------------------------------------------------------------
-*
*& Module STATUS_2000 OUTPUT
*&--------------------------------------------------------------------
-*
* text
*---------------------------------------------------------------------
-*
MODULE status_2000 OUTPUT.
SET PF-STATUS 'ST_2000'.
* SET TITLEBAR 'xxx'.

* register event
IF NOT cc_report_display IS INITIAL.
gv_html_event-eventid = cc_report_display->m_id_sapevent.
gv_html_event-appl_event = 'x'.
APPEND gv_html_event TO gv_html_event_tab.

CALL METHOD cc_report_display->set_registered_events


EXPORTING
events = gv_html_event_tab.

CREATE OBJECT gv_evt_receiver.

SET HANDLER gv_evt_receiver->on_sapevent


FOR cc_report_display.
ELSE.
LEAVE TO SCREEN 0.
ENDIF.
ENDMODULE. " STATUS_2000 OUTPUT

22) Modified module ”USER_COMMAND_2000”

Before

106
*&--------------------------------------------------------------------
-*
*& Module USER_COMMAND_2000 INPUT
*&--------------------------------------------------------------------
-*
* text
*---------------------------------------------------------------------
-*
MODULE user_command_2000 INPUT.
save_ok = ok_code.
CLEAR ok_code.

CASE save_ok.
WHEN 'BACK'.
LEAVE TO SCREEN 0.
WHEN OTHERS.

ENDCASE.

CLEAR ok_code.
ENDMODULE. " USER_COMMAND_2000 INPUT

After
*&--------------------------------------------------------------------
-*
*& Module USER_COMMAND_2000 INPUT
*&--------------------------------------------------------------------
-*
* text
*---------------------------------------------------------------------
-*
MODULE user_command_2000 INPUT.
save_ok = ok_code.
CLEAR ok_code.

CASE save_ok.
WHEN 'BACK'.
REFRESH gi_query_table.
IF NOT cc_report_display IS INITIAL.
CALL METHOD cc_report_display->free.
FREE cc_report_display.
ENDIF.
LEAVE TO SCREEN 0.
WHEN OTHERS.
CALL METHOD cl_gui_cfw=>dispatch.

ENDCASE.

CLEAR ok_code.
ENDMODULE. " USER_COMMAND_2000 INPUT

23) Save and activate program


24) Select 4 object like this below

25) Click ” ” to activate all object


26) Test and Run program

107
27) Create T-Code ”YP302”
28) Finished

d. ALV
ALV List
Report (401) – Create Simple ALV List Report

 Input Selection

 Output

108
Functional Specification (401)

I.REQUEST

Module MM (Material Management) Date 15 July 2008


Request By - Initial Name
Request ABAP Report Characteristic ALV List
Type
Printer - Reference T- MM03
Code

II. OBJECT INFO


1 Package $TMP 4 T-Code YP501
2 Program Name YPRACTICE_501 5 Include
Program
3 Function Module 6

III. DETAIL DESCRIPTION


1 Background Display List of Master Material
2 Flow of Process Select Material Data -> Display
3 Table MARA, MAKT, T006A
4 Input Screen/Selection Selection Parameter

Material Group (MARA-MATKL)

Material Number (MARA-MATNR)


5 Output
Mat. Group Mat. No. Description Old Mat. Base Unit of Measure
No. Measure
(MARA-MATKL) (MARA-MATNR) (MAKT-MAKTX) (MARA-BISMT) (MARA-MEINS) (T006A-MSEHT)

109
Report (401)
1) Open SE38.
2) Copy Program ”YPRACTICE_101” to ”YPRACTICE_401”.
3) Open GoTo > Attributes, and change Title with ”401 – Display List of
Master Material”.
4) Modification Report Declaration.

Before
REPORT ypractice_101.

After
REPORT ypractice_401 .

5) Click ” ”.
6) Add new Include Program.

7) Fill include name with ”YPRACTICE_401_ALV” and then click ” ”.

8) Click ” ” to create new include.

110
9) Save into same peckage with ”YPRACTICE_401” and then click ” ” to
insert the include into main program.
10) Insert the source code from page of ”YPRACTICE_401_ALV” into the
include program.
*&-------------------------------------------------------------------*
*& Include YPRACTICE_502_ALV
*
*&-------------------------------------------------------------------*
TYPE-POOLS : slis.

DATA : gw_is_layout TYPE slis_layout_alv,


gi_it_fieldcat TYPE slis_t_fieldcat_alv WITH
HEADER LINE,
gi_it_excluding TYPE slis_t_extab WITH
HEADER LINE,
gi_it_special_groups TYPE slis_t_sp_group_alv
WITH HEADER LINE,
gi_it_sort TYPE slis_t_sortinfo_alv WITH
HEADER LINE,
gi_it_filter TYPE slis_t_filter_alv WITH
HEADER LINE,
gw_is_sel_hide TYPE slis_sel_hide_alv,
gv_i_default,
gv_i_save,
gw_is_variant LIKE disvariant,
gi_it_events TYPE slis_t_event WITH
HEADER LINE,
gi_it_event_exit TYPE slis_t_event_exit WITH
HEADER LINE,
gw_is_print TYPE slis_print_alv,
gw_is_reprep_id TYPE slis_reprep_id.

*&-------------------------------------------------------------------*
*& Form fm_alv_show
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
* -->FT_ITAB text

111
*--------------------------------------------------------------------*
FORM fm_alv_show TABLES ft_itab.
CLEAR gi_it_event_exit.
gi_it_event_exit-ucomm = '&OUP'.
gi_it_event_exit-after = 'X'.
APPEND gi_it_event_exit.

CLEAR gi_it_event_exit.
gi_it_event_exit-ucomm = '&ODN'.
gi_it_event_exit-after = 'X'.
APPEND gi_it_event_exit.

CLEAR gi_it_event_exit.
gi_it_event_exit-ucomm = '&ETA'.
gi_it_event_exit-after = 'X'.
APPEND gi_it_event_exit.

CLEAR gi_it_event_exit.
gi_it_event_exit-ucomm = '&IC1'.
gi_it_event_exit-after = 'X'.
APPEND gi_it_event_exit.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE = ' '
i_callback_program = sy-repid
i_callback_pf_status_set = 'FM_ALV_SET_PF_STATUS'
i_callback_user_command = 'FM_ALV_USER_COMMAND'
* I_STRUCTURE_NAME =
is_layout = gw_is_layout
it_fieldcat = gi_it_fieldcat[]
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
it_sort = gi_it_sort[]
it_filter = gi_it_filter[]
is_sel_hide = gw_is_sel_hide
i_default = gv_i_default
i_save = gv_i_save
is_variant = gw_is_variant
it_events = gi_it_events[]
it_event_exit = gi_it_event_exit[]
is_print = gw_is_print
is_reprep_id = gw_is_reprep_id
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
t_outtab = ft_itab
EXCEPTIONS
program_error = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

ENDFORM. "fm_alv_show

*&--------------------------------------------------------------------
*

112
*& Form fm_alv_reset_data
*&--------------------------------------------------------------------
*
* text
*---------------------------------------------------------------------
*
FORM fm_alv_reset_data.
CLEAR : gw_is_layout,
gi_it_fieldcat,
gi_it_excluding,
gi_it_special_groups,
gi_it_sort,
gi_it_filter,
gw_is_sel_hide,
gv_i_default,
gv_i_save,
gw_is_variant,
gi_it_events,
gi_it_event_exit,
gw_is_print,
gw_is_reprep_id.

REFRESH : gi_it_fieldcat,
gi_it_excluding,
gi_it_special_groups,
gi_it_sort,
gi_it_filter,
gi_it_events,
gi_it_event_exit.

ENDFORM. "fm_alv_reset_data

*&-------------------------------------------------------------------*
*& Form fm_alv_set_layout
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
FORM fm_alv_set_layout USING fu_title.
gw_is_layout-window_titlebar = fu_title.
gw_is_layout-zebra = 'X'.
gw_is_layout-colwidth_optimize = 'X'.
gw_is_layout-no_colhead = space.
gw_is_layout-group_change_edit = 'X'.
* gw_is_layout-box_fieldname = 'CHBOX'.

ENDFORM. "fm_alv_set_layout

*&-------------------------------------------------------------------*
*& Form fm_alv_set_print
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
FORM fm_alv_set_print.
gw_is_print-no_print_listinfos = 'X'.
gw_is_print-no_print_selinfos = 'X'.
gw_is_print-no_coverpage = 'X'.
gw_is_print-no_print_hierseq_item = 'X'.
ENDFORM. "fm_alv_set_print

*&-------------------------------------------------------------------*
*& Form fm_alv_add_fieldcat
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
* -->FU_1 text
* -->FU_2 text
* -->FU_3 text

113
* -->FU_4 text
* -->FU_5 text
* -->FU_6 text
* -->FU_7 text
* -->FU_8 text
* -->FU_9 text
* -->FU_10 text
* -->FU_11 text
* -->FU_12 text
* -->FU_13 text
* -->FU_14 text
* -->FU_15 text
* -->FU_16 text
* -->FU_17 text
* -->FU_18 text
* -->FU_19 text
* -->FU_20 text
* -->FU_21 text
*--------------------------------------------------------------------*
FORM fm_alv_add_fieldcat USING
fu_1 fu_2 fu_3 fu_4 fu_5 fu_6 fu_7 fu_8 fu_9 fu_10
fu_11 fu_12 fu_13 fu_14 fu_15 fu_16
fu_17 fu_18 fu_19 fu_20 fu_21.

CLEAR: gi_it_fieldcat.
gi_it_fieldcat-fieldname = fu_1. " Fieldname
gi_it_fieldcat-ref_tabname = fu_2. " Reference Tablename
gi_it_fieldcat-ref_fieldname = fu_3. " Reference Fieldname
gi_it_fieldcat-no_out = fu_4. " (O)blig.(X)no out
gi_it_fieldcat-outputlen = fu_5. " Output length
gi_it_fieldcat-seltext_l = fu_6. " long key word
gi_it_fieldcat-seltext_m = fu_7. " middle key word
gi_it_fieldcat-seltext_s = fu_8. " short key word
gi_it_fieldcat-reptext_ddic = fu_9. " heading (ddic)
gi_it_fieldcat-round = fu_10. " round in write statement
gi_it_fieldcat-do_sum = fu_11. " sum up
gi_it_fieldcat-hotspot = fu_12. " 'X' = hotspot is active ->
Event click
gi_it_fieldcat-decimals_out = fu_13. " decimals in write statement
gi_it_fieldcat-currency = fu_14.
gi_it_fieldcat-quantity = fu_15.
gi_it_fieldcat-qfieldname = fu_16. " field with quantity unit
gi_it_fieldcat-cfieldname = fu_17. " field with currency unit
gi_it_fieldcat-checkbox = fu_18. " 'X' = checkbox or ' ' = not
checkbox
gi_it_fieldcat-icon = fu_19. " 'X' = icon or ' ' = not icon
gi_it_fieldcat-fix_column = fu_20. " 'X' = Fix Column On or ' ' =
Fix Column off gi_it_fieldcat-key = &21. "
gi_it_fieldcat-key = fu_21. " 'X' = Key or ' ' = not Key

APPEND gi_it_fieldcat.
ENDFORM. "fm_alv_add_fieldcat

*&-------------------------------------------------------------------*
*& Form FM_ALV_SET_PF_STATUS
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
* -->RT_EXTAB text
*--------------------------------------------------------------------*
FORM fm_alv_set_pf_status USING rt_extab TYPE slis_t_extab.
SET PF-STATUS 'YSTANDARD'.
ENDFORM. "fm_alv_set_pf_status

*&-------------------------------------------------------------------*
*& Form FM_USER_COMMAND

114
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
FORM fm_alv_user_command USING fu_ucomm LIKE sy-ucomm
fu_selfield TYPE slis_selfield.
DATA: lt_dynpread LIKE dynpread OCCURS 0 WITH HEADER LINE,
lv_ok_code LIKE sy-ucomm.

MOVE fu_ucomm TO lv_ok_code.


CASE lv_ok_code.
WHEN '&IC1'.
* PERFORM fm_alv_event_double_click.
WHEN '&ETA'.
* PERFORM fm_alv_event_double_click.
WHEN '&F03' OR '&F15' OR '&F12'.

ENDCASE.

MOVE 'X' TO fu_selfield-refresh.

ENDFORM. "FM_USER_COMMAND

11) Open new session of SE38, by pressing ‘/oSE38’ tehne enter at the command
field.
12) Fill program name with ”SAPLKKBL”.

13) Click ” ” to display the program.


14) Click ” ”.
15) Open GUI Status tree menu.

115
16) Copy GUI Status of ”Standard”.

116
17) Fill program with ”YPRACTICE_401” and status with ”YSTANDARD”.

18) Click ” ”.

19) Don’t change anything, just click ” ” again.


20) Back to program ”YPRACTICE_401” and start writing source code.
21) Remove ” DATA: gv_width TYPE i. " Width of list”
22) Modified ”Input Screen / Selection”.
Before
*---------------------------------------------------------------------
-*
*Input Screen/Selection
*---------------------------------------------------------------------
-*
SELECT-OPTIONS so_matkl FOR mara-matkl.
SELECT-OPTIONS so_matnr FOR mara-matnr.

After
*--------------------------------------------------------------------*
*Input Screen/Selection
*--------------------------------------------------------------------*

117
SELECTION-SCREEN BEGIN OF BLOCK groupbox1 WITH FRAME TITLE text_101.
"Declare Group Box 1

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_102 FOR FIELD so_matkl.
SELECT-OPTIONS so_matkl FOR mara-matkl.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_103 FOR FIELD so_matnr.
SELECT-OPTIONS so_matnr FOR mara-matnr.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK


groupbox1. "End Group Box 1

SELECTION-SCREEN BEGIN OF BLOCK groupbox2 WITH FRAME TITLE text_201.


"Declare Group Box 2

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_202 FOR FIELD p_mwidth.
PARAMETERS p_mwidth TYPE n DEFAULT 113 LENGTH 4.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_203 FOR FIELD p_mline .
PARAMETERS p_mline TYPE n DEFAULT 30 LENGTH 4.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK


groupbox2. "End Group Box 2

23) Create initialization code, write it after input Screen Block.


*---------------------------------------------------------------------
-*
*INITIALIZATION
*---------------------------------------------------------------------
-*
INITIALIZATION.
text_101 = 'Selection Parameter'.
text_102 = 'Material Group'.
text_103 = 'Material Number'.

text_201 = 'Page Setup'.


text_202 = 'Max. Width'.
text_203 = 'Max. Line per Page'.

24) Move ”INCLUDE ypractice_401_alv” to the top of source code.


*--------------------------------------------------------------------*
* Tables
*--------------------------------------------------------------------*
TABLES : mara, makt, t006a.

INCLUDE ypractice_401_alv.

*--------------------------------------------------------------------*
*GLOBAL VARIABLE DECRALATION
*--------------------------------------------------------------------*
TYPES: BEGIN OF ty_header,
...

118
25) Modified global variable declaration.

Before
*--------------------------------------------------------------------*
*GLOBAL VARIABLE DECRALATION
*--------------------------------------------------------------------*
DEFINE macro_data_possition.
if &1 = 'HEADER'.
write : /'|' no-gap,(9) &2 centered,
'|' no-gap,(18) &3 centered,
'|' no-gap,(40) &4 centered,
'|' no-gap,(18) &5 centered,
'|' no-gap,(5) &6 centered,
'|' no-gap,(10) &7 centered,
'|' no-gap.
else.
write : /'|' no-gap,(9) &2 centered,
'|' no-gap,(18) &3 ,
'|' no-gap,(40) &4 ,
'|' no-gap,(18) &5 ,
'|' no-gap,(5) &6 ,
'|' no-gap,(10) &7 ,
'|' no-gap.
endif.
END-OF-DEFINITION.

TYPES: BEGIN OF ty_header,


matkl LIKE mara-matkl, " Material Group
matnr LIKE mara-matnr, " Material Number
maktx LIKE makt-maktx, " Material Description
bismt LIKE mara-bismt, " Old material number
meins LIKE mara-meins, " Base Unit of Measure
mseht LIKE t006a-mseht, " Unit of Measurement Text
END OF ty_header.

DATA: gi_header TYPE STANDARD TABLE OF ty_header WITH HEADER LINE,


gi_makt LIKE STANDARD TABLE OF makt WITH HEADER LINE,
gi_t006a LIKE STANDARD TABLE OF t006a WITH HEADER LINE.

DATA: gv_width TYPE i. " Width of list

After
*--------------------------------------------------------------------*
*GLOBAL VARIABLE DECRALATION
*--------------------------------------------------------------------*

TYPES: BEGIN OF ty_mara,


matnr TYPE mara-matnr,
matkl TYPE mara-matkl,
bismt TYPE mara-bismt,
meins TYPE mara-meins,
END OF ty_mara.

TYPES: BEGIN OF ty_makt,


matnr TYPE mara-matnr,
maktx TYPE makt-maktx,
END OF ty_makt.

TYPES: BEGIN OF ty_t006a,


msehi TYPE t006a-msehi,
mseht TYPE t006a-mseht,
END OF ty_t006a.

119
TYPES: BEGIN OF ty_header,
matkl TYPE mara-matkl, " Material Group
matnr TYPE mara-matnr, " Material Number
maktx TYPE makt-maktx, " Material Description
bismt TYPE mara-bismt, " Old material number
meins TYPE mara-meins, " Base Unit of Measure
mseht TYPE t006a-mseht, " Unit of Measurement Text
END OF ty_header.

DATA: gi_header TYPE STANDARD TABLE OF ty_header,


gi_mara TYPE STANDARD TABLE OF ty_mara,
gi_makt TYPE STANDARD TABLE OF ty_makt,
gi_t006a TYPE STANDARD TABLE OF ty_t006a,
wa_header type ty_header,
wa_mara type ty_mara,
wa_makt type ty_makt,
wa_t006a type ty_t006a.

DATA: gv_width TYPE i. " Width of list

26) Modified sub routine ”fm_collect_data”.

Before
*&-------------------------------------------------------------------*
*& Form fm_collect_data
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
FORM fm_collect_data.
* Collect Master Material
SELECT matnr matkl bismt meins
INTO CORRESPONDING FIELDS OF TABLE gi_header
FROM mara
WHERE
matkl IN so_matkl AND
matnr IN so_matnr.

* "For SAP 4.6C


* DATA : lv_total_data type i.
* DESCRIBE TABLE gi_header LINES lv_total_data.
* IF LINES( lv_total_data ) > 0.

IF LINES( gi_header ) > 0." For SAP 4.7 above


* Collect Material Decription
SELECT matnr maktx
INTO CORRESPONDING FIELDS OF TABLE gi_makt
FROM makt
FOR ALL ENTRIES IN gi_header
WHERE
matnr = gi_header-matnr AND
spras = sy-langu.

* Collect Measurement Text


SELECT msehi mseht
INTO CORRESPONDING FIELDS OF TABLE gi_t006a
FROM t006a
FOR ALL ENTRIES IN gi_header
WHERE
msehi = gi_header-meins AND
spras = sy-langu.
ENDIF.

* Notes :
* Avoid using inner join

120
ENDFORM. "FM_COLLECT_DATA

After
*&-------------------------------------------------------------------*
*& Form fm_collect_data
*&-------------------------------------------------------------------*
text
*--------------------------------------------------------------------*
FORM fm_collect_data.
* Collect Master Material
SELECT matnr
matkl
bismt
meins
INTO TABLE gi_mara
FROM mara
WHERE
matkl IN so_matkl AND
matnr IN so_matnr.

IF LINES( gi_mara ) > 0.

* Collect Material Decription

SELECT matnr
maktx
INTO TABLE gi_makt
FROM makt
FOR ALL ENTRIES IN gi_mara
WHERE
matnr = gi_mara-matnr AND
spras = sy-langu.

* Collect Measurement Text

SELECT msehi
mseht
INTO TABLE gi_t006a
FROM t006a
FOR ALL ENTRIES IN gi_mara
WHERE
msehi = gi_mara-meins AND
spras = sy-langu.

ENDIF.

* Notes :
* Avoid using inner join
ENDFORM. "FM_COLLECT_DATA

27) Modified sub routine ”fm_process_data”.

Before
*&-------------------------------------------------------------------*
*& Form FM_PROCESS_DATA
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
FORM fm_process_data.
*Get other requirement information
LOOP AT gi_header.

121
* Get Material Description
READ TABLE gi_makt WITH KEY matnr = gi_header-matnr.
IF sy-subrc = 0.
gi_header-maktx = gi_makt-maktx.
ENDIF.

* Get Measurement Text


READ TABLE gi_t006a WITH KEY msehi = gi_header-meins.
IF sy-subrc = 0.
gi_header-mseht = gi_t006a-mseht.
ENDIF.

MODIFY gi_header.
ENDLOOP.

ENDFORM. "FM_PROCESS_DATA

After
*&-------------------------------------------------------------------*
*& Form FM_PROCESS_DATA
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*

FORM fm_process_data.

*Get other requirement information

SORT gi_makt BY matnr.


SORT gi_t006a BY msehi.
LOOP AT gi_mara INTO wa_mara.
IF sy-subrc = 0.
wa_header-matnr = wa_mara-matnr.
wa_header-matkl = wa_mara-matkl.
wa_header-bismt = wa_mara-bismt.
wa_header-meins = wa_mara-meins.

* Get Material Description

READ TABLE gi_makt INTO wa_makt WITH KEY matnr = wa_mara-matnr


BINARY SEARCH.
IF sy-subrc = 0.
wa_header-maktx = wa_makt-maktx.
ENDIF.

* Get Measurement Text

READ TABLE gi_t006a INTO wa_t006a WITH KEY msehi = wa_mara-meins


BINARY SEARCH.
IF sy-subrc = 0.
wa_header-mseht = wa_t006a-mseht.
ENDIF.
APPEND wa_header TO gi_header.
ENDIF.
ENDLOOP.

ENDFORM. "FM_PROCESS_DATA

28) Modified sub routine ”fm_display_data”.

Before
*&-------------------------------------------------------------------*
*& Form fm_display_data
*&-------------------------------------------------------------------*

122
* text
*--------------------------------------------------------------------*
FORM fm_display_data.
* Create Header Text
ULINE AT (gv_width). " Upper frame border
FORMAT COLOR COL_HEADING INTENSIFIED. " Title color
macro_data_possition : 'HEADER' 'Mat. Group' 'Mat. No.'
'Description' 'Old Mat. No.' 'Base Unit' 'Measure'.
WRITE: AT gv_width sy-vline. " Right border
ULINE AT (gv_width). " Line below titles
FORMAT COLOR OFF.

* Display Data to Screen


LOOP AT gi_header.
macro_data_possition : 'CONTENT'
gi_header-matkl
gi_header-matnr
gi_header-maktx
gi_header-bismt
gi_header-meins
gi_header-mseht.
ENDLOOP.

* End of Line
ULINE AT (gv_width). " Line below last data

ENDFORM. "fm_display_data

After
*&-------------------------------------------------------------------*
*& Form fm_display_data
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
FORM fm_display_data.
PERFORM fm_alv_reset_data.

* Set ALV Parameters and Data


PERFORM fm_alv_set_layout USING 'Display List of Master Material'.
PERFORM fm_alv_set_print.
PERFORM FM_ALV_SET_COLUMN.

GV_I_DEFAULT = 'X'.
GV_I_SAVE = 'A'.

PERFORM FM_ALV_SHOW TABLES GI_HEADER.

ENDFORM. "fm_display_data

29) Create new sub routine ”fm_alv_set_column” at the bottom of source code.
*&-------------------------------------------------------------------*
*& Form fm_alv_set_column
*&-------------------------------------------------------------------*
* text
*--------------------------------------------------------------------*
FORM fm_alv_set_column.
* matkl LIKE mara-matkl, " Material Group
* matnr LIKE mara-matnr, " Material Number
* maktx LIKE makt-maktx, " Material Description
* bismt LIKE mara-bismt, " Old material number
* meins LIKE mara-meins, " Base Unit of Measure
* mseht LIKE t006a-mseht, " Unit of Measurement Text

123
* Displaying Column by Fieldname

perform fm_alv_add_fieldcat using :


'MATKL' 'MARA' 'MATKL' '' '' 'Mat. Group' '' '' '' '' '' '' ''
'' '' '' '' '' '' 'X' 'X',
'MATNR' 'MARA' 'MATNR' '' '' 'Mat. Number' '' '' '' '' '' '' ''
'' '' '' '' '' '' 'X' 'X',
'MAKTX' 'MAKT' 'MAKTX' '' '' 'Decription' '' '' '' '' '' '' ''
'' '' '' '' '' '' '' '',
'BISMT' 'MARA' 'BISMT' '' '' 'Old Mat. No' '' '' '' '' '' '' ''
'' '' '' '' '' '' '' '',
'MEINS' 'MARA' 'MEINS' '' '' 'Base Unit' '' '' '' '' '' '' ''
'' '' '' '' '' '' '' '',
'MSEHT' 'T006A' 'MSEHT' '' '' 'Measure' '' '' '' '' '' '' ''
'' '' '' '' '' '' '' ''.

* Sort and Group by Field


* CLEAR gi_it_sort.
* gi_it_sort-fieldname = 'WERKS'. ">> Filled by Fieldname
* gi_it_sort-up = 'X'. ">> 'X' = Ascending ; ' ' =
Descending
* gi_it_sort-subtot = 'X'.
* gi_it_sort-group = '*'. ">> '*' = Grouped by field ; ' ' =
Not grouped by this field
* APPEND gi_it_sort.

ENDFORM. "fm_alv_set_column

30) Activate and run.


31) Create T-Code ”YP401”.
32) Finished.

Revisi Report 401


REPORT y_revisi_401.
*----------------------------------------------------------------------*
* Tables
*----------------------------------------------------------------------*

TABLES : mara, makt, t006a.

INCLUDE ypractice_401_alv.

*----------------------------------------------------------------------*
*GLOBAL VARIABLE DECRALATION
*----------------------------------------------------------------------*

TYPES: BEGIN OF ty_header,


matkl TYPE mara-matkl, " Material Group
matnr TYPE mara-matnr, " Material Number
maktx TYPE makt-maktx, " Material Description
bismt TYPE mara-bismt, " Old material number
meins TYPE mara-meins, " Base Unit of Measure
mseht TYPE t006a-mseht, " Unit of Measurement Text
END OF ty_header.

TYPES: BEGIN OF ty_mara,


matkl TYPE mara-matkl,
matnr TYPE mara-matnr,
bismt TYPE mara-bismt,

124
meins TYPE mara-meins,
END OF ty_mara.

TYPES: BEGIN OF ty_makt,


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

TYPES: BEGIN OF ty_t006a,


msehi TYPE t006a-msehi,
mseht TYPE t006a-mseht,
END OF ty_t006a.

*internal table
DATA: gi_header TYPE STANDARD TABLE OF ty_header,
gi_mara TYPE STANDARD TABLE OF ty_mara,
gi_makt TYPE STANDARD TABLE OF ty_makt,
gi_t006a TYPE STANDARD TABLE OF ty_t006a.

*workarea
DATA: wa_header TYPE ty_header,
wa_mara TYPE ty_mara,
wa_makt TYPE ty_makt,
wa_t006a TYPE ty_t006a.

DATA: gv_width TYPE i. " Width of list

*----------------------------------------------------------------------*
*Input Screen/Selection
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK groupbox1 WITH FRAME TITLE text_101.
"Declare Group Box 1
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(18) text_102 FOR FIELD so_matkl.
SELECT-OPTIONS so_matkl FOR mara-matkl.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_103 FOR FIELD so_matnr.
SELECT-OPTIONS so_matnr FOR mara-matnr.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK groupbox1. "End
Group Box 1
*----------------------------------------------------------------------*
*EVENT
*----------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
text_101 = 'Selection Parameter'.
text_102 = 'Material Group'.
text_103 = 'Material Number'.

INITIALIZATION.

*======================================================================*
*MAIN PROGRAM
*Execute after Input Screen
*======================================================================*

START-OF-SELECTION.
gv_width = 113.
PERFORM fm_collect_data.
PERFORM fm_process_data.
PERFORM fm_display_data.

END-OF-SELECTION.

*&--------------------------------------------------------------------*
*& Form fm_collect_data

125
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*

FORM fm_collect_data.
* Collect Master Material
SELECT matkl
matnr
bismt
meins
INTO TABLE gi_mara
FROM mara
WHERE
matkl IN so_matkl AND
matnr IN so_matnr.
* "For SAP 4.6C
* DATA : lv_total_data type i.
* DESCRIBE TABLE gi_header LINES lv_total_data.
* IF LINES( lv_total_data ) > 0.

IF gi_mara[] IS NOT INITIAL.


* Collect Material Decription
SELECT matnr
maktx
INTO TABLE gi_makt
FROM makt
FOR ALL ENTRIES IN gi_mara
WHERE
matnr = gi_mara-matnr AND
spras = sy-langu.
* Collect Measurement Text
SELECT msehi
mseht
INTO TABLE gi_t006a
FROM t006a
FOR ALL ENTRIES IN gi_mara
WHERE
msehi = gi_mara-meins AND
spras = sy-langu.
ENDIF.
* Notes :
* Avoid using inner join
ENDFORM. "FM_COLLECT_DATA

*&--------------------------------------------------------------------*
*& Form FM_PROCESS_DATA
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*

FORM fm_process_data.
*Get other requirement information
LOOP AT gi_mara INTO wa_mara.
IF sy-subrc = 0.
wa_header-matkl = wa_mara-matkl.
wa_header-matnr = wa_mara-matnr.
wa_header-bismt = wa_mara-bismt.
wa_header-meins = wa_mara-meins.
* Get Material Description
READ TABLE gi_makt INTO wa_makt WITH KEY matnr = wa_mara-matnr.
IF sy-subrc = 0.
wa_header-maktx = wa_makt-maktx.
ENDIF.
* Get Measurement Text
READ TABLE gi_t006a INTO wa_t006a WITH KEY msehi = wa_mara-meins.
IF sy-subrc = 0.
wa_header-mseht = wa_t006a-mseht.
ENDIF.

126
ENDIF.
APPEND wa_header TO gi_header.
ENDLOOP.
ENDFORM. "FM_PROCESS_DATA

*&--------------------------------------------------------------------*
*& Form fm_display_data
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*

FORM fm_display_data.
PERFORM fm_alv_reset_data.
* Set ALV Parameters and Data
PERFORM fm_alv_set_layout USING 'Display List of Master Material'.
PERFORM fm_alv_set_print.
PERFORM fm_alv_set_column.
gv_i_default = 'X'.
gv_i_save = 'A'.
PERFORM fm_alv_show TABLES gi_header.
ENDFORM. "fm_display_data

*======================================================================
*Set ALV
*======================================================================
*&--------------------------------------------------------------------*
*& Form fm_alv_set_column
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM fm_alv_set_column.
* matkl type mara-matkl, " Material Group
* matnr type mara-matnr, " Material Number
* maktx type makt-maktx, " Material Description
* bismt type mara-bismt, " Old material number
* meins type mara-meins, " Base Unit of Measure
* mseht type t006a-mseht, " Unit of Measurement Text
* Displaying Column by Fieldname

PERFORM fm_alv_add_fieldcat USING :


'MATKL' 'MARA' 'MATKL' '' '' 'Mat. Group' '' '' '' '' '' '' '' '' ''
'' '' '' '' 'X' 'X',
'MATNR' 'MARA' 'MATNR' '' '' 'Mat. Number' '' '' '' '' '' '' '' '' ''
'' '' '' '' 'X' 'X',
'MAKTX' 'MAKT' 'MAKTX' '' '' 'Decription' '' '' '' '' '' '' '' '' ''
'' '' '' '' '' '',
'BISMT' 'MARA' 'BISMT' '' '' 'Old Mat. No' '' '' '' '' '' '' '' '' ''
'' '' '' '' '' '',
'MEINS' 'MARA' 'MEINS' '' '' 'Base Unit' '' '' '' '' '' '' '' '' ''
'' '' '' '' '' '',
'MSEHT' 'T006A' 'MSEHT' '' '' 'Measure' '' '' '' '' '' '' '' '' ''
'' '' '' '' '' ''.

* Sort and Group by Field


* CLEAR gi_it_sort.
* gi_it_sort-fieldname = 'WERKS'. ">> Filled by Fieldname
* gi_it_sort-up = 'X'. ">> 'X' = Ascending ; ' ' = Descending
* gi_it_sort-subtot = 'X'.
* gi_it_sort-group = '*'. ">> '*' = Grouped by field ; ' ' = Not
grouped by this field
* APPEND gi_it_sort.
ENDFORM. "fm_alv_set_column

ALV GRID

127
Report (402) – Create Simple ALV Grid Report

 Input Selection

 Output

Functional Specification (402)

128
I.REQUEST
Module MM (Material Management) Date 15 July 2008
Request By - Initial Name
Request ABAP Report Characteristic ALV List
Type
Printer - Reference T- MM03
Code

II. OBJECT INFO


1 Package $TMP 4 T-Code YP501
2 Program Name YPRACTICE_501 5 Include
Program
3 Function Module 6

III. DETAIL DESCRIPTION


1 Background Display List of Master Material
2 Flow of Process Select Material Data -> Display
3 Table MARA, MAKT, T006A
4 Input Screen/Selection Selection Parameter

Material Group (MARA-MATKL)

Material Number (MARA-MATNR)


5 Output
Mat. Group Mat. No. Description Old Mat. Base Unit of Measure
No. Measure
(MARA-MATKL) (MARA-MATNR) (MAKT-MAKTX) (MARA-BISMT) (MARA-MEINS) (T006A-MSEHT)

Report (402)

Creating Report

1) Open SE38.

129
2) Copy Program ”YPRACTICE_401” to ”YPRACTICE_402”.
3) Select all object.

4) Click ” ”.

5) Copy Include Program with name ”YPRACTICE_402_ALV”.

6) Click ” ” and then save the program.


7) Change program ”YPRACTICE_402”.
8) Modified report declaration.

Before
REPORT ypractice_401.

After

130
REPORT ypractice_402.

9) Double click Include Program ”YPRACTICE_402_ALV” at this source code


below.
...
TABLES : mara, makt, t006a.

INCLUDE YPRACTICE_402_ALV.
*INCLUDE ypractice_501_alv.

*--------------------------------------------------------------------*
*GLOBAL VARIABLE DECRALATION
*--------------------------------------------------------------------*
TYPES: BEGIN OF ty_header,
...

10) Rename function name.

Before
...
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
..

After
...
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
...

11) Activated all object and run.

131
12) Create T-Code ”YP402”.
13) Finished.

Revisi Report 402


REPORT y_revisi_402.
*----------------------------------------------------------------------*
* Tables
*----------------------------------------------------------------------*

TABLES : mara, makt, t006a.

INCLUDE ypractice_402_alv.
*INCLUDE ypractice_501_alv.

*----------------------------------------------------------------------*
*GLOBAL VARIABLE DECRALATION
*----------------------------------------------------------------------*

TYPES: BEGIN OF ty_header,


matkl TYPE mara-matkl, " Material Group
matnr TYPE mara-matnr, " Material Number
maktx TYPE makt-maktx, " Material Description
bismt TYPE mara-bismt, " Old material number
meins TYPE mara-meins, " Base Unit of Measure
mseht TYPE t006a-mseht, " Unit of Measurement Text
END OF ty_header.

TYPES: BEGIN OF ty_mara,


matkl TYPE mara-matkl,
matnr TYPE mara-matnr,
bismt TYPE mara-bismt,
meins TYPE mara-meins,
END OF ty_mara.

TYPES: BEGIN OF ty_makt,


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

TYPES: BEGIN OF ty_t006a,


msehi TYPE t006a-msehi,
mseht TYPE t006a-mseht,
END OF ty_t006a.

*internal table
DATA: gi_header TYPE STANDARD TABLE OF ty_header,
gi_mara TYPE STANDARD TABLE OF ty_mara,
gi_makt TYPE STANDARD TABLE OF ty_makt,
gi_t006a TYPE STANDARD TABLE OF ty_t006a.

*workarea
DATA: wa_header TYPE ty_header,
wa_mara TYPE ty_mara,
wa_makt TYPE ty_makt,
wa_t006a TYPE ty_t006a.

DATA: gv_width TYPE i. " Width of list

*----------------------------------------------------------------------*
*Input Screen/Selection
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK groupbox1 WITH FRAME TITLE text_101.
"Declare Group Box 1

132
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(18) text_102 FOR FIELD so_matkl.
SELECT-OPTIONS so_matkl FOR mara-matkl.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_103 FOR FIELD so_matnr.
SELECT-OPTIONS so_matnr FOR mara-matnr.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK groupbox1. "End
Group Box 1
*----------------------------------------------------------------------*
*EVENT
*----------------------------------------------------------------------*
AT SELECTION-SCREEN OUTPUT.
text_101 = 'Selection Parameter'.
text_102 = 'Material Group'.
text_103 = 'Material Number'.

INITIALIZATION.

*======================================================================*
*MAIN PROGRAM
*Execute after Input Screen
*======================================================================*

START-OF-SELECTION.
gv_width = 113.
PERFORM fm_collect_data.
PERFORM fm_process_data.
PERFORM fm_display_data.

END-OF-SELECTION.

*&--------------------------------------------------------------------*
*& Form fm_collect_data
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*

FORM fm_collect_data.
* Collect Master Material
SELECT matkl
matnr
bismt
meins
INTO TABLE gi_mara
FROM mara
WHERE
matkl IN so_matkl AND
matnr IN so_matnr.
* "For SAP 4.6C
* DATA : lv_total_data type i.
* DESCRIBE TABLE gi_header LINES lv_total_data.
* IF LINES( lv_total_data ) > 0.

IF gi_mara[] IS NOT INITIAL.


* Collect Material Decription
SELECT matnr
maktx
INTO TABLE gi_makt
FROM makt
FOR ALL ENTRIES IN gi_mara
WHERE
matnr = gi_mara-matnr AND
spras = sy-langu.
* Collect Measurement Text
SELECT msehi

133
mseht
INTO TABLE gi_t006a
FROM t006a
FOR ALL ENTRIES IN gi_mara
WHERE
msehi = gi_mara-meins AND
spras = sy-langu.
ENDIF.
* Notes :
* Avoid using inner join
ENDFORM. "FM_COLLECT_DATA

*&--------------------------------------------------------------------*
*& Form FM_PROCESS_DATA
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*

FORM fm_process_data.
*Get other requirement information
LOOP AT gi_mara INTO wa_mara.
IF sy-subrc = 0.
wa_header-matkl = wa_mara-matkl.
wa_header-matnr = wa_mara-matnr.
wa_header-bismt = wa_mara-bismt.
wa_header-meins = wa_mara-meins.
* Get Material Description
READ TABLE gi_makt INTO wa_makt WITH KEY matnr = wa_mara-matnr.
IF sy-subrc = 0.
wa_header-maktx = wa_makt-maktx.
ENDIF.
* Get Measurement Text
READ TABLE gi_t006a INTO wa_t006a WITH KEY msehi = wa_mara-meins.
IF sy-subrc = 0.
wa_header-mseht = wa_t006a-mseht.
ENDIF.
ENDIF.
APPEND wa_header TO gi_header.
ENDLOOP.
ENDFORM. "FM_PROCESS_DATA

*&--------------------------------------------------------------------*
*& Form fm_display_data
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*

FORM fm_display_data.
PERFORM fm_alv_reset_data.
* Set ALV Parameters and Data
PERFORM fm_alv_set_layout USING 'Display List of Master Material'.
PERFORM fm_alv_set_print.
PERFORM fm_alv_set_column.
gv_i_default = 'X'.
gv_i_save = 'A'.
PERFORM fm_alv_show TABLES gi_header.
ENDFORM. "fm_display_data

*======================================================================
*Set ALV
*======================================================================
*&--------------------------------------------------------------------*
*& Form fm_alv_set_column
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM fm_alv_set_column.
* matkl type mara-matkl, " Material Group

134
* matnr type mara-matnr, " Material Number
* maktx type makt-maktx, " Material Description
* bismt type mara-bismt, " Old material number
* meins type mara-meins, " Base Unit of Measure
* mseht type t006a-mseht, " Unit of Measurement Text
* Displaying Column by Fieldname

PERFORM fm_alv_add_fieldcat USING :


'MATKL' 'MARA' 'MATKL' '' '' 'Mat. Group' '' '' '' '' '' '' '' '' ''
'' '' '' '' 'X' 'X',
'MATNR' 'MARA' 'MATNR' '' '' 'Mat. Number' '' '' '' '' '' '' '' '' ''
'' '' '' '' 'X' 'X',
'MAKTX' 'MAKT' 'MAKTX' '' '' 'Decription' '' '' '' '' '' '' '' '' ''
'' '' '' '' '' '',
'BISMT' 'MARA' 'BISMT' '' '' 'Old Mat. No' '' '' '' '' '' '' '' '' ''
'' '' '' '' '' '',
'MEINS' 'MARA' 'MEINS' '' '' 'Base Unit' '' '' '' '' '' '' '' '' ''
'' '' '' '' '' '',
'MSEHT' 'T006A' 'MSEHT' '' '' 'Measure' '' '' '' '' '' '' '' '' ''
'' '' '' '' '' ''.

* Sort and Group by Field


* CLEAR gi_it_sort.
* gi_it_sort-fieldname = 'WERKS'. ">> Filled by Fieldname
* gi_it_sort-up = 'X'. ">> 'X' = Ascending ; ' ' = Descending
* gi_it_sort-subtot = 'X'.
* gi_it_sort-group = '*'. ">> '*' = Grouped by field ; ' ' = Not
grouped by this field
* APPEND gi_it_sort.
ENDFORM. "fm_alv_set_column

e. SmartForms
 Seleksi Input:

 Output:

135
Functional Specification

I.PERMINTAAN
Module MM (Material Management) Date 15 Oktober 2009
Request By - Initial Name
Request Report ABAP Characteristic FORM (SmartForms)
Type
Printer - Reference T-Code MM03

INFO
II. OBJEK

1 Package $TMP 4 T-Code YP601


2 Program YPRACTICE_601 5 Include

136
Name Program
3 Function 6
Modul

DISKRIPSI
III.DETAIL

1 Background Displaying Material Master List


2 Flow of Process Select Material Data -> Display
3 Tables MARA, MAKT, T006A
4 Input Screen/Selection Material Group (MARA-MATKL)

Material Number (MARA-MATNR)

Page Setup

Max. Row
5 Output
Mat. Mat. No. Description Old Mat. Base Unit of Measure
Group No. Measure
(MARA-MATKL) (MARA-MATNR) (MAKT-MAKTX) (MARA-BISMT) (MARA-MEINS) (T006A-MSEHT)

Report (501)

Creating Report

1) Create New Form:


 Open T-Code SMARTFORMS.
 Insert name of program, program name must begin with the letter Y or Z.
Name of the form = “YFO_PRACTICE_101”.

 Click

137
 Change the word on the ”Meaning” with ”Form List of Master Material”.

 Click
 Optional insert Package to create programs that can transport to another
client, if only for training package need not be filled.

138
 Click “ ” save if you want to create program that can be transported to
another client, or click “ ” if only for training.
 SmartForms be made.
2) Double click on the menu ”Form Interface”.
3) Open the tab ”Import” and add the import parameters, like the image below.

4) Open the tab ”Table” and add the table parameters, like the image below.

139
5) Firstly you must create Function Builder of ”YST_HEADER_101,
YST_RANGE_MATKL and YST_RANGE_MATNR”.

 Create new Structure of YST_HEADER_101


 Open T-Code ”SE11”.
 Enter Data Type ”YST_HEADER_101”.

 Click ” ”.
 Select ”Structure”.

 Fill Short Description ”Structure for RFC Report”.

140
 Add component / field like this below.

 Click ” ” to save structure.


Notes: You can save the Existing Package or Local Object.
 Click ” ” to activated structure.

 Create Function
 Open T-Code ”SE37”.
 Enter new Function ”YFM_RFC_PRACTICE_101”

 Click “ ”
 Fill function group with “YFG MIL” and short text with “RFC Practice
101”

 Click “ ” to save function.

141
 Edit and set Processing type to “Remote enabled menu”

 Add import variable like this screen capture bellow

 Add table variable like this screen capture bellow

 Add new source code, copy and paste this source code bellow
to”Source Code” tab
FUNCTION yfm_rfc_practice_101.
*"-------------------------------------------------------------
--------
*"*"Local interface:
*" IMPORTING
*" VALUE(GV_MATKL) LIKE MARA-MATKL OPTIONAL
*" VALUE(GV_MATNR) LIKE MARA-MATNR OPTIONAL
*" VALUE(GV_MAX_ROW) TYPE I DEFAULT 100
*" TABLES
*" GI_HEADER STRUCTURE YTA_HEADER_101 OPTIONAL

142
*"-------------------------------------------------------------
--------

DATA: gi_makt TYPE STANDARD TABLE OF makt WITH HEADER LINE,


gi_t006a TYPE STANDARD TABLE OF t006a WITH HEADER LINE.
* DATA: lv_counter TYPE i.

RANGES : lr_matkl FOR mara-matkl,


lr_matnr FOR mara-matnr.

IF gv_matkl IS NOT INITIAL.


MOVE : gv_matkl TO lr_matkl-low,
space TO lr_matkl-high,
'EQ' TO lr_matkl-option,
'I' TO lr_matkl-sign.
APPEND lr_matkl.
ENDIF.

IF gv_matnr IS NOT INITIAL.


MOVE : gv_matnr TO lr_matnr-low,
space TO lr_matnr-high,
'EQ' TO lr_matnr-option,
'I' TO lr_matnr-sign.
APPEND lr_matnr.
ENDIF.

* Collect Master Material


SELECT matnr matkl bismt meins
UP TO gv_max_row ROWS
INTO CORRESPONDING FIELDS OF TABLE gi_header
FROM mara
WHERE
matkl IN lr_matkl AND
matnr IN lr_matnr.

* Collect Material Decription


SELECT matnr maktx
INTO CORRESPONDING FIELDS OF TABLE gi_makt
FROM makt
FOR ALL ENTRIES IN gi_header
WHERE
matnr = gi_header-matnr AND
spras = sy-langu.

* Collect Measurement Text

SELECT msehi mseht


INTO CORRESPONDING FIELDS OF TABLE gi_t006a
FROM t006a
FOR ALL ENTRIES IN gi_header
WHERE
msehi = gi_header-meins AND
spras = sy-langu.

*Get other requirement information

LOOP AT gi_header.
* Get Material Description
READ TABLE gi_makt WITH KEY matnr = gi_header-matnr.
IF sy-subrc = 0.
gi_header-maktx = gi_makt-maktx.
ENDIF.

* Get Measurement Text


READ TABLE gi_t006a WITH KEY msehi = gi_header-meins.
IF sy-subrc = 0.

143
gi_header-mseht = gi_t006a-mseht.
ENDIF.

MODIFY gi_header.

ENDLOOP.

ENDFUNCTION.

 Save and active the function

 Create New Structure of YST_RANGE_MATKL


 Open T-Code “SE11”
 Enter Data Type “YST_RANGE_MATKL”

 Click “ ”
 Select ”Structure”

144
 Fill short description “Structure for RANGE of Material Group”

 Add component/field like this bellow

 Click “ ” to save structure.


Notes: you can save to Existing Package or Local Object.
 Click “ ” to active structure.

 Create New Structure of YST_RANGE_MATNR


 Open T-Code “SE11”

145
 Enter Data Type “YST_RANGE_MATNR”

 Click “ ”
 Select ”Structure”

 Fill short description “Structure for RANGE of Material Group”

146
 Add component/field like this bellow

 Click “ ” to save structure.


Notes: you can save to Existing Package or Local Object.
 Click “ ” to active structure.

 Create Function
 Open T-Code “SE37”
 Copy function YFM_RFC_PRACTICE_101 to
YFM_RFC_PRACTICE_102

 Click “ ”
 Fill the function module with “YFM_RFC_PRACTICE_102”

 Click “ ” to copy and save function


 Click “ ” to change function

147
 Edit the short text with “RFC Practice 102”

 Delete import variable like this capture bellow

 Add new source code, copy and paste this source code bellow
to”Source Code” tab

FUNCTION yfm_rfc_practice_102.
*"-------------------------------------------------------------
---------
*"*"Local interface:
*" IMPORTING
*" VALUE(GV_MAX_ROW) TYPE I DEFAULT 100
*" TABLES
*" GI_HEADER STRUCTURE YTA_HEADER_101 OPTIONAL
*" GR_MATKL STRUCTURE YST_RANGE_MATKL OPTIONAL
*" GR_MATNR STRUCTURE YST_RANGE_MATNR OPTIONAL
*"-------------------------------------------------------------
---------

DATA: gi_makt TYPE STANDARD TABLE OF makt WITH HEADER LINE,


gi_t006a TYPE STANDARD TABLE OF t006a WITH HEADER LINE.

148
* DATA: lv_counter TYPE i.

* Collect Master Material


SELECT matnr matkl bismt meins
UP TO gv_max_row ROWS
INTO CORRESPONDING FIELDS OF TABLE gi_header
FROM mara
WHERE
matkl IN gr_matkl AND
matnr IN gr_matnr.

* Collect Material Decription


SELECT matnr maktx
INTO CORRESPONDING FIELDS OF TABLE gi_makt
FROM makt
FOR ALL ENTRIES IN gi_header
WHERE
matnr = gi_header-matnr AND
spras = sy-langu.

* Collect Measurement Text

SELECT msehi mseht


INTO CORRESPONDING FIELDS OF TABLE gi_t006a
FROM t006a
FOR ALL ENTRIES IN gi_header
WHERE
msehi = gi_header-meins AND
spras = sy-langu.

*Get other requirement information

LOOP AT gi_header.
* Get Material Description
READ TABLE gi_makt WITH KEY matnr = gi_header-matnr.
IF sy-subrc = 0.
gi_header-maktx = gi_makt-maktx.
ENDIF.

* Get Measurement Text


READ TABLE gi_t006a WITH KEY msehi = gi_header-meins.
IF sy-subrc = 0.
gi_header-mseht = gi_t006a-mseht.
ENDIF.

MODIFY gi_header.

ENDLOOP.

ENDFUNCTION.

 Save and active the function.

 Back to Smartforms YFO_PRACTICE_101


 Double click on the menu “Global Definition”

149
 Open the tab “Global Data” and add parameter like the image bellow

 Double-click on the menu “Main”

150
 Open the tab “Output Options” and set the value “Possition and Size”
as shown bellow

 Right click on the menu “Main” and click on “Create> Table” to create
a table (List Data)

 Click “ ” on the tab “Table” to define the columns


to be displayed

151
 Fill in value as the image bellow

Note: The total value of all columns must be no more than “Table
Width”

 Press “ ” to add column

152
 Add the value at the column number 6 with value like this image
bellow

 Press the “ ” to return to the initial menu.


 Press ” ” to set the pattern of lines on the List Data

153
 Press “ ”

 Select this pattern “ ”


 Click tab “Data” and enter the value as shown bellow

154
 Right-click on the menu “Header” and click “Create> Table Line” to
make header on the List Data

 Select line type “%LTYPE1” and automatically column (Cell) will be


formed

Note: one cell represent one column

 Right-click on the menu “%CELL1” and click “Create > Text” to


create the column header title

155
 Open the tab “General Attribute” and content of text “Mat. Group” like
the picture bellow.

 Re doing step 15 and 16 for “%CELL2” until “%CELL6” with the


following text.
“%CELL2” = Mat. No.
“%CELL3” = Description.
“%CELL4” = Old Mat. No.
“%CELL5” = Base Unit of Measure
“%CELL6” = Measure
Note: Don’t forget to press the button “ ” every single long process

156
 Right-click on the menu “Main Area” and click “Create > Table Line”
to make Line Data

 Select line type “%LTYPE1” and automatically column (Cell) will be


formed

157
 Right-click on the menu “%CELL7” and click “Create > Text” to
create a row of data in column

 Open tab “General Attribute”

158
 Click “Utilities > Field List on/off” or press “Ctrl + Shift + F4” to open
the list of parameters in the declaration onsteps 3-7

 Open field “Global Data > GW_HEADER”

159
 Drag and Drop “MATKL” into tab “General Attribute”

 Do it again step 21 and 25 for “%CELL8” until “%CELL12” with the


following text
“%CELL8” = MATNR.
“%CELL9” = MAKTX.
“%CELL10” = BISMT.
“%CELL11” = MEINS.
“%CELL8” = MSEHT.
Note: Don’t forget to press the button “ ” every single long process

 Press “ ” for activation and check form.


 Press “ ” to test running form.
 Finished.

 Create Report
 Open SE38
 Copy program “YPRACTICE_101” become “YPRACTICE_501”
 Open GoTo > Attributes and change “Title” with “501-Display List
of Master Material”
 Modification declaration Report

Before
REPORT ypractice_101.

After
REPORT ypractice_601.

 Modified “Global Variable Declaration”

160
Before
*--------------------------------------------------------------
--------*
*GLOBAL VARIABLE DECRALATION
*--------------------------------------------------------------
--------*
DEFINE macro_data_possition.
if &1 = 'HEADER'.
write : /'|' no-gap,(9) &2 centered,
'|' no-gap,(18) &3 centered,
'|' no-gap,(40) &4 centered,
'|' no-gap,(18) &5 centered,
'|' no-gap,(5) &6 centered,
'|' no-gap,(10) &7 centered,
'|' no-gap.
else.
write : /'|' no-gap,(9) &2 centered,
'|' no-gap,(18) &3 ,
'|' no-gap,(40) &4 ,
'|' no-gap,(18) &5 ,
'|' no-gap,(5) &6 ,
'|' no-gap,(10) &7 ,
'|' no-gap.
endif.
END-OF-DEFINITION.

TYPES: BEGIN OF ty_header,


matkl LIKE mara-matkl, " Material Group
matnr LIKE mara-matnr, " Material Number
maktx LIKE makt-maktx, " Material Description
bismt LIKE mara-bismt, " Old material number
meins LIKE mara-meins, " Base Unit of Measure
mseht LIKE t006a-mseht, " Unit of Measurement Text
END OF ty_header.

DATA: gi_header TYPE STANDARD TABLE OF ty_header WITH HEADER


LINE,
gi_makt LIKE STANDARD TABLE OF makt WITH HEADER LINE,
gi_t006a LIKE STANDARD TABLE OF t006a WITH HEADER LINE.

DATA: gv_width TYPE i. " Width of list

After
*--------------------------------------------------------------
--------*
*GLOBAL VARIABLE DECRALATION
*--------------------------------------------------------------
--------*
DATA: gi_header LIKE STANDARD TABLE OF yst_header_101 WITH
HEADER LINE,
gi_makt LIKE STANDARD TABLE OF makt WITH HEADER LINE,
gi_t006a LIKE STANDARD TABLE OF t006a WITH HEADER LINE.

 Modified “Input Screen Declaration”

Before
*--------------------------------------------------------------
--------*
*Input Screen/Selection
*--------------------------------------------------------------
--------*
SELECT-OPTIONS so_matkl FOR mara-matkl.
SELECT-OPTIONS so_matnr FOR mara-matnr.

161
After
*--------------------------------------------------------------
--------*
*Input Screen/Selection
*--------------------------------------------------------------
--------*
SELECTION-SCREEN BEGIN OF BLOCK groupbox1 WITH FRAME TITLE
text_101. "Declare Group Box 1

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_102 FOR FIELD so_matkl.
SELECT-OPTIONS so_matkl FOR mara-matkl.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_103 FOR FIELD so_matnr.
SELECT-OPTIONS so_matnr FOR mara-matnr.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK


groupbox1. "End Group Box 1

SELECTION-SCREEN BEGIN OF BLOCK groupbox2 WITH FRAME TITLE


text_201. "Declare Group Box 2

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) text_202 FOR FIELD p_mrow.
PARAMETERS p_mrow TYPE i DEFAULT 1000 LENGTH 5.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN END OF BLOCK


groupbox2. "End Group Box 2

 Create event and initialization code, write down the input Screen Block

*--------------------------------------------------------------
--------*
*EVENT
*--------------------------------------------------------------
--------*
AT SELECTION-SCREEN OUTPUT.
text_101 = 'Selection Parameter'.
text_102 = 'Material Group'.
text_103 = 'Material Number'.

text_201 = 'Page Setup'.


text_202 = 'Max. Row'.

*--------------------------------------------------------------
--------*
*INITIALIZATION
*--------------------------------------------------------------
--------*
INITIALIZATION.

 Modified “Main Program”

Before
*==============================================================
========*
*MAIN PROGRAM
*Execute after Input Screen

162
*==============================================================
========*
START-OF-SELECTION.
gv_width = 113.
PERFORM fm_collect_data.
PERFORM fm_process_data.
PERFORM fm_display_data.

END-OF-SELECTION.

After
*==============================================================
========*
*MAIN PROGRAM
*Execute after Input Screen
*==============================================================
========*
START-OF-SELECTION.
PERFORM fm_collect_data.
PERFORM fm_process_data.
PERFORM fm_display_data.
END-OF-SELECTION.

 Modification sub routine “fm_display_data”

Before
*&-------------------------------------------------------------
-------*
*& Form fm_display_data
*&-------------------------------------------------------------
-------*
* text
*--------------------------------------------------------------
-------*
FORM fm_display_data.
* Membuat Teks header
ULINE AT (gv_width). " Upper frame border
FORMAT COLOR COL_HEADING INTENSIFIED. " Title color
macro_data_possition : 'HEADER' 'Mat. Group' 'Mat. No.'
'Description' 'Old Mat. No.' 'Base Unit' 'Measure'.
WRITE: AT gv_width sy-vline. " Right border
ULINE AT (gv_width). " Line below titles
FORMAT COLOR OFF.

* Menampilkan Data ke Screen


LOOP AT gi_header.
macro_data_possition : 'CONTENT'
gi_header-matkl
gi_header-matnr
gi_header-maktx
gi_header-bismt
gi_header-meins
gi_header-mseht.
ENDLOOP.

* Akhir dari Line


ULINE AT (gv_width). " Line below last
data

ENDFORM. "fm_display_data

After

163
*&-------------------------------------------------------------
-------*
*& Form fm_display_data
*&-------------------------------------------------------------
-------*
* text
*--------------------------------------------------------------
-------*
FORM fm_display_data.
DATA: lv_fmname TYPE rs38l_fnam,
lw_options TYPE ssfcompop,
lw_control TYPE ssfctrlop,
lw_tdbool TYPE tdbool.

* Get Function Module name base on SmartForms name


lv_fmname = 'YFO_PRACTICE_101'.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = lv_fmname
IMPORTING
fm_name = lv_fmname
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.

* Set Properties of Printer


lw_tdbool = space.

lw_control-no_dialog = ''.
lw_control-preview = 'X'.

* lw_options-tddest = nast-ldest.
lw_options-tdimmed = 'X'.
lw_options-tddelete = 'X'.

* Call and Run SmartForms


CALL FUNCTION lv_fmname
EXPORTING
control_parameters = lw_control
output_options = lw_options
user_settings = lw_tdbool

gv_max_row = p_mrow "--User Define Form


Interface
TABLES
gi_header = gi_header "--User Define Form
Interface
gr_matkl = so_matkl "--User Define Form
Interface
gr_matnr = so_matnr "--User Define Form
Interface

EXCEPTIONS
formatting_error = 1
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.

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

164
ENDIF.

ENDFORM. "fm_display_data

 Activate the program and run program


 Making T-Code “YP501”
 Finished

 Create Report YPRACTICE_501 (Revisi)

REPORT ypractice_501 .

*----------------------------------------------------------------------*
* Tables
*----------------------------------------------------------------------*
TABLES : mara, makt, t006a.

*----------------------------------------------------------------------*
*GLOBAL VARIABLE DECRALATION
*----------------------------------------------------------------------*

TYPES: BEGIN OF ty_header,


matkl TYPE mara-matkl, " Material Group
matnr TYPE mara-matnr, " Material Number
maktx TYPE makt-maktx, " Material Description
bismt TYPE mara-bismt, " Old material number
meins TYPE mara-meins, " Base Unit of Measure
mseht TYPE t006a-mseht, " Unit of Measurement Text
END OF ty_header.

TYPES: BEGIN OF ty_mara,


matnr TYPE mara-matnr,
matkl TYPE mara-matkl,
bismt TYPE mara-bismt,
meins TYPE mara-meins,
END OF ty_mara.

TYPES: BEGIN OF ty_makt,


matnr TYPE mara-matnr,
maktx TYPE makt-maktx,
END OF ty_makt.

TYPES: BEGIN OF ty_t006a,


msehi TYPE t006a-msehi,
mseht TYPE t006a-mseht,
END OF ty_t006a.

DATA: gi_header TYPE STANDARD TABLE OF ty_header,


gi_mara TYPE STANDARD TABLE OF ty_mara,
gi_makt TYPE STANDARD TABLE OF ty_makt,
gi_t006a TYPE STANDARD TABLE OF ty_t006a,
yst_header_101 TYPE ty_header,
wa_mara TYPE ty_mara,
wa_makt TYPE ty_makt,
wa_t006a TYPE ty_t006a.
DATA: gv_width TYPE i. " Width of list

*----------------------------------------------------------------------*
*Input Screen/Selection
*----------------------------------------------------------------------*

SELECTION-SCREEN BEGIN OF BLOCK groupbox1 WITH FRAME TITLE txt_101.


SELECTION-SCREEN BEGIN OF LINE.

165
SELECTION-SCREEN COMMENT 1(18) txt_102 FOR FIELD so_matkl.
SELECT-OPTIONS so_matkl FOR mara-matkl.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.


SELECTION-SCREEN COMMENT 1(18) txt_103 FOR FIELD so_matnr.
SELECT-OPTIONS so_matnr FOR mara-matnr.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK groupbox1.

SELECTION-SCREEN BEGIN OF BLOCK groupbox2 WITH FRAME TITLE txt_201.


SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(18) txt_202 FOR FIELD p_mrow.
PARAMETERS p_mrow TYPE i DEFAULT 1000.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK groupbox2.

*----------------------------------------------------------------------*
*EVENT
*----------------------------------------------------------------------*

AT SELECTION-SCREEN OUTPUT.
txt_101 = 'Selection Parameter'.
txt_102 = 'Material Group'.
txt_103 = 'Material Number'.

txt_201 = 'Page Setup'.


txt_202 = 'Max Row'.

*----------------------------------------------------------------------*
*INITIALIZATION
*----------------------------------------------------------------------*

INITIALIZATION.

*======================================================================*
*MAIN PROGRAM
*Execute after Input Screen
*======================================================================*

START-OF-SELECTION.

PERFORM fm_collect_data.
PERFORM fm_process_data.
PERFORM fm_display_data.

END-OF-SELECTION.

*======================================================================*
*SUB PROGRAM / SUB ROUTINE
*======================================================================*

*&--------------------------------------------------------------------*
*& Form fm_collect_data
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*

FORM fm_collect_data.

* Collect Master Material

SELECT matnr
matkl
bismt
meins
INTO TABLE gi_mara

166
FROM mara
WHERE
matkl IN so_matkl AND
matnr IN so_matnr.

* "For SAP 4.6C


* DATA : lv_total_data type i.
* DESCRIBE TABLE gi_header LINES lv_total_data.
* IF LINES( lv_total_data ) > 0.

* IF LINES( gi_header ) > 0." For SAP 4.7 above


IF gi_mara[] IS NOT INITIAL.
* Collect Material Decription

SELECT matnr
maktx
INTO TABLE gi_makt
FROM makt
FOR ALL ENTRIES IN gi_mara
WHERE
matnr = gi_mara-matnr AND
spras = sy-langu.

* Collect Measurement Text

SELECT msehi
mseht
INTO TABLE gi_t006a
FROM t006a
FOR ALL ENTRIES IN gi_mara
WHERE
msehi = gi_mara-meins AND
spras = sy-langu.
ENDIF.

* Notes :
* Avoid using inner join

ENDFORM. "FM_COLLECT_DATA

*&--------------------------------------------------------------------*
*& Form FM_PROCESS_DATA
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*

FORM fm_process_data.

*Get other requirement information

SORT gi_makt BY matnr.


SORT gi_t006a BY msehi.
LOOP AT gi_mara INTO wa_mara.
IF sy-subrc = 0.

yst_header_101-matnr = wa_mara-matnr.
yst_header_101-matkl = wa_mara-matkl.
yst_header_101-bismt = wa_mara-bismt.
yst_header_101-meins = wa_mara-meins.

* Get Material Description

READ TABLE gi_makt INTO wa_makt WITH KEY matnr = wa_mara-matnr


BINARY SEARCH.
IF sy-subrc = 0.
yst_header_101-maktx = wa_makt-maktx.
ENDIF.

167
* Get Measurement Text

READ TABLE gi_t006a INTO wa_t006a WITH KEY msehi = wa_mara-meins


BINARY SEARCH.
IF sy-subrc = 0.
yst_header_101-mseht = wa_t006a-mseht.
ENDIF.
APPEND yst_header_101 TO gi_header.

ENDIF.
ENDLOOP.
ENDFORM. "FM_PROCESS_DATA

*&--------------------------------------------------------------------*
*& Form fm_display_data
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM fm_display_data.

DATA: lv_fmname TYPE rs38l_fnam,


lw_options TYPE ssfcompop,
lw_control TYPE ssfctrlop,
lw_tdbool TYPE tdbool.

* Get Function Module name base on SmartForms name

lv_fmname = 'YFO_PRACTICE_101'.
CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
EXPORTING
formname = lv_fmname
IMPORTING
fm_name = lv_fmname
EXCEPTIONS
no_form = 1
no_function_module = 2
OTHERS = 3.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

ENDIF.

* Set Properties of Printer

lw_tdbool = space.
lw_control-no_dialog = ''.
lw_control-preview = 'X'.

* lw_options-tddest = nast-ldest.

lw_options-tdimmed = 'X'.
lw_options-tddelete = 'X'.

* Call and Run SmartForms

CALL FUNCTION lv_fmname


EXPORTING
control_parameters = lw_control
output_options = lw_options
user_settings = lw_tdbool
gv_max_row = p_mrow "--User Define Form Interface
TABLES
gi_header = gi_header "--User Define Form Interface
gr_matkl = so_matkl "--User Define Form Interface
gr_matnr = so_matnr "--User Define Form Interface
EXCEPTIONS
formatting_error = 1

168
internal_error = 2
send_error = 3
user_canceled = 4
OTHERS = 5.

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

169

You might also like