恩达

可爱的儿子--阳阳坨

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  43 随笔 :: 14 文章 :: 55 评论 :: 0 Trackbacks

*&---------------------------------------------------------------------*
*& Report  ZMD04_XX                                                    *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

INCLUDE zmd04_XX_top.
INCLUDE zmd04_XX_sel.

START-OF-SELECTION.
  IF sel03 = 'X'.
*取数据(需求日期)
    PERFORM get_data_by_date.
  ELSE.
*取数据(其他方式)
    PERFORM get_data_by_others.
  ENDIF.
*通过MRP运算得到符合条件的数据(类似TCODE:MD04的处理方式)
  PERFORM get_data_from_mrp_calc.
*整理itab.1.将检验批纳入可用数量;2.按可用日期排序
  PERFORM data_process_step_one.
  IF NOT s_lgort IS INITIAL.
*扣减排除条件库存数据(按MRP范围计算,不考虑后台已排除与MRP相关的
*库存地的扣减,以便与MD04考虑方式一致!)
    PERFORM del_speme_from_stock.
  ENDIF.
*DATA_OUTPUT_TO_ALV
  PERFORM ouput_to_alv.
*&--------------------------------------------------------------------*
*&      Form  data_output
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM data_output.
  DATA:pos TYPE i VALUE 1.

  CLEAR wa_fields.
  wa_fields-fieldname = 'MATNR'.
  wa_fields-seltext_l = '物料代码'.
  wa_fields-outputlen = '14'.
  wa_fields-key       = 'X'.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'MAKTX'.
  wa_fields-seltext_l = '物料描述'.
  wa_fields-outputlen = 18.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'DELB0'.
  wa_fields-seltext_l = 'MRP元素'.
  wa_fields-outputlen = 8.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'DAT00'.
  wa_fields-seltext_l = '可用日期'.
  wa_fields-outputlen = 8.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'DAT01'.
  wa_fields-seltext_l = '收货日期'.
  wa_fields-outputlen = 8.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'EXTRA'.
  wa_fields-seltext_l = 'MRP元素数据'.
  wa_fields-outputlen = 15.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'MNG01'.
  wa_fields-seltext_l = '收货/需求数量'.
  wa_fields-outputlen = 11.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'MNG02'.
  wa_fields-seltext_l = '可用量'.
  wa_fields-outputlen = 11.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'SPEME'.
  wa_fields-seltext_l = '冻结库存量'.
  wa_fields-outputlen = 11.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'LGORT'.
  wa_fields-seltext_l = '库存'.
  wa_fields-outputlen = 4.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'AUSKT'.
  wa_fields-seltext_l = '例外'.
  wa_fields-outputlen = 3.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'DELNR'.
  wa_fields-seltext_l = 'MRP元素号'.
  wa_fields-outputlen = 10.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'DELPS'.
  wa_fields-seltext_l = 'MRP元素项'.
  wa_fields-outputlen = 9.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.


  wa_fields-fieldname = 'BERID'.
  wa_fields-seltext_l = 'MRP范围'.
  wa_fields-outputlen = 7.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program = sy-repid
      i_grid_title       = alv_title
      i_save             = 'X'
      it_fieldcat        = alv_fields
    TABLES
      t_outtab           = itab     "输出内表
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.

ENDFORM.                    "data_output
*&---------------------------------------------------------------------*
*&      Form  get_data_from_mrp_calc
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_data_from_mrp_calc .
  LOOP AT it00.
    ON CHANGE OF it00-matnr OR it00-berid.
      CALL FUNCTION 'MD_STOCK_REQUIREMENTS_LIST_API'
        EXPORTING
          matnr   = it00-matnr
          werks   = it00-werks
          berid   = it00-berid
        IMPORTING
          e_mt61d = imt61d
          e_mdkp  = imdkp
          e_cm61m = icm61m
          e_mdsta = imdsta
        TABLES
          mdpsx   = imdps
          mdezx   = imdez
          mdsux   = imdsu.
      IF sy-subrc EQ 0.
        MOVE-CORRESPONDING imt61d TO itab.
        IF itab-dispo IN s_dispo.
          LOOP AT imdez.
            MOVE-CORRESPONDING imdez TO itab.
            READ TABLE imdps INDEX sy-tabix.
            IF sy-subrc EQ 0 AND imdez-delkz = 'AR'.
              itab-delnr = imdps-delnr.
              itab-delps = imdps-delps.
            ENDIF.
            APPEND itab.
          ENDLOOP.
        ENDIF.
        CLEAR imt61d.
        CLEAR itab.
      ENDIF.
    ENDON.
  ENDLOOP.

ENDFORM.                                                    " get_data_from_mrp_calc
*&---------------------------------------------------------------------*
*&      Form  IT00lgt
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM del_speme_from_stock .
  LOOP AT itab.
    num = sy-tabix.
    ON CHANGE OF itab-matnr OR itab-berid.
      PERFORM mrp_area USING itab-matnr
                             itab-werks
                             itab-berid.

      LOOP AT ilgort WHERE  berid = itab-berid AND lgort IN s_lgort.
        SELECT SINGLE * FROM t001l WHERE werks = ilgort-werks
                                     AND lgort = ilgort-lgort
                                     AND diskz NE ''.
        IF sy-subrc NE 0.
          itab-mng02 = itab-mng02 - ilgort-labst - ilgort-insme.
        ENDIF.
      ENDLOOP.
      MODIFY itab INDEX num TRANSPORTING mng02.
      CLEAR:ilgort,ilgort[].
    ENDON.
  ENDLOOP.
ENDFORM.                          " del_speme_from_stock


*&---------------------------------------------------------------------*
*&      Form  data_process_step_one
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM data_process_step_one .
*
  DATA: BEGIN OF x_line OCCURS 0,
     lines LIKE sy-tabix,
     mngxx LIKE itab-mng01,
  END OF x_line.
*
  LOOP AT itab.
    num = sy-tabix.
    IF  itab-plumi = 'B'.
      IF NOT x_line IS INITIAL AND x_line-mngxx NE 0.
        APPEND x_line.
        CLEAR x_line.
      ENDIF.
      x_line-lines = num.
    ENDIF.
    IF itab-delkz = 'QM'.
      x_line-mngxx = x_line-mngxx + itab-mng01.
    ENDIF.
*一个物料计算结束清空中间结果
    AT END OF matnr.
      IF NOT x_line IS INITIAL AND x_line-mngxx NE 0.
        APPEND x_line.
        CLEAR:x_line.
      ENDIF.
    ENDAT.
    CLEAR:itab.
  ENDLOOP.

  LOOP AT x_line.
    READ TABLE itab INDEX x_line-lines.
    IF sy-subrc EQ 0.
      itab-mng02 = itab-mng02 + x_line-mngxx.
      itab-mng01 = itab-mng02.
      MODIFY itab INDEX x_line-lines TRANSPORTING mng01 mng02.
    ENDIF.
  ENDLOOP.
*按收货日期排序
  SORT itab BY matnr berid plaab planr dat01.
*重新计算MNG02
  DATA x_mng02 LIKE itab-mng02.
  DATA: num LIKE sy-tabix.
  LOOP AT itab.
    num = sy-tabix.
    IF itab-plumi NE 'B'.
      itab-mng02 = x_mng02 + itab-mng01.
      MODIFY itab INDEX num TRANSPORTING mng02.
    ENDIF.
    x_mng02 = itab-mng02.
  ENDLOOP.
ENDFORM.                    " data_process_step_one

*&---------------------------------------------------------------------*
*&      Form  itab_cZL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM itab_czl .
  DATA: zdatum LIKE sy-datum.
  DATA: nnn LIKE sy-tabix.

  it_itab[] = itab[].
  po_itab[] = itab[].

  PERFORM calcit_itab.
  PERFORM calcpo_itab.

  LOOP AT it00.
    READ TABLE it_itab WITH KEY matnr = it00-matnr
                                berid = it00-berid
                                delkz =  'WB'.
    IF sy-subrc EQ 0.
      it01-aufnr = it00-aufnr.
      it01-rsnum = it00-rsnum.
      it01-rspos = it00-rspos.
      it01-berid = it00-berid.
      it01-matnr = it00-matnr.
      it01-prgrp = it00-prgrp.
      it01-lbtxt = it00-lbtxt.
      it01-normt = it00-normt.
      IF it00-kzear IS INITIAL.
        it01-m_jxq = it00-enmng - it00-bdmng.
      ENDIF.
*取库存地下的冻结库存
      PERFORM get_speme_from_mard USING it00-matnr
                                        it00-werks
                                       it00-berid
                                  CHANGING x_speme.
      it01-speme = x_speme.
      it_itab-mng02 = it_itab-mng02 - x_speme.
      CLEAR:x_speme.
      it01-m_kyk = it_itab-mng02.
      it01-maktx = it_itab-maktx.
      it01-werks = it_itab-werks.
      it01-dispo = it_itab-dispo.

      it01-mng_a = it01-m_kyk + it01-m_jxq.
      READ TABLE it_itab WITH KEY delnr = it00-rsnum delps = it00-rspos.
      IF sy-subrc EQ 0.
        zdatum = it_itab-dat01.
        LOOP AT po_itab WHERE matnr = it00-matnr
                          AND berid = it00-berid
                          AND delkz NE 'WB'
                          AND dat01 <= zdatum.
          it01-mng_a1 = it01-mng_a1 + po_itab-mng01.
        ENDLOOP.
        it01-mng_a2 = it01-mng_a + it01-mng_a1.
        IF it01-mng_a2 > 0.
          it01-mng_a2 = 0.
        ENDIF.
      ENDIF.
      APPEND it01.
    ENDIF.
    CLEAR it01.
  ENDLOOP.

  LOOP AT it01.
    ON CHANGE OF it01-aufnr OR it01-matnr OR it01-berid.
      IF sy-tabix NE 1.
        APPEND it01_01.
        CLEAR it01_01.
      ENDIF.
      MOVE it01 TO it01_01.
    ENDON.
    IF it01-rspos NE it01_01-rspos.
      it01_01-rspos = ''.
      it01_01-m_jxq = it01_01-m_jxq + it01-m_jxq.
      it01_01-mng_a = it01_01-mng_a  + it01-m_jxq.
      it01_01-mng_a2 = it01_01-mng_a + it01_01-mng_a1.
      IF it01_01-mng_a2 > 0.
        it01_01-mng_a2 = 0.
      ENDIF.
    ENDIF.
    AT LAST.
      APPEND it01_01.
      CLEAR it01_01.
    ENDAT.
  ENDLOOP.
  REFRESH: it00,itab,it01,it_itab,po_itab.
ENDFORM.                    " itab_cZL
*&---------------------------------------------------------------------*
*&      Form  data_output_iT01
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM data_output_it01 .
  DATA:pos TYPE i VALUE 1.

  CLEAR wa_fields.

  wa_fields-fieldname = 'PRGRP'.
  wa_fields-seltext_l = '型号'.
  wa_fields-outputlen = 12.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'LBTXT'.
  wa_fields-seltext_l = '国家'.
  wa_fields-outputlen = 12.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'NORMT'.
  wa_fields-seltext_l = '颜色'.
  wa_fields-outputlen = 12.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'MATNR'.
  wa_fields-seltext_l = '物料代码'.
  wa_fields-outputlen = '15'.
*  wa_fields-KEY       = 'X'.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'MAKTX'.
  wa_fields-seltext_l = '物料描述'.
*  wa_fields-no_out    = 'X'.

*  wa_fields-DO_SUM    =  'X'.
  wa_fields-outputlen = 20.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.
*
*  wa_fields-fieldname = 'DELB0'.
*  wa_fields-seltext_l = 'MRP元素'.
*  wa_fields-outputlen = 6.
*  wa_fields-COL_POS  = POS.
*  APPEND wa_fields TO ALV_fields.
*  POS = POS + 1.
*  CLEAR wa_fields.

*  wa_fields-fieldname = 'DAT00'.
*  wa_fields-seltext_l = '可用日期'.
*  wa_fields-outputlen = 8.
*  wa_fields-COL_POS  = POS.
*  APPEND wa_fields TO ALV_fields.
*  POS = POS + 1.
*  CLEAR wa_fields.

*  wa_fields-fieldname = 'DAT01'.
*  wa_fields-seltext_l = '收货日期'.
*  wa_fields-outputlen = 8.
*  wa_fields-COL_POS  = POS.
*  APPEND wa_fields TO ALV_fields.
*  POS = POS + 1.
*  CLEAR wa_fields.
*
*  wa_fields-fieldname = 'EXTRA'.
*  wa_fields-seltext_l = 'MRP元素数据'.
*  wa_fields-outputlen = 40.
*  wa_fields-COL_POS  = POS.
*  APPEND wa_fields TO ALV_fields.
*  POS = POS + 1.
*  CLEAR wa_fields.

  wa_fields-fieldname = 'M_JXQ'.
  wa_fields-seltext_l = '净需求数量'.
  wa_fields-outputlen = 13.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'M_KYK'.
  wa_fields-seltext_l = '可用库存量'.
  wa_fields-outputlen = 13.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'SPEME'.
  wa_fields-seltext_l = '冻结库存量'.
  wa_fields-outputlen = 13.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'MNG_A'.
  wa_fields-seltext_l = '确认需求量'.
  wa_fields-outputlen = 13.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'MNG_A1'.
  wa_fields-seltext_l = '确认的PO量'.
  wa_fields-outputlen = 13.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'MNG_A2'.
  wa_fields-seltext_l = '短缺数量'.
  wa_fields-outputlen = 13.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.
*
*  wa_fields-fieldname = 'LGORT'.
*  wa_fields-seltext_l = '库存'.
*  wa_fields-outputlen = 4.
*  wa_fields-COL_POS  = POS.
*  APPEND wa_fields TO ALV_fields.
*  POS = POS + 1.
*  CLEAR wa_fields.
*
*  wa_fields-fieldname = 'AUSKT'.
*  wa_fields-seltext_l = '库存'.
*  wa_fields-outputlen = 2.
*  wa_fields-COL_POS  = POS.
*  APPEND wa_fields TO ALV_fields.
*  POS = POS + 1.
*  CLEAR wa_fields.

  wa_fields-fieldname = 'AUFNR'.
  wa_fields-seltext_l = '生产订单'.
  wa_fields-outputlen = 12.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'RSNUM'.
  wa_fields-seltext_l = '预留号'.
  wa_fields-outputlen = 10.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'RSPOS'.
  wa_fields-seltext_l = '项目'.
  wa_fields-outputlen = 4.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'BERID'.
  wa_fields-seltext_l = 'MRP范围'.
  wa_fields-outputlen = 10.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'DISPO'.
  wa_fields-seltext_l = 'MRP控制者'.
  wa_fields-outputlen = 10.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

 

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
* CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'

    EXPORTING
      i_callback_program = sy-repid
     i_grid_title       = alv_title
      i_save             = 'X'
      it_fieldcat        = alv_fields
       i_callback_user_command = 'MYCOMMANDC'
    TABLES
      t_outtab           = it01_01     "输出内表
    EXCEPTIONS
      program_error      = 1
      OTHERS             = 2.

ENDFORM.                    " data_output_iT01

*&---------------------------------------------------------------------*
*&      Form  itab_bzl
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM itab_bzl .
  DATA: zdatum LIKE sy-datum.
  DATA: nnn LIKE sy-tabix.
*AR 相关预订
*BE 订单项目计划行
*FE 生产订单
*LA 发运通知
*MR 预定
*SB 相关需求
*U2 库存转移请求的批准订单
*UR 转储预定的库存
*WB 工厂库存
  it_itab[] = itab[].
  po_itab[] = itab[].

  PERFORM calcit_itab.
  PERFORM calcpo_itab.

  LOOP AT it00.
    READ TABLE it_itab WITH KEY matnr = it00-matnr
                                berid = it00-berid
                                delkz =  'WB'.
    IF sy-subrc EQ 0.
      iout-aufnr = it00-aufnr.
      iout-rsnum = it00-rsnum.
      iout-rspos = it00-rspos.
      iout-berid = it00-berid.
      iout-matnr = it00-matnr.
      iout-prgrp = it00-prgrp.
      iout-lbtxt = it00-lbtxt.
      iout-normt = it00-normt.
*取库存地下的冻结库存
      PERFORM get_speme_from_mard USING it00-matnr
                                        it00-werks
                                       it00-berid
                                  CHANGING x_speme.
      iout-speme = x_speme.
      it_itab-mng02 = it_itab-mng02 - x_speme.
      CLEAR:x_speme.
      iout-m_kyk = it_itab-mng02.
      iout-maktx = it_itab-maktx.
      iout-werks = it_itab-werks.
      iout-dispo = it_itab-dispo.

      READ TABLE it_itab WITH KEY delnr = it00-rsnum
                                  delps = it00-rspos.
      IF sy-subrc EQ 0.
        iout-m_jxq = it_itab-mng01.
        zdatum = it_itab-dat01.
        out_datum = zdatum.

        PERFORM fill_dates_2_itab
                    USING
                       out_datum
                       iout-mng_a
                       iout-mng_a1
                       iout-mng_a2
                       iout-jxq_a.

        IF out_datum > sy-datum.
          out_datum = out_datum - s_days.
          IF out_datum < sy-datum.
            out_datum = sy-datum.
          ENDIF.
          PERFORM fill_dates_2_itab
                 USING
                    out_datum
                    iout-mng_b
                    iout-mng_b1
                    iout-mng_b2
                    iout-jxq_b.
        ENDIF.

        IF out_datum > sy-datum.
          out_datum = out_datum - s_days.
          IF out_datum < sy-datum.
            out_datum = sy-datum.
          ENDIF.
          PERFORM fill_dates_2_itab
                 USING
                    out_datum
                    iout-mng_c
                    iout-mng_c1
                    iout-mng_c2
                    iout-jxq_c.
        ENDIF.

        IF out_datum > sy-datum.
          out_datum = out_datum - s_days.
          IF out_datum < sy-datum.
            out_datum = sy-datum.
          ENDIF.
          PERFORM fill_dates_2_itab
                 USING
                    out_datum
                    iout-mng_d
                    iout-mng_d1
                    iout-mng_d2
                    iout-jxq_d.
        ENDIF.

        IF out_datum > sy-datum.
          out_datum = out_datum - s_days.
          IF out_datum < sy-datum.
            out_datum = sy-datum.
          ENDIF.
          PERFORM fill_dates_2_itab
                 USING
                    out_datum
                    iout-mng_e
                    iout-mng_e1
                    iout-mng_e2
                    iout-jxq_e.
        ENDIF.

        IF out_datum > sy-datum.
          out_datum = out_datum - s_days.
          IF out_datum < sy-datum.
            out_datum = sy-datum.
          ENDIF.
          PERFORM fill_dates_2_itab
                 USING
                    out_datum
                    iout-mng_f
                    iout-mng_f1
                    iout-mng_f2
                    iout-jxq_f.
        ENDIF.

        IF out_datum > sy-datum.
          out_datum = out_datum - s_days.
          IF out_datum < sy-datum.
            out_datum = sy-datum.
          ENDIF.
          PERFORM fill_dates_2_itab
                 USING
                    out_datum
                    iout-mng_g
                    iout-mng_g1
                    iout-mng_g2
                    iout-jxq_g.
        ENDIF.

        IF out_datum > sy-datum.
          out_datum = out_datum - s_days.
          IF out_datum < sy-datum.
            out_datum = sy-datum.
          ENDIF.
          PERFORM fill_dates_2_itab
                 USING
                    out_datum
                    iout-mng_h
                    iout-mng_h1
                    iout-mng_h2
                    iout-jxq_h.
        ENDIF.

        IF out_datum > sy-datum.
          out_datum = out_datum - s_days.
          IF out_datum < sy-datum.
            out_datum = sy-datum.
          ENDIF.
          PERFORM fill_dates_2_itab
                 USING
                    out_datum
                    iout-mng_i
                    iout-mng_i1
                    iout-mng_i2
                    iout-jxq_i.
        ENDIF.

        IF out_datum > sy-datum.
          out_datum = out_datum - s_days.
          IF out_datum < sy-datum.
            out_datum = sy-datum.
          ENDIF.
          PERFORM fill_dates_2_itab
                 USING
                    out_datum
                    iout-mng_j
                    iout-mng_j1
                    iout-mng_j2
                    iout-jxq_j.
        ENDIF.

        IF out_datum > sy-datum.
          out_datum = out_datum - s_days.
          IF out_datum < sy-datum.
            out_datum = sy-datum.
          ENDIF.
          PERFORM fill_dates_2_itab
                 USING
                    out_datum
                    iout-mng_k
                    iout-mng_k1
                    iout-mng_k2
                    iout-jxq_k.
        ENDIF.

        IF out_datum > sy-datum.
          out_datum = out_datum - s_days.
          IF out_datum < sy-datum.
            out_datum = sy-datum.
          ENDIF.
          PERFORM fill_dates_2_itab
                 USING
                    out_datum
                    iout-mng_l
                    iout-mng_l1
                    iout-mng_l2
                    iout-jxq_l.
        ENDIF.

        IF out_datum > sy-datum.
          out_datum = out_datum - s_days.
          IF out_datum < sy-datum.
            out_datum = sy-datum.
          ENDIF.
          PERFORM fill_dates_2_itab
                 USING
                    out_datum
                    iout-mng_m
                    iout-mng_m1
                    iout-mng_m2
                    iout-jxq_m.
        ENDIF.

        IF out_datum > sy-datum.
          out_datum = out_datum - s_days.
          IF out_datum < sy-datum.
            out_datum = sy-datum.
          ENDIF.
          PERFORM fill_dates_2_itab
                 USING
                    out_datum
                    iout-mng_n
                    iout-mng_n1
                    iout-mng_n2
                    iout-jxq_n.
        ENDIF.
        out_datum = zdatum.
        APPEND iout.
      ENDIF.
    ENDIF.
    CLEAR iout.
  ENDLOOP.

  SORT iout BY aufnr matnr berid rspos DESCENDING.

  LOOP AT iout.
    ON CHANGE OF iout-aufnr OR iout-matnr OR iout-berid.
      IF sy-tabix NE 1.
        APPEND iout_01.
        CLEAR iout_01.
      ENDIF.
      MOVE iout TO iout_01.
    ENDON.

    IF iout-rspos NE iout_01-rspos.
      iout_01-rspos = ''.
      iout_01-m_jxq = iout_01-m_jxq + iout-m_jxq.
    ENDIF.

    AT LAST.
      APPEND iout_01.
      CLEAR iout_01.
    ENDAT.
  ENDLOOP.
  REFRESH: it00,itab,iout,it_itab,po_itab.
ENDFORM.                    " itab_bzl
*&---------------------------------------------------------------------*
*&      Form  data_output_IOUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM data_output_iout .
  DATA:pos TYPE i VALUE 1,
      itab_outdatum(18),
      itab_datum LIKE sy-datum.
  CLEAR wa_fields.
  wa_fields-fieldname = 'PRGRP'.
  wa_fields-seltext_l = '型号'.
  wa_fields-outputlen = 12.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'LBTXT'.
  wa_fields-seltext_l = '国家'.
  wa_fields-outputlen = 12.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'NORMT'.
  wa_fields-seltext_l = '颜色'.
  wa_fields-outputlen = 12.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'AUFNR'.
  wa_fields-seltext_l = '生产订单'.
  wa_fields-outputlen = 12.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'MATNR'.
  wa_fields-seltext_l = '物料代码'.
  wa_fields-outputlen = '15'.
*  wa_fields-KEY       = 'X'.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'MAKTX'.
  wa_fields-seltext_l = '物料描述'.
*  wa_fields-no_out    = 'X'.

*  wa_fields-DO_SUM    =  'X'.
  wa_fields-outputlen = 20.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'M_JXQ'.
  wa_fields-seltext_l = '净需求数量'.
  wa_fields-outputlen = 13.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'M_KYK'.
  wa_fields-seltext_l = '可用库存量'.
  wa_fields-outputlen = 13.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'SPEME'.
  wa_fields-seltext_l = '冻结库存量'.
  wa_fields-outputlen = 13.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.

  pos = pos + 1.
  CLEAR wa_fields.
  itab_datum = out_datum.
  itab_outdatum(10) = '确认需求/'.
  out_datum = out_datum .
  itab_outdatum+10(8) =  out_datum.
  CONDENSE itab_outdatum.

  wa_fields-fieldname = 'MNG_A'.
  wa_fields-seltext_l = itab_outdatum.
  CLEAR itab_outdatum.
  wa_fields-outputlen = 13.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认需求/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_B'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认需求/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_C'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认需求/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.

    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_D'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认需求/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_E'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认需求/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_F'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认需求/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_G'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认需求/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_H'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认需求/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_I'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认需求/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_J'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认需求/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_K'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认需求/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_L'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认需求/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_M'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认需求/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_N'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.
  out_datum = itab_datum.


  itab_outdatum(10) = '确认PO/'.
  itab_outdatum+10(8) =  out_datum.
  CONDENSE itab_outdatum.

  wa_fields-fieldname = 'MNG_A1'.
  wa_fields-seltext_l = itab_outdatum.
  CLEAR itab_outdatum.
  wa_fields-outputlen = 13.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认PO/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_B1'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认PO/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_C1'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认PO/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_D1'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认PO/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_E1'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认PO/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_F1'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认PO/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_G1'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认PO/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_H1'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认PO/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_I1'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认PO/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_J1'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认PO/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_K1'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认PO/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_L1'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认PO/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_M1'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认PO/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_N1'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  out_datum = itab_datum.

  itab_outdatum(10) = '短缺数量/'.
  itab_outdatum+10(8) =  out_datum.
  CONDENSE itab_outdatum.

  wa_fields-fieldname = 'MNG_A2'.
  wa_fields-seltext_l = itab_outdatum.
  CLEAR itab_outdatum.
  wa_fields-outputlen = 13.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '短缺数量/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_B2'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '短缺数量/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_C2'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '短缺数量/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_D2'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '短缺数量/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_E2'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '短缺数量/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_F2'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '短缺数量/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_G2'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '短缺数量/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_H2'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '短缺数量/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_I2'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '短缺数量/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_J2'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '短缺数量/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_K2'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '短缺数量/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_L2'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '短缺数量/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_M2'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '短缺数量/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_N2'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  out_datum = itab_datum.

 

  wa_fields-fieldname = 'RSNUM'.
  wa_fields-seltext_l = '预留号'.
  wa_fields-outputlen = 10.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'RSPOS'.
  wa_fields-seltext_l = '项目'.
  wa_fields-outputlen = 4.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'BERID'.
  wa_fields-seltext_l = 'MRP范围'.
  wa_fields-outputlen = 10.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'DISPO'.
  wa_fields-seltext_l = 'MRP控制者'.
  wa_fields-outputlen = 10.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program      = sy-repid
      i_grid_title            = alv_title
      i_save                  = 'X'
      it_fieldcat             = alv_fields
      i_callback_user_command = 'MYCOMMAND'
    TABLES
      t_outtab                = iout_01     "输出内表
    EXCEPTIONS
      program_error           = 1
      OTHERS                  = 2.

ENDFORM.                    " data_output_IOUT
*&---------------------------------------------------------------------*
*&      Form  calcit_itab
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM calcit_itab .
  DATA x_mng02 LIKE itab-mng02.

  DELETE it_itab WHERE delkz NE 'AR'
                   AND delkz NE 'WB'
                    OR plaab NE '02'.

  LOOP AT it_itab.
    num = sy-tabix.
    IF it_itab-plumi NE 'B'.
      it_itab-mng02 = x_mng02 + it_itab-mng01.
      MODIFY it_itab INDEX num TRANSPORTING mng02.
    ENDIF.
    x_mng02 = it_itab-mng02.
  ENDLOOP.
ENDFORM.                    " calcit_itab
*&---------------------------------------------------------------------*
*&      Form  calcpo_itab
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM calcpo_itab .
  DATA x_mng02 LIKE itab-mng02.

  DELETE po_itab WHERE delkz NE 'BE'
                   AND delkz NE 'WB'
                    OR plaab NE '02'.
  LOOP AT po_itab.
    num = sy-tabix.
    IF po_itab-plumi NE 'B'.
      po_itab-mng02 = x_mng02 + po_itab-mng01.
      MODIFY po_itab INDEX num TRANSPORTING mng02.
    ENDIF.
    x_mng02 = po_itab-mng02.
  ENDLOOP.
ENDFORM.                    " calcpo_itab

*&--------------------------------------------------------------------*
*&      Form  GET_data_BY_OTHERS
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM get_data_by_others.
  SELECT resb~rsnum resb~rspos resb~werks resb~lgort resb~bdmng
         resb~enmng resb~kzear afko~aufnr  afko~plnbez resb~matnr
    APPENDING TABLE it00 FROM afko INNER JOIN resb
                 ON afko~rsnum = resb~rsnum
              WHERE afko~aufnr = s_aufnr
                AND resb~matnr IN s_matnr
                AND resb~werks = s_werks
                AND resb~xloek = ''
                AND resb~dumps EQ space. "非虚拟件
*                AND resb~kzkup EQ space. "非散装物料

  LOOP AT it00 WHERE NOT lgort IS INITIAL.
    SELECT SINGLE * FROM mdlg WHERE werks = it00-werks
                                AND lgort = it00-lgort.
    IF sy-subrc EQ 0.
      SELECT SINGLE * FROM mdma WHERE matnr = it00-matnr
                                  AND berid = mdlg-berid.
      IF sy-subrc EQ 0.
        it00-berid = mdma-berid.
        MODIFY it00.
      ENDIF.
    ENDIF.
  ENDLOOP.

  LOOP AT it00.
    IF it00-berid IS INITIAL.
      SELECT SINGLE * FROM mdlv WHERE werzg = it00-werks
                  AND berty = '01'.
      IF sy-subrc EQ 0.
        it00-berid = mdlv-berid.
        SELECT SINGLE * FROM marc WHERE matnr = it00-matnr
                                    AND werks = it00-werks
                                    AND diber = 'X'.
        IF sy-subrc EQ 0.
          MODIFY it00.
        ENDIF.
      ENDIF.
    ENDIF.
    IF NOT it00-berid IN s_berid.
      DELETE it00.
    ENDIF.
  ENDLOOP.

  SORT it00 BY aufnr.
  LOOP AT it00.
    ON CHANGE OF it00-aufnr.
      CLEAR:it00_01-lbtxt,it00_01-normt,it00_01-prgrp.
      SELECT SINGLE * FROM afko WHERE aufnr = it00-aufnr.
      IF sy-subrc EQ 0.
        SELECT SINGLE * FROM mara WHERE matnr = afko-plnbez.
        IF sy-subrc EQ 0.
          it00_01-normt = mara-normt.
          SELECT SINGLE * FROM t024x WHERE labor = mara-labor
                                      AND spras = sy-langu.

          IF sy-subrc EQ 0.
            it00_01-lbtxt = t024x-lbtxt.
          ENDIF.

          SELECT SINGLE * FROM pgmi WHERE werks = s_werks
                                      AND nrmit = afko-plnbez
                                      AND pgtyp = ''.
          IF sy-subrc EQ 0.
            it00_01-prgrp = pgmi-prgrp.
          ENDIF.
        ENDIF.
      ENDIF.

    ENDON.

    it00-lbtxt = it00_01-lbtxt.
    it00-normt = it00_01-normt.
    it00-prgrp = it00_01-prgrp.
    MODIFY it00.
  ENDLOOP.
  SORT it00 BY matnr berid.
  CLEAR it00.
ENDFORM.                    "GET_data_BY_OTHERS
*&---------------------------------------------------------------------*
*&      Form  GET_data_BY_dATE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM get_data_by_date .
  SELECT resb~rsnum resb~rspos resb~werks resb~lgort resb~bdmng
         resb~enmng resb~kzear afko~aufnr afko~plnbez resb~matnr
  INTO TABLE it00 FROM resb INNER JOIN afko ON afko~aufnr = resb~aufnr
       WHERE resb~bdter  <= sel_datu
         AND resb~aufnr  NE ''
         AND resb~matnr  IN s_matnr
         AND resb~werks  EQ s_werks
         AND resb~xloek  EQ ''
         AND afko~plnbez IN s_plnbez
         AND resb~dumps EQ space. "非虚拟件
*         AND resb~kzkup EQ space. "非散装物料

  LOOP AT it00 WHERE NOT lgort IS INITIAL.
    num = sy-tabix.
    SELECT SINGLE * FROM mdlg WHERE werks = it00-werks
                                AND lgort = it00-lgort.
    IF sy-subrc EQ 0.
      SELECT SINGLE * FROM mdma WHERE matnr = it00-matnr
                                  AND berid = mdlg-berid
                                  AND loekz = ''.
      IF sy-subrc EQ 0.
        it00-berid = mdma-berid.
        MODIFY it00 INDEX num TRANSPORTING berid.
      ENDIF.
    ENDIF.
  ENDLOOP.

  LOOP AT it00.
    num = sy-tabix.
    IF it00-berid IS INITIAL.
      SELECT SINGLE * FROM mdlv WHERE werzg = it00-werks
                  AND berty = '01'.
      IF sy-subrc EQ 0.
        it00-berid = mdlv-berid.
        SELECT SINGLE * FROM marc WHERE matnr = it00-matnr
                                    AND werks = it00-werks
                                    AND diber = 'X'.
        IF sy-subrc EQ 0.
          MODIFY it00 INDEX num TRANSPORTING berid.
        ENDIF.
      ENDIF.
    ENDIF.
    IF NOT it00-berid IN s_berid.
      DELETE it00.
    ENDIF.
  ENDLOOP.

  SORT it00 BY aufnr.
  LOOP AT it00.
    ON CHANGE OF it00-aufnr.
      CLEAR:it00_01-lbtxt,it00_01-normt,it00_01-prgrp.
      SELECT SINGLE * FROM afko WHERE aufnr = it00-aufnr.
      IF sy-subrc EQ 0.
        SELECT SINGLE * FROM mara WHERE matnr = afko-plnbez.
        IF sy-subrc EQ 0.
          it00_01-normt = mara-normt.
          SELECT SINGLE * FROM t024x WHERE labor = mara-labor
                                      AND spras = sy-langu.
          IF sy-subrc EQ 0.
            it00_01-lbtxt = t024x-lbtxt.
          ENDIF.
          SELECT SINGLE * FROM pgmi WHERE werks = s_werks
                                      AND nrmit = afko-plnbez
                                      AND pgtyp = ''.
          IF sy-subrc EQ 0.
            it00_01-prgrp = pgmi-prgrp.
          ENDIF.
        ENDIF.
      ENDIF.

    ENDON.
    it00-lbtxt = it00_01-lbtxt.
    it00-normt = it00_01-normt.
    it00-prgrp = it00_01-prgrp.
    MODIFY it00.
  ENDLOOP.
  SORT it00 BY matnr berid.
  CLEAR it00.
ENDFORM.                    " GET_data_BY_dATE

*&--------------------------------------------------------------------*
*&      Form  itab_Ezl
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
FORM itab_ezl .
  DATA: zdatum LIKE sy-datum.

  it_itab[] = itab[].
  po_itab[] = itab[].

  PERFORM calcit_itab.
  PERFORM calcpo_itab.

  LOOP AT it00.
    ON CHANGE OF it00-matnr OR it00-berid.

      READ TABLE it_itab WITH KEY matnr = it00-matnr
                                  berid = it00-berid
                                  delkz =  'WB'.
      IF sy-subrc EQ 0.

        iout-berid = it00-berid.
        iout-matnr = it00-matnr.
*取库存地下的冻结库存
        PERFORM get_speme_from_mard USING  it00-matnr
                                           it00-werks
                                           it00-berid
                                 CHANGING  x_speme.
        iout-speme = x_speme.
        it_itab-mng02 = it_itab-mng02 - x_speme.
        CLEAR:x_speme.
        iout-m_kyk = it_itab-mng02.
        iout-maktx = it_itab-maktx.
        iout-werks = it_itab-werks.
        iout-dispo = it_itab-dispo.
        zdatum = sel_datu.
        out_datum = zdatum.

        PERFORM fill_days_to_itab
                    USING
                       out_datum
                       iout-mng_a
                       iout-mng_a1
                       iout-mng_a2
                       iout-jxq_a
                       'a'.


        IF out_datum > sy-datum.
          out_datum = out_datum - s_days.
          IF out_datum < sy-datum.
            out_datum = sy-datum.
          ENDIF.

          PERFORM fill_days_to_itab
                 USING
                    out_datum
                    iout-mng_b
                    iout-mng_b1
                    iout-mng_b2
                    iout-jxq_b
                    'b'.
        ENDIF.


        IF out_datum > sy-datum.
          out_datum = out_datum - s_days.
          IF out_datum < sy-datum.
            out_datum = sy-datum.
          ENDIF.
          PERFORM fill_days_to_itab
                 USING
                    out_datum
                    iout-mng_c
                    iout-mng_c1
                    iout-mng_c2
                    iout-jxq_c
                    'c'.
        ENDIF.

        IF out_datum > sy-datum.
          out_datum = out_datum - s_days.
          IF out_datum < sy-datum.
            out_datum = sy-datum.
          ENDIF.
          PERFORM fill_days_to_itab
                 USING
                    out_datum
                    iout-mng_d
                    iout-mng_d1
                    iout-mng_d2
                    iout-jxq_d
                    'd'.
        ENDIF.

        IF out_datum > sy-datum.
          out_datum = out_datum - s_days.
          IF out_datum < sy-datum.
            out_datum = sy-datum.
          ENDIF.
          PERFORM fill_days_to_itab
                 USING
                    out_datum
                    iout-mng_e
                    iout-mng_e1
                    iout-mng_e2
                    iout-jxq_e
                    'e'.
        ENDIF.

        IF out_datum > sy-datum.
          out_datum = out_datum - s_days.
          IF out_datum < sy-datum.
            out_datum = sy-datum.
          ENDIF.
          PERFORM fill_days_to_itab
                 USING
                    out_datum
                    iout-mng_f
                    iout-mng_f1
                    iout-mng_f2
                    iout-jxq_f
                    'f'.
        ENDIF.

        IF out_datum > sy-datum.
          out_datum = out_datum - s_days.
          IF out_datum < sy-datum.
            out_datum = sy-datum.
          ENDIF.
          PERFORM fill_days_to_itab
                 USING
                    out_datum
                    iout-mng_g
                    iout-mng_g1
                    iout-mng_g2
                    iout-jxq_g
                    'g'.
        ENDIF.

        IF out_datum > sy-datum.
          out_datum = out_datum - s_days.
          IF out_datum < sy-datum.
            out_datum = sy-datum.
          ENDIF.
          PERFORM fill_days_to_itab
                 USING
                    out_datum
                    iout-mng_h
                    iout-mng_h1
                    iout-mng_h2
                    iout-jxq_h
                    'h'.
        ENDIF.

        IF out_datum > sy-datum.
          out_datum = out_datum - s_days.
          IF out_datum < sy-datum.
            out_datum = sy-datum.
          ENDIF.
          PERFORM fill_days_to_itab
                 USING
                    out_datum
                    iout-mng_i
                    iout-mng_i1
                    iout-mng_i2
                    iout-jxq_i
                    'i'.
        ENDIF.

        IF out_datum > sy-datum.
          out_datum = out_datum - s_days.
          IF out_datum < sy-datum.
            out_datum = sy-datum.
          ENDIF.
          PERFORM fill_days_to_itab
                 USING
                    out_datum
                    iout-mng_j
                    iout-mng_j1
                    iout-mng_j2
                    iout-jxq_j
                    'j'.
        ENDIF.

        IF out_datum > sy-datum.
          out_datum = out_datum - s_days.
          IF out_datum < sy-datum.
            out_datum = sy-datum.
          ENDIF.
          PERFORM fill_days_to_itab
                 USING
                    out_datum
                    iout-mng_k
                    iout-mng_k1
                    iout-mng_k2
                    iout-jxq_k
                    'k'.
        ENDIF.

        IF out_datum > sy-datum.
          out_datum = out_datum - s_days.
          IF out_datum < sy-datum.
            out_datum = sy-datum.
          ENDIF.
          PERFORM fill_days_to_itab
                 USING
                    out_datum
                    iout-mng_l
                    iout-mng_l1
                    iout-mng_l2
                    iout-jxq_l
                    'l'.
        ENDIF.

        IF out_datum > sy-datum.
          out_datum = out_datum - s_days.
          IF out_datum < sy-datum.
            out_datum = sy-datum.
          ENDIF.
          PERFORM fill_days_to_itab
                 USING
                    out_datum
                    iout-mng_m
                    iout-mng_m1
                    iout-mng_m2
                    iout-jxq_m
                    'm'.
        ENDIF.

        IF out_datum > sy-datum.
          out_datum = out_datum - s_days.
          IF out_datum < sy-datum.
            out_datum = sy-datum.
          ENDIF.
          PERFORM fill_days_to_itab
                 USING
                    out_datum
                    iout-mng_n
                    iout-mng_n1
                    iout-mng_n2
                    iout-jxq_n
                    'n'.
        ENDIF.
        out_datum = zdatum.
        iout-m_jxq = iout-jxq_a.
        APPEND iout.
      ENDIF.
      CLEAR iout.
    ENDON.
  ENDLOOP.
  it02[] = iout[].
  REFRESH:it00,itab,iout,it_itab,po_itab.
ENDFORM.                    "itab_Ezl
*&---------------------------------------------------------------------*
*&      Form  data_output_IT02
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM data_output_it02 .
  DATA:pos TYPE i VALUE 1,
      itab_outdatum(18),
      itab_datum LIKE sy-datum.

  CLEAR wa_fields.
  wa_fields-fieldname = 'MATNR'.
  wa_fields-seltext_l = '物料代码'.
  wa_fields-outputlen = '15'.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'MAKTX'.
  wa_fields-seltext_l = '物料描述'.
  wa_fields-outputlen = 20.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'M_JXQ'.
  wa_fields-seltext_l = '净需求数量'.
  wa_fields-outputlen = 13.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'M_KYK'.
  wa_fields-seltext_l = '可用库存量'.
  wa_fields-outputlen = 13.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'SPEME'.
  wa_fields-seltext_l = '冻结库存量'.
  wa_fields-outputlen = 13.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  itab_datum = out_datum.
  itab_outdatum(10) = '确认需求/'.
  out_datum = out_datum .
  itab_outdatum+10(8) =  out_datum.
  CONDENSE itab_outdatum.

  wa_fields-fieldname = 'MNG_A'.
  wa_fields-seltext_l = itab_outdatum.
  CLEAR itab_outdatum.
  wa_fields-outputlen = 13.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认需求/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_B'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认需求/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_C'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认需求/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.

    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_D'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认需求/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_E'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认需求/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_F'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认需求/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_G'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认需求/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_H'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认需求/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_I'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认需求/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_J'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认需求/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_K'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认需求/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_L'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认需求/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_M'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认需求/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_N'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.
  out_datum = itab_datum.


  itab_outdatum(10) = '确认PO/'.
  itab_outdatum+10(8) =  out_datum.
  CONDENSE itab_outdatum.

  wa_fields-fieldname = 'MNG_A1'.
  wa_fields-seltext_l = itab_outdatum.
  CLEAR itab_outdatum.
  wa_fields-outputlen = 13.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认PO/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_B1'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认PO/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_C1'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认PO/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_D1'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认PO/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_E1'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认PO/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_F1'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认PO/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_G1'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认PO/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_H1'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认PO/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_I1'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认PO/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_J1'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认PO/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_K1'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认PO/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_L1'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认PO/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_M1'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '确认PO/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_N1'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  out_datum = itab_datum.

  itab_outdatum(10) = '短缺数量/'.
  itab_outdatum+10(8) =  out_datum.
  CONDENSE itab_outdatum.

  wa_fields-fieldname = 'MNG_A2'.
  wa_fields-seltext_l = itab_outdatum.
  CLEAR itab_outdatum.
  wa_fields-outputlen = 13.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '短缺数量/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_B2'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '短缺数量/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_C2'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '短缺数量/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_D2'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '短缺数量/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_E2'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '短缺数量/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_F2'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '短缺数量/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_G2'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '短缺数量/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_H2'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '短缺数量/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_I2'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '短缺数量/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_J2'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '短缺数量/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_K2'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '短缺数量/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_L2'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '短缺数量/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_M2'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  IF out_datum > sy-datum.
    itab_outdatum(10) = '短缺数量/'.
    out_datum = out_datum - s_days.
    IF out_datum < sy-datum.
      out_datum = sy-datum.
    ENDIF.
    itab_outdatum+10(8) =  out_datum.
    CONDENSE itab_outdatum.

    wa_fields-fieldname = 'MNG_N2'.
    wa_fields-seltext_l = itab_outdatum.
    CLEAR itab_outdatum.
    wa_fields-outputlen = 13.
    wa_fields-col_pos  = pos.
    APPEND wa_fields TO alv_fields.
    pos = pos + 1.
    CLEAR wa_fields.
  ENDIF.

  out_datum = itab_datum.

 

  wa_fields-fieldname = 'BERID'.
  wa_fields-seltext_l = 'MRP范围'.
  wa_fields-outputlen = 10.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

  wa_fields-fieldname = 'DISPO'.
  wa_fields-seltext_l = 'MRP控制者'.
  wa_fields-outputlen = 10.
  wa_fields-col_pos  = pos.
  APPEND wa_fields TO alv_fields.
  pos = pos + 1.
  CLEAR wa_fields.

 

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_callback_program      = sy-repid
      i_grid_title            = alv_title
      i_save                  = 'X'
      it_fieldcat             = alv_fields
      i_callback_user_command = 'MYCOMMANDE'
    TABLES
      t_outtab                = it02     "输出内表
    EXCEPTIONS
      program_error           = 1
      OTHERS                  = 2.

ENDFORM.                    " data_output_IT02

*&--------------------------------------------------------------------*
*&      Form  fill_days_to_itab
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
*      -->P_datum  text
*      -->P_mng_a    text
*      -->P_mng_a1   text
*      -->P_mng_a2   text
*      -->P_m_jxq    text
*---------------------------------------------------------------------*
FORM fill_days_to_itab USING p_datum
                             p_mng_a
                             p_mng_a1
                             p_mng_a2
                             p_m_jxq
                             p_x.


  CLEAR:p_mng_a,p_mng_a1,p_mng_a2,p_m_jxq.
  IF p_datum <= sy-datum."OPEN PO在当前日期之前的都放到当前日期栏位
    LOOP AT po_itab WHERE matnr = it00-matnr
                      AND berid = it00-berid
                      AND delkz NE 'WB'
                      AND dat01 <= p_datum.
      p_mng_a1 = p_mng_a1 + po_itab-mng01.
    ENDLOOP.
  ELSE.
    LOOP AT po_itab WHERE matnr = it00-matnr
                      AND berid = it00-berid
                      AND delkz NE 'WB'
                      AND dat01 = p_datum.
      p_mng_a1 = p_mng_a1 + po_itab-mng01.
    ENDLOOP.
  ENDIF.
*
  LOOP AT it_itab WHERE matnr = it00-matnr
                    AND berid = it00-berid
                    AND delkz NE 'WB'
                    AND dat01 <= p_datum.

    p_mng_a = p_mng_a + it_itab-mng01.

  ENDLOOP.
  p_m_jxq =  p_mng_a.
  p_mng_a = iout-m_kyk + p_m_jxq.
  p_mng_a2 = p_mng_a + p_mng_a1.
  IF p_mng_a2 > 0.
    p_mng_a2 = 0.
  ENDIF.
ENDFORM.                    "fill_days_to_itab


*&--------------------------------------------------------------------*
*&      Form  fill_dates_2_itab
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
*      -->P_datum  text
*      -->P_mng_a    text
*      -->P_mng_a1   text
*      -->P_mng_a2   text
*      -->P_m_jxq    text
*---------------------------------------------------------------------*
FORM fill_dates_2_itab USING p_datum
                             p_mng_a
                             p_mng_a1
                             p_mng_a2
                             p_m_jxq.

  CLEAR: p_mng_a,p_mng_a1,p_mng_a2,p_m_jxq.

  LOOP AT po_itab WHERE matnr = it00-matnr
                    AND berid = it00-berid
                    AND delkz NE 'WB'
                    AND dat01 <= p_datum.
    p_mng_a1 = p_mng_a1 + po_itab-mng01.
  ENDLOOP.

  LOOP AT it_itab WHERE matnr = it00-matnr
                    AND berid = it00-berid
                    AND  delkz NE 'WB'
                    AND dat01 <=  p_datum
                    AND delnr NE it00-rsnum.

    p_mng_a = p_mng_a + it_itab-mng01.
  ENDLOOP.

  LOOP AT it_itab WHERE matnr = it00-matnr
                    AND berid = it00-berid
                    AND  delkz NE 'WB'
                    AND dat01 <=  p_datum
                    AND delnr = it00-rsnum
                    AND delps <= it00-rspos.

    p_mng_a = p_mng_a + it_itab-mng01.
  ENDLOOP.

  p_m_jxq = p_mng_a.
  p_mng_a = iout-m_kyk + p_mng_a .
  p_mng_a2 = p_mng_a + p_mng_a1.
  IF p_mng_a2 > 0.
    p_mng_a2 = 0.
  ENDIF.
ENDFORM.                    "fill_dates_2_itab

*&--------------------------------------------------------------------*
*&      Form  MYCOMMAND
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
*      -->R_UCOMM    text
*      -->RS_SELFIELDtext
*---------------------------------------------------------------------*
FORM mycommand USING r_ucomm LIKE sy-ucomm
                        rs_selfield TYPE slis_selfield.

  CASE r_ucomm.

    WHEN '&IC1'.

      READ TABLE iout_01 INDEX  rs_selfield-tabindex.
      IF sy-subrc EQ 0.
        SET PARAMETER ID 'MAT' FIELD iout_01-matnr.
        SET PARAMETER ID 'LAG' FIELD id_lgort.
        SET PARAMETER ID 'CHA' FIELD id_charg.
        SET PARAMETER ID 'WRK' FIELD iout_01-werks .
        CALL TRANSACTION 'MMBE'  AND SKIP FIRST SCREEN .

      ENDIF.
      CLEAR: rs_selfield-tabindex.
  ENDCASE.
ENDFORM.                               " USER_COMMAND

*&--------------------------------------------------------------------*
*&      Form  MYCOMMANDC
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
*      -->R_UCOMM    text
*      -->RS_SELFIELDtext
*---------------------------------------------------------------------*
FORM mycommandc USING r_ucomm LIKE sy-ucomm
                        rs_selfield TYPE slis_selfield.

  CASE r_ucomm.

    WHEN '&IC1'.

      READ TABLE it01_01 INDEX  rs_selfield-tabindex.
      IF sy-subrc EQ 0.
        SET PARAMETER ID 'MAT' FIELD it01_01-matnr.
        SET PARAMETER ID 'BERID' FIELD it01_01-berid.
        SET PARAMETER ID 'WRK' FIELD it01_01-werks.

*        SET PARAMETER ID 'LAG' FIELD id_lgort.
*        SET PARAMETER ID 'CHA' FIELD id_charg.
        CALL TRANSACTION 'MD04'  AND SKIP FIRST SCREEN .

      ENDIF.
      IF sy-subrc EQ 0.
        SET PARAMETER ID 'MAT' FIELD it01_01-matnr.
        SET PARAMETER ID 'WRK' FIELD it01_01-werks.
        SET PARAMETER ID 'LAG' FIELD id_lgort.
        SET PARAMETER ID 'CHA' FIELD id_charg.
        CALL TRANSACTION 'MMBE'  AND SKIP FIRST SCREEN .

      ENDIF.
      CLEAR: rs_selfield-tabindex.

  ENDCASE.
ENDFORM.                               " USER_COMMAND

*&--------------------------------------------------------------------*
*&      Form  MYCOMMANDE
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
*      -->R_UCOMM    text
*      -->RS_SELFIELDtext
*---------------------------------------------------------------------*
FORM mycommande USING r_ucomm LIKE sy-ucomm
                        rs_selfield TYPE slis_selfield.

  CASE r_ucomm.

    WHEN '&IC1'.

      READ TABLE it02 INDEX  rs_selfield-tabindex.
      IF sy-subrc EQ 0.
        SET PARAMETER ID 'MAT' FIELD it02-matnr.
        SET PARAMETER ID 'LAG' FIELD id_lgort.
        SET PARAMETER ID 'CHA' FIELD id_charg.
        SET PARAMETER ID 'WRK' FIELD it02-werks .
        CALL TRANSACTION 'MMBE'  AND SKIP FIRST SCREEN .

      ENDIF.
      CLEAR: rs_selfield-tabindex.
  ENDCASE.
ENDFORM.                               " USER_COMMAND

*&--------------------------------------------------------------------*
*&      Form  mrp_area
*&--------------------------------------------------------------------*
*       text
*---------------------------------------------------------------------*
*      -->p_matnr    text
*      -->p_werks    text
*      -->p_berid    text
*---------------------------------------------------------------------*
FORM mrp_area USING p_matnr p_werks p_berid .
  DATA:nnn LIKE sy-tabix.
  SELECT matnr werks lgort labst speme insme FROM mard
    INTO TABLE ilgort WHERE matnr = p_matnr
                        AND werks = p_werks.
  IF NOT p_berid IS INITIAL.
    LOOP AT ilgort.
******change by zhaohd****************
      nnn = sy-tabix.
      IF NOT ilgort[] IS INITIAL.
********end***************************
        SELECT SINGLE * FROM mdlg WHERE werks = p_werks
                                    AND lgort = ilgort-lgort.
        IF sy-subrc EQ 0.
          SELECT SINGLE * FROM mdma WHERE matnr = p_matnr
                                      AND berid = mdlg-berid
                                      AND loekz = ''.
          IF sy-subrc EQ 0.
            ilgort-berid = mdlg-berid.
            MODIFY ilgort INDEX nnn TRANSPORTING berid.
          ELSE.
            SELECT SINGLE * FROM mdlv WHERE werzg = p_werks.
            IF sy-subrc EQ 0.
              ilgort-berid = mdlv-berid.
              MODIFY ilgort INDEX nnn TRANSPORTING berid.
            ENDIF.
          ENDIF.
        ELSE.
          SELECT SINGLE * FROM mdlv WHERE werzg = p_werks.
          IF sy-subrc EQ 0.
            ilgort-berid = mdlv-berid.
            MODIFY ilgort INDEX nnn TRANSPORTING berid.
          ENDIF.
        ENDIF.
*****change by zhaohd20050411***************
      ELSE.
        EXIT.
      ENDIF.
*******end***************************
    ENDLOOP.
  ENDIF.
ENDFORM.                    "mrp_area
*&---------------------------------------------------------------------*
*&      Form  OUPUT_TO_ALV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM ouput_to_alv .
  IF sel02 = 'X'.
    IF sel00 = 'X'.
      IF itab[] IS INITIAL.
        MESSAGE '没有数据存在!' TYPE 'S'.
      ELSE.
        PERFORM data_output.
      ENDIF.
    ELSE.
      PERFORM itab_bzl.
      IF iout_01[] IS INITIAL.
        MESSAGE '没有数据存在!' TYPE 'S'.
      ELSE.
        PERFORM data_output_iout.
      ENDIF.
    ENDIF.
  ELSEIF sel01 = 'X'.
    IF sel00 = 'X'.
      IF itab[] IS INITIAL.
        MESSAGE '没有数据存在!' TYPE 'S'.
      ELSE.
        PERFORM data_output.
      ENDIF.
    ELSE.
      PERFORM itab_czl.
      IF it01_01[] IS INITIAL.
        MESSAGE '没有数据存在!' TYPE 'S'.
      ELSE.
        PERFORM data_output_it01.
      ENDIF.
    ENDIF.
  ELSEIF sel03 = 'X'.
    IF sel00 = 'X'.
      IF itab[] IS INITIAL.
        MESSAGE '没有数据存在!' TYPE 'S'.
      ELSE.
        PERFORM data_output.
      ENDIF.
    ELSE.
      PERFORM itab_ezl.
      IF it02[] IS INITIAL.
        MESSAGE '没有数据存在!' TYPE 'S'.
      ELSE.
        PERFORM data_output_it02.
      ENDIF.
    ENDIF.
  ENDIF.
ENDFORM.                    " OUPUT_TO_ALV
*&---------------------------------------------------------------------*
*&      Form  get_speme_from_mard
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_MATNR  text
*      -->P_WERKS  text
*      -->P_LGORT  text
*      <--P_SPEME  text
*----------------------------------------------------------------------*
FORM get_speme_from_mard  USING    p_matnr
                                   p_werks
                                   p_berid
                         CHANGING  p_speme.
*找冻结库存
*如果MRParea 存在 则找此MRParea下所有库存地的冻结库存
  IF p_berid NE '1000'.
    SELECT lgort FROM mdlg INTO CORRESPONDING FIELDS OF TABLE ilgort1
                                     WHERE berid = p_berid
                                       AND werks = p_werks.

    IF NOT ilgort1[] IS INITIAL.
      SELECT * FROM mard INTO CORRESPONDING FIELDS OF TABLE istock
      FOR ALL ENTRIES IN ilgort1 WHERE matnr = p_matnr
                                  AND werks = p_werks
                                  AND lgort = ilgort1-lgort
                                  and DISKZ = ''.
      LOOP AT istock.
         p_speme = istock-speme + p_speme.
         ENDLOOP.
    ENDIF.
*否则找该物料工厂下的所有库存并减掉该物料存在MRParea下库存地的库存
  ELSE.
    SELECT * FROM mard INTO CORRESPONDING FIELDS OF TABLE istock
                          WHERE matnr = p_matnr
                            AND werks = p_werks
                            and DISKZ = ''.
*                                AND lgort = ilgort-lgort.
    LOOP AT istock.
*排除MRParea下的库存地库存
      SELECT SINGLE * FROM mdlg WHERE werks = s_werks
                                 AND lgort = istock-lgort.
      IF sy-subrc NE space.
        p_speme = istock-speme + p_speme.
      ENDIF.
    ENDLOOP.
  ENDIF.


*  SELECT SUM( speme ) INTO p_speme FROM mard WHERE matnr = p_matnr
*                                                 AND werks = p_werks
**                                                 AND lgort = p_lgort
*                                                 AND lvorm = ''.
ENDFORM.                    " get_speme_from_mard

posted on 2007-05-09 21:41 恩达 阅读(4076) 评论(4)  编辑  收藏 所属分类: ERP

评论

# re: SAP 程序介绍-本人曾写的一个报表程序(ABAP/4语言-R/3专用语言) 2008-08-15 14:05 yu
怎么提示不能用,INCLUDE zmd04_XX_top.
INCLUDE zmd04_XX_sel. 能不能提供一下  回复  更多评论
  

# re: SAP 程序介绍-本人曾写的一个报表程序(ABAP/4语言-R/3专用语言) 2008-08-15 14:28 wangs
好几年前写的东西了,都快忘了,呵呵,实在不好意思,提供不了了,找不到原代码了  回复  更多评论
  

# re: SAP 程序介绍-本人曾写的一个报表程序(ABAP/4语言-R/3专用语言)[未登录] 2010-05-27 18:01 edison
@wangs
班竹写modify几乎都会用tabix
我则是很少用用tabix
因为当你在loop中要modify该笔资料不用tabix也可以
只要modify itab transoprting xxx即可

不过也是因此让我对mdpsx没有流水号跟mdezx对应很困扰
但看了班竹tabix的写法刚好可以解这个问题
非常感谢!  回复  更多评论
  

# re: SAP 程序介绍-本人曾写的一个报表程序(ABAP/4语言-R/3专用语言) 2013-06-07 22:45 SAP
找找啊,很不错的啊  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: