cancel
Showing results for 
Search instead for 
Did you mean: 

End Routine in Transformation

Former Member
0 Kudos

Hi Everyone,

Anyone that can assist me with my end routine code? You will notice in the source screenshot there are records against 0STKEYFIG 'CS149' & 'CS158'. What I want to achieve is where the material and creditor fields against cs158 matches the material creditor fields against cs149, to populate 0value_lc against cs149 records using 0value_lc value from cs158, as shown in destination screenshot.

Attached is also the source code of my end routine, but it is not working.

Thanks guru's, any assistance would be appreciated.

Best Regards,

Rudi

Source:

Destination:

Accepted Solutions (1)

Accepted Solutions (1)

former_member183519
Contributor
0 Kudos

Hello Rudi,

use either of below approach...

APPROACH--> 1

FIELD-SYMBOLS:<RESULT_FIELDS_1>    TYPE _ty_s_TG_1.

data: IT_RESULT_PACKAGE TYPE STNADARD TABLE OF _ty_s_TG_1,

      lv_index type sy-index.

IT_RESULT_PACKAGE[] = RESULT_PACKAGE[].

DELETE RESULT_PACKAGE WHERE stkeyfig = 'cs149' .

DELETE RESULT_PACKAGE WHERE stkeyfig = 'cs158' .

DELETE IT_RESULT_PACKAGE WHERE stkeyfig <> 'cs149'

                            OR stkeyfig <> 'cs158'.

SORT it_result_package by CREDITOR MATERIAL acending STKEYFIG decending.

lv_index = 0.

LOOP AT it_result_package ASSIGNING <result_fields> FROM lv_index

                          WHERE     <result_fields>-stkeyfig = 'CS158' .

   lv_index =  sy-index + 1 .

    LOOP AT it_result_package ASSIGNING <result_fields_1> FROM lv_index.

         IF <result_fields_1>-stkeyfig = 'CS149'                  AND

            <result_fields_1>-CREDITOR = <result_fields>-CREDITOR AND

            <result_fields_1>-MATERIAL = <result_fields>-MATERIAL.

            <result_fields_1>-VALUE_LC = <result_fields>-VALUE_LC .

         ELSE.

             <result_fields_1>-VALUE_LC = 0.

             exit.

         ENDIF.

    ENDLOOP. 

  lv_index = sy_index.

ENDLOOP.

APEEND LINES OF it_result_package TO table RESULT_PACKAGE.

CLEAR : it_result_package.

----------------------------------------------------------------------------

APPROACH--> 2

DATA : RESULT_PACKAGE_CS149  TYPE STNADARD TABLE OF _ty_s_TG_1,

       RESULT_PACKAGE_CS158  TYPE STNADARD TABLE OF _ty_s_TG_1.

FIELD-SYMBOLS:<RESULT_FIELDS_CS149> TYPE _ty_s_TG_1,

              <RESULT_FIELDS_CS158> TYPE _ty_s_TG_1.

IT_RESULT_PACKAGE_CS149[] = RESULT_PACKAGE[].

IT_RESULT_PACKAGE_CS158[] = RESULT_PACKAGE[].

DELETE RESULT_PACKAGE WHERE stkeyfig = 'cs149'.

DELETE RESULT_PACKAGE WHERE stkeyfig = 'cs158'.

DELETE RESULT_PACKAGE_CS149 WHERE stkeyfig <> 'cs149'.

DELETE RESULT_PACKAGE_CS158 WHERE stkeyfig <> 'cs158'.

SORT RESULT_PACKAGE_CS158 BY CREDITOR MATERIAL. 

LOOP AT RESULT_PACKAGE_CS149  ASSIGNING <RESULT_FIELDS_CS149>.

READ TABLE RESULT_PACKAGE_CS158 ASSIGNING <RESULT_FIELDS_CS158>

                     WITH KEY <RESULT_FIELDS_CS158>-CREDITOR = <RESULT_FIELDS_CS149>-CREDITOR

       <RESULT_FIELDS_CS158>-MATERIAL = <RESULT_FIELDS_CS149>-MATERIAL  BINARY SEARCH.

  IF sy-subrc = 0 .

     <RESULT_FIELDS_CS149>-VALUE_LC = <RESULT_FIELDS_CS158>-VALUE_LC.

  ENDIF.

ENDLOOP.

APPEND LINES OF RESULT_PACKAGE_CS149 TO RESULT_PACKAGE.

APPEND LINES OF RESULT_PACKAGE_CS149 TO RESULT_PACKAGE.

FREE: RESULT_PACKAGE_CS149[] , RESULT_PACKAGE_CS158[].

----------------------------------------------------------------------------------------------------------------

NOTE: For either approch u need to set Semantic grouping @ DTP Level on Fields : CREDITOR & MATERIAL.

for approach 2 u may required nothing to change.. but i will suggest approach 1 for performance (may require little chnages).....

Regards,

Hitesh

Former Member
0 Kudos

Hi Hitesh,

Thank you so much for the time and effort in helping me. Unfortunately I am still at the same place with these table declarations, not finding certain components. These errors occur in both the approaches, assume I am missing another sort of declaration.


No component exist with the name "<RESULT_FIELDS>-STKEYFIG".

As mentioned previously, this is the frustrating part, as result fields is of type _ty_s_TG_1 and definitely have the field STKEYFIG. Urghhh, hopefully one day I will understand this complex language...hehehe

Thanks again for the time.

Best Regards

Rudi

former_member183519
Contributor
0 Kudos

Hi Rudi,

Which approach u r tying ?

try approach 2,  becasue in approach 2 i have nowhere used <RESULT_FIELDS> , i have used <<RESULT_FIELDS_CS149> & <RESULT_FIELDS_CS158>.

replace all your code with approch 2.. &  if same problem still appears..

do one thing..

delete all code inside end routine(take a backup if any extra code is there) and activate transformation first.. after successfully activation , try to put code again and then check.

Regards,

Hitesh

Former Member
0 Kudos

Hi,

It was in the first approach, what I did in that routine was with the line <result_fields>-stkeyfig I just removed the result fields part, but unfortunately the code did not work as the result was as in the screenshot still. I am now busy with the second approach, but on the line where it reads...


.... WITH KEY <RESULT_FIELDS_CS158>CREDITOR = <RESULT_FIELDS_CS149> CREDITOR

Get the same error, component does not exist <result_fields_cs158>-creditor. I have removed the <result_fields> part again, so the read table code looks like this...


read table result_package_cs158 assigning <result_fields_cs158>

                                        with key creditor = <result_fields_cs149>-creditor.

Do not get a syntax error on that line any more, although it is not happy with the binary search syntax.


Incorrect arithmetic or bit expression: instead of "BINARY", an operater (+, -, *, /, .... or BIT-AND, BIT-XOR, BIT-OR) was expected

Thanks,

Rudi

former_member183519
Contributor
0 Kudos

Hi Rudi,

Put debugger point at 2 places in code :

1)

-->LOOP AT RESULT_PACKAGE_CS149  ASSIGNING <RESULT_FIELDS_CS149>.

2)

-->READ TABLE RESULT_PACKAGE_CS158 ASSIGNING <RESULT_FIELDS_CS158>

                     WITH KEY <RESULT_FIELDS_CS158>-CREDITOR = <RESULT_FIELDS_CS149>-CREDITOR

       <RESULT_FIELDS_CS158>-MATERIAL = <RESULT_FIELDS_CS149>-MATERIAL  BINARY SEARCH.

check:

a) what are entries u get in RESULT_PACKAGE_CS149(should get only CS149 entries..check for this ) & RESULT_PACKAGE_CS158(should get only CS158 entries.. check for this too)

b) if above points works fine then  check what happening exactly inside Loop.. means why READ TABLE statement going wrong..

also to cross verify point B, do one thing ..

comment on line  SORT RESULT_PACKAGE_CS158 BY CREDITOR MATERIAL.

and remove Binary seach Keyword from READ TABLE statement and run dtp again and check result..

Regards,

Hitesh

Former Member
0 Kudos

Hi Hitesh,

Apologies for my lack of knowledge, unfortunately I do not have a abap person that can assist me, so all this is a learning curve for me. Thanks man.

On Topic:

The code stops on the first breakpoint, then immediately jumps to the "Append lines... " record.
Which tells me that result_package_cs149 is blank throughout, and therefore not stopping at the second breakpoint....

EDIT:

Based on the above, found that it gets cleared when deleting <> 'cs149', this statement seems case sensitive, I changed it to <> 'CS149' and data are populated now, I am busy testing to see if all is in order.

Regards,

Rudi

Message was edited by: Rudi Hattingh

former_member183519
Contributor
0 Kudos

great.. let me know if any further issues.

Answers (2)

Answers (2)

Former Member
0 Kudos

Thanks Amit and Hitesh, with some modifications your method worked Hitesh... much appreciated.

former_member220624
Contributor
0 Kudos

Hi,

What exactly you mean by not working ?

Can you share a screenshot of the output using your end routine like how is the data populated presently?

Regards,

Amit

Former Member
0 Kudos

Hi Amit,

The code in my end routine currently make 0VALUE_LC zero for all records, even the ones that was against the 0STKEYFIG = 'CS158' records.

Incorrect Result:

former_member220624
Contributor
0 Kudos

Hi,

I am not sure about the end routine code you have written since you are using the looping on the result package twice. Maybe you can include the modify statement inside the inner loop and check.

Alternatively i can think of the following -


Create two internal tables itab1,itab2 of type result_package


      Loop at itab1 with 0STKEYFIG = 'CS149'

                Read itab2 with key 0STKEYFIG = 'CS158'


                         if itab2-0creditor=itab1-0creditor and itab2-0material=itab1-0material

                        

                                   itab1-value_lc=itab2-value_lc


                              endif

     endloop


Hope this gives you an idea.


Regards,

Amit

Former Member
0 Kudos

Thanks Amit for the response..


Create two internal tables itab1,itab2 of type result_package

Obviously my abap skills is dull, but this is the part I struggle with... and somehow just can not get it declared correctly. When I think the internal table is created, I get the error "x is neither specified under "TABLES" nor is it defined as an internal table" when I try to loop through it...

Hehe, I am so glad its Friday as my frustration is note able due to my lack of knowledge in this language...