ABAP获取销售合同执行数量

Posted SAP剑客

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ABAP获取销售合同执行数量相关的知识,希望对你有一定的参考价值。

SAP销售合同执行量校验

获取销售合同的数量(ZMENG)、已转为销售订单数量(KWMENG)、未转化数量(ZMENG -KWMENG)。

销售合同(VA43)明细界面中显示的”订单数量“其实并不准确,没有剔除行项目被拒绝的销售订单数量。

这里采用笨办法逐步获取合同执行数量,个人感觉比较低效,有更方便更有效的方式请留言,谢谢。

基本思路还是通过凭证流表”VBFA“。

  IF I_HEAD-VGBEL <> '' .
    PERFORM CHECK_QUANTITY TABLES IT_ITEM[] USING I_HEAD-VGBEL
                        CHANGING E_SUCC E_MESSAGE.
    IF E_SUCC = 'E'.
      EXIT.
    ENDIF.
  ENDIF.
*&---------------------------------------------------------------------*
*&      Form  CHECK_QUANTITY
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM CHECK_QUANTITY TABLES LT_ITEM STRUCTURE ZVS_CITEM
                      USING P_VGBEL
                   CHANGING E_SUCC E_MESSAGE.

  DATA : BEGIN OF LT_HT OCCURS 0,
           VBELN  LIKE VBAK-VBELN,
           POSNR  LIKE VBAP-POSNR,
           ZMENG  LIKE VBAP-ZMENG,
           KWMENG LIKE VBAP-KWMENG,
           ZLEFT  LIKE VBAP-KWMENG,
         END OF LT_HT,
         BEGIN OF LT_VBAP OCCURS 0,
           VBELN  LIKE VBAP-VBELN,
           POSNR  LIKE VBAP-POSNR,
           KWMENG LIKE VBAP-KWMENG,
         END OF LT_VBAP.
  DATA : LT_VBFA LIKE TABLE OF VBFA WITH HEADER LINE.

*** 获取合同数量
  SELECT A~VBELN B~POSNR B~ZMENG
  FROM VBAK AS A
  INNER JOIN VBAP AS B ON A~VBELN = B~VBELN
  APPENDING CORRESPONDING FIELDS OF TABLE LT_HT
  WHERE A~VBELN = P_VGBEL
    AND A~VBTYP = 'G' .

  CHECK LT_HT[] IS NOT INITIAL.

*** 获取参照合同的订单编号
  SELECT VBELN POSNN VBELV POSNV VBTYP_N VBTYP_V
    FROM VBFA
    INTO CORRESPONDING FIELDS OF TABLE LT_VBFA
    FOR ALL ENTRIES IN LT_HT
    WHERE VBELV = LT_HT-VBELN
      AND POSNV = LT_HT-POSNR
      AND VBTYP_N = 'C'"后继 订单
      AND VBTYP_V = 'G'."先前 合同

*** 获取订单数量
  IF LT_VBFA[] IS NOT INITIAL.
    SELECT VBELN POSNR KWMENG ABGRU
      FROM VBAP
      INTO CORRESPONDING FIELDS OF TABLE LT_VBAP
      FOR ALL ENTRIES IN LT_VBFA
      WHERE VBELN = LT_VBFA-VBELN
        AND POSNR = LT_VBFA-POSNN
        AND ( ABGRU = '' OR ABGRU = '01' )
      .
  ENDIF.

  SORT LT_VBFA BY VBELV POSNV.

  LOOP AT LT_HT.
    READ TABLE LT_VBFA WITH KEY VBELV = LT_HT-VBELN
                                POSNV = LT_HT-POSNR
                                BINARY SEARCH
                                TRANSPORTING NO FIELDS.
    LOOP AT LT_VBFA FROM SY-TABIX.
      IF LT_VBFA-VBELV = LT_HT-VBELN AND LT_VBFA-POSNV = LT_HT-POSNR.
        READ TABLE LT_VBAP WITH KEY VBELN = LT_VBFA-VBELN
                                    POSNR = LT_VBFA-POSNN
                                    BINARY SEARCH.
        IF SY-SUBRC = 0.
          ADD LT_VBAP-KWMENG TO LT_HT-KWMENG.
        ENDIF.
      ELSE.
        EXIT.
      ENDIF.
    ENDLOOP.
    LT_HT-ZLEFT = LT_HT-ZMENG - LT_HT-KWMENG.
    MODIFY LT_HT.
  ENDLOOP.

*** 校验项目数量是否超出
  SORT LT_HT BY VBELN POSNR.
  LOOP AT LT_ITEM.
    READ TABLE LT_HT WITH KEY VBELN = P_VGBEL
                              POSNR = LT_ITEM-POSNR_G
                              BINARY SEARCH.
    IF SY-SUBRC = 0.
      IF LT_HT-ZLEFT < LT_ITEM-KWMENG.
        E_SUCC = 'E'.
        E_MESSAGE = '订单项目'
        && LT_ITEM-POSNR
        && '的数量超出合同可执行数量,请确认!'.
      ENDIF.
    ENDIF.
  ENDLOOP.

ENDFORM.

以上是关于ABAP获取销售合同执行数量的主要内容,如果未能解决你的问题,请参考以下文章

SAP 框架合同创建

ERP系统-SAP主要有几大模块?分别的功能是啥?

[ChatGPT 勘误] SAP ABAP 里 cl_r3standard_persistence 的用途?

SAP abap 怎么拆分字符串?

abap 销售订单修改增强 LV69AFZZ 怎么进行修改 添加代码的呢?

sap rsa5事务代码是在erp 中 还是在bw中