Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Need ABAP program.

Former Member
0 Kudos

Hi All,


I need a program for below scenario, Can any body please help me on this.


Develop the program by following below steps (create two programs for Presentation and Application Servers):

    1. a.       Selection screen should consists “Source Directory”, “Destination Directory” paths (Parameters)
    2. b.      Read all the files from “Source Directory” and rename them with “*_Copy.XXX”, and place in Target Folder.

Thanks,

Bhaskar.

2 REPLIES 2

Laszlo_B
Active Contributor
0 Kudos

Hello Bhaskar,

if you need assistance in the writing of an ABAP program, you can post the question in Space http://scn.sap.com/community/abap.

This is the Download Space for SAP programs, while http://scn.sap.com/community/abap handles ABAP-development related questions.

Best regards,

Laszlo

former_member183519
Contributor
0 Kudos

Hello Bhaskar,

PFA Below code...I have done this as per your requirement

***************************************************************************************************

*************************************  Code Starts *********************************************

REPORT  ZZTEST_PROGRAM.

SELECTION-SCREEN BEGIN OF SCREEN 200 AS WINDOW.

PARAMETER: p_file TYPE pfeflnamel DEFAULT '/usr/sap/tmp',

            d_file TYPE pfeflnamel DEFAULT '/tmp'.

DATA:l_serfil TYPE sapb-sappfad.

SELECTION-SCREEN END OF SCREEN 200.

DATA: it_files_in_dir  TYPE salfldir OCCURS 0 WITH HEADER LINE.

FIELD-SYMBOLS : <FS_it_files> TYPE salfldir.

DATA : LD_TGT_FILE TYPE STRING,

        LD_SRC_FILE TYPE STRING.

DATA: LV_STR TYPE STRING.

CALL SELECTION-SCREEN '0200' STARTING AT 10 10.

" Get Current Directory Listing for OUT Dir

   CALL FUNCTION 'RZL_READ_DIR_LOCAL'

     EXPORTING

       name     = p_file

     TABLES

       file_tbl = it_files_in_dir.

DATA : lv_codepage TYPE CPCODEPAGE.

CALL FUNCTION 'NLS_GET_FRONTEND_CP'

     EXPORTING

       langu                 = sy-langu

       fetype                = 'MS'

     IMPORTING

       frontend_codepage     = lv_codepage

     EXCEPTIONS

       illegal_syst_codepage = 1

       no_frontend_cp_found  = 2

       internal_or_db_error  = 3

       OTHERS                = 4.

LOOP AT it_files_in_dir ASSIGNING <FS_it_files> FROM 3 .

  CONCATENATE p_file '/' <FS_it_files>-name INTO l_serfil.

   LD_SRC_FILE = l_serfil.

  CONCATENATE d_file '/' <FS_it_files>-name '_COPY.XXX' INTO LD_TGT_FILE.

  PERFORM COPY_FILE_IN_APP_SERVER USING LD_SRC_FILE

                                       LD_TGT_FILE.

ENDLOOP.

   FORM COPY_FILE_IN_APP_SERVER USING LV_SRC_FILE TYPE STRING

                                      LV_TGT_FILE TYPE STRING.

    " OPEN DATASET FILE FROM SERVER FOR READING

    OPEN DATASET LV_SRC_FILE FOR INPUT IN LEGACY TEXT MODE CODE PAGE lv_codepage.

    IF SY-SUBRC = 0.

       OPEN DATASET LV_TGT_FILE FOR OUTPUT IN LEGACY TEXT MODE CODE PAGE lv_codepage.

          DO.

            READ DATASET LV_SRC_FILE INTO LV_STR.

              IF SY-SUBRC = 0.

                 TRANSFER LV_STR TO LV_TGT_FILE.

                 CLEAR LV_STR.

              ELSE.

                 EXIT.

              ENDIF.

          ENDDO.

    ENDIF.

     CLOSE DATASET LV_SRC_FILE.

     CLOSE DATASET LV_TGT_FILE.

   ENDFORM


***************************************************************************************************

*************************************  Code Ends *********************************************

Copy n paste above code.

On program execution :-

Enter Your Source Directory ---> P_FILE

Enter  Your Destin. Directory ---> D_FILE

This will read all the files from “Source Directory” and rename them it with “*_Copy.XXX”, and place in Target Folder.  

Regards,

Hitesh Gavande