Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

how to use offset in select query

Former Member
0 Kudos

Suppose i have data like ssonje 00000001 as a one field in database table . i have to segregate this two data. how should I do this.the first part is of 12 characters and the last is of 10 character long.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

HI,

CHECK THIS Code:

select db-field0(12) db-field12(10) from table into corresponding fields of itab.

endselect.

reward points if it helps

Message was edited by:

abaper s

37 REPLIES 37

Former Member
0 Kudos

Hi,

You can use the Offset in the Select statment

Select FIELD10(10) into L_FIELD1 where FIELD2 = L_FIELD22(10).

Regards

Sudheer

0 Kudos

data:uname type UF05A-UNAMD.

data:temp type UF05A-TEMPD.

SELECT-OPTIONS:UNAMED FOR UNAME,

TEMPD FOR TEMP.

unamed is manadatory field for the user.

if user enters the unamed then the query should be fired as

SELECT SRTFD +0(10) FROM RFDT INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE SRTFD EQ unamed.

Please correct this query.

varma_narayana
Active Contributor
0 Kudos

Hi..

Try this logic.

<b>if u declare ITAB with those fields</b>

SELECT FIELD+(12) "First 12 Chars of the field

FIELD+12(10) "Next 10 Chars of the field

FORM <TABLE>

INTO TABLE ITAB WHERE <COND>.

<b>or for workarea use</b>

SELECT FIELD(12) FIELD12(10) FORM <TABLE>

INTO (WA_FIELD1, WA_FIELD2)

WHERE <COND>.

ENDSELECT.

<b>Reward if Helpful</b>

<b>Reward if Helpful</b>

0 Kudos

SELECT SRTFD+0(12) SRTFD +12(10) FROM RFDT INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE SRTFD EQ unamed.

it is showing that the column name srtfd+0(12)field error.

if possible send me one example.

Former Member
0 Kudos

HI,

CHECK THIS Code:

select db-field0(12) db-field12(10) from table into corresponding fields of itab.

endselect.

reward points if it helps

Message was edited by:

abaper s

0 Kudos

i want to fetch that data from database which has user id same as user id entered by the user. just go through the code below:

data:uname type UF05A-UNAMD.

data:temp type UF05A-TEMPD.

SELECT-OPTIONS:UNAMED FOR UNAME," uname is manadatory.

TEMPD FOR TEMP.

just tell me that how to select form database the whole field SRTFD which contains record like this: SSONJE 00000001. i want to compare only user name (ie. UNAMED) as mentioned below.

SELECT SRTFD FROM RFDT INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE SRTFD EQ unamed.

just give correct syntax for this select query, so that i get the SRTFD depending on user name(UNAMED) user entered.

0 Kudos

Hi,

Use IN instaed of EQ in where condition.as u r using select-options.

SELECT SRTFD FROM RFDT INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE SRTFD IN unamed.

Reward with points if helpful.

Revert back if any issues.

Regards,

Naveen

0 Kudos

i had used in. But the record was not coming into the internal table(ie. itab)

can you specify some other way.

0 Kudos

hi,

Check the structure of internal table.

Declare the staructure in this way.

select-options: unamed for RFDT-SRTFD.

data: begin of itab occurs 0.

include structure RFDT.

data : end of itab.

SELECT SRTFD FROM RFDT INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE SRTFD IN unamed.

Revert back if any issues.

Regards,

Naveen

0 Kudos

can you say us

SRTFD which contains record like this: SSONJE 00000001.

but what the user will enter in

UNAMED ?

and what is the output you want to get?

may be as per my previous thread you may have to try

concatenate '%' UNAMED into vname.

SELECT SRTFD FROM RFDT INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE SRTFD like vname.

pls let us know clearly about your user input and your desired output.

regards

shiba dutta

0 Kudos

Hi Navin,

i did that but still records were not coming.

please mention if any other way is there

thanks

0 Kudos

hi Darshana,

Can u just send the code what u have implemented.

Revert back .

Regards,

Naveen

0 Kudos

Hi Shiba,

User will enter the user name (ie. UNAMED) and the output should be all the document id, but this two values are there in one field ie. RFDT-SRTFD(ie. UNAMED TEMPD). UNAMED is username which is of 10 character long and TEMPD is Document id which is of 12 character long.

Now, i want to check the username ie. UNAMED in select query and in where part and display the output as document id.

Thanks

0 Kudos

Hi Navin,

i am sending my query to you. If possible please suggest some way to resolve this issue.

User will enter the user name (ie. UNAMED) and the output should be all the document id, but this two values are there in one field ie. RFDT-SRTFD(ie. UNAMED TEMPD). UNAMED is username which is of 10 character long and TEMPD is Document id which is of 12 character long.

Now, i want to check the username ie. UNAMED in select query and in where part and display the output as document id.

Thanks

0 Kudos

i had done this much of coding.

data:uname type UF05A-UNAMD.

data:temp type UF05A-TEMPD.

data: begin of itab occurs 0.

include structure RFDT.

data : end of itab.

SELECT-OPTIONS:UNAMED FOR UNAME,

TEMPD FOR TEMP.

SELECT SRTFD FROM RFDT INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE SRTFD IN unamed.

0 Kudos

Hi Darshana,

now i got the issue.

the enduser is enetring a part of the record and not the whole record.Am i right.

change ur select staement to this:

Instaed of IN use CP in ur where condition.

SELECT SRTFD FROM RFDT INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE SRTFD CP unamed.

and in the selection screen , user shud eneter "UNAMED*'.

end the field value with wild card character '*'.

Revert back if any iussues.

regards,

Naveen

0 Kudos

Hi Naveen,

You are right. User enter only part of record.

i had use CP instead of IN, but it is syntax error as- CP is not a valid comparison operator.

Please mention some other way.

Thanks

0 Kudos

Hi Darshana,

make sure that user enters the UNAME* , i.e value should be ended with '*' asterik .

Selection-screen.

UNAME = Naveen* to ________.

Make surethat ASTERIK is also eneterd in the selction screen.

Unless u give the ASTREIK , CP doesnt work in select query.

revert back if any issues,

Regards,

Naveen

Message was edited by:

Naveen Deva

0 Kudos

stil now i dont know why the like is failing...

as per my understanding user will give the input SSONJE in input box i.e. in UNAMED and you want to get output 00000001. If it is so then it must work..

SELECT-OPTIONS:UNAMED FOR UNAME," uname is manadatory.

TEMPD FOR TEMP.

translate unamed to uppercase.

data : vname(11).

data : vtempid(12)

concatenate UNAMED '%' into vname.

SELECT SRTFD FROM RFDT INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE SRTFD like vname.

loop at itab.

vtempid = itab-srtfd+10(12).

endloop.

one more thing in your itab SRTFD should be a field not unamed or tempd...

regards

shiba dutta

0 Kudos

Hi Naveen,

i had used CP in select query, but it is not allowing me to run the program, the error were occured while checking sytax and the error is- CP is not a valid operator

0 Kudos

Hi Shiba,

i had tried it again by using LIKE but the data is not coming in internal table(itab).

0 Kudos

Hi Darshana,

Yes, u r correct .it wont accept CP in select statement.

so u shud initialize OPTION = CP as below.

and ASTERIK shud be used explicitly.

Just Paste teh below CODE.

.

REPORT Y_TEST_1 .

tables : mara.

select-options: s_mat for mara-matnr.

data: begin of itab occurs 0,

matnr type matnr,

end of itab.

initialization .

s_mat-option = 'CP'.

append s_mat.

start-of-selection.

select matnr from mara into table itab where matnr in s_mat.

loop at itab.

;;;;;;

endloop.

Rewrad with poits.

Revert back if still any further issues.

Regards,

Naveen

0 Kudos

sorry i did not see the select-option rather i thouht unamed as parameter

so just change like this

SELECT-OPTIONS:UNAMED FOR UNAME," uname is manadatory.

TEMPD FOR TEMP.

translate unamed to uppercase.

data : vname(11).

data : vtempid(12)

concatenate <b>UNAMED-low</b> '%' into vname.

SELECT SRTFD FROM RFDT INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE SRTFD like vname.

loop at itab.

vtempid = itab-srtfd+10(12).

endloop.

but here you have to put only one uname in the low field...(i.e. no high value or range)

regards

shiba dutta

0 Kudos

Hi Naveen,

i had written the following code,

data:uname type UF05A-UNAMD.

data:temp type UF05A-TEMPD.

data: begin of itab occurs 0.

include structure RFDT.

data : end of itab.

SELECT-OPTIONS:UNAMED FOR UNAME,

TEMPD FOR TEMP.

UNAMED-option = 'CP'.

append UNAMED.

SELECT SRTFD FROM RFDT INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE SRTFD IN unamed.

i had put the debugger on select statement to see the data in the internal table, but still internal table is empty ie. SRTFD field in the internal table is empty.

Just check the code and send me the way to do this.

thanks

0 Kudos

hi Darshana:-)

under INITIALIZATION event ,

i.e

INITIALIZATION.

UNAMED-option = 'CP'.

append UNAMED.

start-of-selection.

select .............

Revert backif any further issues.

Regards,

Naveen

0 Kudos

Hi Naveen,

what is wrong in the coding , i am not getting. Please specify

0 Kudos

Hi Darshana,

Tables: RFDT.

data:uname type UF05A-UNAMD.

data:temp type UF05A-TEMPD.

data: begin of itab occurs 0.

include structure RFDT.

data : end of itab.

SELECT-OPTIONS:UNAMED FOR RFDT-UNAME,

TEMPD FOR TEMP.

Initialization.----


> u shud initialize.

UNAMED-option = 'CP'.

append UNAMED.

Start-of-selection----


> start of selection

SELECT SRTFD FROM RFDT INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE SRTFD IN unamed.

Revert back if any issues Darshana.

Cheers ,

Naveen .

0 Kudos

Thank you very much!!!

prolem solved .

0 Kudos

Hi Naveen,

I am again in trouble, Now the requirement were changed. I am sending you the code which i had implemented.

Now, the user enter username(ie UNAMED) and document id (ie. TEMPD) and the output should be doucment id, which has been search through database table RFDT , field SRTFD, this field contains both the username and the document id.

That means: suppose user enters UNAMED as SSONJE and TEMPD as 0000000030, then i want to fier the select query from RFDT on field SRTFD and get only the document id of that user which user enter on input field-UNAMED.

i had tried but result were not coming.

please go through the code.

data:uname type UF05A-UNAMD.

data:temp type UF05A-TEMPD.

TYPES: BEGIN OF TEITAB_RFDT,

SRTFD TYPE RFDT-SRTFD,

END OF TEITAB_RFDT.

DATA: ITAB_RFDT TYPE TABLE OF TEITAB_RFDT.

DATA: WA_RFDT TYPE TEITAB_RFDT.

DATA: STR(22) TYPE c.

SELECT-OPTIONS:UNAMED FOR uname,

TEMPD FOR TEMP.

UNAMED-option = 'CP'.

append UNAMED.

CONCATENATE UNAMED TEMPD INTO STR.

SELECT SRTFD FROM RFDT INTO CORRESPONDING FIELDS OF TABLE ITAB_RFDT WHERE SRTFD eq str.

LOOP AT ITAB_RFDT INTO WA_RFDT.

SPLIT WA_RFDT AT SPACE INTO STR1 STR2.

WRITE: / STR1,STR2.

ENDLOOP.

Please mentioned what is the way to do this.

Thanks

0 Kudos

Hi Naveen,

I got the answer of my previous question. Anyway Thank you.

Former Member
0 Kudos

hi,

chek his code:

data var type bseg-dmbtr.

data str(20) type c.

select dmbtr from bseg into var where ( augbl = '0100000156' and belnr = '0100000156' ) .

move var to str.

endselect.

condense str.

str = str+0(4).

write str.

reward points if it helps

when vr is printed i get the value :5,150,000.00.

& str has value :5150

Message was edited by:

abaper s

Neslinn
Participant
0 Kudos

Hi darshana,

I dont think you can make a query on the ofset basis.

U have to get those entries into some work variable and get the entires from the wrk variables on the basis of the offset u want..

Regards,

Neslin.

Former Member
0 Kudos

try this it may help

SELECT-OPTIONS:UNAMED FOR UNAME," uname is manadatory.

TEMPD FOR TEMP.

data : vname(40).

concatenate UNAMED '%' into vname.

SELECT SRTFD FROM RFDT INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE SRTFD like vname.

regards

shiba dutta

0 Kudos

no it is not working

records are not coming into the internal table ie. itab.

can you specify some other way.

0 Kudos

Hi,

ur select stament syntax was wrong.

Use IN instaed of EQ in where condition.as u r using select-options.

SELECT SRTFD FROM RFDT INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE SRTFD IN unamed.

Reward with points if helpful.

Revert back if any issues.

Regards,

Naveen

0 Kudos

yes i had used the IN. but still the record were not coming in the internal table(itab).

can you specify some other way to select the record from database depending on the username entered by the user.

Former Member
0 Kudos

data:uname type UF05A-UNAMD.

data:temp type UF05A-TEMPD.

SELECT-OPTIONS:UNAMED FOR UNAME,

TEMPD FOR TEMP.

unamed is manadatory field for the user.

if user enters the unamed then the query should be fired as

SELECT SRTFD +0(10) FROM RFDT INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE SRTFD EQ unamed.