report zgeedpc0010 line-size 255 line-count 65
no standard page heading.
*----------------------------------------------------------------------*
* C R E S T P R O J E C T *
*----------------------------------------------------------------------*
* NCS Confidential and Proprietary *
* Copyright 2008, *
* All Rights Reserved *
*----------------------------------------------------------------------*
* PURPOSE/TITLE: BDC Framework Program *
* VERSION : 1.0 *
* CREATED BY : Andre *
* PROCESS SPEC : N/A(This is BDC template only, not require by youself)*
* ASSUMPTIONS : This program can transfer many records *
* WEAKNESSES : *
*----------------------------------------------------------------------*
* Revision History: *
* *
* Date Author Transport/Description *
* --------- --------- ---------------------- *
* 25-Jun-08 Andre ND4K123456 *
* Modify the naming conversion *
* *
* 25-Jun-08 zhang jitang ND4K900485
* 1. Test one record work fine *
* 2. Test two records work fine *
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* D A T A A N D T Y P E D E F I N I T I O N S *
*----------------------------------------------------------------------*
type-pools:slis, icon.
constants:
*V====================================================================V
gc_bdc_ok_id type sy-msgid value 'PG',
gc_bdc_ok_nr type sy-msgno value '102',
gc_bdc_tcode type sy-tcode value 'PA30',
gc_itype_num(2) type c value '35',
*^====================================================================^
gc_yes type c value 'X',
gc_no type c value space,
gc_zero type i value 0,
gc_delimiter type c value '|',
* User Spesific Layout Saving
gc_save type c value 'U'.
*--Common Mandatory and Non Mandatory ALV Variables
data:
gt_layout type slis_layout_alv,
gt_events type slis_t_event,
gt_fieldcat type slis_t_fieldcat_alv,
gt_list_top type slis_t_listheader,
gwa_print_ctrl type slis_print_alv,
gwa_fieldcat type slis_fieldcat_alv,
gt_variant type disvariant,
g_data_count type i.
data:
gwa_gs_extract1 type disextract,
gwa_gs_extract2 type disextract.
data:
gt_bdcdata type standard table of bdcdata,
gwa_bdcdata type bdcdata,
gt_messtab type standard table of bdcmsgcoll,
gwa_messtab type bdcmsgcoll,
gt_flist type filetable,
gwa_flist(1024) type c,
g_fcoun type i,
*Defined a string table to store the data,because the GUI_UPLOAD just can identify the data file separated by tab.
*changed by jitang 21,07,2008.
gt_string type table of string.
types:
begin of ty_s_print,
recno type i,
eflag(4) type c,
messg type string,
colinfo type lvc_t_scol,
end of ty_s_print,
ty_t_print type standard table of ty_s_print,
begin of ty_s_record,
*V====================================================================V
pernr_001(8) type c, "Personnel Number
begda_002(10) type c, "Start Date
endda_003(10) type c, "End Date
blehr_004(4) type c, "Instruction
dat35_005(10) type c,
"Date for infortype 0035 Company instructions
text1_006(72) type c, "Excerpt from infotype text module
text2_007(72) type c, "Excerpt from infotype text module
text3_008(72) type c, "Excerpt from infotype text module
*^====================================================================^
end of ty_s_record,
ty_t_record type standard table of ty_s_record.
data:
gt_print type ty_t_print,
gt_record type ty_t_record.
data:
gwa_print type ty_s_print,
gwa_record type ty_s_record.
data: g_keep value 'X'.
*-- ' ' = delete session if finished
*-- 'X' = keep session if finished
data:
g_holddate like sy-datum,
g_nodata value '/'.
data :
gwa_option type ctu_params,
g_msgno type sy-msgno,
gwa_message type message,
g_bdctabix type sy-tabix,
g_record type string.
data:
g_file_odialog_title type string,
g_file_odialog_def_fname type string,
g_file_odialog_init_dir type string.
*----------------------------------------------------------------------*
* S E L E C T I O N S C R E E N *
*----------------------------------------------------------------------*
selection-screen: begin of block bl001 with frame title text-t01.
*--Local File ('X' is True)
*--File Name
*--Remote File Mode ('X' is True)
*--Data Set Name
parameters:
rb_lfile radiobutton group g1a default 'X' user-command uc2,
p_fname type string default text-c01 modif id m3,
rb_rfile radiobutton group g1a,
p_dtset type filenameci-fileintern modif id m4 default text-c08.
selection-screen: begin of block bl002 with frame title text-t02.
*--Session Mode
*--Call Transaction Mode
parameters:
rb_sessm radiobutton group g1 user-command uc1,
rb_tranm radiobutton group g1 default 'X'.
selection-screen: end of block bl002.
selection-screen: begin of block bl003.
*--Session Name
parameters:
p_sesnm(12) type c modif id m1 default sy-uzeit.
selection-screen: end of block bl003.
selection-screen: begin of block bl004 with frame title text-t03.
*--Background Mode
*--Foreground Mode
*--Foreground When Error Mode
parameters:
rb_backg radiobutton group g1b default 'X' modif id m2,
rb_foreg radiobutton group g1b modif id m2,
rb_errrg radiobutton group g1b modif id m2.
selection-screen: end of block bl004.
selection-screen: end of block bl001.
*----------------------------------------------------------------------*
* I N I T I A L I Z A T I O N *
*----------------------------------------------------------------------*
initialization.
g_file_odialog_title = text-c02.
g_file_odialog_def_fname = text-c05.
g_file_odialog_init_dir = text-c06.
call function 'REUSE_ALV_EXTRACT_AT_INIT'
changing
cs_extract1 = gwa_gs_extract1
cs_extract2 = gwa_gs_extract2.
at selection-screen on value-request for p_fname.
refresh gt_flist.
call method cl_gui_frontend_services=>file_open_dialog
exporting
window_title = g_file_odialog_title
default_filename = g_file_odialog_def_fname
initial_directory = g_file_odialog_init_dir
multiselection = gc_no
changing
file_table = gt_flist
rc = g_fcoun
exceptions
file_open_dialog_failed = 1
cntl_error = 2
error_no_gui = 3
not_supported_by_gui = 4
others = 5.
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 gt_flist into gwa_flist index 1.
p_fname = gwa_flist.
at selection-screen output.
loop at screen.
*If Local file chosen, show only the file name parameters
*If Server file chosen, show only the Dataset parameters
if rb_lfile is not initial.
if screen-group1 eq 'M3'.
screen-active = '1'.
elseif screen-group1 eq 'M4'.
screen-active = '0'.
endif.
elseif rb_rfile is not initial.
if screen-group1 eq 'M4'.
screen-active = '1'.
elseif screen-group1 eq 'M3'.
screen-active = '0'.
endif.
endif.
*If Session Mode chosen, show only the Session Name parameters
*If Transaction Mode chosen, show only the Processing Mode Option
if rb_sessm is not initial.
if screen-group1 eq 'M1'.
screen-active = '1'.
elseif screen-group1 eq 'M2'.
screen-active = '0'.
endif.
elseif rb_tranm is not initial.
if screen-group1 eq 'M2'.
screen-active = '1'.
elseif screen-group1 eq 'M1'.
screen-active = '0'.
endif.
endif.
modify screen.
endloop.
*----------------------------------------------------------------------*
* M A I N P R O G R A M *
*----------------------------------------------------------------------*
start-of-selection.
*To check authorization of the user for the related TCode
authority-check object 'S_TCODE'
id 'TCD' field gc_bdc_tcode.
if sy-subrc <> 0.
message text-e01 type 'E'.
return.
endif.
clear gwa_option.
case 'X'.
when rb_backg.
gwa_option-dismode = 'N'. "No Display
when rb_foreg.
gwa_option-dismode = 'A'. "All Display
when rb_errrg.
gwa_option-dismode = 'E'. "Display on Error
endcase.
*-- UPDMODE = S -> Synchronous Update
*-- UPDMODE = A -> Asynchronous Update
*-- UPDMODE = L -> Local File
gwa_option-updmode = 'S'.
gwa_option-racommit = 'X'.
gwa_option-nobiend = 'X'.
*--If the recording is using No Batch Input option, make sure you have
*--GWA_OPTION-nobinpt = 'X' as written below
gwa_option-nobinpt = 'X'.
if rb_sessm = 'X' and p_sesnm is initial.
message text-c03 type 'I'.
else.
if rb_lfile is not initial.
call function 'GUI_UPLOAD'
exporting
filename = p_fname
filetype = 'DAT'
tables
data_tab = gt_string
exceptions
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
others = 17.
if sy-subrc <> 0.
message i001(z02).
else.
*changed by jitang 21,07,2008.
* after you get the data from local file, you need to read the into the internal table.
refresh gt_record.
loop at gt_string into g_record.
* create a subroutine F_SPLIT_STRIN to split the data.
perform f_split_string.
endloop.
*end of changed by jitang 21,07,2008.
endif.
else.
if rb_rfile = 'X'.
perform open_dataset using p_dtset.
do.
clear g_record.
read dataset p_dtset into g_record.
if sy-subrc ne 0.
exit.
else.
perform f_split_string.
endif.
enddo.
perform close_dataset using p_dtset.
endif.
endif.
if rb_sessm = 'X'.
perform open_group.
endif.
*--Begin Of GT_RECORD loop
loop at gt_record into gwa_record.
g_bdctabix = sy-tabix.
refresh gt_bdcdata.
*V====================================================================V
if rb_sessm = 'X'.
perform bdc_dynpro using 'SAPMP50A' '1000'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RP50G-PERNR'
gwa_record-pernr_001.
perform bdc_field using 'RP50G-TIMR6'
gc_yes.
perform bdc_field using 'BDC_CURSOR'
'RP50G-CHOIC'.
perform bdc_field using 'RP50G-CHOIC'
gc_itype_num.
perform bdc_dynpro using 'SAPMP50A' '1000'.
perform bdc_field using 'BDC_CURSOR'
'RP50G-PERNR'.
perform bdc_field using 'BDC_OKCODE'
'=INS'.
perform bdc_field using 'RP50G-CHOIC'
'Company Instructions'.
else.
perform bdc_dynpro using 'SAPMP50A' '1100'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RP50G-PERNR'
gwa_record-pernr_001.
perform bdc_field using 'RP50G-TIMR6'
gc_yes.
perform bdc_field using 'BDC_CURSOR'
'RP50G-CHOIC'.
perform bdc_field using 'RP50G-CHOIC'
gc_itype_num.
perform bdc_dynpro using 'SAPMP50A' '1100'.
perform bdc_field using 'BDC_CURSOR'
'RP50G-PERNR'.
perform bdc_field using 'BDC_OKCODE'
'=INS'.
perform bdc_field using 'RP50G-CHOIC'
'Company Instructions'.
endif.
perform bdc_dynpro using 'MP003500' '2000'.
perform bdc_field using 'BDC_CURSOR'
'RP50M-TEXT3'.
perform bdc_field using 'BDC_OKCODE'
'=UPD'.
perform bdc_field using 'P0035-BEGDA'
gwa_record-begda_002.
perform bdc_field using 'P0035-ENDDA'
gwa_record-endda_003.
perform bdc_field using 'P0035-BLEHR'
gwa_record-blehr_004.
perform bdc_field using 'P0035-DAT35'
gwa_record-dat35_005.
perform bdc_field using 'RP50M-TEXT1'
gwa_record-text1_006.
perform bdc_field using 'RP50M-TEXT2'
gwa_record-text2_007.
perform bdc_field using 'RP50M-TEXT3'
gwa_record-text3_008.
if rb_sessm = 'X'.
perform bdc_dynpro using 'SAPMP50A' '1000'.
else.
perform bdc_dynpro using 'SAPMP50A' '1100'.
endif.
perform bdc_field using 'BDC_OKCODE'
'/EEND'.
perform bdc_field using 'BDC_CURSOR'
'RP50G-PERNR'.
*^====================================================================^
perform bdc_transaction using gc_bdc_tcode.
*----------------------------------------------------------------------*
* MESSAGE PROCESSING *
* 错误处理 *
*----------------------------------------------------------------------*
*--Is program run under Call Transaction Mode
if rb_tranm = 'X'.
clear gwa_print.
gwa_print-recno = g_bdctabix.
*--Find the succcess message
clear gwa_messtab.
read table gt_messtab into gwa_messtab
with key msgid = gc_bdc_ok_id
msgnr = gc_bdc_ok_nr.
if sy-subrc eq 0.
gwa_print-eflag = icon_green_light.
else.
gwa_print-eflag = icon_red_light.
endif.
if gwa_print-eflag = icon_green_light.
gwa_print-messg = text-c04.
else.
*--Loop at error messages
loop at gt_messtab into gwa_messtab where msgtyp = 'E'.
g_msgno = gwa_messtab-msgnr.
call function 'WRITE_MESSAGE'
exporting
msgid = gwa_messtab-msgid
msgno = g_msgno
msgty = gwa_messtab-msgtyp
msgv1 = gwa_messtab-msgv1
msgv2 = gwa_messtab-msgv2
msgv3 = gwa_messtab-msgv3
msgv4 = gwa_messtab-msgv4
importing
messg = gwa_message.
if gwa_print-messg is initial.
gwa_print-messg = gwa_message-msgtx.
else.
concatenate gwa_print-messg gwa_message-msgtx
into gwa_print-messg separated by ';'.
endif.
clear gwa_messtab.
endloop.
endif.
*--Add log to table to be displayed on ALV
append gwa_print to gt_print.
endif.
endloop.
*--End Of GT_RECORD loop
*----------------------------------------------------------------------*
* ALV REPORTING SEGMENT *
*----------------------------------------------------------------------*
if rb_tranm = 'X'.
describe table gt_print lines g_data_count.
if g_data_count > gc_zero.
perform f_layout_init using gt_layout.
perform f_eventtab_build using gt_events[].
gt_variant-report = sy-repid.
perform f_print_control.
perform f_build_header_list.
perform f_build_fieldcat.
perform print_alv.
perform top_of_page.
else.
message i000(z02).
endif.
endif.
if rb_sessm = 'X'.
perform close_group.
endif.
endif.
*----------------------------------------------------------------------*
* M O D U L E S *
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* FORM open_dataset : open dataset *
*----------------------------------------------------------------------*
form open_dataset using p_dataset type filenameci-fileintern.
open dataset p_dataset for input in text mode encoding default.
if sy-subrc <> gc_zero.
message text-e00 type 'E'.
endif.
endform. "OPEN_DATASET
*----------------------------------------------------------------------*
* FORM close_dataset : close dataset *
*----------------------------------------------------------------------*
form close_dataset using p_dataset type filenameci-fileintern.
close dataset p_dataset.
if sy-subrc <> gc_zero.
message text-e02 type 'E'.
endif.
endform. "CLOSE_DATASET
*----------------------------------------------------------------------*
* FORM open_group : create batchinput session *
* (not for call transaction using...) *
*----------------------------------------------------------------------*
form open_group.
skip.
write: /(20) text-i01, p_sesnm.
skip.
* open batchinput group
call function 'BDC_OPEN_GROUP'
exporting
client = sy-mandt
group = p_sesnm
user = sy-uname
keep = g_keep
holddate = g_holddate.
**Replaces the SY-SUBRC check
write: /(30) 'BDC_OPEN_GROUP', (12) 'returncode:', sy-subrc.
endform. "OPEN_GROUP
*----------------------------------------------------------------------*
* FORM close_group : end batchinput session *
* (call transaction using...: error session) *
*----------------------------------------------------------------------*
form close_group.
* close batchinput group
call function 'BDC_CLOSE_GROUP'.
write: /(30) 'BDC_CLOSE_GROUP', (12) text-t04, sy-subrc.
endform. "CLOSE_GROUP
*-----------------------------------------------------------------------*
* FORM bdc_transaction : Start new transaction according to parameters*
*-----------------------------------------------------------------------*
form bdc_transaction using tcode type sy-tcode.
if rb_sessm = 'X'.
call function 'BDC_INSERT'
exporting
tcode = tcode
ctuparams = gwa_option
tables
dynprotab = gt_bdcdata.
write: / 'BDC_INSERT', tcode,
text-t04, sy-subrc,
'RECORD:', sy-index.
elseif rb_tranm = gc_yes.
refresh gt_messtab[].
call transaction tcode
using gt_bdcdata
messages into gt_messtab
options from gwa_option.
endif.
endform. "BDC_TRANSACTION
*----------------------------------------------------------------------*
* FORM bdc_dynpro : Start new screen *
*----------------------------------------------------------------------*
form bdc_dynpro using program type bdc_prog
dynpro type bdc_dynr.
clear gwa_bdcdata.
gwa_bdcdata-program = program.
gwa_bdcdata-dynpro = dynpro.
gwa_bdcdata-dynbegin = gc_yes.
append gwa_bdcdata to gt_bdcdata.
endform. "BDC_DYNPRO
*----------------------------------------------------------------------*
* FORM bdc_field : Insert field *
*----------------------------------------------------------------------*
form bdc_field using fnam type fnam_____4
fval type any.
if fval <> g_nodata.
clear gwa_bdcdata.
gwa_bdcdata-fnam = fnam.
gwa_bdcdata-fval = fval.
append gwa_bdcdata to gt_bdcdata.
endif.
endform. "BDC_FIELD
*&--------------------------------------------------------------------*
*&Form f_layout_init : Global settings for ALV worksheet *
*&--------------------------------------------------------------------*
form f_layout_init using p_layout type slis_layout_alv.
p_layout-detail_popup = gc_yes.
p_layout-numc_sum = gc_yes.
p_layout-colwidth_optimize = gc_no.
p_layout-zebra = gc_yes.
p_layout-get_selinfos = gc_yes.
endform. " f_layout_init
*&--------------------------------------------------------------------*
*&Form f_eventtab_build : Event listing for ALV worksheet *
*&--------------------------------------------------------------------*
form f_eventtab_build using gt_events type slis_t_event.
data:
wa_event type slis_alv_event.
call function 'REUSE_ALV_EVENTS_GET'
exporting
i_list_type = 0
importing
et_events = gt_events.
read table gt_events with key name = slis_ev_top_of_page into wa_event.
if sy-subrc = 0.
move slis_ev_top_of_page to: wa_event-form, wa_event-name.
append wa_event to gt_events.
endif.
endform. " f_eventtab_build
*&--------------------------------------------------------------------*
*&Form f_print_control : Global settings for print control *
*&--------------------------------------------------------------------*
form f_print_control.
gwa_print_ctrl-no_print_selinfos = gc_yes.
gwa_print_ctrl-no_print_listinfos = gc_yes.
gwa_print_ctrl-reserve_lines = gc_zero.
gwa_print_ctrl-no_change_print_params = gc_yes.
endform. " f_print_control
*&--------------------------------------------------------------------*
*&Form f_build_header_list : To write down the title on ALV header *
*&--------------------------------------------------------------------*
form f_build_header_list.
data: wa_list_top type slis_listheader.
refresh gt_list_top.
clear wa_list_top.
wa_list_top-typ = 'H'.
wa_list_top-key = gc_no.
wa_list_top-info = sy-title.
append wa_list_top to gt_list_top.
endform. " f_build_header_list
*&--------------------------------------------------------------------*
*&Form f_build_fieldcat : Define The Fields on ALV *
*&--------------------------------------------------------------------*
form f_build_fieldcat.
refresh gt_fieldcat.
clear gwa_fieldcat.
gwa_fieldcat-fieldname = text-f01.
gwa_fieldcat-tabname =
gwa_fieldcat-ctabname =
gwa_fieldcat-qtabname = 'IT_PRINT'.
gwa_fieldcat-just = 'L'.
gwa_fieldcat-seltext_s = text-h01.
gwa_fieldcat-ddictxt = 'S'.
append gwa_fieldcat to gt_fieldcat.
clear gwa_fieldcat.
gwa_fieldcat-fieldname = text-f02.
gwa_fieldcat-tabname =
gwa_fieldcat-ctabname =
gwa_fieldcat-qtabname = 'IT_PRINT'.
gwa_fieldcat-just = 'L'.
gwa_fieldcat-seltext_s = text-h02.
gwa_fieldcat-ddictxt = 'S'.
append gwa_fieldcat to gt_fieldcat.
clear gwa_fieldcat.
gwa_fieldcat-fieldname = text-f03.
gwa_fieldcat-tabname =
gwa_fieldcat-ctabname =
gwa_fieldcat-qtabname = 'IT_PRINT'.
gwa_fieldcat-just = 'L'.
gwa_fieldcat-seltext_s = text-h03.
gwa_fieldcat-ddictxt = 'S'.
gwa_fieldcat-outputlen = 200.
append gwa_fieldcat to gt_fieldcat.
endform. "f_build_field_cat
*&--------------------------------------------------------------------*
*&Form print_alv : Show the ALV
*&--------------------------------------------------------------------*
form print_alv.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = gwa_gs_extract1-report
is_layout = gt_layout
it_fieldcat = gt_fieldcat
i_save = gc_save
is_variant = gt_variant
it_events = gt_events[]
is_print = gwa_print_ctrl
tables
t_outtab = gt_print
exceptions
program_error = 1
others = 2.
if sy-subrc <> gc_zero.
message id sy-msgid type sy-msgty number sy-msgno
with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
endif.
endform. "
*&---------------------------------------------------------------------*
*&Form TOP_OF_PAGE : Dynamic form on TOP_OF_PAGE Event
*&---------------------------------------------------------------------*
form top_of_page. "#EC CALLED
call function 'REUSE_ALV_COMMENTARY_WRITE'
exporting
i_logo = 'ENJOYSAP_LOGO'
it_list_commentary = gt_list_top.
endform. "TOP_OF_PAGE
*&---------------------------------------------------------------------*
*& Form f_split_String
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
form f_split_string.
clear gwa_record.
split g_record at gc_delimiter into
*V====================================================================V
gwa_record-pernr_001
gwa_record-begda_002
gwa_record-endda_003
gwa_record-blehr_004
gwa_record-dat35_005
gwa_record-text1_006
gwa_record-text2_007
gwa_record-text3_008.
*^====================================================================^
append gwa_record to gt_record.
endform. "f_split_String
阅读(1087) | 评论(0) | 转发(0) |