08-11-2008 1:14 PM
Hi,
I am new in ABAP. I have create a module pool but i want to display the reecord from database table. I have write the code into Display button for display Record , When we press the button only one record is displayed into the form. so how i can fetch the total record from this table.
Ram Shanker
08-11-2008 1:16 PM
Hi ram...
For fetching the data from db table ..you have to declare an internal table type db table and make a table control for that and write select query in PBO of that screeen
regards
vivek
08-11-2008 1:19 PM
Hi
Treat module pool program like a normal report program, where PBO is the module where u print data and PIA will have the actions that u perform on the screen.
In PBO, fetch all data entries from DB table into internal table, Loop on internal table and print data
Please let me know incase of further clarifications
08-12-2008 6:00 AM
Hi,
I have already declard internal same as database table.
When i write the following code in PAI for display.
select * into git_abc from abc.
Then , There is not record displayed in form.
but i have written in select * into abc from abc.then Only last record is displayed. Plz guide me what to do for this selection.
Ram Shanker
08-12-2008 6:12 AM
Hi,
try like this..
select * from abc into corresponding fields of table git_abc.
Regards,
Satish Reddy.
08-11-2008 1:24 PM
hi,
to display all the records, your program should have a table control,declare an internal table like database table and write the select query like this.
select * from <dbtable> into corresponding fileds of table <itab>.
in the table control make sure that the screen field names should be like internal table filed names.
Regards,
Satish Reddy.
08-12-2008 6:09 AM
I 've same thing as per your suggestion but i am unable to solve this problem. Plz help. how to fetch the data from database table into screen.
Ram Shanker
08-11-2008 1:34 PM
Hi,
please refer the below code which will help u to solve ur requirement.
create a screen in that declare a table control and write the below code in flow logic
PROCESS BEFORE OUTPUT.
*&SPWIZARD: PBO FLOW LOGIC FOR TABLECONTROL 'TABLE1'
MODULE TABLE1_CHANGE_TC_ATTR.
*&SPWIZARD: MODULE TABLE1_CHANGE_COL_ATTR.
LOOP AT T_OUTPUT
INTO FS_OUTPUT
WITH CONTROL TABLE1
CURSOR TABLE1-CURRENT_LINE.
MODULE TABLE1_GET_LINES.
*&SPWIZARD: MODULE TABLE1_CHANGE_FIELD_ATTR
ENDLOOP.
MODULE STATUS_0100.
*
PROCESS AFTER INPUT.
*&SPWIZARD: PAI FLOW LOGIC FOR TABLECONTROL 'TABLE1'
LOOP AT T_OUTPUT.
CHAIN.
FIELD FS_OUTPUT-CARRID.
FIELD FS_OUTPUT-CONNID.
FIELD FS_OUTPUT-SEATSOCC.
FIELD FS_OUTPUT-TOTAL.
MODULE TABLE1_MODIFY ON CHAIN-REQUEST.
endchain.
ENDLOOP.
MODULE TABLE1_USER_COMMAND.
*&SPWIZARD: MODULE TABLE1_CHANGE_TC_ATTR.
*&SPWIZARD: MODULE TABLE1_CHANGE_COL_ATTR.
REPORT ZTEST_TABLECONTROL.
tables spfli.
CONTROLS: TABLE1 TYPE TABLEVIEW USING SCREEN 0100.
DATA: G_TABLE1_LINES LIKE SY-LOOPC.
DATA: OK_CODE LIKE SY-UCOMM.
data: count like sy-index value 1.
parameters:
p_carrid type S_CARR_ID,
p_connid type S_CONN_ID.
data:
begin of fs_spfli,
carrid type S_CARR_ID,
connid type S_CONN_ID,
SEATSOCC type s_SEATSOCC,
end of fs_spfli,
begin of fs_output,
carrid type S_CARR_ID,
connid type S_CONN_ID,
SEATSOCC type s_SEATSOCC,
total type s_SEATSOCC,
end of fs_output.
data:
t_spfli like table of fs_spfli,
t_output like table of fs_output,
p_index like sy-index.
select carrid
connid
seatsocc
from sflight
into table t_spfli
where carrid eq p_carrid
and connid eq p_connid.
if sy-subrc eq 0.
loop at t_spfli into fs_spfli.
fs_output-carrid = fs_spfli-carrid.
fs_output-connid = fs_spfli-connid.
fs_output-seatsocc = fs_spfli-seatsocc.
append fs_output to t_output.
p_index = sy-tabix.
perform calculation using p_index.
endloop.
endif.
call screen 100.
*&SPWIZARD: OUTPUT MODULE FOR TC 'TABLE1'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: UPDATE LINES FOR EQUIVALENT SCROLLBAR
MODULE TABLE1_CHANGE_TC_ATTR OUTPUT.
DESCRIBE TABLE T_OUTPUT LINES TABLE1-lines.
ENDMODULE.
*&SPWIZARD: OUTPUT MODULE FOR TC 'TABLE1'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: GET LINES OF TABLECONTROL
MODULE TABLE1_GET_LINES OUTPUT.
perform calculation.
modify t_output from fs_output index table1-current_line transporting total.
G_TABLE1_LINES = SY-LOOPC.
ENDMODULE.
*&SPWIZARD: INPUT MODULE FOR TC 'TABLE1'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: MODIFY TABLE
MODULE TABLE1_MODIFY INPUT.
MODIFY T_OUTPUT
FROM FS_OUTPUT
INDEX TABLE1-CURRENT_LINE.
p_index = TABLE1-CURRENT_LINE.
perform calculation using p_index.
modify t_output from fs_output index table1-current_line transporting total.
ENDMODULE.
*&SPWIZARD: INPUT MODULE FOR TC 'TABLE1'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: PROCESS USER COMMAND
MODULE TABLE1_USER_COMMAND INPUT.
OK_CODE = SY-UCOMM.
PERFORM USER_OK_TC USING 'TABLE1'
'T_OUTPUT'
' '
CHANGING OK_CODE.
SY-UCOMM = OK_CODE.
if sy-ucomm eq 'BACK' OR
sy-ucomm eq 'CANCEL'.
LEAVE PROGRAM.
endif.
if sy-ucomm = space.
MODIFY T_OUTPUT
FROM FS_OUTPUT
INDEX TABLE1-CURRENT_LINE.
*
endif.
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 STATUS_0100 OUTPUT
&----
text
----
module STATUS_0100 output.
SET PF-STATUS 'STATUS'.
SET TITLEBAR 'xxx'.
endmodule. " STATUS_0100 OUTPUT
&----
*& Form calculation
&----
text
----
--> p1 text
<-- p2 text
----
form calculation using p_p_index.
read table t_output into fs_output INDEX p_p_index.
if sy-subrc eq 0.
fs_output-total = fs_output-seatsocc * 2.
modify t_output from fs_output index p_p_index transporting total.
endif.
endform. " calculation
08-13-2008 6:35 AM