Upload
e970029
View
165
Download
4
Embed Size (px)
Citation preview
Subscribe
Permalink
Share
Blogs
The Standard Text Editor (OO ABAP CFW class)Igor Barbaric
Business Card
Company: G2R
Posted on Jun. 06, 2005 05:02 AM in ABAP
Introduction
If you want to enable users editing standard texts in extremely simple and straightforward UI, you can use the component described in this weblog. It's a class (OOABAP) which pops up a CL_GUI_TOOLBAR (CFW) control which enables user to enter text and save or close.
Why not a standard transaction? I had a request from a user. On a custom-made purchase order (I made it as a SmartForm) the user wanted to have a piece of freely entered text. The text should'vebeen vendor-specific and user wanted to be able to change it from time to time. The obvious solution to me was a dynamical standard-text node in the SmartForm. Thequestion was how to let the user edit standard text?
Stanard solution <big>CALL TRANSACTION 'SO10'</big> is not bad, but has drawbacks:
Going directly to the text editor is possible by using the <big>AND SKIP FIRST SCREEN</big> addition. However, returning to the calling program displays the SO10
first screen. It's one useles and irritating screen too much for the user, and one click too much:
Formatting options are good to have. But if they are unneccessary for some functionality, then it's good to hide them from users. What they can't see they can'tbreak. Look at all the nice confuzing buttons to mess with in SO10:
SO10 occupies the entire session screen - I can't run it in a popup (or any desired) container
The new componentAll in all, I wanted to make it as simple as possible for users. Ofcourse, I wanted to make my life easy too, by making a generic reusable OO component with simpleprogramming interface. So I came up with this.
This executable little sample program...
17/06/2010 SAP Community Network Blogs
www.sdn.sap.com/irj/scn/weblogs?bl… 1/7
5
6
REPORT Z_TEST_ST_TEXT_EDITOR.
DATA: o_txe TYPE REF TO zcl_standard_text_editor,
v_caption TYPE char100,
s_thead TYPE thead.
* call screen
CALL SCREEN 0100.
* MODULE s0100_start
MODULE s0100_start OUTPUT.
SET PF-STATUS 'BASIC'.
s_thead-tdname = 'VENDOR0000000011'.
s_thead-tdid = 'ST'.
s_thead-tdobject = 'TEXT'.
s_thead-tdspras = sy-langu.
CONCATENATE 'Standard text:' s_thead-tdname
INTO v_caption SEPARATED BY space.
IF o_txe IS INITIAL.
CREATE OBJECT o_txe
EXPORTING i_thead = s_thead
i_caption = v_caption.
ENDIF.
ENDMODULE.
* MODULE s0100_exit
MODULE s0100_exit INPUT.
LEAVE PROGRAM.
ENDMODULE.
...results with a popup screen:
Could it be more simple? Well, maybe by hiding the standard buttons.
Create the component yourself To be able to run the sample program yourself, you need to create the class ZCL_STANDARD_TEXT_EDITOR. To do this, please follow the procedure:
1. Create Class ZCL_STANDARD_TEXT_EDITOR
2. Go to Types and declare the table type TY_T_TEXT:<big>TYPES: ty_t_text TYPE STANDARD TABLE OF tdline.</big>
3. Create attributes:
Attribute Level Visibility Typing Assoc. type In.Val.
C_SAVE Constant Public Type UI_FUNC 'P_SAVE'
C_CLOSE Constant Public Type UI_FUNC 'P_CLOSE'
MAIN_CONTAINERInstance ProtectedType Ref ToCL_GUI_CONTAINER
SPLITTER Instance ProtectedType Ref ToCL_GUI_EASY_SPLITTER_CONTAINER
TEXTEDIT Instance ProtectedType Ref ToCL_GUI_TEXTEDIT
TOOLBAR Instance ProtectedType Ref ToCL_GUI_TOOLBAR
THEAD Instance ProtectedType THEAD
CAPTION Instance ProtectedType TEXT100
T_INITIAL_TEXT Instance Private Type TY_T_TEXT
3. Create methods:
Method Level VisibilityParameters
Name TypeOptTyping Assc. Type DefVal
CONSTRUCTOR InstancePublic I_CONTAINERImp X TypeRefToCL_GUI_CONTAINER
I_CAPTION Imp X Type C
I_THEAD Imp Type THEAD
FREE InstancePublic
ON_TOOLBAR_FUNC_SELInstanceProtectedFCODE
SAVE InstanceProtected
ON_CONTAINER_CLOSE InstanceProtected
M_CLOSE InstanceProtected (continued from the above table):
Event handler for
17/06/2010 SAP Community Network Blogs
www.sdn.sap.com/irj/scn/weblogs?bl… 2/7
MethodEvent handler for
Class/interface Event
CONSTRUCTOR
FREE
ON_TOOLBAR_FUNC_SELCL_GUI_TOOLBAR FUNCTION_SELECTED
SAVE
ON_CONTAINER_CLOSE CL_GUI_DIALOGBOX_CONTAINERCLOSE
M_CLOSE
4. Create event (you might need it for unlocking in a calling program)
Event Level VisibilityParameters
Name TypeOptTyping Assc. Type
CLOSEInstancePublic E_THEAD Exp X Type THEAD
E_OBJECTExp X Type Ref ToZCL_STANDARD_TEXT_EDITOR5. Implement methods (create methods' code)
5
6
method CONSTRUCTOR.
DATA: o_dialogbox TYPE REF TO cl_gui_dialogbox_container,
t_text TYPE STANDARD TABLE OF tdline,
s_event TYPE cntl_simple_event,
t_events TYPE cntl_simple_events,
t_lines TYPE STANDARD TABLE OF tline,
v_text TYPE tdline,
v_text_temp TYPE tdline,
v_line_temp TYPE tdline,
v_line_len TYPE i,
v_index TYPE i.
FIELD-SYMBOLS: <line> TYPE tline.
me->thead = i_thead.
me->caption = i_caption.
*------ containers
The end
Well, that's all. Nothing fascinating, but I believe simple and handy. Have fun! Igor
Igor Barbaric is a BC consultant and ABAPer in G2R, Croatia
Tell me how do you like this one. Thanks! IgorComment on this weblog
Showing messages 1 through 11 of 11.
Titles Only Main Topics Oldest First
problems with save and exit buttons
2006-05-31 04:13:19 Joachim Bultmann Business Card [Reply]
I know the Weblog is already old, but I have the same problem Ian had.
The "save" and "close" button don't do anything.
The events seem to be registered but the event itself never starts.
If anybody has a solution, I would be very glad and thankful.
Best regards
Joachim
problems with save and exit buttons
2006-08-30 05:15:00 Johan von Reedtz Business Card [Reply]
Hi Joachim,
I faced the same situation as you did and finally after some lengthy investigation I found the solution.
When used inside a class it is apparantly not an application event but a system event that should be registered.
17/06/2010 SAP Community Network Blogs
www.sdn.sap.com/irj/scn/weblogs?bl… 3/7
*------ register events
REFRESH t_events.
s_event-eventid = cl_gui_toolbar=>m_id_function_selected.
s_event-appl_event = ' '. "Change to this!
APPEND s_event TO t_events.
CALL METHOD me->toolbar->set_registered_events
EXPORTING events = t_events.
SET HANDLER: me->on_toolbar_func_sel FOR me->toolbar.
I found this by looking at method FILL_TOOLBAR in std SAP class CL_BUPA_STATUS_ALV. I am on R/3 4.7 BTW.
Best regards, Johan
problems with save and exit buttons
2006-09-04 05:57:47 Igor Barbaric Business Card [Reply]
Johan,
Thanks a lot for your effort and correction!
I have updated the code in weblog according to your findings.
Regards,
Igor
Works great
2005-11-22 08:34:39 Rajesh Dash Business Card [Reply]
Igor,
I could use your code for my design. Thanks for publishing it.
Rajesh
Re: Works great
2005-11-22 22:09:42 Igor Barbaric Business Card [Reply]
Thanks for your comment, Rajesh! I am happy that people still read old weblogs and find them useful.
Kind regards,
Igor
Toolbar event not firing
2005-08-04 09:18:54 Ian Stubbings Business Card [Reply]
Hi Igor
I have just implemented your code but the toolbar events do not seem to fire. Any ideas? I have double check the atributes, mthods etc. The code was copied and
pasted in so there should not be any typos etc.
I am on 46B BTW.
Thanks in advance
Ian
Toolbar event not firing
2005-08-08 05:32:03 Igor Barbaric Business Card [Reply]
Hi, Ian!
First, I'd like to appologize for delayed answer. I have just got hired by a new company (today starts my 2nd week). The transport system was not functioning,
so I had to fix it first (urgent), import the components and then try the program.
However, my sample program works fine. Although I was pretty much certain, I have compared the code again just in case (my class against weblog code) and
it's the same.
I don't know what could cause your toolbar event not firing. By the way, do you mean standard commands (export, import etc), or custom (save and close)? All
the same, it works in my program.
You can debug the code and see what's happening: Try setting the first breakpoint in CONSTRUCTOR method, the part where the event is registered - find the
comment "*------ register events". Is event registered properly?
You can place the second breakpoint at the beginning of the ON_TOOLBAR_FUNC_SEL method. Does program even step in there when you press the Save
button?
17/06/2010 SAP Community Network Blogs
www.sdn.sap.com/irj/scn/weblogs?bl… 4/7
Please tell me how you're doing. I'd love to see it work. Don't hesitate to contact me by email at <firstname>.<lastname>@infotehna.hr (let's avoid spam).
I am on Enterprise 4.7 WAS 620.
Regards,
Igor
syntax error.
2005-06-07 21:15:36 Salmon Salmon Business Card [Reply]
Dear Igor,
I had used the standard text for default text in the sales transaction, and it would be great if your provided code can be replace the functionally of standard text.
I have tried to implement your code, but found some errors.
1. while declare attribute T_INITIAL_TEXT, our system didn't have Associated type TY_T_TEXT.
2. syntax error in method CONSTRUCTOR line 83 with error message "V_HEX1 must be a character-type data object (data type C, N, D, T or String), field string)."
could you please advice regarding these problems?
Thank you.
Best Regards,
Salmon
Standard Text Editor - syntax error.
2005-06-08 02:04:58 Igor Barbaric Business Card [Reply]
Hi, Salmon!
You can resolve the problem #1 easily. Get into the class ZCL_STANDARD_TEXT_EDITOR (trans SE24) and press the button "Types". Then you get a text
editor and insert the statement
[code]TYPES: ty_t_text TYPE STANDARD TABLE OF tdline.[/code]
and that's all. Please take a look at the instructions in the weblog - it's step 2.
As for the problem #2 - syntax error when trying to concatenate hex value with text, I must admit that I don't know what to do at the moment. It works fine
on my system, and I'm pretty much sure that this is caused by version difference. I'm on 4.7 WAS 620. What's your version?
I'll try to find the alternative way to accomplish this and I'll post the solution as soon as I find it. Meanwhile, you can comment out the entire IF...ELSE...ENDIF
part and leave only the statements
[code]v_line_temp = <line>-tdline.
CONCATENATE v_text v_line_temp INTO v_text_temp.[/code]
You'll temporarily lose the functionality of paragraph breaks, untill I find the version-independant solution to this.
Thanks!
Igor
P.S. By the way, this code does not replace the standard texts. It just enables another way to let the user edit standard texts.
Standard Text Editor - syntax error.
2005-06-08 23:55:17 Salmon Salmon Business Card [Reply]
Hi Igor,
The problem #1 has been resolved, I missed the 2nd step when trying the code, sorry....
I tried the code on CRM 4.0 WAS 620.
Thanks!
B.Rgds,
Salmon
Standard Text Editor - syntax error CORRECTED!
2005-06-10 05:37:18 Igor Barbaric Business Card [Reply]
Hi, Salmon (and everyone else who tried this)!
I found the solution. The problem was not the version, but rather unicode. There's "Unicode checks active" checkbox in class properties. If it's checked,
the systax check doesn't pass the mixed (text and hex) CONCATENATE statement.
Thanks to Durairaj Athavan Raja and Christian Finkbeiner I have corrected the code to be unicode independant and updated the weblog. You have to
update the source code of CONSTRUCTOR and SAVE methods in the class.
Thanks for patience!
Igor
17/06/2010 SAP Community Network Blogs
www.sdn.sap.com/irj/scn/weblogs?bl… 5/7
Showing messages 1 through 11 of 11.
17/06/2010 SAP Community Network Blogs
www.sdn.sap.com/irj/scn/weblogs?bl… 6/7
17/06/2010 SAP Community Network Blogs
www.sdn.sap.com/irj/scn/weblogs?bl… 7/7