2007 Aug 21 7:27 AM
Hi experts,
How i can insert data from tablecontrol field to Ztable by clicking the Pushbutton at that screen. I get the fields of table control from internal table define in program, and internal table is like of ztable.
Thanks
Hi Prakash,
Create an internal table similar to the fields of table control and when u select the push button write the code in PAI, to put the data in internal table. and then itab to your Ztable.
See this code...It will give u some idea: -
program z_k_table1 .
*tables declaration
tables : zemploykk.
*data declaration
data : ok_code type sy-ucomm.
data : v_lines type i.
data : i_final type table of zemploykk.
*for using table control
controls : tabcont type tableview using screen '3000'.
*for pbo event in screen programming
include z_k_table1_pbo.
*for pai event in screen programming
include z_k_table1_pai.
INCLUDE PROGRAM FOR PBO
----
INCLUDE Z_K_TABLE1_PBO *
----
&----
*& Module STATUS_3000 OUTPUT
&----
text
----
module status_3000 output.
set pf-status 'DEMO'.
set titlebar 'TABLE1'.
describe table i_final lines tabcont-lines.
endmodule. " STATUS_3000 OUTPUT
&----
*& Module output OUTPUT
&----
text
----
" output OUTPUT
INCLUDE PROGRAM FOR PAI
----
INCLUDE Z_K_TABLE1_PAI *
----
&----
*& Module USER_COMMAND_3000 INPUT
&----
text
----
module user_command_3000 input.
case ok_code.
when 'DISPLAY'.
if i_final is initial.
select * from zemploykk into table i_final.
endif.
when 'BACK'.
leave to screen '0'.
when 'CLEAR'.
clear i_final.
when 'MODIFY'.
update zemploykk from table i_final.
clear i_final.
when 'INSERT'.
insert zemploykk from table i_final.
clear i_final.
endcase.
endmodule. " USER_COMMAND_3000 INPUT
&----
*& Module update_tab_control1 INPUT
&----
text
----
module update_tab_control1 input.
describe table i_final lines v_lines.
if v_lines < tabcont-current_line.
append zemploykk to i_final.
else.
modify i_final from zemploykk index tabcont-current_line.
endif.
endmodule. " update_tab_control1 INPUT
Flow Logic
process before output.
module status_3000.
loop at i_final into zemploykk with control tabcont.
endloop.
process after input.
loop at i_final.
module update_tab_control1.
endloop.
module user_command_3000.
Give me your mail ID...I have the one which I already developed.
Regards,
Krishna.
2007 Aug 21 8:29 AM
write a module in the PAI between loop and endloop. Inside that module get the values from screen varialbles to program variables and then write the insert commend.
if u want the exact code. I can provide that too.
2007 Aug 21 8:37 AM
Hi Prakash,
Create an internal table similar to the fields of table control and when u select the push button write the code in PAI, to put the data in internal table. and then itab to your Ztable.
See this code...It will give u some idea: -
program z_k_table1 .
*tables declaration
tables : zemploykk.
*data declaration
data : ok_code type sy-ucomm.
data : v_lines type i.
data : i_final type table of zemploykk.
*for using table control
controls : tabcont type tableview using screen '3000'.
*for pbo event in screen programming
include z_k_table1_pbo.
*for pai event in screen programming
include z_k_table1_pai.
INCLUDE PROGRAM FOR PBO
----
INCLUDE Z_K_TABLE1_PBO *
----
&----
*& Module STATUS_3000 OUTPUT
&----
text
----
module status_3000 output.
set pf-status 'DEMO'.
set titlebar 'TABLE1'.
describe table i_final lines tabcont-lines.
endmodule. " STATUS_3000 OUTPUT
&----
*& Module output OUTPUT
&----
text
----
" output OUTPUT
INCLUDE PROGRAM FOR PAI
----
INCLUDE Z_K_TABLE1_PAI *
----
&----
*& Module USER_COMMAND_3000 INPUT
&----
text
----
module user_command_3000 input.
case ok_code.
when 'DISPLAY'.
if i_final is initial.
select * from zemploykk into table i_final.
endif.
when 'BACK'.
leave to screen '0'.
when 'CLEAR'.
clear i_final.
when 'MODIFY'.
update zemploykk from table i_final.
clear i_final.
when 'INSERT'.
insert zemploykk from table i_final.
clear i_final.
endcase.
endmodule. " USER_COMMAND_3000 INPUT
&----
*& Module update_tab_control1 INPUT
&----
text
----
module update_tab_control1 input.
describe table i_final lines v_lines.
if v_lines < tabcont-current_line.
append zemploykk to i_final.
else.
modify i_final from zemploykk index tabcont-current_line.
endif.
endmodule. " update_tab_control1 INPUT
Flow Logic
process before output.
module status_3000.
loop at i_final into zemploykk with control tabcont.
endloop.
process after input.
loop at i_final.
module update_tab_control1.
endloop.
module user_command_3000.
Give me your mail ID...I have the one which I already developed.
Regards,
Krishna.
2007 Aug 21 8:41 AM
Here is the exact code for your question: -
PROCESS BEFORE OUTPUT.
*-- Initialize data before outputting the screen
MODULE initialize_data.
*-- Get default data
MODULE get_defaultdata.
LOOP AT i_test WITH CONTROL TC.
MODULE screen_modify.
ENDLOOP.
PROCESS AFTER INPUT.
LOOP AT i_test.
FIELD I_TEST-MARK MODULE check.
CHAIN.
FIELD: i_test-source_type,
i_test-length,
i_test-width,
i_test-height.
MODULE pass_data.
ENDCHAIN.
ENDLOOP.
MODULE user_command.
-
Top declarations
-
&----
*& Include ZHKTEST2TOP
&----
PROGRAM ZHKTEST2.
TABLES: ZTEST.
*-- OKCODE to handle
DATA: ok_code TYPE SY-UCOMM.
*---Table control declaration
CONTROLS: tc TYPE TABLEVIEW USING SCREEN 100.
TYPES: BEGIN OF ty_test.
TYPES MARK TYPE CHAR1.
INCLUDE TYPE ZTEST.
TYPES: END OF ty_test.
DATA: t_test TYPE ty_test.
DATA: i_test like t_test OCCURS 0 WITH HEADER LINE,
wa_test TYPE ty_test.
DATA: i_ztest LIKE ZTEST OCCURS 0 WITH HEADER LINE.
DATA: lv_count TYPE i,
gv_tabix TYPE i,
lv_test TYPE i,
flag_check type CHAR1,
flagx TYPE char1,
flag_init TYPE CHAR1,
flag_all type char1, "For select all icon
flag_deselect type char1, "For deselecting icon
flag_ins TYPE CHAR1,
flag_sortup TYPE CHAR1,
flag_sortdown TYPE CHAR1.
-
PBO Modules
-
&----
*& Module initialize_data OUTPUT
&----
text
----
MODULE initialize_data OUTPUT.
*-- To get GUI status
PERFORM get_gui_status.
*-- Set cursor field
PERFORM set_cursor_field.
ENDMODULE. " initialize_data OUTPUT
&----
*& Module get_defaultdata OUTPUT
&----
text
----
MODULE get_defaultdata OUTPUT.
*-- Get default data from ZTEST table
IF flag_init IS INITIAL.
SELECT *
FROM ZTEST
INTO CORRESPONDING FIELDS OF TABLE i_test.
flag_init = 'X'.
ENDIF.
*-- For table control scrolling
DESCRIBE TABLE i_test LINES lv_count.
TC-lines = lv_count + 100.
*-- For selecting all rows in a table control
IF flag_all = 'X'.
LOOP AT i_test.
i_test-MARK = 'X'.
MODIFY i_test TRANSPORTING MARK.
ENDLOOP.
CLEAR flag_all.
ENDIF.
*-- For deselecting all rows
IF flag_deselect = 'X'.
LOOP AT i_test.
i_test-MARK = SPACE.
MODIFY i_test TRANSPORTING MARK.
ENDLOOP.
CLEAR flag_deselect.
ENDIF.
*-- For sorting
IF flag_sortup = 'X'.
SORT i_test BY source_type ASCENDING.
CLEAR flag_sortup.
ELSEIF flag_sortdown = 'X'.
SORT i_test BY source_type DESCENDING.
CLEAR flag_sortdown.
ENDIF.
ENDMODULE. " get_defaultdata OUTPUT
&----
*& Module screen_modify OUTPUT
&----
text
----
MODULE screen_modify OUTPUT.
READ TABLE I_TEST INTO WA_TEST INDEX TC-CURRENT_LINE.
IF SY-SUBRC = 0.
LOOP AT SCREEN.
IF SCREEN-NAME = 'I_TEST-SOURCE_TYPE'.
SCREEN-INPUT = '0'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDIF.
CASE ok_code.
WHEN 'INSE'.
IF TC-CURRENT_LINE = gv_tabix.
LOOP AT SCREEN.
IF SCREEN-NAME = 'I_TEST-SOURCE_TYPE'.
SCREEN-INPUT = '1'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
CLEAR gv_tabix.
ENDIF.
ENDCASE.
ENDMODULE. " screen_modify OUTPUT
-
PAI Modules
-
&----
*& Module user_command INPUT
&----
text
----
MODULE user_command INPUT.
DATA: lin type i.
CLEAR ok_code.
ok_code = SY-UCOMM.
CASE ok_code.
*-- When clicking on BACK, EXIT or CANCEL buttons
WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
LEAVE TO SCREEN 0.
*-- Inserting a new record within selection
WHEN 'INSE'.
READ TABLE i_test WITH KEY mark = 'X'.
IF SY-SUBRC = 0.
INSERT INITIAL LINE into I_TEST INDEX sy-tabix.
gv_tabix = sy-tabix.
flag_ins = 'X'.
flag_deselect = 'X'.
ENDIF.
*-- Deleting the selected records
WHEN 'DEL'.
IF NOT i_test[] IS INITIAL.
DATA: answer TYPE c.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
TITLEBAR = 'Confirmation'
TEXT_QUESTION = 'This will delete database entry also...'
TEXT_BUTTON_1 = 'Yes'
TEXT_BUTTON_2 = 'No'
DEFAULT_BUTTON = '1'
DISPLAY_CANCEL_BUTTON = 'X'
START_COLUMN = 25
START_ROW = 6
IMPORTING
ANSWER = answer.
IF answer = '1'.
LOOP AT i_test WHERE MARK = 'X'.
DELETE FROM ZTEST WHERE source_type = i_test-source_type.
COMMIT WORK.
ENDLOOP.
DELETE i_test WHERE mark = 'X'.
ELSEIF answer = '2'.
LOOP AT i_test WHERE MARK = 'X'.
i_test-mark = SPACE.
MODIFY i_test TRANSPORTING MARK.
ENDLOOP.
ENDIF.
ENDIF.
*--- select all button
WHEN 'ALSI'.
flag_all = 'X'.
*-- Deselect all
WHEN 'DESEL'.
flag_deselect = 'X'.
*-- Sort UP
WHEN 'SUP'.
flag_sortup = 'X'.
*-- Sort down
WHEN 'SDOWN'.
flag_sortdown = 'X'.
*--Save
WHEN 'SAVE'.
IF NOT i_test[] IS INITIAL.
LOOP AT i_test.
i_ztest-mandt = SY-MANDT.
i_ztest-source_type = i_test-source_type.
i_ztest-length = i_test-length.
i_ztest-width = i_test-width.
i_ztest-height = i_test-height.
APPEND i_ztest.
CLEAR i_ztest.
ENDLOOP.
MODIFY ZTEST from table i_ztest.
COMMIT WORK.
MESSAGE s998(hk) WITH 'Table ZTEST successfully updated'.
ENDIF.
ENDCASE.
ENDMODULE. " user_command INPUT
&----
*& Module check INPUT
&----
text
----
MODULE check INPUT.
MODIFY i_test INDEX tc-current_line.
ENDMODULE. " check INPUT
&----
*& Module pass_data INPUT
&----
text
----
MODULE pass_data INPUT.
IF tc-current_line GT lv_count.
APPEND i_test.
ELSE.
MODIFY i_test INDEX tc-current_line.
ENDIF.
ENDMODULE. " pass_data INPUT
-
subroutines
-
&----
*& Form get_gui_status
&----
FORM get_gui_status .
SET PF-STATUS 'TEST'.
ENDFORM. " get_gui_status
&----
*& Form set_cursor_field
&----
FORM set_cursor_field .
SET CURSOR FIELD 'I_TEST-SOURCE_TYPE' LINE
TC-TOP_LINE.
ENDFORM. " set_cursor_field
Reward points if the information is helpful
Regards,
Hari krishna
2007 Aug 21 1:15 PM
Hello Rajiv ,
please give me the code so that i can understand easily.
Thanks
2007 Aug 21 1:35 PM
In the Flow logic write:
PROCESS AFTER INPUT.
loop at itab.
module insert.
endloop.
after double clicking when u get into the insert module.
there you write:
move-corresponding fields of ztable to ztable.
INSERT INTO database table VALUES ztable.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |