Archive

Archive for the ‘ALV’ Category

SAP ALV – ALV Samples in SAP (cl_salv_table and cl_gui_alv_grid)

December 22nd, 2011 No comments

ALV is a very usual topic of the search keywords about ABAP.

Recently,I make some research about ALV,such like ALV tree,drag and drop effects of ALV,how to display two alv on one screen.

What is the difference between package SLIS and SALV_TABLE?

Before try to use the data,we should init data for flight sample and sbook sample of ALV.Program SAPBC_DATA_GENERATOR can init the data

of this two sample.

ALV_T_T2 is used for alv tree sample.We can init the data with function

module BCALV_GENERATE_ALV_T_T2.

Difference between SLIS and SALV_TABLE

1 cl_salv_table in package salv_table does not support editable grid,but SLIS can.

2 drag and drop effects of alv are only avaliable for SLIS

3 For full screen ALV,SALV_TABLE is much more easier to use.If we want to use SLIS to achieve the fullscreen effect,we only can use function module API to achieve this,with cl_gui_alv_grid is impossible.

 

There are still many points we can talk about  ALV.You can find many other blogs introducing ALV on sapgeek .Try to avoid repeating.I will focus on talking about some  other areas of ALV in later blogs,such like drag and drop effects,and then extends to SAP control framework(SAP GUI Programing)

SAP ALV- Control negative sign display for currency fields

December 5th, 2011 No comments

In SAP ALV, display minus singal ‘-’from left to right is very usual requirements.

We can implement this requirements throuth eidt mask feature of SAP ALV.

In class cl_salv_column_table ,there is a method set_edit_mask.

It is allowed to set own developed conversion routine here.

Just define ROUTINE named like ‘CONVERSION_EXIT_**_OUTPUT’.I will give a example later.

For curr Type fields, by default,the negative sign is not displayed in ALV.We should

use the method ‘SET_SIGN’ of class cl_salv_column_table to resolve this problem.

If we do not set sign for the column,when printing view or background processing the report,the result will not display ‘-’.

SAP ALV Overview

November 9th, 2011 No comments

ALV is the abbreviation of SAP List View which is an UI element for displaying tabular data. ALV provides a rich set of functionalities like sorting, filtering, aggregation, exporting, persistence of custom settings.

image

History of SAP ALV

ALV is formerly known as ABAP List Viewer. From basis 4.0, ALV is available for SAP internal usage based on ABAP list processor technology.

Read more…

ABAP Report Template

January 7th, 2010 No comments

Here is the abap report program template. I record it in my blog for further reference.

************************************************************************
*  Program ID     : ZRPSD_TEST                                         *
*  Program Title  : Sales test report                                  *
*  Created By     : XXXXX XXXXX                                        *
*  Creation Date  : 01/07/2010                                         *
*  REQ # / CRF #  : REQ # 100                                          *
*                                                                      *
*  Description    :                                                    *
*                                                                      *
*                                                                      *
*  Additional Information :                                            *
*                                                                      *
************************************************************************
*                     Modification History                             *
************************************************************************
*  Date       User ID       REQ # CRF #     Transport # / Description  *
*  ---------- ------------  -------------   -------------------------  *
*  01/07/2010 XXXXXXX       REQ 100         XXXK900003                 *
*             Initial Version                                          *
************************************************************************
 
REPORT  ZRPSD_TEST MESSAGE-ID zsd.
 
*--Contains all the declarations
INCLUDE zilsd_test_top.
 
*--Contains all screen declarations and validations
INCLUDE zilsd_test_scrn.
 
*--Contains all subroutines with program processing logic
INCLUDE zilsd_test_sub.
 
*----------------------------------------------------------------------*
* Declaration of Tables                                                *
*----------------------------------------------------------------------*
 
*----------------------------------------------------------------------*
* Declaration of Variables                                             *
*----------------------------------------------------------------------*
 
*----------------------------------------------------------------------*
* Declaration of Constants                                             *
*----------------------------------------------------------------------*
 
*----------------------------------------------------------------------*
* Declaration of Flags                                                 *
*----------------------------------------------------------------------*
 
*----------------------------------------------------------------------*
* Declaration of Internal Tables                                       *
*----------------------------------------------------------------------*
 
*----------------------------------------------------------------------*
* Selection Screen                                                     *
*----------------------------------------------------------------------*
 
*----------------------------------------------------------------------*
* Initialization                                                       *
*----------------------------------------------------------------------*
 
*----------------------------------------------------------------------*
* At Selection screen                                                  *
*----------------------------------------------------------------------*
 
*----------------------------------------------------------------------*
* Start of Selection                                                   *
*----------------------------------------------------------------------*
 
*----------------------------------------------------------------------*
* End of Selection                                                     *
*----------------------------------------------------------------------*

ALV Tips – Display column as Icon

December 30th, 2009 2 comments

We may need to display traffic light or some other icons in the ALV output to highlight some lines. Here is an example.

To use icons, you need to use types-pool: icon or include the include file <ICON> in the program.

Read more…

ALV Tips – Select Line

December 30th, 2009 No comments

We can make one or several lines in ALV report selectable according to select mode set in layout structure.

Step 1. Define another field in the output table with type c length 1. This field will be used to record the select status of front end in the backend.

* Data to be displayed
DATA: BEGIN OF gt_data OCCURS 50,
        k(10),
        a TYPE int1,
        mark(1) type c,
      END OF gt_data.

Step 2. Set this field name ‘MARK’ to the attribute ‘box_fname’ in layout structure.

gs_layout-sel_mode = 'A'.  " set the selection mode
gs_layout-box_fname = 'MARK'.

When user choose one or several lines in the report and trigger event in the frontend, you can easily loop the output table and the field mark with value ‘X’ is those user selected.

loop at gtouttab.
  if gtouttab-mark = 'X'.
* add your action hereendif.
endloop.

Read more…

ALV Tips – Column length has maximum of 128 characters

December 30th, 2009 No comments

The column length in ALV has a maxmium 128 characters. Note 857823 has the detail. Below is the detail from SAP.

Symptom
Entries in cells of the type CHAR or string are truncated after 128 characters in the SAP GUI.

Other terms
ALV Grid Control (cl_gui_alv_grid), function module (Full-screen) Grid (Reuse_alv_grid_display, SAPLSLVC_FULLSCREEN), SAPGUI, back end, front end

Reason and Prerequisites
The data table that is sent to the frontend only allows character values with the length 128.

Solution
This is the standard system behavior and cannot be changed.

Read more…

SAP ALV Tutorial – Currency/Quantity field

December 16th, 2009 No comments

If the field in ALV output table is for currency or quantity, we need to do some effort to display it in our ALV. you must assign these fields to a currency or unit. There are three ways how you can do this in the field catalog:

  • Reference to a Currency or Unit Field
  • Value or Unit for the Entire Column
  • Format the value field manually

Reference to a Currency or Unit Field

If you define your output table as an structure in DDIC, you need to provide corrsponding reference table and field for currency/quantity field when you activate it. The reference field can be used to display values in the correct user-specific format.

When you read the whole field catalog of the output table using function module ‘REUSE_ALV_FIELDCATALOG_MERGE’, you can automatically fill the field CFIELDNAME or QFIELDNAME in field catalog structure. That means you can fill above two field maually if your output table type is defined in the program not in DDIC.

It is also very useful when you want to have subtotal according to different currency or unit.The field catalog also contains an entry for the unit field. If you do not want to display the unit as a column in the list and do not want to allow users to interactively show it as a column, you can mark the field catalog entry for the unit field as a technical field by setting field TECH. This makes sense, for example, if the unit is always unique and therefore explicitly output in the list header by the caller.

For initial value or currency fields, you must consider the following points:

Read more…

SAP ALV Tutorial – Handling Data Change

December 8th, 2009 No comments

In previous article, we have already set alv editable, but we still need to validate the input data as well as save the input data to the database. In another case, we also need to change according to user’s event.

As we can now make our alv Grid editable we may require controlling input data. The alv Grid has events data_changed and data_changed_finished. The former method is triggered just after the change at an editable field is perceived. Here you can make checks for the input. And the second event is triggered after the change is committed. You can select the way how the control perceives data changes by using the method register_edit_event. You have two choices:

1. After return key is pressed: To select this way, to the parameter event_id pass cl_gui_alv_grid=>mc_evt_enter.
2. After the field is modified and the cursor is moved to another field: For this, pass cl_gui_alv_grid=>mc_evt_modifies to the same parameter.

Read more…

SAP ALV Tutorial – Make ALV editable

December 8th, 2009 No comments

Sometimes, we need to make our ALV editable. SAP has already provide table control to modify table data(previously we use loop step instead). But ALV can provide more functionality to support sort, total,filter, etc.

As far as the edit feature is concerned, a cell of the alv grid control can have the following states:

1. non-editable : edit feature not set for this cell

2. editable : edit feature set for this cell

The second state (”editable”) has two substates:

1. editable and not ready for input: edit feature set but not active

2. editable and ready for input: edit feature set and active

You switch between “editable and not ready for input” and “editable and ready for input” using method SET_READY_FOR_INPUT. Below is a piece of code.

    CALL METHOD g_grid->set_table_for_first_display
         EXPORTING i_structure_name = 'SFLIGHT'
                   is_layout        = gs_layout
         CHANGING  it_outtab        = gt_outtab.
*2.Use SET_READY_FOR_INPUT to allow editing initially.
*   (state ”editable and ready for input”).
    CALL METHOD g_grid->set_ready_for_input
          EXPORTING i_ready_for_input = 1.

Read more…