zoukankan      html  css  js  c++  java
  • LIST动态表格画线(动态列)

    image058
    TABLES: mara,
            makt,
            mard.

    DATA: BEGIN OF gx_mara,
          matnr LIKE mara-matnr,
          meins LIKE mara-meins,
    END OF gx_mara,
    gt_mara LIKE TABLE OF gx_mara.

    DATA: BEGIN OF gx_makt,
          matnr LIKE makt-matnr,
          maktx LIKE makt-maktx,
    END OF gx_makt,
    gt_makt LIKE TABLE OF gx_makt.

    DATA: BEGIN OF gx_mard,"Storage Location Data for M
          "
    由于werks字段用在了循环中的AT...ENDAT语句中了,所以需要声明在最前面
          werks LIKE mard-werks,"Plant
    工厂
          lgort LIKE mard-lgort,"Storage Location
    库位
          matnr LIKE mard-matnr,
          labst LIKE mard-labst,"
    库存
    END OF gx_mard,
    gt_mard LIKE TABLE OF gx_mard WITH KEY werks lgort,

    gx_uniq LIKE gx_mard,
    gt_uniq LIKE TABLE OF gx_uniq.

    TYPES: BEGIN OF gx_plant,
          werks LIKE mard-werks,
          cols TYPE i,
    END OF gx_plant.
    DATA: gt_plant TYPE HASHED TABLE OF gx_plant WITH HEADER LINE WITH UNIQUE KEY werks.

    *error message table
    DATA: BEGIN OF check_msg OCCURS 0,
          no   TYPE i,
          line(100),
    END OF check_msg.

    DATA: c_err_no TYPE i,
          c_l_error.
    DATA: g_line TYPE i,g_line2 TYPE i.

    CONSTANTS: p_char_x VALUE 'X'.

    SELECTION-SCREEN BEGIN OF BLOCK rad1 WITH FRAME TITLE text-001.
    SELECT-OPTIONS: s_matnr FOR mard-matnr,
                    s_werks FOR mard-werks,
                    s_lgort FOR mard-lgort,
                    s_labst FOR mard-labst.
    SELECTION-SCREEN END OF BLOCK rad1.

    DEFINE ins_msg.
      add 1 to c_err_no.
      check_msg-no = c_err_no.
      append check_msg.
      clear check_msg.
      c_l_error = 'X'.
    END-OF-DEFINITION.

    DEFINE write_screen.
      call function 'SAPGUI_PROGRESS_INDICATOR'
        exporting
          text   = &1
        exceptions
          others = 1.
    END-OF-DEFINITION.

    INITIALIZATION.

    START-OF-SELECTION.
      PERFORM frm_get_data.
      CHECK c_l_error IS INITIAL.

      PERFORM frm_process_data.
      CHECK c_l_error IS INITIAL.

      PERFORM frm_disp_data.

    FORM frm_get_data .
      DATA: g_lines TYPE i.

    *mara
    *  SELECT matnr werks lgort labst INTO CORRESPONDING FIELDS OF TABLE gt_mard
    *         FROM mard WHERE
    *         matnr IN s_matnr AND
    *         werks IN s_werks AND
    *         lgort IN s_lgort AND
    *         labst IN s_labst.
    *  IF sy-subrc NE 0.
    *    check_msg-line = 'no data'.
    *    ins_msg.
    *  ENDIF.
    *  CHECK c_l_error IS INITIAL.
    *
    模拟数据
      gx_mard-matnr = 'M001'.
      gx_mard-werks = 'W001'.
      gx_mard-lgort = 'L001'.
      gx_mard-labst = 1.

      APPEND gx_mard TO gt_mard.
      gx_mard-matnr = 'M001'.
      gx_mard-werks = 'W002'.
      gx_mard-lgort = 'L001'.
      gx_mard-labst = 2.
      APPEND gx_mard TO gt_mard.

      gx_mard-matnr = 'M001'.
      gx_mard-werks = 'W002'.
      gx_mard-lgort = 'L002'.
      gx_mard-labst = 3.
      APPEND gx_mard TO gt_mard.

      gx_mard-matnr = 'M002'.
      gx_mard-werks = 'W003'.
      gx_mard-lgort = 'L001'.
      gx_mard-labst = 4.
      APPEND gx_mard TO gt_mard.

      SORT gt_mard BY matnr werks lgort.
      gt_uniq = gt_mard.
      SORT gt_uniq BY werks lgort.
      DELETE ADJACENT DUPLICATES FROM gt_uniq COMPARING werks lgort.
      "
    计算每个工厂下面有多少个库位
      DATA: count TYPE i .
      LOOP AT gt_uniq INTO gx_uniq.
        AT NEW  werks.
          count = 0.
        ENDAT.
        count = count + 1.
        AT END OF werks.
          gt_plant-werks = gx_uniq-werks.
          gt_plant-cols = count.
          INSERT gt_plant INTO TABLE gt_plant.
        ENDAT.
      ENDLOOP.

      g_line = 52.
      DESCRIBE TABLE gt_uniq LINES g_lines.

      g_line2 = g_lines * 14."
    每列占14个位置
      g_line = g_line + g_line2.


    *mara
    *  SELECT matnr meins INTO CORRESPONDING FIELDS OF TABLE gt_mara FROM mara
    *         FOR ALL ENTRIES IN gt_mard WHERE
    *         matnr EQ gt_mard-matnr.
    *
    模拟数据
      gx_mara-matnr = 'M001'.
      gx_mara-meins = 'EA'.
      APPEND gx_mara TO gt_mara.
      gx_mara-matnr = 'M002'.
      gx_mara-meins = 'ST'.
      APPEND gx_mara TO gt_mara.

      SORT gt_mara BY matnr.

    *makt
      SELECT matnr maktx INTO CORRESPONDING FIELDS OF TABLE gt_makt FROM makt
             FOR ALL ENTRIES IN gt_mard WHERE
             matnr EQ gt_mard-matnr.
      SORT gt_makt BY matnr.

    *  DELETE ADJACENT DUPLICATES FROM gt_makt COMPARING matnr maktx.

      DELETE ADJACENT DUPLICATES FROM gt_makt COMPARING matnr.
    ENDFORM. " frm_Get_data

    FORM frm_process_data .

    ENDFORM. " frm_process_data
    FORM frm_disp_data .
    *header
      DATA: g_name(13),len TYPE i VALUE 0,l_len TYPE i VALUE 0.
      ULINE AT /02(g_line).
      "
    标题第一行
      WRITE:/02(01) '|' NO-GAP, (18) '' NO-GAP,
               (01) '|' NO-GAP, (25) '' NO-GAP,
               (01) '|' NO-GAP, (05) '' NO-GAP.                 "
    共占52

      WRITE: (01) '|' NO-GAP.
      LOOP AT gt_plant.
        len = 13 * gt_plant-cols.
        WRITE: AT (len) gt_plant-werks CENTERED NO-GAP.
        l_len = gt_plant-cols - 1.
        WRITE: AT (l_len) '' NO-GAP.
        WRITE: (01) '|' NO-GAP.
      ENDLOOP.

      "
    标题第二行
      WRITE:/02(01) '|' NO-GAP, (18) 'MAterial Number' NO-GAP,
               (01) '|' NO-GAP, (25) 'Material Desc.'  NO-GAP,
               (01) '|' NO-GAP, (05) 'Unit'            NO-GAP.
      ULINE AT 53(g_line2) NO-GAP.
      WRITE:(01) '|'.

      "
    标题第三行
      WRITE:/02(01) '|' NO-GAP, (18) '' NO-GAP,
               (01) '|' NO-GAP, (25) '' NO-GAP,
               (01) '|' NO-GAP, (05) '' NO-GAP.
      LOOP AT gt_uniq INTO gx_uniq.
        WRITE: (01) '|' NO-GAP, (13) gx_uniq-lgort CENTERED NO-GAP.
      ENDLOOP.
      WRITE: (01) '|' NO-GAP.
      ULINE AT /02(g_line).

    *
    主表内容
      LOOP AT gt_mara INTO gx_mara.
        CLEAR: gx_makt.
        READ TABLE gt_makt INTO gx_makt WITH KEY matnr = gx_mara-matnr.
        WRITE:/02(01) '|' NO-GAP, (18) gx_mara-matnr NO-GAP,
                 (01) '|' NO-GAP, (25) gx_makt-maktx NO-GAP,
                 (01) '|' NO-GAP, (05) gx_mara-meins NO-GAP.
        "
    针对每个动态列进行动态取值

        LOOP AT gt_uniq INTO gx_uniq.
          CLEAR: gx_mard.
          READ TABLE gt_mard INTO gx_mard WITH KEY
               matnr = gx_mara-matnr
               werks = gx_uniq-werks
               lgort = gx_uniq-lgort.
          IF sy-subrc = 0.
            WRITE: (01) '|' NO-GAP, (13) gx_mard-labst NO-GAP.
          ELSE.
            WRITE: (01) '|' NO-GAP, (13) '-' NO-GAP.
          ENDIF.
        ENDLOOP.
        WRITE: (01) '|' NO-GAP.
        ULINE AT /02(g_line).
      ENDLOOP.
    ENDFORM
    .

  • 相关阅读:
    deepin之创建快捷idea启动方式
    python-docx读取doc,docx文档
    Jenkins节点配置-K8S云节点
    K8S创建用户RBAC授权
    在K8S中部署禅道zentao
    yum常用操作
    Git常用命令及方法大全
    rocket mq 1
    基于SpringBoot+LayUI+Freemarker+Mybatis的通用后台管理系统
    Struts+Servlet+JDBC网上手机销售系统
  • 原文地址:https://www.cnblogs.com/jiangzhengjun/p/4291398.html
Copyright © 2011-2022 走看看