2006 Feb 17 12:24 PM
hi,
i have this report to make , in which when the user enters the first four char of the field mara-normt, then i should select all the materials belonging to normt and add their quantity and return. i.e. if the user enters first four digits e.g 'fort' then i should calculate all the material's quantity (mard-labst)which start with 'fort' and give the total quantity. can anyone give me some code for this.
bye
2006 Feb 17 12:47 PM
Hi indira,
1. Simple.
2.
REPORT zam_temp169 .
DATA : labst LIKE mard-labst.
PARAMETERS : normt LIKE mara-normt.
DATA : var(18) TYPE c.
CONCATENATE '%' normt '%' INTO var.
SELECT SUM( labst ) AS labst FROM mara AS a
INNER JOIN mard AS b
ON amatnr = bmatnr
INTO labst
WHERE a~normt LIKE var.
BREAK-POINT.
WRITE 😕 labst.
regards,
amit m.
Hi indira,
1. Simple.
2.
REPORT zam_temp169 .
DATA : labst LIKE mard-labst.
PARAMETERS : normt LIKE mara-normt.
DATA : var(18) TYPE c.
CONCATENATE '%' normt '%' INTO var.
SELECT SUM( labst ) AS labst FROM mara AS a
INNER JOIN mard AS b
ON amatnr = bmatnr
INTO labst
WHERE a~normt LIKE var.
BREAK-POINT.
WRITE 😕 labst.
regards,
amit m.
2006 Feb 17 12:30 PM
Hi,
data itab type standard table of mara.
data v(20).
parameter p_normt type mara-normt.
start-of-selection.
concatenate p_normt '%' into v.
select * from mara into table itab where normt like v.
Then calculate the total quantiry.Otherwise try using sum(quantity) in select statement with group by.
Kindly reward points by clicking the star on the left of reply,if it helps.
2006 Feb 17 12:45 PM
Hi,
The user will enter only text(not wildcard say eg.. fort) in the parameter in selection screen.
We are only appending % in our code to fetch the records starting with fort%.
2006 Feb 17 12:36 PM
hi
I hope the user will give a wild card while he is inputting values in selection screen. i.e., he would be entering 'fort*' for selecting all values starting with 'fort' in that case use
REPLACE '*' WITH '%' INTO <b>p_normt</b>.
select mard-labst
from mara
into table itab
where normt like p_normt.
now after capturing all the values you can sum it up.
if the user is just giving first four charecters without a wild card then you add it explicitly.
Regards
Santosh
2006 Feb 17 12:41 PM
hi, thankyou for this, but user will not enter any wild card. so, can you please send me complete code sample.
2006 Feb 17 12:42 PM
HI Indira,
try this one..
DATA : ITAB LIKE TABLE OF MARD WITH HEADER LINE.
SELECT * UP TO 2 ROWS FROM MARD INTO TABLE ITAB
WHERE <field> CP 'FORT*'.
LOOP AT ITAB.
AT LAST.
SUM.
write : / <fields>
ENDLOOP.
if the user enters fort in
parameters : p_field ..
concatenate p_field '*' into p_field.
and then use..
SELECT * UP TO 2 ROWS FROM MARD INTO TABLE ITAB
WHERE <field> CP p_field.
regards
satesh
2006 Feb 17 12:47 PM
Hi indira,
1. Simple.
2.
REPORT zam_temp169 .
DATA : labst LIKE mard-labst.
PARAMETERS : normt LIKE mara-normt.
DATA : var(18) TYPE c.
CONCATENATE '%' normt '%' INTO var.
SELECT SUM( labst ) AS labst FROM mara AS a
INNER JOIN mard AS b
ON amatnr = bmatnr
INTO labst
WHERE a~normt LIKE var.
BREAK-POINT.
WRITE 😕 labst.
regards,
amit m.
2006 Feb 17 12:56 PM
HI indira
tables: mara,mard.
parameters: p_param like mara-normt.
data: total like mard-labst.
data: begin of itab occurs 0,
matnr like mara-matnr,
labst like mard-labst,
end of itab.
concatenate P_param '%' into p_param.
select maramatnr mardlabst into table itab from mara inner join mard on maramatnr = mardmatnr where mara~normt like p_param.
loop at itab.
total = total + itab-labst.
endloop.
write : total.
this code works fine
regards
kishore
2006 Feb 17 2:08 PM
i have tried the code below but im getting all the list of material which are not related to ngort also.
REPORT ztesting NO STANDARD PAGE HEADING .
TABLES: mara,mard.
PARAMETERS: p_param LIKE mara-normt.
DATA: BEGIN OF itab OCCURS 0,
matnr LIKE mara-matnr,
END OF itab.
CONCATENATE p_param '%' INTO p_param.
SELECT mara~matnr INTO TABLE itab FROM mara INNER JOIN mard
ON maramatnr = mardmatnr
WHERE mara~normt LIKE p_param.
LOOP AT itab.
write:/ itab-matnr.
ENDLOOP.
2006 Feb 17 2:20 PM
hi
Are you getting any Extra records(Materials)? and why is Inner Join used in the select?
More over I am getting only related materials when I Execute your code
Santosh
2006 Feb 17 2:31 PM
i'm not just trying to print the materials which if the user enters first four char of normt field. but its not executing. i dont know, its coming out of the select statement. the following is the code
REPORT ztesting NO STANDARD PAGE HEADING .
TABLES: mara.
PARAMETERS: p_param LIKE mara-normt.
DATA: BEGIN OF itab OCCURS 0,
matnr LIKE mara-matnr,
normt LIKE mara-normt,
END OF itab.
CONCATENATE p_param '%' INTO p_param.
SELECT matnr normt FROM mara INTO itab
WHERE normt = p_param.
APPEND itab.
CLEAR itab.
ENDSELECT.
WRITE:/ 'matnr',25 'normt'.
LOOP AT itab.
WRITE:/ itab-matnr,25 itab-normt.
ENDLOOP.
2006 Feb 17 2:33 PM
Change select to
SELECT matnr normt FROM mara INTO table itab
WHERE normt like p_param.
Also make sure you are passing value for P_PARAM.
What is the value you see for P_PARAM after concatenating with '%'?
2006 Feb 17 3:02 PM
Hi Indira,
Just change it this way..
TABLES: mara.
PARAMETERS: p_param LIKE mara-ernam.
DATA: BEGIN OF itab OCCURS 0,
matnr LIKE mara-matnr,
ernam LIKE mara-ernam,
END OF itab.
CONCATENATE p_param '%' INTO p_param.
SELECT matnr ernam
FROM mara
INTO TABLE itab
WHERE ernam like P_param.
WRITE:/ 'matnr',25 'normt'.
LOOP AT itab.
WRITE:/ itab-matnr,25 itab-ernam.
ENDLOOP.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |