Deep
Deep

Reputation: 99

How to include a selection screen into another screen

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?

Upvotes: 2

Views: 9087

Answers (1)

Sandra Rossi
Sandra Rossi

Reputation: 13656

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> and SELECTION-SCREEN END OF SCREEN <any-screen-number>), and adding the words "AS SUBSCREEN" after BEGIN OF SCREEN <any-screen-number>). For example:

SELECTION-SCREEN BEGIN OF SCREEN 1001 AS SUBSCREEN.
    PARAMETERS test AS CHECKBOX.
SELECTION-SCREEN END OF SCREEN 1001.

If you have to include an existing selection screen, which is not yet defined as a subscreen, there are two main possibilities:

  1. If it was already defined as a "standalone screen" (with SELECTION-SCREEN BEGIN OF SCREEN ...), and it's to be used only as a subscreen, you may simply add AS SUBSCREEN as said above.
  2. If it has to be used both as a subscreen and as a normal screen, then the most simple solution is to wrap its elements inside a block (ABAP statements SELECTION-SCREEN BEGIN OF BLOCK <block ID> and SELECTION-SCREEN END OF BLOCK <block ID>), and define another selection screen which includes this block (ABAP statement SELECTION-SCREEN INCLUDE BLOCKS <block ID>).

Below are two examples for the case 2.

Example 1, with the default selection screen (1000 cf footnote)

  • Before:
REPORT zprg1.

PARAMETERS test AS CHECKBOX. " screen 1000 cf footnote
  • After:
REPORT zprg1.

SELECTION-SCREEN BEGIN OF BLOCK b1000.
    PARAMETERS test AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK b1000.

SELECTION-SCREEN BEGIN OF SCREEN 1001 AS SUBSCREEN.
    SELECTION-SCREEN INCLUDE BLOCKS b1000.
SELECTION-SCREEN END OF SCREEN 1002.

Example 2 with a Standalone selection screen (1002, included using CALL SUBSCREEN subarea INCLUDING 'ZPRG1' '1002'.)

  • Before:
REPORT zprg1.

SELECTION-SCREEN BEGIN OF SCREEN 1002.
    PARAMETERS test AS CHECKBOX.
SELECTION-SCREEN END OF SCREEN 1002.
  • After:
REPORT zprg1.

SELECTION-SCREEN BEGIN OF SCREEN 1002.
SELECTION-SCREEN BEGIN OF BLOCK b1002.
    PARAMETERS test AS CHECKBOX.
SELECTION-SCREEN END OF BLOCK b1002.
SELECTION-SCREEN END OF SCREEN 1002.

SELECTION-SCREEN BEGIN OF SCREEN 1003 AS SUBSCREEN.
    SELECTION-SCREEN INCLUDE BLOCKS b1002.
SELECTION-SCREEN END OF SCREEN 1003.

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 using SELECTION-SCREEN BEGIN OF SCREEN 1000... leads to a syntax error.

Upvotes: 3

Related Questions