VA02 释放行项目计划行确认数量

Posted springzt

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VA02 释放行项目计划行确认数量相关的知识,希望对你有一定的参考价值。

标准功能操作事物代码VA02

 

 

技术图片

 

 技术图片

 

 技术图片

 

操作后计划行被删除

需求是:实现批量操作,用户不需要一个一个的点,程序批量释放

参考地址:http://www.abapcookbook.com/sap-abap-code-sample/function-module-change-cancel-confirmed-quantity/

调用function : CALL FUNCTION ‘SD_BACKORDER_UPDATE‘

 

REPORT ztestfmconfirmedquantity.
*&--------------------------------------------------------------------&*
*& Program Description:                                               &*
*& -----------------------                                            &*
*& This demo program will update the confirmed quantity in a          &*
*& sales order.                                                       &*
*&                                                                    &*
*& The program demonstrate the use of the FM ‘SD_BACKORDER_UPDATE‘.   &*
*&                                                                    &*
*& Author:  ABAPCOOKBOOK                                              &*
*& Website: www.abapcookbook.com                                      &*
************************************************************************

************************************************************************
* DATA DECLARATIONS                                                    *
************************************************************************
*Tables:
TABLES:
  vbap,
  vbep.

*Internal tables:
DATA:
  gt_vbap               TYPE STANDARD TABLE OF vbap,
  gt_vbep               TYPE STANDARD TABLE OF vbep,
  gt_kortab             TYPE STANDARD TABLE OF mdvu,
  gt_return             TYPE STANDARD TABLE OF bapiret2.

*Field Symbols:
FIELD-SYMBOLS:
  <fs_vbap>             TYPE vbap,
  <fs_vbep>             TYPE vbep.

*Structures:
DATA:
  gst_kortab            TYPE mdvu.

*Variables:
DATA:
  gv_msg                TYPE string,
  gv_tabix              TYPE sy-tabix.

*Constants:
CONSTANTS:
  gc_error              TYPE string VALUE ‘: An error occured, no change done to the sales order.‘,
  gc_success            TYPE string VALUE ‘: Sales order changed successfully.‘.

************************************************************************
* SELECTION SCREEN                                                     *
************************************************************************
SELECT-OPTIONS:
*  Sales Order Number.
   s_vbeln FOR vbap-vbeln OBLIGATORY.

PARAMETERS:
* Reason for Rejection.
  p_abgru TYPE vbap-abgru OBLIGATORY,

* Confirm Quantity.
  p_bmeng TYPE vbep-bmeng OBLIGATORY.


************************************************************************
* CODE LOGIC                                                           *
************************************************************************

*Select sales order data from table VBAP.
SELECT *
  FROM vbap
  INTO TABLE gt_vbap
  WHERE vbeln IN s_vbeln.

IF sy-subrc EQ 0.

* Rules ‘For All Entries‘.
* Not necessary as ‘VBELN‘ and ‘POSNR‘ is already primary key, this logic
* just to demonstrate ‘For All Entries‘ rule.
  SORT gt_vbap BY vbeln posnr.
  DELETE ADJACENT DUPLICATES FROM gt_vbap COMPARING vbeln posnr.

* Retrieving schedule lines entries.
  SELECT *
    FROM vbep
   INTO TABLE gt_vbep
 FOR ALL ENTRIES IN gt_vbap
   WHERE vbeln EQ gt_vbap-vbeln
     AND posnr EQ gt_vbap-posnr.

  IF sy-subrc EQ 0.

*   Sorting for binary search.
    SORT gt_vbep BY vbeln posnr.

    LOOP AT gt_vbap ASSIGNING <fs_vbap>.

*     ........................
*     FM Data for updating the confirm quantity.
*     ........................
*     Adding the schedule lines items.
      READ TABLE gt_vbep TRANSPORTING NO FIELDS
      WITH KEY  vbeln = <fs_vbap>-vbeln
                posnr = <fs_vbap>-posnr
                BINARY SEARCH.

      IF sy-subrc EQ 0.

        gv_tabix = sy-tabix.

*       Index looping for better performance.
        LOOP AT gt_vbep ASSIGNING <fs_vbep> FROM gv_tabix.

          IF  <fs_vbep>-vbeln EQ <fs_vbap>-vbeln
          AND <fs_vbep>-posnr EQ <fs_vbap>-posnr.

*           Current item of the sales order for the current
*           availability date.
            gst_kortab-vbeln = <fs_vbep>-vbeln.
            gst_kortab-posnr = <fs_vbep>-posnr.
            gst_kortab-mbdat = <fs_vbep>-mbdat.

*           Setting the confirm quantity. Please note that
*           setting this value to ‘0‘ will cancel the confirm quantity
*           in the sales order on all schedule lines.
            gst_kortab-vmeng = p_bmeng.

            APPEND gst_kortab TO gt_kortab.

          ELSE.

*           Clear index
            CLEAR gv_tabix.

*           Move out of the loop.
            EXIT.

          ENDIF.

*         Clearing of work areas.
          CLEAR:
            gst_kortab.

        ENDLOOP.

      ENDIF.

*     Calling function module to update confirm quantity. The ATP check is
*     also generated using this function module.
*     Please Note: The drawback of this FM is that it automatically commit
*     changes to database even if a sales order is in edit mode and
*     it don‘t look that much perfomant.
      CALL FUNCTION ‘SD_BACKORDER_UPDATE‘
        TABLES
          kortab    = gt_kortab
          et_return = gt_return.

*     Preparing the result message.
      CONCATENATE <fs_vbap>-vbeln   " Sales Order Number
                  <fs_vbap>-posnr   " Item Number
             INTO gv_msg            " Message
     SEPARATED BY space.            " Space

*     Check if at least one error was raised by the FM. Loop inside
*     loop is not advise, however, the return table will contains small
*     amount of entries. We can use that for our demo.
      LOOP AT gt_return TRANSPORTING NO FIELDS
      WHERE type EQ ‘E‘
         OR type EQ ‘A‘.

*       Exit and rollback changes.
        EXIT.

      ENDLOOP.

*     If error found, rollback database changes.
      IF sy-subrc EQ 0.

*       Preparing error message.
        CONCATENATE gv_msg        "Sales Order and Item Number
                    gc_error      "Error Message
               INTO gv_msg
       SEPARATED BY space.

*       Output message.
        WRITE / gv_msg.

*     Else, no error found, commit database changes.
      ELSE.

*       Preparing success message.
        CONCATENATE gv_msg        "Sales Order and Item Number
                    gc_success    "Success Message
               INTO gv_msg
       SEPARATED BY space.

*       Output message.
        WRITE / gv_msg.

      ENDIF.

*     Write a line after each sales order.
      AT END OF vbeln.
        WRITE: sy-uline.
      ENDAT.

*     Clearing of variables and structures:
      CLEAR:
*       Variables:
        gv_msg,
        gv_tabix.

*     Refreshing internal tables:
      REFRESH:
        gt_kortab,
        gt_return.

    ENDLOOP.

  ENDIF.

ENDIF.

  

 

以上是关于VA02 释放行项目计划行确认数量的主要内容,如果未能解决你的问题,请参考以下文章

SAP 框架合同创建

SAP 计划行审核是自动修改,产生MD04需求

在SAP系统中,怎么查找季度生产订单计划完成的成品数量和度计划订单交货数量。

ABAP VA31创建销售计划协议

禁用 VA01 中的列

项目中实现幂等的几种方式