Purpose:
Use customer SAP SE38 Editor.Right click & double click will come amazing result.
Used CL_GUI_ABAPEDIT &CL_CTMENU.
Leaved interface for SAP OPENAI CHAGTGPT CODING.
REPORT YSE38.
DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
* messages of call transaction
DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
**DO NOT DELETE THIS WEB
DATA GV_WEBSITE TYPE STRING VALUE ‘HTTP://WWW.HOT583.COM/’.
DATA LV_DESK TYPE STRING .
DATA GV_REPID TYPE SY-REPID.
TYPE-POOLS: SWBSE.
DATA: BEGIN OF GS_USER,
BNAME TYPE C LENGTH 12,
ACTIVE TYPE C LENGTH 1 VALUE ‘X’,
* 引号开头的注释对齐
ALIGN_COMMENTS TYPE C LENGTH 1 VALUE ‘X’,
MIN_POS TYPE I VALUE 30,
MOVE_TO_POS TYPE I VALUE 60,
* DATA 和TYPE要不要对齐标记
ALIGN_DECL TYPE C VALUE ‘X’.
DATA END OF GS_USER.
TYPES: BEGIN OF GTY_BLOCKS,
FROM TYPE I, ” stm
TO TYPE I, ” stm
TYPE TYPE STRING,
POS1 TYPE I,
POS2 TYPE I,
POS3 TYPE I,
POS4 TYPE I,
LINE_FROM TYPE I,
LINE_TO TYPE I,
END OF GTY_BLOCKS.
DATA: GT_BLOCKS TYPE TABLE OF GTY_BLOCKS.
DATA:
GV_INSIDE_BEGINOF TYPE FLAG,
GV_LAST_LINE_FROM TYPE I,
GV_BEGINOF_COL TYPE I,
GT_KEYWORDS TYPE TABLE OF CHAR128, “txh01
GT_TOKENS TYPE STOKESX_TAB WITH HEADER LINE,
GT_STM TYPE SSTMNT_TAB WITH HEADER LINE.
DATA: BEGIN OF MTAB_OLD_PROG OCCURS 0,
LINE(472) TYPE C,
END OF MTAB_OLD_PROG.
DATA: BEGIN OF MTAB_NEW_PROG OCCURS 0,
LINE(472) TYPE C,
END OF MTAB_NEW_PROG.
DATA: BEGIN OF MTAB_JNC_PROG OCCURS 0,
LINE(472) TYPE C,
END OF MTAB_JNC_PROG.
DATA:
* Hold an entire statement, even if it spans multiple lines
BEGIN OF MTAB_LONG_LINE OCCURS 0,
START TYPE I,
END TYPE I,
CODE(9999) TYPE C, “For type “C”, a maximum length specification “of 65535 is allowed.
END OF MTAB_LONG_LINE.
DATA: BEGIN OF MTAB_TABNAME OCCURS 0,
TABNAME LIKE DD02T-TABNAME, ” Table name
TABDESC LIKE DD02T-DDTEXT, ” Short text describing ABAP/4 Dictio
END OF MTAB_TABNAME.
* Queue to hold list of internal table names for commenting the ENDLOOP
* line
DATA: BEGIN OF MTAB_ITAB_NAMES OCCURS 0,
TABNAME(40) TYPE C,
END OF MTAB_ITAB_NAMES.
* Queue to hold list of table names for commenting the ENDSELECT line
DATA: BEGIN OF MTAB_TAB_NAMES OCCURS 0,
TABNAME(40) TYPE C,
END OF MTAB_TAB_NAMES.
DATA: BEGIN OF MTAB_FORM_NAMES OCCURS 0,
TABNAME(40) TYPE C,
END OF MTAB_FORM_NAMES.
CONSTANTS: MYHATS(40) VALUE ‘^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^’.
**********************************************************************
**********************************************************************
**********************************************************************
TYPES:BEGIN OF TY_ROOT,
SEQ TYPE I,
LAYOUT TYPE I,
TOPID TYPE C LENGTH 30,
ZID TYPE C LENGTH 30,
ZNAME TYPE C LENGTH 30,
END OF TY_ROOT.
DATA GT_ROOT TYPE STANDARD TABLE OF TY_ROOT WITH HEADER LINE.
DATA GT_RIGHT TYPE STANDARD TABLE OF TY_ROOT WITH HEADER LINE.
**第1层
GT_ROOT-SEQ = 1.GT_ROOT-LAYOUT = 1.GT_ROOT-TOPID = ”. GT_ROOT-ZID = ‘FRM_ME’. GT_ROOT-ZNAME = ‘User Info’.APPEND GT_ROOT.
GT_ROOT-SEQ = 2.GT_ROOT-LAYOUT = 1.GT_ROOT-TOPID = ”. GT_ROOT-ZID = ‘FRM_ROOT’. GT_ROOT-ZNAME = ‘Try ChatGpt for SAP ABAPer’.APPEND GT_ROOT.
GT_ROOT-SEQ = 3.GT_ROOT-LAYOUT = 1.GT_ROOT-TOPID = ”. GT_ROOT-ZID = ‘FRM_JUMP2’.GT_ROOT-ZNAME = ‘Jump To’.APPEND GT_ROOT.
**第2层
GT_ROOT-SEQ = 5.GT_ROOT-LAYOUT = 2.GT_ROOT-TOPID = ‘FRM_ME’. GT_ROOT-ZID = ‘FRM_MY_INFO’. GT_ROOT-ZNAME = ‘About Me’.APPEND GT_ROOT.
GT_ROOT-SEQ = 1.GT_ROOT-LAYOUT = 2.GT_ROOT-TOPID = ‘FRM_ROOT’. GT_ROOT-ZID = ‘ALV’. GT_ROOT-ZNAME = ‘.ALV ‘.APPEND GT_ROOT.
GT_ROOT-SEQ = 2.GT_ROOT-LAYOUT = 2.GT_ROOT-TOPID = ‘FRM_ROOT’. GT_ROOT-ZID = ‘SQL’. GT_ROOT-ZNAME = ‘.SQL ‘.APPEND GT_ROOT.
GT_ROOT-SEQ = 1.GT_ROOT-LAYOUT = 2.GT_ROOT-TOPID = ‘FRM_JUMP2’. GT_ROOT-ZID = ‘FRM_SAVE_COD’. GT_ROOT-ZNAME = ‘Save Source Code’. APPEND GT_ROOT.
GT_ROOT-SEQ = 1.GT_ROOT-LAYOUT = 2.GT_ROOT-TOPID = ‘FRM_JUMP2’. GT_ROOT-ZID = ‘FRM_BAPIS’. GT_ROOT-ZNAME = ‘Search Bapis Demo’. APPEND GT_ROOT.
GT_ROOT-SEQ = 2.GT_ROOT-LAYOUT = 2.GT_ROOT-TOPID = ‘FRM_JUMP2’. GT_ROOT-ZID = ‘FRM_JUMP2SCR’. GT_ROOT-ZNAME = ‘JumpTo Screen Define’. APPEND GT_ROOT.
GT_ROOT-SEQ = 3.GT_ROOT-LAYOUT = 2.GT_ROOT-TOPID = ‘FRM_JUMP2’. GT_ROOT-ZID = ‘FRM_JUMP2INT’. GT_ROOT-ZNAME = ‘JumpTo Initialization’.APPEND GT_ROOT.
GT_ROOT-SEQ = 4.GT_ROOT-LAYOUT = 2.GT_ROOT-TOPID = ‘FRM_JUMP2’. GT_ROOT-ZID = ‘FRM_JUMP2BEG’. GT_ROOT-ZNAME = ‘JumpTo Start-of-selection’.APPEND GT_ROOT.
GT_ROOT-SEQ = 5.GT_ROOT-LAYOUT = 2.GT_ROOT-TOPID = ‘FRM_JUMP2’. GT_ROOT-ZID = ‘FRM_JUMP2END’. GT_ROOT-ZNAME = ‘JumpTo End Of Souce’.APPEND GT_ROOT.
**第3层
GT_ROOT-SEQ = 1.GT_ROOT-LAYOUT = 3.GT_ROOT-TOPID = ‘ALV’. GT_ROOT-ZID = ‘FRM_ALV_DEMO’. GT_ROOT-ZNAME = ‘Set ALV Demo’. APPEND GT_ROOT.
GT_ROOT-SEQ = 2.GT_ROOT-LAYOUT = 3.GT_ROOT-TOPID = ‘ALV’. GT_ROOT-ZID = ‘FRM_LAYOUT’. GT_ROOT-ZNAME = ‘Set LAYOUT’. APPEND GT_ROOT.
GT_ROOT-SEQ = 3.GT_ROOT-LAYOUT = 3.GT_ROOT-TOPID = ‘ALV’. GT_ROOT-ZID = ‘FRM_FIELDCAT’. GT_ROOT-ZNAME = ‘Set FIELD CAT’.APPEND GT_ROOT.
GT_ROOT-SEQ = 1.GT_ROOT-LAYOUT = 3.GT_ROOT-TOPID = ‘SQL’. GT_ROOT-ZID = ‘FRM_FAI’. GT_ROOT-ZNAME = ‘For All Entries In’. APPEND GT_ROOT.
GT_ROOT-SEQ = 2.GT_ROOT-LAYOUT = 3.GT_ROOT-TOPID = ‘SQL’. GT_ROOT-ZID = ‘FRM_BIN_SEA’. GT_ROOT-ZNAME = ‘Binary Search’. APPEND GT_ROOT.
GT_ROOT-SEQ = 3.GT_ROOT-LAYOUT = 3.GT_ROOT-TOPID = ‘SQL’. GT_ROOT-ZID = ‘FRM_DEL_DUP’. GT_ROOT-ZNAME = ‘Delete Adjacent Duplicates’. APPEND GT_ROOT.
**********************************************************************
**********************************************************************
**********************************************************************
**右边代码层菜单:第1层
GT_RIGHT-SEQ = 2.GT_RIGHT-LAYOUT = 1.GT_RIGHT-TOPID = ”. GT_RIGHT-ZID = ‘FRM_ASK_CHATGPT_NO’. GT_RIGHT-ZNAME = ‘【Ask Chat GPT No Waitting】’.APPEND GT_RIGHT.
GT_RIGHT-SEQ = 2.GT_RIGHT-LAYOUT = 1.GT_RIGHT-TOPID = ”. GT_RIGHT-ZID = ‘FRM_ASK_CHATGPT_WAIT’.GT_RIGHT-ZNAME = ‘【Ask Chat GPT Waitting Answer】’.APPEND GT_RIGHT.
GT_RIGHT-SEQ = 2.GT_RIGHT-LAYOUT = 1.GT_RIGHT-TOPID = ”. GT_RIGHT-ZID = ‘FRM_ASK_BING_CHAT’.GT_RIGHT-ZNAME = ‘【Ask Chat Bing Chat GPT Waitting Answer】’.APPEND GT_RIGHT.
GT_RIGHT-SEQ = 1.GT_RIGHT-LAYOUT = 2.GT_RIGHT-TOPID = ‘.Customer Format’. GT_RIGHT-ZID = ‘FRM_PRET_PRT’.GT_RIGHT-ZNAME = ‘Pretty Printer’.APPEND GT_RIGHT.
GT_RIGHT-SEQ = 2.GT_RIGHT-LAYOUT = 2.GT_RIGHT-TOPID = ‘.Customer Format’. GT_RIGHT-ZID = ‘FRM_AUTO_COM’.GT_RIGHT-ZNAME = ‘Auto Comment’.APPEND GT_RIGHT.
GT_RIGHT-SEQ = 2.GT_RIGHT-LAYOUT = 2.GT_RIGHT-TOPID = ‘.Customer Format’. GT_RIGHT-ZID = ‘FRM_ADD_LOG’.GT_RIGHT-ZNAME = ‘Add Modify Log’.APPEND GT_RIGHT.
**********************************************************************自动填充函数定义.
GT_RIGHT-SEQ = 2.GT_RIGHT-LAYOUT = 2.GT_RIGHT-TOPID = ‘.Auto Fill Object’. GT_RIGHT-ZID = ‘FRM_AUTO_FILL_G’.GT_RIGHT-ZNAME = ‘Fill Object With Global Naming’.APPEND GT_RIGHT.
GT_RIGHT-SEQ = 2.GT_RIGHT-LAYOUT = 2.GT_RIGHT-TOPID = ‘.Auto Fill Object’. GT_RIGHT-ZID = ‘FRM_AUTO_FILL_L’.GT_RIGHT-ZNAME = ‘Fill Object With Local Naming’.APPEND GT_RIGHT.
CLASS LCL_code_EVENTHANDLER DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
HANDLE_CODE_CONTEXT_MENU
FOR EVENT CONTEXT_MENU OF CL_GUI_ABAPEDIT
IMPORTING
MENU
SENDER,
HANDLE_CODE_CTXMENU_SELECTED
FOR EVENT CONTEXT_MENU_SELECTED OF CL_GUI_ABAPEDIT
IMPORTING
FCODE
SENDER,
HANDLE_CODE_BORDER_CLICK
FOR EVENT BORDER_CLICK OF CL_GUI_ABAPEDIT
IMPORTING
LINE
CNTRL_PRESSED_SET
SHIFT_PRESSED_SET,
HANDLE_CODE_BP_CHG
FOR EVENT BREAKPOINT_CHANGED OF CL_GUI_ABAPEDIT
IMPORTING
LINE
IS_SET
IS_DISABLED,
HANDLE_code_dbclick
FOR EVENT DBLCLICK OF CL_GUI_ABAPEDIT.
ENDCLASS. “LCL_code_EVENTHANDLER DEFINITION
*———————————————————————*
* CLASS LCL_code_EVENTHANDLER IMPLEMENTATION
*———————————————————————*
*
*———————————————————————*
CLASS LCL_code_EVENTHANDLER IMPLEMENTATION.
METHOD HANDLE_code_CONTEXT_MENU.
DATA LV_ICON TYPE ICON_D.
DATA LR_SUB_MEN TYPE REF TO CL_CTMENU.
DATA LWA_RIGHT TYPE TY_ROOT.
DATA LT_SUB TYPE STANDARD TABLE OF TY_ROOT.
DATA LWA_SUB TYPE TY_ROOT.
DATA: TEXT TYPE GUI_TEXT.
DATA: UI_FUNC TYPE UI_FUNC.
LV_ICON = ‘@01@’.
**********************************************************************
**********************************************************************
**********************************************************************
LOOP AT GT_RIGHT INTO LWA_RIGHT WHERE LAYOUT = 1.
UI_FUNC = LWA_RIGHT-ZID.
TEXT = LWA_RIGHT-ZNAME.
CALL METHOD MENU->ADD_FUNCTION
EXPORTING
FCODE = UI_FUNC “‘MY_FUNC2’
TEXT = TEXT ” ‘My Function2’
ICON = LV_ICON.
ENDLOOP. ” LOOP AT GT_RIGHT
LT_SUB = GT_RIGHT[].
**********************************************************************
************子菜单****************************************************
**********************************************************************
DELETE LT_SUB WHERE LAYOUT <> 2.
SORT LT_SUB BY TOPID.
DELETE ADJACENT DUPLICATES FROM LT_SUB COMPARING TOPID.
LOOP AT LT_SUB INTO LWA_SUB .
LR_SUB_MEN = NEW CL_CTMENU( ).
LOOP AT GT_RIGHT INTO LWA_RIGHT WHERE LAYOUT = 2 AND TOPID = LWA_SUB-TOPID.
UI_FUNC = LWA_RIGHT-ZID.
TEXT = LWA_RIGHT-ZNAME.
CALL METHOD LR_SUB_MEN->ADD_FUNCTION
EXPORTING
FCODE = UI_FUNC “‘MY_FUNC2’
TEXT = TEXT ” ‘My Function2’
ICON = LV_ICON.
ENDLOOP. ” LOOP AT GT_RIGHT
TEXT = LWA_SUB-TOPID.
CALL METHOD MENU->ADD_SUBMENU
EXPORTING
MENU = LR_SUB_MEN
TEXT = TEXT. “‘SUB’.
ENDLOOP. ” LOOP AT LT_SUB
ENDMETHOD. “handle_context_menu
METHOD HANDLE_code_CTXMENU_SELECTED.
DATA LV_FORM TYPE SY-REPID.
LV_FORM = FCODE.
PERFORM (LV_FORM) IN PROGRAM (SY-REPID) IF FOUND.
ENDMETHOD. “handle_ctxmenu_selected
METHOD HANDLE_code_dbclick.
* 双击代码行的时候
PERFORM FRM_CODE_DB_CLICK .
ENDMETHOD. “HANDLE_code_dbclick
METHOD HANDLE_code_BORDER_CLICK.
ENDMETHOD.
METHOD HANDLE_CODE_BP_CHG.
PERFORM FRM_SET_BP USING IS_SET LINE.
ENDMETHOD.
ENDCLASS.
**********************************************************************
CLASS LCL_NODE_APPLICATION DEFINITION DEFERRED.
CLASS CL_GUI_CFW DEFINITION LOAD.
TYPES: NODE_TABLE_TYPE LIKE STANDARD TABLE OF MTREESNODE
WITH DEFAULT KEY.
TYPES: SOURCE_TABLE TYPE SOLI_TAB.
DATA: G_APPLICATION TYPE REF TO LCL_NODE_APPLICATION,
GV_READ_ONLY TYPE I.
**********************************************************************
*———————————————————————-*
* INCLUDE SIMPLE_TREE_CONTROL_DEMOCL1 *
*———————————————————————-*
CLASS LCL_NODE_APPLICATION DEFINITION.
**********************************************************************
PUBLIC SECTION.
METHODS:
HANDLE_NODE_DOUBLE_CLICK FOR EVENT NODE_DOUBLE_CLICK
OF CL_GUI_SIMPLE_TREE IMPORTING NODE_KEY,
**********************************************************************
HANDLE_NODE_CONTEXT_MENU_REQ
FOR EVENT NODE_CONTEXT_MENU_REQUEST
OF CL_GUI_SIMPLE_TREE
IMPORTING NODE_KEY MENU,
**********************************************************************
HANDLE_NODE_CONTEXT_MENU_SEL
FOR EVENT NODE_CONTEXT_MENU_SELECT
OF CL_GUI_SIMPLE_TREE
IMPORTING NODE_KEY FCODE.
ENDCLASS.
*———————————————————————*
* CLASS LCL_NODE_APPLICATION IMPLEMENTATION
*———————————————————————*
* …. *
*———————————————————————*
CLASS LCL_NODE_APPLICATION IMPLEMENTATION.
METHOD HANDLE_NODE_CONTEXT_MENU_REQ.
DATA: TEXT TYPE GUI_TEXT.
DATA: UI_FUNC TYPE UI_FUNC.
DATA LWA_ROOT TYPE TY_ROOT.
DATA LWA_ROOT2 TYPE TY_ROOT.
LOOP AT GT_ROOT INTO LWA_ROOT
WHERE LAYOUT = 2
AND ZID = NODE_KEY.
LOOP AT GT_ROOT INTO LWA_ROOT2
WHERE LAYOUT = 3
AND TOPID = LWA_ROOT-ZID .
TEXT = LWA_ROOT2-ZNAME.
UI_FUNC = LWA_ROOT2-ZID.
CALL METHOD MENU->ADD_FUNCTION
EXPORTING
TEXT = TEXT
FCODE = UI_FUNC. “#EC NOTEXT
ENDLOOP. ” LOOP AT GT_ROOT
ENDLOOP. ” LOOP AT GT_ROOT
ENDMETHOD.
METHOD HANDLE_NODE_CONTEXT_MENU_SEL.
DATA LV_REP TYPE C LENGTH 30.
LV_REP = FCODE.
PERFORM (LV_REP) IN PROGRAM (SY-REPID) IF FOUND.
ENDMETHOD.
METHOD HANDLE_NODE_DOUBLE_CLICK.
DATA LWA_ROOT TYPE TY_ROOT.
LOOP AT GT_ROOT INTO LWA_ROOT WHERE “LAYOUT = 2 AND
ZID = NODE_KEY.
PERFORM (LWA_ROOT-ZID) IN PROGRAM (SY-REPID) IF FOUND.
EXIT.
ENDLOOP. ” LOOP AT GT_ROOT
ENDMETHOD.
ENDCLASS.
**********************************************************************
TYPES: BEGIN OF TY_KEY_INFO,
HEAD TYPE LVC_VALUE,
NODE TYPE LVC_VALUE,
KEY TYPE LVC_NKEY,
END OF TY_KEY_INFO.
PARAMETERS P_USER TYPE C LENGTH 20 NO-DISPLAY.
PARAMETERS P_PASS TYPE C LENGTH 20 NO-DISPLAY.
PARAMETERS: P_BOR TYPE REPOSRC-PROGNAME DEFAULT ‘YSE38B’.
DATA:
GO_ALV_TREE TYPE REF TO CL_GUI_SIMPLE_TREE,
GO_SPLITTER TYPE REF TO CL_GUI_SPLITTER_CONTAINER,
GV_FULLSCREEN TYPE C,
GO_EDITOR TYPE REF TO CL_GUI_ABAPEDIT,
GO_SCHECK TYPE REF TO CL_GUI_TEXTEDIT,
GO_WB_EDITOR TYPE REF TO CL_WB_EDITOR,
GT_KEY_INFO TYPE STANDARD TABLE OF TY_KEY_INFO,
GS_KEY_INFO TYPE TY_KEY_INFO,
OK_CODE LIKE SY-UCOMM, ” ABAP system field: Function code that raised PAI
GT_PROGRAM TYPE STRING_TABLE.
CLASS CL_GUI_COLUMN_TREE DEFINITION LOAD.
CLASS CL_GUI_CFW DEFINITION LOAD.
INITIALIZATION.
PERFORM FRM_INIT.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_BOR.
PERFORM FRM_F4.
START-OF-SELECTION.
CREATE OBJECT G_APPLICATION.
**********************************************************************
**********************************************************************
END-OF-SELECTION.
READ REPORT P_BOR INTO GT_PROGRAM.
CALL SCREEN 100.
MODULE STATUS_0100 OUTPUT.
* WB_EDIT_ENH 增强
* WB_BACK_TB 前进
* WB_ACT_INACT_TOGGLE
* WB_OTHER_OBJECT
* WB_EDIT_ENH
* WB_WHERE_USED_LIST
* WB_OBJECT_LIST
* WB_NAVSTACK_EDIT
* ED_HELP_ABAP
* ED_SET_BREAK “打断点。
* ED_SET_EXT_BREAK ”外部断点
DATA LT_EXE TYPE STANDARD TABLE OF CHAR100 WITH HEADER LINE.
LT_EXE = ‘WB_EDIT_ENH ‘.APPEND LT_EXE.
LT_EXE = ‘WB_BACK_TB ‘.APPEND LT_EXE.
LT_EXE = ‘WB_ACT_INACT_TOGGLE’.APPEND LT_EXE.
LT_EXE = ‘WB_OTHER_OBJECT’.APPEND LT_EXE.
LT_EXE = ‘WB_EDIT_ENH’.APPEND LT_EXE.
LT_EXE = ‘WB_WHERE_USED_LIST’.APPEND LT_EXE.
LT_EXE = ‘WB_OBJECT_LIST’.APPEND LT_EXE.
LT_EXE = ‘WB_NAVSTACK_EDIT’.APPEND LT_EXE.
LT_EXE = ‘ED_HELP_ABAP ‘.APPEND LT_EXE.
LT_EXE = ‘ED_SET_BREAK ‘.APPEND LT_EXE.
LT_EXE = ‘ED_SET_EXT_BREAK ‘.APPEND LT_EXE.
SET PF-STATUS ‘WB_WITH_TOOL_PC’ OF PROGRAM ‘SAPLS38E’ EXCLUDING LT_EXE[].
SET TITLEBAR ‘WB_TITLE’ OF PROGRAM ‘SAPLS38E’ WITH ‘程序:’ P_BOR.
IF GO_ALV_TREE IS INITIAL.
PERFORM INIT_TREE.
ENDIF.
CALL METHOD CL_GUI_CFW=>FLUSH.
ENDMODULE. ” STATUS_0100 OUTPUT
MODULE USER_COMMAND_0100 INPUT.
TYPES: TY_EDITOR_LINE(72) TYPE C.
DATA: LT_ERROR TYPE STANDARD TABLE OF SWOTERROR,
LV_SUBRC TYPE SY-SUBRC, ” ABAP System Field: Return Code of ABAP Statements
LS_MESSAGE TYPE TLINE,
LT_EDLINE TYPE STANDARD TABLE OF TY_EDITOR_LINE,
LV_INDEX TYPE I,
LV_LINE TYPE I.
GO_SCHECK->SET_TEXT_AS_STREAM( LT_EDLINE[] ).
GO_SPLITTER->SET_ROW_HEIGHT( ID = 2 HEIGHT = 0 ).
CASE OK_CODE.
WHEN ‘ED_NUM_TEXT’.”文本元素.
DATA LV_SE38 TYPE RS38M-PROGRAMM.
LV_SE38 = P_BOR.
CALL FUNCTION ‘RS_TEXTPOOL_SHOW’
EXPORTING
OBJECTNAME = LV_SE38
EXCEPTIONS
OBJECT_NOT_FOUND = 1
PERMISSION_FAILURE = 2
INVALID_PROGRAM_TYPE = 3
ERROR_OCCURED = 4
ACTION_CANCELLED = 5
OTHERS = 6.
IF SY-SUBRC <> 0.
BREAK-POINT.
ENDIF.
WHEN ‘WB_BACK_TB’.
CALL METHOD GO_ALV_TREE->FREE.
CALL METHOD GO_EDITOR->FREE.
CALL METHOD GO_SCHECK->FREE.
CALL METHOD GO_SPLITTER->FREE.
PERFORM UNLOCK_OBJECT.
LEAVE PROGRAM.
WHEN ‘WB_BACK’ OR ‘WB_END’ OR ‘WB_CANCEL’. “返回/退出/结束按钮.
CALL METHOD GO_ALV_TREE->FREE.
CALL METHOD GO_EDITOR->FREE.
CALL METHOD GO_SCHECK->FREE.
CALL METHOD GO_SPLITTER->FREE.
PERFORM UNLOCK_OBJECT.
LEAVE PROGRAM.
WHEN ‘ED_PRETTY_PRINT’ .”代码格式化PRETTY PRINTER 按钮。
PERFORM FRM_PRET_PRT.
WHEN ‘WB_SAVE’.”保存按钮。
PERFORM FRM_SAVE.
WHEN ‘WB_CHECK’.”检查按钮。
DATA LV_MAKER TYPE I.
DATA LT_M TYPE STANDARD TABLE OF I.
CALL METHOD GO_EDITOR->GET_MARKER
EXPORTING
MARKER_NUMBER = LV_MAKER
IMPORTING
MARKER_LINES = LT_M.
PERFORM SYNTAX_CHECK CHANGING LV_SUBRC.
WHEN ‘WB_ACTIVATE’.”激活按钮
CLEAR: LV_SUBRC, LT_ERROR.
PERFORM SYNTAX_CHECK CHANGING LV_SUBRC.
IF LV_SUBRC = 0.
PERFORM FRM_SAVE.
DATA L_INDEX_PROGRAMS TYPE PROGRAMT.
DATA LV_OBJ TYPE E071-OBJ_NAME. ” Object Name in Object List
LV_OBJ = P_BOR.
CALL FUNCTION ‘REPS_OBJECT_ACTIVATE’
EXPORTING
OBJECT_NAME = LV_OBJ
SUPPRESS_INDEX_UPDATE = ”
IMPORTING
INDEX_PROGRAMS = L_INDEX_PROGRAMS
EXCEPTIONS
OTHERS = 1.
IF SY-SUBRC <> 0.
MESSAGE ‘Object could not be generated’ TYPE ‘S’.
ELSE.
MESSAGE ‘Object successfully generated’ TYPE ‘S’.
ENDIF.
ENDIF.
WHEN ‘WB_DISP_EDIT_TOGGLE’. “铅笔,编辑或者取消编辑
IF GV_READ_ONLY = 1.
CLEAR LV_SUBRC.
PERFORM LOCK_OBJECT CHANGING LV_SUBRC.
IF LV_SUBRC EQ 0.
GV_READ_ONLY = 0.
ENDIF.
ELSE.
PERFORM UNLOCK_OBJECT.
GV_READ_ONLY = 1.
ENDIF.
GO_EDITOR->SET_READONLY_MODE( GV_READ_ONLY ).
WHEN ‘WB_EXEC’.”F8执行。
PERFORM SYNTAX_CHECK CHANGING LV_SUBRC.
IF LV_SUBRC IS INITIAL.
SUBMIT (P_BOR) VIA SELECTION-SCREEN AND RETURN.
ENDIF.
WHEN ‘ED_INS_FRAME’.”调用pattern。
PERFORM FRM_PATTERN.
WHEN ‘WB_FULLSCREEN’.
IF GV_FULLSCREEN IS INITIAL.
GO_SPLITTER->SET_COLUMN_WIDTH( ID = 1 WIDTH = 0 ).
GO_SPLITTER->SET_COLUMN_WIDTH( ID = 2 WIDTH = 120 ).
GV_FULLSCREEN = ‘X’.
ELSE.
GO_SPLITTER->SET_COLUMN_WIDTH( ID = 1 WIDTH = 15 ).
GO_SPLITTER->SET_COLUMN_WIDTH( ID = 2 WIDTH = 100 ).
CLEAR GV_FULLSCREEN.
ENDIF.
WHEN OTHERS.
CALL METHOD CL_GUI_CFW=>DISPATCH.
ENDCASE.
CLEAR OK_CODE.
CALL METHOD CL_GUI_CFW=>FLUSH.
ENDMODULE. ” USER_COMMAND_0100 INPUT
FORM INIT_TREE .
DATA: LO_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
LO_TREE TYPE REF TO CL_GUI_CONTAINER,
LO_CODE TYPE REF TO CL_GUI_CONTAINER,
LO_Source_CHECK TYPE REF TO CL_GUI_CONTAINER,
lo_AD TYPE REF TO CL_GUI_CONTAINER,
LS_HIERARCHY_HEADER TYPE TREEV_HHDR,
LS_VARIANT TYPE DISVARIANT.
*
CREATE OBJECT LO_CONTAINER
EXPORTING
CONTAINER_NAME = ‘CONT’
EXCEPTIONS
OTHERS = 5.
IF SY-SUBRC <> 0.
BREAK-POINT.
ENDIF.
CREATE OBJECT GO_SPLITTER
EXPORTING
PARENT = LO_CONTAINER
ROWS = 2
COLUMNS = 2
ALIGN = 15.
GO_SPLITTER->SET_COLUMN_WIDTH( ID = 1 WIDTH = 15 ).
GO_SPLITTER->SET_COLUMN_WIDTH( ID = 2 WIDTH = 90 ).
GO_SPLITTER->SET_ROW_HEIGHT( ID = 2 HEIGHT = 0 ).
* 左边
CALL METHOD GO_SPLITTER->GET_CONTAINER
EXPORTING
ROW = 1
COLUMN = 1
RECEIVING
CONTAINER = LO_TREE.
* 右边
CALL METHOD GO_SPLITTER->GET_CONTAINER
EXPORTING
ROW = 1
COLUMN = 2
RECEIVING
CONTAINER = LO_CODE.
* 右下角代码检查报错。
CALL METHOD GO_SPLITTER->GET_CONTAINER
EXPORTING
ROW = 2
COLUMN = 2
RECEIVING
CONTAINER = LO_Source_CHECK.
* 左下角代码检查报错。
CALL METHOD GO_SPLITTER->GET_CONTAINER
EXPORTING
ROW = 2
COLUMN = 1
RECEIVING
CONTAINER = lo_AD.
DATA G_HTML_VIEWER TYPE REF TO CL_GUI_HTML_VIEWER.
CREATE OBJECT G_HTML_VIEWER
EXPORTING
PARENT = lo_AD.
DATA: LV_URL(255) TYPE C.
LV_URL = GV_WEBSITE.
CONDENSE LV_URL NO-GAPS.
G_HTML_VIEWER->SHOW_URL( URL = LV_URL ).
**********************************************************************
**********************************************************************
PERFORM CREATE_TREE USING LO_TREE LO_CONTAINER.
PERFORM CREATE_EDITOR USING LO_CODE.
PERFORM set_registered_events_RIGHT.
GO_EDITOR->SET_TEXT( GT_PROGRAM ).
GO_EDITOR->SET_TOOLBAR_MODE( 1 ).
GO_EDITOR->SET_TABBAR_MODE( 1 ).
GV_READ_ONLY = 1.
GO_EDITOR->SET_READONLY_MODE( GV_READ_ONLY ).
GO_EDITOR->SET_VISIBLE( ‘X’ ).
PERFORM CREATE_SCHECK USING LO_Source_CHECK.
DATA: NODE_TABLE TYPE NODE_TABLE_TYPE.
PERFORM BUILD_NODE_TABLE USING NODE_TABLE.
CALL METHOD GO_ALV_TREE->ADD_NODES
EXPORTING
TABLE_STRUCTURE_NAME = ‘MTREESNODE’
NODE_TABLE = NODE_TABLE
EXCEPTIONS
FAILED = 1
ERROR_IN_NODE_TABLE = 2
DP_ERROR = 3
TABLE_STRUCTURE_NAME_NOT_FOUND = 4
OTHERS = 5.
IF SY-SUBRC <> 0.
BREAK-POINT.
ENDIF.
* expand the root node
DATA LT_ROOT TYPE STANDARD TABLE OF TY_ROOT.
LT_ROOT = GT_ROOT[].
SORT LT_ROOT BY LAYOUT SEQ.
DELETE ADJACENT DUPLICATES FROM LT_ROOT COMPARING LAYOUT.
LOOP AT GT_ROOT WHERE LAYOUT = 1.
DATA LV_NODEKEY TYPE TV_NODEKEY.
LV_NODEKEY = GT_ROOT-ZID.
CALL METHOD GO_ALV_TREE->EXPAND_NODE
EXPORTING
NODE_KEY = LV_NODEKEY “#EC NOTEXT
EXCEPTIONS
FAILED = 1
ILLEGAL_LEVEL_COUNT = 2
CNTL_SYSTEM_ERROR = 3
NODE_NOT_FOUND = 4
CANNOT_EXPAND_LEAF = 5.
IF SY-SUBRC <> 0.
BREAK-POINT.
ENDIF.
ENDLOOP. ” LOOP AT GT_ROOT
ENDFORM. ” INIT_TREE
FORM CREATE_TREE USING PO_TREE TYPE REF TO CL_GUI_CONTAINER
U_cl_gui_custom_container TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
CREATE OBJECT GO_ALV_TREE
EXPORTING
PARENT = PO_TREE
NODE_SELECTION_MODE = CL_GUI_COLUMN_TREE=>NODE_SEL_MODE_MULTIPLE
EXCEPTIONS
OTHERS = 7.
* define the events which will be passed to the backend
” node context menu request
DATA: NODE_TABLE TYPE NODE_TABLE_TYPE,
EVENTS TYPE CNTL_SIMPLE_EVENTS,
EVENT TYPE CNTL_SIMPLE_EVENT.
EVENT-EVENTID = CL_GUI_SIMPLE_TREE=>EVENTID_NODE_CONTEXT_MENU_REQ. EVENT-APPL_EVENT = ‘ ‘. APPEND EVENT TO EVENTS.
EVENT-EVENTID = CL_GUI_SIMPLE_TREE=>EVENTID_NODE_DOUBLE_CLICK . EVENT-APPL_EVENT = ‘ ‘. APPEND EVENT TO EVENTS.
” process PAI if context menu select event occurs
CALL METHOD GO_ALV_TREE->SET_CTX_MENU_SELECT_EVENT_APPL
EXPORTING
APPL_EVENT = ‘X’.
CALL METHOD GO_ALV_TREE->SET_REGISTERED_EVENTS
EXPORTING
EVENTS = EVENTS
EXCEPTIONS
CNTL_ERROR = 1
CNTL_SYSTEM_ERROR = 2
ILLEGAL_EVENT_COMBINATION = 3.
IF SY-SUBRC <> 0.
BREAK-POINT.
ENDIF.
** 显示菜单
SET HANDLER G_APPLICATION->HANDLE_NODE_DOUBLE_CLICK FOR GO_ALV_TREE.
SET HANDLER G_APPLICATION->HANDLE_NODE_CONTEXT_MENU_REQ FOR GO_ALV_TREE.
** 菜单出来后,选中菜单,点击后操作
SET HANDLER G_APPLICATION->HANDLE_NODE_CONTEXT_MENU_SEL FOR GO_ALV_TREE.
ENDFORM. ” CREATE_TREE
FORM CREATE_EDITOR USING PO_CODE TYPE REF TO CL_GUI_CONTAINER.
DATA: LO_SOURCE TYPE REF TO CL_WB_SOURCE.
CREATE OBJECT GO_EDITOR “CL_GUI_ABAPEDIT
EXPORTING
PARENT = PO_CODE. “CL_GUI_CONTAINER
CL_WB_EDITOR=>CONTROL_CONTAINER2 = PO_CODE.
CL_WB_EDITOR=>CONTROL_HANDLE3 = GO_EDITOR.
CREATE OBJECT GO_WB_EDITOR
EXPORTING
CONTENT = GT_PROGRAM
MODE = ‘EDIT’
LINK_DYNNR = ‘0100’.
GO_WB_EDITOR->CREATE_SOURCE_OBJECT( IMPORTING SOURCE_OBJECT = LO_SOURCE ).
ENDFORM. ” CREATE_EDITOR
FORM CREATE_SCHECK USING PO_SCHECK TYPE REF TO CL_GUI_CONTAINER.
CREATE OBJECT GO_SCHECK
EXPORTING
PARENT = PO_SCHECK
EXCEPTIONS
OTHERS = 6.
GO_SCHECK->SET_VISIBLE( ‘2’ ).
GO_SCHECK->SET_READONLY_MODE( 1 ).
GO_SCHECK->SET_TOOLBAR_MODE( 0 ).
GO_SCHECK->SET_WORDWRAP_BEHAVIOR( WORDWRAP_MODE = 2 WORDWRAP_POSITION = 60 ).
ENDFORM. ” CREATE_SCHECK
FORM SYNTAX_CHECK CHANGING CV_SUBRC.
TYPES: TY_EDITOR_LINE(72) TYPE C.
DATA: LT_ERROR TYPE STANDARD TABLE OF SWOTERROR,
LS_ERROR TYPE SWOTERROR,
LS_MESSAGE TYPE TLINE,
LT_MESSAGE TYPE STANDARD TABLE OF TLINE,
LT_EDLINE TYPE STANDARD TABLE OF TY_EDITOR_LINE.
CLEAR CV_subrc.
DATA: LV_PROGRAM TYPE PROGRAMM,
LV_MSG TYPE STRING,
LV_LINE TYPE C LENGTH 5,
LV_WORD TYPE CHAR50,
LT_STR TYPE TABLE OF STRING,
LS_TRDIR TYPE TRDIR,
LV_STR1 TYPE STRING,
LV_STR2 TYPE STRING,
LV_STR3 TYPE STRING,
LV_STR4 TYPE STRING.
DATA: L_FROM TYPE I,
L_TO TYPE I,
L_FROM_NEW TYPE I,
L_TO_NEW TYPE I,
L_FROM_LINE TYPE I,
L_TO_LINE TYPE I,
L_LEN TYPE I,
LV_LINES TYPE I,
LV_MIDDLE_STRING TYPE STRING,
LT_TEXT TYPE SOURCE_TABLE WITH HEADER LINE,
LT_TEXT_TEMP TYPE SOURCE_TABLE,
L_TEXT LIKE LINE OF LT_TEXT_TEMP,
LSTR TYPE STRING,
LSTR2 TYPE STRING,
LT_TEXT_SPLIT TYPE TABLE OF STRING,
LS_SEL_FIELD_LIST TYPE STRING,
LV_FROM_COPY TYPE I.
CALL METHOD GO_EDITOR->GET_SELECTION_POS
IMPORTING
FROM_LINE = L_FROM_LINE
FROM_POS = L_FROM
TO_LINE = L_TO_LINE
TO_POS = L_TO
EXCEPTIONS
ERROR_CNTL_CALL_METHOD = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
IF SY-MSGNO IS NOT INITIAL.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO DISPLAY LIKE ‘I’
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4 .
ENDIF.
ENDIF.
*abaped CALL METHOD g_textedit->get_text_as_r3table
CALL METHOD GO_EDITOR->GET_TEXT
IMPORTING
TABLE = GT_PROGRAM[]
EXCEPTIONS
*abaped potential_data_loss = 1.
OTHERS = 1.
SYNTAX-CHECK FOR GT_PROGRAM[]
MESSAGE LV_MSG
LINE LV_LINE
WORD LV_WORD
PROGRAM P_BOR.
CV_subrc = SY-SUBRC.
IF CV_subrc IS INITIAL.
MESSAGE ‘No Syntax error in object’ TYPE ‘S’.
ELSE.
CV_subrc = 2.
LOOP AT LT_ERROR INTO LS_ERROR.
LS_MESSAGE-TDFORMAT = ‘/’.
CONCATENATE LS_ERROR-VARIABLE1 LS_ERROR-VARIABLE2 LS_ERROR-VARIABLE3 LS_ERROR-VARIABLE4 INTO LS_MESSAGE-TDLINE.
ENDLOOP. ” LOOP AT LT_ERROR
LS_MESSAGE-TDFORMAT = ‘/’.
CONCATENATE ‘行:’ LV_LINE ‘:’ LV_WORD INTO LS_MESSAGE-TDLINE. APPEND LS_MESSAGE TO LT_MESSAGE.
CONCATENATE ‘错误:’ LV_MSG INTO LS_MESSAGE-TDLINE. APPEND LS_MESSAGE TO LT_MESSAGE.
CALL FUNCTION ‘CONVERT_ITF_TO_STREAM_TEXT’
TABLES
ITF_TEXT = LT_MESSAGE
TEXT_STREAM = LT_EDLINE.
GO_SCHECK->SET_TEXT_AS_STREAM( LT_EDLINE ).
GO_SCHECK->SET_VISIBLE( ‘X’ ).
GO_SPLITTER->SET_ROW_HEIGHT( ID = 2 HEIGHT = 20 ).
REFRESH LT_MESSAGE.
DATA LV_L TYPE I.
LV_L = LV_LINE.
GO_EDITOR->SET_FIRST_VISIBLE_LINE( LV_L ).
ENDIF.
ENDFORM. ” SYNTAX_CHECK
FORM LOCK_OBJECT CHANGING P_SUBRC.
DATA: LV_VARKEY TYPE PROGNAME.
LV_VARKEY = P_BOR.
CALL FUNCTION ‘ENQUEUE_E_TRDIR’
EXPORTING
MODE_TRDIR = ‘X’
NAME = LV_VARKEY
X_NAME = ‘ ‘
_SCOPE = ‘2’
_WAIT = ‘ ‘
_COLLECT = ‘ ‘
EXCEPTIONS
FOREIGN_LOCK = 1
SYSTEM_FAILURE = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
P_SUBRC = SY-SUBRC.
CLEAR OK_CODE.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 LV_VARKEY SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. ” LOCK_OBJECT
FORM UNLOCK_OBJECT .
DATA: LV_VARKEY TYPE PROGNAME.
LV_VARKEY = P_BOR.
CALL FUNCTION ‘DEQUEUE_E_TRDIR’
EXPORTING
MODE_TRDIR = ‘X’
NAME = LV_VARKEY
X_NAME = ‘ ‘
_SCOPE = ‘3’
_SYNCHRON = ‘ ‘
_COLLECT = ‘ ‘.
ENDFORM. ” UNLOCK_OBJECT
FORM BUILD_NODE_TABLE
USING NODE_TABLE TYPE NODE_TABLE_TYPE.
DATA: NODE LIKE MTREESNODE.
LOOP AT GT_ROOT WHERE LAYOUT = 1.
NODE-NODE_KEY = GT_ROOT-ZID . “#EC NOTEXT
NODE-ISFOLDER = ‘X’.
NODE-TEXT = GT_ROOT-ZNAME.
APPEND NODE TO NODE_TABLE.
CLEAR NODE.
ENDLOOP. ” LOOP AT GT_ROOT
LOOP AT GT_ROOT WHERE LAYOUT = 2.
NODE-NODE_KEY = GT_ROOT-ZID . “#EC NOTEXT
NODE-RELATKEY = GT_ROOT-TOPID.
NODE-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD.
NODE-TEXT = GT_ROOT-ZNAME.
APPEND NODE TO NODE_TABLE.
CLEAR NODE.
ENDLOOP. ” LOOP AT GT_ROOT
IF 1 = 2.
* Node with key ‘Root’
NODE-NODE_KEY = ‘Root’. “#EC NOTEXT
NODE-ISFOLDER = ‘X’.
NODE-TEXT = ‘Root’.
APPEND NODE TO NODE_TABLE.
**********************************************************************
NODE-NODE_KEY = ‘Root2’.
NODE-TEXT = ‘Root2’.
APPEND NODE TO NODE_TABLE.
CLEAR NODE.
NODE-NODE_KEY = ‘CHILD1’. “#EC NOTEXT
NODE-RELATKEY = ‘Root’.
NODE-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD.
NODE-TEXT = ‘第1:ALV’.
APPEND NODE TO NODE_TABLE.
CLEAR NODE.
NODE-NODE_KEY = ‘CHILD2’. “#EC NOTEXT
NODE-RELATKEY = ‘Root’.
NODE-RELATSHIP = CL_GUI_SIMPLE_TREE=>RELAT_LAST_CHILD.
NODE-TEXT = ‘第2:SQL’.
APPEND NODE TO NODE_TABLE.
ENDIF.
ENDFORM. ” FORM BUILD_NODE_TABLE
*&———————————————————————*
*& Form FRM_GET_SELE
*&———————————————————————*
*&当前选选中的内容。
*&———————————————————————*
FORM FRM_GET_SELE TABLES LT_TEXT.
DATA: L_FROM TYPE I,
L_TO TYPE I,
L_FROM_NEW TYPE I,
L_TO_NEW TYPE I,
L_FROM_LINE TYPE I,
L_TO_LINE TYPE I,
L_LEN TYPE I,
LV_LINES TYPE I,
LV_MIDDLE_STRING TYPE STRING,
LT_TEXT_TEMP TYPE SOURCE_TABLE,
LV_FROM_COPY TYPE I.
PERFORM FRM_GET_ALL_CODE TABLES LT_TEXT[]
CHANGING L_FROM_LINE L_FROM L_TO_LINE L_TO.
IF L_FROM_LINE = L_TO_LINE AND L_FROM = L_TO.
CLEAR LT_TEXT[].
RETURN.
ENDIF.
L_TO_LINE = L_TO_LINE + 1.
DELETE LT_TEXT FROM L_TO_LINE TO 9999999.
L_FROM_LINE = L_FROM_LINE – 1.
IF L_FROM_LINE > 0.
DELETE LT_TEXT FROM 1 TO L_FROM_LINE.
ENDIF.
* 处理列。
IF L_FROM_LINE = 0 AND L_FROM = 1. “全选按钮
ELSE.
DATA LV_C TYPE C LENGTH 1000.
L_FROM = L_FROM – 1.
DATA LWA_TEXT TYPE SOLI.
LOOP AT LT_TEXT INTO LWA_TEXT.
LV_C = LWA_TEXT-LINE.
LV_C+L_TO(300) = ”.
IF L_FROM > 0.
LV_C+0(L_FROM) = ”.
ENDIF.
LWA_TEXT-LINE = LV_C.
MODIFY LT_TEXT FROM LWA_TEXT.
ENDLOOP. ” LOOP AT LT_TEXT
ENDIF.
ENDFORM. ” FORM FRM_GET_SELE
*&———————————————————————*
*& Form FRM_SAVE
*&———————————————————————*
*& 保存。
*&———————————————————————*
FORM FRM_SAVE .
CALL METHOD GO_EDITOR->GET_TEXT( IMPORTING TABLE = GT_PROGRAM ).
INSERT REPORT P_BOR FROM GT_PROGRAM.
IF SY-SUBRC = 0.
MESSAGE ‘Object saved successfully’ TYPE ‘S’.
ENDIF.
ENDFORM. ” FORM FRM_SAVE
*&———————————————————————*
*& Form frm_pattern
*&———————————————————————*
*& 调用pattern。
*&———————————————————————*
FORM FRM_PATTERN .
DATA: L_FROM TYPE I,
##NEEDED L_TO TYPE I,
L_FROM_NEW TYPE I,
L_TO_NEW TYPE I,
L_FROM_LINE TYPE I,
##NEEDED L_TO_LINE TYPE I,
L_LEN TYPE I,
LV_LINES TYPE I,
LV_MIDDLE_STRING TYPE STRING,
LT_TEXT TYPE RSWSOURCET,
LT_TEXT_TEMP TYPE RSWSOURCET .
IF GV_READ_ONLY IS NOT INITIAL.
MESSAGE S398(00) WITH ‘Please Set Code In 【Edit】 Status’.
RETURN.
ENDIF.
CLEAR GO_WB_EDITOR->BUFFER.
GO_WB_EDITOR->EXECUTE_FUNCTION( CHANGING FCODE = OK_CODE ).
IF NOT GO_WB_EDITOR->BUFFER[] IS INITIAL.
**********************************************************************
DATA LWA_rswsourcet LIKE LINE OF LT_TEXT.
LOOP AT GO_WB_EDITOR->BUFFER[] INTO LWA_rswsourcet.
SHIFT LWA_rswsourcet LEFT DELETING LEADING ‘* ‘.
MODIFY GO_WB_EDITOR->BUFFER[] FROM LWA_rswsourcet.
ENDLOOP. ” LOOP AT GO_WB_EDITOR->BUFFER[]
CALL METHOD GO_EDITOR->GET_SELECTION_POS
IMPORTING
FROM_LINE = L_FROM_LINE
FROM_POS = L_FROM
TO_LINE = L_TO_LINE
TO_POS = L_TO
EXCEPTIONS
ERROR_CNTL_CALL_METHOD = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
IF SY-MSGNO IS NOT INITIAL.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO DISPLAY LIKE ‘I’
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4 .
ENDIF.
ENDIF.
CALL METHOD GO_EDITOR->GET_TEXT
IMPORTING
TABLE = LT_TEXT[]
EXCEPTIONS
OTHERS = 1.
IF SY-SUBRC = 1.
RETURN.
ENDIF.
LT_TEXT_TEMP[] = LT_TEXT[].
* 5.
L_FROM_LINE = L_FROM_LINE + 1.
DELETE LT_TEXT_TEMP[] FROM L_FROM_LINE TO 99999. “6-LAST 保留1-5.
L_FROM_LINE = L_FROM_LINE – 1.
DELETE LT_TEXT[] FROM 1 TO L_FROM_LINE. “保留6-最后。
APPEND LINES OF GO_WB_EDITOR->BUFFER[] TO LT_TEXT_TEMP[].
APPEND LINES OF LT_TEXT[] TO LT_TEXT_TEMP[].
CALL METHOD GO_EDITOR->SET_TEXT
EXPORTING
TABLE = LT_TEXT_TEMP[]
EXCEPTIONS
ERROR_DP = 1
ERROR_DP_CREATE = 2
ERROR_CODE_PAGE = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
BREAK-POINT.
ENDIF.
ENDIF.
ENDFORM. ” FORM FRM_PATTERN
FORM SET_REGISTERED_EVENTS_RIGHT .
* define local data
DATA:
LT_EVENTS TYPE CNTL_SIMPLE_EVENTS,
LS_EVENT TYPE CNTL_SIMPLE_EVENT.
LS_EVENT-EVENTID = CL_GUI_ABAPEDIT=>EVENT_CONTEXT_MENU. APPEND LS_EVENT TO LT_EVENTS.
LS_EVENT-EVENTID = CL_GUI_ABAPEDIT=>EVENT_CONTEXT_MENU_SELECTED. APPEND LS_EVENT TO LT_EVENTS.
LS_EVENT-EVENTID = CL_GUI_ABAPEDIT=>EVENT_DOUBLE_CLICK. APPEND LS_EVENT TO LT_EVENTS.
LS_EVENT-EVENTID = CL_GUI_ABAPEDIT=>EVENT_BORDER_CLICK. APPEND LS_EVENT TO LT_EVENTS.
LS_EVENT-EVENTID = CL_GUI_ABAPEDIT=>EVENT_BREAKPOINT_CHANGED. APPEND LS_EVENT TO LT_EVENTS.
CALL METHOD GO_EDITOR->SET_REGISTERED_EVENTS
EXPORTING
EVENTS = LT_EVENTS
EXCEPTIONS
CNTL_ERROR = 1
CNTL_SYSTEM_ERROR = 2
ILLEGAL_EVENT_COMBINATION = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
SET HANDLER:
LCL_code_EVENTHANDLER=>HANDLE_code_CONTEXT_MENU FOR GO_EDITOR,
LCL_code_EVENTHANDLER=>HANDLE_code_CTXMENU_SELECTED FOR GO_EDITOR,
LCL_code_EVENTHANDLER=>HANDLE_code_BORDER_CLICK FOR GO_EDITOR,
LCL_code_EVENTHANDLER=>HANDLE_CODE_BP_CHG FOR GO_EDITOR,
LCL_code_EVENTHANDLER=>HANDLE_code_dbclick FOR GO_EDITOR.
ENDFORM. ” FORM SET_REGISTERED_EVENTS_RIGHT
*&———————————————————————*
*& Form frm_f4
*&———————————————————————*
*& Prog Help.
*&———————————————————————*
FORM FRM_F4 .
TYPES:BEGIN OF LTY_REP,
PROGNAME TYPE REPOSRC-PROGNAME, ” ABAP Program Name
UDAT TYPE REPOSRC-UDAT, ” Changed On
CNAM TYPE REPOSRC-CNAM, ” Author
CDAT TYPE REPOSRC-CDAT, ” Created On
END OF LTY_REP.
DATA LT_REP TYPE STANDARD TABLE OF LTY_REP.
SELECT PROGNAME UDAT CNAM CDAT
FROM REPOSRC
INTO CORRESPONDING FIELDS OF TABLE LT_REP
UP TO 200 ROWS
WHERE ( PROGNAME LIKE ‘Z%’ OR PROGNAME LIKE ‘Y%’ )
AND UNAM = SY-UNAME
ORDER BY UDAT DESCENDING.
.
DATA: LT_RETURN TYPE TABLE OF DDSHRETVAL.
CALL FUNCTION ‘F4IF_INT_TABLE_VALUE_REQUEST’
EXPORTING
RETFIELD = ‘PROGNAME’ “指定要返回内表的哪个field的vlaue(本例是ITAB_CARRID-CARRNAME)
VALUE_ORG = ‘S’ “S代表structure
DYNPPROG = GV_REPID “指定屏幕参数所在的程序名称
DYNPNR = SY-DYNNR “指定参数所在的屏幕编号
DYNPROFIELD = ‘P_BOR’ “指定屏幕参数的名称(如果有fieldname可以直接使用,不必通过LT_RETURN获取值)
TABLES
VALUE_TAB = LT_REP[] “内表
RETURN_TAB = LT_RETURN
EXCEPTIONS
PARAMETER_ERROR = 1
NO_VALUES_FOUND = 2
OTHERS = 3.
IF SY-SUBRC = 0.
* READ TABLE lt_return INTO ls_return INDEX 1.
* P_BOR = ls_return-fieldval.
ENDIF.
ENDFORM. ” FORM FRM_F4
*&———————————————————————*
*& Form FRM_GET_ALL_CODE
*&———————————————————————*
*& 获取所有代码文本。
*&———————————————————————*
FORM FRM_GET_ALL_CODE TABLES LT_TEXT
CHANGING CV_FROM_LINE
CV_FROM
CV_TO_LINE
CV_TO.
CALL METHOD GO_EDITOR->GET_SELECTION_POS
IMPORTING
FROM_LINE = CV_FROM_LINE
FROM_POS = CV_FROM
TO_LINE = CV_TO_LINE
TO_POS = CV_TO
EXCEPTIONS
ERROR_CNTL_CALL_METHOD = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
BREAK-POINT.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO DISPLAY LIKE ‘I’
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4 .
ENDIF.
CALL METHOD GO_EDITOR->GET_TEXT
IMPORTING
TABLE = LT_TEXT[]
EXCEPTIONS
*abaped potential_data_loss = 1.
OTHERS = 1.
IF SY-SUBRC <> 0.
BREAK-POINT.
ENDIF.
ENDFORM. ” FORM FRM_GET_ALL_CODE
*&———————————————————————*
*& Form FRM_OKCODE_PRET_PRT
*&———————————————————————*
*&
*&———————————————————————*
FORM FRM_PRET_PRT .
DATA: L_FROM TYPE I,
L_TO TYPE I,
L_FROM_NEW TYPE I,
L_TO_NEW TYPE I,
L_FROM_LINE TYPE I,
L_TO_LINE TYPE I.
CALL METHOD GO_EDITOR->GET_FIRST_VISIBLE_LINE( IMPORTING LINE = LV_LINE ).
GO_WB_EDITOR->EXECUTE_FUNCTION( CHANGING FCODE = OK_CODE ).
CLEAR MTAB_OLD_PROG[].
CLEAR MTAB_JNC_PROG[].
CLEAR MTAB_NEW_PROG[].
CLEAR MTAB_LONG_LINE[].
CLEAR MTAB_OLD_PROG.
CLEAR MTAB_JNC_PROG.
CLEAR MTAB_NEW_PROG.
CLEAR MTAB_LONG_LINE.
* 获取所有代码
PERFORM FRM_GET_ALL_CODE TABLES MTAB_OLD_PROG[]
CHANGING L_FROM_LINE L_FROM L_TO_LINE L_TO.
PERFORM CREATE_CONDENSED_TABLE TABLES MTAB_OLD_PROG[] MTAB_LONG_LINE.
PERFORM FORMAT_PROGRAM.
CALL FUNCTION `PRETTY_PRINTER`
EXPORTING
INCTOO = SPACE
TABLES
NTEXT = MTAB_JNC_PROG
OTEXT = MTAB_NEW_PROG
EXCEPTIONS
ENQUEUE_TABLE_FULL = 1
INCLUDE_ENQUEUED = 2
INCLUDE_READERROR = 3
INCLUDE_WRITEERROR = 4
OTHERS = 5.
* 自动对齐
PERFORM FRM_PRETY_PRINT TABLES MTAB_JNC_PROG[] .
* 设置美化过的代码到编辑器
CALL METHOD GO_EDITOR->SET_TEXT
EXPORTING
TABLE = MTAB_JNC_PROG[]
EXCEPTIONS
ERROR_DP = 1
ERROR_DP_CREATE = 2
ERROR_CODE_PAGE = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
BREAK-POINT.
ENDIF.
GO_EDITOR->SET_FIRST_VISIBLE_LINE( LV_LINE ).
ENDFORM. ” FORM FRM_PRET_PRT
*———————————————————————*
* FORM CREATE_CONDENSED_TABLE *
*———————————————————————*
* Create a table that has all statements condensed onto 1 line *
*———————————————————————*
FORM CREATE_CONDENSED_TABLE
TABLES FTAB_OLD_PROG STRUCTURE MTAB_OLD_PROG
FTAB_LONG_LINE STRUCTURE MTAB_LONG_LINE.
DATA:
* Structure to hold program code/comment
BEGIN OF FSTR_LINE,
CODE(172) TYPE C, ” Program Code
COMMENT(172) TYPE C, ” Inline comments
END OF FSTR_LINE.
CLEAR FTAB_LONG_LINE[].
LOOP AT FTAB_OLD_PROG.
IF FTAB_LONG_LINE-START = 0.
FTAB_LONG_LINE-START = FTAB_LONG_LINE-END + 1.
CLEAR FTAB_LONG_LINE-END.
ENDIF.
* Strip off any inline comments so they do not get in the way
* If comments are not separated, then words in the comments could
* look like keywords, and cause problems
SPLIT FTAB_OLD_PROG-LINE AT ` “` INTO FSTR_LINE-CODE FSTR_LINE-COMMENT.
* Align all statements to be left justified
SHIFT FSTR_LINE-CODE LEFT DELETING LEADING SPACE.
* Put all lines that make up a single statement into one field
* This will make it easier to isolate key words. For example, if you
* want to process a TABLES statement, but exclude the TABLES part of a
* function call, or a subroutine call.
CONCATENATE FTAB_LONG_LINE-CODE FSTR_LINE-CODE
INTO FTAB_LONG_LINE-CODE SEPARATED BY SPACE.
IF FSTR_LINE-CODE CA `.` OR ” Period means end of statement
FSTR_LINE-CODE(1) = `*` OR ” Comment Line
FSTR_LINE-CODE CO SPACE. ” Blank Line
* Keep track of the table index that the statement ends on
FTAB_LONG_LINE-END = SY-TABIX.
* Remove delimiter from concatenation of fields
SHIFT FTAB_LONG_LINE-CODE LEFT BY 1 PLACES.
APPEND FTAB_LONG_LINE.
CLEAR: FTAB_LONG_LINE-CODE, FTAB_LONG_LINE-START.
* Don`t clear out fstr_long_line-end yet. It is used to calc
* fstr_long_line-start.
ELSE.
* FTAB_LONG_LINE-START = 1.
* FTAB_LONG_LINE-END = 1.
* FTAB_LONG_LINE-CODE = FTAB_OLD_PROG.
* APPEND FTAB_LONG_LINE.
* CLEAR FTAB_LONG_LINE.
ENDIF.
ENDLOOP. ” LOOP AT FTAB_OLD_PROG
ENDFORM. ” FORM CREATE_CONDENSED_TABLE
*———————————————————————*
* FORM FORMAT_PROGRAM *
*———————————————————————*
FORM FORMAT_PROGRAM.
DATA: LSTR_OLD_PROG LIKE LINE OF MTAB_OLD_PROG.
CLEAR MTAB_NEW_PROG[].
CLEAR MTAB_ITAB_NAMES[].
CLEAR MTAB_FORM_NAMES[].
CLEAR MTAB_ITAB_NAMES[].
CLEAR MTAB_TABNAME[].
LOOP AT MTAB_LONG_LINE.
TRANSLATE MTAB_LONG_LINE-CODE TO UPPER CASE.
IF MTAB_LONG_LINE-CODE(1) EQ `*`. ” Do not modify Comment Lines
LOOP AT MTAB_OLD_PROG FROM MTAB_LONG_LINE-START
TO MTAB_LONG_LINE-END.
MTAB_NEW_PROG-LINE = MTAB_OLD_PROG-LINE.
APPEND MTAB_NEW_PROG.
ENDLOOP. ” LOOP AT MTAB_OLD_PROG
ELSEIF MTAB_LONG_LINE-CODE(6) EQ `TABLES`.
* Reformat any TABLES statements. Will only reformat when TABLES
* is at the start of the statement. Will not try to get table
* descriptions for CALL FUNCTIONS or FORM/PERFORMs
* Get the table names from mstr_long_line.
PERFORM GET_TABLE_NAMES_FROM_STATEMENT TABLES MTAB_TABNAME
USING MTAB_LONG_LINE-CODE.
* Find the descriptions for each table
PERFORM GET_TABLE_DESCRIPTIONS TABLES MTAB_TABNAME.
* create the new statement
PERFORM BUILD_NEW_TABLES_STATEMENT USING MTAB_LONG_LINE.
ELSE. ” All other modifications to the code handled here
LOOP AT MTAB_OLD_PROG FROM MTAB_LONG_LINE-START
TO MTAB_LONG_LINE-END.
* Remove extra spaces from line for comparisons
LSTR_OLD_PROG-LINE = MTAB_OLD_PROG-LINE.
CONDENSE LSTR_OLD_PROG-LINE.
TRANSLATE LSTR_OLD_PROG-LINE TO UPPER CASE.
IF LSTR_OLD_PROG-LINE CS ` “`. ” Comments
MTAB_NEW_PROG-LINE = MTAB_OLD_PROG-LINE.
ELSE.
IF LSTR_OLD_PROG-LINE CS ` LIKE ` OR
LSTR_OLD_PROG-LINE CS ` TYPE ` OR
LSTR_OLD_PROG-LINE CS ` FOR ` OR
LSTR_OLD_PROG-LINE CS `~`. “jnc OpenSQL table~column
PERFORM GET_FOR_LIKE_COMMENT USING MTAB_OLD_PROG
CHANGING MTAB_NEW_PROG.
ELSEIF LSTR_OLD_PROG-LINE(8) = ‘LOOP AT’.
* save table name into a queue
PERFORM ENQUEUE_ITAB_NAME USING MTAB_LONG_LINE-CODE.
MTAB_NEW_PROG-LINE = MTAB_OLD_PROG-LINE.
ELSEIF LSTR_OLD_PROG-LINE(7) = `ENDLOOP`.
* get name off of queue and add it as a comment to the ENDLOOP line
PERFORM ADD_COMMENT_TO_ENDLOOP USING MTAB_OLD_PROG-LINE
CHANGING MTAB_NEW_PROG-LINE.
ELSEIF LSTR_OLD_PROG-LINE(7) EQ ‘SELECT’ AND
LSTR_OLD_PROG-LINE(13) NE ‘SELECT SINGLE’.
* save table name into a queue
PERFORM ENQUEUE_TAB_NAME USING MTAB_OLD_PROG-LINE.
MTAB_NEW_PROG-LINE = MTAB_OLD_PROG-LINE.
ELSEIF LSTR_OLD_PROG-LINE(9) = `ENDSELECT`.
* get name off of queue and add it as a comment to the ENDSELECT
PERFORM ADD_COMMENT_TO_SELECT USING MTAB_OLD_PROG-LINE
CHANGING MTAB_NEW_PROG-LINE.
ELSEIF LSTR_OLD_PROG-LINE(5) = ‘FORM’.
* save form name into a queue
PERFORM ENQUEUE_FORM_NAME USING MTAB_OLD_PROG-LINE.
MTAB_NEW_PROG-LINE = MTAB_OLD_PROG-LINE.
ELSEIF LSTR_OLD_PROG-LINE(7) = `ENDFORM`.
* get name off of queue and add it as a comment to the ENDFORM
PERFORM ADD_COMMENT_TO_ENDFORM USING MTAB_OLD_PROG-LINE
CHANGING MTAB_NEW_PROG-LINE.
ELSE. ” Any other lines
MTAB_NEW_PROG-LINE = MTAB_OLD_PROG-LINE.
ENDIF.
ENDIF.
APPEND MTAB_NEW_PROG.
ENDLOOP. ” LOOP AT MTAB_OLD_PROG
ENDIF.
ENDLOOP. ” LOOP AT MTAB_LONG_LINE
ENDFORM. ” FORM FORMAT_PROGRAM
*———————————————————————*
* FORM GET_TABLE_NAMES_FROM_STATEMENT *
*———————————————————————*
FORM GET_TABLE_NAMES_FROM_STATEMENT TABLES FTAB_TABNAME
STRUCTURE MTAB_TABNAME
USING FC_STATEMENT.
CLEAR FTAB_TABNAME.
REFRESH FTAB_TABNAME.
REPLACE `TABLES` WITH SPACE INTO FC_STATEMENT.
TRANSLATE FC_STATEMENT USING `. `. ” Replace periods
TRANSLATE FC_STATEMENT USING `, `. ” Replace commas
TRANSLATE FC_STATEMENT USING `: `. ” Replace colons
CONDENSE FC_STATEMENT. ” Remove all extra spaces
SPLIT FC_STATEMENT AT SPACE INTO TABLE FTAB_TABNAME.
ENDFORM. ” FORM GET_TABLE_NAMES_FROM_STATEMENT
*———————————————————————*
* FORM GET_TABLE_DESCRIPTIONS *
*———————————————————————*
FORM GET_TABLE_DESCRIPTIONS TABLES FTAB_TABNAME STRUCTURE MTAB_TABNAME.
DATA LWA_DD02T TYPE DD02T.
LOOP AT FTAB_TABNAME.
CLEAR LWA_DD02T.
SELECT SINGLE * FROM DD02T
INTO CORRESPONDING FIELDS OF LWA_DD02T
WHERE TABNAME = FTAB_TABNAME-TABNAME
AND DDLANGUAGE = ‘1’ .”SY-LANGU.
IF SY-SUBRC = 0.
FTAB_TABNAME-TABDESC = LWA_DD02T-DDTEXT.
MODIFY FTAB_TABNAME.
ENDIF.
ENDLOOP. ” LOOP AT FTAB_TABNAME
ENDFORM. ” FORM GET_TABLE_DESCRIPTIONS
*———————————————————————*
* FORM BUILD_NEW_TABLES_STATEMENT *
*———————————————————————*
FORM BUILD_NEW_TABLES_STATEMENT USING FSTR_LONG_LINE LIKE MTAB_LONG_LINE.
DATA: LC_SEP(1) TYPE C,
LI_ROWS TYPE I,
WORDLEN TYPE I.
DESCRIBE TABLE MTAB_TABNAME LINES LI_ROWS.
MTAB_NEW_PROG-LINE = `TABLES:`.
APPEND MTAB_NEW_PROG.
LOOP AT MTAB_TABNAME.
IF SY-TABIX = LI_ROWS.
LC_SEP = `.`.
ELSE.
LC_SEP = `,`.
ENDIF.
WORDLEN = STRLEN( MTAB_TABNAME-TABNAME ).
IF WORDLEN < 12.
WORDLEN = 12 – WORDLEN.
ELSE.
WORDLEN = 1.
ENDIF.
CONCATENATE `^^` MTAB_TABNAME-TABNAME LC_SEP MYHATS+0(WORDLEN) ` ” `
MTAB_TABNAME-TABDESC INTO MTAB_NEW_PROG.
TRANSLATE MTAB_NEW_PROG USING `^ `.
APPEND MTAB_NEW_PROG.
ENDLOOP. ” LOOP AT MTAB_TABNAME
ENDFORM. ” FORM GET_TABLE_DESCRIPTIONS
*———————————————————————*
* FORM GET_FOR/LIKE_COMMENT *
*———————————————————————*
FORM GET_FOR_LIKE_COMMENT USING VALUE(F_OLD_PROG) LIKE MTAB_OLD_PROG
CHANGING F_NEW_PROG LIKE MTAB_NEW_PROG
.
DATA:
LC_DUMMY(1) TYPE C,
LC_TABNAME(40) TYPE C,
WORDLEN TYPE I,
LTAB_NAMETAB LIKE DNTAB OCCURS 0 WITH HEADER LINE,
LSTR_OLD_PROG LIKE LINE OF MTAB_OLD_PROG,
BEGIN OF LSTR_FIELD,
TABNAME LIKE DD02T-TABNAME, ” Table name
FLDNAME LIKE DD02T-TABNAME, ” Table name
END OF LSTR_FIELD.
LSTR_OLD_PROG-LINE = F_OLD_PROG. ” SAVE input
TRANSLATE F_OLD_PROG TO UPPER CASE.
CONDENSE F_OLD_PROG.
IF F_OLD_PROG-LINE CA `”` OR ” Line already commented
F_OLD_PROG-LINE(1) = `*`.
F_NEW_PROG = F_OLD_PROG.
RETURN.
ELSEIF F_OLD_PROG CS ` LIKE `.
SPLIT F_OLD_PROG AT ` LIKE ` INTO LC_DUMMY LC_TABNAME.
ELSEIF F_OLD_PROG CS ` TYPE `.
SPLIT F_OLD_PROG AT ` TYPE ` INTO LC_DUMMY LC_TABNAME.
ELSEIF F_OLD_PROG CS ` FOR `.
SPLIT F_OLD_PROG AT ` FOR ` INTO LC_DUMMY LC_TABNAME.
ELSEIF F_OLD_PROG CS `~`.
MOVE F_OLD_PROG TO LC_TABNAME.
CONDENSE LC_TABNAME.
SPLIT LC_TABNAME AT `~` INTO LSTR_FIELD-TABNAME LSTR_FIELD-FLDNAME.
ELSE.
F_NEW_PROG = LSTR_OLD_PROG-LINE.
RETURN.
ENDIF.
* If there is anything following the table-field in a LIKE or FOR clause
* it will be removed so that only the table-field remains
IF NOT F_OLD_PROG CS `~`.
CONDENSE LC_TABNAME.
TRANSLATE LC_TABNAME USING `. `. ” Remove periods
TRANSLATE LC_TABNAME USING `, `. ” Remove commas
CONDENSE LC_TABNAME. ” Remove extra white space
SPLIT LC_TABNAME AT `-` INTO LSTR_FIELD-TABNAME LSTR_FIELD-FLDNAME.
* The system variables are actually defined in DDIC structure SYST
IF LSTR_FIELD-TABNAME = `SY`.
LSTR_FIELD-TABNAME = `SYST`.
ENDIF.
ENDIF.
TRANSLATE LSTR_FIELD-TABNAME TO UPPER CASE.
TRANSLATE LSTR_FIELD-FLDNAME TO UPPER CASE.
CALL FUNCTION ‘NAMETAB_GET’
EXPORTING
LANGU = SY-LANGU
TABNAME = LSTR_FIELD-TABNAME
TABLES
NAMETAB = LTAB_NAMETAB
EXCEPTIONS
INTERNAL_ERROR = 1
TABLE_HAS_NO_FIELDS = 2
TABLE_NOT_ACTIV = 3
NO_TEXTS_FOUND = 4
OTHERS = 5.
IF SY-SUBRC <> 0.
* MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
* WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
READ TABLE LTAB_NAMETAB
WITH KEY TABNAME = LSTR_FIELD-TABNAME
FIELDNAME = LSTR_FIELD-FLDNAME.
IF SY-SUBRC = 0.
WORDLEN = STRLEN( LSTR_OLD_PROG-LINE ).
IF WORDLEN < 45.
WORDLEN = 45 – WORDLEN.
ELSE.
WORDLEN = 1.
ENDIF.
CONCATENATE LSTR_OLD_PROG-LINE MYHATS+0(WORDLEN) ` ” ` LTAB_NAMETAB-FIELDTEXT
INTO F_NEW_PROG.
TRANSLATE MTAB_NEW_PROG USING `^ `.
ELSE.
F_NEW_PROG = LSTR_OLD_PROG-LINE.
ENDIF.
ENDFORM. ” FORM GET_TABLE_DESCRIPTIONS
*———————————————————————*
* FORM ENQUEUE_ITAB_NAME *
*———————————————————————*
FORM ENQUEUE_ITAB_NAME USING VALUE(F_LINE) LIKE MTAB_LONG_LINE-CODE.
DATA:
LC_DUMMY(1) TYPE C,
LC_ITAB(40) TYPE C.
TRANSLATE F_LINE TO UPPER CASE.
SPLIT F_LINE AT `LOOP AT ` INTO LC_DUMMY LC_ITAB.
SPLIT LC_ITAB AT SPACE INTO LC_ITAB LC_DUMMY.
TRANSLATE LC_ITAB USING `. `.
CONDENSE LC_ITAB.
MTAB_ITAB_NAMES = LC_ITAB.
* Always have the most recent LOOP AT table as the first entry in the
* queue
INSERT MTAB_ITAB_NAMES INDEX 1.
ENDFORM. ” FORM GET_TABLE_DESCRIPTIONS
*———————————————————————*
* FORM ADD_COMMENT_TO_ENDLOOP *
*———————————————————————*
FORM ADD_COMMENT_TO_ENDLOOP USING FSTR_LONG_LINE LIKE MTAB_OLD_PROG-LINE
CHANGING F_PROG_LINE LIKE MTAB_NEW_PROG-LINE
.
IF MTAB_OLD_PROG-LINE NA `”`. ” No comments
* Get the internal table from the queue
READ TABLE MTAB_ITAB_NAMES INDEX 1.
CONCATENATE MTAB_OLD_PROG-LINE ` “` `LOOP AT` MTAB_ITAB_NAMES-TABNAME
INTO F_PROG_LINE SEPARATED BY SPACE.
* Dequeue the itab name
DELETE MTAB_ITAB_NAMES INDEX 1.
ELSE.
F_PROG_LINE = MTAB_OLD_PROG-LINE.
ENDIF.
ENDFORM. ” FORM GET_TABLE_DESCRIPTIONS
*———————————————————————*
* FORM ENQUEUE_TAB_NAME *
*———————————————————————*
FORM ENQUEUE_TAB_NAME USING F_LINE LIKE MTAB_OLD_PROG-LINE.
DATA:
##NEEDED LC_DUMMY(1) TYPE C,
LC_TAB(40) TYPE C.
TRANSLATE F_LINE TO UPPER CASE.
SPLIT F_LINE AT ` FROM ` INTO LC_DUMMY LC_TAB.
CONDENSE LC_TAB. ” Remove leading/trailing extra spaces
SPLIT LC_TAB AT SPACE INTO LC_TAB LC_DUMMY.
TRANSLATE LC_TAB USING `. `.
CONDENSE LC_TAB.
MTAB_TAB_NAMES = LC_TAB.
* Always have the most recent LOOP AT table as the first entry in the
* queue
INSERT MTAB_TAB_NAMES INDEX 1.
ENDFORM. ” FORM GET_TABLE_DESCRIPTIONS
*———————————————————————*
* FORM ADD_COMMENT_TO_SELECT *
*———————————————————————*
FORM ADD_COMMENT_TO_SELECT USING FSTR_LONG_LINE LIKE MTAB_OLD_PROG-LINE
CHANGING F_PROG_LINE.
IF MTAB_OLD_PROG-LINE NA `”`. ” No comments
* Get the table from the queue
READ TABLE MTAB_TAB_NAMES INDEX 1.
CONCATENATE MTAB_OLD_PROG-LINE ` “` `SELECT FROM` MTAB_TAB_NAMES-TABNAME
INTO F_PROG_LINE SEPARATED BY SPACE.
* Dequeue the tab name
DELETE MTAB_TAB_NAMES INDEX 1.
ELSE.
F_PROG_LINE = MTAB_OLD_PROG-LINE.
ENDIF.
ENDFORM. ” FORM GET_TABLE_DESCRIPTIONS
*———————————————————————*
* FORM ADD_COMMENT_TO_ENDFORM *
*———————————————————————*
FORM ADD_COMMENT_TO_ENDFORM USING FSTR_LONG_LINE LIKE MTAB_OLD_PROG-LINE
CHANGING F_PROG_LINE.
IF MTAB_OLD_PROG-LINE NA `”`. ” No comments
* Get the table from the queue
READ TABLE MTAB_FORM_NAMES INDEX 1.
CONCATENATE MTAB_OLD_PROG-LINE ` “` `FORM` MTAB_FORM_NAMES-TABNAME
INTO F_PROG_LINE SEPARATED BY SPACE.
* Dequeue the form name
DELETE MTAB_FORM_NAMES INDEX 1.
ELSE.
F_PROG_LINE = MTAB_OLD_PROG-LINE.
ENDIF.
ENDFORM. ” FORM GET_TABLE_DESCRIPTIONS
*———————————————————————*
* FORM ENQUEUE_FORM_NAME *
*———————————————————————*
FORM ENQUEUE_FORM_NAME USING F_LINE.
DATA:
LC_DUMMY(1) TYPE C,
LC_TAB(40) TYPE C.
TRANSLATE F_LINE TO UPPER CASE.
SPLIT F_LINE AT `FORM ` INTO LC_DUMMY
LC_TAB.
CONDENSE LC_TAB. ” Remove leading/trailing extra spaces
SPLIT LC_TAB AT SPACE INTO LC_TAB LC_DUMMY.
TRANSLATE LC_TAB USING `. `.
CONDENSE LC_TAB.
MTAB_FORM_NAMES = LC_TAB.
* Always have the most recent LOOP AT table as the first entry in the
* queue
INSERT MTAB_FORM_NAMES INDEX 1.
ENDFORM. ” FORM ENQUEUE_FORM_NAME
*&———————————————————————*
*& Form FRM_ADD_COMMENT4FIELDS
*&———————————————————————*
*& 添加注释。
*&———————————————————————*
FORM FRM_ADD_COMMENT4FIELDS .
PERFORM CREATE_CONDENSED_TABLE TABLES MTAB_OLD_PROG[] MTAB_LONG_LINE.
PERFORM FORMAT_PROGRAM.
CALL FUNCTION `PRETTY_PRINTER`
EXPORTING
INCTOO = SPACE
TABLES
NTEXT = MTAB_JNC_PROG
OTEXT = MTAB_NEW_PROG
EXCEPTIONS
ENQUEUE_TABLE_FULL = 1
INCLUDE_ENQUEUED = 2
INCLUDE_READERROR = 3
INCLUDE_WRITEERROR = 4
OTHERS = 5.
PERFORM FRM_PRETY_PRINT TABLES MTAB_NEW_PROG[] .
ENDFORM. ” FORM FRM_ADD_COMMENT4FIELDS
FORM FRM_PRETY_PRINT TABLES CT_SOURCE.
DATA:
LV_COPY_LEN TYPE I,
LV_POS TYPE I,
LV_TO_POS TYPE I,
LV_LINE_PART1 TYPE STRING,
LV_LINE_PART2 TYPE STRING,
LV_LINE_CHAR TYPE CHAR256,
LV_POS_DIFF TYPE I,
LV_POS_DIFF_PREV TYPE I,
LV_LAST_ROW TYPE I,
LV_STRING TYPE STRING, “txh01
LV_TABIX TYPE SYTABIX,
LV_CHAINED_STM_COUNTER TYPE I,
LV_SKIP_FIRST_TOKEN TYPE FLAG.
FIELD-SYMBOLS: <LS_STM> LIKE LINE OF GT_STM,
<LV_LINE> TYPE ANY, “txh01
<LS_TOKEN> LIKE LINE OF GT_TOKENS,
<LS_TOKENS_MOD> LIKE LINE OF GT_TOKENS,
<LS_BLOCKS> LIKE LINE OF GT_BLOCKS.
CLEAR GV_INSIDE_BEGINOF.
CLEAR GV_LAST_LINE_FROM.
CLEAR GV_BEGINOF_COL.
CLEAR MTAB_OLD_PROG[].
CLEAR GT_KEYWORDS[].
IF GT_KEYWORDS IS INITIAL.
PERFORM ADD_KEYWORDS.
ENDIF.
CLEAR GT_TOKENS[].
CLEAR GT_STM[].
CLEAR GT_BLOCKS[].
SCAN ABAP-SOURCE CT_SOURCE
TOKENS INTO GT_TOKENS
STATEMENTS INTO GT_STM
KEYWORDS FROM GT_KEYWORDS
WITH ANALYSIS.
IF GS_USER-ALIGN_DECL EQ ‘X’.
PERFORM IDENTIFY_BLOCKS.
LOOP AT GT_BLOCKS ASSIGNING <LS_BLOCKS>.
CLEAR: LV_LINE_PART1, LV_LINE_PART2, LV_CHAINED_STM_COUNTER.
* get first statement of block
LOOP AT GT_STM ASSIGNING <LS_STM> FROM <LS_BLOCKS>-FROM TO <LS_BLOCKS>-TO.
ADD 1 TO LV_CHAINED_STM_COUNTER.
* check if token is really there (chained statements)
IF <LS_STM>-COLONCOL GT 0.
LV_SKIP_FIRST_TOKEN = ‘X’.
ELSE.
CLEAR: LV_SKIP_FIRST_TOKEN.
ENDIF.
CLEAR: LV_POS_DIFF_PREV, LV_LAST_ROW.
LOOP AT GT_TOKENS ASSIGNING <LS_TOKEN> FROM <LS_STM>-FROM TO <LS_STM>-TO.
LV_TABIX = SY-TABIX – <LS_STM>-FROM + 1.
IF ( LV_SKIP_FIRST_TOKEN EQ ‘X’ AND LV_TABIX EQ 1 ) AND ( LV_CHAINED_STM_COUNTER NE 1 ).
CONTINUE.
ENDIF.
CHECK LV_TABIX LT 4.
READ TABLE CT_SOURCE ASSIGNING <LV_LINE> INDEX <LS_TOKEN>-ROW.
CHECK SY-SUBRC EQ 0.
LV_STRING = <LV_LINE>. “txh01
IF <LS_TOKEN>-ROW EQ LV_LAST_ROW.
ADD LV_POS_DIFF_PREV TO <LS_TOKEN>-COL.
ENDIF.
CASE LV_TABIX.
WHEN 1.
LV_POS_DIFF = <LS_BLOCKS>-POS1 – <LS_TOKEN>-COL.
WHEN 2.
LV_POS_DIFF = <LS_BLOCKS>-POS2 – <LS_TOKEN>-COL.
WHEN 3.
LV_POS_DIFF = <LS_BLOCKS>-POS3 – <LS_TOKEN>-COL.
WHEN 4.
CHECK <LS_BLOCKS>-POS4 NE 0.
LV_POS_DIFF = <LS_BLOCKS>-POS4 – <LS_TOKEN>-COL.
ENDCASE.
IF LV_POS_DIFF NE 0.
LV_LINE_PART1 = LV_STRING(<LS_TOKEN>-COL). “txh01
LV_LINE_PART2 = LV_STRING+<LS_TOKEN>-COL. “txh01
IF LV_POS_DIFF GT 0.
SHIFT LV_LINE_PART2 BY LV_POS_DIFF PLACES RIGHT.
ELSE.
LV_COPY_LEN = <LS_TOKEN>-COL + LV_POS_DIFF.
LV_LINE_PART1 = LV_LINE_PART1(LV_COPY_LEN).
ENDIF.
CONCATENATE LV_LINE_PART1 LV_LINE_PART2 INTO LV_STRING. “txh01
<LV_LINE> = LV_STRING. “txh01
CASE LV_TABIX.
WHEN 1.
<LS_TOKEN>-COL = <LS_BLOCKS>-POS1.
WHEN 2.
<LS_TOKEN>-COL = <LS_BLOCKS>-POS2.
WHEN 3.
<LS_TOKEN>-COL = <LS_BLOCKS>-POS3.
WHEN 4.
<LS_TOKEN>-COL = <LS_BLOCKS>-POS4.
ENDCASE.
ENDIF.
LV_POS_DIFF_PREV = LV_POS_DIFF_PREV + LV_POS_DIFF.
LV_LAST_ROW = <LS_TOKEN>-ROW.
ENDLOOP. ” LOOP AT GT_TOKENS
IF STRLEN( LV_STRING ) GE <LS_BLOCKS>-POS3. “txh01
LV_LINE_PART1 = LV_STRING(<LS_BLOCKS>-POS3). “txh01
LV_LINE_PART2 = LV_STRING+<LS_BLOCKS>-POS3. “txh01
CONDENSE LV_LINE_PART2.
CONCATENATE LV_LINE_PART1 LV_LINE_PART2 INTO LV_STRING. “txh01
<LV_LINE> = LV_STRING. “txh01
ENDIF.
ENDLOOP. ” LOOP AT GT_STM
ENDLOOP. ” LOOP AT GT_BLOCKS
* process begin of – end of
CLEAR: GV_INSIDE_BEGINOF, GV_LAST_LINE_FROM.
LOOP AT GT_STM ASSIGNING <LS_STM>.
PERFORM UPDATE_BEGINOF_STATUS_STM USING <LS_STM>.
LOOP AT GT_TOKENS ASSIGNING <LS_TOKEN> FROM <LS_STM>-FROM TO <LS_STM>-TO.
DATA LV_1ST_TOKEN LIKE <LS_TOKEN>-STR.
LV_TABIX = SY-TABIX – <LS_STM>-FROM + 1.
READ TABLE CT_SOURCE ASSIGNING <LV_LINE> INDEX <LS_TOKEN>-ROW.
CHECK SY-SUBRC EQ 0.
LV_STRING = <LV_LINE>. “txh01
IF LV_TABIX EQ 1.
LV_1ST_TOKEN = <LS_TOKEN>-STR.
ELSEIF LV_TABIX EQ 2 AND <LS_TOKEN>-STR EQ ‘END’ AND LV_1ST_TOKEN NE ‘SELECTION-SCREEN’.
LV_POS_DIFF = GV_BEGINOF_COL – <LS_TOKEN>-COL.
IF LV_POS_DIFF NE 0.
LV_LINE_PART1 = LV_STRING(<LS_TOKEN>-COL). “txh01
LV_LINE_PART2 = LV_STRING+<LS_TOKEN>-COL. “txh01
IF LV_POS_DIFF GT 0.
SHIFT LV_LINE_PART2 BY LV_POS_DIFF PLACES RIGHT.
ELSE.
LV_COPY_LEN = <LS_TOKEN>-COL + LV_POS_DIFF.
LV_LINE_PART1 = LV_LINE_PART1(LV_COPY_LEN).
ENDIF.
CONCATENATE LV_LINE_PART1 LV_LINE_PART2 INTO LV_STRING. “txh01
<LV_LINE> = LV_STRING. “txh01
ADD LV_POS_DIFF TO <LS_TOKEN>-COL.
LOOP AT GT_TOKENS ASSIGNING <LS_TOKENS_MOD> WHERE ROW EQ <LS_TOKEN>-ROW AND COL GT <LS_TOKEN>-COL.
ADD LV_POS_DIFF TO <LS_TOKENS_MOD>-COL.
ENDLOOP. ” LOOP AT GT_TOKENS
ENDIF.
EXIT.
ENDIF.
ENDLOOP. ” LOOP AT GT_TOKENS
ENDLOOP. ” LOOP AT GT_STM
ENDIF.
* adjust ” comments
IF GS_USER-ALIGN_COMMENTS EQ ‘X’.
LOOP AT CT_SOURCE ASSIGNING <LV_LINE>. “txh01 WHERE table_line CS ‘”‘.
CHECK <LV_LINE> CS ‘”‘.
CHECK <LV_LINE>(1) NE ‘*’.
LV_STRING = <LV_LINE>. “txh01
PERFORM GET_COMMENT_POS USING LV_STRING CHANGING LV_POS. “txh01
IF LV_POS GT GS_USER-MIN_POS OR GS_USER-MIN_POS IS INITIAL.
IF LV_POS GT GS_USER-MOVE_TO_POS.
LV_TO_POS = LV_POS + 1.
ELSE.
LV_TO_POS = GS_USER-MOVE_TO_POS.
ENDIF.
LV_POS_DIFF = LV_TO_POS – LV_POS.
IF LV_POS GT 1.
SUBTRACT 1 FROM LV_POS.
ENDIF.
LV_LINE_PART1 = LV_STRING(LV_POS). “txh01
LV_LINE_PART2 = LV_STRING+LV_POS. “txh01
IF LV_POS_DIFF GT 0.
DATA LV_C TYPE C LENGTH 1.
LV_C = LV_LINE_PART2.
IF LV_POS_DIFF = ‘1’ AND LV_C = `”`.
ELSE.
SHIFT LV_LINE_PART2 BY LV_POS_DIFF PLACES RIGHT.
ENDIF.
ELSE.
LV_COPY_LEN = LV_POS + LV_POS_DIFF.
LV_LINE_PART1 = LV_LINE_PART1(LV_COPY_LEN).
ENDIF.
CONCATENATE LV_LINE_PART1 LV_LINE_PART2 INTO LV_STRING. “txh01
<LV_LINE> = LV_STRING. “txh01
ENDIF.
ENDLOOP. ” LOOP AT MTAB_TABNAME
ENDIF.
ENDFORM. ” FORM FRM_PRETY_PRINT
FORM IDENTIFY_BLOCKS.
DATA: LS_BLOCKS LIKE LINE OF GT_BLOCKS.
DATA: LV_LAST_STM_TYPE TYPE STRING.
DATA: LV_CURR_STM_TYPE TYPE STRING,
LV_TABIX TYPE I,
LV_TABIX_STM TYPE I,
LV_PREV_STM_ROW TYPE I,
LV_SKIP TYPE FLAG,
LV_CHAINED_STM TYPE FLAG,
LV_ROW TYPE I,
LV_MAX_2ND_TOKEN_LEN TYPE I,
LV_MAX_1ST_TOKEN_LEN TYPE I,
LV_ROWID TYPE I.
FIELD-SYMBOLS: <LS_TOKENS> LIKE LINE OF GT_TOKENS,
<LS_STM> LIKE LINE OF GT_STM.
CLEAR GT_BLOCKS.
DELETE ADJACENT DUPLICATES FROM GT_STM COMPARING COLONROW TROW.
LOOP AT GT_STM ASSIGNING <LS_STM>.
LV_TABIX_STM = SY-TABIX.
PERFORM DETERMINE_STM_TYPE USING <LS_STM>-FROM <LS_STM>-TO CHANGING LV_CURR_STM_TYPE LV_ROW.
LV_ROWID = LV_ROW – 1.
* blokk kezdodhet/vegzodhet
IF LV_CURR_STM_TYPE NE LV_LAST_STM_TYPE OR ( LV_PREV_STM_ROW NE LV_ROWID ).
* ha tobb mint egysoros a blokk
IF ( LS_BLOCKS-FROM NE LS_BLOCKS-TO ).
LS_BLOCKS-TYPE = LV_LAST_STM_TYPE.
APPEND LS_BLOCKS TO GT_BLOCKS.
ENDIF.
CLEAR LS_BLOCKS.
LS_BLOCKS-FROM = LS_BLOCKS-TO = LV_TABIX_STM.
ELSEIF LV_CURR_STM_TYPE EQ LV_LAST_STM_TYPE.
ADD 1 TO LS_BLOCKS-TO.
ENDIF.
LV_LAST_STM_TYPE = LV_CURR_STM_TYPE.
LV_PREV_STM_ROW = LV_ROW.
ENDLOOP. ” LOOP AT GT_STM
* utolso rekord
IF ( LS_BLOCKS-FROM NE LS_BLOCKS-TO ).
LS_BLOCKS-TYPE = LV_LAST_STM_TYPE.
APPEND LS_BLOCKS TO GT_BLOCKS.
ENDIF.
DELETE GT_BLOCKS WHERE TYPE IS INITIAL.
* calculate positions
DATA: LV_TABIX_BLOCK TYPE I,
LV_LAST_STM TYPE FLAG,
LV_LINES_STM TYPE I,
LV_LINES_TK TYPE I,
LV_LEN TYPE I.
LOOP AT GT_BLOCKS INTO LS_BLOCKS.
LV_TABIX_BLOCK = SY-TABIX.
CLEAR: LV_MAX_2ND_TOKEN_LEN, LV_MAX_1ST_TOKEN_LEN, LV_LAST_STM.
* get longest token
LOOP AT GT_STM ASSIGNING <LS_STM> FROM LS_BLOCKS-FROM TO LS_BLOCKS-TO.
LV_TABIX_STM = SY-TABIX – LS_BLOCKS-FROM + 1.
LV_LINES_STM = LS_BLOCKS-TO – LS_BLOCKS-FROM.
IF LV_TABIX_STM EQ LV_LINES_STM.
LV_LAST_STM = ‘X’.
ENDIF.
LOOP AT GT_TOKENS ASSIGNING <LS_TOKENS> FROM <LS_STM>-FROM TO <LS_STM>-TO.
LV_TABIX = SY-TABIX – <LS_STM>-FROM + 1.
LV_LINES_TK = <LS_STM>-TO – <LS_STM>-FROM.
IF LV_TABIX_STM EQ 1 AND LV_TABIX EQ 1.
LS_BLOCKS-LINE_FROM = <LS_TOKENS>-ROW.
ENDIF.
IF LV_TABIX EQ LV_LINES_TK.
IF LV_LAST_STM EQ ‘X’.
LS_BLOCKS-LINE_TO = <LS_TOKENS>-ROW.
ENDIF.
ENDIF.
LV_LEN = <LS_TOKENS>-LEN1.
IF <LS_TOKENS>-LEN2 GT 0.
ADD <LS_TOKENS>-LEN2 TO LV_LEN.
ADD 1 TO LV_LEN.
ENDIF.
IF <LS_TOKENS>-LEN3 GT 0.
ADD <LS_TOKENS>-LEN3 TO LV_LEN.
ADD 2 TO LV_LEN.
ENDIF.
IF LS_BLOCKS-TYPE EQ ‘=’.
IF LV_TABIX EQ 1 AND LV_LEN GT LV_MAX_1ST_TOKEN_LEN.
LV_MAX_1ST_TOKEN_LEN = LV_LEN.
EXIT.
ENDIF.
ELSE.
IF LV_TABIX EQ 2 AND LV_LEN GT LV_MAX_2ND_TOKEN_LEN.
LV_MAX_2ND_TOKEN_LEN = LV_LEN.
EXIT.
ENDIF.
ENDIF.
ENDLOOP. ” LOOP AT GT_TOKENS
ENDLOOP. ” LOOP AT GT_STM
CLEAR: GV_INSIDE_BEGINOF, GV_LAST_LINE_FROM.
LOOP AT GT_STM ASSIGNING <LS_STM> FROM LS_BLOCKS-FROM TO LS_BLOCKS-TO.
IF <LS_STM>-COLONCOL GT 0.
LV_CHAINED_STM = ‘X’.
ELSE.
CLEAR LV_CHAINED_STM.
ENDIF.
PERFORM UPDATE_BEGINOF_STATUS_STM USING <LS_STM>.
PERFORM ADJUST_POSITIONS USING <LS_STM>-FROM
<LS_STM>-TO
LV_CHAINED_STM
LV_MAX_1ST_TOKEN_LEN
LV_MAX_2ND_TOKEN_LEN
CHANGING LS_BLOCKS.
ENDLOOP. ” LOOP AT GT_STM
MODIFY GT_BLOCKS FROM LS_BLOCKS INDEX LV_TABIX_BLOCK.
ENDLOOP. ” LOOP AT GT_BLOCKS
* LOOP AT gt_blocks INTO ls_blocks.
* IF ( ls_blocks-from = ls_blocks-to ) and ls_blocks-type NE ‘DOBJ_BO’.
* DELETE gt_blocks INDEX sy-tabix.
* ENDIF.
* ENDLOOP.
ENDFORM. “identify_blocks
*&———————————————————————*
*& Form adjust_positions
*&———————————————————————*
* text
*———————————————————————-*
FORM ADJUST_POSITIONS USING IV_FROM TYPE I
IV_TO TYPE I
IV_CHAINED TYPE FLAG
IV_MAX_1ST_TOKEN_LEN TYPE I
IV_MAX_2ND_TOKEN_LEN TYPE I
CHANGING CS_BLOCKS TYPE GTY_BLOCKS.
DATA: LV_TABIX TYPE SYTABIX,
LV_POS_DIFF_PREV TYPE I,
LV_POS_DIFF TYPE I,
LV_STM_TYPE TYPE STRING,
LV_COL TYPE I,
LV_TABIX_CORRECTION TYPE I,
LV_TABIX_ORIG TYPE I,
LV_NEWPOS TYPE I,
LV_FIRST_TOKEN_LEN TYPE I,
LV_SECOND_TOKEN_LEN TYPE I,
LV_LAST_ROW TYPE I.
FIELD-SYMBOLS: <LS_TOKENS> LIKE LINE OF GT_TOKENS.
LOOP AT GT_TOKENS ASSIGNING <LS_TOKENS> FROM IV_FROM TO IV_TO.
LV_TABIX = SY-TABIX – IV_FROM + 1.
LV_COL = <LS_TOKENS>-COL.
IF LV_TABIX EQ 1.
IF CS_BLOCKS-POS1 LT LV_COL.
CS_BLOCKS-POS1 = LV_COL.
ENDIF.
LV_FIRST_TOKEN_LEN = STRLEN( <LS_TOKENS>-STR ).
ELSEIF LV_TABIX EQ 2.
IF CS_BLOCKS-TYPE EQ ‘=’.
LV_NEWPOS = CS_BLOCKS-POS1 + IV_MAX_1ST_TOKEN_LEN + 1.
ELSE.
LV_NEWPOS = CS_BLOCKS-POS1 + LV_FIRST_TOKEN_LEN + 1.
IF IV_CHAINED EQ ‘X’.
ADD 1 TO LV_NEWPOS.
ENDIF.
IF GV_INSIDE_BEGINOF EQ ‘X’.
ADD 2 TO LV_NEWPOS.
ENDIF.
ENDIF.
IF CS_BLOCKS-POS2 LT LV_NEWPOS.
CS_BLOCKS-POS2 = LV_NEWPOS.
ENDIF.
ELSEIF LV_TABIX EQ 3.
IF CS_BLOCKS-TYPE EQ ‘=’.
LV_NEWPOS = CS_BLOCKS-POS2 + 2.
ELSE.
LV_NEWPOS = CS_BLOCKS-POS2 + IV_MAX_2ND_TOKEN_LEN + 1.
ENDIF.
IF CS_BLOCKS-POS3 LT LV_NEWPOS.
CS_BLOCKS-POS3 = LV_NEWPOS.
ENDIF.
ELSEIF LV_TABIX EQ 4.
ENDIF.
ENDLOOP. ” LOOP AT GT_TOKENS
ENDFORM. “adjust_positions
*&———————————————————————*
*& Form determine_stm_type
*&———————————————————————*
* text
*———————————————————————-*
* –>IV_FROM text
* –>IV_TO text
* –>CV_STM_TYPE text
* –>CV_ROW text
*———————————————————————-*
FORM DETERMINE_STM_TYPE USING IV_FROM TYPE I
IV_TO TYPE I
CHANGING CV_STM_TYPE TYPE STRING
CV_ROW TYPE I.
DATA: LV_BEGINOF TYPE FLAG,
LV_ENDOF_POS TYPE I.
FIELD-SYMBOLS: <LS_TOKENS> LIKE LINE OF GT_TOKENS.
CLEAR: CV_ROW, CV_STM_TYPE.
LOOP AT GT_TOKENS ASSIGNING <LS_TOKENS> FROM IV_FROM TO IV_TO.
CV_ROW = <LS_TOKENS>-ROW.
IF SY-TABIX EQ IV_FROM.
CASE <LS_TOKENS>-STR.
WHEN ‘DATA’ OR ‘TYPES’ OR ‘STATICS’ OR ‘CLASS-DATA’ OR ‘CONSTANTS’ OR ‘PARAMETERS’ OR ‘SELECT-OPTIONS’. ” or ‘FIELD-SYMBOLS’.
PERFORM CHECK_BEGINOF USING SY-TABIX CHANGING LV_BEGINOF. ” lv_endof_pos.
IF LV_BEGINOF EQ ‘X’.
CV_STM_TYPE = ‘DOBJ_BO’.
ELSE.
CV_STM_TYPE = ‘DOBJ’.
ENDIF.
WHEN ‘MOVE’.
CV_STM_TYPE = ‘MOVE’.
RETURN.
WHEN ‘FIELD-SYMBOLS’.
CV_STM_TYPE = ‘FS’.
WHEN OTHERS.
CONTINUE.
ENDCASE.
ELSE.
CASE <LS_TOKENS>-STR.
WHEN ‘=’.
CV_STM_TYPE = ‘=’.
RETURN.
WHEN OTHERS.
RETURN.
ENDCASE.
ENDIF.
ENDLOOP. ” LOOP AT GT_TOKENS
ENDFORM. “determine_stm_type
*&———————————————————————*
*& Form check_beginof
*&———————————————————————*
* text
*———————————————————————-*
* –>IV_TABIX text
* –>CV_BEGINOF text
*———————————————————————-*
FORM CHECK_BEGINOF USING IV_TABIX TYPE I
CHANGING CV_BEGINOF TYPE FLAG.
* cv_endof_pos TYPE i.
DATA LV_TABIX TYPE I.
FIELD-SYMBOLS: <LS_TOKEN> LIKE LINE OF GT_TOKENS.
CLEAR CV_BEGINOF.
LV_TABIX = IV_TABIX + 1.
READ TABLE GT_TOKENS INDEX LV_TABIX ASSIGNING <LS_TOKEN>.
CHECK SY-SUBRC EQ 0.
IF <LS_TOKEN>-STR EQ ‘BEGIN’ OR <LS_TOKEN>-STR EQ ‘END’.
* lv_tabix = iv_tabix – 1. “txh01
*
* READ TABLE gt_tokens INDEX lv_tabix ASSIGNING <ls_token>. “txh01
* CHECK sy-subrc EQ 0. “txh01
*
* IF <ls_token>-str EQ ‘AT’. “txh01
* RETURN. “txh01
* ENDIF. “txh01
*
* lv_tabix = iv_tabix + 2. “txh01
LV_TABIX = IV_TABIX + 1.
READ TABLE GT_TOKENS INDEX LV_TABIX ASSIGNING <LS_TOKEN>.
CHECK SY-SUBRC EQ 0.
IF <LS_TOKEN>-STR EQ ‘OF’.
CV_BEGINOF = ‘X’.
** lv_tabix = iv_tabix + 2.
**
** LOOP AT gt_tokens FROM lv_tabix ASSIGNING <ls_token>.
**
** IF <ls_token>-str EQ ‘END’.
**
** lv_tabix = iv_tabix + 1.
**
** READ TABLE gt_tokens INDEX lv_tabix ASSIGNING <ls_token2>.
** CHECK sy-subrc EQ 0.
**
** IF <ls_token2>-str EQ ‘OF’.
** cv_endof_pos = lv_tabix – 1.
** EXIT.
** ENDIF.
**
** ENDIF.
**
** ENDLOOP.
ENDIF.
ENDIF.
ENDFORM. “check_beginof
*&———————————————————————*
*& Form get_comment_pos
*&———————————————————————*
* text
*———————————————————————-*
* –>IV_LINE text
* –>CV_POS text
*———————————————————————-*
FORM GET_COMMENT_POS USING IV_LINE TYPE STRING “SWBSE_MAX_LINE
CHANGING CV_POS TYPE I.
DATA: LV_LENGTH TYPE I,
LV_OFFSET TYPE I,
LV_APTH_OPEN TYPE FLAG.
CLEAR CV_POS.
LV_LENGTH = STRLEN( IV_LINE ).
DO LV_LENGTH TIMES.
LV_OFFSET = SY-INDEX – 1.
IF IV_LINE+LV_OFFSET(1) EQ ””.
IF LV_APTH_OPEN IS INITIAL.
LV_APTH_OPEN = ‘X’.
ELSE.
CLEAR LV_APTH_OPEN.
ENDIF.
ELSEIF IV_LINE+LV_OFFSET(1) EQ ‘”‘ AND LV_APTH_OPEN IS INITIAL.
CV_POS = SY-INDEX.
RETURN.
ENDIF.
ENDDO.
ENDFORM. “get_comment_pos
*&———————————————————————*
*& Form update_beginof_status_stm
*&———————————————————————*
* text
*———————————————————————-*
* –>IS_STM text
*———————————————————————-*
FORM UPDATE_BEGINOF_STATUS_STM USING IS_STM TYPE SSTMNT.
DATA: LV_TABIX TYPE I,
LV_KEYWORD TYPE STRING.
FIELD-SYMBOLS: <LS_TOKEN> LIKE LINE OF GT_TOKENS,
<LS_TOKEN_NEXT> LIKE LINE OF GT_TOKENS.
LOOP AT GT_TOKENS ASSIGNING <LS_TOKEN>
WHERE ROW BETWEEN GV_LAST_LINE_FROM AND IS_STM-TROW
AND ( STR EQ ‘BEGIN’ OR STR EQ ‘END’ ).
LV_TABIX = SY-TABIX.
SUBTRACT 1 FROM LV_TABIX.
READ TABLE GT_TOKENS ASSIGNING <LS_TOKEN_NEXT> INDEX LV_TABIX.
CHECK SY-SUBRC EQ 0.
CHECK <LS_TOKEN_NEXT>-STR NE ‘SELECTION-SCREEN’ AND <LS_TOKEN_NEXT>-STR NE ‘AT’. “txh01
ADD 1 TO LV_TABIX.
IF <LS_TOKEN>-ROW EQ IS_STM-TROW.
CHECK <LS_TOKEN>-COL LT IS_STM-TCOL.
ENDIF.
LV_KEYWORD = <LS_TOKEN>-STR.
ADD 1 TO LV_TABIX.
IF <LS_TOKEN>-STR EQ ‘BEGIN’.
GV_BEGINOF_COL = <LS_TOKEN>-COL.
ENDIF.
READ TABLE GT_TOKENS ASSIGNING <LS_TOKEN_NEXT> INDEX LV_TABIX.
IF SY-SUBRC EQ 0.
IF <LS_TOKEN_NEXT>-ROW EQ IS_STM-TROW.
CHECK <LS_TOKEN_NEXT>-COL LT IS_STM-TCOL.
ENDIF.
IF <LS_TOKEN_NEXT>-STR EQ ‘OF’.
IF LV_KEYWORD EQ ‘BEGIN’.
GV_INSIDE_BEGINOF = ‘X’.
ELSEIF LV_KEYWORD EQ ‘END’.
CLEAR: GV_INSIDE_BEGINOF.
ENDIF.
ENDIF.
ENDIF.
* gv_last_line_from = is_stm-trow.
ENDLOOP. ” LOOP AT GT_TOKENS
GV_LAST_LINE_FROM = IS_STM-TROW.
ENDFORM. ” UPDATE_BEGINOF_STATUS
FORM ADD_KEYWORDS.
APPEND ‘DATA’ TO GT_KEYWORDS.
APPEND ‘TYPES’ TO GT_KEYWORDS.
APPEND ‘SELECTION-SCREEN’ TO GT_KEYWORDS.
APPEND ‘FIELD-SYMBOLS’ TO GT_KEYWORDS.
APPEND ‘STATICS’ TO GT_KEYWORDS.
APPEND ‘CONSTANTS’ TO GT_KEYWORDS.
APPEND ‘CLASS-DATA’ TO GT_KEYWORDS.
APPEND ‘SELECT-OPTIONS’ TO GT_KEYWORDS.
APPEND ‘PARAETERS’ TO GT_KEYWORDS.
APPEND ‘MOVE’ TO GT_KEYWORDS.
APPEND ‘COMPUTE’ TO GT_KEYWORDS.
ENDFORM. ” FORM ADD_KEYWORDS
*&———————————————————————*
*& Form frm_code_db_click
*&———————————————————————*
*& 双击代码行的时候
*&———————————————————————*
FORM FRM_CODE_DB_CLICK .
DATA: L_FROM_col TYPE I,
L_TO_col TYPE I,
L_FROM_NEW TYPE I,
L_TO_NEW TYPE I,
L_FROM_LINE TYPE I,
L_TO_LINE TYPE I,
L_LEN TYPE I,
LV_LINES TYPE I,
LV_MAX TYPE C LENGTH 6,
LV_MIDDLE_STRING TYPE STRING,
LT_TEXT TYPE SOURCE_TABLE WITH HEADER LINE.
* 记录好代码位置。
CALL METHOD GO_EDITOR->GET_FIRST_VISIBLE_LINE( IMPORTING LINE = LV_LINE ).
* 获取所有代码,双击的时候的行,列。
PERFORM FRM_GET_ALL_CODE TABLES MTAB_OLD_PROG[]
CHANGING L_FROM_LINE L_FROM_col L_TO_LINE L_TO_col.
DESCRIBE TABLE MTAB_OLD_PROG[] LINES LV_MAX.
* 判断双击的左边还是右边。左边向上查找,右边则向下查找。
DATA LWA_CLK_CODE LIKE LINE OF MTAB_OLD_PROG.
CLEAR LWA_CLK_CODE.
READ TABLE MTAB_OLD_PROG INTO LWA_CLK_CODE INDEX L_FROM_LINE.
CHECK NOT LWA_CLK_CODE IS INITIAL.
DATA LV_C TYPE C LENGTH 1.
DATA LV_I TYPE I.
DATA LV_END TYPE I.
DATA LV_CODE TYPE C LENGTH 300.
CLEAR LV_CODE.
DO 270 TIMES.
LV_I = SY-INDEX – 1.
LV_C = LWA_CLK_CODE+LV_I(1).
IF SY-INDEX <= L_FROM_col.
CONCATENATE LV_CODE LV_C INTO LV_CODE.
IF LV_C IS INITIAL
OR LV_C = `-`
OR LV_C = `>`
.
CLEAR LV_CODE.
ENDIF.
ELSE.
CONCATENATE LV_CODE LV_C INTO LV_CODE.
IF LV_C IS INITIAL
OR LV_C = ‘.’
OR LV_C = ‘=’
OR LV_C = ‘-‘
OR LV_C = ‘[‘
OR LV_C = ‘,’.
LV_END = LV_I.
EXIT.
ENDIF.
ENDIF.
ENDDO.
REPLACE FIRST OCCURRENCE OF `,` IN LV_CODE WITH SPACE.
REPLACE FIRST OCCURRENCE OF `.` IN LV_CODE WITH SPACE.
REPLACE FIRST OCCURRENCE OF `=` IN LV_CODE WITH SPACE.
REPLACE FIRST OCCURRENCE OF `>` IN LV_CODE WITH SPACE.
REPLACE FIRST OCCURRENCE OF `[` IN LV_CODE WITH SPACE.
REPLACE FIRST OCCURRENCE OF `-` IN LV_CODE WITH SPACE.
LV_I = STRLEN( LV_CODE ) / 2 + L_FROM_col.
DATA LV_DIR TYPE C LENGTH 1.
DATA LV_GOT_LINE TYPE I.
DATA LV_GOT TYPE C.
IF LV_I > LV_END.
LV_DIR = ‘下’.
LV_I = L_FROM_LINE + 1.
LOOP AT MTAB_OLD_PROG FROM LV_I.
LV_GOT_LINE = SY-TABIX.
PERFORM FRM_FIND_KEY USING LV_CODE MTAB_OLD_PROG CHANGING LV_GOT.
IF NOT LV_GOT IS INITIAL.
EXIT.
ENDIF.
ENDLOOP.
ELSE.
LV_I = L_FROM_LINE – 1.
IF LV_I > 1.
LOOP AT MTAB_OLD_PROG FROM 1 TO LV_I.
LV_GOT_LINE = SY-TABIX.
PERFORM FRM_FIND_KEY USING LV_CODE MTAB_OLD_PROG CHANGING LV_GOT.
IF NOT LV_GOT IS INITIAL.
EXIT.
ENDIF.
ENDLOOP.
ENDIF.
LV_DIR = ‘上’.
ENDIF.
IF NOT LV_GOT IS INITIAL AND NOT LV_GOT_LINE IS INITIAL.
GO_EDITOR->SET_FIRST_VISIBLE_LINE( LV_GOT_LINE ).
ELSE.
TRANSLATE LWA_CLK_CODE TO UPPER CASE.
CONDENSE LWA_CLK_CODE NO-GAPS.
IF LWA_CLK_CODE CS `CALLFUNCTION’`.
REPLACE ALL OCCURRENCES OF `’` IN LV_CODE WITH SPACE.
REPLACE ALL OCCURRENCES OF ‘`’ IN LV_CODE WITH SPACE.
PERFORM BDC_DYNPRO USING ‘SAPLSFUNCTION_BUILDER’ ‘1008’.
PERFORM BDC_FIELD USING ‘BDC_CURSOR’
‘RS38L-NAME’.
PERFORM BDC_FIELD USING ‘BDC_OKCODE’
‘=WB_DISPLAY’.
PERFORM BDC_FIELD USING ‘RS38L-NAME’
LV_CODE.
PERFORM BDC_DYNPRO USING ‘SAPLSFUNCTION_BUILDER’ ‘3000’.
PERFORM BDC_FIELD USING ‘BDC_OKCODE’
‘=WB_BACK’.
PERFORM BDC_DYNPRO USING ‘SAPLSFUNCTION_BUILDER’ ‘1008’.
PERFORM BDC_FIELD USING ‘BDC_CURSOR’
‘RS38L-NAME’.
* PERFORM BDC_FIELD USING ‘BDC_OKCODE’
* ‘=WB_BACK’.
* PERFORM BDC_FIELD USING ‘RS38L-NAME’
* LV_CODE.
*
* PERFORM BDC_FIELD USING ‘BDC_OKCODE’
* ‘=XX’.
* PERFORM BDC_TRANSACTION USING ‘SE37’.
DATA LV_FM TYPE C LENGTH 30.
LV_FM = LV_CODE.
SET PARAMETER ID ‘LIB’ FIELD LV_FM .
SUBMIT RSFUNCTIONBUILDER WITH NAME = LV_FM
WITH BUT3 = ‘X’
AND RETURN.
ELSE.
* 查看是否已经有了FORM 代码
DATA LV_GOT_FORM TYPE C.
CLEAR LV_GOT_FORM.
DATA LT_SPACE TYPE STANDARD TABLE OF STRING WITH HEADER LINE.
LOOP AT MTAB_OLD_PROG.
TRANSLATE MTAB_OLD_PROG TO UPPER CASE.
IF MTAB_OLD_PROG CS LV_CODE.
CONDENSE MTAB_OLD_PROG.
CLEAR LT_SPACE[].
SPLIT MTAB_OLD_PROG AT SPACE INTO TABLE LT_SPACE.
DELETE LT_SPACE WHERE TABLE_LINE = SPACE.
DELETE LT_SPACE WHERE TABLE_LINE = ‘.’.
CLEAR LT_SPACE.
READ TABLE LT_SPACE INDEX 2.
IF SY-SUBRC = 0 AND LT_SPACE = LV_CODE.
CLEAR LT_SPACE.
READ TABLE LT_SPACE INDEX 1.
IF LT_SPACE = ‘FORM’.
LV_GOT_FORM = ‘X’.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
IF LWA_CLK_CODE+0(7) = ‘PERFORM’ AND GV_READ_ONLY IS INITIAL
AND LV_GOT_FORM IS INITIAL.
LV_MAX = LV_MAX + 1.
DATA LV_21 TYPE C LENGTH 21.
LV_21 = LV_CODE.
DATA LT_INS_CODE LIKE TABLE OF MTAB_OLD_PROG WITH HEADER LINE.
CONCATENATE ‘*&———————————————————————*’ SPACE INTO LT_INS_CODE RESPECTING BLANKS. APPEND LT_INS_CODE.
CONCATENATE ‘*& ‘ LV_CODE INTO LT_INS_CODE RESPECTING BLANKS. APPEND LT_INS_CODE.
CONCATENATE ‘*&———————————————————————*’ SPACE INTO LT_INS_CODE RESPECTING BLANKS. APPEND LT_INS_CODE.
* 1 PERFORM
* 2 FRM_AA
* 3 TABLES
* 4 A
* 5 USING
* 6 B
* 7 C
* 8 CHANGING
* 9 CC.
CLEAR LV_GOT.
DATA LV_GOT_FORMS TYPE C LENGTH 1.
DATA LV_TABIX TYPE I.
DELETE LT_SPACE WHERE TABLE_LINE = ‘.’.
DELETE LT_SPACE WHERE TABLE_LINE = SPACE.
LOOP AT LT_SPACE WHERE TABLE_LINE = ‘TABLES’.
LV_TABIX = SY-TABIX + 1.
LOOP AT LT_SPACE FROM LV_TABIX.
REPLACE ALL OCCURRENCES OF ‘.’ IN LT_SPACE WITH SPACE.
IF LT_SPACE = ‘USING’ OR LT_SPACE = ‘CHANGING’.
EXIT.
ENDIF.
IF LV_GOT IS INITIAL.
LV_GOT = ‘X’.
LV_GOT_FORMS = ‘X’.
CONCATENATE ‘FORM ‘ LV_21 `TABLES T_` LT_SPACE INTO LT_INS_CODE RESPECTING BLANKS. APPEND LT_INS_CODE.
ELSE.
CONCATENATE ‘ ‘ ` T_` LT_SPACE INTO LT_INS_CODE RESPECTING BLANKS. APPEND LT_INS_CODE.
ENDIF.
ENDLOOP.
EXIT.
ENDLOOP.
**********************************************************************
CLEAR LV_GOT.
LOOP AT LT_SPACE WHERE TABLE_LINE = ‘USING’.
LV_TABIX = SY-TABIX + 1.
LOOP AT LT_SPACE FROM LV_TABIX.
REPLACE ALL OCCURRENCES OF ‘.’ IN LT_SPACE WITH SPACE.
IF LT_SPACE = ‘TABLES’ OR LT_SPACE = ‘CHANGING’.
EXIT.
ENDIF.
IF LV_GOT_FORMS IS INITIAL.
LV_GOT_FORMS = ‘X’.
IF LV_GOT IS INITIAL.
LV_GOT = ‘X’.
CONCATENATE ‘FORM ‘ LV_21 `USING UV_` LT_SPACE INTO LT_INS_CODE RESPECTING BLANKS. APPEND LT_INS_CODE.
ELSE.
CONCATENATE ‘ ‘ `UV_` LT_SPACE INTO LT_INS_CODE RESPECTING BLANKS. APPEND LT_INS_CODE.
ENDIF.
ELSE.
IF LV_GOT IS INITIAL.
LV_GOT = ‘X’.
CONCATENATE ‘ ‘ `USING UV_` LT_SPACE INTO LT_INS_CODE RESPECTING BLANKS. APPEND LT_INS_CODE.
ELSE.
CONCATENATE ‘ ‘ `UV_` LT_SPACE INTO LT_INS_CODE RESPECTING BLANKS. APPEND LT_INS_CODE.
ENDIF.
ENDIF.
ENDLOOP.
EXIT.
ENDLOOP.
**********************************************************************
CLEAR LV_GOT.
LOOP AT LT_SPACE WHERE TABLE_LINE = ‘CHANGING’.
LV_TABIX = SY-TABIX + 1.
LOOP AT LT_SPACE FROM LV_TABIX.
REPLACE ALL OCCURRENCES OF ‘.’ IN LT_SPACE WITH SPACE.
IF LT_SPACE = ‘USING’ OR LT_SPACE = ‘TABLES’.
EXIT.
ENDIF.
IF LV_GOT_FORMS IS INITIAL.
LV_GOT_FORMS = ‘X’.
IF LV_GOT IS INITIAL.
LV_GOT = ‘X’.
CONCATENATE ‘FORM ‘ LV_21 `CHANGING UV_ ` LT_SPACE INTO LT_INS_CODE RESPECTING BLANKS. APPEND LT_INS_CODE.
ELSE.
CONCATENATE ‘ ‘ `CV_` LT_SPACE INTO LT_INS_CODE RESPECTING BLANKS. APPEND LT_INS_CODE.
ENDIF.
ELSE.
IF LV_GOT IS INITIAL.
LV_GOT = ‘X’.
CONCATENATE ‘ ‘ `CHANGING CV_` LT_SPACE INTO LT_INS_CODE RESPECTING BLANKS. APPEND LT_INS_CODE.
ELSE.
CONCATENATE ‘ ‘ `CV_` LT_SPACE INTO LT_INS_CODE RESPECTING BLANKS. APPEND LT_INS_CODE.
ENDIF.
ENDIF.
ENDLOOP.
EXIT.
ENDLOOP.
*
* CONCATENATE ‘FORM ‘ LV_21 `TABLES TA ` INTO LT_INS_CODE RESPECTING BLANKS. APPEND LT_INS_CODE.
* CONCATENATE ‘ USING UV_KEY’ SPACE INTO LT_INS_CODE RESPECTING BLANKS. APPEND LT_INS_CODE.
* CONCATENATE ‘ uV_CODE’ SPACE INTO LT_INS_CODE RESPECTING BLANKS. APPEND LT_INS_CODE.
* CONCATENATE ‘ CHANGING cV_GOT’ SPACE INTO LT_INS_CODE RESPECTING BLANKS. APPEND LT_INS_CODE.
* CONCATENATE ‘ cV_GOT2’ SPACE INTO LT_INS_CODE RESPECTING BLANKS. APPEND LT_INS_CODE.
CONCATENATE ‘ .’ SPACE INTO LT_INS_CODE RESPECTING BLANKS. APPEND LT_INS_CODE.
CONCATENATE ” SPACE INTO LT_INS_CODE RESPECTING BLANKS. APPEND LT_INS_CODE.
CONCATENATE ” SPACE INTO LT_INS_CODE RESPECTING BLANKS. APPEND LT_INS_CODE.
CONCATENATE ‘ENDFORM. ‘ SPACE INTO LT_INS_CODE RESPECTING BLANKS. APPEND LT_INS_CODE.
PERFORM FRM_INSERT_CODE TABLES LT_INS_CODE[] USING LV_MAX.
ENDIF.
MESSAGE S398(00) WITH ‘向’ LV_DIR ‘找不到:’ LV_CODE.
ENDIF.
* & & & &
ENDIF.
ENDFORM.
*&———————————————————————*
*& 在一行中查找关键字代码,忽略注释。
*&———————————————————————*
FORM FRM_FIND_KEY USING UV_KEY
uV_CODE
CHANGING cV_GOT.
DATA LV_CODE_01 TYPE C LENGTH 300.
DATA LV_CODE_02 TYPE C LENGTH 300.
IF uV_CODE+0(1) = ‘*’.
RETURN.
ENDIF.
LV_CODE_01 = uV_CODE.
CONDENSE LV_CODE_01 .
IF LV_CODE_01+0(1) = ‘”‘.
RETURN.
ENDIF.
CLEAR LV_CODE_01.
SPLIT uV_CODE AT `”` INTO LV_CODE_01 LV_CODE_02.
IF SY-SUBRC = 0.
* 去掉了后半截的注释
ELSE.
LV_CODE_01 = uV_CODE.
ENDIF.
DATA LV_MOFF TYPE I.
DATA LV_MLEN TYPE I.
DATA LV_i TYPE I.
DATA LV_before TYPE I.
FIND UV_KEY IN LV_CODE_01 IGNORING CASE MATCH OFFSET LV_MOFF
MATCH LENGTH LV_MLEN.
IF SY-SUBRC = 0.
* 并且前后都是空或者符号。则算完全匹配.
LV_i = LV_MOFF + LV_MLEN.
LV_before = LV_MOFF – 1.
IF LV_before >= 0.
IF ( LV_CODE_01+LV_i(1) = ”
OR LV_CODE_01+LV_i(1) = ‘-‘
OR LV_CODE_01+LV_i(1) = ‘.’
OR LV_CODE_01+LV_i(1) = ‘[‘
OR LV_CODE_01+LV_i(1) = ‘=’ )
AND ( LV_CODE_01+LV_before(1) = ”
OR LV_CODE_01+LV_before(1) = ‘=’
OR LV_CODE_01+LV_before(1) = ‘-‘
OR LV_CODE_01+LV_before(1) = ‘[‘
OR LV_CODE_01+LV_before(1) = ‘>’
).
cV_GOT = ‘X’.
ENDIF.
ELSE.
IF ( LV_CODE_01+LV_i(1) = ”
OR LV_CODE_01+LV_i(1) = ‘-‘
OR LV_CODE_01+LV_i(1) = ‘.’
OR LV_CODE_01+LV_i(1) = ‘[‘
OR LV_CODE_01+LV_i(1) = ‘=’ ) .
cV_GOT = ‘X’.
ENDIF.
ENDIF.
ENDIF.
ENDFORM.
*———————————————————————-*
* Start new screen *
*———————————————————————-*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = ‘X’.
APPEND BDCDATA.
ENDFORM.
*———————————————————————-*
* Insert field *
*———————————————————————-*
FORM BDC_FIELD USING FNAM FVAL.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDFORM.
FORM BDC_TRANSACTION USING TCODE.
REFRESH MESSTAB.
CALL TRANSACTION TCODE USING BDCDATA
MODE ‘E’
MESSAGES INTO MESSTAB.
REFRESH BDCDATA.
ENDFORM.
FORM FRM_AUTO_FILL_G.
PERFORM FRM_AUTO_FILL USING ‘G’.
ENDFORM.
FORM FRM_AUTO_FILL_L.
PERFORM FRM_AUTO_FILL USING ‘L’.
ENDFORM.
*&———————————————————————*
*& Form FRM_AUTO_FILL
*&———————————————————————*
*& 自动命名。
*&———————————————————————*
FORM FRM_AUTO_FILL USING UV_NAMING_BEG.
IF GV_READ_ONLY IS NOT INITIAL.
MESSAGE S398(00) WITH ‘Please Set Code In 【Edit】 Status’.
RETURN.
ENDIF.
DATA: L_FROM_col TYPE I,
L_TO_col TYPE I,
L_FROM_NEW TYPE I,
L_TO_NEW TYPE I,
L_FROM_LINE TYPE I,
L_TO_LINE TYPE I.
* 记录好代码位置。
CALL METHOD GO_EDITOR->GET_FIRST_VISIBLE_LINE( IMPORTING LINE = LV_LINE ).
* 获取所有代码,右击的时候的行,列。
PERFORM FRM_GET_ALL_CODE TABLES MTAB_OLD_PROG[]
CHANGING L_FROM_LINE L_FROM_col L_TO_LINE L_TO_col.
DATA LV_GOT TYPE C.
CLEAR MTAB_OLD_PROG.
READ TABLE MTAB_OLD_PROG INDEX L_FROM_LINE.
CHECK NOT MTAB_OLD_PROG IS INITIAL.
DATA LT_TMP LIKE TABLE OF MTAB_OLD_PROG WITH HEADER LINE.
LT_TMP[] = MTAB_OLD_PROG[].
DELETE LT_TMP[] FROM L_FROM_LINE TO 99999.
APPEND MTAB_OLD_PROG TO LT_TMP.
* ‘CONVERSION_EXIT_ALPHA_INPUT’
REPLACE ALL OCCURRENCES OF ` ` IN MTAB_OLD_PROG WITH `’`.
REPLACE ALL OCCURRENCES OF ‘`’ IN MTAB_OLD_PROG WITH `’`.
REPLACE ALL OCCURRENCES OF ‘:’ IN MTAB_OLD_PROG WITH `’`.
REPLACE ALL OCCURRENCES OF ‘:’ IN MTAB_OLD_PROG WITH `’`.
REPLACE ALL OCCURRENCES OF ‘,’ IN MTAB_OLD_PROG WITH `’`.
REPLACE ALL OCCURRENCES OF ‘,’ IN MTAB_OLD_PROG WITH `’`.
REPLACE ALL OCCURRENCES OF ‘。’ IN MTAB_OLD_PROG WITH `’`.
REPLACE ALL OCCURRENCES OF ‘.’ IN MTAB_OLD_PROG WITH `’`.
REPLACE ALL OCCURRENCES OF ‘*’ IN MTAB_OLD_PROG WITH `’`.
REPLACE ALL OCCURRENCES OF ‘”‘ IN MTAB_OLD_PROG WITH `’`.
TYPES:BEGIN OF LTY_OBJ,
OBJ TYPE C LENGTH 30,
END OF LTY_OBJ.
DATA LT_OBJ TYPE STANDARD TABLE OF LTY_OBJ WITH HEADER LINE .
DATA C_WA TYPE C LENGTH 2 VALUE ‘WA’.
SPLIT MTAB_OLD_PROG AT `’` INTO TABLE LT_OBJ[].
DELETE LT_OBJ WHERE OBJ = SPACE.
TYPES:BEGIN OF LTY_SE37,
FUNCNAME TYPE FUPARAREF-FUNCNAME,
PARAMETER TYPE FUPARAREF-PARAMETER,
PARAMTYPE TYPE FUPARAREF-PARAMTYPE,
STRUCTURE TYPE FUPARAREF-STRUCTURE,
DEFAULTVAL TYPE FUPARAREF-DEFAULTVAL,
REFERENCE TYPE FUPARAREF-REFERENCE,
PPOSITION TYPE FUPARAREF-PPOSITION,
OPTIONAL TYPE FUPARAREF-OPTIONAL,
TYPE TYPE FUPARAREF-TYPE,
DEF_NAME TYPE C LENGTH 30,
DEF_WA_NAME TYPE C LENGTH 30,
TEXT TYPE C LENGTH 30,
STRUCTURE_FLAG TYPE C,
END OF LTY_SE37.
DATA LT_SE37 TYPE STANDARD TABLE OF LTY_SE37 WITH HEADER LINE .
CLEAR LT_SE37[].
DATA LT_INS_CODE LIKE TABLE OF MTAB_OLD_PROG WITH HEADER LINE.
IF NOT LT_OBJ[] IS INITIAL .
SELECT *
INTO CORRESPONDING FIELDS OF TABLE LT_SE37
FROM FUPARAREF
FOR ALL ENTRIES IN LT_OBJ
WHERE FUNCNAME = LT_OBJ-OBJ.
SORT LT_SE37 BY PPOSITION.
ENDIF.
CLEAR LT_INS_CODE[].
IF NOT LT_SE37[] IS INITIAL.
DATA LWA_SE37 LIKE LINE OF LT_SE37.
READ TABLE LT_SE37 INTO LWA_SE37 INDEX 1.
IF SY-SUBRC = 0.
**********************************************************************
**********定义阶段.***************************************************
**********************************************************************
* EXPORTING
DATA LV_STRUC TYPE STRING.
LOOP AT LT_SE37 WHERE PARAMTYPE = ‘I’ .
LV_STRUC = LT_SE37-STRUCTURE .
PERFORM FRM_GET_STRUC_TEXT USING LT_SE37-STRUCTURE CHANGING LT_SE37-TEXT LT_SE37-STRUCTURE_FLAG.
IF LT_SE37-STRUCTURE_FLAG = SPACE. “变量.
CONCATENATE UV_NAMING_BEG `V_` LT_SE37-PARAMETER INTO LT_SE37-DEF_NAME.
CONCATENATE ` DATA ` LT_SE37-DEF_NAME ‘ TYPE ‘ LV_STRUC ‘.’ LT_SE37-TEXT INTO LT_INS_CODE RESPECTING BLANKS .
ELSE.
CONCATENATE UV_NAMING_BEG C_WA ‘_’ LT_SE37-PARAMETER INTO LT_SE37-DEF_NAME.
CONCATENATE ` DATA ` LT_SE37-DEF_NAME ‘ TYPE ‘ LV_STRUC ‘.’ LT_SE37-TEXT INTO LT_INS_CODE RESPECTING BLANKS .
ENDIF.
IF NOT LT_SE37-OPTIONAL IS INITIAL.
CONCATENATE ‘*’ LT_INS_CODE INTO LT_INS_CODE.
ENDIF.
APPEND LT_INS_CODE.
MODIFY LT_SE37.
ENDLOOP.
* IMPORTING
LOOP AT LT_SE37 WHERE PARAMTYPE = ‘E’ .
PERFORM FRM_GET_STRUC_TEXT USING LT_SE37-STRUCTURE CHANGING LT_SE37-TEXT LT_SE37-STRUCTURE_FLAG.
LV_STRUC = LT_SE37-STRUCTURE .
IF LT_SE37-STRUCTURE_FLAG = SPACE. “变量.
CONCATENATE UV_NAMING_BEG `V_` LT_SE37-PARAMETER INTO LT_SE37-DEF_NAME.
CONCATENATE ` DATA ` LT_SE37-DEF_NAME ‘ TYPE ‘ LV_STRUC ‘.’ LT_SE37-TEXT INTO LT_INS_CODE RESPECTING BLANKS .
ELSE.
CONCATENATE UV_NAMING_BEG C_WA ‘_’ LT_SE37-PARAMETER INTO LT_SE37-DEF_NAME.
CONCATENATE ` DATA ` LT_SE37-DEF_NAME ‘ TYPE ‘ LV_STRUC ‘.’ LT_SE37-TEXT INTO LT_INS_CODE RESPECTING BLANKS .
ENDIF.
IF NOT LT_SE37-OPTIONAL IS INITIAL.
CONCATENATE ‘*’ LT_INS_CODE INTO LT_INS_CODE.
ENDIF.
APPEND LT_INS_CODE.
MODIFY LT_SE37.
ENDLOOP.
* TABLES.
LOOP AT LT_SE37 WHERE PARAMTYPE = ‘T’ .
PERFORM FRM_GET_STRUC_TEXT USING LT_SE37-STRUCTURE CHANGING LT_SE37-TEXT LT_SE37-STRUCTURE_FLAG.
IF LT_SE37-STRUCTURE IS INITIAL.
LT_SE37-STRUCTURE = ‘XXXXX’.
ENDIF.
LV_STRUC = LT_SE37-STRUCTURE .
CONCATENATE UV_NAMING_BEG ‘T_’ LT_SE37-PARAMETER INTO LT_SE37-DEF_NAME.
CONCATENATE UV_NAMING_BEG C_WA ‘_’ LT_SE37-PARAMETER INTO LT_SE37-DEF_WA_NAME.
CONCATENATE ` DATA ` LT_SE37-DEF_NAME ‘ TYPE STANDARD TABLE OF ‘ LV_STRUC ‘.’ LT_SE37-TEXT INTO LT_INS_CODE RESPECTING BLANKS .
MODIFY LT_SE37.
IF NOT LT_SE37-OPTIONAL IS INITIAL.
CONCATENATE ‘*’ LT_INS_CODE INTO LT_INS_CODE.
ENDIF.
APPEND LT_INS_CODE.
* 工作区
CONCATENATE ` DATA ` LT_SE37-DEF_WA_NAME ‘ TYPE ‘ LV_STRUC ‘.’ LT_SE37-TEXT INTO LT_INS_CODE RESPECTING BLANKS .
IF NOT LT_SE37-OPTIONAL IS INITIAL.
CONCATENATE ‘*’ LT_INS_CODE INTO LT_INS_CODE.
ENDIF.
APPEND LT_INS_CODE.
ENDLOOP.
* CHANGE.
LOOP AT LT_SE37 WHERE PARAMTYPE = ‘C’ .
PERFORM FRM_GET_STRUC_TEXT USING LT_SE37-STRUCTURE CHANGING LT_SE37-TEXT LT_SE37-STRUCTURE_FLAG.
LV_STRUC = LT_SE37-STRUCTURE .
IF LT_SE37-STRUCTURE_FLAG = SPACE. “变量.
CONCATENATE UV_NAMING_BEG `V_` LT_SE37-PARAMETER INTO LT_SE37-DEF_NAME.
CONCATENATE ` DATA ` LT_SE37-DEF_NAME ‘ TYPE ‘ LV_STRUC ‘.’ LT_SE37-TEXT INTO LT_INS_CODE RESPECTING BLANKS .
ELSE.
CONCATENATE UV_NAMING_BEG C_WA ‘_’ LT_SE37-PARAMETER INTO LT_SE37-DEF_NAME.
CONCATENATE ` DATA ` LT_SE37-DEF_NAME ‘ TYPE ‘ LV_STRUC ‘.’ LT_SE37-TEXT INTO LT_INS_CODE RESPECTING BLANKS .
ENDIF.
IF NOT LT_SE37-OPTIONAL IS INITIAL.
CONCATENATE ‘*’ LT_INS_CODE INTO LT_INS_CODE.
ENDIF.
APPEND LT_INS_CODE.
MODIFY LT_SE37.
ENDLOOP.
*******************正式编辑代码。***************************************************
DATA LV_FM TYPE STRING.
LV_FM = LWA_SE37-FUNCNAME.
CONDENSE LV_FM NO-GAPS.
APPEND INITIAL LINE TO LT_INS_CODE.
CONCATENATE ` CALL FUNCTION ‘` LV_FM `’` INTO LT_INS_CODE RESPECTING BLANKS .APPEND LT_INS_CODE.
CLEAR LV_GOT.
LOOP AT LT_SE37 WHERE PARAMTYPE = ‘I’.
IF LV_GOT IS INITIAL.
CONCATENATE ` EXPORTING` SPACE INTO LT_INS_CODE RESPECTING BLANKS .APPEND LT_INS_CODE.
LV_GOT = ‘X’.
ENDIF.
CONCATENATE ` ` LT_SE37-PARAMETER ‘ = ‘ LT_SE37-DEF_NAME ‘ ‘ LT_SE37-TEXT INTO LT_INS_CODE RESPECTING BLANKS .
IF NOT LT_SE37-OPTIONAL IS INITIAL.
CONCATENATE ‘*’ LT_INS_CODE INTO LT_INS_CODE.
ENDIF.
APPEND LT_INS_CODE.
ENDLOOP.
*** IMPORTING.
CLEAR LV_GOT.
LOOP AT LT_SE37 WHERE PARAMTYPE = ‘E’.
IF LV_GOT IS INITIAL.
CONCATENATE ` IMPORTING` SPACE INTO LT_INS_CODE RESPECTING BLANKS .APPEND LT_INS_CODE.
LV_GOT = ‘X’.
ENDIF.
CONCATENATE ` ` LT_SE37-PARAMETER ‘ = ‘ LT_SE37-DEF_NAME ‘ ‘ LT_SE37-TEXT INTO LT_INS_CODE RESPECTING BLANKS .
IF NOT LT_SE37-OPTIONAL IS INITIAL.
CONCATENATE ‘*’ LT_INS_CODE INTO LT_INS_CODE.
ENDIF.
APPEND LT_INS_CODE.
ENDLOOP.
*** TABLES.
CLEAR LV_GOT.
LOOP AT LT_SE37 WHERE PARAMTYPE = ‘T’.
IF LV_GOT IS INITIAL.
CONCATENATE ` TABLES` SPACE INTO LT_INS_CODE RESPECTING BLANKS .
APPEND LT_INS_CODE.
LV_GOT = ‘X’.
ENDIF.
CONCATENATE ` ` LT_SE37-PARAMETER ‘ = ‘ LT_SE37-DEF_NAME ‘ ‘ LT_SE37-TEXT INTO LT_INS_CODE RESPECTING BLANKS .
IF NOT LT_SE37-OPTIONAL IS INITIAL.
CONCATENATE ‘*’ LT_INS_CODE INTO LT_INS_CODE.
ENDIF.
APPEND LT_INS_CODE.
ENDLOOP.
*** CHANGING.
CLEAR LV_GOT.
LOOP AT LT_SE37 WHERE PARAMTYPE = ‘C’.
IF LV_GOT IS INITIAL.
CONCATENATE ` CHANGING` SPACE INTO LT_INS_CODE RESPECTING BLANKS .
APPEND LT_INS_CODE.
LV_GOT = ‘X’.
ENDIF.
CONCATENATE ` ` LT_SE37-PARAMETER ‘ = ‘ LT_SE37-DEF_NAME ‘ ‘ LT_SE37-TEXT INTO LT_INS_CODE RESPECTING BLANKS .
IF NOT LT_SE37-OPTIONAL IS INITIAL.
CONCATENATE ‘*’ LT_INS_CODE INTO LT_INS_CODE.
ENDIF.
APPEND LT_INS_CODE.
ENDLOOP.
*** EXCEPTIONS.
CLEAR LV_GOT.
LOOP AT LT_SE37 WHERE PARAMTYPE = ‘X’.
IF LV_GOT IS INITIAL.
CONCATENATE ` EXCEPTIONS` SPACE INTO LT_INS_CODE RESPECTING BLANKS .APPEND LT_INS_CODE.
LV_GOT = ‘X’.
ENDIF.
LT_SE37-DEF_NAME = LT_SE37-PPOSITION .
CONCATENATE ` ` LT_SE37-PARAMETER ‘ = ‘ LT_SE37-DEF_NAME SPACE INTO LT_INS_CODE RESPECTING BLANKS .
APPEND LT_INS_CODE.
ENDLOOP.
IF LV_GOT = ‘X’.
LT_SE37-DEF_NAME = LT_SE37-DEF_NAME + 1.
LT_SE37-PARAMETER = ‘OTHERS’.
CONCATENATE ` ` LT_SE37-PARAMETER ‘ = ‘ LT_SE37-DEF_NAME ‘.’ SPACE INTO LT_INS_CODE RESPECTING BLANKS .APPEND LT_INS_CODE.
CONCATENATE ` IF SY-SUBRC <> 0.` SPACE INTO LT_INS_CODE RESPECTING BLANKS .APPEND LT_INS_CODE.
CONCATENATE ` MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO DISPLAY LIKE ‘E’ WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4 .` SPACE
INTO LT_INS_CODE RESPECTING BLANKS .APPEND LT_INS_CODE.
CONCATENATE ` RETURN.` SPACE INTO LT_INS_CODE RESPECTING BLANKS .APPEND LT_INS_CODE.
CONCATENATE ` ENDIF.` SPACE INTO LT_INS_CODE RESPECTING BLANKS .APPEND LT_INS_CODE.
ELSE.
CONCATENATE ` .` SPACE INTO LT_INS_CODE RESPECTING BLANKS .APPEND LT_INS_CODE.
ENDIF.
ENDIF.
ENDIF.
IF NOT LT_INS_CODE[] IS INITIAL.
APPEND LINES OF LT_INS_CODE[] TO LT_TMP[].
DELETE MTAB_OLD_PROG[] FROM 1 TO L_FROM_LINE.
APPEND LINES OF MTAB_OLD_PROG[] TO LT_TMP[].
* 设置添加后的代码到编辑器
CALL METHOD GO_EDITOR->SET_TEXT
EXPORTING
TABLE = LT_TMP[]
EXCEPTIONS
ERROR_DP = 1
ERROR_DP_CREATE = 2
ERROR_CODE_PAGE = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
BREAK-POINT.
ENDIF.
GO_EDITOR->SET_FIRST_VISIBLE_LINE( LV_LINE ).
ENDIF.
ENDFORM.
*&———————————————————————*
*& Form FRM_GET_STRUC_TEXT
*&———————————————————————*
*& 获取参数文本.
*&———————————————————————*
FORM FRM_GET_STRUC_TEXT USING UV_STRU CHANGING CV_TEXT CV_FLAG_STRUC.
DATA LV_TAB TYPE C LENGTH 30.
DATA LV_FLD TYPE C LENGTH 30.
CLEAR CV_TEXT.
CLEAR CV_FLAG_STRUC.
IF UV_STRU CS ‘-‘. “变量.
SPLIT UV_STRU AT ‘-‘ INTO LV_TAB LV_FLD.
IF NOT LV_TAB IS INITIAL AND NOT LV_FLD IS INITIAL .
PERFORM FRM_GET_FIELD_TEXT USING LV_TAB LV_FLD CHANGING CV_TEXT.
ENDIF.
ELSE.
SELECT SINGLE DD02T~DDTEXT
INTO CV_TEXT
FROM DD02T
WHERE DD02T~TABNAME = UV_STRU
AND DD02T~DDLANGUAGE = SY-LANGU
AND DD02T~AS4LOCAL = ‘A’ .
IF SY-SUBRC <> 0.
SELECT SINGLE DD02T~DDTEXT
INTO CV_TEXT
FROM DD02T
WHERE DD02T~TABNAME = UV_STRU
AND DD02T~AS4LOCAL = ‘A’
AND DD02T~DDTEXT <> SPACE
.
ENDIF.
IF NOT CV_TEXT IS INITIAL.
CV_FLAG_STRUC = ‘X’.
ELSE.
SELECT SINGLE DD04T~DDTEXT
INTO CV_TEXT
FROM DD04T
WHERE ROLLNAME = UV_STRU
AND DD04T~DDLANGUAGE = SY-LANGU
AND DD04T~AS4LOCAL = ‘A’
.
IF CV_TEXT IS INITIAL.
SELECT SINGLE DD04T~DDTEXT
INTO CV_TEXT
FROM DD04T
WHERE ROLLNAME = UV_STRU
AND DD04T~AS4LOCAL = ‘A’
AND DD04T~DDTEXT <> SPACE
.
ENDIF.
ENDIF.
ENDIF.
IF NOT CV_TEXT IS INITIAL.
CONCATENATE `”` CV_TEXT INTO CV_TEXT.
ENDIF.
ENDFORM.
FORM FRM_FAI.
IF GV_READ_ONLY IS NOT INITIAL.
MESSAGE S398(00) WITH ‘Please Set Code In 【Edit】 Status’.
RETURN.
ENDIF.
DATA LT_TEXT TYPE SOURCE_TABLE WITH HEADER LINE .
* 当前选选中的内容。
PERFORM FRM_GET_SELE TABLES LT_TEXT[].
DATA LV_TAB TYPE STRING VALUE ‘XXX’.
DATA LT_INS_CODE LIKE TABLE OF MTAB_OLD_PROG WITH HEADER LINE.
LT_INS_CODE = ` IF NOT LT_YYY[] IS INITIAL. `.APPEND LT_INS_CODE.
DATA LV_GOT TYPE C LENGTH 1.
CLEAR LV_GOT.
DATA LV_COMM TYPE STRING.
IF LT_TEXT[] IS INITIAL.
APPEND INITIAL LINE TO LT_TEXT.
ENDIF.
LOOP AT LT_TEXT .
CONDENSE LT_TEXT-LINE NO-GAPS.
DATA LT_DD03L TYPE STANDARD TABLE OF DD03L WITH HEADER LINE.
CLEAR LT_DD03L[].
SELECT *
FROM DD03L
INTO CORRESPONDING FIELDS OF TABLE LT_DD03L
WHERE TABNAME = LT_TEXT
AND KEYFLAG = ‘X’.
DELETE LT_DD03L WHERE FIELDNAME = ‘MANDT’.
SORT LT_DD03L BY POSITION.
IF NOT LT_DD03L[] IS INITIAL.
LOOP AT LT_DD03L.
LV_TAB = LT_DD03L-TABNAME.
PERFORM FRM_GET_FIELD_TEXT USING LT_DD03L-TABNAME LT_DD03L-FIELDNAME CHANGING LV_COMM.
IF LV_GOT IS INITIAL.
SELECT SINGLE DDTEXT
FROM DD02T
INTO LT_INS_CODE
WHERE TABNAME = LV_TAB
AND DDLANGUAGE = SY-LANGU.
IF SY-SUBRC <> 0.
SELECT SINGLE DDTEXT
FROM DD02T
INTO LT_INS_CODE
WHERE TABNAME = LV_TAB
AND DDTEXT <> SPACE.
ENDIF.
CONCATENATE ‘* ‘ LT_INS_CODE INTO LT_INS_CODE RESPECTING BLANKS.
APPEND LT_INS_CODE.
CONCATENATE ` DATA LT_` LV_TAB ` TYPE STANDARD TABLE OF ` LV_TAB ‘.’ INTO LT_INS_CODE RESPECTING BLANKS .APPEND LT_INS_CODE.
CONCATENATE ` SELECT ` LT_DD03L-FIELDNAME ` “` LV_COMM INTO LT_INS_CODE RESPECTING BLANKS .APPEND LT_INS_CODE.
LV_GOT = ‘X’.
ELSE.
CONCATENATE ` ` LT_DD03L-FIELDNAME ` “` LV_COMM INTO LT_INS_CODE RESPECTING BLANKS .APPEND LT_INS_CODE.
ENDIF.
ENDLOOP.
CONCATENATE ` INTO CORRESPONDING FIELDS OF TABLE LT_` LV_TAB INTO LT_INS_CODE RESPECTING BLANKS .APPEND LT_INS_CODE.
CONCATENATE ` FROM ` LV_TAB INTO LT_INS_CODE RESPECTING BLANKS .APPEND LT_INS_CODE.
LT_INS_CODE = ` FOR ALL ENTRIES IN LT_YYY`.APPEND LT_INS_CODE.
CLEAR LV_GOT.
LOOP AT LT_DD03L.
LV_TAB = LT_DD03L-TABNAME.
PERFORM FRM_GET_FIELD_TEXT USING LT_DD03L-TABNAME LT_DD03L-FIELDNAME CHANGING LV_COMM.
IF LV_GOT IS INITIAL.
CONCATENATE ` WHERE ` LT_DD03L-FIELDNAME ` = LT_YYY-` LT_DD03L-FIELDNAME ` “` LV_COMM INTO LT_INS_CODE RESPECTING BLANKS .APPEND LT_INS_CODE.
LV_GOT = ‘X’.
ELSE.
CONCATENATE ` AND ` LT_DD03L-FIELDNAME ` = LT_YYY-` LT_DD03L-FIELDNAME ` “` LV_COMM INTO LT_INS_CODE RESPECTING BLANKS .APPEND LT_INS_CODE.
ENDIF.
ENDLOOP.
ELSE.
LT_INS_CODE = ` DATA LT_XXX TYPE STANDARD TABLE OF AAAA.”`.APPEND LT_INS_CODE.
LT_INS_CODE = ` SELECT A “`.APPEND LT_INS_CODE.
LT_INS_CODE = ` B “`.APPEND LT_INS_CODE.
LT_INS_CODE = ` c “`.APPEND LT_INS_CODE.
LT_INS_CODE = ` D ” `.APPEND LT_INS_CODE.
CONCATENATE ` INTO CORRESPONDING FIELDS OF TABLE LT_` LV_TAB INTO LT_INS_CODE RESPECTING BLANKS .APPEND LT_INS_CODE.
LT_INS_CODE = ` FROM AAAA`.APPEND LT_INS_CODE.
LT_INS_CODE = ` FOR ALL ENTRIES IN LT_YYY`.APPEND LT_INS_CODE.
LT_INS_CODE = ` WHERE A = LT_YYY-A`.APPEND LT_INS_CODE.
LT_INS_CODE = ` AND B = LT_YYY-B`.APPEND LT_INS_CODE.
ENDIF.
LT_INS_CODE = ` .`.APPEND LT_INS_CODE.
LT_INS_CODE = ` ENDIF.`.APPEND LT_INS_CODE.
EXIT.
ENDLOOP.
PERFORM FRM_INSERT_CODE TABLES LT_INS_CODE[] USING ”.
ENDFORM.
*&———————————————————————*
*& Form FRM_INSERT_CODE
*&———————————————————————*
*& 当前行插入一系列死代码。
*&———————————————————————*
FORM FRM_INSERT_CODE TABLES T_CODE
USING UV_LINE TYPE C.
DATA: L_FROM_col TYPE I,
L_TO_col TYPE I,
L_FROM_NEW TYPE I,
L_TO_NEW TYPE I,
L_FROM_LINE TYPE I,
L_TO_LINE TYPE I,
L_LEN TYPE I,
LV_LINES TYPE I,
LV_MIDDLE_STRING TYPE STRING,
LT_TEXT TYPE SOURCE_TABLE WITH HEADER LINE.
* 记录好代码位置。
CALL METHOD GO_EDITOR->GET_FIRST_VISIBLE_LINE( IMPORTING LINE = LV_LINE ).
IF UV_LINE IS NOT INITIAL.
LV_LINE = UV_LINE.
ENDIF.
* 获取双击的时候的行,列。
PERFORM FRM_GET_ALL_CODE TABLES MTAB_OLD_PROG[]
CHANGING L_FROM_LINE L_FROM_col L_TO_LINE L_TO_col.
IF UV_LINE IS NOT INITIAL.
L_FROM_LINE = UV_LINE.
ENDIF.
CLEAR MTAB_OLD_PROG.
READ TABLE MTAB_OLD_PROG INDEX L_FROM_LINE.
DATA LT_TMP LIKE TABLE OF MTAB_OLD_PROG WITH HEADER LINE.
* 保留到当前行的
LT_TMP[] = MTAB_OLD_PROG[].
DELETE LT_TMP[] FROM L_FROM_LINE TO 99999.
APPEND MTAB_OLD_PROG TO LT_TMP.
APPEND LINES OF T_CODE[] TO LT_TMP[].
* 保留之后的
DELETE MTAB_OLD_PROG[] FROM 1 TO L_FROM_LINE.
APPEND LINES OF MTAB_OLD_PROG[] TO LT_TMP[].
* 设置添加后的代码到编辑器
CALL METHOD GO_EDITOR->SET_TEXT
EXPORTING
TABLE = LT_TMP[]
EXCEPTIONS
ERROR_DP = 1
ERROR_DP_CREATE = 2
ERROR_CODE_PAGE = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
BREAK-POINT.
ENDIF.
GO_EDITOR->SET_FIRST_VISIBLE_LINE( LV_LINE ).
ENDFORM.
*&———————————————————————*
*& Form FRM_GET_FIELD_TEXT
*&———————————————————————*
*& 获取字段文本.
*&———————————————————————*
FORM FRM_GET_FIELD_TEXT USING LV_TAB
LV_FLD
CHANGING CV_TEXT.
CLEAR CV_TEXT.
SELECT SINGLE DD04T~SCRTEXT_L
INTO CV_TEXT
FROM DD03L
INNER JOIN DD04T
ON DD03L~ROLLNAME = DD04T~ROLLNAME
WHERE DD03L~TABNAME = LV_TAB
AND DD03L~FIELDNAME = LV_FLD
AND DD03L~AS4LOCAL = ‘A’
AND DD04T~DDLANGUAGE = SY-LANGU
AND DD04T~AS4LOCAL = ‘A’.
IF CV_TEXT IS INITIAL.
SELECT SINGLE DD03T~DDTEXT
INTO CV_TEXT
FROM DD03T
WHERE DD03T~TABNAME = LV_TAB
AND DD03T~DDLANGUAGE = SY-LANGU
AND DD03T~AS4LOCAL = ‘A’
AND DD03T~FIELDNAME = LV_FLD.
ENDIF.
IF CV_TEXT IS INITIAL.
SELECT SINGLE DD04T~SCRTEXT_L
INTO CV_TEXT
FROM DD03L
INNER JOIN DD04T
ON DD03L~ROLLNAME = DD04T~ROLLNAME
WHERE DD03L~TABNAME = LV_TAB
AND DD03L~FIELDNAME = LV_FLD
AND DD03L~AS4LOCAL = ‘A’
AND DD04T~SCRTEXT_L <> SPACE
AND DD04T~AS4LOCAL = ‘A’.
ENDIF.
IF CV_TEXT IS INITIAL.
SELECT SINGLE DD03T~DDTEXT
INTO CV_TEXT
FROM DD03T
WHERE DD03T~TABNAME = LV_TAB
AND DD03T~AS4LOCAL = ‘A’
AND DD03T~FIELDNAME = LV_FLD
AND DD03T~DDTEXT <> SPACE
.
ENDIF.
ENDFORM.
FORM FRM_ALV_DEMO.
IF GV_READ_ONLY IS NOT INITIAL.
MESSAGE S398(00) WITH ‘Please Set Code In 【Edit】 Status’.
RETURN.
ENDIF.
DATA LT_INS_CODE LIKE TABLE OF MTAB_OLD_PROG WITH HEADER LINE.
PERFORM FRM_GET_CODE TABLES LT_INS_CODE USING P_USER P_PASS ‘ALV_DEMO2’.
PERFORM FRM_INSERT_CODE TABLES LT_INS_CODE[] USING ”.
ENDFORM.
FORM FRM_BIN_SEA.
IF GV_READ_ONLY IS NOT INITIAL.
MESSAGE S398(00) WITH ‘Please Set Code In 【Edit】 Status’.
RETURN.
ENDIF.
DATA LT_INS_CODE LIKE TABLE OF MTAB_OLD_PROG WITH HEADER LINE.
LT_INS_CODE = ` CLEAR LWA_FOUND.`.APPEND LT_INS_CODE.
LT_INS_CODE = ` READ TABLE GT_KEY_INFO INTO LWA_FOUND `.APPEND LT_INS_CODE.
LT_INS_CODE = ` WITH KEY KEY2 = NODE_KEY`.APPEND LT_INS_CODE.
LT_INS_CODE = ` KEY2 = NODE_KEY`.APPEND LT_INS_CODE.
LT_INS_CODE = ` BINARY SEARCH.`.APPEND LT_INS_CODE.
LT_INS_CODE = ` IF SY-SUBRC = 0.`.APPEND LT_INS_CODE.
LT_INS_CODE = ` LWA_ALV- = LWA_FOUND-.`.APPEND LT_INS_CODE.
LT_INS_CODE = “.APPEND LT_INS_CODE.
LT_INS_CODE = ` ENDIF.`.APPEND LT_INS_CODE.
PERFORM FRM_INSERT_CODE TABLES LT_INS_CODE[] USING ”.
ENDFORM.
FORM FRM_SAVE_COD.
DATA: L_FROM_col TYPE I,
L_TO_col TYPE I,
L_FROM_NEW TYPE I,
L_TO_NEW TYPE I,
L_FROM_LINE TYPE I,
L_TO_LINE TYPE I,
L_LEN TYPE I,
LV_LINES TYPE I,
LV_MIDDLE_STRING TYPE STRING,
LT_TEXT TYPE SOURCE_TABLE WITH HEADER LINE.
* 获取双击的时候的行,列。
PERFORM FRM_GET_ALL_CODE TABLES MTAB_OLD_PROG[]
CHANGING L_FROM_LINE L_FROM_col L_TO_LINE L_TO_col.
**********************************************************************
**********************************************************************
DATA WA_TXT TYPE C LENGTH 300.
DATA WA_POOL TYPE TEXTPOOL.
DATA GT_POOL TYPE TABLE OF TEXTPOOL.
DATA WA_STR TYPE STRING.
READ TEXTPOOL P_BOR INTO GT_POOL.
IF SY-SUBRC = 0.
WA_TXT = ‘*@@@@@@@textelement’.
APPEND WA_TXT TO MTAB_OLD_PROG.
LOOP AT GT_POOL INTO WA_POOL.
CONCATENATE ‘@ID@’
WA_POOL-ID
‘@KEY@’
WA_POOL-KEY
‘@ENTRY@’
WA_POOL-ENTRY
‘@LENGTH@’
INTO WA_STR.
APPEND WA_STR TO MTAB_OLD_PROG.
ENDLOOP.
ENDIF.
DO 3 TIMES.
IF NOT LV_DESK IS INITIAL.
EXIT.
ENDIF.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>GET_DESKTOP_DIRECTORY
CHANGING
DESKTOP_DIRECTORY = LV_DESK
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
NOT_SUPPORTED_BY_GUI = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
ENDDO.
CHECK NOT LV_DESK IS INITIAL.
DATA LV_STR TYPE STRING.
CONCATENATE LV_DESK ‘\\SAP_CODE\\’ P_BOR ‘_’ SY-DATUM ‘_’ SY-UZEIT ‘.TXT’ INTO LV_STR.
CALL FUNCTION ‘GUI_DOWNLOAD’
EXPORTING
FILENAME = LV_STR
TABLES
DATA_TAB = MTAB_OLD_PROG[]
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 .
MESSAGE I398(00) WITH P_BOR ‘Source code saved to Desktop.’.
ENDIF.
ENDFORM.
FORM FRM_DEL_DUP.
IF GV_READ_ONLY IS NOT INITIAL.
MESSAGE S398(00) WITH ‘Please Set Code In 【Edit】 Status’.
RETURN.
ENDIF.
DATA LT_INS_CODE LIKE TABLE OF MTAB_OLD_PROG WITH HEADER LINE.
LT_INS_CODE = ` SORT LT_XXXXXXXXX BY A `.APPEND LT_INS_CODE.
LT_INS_CODE = ` B`.APPEND LT_INS_CODE.
LT_INS_CODE = ` C.`.APPEND LT_INS_CODE.
LT_INS_CODE = ` DELETE ADJACENT DUPLICATES FROM LT_XXXXXXXXX COMPARING A`.APPEND LT_INS_CODE.
LT_INS_CODE = ` B`.APPEND LT_INS_CODE.
LT_INS_CODE = ` C.`.APPEND LT_INS_CODE.
PERFORM FRM_INSERT_CODE TABLES LT_INS_CODE[] USING ”.
ENDFORM.
FORM FRM_ADD_LOG.
IF GV_READ_ONLY IS NOT INITIAL.
MESSAGE S398(00) WITH ‘Please Set Code In 【Edit】 Status’.
RETURN.
ENDIF.
DATA LT_INS_CODE LIKE TABLE OF MTAB_OLD_PROG WITH HEADER LINE.
DATA LV_US TYPE STRING.
LV_US = SY-UNAME.
CONCATENATE ‘*{-BEGIN OF MODIFY BY ‘ LV_US ‘ ON ‘ SY-DATUM+0(4) ‘-‘ SY-DATUM+4(2) ‘-‘ SY-DATUM+6(2) ‘ ‘ SY-UZEIT ‘.’ INTO LT_INS_CODE RESPECTING BLANKS.
APPEND LT_INS_CODE.
CONCATENATE ‘*}-END OF MODIFY BY ‘ LV_US ‘ ON ‘ SY-DATUM+0(4) ‘-‘ SY-DATUM+4(2) ‘-‘ SY-DATUM+6(2) ‘ ‘ SY-UZEIT ‘.’ INTO LT_INS_CODE RESPECTING BLANKS.
APPEND LT_INS_CODE.
PERFORM FRM_INSERT_CODE TABLES LT_INS_CODE[] USING ”.
ENDFORM.
FORM FRM_JUMP2BEG.
DATA LV_I TYPE I.
PERFORM FRM_JUMP2 USING ‘START-OF-SELECTION.’ CHANGING LV_I.
ENDFORM.
FORM FRM_JUMP2END.
DATA LV_I TYPE I.
PERFORM FRM_JUMP2 USING ‘END-OF-SELECTION.’ CHANGING LV_I..
ENDFORM.
FORM FRM_JUMP2INT.
DATA LV_I TYPE I.
PERFORM FRM_JUMP2 USING ‘INITIALIZATION.’ CHANGING LV_I..
ENDFORM.
FORM FRM_JUMP2SCR.
DATA LV_I TYPE I.
PERFORM FRM_JUMP2 USING ‘PARAMETERS’ CHANGING LV_I.
IF LV_I IS INITIAL.
PERFORM FRM_JUMP2 USING ‘SELECT-OPTIONS’ CHANGING LV_I.
ENDIF.
ENDFORM.
*&———————————————————————*
*& 跳转到
*&———————————————————————*
FORM FRM_JUMP2 USING UV_TEXT CHANGING LV_I.
DATA: L_FROM_col TYPE I,
L_TO_col TYPE I,
L_FROM_NEW TYPE I,
L_TO_NEW TYPE I,
L_FROM_LINE TYPE I,
L_TO_LINE TYPE I,
L_LEN TYPE I,
LV_LINES TYPE I,
LV_MIDDLE_STRING TYPE STRING,
LT_TEXT TYPE SOURCE_TABLE WITH HEADER LINE.
* 记录好代码位置。
CALL METHOD GO_EDITOR->GET_FIRST_VISIBLE_LINE( IMPORTING LINE = LV_LINE ).
* 获取双击的时候的行,列。
PERFORM FRM_GET_ALL_CODE TABLES MTAB_OLD_PROG[]
CHANGING L_FROM_LINE L_FROM_col L_TO_LINE L_TO_col.
DATA LV_GOT TYPE C.
CLEAR MTAB_OLD_PROG.
CLEAR LV_I.
LOOP AT MTAB_OLD_PROG.
LV_I = LV_I + 1.
CONDENSE MTAB_OLD_PROG NO-GAPS.
TRANSLATE MTAB_OLD_PROG TO UPPER CASE.
IF MTAB_OLD_PROG CS UV_TEXT .
LV_GOT = ‘X’.
EXIT.
ENDIF.
ENDLOOP.
IF LV_GOT IS INITIAL.
CLEAR LV_I.
ENDIF.
CHECK NOT LV_GOT IS INITIAL.
GO_EDITOR->SET_FIRST_VISIBLE_LINE( LV_I ).
ENDFORM.
*&———————————————————————*
*& Form FRM_SET_BP
*&———————————————————————*
*& 设置断点.
*&———————————————————————*
FORM FRM_SET_BP USING IS_SET LINE .
IF IS_SET = 1.
CALL FUNCTION ‘RS_SET_BREAKPOINT’
EXPORTING
INDEX = LINE
PROGRAM = P_BOR
MAINPROGRAM = P_BOR
* HTTP_DEBUGGING = ‘ ‘
* WITHOUT_DIALOG = ‘ ‘
BP_TYPE = ‘S’
* NO_MESSAGE = ‘ ‘
* IMPORTING
* O_INDEX =
EXCEPTIONS
NOT_EXECUTED = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
RETURN.
ENDIF.
ELSE.
CALL FUNCTION ‘RS_DELETE_BREAKPOINT’
EXPORTING
INDEX = LINE
MAINPROG = P_BOR
PROGRAM = P_BOR
* HTTP_DEBUGGING = ‘ ‘
BP_TYPE = ‘S’
* NO_MESSAGE = ‘ ‘
* IMPORTING
* NOT_ANY_BREAK =
.
ENDIF.
ENDFORM.
FORM FRM_BAPIS.
DATA LV_URLL TYPE C LENGTH 300.
LV_URLL = GV_WEBSITE && ‘search/?s=BAPI_’.
CALL FUNCTION ‘CALL_BROWSER’
EXPORTING
URL = LV_URLL
* WINDOW_NAME = ‘ ‘
* NEW_WINDOW = ‘ ‘
* BROWSER_TYPE =
* CONTEXTSTRING =
EXCEPTIONS
FRONTEND_NOT_SUPPORTED = 1
FRONTEND_ERROR = 2
PROG_NOT_FOUND = 3
NO_BATCH = 4
UNSPECIFIED_ERROR = 5
OTHERS = 6.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
ENDFORM.
FORM FRM_MY_INFO.
DATA LV_URLL TYPE C LENGTH 300.
LV_URLL = GV_WEBSITE.
CALL FUNCTION ‘CALL_BROWSER’
EXPORTING
URL = LV_URLL
* WINDOW_NAME = ‘ ‘
* NEW_WINDOW = ‘ ‘
* BROWSER_TYPE =
* CONTEXTSTRING =
EXCEPTIONS
FRONTEND_NOT_SUPPORTED = 1
FRONTEND_ERROR = 2
PROG_NOT_FOUND = 3
NO_BATCH = 4
UNSPECIFIED_ERROR = 5
OTHERS = 6.
IF SY-SUBRC <> 0.
* Implement suitable error handling here
ENDIF.
* & & & &
ENDFORM.
*&———————————————————————*
*&
*&———————————————————————*
FORM FRM_GET_CODE TABLES T_CODE
USING UV_USER
UV_PASS
UV_CODE
.
DATA LV_USER TYPE C LENGTH 20.
DATA LV_PASS TYPE C LENGTH 20.
CLEAR T_CODE[].
LV_USER = UV_USER.
LV_PASS = UV_PASS.
IF UV_USER IS INITIAL AND UV_PASS IS INITIAL.
LV_USER = ‘FREE’.
LV_PASS = ‘FreeAccount2023hot58’.
ENDIF.
DATA LV_URL TYPE STRING.
*http://www.hot583.com/HOT583_IF/SAP.PHP?account=test&password=123456&date=20231126&time=163600&privateKey=SAP2023&md5Hash=216f79d59049295031fedc1cdb956651&apiId=api01
DATA LV_privateKey TYPE C LENGTH 30 VALUE ‘SAP2023’.
DATA LV_MD5 TYPE STRING.
GET TIME.
DATA LV_TIME TYPE SY-UZEIT.
LV_TIME = SY-UZEIT.
CONCATENATE SY-DATUM LV_TIME LV_privateKey INTO LV_MD5.
PERFORM MD5_ENCODE USING LV_MD5 CHANGING LV_MD5.
CONCATENATE GV_WEBSITE ‘HOT583_IF/SAP.PHP?account=’ LV_USER
`&password=` LV_PASS
`&date=` SY-DATUM
`&time=` LV_TIME
`&md5Hash=` LV_MD5
`&apiId=` UV_CODE
INTO LV_URL.
DATA LV_RET TYPE STRING.
PERFORM POST_XML USING LV_URL
CHANGING LV_RET.
IF LV_RET = `{“data”:false}`.
MESSAGE S398(00) WITH ‘Got Source Code Failed.go To ‘ ‘WWW.HOT583.COM See Detail.’.
RETURN.
* & & & &
.
ENDIF.
DATA LV_CODE TYPE STRING.
SPLIT LV_RET AT `”,”zline”:”` INTO LV_RET LV_CODE.
DATA LT_STR_CODE TYPE STANDARD TABLE OF STRING WITH HEADER LINE.
REPLACE ALL OCCURRENCES OF `\\”` IN LV_CODE WITH `”`.
REPLACE ALL OCCURRENCES OF `\/` IN LV_CODE WITH `/`.
REPLACE ALL OCCURRENCES OF `\\/` IN LV_CODE WITH `/`.
SPLIT LV_CODE AT `\\r\\n` INTO TABLE LT_STR_CODE.
* REPORT ZDEMO NO STANDARD PAGE \\r\\n
LOOP AT LT_STR_CODE.
T_CODE = LT_STR_CODE.
APPEND T_CODE.
ENDLOOP.
DATA LV_CNT TYPE I.
DESCRIBE TABLE T_CODE LINES LV_CNT.
LOOP AT T_CODE FROM LV_CNT TO LV_CNT.
REPLACE ALL OCCURRENCES OF `”}}` IN T_CODE WITH SPACE.
MODIFY T_CODE.
ENDLOOP.
ENDFORM.
FORM MD5_ENCODE USING UV_BASE64 TYPE STRING
CHANGING CV_MD5 TYPE STRING.
DATA:LV_HASH TYPE HASH160,
LV_LEN TYPE I,
LV_STR TYPE STRING,
LV_HASHLEN TYPE I,
LV_HASHX TYPE HASH160X,
LV_HASHXLEN TYPE I.
LV_LEN = STRLEN( UV_BASE64 ).
LV_STR = UV_BASE64.
CLEAR CV_MD5.
CALL FUNCTION ‘CALCULATE_HASH_FOR_CHAR’
EXPORTING
ALG = ‘MD5’
DATA = LV_STR
LENGTH = LV_LEN
IMPORTING
HASH = LV_HASH
HASHLEN = LV_HASHLEN
HASHX = LV_HASHX
HASHXLEN = LV_HASHXLEN
EXCEPTIONS
UNKNOWN_ALG = 1
PARAM_ERROR = 2
INTERNAL_ERROR = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
MESSAGE E398(00) WITH ‘CALCULATE_HASH_FOR_CHAR’ SPACE SPACE SPACE.
* & & & &
ELSE.
TRANSLATE LV_HASH TO LOWER CASE.
CV_MD5 = LV_HASH.
ENDIF.
ENDFORM.
FORM POST_XML USING UV_LINK TYPE STRING
CHANGING CV_RETURN TYPE STRING.
CLEAR CV_RETURN.
DATA:LV_DATA TYPE STRING,
LV_SUBRC TYPE SY-SUBRC,
LV_MSG TYPE STRING.
* 根据链接地址获取 client
DATA GV_CLIENT TYPE REF TO IF_HTTP_CLIENT.
CALL METHOD CL_HTTP_CLIENT=>CREATE_BY_URL
EXPORTING
URL = UV_LINK
IMPORTING
CLIENT = GV_CLIENT
EXCEPTIONS
ARGUMENT_NOT_FOUND = 1
PLUGIN_NOT_ACTIVE = 2
INTERNAL_ERROR = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
RETURN.
ENDIF.
GV_CLIENT->REQUEST->SET_HEADER_FIELD( NAME = ‘~request_method’
VALUE = ‘GET’ ).
* 发送 Send the request
CALL METHOD GV_CLIENT->SEND
EXPORTING
TIMEOUT = 300
EXCEPTIONS
HTTP_COMMUNICATION_FAILURE = 1
HTTP_INVALID_STATE = 2
HTTP_PROCESSING_FAILED = 3
HTTP_INVALID_TIMEOUT = 4
OTHERS = 5.
IF SY-SUBRC <> 0.
RETURN.
ENDIF.
* Reterive the result
CALL METHOD GV_CLIENT->RECEIVE
EXCEPTIONS
HTTP_COMMUNICATION_FAILURE = 1
HTTP_INVALID_STATE = 2
HTTP_PROCESSING_FAILED = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
CALL METHOD GV_CLIENT->GET_LAST_ERROR
IMPORTING
CODE = LV_SUBRC
MESSAGE = LV_MSG.
MESSAGE E398(00) WITH ‘Reterive the result ‘ SPACE SPACE SPACE.
ELSE.
ENDIF.
LV_DATA = GV_CLIENT->RESPONSE->GET_CDATA( ).
CV_RETURN = LV_DATA.
* close
CALL METHOD GV_CLIENT->CLOSE
EXCEPTIONS
HTTP_INVALID_STATE = 1
OTHERS = 2.
ENDFORM.
*&———————————————————————*
*& Form FRM_INIT
*&———————————————————————*
*& 初始化。
*&———————————————————————*
FORM FRM_INIT .
GV_REPID = SY-REPID.
%_P_BOR_%_APP_%-TEXT = ‘Report Name’.
SY-TITLE = ‘DIY SAP ABAP Editor’.
SELECT SINGLE PROG
FROM D020S
INTO GV_REPID
WHERE PROG = SY-REPID.
CHECK NOT SY-SUBRC <> 0.
PERFORM FRM_CREATE_DYNPRO USING SY-REPID ‘0100’.
ENDFORM.
FORM FRM_CREATE_DYNPRO USING UV_REPID UV_NUM.
DATA:LV_MESSAGE_TEXT TYPE STRING,
LV_SCREEN_LINE TYPE STRING,
LV_INCORRECTWORD TYPE STRING,
LS_FIELD_LIST TYPE D021S,
LT_FIELD_LIST TYPE TABLE OF D021S WITH HEADER LINE,
LT_FLOW_LOGIC TYPE TABLE OF D022S WITH HEADER LINE,
LT_SCREEN_HEADER TYPE TABLE OF D020S WITH HEADER LINE,
LS_HEADER TYPE D020S,
LV_DYNPRO TYPE CHAR44,
LT_ATTRIB TYPE TABLE OF D023S WITH HEADER LINE.
LS_FIELD_LIST-FNAM = ‘CONT’.
LS_FIELD_LIST-DIDX = ‘0027’.
LS_FIELD_LIST-FLG1 = ’00’.
LS_FIELD_LIST-FLG2 = ’00’.
LS_FIELD_LIST-FLG3 = ’00’.
LS_FIELD_LIST-FILL = ‘U’.
LS_FIELD_LIST-FMB1 = ’30’.
LS_FIELD_LIST-LENG = ‘DD’.
LS_FIELD_LIST-LINE = ’01’.
LS_FIELD_LIST-COLN = ’02’.
LS_FIELD_LIST-AUTH = ‘101’.
LS_FIELD_LIST-AGLT = ’01’.
LS_FIELD_LIST-ADEZ = ’01’.
APPEND LS_FIELD_LIST TO LT_FIELD_LIST.
CLEAR LS_FIELD_LIST.
LS_FIELD_LIST-FNAM = ‘OK_CODE’.
LS_FIELD_LIST-FLG1 = ’80’.
LS_FIELD_LIST-DIDX = ‘0000’.
LS_FIELD_LIST-FLG2 = ’10’.
LS_FIELD_LIST-FLG3 = ’00’.
LS_FIELD_LIST-FILL = ”.
LS_FIELD_LIST-LTYP = ‘O’.
LS_FIELD_LIST-FMB1 = ’00’.
LS_FIELD_LIST-LENG = ’14’.
LS_FIELD_LIST-LINE = ‘FF’.
LS_FIELD_LIST-COLN = ’01’.
LS_FIELD_LIST-TYPE = ‘CHAR’.
LS_FIELD_LIST-AGLT = ’00’.
LS_FIELD_LIST-ADEZ = ’00’.
LS_FIELD_LIST-STXT = ‘____________________’.
APPEND LS_FIELD_LIST TO LT_FIELD_LIST.
CLEAR LS_FIELD_LIST.
LV_DYNPRO = UV_REPID.
LV_DYNPRO+40(4) = UV_NUM.
LT_FLOW_LOGIC-LINE = `PROCESS BEFORE OUTPUT.`. APPEND LT_FLOW_LOGIC.
LT_FLOW_LOGIC-LINE = ` MODULE STATUS_0100.`. APPEND LT_FLOW_LOGIC.
LT_FLOW_LOGIC-LINE = `PROCESS AFTER INPUT.`. APPEND LT_FLOW_LOGIC.
LT_FLOW_LOGIC-LINE = ` MODULE USER_COMMAND_0100.`. APPEND LT_FLOW_LOGIC.
LT_SCREEN_HEADER-PROG = UV_REPID.
LT_SCREEN_HEADER-FNUM = UV_NUM.
LT_SCREEN_HEADER-DNUM = UV_NUM.
LT_SCREEN_HEADER-BZMX = 39.
LT_SCREEN_HEADER-BZBR = 221.”定义长度
LT_SCREEN_HEADER-MILI = 192.
LT_SCREEN_HEADER-MICO = 37.
LT_SCREEN_HEADER-NOLI = 39.”高度”
LT_SCREEN_HEADER-CUAN = ‘G’.
LT_SCREEN_HEADER-NOCO = 224.
LT_SCREEN_HEADER-SPRA = SY-LANGU.
APPEND LT_SCREEN_HEADER.
SYNTAX-CHECK FOR DYNPRO LT_SCREEN_HEADER
LT_FIELD_LIST
LT_FLOW_LOGIC
LT_ATTRIB
MESSAGE LV_MESSAGE_TEXT LINE LV_SCREEN_LINE WORD LV_INCORRECTWORD.
CHECK SY-SUBRC = 0.
EXPORT DYNPRO LT_SCREEN_HEADER
LT_FIELD_LIST
LT_FLOW_LOGIC
LT_ATTRIB ID LV_DYNPRO.
CHECK SY-SUBRC = 0.
GENERATE DYNPRO LT_SCREEN_HEADER
LT_FIELD_LIST
LT_FLOW_LOGIC
LT_ATTRIB
ID LV_DYNPRO
MESSAGE LV_MESSAGE_TEXT LINE LV_SCREEN_LINE WORD LV_INCORRECTWORD. “#EC CI_GENERATE
MESSAGE S398(00) WITH ‘ok’ LV_MESSAGE_TEXT.
ENDFORM. ” FRM_CREATE_DYNPR
This post is come from www.hot583.com, you can share/use it with the post original link for free.
But pay attention of any risk yourself.
微信原文《The End》