Brief overview of BAPI_PRICES_CONDITIONS: is the unreleased BAPI and deficient in many aspects as there is missing documentation and also the BAPI has structural defects. This BAPI fairs not so well when compared to VK11 BDC updates [ or other application transactions ] or Idoc Creation. However like all BAPIs, we can rollback our changes in mass and the use of it to load all conditions from excel file and if any error, rollback is one of the reasons I would recommend to use this.
However the BAPI_PRICES_CONDITIONS has many structural issues that need to be addressed.
1. There is no update task when a condition is committed.
2. Test mode.
3. There are no validations happening in the BAPI
4. If the conditions are overlapped, one needs to handle it in more detail.
5. If the condition is in non blocked mode, we need to pass the certain fields.
6. The change pointers which are used to workflow approval need to be considered
All these are covered in this blog post.
1. Update Task: As the BAPI does not do an update task , we need to careful with rollback and commit based on BAPI return parameters .
2. Use it in Test mode: Especially one can use in test mode with condition like TESTMODE, thus conditions are not lost. It should also be part of training to first run in test mode then save as we can conserve condition numbers.
3. Validations in BAPI: As the BAPI does not do custom validations, it would be good to do validations before we call the BAPI
4. Conditions overlapped: BAPI itself does not handle condition overlap. So it needs to be broken down into 4 distinct areas , which means we need to call the BAPI for all overlaps in four phases
PHASE 1: All old conditions valid from outside but valid to lying in the new condition validfrom-validto. But since valid to is a key in the condition table, we need to delete operation 003( Delete) and then change operation (004).
However the BAPI_PRICES_CONDITIONS has many structural issues that need to be addressed.
1. There is no update task when a condition is committed.
2. Test mode.
3. There are no validations happening in the BAPI
4. If the conditions are overlapped, one needs to handle it in more detail.
5. If the condition is in non blocked mode, we need to pass the certain fields.
6. The change pointers which are used to workflow approval need to be considered
All these are covered in this blog post.
1. Update Task: As the BAPI does not do an update task , we need to careful with rollback and commit based on BAPI return parameters .
2. Use it in Test mode: Especially one can use in test mode with condition like TESTMODE, thus conditions are not lost. It should also be part of training to first run in test mode then save as we can conserve condition numbers.
3. Validations in BAPI: As the BAPI does not do custom validations, it would be good to do validations before we call the BAPI
4. Conditions overlapped: BAPI itself does not handle condition overlap. So it needs to be broken down into 4 distinct areas , which means we need to call the BAPI for all overlaps in four phases
PHASE 1: All old conditions valid from outside but valid to lying in the new condition validfrom-validto. But since valid to is a key in the condition table, we need to delete operation 003( Delete) and then change operation (004).
PHASE 2: Delete all old conditions within the the current validfrom-validto.
PHASE 3: All old conditions valid to outside but valid from lying in the new condition validfrom-validto. All these conditions can just be changed operation 004.
PHASE 4: Create new condition , operation 009.
5. Blocked condition: Just like the condition key is passed through varkey, the blocked status can be passed by vardate. ls_bapicondhd–varkey = ls_varkey_header.
ls_bapicondhd–vardate = ls_vardat_header.
6. Change pointer: The trick here is to pass in PHASE 4 for the new condition where db_ykonp is essentially empty except for certain fields. The change pointer can be invoked using function SD_CONDITION_CHANGE_DOCS_WRITE.
Check the code snippet below for the above five main handling.
Code Snippet
LOOP AT gt_upload ASSIGNING <fs_gt_upload>.
lv_amount = <fs_gt_upload>-old_price +
<fs_gt_upload>-act .
READ TABLE lt_tcurc ASSIGNING <fs_lt_tcurc>
WITH KEY waers = <fs_gt_upload>-waers.
IF sy-subrc IS NOT INITIAL.
<fs_gt_upload>-icon = icon_cancel.
IF <fs_gt_upload>-waers IS NOT INITIAL.
<fs_gt_upload>-message = 'Invalid Currency'.
ELSE.
<fs_gt_upload>-message = 'Currency is not Filled'.
ENDIF.
ENDIF.
READ TABLE lt_marm ASSIGNING <fs_lt_marm>
WITH KEY matnr = <fs_gt_upload>-matnr
meinh = <fs_gt_upload>-kmein.
IF sy-subrc IS NOT INITIAL.
<fs_gt_upload>-icon = icon_cancel.
IF <fs_gt_upload>-kmein IS NOT INITIAL.
<fs_gt_upload>-message = 'Invalid UOM'.
ELSE.
<fs_gt_upload>-message = 'UOM is not Filled'.
ENDIF.
ENDIF.
READ TABLE lt_mara ASSIGNING <fs_lt_mara>
WITH KEY matnr = <fs_gt_upload>-matnr.
IF sy-subrc IS NOT INITIAL.
<fs_gt_upload>-icon = icon_cancel.
IF <fs_gt_upload>-matnr IS NOT INITIAL.
<fs_gt_upload>-message = 'Invalid Material'.
ELSE.
<fs_gt_upload>-message = 'Material is not Filled'.
ENDIF.
ENDIF.
READ TABLE lt_kna1 ASSIGNING <fs_lt_kna1>
WITH KEY kunnr = <fs_gt_upload>-kunnr.
IF sy-subrc IS NOT INITIAL.
<fs_gt_upload>-icon = icon_cancel.
IF <fs_gt_upload>-kunnr IS NOT INITIAL.
<fs_gt_upload>-message = 'Invalid Customer'.
ELSE.
<fs_gt_upload>-message = 'Customer is not Filled'.
ENDIF.
ENDIF.
READ TABLE lt_history ASSIGNING <fs_lt_history>
WITH KEY kschl = <fs_gt_upload>-kschl
vkorg = <fs_gt_upload>-vkorg
vtweg = <fs_gt_upload>-vtweg
kunnr = <fs_gt_upload>-kunnr
matnr = <fs_gt_upload>-matnr
effective_date = <fs_gt_upload>-effective_date
effective_time = <fs_gt_upload>-effective_time.
IF sy-subrc IS INITIAL.
<fs_gt_upload>-icon = icon_cancel.
<fs_gt_upload>-message = 'Record already exists in table ZSD_VK11_REASON.'.
ENDIF.
IF <fs_gt_upload>-kbetr IS INITIAL.
<fs_gt_upload>-icon = icon_cancel.
<fs_gt_upload>-message = 'Amount is not filled.'.
CONTINUE.
ENDIF.
IF <fs_gt_upload>-effective_date IS INITIAL.
<fs_gt_upload>-icon = icon_cancel.
<fs_gt_upload>-message = 'Effective Date is not filled.'.
CONTINUE.
ENDIF.
IF <fs_gt_upload>-datab IS INITIAL.
<fs_gt_upload>-icon = icon_cancel.
<fs_gt_upload>-message = 'Valid from is not filled.'.
CONTINUE.
ENDIF.
IF <fs_gt_upload>-datbi IS INITIAL.
<fs_gt_upload>-icon = icon_cancel.
<fs_gt_upload>-message = 'Valid to is not filled.'.
CONTINUE.
ENDIF.
IF <fs_gt_upload>-kschl IS INITIAL.
<fs_gt_upload>-icon = icon_cancel.
<fs_gt_upload>-message = 'Condition Type is not filled.'.
CONTINUE.
ENDIF.
IF <fs_gt_upload>-vkorg IS INITIAL.
<fs_gt_upload>-icon = icon_cancel.
<fs_gt_upload>-message = 'Sales Org is not filled.'.
CONTINUE.
ENDIF.
IF <fs_gt_upload>-vtweg IS INITIAL.
<fs_gt_upload>-icon = icon_cancel.
<fs_gt_upload>-message = 'Distribution Channel is not filled.'.
CONTINUE.
ENDIF.
IF <fs_gt_upload>-kunnr IS INITIAL.
<fs_gt_upload>-icon = icon_cancel.
<fs_gt_upload>-message = 'Customer is not filled.'.
CONTINUE.
ENDIF.
IF <fs_gt_upload>-matnr IS INITIAL.
<fs_gt_upload>-icon = icon_cancel.
<fs_gt_upload>-message = 'Material is not filled.'.
CONTINUE.
ENDIF.
IF lv_amount = <fs_gt_upload>-kbetr.
ELSE.
<fs_gt_upload>-icon = icon_cancel.
<fs_gt_upload>-message = 'Amount does not match Old Price + Price Change Components.'.
CONTINUE.
ENDIF.
CHECK <fs_gt_upload>-icon <> icon_cancel.
*1 Get all records before and into the current From/To
REFRESH: lt_a305[].
SELECT a305~kappl
a305~kschl
a305~vkorg
a305~vtweg
a305~kunnr
a305~matnr
a305~kfrst
a305~datbi
a305~datab
a305~kbstat
a305~knumh
konp~konwa
konp~kbetr
konp~kmein
konp~kpein
FROM a305
INNER JOIN konp ON konp~knumh = a305~knumh
APPENDING CORRESPONDING FIELDS OF TABLE lt_a305
WHERE a305~kappl = lcon_applicatio_v AND
a305~kschl = <fs_gt_upload>-kschl AND
a305~vkorg = <fs_gt_upload>-vkorg AND
a305~vtweg = <fs_gt_upload>-vtweg AND
a305~kunnr = <fs_gt_upload>-kunnr AND
a305~matnr = <fs_gt_upload>-matnr AND
a305~kfrst = lcon_kfrst_a AND
a305~datbi GE <fs_gt_upload>-datab AND
a305~datbi LE <fs_gt_upload>-datbi AND
a305~datab LT <fs_gt_upload>-datab.
LOOP AT lt_a305 ASSIGNING <fs_lt_a305>.
IF <fs_gt_upload>-icon <> icon_cancel.
ELSE.
EXIT.
ENDIF.
IF <fs_lt_a305>-kfrst = lcon_kfrst_a.
*1a Get all records before and into the current From/To:
* Delete the record
REFRESH: lt_bapicondct[],
lt_bapicondhd[],
lt_bapicondit[],
lt_bapicondqs[],
lt_bapicondvs[],
lte_bapiret2[],
lte_bapiknumhs[],
lte_mem_initial[].
CLEAR: ls_bapicondct,
ls_bapicondhd,
ls_bapicondit,
ls_bapicondqs,
ls_bapicondvs,
lse_bapiret2,
lse_bapiknumhs,
lse_mem_initial,
ls_varkey_a305_header,
ls_varkey_header,
ls_vardat_a305_header,
ls_vardat_header,
ls_varkey_item.
ls_bapicondct-operation = lcon_operation_003.
ls_bapicondct-cond_usage = lcon_cond_usage_a .
ls_bapicondct-table_no = lcon_table_no_305.
ls_varkey_a305_header-vkorg = <fs_lt_a305>-vkorg.
ls_varkey_a305_header-vtweg = <fs_lt_a305>-vtweg.
ls_varkey_a305_header-kunnr = <fs_lt_a305>-kunnr.
ls_varkey_a305_header-matnr = <fs_lt_a305>-matnr.
ls_varkey_a305_header-KFRST = <fs_lt_a305>-KFRST.
ls_varkey_header = ls_varkey_a305_header.
ls_vardat_a305_header-kbstat = <fs_lt_a305>-kbstat.
ls_vardat_header = ls_vardat_a305_header.
ls_bapicondct-cond_no = <fs_lt_a305>-knumh.
CLEAR: lv_knumh.
lv_knumh = ls_bapicondct-cond_no .
ls_bapicondct-applicatio = lcon_applicatio_v .
ls_bapicondct-cond_type = <fs_lt_a305>-kschl.
IF ls_bapicondct-cond_type IS INITIAL.
ls_bapicondct-cond_type = lcon_cond_type_pr00.
ENDIF.
ls_bapicondct-varkey = ls_varkey_header.
ls_bapicondct-vadat = ls_vardat_header.
ls_bapicondct-valid_to = <fs_lt_a305>-datbi. " lcon_valid_to.
ls_bapicondct-valid_from = <fs_lt_a305>-datab.
APPEND ls_bapicondct TO lt_bapicondct.
ls_bapicondhd-operation = ls_bapicondct-operation. "lcon_operation_009.
ls_bapicondhd-cond_no = ls_bapicondct-cond_no. "lcon_knumh_i .
ls_bapicondhd-created_by = sy-uname.
ls_bapicondhd-creat_date = sy-datum.
ls_bapicondhd-cond_usage = lcon_cond_usage_a .
ls_bapicondhd-table_no = ls_bapicondct-table_no.
ls_bapicondhd-applicatio = lcon_applicatio_v .
ls_bapicondhd-cond_type = ls_bapicondct-cond_type.
ls_bapicondhd-varkey = ls_varkey_header.
ls_bapicondhd-vardate = ls_vardat_header.
ls_bapicondhd-valid_from = <fs_lt_a305>-datab.
ls_bapicondhd-valid_to = <fs_lt_a305>-datbi. " lcon_valid_to.
APPEND ls_bapicondhd TO lt_bapicondhd.
ls_bapicondit-operation = ls_bapicondct-operation. "lcon_operation_009.
ls_bapicondit-cond_no = ls_bapicondct-cond_no. "lcon_knumh_i .
ls_bapicondit-cond_count = lcon_cond_count_i .
ls_bapicondit-applicatio = lcon_applicatio_v .
ls_bapicondit-cond_type = ls_bapicondct-cond_type.
* text_no
ls_bapicondit-scaletype = lcon_scale_type_c.
* scalebasin
* scale_qty
* unitmeasur
* measur_iso
* scale_val
* currenckey
* curren_iso
ls_bapicondit-calctypcon = lcon_calc_type_c.
ls_bapicondit-cond_value = <fs_lt_a305>-kbetr.
ls_bapicondit-condcurr = <fs_lt_a305>-konwa.
* ls_bapicondit-cond_iso
ls_bapicondit-cond_p_unt = <fs_lt_a305>-kpein.
ls_bapicondit-cond_unit = <fs_lt_a305>-kmein.
* conunitiso
* pricelevel
* numconvert
* denominato
* base_uom
* baseqtyiso
* lowerlimit
* upperlimit
* plcondval
* currency
* curr_iso
* condcurren
* isocurrenc
* plan_basis
* rate_unit
* exclusion
* customer
* vendor_no
* tax_code
* indidelete
* conditidx
* matlsettl
* accruals
* reb_retroa
* statofagre
* promot_no
* sales_deal
* salesquote
* add_val_dy
* fix_val_dy
* pmnttrms
* numborders
* minconbava
* maxconbava
* maxconval
* incr_scale
* pricscale
* relprcg
* promotion
* rebagreemt
* withtaxcod
* contract
* contractno
* flow_type
* indimatmai
ls_bapicondit-status = <fs_lt_a305>-KFRST.
* umsabst
* matlsettl_external
* matlsettl_guid
* matlsettl_version
APPEND ls_bapicondit TO lt_bapicondit.
refresh: db_xkondat[],
db_ykondat[],
db_xkonh[],
db_ykonh[],
db_xkonp[],
db_ykonp[],
db_xkonm[],
db_xkonw[],
db_ykonm[],
db_ykonw[].
select * from konh APPENDING CORRESPONDING FIELDS OF TABLE
db_ykonh where knumh = <fs_lt_a305>-knumh.
loop at db_ykonh ASSIGNING <fs_db_ykonh>.
<fs_db_ykonh>-updkz = 'U'.
ENDLOOP.
select * from konp APPENDING CORRESPONDING FIELDS OF TABLE
db_ykonp where knumh = <fs_lt_a305>-knumh.
loop at db_ykonp ASSIGNING <fs_db_ykonp>.
<fs_db_ykonp>-updkz = 'U'.
ENDLOOP.
CALL FUNCTION 'BAPI_PRICES_CONDITIONS'
EXPORTING
* PI_INITIALMODE = ' '
* PI_BLOCKNUMBER =
pi_physical_deletion = lv_del
TABLES
ti_bapicondct = lt_bapicondct
ti_bapicondhd = lt_bapicondhd
ti_bapicondit = lt_bapicondit
ti_bapicondqs = lt_bapicondqs
ti_bapicondvs = lt_bapicondvs
to_bapiret2 = lte_bapiret2
to_bapiknumhs = lte_bapiknumhs
to_mem_initial = lte_mem_initial
EXCEPTIONS
update_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
select * from konh APPENDING CORRESPONDING FIELDS OF TABLE
db_xkonh where knumh = <fs_lt_a305>-knumh.
loop at db_xkonh ASSIGNING <fs_db_xkonh>.
<fs_db_xkonh>-updkz = 'U'.
ENDLOOP.
select * from konp APPENDING CORRESPONDING FIELDS OF TABLE
db_xkonp where knumh = <fs_lt_a305>-knumh.
loop at db_xkonp ASSIGNING <fs_db_xkonp>.
<fs_db_xkonp>-updkz = 'U'.
ENDLOOP.
if db_xkondat[] is INITIAL.
loop at db_xkonh.
db_xkondat-knumh = db_xkonh-knumh.
db_xkondat-DATAN = ls_bapicondhd-valid_from.
read TABLE db_ykonh with key knumh = db_xkonh-knumh.
if sy-subrc is INITIAL.
db_xkondat-datab = db_ykonh-DATAB.
db_xkondat-datbi = db_ykonh-DATBI.
db_xkondat-kz = db_ykonh-updkz.
append db_xkondat.
else.
db_xkondat-datab = db_xkonh-DATAB.
db_xkondat-datbi = db_xkonh-DATBI.
db_xkondat-kz = db_xkonh-updkz.
append db_xkondat.
endif.
ENDLOOP.
endif.
if db_ykondat[] is INITIAL.
loop at db_ykonh.
db_ykondat-knumh = db_ykonh-knumh.
db_ykondat-DATAN = db_ykonh-DATAB.
db_ykondat-datab = db_ykonh-DATAB.
db_ykondat-datbi = db_ykonh-DATBI.
db_ykondat-kz = db_ykonh-updkz.
append db_ykondat.
ENDLOOP.
endif.
* write change documents
CALL FUNCTION 'SD_CONDITION_CHANGE_DOCS_WRITE'
TABLES
p_xkondat = db_xkondat
p_ykondat = db_ykondat
p_xkonh = db_xkonh
p_ykonh = db_ykonh
p_xkonp = db_xkonp
p_ykonp = db_ykonp
p_xkonm = db_xkonm
p_xkonw = db_xkonw
p_ykonm = db_ykonm
p_ykonw = db_ykonw.
LOOP AT lte_bapiret2 ASSIGNING <fs_lte_bapiret2>
WHERE type = 'E'.
EXIT.
ENDLOOP.
IF sy-subrc IS INITIAL.
<fs_gt_upload>-icon = icon_cancel.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
* IMPORTING
* RETURN =
.
ELSE.
LOOP AT lte_bapiret2 ASSIGNING <fs_lte_bapiret2>
WHERE type = 'S' OR type = 'W'.
EXIT.
ENDLOOP.
IF sy-subrc IS INITIAL.
* CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* wait = 'X'.
ELSE.
<fs_gt_upload>-icon = icon_cancel.
ENDIF.
ENDIF.
ENDIF.
IF <fs_gt_upload>-icon <> icon_cancel.
ELSE.
EXIT.
ENDIF.
*1b Get all records before and into the current From/To:
* Change the record to = current From - 1.
IF <fs_lt_a305>-kfrst = lcon_kfrst_a.
REFRESH: lt_bapicondct[],
lt_bapicondhd[],
lt_bapicondit[],
lt_bapicondqs[],
lt_bapicondvs[],
lte_bapiret2[],
lte_bapiknumhs[],
lte_mem_initial[].
CLEAR: ls_bapicondct,
ls_bapicondhd,
ls_bapicondit,
ls_bapicondqs,
ls_bapicondvs,
lse_bapiret2,
lse_bapiknumhs,
lse_mem_initial,
ls_varkey_a305_header,
ls_varkey_header,
ls_vardat_a305_header,
ls_vardat_header,
ls_varkey_item.
ls_bapicondct-operation = lcon_operation_004. "lcon_operation_009.
ls_bapicondct-cond_usage = lcon_cond_usage_a .
ls_bapicondct-table_no = lcon_table_no_305.
ls_varkey_a305_header-vkorg = <fs_lt_a305>-vkorg.
ls_varkey_a305_header-vtweg = <fs_lt_a305>-vtweg.
ls_varkey_a305_header-kunnr = <fs_lt_a305>-kunnr.
ls_varkey_a305_header-matnr = <fs_lt_a305>-matnr.
ls_varkey_a305_header-kfrst = <fs_lt_a305>-kfrst.
ls_varkey_header = ls_varkey_a305_header.
ls_vardat_a305_header-kbstat = <fs_lt_a305>-kbstat.
ls_vardat_header = ls_vardat_a305_header.
ls_bapicondct-cond_no = <fs_lt_a305>-knumh.
CLEAR: lv_knumh.
lv_knumh = ls_bapicondct-cond_no .
ls_bapicondct-applicatio = lcon_applicatio_v .
ls_bapicondct-cond_type = <fs_lt_a305>-kschl.
IF ls_bapicondct-cond_type IS INITIAL.
ls_bapicondct-cond_type = lcon_cond_type_pr00.
ENDIF.
ls_bapicondct-varkey = ls_varkey_header.
ls_bapicondct-vadat = ls_vardat_header.
ls_bapicondct-valid_to = <fs_gt_upload>-datab - 1.
ls_bapicondct-valid_from = <fs_lt_a305>-datab.
APPEND ls_bapicondct TO lt_bapicondct.
ls_bapicondhd-operation = ls_bapicondct-operation. "lcon_operation_009.
ls_bapicondhd-cond_no = ls_bapicondct-cond_no. "lcon_knumh_i .
ls_bapicondhd-created_by = sy-uname.
ls_bapicondhd-creat_date = sy-datum.
ls_bapicondhd-cond_usage = lcon_cond_usage_a .
ls_bapicondhd-table_no = ls_bapicondct-table_no.
ls_bapicondhd-applicatio = lcon_applicatio_v .
ls_bapicondhd-cond_type = ls_bapicondct-cond_type.
ls_bapicondhd-varkey = ls_varkey_header.
ls_bapicondhd-vardate = ls_vardat_header.
ls_bapicondhd-valid_from = <fs_gt_upload>-datab - 1.
ls_bapicondhd-valid_to = <fs_lt_a305>-datbi. " lcon_valid_to.
APPEND ls_bapicondhd TO lt_bapicondhd.
ls_bapicondit-operation = ls_bapicondct-operation. "lcon_operation_009.
ls_bapicondit-cond_no = ls_bapicondct-cond_no. "lcon_knumh_i .
ls_bapicondit-cond_count = lcon_cond_count_i .
ls_bapicondit-applicatio = lcon_applicatio_v .
ls_bapicondit-cond_type = ls_bapicondct-cond_type.
* text_no
ls_bapicondit-scaletype = lcon_scale_type_c.
* scalebasin
* scale_qty
* unitmeasur
* measur_iso
* scale_val
* currenckey
* curren_iso
ls_bapicondit-calctypcon = lcon_calc_type_c.
ls_bapicondit-cond_value = <fs_lt_a305>-kbetr.
ls_bapicondit-condcurr = <fs_lt_a305>-konwa.
* ls_bapicondit-cond_iso
ls_bapicondit-cond_p_unt = <fs_lt_a305>-kpein.
ls_bapicondit-cond_unit = <fs_lt_a305>-kmein.
* conunitiso
* pricelevel
* numconvert
* denominato
* base_uom
* baseqtyiso
* lowerlimit
* upperlimit
* plcondval
* currency
* curr_iso
* condcurren
* isocurrenc
* plan_basis
* rate_unit
* exclusion
* customer
* vendor_no
* tax_code
* indidelete
* conditidx
* matlsettl
* accruals
* reb_retroa
* statofagre
* promot_no
* sales_deal
* salesquote
* add_val_dy
* fix_val_dy
* pmnttrms
* numborders
* minconbava
* maxconbava
* maxconval
* incr_scale
* pricscale
* relprcg
* promotion
* rebagreemt
* withtaxcod
* contract
* contractno
* flow_type
* indimatmai
ls_bapicondit-status = <fs_lt_a305>-kfrst.
* umsabst
* matlsettl_external
* matlsettl_guid
* matlsettl_version
APPEND ls_bapicondit TO lt_bapicondit.
refresh: db_xkondat[],
db_ykondat[],
db_xkonh[],
db_ykonh[],
db_xkonp[],
db_ykonp[],
db_xkonm[],
db_xkonw[],
db_ykonm[],
db_ykonw[].
select * from konh APPENDING CORRESPONDING FIELDS OF TABLE
db_ykonh where knumh = <fs_lt_a305>-knumh.
loop at db_ykonh ASSIGNING <fs_db_ykonh>.
<fs_db_ykonh>-updkz = 'U'.
ENDLOOP.
select * from konp APPENDING CORRESPONDING FIELDS OF TABLE
db_ykonp where knumh = <fs_lt_a305>-knumh.
loop at db_ykonp ASSIGNING <fs_db_ykonp>.
<fs_db_ykonp>-updkz = 'U'.
ENDLOOP.
CALL FUNCTION 'BAPI_PRICES_CONDITIONS'
EXPORTING
* PI_INITIALMODE = ' '
* PI_BLOCKNUMBER =
pi_physical_deletion = lv_del
TABLES
ti_bapicondct = lt_bapicondct
ti_bapicondhd = lt_bapicondhd
ti_bapicondit = lt_bapicondit
ti_bapicondqs = lt_bapicondqs
ti_bapicondvs = lt_bapicondvs
to_bapiret2 = lte_bapiret2
to_bapiknumhs = lte_bapiknumhs
to_mem_initial = lte_mem_initial
EXCEPTIONS
update_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
select * from konh APPENDING CORRESPONDING FIELDS OF TABLE
db_xkonh where knumh = <fs_lt_a305>-knumh.
loop at db_xkonh ASSIGNING <fs_db_xkonh>.
<fs_db_xkonh>-updkz = 'U'.
ENDLOOP.
select * from konp APPENDING CORRESPONDING FIELDS OF TABLE
db_xkonp where knumh = <fs_lt_a305>-knumh.
loop at db_xkonp ASSIGNING <fs_db_xkonp>.
<fs_db_xkonp>-updkz = 'U'.
ENDLOOP.
if db_xkondat[] is INITIAL.
loop at db_xkonh.
db_xkondat-knumh = db_xkonh-knumh.
db_xkondat-DATAN = ls_bapicondhd-valid_from.
read TABLE db_ykonh with key knumh = db_xkonh-knumh.
if sy-subrc is INITIAL.
db_xkondat-datab = db_ykonh-DATAB.
db_xkondat-datbi = db_ykonh-DATBI.
db_xkondat-kz = db_ykonh-updkz.
append db_xkondat.
else.
db_xkondat-datab = db_xkonh-DATAB.
db_xkondat-datbi = db_xkonh-DATBI.
db_xkondat-kz = db_xkonh-updkz.
append db_xkondat.
endif.
ENDLOOP.
endif.
if db_ykondat[] is INITIAL.
loop at db_ykonh.
db_ykondat-knumh = db_ykonh-knumh.
db_ykondat-DATAN = db_ykonh-DATAB.
db_ykondat-datab = db_ykonh-DATAB.
db_ykondat-datbi = db_ykonh-DATBI.
db_ykondat-kz = db_ykonh-updkz.
append db_ykondat.
ENDLOOP.
endif.
* write change documents
CALL FUNCTION 'SD_CONDITION_CHANGE_DOCS_WRITE'
TABLES
p_xkondat = db_xkondat
p_ykondat = db_ykondat
p_xkonh = db_xkonh
p_ykonh = db_ykonh
p_xkonp = db_xkonp
p_ykonp = db_ykonp
p_xkonm = db_xkonm
p_xkonw = db_xkonw
p_ykonm = db_ykonm
p_ykonw = db_ykonw.
LOOP AT lte_bapiret2 ASSIGNING <fs_lte_bapiret2>
WHERE type = 'E'.
EXIT.
ENDLOOP.
IF sy-subrc IS INITIAL.
<fs_gt_upload>-icon = icon_cancel.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
* IMPORTING
* RETURN =
.
ELSE.
LOOP AT lte_bapiret2 ASSIGNING <fs_lte_bapiret2>
WHERE type = 'S' OR type = 'W'.
EXIT.
ENDLOOP.
IF sy-subrc IS INITIAL.
* CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* wait = 'X'.
ELSE.
<fs_gt_upload>-icon = icon_cancel.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
CHECK <fs_gt_upload>-icon <> icon_cancel.
*2 Get all records into the current From/To
REFRESH: lt_a305[].
SELECT a305~kappl
a305~kschl
a305~vkorg
a305~vtweg
a305~kunnr
a305~matnr
a305~kfrst
a305~datbi
a305~datab
a305~kbstat
a305~knumh
konp~konwa
konp~kbetr
konp~kmein
konp~kpein
FROM a305
INNER JOIN konp ON konp~knumh = a305~knumh
APPENDING CORRESPONDING FIELDS OF TABLE lt_a305
WHERE a305~kappl = lcon_applicatio_v AND
a305~kschl = <fs_gt_upload>-kschl AND
a305~vkorg = <fs_gt_upload>-vkorg AND
a305~vtweg = <fs_gt_upload>-vtweg AND
a305~kunnr = <fs_gt_upload>-kunnr AND
a305~matnr = <fs_gt_upload>-matnr AND
a305~kfrst = lcon_kfrst_a AND
a305~datbi LE <fs_gt_upload>-datbi AND
a305~datab GE <fs_gt_upload>-datab.
LOOP AT lt_a305 ASSIGNING <fs_lt_a305>.
IF <fs_gt_upload>-icon <> icon_cancel.
ELSE.
EXIT.
ENDIF.
IF <fs_lt_a305>-kfrst = lcon_kfrst_a.
*2a Get all records into the current From/To
* Delete the record
REFRESH: lt_bapicondct[],
lt_bapicondhd[],
lt_bapicondit[],
lt_bapicondqs[],
lt_bapicondvs[],
lte_bapiret2[],
lte_bapiknumhs[],
lte_mem_initial[].
CLEAR: ls_bapicondct,
ls_bapicondhd,
ls_bapicondit,
ls_bapicondqs,
ls_bapicondvs,
lse_bapiret2,
lse_bapiknumhs,
lse_mem_initial,
ls_varkey_a305_header,
ls_varkey_header,
ls_vardat_a305_header,
ls_vardat_header,
ls_varkey_item.
ls_bapicondct-operation = lcon_operation_003.
ls_bapicondct-cond_usage = lcon_cond_usage_a .
ls_bapicondct-table_no = lcon_table_no_305.
ls_varkey_a305_header-vkorg = <fs_lt_a305>-vkorg.
ls_varkey_a305_header-vtweg = <fs_lt_a305>-vtweg.
ls_varkey_a305_header-kunnr = <fs_lt_a305>-kunnr.
ls_varkey_a305_header-matnr = <fs_lt_a305>-matnr.
ls_varkey_a305_header-kfrst = <fs_lt_a305>-kfrst.
ls_varkey_header = ls_varkey_a305_header.
ls_vardat_a305_header-kbstat = <fs_lt_a305>-kbstat.
ls_vardat_header = ls_vardat_a305_header.
ls_bapicondct-cond_no = <fs_lt_a305>-knumh.
CLEAR: lv_knumh.
lv_knumh = ls_bapicondct-cond_no .
ls_bapicondct-applicatio = lcon_applicatio_v .
ls_bapicondct-cond_type = <fs_lt_a305>-kschl.
IF ls_bapicondct-cond_type IS INITIAL.
ls_bapicondct-cond_type = lcon_cond_type_pr00.
ENDIF.
ls_bapicondct-varkey = ls_varkey_header.
ls_bapicondct-vadat = ls_vardat_header.
ls_bapicondct-valid_to = <fs_lt_a305>-datbi. " lcon_valid_to.
ls_bapicondct-valid_from = <fs_lt_a305>-datab.
APPEND ls_bapicondct TO lt_bapicondct.
ls_bapicondhd-operation = ls_bapicondct-operation. "lcon_operation_009.
ls_bapicondhd-cond_no = ls_bapicondct-cond_no. "lcon_knumh_i .
ls_bapicondhd-created_by = sy-uname.
ls_bapicondhd-creat_date = sy-datum.
ls_bapicondhd-cond_usage = lcon_cond_usage_a .
ls_bapicondhd-table_no = ls_bapicondct-table_no.
ls_bapicondhd-applicatio = lcon_applicatio_v .
ls_bapicondhd-cond_type = ls_bapicondct-cond_type.
ls_bapicondhd-varkey = ls_varkey_header.
ls_bapicondhd-vardate = ls_vardat_header.
ls_bapicondhd-valid_from = <fs_lt_a305>-datab.
ls_bapicondhd-valid_to = <fs_lt_a305>-datbi. " lcon_valid_to.
APPEND ls_bapicondhd TO lt_bapicondhd.
ls_bapicondit-operation = ls_bapicondct-operation. "lcon_operation_009.
ls_bapicondit-cond_no = ls_bapicondct-cond_no. "lcon_knumh_i .
ls_bapicondit-cond_count = lcon_cond_count_i .
ls_bapicondit-applicatio = lcon_applicatio_v .
ls_bapicondit-cond_type = ls_bapicondct-cond_type.
* text_no
ls_bapicondit-scaletype = lcon_scale_type_c.
* scalebasin
* scale_qty
* unitmeasur
* measur_iso
* scale_val
* currenckey
* curren_iso
ls_bapicondit-calctypcon = lcon_calc_type_c.
ls_bapicondit-cond_value = <fs_lt_a305>-kbetr.
ls_bapicondit-condcurr = <fs_lt_a305>-konwa.
* ls_bapicondit-cond_iso
ls_bapicondit-cond_p_unt = <fs_lt_a305>-kpein.
ls_bapicondit-cond_unit = <fs_lt_a305>-kmein.
* conunitiso
* pricelevel
* numconvert
* denominato
* base_uom
* baseqtyiso
* lowerlimit
* upperlimit
* plcondval
* currency
* curr_iso
* condcurren
* isocurrenc
* plan_basis
* rate_unit
* exclusion
* customer
* vendor_no
* tax_code
* indidelete
* conditidx
* matlsettl
* accruals
* reb_retroa
* statofagre
* promot_no
* sales_deal
* salesquote
* add_val_dy
* fix_val_dy
* pmnttrms
* numborders
* minconbava
* maxconbava
* maxconval
* incr_scale
* pricscale
* relprcg
* promotion
* rebagreemt
* withtaxcod
* contract
* contractno
* flow_type
* indimatmai
ls_bapicondit-status = <fs_lt_a305>-kfrst.
* umsabst
* matlsettl_external
* matlsettl_guid
* matlsettl_version
APPEND ls_bapicondit TO lt_bapicondit.
refresh: db_xkondat[],
db_ykondat[],
db_xkonh[],
db_ykonh[],
db_xkonp[],
db_ykonp[],
db_xkonm[],
db_xkonw[],
db_ykonm[],
db_ykonw[].
select * from konh APPENDING CORRESPONDING FIELDS OF TABLE
db_ykonh where knumh = <fs_lt_a305>-knumh.
loop at db_ykonh ASSIGNING <fs_db_ykonh>.
<fs_db_ykonh>-updkz = 'U'.
ENDLOOP.
select * from konp APPENDING CORRESPONDING FIELDS OF TABLE
db_ykonp where knumh = <fs_lt_a305>-knumh.
loop at db_ykonp ASSIGNING <fs_db_ykonp>.
<fs_db_ykonp>-updkz = 'U'.
ENDLOOP.
CALL FUNCTION 'BAPI_PRICES_CONDITIONS'
EXPORTING
* PI_INITIALMODE = ' '
* PI_BLOCKNUMBER =
pi_physical_deletion = lv_del
TABLES
ti_bapicondct = lt_bapicondct
ti_bapicondhd = lt_bapicondhd
ti_bapicondit = lt_bapicondit
ti_bapicondqs = lt_bapicondqs
ti_bapicondvs = lt_bapicondvs
to_bapiret2 = lte_bapiret2
to_bapiknumhs = lte_bapiknumhs
to_mem_initial = lte_mem_initial
EXCEPTIONS
update_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
select * from konh APPENDING CORRESPONDING FIELDS OF TABLE
db_xkonh where knumh = <fs_lt_a305>-knumh.
loop at db_xkonh ASSIGNING <fs_db_xkonh>.
<fs_db_xkonh>-updkz = 'U'.
ENDLOOP.
select * from konp APPENDING CORRESPONDING FIELDS OF TABLE
db_xkonp where knumh = <fs_lt_a305>-knumh.
loop at db_xkonp ASSIGNING <fs_db_xkonp>.
<fs_db_xkonp>-updkz = 'U'.
ENDLOOP.
if db_xkondat[] is INITIAL.
loop at db_xkonh.
db_xkondat-knumh = db_xkonh-knumh.
db_xkondat-DATAN = ls_bapicondhd-valid_from.
read TABLE db_ykonh with key knumh = db_xkonh-knumh.
if sy-subrc is INITIAL.
db_xkondat-datab = db_ykonh-DATAB.
db_xkondat-datbi = db_ykonh-DATBI.
db_xkondat-kz = db_ykonh-updkz.
append db_xkondat.
else.
db_xkondat-datab = db_xkonh-DATAB.
db_xkondat-datbi = db_xkonh-DATBI.
db_xkondat-kz = db_xkonh-updkz.
append db_xkondat.
endif.
ENDLOOP.
endif.
if db_ykondat[] is INITIAL.
loop at db_ykonh.
db_ykondat-knumh = db_ykonh-knumh.
db_ykondat-DATAN = db_ykonh-DATAB.
db_ykondat-datab = db_ykonh-DATAB.
db_ykondat-datbi = db_ykonh-DATBI.
db_ykondat-kz = db_ykonh-updkz.
append db_ykondat.
ENDLOOP.
endif.
* write change documents
CALL FUNCTION 'SD_CONDITION_CHANGE_DOCS_WRITE'
TABLES
p_xkondat = db_xkondat
p_ykondat = db_ykondat
p_xkonh = db_xkonh
p_ykonh = db_ykonh
p_xkonp = db_xkonp
p_ykonp = db_ykonp
p_xkonm = db_xkonm
p_xkonw = db_xkonw
p_ykonm = db_ykonm
p_ykonw = db_ykonw.
LOOP AT lte_bapiret2 ASSIGNING <fs_lte_bapiret2>
WHERE type = 'E'.
EXIT.
ENDLOOP.
IF sy-subrc IS INITIAL.
<fs_gt_upload>-icon = icon_cancel.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
* IMPORTING
* RETURN =
.
ELSE.
LOOP AT lte_bapiret2 ASSIGNING <fs_lte_bapiret2>
WHERE type = 'S' OR type = 'W'.
EXIT.
ENDLOOP.
IF sy-subrc IS INITIAL.
* CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* wait = 'X'.
ELSE.
<fs_gt_upload>-icon = icon_cancel.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
CHECK <fs_gt_upload>-icon <> icon_cancel.
*3 Get all records where from in the current From/To
* Delete the record
REFRESH: lt_a305[].
SELECT a305~kappl
a305~kschl
a305~vkorg
a305~vtweg
a305~kunnr
a305~matnr
a305~kfrst
a305~datbi
a305~datab
a305~kbstat
a305~knumh
konp~konwa
konp~kbetr
konp~kmein
konp~kpein
FROM a305
INNER JOIN konp ON konp~knumh = a305~knumh
APPENDING CORRESPONDING FIELDS OF TABLE lt_a305
WHERE a305~kappl = lcon_applicatio_v AND
a305~kschl = <fs_gt_upload>-kschl AND
a305~vkorg = <fs_gt_upload>-vkorg AND
a305~vtweg = <fs_gt_upload>-vtweg AND
a305~kunnr = <fs_gt_upload>-kunnr AND
a305~matnr = <fs_gt_upload>-matnr AND
a305~kfrst = lcon_kfrst_a AND
a305~datbi GT <fs_gt_upload>-datab AND
a305~datab GE <fs_gt_upload>-datab AND
a305~datab LE <fs_gt_upload>-datbi .
LOOP AT lt_a305 ASSIGNING <fs_lt_a305>.
IF <fs_gt_upload>-icon <> icon_cancel.
ELSE.
EXIT.
ENDIF.
IF <fs_lt_a305>-kfrst = lcon_kfrst_a.
*3 Get all records where from in the current From/To
* Delete
* REFRESH: lt_bapicondct[],
* lt_bapicondhd[],
* lt_bapicondit[],
* lt_bapicondqs[],
* lt_bapicondvs[],
* lte_bapiret2[],
* lte_bapiknumhs[],
* lte_mem_initial[].
*
* CLEAR: ls_bapicondct,
* ls_bapicondhd,
* ls_bapicondit,
* ls_bapicondqs,
* ls_bapicondvs,
* lse_bapiret2,
* lse_bapiknumhs,
* lse_mem_initial,
* ls_varkey_a305_header,
* ls_varkey_header,
* ls_vardat_a305_header,
* ls_vardat_header,
* ls_varkey_item.
* ls_bapicondct-operation = lcon_operation_003.
* ls_bapicondct-cond_usage = lcon_cond_usage_a .
* ls_bapicondct-table_no = lcon_table_no_305.
* ls_varkey_a305_header-vkorg = <fs_lt_a305>-vkorg.
* ls_varkey_a305_header-vtweg = <fs_lt_a305>-vtweg.
* ls_varkey_a305_header-kunnr = <fs_lt_a305>-kunnr.
* ls_varkey_a305_header-matnr = <fs_lt_a305>-matnr.
* ls_varkey_a305_header-KFRST = <fs_lt_a305>-KFRST.
* ls_varkey_header = ls_varkey_a305_header.
* ls_vardat_a305_header-kbstat = <fs_lt_a305>-kbstat.
* ls_vardat_header = ls_vardat_a305_header.
* ls_bapicondct-cond_no = <fs_lt_a305>-knumh.
*
*
* CLEAR: lv_knumh.
* lv_knumh = ls_bapicondct-cond_no .
*
* ls_bapicondct-applicatio = lcon_applicatio_v .
* ls_bapicondct-cond_type = <fs_lt_a305>-kschl.
* IF ls_bapicondct-cond_type IS INITIAL.
* ls_bapicondct-cond_type = lcon_cond_type_pr00.
* ENDIF.
*
* ls_bapicondct-varkey = ls_varkey_header.
* ls_bapicondct-vadat = ls_vardat_header.
* ls_bapicondct-valid_to = <fs_lt_a305>-datbi. " lcon_valid_to.
* ls_bapicondct-valid_from = <fs_lt_a305>-datab.
* APPEND ls_bapicondct TO lt_bapicondct.
*
* ls_bapicondhd-operation = ls_bapicondct-operation. "lcon_operation_009.
* ls_bapicondhd-cond_no = ls_bapicondct-cond_no. "lcon_knumh_i .
* ls_bapicondhd-created_by = sy-uname.
* ls_bapicondhd-creat_date = sy-datum.
* ls_bapicondhd-cond_usage = lcon_cond_usage_a .
* ls_bapicondhd-table_no = ls_bapicondct-table_no.
* ls_bapicondhd-applicatio = lcon_applicatio_v .
* ls_bapicondhd-cond_type = ls_bapicondct-cond_type.
* ls_bapicondhd-varkey = ls_varkey_header.
* ls_bapicondhd-vardate = ls_vardat_header.
* ls_bapicondhd-valid_from = <fs_lt_a305>-datab.
* ls_bapicondhd-valid_to = <fs_lt_a305>-datbi. " lcon_valid_to.
* APPEND ls_bapicondhd TO lt_bapicondhd.
*
* ls_bapicondit-operation = ls_bapicondct-operation. "lcon_operation_009.
* ls_bapicondit-cond_no = ls_bapicondct-cond_no. "lcon_knumh_i .
* ls_bapicondit-cond_count = lcon_cond_count_i .
* ls_bapicondit-applicatio = lcon_applicatio_v .
* ls_bapicondit-cond_type = ls_bapicondct-cond_type.
** text_no
* ls_bapicondit-scaletype = lcon_scale_type_c.
** scalebasin
** scale_qty
** unitmeasur
** measur_iso
** scale_val
** currenckey
** curren_iso
* ls_bapicondit-calctypcon = lcon_calc_type_c.
* ls_bapicondit-cond_value = <fs_lt_a305>-kbetr.
* ls_bapicondit-condcurr = <fs_lt_a305>-konwa.
** ls_bapicondit-cond_iso
* ls_bapicondit-cond_p_unt = <fs_lt_a305>-kpein.
* ls_bapicondit-cond_unit = <fs_lt_a305>-kmein.
** conunitiso
** pricelevel
** numconvert
** denominato
** base_uom
** baseqtyiso
** lowerlimit
** upperlimit
** plcondval
** currency
** curr_iso
** condcurren
** isocurrenc
** plan_basis
** rate_unit
** exclusion
** customer
** vendor_no
** tax_code
** indidelete
** conditidx
** matlsettl
** accruals
** reb_retroa
** statofagre
** promot_no
** sales_deal
** salesquote
** add_val_dy
** fix_val_dy
** pmnttrms
** numborders
** minconbava
** maxconbava
** maxconval
** incr_scale
** pricscale
** relprcg
** promotion
** rebagreemt
** withtaxcod
** contract
** contractno
** flow_type
** indimatmai
* ls_bapicondit-status = <fs_lt_a305>-KFRST.
** umsabst
** matlsettl_external
** matlsettl_guid
** matlsettl_version
*
* APPEND ls_bapicondit TO lt_bapicondit.
*
* CALL FUNCTION 'BAPI_PRICES_CONDITIONS'
* EXPORTING
** PI_INITIALMODE = ' '
** PI_BLOCKNUMBER =
* pi_physical_deletion = lv_del
* TABLES
* ti_bapicondct = lt_bapicondct
* ti_bapicondhd = lt_bapicondhd
* ti_bapicondit = lt_bapicondit
* ti_bapicondqs = lt_bapicondqs
* ti_bapicondvs = lt_bapicondvs
* to_bapiret2 = lte_bapiret2
* to_bapiknumhs = lte_bapiknumhs
* to_mem_initial = lte_mem_initial
* EXCEPTIONS
* update_error = 1
* OTHERS = 2.
* IF sy-subrc <> 0.
** Implement suitable error handling here
* ENDIF.
* LOOP AT lte_bapiret2 ASSIGNING <fs_lte_bapiret2>
* WHERE type = 'E'.
* EXIT.
* ENDLOOP.
* IF sy-subrc IS INITIAL.
* <fs_gt_upload>-icon = icon_cancel.
* CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
** IMPORTING
** RETURN =
* .
* ELSE.
*
* LOOP AT lte_bapiret2 ASSIGNING <fs_lte_bapiret2>
* WHERE type = 'S' OR type = 'W'.
* EXIT.
* ENDLOOP.
* IF sy-subrc IS INITIAL.
** CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
** EXPORTING
** wait = 'X'.
* ELSE.
* <fs_gt_upload>-icon = icon_cancel.
* ENDIF.
* ENDIF.
ENDIF.
IF <fs_gt_upload>-icon <> icon_cancel.
ELSE.
EXIT.
ENDIF.
IF <fs_lt_a305>-kfrst = lcon_kfrst_a.
*3 Get all records where from in the current From/To
* From = current To + 1.
REFRESH: lt_bapicondct[],
lt_bapicondhd[],
lt_bapicondit[],
lt_bapicondqs[],
lt_bapicondvs[],
lte_bapiret2[],
lte_bapiknumhs[],
lte_mem_initial[].
CLEAR: ls_bapicondct,
ls_bapicondhd,
ls_bapicondit,
ls_bapicondqs,
ls_bapicondvs,
lse_bapiret2,
lse_bapiknumhs,
lse_mem_initial,
ls_varkey_a305_header,
ls_varkey_header,
ls_vardat_a305_header,
ls_vardat_header,
ls_varkey_item.
ls_bapicondct-operation = lcon_operation_004. "lcon_operation_009.
ls_bapicondct-cond_usage = lcon_cond_usage_a .
ls_bapicondct-table_no = lcon_table_no_305.
ls_varkey_a305_header-vkorg = <fs_lt_a305>-vkorg.
ls_varkey_a305_header-vtweg = <fs_lt_a305>-vtweg.
ls_varkey_a305_header-kunnr = <fs_lt_a305>-kunnr.
ls_varkey_a305_header-matnr = <fs_lt_a305>-matnr.
ls_varkey_a305_header-kfrst = <fs_lt_a305>-kfrst.
ls_varkey_header = ls_varkey_a305_header.
ls_vardat_a305_header-kbstat = <fs_lt_a305>-kbstat.
ls_vardat_header = ls_vardat_a305_header.
ls_bapicondct-cond_no = <fs_lt_a305>-knumh.
CLEAR: lv_knumh.
lv_knumh = ls_bapicondct-cond_no .
ls_bapicondct-applicatio = lcon_applicatio_v .
ls_bapicondct-cond_type = <fs_lt_a305>-kschl.
IF ls_bapicondct-cond_type IS INITIAL.
ls_bapicondct-cond_type = lcon_cond_type_pr00.
ENDIF.
ls_bapicondct-varkey = ls_varkey_header.
ls_bapicondct-vadat = ls_vardat_header.
ls_bapicondct-valid_to = <fs_lt_a305>-datbi.
ls_bapicondct-valid_from = <fs_gt_upload>-datbi + 1.
APPEND ls_bapicondct TO lt_bapicondct.
ls_bapicondhd-operation = ls_bapicondct-operation. "lcon_operation_009.
ls_bapicondhd-cond_no = ls_bapicondct-cond_no. "lcon_knumh_i .
ls_bapicondhd-created_by = sy-uname.
ls_bapicondhd-creat_date = sy-datum.
ls_bapicondhd-cond_usage = lcon_cond_usage_a .
ls_bapicondhd-table_no = ls_bapicondct-table_no.
ls_bapicondhd-applicatio = lcon_applicatio_v .
ls_bapicondhd-cond_type = ls_bapicondct-cond_type.
ls_bapicondhd-varkey = ls_varkey_header.
ls_bapicondhd-vardate = ls_vardat_header.
ls_bapicondhd-valid_from = <fs_lt_a305>-datbi.
ls_bapicondhd-valid_to = <fs_gt_upload>-datbi + 1.
APPEND ls_bapicondhd TO lt_bapicondhd.
ls_bapicondit-operation = ls_bapicondct-operation. "lcon_operation_009.
ls_bapicondit-cond_no = ls_bapicondct-cond_no. "lcon_knumh_i .
ls_bapicondit-cond_count = lcon_cond_count_i .
ls_bapicondit-applicatio = lcon_applicatio_v .
ls_bapicondit-cond_type = ls_bapicondct-cond_type.
* text_no
ls_bapicondit-scaletype = lcon_scale_type_c.
* scalebasin
* scale_qty
* unitmeasur
* measur_iso
* scale_val
* currenckey
* curren_iso
ls_bapicondit-calctypcon = lcon_calc_type_c.
ls_bapicondit-cond_value = <fs_lt_a305>-kbetr.
ls_bapicondit-condcurr = <fs_lt_a305>-konwa.
* ls_bapicondit-cond_iso
ls_bapicondit-cond_p_unt = <fs_lt_a305>-kpein.
ls_bapicondit-cond_unit = <fs_lt_a305>-kmein.
* conunitiso
* pricelevel
* numconvert
* denominato
* base_uom
* baseqtyiso
* lowerlimit
* upperlimit
* plcondval
* currency
* curr_iso
* condcurren
* isocurrenc
* plan_basis
* rate_unit
* exclusion
* customer
* vendor_no
* tax_code
* indidelete
* conditidx
* matlsettl
* accruals
* reb_retroa
* statofagre
* promot_no
* sales_deal
* salesquote
* add_val_dy
* fix_val_dy
* pmnttrms
* numborders
* minconbava
* maxconbava
* maxconval
* incr_scale
* pricscale
* relprcg
* promotion
* rebagreemt
* withtaxcod
* contract
* contractno
* flow_type
* indimatmai
ls_bapicondit-status = <fs_lt_a305>-kfrst.
* umsabst
* matlsettl_external
* matlsettl_guid
* matlsettl_version
APPEND ls_bapicondit TO lt_bapicondit.
refresh: db_xkondat[],
db_ykondat[],
db_xkonh[],
db_ykonh[],
db_xkonp[],
db_ykonp[],
db_xkonm[],
db_xkonw[],
db_ykonm[],
db_ykonw[].
select * from konh APPENDING CORRESPONDING FIELDS OF TABLE
db_ykonh where knumh = <fs_lt_a305>-knumh.
loop at db_ykonh ASSIGNING <fs_db_ykonh>.
<fs_db_ykonh>-updkz = 'U'.
ENDLOOP.
select * from konp APPENDING CORRESPONDING FIELDS OF TABLE
db_ykonp where knumh = <fs_lt_a305>-knumh.
loop at db_ykonp ASSIGNING <fs_db_ykonp>.
<fs_db_ykonp>-updkz = 'U'.
ENDLOOP.
CALL FUNCTION 'BAPI_PRICES_CONDITIONS'
EXPORTING
* PI_INITIALMODE = ' '
* PI_BLOCKNUMBER =
pi_physical_deletion = lv_del
TABLES
ti_bapicondct = lt_bapicondct
ti_bapicondhd = lt_bapicondhd
ti_bapicondit = lt_bapicondit
ti_bapicondqs = lt_bapicondqs
ti_bapicondvs = lt_bapicondvs
to_bapiret2 = lte_bapiret2
to_bapiknumhs = lte_bapiknumhs
to_mem_initial = lte_mem_initial
EXCEPTIONS
update_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
select * from konh APPENDING CORRESPONDING FIELDS OF TABLE
db_xkonh where knumh = <fs_lt_a305>-knumh.
loop at db_xkonh ASSIGNING <fs_db_xkonh>.
<fs_db_xkonh>-updkz = 'U'.
ENDLOOP.
select * from konp APPENDING CORRESPONDING FIELDS OF TABLE
db_xkonp where knumh = <fs_lt_a305>-knumh.
loop at db_xkonp ASSIGNING <fs_db_xkonp>.
<fs_db_xkonp>-updkz = 'U'.
ENDLOOP.
if db_xkondat[] is INITIAL.
loop at db_xkonh.
db_xkondat-knumh = db_xkonh-knumh.
db_xkondat-DATAN = ls_bapicondhd-valid_from.
read TABLE db_ykonh with key knumh = db_xkonh-knumh.
if sy-subrc is INITIAL.
db_xkondat-datab = db_ykonh-DATAB.
db_xkondat-datbi = db_ykonh-DATBI.
db_xkondat-kz = db_ykonh-updkz.
append db_xkondat.
else.
db_xkondat-datab = db_xkonh-DATAB.
db_xkondat-datbi = db_xkonh-DATBI.
db_xkondat-kz = db_xkonh-updkz.
append db_xkondat.
endif.
ENDLOOP.
endif.
if db_ykondat[] is INITIAL.
loop at db_ykonh.
db_ykondat-knumh = db_ykonh-knumh.
db_ykondat-DATAN = db_ykonh-DATAB.
db_ykondat-datab = db_ykonh-DATAB.
db_ykondat-datbi = db_ykonh-DATBI.
db_ykondat-kz = db_ykonh-updkz.
append db_ykondat.
ENDLOOP.
endif.
* write change documents
CALL FUNCTION 'SD_CONDITION_CHANGE_DOCS_WRITE'
TABLES
p_xkondat = db_xkondat
p_ykondat = db_ykondat
p_xkonh = db_xkonh
p_ykonh = db_ykonh
p_xkonp = db_xkonp
p_ykonp = db_ykonp
p_xkonm = db_xkonm
p_xkonw = db_xkonw
p_ykonm = db_ykonm
p_ykonw = db_ykonw.
LOOP AT lte_bapiret2 ASSIGNING <fs_lte_bapiret2>
WHERE type = 'E'.
EXIT.
ENDLOOP.
IF sy-subrc IS INITIAL.
<fs_gt_upload>-icon = icon_cancel.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
* IMPORTING
* RETURN =
.
ELSE.
LOOP AT lte_bapiret2 ASSIGNING <fs_lte_bapiret2>
WHERE type = 'S' OR type = 'W'.
EXIT.
ENDLOOP.
IF sy-subrc IS INITIAL.
* CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* wait = 'X'.
ELSE.
<fs_gt_upload>-icon = icon_cancel.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
CHECK <fs_gt_upload>-icon <> icon_cancel.
*Finally create current condition
REFRESH: lt_bapicondct[],
lt_bapicondhd[],
lt_bapicondit[],
lt_bapicondqs[],
lt_bapicondvs[],
lte_bapiret2[],
lte_bapiknumhs[],
lte_mem_initial[].
CLEAR: ls_bapicondct,
ls_bapicondhd,
ls_bapicondit,
ls_bapicondqs,
ls_bapicondvs,
lse_bapiret2,
lse_bapiknumhs,
lse_mem_initial,
ls_varkey_a305_header,
ls_varkey_header,
ls_vardat_a305_header,
ls_vardat_header,
ls_varkey_item.
ls_bapicondct-operation = lcon_operation_009.
ls_bapicondct-cond_usage = lcon_cond_usage_a .
ls_bapicondct-table_no = lcon_table_no_305.
ls_varkey_a305_header-vkorg = <fs_gt_upload>-vkorg.
ls_varkey_a305_header-vtweg = <fs_gt_upload>-vtweg.
ls_varkey_a305_header-kunnr = <fs_gt_upload>-kunnr.
ls_varkey_a305_header-matnr = <fs_gt_upload>-matnr.
ls_varkey_a305_header-kfrst = lcon_kfrst_a .
ls_varkey_header = ls_varkey_a305_header.
ls_vardat_a305_header-kbstat = lcon_kbstat_1.
ls_vardat_header = ls_vardat_a305_header.
ls_bapicondct-cond_no = lcon_knumh_i .
IF p_test IS NOT INITIAL.
ls_bapicondct-cond_no = lcon_knumh_test .
ENDIF.
CLEAR: lv_knumh.
lv_knumh = ls_bapicondct-cond_no .
ls_bapicondct-applicatio = lcon_applicatio_v .
ls_bapicondct-cond_type = <fs_gt_upload>-kschl.
IF ls_bapicondct-cond_type IS INITIAL.
ls_bapicondct-cond_type = lcon_cond_type_pr00.
ENDIF.
ls_bapicondct-varkey = ls_varkey_header.
ls_bapicondct-vadat = ls_vardat_header.
ls_bapicondct-valid_to = <fs_gt_upload>-datbi. " lcon_valid_to.
ls_bapicondct-valid_from = <fs_gt_upload>-datab.
APPEND ls_bapicondct TO lt_bapicondct.
ls_bapicondhd-operation = ls_bapicondct-operation. "lcon_operation_009.
ls_bapicondhd-cond_no = ls_bapicondct-cond_no. "lcon_knumh_i .
ls_bapicondhd-created_by = sy-uname.
ls_bapicondhd-creat_date = sy-datum.
ls_bapicondhd-cond_usage = lcon_cond_usage_a .
ls_bapicondhd-table_no = ls_bapicondct-table_no.
ls_bapicondhd-applicatio = lcon_applicatio_v .
ls_bapicondhd-cond_type = ls_bapicondct-cond_type.
ls_bapicondhd-varkey = ls_varkey_header.
ls_bapicondhd-vardate = ls_vardat_header.
ls_bapicondhd-valid_from = <fs_gt_upload>-datab.
ls_bapicondhd-valid_to = <fs_gt_upload>-datbi. " lcon_valid_to.
APPEND ls_bapicondhd TO lt_bapicondhd.
ls_bapicondit-operation = ls_bapicondct-operation. "lcon_operation_009.
ls_bapicondit-cond_no = ls_bapicondct-cond_no. "lcon_knumh_i .
ls_bapicondit-cond_count = lcon_cond_count_i .
ls_bapicondit-applicatio = lcon_applicatio_v .
ls_bapicondit-cond_type = ls_bapicondct-cond_type.
* text_no
ls_bapicondit-scaletype = lcon_scale_type_c.
* scalebasin
* scale_qty
* unitmeasur
* measur_iso
* scale_val
* currenckey
* curren_iso
ls_bapicondit-calctypcon = lcon_calc_type_c.
ls_bapicondit-cond_value = <fs_gt_upload>-kbetr.
ls_bapicondit-condcurr = <fs_gt_upload>-waers.
* ls_bapicondit-cond_iso
ls_bapicondit-cond_p_unt = <fs_gt_upload>-kpein.
ls_bapicondit-cond_unit = <fs_gt_upload>-kmein.
* conunitiso
* pricelevel
* numconvert
* denominato
* base_uom
* baseqtyiso
* lowerlimit
* upperlimit
* plcondval
* currency
* curr_iso
* condcurren
* isocurrenc
* plan_basis
* rate_unit
* exclusion
* customer
* vendor_no
* tax_code
* indidelete
* conditidx
* matlsettl
* accruals
* reb_retroa
* statofagre
* promot_no
* sales_deal
* salesquote
* add_val_dy
* fix_val_dy
* pmnttrms
* numborders
* minconbava
* maxconbava
* maxconval
* incr_scale
* pricscale
* relprcg
* promotion
* rebagreemt
* withtaxcod
* contract
* contractno
* flow_type
* indimatmai
ls_bapicondit-status = lcon_kfrst_a .
* umsabst
* matlsettl_external
* matlsettl_guid
* matlsettl_version
APPEND ls_bapicondit TO lt_bapicondit.
refresh: db_xkondat[],
db_ykondat[],
db_xkonh[],
db_ykonh[],
db_xkonp[],
db_ykonp[],
db_xkonm[],
db_xkonw[],
db_ykonm[],
db_ykonw[].
* select * from konh APPENDING CORRESPONDING FIELDS OF TABLE
* db_ykonh where knumh = <fs_lt_a305>-knumh.
* loop at db_ykonh ASSIGNING <fs_db_ykonh>.
* <fs_db_ykonh>-updkz = 'I'.
* ENDLOOP.
*
* select * from konp APPENDING CORRESPONDING FIELDS OF TABLE
* db_ykonp where knumh = <fs_lt_a305>-knumh.
CALL FUNCTION 'BAPI_PRICES_CONDITIONS'
EXPORTING
* PI_INITIALMODE = ' '
* PI_BLOCKNUMBER =
pi_physical_deletion = lv_del
TABLES
ti_bapicondct = lt_bapicondct
ti_bapicondhd = lt_bapicondhd
ti_bapicondit = lt_bapicondit
ti_bapicondqs = lt_bapicondqs
ti_bapicondvs = lt_bapicondvs
to_bapiret2 = lte_bapiret2
to_bapiknumhs = lte_bapiknumhs
to_mem_initial = lte_mem_initial
EXCEPTIONS
update_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
clear lv_knumh_saved.
LOOP AT lte_bapiret2 ASSIGNING <fs_lte_bapiret2>
WHERE type = 'S'.
lv_knumh_saved = <fs_lte_bapiret2>-message_v1.
exit.
ENDLOOP.
clear db_ykonp.
append db_ykonp.
loop at db_ykonp ASSIGNING <fs_db_ykonp>.
<fs_db_ykonp>-knumh = lv_knumh_saved.
ENDLOOP.
select * from konh APPENDING CORRESPONDING FIELDS OF TABLE
db_xkonh where knumh = lv_knumh_saved.
loop at db_xkonh ASSIGNING <fs_db_xkonh>.
<fs_db_xkonh>-updkz = 'I'.
ENDLOOP.
select * from konp APPENDING CORRESPONDING FIELDS OF TABLE
db_xkonp where knumh = lv_knumh_saved.
loop at db_xkonp ASSIGNING <fs_db_xkonp>.
<fs_db_xkonp>-updkz = 'I'.
ENDLOOP.
loop at db_ykonp ASSIGNING <fs_db_ykonp>.
READ TABLE db_xkonp ASSIGNING <fs_db_xkonp>
with key knumh = <fs_db_ykonp>-knumh.
if sy-subrc is INITIAL.
<fs_db_ykonp>-MANDT = <fs_db_xkonp>-mandt.
<fs_db_ykonp>-KNUMH = <fs_db_xkonp>-KNUMH.
<fs_db_ykonp>-KOPOS = <fs_db_xkonp>-kopos.
<fs_db_ykonp>-KAPPL = <fs_db_xkonp>-kappl.
<fs_db_ykonp>-KSCHL = <fs_db_xkonp>-kschl.
<fs_db_ykonp>-STFKZ = <fs_db_xkonp>-stfkz.
<fs_db_ykonp>-KRECH = <fs_db_xkonp>-krech.
<fs_db_ykonp>-KWAEH = <fs_db_xkonp>-kwaeh.
<fs_db_ykonp>-ZAEHK_IND = <fs_db_xkonp>-ZAEHK_IND.
<fs_db_ykonp>-RV13ABKONW = <fs_db_xkonp>-RV13ABKONW.
<fs_db_ykonp>-RV13AKONWA = <fs_db_xkonp>-RV13AKONWA .
<fs_db_ykonp>-UPDKZ = <fs_db_xkonp>-UPDKZ.
endif.
ENDLOOP.
if db_xkondat[] is INITIAL.
loop at db_xkonh.
db_xkondat-knumh = db_xkonh-knumh.
db_xkondat-DATAN = ls_bapicondhd-valid_from.
read TABLE db_ykonh with key knumh = db_xkonh-knumh.
if sy-subrc is INITIAL.
db_xkondat-datab = db_ykonh-DATAB.
db_xkondat-datbi = db_ykonh-DATBI.
db_xkondat-kz = 'U' ."db_ykonh-updkz.
append db_xkondat.
else.
db_xkondat-datab = db_xkonh-DATAB.
db_xkondat-datbi = db_xkonh-DATBI.
db_xkondat-kz = 'U'. "db_xkonh-updkz.
append db_xkondat.
endif.
ENDLOOP.
endif.
if db_ykondat[] is INITIAL.
* loop at db_ykonh.
* db_ykondat-knumh = db_ykonh-knumh.
* db_ykondat-DATAN = db_ykonh-DATAB.
* db_ykondat-datab = db_ykonh-DATAB.
* db_ykondat-datbi = db_ykonh-DATBI.
* db_ykondat-kz = db_ykonh-updkz.
* append db_ykondat.
* ENDLOOP.
db_ykondat[] = db_xkondat[].
loop at db_ykondat ASSIGNING <fs_db_ykondat>.
clear: <fs_db_ykondat>-datab,
<fs_db_ykondat>-datbi.
endloop.
endif.
* write change documents
CALL FUNCTION 'SD_CONDITION_CHANGE_DOCS_WRITE'
TABLES
p_xkondat = db_xkondat
p_ykondat = db_ykondat
p_xkonh = db_xkonh
p_ykonh = db_ykonh
p_xkonp = db_xkonp
p_ykonp = db_ykonp
p_xkonm = db_xkonm
p_xkonw = db_xkonw
p_ykonm = db_ykonm
p_ykonw = db_ykonw.
LOOP AT lte_bapiret2 ASSIGNING <fs_lte_bapiret2>
WHERE type = 'E'.
EXIT.
ENDLOOP.
IF sy-subrc IS INITIAL.
<fs_gt_upload>-icon = icon_cancel.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'
* IMPORTING
* RETURN =
.
ELSE.
LOOP AT lte_bapiret2 ASSIGNING <fs_lte_bapiret2>
WHERE type = 'S' OR type = 'W'.
<fs_gt_upload>-message = <fs_lte_bapiret2>-message.
<fs_gt_upload>-knumh = <fs_lte_bapiret2>-message_v1.
EXIT.
ENDLOOP.
IF sy-subrc IS INITIAL.
* CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* wait = 'X'.
<fs_gt_upload>-icon = icon_okay.
ELSE.
<fs_gt_upload>-icon = icon_cancel.
ENDIF.
ENDIF.
ENDLOOP.
LOOP AT gt_upload ASSIGNING <fs_gt_upload> WHERE icon = icon_cancel.
EXIT.
ENDLOOP.
IF sy-subrc IS NOT INITIAL AND p_test IS INITIAL AND gt_upload[] IS NOT INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.
No comments:
Post a Comment