cancel
Showing results for 
Search instead for 
Did you mean: 

sorting the fieldgroup

Former Member
0 Kudos

hi,

i have fieldgroup like,

data: begin of itab,

f1 type i,

f2 type i,

f3 type i,

f4 type i,

.........,

.........,

.........,

f99 type i,

f100 type i,

end of itab.

i want to sort the fieldgroup in ascending order.

how to do this?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi suresh,

yes it is a fieldstring.

i have a 100 fields on that, and i want to know the max value and min value from those fields.

give me a small example taking fieldstring with 5 or 6 values.

thank u,

prashanth

suresh_datti
Active Contributor
0 Kudos

Hi Prashanth,

Unfortunately, there si no SORT command for a field string.. You have to compare each field to the other.. here is sample code that you can use..


*&---------------------------------------------------------------------*
*& Report  ZINC12                                                      *
*&                                                                     *
*&---------------------------------------------------------------------*
*&                                                                     *
*&                                                                     *
*&---------------------------------------------------------------------*

report  zinc12.

data: begin of itab,
fld1 type i,
fld2 type i,
fld3 type i,
fld4 type i,
fld5 type i,
end of itab.
data: w_max type i,w_min type i.
data: begin of  itab1 occurs 5,
      fld type i,
      end of itab1.
data: begin of rec,
      fld type i,
      end of rec.
itab-fld1 = '32'.
itab-fld2 = '65'.
itab-fld3 = '11'.
itab-fld4 = '22'.
itab-fld5 = '10'.

do 5 times varying rec-fld from itab-fld1 next itab-fld2.
  itab1-fld = rec-fld.
  append itab1.
  clear itab1.
enddo.

sort itab1 by fld ascending.
read table itab1 index 1.
if sy-subrc eq 0.
  w_min = itab1-fld.
endif.
sort itab1 by fld descending.
read table itab1 index 1.
if sy-subrc eq 0.
  w_max = itab1-fld.
endif.

write:/ 'Max:',w_max,'Min:',w_min.

Regards,

Suresh Datti

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Prasanth,

Ru looking for a Field group example or field symbol example?

Field Group : A field group combines several existing fields together under one name. You use the INSERT statement to determine which fields belong to a field group at runtime.

Field Symbol : At runtime, you can assign a concrete field to the field symbol using ASSIGN. All operations performed with the field symbol then directly affect the field assigned to it.

You will get the example for both in ABABDOCU.

Please find the sample code for Field group .

DATA: ONR(7) TYPE C,

DATE TYPE D,

POSITION(3) TYPE N,

CUSTOMER(16) TYPE C,

PNR(5) TYPE N,

NAME(10) TYPE C,

UNITS TYPE I,

ORDERS TYPE I.

FIELD-GROUPS:

HEADER, ORDER, PRODUCT, DATE_FIRST.

INSERT ONR DATE POSITION INTO HEADER.

INSERT CUSTOMER INTO ORDER.

INSERT PNR NAME UNITS INTO PRODUCT.

INSERT DATE ONR POSITION INTO DATE_FIRST.

ONR = 'GF00012'. DATE = '19921224'.

POSITION = '000'. CUSTOMER = 'Good friend (2.)'.

EXTRACT ORDER.

ADD 1 TO POSITION.

PNR = '12345'. NAME = 'Screw'. UNITS = 100.

EXTRACT PRODUCT.

ADD 1 TO POSITION.

PNR = '23456'. NAME = 'Nail'. UNITS = 200.

EXTRACT PRODUCT.

ONR = 'MM00034'. DATE = '19920401'.

POSITION = '000'. CUSTOMER = 'Moneymaker'.

EXTRACT ORDER.

ADD 1 TO POSITION.

PNR = '23456'. NAME = 'Nail'. UNITS = 300.

EXTRACT PRODUCT.

ADD 1 TO POSITION.

PNR = '34567'. NAME = 'Hammer'. UNITS = 4.

EXTRACT PRODUCT.

ONR = 'GF00011'. DATE = '19921224'.

POSITION = '000'. CUSTOMER = 'Good friend (1.)'.

EXTRACT ORDER.

ADD 1 TO POSITION.

PNR = '34567'. NAME = 'Hammer'. UNITS = 5.

EXTRACT PRODUCT.

SORT BY DATE_FIRST.

LOOP.

AT ORDER.

WRITE: /, / DATE, ONR, POSITION,

CUSTOMER, 'ordered:'.

ENDAT.

AT PRODUCT.

WRITE: / DATE, ONR, POSITION,

PNR, NAME, UNITS.

ENDAT.

ENDLOOP.

Cheers

Sunny

If Helpful , Pls rewrd points

suresh_datti
Active Contributor
0 Kudos

It looks what you have is a field string & not a

FIELD-GROUP.

You can use the SORT command on FIELD_GROUPS similar to how you use them on an internal table.

FIELD-GROUPS ORDER.

INSERT field1 feild2 into ORDER.

....

EXTRACT ORDER

SORT by field1 field2 ascending.

Regards,

Suresh Datti