BAPI_COPAACTUALS_POSTCOSTDATA--COPA

*&---------------------------------------------------------------------*
*& Report ZCO_COST_UPLOAD
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT zco_cost_upload.

*Tables
TABLES : mara,lfa1.

* Type / Data declarations
TYPES : BEGIN OF ty_upload ,

record_id TYPE char6,
val_01 TYPE rke_param_value,
val_02 TYPE rke_param_value,
val_03 TYPE rke_param_value,
val_04 TYPE rke_param_value,
val_05 TYPE rke_param_value,
val_06 TYPE rke_param_value,
val_07 TYPE rke_param_value,
val_08 TYPE rke_param_value,
val_09 TYPE rke_param_value,
val_10 TYPE rke_param_value,
val_11 TYPE rke_param_value,
val_12 TYPE rke_param_value,
val_13 TYPE rke_param_value,
val_14 TYPE rke_param_value,
val_15 TYPE rke_param_value,
val_16 TYPE rke_param_value,
val_17 TYPE rke_param_value,
val_18 TYPE rke_param_value,
val_19 TYPE rke_param_value,
val_20 TYPE rke_param_value,
val_21 TYPE rke_param_value,
val_22 TYPE rke_param_value,
val_23 TYPE rke_param_value, " new
val_24 TYPE rke_param_value, " new KWGOHD

END OF ty_upload.


TYPES : BEGIN OF ty_matnr,

matnr TYPE matnr,

END OF ty_matnr.

 

DATA : it_upload TYPE TABLE OF ty_upload,
it_uploadx TYPE TABLE OF ty_upload,
wa_upload LIKE LINE OF it_upload,
it_ipdata TYPE TABLE OF bapi_copa_data,
wa_ipdata LIKE LINE OF it_ipdata,
it_flist TYPE TABLE OF bapi_copa_field,
wa_flist LIKE LINE OF it_flist,
it_ret TYPE TABLE OF bapiret2 WITH HEADER LINE,
it_mara TYPE TABLE OF mara,
wa_mara LIKE LINE OF it_mara,
it_matnr TYPE TABLE OF ty_matnr,
wa_matnr LIKE LINE OF it_matnr.


* Selection Screen
SELECTION-SCREEN BEGIN OF BLOCK blk WITH FRAME TITLE text-001 .
SELECTION-SCREEN SKIP 1.

PARAMETERS: p_file LIKE rlgrap-filename OBLIGATORY MEMORY ID file,
p_oc LIKE bapi0017-op_concern DEFAULT 'HOPE' ,
p_test LIKE bapi0017-testrun DEFAULT 'X'.

SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN END OF BLOCK blk.

 


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

PERFORM get_filename CHANGING p_file .


START-OF-SELECTION.

PERFORM upload_file.

PERFORM fill_feild_table.

PERFORM bapi_update.


*&---------------------------------------------------------------------*
*& Form get_filename
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* <--P_P_FILE text
*----------------------------------------------------------------------*
FORM get_filename CHANGING p_p_file LIKE p_file.

DATA: filename LIKE p_file.

CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_filename = 'BDS.txt'
def_path = 'C:'
mask = ',BDC Upload File,*.*.'
mode = '0'
title = 'Chose file location'
IMPORTING
filename = filename
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.
IF sy-subrc <> 0.
EXIT.
ELSE.
p_p_file = filename.

ENDIF.


ENDFORM. " get_filename
*&---------------------------------------------------------------------*
*& Form upload_file
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM upload_file .

DATA : v_file TYPE string.
v_file = p_file.

 


CALL FUNCTION 'WS_UPLOAD'
EXPORTING
codepage = 'IBM'
filename = p_file
filetype = 'DAT'
* HEADLEN = ' '
* LINE_EXIT = ' '
* TRUNCLEN = ' '
* USER_FORM = ' '
* USER_PROG = ' '
* DAT_D_FORMAT = ' '
* IMPORTING
* FILELENGTH =
TABLES
data_tab = it_upload
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
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

 


* BREAK-POINT.

* DELETE it_upload WHERE lifnr IS INITIAL.

ENDFORM. " upload_file
*&---------------------------------------------------------------------*
*& Form fill_feild_table
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fill_feild_table .

DATA : cnt TYPE rke_record_id,
v_kunnr TYPE kunnr.

LOOP AT it_upload INTO wa_upload.

CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = wa_upload-val_02
IMPORTING
output = wa_upload-val_02
* EXCEPTIONS
* LENGTH_ERROR = 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.

wa_matnr-matnr = wa_upload-val_02.
APPEND wa_matnr TO it_matnr.

ENDLOOP.

IF it_matnr[] IS NOT INITIAL.

SELECT * FROM mara INTO CORRESPONDING FIELDS OF TABLE it_mara
FOR ALL ENTRIES IN it_matnr
WHERE matnr = it_matnr-matnr.

ENDIF.


LOOP AT it_upload INTO wa_upload.
* Fill the field name and value based on fixed sequence

* Starts from Col 2 of EXCEL
CLEAR: wa_ipdata.
wa_ipdata-record_id = wa_upload-record_id.
wa_ipdata-fieldname = 'BUDAT'.
wa_ipdata-value = wa_upload-val_01.
APPEND wa_ipdata TO it_ipdata.
wa_flist-fieldname = wa_ipdata-fieldname.
APPEND wa_flist TO it_flist.

CLEAR: wa_ipdata.
wa_ipdata-record_id = wa_upload-record_id.
wa_ipdata-fieldname = 'ARTNR'.

CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = wa_upload-val_02
IMPORTING
output = wa_upload-val_02
* EXCEPTIONS
* LENGTH_ERROR = 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.

wa_ipdata-value = wa_upload-val_02.
APPEND wa_ipdata TO it_ipdata.
wa_flist-fieldname = wa_ipdata-fieldname.
APPEND wa_flist TO it_flist.


* Find wt and dimension

READ TABLE it_mara INTO wa_mara WITH KEY matnr = wa_upload-val_02.
IF sy-subrc = 0.

CLEAR: wa_ipdata.

wa_mara-volum = wa_mara-volum * wa_upload-val_13. "ABSMG
wa_mara-ntgew = wa_mara-ntgew * wa_upload-val_13. "ABSMG

wa_ipdata-record_id = wa_upload-record_id.
wa_ipdata-fieldname = 'VVVOL'.
wa_ipdata-value = wa_mara-volum.
APPEND wa_ipdata TO it_ipdata.
wa_flist-fieldname = wa_ipdata-fieldname.
APPEND wa_flist TO it_flist.

wa_ipdata-record_id = wa_upload-record_id.
wa_ipdata-fieldname = 'VVVOL_ME'.
wa_ipdata-value = wa_mara-voleh.
APPEND wa_ipdata TO it_ipdata.
wa_flist-fieldname = wa_ipdata-fieldname.
APPEND wa_flist TO it_flist.


CLEAR: wa_ipdata.
wa_ipdata-record_id = wa_upload-record_id.
wa_ipdata-fieldname = 'VVWGT'.
wa_ipdata-value = wa_mara-ntgew.
APPEND wa_ipdata TO it_ipdata.
wa_flist-fieldname = wa_ipdata-fieldname.
APPEND wa_flist TO it_flist.

CLEAR: wa_ipdata.
wa_ipdata-record_id = wa_upload-record_id.
wa_ipdata-fieldname = 'VVWGT_ME'.
wa_ipdata-value = wa_mara-gewei.
APPEND wa_ipdata TO it_ipdata.
wa_flist-fieldname = wa_ipdata-fieldname.
APPEND wa_flist TO it_flist.

ENDIF.

 

CLEAR: wa_ipdata.
wa_ipdata-record_id = wa_upload-record_id.
wa_ipdata-fieldname = 'BUKRS'.
wa_ipdata-value = wa_upload-val_03.
APPEND wa_ipdata TO it_ipdata.
wa_flist-fieldname = wa_ipdata-fieldname.
APPEND wa_flist TO it_flist.

CLEAR: wa_ipdata.
wa_ipdata-record_id = wa_upload-record_id.
wa_ipdata-fieldname = 'KNDNR'.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_upload-val_04
IMPORTING
output = v_kunnr.


wa_ipdata-value = v_kunnr.
APPEND wa_ipdata TO it_ipdata.
wa_flist-fieldname = wa_ipdata-fieldname.
APPEND wa_flist TO it_flist.

CLEAR: wa_ipdata.
wa_ipdata-record_id = wa_upload-record_id.
wa_ipdata-fieldname = 'KOKRS'.
wa_ipdata-value = wa_upload-val_05.
APPEND wa_ipdata TO it_ipdata.
wa_flist-fieldname = wa_ipdata-fieldname.
APPEND wa_flist TO it_flist.

 


CLEAR: wa_ipdata.
wa_ipdata-record_id = wa_upload-record_id.
wa_ipdata-fieldname = 'PRCTR'.
wa_ipdata-value = wa_upload-val_06.
APPEND wa_ipdata TO it_ipdata.
wa_flist-fieldname = wa_ipdata-fieldname.
APPEND wa_flist TO it_flist.

CLEAR: wa_ipdata.
wa_ipdata-record_id = wa_upload-record_id.
wa_ipdata-fieldname = 'VKORG'.
wa_ipdata-value = wa_upload-val_07.
APPEND wa_ipdata TO it_ipdata.
wa_flist-fieldname = wa_ipdata-fieldname.
APPEND wa_flist TO it_flist.

CLEAR: wa_ipdata.
wa_ipdata-record_id = wa_upload-record_id.
wa_ipdata-fieldname = 'VRGAR'.
wa_ipdata-value = wa_upload-val_08.
APPEND wa_ipdata TO it_ipdata.
wa_flist-fieldname = wa_ipdata-fieldname.
APPEND wa_flist TO it_flist.

CLEAR: wa_ipdata.
wa_ipdata-record_id = wa_upload-record_id.
wa_ipdata-fieldname = 'VTWEG'.
wa_ipdata-value = wa_upload-val_09.
APPEND wa_ipdata TO it_ipdata.
wa_flist-fieldname = wa_ipdata-fieldname.
APPEND wa_flist TO it_flist.

CLEAR: wa_ipdata.
wa_ipdata-record_id = wa_upload-record_id.
wa_ipdata-fieldname = 'WERKS'.
wa_ipdata-value = wa_upload-val_10.
APPEND wa_ipdata TO it_ipdata.
wa_flist-fieldname = wa_ipdata-fieldname.
APPEND wa_flist TO it_flist.

 


CLEAR: wa_ipdata.
wa_ipdata-record_id = wa_upload-record_id.
wa_ipdata-fieldname = 'KMKDGR'.
wa_ipdata-value = wa_upload-val_11.
APPEND wa_ipdata TO it_ipdata.
wa_flist-fieldname = wa_ipdata-fieldname.
APPEND wa_flist TO it_flist.

CLEAR: wa_ipdata.
wa_ipdata-record_id = wa_upload-record_id.
wa_ipdata-fieldname = 'MVGR1'.
wa_ipdata-value = wa_upload-val_12.
APPEND wa_ipdata TO it_ipdata.
wa_flist-fieldname = wa_ipdata-fieldname.
APPEND wa_flist TO it_flist.

CLEAR: wa_ipdata.
wa_ipdata-record_id = wa_upload-record_id.
wa_ipdata-fieldname = 'ABSMG'.
wa_ipdata-value = wa_upload-val_13.
APPEND wa_ipdata TO it_ipdata.
wa_flist-fieldname = wa_ipdata-fieldname.
APPEND wa_flist TO it_flist.

CLEAR: wa_ipdata.
wa_ipdata-record_id = wa_upload-record_id.
wa_ipdata-fieldname = 'ERLOS'.
wa_ipdata-value = wa_upload-val_14.
wa_ipdata-currency = 'LKR'.
APPEND wa_ipdata TO it_ipdata.
wa_flist-fieldname = wa_ipdata-fieldname.
APPEND wa_flist TO it_flist.

CLEAR: wa_ipdata.
wa_ipdata-record_id = wa_upload-record_id.
wa_ipdata-fieldname = 'KWAGTK'.
wa_ipdata-currency = 'LKR'.
wa_ipdata-value = wa_upload-val_15.
APPEND wa_ipdata TO it_ipdata.
wa_flist-fieldname = wa_ipdata-fieldname.
APPEND wa_flist TO it_flist.


CLEAR: wa_ipdata.
wa_ipdata-record_id = wa_upload-record_id.
wa_ipdata-fieldname = 'VVCOG'.
wa_ipdata-currency = 'LKR'.
wa_ipdata-value = wa_upload-val_16.
APPEND wa_ipdata TO it_ipdata.
wa_flist-fieldname = wa_ipdata-fieldname.
APPEND wa_flist TO it_flist.

CLEAR: wa_ipdata.
wa_ipdata-record_id = wa_upload-record_id.
wa_ipdata-fieldname = 'KWMAEK'.
wa_ipdata-currency = 'LKR'.
wa_ipdata-value = wa_upload-val_17.
APPEND wa_ipdata TO it_ipdata.
wa_flist-fieldname = wa_ipdata-fieldname.
APPEND wa_flist TO it_flist.

CLEAR: wa_ipdata.
wa_ipdata-record_id = wa_upload-record_id.
wa_ipdata-fieldname = 'VVCPK'.
wa_ipdata-currency = 'LKR'.
wa_ipdata-value = wa_upload-val_18.
APPEND wa_ipdata TO it_ipdata.
wa_flist-fieldname = wa_ipdata-fieldname.
APPEND wa_flist TO it_flist.

CLEAR: wa_ipdata.
wa_ipdata-record_id = wa_upload-record_id.
wa_ipdata-fieldname = 'VVDLR'.
wa_ipdata-value = wa_upload-val_19.
wa_ipdata-currency = 'LKR'.
APPEND wa_ipdata TO it_ipdata.
wa_flist-fieldname = wa_ipdata-fieldname.
APPEND wa_flist TO it_flist.

CLEAR: wa_ipdata.
wa_ipdata-record_id = wa_upload-record_id.
wa_ipdata-fieldname = 'VVDSA'.
wa_ipdata-value = wa_upload-val_20.
wa_ipdata-currency = 'LKR'.
APPEND wa_ipdata TO it_ipdata.
wa_flist-fieldname = wa_ipdata-fieldname.
APPEND wa_flist TO it_flist.

CLEAR: wa_ipdata.
wa_ipdata-record_id = wa_upload-record_id.
wa_ipdata-fieldname = 'VVTXS'.
wa_ipdata-value = wa_upload-val_21.
wa_ipdata-currency = 'LKR'.
APPEND wa_ipdata TO it_ipdata.
wa_flist-fieldname = wa_ipdata-fieldname.
APPEND wa_flist TO it_flist.


* Hardcoded feilds
* ABSMG_ME
CLEAR: wa_ipdata.
wa_ipdata-record_id = wa_upload-record_id.
wa_ipdata-fieldname = 'ABSMG_ME'.
wa_ipdata-value = wa_upload-val_22.
APPEND wa_ipdata TO it_ipdata.
wa_flist-fieldname = wa_ipdata-fieldname.
APPEND wa_flist TO it_flist.

CLEAR: wa_ipdata.
wa_ipdata-record_id = wa_upload-record_id.
wa_ipdata-fieldname = 'VVTOT'.
wa_ipdata-value = wa_upload-val_23.
wa_ipdata-currency = 'LKR'.
APPEND wa_ipdata TO it_ipdata.
wa_flist-fieldname = wa_ipdata-fieldname.
APPEND wa_flist TO it_flist.

CLEAR: wa_ipdata.
wa_ipdata-record_id = wa_upload-record_id.
wa_ipdata-fieldname = 'KWGOHD'.
wa_ipdata-value = wa_upload-val_24.
wa_ipdata-currency = 'LKR'.
APPEND wa_ipdata TO it_ipdata.
wa_flist-fieldname = wa_ipdata-fieldname.
APPEND wa_flist TO it_flist.

ENDLOOP.

ENDFORM. " fill_feild_table
*&---------------------------------------------------------------------*
*& Form bapi_update
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM bapi_update .
DATA : ret LIKE LINE OF it_ret.
WRITE : / 'Log of the Cost Data upload..'.
SKIP 2.
SORT it_flist .
DELETE ADJACENT DUPLICATES FROM it_flist COMPARING fieldname.


CALL FUNCTION 'BAPI_COPAACTUALS_POSTCOSTDATA'
EXPORTING
operatingconcern = p_oc
testrun = p_test
TABLES
inputdata = it_ipdata
fieldlist = it_flist
return = it_ret.

 

 


READ TABLE it_ret WITH KEY type = 'E'.

IF sy-subrc NE 0.
READ TABLE it_ret WITH KEY type = 'A'.

ENDIF.

IF sy-subrc = 0.
* error.

WRITE : / 'Upload error...'.

LOOP AT it_ret INTO ret.

WRITE : / ret-type , ret-id , ret-number,
ret-message, ret-log_no,
ret-message_v1, ret-message_v2,
ret-message_v3, ret-message_v4.

ENDLOOP.
SKIP 1.

ELSE.

IF p_test = ' '.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
* IMPORTING
* RETURN =
.
WRITE : 'List of Records uploaded...'.
ENDIF.

 

LOOP AT it_upload INTO wa_upload.

WRITE : / 'Record No. ' , wa_upload-record_id,
'Product : ' , wa_upload-val_02.
ENDLOOP.

ENDIF.

SKIP 2.

ENDFORM. " bapi_update  

posted on 2007-05-08 15:28  毛小娃  阅读(237)  评论(0编辑  收藏  举报

导航