Chinaunix首页 | 论坛 | 博客
  • 博客访问: 232420
  • 博文数量: 17
  • 博客积分: 50
  • 博客等级: 民兵
  • 技术积分: 329
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-31 20:05
个人简介

linux kernal research

文章分类

全部博文(17)

文章存档

2023年(7)

2013年(10)

分类: 项目管理

2013-09-04 16:23:46

本题题目参照:SAP 内表数据查询


  1. *&---------------------------------------------------------------------*
  2. *& Report ZY20130903_ITAB
  3. *&
  4. *&---------------------------------------------------------------------*
  5. *&
  6. *&
  7. *&---------------------------------------------------------------------*

  8. REPORT ZY20130903_ITAB.
  9. "TYPE-POOLS slis. "ALV类型池
  10. TABLES: vbak,marc.
  11. TYPES: BEGIN OF ty_mara,
  12.          matnr TYPE mara-matnr, "物料编号
  13.          meins TYPE mara-meins, "单位
  14.        END OF ty_mara,
  15.        BEGIN OF ty_makt,
  16.          matnr TYPE makt-matnr, "物料编号
  17.          maktx TYPE makt-maktx, "物料描述
  18.        END OF ty_makt,
  19.        BEGIN OF ty_vbap,
  20.          matnr TYPE vbap-matnr, "物料编号
  21.          kwmeng TYPE vbap-kwmeng, "销售数量
  22.          meins TYPE vbap-meins, "单位
  23.        END OF ty_vbap,
  24.        BEGIN OF ty_mard,
  25.          werks TYPE mard-werks, "工厂
  26.          matnr TYPE mard-matnr, "物料编号
  27.          labst TYPE mard-labst, "非限制使用库存
  28.        END OF ty_mard,
  29.        BEGIN OF ty_out,
  30.          werks TYPE mard-werks, "工厂
  31.          matnr TYPE mard-matnr, "物料编号
  32.          maktx TYPE makt-maktx, "物料描述
  33.          kwmeng TYPE vbap-kwmeng, "销售数量
  34.          meins_m TYPE mara-meins, "单位
  35.          labst TYPE mard-labst, "非限制使用库存
  36.          meins_v TYPE vbap-meins, "单位
  37.        END OF ty_out.
  38. "定义相应的工作区
  39. DATA : wa_mara TYPE ty_mara,
  40.         wa_makt TYPE ty_makt,
  41.         wa_vbap TYPE ty_vbap,
  42.         wa_mard TYPE ty_mard,
  43.         wa_out TYPE ty_out,
  44. "定义相应的内表
  45.         it_mara TYPE STANDARD TABLE OF ty_mara,
  46.         it_makt TYPE STANDARD TABLE OF ty_makt,
  47.         it_vbap TYPE STANDARD TABLE OF ty_vbap,
  48.         it_mard TYPE STANDARD TABLE OF ty_mard,
  49.         it_out TYPE STANDARD TABLE OF ty_out.
  50. "定义alv相关
  51. DATA: it_field TYPE slis_t_fieldcat_alv,
  52.       wa_field TYPE slis_fieldcat_alv,
  53.       wa_layout TYPE slis_layout_alv,
  54.       it_sort TYPE slis_t_sortinfo_alv,
  55.       wa_sort TYPE slis_sortinfo_alv.
  56. *选择屏幕
  57. SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
  58. SELECT-OPTIONS: s_erdat FOR vbak-erdat,
  59.                 s_matnr FOR wa_mara-matnr,
  60.                 s_werks FOR marc-werks NO INTERVALS NO-EXTENSION OBLIGATORY.
  61. SELECTION-SCREEN END OF BLOCK b1.
  62. *INITIALIZATION.
  63. INITIALIZATION.
  64.   PERFORM init_screen. "初始化
  65. *AT SELECTION-SCREEN.
  66. AT SELECTION-SCREEN.
  67.   PERFORM check_werks. "检查工厂有效性
  68. *START-OF-SELECTION.
  69. START-OF-SELECTION.
  70.   PERFORM get_meins. "获得单位
  71.   PERFORM get_maktx. "获得物料描述
  72.   PERFORM get_kwmeng. "获得销量
  73.   PERFORM get_labst. "获得库存
  74.   PERFORM edit_data. "编辑数据


  75. PERFORM edit_fieldcat USING: 'WERKS' '工厂' '' '1' '',
  76.                              'MATNR' '物料编号' '' '2' '',
  77.                              'MAKTX' '物料描述' '' '3' '',
  78.                              'KWMENG' '销售数量' '' '4' '',
  79.                              'MEINS_M' '销售单位' '' '5' '',
  80.                              'LABST' '库存数量' '' '6' 'X',
  81.                              'MEINS_V' '基本单位' '' '7' ''.
  82. PERFORM output_alv. "alv方式展示数据
  83. **& Form INIT_SCREEN INIT_SCREEN :
  84. FORM init_screen .
  85.   s_werks-sign = 'I'.
  86.   s_werks-option = 'EQ'.
  87.   s_werks-low = '1000'.
  88.   APPEND s_werks.
  89.   s_erdat-sign = 'I'.
  90.   s_erdat-option = 'BT'.
  91.   s_erdat-low = '20110201'.
  92.   s_erdat-high = '20110228'.
  93.   APPEND s_erdat.
  94.   s_matnr-sign = 'I'.
  95.   s_matnr-option = 'EQ'.
  96.   s_matnr-low = 'P-102'.
  97.   s_matnr-high = 'p-104'.
  98.   APPEND s_matnr.
  99. ENDFORM. " INIT_SCREEN
  100. *& Form CHECK_WERKS
  101. FORM check_werks .
  102.   DATA: l_werks TYPE werks_d.
  103.   SELECT SINGLE werks
  104.     FROM t001w "工厂检查表
  105.       INTO l_werks
  106.     WHERE werks IN s_werks.
  107.   IF sy-subrc <> 0.
  108.     MESSAGE 'The plant is not exist' TYPE 'E'.
  109.   ENDIF.
  110. ENDFORM. " CHECK_WERKS
  111. *& Form GET_MEINS
  112. FORM get_meins .
  113.   SELECT matnr "物料号
  114.          meins "单位
  115.     FROM mara
  116.     INTO CORRESPONDING FIELDS OF TABLE it_mara
  117.     WHERE matnr IN s_matnr.
  118. * 排序
  119.   SORT it_mara BY matnr ASCENDING.
  120. ENDFORM. " GET_MEINS
  121. * GET_MAKTX
  122. FORM get_maktx .
  123.   CHECK it_mara IS NOT INITIAL. "检查内表是否为空
  124.   SELECT makt~matnr
  125.          spras
  126.          maktx
  127.     FROM makt
  128.       INTO CORRESPONDING FIELDS OF TABLE it_makt
  129.         FOR ALL ENTRIES IN it_mara
  130.     WHERE matnr = it_mara-matnr
  131.       AND spras = 'EN'.
  132. * 排序
  133.   SORT it_makt BY matnr ASCENDING.
  134. ENDFORM. " GET_MAKTX
  135. *& Form GET_KWMENG
  136. FORM get_kwmeng .
  137.   SELECT vbap~matnr
  138.          vbap~kwmeng "销量
  139.          vbap~meins "
  140.     INTO CORRESPONDING FIELDS OF TABLE it_vbap
  141.        FROM vbap
  142.          INNER JOIN vbak ON vbak~vbeln = vbap~vbeln
  143.     WHERE vbak~auart = 'TA' "类型
  144.       AND vbak~erdat IN s_erdat. "日期
  145. * 排序
  146.   SORT it_vbap BY matnr ASCENDING.
  147. ENDFORM. " GET_KWMENG
  148. *& Form GET_LABST
  149. FORM get_labst .
  150.   CHECK it_vbap IS NOT INITIAL. "检查内表是否为空
  151.   SELECT werks "工厂
  152.          matnr "物料编号
  153.          labst "非限制使用库存
  154.     FROM mard
  155.       INTO CORRESPONDING FIELDS OF TABLE it_mard
  156.      WHERE werks IN s_werks "工厂
  157.     AND matnr IN s_matnr.
  158. * 排序
  159.   SORT it_mard BY matnr ASCENDING.
  160. ENDFORM. " GET_LABST
  161. *& Form EDIT_DATA
  162. FORM edit_data .
  163.   CHECK it_mard IS NOT INITIAL. "检查内表是否为空
  164.   LOOP AT it_mard INTO wa_mard. "循环内表
  165.     wa_out-werks = wa_mard-werks.
  166.     wa_out-matnr = wa_mard-matnr.
  167.     wa_out-labst = wa_mard-labst.
  168.     READ TABLE it_mara INTO wa_mara WITH KEY matnr = wa_mard-matnr BINARY SEARCH.
  169.     IF sy-subrc = 0.
  170.       wa_out-meins_m = wa_mara-meins.
  171.     ENDIF.
  172.     READ TABLE it_makt INTO wa_makt WITH KEY matnr = wa_mard-matnr BINARY SEARCH.
  173.     IF sy-subrc = 0.
  174.       wa_out-maktx = wa_makt-maktx.
  175.     ENDIF.
  176.     LOOP AT it_vbap INTO wa_vbap WHERE matnr = wa_mard-matnr.
  177.       AT END OF matnr.
  178.         SUM. "求合
  179.         wa_out-kwmeng = wa_vbap-kwmeng.
  180.       ENDAT.
  181.       wa_out-meins_v = wa_vbap-meins.
  182.     ENDLOOP.
  183.     APPEND wa_out TO it_out. "添加到内表
  184.      write: / wa_out-werks,
  185.           wa_out-matnr,
  186.           wa_out-maktx,
  187.           wa_out-kwmeng,
  188.           wa_out-meins_m,
  189.           wa_out-labst,
  190.           wa_out-meins_v.

  191.   ENDLOOP.
  192. ENDFORM. " EDIT_DATA
  193. *& Form EDIT_FIELDCAT

  194. FORM edit_fieldcat USING $i_filedname
  195.                             $i_seltext
  196.                             $i_key
  197.                             $i_col
  198.                             $i_sum.
  199.   CLEAR wa_field.
  200.   wa_field-fieldname = $i_filedname.
  201.   wa_field-seltext_l = $i_seltext. "长文本
  202.   wa_field-key = $i_key.
  203.   wa_field-col_pos = $i_col. "列的位置
  204.   wa_field-do_sum = $i_sum. "求和
  205.   APPEND wa_field TO it_field.
  206. ENDFORM. " EDIT_FIELDCAT

  207. "& Form OUTPUT_ALV
  208. FORM output_alv .
  209.   DATA: w_repid TYPE sy-repid.
  210.   wa_layout-zebra = 'X'. "使ALV界面呈现颜色交替
  211.   wa_layout-colwidth_optimize = 'X'. "自动优化列宽
  212.   wa_sort-spos = 1. "排序顺序
  213.   wa_sort-fieldname = 'WERKS'. "排序字段
  214.   wa_sort-up = 'X'. "升序
  215.   wa_sort-subtot = 'X'. "小计
  216.   APPEND wa_sort TO it_sort.
  217.   CLEAR wa_sort .
  218.   wa_sort-spos = 2. "排序顺序
  219.   wa_sort-fieldname = 'MATNR'. "排序字段
  220.   wa_sort-up = 'X'. "升序
  221.   wa_sort-subtot = 'X'. "小计
  222.   APPEND wa_sort TO it_sort.
  223.   CLEAR wa_sort .
  224.   w_repid = sy-repid. "当前程序的名称
  225.   CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
  226.     EXPORTING
  227.       i_grid_title = 'ALV TITLE'
  228.       is_layout = wa_layout
  229.       it_fieldcat = it_field
  230.       it_sort = it_sort
  231.     TABLES
  232.       t_outtab = it_out
  233.     EXCEPTIONS
  234.       program_error = 1
  235.       OTHERS = 2.
  236. ENDFORM.


阅读(4825) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~