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 problem.........

Former Member
0 Likes
3,573

HI,

when I use  collect statement ,the interlnal table add an extra row ...:

I want only 16 in fking not 8

                                          8

                                         16

1 ACCEPTED SOLUTION
Read only

philipdavy
Contributor
0 Likes
3,396

Share your code please.

20 REPLIES 20
Read only

philipdavy
Contributor
0 Likes
3,397

Share your code please.

Read only

0 Likes
3,396

select

      zprs_role

      fkimg

      vbeln

    ZPRS_OFFSHORE

      ps_psp_pnr

      arktx

      posnr

      netwr

      from vbrp into corresponding fields of table it_tab

       where vbeln = wa_vbrk-vbeln.

loop at it_role into wa_role.

    collect wa_role into it_tab.

*    read table it_tab into wa_tab index sy-index.

    endloop.

ypes: begin of ty_tab,



       zprs_role type vbrp-zprs_role,

       fkimg type vbrp-fkimg,

      fkdat type vbrk-fkdat,

      knumv type vbrk-knumv,

      kawrt type konv-kawrt,

     ZPRS_OFFSHORE type vbrp-ZPRS_OFFSHORE,

      ps_psp_pnr type vbrp-ps_psp_pnr,

      post1 type prps-post1,

      arktx type vbrp-arktx,

      posnr type vbrp-posnr,

      netwr type vbrp-netwr,

      vbeln type vbrp-vbeln,



      end of ty_tab.

Read only

0 Likes
3,396

elect

      zprs_role

      fkimg

      vbeln

    ZPRS_OFFSHORE

      ps_psp_pnr

      arktx

      posnr

      netwr

      from vbrp into corresponding fields of table it_tab

       where vbeln = wa_vbrk-vbeln. 

loop at it_role into wa_role.

    collect wa_role into it_tab.

*    read table it_tab into wa_tab index sy-index.

    endloop.

delete it_itab where    zprs_role = ''

Read only

0 Likes
3,396

I cant make zprs_role = any hard coded value

Read only

0 Likes
3,396
  •   Please note that while using the collect statement that non-key fields must be numeric and key fields must be of type character type (C,N, etc).

  • Create one more internal table with the same internal table type as that of it_role. (say it_role1 and work area wa_role1).

        loop at it_role into wa_role.

       Move-corresponding wa_role to wa_role1.

       collect wa_role1 to it_role1.

       endloop.

Philip.

Read only

0 Likes
3,396

1. You are using the same table to retrieve the data using select statement and in the collect statement

The first two records are retrieved from the select statement, it is not coming from the collect statement. Its only the last record that is coming from the collect statement. So the collect statement is working fine, resulting in just one record having the total 16.

2.  When using collect statement, the structure of it_role and the table you are collecting to must be same.

TYPES: BEGIN OF t_collect,
      
        zprs_role type vbrp-zprs_role,
            fkimg TYPE vbrp-fkimg,
    END OF t_collect.

DATA: it_roles TYPE STANDARD TABLE OF t_collect, wa_roles type t_collect.
data : it_collect type TABLE OF t_collect.


loop at it_itab into wa_itab.
    move-corresponding wa_itab to wa_roles.
    APPEND wa_roles to it_roles.
  endloop.


sort it_roles by
zprs_role.

loop at it_roles into wa_roles.

    collect wa_roles into it_collect.

endloop.

Read only

0 Likes
3,396

Use separate tables for select statement and collect statement..

Read only

0 Likes
3,396

Hi,

If your requirement is to delete the duplicate entries you can go for this,

DELETE ADJACENT DUPLICATES FROM it_itab COMPARING zprs_role fkimg.

Regards,

Anoop




Read only

0 Likes
3,396

OK Susmitha......I got it.........now   ZPRS_OFFSHORE value is 0 and 1...but instade of 0 and 1 ihave to display domain fixed vale OFF and ON

Read only

0 Likes
3,396

To get the domain, use the following FM.

DATA :it_taba TYPE STANDARD TABLE OF dd07v WITH HEADER LINE,
it_tabb TYPE STANDARD TABLE OF dd07v.


CLEAR :it_taba, it_tabb.
     CALL FUNCTION 'DD_DOMA_GET'
       EXPORTING
         domain_name   = 'ZECAT'  " Domain name of ZPRS_Offshore
         langu         = sy-langu
         withtext      = 'X'
       TABLES
         dd07v_tab_a   = it_taba
         dd07v_tab_n   = it_tabb
       EXCEPTIONS
         illegal_value = 1
         op_failure    = 2
         OTHERS        = 3.

" Pass the value for the field, you will get the domain value description in it_taba-DOMVALUE_L

     READ TABLE it_taba WITH KEY VALPOS = wa_itab-zprs_offshore.

Read only

0 Likes
3,396

hi,

my code is

R :it_taba, it_tabb.

     CALL FUNCTION 'DD_DOMA_GET'

       EXPORTING

         domain_name   = 'Z_PRS_Offshore'  " Domain name of ZPRS_Offshore

         langu         = sy-langu

         withtext      = 'X'

       TABLES

         dd07v_tab_a   = it_taba

         dd07v_tab_n   = it_tabb

       EXCEPTIONS

         illegal_value = 1

         op_failure    = 2

         OTHERS        = 3.

READ TABLE it_taba into wa_taba WITH KEY VALPOS = wa_tab-zprs_offshore

but finally I have to display under loop  it_tab into wa_tab in smartforms table?

Read only

0 Likes
3,396

You have two options, either add a zprs_offshore description field (Character field withe required length) in ty_tab. And modify the table to update the table it_itab.

types: begin of ty_tab.

...

...

..

offsh_desc type char10 ,

...

end of ty_tab.

lv_ofsdesc type char10.

loop at it_itab into wa_itab.

" Use the above code to get the description in lv_ofsdesc = it_taba-domvalue_l.

   perform get_domain.  

   wa_itab-offsh_desc = lv_ofsdesc.

  modify it_itab from wa_itab index sy-tabix transport offsh_desc.

endloop.

Now you can use the field wa_itab-offsh_desc in your smartform.

Another option would be to call the above FM within the loop in the smartform. And providing the variable having the output in the smartform.

Btw, if there are only two values for zprs_offshore, you could just manually fill the offsh_desc field without calling the FM.

if wa_itab-zprs_offshore = '1'.

   wa_itab-offsh_desc = 'ON'.

else.

     wa_itab-offsh_desc = 'OFF'.

endif.

modify table it_itab from wa_itab index sy-tabix transporting offsh_desc.

Read only

0 Likes
3,396

thanks susmita its done.......

Read only

nabheetscn
SAP Champion
SAP Champion
0 Likes
3,396

Please check your internal table on which you are making this Collect. After collect you can delete IT_ITAB where ZPRS_ROLE = ''.

Nabheet

Read only

venkat_aileni
Contributor
0 Likes
3,396

Collect statement will sum up all the numeric values only when all the character values are equal. In your case value of  'ZPRS_OFFSHORE' value differs for both lines hence you are getting a new line.

-Venkat

Read only

0 Likes
3,396

hi venkat,

yes here zprs_offshore value is diff.......then how can I add the fkimg and netwr and display only addition value in smartforms?

Read only

0 Likes
3,396

Hi-

If you have got nothing to do with that value before collect statement clear that particular field value and please use separate table for collect statement.

-Venkat

Read only

Former Member
0 Likes
3,396

Why dont you take vbeln posnr as your key fields in internal table.

Regards

Vivek

Read only

0 Likes
3,396

hi vivek ,

I alrady take vbeln as key field in internal table..

Read only

former_member209120
Active Contributor
0 Likes
3,396

Hi

Try like this

Types : begin of ty_final,
         a type string,
         b type p LENGTH 7 DECIMALS 3,
         end of ty_final.



data : it_final type TABLE OF ty_final,
        it_final1 type TABLE OF ty_final,
        wa_final type ty_final.


wa_final-a = 'SAP CONSULTANT'.
wa_final-B = '8.000'.
APPEND WA_FINAL TO IT_FINAL.
CLEAR WA_FINAL.

wa_final-a = 'SAP CONSULTANT'.
wa_final-B = '8.000'.
APPEND WA_FINAL TO IT_FINAL.
CLEAR WA_FINAL.


Loop at it_final into wa_final.

collect wa_final into it_final1.

endloop.


Loop at it_final1 into wa_final.
Write :/ wa_final-a, wa_final-b.
endloop.