Skip to Content

Consumption-based planning procedures use past consumption data to calculate future requirements.

The consumptions are automatically updated according to the movement types defined in OMJJ.

Sometimes, the consumption values need to be updated. For example, if you change the period indicator, the consumption records are reset to zero. In this case, the consumptions will need to be updated.

In the following screenshot, you will see how the consumtion values are reset when the period indicator is changed from M (monthly) to W (weekly).

SAP3.jpg.png

I would like to share a custom program that can be used to update the consumption history. It will let you to define the movement types and the period to be considered when the consumptions are updated in the forecasting view (table MVER).

This is the selection screen:

/wp-content/uploads/2014/09/sap4_532949.jpg

Note that you will need to enter the movement types. Its recommended to enter the same MTs used by SAP when the consumptions are automatically updated (check t-code OMJJ).

Once the program is executed you will get a simple log:

/wp-content/uploads/2014/09/sap5_532950.png

Note that after running the program, the consumption values are updated:

/wp-content/uploads/2014/09/sap8_532968.jpg

This is the code:

*———————————————————————–
*  Consulting2b SRL
*———————————————————————–
*  Program:        ZUPDATE_CONSUMPTIONS_AUTOMATIC
*  Type:           Report
*———————————————————————–
*  Created By:     Mariano Cabalen
*  Creation Date:  NOV/26/2008
*———————————————————————–
*  Description     Update Consumption Values from Movement types
*  Report.
*=======================================================================
*  Change Log
*  DATE                AUTHOR          TRANSPORT ORDER       DESCRIPTION
*  NOV/26/2008    CABALENM      XXXXXXXXXX                   Creation
*=======================================================================

REPORT  ZUPDATE_CONSUMPTIONS_AUTOMATIC NO STANDARD PAGE HEADING
                                      LINE-SIZE 132
                                      LINE-COUNT 65
                                      MESSAGE-ID PP.

************************************************************************
* TYPES and TYPE-POOLS                                                 *
************************************************************************
TYPE-POOLS: slis.

TYPES: BEGIN OF ty_data,
        MANDT     LIKE MVEG_UEB-MANDT,     ” Client
        MATNR     LIKE MVEG_UEB-MATNR,     ” Material
        WERKS     LIKE MVEG_UEB-WERKS,     ” Plant
        ERTAG     LIKE MVEG_UEB-ERTAG,     ” First day values ref.
        VBWRT     LIKE MVEG_UEB-VBWRT,     ” Consumption value
        MEINS     LIKE MARA-MEINS,         ” Base Unit of Measure
        PERKZ     LIKE MARC-PERKZ.         ” Period Indicator
TYPES: END OF ty_data.

TYPES: BEGIN OF ty_log,
        MANDT     LIKE MVEG_UEB-MANDT,     ” Client
        MATNR     LIKE MVEG_UEB-MATNR,     ” Material
        WERKS     LIKE MVEG_UEB-WERKS,     ” Plant
        STATUS(40) TYPE C.                 ” Status
TYPES: END OF ty_log.

************************************************************************
* CONSTANTS                                                            *
************************************************************************
CONSTANTS: c_1 TYPE c VALUE ‘1’,
           c_marca(5) TYPE c VALUE ‘MARCA’,
           c_x VALUE ‘X’.

************************************************************************
* Data                                                                 *
************************************************************************
DATA: it_data  TYPE STANDARD TABLE OF ty_data WITH HEADER LINE.
DATA: it_log  TYPE STANDARD TABLE OF ty_log WITH HEADER LINE.

**********data for the alv
DATA: gt_fieldcat TYPE slis_t_fieldcat_alv.
DATA: wa_layout TYPE slis_layout_alv.
DATA: v_repid LIKE sy-repid.

************************************************************************
* Tables                                                               *
************************************************************************
TABLES: mara, marc, mseg, mkpf.

************************************************************************
* SELECTION-SCREEN
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK a1 WITH FRAME TITLE text-001.
SELECT-OPTIONS:
            s_matnr FOR mara-matnr,
            s_mtart FOR mara-mtart,
            s_werks FOR marc-werks obligatory,
            s_dispo FOR marc-dispo,
            s_dismm FOR marc-dismm,
            s_lvorm FOR mara-lvorm,
            s_mstae FOR mara-mstae,
            s_lvor1 FOR marc-lvorm,
            s_mmsta FOR marc-mmsta.
SELECTION-SCREEN END OF BLOCK a1.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-002.
PARAMETERS:
            s_start like mkpf-cpudt obligatory,
            s_end like mkpf-cpudt obligatory.
SELECT-OPTIONS:
            s_bwart FOR mseg-bwart.
SELECTION-SCREEN END OF BLOCK b1.

************************************************************************
* START-OF-SELECTION Event                                             *
***********************************************************************
AT SELECTION-SCREEN.
START-OF-SELECTION.

      PERFORM get_data      TABLES it_data.

      IF sy-subrc NE 0 OR it_data[] IS INITIAL.
        MESSAGE I000 WITH text-E02.
      ELSE.
        SORT it_data BY MANDT MATNR WERKS ERTAG.
        CLEAR it_log.
        REFRESH it_log.
        LOOP AT it_data.
          IF it_data-mandt NE it_log-mandt OR
            it_data-matnr NE it_log-matnr OR
            it_data-werks NE it_log-werks.

            it_log-mandt = it_data-mandt.
            it_log-matnr = it_data-matnr.
            it_log-werks = it_data-werks.

*           Upload Consumption Values.
            PERFORM update_MVER     USING it_log-mandt
                                          it_log-matnr
                                          it_log-werks
                                          it_log-status.
            APPEND it_log.
          ENDIF.
        ENDLOOP.
      ENDIF.

      IF NOT it_log[] IS INITIAL.
        PERFORM alv.
      ELSE.
        MESSAGE I000 with Text-E04.
      ENDIF.

END-OF-SELECTION.

************************************************************************
*                       STAR OF FORMS                                  *
************************************************************************
*&———————————————————————*
*&      Form  get_data
*&———————————————————————*
*       text
*———————————————————————-*
FORM get_data TABLES  pit_data STRUCTURE  it_data.

  SELECT
        b~mandt                            ” Client
        b~matnr                            ” Material
        b~werks                            ” Plant
        a~budat                            ” First day values ref.
        b~menge                            ” Quantity
        b~meins                            ” Base Unit of Measure
        d~perkz                            ” Period Indicator
    INTO TABLE pit_data
    FROM mkpf AS a
        INNER JOIN mseg AS b ON a~mblnr EQ b~mblnr
                            AND a~mjahr EQ b~mjahr
        INNER JOIN mara AS c ON b~matnr EQ c~matnr
        INNER JOIN marc AS d ON b~matnr EQ d~matnr
                            AND b~werks EQ d~werks
    WHERE c~matnr IN s_matnr
      AND c~mtart IN s_mtart
      AND d~werks IN s_werks
      AND d~dispo IN s_dispo
      AND d~dismm IN s_dismm
      AND c~lvorm IN s_lvorm
      AND c~mstae IN s_mstae
      AND d~lvorm IN s_lvor1
      AND d~mmsta IN s_mmsta
      AND b~bwart IN s_bwart
      AND a~cpudt BETWEEN s_start AND s_end.

ENDFORM.                    ” get_data

*&——————————————————————*
*&      Form  update_MVER.
*&——————————————————————*
*                                                                   *
*                                                                   *
*——————————————————————-*
Form update_MVER        USING  Z_MANDT Z_MATNR Z_WERKS Z_STATUS.

************************************************************************
* DATA Declarations                                                    *
************************************************************************
  DATA: AMVEG_UEB  LIKE MVEG_UEB  OCCURS 0 WITH HEADER LINE.
  DATA: AMVEU_UEB  LIKE MVEU_UEB  OCCURS 0 WITH HEADER LINE.
  DATA: AMERRDAT_F LIKE MERRDAT_F OCCURS 0 WITH HEADER LINE.
  DATA: ROLLBACK_FLAG LIKE T130F-KZREF.
  DATA: X(1)       TYPE C VALUE ‘X’.
  DATA: s_keydate(8) TYPE N.
  DATA: z_total like mseg-menge.
*  DATA: ZMANDT LIKE AMVEG_UEB-MANDT.
*  DATA: ZMATNR LIKE AMVEG_UEB-MATNR.
*  DATA: ZWERKS LIKE AMVEG_UEB-WERKS.
  DATA: ZERTAG LIKE AMVEG_UEB-ERTAG.
  DATA: ZTOTAL LIKE AMVEG_UEB-VBWRT.

  CLEAR: ZERTAG, ZTOTAL.
  SORT it_data BY MANDT MATNR WERKS ERTAG.

  LOOP AT it_data where mandt = z_mandt AND matnr = z_matnr
                    AND werks = z_werks.

    PERFORM CONVERT_PERIOD USING it_data-PERKZ it_data-ERTAG.

    s_keydate = it_data-ERTAG.
    z_total = it_data-VBWRT.

    IF sy-subrc = 0.

      IF  ZERTAG = s_keydate.

        AMVEG_UEB-VBWRT = AMVEG_UEB-VBWRT + z_total.
        AMVEG_UEB-KOVBW = AMVEG_UEB-KOVBW + z_total.

        AMVEU_UEB-VBWRT = AMVEU_UEB-VBWRT + z_total.
        AMVEU_UEB-KOVBW = AMVEU_UEB-KOVBW + z_total.

      ELSEIF NOT ZERTAG IS INITIAL.

        ZERTAG = s_keydate.
        ZTOTAL = z_total.

        APPEND AMVEG_UEB.
        APPEND AMVEU_UEB.
        CLEAR AMVEG_UEB.
        CLEAR AMVEU_UEB.

        AMVEG_UEB-MANDT = it_data-mandt.
        AMVEG_UEB-MATNR = it_data-matnr.
        AMVEG_UEB-WERKS = it_data-werks.
        AMVEG_UEB-ERTAG = s_keydate.
        AMVEG_UEB-VBWRT = z_total.
        AMVEG_UEB-KOVBW = z_total.

        AMVEU_UEB-MANDT = it_data-mandt.
        AMVEU_UEB-MATNR = it_data-matnr.
        AMVEU_UEB-WERKS = it_data-werks.
        AMVEU_UEB-ERTAG = s_keydate.
        AMVEU_UEB-VBWRT = z_total.
        AMVEU_UEB-KOVBW = z_total.

      ENDIF.

      IF ZERTAG IS INITIAL.

        ZERTAG = s_keydate.
        ZTOTAL = z_total.

        AMVEG_UEB-MANDT = it_data-mandt.
        AMVEG_UEB-MATNR = it_data-matnr.
        AMVEG_UEB-WERKS = it_data-werks.
        AMVEG_UEB-ERTAG = s_keydate.
        AMVEG_UEB-VBWRT = z_total.
        AMVEG_UEB-KOVBW = z_total.

        AMVEU_UEB-MANDT = it_data-mandt.
        AMVEU_UEB-MATNR = it_data-matnr.
        AMVEU_UEB-WERKS = it_data-werks.
        AMVEU_UEB-ERTAG = s_keydate.
        AMVEU_UEB-VBWRT = z_total.
        AMVEU_UEB-KOVBW = z_total.

      ENDIF.

    ENDIF.

  ENDLOOP.

  APPEND AMVEG_UEB.
  APPEND AMVEU_UEB.
  CLEAR AMVEG_UEB.
  CLEAR AMVEU_UEB.

  IF NOT AMVEG_UEB[] IS INITIAL AND NOT AMVEU_UEB[] IS INITIAL.

    CALL FUNCTION ‘MVER_MAINTAIN_DARK’
           TABLES
                AMVEG_UEB       = AMVEG_UEB
                AMVEU_UEB       = AMVEU_UEB
                AMERRDAT_F      = AMERRDAT_F
           EXCEPTIONS
                UPDATE_ERROR    = 1
                INTERNAL_ERROR  = 2
                TOO_MANY_ERRORS = 3
                OTHERS          = 4.

    IF SY-SUBRC = 0.
      CLEAR ROLLBACK_FLAG.
      LOOP AT AMERRDAT_F.
        IF AMERRDAT_F-MSGTY = ‘E’ OR
           AMERRDAT_F-MSGTY = ‘A’.
          ROLLBACK WORK.
          ROLLBACK_FLAG = ‘X’.
          EXIT.
        ENDIF.
      ENDLOOP.
      IF ROLLBACK_FLAG IS INITIAL.
        COMMIT WORK.
        MESSAGE S000 WITH TEXT-S01.
        Z_STATUS = Text-S01.
      ENDIF.
    ELSE.
      ROLLBACK WORK.
    ENDIF.

  ENDIF.

endform.

*&———————————————————————*
*&      Form  CONVERT_PERIOD
*&———————————————————————*
*       text
*———————————————————————-*
*      –>P_PERKZ
*      –>P_ERTAG
*———————————————————————-*
FORM CONVERT_PERIOD USING    P_PERKZ LIKE MARC-PERKZ
                             P_ERTAG LIKE MVEG_UEB-ERTAG.

DATA: xweek(6)    TYPE n.

  IF P_PERKZ = ‘W’.

    CALL FUNCTION ‘DATE_GET_WEEK’
      EXPORTING
        DATE               = P_ERTAG
     IMPORTING
       WEEK               = xweek
     EXCEPTIONS
       DATE_INVALID       = 1
*       OTHERS             = 2
                .
    IF SY-SUBRC <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

    CALL FUNCTION ‘WEEK_GET_FIRST_DAY’
       EXPORTING
         week         = xweek
       IMPORTING
         date         = P_ERTAG
       EXCEPTIONS
         week_invalid = 1
         others       = 2.

  ELSEIF P_PERKZ = ‘M’.

    CONCATENATE P_ERTAG(6) ’01’ INTO P_ERTAG.

  ENDIF.

ENDFORM.                    ” CONVERT_PERIOD

*&———————————————————————*
*&      Form  DELTA_CONSUMPTION
*&———————————————————————*
*       text
*———————————————————————-*
*  –>  p1        text
*  <–  p2        text
*———————————————————————-*
FORM DELTA_CONSUMPTION USING P_total.

************************************************************************
* DATA Declarations                                                    *
************************************************************************
  DATA: s_month(2) type N.
  DATA: AUX1(10) TYPE C.
  DATA: AUX2(10) TYPE C.

************************************************************************
* TABLE Declarations                                                   *
************************************************************************
  TABLES: mver.

************************************************************************
* FIELD SYMBOLS Declarations                                           *
************************************************************************
  FIELD-SYMBOLS: <xi>.
  UNASSIGN <xi>.
  FIELD-SYMBOLS: <yi>.
  UNASSIGN <yi>.

  CLEAR AUX1.

  Select single * from mver
  where matnr = it_data-matnr
  AND werks = it_data-werks
  AND gjahr = it_data-ERTAG(4).

  s_month = it_data-ERTAG+4(2).

*  Corregido
  CONCATENATE ‘mver-MGV’ s_month INTO aux1.
  CONDENSE aux1.
  ASSIGN (aux1) TO <xi>.

* Total
  CONCATENATE ‘mver-GSV’ s_month INTO aux2.
  CONDENSE aux2.
  ASSIGN (aux2) TO <yi>.
  IF <xi> <> 0.
    P_total = <xi> + it_data-VBWRT.
  ELSE.
    P_total = <yi> + it_data-VBWRT.
  ENDIF.

ENDFORM.                    ” DELTA_CONSUMPTION

*&———————————————————————*
*&      Form  alv
*&———————————————————————*
*       text
*———————————————————————-*
*  –>  p1        text
*  <–  p2        text
*———————————————————————-*
FORM alv.
  PERFORM init_fieldcat.
  PERFORM init_layout.
  PERFORM list.
ENDFORM.                    ” alv

*&———————————————————————*
*&      Form  init_layout
*&———————————————————————*
*       text
*———————————————————————-*
*  –>  p1        text
*  <–  p2        text
*———————————————————————-*
FORM init_layout.
  wa_layout-zebra = c_x.
  wa_layout-colwidth_optimize = c_x.
  wa_layout-box_fieldname = c_marca.
  wa_layout-expand_fieldname = c_x.
ENDFORM.                    ” init_layout

*&———————————————————————*
*&      Form  init_fieldcat
*&———————————————————————*
*       text
*———————————————————————-*
*  –>  p1        text
*  <–  p2        text
*———————————————————————-*
FORM init_fieldcat.

  DATA: wa_fieldcat  TYPE slis_fieldcat_alv,
  sum TYPE i .

  REFRESH gt_fieldcat.
  CLEAR: wa_fieldcat.
  sum = c_1.

  wa_fieldcat-fieldname = ‘MANDT’.
  wa_fieldcat-tabname = ‘IT_LOG’.
  wa_fieldcat-ref_fieldname = ‘MANDT’.
  wa_fieldcat-ref_tabname = ‘MARC’.
  wa_fieldcat-col_pos = sum.
  APPEND wa_fieldcat TO gt_fieldcat .
  CLEAR: wa_fieldcat.
  sum = sum + c_1.

  wa_fieldcat-fieldname = ‘MATNR’.
  wa_fieldcat-tabname = ‘IT_LOG’.
  wa_fieldcat-ref_fieldname = ‘MATNR’.
  wa_fieldcat-ref_tabname = ‘MARC’.
  wa_fieldcat-col_pos = sum.
  APPEND wa_fieldcat TO gt_fieldcat .
  CLEAR: wa_fieldcat.
  sum = sum + c_1.

  wa_fieldcat-fieldname = ‘WERKS’.
  wa_fieldcat-tabname = ‘IT_LOG’.
  wa_fieldcat-ref_fieldname = ‘WERKS’.
  wa_fieldcat-ref_tabname = ‘MARC’.
  wa_fieldcat-col_pos = sum.
  APPEND wa_fieldcat TO gt_fieldcat .
  CLEAR: wa_fieldcat.
  sum = sum + c_1.

  wa_fieldcat-fieldname = ‘STATUS’.
  wa_fieldcat-tabname = ‘IT_LOG’.
  wa_fieldcat-seltext_s = TEXT-T01.
  wa_fieldcat-seltext_m = TEXT-T01.
  wa_fieldcat-seltext_l = TEXT-T01.
  wa_fieldcat-col_pos = sum.
  APPEND wa_fieldcat TO gt_fieldcat .
  CLEAR: wa_fieldcat.
  sum = sum + c_1.

ENDFORM.                    ” init_fieldcat

*&———————————————————————*
*&      Form  list
*&———————————————————————*
*       text
*———————————————————————-*
*  –>  p1        text
*  <–  p2        text
*———————————————————————-*
FORM list.

  CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
       EXPORTING
*            i_callback_pf_status_set = ‘PF_STATUS_SET’
            i_callback_program       = v_repid
*            i_callback_user_command  = ‘USER_COMMAND’
            is_layout                = wa_layout
            it_fieldcat              = gt_fieldcat
*            it_events                = t_events[]
       TABLES
            t_outtab                 = it_log
       EXCEPTIONS
            program_error            = 1
            OTHERS                   = 2.

  IF sy-subrc <> 0.
    MESSAGE E000 WITH TEXT-E04.
  ENDIF.

ENDFORM.                    ” list

Here the Text Elements:

SAP6.jpg

SAP7.jpg

Note that this program uses FM: ‘MVER_MAINTAIN_DARK’. This FM is not released by SAP, so its important to know what are the risks in case of an SAP upgrade or New Support Package.

You can read more about Consumption-Based Planning here:

Consumption-Based Planning – MRP Procedures – SAP Library

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply