码迷,mamicode.com
首页 > 其他好文 > 详细

SAP OOALV- 合计

时间:2021-03-30 13:34:48      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:mamicode   lazy   get   app   table   into   -name   adr   ted   

技术图片

 

 

TYPES: BEGIN OF ty_mara,
         srno  LIKE adrc-name1, " Storing the total text
         matnr LIKE mara-matnr,  " Material
         ersda LIKE mara-ersda,  " Creation date
         ernam LIKE mara-ernam,  " Created by
         laeda LIKE mara-laeda,  " Last change date
         aenam LIKE mara-aenam,  " Last change by
         vpsta LIKE mara-vpsta,  " Maintenance status
         brgew LIKE mara-brgew,  " Gross weight
         ntgew LIKE mara-ntgew,  " Net weight
         gewei LIKE mara-gewei,  " Weight Unit
       END OF ty_mara.

TYPES: BEGIN OF ty_mara_tmp,
         matnr TYPE matnr, " Material
         ersda TYPE ersda, " Creation date
         ernam TYPE ernam, " Created by
         laeda TYPE laeda, " Last change date
         aenam TYPE aenam, " Last change by
         vpsta TYPE vpsta, " Maintenance status
         brgew TYPE brgew, " Gross weight
         ntgew TYPE ntgew, " Net weight
         gewei TYPE gewei, " Weight Unit
       END OF ty_mara_tmp.

DATA: gt_mara_tmp TYPE STANDARD TABLE OF ty_mara_tmp INITIAL SIZE 0,
      gt_sort2    TYPE STANDARD TABLE OF lvc_s_sort INITIAL SIZE 0,
      gt_mara     TYPE STANDARD TABLE OF ty_mara INITIAL SIZE 0,
      go_grid     TYPE REF TO cl_gui_alv_grid,
      gt_fieldcat TYPE lvc_t_fcat,
      gs_mara_tmp TYPE ty_mara_tmp,
      gs_layout   TYPE lvc_s_layo,
      gs_mara     TYPE ty_mara,
      gs_field    TYPE lvc_s_fcat,
      gs_sort2    TYPE lvc_s_sort.
*Set alv field
DEFINE set_alv_fieldcat.
  gs_field-fieldname = &1.
  gs_field-coltext   = &2.
  gs_field-rollname  = &3.
  gs_field-lzero     = space.
  gs_field-no_zero   = X.
  APPEND gs_field TO gt_fieldcat.
  CLEAR gs_field.
END-OF-DEFINITION.

START-OF-SELECTION.
  PERFORM frm_get_data.
  PERFORM frm_set_field.

END-OF-SELECTION.
  CALL SCREEN 100.

FORM frm_get_data.
* Fetch data
  SELECT  matnr   " Material
          ersda   " Creation date
          ernam   " Created by
          laeda   " Last change date
          aenam   " Last change by
          vpsta   " Maintenance status
          brgew   " Gross weight
          ntgew   " Net weight
          gewei   " Weight Unit
    FROM mara
    INTO TABLE gt_mara_tmp
  UP TO 10 ROWS
    WHERE  brgew NE 0.
  CHECK sy-subrc = 0.

  LOOP AT gt_mara_tmp INTO gs_mara_tmp.
    gs_mara-srno  = 总计:.
    gs_mara-matnr = gs_mara_tmp-matnr.
    gs_mara-ersda = gs_mara_tmp-ersda.
    gs_mara-ernam = gs_mara_tmp-ernam .
    gs_mara-laeda = gs_mara_tmp-laeda.
    gs_mara-aenam = gs_mara_tmp-aenam.
    gs_mara-vpsta = gs_mara_tmp-vpsta.
    gs_mara-brgew = gs_mara_tmp-brgew.
    gs_mara-ntgew = gs_mara_tmp-ntgew.
    gs_mara-gewei = gs_mara_tmp-gewei.
    APPEND gs_mara TO gt_mara.
  ENDLOOP.
ENDFORM.

FORM frm_set_field.

  gs_sort2-spos = 1.           "Sort Order
  gs_sort2-fieldname = SRNO.
*  gs_sort2-up = ‘X‘.
  gs_sort2-down = X.
  gs_sort2-subtot = X."Output subtotal
  APPEND gs_sort2 TO gt_sort2.

  gs_layout-no_totline = X.
  gs_field-tech = X.
  gs_field-no_out = X.
  set_alv_fieldcat SRNO ‘‘ MAKTX .
  set_alv_fieldcat MATNR ‘‘ MATNR .
  set_alv_fieldcat ERSDA ‘‘ ERSDA .
  set_alv_fieldcat ERNAM ‘‘ ERNAM .
  set_alv_fieldcat LAEDA ‘‘ LAEDA .
  set_alv_fieldcat AENAM ‘‘ AENAM .
  set_alv_fieldcat VPSTA ‘‘ VPSTA .

  gs_field-do_sum = X.
  gs_field-ref_table = MARA.
  gs_field-ref_field = BRGEW.
  set_alv_fieldcat BRGEW ‘‘ BRGEW .

  gs_field-do_sum = X.
  gs_field-ref_table = MARA.
  gs_field-ref_field = NTGEW.
  set_alv_fieldcat NTGEW ‘‘ NTGEW .
  set_alv_fieldcat GEWEI ‘‘ GEWEI .
ENDFORM.

* Calling the screen to display ALV

*&----------------------------------------------------------------*
*&      Module  STATUS_0100  OUTPUT
*&----------------------------------------------------------------*
*       Display ALV report
*-----------------------------------------------------------------*
MODULE status_0100 OUTPUT.
  SET PF-STATUS STATUS_100.
  IF go_grid IS INITIAL.
    CREATE OBJECT go_grid
      EXPORTING
        i_parent          = cl_gui_custom_container=>screen0
      EXCEPTIONS
        error_cntl_create = 1
        error_cntl_init   = 2
        error_cntl_link   = 3
        error_dp_create   = 4
        OTHERS            = 5.
    CHECK sy-subrc = 0.

*    CALL FUNCTION ‘LVC_FIELDCATALOG_MERGE‘
*      EXPORTING
*        i_internal_tabname     = ‘GT_MARA‘
**       i_structure_name       = ‘GT_MARA‘
*      CHANGING
*        ct_fieldcat            = gt_fieldcat
*      EXCEPTIONS
*        inconsistent_interface = 1
*        program_error          = 2
*        OTHERS                 = 3.
*    IF sy-subrc = 0.
*
*    ENDIF.


    CALL METHOD go_grid->set_table_for_first_display
      EXPORTING
        is_layout                     = gs_layout
      CHANGING
        it_outtab                     = gt_mara[]
        it_fieldcatalog               = gt_fieldcat
        it_sort                       = gt_sort2
      EXCEPTIONS
        invalid_parameter_combination = 1
        program_error                 = 2
        too_many_lines                = 3
        OTHERS                        = 4.
    IF sy-subrc <> 0.
    ENDIF.

    CALL METHOD cl_gui_alv_grid=>set_focus
      EXPORTING
        control           = go_grid
      EXCEPTIONS
        cntl_error        = 1
        cntl_system_error = 2
        OTHERS            = 3.
    IF sy-subrc <> 0.
    ENDIF.
  ENDIF.
ENDMODULE.                 " STATUS_0100  OUTPUT
MODULE exit INPUT.
  LEAVE TO SCREEN 0.
ENDMODULE.

 

SAP OOALV- 合计

标签:mamicode   lazy   get   app   table   into   -name   adr   ted   

原文地址:https://www.cnblogs.com/JackeyLove/p/14591565.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!