Skip to Content
1
May 04, 2018 at 04:07 PM

How to refresh the cache after mass creation of release strategies for purchase requisition?

537 Views Last edit May 07, 2018 at 08:34 AM 6 rev

Dear SAP-Experts,

i have a small report, wich have to create mass release strategies for purchase requisition from a Excel file. My report works fine for all new release strategies (not allready existing in SAP). When a release strategy already exist in SAP, it will be overwritten with the release strategy from Excel file (the new release code will be addopted). The code is as follow.

REPORT ztof_rs.

TYPE-POOLS: truxs.

TYPES:
  BEGIN OF gty_relstrat,
    gruppe      TYPE frggr,
    strategie   TYPE frgsx,
    bezeichnung TYPE frgxt,
    code_1      TYPE frgco,
    code_2      TYPE frgco,
    code_3      TYPE frgco,
    code_4      TYPE frgco,
    code_5      TYPE frgco,
    code_6      TYPE frgco,
    code_7      TYPE frgco,
    code_8      TYPE frgco,
  END OF gty_relstrat.

DATA: lt_relstrat TYPE TABLE OF gty_relstrat,
      ls_relstrat TYPE gty_relstrat,
      lt_t16fv    TYPE TABLE OF t16fv,
      ls_t16fv    TYPE t16fv,
      lt_t16fk    TYPE TABLE OF t16fk,
      ls_t16fk    TYPE t16fk,
      lt_t16ft    TYPE TABLE OF t16ft,
      ls_t16ft    TYPE t16ft,
      lt_t16fs    TYPE TABLE OF t16fs,
      ls_t16fs    TYPE t16fs.

DATA: oerror           TYPE REF TO cx_root,
      lt_raw           TYPE truxs_t_text_data,
      lv_txterror      TYPE string,
      lv_txterror_long TYPE string,
      f_path           TYPE string.


DATA: lv_rc         TYPE i,
      lt_file_table TYPE filetable,
      ls_file_table LIKE LINE OF lt_file_table,
      lv_nr         TYPE i.



PARAMETERS lp_fname TYPE rlgrap-filename.


AT SELECTION-SCREEN ON VALUE-REQUEST FOR lp_fname.
  CALL METHOD cl_gui_frontend_services=>file_open_dialog
    EXPORTING
      window_title            = 'Datei auswählen'
      file_filter             = '*.XLS)|*.XLSX'
    CHANGING
      file_table              = lt_file_table
      rc                      = lv_rc
    EXCEPTIONS
      file_open_dialog_failed = 1
      cntl_error              = 2
      error_no_gui            = 3
      not_supported_by_gui    = 4
      OTHERS                  = 5.

  IF sy-subrc EQ 0.
    READ TABLE lt_file_table INTO ls_file_table INDEX 1.
    WRITE ls_file_table-filename TO lp_fname.
  ELSE.
    MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  ENDIF.



START-OF-SELECTION.
  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
      i_line_header        = abap_true
      i_tab_raw_data       = lt_raw
      i_filename           = lp_fname
    TABLES
      i_tab_converted_data = lt_relstrat
    EXCEPTIONS
      conversion_failed    = 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.





    TRY.
        LOOP AT lt_relstrat INTO ls_relstrat.
          DELETE FROM t16fs WHERE frggr = ls_relstrat-gruppe AND frgsx = ls_relstrat-strategie.
          DELETE FROM t16fk WHERE frggr = ls_relstrat-gruppe AND frgsx = ls_relstrat-strategie.
          DELETE FROM t16ft WHERE frggr = ls_relstrat-gruppe AND frgsx = ls_relstrat-strategie.
          DELETE FROM t16fv WHERE frggr = ls_relstrat-gruppe AND frgsx = ls_relstrat-strategie.
        ENDLOOP.
        COMMIT WORK.
      CATCH cx_sy_zerodivide INTO oerror.
        ROLLBACK WORK.
        lv_txterror_long = oerror->get_longtext( ).
        MESSAGE lv_txterror_long TYPE 'I'.
    ENDTRY.



    LOOP AT lt_relstrat INTO ls_relstrat.
      " Add dataset to lt_t16fs from excel file
      ls_t16fs-mandt = sy-mandt.
      ls_t16fs-frggr = ls_relstrat-gruppe.
      ls_t16fs-frgsx = ls_relstrat-strategie.
      ls_t16fs-frgc1 = ls_relstrat-code_1.
      ls_t16fs-frgc2 = ls_relstrat-code_2.
      ls_t16fs-frgc3 = ls_relstrat-code_3.
      ls_t16fs-frgc4 = ls_relstrat-code_4.
      ls_t16fs-frgc5 = ls_relstrat-code_5.
      ls_t16fs-frgc6 = ls_relstrat-code_6.
      ls_t16fs-frgc7 = ls_relstrat-code_7.
      ls_t16fs-frgc8 = ls_relstrat-code_8.
      APPEND ls_t16fs TO lt_t16fs.
      CLEAR ls_t16fs.



      " Add dataset to lt_t16ft from excel file
      ls_t16ft-mandt = sy-mandt.
      ls_t16ft-spras = sy-langu.
      ls_t16ft-frggr = ls_relstrat-gruppe.
      ls_t16ft-frgsx = ls_relstrat-strategie.
      ls_t16ft-frgxt = ls_relstrat-bezeichnung.
      APPEND ls_t16ft TO lt_t16ft.
      CLEAR ls_t16ft.



      " Add dataset to lt_t16fk from excel file
      IF ls_relstrat-code_1 IS NOT INITIAL.
        ls_t16fk-mandt = sy-mandt.
        ls_t16fk-frggr = ls_relstrat-gruppe.
        ls_t16fk-frgsx = ls_relstrat-strategie.
        ls_t16fk-frgkx = 'G'.
        APPEND ls_t16fk TO lt_t16fk.
        CLEAR ls_t16fk.
        ls_t16fk-mandt = sy-mandt.
        ls_t16fk-frggr = ls_relstrat-gruppe.
        ls_t16fk-frgsx = ls_relstrat-strategie.
        ls_t16fk-frga1 = 'X'.
        IF ls_relstrat-code_2 IS NOT INITIAL.
          ls_t16fk-frgkx = 'G'.
        ELSE.
          ls_t16fk-frgkx = 'F'.
        ENDIF.
        APPEND ls_t16fk TO lt_t16fk.
        CLEAR ls_t16fk.
      ENDIF.



      IF ls_relstrat-code_2 IS NOT INITIAL.
        ls_t16fk-mandt = sy-mandt.
        ls_t16fk-frggr = ls_relstrat-gruppe.
        ls_t16fk-frgsx = ls_relstrat-strategie.
        ls_t16fk-frga1 = 'X'.
        ls_t16fk-frga2 = 'X'.
        IF ls_relstrat-code_3 IS NOT INITIAL.
          ls_t16fk-frgkx = 'G'.
        ELSE.
          ls_t16fk-frgkx = 'F'.
        ENDIF.
        APPEND ls_t16fk TO lt_t16fk.
        CLEAR ls_t16fk.
      ENDIF.

      IF ls_relstrat-code_3 IS NOT INITIAL.
        ls_t16fk-mandt = sy-mandt.
        ls_t16fk-frggr = ls_relstrat-gruppe.
        ls_t16fk-frgsx = ls_relstrat-strategie.
        ls_t16fk-frga1 = 'X'.
        ls_t16fk-frga2 = 'X'.
        ls_t16fk-frga3 = 'X'.
        IF ls_relstrat-code_4 IS NOT INITIAL.
          ls_t16fk-frgkx = 'G'.
        ELSE.
          ls_t16fk-frgkx = 'F'.
        ENDIF.
        APPEND ls_t16fk TO lt_t16fk.
        CLEAR ls_t16fk.
      ENDIF.

      IF ls_relstrat-code_4 IS NOT INITIAL.
        ls_t16fk-mandt = sy-mandt.
        ls_t16fk-frggr = ls_relstrat-gruppe.
        ls_t16fk-frgsx = ls_relstrat-strategie.
        ls_t16fk-frga1 = 'X'.
        ls_t16fk-frga2 = 'X'.
        ls_t16fk-frga3 = 'X'.
        ls_t16fk-frga4 = 'X'.
        IF ls_relstrat-code_5 IS NOT INITIAL.
          ls_t16fk-frgkx = 'G'.
        ELSE.
          ls_t16fk-frgkx = 'F'.
        ENDIF.
        APPEND ls_t16fk TO lt_t16fk.
        CLEAR ls_t16fk.
      ENDIF.

      IF ls_relstrat-code_5 IS NOT INITIAL.
        ls_t16fk-mandt = sy-mandt.
        ls_t16fk-frggr = ls_relstrat-gruppe.
        ls_t16fk-frgsx = ls_relstrat-strategie.
        ls_t16fk-frga1 = 'X'.
        ls_t16fk-frga2 = 'X'.
        ls_t16fk-frga3 = 'X'.
        ls_t16fk-frga4 = 'X'.
        ls_t16fk-frga5 = 'X'.
        IF ls_relstrat-code_6 IS NOT INITIAL.
          ls_t16fk-frgkx = 'G'.
        ELSE.
          ls_t16fk-frgkx = 'F'.
        ENDIF.
        APPEND ls_t16fk TO lt_t16fk.
        CLEAR ls_t16fk.
      ENDIF.


      IF ls_relstrat-code_6 IS NOT INITIAL.
        ls_t16fk-mandt = sy-mandt.
        ls_t16fk-frggr = ls_relstrat-gruppe.
        ls_t16fk-frgsx = ls_relstrat-strategie.
        ls_t16fk-frga1 = 'X'.
        ls_t16fk-frga2 = 'X'.
        ls_t16fk-frga3 = 'X'.
        ls_t16fk-frga4 = 'X'.
        ls_t16fk-frga5 = 'X'.
        ls_t16fk-frga6 = 'X'.
        IF ls_relstrat-code_7 IS NOT INITIAL.
          ls_t16fk-frgkx = 'G'.
        ELSE.
          ls_t16fk-frgkx = 'F'.
        ENDIF.
        APPEND ls_t16fk TO lt_t16fk.
        CLEAR ls_t16fk.
      ENDIF.

      IF ls_relstrat-code_7 IS NOT INITIAL.
        ls_t16fk-mandt = sy-mandt.
        ls_t16fk-frggr = ls_relstrat-gruppe.
        ls_t16fk-frgsx = ls_relstrat-strategie.
        ls_t16fk-frga1 = 'X'.
        ls_t16fk-frga2 = 'X'.
        ls_t16fk-frga3 = 'X'.
        ls_t16fk-frga4 = 'X'.
        ls_t16fk-frga5 = 'X'.
        ls_t16fk-frga6 = 'X'.
        ls_t16fk-frga7 = 'X'.

        IF ls_relstrat-code_8 IS NOT INITIAL.
          ls_t16fk-frgkx = 'G'.
        ELSE.
          ls_t16fk-frgkx = 'F'.
        ENDIF.
        APPEND ls_t16fk TO lt_t16fk.
        CLEAR ls_t16fk.
      ENDIF.


      IF ls_relstrat-code_8 IS NOT INITIAL.
        ls_t16fk-mandt = sy-mandt.
        ls_t16fk-frggr = ls_relstrat-gruppe.
        ls_t16fk-frgsx = ls_relstrat-strategie.
        ls_t16fk-frga1 = 'X'.
        ls_t16fk-frga2 = 'X'.
        ls_t16fk-frga3 = 'X'.
        ls_t16fk-frga4 = 'X'.
        ls_t16fk-frga5 = 'X'.
        ls_t16fk-frga6 = 'X'.
        ls_t16fk-frga7 = 'X'.
        ls_t16fk-frga8 = 'X'.
        ls_t16fk-frgkx = 'F'.
        APPEND ls_t16fk TO lt_t16fk.
        CLEAR ls_t16fk.
      ENDIF.



      " Add dataset to dataset to lt_t16fv from excel file
      IF ls_relstrat-code_1 IS NOT INITIAL.
        ls_t16fv-mandt = sy-mandt.
        ls_t16fv-frggr = ls_relstrat-gruppe.
        ls_t16fv-frgsx = ls_relstrat-strategie.
        ls_t16fv-frgco = ls_relstrat-code_1.
        ls_t16fv-frga1 = 'X'.
        APPEND ls_t16fv TO lt_t16fv.
        CLEAR ls_t16fv.
      ENDIF.


      IF ls_relstrat-code_2 IS NOT INITIAL.
        ls_t16fv-mandt = sy-mandt.
        ls_t16fv-frggr = ls_relstrat-gruppe.
        ls_t16fv-frgsx = ls_relstrat-strategie.
        ls_t16fv-frgco = ls_relstrat-code_2.
        ls_t16fv-frga1 = '+'.
        ls_t16fv-frga2 = 'X'.
        APPEND ls_t16fv TO lt_t16fv.
        CLEAR ls_t16fv.
      ENDIF.



      IF ls_relstrat-code_3 IS NOT INITIAL.
        ls_t16fv-mandt = sy-mandt.
        ls_t16fv-frggr = ls_relstrat-gruppe.
        ls_t16fv-frgsx = ls_relstrat-strategie.
        ls_t16fv-frgco = ls_relstrat-code_3.
        ls_t16fv-frga1 = '+'.
        ls_t16fv-frga2 = '+'.
        ls_t16fv-frga3 = 'X'.
        APPEND ls_t16fv TO lt_t16fv.
        CLEAR ls_t16fv.
      ENDIF.



      IF ls_relstrat-code_4 IS NOT INITIAL.
        ls_t16fv-mandt = sy-mandt.
        ls_t16fv-frggr = ls_relstrat-gruppe.
        ls_t16fv-frgsx = ls_relstrat-strategie.
        ls_t16fv-frgco = ls_relstrat-code_4.
        ls_t16fv-frga1 = '+'.
        ls_t16fv-frga2 = '+'.
        ls_t16fv-frga3 = '+'.
        ls_t16fv-frga4 = 'X'.
        APPEND ls_t16fv TO lt_t16fv.
        CLEAR ls_t16fv.
      ENDIF.



      IF ls_relstrat-code_5 IS NOT INITIAL.
        ls_t16fv-mandt = sy-mandt.
        ls_t16fv-frggr = ls_relstrat-gruppe.
        ls_t16fv-frgsx = ls_relstrat-strategie.
        ls_t16fv-frgco = ls_relstrat-code_5.
        ls_t16fv-frga1 = '+'.
        ls_t16fv-frga2 = '+'.
        ls_t16fv-frga3 = '+'.
        ls_t16fv-frga4 = '+'.
        ls_t16fv-frga5 = 'X'.
        APPEND ls_t16fv TO lt_t16fv.
        CLEAR ls_t16fv.
      ENDIF.



      IF ls_relstrat-code_6 IS NOT INITIAL.
        ls_t16fv-mandt = sy-mandt.
        ls_t16fv-frggr = ls_relstrat-gruppe.
        ls_t16fv-frgsx = ls_relstrat-strategie.
        ls_t16fv-frgco = ls_relstrat-code_6.
        ls_t16fv-frga1 = '+'.
        ls_t16fv-frga2 = '+'.
        ls_t16fv-frga3 = '+'.
        ls_t16fv-frga4 = '+'.
        ls_t16fv-frga5 = '+'.
        ls_t16fv-frga6 = 'X'.
        APPEND ls_t16fv TO lt_t16fv.
        CLEAR ls_t16fv.
      ENDIF.



      IF ls_relstrat-code_7 IS NOT INITIAL.
        ls_t16fv-mandt = sy-mandt.
        ls_t16fv-frggr = ls_relstrat-gruppe.
        ls_t16fv-frgsx = ls_relstrat-strategie.
        ls_t16fv-frgco = ls_relstrat-code_7.
        ls_t16fv-frga1 = '+'.
        ls_t16fv-frga2 = '+'.
        ls_t16fv-frga3 = '+'.
        ls_t16fv-frga4 = '+'.
        ls_t16fv-frga5 = '+'.
        ls_t16fv-frga6 = '+'.
        ls_t16fv-frga7 = 'X'.
        APPEND ls_t16fv TO lt_t16fv.
        CLEAR ls_t16fv.
      ENDIF.



      IF ls_relstrat-code_8 IS NOT INITIAL.
        ls_t16fv-mandt = sy-mandt.
        ls_t16fv-frggr = ls_relstrat-gruppe.
        ls_t16fv-frgsx = ls_relstrat-strategie.
        ls_t16fv-frgco = ls_relstrat-code_8.
        ls_t16fv-frga1 = '+'.
        ls_t16fv-frga2 = '+'.
        ls_t16fv-frga3 = '+'.
        ls_t16fv-frga4 = '+'.
        ls_t16fv-frga5 = '+'.
        ls_t16fv-frga6 = '+'.
        ls_t16fv-frga7 = '+'.
        ls_t16fv-frga8 = 'X'.
        APPEND ls_t16fv TO lt_t16fv.
        CLEAR ls_t16fv.
      ENDIF.

    ENDLOOP.

    TRY.


        INSERT t16fv FROM TABLE lt_t16fv.
        INSERT t16ft FROM TABLE lt_t16ft.
        INSERT t16fk FROM TABLE lt_t16fk.
        INSERT t16fs FROM TABLE lt_t16fs.
        COMMIT WORK.
        DESCRIBE TABLE lt_relstrat LINES lv_nr.
        IF lv_nr = 1.
          lv_txterror_long = 'Ein Datensatz wurde aus der Excel-Datei in Freigabestrategien übernommen'.
        ELSE.
          lv_txterror_long = lv_nr && ' Datensätze wurden aus Excel-Datei in Freigabestrategien übernommen'.
        ENDIF.
        MESSAGE lv_txterror_long TYPE 'I'.

      CATCH cx_sy_zerodivide INTO oerror.

        ROLLBACK WORK.
        lv_txterror_long = oerror->get_longtext( ).
        MESSAGE lv_txterror_long TYPE 'I'.

    ENDTRY.


  ENDIF.

But it appears a display problem. When I click on the "Release Statuses" button, the indicator within the release strategy drift from datasets of T16FK table .

When I log out form SAP and logon again, than disappear the display problem. The display problem is also resolved, when I logon without ending any other logons (see Figure below).

How can I solve the cache problem? Is there some OSS?

Kind regard

Emal

Attachments