生产排产表DL-ZPPR002

*&---------------------------------------------------------------------*
*& Report  ZPPR002
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT zppr002 NO STANDARD PAGE HEADING MESSAGE-ID zpp.

INCLUDE zppr002_top.

SELECTION-SCREEN BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
SELECT-OPTIONS:s_werks FOR marc-werks NO-EXTENSION NO INTERVALS OBLIGATORY,
               s_dispo FOR marc-dispo,
               s_matkl FOR mara-matkl,
               s_matnr FOR marc-matnr,
               s_gstrp FOR afko-gstrp NO-EXTENSION OBLIGATORY.
PARAMETERS:p_edatu TYPE vbep-edatu OBLIGATORY.
SELECTION-SCREEN END OF BLOCK blk1.

SELECTION-SCREEN BEGIN OF BLOCK blk2 WITH FRAME TITLE text-002.
PARAMETERS:p_rb1 RADIOBUTTON GROUP r1 DEFAULT ‘X‘,
           p_rb2 RADIOBUTTON GROUP r1.
SELECTION-SCREEN END OF BLOCK blk2.

INITIALIZATION.
  PERFORM frm_initialization.

START-OF-SELECTION.
  PERFORM frm_auth_check.

  PERFORM frm_get_data.

  PERFORM frm_process_data.

  PERFORM frm_display_alv.

*&---------------------------------------------------------------------*
*&      Form  FRM_INITIALIZATION
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_initialization .
  IF s_gstrp[] IS INITIAL.
    s_gstrp-sign = ‘I‘.
    s_gstrp-option = ‘EQ‘.
    s_gstrp-low = sy-datum + 1.
    APPEND s_gstrp.
  ENDIF.

  IF p_edatu IS INITIAL.
    p_edatu = sy-datum + 1.
  ENDIF.

*  IF s_werks IS INITIAL.
*    s_werks-sign = ‘I‘.
*    s_werks-option = ‘EQ‘.
*    s_werks-low = ‘2001‘.
*    APPEND s_werks.
*  ENDIF.
ENDFORM.                    " FRM_INITIALIZATION
*&---------------------------------------------------------------------*
*&      Form  FRM_GET_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_get_data .
  DATA:l_datum TYPE sy-datum.
  DATA:lt_rxsjh TYPE TABLE OF ztsd_rxsjh,
       lw_rxsjh TYPE          ztsd_rxsjh.

  "查询出“MRP控制者”(MARC-DISPO)为P01、P02、P03或P08,或“物料组”(MARC-MATKL)为5010110的所有物料

  SELECT marc~matnr marc~werks marc~disgr marc~eisbe marc~frtme marc~dispo mara~meins mara~matkl t438m~auart
    INTO CORRESPONDING FIELDS OF TABLE gt_matnr
    FROM marc
   INNER JOIN mara
      ON mara~matnr EQ marc~matnr
    LEFT JOIN t438m
      ON t438m~werks = marc~werks
     AND t438m~mtart = marc~disgr
   WHERE marc~werks IN s_werks
     AND marc~matnr IN s_matnr
     AND ( marc~dispo IN (‘P01‘,‘P02‘,‘P03‘,‘P08‘) OR mara~matkl EQ ‘5010110‘ ).

  IF s_matkl[] IS NOT INITIAL.
    DELETE gt_matnr WHERE matkl NOT IN s_matkl.
  ENDIF.

  IF s_dispo[] IS NOT INITIAL.
    DELETE gt_matnr WHERE dispo NOT IN s_dispo.
  ENDIF.

*  SELECT marc~matnr marc~werks marc~disgr marc~eisbe marc~frtme mara~meins t438m~auart
*   APPENDING CORRESPONDING FIELDS OF TABLE gt_matnr
*    FROM marc
*   INNER JOIN mara
*      ON mara~matnr = marc~matnr
*     LEFT JOIN t438m
*      ON t438m~werks = marc~werks
*     AND t438m~mtart = marc~disgr
*   WHERE marc~werks IN s_werks
*     AND marc~matnr IN s_matnr
*     AND mara~matkl EQ ‘5010110‘.

*   SELECT marc~matnr marc~werks marc~disgr marc~eisbe marc~frtme mara~meins t438m~auart
*      APPENDING CORRESPONDING FIELDS OF TABLE gt_matnr
*      FROM marc
*      INNER JOIN mara
*      ON mara~matnr = marc~matnr
*      LEFT JOIN t438m
*      ON t438m~werks = marc~werks
*      AND t438m~mtart = marc~disgr
*      WHERE marc~werks IN s_werks
*        AND marc~matnr IN s_matnr
*        AND marc~dispo IN s_dispo
*        AND mara~matkl IN s_matkl.

  IF gt_matnr IS INITIAL.
    MESSAGE s000 WITH ‘没有符合条件的数据‘ DISPLAY LIKE ‘E‘.
    STOP.
  ELSE.
    LOOP AT gt_matnr INTO gw_matnr WHERE frtme IS INITIAL.
      gw_matnr-frtme = gw_matnr-meins.
      MODIFY gt_matnr FROM gw_matnr TRANSPORTING frtme.
    ENDLOOP.
  ENDIF.

  SORT gt_matnr BY matnr werks.
  DELETE ADJACENT DUPLICATES FROM gt_matnr COMPARING matnr werks.

  "物料描述
  SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_makt
    FROM makt
    FOR ALL ENTRIES IN gt_matnr
    WHERE matnr = gt_matnr-matnr
      AND spras = sy-langu.

  "生产订单编号和数量
  SELECT afpo~aufnr afpo~posnr afpo~dwerk afpo~matnr afpo~dauat afpo~psmng afko~gstrp
    INTO CORRESPONDING FIELDS OF TABLE gt_afpo
    FROM afpo
    INNER JOIN afko
    ON afko~aufnr EQ afpo~aufnr
    FOR ALL ENTRIES IN gt_matnr
    WHERE afpo~dwerk EQ gt_matnr-werks
      AND afpo~matnr EQ gt_matnr-matnr
      AND afpo~dauat EQ gt_matnr-auart
      AND afko~gstrp IN s_gstrp.   "订单开始时间
  IF gt_afpo IS NOT INITIAL.
    SELECT aufnr objnr INTO CORRESPONDING FIELDS OF TABLE gt_objnr FROM aufk
                        FOR ALL ENTRIES IN gt_afpo
                      WHERE aufnr = gt_afpo-aufnr .
    SORT gt_objnr BY aufnr .

    LOOP AT gt_afpo INTO gw_afpo.
      CLEAR:g_line,gw_objnr .
      READ TABLE gt_objnr INTO gw_objnr WITH KEY aufnr = gw_afpo-aufnr BINARY SEARCH .
      IF sy-subrc = 0.
        "状态读取
        CALL FUNCTION ‘STATUS_TEXT_EDIT‘
          EXPORTING
            objnr            = gw_objnr-objnr
            spras            = sy-langu
          IMPORTING
            line             = g_line
          EXCEPTIONS
            object_not_found = 1
            OTHERS           = 2.
        FIND ‘DLFL‘ IN g_line .
        IF sy-subrc = 0.
          DELETE gt_afpo.
        ENDIF.
      ENDIF.
    ENDLOOP.
  ENDIF.

  "工艺路线版本和版本描述
  SELECT mapl~matnr mapl~werks mapl~plnty mapl~plnnr mapl~plnal mapl~zaehl plko~ktext
    INTO CORRESPONDING FIELDS OF TABLE gt_gylx
    FROM mapl
    INNER JOIN plko
    ON  plko~plnty = mapl~plnty
    AND plko~plnnr = mapl~plnnr
    AND plko~plnal = mapl~plnal
    AND plko~zaehl = mapl~zaehl
    WHERE mapl~plnty = ‘N‘
      AND mapl~loekz = ‘‘.

  "未清提单
  SELECT vbbe~werks vbbe~matnr vbbe~vbeln vbbe~posnr vbbe~etenr vbbe~omeng AS bmeng vbbe~meins AS vrkme
    INTO CORRESPONDING FIELDS OF TABLE gt_wqdd
    FROM vbbe
    FOR ALL ENTRIES IN gt_matnr
    WHERE vbbe~werks EQ gt_matnr-werks
      AND vbbe~matnr EQ gt_matnr-matnr
      AND vbbe~vbtyp IN (‘J‘,‘C‘)
      AND vbbe~mbdat LE p_edatu.
*  SELECT vbap~werks vbap~lgort vbap~matnr vbep~vbeln vbep~posnr vbep~etenr vbep~vrkme vbep~bmeng
*    INTO CORRESPONDING FIELDS OF TABLE gt_wqdd
*    FROM vbap
*    INNER JOIN vbuk
*    ON vbuk~vbeln = vbap~vbeln
*    INNER JOIN vbep
*    ON  vbep~vbeln = vbap~vbeln
*    AND vbep~posnr = vbap~posnr
*    FOR ALL ENTRIES IN gt_matnr
*    WHERE vbap~werks EQ gt_matnr-werks
*      AND vbap~matnr EQ gt_matnr-matnr
*      AND vbuk~vbtyp = ‘C‘
*      AND vbuk~lfstk = ‘A‘
*      AND vbep~edatu LE p_edatu.
  "汇总未清提单数量
  LOOP AT gt_wqdd INTO gw_wqdd.
    CLEAR gw_matnr.
    READ TABLE gt_matnr INTO gw_matnr WITH KEY matnr = gw_wqdd-matnr
                                               werks = gw_wqdd-werks
                                               BINARY SEARCH.
    CALL FUNCTION ‘MD_CONVERT_MATERIAL_UNIT‘
      EXPORTING
        i_matnr              = gw_matnr-matnr
        i_in_me              = gw_wqdd-vrkme
        i_out_me             = gw_matnr-frtme
        i_menge              = gw_wqdd-bmeng
      IMPORTING
        e_menge              = gw_wqdd-bmeng
      EXCEPTIONS
        error_in_application = 1
        error                = 2
        OTHERS               = 3.
    IF sy-subrc <> 0.
* Implement suitable error handling here
    ENDIF.

    CLEAR gw_wqddsl.
    MOVE-CORRESPONDING gw_wqdd TO gw_wqddsl.

    COLLECT gw_wqddsl INTO gt_wqddsl.
  ENDLOOP.

  "当前库存
  SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_mard
    FROM mard
    INNER JOIN t001l
    ON  t001l~werks = mard~werks
    AND t001l~lgort = mard~lgort
    FOR ALL ENTRIES IN gt_matnr
    WHERE mard~werks = gt_matnr-werks
      AND mard~matnr = gt_matnr-matnr
      AND t001l~diskz NE ‘1‘.
  "汇总当前库存数量
  LOOP AT gt_mard INTO gw_mard.
    CLEAR gw_matnr.
    READ TABLE gt_matnr INTO gw_matnr WITH KEY matnr = gw_mard-matnr
                                               werks = gw_mard-werks
                                               BINARY SEARCH.
    CALL FUNCTION ‘MD_CONVERT_MATERIAL_UNIT‘
      EXPORTING
        i_matnr              = gw_matnr-matnr
        i_in_me              = gw_matnr-meins
        i_out_me             = gw_matnr-frtme
        i_menge              = gw_mard-labst
      IMPORTING
        e_menge              = gw_mard-labst
      EXCEPTIONS
        error_in_application = 1
        error                = 2
        OTHERS               = 3.
    IF sy-subrc <> 0.
* Implement suitable error handling here
    ENDIF.

    CLEAR gw_dqkcsl.
    MOVE-CORRESPONDING gw_mard TO gw_dqkcsl.
    COLLECT gw_dqkcsl INTO gt_dqkcsl.
  ENDLOOP.

*  "在产订单
  SELECT afpo~aufnr afpo~posnr afpo~dwerk afpo~matnr afpo~dauat afpo~psmng afko~gstrp
     INTO CORRESPONDING FIELDS OF TABLE gt_afpo_zc
    FROM afpo
    INNER JOIN afko
    ON afko~aufnr EQ afpo~aufnr
    FOR ALL ENTRIES IN gt_matnr
    WHERE afpo~dwerk EQ gt_matnr-werks
      AND afpo~matnr EQ gt_matnr-matnr
      AND afko~gstrp IN s_gstrp.   "订单开始时间
  "汇总在产数量
  LOOP AT gt_afpo_zc INTO gw_afpo.
    CLEAR gw_zcsl.
    MOVE-CORRESPONDING gw_afpo TO gw_zcsl.
    gw_zcsl-werks = gw_afpo-dwerk.

*    SELECT SINGLE gstrp INTO gw_zcsl-gstrp
*      FROM afko
*      WHERE aufnr = gw_afpo-aufnr.

    gw_zcsl-zcsl = gw_zcsl-psmng - gw_zcsl-wemng.
    COLLECT gw_zcsl INTO gt_zcsl.
  ENDLOOP.
  SORT gt_zcsl BY werks matnr gstrp.

  "前1-7天出货量
  DATA:l_date_low  TYPE sy-datum,
       l_date_high TYPE sy-datum.
  l_date_low = sy-datum - 7.
  l_date_high = sy-datum." - 1.   "加当天出货数量

  SELECT lips~vbeln lips~posnr lips~werks lips~matnr lips~lfimg lips~vrkme likp~wadat_ist AS lfdat
    INTO CORRESPONDING FIELDS OF TABLE gt_lips
    FROM lips
    INNER JOIN likp
    ON likp~vbeln = lips~vbeln
    INNER JOIN vbuk
    ON vbuk~vbeln = lips~vbeln
    FOR ALL ENTRIES IN gt_matnr
    WHERE lips~werks = gt_matnr-werks
      AND lips~matnr = gt_matnr-matnr
      AND likp~lfart = ‘ZLF1‘
      AND likp~wadat_ist BETWEEN l_date_low AND l_date_high "WADAT_IST lfdat
      AND vbuk~wbstk = ‘C‘.
  "汇总出货量
  LOOP AT gt_lips INTO gw_lips.
    gw_chl-werks = gw_lips-werks.
    gw_chl-matnr = gw_lips-matnr.
    CLEAR gw_matnr.
    READ TABLE gt_matnr INTO gw_matnr WITH KEY matnr = gw_lips-matnr
                                               werks = gw_lips-werks
                                               BINARY SEARCH.
    CALL FUNCTION ‘MD_CONVERT_MATERIAL_UNIT‘
      EXPORTING
        i_matnr              = gw_lips-matnr
        i_in_me              = gw_lips-vrkme
        i_out_me             = gw_matnr-frtme
        i_menge              = gw_lips-lfimg
      IMPORTING
        e_menge              = gw_lips-lfimg
      EXCEPTIONS
        error_in_application = 1
        error                = 2
        OTHERS               = 3.
    IF sy-subrc <> 0.
* Implement suitable error handling here
    ENDIF.

    CLEAR g_ts.
    CALL FUNCTION ‘FIMA_DAYS_AND_MONTHS_AND_YEARS‘
      EXPORTING
        i_date_from = gw_lips-lfdat
        i_date_to   = sy-datum
      IMPORTING
        e_days      = g_ts.

    CASE g_ts.
      WHEN ‘0‘.
        gw_chl-zq0tchl = gw_lips-lfimg.
      WHEN ‘1‘.
        gw_chl-zq1tchl = gw_lips-lfimg.
      WHEN ‘2‘.
        gw_chl-zq2tchl = gw_lips-lfimg.
      WHEN ‘3‘.
        gw_chl-zq3tchl = gw_lips-lfimg.
      WHEN ‘4‘.
        gw_chl-zq4tchl = gw_lips-lfimg.
      WHEN ‘5‘.
        gw_chl-zq5tchl = gw_lips-lfimg.
      WHEN ‘6‘.
        gw_chl-zq6tchl = gw_lips-lfimg.
      WHEN ‘7‘.
        gw_chl-zq7tchl = gw_lips-lfimg.
      WHEN OTHERS.
    ENDCASE.
    COLLECT gw_chl INTO gt_chl.
    CLEAR gw_chl.
  ENDLOOP.

  "日提货计划
  CLEAR l_datum.
  l_datum = sy-datum + 1.
  SELECT * INTO CORRESPONDING FIELDS OF TABLE lt_rxsjh
    FROM ztsd_rxsjh
    FOR ALL ENTRIES IN gt_matnr
    WHERE zwerks = gt_matnr-werks
      AND zjhqj = l_datum
      AND zmatnr = gt_matnr-matnr.
  SORT lt_rxsjh BY zwerks zvkorg zjhqj zmatnr zbanbe DESCENDING.
  DELETE ADJACENT DUPLICATES FROM lt_rxsjh COMPARING  zwerks zvkorg zjhqj zmatnr.
  "汇总日销售计划量
  CLEAR:gw_rxsjh,gt_rxsjh.
  LOOP AT lt_rxsjh INTO lw_rxsjh.
    gw_rxsjh-zwerks = lw_rxsjh-zwerks.
    gw_rxsjh-zjhqj = lw_rxsjh-zjhqj.
    gw_rxsjh-zmatnr = lw_rxsjh-zmatnr.

    CLEAR gw_matnr.
    READ TABLE gt_matnr INTO gw_matnr WITH KEY matnr = gw_rxsjh-zmatnr
                                               werks = gw_rxsjh-zwerks
                                               BINARY SEARCH.
    CALL FUNCTION ‘MD_CONVERT_MATERIAL_UNIT‘
      EXPORTING
        i_matnr              = gw_matnr-matnr
        i_in_me              = lw_rxsjh-zmeins
        i_out_me             = gw_matnr-frtme
        i_menge              = lw_rxsjh-zxjhsl1
      IMPORTING
        e_menge              = gw_rxsjh-zxjhsl1
      EXCEPTIONS
        error_in_application = 1
        error                = 2
        OTHERS               = 3.
    CALL FUNCTION ‘MD_CONVERT_MATERIAL_UNIT‘
      EXPORTING
        i_matnr              = gw_matnr-matnr
        i_in_me              = lw_rxsjh-zmeins
        i_out_me             = gw_matnr-frtme
        i_menge              = lw_rxsjh-zxjhsl2
      IMPORTING
        e_menge              = gw_rxsjh-zxjhsl2
      EXCEPTIONS
        error_in_application = 1
        error                = 2
        OTHERS               = 3.
    CALL FUNCTION ‘MD_CONVERT_MATERIAL_UNIT‘
      EXPORTING
        i_matnr              = gw_matnr-matnr
        i_in_me              = lw_rxsjh-zmeins
        i_out_me             = gw_matnr-frtme
        i_menge              = lw_rxsjh-zxjhsl3
      IMPORTING
        e_menge              = gw_rxsjh-zxjhsl3
      EXCEPTIONS
        error_in_application = 1
        error                = 2
        OTHERS               = 3.

    "MODIFY gt_rxsjh FROM gw_rxsjh TRANSPORTING zxjhsl1 zxjhsl2 zxjhsl3.
    COLLECT gw_rxsjh INTO gt_rxsjh.
  ENDLOOP.
ENDFORM.                    " FRM_GET_DATA
*&---------------------------------------------------------------------*
*&      Form  FRM_PROCESS_DATA
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_process_data .
  DATA:l_begin_d TYPE sy-datum,
       l_end_d   TYPE sy-datum.
  DATA:l_times TYPE i,
       l_sqr   TYPE i.

  IF s_gstrp-high IS INITIAL.
    l_end_d = s_gstrp-low.
  ELSE.
    l_end_d = s_gstrp-high.
  ENDIF.

  SORT gt_afpo BY matnr dwerk gstrp aufnr.
  SORT gt_makt BY matnr.
  SORT gt_gylx BY matnr werks.
  SORT gt_wqddsl BY matnr werks.
  SORT gt_dqkcsl BY matnr werks.
  SORT gt_zcsl BY matnr werks gstrp.
  SORT gt_chl BY matnr werks.
  SORT gt_rxsjh BY zmatnr zwerks."zvkorg.

  LOOP AT gt_matnr INTO gw_matnr.
    l_begin_d = s_gstrp-low.
    CLEAR l_times.
    DO.
      l_times = l_times + 1.
      IF l_begin_d GT l_end_d.
        EXIT.
      ENDIF.
      gw_output-gstrp = l_begin_d.
      gw_output-werks = gw_matnr-werks.
      gw_output-matnr = gw_matnr-matnr.
      gw_output-auart = gw_matnr-auart.
      gw_output-eisbe = gw_matnr-eisbe.  "安全库存
      CALL FUNCTION ‘MD_CONVERT_MATERIAL_UNIT‘
        EXPORTING
          i_matnr              = gw_matnr-matnr
          i_in_me              = gw_matnr-meins
          i_out_me             = gw_matnr-frtme
          i_menge              = gw_output-eisbe
        IMPORTING
          e_menge              = gw_output-eisbe
        EXCEPTIONS
          error_in_application = 1
          error                = 2
          OTHERS               = 3.

      gw_output-frtme = gw_matnr-frtme.  "生产单位
      READ TABLE gt_makt INTO gw_makt WITH KEY matnr = gw_matnr-matnr BINARY SEARCH.
      IF sy-subrc = 0.
        gw_output-maktx = gw_makt-maktx.
      ENDIF.
      "生产订单号和生产订单数量
      CLEAR gw_afpo.
      READ TABLE gt_afpo INTO gw_afpo WITH KEY matnr = gw_matnr-matnr
                                               dwerk = gw_matnr-werks
                                               gstrp = l_begin_d
                                               BINARY SEARCH.
      IF sy-subrc = 0.
        gw_output-aufnr = gw_afpo-aufnr.
        gw_output-psmng = gw_afpo-psmng.

        CLEAR:g_fname,gw_tline,gt_tline.

        CONCATENATE sy-mandt gw_output-aufnr INTO g_fname.
        CALL FUNCTION ‘READ_TEXT‘
          EXPORTING
            id                      = ‘KOPF‘
            language                = sy-langu
            name                    = g_fname
            object                  = ‘AUFK‘
          TABLES
            lines                   = gt_tline
          EXCEPTIONS
            id                      = 1
            language                = 2
            name                    = 3
            not_found               = 4
            object                  = 5
            reference_check         = 6
            wrong_access_to_archive = 7
            OTHERS                  = 8.
        "原料来源
        READ TABLE gt_tline INTO gw_tline INDEX 1.
        IF sy-subrc = 0.
          gw_output-zylly = gw_tline-tdline.
        ENDIF.

      ENDIF.
      "工艺路线版本&工艺路线版本描述
      READ TABLE gt_gylx INTO gw_gylx WITH KEY matnr = gw_matnr-matnr
                                               werks = gw_matnr-werks
                                               BINARY SEARCH.
      IF sy-subrc = 0.
        gw_output-plnnr = gw_gylx-plnnr.
        gw_output-plnal = gw_gylx-plnal.
        gw_output-ktext = gw_gylx-ktext.
      ENDIF.
      "未清提单数量
      READ TABLE gt_wqddsl INTO gw_wqddsl WITH KEY matnr = gw_matnr-matnr
                                               werks = gw_matnr-werks
                                               BINARY SEARCH.
      IF sy-subrc = 0.
        gw_output-zwqddsl = gw_wqddsl-bmeng.
      ENDIF.
      "当前库存

      READ TABLE gt_dqkcsl INTO gw_dqkcsl WITH KEY matnr = gw_matnr-matnr
                                               werks = gw_matnr-werks
                                               BINARY SEARCH.
      IF sy-subrc = 0.
        gw_output-zdqkc = gw_dqkcsl-labst.
      ENDIF.

      "在产数量
      READ TABLE gt_zcsl INTO gw_zcsl WITH KEY matnr = gw_matnr-matnr
                                               werks = gw_matnr-werks
                                               gstrp = l_begin_d
                                               BINARY SEARCH.
      IF sy-subrc = 0.
        gw_output-zzcsl = gw_zcsl-zcsl.
      ENDIF.

      "后X天销售计划量
      CLEAR gw_rxsjh.
      READ TABLE gt_rxsjh INTO gw_rxsjh WITH KEY zmatnr = gw_matnr-matnr
                                                 zwerks = gw_matnr-werks
                                                 "zvkorg = gw_matnr-werks
                                   BINARY SEARCH.
      IF sy-subrc = 0.
        gw_output-zh1txsjhl = gw_rxsjh-zxjhsl1.
        gw_output-zh2txsjhl = gw_rxsjh-zxjhsl2.
        gw_output-zh3txsjhl = gw_rxsjh-zxjhsl3.
      ENDIF.

      IF l_times EQ 1.
        gw_output-zjyscsl = gw_output-zwqddsl + gw_output-zh1txsjhl - gw_output-zdqkc
                           - gw_output-zzcsl + gw_output-eisbe.
      ELSE.
        gw_output-zjyscsl =  gw_output-zh1txsjhl.
      ENDIF.
      IF  gw_output-zjyscsl LT 0.
        gw_output-zjyscsl = 0.
      ENDIF.
      "出货数量
      CLEAR gw_chl.
      READ TABLE gt_chl INTO gw_chl WITH KEY matnr = gw_matnr-matnr
                                               werks = gw_matnr-werks
                                               BINARY SEARCH.
      IF sy-subrc = 0.
        gw_output-zq0tchl = gw_chl-zq0tchl.
        gw_output-zq1tchl = gw_chl-zq1tchl.
        gw_output-zq2tchl = gw_chl-zq2tchl.
        gw_output-zq3tchl = gw_chl-zq3tchl.
        gw_output-zq4tchl = gw_chl-zq4tchl.
        gw_output-zq5tchl = gw_chl-zq5tchl.
        gw_output-zq6tchl = gw_chl-zq6tchl.
        gw_output-zq7tchl = gw_chl-zq7tchl.
      ENDIF.

      APPEND gw_output TO gt_output.
      CLEAR gw_output.

      l_sqr = l_sqr + 1.
      l_begin_d = l_begin_d + 1.
    ENDDO.
  ENDLOOP.

  IF p_rb1 EQ ‘X‘.
    DELETE gt_output WHERE zjyscsl EQ 0.
  ENDIF.

  l_sqr = 0.
  LOOP AT gt_output INTO gw_output.
    l_sqr = l_sqr + 1.
    gw_output-sqr = l_sqr.

    IF gw_output-aufnr IS NOT INITIAL.
      gw_style-style = cl_gui_alv_grid=>mc_style_disabled. " 设置为不可编辑状态
      gw_style-fieldname = ‘AUART‘. " 需要编辑的列名
      APPEND gw_style TO gw_output-style.
      gw_style-fieldname = ‘PLNAL‘. " 需要编辑的列名
      APPEND gw_style TO gw_output-style.
      gw_style-fieldname = ‘PLNNR‘. " 需要编辑的列名
      APPEND gw_style TO gw_output-style.
      gw_style-fieldname = ‘ZJYSCSL‘. " 需要编辑的列名
      APPEND gw_style TO gw_output-style.
      gw_style-fieldname = ‘ZYLLY‘. " 需要编辑的列名
      APPEND gw_style TO gw_output-style.
    ENDIF.
    MODIFY gt_output FROM gw_output TRANSPORTING sqr style.
  ENDLOOP.

ENDFORM.                    " FRM_PROCESS_DATA
*&---------------------------------------------------------------------*
*&      Form  FRM_DISPLAY_ALV
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_display_alv .
  PERFORM frm_build_fieldcat.

  gw_layout-zebra = ‘X‘.
  gw_layout-cwidth_opt = ‘X‘.
  gw_layout-stylefname = ‘STYLE‘.

  gw_events-name = ‘CALLER_EXIT‘.   "slis_ev_caller_exit_at_start事件 调用来获取ALV对象并注册回车事件
  gw_events-form = ‘FRM_CALLER_EXIT‘.
  APPEND gw_events TO gt_events.

  CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY_LVC‘
    EXPORTING
      i_callback_program       = sy-repid
      i_callback_pf_status_set = ‘FRM_PF_STATUS_SET‘
      i_callback_user_command  = ‘FRM_USER_COMMAND‘
      "i_grid_settings          = gw_setting
      is_layout_lvc            = gw_layout
      it_fieldcat_lvc          = gt_fieldcat
   "  it_sort_lvc              = gt_sort
      it_events                = gt_events
      i_default                = ‘X‘
      i_save                   = ‘A‘
    TABLES
      t_outtab                 = gt_output
    EXCEPTIONS
      program_error            = 1
      OTHERS                   = 2.
  IF sy-subrc <> 0.
* Implement suitable error handling here
  ENDIF.

ENDFORM.                    " FRM_DISPLAY_ALV
*&---------------------------------------------------------------------*
*&      Form  FRM_BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_build_fieldcat .
  mcr_fieldcat:‘ZSEL‘ ‘选择‘ ‘X‘ ‘‘ ‘‘,
               ‘ICON‘ ‘状态‘ ‘‘ ‘ICON‘ ‘ID‘,
               ‘MSG‘ ‘消息‘ ‘‘ ‘‘ ‘‘,
               ‘AUFNR‘ ‘生产订单号‘ ‘‘ ‘AUFK‘ ‘AUFNR‘,
               ‘SQR‘ ‘序号‘ ‘‘ ‘‘ ‘‘,
               ‘GSTRP‘ ‘计划生产日期‘ ‘‘ ‘‘ ‘‘,
               ‘PSMNG‘ ‘生产订单数量‘ ‘‘ ‘‘ ‘‘,
               ‘WERKS‘ ‘工厂‘ ‘‘ ‘MARC‘ ‘WERKS‘,
               ‘MATNR‘ ‘物料编码‘ ‘‘ ‘MARC‘ ‘MATNR‘,
               ‘MAKTX‘ ‘物料描述‘ ‘‘ ‘‘ ‘‘,
               ‘AUART‘ ‘订单类型‘ ‘X‘ ‘T438M‘ ‘AUART‘,
               ‘PLNNR‘ ‘组‘ ‘X‘ ‘MAPL‘ ‘PLNNR‘,   "工艺路线版本编码
               ‘PLNAL‘ ‘组计算器‘ ‘X‘ ‘MAPL‘ ‘PLNAL‘,
               ‘KTEXT‘ ‘工艺路线版本描述‘ ‘‘ ‘‘ ‘‘,
               ‘ZWQDDSL‘ ‘未清提单数量‘ ‘‘ ‘‘ ‘‘,
               ‘ZH1TXSJHL‘ ‘后1天销售计划量‘ ‘‘ ‘‘ ‘‘,
               ‘ZH2TXSJHL‘ ‘后2天销售计划量‘ ‘‘ ‘‘ ‘‘,
               ‘ZH3TXSJHL‘ ‘后3天销售计划量‘ ‘‘ ‘‘ ‘‘,
               ‘ZDQKC‘ ‘当前库存‘ ‘‘ ‘‘ ‘‘,
               ‘ZZCSL‘ ‘在产数量‘ ‘‘ ‘‘ ‘‘,
               ‘EISBE‘ ‘安全库存‘ ‘‘ ‘‘ ‘‘,
               ‘ZJYSCSL‘ ‘建议生产数量‘ ‘X‘ ‘VBEP‘ ‘BMENG‘,
               ‘FRTME‘ ‘单位‘ ‘‘ ‘MARC‘ ‘FRTME‘,
               ‘ZYLLY‘ ‘原料来源‘ ‘X‘ ‘‘ ‘‘,
               ‘ZQ0TCHL‘ ‘当天出货数量‘ ‘‘ ‘‘ ‘‘,
               ‘ZQ1TCHL‘ ‘前1天出货数量‘ ‘‘ ‘‘ ‘‘,
               ‘ZQ2TCHL‘ ‘前2天出货数量‘ ‘‘ ‘‘ ‘‘,
               ‘ZQ3TCHL‘ ‘前3天出货数量‘ ‘‘ ‘‘ ‘‘,
               ‘ZQ4TCHL‘ ‘前4天出货数量‘ ‘‘ ‘‘ ‘‘,
               ‘ZQ5TCHL‘ ‘前5天出货数量‘ ‘‘ ‘‘ ‘‘,
               ‘ZQ6TCHL‘ ‘前6天出货数量‘ ‘‘ ‘‘ ‘‘,
               ‘ZQ7TCHL‘ ‘前7天出货数量‘ ‘‘ ‘‘ ‘‘.
*               ‘ZQ1TXSJHL‘ ‘前1天销售计划量‘ ‘‘ ‘‘ ‘‘,
*               ‘ZQ2TXSJHL‘ ‘前2天销售计划量‘ ‘‘ ‘‘ ‘‘,
*               ‘ZQ3TXSJHL‘ ‘前3天销售计划量‘ ‘‘ ‘‘ ‘‘,
*               ‘ZQ4TXSJHL‘ ‘前4天销售计划量‘ ‘‘ ‘‘ ‘‘,
*               ‘ZQ5TXSJHL‘ ‘前5天销售计划量‘ ‘‘ ‘‘ ‘‘,
*               ‘ZQ6TXSJHL‘ ‘前6天销售计划量‘ ‘‘ ‘‘ ‘‘,
*               ‘ZQ7TXSJHL‘ ‘前7天销售计划量‘ ‘‘ ‘‘ ‘‘.
ENDFORM.                    " FRM_BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*&      Form  FRM_AUTH_CHECK
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_auth_check .
  AUTHORITY-CHECK OBJECT ‘C_AFKO_AWA‘
           ID ‘ACTVT‘  DUMMY
           ID ‘AUTYP‘ DUMMY
           ID ‘AUFART‘ DUMMY
           ID ‘WERKS‘ FIELD s_werks-low .
  IF sy-subrc <> 0.
    MESSAGE e000 WITH ‘没有工厂‘ s_werks-low ‘权限‘.
  ENDIF.

ENDFORM.                    " FRM_AUTH_CHECK

FORM frm_pf_status_set USING rt_extab TYPE slis_t_extab.
  SET PF-STATUS ‘STANDARD_FULLSCREEN‘.
ENDFORM.

FORM frm_user_command USING r_ucomm LIKE sy-ucomm rs_selfield TYPE slis_selfield.

  CALL METHOD g_grid->check_changed_data.
  CLEAR:gt_message[].
  CASE r_ucomm.
    WHEN ‘ALL‘.
      gw_output-zsel = ‘X‘.
      MODIFY gt_output FROM gw_output TRANSPORTING zsel WHERE zsel NE ‘X‘.
    WHEN ‘DALL‘.
      CLEAR gw_output-zsel.
      MODIFY gt_output FROM gw_output TRANSPORTING zsel WHERE zsel EQ ‘X‘.
    WHEN ‘CREATE‘.
      PERFORM frm_create_prodord.
    WHEN ‘SCBCAP‘.
      PERFORM frm_scbcap.
    WHEN ‘CHANGE‘.
      PERFORM frm_change_prodord.
    WHEN ‘KCXQQD‘.
      PERFORM frm_kcxqqd.
    WHEN ‘BACK‘ OR ‘EXIT‘ OR ‘CANC‘.
      LEAVE SCREEN.
    WHEN OTHERS.
  ENDCASE.
  " rs_selfield-refresh = ‘X‘.   "刷新ALV

*   稳定刷新
  g_stbl-row = ‘X‘." 基于行的稳定刷新
  g_stbl-col = ‘X‘." 基于列稳定刷新
  CALL METHOD g_grid->refresh_table_display
    EXPORTING
      is_stable = g_stbl.

  IF gt_message[] IS NOT INITIAL.
    CALL FUNCTION ‘USMD_MESSAGE_POPUP‘
      EXPORTING
        it_message        = gt_message[]
        if_save_necessary = gv_necessary.
  ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  FRM_CREATE_PRODORD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_create_prodord .
  DATA:lt_output LIKE TABLE OF gw_output.
  DATA:gs_keko TYPE keko.

  CALL METHOD g_grid->check_changed_data
*    IMPORTING
*      e_valid   =
*    CHANGING
*      c_refresh = ‘X‘
    .
  CLEAR:gw_order,gt_order,lt_output,gt_message[].
  LOOP AT gt_output INTO gw_output WHERE aufnr IS INITIAL
                                     AND zjyscsl GT 0
                                     AND zsel EQ ‘X‘.
    gw_orderdata-material = gw_output-matnr.
    gw_orderdata-plant = gw_output-werks.
    gw_orderdata-order_type = gw_output-auart.
    gw_orderdata-basic_start_date = gw_output-gstrp.
    gw_orderdata-basic_end_date = gw_output-gstrp.
    gw_orderdata-quantity = gw_output-zjyscsl.
    gw_orderdata-quantity_uom = gw_output-frtme.
    gw_orderdata-routing_type = ‘N‘.
    gw_orderdata-routing_group = gw_output-plnnr.
    gw_orderdata-routing_counter = gw_output-plnal.

    "add by ly 20151124
    SELECT SINGLE * INTO CORRESPONDING FIELDS OF gs_keko
      FROM keko WHERE matnr = gw_output-matnr
      AND werks = gw_output-werks
      AND bwkey = gw_output-werks
      AND kadat LE sy-datum
      AND bidat GE sy-datum
      AND freig = ‘X‘.
    IF sy-subrc <> 0.
      gs_message-msgid = ‘ZPP‘.
      gs_message-msgty = ‘E‘.
      gs_message-msgno = ‘000‘.
      gs_message-msgv1 = ‘物料‘.
      gs_message-msgv2 = gw_output-matnr.
      gs_message-msgv3 = ‘未下达标准成本估算!‘.
      APPEND gs_message TO gt_message.
      CONTINUE.
    ENDIF.
    "add by ly 20151124

    CLEAR:gw_return,g_aufnr.
    CALL FUNCTION ‘BAPI_PRODORD_CREATE‘
      EXPORTING
        orderdata    = gw_orderdata
      IMPORTING
        return       = gw_return
        order_number = g_aufnr
      " ORDER_TYPE   =
      .
    IF g_aufnr IS NOT INITIAL.
*      CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT‘
*        EXPORTING
*          wait = ‘X‘.

      gw_output-aufnr = g_aufnr.
      gw_output-psmng = gw_output-zjyscsl.

      gw_output-icon = icon_led_green.

      gw_order-order_number = gw_output-aufnr.
      APPEND gw_order TO gt_order.
      APPEND gw_output TO lt_output.
    ELSE.
*      CALL FUNCTION ‘BAPI_TRANSACTION_ROLLBACK‘.
*
*      gw_output-icon = icon_led_red.
    ENDIF.

    gw_output-msg = gw_return-message.

    IF gw_output-aufnr IS NOT INITIAL.
      gw_style-style = cl_gui_alv_grid=>mc_style_disabled. " 设置为不可编辑状态
      gw_style-fieldname = ‘AUART‘. " 需要编辑的列名
      APPEND gw_style TO gw_output-style.
      gw_style-fieldname = ‘PLNAL‘. " 需要编辑的列名
      APPEND gw_style TO gw_output-style.
      gw_style-fieldname = ‘PLNNR‘. " 需要编辑的列名
      APPEND gw_style TO gw_output-style.
      gw_style-fieldname = ‘ZJYSCSL‘. " 需要编辑的列名
      APPEND gw_style TO gw_output-style.
      gw_style-fieldname = ‘ZYLLY‘. " 需要编辑的列名
      APPEND gw_style TO gw_output-style.
    ENDIF.

    MODIFY gt_output FROM gw_output.
  ENDLOOP.

  IF gt_order IS NOT INITIAL.
    WAIT UP TO 5 SECONDS.
    LOOP AT lt_output INTO gw_output.
      IF gw_output-zylly IS NOT INITIAL.
        CONCATENATE sy-mandt gw_output-aufnr INTO g_fname.
        CLEAR:gw_tline,gt_tline.
        gw_tline-tdline = gw_output-zylly.
        APPEND gw_tline TO gt_tline.
        CALL FUNCTION ‘CREATE_TEXT‘
          EXPORTING
            fid       = ‘KOPF‘
            flanguage = sy-langu
            fname     = g_fname
            fobject   = ‘AUFK‘
          TABLES
            flines    = gt_tline
          EXCEPTIONS
            no_init   = 1
            no_save   = 2
            OTHERS    = 3.
        IF sy-subrc = 0.
          UPDATE aufk SET ltext = 1 WHERE aufnr = gw_output-aufnr.
        ENDIF.
      ENDIF.
    ENDLOOP.

    CALL FUNCTION ‘BAPI_PRODORD_RELEASE‘
      TABLES
        orders = gt_order.
    CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT‘
      EXPORTING
        wait = ‘X‘.
  ENDIF.

*  IF gt_message[] IS NOT INITIAL.
*    CALL FUNCTION ‘USMD_MESSAGE_POPUP‘
*      EXPORTING
*        it_message        = gt_message[]
*        if_save_necessary = gv_necessary.
*  ENDIF.
ENDFORM.                    " FRM_CREATE_PRODORD
*&---------------------------------------------------------------------*
*&      Form  FRM_CHANGE_PRODORD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_change_prodord .
*  CLEAR gt_row.
*  CALL METHOD g_grid->get_selected_rows
*    IMPORTING
*      et_index_rows = gt_row
**     et_row_no     =
*    .
*  READ TABLE gt_row INTO gw_row INDEX 1.
*  IF sy-subrc NE 0.
*    MESSAGE s000 WITH ‘请选择一条数据‘ DISPLAY LIKE ‘E‘.
*    RETURN.
*  ENDIF.
*
*  READ TABLE gt_output INTO gw_output INDEX gw_row-index.

  READ TABLE gt_output INTO gw_output WITH KEY zsel = ‘X‘.
  IF sy-subrc NE 0.
    MESSAGE s000 WITH ‘请选择一条数据‘ DISPLAY LIKE ‘E‘.
    RETURN.
  ENDIF.

  IF gw_output-aufnr IS INITIAL.
    MESSAGE s000 WITH ‘生产订单为空,请先创建生产订单‘ DISPLAY LIKE ‘E‘.
    RETURN.
  ENDIF.

  SET PARAMETER ID ‘ANR‘ FIELD gw_output-aufnr.

  CALL TRANSACTION ‘CO02‘ AND SKIP FIRST SCREEN.
ENDFORM.                    " FRM_CHANGE_PRODORD
*&---------------------------------------------------------------------*
*&      Form  FRM_KCXQQD
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_kcxqqd .
*  CLEAR gt_row.
*  CALL METHOD g_grid->get_selected_rows
*    IMPORTING
*      et_index_rows = gt_row
**     et_row_no     =
*    .
*  READ TABLE gt_row INTO gw_row INDEX 1.
*  IF sy-subrc NE 0.
*    MESSAGE s000 WITH ‘请选择一条数据‘ DISPLAY LIKE ‘E‘.
*    RETURN.
*  ENDIF.
*
*  READ TABLE gt_output INTO gw_output INDEX gw_row-index.
  READ TABLE gt_output INTO gw_output WITH KEY zsel = ‘X‘.
  IF sy-subrc NE 0.
    MESSAGE s000 WITH ‘请选择一条数据‘ DISPLAY LIKE ‘E‘.
    RETURN.
  ENDIF.

  SET PARAMETER ID ‘MAT‘ FIELD gw_output-matnr.
  SET PARAMETER ID ‘WRK‘ FIELD gw_output-werks.

  CALL TRANSACTION ‘MD04‘ AND SKIP FIRST SCREEN.
ENDFORM.                    " FRM_KCXQQD

FORM frm_caller_exit  USING e_grid TYPE slis_data_caller_exit.
  CALL FUNCTION ‘GET_GLOBALS_FROM_SLVC_FULLSCR‘
    IMPORTING
      e_grid = g_grid.

  " 设置enter事件
  CALL METHOD g_grid->register_edit_event
    EXPORTING
      i_event_id = cl_gui_alv_grid=>mc_evt_enter
    EXCEPTIONS
      error      = 1
      OTHERS     = 2.

* 设置 单光标焦点移开被修改单元格后既触发事件
*  CALL METHOD g_grid->register_edit_event
*    EXPORTING
*      i_event_id = cl_gui_alv_grid=>mc_evt_modified
*    EXCEPTIONS
*      error      = 1
*      OTHERS     = 2.
  CLEAR gw_f4.
  gw_f4-fieldname = ‘PLNNR‘.
  gw_f4-register = ‘X‘.
  gw_f4-chngeafter = ‘X‘.
  APPEND gw_f4 TO gt_f4.
  CALL METHOD g_grid->register_f4_for_fields
    EXPORTING
      it_f4 = gt_f4[].

  CREATE OBJECT gt_event_receiver.
*  SET HANDLER   gt_event_receiver->handle_modify FOR g_grid.
  SET HANDLER gt_event_receiver->handle_onf4 FOR g_grid.
ENDFORM.

INCLUDE zppr002_module.
*&---------------------------------------------------------------------*
*&      Form  FRM_UNIT_CONVERT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_GW_MATNR_MATNR  text
*      -->P_GW_MATNR_FRTME  text
*      -->P_GW_WQDD_VRKME  text
*      -->P_GW_WQDD_BMENG  text
*----------------------------------------------------------------------*
FORM frm_unit_convert  USING    p_matnr
                                p_in_unit
                                p_out_unit
                                p_in_sl
                       CHANGING c_out_sl.

ENDFORM.                    " FRM_UNIT_CONVERT
*&---------------------------------------------------------------------*
*&      Form  FRM_SCBCAP
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_scbcap .
*  CLEAR gt_row.
*  CALL METHOD g_grid->get_selected_rows
*    IMPORTING
*      et_index_rows = gt_row
**     et_row_no     =
*    .
*  READ TABLE gt_row INTO gw_row INDEX 1.
*  IF sy-subrc NE 0.
*    MESSAGE s000 WITH ‘请选择一条数据‘ DISPLAY LIKE ‘E‘.
*    RETURN.
*  ENDIF.
*
*  READ TABLE gt_output INTO gw_output INDEX gw_row-index.

  READ TABLE gt_output INTO gw_output WITH KEY zsel = ‘X‘.
  IF sy-subrc NE 0.
    MESSAGE s000 WITH ‘请选择一条数据‘ DISPLAY LIKE ‘E‘.
    RETURN.
  ENDIF.

  IF gw_output-aufnr IS INITIAL.
    MESSAGE s000 WITH ‘生产订单编号为空,请先创建生产订单‘ DISPLAY LIKE ‘E‘.
    RETURN.
  ELSE.
    CALL SCREEN 100 STARTING AT 30 5 ENDING AT 65 13.
  ENDIF.
ENDFORM.                    " FRM_SCBCAP
*&---------------------------------------------------------------------*
*&      Form  FRM_QD_SCBC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_qd_scbc .

  PERFORM frm_save_longtext.
ENDFORM.                    " FRM_QD_SCBC
*&---------------------------------------------------------------------*
*&      Form  FRM_SAVE_LONGTEXT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_save_longtext .
  DATA:l_sl    TYPE char20,
       l_mseh3 TYPE t006a-mseh3.

  IF ( g_jb + g_yb + g_bb ) GT gw_output-psmng.
    MESSAGE s000 WITH ‘生产订单‘ gw_output-aufnr ‘班次安排的数量之和要小于订单数量‘ DISPLAY LIKE ‘E‘.
    LEAVE SCREEN .
  ENDIF.

  CONCATENATE sy-mandt gw_output-aufnr INTO g_fname.

  CLEAR l_mseh3.
  SELECT SINGLE mseh3 INTO l_mseh3
    FROM t006a
    WHERE spras = sy-langu
      AND msehi = gw_output-frtme.

  CLEAR:gw_tline,gt_tline.
  gw_tline-tdline = gw_output-zylly.
  APPEND gw_tline TO gt_tline.

  l_sl = g_jb.
  SHIFT l_sl LEFT DELETING LEADING space.
  CONCATENATE ‘甲班‘ l_sl l_mseh3 INTO gw_tline-tdline SEPARATED BY ‘-‘.
  APPEND gw_tline TO gt_tline.

  l_sl = g_yb.
  SHIFT l_sl LEFT DELETING LEADING space.
  CONCATENATE ‘乙班‘ l_sl l_mseh3 INTO gw_tline-tdline SEPARATED BY ‘-‘.
  APPEND gw_tline TO gt_tline.
  l_sl = g_bb.
  SHIFT l_sl LEFT DELETING LEADING space.
  CONCATENATE ‘丙班‘ l_sl l_mseh3 INTO gw_tline-tdline SEPARATED BY ‘-‘.
  APPEND gw_tline TO gt_tline.

  CALL FUNCTION ‘CREATE_TEXT‘
    EXPORTING
      fid       = ‘KOPF‘
      flanguage = sy-langu
      fname     = g_fname
      fobject   = ‘AUFK‘
    TABLES
      flines    = gt_tline
    EXCEPTIONS
      no_init   = 1
      no_save   = 2
      OTHERS    = 3.
  IF sy-subrc EQ 0.

    UPDATE aufk SET ltext = 1 WHERE aufnr = gw_output-aufnr.

    MESSAGE s000 WITH ‘生产订单‘ gw_output-aufnr ‘班次已安排‘.

  ELSE.
    MESSAGE s000 WITH ‘生产订单‘ gw_output-aufnr ‘班次安排失败‘ DISPLAY LIKE ‘E‘.
  ENDIF.

  LEAVE TO SCREEN 0.
ENDFORM.                    " FRM_SAVE_LONGTEXT
*&---------------------------------------------------------------------*
*&      Form  FRM_GET_BC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_get_bc .
  DATA:l_index TYPE i,
       l_zbc   TYPE string,
       l_menge TYPE string,
       l_meins TYPE string.

  CLEAR:g_fname,gw_tline,gt_tline.

  CONCATENATE sy-mandt gw_output-aufnr INTO g_fname.
  CALL FUNCTION ‘READ_TEXT‘
    EXPORTING
      id                      = ‘KOPF‘
      language                = sy-langu
      name                    = g_fname
      object                  = ‘AUFK‘
    TABLES
      lines                   = gt_tline
    EXCEPTIONS
      id                      = 1
      language                = 2
      name                    = 3
      not_found               = 4
      object                  = 5
      reference_check         = 6
      wrong_access_to_archive = 7
      OTHERS                  = 8.

  CLEAR:g_jb,g_yb,g_bb.
  LOOP AT gt_tline INTO gw_tline.
    CLEAR:l_zbc,l_menge,l_meins.
    SPLIT gw_tline-tdline AT ‘-‘ INTO l_zbc l_menge l_meins.
    CASE l_zbc.
      WHEN ‘甲班‘.
        g_jb = l_menge.
      WHEN ‘乙班‘.
        g_yb = l_menge.
      WHEN ‘丙班‘.
        g_bb = l_menge.
      WHEN OTHERS.
    ENDCASE.
  ENDLOOP.

*  IF g_jb IS NOT INITIAL OR g_yb IS NOT INITIAL AND g_bb IS NOT INITIAL.
*  "READ TABLE gt_order WITH KEY order_number = gw_output-aufnr TRANSPORTING NO FIELDS.
*  "IF sy-subrc NE 0.
*    LOOP AT SCREEN.
*      IF screen-name = ‘G_JB‘ OR screen-name = ‘G_YB‘ OR screen-name = ‘G_BB‘ .
*        screen-input = 0.
*      ELSEIF  screen-name = ‘QUEDING‘ .
*        screen-input = 0.
*        screen-invisible = 0.
*      ENDIF.
*      MODIFY SCREEN.
*    ENDLOOP.
*  ENDIF.
ENDFORM.                    " FRM_GET_BC

FORM frm_plnnr TABLES it_shlp STRUCTURE seahlpres
CHANGING r_shlp TYPE shlp_descr_t
r_callcontrol LIKE ddshf4ctrl.
  DATA: ls_interface TYPE ddshiface.
  DATA: l_tabix TYPE sy-tabix.

  LOOP AT r_shlp-interface INTO ls_interface.
    l_tabix = sy-tabix.
    IF ls_interface-valfield IS INITIAL.
      ls_interface-valfield = ls_interface-shlpfield.

      MODIFY r_shlp-interface FROM ls_interface INDEX l_tabix.
    ENDIF.
  ENDLOOP.
ENDFORM.
时间: 2024-10-27 12:25:09

生产排产表DL-ZPPR002的相关文章

ERP系统个性化定制生产计划,简化排产流程

数字时代拼的就是"快",可作为生产型企业,你在生产环节是否经常遇到这样的难题:网站.电商.微信.门店订单接二连三,汇总起来手忙脚乱?加单.减单.插单时刻变化,生产计划和生产节奏频频打乱?马上到交期了,原材料还没到?仓库堆积如山,能用的没几样,保管起来苦不堪言,坏掉了损失惨重?-- 细细追究,所有这些问题,其实都是生产计划盲目.杂乱.无章惹的祸!作为企业管理软件领导品牌,智邦国际针对机械行业生产计划管理痛点,将最新AI技术无缝植入erp系统,带来新一代的智能生产计划管理模式:智能生产计划

ERP系统“数字排产”功能,实现企业高效排产

工厂车间的管理人员,如同坚守一线领兵打仗的将领,既要总揽全局指挥各部,又要运筹帷幄决胜千里,管理水平高低直接影响最终交付结果.无论客户.销售.采购.仓储.财务等内外环节,对生产部门的期望都很高.但对很多机械行业生产制造型企业来说,现实却很尴尬. 销售订单.采购进度.库存数量等信息,与生产部门严重脱节,而生产现场数据仅能依靠人工和纸质来回统计反馈,费时费力,时效性低,生产计划很难准确.与此同时,客户需求.订单数量.原料库存.工艺产线.设备人员等数据,时刻都在改变,用Excel表进行排产,计划赶不上

生产排程甘特图应用及绘制步骤

概述:甘特图(Gantt chart)是一种按照时间进度标出工作活动的图表,常用于项目管理,航空管理,生产排程等.甘特图(Gantt chart)也叫横道图.条状图.生产计划进度图. 甘特图(Gantt chart)是一种按照时间进度标出工作活动的图表,常用于项目管理,航空管理,生产排程等. 甘特图(Gantt chart)也叫横道图.条状图.生产计划进度图.它是在第一次世界大战时期发明的,以亨利·L·甘特先生的名字命名,他制定了一个完整地用条形图表进度的标志系统.甘特图内在思想简单,即以图示的

APS应用案例|纽威阀门实现高效排产

企业背景: 苏州纽威阀门股份有限公司(下文简称:纽威阀门)成立于1997年,总部设在江苏苏州.自成立以来一直致力于工业阀门的研发与制造,以为客户提供全套工业阀门解决方案为目标.纽威阀门通过企业的努力发展,已从16年前以12.5万元资本起家的民营企业,发展成为年生产能力达60万台,销售收入近20亿元的国内阀门行业的最大制造商,同时也成为了世界著名的工业阀门制造商. 一.企业信息化建设方面的现状 目前阀门市场总特点为"多品种.小批量.定制化生产",而当前纽威阀门的运营模式是100%按订单生

排产的两种方式(前推式与后拉式)在Optaplanner上的体现

生产计划的约束 在制定生产计划过程中,必然是存在某些制约因素,满足某些需求才能进行的,或是交期保证.或是产能限制.或是关键工序制约.即TOC理论 - 任何系统至少存在着一个制约因素/瓶颈:否则它就可能有无限的产出.就是说,如果不存在这个(或这些)制约因素,生产计划就没必要"排"了,只需随意地,毫无约束地把任意一个或多个生产任务纳入生产日程,都能满足生产.营业等所有业务要求.那也不需要人的智慧参投入其中了. 两种计划模式 而现实环境中,资源是有限的,且往往是在资源不足,并需要尽量满足制约

关于生产库的表空间是否自动扩展的看法?

我觉得 既然ORACLE设置了自动扩展 必然有其意图. 如何在生产环境使用手动还是自动呢? 主要看生产环境问题. 一是看业务产生的数据量的问题, 一次扩展数据文件大小多少,20M会不会太频繁,1G会不会磁盘操作时间太长. 自动扩展会影响下性能. 性能主要看你的硬件配置情况. 二手动扩展好处是 可以在业务低峰期扩大数据文件, 唯独麻烦的是管理麻烦,如果来不急人工添加数据文件,岂不是影响到业务的运营? 三是自动扩展,数据文件所在的硬盘是否足够,Linux下是32GB  会不会被其他文件所霸占掉? 注

基于hadoop (map/reduce)的大规模分布式并行计算生产排程系统的设计

map/reduce是大数据处理的技术,它的思路是把大规模数据分成一个个小数据块,每个数据块由一个map任务来处理,处理的中间结果汇总到reduce,最后生成最终的处理结果,这个处理和汇总的过程是可以反复多次的,也就是map-reduce-map-reduce 基于map/reduce的思路,我们可以设计基于hadoop(map/reduce)的大规模分布式并行计算生产排程系统,怎么样把大数据处理变成大规模分布式并行计算呢,就是我们不切分数据,每个map任务的数据都是相同的,每个map任务对排程

mysql 生产库大表delete

mysql 生产库大表删除 一般线上业务增长较快,造成某些表达到分表的临界值,表行数超过2000w且查询频繁,如表业务没有较多的聚合查询的话,可以考虑按时间归档部分历史数据.现推荐2种本人之前使用过的删除方式. 按照主键或者索引拆分后分段执行,使用存储过程 需要注意这种大表删除,如果是在主库执行,尽量把会话改成语句格式,以保证不会出现复制延迟 语句如下:set session binlog_format='STATEMENT'; CREATE PROCEDURE sp_delete_data()

APS传统生产计划数据连续更新管理排程排产

需求的不确定性使计划与现实之间存在偏差,因此必须进行控制,如果偏差过大,计划就要重新修改.“滑动范围窗”的计划方法就是这种计划-控制-修改的交互实施,计划范围被分成若干时间段,计划在1月份开始时制定,涵盖12个月,但只在第一个时段计划才真正被付诸实施.新的计划在第二个时段开始时重新制定,新计划考虑了第一个时段中的实际变化,并更新未来时段的预测.新计划的范围与原先的计划重叠,但延伸了一个时段,如此类推.在传统生产计划系统和APS中,这种方法是处理运作计划中不确定性的常用方法.另一种更有效地更新计划