通过上面三节,我们大致了解了ALV开发中与用户端直接交互的选择屏幕的开发。从这节开始,就进入ALV 的开发讲解咯。
一、ALV简介
ALV--SAP LIST VIEWER 是SAP提供的一种报表方式。
二、ALV开发
ALV 的开发可以通过多种方式实现,下面先讲以类型池SLIS为开头的AVL类型报表的开发。
2.1 SLIS
以这种方式开发的ALV 报表需要预先声明SLIS:Type-pools:slis.
在该类型池下会有相应的结构或表类型供我们参考调用,如下:
SLIS_T_LISTHEADER:用于设置ALV的抬头信息的表结构;
SLIS_FIELDCAT_ALV:用于设置ALV输出字段信息的结构;
SLIS_T_FIELDCAT_ALV:用于设置ALV输出字段信息的表结构;
SLIS_T_SORTINFO_ALV:用于指定ALV输出数据按指定的字段进行排序的表结构;
SLIS_LAYOUT_ALV:用于设置ALV 输出的报表布局的结构;
SLIS_T_EVENT:用于ALV事件设置的表结构;
该ALV报表调用到的显示函数有:REUSE_ALV_GRID_DISPLAY 和REUSE_ALV_LIST_DISPLAY,这两个函数的区别在于ALV显示的模式不同,个人而言前者比较没有、实用。
2.1.1 应用实例
需求提出:SD部门提出开发一张销售订单跟踪报表来反映销售订单的终止。
可以从中看出ALV的开发过程:
第一步,要定义Type-pools:slis.
事件处理子程序,(一般的开发中,我对于这个字模块都是直接COPY,不做修改)
ALV布局设置子程序,
ALV输出字段定义,由于输出的字段太多,因此我只截取了其中几个字段,输出字段的设置还可以通过宏定义进行调用设置。
ALV 输出调用函数,在该例子中使用的函数是 : REUSE_ALV_GRID_DISPLAY,调用该函数显示比较美观
以下是该程序的具体代码,供参考:不足之处请指点,谢谢!
1 report zsdr0010. 2 3 *----------------------------------------------------------------------* 4 * 包含 * 5 *----------------------------------------------------------------------* 6 include zsdr0010_define. "全局定义 7 include zsdr0010_sel. "选择界面定义 8 include zsdr0010_frm. "子例程 9 10 11 *&---------------------------------------------------------------------* 12 *& Include ZSDR0010_DEFINE 13 *&---------------------------------------------------------------------* 14 *----------------------------------------------------------------------* 15 *表声明 * 16 *----------------------------------------------------------------------* 17 tables: vbap,vbep,vbkd,vbak. 18 *----------------------------------------------------------------------* 19 *结构定义 * 20 *----------------------------------------------------------------------* 21 types: begin of gs_xsgz, 22 sortl type kna1-sortl, "客户检索 23 kunnr type vbak-kunnr, "售达方 24 kunnr1 type vbpa-kunnr, "付款方 25 kunnr2 type vbpa-kunnr, "收货方/送达方 26 bezei type tvakt-bezei,"订单类型秒送 27 vkorg type vbak-vkorg, "销售组织 28 spart type vbak-spart, "产品组 29 erdat type vbak-erdat, "凭证日期 30 vbeln type vbak-vbeln, "销售订单 31 posnr type vbap-posnr, "订单行项目 32 matnr type vbap-matnr, "物料ID 33 zkhwl type c length 200,"客户物料描述 34 arktx type vbap-arktx, "物料描述 35 zpsdat1 type zsdt0011-zpsdat1, "订单评审提交日期 36 zpsdat2 type zsdt0011-zpsdat2, "订单评审完成日期 37 zpsdat3 type zsdt0011-zpsdat3, "订单签发完成日期 38 kwmeng type vbap-kwmeng,"订单数量 39 bstkd type vbkd-bstkd, "采购订单编号 40 edatu type vbep-edatu, "交货日期 41 kpein type vbap-kpein, "单位 42 kbetr type konv-kbetr, "单价 43 netwr type vbap-netwr, "金额 44 waerk type vbak-waerk, "币种 45 vkbur type vbak-vkbur, "销售部门 46 zaed type tvgrt-bezei,"AE 47 zomd type tvv2t-bezei,"OM 48 zstau type tvbst-bezei,"订单行状态 49 wjhsl type vbap-kwmeng,"未计划数量 50 gsmng type plaf-gsmng, "在计划数量 51 zwqcg type eket-menge, "未清采购订单 52 psmng type afpo-psmng, "在制生产订单 53 rfmng type vbfa-rfmng, "已出货数量 54 wchsl type vbap-kwmeng,"未出货数量 55 kalab type mska-kalab, "库存数量 56 end of gs_xsgz, 57 58 begin of gs_vbap, 59 vbeln type vbak-vbeln, "销售订单 60 auart type vbak-auart, "订单类型 61 vkorg type vbak-vkorg, "销售组织 62 vkgrp type vbak-vkgrp, "销售组 63 spart type vbak-spart, "产品组 64 erdat type vbak-erdat, "凭证日期 65 kunnr type vbak-kunnr, "售达方 66 waerk type vbak-waerk, "币种 67 vkbur type vbak-vkbur, "销售部门 68 knumv type vbak-knumv, "单据条件数 69 kvgr2 type vbak-kvgr2, "OM 70 posnr type vbap-posnr, "订单行项目 71 matnr type vbap-matnr, "物料ID 72 arktx type vbap-arktx, "物料描述 73 werks type vbap-werks, "工厂 74 kwmeng type vbap-kwmeng,"订单数量 75 kpein type vbap-kpein, "单位 76 netwr type vbap-netwr, "金额 77 lfsta type vbup-lfsta, "行项目状态标识 78 end of gs_vbap, 79 80 begin of gs_kna1, 81 kunnr type kna1-kunnr,"客户号 82 sortl type kna1-sortl,"客户检索 83 end of gs_kna1, 84 85 begin of gs_vbkd, 86 vbeln type vbkd-vbeln, "销售订单 87 "posnr TYPE vbkd-posnr, "订单行项目 88 bstkd type vbkd-bstkd, "采购订单编号 89 bzirk type vbkd-bzirk, "销售地区 90 end of gs_vbkd, 91 92 begin of gs_vbep, 93 vbeln type vbep-vbeln, "销售订单 94 posnr type vbep-posnr, "销售订单 95 edatu type vbep-edatu, "交货日期 96 end of gs_vbep, 97 98 begin of gs_vbpa, 99 vbeln type vbpa-vbeln, "销售订单 100 posnr type vbpa-posnr, "订单行项目 101 parvw type vbpa-parvw, "合作伙伴功能 102 kunnr type vbpa-kunnr, "客户 103 end of gs_vbpa, 104 105 begin of gs_zsdt0011, 106 vbeln type zsdt0011-vbeln, "销售订单 107 posnr type zsdt0011-posnr, "订单行项目 108 zpsdat1 type zsdt0011-zpsdat1, "订单评审提交日期 109 zpsdat2 type zsdt0011-zpsdat2, "订单评审完成日期 110 zpsdat3 type zsdt0011-zpsdat3, "订单签发完成日期 111 end of gs_zsdt0011, 112 113 begin of gs_konv, 114 knumv type konv-knumv, "单据条件数 115 kposn type konv-kposn, "条件项目号 116 kschl type konv-kschl, "条件类型 117 kbetr type konv-kbetr, "价格( 条件金额或百分数 ) 118 end of gs_konv, 119 120 begin of gs_plaf, 121 kdauf type plaf-kdauf, "销售订单 122 kdpos type plaf-kdpos, "订单行项目 123 auffx type plaf-auffx, "计划订货数据的确定的标识 124 gsmng type plaf-gsmng, "全部的计划订单数量 125 end of gs_plaf, 126 127 begin of gs_afpo, 128 aufnr type afpo-aufnr,"订单号 129 posnr type afpo-posnr,"订单项目编号 130 kdauf type afpo-kdauf,"销售订单号 131 kdpos type afpo-kdpos,"销售订单行项 132 psmng type afpo-psmng,"订单项数量 133 wemng type afpo-wemng,"此订单项的收货数量 134 end of gs_afpo, 135 136 begin of gs_mska, 137 matnr type mska-matnr,"物料号 138 vbeln type mska-vbeln,"销售和分销凭证号 139 posnr type mska-posnr,"销售和分销凭证的项目号 140 charg type mska-charg,"批号 141 kalab type mska-kalab,"非限制使用的估价的库存 142 kains type mska-kains," 143 end of gs_mska, 144 145 *定义存放销售组织的结构 146 begin of gs_tvko, 147 bukrs type tvko-bukrs, "公司代码 148 vkorg type tvko-vkorg, "销售组织 149 end of gs_tvko. 150 151 *----------------------------------------------------------------------* 152 *DSEC;表定义 * 153 *----------------------------------------------------------------------* 154 data: gt_xsgz type standard table of gs_xsgz, 155 gt_vbap type standard table of gs_vbap, 156 gt_kna1 type standard table of gs_kna1, 157 gt_vbkd type standard table of gs_vbkd, 158 gt_vbep type standard table of gs_vbep, 159 gt_vbpa type standard table of gs_vbpa, 160 gt_konv type standard table of gs_konv, 161 gt_zsdt0011 type standard table of gs_zsdt0011, 162 gt_tvakt type standard table of tvakt, 163 gt_tvgrt type standard table of tvgrt, 164 gt_tvv2t type standard table of tvv2t, 165 gt_tvbst type standard table of tvbst, 166 gt_line type standard table of tline with header line, 167 gt_plaf type standard table of gs_plaf, 168 gt_afpo type standard table of gs_afpo, 169 gt_mska type standard table of gs_mska, 170 gt_tvko type standard table of gs_tvko. 171 data: gt_zbos001 type standard table of zbos001. "操作人员权限公司 172 173 *&---------------------------------------------------------------------* 174 *& DESC:ALV 变量定义 * 175 *&---------------------------------------------------------------------* 176 type-pools: slis. 177 data: gt_fieldcat type slis_t_fieldcat_alv with header line, "定义存放输出字段的内表 178 gw_layout type slis_layout_alv, "定义ALV布局设置的工作区 179 g_repid type sy-repid. "定义系统当前程序名变量 180 data: gw_stru_disvar type disvariant, "ALV 显示格式 181 gt_events type slis_t_event. "ALV 事件 182 183 *----------------------------------------------------------------------* 184 *DESC:字段符号 * 185 *----------------------------------------------------------------------* 186 field-symbols: <fs_vbap> type gs_vbap, 187 <fs_kna1> type gs_kna1, 188 <fs_vbkd> type gs_vbkd, 189 <fs_vbep> type gs_vbep, 190 <fs_vbpa> type gs_vbpa, 191 <fs_konv> type gs_konv, 192 <fs_tvak> type tvakt, 193 <fs_tvgr> type tvgrt, 194 <fs_tvv2> type tvv2t, 195 <fs_tvbs> type tvbst, 196 <fs_zsdt0011> type gs_zsdt0011, 197 <fs_afpo> type gs_afpo. 198 199 *----------------------------------------------------------------------* 200 *DESC:全局变量 * 201 *----------------------------------------------------------------------* 202 data: g_date type d. 203 data: gw_xsgz type gs_xsgz. 204 data: gw_plaf type gs_plaf. 205 data: g_name type c length 70. 206 data: gw_zbos001 type zbos001. "定义权限公司工作区 207 data: gw_tvko type gs_tvko. "定义销售组织工作区 208 ranges: r_vkorg for tvko-vkorg. 209 data: g_amta type c."设置金额显示权限标识 210 211 212 213 *&---------------------------------------------------------------------* 214 *& Include ZSDR0010_SEL 215 *&---------------------------------------------------------------------* 216 *----------------------------------------------------------------------* 217 *DESC:选择屏幕定义 * 218 *----------------------------------------------------------------------* 219 selection-screen begin of block blk1 with frame title text-001. 220 select-options: s_vbeln for vbap-vbeln,"销售订单 221 s_posnr for vbap-posnr,"订单行项目 222 s_matnr for vbap-matnr,"物料ID 223 s_edatu for vbep-edatu obligatory,"交货日期 224 s_audat for vbak-audat,"创建日期 225 s_bzirk for vbkd-bzirk,"销售地区__ 226 s_kunnr for vbak-kunnr."售达方 227 selection-screen end of block blk1. 228 229 *&---------------------------------------------------------------------* 230 *& Initialization 231 *&---------------------------------------------------------------------* 232 initialization. 233 perform frm_init. 234 235 *&---------------------------------------------------------------------* 236 *& At selection-screen 237 *&---------------------------------------------------------------------* 238 at selection-screen. 239 "PERFORM frm_check_input. 240 241 *&---------------------------------------------------------------------* 242 *& start-of-selection 243 *&---------------------------------------------------------------------* 244 start-of-selection. 245 perform frm_fetch_data. 246 perform frm_get_event. "设置自定义事件处理程序 247 perform frm_init_layout. "设置输出格式 248 perform frm_init_fieldcat. "设置输出字段 249 perform frm_output. "输出 250 251 252 253 254 *&---------------------------------------------------------------------* 255 *& Include ZSDR0010_FRM 256 *&---------------------------------------------------------------------* 257 *----------------------------------------------------------------------* 258 *DESC:初始化选择日期 * 259 *----------------------------------------------------------------------* 260 form frm_init. 261 clear: g_date. 262 call function 'MONTH_PLUS_DETERMINE' 263 exporting 264 months = '-1' 265 olddate = sy-datum 266 importing 267 newdate = g_date. 268 s_edatu-low = g_date. 269 s_edatu-high = sy-datum. 270 append s_edatu. 271 endform. "frm_init 272 273 *----------------------------------------------------------------------* 274 *DESC:对操作人员进行权限处理 * 275 *----------------------------------------------------------------------* 276 form frm_check_input. 277 "定义临时变量 278 ranges:l_bukrs for tvko-bukrs. 279 280 call function 'ZBO_AUTHORITY_CHECK' 281 exporting 282 * HIGH = 283 * LOW = 284 uname = sy-uname 285 tables 286 pt_zbot001 = gt_zbos001. 287 288 "判断 289 if gt_zbos001 is initial. 290 message '当前用户没有授予权限查询该报表!' type 'E'. 291 else. 292 "组合公司代码范围 293 sort gt_zbos001 by bukrs. 294 read table gt_zbos001 into gw_zbos001 index 1. 295 l_bukrs-low = gw_zbos001-bukrs. 296 sort gt_zbos001 by bukrs descending. 297 read table gt_zbos001 into gw_zbos001 index 1. 298 l_bukrs-high = gw_zbos001-bukrs. 299 l_bukrs-sign = 'I'. 300 l_bukrs-option = 'BT'. 301 append l_bukrs. 302 "根据公司代码获取销售组织 303 select bukrs "公司代码 304 vkorg "销售组织 305 into corresponding fields of table gt_tvko 306 from tvko 307 where bukrs in l_bukrs. 308 "组合销售组织范围 309 sort gt_tvko by vkorg. 310 read table gt_tvko into gw_tvko index 1. 311 r_vkorg-low = gw_tvko-vkorg. 312 sort gt_tvko by vkorg descending. 313 read table gt_tvko into gw_tvko index 1. 314 r_vkorg-high = gw_tvko-vkorg. 315 r_vkorg-sign = 'I'. 316 r_vkorg-option = 'BT'. 317 append r_vkorg. 318 endif. 319 320 "金额权限判定 321 authority-check object 'ZAMTA' for user sy-uname id 'NETWR' dummy. 322 if sy-subrc = 0. 323 g_amta = 'X'. 324 endif. 325 326 endform. "frm_check_input 327 328 *&---------------------------------------------------------------------* 329 *&DESC: Form FRM_Fetch_Data 获取数据库的相关数据 * 330 *&---------------------------------------------------------------------* 331 form frm_fetch_data. 332 *定义临时变量: 333 data: l_rfmng1 type vbfa-rfmng,"存放正值出货数量 334 l_rfmng2 type vbfa-rfmng,"存放负值出货数量 335 l_kalab type mska-kalab,"存放销售订单库存数据1 336 l_kains type mska-kains,"存放销售订单库存数据2 337 l_menge type eket-menge,"存放未清销售订单数据1 338 l_wemng type eket-wemng,"存放未清销售订单数据2 339 l_objnr like jsto-objnr,"对象号 340 lw_jstat type jstat,"状态工作区 341 lt_jstat type table of jstat."状态内表 342 data: lt_vbap type standard table of gs_vbap."____lyf 09-04 343 *先根据选择屏幕筛选出相应字段到内表gt_vbap 344 select vbak~vbeln "销售订单 345 vbak~auart "订单类型 346 vbak~vkorg "销售组织 347 vbak~vkgrp "销售组 348 vbak~spart "产品组 349 vbak~erdat "凭证日期 350 vbak~kunnr "售达方 351 vbak~waerk "币种 352 vbak~vkbur "销售部门 353 vbak~knumv "单据条件数 354 vbak~kvgr2 "OM 355 vbap~posnr "订单行项目 356 vbap~matnr "物料ID 357 vbap~arktx "物料描述 358 vbap~kwmeng "订单数量 359 vbap~werks "工厂 360 vbap~kpein "单位 361 vbap~netwr "金额 362 into corresponding fields of table gt_vbap 363 from vbak join vbap on vbak~vbeln = vbap~vbeln 364 * JOIN vbkd ON vbkd~vbeln = vbap~vbeln 365 * AND vbkd~posnr = vbap~posnr 366 where vbak~vbeln in s_vbeln 367 and vbap~posnr in s_posnr 368 and vbap~matnr in s_matnr 369 "AND vbkd~bzirk IN s_bzirk 370 and vbak~kunnr in s_kunnr 371 and vbak~audat in s_audat. 372 "AND vbak~vkorg IN r_vkorg."根据操作人员的权限而对应的销售组织 373 374 sort gt_vbap by vbeln posnr. 375 376 *删除不在选择范围内的记录 377 if gt_vbap[] is not initial. 378 select vbeln "销售订单 379 posnr "订单行项目 380 edatu "交货日期 381 into corresponding fields of table gt_vbep 382 from vbep 383 for all entries in gt_vbap 384 where vbeln = gt_vbap-vbeln 385 and posnr = gt_vbap-posnr 386 and etenr = 1. 387 sort gt_vbep by vbeln posnr. 388 389 loop at gt_vbap assigning <fs_vbap>. 390 read table gt_vbep assigning <fs_vbep> with key vbeln = <fs_vbap>-vbeln 391 posnr = <fs_vbap>-posnr binary search. 392 if sy-subrc = 0."该销售订单存在交货日期 393 if <fs_vbep>-edatu not in s_edatu. "交货日期不在选择范围内 394 delete gt_vbap. 395 else. "如果在选择范围内,则维护订单行项目状态 396 select single lfsta 397 into <fs_vbap>-lfsta 398 from vbup 399 where vbeln = <fs_vbap>-vbeln 400 and posnr = <fs_vbap>-posnr. 401 endif. 402 else. "交货日期为空,删除 403 delete gt_vbap. 404 endif. 405 endloop. 406 endif. 407 408 *获取采购订单编号并删除不在范围内的记录 409 410 if gt_vbap[] is not initial. 411 select vbeln "销售订单 412 bstkd "采购订单编号 413 bzirk "销售地区 414 into corresponding fields of table gt_vbkd 415 from vbkd 416 for all entries in gt_vbap 417 where vbeln = gt_vbap-vbeln. 418 sort gt_vbkd by vbeln. 419 420 if s_bzirk is not initial."如果筛选条件有销售地区 421 delete gt_vbkd where bzirk not in s_bzirk."删除销售地区不在选择范围内的记录 422 loop at gt_vbap assigning <fs_vbap>. 423 read table gt_vbkd assigning <fs_vbkd> with key vbeln = <fs_vbap>-vbeln binary search. 424 if sy-subrc <> 0."销售地区不在选择范围内,删除 425 delete gt_vbap. 426 endif. 427 endloop. 428 endif. 429 endif. 430 *获取客户检索号 431 if gt_vbap[] is not initial. 432 select kunnr "客户号 433 sortl "客户检索号 434 into corresponding fields of table gt_kna1 435 from kna1 436 for all entries in gt_vbap 437 where kunnr = gt_vbap-kunnr. 438 endif. 439 440 *获取客户号 441 if gt_vbap[] is not initial. 442 select vbeln "销售订单 443 posnr "订单行项目 444 parvw "客户类型 445 kunnr "客户号 446 into corresponding fields of table gt_vbpa 447 from vbpa 448 for all entries in gt_vbap 449 where vbeln = gt_vbap-vbeln. 450 "AND posnr = gt_vbap-posnr. 451 endif. 452 453 *获取订单评审日期 454 if gt_vbap[] is not initial. 455 select vbeln "销售订单 456 posnr "订单行项目 457 zpsdat1 "订单评审提交日期 458 zpsdat2 "订单评审完成日期 459 zpsdat3 "订单签发完成日期 460 into corresponding fields of table gt_zsdt0011 461 from zsdt0011 462 for all entries in gt_vbap 463 where vbeln = gt_vbap-vbeln 464 and posnr = gt_vbap-posnr. 465 endif. 466 467 *获取销售凭证单价 468 if gt_vbap[] is not initial. 469 select knumv "单据条件数 470 kposn "条件项目号 471 kschl "条件类型 472 kbetr "价格 473 into corresponding fields of table gt_konv 474 from konv 475 for all entries in gt_vbap 476 where knumv = gt_vbap-knumv 477 and kposn = gt_vbap-posnr 478 and kschl = 'PR00'. 479 endif. 480 481 *获取销售订单类型描述 482 if gt_vbap[] is not initial. 483 select * 484 into corresponding fields of table gt_tvakt 485 from tvakt 486 for all entries in gt_vbap 487 where auart = gt_vbap-auart 488 and spras = '1'. 489 endif. 490 491 *获取AE描述 492 if gt_vbap[] is not initial. 493 select * 494 into corresponding fields of table gt_tvgrt 495 from tvgrt 496 for all entries in gt_vbap 497 where vkgrp = gt_vbap-vkgrp 498 and spras = '1'. 499 endif. 500 501 *获取OM 502 if gt_vbap[] is not initial. 503 select * 504 into corresponding fields of table gt_tvv2t 505 from tvv2t 506 for all entries in gt_vbap 507 where kvgr2 = gt_vbap-kvgr2 508 and spras = '1'. 509 endif. 510 511 *获取订单行项目状态 512 if gt_vbap[] is not initial. 513 select * 514 into corresponding fields of table gt_tvbst 515 from tvbst 516 for all entries in gt_vbap 517 where spras = '1' 518 and tbnam = 'VBUP' 519 and fdnam = 'LFSTA' 520 and statu = gt_vbap-lfsta. 521 endif. 522 523 *维护主数据 524 sort gt_kna1 by kunnr. 525 sort gt_tvakt by auart. 526 sort gt_tvgrt by vkgrp. 527 sort gt_tvv2t by kvgr2. 528 sort gt_vbkd by vbeln." posnr. 529 sort gt_vbpa by vbeln posnr parvw. 530 sort gt_vbep by vbeln posnr. 531 sort gt_konv by knumv kposn. 532 sort gt_tvbst by statu. 533 loop at gt_vbap assigning <fs_vbap>. 534 clear: gw_xsgz. 535 "维护主结构的一般数据 536 gw_xsgz-vbeln = <fs_vbap>-vbeln. "销售订单 537 gw_xsgz-posnr = <fs_vbap>-posnr. "销售订单行项目 538 gw_xsgz-vkorg = <fs_vbap>-vkorg. "销售组织 539 gw_xsgz-spart = <fs_vbap>-spart. "产品组 540 gw_xsgz-erdat = <fs_vbap>-erdat. "凭证日期 541 gw_xsgz-matnr = <fs_vbap>-matnr. "产品ID 542 gw_xsgz-arktx = <fs_vbap>-arktx. "产品描述 543 gw_xsgz-kunnr = <fs_vbap>-kunnr. "售达方 544 gw_xsgz-kpein = <fs_vbap>-kpein. "单位 545 gw_xsgz-netwr = <fs_vbap>-netwr. "金额 546 gw_xsgz-waerk = <fs_vbap>-waerk. "币种 547 gw_xsgz-vkbur = <fs_vbap>-vkbur. "销售部门 548 "gw_xsgz-kvgr2 = <fs_vbap>-kvgr2. "OM 549 gw_xsgz-kwmeng = <fs_vbap>-kwmeng. "订单数量 550 "维护客户检索 551 read table gt_kna1 assigning <fs_kna1> with key kunnr = <fs_vbap>-kunnr binary search. 552 if sy-subrc = 0. 553 gw_xsgz-sortl = <fs_kna1>-sortl. 554 endif. 555 "订单类型描述 556 read table gt_tvakt assigning <fs_tvak> with key auart = <fs_vbap>-auart binary search. 557 if sy-subrc = 0. 558 gw_xsgz-bezei = <fs_tvak>-bezei. 559 endif. 560 "获取采购订单编号 561 read table gt_vbkd assigning <fs_vbkd> with key vbeln = <fs_vbap>-vbeln binary search. 562 if sy-subrc = 0. 563 gw_xsgz-bstkd = <fs_vbkd>-bstkd. 564 endif. 565 "获取AE 566 read table gt_tvgrt assigning <fs_tvgr> with key vkgrp = <fs_vbap>-vkgrp binary search. 567 if sy-subrc = 0. 568 gw_xsgz-zaed = <fs_tvgr>-bezei. 569 endif. 570 "获取OM 571 read table gt_tvv2t assigning <fs_tvv2> with key kvgr2 = <fs_vbap>-kvgr2 binary search. 572 if sy-subrc = 0. 573 gw_xsgz-zomd = <fs_tvv2>-bezei. 574 endif. 575 "获取付款方 576 read table gt_vbpa assigning <fs_vbpa> with key vbeln = <fs_vbap>-vbeln 577 "posnr = <fs_vbap>-posnr 578 parvw = 'RG' binary search. 579 if sy-subrc = 0. 580 gw_xsgz-kunnr1 = <fs_vbap>-kunnr. 581 endif. 582 "获取收货方 583 read table gt_vbpa assigning <fs_vbpa> with key vbeln = <fs_vbap>-vbeln 584 "posnr = <fs_vbap>-posnr 585 parvw = 'WE' binary search. 586 if sy-subrc = 0. 587 gw_xsgz-kunnr2 = <fs_vbap>-kunnr. 588 endif. 589 "获取交货日期 590 read table gt_vbep assigning <fs_vbep> with key vbeln = <fs_vbap>-vbeln 591 posnr = <fs_vbap>-posnr binary search. 592 if sy-subrc = 0. 593 gw_xsgz-edatu = <fs_vbep>-edatu. 594 endif. 595 "获取评审日期 596 read table gt_zsdt0011 assigning <fs_zsdt0011> with key vbeln = <fs_vbap>-vbeln 597 posnr = <fs_vbap>-posnr binary search. 598 if sy-subrc = 0. 599 gw_xsgz-zpsdat1 = <fs_zsdt0011>-zpsdat1."订单评审提交日期 600 gw_xsgz-zpsdat2 = <fs_zsdt0011>-zpsdat2."订单评审完成日期 601 gw_xsgz-zpsdat3 = <fs_zsdt0011>-zpsdat3."订单签发完成日期 602 endif. 603 "获取客户物料描述 604 concatenate <fs_vbap>-vbeln <fs_vbap>-posnr into g_name. 605 perform frm_read_text tables gt_line 606 using 'Z001' '1' g_name 'VBBP'. 607 if gt_line[] is not initial. 608 loop at gt_line. 609 concatenate gw_xsgz-zkhwl gt_line-tdline into gw_xsgz-zkhwl. 610 endloop. 611 endif. 612 clear: g_name. 613 refresh gt_line. 614 "获取AE值 615 read table gt_tvgrt assigning <fs_tvgr> with key vkgrp = <fs_vbap>-vkgrp 616 spras = '1' binary search. 617 if sy-subrc = 0. 618 gw_xsgz-zaed = <fs_tvgr>-bezei. 619 endif. 620 "获取单价 621 read table gt_konv assigning <fs_konv> with key knumv = <fs_vbap>-knumv 622 kposn = <fs_vbap>-posnr binary search. 623 if sy-subrc = 0. 624 gw_xsgz-kbetr = <fs_konv>-kbetr. 625 endif. 626 "维护行项目状态 627 read table gt_tvbst assigning <fs_tvbs> with key statu = <fs_vbap>-lfsta binary search. 628 if sy-subrc = 0. 629 gw_xsgz-zstau = <fs_tvbs>-bezei. 630 endif. 631 632 "维护在计划数量 633 clear: gw_plaf. 634 select single kdauf kdpos auffx gsmng 635 from plaf 636 into corresponding fields of gw_plaf 637 where kdauf = <fs_vbap>-vbeln 638 and kdpos = <fs_vbap>-posnr 639 and auffx = 'X' 640 and obart = 1. 641 if sy-subrc = 0. 642 gw_xsgz-gsmng = gw_plaf-gsmng. 643 endif. 644 "维护未清采购订单 645 clear:l_menge,l_wemng. 646 select sum( eket~menge ) 647 into l_menge 648 from ekkn join ekpo on ekkn~ebeln = ekpo~ebeln 649 and ekkn~ebelp = ekpo~ebelp 650 join eket on ekpo~ebeln = eket~ebeln 651 and ekpo~ebelp = eket~ebelp 652 where ekkn~vbeln = <fs_vbap>-vbeln 653 and ekkn~vbelp = <fs_vbap>-posnr 654 and ekpo~matnr = <fs_vbap>-matnr 655 and ekpo~werks = <fs_vbap>-werks 656 and ekpo~loekz <> 'L' 657 and ekpo~elikz <> 'X'. 658 select sum( eket~wemng ) 659 into l_wemng 660 from ekkn join ekpo on ekkn~ebeln = ekpo~ebeln 661 and ekkn~ebelp = ekpo~ebelp 662 join eket on ekpo~ebeln = eket~ebeln 663 and ekpo~ebelp = eket~ebelp 664 where ekkn~vbeln = <fs_vbap>-vbeln 665 and ekkn~vbelp = <fs_vbap>-posnr 666 and ekpo~matnr = <fs_vbap>-matnr 667 and ekpo~werks = <fs_vbap>-werks 668 and ekpo~loekz <> 'L' 669 and ekpo~elikz <> 'X'. 670 gw_xsgz-zwqcg = l_menge - l_wemng."未清采购订单 671 "维护已出货数量 672 clear: l_rfmng1,l_rfmng2. 673 select sum( rfmng ) 674 into l_rfmng1 675 from vbfa 676 where vbelv = <fs_vbap>-vbeln 677 and posnv = <fs_vbap>-posnr 678 and vbtyp_n in ('R','h') 679 and bwart in ('601','Z61'). 680 select sum( rfmng ) 681 into l_rfmng2 682 from vbfa 683 where vbelv = <fs_vbap>-vbeln 684 and posnv = <fs_vbap>-posnr 685 and vbtyp_n in ('R','h') 686 and bwart in ('602','Z62'). 687 gw_xsgz-rfmng = l_rfmng1 - l_rfmng2."已出货数量 688 "未出货数量 689 gw_xsgz-wchsl = gw_xsgz-kwmeng - gw_xsgz-rfmng."未出货数量 690 "维护订单库存数量 691 clear: l_kalab,l_kains. 692 select sum( kalab ) 693 into l_kalab 694 from mska 695 where vbeln = gw_xsgz-vbeln 696 and posnr = gw_xsgz-posnr 697 and matnr = gw_xsgz-matnr. 698 select sum( kains ) 699 into l_kains 700 from mska 701 where vbeln = gw_xsgz-vbeln 702 and posnr = gw_xsgz-posnr 703 and matnr = gw_xsgz-matnr. 704 gw_xsgz-kalab = l_kalab + l_kains. 705 "维护在制生产订单 706 clear gt_afpo. 707 select aufnr posnr kdauf kdpos psmng wemng 708 from afpo 709 into corresponding fields of table gt_afpo 710 where kdauf = <fs_vbap>-vbeln 711 and kdpos = <fs_vbap>-posnr. 712 loop at gt_afpo assigning <fs_afpo>. 713 clear l_objnr. 714 concatenate 'OR' <fs_afpo>-aufnr into l_objnr. 715 clear lt_jstat. 716 call function 'STATUS_READ' 717 exporting 718 objnr = l_objnr 719 only_active = 'X' 720 tables 721 status = lt_jstat 722 exceptions 723 object_not_found = 1 724 others = 2. 725 if sy-subrc = 0. 726 "CRTD 727 clear lw_jstat. 728 read table lt_jstat into lw_jstat with key stat = 'I0001'. 729 if sy-subrc = 0. 730 "DLV 731 clear lw_jstat. 732 read table lt_jstat into lw_jstat with key stat = 'I0012'. 733 if sy-subrc = 0. 734 continue. 735 endif. 736 "DLID 737 clear lw_jstat. 738 read table lt_jstat into lw_jstat with key stat = 'I0076'. 739 if sy-subrc = 0. 740 continue. 741 endif. 742 gw_xsgz-psmng = gw_xsgz-psmng + <fs_afpo>-psmng - <fs_afpo>-wemng. 743 continue. 744 endif. 745 "REL 746 clear lw_jstat. 747 read table lt_jstat into lw_jstat with key stat = 'I0002'. 748 if sy-subrc = 0. 749 "DLV 750 clear lw_jstat. 751 read table lt_jstat into lw_jstat with key stat = 'I0012'. 752 if sy-subrc = 0. 753 continue. 754 endif. 755 "DLID 756 clear lw_jstat. 757 read table lt_jstat into lw_jstat with key stat = 'I0076'. 758 if sy-subrc = 0. 759 continue. 760 endif. 761 gw_xsgz-psmng = gw_xsgz-psmng + <fs_afpo>-psmng - <fs_afpo>-wemng. 762 continue. 763 endif. 764 endif. 765 endloop. 766 "未计划数量= 未出货数量-在计划数量-在制生产订单-销售库存-未清采购数 767 gw_xsgz-wjhsl = gw_xsgz-wchsl - gw_xsgz-gsmng - gw_xsgz-psmng - gw_xsgz-kalab - gw_xsgz-zwqcg. 768 769 append gw_xsgz to gt_xsgz. 770 771 endloop. 772 773 endform. "frm_fetch_date 774 775 *&---------------------------------------------------------------------* 776 *&DESC: Form FRM_GET_EVENT 事件获取子程序 * 777 *&---------------------------------------------------------------------* 778 form frm_get_event . 779 data l_events type slis_alv_event."slis_alv_event是一个包含name和form字段的结构,均为字符型 780 781 call function 'REUSE_ALV_EVENTS_GET' 782 exporting 783 i_list_type = 0 784 importing 785 et_events = gt_events 786 exceptions 787 list_type_wrong = 1 788 others = 2. 789 if sy-subrc <> 0. 790 message id sy-msgid type sy-msgty number sy-msgno 791 with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 792 endif. 793 794 endform. " FRM_GET_EVENT 795 796 *&---------------------------------------------------------------------* 797 *& Form FRM_INIT_LAYOUT 798 *&---------------------------------------------------------------------* 799 form frm_init_layout. 800 gw_layout-zebra = 'X'."间隔行颜色变换 801 gw_layout-detail_popup = 'X'. 802 gw_layout-colwidth_optimize = 'X'."自动调整列宽 803 804 endform. " FRM_INIT_LAYOUT 805 806 *&---------------------------------------------------------------------* 807 *&DESC: Form frm_init_fieldcat ALV输出字段定义 * 808 *&---------------------------------------------------------------------* 809 form frm_init_fieldcat. 810 refresh gt_fieldcat. 811 812 clear: gt_fieldcat. 813 gt_fieldcat-fieldname = 'SORTL'. 814 gt_fieldcat-seltext_m = '客户检索号'. 815 gt_fieldcat-no_zero = 'X'. 816 append gt_fieldcat. 817 818 clear: gt_fieldcat. 819 gt_fieldcat-fieldname = 'KUNNR'. 820 gt_fieldcat-seltext_m = '售达方'. 821 gt_fieldcat-no_zero = 'X'. 822 append gt_fieldcat. 823 824 clear: gt_fieldcat. 825 gt_fieldcat-fieldname = 'KUNNR1'. 826 gt_fieldcat-seltext_m = '付款方'. 827 gt_fieldcat-no_zero = 'X'. 828 append gt_fieldcat. 829 830 clear: gt_fieldcat. 831 gt_fieldcat-fieldname = 'KUNNR2'. 832 gt_fieldcat-seltext_m = '收货方'. 833 gt_fieldcat-no_zero = 'X'. 834 append gt_fieldcat. 835 836 clear: gt_fieldcat. 837 gt_fieldcat-fieldname = 'BEZEI'. 838 gt_fieldcat-seltext_m = '订单类型'. 839 gt_fieldcat-no_zero = 'X'. 840 append gt_fieldcat. 841 842 clear: gt_fieldcat. 843 gt_fieldcat-fieldname = 'VKORG'. 844 gt_fieldcat-seltext_m = '销售组织'. 845 gt_fieldcat-no_zero = 'X'. 846 append gt_fieldcat. 847 848 clear: gt_fieldcat. 849 gt_fieldcat-fieldname = 'SPART'. 850 gt_fieldcat-seltext_m = '产品组'. 851 gt_fieldcat-no_zero = 'X'. 852 append gt_fieldcat. 853 854 clear: gt_fieldcat. 855 gt_fieldcat-fieldname = 'ERDAT'. 856 gt_fieldcat-seltext_m = '凭证日期'. 857 gt_fieldcat-no_zero = 'X'. 858 append gt_fieldcat. 859 860 clear: gt_fieldcat. 861 gt_fieldcat-fieldname = 'VBELN'. 862 gt_fieldcat-seltext_m = '销售订单'. 863 gt_fieldcat-no_zero = 'X'. 864 append gt_fieldcat. 865 866 clear: gt_fieldcat. 867 gt_fieldcat-fieldname = 'POSNR'. 868 gt_fieldcat-seltext_m = '销售订单行项目'. 869 gt_fieldcat-no_zero = 'X'. 870 append gt_fieldcat. 871 872 clear: gt_fieldcat. 873 gt_fieldcat-fieldname = 'MATNR'. 874 gt_fieldcat-seltext_m = '产品ID'. 875 gt_fieldcat-no_zero = 'X'. 876 append gt_fieldcat. 877 878 clear: gt_fieldcat. 879 gt_fieldcat-fieldname = 'ZKHWL'. 880 gt_fieldcat-seltext_m = '客户物料描述'. 881 gt_fieldcat-no_zero = 'X'. 882 append gt_fieldcat. 883 884 clear: gt_fieldcat. 885 gt_fieldcat-fieldname = 'ARKTX'. 886 gt_fieldcat-seltext_m = '产品描述'. 887 gt_fieldcat-no_zero = 'X'. 888 append gt_fieldcat. 889 890 clear: gt_fieldcat. 891 gt_fieldcat-fieldname = 'ZPSDAT1'. 892 gt_fieldcat-seltext_m = '订单评审提交时间'. 893 gt_fieldcat-no_zero = 'X'. 894 append gt_fieldcat. 895 896 clear: gt_fieldcat. 897 gt_fieldcat-fieldname = 'ZPSDAT2'. 898 gt_fieldcat-seltext_m = '订单评审完成时间'. 899 gt_fieldcat-no_zero = 'X'. 900 append gt_fieldcat. 901 902 clear: gt_fieldcat. 903 gt_fieldcat-fieldname = 'ZPSDAT3'. 904 gt_fieldcat-seltext_m = '订单签发时间'. 905 gt_fieldcat-no_zero = 'X'. 906 append gt_fieldcat. 907 908 clear: gt_fieldcat. 909 gt_fieldcat-fieldname = 'KWMENG'. 910 gt_fieldcat-seltext_m = '订单数量'. 911 gt_fieldcat-no_zero = 'X'. 912 append gt_fieldcat. 913 914 clear: gt_fieldcat. 915 gt_fieldcat-fieldname = 'BSTKD'. 916 gt_fieldcat-seltext_m = '采购订单编号'. 917 gt_fieldcat-no_zero = 'X'. 918 append gt_fieldcat. 919 920 clear: gt_fieldcat. 921 gt_fieldcat-fieldname = 'EDATU'. 922 gt_fieldcat-seltext_m = '交货日期'. 923 gt_fieldcat-no_zero = 'X'. 924 append gt_fieldcat. 925 926 clear: gt_fieldcat. 927 gt_fieldcat-fieldname = 'KPEIN'. 928 gt_fieldcat-seltext_m = '单位'. 929 gt_fieldcat-no_zero = 'X'. 930 append gt_fieldcat. 931 932 if g_amta = 'X'. 933 clear: gt_fieldcat. 934 gt_fieldcat-fieldname = 'KBETR'. 935 gt_fieldcat-seltext_m = '单价'. 936 gt_fieldcat-no_zero = 'X'. 937 append gt_fieldcat. 938 939 clear: gt_fieldcat. 940 gt_fieldcat-fieldname = 'NETWR'. 941 gt_fieldcat-seltext_m = '金额'. 942 gt_fieldcat-no_zero = 'X'. 943 append gt_fieldcat. 944 endif. 945 946 clear: gt_fieldcat. 947 gt_fieldcat-fieldname = 'WAERK'. 948 gt_fieldcat-seltext_m = '币种'. 949 gt_fieldcat-no_zero = 'X'. 950 append gt_fieldcat. 951 952 clear: gt_fieldcat. 953 gt_fieldcat-fieldname = 'VKBUR'. 954 gt_fieldcat-seltext_m = '销售部门'. 955 gt_fieldcat-no_zero = 'X'. 956 append gt_fieldcat. 957 958 clear: gt_fieldcat. 959 gt_fieldcat-fieldname = 'ZAED'. 960 gt_fieldcat-seltext_m = 'AE'. 961 gt_fieldcat-no_zero = 'X'. 962 append gt_fieldcat. 963 964 clear: gt_fieldcat. 965 gt_fieldcat-fieldname = 'ZOMD'. 966 gt_fieldcat-seltext_m = 'OM'. 967 gt_fieldcat-no_zero = 'X'. 968 append gt_fieldcat. 969 970 clear: gt_fieldcat. 971 gt_fieldcat-fieldname = 'ZSTAU'. 972 gt_fieldcat-seltext_m = '订单行状态'. 973 gt_fieldcat-no_zero = 'X'. 974 append gt_fieldcat. 975 976 clear: gt_fieldcat. 977 gt_fieldcat-fieldname = 'WJHSL'. 978 gt_fieldcat-seltext_m = '未计划数量'. 979 gt_fieldcat-no_zero = 'X'. 980 append gt_fieldcat. 981 982 clear: gt_fieldcat. 983 gt_fieldcat-fieldname = 'GSMNG'. 984 gt_fieldcat-seltext_m = '在计划数量'. 985 gt_fieldcat-no_zero = 'X'. 986 append gt_fieldcat. 987 988 clear: gt_fieldcat. 989 gt_fieldcat-fieldname = 'ZWQCG'. 990 gt_fieldcat-seltext_m = '未清采购订单数量'. 991 gt_fieldcat-no_zero = 'X'. 992 append gt_fieldcat. 993 994 clear: gt_fieldcat. 995 gt_fieldcat-fieldname = 'PSMNG'. 996 gt_fieldcat-seltext_m = '在制生产订单'. 997 gt_fieldcat-no_zero = 'X'. 998 append gt_fieldcat. 999 1000 clear: gt_fieldcat. 1001 gt_fieldcat-fieldname = 'RFMNG'. 1002 gt_fieldcat-seltext_m = '已出货数量'. 1003 gt_fieldcat-no_zero = 'X'. 1004 append gt_fieldcat. 1005 1006 clear: gt_fieldcat. 1007 gt_fieldcat-fieldname = 'WCHSL'. 1008 gt_fieldcat-seltext_m = '未出货数量'. 1009 gt_fieldcat-no_zero = 'X'. 1010 append gt_fieldcat. 1011 1012 clear: gt_fieldcat. 1013 gt_fieldcat-fieldname = 'KALAB'. 1014 gt_fieldcat-seltext_m = '库存数量'. 1015 gt_fieldcat-no_zero = 'X'. 1016 append gt_fieldcat. 1017 1018 endform. "frm_init_fieldcat 1019 *&---------------------------------------------------------------------* 1020 *&DESC: Form FRM_OUTPUT ALV输出 * 1021 *&---------------------------------------------------------------------* 1022 form frm_output. 1023 *ALV输出 1024 g_repid = sy-repid. 1025 1026 call function 'REUSE_ALV_GRID_DISPLAY' 1027 exporting 1028 i_callback_program = g_repid 1029 is_layout = gw_layout 1030 it_fieldcat = gt_fieldcat[] 1031 i_save = 'X' 1032 is_variant = gw_stru_disvar"变量信息 1033 it_events = gt_events[] "i_callback_user_command = 'FRM_UCOMM' "命令指令定义 1034 tables 1035 t_outtab = gt_xsgz 1036 exceptions 1037 program_error = 1 1038 others = 2. 1039 if sy-subrc <> 0. 1040 message id sy-msgid type sy-msgty number sy-msgno 1041 with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. 1042 endif. 1043 endform. " FRM_OUTPUT 1044 1045 *----------------------------------------------------------------------* 1046 *DESC:获取长文本 * 1047 *----------------------------------------------------------------------* 1048 form frm_read_text tables tab1 1049 using p_v1 p_v2 p_v3 p_v4. 1050 call function 'READ_TEXT' 1051 exporting 1052 client = sy-mandt 1053 id = p_v1 1054 language = p_v2 1055 name = p_v3 1056 object = p_v4 1057 tables 1058 lines = tab1 1059 exceptions 1060 id = 1 1061 language = 2 1062 name = 3 1063 not_found = 4 1064 object = 5 1065 reference_check = 6 1066 wrong_access_to_archive = 7 1067 others = 8. 1068 1069 endform. "frm_read_text