SAP ABAP 从选择屏幕动态调用数据库表字段名称

2023-10-12 18:47:39 浏览数 (1)

该程序演示从选择屏幕调用数据库表字段名称、数据类型和长度。在此最初在选择屏幕中输入数据库表,然后单击执行按钮,然后自动获取数据库表字段名称、数据类型和特定字段的长度。

代码语言:javascript复制
REPORT  ZRTTI.
 
 
 
*data:gs TYPE mara.
 
PARAMETERS:p_tab type dd02l-tabname .
 
data wa type dd02l.
AT SELECTION-SCREEN ON p_tab.
 
 IF p_tab IS INITIAL.
 
MESSAGE 'please provide the database table name' type 'E'.
 
 ENDIF.
*field-symbols:.
*
*assign p_tab to .
 
START-OF-SELECTION.
 
DATA:GO_DESCR TYPE REF TO CL_ABAP_STRUCTDESCR,
        GS_COMP TYPE ABAP_COMPDESCR.
 
 
select single * from  dd02l into wa where tabname = p_tab.
 
IF SY-SUBRC <> 0.
 
   WRITE:/ 'PLEASE PROVIDE THE VALID DATABASE TABLE NAME'.
 
  else.
 
 go_descr ?= CL_ABAP_TYPEDESCR=>DESCRIBE_BY_name( p_tab ).
 
 WRITE:/ 'the following below field names are belonging to table name:',p_tab.
 
 skip 1.
 
 uline 1(80).
 
 skip 1.
 
  LOOP AT GO_DESCR->COMPONENTS INTO GS_COMP."HERE COMPONENTS IS STRUCTURE FOR STORING ALL THE FIELDS OF PARTICULAR TABLE
 
  WRITE:/ GS_COMP-NAME,GS_COMP-length,GS_COMP-decimals,GS_COMP-type_kind.
 
  ENDLOOP.
 
  ENDIF.

0 人点赞