Program To Close All Open Partial Sales Quotation

How to mass deleting/closing of open/partially completed quotations?

There was a request raise by user to help them closed all the old sales quotations that was not required anymore.

This customize ABAP program was written to close all the open/partial quotations.

REPORT  ZRPT_SD_001.

tables : vbak, vbuk, vbup.

*----------------------------------------------------------------------*
* Selection Screen
*----------------------------------------------------------------------*

selection-screen begin of block b1 with frame title text-001.

  parameters     : p_abgru      like    vbap-abgru obligatory.

  select-options : S_vbeln      for     vbuk-vbeln,
                           S_audat      for     vbak-audat no-extension.

selection-screen end   of block b1.

*----------------------------------------------------------------------*
* Data Declaration
*----------------------------------------------------------------------*

types : begin of t_tab,
          vbeln     type  vbak-vbeln,
          posnr     type  vbup-posnr,
          message   type  char80,
        end   of t_tab.

data: it_tab    type standard table of t_tab,
        wa_Tab    type t_tab.

data: flag_end.

* BAPI Declaration

data: HEADER_INX  type  BAPISDH1X,
        ITEM_IN     type standard table of BAPISDITM
                   with header line,
        ITEM_INX    type standard table of BAPISDITMX
                   with header line,
        RETURN                type standard table of BAPIRET2
                    with header line.

*----------------------------------------------------------------------*
* Start of Selection
*----------------------------------------------------------------------*

start-of-selection.

* Get All Open Quotations

  select vbup~vbeln vbup~posnr
    into table it_tab
    from vbak as vbak inner join vbuk on vbak~vbeln eq vbuk~vbeln
                      inner join vbup on vbak~vbeln eq vbup~vbeln
    where vbak~vbeln in s_vbeln
      and   vbak~vbtyp eq 'B'
      and   vbak~audat in s_audat
     and   vbup~gbsta <> 'C'.

loop at it_tab into wa_tab.

    HEADER_INX-UPDATEFLAG = 'U'.
    item_in-ITM_NUMBER = wa_tab-posnr.
   item_in-REASON_REJ = p_abgru.

    append item_in.

    item_inx-ITM_NUMBER = wa_tab-posnr.
    item_inx-REASON_REJ = 'X'.

    append item_inx.

    at end of vbeln.

      FLAG_END = 'X'.

      CALL FUNCTION 'BAPI_CUSTOMERQUOTATION_CHANGE'
         EXPORTING
            SALESDOCUMENT                = wa_tab-vbeln
            QUOTATION_HEADER_INX         = HEADER_INX
        TABLES
            RETURN                       = return
         QUOTATION_ITEM_IN            = item_in
         QUOTATION_ITEM_INX           = item_inx.

      read table return with key type = 'E'.

      if sy-subrc <> 0.
          CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' .
          clear: header_inx,
               item_in, item_in[],
               item_inx, item_inx[],
               return, return[].
      endif.
    endat.

   if flag_end eq 'X'.
       clear flag_end.
      if return-type eq 'E'.
        wa_tab-message = return-MESSAGE.
      else.
        WA_TAB-MESSAGE = 'Sucessfully Update'.
      endif.

      modify it_tab from wa_tab.
    endif.

endloop.

end-of-selection.

  uline.

  write:/ sy-vline , (15)'Quotation.No' centered,
            sy-vline , (10)'Item No' centered,
            sy-vline , (60)'Message'.
  uline.

  loop at it_tab into wa_tab.

    write:/ sy-vline , (15)wa_tab-vbeln centered,
               sy-vline , (10)wa_tab-posnr centered,
              sy-vline , (60)wa_tab-message.

    at end of vbeln.
      uline.
    endat.

   endloop.

*-- End of Program

ABAP Tips

See Also
Changed Service Order Status Upon Service Confirmation

Get help for your ABAP problems
Do you have a ABAP Question?

ABAP Books
ABAP Certification, BAPI, Java, Web Programming, Smart Forms, Sapscripts Reference Books

More ABAP Tips

Main Index
SAP ERP Modules, Basis, ABAP and Other IMG Stuff

All the site contents are Copyright © www.erpgreat.com and the content authors. All rights reserved.
All product names are trademarks of their respective companies.  The site www.erpgreat.com is in no way affiliated with SAP AG. 
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk. 
 The content on this site may not be reproduced or redistributed without the express written permission of 
www.erpgreat.com or the content authors.