Skip to Content
author's profile photo Former Member
Former Member

BAPI

Plz anyone give me a simple BAPI pogram to understand abt how BAPI works

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Posted on Dec 03, 2007 at 06:03 AM

    Hi mahesh,

    try this one...

    here im creating purchase order using BAPI.

    REPORT ZGPO_CREATION_BAPI.

    DATA : GT_HEADER TYPE STANDARD TABLE OF BAPIMEPOHEADER,

    GW_HEADER TYPE BAPIMEPOHEADER,

    GT_HEADERX TYPE STANDARD TABLE OF BAPIMEPOHEADERX,

    GW_HEADERX TYPE BAPIMEPOHEADERX,

    GT_ITEM TYPE STANDARD TABLE OF BAPIMEPOITEM,

    GW_ITEM TYPE BAPIMEPOITEM,

    GT_ITEMX TYPE STANDARD TABLE OF BAPIMEPOITEMX,

    GW_ITEMX TYPE BAPIMEPOITEMX,

    GT_RETURN TYPE STANDARD TABLE OF BAPIRET2,

    GW_RETURN TYPE BAPIRET2,

    GW_LANGU TYPE SY-LANGU,

    A TYPE BAPIRET2,

    V_PONUMBER TYPE BAPIMEPOHEADER-PO_NUMBER. " Internal table and work area declaration for PO header and PO item

    TYPES:BEGIN OF PO_STR,

    COMPANY TYPE BAPIMEPOHEADER-COMP_CODE,

    DOCTYPE TYPE BAPIMEPOHEADER-DOC_TYPE,

    CDATE TYPE BAPIMEPOHEADER-CREAT_DATE,

    VENDOR TYPE BAPIMEPOHEADER-VENDOR,

    PUR_ORG TYPE BAPIMEPOHEADER-PURCH_ORG,

    PUR_GRP TYPE BAPIMEPOHEADER-PUR_GROUP,

    ITEM_NUM TYPE BAPIMEPOITEM-PO_ITEM,

    MATERIAL TYPE BAPIMEPOITEM-MATERIAL,

    PLANT TYPE BAPIMEPOITEM-PLANT,

    QUANTITY(13) TYPE C,

    END OF PO_STR. "Structure declaration

    DATA :GT_POSTR TYPE STANDARD TABLE OF PO_STR,

    GW_POSTR TYPE PO_STR,

    V_PATH TYPE STRING. "Local internal table and work area declaration

    CONSTANTS: C_X TYPE C VALUE 'X'.

    PARAMETERS FILEPATH TYPE IBIPPARMS-PATH OBLIGATORY DEFAULT 'D:\Guna\desktop\Sample_BAPI_PO_Creation.txt'.

    AT SELECTION-SCREEN ON VALUE-REQUEST FOR FILEPATH.

    PERFORM GETFILEPATH USING FILEPATH.

    START-OF-SELECTION. "Start-of-selection event is triggered

    V_PATH = FILEPATH.

    PERFORM UPLOAD.

    GW_LANGU = SY-LANGU.

    LOOP AT GT_POSTR INTO GW_POSTR.

    *READ TABLE GT_POSTR INTO GW_POSTR INDEX 1.

    GW_HEADER-COMP_CODE = GW_POSTR-COMPANY .

    GW_HEADER-DOC_TYPE = GW_POSTR-DOCTYPE.

    GW_HEADER-CREAT_DATE = GW_POSTR-CDATE .

    GW_HEADER-VENDOR = GW_POSTR-VENDOR.

    GW_HEADER-LANGU = GW_LANGU.

    GW_HEADER-PURCH_ORG = GW_POSTR-PUR_ORG.

    GW_HEADER-PUR_GROUP = GW_POSTR-PUR_GRP.

    GW_HEADERX-COMP_CODE = C_X.

    GW_HEADERX-DOC_TYPE = C_X.

    GW_HEADERX-CREAT_DATE = C_X .

    GW_HEADERX-VENDOR = C_X.

    GW_HEADERX-LANGU = C_X.

    GW_HEADERX-PURCH_ORG = C_X.

    GW_HEADERX-PUR_GROUP = C_X.

    GW_ITEM-PO_ITEM = GW_POSTR-ITEM_NUM.

    GW_ITEM-MATERIAL = GW_POSTR-MATERIAL .

    GW_ITEM-PLANT = GW_POSTR-PLANT.

    GW_ITEM-QUANTITY = GW_POSTR-QUANTITY.

    APPEND GW_ITEM TO GT_ITEM.

    GW_ITEMX-PO_ITEM = GW_POSTR-ITEM_NUM.

    GW_ITEMX-MATERIAL = C_X .

    GW_ITEMX-PLANT = C_X.

    GW_ITEMX-QUANTITY = C_X.

    APPEND GW_ITEMX TO GT_ITEMX. "Assigning the flat file value to the work area

    CALL FUNCTION 'BAPI_PO_CREATE1'

    EXPORTING

    POHEADER = GW_HEADER

    POHEADERX = GW_HEADERX

    • POADDRVENDOR =

    • TESTRUN =

    • MEMORY_UNCOMPLETE =

    • MEMORY_COMPLETE =

    • POEXPIMPHEADER =

    • POEXPIMPHEADERX =

    • VERSIONS =

    • NO_MESSAGING =

    • NO_MESSAGE_REQ =

    • NO_AUTHORITY =

    • NO_PRICE_FROM_PO =

    IMPORTING

    EXPPURCHASEORDER = V_PONUMBER

    • EXPHEADER =

    • EXPPOEXPIMPHEADER =

    TABLES

    RETURN = GT_RETURN

    POITEM = GT_ITEM

    POITEMX = GT_ITEMX

    • POADDRDELIVERY =

    • POSCHEDULE =

    • POSCHEDULEX =

    • POACCOUNT =

    • POACCOUNTPROFITSEGMENT =

    • POACCOUNTX =

    • POCONDHEADER =

    • POCONDHEADERX =

    • POCOND =

    • POCONDX =

    • POLIMITS =

    • POCONTRACTLIMITS =

    • POSERVICES =

    • POSRVACCESSVALUES =

    • POSERVICESTEXT =

    • EXTENSIONIN =

    • EXTENSIONOUT =

    • POEXPIMPITEM =

    • POEXPIMPITEMX =

    • POTEXTHEADER =

    • POTEXTITEM =

    • ALLVERSIONS =

    • POPARTNER =

    • POCOMPONENTS =

    • POCOMPONENTSX =

    • POSHIPPING =

    • POSHIPPINGX =

    • POSHIPPINGEXP =

    . "BAPI PO creation function is called

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

    EXPORTING

    WAIT = 'X'

    IMPORTING

    RETURN = A

    .

    *COMMIT WORK .

    WRITE: V_PONUMBER.

    CLEAR : GT_RETURN, GW_ITEM,GW_ITEMX,GT_ITEM,GT_ITEMX,

    GW_HEADER,GW_HEADERX, V_PONUMBER. "All the work area is cleared

    ENDLOOP.

    *WRITE: V_PONUMBER.

    &----


    *& Form GETFILEPATH

    &----


    • text

    ----


    • -->P_FILEPATH text

    ----


    FORM GETFILEPATH USING P_FILEPATH.

    CALL FUNCTION 'F4_FILENAME'

    EXPORTING

    PROGRAM_NAME = SYST-CPROG

    DYNPRO_NUMBER = SYST-DYNNR

    IMPORTING

    FILE_NAME = FILEPATH

    .

    ENDFORM. " GETFILEPATH

    &----


    *& Form UPLOAD

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM UPLOAD .

    CALL FUNCTION 'GUI_UPLOAD'

    EXPORTING

    FILENAME = V_PATH

    • FILETYPE = 'ASC'

    • HAS_FIELD_SEPARATOR = ' '

    • HEADER_LENGTH = 0

    • READ_BY_LINE = 'X'

    • DAT_MODE = ' '

    • CODEPAGE = ' '

    • IGNORE_CERR = ABAP_TRUE

    • REPLACEMENT = '#'

    • CHECK_BOM = ' '

    • VIRUS_SCAN_PROFILE =

    • NO_AUTH_CHECK = ' '

    • IMPORTING

    • FILELENGTH =

    • HEADER =

    TABLES

    DATA_TAB = GT_POSTR

    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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

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

    ENDIF.

    ENDFORM. " UPLOADREPORT ZGPO_CREATION_BAPI.

    DATA : GT_HEADER TYPE STANDARD TABLE OF BAPIMEPOHEADER,

    GW_HEADER TYPE BAPIMEPOHEADER,

    GT_HEADERX TYPE STANDARD TABLE OF BAPIMEPOHEADERX,

    GW_HEADERX TYPE BAPIMEPOHEADERX,

    GT_ITEM TYPE STANDARD TABLE OF BAPIMEPOITEM,

    GW_ITEM TYPE BAPIMEPOITEM,

    GT_ITEMX TYPE STANDARD TABLE OF BAPIMEPOITEMX,

    GW_ITEMX TYPE BAPIMEPOITEMX,

    GT_RETURN TYPE STANDARD TABLE OF BAPIRET2,

    GW_RETURN TYPE BAPIRET2,

    GW_LANGU TYPE SY-LANGU,

    A TYPE BAPIRET2,

    V_PONUMBER TYPE BAPIMEPOHEADER-PO_NUMBER. " Internal table and work area declaration for PO header and PO item

    TYPES:BEGIN OF PO_STR,

    COMPANY TYPE BAPIMEPOHEADER-COMP_CODE,

    DOCTYPE TYPE BAPIMEPOHEADER-DOC_TYPE,

    CDATE TYPE BAPIMEPOHEADER-CREAT_DATE,

    VENDOR TYPE BAPIMEPOHEADER-VENDOR,

    PUR_ORG TYPE BAPIMEPOHEADER-PURCH_ORG,

    PUR_GRP TYPE BAPIMEPOHEADER-PUR_GROUP,

    ITEM_NUM TYPE BAPIMEPOITEM-PO_ITEM,

    MATERIAL TYPE BAPIMEPOITEM-MATERIAL,

    PLANT TYPE BAPIMEPOITEM-PLANT,

    QUANTITY(13) TYPE C,

    END OF PO_STR. "Structure declaration

    DATA :GT_POSTR TYPE STANDARD TABLE OF PO_STR,

    GW_POSTR TYPE PO_STR,

    V_PATH TYPE STRING. "Local internal table and work area declaration

    CONSTANTS: C_X TYPE C VALUE 'X'.

    PARAMETERS FILEPATH TYPE IBIPPARMS-PATH OBLIGATORY DEFAULT 'D:\Guna\desktop\Sample_BAPI_PO_Creation.txt'.

    AT SELECTION-SCREEN ON VALUE-REQUEST FOR FILEPATH.

    PERFORM GETFILEPATH USING FILEPATH.

    START-OF-SELECTION. "Start-of-selection event is triggered

    V_PATH = FILEPATH.

    PERFORM UPLOAD.

    GW_LANGU = SY-LANGU.

    LOOP AT GT_POSTR INTO GW_POSTR.

    *READ TABLE GT_POSTR INTO GW_POSTR INDEX 1.

    GW_HEADER-COMP_CODE = GW_POSTR-COMPANY .

    GW_HEADER-DOC_TYPE = GW_POSTR-DOCTYPE.

    GW_HEADER-CREAT_DATE = GW_POSTR-CDATE .

    GW_HEADER-VENDOR = GW_POSTR-VENDOR.

    GW_HEADER-LANGU = GW_LANGU.

    GW_HEADER-PURCH_ORG = GW_POSTR-PUR_ORG.

    GW_HEADER-PUR_GROUP = GW_POSTR-PUR_GRP.

    GW_HEADERX-COMP_CODE = C_X.

    GW_HEADERX-DOC_TYPE = C_X.

    GW_HEADERX-CREAT_DATE = C_X .

    GW_HEADERX-VENDOR = C_X.

    GW_HEADERX-LANGU = C_X.

    GW_HEADERX-PURCH_ORG = C_X.

    GW_HEADERX-PUR_GROUP = C_X.

    GW_ITEM-PO_ITEM = GW_POSTR-ITEM_NUM.

    GW_ITEM-MATERIAL = GW_POSTR-MATERIAL .

    GW_ITEM-PLANT = GW_POSTR-PLANT.

    GW_ITEM-QUANTITY = GW_POSTR-QUANTITY.

    APPEND GW_ITEM TO GT_ITEM.

    GW_ITEMX-PO_ITEM = GW_POSTR-ITEM_NUM.

    GW_ITEMX-MATERIAL = C_X .

    GW_ITEMX-PLANT = C_X.

    GW_ITEMX-QUANTITY = C_X.

    APPEND GW_ITEMX TO GT_ITEMX. "Assigning the flat file value to the work area

    CALL FUNCTION 'BAPI_PO_CREATE1'

    EXPORTING

    POHEADER = GW_HEADER

    POHEADERX = GW_HEADERX

    • POADDRVENDOR =

    • TESTRUN =

    • MEMORY_UNCOMPLETE =

    • MEMORY_COMPLETE =

    • POEXPIMPHEADER =

    • POEXPIMPHEADERX =

    • VERSIONS =

    • NO_MESSAGING =

    • NO_MESSAGE_REQ =

    • NO_AUTHORITY =

    • NO_PRICE_FROM_PO =

    IMPORTING

    EXPPURCHASEORDER = V_PONUMBER

    • EXPHEADER =

    • EXPPOEXPIMPHEADER =

    TABLES

    RETURN = GT_RETURN

    POITEM = GT_ITEM

    POITEMX = GT_ITEMX

    • POADDRDELIVERY =

    • POSCHEDULE =

    • POSCHEDULEX =

    • POACCOUNT =

    • POACCOUNTPROFITSEGMENT =

    • POACCOUNTX =

    • POCONDHEADER =

    • POCONDHEADERX =

    • POCOND =

    • POCONDX =

    • POLIMITS =

    • POCONTRACTLIMITS =

    • POSERVICES =

    • POSRVACCESSVALUES =

    • POSERVICESTEXT =

    • EXTENSIONIN =

    • EXTENSIONOUT =

    • POEXPIMPITEM =

    • POEXPIMPITEMX =

    • POTEXTHEADER =

    • POTEXTITEM =

    • ALLVERSIONS =

    • POPARTNER =

    • POCOMPONENTS =

    • POCOMPONENTSX =

    • POSHIPPING =

    • POSHIPPINGX =

    • POSHIPPINGEXP =

    . "BAPI PO creation function is called

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

    EXPORTING

    WAIT = 'X'

    IMPORTING

    RETURN = A

    .

    *COMMIT WORK .

    WRITE: V_PONUMBER.

    CLEAR : GT_RETURN, GW_ITEM,GW_ITEMX,GT_ITEM,GT_ITEMX,

    GW_HEADER,GW_HEADERX, V_PONUMBER. "All the work area is cleared

    ENDLOOP.

    *WRITE: V_PONUMBER.

    &----


    *& Form GETFILEPATH

    &----


    • text

    ----


    • -->P_FILEPATH text

    ----


    FORM GETFILEPATH USING P_FILEPATH.

    CALL FUNCTION 'F4_FILENAME'

    EXPORTING

    PROGRAM_NAME = SYST-CPROG

    DYNPRO_NUMBER = SYST-DYNNR

    IMPORTING

    FILE_NAME = FILEPATH

    .

    ENDFORM. " GETFILEPATH

    &----


    *& Form UPLOAD

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM UPLOAD .

    CALL FUNCTION 'GUI_UPLOAD'

    EXPORTING

    FILENAME = V_PATH

    • FILETYPE = 'ASC'

    • HAS_FIELD_SEPARATOR = ' '

    • HEADER_LENGTH = 0

    • READ_BY_LINE = 'X'

    • DAT_MODE = ' '

    • CODEPAGE = ' '

    • IGNORE_CERR = ABAP_TRUE

    • REPLACEMENT = '#'

    • CHECK_BOM = ' '

    • VIRUS_SCAN_PROFILE =

    • NO_AUTH_CHECK = ' '

    • IMPORTING

    • FILELENGTH =

    • HEADER =

    TABLES

    DATA_TAB = GT_POSTR

    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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

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

    ENDIF.

    ENDFORM. " UPLOADREPORT ZGPO_CREATION_BAPI.

    DATA : GT_HEADER TYPE STANDARD TABLE OF BAPIMEPOHEADER,

    GW_HEADER TYPE BAPIMEPOHEADER,

    GT_HEADERX TYPE STANDARD TABLE OF BAPIMEPOHEADERX,

    GW_HEADERX TYPE BAPIMEPOHEADERX,

    GT_ITEM TYPE STANDARD TABLE OF BAPIMEPOITEM,

    GW_ITEM TYPE BAPIMEPOITEM,

    GT_ITEMX TYPE STANDARD TABLE OF BAPIMEPOITEMX,

    GW_ITEMX TYPE BAPIMEPOITEMX,

    GT_RETURN TYPE STANDARD TABLE OF BAPIRET2,

    GW_RETURN TYPE BAPIRET2,

    GW_LANGU TYPE SY-LANGU,

    A TYPE BAPIRET2,

    V_PONUMBER TYPE BAPIMEPOHEADER-PO_NUMBER. " Internal table and work area declaration for PO header and PO item

    TYPES:BEGIN OF PO_STR,

    COMPANY TYPE BAPIMEPOHEADER-COMP_CODE,

    DOCTYPE TYPE BAPIMEPOHEADER-DOC_TYPE,

    CDATE TYPE BAPIMEPOHEADER-CREAT_DATE,

    VENDOR TYPE BAPIMEPOHEADER-VENDOR,

    PUR_ORG TYPE BAPIMEPOHEADER-PURCH_ORG,

    PUR_GRP TYPE BAPIMEPOHEADER-PUR_GROUP,

    ITEM_NUM TYPE BAPIMEPOITEM-PO_ITEM,

    MATERIAL TYPE BAPIMEPOITEM-MATERIAL,

    PLANT TYPE BAPIMEPOITEM-PLANT,

    QUANTITY(13) TYPE C,

    END OF PO_STR. "Structure declaration

    DATA :GT_POSTR TYPE STANDARD TABLE OF PO_STR,

    GW_POSTR TYPE PO_STR,

    V_PATH TYPE STRING. "Local internal table and work area declaration

    CONSTANTS: C_X TYPE C VALUE 'X'.

    PARAMETERS FILEPATH TYPE IBIPPARMS-PATH OBLIGATORY DEFAULT 'D:\Guna\desktop\Sample_BAPI_PO_Creation.txt'.

    AT SELECTION-SCREEN ON VALUE-REQUEST FOR FILEPATH.

    PERFORM GETFILEPATH USING FILEPATH.

    START-OF-SELECTION. "Start-of-selection event is triggered

    V_PATH = FILEPATH.

    PERFORM UPLOAD.

    GW_LANGU = SY-LANGU.

    LOOP AT GT_POSTR INTO GW_POSTR.

    *READ TABLE GT_POSTR INTO GW_POSTR INDEX 1.

    GW_HEADER-COMP_CODE = GW_POSTR-COMPANY .

    GW_HEADER-DOC_TYPE = GW_POSTR-DOCTYPE.

    GW_HEADER-CREAT_DATE = GW_POSTR-CDATE .

    GW_HEADER-VENDOR = GW_POSTR-VENDOR.

    GW_HEADER-LANGU = GW_LANGU.

    GW_HEADER-PURCH_ORG = GW_POSTR-PUR_ORG.

    GW_HEADER-PUR_GROUP = GW_POSTR-PUR_GRP.

    GW_HEADERX-COMP_CODE = C_X.

    GW_HEADERX-DOC_TYPE = C_X.

    GW_HEADERX-CREAT_DATE = C_X .

    GW_HEADERX-VENDOR = C_X.

    GW_HEADERX-LANGU = C_X.

    GW_HEADERX-PURCH_ORG = C_X.

    GW_HEADERX-PUR_GROUP = C_X.

    GW_ITEM-PO_ITEM = GW_POSTR-ITEM_NUM.

    GW_ITEM-MATERIAL = GW_POSTR-MATERIAL .

    GW_ITEM-PLANT = GW_POSTR-PLANT.

    GW_ITEM-QUANTITY = GW_POSTR-QUANTITY.

    APPEND GW_ITEM TO GT_ITEM.

    GW_ITEMX-PO_ITEM = GW_POSTR-ITEM_NUM.

    GW_ITEMX-MATERIAL = C_X .

    GW_ITEMX-PLANT = C_X.

    GW_ITEMX-QUANTITY = C_X.

    APPEND GW_ITEMX TO GT_ITEMX. "Assigning the flat file value to the work area

    CALL FUNCTION 'BAPI_PO_CREATE1'

    EXPORTING

    POHEADER = GW_HEADER

    POHEADERX = GW_HEADERX

    • POADDRVENDOR =

    • TESTRUN =

    • MEMORY_UNCOMPLETE =

    • MEMORY_COMPLETE =

    • POEXPIMPHEADER =

    • POEXPIMPHEADERX =

    • VERSIONS =

    • NO_MESSAGING =

    • NO_MESSAGE_REQ =

    • NO_AUTHORITY =

    • NO_PRICE_FROM_PO =

    IMPORTING

    EXPPURCHASEORDER = V_PONUMBER

    • EXPHEADER =

    • EXPPOEXPIMPHEADER =

    TABLES

    RETURN = GT_RETURN

    POITEM = GT_ITEM

    POITEMX = GT_ITEMX

    • POADDRDELIVERY =

    • POSCHEDULE =

    • POSCHEDULEX =

    • POACCOUNT =

    • POACCOUNTPROFITSEGMENT =

    • POACCOUNTX =

    • POCONDHEADER =

    • POCONDHEADERX =

    • POCOND =

    • POCONDX =

    • POLIMITS =

    • POCONTRACTLIMITS =

    • POSERVICES =

    • POSRVACCESSVALUES =

    • POSERVICESTEXT =

    • EXTENSIONIN =

    • EXTENSIONOUT =

    • POEXPIMPITEM =

    • POEXPIMPITEMX =

    • POTEXTHEADER =

    • POTEXTITEM =

    • ALLVERSIONS =

    • POPARTNER =

    • POCOMPONENTS =

    • POCOMPONENTSX =

    • POSHIPPING =

    • POSHIPPINGX =

    • POSHIPPINGEXP =

    . "BAPI PO creation function is called

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

    EXPORTING

    WAIT = 'X'

    IMPORTING

    RETURN = A

    .

    *COMMIT WORK .

    WRITE: V_PONUMBER.

    CLEAR : GT_RETURN, GW_ITEM,GW_ITEMX,GT_ITEM,GT_ITEMX,

    GW_HEADER,GW_HEADERX, V_PONUMBER. "All the work area is cleared

    ENDLOOP.

    *WRITE: V_PONUMBER.

    &----


    *& Form GETFILEPATH

    &----


    • text

    ----


    • -->P_FILEPATH text

    ----


    FORM GETFILEPATH USING P_FILEPATH.

    CALL FUNCTION 'F4_FILENAME'

    EXPORTING

    PROGRAM_NAME = SYST-CPROG

    DYNPRO_NUMBER = SYST-DYNNR

    IMPORTING

    FILE_NAME = FILEPATH

    .

    ENDFORM. " GETFILEPATH

    &----


    *& Form UPLOAD

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM UPLOAD .

    CALL FUNCTION 'GUI_UPLOAD'

    EXPORTING

    FILENAME = V_PATH

    • FILETYPE = 'ASC'

    • HAS_FIELD_SEPARATOR = ' '

    • HEADER_LENGTH = 0

    • READ_BY_LINE = 'X'

    • DAT_MODE = ' '

    • CODEPAGE = ' '

    • IGNORE_CERR = ABAP_TRUE

    • REPLACEMENT = '#'

    • CHECK_BOM = ' '

    • VIRUS_SCAN_PROFILE =

    • NO_AUTH_CHECK = ' '

    • IMPORTING

    • FILELENGTH =

    • HEADER =

    TABLES

    DATA_TAB = GT_POSTR

    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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

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

    ENDIF.

    ENDFORM. " UPLOADREPORT ZGPO_CREATION_BAPI.

    DATA : GT_HEADER TYPE STANDARD TABLE OF BAPIMEPOHEADER,

    GW_HEADER TYPE BAPIMEPOHEADER,

    GT_HEADERX TYPE STANDARD TABLE OF BAPIMEPOHEADERX,

    GW_HEADERX TYPE BAPIMEPOHEADERX,

    GT_ITEM TYPE STANDARD TABLE OF BAPIMEPOITEM,

    GW_ITEM TYPE BAPIMEPOITEM,

    GT_ITEMX TYPE STANDARD TABLE OF BAPIMEPOITEMX,

    GW_ITEMX TYPE BAPIMEPOITEMX,

    GT_RETURN TYPE STANDARD TABLE OF BAPIRET2,

    GW_RETURN TYPE BAPIRET2,

    GW_LANGU TYPE SY-LANGU,

    A TYPE BAPIRET2,

    V_PONUMBER TYPE BAPIMEPOHEADER-PO_NUMBER. " Internal table and work area declaration for PO header and PO item

    TYPES:BEGIN OF PO_STR,

    COMPANY TYPE BAPIMEPOHEADER-COMP_CODE,

    DOCTYPE TYPE BAPIMEPOHEADER-DOC_TYPE,

    CDATE TYPE BAPIMEPOHEADER-CREAT_DATE,

    VENDOR TYPE BAPIMEPOHEADER-VENDOR,

    PUR_ORG TYPE BAPIMEPOHEADER-PURCH_ORG,

    PUR_GRP TYPE BAPIMEPOHEADER-PUR_GROUP,

    ITEM_NUM TYPE BAPIMEPOITEM-PO_ITEM,

    MATERIAL TYPE BAPIMEPOITEM-MATERIAL,

    PLANT TYPE BAPIMEPOITEM-PLANT,

    QUANTITY(13) TYPE C,

    END OF PO_STR. "Structure declaration

    DATA :GT_POSTR TYPE STANDARD TABLE OF PO_STR,

    GW_POSTR TYPE PO_STR,

    V_PATH TYPE STRING. "Local internal table and work area declaration

    CONSTANTS: C_X TYPE C VALUE 'X'.

    PARAMETERS FILEPATH TYPE IBIPPARMS-PATH OBLIGATORY DEFAULT 'D:\Guna\desktop\Sample_BAPI_PO_Creation.txt'.

    AT SELECTION-SCREEN ON VALUE-REQUEST FOR FILEPATH.

    PERFORM GETFILEPATH USING FILEPATH.

    START-OF-SELECTION. "Start-of-selection event is triggered

    V_PATH = FILEPATH.

    PERFORM UPLOAD.

    GW_LANGU = SY-LANGU.

    LOOP AT GT_POSTR INTO GW_POSTR.

    *READ TABLE GT_POSTR INTO GW_POSTR INDEX 1.

    GW_HEADER-COMP_CODE = GW_POSTR-COMPANY .

    GW_HEADER-DOC_TYPE = GW_POSTR-DOCTYPE.

    GW_HEADER-CREAT_DATE = GW_POSTR-CDATE .

    GW_HEADER-VENDOR = GW_POSTR-VENDOR.

    GW_HEADER-LANGU = GW_LANGU.

    GW_HEADER-PURCH_ORG = GW_POSTR-PUR_ORG.

    GW_HEADER-PUR_GROUP = GW_POSTR-PUR_GRP.

    GW_HEADERX-COMP_CODE = C_X.

    GW_HEADERX-DOC_TYPE = C_X.

    GW_HEADERX-CREAT_DATE = C_X .

    GW_HEADERX-VENDOR = C_X.

    GW_HEADERX-LANGU = C_X.

    GW_HEADERX-PURCH_ORG = C_X.

    GW_HEADERX-PUR_GROUP = C_X.

    GW_ITEM-PO_ITEM = GW_POSTR-ITEM_NUM.

    GW_ITEM-MATERIAL = GW_POSTR-MATERIAL .

    GW_ITEM-PLANT = GW_POSTR-PLANT.

    GW_ITEM-QUANTITY = GW_POSTR-QUANTITY.

    APPEND GW_ITEM TO GT_ITEM.

    GW_ITEMX-PO_ITEM = GW_POSTR-ITEM_NUM.

    GW_ITEMX-MATERIAL = C_X .

    GW_ITEMX-PLANT = C_X.

    GW_ITEMX-QUANTITY = C_X.

    APPEND GW_ITEMX TO GT_ITEMX. "Assigning the flat file value to the work area

    CALL FUNCTION 'BAPI_PO_CREATE1'

    EXPORTING

    POHEADER = GW_HEADER

    POHEADERX = GW_HEADERX

    • POADDRVENDOR =

    • TESTRUN =

    • MEMORY_UNCOMPLETE =

    • MEMORY_COMPLETE =

    • POEXPIMPHEADER =

    • POEXPIMPHEADERX =

    • VERSIONS =

    • NO_MESSAGING =

    • NO_MESSAGE_REQ =

    • NO_AUTHORITY =

    • NO_PRICE_FROM_PO =

    IMPORTING

    EXPPURCHASEORDER = V_PONUMBER

    • EXPHEADER =

    • EXPPOEXPIMPHEADER =

    TABLES

    RETURN = GT_RETURN

    POITEM = GT_ITEM

    POITEMX = GT_ITEMX

    • POADDRDELIVERY =

    • POSCHEDULE =

    • POSCHEDULEX =

    • POACCOUNT =

    • POACCOUNTPROFITSEGMENT =

    • POACCOUNTX =

    • POCONDHEADER =

    • POCONDHEADERX =

    • POCOND =

    • POCONDX =

    • POLIMITS =

    • POCONTRACTLIMITS =

    • POSERVICES =

    • POSRVACCESSVALUES =

    • POSERVICESTEXT =

    • EXTENSIONIN =

    • EXTENSIONOUT =

    • POEXPIMPITEM =

    • POEXPIMPITEMX =

    • POTEXTHEADER =

    • POTEXTITEM =

    • ALLVERSIONS =

    • POPARTNER =

    • POCOMPONENTS =

    • POCOMPONENTSX =

    • POSHIPPING =

    • POSHIPPINGX =

    • POSHIPPINGEXP =

    . "BAPI PO creation function is called

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

    EXPORTING

    WAIT = 'X'

    IMPORTING

    RETURN = A

    .

    *COMMIT WORK .

    WRITE: V_PONUMBER.

    CLEAR : GT_RETURN, GW_ITEM,GW_ITEMX,GT_ITEM,GT_ITEMX,

    GW_HEADER,GW_HEADERX, V_PONUMBER. "All the work area is cleared

    ENDLOOP.

    *WRITE: V_PONUMBER.

    &----


    *& Form GETFILEPATH

    &----


    • text

    ----


    • -->P_FILEPATH text

    ----


    FORM GETFILEPATH USING P_FILEPATH.

    CALL FUNCTION 'F4_FILENAME'

    EXPORTING

    PROGRAM_NAME = SYST-CPROG

    DYNPRO_NUMBER = SYST-DYNNR

    IMPORTING

    FILE_NAME = FILEPATH

    .

    ENDFORM. " GETFILEPATH

    &----


    *& Form UPLOAD

    &----


    • text

    ----


    • --> p1 text

    • <-- p2 text

    ----


    FORM UPLOAD .

    CALL FUNCTION 'GUI_UPLOAD'

    EXPORTING

    FILENAME = V_PATH

    • FILETYPE = 'ASC'

    • HAS_FIELD_SEPARATOR = ' '

    • HEADER_LENGTH = 0

    • READ_BY_LINE = 'X'

    • DAT_MODE = ' '

    • CODEPAGE = ' '

    • IGNORE_CERR = ABAP_TRUE

    • REPLACEMENT = '#'

    • CHECK_BOM = ' '

    • VIRUS_SCAN_PROFILE =

    • NO_AUTH_CHECK = ' '

    • IMPORTING

    • FILELENGTH =

    • HEADER =

    TABLES

    DATA_TAB = GT_POSTR

    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 ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

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

    ENDIF.

    ENDFORM. " UPLOAD

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2007 at 06:11 AM

    Hi,

    i am sending the BAPI for creating PO.

    we use the function module for creating PO

    BAP_PO_CTREAT1.

    constants : c_x value 'X'.

    data: del_date type sy-datum.

    data: pohead type bapimepoheader.

    data: poheadx type bapimepoheaderx.

    data: exp_head type bapimepoheader.

    data: return type table of bapiret2 with header line.

    data: poitem type table of bapimepoitem with header line.

    data: poitemx type table of bapimepoitemx with header line.

    data: posched type table of bapimeposchedule with header line.

    data: poschedx type table of bapimeposchedulx with header line.

    data: ex_po_number type bapimepoheader-po_number.

    parameters: p_matnr type ekpo-matnr.

    parameters: p_werks type ekpo-werks.

    parameters: p_lgort type ekpo-lgort.

    parameters: p_menge type ekpo-menge.

    parameters: p_lifnr type ekko-lifnr.

    parameters: p_ekorg type ekko-ekorg.

    parameters: p_ekgrp type ekko-ekgrp.

    parameters: p_bukrs type ekko-bukrs.

    • Header Level Data

    pohead-comp_code = p_bukrs.

    pohead-doc_type = 'NB' .

    pohead-creat_date = sy-datum .

    pohead-vendor = p_lifnr.

    pohead-purch_org = p_ekorg.

    pohead-pur_group = p_ekgrp.

    pohead-langu = sy-langu .

    pohead-doc_date = sy-datum.

    poheadx-comp_code = c_x.

    poheadx-doc_type = c_x.

    poheadx-creat_date = c_x.

    poheadx-vendor = c_x.

    poheadx-langu = c_x.

    poheadx-purch_org = c_x.

    poheadx-pur_group = c_x.

    poheadx-doc_date = c_x.

    • Item Level Data

    poitem-po_item = 1.

    poitem-material = p_matnr.

    poitem-plant = p_werks.

    poitem-stge_loc = p_lgort.

    poitem-quantity = p_menge.

    append poitem.

    poitemx-po_item = 1.

    poitemx-po_itemx = c_x.

    poitemx-material = c_x.

    poitemx-plant = c_x .

    poitemx-stge_loc = c_x .

    poitemx-quantity = c_x .

    poitemx-tax_code = c_x .

    poitemx-item_cat = c_x .

    poitemx-acctasscat = c_x .

    append poitemx.

    • Schedule Line Level Data

    posched-po_item = 1.

    posched-sched_line = 1.

    posched-del_datcat_ext = 'D'.

    del_date = sy-datum + 1.

    write del_date to posched-delivery_date.

    posched-deliv_time = '000001'.

    posched-quantity = p_menge.

    append posched.

    poschedx-po_item = 1.

    poschedx-sched_line = 1.

    poschedx-po_itemx = c_x.

    poschedx-sched_linex = c_x.

    poschedx-del_datcat_ext = c_x.

    poschedx-delivery_date = c_x.

    poschedx-quantity = c_x.

    append poschedx.

    call function 'BAPI_PO_CREATE1'

    exporting

    poheader = pohead

    poheaderx = poheadx

    testrun = ' '

    importing

    exppurchaseorder = ex_po_number

    expheader = exp_head

    tables

    return = return

    poitem = poitem

    poitemx = poitemx

    poschedule = posched

    poschedulex = poschedx.

    call function 'BAPI_TRANSACTION_COMMIT'

    exporting

    wait = 'X'.

    if not ex_po_number is initial.

    call function 'DEQUEUE_ALL'.

    else.

    call function 'DEQUEUE_ALL'.

    • message i036.

    Refar these links.

    bapipocreate1-and-net-price

    using-bapipocreate1--linking-service-and-account-a

    <b>reward is usefull</b>

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2007 at 06:13 AM

    Hi Mahesh,

    Bapi: def::: it is a middleware component in sap and it deals with businness objects like sales order create and purchase order create etc...all business objects are stored in BOR ie Business Object Repository tcode to view them is

    "Bapi". But Business Objects are created using tcode SWO1.

    Or we can alse say tht as bapi is a programming interace to acess sap Db from or within sap or frm other independent platforms...

    Bapi Function modules are RFC unabled and can be accessed frm various environments like VB, Java, etc.

    even check this link for more details:

    searchsap.techtarget.com/sDefinition/0,,sid21_gci845424,00.html>

    if ur not clear with this plz reply me i will send u an easiest way to work with bapi....

    www.sap-img.com/bapi.htm - 8k

    Regards,

    sana.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2007 at 07:23 AM

    Hi,

    check the below links

    http://www.erpgenie.com/abap/bapi/example.htm

    Regards,

    Nagaraj

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 04, 2007 at 04:35 AM

    thanks

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.