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

loop at itab

Former Member
0 Likes
1,090

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.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,047

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

8 REPLIES 8
Read only

Former Member
0 Likes
1,047

Hello,

sort itab by date in ascending order, read the first record.

Regards,

Vasavi.k

Read only

Former Member
0 Likes
1,047

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.

Read only

ferry_lianto
Active Contributor
0 Likes
1,047

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

Read only

Former Member
0 Likes
1,047

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.

Read only

0 Likes
1,047

arun nice answer thsnks.

i need to update is033-zlbkum every line that i have in is033.

the calc is

zlbkum = end_qty - magbb.

Read only

Manohar2u
Active Contributor
0 Likes
1,047

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

Read only

Former Member
0 Likes
1,048

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

Read only

0 Likes
1,047

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