Executing BAPI_PO_CREATE1 in a loop results in multiple success messages

Hi all,
I have a process where I need to create multiple POs with one item each. For creating the POs I use BAPI_PO_CREATE1. The creation itself works fine and created POs are also correct.
But what is a bit confusing is the content of the RETURN table of the BAPI. From the second created PO on I also get ALL messages of the previously created POs although I have a COMMIT WORK AND WAIT after each creation and the return table is always empty when executing the BAPI.
Example:
I need to create two POs.
First run of the BAPI_PO_CREATE: PO A is created and return table has success message "PO A successfully created"
Second run of the BAPI_PO_CREATE: PO B is created and return table has two success messages: "PO A successfully created" and "PO B successfully created"
But for the second run I also would expect to get only one success message.
Why do I get too many messages? Or do I need to initilize the BAPI somehow?
By the way, I have the same problem with BAPI_PO_CHANGE.
regards
René

Hi,
so again: the return table is cleared/refreshed all times when executing the loop and a commit is done!
Unfortunately the whole coding is implemented to the SAP AIF so the AIF is doing the loops. But in debugging I clearly see that the return table is empty before executing the BAPI.
Here is the coding. The AIF calls the here described function module in a loop and executes a commit work and wait after each call of the FM.
FUNCTION POST_PURCHASE_ORDER.
*"*"Local Interface:
*"  IMPORTING
*"     REFERENCE(TESTRUN) TYPE  C
*"     REFERENCE(HASH_TAB) TYPE  /AIF/HASHTAB_T OPTIONAL
*"     REFERENCE(IDX_TAB) TYPE  /AIF/IDXTAB_T OPTIONAL
*"  TABLES
*"      RETURN_TAB STRUCTURE  BAPIRET2
*"  CHANGING
*"     REFERENCE(DATA)
*"     REFERENCE(CURR_LINE)
*"     REFERENCE(CURR_DATA)
*"     REFERENCE(SUCCESS) TYPE  /AIF/SUCCESSFLAG
*"     REFERENCE(OLD_MESSAGES) TYPE  BAL_T_MSG
  DATA: lt_po_items        TYPE TABLE OF bapimepoitem,
        lt_po_itemsx       TYPE TABLE OF bapimepoitemx,
        lt_bapiparex       TYPE TABLE OF bapiparex,
        lt_po_conditionx   TYPE TABLE OF bapimepocondx,
        lt_po_header_texts TYPE TABLE OF bapimepotextheader,
        lt_po_item_texts   TYPE TABLE OF bapimepotext,
        ls_po_headerx      TYPE bapimepoheaderx,
        ls_po_headerx_cust TYPE bapi_te_mepoheaderx,
        ls_po_itemx        TYPE bapimepoitemx,
        ls_po_condition    TYPE bapimepocond,
        ls_po_conditionx   TYPE bapimepocondx,
        l_testrun          TYPE bapiflag-bapiflag.
  CHECK curr_line IS NOT INITIAL.
  REFRESH: return_tab[].
  CLEAR: return_tab[].
  l_testrun = testrun.
* Get X-structures for PO header
  PERFORM fill_x_structure USING curr_line-po_header 0 CHANGING ls_po_headerx.
* Create PO Header Custom Fields.
  PERFORM fill_bapiparex USING curr_line-po_header_cust space
                      CHANGING lt_bapiparex[] return_tab[].
* Get X-structures for PO ExtensionIn fields and post them to ExtensionIn as well
  PERFORM fill_x_structure USING curr_line-po_header_cust 0 CHANGING ls_po_headerx_cust.
  PERFORM fill_bapiparex USING ls_po_headerx_cust space
                      CHANGING lt_bapiparex[] return_tab[].
* Get X-structure for PO item
  curr_line-po_item-info_upd = 'A'.
  curr_line-po_item-po_price = '1'.
  PERFORM fill_x_structure USING curr_line-po_item 1 CHANGING ls_po_itemx.
  ls_po_itemx-po_item        = curr_line-po_item-po_item.
  curr_line-po_item-po_price = space.
  curr_line-po_item-info_upd = space.
  APPEND curr_line-po_item  TO lt_po_items.
  APPEND ls_po_itemx TO lt_po_itemsx.
* Get X-structures for PO conditions
  IF NOT curr_line-po_conditions IS INITIAL.
    LOOP AT curr_line-po_conditions INTO ls_po_condition.
      CLEAR ls_po_conditionx.
      ls_po_conditionx-itm_number = ls_po_condition-itm_number.
      PERFORM fill_x_structure_2 USING ls_po_condition 3 0
                              CHANGING ls_po_conditionx.
      APPEND ls_po_conditionx TO lt_po_conditionx.
    ENDLOOP.
  ENDIF.
* Get header and item texts
  APPEND curr_line-po_header_text TO lt_po_header_texts.
  APPEND curr_line-po_item_text   TO lt_po_item_texts.
* Execute BAPI_PO_CREATE1
  CALL FUNCTION 'BAPI_PO_CREATE1'
    EXPORTING
      poheader         = curr_line-po_header
      poheaderx        = ls_po_headerx
      testrun          = l_testrun
      no_price_from_po = c_checked
    IMPORTING
      exppurchaseorder = curr_line-po_number_return
    TABLES
      return           = return_tab
      poitem           = lt_po_items
      poitemx          = lt_po_itemsx
      pocond           = curr_line-po_conditions
      pocondx          = lt_po_conditionx
      extensionin      = lt_bapiparex
      potextheader     = lt_po_header_texts
      potextitem       = lt_po_item_texts
    EXCEPTIONS
      error_message    = 1.
  IF sy-subrc = 1.
    IF NOT sy-msgid IS INITIAL
      AND NOT sy-msgty IS INITIAL
      AND NOT sy-msgno IS INITIAL.
      PERFORM util_add_msg USING sy-msgty sy-msgid sy-msgno sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 CHANGING return_tab[].
    ENDIF.
  ENDIF.
ENDFUNCTION.

Similar Messages

  • Show multiple success messages

    Hi  ,
         I ma showing success messages inside a loop verifying a paticulra condition.  Now when the user runs the report in foreground only  the last message is shown. 
    Is there any way  around.
    Thanks in advance.

    I´d rather go for the solution of building a protocoll in your loop, and adding sucess or error messages for the certain records.
    Then show your protocoll when ready or maybe even just on demand (button).
    This avoids such problems as you run into right now, and it´s a lil bit of a cleaner solution. Besides you will still be able to view the protocoll half an hour later, while your sucess messages would be gone once you press F3.

  • How to clear last payroll result of multiple workers?

    Experts,
    My requirement is to delete the last payroll result of multiple employees.
    PU01 allows to delete for only one employee at a time.
    I tried to create a BDC but not working. Is there any other alternative to do so.
    Regards.

    here it is:
    loop at pa_pernr.
      PERFORM bdc_dynpro     USING 'RPCDPU01'   '1000'.
      PERFORM bdc_field          USING 'BDC_CURSOR' 'RP50G-PERNR'.
      PERFORM bdc_field          USING 'BDC_OKCODE' '=STAR'.
      PERFORM bdc_field          USING 'RP50G-PERNR' pa_pernr-low.
      PERFORM bdc_dynpro     USING 'SAPLSLVC_FULLSCREEN' '0500'.
      PERFORM bdc_field          USING 'BDC_OKCODE' '=DELE'.
      PERFORM bdc_dynpro     USING 'SAPLSPO1'   '0300'.
      PERFORM bdc_field          USING 'BDC_OKCODE' '=YES'.
      CALL TRANSACTION  'PU01' USING bdcdata MODE 'A' UPDATE 'S'.
    endloop.
    " pa_pernr-low contains the employed id number.

  • Errors while executing bapi_po_create1

    Hi experts,
    I am getting errors while executing bapi_po_create1.
    The errors are -
    1. No instance of object type purchaseorder has been created.External reference
    2.Purchase order still contain faulty item
    Please help <removed by moderator>.
    Thanks
    Sahil
    Edited by: Thomas Zloch on Sep 14, 2010 2:30 PM

    Hi,
    Check this code it may help you.
    DATA:
    W_BAPIMEPOHEADER TYPE BAPIMEPOHEADER,
    W_BAPIMEPOHEADERX TYPE BAPIMEPOHEADERX,
    T_BAPIRET2        TYPE STANDARD TABLE OF BAPIRET2
                       WITH HEADER LINE,
    T_BAPIMEPOITEM    TYPE STANDARD TABLE OF BAPIMEPOITEM
                       WITH HEADER LINE,
    T_BAPIMEPOITEMX   TYPE STANDARD TABLE OF BAPIMEPOITEMX
                       WITH HEADER LINE,
    T_POSCHEDULE      TYPE STANDARD TABLE OF BAPIMEPOSCHEDULE
                          WITH HEADER LINE,
    T_POSCHEDULEX     TYPE STANDARD TABLE OF BAPIMEPOSCHEDULX
                      WITH HEADER LINE.
    W_BAPIMEPOHEADER-COMP_CODE = '1000'.
    W_BAPIMEPOHEADER-DOC_TYPE = 'NB'.
    W_BAPIMEPOHEADER-CREAT_DATE = SY-DATUM.
    W_BAPIMEPOHEADER-CREATED_BY = SY-UNAME.
    W_BAPIMEPOHEADER-ITEM_INTVL = '00010'.
    W_BAPIMEPOHEADER-VENDOR = '0000300001'.
    W_BAPIMEPOHEADER-LANGU = SY-LANGU.
    W_BAPIMEPOHEADER-PMNTTRMS = '0001'.
    W_BAPIMEPOHEADER-PURCH_ORG = '1000'.
    W_BAPIMEPOHEADER-PUR_GROUP = '100'.
    W_BAPIMEPOHEADER-CURRENCY = 'INR'.
    W_BAPIMEPOHEADER-DOC_DATE = SY-DATUM.
    W_BAPIMEPOHEADER-VPER_START = '20100728'.
    W_BAPIMEPOHEADER-VPER_END = '20100828'.
    W_BAPIMEPOHEADERX-COMP_CODE = 'X'.
    W_BAPIMEPOHEADERX-DOC_TYPE = 'X'.
    W_BAPIMEPOHEADERX-CREAT_DATE = 'X'.
    W_BAPIMEPOHEADERX-CREATED_BY = 'X'..
    W_BAPIMEPOHEADERX-ITEM_INTVL = 'X'.
    W_BAPIMEPOHEADERX-VENDOR = 'X'.
    W_BAPIMEPOHEADERX-LANGU = 'X'.
    W_BAPIMEPOHEADERX-PMNTTRMS = 'X'.
    W_BAPIMEPOHEADERX-PURCH_ORG = 'X'.
    W_BAPIMEPOHEADERX-PUR_GROUP = 'X'.
    W_BAPIMEPOHEADERX-CURRENCY = 'X'.
    W_BAPIMEPOHEADERX-DOC_DATE = 'X'.
    W_BAPIMEPOHEADERX-VPER_START = 'X'.
    W_BAPIMEPOHEADERX-VPER_END = 'X'.
    T_BAPIMEPOITEM-PO_ITEM  =     '00010'.
    T_BAPIMEPOITEM-MATERIAL =     '000000001002000031'.
    T_BAPIMEPOITEM-PLANT =     '1000'.
    T_BAPIMEPOITEM-QUANTITY =     '10'.
    T_BAPIMEPOITEM-PO_UNIT =     'NOS'.
    T_BAPIMEPOITEM-NET_PRICE = '120.00'.
    T_BAPIMEPOITEM-INFO_UPD ='X'.
    T_BAPIMEPOITEM-PRICE_UNIT = '1'.
    T_BAPIMEPOITEM-TAX_CODE =     'VE'.
    APPEND T_BAPIMEPOITEM.
    T_BAPIMEPOITEMX-PO_ITEM = '00010'.
    T_BAPIMEPOITEMX-PO_ITEMX  =     'X'.
    T_BAPIMEPOITEMX-MATERIAL =     'X'.
    T_BAPIMEPOITEMX-PLANT =     'X'.
    T_BAPIMEPOITEMX-QUANTITY =     'X'.
    T_BAPIMEPOITEMX-PO_UNIT =     'X'.
    T_BAPIMEPOITEMx-NET_PRICE = 'X'.
    T_BAPIMEPOITEMX-INFO_UPD ='X'.
    T_BAPIMEPOITEMX-PRICE_UNIT = 'X'.
    T_BAPIMEPOITEMX-TAX_CODE =     'X'.
    APPEND T_BAPIMEPOITEMX.
    T_POSCHEDULE-PO_ITEM          = '00010'.
    T_POSCHEDULE-SCHED_LINE        = '0001'.
    T_POSCHEDULE-DEL_DATCAT_EXT    = 'D'.
    T_POSCHEDULE-DELIVERY_DATE     =  '09.09.2010'.
    T_POSCHEDULE-QUANTITY          = '10'.
    APPEND T_POSCHEDULE.
    T_POSCHEDULEX-PO_ITEM = '00010'.
    T_POSCHEDULEX-SCHED_LINE = '0001'.
    T_POSCHEDULEX-PO_ITEMX = 'X'.
    T_POSCHEDULEX-SCHED_LINEX = 'X'.
    T_POSCHEDULEX-DEL_DATCAT_EXT = 'X'.
    T_POSCHEDULEX-DELIVERY_DATE = 'X'.
    T_POSCHEDULEX-QUANTITY  = 'X'.
    APPEND T_POSCHEDULEX.
    CALL FUNCTION 'BAPI_PO_CREATE1'
      EXPORTING
        POHEADER                     =  W_BAPIMEPOHEADER
        POHEADERX                    =  W_BAPIMEPOHEADERX
    TABLES
       RETURN                       = T_BAPIRET2[]
       POITEM                       = T_BAPIMEPOITEM[]
       POITEMX                      = T_BAPIMEPOITEMX[]
       POSCHEDULE                   = T_POSCHEDULE[]
       POSCHEDULEX                  = T_POSCHEDULEX[].
    IF SY-SUBRC = 0.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
    EXPORTING
      WAIT          =
    IMPORTING
      RETURN        =
    ENDIF.
    LOOP AT T_BAPIRET2.
    WRITE: /
    T_BAPIRET2-TYPE ,
    T_BAPIRET2-ID,
    T_BAPIRET2-NUMBER,
    T_BAPIRET2-MESSAGE,
    T_BAPIRET2-LOG_NO,
    T_BAPIRET2-LOG_MSG_NO,
    T_BAPIRET2-MESSAGE_V1,
    T_BAPIRET2-MESSAGE_V2,
    T_BAPIRET2-MESSAGE_V3,
    T_BAPIRET2-MESSAGE_V4,
    T_BAPIRET2-PARAMETER,
    T_BAPIRET2-ROW,
    T_BAPIRET2-FIELD,
    T_BAPIRET2-SYSTEM.
    WRITE: / '----
    ENDLOOP.
    Regards,
    Jagadeesh T.

  • How to display MySql query results in multiple columns?

    Hi, I know how to display PHP/MySq
    l query results in a single column, but I am really stuck at displa
    ying the results in multiple columns in DW CS4.
    Can anyone help me with a code example?. I am new to php/mysql. Thanks

    Are you asking how to pivot the results of the query? Do a search for horizontal looping. If that's not what you are asking, please provide more details.

  • ODBC error occurred while executing SQLExtendedFetch to retrieve the result

    Good morning everyone,
    I had the following error message while trying to run a simple query in Answers with 3 dimensional columns, 1 fact, and 4 calculated facts...
    "State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 16001] ODBC error state: S1001 code: 0 message: [Oracle][ODBC]Memory allocation error.. [nQSError: 16011] ODBC error occurred while executing SQLExtendedFetch to retrieve the results of a SQL statement. (HY000)
    It's taking around 2,5 minutes to run, then it give that error message.
    Has anyone got any ideas on where I should get started?
    Update: after 2nd time - it's running fine....I've added a filter...could this be the issue? Too many rows initially?

    Damon,
    you were correct - it was indeed an ODBC issue. Switching to OCI has fixed the issue. This link was also very helpful:
    regarding performance
    In my case, the problem with OCI happened because I was using System DSN name instead of how it's called in tnsnames.

  • Scanning (Into JPEG) of Plain Paper with few graphics results into multiple images on HP 3545

    Scanning (Into JPEG) of Plain Paper with few graphics results into multiple images.
    Whenever I scan a page which is almost a white paper, but has some graphics on it, then the Scanned Files is not a single, rather it becomes in multiple parts e.g. circle in one jpeg file, square in another jpeg file. However the scanning to PDF works fine. Please let me know if this is manufacturing defect or defect in the product I purchased. 

    This only happens if I scan plain paper with few graphics. But scan to jpeg is working fine if the page has multiple objects

  • Handling Multiple Error Messages through EXIT_SAPMM06E_012 for ME28

    Dear Team,
                           After Executing ME28, system will give List of PO's that are to be Released . User will select Multiple  PO's and
    Press Release button in Application toolbar. once it is relased, User will press save Icon for all released PO's. 
    Once Save icon is presed, I need to  do  Validation for Multiple PO's in the user Exit EXIT_SAPMM06E_012 and capture my
    ErrorMessages for all Released PO's for which Validation fails.
    Here in the given user Exit, one PO will be processed at a time as PO is defined as Import Parameter but it will handle all PO's
    and give the output in status bar saying 'Relased Saved' for all PO's which succesfully gonethrough.
    once we execute ME28, system is showing list output with PO's to be Released(As system is handling with Write statments). In this case, we dont have scenario of PBO and PAI Modules( where user can correct error if any validation fails) like we have for ME22,etc.
    I have Written simpel Error Message in the  User Exit.
    once i tried to trigger my user exit  by Releasing and Saving with One PO, Error Message is displayed ( as information Message
    appears) and if i Press Exit button in Error Message, it is coming out of Transaction.
    Is there any Possibilty to Handle Multiple Error Messages ( in my case for  Valdiation Failed Po's)  in ME28 ,after Releasing and Saving , and also user should not come out of Transaction once  Error Messages are Displayed.
    Thanks and Regards
    Suresh

    Hi Suresh,
    there is a tekpo table to handle all po items. you can put it in loop and do validations.
    if any errors through, there may be a ex_messages table of type bapiret2.
    or
    try like this:  MESSAGE E368(00) WITH TEXT-001 TEXT-002.
    thanks
    srinu
    Edited by: srinu rao on Sep 22, 2009 3:43 AM

  • Disk Utility says everything's fine, but Install disk doesn't find my internal drive as a possible destination. When I startup with Command   S, I get a looping "cannot mount errno = 19" message.

    Disk Utility says everything's fine, but Install disk doesn't find my internal drive as a possible destination. When I startup with Command + S, I get a looping "cannot mount errno = 19" message.
    Problem started when I used Tech Tool Pro 6 to "de-fragment volume". Had to cancel that process before it finished because I ran out of time. Thereafter, when I startup my machine normally, I get the gray Apple logo at first, but it changes to a prohibited symbol (circle with a slash thru it) and hangs.
    When I startup holding the Option key, I can see my internal drive, but I get the same results as above.
    When I startup using the MacBook OSX Install DVD, it does not find my internal drive as possible destination.
    When I startup using the MacBook OSX Install DVD and then run Disk Utility, it finds my drive, allows me to "repair" and says everything is fine.
    When I startup with Command + S, I get a looping error message "errno = 19" and cannot stop it to do anything else.
    When I startup from Disk Warrior v4.4, it does not find my internal drive to do any repairs.
    When I startup from Tech Tool Pro 6 and run the "computer check" diagnostics, everything passes but the Volume Structure, which fails at "Volume Extents (B-tree)." When I use TTP's "Tools" option to run "volume repair" it will show my internal drive and allow me to click the GO button, but nothing happens and nothing changes.
    I have a Time Machine backup on an external USB drive, but for as long as the internal drive doesn't mount, I can't use the backup to restore.

    It's a false report and should be ignored.
    I would not rely on TT as I've already said earlier even before Grant posted similar advice.
    I really think the Rigid Disk Block may be corrupted. This holds the partition map and could prevent a volume from being unmounted. Unfortunately, there is no way to fix that without repartitioning the drive which will remove everything. So, before going down this road I hope you have backups or can make a backup.
    Drive Partition and Format
    1. Boot from your Snow Leopard Installer Disc. After the installer loads select your language and click on the Continue button.  When the menu bar appears select Disk Utility from the Utilities menu.
    2. After DU loads select your hard drive (this is the entry with the mfgr.'s ID and size) from the left side list. Note the SMART status of the drive in DU's status area.  If it does not say "Verified" then the drive is failing or has failed and will need replacing.  SMART info will not be reported  on external drives. Otherwise, click on the Partition tab in the DU main window.
    3. Under the Volume Scheme heading set the number of partitions from the drop down menu to one. Click on the Options button, set the partition scheme to GUID then click on the OK button. Set the format type to Mac OS Extended (Journaled.) Click on the Partition button and wait until the process has completed.
    4. Quit DU and return to the installer.  Proceed with reinstalling OS X.
    5. Download and install Mac OS X 10.6.8 Update Combo v1.1.

  • Trying to export my forms results to excel  error message is adobe can not save as the file is open

    trying to export my forms results to excel, error message is adobe cn not save as the file is open in another location,   however, no other file is open.

    Thanks for continuing the help, but it is a medical realted form and I will just keep it confidential at this time.
    Larry Lakes,  Executive Director
    The HANDLE Institute
    [email protected]
    541-639-1588
    P. O. Box 6264
    Bend, OR  97708

  • One IDOC to multiple XML messages

    Hi! I am using the graphical mapper in XI to map the SHPMNT03 IDOC to an XML message. The IDOC has a shipment node and potentially multiple delivery nodes, for example:
    E1EDT20
      - E1EDL20
      - E1EDL20
      - E1EDL20
    I need to create one XML message per E1EDL20 node. I figured I could do this in the mapper but when I execute the map for an IDOC with multiple E1EDL20 nodes, I get a 'Cannot cast 2 to boolean' error. The map executes fine when there is a single E1EDL20 in the IDOC.
    As always, help is very much appreciated and points awarded.
    Thx, Duncan

    Hi Duncan,
    Can you just check if this is what you have done,
    IR
    1. Message Mapping -- Occurence of the Destination message type ( file ) is unbounded
    2. Interface Mapping -- Occurence of the Destination Interface ( File ) is unbounded
    ID
    1. No sender communication channel , sender agreement
    2. Receiver communcation channel for FIle with appropriate FILE CONSTRUCTION MODE
    3. Receiver Determination  and Interface Determination with Sender Interface as the IDOC interface and Receiver Interface as the FILE INTERFACE.
    I think there is some misunderstanding on this front.
    Multimapping will work if you are trying to  do an IDOC to FILE with a 1:N split
    just check this and let me know if you ve missed something.
    Regards,
    Bhavesh

  • How do you remove multiple email messages at one time

    I have a iphone 4 and today it started piling up over 4000 undeliverable messages for no apparent reason. I somehow managed to stop the process but I am left with over 4000 messages that I need to delete. How do you remove multiple email messages at one time. I can "mark" all the messages at once but I cannot find the move or delete button to trash the messages. Can some one help me out.
    Thanking you in advance.
    PL

    Just figured it out - I can select multiple messages as you suggested when I am not in full screen mode.
    So once I come out of full screen mode - then the multiple windows open.
    QED

  • How do I open multiple Mail messages at once?

    I can select multiple Mail messages, but how do I get all of them to open at once? (I actually do want all of them open; I'm not just trying to mark them as Read.) If I double-click on the multiple selection, the first click un-selects all but one message, which the second click opens. I assumed there'd be an Open in the Edit menu, or a Command-O, or an Open button for the Tool Bar, or an Open on a right-click menu or other special menu, but I can't see any of those. The closest I've come so far is Forward, which quotes them all in one reply, but that isn't really what I want. What am I missing?

    just make it is not junk mail

  • Can there be multiple success captions

    I am working in captivate 4 and I would like to know if there is a way to have multiple "success captions". I would essentially like if the video would have a person type in a number and then a random sequence of numbers comes up. The sequence of numbers has to be ten different sets. Thank you veery much.
    - danny

    I don't think so. Does what the user types have to be evaluated (is why you're using success captions)?
    Perhaps better to use a simple interaction and branching?
    Erik

  • How to delete multiple email messages from my Iphone 5c; email folder?

    How to delete multiple email messages from my Iphone 5C; email folder.

    there used to be option to keep last 50,100,200 messages/emails. We need that back. This is ridiculous to delete one by one.

Maybe you are looking for