Subscreen in tab not getting refreshed - abap

I have a selection screen on which I want to change tabs dynamically. In my example tab1 should be shown if the flag p_flg1 is set otherwise tab2 is to be presented and the other one deactivated.
REPORT zzz.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE tit1.
PARAMETERS:
p_flg1 TYPE abap_bool AS CHECKBOX USER-COMMAND md DEFAULT abap_true. "Master data
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN BEGIN OF TABBED BLOCK tab FOR 20 lines.
SELECTION-SCREEN TAB (54) tab1 USER-COMMAND tab1 DEFAULT SCREEN 010.
SELECTION-SCREEN TAB (54) tab2 USER-COMMAND tab2 DEFAULT SCREEN 011.
SELECTION-SCREEN TAB (54) tab3 USER-COMMAND tab3 DEFAULT SCREEN 900.
SELECTION-SCREEN END OF BLOCK tab.
SELECTION-SCREEN BEGIN OF SCREEN 010 AS SUBSCREEN.
PARAMETERS:
p_flg2 TYPE abap_bool AS CHECKBOX.
SELECTION-SCREEN END OF SCREEN 010.
SELECTION-SCREEN BEGIN OF SCREEN 011 AS SUBSCREEN.
PARAMETERS:
p_text TYPE text.
SELECTION-SCREEN END OF SCREEN 011.
SELECTION-SCREEN BEGIN OF SCREEN 900 AS SUBSCREEN.
PARAMETERS:
p_flg3 TYPE abap_bool AS CHECKBOX.
SELECTION-SCREEN END OF SCREEN 900.
INITIALIZATION.
tit1 = 'Tit1'.
tab1 = 'Tab1'.
tab2 = 'Tab2'.
tab3 = 'Tab3'.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF screen-name = 'TAB1'.
IF p_flg1 = abap_true.
screen-active = 1.
ELSE.
screen-active = 0.
ENDIF.
ELSEIF screen-name = 'TAB2'.
IF p_flg1 = abap_true.
screen-active = 0.
ELSE.
screen-active = 1.
ENDIF.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
However what gets changed after unsetting the parameter p_flg1 is only the tab name and not the subscreen under it. It only gets changed if I switch to the tab3 and back.
After starting the program.
After unsetting the P_FLG1 only the tab name gets changed not the subscreen under it.
To work around it I have to switch to Tab3...
...and back
I assume that I need to call something, e.g. a function module after MODIFY SCREEN to execute some event (maybe PAI?) however I failed in finding any information on that.
What do I have to do to get the subscreen under the tab refreshed immediately after setting/unsetting the flag?

This is a common issue - if you disable/hide the first tab of a register, the subscreen of the first card stays in place until the user selects a different card. A register is essentially a subscreen area with a button bar on top, and if the included screen isn't changed by something, the default is displayed. You might get a better result using the "Dynamic Assignment" described here (approx. center of the page). If this doesn't work, you might have to emulate the card change after the checkbox has been changed. Of course, the simple solution would be to move the third (static) card to the front...

Related

Radiobutton runtime error in selection screen with dynamic visibility

When setting up a selection screen with dynamic visibility of the controls I ran into an unexpected runtime error DYNP_TOO_MANY_RADIOBUTTONS_ON. Reduced sample code to the following reproducible example:
REPORT ztest1.
SELECTION-SCREEN BEGIN OF BLOCK category.
PARAMETER:
rb_cata RADIOBUTTON GROUP cat USER-COMMAND selection_changed DEFAULT 'X',
rb_catb RADIOBUTTON GROUP cat.
SELECTION-SCREEN END OF BLOCK category.
SELECTION-SCREEN BEGIN OF BLOCK action.
PARAMETER:
rb_act1 RADIOBUTTON GROUP act USER-COMMAND selection_changed DEFAULT 'X' MODIF ID act,
rb_act2 RADIOBUTTON GROUP act.
SELECTION-SCREEN END OF BLOCK action.
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
CASE screen-group1.
WHEN 'ACT'.
screen-invisible = COND #( WHEN rb_cata = abap_true THEN 0 ELSE 1 ).
WHEN OTHERS.
ENDCASE.
MODIFY SCREEN.
ENDLOOP.
When selecting rb_catb and then re-selecting the first radiobuttion I get the runtime error DYNP_TOO_MANY_RADIOBUTTONS_ON with comment:
In a group of radio buttons, exactly one of the fields must be set -
meaning that must have the value 'X'. If this is not the case, one of
the following situations occurs:
- Multiple radio buttons of the group are set at the same time. This error causes the appplication to terminated and triggers the short
dump that you are currently reading.
But I'm only changing the visibility of the buttons, why am I getting an error relating to the actual active status?
The reason for this is a failure to set the exact same MODIF ID on all buttons in the radiobutton group. While the precise screen processing logic is hard to get at, it appears that all elements in the radiobutton group (RBG) need to be changed at the same time to avoid processing issues. So in the above example:
rb_act1 RADIOBUTTON GROUP act USER-COMMAND selection_changed DEFAULT 'X' MODIF ID act,
rb_act2 RADIOBUTTON GROUP act MODIF ID act.
I initially suspected issues with the ACTIVE or INVISIBLE attributes conflict but those appear unrelated. The actual reason these controls need to change in lockstep is unknown without being able to look at the screen processing logic that's likely hidden in the kernel. Note that the MODIF ID has to be the exact same, any mixing of these IDs within a single RBG will result in this runtime error.

how to leave program with f12 after write

Once I leave the selection screen in ABAP e.g. by write: How to rewrite cancel button behavior? In my shortened code below, each time I click execute and then cancel, I'm back at the selection screen :( Instead of this behavior I want to leave the program entirely when clicking in write output the red button.
PARAMETERS p_output AS CHECKBOX DEFAULT ' '.
SELECTION-SCREEN BEGIN OF SCREEN 101 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK such WITH FRAME TITLE text-001.
"...
SELECTION-SCREEN END OF BLOCK such.
SELECTION-SCREEN END OF SCREEN 101.
SELECTION-SCREEN BEGIN OF SCREEN 102 AS SUBSCREEN.
SELECTION-SCREEN BEGIN OF BLOCK such2 WITH FRAME TITLE text-002.
"...
SELECTION-SCREEN END OF BLOCK such2.
SELECTION-SCREEN END OF SCREEN 102.
SELECTION-SCREEN BEGIN OF TABBED BLOCK searchtab FOR 20 LINES.
SELECTION-SCREEN TAB (15) expert USER-COMMAND ucomm1
DEFAULT SCREEN 101.
SELECTION-SCREEN TAB (17) common USER-COMMAND ucomm2
DEFAULT SCREEN 102.
SELECTION-SCREEN END OF BLOCK searchtab.
INITIALIZATION.
expert = text-001.
common = text-002.
searchtab-prog = sy-repid.
searchtab-dynnr = 101.
searchtab-activetab = 'EXPERT_SEARCH'.
"...
AT SELECTION-SCREEN ON EXIT-COMMAND.
CASE sy-dynnr.
WHEN 1000."main screen number
CASE sy-ucomm.
WHEN 'ECAN'.
LEAVE PROGRAM.
WHEN 'DBAC' OR 'ENDE'. "execute go back
LEAVE TO SCREEN 1000." SELECTION-SCREEN 1000.
WHEN 'UCOMM1'.
searchtab-dynnr = 101."subscreen number 1
searchtab-activetab = 'EXPERT'.
WHEN 'UCOMM2'.
searchtab-dynnr = 102."subscreen number 2
searchtab-activetab = 'COMMON'.
ENDCASE.
WHEN Others.
CASE sy-ucomm.
WHEN 'ECAN'.
LEAVE PROGRAM.
WHEN 'DBAC' OR 'ENDE'. "execute go back
LEAVE TO SCREEN 1000." SELECTION-SCREEN 1000.
ENDCASE.
ENDCASE.
START-OF-SELECTION.
PERFORM say_hello.
FORM say_hello .
WRITE: 'from the write output screen I want to navigate by Cancel button or key f12',
'not back to selection screen but leave the program entirely.'.
ENDFORM. " SAY_HELLO
Here is what works, it's not pretty.
Copy GUI status INLI from program SAPMSSY0 to your own program
Change the OK code for the cancel button. To work with your example code, change it to ECAN. Also change the one in the Edit menu to be complete
As the first command in your START-OF-SELECTION use
SET PF-STATUS 'INLI'. This is assuming you named it the same
Change the AT SELECTION-SCREEN to AT USER-COMMAND
Activate, test and be amazed
This works because it removes the standard behavior for lists and replaces it with your own, only for the cancel button mind you. Without changing the OK code for cancel the standard SAP code will take over and you have no control over the behavior.

Obligatory field check ignored if TABBED BLOCK used

I have the following program.
REPORT zz_tab_strip_obligatory.
SELECTION-SCREEN BEGIN OF TABBED BLOCK tab FOR 20 LINES.
SELECTION-SCREEN TAB (54) tab1 USER-COMMAND tab1 DEFAULT SCREEN 100.
SELECTION-SCREEN TAB (54) tab2 USER-COMMAND tab2 DEFAULT SCREEN 200.
SELECTION-SCREEN END OF BLOCK tab.
SELECTION-SCREEN BEGIN OF SCREEN 100 AS SUBSCREEN.
PARAMETERS:
p1 TYPE i.
SELECTION-SCREEN END OF SCREEN 100.
SELECTION-SCREEN BEGIN OF SCREEN 200 AS SUBSCREEN.
PARAMETERS:
p2 TYPE i OBLIGATORY.
SELECTION-SCREEN END OF SCREEN 200.
INITIALIZATION.
tab1 = 'Tab1'.
tab2 = 'Tab2'.
The first tab has no obligatory fields. The second one on the other hand does.
The problem I am having is that if the user does not go to the second tab and instead of it starts the program immediately with F8 then the obligatory check for the parameters p2 is not performed at all. It looks like all of the events like AT SELECTION-SCREEN are executed only for the current tab ergo for the displayed subscreen.
Is there any way to work around it? My current solution right now is sadly getting rid of OBLIGATORY keywords and making the checks after START-OF-SELECTION (my real program has many tabs).
I do not think there is a direct solution to the selection screen obligatory issue. Here is a similar topic. However, you can store all the obligatory parameters in an internal table. At the Start-of-selection, loop through them and check them.
DATA: BEGIN OF gt_obl_fields OCCURS 0,
fname TYPE char10,
ftext type char50,
END OF gt_obl_fields.
INITIALIZATION.
tab1 = 'Tab1'.
tab2 = 'Tab2'.
gt_obl_fields-fname = 'P2'.
gt_obl_fields-ftext = text-001.
APPEND gt_obl_fields.
"...
START-OF-SELECTION.
LOOP AT gt_obl_fields .
ASSIGN (gt_obl_fields-fname) TO FIELD-SYMBOL(<fs_field>).
IF <fs_field> IS ASSIGNED AND <fs_field> IS INITIAL..
CONCATENATE gt_obl_fields-ftext 'field must be filled!' INTO data(lv_message).
MESSAGE lv_message TYPE 'E'.
ENDIF.
ENDLOOP.

Dynamically fill selection-screen parameter on change

Suppose I have a selection-screen block with two parameters. I want to dynamically fill the second parameter based on what the user inputs in the first, for instance by querying a table to find the expected value for the key field in parameter 1.
As an example, say I have a program that does something for a combination of order number (p_aufnr) and WBS element (p_wbs). Instead of asking the user to provide both, I can determine one of them from the PSPEL field on the AUFK table. However, I still want to show this field to the user after he inputs his order number so he can verify that the WBS element is correct.
I've managed to do this by using the AT SELECTION SCREEN ON p_aufnr event to assign a value to p_wbs. This event is processed when the user presses enter. However, I can only ever get it to work once. So if the user enters an order number, realises from the retrieved WBS element that he made a mistake and changes it, the second parameter never changes. Even though the AT SELECTION SCREEN event is processed in the debugger, the parameter is not updated.
Am I not supposed to use this event for my scenario? If so, how would I then implement this sort of dynamic selection screen?
Forgot to add a code sample. The following report illustrates my issue: after entering a value in p_netw and pressing enter, p_wbs is filled with the value 1. However, if you press enter again the AT SELECTION-SCREEN ON routine is processed but the value for p_wbs is not updated, while lv_count is.
DATA: lv_count TYPE i.
SELECTION-SCREEN BEGIN OF BLOCK main.
PARAMETERS: p_netw TYPE aufnr OBLIGATORY MODIF ID auf.
PARAMETERS: p_wbs TYPE i MODIF ID psp.
SELECTION-SCREEN END OF BLOCK main.
AT SELECTION-SCREEN ON p_netw.
ADD 1 TO lv_count.
p_wbs = lv_count.
START-OF-SELECTION.
PERFORM main.
FORM main.
WRITE: 'The value reached ', lv_count.
ENDFORM.
Apparently the data is not written back to the screen if you update the field in the field-specific block. If you move the field update from AT SELECTION-SCREEN ON p_netw to the global AT SELECTION-SCREEN event, it works. Don't ask me why, though - this seems to a case of undocumented system behaviour...
DATA: lv_count TYPE i.
SELECTION-SCREEN BEGIN OF BLOCK main.
PARAMETERS: p_netw TYPE aufnr OBLIGATORY MODIF ID auf.
PARAMETERS: p_wbs TYPE i MODIF ID psp.
SELECTION-SCREEN END OF BLOCK main.
AT SELECTION-SCREEN ON p_netw.
ADD 1 TO lv_count.
AT SELECTION-SCREEN.
p_wbs = lv_count.
You need to use a PAI (process after input) module on your screen which then takes the new p_aufnr and finds the appropriate p_wbs - probably exactly like your at selection screen event. You will then CALL SCREEN ### <-- your screen number to display the data on your screen. Without any code to work off thats all i can help with.

Hide a obligatory parameter when changing radio buttons

I have some radiobuttons and when I change between them some blocks appear/disappear.
However, if I set parameters as obligatory or required they do not hide unless I fill them. I want to make parameters required but I need to hide them when I change the radiobutton option.
I guess it's a selection screen...
then loop at your screen and check the value of "YOUR_RADIO_BUTTON"
enable or disable the blocks
AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
* Radio button parameter = P_RADIO
* hide the parameter named "to_hide"
IF P_RADIO EQ 'X' AND SCREEN-NAME CS 'TO_HIDE'.
SCREEN-INPUT = 0.
MODIFY SCREEN.
ENDIF.
* display the parameter named "to_hide"
IF P_RADIO <> 'X' AND SCREEN-NAME CS 'TO_HIDE'.
SCREEN-INPUT = 1.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
If you use PARAMETERS ... OBLIGATORY, this is an unconditional statement - this parameter is required regardless of the other settings. If you need a conditional check, you have to code it for yourself:
PARAMETERS p_chkbuk AS CHECKBOX.
PARAMETERS p_bukrs TYPE bukrs.
AT SELECTION-SCREEN ON p_bukrs.
IF p_chkbuk = abap_true AND p_bukrs IS INITIAL.
MESSAGE 'You need to enter something.' TYPE 'I' DISPLAY LIKE 'E'.
ENDIF.