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

Looping the internal table

Former Member
0 Likes
2,096

Hi Guru's,

I have one internal table it_mbew. i have the fields matnr salk3 lbkum when i loop this table i will get the calculation salk3 / lbkum with maaterial wise.

can any one pls suggest me how to do this.

Thanks & Best Regards,

Praveen.

1 ACCEPTED SOLUTION
Read only

faisalatsap
Active Contributor
0 Likes
2,038

Hi, Praveen

Test the following code it is working fine and hope will sove out you problem

TABLES: ent5507.

TYPES: BEGIN OF t_ent5507,
  matnr LIKE ent5507-matnr,
  salk3 LIKE ent5507-salk3,
  lbkum LIKE ent5507-lbkum,
  salk3_d_lbkum TYPE p DECIMALS 2,
  END OF t_ent5507.

DATA: it_ent5507 TYPE STANDARD TABLE OF t_ent5507 WITH HEADER LINE,
      wa_it_ent5507 TYPE t_ent5507.

SELECT matnr salk3 lbkum FROM ent5507
  INTO CORRESPONDING FIELDS OF TABLE it_ent5507.

LOOP AT it_ent5507 INTO wa_it_ent5507.
  wa_it_ent5507-salk3_d_lbkum = wa_it_ent5507-salk3 / wa_it_ent5507-lbkum.
  MODIFY it_ent5507 from wa_it_ent5507 INDEX sy-tabix.
ENDLOOP.

Please Reply if any Issue,

Kind Regards,

Faisal

Hi Guru's,

I have one internal table it_mbew. i have the fields matnr salk3 lbkum when i loop this table i will get the calculation salk3 / lbkum with maaterial wise.

can any one pls suggest me how to do this.

Thanks & Best Regards,

Praveen.

14 REPLIES 14
Read only

Former Member
0 Likes
2,038

data: calc type i.

loop at it_mbew into wa.

calc = wa-salk3/wa-lbkum.

write: \ wa-matnr, wa-calc.

endloop.

Is that what u want?

It wud be better if u show us with example what exactly u want?

кu03B1ятu03B9к

Read only

0 Likes
2,038

HI kartik,

i have two inetrnal tables names it_mbew and bestand now i am having the fields in the

table it_mbew are

matnr salk3 lbkum and 2n d internal table are only one field i.e factor now i want to add this firld in to the first internal table like

matnr salk3 lbkum factor this is the output i want finally. can u pls tell me how to do this.

Thanks & Best Regadrs,

Praveen.

Read only

0 Likes
2,038

Hi i need to know two things.

first

-->relation between matnr salk3 lbkum and factor.

If thr is no relation then

-->are the no. of records in it_mbew and bestand same?

Does the stucture of it_mbew have this field factor?

кu03B1ятu03B9к

Read only

0 Likes
2,038

let me assume that ur it_mbew has field factor and number of records in it_mbew and bestand are same in tht case. do like this.



loop at it_mbew into wa_mbew.

v_index = sy-tabix.
read table bestand into wa index v_index.

wa_mbew-factor = wa-factor.

modify it_mbew index v_index from wa_mbew transporting factor.

endloop.

кu03B1ятu03B9к

Edited by: kartik tarla on Jan 22, 2009 9:19 AM

Read only

0 Likes
2,038

HI kartik,

i am sorry i will explain u my problem clearly...

i am having the two inetrnal tables it_mbew and bestand.

in mbew i am having the fields

fields : matnr salk3 lbkum wlabs

in bestand only one field i have

field : factor

the value of this factor is

factor = salk3 / lbkum.

now this factor i have to transport to it_mbew-wlabs table .

and bellow is the my coding.

REPORT ZMMR042.

tables : mara , mard, mbew.

type-pools: slis.

*-> types / internal table / work area

types: begin of t_mara,

matnr like mara-matnr, " Material Number

ersda like mara-ersda, " date

end of t_mara.

data: it_mara type standard table of t_mara,

wa_mara type t_mara.

types : begin of t_mard,

matnr like mard-matnr, " Material Number

lgort like mard-lgort, " Storage Location

labst like mard-labst, " valueated unrestricted usage stock

end of t_mard.

data: it_mard type standard table of t_mard,

wa_mard type t_mard.

types : begin of t_mbew,

matnr like mbew-matnr, " Material Number

salk3 like mbew-salk3, " value of total value stock

lbkum like mbew-lbkum,

wlabs like mbew-salk3,

end of t_mbew.

data: it_mbew type standard table of t_mbew with header line,

wa_mbew type t_mbew.

data : begin of bestand occurs 0,

factor type f,

end of bestand.

selection-screen begin of block 001 with frame title text-001.

select-options : so_ersda for mara-ersda.

selection-screen end of block 001.

perform getdata.

perform calculation.

&----


*& Form getdata

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form getdata .

select matnr ersda from mara into corresponding fields of table it_mara where

ersda in so_ersda.

select matnr lgort labst from mard into corresponding fields of table it_mard

for all entries in it_mara where matnr = it_mara-matnr and

( lgort EQ 'LSTP' or lgort EQ '10TP' or lgort EQ 'PORJ'

or lgort EQ '22HQ' or lgort EQ 'V60S' or lgort EQ 'V70R'

or lgort EQ 'V80B' or lgort EQ 'V90S' or lgort EQ 'VOTH').

.

select matnr salk3 lbkum from mbew into corresponding fields of table it_mbew for all entries in

it_mard where matnr = it_mard-matnr .

endform. " getdata

&----


*& Form calculation

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form calculation .

loop at it_mbew into wa_mbew .

bestand-factor = wa_mbew-salk3 / wa_mbew-lbkum.

append bestand.

endloop.

endform. " calculation

can u pls explain me...

Thanks & Best Regards,

Praveen.

Read only

0 Likes
2,038

hi,

u can use like this

1.in the fisrt table u have a field wlabs where u want to fill the factor with from the second table(that is the calculation is based on the 2 fields of the first table).but for this u can loop on the same internal table.

do like this

loop at first.

first-wlabs = field1/field2(both in same table).

modify the table.

endloop.

Read only

Former Member
0 Likes
2,038

data: a type i.

loop at itab.

a = c/b.

write: / a.

endloop.

Read only

Former Member
0 Likes
2,038

sort the matnr before looping

Read only

Former Member
0 Likes
2,038

Hi Prveen,

If you have two internal table and move one final internal tabel then you declaere one more structure for final internal table and move to values into that internal table.

Regards

Md.MahaboobKhan

Read only

former_member206439
Contributor
0 Likes
2,038

Hi

1st you need to declare some integer varaible , and with in the loop of internal table do that claculation and store that in that variable.

Data : cal type i.

Loop at  it_mbew.

cal = salk3 / lbkum .

ENDLOOP.

if you want to display that value in output then declare that variable in final internal table.

Read only

faisalatsap
Active Contributor
0 Likes
2,039

Hi, Praveen

Test the following code it is working fine and hope will sove out you problem

TABLES: ent5507.

TYPES: BEGIN OF t_ent5507,
  matnr LIKE ent5507-matnr,
  salk3 LIKE ent5507-salk3,
  lbkum LIKE ent5507-lbkum,
  salk3_d_lbkum TYPE p DECIMALS 2,
  END OF t_ent5507.

DATA: it_ent5507 TYPE STANDARD TABLE OF t_ent5507 WITH HEADER LINE,
      wa_it_ent5507 TYPE t_ent5507.

SELECT matnr salk3 lbkum FROM ent5507
  INTO CORRESPONDING FIELDS OF TABLE it_ent5507.

LOOP AT it_ent5507 INTO wa_it_ent5507.
  wa_it_ent5507-salk3_d_lbkum = wa_it_ent5507-salk3 / wa_it_ent5507-lbkum.
  MODIFY it_ent5507 from wa_it_ent5507 INDEX sy-tabix.
ENDLOOP.

Please Reply if any Issue,

Kind Regards,

Faisal

Read only

0 Likes
2,038

HI frisal,

I am having the inetrnal table it_mard in that the data is like this

Example :

matnr store.loc labst wlabs1.

0001 10tp 23 44

0001 10tp 12 13

0002 10tp 7 5

now i want to loop the it_mard table i need to get the wlabst value total like

matnr store.loc labst wlabs1.

0001 10tp 23 44

0001 10tp 12 13

M. total 55

0002 10tp 7 4

10tp 2 1

M. total 5

TOTAL = 60.

Note : here TOTAL = 60 value i need to get.

can u pls give me a suggestion how to do that one.

in bellow is the my coding pls let me know if any...

Thanks & Best Regards,

Praveens.

Read only

0 Likes
2,038

Hi, Praveen

Test the following code If it is can fulfill your requirement.

TYPES: BEGIN OF t_vbeln,
  likp LIKE likp-vbeln,
  lfimg LIKE lips-lfimg,
END OF t_vbeln.

DATA: it_vbeln TYPE STANDARD TABLE OF t_vbeln WITH HEADER LINE,
      wa_it_vbeln TYPE t_vbeln,
      it2_vbeln TYPE STANDARD TABLE OF t_vbeln WITH HEADER LINE,
      wa_it2_vbeln TYPE t_vbeln.

SELECT lfimg FROM lips UP TO 10 ROWS
  INTO CORRESPONDING FIELDS OF wa_it_vbeln.
  wa_it_vbeln-likp = '1'.
  APPEND wa_it_vbeln TO it_vbeln.
ENDSELECT.
SELECT lfimg FROM lips UP TO 10 ROWS
  INTO CORRESPONDING FIELDS OF wa_it_vbeln.
  wa_it_vbeln-likp = '2'.
  APPEND wa_it_vbeln TO it_vbeln.
ENDSELECT.

SORT it_vbeln by likp lfimg.
LOOP AT it_vbeln INTO wa_it_vbeln.

  APPEND wa_it_vbeln to it2_vbeln.
  WRITE : / wa_it_vbeln-likp,  wa_it_vbeln-lfimg.

  AT END OF likp.
    SUM.
    wa_it_vbeln-likp = 'Sub Tot'.
    APPEND wa_it_vbeln to it2_vbeln.
    WRITE :/ wa_it_vbeln-likp,  wa_it_vbeln-lfimg.
  ENDAT.

  AT LAST.
    SUM.
    wa_it_vbeln-likp = 'Grand Tot'.
    APPEND wa_it_vbeln to it2_vbeln.
    WRITE :/ wa_it_vbeln-likp,  wa_it_vbeln-lfimg.
  ENDAT.

ENDLOOP.

Please let me now if you need some thing else and I think that better to submit new question for because it is again the rules of SDN.

Kind Regards,

Faisal

Edited by: Faisal Altaf on Jan 22, 2009 1:05 PM

Edited by: Faisal Altaf on Jan 22, 2009 1:14 PM

Read only

faisalatsap
Active Contributor
0 Likes
2,038

Hi,

I have changed you code Please test it, it is working according to you requirment,

TABLES : mara , mard, mbew.
TYPE-POOLS: slis.

*-> types / internal table / work area

TYPES: BEGIN OF t_mara,
matnr LIKE mara-matnr, " Material Number
ersda LIKE mara-ersda, " date
END OF t_mara.
DATA: it_mara TYPE STANDARD TABLE OF t_mara,
wa_mara TYPE t_mara.

TYPES : BEGIN OF t_mard,
matnr LIKE mard-matnr, " Material Number
lgort LIKE mard-lgort, " Storage Location
labst LIKE mard-labst, " valueated unrestricted usage stock

END OF t_mard.

DATA: it_mard TYPE STANDARD TABLE OF t_mard,
wa_mard TYPE t_mard.

TYPES : BEGIN OF t_mbew,
matnr LIKE mbew-matnr, " Material Number
salk3 LIKE mbew-salk3, " value of total value stock
lbkum LIKE mbew-lbkum,
wlabs LIKE mbew-salk3,
  factor TYPE f,
END OF t_mbew.


DATA: it_mbew TYPE STANDARD TABLE OF t_mbew WITH HEADER LINE,
wa_mbew TYPE t_mbew.

DATA : BEGIN OF bestand OCCURS 0,
factor TYPE f,

END OF bestand.

SELECTION-SCREEN BEGIN OF BLOCK 001 WITH FRAME TITLE text-001.

SELECT-OPTIONS : so_ersda FOR mara-ersda.

SELECTION-SCREEN END OF BLOCK 001.

PERFORM getdata.
PERFORM calculation.
BREAK-POINT .

*&---------------------------------------------------------------------*
*&      Form  getdata
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM getdata .

  SELECT matnr ersda FROM mara INTO CORRESPONDING FIELDS OF TABLE it_mara WHERE
  ersda IN so_ersda.

  SELECT matnr lgort labst FROM mard INTO CORRESPONDING FIELDS OF TABLE it_mard
  FOR ALL ENTRIES IN it_mara WHERE matnr = it_mara-matnr AND
  ( lgort EQ 'LSTP' OR lgort EQ '10TP' OR lgort EQ 'PORJ'
  OR lgort EQ '22HQ' OR lgort EQ 'V60S' OR lgort EQ 'V70R'
  OR lgort EQ 'V80B' OR lgort EQ 'V90S' OR lgort EQ 'VOTH').
  .

  SELECT matnr salk3 lbkum FROM mbew INTO CORRESPONDING FIELDS OF TABLE it_mbew FOR ALL ENTRIES IN
  it_mard WHERE matnr = it_mard-matnr .

ENDFORM. " getdata

*&---------------------------------------------------------------------*
*&      Form  calculation
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM calculation .

  LOOP AT it_mbew INTO wa_mbew .

    wa_mbew-factor = wa_mbew-salk3 / wa_mbew-lbkum.

    MODIFY it_mbew from wa_mbew.

  ENDLOOP.

ENDFORM. " calculation

Please Reply if any Issue.

Kind Regards,

Faisal