This code copies variants from one program to another provided that the programs have identical selection screens.

* ------------------------------------------------------
* Copy Variants from one Program to another.
* ------------------------------------------------------
REPORT Z_COPY_VARIANTS_PROG_TO_PROG .

* =====================================================
* Data Declarations Section
* =====================================================
TABLES : VARID , VARIS , VARIT  .
* -----------------------------------------------------
DATA : BEGIN OF MYVARID OCCURS 0 .
        INCLUDE STRUCTURE VARID .
DATA : END OF MYVARID .
* -----------------------------------------------------
DATA : BEGIN OF MYVARIS OCCURS 0 .
        INCLUDE STRUCTURE VARIS .
DATA : END OF MYVARIS .
* -----------------------------------------------------
DATA : BEGIN OF MYVARIT OCCURS 0 .
        INCLUDE STRUCTURE VARIT .
DATA : END OF MYVARIT .
* -----------------------------------------------------
DATA : BEGIN OF MYVARI  OCCURS 0 .
        INCLUDE STRUCTURE VARI  .
DATA : END OF MYVARI .

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_D  LIKE   RLGRAP-FILENAME DEFAULT 'c:\varid.txt' .
PARAMETERS : P_FILE_S  LIKE   RLGRAP-FILENAME DEFAULT 'c:\varis.txt' .
PARAMETERS : P_FILE_T  LIKE   RLGRAP-FILENAME DEFAULT 'c:\varit.txt' .
PARAMETERS : P_FILE    LIKE   RLGRAP-FILENAME DEFAULT 'c:\vari.txt' .

* =====================================================
* At Selection Screen Events
* =====================================================
AT SELECTION-SCREEN .
  PROGRAMM = P_FROM_P .

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE_D .
  GET_FILENAME 'c:\varid.txt' P_FILE_D .

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE_S .
  GET_FILENAME 'c:\varis.txt' P_FILE_S .

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE_T .
  GET_FILENAME 'c:\varit.txt' P_FILE_T .

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE .
  GET_FILENAME 'c:\vari.txt' P_FILE .

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 MYVARID . CLEAR MYVARID .
    SELECT * FROM VARID  INTO TABLE MYVARID
                        WHERE REPORT = P_FROM_P.
    LOOP AT MYVARID .
      MYVARID-REPORT = P_TO_P .
      MODIFY MYVARID .
    ENDLOOP .
    IF SY-SUBRC = 0 .
      DELETE FROM VARID WHERE REPORT = P_TO_P .
      INSERT VARID FROM TABLE MYVARID .
    ENDIF .
* ----------------------------------------------------
    REFRESH MYVARIS . CLEAR MYVARIS .
    SELECT * FROM VARIS  INTO TABLE MYVARIS
                        WHERE REPORT = P_FROM_P.
    LOOP AT MYVARIS .
      MYVARIS-REPORT = P_TO_P .
      MODIFY MYVARIS .
    ENDLOOP .
    IF SY-SUBRC = 0 .
      DELETE FROM VARIS WHERE REPORT = P_TO_P .
      INSERT VARIS FROM TABLE MYVARIS .
    ENDIF .
* -----------------------------------------------------
    REFRESH MYVARIT . CLEAR MYVARIT .
    SELECT * FROM VARIT  INTO TABLE MYVARIT
                        WHERE REPORT = P_FROM_P.
    LOOP AT MYVARIT .
      MYVARIT-REPORT = P_TO_P .
      MODIFY MYVARIT .
    ENDLOOP .
    IF SY-SUBRC = 0 .
      DELETE FROM VARIT WHERE REPORT = P_TO_P .
      INSERT VARIT FROM TABLE MYVARIT .
    ENDIF .
* -----------------------------------------------------
    REFRESH MYVARI . CLEAR MYVARI .
    SELECT * FROM VARI   INTO TABLE MYVARI
                        WHERE REPORT = P_FROM_P.
    LOOP AT MYVARI  .
      MYVARI-REPORT = P_TO_P .
      MODIFY MYVARI  .
    ENDLOOP .
    IF SY-SUBRC = 0 .
      DELETE FROM VARI WHERE REPORT = P_TO_P .
      INSERT VARI FROM TABLE MYVARI .
    ENDIF .

  ENDIF .

ENDFORM.                               " COPY_FROM_PROG_TO_PROG

*&-----------------------------------------------------*
*&      Form  VDOWNLOAD
*&-----------------------------------------------------*
*       text
*------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*------------------------------------------------------*
FORM VDOWNLOAD.
  REFRESH MYVARID . CLEAR MYVARID .
  SELECT * FROM VARID  INTO TABLE MYVARID
                      WHERE REPORT = P_FROM_P.
  DOWNLOAD_TO_ASCII  P_FILE_D  MYVARID .

* -----------------------------------------------------
  REFRESH MYVARIS . CLEAR MYVARIS .
  SELECT * FROM VARIS  INTO TABLE MYVARIS
                      WHERE REPORT = P_FROM_P.
  DOWNLOAD_TO_ASCII P_FILE_S  MYVARIS .

* -----------------------------------------------------
  REFRESH MYVARIT . CLEAR MYVARIT .
  SELECT * FROM VARIT  INTO TABLE MYVARIT
                      WHERE REPORT = P_FROM_P.
  DOWNLOAD_TO_ASCII P_FILE_T  MYVARIT .

* ----------------------------------------------------
  REFRESH MYVARI . CLEAR MYVARI .
  SELECT * FROM VARI   INTO TABLE MYVARI
                      WHERE REPORT = P_FROM_P.
  DOWNLOAD_TO_ASCII P_FILE  MYVARI .

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 MYVARID . CLEAR MYVARID .
    UPLOAD_FROM_ASCII P_FILE_D MYVARID .
    LOOP AT MYVARID .
      MYVARID-REPORT = P_TO_P .
      MODIFY MYVARID .
    ENDLOOP .
    IF SY-SUBRC = 0 .
      DELETE FROM VARID WHERE REPORT = P_TO_P .
      INSERT VARID FROM TABLE MYVARID .
    ENDIF .
* -----------------------------------------------------
    REFRESH MYVARIS . CLEAR MYVARIS .
    UPLOAD_FROM_ASCII P_FILE_S MYVARIS  .
    LOOP AT MYVARIS .
      MYVARIS-REPORT = P_TO_P .
      MODIFY MYVARIS .
    ENDLOOP .
    IF SY-SUBRC = 0 .
      DELETE FROM VARIS WHERE REPORT = P_TO_P .
      INSERT VARIS FROM TABLE MYVARIS .
    ENDIF .
* -----------------------------------------------------
    REFRESH MYVARIT . CLEAR MYVARIT .
    UPLOAD_FROM_ASCII P_FILE_T MYVARIT  .
    LOOP AT MYVARIT .
      MYVARIT-REPORT = P_TO_P .
      MODIFY MYVARIT .
    ENDLOOP .
    IF SY-SUBRC = 0 .
      DELETE FROM VARIT WHERE REPORT = P_TO_P .
      INSERT VARIT FROM TABLE MYVARIT .
    ENDIF .
* ------------------------------------------------------
    REFRESH MYVARI . CLEAR MYVARI .
    UPLOAD_FROM_ASCII P_FILE  MYVARI   .
    LOOP AT MYVARI  .
      MYVARI-REPORT = P_TO_P .
      MODIFY MYVARI  .
    ENDLOOP .
    IF SY-SUBRC = 0 .
      DELETE FROM VARI WHERE REPORT = P_TO_P .
      INSERT VARI FROM TABLE MYVARI .
    ENDIF .

  ENDIF .

ENDFORM.                               " VUPLOAD
 
 
 
Serkan AKKAVAK
Computer Engineer
SAP Department Deputy Manager
Contact : serkurumsal@yandex.com