Tips and Tricks for the ABAP® Programming Language
Y9030015: A table browser (for TRANSP’, ‘POOL’ and ‘CLUSTERS’)
To support the testing work it is quite useful to have a utility which quickly displays some lines from an external table in an prepared format. The display area consists of 255 Bytes, tables are read up to a line length of 8000 bytes. The table types ‘INTAB’, ‘VIEW’ and ‘APPEND’ remain unconsidered, in the case of ‘VIEW’ for example because considerable run times can be the result.
Parameters:
P_TABNAM = name of the desired external table
P_NUMBER = number of the table lines which have to be output
P_SKIP = number of the table lines which have to be skipped at the beginning of the table
ABAP™-Source-Code
You can cut and paste the source code directly into the ABAP™-Workbench.
REPORT Y9030015 LINE-SIZE 1023. "Release 3.1G, 4.5A ************************************************************************ * Copyright (c) 1998 by CT-Team, 33415 Verl, http://www.ct-software.com * * You can use or modify this report for your own work as long * as you don't try to sell or republish it. * In no event will the author be liable for indirect, special, * Incidental, or consequental damages (if any) arising out of * the use of this report. * ************************************************************************ *//////////////////////////////////////////////////////////////////////* MOVE: 'Read and display variable external tables (max. 1023 bytes) ' TO SY-TITLE. *////////////////////////////////////////////////////////////////////// PARAMETERS: P_TABNAM LIKE DD02L-TABNAME DEFAULT 'DD01L ', P_NUMBER(4) TYPE N DEFAULT '0125', P_SKIP(4) TYPE N DEFAULT '0'. *************** External tables ********************** TABLES DD02L. * *************** Variables ********************** DATA: ZX030L LIKE X030L. DATA: FUN_OK(1) TYPE N. DATA: OFF TYPE I. DATA: ZLEN TYPE I. DATA: WORK(8000) TYPE C. DATA: WORK1(8000) TYPE C. DATA: TABLEN TYPE I. DATA TAB_OK(1) TYPE N. * *************** internal tables ********************** DATA BEGIN OF ZDFIES OCCURS 1000. INCLUDE STRUCTURE DFIES. DATA END OF ZDFIES. *************** Field symbols ********************** FIELD-SYMBOLS: <FS1>, <FS2>. *************** Macro definition ********************** DEFINE HEAD1. * ZLEN = ZLEN + ZDFIES-LENG. IF OFF EQ 0. MOVE '|' TO WORK+OFF(1). ADD 1 TO OFF. ENDIF. IF ZLEN LE TABLEN. MOVE &1 TO WORK+OFF(&2). ADD &2 TO OFF. MOVE '|' TO WORK+OFF(1). ADD 1 TO OFF. ENDIF. * END-OF-DEFINITION. *//////////////////////////////////////////////////////////////////////* ************* Main Section ******************* *//////////////////////////////////////////////////////////////////////* * PERFORM CHECK-TABLE-CLASS. PERFORM READ-DIRECT-TABLE. * *//////////////////////////////////////////////////////////////////////* ************* Subroutines ******************* *//////////////////////////////////////////////////////////////////////* ************************************************************************ * Check tablename and tableclass ************************************************************************ FORM CHECK-TABLE-CLASS. * CLEAR TAB_OK. *....................................................................... SELECT * FROM DD02L WHERE TABNAME EQ P_TABNAM. TAB_OK = 1. IF DD02L-TABCLASS CS 'TRANSP' OR DD02L-TABCLASS CS 'POOL' OR DD02L-TABCLASS CS 'CLUSTER '. TAB_OK = 2. ENDIF. ENDSELECT. * IF TAB_OK EQ 0. WRITE: /1 'Sorry, table name not found : ', P_TABNAM. WRITE: /1 'Report must be canceled' COLOR 6. STOP. ENDIF. * IF TAB_OK EQ 1. WRITE: /1 'Tableclass not ''TRANSP'', ''POOL'' or ''CLUSTER'' :', DD02L-TABCLASS COLOR 6. *...................... INNTAB = no external table *...................... VIEW = perhaps long distance run *...................... APPEND = APPEND-structur *....................................................................... SKIP. WRITE: /1 'DD02L: ', DD02L+0(80). WRITE: /1 'Report must be canceled' COLOR 6. STOP. ENDIF. * ENDFORM. ************************************************************************ * read table direct ***********************************************************************. FORM READ-DIRECT-TABLE. * DATA: OFFS TYPE I. DATA: ANZ_NUMB TYPE I. *....................................................................... * IF P_NUMBER EQ 0. WRITE: /1 'No number of tablerows entered ''P_NUMBER = 0 '' '. EXIT. ENDIF. ******************** Headline ****************************************** * PERFORM LESEN-FIELDTAB USING P_TABNAM. * IF FUN_OK EQ 1. WRITE: /1 'Content of Table : ' COLOR 3 , P_TABNAM COLOR 6. WRITE: /1 'Maximum length : ', tablen COLOR 4. WRITE: /1 'Type of table : ', DD02L-TABCLASS COLOR 5. SKIP 3. * DO TABLEN TIMES. * POSITION SY-INDEX. * WRITE '-'. * ENDDO. * WRITE AT /(TABLEN) SY-ULINE. * LOOP AT ZDFIES. HEAD1 ZDFIES-FIELDNAME ZDFIES-LENG. ENDLOOP. WRITE: /1 sy-uline(off). WRITE: /1 WORK(off) COLOR 3. * SKIP. WRITE /1 SPACE. DO off TIMES. POSITION SY-INDEX. WRITE '='. ENDDO. * WRITE AT /(TABLEN) SY-ULINE. CLEAR: WORK, OFF. ******************** content ****************************************** SELECT * FROM (P_TABNAM) INTO WORK1. * IF SY-DBCNT GT P_SKIP. ADD 1 TO ANZ_NUMB. IF ANZ_NUMB GT P_NUMBER. EXIT. ENDIF. * * WHILE TABLEN GE OFF. LOOP AT ZDFIES. IF SY-TABIX EQ 1. MOVE '|' TO WORK+OFF(1). ADD 1 TO OFF. ENDIF. IF ZDFIES-INTTYPE = 'P'. ASSIGN WORK1+ZDFIES-OFFSET(ZDFIES-INTLEN) TO <FS1> TYPE 'P' DECIMALS ZDFIES-DECIMALS. ELSE. IF ZDFIES-INTTYPE = 'F'. "noch verbessern !!!!! ASSIGN WORK1+ZDFIES-OFFSET(ZDFIES-INTLEN) TO <FS1> CASTING TYPE C. * TYPE 'F' DECIMALS ZDFIES-DECIMALS. ELSE. ASSIGN WORK1+ZDFIES-OFFSET(ZDFIES-INTLEN) TO <FS1> TYPE ZDFIES-INTTYPE. ENDIF. ENDIF. * MOVE <FS1> TO WORK+OFF(zdfies-leng). ADD ZDFIES-LENG TO OFF. MOVE '|' TO WORK+OFF(1). ADD 1 TO OFF. IF TABLEN LT OFF. TABLEN = OFF. ENDIF. ENDLOOP. * ENDWHILE. WRITE: /1 Work. CLEAR: OFF, work, work1. ENDIF. ENDSELECT. ELSE. WRITE: /1 'NO DFIES found'. ENDIF. * ENDFORM. ************************************************************************ * read info about table ************************************************************************ FORM LESEN-FIELDTAB USING TNAME. * DATA: LIN1 TYPE I. CLEAR FUN_OK. *....................................................................... CALL FUNCTION 'GET_FIELDTAB' EXPORTING LANGU = SY-LANGU ONLY = SPACE TABNAME = TNAME WITHTEXT = 'X' IMPORTING HEADER = ZX030L TABLES FIELDTAB = ZDFIES EXCEPTIONS INTERNAL_ERROR = 01 NO_TEXTS_FOUND = 02 TABLE_HAS_NO_FIELDS = 03 TABLE_NOT_ACTIV = 04. * CASE SY-SUBRC. WHEN 0. MOVE 1 TO FUN_OK. DESCRIBE TABLE ZDFIES LINES LIN1. IF LIN1 NE 0. READ TABLE ZDFIES INDEX LIN1. IF SY-SUBRC EQ 0. TABLEN = ZDFIES-OFFSET + ZDFIES-INTLEN. ELSE. WRITE: /1 'ERROR: LESEN-FIELDTAB, LIN1 = unable'. BREAK-POINT. "what to do ENDIF. ELSE. WRITE: /1 'ERROR: LESEN-FIELDTAB, LIN1 = 0'. BREAK-POINT. "what to do ENDIF. * WHEN OTHERS. WRITE: /1 'Error ''GET_FIELDTAB'' :', SY-SUBRC. ENDCASE. * ENDFORM. ************************************************************************ ************************************************************************ ******************* END OF PROGRAM *************************************