kaio1001

Untitled

Jul 13th, 2020
146
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. *&------------------------------------------------------------------------*
  2. *& Report  ZHCMR_PT0002
  3. *& Carregar dados Ponto e executar programa
  4. *&-*----------------------------------------------------------------------*
  5. * Autor      : Camila Brand                              Data: 03.02.2017 *
  6. * Observações: Desenvolvimento inicial do Programa                        *
  7. *&------------------------------------------------------------------------*
  8. REPORT  ZHCMPTR011.
  9.  
  10. *----------------------------------------------------------------------*
  11. * TABLES
  12. *----------------------------------------------------------------------*
  13. TABLES: ZHCMT_PT_0004.
  14. *----------------------------------------------------------------------*
  15. * TYPE POOLS
  16. *----------------------------------------------------------------------*
  17. TYPE-POOLS: ICON,
  18.             SLIS.
  19. *&---------------------------------------------------------------------*
  20. *& TYPES
  21. *&---------------------------------------------------------------------*
  22.  
  23. TYPES: BEGIN OF TY_ITAB,
  24.          MSGTY_AUX TYPE BAL_S_SHOW-MSGTY,
  25.          T_MSG_AUX TYPE BAL_S_SHOW-T_MSG,
  26.        END OF TY_ITAB.
  27.  
  28. TYPES: TT_ITAB TYPE STANDARD TABLE OF TY_ITAB.
  29.  
  30. *&---------------------------------------------------------------------*
  31. *& DATA
  32. *&---------------------------------------------------------------------*
  33. DATA: DLIST       LIKE EPSFILI OCCURS 0 WITH HEADER LINE.
  34. DATA: TABAPLIST   LIKE ABAPLIST OCCURS 0 WITH HEADER LINE.
  35.  
  36. DATA: ITAB     TYPE TABLE OF TY_ITAB,
  37.       WA_ITAB  LIKE LINE OF ITAB,
  38.       TG_TEXTO TYPE TABLE OF TXLINE,
  39.       WG_TEXTO LIKE LINE OF TG_TEXTO.
  40.  
  41. DATA: IT_PT_0001 LIKE ZHCMT_PT_0001 OCCURS 0 WITH HEADER LINE,
  42.       WA_PT_0001 LIKE LINE OF IT_PT_0001,
  43.       T_MSG      TYPE TABLE OF BDCMSGCOLL.
  44.  
  45. DATA: BDCDATA_WA  TYPE BDCDATA,
  46.       BDCDATA_TAB TYPE TABLE OF BDCDATA.
  47.  
  48. DATA: CTU_PARAMETERS TYPE CTU_PARAMS.
  49.  
  50. DATA: LV_NOME_ARQUIVO_ERRO   TYPE STRING,
  51.       LV_NOME_ARQUIVO_PROC   TYPE STRING,
  52.       LV_NOME_ARQUIVO        TYPE STRING,
  53.  
  54.       T_FILE                 TYPE TABLE OF ZARQ_BLOOMBERG WITH HEADER LINE,
  55.       WA_T_FILE              TYPE ZARQ_BLOOMBERG,
  56.  
  57.       V_FILENAME_STRING      TYPE RLGRAP-FILENAME,
  58.       V_FILENAME_STRING_PROC TYPE RLGRAP-FILENAME,
  59.       V_FILENAME_STRING_ERRO TYPE RLGRAP-FILENAME,
  60.  
  61.       P_DIR(60)              TYPE C,
  62.       P_DIR_PROC(50)         TYPE C,
  63.       P_DIR_ERRO(50)         TYPE C.
  64.  
  65. DATA V_SEQPROC TYPE NUM06.
  66.  
  67. TYPES : BEGIN OF TY_GET_SPOOLDATA,
  68.           LINE(1000) TYPE  C,
  69.           FLAG(1)    TYPE  C,
  70.         END OF TY_GET_SPOOLDATA.
  71.  
  72. *&---------------------------------------------------------------------*
  73. *& START OF SELECTION
  74. *&---------------------------------------------------------------------*
  75. START-OF-SELECTION.
  76.   IF SY-BATCH IS INITIAL.
  77.     CALL SCREEN 0100.
  78.   ELSE.
  79.     PERFORM:
  80.          CHECK_RUNNING_JOB,
  81.          F_PROCESSA_DADOS. " Form seleciona dados
  82.   ENDIF.
  83.  
  84. END-OF-SELECTION.
  85.  
  86. *&---------------------------------------------------------------------*
  87. *& INICIO PROCESSAMENTO
  88. *&---------------------------------------------------------------------*
  89. FORM F_PROCESSA_DADOS .
  90.  
  91.   DATA: VL_DIR_NAME  TYPE  EPSF-EPSDIRNAM,
  92.         T_PARAMS     TYPE TABLE OF RSPARAMS,
  93.         T_PARAMS_255 TYPE TABLE OF RSPARAMSL_255.
  94.  
  95.   P_DIR_PROC      = '/usr/sap/afd/Processados'.
  96.   P_DIR_ERRO      = '/usr/sap/afd/Erro'.
  97.  
  98.   SELECT * FROM ZHCMT_PT_0004
  99.   INTO TABLE @DATA(TG_ZHCMT_PT_0004).
  100.  
  101.   IF ( SY-SUBRC EQ 0 ).
  102.     CLEAR: TG_TEXTO[].
  103.     LOOP AT TG_ZHCMT_PT_0004 INTO DATA(WL_ZHCMT_PT_0004).
  104.  
  105.       P_DIR = WL_ZHCMT_PT_0004-DIR_DESC.
  106.       WRITE P_DIR TO VL_DIR_NAME.
  107.  
  108.       CONDENSE VL_DIR_NAME.
  109.  
  110.       CALL FUNCTION 'EPS_GET_DIRECTORY_LISTING'
  111.         EXPORTING
  112.           DIR_NAME               = VL_DIR_NAME                               "'/usr/sap/afd/Ponto' "'\\srvvm07\HCM_DEV$\Ponto'
  113.         TABLES
  114.           DIR_LIST               = DLIST
  115.         EXCEPTIONS
  116.           INVALID_EPS_SUBDIR     = 1
  117.           SAPGPARAM_FAILED       = 2
  118.           BUILD_DIRECTORY_FAILED = 3
  119.           NO_AUTHORIZATION       = 4
  120.           READ_DIRECTORY_FAILED  = 5
  121.           TOO_MANY_READ_ERRORS   = 6
  122.           EMPTY_DIRECTORY_LIST   = 7
  123.           OTHERS                 = 8.
  124.  
  125.       IF SY-SUBRC = 0 .
  126.  
  127.         SORT: DLIST      BY NAME.
  128.  
  129.         LOOP AT DLIST .
  130.  
  131.           CONCATENATE  P_DIR       '/'  DLIST-NAME INTO V_FILENAME_STRING.
  132.           CONCATENATE  P_DIR_PROC  '/'  DLIST-NAME INTO V_FILENAME_STRING_PROC.
  133.           CONCATENATE  P_DIR_ERRO  '/'  DLIST-NAME INTO V_FILENAME_STRING_ERRO.
  134.  
  135.           MOVE V_FILENAME_STRING        TO LV_NOME_ARQUIVO.
  136.           MOVE V_FILENAME_STRING_PROC   TO LV_NOME_ARQUIVO_PROC.
  137.           MOVE V_FILENAME_STRING_ERRO   TO LV_NOME_ARQUIVO_ERRO.
  138.  
  139.           CLEAR BDCDATA_WA.
  140.           BDCDATA_WA-PROGRAM  = 'HBRTMIF0'. "Nome do Programa
  141.           BDCDATA_WA-DYNPRO   = '1000'.     " Numero da tela
  142.           BDCDATA_WA-DYNBEGIN = 'X'.
  143.           APPEND BDCDATA_WA TO BDCDATA_TAB.
  144.  
  145.           CLEAR BDCDATA_WA.
  146.           BDCDATA_WA-FNAM = 'BDC_OKCODE'.
  147.           BDCDATA_WA-FVAL = '=ONLI'.
  148.           APPEND BDCDATA_WA TO BDCDATA_TAB.
  149.  
  150.           CLEAR BDCDATA_WA.
  151.           BDCDATA_WA-FNAM = 'BDC_CURSOR'.
  152.           BDCDATA_WA-FVAL = 'FILE'.
  153.           APPEND BDCDATA_WA TO BDCDATA_TAB.
  154.  
  155.           CLEAR BDCDATA_WA.
  156.           BDCDATA_WA-FNAM = 'FILE'.  "Area de tela.
  157.           BDCDATA_WA-FVAL = V_FILENAME_STRING.
  158.           APPEND BDCDATA_WA TO BDCDATA_TAB.
  159.  
  160.           CLEAR BDCDATA_WA.
  161.           BDCDATA_WA-FNAM = 'P_LOG'.  "Area de tela.
  162.           BDCDATA_WA-FVAL = 'X'.
  163.           APPEND BDCDATA_WA TO BDCDATA_TAB.
  164.  
  165.           CLEAR CTU_PARAMETERS.
  166.  
  167.           CTU_PARAMETERS-DISMODE =  'N'.
  168.           CTU_PARAMETERS-UPDMODE =  'S'.
  169.           CTU_PARAMETERS-RACOMMIT = 'X'.
  170.  
  171.           DATA:  DATASTAMP.
  172.  
  173.           CALL TRANSACTION 'PC00_M37_TMIF' USING BDCDATA_TAB OPTIONS FROM CTU_PARAMETERS.
  174.  
  175.  
  176.           IMPORT ITAB TO ITAB FROM MEMORY ID 'ZHCM_LOG_HB'.
  177.           IMPORT ITAB TO ITAB FROM MEMORY ID 'LOG_HBRTMIF0'.
  178.  
  179.           DELETE FROM MEMORY ID 'ZHCM_LOG_HB'.
  180.  
  181.           IMPORT ITAB = ITAB
  182.                  FROM SHARED BUFFER INDX(ST) ID 'LOG_HBRTMIF0'.
  183.  
  184.           DELETE FROM SHARED BUFFER INDX(ST) ID 'LOG_HBRTMIF0'.
  185.  
  186.           SELECT SINGLE MSG FROM ZHCMT_PT_0001
  187.             INTO @DATA(V_MSG)
  188.             WHERE AEDTM = @SY-DATUM   AND
  189.                   SEQPROC = '999999'  AND
  190.                   NOM_ARQ = 'LOG_PROCESSAMENTO' AND
  191.                   TP_MSG  = 'E' AND
  192.                   STATUS  = 'S'.
  193.           IF SY-SUBRC = 0.
  194.             DATA(W_LOG) = VALUE TY_ITAB(
  195.                 MSGTY_AUX = 'E'
  196.                 T_MSG_AUX = V_MSG
  197.             ).
  198.             APPEND W_LOG TO ITAB.
  199.  
  200.             DELETE FROM ZHCMT_PT_0001 WHERE AEDTM = SY-DATUM
  201.                                         AND SEQPROC = '999999'
  202.                                         AND NOM_ARQ = 'LOG_PROCESSAMENTO'.
  203.             COMMIT WORK.
  204.             CLEAR: V_MSG, W_LOG.
  205.           ENDIF.
  206.  
  207.  
  208.           "Verifica se existe erro.
  209.           CLEAR WA_ITAB.
  210.  
  211.           READ TABLE ITAB INTO WA_ITAB WITH KEY MSGTY_AUX = 'E' .
  212.  
  213.           IF SY-SUBRC = 0 AND ITAB IS NOT INITIAL.
  214.  
  215.             CLEAR WA_ITAB.
  216.  
  217.             "Mover os erros para a tabela de erros. ZHCMT_PT_0001
  218.             V_SEQPROC = 1.
  219.  
  220.             LOOP AT ITAB INTO WA_ITAB .
  221.  
  222.               WA_PT_0001-MANDT   = SY-MANDT.
  223.               WA_PT_0001-AEDTM   = SY-DATUM.
  224.               WA_PT_0001-AEZET   = SY-UZEIT.
  225.               WA_PT_0001-SEQPROC = V_SEQPROC.
  226.               WA_PT_0001-TP_MSG  = WA_ITAB-MSGTY_AUX.
  227.               WA_PT_0001-MSG     = WA_ITAB-T_MSG_AUX.
  228.               WA_PT_0001-NOM_ARQ = LV_NOME_ARQUIVO_ERRO.
  229.               WA_PT_0001-STATUS  = 'N'.
  230.  
  231.               V_SEQPROC = V_SEQPROC + 1.
  232.  
  233.               APPEND WA_PT_0001 TO IT_PT_0001.
  234.  
  235.               CLEAR : WA_PT_0001.
  236.  
  237.             ENDLOOP.
  238.  
  239.             MODIFY ZHCMT_PT_0001 FROM TABLE IT_PT_0001.
  240.  
  241.             COMMIT WORK.
  242.  
  243.             CLEAR: IT_PT_0001[].
  244.  
  245.             OPEN DATASET LV_NOME_ARQUIVO IN TEXT MODE FOR INPUT ENCODING NON-UNICODE.
  246.  
  247.             CLEAR: T_FILE[].
  248.             DO.
  249.               READ DATASET LV_NOME_ARQUIVO INTO T_FILE.
  250.               IF SY-SUBRC  IS INITIAL.
  251.                 APPEND T_FILE.
  252.               ELSE.
  253.                 EXIT.
  254.               ENDIF.
  255.             ENDDO.
  256.  
  257.             CLOSE DATASET LV_NOME_ARQUIVO.
  258.  
  259.             OPEN DATASET LV_NOME_ARQUIVO_ERRO IN TEXT MODE FOR OUTPUT ENCODING NON-UNICODE.
  260.  
  261.             LOOP AT T_FILE.
  262.               TRANSFER T_FILE TO LV_NOME_ARQUIVO_ERRO.
  263.             ENDLOOP.
  264.  
  265.             CLOSE DATASET  LV_NOME_ARQUIVO_ERRO.
  266.             DELETE DATASET LV_NOME_ARQUIVO.
  267.  
  268.             CLEAR : T_FILE[].
  269.  
  270.           ELSE. "SUCESSO
  271.  
  272.             OPEN DATASET LV_NOME_ARQUIVO IN TEXT MODE FOR INPUT ENCODING NON-UNICODE.
  273.  
  274.             CLEAR: T_FILE[].
  275.             DO.
  276.               READ DATASET LV_NOME_ARQUIVO INTO T_FILE.
  277.               IF SY-SUBRC  IS INITIAL.
  278.                 APPEND T_FILE.
  279.               ELSE.
  280.                 EXIT.
  281.               ENDIF.
  282.             ENDDO.
  283.  
  284.             CLOSE DATASET LV_NOME_ARQUIVO.
  285.  
  286.             OPEN DATASET LV_NOME_ARQUIVO_PROC IN TEXT MODE FOR OUTPUT ENCODING NON-UNICODE.
  287.  
  288.             LOOP AT T_FILE.
  289.               TRANSFER T_FILE TO LV_NOME_ARQUIVO_PROC.
  290.             ENDLOOP.
  291.  
  292.             CLOSE DATASET  LV_NOME_ARQUIVO_PROC.
  293.             DELETE DATASET LV_NOME_ARQUIVO.
  294.  
  295.             CLEAR : T_FILE[].
  296.  
  297.           ENDIF.
  298.  
  299.           CLEAR:  BDCDATA_TAB,
  300.                   BDCDATA_WA,
  301.                   V_FILENAME_STRING,
  302.                   V_FILENAME_STRING_PROC,
  303.                   V_FILENAME_STRING_ERRO,
  304.                   LV_NOME_ARQUIVO,
  305.                   LV_NOME_ARQUIVO_PROC,
  306.                   LV_NOME_ARQUIVO_ERRO,
  307.                   ITAB,
  308.                   WA_ITAB.
  309.  
  310.         ENDLOOP.
  311.  
  312.         IF ( SY-SUBRC EQ 0 ).
  313.           WG_TEXTO = | { P_DIR } - PROCESSADO. | .
  314.           APPEND WG_TEXTO TO TG_TEXTO[].
  315.           CLEAR WG_TEXTO.
  316.         ENDIF.
  317.  
  318.         MESSAGE 'Registros Processadsos com Sucesso' TYPE 'S'.
  319.  
  320.       ELSE.
  321.  
  322.         WG_TEXTO = COND #(
  323.                     WHEN ( SY-SUBRC = 1 ) THEN |{ P_DIR } - Diretório Inválido. |
  324.                     WHEN ( SY-SUBRC = 2 ) THEN |{ P_DIR } - Erro de Parâmetro. |
  325.                     WHEN ( SY-SUBRC = 3 ) THEN |{ P_DIR } - Diretório Com Falha. |
  326.                     WHEN ( SY-SUBRC = 4 ) THEN |{ P_DIR } - Sem autorização no Diretório. |
  327.                     WHEN ( SY-SUBRC = 5 ) THEN |{ P_DIR } - Leitura Falhou. |
  328.                     WHEN ( SY-SUBRC = 6 ) THEN |{ P_DIR } - Erro de Leitura. |
  329.                     WHEN ( SY-SUBRC = 7 ) THEN |{ P_DIR } - Sem Dados. |
  330.                     WHEN ( SY-SUBRC = 8 ) THEN |{ P_DIR } - Erro na exportação. | ).
  331.         APPEND  WG_TEXTO TO TG_TEXTO[].
  332.         CLEAR:  WG_TEXTO.
  333.  
  334.       ENDIF.
  335.  
  336.     ENDLOOP.
  337.  
  338.     IF ( SY-TCODE EQ 'ZHCM_PT0003' ).
  339.  
  340.       CALL FUNCTION 'CATSXT_SIMPLE_TEXT_EDITOR'
  341.         EXPORTING
  342.           IM_TITLE        = 'Resumo da importação:'
  343.           IM_DISPLAY_MODE = 'X'
  344.         CHANGING
  345.           CH_TEXT         = TG_TEXTO.
  346.  
  347.     ENDIF.
  348.  
  349.   ENDIF.
  350.  
  351. ENDFORM.
  352.  
  353.  
  354. FORM CHECK_RUNNING_JOB.
  355.  
  356.   SELECT SINGLE JOBNAME FROM TBTCO INTO @DATA(V_JOB)
  357.       WHERE JOBNAME = 'TRATA_AFD_EMAIL'
  358.          OR JOBNAME = 'HCM_CARGA_TIME'
  359.         AND STATUS = 'R'.
  360.   IF SY-SUBRC = 0.
  361.     WAIT UP TO 10 SECONDS.
  362.     SELECT SINGLE JOBNAME FROM TBTCO INTO V_JOB
  363.       WHERE JOBNAME = 'TRATA_AFD_EMAIL'
  364.          OR JOBNAME = 'HCM_CARGA_TIME'
  365.         AND STATUS = 'R'.
  366.     IF SY-SUBRC = 0.
  367.       EXIT.
  368.     ENDIF.
  369.   ENDIF.
  370.  
  371. ENDFORM.
  372.  
  373. *&---------------------------------------------------------------------*
  374. *&      Module  STATUS_0100  OUTPUT
  375. *&---------------------------------------------------------------------*
  376. *       text
  377. *----------------------------------------------------------------------*
  378. MODULE STATUS_0100 OUTPUT.
  379.   SET PF-STATUS 'FF0100'.
  380.   SET TITLEBAR  'TB0100'.
  381. ENDMODULE.
  382. *&---------------------------------------------------------------------*
  383. *&      Module  USER_COMMAND_0100  INPUT
  384. *&---------------------------------------------------------------------*
  385. *       text
  386. *----------------------------------------------------------------------*
  387. MODULE USER_COMMAND_0100 INPUT.
  388.   CASE SY-UCOMM.
  389.     WHEN 'BACK'.
  390.       LEAVE TO SCREEN 0.
  391.     WHEN 'SEL'.
  392.       PERFORM:
  393.                F_PROCESSA_DADOS. " Form seleciona dados
  394.   ENDCASE.
  395. ENDMODULE.
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×