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

collect statement issue

Former Member
0 Likes
1,433

Hi all,

I have a requirement in which I am using Collect statement to club the numeric values.

TYPES: BEGIN OF  ST_VBBE ,
                  MATNR TYPE VBBE-MATNR,
                  WERKS TYPE VBBE-WERKS,
                  OMENG TYPE VBBE-OMENG,
            END OF ST_VBBE.
data : IT_VBBE TYPE TABLE OF ST_VBBE,
          WA_VBBE TYPE ST_VBBE,
          it_vbbe_f TYPE TABLE OF st_vbbe,
          WA_VBBE_F TYPE ST_VBBE.
START-OF-SELECTION.
       SELECT MATNR WERKS OMENG
                    FROM VBBE INTO TABLE IT_VBBE UP TO 500 rows.
BREAK-POINT.
LOOP AT IT_VBBE INTO WA_VBBE.
   COLLECT WA_VBBE_f INTO IT_VBBE_f.
ENDLOOP.


This is my code.. But I am not getting a single value in the table in which I am collecting the data.


I am getting the data in IT_VBBE.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,396

Hi

use the following code.

loop at it_vbbe into wa_vbbe.

collect wa_vbbe into it_vbbe_f.

endloop.

you will find the collected data in it_vbbe_f.

Regards

Shaik

12 REPLIES 12
Read only

Former Member
0 Likes
1,396

Hi,

     from where u are getting data into wa_vbbe_f , which you are collecting into it_vbbe_f. Check your Workarea and Table in Collect Statement

Read only

Former Member
0 Likes
1,397

Hi

use the following code.

loop at it_vbbe into wa_vbbe.

collect wa_vbbe into it_vbbe_f.

endloop.

you will find the collected data in it_vbbe_f.

Regards

Shaik

Read only

Mohamed_Mukhtar
Active Contributor
0 Likes
1,396

Hello Yash

Change the collect statement to COLLECT WA_VBBE INTO IT_VBBE_f.

Read only

jarus
Participant
0 Likes
1,396

Hi Yash,

use your coding as

LOOP AT IT_VBBE INTO WA_VBBE.

   COLLECT WA_VBBE INTO IT_VBBE_f.

ENDLOOP.


or


LOOP AT IT_VBBE INTO WA_VBBE.

  move WA_VBBE to WA_VBBE_f.

  COLLECT WA_VBBE_f INTO IT_VBBE_f.

ENDLOOP.



Thanks,

Sooraj Saini

Read only

SharathYaralkattimath
Contributor
0 Likes
1,396

Add the highlighted code.


LOOP AT IT_VBBE INTO WA_VBBE.

    MOVE: WA_VBBE TO WA_VBBE_f.

   COLLECT WA_VBBE_f INTO IT_VBBE_f.

ENDLOOP.

Read only

Former Member
0 Likes
1,396

Hi Yash,



TYPES: BEGIN OF  ST_VBBE ,

                 MATNR TYPE VBBE-MATNR,

                   WERKS TYPE VBBE-WERKS,

                   OMENG TYPE VBBE-OMENG,

             END OF ST_VBBE.

data : IT_VBBE TYPE TABLE OF ST_VBBE,

           WA_VBBE TYPE ST_VBBE,

           it_vbbe_f TYPE TABLE OF st_vbbe,

           WA_VBBE_F TYPE ST_VBBE.

START-OF-SELECTION.

        SELECT MATNR WERKS OMENG

                     FROM VBBE INTO TABLE IT_VBBE UP TO 500 rows.

LOOP AT IT_VBBE INTO WA_VBBE_f.

    COLLECT WA_VBBE_f INTO IT_VBBE_f.

ENDLOOP.



Regards

Ashwin.

Read only

former_member201275
Active Contributor
0 Likes
1,396

You are looping int WA_VBBE, but collecting from WA_VBBE_F? Thats not going to work. Change your collect to "COLLECT WA_VBBE INTO IT_VBBE_F".

Read only

Former Member
0 Likes
1,396

As per your code you doing worng,

TYPES: BEGIN OF  ST_VBBE ,

                  MATNR TYPE VBBE-MATNR,

                  WERKS TYPE VBBE-WERKS,

                  OMENG TYPE VBBE-OMENG,

            END OF ST_VBBE.

data : IT_VBBE TYPE TABLE OF ST_VBBE,

          WA_VBBE TYPE ST_VBBE,

          it_vbbe_f TYPE TABLE OF st_vbbe,

          WA_VBBE_F TYPE ST_VBBE.

START-OF-SELECTION.

       SELECT MATNR WERKS OMENG

                    FROM VBBE INTO TABLE IT_VBBE UP TO 500 rows.

BREAK-POINT.

LOOP AT IT_VBBE INTO WA_VBBE.

   COLLECT WA_VBBE_f INTO IT_VBBE_f.  " wrong here you taking data in WA_VBBE, so need to pass in WA_VBBE_F and then collect.

ENDLOOP.




"Refer this code


TYPES: BEGIN OF  ST_VBBE ,

                  MATNR TYPE VBBE-MATNR,

                  WERKS TYPE VBBE-WERKS,

                  OMENG TYPE VBBE-OMENG,

            END OF ST_VBBE.

data : IT_VBBE TYPE TABLE OF ST_VBBE,

          WA_VBBE TYPE ST_VBBE,

          it_vbbe_f TYPE TABLE OF st_vbbe,

          WA_VBBE_F TYPE ST_VBBE.

START-OF-SELECTION.

       SELECT MATNR WERKS OMENG

                    FROM VBBE INTO TABLE IT_VBBE UP TO 500 rows.

BREAK-POINT.

LOOP AT IT_VBBE INTO WA_VBBE.

  

    WA_VBBE_f = WA_VBBE.

   COLLECT WA_VBBE_f INTO IT_VBBE_f

ENDLOOP.



Regards,

Sandeep


Read only

Former Member
0 Likes
1,396

Hello ,

Try the below code. Only chnage required is the collect statement will use the same looping table. Inorder to see the other entries in your it_vbbe_f table you need to use append statement also as well.

TYPES: BEGIN OF  ST_VBBE ,

                 MATNR TYPE VBBE-MATNR,

                 WERKS TYPE VBBE-WERKS,

                 OMENG TYPE VBBE-OMENG,

           END OF ST_VBBE.

data : IT_VBBE TYPE TABLE OF ST_VBBE,

         WA_VBBE TYPE ST_VBBE.

START-OF-SELECTION.

      SELECT MATNR WERKS  OMENGE

                   FROM VBBE INTO TABLE IT_VBBE.

LOOP AT IT_VBBE INTO WA_VBBE.

  COLLECT WA_VBBE INTO IT_VBBE.

ENDLOOP.

COLLECT  allows you to create unique or summarized datasets.

              The system first tries to find a table entry corresponding to

              the table key (see Key definition for internal tables). The

              key values are taken either from the header line of the

              internal table itab, or from the explicitly-specified work

              area wa. itab must have a flat structure, that is, it may not

              contain other internal tables. All components that are not

              part of the key must be have numeric types (see ABAP numeric

              types).

              If the system finds an entry, the numeric fields that are not

              part of the table key (see ABAP number types) are added to the

              sum total of the existing entries. If it does not find an

              entry, the system creates a new entry instead.

              The way in which the system finds the entries depends on the

              type of the internal table:

Thanks,

SK

Read only

0 Likes
1,396

Siva,

WA_VBBE_f doesn't have any values. You can check the following loop:

LOOP AT IT_VBBE INTO WA_VBBE.

   wa_vbbe_f-matnr = wa_vbbe-matnr.

   wa_vbbe_f-werks = wa_vbbe-werks.

   wa_vbbe_f-omeng = wa_vbbe-omeng.

   COLLECT WA_VBBE_f INTO IT_VBBE_f.

ENDLOOP.

Regards

Purnand

Read only

former_member201275
Active Contributor
0 Likes
1,396

Is your issue resolved? Did any of the replies help or answer your question? Please mark accordingly and close.

Read only

Pavan_Golesar
Active Participant
0 Likes
1,396

hi, yash you have made a slight mistake in my sense, which is why you are unable to get the data through collect statemant.


Here is the recorrect code, kindly like if you are satisfied.


TYPES: BEGIN OF  ST_VBBE ,
                  MATNR TYPE VBBE-MATNR,
                  WERKS TYPE VBBE-WERKS,
                  OMENG TYPE VBBE-OMENG,
            END OF ST_VBBE.
data : IT_VBBE TYPE TABLE OF ST_VBBE,
          WA_VBBE TYPE ST_VBBE,
          it_vbbe_f TYPE TABLE OF st_vbbe,
          WA_VBBE_F TYPE ST_VBBE.
START-OF-SELECTION.
       SELECT MATNR WERKS OMENG
                    FROM VBBE INTO TABLE IT_VBBE UP TO 500 rows.
BREAK-POINT.
LOOP AT IT_VBBE INTO WA_VBBE.
   COLLECT WA_VBBE INTO IT_VBBE_f.
ENDLOOP.


i hope this solves your query.

thanks.