jueves, 3 de junio de 2010

Crear/Modificar Condiciones de precio en Pedidos

Para crear/modificar condiciones de precio en un pedido existente se puede utilizar la función 'BAPI_PO_CHANGE'.

Adjunto un código de ejemplo:

tables: t685a,
lfm1,
tmks,
t683s.
data: w_ekko like ekko,
t_konv like standard table of konv with header line,
t_t683s like standard table of t683s with header line.

* Obtener Datos del Pedido
select single *
from ekko
into w_ekko
where ebeln eq i_costos-notaped.

* Obtener Condiciones del pedido
select *
from konv
into table t_konv
where knumv = w_ekko-knumv.

* Obtener Datos Esquemas de cálculo
select *
from t683s
into table t_t683s
where kalsm eq w_ekko-kalsm.

loop at i_costos into wa_costos where valor ne 0.

clear t685a.
select single *
from t685a
where kschl eq wa_costos-condicion
and kappl eq 'M'.

clear lfm1.
select single *
from lfm1
where lifnr eq w_ekko-lifnr
and ekorg eq w_ekko-ekorg.

clear tmks.
select single *
from tmks
where kalsk eq lfm1-kalsk.

clear t683s.
select single *
from t683s
where kschl eq wa_costos-condicion
and kappl eq 'M'
and kalsm eq tmks-kalsm.

* Asignar datos de condiciones a nivel cabecera
pocondheader-condition_no = wa_costos-knumv.
pocondheader-itm_number = '000000'.
pocondheader-cond_st_no = t683s-stunr. " Número de nivel
pocondheader-cond_count = t683s-zaehk. "contador
pocondheader-cond_type = wa_costos-condicion."Clase de cond
pocondheader-cond_value = wa_costos-valor. "valor
pocondheader-currency = wa_costos-moneda.
pocondheader-currency_iso = wa_costos-moneda.
pocondheader-applicatio = 'M'.

* Verifica condiciones existentes en el pedido a nivel cabecera
read table t_konv with key kposn = '000000'
kschl = wa_costos-condicion.

if sy-subrc is initial.
pocondheader-change_id = 'U'. "Update
else.
pocondheader-change_id = 'I'. "Insert
endif.
append pocondheader.

* Asignar valores en tabla de campos a modificar
clear pocondheader.
pocondheaderx-condition_no = wa_costos-knumv.
pocondheaderx-itm_number = '000000'.
pocondheaderx-cond_st_no = t683s-stunr. " Número de nivel
pocondheaderx-cond_count = 'X'."contador
pocondheaderx-cond_type = 'X'."Clase de cond
pocondheaderx-cond_value = 'X'. "valor
pocondheaderx-currency = 'X'. "ti_cond-KOEIN
pocondheaderx-currency_iso = 'X'. "ti_cond-KOEIN
pocondheaderx-applicatio = 'X'.
append pocondheaderx.
clear pocondheaderx.
endloop.


call function 'BAPI_PO_CHANGE'
exporting
purchaseorder = wa_costos-notaped
tables
return = return
pocondheader = pocondheader
pocondheaderx = pocondheaderx.

call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.

Nota: En este ejemplo la tabla interna I_COSTOS posee los campos CONDICION, VALOR y MONEDA.

No hay comentarios:

Publicar un comentario