Application Development and Automation 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: 
Read only

function module MM_group_requisistions

Former Member
0 Likes
518

Hi all,

I have a question regarding mm_group_requisitons .

i have a group of requsitons in hand

i need to group all the purchanse requsitions using the function module mm_group_requisitons on certain conditions example : group by company code .

pls help me out with a sample code .

Thanks in advance ,

siva.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
484

Hi,

use BAPI_PO_CREATE1.

check this Sample code,

REPORT zpo_create .

PARAMETERS: p-file LIKE rlgrap-filename DEFAULT

'c:\demo3.txt'.

DATA: BEGIN OF itab OCCURS 0,

line(1000),

END OF itab.

DATA l_item(5) TYPE n.

TABLES : zerror.

DATA lcounter(3) TYPE n.

DATA : l_errflag.

DATA : l_po_header LIKE bapimepoheader.

DATA : l_po_headerx LIKE bapimepoheaderx.

DATA : t_po_account LIKE bapimepoaccount OCCURS 0 WITH HEADER LINE.

DATA : t_po_accountx LIKE bapimepoaccountx OCCURS 0 WITH HEADER LINE.

DATA : l_new_po(10), l_last_po(10).

DATA : l_purchaseorder LIKE bapimepoheader-po_number.

*DATA : L_HEADER LIKE BAPIMEPOHEADER STRUCTURE BAPIMEPOHEADER.

DATA : BEGIN OF t_po_items OCCURS 0.

INCLUDE STRUCTURE bapimepoitem.

DATA : END OF t_po_items.

DATA : BEGIN OF t_po_itemsx OCCURS 0.

INCLUDE STRUCTURE bapimepoitemx.

DATA : END OF t_po_itemsx.

DATA : BEGIN OF t_return OCCURS 0.

INCLUDE STRUCTURE bapiret2.

DATA : END OF t_return.

CLEAR : l_po_header.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

filename = p-file

filetype = 'DAT'

TABLES

data_tab = itab

EXCEPTIONS

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

invalid_type = 5

OTHERS = 6.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

EXIT.

ENDIF.

LOOP AT itab.

IF itab-line(1) EQ 'K'.

l_new_po = itab-line(10).

IF l_last_po NE l_new_po AND l_last_po NE space.

PERFORM create_po.

PERFORM refresh_table.

ENDIF.

IF itab-line+13(2) EQ '40'.

PERFORM append_header.

ENDIF.

IF itab-line+13(2) EQ '81'.

PERFORM append_item.

ENDIF.

l_last_po = l_new_po.

ENDIF.

ENDLOOP.

IF sy-subrc EQ 0.

PERFORM create_po.

PERFORM refresh_table.

ENDIF.

&----


*& Form CREATE_PO

&----


  • PO Create

----


  • --> p1 text

  • <-- p2 text

----


FORM create_po .

CLEAR : l_purchaseorder.

CALL FUNCTION 'BAPI_PO_CREATE1'

EXPORTING

poheader = l_po_header

poheaderx = l_po_headerx

  • POADDRVENDOR =

  • TESTRUN =

  • MEMORY_UNCOMPLETE =

  • MEMORY_COMPLETE =

  • POEXPIMPHEADER =

  • POEXPIMPHEADERX =

  • VERSIONS =

  • NO_MESSAGING =

  • NO_MESSAGE_REQ =

  • NO_AUTHORITY =

  • NO_PRICE_FROM_PO =

IMPORTING

exppurchaseorder = l_purchaseorder

  • EXPHEADER =

  • EXPPOEXPIMPHEADER =

TABLES

return = t_return

poitem = t_po_items

poitemx = t_po_itemsx

  • POADDRDELIVERY =

  • POSCHEDULE =

  • POSCHEDULEX =

poaccount = t_po_account

  • POACCOUNTPROFITSEGMENT =

poaccountx = t_po_accountx

  • POCONDHEADER =

  • POCONDHEADERX =

  • POCOND =

  • POCONDX =

  • POLIMITS =

  • POCONTRACTLIMITS =

  • POSERVICES =

  • POSRVACCESSVALUES =

  • POSERVICESTEXT =

  • EXTENSIONIN =

  • EXTENSIONOUT =

  • POEXPIMPITEM =

  • POEXPIMPITEMX =

  • POTEXTHEADER =

  • POTEXTITEM =

  • ALLVERSIONS =

  • POPARTNER =

.

l_errflag = space.

lcounter = 1.

LOOP AT t_return .

IF t_return-type = 'E'.

l_errflag = 'X'.

GET TIME.

PERFORM append_error.

ENDIF.

WRITE : /1 t_return-message.

ENDLOOP.

IF l_errflag EQ space.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

  • EXPORTING

  • WAIT =

  • IMPORTING

  • RETURN =

.

ENDIF.

ENDFORM. " CREATE_PO

&----


*& Form APPEND_HEADER

&----


  • PO Header print

----


  • --> p1 text

  • <-- p2 text

----


FORM append_header .

l_po_header-comp_code = '1000'." Company Code

l_po_header-doc_type = 'NB'. " Order Typr BSART

l_po_header-creat_date = sy-datum. " P.O Dt - BEDAT

*CONCATENATE '0000' ITAB+72(6) INTO L_PO_HEADER-VENDOR .

l_po_header-vendor = itab-line+71(6).

*L_PO_HEADER-VENDOR = ITAB+72(6) " 'ABC'. "Vendor - EKKO-LIFNR

IF itab-line(4) NE 'K034'.

l_po_header-purch_org = '2000'. " Purch. Org - EKKO-EKORG

l_po_header-pur_group = 'F01'. " Purch Group - EKKO-EKGRP

ELSE.

l_po_header-purch_org = '1000'. " Purch. Org - EKKO-EKORG

l_po_header-pur_group = '001'. " Purch Group - EKKO-EKGRP

ENDIF.

l_po_header-currency_iso = 'USD'. " Currency Default field for Enjoy

l_po_header-ref_1 = itab-line+1(9).

*L_PO_HEADER-DOC_CAT = 'F'. " Account Assign Cat EKPO-KNTTP

*_PO_HEADER-CREATED_BY = SY-UNAME.

CLEAR : l_po_headerx.

l_po_headerx-po_number = 'X'.

l_po_headerx-comp_code = 'X'." Company Code

l_po_headerx-doc_type = 'X'. " Order Typr BSART

l_po_headerx-vendor = 'X'. "Vendor - EKKO-LIFNR

l_po_headerx-purch_org = 'X'. " Purch. Org - EKKO-EKORG

l_po_headerx-pur_group = 'X'. " Purch Group - EKKO-EKGRP

l_po_headerx-currency_iso = 'X'. " Currency Default field for Enjoy

l_po_headerx-ref_1 = 'X'.

ENDFORM. " APPEND_HEADER

&----


*& Form APPEND_ITEM

&----


  • Material Number and Item print

----


  • --> p1 text

  • <-- p2 text

----


FORM append_item .

  • PO Line Items

l_item = l_item + 10.

t_po_items-po_item = l_item.

*T_PO_ITEMS-PO_ITEM = '00010'." Line Item No - EKPO-EBELP

*T_PO_ITEMS-SHORT_TEXT = 'KSR TEXT'." Line Item TEXT

CONCATENATE '00000000' itab-line+32(10) INTO t_po_items-material.

*T_PO_ITEMS-MATERIAL = '000000000000000043'. " Material No - EKPO-EMATN

CONCATENATE '00000000' itab-line+32(10) INTO t_po_items-ematerial.

t_po_items-plant = '2001'. " Plant - EKPO-WERKS

t_po_items-quantity = '1.000'.

t_po_items-net_price = '10.00'. " EKPO-NETPR

t_po_items-price_unit = '10 '.

*T_PO_ITEMS-TAX_CODE = 'A2'.

IF itab-line+0(4) EQ 'K034'.

t_po_items-acctasscat = 'R'.

t_po_items-plant = '1001'.

t_po_account-po_item = l_item.

t_po_account-profit_ctr = 'BR034'.

t_po_account-gl_account = '0000135075'.

  • T_PO_ACCOUNT-CO_AREA = '1000'.

APPEND t_po_account.

CLEAR t_po_account.

t_po_accountx-po_item = l_item.

t_po_accountx-profit_ctr = 'X'.

t_po_accountx-gl_account = 'X'.

  • T_PO_ACCOUNTX-CO_AREA = 'X'.

APPEND t_po_accountx.

CLEAR t_po_accountx.

ENDIF.

APPEND t_po_items.

CLEAR t_po_items.

t_po_itemsx-po_item = l_item.

t_po_itemsx-po_itemx = 'X'.

t_po_itemsx-acctasscat = 'X'.

t_po_itemsx-material = 'X'.

t_po_itemsx-ematerial = 'X'.

t_po_itemsx-plant = 'X'.

t_po_itemsx-quantity = 'X'.

t_po_itemsx-net_price = 'X'.

t_po_itemsx-price_unit = 'X'.

*T_PO_ITEMSX-TAX_CODE = 'X'.

APPEND t_po_itemsx.

CLEAR t_po_itemsx.

      • Second Line Item

ENDFORM. " APPEND_ITEM

&----


*& Form REFRESH_TABLE

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM refresh_table .

REFRESH : t_po_items, t_po_itemsx.

CLEAR l_item.

ENDFORM. " REFRESH_TABLE

&----


*& Form append_error

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM append_error .

MOVE : sy-datum TO zerror-zdate,

sy-uzeit TO zerror-ztime,

itab+3(5) TO zerror-document_no,

t_return-message TO zerror-message.

lcounter = lcounter + 1.

zerror-counter = lcounter .

zerror-rec_type = itab-line(1).

MODIFY zerror. CLEAR zerror.

COMMIT WORK.

ENDFORM. " append_error

Regarsd

2 REPLIES 2
Read only

Former Member
0 Likes
485

Hi,

use BAPI_PO_CREATE1.

check this Sample code,

REPORT zpo_create .

PARAMETERS: p-file LIKE rlgrap-filename DEFAULT

'c:\demo3.txt'.

DATA: BEGIN OF itab OCCURS 0,

line(1000),

END OF itab.

DATA l_item(5) TYPE n.

TABLES : zerror.

DATA lcounter(3) TYPE n.

DATA : l_errflag.

DATA : l_po_header LIKE bapimepoheader.

DATA : l_po_headerx LIKE bapimepoheaderx.

DATA : t_po_account LIKE bapimepoaccount OCCURS 0 WITH HEADER LINE.

DATA : t_po_accountx LIKE bapimepoaccountx OCCURS 0 WITH HEADER LINE.

DATA : l_new_po(10), l_last_po(10).

DATA : l_purchaseorder LIKE bapimepoheader-po_number.

*DATA : L_HEADER LIKE BAPIMEPOHEADER STRUCTURE BAPIMEPOHEADER.

DATA : BEGIN OF t_po_items OCCURS 0.

INCLUDE STRUCTURE bapimepoitem.

DATA : END OF t_po_items.

DATA : BEGIN OF t_po_itemsx OCCURS 0.

INCLUDE STRUCTURE bapimepoitemx.

DATA : END OF t_po_itemsx.

DATA : BEGIN OF t_return OCCURS 0.

INCLUDE STRUCTURE bapiret2.

DATA : END OF t_return.

CLEAR : l_po_header.

CALL FUNCTION 'WS_UPLOAD'

EXPORTING

filename = p-file

filetype = 'DAT'

TABLES

data_tab = itab

EXCEPTIONS

file_open_error = 1

file_read_error = 2

no_batch = 3

gui_refuse_filetransfer = 4

invalid_type = 5

OTHERS = 6.

IF sy-subrc <> 0.

MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno

WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

EXIT.

ENDIF.

LOOP AT itab.

IF itab-line(1) EQ 'K'.

l_new_po = itab-line(10).

IF l_last_po NE l_new_po AND l_last_po NE space.

PERFORM create_po.

PERFORM refresh_table.

ENDIF.

IF itab-line+13(2) EQ '40'.

PERFORM append_header.

ENDIF.

IF itab-line+13(2) EQ '81'.

PERFORM append_item.

ENDIF.

l_last_po = l_new_po.

ENDIF.

ENDLOOP.

IF sy-subrc EQ 0.

PERFORM create_po.

PERFORM refresh_table.

ENDIF.

&----


*& Form CREATE_PO

&----


  • PO Create

----


  • --> p1 text

  • <-- p2 text

----


FORM create_po .

CLEAR : l_purchaseorder.

CALL FUNCTION 'BAPI_PO_CREATE1'

EXPORTING

poheader = l_po_header

poheaderx = l_po_headerx

  • POADDRVENDOR =

  • TESTRUN =

  • MEMORY_UNCOMPLETE =

  • MEMORY_COMPLETE =

  • POEXPIMPHEADER =

  • POEXPIMPHEADERX =

  • VERSIONS =

  • NO_MESSAGING =

  • NO_MESSAGE_REQ =

  • NO_AUTHORITY =

  • NO_PRICE_FROM_PO =

IMPORTING

exppurchaseorder = l_purchaseorder

  • EXPHEADER =

  • EXPPOEXPIMPHEADER =

TABLES

return = t_return

poitem = t_po_items

poitemx = t_po_itemsx

  • POADDRDELIVERY =

  • POSCHEDULE =

  • POSCHEDULEX =

poaccount = t_po_account

  • POACCOUNTPROFITSEGMENT =

poaccountx = t_po_accountx

  • POCONDHEADER =

  • POCONDHEADERX =

  • POCOND =

  • POCONDX =

  • POLIMITS =

  • POCONTRACTLIMITS =

  • POSERVICES =

  • POSRVACCESSVALUES =

  • POSERVICESTEXT =

  • EXTENSIONIN =

  • EXTENSIONOUT =

  • POEXPIMPITEM =

  • POEXPIMPITEMX =

  • POTEXTHEADER =

  • POTEXTITEM =

  • ALLVERSIONS =

  • POPARTNER =

.

l_errflag = space.

lcounter = 1.

LOOP AT t_return .

IF t_return-type = 'E'.

l_errflag = 'X'.

GET TIME.

PERFORM append_error.

ENDIF.

WRITE : /1 t_return-message.

ENDLOOP.

IF l_errflag EQ space.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

  • EXPORTING

  • WAIT =

  • IMPORTING

  • RETURN =

.

ENDIF.

ENDFORM. " CREATE_PO

&----


*& Form APPEND_HEADER

&----


  • PO Header print

----


  • --> p1 text

  • <-- p2 text

----


FORM append_header .

l_po_header-comp_code = '1000'." Company Code

l_po_header-doc_type = 'NB'. " Order Typr BSART

l_po_header-creat_date = sy-datum. " P.O Dt - BEDAT

*CONCATENATE '0000' ITAB+72(6) INTO L_PO_HEADER-VENDOR .

l_po_header-vendor = itab-line+71(6).

*L_PO_HEADER-VENDOR = ITAB+72(6) " 'ABC'. "Vendor - EKKO-LIFNR

IF itab-line(4) NE 'K034'.

l_po_header-purch_org = '2000'. " Purch. Org - EKKO-EKORG

l_po_header-pur_group = 'F01'. " Purch Group - EKKO-EKGRP

ELSE.

l_po_header-purch_org = '1000'. " Purch. Org - EKKO-EKORG

l_po_header-pur_group = '001'. " Purch Group - EKKO-EKGRP

ENDIF.

l_po_header-currency_iso = 'USD'. " Currency Default field for Enjoy

l_po_header-ref_1 = itab-line+1(9).

*L_PO_HEADER-DOC_CAT = 'F'. " Account Assign Cat EKPO-KNTTP

*_PO_HEADER-CREATED_BY = SY-UNAME.

CLEAR : l_po_headerx.

l_po_headerx-po_number = 'X'.

l_po_headerx-comp_code = 'X'." Company Code

l_po_headerx-doc_type = 'X'. " Order Typr BSART

l_po_headerx-vendor = 'X'. "Vendor - EKKO-LIFNR

l_po_headerx-purch_org = 'X'. " Purch. Org - EKKO-EKORG

l_po_headerx-pur_group = 'X'. " Purch Group - EKKO-EKGRP

l_po_headerx-currency_iso = 'X'. " Currency Default field for Enjoy

l_po_headerx-ref_1 = 'X'.

ENDFORM. " APPEND_HEADER

&----


*& Form APPEND_ITEM

&----


  • Material Number and Item print

----


  • --> p1 text

  • <-- p2 text

----


FORM append_item .

  • PO Line Items

l_item = l_item + 10.

t_po_items-po_item = l_item.

*T_PO_ITEMS-PO_ITEM = '00010'." Line Item No - EKPO-EBELP

*T_PO_ITEMS-SHORT_TEXT = 'KSR TEXT'." Line Item TEXT

CONCATENATE '00000000' itab-line+32(10) INTO t_po_items-material.

*T_PO_ITEMS-MATERIAL = '000000000000000043'. " Material No - EKPO-EMATN

CONCATENATE '00000000' itab-line+32(10) INTO t_po_items-ematerial.

t_po_items-plant = '2001'. " Plant - EKPO-WERKS

t_po_items-quantity = '1.000'.

t_po_items-net_price = '10.00'. " EKPO-NETPR

t_po_items-price_unit = '10 '.

*T_PO_ITEMS-TAX_CODE = 'A2'.

IF itab-line+0(4) EQ 'K034'.

t_po_items-acctasscat = 'R'.

t_po_items-plant = '1001'.

t_po_account-po_item = l_item.

t_po_account-profit_ctr = 'BR034'.

t_po_account-gl_account = '0000135075'.

  • T_PO_ACCOUNT-CO_AREA = '1000'.

APPEND t_po_account.

CLEAR t_po_account.

t_po_accountx-po_item = l_item.

t_po_accountx-profit_ctr = 'X'.

t_po_accountx-gl_account = 'X'.

  • T_PO_ACCOUNTX-CO_AREA = 'X'.

APPEND t_po_accountx.

CLEAR t_po_accountx.

ENDIF.

APPEND t_po_items.

CLEAR t_po_items.

t_po_itemsx-po_item = l_item.

t_po_itemsx-po_itemx = 'X'.

t_po_itemsx-acctasscat = 'X'.

t_po_itemsx-material = 'X'.

t_po_itemsx-ematerial = 'X'.

t_po_itemsx-plant = 'X'.

t_po_itemsx-quantity = 'X'.

t_po_itemsx-net_price = 'X'.

t_po_itemsx-price_unit = 'X'.

*T_PO_ITEMSX-TAX_CODE = 'X'.

APPEND t_po_itemsx.

CLEAR t_po_itemsx.

      • Second Line Item

ENDFORM. " APPEND_ITEM

&----


*& Form REFRESH_TABLE

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM refresh_table .

REFRESH : t_po_items, t_po_itemsx.

CLEAR l_item.

ENDFORM. " REFRESH_TABLE

&----


*& Form append_error

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM append_error .

MOVE : sy-datum TO zerror-zdate,

sy-uzeit TO zerror-ztime,

itab+3(5) TO zerror-document_no,

t_return-message TO zerror-message.

lcounter = lcounter + 1.

zerror-counter = lcounter .

zerror-rec_type = itab-line(1).

MODIFY zerror. CLEAR zerror.

COMMIT WORK.

ENDFORM. " append_error

Regarsd

Read only

Former Member
0 Likes
484

Hi,

Thanks for your reply

whats my question is

i will fetch all the requisitions created on a perticular day OPEN items created by a particular user using the bapi bapi_purrequisitions_getitems.

and i will fetch all the required data from our custom and related tables from sap .

and i will assingn the source of supply using RM06BZ00(standard report)

then i need to combine all purchance requisitons into one PO with certain conditons like all PR containg to on group will be combined into one PO the all the same items will become one (EX : ALL qty will me added to same PR)

Now i have doubt on this point that how to group all PRs using MM_GROUP_requsitions

PLs help me out regarding this issue

POINTS WILL be ASSIGEND TO YOUR ANSWER.

Thanks in advance

siva