Reputation: 1
I've a Z-table which has certain number of records for now say 15 records. Using these 15 records and based on 2 fields say group and position I've to create 15 check boxes in selection screen dynamically. If in future the Z-table records are updated to 25 or 30 records . I need 25-30 check boxes in selection screen dynamically with out change in the code.. Please help with this problem...
Upvotes: 0
Views: 3182
Reputation: 2565
Here is a solution with an upper limit of 10 dynamical check boxes on the selection screen with dynamic descriptions and value assignment.
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.
...
Upvotes: 0
Reputation: 476
Here's a suggestion. Instead of generating checkboxes from your table lines you could easily populate a dropdown menu or better yet an ALV grid with the values from your table, which can then in turn be selected by the user. Evaluating the user selection programmatically will be easy enough. Plus you won't have to worry about varying dynpro sizes as your table grows further.
Upvotes: 1