HI all,
I have written some logic in such a way i get the data from hdr table and later i check the details table based on some combination is there any data exist or not then again i go back to hdr table i get the relavent data.
SELECT * INTO CORRESPONDING FIELDS OF TABLE t_formdata
FROM zbrf_benf_list " Header table
WHERE fin_id = iv_fincr_id
AND loan_no = iv_loan_id
AND delete_flag = ' '
* AND benf_status NE 'INAC'.
AND benf_status IN lt_benf_status.
IF sy-subrc <> 0.
wa_return-type = 'E'.
wa_return-id = 'ZPPM'.
wa_return-number = '000'.
wa_return-message_v1 = 'Data not found.'.
PERFORM fill_return_tab TABLES t_return
USING wa_return .
ELSE.
APPEND LINES OF t_formdata TO lt_formdata.
ENDIF.
IF iv_brf_type = 'DA'.
* Get all DA_ID of primary loan
PERFORM get_ilap_related_loans TABLES lt_rel_loans
USING iv_brf_type
iv_fincr_id
iv_loan_id.
* try to find distinct DA_ID of the primary loan
* Here DA_ID is internal id
DELETE ADJACENT DUPLICATES FROM lt_rel_loans
COMPARING sa_internal_id.
IF lt_rel_loans IS NOT INITIAL.
SELECT * FROM zbrf_benf_list
APPENDING CORRESPONDING FIELDS OF TABLE t_formdata
FOR ALL ENTRIES IN lt_rel_loans
WHERE fin_id = iv_fincr_id
AND da_id = lt_rel_loans-sa_internal_id
AND delete_flag = ' '
* AND benf_status NE 'INAC'
AND benf_status IN lt_benf_status.
ENDIF.
SORT t_formdata DESCENDING BY brf_id .
ELSE. "This else will trigger because of type
CLEAR lt_ilap_benf_det.
REFRESH lt_ilap_benf_det.
* Get all DA_ID of primary loan
SELECT * FROM zbrf_benf_det
INTO TABLE lt_ilap_benf_det
FOR ALL ENTRIES IN lt_formdata
WHERE brf_id NE lt_formdata-brf_id Here my condition fails. Except the entries which i have chosen in hdr should "not be taken again
AND ver_id NE lt_formdata-ver_id
AND fin_id = iv_fincr_id
AND loan_no = iv_loan_id.
IF sy-subrc = 0.
SELECT * FROM zbrf_benf_list
APPENDING CORRESPONDING FIELDS OF TABLE t_formdata
FOR ALL ENTRIES IN lt_ilap_benf_det
WHERE brf_id = lt_ilap_benf_det-brf_id
AND ver_id = lt_ilap_benf_det-ver_id
AND fin_id = iv_fincr_id
AND loan_no = iv_loan_id
AND delete_flag = ' '
AND benf_status IN lt_benf_status.
* There should not be any duplicates
ENDIF.
ENDIF.