Dinamik Sorgu Örneği
FREE_SELECTIONS_RANGE_2_WHERE Fonksiyonu ile dinamik sorgular oluşturulabilir.
KNA1-LFA1 veya BSID/BSAD/BSIK/BSAK gibi yapıları birbirine benzeyeb tablolar için ortak kodlar kullanılabilir.
SELECT
lifnr kunnr name1 name2 stcd1 stcd2 spras
INTO CORRESPONDING FIELDS OF TABLE lt_hesap
FROM (prm_kaynak-tbl_hesap)
WHERE (ls_where-where_tab).
SELECT
lifnr kunnr name1 name2 stcd1 stcd2 spras
INTO CORRESPONDING FIELDS OF TABLE lt_hesap
FROM (prm_kaynak-tbl_hesap)
WHERE (ls_where-where_tab).
Kaynak: http://sapjoy.co.kr/index.php?mid=ASOURCE&m=0&document_srl=89218
constants koart_musteri_d type koart value `D`.
constants koart_satici_k type koart value `K`.
DATA MASTER_KOART type koart.
TYPES: BEGIN OF TY_HESAP ,
HESAPNO TYPE ZFI_E_HESAPNO, "KUNNR / LIFNR
LIFNR TYPE LIFNR,
KUNNR TYPE KUNNR,
NAME1 TYPE NAME1_GP,
NAME2 TYPE NAME2_GP,
NAME3 TYPE NAME3_GP,
NAME4 TYPE NAME4_GP,
REGIO TYPE REGIO,
SORTL TYPE SORTL,
STRAS TYPE STRAS_GP,
ADRNR TYPE ADRNR,
STCD1 TYPE STCD1,
STCD2 TYPE STCD2,
SPRAS TYPE SPRAS,
END OF TY_HESAP.
types: TTY_HESAP type sorted table of TY_HESAP
with unique key HESAPNO LIFNR KUNNR
with NON-UNIQUE SORTED KEY KUNNR COMPONENTS KUNNR
with NON-UNIQUE SORTED KEY LIFNR COMPONENTS LIFNR.
data: gt_HESAP type TTY_HESAP.
data: gt_SATICI type TTY_HESAP.
data: gt_musterı type TTY_HESAP.
constants koart_satici_k type koart value `K`.
DATA MASTER_KOART type koart.
TYPES: BEGIN OF TY_HESAP ,
HESAPNO TYPE ZFI_E_HESAPNO, "KUNNR / LIFNR
LIFNR TYPE LIFNR,
KUNNR TYPE KUNNR,
NAME1 TYPE NAME1_GP,
NAME2 TYPE NAME2_GP,
NAME3 TYPE NAME3_GP,
NAME4 TYPE NAME4_GP,
REGIO TYPE REGIO,
SORTL TYPE SORTL,
STRAS TYPE STRAS_GP,
ADRNR TYPE ADRNR,
STCD1 TYPE STCD1,
STCD2 TYPE STCD2,
SPRAS TYPE SPRAS,
END OF TY_HESAP.
types: TTY_HESAP type sorted table of TY_HESAP
with unique key HESAPNO LIFNR KUNNR
with NON-UNIQUE SORTED KEY KUNNR COMPONENTS KUNNR
with NON-UNIQUE SORTED KEY LIFNR COMPONENTS LIFNR.
data: gt_HESAP type TTY_HESAP.
data: gt_SATICI type TTY_HESAP.
data: gt_musterı type TTY_HESAP.
types: begin of ty_source,
KOART type KOART,
TBL_HESAP TYPE TABNAME16, "kna1 lfa1
FLD_HESAP_KEY TYPE NAME_FELD, "kunnr lifnr
TBL_BSA TYPE TABNAME16,
TBL_BSI TYPE TABNAME16,
range_hesap type ZGLB_T_RANGE_LIFNR,
range_UMSKZ type ZGLB_T_RANGE_UMSKZ,
range_BUKRS type ZGLB_T_RANGE_BUKRS,
range_BUDAT type ZGLB_T_RANGE_DATUM,
range_AUGDT type ZGLB_T_RANGE_DATUM,
range_BSTAT type ZGLB_T_RANGE_BSTAT,
diger type xfeld,
SHKZG_BORC Type SHKZG,
SHKZG_ALACAK Type SHKZG,
althesap type TTY_HESAP,
END OF ty_source.
types: tty_source type sorted table of ty_source with unique key KOART .
data: gs_src_musteri type ty_source.
data: gs_src_satici type ty_source.
TYPES: BEGIN OF TY_kalem ,
HESAPNO TYPE ZFI_E_HESAPNO, "KUNNR / LIFNR
koart TYPE KOART,
KUNNR TYPE KUNNR,
LIFNR TYPE LIFNR,
BUKRS TYPE BUKRS,
UMSKS TYPE UMSKS,
UMSKZ TYPE UMSKZ,
AUGDT TYPE AUGDT,
AUGBL TYPE AUGBL,
ZUONR TYPE DZUONR,
GJAHR TYPE GJAHR,
BELNR TYPE BELNR_D,
BUZEI TYPE BUZEI,
BUDAT TYPE BUDAT,
BLDAT TYPE BLDAT,
CPUDT TYPE CPUDT,
WAERS TYPE WAERS,
XBLNR TYPE XBLNR1,
BLART TYPE BLART,
MONAT TYPE MONAT,
BSCHL TYPE BSCHL,
ZUMSK TYPE DZUMSK,
SHKZG TYPE SHKZG,
SGTXT TYPE SGTXT,
DMBTR TYPE DMBTR,
WRBTR TYPE WRBTR,
DMBE2 TYPE DMBE2,
DMBE3 TYPE DMBE3 ,
END OF TY_kalem.
types: TTY_kalem type STANDARD TABLE OF TY_kalem .
data: gt_kalemler type TTY_kalem.
PERFORM f_hesaplar CHANGING cht_hesaplar
cht_musteri
cht_satici .
FORM f_hesaplar CHANGING cht_hesaplar TYPE tty_hesap
cht_musteri TYPE tty_hesap
cht_satici TYPE tty_hesap .
DATA: ls_kaynak TYPE ty_source.
DATA: ls_diger TYPE ty_source.
DATA: lt_hesap TYPE tty_hesap.
DATA: ls_hesap TYPE ty_hesap.
CASE `X`.
WHEN p_knr. ls_kaynak = gs_src_musteri.
WHEN p_lfr. ls_kaynak = gs_src_satici.
ENDCASE.
master_koart = ls_kaynak-koart.
PERFORM f_hesap_bul USING ls_kaynak
CHANGING lt_hesap.
LOOP AT lt_hesap INTO ls_hesap.
INSERT ls_hesap INTO TABLE cht_hesaplar.
IF ls_hesap-lifnr IS NOT INITIAL.
INSERT ls_hesap INTO TABLE cht_satici.
ENDIF.
IF ls_hesap-kunnr IS NOT INITIAL.
INSERT ls_hesap INTO TABLE cht_musteri.
ENDIF.
ENDLOOP.
ENDFORM.
FORM f_hesap_bul USING prm_kaynak TYPE ty_source
CHANGING cht_hesap TYPE tty_hesap.
DATA : lt_trange TYPE rsds_trange,
ls_trange LIKE LINE OF lt_trange,
ls_field TYPE rsds_frange,
ls_condi TYPE rsdsselopt.
DATA : lt_where TYPE rsds_twhere,
ls_where LIKE LINE OF lt_where.
DATA: lt_hesap TYPE STANDARD TABLE OF ty_hesap.
PERFORM set_where TABLES lt_trange prm_kaynak-range_hesap USING prm_kaynak-tbl_hesap prm_kaynak-fld_hesap_key .
CALL FUNCTION `FREE_SELECTIONS_RANGE_2_WHERE`
EXPORTING
field_ranges = lt_trange
IMPORTING
where_clauses = lt_where.
READ TABLE lt_where INTO ls_where WITH KEY tablename = prm_kaynak-tbl_hesap.
SELECT
lifnr
kunnr
name1
name2
name3
name4
regio
sortl
stras
adrnr
stcd1
stcd2
spras
INTO CORRESPONDING FIELDS OF TABLE lt_hesap
FROM (prm_kaynak-tbl_hesap)
WHERE (ls_where-where_tab).
DATA: ls_hesap TYPE ty_hesap.
LOOP AT lt_hesap INTO ls_hesap.
CASE prm_kaynak-koart.
WHEN koart_musteri_d.
ls_hesap-hesapno = ls_hesap-kunnr.
IF prm_kaynak-diger IS INITIAL.
CLEAR ls_hesap-lifnr.
ENDIF.
WHEN koart_satici_k.
ls_hesap-hesapno = ls_hesap-lifnr.
IF prm_kaynak-diger IS INITIAL.
CLEAR ls_hesap-kunnr.
ENDIF.
ENDCASE.
INSERT ls_hesap INTO TABLE cht_hesap.
ENDLOOP.
ENDFORM.
FORM set_where TABLES t_tab TYPE rsds_trange
t_range
USING prm_tabname p_dbfield .
DATA : lt_trange TYPE rsds_trange,
ls_trange LIKE LINE OF lt_trange,
ls_field TYPE rsds_frange,
ls_condi TYPE rsdsselopt.
DATA : lt_where TYPE rsds_twhere,
ls_where LIKE LINE OF lt_where.
DATA : lv_constring TYPE string.
DATA : wa TYPE REF TO data,
ldyn_wa TYPE REF TO data,
ldyn_tab TYPE REF TO data.
DATA : lt_fcat TYPE lvc_t_fcat.
FIELD-SYMBOLS : TYPE any,
,
TYPE STANDARD TABLE.
CLEAR ls_trange.
ls_trange-tablename = prm_tabname.
ls_field-fieldname = p_dbfield.
IF NOT t_range[] IS INITIAL.
LOOP AT t_range ASSIGNING.
MOVE-CORRESPONDING TO ls_condi.
APPEND ls_condi TO ls_field-selopt_t.
ENDLOOP.
ENDIF.
APPEND ls_field TO ls_trange-frange_t.
APPEND ls_trange TO t_tab.
ENDFORM.
t_range
USING prm_tabname p_dbfield .
DATA : lt_trange TYPE rsds_trange,
ls_trange LIKE LINE OF lt_trange,
ls_field TYPE rsds_frange,
ls_condi TYPE rsdsselopt.
DATA : lt_where TYPE rsds_twhere,
ls_where LIKE LINE OF lt_where.
DATA : lv_constring TYPE string.
DATA : wa TYPE REF TO data,
ldyn_wa TYPE REF TO data,
ldyn_tab TYPE REF TO data.
DATA : lt_fcat TYPE lvc_t_fcat.
FIELD-SYMBOLS :
CLEAR ls_trange.
ls_trange-tablename = prm_tabname.
ls_field-fieldname = p_dbfield.
IF NOT t_range[] IS INITIAL.
LOOP AT t_range ASSIGNING
MOVE-CORRESPONDING
APPEND ls_condi TO ls_field-selopt_t.
ENDLOOP.
ENDIF.
APPEND ls_field TO ls_trange-frange_t.
APPEND ls_trange TO t_tab.
ENDFORM.
FORM f_get_bsx USING prm_source TYPE ty_source
prm_src_table TYPE tabname16
CHANGING cht_kalem TYPE tty_kalem .
DATA: ls_kalem TYPE ty_kalem .
DATA: lv_index_other TYPE string .
DATA: lv_key_other TYPE string .
DATA: lt_dyntable TYPE REF TO data .
FIELD-SYMBOLS:
FIELD-SYMBOLS:
DATA: ls_return TYPE bapireturn.
DATA: obj_structdesc TYPE REF TO cl_abap_structdescr,
components TYPE abap_component_tab,
obj_tabledescr TYPE REF TO cl_abap_tabledescr.
DATA : lt_trange TYPE rsds_trange,
ls_trange LIKE LINE OF lt_trange,
ls_field TYPE rsds_frange,
ls_condi TYPE rsdsselopt.
DATA : lt_where TYPE rsds_twhere,
ls_where LIKE LINE OF lt_where.
PERFORM set_where TABLES lt_trange prm_source-range_budat USING prm_src_table `BUDAT` .
IF prm_src_table+2(1) = `I`.
PERFORM set_where TABLES lt_trange prm_source-range_augdt USING prm_src_table `AUGDT` .
ENDIF.
PERFORM set_where TABLES lt_trange prm_source-range_bukrs USING prm_src_table `BUKRS` .
PERFORM set_where TABLES lt_trange prm_source-range_hesap USING prm_src_table prm_source-fld_hesap_key .
PERFORM set_where TABLES lt_trange prm_source-range_bstat USING prm_src_table `BSTAT` .
PERFORM set_where TABLES lt_trange prm_source-range_umskz USING prm_src_table `UMSKZ` ."Ortak
CALL FUNCTION `FREE_SELECTIONS_RANGE_2_WHERE`
EXPORTING
field_ranges = lt_trange
IMPORTING
where_clauses = lt_where.
READ TABLE lt_where INTO ls_where WITH KEY tablename = prm_src_table.
obj_structdesc ?= cl_abap_structdescr=>describe_by_name( prm_src_table ).
components[] = obj_structdesc->get_components( ).
obj_tabledescr ?= cl_abap_tabledescr=>create( p_line_type = obj_structdesc
p_table_kind = cl_abap_tabledescr=>tablekind_std ).
CREATE DATA lt_dyntable TYPE HANDLE obj_tabledescr.
ASSIGN lt_dyntable->* TO
SELECT * INTO TABLE
FROM (prm_src_table)
WHERE (ls_where-where_tab).
LOOP AT
MOVE-CORRESPONDING
ls_kalem-koart = prm_source-koart.
CASE prm_source-koart.
WHEN koart_satici_k.
ls_kalem-hesapno = ls_kalem-lifnr.
lv_index_other = `KUNNR`."ters
WHEN koart_musteri_d.
ls_kalem-hesapno = ls_kalem-kunnr.
lv_index_other = `LIFNR`."ters
ENDCASE.
IF master_koart NE prm_source-koart.
DATA: ls_hesap TYPE ty_hesap.
READ TABLE gt_hesap INTO ls_hesap
WITH KEY (lv_index_other)
COMPONENTS (lv_index_other) = ls_kalem-hesapno.
IF sy-subrc EQ 0.
ls_kalem-hesapno = ls_hesap-hesapno.
ENDIF.
ENDIF.
APPEND ls_kalem TO cht_kalem.
ENDLOOP.
ENDFORM.
ENDIF.
ENDIF.
APPEND ls_kalem TO cht_kalem.
ENDLOOP.
ENDFORM.
SPAN {
font-family: "Courier New";
font-size: 10pt;
color: #000000;
background: #FFFFFF;
}.L0S33 {
color: #4DA619;
}.L0S52 {
color: #0000FF;
}