BSP报表开发实例日期:2007-7-12作者:侯志宇一、输入事务代码SE80,选择BSPAPPLICATION,输入BSP的程序名按回车选择创建;二、创建一个页面,操作如下:输入网页名字,输入描述,选择网页类型,单击确认;三、如果需要调用CSS样式,则需要引用一个CSS样式文件,操作如下:如上图操作后选择一个CSS文件即可;四、代码实现,在LAYOUT页签中输入如下代:%@pagelanguage=abap%h3%=errormsg%/h3htmllinkrel=stylesheethref=./style.csstype=text/cssHEADTITLE/TITLEformname=PageFormid=PageFormmethod=postTABLEalign=centerborder=0cellpadding=0cellspacing=0width='80%'TRtdcolspan=6inputclass='InputBox'type=textname=st_custnosize=10value=%=gt_custno%maxlength=10/td/trTRtdinputclass='InputBox'type=textname=st_ordsize=10value=%=gt_dat%maxlength=10/td/trtdcolspan=2align=rightINPUTname=onInputProcessing(sub)class=form1TYPE=submitvalue=/tdtrtdhrsize=1bordercolor=black/td/trTRTDalign=centerDIVid=Listclass=TableDivalign=centertableborder=0width=100%class=table1cellspacing=1trclass=thtdnowrapalign=LEFT /tdtdnowrapalign=LEFT /tdtdnowrapalign=LEFT /tdtdnowrapalign=LEFT /tdtdnowrapalign=LEFT /tdtdnowrapalign=LEFT /tdtdnowrapalign=right/tdtdnowrapalign=LEFT /tdtdnowrapalign=LEFT /tdtdnowrapalign=LEFT /td/tr/TD/TR%DATA:wa_YSHDDCXLIKELINEOFZSDFB_YSHDDCX.loopatZSDFB_YSHDDCXintowa_YSHDDCX.%trtdnowrapalign=center%=wa_YSHDDCX-AUDAT%/tdtdnowrapalign=center%=wa_YSHDDCX-VBELN%/tdtdnowrapalign=center%=wa_YSHDDCX-BSTNK%/tdtdnowrapalign=center%=wa_YSHDDCX-SMNAM%/tdtdnowrapalign=center%=wa_YSHDDCX-BEZEI20%/tdtdnowrapalign=center%=wa_YSHDDCX-VDATU%/tdtdnowrapalign=right%=wa_YSHDDCX-ZJSL%/tdtdnowrapalign=right%=wa_YSHDDCX-KZWI2%/tdtdnowrapalign=right%=wa_YSHDDCX-YCHJE%/tdtdnowrapalign=center%=wa_YSHDDCX-VTEXT%/td/tr%endloop.%/TABLE/DIV/TABLE/form/HEAD/html五、代码实现,在EventHandler签中输入如下代:*eventhandlerforcheckingandprocessinguserinputand*fordefiningnavigationcaseevent_id.when'sub'.*------------取得输入值-------------------------navigation-set_parameter('st_custno').gt_custno=navigation-get_parameter(name='st_custno').*-------------------------------------------------navigation-set_parameter('st_ord').gt_dat=navigation-get_parameter(name='st_ord').*-------------------------------------------------------------------*通过关联来调用网页*navigation-next_page('要关联的值(在属性中定义)').*navigation-goto_page('custord_list.htm').直接调用网页*--------------------------------------------------------whenothers.endcase.*---输入判断clearerrormsg.ifgt_custnoisnotinitial.unpackgt_custnotogt_custno.else.errormsg='请输入客户编号'.exit.endif.*ifgt_datisnotinitial.*unpackgt_dattogt_dat.*else.*errormsg='请输订单日期'.*exit.*endif.*----取值区-------DATA:wa_YSHDDCXLIKELINEOFZSDFB_YSHDDCX.selectKUNNRVBELNBSTNKAUDATVDATUSPARTVKGRPVTWEGintocorrespondingfieldsoftableZSDFB_YSHDDCXfromVBAKwhereKUNNReqgt_custnoandAUDATeqgt_dat.loopatZSDFB_YSHDDCXintowa_YSHDDCX.*--------取得客户描述--------------------------selectsingleNAME1fromKNA1intowa_YSHDDCX-NAME1whereKUNNR=wa_YSHDDCX-KUNNR.*---------取销售组代码对应得描述----------------------selectsingleBEZEIfromTVGRTintowa_YSHDDCX-BEZEI20whereVKGRP=wa_YSHDDCX-VKGRP.*---------取销售雇员代码-----------------------------selectsingleT~PERNRfromVBPAasTintowa_YSHDDCX-BUPARTNRwhereT~PARVW='VE'andT~VBELN=wa_YSHDDCX-VBELN.*---------取销售雇员名称-----------------------------selectsinglePA0001~SNAMEfromPA0001intowa_YSHDDCX-SMNAMwherePA0001~PERNR=wa_YSHDDCX-BUPARTNR.*selectsinglePA0001~SNAMEintowa_YSHDDCX-SMNAM*fromPA0001asXinnerjoin*where*--------------取订单金额---------selectsum(KZWI2)fromVBAPintowa_YSHDDCX-KZWI2whereVBELN=wa_YSHDDCX-VBELN.**-------主机数量-------------------*selectMATNRKWMENGfromVBAP*intocorrespondingfieldsoftableMATNR*whereVBELN=wa_YSHDDCX-VBELN.*loopatMATNRintowa_MATNR.*if(wa_MATNR-MATNR+9(1)='5')and(wa_MATNR-MATNR+9(3)*'505').*SUM=SUM+wa_MATNR-KWMENG.*endif.*endloop.*wa_YSHDDCX-ZJSL=SUM.***----------取得已出货金额----------------------------**取数逻辑:在vbfa中将类型为M的累加,在将类型为N的累加**类型为M的累加值减去类型为N的累加值**将算出的值乘以1.17**--------------------------*selectsum(RFWRT)fromVBFA*intoM_RFWRT*whereVBELV=wa_YSHDDCX-VBELN*andVBTYP_N='M'.*selectsum(RFWRT)fromVBFA*intoN_RFWRT*whereVBELV=wa_YSHDDCX-VBELN*andVBTYP_N='N'.*wa_YSHDDCX-YCHJE=(M_RFWRT-N_RFWRT)*FLOAT.取得产品组描述selectsingleVTEXTfromTSPATintocorrespondingfieldsofwa_YSHDDCXwhereSPART=wa_YSHDDCX-SPART.*--取得分销渠道描述selectsingleVTEXTfromTVTWTintowa_YSHDDCX-VTEXTwhereVTWEG=wa_YSHDDCX-VTWEGandSPRAS='1'.modifyZSDFB_YSHDDCXfromwa_YSHDDCX.*clearSUM.clearM_RFWRT.clearN_RFWRT.clearMATNR[].endloop.六、代码实现,在pageAttribute中定义变量,变量如下:errormsgTYPESTRINGgt_custnoTYPEVBAK-KUNNRgt_datTYPEDZSDFB_YSHDDCXTYPETT_YSHDDCX变量作用解释:Errormsg,定义展现错误信息的;gt_custno:存放网页上客户的数据gt_dat:存放网页上日期的数据ZSDFB_YSHDDCX:自定义的类型用来存放要输出数据的内表;七、代码实现,在Typedefinition定义类型,定义如下:TYPES:tt_YSHDDCXTYPESTANDARDTABLEOFZSDFB_YSHDDCXINITIALSIZE0.注意:ZSDFB_YSHDDCX是自定义的一个结构,结果字段如下:KUNNRKUNAGCHAR100售达方NAME1NAME1CHAR300名称VBELNVBELNCHAR100销售和分销凭证号BSTNKBSTNKCHAR200客户采购订单编号AUDATAUDATDATS80凭证日期(接收/发送日期)KZWI2KZWI1CURR132从条件定价过程小计1VDATUEDATU_VBAKDATS80请求交货日期SPARTSPARTCHAR20产品组ZJSLKWMENGQUAN153以销售单位表