SAP_ABAP_选择屏幕的DIV布局功能实现步骤 && SAP资产负债表的实现步骤

2023-12-28 14:25:02

1 实现效果:

2 代码实现片段:

INITIALIZATION.
  l_txt =
  '资产:' && cl_abap_char_utilities=>cr_lf &&
  '  流动资产:' && cl_abap_char_utilities=>cr_lf &&
  '    货币资金:1001*+1002*+1012*+1132*' && cl_abap_char_utilities=>cr_lf &&
  '    交易性金融资产:1101*' && cl_abap_char_utilities=>cr_lf &&
  '    衍生金融资产:' && cl_abap_char_utilities=>cr_lf &&
  '    应收票据:' && cl_abap_char_utilities=>cr_lf &&
  '    应收账款:1122*(排除1122040000科目)+ 123101*' && cl_abap_char_utilities=>cr_lf &&
  '    应收款项融资:1121*' && cl_abap_char_utilities=>cr_lf &&
  '    预付款项:1124*+1803030000+1803040000+1803050000' && cl_abap_char_utilities=>cr_lf &&
  '    其他应收款:1221*+123102*+1131*' && cl_abap_char_utilities=>cr_lf &&
  '    存货:1401*+1403*+1404*+1405*+1406*+1407*+1408*+1410*+1411*+1471*' && cl_abap_char_utilities=>cr_lf &&
  '    合同资产:1462*+123103*' && cl_abap_char_utilities=>cr_lf &&
  '    持有待售资产:1481*+1482*' && cl_abap_char_utilities=>cr_lf &&
  '    一年内到期的非流动资产:' && cl_abap_char_utilities=>cr_lf &&
  '    其他流动资产:1905*+ 1122040000 ' && cl_abap_char_utilities=>cr_lf &&
  '  非流动资产:' && cl_abap_char_utilities=>cr_lf &&
  '    债权投资:1501*+1502*' && cl_abap_char_utilities=>cr_lf &&
  '    其他债权投资:1503*' && cl_abap_char_utilities=>cr_lf &&
  '    长期应收款:1531*+123104*' && cl_abap_char_utilities=>cr_lf &&
  '    长期股权投资:1511*+1512*' && cl_abap_char_utilities=>cr_lf &&
  '    其他权益工具投资:1504*' && cl_abap_char_utilities=>cr_lf &&
  '    其他非流动金融资产:1533*' && cl_abap_char_utilities=>cr_lf &&
  '    投资性房地产:1521*+1522*+1523*' && cl_abap_char_utilities=>cr_lf &&
  '    固定资产:1601*+1602*+1603*+1608*' && cl_abap_char_utilities=>cr_lf &&
  '    在建工程:1604*+1605*' && cl_abap_char_utilities=>cr_lf &&
  '    生产性生物资产:' && cl_abap_char_utilities=>cr_lf &&
  '    油气资产:' && cl_abap_char_utilities=>cr_lf &&
  '    使用权资产:1902*+1903*+1904*' && cl_abap_char_utilities=>cr_lf &&
  '    无形资产:1701*+1702*+1703*' && cl_abap_char_utilities=>cr_lf &&
  '    开发支出:1704*+1705*' && cl_abap_char_utilities=>cr_lf &&
  '    商誉:' && cl_abap_char_utilities=>cr_lf &&
  '    长期待摊费用:1801*+1802*+1803010000+1803020000' && cl_abap_char_utilities=>cr_lf &&
  '    递延所得税资产:1811*' && cl_abap_char_utilities=>cr_lf &&
  '    其他非流动资产:'.


  r_txt =
  '负债和所有者权益:(科目余额需做正负号转换)'&& cl_abap_char_utilities=>cr_lf &&
  '  流动负债:' && cl_abap_char_utilities=>cr_lf &&
  '    短期借款:2001*' && cl_abap_char_utilities=>cr_lf &&
  '    交易性金融负债:2101*' && cl_abap_char_utilities=>cr_lf &&
  '    衍生金融负债:2111*' && cl_abap_char_utilities=>cr_lf &&
  '    应付票据:2201*' && cl_abap_char_utilities=>cr_lf &&
  '    应付账款:2202*' && cl_abap_char_utilities=>cr_lf &&
  '    预收款项:2203*' && cl_abap_char_utilities=>cr_lf &&
  '    合同负债:2204*' && cl_abap_char_utilities=>cr_lf &&
  '    应付职工薪酬:2211*' && cl_abap_char_utilities=>cr_lf &&
  '    应交税费:2221*' && cl_abap_char_utilities=>cr_lf &&
  '    其他应付款:2241*+2232*' && cl_abap_char_utilities=>cr_lf &&
  '    持有待售负债:2301*' && cl_abap_char_utilities=>cr_lf &&
  '    一年内到期的非流动负债:250102*' && cl_abap_char_utilities=>cr_lf &&
  '    其他流动负债:' && cl_abap_char_utilities=>cr_lf &&
  '  非流动负债:' && cl_abap_char_utilities=>cr_lf &&
  '    长期借款:2501*(排除250102*科目)' && cl_abap_char_utilities=>cr_lf &&
  '    应付债券:2502*' && cl_abap_char_utilities=>cr_lf &&
  '    其中:优先股:' && cl_abap_char_utilities=>cr_lf &&
  '             永续债:' && cl_abap_char_utilities=>cr_lf &&
  '    租赁负债:2601*' && cl_abap_char_utilities=>cr_lf &&
  '    长期应付款:2701*+2702*+2711*' && cl_abap_char_utilities=>cr_lf &&
  '    预计负债:2801*' && cl_abap_char_utilities=>cr_lf &&
  '    递延收益:2401*' && cl_abap_char_utilities=>cr_lf &&
  '    递延所得税负债:2901*' && cl_abap_char_utilities=>cr_lf &&
  '    其他非流动负债:' && cl_abap_char_utilities=>cr_lf &&
  '  所有者权益:' && cl_abap_char_utilities=>cr_lf &&
  '    实收资本(或股本):4001*' && cl_abap_char_utilities=>cr_lf &&
  '    其他权益工具:' && cl_abap_char_utilities=>cr_lf &&
  '    其中:优先股:' && cl_abap_char_utilities=>cr_lf &&
  '             永续债:' && cl_abap_char_utilities=>cr_lf &&
  '    资本公积:4002*' && cl_abap_char_utilities=>cr_lf &&
  '    减:库存股:4201*' && cl_abap_char_utilities=>cr_lf &&
  '    其他综合收益:4003*' && cl_abap_char_utilities=>cr_lf &&
  '    专项储备:4301*' && cl_abap_char_utilities=>cr_lf &&
  '    盈余公积:4101*' && cl_abap_char_utilities=>cr_lf &&
  '    未分配利润:4103*+4104*+6001*+6051*+(6401*+6403*+6404*)+66*(功能范围Z200)+66*(功能范围Z100)+66*(功能范围Z500)+6604*+6302*+6111*+6101*+6701*+6702*+6703*+6301*+6711*+6801*' && cl_abap_char_utilities=>cr_lf &&
  '另:' && cl_abap_char_utilities=>cr_lf &&
  '1)如果选择屏幕期间选择12,则“期末余额”排除了13-16期间的数据;' && cl_abap_char_utilities=>cr_lf &&
  '2)如果选择屏幕期间选择12,且勾选“审计重分类”,则报表中“期末余额”会加上13-16期间的数据;' && cl_abap_char_utilities=>cr_lf .
* &&'3)如果选择屏幕“单位”选择“千元”,则报表数据会在以“元”计算的基础上除以1000体现。'.
  .

AT SELECTION-SCREEN OUTPUT.
  g_repid  = sy-repid.
  IF go_docking IS INITIAL.
    "创建容器对象
    CREATE OBJECT go_docking
      EXPORTING
        repid                       = g_repid
        dynnr                       = sy-dynnr
        side                        = cl_gui_docking_container=>dock_at_bottom " 容器固定在底部
        extension                   = '200' "高度,
      EXCEPTIONS
        cntl_error                  = 1
        cntl_system_error           = 2
        create_error                = 3
        lifetime_error              = 4
        lifetime_dynpro_dynpro_link = 5.
  ENDIF.
  "拆分为左、右,即一行2列
  CREATE OBJECT go_splitter_con
    EXPORTING
      parent  = go_docking
      rows    = 1
      columns = 2.
  "取得左边子容器----------------------------------------
  CALL METHOD go_splitter_con->get_container
    EXPORTING
      row       = 1
      column    = 1
    RECEIVING
      container = go_sub_go_docking_l.
  "创建左文本框
  IF go_editor_l IS INITIAL.
    CREATE OBJECT go_editor_l
      EXPORTING
        parent            = go_sub_go_docking_l
        wordwrap_mode     = cl_gui_textedit=>wordwrap_at_windowborder "WORDWRAP_AT_FIXED_POSITION "边框模式,设置为0可以去掉编辑框的滚动条 设置为2可以自动换行 WORDWRAP_AT_WINDOWBORDER"
        wordwrap_position = 77   "换行宽度
        max_number_chars  = 10000. "最大文本数
  ENDIF.
  go_editor_l->set_toolbar_mode( 0 )."工具栏不可见
  go_editor_l->set_readonly_mode( 1 )."文本框不可见
  "对文本框赋值

  PERFORM frm_set_text USING go_editor_l   l_txt.
  "取得右边子容器--------------------------------------
  CALL METHOD go_splitter_con->get_container
    EXPORTING
      row       = 1
      column    = 2
    RECEIVING
      container = go_sub_go_docking_r.
  "创建右文本框
  IF go_editor_r IS INITIAL.
    CREATE OBJECT go_editor_r
      EXPORTING
        parent            = go_sub_go_docking_r
        wordwrap_mode     = cl_gui_textedit=>wordwrap_at_windowborder "WORDWRAP_AT_FIXED_POSITION "边框模式,设置为0可以去掉编辑框的滚动条 设置为2可以自动换行
        wordwrap_position = 77   "换行宽度
        max_number_chars  = 10000. "最大文本数
  ENDIF.
  go_editor_r->set_toolbar_mode( 0 )."工具栏不可见
  go_editor_r->set_readonly_mode( 1 )."文本框不可见
  "对文本框赋值
  PERFORM frm_set_text USING go_editor_r   r_txt.

3 .? 资产负责表的功能代码:

*&---------------------------------------------------------------------*
*& Report ZFIDG005
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
REPORT zfico06.

TABLES: faglflext.

TYPES: BEGIN OF typ_fag,
         rbukrs TYPE faglflext-rbukrs, "公司代码
         ryear  TYPE faglflext-ryear,  "财年
         racct  TYPE faglflext-racct,  "科目号
         rpmax  TYPE faglflext-rpmax,  "期间
         drcrk  TYPE faglflext-drcrk,  "借方/贷方标识
         hslvt  TYPE faglflext-hslvt,
         hsl01  TYPE faglflext-hsl01,
         hsl02  TYPE faglflext-hsl02,
         hsl03  TYPE faglflext-hsl03,
         hsl04  TYPE faglflext-hsl04,
         hsl05  TYPE faglflext-hsl05,
         hsl06  TYPE faglflext-hsl06,
         hsl07  TYPE faglflext-hsl07,
         hsl08  TYPE faglflext-hsl08,
         hsl09  TYPE faglflext-hsl09,
         hsl10  TYPE faglflext-hsl10,
         hsl11  TYPE faglflext-hsl11,
         hsl12  TYPE faglflext-hsl12,
         hsl13  TYPE faglflext-hsl13,
         hsl14  TYPE faglflext-hsl14,
         hsl15  TYPE faglflext-hsl15,
         hsl16  TYPE faglflext-hsl16,
         rfarea TYPE faglflext-rfarea,
       END OF typ_fag.

TYPES: BEGIN OF typ_alv,
         sel,
         zxh         TYPE int4,
         asset       TYPE char30,
         asset_qc    TYPE char16,
         asset_qm    TYPE char16,
         debt        TYPE char30,
         debt_qc     TYPE char16,
         debt_qm     TYPE char16,
         field_color TYPE lvc_t_scol.
TYPES: END OF typ_alv.

DATA: gt_alv  TYPE TABLE OF typ_alv,
      gs_alv  TYPE typ_alv,
      gs_layo TYPE lvc_s_layo,
      gs_fcat TYPE lvc_s_fcat,
      gt_fcat TYPE lvc_t_fcat.
DATA: gt_fag TYPE TABLE OF typ_fag,
      gs_fag TYPE typ_fag.

DATA: ls_color TYPE lvc_s_scol.

RANGES: lr_hkont       FOR faglflext-racct,
        lr_minus_racct FOR faglflext-racct,
        lr_minus_racct2 FOR faglflext-racct.   "ADD BY HXM 20180118


DATA: lv_last_day TYPE sy-datum,
      lv_butxt    TYPE t001-butxt,
      lv_day_txt  TYPE string,
      lv_hsl_txt  TYPE string.

DATA: lv_fa_c    TYPE char16, "流动资产合计 期初
      lv_fa_m    TYPE char16, "流动资产合计 期末
      lv_fd_c    TYPE char16, "流动负债合计 期初
      lv_fd_m    TYPE char16, "流动负债合计 期末
      lv_nfa_c   TYPE char16, "非流动资产合计 期初
      lv_nfa_m   TYPE char16, "非流动资产合计 期末
      lv_nfd_c   TYPE char16, "非流动负债合计 期初
      lv_nfd_m   TYPE char16, "非流动负债合计 期末
      lv_eq_c    TYPE char16, "股东权益合计 期初
      lv_eq_m    TYPE char16, "股东权益合计 期末
      lv_eq_c_fh TYPE char16, "未分配利润符号计算 期初
      lv_eq_m_fh TYPE char16. "未分配利润符号计算 期末


DATA: lv_inventory,             "未分配利润标识
      lv_fa_c_ivty TYPE char16, "未分配利润-期初余额
      lv_fa_m_ivty TYPE char16. "未分配利润-期末余额
DATA: before_wfplr_fh_qc(1) TYPE c."qc除未分配利润以外的其他所有者权益符号 - +
DATA: before_wfplr_fh_qm(1) TYPE c."qm除未分配利润以外的其他所有者权益符号 - +
DATA: gt_val TYPE vrm_values,
      gs_val TYPE vrm_value.

INCLUDE ole2incl.
DATA: application TYPE ole2_object,       "excel object
      excel       TYPE ole2_object,
      workbook    TYPE ole2_object,       "excel workbook objcet
      sheet       TYPE ole2_object,       "workbook sheet object
      columns     TYPE ole2_object,       "sheet col objcet
*      rows        TYPE ole2_object,       "sheet row objcet
      range       TYPE ole2_object,       "range
      font        TYPE ole2_object,       "font
      cells       TYPE ole2_object,       "cell
      borders     TYPE ole2_object,       "borders
      interior    TYPE ole2_object.
DATA:lv_filename TYPE string,
     lv_path     TYPE string,
     lv_fullpath TYPE string.

DATA:lv_shsl TYPE zacdoca-hsl,
     lv_hhsl TYPE zacdoca-hsl.
"ADD BY HUANGXMA 20190318
DATA:lt_zacdoca TYPE TABLE OF zacdoca,
     ls_zacdoca TYPE zacdoca.
DATA:lt_zacdoca1 TYPE TABLE OF zacdoca,
     ls_zacdoca1 TYPE zacdoca.
RANGES: r_zclassify FOR zacdoca-zclassify. "重分类类别
DATA:lastyear TYPE gjahr.

**begin 20200420 **********************************************
DATA: g_repid TYPE sy-repid.
DATA: go_docking          TYPE REF TO cl_gui_docking_container, "容器
      go_splitter_con     TYPE REF TO cl_gui_splitter_container, "分割容器
      go_sub_go_docking_l TYPE REF TO cl_gui_container, "左边子容器
      go_sub_go_docking_r TYPE REF TO cl_gui_container, "右边子容器
      go_editor_l         TYPE REF TO cl_gui_textedit, "左边文本框
      go_editor_r         TYPE REF TO cl_gui_textedit. "右边文本框
DATA: l_txt TYPE string,r_txt TYPE string.

**end 20200420*************************************************

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-099 .
  PARAMETERS: p_rbukrs TYPE faglflext-rbukrs OBLIGATORY , "公司代码
              p_ryear  TYPE faglflext-ryear  OBLIGATORY , "年度
              p_rpmax  TYPE faglflext-rpmax  OBLIGATORY.  "期间
*
*  PARAMETERS: p_hsl TYPE char4 AS LISTBOX VISIBLE LENGTH 6 DEFAULT 'A'.
  PARAMETERS:p_reass TYPE c AS CHECKBOX DEFAULT ''."审计调整
**begin 20200420 **********************************************
  SELECTION-SCREEN BEGIN OF LINE .
    SELECTION-SCREEN COMMENT (79)    TEXT-001.
  SELECTION-SCREEN END OF LINE.
  SELECTION-SCREEN BEGIN OF LINE .
    SELECTION-SCREEN COMMENT (79)    TEXT-002.
  SELECTION-SCREEN END OF LINE.
  SELECTION-SCREEN BEGIN OF LINE .
    SELECTION-SCREEN COMMENT (79)    TEXT-003.
  SELECTION-SCREEN END OF LINE.
**end 20200420*****************************************************
SELECTION-SCREEN END OF BLOCK b1.
**begin 20200420 **********************************************
INITIALIZATION.
  l_txt =
  '资产:' && cl_abap_char_utilities=>cr_lf &&
  '  流动资产:' && cl_abap_char_utilities=>cr_lf &&
  '    货币资金:1001*+1002*+1012*+1132*' && cl_abap_char_utilities=>cr_lf &&
  '    交易性金融资产:1101*' && cl_abap_char_utilities=>cr_lf &&
  '    衍生金融资产:' && cl_abap_char_utilities=>cr_lf &&
  '    应收票据:' && cl_abap_char_utilities=>cr_lf &&
  '    应收账款:1122*(排除1122040000科目)+ 123101*' && cl_abap_char_utilities=>cr_lf &&
  '    应收款项融资:1121*' && cl_abap_char_utilities=>cr_lf &&
  '    预付款项:1124*+1803030000+1803040000+1803050000' && cl_abap_char_utilities=>cr_lf &&
  '    其他应收款:1221*+123102*+1131*' && cl_abap_char_utilities=>cr_lf &&
  '    存货:1401*+1403*+1404*+1405*+1406*+1407*+1408*+1410*+1411*+1471*' && cl_abap_char_utilities=>cr_lf &&
  '    合同资产:1462*+123103*' && cl_abap_char_utilities=>cr_lf &&
  '    持有待售资产:1481*+1482*' && cl_abap_char_utilities=>cr_lf &&
  '    一年内到期的非流动资产:' && cl_abap_char_utilities=>cr_lf &&
  '    其他流动资产:1905*+ 1122040000 ' && cl_abap_char_utilities=>cr_lf &&
  '  非流动资产:' && cl_abap_char_utilities=>cr_lf &&
  '    债权投资:1501*+1502*' && cl_abap_char_utilities=>cr_lf &&
  '    其他债权投资:1503*' && cl_abap_char_utilities=>cr_lf &&
  '    长期应收款:1531*+123104*' && cl_abap_char_utilities=>cr_lf &&
  '    长期股权投资:1511*+1512*' && cl_abap_char_utilities=>cr_lf &&
  '    其他权益工具投资:1504*' && cl_abap_char_utilities=>cr_lf &&
  '    其他非流动金融资产:1533*' && cl_abap_char_utilities=>cr_lf &&
  '    投资性房地产:1521*+1522*+1523*' && cl_abap_char_utilities=>cr_lf &&
  '    固定资产:1601*+1602*+1603*+1608*' && cl_abap_char_utilities=>cr_lf &&
  '    在建工程:1604*+1605*' && cl_abap_char_utilities=>cr_lf &&
  '    生产性生物资产:' && cl_abap_char_utilities=>cr_lf &&
  '    油气资产:' && cl_abap_char_utilities=>cr_lf &&
  '    使用权资产:1902*+1903*+1904*' && cl_abap_char_utilities=>cr_lf &&
  '    无形资产:1701*+1702*+1703*' && cl_abap_char_utilities=>cr_lf &&
  '    开发支出:1704*+1705*' && cl_abap_char_utilities=>cr_lf &&
  '    商誉:' && cl_abap_char_utilities=>cr_lf &&
  '    长期待摊费用:1801*+1802*+1803010000+1803020000' && cl_abap_char_utilities=>cr_lf &&
  '    递延所得税资产:1811*' && cl_abap_char_utilities=>cr_lf &&
  '    其他非流动资产:'.


  r_txt =
  '负债和所有者权益:(科目余额需做正负号转换)'&& cl_abap_char_utilities=>cr_lf &&
  '  流动负债:' && cl_abap_char_utilities=>cr_lf &&
  '    短期借款:2001*' && cl_abap_char_utilities=>cr_lf &&
  '    交易性金融负债:2101*' && cl_abap_char_utilities=>cr_lf &&
  '    衍生金融负债:2111*' && cl_abap_char_utilities=>cr_lf &&
  '    应付票据:2201*' && cl_abap_char_utilities=>cr_lf &&
  '    应付账款:2202*' && cl_abap_char_utilities=>cr_lf &&
  '    预收款项:2203*' && cl_abap_char_utilities=>cr_lf &&
  '    合同负债:2204*' && cl_abap_char_utilities=>cr_lf &&
  '    应付职工薪酬:2211*' && cl_abap_char_utilities=>cr_lf &&
  '    应交税费:2221*' && cl_abap_char_utilities=>cr_lf &&
  '    其他应付款:2241*+2232*' && cl_abap_char_utilities=>cr_lf &&
  '    持有待售负债:2301*' && cl_abap_char_utilities=>cr_lf &&
  '    一年内到期的非流动负债:250102*' && cl_abap_char_utilities=>cr_lf &&
  '    其他流动负债:' && cl_abap_char_utilities=>cr_lf &&
  '  非流动负债:' && cl_abap_char_utilities=>cr_lf &&
  '    长期借款:2501*(排除250102*科目)' && cl_abap_char_utilities=>cr_lf &&
  '    应付债券:2502*' && cl_abap_char_utilities=>cr_lf &&
  '    其中:优先股:' && cl_abap_char_utilities=>cr_lf &&
  '             永续债:' && cl_abap_char_utilities=>cr_lf &&
  '    租赁负债:2601*' && cl_abap_char_utilities=>cr_lf &&
  '    长期应付款:2701*+2702*+2711*' && cl_abap_char_utilities=>cr_lf &&
  '    预计负债:2801*' && cl_abap_char_utilities=>cr_lf &&
  '    递延收益:2401*' && cl_abap_char_utilities=>cr_lf &&
  '    递延所得税负债:2901*' && cl_abap_char_utilities=>cr_lf &&
  '    其他非流动负债:' && cl_abap_char_utilities=>cr_lf &&
  '  所有者权益:' && cl_abap_char_utilities=>cr_lf &&
  '    实收资本(或股本):4001*' && cl_abap_char_utilities=>cr_lf &&
  '    其他权益工具:' && cl_abap_char_utilities=>cr_lf &&
  '    其中:优先股:' && cl_abap_char_utilities=>cr_lf &&
  '             永续债:' && cl_abap_char_utilities=>cr_lf &&
  '    资本公积:4002*' && cl_abap_char_utilities=>cr_lf &&
  '    减:库存股:4201*' && cl_abap_char_utilities=>cr_lf &&
  '    其他综合收益:4003*' && cl_abap_char_utilities=>cr_lf &&
  '    专项储备:4301*' && cl_abap_char_utilities=>cr_lf &&
  '    盈余公积:4101*' && cl_abap_char_utilities=>cr_lf &&
  '    未分配利润:4103*+4104*+6001*+6051*+(6401*+6403*+6404*)+66*(功能范围Z200)+66*(功能范围Z100)+66*(功能范围Z500)+6604*+6302*+6111*+6101*+6701*+6702*+6703*+6301*+6711*+6801*' && cl_abap_char_utilities=>cr_lf &&
  '另:' && cl_abap_char_utilities=>cr_lf &&
  '1)如果选择屏幕期间选择12,则“期末余额”排除了13-16期间的数据;' && cl_abap_char_utilities=>cr_lf &&
  '2)如果选择屏幕期间选择12,且勾选“审计重分类”,则报表中“期末余额”会加上13-16期间的数据;' && cl_abap_char_utilities=>cr_lf .
* &&'3)如果选择屏幕“单位”选择“千元”,则报表数据会在以“元”计算的基础上除以1000体现。'.
  .

AT SELECTION-SCREEN OUTPUT.
  g_repid  = sy-repid.
  IF go_docking IS INITIAL.
    "创建容器对象
    CREATE OBJECT go_docking
      EXPORTING
        repid                       = g_repid
        dynnr                       = sy-dynnr
        side                        = cl_gui_docking_container=>dock_at_bottom " 容器固定在底部
        extension                   = '200' "高度,
      EXCEPTIONS
        cntl_error                  = 1
        cntl_system_error           = 2
        create_error                = 3
        lifetime_error              = 4
        lifetime_dynpro_dynpro_link = 5.
  ENDIF.
  "拆分为左、右,即一行2列
  CREATE OBJECT go_splitter_con
    EXPORTING
      parent  = go_docking
      rows    = 1
      columns = 2.
  "取得左边子容器----------------------------------------
  CALL METHOD go_splitter_con->get_container
    EXPORTING
      row       = 1
      column    = 1
    RECEIVING
      container = go_sub_go_docking_l.
  "创建左文本框
  IF go_editor_l IS INITIAL.
    CREATE OBJECT go_editor_l
      EXPORTING
        parent            = go_sub_go_docking_l
        wordwrap_mode     = cl_gui_textedit=>wordwrap_at_windowborder "WORDWRAP_AT_FIXED_POSITION "边框模式,设置为0可以去掉编辑框的滚动条 设置为2可以自动换行 WORDWRAP_AT_WINDOWBORDER"
        wordwrap_position = 77   "换行宽度
        max_number_chars  = 10000. "最大文本数
  ENDIF.
  go_editor_l->set_toolbar_mode( 0 )."工具栏不可见
  go_editor_l->set_readonly_mode( 1 )."文本框不可见
  "对文本框赋值

  PERFORM frm_set_text USING go_editor_l   l_txt.
  "取得右边子容器--------------------------------------
  CALL METHOD go_splitter_con->get_container
    EXPORTING
      row       = 1
      column    = 2
    RECEIVING
      container = go_sub_go_docking_r.
  "创建右文本框
  IF go_editor_r IS INITIAL.
    CREATE OBJECT go_editor_r
      EXPORTING
        parent            = go_sub_go_docking_r
        wordwrap_mode     = cl_gui_textedit=>wordwrap_at_windowborder "WORDWRAP_AT_FIXED_POSITION "边框模式,设置为0可以去掉编辑框的滚动条 设置为2可以自动换行
        wordwrap_position = 77   "换行宽度
        max_number_chars  = 10000. "最大文本数
  ENDIF.
  go_editor_r->set_toolbar_mode( 0 )."工具栏不可见
  go_editor_r->set_readonly_mode( 1 )."文本框不可见
  "对文本框赋值
  PERFORM frm_set_text USING go_editor_r   r_txt.

*AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_hsl.
*  PERFORM frm_set_listbox.

AT SELECTION-SCREEN.
  PERFORM frm_check_data.

START-OF-SELECTION.
  PERFORM frm_init_data.
  PERFORM frm_get_data.
  PERFORM frm_dis_data.

  INCLUDE zfico06_frm.
*  INCLUDE ZFIDG005A_FRM.
*&---------------------------------------------------------------------*
*& Include ZFIDG005_FRM
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*& Form FRM_CHECK_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_check_data .

  SELECT bukrs FROM t001 WHERE bukrs = @p_rbukrs AND spras = 1
  INTO TABLE @DATA(lt_t001).
  IF lt_t001 IS INITIAL.
    MESSAGE '公司代码不存在请检查' TYPE 'E'.
  ENDIF.
  LOOP AT lt_t001 INTO DATA(ls_t001).
    AUTHORITY-CHECK OBJECT 'F_BKPF_BUK'
    ID 'BUKRS' FIELD ls_t001-bukrs
    ID 'ACTVT' FIELD '03'.
    IF sy-subrc <> 0.
      MESSAGE '你没有选择这个公司代码' && ls_t001-bukrs && '的权限' TYPE 'E'.

    ENDIF.

  ENDLOOP.
  IF p_rpmax NOT BETWEEN 01 AND 12.
    MESSAGE '期间值必须在1-12之间' TYPE 'E' DISPLAY LIKE 'S'.
  ENDIF.

*  IF p_hsl IS INITIAL.
*    MESSAGE '请选择具体的单位' TYPE 'E' DISPLAY LIKE 'S'.
*  ENDIF.

*  AUTHORITY-CHECK OBJECT 'F_BKPF_BUK'
*    ID 'BUKRS' FIELD p_rbukrs
*    ID 'ACTVT' FIELD '03'.
*  IF sy-subrc <> 0.
*    MESSAGE '你没有选择这个公司代码的权限' TYPE 'E'.
*  ENDIF.

*  CLEAR:r_zclassify,r_zclassify[].
*  IF p_reass = 'X'. "审计调整
*    r_zclassify-option = 'EQ'.
*    r_zclassify-sign = 'I'.
*    r_zclassify-low = '月度调整'.
*    APPEND r_zclassify.
*
*    r_zclassify-option = 'EQ'.
*    r_zclassify-sign = 'I'.
*    r_zclassify-low = '审计调整'.
*    APPEND r_zclassify.
*  ELSEIF p_reass1 = 'X'."月度调整
*    r_zclassify-option = 'EQ'.
*    r_zclassify-sign = 'I'.
*    r_zclassify-low = '月度调整'.
*    APPEND r_zclassify.
*
*  ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_GET_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_get_data .

  SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_fag
    FROM faglflext
    WHERE rbukrs = p_rbukrs
    AND   ryear  = p_ryear.

*    AND   racct IN lr_hkont.
*    AND   rldnr = p_rldnr.

  SORT gt_fag BY ryear rbukrs racct drcrk rpmax.


  " FA:流动资产  FD:流动负债   NFA:非流动资产   NFD:非流动负债   EQ:所有者权益
  DATA: p_debt_qc  TYPE faglflext-hslvt,
        p_debt_qm  TYPE faglflext-hslvt,
        p_asset_qc TYPE faglflext-hslvt,
        p_asset_qm TYPE faglflext-hslvt.

  PERFORM frm_append_alv USING '流动资产:' '流动负债:' '' '1' CHANGING gs_alv.

  CLEAR: p_asset_qc,p_asset_qm.
  PERFORM frm_get_hslvt USING '1001*' '1002*' '1012*' '' '' 'FA' CHANGING p_asset_qc p_asset_qm.
  gs_alv-asset_qc = gs_alv-asset_qc + p_asset_qc.
  gs_alv-asset_qm = gs_alv-asset_qm + p_asset_qm.

  CLEAR: p_asset_qc,p_asset_qm.
  PERFORM frm_get_hslvt USING '1132*' '' '' '' '' 'FA' CHANGING p_asset_qc p_asset_qm.
  gs_alv-asset_qc = gs_alv-asset_qc + p_asset_qc.
  gs_alv-asset_qm = gs_alv-asset_qm + p_asset_qm.
  CLEAR: p_asset_qc,p_asset_qm.


  PERFORM frm_get_hslvt USING '2001*' '' '' '' '' 'FD' CHANGING gs_alv-debt_qc  gs_alv-debt_qm.
  PERFORM frm_append_alv USING '货币资金' '短期借款' '' '2' CHANGING gs_alv.

  PERFORM frm_get_hslvt USING '1101*' '' '' '' '' 'FA' CHANGING gs_alv-asset_qc gs_alv-asset_qm.
  PERFORM frm_get_hslvt USING '2101*' '' '' '' '' 'FD' CHANGING gs_alv-debt_qc  gs_alv-debt_qm.
  PERFORM frm_append_alv USING '交易性金融资产' '交易性金融负债' '' '3' CHANGING gs_alv.

  PERFORM frm_get_hslvt USING '2111*' '' '' '' '' 'FD' CHANGING gs_alv-debt_qc  gs_alv-debt_qm.
  PERFORM frm_append_alv USING '衍生金融资产' '衍生金融负债' '' '4' CHANGING gs_alv.

  "PERFORM frm_get_hslvt USING '1121*' '' '' '' 'FA' CHANGING gs_alv-asset_qc gs_alv-asset_qm.
  PERFORM frm_get_hslvt USING '2201*' '' '' '' '' 'FD' CHANGING gs_alv-debt_qc  gs_alv-debt_qm.
  PERFORM frm_append_alv USING '应收票据' '应付票据' '' '5' CHANGING gs_alv.

  PERFORM frm_get_hslvt USING '1122*' '' '' '123101*' '' 'FA' CHANGING gs_alv-asset_qc gs_alv-asset_qm.
*  gs_alv-asset_qm = qm1122.
*  gs_alv-asset_qc = qc1122.
*  CLEAR:p_asset_qc,p_asset_qm.
  PERFORM frm_get_hslvt USING '2202*' '' '' '' '' 'FD' CHANGING gs_alv-debt_qc  gs_alv-debt_qm.
  PERFORM frm_append_alv USING '应收账款' '应付账款' '' '6' CHANGING gs_alv.

  PERFORM frm_get_hslvt USING '1121*' '' '' '' '' 'FA' CHANGING gs_alv-asset_qc gs_alv-asset_qm.
  PERFORM frm_get_hslvt USING '2203*' '' '' '' '' 'FD' CHANGING gs_alv-debt_qc  gs_alv-debt_qm.
  PERFORM frm_append_alv USING '应收账款融资' '预收款项' '' '7' CHANGING gs_alv.

  CLEAR: p_asset_qc,p_asset_qm.
  PERFORM frm_get_hslvt USING '1124*' '' '' '' '1803030000' 'FA' CHANGING p_asset_qc p_asset_qm.
  gs_alv-asset_qc = gs_alv-asset_qc + p_asset_qc.
  gs_alv-asset_qm = gs_alv-asset_qm + p_asset_qm.

  CLEAR: p_asset_qc,p_asset_qm.
  PERFORM frm_get_hslvt USING '' '' '' '' '1803040000' 'FA' CHANGING p_asset_qc p_asset_qm.
  gs_alv-asset_qc = gs_alv-asset_qc + p_asset_qc.
  gs_alv-asset_qm = gs_alv-asset_qm + p_asset_qm.
  CLEAR: p_asset_qc,p_asset_qm.

  CLEAR: p_asset_qc,p_asset_qm.
  PERFORM frm_get_hslvt USING '' '' '' '' '1803050000' 'FA' CHANGING p_asset_qc p_asset_qm.
  gs_alv-asset_qc = gs_alv-asset_qc + p_asset_qc.
  gs_alv-asset_qm = gs_alv-asset_qm + p_asset_qm.
  CLEAR: p_asset_qc,p_asset_qm.

  PERFORM frm_get_hslvt USING '2204*' '' '' '' '' 'FD' CHANGING gs_alv-debt_qc  gs_alv-debt_qm."合同负债
  PERFORM frm_append_alv USING '预付款项' '合同负债' '' '8' CHANGING gs_alv.

  PERFORM frm_get_hslvt USING '1221*' '1131*' '' '123102*' '' 'FA' CHANGING gs_alv-asset_qc gs_alv-asset_qm.
  PERFORM frm_get_hslvt USING '2211*' '' '' '' '' 'FD' CHANGING gs_alv-debt_qc  gs_alv-debt_qm.
  PERFORM frm_append_alv USING '其他应收款' '应付职工薪酬' '' '9' CHANGING gs_alv.


* 存货计算
  CLEAR:p_asset_qc,p_asset_qm.
  PERFORM frm_get_hslvt USING '1401*' '1403*' '1404*' '' '' 'FA' CHANGING p_asset_qc p_asset_qm.
  gs_alv-asset_qm = gs_alv-asset_qm + p_asset_qm.
  gs_alv-asset_qc = gs_alv-asset_qc + p_asset_qc.

  CLEAR:p_asset_qc,p_asset_qm.
  PERFORM frm_get_hslvt USING '1405*' '1406*' '1407*' '' '' 'FA' CHANGING p_asset_qc p_asset_qm.
  gs_alv-asset_qm = gs_alv-asset_qm + p_asset_qm.
  gs_alv-asset_qc = gs_alv-asset_qc + p_asset_qc.

  CLEAR:p_asset_qc,p_asset_qm.
  PERFORM frm_get_hslvt USING '1408*' '1410*' '1411*' '' '' 'FA' CHANGING p_asset_qc p_asset_qm.
  gs_alv-asset_qm = gs_alv-asset_qm + p_asset_qm.
  gs_alv-asset_qc = gs_alv-asset_qc + p_asset_qc.

  CLEAR:p_asset_qc,p_asset_qm.
  PERFORM frm_get_hslvt USING '1471*' '' '' '' '' 'FA' CHANGING p_asset_qc p_asset_qm.
  gs_alv-asset_qm = gs_alv-asset_qm + p_asset_qm.
  gs_alv-asset_qc = gs_alv-asset_qc + p_asset_qc.
  CLEAR:p_asset_qc,p_asset_qm.
  PERFORM frm_get_hslvt USING '2221*' '' '' '' '' 'FD' CHANGING gs_alv-debt_qc  gs_alv-debt_qm.
  PERFORM frm_append_alv USING '存货' '应交税费' '' '10' CHANGING gs_alv.
  CLEAR:p_debt_qc,p_debt_qm.

  PERFORM frm_get_hslvt USING '1462*' '' '' '123103*' '' 'FA' CHANGING gs_alv-asset_qc  gs_alv-asset_qm.
  PERFORM frm_get_hslvt USING '2241*' '2232*' '' '' '' 'FD' CHANGING gs_alv-debt_qc  gs_alv-debt_qm.
  PERFORM frm_append_alv USING '合同资产' '其他应付款' '' '11' CHANGING gs_alv.

  PERFORM frm_get_hslvt USING '1481*' '1482*' '' '' '' 'FA' CHANGING gs_alv-asset_qc gs_alv-asset_qm.
  PERFORM frm_get_hslvt USING '2301*' '' '' '' '' 'FD' CHANGING gs_alv-debt_qc  gs_alv-debt_qm.
  PERFORM frm_append_alv USING '持有待售资产' '持有待售负债' '' '12' CHANGING gs_alv.

  PERFORM frm_get_hslvt USING '' '' '' '250102*' '' 'FD' CHANGING gs_alv-debt_qc  gs_alv-debt_qm.
  PERFORM frm_append_alv USING '一年内到期的非流动资产' '一年内到期的非流动负债' '' '13' CHANGING gs_alv.

  PERFORM frm_get_hslvt USING '1905*' '' '' '' '1122040000' 'FA' CHANGING gs_alv-asset_qc gs_alv-asset_qm.
*  gs_alv-asset_qm = qm1905.
*  gs_alv-asset_qc = qc1905.
*  CLEAR:p_asset_qc,p_asset_qm.

  PERFORM frm_append_alv USING '其他流动资产' '其他流动负债' '' '14' CHANGING gs_alv.

  PERFORM frm_append_alv USING '流动资产合计' '流动负债合计' 'FAFD' '15' CHANGING gs_alv.
*------------------------------------------------------------------------------------------------------
*------------------------------------------------------------------------------------------------------
*------------------------------------------------------------------------------------------------------

  PERFORM frm_append_alv USING '非流动资产:' '非流动负债:' '' '16' CHANGING gs_alv.


  PERFORM frm_get_hslvt USING '1501*' '1502*' '' '' '' 'NFA' CHANGING gs_alv-asset_qc gs_alv-asset_qm.
  PERFORM frm_get_hslvt USING '2501*' '' '' '' '' 'NFD' CHANGING gs_alv-debt_qc  gs_alv-debt_qm.
  PERFORM frm_append_alv USING '债权投资' '长期借款' '' '17' CHANGING gs_alv.

  PERFORM frm_get_hslvt USING '1503*' '' '' '' '' 'NFA' CHANGING gs_alv-asset_qc gs_alv-asset_qm.
  PERFORM frm_get_hslvt USING '2502*' '' '' '' '' 'NFD' CHANGING gs_alv-debt_qc  gs_alv-debt_qm.
  PERFORM frm_append_alv USING '其他债权投资' '应付债券' '' '18' CHANGING gs_alv.

  PERFORM frm_get_hslvt USING '1531*' '' '' '123104*' '' 'NFA' CHANGING gs_alv-asset_qc gs_alv-asset_qm.
  PERFORM frm_append_alv USING '长期应收款' '其中:优先股' '' '19' CHANGING gs_alv.

  PERFORM frm_get_hslvt USING '1511*' '1512*' '' '' '' 'NFA' CHANGING gs_alv-asset_qc gs_alv-asset_qm.
  PERFORM frm_append_alv USING '长期股权投资' '       永续债' '' '20' CHANGING gs_alv.

  PERFORM frm_get_hslvt USING '1504*' '' '' '' '' 'NFA' CHANGING gs_alv-asset_qc gs_alv-asset_qm.
  PERFORM frm_get_hslvt USING '2601*' '' '' '' '' 'NFD' CHANGING gs_alv-debt_qc  gs_alv-debt_qm.
  PERFORM frm_append_alv USING '其他权益工具投资' '租赁负债' '' '21' CHANGING gs_alv.

  PERFORM frm_get_hslvt USING '1533*' '' '' '' '' 'NFA' CHANGING gs_alv-asset_qc gs_alv-asset_qm.
  PERFORM frm_get_hslvt USING '2701*' '2702*' '2711*' '' '' 'NFD' CHANGING gs_alv-debt_qc  gs_alv-debt_qm.
  PERFORM frm_append_alv USING '其他非流动金融资产' '长期应付款' '' '22' CHANGING gs_alv.

  PERFORM frm_get_hslvt USING '1521*' '1522*' '1523*' '' '' 'NFA' CHANGING gs_alv-asset_qc gs_alv-asset_qm.
  PERFORM frm_get_hslvt USING '2801*' '' '' '' '' 'NFD' CHANGING gs_alv-debt_qc  gs_alv-debt_qm.
  PERFORM frm_append_alv USING '投资性房地产' '预计负债' '' '23' CHANGING gs_alv.

  CLEAR: p_asset_qc,p_asset_qm.
  PERFORM frm_get_hslvt USING '1601*' '1602*' '1603*' '' '' 'NFA' CHANGING p_asset_qc p_asset_qm.
  gs_alv-asset_qc = gs_alv-asset_qc + p_asset_qc.
  gs_alv-asset_qm = gs_alv-asset_qm + p_asset_qm.

  CLEAR: p_asset_qc,p_asset_qm.
  PERFORM frm_get_hslvt USING '1608*' '' '' '' '' 'NFA' CHANGING p_asset_qc p_asset_qm.
  gs_alv-asset_qc = gs_alv-asset_qc + p_asset_qc.
  gs_alv-asset_qm = gs_alv-asset_qm + p_asset_qm.
  CLEAR: p_asset_qc,p_asset_qm.

  PERFORM frm_get_hslvt USING '2401*' '' '' '' '' 'NFD' CHANGING gs_alv-debt_qc  gs_alv-debt_qm.
  PERFORM frm_append_alv USING '固定资产' '递延收益' '' '24' CHANGING gs_alv.

  PERFORM frm_get_hslvt USING '1604*' '1605*' '' '' '' 'NFA' CHANGING gs_alv-asset_qc gs_alv-asset_qm.
  PERFORM frm_get_hslvt USING '2901*' '' '' '' '' 'NFD' CHANGING gs_alv-debt_qc  gs_alv-debt_qm.
  PERFORM frm_append_alv USING '在建工程' '递延所得税负债' '' '25' CHANGING gs_alv.

  PERFORM frm_append_alv USING '生产性生物资产' '其他非流动负债' '' '26' CHANGING gs_alv.

  PERFORM frm_append_alv USING '油气资产' '非流动负债合计' 'NFD' '27' CHANGING gs_alv.

  PERFORM frm_get_hslvt USING '1902*' '1903*' '1904*' '' '' 'NFA' CHANGING gs_alv-asset_qc gs_alv-asset_qm.
  PERFORM frm_append_alv USING '使用权资产' '负债合计' 'D' '28' CHANGING gs_alv.

  PERFORM frm_get_hslvt USING '1701*' '1702*' '1703*' '' '' 'NFA' CHANGING gs_alv-asset_qc gs_alv-asset_qm.
  PERFORM frm_append_alv USING '无形资产' '所有者权益:' '' '29' CHANGING gs_alv.

  PERFORM frm_get_hslvt USING '1704*' '1705*' '' '' '' 'NFA' CHANGING gs_alv-asset_qc gs_alv-asset_qm.
  PERFORM frm_get_hslvt USING '4001*' '' '' '' '' 'EQ' CHANGING gs_alv-debt_qc  gs_alv-debt_qm.
  PERFORM frm_append_alv USING '开发支出' '实收资本(或股本)' '' '30' CHANGING gs_alv.

  PERFORM frm_get_hslvt USING '4401*' '' '' '' '' 'EQ' CHANGING gs_alv-debt_qc  gs_alv-debt_qm.
  PERFORM frm_append_alv USING '商誉' '其他权益工具' '' '31' CHANGING gs_alv.

  CLEAR: p_asset_qc,p_asset_qm.
  PERFORM frm_get_hslvt USING '1801*' '1802*' '' '' '' 'NFA' CHANGING p_asset_qc p_asset_qm.
  gs_alv-asset_qc = gs_alv-asset_qc + p_asset_qc.
  gs_alv-asset_qm = gs_alv-asset_qm + p_asset_qm.

  CLEAR: p_asset_qc,p_asset_qm.
  PERFORM frm_get_hslvt USING '' '' '' '' '1803010000' 'NFA' CHANGING p_asset_qc p_asset_qm.
  gs_alv-asset_qc = gs_alv-asset_qc + p_asset_qc.
  gs_alv-asset_qm = gs_alv-asset_qm + p_asset_qm.

  CLEAR: p_asset_qc,p_asset_qm.
  PERFORM frm_get_hslvt USING '' '' '' '' '1803020000' 'NFA' CHANGING p_asset_qc p_asset_qm.
  gs_alv-asset_qc = gs_alv-asset_qc + p_asset_qc.
  gs_alv-asset_qm = gs_alv-asset_qm + p_asset_qm.

  PERFORM frm_append_alv USING '长期待摊费用' ' 其中:优先股' '' '32' CHANGING gs_alv.


  PERFORM frm_get_hslvt USING '1811*' '' '' '' '' 'NFA' CHANGING gs_alv-asset_qc gs_alv-asset_qm.
  PERFORM frm_append_alv USING '递延所得税资产' '       永续债' '' '33' CHANGING gs_alv.

  PERFORM frm_get_hslvt USING '4002*' '' '' '' '' 'EQ' CHANGING gs_alv-debt_qc  gs_alv-debt_qm.
  PERFORM frm_append_alv USING '其他非流动资产' '资本公积' '' '34' CHANGING gs_alv.

  PERFORM frm_get_hslvt USING '4201*' '' '' '' '' 'EQ' CHANGING gs_alv-debt_qc  gs_alv-debt_qm.
  PERFORM frm_append_alv USING '非流动资产合计' '减:库存股' 'NFA' '35' CHANGING gs_alv.


  PERFORM frm_get_hslvt USING '4003*' '' '' '' '' 'EQ' CHANGING gs_alv-debt_qc  gs_alv-debt_qm.
  PERFORM frm_append_alv USING '' '其他综合收益' '' '36' CHANGING gs_alv.

  PERFORM frm_get_hslvt USING '4301*' '' '' '' '' 'EQ' CHANGING gs_alv-debt_qc  gs_alv-debt_qm.
  PERFORM frm_append_alv USING '' '专项储备' '' '37' CHANGING gs_alv.

  PERFORM frm_get_hslvt USING '4101*' '' '' '' '' 'EQ' CHANGING gs_alv-debt_qc  gs_alv-debt_qm.
  PERFORM frm_append_alv USING '' '盈余公积' '' '38' CHANGING gs_alv.
*未分配利润
*  4103,4014,6001,6051,6301   *(-1)  + ( -1 ) * (  )
* 4103+4014+6001+6051+6301-(6401+6403+6404)-(6600+6604)+6302+6111+6101+6701+6702+6703-6711-6801
*4103*+4104*+6001*+6051*-(6401*+6403*+6404*)-6600*(功能范围Z200)-6600*(功能范围Z100)-6600*(功能范围Z500)-6604*+6302*+6111*+6101*+6701*+6702*+6703*+6301*-6711*-6801*

  lv_inventory = 'X'.

  CLEAR: p_debt_qc,p_debt_qm.
  PERFORM frm_get_hslvt USING '6001*' '6051*' '' '' '' 'EQ' CHANGING p_debt_qc p_debt_qm."
  gs_alv-debt_qc = gs_alv-debt_qc + p_debt_qc."+ ( -1 ) * ( p_debt_qc )."
  gs_alv-debt_qm = gs_alv-debt_qm + p_debt_qm."+ ( -1 ) * ( p_debt_qm )."

  CLEAR: p_debt_qc,p_debt_qm.
  PERFORM frm_get_hslvt USING '4103*' '4104*' '6301*' '' '' 'EQ' CHANGING p_debt_qc p_debt_qm."
  gs_alv-debt_qc = gs_alv-debt_qc  + p_debt_qc."+ ( -1 ) * ( p_debt_qc )."+ p_debt_qc."
  gs_alv-debt_qm = gs_alv-debt_qm  + p_debt_qm."+ ( -1 ) * ( p_debt_qm )."+ p_debt_qm."

  CLEAR: p_debt_qc,p_debt_qm.
  PERFORM frm_get_hslvt USING '6401*' '6403*' '6404*' '' '' 'EQ' CHANGING p_debt_qc p_debt_qm."
  gs_alv-debt_qc = gs_alv-debt_qc + p_debt_qc."- p_debt_qc.
  gs_alv-debt_qm = gs_alv-debt_qm + p_debt_qm."- p_debt_qm.

  CLEAR: p_debt_qc,p_debt_qm.
  PERFORM frm_get_hslvt USING '6600*' '' '' '' '' 'EQ' CHANGING p_debt_qc p_debt_qm."
  gs_alv-debt_qc = gs_alv-debt_qc + p_debt_qc."- p_debt_qc.
  gs_alv-debt_qm = gs_alv-debt_qm + p_debt_qm."- p_debt_qm.

  CLEAR: p_debt_qc,p_debt_qm.
  PERFORM frm_get_hslvt USING '6604*' '' '' '' '' 'EQ' CHANGING p_debt_qc p_debt_qm."
  gs_alv-debt_qc = gs_alv-debt_qc + p_debt_qc."- ( -1 ) * ( p_debt_qc ).
  gs_alv-debt_qm = gs_alv-debt_qm + p_debt_qm."- ( -1 ) * ( p_debt_qm ).

  CLEAR: p_debt_qc,p_debt_qm.
  PERFORM frm_get_hslvt USING '6302*' '' '' '' '' 'EQ' CHANGING p_debt_qc p_debt_qm."
  gs_alv-debt_qc = gs_alv-debt_qc + p_debt_qc."+ ( -1 ) * ( p_debt_qc ).
  gs_alv-debt_qm = gs_alv-debt_qm + p_debt_qm."+ ( -1 ) * ( p_debt_qm ).

  CLEAR: p_debt_qc,p_debt_qm.
  PERFORM frm_get_hslvt USING '6101*' '6111*' '' '' '' 'EQ' CHANGING p_debt_qc p_debt_qm.
  gs_alv-debt_qc = gs_alv-debt_qc  + p_debt_qc."+ ( -1 ) * ( p_debt_qc ).
  gs_alv-debt_qm = gs_alv-debt_qm  + p_debt_qm."+ ( -1 ) * ( p_debt_qm ).

  CLEAR: p_debt_qc,p_debt_qm.
  PERFORM frm_get_hslvt USING '6701*' '6702*' '6703*' '' '' 'EQ' CHANGING p_debt_qc p_debt_qm."
  gs_alv-debt_qc = gs_alv-debt_qc  + p_debt_qc."+ ( -1 ) * ( p_debt_qc ).
  gs_alv-debt_qm = gs_alv-debt_qm  + p_debt_qm."+ ( -1 ) * ( p_debt_qm ).

  CLEAR: p_debt_qc,p_debt_qm.
  PERFORM frm_get_hslvt USING '6801*' '6711*' '' '' '' 'EQ' CHANGING p_debt_qc p_debt_qm.
  gs_alv-debt_qc = gs_alv-debt_qc + p_debt_qc."- p_debt_qc.
  gs_alv-debt_qm = gs_alv-debt_qm + p_debt_qm."- p_debt_qm.
  CLEAR: p_debt_qc,p_debt_qm.
*  gs_alv-debt_qc = ( -1 ) * gs_alv-debt_qc.
*  gs_alv-debt_qm = ( -1 ) * gs_alv-debt_qm.
  lv_fa_c_ivty =  ( -1 ) * gs_alv-debt_qc.
  lv_fa_m_ivty =  ( -1 ) * gs_alv-debt_qm.
*  IF gs_alv-debt_qc < 0.
*    lv_fa_c_ivty = ( -1 ) * gs_alv-debt_qc.
*  ELSE.
*    lv_fa_c_ivty = gs_alv-debt_qc.
*  ENDIF.
*  IF gs_alv-debt_qm < 0.
*    lv_fa_m_ivty = ( -1 ) * gs_alv-debt_qm.
*  ELSE.
*    lv_fa_m_ivty = gs_alv-debt_qm.
*  ENDIF.


  PERFORM frm_append_alv USING '' '未分配利润' '' '39' CHANGING gs_alv.
  lv_inventory = ''.

  PERFORM frm_append_alv USING '' '所有者权益合计' 'EQ' '40' CHANGING gs_alv.

  PERFORM frm_append_alv USING '  资产总计' '  负债和所有者权益总计' 'ADEQ' '41' CHANGING gs_alv.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_DIS_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_dis_data .

  DEFINE add_fcat.
    gs_fcat-fieldname = &1.
    gs_fcat-coltext   = &2.
    gs_fcat-outputlen = &3.
    gs_fcat-just      = &4.
    gs_fcat-decimals_o  = &5.
    gs_fcat-no_zero     = &6.
    APPEND gs_fcat TO gt_fcat.
    CLEAR gs_fcat.
  END-OF-DEFINITION.
  add_fcat 'ASSET'      '资产' '30' 'L' ''  ''.
  add_fcat 'ASSET_QM'   '期末余额' '' 'R' ''  ''.
  add_fcat 'ASSET_QC'   '期初余额' '' 'R' ''  ''.
  add_fcat 'DEBT'       '负债和所有者权益' '30' 'L' ''  ''.
  add_fcat 'DEBT_QM'    '期末余额' '' 'R' ''  ''.
  add_fcat 'DEBT_QC'    '期初余额' '' 'R' ''  ''.

  gs_layo-cwidth_opt = 'X'.
  gs_layo-zebra      = 'X'.
  gs_layo-box_fname  = 'SEL'. "设置多行选择
  gs_layo-ctab_fname  = 'FIELD_COLOR' .

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      i_callback_program          = sy-repid
      i_callback_pf_status_set    = 'FRM_SET_STATUS'
      i_callback_html_top_of_page = 'FRM_HTML_PAGE'
      i_callback_user_command     = 'FRM_USER_COMMAND'
      is_layout_lvc               = gs_layo
      it_fieldcat_lvc             = gt_fcat
      i_default                   = 'X'
      i_save                      = 'A'
    TABLES
      t_outtab                    = gt_alv[].

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  frm_set_status
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->RT_EXTAB   text
*----------------------------------------------------------------------*
FORM frm_set_status USING rt_extab TYPE slis_t_extab .

  SET PF-STATUS 'STANDARD' EXCLUDING rt_extab.
*  SET TITLEBAR ''.

ENDFORM.                    "FRM_SET_PF_STATUS
*&---------------------------------------------------------------------*
*&      Form  FRM_USER_COMMAND
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_user_command USING r_ucomm LIKE sy-ucomm
                        rs_selfield TYPE slis_selfield.

  rs_selfield-refresh    = 'X'.
  rs_selfield-col_stable = 'X'.
  rs_selfield-row_stable = 'X'.

  CASE r_ucomm.
    WHEN 'EXPORT'.
      PERFORM frm_save_temp.
      CHECK lv_fullpath IS NOT INITIAL.

      PERFORM frm_get_temp.
      PERFORM frm_create_application.
      PERFORM frm_fill_sheet.
      PERFORM frm_save_excel.
    WHEN OTHERS.
  ENDCASE.

ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  frm_save_temp
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM frm_save_temp .

  CALL METHOD cl_gui_frontend_services=>file_save_dialog
    EXPORTING
      window_title         = '保存文件'
      default_extension    = 'XLS'
      default_file_name    = '资产负债表'
    CHANGING
      filename             = lv_filename
      path                 = lv_path
      fullpath             = lv_fullpath
    EXCEPTIONS
      cntl_error           = 1
      error_no_gui         = 2
      not_supported_by_gui = 3
      OTHERS               = 4.
  IF sy-subrc NE 0.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
     WITH sy-msgv1  sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.
  IF lv_fullpath IS INITIAL.
    MESSAGE '下载模板取消' TYPE 'S' DISPLAY LIKE 'E'.
    EXIT.
  ENDIF.

ENDFORM.                    " frm_save_temp
*&---------------------------------------------------------------------*
*&      Form  frm_get_temp
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM frm_get_temp  .

  DATA:ls_objdata     LIKE wwwdatatab,
       lv_destination LIKE rlgrap-filename,
       lv_rc          LIKE sy-subrc,
       lv_objnam      TYPE string,
       lv_errtxt      TYPE string.

  CONCATENATE '资产负债表' '.XLS' INTO lv_objnam.
  CONDENSE lv_objnam NO-GAPS.
  CLEAR ls_objdata.
  SELECT SINGLE relid objid INTO CORRESPONDING FIELDS OF ls_objdata
    FROM wwwdata
    WHERE srtf2 = 0
    AND   relid = 'MI'
    AND   objid = 'ZFIDG005'.
  IF sy-subrc NE 0 OR ls_objdata-objid EQ space.
    CONCATENATE '模板文件:' lv_objnam '不存在,请用TCODE:SMW0进行加载' INTO lv_errtxt.
    MESSAGE lv_errtxt TYPE 'E'.
  ENDIF.
  lv_destination = lv_fullpath.
  CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
    EXPORTING
      key         = ls_objdata
      destination = lv_destination
    IMPORTING
      rc          = lv_rc.
  IF lv_rc NE 0.
    CONCATENATE '模板文件:' lv_objnam '下载失败' INTO lv_errtxt.
    MESSAGE lv_errtxt TYPE 'E'.
  ELSE.
    CONCATENATE '模板文件:' lv_objnam '下载成功' INTO lv_errtxt.
    MESSAGE lv_errtxt TYPE 'S'.
  ENDIF.

ENDFORM.                    " frm_get_temp
*&---------------------------------------------------------------------*
*&      Form  frm_create_application
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM frm_create_application.

***【EXCEL】
  CREATE OBJECT excel 'EXCEL.APPLICATION'.
  IF sy-subrc NE 0.
    CREATE OBJECT excel 'ET.APPLICATION'.
    IF sy-subrc NE 0.
      MESSAGE a001(00) WITH '无法创建OBJECT,请检查是否安全安装office'.
    ENDIF.
  ENDIF.
  SET PROPERTY OF excel  'Visible'         = 1.
  SET PROPERTY OF excel  'screenupdating'  = 1.
  SET PROPERTY OF excel  'DisplayAlerts'   = 1.

***【WORKBOOK】
  CALL METHOD OF excel 'WORKBOOKS' = workbook.
  CALL METHOD OF workbook 'OPEN'   = workbook
    EXPORTING
      #1       = lv_fullpath.

ENDFORM.                    " FRM_CREATE_APPLICATION
*&---------------------------------------------------------------------*
*&      Form  frm_fill_sheet
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM frm_fill_sheet.

***【SHEET】
  CALL METHOD OF excel 'WORKSHEETS' = sheet
     EXPORTING
       #1 = '资产负债表'.
  CALL METHOD OF sheet 'ACTIVATE'.

  PERFORM frm_fill_cell USING '110'  2 2 '' '' ''.
  PERFORM frm_fill_cell USING '120'  4 2 '' '' ''.
  PERFORM frm_fill_cell USING '130'  4 7 '' '' ''.

  "p_zxh p_row p_col1 p_col2 p_col3 p_col4.
  PERFORM frm_fill_cell USING 2  7 3 4 6 7.
  PERFORM frm_fill_cell USING 3  8 3 4 6 7.
  PERFORM frm_fill_cell USING 4  9 3 4 6 7.
  PERFORM frm_fill_cell USING 5  10 3 4 6 7.
  PERFORM frm_fill_cell USING 6  11 3 4 6 7.
  PERFORM frm_fill_cell USING 7  12 3 4 6 7.
  PERFORM frm_fill_cell USING 8  13 3 4 6 7.
  PERFORM frm_fill_cell USING 9  14 3 4 6 7.
  PERFORM frm_fill_cell USING 10  15 3 4 6 7.
  PERFORM frm_fill_cell USING 11  16 3 4 6 7.
  PERFORM frm_fill_cell USING 12  17 3 4 6 7.
  PERFORM frm_fill_cell USING 13  18 3 4 6 7.

  PERFORM frm_fill_cell USING 14  19 3 4 6 7.
  PERFORM frm_fill_cell USING 15  20 3 4 6 7.
  PERFORM frm_fill_cell USING 16  21 3 4 6 7.
  PERFORM frm_fill_cell USING 17  22 3 4 6 7.
  PERFORM frm_fill_cell USING 18  23 3 4 6 7.
  PERFORM frm_fill_cell USING 19  24 3 4 6 7.
  PERFORM frm_fill_cell USING 20  25 3 4 6 7.
  PERFORM frm_fill_cell USING 21  26 3 4 6 7.
  PERFORM frm_fill_cell USING 22  27 3 4 6 7.
  PERFORM frm_fill_cell USING 23  28 3 4 6 7.
  PERFORM frm_fill_cell USING 24  29 3 4 6 7.
  PERFORM frm_fill_cell USING 25  30 3 4 6 7.
  PERFORM frm_fill_cell USING 26  31 3 4 6 7.
  PERFORM frm_fill_cell USING 27  32 3 4 6 7.
  PERFORM frm_fill_cell USING 28  33 3 4 6 7.
  PERFORM frm_fill_cell USING 29  34 3 4 6 7.
  PERFORM frm_fill_cell USING 30  35 3 4 6 7.
  PERFORM frm_fill_cell USING 31  36 3 4 6 7.
  PERFORM frm_fill_cell USING 32  37 3 4 6 7.
  PERFORM frm_fill_cell USING 33  38 3 4 6 7.
  PERFORM frm_fill_cell USING 34  39 3 4 6 7.
  PERFORM frm_fill_cell USING 35  40 3 4 6 7.
  PERFORM frm_fill_cell USING 36  41 3 4 6 7.
  PERFORM frm_fill_cell USING 37  42 3 4 6 7.
  PERFORM frm_fill_cell USING 38  43 3 4 6 7.
  PERFORM frm_fill_cell USING 39  44 3 4 6 7.
  PERFORM frm_fill_cell USING 40  45 3 4 6 7.  "ADD BY HUANGXMA 20190430
  PERFORM frm_fill_cell USING 41  46 3 4 6 7.  "ADD BY HUANGXMA 20190430
  PERFORM frm_fill_cell USING 42  47 3 4 6 7.  "ADD BY HUANGXMA 20190505
  PERFORM frm_fill_cell USING 43  48 3 4 6 7.  "ADD BY HUANGXMA 20190506
  PERFORM frm_fill_cell USING 44  49 3 4 6 7.  "ADD BY HUANGXMA 20190506
  PERFORM frm_fill_cell USING 45  50 3 4 6 7.  "ADD BY HUANGXMA 20190506
  PERFORM frm_fill_cell USING 45  50 3 4 6 7.  "ADD BY HUANGXMA 20190506

  GET PROPERTY OF excel 'ACTIVEWORKBOOK' = workbook.
  GET PROPERTY OF excel 'ACTIVESHEET'    = sheet.
  GET PROPERTY OF excel 'ACTIVECELL'     = cells.

ENDFORM.                    " FRM_FILL_SHEET
*&---------------------------------------------------------------------*
*&      Form  frm_fill_cell
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_ROW      text
*      -->P_COL      text
*      -->P_VALUE    text
*      -->P_HOR      text
*      -->P_COLOR    text
*      -->P_BOLD     text
*----------------------------------------------------------------------*
FORM frm_fill_cell USING p_zxh p_row p_col1 p_col2 p_col3 p_col4.

  DATA: p_value TYPE string.

  CLEAR: p_value,gs_alv.

  CASE p_zxh.
    WHEN '110'.
      p_value = lv_day_txt.
    WHEN '120'.
      p_value = lv_butxt.
    WHEN '130'.
      p_value = lv_hsl_txt.
    WHEN OTHERS.

      READ TABLE gt_alv INTO gs_alv WITH KEY zxh = p_zxh.
      IF sy-subrc EQ 0.

        "excel导出,负号需前置,再做汇总
        IF gs_alv-asset_qc < 0.
          gs_alv-asset_qc = - gs_alv-asset_qc.
          gs_alv-asset_qc = '-' && gs_alv-asset_qc.
        ENDIF.
        IF gs_alv-asset_qm < 0.
          gs_alv-asset_qm = - gs_alv-asset_qm.
          gs_alv-asset_qm = '-' && gs_alv-asset_qm.
        ENDIF.
        IF gs_alv-debt_qc < 0.
          gs_alv-debt_qc = - gs_alv-debt_qc.
          gs_alv-debt_qc = '-' && gs_alv-debt_qc.
        ENDIF.
        IF gs_alv-debt_qm < 0.
          gs_alv-debt_qm = - gs_alv-debt_qm.
          gs_alv-debt_qm = '-' && gs_alv-debt_qm.
        ENDIF.

      ENDIF.
  ENDCASE.

***【CELLS】
  CALL METHOD OF sheet 'Cells' = cells
    EXPORTING
      #1      = p_row
      #2      = p_col1.

  IF p_col2 IS INITIAL.
    SET PROPERTY OF cells 'value' = p_value.
  ELSE.
    SET PROPERTY OF cells 'value' = gs_alv-asset_qm.
  ENDIF.

  CALL METHOD OF sheet 'Cells' = cells
    EXPORTING
      #1      = p_row
      #2      = p_col2.
  SET PROPERTY OF cells 'value' = gs_alv-asset_qc.

  CALL METHOD OF sheet 'Cells' = cells
    EXPORTING
      #1      = p_row
      #2      = p_col3.
  SET PROPERTY OF cells 'value' = gs_alv-debt_qm.

  CALL METHOD OF sheet 'Cells' = cells
  EXPORTING
    #1      = p_row
    #2      = p_col4.
  SET PROPERTY OF cells 'value' = gs_alv-debt_qc.

***【COLUMNS】
  CALL METHOD OF sheet 'COLUMNS' = columns
    EXPORTING
      #1        = p_col1
      #2        = p_col2
      #3        = p_col3
      #4        = p_col4.
  CALL METHOD OF columns 'AutoFit'.

ENDFORM.                    "FRM_FILL_CELL
*&---------------------------------------------------------------------*
*&      Form  frm_save_excel
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM frm_save_excel .

  CALL METHOD OF excel 'WORKSHEETS' = sheet.

  SET PROPERTY OF sheet 'Visible' = 1.      "显示页签
  SET PROPERTY OF excel 'Visible' = 1.      "设置excel可见
  SET PROPERTY OF excel 'DisplayAlerts' = 0."不显示提示信息

  CALL METHOD OF workbook 'SAVE'.
  CALL METHOD OF workbook 'CLOSE' = workbook.
  CALL METHOD OF excel 'QUIT'.

  FREE: application,
        excel,
        workbook,
        sheet,
        columns,
        font,
        cells,
        borders,
        interior.

  MESSAGE '数据下载成功' TYPE 'S'.

ENDFORM.                    " FRM_SAVE_EXCEL
*&---------------------------------------------------------------------*
*&      Form  FRM_HTML_PAGE
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->DOCUMENT   text
*----------------------------------------------------------------------*
FORM frm_html_page USING cl_document TYPE REF TO cl_dd_document..

  DATA: lv_contents TYPE string,
        lv_position TYPE i.

  lv_day_txt = lv_last_day+0(4) && '/' && lv_last_day+4(2) && '/' && lv_last_day+6(2).

  lv_contents = lv_contents && '<table border=0 bordercolor=#000000 style="border-collapse:collapse;width:1250px">'.
  lv_contents = lv_contents && '<tr><th colSpan="2" style="height:12px;text-align:center;font-size:24px;line-height:1;">'  &&
  '资产负债表'  && '</th></tr>'.
  lv_contents = lv_contents && '<tr><th colSpan="2" style="height:12px;text-align:center;font-size:20px;line-height:1;">'  &&
  lv_day_txt   && '</th></tr>'.

  lv_contents = lv_contents && '<tr>'.
  lv_contents = lv_contents && '<th style="height:24px;text-align:left;font-size:20px;line-height:1;">'    &&
  lv_butxt     && '</th>'.
  lv_contents = lv_contents && '<th style="height:24px;text-align:right;font-size:20px;line-height:1;">'   &&
  lv_hsl_txt   && '</th>'.
  lv_contents = lv_contents && '</tr>'.

  CALL METHOD cl_document->html_insert
    EXPORTING
      contents = lv_contents
    CHANGING
      position = lv_position.

ENDFORM.                    "html_top_of_page
*&---------------------------------------------------------------------*
*& Form FRM_INIT_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_init_data .

  "日期
  DATA: lv_date TYPE sy-datum.
  lv_date = p_ryear && p_rpmax+1(2) && '01'.
  CALL FUNCTION 'BKK_GET_MONTH_LASTDAY'
    EXPORTING
      i_date = lv_date
    IMPORTING
      e_date = lv_last_day.
  lastyear = p_ryear - 1.

  "公司名称
  SELECT SINGLE butxt INTO lv_butxt FROM t001 WHERE bukrs EQ p_rbukrs.
  lv_butxt = '编制单位:' && lv_butxt.

  "单位
*  READ TABLE gt_val INTO gs_val WITH KEY key = p_hsl.
*  IF sy-subrc EQ 0.
*    lv_hsl_txt = gs_val-text.
*    lv_hsl_txt = '单位:' && lv_hsl_txt && '     币种:人民币'.
*  ENDIF.
  lv_hsl_txt = '单位:元     币种:人民币'.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form frm_get_hslvt
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*      -->P_       text
*      -->P_       text
*      -->P_       text
*&---------------------------------------------------------------------*
FORM frm_get_hslvt  USING VALUE(racct1)
                           VALUE(racct2)
                           VALUE(racct3)
                           VALUE(racct4) "六位开头专用
                           VALUE(racct5) "十位开头专用
                           VALUE(p1)
                   CHANGING qc qm.

  DATA: lv_condition TYPE string.
  DATA: lv_rpmax     TYPE faglflext-rpmax.
  DATA: lv_index(2) TYPE n,
        fieldname   TYPE string,
        hj          TYPE faglflext-hslvt,
        qc1462      TYPE faglflext-hslvt,
        hj1462      TYPE faglflext-hslvt,
        qm6600      TYPE faglflext-hslvt,
        qc6600      TYPE faglflext-hslvt,
        qm1905      TYPE faglflext-hslvt,
        qc1905      TYPE faglflext-hslvt,
        qm1122      TYPE faglflext-hslvt,
        qc1122      TYPE faglflext-hslvt,
        qm250102      TYPE faglflext-hslvt,
        qc250102      TYPE faglflext-hslvt,
        qm2501      TYPE faglflext-hslvt,
        qc2501      TYPE faglflext-hslvt.


  FIELD-SYMBOLS: <dyn_field>.

  lv_rpmax = p_rpmax.
  IF lv_rpmax EQ '012' AND p_reass = 'X'. "期间为12并且选择审计调整,需要加上特殊区间13-16的余额
    lv_rpmax = '016'.
  ENDIF.

  CLEAR: qc,qm.
  "如果有参数才进行计算
  IF racct1 IS NOT INITIAL OR racct2 IS NOT INITIAL OR racct3 IS NOT INITIAL OR racct4 IS NOT INITIAL OR racct5 IS NOT INITIAL.
    LOOP AT gt_fag  ASSIGNING FIELD-SYMBOL(<gt_fag>)  .
      "如果科目开头等于参数
      IF ( substring(  val = <gt_fag>-racct len = 4 ) && '*' = racct1 )
        OR ( substring(  val = <gt_fag>-racct len = 4 ) && '*' = racct2 )
        OR ( substring(  val = <gt_fag>-racct len = 4 ) && '*' = racct3 )
        OR ( substring(  val = <gt_fag>-racct len = 6 ) && '*' = racct4 )
        OR ( substring(  val = <gt_fag>-racct len = 10 ) = racct5 ).

        IF ( substring(  val = <gt_fag>-racct len = 4 ) && '*' = '6600*' ) .
          IF <gt_fag>-rfarea = 'Z100' OR <gt_fag>-rfarea = 'Z200' OR <gt_fag>-rfarea = 'Z500'.
            qc6600 = qc6600 + <gt_fag>-hslvt .
            DO lv_rpmax TIMES.
              lv_index = lv_index + 1.
              fieldname = 'HSL' && lv_index.
              ASSIGN COMPONENT fieldname OF STRUCTURE <gt_fag> TO <dyn_field>.
              qm6600 = qm6600 + <dyn_field>  .
            ENDDO.
          ENDIF.
          "如果是1122040000 先写入1905
        ELSEIF ( substring(  val = <gt_fag>-racct len = 10 ) = racct5 ).
          qc1905 = qc1905 + <gt_fag>-hslvt .
          DO lv_rpmax TIMES.
            lv_index = lv_index + 1.
            fieldname = 'HSL' && lv_index.
            ASSIGN COMPONENT fieldname OF STRUCTURE <gt_fag> TO <dyn_field>.
            qm1905 = qm1905 + <dyn_field>  .
          ENDDO.
        ELSEIF ( substring(  val = <gt_fag>-racct len = 4 ) && '*' = '1122*' ) OR ( substring(  val = <gt_fag>-racct len = 6 ) && '*' = '123101*' ) .
          "应收账款排除1122040000 写到 非流动资产

          IF <gt_fag>-racct <> '1122040000'.
            qc1122 = qc1122 + <gt_fag>-hslvt .
            DO lv_rpmax TIMES.
              lv_index = lv_index + 1.
              fieldname = 'HSL' && lv_index.
              ASSIGN COMPONENT fieldname OF STRUCTURE <gt_fag> TO <dyn_field>.
              qm1122 = qm1122 + <dyn_field>  .
            ENDDO.
          ENDIF.
        ELSEIF ( substring(  val = <gt_fag>-racct len = 4 ) && '*' = '1905*' ).
          "其他流动资产 1905  + 1122040000
          qc1905 = qc1905 + <gt_fag>-hslvt .
          DO lv_rpmax TIMES.
            lv_index = lv_index + 1.
            fieldname = 'HSL' && lv_index.
            ASSIGN COMPONENT fieldname OF STRUCTURE <gt_fag> TO <dyn_field>.
            qm1905 = qm1905 + <dyn_field>  .
          ENDDO.
        elseif ( substring(  val = <gt_fag>-racct len = 6 ) && '*' = '250102*' ).
          "先写入一年内到期的非流动资产负债
          qc250102 = qc250102 + <gt_fag>-hslvt .
            DO lv_rpmax TIMES.
              lv_index = lv_index + 1.
              fieldname = 'HSL' && lv_index.
              ASSIGN COMPONENT fieldname OF STRUCTURE <gt_fag> TO <dyn_field>.
              qm250102 = qm250102 + <dyn_field>  .
            ENDDO.
        elseif ( substring(  val = <gt_fag>-racct len = 4 ) && '*' = '2501*' ) and ( substring(  val = <gt_fag>-racct len = 6 ) && '*' <> '250102*' ).
          "长期借款 排除 250102*
          qc2501 = qc2501 + <gt_fag>-hslvt .
            DO lv_rpmax TIMES.
              lv_index = lv_index + 1.
              fieldname = 'HSL' && lv_index.
              ASSIGN COMPONENT fieldname OF STRUCTURE <gt_fag> TO <dyn_field>.
              qm2501 = qm2501 + <dyn_field>  .
            ENDDO.
           clear qc250102.
           clear qm250102.
        ELSE.
          "年初数据
          qc = qc + <gt_fag>-hslvt .
          "期间数据合计
          DO lv_rpmax TIMES.
            lv_index = lv_index + 1.
            fieldname = 'HSL' && lv_index.
            ASSIGN COMPONENT fieldname OF STRUCTURE <gt_fag> TO <dyn_field>.
            hj = hj + <dyn_field>  .
          ENDDO.
        ENDIF.
        qc = qc + qc6600 + qc1122 + qc1905 + qc250102 + qc2501 .
*      期末数据
        qm =  qc + hj + qm6600 + qm1122 + qm1905 + qm250102 + qm2501.

      ENDIF.
      CLEAR lv_index.
    ENDLOOP.
  ENDIF.


*    "单位不同,金额对应作转换
*    IF p_hsl EQ 'B'.
*      qc = qc / 1000.
*      qm = qm / 1000.
*    ENDIF.


  "get total
  CASE p1.
    WHEN 'FA'.
      lv_fa_c = lv_fa_c + qc.
      lv_fa_m = lv_fa_m + qm.

    WHEN 'FD'.
      lv_fd_c = lv_fd_c + qc.
      lv_fd_m = lv_fd_m + qm.

    WHEN 'NFA'.
      lv_nfa_c = lv_nfa_c + qc.
      lv_nfa_m = lv_nfa_m + qm.

    WHEN 'NFD'.
      lv_nfd_c = lv_nfd_c + qc.
      lv_nfd_m = lv_nfd_m + qm.

    WHEN 'EQ'.
      IF lv_inventory = ''."未分配利润在perform处计算合计

        lv_eq_c = lv_eq_c + qc.
        lv_eq_m = lv_eq_m + qm.
      ELSE.
        lv_eq_c_fh = lv_eq_c_fh + qc.
        lv_eq_m_fh = lv_eq_m_fh + qm.

        IF lv_eq_c_fh < 0.
          before_wfplr_fh_qc = '-'.
        ENDIF.
        IF lv_eq_c_fh > 0.
          before_wfplr_fh_qc = '+'.
        ENDIF.
        IF lv_eq_m_fh < 0.
          before_wfplr_fh_qm = '-'.
        ENDIF.
        IF lv_eq_m_fh > 0.
          before_wfplr_fh_qm = '+'.
        ENDIF.
      ENDIF.
  ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_APPEND_ALV
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_append_alv USING p1 TYPE c
                           p2 TYPE c
                           p3
                           p4 CHANGING gs_alv TYPE typ_alv.

  DEFINE field_color.
    ls_color-fname = &1.
    ls_color-color-col = &2.
    ls_color-color-int = &3.
    ls_color-color-inv = &4.
    APPEND ls_color TO gs_alv-field_color.
    CLEAR: ls_color.
  END-OF-DEFINITION.

  gs_alv-asset    = p1.
  gs_alv-debt     = p2.
  gs_alv-zxh      = p4.



*期初期末加入合计值后 ,取绝对值进行展示
*  IF gs_alv-asset_qc < 0.
*    gs_alv-asset_qc = ( -1 ) * gs_alv-asset_qc.
*  ENDIF.
*  IF gs_alv-asset_qm < 0.
*    gs_alv-asset_qm = ( -1 ) * gs_alv-asset_qm.
*  ENDIF.
  gs_alv-debt_qc = ( -1 ) * gs_alv-debt_qc.
  gs_alv-debt_qm = ( -1 ) * gs_alv-debt_qm.

  DATA absstr TYPE char16.

  IF gs_alv-asset_qc < 0.
    absstr = abs( gs_alv-asset_qc ).
    CONCATENATE '-' absstr INTO gs_alv-asset_qc.
    CONDENSE gs_alv-asset_qc NO-GAPS.
    CLEAR absstr.
  ENDIF.
  IF gs_alv-asset_qm < 0.
    absstr = abs( gs_alv-asset_qm ).
    CONCATENATE '-' absstr INTO gs_alv-asset_qm.
    CONDENSE gs_alv-asset_qm NO-GAPS.
    CLEAR absstr.
  ENDIF.

*  IF lv_inventory = 'X'.
*    IF gs_alv-debt_qc < 0.
*      gs_alv-debt_qc = ( -1 ) * gs_alv-debt_qc.
*    ELSE.
*      gs_alv-debt_qc = gs_alv-debt_qc.
*    ENDIF.
*    IF gs_alv-debt_qm < 0.
*      gs_alv-debt_qm = ( -1 ) * gs_alv-debt_qm.
*    ELSE.
*      gs_alv-debt_qm = gs_alv-debt_qm.
*    ENDIF.
*  ENDIF.
*  IF gs_alv-debt_qc < 0.
*    absstr = abs( gs_alv-debt_qc ).
*    CONCATENATE '-' absstr INTO gs_alv-debt_qc.
*    CONDENSE gs_alv-debt_qc NO-GAPS.
*    CLEAR absstr.
*   gs_alv-debt_qc = ( -1 ) * gs_alv-debt_qc.
*  ENDIF.
*  IF gs_alv-debt_qm < 0.
*    absstr = abs( gs_alv-debt_qm ).
*    CONCATENATE '-' absstr INTO gs_alv-debt_qm.
*    CONDENSE gs_alv-debt_qm NO-GAPS.
*    CLEAR absstr.
*    gs_alv-debt_qm = ( -1 ) * gs_alv-debt_qm.
*  ENDIF.

  CASE p3.
    WHEN 'FAFD'."流动资产合计 流动负债合计
      gs_alv-asset_qc = lv_fa_c.
      gs_alv-asset_qm = lv_fa_m.
      gs_alv-debt_qc = lv_fd_c.
      gs_alv-debt_qm = lv_fd_m.
      gs_alv-debt_qc = ( -1 ) * gs_alv-debt_qc.
      gs_alv-debt_qm = ( -1 ) * gs_alv-debt_qm.

      field_color 'ASSET' 5 0 0.
      field_color 'ASSET_QC' 5 0 0.
      field_color 'ASSET_QM' 5 0 0.
      field_color 'DEBT' 7 0 0.
      field_color 'DEBT_QC' 7 0 0.
      field_color 'DEBT_QM' 7 0 0.

    WHEN 'NFD'."非流动负债合计
      gs_alv-debt_qc = lv_nfd_c.
      gs_alv-debt_qm = lv_nfd_m.
      gs_alv-debt_qc = ( -1 ) * gs_alv-debt_qc.
      gs_alv-debt_qm = ( -1 ) * gs_alv-debt_qm.

      field_color 'DEBT' 7 0 0.
      field_color 'DEBT_QC' 7 0 0.
      field_color 'DEBT_QM' 7 0 0.

    WHEN 'D'."负债合计
      gs_alv-debt_qc = lv_fd_c + lv_nfd_c.
      gs_alv-debt_qm = lv_fd_m + lv_nfd_m.
      gs_alv-debt_qc = ( -1 ) * gs_alv-debt_qc.
      gs_alv-debt_qm = ( -1 ) * gs_alv-debt_qm.

      field_color 'DEBT' 6 1 0.
      field_color 'DEBT_QC' 6 1 0.
      field_color 'DEBT_QM' 6 1 0.

    WHEN 'NFA'."非流动资产合计
      gs_alv-asset_qc = lv_nfa_c.
      gs_alv-asset_qm = lv_nfa_m.

      field_color 'ASSET' 5 0 0.
      field_color 'ASSET_QC' 5 0 0.
      field_color 'ASSET_QM' 5 0 0.

    WHEN 'EQ'."所有者权益合计

      lv_fa_c_ivty = ( -1 ) * lv_fa_c_ivty .
      lv_fa_m_ivty = ( -1 ) * lv_fa_m_ivty .
*      IF before_wfplr_fh_qc = '-'.
*        lv_fa_c_ivty = ( -1 ) * lv_fa_c_ivty .
*      ENDIF.
*      IF before_wfplr_fh_qm = '-'.
*        lv_fa_m_ivty = ( -1 ) * lv_fa_m_ivty .
*      ENDIF.
*      IF ( lv_eq_c + lv_fa_c_ivty ) < 0.
*        gs_alv-debt_qc = ( -1 ) * ( lv_eq_c + lv_fa_c_ivty ).
*      ELSE.
*        gs_alv-debt_qc =   lv_eq_c + lv_fa_c_ivty.
*      ENDIF.
*      IF ( lv_eq_m + lv_fa_m_ivty ) < 0.
*        gs_alv-debt_qm = ( -1 ) * ( lv_eq_m + lv_fa_m_ivty ).
*      ELSE.
*        gs_alv-debt_qm = lv_eq_m + lv_fa_m_ivty.
*      ENDIF.
      gs_alv-debt_qc =   lv_eq_c + lv_fa_c_ivty.
      gs_alv-debt_qm = lv_eq_m + lv_fa_m_ivty.
      gs_alv-debt_qc = ( -1 ) * gs_alv-debt_qc.
      gs_alv-debt_qm = ( -1 ) * gs_alv-debt_qm.

      field_color 'DEBT' 6 1 0.
      field_color 'DEBT_QC' 6 1 0.
      field_color 'DEBT_QM' 6 1 0.



    WHEN 'ADEQ'."资产总计 负债和股东权益总计
      gs_alv-asset_qc = lv_fa_c + lv_nfa_c.
      gs_alv-asset_qm = lv_fa_m + lv_nfa_m.
      lv_fa_c_ivty = ( -1 ) * lv_fa_c_ivty .
      lv_fa_m_ivty = ( -1 ) * lv_fa_m_ivty .


*      IF before_wfplr_fh_qc = '-'.
*        lv_fa_c_ivty = ( -1 ) * lv_fa_c_ivty .
*      ENDIF.
*      IF before_wfplr_fh_qm = '-'.
*        lv_fa_m_ivty = ( -1 ) * lv_fa_m_ivty .
*      ENDIF.

      gs_alv-debt_qc = lv_fd_c + lv_nfd_c + lv_eq_c - lv_fa_c_ivty.
      gs_alv-debt_qm = lv_fd_m + lv_nfd_m + lv_eq_m - lv_fa_m_ivty.

      field_color 'ASSET' 3 1 0.
      field_color 'ASSET_QC' 3 1 0.
      field_color 'ASSET_QM' 3 1 0.
      field_color 'DEBT' 3 1 0.
      field_color 'DEBT_QC' 3 1 0.
      field_color 'DEBT_QM' 3 1 0.

      gs_alv-debt_qc = ( -1 ) * gs_alv-debt_qc.
      gs_alv-debt_qm = ( -1 ) * gs_alv-debt_qm.
  ENDCASE.

  PERFORM numtostr USING gs_alv-asset_qc CHANGING gs_alv-asset_qc.
  PERFORM numtostr USING gs_alv-asset_qm CHANGING gs_alv-asset_qm.
  PERFORM numtostr USING gs_alv-debt_qc CHANGING gs_alv-debt_qc.
  PERFORM numtostr USING gs_alv-debt_qm CHANGING gs_alv-debt_qm.

*  IF gs_alv-asset_qc = 0.
*    gs_alv-asset_qc = ''.
*  ENDIF.
*  IF gs_alv-asset_qm = 0.
*    gs_alv-asset_qm = ''.
*  ENDIF.
*  IF gs_alv-debt_qc = 0.
*    gs_alv-debt_qc = ''.
*  ENDIF.
*  IF gs_alv-debt_qm = 0.
*    gs_alv-debt_qm = ''.
*  ENDIF.

  APPEND gs_alv TO gt_alv.
  CLEAR: gs_alv.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form FRM_SET_LISTBOX
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
*FORM frm_set_listbox .
*
*  gs_val-key  = 'A'.
*  gs_val-text = '元'.
*  APPEND gs_val TO gt_val.
*  CLEAR: gs_val.
*  gs_val-key  = 'B'.
*  gs_val-text = '千元'.
*  APPEND gs_val TO gt_val.
*  CLEAR: gs_val.
*
*  CALL FUNCTION 'VRM_SET_VALUES'
*    EXPORTING
*      id     = 'P_HSL'
*      values = gt_val[].
*
*ENDFORM.


**begin 20200420*****************************************************************
* 2、设置文本框的内容
* PS: set_text_as_stream 无法设置多行,需要设置多行,用 set_text_as_r3table
*输入参数PI_TEXT,如果要换行,请用换行符分割
FORM frm_set_text  USING editor TYPE REF TO cl_gui_textedit  pi_text TYPE string.
  DATA: it_line LIKE STANDARD TABLE OF line WITH HEADER LINE.
  SPLIT pi_text AT cl_abap_char_utilities=>cr_lf INTO TABLE it_line.
  CALL METHOD editor->set_text_as_r3table
    EXPORTING
      table           = it_line[]
    EXCEPTIONS
      error_dp        = 1
      error_dp_create = 2
      OTHERS          = 3.
ENDFORM.
**end 20200420*******************************************************************


**end 字符串数字格式换成金额格式123.345,123*******************************************************************

FORM numtostr USING VALUE(znum) CHANGING VALUE(zstr).

  DATA : zclen      TYPE i,
         n          TYPE i,
         zcstr(20)  TYPE c,
         zcstr2(20) TYPE c,
         zctemp(3)  TYPE c,
         zflag(1)   TYPE c VALUE '.', "分离整数与小数
         zflag3(1)  TYPE c VALUE '.', "拼接整数与小数
         zflag2     TYPE i VALUE 0,
         len(2)     TYPE c,
         zcdec(20)  TYPE c. "记录小数部分.
  zstr = ''.

  CHECK abs( znum ) > 0.

  CALL FUNCTION 'ROUND'
    EXPORTING
      decimals      = 2       " 保留多少位小数
      input         = znum
      sign          = '+'     " + 向上取舍 - 向下取舍 (负数也一样)
    IMPORTING
      output        = znum    " 输出返回结果
    EXCEPTIONS
      input_invalid = 1
      overflow      = 2
      type_invalid  = 3
      OTHERS        = 4.


  len = strlen( znum ) - 1.
  IF znum+0(1) = '-' OR znum+len(1) = '-'.
    zflag2 = 1.
  ENDIF.

  znum = abs( znum ).

  IF znum >= 1000.

    zcstr = znum.
* 压缩字符串,去除前面的空格。
    CONDENSE zcstr NO-GAPS.
* 分离整数与小数,好单独处理整数。
    SPLIT zcstr AT zflag INTO zcstr zcdec.
    zclen = strlen( zcstr ).
* 在循环中从右面在每三位的前面加上一个逗号。
    WHILE zclen > 3.
      n = zclen - 3.
      zctemp = zcstr+n(3).
      IF NOT zcstr2 IS INITIAL.
        CONCATENATE zctemp zcstr2 INTO zcstr2 SEPARATED BY ','.
      ELSE.
        zcstr2 = zctemp.
      ENDIF.
      zclen = zclen - 3.
    ENDWHILE.
* 将不剩下的不足三位数加到前面
    CONCATENATE zcstr+0(zclen) zcstr2 INTO zcstr2 SEPARATED BY ','.
    IF zflag2 = 1.
      CONCATENATE '-' zcstr2 INTO zcstr2.
    ENDIF.
    CLEAR zcstr.
* 将处理过的整数与小数连接起来。
    IF zcdec IS INITIAL.
      CONCATENATE zcdec '00' INTO zcdec.
    ELSEIF strlen( zcdec ) = 1.
      CONCATENATE zcdec '0' INTO zcdec.
    ENDIF.

    CONCATENATE zcstr2 zcdec INTO zcstr SEPARATED BY zflag3.
* 将值返回
    zstr = zcstr.
  ELSE.
    zcstr = znum.
    CONDENSE zcstr NO-GAPS.
    SPLIT zcstr AT zflag INTO zcstr zcdec.

    IF zcstr IS INITIAL OR zcstr = ''.
      CONCATENATE '0' zcstr INTO zcstr.
    ENDIF.
    IF zcdec IS INITIAL.
      CONCATENATE zcdec '00' INTO zcdec.
    ELSEIF strlen( zcdec ) = 1.
      CONCATENATE zcdec '0' INTO zcdec.
    ENDIF.

    CONCATENATE zcstr zcdec INTO zstr SEPARATED BY zflag3.
    IF zflag2 = 1.
      CONCATENATE '-' zstr INTO zstr.
    ENDIF.
  ENDIF.



ENDFORM.

***INCLUDE OLE2INCL.
TYPE-POOLS OLE2 .

文章来源:https://blog.csdn.net/java_zhong1990/article/details/135261604
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。