Application Development 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: 

Event in for Dyanmic Internal Table in

former_member375795
Participant
0 Kudos
174

Please tell me

Can you tell how to put event at end of in loop of Dynamic internal Table

Loop at <internal table > assigning <work area>

at end < how to give field name  please write it here >

end at

endloop .

22 REPLIES 22

arivazhagan_sivasamy
Active Contributor
0 Kudos
90

Hi Alok,

Please write a code below and check.

Loop at <internal table > assigning <work area>

at end internal table fieldname.

For Eg:- at end of carrid.

end at

endloop .

Arivazhagan  S

0 Kudos
90

I am not able to give field name from dyanmic Internal Table like Carrid .

Loop at <internal table > assigning <work area>

at end internal table fieldname.

For Eg:- at end of carrid( How to give that field name from Dynamic Internal Table).

end at

endloop .

0 Kudos
90

Hi Alok,

   I think it will be helpful to you..

  First you declare a variable with the type carrid & assign <work area> field to it as shown below.

   data : l_carrid type sflight-carrid.

  loop at <internal table> assigning <work area>

    assign component 'CARRID' of structure <work area> to l_carrid.

     at end of l_carrid.

    endat.

  endloop.

Be careful when you clear assigned variable l_carrid .

Thanks,

Raghu

0 Kudos
90

Field not define error and sum  and You cannot use the "SUM" statement inside "LOOP ... ASSIGNING ...". error

0 Kudos
90

Hi Alok,

   Can i have the Code what you exactly written.

Thanks

Raghu

0 Kudos
90

yes ,

LOOP AT <gfs_dyn_table> INTO <gfs_line>.
INDEX  = 1 .
ASSIGN COMPONENT INDEX OF STRUCTURE <GFS_LINE> TO <gfs_line>.
AT END OF <FS1>.
SUM.
ENDAT.
ENDLOOP.

0 Kudos
90

field-symbols : <f1> type any.

  data : l_carrid type sflight-carrid.

LOOP AT <gfs_dyn_table> INTO <gfs_line>.

ASSIGN COMPONENT 'CARRID' OF STRUCTURE <GFS_LINE> TO <F1>.

l_carrid = <f1>.

AT END OF l_carrid.

SUM.

ENDAT.

ENDLOOP.

Yes, We can not use Sum in dynamic Internal Table. Instead u can take one more Field symbol like line of <gfs_dyn_table>, add into it every time.

Hope, it works for u.

Thanks,

Raghu


0 Kudos
90

It not work .

former_member184569
Active Contributor
0 Kudos
90

at end < how to give field name  please write it here >

Do you know the name of the field to be used here for the at end statement?

0 Kudos
90

yes

I now the field  name  . i throw error that is sum not working in Assigning

0 Kudos
90

At end 'field' is not working (or) sum is not working.

You want Sum at the end of that field carrid ?

0 Kudos
90

YES I WANT SUM

0 Kudos
90

Madam I don't how to give field name

at end of event so that's why I ask you  please sort out that issue

0 Kudos
90

If you know the name of the column then just add it to the sort table, and pass it your ALV.

Former Member
0 Kudos
90

Hi Alok,

for this dyn table, you will be storing the field names some where right.

lets say lv_field contains the field name.

try this  <wa>-(lv_field).

Thanks and Regards,

bhaskar

former_member220538
Active Participant
0 Kudos
90

Hi Alok,

You cannot use the sum statement inside an assigning loop.Since it is an dynamic internal table you have to use assign component and add the fields to a variable.

LOOP AT <itab> ASSIGNING <wa>.

  ASSIGN COMPONENT  '<field>' OF STRUCTURE <wa> TO <comp>.

  IF sy-subrc EQ 0.

    ADD <comp> TO  total.

  ENDIF.

ENDLOOP.

Regards,

Jeffin

0 Kudos
90

Do you want sub totals in Grid Display  ?

0 Kudos
90

YES SIR .

0 Kudos
90

   K fine.. Fallow as shown below.

  If you want Sub total at the end of carrid, fill fieldcat for carrid as shown below.

   If you use lvc type fieldcat.

   CLEAR gw_fieldcat.

   gw_fieldcat-fieldname = 'CARRID'.

   gw_fieldcat-tabname   = 'ITAB'.

   gw_fieldcat-seltext_l = 'Airline Code'.

   gw_fieldcat-col_pos   = 1.   -------> as in your report column

   gw_fieldcat-outputlen = 7.

    gw_fieldcat-do_sum   =  'X'.

   APPEND gw_alv_fieldcat TO gt_alv_fieldcat.

   fill sort internal table

   lt_Sort type lvc_t_sort.

    wa_sort type lvc_s_sort.

    CLEAR WA_SORT.

    WA_SORT-FIELDNAME = 'CARRID'.

    WA_SORT-UP        = 'X'.

    WA_SORT-SUBTOT    = 'X'.

    APPEND WA_SORT TO LT_SORT.

   Use reuse_alv_grid_display_lvc.

    pass sort Internal table to it

   as         IT_SORT_LVC              = LT_SORT..

   Remove at the end of Code..

0 Kudos
90

Hi,

Create an internal table of type LVC_T_FCAT and mark the option do_sum as 'X'  and      LVC_T_SORT and mark the option subtot as 'X' for the field you required. and pass these internal tables to the  method SET_TABLE_FOR_FIRST_DISPLAY.

Please refer this link

http://wiki.scn.sap.com/wiki/display/ABAP/SUBTOTAL+in+ALV

0 Kudos
90

Hi Alok,

      Is it working for You.. ?

Sudhakargadde
Participant
0 Kudos
90

Hello Alok,

Please try below code, but you try to sum the value that is stored inside the field symbol but it is working like a pointer(it points the address) then in mean time the loop comes in to picture the address is over write with current record value so that is the reason SAP Doesn't support for the field symbol summation in LOOP. please find the below program it helps you let me know.

REPORT  ZFIELD_SYMBOL.

types :

   BEGIN OF ty_vbap,

     vbeln TYPE vbeln_va,

     posnr TYPE posnr_Va,

     netwr TYPE netwr_ap,

   END OF ty_vbap,

   ty_tbl_vbap TYPE STANDARD TABLE OF ty_vbap.

data :

   gt_vbap  TYPE ty_tbl_vbap,

   gs_vbap  TYPE ty_vbap,

   gv_netwr TYPE netwr_ap.

FIELD-SYMBOLS:

              <ft_vbap> TYPE ty_tbl_vbap,

              <fs_vbap> TYPE ty_vbap.

SELECT-OPTIONS :

   so_vbeln for <fs_vbap>-vbeln OBLIGATORY.",

*  sd_vbeln FOR gs_vbap-vbeln.

START-OF-SELECTION.

SELECT vbeln posnr netwr

   INTO TABLE gt_vbap

   FROM vbap

  WHERE vbeln in so_vbeln.

end-of-SELECTION.

ASSIGN gt_vbap to <ft_vbap>.

   WRITE :/ 'Sales Dno'(010), 'Item No'(006), 'Amount'."<fs_vbap>-zwert.

loop at <ft_vbap> ASSIGNING <fs_vbap>.

   WRITE :/ <fs_vbap>-vbeln(010), <FS_VBAP>-POSNR(6), <fs_vbap>-netwr.

   gv_netwr = <fs_vbap>-netwr + gv_netwr.

  at END of vbeln.

    WRITE:/'*************************************', gv_netwr.

    CLEAR gv_netwr.

ENDAT.

   ENDLOOP.

Regards

Sudhakar