工作生活与爱好

工作中的记录; 生活中的记忆; 业余爱好的记载。

2007-01-18

 

如何将SAP一段时间内已经成本结算了的工单deletion flag 激活 ?

using program "PPARCHP1" to deal with.

Archiving production order have the following step, number one is what you want.

  1. Activation of a deletion flag in the order
  2. Activation of a deletion indicator in the order
  3. Execute an archiving session

 

ALV的简单例子-单击某行调用事务码

Report ZTEST .

TYPE-POOLS: SLIS.
DATA: FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
FIELDCAT_LN LIKE LINE OF FIELDCAT,
SORTCAT TYPE SLIS_T_SORTINFO_ALV,
SORTCAT_LN LIKE LINE OF SORTCAT,
EVENTCAT TYPE SLIS_T_EVENT,
EVENTCAT_LN LIKE LINE OF EVENTCAT.
DATA: COL_POS TYPE I.


Tables: MARA.
data: begin of itab occurs 10,
MATNR like MARA-MATNR,
MTART LIKE MARA-MTART,
BISMT LIKE MARA-BISMT,
end of itab.

SELECT-OPTIONS: P_MATNR FOR MARA-MATNR.

START-OF-SELECTION.
SELECT MATNR
MTART
BISMT
INTO CORRESPONDING FIELDS OF TABLE ITAB
FROM MARA
WHERE MATNR IN P_MATNR.


ADD 1 TO COL_POS.
FIELDCAT_LN-REF_TABNAME = 'MARA'.
FIELDCAT_LN-FIELDNAME = 'MTART'.
FIELDCAT_LN-KEY = SPACE.
FIELDCAT_LN-DO_SUM = SPACE.
FIELDCAT_LN-COL_POS = COL_POS.
FIELDCAT_LN-NO_OUT = SPACE.
FIELDCAT_LN-QFIELDNAME = SPACE.
FIELDCAT_LN-HOTSPOT = SPACE.
APPEND FIELDCAT_LN TO FIELDCAT.

ADD 1 TO COL_POS.
FIELDCAT_LN-REF_TABNAME = 'MARA'.
FIELDCAT_LN-FIELDNAME = 'MATNR'.
FIELDCAT_LN-KEY = SPACE.
FIELDCAT_LN-DO_SUM = SPACE.
FIELDCAT_LN-COL_POS = COL_POS.
FIELDCAT_LN-NO_OUT = SPACE.
FIELDCAT_LN-QFIELDNAME = SPACE.
FIELDCAT_LN-HOTSPOT = SPACE.
APPEND FIELDCAT_LN TO FIELDCAT.

ADD 1 TO COL_POS.
FIELDCAT_LN-REF_TABNAME = 'MARA'.
FIELDCAT_LN-FIELDNAME = 'BISMT'.
FIELDCAT_LN-KEY = SPACE.
*DEFINE AN SUM
FIELDCAT_LN-DO_SUM = 'X'.
FIELDCAT_LN-COL_POS = COL_POS.
FIELDCAT_LN-NO_OUT = SPACE.
FIELDCAT_LN-QFIELDNAME = SPACE.
FIELDCAT_LN-HOTSPOT = SPACE.
APPEND FIELDCAT_LN TO FIELDCAT.


* DEFINE AN SORT TABLE
* ADD SORT INTO SORT INTERNAL TABLE.
SORTCAT_LN-SPOS = '1'.
* DEFINE AN SORT FIELD
SORTCAT_LN-FIELDNAME = 'BISMT'.
SORTCAT_LN-UP = 'X'.
SORTCAT_LN-DOWN = SPACE.
SORTCAT_LN-SUBTOT = 'X'.
APPEND SORTCAT_LN TO SORTCAT.

* DEFINE EVENT LIST(Event Catalogs)
EVENTCAT_LN-NAME = 'TOP_OF_PAGE'.
EVENTCAT_LN-form = 'PAGE_HEADER'.
APPEND EVENTCAT_LN TO EVENTCAT.

* DEFINE ALV CALL Function Module
DATA: PGM LIKE SY-REPID.
PGM = SY-REPID.

CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = PGM
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IT_FIELDCAT = FIELDCAT
IT_SORT = SORTCAT
I_SAVE = 'A'
IT_EVENT = EVENTCAT
TABLES
T_OUTTAB = ITAB
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.


* DEFINE EVENT OF THE USER CLICKED KEYBOARD.

form USER_COMMAND USING UCOMM LIKE SY-UCOMM
SELFIELD TYPE SLIS_SELFIELD.
READ TABLE ITAB INDEX SELFIELD-TABINDEX.
CHECK SY-SUBRC = 0.
CASE UCOMM.
WHEN '&IC1'.
CASE SELFIELD-SEL_TAB_FIELD.
WHEN 'ITAB-MATNR'.
SET PARAMETER ID 'MAT' FIELD ITAB-MATNR.
CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
ENDCASE.
ENDCASE.
ENDform.


 

如何在双击ALV显示的数据中的某一条,调TRANSATION CODE?

* 要在ABAP/4程序中呼叫ALV Function Module来产生输出画面, *有几个叙述是必需做的:
* ?数据变量(Data Area)宣告
* ?宣告Internal Table来存放自数据文件的数据
* ?自数据文件选取数据存放至Internal Table
* ?建立显示字段清单(Field Catalogs)
* ?建立事件清单(Event Catalogs)
* ?呼叫ALV Function Module
* ?撰写User按键处理事件
*数据变量(Data Area)宣告
* 在SAP上预设有一个数据群组(Data Pool) SLIS, *已预先定义好所有ALV所需之数据型态, 程序如下:
program alvtest .
TYPE-POOLS: SLIS.
DATA:
FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
FIELDCAT_LN LIKE LINE OF FIELDCAT,
SORTCAT TYPE SLIS_T_SORTINFO_ALV,
SORTCAT_LN LIKE LINE OF SORTCAT,
EVENTCAT TYPE SLIS_T_EVENT,
EVENTCAT_LN LIKE LINE OF EVENTCAT.
DATA: COL_POS TYPE I.

* 宣告Internal Table
*宣告屏幕显示所需的Internal Table及包含的字段, 如报表要列出 VBAP数据, *Internal Table 定义如下:
DATA: BEGIN OF IVBAP OCCURS 0,
VBELN LIKE VBAP-VBELN,
MATNR LIKE VBAP-MATNR,
MATKL LIKE VBAP-MATKL,
END OF IVBAP.
* 自数据文件选取数据存放至Internal Table
* 选取单号字段不为空白的所有数据记录插入至Internal Table IVBAP:

SELECT VBELN POSNR MATNR MATKL KWMENG VRKME
INTO CORRESPONDING FIELDS OF TABLE IVBAP
FROM VBAP
WHERE VBELN NE SPACE.

* 建立显示字段清单(Field Catalogs)
* 例如显示的字段有 VBELN (Sales Doc.), *MATNR(Material)及MAKTL(Material Group)三个字段, 必须依序设定其属性:
ADD 1 TO COL_POS.
FIELDCAT_LN-REF_TABNAME = 'VBAP'.
FIELDCAT_LN-FIELDNAME = 'VBELN'.
FIELDCAT_LN-KEY = 'X'.
FIELDCAT_LN-DO_SUM = SPACE.
FIELDCAT_LN-COL_POS = COL_POS.
FIELDCAT_LN-NO_OUT = SPACE.
FIELDCAT_LN-QFIELDNAME = SPACE.
FIELDCAT_LN-HOTSPOT = 'X'.
APPEND FIELDCAT_LN TO FIELDCAT.

ADD 1 TO COL_POS.
FIELDCAT_LN-REF_TABNAME = 'VBAP'.
FIELDCAT_LN-FIELDNAME = 'MATNR'.
FIELDCAT_LN-KEY = SPACE.
FIELDCAT_LN-DO_SUM = SPACE.
FIELDCAT_LN-COL_POS = COL_POS.
FIELDCAT_LN-NO_OUT = SPACE.
FIELDCAT_LN-QFIELDNAME = SPACE.
FIELDCAT_LN-HOTSPOT = SPACE.
APPEND FIELDCAT_LN TO FIELDCAT.

ADD 1 TO COL_POS.
FIELDCAT_LN-REF_TABNAME = 'VBAP'.
FIELDCAT_LN-FIELDNAME = 'MATKL'.
FIELDCAT_LN-KEY = SPACE.
FIELDCAT_LN-DO_SUM = 'X'.
FIELDCAT_LN-COL_POS = COL_POS.
FIELDCAT_LN-NO_OUT = SPACE.
FIELDCAT_LN-QFIELDNAME = SPACE.
FIELDCAT_LN-HOTSPOT = SPACE.
APPEND FIELDCAT_LN TO FIELDCAT.

SORTCAT_LN-SPOS = '1'.
SORTCAT_LN-FIELDNAME = 'MATNR'.
SORTCAT_LN-UP = 'X'.
SORTCAT_LN-DOWN = SPACE.
SORTCAT_LN-SUBTOT = 'X'.
APPEND SORTCAT_LN TO SORTCAT.
* 建立事件清单(Event Catalogs)
EVENTCAT_LN-NAME = 'TOP_OF_PAGE'.
EVENTCAT_LN-form = 'PAGE_HEADER'.
APPEND EVENTCAT_LN TO EVENTCAT.
* 呼叫ALV Function Module
DATA: PGM LIKE SY-REPID.
PGM = SY-REPID.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = PGM
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
IT_FIELDCAT = FIELDCAT
IT_SORT = SORTCAT
I_SAVE = 'A'
IT_EVENT = EVENTCAT
TABLES
T_OUTTAB = IVBAP
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
* 撰写User按键处理事件
* 例如我们要加上让User可以连续按鼠标两次后可依游标所在值, 如Sales *Doc*.或Material进入 Sales Doc查询画面(T-Code VA03)或Material **查询画面(T-Code MM03)。
form USER_COMMAND USING UCOMM LIKE SY-UCOMM
SELFIELD TYPE SLIS_SELFIELD.
READ TABLE IVBAP INDEX SELFIELD-TABINDEX.
CHECK SY-SUBRC = 0.
CASE UCOMM.
WHEN '&IC1'.
CASE SELFIELD-SEL_TAB_FIELD.
WHEN 'IVBAP-VBELN'.
SET PARAMETER ID 'AUN' FIELD IVBAP-VBELN.
CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
WHEN 'IVBAP-MATNR'.
SET PARAMETER ID 'MAT' FIELD IVBAP-MATNR.
CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
ENDCASE.
ENDCASE.
ENDform.

把自己定义的按钮和ALV的标准按钮结合起来,也是用的ALV的函数。
eg:
call function 'REUSE_ALV_LIST_DISPLAY'
exporting
i_callback_program = v_repid
i_callback_pf_status_set = 'MENU_SET'
i_callback_user_command = 'EXECUTE_COMMAND'
is_layout = ws_layout
it_fieldcat = ws_fieldcat[]
i_save = g_save
is_variant = g_variant
sp_group = alv_sp_group
it_special_groups = ws_fieldgroups_tab[]
it_sort = ws_sortfields_tab[]
it_events = ws_events[]
i_grid_title = title
tables
t_outtab = itab2
exceptions
program_error = 1
others = 2.

主要是通过两个参数来实现自定义按钮的,两个参数为:“MENU_SET”、“EXECUTE_COMMAND”,然后通过他们对应的两个子函数来实现。
*------------------------------------------------------------*
* Name: form menu_set using rt_extab type slis_t_extab *
* Desc: ALV添加按钮 *
*------------------------------------------------------------*
form menu_set using rt_extab type slis_t_extab..
set pf-status '100'. "定义屏幕状态,然后在里面定义自己的按钮
endform.
*----------------------------------------------------------------*
* Name: form execute_command using r_ucomm like sy-ucomm *
* Desc:响应ALV点击自定义按钮之后的事件 *
*----------------------------------------------------------------*
form execute_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield.
......
case r_ucomm.
when 'TEST'. "在set pf-status '100'.的屏幕状态里面定义的
....
when ..
....
endcase.
endform.

 

ASP与存储过程

ASP与存储过程(Stored Procedures)的文章不少,但是我怀疑作者们是否真正实践过。我在初学时查阅过大量相关资料,发现其中提供的很多方法实际操作起来并不是那么回 事。对于简单的应用,这些资料也许是有帮助的,但仅限于此,因为它们根本就是千篇一律,互相抄袭,稍微复杂点的应用,就全都语焉不详了。
现在,我基本上通过调用存储过程访问SQL Server,以下的文字虽不敢保证绝对正确,但都是实践的总结,希望对大家能有帮助。
存储过程就是作为可执行对象存放在数据库中的一个或多个SQL命令。
定义总是很抽象。存储过程其实就是能完成一定操作的一组SQL语句,只不过这组语句是放在数据库中的(这里我们只谈SQL Server)。如果我们通过创建存储过程以及在ASP中调用存储过程,就可以避免将SQL语句同ASP代码混杂在一起。这样做的好处至少有三个:
第一、大大提高效率。存储过程本身的执行速度非常快,而且,调用存储过程可以大大减少同数据库的交互次数。
第二、提高安全性。假如将SQL语句混合在ASP代码中,一旦代码失密,同时也就意味着库结构失密。
第三、有利于SQL语句的重用。

在ASP中,一般通过command对象调用存储过程,根据不同情况,本文也介绍其它调用方法。为了方便说明,根据存储过程的输入输出,作以下简单分类:
1. 只返回单一记录集的存储过程
假设有以下存储过程(本文的目的不在于讲述T-SQL语法,所以存储过程只给出代码,不作说明):

/*SP1*/
CREATE PROCEDURE dbo.getUserList
as
set nocount on
begin
select * from dbo.[userinfo]
end
go

以上存储过程取得userinfo表中的所有记录,返回一个记录集。通过command对象调用该存储过程的ASP代码如下:

'**通过Command对象调用存储过程**
DIM MyComm,MyRst
Set MyComm = Server.CreateObject("ADODB.Command")
MyComm.ActiveConnection = MyConStr 'MyConStr是数据库连接字串
MyComm.CommandText = "getUserList" '指定存储过程名
MyComm.CommandType = 4 '表明这是一个存储过程
MyComm.Prepared = true '要求将SQL命令先行编译
Set MyRst = MyComm.Execute
Set MyComm = Nothing

存储过程取得的记录集赋给MyRst,接下来,可以对MyRst进行操作。
在以上代码中,CommandType属性表明请求的类型,取值及说明如下:
-1 表明CommandText参数的类型无法确定
1 表明CommandText是一般的命令类型
2 表明CommandText参数是一个存在的表名称
4 表明CommandText参数是一个存储过程的名称

还可以通过Connection对象或Recordset对象调用存储过程,方法分别如下:

'**通过Connection对象调用存储过程**
DIM MyConn,MyRst
Set MyConn = Server.CreateObject("ADODB.Connection")
MyConn.open MyConStr 'MyConStr是数据库连接字串
Set MyRst = MyConn.Execute("getUserList",0,4) '最后一个参断含义同CommandType
Set MyConn = Nothing

'**通过Recordset对象调用存储过程**
DIM MyRst
Set MyRst = Server.CreateObject("ADODB.Recordset")
MyRst.open "getUserList",MyConStr,0,1,4
'MyConStr是数据库连接字串,最后一个参断含义与CommandType相同


2. 没有输入输出的存储过程
请看以下存储过程:

/*SP2*/
CREATE PROCEDURE dbo.delUserAll
as
set nocount on
begin
delete from dbo.[userinfo]
end
go

该存储过程删去userinfo表中的所有记录,没有任何输入及输出,调用方法与上面讲过的基本相同,只是不用取得记录集:

'**通过Command对象调用存储过程**
DIM MyComm
Set MyComm = Server.CreateObject("ADODB.Command")
MyComm.ActiveConnection = MyConStr 'MyConStr是数据库连接字串
MyComm.CommandText = "delUserAll" '指定存储过程名
MyComm.CommandType = 4 '表明这是一个存储过程
MyComm.Prepared = true '要求将SQL命令先行编译
MyComm.Execute '此处不必再取得记录集
Set MyComm = Nothing

当然也可通过Connection对象或Recordset对象调用此类存储过程,不过建立Recordset对象是为了取得记录集,在没有返回记录集的情况下,还是利用Command对象吧。


3. 有返回值的存储过程
在进行类似SP2的操作时,应充分利用SQL Server强大的事务处理功能,以维护数据的一致性。并且,我们可能需要存储过程返回执行情况,为此,将SP2修改如下:

/*SP3*/
CREATE PROCEDURE dbo.delUserAll
as
set nocount on
begin
BEGIN TRANSACTION
delete from dbo.[userinfo]
IF @@error=0
begin
COMMIT TRANSACTION
return 1
end
ELSE
begin
ROLLBACK TRANSACTION
return 0
end
return
end
go

以上存储过程,在delete顺利执行时,返回1,否则返回0,并进行回滚操作。为了在ASP中取得返回值,需要利用Parameters集合来声明参数:

'**调用带有返回值的存储过程并取得返回值**
DIM MyComm,MyPara
Set MyComm = Server.CreateObject("ADODB.Command")
MyComm.ActiveConnection = MyConStr 'MyConStr是数据库连接字串
MyComm.CommandText = "delUserAll" '指定存储过程名
MyComm.CommandType = 4 '表明这是一个存储过程
MyComm.Prepared = true '要求将SQL命令先行编译
'声明返回值
Set Mypara = MyComm.CreateParameter("RETURN",2,4)
MyComm.Parameters.Append MyPara
MyComm.Execute
'取得返回值
DIM retValue
retValue = MyComm(0) '或retValue = MyComm.Parameters(0)
Set MyComm = Nothing

在MyComm.CreateParameter("RETURN",2,4)中,各参数的含义如下:
第一个参数("RETURE")为参数名。参数名可以任意设定,但一般应与存储过程中声明的参数名相同。此处是返回值,我习惯上设为"RETURE";
第二个参数(2),表明该参数的数据类型,具体的类型代码请参阅ADO参考,以下给出常用的类型代码:
adBigInt: 20 ;
adBinary : 128 ;
adBoolean: 11 ;
adChar: 129 ;
adDBTimeStamp: 135 ;
adEmpty: 0 ;
adInteger: 3 ;
adSmallInt: 2 ;
adTinyInt: 16 ;
adVarChar: 200 ;
对于返回值,只能取整形,且-1到-99为保留值;
第三个参数(4),表明参数的性质,此处4表明这是一个返回值。此参数取值的说明如下:
0 : 类型无法确定; 1: 输入参数;2: 输入参数;3:输入或输出参数;4: 返回值

以上给出的ASP代码,应该说是完整的代码,也即最复杂的代码,其实

Set Mypara = MyComm.CreateParameter("RETURN",2,4)
MyComm.Parameters.Append MyPara

可以简化为

MyComm.Parameters.Append MyComm.CreateParameter("RETURN",2,4)

甚至还可以继续简化,稍后会做说明。
对于带参数的存储过程,只能使用Command对象调用(也有资料说可通过Connection对象或Recordset对象调用,但我没有试成过)。


4. 有输入参数和输出参数的存储过程
返回值其实是一种特殊的输入参数。在大多数情况下,我们用到的是同时有输入及输出参数的存储过程,比如我们想取得用户信息表中,某ID用户的用户名,这时候,有一个输入参数----用户ID,和一个输出参数----用户名。实现这一功能的存储过程如下:

/*SP4*/
CREATE PROCEDURE dbo.getUserName
@UserID int,
@UserName varchar(40) output
as
set nocount on
begin
if @UserID is null return
select @UserName=username
from dbo.[userinfo]
where userid=@UserID
return
end
go

调用该存储过程的ASP代码如下:

'**调用带有输入输出参数的存储过程**
DIM MyComm,UserID,UserName
UserID = 1
Set MyComm = Server.CreateObject("ADODB.Command")
MyComm.ActiveConnection = MyConStr 'MyConStr是数据库连接字串
MyComm.CommandText = "getUserName" '指定存储过程名
MyComm.CommandType = 4 '表明这是一个存储过程
MyComm.Prepared = true '要求将SQL命令先行编译
'声明参数
MyComm.Parameters.append MyComm.CreateParameter("@UserID",3,1,4,UserID)
MyComm.Parameters.append MyComm.CreateParameter("@UserName",200,2,40)
MyComm.Execute
'取得出参
UserName = MyComm(1)
Set MyComm = Nothing

在以上代码中,可以看到,与声明返回值不同,声明输入参数时需要5个参数,声明输出参数时需要4个参数。声明输入参数时5个参数分别为:参数名、参数数据类型、参数类型、数据长度、参数值。声明输入参数时,没有最后一个参数:参数值。
需要特别注意的是:在声明参数时,顺序一定要与存储过程中定义的顺序相同,而且各参数的数据类型、长度也要与存储过程中定义的相同。
如果存储过程有多个参数,ASP代码会显得繁琐,可以使用with命令简化代码:

'**调用带有输入输出参数的存储过程(简化代码)**
DIM MyComm,UserID,UserName
UserID = 1
Set MyComm = Server.CreateObject("ADODB.Command")
with MyComm
.ActiveConnection = MyConStr 'MyConStr是数据库连接字串
.CommandText = "getUserName" '指定存储过程名
.CommandType = 4 '表明这是一个存储过程
.Prepared = true '要求将SQL命令先行编译
.Parameters.append .CreateParameter("@UserID",3,1,4,UserID)
.Parameters.append .CreateParameter("@UserName",200,2,40)
.Execute
end with
UserName = MyComm(1)
Set MyComm = Nothing

假如我们要取得ID为1到10,10位用户的用户名,是不是要创建10次Command对象呢?不是的,如果需要多次调用同一存储过程,只需改变输入参数,就会得到不同的输入参数:

'**多次调用同一存储过程**
DIM MyComm,UserID,UserName
UserName = ""
Set MyComm = Server.CreateObject("ADODB.Command")
for UserID = 1 to 10
with MyComm
.ActiveConnection = MyConStr 'MyConStr是数据库连接字串
.CommandText = "getUserName" '指定存储过程名
.CommandType = 4 '表明这是一个存储过程
.Prepared = true '要求将SQL命令先行编译
if UserID = 1 then
.Parameters.append .CreateParameter("@UserID",3,1,4,UserID)
.Parameters.append .CreateParameter("@UserName",200,2,40)
.Execute
else
'重新给入参赋值(此时参数值不发生变化的入参以及出参不必重新声明)
.Parameters("@UserID") = UserID
.Execute
end if
end with
UserName = UserName + MyComm(1) + "," '也许你喜欢用数组存储
next
Set MyComm = Nothing

通过以上代码可以看出:重复调用同一存储过程时,只需为值发生改变的输入参数重新赋值即可,这一方法在有多个输入输出参数,且每次调用时只有一个输入参数的值发生变化时,可以大大减少代码量。


5. 同时具有返回值、输入参数、输出参数的存储过程
前面说过,在调用存储过程时,声明参数的顺序要与存储过程中定义的顺序相同。还有一点要特别注意:如果存储过程同时具有返回值以及输入、输出参数,返回值要最先声明。
为了演示这种情况下的调用方法,我们改善一下上面的例子。还是取得ID为1的用户的用户名,但是有可能该用户不存在(该用户已删除,而userid是自增长的字段)。存储过程根据用户存在与否,返回不同的值。此时,存储过程和ASP代码如下:

/*SP5*/
CREATE PROCEDURE dbo.getUserName
--为了加深对"顺序"的印象,将以下两参数的定义顺序颠倒一下
@UserName varchar(40) output,
@UserID int
as
set nocount on
begin
if @UserID is null return
select @UserName=username
from dbo.[userinfo]
where userid=@UserID
if @@rowcount>0
return 1
else
return 0
return
end
go

'**调用同时具有返回值、输入参数、输出参数的存储过程**
DIM MyComm,UserID,UserName
UserID = 1
Set MyComm = Server.CreateObject("ADODB.Command")
with MyComm
.ActiveConnection = MyConStr 'MyConStr是数据库连接字串
.CommandText = "getUserName" '指定存储过程名
.CommandType = 4 '表明这是一个存储过程
.Prepared = true '要求将SQL命令先行编译
'返回值要最先被声明
.Parameters.Append .CreateParameter("RETURN",2,4)
'以下两参数的声明顺序也做相应颠倒
.Parameters.append .CreateParameter("@UserName",200,2,40)
.Parameters.append .CreateParameter("@UserID",3,1,4,UserID)
.Execute
end with
if MyComm(0) = 1 then
UserName = MyComm(1)
else
UserName = "该用户不存在"
end if
Set MyComm = Nothing


6. 同时返回参数和记录集的存储过程
有时候,我们需要存储过程同时返回参数和记录集,比如在利用存储过程分页时,要同时返回记录集以及数据总量等参数。以下给出一个进行分页处理的存储过程:

/*SP6*/
CREATE PROCEDURE dbo.getUserList
@iPageCount int OUTPUT, --总页数
@iPage int, --当前页号
@iPageSize int --每页记录数
as
set nocount on
begin
--创建临时表
create table #t (ID int IDENTITY, --自增字段
userid int,
username varchar(40))
--向临时表中写入数据
insert into #t
select userid,username from dbo.[UserInfo]
order by userid

--取得记录总数
declare @iRecordCount int
set @iRecordCount = @@rowcount

--确定总页数
IF @iRecordCount%@iPageSize=0
SET @iPageCount=CEILING(@iRecordCount/@iPageSize)
ELSE
SET @iPageCount=CEILING(@iRecordCount/@iPageSize)+1

--若请求的页号大于总页数,则显示最后一页
IF @iPage > @iPageCount
SELECT @iPage = @iPageCount

--确定当前页的始末记录
DECLARE @iStart int --start record
DECLARE @iEnd int --end record
SELECT @iStart = (@iPage - 1) * @iPageSize
SELECT @iEnd = @iStart + @iPageSize + 1

--取当前页记录
select * from #t where ID>@iStart and ID<@iEnd

--删除临时表
DROP TABLE #t

--返回记录总数
return @iRecordCount
end
go

在上面的存储过程中,输入当前页号及每页记录数,返回当前页的记录集,总页数及记录总数。为了更具典型性,将记录总数以返回值的形式返回。以下是调用该存储过程的ASP代码(具体的分页操作略去):

'**调用分页存储过程**
DIM pagenow,pagesize,pagecount,recordcount
DIM MyComm,MyRst
pagenow = Request("pn")
'自定义函数用于验证自然数
if CheckNar(pagenow) = false then pagenow = 1
pagesize = 20
Set MyComm = Server.CreateObject("ADODB.Command")
with MyComm
.ActiveConnection = MyConStr 'MyConStr是数据库连接字串
.CommandText = "getUserList" '指定存储过程名
.CommandType = 4 '表明这是一个存储过程
.Prepared = true '要求将SQL命令先行编译
'返回值(记录总量)
.Parameters.Append .CreateParameter("RETURN",2,4)
'出参(总页数)
.Parameters.Append .CreateParameter("@iPageCount",3,2)
'入参(当前页号)
.Parameters.append .CreateParameter("@iPage",3,1,4,pagenow)
'入参(每页记录数)
.Parameters.append .CreateParameter("@iPageSize",3,1,4,pagesize)
Set MyRst = .Execute
end with
if MyRst.state = 0 then '未取到数据,MyRst关闭
recordcount = -1
else
MyRst.close '注意:若要取得参数值,需先关闭记录集对象
recordcount = MyComm(0)
pagecount = MyComm(1)
if cint(pagenow)>=cint(pagecount) then pagenow=pagecount
end if
Set MyComm = Nothing

'以下显示记录
if recordcount = 0 then
Response.Write "无记录"
elseif recordcount > 0 then
MyRst.open
do until MyRst.EOF
......
loop
'以下显示分页信息
......
else 'recordcount=-1
Response.Write "参数错误"
end if

对于以上代码,只有一点需要说明:同时返回记录集和参数时,若要取得参数,需先将记录集关闭,使用记录集时再将其打开。


7. 返回多个记录集的存储过程
本文最先介绍的是返回记录集的存储过程。有时候,需要一个存储过程返回多个记录集,在ASP中,如何同时取得这些记录集呢?为了说明这一问题,在userinfo表中增加两个字段:usertel及usermail,并设定只有登录用户可以查看这两项内容。

/*SP7*/
CREATE PROCEDURE dbo.getUserInfo
@userid int,
@checklogin bit
as
set nocount on
begin
if @userid is null or @checklogin is null return
select username
from dbo.[usrinfo]
where userid=@userid
--若为登录用户,取usertel及usermail
if @checklogin=1
select usertel,usermail
from dbo.[userinfo]
where userid=@userid
return
end
go

以下是ASP代码:

'**调用返回多个记录集的存储过程**
DIM checklg,UserID,UserName,UserTel,UserMail
DIM MyComm,MyRst
UserID = 1
'checklogin()为自定义函数,判断访问者是否登录
checklg = checklogin()
Set MyComm = Server.CreateObject("ADODB.Command")
with MyComm
.ActiveConnection = MyConStr 'MyConStr是数据库连接字串
.CommandText = "getUserList" '指定存储过程名
.CommandType = 4 '表明这是一个存储过程
.Prepared = true '要求将SQL命令先行编译
.Parameters.append .CreateParameter("@userid",3,1,4,UserID)
.Parameters.append .CreateParameter("@checklogin",11,1,1,checklg)
Set MyRst = .Execute
end with
Set MyComm = Nothing

'从第一个记录集中取值
UserName = MyRst(0)
'从第二个记录集中取值
if not MyRst is Nothing then
Set MyRst = MyRst.NextRecordset()
UserTel = MyRst(0)
UserMail = MyRst(1)
end if
Set MyRst = Nothing

以上代码中,利用Recordset对象的NextRecordset方法,取得了存储过程返回的多个记录集。


至此,针对ASP调用存储过程的各种情况,本文已做了较为全面的说明。最后说一下在一个ASP程序中,调用多个存储过程的不同方法。
在一个ASP程序中,调用多个存储过程至少有以下三种方法都是可行的:
1. 创建多个Command对象。

DIM MyComm
Set MyComm = Server.CreateObject("ADODB.Command")
'调用存储过程一
......
Set MyComm = Nothing
Set MyComm = Server.CreateObject("ADODB.Command")
'调用存储过程二
......
Set MyComm = Nothing
......

2. 只创建一个Command对象,结束一次调用时,清除其参数

DIM MyComm
Set MyComm = Server.CreateObject("ADODB.Command")
'调用存储过程一
.....
'清除参数(假设有三个参数)
MyComm.Parameters.delete 2
MyComm.Parameters.delete 1
MyComm.Parameters.delete 0
'调用存储过程二并清除参数
......
Set MyComm = Nothing

此时要注意:清除参数的顺序与参数声明的顺序相反,原因嘛,我也不知道。

3. 利用Parameters数据集合的Refresh方法重置Parameter对象

DIM MyComm
Set MyComm = Server.CreateObject("ADODB.Command")
'调用存储过程一
.....
'重置Parameters数据集合中包含的所有Parameter对象
MyComm.Parameters.Refresh
'调用存储过程二
.....
Set MyComm = Nothing

一般认为,重复创建对象是效率较低的一种方法,但是经测试(测试工具为Microsoft Application Center Test),结果出人意料:
方法2 >= 方法1 >> 方法3
方法2的运行速度大于等于方法1(最多可高4%左右),这两种方法的运行速度远大于方法3(最多竟高达130%),所以建议在参数多时,采用方法1,在参数较少时,采用方法2。

花了一天的时间,终于把我对于在ASP中调用存储过程的一些粗浅的经验形成了文字。这其中,有些是我只知其果而不明其因的,有些可能是错误的,但是,这些都是经过我亲身实践的。各位看官批判地接受吧。有不同意见,希望一定向我指明,先谢了。

 

正确地使用SAP的标准对话框函数

在用户设计sap的程序时,经常需要一些对话框,用户可以自己编写,但使用SAP系统中提供了的对话框函数将减少许多开发工作。

1、sap的函数组列表和用途说明

适用情况

Function group

提示用户将可能丢失数据

SPO1

提示用户对某个问题选择Yes或者No

SPO1

提示用户将可能丢失数据, 并询问用户是否继续操作

SPO1

提示用户在多个操作中选择一个操作

SPO2

提示用户是继续当前操作或者取消当前操作

SPO2

提示用户输入数据 (可以根据一个表检查或者不检查输入值)

SPO4

将数据显示给用户

SPO4

将详细数据显示给用户

SPO6

从列表中选择数据 SP05

用可滚动的对话框显示数据给用户

STAB

从视图或者数据表中打印数据

STPR

2、函数列表和说明
2.1 SPO1的函数

2.2、Function group SPO2

2.3、Function group SPO4

2.4、Function group SPO6

2.5、Function group SPO5

report rsspo500.
data: selectlist like spopli occurs 5 with header line.
data: antwort type c.
while antwort ne 2.
clear selectlist.
refresh selectlist.
selectlist-varoption = 显示含有单选按钮的弹出框'.
append selectlist.
selectlist-varoption = '显示含有复选框的弹出框'.
selectlist-selflag = 'X'.
append selectlist.
call function 'POPUP_TO_DECIDE_LIST'
exporting
* CURSORLINE = 1
* MARK_FLAG = ' '
mark_max = 1
start_col = 10
start_row = 10
textline1 = 'Text1'
textline2 = 'POPUP_TO_DECIDE_LIST'
textline3 = 'TEXT3'
titel = 'TITLE '
importing
answer = antwort
tables
t_spopli = selectlist
exceptions
not_enough_answers = 1
too_much_answers = 2
too_much_marks = 3
others = 4.
if antwort eq 'A'.
exit.
endif.
endwhile.

if antwort ne 'A'.
clear selectlist.
refresh selectlist.
selectlist-varoption = '最多 15 个选项'.
selectlist-selflag = 'X'.
append selectlist.
selectlist-varoption = '含有复选框'.
selectlist-selflag = 'X'.
append selectlist.
selectlist-varoption = '或单选按钮'.
selectlist-selflag = 'X'.
append selectlist.
selectlist-varoption = '典型的列表功能:'.
selectlist-selflag = 'X'.
append selectlist.
selectlist-varoption = '* 选择'.
selectlist-selflag = 'X'.
append selectlist.
selectlist-varoption = '* 选择全部'.
selectlist-selflag = 'X'.
append selectlist.
selectlist-varoption = ' 取消全部选择'.
selectlist-selflag = 'X'.
append selectlist.
selectlist-varoption = '3 70字符/选项'.
selectlist-selflag = 'X'.
append selectlist.
selectlist-varoption = '65 字符/选项'.
selectlist-selflag = 'X'.
append selectlist.
selectlist-varoption = '激活/不激活可选行'.
selectlist-selflag = 'X'.
selectlist-inactive = 'X'.
append selectlist.

* 2. Aufruf **********************************************************

call function 'POPUP_TO_DECIDE_LIST'
exporting
* CURSORLINE = 1
mark_flag = 'X'
mark_max = 0
start_col = 15
start_row = 15
textline1 = 'Das POPUP bietet'(c01)
textline2 = 'folgende Funktionalit鋞:'(c02)
titel = 'Das Beispiel 2'(b02)
importing
answer = antwort
tables
t_spopli = selectlist
exceptions
not_enough_answers = 1
too_much_answers = 2
too_much_marks = 3
others = 4.

endif.

 

如何在REUSE_ALV_GRID_DISPLAY标识不同行用不同的颜色

1 在内表中加入颜色字段
.............................
color(4) type c,
................................

2 在内表添加记录是通过条件设置颜色字段值
wa_customerinfo-color = 'C110'.

3 设置颜色控制内表 slis_layout_alv 的颜色字段为内表增加的颜色字段
data g_slis_layo type slis_layout_alv. "定义Grid输出颜色控制内表
g_slis_layo-info_fieldname = 'COLOR'.

4 输出记录
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = g_repid
is_layout = g_slis_layo
it_fieldcat = g_field[]
it_sort = g_sort[]
it_events = event_top_of_page[]
tables
t_outtab = i_customerinfo.

以下为显示表头的代码
data event_top_of_page type slis_alv_event occurs 0 with header line.
perform event_top_of_page tables event_top_of_page.

form event_top_of_page tables rt_event type slis_t_event.
refresh rt_event.
clear rt_event.
rt_event-name = slis_ev_top_of_page.
rt_event-form = 'WRITE_TOP_OF_PAGE'.
append rt_event.
endform. "event_top_of_page

form write_top_of_page.
data: hline type slis_listheader,
text(60) type c,
text10(10) type c,
text5(5) type c,
percent type p decimals 2.

refresh head.
clear head.
clear: hline, text.
hline-typ = 'S'.
write: '时间:', g_curdate to text.
hline-info = text.
append hline to head.
write: '客户状态:绿色-老呆死客户,红色-新呆死客户,兰色-超信用额度客户'
to text.
hline-info = text.
write: g_countkunnr to text5.
append hline to head.
concatenate '往来单位:' text5 '个.' into text.
hline-info = text.
append hline to head.
write: g_oldbad_count to text5.
concatenate '老呆死帐单位:' text5 '个,占' into text.
percent = g_oldbad_count * 100 / g_countkunnr.
write: percent to text5.
concatenate text5 '%' into text+23.
write: g_newbad_count to text5.
concatenate '新呆死单位:' text5 '个,占' into text+30.
percent = g_newbad_count * 100 / g_countkunnr.
write: percent to text5.
concatenate text5 '%' into text+53.
* CONDENSE text.
hline-info = text.
append hline to head.
clear text.
percent = g_ccdebit_count / 10000.
write: percent to text10.
concatenate '应收帐款:' text10 '万元' into text.
percent = g_webtr_count / 10000.
write: percent to text10.
concatenate '认可呆死帐:' text10 '万元.' into text+30.
hline-info = text.
append hline to head.

percent = g_oldbad_money / 10000.
write: percent to text10.
concatenate '老呆死帐款:' text10 '万元,' into text.
percent = g_oldbad_money * 100 / g_ccdebit_count.
write: percent to text5.
concatenate '占' text5 '%' into text+30.
hline-info = text.
append hline to head.

percent = g_newbad_money / 10000.
write: percent to text10.
concatenate '新呆死帐款:' text10 '万元,' into text.
percent = g_newbad_money * 100 / g_ccdebit_count.
write: percent to text5.
concatenate '占' text5 '%' into text+30.
hline-info = text.
append hline to head.

write: g_over_count to text5.
concatenate '超安全额度单位:' text5 '个,' into text.
percent = g_over_count * 100 / g_countkunnr.
write: percent to text5.
concatenate '占' text5 '%' into text+24.
percent = g_over_money / 10000.
write: percent to text10.
concatenate '超安全额度:' text10 '万元.' into text+30.
hline-info = text.
append hline to head.
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
it_list_commentary = head.
endform. "write_top_of_page


 

将数字金额转换为人民币大写字符串

function z_convert_numeric_to_chinese.
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(PI_MONEY) LIKE BSEG-DMBTR
*" EXPORTING
*" REFERENCE(PO_CHINESE)
*" EXCEPTIONS
*" WRONG_MONEY
*"----------------------------------------------------------------------
if pi_money = 0.
po_chinese = '零'.
exit.
endif.
data:money_str(13).
money_str = pi_money.
if money_str cn '0123456789. '.
raise wrong_money.
endif.
data:i type i.
if money_str cs '.'.
i = sy-fdpos + 1.

money_str+sy-fdpos = money_str+i.
endif.
condense money_str no-gaps.
data:units_off type i,
curnt_off type i.
data:lastd type n,curntd type n.
data:cword(2),weight(2).
data:units(30) value '分角元拾佰仟万拾佰仟亿拾佰仟万',
digts(20) value '零壹贰叁肆伍陆柒捌玖'.
* clear:po_chinese,units_off.
lastd = 0.
curnt_off = strlen( money_str ) - 1.
while curnt_off >= 0.
curntd = money_str+curnt_off(1).
i = curntd * 2.
cword = digts+i(2).

weight = units+units_off(2).


i = units_off / 2.
if curntd = 0. "Current digit is 0
if i = 2 or i = 6 or i = 10.
clear:cword.
if curnt_off = 0.
clear:weight.
endif.
elseif lastd = 0.
clear:cword,weight.
else.
clear:weight.
endif.
endif.
concatenate cword weight po_chinese into po_chinese.
lastd = curntd.
subtract 1 from curnt_off.
add 2 to units_off.
endwhile.
if po_chinese ns '分'.
concatenate po_chinese '整' into po_chinese.
else.
cword = po_chinese.
if cword = '零'.
shift po_chinese by 2 places.
endif.
endif.
endfunction.





FUNCTION Z_DIGITAL_LOWER_TO_UPPER.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(DIGITALIN) TYPE C
*" EXPORTING
*" REFERENCE(DIGITALOUT) TYPE C
*"----------------------------------------------------------------------

CASE digitalin.
WHEN '0'.
digitalout = '零'.
WHEN '1'.
digitalout = '壹'.
WHEN '2'.
digitalout = '贰'.
WHEN '3'.
digitalout = '叁'.
WHEN '4'.
digitalout = '肆'.
WHEN '5'.
digitalout = '伍'.
WHEN '6'.
digitalout = '陆'.
WHEN '7'.
digitalout = '柒'.
WHEN '8'.
digitalout = '捌'.
WHEN '9'.
digitalout = '玖'.

WHEN OTHERS.
digitalout = 'E'.
ENDCASE.
ENDFUNCTION.







*---------------------------------------------------------------
* CREATE BY:
* CREATE DATE:
* MODIFY BY:
* MODIFY DATE:
*
* 函数功能:完成金额从小写向中文大写的转换。
*
* 其他说明:效率不高,有改进空间。
*---------------------------------------------------------------

FUNCTION z_money_lower_to_upper.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" REFERENCE(MONEYIN) TYPE SALK3 DEFAULT 1
*" EXPORTING
*" REFERENCE(MONEYOUT) TYPE C
*"----------------------------------------------------------------------

DATA: ipos TYPE i,
iwan TYPE i,
imod TYPE i,
pin TYPE p DECIMALS 2,
strint TYPE c LENGTH 10,
strdec TYPE c LENGTH 3,
strintt TYPE c,
strintd TYPE c,
strintu TYPE c LENGTH 40,
strdect TYPE c,
strdecd TYPE c,
strdecu TYPE c LENGTH 4.

pin = moneyin.
IF pin EQ 0.
ipos = 0.
ELSE.
ipos = FLOOR( LOG10( pin ) ) + 1. "计算数值pin的整数位数。
ENDIF.
*write / ipos.

*计算小数部分
pin = pin * 100. "将数值的百分位变为个位,便于处理。
strdect = pin - pin DIV 10 * 10. "获取数值的百分位,也就是分。
IF strdect NE '0'. "如果值为0,则不显示该值,直接跳过。
CALL FUNCTION 'Z_DIGITAL_LOWER_TO_UPPER' "调用数值小写转大写的函数,获得大写的数字。
EXPORTING
digitalin = strdect
IMPORTING
digitalout = strdecd.
CONCATENATE strdecd '分' INTO strdecu. "生成金额的“分”。
ENDIF.
pin = pin DIV 10. "将十分位变为个位。
strdect = pin - pin DIV 10 * 10. "获取数值的十分位,也就是角。
IF strdect EQ '0' AND strdecu EQ ''. "如果角为0,分也为0,则金额的小数部分就没有。
strdecu = ''.
ELSEIF strdect EQ '0' AND strdecu NE ''. "如果角为0,分不为0,则角位只写“零”不写“角”。
CONCATENATE '零' strdecu INTO strdecu.
ELSE. "如果角不为0,则直接与前面生成的分进行拼接。
CALL FUNCTION 'Z_DIGITAL_LOWER_TO_UPPER' "调用数值小写转大写的函数。
EXPORTING
digitalin = strdect
IMPORTING
digitalout = strdecd.
CONCATENATE strdecd '角' strdecu INTO strdecu. "生成金额的“角”和“分”
ENDIF.
pin = pin DIV 10. "恢复原来的整数位。

iwan = 0. "万位标记,四个数值位为一“万”,从个位开始,所以iwan的初值为0。
*计算整数部分
DO ipos TIMES.
strintt = pin - pin DIV 10 * 10.
imod = iwan MOD 4.
IF imod EQ 0.
IF iwan = 0.
IF strintt NE '0'.
CALL FUNCTION 'Z_DIGITAL_LOWER_TO_UPPER'
EXPORTING
digitalin = strintt
IMPORTING
digitalout = strintd.
strintu = strintd.
ENDIF.
ELSEIF iwan = 4.
IF strintt NE '0'.
CALL FUNCTION 'Z_DIGITAL_LOWER_TO_UPPER'
EXPORTING
digitalin = strintt
IMPORTING
digitalout = strintd.
ELSE.
strintd = ''.
ENDIF.
CONCATENATE strintd '万' strintu INTO strintu.
ELSEIF iwan = 8.
IF strintt NE '0'.
CALL FUNCTION 'Z_DIGITAL_LOWER_TO_UPPER'
EXPORTING
digitalin = strintt
IMPORTING
digitalout = strintd.
ELSE.
strintd = ''.
ENDIF.
CONCATENATE strintd '亿' strintu INTO strintu.
ENDIF.
ENDIF.
IF imod EQ 1.
IF strintt NE '0'.
CALL FUNCTION 'Z_DIGITAL_LOWER_TO_UPPER'
EXPORTING
digitalin = strintt
IMPORTING
digitalout = strintd.
CONCATENATE strintd '拾' strintu INTO strintu.
ELSEIF strintd NE '零'.
CONCATENATE '零' strintu INTO strintu.
ENDIF.
ENDIF.
IF imod EQ 2.
IF strintt NE '0'.
CALL FUNCTION 'Z_DIGITAL_LOWER_TO_UPPER'
EXPORTING
digitalin = strintt
IMPORTING
digitalout = strintd.
CONCATENATE strintd '佰' strintu INTO strintu.
ELSEIF strintd NE '零'.
CONCATENATE '零' strintu INTO strintu.
ENDIF.
ENDIF.
IF imod EQ 3.
IF strintt NE '0'.
CALL FUNCTION 'Z_DIGITAL_LOWER_TO_UPPER'
EXPORTING
digitalin = strintt
IMPORTING
digitalout = strintd.
CONCATENATE strintd '仟' strintu INTO strintu.
ELSEIF strintd NE '零'.
CONCATENATE '零' strintu INTO strintu.
ENDIF.
ENDIF.
pin = pin DIV 10.
iwan = iwan + 1.
* write: / iwan, strintt, strintu, imod.
ENDDO.

*连接整数位和小数位。
CONCATENATE strintu '元' strdecu INTO moneyout.

*把“零亿”、“零万”、“零元”都替换掉。
REPLACE '零零' WITH '零' INTO moneyout.
REPLACE '零亿' WITH '亿' INTO moneyout.
REPLACE '零万' WITH '万' INTO moneyout.
REPLACE '零元' WITH '元' INTO moneyout.
IF ipos EQ 0.
moneyout = '零元'.
ENDIF.

ENDFUNCTION.

 

SAP显示处理进度的函数

*---------------------------------------------------------------------*
* FORM PROGRESS_INDICATOR *
*---------------------------------------------------------------------*
form progress_indicator
using value(v_text) type c "输出文本
value(v_processed) like sy-tabix "处理计数
value(v_total) like sy-tabix "总计数
value(v_new) type c.

statics: s_time_next like sy-uzeit,
s_date_next like sy-datum.

data: l_percentage type i,
l_text(72) type c.

get time.
if v_new is initial.
check s_date_next < sy-datum
or s_date_next = sy-datum and s_time_next <= sy-uzeit.
endif.

l_percentage = ( v_processed * 100 ) div v_total.
if l_percentage > 0.
write l_percentage to l_text.
condense l_text.
concatenate l_text '%' into l_text.
condense l_text.
endif.
concatenate l_text v_text into l_text separated by space.
condense l_text.
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
percentage = l_percentage
text = l_text.

s_date_next = sy-datum.
s_time_next = sy-uzeit + 10.
if s_time_next < sy-uzeit.
add 1 to s_date_next.
endif.
endform. "PROGRESS_INDICATOR


*----------------------------------------------------------------------*
* Form WRITE_SAPGUI_TEXT
*----------------------------------------------------------------------*
* write a progress message on the GUI
*----------------------------------------------------------------------*
FORM write_sapgui_text USING p_text.

CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
text = p_text.

ENDFORM. " WRITE_SAPGUI_TEXT

*----------------------------------------------------------------------*
* Form WRITE_SAPGUI_PERC
*----------------------------------------------------------------------*
* write a progress message on the GUI
*----------------------------------------------------------------------*
FORM write_sapgui_perc USING p_text p_perc.

CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
text = p_text
percentage = p_perc.

ENDFORM. " WRITE_SAPGUI_PERC


 

将EXCEL文件上传到SAP AS的内表

REPORT ZEXCELUP.

TABLES: ALSMEX_TABLINE.

DATA: BEGIN OF IEXCEL OCCURS 0.
INCLUDE STRUCTURE ALSMEX_TABLINE.
DATA: END OF IEXCEL.

* No of columns
DATA: BEGIN OF data_tab OCCURS 0,
value_0001(50),
value_0002(50),
value_0003(50),
value_0004(50),
value_0005(50),
value_0006(50),
value_0007(50),
value_0008(50),
value_0009(50),
value_0010(50),
value_0011(50),
value_0012(50),
value_0013(50),
value_0014(50),
value_0015(50),
value_0016(50),
value_0017(50),
value_0018(50),
value_0019(50),
value_0020(50),
value_0021(50),
value_0022(50),
value_0023(50),
value_0024(50),
value_0025(50),
value_0026(50),
value_0027(50),
value_0028(50),
value_0029(50),
value_0030(50),
value_0031(50),
value_0032(50),
value_0033(50),
value_0034(50),
value_0035(50),
value_0036(50),
value_0037(50),
value_0038(50),
value_0039(50),
value_0040(50),
value_0041(50),
value_0042(50),
value_0043(50),
value_0044(50),
value_0045(50),
value_0046(50),
value_0047(50),
value_0048(50),
value_0049(50),
value_0050(50),
value_0051(50),
value_0052(50),
value_0053(50),
value_0054(50),
value_0055(50),
value_0056(50),
value_0057(50),
value_0058(50),
value_0059(50),
value_0060(50),
value_0061(50),
value_0062(50),
value_0063(50),
value_0064(50),
value_0065(50),
value_0066(50),
value_0067(50),
value_0068(50),
value_0069(50),
value_0070(50),
value_0071(50),
value_0072(50),
value_0073(50),
value_0074(50),
value_0075(50),
value_0076(50),
value_0077(50),
value_0078(50),
value_0079(50),
value_0080(50),
value_0081(50),
value_0082(50),
value_0083(50),
value_0084(50),
value_0085(50),
value_0086(50),
value_0087(50),
value_0088(50),
value_0089(50),
value_0090(50),
value_0091(50),
value_0092(50),
value_0093(50),
value_0094(50),
value_0095(50),
value_0096(50),
value_0097(50),
value_0098(50),
value_0099(50),
value_0100(50).
DATA: END OF data_tab.

DATA: tind(4) TYPE n.
DATA: zwfeld(19).
FIELD-SYMBOLS: .

PARAMETERS: FILENM LIKE rlgrap-filename MEMORY ID M01,
NOHEADER AS CHECKBOX.

call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = FILENM
i_begin_col = 1
i_begin_row = 1
i_end_col = 100
i_end_row = 30000
tables
intern = IEXCEL
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.

if sy-subrc <> 0.
WRITE: / 'EXCEL UPLOAD FAILED ', FILENM, SY-SUBRC.
ELSE.
SORT IEXCEL BY row col.
LOOP AT IEXCEL.
IF NOHEADER = 'X'
AND IEXCEL-row = 1.
CONTINUE.
ENDIF.
tind = IEXCEL-col.
CONCATENATE 'DATA_TAB-VALUE_' tind INTO zwfeld.
ASSIGN (zwfeld) TO .
= IEXCEL-value.
AT END OF row.
APPEND data_tab.
WRITE:/ 'data_tab ', data_tab-value_0001, data_tab-value_0002,
data_tab-value_0003, data_tab-value_0004.
CLEAR data_tab.
ENDAT.
ENDLOOP.
endif.


 

如何限制自己开发的耗时报表在sap系统中运行的个数,以保证正常业务的进行

在SAP 系统中经常有许多用户自行开发的报表,有些报表运行很 耗时。如果这种报表被多个用户同时执行,通常会把服务器工作进程资源占用,导致业务操作无法正常进 行。这里提去一个变通的做法,限制自行开发的耗时报表的运行个数,保证服务器工作进程资源对业务操作的响应。具体做法如下:

1、建立耗时报表登记表(zauth0003),结构如下
MANDT 集团
REPORT 耗时程序名

2、建立允许运行耗时报表的同时个数表( zauth0002),结构如下
MANDT 集团
ZNUM 个数

3、建立检查函数
function z_auth_cpu.
*"----------------------------------------------------------------------
*"*"Local interface:
*" EXPORTING
*" REFERENCE(Z_RETURN_ERROR) TYPE SY-SUBRC
*"----------------------------------------------------------------------
data: begin of wp_tabl occurs 10.
include structure wpinfo.
data: end of wp_tabl.
data: with_cpu type x value 0,
inum type i.
z_return_error = 0.
inum = 0.
refresh wp_tabl.
select single * from zauth0002.
if sy-subrc <> 0 or zauth0002-znum = 0.
zauth0002-znum = 5.
endif.
select single * from zauth0003 where report = sy-cprog.
if sy-subrc = 0.
call function 'TH_WPINFO'
exporting
with_cpu = with_cpu
tables
wplist = wp_tabl
exceptions
others = 0.
loop at wp_tabl.
select single * from zauth0003
where report = wp_tabl-wp_report.
if sy-subrc = 0.
inum = inum + 1.
endif.
endloop.
endif.
if inum > zauth0002-znum.
z_return_error = 4.
endif.
endfunction.

4、在程序中写入以下代码,检查是否可运行。

data:t_return_code like sy-subrc.

*判断用否可以运算
data:t_return_error like sy-subrc.
call function 'Z_AUTH_CPU'
importing
z_return_error = t_return_error.
if t_return_error > 0.
message e100 with '服务器达到最大会话数,请稍后再试'.
exit.
endif.


 

关于sap的字段和对象修改记录的查找

sap的字段和对象的修改都会保存旧值,数据保存在CDHDR和CDPOS表中,对于提取旧值你可以采用两种方法

1)使用sap的标准函数CHANGEDOCUMENT_READ_HEADERS 和CHANGEDOCUMENT_READ_POSITIONS

2)使用select语句直接从表中读取。

直接使用SELECT语句读取数据的示例:

*提取信用额度字段修改的抬头信息
select cdhdr~changenr cdhdr~udate cdhdr~utime
into corresponding fields of table p_cdhdr
from cdhdr
where cdhdr~objectclas = 'KLIM' and
cdhdr~objectid = wa_customerinfo-kunnr.
if sy-subrc = 0.
*提取信用额度字段修改的字段值
select cdpos~changenr cdpos~value_old cdpos~value_new
into corresponding fields of table p_cdpos
from cdpos
for all entries in p_cdhdr
where cdpos~objectclas = 'KLIM' and
cdpos~objectid = wa_customerinfo-kunnr and
cdpos~changenr = p_cdhdr-changenr and
cdpos~tabname = 'KNKK' and
cdpos~fname = 'KLIMK'.
if sy-subrc = 0.
endif.
endif.

可以在CHANGEDOCUMENT_READ_HEADERS 中设置中断获得对象类型。

 

SAP的SCreen录入的简单模板

1、主程序单元

************************************************************************
* Copyright 2003 *
* All Rights Reserved *
*----------------------------------------------------------------------*
* Program Name : ZFIE0005 *
* TYPE : REPORT *
* Project :SAP Implementation Project *
* Program Title: 管理部门年度预算考核额调整
* Created by : DEV01 *
* Created on :
* Version : 1.0 *
* Function Description: *
* 管理部门年度预算考核额调整
*----------------------------------------------------------------------*
*操作数据表
*ZFI017
*----------------------------------------------------------------------*
*引用数据表
*
*----------------------------------------------------------------------*
* Modification Log: *
* Date Programmer Correction Number DesingDoc Number *
************************************************************************
include zfie0032top."全局变量说明但愿
include zfie0032o01."输出Module说明单元
include zfie0032i01."输入Module说明单元
include zfie0032f01."共用函数说明单元
include zfie0032fi1."输入函数说明单元
include zfie0032fi2."输入函数说明单元
include zfie0032h01."输入帮助说明单元

2、 zfie0032top单元
************************************************************************
* Copyright 2003 *
* All Rights Reserved *
*----------------------------------------------------------------------*
* Program Name : ZFIE0005 *
* TYPE : REPORT *
* Project :SAP Implementation Project *
* Program Title: 管理部门年度预算考核额调整
* Created by : DEV01 *
* Created on :
* Version : 1.0 *
* Function Description: *
* 管理部门年度预算考核额调整
*----------------------------------------------------------------------*
*操作数据表
*ZFI017
*----------------------------------------------------------------------*
*引用数据表
*
*----------------------------------------------------------------------*
* Modification Log: *
* Date Programmer Correction Number DesingDoc Number *
************************************************************************
report zfie0030 message-id zdev.
constants: con_show(6) value 'SHOW',
con_change(6) value 'CHANGE'.
class cl_gui_cfw definition load.
tables: zfi017v,*zfi017v,bseg,setheadert,zfi010,zfi017,csku,cskt. "
*公司,年份,次数的新旧值
data: v_bukrs like zfi017-bukrs,
v_gjahr like zfi017-gjahr,
v_zmon like zfi017-zmon,
v_oldbukrs like zfi017-bukrs,
v_oldgjahr like zfi017-gjahr,
v_oldzmon like zfi017-zmon.
*grid的控件
controls: tctrl_order type tableview using screen '0100'.
data: col type cxtab_column.
* Table for all entries loaded from database
data: begin of order_extract occurs 0100.
include structure zfi017v.
include structure vimflagtab.
data: end of order_extract.
* Table for entries selected to show on screen
data: begin of order_total occurs 10.
include structure zfi017v.
include structure vimflagtab.
data: end of order_total.
*记录数据的状态信息的变量定义
data: begin of status_order. "state vector
include structure vimstatus.
data: end of status_order.
data: grid_item type i.
data: answer(1) type c,
actionmode(6),
datastate(1),
mark_total type i,
init(1),
first_flag(1).
data: wa_zfi017v type zfi017v.
data: ok_code like sy-ucomm,
save_ok like sy-ucomm. "OK-Code
data g_return_code type i.
data: vim_marked(1) type c. "mark-checkbox field
*存储屏幕选择的字段名
data indexfldname(30).
data: gt_fieldcatalog type lvc_t_fcat,
text(70).
**********************************************************
*用于帮助的变量说明
*屏幕字段的帮助函数使用的变量
*用于成本要素组的属于帮助
data: begin of i_zfi010 occurs 0,
name like zfi010-name,
end of i_zfi010.
*用于成本中心的输入帮助
data: begin of i_setheadert occurs 0,
ktext like cskt-ktext,
end of i_setheadert.
data: butxt like t001-bukrs.
data: ktext like cskt-kostl.
data: name like zfi010-name.
*用于输入帮助,存储帮助函数的通讯内表
data: begin of fldtab occurs 2.
include structure help_value.
data: end of fldtab.
data: f4dyn like sy-dynnr.
data: begin of f4hlp occurs 1.
include structure dynpread.
data: end of f4hlp.

3、ZFIE0032O01单元
************************************************************************
* Copyright 2003 C-Bons Wuhan *
* All Rights Reserved *
*----------------------------------------------------------------------*
* Program Name : ZFIE0005 *
* TYPE : REPORT *
* Project : SAP Implementation Project *
* Program Title: 管理部门年度预算考核额调整
* Created by : DEV01 *
* Created on :
* Version : 1.0 *
* Function Description: *
* 管理部门年度预算考核额调整
*----------------------------------------------------------------------*
*操作数据表
*ZFI017
*----------------------------------------------------------------------*
*引用数据表
*
*----------------------------------------------------------------------*
* Modification Log: *
* Date Programmer Correction Number DesingDoc Number *

************************************************************************
************************************************************************
*&Form Name : init_data
* Created by : DEV01 *
* Created on :
*----------------------------------------------------------------------*
* Function Description: *
*根据用户输入条件的变化,进行数据读取
*----------------------------------------------------------------------*
*参数说明
*
*----------------------------------------------------------------------*
* Date Programmer Description *

************************************************************************
module init_data output.
if first_flag eq space.
first_flag = 'X'.
v_gjahr = sy-datum+0(4).
bseg-pswsl = 2.
endif.
if ( v_oldgjahr ne v_gjahr or v_oldbukrs ne v_bukrs and
v_oldzmon ne v_zmon ) and
v_gjahr ne space and v_bukrs ne space and v_zmon ne space.
perform fill_data.
else.
* SET CURSOR FIELD f LINE lin OFFSET o.
endif.
endmodule. " init_data OUTPUT
************************************************************************
*&Form Name : init_pbo
* Created by : DEV01 *
* Created on :
*----------------------------------------------------------------------*
* Function Description: *
*设置标题栏和工具条按钮
*----------------------------------------------------------------------*
*参数说明
*
*----------------------------------------------------------------------*
* Date Programmer Description *

************************************************************************
module init_pbo output.
set pf-status 'MAIN100'.
set titlebar 'MAINTITLE'.
endmodule. " PBO OUTPUT
************************************************************************
*&Form Name :liste_show_liste
* Created by : DEV01 *
* Created on :
*----------------------------------------------------------------------*
* Function Description: *
*将显示数据写到显示字段中,并设置主键字段是否可输入
*----------------------------------------------------------------------*
*参数说明
*
*----------------------------------------------------------------------*
* Date Programmer Description *

************************************************************************
module liste_show_liste output.
if tctrl_order-current_line gt tctrl_order-lines.
exit from step-loop.
endif.
grid_item = sy-loopc.
zfi017v-kostl = order_extract-kostl.
zfi017v-ktext = order_extract-ktext.
zfi017v-kstar = order_extract-kstar.
zfi017v-descript = order_extract-descript.
zfi017v-adamt = order_extract-adamt.
zfi017v-reasn = order_extract-reasn.
zfi017v-zyearmonth = order_extract-zyearmonth.
vim_marked = order_extract-mark.
loop at screen.
if ( order_extract-action = 'L'
and screen-name = 'VIM_MARKED' ).
screen-input = 0.
modify screen.
endif.
if ( zfi017v-kostl ne space
and screen-name = 'ZFI017V-KOSTL' ) or
( zfi017v-kstar ne space
and screen-name = 'ZFI017V-KSTAR' ) .
screen-input = 0.
modify screen.
endif.
endloop.
if vim_marked = 'M'.
vim_marked = 'X'.
endif.
endmodule. " LISTE_SHOW_LISTE OUTPUT
************************************************************************
*&Form Name : fill_data
* Created by : DEV01 *
* Created on :
*----------------------------------------------------------------------*
* Function Description: *
*根据用户输入读取数据并初试化状态变量
*----------------------------------------------------------------------*
*参数说明
*
*----------------------------------------------------------------------*
* Date Programmer Description *

************************************************************************
form fill_data .
select *
into corresponding fields of order_extract
from zfi017
where zfi017~bukrs = v_bukrs
and zfi017~gjahr = v_gjahr
and zfi017~zmon = v_zmon.
select single cskt~ktext as descript
into (order_extract-descript)
from cskt
where spras = '1'
and kokrs = '1000'
and kostl = order_extract-kostl.
select single ktext
into (order_extract-ktext)
from csku
where spras = '1' and ktopl ='CB00'
and kstar = order_extract-kstar.
append order_extract.
endselect.
sort order_extract by bukrs gjahr kostl kstar.
* order_extract[] = order_total[].
if actionmode = con_change.
perform insert_newworkarea using grid_item.
endif.
describe table order_extract lines tctrl_order-lines.
tctrl_order-top_line = 1.
clear ok_code.
mark_total = 1.
clear:datastate,status_order.
v_oldgjahr = v_gjahr.
v_oldbukrs = v_bukrs.
endform. " fill_data
************************************************************************
*&Form Name : init_ctrl
* Created by : DEV01 *
* Created on :
*----------------------------------------------------------------------*
* Function Description: *
*根据数据状态,设置屏幕字段是否可以输入
*----------------------------------------------------------------------*
*参数说明
*
*----------------------------------------------------------------------*
* Date Programmer Description *

************************************************************************
module init_ctrl output.
if actionmode eq space.
actionmode = con_show.
endif.
if con_show eq actionmode.
loop at screen.
case screen-name.
when 'V_BUKRS'.
screen-input = 1.
modify screen.
when 'V_GJAHR'.
screen-input = 1.
modify screen.
when 'V_ZMON'.
screen-input = 1.
modify screen.
endcase.
endloop.
read table tctrl_order-cols into col
with key screen-name = 'ZFI017V-KOSTL'.
if sy-subrc = 0.
col-screen-input = '0'.
modify tctrl_order-cols index sy-tabix from col.
endif.
read table tctrl_order-cols into col
with key screen-name = 'ZFI017V-KSTAR'.
if sy-subrc = 0.
col-screen-input = '0'.
modify tctrl_order-cols index sy-tabix from col.
endif.
read table tctrl_order-cols into col
with key screen-name = 'ZFI017V-ADAMT'.
if sy-subrc = 0.
col-screen-input = '0'.
modify tctrl_order-cols index sy-tabix from col.
endif.
read table tctrl_order-cols into col
with key screen-name = 'ZFI017V-REASN'.
if sy-subrc = 0.
col-screen-input = '0'.
modify tctrl_order-cols index sy-tabix from col.
endif.
read table tctrl_order-cols into col
with key screen-name = 'ZFI017V-ZYEARMONTH'.
if sy-subrc = 0.
col-screen-input = '0'.
modify tctrl_order-cols index sy-tabix from col.
endif.
else.
loop at screen.
case screen-name.
when 'V_BUKRS'.
screen-input = 0.
modify screen.
when 'V_GJAHR'.
screen-input = 0.
modify screen.
when 'V_ZMON'.
screen-input = 0.
modify screen.
endcase.
endloop.
read table tctrl_order-cols into col
with key screen-name = 'ZFI017V-KOSTL'.
if sy-subrc = 0.
col-screen-input = '1'.
modify tctrl_order-cols index sy-tabix from col.
endif.
read table tctrl_order-cols into col
with key screen-name = 'ZFI017V-KSTAR'.
if sy-subrc = 0.
col-screen-input = '1'.
modify tctrl_order-cols index sy-tabix from col.
endif.
read table tctrl_order-cols into col
with key screen-name = 'ZFI017V-ADAMT'.
if sy-subrc = 0.
col-screen-input = '1'.
modify tctrl_order-cols index sy-tabix from col.
endif.
read table tctrl_order-cols into col
with key screen-name = 'ZFI017V-REASN'.
if sy-subrc = 0.
col-screen-input = '1'.
modify tctrl_order-cols index sy-tabix from col.
endif.
read table tctrl_order-cols into col
with key screen-name = 'ZFI017V-ZYEARMONTH'.
if sy-subrc = 0.
col-screen-input = '1'.
modify tctrl_order-cols index sy-tabix from col.
endif.
endif.
endmodule. " init_ctrl OUTPUT

4、ZFIE0032I01单元
************************************************************************
* Copyright 2003 *
* All Rights Reserved *
*----------------------------------------------------------------------*
* Program Name : ZFIE0005 *
* TYPE : REPORT *
* Project : SAP Implementation Project *
* Program Title: 管理部门年度预算考核额调整
* Created by : DEV01 *
* Created on : *
* Version : 1.0 *
* Function Description: *
* 管理部门年度预算考核额调整
*----------------------------------------------------------------------*
*操作数据表
*ZFI017
*----------------------------------------------------------------------*
*引用数据表
*
*----------------------------------------------------------------------*
* Modification Log: *
* Date Programmer Correction Number DesingDoc Number *
************************************************************************
************************************************************************
*&Form Name : LISTE_EXIT_COMMAND
* Created by : DEV01 *
* Created on :
*----------------------------------------------------------------------*
* Function Description: *
*处理系统退出命令,提示用户是否保存数据
*----------------------------------------------------------------------*
*参数说明
*
*----------------------------------------------------------------------*
* Date Programmer Description *
************************************************************************
module liste_exit_command input.
data: savestate type i .
case ok_code.
when 'CANC'.
set screen 0.
leave screen.
when 'BACK'.
if datastate = 'X'.
call function 'POPUP_TO_CONFIRM_STEP'
exporting
titel = '退出维护'
textline1 = '数据被修改。'
textline2 = '是否先保存所做更改?'
importing
answer = answer.
case answer.
when 'J'.
perform save_data changing savestate.
sy-subrc = savestate.
when 'n'.
sy-subrc = 1.
when 'A'.
sy-subrc = 0.
endcase.
endif.
if sy-subrc = 0.
set screen 0.
leave screen.
endif.
when 'EXIT'.
if datastate = 'X'.
call function 'POPUP_TO_CONFIRM_STEP'
exporting
titel = '退出维护'
textline1 = '数据被修改。'
textline2 = '是否先保存所做更改?'
importing
answer = answer.
case answer.
when 'J'.
perform save_data changing savestate.
sy-subrc = savestate.
when 'n'.
sy-subrc = 1.
when 'A'.
sy-subrc = 0.
endcase.
endif.
if sy-subrc = 0.
set screen 0.
leave screen.
perform exit_program.
endif.
endcase.
endmodule. " LISTE_EXIT_COMMAND INPUT
**&---------------------------------------------------------------------
*
**& Module LISTE_BEFORE_LOOP INPUT
**&---------------------------------------------------------------------
*
** text
**----------------------------------------------------------------------
*
*MODULE liste_before_loop INPUT.
*
*ENDMODULE. " LISTE_BEFORE_LOOP INPUT
************************************************************************
*&Form Name : do_mark_checkbox
* Created by : DEV01 *
* Created on : *
*----------------------------------------------------------------------*
* Function Description: *
*处理记录选中标记字段
*----------------------------------------------------------------------*
*参数说明
*
*----------------------------------------------------------------------*
* Date Programmer Description *
************************************************************************
module liste_mark_checkbox input.
if status_order-upd_flag eq space. "only mouse mark
perform update_entry using space 0 tctrl_order-top_line.
endif.
endmodule. " LISTE_MARK_CHECKBOX INPUT
************************************************************************
*&Form Name : set_update_orderkey_flag
* Created by : DEV01 *
* Created on : *
*----------------------------------------------------------------------*
* Function Description: *
*标记数据被修改,标记关键有新值需要检查
*----------------------------------------------------------------------*
*参数说明
*
*----------------------------------------------------------------------*
* Date Programmer Description *
************************************************************************
module set_update_orderkey_flag input.
status_order-upd_flag = 'X'.
status_order-auth_check = 'X'.
status_order-st_data = 'X'.
datastate = 'X'.
endmodule. " set_update_orderkey_flag INPUT
************************************************************************
*&Form Name : set_update_orderkey_group
* Created by : DEV01 *
* Created on :
*----------------------------------------------------------------------*
* Function Description: *
*标记数据被修改,标记关键有新值需要检查
*----------------------------------------------------------------------*
*参数说明
*
*----------------------------------------------------------------------*
* Date Programmer Description *
************************************************************************
module set_update_orderkey_group input.
status_order-upd_flag = 'X'.
status_order-auth_check = 'X'.
status_order-st_mode = 'X'.
datastate = 'X'.
endmodule. " set_update_orderkey_flag INPUT
************************************************************************
*&Form Name : set_update_order_flag
* Created by : DEV01 *
* Created on : *
*----------------------------------------------------------------------*
* Function Description: *
*标记数据被修改
*----------------------------------------------------------------------*
*参数说明
*
*----------------------------------------------------------------------*
* Date Programmer Description *
************************************************************************
module set_update_order_flag input.
status_order-upd_flag = 'X'.
datastate = 'X'.
endmodule. " SET_UPDATE_FLAG INPUT
************************************************************************
*&Form Name : liste_update_order
* Created by : DEV01 *
* Created on :
*----------------------------------------------------------------------*
* Function Description: *
*将工作区数据更新到显示和缓冲内表中
*----------------------------------------------------------------------*
*参数说明
*
*----------------------------------------------------------------------*
* Date Programmer Description *
************************************************************************
module liste_update_order input.
if status_order-upd_flag = 'X'.
perform check_key_order.
perform update_tab_order using sy-subrc sy-tabix.
clear status_order.
endif.
endmodule. " LISTE_UPDATE_LISTE INPUT
************************************************************************
*&Form Name : check_key_order
* Created by : DEV01 *
* Created on :
*----------------------------------------------------------------------*
* Function Description: *
*关键字检查,判断是否重复
*----------------------------------------------------------------------*
*参数说明
*
*----------------------------------------------------------------------*
* Date Programmer Description *
************************************************************************
form check_key_order .
* CLEAR order_total.
* READ TABLE order_total WITH KEY
* kostl = zfi017v-kostl
* KSTAR = zfi017v-KSTAR BINARY SEARCH.
* CHECK sy-subrc EQ 0.
* IF status_order-auth_check = 'X'.
* IF order_total-action EQ 'D'
* OR order_total-action EQ 'X'
* OR order_total-action EQ 'Y'.
* MESSAGE ID 'SV' TYPE 'E' NUMBER '010'.
* ELSE.
* MESSAGE ID 'SV' TYPE 'E' NUMBER '009'.
* ENDIF.
* ENDIF.
endform. "check_key_order
************************************************************************
*&Form Name : liste_after_loop
* Created by : DEV01 *
* Created on : *
*----------------------------------------------------------------------*
* Function Description: *
*处理用户操作
*----------------------------------------------------------------------*
*参数说明
*
*----------------------------------------------------------------------*
* Date Programmer Description *
************************************************************************
module liste_after_loop input.
* DATA: savestate TYPE i.
save_ok = ok_code.
clear ok_code.
case save_ok.
when 'EXIT' or 'BACK' or 'CANC'.
if datastate = 'C'.
call function 'POPUP_TO_CONFIRM_STEP'
exporting
titel = '退出维护'
textline1 = '数据被修改。'
textline2 = '是否先保存所做更改?'
importing
answer = answer.
case answer.
when 'J'.
perform save_data changing savestate.
sy-subrc = savestate.
when 'n'.
sy-subrc = 1.
when 'A'.
sy-subrc = 0.
endcase.
endif.
if sy-subrc = 0.
set screen 0.
leave screen.
perform exit_program.
endif.
when 'EDIT'.
if datastate eq space.
if con_show eq actionmode.
call function 'ENQUEUE_EZFIE017'
exporting
bukrs = v_bukrs
gjahr = v_gjahr
zmon = v_zmon
exceptions
foreign_lock = 2
system_failure = 3.
if sy-subrc ne 0.
message i622 with v_bukrs v_gjahr sy-msgv1.
else.
actionmode = con_change.
if ( v_oldgjahr = v_gjahr and v_oldbukrs = v_bukrs
and v_gjahr ne space and v_bukrs ne space ).
perform insert_newworkarea using grid_item.
endif.
endif.
endif.
endif.
when 'DELE'.
if con_show ne actionmode.
perform delete_order.
endif.
when 'SAVE' or 'SAVV'.
if datastate ne space.
perform save_data changing savestate.
if savestate eq 0.
call function 'DEQUEUE_EZFIE017'
exporting
bukrs = v_bukrs
gjahr = v_gjahr
zmon = v_zmon.
clear datastate.
endif.
else.
call function 'DEQUEUE_EZFIE017'
exporting
bukrs = v_bukrs
gjahr = v_gjahr
zmon = v_zmon.
perform clear_action.
endif.
when 'SOUP'.
* search for selected columns.
loop at tctrl_order-cols into col.
if col-selected = 'X'.
indexfldname = col-screen-name+11.
sort order_total by (indexfldname).
exit.
endif.
endloop.
when 'SODO'.
loop at tctrl_order-cols into col.
if col-selected = 'X'.
indexfldname = col-screen-name+11.
sort order_total by (indexfldname) descending.
exit.
endif.
endloop.
when others.
call method cl_gui_cfw=>dispatch.
endcase.
call method cl_gui_cfw=>flush.
endmodule. " LISTE_AFTER_LOOP INPUT
************************************************************************
*&Form Name : insert_newworkarea
* Created by : DEV01 *
* Created on : *
*----------------------------------------------------------------------*
* Function Description: *
*为编辑数据添加临时空记录
*----------------------------------------------------------------------*
*参数说明
*-->p_entries:插入新空白记录数
*----------------------------------------------------------------------*
* Date Programmer Description *
************************************************************************
form insert_newworkarea using p_entries.
if p_entries eq 0.
p_entries = 20.
endif.
clear order_extract.
move 'L' to order_extract-action.
do p_entries times.
append order_extract.
enddo.
move tctrl_order-lines to tctrl_order-top_line.
describe table order_extract lines tctrl_order-lines.
endform. " insert_newworkarea
************************************************************************
*&Form Name : delete_order
* Created by : DEV01 *
* Created on :
*----------------------------------------------------------------------*
* Function Description: *
*删除的数据,在缓冲数据中设立删除标志(只能删除新建且未保存的定价)
*----------------------------------------------------------------------*
*参数说明
*
*----------------------------------------------------------------------*
* Date Programmer Description *
* *
************************************************************************
*----------------------------------------------------------------------*
form delete_order .

loop at order_extract.
if order_extract-mark = 'M' and
order_extract-action ne 'L'.
delete order_extract.
endif.
endloop.
describe table order_extract lines tctrl_order-lines.
endform. " delete_order

5、ZFIE0032F01单元
************************************************************************
* Copyright 2003 Wuhan *
* All Rights Reserved *
*----------------------------------------------------------------------*
* Program Name : ZFIE0005 *
* TYPE : REPORT *
* Project : SAP Implementation Project *
* Program Title: 管理部门年度预算考核额调整
* Created by : DEV01 *
* Created on : *
* Version : 1.0 *
* Function Description: *
* 管理部门年度预算考核额调整
*----------------------------------------------------------------------*
*操作数据表
*ZFI017
*----------------------------------------------------------------------*
*引用数据表
*
*----------------------------------------------------------------------*
* Modification Log: *
* Date Programmer Correction Number DesingDoc Number *
************************************************************************
************************************************************************
*&Form Name : exit_program
* Created by : DEV01 *
* Created on : *
*----------------------------------------------------------------------*
* Function Description: *
*退出程序时, 解除锁
*----------------------------------------------------------------------*
*参数说明
*
*----------------------------------------------------------------------*
* Date Programmer Description *
************************************************************************
form exit_program.
call function 'DEQUEUE_EZFIE017'
exporting
bukrs = v_bukrs
gjahr = v_gjahr
znum = v_zmon.
leave program.
endform. " exit_program

6、ZFIE0032FI1单元
************************************************************************
* Copyright 2003 *
* All Rights Reserved *
*----------------------------------------------------------------------*
* Program Name : ZFIE0005 *
* TYPE : REPORT *
* Project : SAP Implementation Project *
* Program Title: 管理部门年度预算考核额调整
* Created by : DEV01 *
* Created on : *
* Version : 1.0 *
* Function Description: *
* 管理部门年度预算考核额调整
*----------------------------------------------------------------------*
*操作数据表
*ZFI017
*----------------------------------------------------------------------*
*引用数据表
*
*----------------------------------------------------------------------*
* Modification Log: *
* Date Programmer Correction Number DesingDoc Number *
************************************************************************
************************************************************************
*&Form Name : clear_action
* Created by : DEV01 *
* Created on :
*----------------------------------------------------------------------*
* Function Description: *
*清除数据操作状态,恢复到初试显示状态
*----------------------------------------------------------------------*
*参数说明
*
*----------------------------------------------------------------------*
* Date Programmer Description *
************************************************************************
form clear_action.
* order_extract[] = order_total[].
actionmode = con_show.
describe table order_extract lines tctrl_order-lines.
tctrl_order-top_line = 1.
clear ok_code.
mark_total = 1.
clear:datastate,status_order.
clear status_order.
endform. " clear_action
************************************************************************
*&Form Name : clear_mark
* Created by : DEV01 *
* Created on :
*----------------------------------------------------------------------*
* Function Description: *
*清除记录选中标记
*----------------------------------------------------------------------*
*参数说明
*
*----------------------------------------------------------------------*
* Date Programmer Description *
************************************************************************
form clear_mark .
loop at order_total.
order_total-mark = space.
modify order_total index sy-tabix.
endloop.
endform. " clear_mark
************************************************************************
*&Form Name : save_data
* Created by : DEV01 *
* Created on :
*----------------------------------------------------------------------*
* Function Description: *
*保存数据
*----------------------------------------------------------------------*
*参数说明
*<--savestate:返回保存是否成功,成功为0值
*----------------------------------------------------------------------*
* Date Programmer Description *
************************************************************************
form save_data changing savestate type i.
data i_znum type i.
savestate = -1.
delete from zfi017
where bukrs = v_bukrs and
gjahr = v_gjahr and
zmon = v_zmon.
i_znum = 1.
loop at order_extract.
if order_extract-action eq space.
zfi017-bukrs = order_extract-bukrs.
zfi017-gjahr = order_extract-gjahr.
zfi017-zmon = order_extract-zmon.
zfi017-znum = i_znum.
zfi017-kostl = order_extract-kostl.
zfi017-kstar = order_extract-kstar.
zfi017-adamt = order_extract-adamt.
zfi017-reasn = order_extract-reasn.
zfi017-zyearmonth = order_extract-zyearmonth.
insert zfi017.
if sy-subrc ne 0.
rollback work.
exit.
endif.
i_znum = i_znum + 1.
elseif order_extract-action = 'U'.
zfi017-bukrs = order_extract-bukrs.
zfi017-gjahr = order_extract-gjahr.
zfi017-zmon = order_extract-zmon.
zfi017-znum = i_znum.
zfi017-kostl = order_extract-kostl.
zfi017-kstar = order_extract-kstar.
zfi017-adamt = order_extract-adamt.
zfi017-reasn = order_extract-reasn.
zfi017-zyearmonth = order_extract-zyearmonth.
insert zfi017.
if sy-subrc ne 0.
rollback work.
exit.
endif.
i_znum = i_znum + 1.
order_total-action = space.
modify order_extract.
elseif order_extract-action = 'X'.
delete order_total.
elseif ( ( order_extract-action = 'D' ) or
( order_extract-action = 'Y' ) ).
delete order_extract.
elseif order_extract-action = 'N'.
zfi017-bukrs = order_extract-bukrs.
zfi017-gjahr = order_extract-gjahr.
zfi017-zmon = order_extract-zmon.
zfi017-znum = i_znum.
zfi017-kostl = order_extract-kostl.
zfi017-kstar = order_extract-kstar.
zfi017-adamt = order_extract-adamt.
zfi017-reasn = order_extract-reasn.
zfi017-zyearmonth = order_extract-zyearmonth.
insert zfi017.
if sy-subrc ne 0.
rollback work.
exit.
endif.
i_znum = i_znum + 1.
order_total-action = space.
modify order_extract.
endif.

7、ZFIE0032FI2单元
************************************************************************
* Copyright 2003 *
* All Rights Reserved *
*----------------------------------------------------------------------*
* Program Name : ZFIE0005 *
* TYPE : REPORT *
* Project : SAP Implementation Project *
* Program Title: 管理部门年度预算考核额调整
* Created by : DEV01 *
* Created on : *
* Version : 1.0 *
* Function Description: *
* 管理部门年度预算考核额调整
*----------------------------------------------------------------------*
*操作数据表
*ZFI017
*----------------------------------------------------------------------*
*引用数据表
*
*----------------------------------------------------------------------*
* Modification Log: *
* Date Programmer Correction Number DesingDoc Number *
************************************************************************
************************************************************************
*&Form Name : update_tab_order
* Created by : DEV01 *
* Created on : *
*----------------------------------------------------------------------*
* Function Description: *
*将显示缓冲work area的数据更新到内表
*----------------------------------------------------------------------*
*参数说明 *
* --> p_rc :记录定位操作返回的sy-subrc的值
* --> p_index :记录的索引位置
*----------------------------------------------------------------------*
* Date Programmer Description *
************************************************************************
form update_tab_order using value(p_rc)
value(p_index).
perform update_entry using 'X' p_rc p_index.
endform. " update_tab
************************************************************************
*&Form Name : update_tab_order
* Created by : DEV01 *
* Created on :*
*----------------------------------------------------------------------*
* Function Description: *
*将显示缓冲work area的数据更新到内表
*----------------------------------------------------------------------*
*参数说明
* --> p_workarea : ‘X' 更新显示和缓冲双份内表数据
* space 只更新显示内表数据
* --> p_rc :记录定位操作返回的sy-subrc的值
* --> p_index :记录的索引位置
*----------------------------------------------------------------------*
* Date Programmer Description *
************************************************************************
form update_entry using value(p_workarea)
value(p_rc)
value(p_index).
read table order_extract index tctrl_order-top_line.
if order_extract-action = 'L'.
move-corresponding zfi017v to order_extract.
order_extract-bukrs = v_bukrs.
order_extract-gjahr = v_gjahr.
order_extract-zmon = v_zmon.
order_extract-action = 'N'.
if vim_marked ne space.
order_extract-mark = 'M'.
endif.
modify order_extract index tctrl_order-top_line.
clear order_extract.
order_extract-action = 'L'.
append order_extract.
else.
move-corresponding zfi017v to order_extract.
order_extract-bukrs = v_bukrs.
order_extract-gjahr = v_gjahr.
order_extract-zmon = v_zmon.
order_extract-action = 'U'.
if vim_marked ne space.
order_extract-mark = 'M'.
endif.
modify order_extract index tctrl_order-top_line.
endif.
describe table order_extract lines tctrl_order-lines.
endform. "update_tab_order
endloop.
commit work.
savestate = 0.
perform clear_action.
message s024.
endform. " save_data

8、ZFIE0032H01单元
************************************************************************
* Copyright 2003 Wuhan *
* All Rights Reserved *
*----------------------------------------------------------------------*
* Program Name : ZFIE0005 *
* TYPE : REPORT *
* Project : SAP Implementation Project *
* Program Title: 管理部门年度预算考核额调整
* Created by : DEV01 *
* Created on : *
* Version : 1.0 *
* Function Description: *
* 管理部门年度预算考核额调整
*----------------------------------------------------------------------*
*操作数据表
*ZFI017
*----------------------------------------------------------------------*
*引用数据表
*
*----------------------------------------------------------------------*
* Modification Log: *
* Date Programmer Correction Number DesingDoc Number *
************************************************************************
************************************************************************
*&Form Name : v_bukrs_check
* Created by : DEV01 *
* Created on : *
*----------------------------------------------------------------------*
* Function Description: *
*公司代码字段输入检查:不能为空且代码不能不存在
*----------------------------------------------------------------------*
*参数说明
*
*----------------------------------------------------------------------*
* Date Programmer Description *
************************************************************************
module v_bukrs_check input.
tables: t001.
if v_bukrs = space.
message e023 with '公司代码'.
endif.
select single * from t001 where bukrs = v_bukrs.
if sy-subrc ne 0.
message e014 with v_bukrs.
endif.
endmodule. " v_bukrs_check INPUT
************************************************************************
*&Form Name : v_gjahr_check
* Created by : DEV01 *
* Created on : *
*----------------------------------------------------------------------*
* Function Description: *
*年份代码字段输入检查:不能为空且年份不能小于1990
*----------------------------------------------------------------------*
*参数说明
*
*----------------------------------------------------------------------*
* Date Programmer Description *
************************************************************************
module v_gjahr_check input.
if v_gjahr = space.
message e023 with '年份'.
endif.
if v_gjahr gt 9999 or v_gjahr lt 1000.
message e046.
endif.
endmodule. " v_gjahr_check INPUT
************************************************************************
*&Form Name : v_zmon_check
* Created by : DEV01 *
* Created on : *
*----------------------------------------------------------------------*
* Function Description: *
*月份字段输入检查
*----------------------------------------------------------------------*
*参数说明
*
*----------------------------------------------------------------------*
* Date Programmer Description *
************************************************************************
module v_zmon_check input.
if v_zmon = space.
message e023 with '月份'.
endif.
if v_zmon gt 12 or v_zmon lt 1.
message e047.
endif.
endmodule. " v_gjahr_check INPUT
************************************************************************
*&Form Name : select_kostl
* Created by : DEV01 *
* Created on : *
*----------------------------------------------------------------------*
* Function Description: *
*获取成本中心组(帮助输入)
*----------------------------------------------------------------------*
*参数说明
*
*----------------------------------------------------------------------*
* Date Programmer Description *
************************************************************************
module select_kostl input.
data:
dynpro_values type table of dynpread,
field_value like line of dynpro_values,
l_year like bkpf-gjahr,
g_kh(10).
data: begin of i_tree occurs 0,
setname like setnode-setname,
end of i_tree.
data: i_subtree like i_tree occurs 0 with header line,
i_temptree like i_tree occurs 0 with header line.
data l_count type i .
ranges: s_setname for setnode-setname.
ranges: s_kostl for cskt-kostl.

refresh dynpro_values.
field_value-fieldname = 'V_GJAHR'.
append field_value to dynpro_values.

call function 'DYNP_VALUES_READ'
exporting
dyname = sy-repid
dynumb = sy-dynnr
translate_to_upper = 'X'
tables
dynpfields = dynpro_values.

read table dynpro_values index 1 into field_value.
l_year = field_value-fieldvalue(4).

refresh i_setheadert.
s_setname-option = 'EQ'.
s_setname-sign = 'I'.
l_count = 1.
refresh i_temptree.
refresh i_subtree.
*特殊处理,2005年预算用2006的机构
if l_year < 2006.
l_year = 2006.
endif.
concatenate 'KH' l_year into g_kh.
while l_count > 0.
select setnode~subsetname as setname
into (setheadert-setname)
from setnode
where setnode~setclass = '0101'
and setnode~subclass = '1000'
and setnode~subsetcls = '0101'
and setnode~subsetscls = '1000'
and setnode~setname = g_kh.
move setheadert-setname to s_setname-low.
append s_setname.
i_temptree-setname = setheadert-setname.
append i_temptree.
endselect.
append lines of i_temptree to i_subtree.
describe table i_subtree lines l_count.
if l_count ne 0.
read table i_subtree index 1.
g_kh = i_subtree-setname.
delete i_subtree index 1.
endif.
refresh i_temptree.
clear i_temptree.
endwhile.

select valsign as sign valoption as option
valfrom as low valto as high
into table s_kostl
from setleaf
where setclass = '0101'
and subclass = '1000' and setname in s_setname.

refresh i_setheadert.
select single bukrs from t001 into butxt
where bukrs = v_bukrs.
if sy-subrc <> 0.
message id 'ZDEV' type 'S' number '049'.
exit.
endif.
select cskt~kostl cskt~ktext
into (cskt-kostl,cskt-ktext)
from cskt
where spras = '1'
and kokrs = '1000'
and kostl in s_kostl.
move cskt-kostl to i_setheadert-ktext.
append i_setheadert.
move cskt-ktext to i_setheadert-ktext.
append i_setheadert.
endselect.
refresh fldtab.
clear fldtab.
fldtab-tabname = 'CSKT'.
fldtab-fieldname = 'KOSTL'.
fldtab-selectflag = 'X'.
append fldtab.
clear fldtab.
fldtab-tabname = 'CSKT'.
fldtab-fieldname = 'KTEXT'.
append fldtab.
call function 'HELP_VALUES_GET_WITH_TABLE'
exporting
display = space
fieldname = 'KOSTL'
tabname = 'ZFI017V'
importing
select_value = ktext
tables
fields = fldtab
valuetab = i_setheadert.
if not ktext is initial.
zfi017v-kostl = ktext.
endif.
endmodule. " select_kostl INPUT

************************************************************************
*&Form Name : select_zgroup
* Created by : DEV01 *
* Created on : *
*----------------------------------------------------------------------*
* Function Description: *
*获取某个年度成本要素组(帮助输入)
*----------------------------------------------------------------------*
*参数说明
*
*----------------------------------------------------------------------*
* Date Programmer Description *
************************************************************************
module select_zgroup input.
refresh i_zfi010.
*********XIONGHM***************
select kstar ktext
into (csku-kstar,csku-ktext)
from csku
where spras = '1' and ktopl ='CB00'.
i_zfi010-name = csku-kstar.
append i_zfi010.
i_zfi010-name = csku-ktext.
append i_zfi010.
endselect.

refresh fldtab.
clear fldtab.
fldtab-tabname = 'ZFI017V'.
fldtab-fieldname = 'KSTAR'.
fldtab-selectflag = 'X'.
append fldtab.
clear fldtab.
fldtab-tabname = 'ZFI017V'.
fldtab-fieldname = 'KTEXT'.
append fldtab.
call function 'HELP_VALUES_GET_WITH_TABLE'
exporting
display = space
fieldname = 'KSTAR'
tabname = 'ZFI017V'
importing
select_value = name
tables
fields = fldtab
valuetab = i_zfi010.
if not name is initial.
zfi017v-kstar = name.
endif.
endmodule. " select_prodh INPUT
************************************************************************
*&Form Name : v_check_kostl
* Created by : DEV01 *
* Created on : *
*----------------------------------------------------------------------*
* Function Description: *
*检查成本输入中心是否存在
*----------------------------------------------------------------------*
*参数说明
*
*----------------------------------------------------------------------*
* Date Programmer Description *
************************************************************************
module v_check_kostl input.
if zfi017v-kostl eq space.
message e621 with zfi017v-kostl.
endif.
if status_order-st_data ne space.
select single ktext as descript
into zfi017v-descript
from cskt
where spras = '1'
and kokrs = '1000'
and kostl = zfi017v-kostl.
if sy-subrc ne 0.
message e620 with zfi017v-kostl.
endif.
endif.
endmodule. " v_check_kostl INPUT
************************************************************************
*&Form Name : v_check_zgroup
* Created by : DEV01 *
* Created on : *
*----------------------------------------------------------------------*
* Function Description: *
*检查输入成本要素组是否存在
*----------------------------------------------------------------------*
*参数说明
*
*----------------------------------------------------------------------*
* Date Programmer Description *
************************************************************************
module v_check_zgroup input.
if zfi017v-kstar eq space.
message e621 with zfi017v-kstar.
endif.
if status_order-st_mode ne space.
select single ktext
into (zfi017v-ktext)
from csku
where spras = '1' and ktopl ='CB00'
and kstar = zfi017v-kstar.
if sy-subrc ne 0.
message e621 with zfi017v-kstar.
endif.
endif.
endmodule. " v_check_zgroup INPUT

9、屏幕PBO和PAI
*BEFORE OUTPUT
process before output.
module init_pbo.
module init_data.
module init_ctrl.
loop at order_extract with control tctrl_order
cursor tctrl_order-top_line.

module liste_show_liste.
endloop.

*After input
process after input.
module liste_exit_command at exit-command.
field v_bukrs module v_bukrs_check on request.
field v_gjahr module v_gjahr_check on request.
field v_zmon module v_zmon_check on request.
module liste_before_loop.
loop at order_extract.
field zfi017v-kostl
module set_update_orderkey_flag on request.
field zfi017v-kstar
module set_update_orderkey_group on request.
chain.
field zfi017v-adamt.
field zfi017v-reasn.
field zfi017v-zyearmonth.
module set_update_order_flag on chain-request.
endchain.
field vim_marked module liste_mark_checkbox.
**检查
field zfi017v-kostl module v_check_kostl.
field zfi017v-kstar module v_check_zgroup.
* save current data to order_total
chain.
field zfi017v-kostl.
field zfi017v-kstar.
field zfi017v-adamt.
field zfi017v-reasn.
field zfi017v-zyearmonth.
module liste_update_order.
endchain.
endloop.
*deal with function Code
module liste_after_loop.

process on value-request.
field zfi017v-kostl module select_kostl.
field zfi017v-kstar module select_zgroup.


Archives

1990年1月15日   2007年1月14日   2007年1月15日   2007年1月16日   2007年1月17日   2007年1月18日   2007年1月19日   2007年1月20日   2007年1月22日   2007年1月23日   2007年1月24日   2007年1月25日   2007年1月26日   2007年1月27日   2007年1月29日   2007年1月30日   2007年1月31日   2007年2月1日   2007年2月2日   2007年2月3日   2007年3月13日   2007年5月15日   2007年5月16日   2007年6月2日  

This page is powered by Blogger. Isn't yours?