Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

ABAP Case Statement in Transformation End Routine


Hi,

I am writing the below Start and end routine with a case statement but some reason its not working as expected.....With my limited ABAP knowledge I could able to correct the issue ...

Shall be grateful if someone could provide me inputs.


Logic: A Z Table is maintained with company code and default Profit Centre.

For all Profit centres from source we need to check if first 2 letters starts with IE and source company code 531 0r 521 then populate source fields to result fields if not then populate from z table

Start Routine

SELECT * FROM ZCC_PC_MAPPING INTO TABLE t_cc_pc_map FOR ALL ENTRIES IN SOURCE_PACKAGE
WHERE COMP_CODE = SOURCE_PACKAGE-COMP_CODE.
SORT t_cc_pc_map BY comp_code.

End Routine:

LOOP AT RESULT_PACKAGE ASSIGNING <RESULT_FIELDS>.

   l_prefix = <RESULT_FIELDS>-PROFIT_CTR(2).

   CASE l_prefix.
     WHEN 'IE'.
          IF <RESULT_FIELDS>-COMP_CODE = '531' OR
            <RESULT_FIELDS>-COMP_CODE =  '521'.
            <RESULT_FIELDS>-PROFIT_CTR = <RESULT_FIELDS>-PROFIT_CTR.
            <RESULT_FIELDS>-CO_AREA    = <RESULT_FIELDS>-CO_AREA.
          ENDIF.
        WHEN 'CY'.
          IF <RESULT_FIELDS>-COMP_CODE = '797' OR
            <RESULT_FIELDS>-COMP_CODE =  '993' OR
            <RESULT_FIELDS>-COMP_CODE =  '994'.
            <RESULT_FIELDS>-PROFIT_CTR = <RESULT_FIELDS>-PROFIT_CTR.
            <RESULT_FIELDS>-CO_AREA    = <RESULT_FIELDS>-CO_AREA.
          ENDIF.
        WHEN 'RW'.
          IF <RESULT_FIELDS>-COMP_CODE = '1004' OR
            <RESULT_FIELDS>-COMP_CODE =  '650'  OR
            <RESULT_FIELDS>-COMP_CODE =  '911'.
            <RESULT_FIELDS>-PROFIT_CTR = <RESULT_FIELDS>-PROFIT_CTR.
            <RESULT_FIELDS>-CO_AREA    = <RESULT_FIELDS>-CO_AREA.
          ENDIF.
        WHEN 'NZ'.
          IF <RESULT_FIELDS>-COMP_CODE = '1029'.
            <RESULT_FIELDS>-PROFIT_CTR = <RESULT_FIELDS>-PROFIT_CTR.
            <RESULT_FIELDS>-CO_AREA    = <RESULT_FIELDS>-CO_AREA.
          ENDIF.
        WHEN 'GB'.
          IF <RESULT_FIELDS>-COMP_CODE <> ' '.
            <RESULT_FIELDS>-PROFIT_CTR = <RESULT_FIELDS>-PROFIT_CTR.
            <RESULT_FIELDS>-CO_AREA    = <RESULT_FIELDS>-CO_AREA.
          ENDIF.
        WHEN 'GS'.
          IF <RESULT_FIELDS>-COMP_CODE <> ' '.
            <RESULT_FIELDS>-PROFIT_CTR = <RESULT_FIELDS>-PROFIT_CTR.
            <RESULT_FIELDS>-CO_AREA    = <RESULT_FIELDS>-CO_AREA.
          ENDIF.
*     WHEN 'GB' OR 'IE' OR 'NZ' OR 'CY' OR 'RW' OR 'GS'.
*        CONTINUE.
     WHEN OTHERS.
       READ TABLE t_cc_pc_map ASSIGNING <fs_cc_pc_map>
           WITH KEY comp_code = <RESULT_FIELDS>-COMP_CODE BINARY SEARCH.

        IF sy-subrc = 0.
           <RESULT_FIELDS>-PROFIT_CTR = <fs_cc_pc_map>-profit_c.
           <RESULT_FIELDS>-CO_AREA    = <fs_cc_pc_map>-co_area.
        ENDIF.
   ENDCASE.
ENDLOOP.

Former Member
replied

looks good. go ahead.

Regards,

Nanda

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question