SAP ABAP 万能修改表程序

2020-11-27 14:20:39 浏览数 (1)

*&---------------------------------------------------------------------* *& Report ZSE16N *& *&---------------------------------------------------------------------* *& *& *&---------------------------------------------------------------------*

REPORT ZSE16N.

DATA: GV_OBJTYPE TYPE OBJTYPE. DATA:IT_SELFIELDS LIKE TABLE OF SE16N_SELTAB WITH HEADER LINE.

PARAMETERS: P_TNAME LIKE DD02L-TABNAME OBLIGATORY, P_MAXL LIKE SY-TABIX DEFAULT '500'.

AT SELECTION-SCREEN. IF P_TNAME IS NOT INITIAL. IF P_TNAME 0(1) <> 'Z' AND P_TNAME 0(1) <> 'Y' AND SY-UNAME <> '0181'. MESSAGE '非自定义表,不能修改' TYPE 'E'. ELSE. CALL FUNCTION 'INTERN_DD_TABL_TYPE' EXPORTING OBJNAME = P_TNAME OBJSTATE = 'M' IMPORTING OBJTYPE = GV_OBJTYPE EXCEPTIONS OBJECT_NOT_FOUND = 1 OBJECT_NOT_SPECIFIED = 2 OTHERS = 3. IF SY-SUBRC <> 0. MESSAGE '输入的表不存在' TYPE 'E'. ELSE. IF GV_OBJTYPE <> 'T' AND GV_OBJTYPE <> 'V'. MESSAGE '输入的表或视图' TYPE 'E'. ENDIF. ENDIF.

ENDIF. ENDIF.

START-OF-SELECTION. PERFORM CALL_SELECTION_COND. PERFORM CALL_SE16N.

*&---------------------------------------------------------------------* *& Form CALL_SELECTION_COND *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM CALL_SELECTION_COND . DATA SELID TYPE RSDYNSEL-SELID. DATA: FIELD_TAB TYPE TABLE OF RSDSFIELDS, LW_FIELD TYPE RSDSFIELDS. DATA TABLE_TAB TYPE TABLE OF RSDSTABS. DATA TABLE LIKE LINE OF TABLE_TAB. DATA:FIELD_RANGES TYPE RSDS_TRANGE, LW_RSDS_R TYPE RSDS_RANGE, LW_RSDS TYPE RSDS_FRANGE, LW_SELOPT TYPE RSDSSELOPT. TABLE-PRIM_TAB = P_TNAME. APPEND TABLE TO TABLE_TAB.

DATA : REF_TABLE_DES TYPE REF TO CL_ABAP_STRUCTDESCR. DATA : IDETAILS TYPE ABAP_COMPDESCR_TAB, XDETAILS TYPE ABAP_COMPDESCR. REF_TABLE_DES ?= CL_ABAP_TABLEDESCR=>DESCRIBE_BY_NAME( P_TNAME ). IDETAILS[] = REF_TABLE_DES->COMPONENTS[]. LOOP AT IDETAILS INTO XDETAILS FROM 2 TO 10. LW_FIELD-TABLENAME = P_TNAME. LW_FIELD-FIELDNAME = XDETAILS-NAME. APPEND LW_FIELD TO FIELD_TAB. ENDLOOP.

CALL FUNCTION 'FREE_SELECTIONS_INIT' EXPORTING KIND = GV_OBJTYPE IMPORTING SELECTION_ID = SELID TABLES TABLES_TAB = TABLE_TAB FIELDS_TAB = FIELD_TAB EXCEPTIONS OTHERS = 4.

CALL FUNCTION 'FREE_SELECTIONS_DIALOG' EXPORTING SELECTION_ID = SELID TITLE = '选择条件' AS_WINDOW = ' ' IMPORTING FIELD_RANGES = FIELD_RANGES TABLES FIELDS_TAB = FIELD_TAB EXCEPTIONS OTHERS = 4.

LOOP AT FIELD_RANGES INTO LW_RSDS_R. LOOP AT LW_RSDS_R-FRANGE_T INTO LW_RSDS. IT_SELFIELDS-FIELD = LW_RSDS-FIELDNAME. LOOP AT LW_RSDS-SELOPT_T INTO LW_SELOPT. IT_SELFIELDS-SIGN = LW_SELOPT-SIGN. IT_SELFIELDS-OPTION = LW_SELOPT-OPTION. IT_SELFIELDS-LOW = LW_SELOPT-LOW. IT_SELFIELDS-HIGH = LW_SELOPT-HIGH. APPEND IT_SELFIELDS. ENDLOOP. CLEAR IT_SELFIELDS. ENDLOOP. ENDLOOP. *FIELD *SIGN *OPTION *LOW *HIGH ENDFORM. " CALL_SELECTION_COND

*&---------------------------------------------------------------------* *& Form CALL_SE16N *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM CALL_SE16N . DATA: I_TAB TYPE SE16N_TAB. I_TAB = P_TNAME. CALL FUNCTION 'SE16N_INTERFACE' EXPORTING I_TAB = I_TAB I_EDIT = 'X' I_SAPEDIT = 'X' * I_NO_TXT = ' ' I_MAX_LINES = P_MAXL * I_LINE_DET = ' ' * I_DISPLAY = 'X' * I_CLNT_SPEZ = ' ' * I_CLNT_DEP = ' ' * I_VARIANT = ' ' * I_OLD_ALV = ' ' * I_CHECKKEY = ' ' * I_TECH_NAMES = ' ' * I_CWIDTH_OPT_OFF = ' ' * I_SCROLL = ' ' * I_NO_CONVEXIT = ' ' * I_LAYOUT_GET = ' ' * I_ADD_FIELD = * I_ADD_FIELDS_ON = * I_UNAME = * I_HANA_ACTIVE = ' ' * I_DBCON = ' ' * I_OJKEY = ' ' * I_DISPLAY_ALL = ' ' * IMPORTING * E_LINE_NR = * E_DREF = * ET_FIELDCAT = TABLES IT_SELFIELDS = IT_SELFIELDS[] * IT_OUTPUT_FIELDS = * IT_OR_SELFIELDS = * IT_CALLBACK_EVENTS = * IT_ADD_UP_CURR_FIELDS = * IT_ADD_UP_QUAN_FIELDS = * IT_SUM_UP_FIELDS = * IT_GROUP_BY_FIELDS = * IT_ORDER_BY_FIELDS = * IT_AGGREGATE_FIELDS = * IT_TOPLOW_FIELDS = * IT_SORTORDER_FIELDS = EXCEPTIONS NO_VALUES = 1 OTHERS = 2. IF SY-SUBRC <> 0. * Implement suitable error handling here ENDIF. ENDFORM. " CALL_SE16N

0 人点赞