Skip to Content
author's profile photo
Former Member

Dyanmic SQL Select Statement

Hello,

Trying to build a dynamic select statement from a listbox but this is the best I can get and I only end up with a error "Missing value" I was hoping someone might have an idea or maybe a better way to do this ???

DATA: listbox TYPE REF TO CL_HTMLB_LISTBOX.

DATA: if TYPE REF TO CL_HTMLB_INPUTFIELD.

if ?= CL_HTMLB_MANAGER=>GET_DATA( request = request

id = 'startdate'

name = 'inputfield' ).

myStart = if->value.

if ?= CL_HTMLB_MANAGER=>GET_DATA( request = request

id = 'enddate'

name = 'inputfield' ).

myEnd = if->value.

CONCATENATE 'MDATE between' myStart 'and' myEnd

INTO myWhereDate SEPARATED BY SPACE.

listbox ?= CL_HTMLB_MANAGER=>GET_DATA(

request = request

id = 'sid'

name = 'listBox' ).

CLEAR listselections.

LOOP AT listbox->selections INTO listselection.

CONCATENATE listselections '(' 'SID' '=' '"' listselection '"' 'AND' myWhereDate ')' 'OR'

INTO listselections SEPARATED BY SPACE.

ENDLOOP.

IF strlen( listselections ) > 0.

listselections = listselections+1.

ENDIF.

IF listbox->selection IS INITIAL.

listbox->selection = ' '.

ENDIF.

IF listselections IS INITIAL.

listselections = ' '.

ELSE.

CONCATENATE listselections '(' 'SID' '=' '"Z"' ')'

INTO myWhere SEPARATED BY SPACE.

ENDIF.

select * from ZDIALOG_STATS into

corresponding fields of table helladialog up to 250 rows

WHERE (myWhere)

order by sid.

It's not the nicest coding but being a Java Programmer and trying to adapt what I know works to BSP's is rather challenging 😔

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • author's profile photo
    Former Member
    Dec 16, 2003 at 02:55 PM

    I found the problem and now it works but if someone has a nicer way of coding this, especially if I don't have to include a DUMMY ending of SID='Z' that would be great.

    DATA: listbox TYPE REF TO CL_HTMLB_LISTBOX.

    DATA: if TYPE REF TO CL_HTMLB_INPUTFIELD.

    if ?= CL_HTMLB_MANAGER=>GET_DATA( request = request

    id = 'startdate'

    name = 'inputfield' ).

    myStart = if->value.

    if ?= CL_HTMLB_MANAGER=>GET_DATA( request = request

    id = 'enddate'

    name = 'inputfield' ).

    myEnd = if->value.

    CONCATENATE '(' 'MDATE between' myStart 'and' myEnd ')'

    INTO myWhereDate SEPARATED BY SPACE.

    listbox ?= CL_HTMLB_MANAGER=>GET_DATA(

    request = request

    id = 'sid'

    name = 'listBox' ).

    CLEAR listselections.

    LOOP AT listbox->selections INTO listselection.

    CONCATENATE '''' listselection '''' INTO listselection.

    CONCATENATE listselections '(' 'SID' '=' listselection ')' 'OR'

    INTO listselections SEPARATED BY SPACE.

    ENDLOOP.

    IF strlen( listselections ) > 0.

    listselections = listselections+1.

    ENDIF.

    IF listbox->selection IS INITIAL.

    listbox->selection = ' '.

    ENDIF.

    IF listselections IS INITIAL.

    listselections = ' '.

    ELSE.

    CONCATENATE listselections '(' 'SID' '=' '''Z''' ')' 'AND' myWhereDate

    INTO myWhere SEPARATED BY SPACE.

    ENDIF.

    select * from ZDIALOG_STATS into

    corresponding fields of table helladialog up to 250 rows

    WHERE (myWhere)

    order by sid.

    Add comment
    10|10000 characters needed characters exceeded