Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *&------------------------------------------------------------------------*
- *& Report ZHCMR_PT0002
- *& Carregar dados Ponto e executar programa
- *&-*----------------------------------------------------------------------*
- * Autor : Camila Brand Data: 03.02.2017 *
- * Observações: Desenvolvimento inicial do Programa *
- *&------------------------------------------------------------------------*
- REPORT ZHCMPTR011.
- *----------------------------------------------------------------------*
- * TABLES
- *----------------------------------------------------------------------*
- TABLES: ZHCMT_PT_0004.
- *----------------------------------------------------------------------*
- * TYPE POOLS
- *----------------------------------------------------------------------*
- TYPE-POOLS: ICON,
- SLIS.
- *&---------------------------------------------------------------------*
- *& TYPES
- *&---------------------------------------------------------------------*
- TYPES: BEGIN OF TY_ITAB,
- MSGTY_AUX TYPE BAL_S_SHOW-MSGTY,
- T_MSG_AUX TYPE BAL_S_SHOW-T_MSG,
- END OF TY_ITAB.
- TYPES: TT_ITAB TYPE STANDARD TABLE OF TY_ITAB.
- *&---------------------------------------------------------------------*
- *& DATA
- *&---------------------------------------------------------------------*
- DATA: DLIST LIKE EPSFILI OCCURS 0 WITH HEADER LINE.
- DATA: TABAPLIST LIKE ABAPLIST OCCURS 0 WITH HEADER LINE.
- DATA: ITAB TYPE TABLE OF TY_ITAB,
- WA_ITAB LIKE LINE OF ITAB,
- TG_TEXTO TYPE TABLE OF TXLINE,
- WG_TEXTO LIKE LINE OF TG_TEXTO.
- DATA: IT_PT_0001 LIKE ZHCMT_PT_0001 OCCURS 0 WITH HEADER LINE,
- WA_PT_0001 LIKE LINE OF IT_PT_0001,
- T_MSG TYPE TABLE OF BDCMSGCOLL.
- DATA: BDCDATA_WA TYPE BDCDATA,
- BDCDATA_TAB TYPE TABLE OF BDCDATA.
- DATA: CTU_PARAMETERS TYPE CTU_PARAMS.
- DATA: LV_NOME_ARQUIVO_ERRO TYPE STRING,
- LV_NOME_ARQUIVO_PROC TYPE STRING,
- LV_NOME_ARQUIVO TYPE STRING,
- T_FILE TYPE TABLE OF ZARQ_BLOOMBERG WITH HEADER LINE,
- WA_T_FILE TYPE ZARQ_BLOOMBERG,
- V_FILENAME_STRING TYPE RLGRAP-FILENAME,
- V_FILENAME_STRING_PROC TYPE RLGRAP-FILENAME,
- V_FILENAME_STRING_ERRO TYPE RLGRAP-FILENAME,
- P_DIR(60) TYPE C,
- P_DIR_PROC(50) TYPE C,
- P_DIR_ERRO(50) TYPE C.
- DATA V_SEQPROC TYPE NUM06.
- TYPES : BEGIN OF TY_GET_SPOOLDATA,
- LINE(1000) TYPE C,
- FLAG(1) TYPE C,
- END OF TY_GET_SPOOLDATA.
- *&---------------------------------------------------------------------*
- *& START OF SELECTION
- *&---------------------------------------------------------------------*
- START-OF-SELECTION.
- IF SY-BATCH IS INITIAL.
- CALL SCREEN 0100.
- ELSE.
- PERFORM:
- CHECK_RUNNING_JOB,
- F_PROCESSA_DADOS. " Form seleciona dados
- ENDIF.
- END-OF-SELECTION.
- *&---------------------------------------------------------------------*
- *& INICIO PROCESSAMENTO
- *&---------------------------------------------------------------------*
- FORM F_PROCESSA_DADOS .
- DATA: VL_DIR_NAME TYPE EPSF-EPSDIRNAM,
- T_PARAMS TYPE TABLE OF RSPARAMS,
- T_PARAMS_255 TYPE TABLE OF RSPARAMSL_255.
- P_DIR_PROC = '/usr/sap/afd/Processados'.
- P_DIR_ERRO = '/usr/sap/afd/Erro'.
- SELECT * FROM ZHCMT_PT_0004
- INTO TABLE @DATA(TG_ZHCMT_PT_0004).
- IF ( SY-SUBRC EQ 0 ).
- CLEAR: TG_TEXTO[].
- LOOP AT TG_ZHCMT_PT_0004 INTO DATA(WL_ZHCMT_PT_0004).
- P_DIR = WL_ZHCMT_PT_0004-DIR_DESC.
- WRITE P_DIR TO VL_DIR_NAME.
- CONDENSE VL_DIR_NAME.
- CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
- EXPORTING
- DIR_NAME = VL_DIR_NAME "'/usr/sap/afd/Ponto' "'\\srvvm07\HCM_DEV$\Ponto'
- TABLES
- DIR_LIST = DLIST
- EXCEPTIONS
- INVALID_EPS_SUBDIR = 1
- SAPGPARAM_FAILED = 2
- BUILD_DIRECTORY_FAILED = 3
- NO_AUTHORIZATION = 4
- READ_DIRECTORY_FAILED = 5
- TOO_MANY_READ_ERRORS = 6
- EMPTY_DIRECTORY_LIST = 7
- OTHERS = 8.
- IF SY-SUBRC = 0 .
- SORT: DLIST BY NAME.
- LOOP AT DLIST .
- CONCATENATE P_DIR '/' DLIST-NAME INTO V_FILENAME_STRING.
- CONCATENATE P_DIR_PROC '/' DLIST-NAME INTO V_FILENAME_STRING_PROC.
- CONCATENATE P_DIR_ERRO '/' DLIST-NAME INTO V_FILENAME_STRING_ERRO.
- MOVE V_FILENAME_STRING TO LV_NOME_ARQUIVO.
- MOVE V_FILENAME_STRING_PROC TO LV_NOME_ARQUIVO_PROC.
- MOVE V_FILENAME_STRING_ERRO TO LV_NOME_ARQUIVO_ERRO.
- CLEAR BDCDATA_WA.
- BDCDATA_WA-PROGRAM = 'HBRTMIF0'. "Nome do Programa
- BDCDATA_WA-DYNPRO = '1000'. " Numero da tela
- BDCDATA_WA-DYNBEGIN = 'X'.
- APPEND BDCDATA_WA TO BDCDATA_TAB.
- CLEAR BDCDATA_WA.
- BDCDATA_WA-FNAM = 'BDC_OKCODE'.
- BDCDATA_WA-FVAL = '=ONLI'.
- APPEND BDCDATA_WA TO BDCDATA_TAB.
- CLEAR BDCDATA_WA.
- BDCDATA_WA-FNAM = 'BDC_CURSOR'.
- BDCDATA_WA-FVAL = 'FILE'.
- APPEND BDCDATA_WA TO BDCDATA_TAB.
- CLEAR BDCDATA_WA.
- BDCDATA_WA-FNAM = 'FILE'. "Area de tela.
- BDCDATA_WA-FVAL = V_FILENAME_STRING.
- APPEND BDCDATA_WA TO BDCDATA_TAB.
- CLEAR BDCDATA_WA.
- BDCDATA_WA-FNAM = 'P_LOG'. "Area de tela.
- BDCDATA_WA-FVAL = 'X'.
- APPEND BDCDATA_WA TO BDCDATA_TAB.
- CLEAR CTU_PARAMETERS.
- CTU_PARAMETERS-DISMODE = 'N'.
- CTU_PARAMETERS-UPDMODE = 'S'.
- CTU_PARAMETERS-RACOMMIT = 'X'.
- DATA: DATASTAMP.
- CALL TRANSACTION 'PC00_M37_TMIF' USING BDCDATA_TAB OPTIONS FROM CTU_PARAMETERS.
- IMPORT ITAB TO ITAB FROM MEMORY ID 'ZHCM_LOG_HB'.
- IMPORT ITAB TO ITAB FROM MEMORY ID 'LOG_HBRTMIF0'.
- DELETE FROM MEMORY ID 'ZHCM_LOG_HB'.
- IMPORT ITAB = ITAB
- FROM SHARED BUFFER INDX(ST) ID 'LOG_HBRTMIF0'.
- DELETE FROM SHARED BUFFER INDX(ST) ID 'LOG_HBRTMIF0'.
- SELECT SINGLE MSG FROM ZHCMT_PT_0001
- INTO @DATA(V_MSG)
- WHERE AEDTM = @SY-DATUM AND
- SEQPROC = '999999' AND
- NOM_ARQ = 'LOG_PROCESSAMENTO' AND
- TP_MSG = 'E' AND
- STATUS = 'S'.
- IF SY-SUBRC = 0.
- DATA(W_LOG) = VALUE TY_ITAB(
- MSGTY_AUX = 'E'
- T_MSG_AUX = V_MSG
- ).
- APPEND W_LOG TO ITAB.
- DELETE FROM ZHCMT_PT_0001 WHERE AEDTM = SY-DATUM
- AND SEQPROC = '999999'
- AND NOM_ARQ = 'LOG_PROCESSAMENTO'.
- COMMIT WORK.
- CLEAR: V_MSG, W_LOG.
- ENDIF.
- "Verifica se existe erro.
- CLEAR WA_ITAB.
- READ TABLE ITAB INTO WA_ITAB WITH KEY MSGTY_AUX = 'E' .
- IF SY-SUBRC = 0 AND ITAB IS NOT INITIAL.
- CLEAR WA_ITAB.
- "Mover os erros para a tabela de erros. ZHCMT_PT_0001
- V_SEQPROC = 1.
- LOOP AT ITAB INTO WA_ITAB .
- WA_PT_0001-MANDT = SY-MANDT.
- WA_PT_0001-AEDTM = SY-DATUM.
- WA_PT_0001-AEZET = SY-UZEIT.
- WA_PT_0001-SEQPROC = V_SEQPROC.
- WA_PT_0001-TP_MSG = WA_ITAB-MSGTY_AUX.
- WA_PT_0001-MSG = WA_ITAB-T_MSG_AUX.
- WA_PT_0001-NOM_ARQ = LV_NOME_ARQUIVO_ERRO.
- WA_PT_0001-STATUS = 'N'.
- V_SEQPROC = V_SEQPROC + 1.
- APPEND WA_PT_0001 TO IT_PT_0001.
- CLEAR : WA_PT_0001.
- ENDLOOP.
- MODIFY ZHCMT_PT_0001 FROM TABLE IT_PT_0001.
- COMMIT WORK.
- CLEAR: IT_PT_0001[].
- OPEN DATASET LV_NOME_ARQUIVO IN TEXT MODE FOR INPUT ENCODING NON-UNICODE.
- CLEAR: T_FILE[].
- DO.
- READ DATASET LV_NOME_ARQUIVO INTO T_FILE.
- IF SY-SUBRC IS INITIAL.
- APPEND T_FILE.
- ELSE.
- EXIT.
- ENDIF.
- ENDDO.
- CLOSE DATASET LV_NOME_ARQUIVO.
- OPEN DATASET LV_NOME_ARQUIVO_ERRO IN TEXT MODE FOR OUTPUT ENCODING NON-UNICODE.
- LOOP AT T_FILE.
- TRANSFER T_FILE TO LV_NOME_ARQUIVO_ERRO.
- ENDLOOP.
- CLOSE DATASET LV_NOME_ARQUIVO_ERRO.
- DELETE DATASET LV_NOME_ARQUIVO.
- CLEAR : T_FILE[].
- ELSE. "SUCESSO
- OPEN DATASET LV_NOME_ARQUIVO IN TEXT MODE FOR INPUT ENCODING NON-UNICODE.
- CLEAR: T_FILE[].
- DO.
- READ DATASET LV_NOME_ARQUIVO INTO T_FILE.
- IF SY-SUBRC IS INITIAL.
- APPEND T_FILE.
- ELSE.
- EXIT.
- ENDIF.
- ENDDO.
- CLOSE DATASET LV_NOME_ARQUIVO.
- OPEN DATASET LV_NOME_ARQUIVO_PROC IN TEXT MODE FOR OUTPUT ENCODING NON-UNICODE.
- LOOP AT T_FILE.
- TRANSFER T_FILE TO LV_NOME_ARQUIVO_PROC.
- ENDLOOP.
- CLOSE DATASET LV_NOME_ARQUIVO_PROC.
- DELETE DATASET LV_NOME_ARQUIVO.
- CLEAR : T_FILE[].
- ENDIF.
- CLEAR: BDCDATA_TAB,
- BDCDATA_WA,
- V_FILENAME_STRING,
- V_FILENAME_STRING_PROC,
- V_FILENAME_STRING_ERRO,
- LV_NOME_ARQUIVO,
- LV_NOME_ARQUIVO_PROC,
- LV_NOME_ARQUIVO_ERRO,
- ITAB,
- WA_ITAB.
- ENDLOOP.
- IF ( SY-SUBRC EQ 0 ).
- WG_TEXTO = | { P_DIR } - PROCESSADO. | .
- APPEND WG_TEXTO TO TG_TEXTO[].
- CLEAR WG_TEXTO.
- ENDIF.
- MESSAGE 'Registros Processadsos com Sucesso' TYPE 'S'.
- ELSE.
- WG_TEXTO = COND #(
- WHEN ( SY-SUBRC = 1 ) THEN |{ P_DIR } - Diretório Inválido. |
- WHEN ( SY-SUBRC = 2 ) THEN |{ P_DIR } - Erro de Parâmetro. |
- WHEN ( SY-SUBRC = 3 ) THEN |{ P_DIR } - Diretório Com Falha. |
- WHEN ( SY-SUBRC = 4 ) THEN |{ P_DIR } - Sem autorização no Diretório. |
- WHEN ( SY-SUBRC = 5 ) THEN |{ P_DIR } - Leitura Falhou. |
- WHEN ( SY-SUBRC = 6 ) THEN |{ P_DIR } - Erro de Leitura. |
- WHEN ( SY-SUBRC = 7 ) THEN |{ P_DIR } - Sem Dados. |
- WHEN ( SY-SUBRC = 8 ) THEN |{ P_DIR } - Erro na exportação. | ).
- APPEND WG_TEXTO TO TG_TEXTO[].
- CLEAR: WG_TEXTO.
- ENDIF.
- ENDLOOP.
- IF ( SY-TCODE EQ 'ZHCM_PT0003' ).
- CALL FUNCTION 'CATSXT_SIMPLE_TEXT_EDITOR'
- EXPORTING
- IM_TITLE = 'Resumo da importação:'
- IM_DISPLAY_MODE = 'X'
- CHANGING
- CH_TEXT = TG_TEXTO.
- ENDIF.
- ENDIF.
- ENDFORM.
- FORM CHECK_RUNNING_JOB.
- SELECT SINGLE JOBNAME FROM TBTCO INTO @DATA(V_JOB)
- WHERE JOBNAME = 'TRATA_AFD_EMAIL'
- OR JOBNAME = 'HCM_CARGA_TIME'
- AND STATUS = 'R'.
- IF SY-SUBRC = 0.
- WAIT UP TO 10 SECONDS.
- SELECT SINGLE JOBNAME FROM TBTCO INTO V_JOB
- WHERE JOBNAME = 'TRATA_AFD_EMAIL'
- OR JOBNAME = 'HCM_CARGA_TIME'
- AND STATUS = 'R'.
- IF SY-SUBRC = 0.
- EXIT.
- ENDIF.
- ENDIF.
- ENDFORM.
- *&---------------------------------------------------------------------*
- *& Module STATUS_0100 OUTPUT
- *&---------------------------------------------------------------------*
- * text
- *----------------------------------------------------------------------*
- MODULE STATUS_0100 OUTPUT.
- SET PF-STATUS 'FF0100'.
- SET TITLEBAR 'TB0100'.
- ENDMODULE.
- *&---------------------------------------------------------------------*
- *& Module USER_COMMAND_0100 INPUT
- *&---------------------------------------------------------------------*
- * text
- *----------------------------------------------------------------------*
- MODULE USER_COMMAND_0100 INPUT.
- CASE SY-UCOMM.
- WHEN 'BACK'.
- LEAVE TO SCREEN 0.
- WHEN 'SEL'.
- PERFORM:
- F_PROCESSA_DADOS. " Form seleciona dados
- ENDCASE.
- ENDMODULE.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement