Hi BAPI_ENTRYSHEET_CREATE Problem

Hi abapers
we have requirement to call BAPI_ENTRYSHEET_CREATE from JAVA throguh JCO.
but the COMMIT is already writeen by sap inisde ABAP Source code.
but when JCO called BAPI_ENTRYSHEET_CREATE Multiple times java people getting the error messgae as 'USER ALREADY PROCESSING PURCHASE ORDER'.
i know that i can use 'BAPI_TRANSACTION_COMMIT' where WAIT = 'X' for BAPI which doesn't have inside Commit code.
for BAPI_ENTRYSHEET_CREATE already commit is written.
how can i avoid the above error message while calling form JAVA.
thanks & Regards
Ramesh

Hi ramesh,
pass the TESTRUN parameter as 'X' and run.
the
if the return table is empty or is with no errors, then use bapi_transaction_commit.
else use the fm BAPI_TRANSACTION_ROLLBACK.
Regards,
ravi

Similar Messages

  • BAPI_ENTRYSHEET_CREATE - problem

    Hi,
    In this FM all field are filled like note 420334 but it returns always the same error - SE536.
    I can´t find any describe about this error.
    Can anybody help pls

    hi,
    i opened a question in SAP about this issue they help me by changing the entries in the function and saying it was work but the cost center, kostl, in the diferent lines are still the same.
    Don´t know what to change so that the diferent kostl´s sent by me could be reflected in the diferent lines in ML81N.
    Could anyone help pls

  • Problem with BAPI_ENTRYSHEET_CREATE

    Hi Experts,
    In my upload program for Service Entry Sheet (ML81N) i am using BAPI_ENTRYSHEET_CREATE.I am reading all the PO related information (like PO, item, quantity, gross price, network, activity etc) from a flat file.Program is successfully creating the Service Entry Sheet, but the problem is that it is not picking the network value from the flat file, instead it is picking network value from the PO.
    I am populating the bapi structures as follows:
    Refresh iEsll.
    Refresh iEskn.
    ***To populate Header Data of Entry Sheet(BAPIESSRC)
    Clear wEssr.
    wEssr-pckg_no = c1.
    wEssr-short_text = short text from flat file
    wEssr-po_number = PO from flat file
    wEssr-po_item = PO Item from flat file
    wEssr-location = Location from flat file
    wEssr-doc_date = sy-datum.
    wEssr-post_date = sy-datum.
    wEssr-acceptance = cX.
    ***To populate Services Data of Entry Sheet(BAPIESLLC)
    Clear wEsll.
    wEsll-pckg_no = c1.
    wEsll-line_no = c1.
    wEsll-ext_line = c0.
    wEsll-outl_level = c0.
    wEsll-outl_ind = cX.
    wEsll-subpckg_no = c2.
    Append wEsll To iEsll.
    Loop At flat file data.
    ***To populate Services Data of Entry Sheet(BAPIESLLC)
    lExt = lExt + 10.
    lLine = lLine + 1.
    Clear wEsll.
    wEsll-pckg_no = c2.
    wEsll-line_no = lLine.
    wEsll-ext_line = lExt.
    wEsll-outl_level = c0.
    wEsll-subpckg_no = c0.
    wEsll-quantity = quantity from flat file
    wEsll-base_uom = UOM from flat file
    wEsll-gr_price = Gross price from flat file
    wEsll-pln_pckg = Package from PO
    wEsll-pln_line = Package line from PO
    wEsll-short_text = Item Short Text from flat file
    wEsll-tax_code = Tax code from flat file
    Append wEsll To iEsll.
    ***To populate Account Assignment Data of Entry Sheet(BAPIESKNC)
    Clear wEskn.
    wEskn-pckg_no = c1.
    wEskn-serial_no = c1.
    wEskn-network = Network from flat file
    wEskn-activity = Activity from flat file
    wEskn-gl_account = GL Account from flat file
    Append wEskn To iEskn.
    Clear wSes1.
    EndLoop.
    CALL FUNCTION 'BAPI_ENTRYSHEET_CREATE'
    EXPORTING
    ENTRYSHEETHEADER = wEssr
    TESTRUN = pTest
    IMPORTING
    ENTRYSHEET = wSnum
    TABLES
    ENTRYSHEETACCOUNTASSIGNMENT = iEskn
    ENTRYSHEETSERVICES = iEsll
    ENTRYSHEETSRVACCASSVALUES = iEskl
    RETURN = iMsg.
    Could anyone please let me know what needs to be done to resolve this.
    Thanks
    Anil

    Hi,
    Thanks a lot for the reply.
    Still im not able to clear the error 'Error during update'.
    Im passing following parameters to BAPI_ENTRYSHEET_CREATE.
        Refresh iEsll.
        Refresh iEskn.
    ***To populate Header Data of Entry Sheet
        Clear wEssr.
        wEssr-po_number = wSes-ebeln.
        wEssr-po_item = wSes-ebelp.
        wEssr-short_text = wSes-txz01.
        wEssr-location = wSes-dlort.
        wEssr-person_int = sy-uname.
        wEssr-pckg_no = 1.
        wEssr-doc_date = sy-datum.
        wEssr-post_date = sy-datum.
        wEssr-acceptance = cX.
        wEssr-fin_entry = cX.
    ***To populate Services Data of Entry Sheet
        Clear wEsll.
        wEsll-pckg_no = 1.
        wEsll-line_no = 1.
        wEsll-ext_line = 0.
        wEsll-outl_level = '0'.
        wEsll-outl_no = '1'.
        wEsll-outl_ind = cX.
        wEsll-subpckg_no = c2.
        wEsll-pln_line = 123.
        wEsll-short_text = wSes-ktext1.
        wEsll-quantity = wSes-menge.
        wEsll-base_uom = wSes-meins.
        wEsll-gr_price = wSes-tbtwr.
        wEsll-tax_code = wSes-mwskz.
        Append wEsll To iEsll.
    ***To populate Account Assignment Data of Entry Sheet
        Clear wEskn.
        wEskn-pckg_no = '1'.
        wEskn-network = wSes-nplnr.
        wEskn-activity = wSes-vornr.
        wEskn-gl_account = wSes-sakto.
        Append wEskn To iEskn.
    Could you please let me know where i am doing wrong.
    Thanks once again.
    Regards,
    Vinny

  • Problems with BAPI_ENTRYSHEET_CREATE

    Hi,
    I am using that function to fill several lines in a document.
    He puts the lines but the field costcenter - kostl is the same to every line but i am sending diferent kostl's in the function.
    It apears that he choses random number in the table sendt in the function and puts to every line.
    What could be the problem??
    i am using the code:
            LOOP AT it_am INTO wa_am WHERE xblnr = wa_am_i-xblnr
                                                   AND txz01 = wa_am_i-txz01.
              counter = counter + 1.
              it_eskn-pckg_no = pac.
              it_eskn-gl_account = it_account-g_l_acct.
              it_eskn-costcenter = wa_am-kostl.
              it_eskn-serial_no = counter.
              it_eskn-counter = counter.
              APPEND it_eskn.
              CLEAR v_quant.
              it_eskl-percentage = ( wa_am-tbtwr / v_quant ) * 100."wa_am_h-mkntm.
              it_eskl-pckg_no = pac.
              it_eskl-line_no = counter.
              APPEND  it_eskl.
            ENDLOOP.
          CALL FUNCTION 'BAPI_ENTRYSHEET_CREATE'
            EXPORTING
              entrysheetheader            = wa_header
              testrun                     = mode
            IMPORTING
              entrysheet                  = num
            TABLES
              entrysheetaccountassignment = it_eskn
              entrysheetservices          = it_esll
              entrysheetsrvaccassvalues   = it_eskl
              return                      = it_return.
    in table it_eskn there are 100 lines with diferent kostl.
    tks in advanced

    ohhh....
    do i need to run the function  CONVERSION_EXIT_ALPHA_INPUT ??
    stupid error
    i will try...tks

  • BAPI BAPI_ENTRYSHEET_CREATE - Service Entry Sheet - MM

    Hi all,
    I am trying to create a service entry sheet using the BAPI - BAPI_ENTRYSHEET_CREATE.
    However the BAPI is executed and the service entry sheet is created OK
    but in ML81N it shows the message SE001.
    The problem occurs only when the PO have 2 items and the entry sheet is for 2o. item.
    When the PO have 1 item the my routine is OK.
    can anyone suggest any solution for this ...
    From now, thanks.
    my code:
    form create_SES.
      data: SUBPCKG_NO type ESLL-SUB_PACKNO,
               LINE_NO    type BAPIESLLC-LINE_NO.
      data: begin of WA_PO_HEADER occurs 1.
              include structure BAPIEKKOL.
      data: end of WA_PO_HEADER.
      data: PO_ITEMS        type BAPIEKPO occurs 0 with header line,
               PO_SERVICES type BAPIESLL occurs 0 with header line.
      data: begin of PO_RET occurs 0.
              include structure BAPIRETURN.
      data: end of PO_RET.
      data: ENTRYSHEET type BAPIESSR-SHEET_NO.
      data: IT_ESSR like BAPIESSRC occurs 0
                    with header line.
      data: IT_ESKN like BAPIESKNC occurs 0
                    with header line.
      data: IT_ESLL like BAPIESLLC occurs 0
                    with header line.
      data: IT_ESKL like BAPIESKLC occurs 0
                    with header line.
      data: begin of IT_RET occurs 0.
              include structure BAPIRET2.
      data: end of IT_RET.
      call function 'BAPI_PO_GETDETAIL'
        exporting
          PURCHASEORDER    = IT_FRS_C-FRS_PO  " for example 4500016194
          ITEMS            = 'X'
          SERVICES         = 'X'
        importing
          PO_HEADER        = WA_PO_HEADER
        tables
          PO_ITEMS         = PO_ITEMS
          PO_ITEM_SERVICES = PO_SERVICES
          RETURN           = PO_RET.
      loop at PO_RET where TYPE = 'E' or TYPE = 'A'.
        return.    " ERROR in PO
      endloop.
      loop at PO_ITEMS.
        if PO_ITEMS-PO_ITEM <> 20.                       " <<<<< atention for this: only item 20 in PO
          read table PO_SERVICES with key PCKG_NO = PO_ITEMS-PCKG_NO.
          SUBPCKG_NO = PO_SERVICES-SUBPCKG_NO.
          delete PO_SERVICES where PCKG_NO = SUBPCKG_NO.
          delete PO_SERVICES where PCKG_NO = PO_ITEMS-PCKG_NO.
          delete PO_ITEMS.
        endif.
      endloop.
      loop at PO_ITEMS.
        IT_ESSR-PO_NUMBER    = PO_ITEMS-PO_NUMBER.
        IT_ESSR-PO_ITEM      = PO_ITEMS-PO_ITEM.
        IT_ESSR-PCKG_NO      = PO_ITEMS-PCKG_NO.
        IT_ESSR-ACCEPTANCE   = IT_FRS_C-FRS_ACEITE.   " begin of my data = ' '
        IT_ESSR-DOC_DATE     = IT_FRS_C-FRS_DTDOC.    "                  = ''
        IT_ESSR-POST_DATE    = IT_FRS_C-FRS_DTLANCA.  "                  = ''
        IT_ESSR-REF_DOC_NO   = IT_FRS_C-FRS_REFER.    "                  = '12345-67'
        IT_ESSR-SHORT_TEXT   = IT_FRS_C-FRS_TXT.      "                  = ''
        IT_ESSR-EXT_NUMBER   = IT_FRS_C-FRS_NROEXT.   "                  = ''
        IT_ESSR-LOCATION     = IT_FRS_C-FRS_LOCAL.    "                  = ''
        IT_ESSR-BEGDATE      = IT_FRS_C-FRS_DTINI.    "                  = ''
        IT_ESSR-ENDDATE      = IT_FRS_C-FRS_DTFIM.    "                  = ''
        IT_ESSR-PERSON_INT   = IT_FRS_C-FRS_ENCINT.   "                  = ''
        IT_ESSR-PERSON_EXT   = IT_FRS_C-FRS_ENCEXT.   " end of my data   = ''
        if PO_ITEMS-ACCTASSCAT = 'U'.
          IT_ESSR-ACCASSCAT = 'K'.
        else.
          IT_ESSR-ACCASSCAT = PO_ITEMS-ACCTASSCAT.
        endif.
        append IT_ESSR.
      endloop.
      LINE_NO = 1.
      loop at PO_SERVICES.
        clear IT_ESLL.
        IT_ESLL-SHORT_TEXT  = PO_SERVICES-SHORT_TEXT.
        IT_ESLL-QUANTITY    = PO_SERVICES-QUANTITY.
        IT_ESLL-SERVICE     = PO_SERVICES-SERVICE.
        IT_ESLL-PCKG_NO     = PO_SERVICES-PCKG_NO.
        IT_ESLL-LINE_NO     = LINE_NO.
        IT_ESLL-EXT_LINE    = PO_SERVICES-EXT_LINE.
        IT_ESLL-OUTL_IND    = PO_SERVICES-OUTL_IND.
        IT_ESLL-SUBPCKG_NO  = PO_SERVICES-SUBPCKG_NO.
        IT_ESLL-PLN_PCKG    = PO_SERVICES-PLN_PCKG.
        IT_ESLL-PLN_LINE    = PO_SERVICES-PLN_LINE.
        IT_ESLL-BASE_UOM    = PO_SERVICES-BASE_UOM.
        IT_ESLL-UOM_ISO     = PO_SERVICES-UOM_ISO.
        IT_ESLL-PRICE_UNIT  = PO_SERVICES-PRICE_UNIT.
        IT_ESLL-FROM_LINE   = PO_SERVICES-FROM_LINE.
        append IT_ESLL.
        LINE_NO = LINE_NO + 1.
      endloop.
      call function 'BAPI_ENTRYSHEET_CREATE'
        exporting
          ENTRYSHEETHEADER           = IT_ESSR
          TESTRUN                    = ' '
        importing
          ENTRYSHEET                  = ENTRYSHEET
        tables
          ENTRYSHEETACCOUNTASSIGNMENT = IT_ESKN
          ENTRYSHEETSERVICES          = IT_ESLL
    *      ENTRYSHEETSRVACCASSVALUES   = IT_ESKL
          RETURN                      = IT_RET
    *      ENTRYSHEETSERVICESTEXTS     =
    *      ENTRYSHEETHEADERTEXT        =
    endform.

    Did you not search? Google has 3600 hits for BAPI_ENTRYSHEET_CREATE
    the second hit is a wiki from SCN with sample coding
    the third hit  has a link to a OSS note with a promising title 420334 - BAPI_ENTRYSHEET_CREATE: Model for creation

  • Examples on values to be given for bapi_entrysheet_create

    hi ,
    just have a problem through the bapi i am able to create the entry sheet but the material , i mean the line items are not created.

    Here is an example of values given to various import/tables parameters of BAPI 'BAPI_ENTRYSHEET_CREATE'.
    Hope this will help you.
    <u><b>ENTRYSHEETHEADER</b></u>
    PCKG_NO                        0000000001     
    SHORT_TEXT                     TEST           
    PO_NUMBER                      4500017443     
    PO_ITEM                        00010          
    BLOCK_IND                                     
    SCORE_TIME                       0            
    SCORE_QUAL                       0            
    DOC_DATE                       12.10.2005     
    POST_DATE                      12.10.2005     
    REF_DOC_NO                                    
    ACCASSCAT                      F              
    COMM_NO                                       
    USER_FIELD                                    
    ACCEPTANCE                     X              
    <u><b>ENTRYSHEETACCOUNTASSIGNMENT</b></u>                                         
    PCKG_NO                        0000000001
    SERIAL_NO                      01        
    GL_ACCOUNT                     417000    
    BUS_AREA                       9900      
    COSTCENTER                     9010      
    SD_DOC                                   
    ITM_NUMBER                     000000    
    ASSET_NO                                 
    SUB_NUMBER                               
    ORDER                                    
    CO_AREA                        2000      
    TO_COSTCTR                               
    TO_ORDER                                 
    TO_PROJECT                               
    COST_OBJ                                 
    PROF_SEG                       0000000000
    PROFIT_CTR                     3402 
    <u><b>ENTRYSHEETSERVICES</b></u>  (two lines)
    PCKG_NO                        0000000001                      
    LINE_NO                        0000000001                      
    EXT_LINE                       0000000000                      
    OUTL_LEVEL                      0                              
    OUTL_NO                                                        
    OUTL_IND                       X                               
    SUBPCKG_NO                     0000000002                      
    SERVICE                                                        
    SERV_TYPE                                                      
    EDITION                        0000                            
    SSC_ITEM                                                       
    EXT_SERV                                                       
    QUANTITY                                   0,000               
    BASE_UOM                                                       
    UOM_ISO                                                        
    OVF_TOL                        0,0                             
    OVF_UNLIM                                                      
    PRICE_UNIT                         0                           
    GR_PRICE                                              0,0000   
    FROM_LINE                      1                               
    TO_LINE                                                        
    PCKG_NO                        0000000002                     
    LINE_NO                        0000000002                     
    EXT_LINE                       0000000020                     
    OUTL_LEVEL                      0                             
    OUTL_NO                                                       
    OUTL_IND                                                      
    SUBPCKG_NO                     0000000000                     
    SERVICE                        3000000000017                  
    SERV_TYPE                                                     
    EDITION                        0000                           
    SSC_ITEM                                                      
    EXT_SERV                                                      
    QUANTITY                                   2,000              
    BASE_UOM                       AU                             
    UOM_ISO                        PCE                            
    OVF_TOL                        0,0                            
    OVF_UNLIM                                                     
    PRICE_UNIT                         1                          
    GR_PRICE                                        100 000,0000  
    FROM_LINE                                                     
    TO_LINE                                                       
    SHORT_TEXT                     WINDOW INSTALLATION            
    <u><b>ENTRYSHEETSRVACCASSVALUES</b></u>
    PCKG_NO                        0000000002       
    LINE_NO                        0000000002       
    SERNO_LINE                     01               
    PERCENTAGE                     100,0            
    SERIAL_NO                      01               
    QUANTITY                                   2,000
    NET_VALUE                          100 000,00

  • BAPI_EntrySheet_Create Issue

    Hi Experts,
    I am using the BAPI_EntrySheet_Create to create a SES without using the service master. I provide the entrysheet header, account assignment and Entryservices information. The BAPI returns with message that SES has been successfully created. But when displaying the SES using ML81N transaction, there is no line information displayed like short text, quantity or gross price.
    Please help.
    Thanks,

    Since it's been a while you wrote I assume this problem was solved.
    But if you didn't....:
    For calling the service, you must specify the service included in the PO by entering such values as PACKNO and SUBPACKNO. You can find this information in EKPO by entering with EBENL and EBELP, and extracting the value that EKPO-PAKNO gives you. Then go to table ESLL and get SUBPACKNO. Be sure to transfer this information (along with other parameters) to bapi BAPI_ENTRYSHEET_CREATE in a correct way or it'll crash.
    Currently we have an issue with this bapi: after getting the service, an endless loop appears and a time-out dump arises.
    If nothing works, I'll write a message with more details to call for help.
    Sebastian

  • Assign the network code with BAPI_ENTRYSHEET_CREATE

    Hi,
    I want to set the NETWORK CODE of the PO to every services that I insert in the entry sheet created with the BAPI_ENTRYSHEET_CREATE.
    Now I am able to set the NETWORK CODE only for planned services but not for services that comes from contract linked with the PO in this case the services are inserted in the entry sheet with the WBS code of the contract.
    How can I resolve this problem. Is there any parameter that I have to set in the BAPI?
    Thanks in advance
    Luca

    Anyone could answer to my question?
    Thanks
    Luca

  • Bapi BAPI_ENTRYSHEET_CREATE

    Hello,
      About this question i found one thread in Abap forum :
    BAPI_ENTRYSHEET_CREATE
      and i have the same doubt that appears in the end of the thread. Can anyone explain the significance of the import and table field parameters, related to one P.O. with services items. Also, please with the link between the data entered in the bapi, and the EKKO, EKPO and ESLL contents for that purchase order.
      I'm trying to use the bapi, but i got the message that there's an error in the register update. The bapi returns one entry sheet number, but it does not exists.
    Thanks,
    Paulo Sousa

    Hi,
      The problem is i believe i'm filling the entry parameters well, but i think there's someting missing, reason why i got the error message. In my example i have P.O n. 4500009283 that have in EKPO PACKNO = 16964. In ESLL the entry that have PACKNO = 16964 has SUB_PACKNO = 16965. Also in ESLL with PACKNO = 16965 i have 4 entries, one of them ( with EXT_NUMBER = 0060 ) is the service i want to pass to the entry sheet with Servico code = 4000001, quantity 1 and value 100, 00.
      To do that i'm filling the following parameters :
    ENTRYSHEETHEADER
    PCKG_NO = 0000016964
    SHORT_TEXT = TEST
    PO_NUMBER = 4500009283
    PO_ITEM = 00010
    DOC_DATE = 27.12.2006
    POST_DATE = 27.12.2006
    ACCEPTANCE = X
    ENTRYSHEETACCOUNTASSIGNMENT
    PCKG_NO = 0000016964
    GL_ACCOUNT = 62235000
    BUS_AREA = ANA
    COSTCENTER = 110400
    ENTRYSHEETSERVICES ( 2 entries )
    1ST
    PCKG_NO = 0000016964
    LINE_NO = 0000000001
    SUBPCKG_NO = 0000016965
    2ND
    PCKG_NO = 0000016965
    LINE_NO = 0000000002
    EXT_LINE = 0000000060 ( the service item i want to enter )
    SERVICE = 4000001
    QUANTITY = 1,000
    BASE_UOM = UN
    GR_PRICE = 100,00
    ENTRYSHEETSRVACCASSVALUES
    PCKG_NO = 0000016965
    LINE_NO = 0000000002
    QUANTITY = 1,000
    NET_VALUE = 100,00
    and when i test the bapi with those parameters i got the message 'Error updating register'. I got a entrysheet number in the ENTRYSHEET parameter but that entry sheet number does not exists.
      I'll apreciate any sugestion about data that i need to give in the entry parameters/table entries, and that is not being filled at the moment.
    Thanks,
    Paulo Sousa

  • BAPI_ENTRYSHEET_CREATE Usage

    Hi Friends,
    i am using this BAPI ( BAPI_ENTRYSHEET_CREATE) in my code
    and for a partcicular scenario return table is filled with the error message
    'sum of percentages > 1000.0 < Exceeds 100%'
    I am unable to run the bapi due to auth issue for the same scenario .
    I tried going through the code of BAPI to search for this message , I tried even checking message class 'SE'.
    Is there any smarter way i can find where exactly msg get triggered.
    Thanks
    Poornima

    Hi,
    I am also facing the same problem.Could you guide me how to solve this issue.
    Regards,
    Surendar Reddy.

  • BAPI_ENTRYSHEET_CREATE ses Change % allocation - Po Planned account assignm

    Objective:
    u2022     Create Service Entry Sheet SES using BAPI_ENTRYSHEET_CREATE Transaction ML81N.for Purchase order with multiple account assignments.
    u2022     Change the percentage allocation or allocate the quantity to selected accounts when creating the SES. We can do so when we create SES sheets manually.
    Problem: BAPI overrides the input. It allocates the amount to all the cost objects.
    Sample :
    PO account assignment Quantity/Percentage is as 55& and 45 %.
    Manually we can enter quantity which is different from the PO Quantity /Percentage.
    In the  example we are trying to create the SES sheet with the allocation of $10 to first accost object 78003000.
    BAPI automatically distributes the amount to both the cost objects based on the POu2019s percentage.
    Question: Does BAPI support the above functionality.
               If this is supported.
                    Please suggest the sample code of the required entries.
    I have read the following oss notes
    MM_SRV series notes.
    Note 420334 - BAPI_ENTRYSHEET_CREATE: Model for creation
    Note 77272 - MM-SRV: Interface for data exchange  
    Note 452608 - BAPI: Service specifications with outline
    BAPI_ENTRY_SHEET_CREATE tutorial by Christian Kleinschroth
    Please let me know any other OSS notes which will help.
    Thanks
    Shivran

    Hi,
    Check SAP Note 536835 and 986683.
    The function module calls PSPNUM_EXTERN_TO_INTERN_CONV and external number has to be passed to this BAPI.
    Hope it helps.
    Sujay

  • A problem with threads

    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,
    Lefty

    This 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

  • J2ME problem with threads

    Hi all,
    I would like to ask you for a help. I need to write a small program at my university. I started to write a midlet which function would be to countdown time for sports activities. I woul like to start a new thread - the one that counts down - and at the same time make the main thread sleep. After the "countdown" thread finishes, the main thread wakes up and waits for user input. The problem is that when the "countdown" thread finishes his work, I've got Uncaught exception java/lang/NullPointerException. error and the midlet halts.
    Below you can find the code
    import java.lang.*;
    import java.util.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    public class intervals extends MIDlet implements CommandListener
    public Display ekran;
    private SweepCanvas sweeper;
    private Form rundy;
    private TextField round0, round1, round2, round3, round4, round5, round6, round7, round8;
    private long czas,x;
    private Command exitCommand;
    private Command addRound;
    private Command delRound;
    private Command start;
    private TextField repeat;
    private Form odliczanie;
    private Alert ostrz;
    Licznik thread;
    String test;
    StringItem test1;
    int parz,i,j,k;
    static int l;
    int ilrund;
    int ilpowt;
    Item sec;
    long sec1;
    public intervals()
        rundy = new Form("Interwa&#322;y sportowe");
        exitCommand = new Command("Wyj&#347;cie", Command.EXIT, 2);
        addRound = new Command("Dodaj","Dodaj rund&#281;", Command.ITEM,1);
        delRound = new Command("Usu&#324;","Usu&#324; ostatni&#261; rund&#281;", Command.ITEM,1);
        start = new Command("Start", Command.ITEM,1);
        odliczanie = new Form("Odliczanie");
        TextField dodaj(TextField kolej)
            kolej=new TextField("Podaj czas (s) rundy "+parz,null, 4, TextField.NUMERIC);//stworzenie nowej instancji do wybierania czasu trwania rundy
            if(rundy.size()==0)
                rundy.insert(rundy.size(),kolej);
                else
                    rundy.insert(rundy.size()-1, kolej);
            return kolej;
        void odliczanie(TextField round)
            monitor m=new monitor();
            k=Integer.parseInt(round.getString());
            ekran.setCurrent(odliczanie);
            thread=new Licznik(k,odliczanie);
            thread.start();
            ekran.setCurrent(rundy);
    public void startApp()// throws MIDletStateChangeException
        rundy.deleteAll();
        repeat = new TextField("Podaj ilo&#347;&#263; powtórze&#324;",null,1,TextField.NUMERIC);
        rundy.addCommand(addRound);
        rundy.addCommand(exitCommand);
        rundy.setCommandListener(this);
        Canvas obrazek = new MyCanvas();
        ekran = Display.getDisplay(this);
        ekran.setCurrent(obrazek);
        czas=System.currentTimeMillis();
        while (System.currentTimeMillis()<czas+1000)
            continue;
        ekran.setCurrent(rundy);
    public void pauseApp()
    public void destroyApp(boolean unconditional)
        notifyDestroyed();
    public void commandAction(Command c, Displayable s)
        if (c == exitCommand)
            destroyApp(false);
            notifyDestroyed();
        else if(c==addRound)
            if(rundy.size()==0)//Sprawdzenie ilo&#347;ci elementów w celu poprawnego wy&#347;wietlania liczby rund w formie
                parz=1;
                else
                parz=rundy.size();
            switch(parz)
                case 1:
                    round0=dodaj(round0);break;
                case 2:
                    round1=dodaj(round1);break;
                case 3:
                   round2= dodaj(round2);break;
                case 4:
                    round3=dodaj(round3);break;
                case 5:
                    round4=dodaj(round4);break;
                default:
                    ostrz=new Alert("Uwaga","Maksymalna liczba rund wynosi 9", null, AlertType.INFO);
                    ostrz.setTimeout(3000);
                    ekran.setCurrent(ostrz);
            if(rundy.size()==1)
                rundy.append(repeat);
                rundy.addCommand(start);
            rundy.addCommand(delRound);
        else if(c==delRound)
            if(rundy.size()!=0)
                rundy.delete(rundy.size()-2);
                if (rundy.size()==1)
                    rundy.deleteAll();
                if(rundy.size()==0)
                    rundy.removeCommand(delRound);
                    rundy.removeCommand(start);
        else if(c==start)
            ilrund=rundy.size()-1;
            if(this.repeat.size()>0)
                ilpowt=Integer.parseInt(this.repeat.getString());
            ekran = Display.getDisplay(this);
            for (i=1; i<=ilpowt;i++)
                odliczanie= new Form("Odliczanie");
                 for (j=0;j<ilrund;j++)
                    switch(j)
                         case 0:
                             odliczanie(round0);
                             break;
                         case 1:
                             odliczanie(round1);
                             break;
                         case 2:
                             odliczanie(round2);
                             break;
                         case 3:
                             odliczanie(round3);
                             break;
                         case 4:
                             odliczanie(round4);
                             break;
                         case 5:
                             odliczanie(round5);
                             break;
                         case 6:
                             odliczanie(round6);
                             break;
                         case 7:
                             odliczanie(round7);
                             break;
                         case 8:
                             odliczanie(round8);
                             break;
    class Licznik extends Thread
        int czas1,k;
        Form forma;
        monitor m;
        public Licznik(int k,Form formap)
            czas1=k;
            forma=formap;
        public synchronized void run()
            while(czas1>0)
                forma.deleteAll();
                forma.append("Czas pozosta&#322;y (s): "+czas1);
                try{Thread.sleep(1000);} catch(InterruptedException e){e.printStackTrace();}
                czas1--;
            if(czas1<=0)
                m.put();
        }and monitor class
    public class monitor
    boolean busy=false;
    synchronized void get()
        if(!busy)
            try
                wait();
            }catch(InterruptedException e){e.printStackTrace();}
        notify();
    synchronized void put()
        if(busy)
            try
            wait();
            }catch(InterruptedException e){e.printStackTrace();}
        busy=true;
        notify();
    }Can anybody help me with this?

    Groovemaker,
    Your Licznik class has a member m of type monitor, which has not been instantiated (in other words is null) hence, when calling m.put() you get NullPointerException. Please also mind, that using Thread.sleep(1000) is not an accurate way of measuring time.
    If I may, please use recommended for Java class naming conventions - some of your names use lower case, while other don't which is confusing to the reader.
    Daniel

  • Problem with threads within applet

    Hello,
    I got an applet, inside this applet I have a singleton, inside this singleton I have a thread.
    this thread is running in endless loop.
    he is doing something and go to sleep on and on.
    the problem is,
    when I refresh my IE6 browser I see more than 1 thread.
    for debug matter, I did the following things:
    inside the thread, sysout every time he goes to sleep.
    sysout in the singleton constructor.
    sysout in the singleton destructor.
    the output goes like this:
    when refresh the page, the singleton constructor loading but not every refresh, sometimes I see the constructor output and sometimes I dont.
    The thread inside the singleton is giving me the same output, sometime I see more than one thread at a time and sometimes I dont.
    The destructor never works (no output there).
    I don't understand what is going on.
    someone can please shed some light?
    thanks.
    btw. I am working with JRE 1.1
    this is very old and big applet and I can't convert it to something new.

    Ooops. sorry!
    I did.
         public void start() {
         public void stop() {
         public void destroy() {
              try {
                   resetAll();
                   Configuration.closeConnection();
                   QuoteItem.closeConnection();
              } finally {
                   try {
                        super.finalize();
                   } catch (Throwable e) {
                        e.printStackTrace();
         }

Maybe you are looking for

  • Error while Deploying composite using Jdeveloper

    Hi , I made app server connection and tested the configuration. All the tests ran succesfully. However when I try to deploy my SOA project on server , I am not able to look up soa server . Server is on different machine and connected using wifi-route

  • After updating my iPhone 4S to IOS6 my iPhone does not appear in iTunes.

    After I updated my iPhone 4S to IOS6, I experienced the following issues. 1. My iPhone would not connect to WIFI, even though the WIFI icon on my iPhone indicated that it was. This in it self cost me $239.00 in excess data usage. I have since got the

  • How to input tapes from a DAT into garage band?

    I have a Sony DAT recorder and I want to transfer my tapes into garage band. I tired using a stereo male to stereo male audio cable through the headphone jack on my mac and no sound can be detected by garage band. What type of cable/connector would I

  • Problems Running bookstore2

    Hi, I'm trying to run the bookstore application in WDSc and I get the following Error when I try to execute this code. Any help would be greatly appreciated. Thanks, Jim <jsp:setProperty name="bookDB" property="database" value="${bookDBAO}" /> [Servl

  • How do i find my screen name to set up eprint

    I have a 6500A - trying to set up eprint?