Powered By

Free XML Skins for Blogger

Powered by Blogger

Sunday, January 18, 2009

ABAP XML file to word document through SAP

Is there any way to convert XML file to word document through SAP?

The requirement is to import a XML file, convert it to word document and download it back to the same location.

The below program import an XML file to an internal table.

Also, take a look a this XML example: XML file example.

Moises Moreno

*----------------------------------------------------------------------*
* PROGRAMA : ZHR02597 Batch Input Datos Reloj Checador *
* leyendo un archivo XML *
* AUTOR : Moises Moreno De Leon (GALVAK) *
* FECHA : Junio 23, 2004 *
*----------------------------------------------------------------------*
REPORT ZHR02597 MESSAGE-ID ZG LINE-SIZE 80 LINE-COUNT 65
NO STANDARD PAGE HEADING.
*----------------------------------------------------------------------*
* Tablas *
TABLES:
PA0000, "HR Master Record: Infotype 0000 (Events)
PA0001, "HR Master Record: Infotype 0001 (Org. Assignment
PA0007, "HR Master Record: Infotype 0007 (Work Schedule)
PA0008, "HR Master Record: Infotype 0008 (Basic Pay)
PA2003, "HR Time Record: Infotype 2003 (Substitutions)
T508A, "Work Schedule Rules
T552A, "Monthly Work Schedules
T550A, "Daily Work Schedules
ZCATEGORIA. "Pay Scale Groups - Categorias
* Fin de Tablas *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Estructura *
DATA: BEGIN OF BDC_TABLE OCCURS 100. "Tabla para BIS
INCLUDE STRUCTURE BDCDATA.
DATA: END OF BDC_TABLE.
DATA BEGIN OF TH_MESSTAB OCCURS 10.
INCLUDE STRUCTURE BDCMSGCOLL.
DATA END OF TH_MESSTAB.
DATA: BEGIN OF TH_ARCHIVO OCCURS 100,
NUMERO(8), "P2011-PERNR Numero del empleado
FECHA LIKE SY-DATUM, "P2011-LDATE Logical date
AUSENTISMO(4), "
HORA(4), "P2011-LTIME Logical time
TERMINAL(3), "P2011-TERID Terminal ID
RAZON(4), "P2011-ABWGR Att/absence reason
TURNO(2), "PA2003-TPROG Daily work schedule
DEPARTAMENTO(4), "KOSTL Cost center
EMPLEADO2(8), "PA2003-VPERN Personnel no.to be
COORDINADOR_AUTORIZA(8),
IN_OUT(2) TYPE N,
END OF TH_ARCHIVO.
DATA: BEGIN OF TH_ERROR OCCURS 100,
NUMERO(5), "P2011-PERNR Numero del empleado
FECHA LIKE SY-DATUM, "P2011-LDATE Logical date
AUSENTISMO(4),
HORA(4), "P2011-LTIME Logical time
TERMINAL(3), "P2011-TERID Terminal ID
RAZON(4), "P2011-ABWGR Att/absence reason
TURNO(2), "PA2003-TPROG Daily work schedule
DEPARTAMENTO(4), "KOSTL Cost center
EMPLEADO2(5), "PA2003-VPERN Personnel no.to be
END OF TH_ERROR.

TYPES: BEGIN OF REG,
CAMBIO_TURNO,
DIA(10),
AUSENTISMO(4),
TURNO(2),
HORA(5),
TIPO,
INCIDENCIA(3),
CCOSTOS(4),
SOCIO_REEMPLAZA(8),
END OF REG.
DATA: REGISTRO TYPE REG OCCURS 0 WITH HEADER LINE.
TYPES: BEGIN OF EMPLEADO,
NUMERO(8),
REGISTRO LIKE REGISTRO OCCURS 0,
END OF EMPLEADO.
DATA: BEGIN OF CIERRE OCCURS 0,
EMPLEADO TYPE EMPLEADO,
END OF CIERRE.
DATA: CHECADAS TYPE REG OCCURS 0 WITH HEADER LINE.
* Fin de estrucutras *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Variables *
DATA: SW_ERROR, "Swich existencia de empleado
SW_I2002(1) TYPE C VALUE 'F',
WC_FECHA(10), "Fecha con formato dd.mm.aaaa
WC_DIA(2), "Filtra el día de la fecha
WC_MES(2), "Filtra el mes de la fecha
WC_YEAR(4), "Filtra el año de la fecha
WC_TIPO(2), "Tipo de Substitución
WC_TPR00(4), "Turno del empleado
WC_TURNO(4), "Turno del empleado GK(Turno)
WC_TURNO_SUST(4), "Turno Sustitucion
WC_TURNO_R(4), "Turno del RELOJ GK(Turno)
WC_TURNO_S(4), "Turno del SAP GK(Turno)
WC_CATEGORIA(8), "Categoria del empleado
WN_IN_OUT(2) TYPE N, "Tipo de evento IN/OUT
WN_PERNR LIKE PA2003-PERNR,
WI_BETRG1 LIKE ZCATEGORIA-BETRG, "Cantidad por turno Emple. 1
WI_BETRG2 LIKE ZCATEGORIA-BETRG, "Cantidad por turno Emple. 2
WT_TIEMPO LIKE P2011-LTIME, "Hora de chacada
WT_INICIO(4) TYPE N, "Hora de chacada I2002
WT_FINAL(4) TYPE N, "Hora de chacada I2002
WT_HORA LIKE P2011-LTIME VALUE '120000', "Sumar Doce horas
ARCH1(40) TYPE C VALUE '/users/interf/datos/hr/errores.txt',
WC_ARCHIVO(40) TYPE C, "Nombre del archivo
WI_LC TYPE I VALUE 0, "Contador lineas
WD_FECHA_DESC LIKE SY-DATUM, "Fecha de Descanso
WD_FECHA LIKE SY-DATUM,
WI_INDICE LIKE SY-TABIX, "Indice de la tabla interna
SW_DELETE(1) TYPE C VALUE 'F',
WC_REGISTRO1(35) TYPE C, "Registro de la tabla interna
WC_REGISTRO2(35) TYPE C. "Registro de la tabla interna
DATA: QID LIKE APQI-QID,
B-NAME LIKE RFPDO-ALLGBINA,
EXCEPT TYPE I.
DATA: ME TYPE REF TO CL_XML_DOCUMENT.
DATA: SUBRC LIKE SY-SUBRC.
DATA: GVK_MODE.
* Fin de variables *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Parámetros de Selección *
SELECTION-SCREEN BEGIN OF BLOCK BL_01 WITH FRAME TITLE TEXT-001.
PARAMETERS: ARCHIVO TYPE RLGRAP-FILENAME.
SELECTION-SCREEN END OF BLOCK BL_01.
* Fin de parametros de sleccion *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* AT SELECTION SCREEN *
AT SELECTION-SCREEN ON VALUE-REQUEST FOR ARCHIVO.
PERFORM ESPECIFICA_RUTA USING '0'.
* AT SELECTION SCREEN *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Start of selection *
START-OF-SELECTION.
CLEAR GVK_MODE.
GVK_MODE = 'N'.
IF SY-UNAME+0(6) NE 'GKRHUM' AND SY-UNAME+0(6) NE 'GK_961' AND
SY-UNAME+0(6) NE 'GKSIST' AND SY-UNAME NE 'EXUANL_MML'.
WRITE:/ 'Usuario no pertenece a GALVAK, S.A. de C.V.'.
LEAVE PROGRAM.
ENDIF.
PERFORM LEE_ARCHIVO_XML.
PERFORM LLENA_TH_ARCHIVO.
SORT TH_ARCHIVO BY NUMERO FECHA HORA.
PERFORM ELIMINA_DUPLICADOS.
LOOP AT TH_ARCHIVO.
PERFORM VALIDA_INFO.
MOVE ' ' TO : WC_DIA, WC_MES, WC_YEAR, WC_FECHA,
WC_TIPO, WC_TPR00, WC_TURNO, WC_CATEGORIA,
WT_TIEMPO, WN_PERNR, WN_IN_OUT, WT_INICIO,
WT_FINAL.
MOVE 0 TO: WI_LC.
IF SW_ERROR EQ '0'.
SELECT *
FROM PA0001
WHERE PERNR = TH_ARCHIVO-NUMERO.
ENDSELECT.
IF SY-SUBRC EQ 0.
IF TH_ARCHIVO-DEPARTAMENTO = PA0001-KOSTL+6(4).
TH_ARCHIVO-DEPARTAMENTO = ' '.
ENDIF.
ENDIF.
PERFORM FORMATO_FECHA.
MOVE TH_ARCHIVO-HORA TO WT_TIEMPO.
IF TH_ARCHIVO-EMPLEADO2 NE ' '.
WN_PERNR = TH_ARCHIVO-EMPLEADO2.
ELSE.
WN_PERNR = TH_ARCHIVO-NUMERO.
ENDIF.
IF TH_ARCHIVO-AUSENTISMO = 'DESC'.
CONCATENATE WD_FECHA+6(2) '.' WD_FECHA+4(2) '.' WD_FECHA(4)
INTO WC_FECHA.
PERFORM DATOS_DESC. "Actualiza 2003
ELSE.
PERFORM EVENTO_IN_OUT.
CONCATENATE WD_FECHA+6(2) '.' WD_FECHA+4(2) '.' WD_FECHA(4)
INTO WC_FECHA.
PERFORM TRANS_PA61.
CALL TRANSACTION 'PA61' USING BDC_TABLE MODE GVK_MODE
UPDATE 'S' MESSAGES INTO TH_MESSTAB.
IF SY-SUBRC EQ 0.
IF WC_TURNO <> WC_TPR00 OR
WC_TURNO <> WC_TURNO_SUST OR
WC_TURNO = 'DESC' OR
WC_TURNO = 'FREE'.
IF TH_ARCHIVO-IN_OUT = '01'.
PERFORM OTROS_DATOS. "Actualiza 2003
ENDIF.
ELSE.
ENDIF.
ELSE.
MOVE-CORRESPONDING TH_ARCHIVO TO TH_ERROR.
APPEND TH_ERROR.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
DESCRIBE TABLE TH_ERROR LINES WI_LC.
* Fin de start of selection *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* End of selection *
END-OF-SELECTION.
IF WI_LC NE 0.
PERFORM ARCHIVO_ERROR.
ENDIF.
PERFORM BDC_CLOSE USING EXCEPT.
MESSAGE I100.
* DELETE DATASET ARCHIVO. "moises 02.06.1999
* Fin de end of slection *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Funcion valida_info *
FORM VALIDA_INFO.
MOVE '0' TO SW_ERROR.
SELECT DISTINCT *
FROM PA0000
WHERE PERNR EQ TH_ARCHIVO-NUMERO.
EXIT.
ENDSELECT.
IF SY-SUBRC NE 0.
FORMAT INTENSIFIED OFF.
WRITE:/ 'El empleado ', TH_ARCHIVO-NUMERO,
' no esta dado de alta'.
FORMAT INTENSIFIED ON.
MOVE '1' TO SW_ERROR.
ENDIF.
ENDFORM.
* Fin de funcion valida_info *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Funcion formato_fecha *
FORM FORMATO_FECHA.
WC_DIA = TH_ARCHIVO-FECHA(2).
WC_MES = TH_ARCHIVO-FECHA+2(2).
WC_YEAR = TH_ARCHIVO-FECHA+4(4).
CONCATENATE WC_YEAR WC_MES WC_DIA INTO WD_FECHA.
ENDFORM.
* Fin de funicon formato_fecha *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Funcion evento_in_out *
FORM EVENTO_IN_OUT.
SELECT *
FROM PA0007
WHERE PERNR EQ WN_PERNR
AND BEGDA <= WD_FECHA
AND ENDDA >= WD_FECHA.
ENDSELECT.
IF SY-SUBRC EQ 0 AND PA0007-SCHKZ NE ' '.
SELECT *
FROM T508A
WHERE MOFID EQ 'GK'
AND SCHKZ = PA0007-SCHKZ.
ENDSELECT.
SELECT *
FROM T552A
WHERE SCHKZ EQ PA0007-SCHKZ
AND KJAHR EQ WC_YEAR
AND MONAT EQ WC_MES.
ENDSELECT.
IF SY-SUBRC EQ 0.
PERFORM BUSCA_DIA.
WC_TURNO = WC_TPR00.
PERFORM VERIFICA_P2003.
IF WC_TURNO_SUST IS INITIAL.
WC_TURNO_SUST = WC_TURNO.
ENDIF.
IF WC_TURNO EQ 'FREE' OR WC_TURNO EQ 'DESC'.
WC_TIPO = '02'.
IF TH_ARCHIVO-RAZON NE 'ETI ' AND
TH_ARCHIVO-RAZON NE 'EPM ' AND
TH_ARCHIVO-RAZON NE 'ERP ' AND
TH_ARCHIVO-RAZON NE 'STI ' AND
TH_ARCHIVO-RAZON NE 'SPM ' AND
TH_ARCHIVO-RAZON NE 'SRP '.
PERFORM VALIDA_SIGUIENTE_DIA.
IF WC_TPR00 = 'GM11' OR WC_TPR00 = 'GK01'.
WC_TURNO = WC_TPR00.
ENDIF.
ENDIF.
ELSEIF WC_TPR00 = 'DESC' OR WC_TPR00 = 'FREE'.
WC_TIPO = '02'.
ELSE.
WC_TIPO = '01'.
ENDIF.
ENDIF.
PERFORM TIEMPOS_EXTRA.
WC_TURNO_S = WC_TURNO.
IF TH_ARCHIVO-TURNO NE ' '.
IF TH_ARCHIVO-TURNO = 'S1' OR TH_ARCHIVO-TURNO = 'S2' OR
TH_ARCHIVO-TURNO = 'S3'.
CONCATENATE 'DE' TH_ARCHIVO-TURNO INTO WC_TURNO_R.
WC_TURNO = WC_TURNO_R.
ELSEIF TH_ARCHIVO-TURNO = 'T1' OR TH_ARCHIVO-TURNO = 'T2'.
CONCATENATE 'GK' TH_ARCHIVO-TURNO INTO WC_TURNO_R.
WC_TURNO = WC_TURNO_R.
ELSE.
IF TH_ARCHIVO-TURNO < 10.
CONCATENATE 'GK' TH_ARCHIVO-TURNO INTO WC_TURNO_R.
ELSEIF TH_ARCHIVO-TURNO > 10.
CONCATENATE 'GM' TH_ARCHIVO-TURNO INTO WC_TURNO_R.
ENDIF.
IF WC_TURNO NE WC_TURNO_R. " and th_archivo-razon = ' '. moises
WC_TURNO = WC_TURNO_R.
ENDIF.
ENDIF.
ENDIF.
* IF WC_TURNO EQ 'GM11' OR WC_TURNO = 'GK01'.
* WT_TIEMPO = WT_TIEMPO + WT_HORA.
* ENDIF.
SELECT *
FROM T550A
WHERE MOTPR EQ T508A-MOTPR
AND TPROG EQ WC_TURNO.
IF ( T550A-BTBEG <= WT_TIEMPO AND T550A-BTEND >= WT_TIEMPO ) OR
( TH_ARCHIVO-RAZON = 'IJ ' OR TH_ARCHIVO-RAZON = 'II ' OR
TH_ARCHIVO-RAZON = 'ESU ' OR TH_ARCHIVO-RAZON = 'EPM ' OR
TH_ARCHIVO-RAZON = 'ERP ' OR TH_ARCHIVO-RAZON = 'ETI ' ).
WN_IN_OUT = '01'.
IF WC_TURNO EQ 'GM11' OR WC_TURNO = 'GK01'.
* WD_FECHA = WD_FECHA + 1.
ENDIF.
ELSEIF ( T550A-ETBEG <= WT_TIEMPO AND
T550A-ETEND >= WT_TIEMPO ) OR
( TH_ARCHIVO-RAZON = 'FJ ' OR
TH_ARCHIVO-RAZON = 'FI ' OR
TH_ARCHIVO-RAZON = 'SSU ' OR
TH_ARCHIVO-RAZON = 'SPM ' OR
TH_ARCHIVO-RAZON = 'SRP ' OR
TH_ARCHIVO-RAZON = 'STI ' ).
WN_IN_OUT = '02'.
ELSE.
WN_IN_OUT = '02'.
ENDIF.
IF TH_ARCHIVO-RAZON = 'ETI ' AND
( T550A-BTBEG <= WT_TIEMPO AND T550A-BTEND >= WT_TIEMPO ).
WT_INICIO = WT_TIEMPO(4).
WT_FINAL = T550A-SOBEG(4).
SW_I2002 = 'T'.
ELSEIF TH_ARCHIVO-RAZON = 'STI ' AND
( T550A-ETBEG <= WT_TIEMPO AND T550A-ETEND >= WT_TIEMPO ).
WT_INICIO = T550A-SOEND(4).
WT_FINAL = WT_TIEMPO(4).
SW_I2002 = 'T'.
ENDIF.
ENDSELECT.
IF SW_I2002 = 'T'.
SW_I2002 = 'F'.
CONCATENATE WD_FECHA+6(2) '.' WD_FECHA+4(2) '.' WD_FECHA(4)
INTO WC_FECHA.
PERFORM ALTA_I2002.
ENDIF.
ENDIF.
ENDFORM.
* Fin de funcion evento_in_out *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Funcion busca_dia *
FORM BUSCA_DIA.
CASE WC_DIA.
WHEN 01.
MOVE T552A-TPR01 TO WC_TPR00.
WHEN 02.
MOVE T552A-TPR02 TO WC_TPR00.
WHEN 03.
MOVE T552A-TPR03 TO WC_TPR00.
WHEN 04.
MOVE T552A-TPR04 TO WC_TPR00.
WHEN 05.
MOVE T552A-TPR05 TO WC_TPR00.
WHEN 06.
MOVE T552A-TPR06 TO WC_TPR00.
WHEN 07.
MOVE T552A-TPR07 TO WC_TPR00.
WHEN 08.
MOVE T552A-TPR08 TO WC_TPR00.
WHEN 09.
MOVE T552A-TPR09 TO WC_TPR00.
WHEN 10.
MOVE T552A-TPR10 TO WC_TPR00.
WHEN 11.
MOVE T552A-TPR11 TO WC_TPR00.
WHEN 12.
MOVE T552A-TPR12 TO WC_TPR00.
WHEN 13.
MOVE T552A-TPR13 TO WC_TPR00.
WHEN 14.
MOVE T552A-TPR14 TO WC_TPR00.
WHEN 15.
MOVE T552A-TPR15 TO WC_TPR00.
WHEN 16.
MOVE T552A-TPR16 TO WC_TPR00.
WHEN 17.
MOVE T552A-TPR17 TO WC_TPR00.
WHEN 18.
MOVE T552A-TPR18 TO WC_TPR00.
WHEN 19.
MOVE T552A-TPR19 TO WC_TPR00.
WHEN 20.
MOVE T552A-TPR20 TO WC_TPR00.
WHEN 21.
MOVE T552A-TPR21 TO WC_TPR00.
WHEN 22.
MOVE T552A-TPR22 TO WC_TPR00.
WHEN 23.
MOVE T552A-TPR23 TO WC_TPR00.
WHEN 24.
MOVE T552A-TPR24 TO WC_TPR00.
WHEN 25.
MOVE T552A-TPR25 TO WC_TPR00.
WHEN 26.
MOVE T552A-TPR26 TO WC_TPR00.
WHEN 27.
MOVE T552A-TPR27 TO WC_TPR00.
WHEN 28.
MOVE T552A-TPR28 TO WC_TPR00.
WHEN 29.
MOVE T552A-TPR29 TO WC_TPR00.
WHEN 30.
MOVE T552A-TPR30 TO WC_TPR00.
WHEN 31.
MOVE T552A-TPR31 TO WC_TPR00.
ENDCASE.
ENDFORM.
* Fin de funcion busca_dia *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Funcion verifica_p2003 *
FORM VERIFICA_P2003.
DATA: WFECHA LIKE SY-DATUM.
CONCATENATE TH_ARCHIVO-FECHA+4(4) TH_ARCHIVO-FECHA+2(2)
TH_ARCHIVO-FECHA(2) INTO WFECHA.

CLEAR WC_TURNO_SUST.

SELECT SINGLE *
FROM PA2003
WHERE PERNR = WN_PERNR
AND BEGDA <= WFECHA
AND ENDDA >= WFECHA.
CHECK SY-SUBRC EQ 0.
IF PA2003-TPROG NE ' ' AND PA2003-TPROG NE WC_TURNO.
MOVE PA2003-TPROG TO: WC_TURNO, WC_TURNO_SUST.
ELSEIF PA2003-SCHKZ NE ' '.
SELECT *
FROM T552A
WHERE SCHKZ EQ PA2003-SCHKZ
AND KJAHR EQ WC_YEAR
AND MONAT EQ WC_MES.
ENDSELECT.
IF SY-SUBRC EQ 0.
PERFORM BUSCA_DIA.
IF WC_TPR00 NE WC_TURNO.
WC_TURNO = WC_TPR00.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. " VERIFICA_P2003
* Fin de funcion verifica_p2003 *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Funion valida_siguiente_dia *
FORM VALIDA_SIGUIENTE_DIA.
WD_FECHA_DESC = WD_FECHA + 1.
WC_DIA = WD_FECHA_DESC+6(2).
SELECT *
FROM T552A
WHERE SCHKZ EQ PA0007-SCHKZ
AND KJAHR EQ WC_YEAR
AND MONAT EQ WC_MES.
ENDSELECT.
IF SY-SUBRC EQ 0.
PERFORM BUSCA_DIA.
ENDIF.
ENDFORM. " VALIDA_SIGUIENTE_DIA
* Fin de funcion valida_siguiente_dia *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Funcion alta_i2002 *
FORM ALTA_I2002.
IF TH_ARCHIVO-TURNO = 'S1' OR TH_ARCHIVO-TURNO = 'S2' OR
TH_ARCHIVO-TURNO = 'S3'.
ELSE.
REFRESH BDC_TABLE.
PERFORM DYNPRO_START USING 'SAPMP50A' '1000'.
PERFORM DYNPRO_FIELD USING 'RP50G-PERNR' TH_ARCHIVO-NUMERO.
PERFORM DYNPRO_FIELD USING 'RP50G-CHOIC' '2002'.
PERFORM DYNPRO_FIELD USING 'RP50G-SUBTY' '0020'.
PERFORM DYNPRO_FIELD USING 'BDC_OKCODE' '=INS'. "MML QA&C 08.02.00
PERFORM DYNPRO_START USING 'MP200000' '2050'.
PERFORM DYNPRO_FIELD USING 'P2002-BEGDA' WC_FECHA.
PERFORM DYNPRO_FIELD USING 'P2002-ENDDA' WC_FECHA.
PERFORM DYNPRO_FIELD USING 'P2002-BEGUZ' WT_INICIO.
PERFORM DYNPRO_FIELD USING 'P2002-ENDUZ' WT_FINAL.
PERFORM DYNPRO_FIELD USING 'BDC_OKCODE' '=UPD'. "MML QA&C 08.02.00
CALL TRANSACTION 'PA61' USING BDC_TABLE MODE GVK_MODE UPDATE 'S'
MESSAGES INTO TH_MESSTAB.
IF SY-SUBRC NE 0.
MOVE-CORRESPONDING TH_ARCHIVO TO TH_ERROR.
APPEND TH_ERROR.
ENDIF.
ENDIF.
ENDFORM. " ALTA_I2002
* Fin de funcion alta_i2002 *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Funcion trnas_pa61 *
FORM TRANS_PA61.
REFRESH BDC_TABLE.
IF TH_ARCHIVO-AUSENTISMO IS INITIAL.
PERFORM DYNPRO_START USING 'SAPMP50A' '1000'.
PERFORM DYNPRO_FIELD USING 'RP50G-PERNR' TH_ARCHIVO-NUMERO.
PERFORM DYNPRO_FIELD USING 'RP50G-CHOIC' '2011'.
PERFORM DYNPRO_FIELD USING 'BDC_OKCODE' '=INS'. "MML QA&C 20.08.00
PERFORM DYNPRO_START USING 'MP200000' '2500'.
PERFORM DYNPRO_FIELD USING 'P2011-LDATE' WC_FECHA.
PERFORM DYNPRO_FIELD USING 'P2011-LTIME' WT_TIEMPO.
* PERFORM DYNPRO_FIELD USING 'P2011-SATZA' WN_IN_OUT.
PERFORM DYNPRO_FIELD USING 'P2011-SATZA' TH_ARCHIVO-IN_OUT.
IF TH_ARCHIVO-RAZON <> 'ARR'.
PERFORM DYNPRO_FIELD USING 'P2011-ABWGR' TH_ARCHIVO-RAZON.
ENDIF.
PERFORM DYNPRO_FIELD USING 'P2011-TERID' TH_ARCHIVO-TERMINAL.
PERFORM DYNPRO_FIELD USING 'BDC_OKCODE' '=UPD'. "MML QA&C 08.02.00
ELSE.
PERFORM DYNPRO_START USING 'SAPMP50A' '1000'.
PERFORM DYNPRO_FIELD USING 'RP50G-PERNR' TH_ARCHIVO-NUMERO.
PERFORM DYNPRO_FIELD USING 'RP50G-ENDDA' WC_FECHA.
PERFORM DYNPRO_FIELD USING 'RP50G-CHOIC' '2001'.
PERFORM DYNPRO_FIELD USING 'RP50G-SUBTY' TH_ARCHIVO-AUSENTISMO..
PERFORM DYNPRO_FIELD USING 'BDC_OKCODE' '=INS'. "MML QA&C 20.08.00
PERFORM DYNPRO_START USING 'MP200000' '2001'.
PERFORM DYNPRO_FIELD USING 'P2001-BEGDA' WC_FECHA.
PERFORM DYNPRO_FIELD USING 'P2001-ENDDA' WC_FECHA.
PERFORM DYNPRO_FIELD USING 'BDC_OKCODE' '=UPD'. "MML QA&C 08.02.00
ENDIF.
ENDFORM. " TRANS_PA61
* Fin de funcion trans_pa61 *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Funcion otros_datos *
FORM OTROS_DATOS.
IF WC_TURNO_SUST = 'DESC' OR WC_TURNO_SUST = 'FREE'.
PERFORM ELIMINA_SUSTITUCION.
ENDIF.

IF TH_ARCHIVO-TURNO = 'S1' OR TH_ARCHIVO-TURNO = 'S2' OR
TH_ARCHIVO-TURNO = 'S3'.
PERFORM GENERA_SUSTITUCION_S.
CALL TRANSACTION 'PA61' USING BDC_TABLE MODE GVK_MODE
UPDATE 'S' MESSAGES INTO TH_MESSTAB.
IF SY-SUBRC NE 0.
MOVE-CORRESPONDING TH_ARCHIVO TO TH_ERROR.
APPEND TH_ERROR.
ENDIF.
ELSE.
IF WN_IN_OUT = '01'. "or wn_in_out = '02'.
PERFORM GENERATE_BDC_DATA_1. "Actualiza 2003
CALL TRANSACTION 'PA61' USING BDC_TABLE MODE GVK_MODE
UPDATE 'S' MESSAGES INTO TH_MESSTAB.
IF SY-SUBRC NE 0.
MOVE-CORRESPONDING TH_ARCHIVO TO TH_ERROR.
APPEND TH_ERROR.
ENDIF.
ENDIF.
IF WN_IN_OUT = '02'.
IF TH_ARCHIVO-RAZON = 'SSU'.
PERFORM GENERATE_BDC_DATA_1.
CALL TRANSACTION 'PA61' USING BDC_TABLE MODE GVK_MODE
UPDATE 'S' MESSAGES INTO TH_MESSTAB.
IF SY-SUBRC NE 0.
MOVE-CORRESPONDING TH_ARCHIVO TO TH_ERROR.
APPEND TH_ERROR.
ENDIF.
ELSE.
PERFORM GENERATE_BDC_DATA_1.
CALL TRANSACTION 'PA61' USING BDC_TABLE MODE GVK_MODE
UPDATE 'S' MESSAGES INTO TH_MESSTAB.
IF SY-SUBRC NE 0.
MOVE-CORRESPONDING TH_ARCHIVO TO TH_ERROR.
APPEND TH_ERROR.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDFORM. " OTROS_DATOS
* Fin de funicion ortors_datos *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Funcion generate_bdc_data_1 *
FORM GENERATE_BDC_DATA_1.
REFRESH BDC_TABLE.
PERFORM DYNPRO_START USING 'SAPMP50A' '1000'.
PERFORM DYNPRO_FIELD USING 'RP50G-PERNR' TH_ARCHIVO-NUMERO.
PERFORM DYNPRO_FIELD USING 'RP50G-CHOIC' '2003'.
PERFORM DYNPRO_FIELD USING 'BDC_OKCODE' '=INS'. "MML QA&C 08.02.00
PERFORM DYNPRO_START USING 'MP200000' '2100'.
PERFORM DYNPRO_FIELD USING 'P2003-BEGDA' WC_FECHA.
PERFORM DYNPRO_FIELD USING 'P2003-ENDDA' WC_FECHA.
PERFORM DYNPRO_FIELD USING 'P2003-VTART' WC_TIPO.
IF TH_ARCHIVO-EMPLEADO2 NE ' ' AND
TH_ARCHIVO-EMPLEADO2 NE TH_ARCHIVO-NUMERO.
PERFORM BUSCA_CATEGORIA.
ENDIF.
IF WC_TURNO <> WC_TURNO_SUST.
PERFORM DYNPRO_FIELD USING 'P2003-TPROG' WC_TURNO.
ELSE.
IF TH_ARCHIVO-TURNO NE ' ' AND TH_ARCHIVO-TURNO NE WC_TURNO_S.
PERFORM DYNPRO_FIELD USING 'P2003-TPROG' WC_TURNO.
ENDIF.
IF WC_TURNO <> WC_TPR00.
PERFORM DYNPRO_FIELD USING 'P2003-TPROG' WC_TURNO.
ENDIF.
ENDIF.
IF WI_BETRG1 < WI_BETRG2. "Cambia categoria del Empleado 1
PERFORM BUSCA_CATEGORIA.
PERFORM DYNPRO_FIELD USING 'BDC_OKCODE' 'DIFP'.
PERFORM DYNPRO_START USING 'MP200000' '2221'.
PERFORM DYNPRO_FIELD USING 'P2APL-TRFGR' WC_CATEGORIA.
PERFORM DYNPRO_FIELD USING 'BDC_OKCODE' '/8'.
PERFORM DYNPRO_START USING 'MP200000' '2100'.
ENDIF.
IF TH_ARCHIVO-DEPARTAMENTO NE ' '.
PERFORM DYNPRO_FIELD USING 'BDC_OKCODE' 'PRIM'.
PERFORM DYNPRO_START USING 'SAPLHRTV' '0300'.
PERFORM DYNPRO_FIELD USING 'COBL-KOSTL' TH_ARCHIVO-DEPARTAMENTO.
PERFORM DYNPRO_FIELD USING 'BDC_OKCODE' '/8'.
PERFORM DYNPRO_START USING 'MP200000' '2100'.
ENDIF.
PERFORM DYNPRO_FIELD USING 'BDC_OKCODE' '=UPD'. "MML QA&C 08.02.00
ENDFORM. " GENERATE_BDC_DATA_1
* Fin de funcion generate_bdc_data_1 *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Funcion busca_categoria *
FORM BUSCA_CATEGORIA.
SELECT *
FROM PA0008
WHERE PERNR EQ TH_ARCHIVO-NUMERO. "Empleado 1
IF SY-SUBRC EQ 0.
SELECT *
FROM ZCATEGORIA
WHERE TRFGR EQ PA0008-TRFGR.
WI_BETRG1 = ZCATEGORIA-BETRG.
ENDSELECT.
ENDIF.
ENDSELECT.
SELECT *
FROM PA0008
WHERE PERNR EQ TH_ARCHIVO-EMPLEADO2. "Empleado 2
IF SY-SUBRC EQ 0.
SELECT *
FROM ZCATEGORIA
WHERE TRFGR EQ PA0008-TRFGR.
WI_BETRG2 = ZCATEGORIA-BETRG.
WC_CATEGORIA = ZCATEGORIA-TRFGR.
ENDSELECT.
ENDIF.
ENDSELECT.
ENDFORM.
* Fin de funcin busca_categoria *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Fucion archivo_error *
FORM ARCHIVO_ERROR.
OPEN DATASET ARCH1 FOR OUTPUT IN TEXT MODE.
IF SY-SUBRC NE 0.
STOP. EXIT.
ENDIF.
LOOP AT TH_ERROR.
TRANSFER TH_ERROR TO ARCH1.
ENDLOOP.
CLOSE DATASET ARCH1.
ENDFORM.
* Fin de archivo_error *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Funcion bdc_close *
FORM BDC_CLOSE USING EXCEPT.
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
NOT_OPEN = 1
QUEUE_ERROR = 2
OTHERS = 3.
EXCEPT = SY-SUBRC.
ENDFORM.
* Fin de funicon bdc_close *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Funcion dynpro_start *
FORM DYNPRO_START USING PROGRAM DYNPRO.
CLEAR BDC_TABLE.
BDC_TABLE-PROGRAM = PROGRAM.
BDC_TABLE-DYNPRO = DYNPRO.
BDC_TABLE-DYNBEGIN = 'X'.
APPEND BDC_TABLE.
ENDFORM. " DYNPRO_START
* Fin de funcion dynpro_start *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Funion dynpro_field *
FORM DYNPRO_FIELD USING FIELD VALUE.
CLEAR BDC_TABLE.
BDC_TABLE-FNAM = FIELD.
BDC_TABLE-FVAL = VALUE.
APPEND BDC_TABLE.
ENDFORM. " DYNPRO_FIELD
* Fin de funcion dypro_field *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Fucnion tiempos_extra *
FORM TIEMPOS_EXTRA.
IF TH_ARCHIVO-TURNO = 'S1' OR TH_ARCHIVO-TURNO = 'S2' OR
TH_ARCHIVO-TURNO = 'S3'.
CONCATENATE 'DE' TH_ARCHIVO-TURNO INTO WC_TURNO_R.
WC_TURNO = WC_TURNO_R.
ELSEIF TH_ARCHIVO-TURNO = 'T1' OR TH_ARCHIVO-TURNO = 'T2'.
CONCATENATE 'GK' TH_ARCHIVO-TURNO INTO WC_TURNO_R.
WC_TURNO = WC_TURNO_R.
ELSE.
IF ( TH_ARCHIVO-RAZON = 'ETI ' OR TH_ARCHIVO-RAZON = 'EPM ' OR
TH_ARCHIVO-RAZON = 'ERP ' ) AND TH_ARCHIVO-TURNO NE ' '.
IF TH_ARCHIVO-TURNO < 10.
CONCATENATE 'GK' TH_ARCHIVO-TURNO INTO WC_TURNO_R.
ELSEIF TH_ARCHIVO-TURNO > 10.
CONCATENATE 'GM' TH_ARCHIVO-TURNO INTO WC_TURNO_R.
ENDIF.
IF ( WC_TURNO = 'FREE' OR WC_TURNO = 'DESC' ).
IF WC_TURNO_R = 'GM13' OR WC_TURNO_R = 'GK03'.
PERFORM VALIDA_SIGUIENTE_DIA.
IF WC_TPR00 = 'GM11' OR WC_TPR00 = 'GK01'.
IF WC_TPR00 = 'GK01'.
WC_TURNO = 'GK01'.
ELSEIF WC_TPR00 = 'GM11'.
WC_TURNO = 'GM11'.
ENDIF.
ELSE.
WC_TURNO = WC_TURNO_R.
ENDIF.
ELSE.
WC_TURNO = WC_TURNO_R.
ENDIF.
ENDIF.
IF ( WC_TURNO NE 'FREE' OR WC_TURNO NE 'DESC' ).
IF WC_TURNO_R = 'GK02' AND WC_TURNO = 'GK03'.
WC_TURNO = 'GK03'.
ENDIF.
IF WC_TURNO_R = 'GK03' AND WC_TURNO = 'GK01'.
WC_TURNO = 'GK01'.
ENDIF.
IF WC_TURNO_R = 'GK01' AND WC_TURNO = 'GK02'.
WC_TURNO = 'GK02'.
ENDIF.
ENDIF.
ENDIF.
IF ( TH_ARCHIVO-RAZON = 'STI ' OR TH_ARCHIVO-RAZON = 'SPM ' OR
TH_ARCHIVO-RAZON = 'SRP ' ) AND TH_ARCHIVO-TURNO NE ' '.
IF TH_ARCHIVO-TURNO < 10.
CONCATENATE 'GK' TH_ARCHIVO-TURNO INTO WC_TURNO_R.
ELSEIF TH_ARCHIVO-TURNO > 10.
CONCATENATE 'GM' TH_ARCHIVO-TURNO INTO WC_TURNO_R.
ENDIF.
IF ( WC_TURNO = 'FREE' OR WC_TURNO = 'DESC' ).
IF WC_TURNO_R = 'GM11' OR WC_TURNO_R = 'GK01'.
WD_FECHA_DESC = WD_FECHA - 2.
PERFORM VALIDA_SIGUIENTE_DIA. "En realidad DIA ANTERIOR
IF WC_TPR00 = 'GM13' OR WC_TPR00 = 'GK03'.
IF WC_TPR00 = 'GK03'.
WC_TURNO = 'GK03'.
ELSEIF WC_TPR00 = 'GM13'.
WC_TURNO = 'GM13'.
ENDIF.
ELSE.
WC_TURNO = WC_TURNO_R.
ENDIF.
ELSE.
WC_TURNO = WC_TURNO_R.
ENDIF.
ENDIF.
IF ( WC_TURNO NE 'FREE' OR WC_TURNO NE 'DESC' ).
IF WC_TURNO_R = 'GK03' AND WC_TURNO = 'GK02'.
WC_TURNO = 'GK02'.
ENDIF.
IF WC_TURNO_R = 'GK01' AND WC_TURNO = 'GK03'.
WC_TURNO = 'GK03'.
ENDIF.
IF WC_TURNO_R = 'GK02' AND WC_TURNO = 'GK01'.
WC_TURNO = 'GK01'.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDFORM.
* Fin de funicon tiempos_extra *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Funcion elimina_duplicados *
FORM ELIMINA_DUPLICADOS.
DELETE ADJACENT DUPLICATES FROM TH_ARCHIVO.
ENDFORM.
* Fin de funcion elimina_duplicados *
*----------------------------------------------------------------------

*----------------------------------------------------------------------*
* Form LEE_ARCHIVO_XML *
FORM LEE_ARCHIVO_XML.
CREATE OBJECT ME.
REFRESH CIERRE.
CALL METHOD ME->CREATE_WITH_FILE
EXPORTING
FILENAME = ARCHIVO
RECEIVING
RETCODE = SUBRC.
CALL METHOD ME->GET_DATA
IMPORTING
RETCODE = SUBRC
CHANGING
DATAOBJECT = CIERRE[].
ENDFORM.
* Form LEE_ARCHIVO_XML *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* FORM ESPECIFICA_RUTA *
FORM ESPECIFICA_RUTA USING PAR_VALOR.
CASE PAR_VALOR.
WHEN '0'.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
MASK = 'C:\*.xml'
STATIC = 'X'
CHANGING
FILE_NAME = ARCHIVO.
WHEN '1'.
* CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
* EXPORTING
* MASK = 'C:\*.txt'
* STATIC = 'x'
* CHANGING
* FILE_NAME = DESCARGA.
ENDCASE.
ENDFORM.
* FORM ESPECIFICA_RUTA *
*----------------------------------------------------------------------

*----------------------------------------------------------------------*
* Form LLENA_TH_ARCHIVO *
FORM LLENA_TH_ARCHIVO.
CONSTANTS GVK_12HRS LIKE P2011-LTIME VALUE '120000'.
CONSTANTS GVK_1159 LIKE P2011-LTIME VALUE '115900'.
CONSTANTS GVK_0630 LIKE P2011-LTIME VALUE '063000'.
CONSTANTS GVK_0715 LIKE P2011-LTIME VALUE '071500'.
CONSTANTS GVK_1830 LIKE P2011-LTIME VALUE '183000'.
CONSTANTS GVK_1915 LIKE P2011-LTIME VALUE '191500'.
DATA: GVK_HORA LIKE P2011-LTIME.
DATA: GVK_FECHA LIKE SY-DATUM.
CLEAR CIERRE.
REFRESH TH_ARCHIVO.
LOOP AT CIERRE.
CLEAR TH_ARCHIVO.
CHECADAS[] = CIERRE-EMPLEADO-REGISTRO[].
LOOP AT CHECADAS.
CLEAR TH_ARCHIVO.
MOVE: CIERRE-EMPLEADO-NUMERO TO TH_ARCHIVO-NUMERO,
CHECADAS-INCIDENCIA TO TH_ARCHIVO-RAZON,
CHECADAS-CCOSTOS TO TH_ARCHIVO-DEPARTAMENTO,
CHECADAS-SOCIO_REEMPLAZA TO TH_ARCHIVO-EMPLEADO2.
CONCATENATE CHECADAS-DIA(2) CHECADAS-DIA+3(2)
CHECADAS-DIA+6(4) INTO TH_ARCHIVO-FECHA.
CONCATENATE CHECADAS-HORA(2) CHECADAS-HORA+3(2)
INTO TH_ARCHIVO-HORA.
IF CHECADAS-TURNO = 'S1' OR CHECADAS-TURNO = 'S2' OR
CHECADAS-TURNO = 'S3'.
MOVE CHECADAS-TURNO TO TH_ARCHIVO-TURNO.
IF CHECADAS-TIPO = 'E'.
MOVE 'ETI' TO TH_ARCHIVO-RAZON.
ELSEIF CHECADAS-TIPO = 'S'.
MOVE 'STI' TO TH_ARCHIVO-RAZON.
ENDIF.
ELSE.
MOVE CHECADAS-TURNO TO TH_ARCHIVO-TURNO.
ENDIF.

IF CHECADAS-CAMBIO_TURNO = 1.
MOVE CHECADAS-TURNO TO TH_ARCHIVO-TURNO.
ENDIF.
MOVE CHECADAS-AUSENTISMO TO TH_ARCHIVO-AUSENTISMO.
CASE CHECADAS-TURNO.
WHEN '01' OR 'S1'.
IF CHECADAS-TIPO = 'E'.
CLEAR GVK_FECHA.
CONCATENATE CHECADAS-DIA+6(4) CHECADAS-DIA+3(2)
CHECADAS-DIA(2)
INTO GVK_FECHA.
GVK_FECHA = GVK_FECHA + 1.
CONCATENATE GVK_FECHA+6(2) GVK_FECHA+4(2) GVK_FECHA(4)
INTO TH_ARCHIVO-FECHA.
ELSEIF CHECADAS-TIPO = 'S'.
GVK_HORA = TH_ARCHIVO-HORA.
IF GVK_HORA > GVK_1159.
CLEAR GVK_FECHA.
CONCATENATE CHECADAS-DIA+6(4) CHECADAS-DIA+3(2)
CHECADAS-DIA(2)
INTO GVK_FECHA.
GVK_FECHA = GVK_FECHA + 1.
CONCATENATE GVK_FECHA+6(2) GVK_FECHA+4(2)
GVK_FECHA(4)
INTO TH_ARCHIVO-FECHA.
ENDIF.
ENDIF.
CLEAR GVK_HORA.
GVK_HORA = TH_ARCHIVO-HORA.
GVK_HORA = GVK_HORA + GVK_12HRS.
CLEAR TH_ARCHIVO-HORA.
CONCATENATE GVK_HORA(2) GVK_HORA+2(2)
INTO TH_ARCHIVO-HORA.
WHEN 'T1'.
IF CHECADAS-TIPO = 'E'.
CLEAR GVK_FECHA.
CLEAR GVK_HORA.
CONCATENATE CHECADAS-DIA+6(4) CHECADAS-DIA+3(2)
CHECADAS-DIA(2)
INTO GVK_FECHA.
GVK_FECHA = GVK_FECHA + 1.
CONCATENATE GVK_FECHA+6(2) GVK_FECHA+4(2) GVK_FECHA(4)
INTO TH_ARCHIVO-FECHA.
GVK_HORA = TH_ARCHIVO-HORA.
GVK_HORA = GVK_HORA + GVK_12HRS.
CLEAR TH_ARCHIVO-HORA.
CONCATENATE GVK_HORA(2) GVK_HORA+2(2)
INTO TH_ARCHIVO-HORA.
ELSEIF CHECADAS-TIPO = 'S'.
MOVE 'STI' TO TH_ARCHIVO-RAZON.
GVK_HORA = TH_ARCHIVO-HORA.
IF GVK_HORA > GVK_1159.
CLEAR GVK_FECHA.
CONCATENATE CHECADAS-DIA+6(4) CHECADAS-DIA+3(2)
CHECADAS-DIA(2)
INTO GVK_FECHA.
GVK_FECHA = GVK_FECHA + 1.
CONCATENATE GVK_FECHA+6(2) GVK_FECHA+4(2)
GVK_FECHA(4)
INTO TH_ARCHIVO-FECHA.
ENDIF.
GVK_HORA = TH_ARCHIVO-HORA.
IF GVK_HORA BETWEEN GVK_0630 AND GVK_0715.
GVK_HORA = GVK_0630.
ENDIF.
GVK_HORA = GVK_HORA + GVK_12HRS.
CLEAR TH_ARCHIVO-HORA.
CONCATENATE GVK_HORA(2) GVK_HORA+2(2)
INTO TH_ARCHIVO-HORA.
ENDIF.
WHEN 'T2'.
IF CHECADAS-TIPO = 'S'.
MOVE 'STI' TO TH_ARCHIVO-RAZON.
CLEAR GVK_HORA.
GVK_HORA = TH_ARCHIVO-HORA.
IF GVK_HORA BETWEEN GVK_1830 AND GVK_1915.
GVK_HORA = GVK_1830.
CONCATENATE GVK_HORA(2) GVK_HORA+2(2)
INTO TH_ARCHIVO-HORA.
ENDIF.
ENDIF.
ENDCASE.
IF CHECADAS-TIPO = 'E'.
TH_ARCHIVO-IN_OUT = '01'.
ELSEIF CHECADAS-TIPO = 'S'.
TH_ARCHIVO-IN_OUT = '02'.
ENDIF.
APPEND TH_ARCHIVO.
ENDLOOP.
ENDLOOP.
ENDFORM.
* Form LLENA_TH_ARCHIVO *
*----------------------------------------------------------------------

*&---------------------------------------------------------------------*
*& Form DATOS_DESC
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DATOS_DESC.
REFRESH BDC_TABLE.
PERFORM DYNPRO_START USING 'SAPMP50A' '1000'.
PERFORM DYNPRO_FIELD USING 'RP50G-PERNR' TH_ARCHIVO-NUMERO.
PERFORM DYNPRO_FIELD USING 'RP50G-CHOIC' '2003'.
PERFORM DYNPRO_FIELD USING 'BDC_OKCODE' '=INS'. "MML QA&C 08.02.00
PERFORM DYNPRO_START USING 'MP200000' '2100'.
PERFORM DYNPRO_FIELD USING 'P2003-BEGDA' WC_FECHA.
PERFORM DYNPRO_FIELD USING 'P2003-ENDDA' WC_FECHA.
PERFORM DYNPRO_FIELD USING 'P2003-VTART' '01'.
PERFORM DYNPRO_FIELD USING 'P2003-TPROG' 'DESC'.
PERFORM DYNPRO_FIELD USING 'BDC_OKCODE' '=UPD'. "MML QA&C 08.02.00

CALL TRANSACTION 'PA61' USING BDC_TABLE MODE GVK_MODE UPDATE 'S'
MESSAGES INTO TH_MESSTAB.
IF SY-SUBRC NE 0.
MOVE-CORRESPONDING TH_ARCHIVO TO TH_ERROR.
APPEND TH_ERROR.
ENDIF.
ENDFORM. " DATOS_DESC
*

*&---------------------------------------------------------------------*
*& Form GENERA_SUSTITUCION_S
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM GENERA_SUSTITUCION_S.
REFRESH BDC_TABLE.
PERFORM DYNPRO_START USING 'SAPMP50A' '1000'.
PERFORM DYNPRO_FIELD USING 'RP50G-PERNR' TH_ARCHIVO-NUMERO.
PERFORM DYNPRO_FIELD USING 'RP50G-CHOIC' '2003'.
PERFORM DYNPRO_FIELD USING 'BDC_OKCODE' '=INS'. "MML QA&C 08.02.00
PERFORM DYNPRO_START USING 'MP200000' '2100'.
PERFORM DYNPRO_FIELD USING 'P2003-BEGDA' WC_FECHA.
PERFORM DYNPRO_FIELD USING 'P2003-ENDDA' WC_FECHA.
PERFORM DYNPRO_FIELD USING 'P2003-VTART' '02'.
IF TH_ARCHIVO-EMPLEADO2 NE ' ' AND
TH_ARCHIVO-EMPLEADO2 NE TH_ARCHIVO-NUMERO.
PERFORM BUSCA_CATEGORIA.
ENDIF.
IF WC_TURNO <> WC_TURNO_SUST.
PERFORM DYNPRO_FIELD USING 'P2003-TPROG' WC_TURNO.
ELSE.
IF TH_ARCHIVO-TURNO NE ' ' AND TH_ARCHIVO-TURNO NE WC_TURNO_S.
PERFORM DYNPRO_FIELD USING 'P2003-TPROG' WC_TURNO.
ENDIF.
ENDIF.
IF WI_BETRG1 < WI_BETRG2. "Cambia categoria del Empleado 1
PERFORM BUSCA_CATEGORIA.
PERFORM DYNPRO_FIELD USING 'BDC_OKCODE' 'DIFP'.
PERFORM DYNPRO_START USING 'MP200000' '2221'.
PERFORM DYNPRO_FIELD USING 'P2APL-TRFGR' WC_CATEGORIA.
PERFORM DYNPRO_FIELD USING 'BDC_OKCODE' '/8'.
PERFORM DYNPRO_START USING 'MP200000' '2100'.
ENDIF.
IF TH_ARCHIVO-DEPARTAMENTO NE ' '.
PERFORM DYNPRO_FIELD USING 'BDC_OKCODE' 'PRIM'.
PERFORM DYNPRO_START USING 'SAPLHRTV' '0300'.
PERFORM DYNPRO_FIELD USING 'COBL-KOSTL' TH_ARCHIVO-DEPARTAMENTO.
PERFORM DYNPRO_FIELD USING 'BDC_OKCODE' '/8'.
PERFORM DYNPRO_START USING 'MP200000' '2100'.
ENDIF.
PERFORM DYNPRO_FIELD USING 'BDC_OKCODE' '=UPD'. "MML QA&C 08.02.00
ENDFORM.

*----------------------------------------------------------------------*
* Form GENERATE_BDC_DATA_2 *
FORM GENERATE_BDC_DATA_2.
REFRESH BDC_TABLE.
PERFORM DYNPRO_START USING 'SAPMP50A' '1000'.
PERFORM DYNPRO_FIELD USING 'RP50G-PERNR' TH_ARCHIVO-NUMERO.
PERFORM DYNPRO_FIELD USING 'RP50G-CHOIC' '2003'.
PERFORM DYNPRO_FIELD USING 'BDC_OKCODE' '=INS'. "MML QA&C 08.02.00
PERFORM DYNPRO_START USING 'MP200000' '2100'.
PERFORM DYNPRO_FIELD USING 'P2003-BEGDA' WC_FECHA.
PERFORM DYNPRO_FIELD USING 'P2003-ENDDA' WC_FECHA.
PERFORM DYNPRO_FIELD USING 'P2003-VTART' WC_TIPO.
IF TH_ARCHIVO-EMPLEADO2 NE ' ' AND
TH_ARCHIVO-EMPLEADO2 NE TH_ARCHIVO-NUMERO.
PERFORM BUSCA_CATEGORIA.
ENDIF.
PERFORM DYNPRO_FIELD USING 'P2003-TPROG' WC_TURNO.
IF WI_BETRG1 < WI_BETRG2. "Cambia categoria del Empleado 1
PERFORM BUSCA_CATEGORIA.
PERFORM DYNPRO_FIELD USING 'BDC_OKCODE' 'DIFP'.
PERFORM DYNPRO_START USING 'MP200000' '2221'.
PERFORM DYNPRO_FIELD USING 'P2APL-TRFGR' WC_CATEGORIA.
PERFORM DYNPRO_FIELD USING 'BDC_OKCODE' '/8'.
PERFORM DYNPRO_START USING 'MP200000' '2100'.
ENDIF.
IF TH_ARCHIVO-DEPARTAMENTO NE ' '.
PERFORM DYNPRO_FIELD USING 'BDC_OKCODE' 'PRIM'.
PERFORM DYNPRO_START USING 'SAPLHRTV' '0300'.
PERFORM DYNPRO_FIELD USING 'COBL-KOSTL' TH_ARCHIVO-DEPARTAMENTO.
PERFORM DYNPRO_FIELD USING 'BDC_OKCODE' '/8'.
PERFORM DYNPRO_START USING 'MP200000' '2100'.
ENDIF.
PERFORM DYNPRO_FIELD USING 'BDC_OKCODE' '=UPD'. "MML QA&C 08.02.00
ENDFORM.
* Form GENERATE_BDC_DATA_2 *
*----------------------------------------------------------------------

*----------------------------------------------------------------------*
* Form ELIMINA_SUSTITUCION *
FORM ELIMINA_SUSTITUCION.
REFRESH BDC_TABLE.
PERFORM DYNPRO_START USING 'SAPMP50A' '1000'.
PERFORM DYNPRO_FIELD USING 'RP50G-PERNR' TH_ARCHIVO-NUMERO.
PERFORM DYNPRO_FIELD USING 'RP50G-BEGDA' WC_FECHA.
PERFORM DYNPRO_FIELD USING 'RP50G-ENDDA' WC_FECHA.
PERFORM DYNPRO_FIELD USING 'RP50G-CHOIC' '2003'.
PERFORM DYNPRO_FIELD USING 'BDC_OKCODE' '=DEL'.
PERFORM DYNPRO_START USING 'MP200000' '2100'.
PERFORM DYNPRO_FIELD USING 'BDC_OKCODE' '=UPDL'.
CALL TRANSACTION 'PA61' USING BDC_TABLE MODE GVK_MODE
UPDATE 'S' MESSAGES INTO TH_MESSTAB.
IF SY-SUBRC NE 0.
MOVE-CORRESPONDING TH_ARCHIVO TO TH_ERROR.
APPEND TH_ERROR.
ENDIF.
ENDFORM. " ELIMINA_SUSTITUCION
* Form ELIMINA_SUSTITUCION *
*----------------------------------------------------------------

ABAP program Sample XML Source Code For SAP

A XML source code for sap or abap.

*&---------------------------------------------------------------------*
*& Report ZULH_MM_RP_XMLtest001
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT ZULH_MM_RP_XMLtest001.

PARAMETERS: GK_RUTA TYPE RLGRAP-FILENAME DEFAULT 'C:\test01.XML'.

* TYPE TURNOS *
TYPES: BEGIN OF TURNOS,
LU LIKE T552A-TPR01,
MA LIKE T552A-TPR01,
MI LIKE T552A-TPR01,
JU LIKE T552A-TPR01,
VI LIKE T55AA-TPR01,
SA LIKE T552A-TPR01,
DO LIKE T552A-TPR01,
END OF TURNOS.
* TYPE TURNOS *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* TYPE SOCIO *
TYPES: BEGIN OF SOCIO,
NUMERO LIKE PERNR-PERNR,
REPOSICION LIKE PA0050-ZAUVE,
NOMBRE LIKE PA0002-VORNA,
TURNOS TYPE TURNOS,
END OF SOCIO.
* TYPE SOCIO *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* ESTRUCTURA ACCESOS *
DATA: BEGIN OF ACCESOS OCCURS 0,
SOCIO TYPE SOCIO,
END OF ACCESOS.
* ESTRUCTURA ACCESOS *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* START OF SELECTION *
START-OF-SELECTION.
PERFORM LLENA_ACCESOS.
PERFORM DESCARGA_XML.
END-OF-SELECTION.
* END OF SELECTION *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* FORM LLENA_ACCESOS *
FORM LLENA_ACCESOS.
REFRESH ACCESOS.
CLEAR ACCESOS.
MOVE: '45050' TO ACCESOS-SOCIO-NUMERO,
'MOISES MORENO' TO ACCESOS-SOCIO-NOMBRE,
'0' TO ACCESOS-SOCIO-REPOSICION,
'T1' TO ACCESOS-SOCIO-TURNOS-LU,
'T2' TO ACCESOS-SOCIO-TURNOS-MA,
'T3' TO ACCESOS-SOCIO-TURNOS-MI,
'T4' TO ACCESOS-SOCIO-TURNOS-JU,
'T5' TO ACCESOS-SOCIO-TURNOS-VI,
'T6' TO ACCESOS-SOCIO-TURNOS-SA,
'T7' TO ACCESOS-SOCIO-TURNOS-DO.
APPEND ACCESOS.
CLEAR ACCESOS.
MOVE: '45051' TO ACCESOS-SOCIO-NUMERO,
'RUTH PEÑA' TO ACCESOS-SOCIO-NOMBRE,
'0' TO ACCESOS-SOCIO-REPOSICION,
'T1' TO ACCESOS-SOCIO-TURNOS-LU,
'T2' TO ACCESOS-SOCIO-TURNOS-MA,
'T3' TO ACCESOS-SOCIO-TURNOS-MI,
'T4' TO ACCESOS-SOCIO-TURNOS-JU,
'T5' TO ACCESOS-SOCIO-TURNOS-VI,
'T6' TO ACCESOS-SOCIO-TURNOS-SA,
'T7' TO ACCESOS-SOCIO-TURNOS-DO.
APPEND ACCESOS.
ENDFORM.
* FORM LLENA_ACCESOS *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* FORM DESCARGA_XML *
FORM DESCARGA_XML.
DATA: L_DOM TYPE REF TO IF_IXML_ELEMENT,
M_DOCUMENT TYPE REF TO IF_IXML_DOCUMENT,
G_IXML TYPE REF TO IF_IXML,
W_STRING TYPE XSTRING,
W_SIZE TYPE I,
W_RESULT TYPE I,
W_LINE TYPE STRING,
IT_XML TYPE DCXMLLINES,
S_XML LIKE LINE OF IT_XML,
W_RC LIKE SY-SUBRC.

DATA: XML TYPE DCXMLLINES.
DATA: RC TYPE SY-SUBRC,
BEGIN OF XML_TAB OCCURS 0,
D LIKE LINE OF XML,
END OF XML_TAB.

CLASS CL_IXML DEFINITION LOAD.
G_IXML = CL_IXML=>CREATE( ).
CHECK NOT G_IXML IS INITIAL.
M_DOCUMENT = G_IXML->CREATE_DOCUMENT( ).
CHECK NOT M_DOCUMENT IS INITIAL.
WRITE: / 'Converting DATA TO DOM 1:'.
CALL FUNCTION 'SDIXML_DATA_TO_DOM'
EXPORTING
NAME = 'ACCESOS'
DATAOBJECT = ACCESOS[]
IMPORTING
DATA_AS_DOM = L_DOM
CHANGING
DOCUMENT = M_DOCUMENT
EXCEPTIONS
ILLEGAL_NAME = 1
OTHERS = 2.
IF SY-SUBRC = 0.
WRITE 'Ok'.
ELSE.
WRITE: 'Err =',
SY-SUBRC.
ENDIF.
CHECK NOT L_DOM IS INITIAL.
W_RC = M_DOCUMENT->APPEND_CHILD( NEW_CHILD = L_DOM ).
IF W_RC IS INITIAL.
WRITE 'Ok'.
ELSE.
WRITE: 'Err =',
W_RC.
ENDIF.
CALL FUNCTION 'SDIXML_DOM_TO_XML'
EXPORTING
DOCUMENT = M_DOCUMENT
IMPORTING
XML_AS_STRING = W_STRING
SIZE = W_SIZE
TABLES
XML_AS_TABLE = IT_XML
EXCEPTIONS
NO_DOCUMENT = 1
OTHERS = 2.
IF SY-SUBRC = 0.
WRITE 'Ok'.
ELSE.
WRITE: 'Err =',
SY-SUBRC.
ENDIF.
LOOP AT IT_XML INTO XML_TAB-D.
APPEND XML_TAB.
ENDLOOP.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
BIN_FILESIZE = W_SIZE
FILENAME = GK_RUTA
FILETYPE = 'BIN'
TABLES
DATA_TAB = XML_TAB
EXCEPTIONS
OTHERS = 10.
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.

WORK BENCH PPT FREE DOWNLOADS

ABAP WORK BENCH PPT FREE --> http://www.savefile.com/projects/808555773

VALIDATIONS PPT

ABAPVALIDATIONS PPT --> http://www.savefile.com/files/1173112

SAP Learn Object Oriented ABAP online and Download Tutorial

Learn Object Oriented ABAP online and Download Object Oriented ABAP Tutorial

http://www.savefile.com/files/768258

FREE DOWNLOAD ABAP Training Simulator

Abap Debugger Training

Building Web services:

part 1
part 2
part 3
part 4

and download the itutor(ITutor2.00.exe) to play all these simulator(*.sim) files.

SAP ABAP to Edit Text Symbols in INCLUDE RSAQEXCE

Description: Whenever some one faced problem in the existing report text elements as consistencies can check this program as a reference.

Problem Faced: The requirement is that i need to add a column to the report header. Here in my existing report text elements has inconsistencies why because is in the report called a subroutine(page) of include RSAQEXCE(Runtime Routines for Query Reports). Here they maintained the entire report header as one text symbol(GH0). If i tried to add a column & delete entire GH0 the program is not allowing to do. Instead it it regenrating the GH0 twice. Here while debugging i observed that the GH0 text symbol appears as 'GH000001'. So to overcome this problem externally written below separate program.

********************************************************************
*This Program is used to edit text symbols in RSAQEXCE
********************************************************************
REPORT ZDP_TEMP .

DATA: it_pool LIKE TABLE OF textpool.
DATA: WA_POOL like textpool.
DATA: VA_TEMP LIKE wa_pool-entry,
VA_TEMP1 LIKE wa_pool-entry.

START-OF-SELECTION.

* reads the text elemets from 'ZMIR00B' into an internal table
READ TEXTPOOL 'ZMIR00B' INTO it_pool LANGUAGE sy-langu.

* Loop the text symbol where key = 'GH000001' & modify it accordingly
* as per requirement to reflect it in your Report Output header
LOOP AT IT_POOL into wa_pool where key = 'GH000001'.

* Move all the textpool entry with key 'GH000001' to wa_pool-entry
VA_TEMP =
'SLoc Material Material d TCod MvT Mat.doc. Document '.
va_temp1 =
' h Material Slip GR/GI sl Rec. Price Quantity Total '.
clear: wa_pool-entry.
concatenate va_temp va_temp1
' Cost PO Rec. batch Receiving material Plan PARENT'
' Cost c G/L ac User nam Pstg date Time Order'
into wa_pool-entry.

* Delete all text elements of the program 'ZMIR00B' in the language
* "English":
delete textpool 'ZMIR00B' LANGUAGE sy-langu.

* Modify the TEXTPOOL i.e.,it_pool with wa_pool
modify it_pool from wa_pool.
endloop.

* Inserts the text elements from it_pool with language 'EN' to Program
* i.e.,'ZMIR00B' library
insert textpool 'ZMIR00B' from it_pool LANGUAGE sy-langu.

SAP ABAP SYNTAX FOR OOP-OBJECT ORIENTED

Template for making a class | Template for calling a class | Subclass | Template for calling a class | Using a class as a parameter for a method | Interfaces | Events

Template for making a class
Delete the parts that should not be used

******************************************
* Definition part
******************************************
CLASS xxx DEFINITION.
*------------------------------
* Public section
*------------------------------
PUBLIC SECTION.
TYPES:
DATA:
* Static data
CLASS-DATA:
* Methods
METHODS:
* Using the constructor to initialize parameters
constructor IMPORTING xxx type yyy,

* Method with parameters
mm1 IMPORTING iii TYPE ttt.
* Method without parameters
mm2.
* Static methods
CLASS-METHODS:

*---------------------------------------------------*
* Protected section. Also accessable by subclasses
*---------------------------------------------------
PROTECTED SECTION.
*---------------------------------------------------
* Private section. Not accessable by subclasses
*---------------------------------------------------
PRIVATE SECTION.
ENDCLASS.
******************************************
* Implementation part
******************************************
CLASS lcl_airplane IMPLEMENTATION.
METHOD constructor.
ENDMETHOD.

METHOD mm1.
ENDMETHOD.

METHOD mm2.
ENDMETHOD.

ENDCLASS.
Template for calling a class*
Create reference to class lcl_airplane
DATA: airplane1 TYPE REF TO lcl_airplane.

START-OF-SELECTION.
* Create instance using parameters in the cosntructor method
CREATE OBJECT airplane1 exporting im_name = 'Hansemand'
im_planetype = 'Boing 747'.
* Calling a method with parameters
CALL METHOD: airplane1->display_n_o_airplanes,
airplane1->display_attributes.
Subclass
CLASS xxx DEFINITION INHERITING FROM yyy.

Using af class as a parameter for a method
The class LCL_AIRPLANE is used as a parameter for method add_a_new_airplane:

METHODS:

add_a_new_airplane importing im_airplane TYPE REF to lcl_airplane.


Interfaces
In ABAP interfaces are implemented in addition to, and independently of classes. An interface only has a declaration part,
and do not have visibility sections. Components (Attributes, methods, constants, types) can be defined the same way as in classes.

· Interfaces are listed in the definition part lof the class, and must always be in the PUBLIC SECTION.
· Operations defined in the interface atre impemented as methods of the class. All methods of the interface
must be present in the implementation part of the class.
· Attributes, events, constants and types defined in the interface are automatically available to the class
carrying out the implementation.
· Interface components are addressed in the class by ~


Example of how to implement an interface:
INTERFACE lif_document

DATA: author type ref to lcl_author.
METHODS: print,

display.

ENDINTERFACE.
CLASS lcl_text_document DEFINITION.
PUBLIC SECTION.

INTERFACES lif_document.

METHODS display.

ENDCLASS.
CLASS lcl_text_document IMPLEMENTTION.

METHOD lif_document~print.

ENDMETHOD.
METHOD lif_document~display

ENDMETHOD.

METHOD display.

ENDMETHOD.

ENDCLASS.
REPORT zzz.
DATA: text_doc TYPE REF TO lcl_document.
Start-of-selection.

CREATE OBJECT text_doc.
CALL METHOD text_doc->lif_document~print.

CALL METHOD text_doc->lif_document~display.

CALL METHOD text_doc->display.

Events
For events of controls, refer to How to use controls.

· Events can only have EXPORTING parameters
· When an event is triggered, only those events handlers that have registered themselves
using SET HANDLER by this point of runtime are executed. You can register an event using
ACTIVATION 'X' and derigert it by using ACTIVATION 'SPACE'.
Defining events:
CLASS DEFINITION.
EVENTS: EXPORTING VALUE () TYPE type.
CLASS IMPLEMENTATION.

METHOD :

RAISE EVENT EXPORTING = .
Handling events:
CLASS DEFINITION.

METHODS: FOR OF ! IMPORTING ... SENDER.
Setting handler
SET HANDLER FOR ! FOR ALL INSTANCES

[ACTIVATION ]

ABAP Self Test FAQs

1) Authorization Objects
( this question has more than 1 answer )
a) Stored in User Master
b) Defines fields for a complex authority check
c) Grouped together in profiles
d) Covers up to 10 fields
e) Consists of up to 10 authorization objects

2) Authorization Checking
( this question has more than 1 answer )
a) performed with SELECT statement
b) performed with AUTHORITY-CHECK
c) determines if user has authority in master record
d) always refers to authorization profile
e) system admin defines which authorization checks are executed

3) Authorization
( this question has more than 1 answer )
a) contains value for field of an authorization object
b) defines fields for a complex authorization object
c) can be grouped together in profiles
d) always refer to a particular authorization
e) authorizations and profiles are stored in user master record

4) Using SM35 – in which case does the system check authorization:
( this question has more than 1 answer )
a) always
b) process / foreground
c) display errors only
d) process / background
e) system decides based on profile

5) Search Helps:
( this question has more than 1 answer )
a) called at POV
b) controls how fixed values are displayed when F4 is pressed
c) allow different views of info when help is required
d) object stored in data dictionary
e) field names starting with H_

6) Append Structures
( this question has more than 1 answer )
a) append to table without modifying table itself
b) can be assigned to several tables
c) same as substructure
d) use like any other structure
e) you must convert table once append is added

7) Check table
( this question has more than 1 answer )
a) value table assigned to a domain
b) internal table whose contents are used to check input values
c) table assigned to 1 or more fields if a FK (foreign key) table for checking input values
d) table for which a FK is defined
e) table to which a FK refers

8) Modify SAP objects:
( this question has more than 1 answer )
a) R/3 prevents modifications be user id DDIC and SAP*
b) Objects can be changed with registration
c) Register objects in OSS
d) Carry out modification without registration
e) Adjust modified object in upgrade

9) Activities required at upgrade when applying hot pack:
( this question has more than 1 answer )
a) adjust modified object
b) everything is automatic
c) release correction before update
d) abap dictionary tables, data elements and domains are adjusted during upgrade
e) abap dictionary objects not handled seperately

10) SELECT-OPTIONS COUNTRY FOR LFA1-LAND1:
What will internal table be?
a) LAND1
b) LFA1
c) COUNTRY
d) LFA1-LAND1

11) In program A function module F is called from function group G for the first time. Which one is correct:
a) coding of entire function group G is loaded in the roll area
b) global data from A can be accessed in F
c) A and F have common work areas for dictionary table
d) Function module F is called in a separate internal session
e) Function module F can not call any sessions

12) from transaction A you call transaction B with LEAVE TO TRANSACTION B:
a) internal system session opened for B
b) LEAVE can be used to return from B to A
c) Data from A can be accessed in B
d) A can pass data to B with export
e) A can pass data using SET

13) What is a SAP LUW:
a) a modularised unit in ABAP programs
b) all the updates for 1 SAP transaction
c) a logical grouping of database updates that should all be performed at the same time
d) the section of program code from setting a lock until it is released
e) all actions between first and last database update in transaction

14) Why do update functions have attributes of either START NOW (v1) or START DELAYED(V2):
a) define whether update task triggered immediately
b) combine synchronous and asynchronous updates
c) assign different priorities
d) take different speed of servers into account
e) enable reaction to termination n V1

15) Relationship between SAP transactions and database transactions:
a) each SAP corresponds to one database
b) update requests of one SAP transaction are distributed amongst several database transactions
c) one database group change request of several SAP
d) database transaction is an internal system representation of SAP transactions

Answers:
1) b, c, d
2) b, d
3) a, c
4) b, c, d
5) a, c, d
6) a, d
7) a, c, e
8) b, c, e
9) a, c, d
10) c
11) a
12) a, d, e
13) c
14) c
15) b

retrieve statistical data from the STAT file

REPORT ZSTATFILE LINE-SIZE 164.
************************************************************************
* This is an example of how to dig out some interesting performance
* and statistical data from the STAT file.
* The program creates a rank list of users based upon their database
* update and read activity. The results are the accumulated database
* time and row number per user for the different categories:
* insert/delete/modify and sequential/direct read. The results can be
* sorted by any of these categories.
* There are a lot more interesting data in the STAT file that can
* be used to write similar programs.

************************************************************************
DATA: STATISTIC_VERSION_USED LIKE SAPWLPSTRC-VERSION.
DATA: SORT_FIELD(20).

* General input parameters: from/to, client, STAT file path
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE T7.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(30) F1.
SELECTION-SCREEN POSITION 40.
PARAMETERS: FDAT LIKE SY-DATUM,
FTIM LIKE SY-UZEIT.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(30) F2.
SELECTION-SCREEN POSITION 40.
PARAMETERS: TDAT LIKE SY-DATUM,
TTIM LIKE SY-UZEIT.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(30) F4.
SELECTION-SCREEN POSITION 40.
PARAMETERS: CLI LIKE SY-MANDT.
SELECTION-SCREEN END OF LINE.
*SELECTION-SCREEN BEGIN OF LINE.
*SELECTION-SCREEN COMMENT 1(35) F3.
*SELECTION-SCREEN POSITION 40.
*PARAMETERS: FILE(128) LOWER CASE.
*SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK B1.

* Sort order input
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE T5.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(30) F5.
SELECTION-SCREEN POSITION 40.
PARAMETERS: ASC RADIOBUTTON GROUP ORD,
DESC RADIOBUTTON GROUP ORD.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK B2.

* Sort criteria input
SELECTION-SCREEN BEGIN OF BLOCK B3 WITH FRAME TITLE T6.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(30) T1.
SELECTION-SCREEN POSITION 62.
PARAMETERS: A1 RADIOBUTTON GROUP SORT.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(55) T2.
SELECTION-SCREEN POSITION 62.
PARAMETERS: A2 RADIOBUTTON GROUP SORT.
PARAMETERS: A3 RADIOBUTTON GROUP SORT.
SELECTION-SCREEN POSITION 67.
PARAMETERS: A4 RADIOBUTTON GROUP SORT.
PARAMETERS: A5 RADIOBUTTON GROUP SORT.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(55) T3.
SELECTION-SCREEN POSITION 62.
PARAMETERS: A6 RADIOBUTTON GROUP SORT.
PARAMETERS: A7 RADIOBUTTON GROUP SORT.
SELECTION-SCREEN POSITION 67.
PARAMETERS: A8 RADIOBUTTON GROUP SORT.
PARAMETERS: A9 RADIOBUTTON GROUP SORT.
SELECTION-SCREEN POSITION 72.
PARAMETERS: AA RADIOBUTTON GROUP SORT.
PARAMETERS: AB RADIOBUTTON GROUP SORT.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(50) T4.
SELECTION-SCREEN POSITION 62.
PARAMETERS: AC RADIOBUTTON GROUP SORT.
PARAMETERS: AD RADIOBUTTON GROUP SORT.
SELECTION-SCREEN POSITION 67.
PARAMETERS: AE RADIOBUTTON GROUP SORT.
PARAMETERS: AF RADIOBUTTON GROUP SORT.
SELECTION-SCREEN POSITION 72.
PARAMETERS: AG RADIOBUTTON GROUP SORT.
PARAMETERS: AH RADIOBUTTON GROUP SORT.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK B3.

*Internal tables
DATA: BEGIN OF V1_NORMAL_RECORDS OCCURS 100.
INCLUDE STRUCTURE SAPWLSTATR.
DATA: END OF V1_NORMAL_RECORDS.
DATA: BEGIN OF V2_NORMAL_RECORDS OCCURS 100.
INCLUDE STRUCTURE SAPWLPFNRM.
DATA: END OF V2_NORMAL_RECORDS.

DATA: BEGIN OF SUM OCCURS 100,
ACCOUNT(32),
READSEQREC TYPE I,
READSEQTI TYPE I,
READDIRREC TYPE I,
READDIRTI TYPE I,
UPDREC TYPE I,
UPDTI TYPE I,
DELREC TYPE I,
DELTI TYPE I,
INSREC TYPE I,
INSTI TYPE I,
SUM_RD_ROW TYPE I,
SUM_RD_TIM TYPE I,
SUM_MOD_ROW TYPE I,
SUM_MOD_TIM TYPE I,
SUM_ALL_ROW TYPE I,
SUM_ALL_TIM TYPE I,
END OF SUM.

*Initialize the selection screen
INITIALIZATION.
T1 = 'User Name and Report Name'.
T2 = 'READ: Sequential(row/time) Direct(row/time)'.
T3 = 'Update(row/time) Delete(row/time) Insert(row/time)'.
T4 = 'SUM: Read(row/time) Modify(row/time) All(row/time)'.
T5 = 'Sort'.
T6 = 'By'.
T7 = 'Period, Client and STAT file'.

F1 = 'From: (date/time)'.
F2 = 'To: (date/time)'.
* F3 = 'STAT file path(only for old stat)'.
F4 = 'Client'.
F5 = 'Ascending/Descending'.

FDAT = SY-DATUM. FTIM = SY-UZEIT.
FDAT = FDAT - 1. TTIM = SY-UZEIT.
TDAT = SY-DATUM.
CLI = SY-MANDT.

* Write a page header
TOP-OF-PAGE.
WRITE: / 'User and Report ' COLOR 2,
34(15) 'Sequential read' COLOR 2,
50(15) 'Direct read' COLOR 2,
66(15) 'Update' COLOR 2,
82(15) 'Delete' COLOR 2,
98(15) 'Insert' COLOR 2,
114(15) 'Sum Read' COLOR 5,
130(15) 'Sum Modify' COLOR 5,
146(15) 'Sum All' COLOR 6.

WRITE: / 'name' COLOR 2,
34(6) 'rows' COLOR 2,
41(8) 'time(ms)' COLOR 2,
50(6) 'rows' COLOR 2,
57(8) 'time(ms)' COLOR 2,
66(6) 'rows' COLOR 2,
73(8) 'time(ms)' COLOR 2,
82(6) 'rows' COLOR 2,
89(8) 'time(ms)' COLOR 2,
98(6) 'rows' COLOR 2,
105(8) 'time(ms)' COLOR 2,
114(6) 'rows' COLOR 5,
121(8) 'time(ms)' COLOR 5,
130(6) 'rows' COLOR 5,
137(8) 'time(ms)' COLOR 5,
146(6) 'rows' COLOR 6,
153(8) 'time(ms)' COLOR 6.

* Main
START-OF-SELECTION.
* Figure out the sort field name
IF A1 = 'X'.
SORT_FIELD = 'ACCOUNT'.
ELSEIF A2 = 'X'.
SORT_FIELD = 'READSEQREC'.
ELSEIF A3 = 'X'.
SORT_FIELD = 'READSEQTI'.
ELSEIF A4 = 'X'.
SORT_FIELD = 'READDIRREC'.
ELSEIF A5 = 'X'.
SORT_FIELD = 'READDIRTI'.
ELSEIF A6 = 'X'.
SORT_FIELD = 'UPDREC'.
ELSEIF A7 = 'X'.
SORT_FIELD = 'UPDTI'.
ELSEIF A8 = 'X'.
SORT_FIELD = 'DELREC'.
ELSEIF A9 = 'X'.
SORT_FIELD = 'DELTI'.
ELSEIF AA = 'X'.
SORT_FIELD = 'INSREC'.
ELSEIF AB = 'X'.
SORT_FIELD = 'INSTI'.
ELSEIF AC = 'X'.
SORT_FIELD = 'SUM_RD_ROW'.
ELSEIF AD = 'X'.
SORT_FIELD = 'SUM_RD_TIM'.
ELSEIF AE = 'X'.
SORT_FIELD = 'SUM_MOD_ROW'.
ELSEIF AF = 'X'.
SORT_FIELD = 'SUM_MOD_TIM'.
ELSEIF AG = 'X'.
SORT_FIELD = 'SUM_ALL_ROW'.
ELSEIF AH = 'X'.
SORT_FIELD = 'SUM_ALL_TIM'.
ENDIF.

CALL FUNCTION 'SAPWL_STATREC_READ_FILE'
EXPORTING
READ_CLIENT = CLI
READ_END_DATE = TDAT
READ_END_TIME = TTIM
READ_START_DATE = FDAT
READ_START_TIME = FTIM
* STATISTIC_FILE = FILE
IMPORTING
STATISTIC_VERSION_USED = STATISTIC_VERSION_USED
TABLES
V1_NORMAL_RECORDS = V1_NORMAL_RECORDS
V2_NORMAL_RECORDS = V2_NORMAL_RECORDS.

LOOP AT V2_NORMAL_RECORDS.
V2_NORMAL_RECORDS-READSEQTI = V2_NORMAL_RECORDS-READSEQTI / 1000.
V2_NORMAL_RECORDS-READDIRTI = V2_NORMAL_RECORDS-READDIRTI / 1000.
V2_NORMAL_RECORDS-UPDTI = V2_NORMAL_RECORDS-UPDTI / 1000.
V2_NORMAL_RECORDS-DELTI = V2_NORMAL_RECORDS-DELTI / 1000.
V2_NORMAL_RECORDS-INSTI = V2_NORMAL_RECORDS-INSTI / 1000.
MODIFY V2_NORMAL_RECORDS.
ENDLOOP.

LOOP AT V1_NORMAL_RECORDS.
V1_NORMAL_RECORDS-READSEQTI = V1_NORMAL_RECORDS-READSEQTI / 1000.
V1_NORMAL_RECORDS-READDIRTI = V1_NORMAL_RECORDS-READDIRTI / 1000.
V1_NORMAL_RECORDS-UPDTI = V1_NORMAL_RECORDS-UPDTI / 1000.
V1_NORMAL_RECORDS-DELTI = V1_NORMAL_RECORDS-DELTI / 1000.
V1_NORMAL_RECORDS-INSTI = V1_NORMAL_RECORDS-INSTI / 1000.
MODIFY V1_NORMAL_RECORDS.
ENDLOOP.

LOOP AT V2_NORMAL_RECORDS.
MOVE-CORRESPONDING V2_NORMAL_RECORDS TO SUM.
CONCATENATE V2_NORMAL_RECORDS-ACCOUNT V2_NORMAL_RECORDS-CUA_PROG
INTO SUM-ACCOUNT SEPARATED BY SPACE.
COLLECT SUM.
ENDLOOP.

LOOP AT V1_NORMAL_RECORDS.
MOVE-CORRESPONDING V1_NORMAL_RECORDS TO SUM.
CONCATENATE V1_NORMAL_RECORDS-ACCOUNT V1_NORMAL_RECORDS-CUA_PROG
INTO SUM-ACCOUNT SEPARATED BY SPACE.
COLLECT SUM.
ENDLOOP.

LOOP AT SUM.
SUM-SUM_RD_ROW = SUM-READSEQREC + SUM-READDIRREC.
SUM-SUM_RD_TIM = SUM-READSEQTI + SUM-READDIRTI.
SUM-SUM_MOD_ROW = SUM-UPDREC + SUM-DELREC + SUM-INSREC.
SUM-SUM_MOD_TIM = SUM-UPDTI + SUM-DELTI + SUM-INSTI.
SUM-SUM_ALL_ROW = SUM-SUM_RD_ROW + SUM-SUM_MOD_ROW.
SUM-SUM_ALL_TIM = SUM-SUM_RD_TIM + SUM-SUM_MOD_TIM.
MODIFY SUM.
ENDLOOP.

IF ASC = 'X'.
SORT SUM BY (SORT_FIELD) ASCENDING.
ELSE.
SORT SUM BY (SORT_FIELD) DESCENDING.
ENDIF.


LOOP AT SUM.
WRITE: / SUM-ACCOUNT,
34(7) SUM-READSEQREC,
42(7) SUM-READSEQTI,
54(7) SUM-READDIRREC,
58(7) SUM-READDIRTI,
66(7) SUM-UPDREC,
74(7) SUM-UPDTI,
82(7) SUM-DELREC,
90(7) SUM-DELTI,
98(7) SUM-INSREC,
106(7) SUM-INSTI,
114(7) SUM-SUM_RD_ROW,
122(7) SUM-SUM_RD_TIM,
130(7) SUM-SUM_MOD_ROW,
138(7) SUM-SUM_MOD_TIM,
146(7) SUM-SUM_ALL_ROW,
154(7) SUM-SUM_ALL_TIM.

ENDLOOP.
*-------- END OF PROGRAM --------------------------------

SAP ABAP LOCKS

Using the SAP Locking Facility

Definition of an SAP lock

The description of an SAP lock to a table is made via the lock condition
and the lock mode.

The lock condition is a logical condition for the lines of the table to
be locked. It describes the area of the table which the lock is to
protect from competitive access. To avoid the administration of the lock
becoming complicated, the lock condition can not be formulated as freely
as the WHERE clauses: only fully qualified key fields related by AND
may appear in the condition.

Via the lock mode you define which operations on the table are to be
protected by the lock. The lock modes available are:


o Read lock (shared lock)
protects read access to an object. The read lock allows other
transactions read access but not write access to the locked area of
the table.

o Write lock (exclusive lock)
protects write access to an object. The write lock allows other
transactions neither read nor write access to the locked area of the
table.

o Enhanced write lock (exclusive lock without cumulation)
works like a write lock except that the enhanced write lock also
protects from further accesses from the same transaction.

In order to be able to define SAP locks for a table, you must first
create a lock object for the table via Development->Dictionary.
If the data for an application object is distributed among several
database tables, it is often necessary to be able to lock these tables
simultaneously. It is therefore possible to include several tables in a
lock object, althought they must be related via appropriate foreign key
relationships. The tables involved in a lock object are also known as
its base tables.

Requesting an SAP lock

When a lock object obj is activated, two function modules (see CALL
FUNCTION) with the names ENQUEUE_obj and DEQUEUE_obj are generated.
These lock modules are used to explicitly request or release SAP locks
in an ABAP program. The SAP lock concept thus assumes a cooperative
behavior by all the programs involved. This means that access from
programs that do not call the specified modules are not protected.

The lock conditions and lock modes for the requested locks are defined
by the IMPORT parameters of the lock modules.

The lock conditions are defined by the lock parameters of the lock
object. If the lock object has only one base table, each primary key
field of the table corresponds to exactly one lock parameter. Apart from
this, a lock parameter corresponds to a group of primary key fields that
are identified by the join conditions. For each lock parameter par, the
lock modules have two IMPORT parameters with the names par and X_par.
The lock condition is defined by these parameters. If a parameter par is
not defined or if it is defined with the initial value, this means that
the corresponding key fields should be locked generically. If you really
want to lock the key field with the initial value, you must also define
the parameter X_par with the value 'X'.

To define the lock modes, the lock modules have an IMPORT parameter
MODE_tab for each base table tab, with which the lock mode for this
table can be defined. A default value must already be set for this
parameter in the definition of the lock object.

You cannot set an SAP lock by finding all the lines of the table which
satisfy the lock condition and marking them as locked. Rather, the lock
condition and lock mode for a table are entered in a special lock table.

Collision of SAP locks

Before a requested SAP lock is entered in the lock table, a check is
made on whether it collides with a lock already entered in the lock
table. Two locks on the same table collide if their lock conditions
overlap and their lock modes are incompatible.

The overlapping of two lock conditions on one table is a purely logical
attribute. It occurs if a row of the table which meets both conditions
could exist. It is therefore irrelevant for the overlap whether or not
such a row really exists in the table.

The following rules apply for the compatability of locks: An enhanced
write lock is incompatible with all other locks, a write lock is
incompatible with all locks requested by other transactions, and a read
lock is compatible with all other read locks.

If locks are requested with the help of a lock object that has several
base tables, all locks requested are regarded as colliding as soon as a
collision is recognized for just one of the base tables involved.

Behaviour in a collision

An SAP lock that collides with an existing lock cannot be granted and is
therefore not entered in the lock table.

With the help of the IMPORT parameter _WAIT, you can determine how the
ENQUEUE module should behave if the lock it requests collides with an
existing lock. If this parameter has the value ' ', the exception
FOREIGN_LOCK is triggered. The system field SY-MSGV1 is supplied with
the user set by the the colliding lock.
If the parameter has the value 'X', the lock request is repeated at set
intervals until either the lock can be granted or an internal system
time limit is exceeded. In the second case the exception FOREIGN_LOCK is
also triggered.

Duration of an SAP lock

At the end of a transaction, this automatically releases all the SAP
locks it holds. Note, however, that if an update routine is called by
the transaction, locks can be transferred from the ordering transaction
to the update routine. In the same way, these locks are automatically
released at the end of the update routine. Via the IMPORT parameter _SCOPE of the ENQUEUE module, you can determine
whether a lock should be transferred to the update routine if one is
called.
If _SCOPE has the value '1', the lock remains with the the ordering
transaction. If _SCOPE has the value '2', the lock can pass to the
update routine. Finally, if the parameter has the value '3', two locks
of the same kind will be generated, one of which passes to an update
routine when one is called.

By calling the DEQUEUE module, a transaction can explicitly release a
lock which it holds. The lock parameter and lock mode must be supplied
with the same value as for calling the ENQUEUE module. If the parameter
_SCOPE has the value '1', only one lock is released which cannot pass to
an update routine. If the parameter has the value '2', only one lock is
released which can pass to the update program. Finally, if the parameter
has the value '3', both locks can be released. Note however that a
transaction can release neither a lock which has already been
transferred to the update program, nor a lock which is held by another
transaction.
Via the IMPORT parameter _SYNCHRON you can control whether the release
of the lock should be synchronous or asynchronous. If this parameter has
the value 'X', the module waits until the lock has really been removed
from the lock table. If the parameter has the value ' ', a requst for
deletion of the lock from the lock table is sent to the application server which manages the lock table, and then the execution of the
program is immediately continued.

Monitoring of SAP locks

The transaction Display and delete locks monitors the SAP locks.

LOCK PARAMETERS

Definition of the lock parameters of a lock object:

The lock parameters of a lock object are used when the relevant lock
modules are called to allocate the values to the lock arguments of the
lock object.

For each parameter field of the lock object (at most) one lock parameter
can be defined.
The name of the lock parameter generally corresponds to the name of the
relevant parameter field. The name can however be freely chosen as long
as it adheres to the name conventions for lock parameters.

For each parameter of the lock objects the relevant lock modules
receive IMPORT parameters and X_. The parameter
possesses the relevant parameter field as reference field. If the IMPORT
parameter is filled with a value in a call, all the lock fields
equivalent to the parameter field in the corresponding lock arguments
are filled with that value. If the parameter remains initial, generic
locking takes place on these lock fields. If however the flag X_ is
set, initial also means that the corresponding lock field should
be locked at initial value.

NAMING CONVENTIONS OF LOCK OBJECTS

When naming the lock parameters of a lock object, the following
conventions apply:

1. No lock parameter may appear twice in a lock object.

2. Each lock parameter name must adhere to the name conventions for
table fields.

3. No lock parameter name may begin with the prefix 'X_'.

4. No lock parameter name may begin with the prefix 'MODE_'.

5. No lock parameter name may correspond to the name of a Basis table.

6. The names 'DDENQ_LIKE' and 'DD26E' are not allowed for lock
parameters.

LOCK FIELDS

Definition of the lock fields of a lock object:

The lock fields of a lock object are the key fields of the base tables
of the lock object for which a lock mode is defined.
The only exception to this rule is when the lock object only has one
base table and this base table is a structure without key fields. In
this case the lock fields of lock object are precisely those parameter
fields of the lock object for which a lock parameter is defined. (Here
too a lock mode must be defined for this base table.)

The lock argument for a table is now constructed from the lock fields
within this table. By virtue of the join conditions which were used to
construct the lock object, each lock field is equivalent to one
parameter field. If a lock parameter is defined for this parameter
field, the content of the lock field in the lock argument is controlled
via this lock parameter. Otherwise only generic locking is possible for
this lock field.

LOCK MODES

Definition of the lock modes of a lock object:
In the definition of a lock object one of the three lock modes
'S'(shared lock), 'E'(exclusive lock) or 'X'(exclusive lock without
accumulation) can be specified for each Basis table.

For each Basis table , for which a lock mode was specified, the
lock modules belonging to the lock object receive an IMPORT parameter
MODE_. This has the specified value as default. In a call this can
be changed to one of the other two values. This value is then entered in
the lock granule for the table. Basis tables for which no lock mode is
defined cannot be locked with the lock object.

LOCK GRANULE

Definition of the lock granule of a lock object:

For each base table of a lock object for which a lock mode is defined, a
lock granule is formed which consists of the name of the table, the
current lock mode and the lock argument for this base table. These lock
granules are the information which is transmitted to the lock server
when a lock module for a lock object is called.


DATABASE LOCKING

Database Locking

Any database permitting simultaneous access by several users requires a
locking mechanism to manage and synchronize access. The tasks of this
mechanism are to:

- protect data objects which a transaction is currently changing
or reading from being changed by other transactions at the same
time.

- protect a transaction against reading data objects which have
not yet been fully written back by another transaction.

How is locking achieved?

Database systems do not usually provide commands for explicitly setting
or releasing locks. Therefore, prior to executing the database
operation, database locks are set implicitly when one of the Open SQL
statements SELECT SINGLE FOR UPDATE, INSERT, UPDATE, MODIFY, DELETE is
called (or when the corresponding Native SQL statement is called).

What is locked?

Database systems set physical locks on all lines affected by a database
call. In the case of SELECT, these are the selected entries. In the case
of UPDATE, DELETE, INSERT and MODIFY, they are the entries to be
changed, deleted, etc.


It is not always the table line which is locked. Tables, data pages and
index pages can also be locked. The units to be locked depend on the
database system you are using and the access being performed.

Lock mode

In principle, one type of lock is enough to control conflicting data
accesses. However, to achieve a greater degree of parallel running among
transactions, database systems use several types of locks. These can
vary from system to system, but the following two are sufficient to gain
an understanding of how locking works:

o Read lock (shared lock)

Read locks permit the setting of further read locks, but prevent
other transactions from setting write locks for the objects in
question.

o Write lock (exclusive lock)

Write locks do not allow other transactions to set any locks for the
objects in question.

How are locks set?

You set write locks with the Open SQL statements SELECT SINGLE FOR
UPDATE, INSERT, UPDATE, MODIFY and DELETE (or with the appropriate
Native SQL statements).

The decision as to whether the Open SQL command SELECT or the
appropriate Native SQL command sets the lock or not depends on the
isolation level of the transaction. Two possible levels are
distinguished:

o Uncommitted read (or dirty read)

A program using an "uncommitted read" to read data does not set
locks on data objects and does not obey them. For this reason,
programmers must bear in mind that their programs might read data
which has not yet been finally written to the database with a database commit and could thus still be deleted from the database by
a database rollback. "Uncommitted read" is the default setting in
the R/3 system for the isolation level.

o Committed read

A program using a "committed read" to read data obeys the locks on
data objects. This means that programmers can be sure that their
programs will read only data which has been finally written to the
database with a database commit. You can set the isolation level in
the R/3 system to "committed read" by calling the function module
DB_SET_ISOLATION_LEVEL. The next database commit or rollback will
reset the isolation level to its default setting, as will calling
the function module DB_RESET_ISOLATION_TO_DEFAULT.

Many database systems employ additional isolation levels (e.g. "cursor
stability" and "repeatable read"). These work like "committed read", but
the read lock is retained until the next data object is read or until
the database cursor is closed. Since these isolation levels are not
sufficiently standardized, they are not currently used in the R/3
System.

If a transaction cannot lock an object because it is already locked by another transaction, it waits until the other transaction has released
the lock. This can result in a deadlock. A deadlock occurs, for example,
when two transactions are waiting for a lock held by the other.


How long is a lock retained?

In database locking, all locks are released no later than the next database commit or rollback (see Logical Unit of Work (LUW)). Read locks
are usually retained for a shorter period. Sometimes, this causes
problems for transactions which cover several dialog steps:

In the above example, further dialog steps follow the selection of a
flight with free seats to enter additional data for the reservation.
Here, the adding of the flight reservation occurs in a different LUW
than the original selection of the flight. Database locking does not
prevent another transaction from booking this flight in the meantime.
This means that the scheduled booking may have to be canceled after all.

From the user's point of view, this solution is very inconvenient. To
avoid this scenario, a flight reservation system must use the SAP
locking mechanism (see SAP Locking) to lock the flight for the entire
duration of the transaction.

MESSAGES

MESSAGE Syntax Diagram

Variants:
1. MESSAGE xnnn.
2. MESSAGE ID id TYPE mtype NUMBER n.
3. MESSAGE xnnn(mid).

Effect Sends a message. Messages are stored in table T100, and can be
maintained using Transaction SE91. They are fully integrated
in the forward navigation of the ABAP Workbench.

The ABAP runtime environment handles messages according to the
message type specified in the MESSAGE statement and the
context in which the message is sent. There are six kinds of
message type:

A (Abend) Termination
E (Error) Error
I (Info) Information
S (Status) Status message
W (Warning) Warning
X (Exit) Termination with short dump
Messages are used primarily to handle user input on screens.


There is an Example program for messages that displays how
messages behave in various contexts.

Variant 1 MESSAGE xnnn.

Additions:
1. ... WITH f1 ... f4
2. ... RAISING exception
3. ... INTO f

Effect Sends the message nnn from message class i with type x. You
can specify the message class i in the MESSAGE-ID addition to
the REPORT, PROGRAM or other introductory statement.

Example
MESSAGE I001.

- If you want to use a different message class, you can
specify one in parentheses after the message number:
MESSAGE I001(SU).
- When the statement is executed, the following system
variables are set:
* SY-MSGID (Message class)
* SY-MSGTY (Message type)
* SY-MSGNO (Message number)

Note Runtime errors:

- MESSAGE_TYPE_UNKNOWN: Message type unknown
- MESSAGE_TYPE_X: Deliberate program termination with short
dump

TRANSATIONS


1.SCREEN NUMBERS

The screen number identifies a screen within a program (module pool,
report).

Screen numbers can be up to 4 characters long, all of which must be
digits. Screen numbers from 9000 are reserved for customer-specific
screens.

The use of screen numbers is namespace-dependent. For screens in
programs in the SAP namespace, numbers less than 9000 are reserved for
SAP screens, numbers between 9000 and 9500 are reserved for SAP
partners, and numbers greater than 9500 are for customers.