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

Regarding Internal Table Manipulation

Former Member
0 Likes
656

Hi All,

I have a issue in internal table manipilation.

The I.Table decalred as below:

DATA: BEGIN OF i_zzexgen OCCURS 0,

zzalnum LIKE zexport_class-zzalnum,

zzembgr LIKE zexport_class-zzembgr,

zzgennr LIKE zexport_class-zzgennr,

zzexgen LIKE zexport_class-zzexgen,

netwr LIKE vbap-netwr,

END OF i_zzexgen.

Now i am populating data into above internal table as below:

100 ABC 3100 B750 50.00

100 ABC 3100 B750 50.00

100 ABC 3100 B750 50.00

100 ABD 3200 B750 50.00

100 ABD 3200 B850 50.00

100 ABD 3300 B850 50.00

1. Now what i have to do is i need to store the entries where ZZALNUM, ZZEMBGR, ZZGENNR are common by summing up NETWR for the same.

For the above case i should get 3 rows for above combination with summing of NETWR.

2. Now again i need to store the entries where ZZEXGEN are common by summing up NETWR for the same.

For this case i should get 2 rows for above combination with summing of NETWR.

Can anybody give the resolution for the same.

Thanks in advance.

Thanks & Regards,

Prasad.

6 REPLIES 6
Read only

Former Member
0 Likes
608

Prasad,

If the first 3 fields are key fields then you can sum them up using 'Collect' statement else I think it is difficult.

Comming to 4th field you can sum netwr using the conditional statement available in SAP like

at end of field4/ at new etc.

Thanks,

Read only

Former Member
0 Likes
608

1.

sort i_zzexgen by zzalnum zzembgr zzgennr.

read i_zzexgen index 1.

temp_zzalnum = i_zzexgen-zzalnum.

temp_zzembgr = i_zzexgen-zzembgr.

temp_zzgennr = i_zzexgen-zzgennr.

loop at i_zzexgen.

if temp_zzalnum = i_zzexgen-zzalnum AND

temp_zzembgr = i_zzexgen-zzembgr AND

temp_zzgennr = i_zzexgen-zzgennr.

sum_netwr = sum_netwr + i_zzexgen_netwr.

endif.

endloop.

2.

You can follow the same way as above.

Bala

Note: Award points if helpful

Read only

Former Member
0 Likes
608

Sorry prasad..Small change in logic

1.

sort i_zzexgen by zzalnum zzembgr zzgennr.

read i_zzexgen index 1.

temp_zzalnum = i_zzexgen-zzalnum.

temp_zzembgr = i_zzexgen-zzembgr.

temp_zzgennr = i_zzexgen-zzgennr.

loop at i_zzexgen.

if temp_zzalnum = i_zzexgen-zzalnum AND

temp_zzembgr = i_zzexgen-zzembgr AND

temp_zzgennr = i_zzexgen-zzgennr.

sum_netwr = sum_netwr + i_zzexgen_netwr.

else.

temp_zzalnum = i_zzexgen-zzalnum.

temp_zzembgr = i_zzexgen-zzembgr.

temp_zzgennr = i_zzexgen-zzgennr.

endif.

endloop.

2.

You can follow the same way as above.

Read only

0 Likes
608

HI,

For 2nd condition i had written follow code is it correct!

LOOP AT i_vb_ex_ap.

v_netwr = v_netwr + i_vb_ex_ap-netwr.

AT END OF zzexgen.

MOVE i_vb_ex_ap1-posnr TO i_vb_ex_ap_header-posnr.

MOVE i_vb_ex_ap1-alnum TO i_vb_ex_ap_header-alnum.

MOVE i_vb_ex_ap1-embgr TO i_vb_ex_ap_header-embgr.

MOVE i_vb_ex_ap1-gennr TO i_vb_ex_ap_header-gennr.

MOVE i_vb_ex_ap1-zzexgen TO i_vb_ex_ap_header-zzexgen.

MOVE v_netwr TO i_vb_ex_ap_header-netwr.

APPEND i_vb_ex_ap_header.

CLEAR i_vb_ex_ap_header.

CLEAR v_netwr.

ENDAT.

CLEAR i_vb_ex_ap1.

REFRESH i_vb_ex_ap1.

MOVE-CORRESPONDING i_vb_ex_ap TO i_vb_ex_ap1.

APPEND i_vb_ex_ap1.

AT LAST.

MOVE i_vb_ex_ap1-posnr TO i_vb_ex_ap_header-posnr.

MOVE i_vb_ex_ap1-alnum TO i_vb_ex_ap_header-alnum.

MOVE i_vb_ex_ap1-embgr TO i_vb_ex_ap_header-embgr.

MOVE i_vb_ex_ap1-gennr TO i_vb_ex_ap_header-gennr.

MOVE i_vb_ex_ap1-zzexgen TO i_vb_ex_ap_header-zzexgen.

MOVE v_netwr TO i_vb_ex_ap_header-netwr.

APPEND i_vb_ex_ap_header.

CLEAR i_vb_ex_ap_header.

CLEAR i_vb_ex_ap1.

REFRESH i_vb_ex_ap1.

CLEAR v_netwr.

ENDAT.

ENDLOOP.

Thanks,

Prasad.

Read only

Former Member
0 Likes
608

You need two other internal tables.

First Internal table


DATA: BEGIN OF i_zzexgen1 OCCURS 0,
        zzalnum LIKE zexport_class-zzalnum,
        zzembgr LIKE zexport_class-zzembgr,
        zzgennr LIKE zexport_class-zzgennr,
        netwr LIKE vbap-netwr,
END OF i_zzexgen1.

Second Internal Table
DATA: BEGIN OF i_zzexgen2 OCCURS 0,
        zzexgen LIKE zexport_class-zzexgen,
        netwr LIKE vbap-netwr,
END OF i_zzexgen2.

Now your code will be
LOOP AT i_zzexgen.
  MOVE-CORRESPONDING i_zzexgen TO: i_zzexgen1,
                                   i_zzexgen2.
  COLLECT: i_zzexgen1, i_zzexgen2.
  CLEAR i_zzexgen1, i_zzexgen2.
ENDLOOP.

Read only

0 Likes
608

HI,

If i put all the fields of I_ZZEXGEN in I_ZZEXGEN1 & I_ZZEXGEN2 the above code will work.

As i need other fields for UPDATE statements after wards in code.

Thanks,

Prasad.