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

Adding fields

Former Member
0 Likes
1,175

Hi,

i'm having trouble adding the quantity of fields that have the same MATNR and INVTY...Can anyone help me please!

here is my code:

SELECT MATNR LABST UMLME INSME EINME SPEME RETME LGORT

INTO TABLE T_MARD FROM MARD

FOR ALL ENTRIES IN IT_MATNR_TEMP

WHERE MATNR = IT_MATNR_TEMP-MATNR

AND WERKS = '0111'

AND LGORT IN LS_LGORT.

LOOP AT T_MARD.

IF T_MARD-LGORT = '0345'.

IT_MATNR_TEMP-INVTY = '02'.

L_MATNR_QUANT_02 = ( T_MARD-LABST + T_MARD-UMLME + T_MARD-INSME +

T_MARD-EINME + T_MARD-SPEME + T_MARD-RETME )

+ L_MATNR_QUANT_02.

MOVE L_MATNR_QUANT_02 TO IT_MATNR_TEMP-QUANT.

MOVE-CORRESPONDING IT_MATNR_TEMP TO IT_MATNR.

APPEND IT_MATNR.

ELSEIF T_MARD-LGORT = '0340'.

IT_MATNR_TEMP-INVTY = '04'.

L_MATNR_QUANT_04 = ( T_MARD-LABST + T_MARD-UMLME + T_MARD-INSME +

T_MARD-EINME + T_MARD-SPEME + T_MARD-RETME )

+ L_MATNR_QUANT_04.

MOVE L_MATNR_QUANT_04 TO IT_MATNR_TEMP-QUANT.

MOVE-CORRESPONDING IT_MATNR_TEMP TO IT_MATNR.

APPEND IT_MATNR.

ENDIF.

ENDLOOP.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,139

Melissa,

I think COLLECT Stmt would do the thing.

See the follwoing link:

http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb36d5358411d1829f0000e829fbfe/frameset.htm

<b> Instead of APPEND stmt, Use COLLECT.

COLLECT waIT_MATNR into IT_MATNR. </b>

Thanks

Kam

Note: Allot points for all worthful postings

Message was edited by: Kam

11 REPLIES 11
Read only

Former Member
0 Likes
1,139

What is the structure of your internal table IT_MATNR? See if you can use COLLECT statement.

Read only

0 Likes
1,139

Is this whole code in the loop of IT_MATNR_TEMP?

Read only

0 Likes
1,139

i tried it, it doesnt work...

Read only

0 Likes
1,139

Can you give us the whole code starting with the loop of IT_MATNR_TEMP and also the structure of these tables?

Srinivas

Read only

Former Member
0 Likes
1,139

Hi,

Instead of APPEND use COLLECT to summarize the quantity based on Material and Inventory type.

Thanks

Giridhar

Read only

0 Likes
1,139

where would i put COLLECT?

Read only

Former Member
0 Likes
1,140

Melissa,

I think COLLECT Stmt would do the thing.

See the follwoing link:

http://help.sap.com/saphelp_47x200/helpdata/en/fc/eb36d5358411d1829f0000e829fbfe/frameset.htm

<b> Instead of APPEND stmt, Use COLLECT.

COLLECT waIT_MATNR into IT_MATNR. </b>

Thanks

Kam

Note: Allot points for all worthful postings

Message was edited by: Kam

Read only

Former Member
0 Likes
1,139

I think you want to add quantities for every matnr and lgort, if so then use COLLECT instead of APPEND. Collect will sum up all the quantities fields so that it will get what you want.

Read only

0 Likes
1,139

I see that you are adding all the different inventories only if the storage location is 0345 or 0340 and type 02 or 04. What happens for all other cases?

Srinivas

Read only

0 Likes
1,139

Here is the modified code.


SELECT matnr labst umlme insme
       einme speme retme lgort INTO TABLE t_mard
                               FROM mard
                 FOR ALL ENTRIES IN it_matnr_temp
                              WHERE matnr = it_matnr_temp-matnr
                                AND werks = '0111'
                                AND lgort IN ls_lgort.
LOOP AT it_matnr_temp.
  LOOP AT t_mard WHERE matnr = it_matnr_temp-matnr.

    IF t_mard-lgort        = '0345' AND
       it_matnr_temp-invty = '02'.
      CLEAR l_matnr_quant_02.
      l_matnr_quant_02 = t_mard-labst + t_mard-umlme + t_mard-insme +
                         t_mard-einme + t_mard-speme + t_mard-retme.
      MOVE-CORRESPONDING it_matnr_temp TO it_matnr.
      MOVE l_matnr_quant_02 TO it_matnr_temp-quant.

      colelct it_matnr.
      CLEAR it_matnr.
    ELSEIF t_mard-lgort        = '0340' AND
           it_matnr_temp-invty = '04'.
      CLEAR l_matnr_quant_04.
      l_matnr_quant_04 = t_mard-labst + t_mard-umlme + t_mard-insme +
                         t_mard-einme + t_mard-speme + t_mard-retme.
      MOVE-CORRESPONDING it_matnr_temp TO it_matnr.
      MOVE l_matnr_quant_04 TO it_matnr_temp-quant.
      COLLECT it_matnr.
      CLEAR it_matnr.
    ENDIF.
  ENDLOOP.
ENDLOOP.

Read only

Former Member
0 Likes
1,139

Melissa,

If you say the collect is not working, then check how you defined the quantity field in IT_MATNR table. For the collect statement to work the quantity field needs to a numeric data type field not a character data type field. Also make sure that you didn't have any other numeric fields in your internal table IT_MATNR, otherwise they will also get summed up.

Thanks

Giridhar

Message was edited by: Giridhar Nayudu