2008 Jun 11 5:23 PM
Hi,
I was wondering if there is a function module to do a check against foreign keys.
To make things simple:
form check_input
USING imv_tabname " Contains the name of my table
imv_fieldname "contains the field of the table
imv_value.
In this form I want to check if the value in imv_value is valid for my field in this table. I thought about reading manually reading the check table in table DD03L, but some fields are dependant of 2 tables, so how to solve that? Anyone with some experience regarding this issue?
2008 Jun 12 12:32 AM
Hello Bjorn,
I found something in my deepest archive. That's a customer program which displays keys and indexes for all sorts of tables (TRANSP, POOL, CLUSTER). Sorry! It's back to 1997 and therefore doesn't adhere the latest ABAP syntax (e.g. OCCURS shouldn't be used anymore). But it works! You have to use the 2 additional tables DD02L and DD17S (see the code). Try it:
REPORT (SY-REPID).
*----------------------------------------------------------------------*
* Report: Z_KEY_DISPLAY formerly ZSTLINES
* Author: Heinz H. Horner
* Date: 06/11/08
* Functionality: Displays the number of lines and primary and
* secondary keys for specified transparent-,
* pool- and cluster tables.
* Transaction: ??
**----------------------------------------------------------------------*
TABLES: DD02L, DD03L, DD17S.
PARAMETERS: IN_TABLE like dd02l-tabname.
DATA: BEGIN OF TAB_KEY OCCURS 5.
INCLUDE STRUCTURE DD03L.
DATA: END OF TAB_KEY.
DATA: BEGIN OF TAB_SEC OCCURS 5.
INCLUDE STRUCTURE DD17S.
DATA: END OF TAB_SEC.
* run time fields
DATA: TIME_B TYPE P,
TIME_A TYPE P,
TIME_DIFF LIKE SY-DBCNT.
* working fields
DATA: COUNT LIKE SY-DBCNT.
START-OF-SELECTION.
SELECT * FROM DD02L
WHERE TABNAME = IN_TABLE.
EXIT.
ENDSELECT.
IF SY-SUBRC <> 0.
WRITE: / IN_TABLE, 'is not defined in the System table'.
EXIT.
ELSE.
IF DD02L-TABCLASS <> 'TRANSP' AND
DD02L-TABCLASS <> 'POOL' AND
DD02L-TABCLASS <> 'CLUSTER'.
WRITE: / IN_TABLE, 'is not a transparent/pool/cluster table'.
EXIT.
ENDIF.
ENDIF.
* select key-fields
SELECT * FROM DD03L INTO TABLE TAB_KEY
WHERE TABNAME = IN_TABLE AND
KEYFLAG = 'X'.
SORT TAB_KEY BY POSITION.
* select secondary key-fields only for transparent tables
IF DD02L-TABCLASS = 'TRANSP'.
SELECT * FROM DD17S INTO TABLE TAB_SEC
WHERE SQLTAB = IN_TABLE.
ENDIF.
* Direct selection via variable tablename.
GET RUN TIME FIELD TIME_B. "time before counting
SELECT COUNT(*) FROM (IN_TABLE).
IF SY-SUBRC <> 0.
WRITE: / 'Counting Error.'.
WRITE: 'Please try it later again.'.
EXIT.
ENDIF.
GET RUN TIME FIELD TIME_A. "time after counting
TIME_DIFF = TIME_A - TIME_B. "time difference in microseconds
COUNT = SY-DBCNT.
WRITE: / 'The', DD02L-TABCLASS, 'table', IN_TABLE,
'contains', COUNT, 'records.'.
WRITE: / 'Select-Time:', TIME_DIFF UNDER COUNT, 'microseconds.', /.
* output of the key-fields.
WRITE: / 'Primary Keys:'.
LOOP AT TAB_KEY.
IF SY-TABIX <> 1.
WRITE: / ' '.
ENDIF.
WRITE: 17 TAB_KEY-FIELDNAME.
ENDLOOP.
IF DD02L-TABCLASS <> 'TRANSP'.
WRITE: /, 'No secondary keys for tableclass', DD02L-TABCLASS.
ELSE.
WRITE: /, 'Secondary Keys:', 28 'Index:'.
LOOP AT TAB_SEC.
IF SY-TABIX <> 1.
WRITE: / ' '.
ENDIF.
WRITE: 17 TAB_SEC-FIELDNAME, 35 TAB_SEC-INDEXNAME.
ENDLOOP.
ENDIF.
Have success,
Heinz
Hi,
I was wondering if there is a function module to do a check against foreign keys.
To make things simple:
form check_input
USING imv_tabname " Contains the name of my table
imv_fieldname "contains the field of the table
imv_value.
In this form I want to check if the value in imv_value is valid for my field in this table. I thought about reading manually reading the check table in table DD03L, but some fields are dependant of 2 tables, so how to solve that? Anyone with some experience regarding this issue?
2008 Jun 12 12:32 AM
Hello Bjorn,
I found something in my deepest archive. That's a customer program which displays keys and indexes for all sorts of tables (TRANSP, POOL, CLUSTER). Sorry! It's back to 1997 and therefore doesn't adhere the latest ABAP syntax (e.g. OCCURS shouldn't be used anymore). But it works! You have to use the 2 additional tables DD02L and DD17S (see the code). Try it:
REPORT (SY-REPID).
*----------------------------------------------------------------------*
* Report: Z_KEY_DISPLAY formerly ZSTLINES
* Author: Heinz H. Horner
* Date: 06/11/08
* Functionality: Displays the number of lines and primary and
* secondary keys for specified transparent-,
* pool- and cluster tables.
* Transaction: ??
**----------------------------------------------------------------------*
TABLES: DD02L, DD03L, DD17S.
PARAMETERS: IN_TABLE like dd02l-tabname.
DATA: BEGIN OF TAB_KEY OCCURS 5.
INCLUDE STRUCTURE DD03L.
DATA: END OF TAB_KEY.
DATA: BEGIN OF TAB_SEC OCCURS 5.
INCLUDE STRUCTURE DD17S.
DATA: END OF TAB_SEC.
* run time fields
DATA: TIME_B TYPE P,
TIME_A TYPE P,
TIME_DIFF LIKE SY-DBCNT.
* working fields
DATA: COUNT LIKE SY-DBCNT.
START-OF-SELECTION.
SELECT * FROM DD02L
WHERE TABNAME = IN_TABLE.
EXIT.
ENDSELECT.
IF SY-SUBRC <> 0.
WRITE: / IN_TABLE, 'is not defined in the System table'.
EXIT.
ELSE.
IF DD02L-TABCLASS <> 'TRANSP' AND
DD02L-TABCLASS <> 'POOL' AND
DD02L-TABCLASS <> 'CLUSTER'.
WRITE: / IN_TABLE, 'is not a transparent/pool/cluster table'.
EXIT.
ENDIF.
ENDIF.
* select key-fields
SELECT * FROM DD03L INTO TABLE TAB_KEY
WHERE TABNAME = IN_TABLE AND
KEYFLAG = 'X'.
SORT TAB_KEY BY POSITION.
* select secondary key-fields only for transparent tables
IF DD02L-TABCLASS = 'TRANSP'.
SELECT * FROM DD17S INTO TABLE TAB_SEC
WHERE SQLTAB = IN_TABLE.
ENDIF.
* Direct selection via variable tablename.
GET RUN TIME FIELD TIME_B. "time before counting
SELECT COUNT(*) FROM (IN_TABLE).
IF SY-SUBRC <> 0.
WRITE: / 'Counting Error.'.
WRITE: 'Please try it later again.'.
EXIT.
ENDIF.
GET RUN TIME FIELD TIME_A. "time after counting
TIME_DIFF = TIME_A - TIME_B. "time difference in microseconds
COUNT = SY-DBCNT.
WRITE: / 'The', DD02L-TABCLASS, 'table', IN_TABLE,
'contains', COUNT, 'records.'.
WRITE: / 'Select-Time:', TIME_DIFF UNDER COUNT, 'microseconds.', /.
* output of the key-fields.
WRITE: / 'Primary Keys:'.
LOOP AT TAB_KEY.
IF SY-TABIX <> 1.
WRITE: / ' '.
ENDIF.
WRITE: 17 TAB_KEY-FIELDNAME.
ENDLOOP.
IF DD02L-TABCLASS <> 'TRANSP'.
WRITE: /, 'No secondary keys for tableclass', DD02L-TABCLASS.
ELSE.
WRITE: /, 'Secondary Keys:', 28 'Index:'.
LOOP AT TAB_SEC.
IF SY-TABIX <> 1.
WRITE: / ' '.
ENDIF.
WRITE: 17 TAB_SEC-FIELDNAME, 35 TAB_SEC-INDEXNAME.
ENDLOOP.
ENDIF.
Have success,
Heinz
2008 Jun 12 9:35 AM
Hi Heinz,
thanks for your answer, but I found this function module, which does the same with a lot less effort for me
'SD_SCD_FOREIGN_KEY_CHECK'
2008 Jun 12 5:22 PM
Thank you Bjorn,
I will place your found FM in my memory and in my archive.
Regards, Heinz
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |