Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 9076

Re: column to row

$
0
0

Hi,

 

follow the below logic..

 

Suppose, ITAB is you internal table having data..

and  IT_FINAL   for final output .

let ITAB  has data as below...

Year    Period    Type    Cc       COL0001        COL0002         COL0003
2013    10    DCT    100774    0.002301374    0.002301374    0.002152929
2013    10    DCT    100306    0.002259948    0.002259948    0.002610926   
2013    10    DCT    100204    0.004002861    0.004002861    0.004082154

 

As the columns in ITAB are dynamic, set some counter while creating dynamic field in ITAB .

suppose counter = 3  (Total number of dynamic fields..i.e-  col001,col002,col003) .

 

DATA : WA_COUNT TYPE I  ,

             pos_count      type   I  VALUE  4 . (number of non-dynamic fields. i.e-year,period,type,cc)

 

FIELD-SYMBOLS: <wa>   TYPE ANY,

                               <comp> TYPE ANY.

 

ASSIGN   WA_TAB  TO  <WA> .

LOOP AT ITAB INTO WA_TAB .

 

WA_FINAL-YEAR      = WA_TAB-YEAR .

WA_FINAL-PERIOD = WA_TAB-PERIOD .

WA_FINAL-TYPE      = WA_TAB-TYPE .

WA_FINAL-CC          = WA_TAB-CC .

 

 

DO COUNTER TIMES .

 

WA_COUNT = WA_COUNT + 1 .

POS_COUNT = POS_COUNT + 1

********Put logic for creating column name dynamically,,

********as  it is done before for ITAB**********like ...

 

CONCATENATE  'COL'  WA_COUNT INTO WA_FINAL-COL_NAME .

 

ASSIGN COMPONENT  POS_COUNT  OF STRUCTURE <WA> TO <COMP>.

 

WA_FINAL-VALUE = <COMP> .

 

 

APPEND WA_FINAL  TO  IT_FINAL .

 

ENDDO .

 

CLEAR WA_COUNT .

POS_COUNT = 4 .

 

ENDLOOP .

 

 

In above logic..for one loop at ITAB ,, three records will be inserted into IT_FINAL

as below...

 

YEAR  PERIOD     TYPE        CC         COLUMN            VALUE

2013       10              DCT    100774         COL1           0.002301374

2013    10             DCT   100774        COL2          0.002301374
2013    10              DCT   100774        COL3          0.002152929

 

and so on ....

 

Regards

DJ


Viewing all articles
Browse latest Browse all 9076

Trending Articles