cancel
Showing results for 
Search instead for 
Did you mean: 

Transformation ABAP Statement to create Duplicate records

Former Member
0 Kudos

Hi,

I am planning to load Employee and respective sales orgs to a Z Info Object(User ID compounded on Seq No) from a flat file.

Source Data Will be like below


SEQ NO

USER_ID

SALES_ORG
110000167411
210000167473
3100001671068
410000169

*

510000200
610000289501
710000289513
810000289514
910000289513B 
1010000289513C
11  10000289  513D

My requirement is to write a routine in transformation where for Users with * (Ex:10000169),It should create multiple entries with full list of sales org from 0SALESORG master data.


In Start routine  0SALESORG master data is selected and saved in Internal Table IT_SAL_ORG

Please advise how to create multiple entries

Thanks in advance

Accepted Solutions (1)

Accepted Solutions (1)

former_member186053
Active Contributor
0 Kudos

Hi,

Try to use Rule Group functionality in transformations. Google with  "Rule Groups in Transformation" you will some good documents on how to achieve this.

Also go through the below link.

http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/c07161ee-afa6-2c10-06bd-f1c864355...

Regards,

Vengal.

Former Member
0 Kudos

Thanks for the update.

But it won't meet my requirment

shalaka_golde
Participant
0 Kudos

Hi,

You can refer the link that Vengal has given.It will give u a good idea to implement this using start as well as end routines.

In the start routine you can populate the internal table each time reading the internal table in which the master data has been read and append the source package.Then in the end routine u can read the source package and append the result package accordingly.

Regards,

Shalaka

Former Member
0 Kudos

Hi,

I am writing EXPERT routine to meet the above split records..but not getting the required results.

'*' are not splitting up....as my abap skills are limited and inputs are greatly helpful

   TYPES: BEGIN OF TY_SALESORG,
            SALESORG  TYPE /BI0/OISALESORG ,
            OBJVERS   TYPE RSOBJVERS,
           END OF TY_SALESORG.


    DATA: IT_SALESORG TYPE TABLE OF TY_SALESORG.
    DATA: WA_SALESORG TYPE  TY_SALESORG.

    DATA:  t_source TYPE STANDARD TABLE OF _ty_s_SC_1.
    DATA: gs_source TYPE _ty_s_SC_1,
                gs_result TYPE _ty_s_TG_1.
    DATA: l_index  TYPE syindex,
          l_index2 TYPE syindex.

  

CLEAR: IT_SALESORG.
  

SELECT SALESORG OBJVERS
  FROM  /BI0/PSALESORG
  INTO TABLE IT_SALESORG
  WHERE SALESORG  <> ' ' AND
            OBJVERS   = 'A'.

  

t_source[] = SOURCE_PACKAGE[].
*Mapping all common fields.

    LOOP AT SOURCE_PACKAGE INTO gs_source.
      CLEAR: WA_SALESORG.
      READ TABLE IT_SALESORG INTO WA_SALESORG WITH KEY OBJVERS = 'A'.
    

IF gs_source-SALESORG <> '*'.
        gs_result-/BIC/ZSORUSER   = gs_source-/BIC/ZSORUSER.
        gs_result-SALESORG        = gs_source-SALESORG.
        gs_result-/BIC/ZCOUNTER   = '1'.
        APPEND GS_RESULT TO RESULT_PACKAGE.

         IF gs_source-SALESORG = '*'.
          gs_result-/BIC/ZSORUSER   = gs_source-/BIC/ZSORUSER.
          gs_result-SALESORG        = WA_SALESORG-SALESORG.
          gs_result-/BIC/ZCOUNTER   = '1'.
          APPEND GS_RESULT TO RESULT_PACKAGE.
    

   ENDIF.
      ENDIF.
    ENDLOOP.

Former Member
0 Kudos

Suggestions 1: remove OBJVERS from here and every where in the code. unnecessary.

TYPES: BEGIN OF TY_SALESORG,

            SALESORG  TYPE /BI0/OISALESORG ,

            OBJVERS   TYPE RSOBJVERS,

           END OF TY_SALESORG.


Suggestions 2: use refresh stmt to clear the itab. it_salesorg

CLEAR: IT_SALESORG.


Suggestions 3: Use " SELECT DISTINCT SALESORG" , dont need to select objvers

SELECT SALESORG OBJVERS


Suggestions 4: What you really need.


LOOP AT SOURCE_PACKAGE INTO gs_source.

IF gs_source-SALESORG <> '*'.
gs_result-/BIC/ZSORUSER   = gs_source-/BIC/ZSORUSER.
gs_result-SALESORG           = gs_source-SALESORG.
gs_result-/BIC/ZCOUNTER   = '1'.
        APPEND GS_RESULT TO RESULT_PACKAGE.

endif

IF gs_source-SALESORG = '*'.

LOOP AT IT_SALESORG INTO WA_SALESORG.

        gs_result-/BIC/ZSORUSER   = gs_source-/BIC/ZSORUSER.

         gs_result-SALESORG               = WA_SALESORG-SALESORG.

gs_result-/BIC/ZCOUNTER   = '1'.

        APPEND GS_result    TO RESULT_PACKAGE.

CLEAR: WA_SALESORG.

                       ENDLOOP.

          ENDIF.

ENDLOOP.

Former Member
0 Kudos

Hi,

Thanks for all the updates.

Both the proposed approaches are not working.....

Modified the code as below ...like mentioned

  IF gs_source-SALESORG = '*'.

           LOOP AT  IT_SALESORG INTO WA_SALESORG.

          gs_result-/BIC/ZSORUSER   = gs_source-/BIC/ZSORUSER.

          gs_result-SALESORG        = WA_SALESORG-SALESORG.

          gs_result-/BIC/ZCOUNTER   = '1'.

          APPEND GS_RESULT TO RESULT_PACKAGE.

          CLEAR: WA_SALESORG.

          ENDLOOP.

Former Member
0 Kudos

Sorted....Its working as expected

Thanks for all the help

Answers (2)

Answers (2)

anurag_abbi_tm
Participant
0 Kudos

Hi SAP USER,

I am sure if I am late in answering to your query but I propose the following :

TYPES: BEGIN OF ty_salesorg,

          salesorg  TYPE /bi0/oisalesorg ,

          objvers   TYPE rsobjvers,

        END OF ty_salesorg.

DATA  : it_salesorg TYPE TABLE OF ty_salesorg,

         wa_salesorg TYPE  ty_salesorg,

         t_source TYPE STANDARD TABLE OF _ty_s_sc_1,

         gs_source TYPE _ty_s_sc_1,

         gs_result TYPE _ty_s_tg_1,

         lv_sequence TYPE i.

REFRESH : it_salesorg, result_package.

CLEAR : lv_sequence.

SELECT salesorg objvers

   FROM /bi0/psalesorg

   INTO TABLE it_salesorg

  WHERE salesorg <> space

    AND objvers = 'A'.

IF sy-subrc = 0.

   SORT it_salesorg BY salesorg objvers.

   DELETE ADJACENT DUPLICATES FROM it_salesorg.

ENDIF.

   t_source[] = source_package[].                             " Transfer Original Values

   LOOP AT source_package INTO gs_source.

     IF gs_source-salesorg <> '*'.

       lv_sequence = lv_sequence + 1.

       gs_result-/bic/zsoruser   = gs_source-/bic/zsoruser.    "User ID

       gs_result-salesorg        = gs_source-salesorg.         "Sales_Org

       gs_result-/bic/zcounter   = lv_sequence.                "SEQ No

       APPEND gs_result TO result_package.

     ELSEIF gs_source-salesorg = '*'.

       LOOP AT it_salesorg INTO wa_salesorg.                   " Case for multiple entries in case of *

         lv_sequence = lv_sequence + 1.

         gs_result-/bic/zsoruser   = gs_source-/bic/zsoruser"User ID

         gs_result-salesorg        = wa_salesorg-salesorg.     "Sales_Org

         gs_result-/bic/zcounter   = lv_sequence.              "SEQ No

         APPEND gs_result TO result_package.

       ENDLOOP.

     ENDIF.

   ENDLOOP.

" result_package contains final values.


Hope you find some use for the above.


fcorodriguezl
Contributor
0 Kudos

Hi !

Try with this routine.

SELECT SALESORG

FROM  /BI0/PSALESORG

INTO TABLE IT_SALESORG

WHERE SALESORG  <> '' AND

      OBJVERS  = 'A'.

IT_SOURCE[] = SOURCE_PACKAGE[]

LOOP AT SOURCE_PACKAGE ASSIGNING <source_fields>.

  IF <source_fields>-salesorg = '*'.

    LV_SEQNO  =<source_fields>-seqno.

    LV_USERID =<source_fields>-userid.

    LOOP AT it_salesorg INTO wa_salesorg.

      wa_source-seqno    = LV_SEQNO

      wa_source-userid  = LV_USERID

      wa_source-salesorg = wa_salesorg-salesorg

      APPEND IT_SOURCE.

    ENDLOOP.

  ENDIF.

ENDLOOP.

SOURCE_PACKAGE[] = IT_SOURCE[]

Regards.