‎2005 Dec 06 6:34 PM
Hello gurus..
My if conditions are maintained in a table and it will look like
00000219|001|T|SMC|04|02|EQ|O|35
00000219|002|T|SMC|04|02|EQ|O|75
first 2 rows are key fields.. These 2 entries in the the database table will convert into
<b>IF SMC4(2) = 35 OR SMC4(2) = 75
ENDIF.</b>
Lets say i build this if condition in an internal table somehow.. How do I make the ABAP compiler execute something in the internal table??
Regards
Sudhakar
‎2005 Dec 06 6:40 PM
‎2005 Dec 06 6:41 PM
Hi Sudhakar,
Look into Dynamic Report / Subroutine generation GENERATE REPORT / GENERATE SUBROUTINE POOL itab NAME name.
You can use REPLACE statement to change your IF condition based on table entry..
Hope this helps.
-Bharat
‎2005 Dec 06 6:58 PM
Check this out, throw it in debug and whatch it execute.
report zrich_0001
no standard page heading.
types: t_source(72).
data: routine(32) value 'TEMP_ROUTINE',
program(8),
message(128),
line type i.
data: isource type table of t_source,
xsource type t_source.
start-of-selection.
xsource = 'REPORT ZTEMP_REPORT.'.
insert xsource into isource index 1.
xsource = 'FORM &.'.
replace '&' with routine into xsource.
insert xsource into isource index 2.
* Enter your logic here.....
xsource = 'Data: this, that.'.
append xsource to isource.
xsource = 'IF This = that.'.
append xsource to isource.
xsource = 'Write:/ ''This is = that''.'.
append xsource to isource.
xsource = 'ENDif.'.
append xsource to isource.
xsource = 'ENDFORM.'.
append xsource to isource.
generate subroutine pool isource name program
message message
line line.
if sy-subrc = 0.
perform (routine) in program (program).
else.
write:/ message.
endif.
Regards,
Rich Heilman
‎2005 Dec 07 8:15 PM
Hi Rich -
Everything looks good buy I want to have "USING" and "CHANGING" as a part of the subroutine.. Like
You have said
<i>perform (routine) in program (program)</i>
I want to say
<i>perform (routine) in program (program) (xx)</i>
xx should contain the USING and CHANGING Parameters dynamically.. I get a syntax error as I am unable to pass xx dynamically..
Can the GENERATE PROGRAM create a include program??
Regards
Sudhakar
‎2005 Dec 07 8:22 PM
I don't believe that you are allowed to having parameters dynamically. You can do something like this.
report zrich_0001
no standard page heading.
types: t_source(72).
data: routine(32) value 'TEMP_ROUTINE',
program(8),
message(128),
line type i.
data: isource type table of t_source,
xsource type t_source.
start-of-selection.
xsource = 'REPORT ZTEMP_REPORT.'.
insert xsource into isource index 1.
<b> xsource = 'FORM & using message.'.</b>
replace '&' with routine into xsource.
insert xsource into isource index 2.
* Enter your logic here.....
xsource = 'Data: this, that.'.
append xsource to isource.
xsource = 'IF This = that.'.
append xsource to isource.
<b> xsource = 'Write:/ message.'.</b>
append xsource to isource.
xsource = 'ENDif.'.
append xsource to isource.
xsource = 'ENDFORM.'.
append xsource to isource.
generate subroutine pool isource name program
message message
line line.
if sy-subrc = 0.
<b> perform (routine) in program (program)
using 'This is the message'.</b>
else.
write:/ message.
endif.
Regards,
Rich Heilman
‎2005 Dec 07 8:23 PM
‎2005 Dec 07 8:54 PM
Here's what I mean, you can generate a subroutine which will call a generated subroutine. And you can build the parameters into the statement.
report zrich_0001
no standard page heading.
types: t_source(72).
data: routine(32) value 'CALL_ROUTINE',
program(8),
message(128),
line type i.
data: isource type table of t_source,
xsource type t_source.
start-of-selection.
* code for the first form
xsource = 'REPORT ZTEMP_REPORT.'.
insert xsource into isource index 1.
xsource = 'FORM TEMP_ROUTINE using p_message.'.
insert xsource into isource index 2.
xsource = 'Data: this, that.'.
append xsource to isource.
xsource = 'IF This = that.'.
append xsource to isource.
xsource = 'Write:/ p_message.'.
append xsource to isource.
xsource = 'ENDif.'.
append xsource to isource.
xsource = 'ENDFORM.'.
append xsource to isource.
* code for the second form.
xsource = 'form call_routine using p_program.'.
append xsource to isource.
xsource = 'perform temp_routine in program (p_program)'.
append xsource to isource.
xsource = ' using ''this is the message''.'.
append xsource to isource.
xsource = 'ENDFORM.'.
append xsource to isource.
generate subroutine pool isource name program
message message
line line.
if sy-subrc = 0.
perform (routine) in program (program) using program.
else.
write:/ message.
endif.
Regards,
Rich Heilman
‎2005 Dec 08 5:06 AM
Hi there,
if this form you wish to execute is pre-existing and not itslef being created dynamically, maybe you could replace it with a function module? It is possible to call function modules and dynamically pass the parameters thorugh use of the 'PARAMETER-TABLE' addition. See today's discussion of Dynamic function module paramters in another thread.
Regards
Neil
‎2005 Dec 06 7:15 PM
Hi,
You can easily achieve this by using Field symbols too. If you can cleary explain the issue, i can send you the sample code.
Regards,
Suman
‎2005 Dec 06 7:46 PM
You can easily do it using MACROS. The following is psuedo code. Adjust the code as per requirement. Basically it evaluates the part of the expression reprersented by one row in internal table at a time and keep the boolean result in memory and then it goes to next row of same expression and evaluates it and perform the boolean operation on previous result and this result to get current result. It will keep on doing till all sub expressions have been evaluated and combined.
data : v_result1 type X ,
v_result2 type X ,
v_result3 type X.
data : fld(4) type c value '1235'.
data : fld_name(30),
bool_opr(20),
define exec_logexp .
concatenate &1 &2 '(' &3 ')' into fld_name.
if fld_name &4 &5.
v_result1 = '1'.
else.
v_result1 = '0'.
endif.
end-of-definition.
define calc_bool.
v_result2 = v_result2 &1 v_result1.
end-of-definition.
start-of-selection.
break-point.
Loop at itab where ... condition.
exec_logexp itab-fld4 itab-fld5 itab-fld6 itab-fld7 itab-fld9.
*-----boolean operator
if not itab-fld8 is initial.
concatenate 'BIT-' itab-fld8 into bool_opr.
calc_bool bool_opr.
endiif