TYPES EXPORT_LINE_TYPE(512) TYPE C.
TYPES EXPORT_TABLE_TYPE TYPE STANDARD TABLE OF TAB512.

FUNCTION Z_MITI_DOWNLOAD.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(P_AREA) TYPE  DD02L-TABNAME OPTIONAL
*"     VALUE(P_LOCAL_PATH) TYPE  STRING OPTIONAL
*"     VALUE(P_LANGUAGE) TYPE  L001TAB-DATA DEFAULT 'E'
*"     VALUE(ROWSKIPS) TYPE  SO_INT DEFAULT 0
*"     VALUE(ROWCOUNT) TYPE  SO_INT DEFAULT 0
*"  TABLES
*"      EXPORT_TABLE STRUCTURE  TAB512
*"  EXCEPTIONS
*"      E_EXP_GUI_DOWNLOADFAILED
*"----------------------------------------------------------------------

* ----------------------------------------------------------------------
* Copyright © 1997-2023 Meta Integration Technology, Inc. 
* ----------------------------------------------------------------------
*"     P_AREA = metadata to query
*"     P_LOCAL_PATH = local directory to save to
*"     P_LANGUAGE = language to use
*"     ROWSKIPS = number of rows to skip, for pagination of large datasets
*"     ROWCOUNT = number of rows to retrieve, for pagination of large datasets
* ----------------------------------------------------------------------

*  CLASS CL_ABAP_CHAR_UTILITIES DEFINITION LOAD.
DATA: FILE_NAME TYPE STRING.
DATA: FUNCTION_VERSION TYPE STRING.
DATA: FILE_SEP TYPE C.
FUNCTION_VERSION = '8'.

* File separator is backslash on Microsoft Windows
FILE_SEP = '\'.
*  DATA: t1 TYPE timestamp,
*        t2 TYPE timestamp,
*        runtime TYPE timestamp.
*  GET TIME STAMP FIELD t1.
*  GET TIME STAMP FIELD t2.
*  runtime = t2 - t1.

* The boolean flags below can be used to exclude certain types of objects
DATA: INCLUDE_IDOCS TYPE abap_bool VALUE abap_true.
DATA: INCLUDE_PROGRAMS TYPE abap_bool VALUE abap_true.
DATA: INCLUDE_FGROUPS TYPE abap_bool VALUE abap_true.

* You may delete or comment out sections below that are marked optional to exclude certain types of objects

*SystemInformation, required
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'SYSTEMINFO'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_SYSTEMINFO
    USING FUNCTION_VERSION
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'SYSTEMINFO.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
*SoftwareComponents, required
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'SWCOMPS'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_SWCOMPS
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'SWCOMPS.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
*ApplicationComponents, required
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'DF14'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_APPCOMPONENTS
    USING P_LANGUAGE
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'DF14.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
*ApplicationComponents tree Nodes, required
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'TNODE01'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_TREENODES
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'TNODE01.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
*ApplicationComponents hierarchy tree, required
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'SCUS_HIER'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_HIERARCHY_REPLACEMENT
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'SCUS_HIER.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
*Packages (DevelopmentClass in earlier versions), required
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'TDEVC'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_PACKAGES
    USING P_LANGUAGE
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'TDEVC.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.

*Sections below are optional
*Note that they have dependencies on each other: Fields depend on Tables, ...

* List of Tables with their owner Package (Required for Tables)
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'DEVTB'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_PACKAGETABLES
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'DEVTB.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
* Tables properties
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'DD02'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_TABLES
    USING P_LANGUAGE
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'DD02.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
* Table Fields
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'DD03'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_TABLEFIELDS
    USING P_LANGUAGE ROWSKIPS ROWCOUNT
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'DD03.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
* ForeignKey Fields
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'DD05'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_FKFIELDS
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'DD05.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
* Indexes
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'DD12'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_INDEX
    USING P_LANGUAGE
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'DD12.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
* Index Fields
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'DD17S'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_INDEXFIELDS
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'DD17S.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
*Domains
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'DD01'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_DOMAINS
    USING P_LANGUAGE
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'DD01.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
*Domain Values
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'DD07'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_DOMAINVALUES
    USING P_LANGUAGE
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'DD07.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
*DataElements
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'DD04'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_DATAELEMENTS
    USING P_LANGUAGE
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'DD04.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
* DataElements documentation
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'DOKTL_DATAELEMETS'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_DATAELEMENTDOCS
    USING P_LANGUAGE
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'DOKTL_DATAELEMETS.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
*Views properties
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'DD25L'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_VIEWS
    USING P_LANGUAGE
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'DD25L.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
*View Fields
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'DD27S'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_VIEWFIELDS
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'DD27S.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
*View conditions
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'DD28S'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_VIEWCONDS
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'DD28S.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
*View lineage
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'DD26S'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_VIEWTABLES
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'DD26S.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
* List of Views with their owner Package (Required for Views)
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'DEVVW'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_PACKAGEVIEWS
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'DEVVW.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
*Function groups
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'FUGR'.
    CLEAR EXPORT_TABLE[].
    IF INCLUDE_FGROUPS = abap_true.
      PERFORM Z_QUERY_FGROUPS
      USING P_LANGUAGE
      CHANGING EXPORT_TABLE[].
    ENDIF.
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'FUGR.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
*Function groups documentation
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'DOKTL_FUGR'.
    CLEAR EXPORT_TABLE[].
    IF INCLUDE_FGROUPS = abap_true.
      PERFORM Z_QUERY_FGROUPDOCS
      USING P_LANGUAGE
      CHANGING EXPORT_TABLE[].
    ENDIF.
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'DOKTL_FUGR.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
*Programs
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'PROG'.
    CLEAR EXPORT_TABLE[].
    IF INCLUDE_PROGRAMS = abap_true.
      PERFORM Z_QUERY_PROGRAMS
      USING P_LANGUAGE
      CHANGING EXPORT_TABLE[].
    ENDIF.
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'PROG.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
*Classes
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'CLAS'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_CLAS
    USING P_LANGUAGE
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'CLAS.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
* Program to Tables lineage
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'D010TAB_TABLES'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_PROGRAM_TABLES
    USING ROWSKIPS ROWCOUNT
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'D010TAB_TABLES.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
* Program to Views lineage
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'D010TAB_VIEWS'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_PROGRAM_VIEWS
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'D010TAB_VIEWS.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
*Transactions
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'TRAN'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_TRANSACTIONS
    USING P_LANGUAGE
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'TRAN.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
*Transactions to Program lineage
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'TSTC'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_TRANSACTIONPROGRAMS
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'TSTC.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
*Transactions parameters
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'TSTCP'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_TRANSACTIONPARAMS
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'TSTCP.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
*IDocs
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'IDOCTYPES'.
    CLEAR EXPORT_TABLE[].
    IF INCLUDE_IDOCS = abap_true.
      PERFORM Z_QUERY_IDOCTYPES
      USING P_LANGUAGE
      CHANGING EXPORT_TABLE[].
    ENDIF.
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'IDOCTYPES.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
*IDocs
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'BASEIDOCTYPES'.
    CLEAR EXPORT_TABLE[].
    IF INCLUDE_IDOCS = abap_true.
      PERFORM Z_QUERY_BASEIDOCTYPES
      USING P_LANGUAGE
      CHANGING EXPORT_TABLE[].
    ENDIF.
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'BASEIDOCTYPES.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
*FunctionModules
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'TFDIR'.
    CLEAR EXPORT_TABLE[].
    IF INCLUDE_FGROUPS = abap_true.
      PERFORM Z_QUERY_FUNCTIONMODULES
      USING P_LANGUAGE
      CHANGING EXPORT_TABLE[].
    ENDIF.
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'TFDIR.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
*FunctionModule parameters
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'FUPARAREF'.
    CLEAR EXPORT_TABLE[].
    IF INCLUDE_FGROUPS = abap_true.
      PERFORM Z_QUERY_FUNCTIONMODULEPARAMS
      USING P_LANGUAGE
      CHANGING EXPORT_TABLE[].
    ENDIF.
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'FUPARAREF.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
*View DDL
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'VIEWDDL'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_VIEWDDL
    USING P_LANGUAGE ROWSKIPS ROWCOUNT
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'VIEWDDL.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
*Table Function
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'DD02B'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_TABLEFUNC
    USING P_LANGUAGE
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'DD02B.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.

*Table Function fileds
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'DD03ND'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_TF_FIELDS
    USING P_LANGUAGE
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'DD03ND.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
  
*Table Function input paramters
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'DD10B'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_TF_IP
    USING P_LANGUAGE
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'DD10B.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.  
*Table Function DDL
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'TFDDL'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_TFDDL
    USING P_LANGUAGE ROWSKIPS ROWCOUNT
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'TFDDL.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.
* List of Table Functions with their owner Package (Required for Table Functions)
  IF STRLEN( P_AREA ) = 0 OR P_AREA = 'DEVTF'.
    CLEAR EXPORT_TABLE[].
    PERFORM Z_QUERY_PACKAGETFS
    CHANGING EXPORT_TABLE[].
    IF STRLEN( P_LOCAL_PATH ) > 0 .
      CONCATENATE P_LOCAL_PATH 'DEVTF.txt' INTO FILE_NAME SEPARATED BY FILE_SEP.
      PERFORM Z_FORM_DOWNLOAD
      TABLES EXPORT_TABLE
      USING FILE_NAME.
    ENDIF.
    COMMIT WORK.
  ENDIF.  

  IF STRLEN( P_LOCAL_PATH ) > 0 .
    FREE EXPORT_TABLE.
  ENDIF.

ENDFUNCTION.


* ------------------------------------------------------------------- *
FORM Z_FORM_CLEANSTRING
CHANGING P_LINE TYPE STRING.

  DATA: cPat1(2) TYPE X VALUE '0D47'.
  FIELD-SYMBOLS: <ic> TYPE X,
                 <tc> TYPE C.
  ASSIGN cPat1 TO <ic> CASTING.
  ASSIGN <ic> TO <tc> CASTING.

  REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>CR_LF IN P_LINE WITH '/'.
  REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>NEWLINE IN P_LINE WITH '/'.
  REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>FORM_FEED IN P_LINE WITH '/'.
  TRANSLATE P_LINE USING <tc>.

ENDFORM.

FORM Z_FORM_DOWNLOAD
TABLES P_TABLE TYPE EXPORT_TABLE_TYPE
USING P_FILENAME TYPE STRING.

*  DATA: INOROWS LIKE SY-TABIX.

*  DESCRIBE TABLE P_TABLE LINES INOROWS.

  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      FILENAME                = P_FILENAME
      FILETYPE                = 'ASC'
*UTF-8: 4310. Taken from the table TCP00A (or TCP00)
*https://wiki.scn.sap.com/wiki/display/ABAP/Character+encoding+conversion
*Perhaps use 4110 instead?
      CODEPAGE                = '4310'
      WRITE_FIELD_SEPARATOR   = 'X'
      TRUNC_TRAILING_BLANKS   = 'X'
      APPEND                  = ' '
    TABLES
      DATA_TAB                = P_TABLE
    EXCEPTIONS
      " declare specific exceptions here ?
      OTHERS                  = 99.

  IF SY-SUBRC <> 0.
      raise E_EXP_GUI_DOWNLOADFAILED.
  ENDIF.

ENDFORM.

* ---------- FETCH METADATA SECTION ----------*
FORM Z_QUERY_HIERARCHY_REPLACEMENT
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.

  TYPES: BEGIN OF TY_SCUS_HIER,
    ID TYPE SCUS_HIER-ID,
    REPLACES TYPE SCUS_HIER-REPLACES,
    TREE_ID TYPE SCUS_HIER-TREE_ID,
  END OF TY_SCUS_HIER.

  FIELD-SYMBOLS: <WA_SCUS_HIER> TYPE TY_SCUS_HIER.
  DATA: SCUS_HIERTMP TYPE TABLE OF TY_SCUS_HIER.

  SELECT
  ID REPLACES TREE_ID
  FROM SCUS_HIER
  INTO TABLE SCUS_HIERTMP
  WHERE TYPE = 'AKH01'.

  LOOP AT SCUS_HIERTMP ASSIGNING <WA_SCUS_HIER>.
    CONCATENATE
    <WA_SCUS_HIER>-ID <WA_SCUS_HIER>-REPLACES <WA_SCUS_HIER>-TREE_ID
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE SCUS_HIERTMP.
ENDFORM.

FORM Z_QUERY_TREENODES
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.

  TYPES: BEGIN OF TY_TNODE01,
    TREE_ID TYPE TNODE01-TREE_ID,
    NODE_ID TYPE TNODE01-NODE_ID,
    REFTREE_ID TYPE TNODE01-REFTREE_ID,
    PARENT_ID TYPE TNODE01-PARENT_ID,
    BROTHER_ID TYPE TNODE01-BROTHER_ID,
    NODE_TYPE TYPE TNODE01-NODE_TYPE,
    W_SUBNODES TYPE TNODE01-W_SUBNODES,
  END OF TY_TNODE01.

  FIELD-SYMBOLS: <WA_TNODE01> TYPE TY_TNODE01.
  DATA: TNODE01TMP TYPE TABLE OF TY_TNODE01.

  SELECT
  TREE_ID NODE_ID REFTREE_ID PARENT_ID BROTHER_ID NODE_TYPE W_SUBNODES
  FROM TNODE01
  INTO TABLE TNODE01TMP
  WHERE NODE_TYPE = 'REF'
  OR NODE_TYPE = 'BMFR'
  ORDER BY TREE_ID.

  LOOP AT TNODE01TMP ASSIGNING <WA_TNODE01>.
    CONCATENATE
    <WA_TNODE01>-TREE_ID <WA_TNODE01>-NODE_ID <WA_TNODE01>-REFTREE_ID
    <WA_TNODE01>-PARENT_ID <WA_TNODE01>-BROTHER_ID <WA_TNODE01>-NODE_TYPE
    <WA_TNODE01>-W_SUBNODES
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE TNODE01TMP.
ENDFORM.

FORM Z_QUERY_APPCOMPONENTS
USING P_LANGUAGE TYPE L001TAB-DATA
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.

  TYPES: BEGIN OF TY_DF14,
    NODE_ID TYPE TNODE01R-NODE_ID,
    REF_OBJECT TYPE TNODE01R-REF_OBJECT,
    PS_POSID TYPE DF14L-PS_POSID,
    NAME TYPE DF14T-NAME,
  END OF TY_DF14.

  FIELD-SYMBOLS: <WA_DF14> TYPE TY_DF14.
  DATA: DF14TMP TYPE TABLE OF TY_DF14.

  SELECT
  r~NODE_ID r~REF_OBJECT r2~PS_POSID r3~NAME
*TNODE01R: Structure Storage References (map between tree node Id and object type/id)
  FROM TNODE01R AS r
*DF14L: Application Components
  INNER JOIN DF14L AS r2
  ON r~REF_OBJECT EQ r2~FCTR_ID
  AND r2~AS4LOCAL = 'A'
*Skip deleted records
  AND r2~SYNCH <> 'D'
*DF14T: ApplicationComponent Names
  LEFT OUTER JOIN DF14T AS r3
  ON r2~FCTR_ID EQ r3~FCTR_ID
  AND r3~AS4LOCAL = 'A'
  AND r3~LANGU EQ P_LANGUAGE
  INTO TABLE DF14TMP
  WHERE r~REF_TYPE EQ 'BMFR'
  OR r~REF_TYPE EQ 'REF'.

  LOOP AT DF14TMP ASSIGNING <WA_DF14>.
    CONCATENATE
    <WA_DF14>-NODE_ID <WA_DF14>-REF_OBJECT
    <WA_DF14>-PS_POSID <WA_DF14>-NAME
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE DF14TMP.
ENDFORM.

FORM Z_QUERY_DOMAINS
USING P_LANGUAGE TYPE L001TAB-DATA
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.

  TYPES: BEGIN OF TY_DOMAIN,
    DOMNAME TYPE DD01L-DOMNAME,
    DATATYPE TYPE DD01L-DATATYPE,
    LENG TYPE DD01L-LENG,
    DECIMALS TYPE DD01L-DECIMALS,
    ENTITYTAB TYPE DD01L-ENTITYTAB,
    DEVCLASS TYPE TADIR-DEVCLASS,
    DDTEXT TYPE DD01T-DDTEXT,
  END OF TY_DOMAIN.

  FIELD-SYMBOLS: <WA_DOMAIN> TYPE TY_DOMAIN.
  DATA: DOMAINSTMP TYPE TABLE OF TY_DOMAIN.

  SELECT
  l~DOMNAME l~DATATYPE l~LENG l~DECIMALS l~ENTITYTAB d~DEVCLASS t~DDTEXT
  FROM DD01L AS l
  LEFT OUTER JOIN DD01T AS t
    ON l~DOMNAME EQ t~DOMNAME
    AND t~AS4LOCAL = 'A'
    AND t~DDLANGUAGE EQ P_LANGUAGE
  LEFT OUTER JOIN TADIR AS d
    ON d~OBJ_NAME EQ l~DOMNAME
    AND d~OBJECT EQ 'DOMA'
  INTO TABLE DOMAINSTMP
  BYPASSING BUFFER
  WHERE l~AS4LOCAL = 'A'
  ORDER BY l~DOMNAME.

  LOOP AT DOMAINSTMP ASSIGNING <WA_DOMAIN>.
    CONCATENATE
    <WA_DOMAIN>-DOMNAME <WA_DOMAIN>-DATATYPE <WA_DOMAIN>-LENG
    <WA_DOMAIN>-DECIMALS <WA_DOMAIN>-ENTITYTAB <WA_DOMAIN>-DEVCLASS <WA_DOMAIN>-DDTEXT
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE DOMAINSTMP.
ENDFORM.

FORM Z_QUERY_TABLES
USING P_LANGUAGE TYPE L001TAB-DATA
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.

  TYPES: BEGIN OF TY_TABLE,
    TABNAME TYPE DD02L-TABNAME,
    SQLTAB TYPE DD02L-SQLTAB,
    TABCLASS TYPE DD02L-TABCLASS,
    DDTEXT TYPE DD02T-DDTEXT,
  END OF TY_TABLE.

  FIELD-SYMBOLS: <WA_TABLE> TYPE TY_TABLE.
  DATA: TABLESTMP TYPE TABLE OF TY_TABLE.

  SELECT
  l~TABNAME l~SQLTAB l~TABCLASS r~DDTEXT
  FROM DD02L AS l
  LEFT OUTER JOIN DD02T AS r
  ON l~TABNAME EQ r~TABNAME
  AND r~DDLANGUAGE EQ P_LANGUAGE
  AND r~AS4LOCAL = 'A'
  INTO TABLE TABLESTMP
  WHERE l~TABCLASS IN ('TRANSP','POOL','CLUSTER')
  AND  l~AS4LOCAL = 'A'
  ORDER BY l~TABNAME.

  LOOP AT TABLESTMP ASSIGNING <WA_TABLE>.
    CONCATENATE
    <WA_TABLE>-TABNAME <WA_TABLE>-SQLTAB <WA_TABLE>-TABCLASS <WA_TABLE>-DDTEXT
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE TABLESTMP.
ENDFORM.

FORM Z_QUERY_TABLEFIELDS
USING P_LANGUAGE TYPE L001TAB-DATA
      ROWSKIPS TYPE SO_INT
      ROWCOUNT TYPE SO_INT
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.

  TYPES: BEGIN OF TY_TABLEFIELD,
    TABNAME TYPE DD03L-TABNAME,
    FIELDNAME TYPE DD03L-FIELDNAME,
    POSITION TYPE DD03L-POSITION,
    ROLLNAME TYPE DD03L-ROLLNAME,
    KEYFLAG TYPE DD03L-KEYFLAG,
    MANDATORY TYPE DD03L-MANDATORY,
    DATATYPE TYPE DD03L-DATATYPE,
    INTLEN TYPE DD03L-INTLEN,
    DECIMALS TYPE DD03L-DECIMALS,
    COMPTYPE TYPE DD03L-COMPTYPE,
    DDTEXT TYPE DD03T-DDTEXT,
  END OF TY_TABLEFIELD.
  FIELD-SYMBOLS: <WA_TABLEFIELD> TYPE TY_TABLEFIELD.
  DATA: TABLEFIELDSTMP TYPE TABLE OF TY_TABLEFIELD.

  DATA: ROWINDEX TYPE SO_INT.
  DATA: ROWEND TYPE SO_INT.

  SELECT
  l~TABNAME l~FIELDNAME l~POSITION l~ROLLNAME l~KEYFLAG l~MANDATORY
  l~DATATYPE l~INTLEN l~DECIMALS l~COMPTYPE r~DDTEXT
  FROM DD03L AS l
  INNER JOIN DD02L as t
    ON l~TABNAME EQ t~TABNAME
    AND t~AS4LOCAL = 'A'
  LEFT OUTER JOIN DD03T AS r
    ON l~TABNAME EQ r~TABNAME
    AND l~FIELDNAME EQ r~FIELDNAME
    AND r~DDLANGUAGE EQ P_LANGUAGE
    AND r~AS4LOCAL = 'A'
*      	AND r~FIELDNAME NOT LIKE '.%'
  INTO TABLE TABLEFIELDSTMP
  WHERE t~TABCLASS IN ('TRANSP','POOL','CLUSTER')
  AND l~AS4LOCAL = 'A'
  AND l~FIELDNAME NOT LIKE '.%'
  ORDER BY l~TABNAME l~POSITION.

  ROWINDEX = 0.
  ROWEND = ROWSKIPS + ROWCOUNT.
  LOOP AT TABLEFIELDSTMP ASSIGNING <WA_TABLEFIELD>.
    IF ROWCOUNT = 0 OR ( ROWINDEX >= ROWSKIPS AND ROWINDEX < ROWEND ) .
      CONCATENATE
      <WA_TABLEFIELD>-TABNAME <WA_TABLEFIELD>-FIELDNAME <WA_TABLEFIELD>-POSITION
      <WA_TABLEFIELD>-ROLLNAME <WA_TABLEFIELD>-KEYFLAG <WA_TABLEFIELD>-MANDATORY
      <WA_TABLEFIELD>-DATATYPE <WA_TABLEFIELD>-INTLEN <WA_TABLEFIELD>-DECIMALS
      <WA_TABLEFIELD>-COMPTYPE <WA_TABLEFIELD>-DDTEXT
      INTO EXPORT_LINE
      SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
      APPEND EXPORT_LINE TO EXPORT_TABLE.
    ELSEIF ROWCOUNT > 0 AND ROWINDEX >= ROWEND.
      EXIT.
    ENDIF.
    ROWINDEX = ROWINDEX + 1.
  ENDLOOP.
  FREE TABLEFIELDSTMP.
ENDFORM.

FORM Z_QUERY_DATAELEMENTS
USING P_LANGUAGE TYPE L001TAB-DATA
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.

  TYPES: BEGIN OF TY_DATAELT,
    ROLLNAME TYPE DD04L-ROLLNAME,
    DOMNAME TYPE DD04L-DOMNAME,
    DATATYPE TYPE DD04L-DATATYPE,
    LENG TYPE DD04L-LENG,
    DECIMALS TYPE DD04L-DECIMALS,
    REFKIND TYPE DD04L-REFKIND,
    DDTEXT TYPE DD04T-DDTEXT,
*      SCRTEXT_S TYPE DD04T-SCRTEXT_S,
*      SCRTEXT_M TYPE DD04T-SCRTEXT_M,
*      SCRTEXT_L TYPE DD04T-SCRTEXT_L,
    DEVCLASS TYPE TADIR-DEVCLASS,
  END OF TY_DATAELT.
  FIELD-SYMBOLS: <WA_DATAELT> TYPE TY_DATAELT.
  DATA: DATAELTSTMP TYPE TABLE OF TY_DATAELT.

  SELECT DISTINCT
  l~ROLLNAME l~DOMNAME l~DATATYPE l~LENG l~DECIMALS l~REFKIND r~DDTEXT
*      r~SCRTEXT_S r~SCRTEXT_M r~SCRTEXT_L
  d~DEVCLASS
  FROM DD04L AS l
  INNER JOIN DD03L AS f
    ON l~ROLLNAME EQ f~ROLLNAME
  INNER JOIN DD02L AS t
    ON f~TABNAME EQ t~TABNAME
  LEFT OUTER JOIN DD04T AS r
    ON l~ROLLNAME EQ r~ROLLNAME
    AND r~DDLANGUAGE EQ P_LANGUAGE
    AND r~AS4LOCAL = 'A'
  LEFT OUTER JOIN TADIR AS d
    ON d~OBJ_NAME EQ l~ROLLNAME
    AND d~OBJECT EQ 'DTEL'
  INTO TABLE DATAELTSTMP
  BYPASSING BUFFER
  WHERE t~TABCLASS IN ('TRANSP','POOL','CLUSTER')
  AND t~AS4LOCAL = 'A'
  AND f~AS4LOCAL = 'A'
  AND f~FIELDNAME NOT LIKE '.%'
  AND l~AS4LOCAL = 'A'
  ORDER BY l~ROLLNAME.

  LOOP AT DATAELTSTMP ASSIGNING <WA_DATAELT>.
    CONCATENATE
    <WA_DATAELT>-ROLLNAME <WA_DATAELT>-DOMNAME <WA_DATAELT>-DATATYPE
    <WA_DATAELT>-LENG <WA_DATAELT>-DECIMALS <WA_DATAELT>-REFKIND <WA_DATAELT>-DDTEXT
*        <WA_DATAELT>-SCRTEXT_S <WA_DATAELT>-SCRTEXT_M <WA_DATAELT>-SCRTEXT_L
    <WA_DATAELT>-DEVCLASS
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE DATAELTSTMP.
ENDFORM.

FORM Z_QUERY_FKFIELDS
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.

  TYPES: BEGIN OF TY_FKFIELD,
    TABNAME TYPE DD05Q-TABNAME,
    FIELDNAME TYPE DD05Q-FIELDNAME,
    PRIMPOS TYPE DD05Q-PRIMPOS,
    FORTABLE TYPE DD05Q-FORTABLE,
    FORKEY TYPE DD05Q-FORKEY,
    CHECKTABLE TYPE DD05Q-CHECKTABLE,
    CHECKFIELD TYPE DD05Q-CHECKFIELD,
    CARDLEFT TYPE DD08L-CARDLEFT,
    CARD TYPE DD08L-CARD,
    FRKART TYPE DD08L-FRKART,
  END OF TY_FKFIELD.
  FIELD-SYMBOLS: <WA_FKFIELD> TYPE TY_FKFIELD.
  DATA FKFIELDSTMP TYPE TABLE OF TY_FKFIELD.

  SELECT
  l~TABNAME l~FIELDNAME l~PRIMPOS l~FORTABLE l~FORKEY
  l~CHECKTABLE l~CHECKFIELD r~CARDLEFT r~CARD r~FRKART
  FROM DD05Q AS l
  INNER JOIN DD08L AS r
    ON l~TABNAME EQ r~TABNAME
    AND l~FIELDNAME EQ r~FIELDNAME
  INNER JOIN DD02L AS t
    ON l~TABNAME EQ t~TABNAME
    AND t~AS4LOCAL = 'A'
  INTO TABLE FKFIELDSTMP
  WHERE t~TABCLASS IN ('TRANSP','POOL','CLUSTER')
*      AND AS4LOCAL = 'A'
  ORDER BY l~TABNAME l~FIELDNAME l~PRIMPOS.

  LOOP AT FKFIELDSTMP ASSIGNING <WA_FKFIELD>.
    CONCATENATE
    <WA_FKFIELD>-TABNAME <WA_FKFIELD>-FIELDNAME <WA_FKFIELD>-PRIMPOS
    <WA_FKFIELD>-FORTABLE <WA_FKFIELD>-FORKEY <WA_FKFIELD>-CHECKTABLE <WA_FKFIELD>-CHECKFIELD
    <WA_FKFIELD>-CARDLEFT <WA_FKFIELD>-CARD <WA_FKFIELD>-FRKART
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE FKFIELDSTMP.
ENDFORM.

FORM Z_QUERY_DOMAINVALUES
USING P_LANGUAGE TYPE L001TAB-DATA
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.

  TYPES: BEGIN OF TY_DOMAINVALUE,
    DOMNAME TYPE DD07L-DOMNAME,
    DOMVALUE_L TYPE DD07L-DOMVALUE_L,
    DOMVALUE_H TYPE DD07L-DOMVALUE_H,
    VALPOS TYPE DD07L-VALPOS,
    DDTEXT TYPE DD07T-DDTEXT,
  END OF TY_DOMAINVALUE.
  FIELD-SYMBOLS: <WA_DOMAINVALUE> TYPE TY_DOMAINVALUE.
  DATA DOMAINVALUESTMP TYPE TABLE OF TY_DOMAINVALUE.

  SELECT
  l~DOMNAME l~DOMVALUE_L l~DOMVALUE_H l~VALPOS r~DDTEXT
  FROM DD07L AS l
  INNER JOIN DD01L AS d
    ON l~DOMNAME EQ d~DOMNAME
    AND d~AS4LOCAL = 'A'
  LEFT OUTER JOIN DD07T AS r
    ON l~DOMNAME EQ r~DOMNAME
    AND l~VALPOS EQ r~VALPOS
    AND r~DDLANGUAGE EQ P_LANGUAGE
    AND r~AS4LOCAL = 'A'
  INTO TABLE DOMAINVALUESTMP
  BYPASSING BUFFER
  WHERE l~AS4LOCAL = 'A'
  ORDER BY l~DOMNAME.

  LOOP AT DOMAINVALUESTMP ASSIGNING <WA_DOMAINVALUE>.
    CONCATENATE
    <WA_DOMAINVALUE>-DOMNAME <WA_DOMAINVALUE>-DOMVALUE_L <WA_DOMAINVALUE>-DOMVALUE_H
    <WA_DOMAINVALUE>-VALPOS <WA_DOMAINVALUE>-DDTEXT
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE DOMAINVALUESTMP.
ENDFORM.

FORM Z_QUERY_INDEX
USING P_LANGUAGE TYPE L001TAB-DATA
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.

  TYPES: BEGIN OF TY_INDEX,
    SQLTAB TYPE DD12L-SQLTAB,
    INDEXNAME TYPE DD12L-INDEXNAME,
    UNIQUEFLAG TYPE DD12L-UNIQUEFLAG,
    DBINDEX TYPE DD12L-DBINDEX,
    DDTEXT TYPE DD12T-DDTEXT,
  END OF TY_INDEX.
  FIELD-SYMBOLS: <WA_INDEX> TYPE TY_INDEX.
  DATA: INDEXTMP TYPE TABLE OF TY_INDEX.

  SELECT
  l~SQLTAB l~INDEXNAME l~UNIQUEFLAG
  l~DBINDEX r~DDTEXT
  FROM DD12L AS l
  INNER JOIN DD02L AS t
    ON l~SQLTAB EQ t~TABNAME
    AND t~AS4LOCAL = 'A'
  LEFT OUTER JOIN DD12T AS r
  ON l~SQLTAB EQ r~SQLTAB
  AND l~INDEXNAME EQ r~INDEXNAME
  AND r~DDLANGUAGE EQ P_LANGUAGE
  AND r~AS4LOCAL EQ 'A'
  INTO TABLE INDEXTMP
  WHERE t~TABCLASS IN ('TRANSP','POOL','CLUSTER')
  AND  l~AS4LOCAL = 'A'
  ORDER BY l~SQLTAB l~INDEXNAME.

  LOOP AT INDEXTMP ASSIGNING <WA_INDEX>.
    CONCATENATE
    <WA_INDEX>-SQLTAB <WA_INDEX>-INDEXNAME
    <WA_INDEX>-UNIQUEFLAG <WA_INDEX>-DBINDEX <WA_INDEX>-DDTEXT
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE INDEXTMP.
ENDFORM.

FORM Z_QUERY_INDEXFIELDS
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.

  TYPES: BEGIN OF TY_INDEXFIELD,
    SQLTAB TYPE DD17S-SQLTAB,
    INDEXNAME TYPE DD17S-INDEXNAME,
    POSITION TYPE DD17S-POSITION,
    FIELDNAME TYPE DD17S-FIELDNAME,
    DESCFLAG TYPE DD17S-DESCFLAG,
  END OF TY_INDEXFIELD.
  FIELD-SYMBOLS: <WA_INDEXFIELD> TYPE TY_INDEXFIELD.
  DATA: INDEXFIELDSTMP TYPE TABLE OF TY_INDEXFIELD.

  SELECT
  l~SQLTAB l~INDEXNAME l~POSITION l~FIELDNAME l~DESCFLAG
  FROM DD17S AS l
  INNER JOIN DD02L AS t
    ON l~SQLTAB EQ t~TABNAME
    AND t~AS4LOCAL = 'A'
  INTO TABLE INDEXFIELDSTMP
  WHERE t~TABCLASS IN ('TRANSP','POOL','CLUSTER')
  AND  l~AS4LOCAL = 'A'
  ORDER BY l~SQLTAB l~INDEXNAME l~POSITION.

  LOOP AT INDEXFIELDSTMP ASSIGNING <WA_INDEXFIELD>.
    CONCATENATE
    <WA_INDEXFIELD>-SQLTAB <WA_INDEXFIELD>-INDEXNAME <WA_INDEXFIELD>-POSITION
    <WA_INDEXFIELD>-FIELDNAME <WA_INDEXFIELD>-DESCFLAG
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE INDEXFIELDSTMP.
ENDFORM.

FORM Z_QUERY_PACKAGEVIEWS
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.
  TYPES: BEGIN OF TY_PACKAGEVIEW,
    DEVCLASS TYPE TADIR-DEVCLASS,
    VIEWNAME TYPE TADIR-OBJ_NAME,
  END OF TY_PACKAGEVIEW.

  FIELD-SYMBOLS: <WA_PACKAGEVIEW> TYPE TY_PACKAGEVIEW.
  DATA: PACKAGEVIEWSTMP TYPE TABLE OF TY_PACKAGEVIEW.

  SELECT
  DISTINCT l~DEVCLASS l~OBJ_NAME
  FROM TADIR AS l
  INNER JOIN DD25L AS v
    ON l~OBJ_NAME EQ v~VIEWNAME
    AND v~AS4LOCAL = 'A'
    AND v~AGGTYPE = 'V'
  INNER JOIN DD02L AS t
    ON v~ROOTTAB EQ t~TABNAME
    AND t~AS4LOCAL = 'A'
  INTO TABLE PACKAGEVIEWSTMP
  BYPASSING BUFFER
  WHERE t~TABCLASS IN ('TRANSP','POOL','CLUSTER', 'VIEW')
  AND l~OBJECT = 'VIEW'
  AND l~DEVCLASS <> ' '
  AND NOT l~DEVCLASS LIKE '  %'
  ORDER BY l~OBJ_NAME l~DEVCLASS .

  LOOP AT PACKAGEVIEWSTMP ASSIGNING <WA_PACKAGEVIEW>.
    CONCATENATE
    <WA_PACKAGEVIEW>-DEVCLASS <WA_PACKAGEVIEW>-VIEWNAME
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE PACKAGEVIEWSTMP.
ENDFORM.

FORM Z_QUERY_VIEWS
USING P_LANGUAGE TYPE L001TAB-DATA
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.
  DATA: CLEAN_DESCRIPTION TYPE STRING.

  TYPES: BEGIN OF TY_VIEW,
    VIEWNAME TYPE DD25L-VIEWNAME,
    VIEWCLASS TYPE DD25L-VIEWCLASS,
    ROOTTAB TYPE DD25L-ROOTTAB,
    DDTEXT TYPE DD25T-DDTEXT,
  END OF TY_VIEW.
  FIELD-SYMBOLS: <WA_VIEW> TYPE TY_VIEW.
  DATA: VIEWSTMP TYPE TABLE OF TY_VIEW.

  SELECT
  view~VIEWNAME view~VIEWCLASS view~ROOTTAB text~DDTEXT
  INTO TABLE VIEWSTMP
  FROM DD25L as view
  INNER JOIN DD02L AS tab
    ON view~ROOTTAB EQ tab~TABNAME
    AND tab~AS4LOCAL = 'A'
  LEFT JOIN DD25T as text ON
    view~VIEWNAME EQ text~VIEWNAME
    AND DDLANGUAGE EQ P_LANGUAGE
    AND text~AS4LOCAL = 'A'
  WHERE tab~TABCLASS IN ('TRANSP','POOL','CLUSTER','VIEW')
  AND view~AS4LOCAL = 'A'
  AND AGGTYPE = 'V'
  ORDER BY view~VIEWNAME.

  LOOP AT VIEWSTMP ASSIGNING <WA_VIEW>.
    CLEAN_DESCRIPTION = <WA_VIEW>-DDTEXT.
    PERFORM Z_FORM_CLEANSTRING CHANGING CLEAN_DESCRIPTION.
    CONCATENATE
    <WA_VIEW>-VIEWNAME <WA_VIEW>-VIEWCLASS <WA_VIEW>-ROOTTAB CLEAN_DESCRIPTION
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE VIEWSTMP.
ENDFORM.

FORM Z_QUERY_VIEWFIELDS
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.

  TYPES: BEGIN OF TY_VIEWFIELD,
    VIEWNAME TYPE DD27S-VIEWNAME,
    VIEWFIELD TYPE DD27S-VIEWFIELD,
    OBJPOS TYPE DD27S-OBJPOS,
    TABNAME TYPE DD27S-TABNAME,
    FIELDNAME TYPE DD27S-FIELDNAME,
    ROLLNAME TYPE DD27S-ROLLNAME,
  TABCLASS TYPE DD02L-TABCLASS,
  END OF TY_VIEWFIELD.
  FIELD-SYMBOLS: <WA_VIEWFIELD> TYPE TY_VIEWFIELD.
  DATA: VIEWFIELDSTMP TYPE TABLE OF TY_VIEWFIELD.

  SELECT
  l~VIEWNAME l~VIEWFIELD l~OBJPOS l~TABNAME l~FIELDNAME l~ROLLNAME t~TABCLASS
  FROM DD27S AS l
  INNER JOIN DD25L AS v
    ON l~VIEWNAME EQ v~VIEWNAME
  INNER JOIN DD02L AS t
    ON v~ROOTTAB EQ t~TABNAME
  INTO TABLE VIEWFIELDSTMP
  WHERE t~TABCLASS IN ('TRANSP','POOL','CLUSTER','VIEW')
    AND t~AS4LOCAL = 'A'
    AND v~AS4LOCAL = 'A'
    AND v~AGGTYPE = 'V'
    AND l~AS4LOCAL = 'A'
  ORDER BY l~VIEWNAME l~OBJPOS.

  LOOP AT VIEWFIELDSTMP ASSIGNING <WA_VIEWFIELD>.
    CONCATENATE
    <WA_VIEWFIELD>-VIEWNAME <WA_VIEWFIELD>-VIEWFIELD <WA_VIEWFIELD>-OBJPOS
    <WA_VIEWFIELD>-TABNAME <WA_VIEWFIELD>-FIELDNAME <WA_VIEWFIELD>-ROLLNAME
  <WA_VIEWFIELD>-TABCLASS
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE VIEWFIELDSTMP.
ENDFORM.

FORM Z_QUERY_VIEWTABLES
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.

  TYPES: BEGIN OF TY_VIEWTABLE,
    VIEWNAME TYPE DD26S-VIEWNAME,
    TABNAME TYPE DD26S-TABNAME,
    TABPOS TYPE DD26S-TABPOS,
    FORTABNAME TYPE DD26S-FORTABNAME,
    FORDIR TYPE DD26S-FORDIR,
  END OF TY_VIEWTABLE.
  FIELD-SYMBOLS: <WA_VIEWTABLE> TYPE TY_VIEWTABLE.
  DATA: VIEWTABLESTMP TYPE TABLE OF TY_VIEWTABLE.

  SELECT
  l~VIEWNAME l~TABNAME l~TABPOS l~FORTABNAME l~FORDIR
  FROM DD26S AS l
  INNER JOIN DD25L AS v
    ON l~VIEWNAME EQ v~VIEWNAME
  INNER JOIN DD02L AS t
    ON v~ROOTTAB EQ t~TABNAME
  INTO TABLE VIEWTABLESTMP
  WHERE t~TABCLASS IN ('TRANSP','POOL','CLUSTER','VIEW')
  AND t~AS4LOCAL = 'A'
  AND v~AS4LOCAL = 'A'
  AND v~AGGTYPE = 'V'
  AND l~AS4LOCAL = 'A'
  ORDER BY l~VIEWNAME l~TABPOS.

  LOOP AT VIEWTABLESTMP ASSIGNING <WA_VIEWTABLE>.
    CONCATENATE
    <WA_VIEWTABLE>-VIEWNAME <WA_VIEWTABLE>-TABNAME <WA_VIEWTABLE>-FORTABNAME
    <WA_VIEWTABLE>-FORDIR
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE VIEWTABLESTMP.
ENDFORM.

FORM Z_QUERY_VIEWCONDS
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.

  TYPES: BEGIN OF TY_VIEWCOND,
    CONDNAME TYPE DD28S-CONDNAME,
    POSITION TYPE DD28S-POSITION,
    TABNAME TYPE DD28S-TABNAME,
    FIELDNAME TYPE DD28S-FIELDNAME,
    NEGATION TYPE DD28S-NEGATION,
    OPERATOR TYPE DD28S-OPERATOR,
    CONSTANTS TYPE DD28S-CONSTANTS,
    AND_OR TYPE DD28S-AND_OR,
  END OF TY_VIEWCOND.
  FIELD-SYMBOLS: <WA_VIEWCOND> TYPE TY_VIEWCOND.
  DATA: VIEWCONDSTMP TYPE TABLE OF TY_VIEWCOND.

  SELECT
  l~CONDNAME l~POSITION l~TABNAME l~FIELDNAME l~NEGATION l~OPERATOR l~CONSTANTS l~AND_OR
  FROM DD28S AS l
  INNER JOIN DD25L AS v
    ON l~CONDNAME EQ v~VIEWNAME
  INNER JOIN DD02L AS t
    ON v~ROOTTAB EQ t~TABNAME
  INTO TABLE VIEWCONDSTMP
  WHERE t~TABCLASS IN ('TRANSP','POOL','CLUSTER','VIEW')
  AND t~AS4LOCAL = 'A'
  AND v~AS4LOCAL = 'A'
  AND v~AGGTYPE = 'V'
  AND l~AS4LOCAL = 'A'
  ORDER BY l~CONDNAME l~POSITION.

  LOOP AT VIEWCONDSTMP ASSIGNING <WA_VIEWCOND>.
    CONCATENATE
    <WA_VIEWCOND>-CONDNAME <WA_VIEWCOND>-POSITION <WA_VIEWCOND>-TABNAME
    <WA_VIEWCOND>-FIELDNAME <WA_VIEWCOND>-NEGATION <WA_VIEWCOND>-OPERATOR
    <WA_VIEWCOND>-CONSTANTS <WA_VIEWCOND>-AND_OR
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE VIEWCONDSTMP.
ENDFORM.

FORM Z_QUERY_PACKAGES
USING P_LANGUAGE TYPE L001TAB-DATA
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.

  TYPES: BEGIN OF TY_PACKAGE,
    DEVCLASS TYPE TDEVC-DEVCLASS,
    COMPONENT TYPE TDEVC-COMPONENT,
    PARENTCL TYPE TDEVC-PARENTCL,
    CTEXT TYPE TDEVCT-CTEXT,
  END OF TY_PACKAGE.
  FIELD-SYMBOLS: <WA_PACKAGE> TYPE TY_PACKAGE.
  DATA: PACKAGESTMP TYPE TABLE OF TY_PACKAGE.
  DATA: EXPORT_LINECLEANED TYPE STRING.

  SELECT
  l~DEVCLASS l~COMPONENT l~PARENTCL r~CTEXT
  FROM TDEVC AS l
  LEFT OUTER JOIN TDEVCT AS r
  ON l~DEVCLASS EQ r~DEVCLASS
  AND r~SPRAS EQ P_LANGUAGE
  INTO TABLE PACKAGESTMP
  BYPASSING BUFFER
  ORDER BY l~DEVCLASS.

  LOOP AT PACKAGESTMP ASSIGNING <WA_PACKAGE>.
	EXPORT_LINECLEANED = <WA_PACKAGE>-CTEXT
    PERFORM Z_FORM_CLEANSTRING CHANGING EXPORT_LINECLEANED.
    CONCATENATE
    <WA_PACKAGE>-DEVCLASS <WA_PACKAGE>-COMPONENT <WA_PACKAGE>-PARENTCL EXPORT_LINECLEANED
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE PACKAGESTMP.
ENDFORM.

FORM Z_QUERY_PACKAGETABLES
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.
  TYPES: BEGIN OF TY_PACKAGETABLE,
    DEVCLASS TYPE TADIR-DEVCLASS,
    TABNAME TYPE TADIR-OBJ_NAME,
  END OF TY_PACKAGETABLE.
  FIELD-SYMBOLS: <WA_PACKAGETABLE> TYPE TY_PACKAGETABLE.
  DATA: PACKAGETABLESTMP TYPE TABLE OF TY_PACKAGETABLE.

  SELECT
  DISTINCT l~DEVCLASS l~OBJ_NAME
  FROM TADIR AS l
  INNER JOIN DD02L AS t
    ON l~OBJ_NAME EQ t~TABNAME
    AND t~AS4LOCAL = 'A'
  INTO TABLE PACKAGETABLESTMP
  BYPASSING BUFFER
  WHERE t~TABCLASS IN ('TRANSP','POOL','CLUSTER')
  AND l~OBJECT = 'TABL'
  AND l~DEVCLASS <> ' '
  AND NOT l~DEVCLASS LIKE '  %'
  ORDER BY l~OBJ_NAME.

  LOOP AT PACKAGETABLESTMP ASSIGNING <WA_PACKAGETABLE>.
    CONCATENATE
    <WA_PACKAGETABLE>-DEVCLASS <WA_PACKAGETABLE>-TABNAME
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE PACKAGETABLESTMP.
ENDFORM.

FORM Z_QUERY_DATAELEMENTDOCS
USING P_LANGUAGE TYPE L001TAB-DATA
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.

  TYPES: BEGIN OF TY_DOCUMENTATIONLINE,
    ID TYPE DOKTL-ID,
    OBJECT TYPE DOKTL-OBJECT,
    LANGU TYPE DOKTL-LANGU,
    TYP TYPE DOKTL-TYP,
    DOKVERSION TYPE DOKTL-DOKVERSION,
    LINE TYPE DOKTL-LINE,
    DOKFORMAT TYPE DOKTL-DOKFORMAT,
    DOKTEXT TYPE DOKTL-DOKTEXT,
  END OF TY_DOCUMENTATIONLINE.
  TYPES: BEGIN OF TY_DOCUMENTATIONINDEX,
    OBJECT TYPE DOKIL-OBJECT,
    VERSION TYPE DOKIL-VERSION,
  END OF TY_DOCUMENTATIONINDEX.

  DATA: EXPORT_LINECLEANED TYPE STRING.
  DATA: DOCUMENTATIONINDEXTMP TYPE TABLE OF TY_DOCUMENTATIONINDEX.
  DATA: DOCUMENTATIONLINESTMP TYPE TABLE OF TY_DOCUMENTATIONLINE.
  FIELD-SYMBOLS: <WA_DOCUMENTATIONLINE> TYPE TY_DOCUMENTATIONLINE.

  " Query the documentation indexes
  SELECT DISTINCT l~OBJECT l~VERSION
  FROM DOKIL AS l
  INNER JOIN DD03L AS f
    ON l~OBJECT EQ f~ROLLNAME
  INNER JOIN DD02L AS t
    ON f~TABNAME EQ t~TABNAME
  INTO TABLE DOCUMENTATIONINDEXTMP
  BYPASSING BUFFER
  WHERE t~TABCLASS IN ('TRANSP','POOL','CLUSTER')
  AND t~AS4LOCAL = 'A'
  AND f~AS4LOCAL = 'A'
  AND f~FIELDNAME NOT LIKE '.%'
  AND l~ID = 'DE'
  AND l~TYP = 'E'
  AND l~LANGU EQ P_LANGUAGE
  ORDER BY l~OBJECT.

  IF sy-subrc = 0.
    " Query the documentation lines for each index
    " Table DOKTL is a Cluster table, JOIN is not allowed, use FOR ALL ENTRIES instead
    SELECT ID OBJECT LANGU TYP DOKVERSION LINE DOKFORMAT DOKTEXT
    FROM DOKTL
    INTO TABLE DOCUMENTATIONLINESTMP
    FOR ALL ENTRIES IN DOCUMENTATIONINDEXTMP
    WHERE ID = 'DE'
    AND OBJECT = DOCUMENTATIONINDEXTMP-OBJECT
    AND LANGU EQ P_LANGUAGE
    AND DOKVERSION = DOCUMENTATIONINDEXTMP-VERSION
    ORDER BY PRIMARY KEY. "#EC CI_NO_TRANSFORM
  ENDIF.

  LOOP AT DOCUMENTATIONLINESTMP ASSIGNING <WA_DOCUMENTATIONLINE>.
    EXPORT_LINECLEANED = <WA_DOCUMENTATIONLINE>-DOKTEXT.
    PERFORM Z_FORM_CLEANSTRING CHANGING EXPORT_LINECLEANED.
    CONCATENATE
    <WA_DOCUMENTATIONLINE>-OBJECT <WA_DOCUMENTATIONLINE>-LINE <WA_DOCUMENTATIONLINE>-DOKFORMAT EXPORT_LINECLEANED
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE DOCUMENTATIONINDEXTMP.
  FREE DOCUMENTATIONLINESTMP.
ENDFORM.

FORM Z_QUERY_FGROUPS
USING P_LANGUAGE TYPE L001TAB-DATA
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.

  TYPES: BEGIN OF TY_FGROUP,
    OBJ_NAME TYPE TADIR-OBJ_NAME,
    DEVCLASS TYPE TADIR-DEVCLASS,
    AREAT TYPE TLIBT-AREAT,
  END OF TY_FGROUP.
  DATA: FGROUPSTMP TYPE TABLE OF TY_FGROUP.
  FIELD-SYMBOLS: <WA_FGROUP> TYPE TY_FGROUP.

  SELECT
  DISTINCT l~OBJ_NAME l~DEVCLASS r~AREAT
  INTO TABLE FGROUPSTMP
  FROM TADIR AS l
  LEFT OUTER JOIN TLIBT AS r
  ON l~OBJ_NAME EQ r~AREA
  AND r~SPRAS EQ P_LANGUAGE
  BYPASSING BUFFER
  WHERE OBJECT IN ('FUGR','FUGS','FUGX')
  ORDER BY l~OBJ_NAME l~DEVCLASS.

  LOOP AT FGROUPSTMP ASSIGNING <WA_FGROUP>.
    CONCATENATE
    <WA_FGROUP>-OBJ_NAME <WA_FGROUP>-DEVCLASS <WA_FGROUP>-AREAT
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE FGROUPSTMP.
ENDFORM.

FORM Z_QUERY_FGROUPDOCS
USING P_LANGUAGE TYPE L001TAB-DATA
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.
  TYPES: BEGIN OF TY_DOCUMENTATIONLINE,
    ID TYPE DOKTL-ID,
    OBJECT TYPE DOKTL-OBJECT,
    LANGU TYPE DOKTL-LANGU,
    TYP TYPE DOKTL-TYP,
    DOKVERSION TYPE DOKTL-DOKVERSION,
    LINE TYPE DOKTL-LINE,
    DOKFORMAT TYPE DOKTL-DOKFORMAT,
    DOKTEXT TYPE DOKTL-DOKTEXT,
  END OF TY_DOCUMENTATIONLINE.
  TYPES: BEGIN OF TY_DOCUMENTATIONINDEX,
    OBJECT TYPE DOKIL-OBJECT,
    VERSION TYPE DOKIL-VERSION,
  END OF TY_DOCUMENTATIONINDEX.
  DATA: EXPORT_LINECLEANED TYPE STRING.
  FIELD-SYMBOLS: <WA_DOCUMENTATIONLINE> TYPE TY_DOCUMENTATIONLINE.
  DATA: DOCUMENTATIONLINESTMP TYPE TABLE OF TY_DOCUMENTATIONLINE.
  DATA: DOCUMENTATIONINDEXTMP TYPE TABLE OF TY_DOCUMENTATIONINDEX.

  " Query the documentation indexes
  SELECT l~OBJECT l~VERSION
  FROM DOKIL AS l
  INNER JOIN TADIR as f
    ON l~OBJECT EQ f~OBJ_NAME
  INTO TABLE DOCUMENTATIONINDEXTMP
  BYPASSING BUFFER
  WHERE f~OBJECT IN ('FUGR','FUGS','FUGX')
  AND l~ID = 'DE'
  AND l~TYP = 'E'
  AND l~LANGU EQ P_LANGUAGE
  ORDER BY l~OBJECT.

  IF sy-subrc = 0.
    " Query the documentation lines for each index
    " Table DOKTL is a Cluster table, JOIN is not allowed, use FOR ALL ENTRIES instead
    SELECT ID OBJECT LANGU TYP DOKVERSION LINE DOKFORMAT DOKTEXT
    FROM DOKTL
    INTO TABLE DOCUMENTATIONLINESTMP
    FOR ALL ENTRIES IN DOCUMENTATIONINDEXTMP
    WHERE ID = 'DE'
    AND OBJECT = DOCUMENTATIONINDEXTMP-OBJECT
    AND LANGU EQ P_LANGUAGE
    AND DOKVERSION = DOCUMENTATIONINDEXTMP-VERSION
    ORDER BY PRIMARY KEY. "#EC CI_NO_TRANSFORM
  ENDIF.

  LOOP AT DOCUMENTATIONLINESTMP ASSIGNING <WA_DOCUMENTATIONLINE>.
    EXPORT_LINECLEANED = <WA_DOCUMENTATIONLINE>-DOKTEXT.
    PERFORM Z_FORM_CLEANSTRING CHANGING EXPORT_LINECLEANED.
    CONCATENATE
    <WA_DOCUMENTATIONLINE>-OBJECT <WA_DOCUMENTATIONLINE>-LINE <WA_DOCUMENTATIONLINE>-DOKFORMAT EXPORT_LINECLEANED
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE DOCUMENTATIONINDEXTMP.
  FREE DOCUMENTATIONLINESTMP.
ENDFORM.

FORM Z_QUERY_TRANSACTIONS
USING P_LANGUAGE TYPE L001TAB-DATA
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.

  TYPES: BEGIN OF TY_TRANS,
    OBJ_NAME TYPE TADIR-OBJ_NAME,
    DEVCLASS TYPE TADIR-DEVCLASS,
    TTEXT TYPE TSTCT-TTEXT,
  END OF TY_TRANS.
  FIELD-SYMBOLS: <WA_TRANS> TYPE TY_TRANS.
  DATA: TRANSTMP TYPE TABLE OF TY_TRANS.

  SELECT
  DISTINCT l~OBJ_NAME l~DEVCLASS r~TTEXT
  INTO TABLE TRANSTMP
  FROM TADIR AS l
  LEFT OUTER JOIN TSTCT AS r
  ON l~OBJ_NAME EQ r~TCODE
  AND r~SPRSL EQ P_LANGUAGE
  BYPASSING BUFFER
  WHERE OBJECT EQ 'TRAN'
  ORDER BY l~OBJ_NAME l~DEVCLASS.

  LOOP AT TRANSTMP ASSIGNING <WA_TRANS>.
    CONCATENATE
    <WA_TRANS>-OBJ_NAME <WA_TRANS>-DEVCLASS <WA_TRANS>-TTEXT
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE TRANSTMP.
ENDFORM.

FORM Z_QUERY_TRANSACTIONPROGRAMS
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.

  TYPES: BEGIN OF TY_TRANPROG,
    TCODE TYPE TSTC-TCODE,
    PGMNA TYPE TSTC-PGMNA,
  END OF TY_TRANPROG.
  FIELD-SYMBOLS: <WA_TRANPROG> TYPE TY_TRANPROG.
  DATA: TRANPROGSTMP TYPE TABLE OF TY_TRANPROG.

  SELECT
  TCODE PGMNA
  FROM TSTC
  INTO TABLE TRANPROGSTMP
  BYPASSING BUFFER
  ORDER BY TCODE PGMNA.

  LOOP AT TRANPROGSTMP ASSIGNING <WA_TRANPROG>.
    CONCATENATE
    <WA_TRANPROG>-TCODE <WA_TRANPROG>-PGMNA
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE TRANPROGSTMP.
ENDFORM.

FORM Z_QUERY_TRANSACTIONPARAMS
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.

  TYPES: BEGIN OF TY_TRANPARAM,
    TCODE TYPE TSTCP-TCODE,
    PARAM TYPE TSTCP-PARAM,
  END OF TY_TRANPARAM.
  FIELD-SYMBOLS: <WA_TRANPARAM> TYPE TY_TRANPARAM.
  DATA: TRANPARAMSTMP TYPE TABLE OF TY_TRANPARAM.

  SELECT
  TCODE PARAM
  FROM TSTCP
  INTO TABLE TRANPARAMSTMP
  BYPASSING BUFFER
  ORDER BY TCODE.

  LOOP AT TRANPARAMSTMP ASSIGNING <WA_TRANPARAM>.
    CONCATENATE
    <WA_TRANPARAM>-TCODE <WA_TRANPARAM>-PARAM
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE TRANPARAMSTMP.
ENDFORM.

FORM Z_QUERY_PROGRAMS
USING P_LANGUAGE TYPE L001TAB-DATA
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.

  TYPES: BEGIN OF TY_PROG,
    OBJ_NAME TYPE TADIR-OBJ_NAME,
    DEVCLASS TYPE TADIR-DEVCLASS,
    TEXT TYPE TRDIRT-TEXT,
  END OF TY_PROG.
  FIELD-SYMBOLS: <WA_PROG> TYPE TY_PROG.
  DATA: PROGTMP TYPE TABLE OF TY_PROG.

  SELECT DISTINCT l~OBJ_NAME l~DEVCLASS r~TEXT
  INTO TABLE PROGTMP
  FROM TADIR  AS l
  INNER JOIN D010TAB AS dep ON dep~MASTER = l~OBJ_NAME
  LEFT OUTER JOIN TRDIRT AS r
  ON l~OBJ_NAME EQ r~NAME
  AND r~SPRSL EQ P_LANGUAGE
  BYPASSING BUFFER
  WHERE OBJECT = 'PROG'
*  AND OBJ_NAME IN
* ( SELECT DISTINCT MASTER FROM D010TAB )
  ORDER BY l~OBJ_NAME l~DEVCLASS.

  LOOP AT PROGTMP ASSIGNING <WA_PROG>.
    CONCATENATE
    <WA_PROG>-OBJ_NAME <WA_PROG>-DEVCLASS <WA_PROG>-TEXT
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE PROGTMP.
ENDFORM.


FORM Z_QUERY_CLAS
USING P_LANGUAGE TYPE L001TAB-DATA
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.

  TYPES: BEGIN OF TY_CLAS,
    OBJ_NAME TYPE TADIR-OBJ_NAME,
    DEVCLASS TYPE TADIR-DEVCLASS,
    DESCRIPT TYPE SEOCLASSTX-DESCRIPT,
  END OF TY_CLAS.
  FIELD-SYMBOLS: <WA_CLAS> TYPE TY_CLAS.
  DATA: CLASTMP TYPE TABLE OF TY_CLAS.
  DATA: EXPORT_LINECLEANED TYPE STRING.

  SELECT DISTINCT l~OBJ_NAME l~DEVCLASS r~DESCRIPT
  INTO TABLE CLASTMP
  FROM TADIR  AS l
  LEFT OUTER JOIN SEOCLASSTX AS r
    ON l~OBJ_NAME EQ r~CLSNAME
    AND r~LANGU EQ P_LANGUAGE
  BYPASSING BUFFER
  WHERE OBJECT = 'CLAS'
*      AND OBJ_NAME IN
*      ( SELECT DISTINCT MASTER FROM D010TAB )
  ORDER BY l~OBJ_NAME l~DEVCLASS.

  LOOP AT CLASTMP ASSIGNING <WA_CLAS>.
	EXPORT_LINECLEANED = <WA_CLAS>-DESCRIPT.
    PERFORM Z_FORM_CLEANSTRING CHANGING EXPORT_LINECLEANED.
    CONCATENATE
    <WA_CLAS>-OBJ_NAME <WA_CLAS>-DEVCLASS EXPORT_LINECLEANED
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE CLASTMP.
ENDFORM.


FORM Z_QUERY_SYSTEMINFO
USING FUNCTION_VERSION TYPE STRING
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.
  DATA: RFCSI TYPE RFCSI.

    CALL FUNCTION 'RFC_SYSTEM_INFO'
       IMPORTING rfcsi_export = rfcsi.

    CONCATENATE
      RFCSI-RFCHOST RFCSI-RFCSYSID RFCSI-RFCSAPRL FUNCTION_VERSION RFCSI-RFCDEST
*      RFCSI-RFCPROTO RFCSI-RFCCHARTYP RFCSI-RFCINTTYP
*      RFCSI-RFCFLOTYP RFCSI-RFCDEST RFCSI-RFCHOST
*      RFCSI-RFCSYSID RFCSI-RFCDATABS RFCSI-RFCDBHOST
*      RFCSI-RFCDBSYS RFCSI-RFCSAPRL RFCSI-RFCMACH
*      RFCSI-RFCOPSYS RFCSI-RFCTZONE RFCSI-RFCDAYST
*      RFCSI-RFCIPADDR RFCSI-RFCKERNRL RFCSI-RFCHOST2
*      RFCSI-RFCSI_RESV RFCSI-RFCIPV6ADDR
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
ENDFORM.

FORM Z_QUERY_PROGRAM_TABLES
USING ROWSKIPS TYPE SO_INT
      ROWCOUNT TYPE SO_INT
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.
  TYPES: BEGIN OF TY_PROGRAMTABLE,
    MASTER TYPE D010TAB-MASTER,
    TABNAME TYPE D010TAB-TABNAME,
  END OF TY_PROGRAMTABLE.
  FIELD-SYMBOLS: <WA_PROGRAMTABLE> TYPE TY_PROGRAMTABLE.
  DATA: PROGRAM_TABLESTMP TYPE TABLE OF TY_PROGRAMTABLE.
  DATA: ROWINDEX TYPE SO_INT.
  DATA: ROWEND TYPE SO_INT.

  SELECT l~MASTER l~TABNAME
  FROM D010TAB AS l
  INNER JOIN DD02L AS t
    ON l~TABNAME EQ t~TABNAME
    AND t~AS4LOCAL = 'A'
  INTO TABLE PROGRAM_TABLESTMP
  WHERE t~TABCLASS IN ('TRANSP','POOL','CLUSTER')
*  ===Filter for classes(Cannot use a filter because class names in most cases contain suffixes in D010TAB table)
*  AND MASTER IN
*  ( SELECT OBJ_NAME FROM TADIR
*      WHERE OBJECT = 'CLAS' )
*  ===Filter for FunctionGroups
*    MASTER LIKE 'SAPL%'
*  ===Filter for Programs
*    MASTER IN
*  ( SELECT DISTINCT OBJ_NAME FROM TADIR
*  WHERE OBJECT = 'PROG' )
  ORDER BY l~MASTER l~TABNAME.

  ROWINDEX = 0.
  ROWEND = ROWSKIPS + ROWCOUNT.
  LOOP AT PROGRAM_TABLESTMP ASSIGNING <WA_PROGRAMTABLE>.
    IF ROWCOUNT = 0 OR ( ROWINDEX >= ROWSKIPS AND ROWINDEX < ROWEND ) .
      CONCATENATE
      <WA_PROGRAMTABLE>-MASTER <WA_PROGRAMTABLE>-TABNAME
      INTO EXPORT_LINE
      SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
      APPEND EXPORT_LINE TO EXPORT_TABLE.
    ELSEIF ROWCOUNT > 0 AND ROWINDEX >= ROWEND.
      EXIT.
    ENDIF.
    ROWINDEX = ROWINDEX + 1.
  ENDLOOP.
  FREE PROGRAM_TABLESTMP.
ENDFORM.

FORM Z_QUERY_PROGRAM_VIEWS
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.
  TYPES: BEGIN OF TY_PROGRAMVIEW,
    MASTER TYPE D010TAB-MASTER,
    TABNAME TYPE D010TAB-TABNAME,
  END OF TY_PROGRAMVIEW.
  FIELD-SYMBOLS: <WA_PROGRAMVIEW> TYPE TY_PROGRAMVIEW.
  DATA: PROGRAM_VIEWSTMP TYPE TABLE OF TY_PROGRAMVIEW.

  SELECT l~MASTER l~TABNAME
  FROM D010TAB AS l
  INNER JOIN DD25L AS v
    ON l~TABNAME EQ v~VIEWNAME
    AND v~AS4LOCAL = 'A'
    AND v~AGGTYPE = 'V'
  INTO TABLE PROGRAM_VIEWSTMP
*  ===Filter for classes(Cannot use a filter because class names in most cases contain suffixes in D010TAB table)
*  AND MASTER IN
*  ( SELECT OBJ_NAME FROM TADIR
*      WHERE OBJECT = 'CLAS' )
*  ===Filter for FunctionGroups
*    MASTER LIKE 'SAPL%'
*  ===Filter for Programs
*    MASTER IN
*  ( SELECT DISTINCT OBJ_NAME FROM TADIR
*  WHERE OBJECT = 'PROG' )
  ORDER BY l~MASTER l~TABNAME.

  LOOP AT PROGRAM_VIEWSTMP ASSIGNING <WA_PROGRAMVIEW>.
    CONCATENATE
    <WA_PROGRAMVIEW>-MASTER <WA_PROGRAMVIEW>-TABNAME
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE PROGRAM_VIEWSTMP.
ENDFORM.

FORM Z_QUERY_IDOCTYPES
USING P_LANGUAGE TYPE L001TAB-DATA
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.
  TYPES: BEGIN OF TY_IDOCTYPE,
    DOCTYP TYPE EDIDO-DOCTYP,
    IDOCTYP TYPE EDIDO-IDOCTYP,
    CIMTYP TYPE EDIDO-CIMTYP,
    DESCRP TYPE EDIDOT-DESCRP,
    PRESP TYPE EDIDO-PRESP,
    PWORK TYPE EDIDO-PWORK,
  END OF TY_IDOCTYPE.
  FIELD-SYMBOLS: <WA_IDOCTYPE> TYPE TY_IDOCTYPE.
  DATA: IDOCTYPES_TMP TYPE TABLE OF TY_IDOCTYPE.

  SELECT d~DOCTYP d~IDOCTYP d~CIMTYP t~DESCRP d~PRESP d~PWORK
  INTO TABLE IDOCTYPES_TMP
  FROM EDIDO AS d
  LEFT OUTER JOIN EDIDOT AS t
    ON d~DOCTYP EQ t~DOCTYP
    AND t~LANGUA EQ P_LANGUAGE
  BYPASSING BUFFER.

  LOOP AT IDOCTYPES_TMP ASSIGNING <WA_IDOCTYPE>.
    CONCATENATE
    <WA_IDOCTYPE>-DOCTYP <WA_IDOCTYPE>-IDOCTYP <WA_IDOCTYPE>-CIMTYP <WA_IDOCTYPE>-DESCRP
    <WA_IDOCTYPE>-PRESP <WA_IDOCTYPE>-PWORK
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE IDOCTYPES_TMP.
ENDFORM.

FORM Z_QUERY_BASEIDOCTYPES
USING P_LANGUAGE TYPE L001TAB-DATA
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.
  TYPES: BEGIN OF TY_BASEIDOCTYPE,
    IDOCTYP TYPE EDBAS-IDOCTYP,
    DESCRP TYPE EDBAST-DESCRP,
    PRESP TYPE EDBAS-PRESP,
    PWORK TYPE EDBAS-PWORK,
  END OF TY_BASEIDOCTYPE.
  FIELD-SYMBOLS: <WA_BASEIDOCTYPE> TYPE TY_BASEIDOCTYPE.
  DATA: BASEIDOCTYPES_TMP TYPE TABLE OF TY_BASEIDOCTYPE.

  SELECT d~IDOCTYP t~DESCRP d~PRESP d~PWORK
  INTO TABLE BASEIDOCTYPES_TMP
  FROM EDBAS AS d
  LEFT OUTER JOIN EDBAST AS t
    ON d~IDOCTYP EQ t~IDOCTYP
    AND t~LANGUA EQ P_LANGUAGE
  BYPASSING BUFFER.

  LOOP AT BASEIDOCTYPES_TMP ASSIGNING <WA_BASEIDOCTYPE>.
    CONCATENATE
    <WA_BASEIDOCTYPE>-IDOCTYP <WA_BASEIDOCTYPE>-DESCRP <WA_BASEIDOCTYPE>-PRESP <WA_BASEIDOCTYPE>-PWORK
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE BASEIDOCTYPES_TMP.
ENDFORM.

FORM Z_QUERY_FUNCTIONMODULES
USING P_LANGUAGE TYPE L001TAB-DATA
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.
  TYPES: BEGIN OF TY_FUNCMODULE,
    FUNCNAME TYPE TFDIR-FUNCNAME,
    AREA TYPE ENLFDIR-AREA,
    STEXT TYPE TFTIT-STEXT,
  END OF TY_FUNCMODULE.
  FIELD-SYMBOLS: <WA_FUNCMODULE> TYPE TY_FUNCMODULE.
  DATA: FUNCMODULESTMP TYPE TABLE OF TY_FUNCMODULE.

  SELECT fd~FUNCNAME f~AREA t~STEXT
  FROM TFDIR AS fd
  INNER JOIN ENLFDIR AS f
    ON fd~FUNCNAME EQ f~FUNCNAME
  LEFT OUTER JOIN TFTIT AS t
    ON fd~FUNCNAME EQ t~FUNCNAME
  AND t~SPRAS EQ P_LANGUAGE
    INTO TABLE FUNCMODULESTMP
  BYPASSING BUFFER
  WHERE fd~FMODE = 'R' AND f~ACTIVE = 'X'
  ORDER BY fd~FUNCNAME.

  LOOP AT FUNCMODULESTMP ASSIGNING <WA_FUNCMODULE>.
    CONCATENATE
    <WA_FUNCMODULE>-FUNCNAME <WA_FUNCMODULE>-AREA <WA_FUNCMODULE>-STEXT
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE FUNCMODULESTMP.
ENDFORM.

FORM Z_QUERY_FUNCTIONMODULEPARAMS
USING P_LANGUAGE TYPE L001TAB-DATA
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.
  TYPES: BEGIN OF TY_FUNCPARAM,
    FUNCNAME TYPE TFDIR-FUNCNAME,
    PARAMETER TYPE FUPARAREF-PARAMETER,
    PARAMTYPE TYPE FUPARAREF-PARAMTYPE,
    STRUCTURE TYPE FUPARAREF-STRUCTURE,
  END OF TY_FUNCPARAM.
  FIELD-SYMBOLS: <WA_FUNCPARAM> TYPE TY_FUNCPARAM.
  DATA: FUPARAMS_TMP TYPE TABLE OF TY_FUNCPARAM.

  SELECT fd~FUNCNAME p~PARAMETER p~PARAMTYPE p~STRUCTURE
  FROM TFDIR AS fd
  INNER JOIN ENLFDIR AS f
    ON fd~FUNCNAME EQ f~FUNCNAME
  LEFT OUTER JOIN FUPARAREF AS P
  ON f~FUNCNAME EQ p~FUNCNAME
  LEFT OUTER JOIN TFTIT AS t
    ON fd~FUNCNAME EQ t~FUNCNAME
  AND t~SPRAS EQ P_LANGUAGE
    INTO TABLE FUPARAMS_TMP
  BYPASSING BUFFER
  WHERE fd~FMODE = 'R' AND f~ACTIVE = 'X'
  ORDER BY fd~FUNCNAME.

  LOOP AT FUPARAMS_TMP ASSIGNING <WA_FUNCPARAM>.
    CONCATENATE
    <WA_FUNCPARAM>-FUNCNAME <WA_FUNCPARAM>-PARAMETER <WA_FUNCPARAM>-PARAMTYPE <WA_FUNCPARAM>-STRUCTURE
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE FUPARAMS_TMP.
ENDFORM.

* ------------------------------------------------------------------- *
FORM Z_QUERY_SWCOMPS
CHANGING P_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: it_tt_comptab    TYPE STANDARD TABLE OF SPAM_CVERS.
  DATA: it_et_components TYPE STANDARD TABLE OF COMP_PROPS.
  DATA: it_et_complayer	 TYPE STANDARD TABLE OF SPAM_CLAYR.
  DATA: it_et_cvers_sub	 TYPE STANDARD TABLE OF CVERS_SUB.
*  FIELD-SYMBOLS: <wa_tt_comptab> TYPE SPAM_CVERS.
  FIELD-SYMBOLS: <wa_et_components> TYPE COMP_PROPS.
*  FIELD-SYMBOLS: <wa_et_complayer> TYPE SPAM_CLAYR.
*  FIELD-SYMBOLS: <wa_et_cvers_sub> TYPE CVERS_SUB.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.

  CALL FUNCTION 'OCS_GET_INSTALLED_COMPS'
    EXPORTING
      iv_patchable_only       = ' '
      iv_active_only          = ' '
      iv_buffered             = ' '
  TABLES
    tt_comptab              = it_tt_comptab
    et_components           = it_et_components
    et_complayer            = it_et_complayer
    et_cvers_sub            = it_et_cvers_sub
  EXCEPTIONS
      NO_RELEASE_FOUND =           1
      WRONG_RELEASE =              2
    .

  IF SY-SUBRC EQ 0.
    "Success
    LOOP AT it_et_components ASSIGNING <wa_et_components>.
      CONCATENATE
      <wa_et_components>-COMPONENT <wa_et_components>-RELEASE
      INTO EXPORT_LINE
      SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
      APPEND EXPORT_LINE TO P_TABLE.
    ENDLOOP.
  ELSEIF SY-SUBRC EQ 1.
    "Add code for exception here
  ELSEIF SY-SUBRC EQ 2. "Exception
    "Add code for exception here
  ENDIF.

  FREE it_et_components.
  FREE it_tt_comptab.
  FREE it_et_complayer.
  FREE it_et_cvers_sub.

ENDFORM.

FORM Z_CONVERT_TO_BASE64
USING DDL TYPE STRING
  CHANGING BASE_STRING TYPE STRING.

  DATA: XSTRING TYPE XSTRING.

  CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
  EXPORTING
    text   = DDL
  encoding = '4110'
  IMPORTING
    buffer = XSTRING
    EXCEPTIONS
      FAILED = 1
      OTHERS = 2.

  CALL FUNCTION 'SCMS_BASE64_ENCODE_STR'
  EXPORTING
    input = XSTRING
  IMPORTING
    output =  BASE_STRING.

ENDFORM.

FORM Z_QUERY_VIEWDDL
USING P_LANGUAGE TYPE L001TAB-DATA
      ROWSKIPS TYPE SO_INT
      ROWCOUNT TYPE SO_INT
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.
  TYPES: BEGIN OF TY_DDL,
    OBJECTNAME TYPE DDLDEPENDENCY-OBJECTNAME,
    SOURCE TYPE DDDDLSRC-SOURCE,
  END OF TY_DDL.
  FIELD-SYMBOLS: <WA_DDL> TYPE TY_DDL.
  DATA: DDL_TMP TYPE TABLE OF TY_DDL.

  SELECT dep~OBJECTNAME src~SOURCE
  FROM DDLDEPENDENCY as dep
  INNER JOIN DDDDLSRC as src
    ON src~AS4LOCAL EQ 'A'
    AND dep~DDLNAME EQ src~DDLNAME
  INTO TABLE DDL_TMP
  BYPASSING BUFFER
  WHERE dep~STATE EQ 'A'
    AND dep~OBJECTTYPE EQ 'VIEW'
  ORDER BY dep~OBJECTNAME.

  DATA: LT_STRING_COMP LIKE SWASTRTAB OCCURS 0 WITH HEADER LINE.
  DATA: DDL_ROWS TYPE STRING.
  DATA: ROWINDEX TYPE SO_INT.
  DATA: ROWEND TYPE SO_INT.

** Implement pagination, because 42.877 View object can result in 3.122.204 lines
** Objects have on average ~73 lines
  ROWINDEX = 0.
  ROWEND = ROWSKIPS + ROWCOUNT.
  LOOP AT DDL_TMP ASSIGNING <WA_DDL>.
    CLEAR DDL_ROWS.
    PERFORM Z_CONVERT_TO_BASE64 USING <WA_DDL>-SOURCE CHANGING DDL_ROWS.
    CALL FUNCTION 'SWA_STRING_SPLIT'
  EXPORTING
    INPUT_STRING         = DDL_ROWS
    MAX_COMPONENT_LENGTH = 255
  TABLES
    STRING_COMPONENTS    = LT_STRING_COMP.

    LOOP AT LT_STRING_COMP.
      IF ROWCOUNT = 0 OR ( ROWINDEX >= ROWSKIPS AND ROWINDEX < ROWEND ) .
        CONCATENATE <WA_DDL>-OBJECTNAME lt_string_comp-str
        INTO EXPORT_LINE
        SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
        APPEND EXPORT_LINE TO EXPORT_TABLE.
      ELSEIF ROWCOUNT > 0 AND ROWINDEX >= ROWEND.
        EXIT.
      ENDIF.
      ROWINDEX = ROWINDEX + 1.
    ENDLOOP.
  ENDLOOP.
  FREE DDL_TMP.
ENDFORM.

FORM Z_QUERY_TFDDL
USING P_LANGUAGE TYPE L001TAB-DATA
      ROWSKIPS TYPE SO_INT
      ROWCOUNT TYPE SO_INT
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.
  TYPES: BEGIN OF TY_DDL,
    OBJECTNAME TYPE DDLDEPENDENCY-OBJECTNAME,
    SOURCE TYPE DDDDLSRC-SOURCE,
  END OF TY_DDL.
  FIELD-SYMBOLS: <WA_DDL> TYPE TY_DDL.
  DATA: DDL_TMP TYPE TABLE OF TY_DDL.

  SELECT dep~OBJECTNAME src~SOURCE
  FROM DDLDEPENDENCY as dep
  INNER JOIN DD02B as tf
	ON tf~STRUCOBJN EQ dep~OBJECTNAME
  INNER JOIN DDDDLSRC as src
    ON src~AS4LOCAL EQ 'A'
    AND dep~DDLNAME EQ src~DDLNAME
  INTO TABLE DDL_TMP
  BYPASSING BUFFER
  WHERE dep~STATE EQ 'A'
    AND dep~OBJECTTYPE EQ 'STOB'
  ORDER BY dep~OBJECTNAME.

  DATA: LT_STRING_COMP LIKE SWASTRTAB OCCURS 0 WITH HEADER LINE.
  DATA: DDL_ROWS TYPE STRING.
  DATA: ROWINDEX TYPE SO_INT.
  DATA: ROWEND TYPE SO_INT.

** Implement pagination, because 42.877 View object can result in 3.122.204 lines
** Objects have on average ~73 lines
  ROWINDEX = 0.
  ROWEND = ROWSKIPS + ROWCOUNT.
  LOOP AT DDL_TMP ASSIGNING <WA_DDL>.
    CLEAR DDL_ROWS.
    PERFORM Z_CONVERT_TO_BASE64 USING <WA_DDL>-SOURCE CHANGING DDL_ROWS.
    CALL FUNCTION 'SWA_STRING_SPLIT'
  EXPORTING
    INPUT_STRING         = DDL_ROWS
    MAX_COMPONENT_LENGTH = 255
  TABLES
    STRING_COMPONENTS    = LT_STRING_COMP.

    LOOP AT LT_STRING_COMP.
      IF ROWCOUNT = 0 OR ( ROWINDEX >= ROWSKIPS AND ROWINDEX < ROWEND ) .
        CONCATENATE <WA_DDL>-OBJECTNAME lt_string_comp-str
        INTO EXPORT_LINE
        SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
        APPEND EXPORT_LINE TO EXPORT_TABLE.
      ELSEIF ROWCOUNT > 0 AND ROWINDEX >= ROWEND.
        EXIT.
      ENDIF.
      ROWINDEX = ROWINDEX + 1.
    ENDLOOP.
  ENDLOOP.
  FREE DDL_TMP.
ENDFORM.

FORM Z_QUERY_TABLEFUNC
USING P_LANGUAGE TYPE L001TAB-DATA
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.
  DATA: CLEAN_DESCRIPTION TYPE STRING.

  TYPES: BEGIN OF TY_TF,
    STRUCOBJN TYPE DD02B-STRUCOBJN,
    DDTEXT TYPE DD02BT-DDTEXT,
  DD_TYPE TYPE DDLDEPENDENCY-OBJECTTYPE, 
  END OF TY_TF.
  FIELD-SYMBOLS: <WA_VIEW> TYPE TY_TF.
  DATA: TFTMP TYPE TABLE OF TY_TF.

  SELECT
  tf~STRUCOBJN text~DDTEXT ddl2~OBJECTTYPE
  INTO TABLE TFTMP
  FROM DD02B as tf
  INNER JOIN DDLDEPENDENCY AS ddl
    ON tf~STRUCOBJN EQ ddl~OBJECTNAME
    AND ddl~OBJECTTYPE = 'STOB'
	  AND ddl~STATE = 'A'
  LEFT JOIN DDLDEPENDENCY AS ddl2
    ON tf~STRUCOBJN EQ ddl2~OBJECTNAME
    AND ddl2~OBJECTTYPE = 'VIEW'
	  AND ddl2~STATE = 'A'
  LEFT JOIN DD02BT as text ON
    tf~STRUCOBJN EQ text~STRUCOBJN
    AND DDLANGUAGE EQ P_LANGUAGE
    AND text~AS4LOCAL = 'A'
  WHERE tf~AS4LOCAL = 'A'
  ORDER BY tf~STRUCOBJN.

  LOOP AT TFTMP ASSIGNING <WA_VIEW>.
    CLEAN_DESCRIPTION = <WA_VIEW>-DDTEXT.
    PERFORM Z_FORM_CLEANSTRING CHANGING CLEAN_DESCRIPTION.
    CONCATENATE
    <WA_VIEW>-STRUCOBJN CLEAN_DESCRIPTION <WA_VIEW>-DD_TYPE
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE TFTMP.
ENDFORM.

FORM Z_QUERY_TF_FIELDS
USING P_LANGUAGE TYPE L001TAB-DATA
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.
  DATA: CLEAN_DESCRIPTION TYPE STRING.
  DATA: CLEAN_DESCRIPTION2 TYPE STRING.

  TYPES: BEGIN OF TY_TF,
    STRUCOBJN TYPE DD02B-STRUCOBJN,
    FIELDNAME TYPE DD03ND-FIELDNAME,
    POSITION TYPE DD03ND-POSITION,
    ROLLNAME TYPE DD03ND-ROLLNAME,
    KEYFLAG TYPE DD03ND-KEYFLAG,
    DATATYPE TYPE DD03ND-DATATYPE,
    INTLEN TYPE DD03ND-INTLEN,
    DECIMALS TYPE DD03ND-DECIMALS,
    COMPTYPE TYPE DD03ND-COMPTYPE,
	  DDTEXT TYPE DD03NT-DDTEXT,
  END OF TY_TF.
  FIELD-SYMBOLS: <WA_TF_FIELD> TYPE TY_TF.
  DATA: TFTMP TYPE TABLE OF TY_TF.

  SELECT
  tf~STRUCOBJN l~FIELDNAME l~POSITION l~ROLLNAME l~KEYFLAG
  l~DATATYPE l~INTLEN l~DECIMALS l~COMPTYPE r~DDTEXT
  INTO TABLE TFTMP
  FROM DD02B as tf
  INNER JOIN DDLDEPENDENCY AS ddl
    ON tf~STRUCOBJN EQ ddl~OBJECTNAME
    AND ddl~OBJECTTYPE = 'STOB'
	  AND ddl~STATE = 'A'
  INNER JOIN DD03ND AS l
	ON tf~STRUCOBJN EQ l~STRUCOBJN
	AND l~AS4LOCAL = 'A'
  LEFT OUTER JOIN DD03NT AS r
    ON l~STRUCOBJN EQ r~STRUCOBJN
    AND l~FIELDNAME EQ r~FIELDNAME
    AND r~DDLANGUAGE EQ P_LANGUAGE
    AND r~AS4LOCAL = 'A'	
  WHERE tf~AS4LOCAL = 'A'
  ORDER BY tf~STRUCOBJN.

  LOOP AT TFTMP ASSIGNING <WA_TF_FIELD>.
    CLEAN_DESCRIPTION = <WA_TF_FIELD>-DDTEXT.
    PERFORM Z_FORM_CLEANSTRING CHANGING CLEAN_DESCRIPTION.
    CLEAN_DESCRIPTION2 = <WA_TF_FIELD>-POSITION.
    PERFORM Z_FORM_CLEANSTRING CHANGING CLEAN_DESCRIPTION2.
    CONCATENATE
    <WA_TF_FIELD>-STRUCOBJN <WA_TF_FIELD>-FIELDNAME CLEAN_DESCRIPTION2
    <WA_TF_FIELD>-ROLLNAME <WA_TF_FIELD>-KEYFLAG
    <WA_TF_FIELD>-DATATYPE <WA_TF_FIELD>-INTLEN <WA_TF_FIELD>-DECIMALS
    <WA_TF_FIELD>-COMPTYPE CLEAN_DESCRIPTION
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE TFTMP.
ENDFORM.

FORM Z_QUERY_TF_IP
USING P_LANGUAGE TYPE L001TAB-DATA
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.
  DATA: CLEAN_DESCRIPTION TYPE STRING.
  DATA: CLEAN_DESCRIPTION2 TYPE STRING.

  TYPES: BEGIN OF TY_TF,
    STRUCOBJN TYPE DD02B-STRUCOBJN,
    PARAMETERNAME  TYPE DD10B-PARAMETERNAME ,
    POSNR TYPE DD10B-POSNR,
    ROLLNAME TYPE DD10B-ROLLNAME,
    DATATYPE TYPE DD10B-DATATYPE,
    LENG TYPE DD10B-LENG,
    DECIMALS TYPE DD10B-DECIMALS,
    COMPTYPE TYPE DD10B-COMPTYPE,
	DDTEXT TYPE DD03NT-DDTEXT,
  END OF TY_TF.
  FIELD-SYMBOLS: <WA_TF_IP> TYPE TY_TF.
  DATA: TFTMP TYPE TABLE OF TY_TF.

  SELECT
  tf~STRUCOBJN l~PARAMETERNAME  l~POSNR l~ROLLNAME 
  l~DATATYPE l~LENG l~DECIMALS l~COMPTYPE
  INTO TABLE TFTMP
  FROM DD02B as tf
  INNER JOIN DDLDEPENDENCY AS ddl
    ON tf~STRUCOBJN EQ ddl~OBJECTNAME
    AND ddl~OBJECTTYPE = 'STOB'
	  AND ddl~STATE = 'A'
  INNER JOIN DD10B AS l
	ON tf~STRUCOBJN EQ l~STRUCOBJN
	AND l~AS4LOCAL = 'A'
  WHERE tf~AS4LOCAL = 'A'
  ORDER BY tf~STRUCOBJN.

  LOOP AT TFTMP ASSIGNING <WA_TF_IP>.
    CLEAN_DESCRIPTION = <WA_TF_IP>-DDTEXT.
    PERFORM Z_FORM_CLEANSTRING CHANGING CLEAN_DESCRIPTION.
    CLEAN_DESCRIPTION2 = <WA_TF_IP>-POSNR.
    PERFORM Z_FORM_CLEANSTRING CHANGING CLEAN_DESCRIPTION2.
    CONCATENATE
    <WA_TF_IP>-STRUCOBJN <WA_TF_IP>-PARAMETERNAME CLEAN_DESCRIPTION2
    <WA_TF_IP>-ROLLNAME <WA_TF_IP>-DATATYPE <WA_TF_IP>-LENG <WA_TF_IP>-DECIMALS
    <WA_TF_IP>-COMPTYPE CLEAN_DESCRIPTION
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE TFTMP.
ENDFORM.

FORM Z_QUERY_PACKAGETFS
CHANGING EXPORT_TABLE TYPE EXPORT_TABLE_TYPE.

  DATA: EXPORT_LINE TYPE EXPORT_LINE_TYPE.
  TYPES: BEGIN OF TY_PACKAGETF,
    DEVCLASS TYPE TADIR-DEVCLASS,
    TF_NAME TYPE TADIR-OBJ_NAME,
  END OF TY_PACKAGETF.

  FIELD-SYMBOLS: <WA_PACKAGETF> TYPE TY_PACKAGETF.
  DATA: PACKAGETFSTMP TYPE TABLE OF TY_PACKAGETF.

  SELECT
  DISTINCT l~DEVCLASS l~OBJ_NAME
  FROM TADIR AS l
  INNER JOIN DD02B as tf
	ON tf~STRUCOBJN EQ l~OBJ_NAME
  INTO TABLE PACKAGETFSTMP
  BYPASSING BUFFER
  WHERE l~OBJECT = 'STOB'
  AND l~DEVCLASS <> ' '
  AND NOT l~DEVCLASS LIKE '  %'
  ORDER BY l~OBJ_NAME l~DEVCLASS .

  LOOP AT PACKAGETFSTMP ASSIGNING <WA_PACKAGETF>.
    CONCATENATE
    <WA_PACKAGETF>-DEVCLASS <WA_PACKAGETF>-TF_NAME
    INTO EXPORT_LINE
    SEPARATED BY CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
    APPEND EXPORT_LINE TO EXPORT_TABLE.
  ENDLOOP.
  FREE PACKAGETFSTMP.
ENDFORM.