二维码

[ooalv] 在alv的Field catalogue中使用OOPS方式设置格式

Twilight发表于 2014-08-19 17:47Twilight 最后回复于 2014-08-19 17:47 [复制链接] 4330 0

设置这些格式需要
*Include for ALV styles
INCLUDE <cl_alv_control>.

程序代码:
  1. *Include for ALV styles
  2. INCLUDE <cl_alv_control>.
  3. *Type ppols for alv
  4. TYPE-POOLS : slis.
  5. *structure for t582a tbale
  6. TYPES : BEGIN OF ty_table,
  7.         infty TYPE infty,
  8.         pnnnn TYPE pnnnn_d,
  9.         zrmkz TYPE dzrmkz,
  10.         zeitb TYPE dzeitb,
  11.         dname TYPE dianm,
  12.         edynr TYPE edynp,
  13.         ldynr TYPE ldynp,
  14.         stypt TYPE stypt,
  15.         sytxt TYPE sytxt,
  16.         davo TYPE davo,
  17.         davoe TYPE davoe,
  18.         END OF ty_table.
  19. *Structure for infotype text
  20. TYPES : BEGIN OF ty_itext,
  21.         infty TYPE infty,
  22.         itext TYPE intxt,
  23.         sprsl TYPE sprsl,
  24.         END OF ty_itext.
  25. *Structure for output display
  26. TYPES : BEGIN OF ty_output,
  27.         infty TYPE infty,
  28.         itext TYPE intxt,
  29.         pnnnn TYPE pnnnn_d,
  30.         zrmkz TYPE dzrmkz,
  31.         zeitb TYPE dzeitb,
  32.         dname TYPE dianm,
  33.         edynr TYPE edynp,
  34.         ldynr TYPE ldynp,
  35.         stypt TYPE stypt,
  36.         sytxt TYPE sytxt,
  37.         davo TYPE davo,
  38.         davoe TYPE davoe,
  39.         text(6) TYPE c,
  40.         sradio(6) TYPE c,
  41.         scheck(6) TYPE c,
  42.       END OF ty_output.
  43. *internal table and work area declarations
  44. DATA : it_table TYPE STANDARD TABLE OF ty_table INITIAL SIZE 0,
  45.        it_output TYPE STANDARD TABLE OF ty_output INITIAL SIZE 0,
  46.        it_ittext TYPE STANDARD TABLE OF ty_itext INITIAL SIZE 0,
  47.        wa_table TYPE ty_table,
  48.        wa_output TYPE ty_output,
  49.        wa_ittext TYPE ty_itext.
  50. *Data declarations for ALV
  51. DATA: c_ccont TYPE REF TO cl_gui_custom_container,   "Custom container
  52.       c_alvgd         TYPE REF TO cl_gui_alv_grid,   "ALV grid object
  53.       it_fcat            TYPE lvc_t_fcat,            "Field catalogue
  54.       it_layout          TYPE lvc_s_layo.           "Layout

  55. *Field symbols declarations for style
  56. FIELD-SYMBOLS : <wa_fcat> TYPE lvc_s_fcat.
  57. *initialization event
  58. INITIALIZATION.
  59. *start of selection event
  60. START-OF-SELECTION.
  61. *select the infotypes maintained
  62.   SELECT infty
  63.           pnnnn
  64.           zrmkz
  65.           zeitb
  66.           dname
  67.           edynr
  68.           ldynr
  69.           stypt
  70.           sytxt
  71.           davo
  72.           davoe
  73.           FROM t582a UP TO 25 ROWS
  74.           INTO CORRESPONDING FIELDS OF TABLE it_table.
  75. * *Select the infotype texts
  76.   IF it_table[] IS NOT INITIAL.
  77.     SELECT itext
  78.              infty
  79.              sprsl
  80.              FROM t582s
  81.              INTO CORRESPONDING FIELDS OF TABLE it_ittext
  82.              FOR ALL ENTRIES IN it_table
  83.              WHERE infty = it_table-infty
  84.              AND sprsl = 'E'.
  85.   ENDIF.
  86. *Apppending the data to the internal table of ALV output
  87.   LOOP AT it_table INTO wa_table.
  88.     wa_output-infty = wa_table-infty.
  89.     wa_output-pnnnn = wa_table-pnnnn.
  90.     wa_output-zrmkz = wa_table-zrmkz.
  91.     wa_output-zeitb = wa_table-zeitb.
  92.     wa_output-dname = wa_table-dname.
  93.     wa_output-edynr = wa_table-edynr.
  94.     wa_output-ldynr = wa_table-ldynr.
  95.     wa_output-stypt = wa_table-stypt.
  96.     wa_output-sytxt = wa_table-sytxt.
  97.     wa_output-davo = wa_table-davo.
  98.     wa_output-davoe = wa_table-davoe.
  99. * For texts
  100.     READ TABLE it_ittext INTO wa_ittext WITH KEY infty = wa_table-infty.
  101.     wa_output-itext = wa_ittext-itext.
  102.     wa_output-text = wa_ittext-sprsl.
  103.     APPEND wa_output TO it_output.
  104.     CLEAR wa_output.
  105.   ENDLOOP.
  106. * Calling the ALV screen with custom container
  107.   CALL SCREEN 0600.
  108. *On this statement double click  it takes you to the screen painter SE51.
  109. *Enter the attributes
  110. *Create a Custom container and name it CC_CONT and OK code as OK_CODE.
  111. *Save check and Activate the screen painter.
  112. *Now a normal screen with number 600 is created which holds the ALV grid.
  113. * PBO of the actual screen ,
  114. * Here we can give a title and customized menus
  115. *&---------------------------------------------------------------------*
  116. *&      Module  STATUS_0600  OUTPUT
  117. *&---------------------------------------------------------------------*
  118. *       text
  119. *----------------------------------------------------------------------*
  120. MODULE status_0600 OUTPUT.
  121. *  SET PF-STATUS 'xxxxxxxx'.
  122. *  SET TITLEBAR 'xxx'.
  123. ENDMODULE.                 " STATUS_0600  OUTPUT
  124. * calling the PBO module ALV_GRID.
  125. *&---------------------------------------------------------------------*
  126. *&      Module  ALV_GRID  OUTPUT
  127. *&---------------------------------------------------------------------*
  128. *       text
  129. *----------------------------------------------------------------------*
  130. MODULE alv_grid OUTPUT.
  131.   CREATE OBJECT c_ccont
  132.        EXPORTING
  133.           container_name = 'CC_CONT'.
  134.   CREATE OBJECT c_alvgd
  135.        EXPORTING
  136.           i_parent = c_ccont.

  137. *  SET field for ALV
  138.   PERFORM alv_build_fieldcat.
  139. * Setting the styles for the ALV grid control
  140. * using field-symbols
  141.   LOOP AT it_fcat ASSIGNING <wa_fcat>.
  142. *For Each and every line of the fieldcat
  143.     CASE sy-tabix.
  144. *Color Styles
  145. *Background/Font/Group/positive/negative
  146.       WHEN '1'.
  147.         <wa_fcat>-style = alv_style_color_inv_positive.
  148.       WHEN '2'.
  149.         <wa_fcat>-style = alv_style_color_int_negative.
  150.       WHEN '3'.
  151.         <wa_fcat>-style = alv_style_color_inv_negative.
  152.       WHEN '4'.
  153.         <wa_fcat>-style = alv_style_color_int_positive.
  154.       WHEN '5'.
  155.         <wa_fcat>-style = alv_style_color_background.
  156.         <wa_fcat>-style = alv_style_color_inv_background.
  157.       WHEN '6'.
  158.         <wa_fcat>-style = alv_style_color_group.
  159.         <wa_fcat>-style = alv_style_color_int_background.
  160. *Style for F4
  161.       WHEN '7'.
  162.         <wa_fcat>-style = alv_style_f4.
  163. *Style for Alignment(others are also possible)
  164.       WHEN '8'.
  165.         <wa_fcat>-style = alv_style_align_left_bottom.
  166. *Style for Font Underlined/Bold and Italic are possible
  167.       WHEN '9'.
  168.         <wa_fcat>-style = alv_style_font_underlined.
  169. *Style for button type
  170.       WHEN '10'.
  171.         <wa_fcat>-style = alv_style_button.
  172. *Style for Font Symbol
  173.       WHEN '11'.
  174.         <wa_fcat>-style = alv_style_font_symbol.
  175. *Style for Radiobutton
  176.       WHEN '12'.
  177.         <wa_fcat>-style = alv_style_radio_checked.
  178. *Style for  checkbox
  179.       WHEN '13'.
  180.         <wa_fcat>-style = alv_style_checkbox_checked.
  181. *Style for column style characteristics(highlighting the col)
  182.       WHEN '14'.
  183.         <wa_fcat>-style = alv_col_style_characteristic.
  184. *Styles for Enabling the column
  185.       WHEN '15'.
  186.         <wa_fcat>-style = alv_style_enabled.
  187.     ENDCASE.
  188.   ENDLOOP.
  189. * Set ALV attributes FOR LAYOUT
  190.   PERFORM alv_report_layout.
  191.   CHECK NOT c_alvgd IS INITIAL.
  192. * Call ALV GRID
  193.   CALL METHOD c_alvgd->set_table_for_first_display
  194.     EXPORTING
  195.       is_layout                     = it_layout
  196.     CHANGING
  197.       it_outtab                     = it_output
  198.       it_fieldcatalog               = it_fcat
  199.     EXCEPTIONS
  200.       invalid_parameter_combination = 1
  201.       program_error                 = 2
  202.       too_many_lines                = 3
  203.       OTHERS                        = 4.
  204.   IF sy-subrc <> 0.
  205.     MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  206.                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  207.   ENDIF.
  208. ENDMODULE.                 " ALV_GRID  OUTPUT
  209. *&---------------------------------------------------------------------*
  210. *&      Form  alv_build_fieldcat
  211. *&---------------------------------------------------------------------*
  212. *       text
  213. *----------------------------------------------------------------------*
  214. *      <--P_IT_FCAT  text
  215. *----------------------------------------------------------------------*
  216. *subroutine to build fieldcat
  217. FORM alv_build_fieldcat.
  218.   DATA lv_fldcat TYPE lvc_s_fcat.
  219.   CLEAR lv_fldcat.
  220.   lv_fldcat-row_pos   = '1'.
  221.   lv_fldcat-col_pos   = '1'.
  222.   lv_fldcat-fieldname = 'INFTY'.
  223.   lv_fldcat-tabname   = 'IT_OUTPUT'.
  224.   lv_fldcat-outputlen = 8.
  225.   lv_fldcat-scrtext_m = 'Infotype'.
  226.   lv_fldcat-icon = 'X'.
  227.   APPEND lv_fldcat TO it_fcat.
  228.   CLEAR lv_fldcat.
  229.   lv_fldcat-row_pos   = '1'.
  230.   lv_fldcat-col_pos   = '2'.
  231.   lv_fldcat-fieldname = 'PNNNN'.
  232.   lv_fldcat-tabname   = 'IT_OUTPUT'.
  233.   lv_fldcat-outputlen = 15.
  234.   lv_fldcat-scrtext_m = 'Structure'.
  235.   lv_fldcat-icon = ''.
  236.   APPEND lv_fldcat TO it_fcat.
  237.   CLEAR lv_fldcat.
  238.   lv_fldcat-row_pos   = '1'.
  239.   lv_fldcat-col_pos   = '3'.
  240.   lv_fldcat-fieldname = 'ITEXT'.
  241.   lv_fldcat-tabname   = 'IT_OUTPUT'.
  242.   lv_fldcat-outputlen = 60.
  243.   lv_fldcat-scrtext_m = 'Description'.
  244.   lv_fldcat-icon = ''.
  245.   APPEND lv_fldcat TO it_fcat.
  246.   CLEAR lv_fldcat.

  247.   lv_fldcat-row_pos   = '1'.
  248.   lv_fldcat-col_pos   = '4'.
  249.   lv_fldcat-fieldname = 'TEXT'.
  250.   lv_fldcat-tabname   = 'IT_OUTPUT'.
  251.   lv_fldcat-outputlen = 5.
  252.   lv_fldcat-scrtext_m = 'General'.
  253.   lv_fldcat-icon = ''.
  254.   APPEND lv_fldcat TO it_fcat.
  255.   CLEAR lv_fldcat.


  256.   lv_fldcat-row_pos   = '1'.
  257.   lv_fldcat-col_pos   = '5'.
  258.   lv_fldcat-fieldname = 'ZRMKZ'.
  259.   lv_fldcat-tabname   = 'IT_OUTPUT'.
  260.   lv_fldcat-outputlen = 1.
  261.   lv_fldcat-scrtext_m = 'PERIOD'.
  262.   lv_fldcat-icon = ''.
  263.   APPEND lv_fldcat TO it_fcat.
  264.   CLEAR lv_fldcat.
  265.   lv_fldcat-row_pos   = '1'.
  266.   lv_fldcat-col_pos   = '6'.
  267.   lv_fldcat-fieldname = 'ZEITB'.
  268.   lv_fldcat-tabname   = 'IT_OUTPUT'.
  269.   lv_fldcat-outputlen = 60.
  270.   lv_fldcat-scrtext_m = 'Time constraint'.
  271.   lv_fldcat-icon = ''.
  272.   APPEND lv_fldcat TO it_fcat.
  273.   CLEAR lv_fldcat.
  274.   lv_fldcat-row_pos   = '1'.
  275.   lv_fldcat-col_pos   = '7'.
  276.   lv_fldcat-fieldname = 'DNAME'.
  277.   lv_fldcat-tabname   = 'IT_OUTPUT'.
  278.   lv_fldcat-outputlen = 15.
  279.   lv_fldcat-scrtext_m = 'Dialogmodule'.
  280.   lv_fldcat-icon = ''.
  281.   APPEND lv_fldcat TO it_fcat.
  282.   CLEAR lv_fldcat.
  283.   lv_fldcat-row_pos   = '1'.
  284.   lv_fldcat-col_pos   = '8'.
  285.   lv_fldcat-fieldname = 'EDYNR'.
  286.   lv_fldcat-tabname   = 'IT_OUTPUT'.
  287.   lv_fldcat-outputlen = 10.
  288.   lv_fldcat-scrtext_m = 'Single screenno'.
  289.   lv_fldcat-icon = ''.
  290.   APPEND lv_fldcat TO it_fcat.
  291.   CLEAR lv_fldcat.
  292.   lv_fldcat-row_pos   = '1'.
  293.   lv_fldcat-col_pos   = '9'.
  294.   lv_fldcat-fieldname = 'LDYNR'.
  295.   lv_fldcat-tabname   = 'IT_OUTPUT'.
  296.   lv_fldcat-outputlen = 10.
  297.   lv_fldcat-scrtext_m = 'List screenno'.
  298.   lv_fldcat-icon = ''.
  299.   APPEND lv_fldcat TO it_fcat.
  300.   CLEAR lv_fldcat.

  301.   lv_fldcat-row_pos   = '1'.
  302.   lv_fldcat-col_pos   = '10'.
  303.   lv_fldcat-fieldname = 'STYPT'.
  304.   lv_fldcat-tabname   = 'IT_OUTPUT'.
  305.   lv_fldcat-outputlen = 10.
  306.   lv_fldcat-scrtext_m = 'SubtypeTable'.
  307.   lv_fldcat-icon = ''.
  308.   APPEND lv_fldcat TO it_fcat.
  309.   CLEAR lv_fldcat.
  310.   lv_fldcat-row_pos   = '1'.
  311.   lv_fldcat-col_pos   = '11'.
  312.   lv_fldcat-fieldname = 'SYTXT'.
  313.   lv_fldcat-tabname   = 'IT_OUTPUT'.
  314.   lv_fldcat-outputlen = 10.
  315.   lv_fldcat-scrtext_m = 'Font Symbol'.
  316.   lv_fldcat-icon = ''.
  317.   APPEND lv_fldcat TO it_fcat.
  318.   CLEAR lv_fldcat.

  319.   lv_fldcat-row_pos   = '1'.
  320.   lv_fldcat-col_pos   = '12'.
  321.   lv_fldcat-fieldname = 'SRADIO'.
  322.   lv_fldcat-tabname   = 'IT_OUTPUT'.
  323.   lv_fldcat-outputlen = 10.
  324.   lv_fldcat-scrtext_m = 'RADIO'.
  325.   lv_fldcat-icon = ''.
  326.   APPEND lv_fldcat TO it_fcat.
  327.   CLEAR lv_fldcat.
  328.   lv_fldcat-row_pos   = '1'.
  329.   lv_fldcat-col_pos   = '13'.
  330.   lv_fldcat-fieldname = 'SCHECK'.
  331.   lv_fldcat-tabname   = 'IT_OUTPUT'.
  332.   lv_fldcat-outputlen = 10.
  333.   lv_fldcat-scrtext_m = 'CHECK'.
  334.   lv_fldcat-icon = ''.
  335.   APPEND lv_fldcat TO it_fcat.
  336.   CLEAR lv_fldcat.
  337.   lv_fldcat-row_pos   = '1'.
  338.   lv_fldcat-col_pos   = '14'.
  339.   lv_fldcat-fieldname = 'DAVO'.
  340.   lv_fldcat-tabname   = 'IT_OUTPUT'.
  341.   lv_fldcat-outputlen = 10.
  342.   lv_fldcat-scrtext_m = 'Start Date'.
  343.   lv_fldcat-icon = ''.
  344.   APPEND lv_fldcat TO it_fcat.
  345.   CLEAR lv_fldcat.
  346.   lv_fldcat-row_pos   = '1'.
  347.   lv_fldcat-col_pos   = '15'.
  348.   lv_fldcat-fieldname = 'DAVOE'.
  349.   lv_fldcat-tabname   = 'IT_OUTPUT'.
  350.   lv_fldcat-outputlen = 10.
  351.   lv_fldcat-scrtext_m = 'End date'.
  352.   lv_fldcat-icon = ''.
  353.   APPEND lv_fldcat TO it_fcat.
  354.   CLEAR lv_fldcat.
  355. ENDFORM.                    " alv_build_fieldcat
  356. *&---------------------------------------------------------------------*
  357. *&      Form  alv_report_layout
  358. *&---------------------------------------------------------------------*
  359. *       text
  360. *----------------------------------------------------------------------*
  361. *      <--P_IT_LAYOUT  text
  362. *----------------------------------------------------------------------*
  363. *Subroutine for setting alv layout
  364. FORM alv_report_layout.
  365.   it_layout-cwidth_opt = 'X'.
  366.   it_layout-zebra = 'X'.
  367.   it_layout-col_opt = 'X'.

  368. ENDFORM.                    " alv_report_layout
  369. * PAI module of the screen created. In case we use an interactive ALV or
  370. *for additional functionalities we can create OK codes
  371. *and based on the user command we can do the coding.
  372. *&---------------------------------------------------------------------*
  373. *&      Module  USER_COMMAND_0600  INPUT
  374. *&---------------------------------------------------------------------*
  375. *       text
  376. *----------------------------------------------------------------------*
  377. MODULE user_command_0600 INPUT.
  378. ENDMODULE.                 " USER_COMMAND_0600  INPUT
复制代码


程序执行效果:
alv styles using oops.png
回复

使用道具 举报

快速回帖

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

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