首页 > 其他分享 >ALV简单模板

ALV简单模板

时间:2023-07-13 16:26:03浏览次数:45  
标签:DATA CAT LS 简单 ALV TABLE TYPE 模板

ALV简单模板

根据结构(表)名创建LT_ALV_CAT,后续更改显示字段,直接改结构(表)就可以了。

ZPPR0102

*&---------------------------------------------------------------------*
*& Report  ZPPR0102
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZPPR0102.

INCLUDE ZPPR0102_HEAD.
INCLUDE ZPPR0102_SCREEN.
INCLUDE ZPPR0102_FORM.

START-OF-SELECTION.
  PERFORM FRM_CHECK_AUTH.
  IF LV_CHECKF EQ 'X'.
    MESSAGE LV_MSG TYPE 'S' DISPLAY LIKE 'E'.
    RETURN.
  ENDIF.

  PERFORM FRM_GET_DATA. "动态创建内表 <dyn_table>,获取lt_alv_cat
  PERFORM FRM_GET_DATA2."

END-OF-SELECTION.
  PERFORM F_DISPLAY_DATA.
View Code

ZPPR0102_HEAD

*&---------------------------------------------------------------------*
*&  INCLUDE           ZPPR0102_HEAD
*&---------------------------------------------------------------------*
TABLES:SSCRFIELDS,AFKO,AFPO.
TYPE-POOLS: SLIS,OLE2.

TYPES: BEGIN OF SY_OUTPUT.
        INCLUDE STRUCTURE ZPPT002.
TYPES: ZCOLOR(4),
       ZCOLOR2   TYPE CHAR200, "存储导出EXCEL的行数,列数,颜色。 行.列.颜色;行.列.颜色;
*       cellcolor TYPE lvc_t_scol,
       WERKS   TYPE AFPO-DWERK, "超出40位则判为'X'
*       MATNR   TYPE AFPO-MATNR, "超出80位则判为'X'
       SLBOX,
       END OF SY_OUTPUT.

DATA: GT_OUTPUT TYPE TABLE OF SY_OUTPUT,
      GS_OUTPUT TYPE SY_OUTPUT.
FIELD-SYMBOLS: <FS_OUT> TYPE SY_OUTPUT.
DATA: D_REF      TYPE REF TO DATA,
      D_REF2     TYPE REF TO DATA,
      LT_ALV_CAT TYPE TABLE OF LVC_S_FCAT,
      LS_ALV_CAT LIKE LINE OF LT_ALV_CAT.

DATA: LT_TABLE LIKE TABLE OF DNTAB.
DATA: LS_TABLE TYPE DNTAB.

DATA: DYN_TABLE TYPE REF TO DATA.
DATA: DYN_WA TYPE REF TO DATA.
FIELD-SYMBOLS :<DYN_TABLE> TYPE TABLE,
               <DYN_WA>    TYPE ANY,
               <DYN_FIELD> TYPE ANY,
               <FS_STR>    TYPE ANY.


DATA: DYN_TABLE2 TYPE REF TO DATA.
DATA: DYN_WA2 TYPE REF TO DATA.


FIELD-SYMBOLS :<DYN_TABLE2> TYPE TABLE,
               <DYN_WA2>    TYPE ANY,
               <DYN_FIELD2> TYPE ANY,
               <FS_STR2>    TYPE ANY.
DATA: GO_EXCEL    TYPE OLE2_OBJECT,
      GO_WORKBOOK TYPE OLE2_OBJECT,
      GO_SHEET    TYPE OLE2_OBJECT.
DATA: GS_LAYOUT   TYPE LVC_S_LAYO,
      GT_FIELDCAT TYPE LVC_T_FCAT.

DATA  GV_COL TYPE P DECIMALS 0.
DATA: LV_CHECKF TYPE CHAR1,
      LV_MSG TYPE BAPI_MSG.
View Code

ZPPR0102_SCREEN

*&---------------------------------------------------------------------*
*&  INCLUDE           ZPPR0102_SCREEN
*&---------------------------------------------------------------------*
SELECTION-SCREEN: BEGIN OF BLOCK B01 WITH FRAME TITLE TEXT-001.
*PARAMETERS: p_name TYPE dd03l-tabname OBLIGATORY.
SELECT-OPTIONS: S_WERKS FOR AFPO-DWERK DEFAULT '6100' OBLIGATORY,
                S_AUFNR FOR AFPO-AUFNR.
*                S_ERDAT FOR afko-ERDAT,
*                S_MATNR FOR AFPO-MATNR.
SELECTION-SCREEN: END OF BLOCK B01.
View Code

ZPPR0102_FORM

*&---------------------------------------------------------------------*
*&  INCLUDE           ZPPR0102_FORM
*&---------------------------------------------------------------------*

FORM FRM_GET_DATA .
*取出表结构的字段目录

  CALL FUNCTION 'NAMETAB_GET'
    EXPORTING
      LANGU          = SY-LANGU
      TABNAME        = 'ZPPT002'
    TABLES
      NAMETAB        = LT_TABLE
    EXCEPTIONS
      NO_TEXTS_FOUND = 1.
*根据取出的字段目录生成参考字段目录

  CLEAR LT_ALV_CAT.
  LOOP AT LT_TABLE INTO LS_TABLE.
*    IF ls_table-fieldname NE 'MANDT'.
    LS_ALV_CAT-FIELDNAME = LS_TABLE-FIELDNAME.
    LS_ALV_CAT-REF_TABLE = 'ZPPT002'.
*CONVEXIT

    LS_ALV_CAT-REF_FIELD = LS_TABLE-FIELDNAME.
    IF LS_TABLE-FIELDNAME EQ 'MEINS'.
      LS_ALV_CAT-NO_CONVEXT = 'X'.
      CLEAR: LS_ALV_CAT-REF_FIELD,LS_ALV_CAT-REF_TABLE.
    ENDIF.
    LS_ALV_CAT-SELTEXT   = LS_TABLE-FIELDTEXT.
    LS_ALV_CAT-SCRTEXT_L = LS_TABLE-FIELDTEXT.
    LS_ALV_CAT-SCRTEXT_M = LS_TABLE-FIELDTEXT.
    LS_ALV_CAT-SCRTEXT_S = LS_TABLE-FIELDTEXT.
    APPEND LS_ALV_CAT TO LT_ALV_CAT.
*    ENDIF.
    CLEAR LS_ALV_CAT.
  ENDLOOP.

*内表创建

  CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
    EXPORTING
      IT_FIELDCATALOG = LT_ALV_CAT
    IMPORTING
      EP_TABLE        = D_REF.

*指定生成的内表到字段符号
  ASSIGN D_REF->* TO <DYN_TABLE>.

*创建动态工作区结构
  CREATE DATA DYN_WA LIKE LINE OF <DYN_TABLE>.

*创建动态工作区
  ASSIGN DYN_WA->* TO <DYN_WA>.

  DELETE LT_ALV_CAT[] WHERE FIELDNAME EQ 'MANDT'.
*  DELETE lt_alv_cat[] WHERE fieldname EQ 'ZTABIX' OR fieldname EQ 'MANDT'.
*  ls_alv_cat-fieldname = 'ZCOLOR'.
**    ls_alv_cat-ref_table = 'ZMMT090'.
*  ls_alv_cat-ref_field = 'ZCOLOR'.
*  ls_alv_cat-seltext   = '状态'.
*  ls_alv_cat-scrtext_l = '状态'.
*  ls_alv_cat-scrtext_m = '状态'.
*  ls_alv_cat-scrtext_s = '状态'.
*  APPEND ls_alv_cat TO lt_alv_cat.
*  CLEAR: GT_FIELDCAT[].

  DEFINE SET_FIELDCAT.
    CLEAR: LS_ALV_CAT.
    LS_ALV_CAT-FIELDNAME = &1.
    LS_ALV_CAT-REF_FIELD = &2.
    LS_ALV_CAT-REF_TABLE = &3.
    LS_ALV_CAT-CONVEXIT  = &4.
    LS_ALV_CAT-DO_SUM    = &5.
    LS_ALV_CAT-SELTEXT   = &6.
    LS_ALV_CAT-SCRTEXT_L = &6.
    LS_ALV_CAT-SCRTEXT_M = &6.
    LS_ALV_CAT-SCRTEXT_S = &6.
    LS_ALV_CAT-COLTEXT   = &6.
    APPEND LS_ALV_CAT TO LT_ALV_CAT[].
  END-OF-DEFINITION.
*显示内容
  SET_FIELDCAT 'WERKS' 'DWERK' 'AFPO' '' ''  '工厂'.
*  SET_FIELDCAT 'MATNR' 'MATNR' 'AFPO' '' ''  '物料'.

ENDFORM.                    "frm_get_data
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA2
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM FRM_GET_DATA2 .
  DATA: LS_AFPO LIKE AFPO,
        LT_AFPO LIKE TABLE OF AFPO.
  SELECT *
    INTO TABLE GT_OUTPUT
    FROM ZPPT002
   WHERE AUFNR IN S_AUFNR.

  IF GT_OUTPUT[] IS NOT INITIAL.
    SELECT AUFNR POSNR DWERK
      INTO CORRESPONDING FIELDS OF TABLE LT_AFPO
      FROM AFPO
     WHERE AUFNR IN S_AUFNR
       AND DWERK IN S_WERKS.
  ENDIF.

  LOOP AT GT_OUTPUT ASSIGNING <FS_OUT>.
    READ TABLE LT_AFPO INTO LS_AFPO WITH KEY AUFNR = <FS_OUT>-AUFNR BINARY SEARCH.
    IF SY-SUBRC EQ 0.
      <FS_OUT>-WERKS = LS_AFPO-DWERK.
*      <fs_out>-matnr = ls_afpo-matnr.
    ENDIF.
  ENDLOOP.

  DELETE GT_OUTPUT[] WHERE WERKS NOT IN S_WERKS.

ENDFORM.                    "frm_get_data2
*&---------------------------------------------------------------------*
*& Form F_DISPLAY_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM F_DISPLAY_DATA .
  PERFORM F_SET_LAYOUT.
*  PERFORM F_SET_FIELDCAT.
  PERFORM F_ALV_DISPLAY TABLES GT_OUTPUT.
ENDFORM.                    "f_display_data

*&---------------------------------------------------------------------*
*&      Form  f_set_layout
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM F_SET_LAYOUT.
  CLEAR: GS_LAYOUT.
  GS_LAYOUT-BOX_FNAME = 'SLBOX'.
  GS_LAYOUT-ZEBRA = 'X'.
  GS_LAYOUT-CWIDTH_OPT = 'X'.
*  gs_layout-ctab_fname = 'CELLCOLOR'.
ENDFORM.                    "f_set_layout

*&---------------------------------------------------------------------*
*&      Form  f_alv_display
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->IT_TABLE   text
*----------------------------------------------------------------------*
FORM F_ALV_DISPLAY TABLES IT_TABLE.
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      I_CALLBACK_PROGRAM      = SY-REPID
*     i_callback_pf_status_set = 'F_SET_PF_STATUS'
      I_CALLBACK_USER_COMMAND = 'F_USER_COMMAND'
      IS_LAYOUT_LVC           = GS_LAYOUT
      IT_FIELDCAT_LVC         = LT_ALV_CAT
      I_SAVE                  = 'U'
    TABLES
      T_OUTTAB                = IT_TABLE
    EXCEPTIONS
      PROGRAM_ERROR           = 1
      OTHERS                  = 2.
  IF SY-SUBRC <> 0.
  ENDIF.
ENDFORM.                    "f_alv_display
*-----------------------------------------------------------------------* *
*-----------------------------------------------------------------------*
FORM F_SET_PF_STATUS USING RT_EXTAB TYPE SLIS_T_EXTAB.
*  SET PF-STATUS 'STD'.
ENDFORM.                    "f_set_pf_status

*&---------------------------------------------------------------------*
*&      Form  f_user_command
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->R_UCOMM      text
*      -->RS_SELFIELD  text
*----------------------------------------------------------------------*
FORM F_USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
 RS_SELFIELD TYPE SLIS_SELFIELD.
  PERFORM F_CHECK_CHANGE_DATA.
  CASE R_UCOMM.
    WHEN 'ZSAVE'.
*      IF r1 EQ 'X'.
*        PERFORM frm_create_belnr.
*      ENDIF.
    WHEN '&IC1'."双击事件
*      READ TABLE gt_output INTO DATA(gs_output) INDEX rs_selfield-tabindex.
*      IF sy-subrc EQ 0.
*        SET PARAMETER ID 'MAT' FIELD gs_output-matnr.
*        CALL TRANSACTION 'MM03' AND SKIP FIRST SCREEN.
*      ENDIF.
  ENDCASE.
  PERFORM F_REFRESH_ALV.
ENDFORM.                    "f_user_command
*-----------------------------------------------------------------------* *
*-----------------------------------------------------------------------*
FORM F_CHECK_CHANGE_DATA.
  DATA: LO_GRID TYPE REF TO CL_GUI_ALV_GRID.
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      E_GRID = LO_GRID.
  LO_GRID->CHECK_CHANGED_DATA( ).
ENDFORM.                    "f_check_change_data
*-----------------------------------------------------------------------* *
*-----------------------------------------------------------------------*
FORM F_REFRESH_ALV.
  DATA: LO_GRID      TYPE REF TO CL_GUI_ALV_GRID,
        LS_IS_STABLE TYPE LVC_S_STBL.
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      E_GRID = LO_GRID.
  LS_IS_STABLE-COL = 'X'.
  LS_IS_STABLE-ROW = 'X'.
  LO_GRID->REFRESH_TABLE_DISPLAY(
  EXPORTING
  IS_STABLE = LS_IS_STABLE
  EXCEPTIONS
  FINISHED = 1
  OTHERS = 2 ).
  IF SY-SUBRC <> 0.
  ENDIF.
ENDFORM.                    "f_refresh_alv
*&---------------------------------------------------------------------*
*&      Form  FRM_CHECK_AUTH
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM FRM_CHECK_AUTH .
  DATA: LT_T001W LIKE TABLE OF T001W,
        LS_T001W LIKE T001W.

  SELECT WERKS
    INTO TABLE LT_T001W
    FROM T001W
   WHERE WERKS IN S_WERKS.

  LOOP AT LT_T001W INTO LS_T001W.
    AUTHORITY-CHECK OBJECT 'M_MSEG_WWA'
      ID 'WERKS' FIELD LS_T001W-WERKS
      ID 'ACTVT' FIELD '03'.
    IF SY-SUBRC <> 0.
      LV_CHECKF = 'X'.
      CONCATENATE LV_MSG '沒有' LS_T001W-WERKS '工廠權限;' INTO LV_MSG.
      EXIT.
    ENDIF.
  ENDLOOP.
  IF S_AUFNR[] IS INITIAL.
    LV_CHECKF = 'X'.
    CONCATENATE LV_MSG '请填写要查询的工单' INTO LV_MSG.
  ENDIF.
ENDFORM.                    " FRM_CHECK_AUTH
View Code

 

标签:DATA,CAT,LS,简单,ALV,TABLE,TYPE,模板
From: https://www.cnblogs.com/chaguoguo/p/17551218.html

相关文章

  • 各类模板
    高精加luoguP1601A+BProblem(高精)高精减luoguP2142高精度减法高精乘luoguP1303A*BProblem高精除求商luoguP2005A/BProblemII,luoguP1480A/BProblem高精除求余数luoguP2818天使的起誓高精阶乘SP24FCTRL2-Smallfactorials栈luoguB3614【模板】栈队列lu......
  • 树链剖分模板
    区间,边权描述松鼠爸爸为了让松鼠宝宝更熟悉地熟悉采松果的流程,为其定制了一颗“树”,树上有n个点,n-1条边(无环),每条边上都有一定数量的松果。松鼠爸爸为了让松鼠宝宝得到更多的松果,有m次操作,每次操作给定两个点x,y和一个add,在x点到y点的简单路径上所有......
  • 现代C++(Modern C++)基本用法实践:四、模板
    概述C++的模板是泛型编程思想的一种实现。C++是强类型语言,处处强调类型。同样的加法运算,int和float的加法运算需定义两个函数(重载),而使用模板则可以只用一个函数(见下面示例)。这类似我们面向对象所说的多态(定义加法运算,各个类型有不同的实现),所以是所谓静多态的一种实现方式,不同的......
  • ITK 简单使用
    第一个ITK程序1、CMakeLists.txt1#ThisistherootITKCMakeListsfile.2cmake_minimum_required(VERSION3.10)34#ThisprojectisdesignedtobebuiltoutsidetheInsightsourcetree.5project(ITK_demo)67#FindVTK8set(ITK_DIRD:/Progr......
  • SimpleITK 简单使用
    SimpleITKITK是一个开源、跨平台的框架,提供给开发者增强功能的图像分析和处理套件(推荐使用)。Note:注意SimpleITK不支持中文,即路径中不能有中文X射线图像对应的读取1#@file:itk_p1.py2#@Time:2021/8/2816:273#@Author:wmz4importSimpleITKassitk......
  • ipython的安装和简单使用
    前言ipython是一个python的交互式shell,比默认的pythonshell好用得多,支持变量自动补全,自动缩进,支持bashshell命令,内置了许多很有用的功能和函数。学习ipython将会让我们以一种更高的效率来使用python。同时它也是利用Python进行科学计算和交互可视化的一个最佳的平台安装pip......
  • VisualVM 的 OQL 的一些例子
    VisualVM的OQL语言是对HeapDump进行查询,类似于SQL的查询语言,它的基本语法如下:select<JavaScriptexpressiontoselect>[from[instanceof]<classname><identifier>[where<JavaScriptbooleanexpressiontofilter>]]OQL由3个部分组成:select子句、from子句和w......
  • 简单的排序方法汇总
    #include<stdio.h>//定义交换数值函数voidSwap(int*a,int*b);//定义输出数组函数voidPrint_arr(inta[],intsize);//简单插入排序voidFuns_Charu(inta[],intsize);//简单冒泡排序voidFuns_Maopao(inta[],intsize);//简单选择排序voidFuns_Xuanze(inta[],......
  • C# 使用Windows服务项目模板快速创建Windows服务程序
    之前写了一篇使用Topshelf创建Windows服务程序的文章:https://www.cnblogs.com/log9527blog/p/17325795.html还可以直接使用VS自带的Windows服务项目模板快速创建Windows服务程序 Service1.cs里面的OnStart和OnStop方法分别代表服务开始,服务停止时执行的逻辑 配置服务Serv......
  • 线段树模板 洛谷P3374 【模板】树状数组 1
    题目传送门题目描述如题,已知一个数列,你需要进行下面两种操作:1.将某一个数加上x2.求出某区间每一个数的和输入格式第一行包含两个整数N、M,分别表示该数列数字的个数和操作的总个数。第二行包含N个用空格分隔的整数,其中第i个数字表示数列第i项的初始值。接下来M行每行包含3......