动态查询,动态列实例

*&---------------------------------------------------------------------*
*& Report ZFI_0665 *
*& *
*&---------------------------------------------------------------------*
*& 合并报表上报检查表 *
*& *
*&---------------------------------------------------------------------*

REPORT zfi_0665 .


TABLES: zfi_name,
zfi_0373 , "利润表
"资产负债表
"应缴税费表
"商品成本表
"抵消分录表
"成本计算表
zfi_0394 , "财务费用表
"制造费用表
"销售费用表
"管理费用表
zfi_0397, "01 应缴增值税明细表
"02 存货明细表
"补充资料表(01+02)
zfi_0422, "01应付职工薪酬明细表一
"02应付职工薪酬明细表二
zfi_0611, "01其他业务收支表
"02营业外收支表
"03 分产品利润表
"05现金明细表
zfi_0631, "06资产变动情况表"
zfi_0404. "生产费用

CONSTANTS: c_yes(2) VALUE '√',
c_no(2) VALUE '×',
c_unknow(2) VALUE '﹣' .
FIELD-SYMBOLS <fs01>.
DATA: z_fname(9).
DATA: p_zbaobm(30) ,p_table(9).
DATA: v_bukrs(6) ,v_gjahr(5) ,v_monat(5) .
DATA: p_condition(100) .
DATA: BEGIN OF itab OCCURS 0 ,
bukrs LIKE zfi_0373-bukrs ,
butxt LIKE t001-butxt,
bb01(2) ,
bb02(2) ,
bb03(2) ,
bb04(2) ,
bb05(2) ,
bb06(2) ,
bb07(2) ,
bb08(2) ,
bb09(2) ,
bb10(2) ,
bb11(2) ,
bb12(2) ,
bb13(2) ,
bb14(2) ,
bb15(2) ,
bb16(2) ,
bb17(2) ,
bb18(2) ,
bb19(2) ,
END OF itab .

DEFINE data_find .
* select single * from &1
* where gjahr = p_gjahr
* and monat = p_monat
* and zbaobm = (&2)
* and bukrs = (&3).
* if sy-subrc = 0 .
* &4 = c_yes .
* else .
* &4 = c_no .
* endif .
v_gjahr = p_gjahr .
v_monat = p_monat .
shift v_gjahr right by 1 places .
shift v_monat right by 1 places .
concatenate 'GJAHR = ' v_gjahr ' AND MONAT = ' v_monat
' AND ZBAOBM =' ' ''' &1 ''''
' AND BUKRS =' ' ''' &2 ''''
into &3 .
END-OF-DEFINITION.
*------------------------------------------------------------------
SELECTION-SCREEN BEGIN OF BLOCK blk_000 WITH FRAME TITLE text-000.
SELECT-OPTIONS: s_bname FOR zfi_name-zbname NO INTERVALS obligatory.
PARAMETER:
p_gjahr LIKE coep-gjahr OBLIGATORY DEFAULT sy-datum(4),
p_monat LIKE bkpf-monat OBLIGATORY DEFAULT sy-datum+4(2).
SELECTION-SCREEN END OF BLOCK blk_000.
*------------------------------------------------------------------
START-OF-SELECTION.
PERFORM f_init .
PERFORM f_getdata .
CALL SCREEN 9000.
*&---------------------------------------------------------------------*
*& Form f_getdata
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_getdata .
DATA: i_count(2) .
DATA: fname(9),fname01(9) .
DATA: flast(4) .
DATA: f(2).
DATA: l_bukrs(7) .
DATA: rc LIKE sy-subrc .
DATA: l_clsever LIKE zefi_client-clsever .
SELECT SINGLE clsever INTO l_clsever FROM zefi_client .

LOOP AT itab .
DO VARYING f FROM itab-bb01 NEXT itab-bb02 .
i_count = i_count + 1 .
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = i_count
IMPORTING
output = i_count.
IF i_count NOT IN s_bname .
IF i_count < '19' .
CONTINUE .
ELSE .
EXIT.
ENDIF .
ENDIF .
PERFORM get_name USING i_count .
CONCATENATE 'ITAB-BB' i_count INTO fname .
l_bukrs = itab-bukrs .
CLEAR p_condition .
data_find p_zbaobm l_bukrs p_condition .
SELECT SINGLE bukrs FROM (p_table) INTO v_bukrs WHERE (p_condition) .
IF sy-subrc = 0 .
ASSIGN (fname) TO <fs01> .
<fs01> = c_yes .
ELSE .
CALL FUNCTION 'ZFI_GETSTATUS' DESTINATION l_clsever
EXPORTING
p_table = p_table
p_condition = p_condition
IMPORTING
rc = rc.
IF rc = 0 .
ASSIGN (fname) TO <fs01> .
<fs01> = c_yes .
ELSE .
ASSIGN (fname) TO <fs01> .
<fs01> = c_no .
ENDIF .
ENDIF .
flast = fname+5(4) .
MODIFY itab TRANSPORTING (flast).
IF i_count = '19' .
EXIT.
ENDIF .
ENDDO.
CLEAR i_count .
ENDLOOP .
ENDFORM. " f_getdata
*&---------------------------------------------------------------------*
*& Form f_init
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM f_init .
*-------取资产负债表的合并单元---------
SELECT DISTINCT bukrs
txtmi AS butxt
INTO CORRESPONDING FIELDS OF TABLE itab
FROM zfi_0665
left JOIN tf161 ON zfi_0665~bukrs = tf161~bunit .

ENDFORM. " f_init
*&---------------------------------------------------------------------*
*& Module STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_9000 OUTPUT.
SET PF-STATUS 'PF9000'.
* SET TITLEBAR 'xxx'.

ENDMODULE. " STATUS_9000 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_9000 INPUT.
CASE sy-ucomm .
WHEN 'ENTER' .
LEAVE TO SCREEN 0000 .
WHEN 'CANC' .
LEAVE TO SCREEN 0000 .
ENDCASE .

ENDMODULE. " USER_COMMAND_9000 INPUT

*&spwizard: declaration of tablecontrol 'TC_9000' itself
CONTROLS: tc_9000 TYPE TABLEVIEW USING SCREEN 9000.

*&spwizard: lines of tablecontrol 'TC_9000'
DATA: g_tc_9000_lines LIKE sy-loopc.

DATA: ok_code LIKE sy-ucomm.

*&spwizard: output module for tc 'TC_9000'. do not change this line!
*&spwizard: update lines for equivalent scrollbar
MODULE tc_9000_change_tc_attr OUTPUT.
DESCRIBE TABLE itab LINES tc_9000-lines.
ENDMODULE. "TC_9000_change_tc_attr OUTPUT

*&spwizard: output module for tc 'TC_9000'. do not change this line!
*&spwizard: get lines of tablecontrol
MODULE tc_9000_get_lines OUTPUT.
g_tc_9000_lines = sy-loopc.
ENDMODULE. "TC_9000_get_lines OUTPUT

*&spwizard: input module for tc 'TC_9000'. do not change this line!
*&spwizard: process user command
MODULE tc_9000_user_command INPUT.
ok_code = sy-ucomm.
PERFORM user_ok_tc USING 'TC_9000'
'ITAB'
' '
CHANGING ok_code.
sy-ucomm = ok_code.
ENDMODULE. "TC_9000_user_command INPUT

*----------------------------------------------------------------------*
* INCLUDE TABLECONTROL_FORMS *
*----------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*& Form USER_OK_TC *
*&---------------------------------------------------------------------*
FORM user_ok_tc USING p_tc_name TYPE dynfnam
p_table_name
p_mark_name
CHANGING p_ok LIKE sy-ucomm.

*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*
DATA: l_ok TYPE sy-ucomm,
l_offset TYPE i.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*

*&SPWIZARD: Table control specific operations *
*&SPWIZARD: evaluate TC name and operations *
SEARCH p_ok FOR p_tc_name.
IF sy-subrc <> 0.
EXIT.
ENDIF.
l_offset = STRLEN( p_tc_name ) + 1.
l_ok = p_ok+l_offset.
*&SPWIZARD: execute general and TC specific operations *
CASE l_ok.
WHEN 'INSR'. "insert row
PERFORM fcode_insert_row USING p_tc_name
p_table_name.
CLEAR p_ok.

WHEN 'DELE'. "delete row
PERFORM fcode_delete_row USING p_tc_name
p_table_name
p_mark_name.
CLEAR p_ok.

WHEN 'P--' OR "top of list
'P-' OR "previous page
'P+' OR "next page
'P++'. "bottom of list
PERFORM compute_scrolling_in_tc USING p_tc_name
l_ok.
CLEAR p_ok.
* WHEN 'L--'. "total left
* PERFORM FCODE_TOTAL_LEFT USING P_TC_NAME.
*
* WHEN 'L-'. "column left
* PERFORM FCODE_COLUMN_LEFT USING P_TC_NAME.
*
* WHEN 'R+'. "column right
* PERFORM FCODE_COLUMN_RIGHT USING P_TC_NAME.
*
* WHEN 'R++'. "total right
* PERFORM FCODE_TOTAL_RIGHT USING P_TC_NAME.
*
WHEN 'MARK'. "mark all filled lines
PERFORM fcode_tc_mark_lines USING p_tc_name
p_table_name
p_mark_name .
CLEAR p_ok.

WHEN 'DMRK'. "demark all filled lines
PERFORM fcode_tc_demark_lines USING p_tc_name
p_table_name
p_mark_name .
CLEAR p_ok.

* WHEN 'SASCEND' OR
* 'SDESCEND'. "sort column
* PERFORM FCODE_SORT_TC USING P_TC_NAME
* l_ok.

ENDCASE.

ENDFORM. " USER_OK_TC

*&---------------------------------------------------------------------*
*& Form FCODE_INSERT_ROW *
*&---------------------------------------------------------------------*
FORM fcode_insert_row
USING p_tc_name TYPE dynfnam
p_table_name .

*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*
DATA l_lines_name LIKE feld-name.
DATA l_selline LIKE sy-stepl.
DATA l_lastline TYPE i.
DATA l_line TYPE i.
DATA l_table_name LIKE feld-name.
FIELD-SYMBOLS <tc> TYPE cxtab_control.
FIELD-SYMBOLS <table> TYPE STANDARD TABLE.
FIELD-SYMBOLS <lines> TYPE i.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*

ASSIGN (p_tc_name) TO <tc>.

*&SPWIZARD: get the table, which belongs to the tc *
CONCATENATE p_table_name '[]' INTO l_table_name. "table body
ASSIGN (l_table_name) TO <table>. "not headerline

*&SPWIZARD: get looplines of TableControl *
CONCATENATE 'G_' p_tc_name '_LINES' INTO l_lines_name.
ASSIGN (l_lines_name) TO <lines>.

*&SPWIZARD: get current line *
GET CURSOR LINE l_selline.
IF sy-subrc <> 0. " append line to table
l_selline = <tc>-lines + 1.
*&SPWIZARD: set top line *
IF l_selline > <lines>.
<tc>-top_line = l_selline - <lines> + 1 .
ELSE.
<tc>-top_line = 1.
ENDIF.
ELSE. " insert line into table
l_selline = <tc>-top_line + l_selline - 1.
l_lastline = <tc>-top_line + <lines> - 1.
ENDIF.
*&SPWIZARD: set new cursor line *
l_line = l_selline - <tc>-top_line + 1.

*&SPWIZARD: insert initial line *
INSERT INITIAL LINE INTO <table> INDEX l_selline.
<tc>-lines = <tc>-lines + 1.
*&SPWIZARD: set cursor *
SET CURSOR LINE l_line.

ENDFORM. " FCODE_INSERT_ROW

*&---------------------------------------------------------------------*
*& Form FCODE_DELETE_ROW *
*&---------------------------------------------------------------------*
FORM fcode_delete_row
USING p_tc_name TYPE dynfnam
p_table_name
p_mark_name .

*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*
DATA l_table_name LIKE feld-name.

FIELD-SYMBOLS <tc> TYPE cxtab_control.
FIELD-SYMBOLS <table> TYPE STANDARD TABLE.
FIELD-SYMBOLS <wa>.
FIELD-SYMBOLS <mark_field>.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*

ASSIGN (p_tc_name) TO <tc>.

*&SPWIZARD: get the table, which belongs to the tc *
CONCATENATE p_table_name '[]' INTO l_table_name. "table body
ASSIGN (l_table_name) TO <table>. "not headerline

*&SPWIZARD: delete marked lines *
DESCRIBE TABLE <table> LINES <tc>-lines.

LOOP AT <table> ASSIGNING <wa>.

*&SPWIZARD: access to the component 'FLAG' of the table header *
ASSIGN COMPONENT p_mark_name OF STRUCTURE <wa> TO <mark_field>.

IF <mark_field> = 'X'.
DELETE <table> INDEX syst-tabix.
IF sy-subrc = 0.
<tc>-lines = <tc>-lines - 1.
ENDIF.
ENDIF.
ENDLOOP.

ENDFORM. " FCODE_DELETE_ROW

*&---------------------------------------------------------------------*
*& Form COMPUTE_SCROLLING_IN_TC
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_TC_NAME name of tablecontrol
* -->P_OK ok code
*----------------------------------------------------------------------*
FORM compute_scrolling_in_tc USING p_tc_name
p_ok.
*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*
DATA l_tc_new_top_line TYPE i.
DATA l_tc_name LIKE feld-name.
DATA l_tc_lines_name LIKE feld-name.
DATA l_tc_field_name LIKE feld-name.

FIELD-SYMBOLS <tc> TYPE cxtab_control.
FIELD-SYMBOLS <lines> TYPE i.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*

ASSIGN (p_tc_name) TO <tc>.
*&SPWIZARD: get looplines of TableControl *
CONCATENATE 'G_' p_tc_name '_LINES' INTO l_tc_lines_name.
ASSIGN (l_tc_lines_name) TO <lines>.


*&SPWIZARD: is no line filled? *
IF <tc>-lines = 0.
*&SPWIZARD: yes, ... *
l_tc_new_top_line = 1.
ELSE.
*&SPWIZARD: no, ... *
CALL FUNCTION 'SCROLLING_IN_TABLE'
EXPORTING
entry_act = <tc>-top_line
entry_from = 1
entry_to = <tc>-lines
last_page_full = 'X'
loops = <lines>
ok_code = p_ok
overlapping = 'X'
IMPORTING
entry_new = l_tc_new_top_line
EXCEPTIONS
* NO_ENTRY_OR_PAGE_ACT = 01
* NO_ENTRY_TO = 02
* NO_OK_CODE_OR_PAGE_GO = 03
OTHERS = 0.
ENDIF.

*&SPWIZARD: get actual tc and column *
GET CURSOR FIELD l_tc_field_name
AREA l_tc_name.

IF syst-subrc = 0.
IF l_tc_name = p_tc_name.
*&SPWIZARD: et actual column *
SET CURSOR FIELD l_tc_field_name LINE 1.
ENDIF.
ENDIF.

*&SPWIZARD: set the new top line *
<tc>-top_line = l_tc_new_top_line.


ENDFORM. " COMPUTE_SCROLLING_IN_TC

*&---------------------------------------------------------------------*
*& Form FCODE_TC_MARK_LINES
*&---------------------------------------------------------------------*
* marks all TableControl lines
*----------------------------------------------------------------------*
* -->P_TC_NAME name of tablecontrol
*----------------------------------------------------------------------*
FORM fcode_tc_mark_lines USING p_tc_name
p_table_name
p_mark_name.
*&SPWIZARD: EGIN OF LOCAL DATA-----------------------------------------*
DATA l_table_name LIKE feld-name.

FIELD-SYMBOLS <tc> TYPE cxtab_control.
FIELD-SYMBOLS <table> TYPE STANDARD TABLE.
FIELD-SYMBOLS <wa>.
FIELD-SYMBOLS <mark_field>.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*

ASSIGN (p_tc_name) TO <tc>.

*&SPWIZARD: get the table, which belongs to the tc *
CONCATENATE p_table_name '[]' INTO l_table_name. "table body
ASSIGN (l_table_name) TO <table>. "not headerline

*&SPWIZARD: mark all filled lines *
LOOP AT <table> ASSIGNING <wa>.

*&SPWIZARD: access to the component 'FLAG' of the table header *
ASSIGN COMPONENT p_mark_name OF STRUCTURE <wa> TO <mark_field>.

<mark_field> = 'X'.
ENDLOOP.
ENDFORM. "fcode_tc_mark_lines

*&---------------------------------------------------------------------*
*& Form FCODE_TC_DEMARK_LINES
*&---------------------------------------------------------------------*
* demarks all TableControl lines
*----------------------------------------------------------------------*
* -->P_TC_NAME name of tablecontrol
*----------------------------------------------------------------------*
FORM fcode_tc_demark_lines USING p_tc_name
p_table_name
p_mark_name .
*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*
DATA l_table_name LIKE feld-name.

FIELD-SYMBOLS <tc> TYPE cxtab_control.
FIELD-SYMBOLS <table> TYPE STANDARD TABLE.
FIELD-SYMBOLS <wa>.
FIELD-SYMBOLS <mark_field>.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*

ASSIGN (p_tc_name) TO <tc>.

*&SPWIZARD: get the table, which belongs to the tc *
CONCATENATE p_table_name '[]' INTO l_table_name. "table body
ASSIGN (l_table_name) TO <table>. "not headerline

*&SPWIZARD: demark all filled lines *
LOOP AT <table> ASSIGNING <wa>.

*&SPWIZARD: access to the component 'FLAG' of the table header *
ASSIGN COMPONENT p_mark_name OF STRUCTURE <wa> TO <mark_field>.

<mark_field> = space.
ENDLOOP.
ENDFORM. "fcode_tc_mark_lines
*&---------------------------------------------------------------------*
*& Module tc_9000_display_column OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE tc_9000_display_column OUTPUT.

FIELD-SYMBOLS : <f1>,<f> .
DATA: wa TYPE cxtab_column.
LOOP AT tc_9000-cols INTO wa.
IF wa-screen-name CS 'ITAB-BB' .
IF wa-screen-name+7(2) IN s_bname .
wa-invisible = 0 .
ELSE.
wa-invisible = 1 .
ENDIF.
ENDIF .
MODIFY tc_9000-cols FROM wa .
ENDLOOP .
ENDMODULE. " tc_9000_display_column OUTPUT
*&---------------------------------------------------------------------*
*& Form GET_NAME
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_I_COUNT text
*----------------------------------------------------------------------*
FORM get_name USING p_i_count.

CASE p_i_count .
WHEN 01 .
p_zbaobm = '资产负债表 ' .
p_table = 'ZFI_0373' .
WHEN 02 .
p_zbaobm = '利润表 '.
p_table = 'ZFI_0373' .
WHEN 03 .
p_zbaobm = '抵消分录表 ' .
p_table = 'ZFI_0373' .
WHEN 04.
p_zbaobm = '05' .
p_table = 'ZFI_0611'.
WHEN 05 .
p_zbaobm = '06' .
p_table = 'ZFI_0631' .
WHEN 06 .
p_zbaobm = ' 03 ' .
p_table = 'ZFI_0611'.
WHEN 07 .
p_zbaobm = '成本计算表 ' .
p_table = 'ZFI_0373' .
WHEN 08 .
p_zbaobm = '商品成本表 ' .
p_table = 'ZFI_0373' .
WHEN 09 .
p_zbaobm = '制造费用表 ' .
p_table = 'ZFI_0394'.
WHEN 10 .
p_zbaobm = '管理费用表 ' .
p_table = 'ZFI_0394'.
WHEN 11 .
p_zbaobm = '营业费用表 ' .
p_table = 'ZFI_0394'.
WHEN 12 .
p_zbaobm = '财务费用表 ' .
p_table = 'ZFI_0394'.
WHEN 13 .
p_zbaobm = '生产费用 ' .
p_table = 'ZFI_0404'.
WHEN 14 .
p_zbaobm = '01' ."01,02 补充资料表
p_table = 'ZFI_0397'.
WHEN 15 .
p_zbaobm = '01' .
p_table = 'ZFI_0394'.
WHEN 16 .
p_zbaobm = '01' .
p_table = 'ZFI_0397'.
WHEN 17 .
p_zbaobm = '02' .
p_table = 'ZFI_0611'.
WHEN 18 .
p_zbaobm = '01' .
p_table = 'ZFI_0422'.
WHEN 19 .
p_zbaobm = '02' .
p_table = 'ZFI_0422'.
ENDCASE .

ENDFORM. " GET_NAME

你可能感兴趣的:(C++,c,制造,C#,F#)