Professional Documents
Culture Documents
using BAPI_PRICES_CONDITIONS
Category: SD
Published on Thursday, 17 September 2009 18:16
Written by Kevin Wilson
Hits: 11194
This code snippet inserts a condition record for Pricing condition type Z123 with key sales order and line
number.
CONSTANTS: lc_kschl_z123 TYPE kscha VALUE 'Z123'.
DATA: lv_datum
lv_count
lv_unit
TYPE sydatum,
TYPE kopos,
TYPE kpein,
is_bapiret2
TYPE bapiret2,
= '$000000001'.
= '$000000001'.
is_bapicondhd-created_by = sy-uname.
is_bapicondhd-creat_date = sy-datum.
is_bapicondhd-cond_usage = 'A'.
is_bapicondhd-table_no = '700'.
is_bapicondhd-applicatio = 'V'.
is_bapicondhd-cond_type = lc_kschl_z123.
is_bapicondhd-varkey
= is_bapicondct-varkey.
is_bapicondhd-valid_to = '12/31/2009'.
is_bapicondhd-valid_from = lv_datum.
*** BAPI Structure of KONP with English Field Names
CLEAR is_bapicondit.
is_bapicondit-operation = '009'.
is_bapicondit-cond_no
= '$000000001'.
is_bapicondit-cond_count = lv_count.
is_bapicondit-applicatio = 'V'.
is_bapicondit-cond_type = lc_kschl_z123.
is_bapicondit-scaletype = 'A'.
is_bapicondit-scalebasin = 'B'.
ADD 1 TO is_bapicondit-scale_qty.
is_bapicondit-calctypcon = 'B'.
lv_unit = wa_vbap-kwmeng.
is_bapicondit-cond_p_unt = lv_unit.
is_bapicondit-cond_value = wa_vbap-value.
is_bapicondit-condcurr = wa_vbap-waerk.
APPEND: is_bapicondct TO it_bapicondct,
is_bapicondhd TO it_bapicondhd,
is_bapicondit TO it_bapicondit.
ENDLOOP.
*** BAPI for pricing Condition Records
CALL FUNCTION 'BAPI_PRICES_CONDITIONS'
TABLES
ti_bapicondct = it_bapicondct
ti_bapicondhd = it_bapicondhd
ti_bapicondit = it_bapicondit
ti_bapicondqs = it_bapicondqs
ti_bapicondvs = it_bapicondvs
to_bapiret2
= it_bapiret2
to_bapiknumhs = it_bapiknumhs
to_mem_initial = it_mem_initial
EXCEPTIONS
update_error = 1
OTHERS
= 2.
IF sy-subrc EQ 0.
WRITE: /1 'Return Messages for Condition create'(t03).
LOOP AT it_bapiret2 INTO is_bapiret2.
WRITE: /1 is_bapiret2-message.
ENDLOOP.
ULINE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
IMPORTING
return = is_bapiret2.
ENDIF.
Correct AnswerRe: Bapi to create pricing condition\VK11
condition_table
=' '
" 3 character cond. table
condition_type
='
' " cond. type
date_from
= '20120101' " valid on
date_to
= '99991231' " valid to
enqueue
= 'X'
" lock entry
i_komk
= komk
i_komp
= komp
key_fields
= ls_komg " key fields
maintain_mode
= 'B'
" A= create " B= change, " C= display " D= create
no_authority_check
= 'X'
selection_date
= '20120101' " valid on
keep_old_records
=''
overlap_confirmed
= 'X'
no_db_update
= space
IMPORTING
e_komk
= komk
e_komp
= komp
new_record
= lv_new_record
TABLES
copy_records
= lt_komv
EXCEPTIONS
enqueue_on_record
=1
invalid_application
=2
invalid_condition_number = 3
invalid_condition_type = 4
no_selection
=5
table_not_valid
=6
no_authority_ekorg
=7
no_authority_kschl
= 8.
IF sy-subrc = 0.
CALL FUNCTION 'RV_CONDITION_SAVE'.
COMMIT WORK.
CALL FUNCTION 'RV_CONDITION_RESET'.
"necessary to write data
COMMIT WORK.
WRITE:/ 'Success'.
ELSE.
WRITE: / 'Error'.
ENDIF.
Cheers
~Niranjan
Ferry Lianto Apr 13, 2006 9:01 PM (in response to Martn Becker)
Hi Martin,
wtable1-operation = '009'.
wtable1-varkey = '13001001USD 000000000050068946'.
wtable1-valid_to = '99991231'.
wtable1-valid_from = '20051101'.
wtable1-cond_no = 'wtable1-table_no = '306'.
wtable1-applicatio = 'V'.
wtable1-cond_type = 'ZPR0'.
wtable1-operation = '009'.
wtable1-varkey = '13001001USD 000000000050068946'.
wtable1-valid_to = '99991231'.
wtable1-valid_from = '20051101'.
wtable1-cond_no = '$000000001'.
APPEND wtable1 TO table1.
wtable2-operation = '009'.
wtable2-cond_no = '$000000001'.
wtable2-created_by = sy-uname.
wtable2-creat_date = '20051022'.
wtable2-cond_usage = 'A'.
wtable2-table_no = '110'.
wtable2-applicatio = 'V'.
wtable2-cond_type = 'ZPR0'.
wtable2-varkey = '13001001USD 000000000050068946'.
wtable2-valid_from = '20051101'.
wtable2-valid_to = '99991231'.
APPEND wtable2 TO table2.
wtable3-operation = '009'.
wtable3-cond_no = '$000000001'.
wtable3-cond_count = '01'.
wtable3-applicatio = 'V'.
wtable3-cond_type = 'ZPR0'.
wtable3-scaletype = 'A'.
wtable3-scalebasin = 'C'.
wtable3-scale_qty = '1'.
wtable3-cond_p_unt = '1'.
wtable3-cond_unit = 'EA'.
wtable3-calctypcon = 'C'.
wtable3-cond_value = '454'.
wtable3-condcurr = 'USD'.
APPEND wtable3 TO table3.
CALL FUNCTION 'BAPI_PRICES_CONDITIONS'
* EXPORTING
* PI_initialmode = 'X'
* PI_BLOCKNUMBER =
TABLES
ti_bapicondct = table1
ti_bapicondhd = table2
ti_bapicondit = table3
ti_bapicondqs = table4
ti_bapicondvs = table5
to_bapiret2 = table6
to_bapiknumhs = table7
to_mem_initial = table8
EXCEPTIONS
update_error = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
READ TABLE table6 WITH KEY type = 'E' TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
loop at table6 into ret.
write: / ret-type, ret-message, ret-id, RET-LOG_NO, RET-LOG_MSG_NO,
RET-MESSAGE_V1, RET-MESSAGE_V2, RET-MESSAGE_V3, RET-MESSAGE_V4,
RET-PARAMETER,RET-ROW,RET-FIELD.
endloop.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
*EXPORTING
* WAIT =
IMPORTING
return = ret
.
ENDIF.'.
APPEND wtable1 TO table1.
wtable2-operation = '009'.
wtable2-cond_no = 'wtable1-table_no = '306'.
wtable1-applicatio = 'V'.
wtable1-cond_type = 'ZPR0'.
wtable1-operation = '009'.
wtable1-varkey = '13001001USD 000000000050068946'.
wtable1-valid_to = '99991231'.
wtable1-valid_from = '20051101'.
wtable1-cond_no = '$000000001'.
APPEND wtable1 TO table1.
wtable2-operation = '009'.
wtable2-cond_no = '$000000001'.
wtable2-created_by = sy-uname.
wtable2-creat_date = '20051022'.
wtable2-cond_usage = 'A'.
wtable2-table_no = '110'.
wtable2-applicatio = 'V'.
wtable2-cond_type = 'ZPR0'.
wtable2-varkey = '13001001USD 000000000050068946'.
wtable2-valid_from = '20051101'.
wtable2-valid_to = '99991231'.
APPEND wtable2 TO table2.
wtable3-operation = '009'.
wtable3-cond_no = '$000000001'.
wtable3-cond_count = '01'.
wtable3-applicatio = 'V'.
wtable3-cond_type = 'ZPR0'.
wtable3-scaletype = 'A'.
wtable3-scalebasin = 'C'.
wtable3-scale_qty = '1'.
wtable3-cond_p_unt = '1'.
wtable3-cond_unit = 'EA'.
wtable3-calctypcon = 'C'.
wtable3-cond_value = '454'.
wtable3-condcurr = 'USD'.
APPEND wtable3 TO table3.
CALL FUNCTION 'BAPI_PRICES_CONDITIONS'
* EXPORTING
* PI_initialmode = 'X'
* PI_BLOCKNUMBER =
TABLES
ti_bapicondct = table1
ti_bapicondhd = table2
ti_bapicondit = table3
ti_bapicondqs = table4
ti_bapicondvs = table5
to_bapiret2 = table6
to_bapiknumhs = table7
to_mem_initial = table8
EXCEPTIONS
update_error = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
READ TABLE table6 WITH KEY type = 'E' TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
loop at table6 into ret.
write: / ret-type, ret-message, ret-id, RET-LOG_NO, RET-LOG_MSG_NO,
RET-MESSAGE_V1, RET-MESSAGE_V2, RET-MESSAGE_V3, RET-MESSAGE_V4,
RET-PARAMETER,RET-ROW,RET-FIELD.
endloop.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
*EXPORTING
* WAIT =
IMPORTING
return = ret
.
ENDIF.'.
wtable2-created_by = sy-uname.
wtable2-creat_date = '20051022'.
wtable2-cond_usage = 'A'.
wtable2-table_no = '110'.
wtable2-applicatio = 'V'.
wtable2-cond_type = 'ZPR0'.
wtable2-varkey = '13001001USD 000000000050068946'.
wtable2-valid_from = '20051101'.
wtable2-valid_to = '99991231'.
APPEND wtable2 TO table2.
wtable3-operation = '009'.
wtable3-cond_no = 'wtable1-table_no = '306'.
wtable1-applicatio = 'V'.
wtable1-cond_type = 'ZPR0'.
wtable1-operation = '009'.
wtable1-varkey = '13001001USD 000000000050068946'.
wtable1-valid_to = '99991231'.
wtable1-valid_from = '20051101'.
wtable1-cond_no = '$000000001'.
APPEND wtable1 TO table1.
wtable2-operation = '009'.
wtable2-cond_no = '$000000001'.
wtable2-created_by = sy-uname.
wtable2-creat_date = '20051022'.
wtable2-cond_usage = 'A'.
wtable2-table_no = '110'.
wtable2-applicatio = 'V'.
wtable2-cond_type = 'ZPR0'.
wtable2-varkey = '13001001USD 000000000050068946'.
wtable2-valid_from = '20051101'.
wtable2-valid_to = '99991231'.
APPEND wtable2 TO table2.
wtable3-operation = '009'.
wtable3-cond_no = '$000000001'.
wtable3-cond_count = '01'.
wtable3-applicatio = 'V'.
wtable3-cond_type = 'ZPR0'.
wtable3-scaletype = 'A'.
wtable3-scalebasin = 'C'.
wtable3-scale_qty = '1'.
wtable3-cond_p_unt = '1'.
wtable3-cond_unit = 'EA'.
wtable3-calctypcon = 'C'.
wtable3-cond_value = '454'.
wtable3-condcurr = 'USD'.
APPEND wtable3 TO table3.
CALL FUNCTION 'BAPI_PRICES_CONDITIONS'
* EXPORTING
* PI_initialmode = 'X'
* PI_BLOCKNUMBER =
TABLES
ti_bapicondct = table1
ti_bapicondhd = table2
ti_bapicondit = table3
ti_bapicondqs = table4
ti_bapicondvs = table5
to_bapiret2 = table6
to_bapiknumhs = table7
to_mem_initial = table8
EXCEPTIONS
update_error = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
READ TABLE table6 WITH KEY type = 'E' TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
loop at table6 into ret.
write: / ret-type, ret-message, ret-id, RET-LOG_NO, RET-LOG_MSG_NO,
RET-MESSAGE_V1, RET-MESSAGE_V2, RET-MESSAGE_V3, RET-MESSAGE_V4,
RET-PARAMETER,RET-ROW,RET-FIELD.
endloop.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
*EXPORTING
* WAIT =
IMPORTING
return = ret
.
ENDIF.'.
wtable3-cond_count = '01'.
wtable3-applicatio = 'V'.
wtable3-cond_type = 'ZPR0'.
wtable3-scaletype = 'A'.
wtable3-scalebasin = 'C'.
wtable3-scale_qty = '1'.
wtable3-cond_p_unt = '1'.
wtable3-cond_unit = 'EA'.
wtable3-calctypcon = 'C'.
wtable3-cond_value = '454'.
wtable3-condcurr = 'USD'.
APPEND wtable3 TO table3.
CALL FUNCTION 'BAPI_PRICES_CONDITIONS'
* EXPORTING
* PI_initialmode = 'X'
* PI_BLOCKNUMBER =
TABLES
ti_bapicondct = table1
ti_bapicondhd = table2
ti_bapicondit = table3
ti_bapicondqs = table4
ti_bapicondvs = table5
to_bapiret2 = table6
to_bapiknumhs = table7
to_mem_initial = table8
EXCEPTIONS
update_error = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
READ TABLE table6 WITH KEY type = 'E' TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
loop at table6 into ret.
write: / ret-type, ret-message, ret-id, RET-LOG_NO, RET-LOG_MSG_NO,
RET-MESSAGE_V1, RET-MESSAGE_V2, RET-MESSAGE_V3, RET-MESSAGE_V4,
RET-PARAMETER,RET-ROW,RET-FIELD.
endloop.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
*EXPORTING
* WAIT =
IMPORTING
return = ret
.
ENDIF.
Also there are other options:
- from LSMW the report RV14BTCI
- batch input to transaction XK15
- using FM modules RV_CONDITION* (e.g. _copy and _save)