*&---------------------------------------------------------------------*
*& Report Z_BDC_F02
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_BDC_F02.
types:
begin of ty_tab,
document_date type BLDAT,
header type BKTXT,
account1 type NEWKO,
amount type char10,
pstky type NEWBS,
account2 type NEWKO,
end of ty_tab.
data:
it_tab type standard table of ty_tab,
wa_tab type ty_tab,
it_bdc like bdcdata occurs 0 with header line.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: in_file LIKE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.
at selection-screen on value-request for in_file.
perform get_filename.
start-of-selection.
perform upload_data.
perform batch_data.
*&---------------------------------------------------------------------*
*& Form UPLOAD_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form UPLOAD_DATA .
field-symbols:<fs>.
data:
l_ans(1) type c,
it_exc type alsmex_tabline occurs 0 with header line.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = in_file
i_begin_col = 1
i_begin_row = 1
i_end_col = 50
i_end_row = 5000
tables
intern = it_exc
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
else.
IF it_exc[] is initial.
CALL FUNCTION 'POPUP_TO_CONFIRM_WITH_MESSAGE'
EXPORTING
* DEFAULTOPTION = 'Y'
diagnosetext1 = 'No data in excel'
* DIAGNOSETEXT2 = ' '
* DIAGNOSETEXT3 = ' '
textline1 = 'Please check data in excel'
* TEXTLINE2 = ' '
titel = 'Confirm'
* START_COLUMN = 25
* START_ROW = 6
* CANCEL_DISPLAY = 'X'
IMPORTING
ANSWER = l_ans
.
else.
sort it_exc by row col value.
LOOP AT it_exc.
assign component it_exc-col of structure wa_tab to <fs>.
move it_exc-value to <fs>.
at end of row.
append wa_tab to it_tab.
clear wa_tab.
endat.
ENDLOOP.
ENDIF.
ENDIF.
endform. " UPLOAD_DATA
*&---------------------------------------------------------------------*
*& Form GET_FILENAME
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form GET_FILENAME .
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
* DEF_FILENAME = ' '
* DEF_PATH = ' '
MASK = ',Excel Files,*.xls*.'
MODE = 'O'
TITLE = '选择文件'
IMPORTING
FILENAME = in_file
* RC =
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 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.
endform. " GET_FILENAME
*&---------------------------------------------------------------------*
*& Form BATCH_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form BATCH_DATA .
LOOP AT it_tab into wa_tab.
refresh it_bdc.
perform bdc_dynpro using 'SAPMF05A' '0100'.
perform bdc_field using 'BDC_CURSOR'
'RF05A-NEWKO'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BKPF-BLDAT'
wa_tab-document_date.
perform bdc_field using 'BKPF-BLART'
'SA'.
perform bdc_field using 'BKPF-BUKRS'
'1000'.
perform bdc_field using 'BKPF-BUDAT'
sy-datum.
perform bdc_field using 'BKPF-MONAT'
sy-datum+4(2).
perform bdc_field using 'BKPF-WAERS'
'EUR'.
perform bdc_field using 'BKPF-BKTXT'
wa_tab-header.
perform bdc_field using 'RF05A-NEWBS'
'40'.
perform bdc_field using 'RF05A-NEWKO'
wa_tab-account1.
perform bdc_dynpro using 'SAPMF05A' '0300'.
perform bdc_field using 'BDC_CURSOR'
'RF05A-NEWKO'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BSEG-WRBTR'
wa_tab-amount.
perform bdc_field using 'BSEG-VALUT'
sy-datum.
perform bdc_field using 'BSEG-SGTXT'
wa_tab-header.
perform bdc_field using 'RF05A-NEWBS'
wa_tab-pstky.
perform bdc_field using 'RF05A-NEWKO'
wa_tab-account2.
perform bdc_dynpro using 'SAPMF05A' '0300'.
perform bdc_field using 'BDC_CURSOR'
'BSEG-WRBTR'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'BSEG-WRBTR'
wa_tab-amount.
perform bdc_field using 'BSEG-VALUT'
sy-datum.
call transaction 'F-02' using it_bdc
mode 'A'
update 'S'.
ENDLOOP.
endform. " BATCH_DATA
*&---------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0277 text
* -->P_0278 text
*----------------------------------------------------------------------*
form BDC_DYNPRO using program dynpro.
clear it_bdc.
it_bdc-PROGRAM = program.
it_bdc-DYNPRO = dynpro.
it_bdc-DYNBEGIN = 'X'.
append it_bdc.
endform. " BDC_DYNPRO
*&---------------------------------------------------------------------*
*& Form BDC_FIELD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0282 text
* -->P_0283 text
*----------------------------------------------------------------------*
form BDC_FIELD using fnam fval.
IF fval <> ' '.
clear it_bdc.
it_bdc-fnam = fnam.
it_bdc-fval = fval.
append it_bdc.
ENDIF.
endform. " BDC_FIELD
*& Report Z_BDC_F02
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_BDC_F02.
types:
begin of ty_tab,
document_date type BLDAT,
header type BKTXT,
account1 type NEWKO,
amount type char10,
pstky type NEWBS,
account2 type NEWKO,
end of ty_tab.
data:
it_tab type standard table of ty_tab,
wa_tab type ty_tab,
it_bdc like bdcdata occurs 0 with header line.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: in_file LIKE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.
at selection-screen on value-request for in_file.
perform get_filename.
start-of-selection.
perform upload_data.
perform batch_data.
*&---------------------------------------------------------------------*
*& Form UPLOAD_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form UPLOAD_DATA .
field-symbols:<fs>.
data:
l_ans(1) type c,
it_exc type alsmex_tabline occurs 0 with header line.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = in_file
i_begin_col = 1
i_begin_row = 1
i_end_col = 50
i_end_row = 5000
tables
intern = it_exc
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
else.
IF it_exc[] is initial.
CALL FUNCTION 'POPUP_TO_CONFIRM_WITH_MESSAGE'
EXPORTING
* DEFAULTOPTION = 'Y'
diagnosetext1 = 'No data in excel'
* DIAGNOSETEXT2 = ' '
* DIAGNOSETEXT3 = ' '
textline1 = 'Please check data in excel'
* TEXTLINE2 = ' '
titel = 'Confirm'
* START_COLUMN = 25
* START_ROW = 6
* CANCEL_DISPLAY = 'X'
IMPORTING
ANSWER = l_ans
.
else.
sort it_exc by row col value.
LOOP AT it_exc.
assign component it_exc-col of structure wa_tab to <fs>.
move it_exc-value to <fs>.
at end of row.
append wa_tab to it_tab.
clear wa_tab.
endat.
ENDLOOP.
ENDIF.
ENDIF.
endform. " UPLOAD_DATA
*&---------------------------------------------------------------------*
*& Form GET_FILENAME
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form GET_FILENAME .
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
* DEF_FILENAME = ' '
* DEF_PATH = ' '
MASK = ',Excel Files,*.xls*.'
MODE = 'O'
TITLE = '选择文件'
IMPORTING
FILENAME = in_file
* RC =
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 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.
endform. " GET_FILENAME
*&---------------------------------------------------------------------*
*& Form BATCH_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form BATCH_DATA .
LOOP AT it_tab into wa_tab.
refresh it_bdc.
perform bdc_dynpro using 'SAPMF05A' '0100'.
perform bdc_field using 'BDC_CURSOR'
'RF05A-NEWKO'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BKPF-BLDAT'
wa_tab-document_date.
perform bdc_field using 'BKPF-BLART'
'SA'.
perform bdc_field using 'BKPF-BUKRS'
'1000'.
perform bdc_field using 'BKPF-BUDAT'
sy-datum.
perform bdc_field using 'BKPF-MONAT'
sy-datum+4(2).
perform bdc_field using 'BKPF-WAERS'
'EUR'.
perform bdc_field using 'BKPF-BKTXT'
wa_tab-header.
perform bdc_field using 'RF05A-NEWBS'
'40'.
perform bdc_field using 'RF05A-NEWKO'
wa_tab-account1.
perform bdc_dynpro using 'SAPMF05A' '0300'.
perform bdc_field using 'BDC_CURSOR'
'RF05A-NEWKO'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BSEG-WRBTR'
wa_tab-amount.
perform bdc_field using 'BSEG-VALUT'
sy-datum.
perform bdc_field using 'BSEG-SGTXT'
wa_tab-header.
perform bdc_field using 'RF05A-NEWBS'
wa_tab-pstky.
perform bdc_field using 'RF05A-NEWKO'
wa_tab-account2.
perform bdc_dynpro using 'SAPMF05A' '0300'.
perform bdc_field using 'BDC_CURSOR'
'BSEG-WRBTR'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'BSEG-WRBTR'
wa_tab-amount.
perform bdc_field using 'BSEG-VALUT'
sy-datum.
call transaction 'F-02' using it_bdc
mode 'A'
update 'S'.
ENDLOOP.
endform. " BATCH_DATA
*&---------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0277 text
* -->P_0278 text
*----------------------------------------------------------------------*
form BDC_DYNPRO using program dynpro.
clear it_bdc.
it_bdc-PROGRAM = program.
it_bdc-DYNPRO = dynpro.
it_bdc-DYNBEGIN = 'X'.
append it_bdc.
endform. " BDC_DYNPRO
*&---------------------------------------------------------------------*
*& Form BDC_FIELD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0282 text
* -->P_0283 text
*----------------------------------------------------------------------*
form BDC_FIELD using fnam fval.
IF fval <> ' '.
clear it_bdc.
it_bdc-fnam = fnam.
it_bdc-fval = fval.
append it_bdc.
ENDIF.
endform. " BDC_FIELD