Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

PO creation using BAPI

Former Member
0 Kudos

Hi All,

I have a requirement that I need to create a Purchase Order using BAPI  by uploading excel file which contains PO header data and Item data.

while creating the PO , info record also need to be craeted. if the PO already have inforecord , then its should be updated.

Now i  tranfered the data from excel file to internal table by using the function module  TEXT_CONVERT_XLS_TO_SAP .This internal table now contain both PO header and multiple line item.

1. How to pass this internal table to BAPI " BAPI_PO_CREATE1 "   to create  PO ? (internal table contain mutiple line item ).

2. How to create info record ?  if any FM available for both creating and updating info record?

3. If the info record cant be created, then PO should not be created.. how to acheive this?

1 ACCEPTED SOLUTION

SimoneMilesi
Active Contributor
0 Kudos

Hi Ganesh


1. How to pass this internal table to BAPI " BAPI_PO_CREATE1 "   to create  PO ? (internal table

contain mutiple line item ).

Depending by relations between each record you should break for Purch organization/vendor and fill the corresponding structures of BAPI_PO_CREATE1


2. How to create info record ?  if any FM available for both creating and updating info record?

You can use FM ME_DIRECT_INPUT_INFORECORD

3. If the info record cant be created, then PO should not be created.. how to acheive this?

After calling the inforecord's creation, you can test if successfull or not and then process PO or not.

9 REPLIES 9

SimoneMilesi
Active Contributor
0 Kudos

Hi Ganesh


1. How to pass this internal table to BAPI " BAPI_PO_CREATE1 "   to create  PO ? (internal table

contain mutiple line item ).

Depending by relations between each record you should break for Purch organization/vendor and fill the corresponding structures of BAPI_PO_CREATE1


2. How to create info record ?  if any FM available for both creating and updating info record?

You can use FM ME_DIRECT_INPUT_INFORECORD

3. If the info record cant be created, then PO should not be created.. how to acheive this?

After calling the inforecord's creation, you can test if successfull or not and then process PO or not.

0 Kudos

Thanks for your reply,

I have another doubt that after the BAPI execution, the error or success details from the BAPI should be stored in  a file.

How to store this details as a sepereate file in the system ?

0 Kudos

Hi Ganesh,

The Bapi functiona module returns Return table which is having error and successful records information . i.e. mes type, msg variables...etc.

call format_mesage function module to get error messsage by passing above msg type, and msg variables.

collect all these in one internal table and call gui_download to download the file in local system.

or use open data set to download the file in al11.

Thanks & Regards,

Polu

0 Kudos

Hello,

You can create a new internal table with all the information you need and after the bapi fill it with the needed record on RETURN table.

THen, once processed all the input file, you can download your table

0 Kudos

Thanks again,

Is it possible to run this report program in background ? because a excel file need to be uploaded to execute the progam which is in the presentation server. So how to schedule this program to run in background?

Can we read file which is in desktop in background ?


0 Kudos

Hi Ganesh,

When executing in Background Mode, it is not possible to read from Presentation Server as the program is not aware of the foreground.

The ideal way would be to load the file to Application Server (AL11) and then in background execution mode, read the file from the Application Server and continue with execution.

Also, since it is a custom report, you can disable foreground execution mode (as it is a mass creation) and enable only background execution. This will ensure no time out issues also.

Regards,

George Abraham

0 Kudos

Hi George,

I am doing it in IDES as a training for me. I don't have a access to AL11. So is any other way to read this file from presentation server?

0 Kudos

Hi Ganesh,

In simple terms, to access a file in background job, it has to take it from some server - ideal would be Application Server. There is also a possibility of storing it on some FTP server also and accessing it.

The issue is that GUI_UPLOAD will not work when run in Background.

While researching through SCN, I had happened to stumble upon this document written by Former Member which mentions about an RFC approach - basically a PI connection - in which we create an RFC destination on the R/3 system to connect with the Front End when communicating through a background job.

I have not yet tested this approach, as we generally use the Application Server approach. However, you can give it a try and also mention if it works

http://scn.sap.com/docs/DOC-10362

Thanks and Regards,

George Abraham

raymond_giuseppi
Active Contributor
0 Kudos

To create Purchase Info Record you could try use FM IDOC_INPUT_INFREC or ME_DIRECT_INPUT_INFORECORD (after ME_INITIALIZE_INFORECORD) Either check success directly (exception like ERROR_MESSAGE) or thru call of BAPI_INFORECORD_GETLIST.

For the BAPI BAPI_PO_CREATE1, did you read its general documentation and the documentation of parameters POITEM[X]

Regards,

Raymond