CREATE PO USING BAPI
*&--------------------------------------------------------------------------------------------
*& FLAT-FILE:
*& 3702 NB 1000 001 10 100-431 20 100 1000
*& 3910 NB 15.03.2012 3000 012 001 30 R-1004 10 100 3200
*& 3911 NB 15.03.2012 3000 012 001 40 R-1005 20 200 3200
*& 3912 NB 15.03.2012 3000 012 001 50 R-1006 30 300 3200
*& 3913 NB 15.03.2012 3000 012 001 60 R-1007 40 400 3200
*&--------------------------------------------------------------------------------------------
REPORT ZSD_I_IDDL0073_BAPI.
*&---------------------------------------------------------------------*
*& Structures declaration
*&---------------------------------------------------------------------*
*Structor Declaration PO INFO.
TYPES:BEGIN OF TY_EKKO ,
LIFNR TYPE EKKO-LIFNR , "vendor no
BSART TYPE RM06E-BSART , "po type
BEDAT TYPE SY-DATUM , "RM06E-BEDAT , "po date
EKORG TYPE EKKO-EKORG , "po org
EKGRP TYPE EKKO-EKGRP , "po group
* MATKL TYPE RM06E-MATKL , "meterial group
EBELP TYPE RM06E-EBELP , "po item no
MATNR TYPE EKPO-EMATN , "meterial no
MENGE TYPE EKPO-MENGE , "quantity
NETPR TYPE EKPO-NETPR , "net value
WERKS TYPE EKPO-WERKS , "plant
EBELN TYPE EKKO-EBELN , "po no
END OF TY_EKKO .
*&---------------------------------------------------------------------*
*& Internal Tables declaration.
*&---------------------------------------------------------------------*
*Itab declaration for to upload data .
DATA:T_EKKO TYPE STANDARD TABLE OF TY_EKKO INITIAL SIZE 0,
*&---------------------------------------------------------------------*
*& Work area declarations
*&---------------------------------------------------------------------*
* Work area declartion for source
W_EKKO TYPE TY_EKKO.
*&---------------------------------------------------------------------*
*& Selection screen declarations
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
PARAMETERS:P_FILE TYPE FILENAME-FILEINTERN.
SELECTION-SCREEN END OF BLOCK B1.
*&---------------------------------------------------------------------*
*& Initialization declarations
*&---------------------------------------------------------------------*
INITIALIZATION.
* Clear work area
CLEAR:W_EKKO.
* Refresh tables
REFRESH:T_EKKO.
*&---------------------------------------------------------------------*
*& Start of selection declarations
*&---------------------------------------------------------------------*
START-OF-SELECTION.
* This perform is used to upload the flatfile.
PERFORM SUB_UPLOAD_FLAT_FILE.
*This routine is used to upload the data to db using bapi.
PERFORM SUB_FILL_BAPI.
*&---------------------------------------------------------------------*
*& Form sub_upload_flat_file
*&---------------------------------------------------------------------*
* This routine is used to upload the flatfiel data to source itab.
*----------------------------------------------------------------------*
FORM SUB_UPLOAD_FLAT_FILE .
DATA:L_FILE TYPE STRING.
L_FILE = P_FILE .
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = L_FILE
* FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
* 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 = T_EKKO
* 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.
IF SY-SUBRC = 0.
MESSAGE:I001(YNRK_MESS) WITH 'file is uploaded successfully'.
ENDIF.
ENDFORM. " sub_upload_flat_file
*&---------------------------------------------------------------------*
*& Form sub_fill_bapi
*&---------------------------------------------------------------------*
* This routine is used to call the BAPI F.M and fill the required info.
*----------------------------------------------------------------------*
FORM SUB_FILL_BAPI .
DATA:L_HEADER TYPE BAPIEKKOC ,
* item info avaliable here.
L_T_ITEM TYPE STANDARD TABLE OF BAPIEKPOC INITIAL SIZE 0,
L_W_ITEM TYPE BAPIEKPOC ,
* message info avaliable here.
L_T_RETURN TYPE STANDARD TABLE OF BAPIRETURN INITIAL SIZE 0,
*MANDATORY PARAMETER.
L_T_ITEM_SCDULES TYPE STANDARD TABLE OF BAPIEKET INITIAL SIZE 0 ,
L_W_RETURN TYPE BAPIRETURN .
LOOP AT T_EKKO INTO W_EKKO.
*clear work area.
CLEAR:L_HEADER,
L_W_ITEM ,
L_W_RETURN.
*refresh itabs.
REFRESH:L_T_ITEM ,
L_T_RETURN.
*filling the header structor.
*L_HEADER-PO_NUMBER = W_EKKO-EBELN.
L_HEADER-PO_NUMBER = W_EKKO-EBELN.
L_HEADER-VENDOR = W_EKKO-LIFNR.
L_HEADER-DOC_TYPE = W_EKKO-BSART.
L_HEADER-DOC_DATE = SY-DATUM.
L_HEADER-PURCH_ORG = W_EKKO-EKORG.
L_HEADER-PUR_GROUP = W_EKKO-EKGRP.
L_HEADER-SUPPL_PLNT = W_EKKO-WERKS.
*filling the item info.
L_W_ITEM-PO_ITEM = W_EKKO-EBELP.
L_W_ITEM-MATERIAL = W_EKKO-MATNR.
*L_W_ITEM-MAT_GRP = W_EKKO-MATKL.
L_W_ITEM-PLANT = W_EKKO-WERKS.
L_W_ITEM-NET_PRICE = W_EKKO-NETPR.
L_W_ITEM-DISP_QUAN = W_EKKO-MENGE.
APPEND L_W_ITEM TO L_T_ITEM.
**filling the error message info.
*L_W_RETURN-TYPE = 'X'.
*L_W_RETURN-MESSAGE = 'X'.
*
*APPEND L_W_RETURN TO L_T_RETURN.
*calling the bapi function module.
CALL FUNCTION 'BAPI_PO_CREATE'
EXPORTING
PO_HEADER = L_HEADER
* PO_HEADER_ADD_DATA =
* HEADER_ADD_DATA_RELEVANT =
* PO_ADDRESS =
* SKIP_ITEMS_WITH_ERROR = 'X'
* ITEM_ADD_DATA_RELEVANT =
* HEADER_TECH_FIELDS =
* IMPORTING
* PURCHASEORDER =
TABLES
PO_ITEMS = L_T_ITEM
* PO_ITEM_ADD_DATA =
PO_ITEM_SCHEDULES = L_T_ITEM_SCDULES
* PO_ITEM_ACCOUNT_ASSIGNMENT =
* PO_ITEM_TEXT =
RETURN = L_T_RETURN
* PO_LIMITS =
* PO_CONTRACT_LIMITS =
* PO_SERVICES =
* PO_SRV_ACCASS_VALUES =
* PO_SERVICES_TEXT =
* PO_BUSINESS_PARTNER =
* EXTENSIONIN =
* POADDRDELIVERY =
.
IF SY-SUBRC = 0.
MESSAGE:I002(YNRK_MESS) WITH 'data uploaded successfully through bapi'.
ENDIF.
ENDLOOP.
LOOP AT L_T_RETURN INTO L_W_RETURN.
WRITE:L_W_RETURN-TYPE,L_W_RETURN-MESSAGE.
ENDLOOP.
ENDFORM. " sub_fill_bapi
0 comments:
Post a Comment