Posted: Sat Apr 12, 2008 10:07 am Post subject: BAPI_COPAACTUALS_POSTCOSTDATA
BAPI_COPAACTUALS_POSTCOSTDATA - Post Costing-Based Actual Data
Code:
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.
ENDFORM. " get_filename
*&---------------------------------------------------------------------*
*& Form upload_file
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM upload_file .
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.
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.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.