*&---------------------------------------------------------------------**& Report ZZHENGXB_TEST_DOWNLOAD
*& 批量下载程序和表结构
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZZHENGXB_TEST_UPLOAD NO STANDARD PAGE HEADING LINE-SIZE 200 MESSAGE-ID WA.
TABLES:TADIR,TRDIRT,TSTC,DD03L,DD02L,DD04L,DD02T,DD03T,DD04T.
DATA: BEGIN OF YTADIR OCCURS 0.
INCLUDE STRUCTURE TADIR.
INCLUDE STRUCTURE TRDIRT.
DATA: END OF YTADIR.
DATA:PROG(72) TYPE C OCCURS 0 WITH HEADER LINE.
*表结构
DATA:BEGIN OF TAB OCCURS 0.
INCLUDE STRUCTURE DD03L.
DATA:TEXT(40).
DATA:END OF TAB.
DATA:BEGIN OF T1 OCCURS 0,
TABNAME LIKE DD02L-TABNAME,
DDTEXT LIKE DD02T-DDTEXT,
END OF T1.
DATA:BEGIN OF ITAB OCCURS 0,
FIELD(15), "字段
KEY(6), "关键字
ELMENT(15), "字段类型
TYPE(10), "数据类型
LENG(8) , "长度
DECIMALS(8) , "小数
CHK(10), "表检查
CAN(10), "参考表
CFI(10), "参考字段
TEXT(40), "字段描述
END OF ITAB.
DATA: YYNAME(128) TYPE C.
DATA: TT TYPE STRING OCCURS 0 WITH HEADER LINE.
DATA: RN(72).
DATA:FIELDS(40),
LIN TYPE I,
VAL(30),
REP(40).
SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME.
PARAMETERS:DOW AS CHECKBOX. "是否下载
PARAMETERS:P_DIR(50) DEFAULT 'D:'. "下载路径
PARAMETERS:STYPE(6) DEFAULT 'TXT'.
PARAMETERS:R1 RADIOBUTTON GROUP R DEFAULT 'X',
R2 RADIOBUTTON GROUP R.
SELECTION-SCREEN END OF BLOCK BLK1.
SELECTION-SCREEN BEGIN OF BLOCK BLK2 WITH FRAME.
SELECT-OPTIONS:AUTHOR FOR TADIR-AUTHOR DEFAULT 'zhengxb'. "开发人
SELECT-OPTIONS:DEVCLASS FOR TADIR-DEVCLASS. "开发类
SELECT-OPTIONS:OBJ FOR TADIR-OBJ_NAME. "下载程序名称
SELECT-OPTIONS:TABNAME FOR DD02L-TABNAME. "下载表名称
SELECTION-SCREEN END OF BLOCK BLK2.
INITIALIZATION .
START-OF-SELECTION .
IF R1 = 'X'.
PERFORM GET_DATA.
ENDIF.
IF R2 = 'X'.
IF TABNAME IS INITIAL.
MESSAGE I009 WITH '请输入要下载的表名!'.
ELSE.
PERFORM GET_TABLE_DATA.
ENDIF.
ENDIF.
AT LINE-SELECTION.
CLEAR: FIELDS, LIN.
GET CURSOR FIELD FIELDS LINE LIN VALUE VAL.
LIN = LIN - 1.
IF LIN >= 1.
READ TABLE YTADIR INDEX LIN.
IF SY-SUBRC = 0.
CLEAR REP.
CLEAR PROG.
REP = YTADIR-OBJ_NAME.
READ REPORT REP INTO PROG.
EDITOR-CALL FOR PROG.
* SET PARAMETER ID 'RID' FIELD REP.
* CALL TRANSACTION 'SE38' AND SKIP FIRST SCREEN.
ENDIF.
ENDIF.
END-OF-SELECTION.
*---------------------------------------------------------------------*
* FORM GET_DATA *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM GET_DATA.
SELECT * INTO CORRESPONDING FIELDS OF TABLE YTADIR
FROM TADIR
INNER JOIN TRDIRT
ON TADIR~OBJ_NAME = TRDIRT~NAME
WHERE OBJECT = 'PROG'
AND OBJ_NAME IN OBJ
AND DEVCLASS IN DEVCLASS
AND AUTHOR IN AUTHOR.
SORT YTADIR BY OBJ_NAME.
WRITE:/ '开发类','开发人','程序名称','程序标题'.
LOOP AT YTADIR.
IF DOW = 'X'.
REFRESH TT.
RN = YTADIR-OBJ_NAME.
READ REPORT RN INTO TT.
CONCATENATE P_DIR YTADIR-AUTHOR '_' YTADIR-OBJ_NAME
'_' YTADIR-TEXT '.' STYPE
INTO YYNAME.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
FILENAME = YYNAME
FILETYPE = 'ASC'
TABLES
DATA_TAB = TT
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.
IF SY-SUBRC = 0.
WRITE:/1(10) YTADIR-DEVCLASS,
(8) YTADIR-AUTHOR,
(15) YTADIR-OBJ_NAME,
(40) YTADIR-TEXT.
FORMAT COLOR 5.
WRITE: '已下载'.
FORMAT COLOR OFF.
ELSE.
WRITE:/ YTADIR-DEVCLASS,YTADIR-AUTHOR,YTADIR-OBJ_NAME,YTADIR-TEXT.
FORMAT COLOR 4.
WRITE: '无法下载'.
FORMAT COLOR OFF.
ENDIF.
ELSE.
WRITE:/ YTADIR-DEVCLASS,YTADIR-AUTHOR,YTADIR-OBJ_NAME,YTADIR-TEXT.
ENDIF.
ENDLOOP.
ENDFORM. "GET_DATA
*---------------------------------------------------------------------*
* FORM GET_TABLE_DATA *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
FORM GET_TABLE_DATA.
SELECT DISTINCT * INTO CORRESPONDING FIELDS OF TABLE T1
FROM DD02T WHERE TABNAME IN TABNAME
AND DDLANGUAGE EQ '1'.
SELECT * INTO CORRESPONDING FIELDS OF TABLE TAB FROM DD03L AS A
WHERE A~TABNAME IN TABNAME.
SORT TAB BY TABNAME POSITION.
WRITE:/'字段名','关键字','数据元素','数据类型','长度','小数',
'表检查','参考表','参考字段','字段描述'.
ULINE.
LOOP AT T1.
REFRESH ITAB.
CLEAR YYNAME.
IF DOW = 'X'.
ITAB-FIELD = '字段名'.
ITAB-KEY = '关键字'.
ITAB-ELMENT = '数据元素'.
ITAB-TYPE = '数据类型'.
ITAB-LENG = '长度'.
ITAB-DECIMALS = '小数'.
ITAB-TEXT = '字段描述'.
ITAB-CHK = '表检查'.
ITAB-CAN = '参考表'.
ITAB-CFI = '参考字段'.
APPEND ITAB.
CLEAR ITAB.
ENDIF.
CONCATENATE T1-TABNAME '_' T1-DDTEXT '的表结构如下:'
INTO YYNAME.
FORMAT COLOR 3.
WRITE:/ YYNAME.
FORMAT COLOR OFF.
LOOP AT TAB WHERE TABNAME = T1-TABNAME.
ITAB-FIELD = TAB-FIELDNAME.
ITAB-KEY = TAB-KEYFLAG.
ITAB-ELMENT = TAB-ROLLNAME.
ITAB-TYPE = TAB-DATATYPE.
ITAB-LENG = TAB-LENG.
ITAB-CHK = TAB-CHECKTABLE.
ITAB-CAN = TAB-REFTABLE.
ITAB-CFI = TAB-REFFIELD.
ITAB-DECIMALS = TAB-DECIMALS.
IF TAB-ROLLNAME NE SPACE.
SELECT SINGLE * FROM DD04T WHERE ROLLNAME = TAB-ROLLNAME
AND DDLANGUAGE = '1'.
IF SY-SUBRC = 0.
ITAB-TEXT = DD04T-DDTEXT.
ELSE.
CLEAR ITAB-TEXT.
ENDIF.
ELSE.
SELECT SINGLE * FROM DD03T WHERE TABNAME = TAB-TABNAME
AND DDLANGUAGE = '1'
AND FIELDNAME = TAB-FIELDNAME.
IF SY-SUBRC = 0.
ITAB-TEXT = DD03T-DDTEXT.
ELSE.
CLEAR ITAB-TEXT.
ENDIF.
ENDIF.
APPEND ITAB.
WRITE:/ ITAB-FIELD,ITAB-KEY,ITAB-ELMENT,ITAB-TYPE,ITAB-LENG,
ITAB-DECIMALS,ITAB-CHK,ITAB-CAN,ITAB-CFI,ITAB-TEXT.
CLEAR ITAB.
ENDLOOP.
IF DOW = 'X'.
CONCATENATE P_DIR T1-TABNAME '_' T1-DDTEXT '.' STYPE
INTO YYNAME.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
FILENAME = YYNAME
FILETYPE = 'ASC'
TABLES
DATA_TAB = ITAB.
ELSE.
ULINE.
ENDIF.
ENDLOOP.
ENDFORM. "GET_TABLE_DATA
转自:http://blog.csdn.net/matterRZ/archive/2006/10/13/1333312.aspx