ABAP---交互式报表常见技术,动态内表,去重等等

1.创建动态内表的方式

 PERFORM frm_fill_fc TABLES gt_fieldcat USING 'MATNR' '物料编码' 'MARA' 'MATNR' '' '' '' ''.
  PERFORM frm_fill_fc TABLES gt_fieldcat USING 'MAKTX' '名称' 'MAKT' 'MAKTX' '' '' '' ''.
  PERFORM frm_fill_fc TABLES gt_fieldcat USING 'MATKL' '物料组' 'MARA' 'MATKL' '' '' '' ''.
  PERFORM frm_fill_fc TABLES gt_fieldcat USING 'WGBEZ' '物料组描述' 'T023T' 'WGBEZ' '' '' '' ''.
  PERFORM frm_fill_fc TABLES gt_fieldcat USING 'BDMNG' '工单需求总数' 'MSEG' 'MENGE' '' '' '' 'X'.
  PERFORM frm_fill_fc TABLES gt_fieldcat USING 'LGPRO' '库存地点' 'MARC' 'LGPRO' '' '' '' ''.
  PERFORM frm_fill_fc TABLES gt_fieldcat USING 'LABST' '实时库存' 'MSEG' 'MENGE' '' '' '' 'X'.
  PERFORM frm_fill_fc TABLES gt_fieldcat USING 'MENGE_QL' '欠料总数' 'MSEG' 'MENGE' '' '' '' 'X'.

  DATA: lv_fieldname TYPE char30,
        lv_fieldtext TYPE char30,
        lv_days      TYPE char2,
        lv_days_str  TYPE char2,
        lv_date      TYPE dats.

  DO  gv_days TIMES.
    lv_days = sy-index.
    lv_date = gv_date_beg + lv_days - 1.

    PERFORM frm_conversion_zero_input USING lv_days CHANGING lv_days_str.
    lv_fieldname = 'BDMNG' && lv_days_str.
    lv_fieldtext = lv_date && '欠料'.
    PERFORM frm_fill_fc TABLES gt_fieldcat USING lv_fieldname lv_fieldtext 'MSEG' 'MENGE' '' '' '' 'X'.

  ENDDO.

  IF p_htt = 'X'.
    DO  gv_days TIMES.
      lv_days = sy-index.
      lv_date = gv_date_beg + lv_days - 3.

      PERFORM frm_conversion_zero_input USING lv_days CHANGING lv_days_str.
      lv_fieldname = 'SRM' && lv_days_str.
      lv_fieldtext = lv_date && '之前SRM送货计划结余数'.
      PERFORM frm_fill_fc TABLES gt_fieldcat USING lv_fieldname lv_fieldtext 'MSEG' 'MENGE' '' '' '' 'X'.
    ENDDO.

    PERFORM frm_fill_fc TABLES gt_fieldcat USING 'SRMTOT' 'SRM送货计划汇总' 'MSEG' 'MENGE' '' '' '' 'X'.

    PERFORM frm_fill_fc TABLES gt_fieldcat USING 'LABST2' '倒冲仓库存' 'MSEG' 'MENGE' '' '' '' 'X'.
  ENDIF.

  "生成内表
*  把FIELDCAT生成内表,并创建工作区
*  Create inner table base on the field catalog
  DATA: lr_table TYPE REF TO data,
        lr_stru  TYPE REF TO data.

  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
      it_fieldcatalog = gt_fieldcat
    IMPORTING
      ep_table        = lr_table.
  ASSIGN lr_table->* TO <fs_table>.

  CREATE DATA lr_stru LIKE LINE OF <fs_table>.
  ASSIGN lr_stru->* TO <fs_structure>.

相关的子例程

FORM frm_fill_fc TABLES pt_fieldcat TYPE lvc_t_fcat USING p1 p2 p3 p4 p5
      p6 p7 p8.
  DATA: lw_fieldcat TYPE lvc_s_fcat.
  CLEAR lw_fieldcat.
  lw_fieldcat-fieldname = p1.
  lw_fieldcat-seltext = p2.
  lw_fieldcat-tooltip = p2.
  lw_fieldcat-reptext = p2.
  lw_fieldcat-scrtext_s = p2."short text
  lw_fieldcat-scrtext_m = p2."middle text
  lw_fieldcat-scrtext_l = p2."long text
  lw_fieldcat-ref_table = p3."refer table
  lw_fieldcat-ref_field = p4."refer field
  lw_fieldcat-edit = p5.      "editable
  lw_fieldcat-emphasize = p6."column color
  lw_fieldcat-checkbox = p7."checkbox
  IF p8 = 'X'.
    lw_fieldcat-edit_mask = '==ZSIGN'."checkbox
  ENDIF.
  APPEND lw_fieldcat TO pt_fieldcat.
ENDFORM. "FILL_FC

2.FOR ALL ENTRIES IN用法

    SELECT a~werks a~matnr a~lgpro a~lgfsb
     INTO CORRESPONDING FIELDS OF TABLE gt_marc
     FROM marc AS a
     FOR ALL ENTRIES IN lt_resb
     WHERE a~matnr = lt_resb-matnr
     AND a~werks = lt_resb-werks.

3.去重的用法

 SORT gt_mard1 BY matnr lgort.
 DELETE ADJACENT DUPLICATES FROM gt_mard1 COMPARING matnr lgort.

4.循环的便捷用法

  "按组件+基本开始日期,汇总组件需求用量
  LOOP AT gt_wo ASSIGNING FIELD-SYMBOL(<fs_wo>).

    LOOP AT gt_resb ASSIGNING FIELD-SYMBOL(<fs_resb>) WHERE rsnum = <fs_wo>-rsnum.

      lv_bdmng = <fs_resb>-bdmng - <fs_resb>-enmng.

      IF lv_bdmng IS INITIAL.
        CONTINUE.
      ENDIF.

      IF <fs_resb>-shkzg = 'S'.
        lv_bdmng = - lv_bdmng.
      ENDIF.

      CLEAR: lw_resb_col.
      lw_resb_col-werks = <fs_resb>-werks.
      lw_resb_col-matnr = <fs_resb>-matnr.
      lw_resb_col-gstrp = <fs_wo>-gstrp.
      lw_resb_col-matkl = <fs_resb>-matkl.
      lw_resb_col-bdmng = lv_bdmng.
      COLLECT lw_resb_col INTO gt_resb_col.

    ENDLOOP.
  ENDLOOP.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值