When we develop abap programs. We need to create abap data dictionary.
But sometimes, the data will be lost after we add/change/remove some fields in database table in SE14.
Situation: The data count in table is 0, and the active status is inactive.
Solution:Create a Z test program tool and copy paste below ABAP Source Code.
============
PARAMETERS P_TAB TYPE STRING DEFAULT ‘ZCW_CBD’.
START-OF-SELECTION.
DATA WA_DATA TYPE STRING.
DATA LV_TAB TYPE STRING.
CONCATENATE ‘QCM%’ P_TAB ” ‘%’
INTO LV_TAB.
DATA GT_REP TYPE STANDARD TABLE OF STRING WITH HEADER LINE.
PERFORM FRM_SET_REP.
EXEC SQL PERFORMING FRM_APPEND.
SELECT * INTO :WA_DATA
FROM user_tab_comments
WHERE table_name LIKE :LV_TAB
ENDEXEC.
*&———————————————————————*
*& Form FRM_APPEND
*&———————————————————————*
* 内表
*———————————————————————-*
FORM FRM_APPEND .
DATA LV_CNT TYPE I.
DATA LV_CHAR TYPE C LENGTH 30.
LV_CHAR = WA_DATA.
CLEAR LV_CNT.
PERFORM DEMO_LOOKUP USING LV_CHAR CHANGING LV_CNT.
WRITE:/ P_TAB, 40 WA_DATA,80 LV_CNT.
ULINE.
IF NOT LV_CNT IS INITIAL.
DATA LT_REP TYPE STANDARD TABLE OF STRING WITH HEADER LINE.
LT_REP[] = GT_REP[].
LOOP AT LT_REP .
REPLACE ALL OCCURRENCES OF ‘QCM8ZCW_TABLE’ IN LT_REP WITH WA_DATA.
IF SY-SUBRC <> 0.
REPLACE ALL OCCURRENCES OF ‘ZCW_TABLE’ IN LT_REP WITH P_TAB.
ENDIF.
WRITE:/ LT_REP.
ENDLOOP.
ULINE.
ENDIF.
ENDFORM. ” FRM_APPEND
FORM DEMO_LOOKUP USING UV_TAB CHANGING LV_CNT.
DATA:
L_ERROR_MSG TYPE STRING,
LS_T001 TYPE STRING.
PERFORM DYNAMIC_LOOKUP
USING UV_TAB
CHANGING
LS_T001
L_ERROR_MSG
LV_CNT.
ENDFORM. “demo_lookup,from www.hot583.com.
FORM DYNAMIC_LOOKUP
USING
I_TABNAME TYPE TABNAME
CHANGING
OS_DATA TYPE ANY
O_ERROR_MSG TYPE STRING
O_CNT TYPE I.
*
* Use ADBC to select data
DATA:
L_MANDT_REF TYPE REF TO DATA,
L_RESULT_REF TYPE REF TO DATA,
L_MANDT TYPE SYMANDT,
L_TABNAME TYPE TABNAME,
L_SQL_STATEMENT TYPE STRING,
LO_CX_ROOT TYPE REF TO CX_ROOT,
LO_CX_SQL TYPE REF TO CX_SQL_EXCEPTION,
LO_CONNECTION TYPE REF TO CL_SQL_CONNECTION,
LO_STATEMENT TYPE REF TO CL_SQL_STATEMENT,
LO_RESULT_SET TYPE REF TO CL_SQL_RESULT_SET.
CLEAR: OS_DATA, O_ERROR_MSG.
GET REFERENCE OF L_MANDT INTO L_MANDT_REF.
GET REFERENCE OF OS_DATA INTO L_RESULT_REF.
L_MANDT = SY-MANDT.
L_TABNAME = I_TABNAME.
TRY.
LO_CONNECTION = CL_SQL_CONNECTION=>GET_CONNECTION( ).
LO_STATEMENT = LO_CONNECTION->CREATE_STATEMENT( ).
* Set criteria for select:
LO_STATEMENT->SET_PARAM( L_MANDT_REF ).
CONCATENATE
‘select * from’ L_TABNAME
‘where mandt = ?’
INTO L_SQL_STATEMENT SEPARATED BY SPACE.
* Execute
CALL METHOD LO_STATEMENT->EXECUTE_QUERY
EXPORTING
STATEMENT = L_SQL_STATEMENT
HOLD_CURSOR = SPACE
RECEIVING
RESULT_SET = LO_RESULT_SET.
* Get the data from the resultset.
LO_RESULT_SET->SET_PARAM_STRUCT( L_RESULT_REF ).
DATA LV_STR TYPE STRING.
DATA LV_STR_RES TYPE STRING.
FIELD-SYMBOLS <LFS_1> TYPE ANY.
WHILE LO_RESULT_SET->NEXT( ) > 0.
CLEAR LV_STR_RES.
O_CNT = O_CNT + 1.
IF 1 = 2.”PRINT OUT THE DATA.
DO 300 TIMES.
CLEAR LV_STR.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE OS_DATA TO <LFS_1>.
IF SY-SUBRC <> 0.
EXIT.
ELSE.
LV_STR = <LFS_1>.
CONCATENATE LV_STR_RES ‘|’ LV_STR INTO LV_STR_RES.
ENDIF.
ENDDO.
WRITE: / LV_STR_RES.
ENDIF.
ENDWHILE.
* Tidy up:
LO_RESULT_SET->CLOSE( ).
LO_CONNECTION->CLOSE( ).
CATCH CX_SQL_EXCEPTION INTO LO_CX_SQL.
O_ERROR_MSG = LO_CX_SQL->GET_TEXT( ).
CATCH CX_ROOT INTO LO_CX_ROOT.
O_ERROR_MSG = LO_CX_ROOT->GET_TEXT( ).
ENDTRY.
ENDFORM. “dynamic_lookup from www.hot583.com.
FORM FRM_SET_REP .
GT_REP = `DATA WA_DB TYPE ZCW_TABLE.`.APPEND GT_REP.
GT_REP = `DATA WA_DATA TYPE QCM8ZCW_TABLE.`.APPEND GT_REP.
GT_REP = `DATA GT_DB TYPE STANDARD TABLE OF ZCW_TABLE.`.APPEND GT_REP.
GT_REP = `START-OF-SELECTION.`.APPEND GT_REP.
GT_REP = ` EXEC SQL PERFORMING FRM_APPEND.`.APPEND GT_REP.
GT_REP = ` SELECT * INTO :WA_DATA`.APPEND GT_REP.
GT_REP = ` FROM QCM8ZCW_TABLE`.APPEND GT_REP.
GT_REP = ` WHERE MANDT = :SY-MANDT`.APPEND GT_REP.
GT_REP = ` ENDEXEC.`.APPEND GT_REP.
GT_REP = “.APPEND GT_REP.
GT_REP = ` IF NOT GT_DB[] IS INITIAL.`.APPEND GT_REP.
GT_REP = ` INSERT ZCW_TABLE FROM TABLE GT_DB.`.APPEND GT_REP.
GT_REP = ` COMMIT WORK.`.APPEND GT_REP.
GT_REP = ` ENDIF.`.APPEND GT_REP.
GT_REP = “.APPEND GT_REP.
GT_REP = `FORM FRM_APPEND .`.APPEND GT_REP.
GT_REP = ` MOVE-CORRESPONDING WA_DATA TO WA_DB.`.APPEND GT_REP.
GT_REP = ` APPEND WA_DB TO GT_DB.`.APPEND GT_REP.
GT_REP = ` STATICS SV_I TYPE I.`.APPEND GT_REP.
GT_REP = ` SV_I = SV_I + 1.`.APPEND GT_REP.
GT_REP = ` IF SV_I >= 100000.`.APPEND GT_REP.
GT_REP = ` INSERT ZCW_TABLE FROM TABLE GT_DB.`.APPEND GT_REP.
GT_REP = ` CLEAR GT_DB[].`.APPEND GT_REP.
GT_REP = ` CLEAR SV_I.`.APPEND GT_REP.
GT_REP = ` ENDIF.`.APPEND GT_REP.
GT_REP = `ENDFORM. “FRM_APPEND`.APPEND GT_REP.
ENDFORM. ” FRM_SET_REP from www.hot583.com.
我的微信公众号【 hot583 】 或者在这个链接联系我
本文链接 :http://www.hot583.com/2023/01/10/how-to-find-lost-data-in-sap-tcode-se14-active
本文为作者原创,如果这篇文章对您有用,欢迎转载,
转载请务必注明来源《今日热点在看》http://www.hot583.com/
微信原文《全文完》