Skip to Content
avatar image
Former Member

MATNR Count

Hi All,

My internal table has 7 material numbers, ITAB-MATNR1 to ITAB-MATNR7. I have to count(mcnt) the number of MATNR which are not initial. Can some one please help me how to count this.

If 2 MATNR has value then MCNT should be 2, if 4 of them has value then MCNT should be 4.

I will really appriciate your help.

Thanks,

Veni.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • avatar image
    Former Member
    Sep 17, 2008 at 05:33 PM

    Hi,

    Try this code..

    FIELD-SYMBOLS: <FS>.
    DATA: V_COUNT TYPE CHAR5.
    DATA: V_FIELD   TYPE CHAR30.
    DATA: V_MCNT   TYPE INT4.
    
    LOOP AT ITAB INTO WA.
    
    * Clear.
      CLEAR: v_mcnt.
    
      DO 7 TIMES.
    
        V_COUNT = SY-INDEX.
        CONCATENATE 'MATNR' V_COUNT INTO V_FIELD.
        CONDENSE V_FIELD.
    
        ASSIGN COMPONENT V_FIELD OF STRUCTURE WA TO <FS>.
    
        IF SY-SUBRC = 0.
    
           IF NOT <FS> IS INITIAL.
    
    * Incremement the counter if it has some value.
              V_MCNT = V_MCNT + 1.
    
           ENDIF.
    
        ENDIF.
    
      ENDDO.
    
    * Modify the internal table based on the count.
      WA-MCNT = V_MCNT.
      MODIFY ITAB FROM WA.
    
    ENDLOOP.

    Thanks

    Naren

    Add comment
    10|10000 characters needed characters exceeded

  • Sep 17, 2008 at 05:43 PM

    hi,

    i think you will have to specifically check each column if it it blank or having value and keep on incrementing the variable in case of blank.

    regards

    vijay

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 17, 2008 at 05:48 PM

    Hi Veni,

    Try to add one more field 'COUNT' for your internal table. So that you can store the count for the corresponding row in the same row.

    LOOP AT itab ASSIGNING <fs>.

    CLEAR <fs>-count.

    IF <fs>-matnr1 IS NOT INITIAL.

    INCREMENT <fs>-count BY 1.

    ENDIF.

    IF <fs>-matnr2 IS NOT INITIAL.

    INCREMENT <fs>-count BY 1.

    ENDIF.

    IF<fs>-matnr3 IS NOT INITIAL.

    INCREMENT <fs>-count BY 1.

    ENDIF.

    IF <fs>-matnr4 IS NOT INITIAL.

    INCREMENT <fs>-count BY 1.

    ENDIF.

    IF <fs>-matnr5 IS NOT INITIAL.

    INCREMENT <fs>-count BY 1.

    ENDIF.

    IF <fs>-matnr6 IS NOT INITIAL.

    INCREMENT <fs>-count BY 1.

    ENDIF.

    IF <fs>-matnr7 IS NOT INITIAL.

    INCREMENT <fs>-count BY 1.

    ENDIF.

    ENDLOOP.

    Now, Column count is having the exact number of materials having values in the respective rows of the internal table.

    Reward me if useful.

    Thanks,

    Harimanjesh AN

    Edited by: Harimanjesh AN on Sep 17, 2008 7:50 PM

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 17, 2008 at 10:55 PM

    Hi,

    Did you check my code..Please let me know..

    Thanks

    Naren

    Add comment
    10|10000 characters needed characters exceeded