Skip to Content
avatar image
Former Member

Populate all Header level texts using Bapi_po_create1

Hi,

I am trying to create a po with all the header text using bapi_po_create1.but the problem is I am not able to update the loop for all hedaer text after uploading all text files .The itab only screens the lase value.Due to the same I got purchase order created without the header text.

Kindly reply with sample code.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • avatar image
    Former Member
    Sep 20, 2008 at 05:52 AM

    Place paste your code here for review.

    Enjoy SAP.

    Pankaj Singh

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 20, 2008 at 06:16 AM

    My code is as below.

    DATA: BEGIN OF ITAB OCCURS 0,

    BSART LIKE EKKO-BSART,

    EKORG LIKE EKKO-EKORG,

    EKGRP LIKE EKKO-EKGRP,

    BUKRS TYPE EKKO-BUKRS,

    VENDOR LIKE LFA1-LIFNR,

    ZTERM LIKE EKKO-ZTERM,

    WAERS LIKE EKKO-WAERS,

    ZBD1T LIKE EKKO-ZBD1T,

    EMATN LIKE EKPO-EMATN,

    NETPR LIKE EKPO-NETPR,

    PLANT LIKE EKPO-WERKS,

    MENGE LIKE EKPO-MENGE,

    AFNAM LIKE EKPO-AFNAM,

    BEDNR LIKE EKPO-BEDNR,

    REPOS LIKE EKPO-REPOS,

    TAX_CODE LIKE EKPO-MWSKZ,

    TXJCD LIKE EKPO-TXJCD,

    EEIND(10) TYPE C,

    PR LIKE EBAN-BANFN,

    PRITEM LIKE EBAN-BNFPO,

    END OF ITAB.

    • POPULATING HEADER TEXT DATA

    DATA : BEGIN OF ITAB1 OCCURS 0 ,

    POHEADERTEXT LIKE BAPIMEPOTEXTHEADER-TEXT_LINE,

    POHEADERNOTE LIKE BAPIMEPOTEXTHEADER-TEXT_LINE,

    PO_NUMBER LIKE BAPIMEPOTEXTHEADER-PO_NUMBER,

    TEXT_ID LIKE BAPIMEPOTEXTHEADER-TEXT_ID,

    TEXT_FORM LIKE BAPIMEPOTEXTHEADER-TEXT_FORM,

    TEXT_LINE LIKE BAPIMEPOTEXTHEADER-TEXT_LINE,

    END OF ITAB1.

    DATA : BEGIN OF ITAB2 OCCURS 0 ,

    POHEADERTEXT LIKE BAPIMEPOTEXTHEADER-TEXT_LINE,

    POHEADERNOTE LIKE BAPIMEPOTEXTHEADER-TEXT_LINE,

    PO_NUMBER LIKE BAPIMEPOTEXTHEADER-PO_NUMBER,

    TEXT_ID LIKE BAPIMEPOTEXTHEADER-TEXT_ID,

    TEXT_FORM LIKE BAPIMEPOTEXTHEADER-TEXT_FORM,

    TEXT_LINE LIKE BAPIMEPOTEXTHEADER-TEXT_LINE,

    END OF ITAB2.

    • DATA : BEGIN OF ITAB2 OCURS 10,

    • POHEADERTEXT LIKE BAPIMEPOTEXTHEADER,

    • POHEADERNOTE LIKE BAPIMEPOTEXTHEADER,

    • POPRICINGTYPE LIKE BAPIMEPOTEXTHEADER-TEXT_LINE,

    • PODELTERMS LIKE BAPIMEPOTEXTHEADER-TEXT_LINE,

    • POPAYTERMS LIKE BAPIMEPOTEXTHEADER-TEXT_LINE,

    • END OF ITAB2.

    DATA: HEADER LIKE BAPIMEPOHEADER, " Header

    HEADER_IND LIKE BAPIMEPOHEADERX, " Header index

    PO_ITEMS LIKE BAPIMEPOITEM OCCURS 0 WITH HEADER LINE, " Item table

    ITEMS_IND LIKE BAPIMEPOITEMX OCCURS 0 WITH HEADER LINE, " Item index table

    • POHEADERTEXT LIKE BAPIMEPOTEXTHEADER,

    *

    • POHEADERNOTE LIKE BAPIMEPOTEXTHEADER,

    • POTEXT LIKE BAPIMEPOTEXTHEADER OCCURS 10 WITH HEADER LINE, " BAPI PO TEXT TABLE.

    *

    • PONOTES LIKE BAPIMEPOTEXTHEADER OCCURS 10 WITH HEADER LINE,

    Return LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE . " Message Return table

    *Structures to hold PO account data

    DATA : ACCOUNT LIKE BAPIMEPOACCOUNT OCCURS 0 WITH HEADER LINE ,

    ACCOUNTX LIKE BAPIMEPOACCOUNTX OCCURS 0 WITH HEADER LINE .

    *Structures to hold PO schedule data

    DATA : ITEMSCHEDULE LIKE BAPIMEPOSCHEDULE OCCURS 0 WITH HEADER LINE ,

    ITEMSCHEDULEX LIKE BAPIMEPOSCHEDULX OCCURS 0 WITH HEADER LINE .

    *Structures to hold PO services data

    DATA : SERVICES LIKE BAPIESLLC OCCURS 0 WITH HEADER LINE .

    DATA : CTR type N .

    *--


    GETTING FLAT FILE DATA----

    CALL FUNCTION 'WS_UPLOAD'

    EXPORTING

    FILENAME = FNAME

    FILETYPE = 'DAT'

    TABLES

    data_tab = ITAB

    EXCEPTIONS

    CONVERSION_ERROR = 1

    FILE_OPEN_ERROR = 2

    FILE_READ_ERROR = 3

    INVALID_TYPE = 4

    NO_BATCH = 5

    UNKNOWN_ERROR = 6

    INVALID_TABLE_WIDTH = 7

    GUI_REFUSE_FILETRANSFER = 8

    CUSTOMER_ERROR = 9

    NO_AUTHORITY = 10

    OTHERS = 11.

    SUBRC = SY-SUBRC.

    IF SUBRC = 2.

    PODATAFILE = ' ERROR IN FLAT FILE...CHECKED THE FILENAME,PATH.'.

    ELSEIF SUBRC EQ 0.

    PODATAFILE = 'Successfully Uploaded the Flat File into Structure ITAB ..'.

    • *------ -GETTING FLAT FILE HEADER Text DATA ----

    ITAB1-TEXT_ID = 'F01'.

    • IF ITAB1-TEXT_ID = 'F01'.

    CALL FUNCTION 'WS_UPLOAD'

    EXPORTING

    FILENAME = FNAME1

    FILETYPE = 'DAT'

    TABLES

    data_tab = ITAB1

    EXCEPTIONS

    CONVERSION_ERROR = 1

    FILE_OPEN_ERROR = 2

    FILE_READ_ERROR = 3

    INVALID_TYPE = 4

    NO_BATCH = 5

    UNKNOWN_ERROR = 6

    INVALID_TABLE_WIDTH = 7

    GUI_REFUSE_FILETRANSFER = 8

    CUSTOMER_ERROR = 9

    NO_AUTHORITY = 10

    OTHERS = 11.

    SUBRC = SY-SUBRC.

    IF SUBRC = 2.

    POHEADERTEXT = ' ERROR IN FLAT FILE...CHECKED THE FILENAME,PATH.'.

    ELSEIF SUBRC EQ 0.

    POHEADERTEXT = 'Successfully Uploaded the Flat File into Structure ITAB1 ..'.

    ITAB2-TEXT_ID = 'F01'.

    ITAB2-TEXT_LINE = ITAB1-POHEADERTEXT.

    ITAB2-TEXT_FORM = '/'.

    APPEND itab2.

    • MOVE : ITAB1-TEXT_ID TO ITAB2-TEXT_ID,

    • ITAB1-TEXT_LINE TO ITAB2-POHEADERTEXT,

    • ITAB1-TEXT_FORM TO ITAB2-

    ENDIF.

    • *------ -GETTING FLAT FILE HEADER NOTE DATA ----

    ITAB1-TEXT_ID = 'F02'.

    • ELSEIF ITAB1-TEXT_ID = 'F02'.

    refresh itab1.

    CALL FUNCTION 'WS_UPLOAD'

    EXPORTING

    FILENAME = FNAME2

    FILETYPE = 'DAT'

    TABLES

    data_tab = ITAB1

    EXCEPTIONS

    CONVERSION_ERROR = 1

    FILE_OPEN_ERROR = 2

    FILE_READ_ERROR = 3

    INVALID_TYPE = 4

    NO_BATCH = 5

    UNKNOWN_ERROR = 6

    INVALID_TABLE_WIDTH = 7

    GUI_REFUSE_FILETRANSFER = 8

    CUSTOMER_ERROR = 9

    NO_AUTHORITY = 10

    OTHERS = 11.

    SUBRC = SY-SUBRC.

    IF SUBRC = 2.

    POHEADERNOTE = ' ERROR IN FLAT FILE...CHECKED THE FILENAME,PATH.'.

    ELSEIF SUBRC EQ 0.

    POHEADERNOTE = 'Successfully Uploaded the Flat File into Structure ITAB1 ..'.

    ITAB1-TEXT_ID = 'F02'.

    ITAB1-TEXT_LINE = ITAB1-POHEADERNOTE.

    ITAB2-TEXT_ID = 'F02'.

    ITAB2-TEXT_LINE = 'hi yyyy'. "ITAB1-POHEADERTEXT.

    ITAB2-TEXT_FORM = '/'.

    ITAB2-TEXT_LINE = ITAB1-POHEADERNOTE.

    APPEND ITAB2.

    • ENDIF.

    ELSE.

    • LOOP AT ITAB1.

    • WRITE : / ITAB1-POHEADERTEXT.

    • ENDLOOP.

    *

    Endif.

    ENDIF.

    LOOP AT ITAB.

    • Initialize Header values

    HEADER-VENDOR = ITAB-VENDOR.

    HEADER-COMP_CODE = ITAB-BUKRS.

    HEADER-PURCH_ORG = ITAB-EKORG.

    HEADER-PUR_GROUP = ITAB-EKGRP.

    HEADER-DOC_TYPE = ITAB-BSART.

    HEADER-CURRENCY = ITAB-WAERS.

    HEADER-PMNTTRMS = ITAB-ZTERM.

    • Initialize Index values

    HEADER_IND-DOC_TYPE = 'X'.

    HEADER_IND-COMP_CODE = 'X'.

    HEADER_IND-VENDOR = 'X'.

    HEADER_IND-PURCH_ORG = 'X'.

    HEADER_IND-PUR_GROUP = 'X'.

    HEADER_IND-CURRENCY = 'X'.

    HEADER_IND-PMNTTRMS = 'X'.

    ***Initialize Item values

    PO_ITEMS-PO_ITEM = '10'.

    PO_ITEMS-MATERIAL = ITAB-EMATN.

    PO_ITEMS-PLANT = ITAB-PLANT.

    PO_ITEMS-QUANTITY = ITAB-MENGE.

    PO_ITEMS-NET_PRICE = ITAB-NETPR.

    PO_ITEMS-PREQ_NAME = ITAB-AFNAM.

    PO_ITEMS-TRACKINGNO = ITAB-BEDNR.

    PO_ITEMS-TAX_CODE = ITAB-TAX_CODE.

    PO_ITEMS-TAXJURCODE = ITAB-TXJCD.

    PO_ITEMS-PREQ_NO = ITAB-PR.

    PO_ITEMS-PREQ_ITEM = ITAB-PRITEM.

    APPEND PO_ITEMS.

    **

    ***Initialize Item index values

    ITEMS_IND-PO_ITEM = '10'.

    ITEMS_IND-MATERIAL = 'X'.

    ITEMS_IND-PLANT = 'X'.

    ITEMS_IND-QUANTITY = 'X'.

    ITEMS_IND-NET_PRICE = ITAB-NETPR.

    ITEMS_IND-PREQ_NAME = ITAB-AFNAM.

    ITEMS_IND-TRACKINGNO = ITAB-BEDNR.

    ITEMS_IND-TAX_CODE = ITAB-TAX_CODE.

    ITEMS_IND-TAXJURCODE = ITAB-TXJCD.

    ITEMS_IND-PREQ_NO = ITAB-PR.

    ITEMS_IND-PREQ_ITEM = ITAB-PRITEM.

    APPEND ITEMS_IND.

    • Initialize PO Account values

    ACCOUNT-PO_ITEM = CTR.

    ACCOUNT-QUANTITY = CTR.

    ACCOUNT-NET_VALUE = ITAB-NETPR.

    ACCOUNT-GL_ACCOUNT = CTR.

    ACCOUNT-BUS_AREA = CTR.

    account-costcenter = CTR.

    APPEND ACCOUNT.

    LOOP AT ITAB2.

    • * PO HEADER TEXT

    ITAB2-PO_NUMBER = HEADER-po_number.

    *ITAB1-TEXT_ID = 'F01'.

    ITAB2-TEXT_FORM = '/'.

    *ITAB1-TEXT_LINE = ITAB1-POHEADERTEXT.

    ***Create Production order

    CALL FUNCTION 'BAPI_PO_CREATE1'

    EXPORTING

    POHEADER = HEADER

    POHEADERX = HEADER_IND

    • POADDRVENDOR =

    • TESTRUN =

    • MEMORY_UNCOMPLETE =

    • MEMORY_COMPLETE =

    • POEXPIMPHEADER =

    • POEXPIMPHEADERX =

    • VERSIONS =

    • NO_MESSAGING =

    • NO_MESSAGE_REQ =

    • NO_AUTHORITY =

    NO_PRICE_FROM_PO = 'X'

    • IMPORTING

    • EXPPURCHASEORDER =

    • EXPHEADER =

    • EXPPOEXPIMPHEADER =

    TABLES

    RETURN = RETURN

    POITEM = PO_ITEMS

    POITEMX = ITEMS_IND

    • POADDRDELIVERY =

    • POSCHEDULE =

    • POSCHEDULEX =

    • POACCOUNT = ACCOUNT

    • POACCOUNTPROFITSEGMENT =

    • POACCOUNTX =

    • POCONDHEADER =

    • POCONDHEADERX =

    • POCOND =

    • POCONDX =

    • POLIMITS =

    • POCONTRACTLIMITS =

    • POSERVICES =

    • POSRVACCESSVALUES =

    • POSERVICESTEXT =

    • EXTENSIONIN =

    • EXTENSIONOUT =

    • POEXPIMPITEM =

    • POEXPIMPITEMX =

    POTEXTHEADER = ITAB2.

    .

    • Commit BAPI

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

    EXPORTING

    WAIT = 'X'.

    READ TABLE RETURN WITH KEY TYPE = 'S'.

    If SY-SUBRC EQ 0.

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

    • WITH Return.

    *

    PO = RETURN-MESSAGE.

    ELSEIF SY-SUBRC <> 0.

    READ TABLE RETURN WITH KEY TYPE = 'E'.

    RET = RETURN-MESSAGE.

    PO = 'PURCHASE ORDER HAS NOT BEEN CREATED :'.

    ELSE.

    PO = 'ERROR OCCUR .....PURCHASE ORDER HAS NOT BEEN CREATED...'.

    ENDIF.

    ENDLOOP.

    Endloop.

    *WRITE : / ITAB1-TEXT_LINE,

    • ITAB1-TEXT_LINE.

    ENDFUNCTION.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 20, 2008 at 10:38 AM

    Hi,

    I am having some query regarding the po creation using BAPI_PO_CREATE1.I want to create a purchase order with all the header level text .For the same I successfully uploaded three flat files using FM ws_upload for po data, header text,& header note respectively and passes the internal table to BAPI ,here I get po number without the header text .When I debug the code I noticed that the internal table for po text parameters are overwritten by the last row.

    Kindly check the below mention code .

    DATA: BEGIN OF ITAB OCCURS 0,

    BSART LIKE EKKO-BSART,

    EKORG LIKE EKKO-EKORG,

    EKGRP LIKE EKKO-EKGRP,

    BUKRS TYPE EKKO-BUKRS,

    VENDOR LIKE LFA1-LIFNR,

    ZTERM LIKE EKKO-ZTERM,

    WAERS LIKE EKKO-WAERS,

    ZBD1T LIKE EKKO-ZBD1T,

    EMATN LIKE EKPO-EMATN,

    NETPR LIKE EKPO-NETPR,

    PLANT LIKE EKPO-WERKS,

    MENGE LIKE EKPO-MENGE,

    AFNAM LIKE EKPO-AFNAM,

    BEDNR LIKE EKPO-BEDNR,

    REPOS LIKE EKPO-REPOS,

    TAX_CODE LIKE EKPO-MWSKZ,

    TXJCD LIKE EKPO-TXJCD,

    EEIND(10) TYPE C,

    PR LIKE EBAN-BANFN,

    PRITEM LIKE EBAN-BNFPO,

    END OF ITAB.

    • POPULATING HEADER TEXT DATA

    DATA : BEGIN OF ITAB1 OCCURS 0 ,

    PO LIKE BAPIMEPOTEXTHEADER-PO_NUMBER,

    ITEM LIKE BAPIMEPOTEXTHEADER-PO_ITEM,

    TEXT_ID LIKE BAPIMEPOTEXTHEADER-TEXT_ID,

    TEXT_FORM LIKE BAPIMEPOTEXTHEADER-TEXT_FORM,

    TEXT_LINE LIKE BAPIMEPOTEXTHEADER-TEXT_LINE,

    END OF ITAB1.

    DATA: HEADER LIKE BAPIMEPOHEADER, " Header

    HEADER_IND LIKE BAPIMEPOHEADERX, " Header index

    PO_ITEMS LIKE BAPIMEPOITEM OCCURS 0 WITH HEADER LINE, " Item table

    ITEMS_IND LIKE BAPIMEPOITEMX OCCURS 0 WITH HEADER LINE, " Item index table

    POTEXT LIKE BAPIMEPOTEXTHEADER OCCURS 10 WITH HEADER LINE, " BAPI PO TEXT TABLE.

    PONOTE LIKE BAPIMEPOTEXTHEADER OCCURS 10 WITH HEADER LINE,

    Return LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE . " Message Return table

    *Structures to hold PO account data

    DATA : ACCOUNT LIKE BAPIMEPOACCOUNT OCCURS 0 WITH HEADER LINE ,

    ACCOUNTX LIKE BAPIMEPOACCOUNTX OCCURS 0 WITH HEADER LINE .

    *Structures to hold PO schedule data

    DATA : ITEMSCHEDULE LIKE BAPIMEPOSCHEDULE OCCURS 0 WITH HEADER LINE ,

    ITEMSCHEDULEX LIKE BAPIMEPOSCHEDULX OCCURS 0 WITH HEADER LINE .

    *Structures to hold PO services data

    DATA : SERVICES LIKE BAPIESLLC OCCURS 0 WITH HEADER LINE .

    DATA : CTR type N .

    *--


    GETTING FLAT FILE DATA----

    CALL FUNCTION 'WS_UPLOAD'

    EXPORTING

    FILENAME = FNAME

    FILETYPE = 'DAT'

    TABLES

    data_tab = ITAB

    EXCEPTIONS

    CONVERSION_ERROR = 1

    FILE_OPEN_ERROR = 2

    FILE_READ_ERROR = 3

    INVALID_TYPE = 4

    NO_BATCH = 5

    UNKNOWN_ERROR = 6

    INVALID_TABLE_WIDTH = 7

    GUI_REFUSE_FILETRANSFER = 8

    CUSTOMER_ERROR = 9

    NO_AUTHORITY = 10

    OTHERS = 11.

    SUBRC = SY-SUBRC.

    IF SUBRC = 2.

    PODATAFILE = ' ERROR IN FLAT FILE...CHECKED THE FILENAME,PATH.'.

    ELSEIF SUBRC EQ 0.

    PODATAFILE = 'Successfully Uploaded the Flat File into Structure ITAB ..'.

    • *------ -GETTING FLAT FILE HEADER Text DATA ----

    CALL FUNCTION 'WS_UPLOAD'

    EXPORTING

    FILENAME = FNAME1

    FILETYPE = 'DAT'

    TABLES

    data_tab = POTEXT

    EXCEPTIONS

    CONVERSION_ERROR = 1

    FILE_OPEN_ERROR = 2

    FILE_READ_ERROR = 3

    INVALID_TYPE = 4

    NO_BATCH = 5

    UNKNOWN_ERROR = 6

    INVALID_TABLE_WIDTH = 7

    GUI_REFUSE_FILETRANSFER = 8

    CUSTOMER_ERROR = 9

    NO_AUTHORITY = 10

    OTHERS = 11.

    SUBRC = SY-SUBRC.

    IF SUBRC = 2.

    POHEADERTEXT = ' ERROR IN FLAT FILE...CHECKED THE FILENAME,PATH.'.

    ELSEIF SUBRC EQ 0.

    POHEADERTEXT = 'Successfully Uploaded the Flat File into Structure ITAB1 ..'.

    APPEND POTEXT.

    ELSE.

    ENDIF.

    clear ctr.

    ctr = ctr + 1.

    Endif.

    • *------ -GETTING FLAT FILE HEADER NOTE DATA ----

    CALL FUNCTION 'WS_UPLOAD'

    EXPORTING

    FILENAME = FNAME1

    FILETYPE = 'DAT'

    TABLES

    data_tab = PONOTE

    EXCEPTIONS

    CONVERSION_ERROR = 1

    FILE_OPEN_ERROR = 2

    FILE_READ_ERROR = 3

    INVALID_TYPE = 4

    NO_BATCH = 5

    UNKNOWN_ERROR = 6

    INVALID_TABLE_WIDTH = 7

    GUI_REFUSE_FILETRANSFER = 8

    CUSTOMER_ERROR = 9

    NO_AUTHORITY = 10

    OTHERS = 11.

    SUBRC = SY-SUBRC.

    IF SUBRC = 2.

    POHEADERNOTE = ' ERROR IN FLAT FILE...CHECKED THE FILENAME,PATH.'.

    ELSEIF SUBRC EQ 0.

    POHEADERNOTE = 'Successfully Uploaded the Flat File into Structure ITAB1 ..'.

    APPEND ponote.

    ELSE.

    ENDIF.

    LOOP AT ITAB.

    • Initialize Header values

    HEADER-VENDOR = ITAB-VENDOR.

    HEADER-COMP_CODE = ITAB-BUKRS.

    HEADER-PURCH_ORG = ITAB-EKORG.

    HEADER-PUR_GROUP = ITAB-EKGRP.

    HEADER-DOC_TYPE = ITAB-BSART.

    HEADER-CURRENCY = ITAB-WAERS.

    HEADER-PMNTTRMS = ITAB-ZTERM.

    • Initialize Index values

    HEADER_IND-DOC_TYPE = 'X'.

    HEADER_IND-COMP_CODE = 'X'.

    HEADER_IND-VENDOR = 'X'.

    HEADER_IND-PURCH_ORG = 'X'.

    HEADER_IND-PUR_GROUP = 'X'.

    HEADER_IND-CURRENCY = 'X'.

    HEADER_IND-PMNTTRMS = 'X'.

    ***Initialize Item values

    PO_ITEMS-PO_ITEM = CTR.

    PO_ITEMS-MATERIAL = ITAB-EMATN.

    PO_ITEMS-PLANT = ITAB-PLANT.

    PO_ITEMS-QUANTITY = ITAB-MENGE.

    PO_ITEMS-NET_PRICE = ITAB-NETPR.

    PO_ITEMS-PREQ_NAME = ITAB-AFNAM.

    PO_ITEMS-TRACKINGNO = ITAB-BEDNR.

    PO_ITEMS-TAX_CODE = ITAB-TAX_CODE.

    PO_ITEMS-TAXJURCODE = ITAB-TXJCD.

    PO_ITEMS-PREQ_NO = ITAB-PR.

    PO_ITEMS-PREQ_ITEM = ITAB-PRITEM.

    APPEND PO_ITEMS.

    **

    ***Initialize Item index values

    ITEMS_IND-PO_ITEM = CTR.

    ITEMS_IND-MATERIAL = 'X'.

    ITEMS_IND-PLANT = 'X'.

    ITEMS_IND-QUANTITY = 'X'.

    ITEMS_IND-NET_PRICE = ITAB-NETPR.

    ITEMS_IND-PREQ_NAME = ITAB-AFNAM.

    ITEMS_IND-TRACKINGNO = ITAB-BEDNR.

    ITEMS_IND-TAX_CODE = ITAB-TAX_CODE.

    ITEMS_IND-TAXJURCODE = ITAB-TXJCD.

    ITEMS_IND-PREQ_NO = ITAB-PR.

    ITEMS_IND-PREQ_ITEM = ITAB-PRITEM.

    APPEND ITEMS_IND.

    • Initialize PO Account values

    ACCOUNT-PO_ITEM = CTR.

    ACCOUNT-QUANTITY = CTR.

    ACCOUNT-NET_VALUE = ITAB-NETPR.

    ACCOUNT-GL_ACCOUNT = CTR.

    ACCOUNT-BUS_AREA = CTR.

    account-costcenter = CTR.

    APPEND ACCOUNT.

    • * PO HEADER TEXT

    ITAB1-PO = HEADER-po_number.

    ITAB1-ITEM = PO_ITEMS-PO_ITEM.

    ITAB1-TEXT_ID = 'F01'.

    ITAB1-TEXT_FORM = '/'.

    ITAB1-TEXT_LINE = POTEXT.

    COLLECT ITAB1.

    *PO HEADER NOTE

    ITAB1-PO = HEADER-po_number.

    ITAB1-ITEM = PO_ITEMS-PO_ITEM.

    ITAB1-TEXT_ID = 'F02'.

    ITAB1-TEXT_FORM = '/'.

    ITAB1-TEXT_LINE = PONOTE.

    COLLECT ITAB1.

    LOOP AT ITAB1.

    WRITE : / ITAB1-TEXT_ID,

    ITAB1-TEXT_LINE.

    ENDLOOP.

    • PO PRICING TYPE

    *POTEXT-PO_NUMBER = HEADER-po_number.

    *POTEXT-TEXT_ID = 'F03'.

    *POTEXT-TEXT_FORM = '/'.

    *POTEXT-TEXT_LINE = ITAB1-POPRICINGTYPE.

    *

    • PO DELIVERY TERMS

    *POTEXT-PO_NUMBER = HEADER-po_number.

    *POTEXT-TEXT_ID = 'F05'.

    *POTEXT-TEXT_FORM = '/'.

    *POTEXT-TEXT_LINE = ITAB1-PODELTERMS.

    • PO PAYMENT TERMS

    *POTEXT-PO_NUMBER = HEADER-po_number.

    *POTEXT-TEXT_ID = 'F07'.

    *POTEXT-TEXT_FORM = '/'.

    *POTEXT-TEXT_LINE = ITAB1-POPAYTERMS.

    ***Create Production order

    LOOP AT ITAB1.

    CALL FUNCTION 'BAPI_PO_CREATE1'

    EXPORTING

    POHEADER = HEADER

    POHEADERX = HEADER_IND

    NO_PRICE_FROM_PO = 'X'

    TABLES

    RETURN = RETURN

    POITEM = PO_ITEMS

    POITEMX = ITEMS_IND

    POACCOUNT = ACCOUNT

    POTEXTHEADER = ITAB1.

    CTR = CTR + 1.

    ENDLOOP.

    • Commit BAPI

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

    EXPORTING

    WAIT = 'X'.

    READ TABLE RETURN WITH KEY TYPE = 'S'.

    If SY-SUBRC EQ 0.

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

    • WITH Return.

    *

    PO = RETURN-MESSAGE.

    ELSEIF SY-SUBRC <> 0.

    READ TABLE RETURN WITH KEY TYPE = 'E'.

    RET = RETURN-MESSAGE.

    PO = 'PURCHASE ORDER HAS NOT BEEN CREATED :'.

    ELSE.

    PO = 'ERROR OCCUR .....PURCHASE ORDER HAS NOT BEEN CREATED...'.

    ENDIF.

    ENDLOOP.

    ENDFUNCTION.

    Edited by: Anand Ramaiya on Sep 20, 2008 12:40 PM

    Add comment
    10|10000 characters needed characters exceeded