Skip to Content
avatar image
Former Member

Transformation: Issue in End-Routine

Dear all ;

Currently I’m having an issue in the end routine and I hope you can help me.

The goal is, in a transformation between 2 DSOs, populate a counter.

In DSO 1 (source) I have as key the Delivery and Shipment (1:1) were in DSO 2 (target) the Delivery and Material. I can have multiple materials per delivery and the counter should be populated in all.

In the start routine:

    TYPES: BEGIN OF s_odgi,

      deliv_numb TYPE /bi0/oideliv_numb,

     /material TYPE //bi0/oimaterial,

    END OF s_odgi.

    DATA: it_odgi TYPE SORTED TABLE OF s_odgi

          WITH NON-UNIQUE KEY deliv_numb,

          wa_odgi TYPE s_odgi.

    DATA: it_odgi_aux TYPE STANDARD TABLE OF s_odgi,

          wa_odgi_aux TYPE s_odgi.

DATA: t_sp TYPE STANDARD TABLE OF _ty_s_sc_1 .

    REFRESH it_odgi.

    t_sp[] = SOURCE_PACKAGE[] .

    SORT t_sp BY deliv_numb .

    DELETE ADJACENT DUPLICATES FROM t_sp COMPARING deliv_numb .

    DELETE t_sp WHERE deliv_numb IS INITIAL .

      SELECT deliv_numb material

             INTO TABLE it_odgi_aux FROM /BIC/ADSO1V00

             FOR ALL ENTRIES IN t_sp

             WHERE deliv_numb = t_sp-deliv_numb.

      SORT it_odgi_aux BY deliv_numb material.

*      DELETE ADJACENT DUPLICATES FROM it_odgi_aux COMPARING

*      deliv_numb

*      material

*      .

      it_odgi[] = it_odgi_aux[].

      FREE it_odgi_aux.

    ENDIF.

In the transformation:

ZCOUNTER as constant 1

In the End-Routine:

    LOOP AT RESULT_PACKAGE ASSIGNING <RESULT_FIELDS>.

      CLEAR wa_odgi.

      LOOP AT it_odgi INTO wa_odgi

      WHERE DELIV_NUMB = <RESULT_FIELDS>-DELIV_NUMB.

        IF sy-subrc = 0.

          <RESULT_FIELDS>-material= wa_ODGI-material.

        ELSE.

          DELETE RESULT_PACKAGE.

        ENDIF.

      ENDLOOP.

    ENDLOOP.

I also try this one :

    LOOP AT RESULT_PACKAGE ASSIGNING <RESULT_FIELDS>

    WHERE DELIV_NUMB IS NOT INITIAL.

      READ TABLE it_odgi INTO wa_odgi

      WITH TABLE KEY DELIV_NUMB = <RESULT_FIELDS>-DELIV_NUMB.

      IF sy-subrc = 0.

        <RESULT_FIELDS>-/material = wa_ODGI-material.

      ELSE.

        DELETE RESULT_PACKAGE.

      ENDIF.

    ENDLOOP.

But the result is the same : one the last material of the sort will be delivered.

I note the different materials are in it_odgi but the loop will overwrite the last one.

Can anyone help?

Thanks in advance

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Oct 23, 2015 at 03:31 AM

    Hi Ricardio,

    The source has Deliv and Shipment in the key, while the target has Deliv and Material in the key. Due to that, by the time you are in the end routine, you have one record per Delivery in the Result Package. It looks like you want to expand that Result Package into one record per Delivery/Material combination. But there is nothing in the code that does the expanding.

    So you'll need to change the code in the end routine. Your first option for the End Routine (nested LOOPs) was closer to being right than the second one, so I'll take that as a reference.

    First, declare a work area called LS_RP and an itab called LT_RP. The structure of both is the same as that of Result_package. Then change that nested loop end routine to the following:

    LOOP AT RESULT_PACKAGE ASSIGNING <RESULT_FIELDS>.

      CLEAR wa_odgi.

      LOOP AT it_odgi INTO wa_odgi WHERE DELIV_NUMB = <RESULT_FIELDS>-DELIV_NUMB.

         ls_rp = <result_fields>.

        ls_rp-material= wa_ODGI-material.

      CALL METHOD me->new_record__end_routine

        EXPORTING

          source_segid   = 1

          source_record = <result_fields>-RECORD

        IMPORTING

           record_new    = ls_rp-record.

        APPEND ls_rp to lt_rp.

      ENDLOOP.

    ENDLOOP.

    RESULT_PACKAGE = lt_rp.

    Add comment
    10|10000 characters needed characters exceeded

    • I partially agree with Suhas Karnik, however for each 1st entry of the loop on it_odgi you do NOT need to create a new record (you'll just be updating the existing one), so you'll need to skip the "new record" logic for the 1st loop. I personally don't like to fill a separate table and then copy that into RESULT_PACKAGE, so I would actually append RESULT_PACKAGE.

      Also, why this statement: it_odgi[] = it_odgi_aux[] ? You could have just filled one internal table and keep it (there's no need to copy it to another one).

      Tip: you can redefine t_sp so it contains only deliv_numb (providing that's the first field in your source_package) and your code will be more performant.