cancel
Showing results for 
Search instead for 
Did you mean: 

End routine

ashu33
Participant
0 Kudos

Hi All,

I have a requirement where in i need to put add one more column for material, which will be fetched based on 2 Condition against Doc Number and material no

basically i have to sort the mat doc Num and look for corresponding History Cat = E and Movement Type 101 and select the adjacent Material No and fill it to new Column with same matnr

So to achieve this I have added new Infobject and need to write the End Routine

can anyone help with the Code.?

Refer Screenshot for details

Accepted Solutions (1)

Accepted Solutions (1)

Loed
Active Contributor
0 Kudos

Hi,

You may try to implement in END ROUTINE any of the codes below..

Assuming that letter "E" is the lowest HCT value, you may use this..

DATA: temp_zfmatrl TYPE zfmatrl.

     SORT result_package BY material_doc ASCENDING hct ASCENDING mvt ASCENDING.

     LOOP AT result_package ASSIGNING <result_fields>.

       AT NEW material_doc.

         temp_zfmatrl = <result_fields>-material.

       ENDAT.

       <result_fields>-zfmatrl = temp_zfmatrl.

     ENDLOOP.

If there are other HCT values lower than "E" (since I used ASCENDING), just use this..

     DATA: wa_result_pack TYPE _ty_s_tg_1.

     LOOP AT result_package ASSIGNING <result_fields>.

       READ TABLE result_package INTO wa_result_pack

       WITH KEY

       hct = 'E'

       mvt = '101'

       material_doc = <result_fields>-material_doc.

       IF sy-subrc = 0.

         <result_fields>-zfmatrl = wa_result_pack-material.

       ENDIF.

       CLEAR wa_result_pack.

     ENDLOOP.

Just replace them with the correct data types..

Regards,

Loed

ashu33
Participant
0 Kudos

Hi Loed,

Its working but still there is issue i am getting material in alternate lines

what wrong here?

Loed
Active Contributor
0 Kudos

Hi,

What code did you use?

Try to use this:

     DATA: wa_result_pack TYPE _ty_s_tg_1.


     SORT result_package BY material_doc ASCENDING hct ASCENDING mvt ASCENDING.

     LOOP AT result_package ASSIGNING <result_fields>.

       READ TABLE result_package INTO wa_result_pack

       WITH KEY

       hct = 'E'

       mvt = '101'

       material_doc = <result_fields>-material_doc

       binary-search.

       IF sy-subrc = 0.

         <result_fields>-zfmatrl = wa_result_pack-material.

       ENDIF.

     ENDLOOP.

Regards,

Loed

ashu33
Participant
0 Kudos

DATA: wa_result_pack TYPE _ty_s_tg_1.

      SORT RESULT_PACKAGE by DOC_NUM ASCENDING /BIC/ZBEWTP ASCENDING

      MOVETYPE.

      LOOP AT RESULT_PACKAGE ASSIGNING <result_fields>.

        READ TABLE RESULT_PACKAGE INTO wa_result_pack

        WITH KEY

        /BIC/ZBEWTP = 'E'

        MOVETYPE = '101'

        DOC_NUM = <result_fields>-DOC_NUM.

        IF sy-subrc = 0.

          <result_fields>-/BIC/ZFMATNR = wa_result_pack-MATERIAL.

        ENDIF.

        CLEAR wa_result_pack.

      ENDLOOP.

Loed
Active Contributor
0 Kudos

Hi,

Just posted that new code above..Try it first then post here for result..

Else, try the first code I have posted in my 1st reply..

Regards,

Loed

Answers (2)

Answers (2)

Former Member
0 Kudos

Dear,

Store your result_package in temp table say RESULT_TEMP..then

move RESULT_PACKAGE[] to RESULT_TEMP[]....then

Sort RESULT_TEMP by Material doc Hct Mvt.....then

Loop at result_package assigning <result_fields>.

read table RESULT_TEMP into <result_fields_temp> with key  material doc = <result_fields>-material doc Hct = 'E' Mvt = '101' Binary Search.

If sy-subrc = 0.

move <result_fields_temp>-material to <result_fields>-ZFMATRL.

endif.

Endloop.

Thanks & Regards,

M

RafkeMagic
Active Contributor
0 Kudos

I would start by filling an internal table with all the lines for combination Hct = E & Mvt = 101 (either in start or end routine).

In the end routine, you'll read this table for each line where Hct <> E & Mvt <> 101 to find the corresponding value.