ZBCIMAC
De SAP ABAP en castellano
************************************************************************ * TITULO : Macros útiles * * DESCRIPCION : * * AUTOR : Andrés Picazo FECHA: 24/04/99 * * RUTA: ORDEN DE TRANSPORTE: * * ADDRANGO_EQ -> Rellena un rango con opciones de inclusión * ADDRANGO_BT -> Rellena un rango con opciones de inclusión entre 2 * valores. * * MODIFICACIONES * * ------------- * * FECHA NOMBRE RUTA ORDEN * * -------------------------------------------------------------------- * * dd.mm.yyyy username XXXXX-X sidK9nnnnn * ************************************************************************ TABLES: SSCRFIELDS ."CAMPOS EN LAS IMAGENES DE SELECCION DATA: v_btn LIKE smp_dyntxt. DATA: v_ucomm1 LIKE sy-ucomm, v_ucomm2 LIKE sy-ucomm, v_ucomm3 LIKE sy-ucomm, v_ucomm4 LIKE sy-ucomm, v_ucomm5 LIKE sy-ucomm. DATA : i_excel TYPE kcde_cells OCCURS 1000 WITH HEADER LINE, v_aux_filename LIKE rlgrap-filename, v_string_aux TYPE string, l_mac_cant1 like ekpo-menge, l_mac_cant2 like ekpo-menge. *&---------------------------------------------------------------------* *& Macro ADDRANGO_EQ *&---------------------------------------------------------------------* * Rellena un rango con opciones de inclusión * Ej: ADDRANGO_EQ P_BUKRS 'Z021'. *----------------------------------------------------------------------* DEFINE addrango_eq. clear &1. &1-option = 'EQ'. &1-sign = 'I'. &1-low = &2. append &1. END-OF-DEFINITION. *&---------------------------------------------------------------------* *& Macro ADDRANGO_BT *&---------------------------------------------------------------------* * Rellena un rango con opciones de inclusión entre 2 valores * Ej: ADDRANGO_EQ P_BUKRS 'Z001'. 'Z021'. *----------------------------------------------------------------------* DEFINE addrango_bt. clear &1. &1-option = 'BT'. &1-sign = 'I'. &1-low = &2. &1-high = &3. append &1. END-OF-DEFINITION. *&---------------------------------------------------------------------* *& Macro PARAM_CHECKBOX *&---------------------------------------------------------------------* * Linea de checkbox formateada *----------------------------------------------------------------------* DEFINE param_checkbox. selection-screen begin of line. selection-screen comment 1(30) &2 for field &1. parameters: &1 as checkbox default &3. selection-screen end of line. END-OF-DEFINITION. *&---------------------------------------------------------------------* *& Macro PARAM_RADIOBUTTON *&---------------------------------------------------------------------* * Linea de radio button formateada *----------------------------------------------------------------------* DEFINE param_radiobutton. selection-screen begin of line. selection-screen comment 1(30) for field &1. parameters: &1 radiobutton group &2. selection-screen end of line. END-OF-DEFINITION. DEFINE param_radiobutton_def. selection-screen begin of line. selection-screen comment 1(30) for field &1. parameters: &1 radiobutton group &2 default 'X'. selection-screen end of line. END-OF-DEFINITION. * Convierte una fecha en formato AAAAMMDD a formato DDMMAAAA DEFINE invertir_fecha. &2(2) = &1+6(2). &2+2(2) = &1+4(2). &2+4(4) = &1(4). END-OF-DEFINITION. * Convierte una fecha en formato DDMMAAAA a formato AAAAMMDD DEFINE invertir_fecha_inv. &2(4) = &1+4(4). &2+4(2) = &1+2(2). &2+6(2) = &1(2). END-OF-DEFINITION. DEFINE format_fecha. CALL FUNCTION 'CONVERT_DATE_TO_EXTERNAL' EXPORTING date_internal = &1 IMPORTING date_external = &2. END-OF-DEFINITION. * Permite seleccionar un fichero local DEFINE selecciona_fichero. CALL FUNCTION 'WS_FILENAME_GET' exporting def_filename = &1 def_path = '\' mask = ',*.*,*.*.' mode = 'O' title = 'Selecciona fichero' importing filename = &1 * rc = exceptions inv_winsys = 01 no_batch = 02 selection_cancel = 03 selection_error = 04. END-OF-DEFINITION. DEFINE leer_fichero_dat. free &2. v_string_aux = &1. CALL FUNCTION 'GUI_UPLOAD' exporting filename = v_string_aux filetype = 'ASC' has_field_separator = 'X' * HEADER_LENGTH = 0 * READ_BY_LINE = 'X' dat_mode = 'X' * CODEPAGE = ' ' * IGNORE_CERR = ABAP_TRUE * REPLACEMENT = '#' * CHECK_BOM = ' ' * IMPORTING * FILELENGTH = * HEADER = tables data_tab = &2 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. case sy-subrc. when 2. message e015(ba) with &1."no es posible abrir el fichero when 3. message e252(tq) with &1."error lectura en fichero & when 4. message e422(so)."tipo de fichero no válido & when 8. message I398(00) with 'Formato de datos incorrectos'. when others. message e252(tq) with &1."error lectura en fichero & endcase. endif. END-OF-DEFINITION. DEFINE quitar_ceros. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' EXPORTING input = &1 IMPORTING output = &1. END-OF-DEFINITION. DEFINE poner_ceros. CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' EXPORTING input = &1 IMPORTING output = &1. END-OF-DEFINITION. * Leer fichero Excel DEFINE lee_fichero_excel. v_aux_filename = &1. CALL FUNCTION 'KCD_EXCEL_OLE_TO_INT_CONVERT' EXPORTING filename = v_aux_filename i_begin_col = &2 i_begin_row = &3 i_end_col = &4 i_end_row = &5 TABLES intern = i_excel EXCEPTIONS inconsistent_parameters = 1 upload_ole = 2 others = 3. if sy-subrc ne 0. case sy-subrc. when 2. message e398(00) with 'Error al leer el fichero' v_aux_filename. when others. message e398(00) with 'Error' sy-subrc 'al cargar fichero Excel'. endcase. endif. sort i_excel. END-OF-DEFINITION. DEFINE col_excel. when &1. &2 = i_excel-value. END-OF-DEFINITION. * Llamada al mantenimiento estándard DEFINE mantener_tabla. CALL FUNCTION 'VIEW_MAINTENANCE_CALL' EXPORTING action = 'U' view_name = &1. * TABLES * DBA_SELLIST = SELTAB. END-OF-DEFINITION. * Llamada al mantenimiento incluyendo un filtro DATA: seltab LIKE vimsellist OCCURS 1 WITH HEADER LINE. DEFINE mantener_tabla_filtro. free seltab. seltab-viewfield = 'PGM'. seltab-value = &2. seltab-operator = 'LK'. append seltab. CALL FUNCTION 'VIEW_MAINTENANCE_CALL' EXPORTING action = 'U' view_name = &1 TABLES dba_sellist = seltab. END-OF-DEFINITION. * Convierte una fecha en formato AAAAMMDD a formato DDMMAAAA DEFINE invertir_fecha. &2(2) = &1+6(2). &2+2(2) = &1+4(2). &2+4(4) = &1(4). END-OF-DEFINITION. * Convierte una fecha en formato DDMMAAAA a formato AAAAMMDD DEFINE invertir_fecha_inv. &2(4) = &1+4(4). &2+4(2) = &1+2(2). &2+6(2) = &1(2). END-OF-DEFINITION. *&--------------------------------------------------------------------* *& CONVERTIR_A_KILOS *&--------------------------------------------------------------------* * Convierte unidades a kilos * -> &1 Material * -> &2 Cantidad * -> &3 Unidad origen * <- &4 Cantidad en kilos * <- &5 Unidad Kilos *---------------------------------------------------------------------* DEFINE convertir_a_kilos. if &3 = 'KG'. &4 = &2. &5 = &3. elseif &2 = 0. &4 = 0. &5 = 'KG'. else. CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT' EXPORTING i_matnr = &1 i_in_me = &3 i_out_me = 'KG' i_menge = &2 IMPORTING e_menge = &4 EXCEPTIONS error_in_application = 1 error = 2 others = 3. if sy-subrc = 0. &5 = 'KG'. else. &5 = &3. endif. endif. END-OF-DEFINITION. DEFINE convertir_unidad_mat. l_mac_cant1 = &2. l_mac_cant2 = &4. CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT' EXPORTING i_matnr = &1 i_in_me = &3 i_out_me = &5 i_menge = l_mac_cant1 IMPORTING e_menge = l_mac_cant2 EXCEPTIONS error_in_application = 1 error = 2 others = 3. &2 = l_mac_cant1. &4 = l_mac_cant2. END-OF-DEFINITION. DEFINE convertir_unidad_tiempo. if &2 ne &3. CALL FUNCTION 'MS_CONVERT_UNIT_TO_TIME' EXPORTING i_unit = &2 time_unit = &3 i_amount = &1 IMPORTING o_amount = &1 EXCEPTIONS unit_missing = 1 time_unit_missing = 2 no_conversion = 3 numerator_missing = 4 denominator_missing = 5 no_factors = 6 unit_wrong = 7 unit_not_time = 8 others = 9. endif. END-OF-DEFINITION. DEFINE traducir_unidad. CALL FUNCTION 'CONVERSION_EXIT_CUNIT_OUTPUT' exporting input = &1 * LANGUAGE = SY-LANGU importing * LONG_TEXT = output = &2 * SHORT_TEXT = exceptions unit_not_found = 1 others = 2. END-OF-DEFINITION. DEFINE traducir_unidad_input. CALL FUNCTION 'CONVERSION_EXIT_CUNIT_INPUT' exporting input = &1 * LANGUAGE = SY-LANGU importing output = &2 exceptions unit_not_found = 1 others = 2. END-OF-DEFINITION. define format_texto2importe. replace '.' with ' ' into &1. replace '.' with ' ' into &1. replace '.' with ' ' into &1. replace ',' with '.' into &1. condense &1 no-gaps. end-of-definition. * Ejemplo botón DEFINE fill_btn. v_btn-text = &1."Fuction text (menu) v_btn-icon_id = &2."Icon ID v_btn-icon_text = &3."Icon text v_btn-quickinfo = &4."Quick info v_btn-path = ' '."Direct path (one char) move v_btn to &5. END-OF-DEFINITION."FILL_BTN *selection-screen function key 1. "Button #1 - Hint * fill_btn 'Proceso automático' "Menu function text * '@BF@' "@BF@ or @AI@ or @5Y@ "Icon ID * 'Proceso automático' "Icon text * 'Proceso automático' "Quick info * sscrfields-functxt_01. * Ejemplo tabs *SELECTION-SCREEN BEGIN OF SCREEN 1400 AS SUBSCREEN. *SELECTION-SCREEN BEGIN OF BLOCK parau WITH FRAME TITLE text-tpa. * *SELECTION-SCREEN SKIP. * *SELECTION-SCREEN BEGIN OF LINE. *SELECTION-SCREEN POSITION 10. *SELECTION-SCREEN PUSHBUTTON 10(30) b_pau USER-COMMAND baf. *SELECTION-SCREEN END OF LINE. * *SELECTION-SCREEN SKIP. *SELECTION-SCREEN END OF BLOCK parau. *SELECTION-SCREEN END OF SCREEN 1400. *SELECTION-SCREEN BEGIN OF TABBED BLOCK tabs FOR 32 LINES. *SELECTION-SCREEN TAB (20) tabs1 USER-COMMAND ucomm1 * DEFAULT SCREEN 1100. *SELECTION-SCREEN TAB (22) tabs3 USER-COMMAND ucomm3 * DEFAULT SCREEN 1200. *SELECTION-SCREEN END OF BLOCK tabs.