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

Sorting

Former Member
0 Likes
588

Hi There,

I have a structure of the format:

TYPES: BEGIN OF TY_OUTPUT, "Beging of TY_OUTPUT

VKORG TYPE LIKP-VKORG, "Sales Org

ERDAT TYPE LIKP-ERDAT, "Delivery Creation Date

LFDAT TYPE LIKP-LFDAT, "Delivery Date

KUNNR TYPE LIKP-KUNNR, "Customer Number

VBELN TYPE LIKP-VBELN, "Delivery Number

MATNR TYPE LIPS-MATNR, "Material Number

ARKTX TYPE LIPS-ARKTX, "Material Description

LFIMG TYPE LIPS-LFIMG, "Actual Quantity Delivered

VRKME TYPE LIPS-VRKME, "Sales Unit

NAME1 TYPE KNA1-NAME1, "Customer Name

INSPE TYPE TDLINE, "Inspection Number

HAULI TYPE TDLINE, "Haulier

CONTA TYPE TDLINE, "Container

END OF TY_OUTPUT. "End of TY_OUTPUT

It is sorted by VBELN and then by MATNR.

For each unique VBELN where MATNR occurs more than once I want to SUM the values of LFIMG and record only the first occurrence for each MATNR.

Can anyone provide me with an efficient way of doing this. I have one way coded but it looks very inefficient to me.

Thanks for your help,

Colm

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
559

Hi Colm,

Use control commands to meet your requirement.

DATA ITAB_FINAL TYPE STANDARD TABLE OF TY_OUTPUT WITH HEADER LINE.

DATA V_LFIMG TYPE LIPS-LFIMG.

SORT ITAB BY VBELN MATNR.

LOOP AT ITAB.

V_LFIMG = V_LFIMG + ITAB-LFIMG.

AT END OF MATNR.

READ TABLE ITAB INDEX SY-TABIX.

IF SY-SUBRC = 0.

MOVE-CORRESPONDING ITAB TO ITAB_FINAL.

ITAB_FINAL-LFIMG = V_LFIMG.

APPEND ITAB_FINAL.

CLEAR ITAB_FINAL.

CLEAR V_LFIMG.

ENDIF.

ENDAT.

ENDLOOP.

Thanks,

Vinay

5 REPLIES 5
Read only

Former Member
0 Likes
559

You can try this



* Declare like this
TYPES: BEGIN OF ty_output, "Beging of TY_OUTPUT
vbeln TYPE likp-vbeln, "Delivery Number
matnr TYPE lips-matnr, "Material Number
vkorg TYPE likp-vkorg, "Sales Org
erdat TYPE likp-erdat, "Delivery Creation Date
lfdat TYPE likp-lfdat, "Delivery Date
kunnr TYPE likp-kunnr, "Customer Number
arktx TYPE lips-arktx, "Material Description
lfimg TYPE lips-lfimg, "Actual Quantity Delivered
vrkme TYPE lips-vrkme, "Sales Unit
name1 TYPE kna1-name1, "Customer Name
inspe TYPE tdline, "Inspection Number
hauli TYPE tdline, "Haulier
conta TYPE tdline, "Container
END OF ty_output. "End of TY_OUTPUT


SORT i_tab BY vbeln matnr.

LOOP AT i_tab INTO w_tab.

  w_temp = w_tab.

  AT END OF matnr.
    SUM.
    w_temp-lfimg = w_tab-lfimg.
    APPEND w_temp TO i_new_tab.
  ENDAT.

ENDLOOP.

Regards

Kathirvel

Read only

Former Member
0 Likes
559

Move the three fields to another table and collect the values.

Rob

Read only

Former Member
0 Likes
560

Hi Colm,

Use control commands to meet your requirement.

DATA ITAB_FINAL TYPE STANDARD TABLE OF TY_OUTPUT WITH HEADER LINE.

DATA V_LFIMG TYPE LIPS-LFIMG.

SORT ITAB BY VBELN MATNR.

LOOP AT ITAB.

V_LFIMG = V_LFIMG + ITAB-LFIMG.

AT END OF MATNR.

READ TABLE ITAB INDEX SY-TABIX.

IF SY-SUBRC = 0.

MOVE-CORRESPONDING ITAB TO ITAB_FINAL.

ITAB_FINAL-LFIMG = V_LFIMG.

APPEND ITAB_FINAL.

CLEAR ITAB_FINAL.

CLEAR V_LFIMG.

ENDIF.

ENDAT.

ENDLOOP.

Thanks,

Vinay

Read only

0 Likes
559

Thanks Vinay,

That worked perfectly.

Read only

Former Member
0 Likes
559

didnt give the right points