Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic selection-screen in a method

Former Member
0 Kudos

<b>I need to generate selection-screen dynamically from a method of the class.</b>

There are can be select options and parameters on the selection-screen.

At runtime, it's needed to generate a program containing selection-screen and pass a table into the program in order to get results of the user selection (there should be a query to the database in the program). Notice, that dynamic program is called from a method of the class.

Best regards.

9 REPLIES 9

Former Member
0 Kudos

Hi Mikola,

Although a rare requirement, this is possible. I can give you a few pointers to how it can be done.

Read the F1 documentation for the following -

1. INSERT REPORT

2. GENERATE DYNPRO

Regards,

Anand Mandalika.

0 Kudos

Using INSERT REPORT, I have no way to pass my table to get the selection results.

0 Kudos

Hi Mikola,

Firstly, have a look at the following code to see how this can be implemented -


REPORT ZTEST.

perform test.


class test definition.
  public section.
    methods: create_screen.
endclass.

class test implementation.
  method create_screen.
    data:  report_line(72),
           report_source like table of report_line.

    data: err_message(240),
          err_line type i,
          err_word(100).

    report_line = 'REPORT TEST.'.
    append report_line to report_source.

    report_line = 'PARAMETERS: P_TEST TYPE I.'.
    append report_line to report_source.

    report_line = 'START-OF-SELECTION.'.
    append report_line to report_source.

    report_line = 'WRITE : P_TEST.'.
    append report_line to report_source.

    syntax-check for report_source message err_message
                                   line    err_line
                                   word    err_word.
    if err_message is initial.
      INSERT REPORT 'ZZZTESTZZZ' FROM REPORT_SOURCE.
      SUBMIT ZZZTESTZZZ VIA SELECTION-SCREEN AND RETURN.
    endif.
  endmethod.
endclass.

form test.
  data test type ref to test.
  CREATE OBJECT TEST.
  call method test->create_screen.
endform.

As you can see, the report is being written dynamically. Once the INSERT REPORT statement is executed, the program is available. you can you <i>external subroutine calls</i> to pass the data between the programs now.

Regards,

Anand Mandalika.

0 Kudos

Hi,

Just check this code sample.This is the sample I got in SDN some time back.May be this can help you.If so,reward points.

START-OF-SELECTION.

PERFORM DYNAMIC_CODE.

FORM DYNAMIC_CODE.

APPEND 'REPORT ZSEARCH NO STANDARD PAGE HEADING.' TO ITAB.

APPEND 'TABLES : DD03L,DD02L.' TO ITAB.

DATA TAB LIKE TEXTPOOL OCCURS 0 WITH HEADER LINE.

APPEND 'SELECTION-SCREEN BEGIN OF BLOCK BLK' TO ITAB.

APPEND 'WITH FRAME TITLE TEXT-001.' TO ITAB.

DO P4 TIMES.

REC_CNT = SY-INDEX.

CONDENSE REC_CNT NO-GAPS.

IF P1 = 'X'.

CONCATENATE 'PARAMETERS:F' REC_CNT

' LIKE DD03L-FIELDNAME OBLIGATORY.'

INTO WA.

APPEND WA TO ITAB.

TAB-ID = 'S'.

CONCATENATE 'F' REC_CNT INTO WA.

TAB-KEY = WA.

CONCATENATE'$$$$$$$$' 'Field Name' REC_CNT INTO WA.

TAB-ENTRY = WA.

ENDIF.

IF P2 = 'X'.

CONCATENATE 'PARAMETERS:D' REC_CNT

' LIKE DD03L-ROLLNAME OBLIGATORY.'

INTO WA.

APPEND WA TO ITAB.

TAB-ID = 'S'.

CONCATENATE 'D' REC_CNT INTO WA.

TAB-KEY = WA.

CONCATENATE'$$$$$$$$' 'Data Element' REC_CNT INTO WA.

TAB-ENTRY = WA.

ENDIF.

IF P3 = 'X'.

APPEND 'SELECTION-SCREEN BEGIN OF LINE.' TO ITAB.

CONCATENATE 'SELECTION-SCREEN COMMENT (15) FOR FIELD DT'

REC_CNT '.' INTO WA.

APPEND WA TO ITAB.

CONCATENATE 'PARAMETERS:DT' REC_CNT

' LIKE DD03L-DATATYPE OBLIGATORY.'

INTO WA.

APPEND WA TO ITAB.

CONCATENATE 'SELECTION-SCREEN COMMENT (16) FOR FIELD SIZE'

REC_CNT '.' INTO WA.

APPEND WA TO ITAB.

CONCATENATE 'PARAMETERS:SIZE' REC_CNT

' LIKE DD03L-LENG OBLIGATORY.' INTO WA.

APPEND WA TO ITAB.

APPEND 'SELECTION-SCREEN END OF LINE.' TO ITAB.

TAB-ID = 'S'.

CONCATENATE 'DT' REC_CNT INTO WA.

TAB-KEY = WA.

CONCATENATE'$$$$$$$$' 'Data Type' REC_CNT INTO WA.

TAB-ENTRY = WA.

APPEND TAB.

TAB-ID = 'S'.

CONCATENATE 'SIZE' REC_CNT INTO WA.

TAB-KEY = WA.

CONCATENATE'$$$$$$$$' 'Len. of Field' REC_CNT INTO WA.

TAB-ENTRY = WA.

ENDIF.

APPEND TAB.

ENDDO.

APPEND 'SELECTION-SCREEN END OF BLOCK BLK.' TO ITAB.

ENDFORM. " DYNAMIC_CODE

Former Member
0 Kudos

But... How can I get a table with results back from generated report?

0 Kudos

Hi Mikola,

When you call a subroutine (regardless of whether the subroutine is in the same program or another one), all the tables parameters will be passed by reference.

So at the end of the subroutine call, the tables parameter will contain the values that you desire.

Regards,

Anand Mandalika.

0 Kudos

I guess it won't work because of unavailability to access select-option tables(which resides in the generated report memory context) from my program (where I perform a form from the generated report) .

0 Kudos

Hi Mikola,

I'm not getting the prefect picture of your problem yet.

1. where is the subroutine defined? in the generated program or in the calling program ?

2. where do you want to call the subroutine from ?

3. what are the elements you have on the selection-screen of the generated program?

4. What are the parameters you want to pass to the subroutine when you call it ?

Regards,

anand mandalika.

0 Kudos

1. The subroutine is defined in the generated program.

2. It is called from "static" program (from a method).

3. These elements are generated dynamically during runtime in the method (entire dynamic report is generated in the method).

4. There are select options and parameters in the generated report and I want a user to fill them. According to the user selection a query should be executed after END-OF-SELECTION event and the results of the query I want to get back from the generated report.

I have found appropriate function module to implement this task (FREE_SELECTIONS_INIT). So I think I can close the thread.

Thank you for the help.

Best regards