Basic Table Operation with ABAP
Case 1
Description
Update the ZLIANO numbers to 10 digits with given BP_IDs.
MANDT | BP_ID | IDENTIFICATIONCATEGORY | IDENTIFICATIONNUMBER | ... |
001 | 051MbpFO7kUTkQriN42EdG | ZLIANO | 87405302 | |
001 | 051MbpFO7kUTkQriN42EdG | ZLIANO | 0087405302 | |
001 | 051MbpFO7kUTkQuxUxPEdG | ZLIANO | 98406690 | |
001 | 051MbpFO7kUTkQuxUxPEdG | ZLIANO | 0098406690 |
1 TABLES: zbp_ident. 2 3 SELECT-OPTIONS: s_bp_id FOR zbp_ident-bp_id OBLIGATORY. 4 DATA: iv_num(10) TYPE n. 5 6 START-OF-SELECTION. 7 8 DATA: lt_ident LIKE zbp_ident OCCURS 0 WITH HEADER LINE, 9 lt_delete LIKE zbp_ident OCCURS 0 WITH HEADER LINE. 10 11 SELECT * INTO TABLE lt_delete 12 FROM zbp_ident 13 WHERE bp_id IN s_bp_id AND identificationcategory = 'ZLIANO'. 14 15 LOOP AT lt_delete. 16 lt_ident = lt_delete. 17 iv_num = lt_ident-identificationnumber. 18 lt_ident-identificationnumber = iv_num. 19 APPEND lt_ident. 20 ENDLOOP. 21 22 INSERT zbp_ident FROM TABLE lt_ident. 23 DELETE zbp_ident FROM TABLE lt_delete. 24 25 IF sy-subrc = 0. 26 ENDIF.
Tips
> Set a breakpoint at Line 25.
> Check sy-dbcnt.
> Check the internal tables.
Case 2
Description
Delete all the records from the table if they don't contain telephone info.
MANDT | BP_ID | PHONE_ID_LEGACY | TELEPHONE | EXTENSION | ... |
001 | 051MbpFO7jQdd0VT}nTwS0 | 1 | |||
001 | 051MbpFO7jQdd0VVFrOwS0 | 1 |
1 DELETE FROM zbp_comm_phone 2 WHERE bp_id IN ( SELECT bp_id FROM zbp_comm_phone_v WHERE telephone = '' AND extension = '' AND mc = 'UR300' ) 3 AND telephone = '' 4 AND extension = ''. 5 6 IF sy-subrc = 0. 7 ENDIF.
Case 3
Description
Clear the incorrect deathdate assignment.
MANDT | BP_ID | LASTNAME | BIRTHDATE | DEATHDATE | ... |
001 | 051MbpFO7jMLvWmXhY7vum | Allison Yu | 1985-08-09 | 1900-01-01 | |
001 | 051MbpFO7jMLvWmXhY7vum | Allison Yu | 1985-08-09 |
1 UPDATE zbp_central_per SET deathdate = '00000000' 2 WHERE bp_id IN ( SELECT bp_id FROM zbp_central_perv WHERE deathdate = '19000101' AND mc = 'UR300' ) 3 AND deathdate = '19000101'. 4 5 IF sy-subrc = 0. 6 ENDIF.
Case 4
Description
Field RL_SOURCE should be 3 digits rather than 2 digits.
MANDT | BO_ID | INPUT_ROW | RP_TYPCLASS | RP_TYP | RL_SOURCE | ... |
001 | 051MbpFO7kU2mrA6rsuK40 | 1 | 03 | 026 | 9 | |
001 | 051MbpFO7kU2mrA6rsuK40 | 1 | 03 | 026 | 009 | |
001 | 051MbqvR7jU9n}XRM6ES3W | 1 | 05 | 026 | 012 |
1 TABLES: zbp_rm_remark. 2 3 DATA: iv_num(3) TYPE n. 4 5 DATA: lt_remark LIKE zbp_rm_remark OCCURS 0 WITH HEADER LINE. 6 7 SELECT * INTO TABLE lt_remark FROM zbp_rm_remark 8 WHERE bo_id IN ( SELECT bo_id FROM zbp_rm_v WHERE mc = 'UR300' AND bo_id_merged = '' ) 9 AND rl_source BETWEEN '1' AND '99'. 10 11 LOOP AT lt_remark. 12 iv_num = lt_remark-rl_source. 13 lt_remark-rl_source = iv_num. 14 MODIFY lt_remark. 15 ENDLOOP. 16 17 UPDATE zbp_rm_remark FROM TABLE lt_remark. 18 19 IF sy-subrc = 0. 20 ENDIF.
Tips
> Difference between UPDATE and MODIFY.
UPDATE: only update based on the primary key.
MODIFY: update and insert.