07-09-2006 12:51 PM
LOOP AT imard ASSIGNING <ls_mard>.
LOOP AT is033 ASSIGNING <ls_s033>
where matnr = <ls_mard>-matnr
and lgort = <ls_mard>-lgort.
<b>here i get 4 rows and i want to take the highest date(sptag) mzubb
magbb for each matnr</b>and calc the menge.
ENDLOOP.
ENDLOOP.
07-09-2006 1:57 PM
Hi Rani,
Is this OK.
REPORT zzarun_1.
DATA :imard TYPE STANDARD TABLE OF mard WITH HEADER LINE,
is033 TYPE STANDARD TABLE OF s033 WITH HEADER LINE.
FIELD-SYMBOLS : <ls_mard> TYPE mard,
<ls_s033> TYPE s033.
*Declare two Internal Tables
DATA : itemp LIKE is033 OCCURS 0, "Holding four records
ifinal LIKE is033 OCCURS 0. "Holding final data
LOOP AT imard ASSIGNING <ls_mard>.
LOOP AT is033 ASSIGNING <ls_s033> WHERE matnr = <ls_mard>-matnr
AND lgort = <ls_mard>-lgort.
*Substract here befor appending
<b><ls_s033>-zlbkum = <ls_s033>-end_qty - <ls_s033>-magbb.</b>
APPEND <ls_s033> TO itemp.
ENDLOOP.
*Take the row with highest date (sptag)
SORT itemp BY sptag .
READ TABLE itemp ASSIGNING <ls_s033> INDEX 1.
APPEND <ls_s033> TO ifinal.
*Take the row with highest mzubb
SORT itemp BY mzubb.
READ TABLE itemp ASSIGNING <ls_s033> INDEX 1.
APPEND <ls_s033> TO ifinal.
*Take the row with highest magbb
SORT itemp BY magbb.
READ TABLE itemp ASSIGNING <ls_s033> INDEX 1.
APPEND <ls_s033> TO ifinal.
"In internal table IFINAL you have the required data
"Do your processing(Calculation) here.
*After processing dont forget to refresh the Internal tables
CLEAR : itemp, ifinal.
REFRESH : itemp, ifinal.
ENDLOOP.
Regards,
Arun S.
Message was edited by: Arun Sambargi
07-09-2006 1:10 PM
Hello,
sort itab by date in ascending order, read the first record.
Regards,
Vasavi.k
07-09-2006 1:12 PM
before doing this append another itab same structure has imard or is033 based on data mzubb magbb.. apend the itab.
sort the itab.based on sptag,,,and mzubb
LOOP AT imard ASSIGNING <ls_mard>.
LOOP AT is033 ASSIGNING <ls_s033>
where matnr = <ls_mard>-matnr
and lgort = <ls_mard>-lgort.
ENDLOOP.
ENDLOOP.
07-09-2006 1:14 PM
Hi Rani,
Please sort internal table IS033 with MATNR and LGORT (ASCENDING) and SPTAG, MZUBB and MAGBB (DESCENDING) prior to looping statement.
Then you use control break processing to get the highest date for SPTAG MZUBB and MAGBB when looping IS033.
AT NEW SPTAG.
...
ENDAT.
Hope this will give you an idea.
Regards,
Ferry Lianto
07-09-2006 1:24 PM
Hi Rani,
Is your requirement somenthing like this.
Consider this code.
REPORT zzarun_1.
DATA :imard TYPE STANDARD TABLE OF mard WITH HEADER LINE,
is033 TYPE STANDARD TABLE OF s033 WITH HEADER LINE.
FIELD-SYMBOLS : <ls_mard> TYPE mard,
<ls_s033> TYPE s033.
<b>*Declare two Internal Tables</b>
DATA : itemp LIKE is033 OCCURS 0, "Holding four records
ifinal LIKE is033 OCCURS 0. "Holding final data
LOOP AT imard ASSIGNING <ls_mard>.
LOOP AT is033 ASSIGNING <ls_s033> WHERE matnr = <ls_mard>-matnr
AND lgort = <ls_mard>-lgort.
APPEND <ls_s033> TO itemp.
ENDLOOP.
*Take the row with highest date (sptag)
SORT itemp BY sptag .
READ TABLE itemp ASSIGNING <ls_s033> INDEX 1.
APPEND <ls_s033> TO ifinal.
*Take the row with highest mzubb
SORT itemp BY mzubb.
READ TABLE itemp ASSIGNING <ls_s033> INDEX 1.
APPEND <ls_s033> TO ifinal.
*Take the row with highest magbb
SORT itemp BY magbb.
READ TABLE itemp ASSIGNING <ls_s033> INDEX 1.
APPEND <ls_s033> TO ifinal.
"In internal table IFINAL you have the required data
"Do your processing(Calculation) here.
<b>*After processing dont forget to refresh the Internal tables</b>
CLEAR : itemp, ifinal.
REFRESH : itemp, ifinal.
ENDLOOP.
Regards,
Arun Sambargi.
07-09-2006 1:33 PM
arun nice answer thsnks.
i need to update is033-zlbkum every line that i have in is033.
the calc is
zlbkum = end_qty - magbb.
07-09-2006 1:26 PM
Can also try in this way, ( might possible )
sort is033 by sptag.
LOOP AT imard ASSIGNING <ls_mard>.
read table is033 with key marnt = matnr = <ls_mard>-matnr
and lgort = <ls_mard>-lgort.
if sy-subrc = 0.
you will get the first record which should be highest date.
endif.
endloop.
Regds
Manohar
07-09-2006 1:57 PM
Hi Rani,
Is this OK.
REPORT zzarun_1.
DATA :imard TYPE STANDARD TABLE OF mard WITH HEADER LINE,
is033 TYPE STANDARD TABLE OF s033 WITH HEADER LINE.
FIELD-SYMBOLS : <ls_mard> TYPE mard,
<ls_s033> TYPE s033.
*Declare two Internal Tables
DATA : itemp LIKE is033 OCCURS 0, "Holding four records
ifinal LIKE is033 OCCURS 0. "Holding final data
LOOP AT imard ASSIGNING <ls_mard>.
LOOP AT is033 ASSIGNING <ls_s033> WHERE matnr = <ls_mard>-matnr
AND lgort = <ls_mard>-lgort.
*Substract here befor appending
<b><ls_s033>-zlbkum = <ls_s033>-end_qty - <ls_s033>-magbb.</b>
APPEND <ls_s033> TO itemp.
ENDLOOP.
*Take the row with highest date (sptag)
SORT itemp BY sptag .
READ TABLE itemp ASSIGNING <ls_s033> INDEX 1.
APPEND <ls_s033> TO ifinal.
*Take the row with highest mzubb
SORT itemp BY mzubb.
READ TABLE itemp ASSIGNING <ls_s033> INDEX 1.
APPEND <ls_s033> TO ifinal.
*Take the row with highest magbb
SORT itemp BY magbb.
READ TABLE itemp ASSIGNING <ls_s033> INDEX 1.
APPEND <ls_s033> TO ifinal.
"In internal table IFINAL you have the required data
"Do your processing(Calculation) here.
*After processing dont forget to refresh the Internal tables
CLEAR : itemp, ifinal.
REFRESH : itemp, ifinal.
ENDLOOP.
Regards,
Arun S.
Message was edited by: Arun Sambargi
07-09-2006 2:16 PM
I know the <b>loop at where</b> statement has been improved quite a bit but for runtime considerations I would still suggest that you use a sorted table and use <b>read table with key</b> -- instead of the inner loop at itab where
(see one of the previous posts).
This might have very little impact if the table has just a few rows but can be quite different if each table has around 300,000 rows...
Enjoy