Advertisement
Kusterek

ZWL_GET_DATA_FROM_FILE_FM

Dec 5th, 2019
1,103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ABAP 7.17 KB | None | 0 0
  1. *&---------------------------------------------------------------------*
  2. *& Include          ZWL_GET_DATA_FROM_FM
  3. *&---------------------------------------------------------------------*
  4. FORM get_initialization_data.
  5.  
  6. ******************************************************
  7. ** Przykłado config
  8. **  FILE_BATCH_SIZE   500000
  9. **  FILE_PATH           /usr/sap/trans/data/
  10. **  FILE_STRING_MASKS   *maski*
  11. **  FILE_STRING_PC    *skrotyPodatnikowCzynnych*
  12. **  FILE_STRING_PZ    *skrotyPodatnikowZwolnionych*
  13. **
  14. ******************************************************
  15.  
  16.  
  17.   TRY.
  18.  
  19.       go_cfg       = NEW zwl_cl_taxpayer_cfg_helper( ).
  20.       p_path       = go_cfg->get_file_path( ).
  21.       p_batch      = go_cfg->get_file_batch_size( ).
  22.       gv_str_pc    = go_cfg->get_cfg_by_name( 'FILE_STRING_PC' ).
  23.       gv_str_pz    = go_cfg->get_cfg_by_name( 'FILE_STRING_PZ' ).
  24.       gv_str_masks = go_cfg->get_cfg_by_name( 'FILE_STRING_MASKS' ).
  25.       gv_ok = 'X'.
  26.  
  27.     CATCH zcx_wl_taxpayer INTO DATA(lo_cx).
  28.       MESSAGE lo_cx->get_custom_text( ) TYPE 'W' DISPLAY LIKE 'E'.
  29.  
  30.   ENDTRY.
  31.  
  32.  
  33. ENDFORM.
  34.  
  35. FORM convert_data.
  36.  
  37.   DATA: lt_data_pc    TYPE TABLE OF zwl_hashed_pc WITH EMPTY KEY,
  38.         lt_data_pz    TYPE TABLE OF zwl_hashed_pz WITH EMPTY KEY,
  39.         lt_data_masks TYPE TABLE OF zwl_hashed_masks WITH EMPTY KEY,
  40.         lv_line       TYPE string,
  41.         lv_mode       TYPE c.
  42.  
  43.   DATA: lv_ind_pc    TYPE i,
  44.         lv_ind_pz    TYPE i,
  45.         lv_ind_masks TYPE i.
  46.  
  47.   DATA(lv_file_path) = |{ p_path }{ p_dats }{ c_file }|.
  48.  
  49.   OPEN DATASET lv_file_path FOR INPUT IN TEXT MODE ENCODING DEFAULT.
  50.   DO.
  51.     IF sy-subrc = 8.
  52.       EXIT.
  53.     ENDIF.
  54.     READ DATASET lv_file_path INTO lv_line.
  55.     IF lv_line IS NOT INITIAL.
  56.  
  57.       PERFORM get_mode USING lv_line CHANGING lv_mode.
  58.  
  59.       CASE lv_mode.
  60.  
  61.         WHEN 'C'. "Podatnicy czynni
  62.           PERFORM transfer_pc_data USING lv_line CHANGING lv_ind_pc lt_data_pc.
  63.  
  64.         WHEN 'Z'. "Podatnicy zwolnieni
  65.           PERFORM transfer_pz_data USING lv_line CHANGING lv_ind_pz lt_data_pz.
  66.  
  67.         WHEN 'M'. "Maski
  68.           PERFORM transfer_masks_data USING lv_line CHANGING lv_ind_masks lt_data_masks.
  69.  
  70.       ENDCASE.
  71.     ELSE.
  72.       EXIT.
  73.     ENDIF.
  74.  
  75.   ENDDO.
  76.  
  77.   CLOSE DATASET lv_file_path.
  78.  
  79.   PERFORM insert_left_data CHANGING lt_data_pc lt_data_pz lt_data_masks.
  80.  
  81.   IF lv_ind_pc > 0.
  82.     gv_ok = 'X'.
  83.     WRITE : / 'Zaktualizowano tabelę ZWL_HASHED_PC -' COLOR COL_POSITIVE, lv_ind_pc, 'wpisów.'.
  84.   ELSE.
  85.     WRITE : / 'Brak nowych danych dla tabeli ZWL_HASHED_PC.' COLOR COL_NEGATIVE.
  86.   ENDIF.
  87.  
  88.   IF lv_ind_pz > 0.
  89.     gv_ok = 'X'.
  90.     WRITE : / 'Zaktualizowano tabelę ZWL_HASHED_PZ -' COLOR COL_POSITIVE, lv_ind_pz, 'wpisów.'.
  91.   ELSE.
  92.     WRITE : / 'Brak nowych danych dla tabeli ZWL_HASHED_PZ.' COLOR COL_NEGATIVE.
  93.   ENDIF.
  94.  
  95.   IF lv_ind_masks > 0.
  96.     gv_ok = 'X'.
  97.     WRITE : / 'Zaktualizowano tabelę ZWL_HASHED_MASKS -' COLOR COL_POSITIVE, lv_ind_masks, 'wpisów.'.
  98.   ELSE.
  99.     WRITE : / 'Brak nowych danych dla tabeli ZWL_HASHED_MASKS.' COLOR COL_NEGATIVE.
  100.   ENDIF.
  101.  
  102. ENDFORM.
  103.  
  104. FORM insert_left_data CHANGING ct_data_pc TYPE tt_pc ct_data_pz TYPE tt_pz ct_data_masks TYPE tt_masks.
  105.  
  106.   INSERT zwl_hashed_pc FROM TABLE ct_data_pc.
  107.   INSERT zwl_hashed_pz FROM TABLE ct_data_pz.
  108.   INSERT zwl_hashed_masks FROM TABLE ct_data_masks.
  109.  
  110.   CLEAR: ct_data_pc, ct_data_pz, ct_data_masks.
  111.  
  112. ENDFORM.
  113.  
  114. FORM get_mode USING iv_data TYPE string CHANGING cv_mode TYPE c.
  115.  
  116.   IF iv_data CP gv_str_pc.
  117.     cv_mode = 'C'.
  118.     EXIT.
  119.   ENDIF.
  120.  
  121.   IF iv_data CP gv_str_pz.
  122.     cv_mode = 'Z'.
  123.     EXIT.
  124.   ENDIF.
  125.  
  126.   IF iv_data CP gv_str_masks.
  127.     cv_mode = 'M'.
  128.     EXIT.
  129.   ENDIF.
  130.  
  131. ENDFORM.
  132.  
  133. FORM transfer_pc_data USING iv_data TYPE string CHANGING cv_ind ct_data_pc TYPE tt_pc.
  134.  
  135.   DATA: ls_data TYPE zwl_hashed_pc,
  136.         lv_data TYPE string.
  137.  
  138.   FIND REGEX '\"(.*)\"'
  139.     IN iv_data
  140.     SUBMATCHES lv_data
  141.     RESPECTING CASE.
  142.  
  143.   CHECK strlen( lv_data ) = 128.
  144.  
  145.   cv_ind = cv_ind + 1.
  146.  
  147.   IF cv_ind MOD p_batch = 0.
  148.     INSERT zwl_hashed_pc FROM TABLE ct_data_pc.
  149.     CLEAR ct_data_pc.
  150.   ENDIF.
  151.  
  152.   ls_data-hashed_key = lv_data.
  153.   ct_data_pc = VALUE #( BASE ct_data_pc ( ls_data ) ).
  154.  
  155. ENDFORM.
  156.  
  157. FORM transfer_pz_data USING iv_data TYPE string CHANGING cv_ind ct_data_pz TYPE tt_pz.
  158.  
  159.   DATA: ls_data TYPE zwl_hashed_pz,
  160.         lv_data TYPE string.
  161.  
  162.   FIND REGEX '\"(.*)\"'
  163.     IN iv_data
  164.     SUBMATCHES lv_data
  165.     RESPECTING CASE.
  166.  
  167.   CHECK strlen( lv_data ) = 128.
  168.  
  169.   cv_ind = cv_ind + 1.
  170.  
  171.   IF cv_ind MOD p_batch = 0.
  172.     INSERT zwl_hashed_pz FROM TABLE ct_data_pz.
  173.     CLEAR ct_data_pz.
  174.   ENDIF.
  175.  
  176.   ls_data-hashed_key = lv_data.
  177.   ct_data_pz = VALUE #( BASE ct_data_pz ( ls_data ) ).
  178.  
  179. ENDFORM.
  180.  
  181. FORM transfer_masks_data USING iv_data TYPE string CHANGING cv_ind ct_data_masks TYPE tt_masks.
  182.  
  183.   DATA: ls_data TYPE zwl_hashed_masks,
  184.         lv_data TYPE string.
  185.  
  186.   FIND REGEX '\"(.*)\"'
  187.     IN iv_data
  188.     SUBMATCHES lv_data
  189.     RESPECTING CASE.
  190.  
  191.   CHECK strlen( lv_data ) = 26.
  192.  
  193.   cv_ind = cv_ind + 1.
  194.  
  195.   IF cv_ind MOD p_batch = 0.
  196.     INSERT zwl_hashed_masks FROM TABLE ct_data_masks.
  197.     CLEAR ct_data_masks.
  198.   ENDIF.
  199.  
  200.   ls_data-mask_key   = lv_data+2(8).
  201.   ls_data-mask_value = lv_data.
  202.   ct_data_masks = VALUE #( BASE ct_data_masks ( ls_data ) ).
  203.  
  204. ENDFORM.
  205.  
  206.  
  207.  
  208. FORM set_update_date.
  209.  
  210.   IF gv_ok = 'X'.
  211.     go_cfg->set_last_update_date( p_dats ).
  212.   ENDIF.
  213.  
  214. ENDFORM.
  215. *&---------------------------------------------------------------------*
  216. *& Form CLEAR_DB_TABLEs
  217. *&---------------------------------------------------------------------*
  218. *& text
  219. *&---------------------------------------------------------------------*
  220. *& -->  p1        text
  221. *& <--  p2        text
  222. *&---------------------------------------------------------------------*
  223. FORM clear_db_tables .
  224.  
  225.   DELETE FROM zwl_hashed_pc.
  226.   DELETE FROM zwl_hashed_pz.
  227.   DELETE FROM zwl_hashed_masks.
  228.  
  229.   COMMIT WORK AND WAIT.
  230.  
  231. ENDFORM.
  232. *&---------------------------------------------------------------------*
  233. *& Form CHECK_FILES_EXISTS
  234. *&---------------------------------------------------------------------*
  235. *& text
  236. *&---------------------------------------------------------------------*
  237. *& -->  p1        text
  238. *& <--  p2        text
  239. *&---------------------------------------------------------------------*
  240. FORM check_files_exists CHANGING ev_ok.
  241.  
  242.   DATA lv_file_path TYPE string.
  243.  
  244.   ev_ok = 'X'.
  245.  
  246.   lv_file_path = |{ p_path }{ p_dats }{ c_file }|.
  247.   OPEN DATASET lv_file_path FOR INPUT IN TEXT MODE ENCODING DEFAULT.
  248.   IF sy-subrc <> 0.
  249.     CLEAR ev_ok.
  250.     WRITE : / 'Brak pliku' COLOR COL_TOTAL, lv_file_path.
  251.   ENDIF.
  252.   CLOSE DATASET lv_file_path.
  253. *
  254. *  lv_file_path = |{ p_path }{ p_dats }{ c_file_inact }|.
  255. *  OPEN DATASET lv_file_path FOR INPUT IN TEXT MODE ENCODING DEFAULT.
  256. *  IF sy-subrc <> 0.
  257. *    CLEAR ev_ok.
  258. *    WRITE : / 'Brak pliku' COLOR COL_TOTAL, lv_file_path.
  259. *  ENDIF.
  260. *  CLOSE DATASET lv_file_path.
  261. *
  262. *  lv_file_path = |{ p_path }{ p_dats }{ c_file_masks }|.
  263. *  OPEN DATASET lv_file_path FOR INPUT IN TEXT MODE ENCODING DEFAULT.
  264. *  IF sy-subrc <> 0.
  265. *    CLEAR ev_ok.
  266. *    WRITE : / 'Brak pliku' COLOR COL_TOTAL, lv_file_path.
  267. *  ENDIF.
  268. *  CLOSE DATASET lv_file_path.
  269.  
  270.  
  271.  
  272. ENDFORM.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement