IF P_KRED = 'X'. REFRESH ITAB. SELECT * FROM BSID JOIN BSIK ON BSIK~BELNR = BSID~BELNR INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE BSID~BELNR IN SO_BELNR. SELECT * FROM KNA1 JOIN LFA1 ON KNA1~LIFNR = LFA1~LIFNR INTO CORRESPONDING FIELDS OF TABLE IT_H_LFA1 WHERE KNA1~LIFNR IN SO_LIFNR. SELECT * FROM BSIK INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE BUKRS = PA_BUKRS AND WRBTR IN SO_WRBTR AND MANST IN SO_MANST AND BUDAT IN SO_BUDAT AND BELNR IN SO_BELNR AND LIFNR IN SO_LIFNR.

ELSEIF P_DEB = 'X'. SELECT * FROM BSIK JOIN BSID ON BSID~BELNR = BSIK~BELNR INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE BSIK~BELNR IN SO_BELNR. SELECT * FROM LFA1 JOIN KNA1 ON LFA1~KUNNR = KNA1~KUNNR INTO CORRESPONDING FIELDS OF TABLE IT_H_KNA1 WHERE LFA1~KUNNR IN SO_KUNNR. SELECT * FROM BSID INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE BUKRS = PA_BUKRS AND WRBTR IN SO_WRBTR AND MANST IN SO_MANST AND BUDAT IN SO_BUDAT AND BELNR IN SO_BELNR AND KUNNR IN SO_KUNNR.

REFRESH ITAB. SELECT * FROM BSID JOIN BSIK ON BSIK~BELNR = BSID~BELNR INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE BSID~BELNR IN SO_BELNR. SELECT * FROM KNA1 JOIN LFA1 ON KNA1~LIFNR = LFA1~LIFNR INTO CORRESPONDING FIELDS OF TABLE IT_H_LFA1 WHERE KNA1~LIFNR IN SO_LIFNR. SELECT * FROM BSIK INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE BUKRS = PA_BUKRS AND WRBTR IN SO_WRBTR AND MANST IN SO_MANST AND BUDAT IN SO_BUDAT AND BELNR = SO_BELNR AND LIFNR IN SO_LIFNR.

ELSEIF P_DEB = 'X' AND SO_BELNR IS INITIAL. REFRESH ITAB. SELECT * FROM BSIK JOIN BSID ON BSID~BELNR = BSIK~BELNR INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE BSIK~BELNR IN SO_BELNR. SELECT * FROM LFA1 JOIN KNA1 ON LFA1~KUNNR = KNA1~KUNNR INTO CORRESPONDING FIELDS OF TABLE IT_H_KNA1 WHERE LFA1~KUNNR IN SO_KUNNR. SELECT * FROM BSID INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE BUKRS = PA_BUKRS AND WRBTR IN SO_WRBTR AND MANST IN SO_MANST AND BUDAT IN SO_BUDAT AND BELNR = SO_BELNR AND KUNNR IN SO_KUNNR.

SELECT * FROM KNA1 JOIN LFA1 ON KNA1~LIFNR = LFA1~LIFNR INTO CORRESPONDING FIELDS OF TABLE IT_H_LFA1 WHERE KNA1~LIFNR IN SO_LIFNR. SELECT * FROM BSIK INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE BUKRS = PA_BUKRS AND WRBTR IN SO_WRBTR AND MANST IN SO_MANST AND BUDAT IN SO_BUDAT AND LIFNR IN SO_LIFNR.

ELSEIF P_DEB = 'X' AND SO_VBELN IS INITIAL. REFRESH ITAB.* SELECT ** FROM BSIK JOIN BSID ON BSID~BELNR = BSIK~BELNR* INTO CORRESPONDING FIELDS OF TABLE ITAB* WHERE BSIK~BELNR IN SO_BELNR. SELECT * FROM VBUK INTO CORRESPONDING FIELDS OF TABLE IT_H_VBUK WHERE VBUK~VBELN IN SO_VBELN. SELECT * FROM LFA1 JOIN KNA1 ON LFA1~KUNNR = KNA1~KUNNR INTO CORRESPONDING FIELDS OF TABLE IT_H_KNA1 WHERE LFA1~KUNNR IN SO_KUNNR. SELECT * FROM BSID INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE BUKRS = PA_BUKRS AND WRBTR IN SO_WRBTR AND MANST IN SO_MANST AND BUDAT IN SO_BUDAT AND KUNNR IN SO_KUNNR.

IF P_KRED = 'X' AND SO_BELNR IS INITIAL AND SO_VBELN IS INITIAL.ELSEIF P_DEB = 'X' AND SO_BELNR IS INITIAL AND SO_VBELN IS INITIAL.ELSEIF P_KRED = 'X' AND not SO_BELNR IS INITIAL AND SO_VBELN IS INITIAL.ELSEIF P_DEB = 'X' AND not SO_BELNR IS INITIAL AND SO_VBELN IS INITIAL.ELSEIF P_KRED = 'X' AND NOT SO_VBELN IS INITIAL AND SO_BELNR IS INITIAL.ELSEIF P_DEB = 'X' AND NOT SO_VBELN IS INITIAL AND SO_BELNR IS INITIAL.

SELECT * FROM BSIK JOIN BSID ON BSID~BELNR = BSIK~BELNR INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE BSIK~BELNR IN SO_BELNR. SELECT * FROM LFA1 JOIN KNA1 ON LFA1~KUNNR = KNA1~KUNNR INTO CORRESPONDING FIELDS OF TABLE IT_H_KNA1 WHERE LFA1~KUNNR IN SO_KUNNR. SELECT * FROM BSID INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE BUKRS = PA_BUKRS AND WRBTR IN SO_WRBTR AND MANST IN SO_MANST AND BUDAT IN SO_BUDAT AND BELNR IN SO_BELNR AND KUNNR IN SO_KUNNR.

"Alle Belege (FI und SD) der Kreditoren IF P_KRED = 'X' AND SO_BELNR IS INITIAL AND SO_VBELN IS INITIAL. REFRESH ITAB. SELECT * FROM VBRK INTO CORRESPONDING FIELDS OF TABLE IT_H_VBRK WHERE VBRK~VBELN IN SO_VBELN. SELECT * FROM LFA1 INNER JOIN BSIK ON LFA1~LIFNR = BSIK~LIFNR INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE LFA1~LIFNR IN SO_LIFNR AND BUKRS = PA_BUKRS AND WRBTR IN SO_WRBTR AND MANST IN SO_MANST AND BUDAT IN SO_BUDAT AND BELNR IN SO_BELNR.

"Bestimmte FI Belegnummer der Kreditoren ELSEIF P_KRED = 'X' AND NOT SO_BELNR IS INITIAL AND SO_VBELN IS INITIAL. REFRESH ITAB. SELECT * FROM LFA1 INNER JOIN BSIK ON LFA1~LIFNR = BSIK~LIFNR INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE LFA1~LIFNR IN SO_LIFNR AND BUKRS = PA_BUKRS AND WRBTR IN SO_WRBTR AND MANST IN SO_MANST AND BUDAT IN SO_BUDAT AND BELNR IN SO_BELNR.

"Nur bestimmte SD Belegnummer der Kreditoren ELSEIF P_KRED = 'X' AND NOT SO_VBELN IS INITIAL. REFRESH ITAB. SELECT * FROM LFA1 INNER JOIN BSIK ON LFA1~LIFNR = BSIK~LIFNR INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE LFA1~LIFNR IN SO_LIFNR AND BUKRS = PA_BUKRS AND WRBTR IN SO_WRBTR AND MANST IN SO_MANST AND BUDAT IN SO_BUDAT. SELECT * FROM VBRK INTO CORRESPONDING FIELDS OF TABLE IT_H_VBRK WHERE VBRK~VBELN in SO_VBELN.

"Nur bestimmte FI Belegnummer der Debitoren ELSEIF P_DEB = 'X' AND NOT SO_BELNR IS INITIAL AND SO_VBELN IS INITIAL. REFRESH ITAB. SELECT * FROM KNA1 INNER JOIN BSID ON KNA1~KUNNR = BSID~KUNNR INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE KNA1~KUNNR IN SO_KUNNR AND BUKRS = PA_BUKRS AND WRBTR IN SO_WRBTR AND MANST IN SO_MANST AND BUDAT IN SO_BUDAT AND BELNR IN SO_BELNR.

"Nur bestimmte SD Belegnummer der Debitoren ELSEIF P_DEB = 'X' AND NOT SO_VBELN IS INITIAL. REFRESH ITAB. SELECT * FROM VBRK INTO CORRESPONDING FIELDS OF TABLE IT_H_VBRK WHERE VBRK~VBELN IN SO_VBELN. SELECT * FROM KNA1 INNER JOIN BSID ON KNA1~KUNNR = BSID~KUNNR INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE KNA1~KUNNR IN SO_KUNNR AND BUKRS = PA_BUKRS AND WRBTR IN SO_WRBTR AND MANST IN SO_MANST AND BUDAT IN SO_BUDAT.

"NUR FI-BELEGNUMMER: IF SO_VBELN IS INITIAL. SELECT * FROM LFA1 INNER JOIN BSIK ON LFA1~LIFNR = BSIK~LIFNR INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE BUKRS = PA_BUKRS AND WRBTR IN SO_WRBTR AND MANST IN SO_MANST AND BUDAT IN SO_BUDAT AND BELNR IN SO_BELNR AND LFA1~LIFNR IN SO_LIFNR.

"NUR SD-BELEGNUMMER: IF SO_BELNR IS INITIAL. SELECT * FROM LFA1 INNER JOIN BSIK ON LFA1~LIFNR = BSIK~LIFNR INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE BUKRS = PA_BUKRS AND WRBTR IN SO_WRBTR AND MANST IN SO_MANST AND BUDAT IN SO_BUDAT AND LFA1~LIFNR IN SO_LIFNR. SELECT * FROM VBRK INTO CORRESPONDING FIELDS OF TABLE IT_H_VBRK WHERE VBRK~VBELN IN SO_VBELN.

"NUR FI-BELEGNUMMER: IF SO_VBELN IS INITIAL. SELECT * FROM KNA1 INNER JOIN BSID ON KNA1~KUNNR = BSID~KUNNR INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE BUKRS = PA_BUKRS AND WRBTR IN SO_WRBTR AND MANST IN SO_MANST AND BUDAT IN SO_BUDAT AND BELNR IN SO_BELNR AND KNA1~KUNNR IN SO_KUNNR. ENDIF.

"NUR SD-BELEGNUMMER: IF SO_BELNR IS INITIAL. SELECT * FROM KNA1 INNER JOIN BSID ON KNA1~KUNNR = BSID~KUNNR INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE BUKRS = PA_BUKRS AND WRBTR IN SO_WRBTR AND MANST IN SO_MANST AND BUDAT IN SO_BUDAT AND KNA1~KUNNR IN SO_KUNNR. SELECT * FROM VBRK INTO CORRESPONDING FIELDS OF TABLE IT_H_VBRK WHERE VBRK~VBELN IN SO_VBELN.