SAP PM BAPI IL01
From SapWiki
*&---------------------------------------------------------------------* *& Report ZPM_CREAR_UT *& *&---------------------------------------------------------------------* *& Descripcion : Creación de Ubicaciones Técnicas REPORT zpm_crear_ut. *--------------------------------------------------------------------* DATA: BEGIN OF gs_data OCCURS 0, funcloc TYPE bapi_itob_fl_sel_result-funcloc, " strind TYPE bapi_itob_fl_only-strind, " indicador de estructura de ubicación técnica category TYPE bapi_itob_fl_only-category, " tipo de ubicación técnica descript TYPE bapi_itob-descript, " denominación de la ubicación técnic authgrp TYPE bapi_itob-authgrp , " grupo de autorizaciones para objeto técnico obj_weight TYPE bapi_itob-obj_weight , " peso del objeto unit_of_wt TYPE bapi_itob-unit_of_wt, " unidad de peso obj_size TYPE bapi_itob-obj_size , " tamaño/dimensión inventory TYPE bapi_itob-inventory, " número de inventario start_from TYPE bapi_itob-start_from, " fecha de puesta en servicio de objeto técnico objecttype TYPE bapi_itob-objecttype, " clase de objeto técnico acquisval TYPE bapi_itob-acquisval , " valor de adquisición currency TYPE bapi_itob-currency , " clave de moneda acqdate TYPE bapi_itob-acqdate , " fecha de adquisición manfacture TYPE bapi_itob-manfacture, " fabricante del activo fijo mancountry TYPE bapi_itob-mancountry, " país de fabricación manmodel TYPE bapi_itob-manmodel, " denominación de tipo del fabricante constyear TYPE bapi_itob-constyear, " año de construcción constmonth TYPE bapi_itob-constmonth, " mes de construcción manparno TYPE bapi_itob-manparno, " número de pieza de fabricante manserno TYPE bapi_itob-manserno, " número de serie según el fabricante maintplant TYPE bapi_itob-maintplant, " centro de emplazamiento maintloc TYPE bapi_itob-maintloc , " emplazamiento del objeto de mantenimiento maintroom TYPE bapi_itob-maintroom, " local plsectn TYPE bapi_itob-plsectn, " Área de empresa * work_ctr TYPE crhd-arbpl, "bapi_itob-work_ctr, " puesto de trabajo pp_wkctr TYPE crhd-arbpl, "bapi_itob-pp_wkctr, " puesto de trabajo responsable en medidas de mantenimiento abcindic TYPE bapi_itob-abcindic, " indicador abc para objeto técnico sortfield TYPE bapi_itob-sortfield, " campo de clasificación comp_code TYPE bapi_itob-comp_code, " sociedad bus_area TYPE bapi_itob-bus_area, " división asset_no TYPE bapi_itob-asset_no , " número principal de activo fijo sub_number TYPE bapi_itob-sub_number, " subnúmero de activo fijo costcenter TYPE bapi_itob-costcenter, " centro de coste wbs_elem TYPE bapi_itob-wbs_elem, " elemento del plan de estructura de proyecto (elemento pep) standorder TYPE bapi_itob-standorder, " número de orden permanente settlorder TYPE bapi_itob-settlorder, " orden de liquidación planplant TYPE bapi_itob-planplant , " centro de planificación del mantenimiento plangroup TYPE bapi_itob-plangroup , " grupo planificador p.servicio cliente y mantenimiento * pp_wkctr TYPE crhd-arbpl, "bapi_itob-pp_wkctr, " puesto de trabajo responsable en medidas de mantenimiento work_ctr TYPE crhd-arbpl, "bapi_itob-work_ctr, " puesto de trabajo catprofile TYPE bapi_itob-catprofile, " perfil de catálogo eqinstall TYPE bapi_itob_fl_only-eqinstall, " montaje de equipos permitido en ubicación técnica supfloc TYPE bapi_itob_fl_only-supfloc, "ubicacion tecnica superior * STRIND type bapi_itob_fl_only-strind, * CATEGORY type bapi_itob_fl_only-category, eqsingle TYPE bapi_itob_fl_only-eqsingle, posnr TYPE bapi_itob_fl_only-posnr, END OF gs_data. DATA gt_data LIKE TABLE OF gs_data. DATA: BEGIN OF gs_header, colname TYPE scrtext_l, END OF gs_header. DATA gt_header LIKE TABLE OF gs_header. DATA ls_bapiret2 LIKE bapiret2. DATA decstel(2) TYPE c. DATA gd_tfile TYPE ibipparms-path. DATA: e1func_loc_create LIKE e1func_loc_create, e1bp_itob LIKE e1bp_itob, e1bp_itob_fl_only LIKE e1bp_itob_fl_only, functlocation LIKE bapi_itob_parms-funcloc_int, ls_data_general_exp LIKE bapi_itob, ls_data_specific_exp LIKE bapi_itob_fl_only, return LIKE bapiret2, external_number LIKE bapi_itob_parms-funcloc, labeling_system LIKE bapi_itob_parms-label_syst, ls_data_general LIKE bapi_itob, ls_data_specific LIKE bapi_itob_fl_only, t_edidd LIKE edidd OCCURS 0 WITH HEADER LINE, bapi_retn_info LIKE bapiret2 OCCURS 0 WITH HEADER LINE. TYPES: BEGIN OF ty_log, funcloc TYPE bapi_itob_fl_sel_result-funcloc, type TYPE bapi_mtype, message TYPE bapi_msg, END OF ty_log. DATA gt_log TYPE TABLE OF ty_log. DATA gs_log LIKE LINE OF gt_log. DATA ld_tplma LIKE itob-tplma. *--------------------------------------------------------------------* *--------------------------------------------------------------------* PARAMETERS: p_file TYPE string LOWER CASE OBLIGATORY. *--------------------------------------------------------------------* AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file. *--------------------------------------------------------------------* gd_tfile = p_file. CALL FUNCTION 'F4_FILENAME' EXPORTING field_name = 'P_FILE' IMPORTING file_name = gd_tfile. MOVE gd_tfile TO p_file. *--------------------------------------------------------------------* START-OF-SELECTION. *--------------------------------------------------------------------* PERFORM upload. *--------------------------------------------------------------------* END-OF-SELECTION. *--------------------------------------------------------------------* IF gt_data[] IS INITIAL. WRITE:/ 'No se seleccionaron datos'. RETURN. ENDIF. PERFORM crear_ubicacion_tecnica. PERFORM display_log. *&---------------------------------------------------------------------* *& Form select_data *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM crear_ubicacion_tecnica. DATA: ls_data_general_exp LIKE bapi_itob, ls_data_specific_exp LIKE bapi_itob_fl_only, ls_data_install LIKE bapi_itob_eq_install. DATA ld_monto TYPE bapicurr-bapicurr. DATA ld_equipo TYPE equnr. LOOP AT gt_data INTO gs_data. CLEAR: ls_data_specific_exp, ls_data_general_exp, * ls_DATA_INSTALL. ls_bapiret2. SELECT SINGLE objid INTO gs_data-work_ctr FROM crhd WHERE objty = 'A' AND arbpl = gs_data-work_ctr AND werks = gs_data-planplant. IF sy-subrc <> 0. CLEAR gs_data-work_ctr. ENDIF. SELECT SINGLE objid INTO gs_data-pp_wkctr FROM crhd WHERE objty = 'A' AND arbpl = gs_data-pp_wkctr AND werks = gs_data-maintplant. IF sy-subrc <> 0. CLEAR gs_data-pp_wkctr. ENDIF. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = gs_data-costcenter IMPORTING output = gs_data-costcenter. MOVE-CORRESPONDING gs_data TO ls_data_general. MOVE-CORRESPONDING gs_data TO ls_data_specific. CALL FUNCTION 'CONVERSION_EXIT_TPLNR_INPUT' EXPORTING input = gs_data-supfloc IMPORTING output = ls_data_specific-supfloc EXCEPTIONS not_found = 1 OTHERS = 2. IF sy-subrc <> 0. MOVE-CORRESPONDING gs_data TO gs_log. gs_log-type = 'E'. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO gs_log-message. APPEND gs_log TO gt_log. CONTINUE. ENDIF. * * MOVE ld_tplma TO gs_data-supfloc. MOVE gs_data-acquisval TO ld_monto. CALL FUNCTION 'BAPI_CURRENCY_CONV_TO_INTERNAL' EXPORTING currency = gs_data-currency amount_external = ld_monto max_number_of_digits = '15' IMPORTING amount_internal = ls_data_general_exp-acquisval. * RETURN = MOVE gs_data-funcloc TO external_number. CALL FUNCTION 'BAPI_FUNCLOC_CREATE' EXPORTING external_number = external_number * LABELING_SYSTEM = LABELING_SYSTEM data_general = ls_data_general data_specific = ls_data_specific IMPORTING functlocation = functlocation * DATA_GENERAL_EXP = LS_DATA_GENERAL_EXP data_specific_exp = ls_data_specific_exp return = ls_bapiret2 EXCEPTIONS OTHERS = 1. MOVE-CORRESPONDING gs_data TO gs_log. IF functlocation IS NOT INITIAL. CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' EXPORTING wait = 'X' * IMPORTING * RETURN = . gs_log-type = 'S'. * gs_log-funcloc = functlocation. gs_log-message = 'Ubicación Técnica creada con éxito'. * write:/ 'Se creo equipo', * FUNCTLOCATION, * 'copia de', * gs_data-funcloc. ELSE. * write:/ ls_bapiret2-message. gs_log-type = 'E'. gs_log-message = ls_bapiret2-message. ENDIF. APPEND gs_log TO gt_log. ENDLOOP. ENDFORM. "select_data *&---------------------------------------------------------------------* *& Form upload *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM upload. CALL FUNCTION 'GUI_UPLOAD' EXPORTING filename = p_file filetype = 'DAT' TABLES data_tab = gt_data 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. ENDFORM. "upload *&---------------------------------------------------------------------* *& Form display_log *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM display_log. TRY. cl_salv_table=>factory( IMPORTING r_salv_table = DATA(gr_table) CHANGING t_table = gt_log ). CATCH cx_salv_msg. ENDTRY. *... Enable Generic ALV functions DATA(gr_functions) = gr_table->get_functions( ). ** gr_functions->set_default( ). gr_functions->set_all( ). DATA(lr_columns) = gr_table->get_columns( ). * set column text TRY. DATA(lr_column) = lr_columns->get_column( 'EQUIPMENT_O' ). lr_column->set_long_text( 'Equipo Original' ). lr_column->set_medium_text( 'Equi.Ori.' ). lr_column->set_short_text( 'Equi.Ori.' ). CATCH cx_salv_not_found. CATCH cx_salv_existing. CATCH cx_salv_data_error. ENDTRY. *... Display table gr_table->display( ). ENDFORM. "display_log