ā2016 Jan 08 10:52 AM
Hello,
I have a unique requirement to generate a version of a program from other program during runtime.
Can anyone let me know how to generate a version of a program dynamically.
Thanks and Regards
Mohammed
ā2016 Jan 25 8:00 AM
Hi Mohammed Pasha,
I had a similar requirement once, and I used the function module SVRS_STORE_VERSION: The following method adds a version to an include program IV_INCLUDE. The code of this include program is automatically generated from a DSL which is edited in production by the user. One wants to keep track: Who changed it, and when - and what where the changes?
Instead of a real transport, I pass a symbolic name DSL_(number) to the E071 structure, which works pretty well (there is no existence check for the transport order, the field is allowed to have any value). Pass the parameter MODE = SPACE to make this version persistent (otherwise it could be overwritten by the next version).
method add_version.
data: ls_e071 type e071,
lt_e071 type e071_t,
lv_versno type vrsd-versno,
lv_version type trkorr,
lv_rep type repid.
select max( versno ) into lv_versno
from vrsd
where objtype = 'REPS'
and objname = iv_include.
add 1 to lv_versno.
concatenate 'DSL' lv_versno into lv_version.
ls_e071-trkorr = lv_version.
ls_e071-pgmid = 'LIMU'.
ls_e071-object = 'REPS'.
ls_e071-obj_name = iv_include.
append ls_e071 to lt_e071.
call function 'SVRS_STORE_VERSION'
exporting
date = sy-datlo
time = sy-timlo
user = sy-uname
korr = lv_version
mode = space " persistente Version
tables
e071_tab = lt_e071.
endmethod.
That's it. Easy, isn't it?
Kind regards,
Rüdiger
ā2016 Jan 08 11:38 AM
Check READ REPORT and INSERT REPORT, and be very careful.
Horst
ā2016 Jan 08 1:58 PM
Hi Horst,
wouldn't it be safer to create and release a transport request. One could for example set up a dummy transport target, create a transport of copies, add the objects and release it.
This would also generate a version without the risk that is involved in using INSERT REPORT directly.
Christian
ā2016 Jan 08 2:10 PM
Hi Christian,
Depends on what Mohammed wants.
If he needs another "version" in the sense of change and transport management, sure you're right, than one has to deal with transport requests and doing it dynamically means that you have to know the corresponding function modules (no fun, debugging SE09 ).
I assumed that he simply needs a modified (and even temporary?) "version" generated and executed at runtime.
Horst
ā2016 Jan 24 1:27 PM
Hi Horst/Christian,
Thanks for the reply.
Insert report is generating a new code in already existing program.
But I need a new version in current program and when I write as
below.
insert report prog from itab version x.
it is throwing an error message as unable to interpret 'version'.
Please help
ā2016 Jan 24 3:56 PM
Since INSERT REPORT has no addition of VERSION, why do you think it would work? You can't just randomly create new syntax and expect it to do what you want. Have you read the ABAP keyword help?
But I'm afraid that
Insert report is generating a new code in already existing program.
But I need a new version in current program and when I write as
below.
makes no sense to me. I've still no idea what you are trying to achieve. You can have a new version of a current program, but a new version in current program makes no sense.
I think to proceed further you must explain precisely what you are trying to do and (probably more importantly) why.
ā2016 Jan 25 6:12 AM
Hi Mathew,
I am making changes in current program dynamically if it satisfies some criteria.
for that I need to keep the old changes and replace them with new version.
Hope its clear for you now.
Thanks and Regards
Mohammed
ā2016 Jan 25 6:51 AM
Since INSERT REPORT has no addition of VERSION(but this is not for program version but for ABAP language versions since ABAP 7.50).
ā2016 Jan 25 7:12 AM
Good point, well presented. If the OP is on 7.50, then he really should have read what VERSION actually does.
ā2016 Jan 25 7:19 AM
No. It's not clear. So far all you said is that you want to change the current program dynamically. But why?
What, functionally, are you trying to do? What business requirement are you attempting to meet? What business logic are you trying to implement? What is the problem that you are attempting to solve by versioning?
ā2016 Jan 25 7:49 AM
ā2016 Jan 25 9:26 AM
If you do not start supplying meaningful answers, then as a moderator, I'm going to close this thread. I'm very close to giving up. Do you not want help? Do you not understand what I am asking you? Why do you think being able to generate a version of a program dynamically will "fine tune" your code?
If you state clearly and succinctly what you are trying to achieve and why, you'll find that you get useful answers quickly. If you continue to give vague information, then this will drag on and on. You first posted about this two weeks ago. I'm no closer to understand what on earth you think you are going to achieve by dynamically creating new versions of code than at the start. And I doubt anyone else is either.
My suspicion is that you need to generate code on the fly. Have you searched for GENERATE SUBROUTINE which covers exactly this kind of dynamic program generation?
ā2016 Jan 25 10:35 AM
Hi Matthew,
I am making some modifications in custom program via another program(i.e a tool, a report).
once the changes are made ,it should overwrite existing code and store it generating a newer version.
for the question "why do you think being able to generate version of a program dynamically
will fine tune the code?"
I have written the logic in the tool on what basis the changes need to be done in program.
and how it should reflect. also it will fine tune the code for an existing program not creating another one. let me know if still any queries
ā2016 Jan 25 10:59 AM
The way SAP handle this is to generate a new program (entirely overwriting) the old one, in $TMP directory. They do not create new versions of the program.
ā2016 Jan 25 11:21 AM
Just use the function module SVRS_STORE_VERSION, as described below. Then you get a version.
ā2016 Jan 24 4:09 PM
Check the Form Routine FC_VERSION_CREATE in include LS38EF00. We are generating the version of each object during the release of task. Function module SVRS_AFTER_CHANGED_ONLINE_NEW is used to generate the version.
ā2016 Jan 25 6:10 AM
hi rakshit,
could you please let me know where to give program name and internal table in routine.
regards
Mohammed
ā2016 Jan 25 6:36 AM
you can see in the routine FC_VERSION_CREATE, Program ID and Object is hardcoded as 'LIMU' & 'REPS' . This is for the report programs so you just need to put the breakpoint in that routine and try to generate the version(Utilities->Versions->Generate Version) of any test program.
P.S - Just a thought, the object reference 'abap_pgeditor' will be instantiated during SE38 call so i think you can directly use the PERFORM (routine name) IN PROGRAM (program name).
ā2016 Jan 25 8:00 AM
Hi Mohammed Pasha,
I had a similar requirement once, and I used the function module SVRS_STORE_VERSION: The following method adds a version to an include program IV_INCLUDE. The code of this include program is automatically generated from a DSL which is edited in production by the user. One wants to keep track: Who changed it, and when - and what where the changes?
Instead of a real transport, I pass a symbolic name DSL_(number) to the E071 structure, which works pretty well (there is no existence check for the transport order, the field is allowed to have any value). Pass the parameter MODE = SPACE to make this version persistent (otherwise it could be overwritten by the next version).
method add_version.
data: ls_e071 type e071,
lt_e071 type e071_t,
lv_versno type vrsd-versno,
lv_version type trkorr,
lv_rep type repid.
select max( versno ) into lv_versno
from vrsd
where objtype = 'REPS'
and objname = iv_include.
add 1 to lv_versno.
concatenate 'DSL' lv_versno into lv_version.
ls_e071-trkorr = lv_version.
ls_e071-pgmid = 'LIMU'.
ls_e071-object = 'REPS'.
ls_e071-obj_name = iv_include.
append ls_e071 to lt_e071.
call function 'SVRS_STORE_VERSION'
exporting
date = sy-datlo
time = sy-timlo
user = sy-uname
korr = lv_version
mode = space " persistente Version
tables
e071_tab = lt_e071.
endmethod.
That's it. Easy, isn't it?
Kind regards,
Rüdiger
ā2016 Jan 25 3:18 PM
Hİ Mohammed,
I needed the same for a development,
in my project I also needed to put that program in a Change Request :
SAVE_SOURCE function is already doing it,
( btw debug transaction SE38 .. u can already see how it is called )
Here is a part of my code :
LOOP AT gt_diff_inc INTO ls_diff_inc.
" inserting in a Change Request :
CALL FUNCTION 'RS_CORR_INSERT'
EXPORTING
object = ls_diff_inc-org_name
object_class = 'ABAP'
mode = 'MODIFY'
devclass = lv_devclass
korrnum = ip_trkorr
object_class_supports_ma = 'X'
EXCEPTIONS
cancelled = 1
permission_failure = 2
unknown_objectclass = 3
OTHERS = 4
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
CLEAR ls_transport_key.
ls_transport_key-devclass = lv_devclass.
ls_transport_key-obj_type = 'PROG'.
ls_transport_key-obj_name = ls_diff_inc-org_name.
ls_transport_key-sub_type = 'REPS'.
ls_transport_key-sub_name = ls_diff_inc-org_name.
"Creating new version of code by the request :
CALL FUNCTION 'SAVE_SOURCE'
EXPORTING
transport_key = ls_transport_key
modificationmode = ''
source_name = ls_diff_inc-org_name
active_inactive_allowed = ''
trkorr = ip_trkorr
TABLES
content = ls_diff_inc-copy_source
smodilog_abap = lt_smodilog_abap
content_old = ls_diff_inc-org_source
mod_tab = lt_mod_tab
delete_tab = lt_delete_tab
smodisrc_tab = lt_smodisrc_tab
CHANGING
status_flag = lv_stat_flag
source_modified = lv_changed
EXCEPTIONS
not_executed = 1
OTHERS = 2
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
CLEAR ls_diff_inc.
ENDLOOP.
ā2016 Jan 25 4:19 PM
Ok, maybe you can explain why you need this. What problem is it solving!!!
ā2016 Jan 25 4:38 PM
Hi Matthew,
We have developed a product to make ABAP code analyzing and auto-performance tuning
by automatic code corrections,
this was a small part of the application.
I don't want to use forum as a advertising board,
but I can share product features with you if u want,
Regards,
Bulent
ā2016 Jan 25 6:06 PM
ā2016 Jan 26 10:55 PM
Hi Mohammed,
Whether you do an INSERT REPORT from your Z-program or SAP does an INSERT REPORT from SE38 / SE80 is not much different, bar the whole construct around the consistency checks and namespaces and authorizations needed to reach these statements.
If you use SE80 then you can simply assign the change to a transport request once having activated it (ahem... please!).
If you use your own tool to edit the code and want to transport it, then version management is integrated into the transport mechanism.
If you want user input for generated code in production, then you must create a "framework" for the generation. Like SE16 for example. Also some HR reports use this. Some dirty IS (Industry Solutions, not Islamic State) also find this feature tempting because it does not respect the SE06 system change status... bummer..
If you want to send the entire code via RFC to the server and insert it and run it, the it is a stupid idea and you must rethink your design. Eg. a framework for generating very selective subroutines with input validation for the variable parts and restricted to your application.
Bottom line: if you need version management for dynamic code, then the dynamic parts should not be relevant for versioning. They should be equivalent to variables.
Cheers,
Julius
ā2016 Jan 26 11:06 PM
Ps: Are you wanting this version management in DEV system or in PROD? Just to be sure I ask.
Cheers,
Julius
ā2016 Jan 27 7:55 AM
Hi Julius,
Point taken .
But just want to let you know, that I am experimenting with the thought that if this tool works or not.
By the way, I don't need this version management in PROD.
Thanks and Regards
Mohammed