SAP ABAP4 Learning - TableView code analysis

xiaoxiao2021-03-06  38

TableView code analysis

Ssole

* & ------------------------------------------------ --------------------- *

* & Report ztest_bc410_table *

* & *

* & ------------------------------------------------ --------------------- *

* & *

* & Non-wizard mode to do TableView

* & ------------------------------------------------ --------------------- *

Report ZTEST_BC410_TABLE.

.

Tables: mara, Makt.

* Define an inner table, TABLE control, refer to this inner table.

* INPUT is the first column for selecting column .CHAR, 1 bit.

Data: Begin of git_mara occurs 0,

INPUT,

Matnr Like Mara-Matnr,

CHKBOX,

Maktx Like Makt-Maktx,

TMP,

End of git_mara.

* OK_CODE definition

Data: OK_Code Like Sy-Ucomm,

Save_ok like ok_code.

* Constant definitions are selected and not selected.

Constants: CNS_SEL Value 'X',

CNS_SEL_NO VALUE '',

CNS_TRUE VALUE '1',

CNS_FALSE VALUE '0'.

* Define a TableView object.

Controls TBLC Type TableView Using Screen 1000.

* Define a structure in the Table object

Data: g_col like line of tblc-cols,

G_screen_flg value '',

G_datar value ''.

Call Screen 500.

Start-of-selection.

Case Sy-Ucomm.

When 'Output'.

Perform frm_prt_data.

Endcase.

* & ------------------------------------------------ --------------------- *

* & Module status_1000 output

* & ------------------------------------------------ --------------------- *

* Text

* ------------------------------------------------- --------------------- *

Module Status_1000 Output.

Set pf-status 'status_1000'.

"Status_1000 Output

* & ------------------------------------------------ --------------------- ** & module Cancel INPUT

* & ------------------------------------------------ --------------------- *

* Text

* ------------------------------------------------- --------------------- *

Module Cancel INPUT.

Data C_ANTWORT.

IF g_datar = cns_sel.

Call function 'popup_to_confirm'

Exporting

Titlebar = 'Message'

TEXT_QUESTION = 'DON "T Save IT'

TEXT_BUTTON_1 = 'YES'

Text_Button_2 = 'NO'

Default_Button = '1'

Display_cancel_button = ''

START_COLUMN = 25

START_ROW = 6

Importing

Answer = C_ANTWORT

EXCEPTIONS

TEXT_NOT_FOND = 1

Others = 2.

IF SY-SUBRC <> 0.

Message ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

IF c_antwort = '1'.

CLEAR: G_DATAR, G_SCREEN_FLG.

Leave to Screen 500.

ENDIF.

Else.

CLEAR: G_DATAR, G_SCREEN_FLG.

Leave to Screen 500.

ENDIF.

Cancel Input. "CANCEL INPUT

* & ------------------------------------------------ --------------------- *

* & Module user_command_1000 input

* & ------------------------------------------------ --------------------- *

* Text

* ------------------------------------------------- --------------------- *

Module User_Command_1000 INPUT.

Save_ok = OK_CODE.

Clear ok_code.

Case save_ok.

When 'sell'.

* Select all the data. Inside table's Checkbox is all selected

Perform frm_select using cns_sel.

When 'selzero'.

Perform frm_select using cns_sel_no.when 'delline'.

Perform frm_del_line.

WHEN 'DISMOD'.

Perform frm_dis_mod.

When 'sort_up'.

Perform frm_sort using 'up'.

When 'sort_down'.

Perform frm_sort using 'down'.

When 'Output'.

Leave to screen 0.

When 'Insline'.

Perform frm_insert_line.

When 'pick'.

Perform FRM_PICK.

When 'hide_col'.

Perform frm_set_col_hide.

Endcase.

"User_command_1000 input

* & ------------------------------------------------ --------------------- *

* & Form frm_select

* & ------------------------------------------------ --------------------- *

* Text

* ------------------------------------------------- --------------------- *

* -> p1 text

* <- p2 text

* ------------------------------------------------- --------------------- *

Form frm_select using p_sel.

Loop at git_mara.

Git_mara-chkbox = p_sel.

Modify git_mara.

Endloop.

"Frm_select

* & ------------------------------------------------ --------------------- *

* & Module status_0500 Output

* & ------------------------------------------------ --------------------- *

* Text

* ------------------------------------------------- --------------------- *

Module Status_0500 OUTPUT.

Set Pf-Status 'Status_0500'.

"STATUS_0500 OUTPUT

* & ------------------------------------------------ --------------------- *

* & Module user_command_0500 input

* & ------------------------------------------------ --------------------- *

* Text

* Pack the data that meets the user's input conditions to git_mara.

* ------------------------------------------------- -------------------- * Module user_command_0500 input.

Select * Up to 10 rows

INTO CORRESPONDING FIELDS OF TABLE GIT_MARA

From mara

Where Ersda

ORDER by matnr descending.

User_command_0500 input

* & ------------------------------------------------ --------------------- *

* & Form frm_del_line

* & ------------------------------------------------ --------------------- *

* Text

* ------------------------------------------------- --------------------- *

* -> p1 text

* <- p2 text

* ------------------------------------------------- --------------------- *

Form frm_del_line.

Read Table Git_mara with key matnr = space transporting no fields.

IF SY-SUBRC = 0.

DELETE GIT_MARA WHERE MATNR = Space.

Else.

Loop at git_mara where chkbox = cns_sel.

Delete git_mara.

Endloop.

ENDIF.

"Frm_del_line

* & ------------------------------------------------ --------------------- *

* & Module TBL_DATA_GET_1000 INPUT

* & ------------------------------------------------ --------------------- *

* Text

* ------------------------------------------------- --------------------- *

Module TBL_DATA_GET_1000 INPUT.

Modify git_mara index tblc-current_line.

Endmodule. "TBL_DATA_GET_1000 INPUT

* & ------------------------------------------------ --------------------- *

* & Form frm_dis_mod

* & ------------------------------------------------ --------------------- *

* Text

* ------------------------------------------------- --------------------- *

* -> p1 text

* <- p2 text

* ------------------------------------------------- --------------------- *

FORM FRM_DIS_MOD.

LOOP At TBLC-COLS INTO G_COL Where INDEX> 1. "?????,???

IF g_col-screen-input = cns_false.

G_col-screen-infut = cns_true.

Else.

G_col-screen-infut = cns_false.

* G_col-screen-color = 100. "??????????

ENDIF.

Modify TBLC-COLS from g_col.

Endloop.

"FRM_DIS_MOD

* & ------------------------------------------------ --------------------- *

* & Form frm_prt_data

* & ------------------------------------------------ --------------------- *

* Text

* ------------------------------------------------- --------------------- *

* -> p1 text

* <- p2 text

* ------------------------------------------------- --------------------- *

Form frm_prt_data.

Loop at git_mara.

Write: / git_mara-matnr, git_mara-maktx.

Endloop.

"FRM_PRT_DATA

* & ------------------------------------------------ --------------------- *

* & Formfrm_insert_line

* & ------------------------------------------------ --------------------- *

* Text

* ------------------------------------------------- --------------------- *

* -> p1 text

* <- p2 text

* ------------------------------------------------- --------------------- *

FORM FRM_INSERT_LINE.

Data: l_field (20),

L_linno Type I.

Get Cursor Field L_field Line L_Linno.

* SET CURSOR FIELD L_FIELD LINE L_LINNO. "DEMO ?????

IF l_field cp 'git_mara- *' and sy-subrc = 0.

Clear git_mara.

IF l_linno> = 1.

* L_linno = l_linno tblc-top_line - 1. "DEMO ?????

INSERT GIT_MARA INDEX L_LINNO.

Else.

Append git_mara.endif.

TBLC-LINES = TBLC-LINES 1.

ENDIF.

"Frm_insert_line

* & ------------------------------------------------ --------------------- *

* & Form frm_sort

* & ------------------------------------------------ --------------------- *

* Text

* ------------------------------------------------- --------------------- *

* Do a sorted operation

* ------------------------------------------------- --------------------- *

Form frm_sort using p_mode.

* Declare a line of workspace reference table controls.

Data Lit_sel_col Like TBLC-COLS.

Data: l_fldnam1 (100),

L_fldnam2 (100),

L_fldnam3 (100).

* First remove the head, internal space data

CLEAR: LIT_SEL_COL, LIT_SEL_COL [].

* Do a loop for the TABL control, and select it is already selected. Then add to the inner table.

Loop at tblc-cols Into g_col where selected = cns_sel.

Append g_col to lit_sel_col.

Endloop.

* Sort lit_sel_col by index. "DEMO ????? e

CLEAR: L_FLDNAM1, L_FLDNAM2, L_FLDNAM3.

* Read the three column fields of the head head header of the inner table and then take it from the ninth.

* Take it up.

* Git_mara-matnr

* Git_mara-maktx

* Git_mara-TMP

Read Table Lit_sel_col index 1 INTO G_COL.

L_fldnam1 = g_col-screen-name 9.

Read Table Lit_sel_col INDEX 2 INTO G_COL.

L_fldnam2 = g_col-screen-name 9.

Read Table Lit_sel_col INDEX 3 INTO G_COL.

L_fldnam3 = g_col-screen-name 9.

* Start sorting

IF p_mode = 'up'.

Sort git_mara by (l_fldnam1) (l_fldnam3).

Else.

Sort git_mara descending by (l_fldnam1) (l_fldnam2) (l_fldnam3).

ENDIF.

"Frm_sort

* & ------------------------------------------------ --------------------- *

* & Form frm_pick

* & ------------------------------------------------ --------------------- *

* Text

* ------------------------------------------------- --------------------- *

* -> p1 text * <- p2 text

* ------------------------------------------------- --------------------- *

Form frm_pick.

Data L_Lin Type I.

Get Cursor Line L_Lin.

L_lin = (L_LIN TBLC-CURRENT_LINE) - 1.

Read Table Git_mara index l_lin.

IF git_mara-input = ''.

Git_mara-input = 'x'.

Else.

Git_mara-input = ''.

ENDIF.

Modify git_mara index l_lin transporting input.

"FRM_PICK

* & ------------------------------------------------ --------------------- *

* & Module chK_null_lin input

* & ------------------------------------------------ --------------------- *

* Text

* ------------------------------------------------- --------------------- *

Module Chk_null_lin input.

Read Table git_mara index tblc-current_line.

IF git_mara-matnr is initial and ok_code <> 'Delline'.

Message E012 (SS).

ENDIF.

Endmodule. "Chk_null_lin input

* & ------------------------------------------------ --------------------- *

* & Module add_tmp_flg Output

* & ------------------------------------------------ --------------------- *

* Text

* ------------------------------------------------- --------------------- *

Module add_tmp_flg Output.

Git_mara-TMP = 'X'.

Modify git_mara index tblc-current_line.

Add_tmp_flg output

* & ------------------------------------------------ --------------------- *

* & Module set_col_default output OUTPUT

* & ------------------------------------------------ --------------------- *

* Select the item in the 1000 screen in all the selected items all selected. In initialization, when displayed

* ------------------------------------------------- -------------------- * Module Set_col_default output.

Loop at git_mara.

Git_mara-TMP = CNS_SEL.

IF g_screen_flg = ''.

Git_mara-chkbox = cns_sel.

ENDIF.

Modify git_mara.

Endloop.

G_screen_flg = 'x'.

Endmodule. "SET_COL_DEFAULT OUTPUT

* & ------------------------------------------------ --------------------- *

* & Module hide_col output

* & ------------------------------------------------ --------------------- *

* The fields in loop Table, if it is TMP, you will hide this whole column.

* ------------------------------------------------- --------------------- *

Module Hide_col output.

Loop

AT TBLC-COLS INTO G_COL.

IF g_col-screen-name = 'git_mara-tmp'.

G_col-invisible = CNS_TRUE.

G_col-vislength = CNS_FALSE.

Modify TBLC-COLS from g_col.

ENDIF.

Endloop.

"HIDE_COL OUTPUT

* & ------------------------------------------------ --------------------- *

* & Form frm_set_col_hide

* & ------------------------------------------------ --------------------- *

* Text

* ------------------------------------------------- --------------------- *

* -> p1 text

* <- p2 text

* ------------------------------------------------- --------------------- *

Form frm_set_col_hide.

Loop

AT TBLC-COLS INTO G_COL.

IF g_col-selected = cns_sel.

G_col-invisible = CNS_TRUE.

G_col-vislength = CNS_FALSE.

Modify TBLC-COLS from g_col.

ENDIF.

Endloop.

"Frm_set_col_hide

* & ------------------------------------------------ --------------------- *

* & Form frm_del_null_line

* & ------------------------------------------------ --------------------- ** Text

* ------------------------------------------------- --------------------- *

* -> p1 text

* <- p2 text

* ------------------------------------------------- --------------------- *

Form frm_del_null_line.

DELETE GIT_MARA INDEX TBLC-CURRENT_LINE.

"Frm_del_null_line

* & ------------------------------------------------ --------------------- *

* & Module cancel_500 input

* & ------------------------------------------------ --------------------- *

* Text

* ------------------------------------------------- --------------------- *

Module Cancel_500 INPUT.

Leave Program.

Endmodule. "CANCEL_500 INPUT

* & ------------------------------------------------ --------------------- *

* & Module set_datar input

* & ------------------------------------------------ --------------------- *

* Text

* ------------------------------------------------- --------------------- *

Module set_datar INPUT.

IF g_datar = space.

G_datar = SY-DATAR.

ENDIF.

Endmodule. "SET_DATAR INPUT

转载请注明原文地址:https://www.9cbs.com/read-65250.html

New Post(0)