2010 May 07 10:19 AM
Hi
I am working on creating a dynamic ABAP pattern.
I have called it Y_TEST - entered one line with the value *$&$MUSTER - and I have created the function module called Y_TEST_EDITOR_EXIT.
Now I can allow the user of the pattern to enter some data and create the pattern based on these data. This works very fine, but I would like to validate the user input against the current source code.
Not against the saved source code that can be read READ REPORT ..., but against the source code currently active in the editor.
Can I access this source code?
I know after that after a dump, this current source code is sometimes stored in a buffer somewhere, and when I try to open the source in the ABAP editor, I get the option to load the source from this buffer instead of reading it from the database - but can I read this buffer in my function module?
Best regards
Thomas Madsen Nielsen
2010 May 07 11:27 AM
Hi,
I think that the code in buffer is stored some where in the application server.
After the Dump, go to SE38, enter your program name and enter /h in command prompt. Now change. From menu place break point at statement ÖPEN DATA SET. In the popup select the option load from buffer and enter. Control should stop at OPEN DATA SET statement. You can read the code in the same way in your FM also. Just check how the file name is populated in the same code just above the OPEN DATA SET statement.
Thanks,
Vinod.
2010 May 07 11:27 AM
Hi,
I think that the code in buffer is stored some where in the application server.
After the Dump, go to SE38, enter your program name and enter /h in command prompt. Now change. From menu place break point at statement ÖPEN DATA SET. In the popup select the option load from buffer and enter. Control should stop at OPEN DATA SET statement. You can read the code in the same way in your FM also. Just check how the file name is populated in the same code just above the OPEN DATA SET statement.
Thanks,
Vinod.
2010 May 07 11:37 AM
- but I don't have a dump with the option re-read the source from buffer.
2010 May 07 12:47 PM
Not sure what kind of editor you're reffering to, but if it's in the screen then surely you must be able to get it from the memory.
2010 May 07 12:55 PM
Hi,
Why r u getting the dump and what the dump says? If it is from pattern, then you will get read from buffer option when you enter to editor in change mode (Say program/FM) for next time.
Thanks,
Vinod.
2010 May 07 5:08 PM
The editor is of course the ABAP editor from where a programmer press the Pattern push button.
I do not have any dump, and the dump info seems to be confusing - so please forget what I mentioned about a dump.
This is the situation:
I'm writing a dynamic ABAP pattern function module. ( You can find the create pattern option in the ABAP editor under Utilities->More Utilities->Edit Pattern).
Now, when a programmer want to use my dynamic ABAP pattern, he opens an ABAP source in change mode - then he positions the cursor in the source, somewhere he wants to insert the pattern code and press the Pattern push button - in the popup he then choose "Other pattern" and type in the name of my pattern (Y_TEST) - and now my function module (Y_TEST_EDITOR_EXIT) is started.
So far so good - now my requirement is that I want to add functionality to my function module based on what ABAP source the programmer was editing when he pressed the Pattern push button.
And of course the source code is somewhere in memory, but can I access it from my function module?
Best regards
Thomas Madsen Nielsen
2010 May 07 5:23 PM
Hi,
You can use the addition STATE with READ REPORT (Provided you have saved the code (Not activated) before calling the pattern)
DATA itab TYPE TABLE OF string.
READ REPORT 'Z756941' INTO itab STATE 'I'. "I for inactive version, A for active version (By default)You can check the repository tables for finding the status of the object.
Note: As per F1 help, STATE addition is for internal use only. Even though this works, SAP won't gurantee the change in functionality in future.
Regards,
Vinod.
2010 May 07 6:35 PM
Hi Vinod,
Thanks for your info about the State addition.
It is an interesting option, although it is not really the solution i'm looking for. I hope somehow to be able to read the source even if the code is not saved.
Best regards
Thomas
2010 May 07 9:12 PM
Hi Thomas,
Here an untested recipe (unfortunately no time for testing), which might work: Use function module GET_EDITOR_HANDLE to get a reference to class CL_WB_EDITOR. Within the class call method GET_SOURCE_INSTANCE to get a reference to CL_WB_SOURCE (note that you also have a method GET_CURSOR to read the current cursor position). From CL_WB_SOURCE call method GET_SOURCE_TAB. Ideally you now have the information you're looking for.
As I couldn't test it, it would be nice to hear if that approach worked...
Cheers, harald
p.s.: Out of curiosity - how do you trigger your custom function module after the pattern is chosen?
2010 May 08 10:20 AM
Thanks Harald
This is great - your solution works perfect.
data: editor_handle TYPE REF TO CL_WB_EDITOR.
CALL FUNCTION 'GET_EDITOR_HANDLE'
IMPORTING
HANDLE = editor_handle.
data: FIRST_LINE type sy-tabix
, CURSOR_LINE type sy-tabix
, CURSOR_OFFSET type sy-tabix.
CALL METHOD EDITOR_HANDLE->GET_CURSOR
IMPORTING
FIRST_LINE = first_line
CURSOR_LINE = cursor_line
CURSOR_OFFSET = cursor_offset.
data: source_handle TYPE REF TO CL_WB_SOURCE.
CALL METHOD EDITOR_HANDLE->GET_SOURCE_INSTANCE
IMPORTING
SOURCE_OBJECT = source_handle.
data: source type RSWSOURCET.
CALL METHOD SOURCE_HANDLE->GET_SOURCE_TAB
IMPORTING
SOURCE = source.
*Now the program is in the source table
*and the cursor_line contains the position in the source.
Best regards
Thomas Madsen Nielsen
PS. How to create a custom dynamic pattern:
1) In the ABAP editor choose function Utilities->More Utilities->Edit Pattern->Create Pattern
2) In the pop-up screen enter a name for the pattern starting with Y_ or Z_ (in my example y_test)
3) next step an editor comes up. In this editor you can enter a static pattern or if you want to create a dynamic pattern you enter one line with this content: *$&$MUSTER
4) Create a function module named PatternName+_EDITOR_EXIT (in my example Y_TEST_EDITOR_EXIT)
*$&$MUSTER is a trigger that automatic starts the function module.
Try to search sdn for *$&$MUSTER
2010 May 07 5:45 PM
Thomas,
I understand that you stay working with memory. Your need be sure about this, because you have the SAP Memory(Server Memory) and ABAP Memory.
When you work with SAP Memory is basicly when you work with ABAP certain sentences like export, import. When you work with any Function modules, your need be sure that this funcion module is called, this FM open other ABAP Memory independing of your program and other FM called. So... I think this a problem for your case.
Regards,