Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FORM select_entries_to_duplicate
- USING
- it_tblmrg TYPE tt_tblmrgdup
- iv_fldexcl TYPE wdy_boolean " si oui le critére de
- " selection des champs rentre dans le SELECT
- CHANGING
- et_tbllin TYPE tt_tbllindup
- ct_protocole TYPE tt_protocole.
- DATA : ls_tblmrg TYPE ts_tblmrgdup.
- DATA : ls_tbllin TYPE ts_tbllindup.
- DATA : lv_clause TYPE string,
- lv_clkey TYPE string,
- lv_clfld TYPE string.
- DATA : ls_key TYPE ts_fldmrg,
- ls_fld TYPE ts_fldmrg,
- ls_clval TYPE ts_clval.
- DATA : lv_index TYPE i.
- DATA: lv_value TYPE string.
- DATA : lt_tblref TYPE REF TO data.
- FIELD-SYMBOLS : <fs_tbl> TYPE table.
- LOOP AT it_tblmrg INTO ls_tblmrg.
- CLEAR lv_clkey.
- CLEAR lv_clfld.
- CLEAR lv_clause.
- CLEAR ls_tbllin.
- " construire la clause where
- LOOP AT ls_tblmrg-t_key INTO ls_key.
- *
- * IF sy-tabix NE 1 AND lines( ls_key-t_clval ) NE 0.
- * CONCATENATE lv_clause 'AND' INTO lv_clause SEPARATED BY space.
- * ENDIF.
- IF lines( ls_key-t_clval ) NE 0 AND sy-tabix NE 1.
- lv_clkey = lv_clkey && ` AND `.
- ENDIF.
- IF lines( ls_key-t_clval ) NE 0.
- lv_clkey = lv_clkey && ` ( `.
- ENDIF.
- LOOP AT ls_key-t_clval INTO ls_clval.
- IF sy-tabix NE 1.
- lv_clkey = lv_clkey && ` OR `.
- ENDIF.
- lv_clkey = lv_clkey && ls_key-fieldname && ` = ` &&
- `'` && ls_clval-clause_value && `'`.
- " OR
- ENDLOOP.
- IF lines( ls_key-t_clval ) NE 0.
- lv_clkey = lv_clkey && ` ) `.
- ENDIF.
- " AND
- ENDLOOP.
- IF iv_fldexcl EQ abap_true.
- " construire la clause where
- LOOP AT ls_tblmrg-t_fld INTO ls_fld.
- IF lines( ls_fld-t_clval ) NE 0 AND sy-tabix NE 1.
- lv_clfld = lv_clfld && ` AND `.
- ENDIF.
- IF lines( ls_fld-t_clval ) NE 0.
- lv_clfld = lv_clfld && ` ( `.
- ENDIF.
- LOOP AT ls_fld-t_clval INTO ls_clval.
- IF sy-tabix NE 1.
- lv_clfld = lv_clfld && ` OR `.
- ENDIF.
- lv_clfld = lv_clfld && ls_fld-fieldname && ` = ` &&
- `'` && ls_clval-clause_value && `'`.
- " OR
- ENDLOOP.
- IF lines( ls_fld-t_clval ) NE 0.
- lv_clfld = lv_clfld && ` ) `.
- ENDIF.
- " AND
- ENDLOOP.
- ENDIF.
- IF lv_clkey IS NOT INITIAL AND lv_clfld IS NOT INITIAL.
- lv_clause = lv_clkey && ` AND ` && lv_clfld.
- ELSEIF lv_clkey IS INITIAL AND lv_clfld IS NOT INITIAL.
- lv_clause = lv_clfld.
- ELSEIF lv_clkey IS NOT INITIAL AND lv_clfld IS INITIAL.
- lv_clause = lv_clkey.
- ELSE.
- CONTINUE.
- ENDIF.
- CREATE DATA lt_tblref TYPE TABLE OF (ls_tblmrg-tabname).
- ASSIGN lt_tblref->* TO <fs_tbl>.
- SELECT * FROM (ls_tblmrg-tabname) INTO TABLE <fs_tbl>
- WHERE (lv_clause).
- IF lines( <fs_tbl> ) EQ 0.
- " TODO protocole
- CONTINUE.
- ENDIF.
- ls_tbllin-tabname = ls_tblmrg-tabname.
- ls_tbllin-entries = lt_tblref.
- lv_index = lines( et_tbllin ).
- ADD 1 TO lv_index.
- INSERT ls_tbllin INTO et_tbllin INDEX lv_index.
- ENDLOOP.
- ENDFORM.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement