‎2007 Feb 01 1:36 AM
Hi..the following table is a program on internal table...
Tables: MARA, MARD, MAKT.
Select-options: S_MATNR, S_WERKS, S_LGORT
FIELD NAME: MARA-MTART, MARA-MATNR, MARA-MBRSH, MAKT-MAKTX, MARD-WERKS, MARD-LGORT, MARD-LABST.
Internal Tables: Standard Internal table for MARD, MARA, MAKT, OUTTAB with header line.
Processing Flow:
1. Select Material data into Internal table based on selection from MARD
2. Select Material data into Internal table based on selection from MARA
3. Select Material data into Internal table based on selection from MAKT
4. Move-corresponding MARD to OUTTAB. Append OUTTAB.
5. Loop at OUTTAB. Read Table MARA & MAKT and modify OUTTAB.
6. Write OUTTAB to Screen.
I have doubt on Move-corresponding , modify....I have write the code as giving below,,,bt I am not getting proper ouput...data is not selecting from MATNR from selection screen.
tables: MARA, MARD, MAKT.
data: begin of i_mara occurs 0,
MTART type MARA-MTART,
MATNR type MARA-MATNR,
MBRSH type MARA-MBRSH,
end of i_mara.
data: begin of i_mard occurs 0,
WERKS type MARD-WERKS,
LGORT type MARD-LGORT,
LABST type MARD-LABST,
end of i_mard.
data: begin of i_makt occurs 0,
MAKTX type MAKT-MAKTX,
end of i_makt.
data: begin of wa,
col1 type MARD-WERKS,
col2 type MARD-LGORT,
col3 type MARD-LABST,
end of wa.
data: i_outtab like table of wa with header line.
select-options: S_MATNR for MARA-MATNR,
S_WERKS for MARD-WERKS,
S_LGORT for MARD-LGORT.
perform select_data_mard. (I am not including the data inside this )
perform select_data_mara.
perform select_data_makt.
perform fill_second-outtab. ( I am including )
FORM fill_second-outtab .
loop at i_outtab.
move-corresponding i_mard to i_outtab.
append i_outtab.
endloop.
ENDFORM. " fill_second-outtab
perform read_mara.
perform read_makt.
perform read_mard.
clear i_outtab.
wa-col1 = mara-MATNR.
wa-col2 = mard-WERKS.
wa-col3 = mard-LGORT.
modify i_outtab from wa.
loop at i_outtab into wa.
write: / wa-col1, wa-col2, wa-col3.
endloop.
Thanks in advance.
‎2007 Feb 01 1:47 AM
HI,
the code here is bit in proper way..
FORM fill_second-outtab .
loop at i_outtab.
<b>I believe here shud be loop at i_mard</b>
<b>move-corresponding i_mard to i_outtab.</b>
which record of i_mard u r moving?
append i_outtab.
endloop.
ENDFORM. " fill_second-outtab
perform read_mara.
perform read_makt.
perform read_mard.
clear i_outtab.
wa-col1 = mara-MATNR.
wa-col2 = mard-WERKS.
wa-col3 = mard-LGORT.
<b>modify i_outtab from wa
here u can write APPEND i_outtab from wa directly
Modify command shud insert in loop ... endloop.</b>
Can u post the code so we can have a look and help u..
Regards
SAB
‎2007 Feb 01 1:47 AM
HI,
the code here is bit in proper way..
FORM fill_second-outtab .
loop at i_outtab.
<b>I believe here shud be loop at i_mard</b>
<b>move-corresponding i_mard to i_outtab.</b>
which record of i_mard u r moving?
append i_outtab.
endloop.
ENDFORM. " fill_second-outtab
perform read_mara.
perform read_makt.
perform read_mard.
clear i_outtab.
wa-col1 = mara-MATNR.
wa-col2 = mard-WERKS.
wa-col3 = mard-LGORT.
<b>modify i_outtab from wa
here u can write APPEND i_outtab from wa directly
Modify command shud insert in loop ... endloop.</b>
Can u post the code so we can have a look and help u..
Regards
SAB
‎2007 Feb 01 3:35 AM
Thanks
ok I am posting my complete code
If my code is too complicated or wrong , then you can just go through the problem(which I have written at beginning) and give some hints.
Thanks
tables: MARA, MARD, MAKT.
*********************Data Declearation**************************
*This is the internal table for mara .*
data: begin of i_mara occurs 0,
MTART type MARA-MTART,
MATNR type MARA-MATNR,
MBRSH type MARA-MBRSH,
end of i_mara.
**This is the internal table MARD table.*
data: begin of i_mard occurs 0,
WERKS type MARD-WERKS,
LGORT type MARD-LGORT,
LABST type MARD-LABST,
end of i_mard.
**This is the internal table for table MAKT.*
data: begin of i_makt occurs 0,
MAKTX type MAKT-MAKTX,
end of i_makt.
**Declare outtabb**
data: begin of wa,
col1 type MARD-WERKS,
col2 type MARD-LGORT,
col3 type MARD-LABST,
end of wa.
data: i_outtab like table of wa with header line.
*******************start of selection screen***********************
select-options: S_MATNR for MARA-MATNR,
S_WERKS for MARD-WERKS,
S_LGORT for MARD-LGORT.
*****************end of selection screen***************************
***selecting data from databse*******
*******************start of main program***************************
start-of-selection.
*selection from table MARD*
perform select_data_mard.
**select data from MARA*
perform select_data_mara.
*
**select data from MAKT*
*perform select_data_makt.
*move-corressponding outtab*
perform fill_second-outtab.
*read table mara.*
perform read_mara.
*read table makt.*
perform read_makt.
**read table mard.
perform read_mard.
clear i_outtab.
wa-col1 = mara-MATNR.
wa-col2 = mard-WERKS.
wa-col3 = mard-LGORT.
append wa to i_outtab.
loop at i_mard into wa.
write: / wa-col1, wa-col2, wa-col3.
endloop.
*********************end of main program******************
&----
*& Form select_data_mard
&----
text
----
--> p1 text
<-- p2 text
----
FORM select_data_mard .
select WERKS LGORT LABST
from MARD
into table i_mard.
ENDFORM. " select_data_mard
&----
*& Form select_data_mara
&----
text
----
--> p1 text
<-- p2 text
----
FORM select_data_mara .
select MTART MATNR MBRSH
from MARA
into table i_mara.
ENDFORM. " select_data_mara
&----
*& Form select_data_makt
&----
text
----
--> p1 text
<-- p2 text
----
FORM select_data_makt .
select MAKTX
from MAKT
into table i_makt.
ENDFORM. " select_data_makt
&----
*& Form fill_second-outtab
&----
text
----
--> p1 text
<-- p2 text
----
FORM fill_second-outtab .
loop at i_outtab.
move-corresponding i_mard to i_outtab.
append i_outtab.
endloop.
ENDFORM. " fill_second-outtab
&----
*& Form read_mara
&----
text
----
--> p1 text
<-- p2 text
----
FORM read_mara .
read table i_mara with key
matnr = mara-matnr.
ENDFORM. " read_mara
&----
*& Form read_makt
&----
text
----
--> p1 text
<-- p2 text
----
FORM read_makt .
read table i_makt with key
MAKTX = makt-maktx.
ENDFORM. " read_mard
&----
*& Form read_mard
&----
text
----
--> p1 text
<-- p2 text
----
FORM read_mard .
read table i_mard with key
werks = MARD-WERKS
lgort = mard-lgort.
ENDFORM. " read_mard
‎2007 Feb 01 3:54 AM
Sulogna,
You can avoid all the looping using inner Join.... use the below code and delete rest all code. This should serve your purpose
data: begin of wa,
matnr type MARA-matnr,
maktx type MAKT-maktx,
werks type MARD-WERKS,
lgort type MARD-LGORT,
labst type MARD-LABST,
end of wa.
data: i_outtab like table of wa with header line.
*******************start of selection screen***********************
select-options: S_MATNR for MARA-MATNR,
S_WERKS for MARD-WERKS,
S_LGORT for MARD-LGORT.
*****************end of selection screen***************************
select amatnr bmaktx cwerks clgort c~labst from MARA as a
inner join MAKT as b ON amatnr = bmatnr
inner join MARD as c ON amatnr = cmatnr
into table i_outtab
where a~matnr in s_matnr
and c~werks in s_werks
and c~lgort in s_lgort.
loop at i_outtab into wa.
write: / wa-matnr, wa-maktx, wa-werks, wa-lgort, wa-labst.
endloop.
Message was edited by:
Susanth Swain
‎2007 Feb 01 3:55 AM
sorry i dint go through your entire code but what i am seeing the wrong things in code i am just stating it bellow.
1. you dint use your select-option in where clause of select.
2. move-corresponding will moving the value by name of the field not by the type of field so in your outtab and mard tab field names are different. how it will move?
3. after read table you are not defining any operation like modify or appending.
please correct me if i am wrong.
regards
shiba dutta
‎2007 Feb 01 5:06 AM
HI,
try this...
tables: MARA, MARD, MAKT.
data: begin of i_final occurs 0,
MATNR type MARA-MATNR,
MTART type MARA-MTART,
MBRSH type MARA-MBRSH,
WERKS type MARD-WERKS,
LGORT type MARD-LGORT,
LABST type MARD-LABST,
MAKTX type MAKT-MAKTX,
end of i_final.
*******************start of selection screen***********************
select-options: S_MATNR for MARA-MATNR,
S_WERKS for MARD-WERKS,
S_LGORT for MARD-LGORT.
*****************end of selection screen***************************
***selecting data from databse*******
*******************start of main program***************************
start-of-selection.
select maramatnr maramtart marambrsh mardwerks mardlgort mardlabst maktmaktx into table i_final from mara inner join mard on maramatnr = mardmatnr inner join makt on maramatnr = maktmaktx where maramatnr IN s_matnr and mardwerks in s_werks and mardlgort in s_lgort.
loop at i_final.
write: / i_final-werks, i_final-lgort, i_final-labst.
endloop.
Regards
SAB
‎2007 Feb 01 5:05 PM
I am working again on this problem and I will let you know that it is working or not.
Thanks
‎2007 Feb 01 5:43 PM
Hi all
in "select options",, if I have to select s_matnr, s_werks, s_lgort and tables are three----mara, mard, makt,,,,,,,then what is the best way to select this 3 fields from 3 tables? Do I need to use any join?
Thanks
‎2007 Feb 01 5:46 PM
HI,
U can use 1 select statement with JOIN or 3 select statements with loops and modifications..
my suggestion is if the join statement is not having any performance issue then go for that..
if u feel performance is bad with join then u can use select and for all entries to fetch records..
but i believe the best way for ur requirement is JOIN.
*****************************************
as ur output is related to only from MARD table so u can use only 1 select statement... if nothing more operations to do with report.
tables: MARD.
data: begin of i_final occurs 0,
WERKS type MARD-WERKS,
LGORT type MARD-LGORT,
LABST type MARD-LABST,
end of i_final.
*******************start of selection screen***********************
select-options:S_WERKS for MARD-WERKS,
S_LGORT for MARD-LGORT.
*****************end of selection screen***************************
***selecting data from databse*******
*******************start of main program***************************
start-of-selection.
select werks lgort labst from mard into table i_final where werks in
s_werks and lgort in s_lgort.
loop at i_final.
write: / i_final-werks, i_final-lgort, i_final-labst.
endloop.
****************************************
Pls close the thread if the problem is been solved, and reward to all helpful answers.
Regards
SAB
‎2007 Feb 03 6:13 AM
‎2007 Feb 01 5:07 AM
Hi Sulogna,
Please let me know if the given solution is working......
‎2007 Feb 01 5:30 PM
hi sulogna
To move values between the components of structures, use the statement
MOVE-CORRESPONDING <struct1> TO <struct2>.
This statement moves the contents of the components of structure <struct1> to the components of <struct2> that have identical names.
When it is executed, it is broken down into a set of MOVE statements, one for each pair of fields with identical names, as follows:
MOVE STRUCT1-<ci> TO STRUCT2-<c i>.
example
DATA: BEGIN OF ADDRESS,
FIRSTNAME(20) VALUE 'Fred',
SURNAME(20) VALUE 'Flintstone',
INITIALS(4) VALUE 'FF',
STREET(20) VALUE 'Cave Avenue,
NUMBER TYPE I VALUE '11'.
POSTCODE TYPE N VALUE '98765'.
CITY(20) VALUE 'Bedrock',
END OF ADDRESS.
DATA: BEGIN OF NAME,
SURNAME(20),
FIRSTNAME(20),
INITIALS(4),
TITLE(10) VALUE 'Mister',
END OF NAME.
MOVE-CORRESPONDING ADDRESS TO NAME
regards
warun
‎2007 Feb 01 5:46 PM
hi,
if yu want three fields
in mard these fields are there yu can select from mard itself.
regards
warun