‎2008 Sep 17 6:12 PM
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.
‎2008 Sep 17 6: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
‎2008 Sep 17 6:43 PM
‎2008 Sep 17 6: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
‎2008 Sep 17 7:02 PM
Hi All,
Thanks a lot for all your replies. Here is my internal table. If matnr1 only has value then mcnt = 1, if only matnr1 and matnr2 and matnr3 has value then mcnt = 3, if all has value then mcnt = 7.
TYPES: BEGIN OF ty_zcoop,
mandt TYPE mandt,
kunnr TYPE kunnr,
matnr1 TYPE matnr,
matnr2 TYPE matnr,
matnr3 TYPE matnr,
matnr4 TYPE matnr,
matnr5 TYPE matnr,
matnr6 TYPE matnr,
matnr7 TYPE matnr,
iamount TYPE ziamt,
oamount TYPE zoamt,
ref TYPE unsez,
erdat TYPE erdat,
index TYPE sy-index,
END OF ty_zcoop.
DATA: gt_zcoop TYPE TABLE OF ty_zcoop WITH HEADER LINE.
Thanks,
Veni.
Edited by: veni reddy on Sep 17, 2008 8:32 PM
‎2008 Sep 17 11:45 PM
Hi,
Can anyone please help me. I tried all but nothing is working out.
Thanks,
Neelima.
‎2008 Sep 17 11:55 PM