Monday, June 25, 2007

Resumen de Ordenes de Transporte


El otro día, un amigo del trabajo me preguntó como podía saber si un programa había sido transportado a QAS y PRD y sobre todo cuando se habían realizado dichos transportes...Por supuesto, le dije que entrara al programa, le diera Utilidades - Versiones - Gestión de Versiones y revisara las ordenes...Esto es de por si muy tedioso...Así que con un poco de imaginación, desarrollé un programa que dado un programa o transacción, nos muestra las ordenes de transporte con las cuales está asociado, hacia donde fué transportado y cuando. El programa es un poco lento, así que cualquier recomendación de performance será más que bienvenida -:)



REPORT ZDUMMY_ATG_3 NO STANDARD PAGE HEADING MESSAGE-ID ZMM.

*-----------------------------------------------------------------*
* DECLARACION DE TYPES *
*-----------------------------------------------------------------*
TYPES: BEGIN OF TY_E071,
TRKORR TYPE E071-TRKORR,
OBJECT TYPE E071-OBJECT,
OBJ_NAME TYPE E071-OBJ_NAME,
END OF TY_E071.

TYPES: BEGIN OF TY_E071_ENTRY,
TRKORR TYPE E071-TRKORR,
END OF TY_E071_ENTRY.

TYPES: BEGIN OF TY_E070,
TRKORR TYPE E070-TRKORR,
TRSTATUS TYPE E070-TRSTATUS,
TARSYSTEM TYPE E070-TARSYSTEM,
AS4USER TYPE E070-AS4USER,
AS4DATE TYPE E070-AS4DATE,
AS4TIME TYPE E070-AS4TIME,
AS4TEXT TYPE E07T-AS4TEXT,
END OF TY_E070.

TYPES: BEGIN OF CTSLG_ACTION,
DATE LIKE TSTRFCOFIL-TRDATE,
TIME LIKE TSTRFCOFIL-TRTIME,
RC LIKE TSTRFCOFIL-RETCODE,
END OF CTSLG_ACTION,

CTSLG_ACTIONS TYPE SORTED TABLE OF CTSLG_ACTION
WITH UNIQUE KEY DATE TIME
INITIAL SIZE 2,
BEGIN OF CTSLG_STEP,
CLIENTID LIKE TSTRFCOFIL-TARCLIENT,
STEPID LIKE TSTRFCOFIL-FUNCTION,
RC LIKE TSTRFCOFIL-RETCODE,
ACTIONS TYPE CTSLG_ACTIONS,
END OF CTSLG_STEP,

CTSLG_STEPS TYPE CTSLG_STEP OCCURS 10,

BEGIN OF CTSLG_SYSTEM,
SYSTEMID LIKE TSTRFCOFIL-TARSYSTEM,
RC LIKE TSTRFCOFIL-RETCODE,
STEPS TYPE CTSLG_STEPS,
END OF CTSLG_SYSTEM,

CTSLG_SYSTEMS TYPE CTSLG_SYSTEM OCCURS 10,

BEGIN OF CTSLG_MERGELINE,
TRKORR TYPE TRKORR,
RC LIKE TSTRFCOFIL-RETCODE,
END OF CTSLG_MERGELINE,

CTSLG_MERGELINES TYPE CTSLG_MERGELINE OCCURS 0,

BEGIN OF CTSLG_COFILE,
EXISTS TYPE C,
IMPORTED TYPE C,
DEL_LINES_ONLY TYPE C,
SYSTEMS TYPE CTSLG_SYSTEMS,
MERGES TYPE CTSLG_MERGELINES,
RC TYPE I,
END OF CTSLG_COFILE.

*-----------------------------------------------------------------*
* DECLARACION DE TABLAS INTERNAS *
*-----------------------------------------------------------------*
DATA: T_E071 TYPE STANDARD TABLE OF TY_E071 WITH HEADER LINE,
T_E070 TYPE STANDARD TABLE OF TY_E070 WITH HEADER LINE,
T_E071_ENTRY TYPE STANDARD TABLE OF TY_E071_ENTRY
WITH HEADER LINE,
DOMA_VALUES TYPE STANDARD TABLE OF RPY_DVAL WITH HEADER LINE,
ES_COFILE TYPE STANDARD TABLE OF CTSLG_COFILE WITH HEADER LINE,
ES_SYSTEMS TYPE STANDARD TABLE OF CTSLG_SYSTEM,
WA_SYSTEMS TYPE CTSLG_SYSTEMS WITH HEADER LINE,
ES_STEPS TYPE CTSLG_STEPS,
WA_STEPS TYPE CTSLG_STEPS WITH HEADER LINE,
ES_ACTIONS TYPE CTSLG_ACTIONS,
WA_ACTIONS TYPE CTSLG_ACTIONS WITH HEADER LINE.

*-----------------------------------------------------------------*
* DECLARACION DE VARIABLES *
*-----------------------------------------------------------------*
DATA: W_PGMNA TYPE TSTC-PGMNA,
W_NAME(41) TYPE C,
W_FLAG TYPE C.

*-----------------------------------------------------------------*
* DECLARACION DE FIELD-SYMBOLS *
*-----------------------------------------------------------------*
FIELD-SYMBOLS: LIKE LINE OF T_E071,
LIKE LINE OF T_E070.

*-----------------------------------------------------------------*
* SELECTION-SCREEN *
*-----------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK DATA.
PARAMETERS:
P_TCODE LIKE TSTC-TCODE,
P_PGMNA LIKE TSTC-PGMNA.
SELECTION-SCREEN END OF BLOCK DATA.

*-----------------------------------------------------------------*
* START-OF-SELECTION *
*-----------------------------------------------------------------*
START-OF-SELECTION.

PERFORM VALIDAR_ENTRADA.
IF W_FLAG EQ SPACE.
PERFORM OBTENER_ORDENES.
PERFORM IMPRIMIR_ORDENES.
ENDIF.

*&----------------------------------------------------------------*
*& Form VALIDAR_ENTRADA *
*&----------------------------------------------------------------*
FORM VALIDAR_ENTRADA.

IF P_TCODE NE SPACE.
SELECT SINGLE PGMNA
INTO W_PGMNA
FROM TSTC
WHERE TCODE EQ P_TCODE.
IF SY-SUBRC EQ 0.
W_FLAG = SPACE.
ELSE.
MESSAGE S008 WITH 'La transacción solicitada no existe'.
W_FLAG = 'X'.
ENDIF.
ELSEIF P_PGMNA NE SPACE.
SELECT SINGLE PGMNA
INTO W_PGMNA
FROM TSTC
WHERE PGMNA EQ P_PGMNA.
IF SY-SUBRC EQ 0.
W_FLAG = SPACE.
ELSE.
MESSAGE S008 WITH 'El programa solicitado no existe'.
W_FLAG = 'X'.
ENDIF.
ENDIF.

ENDFORM. " VALIDAR_ENTRADA

*&----------------------------------------------------------------*
*& Form OBTENER_ORDENES *
*&----------------------------------------------------------------*
FORM OBTENER_ORDENES.

CALL FUNCTION 'RPY_DOMAIN_READ'
EXPORTING
DOMA_NAME = 'TRSTATUS'
LANGUAGE = SY-LANGU
TABLES
DOMA_VALUES = DOMA_VALUES
EXCEPTIONS
CANCELLED = 1
NOT_FOUND = 2
PERMISSION_ERROR = 3
ILLEGAL_TYPE = 4
OTHERS = 5.

CONCATENATE W_PGMNA '%'
INTO W_NAME.

SELECT TRKORR OBJECT OBJ_NAME
INTO TABLE T_E071
FROM E071
WHERE OBJ_NAME LIKE W_NAME
AND OBJECT EQ 'REPS'.

IF NOT T_E071[] IS INITIAL.
LOOP AT T_E071 ASSIGNING .
MOVE TO T_E071_ENTRY.
APPEND T_E071_ENTRY.
ENDLOOP.

SORT T_E071_ENTRY.
DELETE ADJACENT DUPLICATES FROM T_E071_ENTRY.

IF NOT T_E071_ENTRY[] IS INITIAL.
SELECT E070~TRKORR TRSTATUS TARSYSTEM
AS4USER AS4DATE AS4TIME
AS4TEXT
INTO TABLE T_E070
FROM ( E070 INNER JOIN E07T
ON E070~TRKORR EQ E07T~TRKORR )
FOR ALL ENTRIES IN T_E071_ENTRY
WHERE E070~TRKORR EQ T_E071_ENTRY-TRKORR
AND LANGU EQ SY-LANGU.

SORT T_E070 BY AS4DATE AS4TIME DESCENDING.

ENDIF.
ENDIF.

ENDFORM. " OBTENER_ORDENES

*&----------------------------------------------------------------*
*& Form IMPRIMIR_ORDENES *
*&----------------------------------------------------------------*
FORM IMPRIMIR_ORDENES.

DATA: W_TRKORR TYPE E070-TRKORR.

WRITE:1 'Orden',12 'Estado',22 'Destino',
31 'Nombre',92 'Fecha',104 'Hora'.

LOOP AT T_E070 ASSIGNING .

CLEAR: ES_COFILE.
REFRESH: ES_COFILE.

CALL FUNCTION 'TR_READ_GLOBAL_INFO_OF_REQUEST'
EXPORTING
IV_TRKORR = -TRKORR
IV_DIR_TYPE = 'T'
IMPORTING
ES_COFILE = ES_COFILE.

APPEND ES_COFILE.
READ TABLE ES_COFILE INDEX 1.
MOVE ES_COFILE-SYSTEMS TO ES_SYSTEMS.
LOOP AT ES_SYSTEMS INTO WA_SYSTEMS.
MOVE WA_SYSTEMS-STEPS TO ES_STEPS.
LOOP AT ES_STEPS INTO WA_STEPS WHERE STEPID EQ 'G'.
MOVE WA_STEPS-ACTIONS TO ES_ACTIONS.
LOOP AT ES_ACTIONS INTO WA_ACTIONS.
ENDLOOP.
READ TABLE DOMA_VALUES
WITH KEY DOMVALUE_L = -TRSTATUS.

IF W_TRKORR NE -TRKORR.
W_TRKORR = -TRKORR.
SKIP 1.
ENDIF.

WRITE:/1 -TRKORR,12 DOMA_VALUES-DDTEXT,
22 WA_SYSTEMS-SYSTEMID,31 -AS4TEXT,
92 WA_ACTIONS-DATE,104 WA_ACTIONS-TIME.
ENDLOOP.
ENDLOOP.

ENDLOOP.

ENDFORM. " IMPRIMIR_ORDENES





Technorati tags:

1 comment:

Antonio said...

Me acabas de dejar de piedra. Eres un gran maestro. Intento comprar tus libros pero la pagina me falla, no se cual es el motivo.