Not able to toggle selection screens based on radio button input - radio-button

I am trying to toggle(hide) the selection screens based on radio button input. But the code seems not working.
" Radio button block
SELECTION-SCREEN BEGIN OF BLOCK search_block WITH FRAME TITLE text-001.
PARAMETER: rad_flt RADIOBUTTON GROUP rgb DEFAULT 'X',
rad_cus RADIOBUTTON GROUP rgb.
SELECTION-SCREEN END OF BLOCK search_block.
" Selection screen 1
SELECTION-SCREEN BEGIN OF BLOCK flight_block WITH FRAME TITLE text-002.
PARAMETER: carrid TYPE sbook-carrid,
connid TYPE sbook-connid,
fldate TYPE sbook-fldate MODIF ID sc1.
SELECTION-SCREEN END OF BLOCK flight_block.
" Selection screen 2
SELECTION-SCREEN BEGIN OF BLOCK customid_block WITH FRAME TITLE text-002.
PARAMETER: customid TYPE sbook-customid MODIF ID sc2.
SELECTION-SCREEN END OF BLOCK customid_block.
AT SELECTION-SCREEN OUTPUT.
*Toggle the selection screens based on radio buttons
LOOP AT SCREEN.
IF rad_flt = 'X' AND screen-group1 = 'sc2'.
screen-active = 0.
MODIFY SCREEN.
ELSEIF rad_cus = 'X' AND screen-group1 = 'sc1'.
screen-active = 0.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
The screen displays all the screens. Not able to track the issue using debugger.

By default radio buttons don't trigger any events, which is what you need to perform some actions on radio button toggle (and not on Enter press or execution). You can do it by adding user-command <eventcode> to your radio button group and then handling those events in At selection-screen output .
tables: sscrfields. "Only needed if you need to tell different events apart.
select-options:
so_1_1 for lfa1-lifnr modif id g1,
so_1_2 for lfa1-kunnr modif id g1,
so_2_1 for kna1-lifnr modif id g2,
so_2_2 for kna1-kunnr modif id g2,
parameters:
p_1 radiobutton group prct user-command rb_prct default 'X',
p_2 radiobutton group prct,
p_3 radiobutton group prct.
at selection-screen.
lv_ucomm = sscrfields-ucomm. "only needed if you need to tell different events apart.
At selection-screen output.
"In here you can check if lv_ucomm = 'RB_PRCT' before doing anything
case abap_true.
when p_1.
lv_group = 'G1'.
when p_2.
lv_group = 'G2'.
when p_3.
lv_grou = ' '.
endcase.
loop at screen.
screen-active = boolc( screen-group1 is initial or screen-group1 = lv_group )
modify screen.
endloop.
Something like this will fit your needs, but if you need more processing on radio button press (and not to anything on other actions) you might want to use the SSCRFIELDS related logic to check which event is fired and only process the one that comes from your radio buttons.

Related

Multiple text lines below report selection-screen parameters based on table entries

Before executing my report I want to display the folders below the selection screen.
The folder names are stored inside a table.
Since I don't know how many entries the table has beforehand, this needs to be dynamic - not hardcoded.
This is what I've done so far:
DATA: lt_directories TYPE string_table.
DATA: lv_folders_txt TYPE string.
"Report description with test-checkbox
SELECTION-SCREEN BEGIN OF BLOCK b11 WITH FRAME TITLE title.
PARAMETERS: pa_test TYPE c AS CHECKBOX DEFAULT abap_true.
SELECTION-SCREEN COMMENT /1(20) folders.
SELECTION-SCREEN END OF BLOCK b11.
INITIALIZATION.
lt_directories = VALUE string_table( ( `FOLDER1` ) ( `FOLDER2` ) ( `FOLDER3` ) ( `FOLDER4` ) ).
title = 'This program imports data from the listed folders'.
AT SELECTION-SCREEN OUTPUT.
LOOP AT lt_directories ASSIGNING FIELD-SYMBOL(<directory>).
"TODO: this has to be changed!
lv_folders_txt = lv_folders_txt && <directory>.
ENDLOOP.
folders = lv_folders_txt.
This is how the result looks like:
And this is an example of how I want it to look like:
Does someone know an easy way to do this?
You may create a docking container at the bottom of the screen, and include any "text view" control in it, like the SAP HTML viewer for instance:
DATA: lt_directories TYPE string_table.
DATA: lv_folders_txt TYPE string.
DATA: go_docking TYPE REF TO cl_gui_docking_container.
DATA: go_html_viewer TYPE REF TO cl_gui_html_viewer.
"Report description with test-checkbox
SELECTION-SCREEN BEGIN OF BLOCK b11 WITH FRAME TITLE title.
PARAMETERS: pa_test TYPE c AS CHECKBOX DEFAULT abap_true.
SELECTION-SCREEN END OF BLOCK b11.
INITIALIZATION.
lt_directories = VALUE string_table( ( `FOLDER1` ) ( `FOLDER2` ) ( `FOLDER3` ) ( `FOLDER4` ) ).
title = 'This program imports data from the listed folders'.
AT SELECTION-SCREEN OUTPUT.
IF go_docking IS NOT BOUND.
go_docking = NEW #(
repid = sy-repid
dynnr = sy-dynnr
side = cl_gui_docking_container=>dock_at_bottom
extension = 180 ). " pixels
DATA: lv_url TYPE cndp_url.
DATA(lv_text) = |<html><body>{
REDUCE #( INIT s = `` FOR dir IN lt_directories NEXT s = |{ s }{ dir }<br>| )
}</body></html>|.
go_html_viewer = NEW cl_gui_html_viewer( parent = go_docking ).
data(soli_tab) = cl_bcs_convert=>string_to_soli( lv_text ).
go_html_viewer->load_data(
EXPORTING type = 'text' subtype = 'html' size = strlen( lv_text )
IMPORTING assigned_url = lv_url
CHANGING data_table = soli_tab ).
go_html_viewer->show_url( url = lv_url ).
ENDIF.
If you dont like to generate the dynpro or report at runtime.
If you dont want to dock a control with content.
If there is some limit of the number entries that need to be shown. eg < 100
Then there is a simple option using SELECTION-SCREEN COMMENTS
Just use place holder 100 screen comments and Default them to space.
Then set the first N dynamically.
REPORT zdemo_so.
PARAMETERS: p_test TYPE c AS CHECKBOX DEFAULT abap_true.
SELECTION-SCREEN COMMENT /5(60) folder01.
SELECTION-SCREEN COMMENT /5(60) folder02.
SELECTION-SCREEN COMMENT /5(60) folder03.
SELECTION-SCREEN COMMENT /5(60) folder04.
"... repeat to ??
SELECTION-SCREEN COMMENT /5(60) folder98.
SELECTION-SCREEN COMMENT /5(60) folder99.
initialization.
data lt_directories type string_table.
FIELD-SYMBOLS: <dirname> type string,
<lbl> TYPE any.
data lbl_nn(2) type n.
data lbl_pre(6) type c value 'FOLDER'.
data lbl_name type string.
folder01 = ''.
folder02 = ''.
folder03 = ''.
folder04 = ''.
" ...
folder98 = ''.
folder99 = ''.
lt_directories = VALUE string_table( ( `FOLDERNAME1` ) ( `FOLDERNAME2` ) ( `FOLDERNAME3` ) ( `FOLDERNAME4` ) ).
loop at lt_directories assigning <dirname>.
lbl_nn = sy-tabix.
lbl_name = LBL_pre && lbl_nn.
assign (lbl_name) to <lbl>.
<lbl> = <dirname>.
endloop.
Unfortunately there is no way to do this for COMMENT. It’ll always be displayed in one line. Even using linefeed (or carriage return + linefeed) at the end will not give you the expected result.
REPORT ZZZ.
DATA: lt_directories TYPE string_table.
DATA: lv_folders_txt TYPE string.
"Report description with test-checkbox
SELECTION-SCREEN BEGIN OF BLOCK b11 WITH FRAME TITLE title.
PARAMETERS: pa_test TYPE c AS CHECKBOX DEFAULT abap_true.
SELECTION-SCREEN COMMENT /1(20) folders.
SELECTION-SCREEN END OF BLOCK b11.
INITIALIZATION.
lt_directories = VALUE string_table( ( `FOLDER1` ) ( `FOLDER2` ) ( `FOLDER3` ) ( `FOLDER4` ) ).
title = 'This program imports data from the listed folders'.
AT SELECTION-SCREEN OUTPUT.
LOOP AT lt_directories ASSIGNING FIELD-SYMBOL(<directory>).
"TODO: this has to be changed!
lv_folders_txt = lv_folders_txt && <directory> && cl_abap_char_utilities=>newline.
ENDLOOP.
folders = lv_folders_txt.

ALV Grid custom F4 help works but then shows No help found

I have a program that displays an editable ALV grid, with a custom F4 help for the field "No." handled via the event onf4. My custom F4 help is displayed and the selected value is returned correctly.
However every time after the custom F4 help closes, another window opens saying "No input help is available".
How to get rid of this supplementary popup?
Thanks.
Here's my code:
CLASS lcl_app DEFINITION.
PUBLIC SECTION.
METHODS constructor.
METHODS display.
METHODS on_onf4
FOR EVENT onf4 OF cl_gui_alv_grid
IMPORTING e_fieldname es_row_no e_fieldvalue.
DATA: grid TYPE REF TO cl_gui_alv_grid,
spflis TYPE TABLE OF spfli.
ENDCLASS.
CLASS lcl_app IMPLEMENTATION.
METHOD constructor.
SELECT * FROM spfli INTO TABLE spflis.
grid = NEW cl_gui_alv_grid(
i_parent = cl_gui_container=>screen0 ).
SET HANDLER on_onf4 FOR grid.
grid->register_f4_for_fields(
it_f4 = VALUE #( ( fieldname = 'CONNID' register = 'X' chngeafter = 'X' ) ) ).
ENDMETHOD.
METHOD display.
DATA(fcat) = VALUE lvc_t_fcat(
( fieldname = 'CARRID' ref_table = 'SPFLI' )
( fieldname = 'CONNID' ref_table = 'SPFLI' f4availabl = 'X' ) ).
grid->set_table_for_first_display(
EXPORTING is_layout = VALUE #( edit = 'X' )
CHANGING it_outtab = spflis
it_fieldcatalog = fcat
EXCEPTIONS OTHERS = 4 ).
ENDMETHOD.
METHOD on_onf4.
DATA return TYPE TABLE OF ddshretval.
IF e_fieldname = 'CONNID'.
SELECT DISTINCT connid FROM spfli INTO TABLE #DATA(connids).
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'CONNID'
value_org = 'S'
TABLES
value_tab = connids
return_tab = return
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS = 3.
IF sy-subrc = 0 AND return IS NOT INITIAL.
FIELD-SYMBOLS <modis> TYPE lvc_t_modi.
ASSIGN er_event_data->m_data->* TO <modis>.
<modis> = VALUE #( BASE <modis> ( row_id = es_row_no-row_id
fieldname = e_fieldname
value = return[ 1 ]-fieldval ) ).
ENDIF.
ENDIF.
ENDMETHOD.
ENDCLASS.
PARAMETERS dummy.
AT SELECTION-SCREEN OUTPUT.
NEW lcl_app( )->display( ).
There's a flag er_event_data->m_event_handled which needs to be set to 'X' in the F4 method handler to say that the F4 was actually managed by the custom handling, otherwise the ALV grid attempts displaying the standard F4 (there was no standard F4 in my case hence the popup).
First add the ER_EVENT_DATA parameter in the method declaration :
METHODS on_onf4
FOR EVENT onf4 OF cl_gui_alv_grid
IMPORTING e_fieldname es_row_no e_fieldvalue
er_event_data.
Inside the method ON_ONF4, set the flag :
er_event_data->m_event_handled = 'X'.

How to disable the Editable ALV Grid in case of an incorrect entry?

Whenever an invalid value is entered in an ALV Grid, how do I disable the other fields (grey out) in the grid and force the user to fix the incorrect field.
I have tried adding protocol in DATA_CHANGED event. But protocol list only shows the error in popup. Editing is still possible and no fields are disabled.
But how do I disable the other fields. Sample behavior as shown below:
Here, the other fields are greyed out and the invalid entry is highlighted. Until the user fixes this error, he/she cannot proceed further.
Having screen 100 with container CCONTAINER1 paste this snippet
CLASS zcl_alv_test DEFINITION.
PUBLIC SECTION.
METHODS: constructor, display_grid, populate_grid.
DATA: lr_rtti_struc TYPE REF TO cl_abap_structdescr,
it_fldcat TYPE lvc_t_fcat,
grid_container1 TYPE REF TO cl_gui_custom_container,
grid1 TYPE REF TO cl_gui_alv_grid.
DATA: BEGIN OF gs_outtab.
INCLUDE TYPE spfli.
DATA: celltab TYPE lvc_t_styl.
DATA: END OF gs_outtab.
DATA gt_outtab1 LIKE TABLE OF gs_outtab INITIAL SIZE 0.
METHODS:
handle_data_changed FOR EVENT data_changed OF cl_gui_alv_grid IMPORTING er_data_changed,
handle_data_changed_finished FOR EVENT data_changed_finished OF cl_gui_alv_grid IMPORTING e_modified et_good_cells,
create_dynamic_fcat.
PRIVATE SECTION.
TYPES: ty_tab LIKE LINE OF gt_outtab1.
METHODS: refresh_grid, fill_celltab IMPORTING p_fieldname TYPE lvc_fname
CHANGING pt_celltab TYPE lvc_t_styl.
ENDCLASS.
CLASS zcl_alv_test IMPLEMENTATION.
METHOD constructor.
CREATE OBJECT grid_container1 EXPORTING container_name = 'CCONTAINER1'.
CREATE OBJECT grid1 EXPORTING i_parent = grid_container1.
SET HANDLER handle_data_changed FOR grid1.
SET HANDLER handle_data_changed_finished FOR grid1.
CALL METHOD grid1->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter.
ENDMETHOD. "constructor
METHOD fill_celltab.
LOOP AT pt_celltab ASSIGNING FIELD-SYMBOL(<fs_fcat>).
IF <fs_fcat>-fieldname = p_fieldname.
<fs_fcat>-style = cl_gui_alv_grid=>mc_style_enabled.
ENDIF.
ENDLOOP.
ENDMETHOD.
METHOD handle_data_changed.
DATA: lt_celltab TYPE lvc_t_styl.
LOOP AT it_fldcat ASSIGNING FIELD-SYMBOL(<fs_fcat>).
INSERT VALUE lvc_s_styl( style = cl_gui_alv_grid=>mc_style_disabled fieldname = <fs_fcat>-fieldname ) INTO TABLE lt_celltab.
ENDLOOP.
MODIFY gt_outtab1 FROM VALUE ty_tab( celltab = lt_celltab ) TRANSPORTING celltab WHERE connid IS NOT INITIAL.
LOOP AT er_data_changed->mt_mod_cells ASSIGNING FIELD-SYMBOL(<mods>).
READ TABLE gt_outtab1 ASSIGNING FIELD-SYMBOL(<sym>) INDEX <mods>-row_id.
fill_celltab( EXPORTING p_fieldname = <mods>-fieldname
CHANGING pt_celltab = <sym>-celltab ).
MODIFY gt_outtab1 FROM <sym> INDEX <mods>-row_id.
ENDLOOP.
refresh_grid( ).
ENDMETHOD.
METHOD handle_data_changed_finished.
DATA: lt_celltab TYPE lvc_t_styl.
LOOP AT it_fldcat ASSIGNING FIELD-SYMBOL(<fs_fcat>).
IF sy-tabix MOD 2 = 0.
DATA(style) = cl_gui_alv_grid=>mc_style_disabled.
ELSE.
style = cl_gui_alv_grid=>mc_style_enabled.
ENDIF.
INSERT VALUE lvc_s_styl( style = style fieldname = <fs_fcat>-fieldname ) INTO TABLE lt_celltab.
ENDLOOP.
MODIFY gt_outtab1 FROM VALUE ty_tab( celltab = lt_celltab ) TRANSPORTING celltab WHERE connid IS NOT INITIAL.
refresh_grid( ).
ENDMETHOD.
METHOD create_dynamic_fcat.
lr_rtti_struc ?= cl_abap_structdescr=>describe_by_name( 'SPFLI' ).
DATA(comps) = lr_rtti_struc->components.
LOOP AT comps ASSIGNING FIELD-SYMBOL(<comps>).
IF sy-tabix MOD 2 = 0.
DATA(edit) = abap_false.
ELSE.
edit = abap_true.
ENDIF.
APPEND VALUE lvc_s_fcat( edit = edit fieldname = <comps>-name datatype = <comps>-type_kind inttype = <comps>-type_kind intlen = <comps>-length decimals = <comps>-decimals coltext = <comps>-name lowercase = 'X' ) TO it_fldcat .
ENDLOOP.
ENDMETHOD. "create_dynamic_fcat
METHOD populate_grid.
SELECT * UP TO 1000 ROWS
FROM spfli
INTO CORRESPONDING FIELDS OF TABLE gt_outtab1.
ENDMETHOD. "CHANGE_TITLE
METHOD display_grid.
create_dynamic_fcat( ).
grid1->set_table_for_first_display(
EXPORTING
is_layout = VALUE lvc_s_layo( zebra = abap_true stylefname = 'CELLTAB' )
CHANGING
it_outtab = gt_outtab1
it_fieldcatalog = it_fldcat ).
ENDMETHOD. "display_grid
METHOD refresh_grid.
cl_gui_cfw=>flush( ).
grid1->refresh_table_display( ).
ENDMETHOD.
ENDCLASS.
MODULE status_0100 OUTPUT.
SET PF-STATUS 'MAIN100'.
DATA: yalv TYPE REF TO zcl_alv_test.
CREATE OBJECT yalv.
yalv->populate_grid( ).
yalv->display_grid( ).
ENDMODULE.
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN 'BACK' OR 'EXIT' OR 'RETURN'.
LEAVE PROGRAM.
WHEN OTHERS.
ENDCASE.
ENDMODULE.
START-OF-SELECTION.
CALL SCREEN 100.
It uses the concept of cell styles, where each row in table is assigned a table of styles for each of the column in this row. There you can apply conditional attributes on a cell level, including editability.
When throwing an error through builtin checktables/domains, the grid is made not editable except erroneous cell, and when correcting the error, editability returns.

Delete selected row in ALV

I have ALV table and I made a custom button in the table toolbar. Whenever the button is pressed, I want to delete the selected row. Now there's just a message showing up so I could see if the custom button is working.
METHOD on_user_command.
CASE e_salv_function.
WHEN 'MYFUNC1'.
MESSAGE i301(z_global) WITH 'Function 1'.
*Right here the row should be deleted.
WHEN 'MYFUNC2'.
MESSAGE i301(z_global) WITH 'Function 2'.
WHEN OTHERS.
ENDCASE.
ENDMETHOD.
Here is the sample code for deleting selected row:
CASE e_salv_function.
WHEN 'MYFUNC1'.
PERFORM delete_lines.
...
ENDCASE.
form delete_lines.
data: sav_tabix type lvc_index.
clear row_table.
call method grid1->get_selected_rows( et_index_rows = data(row_table) ).
loop at gt_outtab.
sav_tabix = sav_tabix + 1.
read table row_table with key index = sav_tabix.
if sy-subrc = 0.
delete gt_outtab INDEX sav_tabix.
endif.
endloop.
call method grid1->refresh_table_display.
call method cl_gui_cfw=>flush.
endform.

Allow free text in ALV Grid cell with dropdown

I have set a dropdown list for an ALV Grid cell. The dropdow works fine, but it allows to enter values from the dropdown value list only. Is it possible to allow free text entry in the cell?
My ABAP code is:
Creating a value list:
DATA: lt_dropdown TYPE lvc_t_dral,
ls_dropdown TYPE lvc_s_dral.
data: ls_taba TYPE dd07v,
lt_taba TYPE STANDARD TABLE OF dd07v,
lt_tabb TYPE STANDARD TABLE OF dd07v.
CALL FUNCTION 'DD_DOMA_GET'
EXPORTING
DOMAIN_NAME = 'ZBC_TRADE_NETWORK'
LANGU = SY-LANGU
WITHTEXT = 'X'
TABLES
DD07V_TAB_A = lt_taba
DD07V_TAB_N = lt_tabb
EXCEPTIONS
ILLEGAL_VALUE = 1
OP_FAILURE = 2
OTHERS = 3
.
IF SY-SUBRC <> 0.
return.
ENDIF.
loop at lt_taba into ls_taba.
ls_dropdown-handle = '1'.
ls_dropdown-int_value = ls_taba-domvalue_l.
ls_dropdown-value = ls_taba-ddtext.
APPEND ls_dropdown TO lt_dropdown.
endloop.
*method to display the dropdown in ALV
CALL METHOD go_grid->set_drop_down_table
EXPORTING
IT_DROP_DOWN_ALIAS = lt_dropdown.
Fill the field catalogue:
data: ls_fcat type lvc_s_fcat,
lt_fcat type lvc_t_fcat.
field-symbols: <lfs_fcat> type ls_fcat.
call function 'LVC_FIELDCATALOG_MERGE'
exporting
i_structure_name = gc_struct_name
changing
ct_fieldcat = lt_fcat
exceptions
others = 1.
loop at lt_fcat assigning <lfs_fcat>.
case <lfs_fcat>-fieldname.
when 'NETWORK'.
<lfs_fcat>-drdn_hndl = '1'.
<lfs_fcat>-drdn_alias = 'X'.
<lfs_fcat>-edit = abap_on.
endcase.
endloop.
Set ALV grid for display
go_grid->set_table_for_first_display(
exporting
i_save = lf_save
i_default = lf_default
is_variant = ls_vari
is_layout = ls_layo
it_toolbar_excluding = lt_excl
changing
it_outtab = <lfs_t_data>
it_fieldcatalog = lt_fcat
exceptions
others = 1
).
No. A drop-down field implies a fixed value set. If you want to have both a value catalog and a text editing facility, use a value help (F4 help) to implement the catalog access.