二维码

SD模块带有双击事件的销售分析报表

Twilight发表于 2014-02-04 13:14Twilight 最后回复于 2014-02-04 13:14 [复制链接] 3355 0

选择屏幕
sale_selection_screen.jpg
执行结果,可以双击某行 跳转到系统标准凭证显示界面
sales_report.jpg

主程序代码:
  1. *--------------------------------------------------------------------*
  2. *定义一个与数据库表同名的表
  3. *--------------------------------------------------------------------*
  4. TABLES:KNA1,KNB1,KNVV,KNVP.
  5. *--------------------------------------------------------------------*
  6. *定义结构
  7. *--------------------------------------------------------------------*
  8. DATA:BEGIN OF IT_OUT OCCURS 0,
  9.      VKORG LIKE KNVV-VKORG,"销售组织
  10.      VTEXT LIKE TVKOT-VTEXT,"销售组织描述
  11.      VTWEG like KNVV-VTWEG, "分销渠道
  12.      KUKLA LIKE KNA1-KUKLA, "客户分类
  13.      VTEXT_1 LIKE TKUKT-VTEXT,"分销渠道描述
  14. *--------------------------------------------------------------------*
  15.      SPART LIKE KNVV-SPART,"产品组
  16.      VTEXT_2 LIKE TSPAT-VTEXT,"产品组描述
  17. *--------------------------------------------------------------------*
  18.      VKBUR LIKE KNVV-VKBUR,"销售办事处
  19.      BEZEI LIKE TVKBT-BEZEI,"销售办事处名称
  20.      VKGRP LIKE KNVV-VKGRP,"销售组
  21.      BEZEI_1 LIKE TVGRT-BEZEI,"销售组名称
  22. *--------------------------------------------------------------------*
  23.      KUNNR LIKE KNA1-KUNNR,"客户编号
  24.      KUNN1 LIKE KNA1-KUNNR,"售达方
  25.      KUNN2 LIKE KNA1-KUNNR,"送达方
  26.      NAME1 LIKE KNA1-NAME1,"客户名称
  27.      ADRNR LIKE KNA1-ADRNR,"地址号码
  28.      STREET LIKE ADRC-STREET,"街道名称
  29. *--------------------------------------------------------------------*
  30.      STCEG LIKE KNA1-STCEG,"税号
  31.      BANK1 LIKE KNBK-BANKL,"银行代码
  32.      BANKN LIKE KNBK-BANKN,"银行账户
  33.      KOINH LIKE KNBK-KOINH,"银行户主
  34. *--------------------------------------------------------------------*
  35.      NAME_LAST LIKE ADDR3_DATA-NAME_LAST,"联系人
  36.      ABTNR LIKE KNVK-ABTNR,"职位
  37.      VTEXT_3 LIKE TSABT-VTEXT,"职位描述
  38.      TEL_NUMBER LIKE SZA5_D0700-TEL_NUMBER,"临时存储电话号码
  39.      FAX_NUMBER LIKE SZA5_D0700-FAX_NUMBER,"临时传真电话号码
  40. *--------------------------------------------------------------------*
  41.      KDGRP LIKE KNVV-KDGRP,"客户等级
  42.      KTEXT LIKE T151T-KTEXT,"客户等级描述
  43.      KONDA LIKE KNVV-KONDA,"客户价格等级
  44.      VTEXT_4 LIKE T188T-VTEXT,"客户价格等级描述
  45.      KALKS LIKE KNVV-KALKS,"客户定价
  46.      VTEXT_5 LIKE TVKDT-VTEXT,"客户定价描述
  47. *--------------------------------------------------------------------*
  48.      VWERK LIKE KNVV-VWERK,"交货地点
  49.      NAME2 LIKE T001W-NAME1,"交货地点名称
  50.      TELEPHONE(20),"联系电话
  51.      SORT2 LIKE ADRC-SORT2,"地址检索项
  52.      FAX(20),"传真
  53.      PRSNR LIKE KNVK-PRSNR,"人员内部编号
  54.      ICON_FOLDER TYPE C LENGTH 15,
  55.   END OF IT_OUT.
  56. *--------------------------------------------------------------------*
  57. *定义选择屏幕
  58. *--------------------------------------------------------------------*
  59. SELECT-OPTIONS:S_VKORG FOR KNVV-VKORG OBLIGATORY,
  60.                S_KUKLA FOR KNA1-KUKLA,
  61.                S_VKBUR FOR KNVV-VKBUR,
  62.                S_VKGRP FOR KNVV-VKGRP,
  63.                S_KUNNR FOR KNA1-KUNNR,
  64.                S_KDGRP FOR KNVV-KDGRP,
  65.                S_KUNN1 FOR KNVP-KUNN2,
  66.                S_KUNN2 FOR KNVP-KUNN2.
  67. *--------------------------------------------------------------------*`
  68. DATA:1_TEL_NUMBER LIKE ADRC-TEL_NUMBER,
  69.      1_TEL_EXTENS LIKE ADRC-TEL_EXTENS,
  70.      1_FAX_NUMBER LIKE ADRC-FAX_NUMBER,
  71.      1_FAX_EXTENS LIKE ADRC-FAX_EXTENS,
  72.      1_NAME1 LIKE KNVK-NAME1,
  73.      1_NAMEV LIKE KNVK-NAMEV.
  74. *--------------------------------------------------------------------*
  75. *定义ALV
  76. *--------------------------------------------------------------------*
  77. INCLUDE <ICON>.
  78. TYPE-POOLS:SLIS.
  79. DATA:IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
  80.      WA_FIELDCAT TYPE SLIS_FIELDCAT_ALV,
  81.      IT_EVENT TYPE SLIS_T_EVENT,
  82.      IT_LAYOUT TYPE SLIS_LAYOUT_ALV,
  83.      G_F2CODE LIKE SY-UCOMM VALUE 'LETA'.
  84. *--------------------------------------------------------------------*
  85. *主处理
  86. *--------------------------------------------------------------------*
  87. START-OF-SELECTION.
  88.   SELECT KNVV~VKORG
  89.          KNVV~VTWEG
  90.          KNVV~SPART
  91.          KNVV~VKBUR
  92.          KNVV~VKGRP
  93.          KNA1~KUNNR
  94.          KNA1~NAME1
  95.          KNA1~STCEG
  96.          KNVV~KDGRP
  97.          KNVV~KONDA
  98.          KNVV~KALKS
  99.          KNVV~VWERK
  100.          KNVV~EIKTO
  101.          KNA1~ADRNR
  102.          KNA1~KUKLA
  103.          KNVV~CASSD
  104.   INTO CORRESPONDING FIELDS OF TABLE IT_OUT
  105.   FROM KNA1
  106.   INNER JOIN KNVV ON KNA1~KUNNR = KNVV~KUNNR
  107.     WHERE KNVV~KUNNR IN S_KUNNR
  108.     AND KNVV~VKORG IN S_VKORG
  109.     AND KNA1~KUKLA IN S_KUKLA
  110.     AND KNVV~VKGRP IN S_VKGRP
  111.     AND KNVV~KDGRP IN S_KDGRP
  112.     AND KNVV~VKBUR IN S_VKBUR.

  113.   SORT IT_OUT BY KUNNR VKORG.
  114.   LOOP AT IT_OUT.
  115.     SELECT SINGLE KUNN2 INTO IT_OUT-KUNN1
  116.       FROM KNVP WHERE KUNNR = IT_OUT-KUNNR
  117.       AND SPART = IT_OUT-SPART
  118.       AND VKORG = IT_OUT-VKORG
  119.       AND PARVW = 'AG'.

  120.     IF IT_OUT-KUNN1 NOT IN S_KUNN1.
  121.       DELETE IT_OUT.
  122.       CONTINUE.
  123.     ENDIF.

  124.     SELECT SINGLE KUNN2 INTO IT_OUT-KUNN2
  125.       FROM KNVP WHERE KUNNR = IT_OUT-KUNNR
  126.       AND SPART = IT_OUT-SPART
  127.       AND VKORG = IT_OUT-VKORG
  128.       AND PARVW = 'WE'.

  129.     IF IT_OUT-KUNN2 NOT IN S_KUNN2.
  130.       DELETE IT_OUT.
  131.       CONTINUE.
  132.     ENDIF.
  133.     SELECT SINGLE BANKL BANKN KOINH INTO (IT_OUT-BANK1,IT_OUT-BANKN,IT_OUT-KOINH)
  134.       FROM KNBK WHERE KUNNR = IT_OUT-KUNNR.
  135.     SELECT SINGLE VTEXT INTO IT_OUT-VTEXT
  136.       FROM TVKOT WHERE VKORG = IT_OUT-VKORG.
  137.     SELECT SINGLE VTEXT INTO IT_OUT-VTEXT_1
  138.       FROM TKUKT WHERE KUKLA = IT_OUT-KUKLA.
  139.     SELECT SINGLE VTEXT INTO IT_OUT-VTEXT_2
  140.       FROM TSPAT WHERE SPART = IT_OUT-SPART.
  141.     SELECT SINGLE BEZEI INTO IT_OUT-BEZEI
  142.       FROM TVKBT WHERE VKBUR = IT_OUT-VKBUR.
  143.     SELECT SINGLE BEZEI INTO IT_OUT-BEZEI_1
  144.       FROM TVGRT WHERE VKGRP = IT_OUT-VKGRP.
  145.     SELECT SINGLE STREET SORT2 INTO (IT_OUT-STREET,IT_OUT-SORT2)
  146.       FROM ADRC  WHERE ADDRNUMBER = IT_OUT-ADRNR.

  147.     CLEAR:1_NAME1, 1_NAMEV."获取合作伙伴的信息
  148.     SELECT SINGLE NAME1 NAMEV PRSNR ABTNR
  149.       INTO (1_NAME1,1_NAMEV,IT_OUT-PRSNR,IT_OUT-ABTNR)
  150.       FROM KNVK WHERE KUNNR = IT_OUT-KUNNR.
  151.     CONCATENATE 1_NAME1 1_NAMEV INTO IT_OUT-NAME_LAST.
  152. *--------------------------------------------------------------------*
  153. ***职位描述
  154.     SELECT SINGLE VTEXT INTO IT_OUT-VTEXT_3
  155.       FROM TSABT WHERE ABTNR = IT_OUT-ABTNR.
  156. ***客户等级描述
  157.     SELECT SINGLE KTEXT INTO IT_OUT-KTEXT
  158.       FROM T151T WHERE KDGRP = IT_OUT-KDGRP.
  159. ***客户价格等级描述
  160.     SELECT SINGLE VTEXT INTO IT_OUT-VTEXT_4
  161.       FROM T188T WHERE KONDA = IT_OUT-KONDA.
  162. ***客户定价描述
  163.     SELECT SINGLE VTEXT INTO IT_OUT-VTEXT_5
  164.       FROM TVKDT WHERE KALKS = IT_OUT-KALKS.
  165. ***交货地点名称
  166.     SELECT SINGLE NAME1 INTO IT_OUT-NAME2
  167.       FROM T001W WHERE WERKS = IT_OUT-VWERK.
  168. *--------------------------------------------------------------------*
  169. *电话 传真
  170. *--------------------------------------------------------------------*
  171.     CLEAR: 1_TEL_NUMBER,
  172.            1_TEL_EXTENS,
  173.            1_FAX_NUMBER,
  174.            1_FAX_EXTENS.
  175.     SELECT SINGLE TEL_NUMBER
  176.                   TEL_EXTENS
  177.                   FAX_NUMBER
  178.                   FAX_EXTENS
  179.       INTO (1_TEL_NUMBER,1_TEL_EXTENS,1_FAX_NUMBER,1_FAX_EXTENS)
  180.       FROM ADCP WHERE PERSNUMBER = IT_OUT-PRSNR.
  181.     IF 1_TEL_EXTENS <> SPACE.
  182.       CONCATENATE 1_TEL_NUMBER '-' 1_TEL_EXTENS INTO IT_OUT-TELEPHONE.
  183.       ELSE.
  184.         IT_OUT-TELEPHONE = 1_TEL_NUMBER.
  185.     ENDIF.
  186.     IF 1_FAX_EXTENS <> SPACE.
  187.       CONCATENATE 1_FAX_NUMBER '-' 1_FAX_EXTENS INTO IT_OUT-FAX.
  188.       ELSE.
  189.         IT_OUT-FAX = 1_FAX_NUMBER.
  190.     ENDIF.
  191.     MODIFY IT_OUT.
  192.     CLEAR IT_OUT.
  193.     ENDLOOP.

  194.     LOOP AT IT_OUT .
  195.         CASE IT_OUT-KDGRP.
  196.           WHEN '01'.
  197.             IT_OUT-ICON_FOLDER = icon_led_green.
  198.           WHEN '02'.
  199.             IT_OUT-ICON_FOLDER = icon_led_YELLOW.
  200.           WHEN '03'.
  201.             IT_OUT-ICON_FOLDER = icon_led_RED.
  202.         ENDCASE.
  203.         MODIFY IT_OUT .
  204.     ENDLOOP.
  205. END-OF-SELECTION.
  206. *--------------------------------------------------------------------*
  207. *初始化ALV对象,输出内表数据
  208. *--------------------------------------------------------------------*
  209. DEFINE  INITIAL_FIELD.
  210.    WA_FIELDCAT-SELTEXT_L = &1.
  211.    WA_FIELDCAT-SELTEXT_M = &1.
  212.    WA_FIELDCAT-SELTEXT_S = &1.
  213.    WA_FIELDCAT-FIELDNAME = &2.
  214.    WA_FIELDCAT-EMPHASIZE = &3.
  215.    WA_FIELDCAT-ICON = &4.
  216.    APPEND WA_FIELDCAT TO IT_FIELDCAT.
  217. END-OF-DEFINITION.
  218.   INITIAL_FIELD '销售组织' 'VKORG' '' ''.
  219.   INITIAL_FIELD '销售组织描述' 'VTEXT' '' ''.
  220.   INITIAL_FIELD '分销渠道' 'VTWEG' '' ''.
  221.   INITIAL_FIELD '分销渠道描述' 'VTEXT_1' '' ''.
  222.   INITIAL_FIELD '产品组' 'SPART' '' ''.
  223.   INITIAL_FIELD '产品组描述' 'VTEXT_2' '' ''.
  224.   INITIAL_FIELD '销售办事处' 'VKBUR' '' ''.
  225.   INITIAL_FIELD '销售办事处描述' 'BEZEI' '' ''.
  226.   INITIAL_FIELD '销售组' 'VKGRP' '' ''.
  227.   INITIAL_FIELD '销售组描述' 'BEZEI_1' '' ''.
  228.   INITIAL_FIELD '客户分类' 'KUKIA' '' ''.
  229.   INITIAL_FIELD '客户编号' 'KUNNR' 'X' ''.
  230.   INITIAL_FIELD '客户名称' 'NAME1' '' ''.
  231.   INITIAL_FIELD '详细地址' 'STREET' '' ''.
  232.   INITIAL_FIELD '税号' 'STCEG' '' ''.
  233.   INITIAL_FIELD '银行代码' 'BANKL' '' ''.
  234.   INITIAL_FIELD '银行账户' 'BANKN' '' ''.
  235.   INITIAL_FIELD '银行户主' 'KOINH' '' ''.
  236.   INITIAL_FIELD '联系人' 'NAME_LAST' '' ''.
  237.   INITIAL_FIELD '职位' 'ABTNR' '' ''.
  238.   INITIAL_FIELD '职位描述' 'VTEXT' '' ''.
  239.   INITIAL_FIELD '联系电话' 'TELEPHONE' '' ''.
  240.   INITIAL_FIELD '传真' 'FAX' '' ''.
  241.   INITIAL_FIELD '客户等级' 'KDGRP' '' ''.
  242.   INITIAL_FIELD '客户等级描述' 'VTEXT' '' ''.
  243.   INITIAL_FIELD '客户价格等级' 'KONDA' '' ''.
  244.   INITIAL_FIELD '客户价格等级描述' 'VTEXT_4' '' ''.
  245.   INITIAL_FIELD '客户定价' 'KALKS' '' ''.
  246.   INITIAL_FIELD '客户定价描述' 'VTEXT_5' '' ''.
  247.   INITIAL_FIELD '交货地点' 'VWERK' '' ''.
  248.   INITIAL_FIELD '交货地点描述' 'NAME2' '' ''.
  249.   INITIAL_FIELD '销售冻结' 'CASSD' '' ''.
  250.   INITIAL_FIELD '客户等级状态' 'ICON_FOLDER' '' 'X'.
  251. *--------------------------------------------------------------------*
  252. *输出报表结果
  253. *--------------------------------------------------------------------*
  254. IT_LAYOUT-COLWIDTH_OPTIMIZE = 'X'.
  255. CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  256. EXPORTING
  257. *   I_INTERFACE_CHECK                 = ' '
  258. *   I_BYPASSING_BUFFER                = ' '
  259. *   I_BUFFER_ACTIVE                   = ' '
  260.    I_CALLBACK_PROGRAM                = SY-REPID
  261. *   I_CALLBACK_PF_STATUS_SET          = ' '
  262.     I_CALLBACK_USER_COMMAND           = 'USER_COMMAND'
  263. *   I_CALLBACK_TOP_OF_PAGE            = ' '
  264. *   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
  265. *   I_CALLBACK_HTML_END_OF_LIST       = ' '
  266. *   I_STRUCTURE_NAME                  =
  267. *   I_BACKGROUND_ID                   = ' '
  268. *   I_GRID_TITLE                      =
  269. *   I_GRID_SETTINGS                   =
  270.    IS_LAYOUT                         = it_layout
  271.    IT_FIELDCAT                       = it_fieldcat
  272. *   IT_EXCLUDING                      =
  273. *   IT_SPECIAL_GROUPS                 =
  274. *   IT_SORT                           =
  275. *   IT_FILTER                         =
  276. *   IS_SEL_HIDE                       =
  277.    I_DEFAULT                         = 'X'
  278. *   I_SAVE                            = ' '
  279. *   IS_VARIANT                        =
  280. *   IT_EVENTS                         =
  281. *   IT_EVENT_EXIT                     =
  282. *   IS_PRINT                          =
  283. *   IS_REPREP_ID                      =
  284. *   I_SCREEN_START_COLUMN             = 0
  285. *   I_SCREEN_START_LINE               = 0
  286. *   I_SCREEN_END_COLUMN               = 0
  287. *   I_SCREEN_END_LINE                 = 0
  288. *   I_HTML_HEIGHT_TOP                 = 0
  289. *   I_HTML_HEIGHT_END                 = 0
  290. *   IT_ALV_GRAPHICS                   =
  291. *   IT_HYPERLINK                      =
  292. *   IT_ADD_FIELDCAT                   =
  293. *   IT_EXCEPT_QINFO                   =
  294. *   IR_SALV_FULLSCREEN_ADAPTER        =
  295. * IMPORTING
  296. *   E_EXIT_CAUSED_BY_CALLER           =
  297. *   ES_EXIT_CAUSED_BY_USER            =
  298.   TABLES
  299.     T_OUTTAB                          = it_out
  300. EXCEPTIONS
  301.    PROGRAM_ERROR                     = 1
  302.    OTHERS                            = 2.
  303. IF SY-SUBRC <> 0.
  304. * Implement suitable error handling here
  305. ENDIF.

  306. FORM user_command  USING r_ucomm LIKE sy-ucomm
  307.                                    rs_selfield TYPE slis_selfield.
  308. IF r_ucomm EQ '&IC1'.
  309.   READ TABLE it_out INDEX rs_selfield-TABINDEX.
  310.   IF SY-SUBRC EQ 0.
  311.     SET PARAMETER ID 'UID' FIELD IT_OUT-KUNNR.
  312.     SET PARAMETER ID 'KID' FIELD IT_OUT-VKORG.
  313.     SET PARAMETER ID 'TID' FIELD IT_OUT-VTWEG.
  314.     SET PARAMETER ID 'PID' FIELD IT_OUT-SPART.

  315.     CALL TRANSACTION 'XD03' AND SKIP FIRST SCREEN.
  316.   ENDIF.
  317. ENDIF.

  318. ENDFORM.
复制代码
回复

使用道具 举报

快速回帖

本版积分规则
您需要登录后才可以回帖 登录 | 注册有礼

快速回复 返回顶部 返回列表