You are on page 1of 3

TABLE CONTROL - MODULE_POOL

CODIGO FUENTE
*&---------------------------------------------------------------------*
*& Module Pool
ZTC_MEDICOS_AA
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
PROGRAM

ztc_medicos_aa.

TABLES: zmedico_aa.
CONTROLS tc TYPE TABLEVIEW USING SCREEN 0001. "Variable nombre de la table control TC
DATA columna TYPE cxtab_column." DECLARACION DE LAS COLUMNAS
DATA: it_me TYPE STANDARD TABLE OF zmedico_aa WITH HEADER LINE,"DECLARACION DE LA TABLA I
NTERNA
* del tipo de la tabla z creada en la se11.
wa_med LIKE LINE OF it_me. " WORK AREA DE LA TABLA INTERNA
DATA: ok_code TYPE sy-ucomm, " Variable que captura los eventos de la screen.
var TYPE sy-ucomm." Variable que captura los eventos de la screen.
DATA: init, mark. " variable para las filas de la table control.
*&---------------------------------------------------------------------*
*&
Module STATUS_0001 OUTPUT
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE status_0001 OUTPUT.
1
SET PF-STATUS 'STATUS_0001'.
SET TITLEBAR 'PANTALLA 1'.
"RECORRE LA TABLA Y MOSTRARLA EN PANTALLA /INIT/=VARIABLE
IF init IS INITIAL.
SELECT * FROM zmedico_aa INTO CORRESPONDING FIELDS OF TABLE it_me.
DESCRIBE TABLE it_me LINES tc-lines.
init = 'X'.
ENDIF.
ENDMODULE.
"status_0001 OUTPUT
*&---------------------------------------------------------------------*

*&
Module USER_COMMAND_0001 INPUT
*&---------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE user_command_0001 INPUT. 2
var = ok_code.
CLEAR ok_code.
CASE var.
* activacion de las filar y columas al seleccionarlas.
WHEN 'TOGGLE'. " activa los campo de la tabla para poderlos modificar.
LOOP AT tc-cols INTO columna WHERE index GT 0. " RECORRE LAS COLUMNAs
IF
columna-screen-input = '0'.
columna-screen-input = '1'.
ELSEIF
columna-screen-input = '1'.
columna-screen-input = '0'.
ENDIF.
MODIFY tc-cols FROM columna INDEX sy-tabix.
ENDLOOP.
*Ordesn Ascendente
WHEN 'SORT_UP'.
DATA: id_medico(100), nombre(100).
READ TABLE tc-cols INTO columna WITH KEY selected = 'X'.
SPLIT columna-screen-name AT '-' INTO nombre id_medico .
SORT it_me BY (id_medico) ASCENDING.
*Orden Descendente
WHEN 'SORT_DOWN'.
READ TABLE tc-cols INTO columna WITH KEY selected = 'X'.
SPLIT columna-screen-name AT '-' INTO nombre id_medico .
SORT it_me BY (id_medico) DESCENDING.
* Actualizacion
WHEN 'UPDATE'.
SELECT *
FROM zmedico_aa
INTO CORRESPONDING FIELDS OF TABLE it_me.
DESCRIBE TABLE it_me LINES tc-lines.
WHEN 'BACK'.
LEAVE PROGRAM.
WHEN 'CANCEL'. LEAVE PROGRAM.
WHEN 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.
" USER_COMMAND_0001 INPUT
*----------------------------------------------------------------------*
* MODULE leer_tabla INPUT
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
MODULE leer_tabla INPUT.
IF mark = 'X' AND var = 'DELETE'.
DELETE TABLE it_me FROM zmedico_aa.
DESCRIBE TABLE it_me LINES tc-lines.
PERFORM eliminar USING zmedico_aa.
ENDIF.
ENDMODULE.
" LEER_TABLA INPUT
*&---------------------------------------------------------------------*
*&
Form ELIMINAR
*&---------------------------------------------------------------------*
* SUBRUTINA que permite eliminar una fila de la table control
*----------------------------------------------------------------------*
FORM eliminar USING p_zmedico TYPE zmedico_aa . 3
DELETE FROM zmedico_aa

WHERE id_medico = p_zmedico-id_medico.


COMMIT WORK.
ENDFORM.
" ELIMINAR

SCREEN

CONCEPTOS BASICOS - SCREEN PAINTE