SAP-Forum.ORG
   
This web site isn't affiliated with, sponsored by, or approved by SAP AG. Is only a SAP users community.

Go Back   SAP-Forum.ORG > SAP Forums > SAP ABAP

Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting layout to a report in background job Zoom SAP ABAP 2 11-29-2011 09:07 PM
Spilt GL setting in OKG8 SAPMM SAP PS - Project System 2 11-08-2011 03:23 PM
Accepting 0 in Num field with Mandatory setting ERP SAP ABAP 1 03-28-2011 11:42 PM
Delete decimal zeros from type menge or type packed while displaying in ALV Ramma SAP ABAP 2 02-08-2011 11:05 PM
Call transaction iView dynamically Micro SAP Portal 2 10-29-2010 12:33 AM

Aprenda SAP!
Reply
 
Thread Tools Display Modes
  #1  
Old 01-17-2012, 08:47 PM
Mirna Mirna is offline
Senior Member
 
Join Date: May 2010
Location: Alabama
Posts: 267
Default Setting a TYPE dynamically

Hi All,

I'm trying to create a data with a type setted dynamically.
I have 2 parameters : an internal table (p_reference) and the name (colonne, as a string) of one of its columns.

My code doesnt work because the instruction : "create data: ty_type type (desired_type)"
wont accept these desired_type :
- P(8) DECIMALS 3
- P8
It can only accept 'P'

Can I set the length and the decimals later Or should I change something else to make this code work?

Code:
FIELD-SYMBOLS <table_reference>  TYPE STANDARD TABLE.
  ASSIGN p_reference TO <table_reference>.
 
  FIELD-SYMBOLS <table_reference_fields> TYPE ANY.
  DATA gs_fldname TYPE REF TO data.
  CREATE DATA gs_fldname LIKE LINE OF <table_reference>.
  ASSIGN gs_fldname->* TO <table_reference_fields>.
 
  FIELD-SYMBOLS <lfs_comp_wa> TYPE abap_compdescr.
 
  l_descr_ref ?= cl_abap_typedescr=>describe_by_data( <table_reference_fields> ).
 
  LOOP AT l_descr_ref->components[] ASSIGNING <lfs_comp_wa>.
    IF <lfs_comp_wa>-name = colonne.
      exit.
    endif.
  endloop.
 
  data desired_type type string.
 
" This CONCATENATE dont work but this is just an example
 
  concatenate <lfs_comp_wa>-type_kind 
	      <lfs_comp_wa>-length 
              ' DECIMALS ' 
              <lfs_comp_wa>-decimals
  into desired_type.
 
 
  data: ty_type type ref to data .
  field-SYMBOLS <fs_data> type any .
  create data: ty_type type (desired_type) .  " crash :(
  ASSIGN: ty_type->* TO <fs_data> .
Thanks in advance.

Regards,
Mirna
Reply With Quote
Sponsors
  #2  
Old 01-17-2012, 09:10 PM
Golfi Golfi is offline
Senior Member
 
Join Date: May 2010
Location: Delaware
Posts: 824
Default Re: Setting a TYPE dynamically

Hello Mirna,

Allowed syntax are:

Code:
DATA dref TYPE REF TO data. CREATE DATA dref TYPE p LENGTH 11 DECIMALS 3. * or DATA: dref2 TYPE REF TO data, len TYPE i VALUE 11, dec TYPE i VALUE 3. CREATE DATA dref2 TYPE p LENGTH len DECIMALS dec. * or DATA: dref3 TYPE REF TO data, dataelem type c length 30 value 'WRBTR'. CREATE DATA dref3 TYPE (dataelem).
Regards,
Golfi
Reply With Quote
  #3  
Old 01-17-2012, 09:11 PM
Lala Lala is offline
Senior Member
 
Join Date: May 2010
Location: Chicago
Posts: 394
Default Re: Setting a TYPE dynamically

Hi Mirna,

Why not reading the data type of the table field?

Code:
    select single rollname into lv_type from dd03l
                                        where tabname   = lv_dbtab
                                        and   fieldname = ls_fld_except-fieldname.
    if sy-subrc  0.
      exit.
    endif.
 
    create data f_any type (lv_type).
    assign f_any->* to <f_any>.
Hope this helps.

Regards,
Lala
Reply With Quote
Entre a los Links relacionados
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT. The time now is 09:21 AM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Forum Design By inferno