Application Development and Automation 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: 
Read only

Variable

Former Member
0 Likes
1,012

Hi Expert,

I have a problem when I try to use a variable with LIKE command at SQL command.

The ABAP source code as below.

FORM get_sales_forecast.

DATA: yyyymm(6) TYPE C.

yyyymm = sy-datum+0(6).

SELECT pbimwerks pbimmatnr pbimbedae pbimversb pbim~pbdnr

pbimbdzei pbedpdatu pbedplnmg pbedmeins

INTO TABLE t_pbim_ed

FROM pbim INNER JOIN pbed ON

pbimbdzei = pbedbdzei

FOR ALL ENTRIES IN t_marc

WHERE pbim~matnr = t_marc-matnr

AND pbim~werks = p_werks

AND pbim~loevr = SPACE

AND pbed~loevr = SPACE

AND pbed~pdatu LIKE 'yyyymm%'.

ENDFORM.

When I use a Variable

pbed~pdatu LIKE 'yyyymm%'. give me zero record

Try to use a Literal

pbed~pdatu LIKE '200704%'. give me some records

Could anyone please tell me how to use a variable in LIKE command?

Regards

Tiwa Noitawee.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
957

TRY LIKE THIS..

DATA : MONYR(6) TYPE C,

PAT(7).

MONYR = SY-DATUM+0(6).

CONCATENATE MONYR '%' INTO PAT.

SELECT pbimwerks pbimmatnr pbimbedae pbimversb pbim~pbdnr

pbimbdzei pbedpdatu pbedplnmg pbedmeins

INTO TABLE t_pbim_ed

FROM pbim INNER JOIN pbed ON

pbimbdzei = pbedbdzei

FOR ALL ENTRIES IN t_marc

WHERE pbim~matnr = t_marc-matnr

AND pbim~werks = p_werks

AND pbim~loevr = SPACE

AND pbed~loevr = SPACE

AND <b>pbed~pdatu LIKE PAT</b>.

REGARDS

SHIBA DUTTA

5 REPLIES 5
Read only

Former Member
0 Likes
958

TRY LIKE THIS..

DATA : MONYR(6) TYPE C,

PAT(7).

MONYR = SY-DATUM+0(6).

CONCATENATE MONYR '%' INTO PAT.

SELECT pbimwerks pbimmatnr pbimbedae pbimversb pbim~pbdnr

pbimbdzei pbedpdatu pbedplnmg pbedmeins

INTO TABLE t_pbim_ed

FROM pbim INNER JOIN pbed ON

pbimbdzei = pbedbdzei

FOR ALL ENTRIES IN t_marc

WHERE pbim~matnr = t_marc-matnr

AND pbim~werks = p_werks

AND pbim~loevr = SPACE

AND pbed~loevr = SPACE

AND <b>pbed~pdatu LIKE PAT</b>.

REGARDS

SHIBA DUTTA

Read only

Former Member
0 Likes
957

YYYYMM% it has no meaning ,

so u have

concatenate YYYYMM with % into X.

then call

no sytax checks please.

Regards

Prabhu

Read only

Former Member
0 Likes
957

You can do as below.

data: yyyymm(7) TYPE C.

concatenate sy-datum+0(6) '%' into yyyymm.

SELECT pbimwerks pbimmatnr pbimbedae pbimversb pbim~pbdnr

pbimbdzei pbedpdatu pbedplnmg pbedmeins

INTO TABLE t_pbim_ed

FROM pbim INNER JOIN pbed ON

pbimbdzei = pbedbdzei

FOR ALL ENTRIES IN t_marc

WHERE pbim~matnr = t_marc-matnr

AND pbim~werks = p_werks

AND pbim~loevr = SPACE

AND pbed~loevr = SPACE

AND pbed~pdatu LIKE yyyymm.

Read only

Former Member
0 Likes
957

Hi,

The statement LIKE 'XXXX%' will give you only the matching records thats been mentioned. i.e. for example if you give the condition LIKE 'QM%' it gives you all the records which starts with QM. In your case if you have given it as LIKE 'yyyymm%' and it will search to get the records which starts with yyyymm. SO you are not getting any output.

Hope its clear how to use the LIKE statement.

Regards,

Ram

Pls reward points if helpful.

Read only

Former Member
0 Likes
957

The problem has already resolved.

Thanks everyone.

Regards,

Tiwa Noitawee