Application Development 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: 

Problem in at new

former_member342013
Contributor
0 Kudos

hi All ,

Can any one help on this ?

i have written below code .

clear wa_final.

sort it_final by INSTID_A TYPEID_A.

   LOOP AT it_final into wa_final.

  idx1 = sy-tabix.

  at new INSTID_A.

    clear : vcount.

      endat.

  vcount = vcount + 1.

    wa_final-Count = VCOUNT.

    IF vcount gt 1.

   clear : wa_final-INSTID_A, wa_final-TYPEID_A.

   ENDIF.

    modify it_final from wa_final index idx1.

ENDLOOP.

I'm getting Output as

INSTID_ATYPEID_AFile NamesFile Count
Test1FIPPArchiving message.DOC1


imagearchivingrippon.XLS2


Test.URL3

but my requirement is as shown below

INSTID_ATYPEID_AFile NamesFile Count
Test1FIPPArchiving message.DOC3


imagearchivingrippon.XLS


Test.url

It means when the maximum file count is 3 then it should display only 3 , it should not display 1 and 2.....

how can i do this by using at new ?

Regards

Smitha

8 REPLIES 8

Former Member
0 Kudos

Hi Smitha,

After

vcount = vcount + 1.

Use AT END OF INSTID_A.

            wa_final-Count = VCOUNT.

       ENDAT.

instead of direct pass.

Hope it will work.

Thanks,

Manireddy

Former Member
0 Kudos

Hi smitha,

Try this :

clear wa_final.

sort it_final by INSTID_A TYPEID_A.

   LOOP AT it_final into wa_final.

            idx1 = sy-tabix.

            at new INSTID_A.

            modify it_final from wa_final index idx2 transporting <vcount-> .

             clear idx2.

            idx2 = sy-tabix.

           

            clear : vcount.

           endat.

  vcount = vcount + 1.

    wa_final-Count = VCOUNT.

    IF vcount gt 1.

   clear : wa_final-INSTID_A, wa_final-TYPEID_A.

    ENDIF.

   *

modify it_final from wa_final index idx1  transporting <field names ><all fields except count>.

ENDLOOP.

regards

Vaibhav

0 Kudos

hi Vaibhav ,

Thanks for the reply.

I'm getting the wrong output if i do this way .

Any other solution ?

Regards

Smitha

0 Kudos

hi smitha

what output you are getting now ?

paste here ?

regards

vaibhav

Former Member
0 Kudos

Try This:

sort it_final by TYPEID_A  INSTID_A

Former Member
0 Kudos

Hi Smitha,

When you are populating IT_FINAL table, add one more field at the first position INSTTYP (which is a concatenated string of INSTID_A TYPEID_A). This is assuming that there may be a different values of TYPEID_A for INSTID_A.

For Ex:

INSTID_ATYPEID_AFile NamesFile Count
Test1FIPPArchiving message.DOC2
Test1

FIPP

imagearchivingrippon.XLS
Test1FIPP1Test.URL

1

Once you are ready with the table IT_FINAL, then

clear wa_final.

sort it_final by INSTTYP.

   LOOP AT it_final into wa_final.

  at new INSTTYP.

    clear : vcount.

  idx1 = sy-tabix.

      endat.

  vcount = vcount + 1.

    wa_final-Count = VCOUNT.

    IF vcount gt 1.

   clear : wa_final-INSTID_A, wa_final-TYPEID_A.

   ENDIF.

    modify it_final from wa_final index idx1.

ENDLOOP.

Hope this will work, let us know your comments.

Thanks,

Harsha

Former Member
0 Kudos

Hi Smita,

If you just need the count then you can actually just use a collect statement which will give you the count based on TYPEID_A INSTID_A.

If you are gettting the output as AT NEW which is correct.

INSTID_ATYPEID_AFile NamesFile Count
Test1FIPPArchiving message.DOC1


imagearchivingrippon.XLS2


Test.URL3

Just after the loop is over sort the FileCount field descending.

Let me know if any additional info is required.

Thanks,

Tooshar Bendale

Former Member
0 Kudos

hi smitha,

          i have already seen your post. When i came to reply some one has locked it. please see to the below code. i think u will get the solution. use the below code to your requirement.

TABLES : MCH1,MARA.

*************STRUCTURE FOR MCH1 TABLE********************

TYPES : BEGIN OF ty_material_detail,

        matnr TYPE matnr,

        charg TYPE charg_d,

        END OF ty_material_detail.

*************STRUCTURE FOR FINAL TABLE*******************

TYPES : BEGIN OF ty_final,

        matnr TYPE matnr,

        charg TYPE charg_d,

        count TYPE string,

        END OF ty_final.

DATA : it_mch1 TYPE STANDARD TABLE OF ty_material_detail,

        wa_mch1 TYPE ty_material_detail.

DATA : it_final_temp TYPE STANDARD TABLE OF ty_final,

        wa_final TYPE ty_final.

DATA : it_final1 TYPE STANDARD TABLE OF ty_final,

        wa_final1 TYPE ty_final.

DATA :  gv_temp TYPE string.

DATA :  gv_temp1 TYPE string.

DATA :  gv_temp2 TYPE string,

        flag TYPE c.

SELECT-OPTIONS : p_matnr FOR mara-matnr.

START-OF-SELECTION.

* for mch1 table

  SELECT matnr charg FROM mch1 INTO TABLE it_mch1 WHERE matnr IN p_matnr.

* Sort internal table

  SORT it_mch1 BY matnr.

  gv_temp1 = 0.

  LOOP AT it_mch1 INTO wa_mch1.

    wa_final-matnr = wa_mch1-matnr.

    wa_final-charg = wa_mch1-charg.

    AT END OF matnr.

      wa_final-count = sy-tabix.

      gv_temp = wa_final-count - gv_temp1.

      gv_temp1 = wa_final-count.

      CLEAR wa_final-count.

      wa_final-count = gv_temp.

      APPEND wa_final TO it_final_temp.

      CLEAR gv_temp.

    ENDAT.

    CLEAR wa_final.

  ENDLOOP.

  LOOP AT it_mch1 INTO wa_mch1.

    ON CHANGE OF wa_mch1-matnr.

      READ TABLE it_final_temp INTO wa_final WITH KEY matnr = wa_mch1-matnr.

      wa_final1-matnr = wa_final-matnr.

      wa_final1-charg = wa_final-charg.

      wa_final1-count = wa_final-count.

      APPEND wa_final1 TO it_final1.

      CLEAR : wa_final1,wa_final.

      flag = 'X'.

    ENDON.

    IF flag <> 'X'.

      wa_final1-charg = wa_mch1-charg.

      APPEND wa_final1 TO it_final1.

      CLEAR : wa_final1.

    ENDIF.

    CLEAR flag.

  ENDLOOP.

  LOOP AT it_final1 INTO wa_final1.

    WRITE 😕 wa_final1-matnr,wa_final1-charg,wa_final1-count.

  ENDLOOP.

regards,

Rady.