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

multiple records into single record

Former Member
0 Likes
2,249

Hi all ,

Iam getting multiple record in an internal table .i want validate material number and country if both are same i want make it as single record.

now iam getting multiple records in itab1 like this .

matnr,country,event,stdt,eddt

a1 , us , ga, 01/01/2006,01,01/01/2006

a1,us,pa,02/02/2006,02/02/2006

i want make it as in itab2 i want compare material number and country code

and i have to send some other events aslo

a1,us,ga,01/01/2006,01/01/2006,pa,02/02/2006,02/02/2006,ga, , , es, , ,

can any guide me how to do this?

Hi all ,

Iam getting multiple record in an internal table .i want validate material number and country if both are same i want make it as single record.

now iam getting multiple records in itab1 like this .

matnr,country,event,stdt,eddt

a1 , us , ga, 01/01/2006,01,01/01/2006

a1,us,pa,02/02/2006,02/02/2006

i want make it as in itab2 i want compare material number and country code

and i have to send some other events aslo

a1,us,ga,01/01/2006,01/01/2006,pa,02/02/2006,02/02/2006,ga, , , es, , ,

can any guide me how to do this?

13 REPLIES 13
Read only

Former Member
0 Likes
1,825

SORT itab1 BY matnr land1 ASCENDING..

DELETE ADJACENT DUPLICATES FROM itab1 COMPARING matnr land1.

Read only

0 Likes
1,825

Alex,

i dont want to delte multiple records . I want to make it as single record with material number and country code validation.

Read only

0 Likes
1,825

Hi Priya,

sort the itab by material....loop over the itab...then keep appening the values you want into a string and do the append to the 2nd table when the material changed.

Use the control statement AT END of <field> to achieve this...

Thanks.

Read only

Former Member
0 Likes
1,825

Hi,

Do you want the internal table itab2 to be a structured internal table...OR it can be just a string internal table..

THanks,

Naren

Read only

0 Likes
1,825

My requirement is i am getting data in itab1 in multiple records (with 10 fields).

iam sending this data to iab2 with some manipulation ( with 20 fields ) here also i have multiple records . Finally i have compare material number and country from itab2 and need to send as single record into file .

Read only

Former Member
0 Likes
1,825

Hi,

Which means..In the internal table itab1 you will always have only 2 records for the same material and country..

Meaning in the internal table itab1 you will not have a third record..Lets say

a1 , us , ga, 01/01/2006,01,01/01/2006

a1,us,pa,02/02/2006,02/02/2006

<b>a1,us,pa,02/03/2006,02/03/2006</b>

Thanks,

Naren

Read only

0 Likes
1,825

It depends some times i will have 2 records and some times i will have single record.

Read only

0 Likes
1,825

Hi,

I dont understand what problem you are facing:

matnr,country,event,stdt,eddt

a1 , us , ga, 01/01/2006,01,01/01/2006

a1,us,pa,02/02/2006,02/02/2006

First sort the internal table.

Sort itab1 by matnr ascending country ascending.

delete adjacent duplicates from itab1 comparing matnr country.

This should work.

Regards

Subramanian

Read only

0 Likes
1,825

yes, what u said is correct some times i will have 2 records and some times i will have single record.

That is the reason we checking count.

if it has multiple records it goes into the loop and concatenates.

if it has single record it remains simply like that.

Read only

Former Member
0 Likes
1,825

Hi Priya,

What u have to do is first u

Sort itab by material number and country.

loop at itab INTO W_ITAB.

count = 0.

itab_dup[] = itab[].

loop at itab_dup INTO W_ITAB_DUP where BANFN eq W_itab-BANFN.

count = count + 1.

append W_itab_dup to itab_result.

endloop.

if count > 1.

loop at itab_result INTO W_ITAB_RESULT where matnr = itab-matnr

and country = itab-country.

concatenate W_ITAB W_ITAB_RESULT into some headerline or Workarea.

endloop.

endif.

CLEAR W_ITAB_RESULT.

refresh itab_result.

endloop.

the above logic collects all duplicate entries in one duplicate table. And the first internal table compares with duplicate internal table, if it exists duplicate records it concatenates.

I think this helps u.

if u get any doubts let me know.

if it helps award points.

Thanks,

Rani

Read only

Former Member
0 Likes
1,825

Hi,

So maximum of two records..Correct??

Thanks,

Naren

Read only

0 Likes
1,825

yes

Read only

Former Member
0 Likes
1,825

Hi,

Okay try this..

In the internal table ITAB2 have the same set of fields twice in your internal table ending with 1(marked in bold)..

Like..

DATA: BEGIN OF ITAB2 OCCURS 0,

MATNR TYPE MATNR,

COUNTRY TYPE LAND1,

EVENT,

STDT TYPE SYDATUM,

EDDT TYPE SYDATUM,

<b> EVENT1,

STDT1 TYPE SYDATUM,

EDDT1 TYPE SYDATUM,</b>

END OF ITAB2.

DATA: LV_FOUND TYPE XFELD.

DATA: WA LIKE ITAB1.

SORT ITAB1 BY MATNR COUNTRY.

**Make sure in the internal table ITAB1 declaration..The first field is MATNR and

**the second field is country.

LOOP AT ITAB1.

WA = ITAB1.

AT NEW COUNTRY.

    • Populate the internal table ITAB2.

ITAB2-MATNR = WA-MATNR.

ITAB2-COUNTRY = WA-COUNTRY.

ITAB2-EVENT = ITAB1-EVENT.

ITAB2-STDT = ITAB1-STDT.

ITAB2-ETDT = ITAB1-ETDT.

LV_FOUND = 'X'.

ENDAT.

AT END OF COUNTRY.

IF LV_FOUND IS INITIAL.

**This means the second time.

ITAB2-EVENT1 = ITAB1-EVENT.

ITAB2-STDT1 = ITAB1-STDT.

ITAB2-ETDT1 = ITAB1-ETDT.

ENDIF.

APPEND ITAB2.

CLEAR ITAB2.

ENDAT.

CLEAR: LV_COUNTRY.

ENDLOOP.

Hope this works..

Thanks,

Naren