Está en la página 1de 124

What is SAP and

why SAP ?
+SAP Software is a ERP( Enterprise
Resource Planing) solution, through
which large and medium scale companies
can manage their business.SAP Software is
produced by a German based company SAP.
SAP Company: SAP Company founded in
1972 in Germany by five former employes
of IBM and they released standard versions
called R1 and R2 in early days, and they
released 3-tier architecture R3 in 1990`s
which was very successful.
In 2000 SAP released ECC (Enterprise Core
Component), latest version in market is ECC
6.0 and they are adding additions to this in
the form of enhancement packs.

Why SAP?
Through SAP software a company can plan
their business in different aspects like
Supply Chain Solutions, Material
Management, Sales and Distribution,
Finance controlling, Human Resource
planing, etc.
The total SAP Software is built using ABAP
Programing Language, which is a standard
programing language developed by SAP it
self, we call ABAP as 4th Generation
Programing Language (ABAP/4)
Some of Modules in SAP are :
SAP FI module: FI stands for Financial
Accounting.
SAP CO module: CO stands for
Controlling.

SAP CRM module: CRM stands for


Customer Relationship Management.
SAP CS module: CS stands for Customer
Service.
SAP EC module: EC stands for Enterprise
Controlling.
SAP EHS module: EHS stands for
Environment, Health and Safety.
SAP FM module: FM stands for Fleet
Management.
SAP FSCM module: FSCM stands for
Financial Supply Chain Management.
SAP HR module: HR stands for Human
Resources.
SAP IM module: IM stands for
Investment Management.

SAP MM module: MM stands for


Materials Management .
SAP PLM module: PLM stands for
Product Life Cycle Management.
SAP PM module: PM stands for Plant
Maintenance.
SAP PP module: PP stands for
Production Planning.
SAP Product Costing: Product Costing
deals with Plan Costing Actual Costing of
Finish products.
SAP PS module: PS stands for Project
Systems.
SAP QM module: QM stands for Quality
Management.
SAP RE module: RE stands for Real
Estate.

SAP SD module: SD stands for Sales and


Distribution.
SAP SM module: SM stands for Service
Management.
SAP TR module: TR stands for Treasury.
SAP WM module: WM stands for
Warehouse Management.
SAP LO module: LO stands for Logistics
General.
SAP ABAP module: ABAP stands for
Advanced Business Application
Programming.
SAP Basis module: Basis also known as
Basis Admin is typically the
administration of SAP.
SAP BI module: BI stands for Business
Intelligence.

SAP BPC module: BPC stands for


Business Planning and Consolidation.
SAP BODI module: BODI stands for
Business Objects Data Integrator.
SAP EP module: EP stands for Enterprise
Portal.
SAP GRC module: GRC stands for Group
Risk Compliance.
SAP MDM module: MDM stands for
Master Data Management.
SAP Netweaver module: Netweaver
provides technical foundation for SAP
applications.
SAP Security module: Security ensures
security of enterprise operations.
SAP Solution Manager module:
Solution Manager facilitates technical
support for distributed systems.

SAP XI module: SAP Exchange


Infrastructure (SAP XI) enables you to
implement cross-system processes on
services.
SAP PI module: SAP Process Integration
(SAP PI) is enterprise application
integration (EAI)software.

SAP Consultants
+SAP is a huge software and in order to
implement SAP ERP for a Organization, it
needs lot of man power, the SAP
implementation is done by different type of
consultants .

Types of consultants are


Function
al

Technical

Network

Consulta

Consultan

Administrat

nts

ts

ors

Functional
consultants are
responsible for
configuring the real
world business
scenarios into SAP
software .
Ex: Configurations
like Plants
Configurations,
Business Countries
Configurations,
Sales Organizations
configuration etc

Technical consultants
are responsible for
coustomizing SAP
ABAP software as per
customer
specifications i:e
Developing New SAP
Business Applications,
Enhansing SAP
Software, Creating
SAP Tables etc

Network Administrators are


Basis Consultants, they are
responsible for Network
management and Network
related SAP configurations
like server maintenance,
managing network down
times, controlling network,
user management etc

ABAP Consultant
Roles and
Responsibilities
+SAP ABAP Consultants are responsible for
developing SAP business applications using
SAP Standard programming language ABAP,
the main roles and responsibilities of SAP
ABAP Consultant are...
SAP ABAP Consultants plays crucial role
in implementation of SAP software for a
organization .
Total SAP software is developed using
ABAP, ABAP consultants are needed in
every SAP module.

Implementation Process

Getting the business Requirement document from functional consultant / functional analyst .

Analyse the business Requirement.

Analyse the estimated time for development.

Development of Object ( ABAP application).

Unit Testing by Developer .

Releasing the object to testing environment .

Prepare technical document of the development .

Note: ABAP Consultant roles and


responsibilities may vary from company to
company, the above are standard roles of
ABAP consultants

Ticket system in
support projects
SAP ABAP
Consultants
+Handling tickets is called Issue Tracking
system. The errors or bugs forwarded by
the end user to the support team are
prioritized under three priorities High,
Medium and Low. Each and every priority as
got its time limits before that we have to fix
the error.
The main job of the supporting consultant is
to provide assistance on line to the
customer or the organization where SAP is
already implemented for which the person
should be very strong in the subject and the
process which are implemented in SAP at

the client side to understand,to analyses,to


actuate and to give the right solution in
right time.This is the job of the support
consultant.
The issues or the tickets(problems) which
are raised is taken care of on priority basis
by the support team consultants.
The work process in support projects
are given below for your reference. >
1. The customer or the end user logs a call
through any tool or by mail (RADIX).
2. Each one of the support team is a part of
support group.
3. Whenever a customer logs a call he /she
has to mention to which work group (by
name).
4. Once the calls came to the work group
the support consultant or the team need to

send an IR (Initial Response) to the user


depending upon the priority of the calls.
(Top,High,Med,Low,None)
5. Then the error is fixed, debugged by the
support consultant or the team. Then after
testing properly by generating TR(Transport
Request through the basis admin)
6. Then it is informed to the end
user/customer/super user about the
changes which have moved to the
production server by CTS process.
These are the process. In summary, what I
understand is that if any configuration or
customization is required to solve the issue,
then the consultant have to work on DEV
Client, then the end user will test it in the
QA client and after approval the BASIS
consultant has to transport it to the
PRODUCTION client.

An example: Tickets in SD can be


considered as the problems which the end
user or the employee in the company face
while working on R/3. Tickets usually occur
during the implementation or after the
implementation of the project. There can be
numerous problem which can occur in the
production support and a person who is
working in the support has to resolve those
tickets in the limited duration, every ticket
has the particular deadline alert so your
responsibility is to finish it before that
deadline.
To begin with , we should give "TICKET" to
you for not knowing it.
Here is an eg of a ticket raise:
End user is not able to
1. Create Sales order for a customer from a
New plant , since shipping point
determination is not happened . ( Without

Shipping point the document becomes


INCOMPLETE and he will not be able to
proceed further like DELIVERY, BILLING).
He raises a ticket and the priority is set in
one of the below:
1. Low 2. Medium 3. High.
Now you need to solve this ticket. You
would analyze the problem and identify that
the SP configuration has to be done for the
new plant.
You would request a transport for DEV
CLIENT to BASIS. You do the change and
Request one more Transport to BASIS for QA
client. The End user will test the same by
creating a sales order for the new plant and
approve it.
Finally, you request a transport to move the
changes to PRODUCTION. Once the change
is deployed in production the TICKET is

closed. What I have given is a small


example. You would get some real issues
with severity HIGH in your day-day support.

SAP System
landscape
+SAP System landscape is the group of
systems you have installed, all the systems
are linked to different transport routs to
main system, system landscape may vary
from company to company or business to
business, SAP recommended landscape is
explained below.

What happens at system levels in


SAP project implementation ?
All SAP custom object developments and
enhancements will be done in
development system.

Testing and different quality checks will


be done in quality assurance system.
After testing, the objects will be moved
to main production system .
All these systems are connected using
Transport System.
All systems are divided into different
clients depends on business
requirement.

What is client concept in SAP ?


Client is a concept of protecting data in SAP
from accessing from outside a legal entity.
SAP systems are divided into different
clients depending on business requirement,
the data can be accesses within the client
only.
Ex: Client 200, 300 etc.

DEV
Development system, where all custom
developments, enhancements and
configurations will be done. Once
development is completed the objects will
be moved to testing system (QAS).It may
have more than one client that is one for
development and one is for configurations.

QAS
Quality Assurance System where all the
developed objects will be tested with
different test cases.

PRD
This is alive business system, where
business users will be using the objects with
real-time data, this is where the developed

objects will be integrated and used for


business purposes .

SAP Range Table


April 23, 2014 ABAP Leave a comment
Tagged: dictionary, range table, report, select option

SAP Range Table represents complex selection


criteria, its data structures is exactly like
select-option but without any UI part and
header line. In this blog I will explain how to
define range table type in program and in
dictionary
for
global
use.
First little bit more about range table. When
you define a select-option on selection screen
you automatically get range table which is
attached with that select option. However, if
you want to define range table without having
to define select option than you need to either
define local or global range type. Also you need
some mechanism of defining work area so that
you can perform usual operation on range
table. Range table have four columns SIGN,
OPTION, LOW and HIGH.
Column

Data Type

SIGN CHAR length 1


OPTIO CHAR length 2
N

Possible Value
I include
E exclude
EQ Equal
NE Not Equal
GE Greater Than or Equal

GT Greater Than
LE Less Than or Equal
LT Less Than
CP Contains Pattern
NP LOW Data type of selection field
Data value. Can also contain wildcards
Data type of selection field, same Data value in case of range criteria. Can also
HIGH
as LOW
contain wildcards

ALV Report with


Structure
+Requirement: Develop a ALV report to
display material details with all fields from
MARA table for a material range
input(Select-Options input).
In this requirement we have to display all
fields from MARA (Material master table) in
ALV format. We
use REUSE_ALV_GRID_DISPLAY Function
module to display ALV report.

Steps to create ALV Report with


Structure .
Step1: Declare Internal table for MARA
table.

Step2: Print Select-Options.


Step3: Get data from database using select
statements.
Step4: Call Function
Module REUSE_ALV_GRID_DISPLAY and pass
structure name, program name and itab
name.
TABLES : MARA. "DECLARE TABLE FOR SELECTOPTIONS
DATA : IT_MARA TYPE TABLE OF MARA.
"DECLARE INTERNAL TABLE FOR MARA
DATA : WA_MARA TYPE MARA.
SELECT-OPTIONS: S_MATNR FOR MARA-MATNR.
"PRINT SELECT-OPTIONS FOR MATNR
START-OF-SELECTION.
SELECT * FROM MARA INTO TABLE IT_MARA
WHERE MATNR IN S_MATNR .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


"CALL FUNCTION MODULE TO DISPLAY ALV
GRID
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID "SY-REPID
IS A SYSTEM VARIABLE WHICH STORES
CURRENT PROGRAM NAME
I_STRUCTURE_NAME = 'MARA'
TABLES
T_OUTTAB = IT_MARA. "PASS INTERNAL TABLE
TO DISPLAY ALV FORMAT

The above report after modularization

The below one is full report after


using modularization techniques.
*&--------------------------------------------------------------------*
*& Report ZALV_STR
*&

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

REPORT ZALV_STR.
TABLES: MARA.
DATA : IT_MARA TYPE TABLE OF MARA .

SELECT-OPTIONS : S_MATNR FOR MARA-MATNR.

START-OF-SELECTION .
PERFORM GET_MARA_DATA . "Double click to
create below form

END-OF-SELECTION .
PERFORM DISP_MARA_ALV . "Double click to
create below form

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

Form GET_MARA_DATA

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

text

*---------------------------------------------------------------------*
* --> p1

text

* <-- p2

text

*---------------------------------------------------------------------*
FORM GET_MARA_DATA .
SELECT * FROM MARA
INTO TABLE IT_MARA
WHERE MATNR IN S_MATNR
.

ENDFORM.

" GET__MARA_DATA

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

Form DISP_MARA_ALV

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

text

*---------------------------------------------------------------------*
* --> p1

text

* <-- p2

text

*---------------------------------------------------------------------*
FORM DISP_MARA_ALV .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
I_STRUCTURE_NAME = 'MARA'

TABLES
T_OUTTAB

ENDFORM.

= IT_MARA.

" DISP_MARA_ALV

ALV Report with


Field Catelogue
+-

Field Catalog
Field catalog is an internal table which is
used to pass list of fields to display in ALV
report, we can set different properties to
fields which are going to display in ALV.

Type Group
It is a data dictionary objects which
contains all the reusable user-defined types.
Example for a type group is SLIS, which
contains all the user-defined types for
developing ALV reports.

TYPE-POOLS is a keyword which is used to

assign the type-group to a ALV report .


Syntax :
TYPE-POOLS SLIS . "TO USE FIELD CATALOG WE
HAVE TO INCLUDE SLIS TYPE-POOLS
DATA : <IT_FCAT> TYPE SLIS_T_FIELDCAT_ALV .
"INTERNAL TABLE FOR FIELD CATALOG
DATA : <WA_FCAT> TYPE SLIS_FIELDCAT_ALV .
" WORK AREA FOR FIELD CATLOG

Options/properties of field catalog.


WA_FCAT-COL_POS = '1' . "Specify position of
a field
WA_FCAT-FIELDNAME = 'MATNR' . "Specify
field name
WA_FCAT-TABNAME = 'IT_MARA' . "Specify
internal table name
WA_FCAT-SELTEXT_M = 'MATERIALNO' .
"Specify text to display column header

WA_FCAT-KEY = 'X' . "Specify if it is a key field


APPEND WA_FCAT TO IT_FCAT . "Append to
field catalog internal table

Useful resourse Using append in SAP


ABAP and also Using Clear in SAP ABAP
Requirement: Develop a ALV report to
display Material no(MATNR), Material
type(MTART), Industry Sector(MBRSH) and
Basic Unit Of measure(MEINS) for a range of
material input (Select-Options).
To develop above report we have to use
field catalog (because we have to display
four fields only from MARA) and we have to
pass foeld catalog parameter to Function
ModuleREUSE_ALV_GIRD_DISPLAY.
REPORT ZSAPN_ALV_FCAT.
TABLES : MARA.

TYPE-POOLS SLIS .

TYPES : BEGIN OF TY_MARA, "User defined


internal table type
MATNR TYPE MARA-MATNR,
MTART TYPE MARA-MTART,
MBRSH TYPE MARA-MBRSH,
MEINS TYPE MARA-MEINS,
END OF TY_MARA.

DATA : IT_MARA TYPE TABLE OF TY_MARA .


DATA : WA_MARA TYPE TY_MARA .

DATA : IT_FCAT TYPE SLIS_T_FIELDCAT_ALV .


DATA : WA_FCAT LIKE LINE OF IT_FCAT .
SELECT-OPTIONS: S_MATNR FOR MARA-MATNR.

START-OF-SELECTION .
PERFORM GET_DATA .
PERFORM CREATE_FCAT.

END-OF-SELECTION .
PERFORM DISP_ALV .

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

Form GET_DATA

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

text

*---------------------------------------------------------------------*
* --> p1

text

* <-- p2

text

*---------------------------------------------------------------------*
FORM GET_DATA .
SELECT MATNR MTART MBRSH MEINS FROM
MARA
INTO TABLE IT_MARA
WHERE MATNR IN S_MATNR.
.
ENDFORM.

" GET_DATA

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

Form DISP_ALV

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

text

*---------------------------------------------------------------------*
* --> p1

text

* <-- p2

text

*---------------------------------------------------------------------*
FORM DISP_ALV .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IT_FIELDCAT
CATALOG TO ALV

= IT_FCAT "PASS FIELD

TABLES
T_OUTTAB

ENDFORM.

= IT_MARA.

" DISP_ALV

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

Form CREATE_FCAT

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

text

*---------------------------------------------------------------------*
* --> p1

text

* <-- p2

text

*---------------------------------------------------------------------*
FORM CREATE_FCAT .
WA_FCAT-COL_POS = '1' .
WA_FCAT-FIELDNAME = 'MATNR' .
WA_FCAT-TABNAME = 'IT_MARA' .
WA_FCAT-SELTEXT_M = 'MATERIALNO' .
WA_FCAT-KEY = 'X' .
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_FCAT .

WA_FCAT-COL_POS = '2' .
WA_FCAT-FIELDNAME = 'MTART' .
WA_FCAT-TABNAME = 'IT_MARA' .
WA_FCAT-SELTEXT_M = 'MATERIALTYPE' .
* WA_FCAT-NO_OUT = 'X' .
WA_FCAT-HOTSPOT = 'X' .
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_FCAT .

WA_FCAT-COL_POS = '3' .
WA_FCAT-FIELDNAME = 'MBRSH' .
WA_FCAT-REF_FIELDNAME = 'MBRSH' .
WA_FCAT-REF_TABNAME = 'MARA' .
* WA_FCAT-TABNAME = 'IT_MARA' .
* WA_FCAT-SELTEXT_M = 'INDSECTOR' .

* WA_FCAT-EDIT = 'X' .
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_FCAT .

WA_FCAT-COL_POS = '4' .
WA_FCAT-FIELDNAME = 'MEINS' .
WA_FCAT-TABNAME = 'IT_MARA' .
WA_FCAT-SELTEXT_M = 'MAT.UNITS' .
WA_FCAT-EMPHASIZE = 'C610'.
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_FCAT .

ENDFORM.

" CREATE_FCAT

Field Catalog Merge Not Recommanded

Field Catalog can be generated in

two ways one is manual with field


catalog internal table and another
one is with automatic field catalog
generation...like below one but
this one uses old syntax, this one
is obsolete and is not
recommended.
*&--------------------------------------------------------------------*
*& Report ZALV_WITH_FCAT
*&
*&--------------------------------------------------------------------*
*&
*&
*&--------------------------------------------------------------------*

REPORT ZALV_WITH_FCAT_MERGE.

TYPE-POOLS SLIS .

DATA : BEGIN OF I_MARA OCCURS 0,


MATNR LIKE MARA-MATNR,
MTART LIKE MARA-MTART,
MBRSH LIKE MARA-MBRSH,
MEINS LIKE MARA-MEINS,
END OF I_MARA.

DATA : I_FCAT TYPE SLIS_T_FIELDCAT_ALV .


DATA : WA_FCAT LIKE LINE OF I_FCAT .

START-OF-SELECTION .
PERFORM GET_DATA .
PERFORM CREATE_FCAT_MERGE .

END-OF-SELECTION .
PERFORM DISP_ALV .

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

Form GET_DATA

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

text

*---------------------------------------------------------------------*
* --> p1

text

* <-- p2

text

*---------------------------------------------------------------------*
FORM GET_DATA .
SELECT * FROM MARA
INTO CORRESPONDING FIELDS OF TABLE
I_MARA
.
ENDFORM.

" GET_DATA

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

Form DISP_ALV

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

text

*---------------------------------------------------------------------*
* --> p1

text

* <-- p2

text

*---------------------------------------------------------------------*
FORM DISP_ALV .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IT_FIELDCAT

= I_FCAT

TABLES
T_OUTTAB

ENDFORM.

= I_MARA.

" DISP_ALV

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

Form CREATE_FCAT_MERGE

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

text

*---------------------------------------------------------------------*
* --> p1

text

* <-- p2

text

*---------------------------------------------------------------------*
FORM CREATE_FCAT_MERGE .
CALL FUNCTION
'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
I_PROGRAM_NAME

= SY-REPID

I_INTERNAL_TABNAME = 'I_MARA'
I_INCLNAME

= SY-REPID

CHANGING
CT_FIELDCAT
ENDFORM.

= I_FCAT.
" CREATE_FCAT_MERGE

ALV Report with


layout
+-

Layout:
Layout is a structure which is used to
decorate or embellish the out put of ALV
Report.
Requirement: Display list of materials for
a material type, with all fields of out put are
editable, no horizontal and vertical lines
and hotspot on material no.
Input Screen

Out put Screen (all rows are editable and


hotspot on material no)

Please follow previous lesson steps


to create a fieldcatlog in ALV, in addition to
that we will be adding additional properties
hotspot, editable to out put fields using
layout options.
The below is the code to add layout to ALV.
DATA : WA_LAYOUT TYPE SLIS_LAYOUT_ALV .
WA_LAYOUT-ZEBRA = 'X' .
WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X' .
WA_LAYOUT-EDIT = 'X' .
WA_LAYOUT-NO_VLINE = 'X' .
WA_LAYOUT-NO_HLINE = 'X' .

We will supply remaining options through


fieldcatlog also.

Full referance code for using


layout in ALV
REPORT ZSAPN_ALV_LAYOUT.
TYPE-POOLS : SLIS .
*DATA DECLARAATIONS
DATA : I_MARA TYPE TABLE OF MARA .
DATA : WA_MARA TYPE MARA .
*ALV DECLARATIONS
DATA : I_FCAT TYPE SLIS_T_FIELDCAT_ALV .
DATA : WA_FCAT TYPE SLIS_FIELDCAT_ALV .
DATA : V_POS TYPE I .
DATA : WA_LAYOUT TYPE SLIS_LAYOUT_ALV .
PARAMETERS : P_MTART TYPE MARA-MTART.

START-OF-SELECTION .
PERFORM GET_DATA .

PERFORM CREATE_FCAT .
PERFORM CREATE_LAYOUT.
PERFORM DISPLAY_DATA .
END-OF-SELECTION .
FORM GET_DATA .

SELECT * FROM MARA


INTO TABLE I_MARA
UP TO 100 ROWS WHERE MTART =
P_MTART .
ENDFORM.

" GET_DATA

FORM DISPLAY_DATA .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
I_CALLBACK_PROGRAM = SY-REPID
IS_LAYOUT

= WA_LAYOUT

IT_FIELDCAT

= I_FCAT

TABLES
T_OUTTAB
ENDFORM.

= I_MARA.
" DISPLAY_DATA

FORM DISPLAY_DATA_LIST .
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_STRUCTURE_NAME = 'MARA'
TABLES
T_OUTTAB

= I_MARA.

IF SY-SUBRC NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY
NUMBER SY-MSGNO
*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3
SY-MSGV4.
ENDIF.

ENDFORM.

" DISPLAY_DATA_LIST

FORM CREATE_FCAT .
V_POS = 1 .
WA_FCAT-COL_POS = V_POS.
WA_FCAT-FIELDNAME = 'MATNR' .
WA_FCAT-SELTEXT_M = 'Material.NO' .
WA_FCAT-HOTSPOT = 'X' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .

V_POS = V_POS 1.
WA_FCAT-COL_POS = V_POS .
WA_FCAT-FIELDNAME = 'MTART' .
WA_FCAT-SELTEXT_M = 'Material.Type' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .

V_POS = V_POS 1.
WA_FCAT-COL_POS = V_POS .
WA_FCAT-FIELDNAME = 'MBRSH' .
WA_FCAT-SELTEXT_M = 'Ind.Sector' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .

V_POS = V_POS 1.
WA_FCAT-COL_POS = V_POS .
WA_FCAT-FIELDNAME = 'MATKL' .
WA_FCAT-SELTEXT_M = 'Mat.Grp' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .

V_POS = V_POS 1.
WA_FCAT-COL_POS = V_POS .
WA_FCAT-FIELDNAME = 'MEINS' .
WA_FCAT-SELTEXT_M = 'Units' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .

ENDFORM.

" CREATE_FCAT

FORM CREATE_LAYOUT .
WA_LAYOUT-ZEBRA = 'X' .
WA_LAYOUT-COLWIDTH_OPTIMIZE = 'X' .
WA_LAYOUT-EDIT = 'X' .
WA_LAYOUT-NO_VLINE = 'X' .
WA_LAYOUT-NO_HLINE = 'X' .

ENDFORM.

" CREATE_LAYOUT

ALV with totals and


sub totals in SAP
ABAP
+To calculate totals and sub-totals in ALV we
need to sort table in ascending order and
we need to set SUBTOT = 'X' of SORT in
ALV.

Layout:
Layout is a structure which is used to
decorate or embellish the out put of ALV
Report.
Requirement: Display list of sales order
for sales order range with totals and
subtotals of price

Input screen

Output screen (with totals and subtotals).

Please follow previous lesson steps


to create a fieldcatlog in ALV, in addition to
that we will be adding additional properties
hotspot, editable to out put fields using
layout options.
The below code is used to display totals and
subtotals in ALV.

DATA : I_SORT TYPE SLIS_T_SORTINFO_ALV .


DATA : WA_SORT LIKE LINE OF I_SORT .
WA_SORT-FIELDNAME = 'VBELN '.
WA_SORT-UP = 'X'.
WA_SORT-SUBTOT = 'X '.

APPEND WA_SORT TO I_SORT .

Full referance code for displaying


totals and subtotals in ALV
REPORT ZALV_WITH_TOTALS_SUBTOT.
TYPE-POOLS SLIS .
tables : vbap.
TYPES : BEGIN OF TY_VBAP,
VBELN TYPE VBAP-VBELN,
POSNR TYPE VBAP-POSNR,
MATNR TYPE VBAP-MATNR,

NETWR TYPE VBAP-NETWR,


END OF TY_VBAP.
DATA : I_VBAP TYPE TABLE OF TY_VBAP .
DATA : WA_VBAP TYPE TY_VBAP .

DATA : I_FCAT TYPE SLIS_T_FIELDCAT_ALV .


DATA : WA_FCAT LIKE LINE OF I_FCAT .
DATA : I_SORT TYPE SLIS_T_SORTINFO_ALV .
DATA : WA_SORT LIKE LINE OF I_SORT .
select-options : s_vbeln for vbap-vbeln.
START-OF-SELECTION .
PERFORM GET_DATA .
PERFORM CREATE_FCAT.
PERFORM CALC_SUBTOT.

END-OF-SELECTION .

PERFORM DISP_ALV .
FORM GET_DATA .
SELECT VBELN POSNR MATNR NETWR FROM
VBAP
INTO TABLE I_VBAP where vbeln in s_vbeln
.
ENDFORM.

" GET_DATA

FORM DISP_ALV .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK

=''

* I_BYPASSING_BUFFER

=''

* I_BUFFER_ACTIVE

=''

I_CALLBACK_PROGRAM
* I_CALLBACK_PF_STATUS_SET
* I_CALLBACK_USER_COMMAND
* I_CALLBACK_TOP_OF_PAGE

= SY-REPID
=''
=''
=''

* I_CALLBACK_HTML_TOP_OF_PAGE
* I_CALLBACK_HTML_END_OF_LIST
* I_STRUCTURE_NAME

* I_BACKGROUND_ID

=''

* I_GRID_TITLE

* I_GRID_SETTINGS
* IS_LAYOUT

=
=

IT_FIELDCAT

= I_FCAT

* IT_EXCLUDING

* IT_SPECIAL_GROUPS
IT_SORT
* IT_FILTER
* IS_SEL_HIDE
* I_DEFAULT
* I_SAVE
* IS_VARIANT

=
= I_SORT
=
=
= 'X'
=''
=

=''
=''

* IT_EVENTS

* IT_EVENT_EXIT
* IS_PRINT

=
=

* IS_REPREP_ID

* I_SCREEN_START_COLUMN

=0

* I_SCREEN_START_LINE

=0

* I_SCREEN_END_COLUMN

=0

* I_SCREEN_END_LINE

=0

* I_HTML_HEIGHT_TOP

=0

* I_HTML_HEIGHT_END

=0

* IT_ALV_GRAPHICS
* IT_HYPERLINK

=
=

* IT_ADD_FIELDCAT

* IT_EXCEPT_QINFO

* IR_SALV_FULLSCREEN_ADAPTER
* IMPORTING

* E_EXIT_CAUSED_BY_CALLER

* ES_EXIT_CAUSED_BY_USER

TABLES
T_OUTTAB

= I_VBAP

* EXCEPTIONS
* PROGRAM_ERROR
* OTHERS

=1
=2

.
IF SY-SUBRC NE 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY
NUMBER SY-MSGNO
*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3
SY-MSGV4.
ENDIF.

ENDFORM.

" DISP_ALV

FORM CREATE_FCAT .
WA_FCAT-COL_POS = '1' .
WA_FCAT-FIELDNAME = 'VBELN' .
WA_FCAT-TABNAME = 'I_VBAP' .
WA_FCAT-SELTEXT_M = 'SDNO' .
WA_FCAT-KEY = 'X' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .

WA_FCAT-COL_POS = '2' .
WA_FCAT-FIELDNAME = 'POSNR' .
WA_FCAT-TABNAME = 'I_VBAP' .
WA_FCAT-SELTEXT_M = 'ITEMNO' .
* WA_FCAT-NO_OUT = 'X' .
WA_FCAT-HOTSPOT = 'X' .

APPEND WA_FCAT TO I_FCAT .


CLEAR WA_FCAT .

WA_FCAT-COL_POS = '3' .
WA_FCAT-FIELDNAME = 'MATNR' .
WA_FCAT-TABNAME = 'I_VBAP' .
WA_FCAT-SELTEXT_M = 'MATERIALNO' .
* WA_FCAT-EDIT = 'X' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .

WA_FCAT-COL_POS = '4' .
WA_FCAT-FIELDNAME = 'NETWR' .
WA_FCAT-TABNAME = 'I_VBAP' .
WA_FCAT-SELTEXT_M = 'NETPRICE' .
WA_FCAT-EMPHASIZE = 'C610'.

WA_FCAT-DO_SUM = 'X' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .

ENDFORM.

" CREATE_FCAT

FORM CALC_SUBTOT .
WA_SORT-FIELDNAME = 'VBELN '.
WA_SORT-UP = 'X'.
WA_SORT-SUBTOT = 'X '.
APPEND WA_SORT TO I_SORT .
ENDFORM.

" CALC_SUBTOT

Events in ALV
reports
+There are total 17 events available for ALV
reporting, by using this events we can
display report headers, report footers, user
command, pf status etc.
We use REUSE_ALV_EVENTS_GET function
module to get events and use in our report.
Steps for implementing events.
STEP1: Call the function module
REUSE_ALV_EVENTS_GET and get all
the events into a Internal Table(I_EVENTS).
STEP2: For each EVENT we need to provide
a Sub-Routine name. So Read the EVENT
from Internal Table into WorkArea and
provide the Sub-Routine name.

STEP3: Finally , define the Sub-Routine and


write logic.
Event definition Syntax.
*Get events using function module
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
* EXPORTING
* I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = I_EVENTS .
*add perform name to a event
READ TABLE I_EVENTS INTO WA_EVENTS WITH
KEY NAME = <EVENT NAME>' .
WA_EVENTS-FORM = '<FORM_XXX>' .
MODIFY I_EVENTS FROM WA_EVENTS INDEX SYTABIX .
*<EVENT NAME> = name of the event

*<FORM_XXX> is perform name to implement


for particular event

Event implementation in perform


FORM <FORM_XXX>.

** Add functionality for event


ENDFORM.

sing Top of page and


end of list IN ALV
reports
+ Call the function module
REUSE_ALV_EVENTS_GET.
Provide the sub routine name for top-ofpage event.
Implement the subroutine to display top
of page .
Call the function module
REUSE_ALV_COMMENTARY_WRITE to
display top-of-page in ALV
Finally export the events into internal
table to the REUSE_ALV_GRID_DISPLAY.

REPORT ZALV_MATERIAL_TOP_OF_PAGE.
TYPE-POOLS : SLIS .
*DATA DECLARAATIONS
DATA : I_MARA TYPE TABLE OF MARA .
DATA : WA_MARA TYPE MARA .
*ALV DECLARATIONS
DATA : I_FCAT TYPE SLIS_T_FIELDCAT_ALV .
DATA : WA_FCAT TYPE SLIS_FIELDCAT_ALV .
DATA : V_POS TYPE I .
DATA : I_EVENTS TYPE SLIS_T_EVENT .
DATA : WA_EVENTS LIKE LINE OF I_EVENTS .
DATA : I_HEADING TYPE SLIS_T_LISTHEADER .
DATA : WA_HEADING LIKE LINE OF I_HEADING .

START-OF-SELECTION .
PERFORM GET_DATA .

PERFORM CREATE_FCAT .
PERFORM GET_EVENTS .
PERFORM DISPLAY_DATA .

END-OF-SELECTION .

FORM GET_DATA .
SELECT * FROM MARA
INTO TABLE I_MARA
UP TO 100 ROWS .
ENDFORM.

" GET_DATA

FORM DISPLAY_DATA .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
I_CALLBACK_PROGRAM = SY-REPID

IT_FIELDCAT

= I_FCAT

IT_EVENTS

= I_EVENTS

TABLES
T_OUTTAB

= I_MARA.

ENDFORM.

" DISPLAY_DATA

FORM CREATE_FCAT .
V_POS = 1 .
WA_FCAT-COL_POS = V_POS.
WA_FCAT-FIELDNAME = 'MATNR' .
WA_FCAT-SELTEXT_M = 'Material.NO' .
WA_FCAT-HOTSPOT = 'X' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .

V_POS = V_POS 1.

WA_FCAT-COL_POS = V_POS .
WA_FCAT-FIELDNAME = 'MTART' .
WA_FCAT-SELTEXT_M = 'Material.Type' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .

V_POS = V_POS 1.
WA_FCAT-COL_POS = V_POS .
WA_FCAT-FIELDNAME = 'MBRSH' .
WA_FCAT-SELTEXT_M = 'Ind.Sector' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .

V_POS = V_POS 1.

WA_FCAT-COL_POS = V_POS .
WA_FCAT-FIELDNAME = 'MATKL' .
WA_FCAT-SELTEXT_M = 'Mat.Grp' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .

V_POS = V_POS 1.
WA_FCAT-COL_POS = V_POS .
WA_FCAT-FIELDNAME = 'MEINS' .
WA_FCAT-SELTEXT_M = 'Units' .
APPEND WA_FCAT TO I_FCAT .
CLEAR WA_FCAT .

ENDFORM.
FORM GET_EVENTS .

" CREATE_FCAT

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'


* EXPORTING
* I_LIST_TYPE

=0

IMPORTING
ET_EVENTS

= I_EVENTS .

READ TABLE I_EVENTS INTO WA_EVENTS WITH


KEY NAME = 'TOP_OF_PAGE' .
WA_EVENTS-FORM = 'FORM_TOP_OF_PAGE' .
MODIFY I_EVENTS FROM WA_EVENTS INDEX
SY-TABIX .

***********END OF LIST
READ TABLE I_EVENTS INTO WA_EVENTS WITH
KEY NAME = 'END_OF_LIST' .
WA_EVENTS-FORM = 'FORM_END_OF_LIST' .

MODIFY I_EVENTS FROM WA_EVENTS INDEX


SY-TABIX .
ENDFORM.

" GET_EVENTS

FORM FORM_TOP_OF_PAGE .
WA_HEADING-TYP = 'H' .
* WA_HEADING-KEY = 'H' .
WA_HEADING-INFO = 'MATERIAL MASTER
REPORT' .
APPEND WA_HEADING TO I_HEADING .

WA_HEADING-TYP = 'S' .
WA_HEADING-KEY = 'USERNAME' .
WA_HEADING-INFO = SY-UNAME .
APPEND WA_HEADING TO I_HEADING .

WA_HEADING-TYP = 'A' .

WA_HEADING-KEY = 'DATE' .
WA_HEADING-INFO = SY-DATUM .
APPEND WA_HEADING TO I_HEADING .

CALL FUNCTION
'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY
*

I_LOGO

I_END_OF_LIST_GRID

I_ALV_FORM

= I_HEADING

=
=
=

ENDFORM .

"FORM_TOP_OF_PAGE

FORM FORM_END_OF_LIST .

REFRESH I_HEADING .
CLEAR WA_HEADING .

WA_HEADING-TYP = 'S' .
WA_HEADING-INFO = 'IBM INDIA PVT.LTD' .
APPEND WA_HEADING TO I_HEADING .

CALL FUNCTION
'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
IT_LIST_COMMENTARY
I_END_OF_LIST_GRID

= I_HEADING
= 'X'

.
ENDFORM .

"FORM_END_OF_LIST

ALV Blocked List


Display
+Requirement: Develop a blocked list ALV to
display list of materials for a material type
and also display material descriptions in
another grid.
Analysis: For this requirement, we need to
add one input parameter for material type,
we need to get materials from MARA, and
from MAKT and display in two list ALV`s
using ALV blocked display.
Blocked list ALV is used to display multiple
ALV`s on the same screen with blocks.

List of Function Modules used for


blocked list ALV
REUSE_ALV_BLOCK_LIST_INIT
REUSE_ALV_BLOCK_LIST_APPEND
REUSE_ALV_BLOCK_LIST_DISPLAY
REUSE_ALV_BLOCK_LIST_INIT : is used to
initialize blocked list ALV.
REUSE_ALV_BLOCK_LIST_APPEND : is
used to add blocked list ALV's(we can add
multiple).
REUSE_ALV_BLOCK_LIST_DISPLAY : is
used to display blocked list ALV.

Follow the below


steps to create
blocked list ALV
Create a program in SE38, add
data declerations
Create a report program in SE38 and add
data declerations for MARA table, MAKT
table.Add a input parameter for material
type input.

TYPES: BEGIN OF TY_MARA, "user defined type


for mara
MATNR TYPE MARA-MATNR,

MTART TYPE MARA-MTART,


MBRSH TYPE MARA-MBRSH,
MATKL TYPE MARA-MATKL,
MEINS TYPE MARA-MEINS,
END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA,
"mara internal table
WA_MARA TYPE TY_MARA. "mara work area
TYPES: BEGIN OF TY_MAKT, "user defined type
for MAKT
MATNR TYPE MAKT-MATNR,
SPRAS TYPE MAKT-SPRAS,
MAKTX TYPE MAKT-MAKTX,
END OF TY_MAKT.
DATA : IT_MAKT TYPE TABLE OF TY_MAKT, "makt
internal table
WA_MAKT TYPE TY_MAKT.

PARAMETERS : P_MTART TYPE MARA-MTART.


"material type input

Build Field catalog for MARA and


MAKT tables
Build field catalog for MARA and MAKT
tables.
DATA : T_FCAT TYPE SLIS_T_FIELDCAT_ALV.
"field catalog for MARA table
DATA : W_FCAT LIKE LINE OF T_FCAT.
DATA : T_FCAT_MAKT TYPE
SLIS_T_FIELDCAT_ALV. "makt field catalog
DATA : W_FCAT_MAKT LIKE LINE OF
T_FCAT_MAKT.

***build fcat for MARA


W_FCAT-COL_POS

= '1'. "coloum position

W_FCAT-FIELDNAME
name

= 'MATNR'. "column

W_FCAT-TABNAME

= 'IT_MARA'. "table

W_FCAT-REF_TABNAME = 'MARA'. "table


W_FCAT-REF_FIELDNAME = 'MATNR'.
"referance field, it will show descriptions
automatically
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.

W_FCAT-COL_POS
W_FCAT-FIELDNAME
W_FCAT-TABNAME

= '2'.
= 'MTART'.
= 'IT_MARA'.

W_FCAT-REF_TABNAME = 'MARA'.
W_FCAT-REF_FIELDNAME = 'MTART'.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.

W_FCAT-COL_POS

= '3'.

W_FCAT-FIELDNAME
W_FCAT-TABNAME

= 'MBRSH'.
= 'IT_MARA'.

W_FCAT-REF_TABNAME = 'MARA'.
W_FCAT-REF_FIELDNAME = 'MBRSH'.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.

W_FCAT-COL_POS
W_FCAT-FIELDNAME
W_FCAT-TABNAME

= '4'.
= 'MATKL'.
= 'IT_MARA'.

W_FCAT-REF_TABNAME = 'MARA'.
W_FCAT-REF_FIELDNAME = 'MATKL'.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.

W_FCAT-COL_POS

= '5'.

W_FCAT-FIELDNAME
W_FCAT-TABNAME

= 'MEINS'.
= 'IT_MARA'.

W_FCAT-REF_TABNAME = 'MARA'.
W_FCAT-REF_FIELDNAME = 'MEINS'.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.

***build fcat for MAKT


W_FCAT_MAKT-COL_POS
W_FCAT_MAKT-FIELDNAME
W_FCAT_MAKT-TABNAME

= '1'.
= 'MATNR'.
= 'IT_MAKT'.

W_FCAT_MAKT-REF_TABNAME = 'MAKT'.
W_FCAT_MAKT-REF_FIELDNAME = 'MATNR'.
APPEND W_FCAT_MAKT TO T_FCAT_MAKT.
CLEAR W_FCAT_MAKT.
W_FCAT_MAKT-COL_POS

= '2'.

W_FCAT_MAKT-FIELDNAME
W_FCAT_MAKT-TABNAME

= 'SPRAS'.
= 'IT_MAKT'.

W_FCAT_MAKT-REF_TABNAME = 'MAKT'.
W_FCAT_MAKT-REF_FIELDNAME = 'SPRAS'.
APPEND W_FCAT_MAKT TO T_FCAT_MAKT.
CLEAR W_FCAT_MAKT.
W_FCAT_MAKT-COL_POS
W_FCAT_MAKT-FIELDNAME
W_FCAT_MAKT-TABNAME

= '3'.
= 'MAKTX'.
= 'IT_MAKT'.

W_FCAT_MAKT-REF_TABNAME = 'MAKT'.
W_FCAT_MAKT-REF_FIELDNAME = 'MAKTX'.
APPEND W_FCAT_MAKT TO T_FCAT_MAKT.
CLEAR W_FCAT_MAKT.

Initialize Blocked List ALV


Initialize blocked list ALV using Function
Module REUSE_ALV_BLOCK_LIST_INIT.

* * init
CALL FUNCTION
'REUSE_ALV_BLOCK_LIST_INIT' "initialize Block
List ALV
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID.

Add lists to blocked list ALV


Add all ALV lists with field catalogs
DATA S_EVENTS TYPE SLIS_T_EVENT.
DATA S_LAYOUT TYPE SLIS_LAYOUT_ALV.
S_LAYOUT-ZEBRA = 'X'. "display zebra
colours(alternate colours on rows)
**Add MARA list
CALL FUNCTION
'REUSE_ALV_BLOCK_LIST_APPEND' "append ALV
lists
EXPORTING

IS_LAYOUT = S_LAYOUT "set layout


IT_FIELDCAT = T_FCAT "set field catalog
I_TABNAME = 'IT_MARA' "table
IT_EVENTS = S_EVENTS "events
*

IT_SORT

I_TEXT

=
=''

TABLES
T_OUTTAB

= IT_MARA "out put table

* EXCEPTIONS
*

PROGRAM_ERROR

=1

MAXIMUM_OF_APPENDS_REACHED

OTHERS

=3

.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

=2

**add MAKT list


CALL FUNCTION
'REUSE_ALV_BLOCK_LIST_APPEND' "append ALV
lists
EXPORTING
IS_LAYOUT = S_LAYOUT "set layout
IT_FIELDCAT = T_FCAT_MAKT "set field
catalog
I_TABNAME = 'IT_MAKT' "table
IT_EVENTS = S_EVENTS "events
*

IT_SORT

I_TEXT

=
=''

TABLES
T_OUTTAB

= IT_MAKT "out put table

* EXCEPTIONS
*

PROGRAM_ERROR

=1

MAXIMUM_OF_APPENDS_REACHED

=2

OTHERS

=3

.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

Display Blocked List


Display blocked list ALV using Function
module REUSE_ALV_BLOCK_LIST_DISPLAY.
CALL FUNCTION
'REUSE_ALV_BLOCK_LIST_DISPLAY' . "display
blocked list

Full and Final Code to display


blocked list ALV
REPORT ZSAPN_ALV_BLOCKEDLIST.
TYPES: BEGIN OF TY_MARA, "user defined type
for mara

MATNR TYPE MARA-MATNR,


MTART TYPE MARA-MTART,
MBRSH TYPE MARA-MBRSH,
MATKL TYPE MARA-MATKL,
MEINS TYPE MARA-MEINS,
END OF TY_MARA.
DATA : IT_MARA TYPE TABLE OF TY_MARA,
"mara internal table
WA_MARA TYPE TY_MARA. "mara work area
DATA : T_FCAT TYPE SLIS_T_FIELDCAT_ALV.
"field catalog for MARA table
DATA : W_FCAT LIKE LINE OF T_FCAT.

TYPES: BEGIN OF TY_MAKT, "user defined type


for MAKT
MATNR TYPE MAKT-MATNR,
SPRAS TYPE MAKT-SPRAS,

MAKTX TYPE MAKT-MAKTX,


END OF TY_MAKT.
DATA : IT_MAKT TYPE TABLE OF TY_MAKT, "makt
internal table
WA_MAKT TYPE TY_MAKT.
DATA : T_FCAT_MAKT TYPE
SLIS_T_FIELDCAT_ALV. "makt field catalog
DATA : W_FCAT_MAKT LIKE LINE OF
T_FCAT_MAKT.
PARAMETERS : P_MTART TYPE MARA-MTART.
"material type input

START-OF-SELECTION.

SELECT MATNR
MTART
MBRSH
MATKL

MEINS FROM MARA "get MARA data


INTO TABLE IT_MARA UP TO 10 ROWS
WHERE MTART = P_MTART.
IF NOT IT_MARA IS INITIAL .
SELECT MATNR
SPRAS
MAKTX FROM MAKT INTO TABLE IT_MAKT
"get makt data
FOR ALL ENTRIES IN IT_MARA WHERE
MATNR = IT_MARA-MATNR.
ENDIF.
***build fcat for MARA
W_FCAT-COL_POS

= '1'. "coloum position

W_FCAT-FIELDNAME
name

= 'MATNR'. "column

W_FCAT-TABNAME

= 'IT_MARA'. "table

W_FCAT-REF_TABNAME = 'MARA'. "table

W_FCAT-REF_FIELDNAME = 'MATNR'.
"referance field, it will show descriptions
automatically
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.

W_FCAT-COL_POS
W_FCAT-FIELDNAME
W_FCAT-TABNAME

= '2'.
= 'MTART'.
= 'IT_MARA'.

W_FCAT-REF_TABNAME = 'MARA'.
W_FCAT-REF_FIELDNAME = 'MTART'.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.

W_FCAT-COL_POS
W_FCAT-FIELDNAME
W_FCAT-TABNAME

= '3'.
= 'MBRSH'.
= 'IT_MARA'.

W_FCAT-REF_TABNAME = 'MARA'.
W_FCAT-REF_FIELDNAME = 'MBRSH'.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.

W_FCAT-COL_POS
W_FCAT-FIELDNAME
W_FCAT-TABNAME

= '4'.
= 'MATKL'.
= 'IT_MARA'.

W_FCAT-REF_TABNAME = 'MARA'.
W_FCAT-REF_FIELDNAME = 'MATKL'.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.

W_FCAT-COL_POS
W_FCAT-FIELDNAME
W_FCAT-TABNAME

= '5'.
= 'MEINS'.
= 'IT_MARA'.

W_FCAT-REF_TABNAME = 'MARA'.
W_FCAT-REF_FIELDNAME = 'MEINS'.
APPEND W_FCAT TO T_FCAT.
CLEAR W_FCAT.

***build fcat for MAKT


W_FCAT_MAKT-COL_POS
W_FCAT_MAKT-FIELDNAME
W_FCAT_MAKT-TABNAME

= '1'.
= 'MATNR'.
= 'IT_MAKT'.

W_FCAT_MAKT-REF_TABNAME = 'MAKT'.
W_FCAT_MAKT-REF_FIELDNAME = 'MATNR'.
APPEND W_FCAT_MAKT TO T_FCAT_MAKT.
CLEAR W_FCAT_MAKT.
W_FCAT_MAKT-COL_POS
W_FCAT_MAKT-FIELDNAME
W_FCAT_MAKT-TABNAME

= '2'.
= 'SPRAS'.
= 'IT_MAKT'.

W_FCAT_MAKT-REF_TABNAME = 'MAKT'.
W_FCAT_MAKT-REF_FIELDNAME = 'SPRAS'.
APPEND W_FCAT_MAKT TO T_FCAT_MAKT.
CLEAR W_FCAT_MAKT.
W_FCAT_MAKT-COL_POS
W_FCAT_MAKT-FIELDNAME
W_FCAT_MAKT-TABNAME

= '3'.
= 'MAKTX'.
= 'IT_MAKT'.

W_FCAT_MAKT-REF_TABNAME = 'MAKT'.
W_FCAT_MAKT-REF_FIELDNAME = 'MAKTX'.
APPEND W_FCAT_MAKT TO T_FCAT_MAKT.
CLEAR W_FCAT_MAKT.
* * init
CALL FUNCTION
'REUSE_ALV_BLOCK_LIST_INIT' "initialize Block
List ALV
EXPORTING
I_CALLBACK_PROGRAM = SY-REPID.

DATA S_EVENTS TYPE SLIS_T_EVENT.


DATA S_LAYOUT TYPE SLIS_LAYOUT_ALV.
S_LAYOUT-ZEBRA = 'X'.
CALL FUNCTION
'REUSE_ALV_BLOCK_LIST_APPEND' "append ALV
lists
EXPORTING
IS_LAYOUT = S_LAYOUT "set layout
IT_FIELDCAT = T_FCAT "set field catalog
I_TABNAME = 'IT_MARA' "table
IT_EVENTS = S_EVENTS "events
*

IT_SORT

I_TEXT

=
=''

TABLES
T_OUTTAB
* EXCEPTIONS

= IT_MARA "out put table

PROGRAM_ERROR

=1

MAXIMUM_OF_APPENDS_REACHED

OTHERS

=2

=3

.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

CALL FUNCTION
'REUSE_ALV_BLOCK_LIST_APPEND' "append ALV
lists
EXPORTING
IS_LAYOUT = S_LAYOUT "set layout
IT_FIELDCAT = T_FCAT_MAKT "set field
catalog
I_TABNAME = 'IT_MAKT' "table
IT_EVENTS = S_EVENTS "events

IT_SORT

I_TEXT

=
=''

TABLES
T_OUTTAB

= IT_MAKT "out put table

* EXCEPTIONS
*

PROGRAM_ERROR

=1

MAXIMUM_OF_APPENDS_REACHED

OTHERS

=2

=3

.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
CALL FUNCTION
'REUSE_ALV_BLOCK_LIST_DISPLAY' . "display
blocked list

Hide ALV toolbar


buttons using ALV
Exclude
+Sometimes, we may need to hide some ALV
toolbar buttons in ALV grid Display using
REUSE_ALV_GRID_DISPLAY.
The below are the steps we are going to do
to hide ALV tool bar buttons.
1.

Get Standard GUI Function Codes.

2.
Exclude ALV toolbar functions using
IT_EXCLUDE exporting parameter.

Get Standard GUI function codes


We can get standard GUI function codes
using function
module RS_CUA_GET_STATUS_FUNCTIONS by
passing standard
program SAPLKKBL and
statusSTANDARD_FULLSCREEN.
DATA : FUN TYPE TABLE OF RSEUL_FUN.
DATA : WA_FUN LIKE LINE OF FUN.
CALL FUNCTION
'RS_CUA_GET_STATUS_FUNCTIONS'
EXPORTING
LANGUAGE = 'E'
PROGRAM = 'SAPLKKBL'
STATUS

= 'STANDARD_FULLSCREEN'

TABLES
FUNCTIONS = FUN.

IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

Exclude functions using


IT_EXCLUDE parameter of ALV
grid
Loop through the standard GUI function
which we got in previous step, and pass to
exclude table.
DATA : IT_EXCLUDE TYPE SLIS_T_EXTAB,
WA_EXCLUDE TYPE SLIS_EXTAB.
LOOP AT FUN INTO WA_FUN. "loop through all
functions
IF WA_FUN-FCODE EQ '&F03' OR WA_FUNFCODE EQ '&F15' OR WA_FUN-FCODE EQ
'&F12'. "don`t add back, exit, stop functions

ELSE.
WA_EXCLUDE-FCODE = WA_FUN-FCODE.
"add all remaining
APPEND WA_EXCLUDE TO IT_EXCLUDE.
CLEAR WA_EXCLUDE.
ENDIF.
ENDLOOP.

Full and Final Code


REPORT ZSAPN_ALV_FUNCTIONS.
DATA: IT_MARA TYPE TABLE OF MARA,
WA_MARA TYPE MARA.
DATA : FUN TYPE TABLE OF RSEUL_FUN.
DATA : WA_FUN LIKE LINE OF FUN.
DATA : IT_EXCLUDE TYPE SLIS_T_EXTAB,
WA_EXCLUDE TYPE SLIS_EXTAB.

START-OF-SELECTION.
SELECT * FROM MARA INTO TABLE IT_MARA
UP TO 50 ROWS.

CALL FUNCTION
'RS_CUA_GET_STATUS_FUNCTIONS'
EXPORTING
LANGUAGE = 'E'
PROGRAM = 'SAPLKKBL'
STATUS

= 'STANDARD_FULLSCREEN'

TABLES
FUNCTIONS = FUN.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

*&--------------------------------------------------------------------*
*
FOR EXCLUDING STANDARD BUTTONS
FROM ALV TOOLBAR
*&--------------------------------------------------------------------*
LOOP AT FUN INTO WA_FUN. "loop through all
functions
IF WA_FUN-FCODE EQ '&F03' OR WA_FUNFCODE EQ '&F15' OR WA_FUN-FCODE EQ
'&F12'. "don`t add back, exit, stop functions

ELSE.
WA_EXCLUDE-FCODE = WA_FUN-FCODE.
"add all remaining
APPEND WA_EXCLUDE TO IT_EXCLUDE.
CLEAR WA_EXCLUDE.
ENDIF.
ENDLOOP.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
*

I_CALLBACK_PF_STATUS_SET = 'PF_STATUS'
I_STRUCTURE_NAME = 'MARA'

IT_EXCLUDING
functions

= IT_EXCLUDE "exclude

TABLES
T_OUTTAB
data

= IT_MARA. "MARA table

IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.

Interactive Report
ALV
+Requirement: Display list of materials for a
material type with below options. 1. Add a
hotspot for material number. 2. Whenever
user double click on any material no, it

should go to MM03 transaction to display


material.
To make an interactive report we use USER
COMMAND event as call back user
command for ALV.
Follow below steps to develop an
interactive ALV.
Step1: Data decelerations.
TYPES : BEGIN OF TY_MARA, "User defined
internal table type
MATNR TYPE MARA-MATNR,
MTART TYPE MARA-MTART,
MBRSH TYPE MARA-MBRSH,
MEINS TYPE MARA-MEINS,
END OF TY_MARA.

DATA : IT_MARA TYPE TABLE OF


TY_MARA ."internal table
DATA : WA_MARA TYPE TY_MARA . "work area
PARAMETERS : P_MTART TYPE MARA-MTART.
"material type input

Step2: Get data from MARA


START-OF-SELECTION.
**get table data
SELECT MATNR MTART MBRSH MEINS FROM
MARA "get data from MARA
INTO TABLE IT_MARA UP TO 50 ROWS
WHERE MTART = P_MTART.

Step3: Build field catalog


DATA : IT_FCAT TYPE SLIS_T_FIELDCAT_ALV .
"field catalog table

DATA : WA_FCAT LIKE LINE OF IT_FCAT . "field


catalog work area
*** build field catalogue
WA_FCAT-COL_POS = '1' . "column position
WA_FCAT-FIELDNAME = 'MATNR' . "column
name
WA_FCAT-TABNAME = 'IT_MARA' . "table
WA_FCAT-SELTEXT_M = 'Material' . "Column
lable
WA_FCAT-KEY = 'X' . "is a key field
WA_FCAT-HOTSPOT = 'X' . "Set hotspot for
matnr
APPEND WA_FCAT TO IT_FCAT . "append to
fcat
CLEAR WA_FCAT .
WA_FCAT-COL_POS = '2' .
WA_FCAT-FIELDNAME = 'MBRSH' .
WA_FCAT-TABNAME = 'IT_MARA' .

WA_FCAT-SELTEXT_M = 'Industry Sec' .


APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_FCAT .

WA_FCAT-COL_POS = '3' .
WA_FCAT-FIELDNAME = 'MTART' .
WA_FCAT-TABNAME = 'IT_MARA' .
WA_FCAT-SELTEXT_M = 'Material Type' .
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_FCAT .

WA_FCAT-COL_POS = '4' .
WA_FCAT-FIELDNAME = 'MEINS' .
WA_FCAT-TABNAME = 'IT_MARA' .
WA_FCAT-SELTEXT_M = 'Base.Unit' .
WA_FCAT-REF_TABNAME = 'MARA' .

APPEND WA_FCAT TO IT_FCAT .


CLEAR WA_FCAT .

Step4: Display ALV


TYPE-POOLS SLIS . "SLIS type pool
**display ALV
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM

= SY-REPID

I_CALLBACK_USER_COMMAND =
'USER_COMMAND' "user command form
IT_FIELDCAT
CATALOG TO ALV

= IT_FCAT "PASS FIELD

TABLES
T_OUTTAB
table

= IT_MARA. "output

Step4: Implement user command

**for to handle user command


FORM USER_COMMAND USING R_UCOMM LIKE
SY-UCOMM
RS_SELFIELD TYPE
SLIS_SELFIELD.
CASE R_UCOMM.
WHEN '&IC1'. "standard Function code for
double click
READ TABLE IT_MARA INTO WA_MARA
INDEX RS_SELFIELD-TABINDEX.
IF SY-SUBRC = 0.
SET PARAMETER ID 'MAT' FIELD WA_MARAMATNR. "set parameter id
CALL TRANSACTION 'MM03' AND SKIP
FIRST SCREEN. "call transaction
ENDIF.
ENDCASE.
ENDFORM.

"user_command

Final code will be


REPORT ZSAPN_ALV_INTERACTIVE.
TYPE-POOLS SLIS .
TYPES : BEGIN OF TY_MARA, "User defined
internal table type
MATNR TYPE MARA-MATNR,
MTART TYPE MARA-MTART,
MBRSH TYPE MARA-MBRSH,
MEINS TYPE MARA-MEINS,
END OF TY_MARA.

DATA : IT_MARA TYPE TABLE OF


TY_MARA ."internal table
DATA : WA_MARA TYPE TY_MARA . "work area

DATA : IT_FCAT TYPE SLIS_T_FIELDCAT_ALV .


"field catalog table
DATA : WA_FCAT LIKE LINE OF IT_FCAT . "field
catalog work area
PARAMETERS : P_MTART TYPE MARA-MTART.
"material type input

START-OF-SELECTION.
**get table data
SELECT MATNR MTART MBRSH MEINS FROM
MARA "get data from MARA
INTO TABLE IT_MARA UP TO 50 ROWS
WHERE MTART = P_MTART.
*** generate field catalogue
WA_FCAT-COL_POS = '1' . "column position
WA_FCAT-FIELDNAME = 'MATNR' . "column
name
WA_FCAT-TABNAME = 'IT_MARA' . "table

WA_FCAT-SELTEXT_M = 'Material' . "Column


label
WA_FCAT-KEY = 'X' . "is a key field
WA_FCAT-HOTSPOT = 'X' . "Set hotspot for
matnr
APPEND WA_FCAT TO IT_FCAT . "append to
fcat
CLEAR WA_FCAT .
WA_FCAT-COL_POS = '2' .
WA_FCAT-FIELDNAME = 'MBRSH' .
WA_FCAT-TABNAME = 'IT_MARA' .
WA_FCAT-SELTEXT_M = 'Industry Sec' .
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_FCAT .

WA_FCAT-COL_POS = '3' .
WA_FCAT-FIELDNAME = 'MTART' .

WA_FCAT-TABNAME = 'IT_MARA' .
WA_FCAT-SELTEXT_M = 'Material Type' .
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_FCAT .

WA_FCAT-COL_POS = '4' .
WA_FCAT-FIELDNAME = 'MEINS' .
WA_FCAT-TABNAME = 'IT_MARA' .
WA_FCAT-SELTEXT_M = 'Base.Unit' .
WA_FCAT-REF_TABNAME = 'MARA' .
APPEND WA_FCAT TO IT_FCAT .
CLEAR WA_FCAT .
**display ALV
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM

= SY-REPID

I_CALLBACK_USER_COMMAND =
'USER_COMMAND' "user command form
IT_FIELDCAT
CATALOG TO ALV

= IT_FCAT "PASS FIELD

TABLES
T_OUTTAB
table

= IT_MARA. "output

**for to handle user command


FORM USER_COMMAND USING R_UCOMM LIKE
SY-UCOMM
RS_SELFIELD TYPE
SLIS_SELFIELD.
CASE R_UCOMM.
WHEN '&IC1'. "standard Function code for
doubel click
READ TABLE IT_MARA INTO WA_MARA
INDEX RS_SELFIELD-TABINDEX.
IF SY-SUBRC = 0.

SET PARAMETER ID 'MAT' FIELD WA_MARAMATNR. "set parameter id


CALL TRANSACTION 'MM03' AND SKIP
FIRST SCREEN. "call transaction
ENDIF.
ENDCASE.
ENDFORM.

"user_command

También podría gustarte