Problem in CREATE_TEXT FM
Hi ,
In our RFC to place an order we are using the FM CREATE_TEXT to save header text in salesorder . The text that needs to be saved is entered through the front end ( java ). Now the issue we are facing is that , if in the front end they use a new line character while they enter the header text ( i.e. , if the user press enter ) , the same character is being stored in SAP as ##. We don't want this character to be stored as it is creating some errors while transferring the sales order data to some other system other than SAP , through IDOC's .
Assumption is that ## is a command for page break (probably done when entered the text in the front end and translated into this command when posting the text in SAP).
Is there anyway that we can avoid this special character being stored in SAP ?
Any help in this regard would be highly appreciated
Regards,
Beena
Hi Beena,
While passing the text to the FM CREATE_TEXT, why dont you search and replace '##' with a single blank space?
Or, you dont have control over the text passed to the FM?
Understood that you dont find them while creating, then use FMs READ_TEXT modify the text, so that these are removed('##') and again use FM SAVE_TEXT, to save the text.
Regards,
Raj
Message was edited by: Rajasekhar Dinavahi
Similar Messages
-
Problem with Create_Text Function module
Hi All,
I am using the function module Create_Text to create the text for Condition types in ME31K. Its working fine and creating text when i go to debug mode. Its updating into transactions(ME31K). But if i run the program in back ground or foregorund with out debuging modes its not creating text. Please do let me know any reasonsHi,
Have you used FM COMMIT_TEXT after CREATE_TEXT ? :
CALL FUNCTION 'COMMIT_TEXT'
EXPORTING
OBJECT = 'PMS'
NAME = W_TDNAME
ID = 'LTXT'
LANGUAGE = 'E'.
Try adding the 'COMMIT_TEXT' and check.
Thanks & Regards,
Faheem. -
Problem in Getting Long Text After uploading LT using CREATE_TEXT in CORS
Hi Gurus,
i am uploading long text for Reason for cancellation in CORS Transaction through CREATE_TEXT.
after uploading this text by using this FM CREATE_TEXT i am seeing the long text what ever i uploaded through CREATE_TEXT , i am unable to see first 40 characters of that long text.
if anybody faced this problem earlier please guide me to resolve this problem.
Thanks & Regards
Venkata Ramesh JHi,
can you please check this link
Replacing the text created in create_text
Thanks
durga.K -
Problem when Saving Texts using Function Module CREATE_TEXT
Hi All,
I am using Function Module CREATE_TEXT to save text in transaction XK02.
But the first character of few lines disappears in one of (Ruled) editor while that character appears in a new line in another editor.
In debug mode, I found that value of TDFORMAT is '=' in the line in which first character disappears.
while in rest its value is '*'.
I tried hardcoding the value FFORMAT in function module CREATE_TEXT with '*'. Please suggest me solution to this.
Regards,
NibhaHI.
Refer this link.
http://www. ****************/Tutorials/ABAP/MaterialLongText/info.htm
Regards.
Jay -
Hi folks,
iam uploading longtext in transaction KP06 in bdc programing using create_text.
now my problem is if i pass selection criteria
case 1:
Vertion : N0
fiscal year : 2007
planner profile: CCPLAN4
then the budeget plan data uploading successfully along with long text.
case2: Vertion : N1
in this case also everthing wrking fine
case3: Vertion : 001
in this case budgetplan data uploading sucessfully but longtext is not uploading,
i debbug the proragm , create_text also returning sy-subrc = 0. but if i check in KP06 the long text is not there.
data declaration
vertion : VERSN type C(3)
can u tell me the problem is in logic or with FM ?
note : i checked with save_text also.
regards
neeruHI Naimesh,
the FM Create_text internally contains both FMs save_text and commit_text,
even i debug the FM in case of vertion N1, N0 and 001,
all the cases sy-subrc = 0.
code:
CLEAR G_OBJNR.
LOOP AT RECORD.
COST = RECORD-BDC01.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = COST
IMPORTING
output = COST.
CONCATENATE 'KS' p_kokrs record-bdc00 INTO g_objnr.
SELECT SINGLE * FROM COSP WHERE OBJNR = g_objnr
AND GJAHR = P_GJAHR
AND VERSN = p_ver
AND KSTAR = COST.
IF SY-SUBRC = 0.
LEDNR = COSP-LEDNR.
OBJNR = COSP-OBJNR.
GJAHR = COSP-GJAHR.
WRTTP = COSP-WRTTP.
VERSN = COSP-VERSN.
KSTAR = COSP-KSTAR.
HRKFT = COSP-HRKFT.
VRGNG = COSP-VRGNG.
VBUND = COSP-VBUND.
PARGB = COSP-PARGB.
BEKNZ = COSP-BEKNZ.
TWAER = COSP-TWAER.
CONCATENATE LEDNR OBJNR INTO OBJNR.
CONCATENATE OBJNR GJAHR INTO TNAME1 separated BY SPACE10.
CONCATENATE TNAME1 WRTTP VERSN INTO TNAME2.
CONCATENATE TNAME2 KSTAR INTO TNAME3 separated BY SPACE.
CONCATENATE TNAME3 VRGNG INTO TNAME4 separated BY SPACE4.
CONCATENATE TNAME4 BEKNZ INTO TNAME5 separated BY SPACE10.
CONCATENATE TNAME5 TWAER INTO TNAME.
I_THEAD-TDOBJECT = 'CCSS'.
I_THEAD-TDID = 'COSP'.
I_THEAD-TDNAME = TNAME.
I_THEAD-TDSPRAS = 'E'.
APPEND I_THEAD.
i_tline-tdformat = '*'.
I_TLINE-TDLINE = RECORD-LONGTEXT.
APPEND I_TLINE.
loop at i_thead.
CALL FUNCTION 'CREATE_TEXT'
EXPORTING
FID = I_THEAD-TDID
FLANGUAGE = I_THEAD-TDSPRAS
FNAME = I_THEAD-TDNAME
FOBJECT = I_THEAD-TDOBJECT
SAVE_DIRECT = 'X'
FFORMAT = '*'
TABLES
FLINES = i_tline
EXCEPTIONS
NO_INIT = 1
NO_SAVE = 2
OTHERS = 3
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDLOOP.
CLEAR I_TLINE.
REFRESH I_TLINE.
CLEAR I_THEAD.
REFRESH I_THEAD.
SELECT SINGLE * from cokp into itab WHERE OBJNR = g_objnr
AND GJAHR = P_GJAHR
AND VERSN = p_ver
AND KSTAR = COST.
if sy-subrc = 0.
itab-TXFLG = 'X'.
append itab.
write:/ 'Text saved for', record-bdc00 , record-bdc01.
else.
write:/ 'Text saved for', record-bdc00 , record-bdc01.
ENDIF.
ENDIF.
my program wrking fine but the long text is not visible for vertion 001.
regards
niru -
Save_TEXT problem in IW32
Hi All,
I am facing problem as specified below,
In IW32 I am trying to Append or add new text lines to existing long text lines (read_text then append new lines then
save_text) then it is successful,
but if there is no text lines maintained for Long text then read text is successful & having no data its ok, then
I am trying to append new lines then using SAVE_TEXT as well Create_text with commit_text
it successful & once I tryed to use READ_TEXT then it showing new added text
the main problem is it is not DISPLAYED in IW32 TEXT EDITOR.............?
As I tryed to update AUFK table for the same order with LTEXT field = 'X'......
is there any other tables & fields I nedd to update for LONG TEXT so that it becomes visible..............?Hi Vijay,
I had updated AUFK-LTEXT as 'E' also its not giving text output in IW32 text editor...........
is there any additional fields to modify or update.......... -
Problem while displaying top of page in list display
Hi,
M facing problem in displaying top of page in list .
M using following methods:-
lr_outer_grid TYPE REF TO cl_salv_form_layout_grid,
lr_inner_grid TYPE REF TO cl_salv_form_layout_grid,
lr_label TYPE REF TO cl_salv_form_label,
lr_text TYPE REF TO cl_salv_form_text.
For displaying the top of page m using event TOP_OF_PAGE.
CREATE OBJECT lr_outer_grid.
*Outer grid
lr_inner_grid = lr_outer_grid->create_grid(
row = 1
column = 1 ).
*... create lable information in inner_grid
User ID
lr_label = lr_inner_grid->create_label(
row = 1
column = 1
text = text-h03 ).
*... create text information in inner_grid
lr_text = lr_inner_grid->create_text(
row = 1
column = 2
text = sy-uname ).
*... set label for text
lr_label->set_label_for( lr_text ).
But while m going to do same coding for second parameter its not intializing length so adding extra spaces while displaying second row.
e.g
USERID abcdefghjik
PLANT jhk to hjk
I want that output should look like
USERID abcdefghjik
PLANT jhk to hjk
Please tell me the solution what should i do for avoiding extra spaceHi Neelema,
You could try this sample code.
[http://sap-img.com/fu037.htm]
[http://sap-img.com/abap/sample-alv-heading-in-alv.htm]
Regards,
Amit. -
Problem in loading the long text in bdc.
Hai Friends,
I am uploading the material master using bdc, Here i need to upload the long text field. so am using the separate report for upload the long text field using the create_text function module. but the problem is the long text field only accepting 132 charactors. but i need to upload the 500 charactors. what i want to do now ?
Regards ,
Sathis Kumar RHi Sathis,
What u do is that while recording the text part in bdc , click on the first delete button, and then create button and after that double click on the editor or click on the text-editor change button, a window will get opened , then click go-to menu -> change editor.
there u can use loop the text table and wirte it according .
eg
PERFORM bdc_dynpro USING 'SAPMV45A' '4002'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=TP_DELETE'. "first delete
PERFORM bdc_dynpro USING 'SAPMV45A' '4002'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=TP_CREATE'. " then create
PERFORM bdc_field USING 'LV70T-SPRAS'
sy-langu.
PERFORM bdc_dynpro USING 'SAPMV45A' '4002'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=TP_DETAIL'. "if not double click then click on change button after the delete button and then click on the change-editor menu .
PERFORM bdc_field USING 'LV70T-SPRAS'
sy-langu.
PERFORM bdc_dynpro USING 'SAPLSTXX' '1100'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RSTXT-TXLINE(02)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=TXVB'.
PERFORM bdc_field USING 'RSTXT-TXPARGRAPH(02)'
PERFORM bdc_field USING 'RSTXT-TXPARGRAPH(03)'
PERFORM bdc_field USING 'RSTXT-TXLINE(02)'
wa_itab-htext1.
PERFORM bdc_field USING 'RSTXT-TXLINE(03)'
wa_itab-htext2.
PERFORM bdc_dynpro USING 'SAPLSTXX' '1100'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RSTXT-TXLINE(02)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=TXBA'.
PERFORM bdc_dynpro USING 'SAPMV45A' '4002'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/EBACK'.
regards,
Santosh Thorat -
PR to PO ...Standard text problem
Hi all,
I am writing one report , which converts the purchasing requistion to purchase order. I am using the BAPI function module...BAPI_PO_CREATE1.
In this i want to populate the purchase order header text. I am using the standard text for all po's whose are convertable.
but the problem is , the header text table paramers(POTEXTHEADER) in BAPI FM will take 132 chars only. But my standard text is 6 paragraphs are there . how do i long text populate? Am i using the wrong parameters in the BAPI FM.
please suggest me ...how to use this BAPI FM , to populate the lonf standard text.
regards,
Ajay Reddy
Edited by: Ajay on May 27, 2008 9:08 AMhi
use the function module create_text to upload long text. below is the
sample program which uploads purchase order text more than 132 characters.
TABLES : MARA, TLINE, THEAD.
DATA: BEGIN OF ITAB OCCURS 0,
MATNR LIKE MARA-MATNR, " MATERIAL NUMBER
TEXT(5000) TYPE C, " Long Text
END OF ITAB.
DATA: BEGIN OF ITAB1 OCCURS 0,
MATNR LIKE MARA-MATNR, " Material No
SEQU TYPE I, " Text Sequence
TEXT(5000) TYPE C, " Long Text
END OF ITAB1.
DATA:BEGIN OF DT_LINES OCCURS 0.
INCLUDE STRUCTURE TLINE. " Long Text
DATA:END OF DT_LINES.
DATA : P_FILE1 TYPE STRING.
DATA : DL_NAME TYPE THEAD-TDNAME, " Object Name(material no)
DL_LAN TYPE THEAD-TDSPRAS. " Language
CONSTANTS:C_BEST TYPE THEAD-TDID VALUE 'BEST',
C_MATERIAL TYPE THEAD-TDOBJECT VALUE 'MATERIAL'. " OBJECT
DATA: START TYPE I,
LEN TYPE I VALUE 92,
TOTLEN TYPE I,
N TYPE I.
SELECTION-SCREEN : BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-101.
PARAMETERS P_FILE LIKE RLGRAP-FILENAME."input file
SELECTION-SCREEN : END OF BLOCK B1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
PERFORM FETCH_FILE USING P_FILE.
*& Form fetch_file
text
-->P_FILE text
FORM FETCH_FILE USING P_FILE.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
IMPORTING
FILE_NAME = P_FILE.
ENDFORM. "fetch_file
START-OF-SELECTION.
PERFORM UPLOAD USING P_FILE. " *To Upload Flat file
PERFORM UPLOAD_TEXT.
*& Form UPLOAD
text
-->P_FILE text
FORM UPLOAD USING P_FILE.
P_FILE1 = P_FILE.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = P_FILE1
FILETYPE = 'DAT'
HAS_FIELD_SEPARATOR = ' '
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
VIRUS_SCAN_PROFILE =
NO_AUTH_CHECK = ' '
IMPORTING
FILELENGTH =
HEADER =
TABLES
DATA_TAB = ITAB
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17
IF SY-SUBRC EQ 0.
*message i001 with p_file .
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. "UPLOAD
*& Form UPLOAD_TEXT
text
FORM UPLOAD_TEXT.
LOOP AT ITAB.
ITAB1-MATNR = ITAB-MATNR.
CLEAR: TOTLEN,N, START.
TOTLEN = STRLEN( ITAB-TEXT ).
N = TOTLEN / LEN.
N = N + 1.
DO N TIMES.
ITAB1-TEXT = ITAB-TEXT+START(LEN).
ITAB1-SEQU = SY-INDEX.
START = START + LEN.
APPEND ITAB1.
ENDDO.
ENDLOOP.
DELETE ITAB1 WHERE TEXT IS INITIAL.
SORT ITAB1 BY MATNR SEQU.
LOOP AT ITAB1.
DT_LINES-TDFORMAT = '*'.
DT_LINES-TDLINE = ITAB1-TEXT.
APPEND DT_LINES.
AT END OF MATNR.
DL_LAN = SY-LANGU.
WRITE : / itab-MATNR.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = ITAB1-MATNR
IMPORTING
OUTPUT = ITAB1-MATNR.
MOVE ITAB1-MATNR TO DL_NAME.
CALL FUNCTION 'CREATE_TEXT'
EXPORTING
FID = C_BEST
FLANGUAGE = DL_LAN
FNAME = DL_NAME
FOBJECT = C_MATERIAL
SAVE_DIRECT = 'X'
FFORMAT = '*'
TABLES
FLINES = DT_LINES
EXCEPTIONS
NO_INIT = 1
NO_SAVE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
WRITE:/10 'Long Text Creation failed for Material No', ITAB1-MATNR.
ELSE.
WRITE:/10 'Long Text Created Successfully for Material No', ITAB1-MATNR.
ENDIF.
REFRESH DT_LINES.
ENDAT.
ENDLOOP.
ENDFORM. "UPLOAD_TEXT -
Problem in Purchase Requisition Upload
Hi all,
I am uploading Purchase Requisition through BAPI
by BAPI_REQUISITION_CREATE.
Then I am appending text both in items and header by
fm CREATE TEXT.
But when i am uploading the item text
Line Comments are transfering with the extra characters.
example:-
When we type long descriptions we use returns and blank lines for formatting. Right now the text is coming over but the formatting is getting messed up.( The Blank lines and return are getting messed with # .)
how to solve it.
thanks in advance.
SGHi ,
One suggestion it may work try out..
i think the problem is with the formatting input to the create_text function module. try to change the import parameter of the function module CREATE_TEXT i.e FFORMAT to initial. -
Prblm in create_text or save_text
Hi Folks,
Iam uploading long text using a call transaction program.
case1: selection screen
version : N0
fiscal year : 2007
in coding tried both FM (save_text or create_text).
result if check the tcode 'kp06' the text is uploaede successfully wrking with any FM.
case2 selection screen
version : 001
fiscal year : 2007
inthis case i used same data
result if i check the t code 'kp06' except long text other fileds uploaded successfully.
in the debugging the FM is working properly but the text is not visible in KP06.
please tell me the problem is with FM? or the selection screen data?
Thanks
niruHi Beena,
While passing the text to the FM CREATE_TEXT, why dont you search and replace '##' with a single blank space?
Or, you dont have control over the text passed to the FM?
Understood that you dont find them while creating, then use FMs READ_TEXT modify the text, so that these are removed('##') and again use FM SAVE_TEXT, to save the text.
Regards,
Raj
Message was edited by: Rajasekhar Dinavahi -
Use CREATE_TEXT on VA01 user exits
Hi,
I need to write item text using FM CREATE_TEXT in VA01 user exits. The FM required VBELN and I don't have when creating order.
How can I create item text in VA01 user exits ?
Thanks,
QuincyHi,
i have a similar requirement where i need to copy custom populated fields of vbap table into item->text->item notes tab.
i tried with both create_text and save_text. but i couldn't see the item in the item->texts->item notes.
here is my code:
CONCATENATE vbap-zzrelid vbap-zzsorg2 vbap-zzsorg3
vbap-zzsorg4 vbap-zzsorg5 vbap-zzsorg6
vbap-zzsorg7 vbap-zzsorg8 vbap-zzsorg9
vbap-zzsorg10 INTO gt_textname.
gt_textobject-tdid = c_0002.
gt_textobject-tdname = gt_textname.
gt_textobject-tdobject = c_vbbp.
gt_textobject-tdspras = sy-langu.
APPEND gt_textobject.
CONCATENATE 'relationship Owner:' vbap-zzrelid INTO gt_text-tdline
SEPARATED BY space.
APPEND gt_text.
CONCATENATE 'sales org 2 :' vbap-zzsorg2 INTO gt_text-tdline
SEPARATED BY space.
APPEND gt_text.
CONCATENATE 'sales org 3 :' vbap-zzsorg3 INTO gt_text-tdline
SEPARATED BY space.
APPEND gt_text.
CONCATENATE 'sales org 4 :' vbap-zzsorg4 INTO gt_text-tdline
SEPARATED BY space.
APPEND gt_text.
CONCATENATE 'sales org 5 :' vbap-zzsorg5 INTO gt_text-tdline
SEPARATED BY space.
APPEND gt_text.
CONCATENATE 'sales org 6 :' vbap-zzsorg6 INTO gt_text-tdline
SEPARATED BY space.
APPEND gt_text.
CONCATENATE 'sales org 7 :' vbap-zzsorg7 INTO gt_text-tdline
SEPARATED BY space.
APPEND gt_text.
CONCATENATE 'sales org 8 :' vbap-zzsorg8 INTO gt_text-tdline
SEPARATED BY space.
APPEND gt_text.
CONCATENATE 'sales org 9 :' vbap-zzsorg9 INTO gt_text-tdline
SEPARATED BY space.
APPEND gt_text.
CONCATENATE 'sales org 10 :' vbap-zzsorg10 INTO gt_text-tdline
SEPARATED BY space.
APPEND gt_text.
CALL FUNCTION 'SAVE_TEXT'
EXPORTING
header = gt_textobject
savemode_direct = 'X'
TABLES
lines = gt_text
EXCEPTIONS
id = 1
language = 2
name = 3
object = 4
OTHERS = 5.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
kindly resolve the problem with the above code.
Thanks,
Preethi. -
Hi,
I'm trying to create a new text for an existing production order using FM:
CALL FUNCTION 'CREATE_TEXT'
EXPORTING
fid = 'KOPF'
flanguage = sy-langu
fname = l_name "mandt+Prod.order
fobject = 'AUFK'
TABLES
flines = i_line[] "Message text info
EXCEPTIONS
no_init = 1
no_save = 2
OTHERS = 3.
But when I go to see it with transaction CO03 ... this created text do not appear !!!!!
Table STXH has my new register .... can someone help me?I see the problem now, it shows in STXH, but not in CO02. The problem is that in this transaction, it checks an indicator in AUFK called LTEXT. This needs to be set in order to show the text in the text container in CO02. Normally, I wouldn't suggest a direct table update, but in this case it may be ok to do so. Move SY-LANGU to this field and update, then the text should show fine in the CO02 transaction. See the sample program, this works in my system. I can see the text in the container in CO02.
report zrich_0001.
data: xaufk type aufk.
data: header type thead.
data: ilines type table of tline with header line.
parameters: p_aufnr type aufk-aufnr.
header-tdobject = 'AUFK'.
concatenate sy-mandt p_aufnr into header-tdname.
condense header-tdname no-gaps.
header-tdid = 'KOPF'.
header-tdspras = sy-langu.
ilines-tdline = 'This is a test 1'.
append ilines.
ilines-tdline = 'This is a test 2'.
append ilines.
call function 'SAVE_TEXT'
exporting
client = sy-mandt
header = header
savemode_direct = 'X'
tables
lines = ilines
exceptions
id = 1
language = 2
name = 3
object = 4
others = 5
<b>
* Direct Database Update.
if sy-subrc = 0.
select single * into xaufk from aufk
where aufnr = p_aufnr.
check sy-subrc = 0.
xaufk-ltext = sy-langu.
modify aufk from xaufk.
endif.</b>
Regards,
Rich Heilman -
I am trying to implement some kind of a server listening for requests. The listener part of the app, is a daemon thread that listens for connections and instantiates a handling daemon thread once it gets some. However, my problem is that i must be able to kill the listening thread at the user's will (say via a sto button). I have done this via the Sun's proposed way, by testing a boolean flag in the loop, which is set to false when i wish to kill the thread. The problem with this thing is the following...
Once the thread starts excecuting, it will test the flag, find it true and enter the loop. At some point it will LOCK on the server socket waiting for connection. Unless some client actually connects, it will keep on listening indefinatelly whithought ever bothering to check for the flag again (no matter how many times you set the damn thing to false).
My question is this: Is there any real, non-theoretical, applied way to stop thread in java safely?
Thank you in advance,
LeftyThis was one solution from the socket programming forum, have you tried this??
public Thread MyThread extends Thread{
boolean active = true;
public void run(){
ss.setSoTimeout(90);
while (active){
try{
serverSocket = ss.accept();
catch (SocketTimeoutException ste){
// do nothing
// interrupt thread
public void deactivate(){
active = false;
// you gotta sleep for a time longer than the
// accept() timeout to make sure that timeout is finished.
try{
sleep(91);
}catch (InterruptedException ie){
interrupt();
} -
A problem with Threads and MMapi
I am tring to execute a class based on Game canvas.
The problem begin when I try to Play both a MIDI tone and to run an infinit Thread loop.
The MIDI tone "Stammers".
How to over come the problem?
Thanks in advance
Kobi
See Code example below:
import java.io.IOException;
import java.io.InputStream;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;
public class MainScreenCanvas extends GameCanvas implements Runnable {
private MainMIDlet parent;
private boolean mTrucking = false;
Image imgBackgound = null;
int imgBackgoundX = 0, imgBackgoundY = 0;
Player player;
public MainScreenCanvas(MainMIDlet parent)
super(true);
this.parent = parent;
try
imgBackgound = Image.createImage("/images/area03_bkg0.png");
imgBackgoundX = this.getWidth() - imgBackgound.getWidth();
imgBackgoundY = this.getHeight() - imgBackgound.getHeight();
catch(Exception e)
System.out.println(e.getMessage());
* starts thread
public void start()
mTrucking = true;
Thread t = new Thread(this);
t.start();
* stops thread
public void stop()
mTrucking = false;
public void play()
try
InputStream is = getClass().getResourceAsStream("/sounds/scale.mid");
player = Manager.createPlayer(is, "audio/midi");
player.setLoopCount(-1);
player.prefetch();
player.start();
catch(Exception e)
System.out.println(e.getMessage());
public void run()
Graphics g = getGraphics();
play();
while (true)
tick();
input();
render(g);
* responsible for object movements
private void tick()
* response to key input
private void input()
int keyStates = getKeyStates();
if ((keyStates & LEFT_PRESSED) != 0)
imgBackgoundX++;
if (imgBackgoundX > 0)
imgBackgoundX = 0;
if ((keyStates & RIGHT_PRESSED) != 0)
imgBackgoundX--;
if (imgBackgoundX < this.getWidth() - imgBackgound.getWidth())
imgBackgoundX = this.getWidth() - imgBackgound.getWidth();
* Responsible for the drawing
* @param g
private void render(Graphics g)
g.drawImage(imgBackgound, imgBackgoundX, imgBackgoundY, Graphics.TOP | Graphics.LEFT);
this.flushGraphics();
}You can also try to provide a greater Priority to your player thread so that it gains the CPU time when ever it needs it and don't harm the playback.
However a loop in a Thread and that to an infinite loop is one kind of very bad programming, 'cuz the loop eats up most of your CPU time which in turn adds up more delays of the execution of other tasks (just as in your case it is the playback). By witting codes bit efficiently and planning out the architectural execution flow of the app before start writing the code helps solve these kind of issues.
You can go through [this simple tutorial|http://oreilly.com/catalog/expjava/excerpt/index.html] about Basics of Java and Threads to know more about threads.
Regds,
SD
N.B. And yes there are more articles and tutorials available but much of them targets the Java SE / EE, but if you want to read them here is [another great one straight from SUN|http://java.sun.com/docs/books/tutorial/essential/concurrency/index.html] .
Edited by: find_suvro@SDN on 7 Nov, 2008 12:00 PM
Maybe you are looking for
-
A lot of questions but few answers. That is a fact.
A lot of questions and few answers. That is a fact. My question is about deregistering a kaputt PC, and synchronizing iPod and iPod with a replacement PC w/o losing content. I had a Toshiba with tummy trouble sychronized with and iPod and an iPad.
-
Batch Convert InDesign Files to PDF: Acrobat 9 Pro Opens CS3
A question came up in the InDesign forum about batch converting InDesign files. I've never really needed to do it but I was aware of the batch convert command. The OP reported errors so I tried it myself and while it worked, for some reason Acrobat 9
-
I`m just wondering if someone can help me with this. We are having difficulties with the scrept that previous IT guy created. Suddenly it gives us the following error: Script : '==================== ' NAME: CreateOutlookSignature.vbs ' AUTHOR:
-
I'm building an Ultrabeat kit using various samples from Logic/Garageband. Is there a way to link multiple voices together, such as the way playing a closed hi-hat after an open one will stop the open sample? I know this can be done in EXS, but I als
-
Problem solving pivot or not to pivot
Problem: my current code is not viewing data as expected will come back re-write the question