How to implement F4 search help in OO ALV Grid

I have searched SDN myself for the answer for sometime. All the friends that answered were helpful but there were only example links. So here is a simple code to implement F4 search help for OO ALV grid cells:

First we have to define the method and sub programs. In the definition part of our events class, include a code as the following: 

CLASS lcl_event_handler DEFINITION .
  PUBLIC SECTION .
    METHODS:

….

    on_f4 FOR EVENT onf4 OF cl_gui_alv_grid
      IMPORTING e_fieldname
                es_row_no
                er_event_data
                et_bad_cells

                e_display.

….

ENDCLASS.  

For the implementation part, code can be as follows:
  CLASS lcl_event_handler IMPLEMENTATION .
…..
….
  METHOD on_f4.
    PERFORM on_f4 USING e_fieldname
                es_row_no-row_id
                er_event_data
                et_bad_cells
                e_display
                er_data_changed.
    er_event_data->m_event_handled = ‘X’.
  ENDMETHOD.                                                "on_f4
…..
…..
ENDCLASS . 

Within our main program after displaying the table (by method set_table_for_first_display), we have to create the event handler object and set the handlers for these events.
    CREATE OBJECT gr_event_handler .
*–Registering handler methods to handle ALV Grid events
…..
…..
    SET HANDLER gr_event_handler->on_f4 FOR gr_alvgrid .
    PERFORM register_f4_fields.    "set cells with search help
*§3.Optionally register ENTER to raise event DATA_CHANGED.
    call method gr_alvgrid->register_edit_event
      EXPORTING
        i_event_id = cl_gui_alv_grid=>mc_evt_modified.
…… ……. ……
FORM register_f4_fields.    "which fields will have F4 search help  DATA: lt_f4 TYPE lvc_t_f4 WITH HEADER LINE .
  DATA: lt_f4_data TYPE lvc_s_f4.
  lt_f4_data-fieldname = ‘CHARG’.
  lt_f4_data-register = ‘X’ .
*  lt_f4_data-getbefore = ‘X’ .
  lt_f4_data-CHNGEAFTER  =’X’.
  INSERT lt_f4_data INTO TABLE lt_f4.
  lt_f4_data-fieldname = ‘LGORT’.
  lt_f4_data-register = ‘X’ .
*  lt_f4_data-getbefore = ‘X’ .
  lt_f4_data-CHNGEAFTER  =’X’.
  INSERT lt_f4_data INTO TABLE lt_f4.
  CALL METHOD gr_alvgrid->register_f4_for_fields
    EXPORTING
      it_f4 = lt_f4[].
ENDFORM.                    "register_f4_fields

The main sub program where we handle the changed cell value is as follows:
FORM on_f4  USING    P_E_FIELDNAME
                     ROW_ID
                     P_ER_EVENT_DATA
                              TYPE REF TO CL_ALV_EVENT_DATA
                     P_ET_BAD_CELLS
                     P_E_DISPLAY
                     IR_DATA_CHANGED
                              TYPE REF TO cl_alv_changed_data_protocol.
  DATA: BEGIN OF value_charg OCCURS 0, "the value table that is passed to F4 fm
          charg like zpp_kpduzelt-charg,
          lgort like zpp_kpduzelt-lgort,
          clabs like mchb-clabs,
  END OF value_charg.
  DATA : ls_mod_cell TYPE lvc_s_modi ,
         ls_del_cell TYPE lvc_s_moce  ,
         ls_good_cell TYPE lvc_s_modi,
         lv_value TYPE lvc_value .
  DATA : ls_mod_row like line of gt_list.

…..,

…. *§5 define fields and field-symbols for data-update
  field-symbols: <itab> type lvc_t_modi.
  data: ls_modi type lvc_s_modi.
  create object ir_data_changed.
  SORT ir_data_changed->mt_mod_cells BY row_id .
  LOOP AT ir_data_changed->mt_mod_cells
  INTO ls_mod_cell.
  ENDLOOP.
  case p_e_fieldname.   "read changed cell
    when ‘CHARG’.      
……
* here must be the code to fill in the possible values table
* and the call to fm F4IF_INT_TABLE_VALUE_REQUEST
……
      CALL FUNCTION ‘F4IF_INT_TABLE_VALUE_REQUEST’
        EXPORTING
          retfield        = ‘CHARG’
          value_org       = ‘S’
*      DYNPPROG        = SY-REPID
*      DYNPNR          = SY-DYNNR
*      DYNPROFIELD     = ‘PRUEFLOS’
        TABLES
          value_tab       = value_charg
*          field_tab       = field_tab
          return_tab      = return_tab
        EXCEPTIONS
          parameter_error = 1
          no_values_found = 2
          OTHERS          = 3.
      IF sy-subrc = 0 and return_tab-fieldval <> ”.
        move return_tab-fieldval to charg.
        ls_mod_cell-row_id    = row_id.
        ls_mod_cell-fieldname = ‘CHARG’.
        move charg to lv_value.
        ls_mod_cell-value = lv_value.
        append ls_mod_cell to ir_data_changed->mt_mod_cells.
*******************
        call method gr_alvgrid->get_frontend_fieldcatalog
          IMPORTING
            et_fieldcatalog = lt_fcat.
        read table gt_list index row_id into wa_tab.
        create data lp_wa like line of gt_list.
        assign lp_wa->* to <ls_wa>.
        <ls_wa> = wa_tab.
        read table lt_fcat
           with key fieldname = ls_mod_cell-fieldname into ls_fieldcat.
        move ls_fieldcat-ref_table to l_tabname.
        move ls_fieldcat-fieldname to l_fieldname.
        assign component ls_fieldcat-fieldname
                       of structure wa_tab
                       to <l_field_value>.
**§6 assign the cell table fieldsymbol to the dereferenced data table
*and
*   fill the table.
        assign p_er_event_data->m_data->* to <itab>.
        append ls_mod_cell to <itab>.
….
….
     ENDIF.
….
…..
endcase.

–>

SAP ABAP建立多个SELECTION SCREEN

当用户输入选择条件时,须一步一步确定的时候,可以建立多个选择屏幕,根据用户的选择弹出选择屏幕。

REPORT demo_call_selection_screen.

SELECTION-SCREEN BEGIN OF BLOCK sel1 WITH FRAME TITLE tit1.
PARAMETERS: cityfr TYPE spfli-cityfrom,
             cityto TYPE spfli-cityto.
SELECTION-SCREEN END OF BLOCK sel1.

SELECTION-SCREEN BEGIN OF SCREEN 500 AS WINDOW.
SELECTION-SCREEN INCLUDE BLOCKS sel1.
SELECTION-SCREEN BEGIN OF BLOCK sel2
                           WITH FRAME TITLE tit2.
PARAMETERS: airpfr TYPE spfli-airpfrom,
             airpto TYPE spfli-airpto.
SELECTION-SCREEN END OF BLOCK sel2.
SELECTION-SCREEN END OF SCREEN 500.

INITIALIZATION.
   tit1 = ‘Cities’.

AT SELECTION-SCREEN.
   CASE sy-dynnr.
     WHEN ‘0500’.
       MESSAGE w888(SABAPDOCU) WITH ‘Screen 500’.
     WHEN ‘1000’.
       MESSAGE w888(SABAPDOCU) WITH ‘Screen 1000’.
   ENDCASE.

START-OF-SELECTION.
   tit1 = ‘Cities for Airports’.
   tit2 = ‘Airports’.
   CALL SELECTION-SCREEN 500 STARTING AT 10 10.
   tit1 = ‘Cities again’.
   CALL SELECTION-SCREEN 1000 STARTING AT 10 10.

如何在SAP的Screen中编写List报表

1、相关命令
LEAVE TO LIST-PROCESSING [AND RETURN TO SCREEN <nnnn>].

LEAVE LIST-PROCESSING.

2、使用说明

3、推荐设计思路
设计一个空屏幕,在需要调用list的屏幕的逻辑流中使用CALL SCREEN调用空屏幕。空屏幕的next   screen设置为0,不需要PAI,只需要在PBO中设计一个Module,这个module的具体步骤如下:

  1. 首先调用LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0.
  2. 为list设置GUI status ;如:设置SPACE 或者为自己定义的.
  3. 使用下列语句使空屏幕不输出:

    SUPPRESS DIALOG.

    or

    LEAVE SCREEN. 

  4. 进行List输出和处理.

4、示例
REPORT demo_leave_to_list_processing .
TABLES sdyn_conn.
DATA: wa_spfli TYPE spfli,
       flightdate TYPE sflight-fldate.

CALL SCREEN 100.

MODULE status_0100 OUTPUT.
   SET PF-STATUS ‘SCREEN_100’.
ENDMODULE.

MODULE cancel INPUT.
   LEAVE PROGRAM.
ENDMODULE.

MODULE user_command_0100.
   CALL SCREEN 500.
   SET SCREEN 100.
ENDMODULE.

MODULE call_list_500 OUTPUT.
   LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0.
   SET PF-STATUS space.
   SUPPRESS DIALOG.
   SELECT   carrid connid cityfrom cityto
     FROM   spfli
     INTO   CORRESPONDING FIELDS OF wa_spfli
     WHERE carrid = sdyn_conn-carrid.
     WRITE: / wa_spfli-carrid, wa_spfli-connid,
              wa_spfli-cityfrom, wa_spfli-cityto.
     HIDE: wa_spfli-carrid, wa_spfli-connid.
   ENDSELECT.
   CLEAR: wa_spfli-carrid.
ENDMODULE.

TOP-OF-PAGE.
   WRITE text-001 COLOR COL_HEADING.
   ULINE.

TOP-OF-PAGE DURING LINE-SELECTION.
   WRITE sy-lisel COLOR COL_HEADING.
   ULINE.

AT LINE-SELECTION.
   CHECK not wa_spfli-carrid is initial.
   SELECT   fldate
     FROM   sflight
     INTO   flightdate
     WHERE carrid = wa_spfli-carrid AND
           connid = wa_spfli-connid.
      WRITE / flightdate.
   ENDSELECT.
   CLEAR: wa_spfli-carrid.

该示例屏幕100只包含一个输入字段(SDYN_CONN-CARRID ),在屏幕100的逻辑流中会调用list处理.屏幕100的逻辑流如下:

PROCESS BEFORE OUTPUT.
   MODULE STATUS_0100.

PROCESS AFTER INPUT.
   MODULE CANCEL AT EXIT-COMMAND.
   MODULE USER_COMMAND_0100.

在屏幕100的PAI的module USER_COMMAND_100 将使用CALL SCREEN调用屏幕500。屏幕500的逻辑流中封装了所有List处理,屏幕500的逻辑流如下:

PROCESS BEFORE OUTPUT.
   MODULE CALL_LIST_500.

PROCESS AFTER INPUT.

屏幕500的PBO的module CALL_LIST_500定义了list处理代码。另外由于屏幕500的屏幕流设置为0,该程序从List处理返回时到屏幕100的USER_COMMAND_100的调用CALL SCREEN 500的语句之后.

该程序会在list处理时显示一个明细List,具体代码参见AT LINE-SELECTION、TOP-OF-PAGE 和 TOP-OF-PAGE DURING LINE-SELECTION事件代码.

SAP Uninterested in Enterprise SAAS

SAP对企业级SAAS不感兴趣,这是意料之中的,企业最看重什么?数据安全,服务稳定,成本放在第二位,当然也是要可以承受。如果一个企业级应用系统涉及到数万用户,百亿资金的业务数据,你如何让他放心的把数据保存在自己的企业之外?

SAP的服务定位在企业级应用,SAAS的模式不可能应用于企业级,注意,在大企业中的应用并不代表企业级应用。SAAS只能提供轻量级服务,而SAP提供的则是与业务紧密结合在一起的解决方案,是企业的一部分。

Tash Shifrin, Computerworld

SAP will not plunge into competing in the Software as a Service (SAAS) market for large companies, despite its launch of a hosted enterprise resource planning suite earlier this year, its chief executive has said.

Henning Kagermann told delegates at the Gartner ITxpo in Cannes, France, that SAP would hold its own against the rise of SAAS because of its experience in core enterprise systems to "keep the lights on."

It was "impractical" to bring the approach behind SAP’s new hosted Business ByDesign suite to large enterprises "because it’s so new" and had been built on entirely new technology. Testing with SAP user groups had confirmed that they agreed, he said.

The hosted suite was "designed to the needs" of mid-market companies, but large enterprises would see "proof of concept," Kagermann said. The "first step" for enterprises might be for their smaller subsidiaries to adopt it.

But the technology would be used as a springboard for innovations in SAP’s big business products, Kagermann said. "We will bring to large enterprises accelerated and radical innovations in future. Some of these innovations will follow concepts we’ve developed and proved with Business ByDesign."

SAP was not looking at an immediate move into the multitenancy SAAS market to compete with providers such as Salesforce.com, Kagermann said. "We will think about it. It’s not our first priority because it’s not where we come from."

The ERP giant was "not so interested in ‘drop-in’ services for three or four users, he said. "We want to run the company, we want to run the business, we don’t want to just support some services for some users in the company."

Business ByDesign offered some of the benefits of the multitenancy SAAS model — "we manage it, but we have isolation, we keep the data of the user protected," Kagermann said.

Asked by Gartner analysts if large companies were attracted to the SAAS model, Kagermann said: "I think they want it." In particular, firms would look at it as a first step towards implementing major on-premises customer relationship management projects, he suggested.

"They would prefer a quick win, that could be some CRM functions on demand," he said. They might later want to bring in on-premises software, he said. "That would take the risk and cost down."

Gartner research shows that decisions to implement SAAS were increasingly being made by business unit leaders, bypassing corporate IT departments. But Kagermann denied this made SAAS providers more of a threat to SAP. "Frankly no," he said.

"We see them as competition because without them we could sell even more, no doubt. We see them as competition in a way that keeps us moving and thinking about alternatives — that’s good. I don’t see them as competition in switching and running the show and keeping the lights on instead of us."

SAAS providers had "no track record" of running core business processes, he said. "We are 35 years in this business and we know how to run a big organization round the clock. We know what to do if the CIO calls and says production is down."

He added: "I view it as more of a challenge for us to move even faster in what’s outside the core." Not everything was about "keeping the lights on," Kagermann said. "We want to optimize the [user’s] business, we want to innovate."

原文地址:http://www.pcworld.com/businesscenter/article/139325/sap_uninterested_in_enterprise_saas.html

ABAP 动态内表构建 Dynamic internal table

这两天做了一个这样的需求,其中要求根据用户输入的工资项(T512W-LGART)查找数据,并输出到ALV,要求是输出跟着输入变。由于工资项的配置信息可能会变,因此用于存储要显示的数据的内表就不能预先知道,因此不得不寻求动态内表的构建方法。
其实网上的例子也有不少,但是都缺少说明,折腾了一上午才弄明白一些,写出来与大家分享。
REPORT Z_DT2.
type-pools : abap.
*以t512w为例,构建一个动态内表
tables: t512w.
*field-symbols是一个标志,你可以理解为一个指针,将来创建的内表就要通过它们来访问
field-symbols: type standard table,
,
.
* 这里定义了一个 dy_table 和一个 dy_line 类型是引用,但 to data 未能理解是什么意思,我觉得应该是说指向为空的意思
data: dy_table type ref to data,
dy_line type ref to data,
*用于存储即将构建的动态内表结构
ifc type lvc_t_fcat,
xfc type lvc_s_fcat.
data: begin of t_lgart occurs 0,
LGART like t512w-lgart,
end of t_lgart.
select-options: S_LGART FOR t512w-lgart.
start-of-selection.

*首先从数据库中把符合用户输入的LGART填入内表,将来构建的动态内表每一列就是LGART中的每一行。
select lgart into t_lgart-lgart from t512w where lgart in s_lgart and MOLGA = ’28’.
append t_lgart.
endselect.

*循环读取内表t_lgart,对于每行构建内表
loop at t_lgart.
*这里偷了个懒,因为工资项中会有/103这样的数据,而/是不能用左列明的,大家可以自己写一个替换逻辑,把/替换成_之类的字符。
check t_lgart-lgart+0(1) <> ‘/’.
*列名就用lgart值
xfc-fieldname = t_lgart-lgart.
xfc-datatype = ‘C’.
xfc-inttype = ‘C’.
xfc-intlen = 6.
xfc-decimals = 0.
append xfc to ifc.
endloop.
*此处调用一个方法,这个方法用于构建动态内表,输入的就是要构建的结构,输出的就是一个dy_table,之前定义过,但是并不能直接访问。
call method cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = ifc
IMPORTING
ep_table = dy_table.

*设定指向 dy_table
assign dy_table->* to .

*下面这句建立了一个类型的工作区Work area
create data dy_line like line of .

*同理设定指针
assign dy_line->* to .

于是便动态的建立了一个内表和一个工作区,由于此方法建立的内表没有header line,所以需要一个工作区。
下面是取数或者赋值的方法:
*此行中的xxxx1就是列名
ASSIGN COMPONENT xxxx1 OF STRUCTURE TO .
*此行的作用就是给中的该列一个值
= xxxx2.
*用Append就可以把该行添加到表中了
APPEND TO .
如上所述,即可以动态构建内表,这种方法主要用于表结构无法确定有几列,几有哪些列,尤其与信息配置有关的时候,就只能用这种方法,否则配置一变,程序就不能用了。
才疏学浅,学习体会总结出来希望能对大家有所帮助,有不对的地方希望大家指正,向大家学习!

ABAP开发环境详解

ABAP开发环境从狭义上说是SAP R/3系统的ABAP Workbench,Tcode是SE80,从广义上讲,ABAP开发环境本身构建与SAP 平台,以前是 SAP R/3,版本是3.0~4.71,后来发展到ECC 6.0,开发环境的平台升级为Net Weaver 2004,内部版本是7.0。最新的内部版本7.1 将于2008年7月低向客户Release,7.1版本的ABAP开发环境要优秀的多。

ABAP/4表面看起来很简单,其实是一个复杂的语言。初学者常常感到很迷惑。只有知其然,你才能掌握这个语言。只有知其然并且知其所以然,你才能对这个令人兴奋的知识领域了解别人不了解的内容。

正如熟练的程序员所知道的那样,初学者很快也会知道,创建ABAP/4程序不仅仅是创建一个程序。它常常涉及到创建开发对象(development object)用来支持所创建的程序。

什么是R/3?

R/3是为大公司数据处理所设计的一套集成的应用程序。是由德国的SAP公司开发的(SAP:Systems Applications and Products for data processing)。R/3由运行环境和一组用SAP的4GL语言ABAP/4编写的应用程序所组成。设计这些应用程序是为了满足大型商业应用数据处理的需要。R/3和其以前的版本R/2在制造业非常流行。

R/3的目的是什么?

R/3的唯一目的就是提供一组紧密集成的大型商业应用。这些应用是:

生产计划(PP,Production Planning)
物料管理(MM,Materials Management)
销售和配送(SD,Sales and Distribution)
财务会计(FI,Financial Accounting)
控制(CO,Controlling)
固定资产管理(AM,Fixed Assets Management)
项目管理(PS,Project System)
工作流(WF,Workflow)
IS(IS,Industry Solutions)
人力资源(HR,Human Resources)
工厂维护(PM,Plant Maintenance)
质量管理(QM,Quality Management)
这些应用程序有时被称为R/3的功能模块。

传统上我们是对单个模块进行评估,从多个软件供应商购买这些单独的模块,组装在一起成为数据处理应用。这样在这些单独的模块之间就需要接口。例如,物料管理需要与销售和财务联系,工作流需要从人力资源获得信息。在实施和维护这些接口时花费了大量的时间和金钱。

R/3预置了大多数大公司需要的核心商业应用。这些应用在同一个环境下共存。它们使用的是单个数据库和一组数据表。数据库的大小在12G到接近3T之间。标准的R/3配置有大约8000个数据表。

为什么我们需要知道这些功能模块?

作为一个ABAP/4程序员,知道这些功能模块是重要的。这是因为这些功能模块都是完全用ABAP/4编写的。要想成为一个熟练的R/3开发者,就必须了解这些功能模块。

例如,假定你已熟悉ABAP/4,要求你编写一个财务报表,对企业的每个供应商的年度借贷进行汇总。你或许知道如何编写ABAP代码,你知道如何才能满足这个需求吗?

又或者你的工作是承担了用ABAP/4开发新的应用程序。要求你设计一个系统,向潜在的客户提供股票行情。如果你不了解财务和销售系统,你就不知道你将创建的东西是否在R/3中已经存在了。你也不知道是否已经有了R/3数据表,包含了与你要存储的数据有类似甚至相同类型的数据。这些功能模块是高度集成的。“我要建立自己的数据表,保存自己的数据拷贝”,抱有这样想法的开发者很快就会发现他的数据是多余的,必须与数据库的已有数据同步。这样建立的应用程序没有充分利用R/3环境的高度集成的特性。

我指出这一点是因为许多希望成为独立的咨询顾问的开发者认为,只需学习ABAP/4就可以开发R/3应用。学习ABAP/4当然是一个很好的开始,但仅仅是一个开始。那些有兴趣成为ABAP/4咨询顾问的人常常忽视了在功能模块知识训练的重要性。虽然功能模块知识可以在实际的工作中学习,但是我希望表明的是,学习ABAP/4语言只是迈向SAP万里长征的第一步。如果你希望成为一个成功的独立咨询顾问,你就需要掌握功能模块知识。

了解Basis

Basis就象是R/3的操作系统,它介于ABAP/4代码和计算机操作系统之间。因此,SAP喜欢称之为中间件。

ABAP/4程序不能直接在操作系统上运行,需要一组程序(这组程序就是Basis)对其输入输出进行装载、解释和缓冲。

Basis在某些方面有点像Windows环境。Windows启动后为Windows程序提供了运行环境。没有Windows,为Windows环境编写的程序就不能运行。

Basis对于ABAP/4来说就象Windows对于Windows程序一样。Basis为ABAP/4

程序提供了运行环境。没有Basis,ABAP/4程序就不能运行。当你启动R/3时,你可以认为启动了Basis。Basis是一组带有接口的R/3系统程序,利用这些接口,用户就可以启动ABAP/4程序。

为了安装Basis,安装者在操作系统的命令提示符下运行r3inst程序。像大多数安装过程一样,这将产生一个目录结构,并将一组可执行文件拷贝到这个目录结构。这些可执行文件作为一个整体就形成了Basis。

为了启动R/3系统,只需输入命令startsap。Basis就被启动,处于运行状态,接受用户请求,运行ABAP/4程序。

ABAP/4程序运行在保护性的Basis环境,它们不能在操作系统环境下运行。Basis读取ABAP/4代码,并向操作系统指令解释ABAP/4代码。

ABAP/4程序不能直接访问操作系统的功能,而是利用Basis功能进行文件I/O和在窗口中显示数据。与操作系统的分离使得ABAP/4程序不用修改就可运行在任何支持R/3的系统上。
后文关于Basis的东西省略了,原文:地址