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: 

doubts in BApi_po_create1 ?

Former Member
0 Kudos
1,242

Hi team I am going to create a purchase order using BApi_po_create1 , since this the first time i am working with

bapi i have few doubts about the this bapi.......in this bapi what is the use of

BAPIMEPOHEADERX

BAPIMEPOITEMX

BAPIMEPOACCOUNTX

BAPIMEPOHEADER-PO_NUMBER

and once this BAPI_TRANSACTION_COMMIT is executed purchase order will be created or will it be on hold and can

anyone give some tips or hints on working with bapi ?

thanks in advance,

siva.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
176

Those structures and tables are for change paramaters. For creating the PO u pass the values in the structures for example POHEADER and for the same parameters passed in POHEADER u need to pass 'X' in POHEADERX structure. only then PO wil be created.

PO will be created before commit but it will be saved in the respective tables only when it is committed.

Regards,

Asif Ali Khan

7 REPLIES 7

bpawanchand
Active Contributor
0 Kudos
176

Hi

Check the below links

[Documentation About BAPI|http://abap.wikiprog.com/wiki/BAPI_PO_CREATE1]

[Input Parameters|]

Regards

Pavan

Former Member
0 Kudos
177

Those structures and tables are for change paramaters. For creating the PO u pass the values in the structures for example POHEADER and for the same parameters passed in POHEADER u need to pass 'X' in POHEADERX structure. only then PO wil be created.

PO will be created before commit but it will be saved in the respective tables only when it is committed.

Regards,

Asif Ali Khan

0 Kudos
176

Hai Asif,

I have executed this bapi but i am getting the following error :

No instance of object type PurchaseOrder has been created. External reference:

Purchase order still contains faulty items

Please enter material number or account assignment category

can u tel me what is the mistake in my bapi ? the material number is getting qppended in the internal table ?

0 Kudos
176

Hi Siva,

Eventhough u r passing the material number from the internal table to the BAPI structures, since the material number size is of 18 chars, u need to pass the material number by leading zeroes added with the material number. You can do this by passing ur material to FM CONVERSION_EXIT_ALPHA_INPUT and then pass the output value to the structure.

Regards,

Asif Ali Khan

Former Member
0 Kudos
176

&----


*& Report ZMM_PO_CREATE

*&

&----


*&

*&

&----


REPORT ZMM_PO_CREATE.

TYPE-POOLS : slis.

DATA : wa_fldcat TYPE slis_t_fieldcat_alv,

fldcat TYPE slis_fieldcat_alv,

wa_layout TYPE slis_layout_alv.

DATA : H_FILE TYPE string,

I_FILE TYPE STRING,

C_FILE TYPE STRING.

DATA : I_HEADER LIKE BAPIMEPOHEADER,

I_HEADERX LIKE BAPIMEPOHEADERX,

I_ITEM LIKE STANDARD TABLE OF BAPIMEPOITEM WITH HEADER LINE,

I_ITEMX LIKE STANDARD TABLE OF BAPIMEPOITEMX WITH HEADER LINE,

I_SCHED LIKE STANDARD TABLE OF BAPIMEPOSCHEDULE WITH HEADER LINE,

I_SCHEDX LIKE STANDARD TABLE OF BAPIMEPOSCHEDULX WITH HEADER LINE,

I_COND LIKE STANDARD TABLE OF BAPIMEPOCOND WITH HEADER LINE,

I_CONDX LIKE STANDARD TABLE OF BAPIMEPOCONDX WITH HEADER LINE,

I_RETURN LIKE STANDARD TABLE OF BAPIRET2 WITH HEADER LINE,

I_DISPLAY LIKE STANDARD TABLE OF BAPIRET2 WITH HEADER LINE,

zretcommit TYPE TABLE OF bapiret2 WITH HEADER LINE.

DATA : BEGIN OF I_FINAL OCCURS 0,

EBELN LIKE EKKO-EBELN,

MTYPE LIKE BAPIRET2-TYPE,

MESGE LIKE BAPIRET2-MESSAGE,

END OF I_FINAL.

DATA : BEGIN OF HDATA OCCURS 0,

EBELN LIKE EKKO-EBELN,

LIFNR LIKE EKKO-LIFNR,

EKORG LIKE EKKO-EKORG,

EKGRP LIKE EKKO-EKGRP,

ZTERM LIKE EKKO-ZTERM,

INCO1 LIKE EKKO-INCO1,

INCO2 LIKE EKKO-INCO2,

END OF HDATA.

DATA: BEGIN OF IDATA OCCURS 100 ,

EBELN LIKE EKKO-EBELN, " PO number

EBELP LIKE EKPO-EBELP,

WERKS LIKE EKPO-WERKS, " Plant

LGORT LIKE EKPO-LGORT, " Storage Loc

MATNR LIKE EKPO-MATNR, " Material

MENGE LIKE BAPIMEPOITEM-QUANTITY, " Quantity

NETPR LIKE BAPIMEPOITEM-NET_PRICE, "net Price

  • PEINH LIKE EKPO-PEINH, " Price per

DELIVERY_DATE LIKE BAPIMEPOSCHEDULE-DELIVERY_DATE,

MWSKZ LIKE EKPO-MWSKZ, "TaxCode

END OF IDATA.

DATA : BEGIN OF CDATA OCCURS 0,

EBELN LIKE EKKO-EBELN,

EBELP LIKE EKPO-EBELP,

KSCHL LIKE KONV-KSCHL,

KBETR LIKE KONV-KBETR,

END OF CDATA.

selection-screen begin of block b1 with frame title text-t01.

parameters : P_HEAD like IBIPPARMS-PATH obligatory,

P_ITEM LIKE IBIPPARMS-PATH obligatory,

P_COND LIKE IBIPPARMS-PATH obligatory.

selection-screen end of block b1.

*&& At Selection Event is Called

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_HEAD.

*&& This Function Module will take the filename from

CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = syst-cprog

dynpro_number = syst-dynnr

field_name = 'P_HEAD'

IMPORTING

file_name = p_HEAD.

*&& At Selection Event is Called

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_ITEM.

*&& This Function Module will take the filename from

CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = syst-cprog

dynpro_number = syst-dynnr

field_name = 'P_ITEM'

IMPORTING

file_name = p_ITEM.

*&& At Selection Event is Called

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_COND.

*&& This Function Module will take the filename from

CALL FUNCTION 'F4_FILENAME'

EXPORTING

program_name = syst-cprog

dynpro_number = syst-dynnr

field_name = 'P_COND'

IMPORTING

file_name = p_COND.

*&& At selection-screen event is called

AT SELECTION-SCREEN.

IF p_HEAD IS INITIAL.

MESSAGE 'Enter the File Name' TYPE 'E'.

ENDIF.

IF p_ITEM IS INITIAL.

MESSAGE 'Enter the File Name' TYPE 'E'.

ENDIF.

IF p_COND IS INITIAL.

MESSAGE 'Enter the File Name' TYPE 'E'.

ENDIF.

START-OF-SELECTION.

H_FILE = P_HEAD.

I_FILE = P_ITEM.

C_FILE = P_COND.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = H_FILE

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

tables

data_tab = HDATA

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17.

IF sy-subrc <> 0.

MESSAGE 'Error Occured while Uploading Header Data File' TYPE 'E'.

ENDIF.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = I_FILE

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

tables

data_tab = IDATA

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17.

IF sy-subrc <> 0.

MESSAGE 'Error Occured while Uploading Item Data File' TYPE 'E'.

ENDIF.

CALL FUNCTION 'GUI_UPLOAD'

EXPORTING

filename = C_FILE

FILETYPE = 'ASC'

HAS_FIELD_SEPARATOR = 'X'

tables

data_tab = CDATA

EXCEPTIONS

FILE_OPEN_ERROR = 1

FILE_READ_ERROR = 2

NO_BATCH = 3

GUI_REFUSE_FILETRANSFER = 4

INVALID_TYPE = 5

NO_AUTHORITY = 6

UNKNOWN_ERROR = 7

BAD_DATA_FORMAT = 8

HEADER_NOT_ALLOWED = 9

SEPARATOR_NOT_ALLOWED = 10

HEADER_TOO_LONG = 11

UNKNOWN_DP_ERROR = 12

ACCESS_DENIED = 13

DP_OUT_OF_MEMORY = 14

DISK_FULL = 15

DP_TIMEOUT = 16

OTHERS = 17.

IF sy-subrc <> 0.

MESSAGE 'Error Occured while Uploading Conditon File' TYPE 'E'.

ENDIF.

LOOP AT HDATA.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = HDATA-EBELN

IMPORTING

output = I_HEADER-PO_NUMBER.

I_HEADER-COMP_CODE = '1000'.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = 'ZUP'

IMPORTING

output = I_HEADER-DOC_TYPE.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = HDATA-LIFNR

IMPORTING

output = I_HEADER-VENDOR.

I_HEADER-PMNTTRMS = HDATA-ZTERM.

I_HEADER-PURCH_ORG = '1000'.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = HDATA-EKGRP

IMPORTING

output = I_HEADER-PUR_GROUP.

I_HEADER-INCOTERMS1 = HDATA-INCO1.

I_HEADER-INCOTERMS2 = HDATA-INCO2.

I_HEADERX-PO_NUMBER = 'X'.

I_HEADERX-COMP_CODE = 'X'.

I_HEADERX-DOC_TYPE = 'X'.

I_HEADERX-PMNTTRMS = 'X'.

I_HEADERX-VENDOR = 'X'.

I_HEADERX-PURCH_ORG = 'X'.

I_HEADERX-PUR_GROUP = 'X'.

I_HEADER-INCOTERMS1 = 'X'.

I_HEADER-INCOTERMS2 = 'X'.

LOOP AT IDATA WHERE EBELN = HDATA-EBELN.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = IDATA-EBELP

IMPORTING

output = I_ITEM-PO_ITEM.

*I_ITEM-PO_ITEM = IDATA-EBELP.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = IDATA-MATNR

IMPORTING

output = I_ITEM-MATERIAL.

I_ITEM-PLANT = IDATA-WERKS.

I_ITEM-QUANTITY = IDATA-MENGE.

I_ITEM-NET_PRICE = IDATA-NETPR.

I_ITEM-INFO_UPD = ''.

I_ITEM-TAX_CODE = IDATA-MWSKZ.

APPEND I_ITEM.

*& ITEM X DATA.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = IDATA-EBELP

IMPORTING

output = I_ITEMX-PO_ITEM.

I_ITEMX-MATERIAL = 'X'.

I_ITEMX-PLANT = 'X'.

I_ITEMX-QUANTITY = 'X'.

I_ITEMX-NET_PRICE = 'X'.

I_ITEMX-TAX_CODE = 'X'.

I_ITEMX-INFO_UPD = 'X'.

APPEND I_ITEMX.

*& SCHDULE

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = IDATA-EBELP

IMPORTING

output = I_SCHED-PO_ITEM.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = IDATA-EBELP

IMPORTING

output = I_SCHED-SCHED_LINE.

I_SCHED-DELIVERY_DATE = IDATA-DELIVERY_DATE.

I_SCHED-QUANTITY = IDATA-MENGE.

APPEND I_SCHED.

*& SCHDULEX

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = IDATA-EBELP

IMPORTING

output = I_SCHEDX-PO_ITEM.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = IDATA-EBELP

IMPORTING

output = I_SCHEDX-SCHED_LINE.

I_SCHEDX-DELIVERY_DATE = 'X'.

I_SCHEDX-QUANTITY = 'X'.

APPEND I_SCHEDX.

ENDLOOP.

*BREAK-POINT.

LOOP AT CDATA WHERE EBELN = HDATA-EBELN.

*& Conditions

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = CDATA-EBELP

IMPORTING

output = I_COND-ITM_NUMBER.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = CDATA-EBELP

IMPORTING

output = I_COND-COND_ST_NO.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = CDATA-KSCHL

IMPORTING

output = I_COND-COND_TYPE.

I_COND-COND_VALUE = CDATA-KBETR.

I_COND-CHANGE_ID = 'I'.

I_COND-CURRENCY = 'INR'.

APPEND I_COND.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = CDATA-EBELP

IMPORTING

output = I_CONDX-ITM_NUMBER.

I_CONDX-COND_ST_NO = '000'.

I_CONDX-ITM_NUMBERX = 'X'.

I_CONDX-COND_TYPE = 'X'.

I_CONDX-COND_VALUE = 'X'.

I_COND-CHANGE_ID = 'X'.

I_CONDX-CURRENCY = 'X'.

APPEND I_CONDX.

ENDLOOP.

CLEAR I_SCHED.

CLEAR I_SCHEDX.

CLEAR I_COND.

CLEAR I_CONDX.

CALL FUNCTION 'BAPI_PO_CREATE1'

EXPORTING

poheader = I_HEADER

POHEADERX = I_HEADERX

  • POADDRVENDOR =

  • TESTRUN =

  • MEMORY_UNCOMPLETE =

  • MEMORY_COMPLETE =

  • POEXPIMPHEADER =

  • POEXPIMPHEADERX =

  • VERSIONS =

  • NO_MESSAGING =

  • NO_MESSAGE_REQ =

  • NO_AUTHORITY =

  • NO_PRICE_FROM_PO =

  • IMPORTING

  • EXPPURCHASEORDER =

  • EXPHEADER =

  • EXPPOEXPIMPHEADER =

TABLES

RETURN = I_RETURN

POITEM = I_ITEM

POITEMX = I_ITEMX

  • POADDRDELIVERY =

POSCHEDULE = I_SCHED

POSCHEDULEX = I_SCHEDX

  • POACCOUNT =

  • POACCOUNTPROFITSEGMENT =

  • POACCOUNTX =

  • POCONDHEADER =

  • POCONDHEADERX =

POCOND = I_COND

POCONDX = I_CONDX

  • POLIMITS =

  • POCONTRACTLIMITS =

  • POSERVICES =

  • POSRVACCESSVALUES =

  • POSERVICESTEXT =

  • EXTENSIONIN =

  • EXTENSIONOUT =

  • POEXPIMPITEM =

  • POEXPIMPITEMX =

  • POTEXTHEADER =

  • POTEXTITEM =

  • ALLVERSIONS =

  • POPARTNER =

.

*BREAK-POINT.

CLEAR I_RETURN.

LOOP AT I_RETURN WHERE TYPE = 'E'.

I_FINAL-EBELN = I_HEADER-PO_NUMBER.

I_FINAL-MTYPE = I_RETURN-TYPE.

CONCATENATE I_FINAL-MESGE I_RETURN-MESSAGE

INTO I_FINAL-MESGE.

APPEND I_FINAL.

CLEAR I_FINAL.

ENDLOOP.

LOOP AT I_RETURN WHERE TYPE = 'S'.

I_FINAL-EBELN = I_HEADER-PO_NUMBER.

I_FINAL-MTYPE = I_RETURN-TYPE.

CONCATENATE I_FINAL-MESGE I_RETURN-MESSAGE

INTO I_FINAL-MESGE.

APPEND I_FINAL.

CLEAR I_FINAL.

ENDLOOP.

*READ TABLE I_RETURN WITH KEY TYPE = 'E'.

  • IF SY-SUBRC = 0.

  • READ TABLE I_RETURN INDEX 3.

  • I_FINAL-EBELN = I_HEADER-PO_NUMBER.

  • I_FINAL-MTYPE = I_RETURN-TYPE.

  • I_FINAL-MESGE = I_RETURN-MESSAGE.

  • APPEND I_FINAL.

  • CLEAR I_FINAL.

  • ENDIF.

*READ TABLE I_RETURN WITH KEY TYPE = 'S'.

  • IF SY-SUBRC = 0.

  • READ TABLE I_RETURN INDEX 1.

  • I_FINAL-EBELN = I_HEADER-PO_NUMBER.

  • I_FINAL-MTYPE = I_RETURN-TYPE.

  • I_FINAL-MESGE = I_RETURN-MESSAGE.

  • APPEND I_FINAL.

  • CLEAR I_FINAL.

  • ENDIF.

CLEAR I_HEADER.

CLEAR I_HEADERX.

CLEAR I_ITEM.

CLEAR I_ITEMX.

REFRESH I_ITEM.

REFRESH I_ITEMX.

CLEAR I_COND.

CLEAR I_CONDX.

REFRESH I_COND.

REFRESH I_CONDX.

CLEAR I_SCHED.

CLEAR I_SCHEDX.

REFRESH I_SCHED.

REFRESH I_SCHEDX.

REFRESH I_RETURN.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

WAIT = 'X'

IMPORTING

RETURN = zretcommit.

ENDLOOP.

DATA : wa_sort TYPE slis_sortinfo_alv,

it_sort TYPE slis_t_sortinfo_alv.

CLEAR wa_sort.

wa_sort-fieldname = 'EBELN'.

wa_sort-spos = 1.

wa_sort-up = 'X'.

wa_sort-group = '*'.

APPEND wa_sort TO it_sort.

  • Prepare the Field Catalog

CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'

EXPORTING

i_program_name = sy-repid

i_internal_tabname = 'I_FINAL'

i_inclname = 'ZMM_PO_CREATE'

CHANGING

ct_fieldcat = wa_fldcat

EXCEPTIONS

inconsistent_interface = 1

program_error = 2

OTHERS = 3.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

LOOP AT wa_fldcat INTO fldcat.

fldcat-key = ' '.

CASE fldcat-fieldname.

WHEN 'EBELN'.

fldcat-seltext_l = 'P.O NUMBER'.

fldcat-seltext_m = 'P.O NUMBER'.

fldcat-seltext_s = 'P.O NUMBER'.

fldcat-reptext_ddic = 'P.O NUMBER'.

fldcat-outputlen = 13.

WHEN 'MTYPE'.

fldcat-seltext_l = 'MESSAGE TYPE'.

fldcat-seltext_m = 'MESSAGE TYPE'.

fldcat-seltext_s = 'MESSAGE TYPE'.

fldcat-reptext_ddic = 'MESSAGE TYPE'.

fldcat-outputlen = 25.

WHEN 'MESGE'.

fldcat-seltext_l = 'MESSAGE'.

fldcat-seltext_m = 'MESSAGE'.

fldcat-seltext_s = 'MESSAGE'.

fldcat-reptext_ddic = 'MESSAGE'.

fldcat-outputlen = 35.

ENDCASE.

MODIFY wa_fldcat FROM fldcat.

ENDLOOP.

    • Display the Output according to field catalog

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = 'ZMM_PO_CREATE'

I_CALLBACK_TOP_OF_PAGE = 'TOP-OF-PAGE'

IS_LAYOUT = wa_layout

IT_FIELDCAT = wa_fldcat

IT_SORT = IT_SORT

I_DEFAULT = 'X'

I_SAVE = 'X'

TABLES

t_outtab = I_FINAL

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2.

IF sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

----


  • Form TOP-OF-PAGE *

----


  • ALV Report Header *

----


FORM top-of-page.

*ALV Header declarations

DATA: t_header TYPE slis_t_listheader,

wa_header TYPE slis_listheader,

t_line LIKE wa_header-info,

ld_lines TYPE i,

ld_linesc(10) TYPE c.

  • Title

wa_header-typ = 'H'.

wa_header-info = 'HINDUSTAN SANITARYWARE & INDUSTRIES LIMITED'.

APPEND wa_header TO t_header.

CLEAR wa_header.

  • Date

wa_header-typ = 'S'.

wa_header-key = 'PO UPLOAD LIST'.

APPEND wa_header TO t_header.

CLEAR: wa_header.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = t_header.

  • i_logo = 'Z_LOGO'.

ENDFORM. "top-of-page

Former Member
0 Kudos
176

REPORT ZR_ALM_MM_PUR_REQ_CONV_PUR_OR no standard page heading

line-size 25

line-count 200.

******************************************************

  • Program Name : ZR_ALM_MM_PUR_REQ_CONV_PUR_OR *

  • Author : Santosh Kumar M *

  • Date of Creation : 08 JUL 2008 *

  • Request No. : R3DK900579 R3DK900589 R3DK900595*

  • R3DK900605 R3DK900611 R3DK900615*

  • R3DK900619 R3DK900621 *

  • Description : This program allows the upload *

  • of Purchase orders based on *

  • the existing purchase requisi- *

  • tions and uploading the same. *

******************************************************

*!-- Global Declarations

type-pools: slis.

*!-- Tables Definition

tables: eban, " Purchase Requisition

ebkn, " Purch Req Account Assignment

ekpo, " Purchasing Document Item

ekko. " Purchasing Document Header

*!-- Structure for Purchase Requisition Details

*submit

types: begin of ty_eban,

BANFN type eban-banfn, " Purchase Requisition No

BNFPO type eban-bnfpo, " Item number of purchase Req

BSART type eban-bsart, " Purch Req Doc type

BSTYP type eban-bstyp, " Purchasing document category

BSAKZ type eban-bsakz, " Control indicator for purchdoc

LOEKZ type eban-loekz, " Deletion indicator of purchdoc

frgkz type eban-frgkz, " Release Indicator

EKGRP type eban-ekgrp, " Purchasing Group

ERNAM type eban-ernam, " Creator of Purch doc

ERDAT type eban-erdat, " Creation Date

txz01 type eban-txz01, " Short text

matnr type eban-matnr, " Material No

WERKS type eban-werks, " Plant

LGORT type eban-lgort, " Storage Location

MATKL type eban-matkl, " Material Group

RESWK type eban-reswk, " Supplying Plant

MENGE type eban-menge, " Puchase Req QTY

MEINS type eban-meins, " UOM

lfdat type eban-lfdat, " Item Delivery Date

PSTYP type eban-pstyp, " Item Category in Puch doc

KNTTP type eban-knttp, " Account assignment category

lifnr type eban-lifnr, " Vendor

flief type eban-flief, " Fixed Vendor

ekorg type eban-ekorg, " Purchase Organization

bsmng type eban-bsmng, " Orderer Quantity

attyp type eban-attyp, " Material Category

bukrs type t001-bukrs, " Company Code

end of ty_eban.

DATA l_t_pritem LIKE BAPIEBAND OCCURS 0 WITH HEADER LINE.

DATA l_t_return LIKE BAPIRETURN OCCURS 0 WITH HEADER LINE.

DATA: BEGIN OF mTAB OCCURS 0,

banfn like eban-banfn,

END OF mTAB.

data : Preq(10) type c, mode type c,

line(5) type c, lno type n,

ans type c.

data lv_menge type mseg-menge.

data gt_eban2 type table of eban with header line.

types: begin of ty_str,

  • matnr type ekpo-matnr,

menge type ekpo-menge,

banfn type ekpo-banfn,

bnfpo type ekpo-bnfpo,

end of ty_str.

data: ty_str type ty_str.

*types: begin of ty_eban1,

  • bsart type eban-bsart,

  • ekgrp type eban-ekgrp,

    • ernam type eban-ernam,

    • erdat type eban-erdat,

  • matnr type eban-matnr,

  • werks type eban-werks,

    • lgort type eban-lgort,

  • menge type eban-menge,

  • meins type eban-meins,

  • lfdat type eban-lfdat,

  • pstyp type eban-pstyp,

  • flief type eban-flief,

  • ekorg type eban-ekorg,

  • bukrs type t001-bukrs,

  • end of ty_eban1.

*!-- Structure for Purchase Requision- Cost Center Data.

types: begin of ty_ebkn,

banfn type ebkn-banfn,

bnfpo type ebkn-bnfpo,

kostl type ebkn-kostl,

sakto type ebkn-sakto,

aufnr type ebkn-aufnr,

end of ty_ebkn.

*!-- Output Structure for Displaying ALV Output with Messages.

types: begin of ty_out,

ICON(4) TYPE C,

flief type eban-flief,

ekgrp type eban-ekgrp,

bukrs type t001-bukrs,

werks type eban-werks,

ebeln type eban-ebeln,

message type BAPI_MSG,

line_color(4) type c,

end of ty_out.

DATA: BEGIN OF ITAB OCCURS 0,

banfn like eban-banfn,

bnfpo like eban-bnfpo,

ebakz like eban-ebakz,

pstyp like eban-pstyp,

matnr like eban-matnr,

menge like eban-menge,

bsmng like eban-bsmng,

mtart like mara-mtart,

lnno type n,

END OF ITAB.

*!-- internal table to store all sto/po.

*DATA: BEGIN OF mTAB OCCURS 0,

  • banfn like eban-banfn,

  • END OF mTAB.

*data : Preq(10) type c, mode type c,

  • line(5) type c, lno type n,

  • ans type c.

*!-- Internal Table Declarations.

data: gt_eban type table of ty_eban with header line,

  • gt_eban type table of ty_eban1 with header line,

gt_out type table of ty_out,

gt_eban1 type table of ty_eban with header line,

gt_ebkn type table of ty_ebkn.

*!-- Internal Table Declarations maintained for ALV Display

DATA : it_fieldcat TYPE slis_t_fieldcat_alv,

it_listheader TYPE slis_t_listheader,

it_alvevent TYPE slis_t_event,

gt_events TYPE slis_t_event WITH HEADER LINE.

*!-- Work Area Declaration for ALV Display

DATA : wa_fieldcat TYPE slis_fieldcat_alv,

wa_listheader TYPE slis_listheader,

WA_OUT TYPE TY_OUT,

wa_eban type ty_eban,

  • wa_eban2 type ty_eban,

wa_ebkn type ty_ebkn,

wa_alvevent TYPE slis_alv_event.

*!-- Internal Table Declarations for BAPI's

data: begin of header occurs 0,

indx type i value 0.

include structure BAPIMEPOHEADER.

data end of header.

data: begin of headerx occurs 0,

indx type i value 0.

include structure BAPIMEPOHEADERX.

data end of headerx.

data: begin of poitems occurs 0,

indx type i.

include structure BAPIMEPOITEM.

data end of poitems.

data: begin of poitemsx occurs 0,

indx type i.

include structure BAPIMEPOITEMx.

data end of poitemsx.

data: begin of scd occurs 0,

indx type i.

include structure BAPIMEPOSCHEDULE.

data end of scd.

data: begin of scdx occurs 0,

indx type i.

include structure BAPIMEPOSCHEDULX.

data end of scdx.

data: begin of account occurs 0,

indx type i.

include structure BAPIMEPOACCOUNT.

data end of account.

data: begin of accountx occurs 0,

indx type i.

include structure BAPIMEPOACCOUNTx.

data end of accountx.

DATA : header1 LIKE BAPIMEPOHEADER OCCURS 0 WITH HEADER LINE,

header1x like bapimepoheaderx occurs 0 with header line,

poitems1 LIKE BAPIMEPOITEM OCCURS 0 WITH HEADER LINE,

poitems1x LIKE BAPIMEPOITEMx OCCURS 0 WITH HEADER LINE,

scd1 LIKE BAPIMEPOSCHEDULE OCCURS 0 WITH HEADER LINE,

scd1x LIKE BAPIMEPOSCHEDULX OCCURS 0 WITH HEADER LINE,

RETURN LIKE BAPIRETURN OCCURS 0 WITH HEADER LINE,

RETURN1 LIKE BAPIRETURN OCCURS 0 WITH HEADER LINE,

bdcitab LIKE bdcdata OCCURS 0 WITH HEADER LINE,

message LIKE bapiret2 OCCURS 0 WITH HEADER LINE,

account1x LIKE BAPIMEPOACCOUNTx OCCURS 0 WITH HEADER LINE,

account1 LIKE BAPIMEPOACCOUNT OCCURS 0 WITH HEADER LINE.

*!-- General Vars Declaration.

data gv_pono like BAPIMEPOHEADER-PO_NUMBER.

DATA : value TYPE i VALUE 10,

value1 type i value 1.

DATA: ls_line TYPE slis_listheader.

data: ld_color(1) type c.

DATA : g_repid LIKE sy-repid, " Program ID

g_layout TYPE slis_layout_alv. " Layout Workarea

*!-- Macro Definition for ALV Field Catalog

DEFINE m_fieldcat.

wa_fieldcat-col_pos = &1. " Fieldcat column

wa_fieldcat-icon = &2.

wa_fieldcat-fieldname = &3. " Field name

wa_fieldcat-seltext_m = &4. " Column Text

wa_fieldcat-outputlen = &5.

WA_FIELDCAT-HOTSPOT = &6.

append wa_fieldcat to it_fieldcat.

clear wa_fieldcat.

END-OF-DEFINITION.

*!-- Selection Screen for Inputting the required Purch Req Details

selection-screen begin of block b1 with frame title text-001.

selection-screen skip.

select-options: s_ekgrp for eban-ekgrp, " Purchase Group

s_ekorg for eban-ekorg, " Purchase organization

s_lifnr for eban-flief, " Vendor

s_konnr for eban-konnr, " Contract

s_werks for eban-werks, " Plant

s_matkl for eban-matkl, " Material Group

s_dispo for eban-dispo, " Materials Planner

s_banfn for eban-BANFN, " Purchase Requision

s_matnr for eban-matnr, " Material

s_bednr for eban-bednr, " Reqt Tracking No

s_bsart for eban-bsart, " Document Type

s_pstyp for eban-pstyp, " Item Category

s_KNTTP for eban-KNTTP, " Acc Assignment Group

s_statu for eban-statu, " Processing Status

s_afnam for eban-afnam, " Requisitioner

s_kostl for ebkn-kostl, " Cost Center

S_BADAT FOR EBAN-BADAT. " Requisition Date

selection-screen skip.

selection-screen end of block b1.

SELECTION-SCREEN SKIP 1.

START-OF-SELECTION.

*!-- Subroutines for Populating/Processing Internal Tables

PERFORM sub_fetch_data.

PERFORM sub_process_data.

PERFORM sub_po_bapi.

END-OF-SELECTION.

*!-- Subroutines for ALV Output

PERFORM sub_build_fieldcat.

PERFORM sub_build_layout.

PERFORM eventtab_build USING gt_events[].

PERFORM comment_build USING it_listheader[].

PERFORM sub_disp_data.

&----


*& Form SUB_BUILD_FIELDCAT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM sub_build_fieldcat .

*!-- Populating the Field Catalog data.

m_fieldcat 1 'X' 'ICON' text-004 4 ''.

m_fieldcat 2 '' 'FLIEF' text-014 10 ''. " VENDOR

m_fieldcat 3 '' 'EKGRP' text-010 4 ''. " PURCHASE GROUP

m_fieldcat 4 '' 'BUKRS' text-011 4 ''. " COMPANY CODE

m_fieldcat 5 '' 'WERKS' text-012 4 ''. " PLANT

m_fieldcat 6 '' 'EBELN' text-006 10 'X'.

m_fiEldcat 7 '' 'MESSAGE' text-008 225 ''.

ENDFORM. " SUB_BUILD_FIELDCAT

&----


*& Form SUB_BUILD_LAYOUT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM sub_build_layout .

*!-- Populating the Layout Structure data

g_layout-zebra = 'X'.

g_layout-colwidth_optimize = 'X'.

g_layout-info_fieldname = 'LINE_COLOR'.

ENDFORM. " SUB_BUILD_LAYOUT

&----


*& Form EVENTTAB_BUILD

&----


  • text

----


  • -->P_GT_EVENTS[] text

----


FORM eventtab_build USING gt_events TYPE slis_t_event.

DATA: ls_event TYPE slis_alv_event.

*!-- Populating the ALV Events Internal table.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = gt_events.

*!-- Reading the Top of Page event

READ TABLE gt_events WITH KEY name = slis_ev_top_of_page

INTO ls_event.

IF sy-subrc = 0.

MOVE 'TOP_OF_PAGE' TO ls_event-form.

APPEND ls_event TO gt_events.

ENDIF.

ENDFORM. " EVENTTAB_BUILD

&----


*& Form COMMENT_BUILD

&----


  • text

----


  • -->P_IT_LISTHEADER[] text

----


FORM comment_build USING p_it_listheader TYPE

slis_t_listheader.

*!-- Populating the List header for Header Information

ls_line-typ = 'H'.

ls_line-info = text-116.

APPEND ls_line TO p_it_listheader.

ls_line-typ = 'S'.

  • ls_line-key = text-090.

    • ls_line-info = v_text.

  • APPEND ls_line TO p_it_listheader.

ENDFORM. " COMMENT_BUILD

&----


*& Form TOP_OF_PAGE

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM top_of_page.

*!-- Function module for Displaying Top of Page

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

it_list_commentary = it_listheader.

ENDFORM. " TOP_OF_PAGE

&----


*& Form SUB_DISP_DATA

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM sub_disp_data .

g_repid = sy-repid.

*!-- Function Module for Displaying ALV Output

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

i_callback_program = g_repid

i_callback_user_command = 'HANDLE_USER_COMMAND'

it_fieldcat = it_fieldcat[]

is_layout = g_layout

i_save = 'U'

it_events = gt_events[]

  • IT_SORT = I_SORT[]

TABLES

t_outtab = gt_OUT[].

ENDFORM. " SUB_DISP_DATA

----


  • FORM HANDLE_USER_COMMAND *

----


  • ........ *

----


  • --> R_UCOMM *

  • --> RS_SELFIELD *

----


form HANDLE_USER_COMMAND using r_ucomm like sy-ucomm

rs_selfield type slis_selfield.

case r_ucomm.

when '&IC1'.

case rs_selfield-FIELDNAME.

when 'EBELN'.

set parameter id 'BES' field rs_selfield-value.

call transaction 'ME23N'.

endcase.

endcase.

endform.

.

&----


*& Form sub_fetch_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM sub_fetch_data.

select BANFN

BNFPO

BSART

BSTYP

BSAKZ

LOEKZ

frgkz

EKGRP

ERNAM

ERDAT

txz01

matnr

WERKS

LGORT

MATKL

RESWK

MENGE

MEINS

lfdat

PSTYP

KNTTP

lifnr

flief

ekorg

bsmng

attyp

from eban

into corresponding fields of table gt_eban

where ekgrp in s_ekgrp

and ekorg in s_ekorg

and lifnr in s_lifnr

and konnr in s_konnr

and werks in s_werks

and matkl in s_matkl

and dispo in s_dispo

and banfn in s_banfn

and matnr in s_matnr

and bednr in s_bednr

and bsart in s_bsart

and pstyp in s_pstyp

and pstyp <> '9'

and knttp in s_KNTTP

and statu in s_statu

and afnam in s_afnam

and badat in s_badat

and flief in s_lifnr

and flief <> space

and frgkz = 2

and ( ( statu ne 'B' and loekz EQ '' )

or ( statu eq 'B' and loekz eq '' ) ).

if sy-subrc = 0.

loop at gt_eban.

if gt_eban-menge <> gt_eban-bsmng.

gt_eban1 = gt_eban.

append gt_eban1.

endif.

endloop.

*!-- Select Statement for fetching the appropriate Cost center

select banfn

bnfpo

kostl

sakto

aufnr

from ebkn

into table gt_ebkn

for all entries in gt_eban1

where banfn = gt_eban1-banfn

and bnfpo = gt_eban1-bnfpo.

endif.

ENDFORM. " sub_fetch_data

&----


*& Form sub_process_data

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM sub_process_data.

data: lv_banfn type eban-banfn,

v_flag1 type c.

sort gt_eban1 by banfn.

*sort gt_ebkn by banfn.

*!-- Code for Populating Order type, Company code data.

loop at gt_eban1 into wa_eban.

*read table gt_eban1 with key banfn = wa_eban-banfn

  • binary search.

if wa_eban-werks = '8501'.

wa_eban-bsart = 'ZWP'.

wa_eban-bukrs = '8500'.

else.

if wa_eban-werks = '8601'.

wa_eban-bsart = 'ZIP'.

wa_eban-bukrs = '8600'.

endif.

endif.

wa_eban-ekorg = '1000'.

modify gt_eban1 from wa_eban transporting bsart EKORG bukrs.

endloop.

sort gt_eban1 by ekgrp werks flief bukrs.

loop at gt_eban1 into wa_eban.

*!-- Code for Populating the BAPI structures and Item data.

read table gt_ebkn into wa_ebkn with key banfn = wa_eban-banfn

bnfpo = wa_eban-bnfpo

binary search.

on change of wa_eban-ekgrp

or wa_eban-werks

or wa_eban-flief

  • or wa_eban-lfdat

or wa_eban-bukrs.

v_flag1 = 'X'.

endon.

if v_flag1 <> ''.

perform sub_append_header.

clear v_flag1.

endif.

if header-doc_type = wa_eban-bsart

and header-comp_code = wa_eban-bukrs

and header-vendor = wa_eban-flief

and header-purch_org = wa_eban-ekorg

and header-pur_group = wa_eban-ekgrp.

perform sub_append_item.

endif.

endloop.

ENDFORM. " sub_process_data

&----


*& Form sub_append_header

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM sub_append_header.

*!-- Populating the BAPI for PO header data

  • header-doc_date = wa_eban-erdat.

value = 10.

header-doc_type = wa_eban-bsart.

header-comp_code = wa_eban-bukrs.

header-vendor = wa_eban-flief.

header-CREATED_BY = sy-uname.

header-purch_org = wa_eban-ekorg.

header-pur_group = wa_eban-ekgrp.

header-langu = sy-langu.

header-indx = header-indx + 1.

APPEND header.

headerx-doc_type = 'X'.

headerx-comp_code = 'X'.

headerx-vendor = 'X'.

headerx-purch_org = 'X'.

headerx-CREATED_BY = 'X'.

headerx-pur_group = 'X'.

headerx-created_by = 'X'.

headerx-langu = 'X'.

headerx-indx = header-indx.

APPEND headerx.

ENDFORM. " sub_append_header

&----


*& Form sub_append_item

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM sub_append_item.

*!-- Populating the BAPI for PO Item data

poitems-po_item = value.

poitems-material = wa_eban-matnr.

poitems-stge_loc = wa_eban-lgort.

poitems-plant = wa_eban-werks.

poitems-item_cat = wa_eban-pstyp.

poitems-po_unit = wa_eban-meins.

poitems-quantity = wa_eban-menge - wa_eban-bsmng.

poitems-preq_no = wa_eban-banfn.

poitems-preq_item = wa_eban-bnfpo.

poitems-indx = header-indx.

APPEND poitems.

poitemsx-po_item = value.

poitemsx-material = 'X'.

poitemsx-stge_loc = 'X'.

poitemsx-plant = 'X'.

poitemsx-item_cat = 'X'.

poitemsx-preq_no = 'X'.

poitemsx-preq_item = 'X'.

poitemsx-po_unit = 'X'.

poitemsx-quantity = 'X'.

poitemsx-indx = header-indx.

APPEND poitemsx.

*!-- Populating the BAPI for PO Item Schedule data

scd-po_item = value.

scd-SCHED_LINE = value1.

scd-delivery_date = wa_eban-lfdat.

scd-quantity = wa_eban-menge - wa_eban-bsmng.

scd-indx = header-indx.

APPEND scd.

scdx-po_item = value.

scdx-SCHED_LINE = value1.

scdx-delivery_date = 'X'.

scdx-quantity = 'X'.

scdx-indx = header-indx.

APPEND scdx.

*!-- Populating the BAPI for PO Item data for Accounting

account-po_item = value.

account-quantity = wa_eban-menge - wa_eban-bsmng.

account-costcenter = wa_ebkn-kostl.

account-GL_ACCOUNT = wa_ebkn-sakto.

account-ORDERID = wa_ebkn-aufnr.

account-indx = header-indx.

APPEND account.

accountx-po_item = value.

accountx-quantity = wa_eban-menge - wa_eban-bsmng.

accountx-costcenter = wa_ebkn-kostl.

accountx-GL_ACCOUNT = wa_ebkn-sakto.

accountx-ORDERID = wa_ebkn-aufnr.

accountx-indx = header-indx.

APPEND accountx.

value = value + 10.

value1 = value1 + 1.

ENDFORM. " sub_append_item

&----


*& Form sub_po_bapi

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM sub_po_bapi.

data v_flag type c.

SORT HEADER BY INDX.

SORT POITEMS BY INDX.

SORT SCD BY INDX.

SORT ACCOUNT BY INDX.

SORT HEADERx BY INDX.

SORT POITEMSx BY INDX.

SORT SCDx BY INDX.

SORT ACCOUNTx BY INDX.

*!-- BAPI for uploading the PO with the above Inputs

LOOP AT HEADER.

MOVE-CORRESPONDING HEADER TO HEADER1.

LOOP AT POITEMS WHERE INDX = HEADER-INDX.

MOVE-CORRESPONDING POITEMS TO POITEMS1.

APPEND POITEMS1.

ENDLOOP.

LOOP AT SCD WHERE INDX = HEADER-INDX.

MOVE-CORRESPONDING SCD TO SCD1.

APPEND SCD1.

ENDLOOP.

LOOP AT ACCOUNT WHERE INDX = HEADER-INDX.

MOVE-CORRESPONDING ACCOUNT TO ACCOUNT1.

APPEND ACCOUNT1.

ENDLOOP.

LOOP AT POITEMSx WHERE INDX = HEADER-INDX.

MOVE-CORRESPONDING POITEMSx TO POITEMS1x.

APPEND POITEMS1x.

ENDLOOP.

LOOP AT SCDx WHERE INDX = HEADER-INDX.

MOVE-CORRESPONDING SCDx TO SCD1x.

APPEND SCD1x.

ENDLOOP.

LOOP AT ACCOUNTx WHERE INDX = HEADER-INDX.

MOVE-CORRESPONDING ACCOUNTx TO ACCOUNT1x.

APPEND ACCOUNT1x.

endloop.

read table headerx with key indx = header-indx binary search.

if sy-subrc = 0.

move-corresponding headerx to header1x.

endif.

sort: poitems1 by PO_ITEM,

scd1 by po_item,

account1 by po_item,

poitems1x by po_item,

scd1x by po_item,

account1x by po_item.

CALL FUNCTION 'BAPI_PO_CREATE1'

EXPORTING

POHEADER = header1

POHEADERX = header1x

  • POADDRVENDOR =

  • TESTRUN =

  • MEMORY_UNCOMPLETE =

  • MEMORY_COMPLETE =

  • NO_MESSAGING =

  • NO_MESSAGE_REQ =

  • NO_AUTHORITY =

  • NO_PRICE_FROM_PO =

IMPORTING

EXPPURCHASEORDER = gv_pono

  • EXPHEADER =

TABLES

RETURN = message

POITEM = poitems1[]

POITEMX = poitems1X[]

  • POADDRDELIVERY =

POSCHEDULE = scd1[]

POSCHEDULEX = scd1x[]

POACCOUNT = account1[]

    • POACCOUNTPROFITSEGMENT =

POACCOUNTX = account1x[]

  • POCONDHEADER =

  • POCONDHEADERX =

  • POCOND =

  • POCONDX =

  • POLIMITS =

  • POCONTRACTLIMITS =

  • POSERVICES =

  • POSRVACCESSVALUES =

  • POSERVICESTEXT =

  • EXTENSIONIN =

  • EXTENSIONOUT =

  • POTEXTHEADER =

  • POTEXTITEM =

  • POPARTNER =

.

wa_out-flief = header1-vendor.

wa_out-ekgrp = header1-pur_group.

wa_out-bukrs = header1-comp_code.

read table poitems1 index 1.

if sy-subrc = 0.

wa_out-werks = poitems1-plant.

endif.

*!-- Clearing all headers and internal tables

  • CLEAR: header,

  • poitems,

  • header1,

  • header1x,

  • poitems1[],

  • scd1[],

  • scd1x[],

  • account1[],

  • account1x[],

  • poitems1x[].

APPEND message.

  • READ TABLE MESSAGE with key type = 'A'

  • type = 'E'

  • type = 'S'.

loop at message.

if message-type = 'A' or message-type = 'E'.

v_flag = 'Y'.

exit.

else.

v_flag = 'N'.

endif.

endloop.

  • v_flag = 'N'.

IF message-type = 'A' OR message-type = 'E'.

  • v_flag = 'Y'.

  • ENDIF.

  • IF v_flag = 'Y'.

*!-- BAPI for rolling back the transaction

CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.

CLEAR v_flag.

ELSEIF v_flag = 'N'.

*!-- BAPI for saving the transaction

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

WAIT = 'X'.

  • IMPORTING

  • RETURN =

.

  • CLEAR v_flag.

endif.

  • delete table message where type = 'W' or type = 'I'.

read table message with key type = 'E' type = 'S'.

if sy-subrc eq 0.

endif.

*!-- Code for Traffic lights

if message-type = 'E'.

wa_out-icon = '@0A@'.

ld_color = 6.

ELSE.

IF MESSAGE-TYPE = 'A'.

ld_color = 7.

WA_OUT-ICON = '@09@'.

ELSE.

IF MESSAGE-TYPE = 'S'.

ld_color = 5.

WA_OUT-ICON = '@08@'.

ENDIF.

ENDIF.

ENDIF.

wa_out-ebeln = gv_pono.

WA_OUT-MESSAGE = MESSAGE-MESSAGE.

concatenate 'C' ld_color '10' into wa_out-line_color.

APPEND WA_OUT TO GT_OUT.

clear gv_pono.

*!-- Logic for closing the Purchase requisition if both the qty and

*!-- ordered qty are same.

if v_flag = 'N'.

sort poitems1 by preq_no preq_item.

select abanfn abnfpo aebakz apstyp amatnr amenge a~bsmng

b~mtart

from eban as a

inner join mara as b on bmatnr = amatnr

into corresponding fields of table itab

for all entries in poitems1

where a~banfn = poitems1-preq_no

and a~bnfpo = poitems1-preq_item.

sort itab by banfn bnfpo.

loop at itab. "where bnfpo in bnfpo

"and ebakz <> 'X'.

MTAB-banfn = itab-banfn.

append mtab.

endloop.

sort Mtab by banfn.

DELETE adjacent duplicates from mtab comparing banfn.

loop at mtab.

lno = 0.

loop at itab where banfn eq mtab-banfn.

lno = lno + 1.

itab-lnno = lno .

modify itab.

endloop.

endloop.

loop at mtab.

PReq = mtab-banfn.

clear : l_t_pritem. refresh : l_t_pritem.

CALL FUNCTION 'C14Z_WAIT_ON_COMMIT'

.

loop at itab where banfn eq mtab-banfn

"and bnfpo in bnfpo

and ebakz <> 'X'.

  • select sum( menge ) banfn bnfpo

  • into (ty_str-menge, ty_str-banfn, ty_str-bnfpo)

  • from ekpo where banfn = itab-banfn

  • and bnfpo = itab-bnfpo

  • group by banfn bnfpo.

  • endselect.

if itab-bsmng = itab-menge.

l_t_pritem-PREQ_ITEM = itab-bnfpo.

l_t_pritem-CLOSED = 'X'.

append l_t_pritem.

endif.

endloop.

*!-- BAPI for closing the Purchase Requisition.

CALL FUNCTION 'BAPI_REQUISITION_DELETE'

EXPORTING

NUMBER = PReq

TABLES

REQUISITION_ITEMS_TO_DELETE = l_t_pritem

RETURN = l_t_return.

IF SY-SUBRC = 0.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

ELSE.

CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'

IMPORTING

RETURN = RETURN.

.

ENDIF.

clear: l_t_pritem[],

l_t_return[],

preq.

*

  • loop at l_t_return.

*

  • write : / l_t_return-message color 5.

*

  • endloop.

*

endloop.

endif.

clear v_flag.

CLEAR: header,

poitems,

header1,

header1x,

poitems1[],

scd1[],

scd1x[],

account1[],

account1x[],

poitems1x[].

ENDLOOP.

ENDFORM. " sub_po_bapi

Former Member
0 Kudos
176

Hi

See the code and process in brief below.

&----


*& Form f9000_create_po

&----


  • Create Return Purchase Order consignment PO

----


FORM f9001_create_po .

  • Local Internal Table for Create PO

DATA:loc_int_bapimepoitem TYPE STANDARD TABLE OF bapimepoitem,

loc_int_bapiret2 TYPE STANDARD TABLE OF bapiret2,

loc_int_poitemx TYPE STANDARD TABLE OF bapimepoitemx.

  • Local Work area for BAPI.

DATA: loc_wa_bapimepoheader TYPE bapimepoheader, "For Header Data

loc_wa_bapimepoitem TYPE bapimepoitem, "For Item Data

loc_wa_bapimepoheaderx TYPE bapimepoheaderx, "For Header Data (Change Toolbar)

loc_wa_poitemx TYPE bapimepoitemx. "For Item Data (Change Parameter)

  • Pass PO Header Data.

loc_wa_bapimepoheader-comp_code = ws_bukrs.

loc_wa_bapimepoheader-purch_org = ws_ekorg.

loc_wa_bapimepoheader-pur_group = ws_ekgrp.

loc_wa_bapimepoheader-doc_type = ws_bsart.

loc_wa_bapimepoheader-creat_date = sy-datum .

loc_wa_bapimepoheader-created_by = sy-uname.

loc_wa_bapimepoheader-vendor = ws_lifnr.

loc_wa_bapimepoheader-currency = ws_waers.

loc_wa_bapimepoheader-langu = sy-langu .

  • Pass POHEADERX(Status)

loc_wa_bapimepoheaderx-comp_code = wc_x.

loc_wa_bapimepoheaderx-purch_org = wc_x.

loc_wa_bapimepoheaderx-pur_group = wc_x.

loc_wa_bapimepoheaderx-doc_type = wc_x.

loc_wa_bapimepoheaderx-creat_date = wc_x.

loc_wa_bapimepoheaderx-created_by = wc_x.

loc_wa_bapimepoheaderx-vendor = wc_x.

loc_wa_bapimepoheaderx-currency = wc_x.

loc_wa_bapimepoheaderx-langu = wc_x.

  • Create Item data.

LOOP AT int_ekpo INTO wa_ekpo.

loc_wa_bapimepoitem-material = wa_ekpo-matnr.

loc_wa_bapimepoitem-plant = wa_ekpo-werks.

loc_wa_bapimepoitem-stge_loc = wa_ekpo-lgort.

loc_wa_bapimepoitem-po_unit = wa_ekpo-meins.

loc_wa_bapimepoitem-batch = wa_vbap-charg. " Sales Order Batch

loc_wa_bapimepoitem-quantity = wa_ekpo-kwmeng. " SO Qty

loc_wa_bapimepoitem-po_item = wa_ekpo-posnr.

  • Read internal table int_eket VENDORBATCH.

READ TABLE int_eket INTO wa_eket WITH KEY ebeln = p_bstnk

ebelp = wa_vbap-posnr

BINARY SEARCH.

IF sy-subrc = 0.

loc_wa_bapimepoitem-vendrbatch = wa_eket-licha.

ENDIF.

  • Append to Item Table

APPEND loc_wa_bapimepoitem TO loc_int_bapimepoitem .

  • Create Corresponding itemx entry(Status Flag)

loc_wa_poitemx-po_item = wa_ekpo-posnr.

loc_wa_poitemx-po_itemx = wc_x.

loc_wa_poitemx-material = wc_x.

loc_wa_poitemx-plant = wc_x.

loc_wa_poitemx-stge_loc = wc_x.

loc_wa_poitemx-batch = wc_x.

loc_wa_poitemx-vendrbatch = wc_x.

loc_wa_poitemx-quantity = wc_x.

loc_wa_poitemx-po_unit = wc_x.

loc_wa_poitemx-net_price = wc_x.

  • Append to PO Item status

APPEND loc_wa_poitemx TO loc_int_poitemx.

ENDIF.

CLEAR : loc_wa_bapimepoitem, wa_ekpo, loc_wa_poitemx,wa_eket,wa_vbap.

ENDLOOP.

  • Call FM to create Consignment Return PO.

CALL FUNCTION 'BAPI_PO_CREATE1'

EXPORTING

poheader = loc_wa_bapimepoheader

poheaderx = loc_wa_bapimepoheaderx

  • testrun = 'X'

IMPORTING

exppurchaseorder = ws_pono

TABLES

return = int_returnp

poitem = loc_int_bapimepoitem

poitemx = loc_int_poitemx.

  • Check PO created or not.

IF ws_pono IS NOT INITIAL.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = wc_x.

  • Wait for Commit the transaction

WAIT UP TO 3 SECONDS.