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: 

BDC For ME21

Former Member
0 Kudos
84

Helo Experts ,

Can Any one help me For ME21 BDC Program

i record the ME21 Transaction but while executing the BDC the Flat file is not uploading any value

3 REPLIES 3

Former Member
0 Kudos
55

Hi,

Refer the below thread

Former Member
0 Kudos
55

Hi Surendra.

I would like to suggest a couple of links, as it is quite similar to your case,

[SDN - Reference for ME21 BDC program|;

[SDN - Reference for ME21 BDC recording transaction|;

[SDN - Reference for program in BDC ME21 for flat file|;

Hope that's usefull.

Good Luck & Regards.

Harsh Dave

former_member262988
Active Contributor
0 Kudos
55

hi,

use this

&----


*& Form CREATE_PO

&----


  • Creating PO

----


  • --> p1 text

  • <-- p2 text

----


FORM CREATE_PO .

DATA: HEAD LIKE BAPIMEPOHEADER,

HEADX LIKE BAPIMEPOHEADERX,

ITEM LIKE BAPIMEPOITEM OCCURS 0 WITH HEADER LINE,

ITEMX LIKE BAPIMEPOITEMX OCCURS 0 WITH HEADER LINE,

SCHEDULE LIKE BAPIMEPOSCHEDULE OCCURS 0 WITH HEADER LINE,

SCHEDULEX LIKE BAPIMEPOSCHEDULX OCCURS 0 WITH HEADER LINE,

CONDITION LIKE BAPIMEPOCONDHEADER OCCURS 0 WITH HEADER LINE,

CONDITIONX LIKE BAPIMEPOCONDHEADERX OCCURS 0 WITH HEADER LINE,

RETURNS LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE,

POPARTNER LIKE BAPIEKKOP OCCURS 0 WITH HEADER LINE.

DATA: V_EKGRP TYPE MARC-EKGRP.

DATA: BEGIN OF IT_WRITE OCCURS 0,

MESSAGE LIKE BAPIRET2-MESSAGE,

END OF IT_WRITE.

DATA: V_EKORG TYPE EKORG.

DATA: V_MAKT LIKE MAKT-MAKTX.

DATA: V_MEINS TYPE MEINS.

DATA: V_REMANT TYPE MATNR,

V_LINT TYPE MATNR,

V_LDESC TYPE MAKTX,

V_RDESC TYPE MAKTX,

V_LMEINS TYPE MEINS,

V_RMEINS TYPE MEINS,

V_LMENGE TYPE ZMENGE,

V_RMENGE TYPE ZMENGE.

CONCATENATE ZMMHGAGREMENT-MATNR+0(9) 'L' INTO V_LINT.

CONCATENATE ZMMHGAGREMENT-MATNR+0(9) 'W' INTO V_REMANT.

SELECT SINGLE MEINS FROM MARA INTO V_MEINS WHERE MATNR = ZMMHGAGREMENT-MATNR.

SELECT SINGLE DCODE FROM ZMMDYNCODE INTO V_MAKT WHERE MATNR = ZMMHGAGREMENT-MATNR

AND ZYEAR = ZMMHGAGREMENT-PYEAR

AND SEASON = ZMMHGAGREMENT-PSEASON.

IF SY-SUBRC NE 0.

SELECT SINGLE MAKTX FROM MAKT INTO V_MAKT WHERE MATNR = ZMMHGAGREMENT-MATNR.

ENDIF.

  • SELECT SINGLE EKORG FROM T001W INTO V_EKORG WHERE WERKS = I_PPLANT.

  • V_BUKRS = ZMMHGAGREMENT-PPLANT+0(1).

CONCATENATE ZMMHGAGREMENT-PPLANT+0(1) '011' INTO V_BUKRS.

V_CHAR = V_BUKRS+0(2).

V_EKORG = V_BUKRS.

CONCATENATE V_CHAR '0' INTO V_EKGRP.

*POHEAD

HEAD-COMP_CODE = V_BUKRS.

HEAD-DOC_TYPE = 'ZREG'.

HEAD-VENDOR = V_LIFNR.

HEAD-PURCH_ORG = V_EKORG.

HEAD-PUR_GROUP = V_EKGRP.

HEAD-DOC_DATE = ZMMHGAGREMENT-ZDATE. "I_ADATE.

HEADX-COMP_CODE = 'X'.

HEADX-DOC_TYPE = 'X'.

HEADX-VENDOR = 'X'.

HEADX-PURCH_ORG = 'X'.

HEADX-PUR_GROUP = 'X'.

HEADX-DOC_DATE = 'X'.

*POITEM

ITEM-PO_ITEM = '10'.

ITEM-MATERIAL = ZMMHGAGREMENT-MATNR..

ITEM-SHORT_TEXT = V_MAKT.

ITEM-PLANT = ZMMHGAGREMENT-PPLANT.

ITEM-QUANTITY = ZMMHGAGREMENT-MENGE.

ITEM-PO_UNIT = V_MEINS.

ITEM-NET_PRICE = ZMMHGAGREMENT-NETPR.

ITEM-BATCH = ZMMHGAGREMENT-BATCH.

ITEM-TAX_CODE = 'V0'.

ITEM-INFO_UPD = ' '.

APPEND ITEM.

ITEMX-PO_ITEM = '10'.

ITEMX-PO_ITEMX = 'X'.

ITEMX-SHORT_TEXT = 'X'.

ITEMX-MATERIAL = 'X'.

ITEMX-PLANT = 'X'.

ITEMX-QUANTITY = 'X'.

ITEMX-PO_UNIT = 'X'.

ITEMX-NET_PRICE = 'X'.

ITEMX-BATCH = 'x'.

ITEMX-TAX_CODE = 'X'.

ITEMX-INFO_UPD = 'X'.

APPEND ITEMX.

*ZPAYMENT-PAYMENT

*SCHEDULE

SCHEDULE-PO_ITEM = '10'.

SCHEDULE-DELIVERY_DATE = ZMMHGAGREMENT-RDATE.

SCHEDULE-QUANTITY = ZMMHGAGREMENT-MENGE..

APPEND SCHEDULE.

SCHEDULEX-PO_ITEM = '10'.

SCHEDULEX-PO_ITEMX = 'X'.

SCHEDULEX-DELIVERY_DATE = 'X'.

SCHEDULEX-QUANTITY = 'X'.

APPEND SCHEDULEX.

  • CONDITIONS

CONDITION-ITM_NUMBER = '10'.

CONDITION-COND_TYPE = 'P001'.

CONDITION-COND_VALUE = ZMMHGAGREMENT-NETPR..

CONDITION-CURRENCY = 'INR'.

APPEND CONDITION.

CONDITIONX-ITM_NUMBER = '10'.

CONDITIONX-ITM_NUMBERX = 'X'.

CONDITIONX-COND_TYPE = 'X'.

CONDITIONX-COND_VALUE = 'X'.

CONDITIONX-CURRENCY = 'X'.

APPEND CONDITIONX.

IF ZMMHGAGREMENT-MATNR+9(1) = 'K'.

*POITEM

  • V_RDESC TYPE MAKTX,

  • V_LMEINS TYPE MEINS,

  • V_RMEINS TYPE MEINS.

SELECT SINGLE MEINS FROM MARA INTO V_LMEINS WHERE MATNR = V_LINT.

SELECT SINGLE MAKTX FROM MAKT INTO V_LDESC WHERE MATNR = V_LINT.

V_LMENGE = ( ( ZMMHGAGREMENT-MENGE * 50 ) / 100 ).

ITEM-PO_ITEM = '20'.

ITEM-MATERIAL = V_LINT.

ITEM-SHORT_TEXT = V_LDESC.

ITEM-PLANT = ZMMHGAGREMENT-PPLANT.

ITEM-QUANTITY = V_LMENGE.

ITEM-PO_UNIT = V_LMEINS.

ITEM-NET_PRICE = ZPPPRDPOLICY-LRATE."ZMMHGAGREMENT-NETPR.

ITEM-BATCH = ZMMHGAGREMENT-BATCH.

ITEM-TAX_CODE = 'V0'.

ITEM-INFO_UPD = ' '.

APPEND ITEM.

ITEMX-PO_ITEM = '20'.

ITEMX-PO_ITEMX = 'X'.

ITEMX-SHORT_TEXT = 'X'.

ITEMX-MATERIAL = 'X'.

ITEMX-PLANT = 'X'.

ITEMX-QUANTITY = 'X'.

ITEMX-PO_UNIT = 'X'.

ITEMX-NET_PRICE = 'X'.

ITEMX-BATCH = 'x'.

ITEMX-TAX_CODE = 'X'.

ITEMX-INFO_UPD = 'X'.

APPEND ITEMX.

*ZPAYMENT-PAYMENT

*SCHEDULE

SCHEDULE-PO_ITEM = '20'.

SCHEDULE-DELIVERY_DATE = ZMMHGAGREMENT-RDATE.

SCHEDULE-QUANTITY = V_LMENGE.

APPEND SCHEDULE.

SCHEDULEX-PO_ITEM = '20'.

SCHEDULEX-PO_ITEMX = 'X'.

SCHEDULEX-DELIVERY_DATE = 'X'.

SCHEDULEX-QUANTITY = 'X'.

APPEND SCHEDULEX.

  • CONDITIONS

CONDITION-ITM_NUMBER = '20'.

CONDITION-COND_TYPE = 'P001'.

CONDITION-COND_VALUE = ZPPPRDPOLICY-LRATE.

CONDITION-CURRENCY = 'INR'.

APPEND CONDITION.

CONDITIONX-ITM_NUMBER = '20'.

CONDITIONX-ITM_NUMBERX = 'X'.

CONDITIONX-COND_TYPE = 'X'.

CONDITIONX-COND_VALUE = 'X'.

CONDITIONX-CURRENCY = 'X'.

APPEND CONDITIONX.

      • ADDING REMNANT TO PO IF REMNANT VALUE IS MAINTAINED IN PO

IF NOT ZPPPRDPOLICY-RCENT IS INITIAL.

SELECT SINGLE MEINS FROM MARA INTO V_RMEINS WHERE MATNR = V_REMANT.

SELECT SINGLE MAKTX FROM MAKT INTO V_RDESC WHERE MATNR = V_REMANT.

V_RMENGE = ( ( ZMMHGAGREMENT-MENGE * ZPPPRDPOLICY-RCENT ) / 100 ).

ITEM-PO_ITEM = '30'.

ITEM-MATERIAL = V_REMANT.

ITEM-SHORT_TEXT = V_RDESC.

ITEM-PLANT = ZMMHGAGREMENT-PPLANT.

ITEM-QUANTITY = V_RMENGE.

ITEM-PO_UNIT = V_RMEINS.

ITEM-NET_PRICE = ZPPPRDPOLICY-RRATE."ZMMHGAGREMENT-NETPR.

ITEM-BATCH = ZMMHGAGREMENT-BATCH.

ITEM-TAX_CODE = 'V0'.

ITEM-INFO_UPD = ' '.

APPEND ITEM.

ITEMX-PO_ITEM = '30'.

ITEMX-PO_ITEMX = 'X'.

ITEMX-SHORT_TEXT = 'X'.

ITEMX-MATERIAL = 'X'.

ITEMX-PLANT = 'X'.

ITEMX-QUANTITY = 'X'.

ITEMX-PO_UNIT = 'X'.

ITEMX-NET_PRICE = 'X'.

ITEMX-BATCH = 'x'.

ITEMX-TAX_CODE = 'X'.

ITEMX-INFO_UPD = 'X'.

APPEND ITEMX.

*ZPAYMENT-PAYMENT

*SCHEDULE

SCHEDULE-PO_ITEM = '30'.

SCHEDULE-DELIVERY_DATE = ZMMHGAGREMENT-RDATE.

SCHEDULE-QUANTITY = V_RMENGE.

APPEND SCHEDULE.

SCHEDULEX-PO_ITEM = '30'.

SCHEDULEX-PO_ITEMX = 'X'.

SCHEDULEX-DELIVERY_DATE = 'X'.

SCHEDULEX-QUANTITY = 'X'.

APPEND SCHEDULEX.

  • CONDITIONS

CONDITION-ITM_NUMBER = '30'.

CONDITION-COND_TYPE = 'P001'.

CONDITION-COND_VALUE = ZPPPRDPOLICY-RRATE.

CONDITION-CURRENCY = 'INR'.

APPEND CONDITION.

CONDITIONX-ITM_NUMBER = '30'.

CONDITIONX-ITM_NUMBERX = 'X'.

CONDITIONX-COND_TYPE = 'X'.

CONDITIONX-COND_VALUE = 'X'.

CONDITIONX-CURRENCY = 'X'.

APPEND CONDITIONX.

ENDIF.

ELSE.

IF NOT ZPPPRDPOLICY-RCENT IS INITIAL.

SELECT SINGLE MEINS FROM MARA INTO V_RMEINS WHERE MATNR = V_REMANT.

SELECT SINGLE MAKTX FROM MAKT INTO V_RDESC WHERE MATNR = V_REMANT.

V_RMENGE = ( ( ZMMHGAGREMENT-MENGE * ZPPPRDPOLICY-RCENT ) / 100 ).

ITEM-PO_ITEM = '20'.

ITEM-MATERIAL = V_REMANT.

ITEM-SHORT_TEXT = V_RDESC.

ITEM-PLANT = ZMMHGAGREMENT-PPLANT.

ITEM-QUANTITY = V_RMENGE.

ITEM-PO_UNIT = V_RMEINS.

ITEM-NET_PRICE = ZPPPRDPOLICY-RRATE."ZMMHGAGREMENT-NETPR.

ITEM-BATCH = ZMMHGAGREMENT-BATCH.

ITEM-TAX_CODE = 'V0'.

ITEM-INFO_UPD = ' '.

APPEND ITEM.

ITEMX-PO_ITEM = '20'.

ITEMX-PO_ITEMX = 'X'.

ITEMX-SHORT_TEXT = 'X'.

ITEMX-MATERIAL = 'X'.

ITEMX-PLANT = 'X'.

ITEMX-QUANTITY = 'X'.

ITEMX-PO_UNIT = 'X'.

ITEMX-NET_PRICE = 'X'.

ITEMX-BATCH = 'x'.

ITEMX-TAX_CODE = 'X'.

ITEMX-INFO_UPD = 'X'.

APPEND ITEMX.

*ZPAYMENT-PAYMENT

*SCHEDULE

SCHEDULE-PO_ITEM = '20'.

SCHEDULE-DELIVERY_DATE = ZMMHGAGREMENT-RDATE.

SCHEDULE-QUANTITY = V_RMENGE.

APPEND SCHEDULE.

SCHEDULEX-PO_ITEM = '20'.

SCHEDULEX-PO_ITEMX = 'X'.

SCHEDULEX-DELIVERY_DATE = 'X'.

SCHEDULEX-QUANTITY = 'X'.

APPEND SCHEDULEX.

  • CONDITIONS

CONDITION-ITM_NUMBER = '20'.

CONDITION-COND_TYPE = 'P001'.

CONDITION-COND_VALUE = ZPPPRDPOLICY-RRATE.

CONDITION-CURRENCY = 'INR'.

APPEND CONDITION.

CONDITIONX-ITM_NUMBER = '20'.

CONDITIONX-ITM_NUMBERX = 'X'.

CONDITIONX-COND_TYPE = 'X'.

CONDITIONX-COND_VALUE = 'X'.

CONDITIONX-CURRENCY = 'X'.

APPEND CONDITIONX.

ENDIF.

ENDIF.

  • FOR PARTNER FUNCTION

POPARTNER-PARTNERDESC = 'VN'.

POPARTNER-LANGU = 'EN' .

POPARTNER-BUSPARTNO = ZMMHGAGREMENT-GNUMBER.

APPEND POPARTNER.

POPARTNER-PARTNERDESC = 'PI'.

POPARTNER-LANGU = 'EN' .

IF ZPAYMENT-PAYMENT = '1'. "V_PAYMENT = '1'. ".

POPARTNER-BUSPARTNO = ZMMHGAGREMENT-ONUMBER.

ELSE.

POPARTNER-BUSPARTNO = ZMMHGAGREMENT-GNUMBER.

ENDIF.

APPEND POPARTNER.

*BREAK SAPUSER..

CALL FUNCTION 'BAPI_PO_CREATE1'

EXPORTING

POHEADER = HEAD

POHEADERX = HEADX

  • POADDRVENDOR =

  • TESTRUN =

IMPORTING

EXPPURCHASEORDER = I_PNO

  • EXPHEADER =

  • EXPPOEXPIMPHEADER =

TABLES

RETURN = RETURNS

POITEM = ITEM

POITEMX = ITEMX

  • POADDRDELIVERY =

POSCHEDULE = SCHEDULE

POSCHEDULEX = SCHEDULEX

POCONDHEADER = CONDITION

POCONDHEADERX = CONDITIONX

POPARTNER = POPARTNER.

  • POCOND =

  • POCONDX =

  • POLIMITS =

.

IF NOT I_PNO IS INITIAL.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

ELSE.

LOOP AT RETURNS WHERE TYPE = 'E'..

IT_WRITE-MESSAGE = RETURNS-MESSAGE.

APPEND IT_WRITE.

ENDLOOP.