‎2014 May 23 1:53 PM
Hi Gurus,
I am new to ABAP and i am working on Step-Loops. Following is my code and called screen 9001 from my code. I named screen elements same as that in my ABAP code. It shows no syntax error and after successfull activation, values are not getting displayed on screen. After debugging my internal table is loaded with values.
Following is my code :
report ztest_013.
* Number of records to be displayed
parameters : p_num type i.
* Types to declare the internal table for records
types: begin of t_itab,
col1 type i,
col2 type i,
end of t_itab.
* Internal table for the records
data: itab type standard table of t_itab,
* Work area for the records
wa like line of itab.
data: idx type i, " Current Line to be displayed
line type i,
lines type i,
" Final Limit of step loop rows that can be displayed
limit type i,
" Cursor position
c type i,
" Lower limit of the record index to be displayed on a page
n1 type i value 1,
" Upper limit of the record index to be displayed on a page
n2 type i,
" Variable to handle next page navigation
y_v_next type i,
" Variable to handle previous page navigation
y_v_prev type i,
y_v_limit type i.
data: ok_code type sy-ucomm,
save_ok type sy-ucomm.
start-of-selection.
* Building the records to be displayed as per the selection screen entry
do p_num times.
wa-col1 = sy-index.
wa-col2 = sy-index ** 2.
append wa to itab.
enddo. if p_num < 0.
n2 = p_num.
else.
n2 = 5.
endif. call screen 9001.
*----------------------------------------------------------------------*
* MODULE status_0100 OUTPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
*MODULE status_0100 OUTPUT.
* SET PF-STATUS 'STATUS_100'.
*ENDMODULE. "status_0100 OUTPUT*----------------------------------------------------------------------*
* MODULE transp_itab_out OUTPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
module transp_itab_out output.
idx = sy-stepl + line.
read table itab into wa index idx.
endmodule. "transp_itab_out OUTPUT*----------------------------------------------------------------------*
* MODULE transp_itab_in INPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
module transp_itab_in input.
lines = sy-loopc.
idx = sy-stepl + line.
modify itab from wa index idx.
endmodule. "transp_itab_in INPUT*----------------------------------------------------------------------*
* MODULE user_command_0100 INPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
module user_command_9001 input.
data : y_v_index type sy-index.
data : y_lv_d type f,
y_lv_div type i,
y_curr_p_num type i.
save_ok = ok_code.
clear ok_code.
case sy-ucomm.
* WHEN 'BACK'.
* LEAVE TO SCREEN 0.
* When Page Down is Hit
when 'PGDN'.
* Number of screens required for output if 5 records per screen
y_lv_d = p_num / 5.
y_lv_div = ceil( y_lv_d ). y_curr_p_num = y_lv_div * 5. y_v_index = y_v_next + 1. if y_v_next < y_lv_div.
y_v_next = y_v_next + 1.
else.
y_v_next = y_lv_div.
endif.
y_v_prev = y_v_next. if y_v_next <> y_lv_div.
n2 = p_num - 5 * y_v_next.
if n2 > 5.
n2 = 5 * y_v_next.
endif.
n1 = 1. line = line + lines.
limit = y_curr_p_num - lines.
if line > limit.
line = limit.
endif.
else.
y_v_next = y_v_next - 1.
endif.
* When Page Up is Hit
when 'PGUP'.
n2 = 5 * y_v_next.
if n1 < 0.
n1 = 1.
endif. if y_v_next > 0.
y_v_next = y_v_next - 1.
else.
y_v_next = 0.
endif.
y_v_prev = y_v_next. if line ne 0 and y_curr_p_num gt 5.
line = y_v_next * 5.
else.
line = 0.
y_v_index = y_v_next - 1.
endif. if line < 0.
line = 0.
endif.
endcase.
endmodule. "user_command_0100 INPUT*----------------------------------------------------------------------*
* MODULE cancel INPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
*MODULE cancel INPUT.
* LEAVE PROGRAM.
*ENDMODULE. "cancel INPUT
*&---------------------------------------------------------------------*
*& Module PGUP_DOWN OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
module pgup_down output. data : y_v_div type i,
y_v_d type f,
y_v_temp type i.
describe table itab[] lines p_num. y_v_d = p_num / 5.
y_v_limit = ceil( y_v_d ).
y_v_temp = y_v_limit - 1. if p_num le 5.
perform y_f_hide_field using 'PD'.
perform y_f_hide_field using 'PU'.
elseif y_v_next = y_v_limit .
perform y_f_hide_field using 'PD'.
perform y_f_show_field using 'PU'.
elseif y_v_prev is initial.
perform y_f_hide_field using 'PU'.
elseif y_v_next gt y_v_limit.
perform y_f_hide_field using 'PD'.
elseif y_v_temp = y_v_next.
perform y_f_hide_field using 'PD'.
endif.endmodule. " PGUP_DOWN OUTPUT
*&---------------------------------------------------------------------*
*& Form Y_F_HIDE_FIELD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0372 text
*----------------------------------------------------------------------*
form y_f_hide_field using value(p_name).
loop at screen.
if screen-name = p_name.
screen-active = '0'.
screen-invisible = '1'.
modify screen.
exit.
endif.
endloop.endform. " Y_F_HIDE_FIELD
*&---------------------------------------------------------------------*
*& Form Y_F_SHOW_FIELD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0388 text
*----------------------------------------------------------------------*
form y_f_show_field using value(p_name). loop at screen.
if screen-name = p_name.
screen-active = '1'.
modify screen.
exit.
endif.
endloop.endform. " Y_F_SHOW_FIELD
‎2014 May 23 2:52 PM
‎2014 May 23 3:58 PM
Step-loops are outdated since maybe 1995...better learn something meaningful.
Have a look around SCN and the "custom development" spaces, there is plenty of inspiration.
Thomas
‎2014 May 26 6:17 AM
‎2014 May 26 7:25 AM
Hi Aditya,
Use Table controls instead of Step loops as they are obsolete.
Table controls are just similar to the step loops except for the fact that multiple lines cannot be built like in step loops which are expanded in a single row.
Browsing SCN you can find many other advantages of using Table Control instead of Step loops.
Regards,
AyyamPerumal