Google Search - Blog...........

ABAP - Downloading Programs Into A Folder In Presentation Server.

This program helps to download a given set of the programs into a folder specified on selection-screen. It also lists the programs that are downloaded/not downloaded from the given set.
Note : This program can download only the programs whose source code line length is less than 72 characters.
REPORT Z_13317_DWLD
LINE-SIZE 80
LINE-COUNT 64
MESSAGE-ID ZZ
NO STANDARD PAGE HEADING.
*----------------------------------------------------------------------*
* Tables *
*----------------------------------------------------------------------*
TABLES : TADIR.
*----------------------------------------------------------------------*
* Types *
*----------------------------------------------------------------------*
TYPES: BEGIN OF T_TYPE,
LINE(72),
END OF T_TYPE,
BEGIN OF T_PROG,
OBJ_NAME TYPE TADIR-OBJ_NAME,
END OF T_PROG.
*----------------------------------------------------------------------*
* Internal Tables *
*----------------------------------------------------------------------*
**--Internal table to hold code
DATA: IT_CODE TYPE TABLE OF T_TYPE,
WA_CODE TYPE T_TYPE,
**--Internal table to hold the program names
IT_OBJ TYPE TABLE OF T_TYPE,
WA_OBJ TYPE T_TYPE,
**--Internal table to hold the program that are not downloaded
IT_PROG TYPE TABLE OF T_PROG,
WA_PROG TYPE T_PROG,
**--Internal table to hold the program that are downloaded
IT_DWLD TYPE TABLE OF T_PROG,
WA_DWLD TYPE T_PROG.
*----------------------------------------------------------------------*
* Field Symbols *
*----------------------------------------------------------------------*
FIELD-SYMBOLS :.
*----------------------------------------------------------------------*
* Constants *
*----------------------------------------------------------------------*
CONSTANTS : GC_EXT(4) TYPE C VALUE '.txt', "File Extension
GC_SEP TYPE C VALUE '\', "Separator
GC_PROG TYPE TADIR-OBJECT VALUE 'PROG'. "Object Type
*----------------------------------------------------------------------*
* Selection Screen *
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME.
SELECT-OPTIONS : S_OBJ FOR TADIR-OBJ_NAME. "Object Name
PARAMETERS : P_PATH(200) VISIBLE LENGTH 10 OBLIGATORY. "Folder Path
SELECTION-SCREEN END OF BLOCK B1.
*----------------------------------------------------------------------*
* At selection-screen *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
**--Validate Path
PERFORM VALIDATE_PATH.
*----------------------------------------------------------------------*
* Start Of Selection *
*----------------------------------------------------------------------*
START-OF-SELECTION.
**--Get Program Names
PERFORM FETCH_PROG_NAMES.
**--Process Program Names Internal table
PERFORM PROCESS_ITAB.
*----------------------------------------------------------------------*
* End Of Selection *
*----------------------------------------------------------------------*
END-OF-SELECTION.
**--Display the list of programs that are not downloaded
PERFORM DISPLAY_ITAB.
*&---------------------------------------------------------------------*
*& Form FETCH_PROG_NAMES
*&---------------------------------------------------------------------*
* Get Program Names
*----------------------------------------------------------------------*
FORM FETCH_PROG_NAMES .
**--Get program names
CLEAR : IT_OBJ[].
SELECT OBJ_NAME
FROM TADIR
INTO TABLE IT_OBJ
WHERE OBJECT EQ GC_PROG
AND OBJ_NAME IN S_OBJ.
IF SY-SUBRC NE 0.
MESSAGE I000(ZZ) WITH 'No programs found'(001).
ENDIF.
ENDFORM. " FETCH_PROG_NAMES
*&---------------------------------------------------------------------*
*& Form PROCESS_ITAB
*&---------------------------------------------------------------------*
* Prepare programs to download
*----------------------------------------------------------------------*
FORM PROCESS_ITAB .
DATA: LV_FILENAME TYPE STRING.
LOOP AT IT_OBJ INTO WA_OBJ.
CLEAR : IT_CODE[].
ASSIGN WA_OBJ-LINE TO .
LV_FILENAME = WA_OBJ-LINE.
TRY.
**--Get the code of the program into internal table
READ REPORT INTO IT_CODE.
IF SY-SUBRC = 0.
CONCATENATE P_PATH GC_SEP LV_FILENAME GC_EXT INTO LV_FILENAME.
CONDENSE LV_FILENAME NO-GAPS.
**--Download code to given path
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = LV_FILENAME
FILETYPE = 'ASC'
TABLES
DATA_TAB = IT_CODE
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22.
IF SY-SUBRC <> 0.
**--Unable to download program
WA_PROG-OBJ_NAME = WA_OBJ-LINE.
APPEND WA_PROG TO IT_PROG.
CLEAR WA_PROG.
ELSE.
WA_DWLD-OBJ_NAME = WA_OBJ-LINE.
APPEND WA_DWLD TO IT_DWLD.
CLEAR WA_DWLD.
ENDIF.
ENDIF.
CATCH CX_SY_READ_SRC_LINE_TOO_LONG.
**--Unable to download program as line length > 72
WA_PROG-OBJ_NAME = WA_OBJ-LINE.
APPEND WA_PROG TO IT_PROG.
CLEAR WA_PROG.
ENDTRY.
ENDLOOP.
ENDFORM. " PROCESS_ITAB
*&---------------------------------------------------------------------*
*& Form VALIDATE_PATH
*&---------------------------------------------------------------------*
* Validate Directory Path
*----------------------------------------------------------------------*
FORM VALIDATE_PATH .
DATA: LV_EXIST TYPE C,
LV_ISDIR TYPE C.
CALL FUNCTION 'TMP_GUI_GET_FILE_EXIST'
EXPORTING
FNAME = P_PATH
IMPORTING
EXIST = LV_EXIST
ISDIR = LV_ISDIR
EXCEPTIONS
FILEINFO_ERROR = 1
OTHERS = 2.
IF SY-SUBRC NE 0 OR LV_EXIST IS INITIAL.
**--Directory does not exist
SET CURSOR FIELD 'P_PATH'.
MESSAGE E000(ZZ) WITH 'Invalid Directory Path'(002).
ELSE.
IF LV_ISDIR IS INITIAL.
**--Given Path is not a directory
SET CURSOR FIELD 'P_PATH'.
MESSAGE E000(ZZ) WITH 'Input Directory Path'(003).
ENDIF.
ENDIF.
ENDFORM. " VALIDATE_PATH
*&---------------------------------------------------------------------*
*& Form DISPLAY_ITAB
*&---------------------------------------------------------------------*
* Display Programs
*----------------------------------------------------------------------*
FORM DISPLAY_ITAB .
LOOP AT IT_DWLD INTO WA_DWLD.
AT FIRST.
WRITE :/ 'List of programs that are downloaded'(006)
COLOR COL_HEADING.
ENDAT.
WRITE :/4 WA_DWLD-OBJ_NAME.
ENDLOOP.
SKIP 2.
LOOP AT IT_PROG INTO WA_PROG.
AT FIRST.
WRITE:/ 'List of programs that are not downloaded'(005)
COLOR COL_HEADING.
ENDAT.
WRITE :/4 WA_PROG-OBJ_NAME.
ENDLOOP.
ENDFORM. " DISPLAY_ITAB



ALSO READ:

- Download SAP Data In XML Format.

- Download SAPScript Output To PDF File.

- Download Data From Application Server Files To Presentation Server Using FM C13Z_APPL_TO_FRONT_END.

- Creating A Directory On Presentation Server Using FM GUI_CREATE_DIRECTORY.

- Removing A Directory From Presentation Server Using FM GUI_REMOVE_DIRECTORY.



RETURN TO MAIN INDEX:

- Sample Programs On Uploading & Downloading Files.

- Sample Programs On HR ABAP.

- Sample Report Programs On ALV List/ Grid Display.

- Sample Programs On Selection Screen.

- Sample Programs On BDC.

.....Back To MAIN INDEX.


No comments:

Post a Comment