Aquí tenéis un ejemplo de validación de NIF. Algo muy común en todos los proyectos:
Validación para los deudores:
Módulo de funciones: EXIT_SAPMF02D_001
USER EXIT ZXF04U01.
Código:
*--------------------------------------------------------*
* INCLUDE ZXF04U01
*--------------------------------------------------------*
TABLES: KNA1.
CASE SY-TCODE.
WHEN 'FD01'.
IF I_KNA1-LAND1 <> 'ES' AND I_KNA1-STCD1 = SPACE.
*-- dejamos grabar
ELSE.
SELECT SINGLE * FROM KNA1 WHERE STCD1 = I_KNA1-STCD1.
IF SY-SUBRC = 0 AND I_KNA1-KUNNR = SPACE.
CALL FUNCTION 'FC_POPUP_ERR_WARN_MESSAGE'
EXPORTING
POPUP_TITLE = 'Atencion NIF existente'
IS_ERROR = 'X'
MESSAGE_TEXT = 'Modifique con un NIF no existente'
START_COLUMN = 25
START_ROW = 6
EXCEPTIONS
OTHERS = 1.
SET SCREEN 120. LEAVE SCREEN.
* set cursor field 'kna1-STCD1'.
ENDIF.
ENDIF.
WHEN 'FD02'.
IF I_KNA1-LAND1 <> 'ES' AND I_KNA1-STCD1 = SPACE.
*-- dejamos grabar
ELSE.
SELECT SINGLE * FROM KNA1 WHERE STCD1 = I_KNA1-STCD1
AND KUNNR = I_KNA1-KUNNR.
IF SY-SUBRC = 0.
*-- dejamos grabar
ELSE.
SELECT SINGLE * FROM KNA1 WHERE STCD1 = I_KNA1-STCD1.
IF SY-SUBRC = 0.
CALL FUNCTION 'FC_POPUP_ERR_WARN_MESSAGE'
EXPORTING
POPUP_TITLE = 'Atencion NIF existente'
IS_ERROR = 'X'
MESSAGE_TEXT = 'Modifique con un NIF no existente'
START_COLUMN = 25
START_ROW = 6
EXCEPTIONS
OTHERS = 1.
SET SCREEN 120. LEAVE SCREEN.
ELSE.
*-- dejamos grabar
ENDIF.
ENDIF.
ENDIF.
ENDCASE.
Validación para los acreedores:
Módulo de funciones: EXIT_SAPMF02K_001
USER EXIT: ZXF05U01.
Código:
*--------------------------------------------------------*
* INCLUDE ZXF05U01 *--------------------------------------------------------*
TABLES: LFA1.
CASE SY-TCODE.
WHEN 'FK01'.
IF I_LFA1-LAND1 <> 'ES' AND I_LFA1-STCD1 = SPACE.
*-- dejamos grabar
ELSE.
SELECT SINGLE * FROM LFA1 WHERE STCD1 = I_LFA1-STCD1.
IF SY-SUBRC = 0 AND I_LFA1-LIFNR = SPACE.
CALL FUNCTION 'FC_POPUP_ERR_WARN_MESSAGE'
EXPORTING
POPUP_TITLE = 'Atencion NIF existente'
IS_ERROR = 'X'
MESSAGE_TEXT = 'Modifique con un NIF no existente'
START_COLUMN = 25
START_ROW = 6
EXCEPTIONS
OTHERS = 1.
SET SCREEN 120. LEAVE SCREEN.
* set cursor field 'LFA1-STCD1'.
ENDIF.
ENDIF.
WHEN 'FK02'.
IF I_LFA1-LAND1 <> 'ES' AND I_LFA1-STCD1 = SPACE.
*-- dejamos grabar
ELSE.
SELECT SINGLE * FROM LFA1 WHERE STCD1 = I_LFA1-STCD1
AND LIFNR = I_LFA1-LIFNR.
IF SY-SUBRC = 0.
*-- dejamos grabar
ELSE.
SELECT SINGLE * FROM LFA1 WHERE STCD1 = I_LFA1-STCD1.
IF SY-SUBRC = 0.
CALL FUNCTION 'FC_POPUP_ERR_WARN_MESSAGE'
EXPORTING
POPUP_TITLE = 'Atencion NIF existente'
IS_ERROR = 'X'
MESSAGE_TEXT = 'Modifique con un NIF no existente'
START_COLUMN = 25
START_ROW = 6
EXCEPTIONS
OTHERS = 1.
SET SCREEN 120. LEAVE SCREEN.
ELSE.
*-- dejamos grabar
ENDIF.
ENDIF.
ENDIF.
*-- Creación desde compras
WHEN 'XK01'.
IF I_LFA1-LAND1 <> 'ES' AND I_LFA1-STCD1 = SPACE.
*-- dejamos grabar
ELSE.
SELECT SINGLE * FROM LFA1 WHERE STCD1 = I_LFA1-STCD1.
IF SY-SUBRC = 0 AND I_LFA1-LIFNR = SPACE.
CALL FUNCTION 'FC_POPUP_ERR_WARN_MESSAGE'
EXPORTING
POPUP_TITLE = 'Atencion NIF existente'IS_ERROR = 'X'
MESSAGE_TEXT = 'Modifique con un NIF no existente'
START_COLUMN = 25
START_ROW = 6
EXCEPTIONS
OTHERS = 1.
SET SCREEN 120. LEAVE SCREEN.
* set cursor field 'LFA1-STCD1'.
ENDIF.
ENDIF.
WHEN 'XK02'.
IF I_LFA1-LAND1 <> 'ES' AND I_LFA1-STCD1 = SPACE.
*-- dejamos grabar
ELSE.
SELECT SINGLE * FROM LFA1 WHERE STCD1 = I_LFA1-STCD1
AND LIFNR = I_LFA1-LIFNR.
IF SY-SUBRC = 0.
*-- dejamos grabar
ELSE.
SELECT SINGLE * FROM LFA1 WHERE STCD1 = I_LFA1-STCD1.
IF SY-SUBRC = 0.
CALL FUNCTION 'FC_POPUP_ERR_WARN_MESSAGE'
EXPORTING
POPUP_TITLE = 'Atencion NIF existente'
IS_ERROR = 'X'
MESSAGE_TEXT = 'Modifique con un NIF no existente'
START_COLUMN = 25
START_ROW = 6
EXCEPTIONS
OTHERS = 1.
SET SCREEN 120. LEAVE SCREEN.
ELSE.
*-- dejamos grabar
ENDIF.
ENDIF.
ENDIF.
*-- Creación por Compras
WHEN 'MK01'.
IF I_LFA1-LAND1 <> 'ES' AND I_LFA1-STCD1 = SPACE.
*-- dejamos grabar
ELSE.
SELECT SINGLE * FROM LFA1 WHERE STCD1 = I_LFA1-STCD1.
IF SY-SUBRC = 0 AND I_LFA1-LIFNR = SPACE.
CALL FUNCTION 'FC_POPUP_ERR_WARN_MESSAGE'
EXPORTING
POPUP_TITLE = 'Atencion NIF existente'
IS_ERROR = 'X'
MESSAGE_TEXT = 'Modifique con un NIF no existente'
START_COLUMN = 25
START_ROW = 6
EXCEPTIONS
OTHERS = 1.
SET SCREEN 120. LEAVE SCREEN.
* set cursor field 'LFA1-STCD1'.
ENDIF.
ENDIF.
WHEN 'MK02'.
IF I_LFA1-LAND1 <> 'ES' AND I_LFA1-STCD1 = SPACE.
*-- dejamos grabar
ELSE.
SELECT SINGLE * FROM LFA1 WHERE STCD1 = I_LFA1-STCD1
AND LIFNR = I_LFA1-LIFNR.
IF SY-SUBRC = 0.
*-- dejamos grabar
ELSE.
SELECT SINGLE * FROM LFA1 WHERE STCD1 = I_LFA1-STCD1.
IF SY-SUBRC = 0.
CALL FUNCTION 'FC_POPUP_ERR_WARN_MESSAGE'
EXPORTING
POPUP_TITLE = 'Atencion NIF existente'
IS_ERROR = 'X'
MESSAGE_TEXT = 'Modifique con un NIF no existente'
START_COLUMN = 25
START_ROW = 6
EXCEPTIONS
OTHERS = 1.
SET SCREEN 120. LEAVE SCREEN.
ELSE.
*-- dejamos grabar
ENDIF.
ENDIF.
ENDIF.
ENDCASE.
No hay comentarios:
Publicar un comentario