*----------------------------------------------------------------------* * FORM MAPPING_AND_BAPI * *----------------------------------------------------------------------* FORM mapping_and_bapi. FIELD-SYMBOLS: <lf_tabella> TYPE table, <lf_riga> TYPE any, <lf_campo> TYPE any. DATA: ls_anlu TYPE anlu, ls_item TYPE soi_generic_item, lv_tf TYPE string, lv_tfx TYPE string, lv_field TYPE string, lv_dtype TYPE c, lv_area TYPE bf_afabe_d, lt_exception_list TYPE TABLE OF rsexc, lt_export_parameter TYPE TABLE OF rsexp, lt_import_parameter TYPE TABLE OF rsimp, lt_tables_parameter TYPE TABLE OF rstbl, ls_tables_parameter TYPE rstbl. *import DATA: ls_key TYPE bapi1022_key, lv_createsubnumber TYPE xsubno, ls_generaldata TYPE bapi1022_feglg001, ls_generaldatax TYPE bapi1022_feglg001x, ls_inventory TYPE bapi1022_feglg011, ls_inventoryx TYPE bapi1022_feglg011x, ls_postinginformation TYPE bapi1022_feglg002, ls_postinginformationx TYPE bapi1022_feglg002x, ls_timedependentdata TYPE bapi1022_feglg003, ls_timedependentdatax TYPE bapi1022_feglg003x, ls_allocations TYPE bapi1022_feglg004, ls_allocationsx TYPE bapi1022_feglg004x, ls_origin TYPE bapi1022_feglg009, ls_originx TYPE bapi1022_feglg009x, ls_investacctassignmnt TYPE bapi1022_feglg010, ls_investacctassignmntx TYPE bapi1022_feglg010x. *export DATA: lv_companycode TYPE bapi1022_1-comp_code, lv_asset TYPE bapi1022_1-assetmaino, lv_subnumber TYPE bapi1022_1-assetsubno, ls_assetcreated TYPE bapi1022_reference. *tables DATA: lt_depreciationareas TYPE TABLE OF bapi1022_dep_areas, ls_depreciationareas TYPE bapi1022_dep_areas, lt_depreciationareasx TYPE TABLE OF bapi1022_dep_areasx, ls_depreciationareasx TYPE bapi1022_dep_areasx, lt_cumulatedvalues TYPE TABLE OF bapi1022_cumval, ls_cumulatedvalues TYPE bapi1022_cumval, lt_return TYPE TABLE OF bapiret2, ls_return TYPE bapiret2. CALL FUNCTION 'FUNCTION_IMPORT_INTERFACE' EXPORTING funcname = 'BAPI_FIXEDASSET_OVRTAKE_CREATE' TABLES exception_list = lt_exception_list export_parameter = lt_export_parameter import_parameter = lt_import_parameter tables_parameter = lt_tables_parameter EXCEPTIONS error_message = 1 function_not_found = 2 invalid_name = 3 OTHERS = 4. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. LOOP AT gt_data INTO gs_data. READ TABLE gt_head INTO ls_item WITH KEY row = '1' column = gs_data-column. READ TABLE lt_tables_parameter INTO ls_tables_parameter WITH KEY parameter = ls_item-value. IF sy-subrc <> 0. *exporting IF ls_item-value = 'CREATESUBNUMBER'. lv_tf = 'LV_CREATESUBNUMBER'. ELSE. CONCATENATE 'LS_' ls_item-value INTO lv_tf. CONCATENATE 'LS_' ls_item-value 'X' INTO lv_tfx. READ TABLE gt_head INTO ls_item WITH KEY row = '2' column = gs_data-column. CONCATENATE lv_tf '-' ls_item-value INTO lv_tf. IF ls_item-value = 'PLATE_NO'. CONCATENATE lv_tfx '-' 'LICENSE_PLATE_NO' INTO lv_tfx. ELSEIF ls_item-value = 'ORIG_ACQ_YR'. CONCATENATE lv_tfx '-' 'ORIG_ACQ_YEAR' INTO lv_tfx. ELSE. CONCATENATE lv_tfx '-' ls_item-value INTO lv_tfx. ENDIF. ENDIF. IF lv_tf = 'LS_ORIGIN-ORIG_ACQ_YR'. IF gs_data-value IS NOT INITIAL. ls_origin-orig_acq_yr = gs_data-value+6(4). ENDIF. ELSEIF lv_tf = 'LS_ORIGIN-PURCH_NEW'. IF gs_data-value = 'X'. CLEAR ls_origin-purch_new. ELSE. ls_origin-purch_new = 'X'. ENDIF. ELSE. ASSIGN (lv_tf) TO <lf_campo>. IF <lf_campo> IS ASSIGNED. DESCRIBE FIELD <lf_campo> TYPE lv_dtype. CASE lv_dtype. WHEN 'D'. CONCATENATE gs_data-value+6(4) gs_data-value+3(2) gs_data-value+0(2) INTO <lf_campo>. WHEN 'P'. TRANSLATE gs_data-value USING ',.'. <lf_campo> = gs_data-value. WHEN OTHERS. <lf_campo> = gs_data-value. ENDCASE. UNASSIGN <lf_campo>. ENDIF. ENDIF. ASSIGN (lv_tfx) TO <lf_campo>. IF <lf_campo> IS ASSIGNED. <lf_campo> = 'X'. UNASSIGN <lf_campo>. ENDIF. ELSE. *tables CONCATENATE 'LT_' ls_item-value INTO lv_tf. CONCATENATE 'LT_' ls_item-value 'X' INTO lv_tfx. ASSIGN (lv_tf) TO <lf_tabella>. READ TABLE gt_head INTO ls_item WITH KEY row = '2' column = gs_data-column. lv_area = ls_item-value(2). SHIFT ls_item-value BY 3 PLACES. lv_field = 'AREA'. READ TABLE <lf_tabella> ASSIGNING <lf_riga> WITH KEY (lv_field) = lv_area. IF sy-subrc <> 0. APPEND INITIAL LINE TO <lf_tabella> ASSIGNING <lf_riga>. ASSIGN COMPONENT lv_field OF STRUCTURE <lf_riga> TO <lf_campo>. IF <lf_campo> IS ASSIGNED. <lf_campo> = lv_area. UNASSIGN <lf_campo>. ENDIF. lv_field = 'FISC_YEAR'. ASSIGN COMPONENT lv_field OF STRUCTURE <lf_riga> TO <lf_campo>. IF <lf_campo> IS ASSIGNED. <lf_campo> = pa_fiscy. UNASSIGN <lf_campo>. ENDIF. lv_field = 'ACQ_VALUE'. ASSIGN COMPONENT lv_field OF STRUCTURE <lf_riga> TO <lf_campo>. IF <lf_campo> IS ASSIGNED. TRANSLATE gs_data-value USING ',.'. <lf_campo> = gs_data-value. UNASSIGN <lf_campo>. ENDIF. UNASSIGN: <lf_tabella>, <lf_riga>, <lf_campo>. ASSIGN (lv_tfx) TO <lf_tabella>. IF <lf_tabella> IS ASSIGNED. APPEND INITIAL LINE TO <lf_tabella> ASSIGNING <lf_riga>. ASSIGN COMPONENT ls_item-value OF STRUCTURE <lf_riga> TO <lf_campo>. <lf_campo> = lv_area. UNASSIGN: <lf_tabella>, <lf_riga>, <lf_campo>. ENDIF. ELSE. ASSIGN COMPONENT ls_item-value OF STRUCTURE <lf_riga> TO <lf_campo>. IF <lf_campo> IS ASSIGNED. DESCRIBE FIELD <lf_campo> TYPE lv_dtype. CASE lv_dtype. WHEN 'D'. CONCATENATE gs_data-value+6(4) gs_data-value+3(2) gs_data-value+0(2) INTO <lf_campo>. WHEN 'P'. TRANSLATE gs_data-value USING ',.'. <lf_campo> = gs_data-value. WHEN OTHERS. <lf_campo> = gs_data-value. ENDCASE. UNASSIGN: <lf_tabella>, <lf_riga>, <lf_campo>. ENDIF. ASSIGN (lv_tfx) TO <lf_tabella>. IF <lf_tabella> IS ASSIGNED. lv_field = 'AREA'. READ TABLE <lf_tabella> ASSIGNING <lf_riga> WITH KEY (lv_field) = lv_area. ASSIGN COMPONENT ls_item-value OF STRUCTURE <lf_riga> TO <lf_campo>. IF <lf_campo> IS ASSIGNED. <lf_campo> = 'X'. UNASSIGN: <lf_tabella>, <lf_riga>, <lf_campo>. ENDIF. ENDIF. ENDIF. ENDIF. AT END OF row. LOOP AT lt_depreciationareas INTO ls_depreciationareas WHERE deactivate = 'X'. DELETE lt_cumulatedvalues WHERE area = ls_depreciationareas-area. ENDLOOP. *elimino se presenti le area da copiare LOOP AT so_aree. READ TABLE lt_depreciationareas INTO ls_depreciationareas WITH KEY area = so_aree-high. IF sy-subrc = 0. DELETE TABLE lt_depreciationareas FROM ls_depreciationareas. READ TABLE lt_depreciationareasx INTO ls_depreciationareasx WITH KEY area = so_aree-high. DELETE TABLE lt_depreciationareasx FROM ls_depreciationareasx. ENDIF. READ TABLE lt_cumulatedvalues INTO ls_cumulatedvalues WITH KEY area = so_aree-high. IF sy-subrc = 0. DELETE TABLE lt_cumulatedvalues FROM ls_cumulatedvalues. ENDIF. ENDLOOP. *copio le aree LOOP AT so_aree. READ TABLE lt_depreciationareas INTO ls_depreciationareas WITH KEY area = so_aree-low. IF sy-subrc = 0. ls_depreciationareas-area = so_aree-high. APPEND ls_depreciationareas TO lt_depreciationareas. READ TABLE lt_depreciationareasx INTO ls_depreciationareasx WITH KEY area = so_aree-low. ls_depreciationareasx-area = so_aree-high. APPEND ls_depreciationareasx TO lt_depreciationareasx. ENDIF. READ TABLE lt_cumulatedvalues INTO ls_cumulatedvalues WITH KEY area = so_aree-low. IF sy-subrc = 0. ls_cumulatedvalues-area = so_aree-high. APPEND ls_cumulatedvalues TO lt_cumulatedvalues. ENDIF. ENDLOOP. DO. SORT: lt_depreciationareas, lt_depreciationareasx, lt_cumulatedvalues. CALL FUNCTION 'BAPI_FIXEDASSET_OVRTAKE_CREATE' EXPORTING key = ls_key createsubnumber = lv_createsubnumber testrun = cb_test generaldata = ls_generaldata generaldatax = ls_generaldatax inventory = ls_inventory inventoryx = ls_inventoryx postinginformation = ls_postinginformation postinginformationx = ls_postinginformationx timedependentdata = ls_timedependentdata timedependentdatax = ls_timedependentdatax allocations = ls_allocations allocationsx = ls_allocationsx origin = ls_origin originx = ls_originx investacctassignmnt = ls_investacctassignmnt investacctassignmntx = ls_investacctassignmntx IMPORTING companycode = lv_companycode asset = lv_asset subnumber = lv_subnumber assetcreated = ls_assetcreated TABLES depreciationareas = lt_depreciationareas depreciationareasx = lt_depreciationareasx cumulatedvalues = lt_cumulatedvalues return = lt_return. READ TABLE lt_return INTO ls_return WITH KEY type = 'E' id = 'AY' number = '221'. IF sy-subrc = 0. DELETE lt_depreciationareas WHERE deactivate = 'X'. DELETE lt_depreciationareasx WHERE deactivate = 'X'. CLEAR lt_return[]. ELSE. COMMIT WORK AND WAIT. EXIT. ENDIF. ENDDO. IF lv_asset IS NOT INITIAL AND cb_test IS INITIAL. ls_anlu-bukrs = lv_companycode. ls_anlu-anln1 = lv_asset. ls_anlu-anln2 = lv_subnumber. MODIFY anlu FROM ls_anlu. LOOP AT lt_depreciationareas INTO ls_depreciationareas WHERE deactivate <> 'X'. UPDATE anlb SET afabg = ls_depreciationareas-odep_start_date WHERE bukrs = lv_companycode AND anln1 = lv_asset AND anln2 = lv_subnumber AND afabe = ls_depreciationareas-area AND bdatu = '99991231'. ENDLOOP. ENDIF. LOOP AT lt_return INTO ls_return. ls_return-row = gs_data-row. APPEND ls_return TO gt_return. ENDLOOP. CLEAR: ls_anlu, ls_key, lv_createsubnumber, ls_generaldata, ls_generaldatax, ls_inventory, ls_inventoryx, ls_postinginformation, ls_postinginformationx, ls_timedependentdata, ls_timedependentdatax, ls_allocations, ls_allocationsx, ls_origin, ls_originx, ls_investacctassignmnt, ls_investacctassignmntx, lv_companycode, lv_asset, lv_subnumber, ls_assetcreated, lt_depreciationareas[], ls_depreciationareas, lt_depreciationareasx[], ls_depreciationareasx, lt_cumulatedvalues[], ls_cumulatedvalues, lt_return[], ls_return. ENDAT. ENDLOOP. ENDFORM. *----------------------------------------------------------------------*
martedì 13 dicembre 2016
Mapping dinamico da Excel a BAPI per creazione cespiti
Iscriviti a:
Commenti sul post (Atom)
Nessun commento:
Posta un commento