Skip to Content
0

BAPI_PO_CREATE1 automatic outbound delivery Transfer Orders

May 25, 2017 at 09:42 AM

760

avatar image

Hi all,

i'm facing a strange behaviour using BAPI_PO_CREATE1 in order to create a Transfer Order and its Outbound delivery.


Scenario

We need to move some goods between two plants of ours so the receiving plant will create a Transfer Order towards the shipping one and two deliveries (Outbound from Shipping and Inbound in Receiving) close the flow.

We'll have an OData service doing the job, exposed towards an Angular App with UI5

Situation and Test
As first step, we tried the flow (obviously) via ME21N and we saw that when we create the Transfer Order, SAP (thanks the customizing) generate the outbound delivery automatically and we see it linked to the TO item

Manually we create the inbound deliver via VL10B and all works.

So i created a local report using the BAPI_PO_CREATE1 to generate the transfer order and the FM BBP_INB_DELIVERY_CREATE for the inbound delivery.

i run the report and.. surprise! Everything works correctly!

i made a copy and paste of the code and put it in my service and i find the issue.


The problem

When we call the service, the BAPI_PO_CREATE1 do not create the Outbound delivery automatically.

But the code is exactly the same of my local report!

To avoid any problem, i made a global wrapper function and put it in both my local report and my OData service and... the behaviour is still different:

  • Local report create the outbound delivery
  • OData service no

I tried to look for OSS Note but i did not find anything and, honestly, it's hard to find something without knowing the exact breaking points.

Any suggestion?

This is my code by the way (and yes, i managed the Commit/Rollback, the PO/TO is created!)

 data: poheader  type  bapimepoheader,
        poheaderx type  bapimepoheaderx,
        item      type  bapimepoitem,
        items      type table of  bapimepoitem,
        itemx     type  bapimepoitemx,
        itemsx    type table of bapimepoitemx,
        returns    type table of  bapiret2,
        extx type bapi_te_mepoitemx,
        ext type bapi_te_mepoitem,
        exin type bapiparex,
        exins type table of bapiparex,
        exppurchaseorder type  bapimepoheader-po_number,
        expheader type  bapimepoheader.

  select single t001k~bukrs t001w~ekorg into (poheader-comp_code, poheader-purch_org)  from t001w inner join t001k
on t001w~bwkey = t001k~bwkey
                where t001w~werks = p_dwerks.

  poheader-doc_type = 'UD'.
  poheader-suppl_plnt = p_werks.
  poheader-pur_group = poheader-comp_code(2).
  poheaderx-doc_type = poheaderx-pur_group =  poheaderx-comp_code = 
              poheaderx-suppl_plnt = poheaderx-purch_org = 'X'.
  item-po_item = 10.
  item-material = p_matnr.
  item-plant = p_dwerks.
  item-stge_loc = p_dlgort.
  item-quantity = p_qty.
  select single meins into item-po_unit from mara where matnr = p_matnr.
  item-item_cat = 'U'.
  item-conf_ctrl = '0004'.
  item-suppl_stloc = p_lgort.
  itemx-po_item = 10.
  itemx-material = itemx-plant = itemx-stge_loc = itemx-quantity = itemx-po_unit = itemx-item_cat = itemx-conf_ctrl =
    itemx-suppl_stloc = abap_true.
  append item to items.
  append itemx to itemsx.
  ext-po_item = extx-po_item = 10.
  ext-zzpl_piid = 'BULK'.
  extx-zzpl_piid = 'X'.
  exin-structure = 'BAPI_TE_MEPOITEM'.
  exin+30 = ext.
  append exin to exins.
  clear exin.
  exin-structure = 'BAPI_TE_MEPOITEMX'.
  exin+30 = extx.
  append exin to exins.

  call function 'BAPI_PO_CREATE1'
    exporting
      poheader          = poheader
      poheaderx         = poheaderx
     testrun           = ' '
    importing
     exppurchaseorder  = exppurchaseorder
      expheader         = expheader
    tables
      return            = returns
      poitem            = items
      poitemx           = itemsx
      extensionin       = exins.

Thanks all

Simone

ok.png (16.3 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

avatar image
Former Member May 26, 2017 at 08:15 AM
1

Dear Simone,

Please try running your local report in background mode... does it still work fine?

Kind regards,

Julian

Show 4 Share
10 |10000 characters needed characters left characters exceeded

Hi Julian!

I didn't try it and... well, the behaviour is the same like my OData service!

How do you guessed it?

0
Former Member

Then the BAPI you are using needs your GUI to be active (sy-batch ne 'X') in order to achieve the results you expect.

I suggest you to try a different bapi and as a very last resource you have our old friend BDC :S

Have a nice day!

Julian

0

Oh no, i found the workaround, manually calling the function responsible of the delivery creation /SPE/OUTBOUND_DELIVERY_CREATE after the BAPI.

I do not want to stick to old techs like BDC!

0
Former Member

Fantastic! Yes, I agree.

Glad to know it worked ;)

0
avatar image
Former Member May 26, 2017 at 11:51 AM
-1

Hi

I am confused with your description, As you mentioned that PO creation, what type of PO It is.

What process your are runing ?

I think you are creating STO through Bapi, then delivery is created automatically and transfer order is created one delivery is created so cehck WMTA output type and automatic delivery creation setting in IMG

But you mentioned VL10B for inbound delivery that will be outbound delivery right?

Regards

R

Show 1 Share
10 |10000 characters needed characters left characters exceeded

As i put in my question, i'm creating a Stock Transfer Order or Transfer Order (name as you want) which manually triggers the creation of outbound delivery (check my comments to Jurgen reply!).

With VL10B i create the inbound delivery as 2nd manual step.

The problem is the BAPI doesn't trigger (check my replies to Sandra and Julian) the specific function to create the outbound delivery when called into an OData Service.

All these steps are explained in the previous comments and answers.

0
Jürgen L May 25, 2017 at 11:14 AM
0

I understand your words but somehow what you explained from a normal business flow does not match with my experience (I am not yet talking about the BAPI, odata or other programming things).

ME21N creates a purchase order. It does not create an outbound delivery automatically

BAPI_PO_CREATE1 is used to create a purchase order too as a technical replacement for the ME21N user transaction, but even this BAPI does not create an outbound delivery.

So I wonder in general how your outbound delivery was created "automatically" . I could assume that there is a batch job scheduled, maybe even event triggered. But from alone is no outbound delivery created in SAP, just because someone entered PO.

Show 6 Share
10 |10000 characters needed characters left characters exceeded

Hi Jurgen.

i was sure the same, but no, i see no job or anything like that creating the outbound delivery (the one in my screenshot).

Talking with our MM consultants, they say it's automatically triggered via customizing.

Basically, i do not care what's behind the creation right now.

The main issue i found is the different behavour of the system when i use the same standard tool (the BAPI_PO_CREATE1).

0

I would be interested what customizing they mean.

0

i agree and it's what i asked indeed :)

0

Here we are!

As per an old discussion here you can follow these steps on customizing

and set it

So the question is.... why in the local report works and in the service it doesn't?!

:(

1.png (205.9 kB)
2.png (273.8 kB)
0

I have to admit that I see these entries the first time (._.);

had not yet much to with service parts management.

No, sorry, I have no idea to your issue then.

0

To add shame and confusion over and over, it happened to have succesfully managed it in a try via service again :\

1
Sandra Rossi May 25, 2017 at 03:23 PM
0

As you can test the two "programs" with an identical test data, maybe you can run an ABAP trace (SAT), compare the two traces (with the comparison tool in SAT), and you should get the same traces except at one point which should be where the problem is.

By the way, you should also test with the same user. I guess this is the only different thing (OData runs with a predefined user, and your program runs with your current user).

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Hi Sandra,

Thanks for the answer!

To avoid any possible difference, i put fix values in both the local program and in my Odata service and assigned my user to the Odata service too, so the only difference is the that one runs on sapgui and the other via service/gateway.

Maybe i found the "critical point": checking OSS Note 1069448 (not applicable to my system), i found out the function responsible of the delivery creation /SPE/OUTBOUND_DELIVERY_CREATE

It seems not being triggered by the service but i do not know why :\

1