Application Development and Automation 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: 
Read only

Dynamic Include Programming - Calling Includes dynamically at runtime

Former Member
0 Likes
3,477

Hi,

The scenario is ....

there is a Z table consisting of Include Names and partner names. In the program we do a select query and select the name of the appropriate include into a variable name.

select INCLUDE_NAME from table where...... into VAR.

I want to do something like Include VAR.

I cannot use a CASE statement on the variable. I have tried Include (VAR). It does not work.

The Question is how to execute the code in the Include Name fetched at runtime ????

Please suggest some dynamc way of executing the code in the Include.

Edited by: rahulgo26 on Sep 20, 2011 7:40 PM

13 REPLIES 13
Read only

Former Member
0 Likes
2,112

Hi we can cnnot call the include dynamically.

But you can call the perform routines or reports dynamically.

SUBMIT (w_rname) USING SELECTION-SET p_var

EXPORTING LIST TO MEMORY

AND RETURN.

Read only

0 Likes
2,112

Hi,

How do you intend to call the code in the include ? Do you know for example that subroutines that you would like to call in the selected include before hand.

If yes,

then may use INSERT REPORT XXXXX from <itab> and create a new report. Do a submit to the report to execute the report.

DATA: code TYPE TABLE OF rssource-line,

lwa_code type rssource-line.

APPEND 'REPORT ZTEST_INCLUDE_1' to code.

CONCATENATE 'INCLUDE'

'BDCRECXX' " fetch the include name form ur Z table here

INTO lwa_code.

APPEND lwa_code to code.

INSERT REPORT 'ZTEST_INCLUDE_1' FROM code.

Read only

0 Likes
2,112

if i do a SUBMIT the error is that only TYPE-1 programs can be used in a SUBMIT statement and not TYPE I programs.

My requirement is that there are some Includes already present in the system, I need to ececute the include code dynamically at runtime based on a condition.

So PERFORM cannot be used as the Includes are already there, and these are not subroutines, converting the Includes to Subroutines might be an option, but that shall be the last option for me.

I have already tried.....

READ REPORT and INSERT REPORT statements but the include is not getting executed.

So I created a blank include program in the system and then inserted the code into it from the internal table using Insert and Read Report statements.

But here the problem is that the Include is not getting overwritten the next time I want to place the code of the next include. If the Include is blank then it works fine.

Is there a solution for this, apart from whatever I have tried ????

Edited by: rahulgo26 on Sep 21, 2011 9:31 AM

Read only

0 Likes
2,112

And one more query is

Can we do this dynamic programming thing in Quality and Production systems where we do not have WRITE access to programs.

Read only

0 Likes
2,112

Hi,

I advice you to first learn what we do in development system,quality system & production system before getting into development

Everything is dealed with transports.

If there are includes alraedy existing then right now i am not getting any idea for your question.

Have a look at link:[Creating and Starting Temporary Subroutines |http://help.sap.com/saphelp_nw04/helpdata/en/9f/db999535c111d1829f0000e829fbfe/content.htm].( Not sure ).

Kesav

Read only

0 Likes
2,112

Hi Kesav,

First try to understand the question then answer. I have told twice that the issue is not with SUBROUTINES but with INCLUDES.

Secondly,

I am asking you not to edit programs in Quality and Prod systems and I also know that everything is dealt with transports. My Question was

IS DYNAMIC PROGRAMMING POSSIBLE IN THE QUALITY AND PROD SYSTEMS.

And the second question is if the name of the Include is in a Variable Name then how can you execute the code in the include ??

Now can u get my question Kesav ??????

Moderator message: please show more respect towards those who are trying to help you. You are asking for help, after all.

Edited by: Thomas Zloch on Sep 22, 2011 11:21 AM

Read only

0 Likes
2,112

Includes can be used inside a subroutine. So try to generate subroutine.

Kesav

Read only

0 Likes
2,112

hi Keshav,

sorry for sounding inappropriate.

The problem with using subroutines is the missing data declarations error which would not be case if the Include code can be executed.

for example :

exit include code.

data : .........

perform sub -


> form sub. missing declarations which are present in the exit include.

BUT.....

If I can do something like this.

exit include code.

data : .........

Include sub.

Then the missing declarations wont be a problem.

Read only

kesavadas_thekkillath
Active Contributor
0 Likes
2,112

Hi,

You can use the PERFORM command to call an ABAP subroutine (form) from any program.

Write the code as subroutines in your include. Then use perform <routine> in program........ I dont have a sap access now to check with a dynamic call example. Try to check it.

Check the syntax with F1 help.

BR

Kesav

Read only

Former Member
0 Likes
2,112

Hi,

Try with

GENERATE REPORT 'INCLUDENAME'.

Note this statement is marked as Internal use.

Regards,

Ravi.

Edited by: rshankar on Sep 21, 2011 5:12 PM

Read only

Former Member
0 Likes
2,112

add a include with fix name into your include then create this fix named include dynamicly.

DATA: CODE(72) OCCURS 0,

PROG(8) value 'zinc_fix',

MSG(120), LIN(3), WRD(10), OFF(3).

select ztable to inttable " ztable contains includes name.

APPEND 'INCLUDES:" TO CODE.

loop at inttable.

concatanate inttable-includename ',' into code.

append code. clear code.

endloop.

APPEND "." TO CODE.

GENERATE SUBROUTINE POOL CODE NAME PROG

take care.

Çağatay

Read only

Former Member
0 Likes
2,112

Normally program code in an include is written in routines. But in your case you need to include an include with plain program code?

Can you give an example of such an include?

Now, if i want to include some external program code, i'd simply add the statement

INCLUDE <insert_include_name_here>.

If i want to do that dynamically, i would try:

INCLUDE gv_some_include_name.

If i want to do it conditionally, i would try:

IF <some_condition>.
  INCLUDE gv_some_include_name..
ENDIF.

But... then i'll have the problem of data declarations of variables in that include.

Read only

Former Member
0 Likes
2,112

Hello Rahul

I don't think we can have dynamic include.

I will propose something else that can do similar job.

1. Create a customized class. Example "ZCL_INCLUDE"

2. Create all the variables, needed by the program and shared throught each include, into the class itself.

3. Create one method by include you would like to use dynamically

4. The ztable containing the include name should now contain the method name.

the following code will execute each method defined into the ztable.

loop at ztable.

  call method zcl_include=>(ztable-methodname).

endloop.

I hope that can help.

Regards

Daniel