zoukankan      html  css  js  c++  java
  • SmartForms——实例

    目录:

    一、设计要求:

     

    1、ALV选择列印盘点卡内容

    2、列印内容按盘点号码分页、每8笔盘点项次分页

    3、每张盘点卡打印8行数据,不足8行数据要打印空行

    二、程序代码:

    1、内文设计

    2、代码:

    ************************************************************************
    * Program Name      :
    * Descriptions      :  盘点清册列印
    * T-Code            :
    * Updates Tables    :
    * Input  Parameters :
    * Output Parameters :
    * Return Codes      :
    * Special Logic     :
    * Includes          :
    ************************************************************************
    * Modification Log
    ************************************************************************
    *   Date   Ver. Programmer   Descriptions
    * -------- ---- ------------ -------------------------------------------
    * 2020 2.22   XXX Create
    *
    ************************************************************************
    REPORT ZMMRTEST.
    ***********************************************************************
    * Tables Definitions
    ************************************************************************
    TABLES: ikpf,iseg.
    *TABLES:.
    ************************************************************************
    * Data Definitions
    ************************************************************************
    DATA: BEGIN OF gt_data OCCURS 0,
      checkbox(1) TYPE c,
      gjahr LIKE ikpf-gjahr,
      zldat LIKE ikpf-zldat,
      iblnr LIKE ikpf-iblnr,
      zeili LIKE iseg-zeili,
      werks LIKE ikpf-werks,
      lgort LIKE ikpf-lgort,
      lgpbe LIKE mard-lgpbe,
      mtart LIKE mara-mtart,
      matnr LIKE iseg-matnr,
      maktx LIKE makt-maktx,
      erfmg LIKE iseg-erfmg,
      erfme LIKE iseg-erfme,
    END OF gt_data.
    
    DATA: BEGIN OF gt_header OCCURS 0,
      iblnr LIKE ikpf-iblnr,
      gjahr LIKE ikpf-gjahr,
      werks LIKE ikpf-werks,
      lgort LIKE ikpf-lgort,
      zldat LIKE ikpf-zldat,
    END OF gt_header.
    
    DATA: BEGIN OF gt_item OCCURS 0,
      iblnr LIKE iseg-iblnr,
      gjahr LIKE iseg-gjahr,
      zeili LIKE iseg-zeili,
      lgpbe LIKE mard-lgpbe,
      mtart LIKE mara-mtart,
      matnr LIKE iseg-matnr,
      maktx LIKE makt-maktx,
      erfmg LIKE iseg-erfmg,
      erfme LIKE iseg-erfme,
    END OF gt_item.
    
    DATA: g_butxt LIKE t001-butxt,
              g_totalpage TYPE i.
    
    TYPE-POOLS: slis.
    DATA: gs_layout TYPE slis_layout_alv,
              gt_fieldcat TYPE slis_t_fieldcat_alv,
              wa_fieldcat TYPE slis_fieldcat_alv.
    
    "For Subtotal sorting
    CONSTANTS alv_pf_status TYPE slis_formname VALUE 'ALV_PF_STATUS'.
    *ALV自定義按鈕
    CONSTANTS alv_user_command TYPE slis_formname  VALUE 'ALV_USER_COMMAND'.
    ************************************************************************
    * Includes Module
    ************************************************************************
    
    ************************************************************************
    * Selection Screen
    ************************************************************************
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-b01.
      PARAMETERS: p_werks LIKE ikpf-werks DEFAULT '2000'.
      SELECT-OPTIONS: s_lgort FOR ikpf-lgort.
      SELECT-OPTIONS: s_iblnr FOR ikpf-iblnr.
      SELECT-OPTIONS: s_matnr FOR iseg-matnr.
    SELECTION-SCREEN END OF BLOCK b1.
    
    ************************************************************************
    * Initialization
    ************************************************************************
    INITIALIZATION.
    
    ************************************************************************
    * At Selection Screen
    ************************************************************************
    AT SELECTION-SCREEN.
    
    ************************************************************************
    * At Selection Screen Output
    ************************************************************************
    AT SELECTION-SCREEN OUTPUT.
    
    ************************************************************************
    * Report Format
    ************************************************************************
    TOP-OF-PAGE.
    
    END-OF-PAGE.
    ************************************************************************
    * Main Process
    ************************************************************************
    START-OF-SELECTION.
      PERFORM get_data.
      PERFORM display_data.
    END-OF-SELECTION.
    
    *&---------------------------------------------------------------------*
    *&      Form  GET_DATA
    *&---------------------------------------------------------------------*
    FORM get_data.
      DATA: BEGIN OF lt_makt OCCURS 0,
          matnr LIKE makt-matnr,
          maktx LIKE makt-maktx,
        END OF lt_makt,
    
        BEGIN OF lt_mard OCCURS 0,
          matnr LIKE mard-matnr,
          lgort LIKE mard-lgort,
          lgpbe LIKE mard-lgpbe,
        END OF lt_mard.
    
      DATA: l_idx LIKE sy-tabix.
    
      "工厂
      SELECT SINGLE butxt INTO g_butxt
                 FROM  t001
                 WHERE bukrs = p_werks.
    
      "盘点文件
      SELECT ikpf~gjahr ikpf~zldat ikpf~iblnr
                 iseg~zeili ikpf~werks ikpf~lgort iseg~matnr
                 iseg~erfmg iseg~erfme mara~mtart
                 INTO CORRESPONDING FIELDS OF TABLE gt_data
                 FROM ikpf
                 INNER JOIN iseg ON ikpf~gjahr = iseg~gjahr
                 AND ikpf~iblnr = iseg~iblnr
                 INNER JOIN mara ON iseg~matnr = mara~matnr
                 WHERE ikpf~werks = p_werks
                 AND ikpf~lgort IN s_lgort
                 AND ikpf~iblnr IN s_iblnr
                 AND iseg~matnr IN s_matnr.
    
      "物料说明
      SELECT matnr maktx INTO TABLE lt_makt
                FROM makt
                WHERE matnr IN s_matnr.
    
      "仓库储位
      SELECT matnr lgort lgpbe INTO TABLE lt_mard
                FROM mard
                WHERE werks = p_werks
                AND lgort IN s_lgort
                AND matnr IN s_matnr.
    
      SORT: gt_data BY gjahr iblnr zeili,
        lt_makt BY matnr,
        lt_mard BY matnr lgort.
    
      LOOP AT gt_data.
        l_idx = sy-tabix.
    
        "物料说明
        READ TABLE lt_makt WITH KEY
            matnr = gt_data-matnr BINARY SEARCH.
        IF sy-subrc = 0.
          gt_data-maktx = lt_makt-maktx.
        ENDIF.
    
        "储位
        READ TABLE lt_mard WITH KEY
          matnr = gt_data-matnr
          lgort = gt_data-lgort BINARY SEARCH.
        IF sy-subrc = 0.
          gt_data-lgpbe = lt_mard-lgpbe.
        ENDIF.
    
        MODIFY gt_data INDEX l_idx.
      ENDLOOP.
    ENDFORM.                "GET_DATA
    
    *&---------------------------------------------------------------------*
    *&      Form  DISPLAY_DATA
    *&---------------------------------------------------------------------*
    FORM display_data.
      DATA: l_repid TYPE sy-repid,
            l_inclname TYPE trdir-name,
            l_idx LIKE sy-tabix.
    
      CLEAR: gt_fieldcat[],wa_fieldcat.
    
      l_repid = l_inclname = sy-cprog.
    
      "栏位最适宽度
      gs_layout-colwidth_optimize = 'X'.
      "复选框
      gs_layout-box_fieldname     = 'CHECKBOX'.
    
      CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
        EXPORTING
          I_PROGRAM_NAME         = l_repid
          I_INTERNAL_TABNAME     = 'GT_DATA'
          I_INCLNAME             = l_inclname
        CHANGING
          CT_FIELDCAT            = gt_fieldcat
        EXCEPTIONS
          INCONSISTENT_INTERFACE = 1
          PROGRAM_ERROR          = 2
          OTHERS                 = 3.
    
      LOOP AT gt_fieldcat INTO wa_fieldcat.
        l_idx = sy-tabix.
    
    
        CASE wa_fieldcat-fieldname.
          WHEN 'CHECKBOX'.
            "技术字段,设置’X’后,该字段不会显示,也不能输出,如同MANDT字段一样的效果
            wa_fieldcat-tech = 'X'.
          WHEN 'LGORT'.
            wa_fieldcat-seltext_s = wa_fieldcat-seltext_m =
            wa_fieldcat-seltext_l = '仓库'.
            wa_fieldcat-ddictxt = 'S'.
          WHEN 'ERFMG'.
            wa_fieldcat-seltext_s = wa_fieldcat-seltext_m =
            wa_fieldcat-seltext_l = '盘点数量'.
            wa_fieldcat-ddictxt = 'S'.
          WHEN 'ERFME'.
            wa_fieldcat-seltext_s = wa_fieldcat-seltext_m =
            wa_fieldcat-seltext_l = '单位'.
            wa_fieldcat-ddictxt = 'S'.
        ENDCASE.
    
        MODIFY gt_fieldcat FROM wa_fieldcat INDEX l_idx.
      ENDLOOP.
    
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          I_CALLBACK_PROGRAM       = sy-repid
          IS_LAYOUT                = gs_layout
          IT_FIELDCAT              = gt_fieldcat[]
          I_CALLBACK_PF_STATUS_SET = 'ALV_PF_STATUS'
          I_CALLBACK_USER_COMMAND  = 'ALV_USER_COMMAND'
          I_SAVE                   = 'A'
        TABLES
          T_OUTTAB            =  gt_data
        EXCEPTIONS
          PROGRAM_ERROR            = 1
          OTHERS                   = 2.
    ENDFORM.                    "DISPLAY_DATA
    
    *&---------------------------------------------------------------------*
    *&      Form  ALV_PF_STATUS
    *&---------------------------------------------------------------------*
    FORM alv_pf_status USING rt_extab TYPE slis_t_extab.
      SET  PF-STATUS  'STATUS_PRINT' .
    ENDFORM.                    " ALV_PF_STATUS
    
    *&---------------------------------------------------------------------*
    *&      Form  ALV_USER_COMMAND
    *&---------------------------------------------------------------------*
    FORM alv_user_command USING  in_ucomm LIKE  sy-ucomm
                             in_selfield TYPE slis_selfield.
    
      DATA: l_iblnr LIKE ikpf-iblnr,
                l_count TYPE i.
    
      CASE in_ucomm.
        WHEN '&PRINT'.
    
          CLEAR: g_totalpage,l_count.
          CLEAR: gt_header[],gt_item[].
    
          SORT gt_data BY iblnr zeili.
    
          LOOP AT gt_data WHERE checkbox = 'X'.
            "列印内容
            MOVE-CORRESPONDING gt_data TO gt_header.
            APPEND gt_header. CLEAR gt_header.
            MOVE-CORRESPONDING gt_data TO gt_item.
            APPEND gt_item. CLEAR gt_item.
    
            "总页数
            IF gt_data-iblnr <> l_iblnr.  "当盘点号不一样则页码+1
              g_totalpage = g_totalpage + 1.
              l_count = 1.
            ELSE.
              l_count = l_count + 1.
              IF l_count > 8. "盘点项次每次>8则页码+1
                g_totalpage = g_totalpage + 1.
                l_count = 1.
              ENDIF.
            ENDIF.
            l_iblnr = gt_data-iblnr.
          ENDLOOP.
    
          "根据年度和盘点文件去重
          DELETE ADJACENT DUPLICATES FROM gt_header
                    COMPARING iblnr gjahr.
    *      cl_demo_output=>write( g_butxt ).
    *      cl_demo_output=>write( gt_item[] ).
    *      cl_demo_output=>display(  ).
    
          "执行打印
          IF gt_item[] IS NOT INITIAL.
            PERFORM print_data.
          ELSE.
            MESSAGE  TEXT-001 TYPE 'E'.
          ENDIF.
      ENDCASE.
    
    ENDFORM.                    " ALV_USER_COMMAND
    
    *&---------------------------------------------------------------------*
    *&      Form  PRINT_DATA
    *&---------------------------------------------------------------------*
    FORM print_data.
      DATA: l_fnam TYPE rs38l_fnam,
               ls_ssfctrlop TYPE ssfctrlop,
               ls_ssfcrescl TYPE ssfcrescl,
               ls_sscompop TYPE ssfcompop.
    
      "DATA: l_totalpage TYPE String.
    
      "填充用户手工输入打印弹框参数
      ls_sscompop-tddest = 'FPW1'.
      ls_ssfctrlop-preview = 'X'.
      ls_ssfctrlop-no_dialog = 'X'.
      "ls_sscompop-tdimmed  = 'X'.
    
      "页码格式转换
      "l_totalpage = g_totalpage.
    
      CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
        EXPORTING
          FORMNAME             = 'ZMMSTEST'
        IMPORTING
          FM_NAME                = l_fnam
        EXCEPTIONS
          NO_FORM                  = 1
          NO_FUNCTION_MODULE       = 2
          OTHERS                   = 3
                .
      CALL FUNCTION l_fnam
        EXPORTING
          CONTROL_PARAMETERS = ls_ssfctrlop
          OUTPUT_OPTIONS = ls_sscompop
          USER_SETTINGS     = ''
          G_BUTXT = g_butxt
          G_TOTALPAGE = g_totalpage
        IMPORTING
          JOB_OUTPUT_INFO = ls_ssfcrescl
        TABLES
          GT_HEADER = gt_header
          GT_ITEM = gt_item
        EXCEPTIONS
          FORMATTING_ERROR      = 1
          INTERNAL_ERROR            = 2
          SEND_ERROR                  = 3
          USER_CANCELED             = 4
          OTHERS                           = 5
                .
    ENDFORM.                    " PRINT_DATA
    View Code

    3、自定义按钮

    三、SmartForms

    3.1、样式:

      表头资料:标准段落选"段落格式"的S1(这里我想要SmartForms所有的字体内容靠左),其余参数默认

      

      段落格式:

    段落格式 说明 对其 缩排-左边界 行间距 字型集 字型大小 字型样式
    S1 标准样式靠左 靠左对齐 0.1CM 1LN CHNEI 10pt  
    S2 居中 置中 0CM 1LN CHNEI 12pt 粗体
    S3 靠右 靠右对齐 0CM 1LN CHNEI 10pt  

      

        

      补充:S1的缩排-左边界有0.1CM是为了保证字体内容不要与表格线重合

      字元格式:无

    3.2、SmartForms:

      3.2.1、通用设定:

      3.2.1.1、表单属性:

      

      

      

      

      

      

      3.2.1.3、通用定义:

      

      

      3.2.2、页面和视窗:

      3.2.2.1、视窗设计

      

      3.2.2.2、SmartForms结构

      

      

      3.2.3、SmartForms逻辑流程和代码

    3.3、模板下载:(系统登陆时语言选ZF再导入)

      链接:https://pan.baidu.com/s/10XDjhjL-lVUrNApv706e1A
      提取码:qwcu

      

     

     

     

    木叶飞舞之处,火亦生生不息
  • 相关阅读:
    爬虫练习:使用xpath 下载站长之家简历封面模板
    爬虫练习:Xpath基本使用
    爬虫练习:使用xpath爬取彼岸图网美女图
    爬虫练习:使用re模块爬取 糗图百科 图片
    爬虫练习:使用bs4爬取诗词名句网的《三国演义》
    爬虫练习:BS4基本使用
    爬虫练习:使用requests模块 爬取化妆品生产许可信息管理系统服务平台
    爬虫练习:贴吧 https://tieba.baidu.com/f?kw=友谊已走到尽头
    爬虫练习:使用 bs4以及正则,urllib.request 爬取 豆瓣TOP250爬虫
    记录kettle错误:无法从套接字读取更多数据 / TNS包错误
  • 原文地址:https://www.cnblogs.com/StephenAmell/p/12344409.html
Copyright © 2011-2022 走看看