Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Splitting one internal table record into four records

Former Member
0 Kudos

I have the below structure,

My requirement is I have to divide one record into four records,

Exam.

From the source I am getting data below.

Mat1 date key1 key2 key3 key4.

Now I want to divide the above record into four records i.e

Mat1 date v1 key1

Mat1 date v2 key2

Mat1 date v3 key3

Mat1 date v4 key4

.

.

Here V1 V2 V3 V4 are constants and it is there in the target structure as type.

Below I tried u2026u2026.

Please give some idea.


TYPES: BEGIN OF y_source_fields ,
         KYF_0002 TYPE /BIC/OIZCOUNT ,
         KYF_0004 TYPE /BIC/OIZCOUNT ,
         KYF_0001 TYPE /BIC/OIZCOUNT ,
         KYF_0003 TYPE /BIC/OIZCOUNT ,
         Matno TYPE /BI0/OIMATERIAL ,
         CALDAY TYPE /BI0/OICALDAY ,
       END OF y_source_fields .
TYPES: yt_source_fields TYPE STANDARD TABLE OF y_source_fields .

TYPES: BEGIN OF y_target_fields ,
         Matno TYPE /BI0/OIMATERIAL,
         CALDAY TYPE /BI0/OICALDAY ,
         TYPYE TYPE /BIC/OIZATNAM ,
         COUNT TYPE /BIC/OIZCOUNT ,
       END OF y_target_fields .
TYPES: yt_target_fields TYPE STANDARD TABLE OF y_target_fields .

DATA: ls_source TYPE y_source_fields,
ls_target TYPE y_target_fields.

DATA: V1(3) TYPE C VALUE 'V1',
      V2(3) TYPE C VALUE 'V2',
      V3(3) TYPE C VALUE 'V3',
      V4(3) TYPE C VALUE 'V4',
      int type i.



*----------- End of type definitions --------------------------------
FORM compute_data_transformation
     USING     it_source TYPE yt_source_fields
               ir_context TYPE REF TO if_rsan_rt_routine_context
     EXPORTING et_target TYPE yt_target_fields .
*--------- Begin of transformation code -----------------------------


Loop at it_source into ls_source.
if ls_source-bp_respper <> 0.
do 4 times.


enddo.


endif.
Endloop.


*---------- End of transformation code ------------------------------
ENDFORM.

Thanks inadvance.

Trecy.

Edited by: Thomas Zloch on Feb 27, 2010 9:34 PM

1 ACCEPTED SOLUTION

Clemenss
Active Contributor
0 Kudos

Hi Trecy,

please give an example of what data you have as source and what do you expectt as target.

Please format code as code so that it can be read.

Please try to make your code free of syntax errors.

Regards,

Clemens

9 REPLIES 9

Clemenss
Active Contributor
0 Kudos

Hi Trecy,

please give an example of what data you have as source and what do you expectt as target.

Please format code as code so that it can be read.

Please try to make your code free of syntax errors.

Regards,

Clemens

Former Member
0 Kudos

Hi clemens,

Many thanks for the reply.

As off now, the diclaration part is error free for the above code.

I am getting data from source below format.

Materail date key1 Key2 Key3 Key4.

101 27/02/2010 2 5 8 4

102 27/02/2010 3 7 9 1

,

,

,

Note Key1, key2,key3, key4 are data type integer and below corredponding values.

example. first off all in my target the structure is three char fields are there, one is material, second is date and third is type (these I need to populate with data) and one keyfigure of data type integer.

And Now I have to divide above eash record in to four records as blow...

Mat, date, type, zkey

101, 27/02/2010 , V1, value of key1 i.e 2.

101, 27/02/2010, v2, value of key 2 i.e 5.

101, 27/02/2010, v3, value of key3 i.e 8.

101, 27/02/2010, v4, value of key4 i.e 4.

102, 27/02/2010 , V1, value of key1 i.e 3.

102, 27/02/2010, v2, value of key 2 i.e 7.

102, 27/02/2010, v3, value of key3 i.e 9.

102, 27/02/2010, v4, value of key4 i.e 1.

Here V1, V2, V3, V4 are constant of data type char. And it is thee in target structure.

Thanks in Advance..

Trecy...

Clemenss
Active Contributor
0 Kudos

Hi Trecy,

probably like this

FORM compute_data_transformation
     USING     it_source TYPE yt_source_fields
               ir_context TYPE REF TO if_rsan_rt_routine_context
*     EXPORTING et_target TYPE yt_target_fields ."EXPORTING only for methods/functions
     CHANGING et_target TYPE yt_target_fields .
*--------- Begin of transformation code -----------------------------
field-symbols:
  <source> type line of   yt_source_fields,
  <target>  type line of yt_target_fields.
 
Loop at it_source into <source>.
* if ls_source-bp_respper EQ(?)  0." No component 'bp_respper' in  yt_target_fields
do 4 times.
  append initial line to et_target assigning <target>.
  move-corresponding <source> to <target>."copy matnol and calday
  case  sy-index.
    when 1.
      TYPYE = 'V1'.
      <target>-count = <source>-KYF_0001.
    when 2.
      TYPYE = 'V2'.
      <target>-count = <source>-KYF_0002.
    when 3.
      TYPYE = 'V3'.
      <target>-count = <source>-KYF_0003.
    when 4.
      TYPYE = 'V4'.
      <target>-count = <source>-KYF_0004.
  endcase.
enddo.
Endloop.
*---------- End of transformation code ------------------------------
ENDFORM.

The use of field-symbols is not obligatory but it makes the code much faster and less memory-consuming.

Regards,

Clemens

StMou
Active Participant
0 Kudos

use a field-symbols with assign and unassign.

ThomasZloch
Active Contributor
0 Kudos

Formatting fixed, subject line changed. Please use a meaningful subject right away, next time. Imagine how the forum overview would look like if everybody named their problems "need some logic". Thomas

Former Member
0 Kudos

Hi ,

If you do little manipulation, you can easily use SPLIT command. Check help on this command. I guess this will be a simpler solution.

Thanks and Best Regards,

Dinesh.

Edited by: Dinesh C.B. on Feb 28, 2010 7:15 AM

0 Kudos

Hi,

SPLIT is used for character type objects or, with IN BYTE MODE addition, for xstrings.

Don't know how to use split here. Even if /BIC/OIZCOUNT is a character field (NUMC) you will not have a character where you can split.

UNASSIGN is never really necessary except if the code checks for IF ... IS ASSIGNED.

I think any kind of hint is more useful if the application is explained or obvious.

Regards,

Clemens

0 Kudos

Hi Clemens,

Thank you very much for your time.

I am working on it now.

And thanks for all inputs...

Thomas I will keep in mind your suggestion, as I am not a Abap er......

Regards,

Trecy....

0 Kudos

Hi Climens,

How about defining the structure as:

TYPES: BEGIN OF y_source_fields ,

KYF_0002 TYPE /BIC/OIZCOUNT ,

separator1 type c value ',',

KYF_0004 TYPE /BIC/OIZCOUNT ,

separator2 type c value ',',

KYF_0001 TYPE /BIC/OIZCOUNT ,

separator3 type c value ',',

KYF_0003 TYPE /BIC/OIZCOUNT ,

separator4 type c value ',',

Matno TYPE /BI0/OIMATERIAL ,

separator5 type c value ',',

CALDAY TYPE /BI0/OICALDAY ,

separator6 type c value ',',

END OF y_source_fields .

TYPES: yt_source_fields TYPE STANDARD TABLE OF y_source_fields .

TYPES: BEGIN OF y_target_fields ,

Matno TYPE /BI0/OIMATERIAL,

separator1 type c value ',',

CALDAY TYPE /BI0/OICALDAY ,

separator2 type c value ',',

TYPYE TYPE /BIC/OIZATNAM ,

separator3 type c value ',',

COUNT TYPE /BIC/OIZCOUNT ,

separator4 type c value ',',

END OF y_target_fields .

TYPES: yt_target_fields TYPE STANDARD TABLE OF y_target_fields .

Thanks and Best Regards,

Dinesh.