*&---------------------------------------------------------------------
*& Report ZGETTABLEFIELD *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZGETTABLEFIELD .
* Data declaration
TYPE-POOLS: SLIS.
* Global structure of list
TYPES: BEGIN OF UD_STRUCT,
POSITION LIKE DD03L-POSITION,
TABNAME LIKE DD03L-TABNAME,
FIELDNAME LIKE DD03L-FIELDNAME,
DATATYPE LIKE DD03L-DATATYPE,
DDLENG LIKE DD03L-LENG,
DECIMALS LIKE DD03L-DECIMALS,
DDTEXT LIKE DD03T-DDTEXT,
EDDTEXT LIKE DD03T-DDTEXT,
DDDTEXT LIKE DD03T-DDTEXT,
END OF UD_STRUCT.
TABLES: DD03L.
DATA: GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA: GT_OUTTAB TYPE UD_STRUCT OCCURS 0 WITH HEADER LINE.
DATA: G_REPID LIKE SY-REPID.
data : begin of exclude occurs 5,
fcode like sy-ucomm,
end of exclude.
DATA p_ucomm LIKE sy-ucomm.
PARAMETER P_TNAME LIKE DD02l-TABNAME DEFAULT 'VBAK'.
*======================================================================*
* Initialization fieldcatalog
*======================================================================*
INITIALIZATION.
G_REPID = SY-REPID.
PERFORM FIELDCAT_INIT USING GT_FIELDCAT[].
*======================================================================*
* Ereignis : AT SELECTION-SCREEN OUTPUT (PBO-Zeitpunkt) *
*======================================================================*
at selection-screen output.
data exclude like rsexfcode occurs 0 with header line.
if sy-dynnr = 1000.
call function 'RS_SET_SELSCREEN_STATUS'
EXPORTING
p_status = 'ZGETTBFD'
TABLES
p_exclude = exclude
EXCEPTIONS
others = 1.
endif.
p_ucomm = SPACE.
*======================================================================*
* Ereignis : AT SELECTION-SCREEN (PAI-Zeitpunkt) *
* letztes PAI-Ereignis *
*======================================================================*
at selection-screen.
p_ucomm = sy-ucomm.
CASE p_ucomm.
WHEN 'STBL'.
SET PARAMETER ID 'DTB' FIELD P_TNAME.
* PERFORM AUTHORITY_CHECK USING 'SE11' .
CALL TRANSACTION 'SE11' AND SKIP FIRST SCREEN.
ENDCASE.
*======================================================================*
* Data selection
*======================================================================*
START-OF-SELECTION.
PERFORM SELECT_DATA TABLES GT_OUTTAB.
perform function_exclude tables exclude.
*======================================================================*
* Display list
*======================================================================*
END-OF-SELECTION.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = G_REPID
IT_FIELDCAT = GT_FIELDCAT[]
TABLES
T_OUTTAB = GT_OUTTAB.
*-----------------------------------------------------------------------
* Forms
*-----------------------------------------------------------------------
* Initialization fieldcatalog
FORM FIELDCAT_INIT
USING RT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV.
DATA: LS_FIELDCAT TYPE SLIS_FIELDCAT_ALV.
DATA: POS TYPE I VALUE 1.
clear ls_fieldcat.
LS_FIELDCAT-COL_POS = POS.
LS_FIELDCAT-FIELDNAME = 'POSITION'.
ls_fieldcat-ref_fieldname = 'POSITION'.
LS_FIELDCAT-REF_TABNAME = 'DD03L'.
LS_FIELDCAT-KEY = 'X'.
APPEND LS_FIELDCAT TO RT_FIELDCAT.
clear ls_fieldcat.
POS = POS + 1.
LS_FIELDCAT-COL_POS = POS.
LS_FIELDCAT-FIELDNAME = 'TABNAME'.
ls_fieldcat-ref_fieldname = 'TABNAME'.
LS_FIELDCAT-REF_TABNAME = 'DD03T'.
* LS_FIELDCAT-KEY = 'X'.
APPEND LS_FIELDCAT TO RT_FIELDCAT.
clear ls_fieldcat.
POS = POS + 1.
LS_FIELDCAT-COL_POS = POS.
LS_FIELDCAT-FIELDNAME = 'FIELDNAME'.
ls_fieldcat-ref_fieldname = 'FIELDNAME'.
LS_FIELDCAT-REF_TABNAME = 'DD03T'.
APPEND LS_FIELDCAT TO RT_FIELDCAT.
clear ls_fieldcat.
POS = POS + 1.
LS_FIELDCAT-COL_POS = POS.
LS_FIELDCAT-FIELDNAME = 'DATATYPE'.
ls_fieldcat-ref_fieldname = 'DATATYPE'.
LS_FIELDCAT-REF_TABNAME = 'DD03T'.
APPEND LS_FIELDCAT TO RT_FIELDCAT.
clear ls_fieldcat.
POS = POS + 1.
LS_FIELDCAT-COL_POS = POS.
LS_FIELDCAT-FIELDNAME = 'DDLENG'.
ls_fieldcat-ref_fieldname = 'LENG'.
LS_FIELDCAT-REF_TABNAME = 'DD03L'.
APPEND LS_FIELDCAT TO RT_FIELDCAT.
clear ls_fieldcat.
POS = POS + 1.
LS_FIELDCAT-COL_POS = POS.
LS_FIELDCAT-FIELDNAME = 'DECIMALS'.
ls_fieldcat-ref_fieldname = 'DECIMALS'.
LS_FIELDCAT-REF_TABNAME = 'DD03L'.
APPEND LS_FIELDCAT TO RT_FIELDCAT.
clear ls_fieldcat.
POS = POS + 1.
LS_FIELDCAT-COL_POS = POS.
LS_FIELDCAT-FIELDNAME = 'DDTEXT'.
ls_fieldcat-ref_fieldname = 'DDTEXT'.
LS_FIELDCAT-REF_TABNAME = 'DD03T'.
* LS_FIELDCAT-NO_OUT = 'X'.
APPEND LS_FIELDCAT TO RT_FIELDCAT.
ENDFORM. "fieldcat_init
* Data selection
FORM SELECT_DATA
TABLES RT_OUTTAB LIKE GT_OUTTAB[].
SELECT DD03L~POSITION DD03L~TABNAME
DD03L~FIELDNAME DD03L~DATATYPE
DD03L~LENG DD03L~DECIMALS
DD03T~DDTEXT
DD04T~DDTEXT DD01T~DDTEXT
INTO (RT_OUTTAB-POSITION, RT_OUTTAB-TABNAME,
RT_OUTTAB-FIELDNAME, RT_OUTTAB-DATATYPE,
RT_OUTTAB-DDLENG, RT_OUTTAB-DECIMALS,
RT_OUTTAB-DDTEXT,
RT_OUTTAB-EDDTEXT,RT_OUTTAB-DDDTEXT)
FROM DD03L LEFT JOIN DD03T
ON DD03L~TABNAME = DD03T~TABNAME
AND DD03L~FIELDNAME = DD03T~FIELDNAME
AND DD03T~DDLANGUAGE = SY-LANGU
LEFT JOIN DD04T
ON DD03L~ROLLNAME = DD04T~ROLLNAME
AND DD04T~DDLANGUAGE = SY-LANGU
LEFT JOIN DD01T
ON DD03L~DOMNAME = DD01T~DOMNAME
AND DD01T~DDLANGUAGE = SY-LANGU
WHERE DD03L~TABNAME = P_TNAME
ORDER BY DD03L~POSITION.
IF RT_OUTTAB-DDTEXT = SPACE.
IF RT_OUTTAB-EDDTEXT = SPACE.
RT_OUTTAB-DDTEXT = RT_OUTTAB-DDDTEXT.
ELSE.
RT_OUTTAB-DDTEXT = RT_OUTTAB-EDDTEXT.
ENDIF.
ENDIF.
APPEND RT_OUTTAB.
ENDSELECT.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form FUNCTION_EXCLUDE
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_EXCLUDE text *
*----------------------------------------------------------------------*
form function_exclude tables p_exclude structure exclude.
* data : rcode like sy-subrc.
* clear p_exclude.
* refresh p_exclude.
* exclude-fcode = 'EERW'.
* append exclude.
* exclude-fcode = 'EXIT'.
* append exclude.
endform. " FUNCTION_EXCLUDE