*&---------------------------------------------------------------------*
*& Progarm : ZSDR013 Author : Jimmy Wong
*& Created : 26 Dec 2012 App : SD
*& Title : Upload Approved SO Price
*& Description : Upload Approved SO Price
*&---------------------------------------------------------------------*
*& Version Author Date description
*& Jimmy 26 Dec 2012 the first version
*& M1 Jimmy 25 Jan 2013 add VK11 Price Update
*& the last update time 2013.02.26 09:00
*&---------------------------------------------------------------------*
report zsdr013 no standard page heading.
tables:rlgrap,vbap,vbak,konp,konh,a304,a305,a306.
data:begin of it_record occurs 0,
matnr like vbap-matnr,
kunnr like kna1-kunnr,
kschl like konv-kschl,
kbetr like konv-kbetr,
kpein like konv-kpein,
waers like konv-waers ,
message type c length 700,
end of it_record.
data:begin of it_pr00 occurs 0, "M1 add
matnr like vbap-matnr,
vkorg like vbak-vkorg,
vtweg like vbak-vtweg,
kschl like konv-kschl,
kbetr like konv-kbetr,
kpein like konv-kpein,
waers like konv-waers ,
vrkme like vbap-vrkme,
mode type c ,
msgpr00 type c length 255,
end of it_pr00.
data:it_success like it_record occurs 0 with header line.
data:it_error like it_record occurs 0 with header line.
data: begin of it_vbeln occurs 0,
vbeln like vbak-vbeln,
message type c length 255,
end of it_vbeln .
data:begin of it_mara occurs 0,
matnr like vbap-matnr,
end of it_mara.
data:begin of it_kna1 occurs 0,
kunnr like kna1-kunnr,
end of it_kna1.
data:begin of it_tcurc occurs 0,
waers like tcurc-waers,
end of it_tcurc.
data:begin of it_t685 occurs 0,
kschl like t685-kschl,
end of it_t685.
data: begin of it_vbrp_08 occurs 0,
aubel like vbrp-aubel,
aupos like vbrp-aupos,
fkimg like vbrp-fkimg,
vbeln like vbrp-vbeln,
posnr like vbrp-posnr,
sfakn like vbrk-sfakn,
end of it_vbrp_08.
data: it_vbrp like it_vbrp_08 occurs 0 with header line.
data: it_konv like konv occurs 0 with header line.
data:begin of it_so occurs 0,
vbeln like vbak-vbeln,
posnr like vbap-posnr,
kunnr like vbak-kunnr,
matnr like vbap-matnr,
knumv like vbak-knumv,
kwmeng like vbap-kwmeng,
kschl like konv-kschl,
kbetr like konv-kbetr,
kpein like konv-kpein,
waers like konv-waers ,
kschl_o like konv-kschl,
kbetr_o like konv-kbetr,
kpein_o like konv-kpein,
waers_o like konv-waers ,
fkimg like vbrp-fkimg,
objnr like vbak-objnr,
stunr like konv-stunr,
zaehk like konv-zaehk,
vkorg like vbak-vkorg, "M1 add
vtweg like vbak-vtweg, "M1 add
vrkme like vbap-vrkme, "M1 add
msgpr00 type c length 255, "M1 add
message type c length 255,
end of it_so.
data:itab like it_so occurs 0 with header line.
data: msg type string,
lv_tabix like sy-tabix.
constants:c_chk_num like pa0001-ename value '0123456789.,'.
type-pools: slis.
data: fc_hier type slis_t_fieldcat_alv,
wa_hier type slis_fieldcat_alv .
data: i_headerx like bapisdh1x ,
i_cond like bapicond occurs 0 with header line,
i_condx like bapicondx occurs 0 with header line,
it_return like bapiret2 occurs 0 with header line.
data: lt_gt_data type alsmex_tabline occurs 0 with header line.
*----------------------------------------------------------------------*
* Parameter & Select-Options *
*----------------------------------------------------------------------*
selection-screen begin of block 1 with frame title text-001.
select-options: s_vbeln for vbap-vbeln,
s_posnr for vbap-posnr,
s_auart for vbak-auart,
s_kunnr for vbak-kunnr.
selection-screen skip 1.
parameters: filename type rlgrap-filename obligatory.
selection-screen skip 1.
parameter :p_vk11 as checkbox .
parameters: p_test as checkbox default 'X'.
selection-screen end of block 1.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN
*----------------------------------------------------------------------*
at selection-screen on value-request for filename.
call function 'WS_FILENAME_GET'
exporting
def_path = 'C:\'
mask = ',Excel Files,*.xls,All Files,*.*.'(101)
mode = 'O'
title = 'Select file'(100)
importing
filename = filename
exceptions
selection_cancel = 1
selection_error = 2
others = 3.
if sy-subrc ne 0.
" .
endif.
*&---------------------------------------------------------------------*
* start of process
*&---------------------------------------------------------------------*
start-of-selection.
refresh: it_record ,lt_gt_data.
clear:it_record ,lt_gt_data.
perform manual_upld.
if sy-subrc ne 0.
clear msg.
concatenate 'Upload Filename ' filename ' is Error' into msg.
message msg type 'I'.
exit.
endif.
sort lt_gt_data by row col value.
read table lt_gt_data index 1.
if sy-subrc ne 0.
clear : msg.
concatenate 'Upload File ' filename ' Is Null!' into msg.
message msg type 'I'.
exit.
endif.
perform get_it_record.
if it_record[] is initial.
clear : msg.
concatenate 'Upload File ' filename ' Is Null!' into msg.
message msg type 'I'.
exit.
endif.
perform get_check_data.
if it_success[] is initial.
message i003(zmm).
exit.
endif.
perform get_update_price_so.
perform get_data.
if p_test is initial.
*M1 add
if p_vk11 is initial.
perform update_vk11_price.
endif.
*M1 End
perform process_data.
endif.
perform get_result_data.
perform display_data.
*&---------------------------------------------------------------------*
*& Form MANUAL_UPLD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form manual_upld .
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
text = 'Getting Data........'.
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = filename
i_begin_col = '1'
i_begin_row = '2'
i_end_col = '6'
i_end_row = '50000'
tables
intern = lt_gt_data
exceptions
upload_ole = 1.
if sy-subrc ne 0.
" message i004(zmm)
endif.
endform. " MANUAL_UPLD
*&---------------------------------------------------------------------*
*& Form GET_FILE_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_it_record .
check not lt_gt_data[] is initial.
loop at lt_gt_data.
shift lt_gt_data-value right deleting trailing space.
shift lt_gt_data-value left deleting leading space.
case lt_gt_data-col.
when '1'.
perform add_pre_zero using lt_gt_data-value
changing it_record-kunnr.
when '2'.
perform tranfer_material using lt_gt_data-value
changing it_record-matnr.
when '3'.
it_record-kschl = lt_gt_data-value .
when '4'.
perform process_num using lt_gt_data-value
changing it_record-kbetr .
when '5'.
perform process_num using lt_gt_data-value
changing it_record-kpein .
when '6'.
it_record-waers = lt_gt_data-value .
endcase.
at end of row.
append it_record.
clear:it_record.
endat.
endloop.
sort it_record by kunnr matnr.
free: lt_gt_data.
endform. " GET_FILE_DATA
*&---------------------------------------------------------------------*
*& Form GET_UPDATE_PRICE_SO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_update_price_so .
data: lv_stonr like tj30-stonr.
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
text = 'Getting SO Data........'.
sort it_success by kunnr matnr kschl.
select a~vbeln b~posnr a~kunnr b~matnr a~knumv b~kwmeng a~objnr a~vkorg a~vtweg b~vrkme
into corresponding fields of table it_so
from vbak as a inner join vbap as b on a~vbeln = b~vbeln
for all entries in it_success
where a~kunnr = it_success-kunnr
and b~matnr = it_success-matnr
and a~vbeln like '01%'
and a~vbeln in s_vbeln
and b~posnr in s_posnr
and a~auart in s_auart
and a~kunnr in s_kunnr.
"check Billing qty is >= so qty , >= is delete
if it_so[] is not initial.
sort it_so by vbeln posnr.
select aubel aupos fkimg vbeln posnr
into corresponding fields of table it_vbrp_08
from vbrp
for all entries in it_so
where aubel = it_so-vbeln
and aupos = it_so-posnr
and ( vbeln like '08%' or vbeln like '09%').
loop at it_vbrp_08 .
it_vbrp-aubel = it_vbrp_08-aubel.
it_vbrp-aupos = it_vbrp_08-aupos.
if it_vbrp_08-vbeln+0(2) = '09'.
it_vbrp-fkimg = 0 - it_vbrp_08-fkimg.
else.
it_vbrp-fkimg = it_vbrp_08-fkimg.
endif.
collect it_vbrp.
clear: it_vbrp.
endloop.
if it_vbrp[] is not initial.
sort it_vbrp by aubel aupos.
loop at it_so.
lv_tabix = sy-tabix.
call function 'STATUS_READ'
exporting
objnr = it_so-objnr
importing
stonr = lv_stonr
exceptions
object_not_found = 1
others = 2.
if lv_stonr ne '20'. " SO Approved
delete it_so index lv_tabix.
else.
read table it_vbrp with key aubel = it_so-vbeln aupos = it_so-posnr binary search.
if sy-subrc eq 0.
if it_vbrp-fkimg >= it_so-kwmeng . " billing qty >= so qty
delete it_so index lv_tabix.
else.
it_vbeln-vbeln = it_so-vbeln.
collect it_vbeln.
clear:it_vbeln.
it_so-fkimg = it_vbrp-fkimg.
modify it_so index lv_tabix transporting fkimg .
endif.
endif.
endif.
endloop.
endif.
endif.
" get so price (old)
if it_so[] is not initial.
sort it_so by knumv posnr.
select *
into corresponding fields of table it_konv
from konv
for all entries in it_so
where knumv = it_so-knumv
and kposn = it_so-posnr
and ( kschl = 'PR00'
or kschl like 'Z%'). " ('PR00','ZSC1','ZSC2' ,'ZSC3')
sort it_konv by knumv kposn.
sort it_so by vbeln posnr.
endif.
free:it_vbrp_08,it_vbrp.
endform. " GET_UPDATE_PRICE_SO
*&---------------------------------------------------------------------*
*& Form GET_CHECK_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_check_data .
data:lv_flag type c.
select matnr
into corresponding fields of table it_mara
from mara
for all entries in it_record
where matnr = it_record-matnr.
sort it_mara by matnr.
select kunnr
into corresponding fields of table it_kna1
from kna1
for all entries in it_record
where kunnr = it_record-kunnr.
sort it_kna1 by kunnr .
select distinct waers
into corresponding fields of table it_tcurc
from tcurc.
sort it_tcurc by waers.
select distinct kschl into table it_t685
from t685.
sort it_t685 by kschl.
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
text = 'Checking Data........'.
loop at it_record.
"Material
read table it_mara with key matnr = it_record-matnr binary search.
if sy-subrc ne 0.
lv_flag = 'X'.
concatenate it_record-message ' Material Not Exists.'
into it_record-message.
endif.
"Customer
read table it_kna1 with key kunnr = it_record-kunnr binary search.
if sy-subrc ne 0.
lv_flag = 'X'.
concatenate it_record-message ' Customer Not Exists.'
into it_record-message.
endif.
"Condition Type
read table it_t685 with key kschl = it_record-kschl binary search .
if sy-subrc <> 0.
lv_flag = 'X'.
concatenate it_record-message ' Condition Type Not Exists.'
into it_record-message.
endif.
if it_record-kbetr < 0.
lv_flag = 'X'.
concatenate it_record-message
' Price is negative or Price not is number.'
into it_record-message.
endif.
"Per
if it_record-kpein = 0.
lv_flag = 'X'.
concatenate it_record-message
' Per = 0 is error.' into it_record-message.
modify it_record index lv_tabix.
elseif it_record-kpein < 0.
lv_flag = 'X'.
concatenate it_record-message
' Per is negative or Per not is number.'
into it_record-message.
endif.
"Currency
read table it_tcurc with key waers = it_record-waers binary search .
if sy-subrc <> 0.
lv_flag = 'X'.
concatenate it_record-message ' Currency Not Exists.'
into it_record-message.
endif.
if lv_flag is initial.
move-corresponding it_record to it_success.
append it_success.
else.
move-corresponding it_record to it_error.
append it_error.
endif.
clear:lv_flag ,it_success,it_error.
endloop.
free:it_record,it_mara,it_kna1, it_t685,it_tcurc.
endform. " GET_CHECK_DATA
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_data .
data: it_so1 like it_so occurs 0 with header line.
it_so1[] = it_so[].
clear:it_so,it_so[].
loop at it_so1.
move-corresponding it_so1 to it_so.
it_vbeln-vbeln = it_so-vbeln.
collect it_vbeln.
clear:it_vbeln.
read table it_konv with key knumv = it_so-knumv kposn = it_so-posnr.
if sy-subrc eq 0.
loop at it_konv where knumv = it_so-knumv and kposn = it_so-posnr.
it_so-kschl_o = it_konv-kschl.
it_so-kbetr_o = it_konv-kbetr.
it_so-waers_o = it_konv-waers.
it_so-kpein_o = it_konv-kpein.
it_so-stunr = it_konv-stunr.
it_so-zaehk = it_konv-zaehk.
read table it_success with key kunnr = it_so-kunnr matnr = it_so-matnr kschl = it_so-kschl.
if sy-subrc eq 0.
it_so-kschl = it_success-kschl.
it_so-kbetr = it_success-kbetr.
it_so-waers = it_success-waers.
it_so-kpein = it_success-kpein.
else.
read table it_success with key kunnr = it_so-kunnr matnr = it_so-matnr.
if sy-subrc eq 0.
it_so-kschl = it_success-kschl.
it_so-kbetr = it_success-kbetr.
it_so-waers = it_success-waers.
it_so-kpein = it_success-kpein.
endif.
endif.
if it_so-waers <> it_so-waers_o or it_so-kschl <> it_so-kschl_o .
if it_so-waers <> it_so-waers_o .
concatenate it_so-message ' Currency not same.'
into it_so-message.
endif.
delete it_vbeln where vbeln = it_so-vbeln.
endif.
*M1 add
if p_vk11 is initial.
if it_so-matnr is not initial and it_so-message is initial..
read table it_pr00 with key matnr = it_so-matnr vkorg = it_so-vkorg vtweg = it_so-vtweg.
if sy-subrc ne 0 .
move-corresponding it_so to it_pr00.
select *
from a304
where kappl = 'V'
and kschl = it_pr00-kschl
and vkorg = it_pr00-vkorg
and vtweg = it_pr00-vtweg
and matnr = it_pr00-matnr
and datbi >= sy-datum
and datab <= sy-datum .
endselect.
if sy-subrc eq 0.
it_pr00-mode = 'B'.
else.
it_pr00-mode = 'A'.
endif.
append it_pr00.
clear: it_pr00.
endif.
endif.
endif.
*M1 End
append it_so.
clear:it_so-kschl_o ,
it_so-kbetr_o ,
it_so-waers_o ,
it_so-kpein_o ,
it_so-stunr ,
it_so-zaehk ,
it_so-kschl ,
it_so-kbetr ,
it_so-waers ,
it_so-kpein ,
it_so-message.
endloop.
else.
read table it_success with key kunnr = it_so-kunnr matnr = it_so-matnr.
if sy-subrc eq 0.
it_so-kschl = it_success-kschl.
it_so-kbetr = it_success-kbetr.
it_so-waers = it_success-waers.
it_so-kpein = it_success-kpein.
it_so-stunr = '011'.
it_so-zaehk = '01'.
endif.
*M1 add
if p_vk11 is initial.
if it_so-matnr is not initial.
read table it_pr00 with key matnr = it_so-matnr vkorg = it_so-vkorg vtweg = it_so-vtweg.
if sy-subrc ne 0 .
move-corresponding it_so to it_pr00.
select *
from a304
where kappl = 'V'
and kschl = it_pr00-kschl
and vkorg = it_pr00-vkorg
and vtweg = it_pr00-vtweg
and matnr = it_pr00-matnr
and datbi >= sy-datum
and datab <= sy-datum .
endselect.
if sy-subrc eq 0.
it_pr00-mode = 'B'.
else.
it_pr00-mode = 'A'.
endif.
append it_pr00.
clear: it_pr00.
endif.
endif.
endif.
*M1 End
append it_so.
clear:it_so.
endif.
endloop.
free:it_so1.
endform. " GET_DATA
*&---------------------------------------------------------------------*
*& Form PROCESS_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form process_data .
check it_vbeln[] is not initial.
data:lv_tabix like sy-tabix.
data:lv_message type c length 255.
call function 'SAPGUI_PROGRESS_INDICATOR'
exporting
text = 'Changing Data........'.
loop at it_vbeln.
lv_tabix = sy-tabix.
i_headerx-updateflag = 'U'. "Update flag
loop at it_so where vbeln = it_vbeln-vbeln.
if it_so-kschl is not initial.
i_cond-itm_number = it_so-posnr.
i_cond-cond_st_no = it_so-stunr.
i_cond-cond_count = it_so-zaehk.
i_cond-cond_type = it_so-kschl. "Condition Type
i_cond-cond_value = it_so-kbetr. "Amount
i_cond-currency = it_so-waers. "Currency
i_cond-cond_p_unt = it_so-kpein . "Per
* i_cond-cond_unit = it_konv-kmein. "Condition Unit
append i_cond.
i_condx-updateflag = 'U'.
i_condx-itm_number = it_so-posnr.
i_condx-cond_st_no = it_so-stunr.
i_condx-cond_count = it_so-zaehk.
i_condx-cond_type = it_so-kschl.
i_condx-cond_value = 'X'.
i_condx-currency = 'X'.
i_condx-cond_p_unt = 'X'.
* i_condx-cond_unit = 'X'.
append i_condx.
endif.
endloop.
if i_cond[] is not initial.
call function 'BAPI_SALESORDER_CHANGE'
exporting
salesdocument = it_vbeln-vbeln
order_header_inx = i_headerx
tables
return = it_return
* order_item_in = i_item
* order_item_inx = i_itemx
* partners = i_partners
* partnerchanges = i_partnerchanges
* PARTNERADDRESSES =
* ORDER_CFGS_REF =
* ORDER_CFGS_INST =
* ORDER_CFGS_PART_OF =
* ORDER_CFGS_VALUE =
* ORDER_CFGS_BLOB =
* ORDER_CFGS_VK =
* ORDER_CFGS_REFINST =
* schedule_lines = i_sch
* schedule_linesx = i_schx
* ORDER_TEXT =
* ORDER_KEYS =
conditions_in = i_cond
conditions_inx = i_condx
* EXTENSIONIN =
.
read table it_return with key type = 'E'.
if sy-subrc eq 0.
loop at it_return where type = 'E'.
shift it_return-message right deleting trailing space.
shift it_return-message left deleting leading space.
concatenate lv_message ' E: ' it_return-message into lv_message.
endloop.
else.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
read table it_return with key type = 'S' id ='V1' number = '311'.
if sy-subrc eq 0.
lv_message ='Update successed.'. "it_return-message.
else.
read table it_return with key type = 'S' id ='V1' number = '041'.
if sy-subrc eq 0.
lv_message = it_return-message.
else.
loop at it_return where type = 'S'.
shift it_return-message right deleting trailing space.
shift it_return-message left deleting leading space.
concatenate lv_message ' S: ' it_return-message into lv_message.
endloop.
endif.
endif.
endif.
else.
lv_message = 'No Found price'.
endif.
it_vbeln-message = lv_message.
modify it_vbeln index lv_tabix.
clear:i_headerx,lv_message,it_return,it_return[],
i_cond, i_cond[],i_condx,i_condx[] .
endloop.
endform. " PROCESS_DATA
*&---------------------------------------------------------------------*
*& Form GET_RESULT_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_result_data .
loop at it_error.
move-corresponding it_error to itab.
append itab.
clear: itab.
endloop.
loop at it_success.
read table it_so with key kunnr = it_success-kunnr matnr = it_success-matnr.
if sy-subrc eq 0.
loop at it_so where kunnr = it_success-kunnr and matnr = it_success-matnr.
move-corresponding it_so to itab.
read table it_vbeln with key vbeln = itab-vbeln.
if sy-subrc eq 0.
itab-message = it_vbeln-message.
endif.
*M1 add
if p_vk11 is initial.
read table it_pr00 with key matnr = it_so-matnr vkorg = it_so-vkorg vtweg = it_so-vtweg.
if sy-subrc eq 0.
itab-msgpr00 = it_pr00-msgpr00.
endif.
endif.
*M1 End
append itab.
clear:itab.
endloop.
else.
move-corresponding it_success to itab.
itab-message = 'No SO Update'.
append itab.
clear: itab.
endif.
endloop.
free: it_error,it_so ,it_success,it_vbeln,it_pr00.
endform. " GET_RESULT_DATA
*&---------------------------------------------------------------------*
*& Form DISPLAY_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form display_data .
refresh fc_hier.
define alv_field.
clear:wa_hier.
wa_hier-fieldname = &1.
wa_hier-seltext_m = &2.
wa_hier-seltext_l = &3.
wa_hier-outputlen = &4.
wa_hier-ref_tabname = &5 .
wa_hier-ref_fieldname = &6 .
wa_hier-hotspot = &7.
append wa_hier to fc_hier.
end-of-definition.
alv_field 'KUNNR' '' '' '10' 'KNA1' 'KUNNR' ''.
alv_field 'MATNR' '' '' '18' 'MARA' 'MATNR' 'X'.
alv_field 'VBELN' '' 'SO No.' '12' 'VBAP' 'VBELN' 'X'.
alv_field 'POSNR' '' 'Item' '6' '' '' ''..
alv_field 'KSCHL' '' 'New Condition type' '6' '' '' ''.
alv_field 'KBETR' '' 'New Value' '10' '' '' ''.
alv_field 'KPEIN' '' 'New Price Unit' '6' '' '' ''.
alv_field 'WAERS' '' 'New Currency' '6' '' '' ''.
alv_field 'KSCHL_O' '' 'Old Condition type' '6' '' '' ''.
alv_field 'KBETR_O' '' 'Old Value' '10' '' '' ''.
alv_field 'KPEIN_O' '' 'Old Price Unit' '6' '' '' ''.
alv_field 'WAERS_O' '' 'Old Currency' '6' '' '' ''.
alv_field 'KWMENG' '' 'Order Qty' '10' '' '' ''.
alv_field 'FKIMG' '' 'Billing Qty' '10' '' '' ''.
alv_field 'MESSAGE' 'SO Message' '' '30' '' '' ''.
alv_field 'MSGPR00' 'VK11 Message' '' '30' '' '' ''.
sort itab by kunnr matnr.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = sy-repid
it_fieldcat = fc_hier[]
i_save = 'A'
i_callback_user_command = 'ALV_USER_COMMAND'
tables
t_outtab = itab
exceptions
program_error = 1
others = 2.
if sy-subrc ne 0.
" message i004(zmm)
endif.
endform. " DISPLAY_DATA
*&---------------------------------------------------------------------*
*& Form ALV_USER_COMMAND
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->R_UCOMM text
* -->RS_SELFIELD text
*----------------------------------------------------------------------*
form alv_user_command using r_ucomm like sy-ucomm
rs_selfield type slis_selfield. "响应ALV点击自定义按钮之后的事件
data:lv_matnr like mara-matnr.
case r_ucomm.
when '&IC1'.
if rs_selfield-fieldname ='VBELN' and rs_selfield-value <>''.
set parameter id :'AUN' field rs_selfield-value .
call transaction 'VA03' and skip first screen .
elseif rs_selfield-fieldname ='MATNR' and rs_selfield-value <>''.
perform tranfer_material using rs_selfield-value changing lv_matnr.
set parameter id :'MAT' field lv_matnr .
call transaction 'MM03' and skip first screen .
endif.
endcase.
endform. "alv_user_command
*&---------------------------------------------------------------------*
*& Form TRANFER_MATERIAL
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_ITAB_MATNR text
* <--P_ITAB_MATNR_C text
*----------------------------------------------------------------------*
form tranfer_material using p_old
changing p_new .
translate p_old to upper case.
call function 'CONVERSION_EXIT_MATN1_INPUT'
exporting
input = p_old
importing
output = p_new
exceptions
length_error = 1
others = 2.
if sy-subrc <> 0.
p_new = p_old.
endif.
endform. "tranfer_material
*&---------------------------------------------------------------------*
*& Form PROCESS_NUM
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_LT_GT_DATA_VALUE text
* <--P_IT_RECORD_KPEIN text
*----------------------------------------------------------------------*
form process_num using p_value
changing p_change.
data :lv_value type c length 30 .
if p_value cn c_chk_num.
p_change = -1.
else.
lv_value = p_value.
call function 'C14DG_CHAR_NUMBER_CONVERSION'
exporting
i_string = lv_value
importing
* E_FLOAT =
e_dec = p_change
* E_DECIMALS =
exceptions
wrong_characters = 1
first_character_wrong = 2
arithmetic_sign = 3
multiple_decimal_separator = 4
thousandsep_in_decimal = 5
thousand_separator = 6
number_too_big = 7
others = 8.
if sy-subrc = 7.
p_change = p_value.
endif.
endif.
endform. " PROCESS_NUM
*&---------------------------------------------------------------------*
*& Form ADD_PRE_ZERO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_IT_RECORD_WEEKS_C text
* <--P_IT_RECORD_WEEKS_C text
*----------------------------------------------------------------------*
form add_pre_zero using p_old
changing p_new .
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = p_old
importing
output = p_new.
endform. " ADD_PRE_ZERO
*&---------------------------------------------------------------------*
*& Form UPDATE_VK11_PRICE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form update_vk11_price .
data: ls_komg type komg,
ls_komv type komv,
lt_komv type table of komv,
lv_new_record,
lv_str type c length 255.
loop at it_pr00.
lv_tabix = sy-tabix.
ls_komg-matnr = it_pr00-matnr. " Mat number
ls_komg-vkorg = it_pr00-vkorg.
ls_komg-vtweg = it_pr00-vtweg.
clear: lt_komv,ls_komv.
ls_komv-kappl = 'V'. " Application V = Sales
ls_komv-kschl = it_pr00-kschl. " Condition type
ls_komv-krech = 'B'. " calculation type; B -Fixed amount
ls_komv-waers = it_pr00-waers. " Currency
ls_komv-kpein = it_pr00-kpein.
ls_komv-kmein = it_pr00-vrkme. " Unit of measurement
ls_komv-kbetr = it_pr00-kbetr. " new condition value
append ls_komv to lt_komv.
call function 'RV_CONDITION_COPY'
exporting
application = 'V'
condition_table = '304'
condition_type = 'PR00'
* DATE_FROM = '20110629'
* DATE_TO = '99991231'
enqueue = 'X'
* I_KOMK = ' '
* I_KOMP = ' '
key_fields = ls_komg
maintain_mode = it_pr00-mode "'B'
no_authority_check = 'X'
no_field_check = 'X'
* SELECTION_DATE = '?'
keep_old_records = 'X'
* MATERIAL_M =
* USED_BY_IDOC = ' '
* I_KONA =
overlap_confirmed = 'X'
no_db_update = ' '
* USED_BY_RETAIL = ' '
importing
* E_KOMK =
* E_KOMP =
new_record = lv_new_record
* E_DATAB =
* E_DATBI =
* E_PRDAT =
tables
copy_records = lt_komv
* COPY_STAFFEL =
* COPY_RECS_IDOC =
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 ne 0.
concatenate sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 into lv_str.
else.
break jdonepud.
call function 'RV_CONDITION_SAVE'.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
lv_str = 'VK11 Price Update Success'.
endif.
it_pr00-msgpr00 = lv_str.
modify it_pr00 index lv_tabix transporting msgpr00.
clear: lt_komv,lt_komv[],lv_str.
endloop.
free: lt_komv.
endform. " UPDATE_VK11_PRICE