Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Need Help with FM RV_CONDITION_SAVE in badi SD_COND_SAVE_A

Former Member
0 Kudos
1,274

Hi ,

I want to run MEK1  in background once VK11 transaction will be called.

For that i did code as below in BADI SD_COND_SAVE_A.

method if_ex_sd_cond_save_a~condition_save_exit.
data   matnr type matnr.
data   : wa_konh_new type konhdb.
data: v_matnr(50) type c,
v2(50) type c,
del(1) type c value ' ',flag type c.

if sy-tcode = 'VK11'.

     loop at ct_konh_new into  wa_konh_new.

      split wa_konh_new-vakey at del into v_matnr v2.
*    **********************************MEk1 or MEk2 pricing data saving****************************************************
           data:cr type table of komv ,wa_cr type komv,
           nr,key_fields type  komg,
           komk type  komkkomp type  komp ,
           wa_konpdb_new type konpdb.

           key_fields-werks = '180D'.
           key_fields-matnr = v_matnr.


           read table ct_konpdb_new into wa_konpdb_new with key knumh = wa_konh_new-knumh.
           if sy-subrc = 0.
              wa_cr-kappl = 'M'.
              wa_cr-kschl = 'P001'.
              wa_cr-kbetr wa_konpdb_new-kbetr.
              wa_cr-kpein wa_konpdb_new-kpein.
              wa_cr-kmein wa_konpdb_new-kmein.
              wa_cr-waers wa_konpdb_new-konwa.
              append wa_cr to cr.
              clear wa_cr.
           endif.
           clear wa_konpdb_new.


         data: wa_pispr type pispr." pispr.
         wa_pispr-matnr = v_matnr.
         wa_pispr-werks = '180D'.

         call function 'SPR_KOMK_KOMP_FILL'
           exporting
             pi_i_spr        = wa_pispr
          importing
            pe_i_komk       = komk
            pe_i_komp       = komp
               .

          call function 'RV_CONDITION_COPY'
          exporting
               application              = 'M'
               condition_table          = '616'
               condition_type           = 'P001'
               date_from                = sy-datum "wa_konh_new-datab
               date_to                  = '99991231'"wa_konh_new-datbi
               enqueue                  = 'X'
               i_komk                   = komk
               i_komp                   = komp
               key_fields               = key_fields
               maintain_mode            = 'A'
               no_authority_check       = 'X'
               keep_old_records         = 'X'
               overlap_confirmed        = 'X'
          importing
               e_komk                   = komk
               e_komp                   = komp
               new_record               = nr
          tables
               copy_records             = cr
          exceptions
               enqueue_on_record        = 01
               invalid_application      = 02
               invalid_condition_number = 03
               invalid_condition_type   = 04
               no_authority_ekorg       = 05
               no_authority_kschl       = 06
               no_authority_vkorg       = 07
               no_selection             = 08
               table_not_valid          = 09.


           call function 'RV_CONDITION_SAVE'.
call function 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
*   WAIT          =
* IMPORTING
*   RETURN        =
           .
endloop.
endif.

endmethod.

when debugger come to   call function 'RV_CONDITION_SAVE' it's again caling the same BADI.

and so tht could not save the data.

Let me know solution for the same.

Thanks

Surekha

2 REPLIES 2

PeterJonker
Active Contributor
0 Kudos
250

performing a commit in a badi is asking for problems.

In this case the call to the copy function module will also call the same badi and you will get into an never ending recurring call and you will keep on copying conditons.

What happens if you leave out the Bapi_transaction_commit ?

Otherwise is there not a bapi that can create the condition, because then you can call this bapi in background task. Else you might have to define a wrapper around this fm to make it rfc enabled and then call this one in background task.

Former Member
0 Kudos
250

You can create a table to store records that are being processed, in the beginning of your badi you insert the condition key in the table and once Fm RV_CONDITION_SAVE runs succesfully you delete the record from table. Before the insertion you must check if the current condition exists in the table, if yes you skip the badi processing.