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 Dynpro - is there a way?

Former Member
0 Kudos

Hi,

This is my first question on this site though. I have a requirement to build SAP Dynpro screens for about 3 tables. Now my approach was pretty straight to use a main/sub-screen with items placed appropriately. Someone in my team came up with an idea of generating the dynpro screens dynamically. Let me explain: There should be a single program that should accept a table structure name and display a dialog control to create/change or display data (like SM30). If you want to suggest me to use SM30, some of the fields in this table are to be text areas providing for long texts. Is this possible at all? How standard it would be? How much time-effort would it take?

Its been quite sometime I did not code for dialogs, but I have never heard of dynamic dynpro's (i know dynamic sel-screens). We can do any magic using programming, but I want a feasible solution and do not want to overkill for a simple object.

Appropriate answers will be rewarded points.

Thanks in advance,

Joe

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Joseph, dynamic dynpros are possible. I would say that they are not suggested, considering the ABAP statements used to create them are "internal SAP" statements and hence will not be supported by SAP when used by a customer. Please see the following example program, you may cut/paste the code into your system to see how it works. With your requirement, i see this becoming a little complex. Is it worth it? Using SAP interal statements, overhead when generating the screen at runtime. You decide.




report zrich_0001
       no standard page heading.

data: h type table of d020s with header line,
      f type table of d021s with header line,
      e type table of d022s with header line,
      m type table of d023s with header line.
data: mess(50) type c,
      line(50) type c,
      word(50) type c.
data: dynproid(44).

dynproid = sy-repid.
dynproid+40(4) = '0100'.

h-prog = sy-repid.
h-dnum = '0100'.
append h.

f-fnam = 'P_TEST1'.
f-flg1 = '80'.
f-flg3 = '80'.
f-line = '01'.
f-coln = '03'.
f-type = 'CHAR'.
f-ityp = 'C'.
f-leng = '20'.
f-stxt = '____________________'.
append f.

f-fnam = 'P_TEST2'.
f-flg1 = '80'.
f-flg3 = '80'.
f-line = '02'.
f-coln = '03'.
f-type = 'CHAR'.
f-ityp = 'C'.
f-leng = '40'.
f-stxt = '________________________________________'.
append f.


e-line = 'PROCESS BEFORE OUTPUT.'.
append e.

e-line = 'PROCESS AFTER INPUT.'.
append e.

generate dynpro h f e m id dynproid
         message mess
         line    line
         word    word.

call screen 100.

Welcome to SDN!!!

Regards,

Rich Heilman

4 REPLIES 4

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Joseph, dynamic dynpros are possible. I would say that they are not suggested, considering the ABAP statements used to create them are "internal SAP" statements and hence will not be supported by SAP when used by a customer. Please see the following example program, you may cut/paste the code into your system to see how it works. With your requirement, i see this becoming a little complex. Is it worth it? Using SAP interal statements, overhead when generating the screen at runtime. You decide.




report zrich_0001
       no standard page heading.

data: h type table of d020s with header line,
      f type table of d021s with header line,
      e type table of d022s with header line,
      m type table of d023s with header line.
data: mess(50) type c,
      line(50) type c,
      word(50) type c.
data: dynproid(44).

dynproid = sy-repid.
dynproid+40(4) = '0100'.

h-prog = sy-repid.
h-dnum = '0100'.
append h.

f-fnam = 'P_TEST1'.
f-flg1 = '80'.
f-flg3 = '80'.
f-line = '01'.
f-coln = '03'.
f-type = 'CHAR'.
f-ityp = 'C'.
f-leng = '20'.
f-stxt = '____________________'.
append f.

f-fnam = 'P_TEST2'.
f-flg1 = '80'.
f-flg3 = '80'.
f-line = '02'.
f-coln = '03'.
f-type = 'CHAR'.
f-ityp = 'C'.
f-leng = '40'.
f-stxt = '________________________________________'.
append f.


e-line = 'PROCESS BEFORE OUTPUT.'.
append e.

e-line = 'PROCESS AFTER INPUT.'.
append e.

generate dynpro h f e m id dynproid
         message mess
         line    line
         word    word.

call screen 100.

Welcome to SDN!!!

Regards,

Rich Heilman

0 Kudos

Hi Rich,

That was definitely useful one. I learnt something for sure.

Thanks very much,

Joe

former_member186741
Active Contributor
0 Kudos

I think the SM30 approach is probably the best. Why reinvent the wheel?

But here's a low-tech rudimentary program which will accept a table name and a number of records as parameters and display the contents. It could be changed to have upadte capability. This took only an hour or two to develop, the table-control wizard did most of the work.

..............

REPORT znrw_tc_play .

SELECTION-SCREEN COMMENT 10(20) TEXT-001.

PARAMETERS: p_table TYPE tablename OBLIGATORY,

p_recs(3) type p decimals 2

default 11.

types: begin of znrw_tc,

COL01 type char20,

COL02 type char20,

COL03 type char20,

COL04 type char20,

COL05 type char20,

COL06 type char20,

COL07 type char20,

COL08 type char20,

COL09 type char20,

COL010 type char20,

end of znrw_tc.

DATA w_row TYPE znrw_tc.

DATA t_tab TYPE TABLE OF znrw_tc WITH HEADER LINE.

data w_sel.

data w_sel_col type sytabix.

FIELD-SYMBOLS: <table> TYPE ANY,

<in_column> TYPE ANY,

<out_column> TYPE any.

START-OF-SELECTION.

DATA dref TYPE REF TO data.

perform fill_table.

CALL SCREEN 0100.

*&spwizard: declaration of tablecontrol 'TC01' itself

CONTROLS: tc01 TYPE TABLEVIEW USING SCREEN 0100.

*&spwizard: lines of tablecontrol 'TC01'

DATA: g_tc01_lines LIKE sy-loopc.

DATA: ok_code LIKE sy-ucomm.

*&spwizard: output module for tc 'TC01'. do not change this line!

*&spwizard: update lines for equivalent scrollbar

MODULE tc01_change_tc_attr OUTPUT.

DESCRIBE TABLE t_tab LINES tc01-lines.

ENDMODULE. "TC01_change_tc_attr OUTPUT

*&spwizard: output module for tc 'TC01'. do not change this line!

*&spwizard: get lines of tablecontrol

MODULE tc01_get_lines OUTPUT.

g_tc01_lines = sy-loopc.

ENDMODULE. "TC01_get_lines OUTPUT

*&spwizard: input module for tc 'TC01'. do not change this line!

*&spwizard: process user command

MODULE tc01_user_command INPUT.

ok_code = sy-ucomm.

PERFORM user_ok_tc USING 'TC01'

'T_TAB'

' '

CHANGING ok_code.

sy-ucomm = ok_code.

ENDMODULE. "TC01_user_command INPUT

----


  • INCLUDE TABLECONTROL_FORMS *

----


&----


*& Form USER_OK_TC *

&----


FORM user_ok_tc USING p_tc_name TYPE dynfnam

p_table_name

p_mark_name

CHANGING p_ok LIKE sy-ucomm.

&SPWIZARD: BEGIN OF LOCAL DATA----


DATA: l_ok TYPE sy-ucomm,

l_offset TYPE i.

&SPWIZARD: END OF LOCAL DATA----


*&SPWIZARD: Table control specific operations *

*&SPWIZARD: evaluate TC name and operations *

SEARCH p_ok FOR p_tc_name.

IF sy-subrc <> 0.

EXIT.

ENDIF.

l_offset = STRLEN( p_tc_name ) + 1.

l_ok = p_ok+l_offset.

*&SPWIZARD: execute general and TC specific operations *

CASE l_ok.

WHEN 'INSR'. "insert row

PERFORM fcode_insert_row USING p_tc_name

p_table_name.

CLEAR p_ok.

WHEN 'DELE'. "delete row

PERFORM fcode_delete_row USING p_tc_name

p_table_name

p_mark_name.

CLEAR p_ok.

WHEN 'P--' OR "top of list

'P-' OR "previous page

'P+' OR "next page

'P++'. "bottom of list

PERFORM compute_scrolling_in_tc USING p_tc_name

l_ok.

CLEAR p_ok.

  • WHEN 'L--'. "total left

  • PERFORM FCODE_TOTAL_LEFT USING P_TC_NAME.

*

  • WHEN 'L-'. "column left

  • PERFORM FCODE_COLUMN_LEFT USING P_TC_NAME.

*

  • WHEN 'R+'. "column right

  • PERFORM FCODE_COLUMN_RIGHT USING P_TC_NAME.

*

  • WHEN 'R++'. "total right

  • PERFORM FCODE_TOTAL_RIGHT USING P_TC_NAME.

*

WHEN 'MARK'. "mark all filled lines

PERFORM fcode_tc_mark_lines USING p_tc_name

p_table_name

p_mark_name .

CLEAR p_ok.

WHEN 'DMRK'. "demark all filled lines

PERFORM fcode_tc_demark_lines USING p_tc_name

p_table_name

p_mark_name .

CLEAR p_ok.

  • WHEN 'SASCEND' OR

  • 'SDESCEND'. "sort column

  • PERFORM FCODE_SORT_TC USING P_TC_NAME

  • l_ok.

ENDCASE.

ENDFORM. " USER_OK_TC

&----


*& Form FCODE_INSERT_ROW *

&----


FORM fcode_insert_row

USING p_tc_name TYPE dynfnam

p_table_name .

&SPWIZARD: BEGIN OF LOCAL DATA----


DATA l_lines_name LIKE feld-name.

DATA l_selline LIKE sy-stepl.

DATA l_lastline TYPE i.

DATA l_line TYPE i.

DATA l_table_name LIKE feld-name.

FIELD-SYMBOLS <tc> TYPE cxtab_control.

FIELD-SYMBOLS <table> TYPE STANDARD TABLE.

FIELD-SYMBOLS <lines> TYPE i.

&SPWIZARD: END OF LOCAL DATA----


ASSIGN (p_tc_name) TO <tc>.

*&SPWIZARD: get the table, which belongs to the tc *

CONCATENATE p_table_name '[]' INTO l_table_name. "table body

ASSIGN (l_table_name) TO <table>. "not headerline

*&SPWIZARD: get looplines of TableControl *

CONCATENATE 'G_' p_tc_name '_LINES' INTO l_lines_name.

ASSIGN (l_lines_name) TO <lines>.

*&SPWIZARD: get current line *

GET CURSOR LINE l_selline.

IF sy-subrc <> 0. " append line to table

l_selline = <tc>-lines + 1.

*&SPWIZARD: set top line *

IF l_selline > <lines>.

<tc>-top_line = l_selline - <lines> + 1 .

ELSE.

<tc>-top_line = 1.

ENDIF.

ELSE. " insert line into table

l_selline = <tc>-top_line + l_selline - 1.

l_lastline = <tc>-top_line + <lines> - 1.

ENDIF.

*&SPWIZARD: set new cursor line *

l_line = l_selline - <tc>-top_line + 1.

*&SPWIZARD: insert initial line *

INSERT INITIAL LINE INTO <table> INDEX l_selline.

<tc>-lines = <tc>-lines + 1.

*&SPWIZARD: set cursor *

SET CURSOR LINE l_line.

ENDFORM. " FCODE_INSERT_ROW

&----


*& Form FCODE_DELETE_ROW *

&----


FORM fcode_delete_row

USING p_tc_name TYPE dynfnam

p_table_name

p_mark_name .

&SPWIZARD: BEGIN OF LOCAL DATA----


DATA l_table_name LIKE feld-name.

FIELD-SYMBOLS <tc> TYPE cxtab_control.

FIELD-SYMBOLS <table> TYPE STANDARD TABLE.

FIELD-SYMBOLS <wa>.

FIELD-SYMBOLS <mark_field>.

&SPWIZARD: END OF LOCAL DATA----


ASSIGN (p_tc_name) TO <tc>.

*&SPWIZARD: get the table, which belongs to the tc *

CONCATENATE p_table_name '[]' INTO l_table_name. "table body

ASSIGN (l_table_name) TO <table>. "not headerline

*&SPWIZARD: delete marked lines *

DESCRIBE TABLE <table> LINES <tc>-lines.

LOOP AT <table> ASSIGNING <wa>.

*&SPWIZARD: access to the component 'FLAG' of the table header *

ASSIGN COMPONENT p_mark_name OF STRUCTURE <wa> TO <mark_field>.

IF <mark_field> = 'X'.

DELETE <table> INDEX syst-tabix.

IF sy-subrc = 0.

<tc>-lines = <tc>-lines - 1.

ENDIF.

ENDIF.

ENDLOOP.

ENDFORM. " FCODE_DELETE_ROW

&----


*& Form COMPUTE_SCROLLING_IN_TC

&----


  • text

----


  • -->P_TC_NAME name of tablecontrol

  • -->P_OK ok code

----


FORM compute_scrolling_in_tc USING p_tc_name

p_ok.

&SPWIZARD: BEGIN OF LOCAL DATA----


DATA l_tc_new_top_line TYPE i.

DATA l_tc_name LIKE feld-name.

DATA l_tc_lines_name LIKE feld-name.

DATA l_tc_field_name LIKE feld-name.

FIELD-SYMBOLS <tc> TYPE cxtab_control.

FIELD-SYMBOLS <lines> TYPE i.

&SPWIZARD: END OF LOCAL DATA----


ASSIGN (p_tc_name) TO <tc>.

*&SPWIZARD: get looplines of TableControl *

CONCATENATE 'G_' p_tc_name '_LINES' INTO l_tc_lines_name.

ASSIGN (l_tc_lines_name) TO <lines>.

*&SPWIZARD: is no line filled? *

IF <tc>-lines = 0.

*&SPWIZARD: yes, ... *

l_tc_new_top_line = 1.

ELSE.

*&SPWIZARD: no, ... *

CALL FUNCTION 'SCROLLING_IN_TABLE'

EXPORTING

entry_act = <tc>-top_line

entry_from = 1

entry_to = <tc>-lines

last_page_full = 'X'

loops = <lines>

ok_code = p_ok

overlapping = 'X'

IMPORTING

entry_new = l_tc_new_top_line

EXCEPTIONS

  • NO_ENTRY_OR_PAGE_ACT = 01

  • NO_ENTRY_TO = 02

  • NO_OK_CODE_OR_PAGE_GO = 03

OTHERS = 0.

ENDIF.

*&SPWIZARD: get actual tc and column *

GET CURSOR FIELD l_tc_field_name

AREA l_tc_name.

IF syst-subrc = 0.

IF l_tc_name = p_tc_name.

*&SPWIZARD: et actual column *

SET CURSOR FIELD l_tc_field_name LINE 1.

ENDIF.

ENDIF.

*&SPWIZARD: set the new top line *

<tc>-top_line = l_tc_new_top_line.

ENDFORM. " COMPUTE_SCROLLING_IN_TC

&----


*& Form FCODE_TC_MARK_LINES

&----


  • marks all TableControl lines

----


  • -->P_TC_NAME name of tablecontrol

----


FORM fcode_tc_mark_lines USING p_tc_name

p_table_name

p_mark_name.

&SPWIZARD: EGIN OF LOCAL DATA----


DATA l_table_name LIKE feld-name.

FIELD-SYMBOLS <tc> TYPE cxtab_control.

FIELD-SYMBOLS <table> TYPE STANDARD TABLE.

FIELD-SYMBOLS <wa>.

FIELD-SYMBOLS <mark_field>.

&SPWIZARD: END OF LOCAL DATA----


ASSIGN (p_tc_name) TO <tc>.

*&SPWIZARD: get the table, which belongs to the tc *

CONCATENATE p_table_name '[]' INTO l_table_name. "table body

ASSIGN (l_table_name) TO <table>. "not headerline

*&SPWIZARD: mark all filled lines *

LOOP AT <table> ASSIGNING <wa>.

*&SPWIZARD: access to the component 'FLAG' of the table header *

ASSIGN COMPONENT p_mark_name OF STRUCTURE <wa> TO <mark_field>.

<mark_field> = 'X'.

ENDLOOP.

ENDFORM. "fcode_tc_mark_lines

&----


*& Form FCODE_TC_DEMARK_LINES

&----


  • demarks all TableControl lines

----


  • -->P_TC_NAME name of tablecontrol

----


FORM fcode_tc_demark_lines USING p_tc_name

p_table_name

p_mark_name .

&SPWIZARD: BEGIN OF LOCAL DATA----


DATA l_table_name LIKE feld-name.

FIELD-SYMBOLS <tc> TYPE cxtab_control.

FIELD-SYMBOLS <table> TYPE STANDARD TABLE.

FIELD-SYMBOLS <wa>.

FIELD-SYMBOLS <mark_field>.

&SPWIZARD: END OF LOCAL DATA----


ASSIGN (p_tc_name) TO <tc>.

*&SPWIZARD: get the table, which belongs to the tc *

CONCATENATE p_table_name '[]' INTO l_table_name. "table body

ASSIGN (l_table_name) TO <table>. "not headerline

*&SPWIZARD: demark all filled lines *

LOOP AT <table> ASSIGNING <wa>.

*&SPWIZARD: access to the component 'FLAG' of the table header *

ASSIGN COMPONENT p_mark_name OF STRUCTURE <wa> TO <mark_field>.

<mark_field> = space.

ENDLOOP.

ENDFORM. "fcode_tc_mark_lines

form fill_table.

CREATE DATA dref TYPE (p_table).

ASSIGN dref->* TO <table>.

refresh t_tab.

SELECT * UP TO p_recs ROWS

FROM (p_table)

INTO <table>.

DO 7 TIMES.

ASSIGN COMPONENT sy-index OF STRUCTURE <table> TO <in_column>.

IF sy-subrc <> 0.

EXIT.

ENDIF.

ASSIGN COMPONENT sy-index OF STRUCTURE w_row TO <out_column>.

<out_column> = <in_column>.

ENDDO.

append w_row to t_tab.

...

ENDSELECT.

endform.

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


module USER_COMMAND_0100 input.

if w_sel_col <> 0.

read table t_tab index w_sel_col.

delete t_tab where col02 <> t_tab-col02.

else.

perform fill_table.

endif.

endmodule. " USER_COMMAND_0100 INPUT

&----


*& Module line_selected INPUT

&----


  • text

----


module line_selected input.

if not w_sel is initial.

w_sel_col = sy-stepl.

endif.

endmodule. " line_selected INPUT

&----


*& Module init_100 OUTPUT

&----


  • text

----


module init_100 output.

set pf-status '100'.

clear w_sel_col.

endmodule. " init_100 OUTPUT

&----


*& Module exit_100 INPUT

&----


  • text

----


module exit_100 input.

leave to screen 0.

endmodule. " exit_100 INPUT

0 Kudos

Hi Neil,

Thanks very much for the answer. As I mentioned in my question, I was referring to SM30, but as per the scenario we cannot use SM30. This is because, all the 3 tables have some text fields of 250 characters long. As a result, I cannot use SM30 for those tables. We would never be able to provide such a screen element in any screen I guess. The only option was to build a custom dialog for the create/change and display of these entries. Now, the description fields would go out of these tables and become SAP Long texts with Text-areas on the GUI(to use Create/Save/Read text function modules).

But I thank you and Rich for your valuable answers. I felt good to recieve answers so quickly.

Cheers!

Joe