*&---------------------------------------------------------------------*
*& Report ZRP_BAPI_PO_CREATE_FLAT_FILE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZRP_BAPI_PO_CREATE_FLAT_FILE.
TYPE-POOLS : TRUXS.
types : BEGIN OF ty_file,
id(2),
type(2),
lifnr(10),
item TYPE n LENGTH 5,
matnr TYPE matnr,
menge type ekpo-menge,
netpr TYPE ekpo-netpr,
werks TYPE marc-werks,
ekorg TYPE ekorg,
ekgrp TYPE ekgrp,
bukrs TYPE ekko-bukrs,
END OF ty_file.
TYPES : tt_file TYPE STANDARD TABLE OF ty_file.
data : it_file TYPE tt_file,
wa_file TYPE ty_file.
PARAMETERs : p_file TYPE IBIPPARMS-PATH.
at SELECTION-SCREEN on VALUE-REQUEST FOR p_file.
PERFORM browse_file.
START-OF-SELECTION.
PERFORM LOAD_FLAT_FILE.
PERFORM CALL_BAPI_CREATE.
*&---------------------------------------------------------------------*
*& Form browse_file
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM browse_file .
CALL FUNCTION 'F4_FILENAME'
IMPORTING
FILE_NAME = p_file
.
ENDFORM. " browse_file
*&---------------------------------------------------------------------*
*& Form LOAD_FLAT_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM LOAD_FLAT_FILE .
DATA : LT_RAW TYPE TRUXS_T_TEXT_DATA.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR = 'X'
I_LINE_HEADER = 'X'
I_TAB_RAW_DATA = LT_RAW
I_FILENAME = P_FILE
TABLES
I_TAB_CONVERTED_DATA = IT_FILE
EXCEPTIONS
CONVERSION_FAILED = 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.
ENDFORM. " LOAD_FLAT_FILE
*&---------------------------------------------------------------------*
*& Form CALL_BAPI_CREATE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CALL_BAPI_CREATE .
DATA : PO_HEADER TYPE BAPIMEPOHEADER,
PO_HEADERX TYPE BAPIMEPOHEADERX,
IT_RETURN TYPE STANDARD TABLE OF BAPIRET2,
WA_RETURN TYPE BAPIRET2,
IT_POITEM TYPE STANDARD TABLE OF BAPIMEPOITEM,
WA_POITEM TYPE BAPIMEPOITEM,
IT_POITEMX TYPE STANDARD TABLE OF BAPIMEPOITEMX,
WA_POITEMX TYPE BAPIMEPOITEMX.
LOOP AT IT_FILE INTO WA_FILE.
PERFORM CONV_EXIT CHANGING wa_file-ekgrp.
PERFORM CONV_EXIT CHANGING wa_file-LIFNR.
PO_HEADER-COMP_CODE = wa_file-bukrs.
PO_HEADER-DOC_TYPE = wa_file-tyPE.
PO_HEADER-VENDOR = wa_file-lifnr.
PO_HEADER-PURCH_ORG = wa_file-ekorg.
PO_HEADER-PUR_GROUP = wa_file-ekgrp.
PO_HEADER-CURRENCY = 'EUR'.
PO_HEADERX-COMP_CODE = 'X'.
PO_HEADERX-DOC_TYPE = 'X'.
PO_HEADERX-VENDOR = 'X'.
PO_HEADERX-PURCH_ORG = 'X'.
PO_HEADERX-PUR_GROUP = 'X'.
PO_HEADERX-CURRENCY = 'X'.
WA_POITEM-PO_ITEM = wa_file-ITEM.
WA_POITEM-MATERIAL = wa_file-MATNR.
WA_POITEM-PLANT = wa_file-WERKS.
WA_POITEM-QUANTITY = wa_file-menge.
WA_POITEM-NET_PRICE = wa_fiLE-NETPR.
APPEND WA_POITEM TO IT_POITEM.
CLEAR WA_POITEM.
WA_POITEMX-PO_ITEM = wa_file-ITEM.
WA_POITEMX-PO_ITEMX = 'X'.
WA_POITEMX-MATERIAL = 'X'.
WA_POITEMX-PLANT = 'X'.
WA_POITEMX-QUANTITY = 'X'.
WA_POITEMX-NET_PRICE = 'X' .
APPEND WA_POITEMX TO IT_POITEMX.
CLEAR WA_POITEMX.
AT END OF ID.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
POHEADER = PO_HEADER
POHEADERX = PO_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 = IT_RETURN
POITEM = IT_POITEM
POITEMX = IT_POITEMX
* 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 =
.
ENDAT.
READ TABLE IT_RETURN INTO WA_RETURN WITH KEY type = 'E'.
IF SY-SUBRC EQ 0.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'
* IMPORTING
* RETURN =
.
ENDIF.
ENDLOOP.
ENDFORM. " CALL_BAPI_CREATE
*&---------------------------------------------------------------------*
*& Form CONV_EXIT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_WA_FILE_EKGRP text
*----------------------------------------------------------------------*
FORM CONV_EXIT CHANGING P_VALUE.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = P_VALUE
IMPORTING
OUTPUT = P_VALUE
.
ENDFORM. " CONV_EXIT
*& Report ZRP_BAPI_PO_CREATE_FLAT_FILE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZRP_BAPI_PO_CREATE_FLAT_FILE.
TYPE-POOLS : TRUXS.
types : BEGIN OF ty_file,
id(2),
type(2),
lifnr(10),
item TYPE n LENGTH 5,
matnr TYPE matnr,
menge type ekpo-menge,
netpr TYPE ekpo-netpr,
werks TYPE marc-werks,
ekorg TYPE ekorg,
ekgrp TYPE ekgrp,
bukrs TYPE ekko-bukrs,
END OF ty_file.
TYPES : tt_file TYPE STANDARD TABLE OF ty_file.
data : it_file TYPE tt_file,
wa_file TYPE ty_file.
PARAMETERs : p_file TYPE IBIPPARMS-PATH.
at SELECTION-SCREEN on VALUE-REQUEST FOR p_file.
PERFORM browse_file.
START-OF-SELECTION.
PERFORM LOAD_FLAT_FILE.
PERFORM CALL_BAPI_CREATE.
*&---------------------------------------------------------------------*
*& Form browse_file
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM browse_file .
CALL FUNCTION 'F4_FILENAME'
IMPORTING
FILE_NAME = p_file
.
ENDFORM. " browse_file
*&---------------------------------------------------------------------*
*& Form LOAD_FLAT_FILE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM LOAD_FLAT_FILE .
DATA : LT_RAW TYPE TRUXS_T_TEXT_DATA.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR = 'X'
I_LINE_HEADER = 'X'
I_TAB_RAW_DATA = LT_RAW
I_FILENAME = P_FILE
TABLES
I_TAB_CONVERTED_DATA = IT_FILE
EXCEPTIONS
CONVERSION_FAILED = 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.
ENDFORM. " LOAD_FLAT_FILE
*&---------------------------------------------------------------------*
*& Form CALL_BAPI_CREATE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM CALL_BAPI_CREATE .
DATA : PO_HEADER TYPE BAPIMEPOHEADER,
PO_HEADERX TYPE BAPIMEPOHEADERX,
IT_RETURN TYPE STANDARD TABLE OF BAPIRET2,
WA_RETURN TYPE BAPIRET2,
IT_POITEM TYPE STANDARD TABLE OF BAPIMEPOITEM,
WA_POITEM TYPE BAPIMEPOITEM,
IT_POITEMX TYPE STANDARD TABLE OF BAPIMEPOITEMX,
WA_POITEMX TYPE BAPIMEPOITEMX.
LOOP AT IT_FILE INTO WA_FILE.
PERFORM CONV_EXIT CHANGING wa_file-ekgrp.
PERFORM CONV_EXIT CHANGING wa_file-LIFNR.
PO_HEADER-COMP_CODE = wa_file-bukrs.
PO_HEADER-DOC_TYPE = wa_file-tyPE.
PO_HEADER-VENDOR = wa_file-lifnr.
PO_HEADER-PURCH_ORG = wa_file-ekorg.
PO_HEADER-PUR_GROUP = wa_file-ekgrp.
PO_HEADER-CURRENCY = 'EUR'.
PO_HEADERX-COMP_CODE = 'X'.
PO_HEADERX-DOC_TYPE = 'X'.
PO_HEADERX-VENDOR = 'X'.
PO_HEADERX-PURCH_ORG = 'X'.
PO_HEADERX-PUR_GROUP = 'X'.
PO_HEADERX-CURRENCY = 'X'.
WA_POITEM-PO_ITEM = wa_file-ITEM.
WA_POITEM-MATERIAL = wa_file-MATNR.
WA_POITEM-PLANT = wa_file-WERKS.
WA_POITEM-QUANTITY = wa_file-menge.
WA_POITEM-NET_PRICE = wa_fiLE-NETPR.
APPEND WA_POITEM TO IT_POITEM.
CLEAR WA_POITEM.
WA_POITEMX-PO_ITEM = wa_file-ITEM.
WA_POITEMX-PO_ITEMX = 'X'.
WA_POITEMX-MATERIAL = 'X'.
WA_POITEMX-PLANT = 'X'.
WA_POITEMX-QUANTITY = 'X'.
WA_POITEMX-NET_PRICE = 'X' .
APPEND WA_POITEMX TO IT_POITEMX.
CLEAR WA_POITEMX.
AT END OF ID.
CALL FUNCTION 'BAPI_PO_CREATE1'
EXPORTING
POHEADER = PO_HEADER
POHEADERX = PO_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 = IT_RETURN
POITEM = IT_POITEM
POITEMX = IT_POITEMX
* 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 =
.
ENDAT.
READ TABLE IT_RETURN INTO WA_RETURN WITH KEY type = 'E'.
IF SY-SUBRC EQ 0.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'
* IMPORTING
* RETURN =
.
ENDIF.
ENDLOOP.
ENDFORM. " CALL_BAPI_CREATE
*&---------------------------------------------------------------------*
*& Form CONV_EXIT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_WA_FILE_EKGRP text
*----------------------------------------------------------------------*
FORM CONV_EXIT CHANGING P_VALUE.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
INPUT = P_VALUE
IMPORTING
OUTPUT = P_VALUE
.
ENDFORM. " CONV_EXIT
No comments:
Post a Comment