I need to include a selection screen of a given program (ZPRG1) into another program's (ZPRG2) subscreen (100).
When I run the program ZPRG2 below, before any screen is displayed, there is the runtime error DYNP_WRONG_SCREEN_TYPE (Wrong screen type: The screen has either been defined incorrectly or is being used incorrectly).
ZPRG1 (selection screen 1000 with one field TEST):
REPORT zprg1.
PARAMETERS test AS CHECKBOX.
ZPRG2:
REPORT zprg2.
CALL SCREEN 100.
MODULE pai INPUT.
SET SCREEN 0. " close screen (all the time)
ENDMODULE.
Screen 100: (of ZPRG2)
The screen layout defines the subscreen area SUBAREA, and any number of elements, and the flow logic is as follows:
PROCESS BEFORE OUTPUT.
CALL SUBSCREEN subarea INCLUDING 'ZPRG1' '1000'.
PROCESS AFTER INPUT.
CALL SUBSCREEN subarea.
MODULE pai.
How to prevent the runtime error?
In the dynpro technology, to include a screen "A" into a screen "B", the screen "A" must be defined as a subscreen and the screen "B" must define a "subscreen area" to contain the screen "A". The flow logic of the screen "B" must contain the statement
CALL SUBSCREEN <subscreen_area> INCLUDING ..., which refers to the subscreen number to include either statically or via a global variable.As with a normal screen, a selection screen can also be defined as a subscreen by defining it as a "standalone selection screen" (wrapping its elements inside the ABAP statements
SELECTION-SCREEN BEGIN OF SCREEN <any-screen-number>andSELECTION-SCREEN END OF SCREEN <any-screen-number>), and adding the words "AS SUBSCREEN" afterBEGIN OF SCREEN <any-screen-number>). For example:If you have to include an existing selection screen, which is not yet defined as a subscreen, there are two main possibilities:
SELECTION-SCREEN BEGIN OF SCREEN ...), and it's to be used only as a subscreen, you may simply addAS SUBSCREENas said above.SELECTION-SCREEN BEGIN OF BLOCK <block ID>andSELECTION-SCREEN END OF BLOCK <block ID>), and define another selection screen which includes this block (ABAP statementSELECTION-SCREEN INCLUDE BLOCKS <block ID>).Below are two examples for the case 2.
Example 1, with the default selection screen (1000 cf footnote)
Example 2 with a Standalone selection screen (1002, included using
CALL SUBSCREEN subarea INCLUDING 'ZPRG1' '1002'.)Footnote:
(1) The selection screen parameters which are not placed inside
SELECTION-SCREEN BEGIN OF SCREEN ... END OF SCREEN ...are implicitly part of the "default selection screen" (1000). Note that usingSELECTION-SCREEN BEGIN OF SCREEN 1000...leads to a syntax error.