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

Former Member
0 Likes
746

Hi all,

This is my code . my collect statement is not collecting all the values .Can any one help me out in this issue?

SELECT-OPTIONS: S_AUFNR FOR AUFK-AUFNR.

PARAMETERS: P_VERSN LIKE COSp-VERSN,

P_GJAHR LIKE COSp-GJAHR,

P1_VERSN LIKE COEP-VERSN.

SELECT * FROM AUFK INTO TABLE IT_AUFK WHERE AUFNR IN S_AUFNR AND

( AUART = '5200 ' OR AUART = '5500' OR AUART = '5700' OR AUART = '8500'

OR AUART = '8700' ) .

LOOP AT IT_AUFK.

SELECT * FROM SETLEAF INTO TABLE IT_SETLEAF

WHERE SETCLASS = '0103' AND

SETNAME = IT_AUFK-AUFNR+6(6).

LOOP AT IT_SETLEAF.

CONCATENATE 'OR' IT_SETLEAF-VALFROM INTO OBJNR.

SELECT * FROM COSS INTO TABLE IT_COSS WHERE

OBJNR = OBJNR AND

GJAHR = P_GJAHR AND

VERSN = P1_VERSN AND

WRTTP = '01'.

LOOP AT IT_COSS.

IT_GROUP-P1 = IT_COSS-WKG001.

IT_GROUP-P2 = IT_COSS-WKG002.

IT_GROUP-P3 = IT_COSS-WKG003.

IT_GROUP-P4 = IT_COSS-WKG004.

IT_GROUP-P5 = IT_COSS-WKG005.

IT_GROUP-P6 = IT_COSS-WKG006.

IT_GROUP-P7 = IT_COSS-WKG007.

IT_GROUP-P8 = IT_COSS-WKG008.

IT_GROUP-P9 = IT_COSS-WKG009.

IT_GROUP-P10 = IT_COSS-WKG010.

IT_GROUP-P11 = IT_COSS-WKG011.

IT_GROUP-P12 = IT_COSS-WKG012.

READ TABLE IT_SETLEAF WITH KEY SETNAME = IT_COSS-OBJNR+8(6).

COLLECT IT_GROUP.

*CLEAR IT_GROUP.

WRITE: / IT_GROUP-P1 ,IT_GROUP-P2.

ENDLOOP.

ENDLOOP.

6 REPLIES 6
Read only

Former Member
0 Likes
670

hi Priya,

declare the value as per the database field length

SELECT * FROM AUFK INTO TABLE IT_AUFK WHERE AUFNR IN S_AUFNR AND

( AUART = <b>'5200 '</b> OR AUART = <b>'5500'</b> OR AUART = '5700' OR AUART = '8500'

OR AUART = <b>'8700'</b> ) .

i meant to say is in the select statement remove the additional space i.e,

AUART = <b>'5200 '</b>

to

AUART = <b>'5200'</b>

Read only

Former Member
0 Likes
670

you are looping at it_coss and collecting it_group. It doesn't work that way.

regards,

Ravi

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
670

How is IT_GROUP defined. Also, make sure to clear each time thru the loop.



LOOP AT IT_COSS.

<b>clear IT_GROUP.</b>

IT_GROUP-P1 = IT_COSS-WKG001.
IT_GROUP-P2 = IT_COSS-WKG002.
IT_GROUP-P3 = IT_COSS-WKG003.
IT_GROUP-P4 = IT_COSS-WKG004.
IT_GROUP-P5 = IT_COSS-WKG005.
IT_GROUP-P6 = IT_COSS-WKG006.
IT_GROUP-P7 = IT_COSS-WKG007.
IT_GROUP-P8 = IT_COSS-WKG008.
IT_GROUP-P9 = IT_COSS-WKG009.
IT_GROUP-P10 = IT_COSS-WKG010.
IT_GROUP-P11 = IT_COSS-WKG011.
IT_GROUP-P12 = IT_COSS-WKG012.
READ TABLE IT_SETLEAF
       WITH KEY SETNAME = IT_COSS-OBJNR+8(6).

COLLECT IT_GROUP.


ENDLOOP.

<b>loop at it_Group.
WRITE: / IT_GROUP-P1 ,IT_GROUP-P2.
endloop.</b>



And yes, you can collect into a different internal table.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
670

This statement inserts the contents of a work area wa either as single row into an internal table itab

OR

Adds the values of its <b>numeric components</b> to the corresponding <b>values of existing rows with the same key</b>.

Check the definition of IT_GROUP

-Kiran

Read only

Former Member
0 Likes
670

I think part of your problem is in:


SELECT * FROM SETLEAF INTO TABLE IT_SETLEAF
  WHERE SETCLASS = '0103' AND
        SETNAME  = IT_AUFK-AUFNR+6(6).

SETCLASS 0103 is for order groups. You seem to be selecting based on the order - IT_AUFK-AUFNR+6(6). (Unless you do have order groups based on part of the order number).

So could you check this selection?

Rob

Read only

0 Likes
670

Also - you don't appear to have any character fields in it_group. Maybe you meant to put something from setleaf into it, but didn't. The COLLECT statement needs at least one character field to collect.

So, assuming I'm wrong about the order group, this may work:


REPORT ztest NO STANDARD PAGE HEADING LINE-SIZE 255.

TABLES: aufk, setleaf, coss.

SELECT-OPTIONS: s_aufnr FOR aufk-aufnr.

PARAMETERS: p_versn  LIKE cosp-versn,
            p_gjahr  LIKE cosp-gjahr,
            p1_versn LIKE coep-versn.

DATA: BEGIN OF it_aufk OCCURS 0.
        INCLUDE STRUCTURE aufk.
DATA: END   OF it_aufk.

DATA: BEGIN OF it_setleaf OCCURS 0.
        INCLUDE STRUCTURE setleaf.
DATA: END   OF it_setleaf.

DATA: BEGIN OF it_coss OCCURS 0.
        INCLUDE STRUCTURE coss.
DATA: END   OF it_coss.

DATA: BEGIN OF it_group OCCURS 0,
        group LIKE setleaf-setname,
        p1  LIKE coss-wkg001,
        p2  LIKE coss-wkg001,
        p3  LIKE coss-wkg001,
        p4  LIKE coss-wkg001,
        p5  LIKE coss-wkg001,
        p6  LIKE coss-wkg001,
        p7  LIKE coss-wkg001,
        p8  LIKE coss-wkg001,
        p9  LIKE coss-wkg001,
        p10 LIKE coss-wkg001,
        p11 LIKE coss-wkg001,
        p12 LIKE coss-wkg001,
      END   OF it_group.

DATA: objnr LIKE coss-objnr.

SELECT * FROM aufk INTO TABLE it_aufk
WHERE aufnr IN s_aufnr AND
( auart = '5200 ' OR auart = '5500' OR auart = '5700' OR auart = '8500'
                  OR auart = '8700' ) .

LOOP AT it_aufk.

  SELECT * FROM setleaf INTO TABLE it_setleaf
  WHERE setclass = '0103' AND
  setname = it_aufk-aufnr+6(6).
  SORT it_setleaf BY setname.

  LOOP AT it_setleaf.
    CONCATENATE 'OR' it_setleaf-valfrom INTO objnr.

    SELECT * FROM coss INTO TABLE it_coss WHERE
    objnr = objnr AND
    gjahr = p_gjahr AND
    versn = p1_versn AND
    wrttp = '01'.
    LOOP AT it_coss.
      it_group-p1 = it_coss-wkg001.
      it_group-p2 = it_coss-wkg002.
      it_group-p3 = it_coss-wkg003.
      it_group-p4 = it_coss-wkg004.
      it_group-p5 = it_coss-wkg005.
      it_group-p6 = it_coss-wkg006.
      it_group-p7 = it_coss-wkg007.
      it_group-p8 = it_coss-wkg008.
      it_group-p9 = it_coss-wkg009.
      it_group-p10 = it_coss-wkg010.
      it_group-p11 = it_coss-wkg011.
      it_group-p12 = it_coss-wkg012.

      READ TABLE it_setleaf WITH KEY
        setname = it_coss-objnr+8(6)
        BINARY SEARCH.
      CHECK sy-subrc = 0.
      it_group-group = it_setleaf-setname.

      COLLECT it_group.
      CLEAR it_group.
      WRITE: / it_group-p1 ,it_group-p2.
    ENDLOOP.
  ENDLOOP.
ENDLOOP.

Rob

Message was edited by: Rob Burbank