生活随笔
收集整理的這篇文章主要介紹了
使用CL_RS_WHERE创建dynamic SQL statement
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Created by Jerry Wang, last modified on May 31, 2014
select from field:
inner join statement:
where語句:
search結果:
REPORT zrs_where.TYPES:BEGIN OF ty_product,product_id TYPE comm_product-product_id,product_type TYPE comm_product-product_type,upname TYPE comm_product-upname,object_family TYPE comm_product-object_family,logsys TYPE comm_product-logsys,short_text TYPE comm_prshtext-short_text,END OF ty_product.DATA :gt_prod TYPE STANDARD TABLE OF ty_product,ls_prod TYPE ty_product.DATA: ob_select TYPE REF TO cl_rs_where.DATA: ob_from TYPE REF TO cl_rs_where.DATA: ob_where TYPE REF TO cl_rs_where,gv_source TYPE abapsource.START-OF-SELECTION.PERFORM build_select.PERFORM build_from.PERFORM build_where.TRY.SELECT (ob_select->n_t_where)FROM (ob_from->n_t_where)INTO CORRESPONDING FIELDS OF TABLE gt_prodWHERE (ob_where->n_t_where).CATCH cx_root INTO DATA(cx_root).WRITE: / cx_root->get_text( ).RETURN.ENDTRY.BREAK-POINT.DEFINE add_select_field.CLEAR gv_source.CALL METHOD cl_rs_where=>build_tabname_fieldnameEXPORTINGi_tabname = &1i_fieldname = &2i_sign = '~'IMPORTINGe_combined = gv_source.ob_select->add_line( i_line = gv_source ).END-OF-DEFINITION.FORM build_select .CREATE OBJECT ob_select.add_select_field 'COMM_PRODUCT' 'PRODUCT_ID'.add_select_field 'COMM_PRODUCT' 'PRODUCT_TYPE'.add_select_field 'COMM_PRODUCT' 'UPNAME'.add_select_field 'COMM_PRODUCT' 'OBJECT_FAMILY'.add_select_field 'COMM_PRODUCT' 'LOGSYS'.add_select_field 'COMM_PRSHTEXT' 'SHORT_TEXT'.ENDFORM.FORM build_from .CREATE OBJECT ob_from.ob_from->add_opening_bracket( ).gv_source = 'COMM_PRODUCT AS COMM_PRODUCT INNER JOIN COMM_PRSHTEXT AS COMM_PRSHTEXT'.ob_from->add_line( i_line = gv_source ).gv_source = 'ON COMM_PRODUCT~PRODUCT_GUID = COMM_PRSHTEXT~PRODUCT_GUID'.ob_from->add_line( i_line = gv_source ).ob_from->add_closing_bracket( ).ENDFORM.FORM build_where .DATA :lv_field TYPE REF TO data,lv_field_low TYPE REF TO data,lv_field_high TYPE REF TO data.CREATE OBJECT ob_where.DATA: lv_id TYPE comm_product-product_id VALUE 'ARNO_TEST004'.CALL METHOD ob_where->add_fieldEXPORTINGi_fieldnm = 'PRODUCT_ID'i_operator = '='i_intlen = strlen( lv_id )i_datatp = 'CHAR'IMPORTINGe_r_field = lv_field.CALL FUNCTION 'CONVERSION_EXIT_PRID1_INPUT'EXPORTINGinput = lv_idIMPORTINGoutput = lv_id.CALL METHOD ob_where->set_value_for_fieldEXPORTINGi_fieldnm = 'PRODUCT_ID'i_value = lv_id.CALL METHOD ob_where->add_and.CALL METHOD ob_where->add_fieldEXPORTINGi_fieldnm = 'PRODUCT_TYPE'i_operator = '='i_intlen = 2i_datatp = 'CHAR'IMPORTINGe_r_field = lv_field.CALL METHOD ob_where->set_value_for_fieldEXPORTINGi_fieldnm = 'PRODUCT_TYPE'i_value = '01'.ENDFORM.
總結
以上是生活随笔為你收集整理的使用CL_RS_WHERE创建dynamic SQL statement的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。