马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。如果您注册时有任何问题请联系客服QQ: 83569622 。
您需要 登录 才可以下载或查看,没有帐号?注册
x
【一个报表样例】 *&---------------------------------------------------------------------* *& Report
ZSD_LONG
* *&
* *&---------------------------------------------------------------------* *&
基础参考 下载
* *&
* *&---------------------------------------------------------------------* REPORT
ZSD_LONG
MESSAGE-ID
zmsgtest
line-size 120
. **************************************************************** ***数据段 声明表 tables : MAKT,
"material table
VBAK,
"sale order header table
VBAP,
"sale order item table
KNA1.
"address table
***数据段 声明结构以便内表使用 data: begin of it_addr occurs 0,
"12/01 add
name1
like KNA1-name1,
"com name
ORT01
like KNA1-ORT01,
"city,
STRAS
like KNA1-STRAS,
" city,street
end of it_addr.
"12/01 add
data : begin of it_header occurs 0,
vbeln
like VBAK-vbeln,
"sale order no
kunnr
like VBAK-kunnr,
"sale to
erdat
like VBAK-erdat,
"created date
addr
like it_addr,
"12/01 rewrite
str可以嵌套
*
addr
like KNA1-ADRNR,
"customer addr old
bukrs
like vbak-BUKRS_VF,
"com code
end of it_header.
data : begin of it_item occurs 0,
vbeln like vbap-vbeln,
"sale order no
matnr like vbap-matnr,
"material no
kwmeng like vbap-kwmeng,
"sale item quanity
*
zmeng like vbap-zmeng,
"sale quanity
ZIEME like vbap-ZIEME,
"unit
netwr like vbap-netwr,
"sale netprice
WAERK like vbap-WAERK,
"currency
maktx like makt-maktx,
"material description
end of it_item.
data : l_list type i.
"output linenum **************************************************************** ***输入屏幕 范围选择输入 Selection-screen begin of block b1
WITH FRAME title text-001. Select-options: s_vbeln for VBAK-vbeln,
s_erdat for VBAK-erdat,
s_kunnr for VBAK-kunnr,
s_ernam for VBAK-ernam,
"created by
s_bukrs for vbak-BUKRS_VF.
"com code
***checkbox and required field PARAMETER: P_run type d.
" OBLIGATORY.
OBLIGATORY:必须输入字段 PARAMETER: P_chk TYPE C AS CHECKBOX .
"DEFAULT 'X'默认值. Selection-screen end of block b1. **************************************************************** ***use customizing messag .when use at clause
return has no use **AT SELECTION-SCREEN ON
s_vbeln. *
if **
s_vbeln-high <> 12. *
s_vbeln-high > s_vbeln-low
. *
message i000 . *
return. *
endif. **************************************************************** ***处理段 以Form调用 start-of-selection.
SET PF-STATUS '0001'.
"用户菜单 12/01 改v1
*AUTHORITY CHECK object id 'in object' field 'the field to be auth'
AUTHORITY-CHECK OBJECT 'FW_ORD_BUK'
ID 'BUKRS' FIELD vbak-BUKRS_VF.
*简单控制运行时间 11/30改 v1
if P_chk <> 'X' and P_run = 0.
message i002.
else.
if P_chk = 'X'.
"注意区分大小写
perform data_retrieve.
perform output_data.
else.
if P_run < sy-DATLO.
message i001.
else.
if P_run = sy-DATLO.
"用户时间
* 没实现控制程序按照计划时间运行
perform data_retrieve.
perform output_data.
endif.
endif.
endif.
endif.
***注意:用户定义菜单sy-ucomm包含了双击事件 所以两者不能同时使用 ***
可以通过修改系统select事件 功能F2 达到选择行,从而响应的目的 ***
不再使用at LINE-SELECTION与hide 这样问题解决一小半, ***
用户菜单、双击可以共存,但不能根据行号来响应。 ****用户自定义菜单 12/01 改 v1 *at user-command. *
CASE SY-UCOMM. *
WHEN 'quit'. *
leave program . *
when 'back'. *
return. *
when 'SELLINE'.
"双击选择行单一响应 *
write: / 'line one'. *
ENDCASE. ****用户自定义菜单 12/01 改v2
注意每次修改要激活,不然不可用 *** 通过case嵌套 只不使用at LINE-SELECTION这样问题解决一半 *** 可响应不同行,但不能根据不同订单的行而不同响应 at user-command.
"用户菜单事件sy-ucomm
CASE SY-UCOMM.
WHEN 'quit'.
"quit 是菜单编辑中的CODE text则是菜单显示
*
leave.
"离开当前程序 同leave program作用. * exit用于do while loop select的退出. *
leave program . *离开当前整个程序,但可能还在当前当前事务.类似的leave screen *其他 EAVE LIST-PROCESSING. *LEAVE TO LIST-PROCESSING [可以加 AND RETURN TO SCREEN scr] *
LEAVE TO CURRENT TRANSACTION. *离开当前程序及所在事务,返回当前事务的前一事务处理. *可以后带 AND SKIP FIRST SCREEN
LEAVE TO TRANSACTION 'SE38'.
*离开当前处理,转到指定事务se38事务 *可以后带 AND SKIP FIRST SCREEN
类似的leave to SCREEN scr.
when 'back'.
return.
"无论任何状况,直接返回前一程序处理
when others.
case l_list.
"case可以嵌套
when '1'.
write: / 'line one'.
when '2'.
write: / 'line 2'.
when '3'.
write: / 'line 3'.
when others.
write:/'wrong'.
endcase.
ENDCASE.
***method1 使用 双击事件响应 *AT LINE-SELECTION. *
case l_list. *
when '1'. *
write: / 'line one'. *
when '2'. *
write: / 'line 2'. *
when '3'. *
write: / 'line 3'. *
when others. *
write:/'wrong'. *
endcase. *&---------------------------------------------------------------------* *&
Form
data_retrieve *&---------------------------------------------------------------------* *
text *----------------------------------------------------------------------* *
-->
p1
text *
<--
p2
text *----------------------------------------------------------------------* *FORM data_retrieve . * *
select vbeln kunnr erdat ernam *
appending table it_header
"use table *
from vbak *
where vbeln in s_vbeln *
and erdat in s_erdat *
and kunnr in s_kunnr *
and ernam in s_ernam. **** 根据输入选择从订单表头选出 订单号、客户、日期、人 插入内表 *
loop at it_header. *
select single ADRNR into it_header-addr *
from KNA1 *
where kunnr eq it_header-kunnr. *
modify it_header. *
endloop. ****循环内表记录,根据客户号从地址表选出地址 *
select vbeln matnr
zmeng ZIEME netwr WAERK *
appending table it_item *
from vbap *
where vbeln in ( select vbeln *
from vbak *
where vbeln in s_vbeln *
and erdat in s_erdat *
and kunnr in s_kunnr *
and ernam in s_ernam ). **** 从item表选出详细信息 *
loop at it_item. *
select single maktx into it_item-maktx *
from makt *
where matnr eq it_item-matnr. *
modify it_item. *
endloop. *ENDFORM.
" data_retrieve ***以上根据范例修改而来 ***以下是新的SQL语句 v1 *FORM data_retrieve . * *
select vbak~vbeln vbak~kunnr vbak~erdat
KNA1~ADRNR *
appending table it_header
"use table *
from vbak inner join KNA1 *
on
vbak~kunnr = KNA1~kunnr *
where vbak~vbeln in s_vbeln *
and vbak~erdat in s_erdat *
and vbak~kunnr in s_kunnr *
and vbak~ernam in s_ernam. **** 根据输入选择从订单表头选出 订单号、客户、日期、人 插入内表 ****使用表的内连接 *
select vbeln matnr
zmeng ZIEME netwr WAERK *
appending table it_item *
from vbap *
where vbeln in ( select vbeln *
from vbak *
where vbeln in s_vbeln *
and erdat in s_erdat *
and kunnr in s_kunnr *
and ernam in s_ernam ). **** 从item表选出详细信息 *
loop at it_item. *
select single maktx into it_item-maktx *
from makt *
where matnr eq it_item-matnr. *
modify it_item. *
endloop. *ENDFORM.
" data_retrieve **以下是SQL语句 v2 weixiugai1129 FORM data_retrieve .
select vbeln kunnr erdat ernam BUKRS_VF
appending table it_header
"use table
from vbak
where vbeln in s_vbeln
and erdat in s_erdat
and kunnr in s_kunnr
and ernam in s_ernam.
*** 根据输入选择从订单表头选出 订单号、客户、日期、人 插入内表
loop at it_header.
select single name1 ORT01 STRAS into it_addr
"12/01 rewrite
from KNA1
where kunnr eq it_header-kunnr.
move it_addr to
it_header-addr.
"12/01 rewrite
*
select single ADRNR into it_header-addr *
from KNA1 *
where kunnr eq it_header-kunnr.
modify it_header.
endloop.
***循环内表记录,根据客户号从地址表选出地址
select vbeln matnr
kwmeng ZIEME netwr WAERK
appending table it_item
from vbap
where vbeln in ( select vbeln
from vbak
where vbeln in s_vbeln
and erdat in s_erdat
and kunnr in s_kunnr
and ernam in s_ernam ).
*** 从item表选出详细信息
loop at it_item.
select single maktx into it_item-maktx
from makt
where matnr eq it_item-matnr.
modify it_item.
endloop.
ENDFORM.
" data_retrieve *&---------------------------------------------------------------------* *&
Form
output_data *&---------------------------------------------------------------------* *
text *----------------------------------------------------------------------* *
-->
p1
text *
<--
p2
text *----------------------------------------------------------------------* *FORM output_data . *
data : l_list type i. *
loop at it_header. *
clear l_list. *
write :/ '订单:',
it_header-vbeln, 30
'购买者', it_header- *kunnr. *
write :/ '订单日期', it_header-erdat, *
30
'地址',it_header-addr under it_header-kunnr. **
write :/ '订单打印日期',sy-datum. *
loop at it_item where vbeln eq it_header-vbeln. *
add 1 to l_list. *
write :/1(2) l_list, *
(18) it_item-matnr, *
30(20) it_item-maktx, *
(18) it_item-zmeng, *
(3)
it_item-zieme, *
(15)
it_item-netwr, *
(3)
it_item-WAERK. *
endloop. *
uline.uline. *
new-page. *
endloop. *ENDFORM.
" output_data ***更改输入 FORM output_data . *
data : l_list type i.
loop at it_header.
clear l_list.
write :/ '订单:',it_header-vbeln, 30
'购买者',
it_header-kunnr , 45 it_header-addr-name1.
write :/ '订单日期', it_header-erdat.
"12/01 rewrite
if it_header-addr-STRAS = ''
.
write:
30
'地址','用户详细地址未知' color 3,
it_header-addr-ORT01.
else.
write:
30
'地址',it_header-addr-STRAS under it_header-kunnr ,
it_header-addr-ORT01.
endif.
write :/ '订单打印日期',sy-datum.
loop at it_item where vbeln eq it_header-vbeln.
add 1 to l_list.
write :/1(2) l_list,
(18) it_item-matnr,
30(20) it_item-maktx,
(18) it_item-kwmeng,
(3)
it_item-zieme,
(15)
it_item-netwr,
(3)
it_item-WAERK.
hide l_list.
"method1 使用 保存行号。相当于系统select事件
endloop.
uline.uline.
new-page.
"换页功能,每个订单一页
endloop.
ENDFORM.
" output_data ************************************************************************ |