View previous topic :: View next topic
Author
Message
admin Администратор Joined: 01 Sep 2007 Posts: 1640
Posted: Sat Oct 27, 2007 2:06 pm Post subject: BAPI_PRICES_CONDITIONS - create pricing conditions for sales
Code:
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> i_ausg-datbi
ENDFORM. " zeitvergleich
*---------------------------------------------------------------------*
* Form bapi_fuellen
*---------------------------------------------------------------------*
FORM bapi_fuellen USING tabelle operation erhoehung " X = JA
kschl knumh_alt
datab_neu
datbi_neu
kbetr_neu.
* hier muss also jetzt der BAPI gefüllt werden
* siehe auch https://www.sdn.sap.com/irj/sdn/thread?threadID=79265
IF operation = 'ANLEGEN'. " ==> Kondition wird NICHT 'geändert'
* Neue KonditionsNr holen für Neuanlage Kondition
CLEAR: knumh_new.
CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
nr_range_nr = '01'
object = 'KONH'
IMPORTING
number = knumh_new
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
* problems with the number range
PERFORM error_message_syst CHANGING ls_return.
APPEND ls_return TO to_bapiret2.
CHECK 1 = 2.
ENDIF.
ENDIF. " operation = 'ANLEGEN'
* Inhalte aus Axxx
CLEAR: ti_bapicondct.
* ti_bapicondct-operation
*003 Löschen: Nachricht enthält Objekte, die zu Löschen sind.
*004 Änderung: Nachricht enthält Änderungen
*005 Ersetze: Diese Nachricht ersetzt vorige Nachrichten
*009 Original: erste Nachricht zum Vorgang
*023 Warte/Abgleich: Daten sollen nicht eingespielt werden
*018 Wiederversenden
IF operation = 'AENDERN'.
ti_bapicondct-operation = '004'.
ELSEIF operation = 'ANLEGEN'.
ti_bapicondct-operation = '009'.
ENDIF. " operation = 'AENDERN'
ti_bapicondct-cond_usage = dd02l_tabname(1).
ti_bapicondct-table_no = dd02l_tabname+1(3).
ti_bapicondct-applicatio = p_kappl. " Fix V
ti_bapicondct-cond_type = kschl.
IF tabelle = 'A914'.
CONCATENATE a914-vkorg a914-vtweg " a914-kunnr
a914-matnr INTO help_vakey.
ELSEIF tabelle = 'A915'.
CONCATENATE a915-vkorg a915-vtweg a915-kunnr
a915-matnr INTO help_vakey.
ELSEIF tabelle = 'A916'.
CONCATENATE a916-vkorg a916-vtweg a916-pltyp
a916-waerk INTO help_vakey.
help_vakey+13 = a916-matnr.
ELSEIF tabelle = 'A918'.
CONCATENATE a918-spart a918-matnr
INTO help_vakey.
ENDIF. " Tabelle = 'A914'
* CONDENSE help_vakey NO-GAPS.
ti_bapicondct-varkey = help_vakey.
* Konditionsdatum gültig bis
ti_bapicondct-valid_to = datbi_neu.
* ti_bapicondct-AGREE_COND =
ti_bapicondct-valid_from = datab_neu.
IF operation = 'ANLEGEN'.
ti_bapicondct-cond_no = knumh_new.
ELSEIF operation = 'AENDERN'.
ti_bapicondct-cond_no = knumh_alt.
ENDIF. " operation = 'ANLEGEN'
* ti_bapicondct-VADAT =
APPEND ti_bapicondct.
* Inhalte aus KONH mit KNUMH aus Axxx
CLEAR: ti_bapicondhd.
ti_bapicondhd-operation = ti_bapicondct-operation.
* ti_bapicondhd-SD_DOC = VBELN
* ti_bapicondhd-ITM_NUMBER = POSNR
ti_bapicondhd-cond_no = ti_bapicondct-cond_no.
ti_bapicondhd-applicatio = p_kappl. " Fix V.
ti_bapicondhd-cond_type = kschl.
ti_bapicondhd-created_by = sy-uname.
ti_bapicondhd-creat_date = sy-datum.
ti_bapicondhd-cond_usage = ti_bapicondct-cond_usage.
ti_bapicondhd-table_no = ti_bapicondct-table_no.
ti_bapicondhd-varkey = help_vakey.
ti_bapicondhd-valid_from = datab_neu.
ti_bapicondhd-valid_to = datbi_neu.
* ti_bapicondhd-SEARCHTERM = KOSRT
* ti_bapicondhd-RESPONS = KZUST
* ti_bapicondhd-PROMOT_NO = KNUMA_PI
* ti_bapicondhd-SALES_DEAL = KNUMA_AG
* ti_bapicondhd-SALESQUOTE = KNUMA_SQ
* ti_bapicondhd-STD_AGRMNT = KNUMA_SD
* ti_bapicondhd-PROMOTION = AKTNR
* ti_bapicondhd-REBAGREEMT = KNUMA_BO
* ti_bapicondhd-LIC_NO = LICNO
* ti_bapicondhd-LIC_DATE = LICDT
* ti_bapicondhd-VARDATE = VADAT
APPEND ti_bapicondhd.
* Inhalte aus KONP mit KNUMH aus Axxx
CLEAR: ti_bapicondit.
SELECT * FROM konp CLIENT SPECIFIED INTO help_konp
WHERE mandt = sy-mandt AND knumh = knumh_alt.
* keine Konditionen mit Löschkennzeichen anlegen
IF help_konp-loevm_ko IS INITIAL.
ti_bapicondit-operation = ti_bapicondct-operation.
ti_bapicondit-cond_no = ti_bapicondct-cond_no.
ti_bapicondit-cond_count = help_konp-kopos.
ti_bapicondit-applicatio = help_konp-kappl.
ti_bapicondit-cond_type = help_konp-kschl.
ti_bapicondit-text_no = help_konp-knumt.
ti_bapicondit-scaletype = help_konp-stfkz.
ti_bapicondit-scalebasin = help_konp-kzbzg.
ti_bapicondit-scale_qty = help_konp-kstbm.
ti_bapicondit-unitmeasur = help_konp-konms.
* ti_bapicondit-measur_iso = help_konp-.
*** ti_bapicondit-scale_val = help_konp-kstbw.
* ti_bapicondit-scale_val = kbetr_neu. "!!!!!
* ti_bapicondit-currenckey = help_konp-konws.
* ti_bapicondit-curren_iso = help_konp-konws.
ti_bapicondit-calctypcon = help_konp-krech.
* Prozentwerte werden falsch umgerechnet!!!
IF help_konp-konwa = '%'.
kbetr_neu = kbetr_neu / 10.
ENDIF.
ti_bapicondit-cond_value = kbetr_neu. "!!!!!
ti_bapicondit-condcurr = help_konp-konwa.
* ti_bapicondit-cond_iso = help_konp-konwa.
ti_bapicondit-cond_p_unt = help_konp-kpein.
ti_bapicondit-cond_unit = help_konp-kmein.
* ti_bapicondit-conunitiso = help_konp-.
ti_bapicondit-pricelevel = help_konp-prsch.
ti_bapicondit-numconvert = help_konp-kumza.
ti_bapicondit-denominato = help_konp-kumne.
ti_bapicondit-base_uom = help_konp-meins.
* ti_bapicondit-baseqtyiso = help_konp-.
*** ti_bapicondit-lowerlimit = help_konp-mxwrt.
*** ti_bapicondit-upperlimit = help_konp-gkwrt.
*** ti_bapicondit-plcondval = help_konp-pkwrt. " ???
*** ti_bapicondit-cum_value = help_konp-fkwrt. " ???
*** ti_bapicondit-cumm_accr = help_konp-rswrt. " ???
* ti_bapicondit-lowerlimit = kbetr_neu. "!!!!!
* ti_bapicondit-upperlimit = kbetr_neu. "!!!!!
* ti_bapicondit-plcondval = kbetr_neu. "!!!!!
* ti_bapicondit-cum_value = kbetr_neu. "!!!!!
* ti_bapicondit-cumm_accr = kbetr_neu. "!!!!!
* ti_bapicondit-CURRENCY = help_konp-konwa.
* ti_bapicondit-CURR_ISO = help_konp-.
ti_bapicondit-condcurren = help_konp-kwaeh.
* ti_bapicondit-ISOCURRENC = help_konp-.
**** ti_bapicondit-plan_basis = help_konp-ukbas.
* ti_bapicondit-plan_basis = kbetr_neu. "!!!!!
* ti_bapicondit-RATE_UNIT = help_konp-.
ti_bapicondit-exclusion = help_konp-kznep.
ti_bapicondit-customer = help_konp-kunnr.
ti_bapicondit-vendor_no = help_konp-lifnr.
ti_bapicondit-tax_code = help_konp-mwsk1.
ti_bapicondit-indidelete = help_konp-loevm_ko.
ti_bapicondit-conditidx = help_konp-zaehk_ind.
ti_bapicondit-matlsettl = help_konp-bomat.
*** ti_bapicondit-accruals = help_konp-kbrue.
* ti_bapicondit-accruals = kbetr_neu. "!!!!!
ti_bapicondit-reb_retroa = help_konp-kspae.
ti_bapicondit-statofagre = help_konp-bosta.
ti_bapicondit-promot_no = help_konp-knuma_pi.
ti_bapicondit-sales_deal = help_konp-knuma_ag.
ti_bapicondit-salesquote = help_konp-knuma_sq.
ti_bapicondit-add_val_dy = help_konp-valtg.
ti_bapicondit-fix_val_dy = help_konp-valdt.
ti_bapicondit-pmnttrms = help_konp-zterm.
ti_bapicondit-numborders = help_konp-anzauf.
ti_bapicondit-minconbava = help_konp-mikbas.
ti_bapicondit-maxconbava = help_konp-mxkbas.
*** ti_bapicondit-maxconval = help_konp-komxwrt.
* ti_bapicondit-maxconval = kbetr_neu. "!!!!!
ti_bapicondit-incr_scale = help_konp-klf_stg.
ti_bapicondit-pricscale = help_konp-klf_kal.
ti_bapicondit-relprcg = help_konp-vkkal.
ti_bapicondit-promotion = help_konp-aktnr.
ti_bapicondit-rebagreemt = help_konp-knuma_bo.
ti_bapicondit-withtaxcod = help_konp-mwsk2.
ti_bapicondit-contract = help_konp-vertt.
ti_bapicondit-contractno = help_konp-vertn.
ti_bapicondit-flow_type = help_konp-vbewa.
ti_bapicondit-indimatmai = help_konp-mdflg.
ti_bapicondit-status = help_konp-kfrst.
ti_bapicondit-umsabst = help_konp-uasta.
APPEND ti_bapicondit.
ENDIF. " help_konp-LOEVM_KO is initial
ENDSELECT. " FROM konp
* IF ti_bapicondit-cond_no IS INITIAL.
** alle Pos mit Löschkennzeichen
** CONTINUE.
* ENDIF.
* Inhalte aus KONM Konditionen (Mengenstaffel 1-dimensional)
CLEAR: ti_bapicondqs.
SELECT * FROM konm CLIENT SPECIFIED INTO help_konm
WHERE mandt = sy-mandt AND knumh = knumh_alt.
ti_bapicondqs-operation = ti_bapicondct-operation.
* TI_BAPICONDQS-SD_DOC = VBELN.
* ti_bapicondqs-itm_number = posnr.
ti_bapicondqs-cond_no = ti_bapicondct-cond_no.
ti_bapicondqs-cond_count = help_konm-kopos.
ti_bapicondqs-line_no = help_konm-klfn1.
ti_bapicondqs-scale_qty = help_konm-kstbm.
ti_bapicondqs-cond_unit = help_konp-kmein.
* ti_bapicondqs-t_unit_iso =
*** Prozentwerte werden falsch umgerechnet!!!
**** TNT: bitte prüfen ob diese Umsetzung erforderlich ist !!!!!
*** IF help_konp-konwa = '%'.
*** help_konm-kbetr = help_konm-kbetr / 10.
*** ENDIF.
*** ti_bapicondqs-currency = help_konm-kbetr.
clear: kbetr_neu.
if erhoehung = 'X'.
PERFORM preisanpassung USING help_konm-kbetr kbetr_neu.
else.
kbetr_neu = help_konm-kbetr.
endif. " erhoehung = 'X'
ti_bapicondqs-currency = kbetr_neu.
ti_bapicondqs-condcurr = help_konp-konwa.
* ti_bapicondqs-curren_iso =
APPEND: ti_bapicondqs.
CLEAR: help_konm.
ENDSELECT. " from konm
* Inhalte aus KONW Konditionen (Wertstaffel 1-dimensional)
CLEAR: ti_bapicondvs.
SELECT * FROM konw CLIENT SPECIFIED INTO help_konw
WHERE mandt = sy-mandt AND knumh = knumh_alt.
ti_bapicondvs-operation = ti_bapicondct-operation.
* ti_bapicondvs-SD_DOC = VBELN.
* ti_bapicondvs-ITM_NUMBER = POSNR.
ti_bapicondvs-cond_no = ti_bapicondct-cond_no.
ti_bapicondvs-cond_count = help_konw-kopos.
ti_bapicondvs-line_no = help_konw-klfn1.
*** ti_bapicondvs-scale_val = help_konw-kstbw.
ti_bapicondvs-currenckey = help_konp-konws.
* ti_bapicondvs-CURRENCISO =
**** Prozentwerte werden falsch umgerechnet!!!
**** TNT: bitte prüfen ob diese Umsetzung erforderlich ist !!!!!
*** IF help_konp-konwa = '%'.
*** help_konw-kbetr = help_konw-kbetr / 10.
*** ENDIF.
clear: kbetr_neu.
if erhoehung = 'X'.
PERFORM preisanpassung USING help_konw-kbetr kbetr_neu.
else.
kbetr_neu = help_konw-kbetr.
endif. " erhoehung = 'X'
ti_bapicondvs-currency = kbetr_neu.
ti_bapicondvs-condcurr = help_konp-konwa.
* ti_bapicondvs-CURREN_ISO =
APPEND: ti_bapicondvs.
ENDSELECT. " from konw
ENDFORM. " bapi_fuellen
*--------------------------------------------------------------------*
* Form error_message_syst
*--------------------------------------------------------------------*
FORM error_message_syst CHANGING pc_return TYPE bapiret2.
CALL FUNCTION 'BALW_BAPIRETURN_GET2'
EXPORTING
type = sy-msgty
cl = sy-msgid
number = sy-msgno
par1 = sy-msgv1
par2 = sy-msgv2
par3 = sy-msgv3
par4 = sy-msgv4
IMPORTING
return = pc_return.
ENDFORM. " error_message_syst
*---------------------------------------------------------------------*
* Form bapi_buchen
*---------------------------------------------------------------------*
FORM bapi_buchen.
* nu geiht datt los, denn man tau
CALL FUNCTION 'BAPI_PRICES_CONDITIONS'
* EXPORTING
* PI_INITIALMODE = ' '
* PI_BLOCKNUMBER =
TABLES
ti_bapicondct = ti_bapicondct
ti_bapicondhd = ti_bapicondhd
ti_bapicondit = ti_bapicondit
ti_bapicondqs = ti_bapicondqs
ti_bapicondvs = ti_bapicondvs
to_bapiret2 = to_bapiret2
to_bapiknumhs = to_bapiknumhs
to_mem_initial = to_mem_initial
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 to_bapiret2 WITH KEY type = 'E'
TRANSPORTING NO FIELDS.
IF sy-subrc = 0. " READ TABLE to_bapiret2
LOOP AT to_bapiret2 WHERE type NE 'I'
AND type NE 'S'
AND type NE 'W'.
* TNT
* WRITE: / to_bapiret2-type, to_bapiret2-message,
* to_bapiret2-id, to_bapiret2-log_no,
* to_bapiret2-log_msg_no, to_bapiret2-message_v1,
* to_bapiret2-message_v2, to_bapiret2-message_v3,
* to_bapiret2-message_v4, to_bapiret2-parameter,
* to_bapiret2-row, to_bapiret2-field.
CONCATENATE to_bapiret2-type to_bapiret2-id(4)
to_bapiret2-number to_bapiret2-message
INTO fehler_tab-line SEPARATED BY ' '.
APPEND fehler_tab.
ENDLOOP. " AT to_bapiret2
ELSE. " sy-subrc = 0. " READ TABLE to_bapiret2
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* WAIT =
IMPORTING
return = to_bapiret2.
* Erfolgsmeldung schreiben
DESCRIBE TABLE ti_bapicondhd LINES sy-tfill.
DATA: help_tfill(10).
MOVE sy-tfill TO help_tfill.
CONCATENATE help_tfill
'Konditionen bearbeitet.'(104)
INTO fehler_tab-line SEPARATED BY ' '.
APPEND fehler_tab.
* und noch 'markieren'
*TNT it_daten-erfolg = 'KOND'.
*TNT MODIFY it_daten.
ENDIF. " sy-subrc = 0. " READ TABLE to_bapiret2
CLEAR: ti_bapicondct, ti_bapicondhd, ti_bapicondit,
ti_bapicondqs, ti_bapicondvs, to_bapiret2,
to_bapiknumhs, to_mem_initial.
REFRESH: ti_bapicondct, ti_bapicondhd, ti_bapicondit,
ti_bapicondqs, ti_bapicondvs, to_bapiret2,
to_bapiknumhs, to_mem_initial.
ENDFORM. " bapi_buchen
Back to top
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.