对于对SAP不是很熟悉的人来说,查表是件痛苦的事,对于ABAPER菜鸟来说更是痛苦,为些我写了一个查表程序,大多数情况下我是用它来找表的。
*&***************************************************************
*& Finding the table thru a field or field description , tables
*& description,Element,etc.
*& Creation Date: 2008-01-24
*& Created BY : Michael Chow
*&****************************************************************
REPORT ZKFTB.
PARAMETERS: p_tb LIKE DD02L-TABNAME, "Table Name
p_tbTx LIKE DD02T-DDTEXT, "Table Name
p_fld LIKE DD03L-FIELDNAME, "Field Name
P_fldTx LIKE DD04T-DDTEXT,
p_cls LIKE DD02L-TABCLASS DEFAULT 'TRANSP', "Table category
p_ROLL LIKE DD03L-ROLLNAME, "Element
P_value(80) TYPE C, "Field Value
p_lang LIKE DD02T-DDLANGUAGE DEFAULT 'EN'. "Language
TYPE-POOLS: SLIS.
DATA: WA_LINE TYPE SLIS_FIELDCAT_ALV.
DATA: IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV .
DATA: WA_LAYOUT TYPE SLIS_LAYOUT_ALV.
DATA: IT_SORT TYPE SLIS_T_SORTINFO_ALV WITH HEADER LINE.
DATA: BEGIN OF IT_Tab OCCURS 0,
TABNAME LIKE DD02L-TABNAME,
TABCLASS LIKE DD02L-TABCLASS,
TABTEXT LIKE DD02T-DDTEXT,
FIELDNAME LIKE DD03L-FIELDNAME,
DATATYPE LIKE DD03L-DATATYPE,
ROLLNAME LIKE DD04T-ROLLNAME,
FILDTEXT LIKE DD04T-DDTEXT,
DEL_IND(1) TYPE C. "Deleted indicator.
DATA: END OF IT_Tab.
DATA: g_command_form TYPE slis_formname VALUE 'USER_COMMAND',
it_event TYPE slis_t_event,
wa_event TYPE slis_alv_event,
g_repid LIKE sy-repid.
INITIALIZATION.
g_repid = sy-repid.
START-OF-SELECTION.
PERFORM PERFORMSQL.
PERFORM ALV_FIELDS.
PERFORM Dispaly_ALV.
END-OF-SELECTION.
*e+ Delete reducing Informaton from Internal Table
FORM Clean_DATA.
*DATA: v_value TYPE REF TO DATA,
* V_INDEX like sy-tabix.
*
*FIELD-SYMBOLS <FS> TYPE ANY.
*
*
*if ( p_value is not initial )
* AND ( p_fld is not initial )
* AND LINES( IT_TAB ) > 0.
* Loop at it_tab where Fieldname = p_fld.
* V_INDEX = SY-TABIX.
* if sy-subrc NE 0.
* it_tab-del_ind = 'X'.
* modify it_tab index v_index.
* else.
* ASSIGN it_tab-FIELDNAME TO <FS>.
*
*
ENDFORM.
FORM Dispaly_ALV.
DATA:
report_name LIKE sy-repid,
alvlo_stb TYPE slis_layout_alv.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
IT_FIELDCAT = IT_FIELDCAT[]
IS_LAYOUT = WA_LAYOUT
I_callback_program = g_repid
i_callback_user_command = g_command_form
it_events = it_event
IT_SORT = IT_SORT[]
TABLES
T_OUTTAB = IT_Tab
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM.
DEFINE APPEND_ALV_FIELD.
CLEAR WA_LINE .
WA_LINE-FIELDNAME = &1.
WA_LINE-SELTEXT_L = &2.
WA_LINE-SELTEXT_M = &2.
WA_LINE-SELTEXT_S = &2.
WA_LINE-CFIELDNAME = &3.
WA_LINE-TECH = &4.
WA_LINE-QFIELDNAME = &5.
WA_LINE-EDIT_MASK = &6.
WA_LINE-OUTPUTLEN = &7.
WA_LINE-DDICTXT = 'L'.
APPEND WA_LINE TO IT_FIELDCAT.
END-OF-DEFINITION .
FORM ALV_FIELDS .
CLEAR IT_FIELDCAT[].
APPEND_ALV_FIELD 'TABNAME' TEXT-H01 '' '' '' '' 10.
APPEND_ALV_FIELD 'TABCLASS' TEXT-H02 '' '' '' '' 10.
APPEND_ALV_FIELD 'TABTEXT' TEXT-H03 '' '' '' '' 30.
APPEND_ALV_FIELD 'FIELDNAME' TEXT-H04 '' '' '' '' 15.
APPEND_ALV_FIELD 'DATATYPE' TEXT-H08 '' '' '' '' 10.
APPEND_ALV_FIELD 'ROLLNAME' TEXT-H05 '' '' '' '' 15.
APPEND_ALV_FIELD 'FILDTEXT' TEXT-H06 '' '' '' '' 30.
* APPEND_ALV_FIELD 'Language' TEXT-H07 '' '' '' '' 10.
ENDFORM. " ALV_FIELDS
FORM PERFORMSQL.
DATA: SQLstr(72) TYPE c,
itabSQL LIKE TABLE OF SQLstr,
v_text(30) TYPE C.
CONCATENATE SPACE 't2~DDLANGUAGE = ''' p_lang '''' INTO SQLstr.
CONCATENATE SPACE 't4~DDLANGUAGE = ''' p_lang '''' INTO SQLstr.
APPEND SQLstr TO itabSQL.
IF ( p_tb IS NOT INITIAL ).
CONCATENATE SPACE 'AND t1~TABNAME = ''' p_tb '''' INTO SQLstr.
APPEND SQLstr TO itabSQL.
ENDIF.
IF ( p_tbtx is not initial ).
clear v_text.
concatenate p_tbtx '%' into v_text.
CONCATENATE SPACE 'AND t2~DDTEXT Like ''' v_text '''' INTO SQLstr.
APPEND SQLstr TO itabSQL.
ENDIF.
IF ( p_fld is not initial ).
CONCATENATE SPACE 'AND t3~FIELDNAME = ''' p_fld '''' INTO SQLstr.
APPEND SQLstr TO itabSQL.
ENDIF.
if ( p_fldtx is not initial ).
clear v_text.
concatenate P_fldTx '%' into v_text.
CONCATENATE SPACE 'AND t4~DDTEXT Like ''' v_text '''' INTO SQLstr.
APPEND SQLstr TO itabSQL.
ENDIF.
IF ( p_cls is not initial ).
CONCATENATE SPACE 'AND t1~TABCLASS = ''' p_cls '''' INTO SQLstr.
APPEND SQLstr TO itabSQL.
ENDIF.
IF ( p_ROLL is not initial ).
clear v_text.
concatenate p_ROLL '%' into v_text.
CONCATENATE SPACE 'AND t3~ROLLNAME Like ''' v_text '''' INTO SQLstr.
APPEND SQLstr TO itabSQL.
ENDIF.
SELECT DISTINCT T1~TABNAME t1~TABCLASS t2~DDTEXT AS TABTEXT
T3~FIELDNAME t3~DATATYPE t3~ROLLNAME
t4~DDTEXT as FILDTEXT
INTO Corresponding fields of table it_tab
FROM DD02L AS t1
INNER JOIN DD02T as t2
ON t1~TABNAME = t2~TABNAME
INNER JOIN DD03L AS t3
ON t2~TABNAME = t3~TABNAME
INNER JOIN DD04T as t4
ON t3~ROLLNAME = t4~ROLLNAME
AND t2~DDLANGUAGE = t4~DDLANGUAGE
WHERE (itabSQL).
sort it_tab by tabname fieldname.
ENDFORM.
FORM user_command USING r_ucomm LIKE sy-ucomm
rs_selfield TYPE slis_selfield.
CASE r_ucomm.
WHEN '&IC1'. "doubleclick
READ TABLE it_tab INDEX rs_selfield-tabindex.
IF sy-subrc = 0.
IF rs_selfield-fieldname EQ 'TABNAME' AND
it_TAB-TABNAME IS NOT INITIAL.
SET PARAMETER ID 'DTB' FIELD it_TAB-TABNAME .
CALL TRANSACTION 'SE11' AND SKIP FIRST SCREEN.
CLEAR r_ucomm.
ENDIF.
ENDIF.
ENDCASE.
ENDFORM. "user_command
SAP 查表程序(通过字段,元素,表名,描述)查表
最新推荐文章于 2024-07-09 17:07:30 发布