BUAG – Business Agreement

This document explains How to create BUAG using BAPI, Update BUAG using BAPI and updating one order document with Baug ID.

Create BUAG using BAPI

  DATA : ls_datagnrl       TYPE bapibus1006130_gnrl_data,
         ls_dataspec      
TYPE bapibus1006130_spec_data,
         ls_datagnrlnew   
TYPE bapibus1006130_gnrl_data_exp,
         ls_dataspecnew   
TYPE bapibus1006130_spec_data_exp ,
         lt_treldata      
TYPE TABLE OF bapibus1006130_rel_data,
         lt_return        
TYPE TABLE OF bapiret2,
         ls_return        
TYPE bapiret2,
         lv_addrnumber    
TYPE ad_addrnum,
         lv_text          
TYPE crmt_babr_text.

  lv_text = ‘Create BUAG using BAPI’.

  ls_datagnrl

babr_text = lv_text.

* Incoming payment method


  ls_datagnrl
method_inc = <Incoming payment method>.* Outgoing payment method
  ls_datagnrl
method_outg = <Outgoing payment method, normally Cheque>.

         “ if you give ‘E’ – Electronic payment method then bank details are mandatory

* Terms of payment
  ls_datagnrl
tofpaym   = <Terms of Payment>.

  ls_dataspecbuag_text = lv_text1.

* Business agreement class
  ls_dataspec
buag_class  = <Business agreement Class>.

* BP address number
  ls_dataspec
addr_no     = lv_addrnumber.

  CALL FUNCTION ‘BAPI_BUPA_FRG0130_CREATE’
   
EXPORTING
      businesspartner
= <Input Business Partner Number>
      datagnrl       
= ls_datagnrl
      dataspec       
= ls_dataspec
   
IMPORTING
      datagnrlnew    
= ls_datagnrlnew
      dataspecnew    
= ls_dataspecnew
   
TABLES
      treldata       
= lt_treldata
     
return          = lt_return.

    COMMIT WORK AND WAIT.

Update BUAG using BAPI

  DATA:
         ls_datagnrl      
TYPE bapibus1006130_gnrl_data,
         ls_dataspec      
TYPE bapibus1006130_spec_data,
         ls_data_spec     
TYPE bapibus1006130_spec_data_exp,
         ls_dataspec_x    
TYPE bapibus1006130_spec_data_x,
         ls_datagnrl_x    
TYPE bapibus1006130_gnrl_data_x,
         lv_text          
TYPE crmt_babr_text,
         lv_text1         
TYPE crmt_buag_text,
         lv_addrnumber    
TYPE ad_addrnum,
         lv_buag_id       
TYPE crmt_buag_id,
         lt_return        
TYPE TABLE OF bapiret2,
         ls_return        
TYPE bapiret2,
         lv_buagguid      
TYPE crmt_buag_guid_c.

  CONSTANTS: lc_x         TYPE c               VALUE ‘X’.

  MOVE : <input BUAG_ID> TO lv_buag_id.


* Get the address number for the BP ID
 
SELECT SINGLE addrnumber
   
INTO lv_addrnumber
   
FROM but020
   
WHERE partner = <Input Business Partner Number>.

lv_text = ‘Update BUAG using BAPI’.


  ls_datagnrl
babr_text  = lv_text.
  ls_datagnrl
method_inc = <Incoming Payment Method>
  ls_datagnrl
method_outg = <Outgoing payment method, normally Cheque>.

  “ if you give ‘E’ – Electronic payment method then bank details are  

  ls_datagnrl

tofpaym   = <Terms of payment>.

* Business Agreement Fields
  ls_dataspec
buag_text  = lv_text.
  ls_dataspec
buag_class = <Business Agreement Class>.
  ls_dataspec
addr_no    = lv_addrnumber.

  ls_datagnrl_xbabr_text   = lc_x.
  ls_datagnrl_x
method_inc  = lc_x.
  ls_datagnrl_x
tofpaym     = lc_x.
  ls_datagnrl_x
method_outg = lc_x.
  ls_dataspec_x
buag_text   = lc_x.
  ls_dataspec_x
buag_class  = lc_x.

  ls_dataspec_xaddr_no     = lc_x.

* Get the BUAG GUID for the BUAG ID
 
CALL FUNCTION ‘BAPI_BUPA_FRG0130_GETDETAIL’
   
EXPORTING
      businesspartner  
= <Input Business Partner Number>.
      businessagreement
= <input BUAG_ID>
   
IMPORTING
      dataspec         
= ls_data_spec
   
TABLES
     
return            = lt_return.

  CLEAR lv_buagguid.
  lv_buagguid
= ls_data_specbuag_guid.

  REFRESH lt_return.


* Change the Business Agreement
 
CALL FUNCTION ‘BAPI_BUPA_FRG0130_CHANGE’
   
EXPORTING
      businesspartner  
= <Input Business Partner Number>.
      businessagreement
= <input BUAG_ID>
      buagguid         
= lv_buagguid
      datagnrl         
= ls_datagnrl
      dataspec         
= ls_dataspec
      datagnrlx        
= ls_datagnrl_x
      dataspecx        
= ls_dataspec_x
   
TABLES
     
return            = lt_return.

  CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
   
EXPORTING
     
wait = ‘X’.

Link BUAG to One order document

DATA :          lt_billing      TYPE crmt_billing_comt,
           ls_billing     
TYPE crmt_billing_com,
           lt_pricing     
TYPE crmt_pricing_comt,
           ls_pricing     
TYPE crmt_pricing_com,
           lt_sales       
TYPE crmt_sales_comt,
           ls_sales       
TYPE crmt_sales_com,
           lt_shipping    
TYPE crmt_shipping_comt,
           ls_shipping    
TYPE crmt_shipping_com,
           lt_input_fields
TYPE crmt_input_field_tab,
           ls_input_fields
TYPE crmt_input_field,
           lt_field_name  
TYPE crmt_input_field_names_tab,
           ls_field_name  
TYPE crmt_input_field_names,
           lv_header_guid 
TYPE crmd_orderadm_hguid,
           lt_orderadm_h  
TYPE crmt_orderadm_h_comt,
           ls_orderadm_h  
TYPE crmt_orderadm_h_com,
           lv_log_handle  
TYPE  balloghndl,
           lt_guid        
TYPE crmt_object_guid_tab,
           ls_guid        
TYPE crmt_object_guid,
           lt_initialized_objects
TYPE crmt_object_guid_tab,
           ls_initialized_objects
TYPE crmt_object_guid,
           lt_rorderadm_h        
TYPE  crmt_orderadm_h_wrkt,
           ls_rorderadm_h        
TYPE  crmt_orderadm_h_wrk,
           lt_rorderadm_i        
TYPE crmt_orderadm_i_wrkt,
           ls_rorderadm_i        
TYPE crmt_orderadm_i_wrk,
           lt_objects_to_save    
TYPE crmt_object_guid_tab,
           ls_objects_to_save    
TYPE crmt_object_guid,
           lt_saved_objects      
TYPE crmt_return_objects,
           ls_saved_objects      
TYPE crmt_return_objects_struc,
           lt_exception          
TYPE crmt_exception_t,
           ls_exception          
TYPE crmt_exception,
           lt_objects_not_saved  
TYPE crmt_object_guid_tab,
           ls_objects_not_saved  
TYPE crmt_object_guid,
           lt_rpartner           
TYPE crmt_partner_external_wrkt,
           ls_rpartner           
TYPE crmt_partner_external_wrk,
           lv_buag_t             
TYPE zdtel00006l.


* Get the one order object GUID for given one order document number
 
SELECT SINGLE guid
   
INTO lv_header_guid
   
FROM crmd_orderadm_h
   
WHERE object_id = iv_agr_id
   
AND object_type = <BUS2000***>. “ Order header

  ls_guid = lv_header_guid.
 
APPEND ls_guid TO lt_guid.

* Initiaize order buffers

  CALL FUNCTION ‘CRM_ORDER_INITIALIZE’
   
EXPORTING
      it_guids_to_init          
= lt_guid
   
IMPORTING
      et_initialized_objects    
= lt_initialized_objects
   
EXCEPTIONS
      error_occurred            
= 1
     
OTHERS                     = 2.
 
IF sysubrc = 0.

*   Read the partner, order header and order item data
   
CALL FUNCTION ‘CRM_ORDER_READ’
     
EXPORTING
        it_header_guid
= lt_guid
     
IMPORTING
        et_orderadm_h 
= lt_rorderadm_h
        et_orderadm_i 
= lt_rorderadm_i
        et_partner    
= lt_rpartner.

*   Orderadm_h data
    ls_orderadm_h
handle = ‘0000000001’ .
    ls_orderadm_h
process_type = <transaction type>.
    ls_orderadm_h
guid = lv_header_guid.
   
APPEND ls_orderadm_h TO lt_orderadm_h.

*   Sales data
    ls_sales
ref_kind = ‘A’.
    ls_sales
ref_guid = lv_header_guid.
   
APPEND ls_sales TO lt_sales.

*   Shipping data
    ls_shipping
ref_kind = ‘A’.
    ls_shipping
ref_guid = lv_header_guid.
   
APPEND ls_shipping TO lt_shipping.


*   Pricing data
    ls_pricing
ref_kind = ‘A’.
    ls_pricing
ref_guid = lv_header_guid.
    ls_pricing
currency = <Currency>.
    ls_pricing
exchg_rate = ‘1.00000’.
   
APPEND ls_pricing TO lt_pricing.

*   Pass business agreement for update on one order
    ls_billing
buag_id = iv_buag_id.
    ls_billing
ref_kind = ‘A’.
    ls_billing
ref_guid = lv_header_guid.
   
APPEND ls_billing TO lt_billing.

    ls_field_namefieldname = ‘BUAG_ID’.
   
APPEND ls_field_name TO lt_field_name.

    ls_input_fieldsref_guid = lv_header_guid.
    ls_input_fields
ref_kind = ‘A’.
    ls_input_fields
objectname = ‘BILLING’.
    ls_input_fields
field_names[] = lt_field_name[].
   
INSERT ls_input_fields INTO TABLE lt_input_fields.
   
CLEAR : lt_field_name, ls_input_fields, ls_field_name.

    LOOP AT lt_rorderadm_i INTO ls_rorderadm_i
   
WHERE object_type = ‘BUS2000***’. “ Order item
      ls_billing
buag_id = iv_buag_id.
      ls_billing
ref_kind = ‘B’.
      ls_billing
ref_guid = ls_rorderadm_iguid.
     
APPEND ls_billing TO lt_billing.

      ls_field_namefieldname = ‘BUAG_ID’.
     
APPEND ls_field_name TO lt_field_name.

      ls_input_fieldsref_guid = ls_rorderadm_iguid.
      ls_input_fields
ref_kind = ‘B’.
      ls_input_fields
objectname = ‘BILLING’.
      ls_input_fields
field_names[] = lt_field_name[].
     
INSERT ls_input_fields INTO TABLE lt_input_fields.
     
CLEAR : lt_field_name, ls_input_fields, ls_field_name.
   
ENDLOOP.*   Order for the changed data
   
CALL FUNCTION ‘CRM_ORDER_MAINTAIN’
     
EXPORTING
        it_billing     
= lt_billing
        it_pricing     
= lt_pricing
        it_sales       
= lt_sales
        it_shipping    
= lt_shipping
     
CHANGING
        ct_orderadm_h  
= lt_orderadm_h
        ct_input_fields
= lt_input_fields
        cv_log_handle  
= lv_log_handle.
   
IF sysubrc = 0.

      ls_objects_to_save = lv_header_guid.
     
APPEND  ls_objects_to_save TO lt_objects_to_save.

*     Save the one order
     
CALL FUNCTION ‘CRM_ORDER_SAVE’
       
EXPORTING
          it_objects_to_save  
= lt_objects_to_save
       
IMPORTING
          et_saved_objects    
= lt_saved_objects
          et_exception        
= lt_exception
          et_objects_not_saved
= lt_objects_not_saved
       
EXCEPTIONS
          document_not_saved  
= 1
         
OTHERS               = 2.
     
IF sysubrc = 0.*       Commit the changes
       
CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT’
         
EXPORTING
           
wait = ‘X’.*       Initialize the order buffer
       
CALL FUNCTION ‘CRM_ORDER_INITIALIZE’
         
EXPORTING
            it_guids_to_init      
= lt_guid
         
IMPORTING
            et_initialized_objects
= lt_initialized_objects
         
EXCEPTIONS
            error_occurred        
= 1
           
OTHERS                 = 2.

      ENDIF.

    ENDIF.

  ENDIF.

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