Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Deleting the condition record

Former Member
0 Likes
981

Hi guys

condition record is their .if that record exist in two tables it has to be exit but it is their in heder table but not in item table then i have to delete the record i have done code but stil i am facing problem....please clarify

DATA: TABLE (4) TYPE C.

DATA: KNUM LIKE KONH-KNUMH

DATA: K_VEWE LIKE T681-KVEWE VALUE 'A'.

DATA: T681_STR LIKE T681.

DATA: LV_NUM TYPE I.

  • GET PARAMETERS

PARAMETERS: TABNO LIKE T681-KOTABNR.

PARAMETERS: TESTMODE DEFAULT 'X' AS CHECKBOX.

REFRESH INT_KNUMH.

Select single * from T681 into T681_STR

where kvewe = K_VEWE AND

KOTABNR = TABNO.

IF SY-SUBRC NE 0.

WRITE: / 'No entry in T681 for number ', TABNO.

WRITE: / 'Check whether corresponding condition table exists.'.

EXIT.

ENDIF.

TABLE = T681_STR-KOTAB.

SELECT KNUMH FROM (TABLE) INTO KNUM.

SELECT SINGLE * FROM KONH WHERE KNUMH = KNUM.

IF SY-SUBRC NE 0.

INT_KNUMH-KNUMH = KNUM.

COLLECT INT_KNUMH.

ENDIF.

ENDSELECT.

DESCRIBE TABLE INT_KNUMH LINES LV_NUM.

IF LV_NUM EQ 0.

WRITE: / 'No inconsistent entries found.'.

WRITE: / 'Each record in the condition table has a corresponding.'.

WRITE: / 'entry in the KONH table.'.

EXIT.

ENDIF.

LOOP AT INT_KNUMH.

IF TESTMODE IS INITIAL.

DELETE FROM (TABLE) WHERE

KNUMH = INT_KNUMH-KNUMH.

IF SY-SUBRC = 0.

WRITE: / 'KNUMH =', INT_KNUMH-KNUMH(10), ' deleted from table ' ,TABLE.

ELSE.

WRITE: / 'DELETE: SY-SUBRC is', SY-SUBRC , ' FOR KNUMH = ' .

WRITE: INT_KNUMH-KNUMH(10).

ENDIF.

ELSE.

WRITE: / 'TESTRUN: KNUMH =', INT_KNUMH-KNUMH(10).

ENDIF.

ENDLOOP.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
795

What is the problem you're facing (beyond having a condition pointer in transaction data for a condition record that no longer exists)? Abends? That's the likely result.

If you read these forums, you'll see over and over that direct updates to SAP DB tables is a route to disaster. Don't write direct database table updates; use transactions or bapis that update the tables via standard SAP programming!

Hi guys

condition record is their .if that record exist in two tables it has to be exit but it is their in heder table but not in item table then i have to delete the record i have done code but stil i am facing problem....please clarify

DATA: TABLE (4) TYPE C.

DATA: KNUM LIKE KONH-KNUMH

DATA: K_VEWE LIKE T681-KVEWE VALUE 'A'.

DATA: T681_STR LIKE T681.

DATA: LV_NUM TYPE I.

  • GET PARAMETERS

PARAMETERS: TABNO LIKE T681-KOTABNR.

PARAMETERS: TESTMODE DEFAULT 'X' AS CHECKBOX.

REFRESH INT_KNUMH.

Select single * from T681 into T681_STR

where kvewe = K_VEWE AND

KOTABNR = TABNO.

IF SY-SUBRC NE 0.

WRITE: / 'No entry in T681 for number ', TABNO.

WRITE: / 'Check whether corresponding condition table exists.'.

EXIT.

ENDIF.

TABLE = T681_STR-KOTAB.

SELECT KNUMH FROM (TABLE) INTO KNUM.

SELECT SINGLE * FROM KONH WHERE KNUMH = KNUM.

IF SY-SUBRC NE 0.

INT_KNUMH-KNUMH = KNUM.

COLLECT INT_KNUMH.

ENDIF.

ENDSELECT.

DESCRIBE TABLE INT_KNUMH LINES LV_NUM.

IF LV_NUM EQ 0.

WRITE: / 'No inconsistent entries found.'.

WRITE: / 'Each record in the condition table has a corresponding.'.

WRITE: / 'entry in the KONH table.'.

EXIT.

ENDIF.

LOOP AT INT_KNUMH.

IF TESTMODE IS INITIAL.

DELETE FROM (TABLE) WHERE

KNUMH = INT_KNUMH-KNUMH.

IF SY-SUBRC = 0.

WRITE: / 'KNUMH =', INT_KNUMH-KNUMH(10), ' deleted from table ' ,TABLE.

ELSE.

WRITE: / 'DELETE: SY-SUBRC is', SY-SUBRC , ' FOR KNUMH = ' .

WRITE: INT_KNUMH-KNUMH(10).

ENDIF.

ELSE.

WRITE: / 'TESTRUN: KNUMH =', INT_KNUMH-KNUMH(10).

ENDIF.

ENDLOOP.

3 REPLIES 3
Read only

Former Member
0 Likes
796

What is the problem you're facing (beyond having a condition pointer in transaction data for a condition record that no longer exists)? Abends? That's the likely result.

If you read these forums, you'll see over and over that direct updates to SAP DB tables is a route to disaster. Don't write direct database table updates; use transactions or bapis that update the tables via standard SAP programming!

Read only

0 Likes
795

i am not able to find the bapi ....you have any idea about this ..any function modules

Read only

0 Likes
795

Hi,

You can do a WHERE-USED-LIST on the Table T681_STR to get all the associated Function Modules. From there you need to look those which Update Function Modules which will perform the update of the Database Tables.

Hope this helps.

Thanks,

Samantak.