Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- " pour la selection
- TYPES : BEGIN OF ts_tblflddup,
- tabname TYPE tabname,
- domname TYPE domname,
- fieldname TYPE fieldname,
- oldvalue TYPE string,
- newvalue TYPE string,
- END OF ts_tblflddup,
- tt_tblflddup TYPE STANDARD TABLE OF ts_tblflddup.
- " pour le merging avant selection dans tables
- TYPES : BEGIN OF ts_clval,
- clause_value TYPE string,
- END OF ts_clval,
- tt_clval TYPE SORTED TABLE OF ts_clval WITH
- UNIQUE KEY clause_value.
- TYPES : BEGIN OF ts_fldmrg,
- fieldname TYPE fieldname,
- t_clval TYPE tt_clval,
- END OF ts_fldmrg,
- tt_fldmrg TYPE SORTED TABLE OF ts_fldmrg WITH UNIQUE KEY
- fieldname.
- TYPES : BEGIN OF ts_tblmrgdup,
- tabname TYPE tabname,
- t_key TYPE tt_fldmrg,
- t_fld TYPE tt_fldmrg,
- END OF ts_tblmrgdup,
- tt_tblmrgdup TYPE SORTED TABLE OF ts_tblmrgdup WITH
- UNIQUE KEY tabname.
- FORM merge_tblflddup
- USING
- it_tblkey TYPE tt_tblflddup
- it_tblfld TYPE tt_tblflddup
- CHANGING
- et_tblmrg TYPE tt_tblmrgdup
- ct_protocole TYPE tt_protocole.
- DATA : ls_tblkey TYPE ts_tblflddup,
- ls_tblfld TYPE ts_tblflddup.
- DATA : ls_tblmrg TYPE ts_tblmrgdup.
- DATA : ls_key TYPE ts_fldmrg,
- ls_fld TYPE ts_fldmrg.
- DATA : ls_clval TYPE ts_clval.
- DATA : lv_index TYPE i,
- lv_index2 TYPE i,
- lv_index3 TYPE i.
- LOOP AT it_tblkey INTO ls_tblkey.
- READ TABLE et_tblmrg WITH TABLE KEY tabname = ls_tblkey-tabname
- INTO ls_tblmrg.
- lv_index = sy-tabix.
- IF sy-subrc EQ 0. "l'entrée existe on ajoute le domaine
- " sauf si il est déjà présent
- " dans ce cas on ajoute la valeurs sauf si elle est déjà
- " présente
- READ TABLE ls_tblmrg-t_key WITH TABLE KEY
- fieldname = ls_tblkey-fieldname INTO ls_key.
- lv_index2 = sy-tabix.
- IF sy-subrc EQ 0. " l'entrée existe on regarde si la valeur existe
- READ TABLE ls_key-t_clval WITH TABLE KEY
- clause_value = ls_tblkey-oldvalue TRANSPORTING NO FIELDS.
- lv_index3 = sy-tabix.
- " notre selection se fera sur l'ancienne valeur !
- IF sy-subrc NE 0. " si pasd'entrée on insére
- CLEAR ls_clval.
- ls_clval-clause_value = ls_tblkey-oldvalue.
- INSERT ls_clval INTO ls_key-t_clval INDEX lv_index3.
- MODIFY ls_tblmrg-t_key FROM ls_key INDEX lv_index2.
- MODIFY et_tblmrg FROM ls_tblmrg INDEX lv_index.
- ENDIF.
- ELSE.
- CLEAR ls_key.
- CLEAR ls_clval.
- " on insére // aucun entrée val
- ls_key-fieldname = ls_tblkey-fieldname.
- ls_clval-clause_value = ls_tblkey-oldvalue.
- INSERT ls_clval INTO ls_key-t_clval INDEX 1.
- INSERT ls_key INTO ls_tblmrg-t_key INDEX lv_index2.
- MODIFY et_tblmrg FROM ls_tblmrg INDEX lv_index.
- ENDIF.
- ELSE.
- CLEAR ls_tblmrg.
- CLEAR ls_key.
- CLEAR ls_clval.
- ls_clval-clause_value = ls_tblkey-oldvalue.
- ls_key-fieldname = ls_tblkey-fieldname.
- ls_tblmrg-tabname = ls_tblkey-tabname.
- INSERT ls_clval INTO ls_key-t_clval INDEX 1.
- INSERT ls_key INTO ls_tblmrg-t_key INDEX 1.
- INSERT ls_tblmrg INTO et_tblmrg INDEX lv_index.
- ENDIF.
- ENDLOOP.
- * IDEM pour les FLD
- LOOP AT it_tblfld INTO ls_tblfld.
- READ TABLE et_tblmrg WITH TABLE KEY tabname = ls_tblfld-tabname
- INTO ls_tblmrg.
- lv_index = sy-tabix.
- " TODO L'entrée est obligé d'existé sinon protocole
- IF sy-subrc EQ 0.
- READ TABLE ls_tblmrg-t_fld WITH TABLE KEY
- fieldname = ls_tblfld-fieldname INTO ls_fld.
- lv_index2 = sy-tabix.
- IF sy-subrc EQ 0. " l'entrée existe on regarde si la valeur existe
- READ TABLE ls_fld-t_clval WITH TABLE KEY
- clause_value = ls_tblfld-oldvalue TRANSPORTING NO FIELDS.
- lv_index3 = sy-tabix.
- " notre selection se fera sur l'ancienne valeur !
- IF sy-subrc NE 0. " si pasd'entrée on insére
- CLEAR ls_clval.
- ls_clval-clause_value = ls_tblfld-oldvalue.
- INSERT ls_clval INTO ls_fld-t_clval INDEX lv_index3.
- MODIFY ls_tblmrg-t_fld FROM ls_fld INDEX lv_index2.
- MODIFY et_tblmrg FROM ls_tblmrg INDEX lv_index.
- ENDIF.
- ELSE.
- CLEAR ls_fld.
- CLEAR ls_clval.
- " on insére // aucun entrée val
- ls_fld-fieldname = ls_tblfld-fieldname.
- ls_clval-clause_value = ls_tblfld-oldvalue.
- INSERT ls_clval INTO ls_fld-t_clval INDEX 1.
- INSERT ls_fld INTO ls_tblmrg-t_fld INDEX lv_index2.
- MODIFY et_tblmrg FROM ls_tblmrg INDEX lv_index.
- ENDIF.
- ELSE.
- CLEAR ls_tblmrg.
- CLEAR ls_fld.
- CLEAR ls_clval.
- ls_clval-clause_value = ls_tblfld-oldvalue.
- ls_fld-fieldname = ls_tblfld-fieldname.
- ls_tblmrg-tabname = ls_tblfld-tabname.
- INSERT ls_clval INTO ls_fld-t_clval INDEX 1.
- INSERT ls_fld INTO ls_tblmrg-t_fld INDEX 1.
- INSERT ls_tblmrg INTO et_tblmrg INDEX lv_index.
- ENDIF.
- ENDLOOP.
- ***
- **********
- * TABLE * FLD * KEY *
- * * FIELDNAME VAL
- * X
- * Y
- * *
- *********
- ENDFORM.
Add Comment
Please, Sign In to add comment