我有一个Z表,它有一定数量的记录现在说是15张唱片。使用这15条记录并基于在2个字段上说我必须创建15个组和位置动态选择屏幕中的复选框。如果在将来Z表记录将更新为25或30记录。在选择屏幕中我需要25-30个复选框动态地,代码中没有变化。。请帮助解决此问题。。。
这里有一个建议。您可以使用表中的值轻松地填充下拉菜单,或者更好地填充ALV网格,而不是从表行生成复选框,然后用户可以依次选择这些值。以编程方式评估用户选择将非常容易。此外,随着桌子的进一步增长,您不必担心dynpro尺寸的变化。
这里有一个解决方案,在选择屏幕上有10个动态复选框的上限,带有动态描述和值分配。
REPORT ztest_check_boxes.
DATA: g_num_check_boxes TYPE i,
g_num_cb_shown TYPE i,
g_first_time TYPE abap_bool VALUE abap_true.
FIELD-SYMBOLS: <cb> TYPE flag,
<text> TYPE any.
PARAMETERS: px_01 AS CHECKBOX MODIF ID cb,
px_02 AS CHECKBOX MODIF ID cb,
px_03 AS CHECKBOX MODIF ID cb,
px_04 AS CHECKBOX MODIF ID cb,
px_05 AS CHECKBOX MODIF ID cb,
px_06 AS CHECKBOX MODIF ID cb,
px_07 AS CHECKBOX MODIF ID cb,
px_08 AS CHECKBOX MODIF ID cb,
px_09 AS CHECKBOX MODIF ID cb,
px_10 AS CHECKBOX MODIF ID cb.
INITIALIZATION.
" Determine the number of checkboxes to show,
" for simplicity I just hard coded this
g_num_check_boxes = 3.
AT SELECTION-SCREEN OUTPUT.
g_num_cb_shown = 0.
LOOP AT SCREEN.
IF screen-group1 EQ 'CB'.
" This will trigger on the check box
" as well as their descriptions
IF g_num_cb_shown LT g_num_check_boxes.
" Need to display this check box
CASE screen-group3.
WHEN 'PAR'.
" This is the check box
" you can set the value here dynamically.
" Should only be done once
IF g_first_time EQ abap_true.
ASSIGN (screen-name) TO <cb>.
IF ( g_num_cb_shown MOD 2 ) EQ 0.
<cb> = 'X'.
ENDIF.
ENDIF.
WHEN 'TXT'.
" This is the text, you could set this with
" data from your database table
ASSIGN (screen-name) TO <text>.
<text> = `Checkbox ` && g_num_cb_shown.
" TXT comes after PAR, so we should do this here
ADD 1 TO g_num_cb_shown.
ENDCASE.
ELSE.
" Need to hide this check box
screen-active = '0'.
MODIFY SCREEN.
ENDIF. " Display?
ENDIF. " Check box?
ENDLOOP. " SCREEN
g_first_time = abap_false.
START-OF-SELECTION.
...