Para empezar vamos a necesitar declarar un rango de tipo DATUM
DATA: r_fecha TYPE RANGE OF datum,
sr_fecha LIKE LINE OF r_fecha.
Luego se loopea el SELECT-OPTIONS/PARAMETER que contiene las fechas para armar el rango.
En este ejemplo vamos a usar un SELECT-OPTIONS
LOOP AT s_peri.
* Se limpia la estructura del rango al inicio de cada vuelta.
CLEAR sr_fecha.
* Como se trata de un rango el valor de option debe ser BT(BeTween).
sr_fecha-option = 'BT'.
* Se asigna el indicador para incluir/excluir valores
sr_fecha-sign = s_peri-sign.
* Modificamos el dia del LOW por el 1
s_peri-low+6(2) = c_01.
* y lo asignamos al LOW de nuestro rango previamente declarado
sr_fecha-low = s_peri-low.
* En este caso necesitamos que el HIGH del SELECT-OPTIONS no esté vacío
* entonces lo validamos
IF s_peri-high IS INITIAL.
MESSAGE s055(zmm) "Debe ingresar período hasta.
DISPLAY LIKE c_e.
LEAVE LIST-PROCESSING.
ELSE.
"Obtenemos el último día del período ingresado.
CONCATENATE c_cero
s_peri-high+4(2)
INTO v_poper.
v_anio = s_peri-high(4).
* Obtener el último día del mes.
CALL FUNCTION 'LAST_DAY_IN_PERIOD_GET'
EXPORTING
i_gjahr = v_anio
i_periv = c_periv
i_poper = v_poper
IMPORTING
e_date = v_high
EXCEPTIONS
input_false = 1
t009_notfound = 2
t009b_notfound = 3
OTHERS = 4.
"Si se produce un error.
IF sy-subrc IS NOT INITIAL.
MESSAGE ID sy-msgid
TYPE sy-msgty
NUMBER sy-msgno
WITH sy-msgv1
sy-msgv2
sy-msgv3
sy-msgv4.
ELSE.
* Se asigna la fecha del último día del mes ingresado en el HIGH
sr_fecha-high = v_high.
* Se calcula la cantidad de meses en el rango porque se necesita que no haya mas de tres períodos de diferencia
CALL FUNCTION 'HR_SGPBS_YRS_MTHS_DAYS'
EXPORTING
beg_da = sr_fecha-low
end_da = sr_fecha-high
IMPORTING
no_month = v_meses
no_year = v_anios
EXCEPTIONS
dateint_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid
TYPE sy-msgty
NUMBER sy-msgno
WITH sy-msgv1
sy-msgv2
sy-msgv3
sy-msgv4.
ELSE.
* Si es mayor a 3 se muestra el mensaje.
IF v_meses GT 3
OR v_anios NE 0.
MESSAGE s056(zmm) "La diferencia entre períodos no puede ser mayor a 3.
DISPLAY LIKE c_e.
LEAVE LIST-PROCESSING.
ELSE.
* Si está todo correcto se apendea la linea al rango
APPEND sr_fecha
TO r_fecha.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
Recordar declara cada variable para uso en las funciones con el tipo indicado dentro de la función.
No hay comentarios.:
Publicar un comentario