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: 

subroutines ?

Former Member
0 Kudos

Hi Experts,

When do we basically look forward to use dynamic subroutines ?

Regards

Pranhsu

2 REPLIES 2

Former Member
0 Kudos

hi rastogi,

Below example explains how to create a select query with dynamically selecting the fieldnames:

Sample code:

REPORT zdynamic_sql_test4.

TABLES: bkpf, t001.

**Internal table for dynamic field name selection

DATA: BEGIN OF itab_fieldname OCCURS 0,

fieldname TYPE dd03l-fieldname,

END OF itab_fieldname.

**Internal table for selection of data

DATA: BEGIN OF itab_selection OCCURS 0,

bukrs TYPE bkpf-bukrs,

belnr TYPE bkpf-belnr,

END OF itab_selection.

**Selection screen parameters

PARAMETERS : p_bukrs TYPE t001-bukrs,

p_belnr TYPE bkpf-belnr.

IF NOT p_bukrs IS INITIAL.

SELECT SINGLE *

FROM t001

WHERE bukrs EQ p_bukrs.

**If user has entered value for BUKRS on selection screen, Insert the

**fieldname for dynamic selection.

IF sy-subrc EQ 0.

INSERT 'BUKRS' INTO itab_fieldname INDEX 1.

ENDIF.

IF NOT p_belnr IS INITIAL.

SELECT SINGLE *

FROM bkpf

WHERE belnr EQ p_belnr.

**If user has entered BUKRS as well as BELNR on selection screen,

**Insert the fieldname for dynamic selection.

IF sy-subrc IS INITIAL.

INSERT 'BELNR' INTO itab_fieldname INDEX 2.

ENDIF.

ENDIF.

ELSE.

IF NOT p_belnr IS INITIAL.

SELECT SINGLE *

FROM bkpf

WHERE belnr EQ p_belnr.

**If user has entered only BELNR on selection screen,

**Insert the fieldname for dynamic selection.

IF sy-subrc IS INITIAL.

INSERT 'BELNR' INTO itab_fieldname INDEX 1.

ENDIF.

ENDIF.

ENDIF.

**Selection of fields using dynamic feidname selection

SELECT (itab_fieldname)

FROM bkpf

INTO TABLE itab_selection

WHERE bukrs EQ p_bukrs

OR belnr EQ p_belnr.

The ability of Dynamic Open SQL is far more than just what explained in this paper, however using these simple examples we understand that there is always a way to develop our Open SQL queries in dynamic form and reducing a potential coding time and increasing the maintainability.

If there is a particular requirement where in you are not able to use these basic principles, one can write the dynamic subroutines pools to achieve the same.

i think this will help u

reagards,

sindhu.

Former Member
0 Kudos

hi check this..

/people/ravishankar.rajan/blog/2007/03/27/using-subroutine-pools-for-dynamic-programming

regards,

venkat