Thursday, October 28, 2010

free downloadABAP/4 OLE Automation Controller pdf book

free downloadABAP/4 OLE Automation Controller pdf book

sap 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.

sap 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 '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_betrg1 =" ZCATEGORIA-BETRG." wi_betrg2 =" ZCATEGORIA-BETRG." wc_categoria =" ZCATEGORIA-TRFGR." not_open =" 1" queue_error =" 2" others =" 3." except =" SY-SUBRC." program =" PROGRAM." dynpro =" DYNPRO." dynbegin =" 'X'." fnam =" FIELD." fval =" VALUE." turno =" 'S1'" turno =" 'S2'" turno =" 'S3'." wc_turno =" WC_TURNO_R." turno =" 'T1'" turno =" 'T2'." wc_turno =" WC_TURNO_R." razon =" 'ETI" razon =" 'EPM" razon =" 'ERP"> 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 '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 <>

Tuesday, October 26, 2010

abap program for How to determine the number of available lines depending on the font size

Many ABAPERS have this problem, if a batch input has a table control, then the font size changes from machine to machine as
a result the no of entries keeps changing, So how to determine the number of available lines depending on the font size.

I have a solution for this and it works fine.

Here is the code.

thanks
Poonam

*****************************************************************
------------------------------------------------------
* data for controlling paging on screen 0102
DATA: W_MAXLINES(2) TYPE N,
W_NEXT_LINE(3) TYPE N,
W_PAGE(1), "y = page forward, n otherwise
W_SCRLEN(2) TYPE I,
W_SCRLINE(2) TYPE I.
DATA: BEGIN OF W_HDR.
INCLUDE STRUCTURE D020S.
DATA: END OF W_HDR.
DATA: BEGIN OF W_FLD OCCURS 100.
INCLUDE STRUCTURE D021S.
DATA: END OF W_FLD.
DATA: BEGIN OF W_LOG OCCURS 20.
INCLUDE STRUCTURE D022S.
DATA: END OF W_LOG.
DATA: BEGIN OF W_MC OCCURS 20.
INCLUDE STRUCTURE D023S.
DATA: END OF W_MC.
DATA: BEGIN OF W_DYNPRONAME,
PROGRAM(8) VALUE 'SAPMM60X',
DYNPRO(4) VALUE '0102',
END OF W_DYNPRONAME.

************************************************************************
FORM GET_MAX_LINES.
* set w_maxlines to the number of var-loop occurrences on the screen so
* that we know when to page forward on screen 0102
* also initialise w_next_line to zero for GET_NEXT_LINE
* this subroutine caters for all cases - including screens without loops
CLEAR: W_MAXLINES,
W_NEXT_LINE.
IMPORT DYNPRO W_HDR
W_FLD
W_LOG
W_MC
ID W_DYNPRONAME.
LOOP AT W_FLD WHERE LTYP EQ 'L'.
MOVE W_FLD-LINE TO W_SCRLINE. "first var-loop line
MOVE W_FLD-LBLK TO W_SCRLEN. "depth of loop block
EXIT.
ENDLOOP.
IF SY-SUBRC EQ 0
AND W_SCRLEN NE 0.
* sy-srows = total no of lines on screen
* w_scrline = actual first line of loop so that
* w_scrline - 1 = number of heading lines (before loop)
* 4 = no of lines at top of screen - command line, pushbuttons, 2 ulines
* 3 = no of lines after loop - uline & Page count
* w_scrlen = no of lines in loop block
* w_maxlines = sy-srows - ( wscrline - 1 ) - 4 - 3
* and then 1 less but not sure why!
W_MAXLINES = SY-SROWS - W_SCRLINE - 1 - 4 - 3.
W_MAXLINES = W_MAXLINES - 1.
W_MAXLINES = W_MAXLINES DIV W_SCRLEN.
ELSE.
MOVE 99 TO W_MAXLINES. "this required if no screen loop
ENDIF.
ENDFORM.


************************************************************************
FORM GET_NEXT_LINE.
* set w_page if page forward is required
W_NEXT_LINE = W_NEXT_LINE + 1.
IF W_NEXT_LINE GT W_MAXLINES.
W_NEXT_LINE = 1.
W_PAGE = 'Y'.
ELSE.
W_PAGE = 'N'.
ENDIF.
ENDFORM.
------------------------------------------------------

ABAP/4 Programming Quickstart

Startup

Log onto SAP. Type "SE38" into the command field as Figure 1.1 shows, and press . You are "going into SE38", the ABAP editor.

Figure 1.1
Figure 1.1 The SAP R/3 main screen

Type in the new program name "ZHELLO1", select *Attributes then click on [Create as Figure 1.2 illustrates. If that name is already taken, choose another name.

Note The opening square brace on [Create is an example of the York-Mills Notation, which we will use throughout the book to describe your navigation through menus, buttons and fields. See Appendix F for a complete description. In this case, the square brace is a prefix that indicates the "Create" is a button. Similarly, "{" indicates a menu item, "*" a radiobutton and "<" a field entry. We'll use italics for the labels on those navigation objects.
Figure 1.2
Figure 1.2 ABAP/4 Program Development: Initial Screen

Fill in a title like "Test program for ABAP programming book". Enter "1" in Type and "S" in Application, select Upper/lower case as you can see in Figure 1.3 and click on "Save" (the file-folder icon on the task bar). Select [Local private object as shown in Figure 1.4, then click on [Source code.

Note We'll explain in later chapters all the things we're racing through so quickly here such as values for "Type" and "Application". In this chapter we're going to just blast ahead to demonstrate some of what you can do in ABAP/4, and how to do it.
Figure 1.3
Figure 1.3 ABAP/4: Program ZHELLO1 Attributes

Figure 1.4
Figure 1.4 Selecting a development class

Your first program

You're now in the editor; it opens with the statement

REPORT ZHELLO1 .

The ABAP editor in Release 3.0 has three ways of presenting the code; you select one in the menu item {Settings {Editor mode. Release 2.2 offers only the "Command Mode" presentation, so we'll assume you're using that mode.

Type in the second line of the program:

WRITE 'Hello World'.

Note We'll create several versions of this program as we work through the chapter. You can view each intact program when it appears in the text by clicking on the "source code" icon

and you can download it by right-clicking on the "disk drive" icon.
Notice the single-quote (') delimiters and the terminating period. Save your work by clicking on the file-folder icon on the task bar, and select the menu items {Program {Execute, or click on [Execute, or in Release 3.0 press F8. Behold! You have followed time-honored tradition with your first programming task, as Figure 1.5 shows.

Figure 1.5
Figure 1.5 Output of first program

This output is called a report (and often a list) in SAP. When you've tired of admiring your success, return to the source code by pressing F3 or by clicking on "Back" (the left-pointing green arrow icon on the task bar).

A simple two-level list

One of the unusual and powerful capabilities in SAP is to "drill-down" through data. We'll gradually build this example to illustrate how you can write programs to drill down, and in the process learn some of the nature and capability of ABAP/4. Add two more lines to your program so it reads like ZHELLO2:

Save and execute it again, and it looks the same. However, if you place the cursor on "Hello World" (or almost anywhere else on the report) and double-click or press F2, you'll see the next level of the report as shown in Figure 1.6:

Figure 1.6
Figure 1.6 List of Continents

From here you can march back up the report levels with "Back" (the left-pointing green arrow icon) or you can Exit all the way back to the source code by pressing Shift-F3 or clicking on the up-pointing yellow arrow.

While you're in the list of continents, double-click on one of them. It'll look as if nothing happened but you must go Back twice to return to the "Hello World" level. The continents have been listed twice, and the two lists of continents have the same contents but they are in distinct levels of the report. R/3 will allow you to go as many as nine levels deep.

AT LINE-SELECTION is an event in ABAP/4 that's triggered when you "select" (double-click or F2) a line in the current report. The code block following the event statement is executed whenever the event is triggered. If the event's code block writes output, then it will force another list level. ABAP/4 recognizes several events; a few of which we'll use in this chapter.

Notice the colon (:) on the second WRITE. This allows you to follow the keyword with any number of comma-separated parameters; each parameter will be processed by the keyword independently. In this case, the statement acts as three separate WRITE statements to print out the three different strings. The forward slash forces a newline, and the number 12 offsets the string to start in the 12th column.

Adding variables

User-variables must be declared and typed in ABAP/4. In addition to user variables, R/3 provides quite a few system variables that contain the state of the program and the report. Rewrite your program to read like ZHELLO3:

Save and execute this version of your program and watch the list level increment as you "Select", and decrement as you go "Back". March down to list level nine and see that indeed, you may not go any deeper. Remember that at any level you can return immediately to the source code with "Exit" (Shift-F3 or the Yellow arrow). "Exit" is a tricky command however; sometimes it'll take you all the way back to the SAP main screen. You have a new way to climb back out by selecting (double-clicking) on the line that reads "Return". Figure 1.7 shows the list of continents selected while you're already in the ninth level.

Figure 1.7
Figure 1.7 Lists are limited to nine levels

The DATA statement declares variables and establishes their types. The default type is C (Character), so it is optional for string variables. The variable's length is specified in the parentheses immediately following the variable name. You can optionally assign an initial value to the variable at declaration.

SY-xxxxx is the naming convention for system variables; SY-LSIND contains the current list index (level); we added it so you can see where you are. SY-LISEL contains the list selection (the contents of the line you selected), so the program can test where it is. SET USER-COMMAND simulates in code a user action, in this case the "Back"(F3 or green-arrow) command. SKIP, of course, skips a line on the screen.

Note The system variables are often mnemonic. SY-LISEL is mnemonic for LIne SELection. SY-SUBRC for SUBroutine Return Code. Most of these mnemonics are in English and contrast with the mnemonics for data fields that are mostly in German.
Notice that every command is terminated by a period (even ELSE!), that a command can span multiple lines (DATA and the second WRITE), and that a line can contain more than one command (SKIP...). ABAP/4 is case-insensitive except in some string comparisons, so keywords can be upper, lower or proper (mixed) case as you choose. We like UPPER keywords, lower variable and table names, and Proper Subroutine and Function Module names. White space (spaces, tabs, newlines) count for very little in ABAP/4. We like to indent structured commands and leave blank lines to make code easier to read. You can insert comment lines by placing an asterisk (*) in the first column, and in-line comments with the double-quote ("); comments are terminated by a newline.
Note The only virtue that we know of for using the asterisk is that the system editors highlight asterisk-indicated comment lines in red. You can use the double quote as your sole comment indicator, thereby simplifying your life.

Using internal tables

One data structure you can declare is the internal table (itab) which exists only while this program runs. Once again, import or rewrite your program to read like ZHELLO4:

Save and execute it again, and now you have a third defined list level: some of the nations in the selected continent as you see in Figure 1.8. The content of the third level depends on what you selected at the second level. Neat! Also, the program no longer continues to deeper levels; it stops where it's "supposed to".

Figure 1.8
Figure 1.8 Output showing list of countries

The BEGIN OF... END OF... construction creates a "structure" - a complex data type that may contain several fields. Adding the OCCURS... option expands that structure into an internal table. The OCCURS value should be somewhat near the number of records you expect, but the program will work fine with zero or a very large number; a larger or smaller number of records affects processing speed and memory utilization, but will work regardless. You refer to fields in a table using the format tablename-fieldname.

Note The hyphen is commonly used to qualify field names to tables, similar to the period in many other languages. It is a legal character in field names, but we like to avoid them so that any hyphenated string obviously refers to a table or structure field.
The BEGIN OF...OCCURS...END OF... commands not only create itabs, but also create separate "header lines" or "work areas" that have the same structure as the itab and HAVE THE SAME NAME! Many commands, such as the assignments, actually affect only the header line. The information doesn't get into the itab until you APPEND the header line to the itab. It'll take you a while to get used to this: when you see a table name, it may refer to the table or to its header line.

LOOP AT itabname loops through the named itab from the first record to the last, executing for each record the commands between the LOOP and ENDLOOP statements. At each iteration, the LOOP command populates the header line with the values in that itab record, so the WRITE statements are actually writing the contents of the header line, not the itab entry.

The CASE statement compares the variable in the first line to the values (variable or literal) in the following WHEN statements. It executes the commands starting at the first matching WHEN and stopping at the next WHEN or the ENDCASE. Finally, it will execute the commands following WHEN OTHERS if no other WHEN matches.

FORM subroutines

As the program gets longer and does more things, it's harder to follow. Sometimes we need to have the program do the same thing in several places. We make the program flow easier to follow and eliminate duplicate code by moving blocks into subroutines which the program calls as needed. One type of subroutine in ABAP/4 is the FORM, which is called with the PERFORM command. Import or rewrite your program to read like ZHELLO5:

Save and execute it yet again, and you see that we have a fourth level which shows the capital city of the country you've selected, shown in Figure 1.9. The "Return" button is now a little more prominent and has a permanent location on the screen. Other than that, the output doesn't look any different. The code has changed a lot though.

Figure 1.9
Figure 1.9 Output showing selected Capital city

We've added the event START-OF-SELECTION which is triggered after the program is initialized, so it contains essentially the "main program". The code block for any event is terminated by the next event statement (in this case, the AT LINE-SELECTION statement), by the first FORM definition, or by the end of the program. In this version, the main program consists of calling the FORM (subroutine) "build_loc", then calling "level0". It's easier to follow when logical blocks are defined elsewhere, named sensibly, and simply called in order. Since we need the return button in several places, it's a natural for a subroutine.

Note ABAP/4 event blocks may appear in any order within a program. An event block is terminated by the start of the next event block, the first FORM definition or the end of the program. However, it is good programming practice to standardize on an ordering. We follow the ordering shown in Appendix E.
Since we've seen enough of the list levels, we removed them from the screens.

The new "Return" function is truly a button now, not just a line in the report. The command GET CURSOR FIELD returns the name of the field you selected. We wanted a big button, and the ability to select anywhere on it, so we used one variable to paint its top and bottom lines and a second variable to paint its label and ends; the variables are called ret_button1 and ret_button2. The comparison operator CS returns TRUE if cfield ContainsString 'ret_button', so the IF statement is satisfied if either variable is selected.

The CASE statement is easier to read when each branch simply calls a subroutine rather than containing all the code. We've removed the WHEN OTHERS option because we don't want anything to happen if the user double-clicks in level 4 or below. The "Return" button or "Back" are the only ways out of that level.

The FORM definition for build_loc illustrates again the distinction between an itab and its header line. The subfields in the header line are independent, so the value of "continent" remains the same until you assign another string to it. Again, you are assigning values to the header line; only with APPEND do they appear in the itab.

Now that we have one flat table, we must write list level 1 in a new way. We don't have a simple table of continents, and we don't want "North America" to appear three times in the list. AT NEW fieldname is a conditional statement that's true every time the value of fieldname changes, as well as in the first record if it differs from the header line. We CLEAR the header line so we know it will not be the same as record one at the start, then LOOP.

Note This technique works only when the table is sorted by continent. Because we built the table this way, though, we know that it will work here. If the internal table is built from a non-sorted source, it must be sorted before using LOOP AT and AT NEW in this way.
To write list level 2 from our single flat table, we need to select those records whose continents match the one you chose in level 1. The WHERE option (optional command clauses are called "additions" in SAP-talk) will limit the execution of the code block to those records that match the WHERE condition, in this case those records for which the value of loc-continent equals the contents of "sel_cont". We assign to sel_cont the value of SY-LISEL (the selected line, remember), offset by 11 characters. In other words, sel_cont equals the selected line, starting at the 12th character; since we wrote the continent to the screen starting in column 12, sel_cont now contains the continent without any leading spaces.

In addition to writing names of countries in the selected continent, we're also using HIDE to store their capital city names. Hidden fields aren't visible, but they are associated with the current line. When a line is selected the hidden field values are assigned to their header line fields, so we can use that information for later displays or tests.

List level 3 differs from the others; it writes a single text statement based on your earlier choices. We must assemble the string to write because R/3 writes the full declared width of the text field, regardless of the length of its contents, and we want a nice-looking sentence. We must concatenate some literal strings and some variables, most separated by spaces, and one (the terminating period) with no leading space. Release 3.0 has a CONCATENATE command that can do it all, but Release 2.2 does not, so we'll do this the old way.

First we stick a period on the end of the capital city name using the function STRING_CONCATENATE. A function is a library subroutine accessible from any program. Our program "exports" parameters to the function and "imports" return values from it; the function also returns the listed error codes if appropriate in the system variable SY-SUBRC (SUBroutine Return Code). Then we start building our string with the start of the sentence "The capital of ". We assign to the string, starting at offset 18, the contents of the selected line, starting at its offset 14. Then we add " is " at offset 38 and the capital name-plus-period at offset 42. Since we don't know how long the country or capital names are, we assemble them with lots of room, then CONDENSE the entire string; that command shifts all the substrings leftwards until they are each separated by one space. Now we can write it out.

Tuning up the report

Now that we're approaching a useful report, let's add some color and clean up some loose ends. We will:
  • Use cfield to require selecting the "Hello World" string itself to go to the second level.
  • Reset cfield and the loc header line after we create each screen so old values can't confuse us.
  • Write headers on each list, and paint the "Return" button as part of the page setup.
  • HIDE the continents in the level 1 list, and test for them in level 2. That way you write the next level only when you select a valid line on the screen.
  • HIDE the nation's name in level 2 so we don't have to extract it from a substring of SY-LISEL in level 3.
  • Only write out level 3 if we selected a valid screen line in level 2.
  • Write the "Return" button and "The capital of..." in colors.
Here's ZHELLO6:

Save and execute this version and select all over the screens; it now responds only when it makes sense. The colored "Return" button is more obvious, and the colored level-3 statement clearly differs from the other lists.

The TOP-OF-PAGE events are triggered whenever R/3 automatically generates a new page. The first one only works on level 0 screens, and the DURING LINE-SELECTION version works on all the other levels.

We discussed the return_button earlier, but we want to point out one more thing in its FORM definition. List level zero, the first output screen, includes a couple of title lines that don't show up on lower (or is that higher?) levels. So we restore the cursor to line five after painting the button if we're in level zero, and to line three in any other level. Subsequent writing will start on the line we move it to.

We like to use "IF cfield CS 'greeting'" instead of "IF cfield = 'greeting'" because R/3 returns the field name capitalized, and we like to keep our lower-case convention for the variable name. The CS operator is case-insensitive, whereas the equality operator is case-sensitive.

The condition IS INITIAL is true if the variable is reset (in its initial state). The initial state for character type variables is a space; that is, a reset character variable contains one space.

Valid color numbers and the colors they display in a typical SAP installation are shown in Table 1-1.

Table 1-1 Valid Color Numbers

  1. Gray-blue
  2. Bright gray
  3. Yellow (Yellow)
  4. Blue-green
  5. Green
  6. Red
  7. Violet

User's initial choices

We can offer the user choices that affect how the program runs; inviting (or requiring) him or her to enter a single value or a range or list of values. We can also send out error messages if the user fails to properly complete the choices.

Reports in R/3 consist of quite a bit more than their code. So far the examples have been limited to code; this time we'll use some of the other capabilities. And we'll look at our first database table.

The final version of our sample program is ZHELLO7:

Before you execute it, you must provide the content of TEXT-001 that we specified in the SELECTION-SCREEN COMMENT line near the beginning of the program. Double-click on the "TEXT-001", select [Yes to create it as shown in Figure 1.10, then type in the label "Color for Capital city display (1-7)" as shown in Figure 1.11. Save it and go back (green arrow) to the source code. This text element is the first example of a program element that is somewhere other than in the code. It's stored in a table associated with the program. You could also have gotten to the table using the path {Goto {Text elements *Numbered texts [Edit.

Figure 1.10
Figure 1.10 Dialog box to create a Text element

Figure 1.11
Figure 1.11 Maintaining Text elements

SAP stores most system data, owner's "Master" (lookup) data and business transaction data in database tables. The TABLES statement hooks in the named tables, making them available to the program, and creates a header line for each. In this example, T005T is SAP's table of country codes, their names and what we call their citizens. Double-click on the "T005T' in the TABLES statement. You'll see a brief description of the table and a list of its fields with their descriptions as shown in Figure 1.12. This illustrates the amazingly integrated nature of R/3: everything seems to connect to everything else, and you can drill down to get there from almost anywhere. "Green arrow" back to the source code.

Figure 1.12
Figure 1.12 Table and Fields of T005T

Save and execute this last version and see the selection screen shown in Figure 1.13. Click on [Execute or press F8. R/3 returns the cursor to the empty Color parameter field and sends you a message that you must enter a valid number. Type in a number between 1 and 7 then [Execute again. This time it places the cursor in the first "s_land1" field (whatever that is) and insists you enter a country code. Type in "a*" in the first field and [Execute again. Now you're in familiar territory. Try the "Country list" choice in level 1 and see what happens. You see every country in the SAP database whose code matches your "s_land1" choices; and you can drill down to see what that country's residents are called.

Figure 1.13
Figure 1.13 Initial selection screen

We placed the range selection option on the entry screen with the SELECT-OPTIONS command. It expects you to enter a single value or a wildcard pattern in the "From" field, or the beginning and ending values of one or more ranges in the "From" and "To" fields. You can look up possible values for those fields: press F4 or click on the down-pointing arrow at the right of the field when the cursor is in the field. Choose [No, you don't want more selection criteria as shown in Figure 1.14, to see the list shown in Figure 1.15. In this case, the values are country codes found in the T005T table.

Figure 1.14
Figure 1.14 "Restrict values ranges" dialog box

Figure 1.15
Figure 1.15 "Possible values" pull-down list

If you click on the right-pointing arrow to the right of the "To" field, a new screen appears in which you can enter as many ranges as you need, as shown in Figure 1.16.

Figure 1.16
Figure 1.16 Multiple-ranges selection screen

The "s_land1" label on the selection screen doesn't mean anything to the user (and is pretty ugly), so let's change it. That label is another text element. You reach that one by {Goto {Text elements *Selection texts [Edit to see the table shown in Figure 1.17. In the "s_land1" record, you can change the second field from "?...(S_LAND1)" to whatever you want that will fit. In our example, we'll use " Range of Countries." Tinker with the leading spaces to align it with the "Color for Capital city display (1-7)" label as shown in Figure 1.18.

Figure 1.17
Figure 1.17 Maintaining Selection texts

Figure 1.18
Figure 1.18 Improved Selection screen

The various SELECTION-SCREEN commands place text on the screen. User choices are invoked by the PARAMETERS (single-value) and SELECT-OPTIONS (ranges) commands. The PARAMETERS label would have been determined by the selection text elements like the SELECT-OPTIONS was if we hadn't painted a COMMENT on the same screen line.

We've added two new events to filter the screen entries. AT SELECTION-SCREEN ON color and AT SELECTION-SCREEN ON s_land1 are triggered when you [Execute out of the selection screen. In these cases, we just test for valid entries. A type "E" (error) message tells R/3 to return to the selection screen with the cursor in the subject field, and to display the message (number 208 in this case) from the message set 00 (notice the MESSAGE-ID 00 option in the REPORT ZHELLO7 line). Double-click on the "00" in the top line and select [Messages to see all the messages available in that set as shown in Figure 1.19. Message 208 is simply "&" which R/3 expands into the contents of the WITH option. If neither IF is satisfied, then the selection screen is accepted and the program proceeds.

Figure 1.19
Figure 1.19 List of messages in set 00

We extract selected records from database tables using the SQL-like SELECT command. The selection conditions we chose are (1) the language (Spras from the German Sprache) is the same as the user's login language, and (2) the country code (Land1; Land is German for country, nation or state) is in the list you selected at the selection screen. All the commands between SELECT and ENDSELECT will be processed for each selected record.

And finally, the string 'We don''t know about the people from ' shows how to include an apostrophe in a string, and USING string2 shows how to pass parameters to the color_write subroutine.

Summary

We have developed an example of interactive list processing in ABAP/4 from the classic, very simple "Hello World" to a rather complete multi-level illustration of the "drill-down" capability. We showed the use of several of the commands available in ABAP/4, and glimpsed a couple areas beyond the code that contain program elements.

The remainder of this book will expand on every command shown and every point illustrated in this example. We'll explain a lot of things that we touched lightly or just leaped over in this chapter, and we'll provide examples of the other two main uses of ABAP/4 in an R/3 installation: creating batch data communications (BDC's), and creating reports.

Handling favorites in ABAP Workbench

This document details the procedure in handling the favorites in the ABAP Workbench. I would always want to add my frequently used objects in the favorites. For our learning purpose, let us add the package SWDP_DEMO_TUTORIALS (Demo tutorials for Web Dynpro ABAP) to the favorite list.

Go to Transaction SE80 and select “Package” from the list box. Enter the package name SWDP_DEMO_TUTORIALS as shown below:

Now open the list box “Favorites” and click on Add:

The following message appears:

Now verify the same by opening the favorites:

This way, we can add the recently used objects in the favorites list.

To download/Upload favorites from one system to another:

In the favorites, click on Edit as shown below:

Following screen appears:

Using the Download/Upload buttons, we can either download/upload the favorites from one system to another.

Number Range Object in sap

Creation of a Number range object:

1. Go to transaction SNRO (Simple way to remember is SapNumberRangeObject).

2. Enter the number range object name and press CREATE.

3. Enter the description, Long text and Number Length domain andWarning % as shown below:

Warning% à Assume that an interval is defined from 1 to 1000. If you want to issue a warning at the number 900, enter 10 (%) here.

4. Press SAVE. You would get a prompt as shown below:

5. Press YES and assign the object to a local class.

6. Now click on “Number Ranges” button on the application toolbar.

7. Click on “Change Intervals”.

8. Click on “Insert Interval”.

9. Enter the values as shown below:

10. Click “Insert” and then SAVE. The number range object is generated.

Testing the Number Range Object:

We can use the function module, NUMBER_GET_NEXT, to get the next number of any number range object.

Following is a test program to get the next available number of the object created above:

REPORT zsnro_test.

DATA:
NUMBER TYPE I.

CALL FUNCTION 'NUMBER_GET_NEXT'
EXPORTING
nr_range_nr = '01'
object = 'ZDEMO'
IMPORTING
NUMBER = NUMBER
EXCEPTIONS
INTERVAL_NOT_FOUND = 1
NUMBER_RANGE_NOT_INTERN = 2
OBJECT_NOT_FOUND = 3
QUANTITY_IS_0 = 4
QUANTITY_IS_NOT_1 = 5
INTERVAL_OVERFLOW = 6
BUFFER_OVERFLOW = 7
OTHERS = 8
.
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

Write :/ 'Next available number is: ', Number.

ABAP Tips and Tricks

Retrieving the deleted program

I recently deleted a custom program (which is already transported to production) accidentally and was wondering if there is any method of retrieving the program back. After some research, I found a way of getting back the program. Following are the steps in getting back the program:

1) Create a program with the same name as earlier (which is deleted)
2) Click on "Utilities" --> "Versions" --> "Version Management"
3) Select the version of your earlier program and click on display.
4) Your earlier program is displayed here. *-- Soumya Ray

Find out in what all Tables a specified field is available.

You can find out through transaction code SE15.

1) Give SE15 on command prompt.
2) Select ABAP Dictionary
3) Select "fields" folder
4) Click on table fields
5) Then you can enter the desired field name (In your case EKGRP)
6) Run OR press F8.

The system will list out all the tables which contain your desired field name.

or

1) using transactin Code SE11( ABAP Dictionary)
2) enter the Data table name where-in the respective field (EKGRP) is used eg; EKKO
3) Click the where -used list button
4) Check out the box(DB tables) Only .

There you can see entire list of tables containing the desired field.

Here the difficulty is that one should know at least the name of the one of the data tables which contain the desired field.

With Compliment by: Manohar TS & Kotha

**********

Find the Table Name For a Field.

I know couple of ways to find the table name for a field.
like.
1. Part the cursor at the field and press F1 & F9.
2. se84 or se15
3. st05 (sql trace).
4. Setting Break point in ABAP.

If you will tell other methods it will be apreciate.

**********

*
* How to print Apostrophe using the write statement
* For e.g. You'll be there.
*
report zapostrophe message-id z1.

DATA: LINE(20).

CONCATENATE 'You''' 'll be there.' INTO LINE.

WRITE:/ LINE.

**********

Given a transaction code, how can I find the menu path?

In 4.6c, you can used tcode search_sap_menu to find the SAP MENU tcode.

Please note that there are no tcode available to find the path of the IMG transaction.

**********

How to un-encrypt SAP user password?

It is not possible to un-encrypt the SAP password, because a one-way encoding (with strong 1024 bit key) is used for this. The result is stored and each time one has entered the password the encoding result is checked.

**********

When you delete an entry from an internal table in ABAP, the system has to re-generate the index for all entries after your delete, slowing the report if you have many records to eliminate.

It is much quicker to do an insert of the correct records into a second table than to delete entries from the first. The reason for this is because the index is only generated for the newest element.

**********

If you want to protect a program against debugging, you just have to set the STATUS = S in the attributes view of the main program.

**********

BDC.
When You use a call transaction ,and populate the BDCDATA table.
Make sure you pass the "DATE FIELDS" of any transaction by formatting it as "XX/XX/YYYY" cos if you pick this data from database it will be of the format 20030505 or something like that. Make sure You pass this value as character field.
Same is true for the "Rate Fields". Make sure you pass them as "Character Fields" by formatting them.

**********

If you need to find out the Okcodes for BDC sessions, look for program RSBDCCUA and run it for any platform say 'WN' for windows or MC for Mac and it will generate list of function codes

**********

To save the contents of an internal table as a Microsoft Excel Worksheet when debugging code in SAP R/3 Enterprise:
1. Click on the "Table" button
2. Type in the name of your internal table in the "Internal table" field and hit Enter.
3. Hit CTRL + F11 or click on the "Save as Excel Worksheet" button.
4. Type in the record numbers that you want to save. (Ex. From Line: 1 To Line: 10) Hit Enter.
5. Save your file.

**********

Starts with a Z is homegrown program
You cannot be sure that anything which starts with a Z is a homegrown program.
SAP provide a number of correction programs, especially within the archiving area, which start with a Z.
For e.g. ZZSTOCKL from note 202345.

**********

Can line-size of abap report large than 255?

You can have line-size upto 1023.
Along with Report statement pass the line-size as 1023. Ex. Report xyz line-size 1023.

**********

How to find out the number of days between a given date, excluding Saturdays and Sundays and public holidays?

Try functions,
=> DATE_CONVERT_TO_FACTORYDATE
=> HR_HK_DIFF_BT_2_DATES

Tutorials on SAP-ABAP

Adobe Interactive Forms Tutorials

Business Server Pages (BSP)

Userexits/BADIs

Web Dynpro for ABAP (Step by step procedure for web dynpro,Tutorials on Web Dynpro,)

ALV Tutorials

Blog Archive

goodsites