Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

Post Reply
Posts: 135
Joined: Thu May 15, 2008 4:25 pm
Location: Butterball LLC., Goldsboro, NC, USA


Post by wilhitern1 » Fri May 16, 2008 2:28 pm


We are making payments against a P-Card. Of course these are sent to the bank with all that such entails. In the meantime, we are loosing information on the real vendor. For instance, the purchaser took their P-Card to Walmart and bought ink pens. This is a non-inventoried item. Once the paymant was approved outside of SAP, we stopped caring that they were ink pens but we still care that we spent $5125.72 at Walmart. The plan is to read the banks file and write a PO to Walmart, recieve(create) a GR from Walmart against that PO, and recieve an invoice from Walmart against that PO. When I have writen the code for that, that will end my part of this. There may be other things that users have to do from there. So I am writing an interface that reads an excel and BAPI's a PO creation, a GR creation, and a invoice receipt.

To date, the PO creation works great (from 'BAPI_PO_CREATE'). The created PO can be MIGO_GR'd with movement type 101 and the OK (or Item is adopted into document) flag set and the GR creates prefectly.

The Problem:

I started working the GR create portion of the problem with 'BAPI_GOODSMVT_CREATE'. Eventually, with the help of searching this forum, I've got the GR creating. Unfortunately, it is not adopting to the PO. I haven't been able to find a flag to set that seems to equate to the OK (adopt) flag in MIGO_GR.

Existing Code:

Here is what I'm setting up for 'BAPI_GOODSMVT_CREATE'.

Code: Select all

  MOVE '01' TO lf_gr_code-gm_code.
         INTO (ekpo-ebeln) FROM ekpo
         WHERE bednr = wa_upload-trackingno.
  IF sy-subrc IS INITIAL.
    MOVE ekpo-ebeln TO lf_gr_header-ref_doc_no.
  MOVE '20080414' TO lf_gr_header-pstng_date.
  MOVE sy-datum TO lf_gr_header-doc_date.
  MOVE sy-uname TO lf_gr_header-pr_uname.
  CONCATENATE 'From Vendor -' wa_upload-short_text
              INTO lf_gr_header-header_txt.

  LOOP AT it_gr INTO wa_upload2 WHERE z_vendor = wa_upload-z_vendor.
    SELECT SINGLE ebeln ebelp werks
           INTO (ekpo-ebeln, ekpo-ebelp, ekpo-werks) FROM ekpo
           WHERE bednr = wa_upload2-trackingno.
    IF sy-subrc IS INITIAL.
      MOVE ekpo-ebeln TO lf_gr_item-po_number.
      MOVE ekpo-ebelp TO lf_gr_item-po_item.
      MOVE 'X' TO lf_gr_item-no_more_gr.
      MOVE '1' TO lf_gr_item-entry_qnt.
      MOVE 'EA' TO lf_gr_item-entry_uom.
*      MOVE 'EA' TO lf_gr_item-ENTRY_UOM_ISO.
      MOVE 'B' TO lf_gr_item-mvt_ind.
      MOVE '101' TO lf_gr_item-move_type.
*      MOVE ekpo-werks TO lf_gr_item-plant.
      APPEND lf_gr_item TO lt_gr_item.
* Do something about this because it is an error.
    DELETE it_gr.
So the questions come down to this. Is 'BAPI_GOODSMVT_CREATE' the right BAPI? If so, What initialization stuff am I missing? If not, is there another BAPI? (I've seen a note that Rinscheid Ruediger suggested FM "MB_CREATE_GOODS_MOVEMENT" (on another forum) as an alternative, but I haven't explored it. Does anyone have experience with it so that they can provide some further inducement? I've been avoiding it because I am biased into believing that SAP provides better support of BAPI's.)

Of course, any other suggestions (on topic) would be greatly appreciated.
Last edited by wilhitern1 on Mon May 19, 2008 3:27 pm, edited 1 time in total.

Posts: 607
Joined: Wed Dec 18, 2002 1:05 am
Location: Russia


Post by SLKorolev » Sun May 18, 2008 3:36 pm

This is the right BAPI, but... unfotunately you have to copy all the material data programmaticaly (material number, quantity, etc.), it does not copy items from the PO automatically.
Best regards, Sergey Korolev

Posts: 135
Joined: Thu May 15, 2008 4:25 pm
Location: Butterball LLC., Goldsboro, NC, USA


Post by wilhitern1 » Mon May 19, 2008 9:44 am

In my code segment, you should see that I've done that. Am I missing a specific piece of item data that you were expecting?

My problem is not that the GR items are not being created. It is that the history is not being created on the PO. Without that component, the GR is unacceptable to the Functional folks.

Neal Wilhite
Senior Project Manager (ABAP Programming)
Butterball, LLC (MIS, Goldsboro, NC, USA)

Posts: 135
Joined: Thu May 15, 2008 4:25 pm
Location: Butterball LLC., Goldsboro, NC, USA


Post by wilhitern1 » Tue May 20, 2008 2:49 pm

I'm going to need serious drugs after this project is finished.

So, suddenly it starts working correctly. :shock: <But you had to change something for that to happen, right.> Well yes, but...
It was originally partially coded and therefore had to be run in two phases. First you ran the PO Create. Then you ran the GR Create. So, while I was waiting for inspiration or saving by you guys (and gals), I when ahead and connected the two pieces correctly so that they dovetailed correctly. Now, one pass and it works correctly.

I won't waste your time by reprinting the full code here. If anyone feels like talking further about it, we can talk off line. My email is
My personal theory (which I won't fully divulge for fear of the derision I might receive) is that it involves some vagueries(?sp) of 'BAPI_TRANSACTION_COMMIT'. All I can say is use it often.
Neal Wilhite (WilhiteRN1)Image

Post Reply