*&---------------------------------------------------------------------*
*&程序名称 :ZFI134
*&程序描述 : 9003差异科目结转 (批量操作 F.02 / 查询 FB03)
*&申请单位 :
*&申请人 :
*&申请日期 :2024年04月09日
*&作者 :
*&---------------------------------------------------------------------*
REPORT zfi134.
TABLES: faglflext,sscrfields, acdoca.
CONSTANTS: gc_icon_green TYPE icon-id VALUE '@08@',
gc_icon_red TYPE icon-id VALUE '@0A@'.
CONSTANTS: gc_saknr2221010600 TYPE saknr VALUE '2221010600',
gc_saknr2221010500 TYPE saknr VALUE '2221010500',
gc_saknr2221020100 TYPE saknr VALUE '2221020100',
gc_saknr2221000000 TYPE saknr VALUE '2221000000'.
*&---------------------------------------------------------------------*
*& 数据类型
*&---------------------------------------------------------------------*
TYPES: BEGIN OF s_head,
bukrs TYPE bkpf-bukrs,
belnr TYPE bkpf-belnr,
gjahr TYPE bkpf-gjahr,
blart TYPE bkpf-blart,
bldat TYPE bkpf-bldat,
budat TYPE bkpf-budat,
monat TYPE bkpf-monat,
waers TYPE bkpf-waers,
END OF s_head.
TYPES: t_head TYPE TABLE OF s_head.
TYPES: BEGIN OF s_item,
sel TYPE char1,
belnr TYPE acdoca-belnr, "分录
docln TYPE numc06, "凭证行
saknr TYPE ska1-saknr,
txt50 TYPE skat-txt50,
bschl TYPE acdoca-bschl,
hsl TYPE acdoca-hsl,
rhcur TYPE acdoca-rhcur,
drcrk TYPE acdoca-drcrk,
bukrs TYPE acdoca-rbukrs,
gjahr TYPE acdoca-gjahr,
monat TYPE bkpf-monat,
blart TYPE bkpf-blart,
sgtxt TYPE bseg-sgtxt, "文本
fkber TYPE bseg-fkber, "功能范围
kostl TYPE bseg-kostl, "成本中心
gsber TYPE bseg-gsber, "业务范围
prctr TYPE bseg-prctr, "利润中心
werks TYPE bseg-werks, "工厂
type TYPE bapiret2-type,
message TYPE bapiret2-message,
icon TYPE icon-id,
END OF s_item.
TYPES: t_item TYPE TABLE OF s_item.
*&---------------------------------------------------------------------*
*& 结构
*&---------------------------------------------------------------------*
DATA: BEGIN OF gs_hide_code,
code TYPE sy-ucomm,
END OF gs_hide_code.
*&---------------------------------------------------------------------*
*& 内表
*&---------------------------------------------------------------------*
DATA: gt_head TYPE t_head,
gt_item TYPE t_item,
gt_hide_code LIKE TABLE OF gs_hide_code.
*&---------------------------------------------------------------------*
*& 对象
*&---------------------------------------------------------------------*
CLASS lcl_alv_event_0100 DEFINITION DEFERRED.
DATA: go_dock_100 TYPE REF TO cl_gui_docking_container,
go_dock_200 TYPE REF TO cl_gui_docking_container,
go_grid_100 TYPE REF TO cl_gui_alv_grid,
go_grid_200 TYPE REF TO cl_gui_alv_grid,
go_alv_event_100 TYPE REF TO lcl_alv_event_0100. "类接收器
*&---------------------------------------------------------------------*
*& 变量
*&---------------------------------------------------------------------*
DATA: ok_code TYPE sy-ucomm,
gv_code TYPE sy-ucomm,
gv_title TYPE repti,
gv_lines TYPE i,
gv_saknr TYPE ska1-saknr,
gv_bukrs TYPE bkpf-bukrs,
gv_post TYPE char1.
DATA:gt_output0 TYPE TABLE OF zsf_zfi040a.
DATA:gt_output TYPE TABLE OF zsf_zfi040a.
DATA:gs_output TYPE zsf_zfi040a.
DATA:itab TYPE TABLE OF zsfi009.
TYPES: BEGIN OF ty_data,
sel TYPE char1,
belnr1 TYPE acdoca-belnr, "分录
ryear TYPE zsf_zfi040a-ryear,
rpmax TYPE zsf_zfi040a-rpmax,
bukrs TYPE acdoca-rbukrs,
butxt TYPE t001-butxt,
racct TYPE zsf_zfi040a-racct, "科目
txt50 TYPE zsf_zfi040a-txt50,
rcntr TYPE zsf_zfi040a-rcntr, "成本中心
ktext TYPE zsf_zfi040a-ktext,
rbusa TYPE zsf_zfi040a-rbusa, "业务范围
gtext TYPE zsf_zfi040a-gtext,
werks TYPE werks_d,
rfarea TYPE zsf_zfi040a-rfarea, "功能范围
fkbtx TYPE zsf_zfi040a-fkbtx,
prctr TYPE zsf_zfi040a-prctr, "利润中心
rtcur TYPE zsf_zfi040a-rtcur,
hsly1 TYPE zsf_zfi040a-hsly1, "本年累计借方(本币)
hsly2 TYPE zsf_zfi040a-hsly2, "本年累计贷方(本币)
hslz1 TYPE zsf_zfi040a-hslz1, "调整金额(本币)
bhsly1 TYPE zsf_zfi040a-hsly1, "本年累计借方(本币)
bhsly2 TYPE zsf_zfi040a-hsly2, "本年累计贷方(本币)
bhslz1 TYPE zsf_zfi040a-hslz1, "调整金额(本币)
belnr TYPE acdoca-belnr, "会计凭证
saknr TYPE ska1-saknr,
txt50s TYPE skat-txt50,
type TYPE bapiret2-type,
message TYPE bapiret2-message,
icon TYPE icon-id,
flag TYPE char1,
END OF ty_data,
BEGIN OF ty_bseg,
bukrs TYPE bseg-bukrs, "公司
belnr TYPE bseg-belnr,
gjahr TYPE bseg-gjahr,
buzei TYPE bseg-buzei,
shkzg TYPE bseg-shkzg,
gsber TYPE bseg-gsber, "业务范围
dmbtr TYPE bseg-dmbtr,
vbund TYPE bseg-vbund, "贸易伙伴的公司标识
hkont TYPE bseg-hkont, "科目
werks TYPE bseg-werks,
prctr TYPE bseg-prctr, "利润中心
monat TYPE bseg-h_monat, "期间
kostl TYPE bseg-kostl, "成本中心
fkber TYPE fkber_long, "功能范围
hsly1 TYPE zsf_zfi040a-hsly1, "本年累计借方(本币)
hsly2 TYPE zsf_zfi040a-hsly2, "本年累计贷方(本币)
hslz1 TYPE zsf_zfi040a-hslz1, "调整金额(本币)
END OF ty_bseg .
DATA: lt_data TYPE TABLE OF ty_data,
ls_data TYPE ty_data,
lt_bseg TYPE TABLE OF ty_bseg,
lt_bseg1 TYPE TABLE OF ty_bseg,
lt_bseg2 TYPE TABLE OF ty_bseg,
ls_bseg TYPE ty_bseg,
* LS_DATA1 TYPE TY_DATA,
lv_waers TYPE bkpf-waers,
num TYPE i..
*&---------------------------------------------------------------------*
*& 选择屏幕
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK bl01 WITH FRAME TITLE TEXT-t01.
SELECT-OPTIONS: s_bukrs FOR acdoca-rbukrs NO-EXTENSION NO INTERVALS,
s_gjahr FOR acdoca-gjahr NO-EXTENSION NO INTERVALS
DEFAULT sy-datum(4),
s_poper FOR acdoca-poper NO-EXTENSION NO INTERVALS
DEFAULT sy-datum+4(2).
SELECT-OPTIONS: "S_POPER FOR VBRK-POPER OBLIGATORY,
s_racct FOR faglflext-racct ."NO-DISPLAY. " 5 与 8 开头的 总帐科目
SELECTION-SCREEN END OF BLOCK bl01.
SELECTION-SCREEN FUNCTION KEY 1.
DATA: restrict TYPE sscr_restrict,
optlist TYPE sscr_opt_list,
ass TYPE sscr_ass.
INITIALIZATION.
optlist-name = 'OBJECTKEY1'.
optlist-options-eq = 'X'.
optlist-options-bt = ''.
APPEND optlist TO restrict-opt_list_tab.
ass-kind = 'S'.
ass-name = 'S_GJAHR'.
ass-sg_main = 'I'.
ass-sg_addy = space.
ass-op_main = 'OBJECTKEY1'.
APPEND ass TO restrict-ass_tab.
CLEAR optlist.
CLEAR ass.
optlist-name = 'OBJECTKEY2'.
optlist-options-cp = 'X'.
optlist-options-ge = 'X'.
optlist-options-lt = 'X'.
optlist-options-ne = 'X'.
optlist-options-eq = 'X'.
optlist-options-bt = 'X'.
APPEND optlist TO restrict-opt_list_tab.
ass-kind = 'S'.
ass-name = 'S_POPER'.
ass-sg_main = 'I'.
ass-sg_addy = space.
ass-op_main = 'OBJECTKEY2'.
APPEND ass TO restrict-ass_tab.
CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'
EXPORTING
restriction = restrict
EXCEPTIONS
too_late = 1
repeated = 2
selopt_without_options = 3
selopt_without_signs = 4
invalid_sign = 5
empty_option_list = 6
invalid_kind = 7
repeated_kind_a = 8
OTHERS = 9.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
PERFORM set_button_text.
AT SELECTION-SCREEN OUTPUT.
PERFORM init_screen_1000.
AT SELECTION-SCREEN.
PERFORM ucomm_screen_1000.
START-OF-SELECTION.
PERFORM program_main.
*----------------------------------------------------------------------*
* CLASS LCL_ALV_EVENT_0100 DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_alv_event_0100 DEFINITION.
PUBLIC SECTION.
" Toolbar事件
METHODS handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object e_interactive.
" USER-COMMAND 事件
METHODS handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
" 双击事件
METHODS header_double_click FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row e_column.
ENDCLASS. "LCL_ALV_EVENT_0100 DEFINITION
*----------------------------------------------------------------------*
* CLASS LCL_ALV_EVENT_0100 IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_alv_event_0100 IMPLEMENTATION.
" Toolbar事件
METHOD handle_toolbar.
PERFORM alv_toolbar CHANGING e_object->mt_toolbar.
ENDMETHOD. "handle_toolbar
" USER_COMMAND 事件
METHOD handle_user_command.
PERFORM alv_user_command USING e_ucomm.
ENDMETHOD. "HANDLE_USER_COMMAND
" 双击事件
METHOD header_double_click.
PERFORM frm_double_click USING e_row e_column.
ENDMETHOD.
ENDCLASS. "LCL_ALV_EVENT_0100 IMPLEMENTATION
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
gv_title = TEXT-t02.
CLEAR gt_hide_code[].
gs_hide_code-code = '&ZAFFIRM'.
APPEND gs_hide_code TO gt_hide_code.
gs_hide_code-code = '&ZCANCEL'.
APPEND gs_hide_code TO gt_hide_code.
SET PF-STATUS 'STATUS_BAR' EXCLUDING gt_hide_code.
SET TITLEBAR 'TITLE_BAR' WITH gv_title gv_lines.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module STATUS_0200 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE status_0200 OUTPUT.
gv_title = TEXT-t04.
CLEAR gt_hide_code[].
IF gv_post IS INITIAL.
gs_hide_code-code = '&ZAFFIRM'.
APPEND gs_hide_code TO gt_hide_code.
ENDIF.
SET PF-STATUS 'STATUS_BAR' EXCLUDING gt_hide_code.
SET TITLEBAR 'TITLE_BAR' WITH gv_title ''.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module INIT_SCREEN_0100 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE init_screen_0100 OUTPUT.
PERFORM init_alv_100.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module INIT_SCREEN_0200 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE init_screen_0200 OUTPUT.
PERFORM init_alv_200.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
gv_code = ok_code.
CLEAR ok_code.
CASE gv_code.
WHEN '&BACK'.
LEAVE TO SCREEN 0.
WHEN OTHERS.
ENDCASE.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0200 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0200 INPUT.
gv_code = ok_code.
CLEAR ok_code.
CASE gv_code.
WHEN '&BACK'.
LEAVE TO SCREEN 0.
WHEN '&ZAFFIRM'.
PERFORM call_bapi_import USING gv_post.
LEAVE TO SCREEN 0.
WHEN '&ZCANCEL'.
LEAVE TO SCREEN 0.
WHEN OTHERS.
ENDCASE.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Form PROGRAM_MAIN
*&---------------------------------------------------------------------*
* text 程序入口
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM program_main.
DATA: lv_subrc TYPE sy-subrc.
PERFORM check_screen_1000.
PERFORM get_data_head CHANGING gt_head.
PERFORM frm_getdata . "获得数据
IF lt_data[] IS INITIAL.
MESSAGE TEXT-m01 TYPE 'S' DISPLAY LIKE 'E'. " 无符合条件的数据!
EXIT.
ENDIF.
PERFORM check_data CHANGING lv_subrc.
DESCRIBE TABLE lt_data LINES gv_lines. " 统计内表行数
CALL SCREEN 100.
ENDFORM. " PROGRAM_MAIN
*&---------------------------------------------------------------------*
*& Form SET_BUTTON_TEXT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM set_button_text .
DATA: ls_smp_dyntxt TYPE smp_dyntxt.
ls_smp_dyntxt-icon_id = '@U3@'.
ls_smp_dyntxt-icon_text = TEXT-t03. " 科目维护
ls_smp_dyntxt-quickinfo = TEXT-t03. " 科目维护
sscrfields-functxt_01 = ls_smp_dyntxt.
ENDFORM. "SET_BUTTON_TEXT
*&---------------------------------------------------------------------*
*& Form INIT_SCREEN_1000
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM init_screen_1000 .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form UCOMM_SCREEN_1000
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM ucomm_screen_1000 .
CASE sscrfields-ucomm.
WHEN 'FC01'.
PERFORM call_view_edit.
WHEN OTHERS.
ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form CALL_VIEW_EDIT
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM call_view_edit .
CALL FUNCTION 'VIEW_MAINTENANCE_CALL'
EXPORTING
action = 'S'
view_name = 'ZTFI113'
EXCEPTIONS
client_reference = 1
foreign_lock = 2
invalid_action = 3
no_clientindependent_auth = 4
no_database_function = 5
no_editor_function = 6
no_show_auth = 7
no_tvdir_entry = 8
no_upd_auth = 9
only_show_allowed = 10
system_failure = 11
unknown_field_in_dba_sellist = 12
view_not_found = 13
maintenance_prohibited = 14
OTHERS = 15.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form CHECK_SCREEN_1000
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM check_screen_1000 .
DATA: lv_message TYPE bapiret2-message.
DATA: str1 TYPE char6,
str2 TYPE char6.
IF s_bukrs[] IS INITIAL.
" 请输入公司代码!
MESSAGE TEXT-m03 TYPE 'S' DISPLAY LIKE 'E'.
LEAVE LIST-PROCESSING.
ENDIF.
IF s_gjahr[] IS INITIAL.
" 请输入年度!
MESSAGE TEXT-m04 TYPE 'S' DISPLAY LIKE 'E'.
LEAVE LIST-PROCESSING.
ENDIF.
IF s_poper[] IS INITIAL.
" 请输入期间!
MESSAGE TEXT-m05 TYPE 'S' DISPLAY LIKE 'E'.
LEAVE LIST-PROCESSING.
ENDIF.
str1 = s_gjahr-low && s_poper-low+1(2).
str2 = sy-datum+(6).
"检则输入的年月
* IF STR1 <> STR2.
* MESSAGE TEXT-M12 TYPE 'S' DISPLAY LIKE 'E'.
* LEAVE LIST-PROCESSING.
* ENDIF.
AUTHORITY-CHECK OBJECT 'F_BKPF_BUK'
ID 'BUKRS' FIELD s_bukrs-low
ID 'ACTVT' FIELD '03'.
IF sy-subrc <> 0.
lv_message = TEXT-m06. " 没有公司代码&1的权限!
REPLACE '&1' IN lv_message WITH s_bukrs-low.
MESSAGE s001(00) DISPLAY LIKE 'E' WITH lv_message.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form GET_DATA_HEAD
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& <-- ct_head
*&---------------------------------------------------------------------*
FORM get_data_head CHANGING ct_head TYPE t_head.
DATA: ls_head TYPE s_head.
DATA: lv_first_date TYPE sy-datum,
lv_last_date TYPE sy-datum,
lv_monat TYPE bkpf-monat,
* LV_WAERS TYPE BKPF-WAERS,
lv_index TYPE sy-index.
CLEAR: lv_waers, ct_head[].
gv_bukrs = s_bukrs-low.
lv_monat = s_poper-low.
lv_first_date = s_gjahr-low && lv_monat && '01'.
CALL FUNCTION 'BKK_GET_MONTH_LASTDAY'
EXPORTING
i_date = lv_first_date
IMPORTING
e_date = lv_last_date.
SELECT SINGLE waers INTO lv_waers
FROM t001
WHERE bukrs = gv_bukrs
%_HINTS HDB 'RESULT_LAG(''hana_sr'')'.
DO 2 TIMES.
lv_index = sy-index.
ls_head-belnr = lv_index.
ls_head-bukrs = gv_bukrs.
ls_head-gjahr = lv_last_date(4).
ls_head-bldat = lv_last_date.
ls_head-budat = lv_last_date.
ls_head-monat = lv_last_date+4(2).
ls_head-blart = 'SA'.
ls_head-waers = lv_waers.
APPEND ls_head TO ct_head.
ENDDO.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form init_alv_100
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM init_alv_100.
DATA: ls_layout TYPE lvc_s_layo,
ls_variant TYPE disvariant.
DATA: lt_fieldcatalog TYPE lvc_t_fcat,
lt_exclude TYPE ui_functions.
IF go_dock_100 IS INITIAL.
" 容器
CREATE OBJECT go_dock_100
EXPORTING
repid = sy-repid " 程序名
dynnr = sy-dynnr " 屏幕号
* SIDE = DOCK_AT_LEFT
extension = 1500 " ALV宽度
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
OTHERS = 6.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
" ALV
CREATE OBJECT go_grid_100
EXPORTING
i_parent = go_dock_100
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 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.
ls_variant-report = sy-repid.
" ALV字段
PERFORM set_fieldcatalog USING '100'
CHANGING lt_fieldcatalog.
" ALV布局
PERFORM set_layout CHANGING ls_layout.
" 隐藏工具条按钮
PERFORM set_toolbar_excluding CHANGING lt_exclude.
" 显示ALV
CALL METHOD go_grid_100->set_table_for_first_display
EXPORTING
i_bypassing_buffer = 'X'
is_variant = ls_variant
i_save = 'A'
i_default = 'X'
is_layout = ls_layout
it_toolbar_excluding = lt_exclude
CHANGING
it_outtab = lt_data[]
it_fieldcatalog = lt_fieldcatalog[]
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
" ALV "注册事件
CREATE OBJECT go_alv_event_100.
SET HANDLER go_alv_event_100->handle_toolbar FOR go_grid_100.
SET HANDLER go_alv_event_100->handle_user_command FOR go_grid_100.
SET HANDLER go_alv_event_100->header_double_click FOR go_grid_100.
CALL METHOD go_grid_100->set_toolbar_interactive.
ELSE.
PERFORM refresh_alv USING go_grid_100.
ENDIF.
ENDFORM. "init_alv_100
*&---------------------------------------------------------------------*
*& Form init_alv_200
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM init_alv_200.
DATA: ls_layout TYPE lvc_s_layo,
ls_variant TYPE disvariant.
DATA: lt_fieldcatalog TYPE lvc_t_fcat,
lt_exclude TYPE ui_functions.
IF go_dock_200 IS INITIAL.
" 容器
CREATE OBJECT go_dock_200
EXPORTING
repid = sy-repid " 程序名
dynnr = sy-dynnr " 屏幕号
extension = 1500 " ALV宽度
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5
OTHERS = 6.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
" ALV
CREATE OBJECT go_grid_200
EXPORTING
i_parent = go_dock_200
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 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.
" ALV字段
PERFORM set_fieldcatalog USING '200'
CHANGING lt_fieldcatalog.
" ALV布局
PERFORM set_layout CHANGING ls_layout.
" 隐藏工具条按钮
PERFORM set_toolbar_excluding CHANGING lt_exclude.
" 显示ALV
CALL METHOD go_grid_200->set_table_for_first_display
EXPORTING
i_bypassing_buffer = 'X'
is_layout = ls_layout
it_toolbar_excluding = lt_exclude
CHANGING
it_outtab = gt_item[]
it_fieldcatalog = lt_fieldcatalog[]
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
ELSE.
PERFORM refresh_alv USING go_grid_200.
ENDIF.
ENDFORM. "init_alv_200
*&---------------------------------------------------------------------*
*& Form SET_FIELDCATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->pv_screen text
* <--ct_fcat text
*----------------------------------------------------------------------*
FORM set_fieldcatalog USING pv_screen TYPE scradnum
CHANGING ct_fcat TYPE lvc_t_fcat.
DEFINE lm_add_fcat.
CLEAR ls_fcat.
ls_fcat-fieldname = &1. " 字段名
ls_fcat-coltext = &2. " 显示字段文本
ls_fcat-scrtext_l = &2. " 显示字段文本
ls_fcat-scrtext_m = &2. " 显示字段文本
* ls_fcat-scrtext_s = &2. " 显示字段文本
ls_fcat-col_pos = &3. " 列顺序
ls_fcat-checkbox = &4. " 复选框
ls_fcat-edit = &5. " 可修改
ls_fcat-no_zero = &6. " 隐藏前导零
ls_fcat-outputlen = &7. " 输出长度
ls_fcat-ref_table = &8. " 参考表
ls_fcat-ref_field = &9. " 参考字段
IF &3 < 7.
ls_fcat-fix_column = 'X'. " 固定列
ENDIF.
APPEND ls_fcat TO ct_fcat.
END-OF-DEFINITION.
DATA: ls_fcat TYPE lvc_s_fcat.
CLEAR: ct_fcat[].
IF pv_screen = '100'.
lm_add_fcat 'ICON' TEXT-f17 '0' '' '' '' '' '' ''. " 状态
lm_add_fcat 'MESSAGE' TEXT-f18 '0' '' '' '' '90' '' ''. " 提示信息
lm_add_fcat 'BELNR1' TEXT-f00 '1' '' '' '' '' '' ''. " 分录
lm_add_fcat 'RYEAR' TEXT-f01 '1' '' '' '' '' '' ''. " 年度
lm_add_fcat 'RPMAX' TEXT-f02 '2' '' '' '' '' '' ''. " 期间
lm_add_fcat 'BUKRS' TEXT-f03 '3' '' '' '' '' '' ''. " 公司编码
lm_add_fcat 'BUTXT' TEXT-f04 '4' '' '' '' '' '' ''. " 公司名称
lm_add_fcat 'RACCT' TEXT-f05 '5' '' '' '' '' '' ''. " 科目编号
lm_add_fcat 'TXT50' TEXT-f06 '6' '' '' '' '' '' ''. " 科目名称
lm_add_fcat 'RCNTR' TEXT-f07 '7' '' '' '' '' '' ''. " 成本中心
lm_add_fcat 'KTEXT' TEXT-f08 '8' '' '' '' '' '' ''. " 成本中心名称
lm_add_fcat 'RBUSA' TEXT-f09 '9' '' '' '' '' '' ''. " 业务范围
lm_add_fcat 'GTEXT' TEXT-f10 '10' '' '' '' '' '' ''. " 业务范围名称
lm_add_fcat 'RFAREA' TEXT-f11 '11' '' '' '' '' '' ''. " 功能范围
lm_add_fcat 'FKBTX' TEXT-f12 '12' '' '' '' '' '' ''. " 功能范围名称
lm_add_fcat 'PRCTR' TEXT-f24 '12' '' '' '' '' '' ''. " 利润中心
lm_add_fcat 'RTCUR' TEXT-f13 '13' '' '' '' '' '' ''. " 币别
lm_add_fcat 'BHSLY1' TEXT-f26 '13' '' '' '' '' '' ''. " 本年累计借方(本币)
lm_add_fcat 'BHSLY2' TEXT-f27 '13' '' '' '' '' '' ''. " 本年累计货方(本币)
lm_add_fcat 'BHSLZ1' TEXT-f14 '14' '' '' '' '' '' ''. " 调整金额(本币)
lm_add_fcat 'SAKNR' TEXT-f15 '15' '' '' '' '' '' ''. " 对方科目
lm_add_fcat 'TXT50S' TEXT-f16 '16' '' '' '' '' '' ''. " 对方科目名称
lm_add_fcat 'BELNR' TEXT-f19 '17' '' '' '' '10' '' ''. " 会计凭证
lm_add_fcat 'WERKS' TEXT-f28 '18' '' '' '' '' '' ''. " 工厂
lm_add_fcat 'HSLY1' TEXT-f29 '19' '' '' '' '' '' ''. " 本年累计借方(本币)
lm_add_fcat 'HSLY2' TEXT-f30 '20' '' '' '' '' '' ''. " 本年累计货方(本币)
lm_add_fcat 'HSLZ1' TEXT-f31 '20' '' '' '' '' '' ''. " 调整金额(本币)
ELSEIF pv_screen = '200'.
lm_add_fcat 'BELNR' TEXT-f00 '10' '' '' '' '' '' ''. " 分录
lm_add_fcat 'DOCLN' TEXT-f21 '10' '' '' '' '' '' ''. " 凭证行
lm_add_fcat 'SAKNR' TEXT-f05 '10' '' '' '' '' '' ''. " 总账科目
lm_add_fcat 'TXT50' TEXT-f06 '20' '' '' '' '' '' ''. " 科目名称
lm_add_fcat 'SGTXT' TEXT-f25 '20' '' '' '' '' '' ''. " 文本
lm_add_fcat 'FKBER' TEXT-f11 '20' '' '' '' '' '' ''. " 功能范围
lm_add_fcat 'KOSTL' TEXT-f07 '20' '' '' '' '' '' ''. " 成本中心
lm_add_fcat 'GSBER' TEXT-f09 '20' '' '' '' '' '' ''. " 业务范围
lm_add_fcat 'PRCTR' TEXT-f24 '20' '' '' '' '' '' ''. " 利润中心
lm_add_fcat 'BSCHL' TEXT-f32 '30' '' '' '' '' '' ''. " 记账码
lm_add_fcat 'HSL' TEXT-f22 '40' '' '' '' '' '' ''. " 金额
lm_add_fcat 'RHCUR' TEXT-f13 '50' '' '' '' '' '' ''. " 货币码
lm_add_fcat 'BUKRS' TEXT-f03 '60' '' '' '' '' '' ''. " 公司代码
lm_add_fcat 'GJAHR' TEXT-f01 '70' '' '' '' '' '' ''. " 年度
lm_add_fcat 'MONAT' TEXT-f02 '80' '' '' '' '' '' ''. " 期间
lm_add_fcat 'WERKS' TEXT-f28 '80' '' '' '' '' '' ''. " 工厂
lm_add_fcat 'BLART' TEXT-f23 '80' '' '' '' '' '' ''. " 凭证类型
ENDIF.
ENDFORM. "SET_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form SET_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->cs_layout text
*----------------------------------------------------------------------*
FORM set_layout CHANGING cs_layout TYPE lvc_s_layo.
CLEAR: cs_layout.
cs_layout-cwidth_opt = 'X'. " 自动调节字段长度
cs_layout-zebra = 'X'. " 颜色交替显示
cs_layout-sel_mode = 'D'. " A、B、C、D
cs_layout-box_fname = 'SEL'. "设置列SEL是选择框
* CS_LAYOUT-EDIT = 'X'. "单元格可编辑
* CS_LAYOUT-STYLEFNAME = 'SEL'. "单元格可编辑
ENDFORM. "SET_LAYOUT
*&---------------------------------------------------------------------*
*& Form SET_TOOLBAR_EXCLUDING
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->CT_FUNCTION text
*----------------------------------------------------------------------*
FORM set_toolbar_excluding CHANGING ct_function TYPE ui_functions.
DATA: ls_function TYPE ui_func.
CLEAR: ct_function[].
ls_function = cl_gui_alv_grid=>mc_fc_print. " 打印
APPEND ls_function TO ct_function.
ls_function = cl_gui_alv_grid=>mc_fc_graph. " 显示图形
APPEND ls_function TO ct_function.
ls_function = cl_gui_alv_grid=>mc_mb_view. " 视图
APPEND ls_function TO ct_function.
ls_function = cl_gui_alv_grid=>mc_fc_info. " 最终用户文档
APPEND ls_function TO ct_function.
ls_function = cl_gui_alv_grid=>mc_fc_print_back. " 打印
APPEND ls_function TO ct_function.
ls_function = cl_gui_alv_grid=>mc_fc_loc_insert_row. " 插入行
APPEND ls_function TO ct_function.
ls_function = cl_gui_alv_grid=>mc_fc_loc_delete_row. " 删除行
APPEND ls_function TO ct_function.
ls_function = cl_gui_alv_grid=>mc_fc_loc_append_row. " 附加行
APPEND ls_function TO ct_function.
ls_function = cl_gui_alv_grid=>mc_fc_loc_copy_row. " 复制行
APPEND ls_function TO ct_function.
ls_function = cl_gui_alv_grid=>mc_fc_loc_copy. " 复制
APPEND ls_function TO ct_function.
ls_function = cl_gui_alv_grid=>mc_fc_loc_cut. " 剪切
APPEND ls_function TO ct_function.
ls_function = cl_gui_alv_grid=>mc_fc_loc_paste. " 插入总览
APPEND ls_function TO ct_function.
ls_function = cl_gui_alv_grid=>mc_fc_loc_paste_new_row. " 插入新行
APPEND ls_function TO ct_function.
ls_function = cl_gui_alv_grid=>mc_fc_loc_undo. " 撤销
APPEND ls_function TO ct_function.
* ls_function = cl_gui_alv_grid=>mc_mb_export. " 导出
* APPEND ls_function TO ct_function.
* ls_function = cl_gui_alv_grid=>mc_fc_maximum. " 最大值
* APPEND ls_function TO ct_function.
* ls_function = cl_gui_alv_grid=>mc_fc_minimum. " 最小值
* APPEND ls_function TO ct_function.
* ls_function = cl_gui_alv_grid=>mc_fc_sum. " 总计
* APPEND ls_function TO ct_function.
* ls_function = cl_gui_alv_grid=>mc_fc_average. " 平均值
* APPEND ls_function TO ct_function.
* ls_function = cl_gui_alv_grid=>mc_fc_refresh. " 刷新
* APPEND ls_function TO ct_function.
* ls_function = cl_gui_alv_grid=>mc_fc_detail. " 明细
* APPEND ls_function TO ct_function.
ENDFORM. "SET_TOOLBAR_EXCLUDING
*&---------------------------------------------------------------------*
*& Form REFRESH_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PO_GRID text
*----------------------------------------------------------------------*
FORM refresh_alv USING po_grid TYPE REF TO cl_gui_alv_grid.
DATA: ls_scroll TYPE lvc_s_stbl.
ls_scroll-row = 'X'.
ls_scroll-col = 'X'.
CALL METHOD po_grid->refresh_table_display
EXPORTING
is_stable = ls_scroll
i_soft_refresh = 'X'
EXCEPTIONS
finished = 1
OTHERS = 2.
ENDFORM. "REFRESH_ALV
*&---------------------------------------------------------------------*
*& Form ALV_TOOLBAR
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& <-- ct_toolbar
*&---------------------------------------------------------------------*
FORM alv_toolbar CHANGING ct_toolbar TYPE ttb_button.
DATA: ls_toolbar TYPE stb_button.
ls_toolbar-butn_type = 3.
APPEND ls_toolbar TO ct_toolbar.
CLEAR: ls_toolbar.
ls_toolbar-function = '&ZPOST'.
ls_toolbar-icon = '@3H@'.
ls_toolbar-quickinfo = TEXT-b01. " 过账
ls_toolbar-butn_type = 0.
ls_toolbar-disabled = ''.
ls_toolbar-text = TEXT-b01. " 过账
APPEND ls_toolbar TO ct_toolbar.
CLEAR: ls_toolbar.
ls_toolbar-butn_type = 3.
APPEND ls_toolbar TO ct_toolbar.
CLEAR: ls_toolbar.
ls_toolbar-function = '&ZCHECK'.
ls_toolbar-icon = '@8Z@'.
ls_toolbar-quickinfo = TEXT-b02. " 模拟
ls_toolbar-butn_type = 0.
ls_toolbar-disabled = ''.
ls_toolbar-text = TEXT-b02. " 模拟
APPEND ls_toolbar TO ct_toolbar.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form ALV_USER_COMMAND
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> pv_ucomm
*&---------------------------------------------------------------------*
FORM alv_user_command USING pv_ucomm TYPE sy-ucomm.
CASE pv_ucomm.
WHEN '&ZPOST'.
PERFORM call_screen_200 USING '1'.
WHEN '&ZCHECK'.
PERFORM call_screen_200 USING '2'.
WHEN '&IC1'.
READ TABLE lt_data INTO ls_data INDEX 1. "PS_SELFIELD-TABINDEX.
IF sy-subrc = 0 .
SET PARAMETER ID 'ACC' FIELD ls_data-racct.
SET PARAMETER ID 'BUK' FIELD ls_data-bukrs.
SET PARAMETER ID 'GJR' FIELD ls_data-ryear.
CALL TRANSACTION 'FAGLB03' AND SKIP FIRST SCREEN.
ENDIF.
ENDCASE.
PERFORM refresh_alv USING go_grid_100.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form call_bapi_import
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> pv_post text
*&---------------------------------------------------------------------*
FORM call_bapi_import USING pv_post TYPE char1.
DATA: ls_documentheader TYPE bapiache09,
ls_accountgl TYPE bapiacgl09,
ls_currencyamount TYPE bapiaccr09,
ls_return TYPE bapiret2,
ls_extension1 TYPE bapiacextc,
ls_extension2 TYPE bapiparex.
DATA: ls_head TYPE s_head,
ls_item TYPE s_item,
ls_ztfi105 TYPE ztfi105.
DATA: lt_accountgl LIKE TABLE OF ls_accountgl,
lt_currencyamount LIKE TABLE OF ls_currencyamount,
lt_return LIKE TABLE OF ls_return,
lt_extension1 LIKE TABLE OF bapiacextc WITH HEADER LINE,
lt_extension2 LIKE TABLE OF bapiparex WITH HEADER LINE. "Reference Structure for BAPI
DATA: lt_ztfi105 LIKE TABLE OF ls_ztfi105.
DATA: lv_obj_type TYPE bapiache09-obj_type,
lv_obj_key TYPE bapiache09-obj_key,
lv_obj_sys TYPE bapiache09-obj_sys.
DATA: lv_hsl TYPE acdoca-hsl,
lv_subrc TYPE sy-subrc,
lv_tabix TYPE sy-tabix,
lv_buzei TYPE bseg-buzei,
lv_message TYPE bapiret2-message.
CLEAR ls_data.
LOOP AT lt_data INTO ls_data WHERE sel = 'X'.
READ TABLE gt_head INTO ls_head INDEX 1.
CLEAR: lt_accountgl[], lt_currencyamount[], lt_return[].
CLEAR: ls_documentheader, lv_buzei.
ls_documentheader-username = sy-uname. " 用户名
ls_documentheader-comp_code = ls_data-bukrs. " 公司代码
ls_documentheader-doc_date = ls_head-bldat. " 凭证中的凭证日期
ls_documentheader-pstng_date = ls_head-budat. " 凭证中的过帐日期
ls_documentheader-fisc_year = ls_head-gjahr. " 财年
ls_documentheader-fis_period = ls_head-monat. " 会计期间
ls_documentheader-doc_type = ls_head-blart. " 凭证类型
ls_documentheader-header_txt = ls_head-gjahr && '年' && ls_head-monat && '月期末结转差异科目到主营业务成本'. " 凭证抬头文本
CLEAR: ls_data.
ENDLOOP.
LOOP AT gt_item INTO ls_item . " WHERE BELNR = LS_DATA1-BELNR1.
CLEAR ls_accountgl.
ls_accountgl-itemno_acc = ls_item-docln. "项目行号
ls_accountgl-gl_account = ls_item-saknr. "会计科目
ls_accountgl-item_text = ls_item-sgtxt. "项目文本
ls_accountgl-func_area = ls_item-fkber. "功能范围
ls_accountgl-costcenter = ls_item-kostl. "成本中心
ls_accountgl-bus_area = ls_item-gsber. "业务范围
ls_accountgl-profit_ctr = ls_item-prctr. "利润中心
APPEND ls_accountgl TO lt_accountgl.
CLEAR ls_currencyamount.
ls_currencyamount-itemno_acc = ls_item-docln. " 会计凭证行项目编号
ls_currencyamount-curr_type = '00'. " 货币和评估视图
ls_currencyamount-currency = ls_head-waers . " Modify By IT065 At 20240325 LS_ITEM-RHCUR. " 货币码
IF ls_item-drcrk = 'S'.
ls_currencyamount-amt_doccur = abs( ls_item-hsl ). " 金额
ELSEIF ls_item-drcrk = 'H'.
ls_currencyamount-amt_doccur = abs( ls_item-hsl ) * ( -1 ). " 金额
ENDIF.
APPEND ls_currencyamount TO lt_currencyamount.
ENDLOOP.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
EXPORTING
documentheader = ls_documentheader
TABLES
accountgl = lt_accountgl
currencyamount = lt_currencyamount
return = lt_return.
LOOP AT lt_return INTO ls_return WHERE type CA 'EA'.
lv_subrc = '1'.
lv_message = lv_message && ls_return-message.
ENDLOOP.
IF lv_subrc <> 0.
LOOP AT lt_data INTO ls_data WHERE sel = 'X'. "BELNR1 = LS_DATA1-BELNR1.
lv_tabix = sy-tabix.
ls_data-type = 'E'.
ls_data-icon = gc_icon_red.
ls_data-message = lv_message.
MODIFY lt_data FROM ls_data INDEX lv_tabix TRANSPORTING type icon message.
CLEAR ls_data.
ENDLOOP.
LOOP AT gt_item INTO ls_item . "WHERE BELNR = LS_DATA1-BELNR1.
lv_tabix = sy-tabix.
ls_item-type = 'E'.
ls_item-icon = gc_icon_red.
ls_item-message = lv_message.
MODIFY gt_item FROM ls_item INDEX lv_tabix TRANSPORTING type icon message.
CLEAR ls_item.
ENDLOOP.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
EXIT.
ENDIF.
* ENDLOOP.
CHECK pv_post = 'X'.
CHECK lv_subrc = 0.
CLEAR ls_data.
LOOP AT lt_data INTO ls_data WHERE sel = 'X'.
READ TABLE gt_head INTO ls_head INDEX 1.
CLEAR: lt_accountgl[], lt_currencyamount[], lt_return[],
lt_ztfi105[], lv_obj_type, lv_obj_key, lv_obj_sys .
CLEAR: ls_documentheader, lv_buzei.
ls_documentheader-username = sy-uname. " 用户名
ls_documentheader-comp_code = ls_data-bukrs. " 公司代码
ls_documentheader-doc_date = ls_head-bldat. " 凭证中的凭证日期
ls_documentheader-pstng_date = ls_head-budat. " 凭证中的过帐日期
ls_documentheader-fisc_year = ls_head-gjahr. " 财年
ls_documentheader-fis_period = ls_head-monat. " 会计期间
ls_documentheader-doc_type = ls_head-blart. " 凭证类型
ls_documentheader-header_txt = ls_head-gjahr && '年' && ls_head-monat && '月期末结转差异科目到主营业务成本'. " 凭证抬头文本
CLEAR ls_data.
ENDLOOP.
DATA: wa_zexten LIKE zexten.
LOOP AT gt_item INTO ls_item . "WHERE BELNR = LS_DATA1-BELNR1.
CLEAR: ls_accountgl.
ls_accountgl-itemno_acc = ls_item-docln. " 会计凭证行项目编号
ls_accountgl-gl_account = ls_item-saknr. " 会计科目
ls_accountgl-item_text = ls_item-sgtxt. " 项目文本
ls_accountgl-func_area = ls_item-fkber. " 功能范围
ls_accountgl-costcenter = ls_item-kostl. " 成本中心
ls_accountgl-bus_area = ls_item-gsber. " 业务范围
ls_accountgl-profit_ctr = ls_item-prctr. " 利润中心
APPEND ls_accountgl TO lt_accountgl.
CLEAR ls_currencyamount.
ls_currencyamount-itemno_acc = ls_item-docln. " 会计凭证行项目编号
ls_currencyamount-curr_type = '00'. " 货币和评估视图
ls_currencyamount-currency = ls_head-waers . " Modify By IT065 At 20240325 LS_ITEM-RHCUR. " 货币码
IF ls_item-drcrk = 'S'.
ls_currencyamount-amt_doccur = abs( ls_item-hsl ). " 金额
ELSEIF ls_item-drcrk = 'H'.
ls_currencyamount-amt_doccur = abs( ls_item-hsl ) * ( -1 ). " 金额
ENDIF.
APPEND ls_currencyamount TO lt_currencyamount.
"标识: 反记帐
IF ls_item-drcrk = 'H'.
CLEAR: wa_zexten.
wa_zexten-posnr = ls_item-docln. "行号
wa_zexten-bschl = ls_item-bschl. "过账码
wa_zexten-xnegp = 'X'. "标识: 反记帐
ls_extension2-structure = 'ZEXTEN'.
ls_extension2-valuepart1 = wa_zexten.
APPEND ls_extension2 TO lt_extension2.
ENDIF.
CLEAR ls_item.
ENDLOOP.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = ls_documentheader
IMPORTING
obj_type = lv_obj_type
obj_key = lv_obj_key
obj_sys = lv_obj_sys
TABLES
accountgl = lt_accountgl
currencyamount = lt_currencyamount
return = lt_return
extension1 = lt_extension1
extension2 = lt_extension2.
LOOP AT lt_return INTO ls_return WHERE type CA 'EA'.
lv_subrc = '1'.
lv_message = lv_message && ls_return-message.
CLEAR ls_return.
ENDLOOP.
IF lv_subrc = 0.
LOOP AT lt_data INTO ls_data WHERE sel = 'X'. "BELNR1 = LS_DATA1-BELNR1.
lv_tabix = sy-tabix.
ls_data-belnr = lv_obj_key(10).
ls_data-ryear = lv_obj_key+14(4).
ls_data-type = 'S'.
ls_data-icon = gc_icon_green.
ls_data-message = TEXT-m02. " 凭证&1记账到公司代码&2中!
REPLACE '&1' IN ls_data-message WITH ls_data-belnr.
REPLACE '&2' IN ls_data-message WITH ls_data-bukrs.
MODIFY lt_data FROM ls_data
INDEX lv_tabix TRANSPORTING belnr ryear type icon message.
CLEAR ls_ztfi105.
LOOP AT gt_item INTO ls_item WHERE belnr = ls_data-belnr1.
ls_ztfi105-rbukrs = ls_data-bukrs.
ls_ztfi105-gjahr = ls_data-ryear.
ls_ztfi105-belnr = ls_data-belnr.
ls_ztfi105-belnr1 = ls_data-belnr1.
ls_ztfi105-docln = ls_item-docln.
ls_ztfi105-poper = ls_head-monat.
ls_ztfi105-racct = ls_data-saknr. " 原始查询出的 会计科目
ls_ztfi105-saknr = ls_item-saknr. " 凭证上会计科目
ls_ztfi105-rhcur = ls_data-rtcur.
ls_ztfi105-drcrk = ls_item-drcrk.
ls_ztfi105-hsly1 = ls_data-hsly1. "本年累计借方(本币)
ls_ztfi105-hsly2 = ls_data-hsly2. "本年累计货方(本币)
IF ls_item-drcrk = 'S'.
ls_ztfi105-hsl = abs( ls_item-hsl ). " 金额 LS_ITEM-HSL_S.
ELSEIF ls_item-drcrk = 'H'.
ls_ztfi105-hsl = abs( ls_item-hsl ) * ( -1 ). " 金额 LS_ITEM-HSL_H.
ENDIF.
ls_ztfi105-sgtxt = ls_item-sgtxt. "文本
ls_ztfi105-fkber = ls_item-fkber. "功能范围
ls_ztfi105-kostl = ls_item-kostl. "成本中心
ls_ztfi105-gsber = ls_item-gsber. "业务范围
ls_ztfi105-prctr = ls_item-prctr. "利润中心
ls_ztfi105-tcode = 'ZFI134'.
ls_ztfi105-uname = sy-uname.
ls_ztfi105-udate = sy-datum.
ls_ztfi105-utime = sy-uzeit.
APPEND ls_ztfi105 TO lt_ztfi105.
CLEAR ls_item.
ENDLOOP.
CLEAR ls_data.
ENDLOOP.
IF lt_ztfi105[] IS NOT INITIAL.
MODIFY ztfi105 FROM TABLE lt_ztfi105.
ENDIF.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ELSE.
LOOP AT lt_data INTO ls_data WHERE sel = 'X'. "BELNR1 = LS_DATA1-BELNR1.
lv_tabix = sy-tabix.
ls_data-type = 'E'.
ls_data-icon = gc_icon_red.
ls_data-message = lv_message.
MODIFY lt_data FROM ls_data INDEX lv_tabix TRANSPORTING type icon message.
CLEAR ls_data.
ENDLOOP.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
EXIT.
ENDIF.
* ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form CALL_SCREEN_200
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> pv_flag text
*&---------------------------------------------------------------------*
FORM call_screen_200 USING pv_flag TYPE char1.
* 处理带选择行 SEL ='X'
DATA : lt_row TYPE lvc_t_roid, "内表
ls_row TYPE lvc_s_roid. "工作区
CLEAR: lt_row[],ls_row.
CALL METHOD go_grid_100->get_selected_rows
IMPORTING
et_row_no = lt_row.
CLEAR: ls_data.
LOOP AT lt_data INTO ls_data.
ls_data-sel = ''.
MODIFY lt_data FROM ls_data.
CLEAR : ls_data.
ENDLOOP.
LOOP AT lt_row INTO ls_row.
READ TABLE lt_data INTO ls_data INDEX ls_row-row_id .
IF sy-subrc EQ 0 .
ls_data-sel = 'X'.
MODIFY lt_data FROM ls_data INDEX sy-tabix TRANSPORTING sel.
CLEAR : ls_data.
ENDIF.
CLEAR: ls_row.
ENDLOOP .
DATA: ls_item TYPE s_item.
DATA: lv_subrc TYPE sy-subrc.
* "READ TABLE LT_DATA INTO LS_DATA INDEX 1.
LOOP AT lt_data INTO ls_data WHERE sel = 'X' AND icon = gc_icon_red. "AND BELNR IS NOT INITIAL.
" 凭证已经生成,不允许再次创建!
MESSAGE TEXT-m13 TYPE 'S' DISPLAY LIKE 'E'. "有错误行项,不允许此次创建!
RETURN.
ENDLOOP.
PERFORM check_data CHANGING lv_subrc.
* CHECK LV_SUBRC = 0.
PERFORM get_item_data CHANGING gt_item.
IF pv_flag = '1'.
gv_post = 'X'.
ELSEIF pv_flag = '2'.
gv_post = ''.
PERFORM call_bapi_import USING gv_post.
ENDIF.
READ TABLE gt_item INTO ls_item WITH KEY type = 'E'.
IF sy-subrc EQ 0.
" 凭证有错误,请检查!
MESSAGE TEXT-m07 TYPE 'S' DISPLAY LIKE 'E'.
EXIT.
ENDIF.
CALL SCREEN 200
STARTING AT 5 2
ENDING AT 160 20.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form GET_ITEM_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& <-- ct_ITEM
*&---------------------------------------------------------------------*
FORM get_item_data CHANGING ct_item TYPE t_item.
DATA: BEGIN OF ls_skat,
spras TYPE skat-spras,
ktopl TYPE skat-ktopl,
saknr TYPE skat-saknr,
txt20 TYPE skat-txt20,
txt50 TYPE skat-txt50,
END OF ls_skat.
DATA: ls_head TYPE s_head,
ls_item TYPE s_item,
sno TYPE i.
DATA: lt_skat LIKE TABLE OF ls_skat.
DATA: lv_hsl TYPE acdoca-hsl,
lv_tabix TYPE sy-tabix,
lv_accountgl40 TYPE bapiacgl09-gl_account,
lv_accountgl50 TYPE bapiacgl09-gl_account.
sno = 0. "凭证序号
CLEAR: ct_item[],ls_head,ls_data,ls_item.
LOOP AT gt_head INTO ls_head.
"借方 S
LOOP AT lt_data INTO ls_data WHERE sel = 'X'.
CLEAR ls_item.
ls_item-belnr = ls_data-belnr1.
ls_item-rhcur = ls_data-rtcur.
ls_item-bukrs = ls_data-bukrs.
ls_item-gjahr = ls_head-gjahr.
ls_item-monat = ls_head-monat.
ls_item-blart = ls_head-blart.
ls_item-docln = ls_head-belnr.
ls_item-sgtxt = ls_head-gjahr && '年' && ls_head-monat && '月期末结转差异科目到主营业务成本'. "文本
ls_item-fkber = ls_data-rfarea. "功能范围
ls_item-kostl = ls_data-rcntr. "成本中心
ls_item-gsber = ls_data-rbusa. "业务范围
ls_item-prctr = ls_data-prctr. "利润中心
sno = sno + 1. "凭证序号
ls_item-docln = sno.
IF ls_head-belnr = 1. "借方 S
"如果 本年累计借方(本币) + 本年累计贷方(本币)> 0, 则对方科目 作为借方科目
IF ls_data-hslz1 > 0.
ls_item-saknr = ls_data-saknr. "对方科目 作 借方 科目编号
ls_item-txt50 = ls_data-txt50s.
ls_item-bschl = '40'.
ls_item-drcrk = 'S'.
ls_item-hsl = abs( ls_data-hslz1 ).
ELSE.
ls_item-saknr = ls_data-racct. "科目编号 作 借方 科目编号
ls_item-txt50 = ls_data-txt50.
ls_item-bschl = '40'.
ls_item-drcrk = 'S'.
ls_item-hsl = abs( ls_data-hslz1 ).
ENDIF.
ELSE. "贷方 H
"如果 期末余额借方(本币) <> 0, 则 科目 作为 贷方科目
IF ls_data-hslz1 > 0.
ls_item-saknr = ls_data-racct. "科目编号 作 贷方 科目编号
ls_item-txt50 = ls_data-txt50.
ls_item-bschl = '50'.
ls_item-drcrk = 'H'.
ls_item-hsl = abs( ls_data-hslz1 ).
ELSE.
ls_item-saknr = ls_data-saknr. "对方科目 作 贷方 科目编号
ls_item-txt50 = ls_data-txt50s.
ls_item-bschl = '50'.
ls_item-drcrk = 'H'.
ls_item-hsl = abs( ls_data-hslz1 ).
ENDIF.
ENDIF.
IF ls_item-txt50 CP '*主营业务成本*' . " 科目名称 含有 “主营业务成本” 字眼 时, 以下 3 栏位 置空
ls_item-kostl = ''. "成本中心
ls_item-fkber = ''. "功能范围
ENDIF.
APPEND ls_item TO ct_item.
CLEAR ls_data.
ENDLOOP.
ENDLOOP.
SORT ct_item BY belnr docln.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form CHECK_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& <-- CV_SUBRC
*&---------------------------------------------------------------------*
FORM check_data CHANGING cv_subrc TYPE sy-subrc.
DATA: BEGIN OF ls_acdoca,
rldnr TYPE acdoca-rldnr,
rbukrs TYPE acdoca-rbukrs,
gjahr TYPE acdoca-gjahr,
belnr TYPE acdoca-belnr,
docln TYPE acdoca-docln,
xreversed TYPE acdoca-xreversed,
END OF ls_acdoca.
DATA: ls_ztfi105 TYPE ztfi105.
DATA: lt_ztfi105 LIKE TABLE OF ls_ztfi105,
lt_acdoca LIKE TABLE OF ls_acdoca.
DATA: lv_tabix TYPE sy-tabix.
CLEAR cv_subrc.
SELECT *
INTO CORRESPONDING FIELDS OF TABLE lt_ztfi105
FROM ztfi105
WHERE tcode = 'ZFI134'
AND rbukrs IN s_bukrs
AND gjahr IN s_gjahr
AND poper IN s_poper
%_HINTS HDB 'RESULT_LAG(''hana_sr'')'.
IF lt_ztfi105[] IS NOT INITIAL.
SELECT rldnr rbukrs gjahr belnr docln xreversed
INTO CORRESPONDING FIELDS OF TABLE lt_acdoca
FROM acdoca
FOR ALL ENTRIES IN lt_ztfi105
WHERE rldnr = '0L'
AND rbukrs = lt_ztfi105-rbukrs
AND gjahr = lt_ztfi105-gjahr
AND belnr = lt_ztfi105-belnr
AND docln = lt_ztfi105-docln
%_HINTS HDB 'RESULT_LAG(''hana_sr'')'.
SORT lt_acdoca BY rbukrs gjahr belnr docln.
LOOP AT lt_ztfi105 INTO ls_ztfi105.
lv_tabix = sy-tabix.
READ TABLE lt_acdoca INTO ls_acdoca WITH KEY rbukrs = ls_ztfi105-rbukrs
gjahr = ls_ztfi105-gjahr
belnr = ls_ztfi105-belnr
docln = ls_ztfi105-docln BINARY SEARCH.
IF sy-subrc EQ 0.
IF ls_acdoca-xreversed = 'X'.
DELETE lt_ztfi105 INDEX lv_tabix.
ENDIF.
ENDIF.
ENDLOOP.
ENDIF.
IF lt_ztfi105[] IS NOT INITIAL.
cv_subrc = 1.
SORT lt_ztfi105 BY rbukrs gjahr racct fkber kostl gsber prctr."BELNR1
LOOP AT lt_data INTO ls_data.
lv_tabix = sy-tabix.
READ TABLE lt_ztfi105 INTO ls_ztfi105 WITH KEY rbukrs = ls_data-bukrs
gjahr = s_gjahr-low
"BELNR1 = LS_DATA-BELNR1
"RACCT = LS_DATA-SAKNR
racct = ls_data-racct " 科目
fkber = ls_data-rfarea " 功能范围
kostl = ls_data-rcntr " 成本中心
gsber = ls_data-rbusa " 业务范围
prctr = ls_data-prctr " 利润中心
BINARY SEARCH.
IF sy-subrc EQ 0.
ls_data-ryear = ls_ztfi105-gjahr.
ls_data-belnr = ls_ztfi105-belnr.
ls_data-type = 'E'.
ls_data-icon = gc_icon_red.
ls_data-message = TEXT-m10.
MODIFY lt_data FROM ls_data INDEX lv_tabix TRANSPORTING ryear belnr type icon message.
ELSE.
READ TABLE lt_ztfi105 INTO ls_ztfi105 WITH KEY rbukrs = ls_data-bukrs
gjahr = s_gjahr-low
racct = ls_data-saknr " 科目
fkber = ls_data-rfarea " 功能范围
kostl = ls_data-rcntr " 成本中心
gsber = ls_data-rbusa " 业务范围
prctr = ls_data-prctr " 利润中心
BINARY SEARCH.
IF sy-subrc EQ 0.
ls_data-ryear = ls_ztfi105-gjahr.
ls_data-belnr = ls_ztfi105-belnr.
ls_data-type = 'E'.
ls_data-icon = icon_yellow_light. "黄灯 GC_ICON_RED.
ls_data-message = TEXT-m11. "M10. 本月凭证已生成,不允许重复创建凭证!
MODIFY lt_data FROM ls_data INDEX lv_tabix TRANSPORTING ryear belnr type icon message.
ENDIF.
ENDIF.
ENDLOOP.
ENDIF.
ENDFORM.
FORM frm_getdata .
DATA: smonat TYPE bkpf-monat.
IF s_racct-low IS INITIAL.
s_racct-sign = 'I'.
s_racct-option = 'CP'.
s_racct-low = '*'.
APPEND s_racct.
ENDIF.
" 只取科目=9003 开头, 功能范围 ='5000'
SELECT rbukrs,ryear,rpmax,racct,rcntr,rassc,prctr,rbusa,rfarea,rtcur,drcrk,activ,sfarea,cost_elem
,hslvt,hsl01,hsl02,hsl03,hsl04,hsl05,hsl06,hsl07,hsl08,hsl09,hsl10,hsl11,hsl12,hsl13,hsl14,hsl15,hsl16
INTO TABLE @DATA(lv_faglflext)
FROM faglflext
WHERE rbukrs = @s_bukrs-low
AND ryear = @s_gjahr-low
AND racct IN @s_racct
AND rldnr = '0L'
AND racct LIKE '9003%'
* AND RFAREA IN ( '3000','4000', '5000' )
.
" 公司 会计科目 成本中心 业务范围 功能范围 利润中心
CLEAR: lt_bseg[], lt_bseg1[],lt_bseg2[].
SELECT bukrs, belnr, gjahr, buzei, shkzg, gsber ,dmbtr, vbund, hkont, werks, prctr, h_monat AS monat,kostl,fkber_long AS fkber
INTO CORRESPONDING FIELDS OF TABLE @lt_bseg
FROM bseg
WHERE bukrs = @s_bukrs-low
AND gjahr = @s_gjahr-low
AND hkont LIKE '9003%'
AND h_monat = @s_poper-low.
IF sy-subrc EQ 0.
LOOP AT lt_bseg INTO ls_bseg.
IF ls_bseg-shkzg EQ 'S'.
ls_bseg-hsly1 = ls_bseg-dmbtr.
ELSEIF ls_bseg-shkzg EQ 'H'.
ls_bseg-hsly2 = 0 - ls_bseg-dmbtr.
ENDIF.
CLEAR: ls_bseg-belnr, ls_bseg-buzei,ls_bseg-shkzg, ls_bseg-dmbtr, ls_bseg-vbund. "贸易伙伴的公司标识.
COLLECT ls_bseg INTO lt_bseg2. "汇总 + 工厂
CLEAR: ls_bseg-werks.
COLLECT ls_bseg INTO lt_bseg1. "汇总
CLEAR ls_bseg.
ENDLOOP.
ENDIF.
CLEAR: gs_output,gt_output[].
LOOP AT lv_faglflext INTO DATA(ls_faglflext).
gs_output-ryear = ls_faglflext-ryear.
gs_output-rpmax = ls_faglflext-rpmax.
gs_output-rbukrs = ls_faglflext-rbukrs.
gs_output-racct = ls_faglflext-racct. "会计科目
gs_output-rcntr = ls_faglflext-rcntr. "成本中心
gs_output-rbusa = ls_faglflext-rbusa. "业务范围
gs_output-rfarea = ls_faglflext-rfarea. "功能范围
gs_output-prctr = ls_faglflext-prctr. "利润中心
* GS_OUTPUT-RTCUR = LS_FAGLFLEXT-RTCUR. "币别
gs_output-rtcur = lv_waers. "本币
"会计科目名称
IF sy-langu EQ 'E'.
SELECT SINGLE skat~txt50 INTO gs_output-txt50 FROM skat
WHERE skat~saknr = gs_output-racct AND skat~ktopl = 'OCOA' AND skat~spras = sy-langu.
ELSE.
SELECT SINGLE skat~txt50 INTO gs_output-txt50 FROM skat
WHERE skat~saknr = gs_output-racct AND skat~ktopl = 'LY00' AND skat~spras = sy-langu.
ENDIF.
"成本中心名称
IF sy-langu EQ 'E'.
SELECT SINGLE cskt~ltext INTO gs_output-ktext FROM cskt
WHERE cskt~kostl = gs_output-rcntr AND cskt~kokrs = 'OCOA' AND cskt~spras = sy-langu.
ELSE.
SELECT SINGLE cskt~ltext INTO gs_output-ktext FROM cskt
WHERE cskt~kostl = gs_output-rcntr AND cskt~kokrs = 'LY00' AND cskt~spras = sy-langu.
ENDIF.
"业务范围名称
SELECT SINGLE tgsbt~gtext INTO gs_output-gtext FROM tgsbt
WHERE tgsbt~gsber = gs_output-rbusa AND tgsbt~spras = sy-langu.
"功能范围名称
SELECT SINGLE tfkbt~fkbtx INTO gs_output-fkbtx FROM tfkbt
WHERE tfkbt~fkber = gs_output-rfarea AND tfkbt~spras = sy-langu.
* IF s_poper-low = '001'.
* IF ls_faglflext-drcrk = 'S'. "本年累计借方(本币)
* gs_output-hsly1 = ls_faglflext-hsl01.
* ELSEIF ls_faglflext-drcrk = 'H'. "本年累计贷方(本币)
* gs_output-hsly2 = ls_faglflext-hsl01.
* ENDIF.
* ELSEIF s_poper-low = '002'.
* IF ls_faglflext-drcrk = 'S'. "本年累计借方(本币)
* gs_output-hsly1 = ls_faglflext-hsl01 + ls_faglflext-hsl02.
* ELSEIF ls_faglflext-drcrk = 'H'. "本年累计贷方(本币)
* gs_output-hsly2 = ls_faglflext-hsl01 + ls_faglflext-hsl02.
* ENDIF.
* ELSEIF s_poper-low = '003'.
* IF ls_faglflext-drcrk = 'S'. "本年累计借方(本币)
* gs_output-hsly1 = ls_faglflext-hsl01 + ls_faglflext-hsl02 + ls_faglflext-hsl03.
* ELSEIF ls_faglflext-drcrk = 'H'. "本年累计贷方(本币)
* gs_output-hsly2 = ls_faglflext-hsl01 + ls_faglflext-hsl02 + ls_faglflext-hsl03.
* ENDIF.
* ELSEIF s_poper-low = '004'.
* IF ls_faglflext-drcrk = 'S'. "本年累计借方(本币)
* gs_output-hsly1 = ls_faglflext-hsl01 + ls_faglflext-hsl02 + ls_faglflext-hsl03 + ls_faglflext-hsl04.
* ELSEIF ls_faglflext-drcrk = 'H'. "本年累计贷方(本币)
* gs_output-hsly2 = ls_faglflext-hsl01 + ls_faglflext-hsl02 + ls_faglflext-hsl03 + ls_faglflext-hsl04.
* ENDIF.
* ELSEIF s_poper-low = '005'.
* IF ls_faglflext-drcrk = 'S'. "本年累计借方(本币)
* gs_output-hsly1 = ls_faglflext-hsl01 + ls_faglflext-hsl02 + ls_faglflext-hsl03 + ls_faglflext-hsl04 + ls_faglflext-hsl05.
* ELSEIF ls_faglflext-drcrk = 'H'. "本年累计贷方(本币)
* gs_output-hsly2 = ls_faglflext-hsl01 + ls_faglflext-hsl02 + ls_faglflext-hsl03 + ls_faglflext-hsl04 + ls_faglflext-hsl05.
* ENDIF.
* ELSEIF s_poper-low = '006'.
* IF ls_faglflext-drcrk = 'S'. "本年累计借方(本币)
* gs_output-hsly1 = ls_faglflext-hsl01 + ls_faglflext-hsl02 + ls_faglflext-hsl03 + ls_faglflext-hsl04 + ls_faglflext-hsl05 + ls_faglflext-hsl06.
* ELSEIF ls_faglflext-drcrk = 'H'. "本年累计贷方(本币)
* gs_output-hsly2 = ls_faglflext-hsl01 + ls_faglflext-hsl02 + ls_faglflext-hsl03 + ls_faglflext-hsl04 + ls_faglflext-hsl05 + ls_faglflext-hsl06.
* ENDIF.
* ELSEIF s_poper-low = '007'.
* IF ls_faglflext-drcrk = 'S'. "本年累计借方(本币)
* gs_output-hsly1 = ls_faglflext-hsl01 + ls_faglflext-hsl02 + ls_faglflext-hsl03 + ls_faglflext-hsl04 + ls_faglflext-hsl05 + ls_faglflext-hsl06 + ls_faglflext-hsl07.
* ELSEIF ls_faglflext-drcrk = 'H'. "本年累计贷方(本币)
* gs_output-hsly2 = ls_faglflext-hsl01 + ls_faglflext-hsl02 + ls_faglflext-hsl03 + ls_faglflext-hsl04 + ls_faglflext-hsl05 + ls_faglflext-hsl06 + ls_faglflext-hsl07.
* ENDIF.
* ELSEIF s_poper-low = '008'.
* IF ls_faglflext-drcrk = 'S'. "本年累计借方(本币)
* gs_output-hsly1 = ls_faglflext-hsl01 + ls_faglflext-hsl02 + ls_faglflext-hsl03 + ls_faglflext-hsl04 + ls_faglflext-hsl05 + ls_faglflext-hsl06 + ls_faglflext-hsl07 + ls_faglflext-hsl08.
* ELSEIF ls_faglflext-drcrk = 'H'. "本年累计贷方(本币)
* gs_output-hsly2 = ls_faglflext-hsl01 + ls_faglflext-hsl02 + ls_faglflext-hsl03 + ls_faglflext-hsl04 + ls_faglflext-hsl05 + ls_faglflext-hsl06 + ls_faglflext-hsl07 + ls_faglflext-hsl08.
* ENDIF.
* ELSEIF s_poper-low = '009'.
* IF ls_faglflext-drcrk = 'S'. "本年累计借方(本币)
* gs_output-hsly1 = ls_faglflext-hsl01 + ls_faglflext-hsl02 + ls_faglflext-hsl03 + ls_faglflext-hsl04 + ls_faglflext-hsl05 + ls_faglflext-hsl06 + ls_faglflext-hsl07 + ls_faglflext-hsl08 + ls_faglflext-hsl09.
* ELSEIF ls_faglflext-drcrk = 'H'. "本年累计贷方(本币)
* gs_output-hsly2 = ls_faglflext-hsl01 + ls_faglflext-hsl02 + ls_faglflext-hsl03 + ls_faglflext-hsl04 + ls_faglflext-hsl05 + ls_faglflext-hsl06 + ls_faglflext-hsl07 + ls_faglflext-hsl08 + ls_faglflext-hsl09.
* ENDIF.
* ELSEIF s_poper-low = '010'.
* IF ls_faglflext-drcrk = 'S'. "本年累计借方(本币)
* gs_output-hsly1 = ls_faglflext-hsl01 + ls_faglflext-hsl02 + ls_faglflext-hsl03 + ls_faglflext-hsl04 + ls_faglflext-hsl05 + ls_faglflext-hsl06 + ls_faglflext-hsl07 + ls_faglflext-hsl08 + ls_faglflext-hsl09 + ls_faglflext-hsl10.
* ELSEIF ls_faglflext-drcrk = 'H'. "本年累计贷方(本币)
* gs_output-hsly2 = ls_faglflext-hsl01 + ls_faglflext-hsl02 + ls_faglflext-hsl03 + ls_faglflext-hsl04 + ls_faglflext-hsl05 + ls_faglflext-hsl06 + ls_faglflext-hsl07 + ls_faglflext-hsl08 + ls_faglflext-hsl09 + ls_faglflext-hsl10.
* ENDIF.
* ELSEIF s_poper-low = '011'.
* IF ls_faglflext-drcrk = 'S'. "本年累计借方(本币)
* gs_output-hsly1 = ls_faglflext-hsl01 + ls_faglflext-hsl02 + ls_faglflext-hsl03 + ls_faglflext-hsl04 + ls_faglflext-hsl05 + ls_faglflext-hsl06 + ls_faglflext-hsl07 + ls_faglflext-hsl08 + ls_faglflext-hsl09 + ls_faglflext-hsl10 +
*ls_faglflext-hsl11.
* ELSEIF ls_faglflext-drcrk = 'H'. "本年累计贷方(本币)
* gs_output-hsly2 = ls_faglflext-hsl01 + ls_faglflext-hsl02 + ls_faglflext-hsl03 + ls_faglflext-hsl04 + ls_faglflext-hsl05 + ls_faglflext-hsl06 + ls_faglflext-hsl07 + ls_faglflext-hsl08 + ls_faglflext-hsl09 + ls_faglflext-hsl10 +
*ls_faglflext-hsl11.
* ENDIF.
* ELSEIF s_poper-low = '012'.
* IF ls_faglflext-drcrk = 'S'. "本年累计借方(本币)
* gs_output-hsly1 = ls_faglflext-hsl01 + ls_faglflext-hsl02 + ls_faglflext-hsl03 + ls_faglflext-hsl04 + ls_faglflext-hsl05 + ls_faglflext-hsl06 + ls_faglflext-hsl07 + ls_faglflext-hsl08 + ls_faglflext-hsl09 + ls_faglflext-hsl10 +
*ls_faglflext-hsl11 + ls_faglflext-hsl12.
* ELSEIF ls_faglflext-drcrk = 'H'. "本年累计贷方(本币)
* gs_output-hsly2 = ls_faglflext-hsl01 + ls_faglflext-hsl02 + ls_faglflext-hsl03 + ls_faglflext-hsl04 + ls_faglflext-hsl05 + ls_faglflext-hsl06 + ls_faglflext-hsl07 + ls_faglflext-hsl08 + ls_faglflext-hsl09 + ls_faglflext-hsl10 +
*ls_faglflext-hsl11 + ls_faglflext-hsl12.
* ENDIF.
* ENDIF.
IF s_poper-low = '001'.
gs_output-hslz1 = ls_faglflext-hsl01. "本位币中的期间的业务总计
ELSEIF s_poper-low = '002'.
gs_output-hslz1 = ls_faglflext-hsl02. "本位币中的期间的业务总计
ELSEIF s_poper-low = '003'.
gs_output-hslz1 = ls_faglflext-hsl03. "本位币中的期间的业务总计
ELSEIF s_poper-low = '004'.
gs_output-hslz1 = ls_faglflext-hsl04. "本位币中的期间的业务总计
ELSEIF s_poper-low = '005'.
gs_output-hslz1 = ls_faglflext-hsl05. "本位币中的期间的业务总计
ELSEIF s_poper-low = '006'.
gs_output-hslz1 = ls_faglflext-hsl06. "本位币中的期间的业务总计
ELSEIF s_poper-low = '007'.
gs_output-hslz1 = ls_faglflext-hsl07. "本位币中的期间的业务总计
ELSEIF s_poper-low = '008'.
gs_output-hslz1 = ls_faglflext-hsl08. "本位币中的期间的业务总计
ELSEIF s_poper-low = '009'.
gs_output-hslz1 = ls_faglflext-hsl09. "本位币中的期间的业务总计
ELSEIF s_poper-low = '010'.
gs_output-hslz1 = ls_faglflext-hsl10. "本位币中的期间的业务总计
ELSEIF s_poper-low = '011'.
gs_output-hslz1 = ls_faglflext-hsl11. "本位币中的期间的业务总计
ELSEIF s_poper-low = '012'.
gs_output-hslz1 = ls_faglflext-hsl12. "本位币中的期间的业务总计
ENDIF.
* " 只取科目= 8 开头的科目,
* " 1. 运输费、报关费、且功能范围=5000
* " 2. 运输费、报关费、且功能范围=3000 、且 成本中心含 "营运部"
* " 3. 仓储费、且功能范围=5000 、4000、3000
* IF ( GS_OUTPUT-RFAREA = '5000' AND ( GS_OUTPUT-TXT50 CP '*运输费*' OR GS_OUTPUT-TXT50 CP '*报关费*' ) ) OR ( ( GS_OUTPUT-RFAREA = '3000' OR GS_OUTPUT-RFAREA = '4000' OR GS_OUTPUT-RFAREA =
*'5000' ) AND GS_OUTPUT-TXT50 CP '*仓储费*' ) OR ( ( GS_OUTPUT-RFAREA = '3000') AND ( GS_OUTPUT-TXT50 CP '*运输费*' OR GS_OUTPUT-TXT50 CP '*报关费*' ) AND GS_OUTPUT-KTEXT CP '*营运部*' )
* OR ( ( GS_OUTPUT-RFAREA = '3000') AND ( GS_OUTPUT-TXT50 CP '*运输费*' OR GS_OUTPUT-TXT50 CP '*报关费*' ) AND gs_output-rbukrs IN gr_bukrs ) ."Add By IT065 At 20240322 For 袁志琴 新增加海外业务逻辑
COLLECT gs_output INTO gt_output.
* ENDIF.
CLEAR: ls_faglflext, gs_output.
ENDLOOP.
CLEAR: lv_faglflext.
num = 0.
SORT gt_output BY rcntr.
CLEAR: ls_data, lt_data[].
SORT lt_bseg1 BY bukrs hkont kostl gsber fkber prctr.""gjahr monat 公司 会计科目 成本中心 业务范围 功能范围 利润中心
SORT lt_bseg2 BY bukrs hkont kostl gsber fkber prctr.
LOOP AT gt_output INTO gs_output .
ls_data-ryear = gs_output-ryear.
ls_data-rpmax = s_poper-low. "GS_OUTPUT-RPMAX.
ls_data-bukrs = gs_output-rbukrs.
ls_data-racct = gs_output-racct.
ls_data-txt50 = gs_output-txt50.
ls_data-rcntr = gs_output-rcntr.
ls_data-ktext = gs_output-ktext. "成本中心名称
ls_data-rbusa = gs_output-rbusa. "业务范围
ls_data-gtext = gs_output-gtext. "业务范围名称
ls_data-rfarea = gs_output-rfarea. "功能范围
ls_data-fkbtx = gs_output-fkbtx. "功能范围名称
ls_data-prctr = gs_output-prctr. "利润中心
ls_data-rtcur = gs_output-rtcur. "币别
ls_data-bhsly1 = gs_output-hsly1. "本年累计借方(本币)
ls_data-bhsly2 = gs_output-hsly2. "本年累计货方(本币)
ls_data-bhslz1 = gs_output-hslz1. "调整金额(本币)
"公司名称
SELECT SINGLE butxt INTO ls_data-butxt
FROM t001 WHERE bukrs = gs_output-rbukrs.
CLEAR ls_bseg.
READ TABLE lt_bseg1 INTO ls_bseg WITH KEY bukrs = ls_data-bukrs hkont = ls_data-racct kostl = ls_data-rcntr
gsber = ls_data-rbusa fkber = ls_data-rfarea prctr = ls_data-prctr
BINARY SEARCH.
IF sy-subrc EQ 0.
ls_bseg-hslz1 = ls_bseg-hsly1 + ls_bseg-hsly2.
IF ls_bseg-hslz1 EQ ls_data-bhslz1.
* IF ls_bseg-hsly1 EQ ls_data-bhsly1 AND ls_bseg-hsly2 EQ ls_data-bhsly2.
LOOP AT lt_bseg2 INTO DATA(lv_bseg) WHERE bukrs = ls_data-bukrs AND hkont = ls_data-racct AND kostl = ls_data-rcntr
AND gsber = ls_data-rbusa AND fkber = ls_data-rfarea AND prctr = ls_data-prctr.
ls_data-werks = lv_bseg-werks.
"对方科目 / 对方科目名称 取自建表SKA1-SAKNR(取640开头)
SELECT SINGLE * INTO @DATA(ls_ztfi113)
FROM ztfi113 WHERE bukrs = @lv_bseg-bukrs AND werks = @lv_bseg-werks AND gsber = @gs_output-rbusa.
IF sy-subrc NE 0.
SELECT SINGLE * INTO @ls_ztfi113 FROM ztfi113 WHERE bukrs = @lv_bseg-bukrs AND gsber = @gs_output-rbusa.
ENDIF.
ls_data-saknr = ls_ztfi113-saknr.
IF ls_data-rbusa IS INITIAL.
ls_data-rbusa = ls_ztfi113-gsber.
ENDIF.
IF sy-langu EQ 'E'.
SELECT SINGLE skat~txt50 INTO ls_data-txt50s FROM skat
WHERE skat~saknr = ls_data-saknr AND skat~ktopl = 'OCOA' AND skat~spras = sy-langu.
ELSE.
SELECT SINGLE skat~txt50 INTO ls_data-txt50s FROM skat
WHERE skat~saknr = ls_data-saknr AND skat~ktopl = 'LY00' AND skat~spras = sy-langu.
ENDIF.
ls_data-hsly1 = lv_bseg-hsly1.
ls_data-hsly2 = lv_bseg-hsly2.
IF ls_data-saknr IS INITIAL.
num = num + 1.
ls_data-belnr1 = num.
ls_data-icon = gc_icon_red.
ls_data-message = '未获取到对方科目'.
APPEND ls_data TO lt_data.
ELSE.
ls_data-hslz1 = lv_bseg-hsly1 + lv_bseg-hsly2..
IF ls_data-hslz1 <> 0.
num = num + 1.
ls_data-belnr1 = num. "分录
APPEND ls_data TO lt_data.
* ELSE.
* num = num + 1.
* ls_data-belnr1 = num.
* ls_data-icon = gc_icon_red.
* ls_data-message = 'BSEG未获取到明细项'.
* APPEND ls_data TO lt_data.
ENDIF.
ENDIF.
ENDLOOP.
* ELSE.
* num = num + 1.
* ls_data-belnr1 = num.
* ls_data-icon = gc_icon_red.
* ls_data-message = 'BSEG未获取到明细项'.
* APPEND ls_data TO lt_data.
ENDIF.
* ELSE.
* num = num + 1.
* ls_data-belnr1 = num.
* ls_data-icon = gc_icon_red.
* ls_data-message = 'BSEG未获取到明细项'.
* APPEND ls_data TO lt_data.
ENDIF.
CLEAR ls_data.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_DOUBLE_CLICK 双击事件
*&---------------------------------------------------------------------*
FORM frm_double_click USING p_row_id TYPE lvc_s_row
p_column_i TYPE lvc_s_col.
IF p_column_i-fieldname EQ 'RFAREA'.
READ TABLE lt_data INTO ls_data INDEX p_row_id-index.
IF sy-subrc = 0 .
SET PARAMETER ID 'ACC' FIELD ls_data-racct.
SET PARAMETER ID 'BUK' FIELD ls_data-bukrs.
SET PARAMETER ID 'GJR' FIELD ls_data-ryear.
CALL TRANSACTION 'FAGLB03' AND SKIP FIRST SCREEN.
ENDIF.
ELSEIF p_column_i-fieldname EQ 'BELNR'.
READ TABLE lt_data INTO ls_data INDEX p_row_id-index.
IF sy-subrc = 0 AND ls_data-belnr IS NOT INITIAL.
SET PARAMETER ID 'BLN' FIELD ls_data-belnr.
SET PARAMETER ID 'BUK' FIELD ls_data-bukrs.
SET PARAMETER ID 'GJR' FIELD ls_data-ryear.
CALL TRANSACTION 'FB03' AND SKIP FIRST SCREEN.
ENDIF.
ENDIF.
ENDFORM.
工厂 | 币别(本币) | 本月累计借方(本币) | 本月累计贷方(本币) | 余额 | 对方科目 | 对方科目名称 | 会计凭证 | 提示信息 |
T001W-WERKS | BSEG-H_HWAER | 取值;当RCRK=S,FAGLFLEXT-HSL01(如1月取HSL01) | 取值;当RCRK=H,FAGLFLEXT-HSL01... | 计算 | FAGLFLEXT-RACCT | SKAT-TXT50 | BKPF-BELNR | |
当T001W-WERKS=BSEG-WERKS,取BSEG-WERKS | 取BSEG-H_HWAER | 查表:内表TB条件:DRCRK=S 取值:如果过滤界面是1月份,取HSL01 | 查表:内表TB条件:DRCRK=H 取值:如果过滤界面是1月份,取HSL01 | 余额=本年累计借方+本年累计贷方,金额为0的则不取 | 根据自建表对应关系,工厂=自建表T001W-WERKS,取自建表SKA1-SAKNR | 根据自建表对应关系:当SKA1-SAKNR=SKAT-SAKNR,取SKAT-TXT50 | BKPF-BELNR=点击过账自动生成凭证编码 | 若是当月凭证已生成,再次点击过账,出现报错:当月凭证已生成,不可以再次过账。(当月生成凭证编码之后,不可以再次操作,按月仅可以操作一次) |
总分类帐名称 | 文本 | 金额 | 功能范围 | 成本中心 | 业务范围 | 利润中心 | 工厂 | 凭证类型 |
SKAT-TXT50 | BSEG-SGTXT | BSEG-FKBER | FAGLFLEXT-RCNTR | FAGLFLEXT-RBUSA | FAGLFLEXT-PRCTR | BSEG-WERKS | BKPF-BLART | |
展示模板对方科目名称SKAT-TXT50 | BSEG-SGTXT=X年X月期末结转差异科目到主营业务成本 | 展示模板的余额 | FAGLFLEXT-RFAREA=BSEG-FKBER | 展示模板科目=FAGLFLEXT-RACCT(科目),取FAGLFLEXT-RCNTR | 展示模板对方科目=FAGLFLEXT-RACCT(科目),取自建表维护工厂对应的业务范围 | FAGLFLEXT-RACCT(科目),取FAGLFLEXT-PRCTR | BSEG-WERKS | BKPF-BLART=SA |