2024 Jul 03 4:41 PM - edited 2024 Jul 03 4:44 PM
Dear Team,
i need a small help in modifing the code.
i have created a following incude program to fetch 'Create time stamp' ( zcolumn CRTTTM) in the Target HANDB when a record is replicated or inserted (IUUC_OPERAT_FLAG =I) . This is working fine.
However when the same record is updated (IUUC_OPERAT_FLAG = 'U) the zcolumn (CRTTTM) with create timestamp is wiped out.
we want to hold this value
CODE/include:
DATA: lv_name_create(30) TYPE c.
STATICS lv_Date TYPE sy-datum.
FIELD-SYMBOLS: <ls_record> TYPE any,
<ls_crt_record> TYPE any,
<lv_crttm> TYPE any,
<lv_operation> TYPE any.
CONCATENATE '<wa_r_' i_p1 '>' INTO lv_name_create.
ASSIGN (lv_name_create) TO <ls_record>.
ASSIGN COMPONENT 'IUUC_OPERAT_FLAG' OF STRUCTURE <ls_record> TO <lv_operation>.
CASE <lv_operation>.
WHEN 'I'.
*** set additional target fields
* set insert timestamp
ASSIGN COMPONENT 'CRTTTM' OF STRUCTURE <ls_record> TO <lv_crttm>.
IF sy-subrc = 0.
CONCATENATE sy-datum sy-uzeit INTO <lv_crttm>.
lv_date = <lv_crttm>.
ENDIF.
WHEN OTHERS.
ASSIGN COMPONENT 'CRTTTM' OF STRUCTURE <ls_record> TO <lv_crttm>.
IF sy-subrc = 0.
<lv_crttm> = lv_date.
ENDIF.
ENDCASE.
Request clarification before answering.
Hi
The original CRTTTM (create timestamp) when the operation changes from insert ('I') to update ('U'), it seems you need to ensure that the CRTTTM value set during insert ('I') is preserved and not overwritten during update ('U'). Please check this once.
DATA: lv_name_create(30) TYPE c.
STATICS lv_original_crttm TYPE any.
FIELD-SYMBOLS: <ls_record> TYPE any,
<lv_crttm> TYPE any,
<lv_operation> TYPE any.
CONCATENATE '<wa_r_' i_p1 '>' INTO lv_name_create.
ASSIGN (lv_name_create) TO <ls_record>.
ASSIGN COMPONENT 'IUUC_OPERAT_FLAG' OF STRUCTURE <ls_record> TO <lv_operation>.
CASE <lv_operation>.
WHEN 'I'.
" Insert operation: set insert timestamp
ASSIGN COMPONENT 'CRTTTM' OF STRUCTURE <ls_record> TO <lv_crttm>.
IF sy-subrc = 0.
CONCATENATE sy-datum sy-uzeit INTO <lv_crttm>.
lv_original_crttm = <lv_crttm>. " Store original CRTTTM
ENDIF.
WHEN 'U'.
" Update operation: retain original create timestamp
" Check if CRTTTM exists in the original record and in static variable
ASSIGN COMPONENT 'CRTTTM' OF STRUCTURE <ls_record> TO <lv_crttm>.
IF sy-subrc = 0 AND lv_original_crttm IS NOT INITIAL.
<lv_crttm> = lv_original_crttm. " Restore original CRTTTM
ENDIF.
ENDCASE.
Ensure that CRTTTM field is correctly defined in your structure <ls_record> and is accessible before you attempt to assign or read its value.
ensure that the original create timestamp (CRTTTM) is correctly preserved during both insert and update operations.
you should be able to maintain the desired behavior where the create timestamp is retained even after an update operation ('U').
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
It seems like you're facing an issue where the 'Create time stamp' (`CRTTTM`) value gets wiped out when a record is updated (`IUUC_OPERAT_FLAG = 'U'`). You want to preserve the original create timestamp value in such cases. Here’s how you can modify your code to achieve that:
```abap
DATA: lv_name_create(30) TYPE c.
STATICS lv_Date TYPE sy-datum.
FIELD-SYMBOLS: <ls_record> TYPE any,
<lv_crttm> TYPE any,
<lv_operation> TYPE any.
CONCATENATE '<wa_r_' i_p1 '>' INTO lv_name_create.
ASSIGN (lv_name_create) TO <ls_record>.
ASSIGN COMPONENT 'IUUC_OPERAT_FLAG' OF STRUCTURE <ls_record> TO <lv_operation>.
CASE <lv_operation>.
WHEN 'I'.
" Insert operation
ASSIGN COMPONENT 'CRTTTM' OF STRUCTURE <ls_record> TO <lv_crttm>.
IF sy-subrc = 0.
CONCATENATE sy-datum sy-uzeit INTO <lv_crttm>.
lv_date = <lv_crttm>.
ENDIF.
WHEN 'U'.
" Update operation
" Preserve the existing CRTTTM value
ASSIGN COMPONENT 'CRTTTM' OF STRUCTURE <ls_record> TO <lv_crttm>.
IF sy-subrc = 0.
" Check if lv_date has been initialized (for the first insert operation)
IF lv_date IS INITIAL.
lv_date = <lv_crttm>.
ELSE.
<lv_crttm> = lv_date.
ENDIF.
ENDIF.
ENDCASE.
```
### Explanation:
1. **Initialization and Assignments**: You're assigning the field `<ls_record>` dynamically based on `<wa_r_i_p1>`. This allows you to work with the fields of the structure dynamically.
2. **Handling Insert (`I`) Operation**:
- When the operation flag `<lv_operation>` is 'I', you fetch the current system date and time (`sy-datum` and `sy-uzeit`) and concatenate them into `<lv_crttm>`. This sets the create timestamp when a new record is inserted.
3. **Handling Update (`U`) Operation**:
- When the operation flag `<lv_operation>` is 'U', you need to preserve the existing create timestamp (`CRTTTM`). This is achieved by assigning `<lv_crttm>` to `lv_date` only if it hasn't been initialized yet (i.e., during the first insert operation).
- For subsequent updates, `<lv_crttm>` is set to `lv_date`, ensuring the original create timestamp is retained.
4. **Field Symbols and Error Handling**: Ensure that you handle errors (`sy-subrc`) appropriately after each `ASSIGN COMPONENT` statement to avoid runtime issues.
By implementing these changes, the create timestamp (`CRTTTM`) should now be preserved when records are updated (`U` operation), while still being set correctly during insertions (`I` operation). This approach leverages dynamic field assignments and conditional logic to achieve the desired behavior.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 8 | |
| 6 | |
| 6 | |
| 3 | |
| 3 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.