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

how to use do varying command

Former Member
0 Likes
2,261

Hi all,

DATA: BEGIN OF i_mgmt OCCURS 0,

btrtl TYPE pa0001-btrtl,

btext TYPE t001p-btext,

perm TYPE pad_amt7s ,

con TYPE pad_amt7s ,

perm2 TYPE pad_amt7s ,

con2 TYPE pad_amt7s ,

perm3 TYPE pad_amt7s ,

con3 TYPE pad_amt7s ,

tot TYPE pad_amt7s ,

avg TYPE pad_amt7s ,

END OF i_mgmt.

This my int. table and i need to calculate tot. row wise How can i use do varying command in this condition. Or any other way to calculate tot. row wise...Plesae help me

Thanks.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,514

Hi Ramya,

After selecting the required data into itab i_mgmt with work area (say wa), do the following.

loop at i_mgmt into wa.

wa-tot = wa-perm + wa-con + wa-perm2 + wa-con2 + wa-perm3 + wa-con3.

wa-avg = wa-tot / 3.

modify i_mgmt index sy-tabix from wa .

endloop.

Hope it helps...

Regards,

Mdi.Deeba

Hi all,

DATA: BEGIN OF i_mgmt OCCURS 0,

btrtl TYPE pa0001-btrtl,

btext TYPE t001p-btext,

perm TYPE pad_amt7s ,

con TYPE pad_amt7s ,

perm2 TYPE pad_amt7s ,

con2 TYPE pad_amt7s ,

perm3 TYPE pad_amt7s ,

con3 TYPE pad_amt7s ,

tot TYPE pad_amt7s ,

avg TYPE pad_amt7s ,

END OF i_mgmt.

This my int. table and i need to calculate tot. row wise How can i use do varying command in this condition. Or any other way to calculate tot. row wise...Plesae help me

Thanks.

8 REPLIES 8
Read only

Former Member
0 Likes
1,514

Hi,

Do you mean that tot will be the sum of perm con, perm2, con2, perm3 and con3 for each btrtl then you can use COLLECT statement and collect the data in a new internal table.

regards,

Ankur Parab

Read only

0 Likes
1,514

Hi,

Ya tot = perm + con + perm2 + con2 + perm3 + con3 for eac btrtl. will collect gives the total row-wise?

Read only

0 Likes
1,514

>

> Hi,

>

> Ya tot = perm + con + perm2 + con2 + perm3 + con3 for eac btrtl. will collect gives the total row-wise?

COLLECT statment should not be used for standard tables (obsolete for standard tables). As suggested by Thomas please use the ASSIGN statement with the INCREMENT addition

Please check the below article(page 6)

[State of the art ABAP programs - part 2|https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/4fbafc9e-0e01-0010-dea9-9d23d1b269fb?overridelayout=true]

Regards

Rajesh

Read only

Former Member
0 Likes
1,514

Hi,

You can use simple loop - endloop to calculate any thing row wise.

Declare some field outside the loop for calculation and initilize it.

then use.

m_tot type p decimals 2 value 0.

loop at i_mgmt.

m_tot = m_tot + tot.

endloop.

m_tot will give you the final total row wise. You can use any number of variable as per calculating different fields total.

If this was your requirement, i think this is more than sufficient.

Regds,

Anil

Read only

0 Likes
1,514

Hi anil,

Here tot = perm + con + perm2 + con2 + perm3 + con3.

How to calculate??

Read only

ThomasZloch
Active Contributor
0 Likes
1,514

Depending on your SAP release, DO ... VARYING might be obsolete, use ASSIGN ... INCREMENT instead inside the loop.

See ABAP Online help for more information, as always.

Thomas

Read only

venkat_o
Active Contributor
0 Likes
1,514

Hi,

Check this example program how to use DO VARYING ..

REPORT ZTEST_NOTEPAD.

DATA: BEGIN OF text,
        word1 TYPE c LENGTH 4 VALUE 'AAAA',
        word2 TYPE c LENGTH 4 VALUE 'BBBB',
        word3 TYPE c LENGTH 4 VALUE 'CCCC',
        word4 TYPE c LENGTH 4 VALUE 'DDDD',
      END OF text.

DATA: word  TYPE c LENGTH 4,
      char1 TYPE c LENGTH 1,
      char2 TYPE c LENGTH 1,
      leng TYPE i.

FIELD-SYMBOLS <word> LIKE text-word1.
DATA inc TYPE i.

DESCRIBE FIELD text LENGTH leng IN CHARACTER MODE.
leng = leng / 2.

DO leng TIMES VARYING char1 FROM text(1)
                            NEXT text+2(1) RANGE text
              VARYING char2 FROM text+1(1)
                            NEXT text+3(1) RANGE text.
  WRITE: char1, char2.
  char1 = 'x'.
  char2 = 'y'.
ENDDO.

DO 4 TIMES VARYING word FROM text-word1 NEXT text-word2.
  WRITE / word.
ENDDO.

DO.
  inc = sy-index  - 1.
  ASSIGN text-word1 INCREMENT inc TO <word> RANGE text.
  IF sy-subrc = 0.
    WRITE / <word>.
  ELSE.
    EXIT.
  ENDIF.
ENDDO.
.

Thanks

Venkat.O

Read only

Former Member
0 Likes
1,515

Hi Ramya,

After selecting the required data into itab i_mgmt with work area (say wa), do the following.

loop at i_mgmt into wa.

wa-tot = wa-perm + wa-con + wa-perm2 + wa-con2 + wa-perm3 + wa-con3.

wa-avg = wa-tot / 3.

modify i_mgmt index sy-tabix from wa .

endloop.

Hope it helps...

Regards,

Mdi.Deeba