0% found this document useful (0 votes)
94 views9 pages

ALVGrid Control

This document discusses different ways to display data in lists in SAP, including: 1. Dynpros (dynamic programs) which control dialog steps and screen flow logic. A dynpro consists of a screen, flow logic, screen attributes, and field attributes which are defined in the Screen Painter. 2. The ALV Grid Control, a flexible tool for displaying lists. Lists can be displayed using either function modules like REUSE_ALV_GRID_DISPLAY or by creating an object instance of class cl_gui_alv_grid. 3. Steps for creating a modulpool program which can contain screens, flow logic, and transaction assignment. Examples are provided for creating dynpros

Uploaded by

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

ALVGrid Control

This document discusses different ways to display data in lists in SAP, including: 1. Dynpros (dynamic programs) which control dialog steps and screen flow logic. A dynpro consists of a screen, flow logic, screen attributes, and field attributes which are defined in the Screen Painter. 2. The ALV Grid Control, a flexible tool for displaying lists. Lists can be displayed using either function modules like REUSE_ALV_GRID_DISPLAY or by creating an object instance of class cl_gui_alv_grid. 3. Steps for creating a modulpool program which can contain screens, flow logic, and transaction assignment. Examples are provided for creating dynpros

Uploaded by

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

UNIT 22.

Dynpro, ALV and Batch Input

Dynpro or Modulpool
A dynpro (Dynamic Program) consists of a screen and its flow logic and controls exactly one dialog steps. Each screen contains
fields used to display or request information. Fields can be text strings, input or output fields, radio buttons, checkboxes, or
pushbuttons. See the screen of program ZSHAD6 (Transaction TZ10).

An SAP dynpro consists of several components:

 Flow logic: Calls of the ABAP/4 modules for a screen.


 Screen layout: Positions of the texts, fields, pushbuttons, and so on for a screen.
 Screen attributes: Number of the screen, number of the subsequent screen, and others.
 Field attributes: Definition of the attributes of the individual fields on a screen.

You create and edit all components of a dynpro in the Screen Painter. To call the Screen Painter, create a dynpro in the Object
Browser or double-click on an existing dynpro. The Object Browser then calls the Screen Painter. There, you can enter the flow
logic of the new dynpro. By pressing the corresponding pushbutton you can maintain the Screen attributes, branch to the Full
Screen-Editor or you choose the pushbutton Field list and change the attributes of fields.

Screen Attributes

From the user's point of view, a transaction is a sequence of screens, displayed one after another. How do I determine this
sequence? The transaction's attributes determine the first screen to be displayed. The attributes of the individual dynpros
determine which screen to display after the current screen. You can also set the number of the subsequent screen dynamically
from within the ABAP/4 program.

For the sample transaction, the screen attributes need not be changed, since no subsequent screen is called.

Layout

Here you can determine the layout of the screen.

Field Attributes

To display and modify the attributes of the individual fields (input/output fields, input required, possible entries button,
invisible, and so on), use the Field list.

The fields can be defined as input/output fields. Other fields can be used only for outputting the data. See Transaction TZ10

Flow Logic

The flow control code of a dynpro consists of a few statements that syntactically resemble ABAP/4 statements. However, you
cannot use flow control keywords in ABAP/4 and vice versa. You enter the flow control code in the Screen Painter as one
component of the dynpro.

The flow control for the dynpro of Transaction ZSHAD6 looks like this:

PROCESS BEFORE OUTPUT.


MODULE STATUS_0001.
*
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0001.
The PROCESS statement names the event type for the dynpro and the MODULE statement tells the system which ABAP/4
routine to call for this event. In this example, there is only one MODULE for each event PBO and PAI. However, an event can
contain several statements with several keywords. (The flow control language contains only few statement types. The most
important are MODULE, FIELD, CHAIN, LOOP, CALL SUBSCREEN.)

To display information on the statement syntax in the flow logic, choose Utilities --> Help on... in the flow logic editor. In the
subsequent dialog window, mark Flow logic keyword, enter the name of the desired keyword, and press ENTER.

Steps to create a modulpool:


 Create a program type Modulpool in SE38
 Press “Display Object list” button
 Right click on the object name (name of program) and create screen

 In “Flow Logic” tab press “Layout” button


 Place components of screen as you need
This create the flow logic PROCESS BEFORE OUTPUT and PROCESS AFTER INPUT
 Create the logic for MODULE USER_COMMAND_0001.
 Right click on the object name (name of program) and create transaction

Listing 22.1  Example of modulpool


PROGRAM ZSHAD6.
TABLES : ZSHAD.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0001 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0001 INPUT.

CASE SY-UCOMM.
WHEN 'INSERT'.
INSERT ZSHAD.

WHEN 'DISPLAY'.
SELECT SINGLE * FROM ZSHAD INTO ZSHAD WHERE PLANETYPE = ZSHAD-PLANETYPE.

WHEN 'CLEAR'.
CLEAR ZSHAD.

WHEN 'EXIT'.
LEAVE TO SCREEN 0 .

ENDCASE.

ENDMODULE. " USER_COMMAND_0001 INPUT


module STATUS_0001 output.
SET PF-STATUS 'MAIN0001'.
SET TITLEBAR 'TITULO0001'.

endmodule. " STATUS_0001 OUTPUT

*************
PROCESS BEFORE OUTPUT.
MODULE STATUS_0001.
*
PROCESS AFTER INPUT.
MODULE USER_COMMAND_0001.
**********************
See ZSHAD6_dynpro.txt

ALV Grid Control


The ALV Grid Control (ALV = SAP List Viewer) is a flexible tool for displaying lists. The tool provides common list operations as
generic functions and can be enhanced by self-defined options. This allows you to use the ALV Grid Control in a large range of
application programs.

The following graphic shows a list displayed with the ALV Grid Control in a dialog box:

The ALV Grid Control consists of a toolbar, a title and the output table displayed in a grid control. If required, the user can hide
the title and the standard functions of the toolbar.

With Functions
REUSE_ALV_GRID_DISPLAY is a function module which is used to display the output in grid format.

The input for this function module are two internal tables: one internal table for data and another for internal table for about
the fields. Example:
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_grid_title = 'titulo'
it_fieldcat = i_fieldcat[]
TABLES
t_outtab = i_valores
EXCEPTIONS
program_error = 1
OTHERS = 2.

i_fieldcat must be type:


i_fieldcat TYPE STANDARD TABLE OF slis_fieldcat_alv.

i_valores must correspond with field description and type o each field in i_fieldcat.

Listing 22.2  Example of ALV using functions

REPORT ZTX2202_ALV_2.
TYPE-POOLS: SLIS.

DATA: BEGIN OF w_sflight,


carrid TYPE sflight-carrid,
connid TYPE sflight-connid,

END OF w_sflight,

i_sflight LIKE STANDARD TABLE OF w_sflight.

* Parameters
PARAMETERS: p_carrid TYPE sflight-carrid.
*SELECT-OPTIONS: s_carrid FOR sflight-carrid.

START-OF-SELECTION.
Perform f_alv.

END-OF-SELECTION.
*********************************************
*&---------------------------------------------------------------------*
*& Form f_alv
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM f_alv.
DATA: lv_tabname(10) VALUE 'sflight'.
CONSTANTS: lc_CARRID(5) VALUE 'CARRID',
lc_CONNID(10) VALUE 'CONNID',
lc_FLDATE(10) VALUE 'FLDATE',
lc_PRICE(10) VALUE 'PRICE'.

DATA: li_fieldcat TYPE STANDARD TABLE OF slis_fieldcat_alv.

DATA: lw_fieldcat TYPE slis_fieldcat_alv,


lv_pos TYPE sy-cucol.

ADD 1 TO lv_pos.
lw_fieldcat-col_pos = lv_pos.
lw_fieldcat-fieldname = lc_carrid.
lw_fieldcat-tabname = lv_tabname.
lw_fieldcat-seltext_l = 'text-010'.
lw_fieldcat-seltext_m = 'text-010'.
lw_fieldcat-seltext_s = 'text-010'.
APPEND lw_fieldcat TO li_fieldcat.
CLEAR lw_fieldcat.

ADD 1 TO lv_pos.
lw_fieldcat-col_pos = lv_pos.
lw_fieldcat-fieldname = lc_connid.
lw_fieldcat-tabname = lv_tabname.
lw_fieldcat-seltext_l = 'text-011'.
lw_fieldcat-seltext_m = 'text-011'.
lw_fieldcat-seltext_s = 'text-011'.
APPEND lw_fieldcat TO li_fieldcat.
CLEAR lw_fieldcat.

ADD 1 TO lv_pos.
lw_fieldcat-col_pos = lv_pos.
lw_fieldcat-fieldname = lc_fldate.
lw_fieldcat-tabname = lv_tabname.
lw_fieldcat-seltext_l = 'text-012'.
lw_fieldcat-seltext_m = 'text-012'.
lw_fieldcat-seltext_s = 'text-012'.
APPEND lw_fieldcat TO li_fieldcat.
CLEAR lw_fieldcat.

ADD 1 TO lv_pos.
lw_fieldcat-col_pos = lv_pos.
lw_fieldcat-fieldname = lc_price.
lw_fieldcat-tabname = lv_tabname.
lw_fieldcat-seltext_l = 'text-013'.
lw_fieldcat-seltext_m = 'text-013'.
lw_fieldcat-seltext_s = 'text-013'.
APPEND lw_fieldcat TO li_fieldcat.
CLEAR lw_fieldcat.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'


EXPORTING
i_grid_title = 'text-t02'
it_fieldcat = li_fieldcat[]
TABLES
t_outtab = i_sflight
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. " f_alv
**************************************************
Note: see also example ZTX2202_ALV

With Objects
This instance is defined with reference to class cl_gui_alv_grid:

data <name of reference variable> type ref to cl_gui_alv_grid.

An instance for the ALV Grid Control manages all information pertaining to a list on your screen. You can call methods on this
instance with which you can define and change the properties of this control.

First Steps

1. Create an instance of the ALV Grid Control and integrate it into a screen.
2. Select the data to be displayed and pass it together with a description of the fields to the instance.

Creating an ALV Grid Control


You instantiate an ALV Grid Control in the same way as other controls:
1. Declare reference variables for the ALV Grid Control and the container. In addition, declare an internal table that you fill with
selected data later on:

DATA: grid TYPE REF TO cl_gui_alv_grid,


g_custom_container TYPE REF TO cl_gui_custom_container
gt_sflight TYPE TABLE OF sflight.

In order to integrate a control into a screen, you can use four different container controls (in this example, we use the custom
container control).
2. Create a standard screen and mark an area for the custom container control in the graphical
Screen Painter (icon identified by letter 'C'). Assign name CCCONTAINER to this area.

3. In the PBO module of the screen, you must now instantiate the container control and the ALV Grid Control. By doing this,
you create a link between the container control and the screen, using the container created in the Screen Painter. Using
parameter parent, you define the container control as the parent of the ALV Grid Control:

IF g_custom_container IS INITIAL.
CREATE OBJECT g_custom_container
EXPORTING
CONTAINER_NAME = 'CCCONTAINER'.
CREATE OBJECT GRID1
EXPORTING
I_PARENT = g_custom_container.
ENDIF.

Displaying a List in the ALV Grid Control


Once you have created the ALV Grid Control and integrated it into a screen using a container control, you must pass the data
and its structure to the ALV Grid Control:
1. Fill the internal table with data:

SELECT * FROM sflight INTO TABLE gt_sflight.

2. Pass the output table and the structure data to the ALV Grid Control. Again, ensure to call this method only once after the
ALV Grid Control is created:

CALL METHOD grid->set_table_for_first_display


EXPORTING I_STRUCTURE_NAME = 'SFLIGHT'
CHANGING IT_OUTTAB = gt_sflight.

In this case, the structure data is provided through the Data Dictionary. The ALV Grid Control gets the field information from
table SFLIGHT and displays all fields of the table.
See sample report BCALV_GRID_DEMO in development class SLIS.

Batch input
 Batch input processing brings large amounts of data into an SAP system using the same types of data entry commands and
processes as manual data input. The difference is that batch input transfers data from an electronic storage medium to the SAP
database and then inputs data automatically rather than relying on a human end user to input data by hand. Transfer speed
and adherence to data integrity rules that ensure data accuracy makes advantages to using batch processing rise in direct
proportion to the amount or size of input data.
Process
 Batch input is a two-step process that starts with exporting or transferring data from the source system according to the
transfer method you choose -- Classical Batch Input or Call Transaction using Call Dialog -- and instructions you provide in a
special data transfer computer program. Although each completes the transfer process differently, both transfer data to a
common structure called a Batch Data Input Structure or BDCDATA. Depending on the transfer method, the BDCDATA holds
data for input later or input to your SAP database takes place immediately.
Classical Batch Input
 Classical Batch Input, or CBI, allows you to run a data transfer program multiple times and store the results -- called transactions
-- within the BDCDATA in “sessions” for later processing. Updating can take place in the foreground but most often occurs
behind the scenes while other programs are running. Although slower, CBI is more appropriate for transferring large amounts
of data and because CBI generates a batch input process log for each input session and offers support for finding and correcting
process errors.
Call Transaction
 Call Transaction Using Call Dialog transfers and processes data for single transactions or each time you run the data transfer
application program. As data arrives at the BDCDATA, processing -- committing the data and updating an SAP database -- takes
place immediately. Because of this, Call Transaction is appropriate for transferring small amounts of data. In addition, Call
Transaction does not generate batch input process logs, meaning there is no support for finding and correcting process errors
and you must provide explicit error detection and handling instructions within the data transfer program.

Listing 22.3  Example of batch input

*&---------------------------------------------------------------------*
*& Report ZTX2203_BATCHI

report ZTX2203_BATCHI

no standard page heading line-size 255.

DATA : BEGIN OF IT_TAB OCCURS 0,

CARRID LIKE SFLIGHT-CARRID,

CONNID LIKE SFLIGHT-CONNID,

FLDATE LIKE SFLIGHT-FLDATE,

PLANETYPE LIKE SFLIGHT-PLANETYPE,

PAYMENTSUM LIKE SFLIGHT-PAYMENTSUM,

END OF IT_TAB.

DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

FILENAME = 'C:\FLIGHT.TXT'

FILETYPE = 'DAT'

TABLES

DATA_TAB = IT_TAB.

IF SY-SUBRC <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

LOOP AT IT_TAB.

REFRESH BDCDATA.

PERFORM MAPPING.

CALL TRANSACTION 'ZSHAD' USING BDCDATA MODE 'A'.

ENDLOOP.

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

*& Form MAPPING

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

* text

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

FORM MAPPING.

perform bdc_dynpro using 'ZSHAD6' '0001'.

perform bdc_field using 'BDC_OKCODE'

'=INSERT'.

perform bdc_field using 'BDC_CURSOR'

'ZSHAD-PAYEMENT'.

perform bdc_field using 'ZSHAD-CARRIAGE'

'AA'.

perform bdc_field using 'ZSHAD-CONNECTIONID'


'1'.

perform bdc_field using 'ZSHAD-FDATE'

'28.01.2012'.

perform bdc_field using 'ZSHAD-PLANETYPE'

'SH21'.

perform bdc_field using 'ZSHAD-PAYEMENT'

'1000'.

ENDFORM. "MAPPING

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

* Start new screen *

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

FORM BDC_DYNPRO USING PROGRAM DYNPRO.

CLEAR BDCDATA.

BDCDATA-PROGRAM = PROGRAM.

BDCDATA-DYNPRO = DYNPRO.

BDCDATA-DYNBEGIN = 'X'.

APPEND BDCDATA.

ENDFORM. "BDC_DYNPRO

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

* Insert field *

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

FORM BDC_FIELD USING FNAM FVAL.

IF FVAL <> SPACE.

CLEAR BDCDATA.

BDCDATA-FNAM = FNAM.

BDCDATA-FVAL = FVAL.

APPEND BDCDATA.

ENDIF.

ENDFORM. "BDC_FIELD

You might also like