*&---------------------------------------------------------------------*
*& Progarm : ZSDR004 Author : Jimmy Wong
*& Created : 17 OCT 2012 App : SD
*& Title : Upload Forecast
*& Description : Upload Forecast
*&---------------------------------------------------------------------*
*& Version Author Date description
*& Jimmy 17 Sep 2012 the first version
*& the last update time 2012.09.17 17:00
*&---------------------------------------------------------------------*
report zsdr006 no standard page heading.
tables:vbak.
data:begin of itab occurs 10,
vbeln like vbak-vbeln,
message type c length 700,
end of itab.
data:lv_tabix like sy-tabix.
data: it_bdcmsg like bdcmsgcoll occurs 0 with header line,
bdcdata like bdcdata occurs 0 with header line,
pr_mode type ctu_mode .
type-pools: slis.
data: fc_hier type slis_t_fieldcat_alv,
wa_hier type slis_fieldcat_alv .
*&---------------------------------------------------------------------*
* parameter & select-options
*&---------------------------------------------------------------------*
selection-screen begin of block 1 with frame title text-010.
select-options: s_vbeln for vbak-vbeln. "default '01*'. "custmer p/n"
selection-screen end of block 1.
initialization.
s_vbeln-sign = 'I'.
s_vbeln-option = 'CP'.
s_vbeln-low = '01*'.
append s_vbeln.
*&---------------------------------------------------------------------*
* start of process
*&---------------------------------------------------------------------*
start-of-selection.
perform get_data.
perform process_data.
perform dispaly_data.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_data .
select vbeln
into corresponding fields of table itab
from vbak
where vbeln in s_vbeln.
endform. " GET_DATA
*&---------------------------------------------------------------------*
*& Form PROCESS_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form process_data .
pr_mode = 'N'.
loop at itab.
clear:it_bdcmsg,it_bdcmsg[], bdcdata, bdcdata[].
* check sy-tabix <= 10.
lv_tabix = sy-tabix.
perform bdc_dynpro using 'SAPMV45A' '0102'.
perform bdc_field using 'BDC_CURSOR'
'VBAK-VBELN'.
perform bdc_field using 'BDC_OKCODE'
'=SUCH'.
perform bdc_field using 'VBAK-VBELN'
itab-vbeln.
perform bdc_dynpro using 'SAPMV45A' '4001'.
perform bdc_field using 'BDC_OKCODE'
'=KSTA'.
perform bdc_field using 'BDC_CURSOR'
'RV45A-MABNR(01)'.
perform bdc_dynpro using 'SAPMV45A' '4002'.
perform bdc_field using 'BDC_OKCODE'
'=KSTC'.
perform bdc_field using 'BDC_CURSOR'
'VBAK-VBELN'.
perform bdc_dynpro using 'SAPLBSVA' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=BACK'.
perform bdc_field using 'BDC_CURSOR'
'J_STMAINT-ANWS(02)'.
perform bdc_field using 'J_STMAINT-ANWS(02)'
'X'.
perform bdc_dynpro using 'SAPMV45A' '4002'.
perform bdc_field using 'BDC_OKCODE'
'=SICH'.
perform bdc_field using 'BDC_CURSOR'
'VBAK-VBELN'.
call transaction 'VA02'
using bdcdata
mode pr_mode "Background performance
update 'S' "local updata
messages into it_bdcmsg. "all message table
read table it_bdcmsg with key msgtyp = 'E'.
if sy-subrc ne 0.
itab-message = it_bdcmsg-msgv1.
modify itab index lv_tabix.
endif.
endloop.
endform. " PROCESS_DATA
*----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*
form bdc_dynpro using program dynpro.
clear bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = 'X'.
append bdcdata.
endform. "BDC_DYNPRO
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
form bdc_field using fnam fval.
clear bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
append bdcdata.
endform. "BDC_FIELD
*&---------------------------------------------------------------------*
*& Form DISPALY_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form dispaly_data .
refresh fc_hier.
define alv_field.
clear:wa_hier.
wa_hier-col_pos = &1.
wa_hier-fieldname = &2.
wa_hier-seltext_m = &3.
wa_hier-seltext_l = &4.
wa_hier-outputlen = &5.
append wa_hier to fc_hier.
end-of-definition.
alv_field '1' 'VBELN' '' 'SO No.' ''.
alv_field '2' 'MESSAGE' 'Message' '' '50'.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
it_fieldcat = fc_hier[]
tables
t_outtab = itab[]
exceptions
program_error = 1
others = 2.
if sy-subrc ne 0.
" message i004(zmm)
endif.
endform. " DISPALY_DATA
*& Progarm : ZSDR004 Author : Jimmy Wong
*& Created : 17 OCT 2012 App : SD
*& Title : Upload Forecast
*& Description : Upload Forecast
*&---------------------------------------------------------------------*
*& Version Author Date description
*& Jimmy 17 Sep 2012 the first version
*& the last update time 2012.09.17 17:00
*&---------------------------------------------------------------------*
report zsdr006 no standard page heading.
tables:vbak.
data:begin of itab occurs 10,
vbeln like vbak-vbeln,
message type c length 700,
end of itab.
data:lv_tabix like sy-tabix.
data: it_bdcmsg like bdcmsgcoll occurs 0 with header line,
bdcdata like bdcdata occurs 0 with header line,
pr_mode type ctu_mode .
type-pools: slis.
data: fc_hier type slis_t_fieldcat_alv,
wa_hier type slis_fieldcat_alv .
*&---------------------------------------------------------------------*
* parameter & select-options
*&---------------------------------------------------------------------*
selection-screen begin of block 1 with frame title text-010.
select-options: s_vbeln for vbak-vbeln. "default '01*'. "custmer p/n"
selection-screen end of block 1.
initialization.
s_vbeln-sign = 'I'.
s_vbeln-option = 'CP'.
s_vbeln-low = '01*'.
append s_vbeln.
*&---------------------------------------------------------------------*
* start of process
*&---------------------------------------------------------------------*
start-of-selection.
perform get_data.
perform process_data.
perform dispaly_data.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form get_data .
select vbeln
into corresponding fields of table itab
from vbak
where vbeln in s_vbeln.
endform. " GET_DATA
*&---------------------------------------------------------------------*
*& Form PROCESS_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form process_data .
pr_mode = 'N'.
loop at itab.
clear:it_bdcmsg,it_bdcmsg[], bdcdata, bdcdata[].
* check sy-tabix <= 10.
lv_tabix = sy-tabix.
perform bdc_dynpro using 'SAPMV45A' '0102'.
perform bdc_field using 'BDC_CURSOR'
'VBAK-VBELN'.
perform bdc_field using 'BDC_OKCODE'
'=SUCH'.
perform bdc_field using 'VBAK-VBELN'
itab-vbeln.
perform bdc_dynpro using 'SAPMV45A' '4001'.
perform bdc_field using 'BDC_OKCODE'
'=KSTA'.
perform bdc_field using 'BDC_CURSOR'
'RV45A-MABNR(01)'.
perform bdc_dynpro using 'SAPMV45A' '4002'.
perform bdc_field using 'BDC_OKCODE'
'=KSTC'.
perform bdc_field using 'BDC_CURSOR'
'VBAK-VBELN'.
perform bdc_dynpro using 'SAPLBSVA' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=BACK'.
perform bdc_field using 'BDC_CURSOR'
'J_STMAINT-ANWS(02)'.
perform bdc_field using 'J_STMAINT-ANWS(02)'
'X'.
perform bdc_dynpro using 'SAPMV45A' '4002'.
perform bdc_field using 'BDC_OKCODE'
'=SICH'.
perform bdc_field using 'BDC_CURSOR'
'VBAK-VBELN'.
call transaction 'VA02'
using bdcdata
mode pr_mode "Background performance
update 'S' "local updata
messages into it_bdcmsg. "all message table
read table it_bdcmsg with key msgtyp = 'E'.
if sy-subrc ne 0.
itab-message = it_bdcmsg-msgv1.
modify itab index lv_tabix.
endif.
endloop.
endform. " PROCESS_DATA
*----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*
form bdc_dynpro using program dynpro.
clear bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = 'X'.
append bdcdata.
endform. "BDC_DYNPRO
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
form bdc_field using fnam fval.
clear bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
append bdcdata.
endform. "BDC_FIELD
*&---------------------------------------------------------------------*
*& Form DISPALY_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form dispaly_data .
refresh fc_hier.
define alv_field.
clear:wa_hier.
wa_hier-col_pos = &1.
wa_hier-fieldname = &2.
wa_hier-seltext_m = &3.
wa_hier-seltext_l = &4.
wa_hier-outputlen = &5.
append wa_hier to fc_hier.
end-of-definition.
alv_field '1' 'VBELN' '' 'SO No.' ''.
alv_field '2' 'MESSAGE' 'Message' '' '50'.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
it_fieldcat = fc_hier[]
tables
t_outtab = itab[]
exceptions
program_error = 1
others = 2.
if sy-subrc ne 0.
" message i004(zmm)
endif.
endform. " DISPALY_DATA