Search code examples
reportabapdynpro

Execute a report program on radio button with validations?


I am trying to run 2 report programs, REPORTS_1 and REPORTS_2. The first program REPORTS_1 should only be executed if the first radio button is selected and all the parameters are filled in(parameter fields are always mandatory?). And the second program REPORTS_2 should only be executed if the second radio button is selected and all the corresponding parameters are filled in. Below is the code. Is this the place and correct way to call SUBMIT?

* Selection screen 1
SELECTION-SCREEN BEGIN OF BLOCK flight_block WITH FRAME TITLE text-002.
    PARAMETERS: carrid TYPE sbook-carrid MODIF ID sc1.
    PARAMETERS: connid TYPE sbook-connid MODIF ID sc1.
    PARAMETERS: 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-003.
    PARAMETERS: 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'.
         PERFORM modify_screen. "Calling subroutine
         SUBMIT Z15081947_MINI_REPORTS_1 AND RETURN. " Issue???
     ELSEIF rad_cus = 'X' AND screen-group1 = 'SC1'.
         PERFORM modify_screen. "Calling subroutine
         SUBMIT Z15081947_MINI_REPORTS_2 AND RETURN. " Issue???
     ENDIF.
 ENDLOOP.
* Subroutines.
FORM modify_screen.
 screen-active = 0.
 MODIFY SCREEN.
ENDFORM.

Solution

  • I don't see the radiobutton declaration. I assume it's something like:

    PARAMETERS rad_flt type char01 RADIOBUTTON GROUP g1 DEFAULT 'X' USER-COMMAND RAD.
    PARAMETERS rad_cus type char01 RADIOBUTTON GROUP g1.
    

    Here the USER-COMMAND RAD part triggers a PBO/PAI immediately after a radiobutton change.

    About the call of the reports: the event AT SELECTION-SCREEN OUTPUT is not the proper place for a SUMBIT statement, since it will be called at PBO, potentially not allowing the user to display the selection screen at all.

    It's a more common practice to only change the screen fields (fields deactivation) in AT SELECTION-SCREEN OUTPUT

    AT SELECTION-SCREEN OUTPUT.
    * Toggle the selection screens based on radio buttons
       LOOP AT SCREEN.
         IF rad_flt = 'X' AND screen-group1 = 'SC2'.
             PERFORM modify_screen. "Calling subroutine
         ELSEIF rad_cus = 'X' AND screen-group1 = 'SC1'.
             PERFORM modify_screen. "Calling subroutine
         ENDIF.
     ENDLOOP.
    

    and to perform the remaining logic in START-OF-SELECTION part for example:

    START-OF-SELECTION.
      CASE 'X'.
      WHEN rad_flt.
        IF carrid IS NOT INITIAL AND
           connid IS NOT INITIAL AND
           fldate IS NOT INITIAL.
          SUBMIT Z15081947_MINI_REPORTS_1 AND RETURN.
        ENDIF.
      WHEN rad_cus.
        IF customid IS NOT INITIAL.
          SUBMIT Z15081947_MINI_REPORTS_2 AND RETURN.
        ENDIF.
      ENDCASE.