2007 Mar 28 3:25 PM
I have a report that each record has a heading line (preceded with a checkbox) and the next line is the information. I want to be able to display the information for all those selected. Right now it doesn't get the right data. Here is the code:
*Note: The fields of zmytable all are type C of 10 length.
DATA: mark TYPE c,
int_tmp TYPE i,
it_mytab TYPE zmytable OCCURS 0,
wa_mytab LIKE LINE OF it_mytab.
LOOP AT it_mytab INTO wa_mytab.
SELECT SINGLE descr FROM zmycodes
INTO st_tmp3
WHERE tp_code = wa_mytab-tp_code.
WRITE: / mark AS CHECKBOX,
st_tmp3 color col_negative intensified off,
/ wa_mytab-field1,
wa_mytab-field2,
wa_mytab-field3.
ULINE.
HIDE: wa_mytab-field1,
wa_mytab-field2,
wa_mytab-field3.
ENDLOOP.
CLEAR mytab.
AT LINE-SELECTION.
CHECK NOT wa_mytab-field1 IS INITIAL.
CASE sy-lsind.
WHEN 1.
DO.
int_tmp = 0.
mark = space.
READ LINE sy-index FIELD VALUE mark.
IF sy-subrc NE 0.
EXIT.
ELSE.
IF mark = 'X'.
ADD 1 TO int_tmp.
WRITE: / int_tmp,
wa_mytab-field1,
wa_mytab-field2,
wa_mytab-field3.
ENDIF.
ENDIF.
ENDDO.
ENDCASE.
Any help would be greatly appreciated. Thanks in advance.
2007 Mar 28 3:40 PM
Hi
U should know the link between the line checked and the record of internal table:
DATA: START_LINE TYPE I,
TABIX TYPE I.
LOOP AT it_mytab INTO wa_mytab.
SELECT SINGLE descr FROM zmycodes
INTO st_tmp3
WHERE tp_code = wa_mytab-tp_code.
WRITE: / mark AS CHECKBOX,
st_tmp3 color col_negative intensified off,
/ wa_mytab-field1,
wa_mytab-field2,
wa_mytab-field3.
ULINE.
HIDE: wa_mytab-field1,
wa_mytab-field2,
wa_mytab-field3.
* Get the first line:
IF START_LINE = 0.
START_LINE = SY-LINNO.
ENDIF.
ENDLOOP.
CLEAR mytab.
AT LINE-SELECTION.
* -----> Now you have the data (wa_mytab) of line where you did the doubleclick,
*
CHECK NOT wa_mytab-field1 IS INITIAL.
CASE sy-lsind.
WHEN 1.
DO.
int_tmp = 0.
mark = space.
READ LINE sy-index FIELD VALUE mark.
IF sy-subrc NE 0.
EXIT.
ELSE.
IF mark = 'X'.
* Calculate the index of the table, if line is START_LINE the index is 1:
TABIX = SY-INDEX - START_LINE + 1.
READ TABLE it_mytab INTO wa_mytab INDEX TABIX.
ADD 1 TO int_tmp.
WRITE: / int_tmp,
wa_mytab-field1,
wa_mytab-field2,
wa_mytab-field3.
ENDIF.
ENDIF.
ENDDO.
ENDCASE.
Max
2007 Mar 28 4:29 PM
Thanks Max,
The exact code didn't work, but I figured out the correct formula to get the correct tabix value and the rest worked. Thanks for helping me out. The formula I used, in case you were wondering was:
tabix = ( sy-index \ 3 ) + 1.
Thanks bunches!
2007 Mar 28 3:43 PM
Hi..
copy and paste this codee.....u can get it...
"----
Declaration of the structure to hold data that needs to be selected *
from database. *
"----
Data:
Begin of fs_spfli,
carrid type spfli-carrid, " Airline Code
connid type spfli-connid, " Flight Connection Code
airpfrom type spfli-airpfrom, " Departure Airport
airpto type spfli-airpto, " Destination Airport
deptime type spfli-deptime, " Departure Time
arrtime type spfli-arrtime, " Arrival Time
End of fs_spfli.
"----
Internal table to hold Flight Scedule data *
"----
Data:
t_spfli like standard table
of fs_spfli.
"----
Declaration of Structure to hold Flight Occupancy Data *
"----
*Data:
Begin of fs_sflight,
fldate type sflight-fldate, " Flight Date
seatsmax type sflight-seatsmax, " Maximum Seats
seatsocc type sflight-seatsocc, " Occupied Seats
End of fs_sflight.
"----
Internal table to hold Flight Occupancy data *
"----
Data:
t_sflight type
standard table
of sflight,
wa_sflight like line
of t_sflight.
*" Data declarations...................................................
"----
Work variables *
"----
data:
w_check type c, " Check box
w_char type c value space. " Stores *
"----
TOP-OF-PAGE *
"----
top-of-page.
perform list_header.
"----
START-OF-SELECTION *
"----
start-of-selection.
Reading Airline Schedule data
Perform read_schedule_data.
"----
END-OF-SELECTION *
"----
end-of-selection.
set pf-status 'PRINT'.
Generating List with Schedule of Flights
Perform print_schedule_data.
"----
AT USER-COMMAND *
"----
at user-command.
Providing Choice of Operations for User
case sy-ucomm.
when 'SFLIGHT'(001).
perform Print_Airfare_data.
when 'SELECTALL'(006).
perform select_all_checkboxes.
when 'DESELECTAL'(011).
perform deselect_all_checkboxes.
Endcase. " CASE SY-UCOMM
&----
*& FORM LIST_HEADER
&----
This subroutine prints list header.
----
There are no interface parameters to be passed to this subroutine. *
----
form list_header .
skip.
format color 1.
write:
/6 'CARRID',
14 'CONNID',
25 'FROM AIRPORT',
40 'TO AIRPORT',
55 'DEP TIME',
70 'ARR TIME'.
format color off.
perform draw_table in program yh642_020301
using 5 1 80 3 3 13 24 39 54 69 0 0 0 5.
endform. " list_header
&----
*& FORM READ_SCHEDULE_DATA
&----
This subroutine gets the required data from database
----
No parameters passing to this subroutine.
----
form read_schedule_data .
Select carrid " Airline Code
connid " Connection Id
airpfrom " Airport from
airpto " Arrival Airport
deptime " Departure time
arrtime " Arrival time
into table t_spfli
from spfli.
if sy-subrc eq 0.
endif. " ENDIF FOR SY-SUBRC
endform. " READ SCHEDULE DATA
&----
*& Form print_schedule_data
&----
This subroutine prints flight scheduled data.
----
No parameters passing to this subroutine.
----
form print_schedule_data .
data:
l_w_lines type i. " Number of lines
skip .
loop at t_spfli into fs_spfli.
write:
/ w_check as checkbox,
3 w_char,
6 fs_spfli-carrid,
15 fs_spfli-connid,
26 fs_spfli-airpfrom,
40 fs_spfli-airpto,
56 fs_spfli-deptime,
71 fs_spfli-arrtime.
Endloop.
describe table t_spfli lines l_w_lines.
add 10 to l_w_lines.
perform draw_table in program yh642_020301
using 5 1 80 l_w_lines 0 13 24 39 54 69 0 0 0 5.
endform. " PRINT SCHEDDULE DATA
&----
*& FORM PRINT AIRFARE DATA
&----
This Subroutine Prints airfare data for the record selected
----
No parameters passing to this subroutine.
----
form Print_Airfare_data .
"----
*Field String that holds the selected line contents. *
"----
Data:
Begin of lfs_spfli,
carrid type spfli-carrid, " Airline code
connid type spfli-connid, " Flight Connection number
End of lfs_spfli.
"----
Internal Table to hold the selected line contents. *
"----
Data:
ltkey_spfli like standard table
of lfs_spfli.
*" Data declarations...................................................
"----
Work variables *
"----
Data:
l_w_lines type i, " Total number of lines
l_w_lineno type i, " Line which is selected
l_w_count type i, " No.of check boxes
l_w_printl type i. " Number of lines to print.
set pf-status SPACE.
Describe table t_spfli lines l_w_lines.
l_w_lineno = l_w_lineno + 5.
Do l_w_lines times.
read line l_w_lineno
field value w_check into w_check
fs_spfli-carrid into fs_spfli-carrid
fs_spfli-connid into fs_spfli-connid.
If sy-subrc eq 0.
If w_check EQ 'X'.
add 1 to l_w_count.
clear w_check.
w_char = '*'.
modify current line field value w_char w_check
field format w_check input off.
line format color 3.
lfs_spfli-carrid = fs_spfli-carrid.
lfs_spfli-connid = fs_spfli-connid.
append lfs_spfli to ltkey_spfli.
clear w_char.
Endif. " IF W_CHECK EQ 'X'
Endif. " IF SY-SUBRC EQ 0
Add 1 to l_w_lineno.
Enddo. " DO W_LINES TIMES
If l_w_count eq 0.
message E007.
Else.
select * " GET SFLIGHT CONTENTS
from sflight
into table t_sflight
for all entries "
in ltkey_spfli
where carrid eq ltkey_spfli-carrid
and connid eq ltkey_spfli-connid.
if sy-subrc eq 0.
describe table t_sflight lines l_w_printl.
skip.
write:
/5 'Flight Date'(008),
20 'Maximum Seats'(012),
35 'Occupied Seats'(009).
skip.
loop at t_sflight into wa_sflight.
write:
/ wa_sflight-fldate under text-008,
wa_sflight-seatsmax under text-012,
wa_sflight-seatsocc under text-009.
endloop. " LOOP AT T_SFLIGHT
else.
Message E008.
Endif. " IF SY-SUBRC EQ 0
Endif. " IF W_COUNT EQ 0
add 5 to l_w_printl.
perform draw_table in program yh642_020301
using 4 1 55 l_w_printl 3 19 34 0 0 0 0 0 0 2.
endform. " PRINT AIRFARE_DATA
&----
*& FORM SELECT ALL CHECK BOXES
&----
This subroutines selects all the lines (Check boxes)
----
There are no interface parameters to be passed to this subroutine.*
----
form select_all_checkboxes .
Data:
lw_lines type i.
sy-lsind = 0.
Describe table t_spfli lines lw_lines.
lw_lines = lw_lines + 5.
Do lw_lines times.
If sy-index ge 5.
read line sy-index field value w_char into w_char.
if w_char eq '*'.
else.
w_check = 'X'(002).
modify line sy-index field value w_check.
endif.
Endif. " IF SY-INDEX GE 3
Enddo. " DO LW_LINES TIMES
endform. " SELECTS ALL CHECKBOXES
&----
*& FORM DESELECT ALL CHECK BOXES *
&----
This subroutine enables the user to deselect all the check boxes once*
----
*There are no interface parameters to be passed to this subroutine. *
----
form deselect_all_checkboxes .
Data:
lw_lines type i.
Describe table t_spfli lines lw_lines.
lw_lines = lw_lines + 8.
Do lw_lines times.
If sy-index ge 5.
read line sy-index field value w_check.
w_check = ' '.
modify line sy-index field value w_check.
Endif. " IF SY-INDEX GE 3
Enddo. " DO LW_LINES TIMES
endform. " DESELECT ALL CHECK BOXES