Thursday, February 24, 2011

Change price of condition records by BAPI as VK12

VK12 is transaction to change condition records.

Requirement need a program to update pricing of condition records at table A914. For anyone who is finding a BAPI for modify pricing without BDC. I recommend to use standards function module RV_CONDITION_COPY and RV_CONDTION_SAVE to update it.

How to use it ?
Let's we go.

Before program update. at TCode VK12, we will see rate 107.64 EUR
When see data in table A914. Table will keep relationship between material, company code, validity date and condition records number (KNUMH)

Rate was keep in table KONP. Focus on field KBETR 107.64 EUR was shown.

Then try to create the program following coding below,


DATA : wa_key_fields LIKE komg,
lt_copy_records TYPE TABLE OF komv WITH HEADER LINE,
wa_konp TYPE konp.
CLEAR : wa_key_fields, lt_copy_records.
REFRESH : lt_copy_records.

select single * from konp
into wa_konp
where knumh = '0000016269'
and loevm_ko <> 'X'.

wa_key_fields-bukrs = '5730'.
wa_key_fields-matnr = '000000000100017001'.
lt_copy_records-knumv = '0000016269'.
lt_copy_records-kposn = wa_konp-kopos.
lt_copy_records-kappl = 'V'.
lt_copy_records-kschl = 'ZGA1'.
lt_copy_records-kbetr = '33.33'.

lt_copy_records-waers = wa_konp-konwa.
lt_copy_records-krech = wa_konp-krech.
lt_copy_records-stfkz = wa_konp-stfkz.
lt_copy_records-kpein = wa_konp-kpein.
lt_copy_records-kmein = wa_konp-kmein.
lt_copy_records-zaehk_ind = wa_konp-zaehk_ind.
APPEND lt_copy_records.
 
CALL FUNCTION 'RV_CONDITION_COPY'
EXPORTING
application = 'V'
condition_table = '914'
condition_type = 'ZGA1'
enqueue = 'X'key_fields = wa_key_fields
maintain_mode = 'B'
no_authority_check = 'X'
TABLES
copy_records = lt_copy_records
EXCEPTIONS
enqueue_on_record = 1
invalid_application = 2
invalid_condition_number = 3
invalid_condition_type = 4
no_authority_ekorg = 5
no_authority_kschl = 6
no_authority_vkorg = 7
no_selection = 8
table_not_valid = 9
no_material_for_settlement = 10
no_unit_for_period_cond = 11
no_unit_reference_magnitude = 12
invalid_condition_table = 13
OTHERS = 14
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'RV_CONDITION_SAVE'.
COMMIT WORK.
CALL FUNCTION 'RV_CONDITION_RESET'.
COMMIT WORK.



From coding, I set new rate to 33.33 EUR. after execute it. The result was shown as below,
When VK12, Rate was changed to 33.33 EUR

let see at table A914.  There are nothing change!!
 But in table KONP. New rate was updated to 33.33 EUR

3 comments: