Chinaunix首页 | 论坛 | 博客
  • 博客访问: 481899
  • 博文数量: 199
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1902
  • 用 户 组: 普通用户
  • 注册时间: 2020-05-14 13:25
个人简介

代码5S

文章分类

全部博文(199)

文章存档

2021年(5)

2020年(194)

我的朋友

分类: 其他平台

2020-11-03 14:15:50


点击(此处)折叠或打开

  1. REPORT zdemo02.

  2. DATA: dy_table TYPE REF TO data,
  3.       dy_wa TYPE REF TO data,
  4.       gt_com TYPE lvc_t_fcat,
  5.       gs_com TYPE lvc_s_fcat,
  6.       gv_col TYPE i,
  7.       gv_fieldname TYPE lvc_fname.

  8. FIELD-SYMBOLS: <dyn_table> TYPE table,
  9.                <dyn_wa> TYPE any,
  10.                <fv> TYPE any.

  11. DEFINE m_add_field.
  12.   gv_col = gv_col + 1.
  13.   gs_com-col_pos = gv_col.
  14.   gs_com-fieldname = &1.
  15.   gs_com-inttype = &2.
  16.   gs_com-intlen = &3.
  17.   gs_com-dd_roll = &4.
  18.   gs_com-decimals = &5.
  19.   APPEND gs_com TO gt_com.
  20.   CLEAR gs_com.
  21. END-OF-DEFINITION.

  22. ***添加结构字段
  23. DATA:BEGIN OF gs_itab,
  24.        lifnr LIKE lfa1-lifnr,
  25.      END OF gs_itab.

  26. DATA:gt_components LIKE TABLE OF rstrucinfo,
  27.      gs_components LIKE LINE OF gt_components.

  28. CALL FUNCTION 'GET_COMPONENT_LIST'
  29.   EXPORTING
  30.     program = sy-repid
  31.     fieldname = 'GS_ITAB'
  32.   TABLES
  33.     components = gt_components.

  34. LOOP AT gt_components INTO gs_components.
  35.   m_add_field gs_components-compname gs_components-type
  36.               gs_components-olen '' gs_components-decs.
  37. ENDLOOP.


  38. ***动态内表字段赋值
  39. m_add_field 'MATNR' '' '' 'MATNR' ''.
  40. m_add_field 'MAKTX' '' '' 'MAKTX' ''.
  41. m_add_field 'NAME1' 'CHAR' '30' '' ''.
  42. DO 12 TIMES.
  43.   gv_fieldname = |MONTH{ sy-index }|.
  44.   m_add_field gv_fieldname '' '' 'DATUM' ''.
  45. ENDDO.


  46. ***创建动态内表
  47. CALL METHOD cl_alv_table_create=>create_dynamic_table
  48.   EXPORTING
  49.     it_fieldcatalog = gt_com
  50.   IMPORTING
  51.     ep_table = dy_table.
  52. ASSIGN dy_table->* TO <dyn_table>.
  53. CREATE DATA dy_wa LIKE LINE OF <dyn_table>.
  54. ASSIGN dy_wa->* TO <dyn_wa>.


  55. ***动态字段赋值
  56. DEFINE m_add_value.
  57.   ASSIGN COMPONENT &1 OF STRUCTURE <dyn_wa> TO <fv>.
  58.   <fv> = &2.
  59.   UNASSIGN <fv>.
  60. END-OF-DEFINITION.

  61. m_add_value 'MATNR' '物料编码'.
  62. m_add_value 'MAKTX' '物料名称'.
  63. m_add_value 'NAME1' 'NAME1'.

  64. DATA:gv_datum TYPE sy-datum.
  65. DO 12 TIMES.
  66.   gv_fieldname = |MONTH{ sy-index }|.
  67.   gv_datum = sy-datum + sy-index.
  68.   m_add_value gv_fieldname gv_datum.
  69. ENDDO.
  70. APPEND <dyn_wa> TO <dyn_table>.
  71. CLEAR <dyn_wa>.

  72. WRITE 'Hello world'.

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