Enabling Line Selection in Table Control with Wizard: A Step-by-Step Guide
-
If you remember we, have created this above program in our previous part.
-
Now Suppose, The Customer wants that the Line Selection ability should also be enabled in case of table data.
-
We will see in the part how we can enable line selection in case of table control with wizard.
Hints :-
- We will create one field label → Order number.
- One input/output field for Order Number.
- Two pushbuttons SUBMIT and MOVE.
- Then we will create table control with wizard and we will display the combined data from our header and item table.
Solution :-
-
Step 1 :- Create a Module Pool Program in ABAP Editor and click on object list display to navigate to SE80.
-
Step 2 :- Create a normal screen 100.
-
Step 3 :- Open the layout of screen 100 and
- Create one label Order Number.
- One input/output field for order number.
- Two push buttons. { Don’t forget to give FCT codes to push buttons }
-
Step 4 :- Double click on the program and declare a final structure and their corresponding internal table and work area which we will be using.
Note :- we also require to declare a character field as the first column in the final table.
-
Step 5 :- Open the layout of the screen 100 and create a table control with wizard for our final table.
Note :- We have discussed step by step procedures on how to create a table control with wizard in previous parts.
- We will not select the first columns, as it will be used for selecting other rows.
- Enable the line selection.
- pass the first field here.
- select multiple.
- Save the layout and get back to program.
Note :- SAP will automatically generate a predefined code for table control with wizard.
- Step 6 :- Open the PAI for Screen 100 and write the logic to enter data.
-
Step 7 :- Create a transaction code for our program.
Code :-
*&---------------------------------------------------------------------*
*& Modulpool ZAR_MODULE_POOL_LINE_SELECTION
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
PROGRAM zar_module_pool_line_selection.
TABLES : zar_header, zar_item.
TYPES : BEGIN OF ty_header,
order_number TYPE zar_order_number,
order_date TYPE zar_order_date,
payment_mode TYPE zar_payment_mode,
total_amount TYPE zar_total_amount,
currency TYPE zar_curency,
END OF ty_header.
TYPES : BEGIN OF ty_item,
order_number TYPE zar_order_number,
order_item_number TYPE zar_order_item_number,
order_description TYPE zar_order_description,
item_cost TYPE zar_total_amount,
END OF ty_item.
TYPES : BEGIN OF ty_final,
selection TYPE c,
order_number TYPE zar_order_number,
order_date TYPE zar_order_date,
payment_mode TYPE zar_payment_mode,
total_amount TYPE zar_total_amount,
currency TYPE zar_curency,
order_item_number TYPE zar_order_item_number,
order_description TYPE zar_order_description,
item_cost TYPE zar_total_amount,
END OF ty_final.
DATA : lt_header TYPE TABLE OF ty_header,
ls_header TYPE ty_header,
lt_item TYPE TABLE OF ty_item,
ls_item TYPE ty_item,
lt_final TYPE TABLE OF ty_final,
ls_final TYPE ty_final.
*&SPWIZARD: DECLARATION OF TABLECONTROL 'ZAR_TABLE_CONT' ITSELF
CONTROLS: zar_table_cont TYPE TABLEVIEW USING SCREEN 0100.
*&SPWIZARD: LINES OF TABLECONTROL 'ZAR_TABLE_CONT'
DATA: g_zar_table_cont_lines LIKE sy-loopc.
DATA: ok_code LIKE sy-ucomm.
*&SPWIZARD: OUTPUT MODULE FOR TC 'ZAR_TABLE_CONT'. DO NOT CHANGE THIS LI
*&SPWIZARD: UPDATE LINES FOR EQUIVALENT SCROLLBAR
MODULE zar_table_cont_change_tc_attr OUTPUT.
DESCRIBE TABLE lt_final LINES zar_table_cont-lines.
ENDMODULE.
*&SPWIZARD: OUTPUT MODULE FOR TC 'ZAR_TABLE_CONT'. DO NOT CHANGE THIS LI
*&SPWIZARD: GET LINES OF TABLECONTROL
MODULE zar_table_cont_get_lines OUTPUT.
g_zar_table_cont_lines = sy-loopc.
ENDMODULE.
*&SPWIZARD: INPUT MODUL FOR TC 'ZAR_TABLE_CONT'. DO NOT CHANGE THIS LINE
*&SPWIZARD: MARK TABLE
MODULE zar_table_cont_mark INPUT.
DATA: g_zar_table_cont_wa2 LIKE LINE OF lt_final.
IF zar_table_cont-line_sel_mode = 1
AND ls_final-selection = 'X'.
LOOP AT lt_final INTO g_zar_table_cont_wa2
WHERE selection = 'X'.
g_zar_table_cont_wa2-selection = ''.
MODIFY lt_final
FROM g_zar_table_cont_wa2
TRANSPORTING selection.
ENDLOOP.
ENDIF.
MODIFY lt_final
FROM ls_final
INDEX zar_table_cont-current_line
TRANSPORTING selection.
ENDMODULE.
*&SPWIZARD: INPUT MODULE FOR TC 'ZAR_TABLE_CONT'. DO NOT CHANGE THIS LIN
*&SPWIZARD: PROCESS USER COMMAND
MODULE zar_table_cont_user_command INPUT.
ok_code = sy-ucomm.
PERFORM user_ok_tc USING 'ZAR_TABLE_CONT'
'LT_FINAL'
'SELECTION'
CHANGING ok_code.
sy-ucomm = ok_code.
ENDMODULE.
*----------------------------------------------------------------------*
* 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 USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
IF sy-ucomm EQ 'SUBMIT'.
SELECT order_number order_date payment_mode
total_amount currency
FROM zar_header INTO TABLE lt_header
WHERE order_number = zar_header-order_number.
IF lt_header IS NOT INITIAL.
SELECT order_number order_item_number order_description
item_cost FROM zar_item INTO TABLE lt_item
FOR ALL ENTRIES IN lt_header
WHERE order_number = lt_header-order_number.
LOOP AT lt_item INTO ls_item.
ls_final-order_number = ls_item-order_number.
ls_final-order_item_number = ls_item-order_item_number.
ls_final-order_description = ls_item-order_description.
ls_final-item_cost = ls_item-item_cost.
READ TABLE lt_header INTO ls_header WITH KEY order_number
= ls_item-order_number.
IF sy-subrc EQ 0.
ls_final-order_date = ls_header-order_number.
ls_final-payment_mode = ls_header-payment_mode.
ls_final-total_amount = ls_header-total_amount.
ls_final-currency = ls_header-currency.
ENDIF.
APPEND ls_final TO lt_final.
CLEAR ls_final.
ENDLOOP.
ENDIF.
ENDIF.
ENDMODULE.
Execute the program :-
- Provide a order number and click on submit.
- Now we can perform line selection on it.
Comments
Post a Comment