SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Copy ALV Variants from one Program to another.



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ALV Grid / ALV Tree / ALV List
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Mon Feb 16, 2009 12:28 pm    Post subject: Copy ALV Variants from one Program to another. Reply with quote

Source from: http: /www.sapfans.com/forums/viewtopic.php?t=251328

Code:
* --------------------------------------------------------------------
* Copy ALV Variants from one Program to another.
* --------------------------------------------------------------------
REPORT z_copy_alv_varnts_prog_to_prog .

* =====================================================================
* Data Declarations Section
* =====================================================================

* ---------------------------------------------------------------------
DATA : BEGIN OF myltdx OCCURS 0 .
        INCLUDE STRUCTURE ltdx .
DATA : END OF myltdx .
* ---------------------------------------------------------------------
DATA : BEGIN OF myltdxt OCCURS 0 .
        INCLUDE STRUCTURE ltdxt .
DATA : END OF myltdxt .
* ---------------------------------------------------------------------
DATA : BEGIN OF myltdxd OCCURS 0 .
        INCLUDE STRUCTURE ltdxd .
DATA : END OF myltdxd .
* ---------------------------------------------------------------------

DATA : mans(1) TYPE c .

DATA : programm LIKE rs38m-programm .
DATA : BEGIN OF mdynpfields OCCURS 1 .
        INCLUDE STRUCTURE dynpread .
DATA : END OF mdynpfields .
CONSTANTS buttonselected(1) TYPE c VALUE 'X' .

* =====================================================================
* Macro for Inputing Filenames
* =====================================================================
DEFINE get_filename .
  call function 'WS_FILENAME_GET'
  exporting
* DEF_FILENAME = ' '
  def_path = &1
  mask = ',*.*,*.*.'
  mode = '0'
* TITLE = ' '
  importing
  filename = &2
* RC =
  exceptions
  inv_winsys = 1
  no_batch = 2
  selection_cancel = 3
  selection_error = 4
  others = 5.

END-OF-DEFINITION .

* =====================================================================
* Macro for Downloading to ASCII Files
* =====================================================================
DEFINE download_to_ascii .
  call function 'WS_DOWNLOAD'
  exporting
* BIN_FILESIZE = ' '
* CODEPAGE = ' '
  filename = &1
  filetype = 'DAT'
* MODE = ' '
* WK1_N_FORMAT = ' '
* WK1_N_SIZE = ' '
* WK1_T_FORMAT = ' '
* WK1_T_SIZE = ' '
* COL_SELECT = ' '
* COL_SELECTMASK = ' '
* NO_AUTH_CHECK = ' '
* IMPORTING
* FILELENGTH =
  tables
  data_tab = &2
* FIELDNAMES =
  exceptions
  file_open_error = 1
  file_write_error = 2
  invalid_filesize = 3
  invalid_table_width = 4
  invalid_type = 5
  no_batch = 6
  unknown_error = 7
  gui_refuse_filetransfer = 8
  others = 9.

END-OF-DEFINITION .

* =====================================================================
* Macro for uploading Data from ASCII files
* =====================================================================
DEFINE upload_from_ascii .
  call function 'WS_UPLOAD'
  exporting
* CODEPAGE = ' '
  filename = &1
  filetype = 'DAT'
* HEADLEN = ' '
* LINE_EXIT = ' '
* TRUNCLEN = ' '
* USER_FORM = ' '
* USER_PROG = ' '
* IMPORTING
* FILELENGTH =
  tables
  data_tab = &2
  exceptions
  conversion_error = 1
  file_open_error = 2
  file_read_error = 3
  invalid_table_width = 4
  invalid_type = 5
  no_batch = 6
  unknown_error = 7
  gui_refuse_filetransfer = 8
  customer_error = 9
  others = 10.
END-OF-DEFINITION .

* =====================================================================
* Selection Screen Default
* =====================================================================
PARAMETERS : p_from_p LIKE rs38m-programm OBLIGATORY .
PARAMETERS : p_to_p LIKE rs38m-programm OBLIGATORY .
PARAMETERS : p_same_s RADIOBUTTON GROUP grp1 DEFAULT 'X' .
PARAMETERS : p_downld RADIOBUTTON GROUP grp1 .
PARAMETERS : p_upload RADIOBUTTON GROUP grp1 .
PARAMETERS : p_file_x LIKE rlgrap-filename DEFAULT 'c:\LTDX.txt' .
PARAMETERS : p_file_t LIKE rlgrap-filename DEFAULT 'c:\LTDXT.txt' .
PARAMETERS : p_file_d LIKE rlgrap-filename DEFAULT 'c:\LTDXD.txt' .

* =====================================================================
* At Selection Screen Events
* =====================================================================
AT SELECTION-SCREEN .
  programm = p_from_p .

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file_x .
  get_filename 'c:\LTDX.txt' p_file_x .

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file_t .
  get_filename 'c:\LTDXT.txt' p_file_t .

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file_d .
  get_filename 'c:\LTDXD.txt' p_file_d .

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_from_p .
  CLEAR mdynpfields . REFRESH mdynpfields .
  mdynpfields-fieldname = 'P_FROM_P' .
  APPEND mdynpfields .
  CALL FUNCTION 'DYNP_VALUES_READ'
       EXPORTING
            dyname               = sy-cprog
            dynumb               = sy-dynnr
       TABLES
            dynpfields           = mdynpfields
       EXCEPTIONS
            invalid_abapworkarea = 1
            invalid_dynprofield  = 2
            invalid_dynproname   = 3
            invalid_dynpronummer = 4
            invalid_request      = 5
            no_fielddescription  = 6
            invalid_parameter    = 7
            undefind_error       = 8
            double_conversion    = 9
            stepl_not_found      = 10
            OTHERS               = 11.

  READ TABLE mdynpfields INDEX 1 .
  programm = mdynpfields-fieldvalue .
  CALL FUNCTION 'REPOSITORY_INFO_SYSTEM_F4'
       EXPORTING
            object_type          = 'PROG'
            object_name          = programm
       IMPORTING
            object_name_selected = programm
       EXCEPTIONS
            cancel               = 1
            wrong_type           = 2
            OTHERS               = 3.
  p_from_p = programm .

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_to_p .
  CLEAR mdynpfields . REFRESH mdynpfields .
  mdynpfields-fieldname = 'P_TO_P' .
  APPEND mdynpfields .
  CALL FUNCTION 'DYNP_VALUES_READ'
       EXPORTING
            dyname               = sy-cprog
            dynumb               = sy-dynnr
       TABLES
            dynpfields           = mdynpfields
       EXCEPTIONS
            invalid_abapworkarea = 1
            invalid_dynprofield  = 2
            invalid_dynproname   = 3
            invalid_dynpronummer = 4
            invalid_request      = 5
            no_fielddescription  = 6
            invalid_parameter    = 7
            undefind_error       = 8
            double_conversion    = 9
            stepl_not_found      = 10
            OTHERS               = 11.

  READ TABLE mdynpfields INDEX 1 .
  programm = mdynpfields-fieldvalue .
  CALL FUNCTION 'REPOSITORY_INFO_SYSTEM_F4'
       EXPORTING
            object_type          = 'PROG'
            object_name          = programm
       IMPORTING
            object_name_selected = programm
       EXCEPTIONS
            cancel               = 1
            wrong_type           = 2
            OTHERS               = 3.
  p_to_p = programm .

* =====================================================================
* Start of Selection
* =====================================================================
START-OF-SELECTION .
  CASE buttonselected.
    WHEN p_same_s .
      PERFORM copy_from_prog_to_prog .
    WHEN p_downld .
      PERFORM vdownload .
    WHEN p_upload .
      PERFORM vupload .
  ENDCASE .

*&---------------------------------------------------------------------*

*& Form COPY_FROM_PROG_TO_PROG
*&---------------------------------------------------------------------*

* text
*----------------------------------------------------------------------*

* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*

FORM copy_from_prog_to_prog.

  CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
  EXPORTING
* DEFAULTOPTION = 'Y'
  textline1 = 'Are you sure you want to copy Variants ? '
* TEXTLINE2 = ' '
  titel = 'Confirmation '
* START_COLUMN = 25
* START_ROW = 6
* CANCEL_DISPLAY = 'X'
  IMPORTING
  answer = mans
  EXCEPTIONS
  OTHERS = 1.

  IF mans = 'J' .
* ---------------------------------------------------------------------
    REFRESH myltdx . CLEAR myltdx .
    SELECT * FROM ltdx INTO TABLE myltdx
    WHERE report = p_from_p.
    LOOP AT myltdx .
      myltdx-report = p_to_p .
      MODIFY myltdx .
    ENDLOOP .
    IF sy-subrc = 0 .
      DELETE FROM ltdx WHERE report = p_to_p .
      INSERT ltdx FROM TABLE myltdx .
    ENDIF .
* ---------------------------------------------------------------------
    REFRESH myltdxt . CLEAR myltdxt .
    SELECT * FROM ltdxt INTO TABLE myltdxt
    WHERE report = p_from_p.
    LOOP AT myltdxt .
      myltdxt-report = p_to_p .
      MODIFY myltdxt .
    ENDLOOP .
    IF sy-subrc = 0 .
      DELETE FROM ltdxt WHERE report = p_to_p .
      INSERT ltdxt FROM TABLE myltdxt .
    ENDIF .
* ---------------------------------------------------------------------
    REFRESH myltdxt . CLEAR myltdxt .
    SELECT * FROM ltdxt INTO TABLE myltdxt
    WHERE report = p_from_p.
    LOOP AT myltdxt .
      myltdxt-report = p_to_p .
      MODIFY myltdxt .
    ENDLOOP .
    IF sy-subrc = 0 .
      DELETE FROM ltdxt WHERE report = p_to_p .
      INSERT ltdxt FROM TABLE myltdxt .
    ENDIF .
* ---------------------------------------------------------------------
  ENDIF .

ENDFORM. " COPY_FROM_PROG_TO_PROG

*&---------------------------------------------------------------------*

*& Form VDOWNLOAD
*&---------------------------------------------------------------------*

* text
*----------------------------------------------------------------------*

* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*

FORM vdownload.
  REFRESH myltdx . CLEAR myltdx .
  SELECT * FROM ltdx INTO TABLE myltdx
  WHERE report = p_from_p.
  download_to_ascii p_file_x myltdx .

* ---------------------------------------------------------------------
  REFRESH myltdxt . CLEAR myltdxt .
  SELECT * FROM ltdxt INTO TABLE myltdxt
  WHERE report = p_from_p.
  download_to_ascii p_file_t myltdxt .

* ---------------------------------------------------------------------
  REFRESH myltdxt . CLEAR myltdxt .
  SELECT * FROM ltdxd INTO TABLE myltdxt
  WHERE report = p_from_p.
  download_to_ascii p_file_d myltdxt .

* ---------------------------------------------------------------------

ENDFORM. " VDOWNLOAD

*&---------------------------------------------------------------------*

*& Form VUPLOAD
*&---------------------------------------------------------------------*

* text
*----------------------------------------------------------------------*

* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*

FORM vupload.
  CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
  EXPORTING
* DEFAULTOPTION = 'Y'
  textline1 =
  'Are you sure you want to upload Variants ? '
* TEXTLINE2 = ' '
  titel = 'Confirmation '
* START_COLUMN = 25
* START_ROW = 6
* CANCEL_DISPLAY = 'X'
  IMPORTING
  answer = mans
  EXCEPTIONS
  OTHERS = 1.

  IF mans = 'J' .
* ---------------------------------------------------------------------
    REFRESH myltdx . CLEAR myltdx .
    upload_from_ascii p_file_x myltdx .
    LOOP AT myltdx .
      myltdx-report = p_to_p .
      MODIFY myltdx .
    ENDLOOP .
    IF sy-subrc = 0 .
      DELETE FROM ltdx WHERE report = p_to_p .
      INSERT ltdx FROM TABLE myltdx .
    ENDIF .
* ---------------------------------------------------------------------
    REFRESH myltdxt . CLEAR myltdxt .
    upload_from_ascii p_file_t myltdxt .
    LOOP AT myltdxt .
      myltdxt-report = p_to_p .
      MODIFY myltdxt .
    ENDLOOP .
    IF sy-subrc = 0 .
      DELETE FROM ltdxt WHERE report = p_to_p .
      INSERT ltdxt FROM TABLE myltdxt .
    ENDIF .
* ---------------------------------------------------------------------
    REFRESH myltdxd . CLEAR myltdxd .
    upload_from_ascii p_file_d myltdxt .
    LOOP AT myltdxt .
      myltdxt-report = p_to_p .
      MODIFY myltdxt .
    ENDLOOP .
    IF sy-subrc = 0 .
      DELETE FROM ltdxt WHERE report = p_to_p .
      INSERT ltdxt FROM TABLE myltdxt .
    ENDIF .
* ---------------------------------------------------------------------
  ENDIF .

ENDFORM. " VUPLOAD
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> ALV Grid / ALV Tree / ALV List All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.