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: 

Type, Types, Data, Like

Former Member
0 Kudos

Hi,

<b>Doubt 1:</b>

Can anybody explain me the difference between Type, Types, Data, Like in SIMPLE WORDS

and how to use them while defining Internal Table and Work Area.

I did like this

TABLES: SPFLI.

TYPES: BEGIN OF STRUCT,

CARRID LIKE SPFLI-CARRID,

CITYFROM LIKE SPFLI-CITYFROM,

CITYTO LIKE SPFLI-CITYTO,

ARRTIME LIKE SPFLI-ARRTIME,

END OF STRUCT.

DATA: ITAB LIKE STRUCT OCCURS 0 WITH HEADER LINE.

Its giving some Error, and i want to define Inter Table an d Work Area seperately.

Please explain me in SIMPLE WORDS.

<b>Doubt 2:</b> in SELECT-OPTIONS

INITIALIZATION.

TABLES: SPFLI.

SELECT-OPTIONS: PARRTIME FOR SPFLI-ARRTIME.

PARRTIME-SIGN = 'I'.

PARRTIME-OPTION = 'BT'.

PARRTIME-LOW = 200000.

PARRTIME-HIGH = 240000.

When i activate and run, in select options its showing

PARRTIME 00:00:00 TO 00:00:00

What is solution.

Thanks

Jen

14 REPLIES 14

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Hi Jen. To be honest I never use LIKE. I always use TYPE. The TYPES statement allows you to define types which can be used in your program. The TYPE statement allows to you reference this type in your DATA statements. The DATA statement reserve space in memory that will hold the data. The TYPES statement does not do this, it only defines the way the data should look. Since you want to specify the work area separatly, your code should look like this.




 
TYPES: BEGIN OF STRUCT,
CARRID LIKE SPFLI-CARRID,
CITYFROM LIKE SPFLI-CITYFROM,
CITYTO LIKE SPFLI-CITYTO,
ARRTIME LIKE SPFLI-ARRTIME,
END OF STRUCT.

DATA: ITAB type table of struct.
data: wa type struct.

REgards,

Rich Heilman

0 Kudos

For your second question, just remember that when you define a select-option, it is really an internal table with the structure SIGN OPTION LOW and HIGH. So when you want to put default values, you need to actually APPEND to the internal table.



INITIALIZATION.
TABLES: SPFLI.
SELECT-OPTIONS: PARRTIME FOR SPFLI-ARRTIME.
PARRTIME-SIGN = 'I'.
PARRTIME-OPTION = 'BT'.
PARRTIME-LOW = 200000.
PARRTIME-HIGH = 240000.
<b>append parrtime.</b>

Regards,

Rich Heilman

ferry_lianto
Active Contributor
0 Kudos

Hi Jen,

Doubt 1:

It should be like this.

DATA: ITAB TYPE STANDARD TABLE OF STRUCT WITH HEADER LINE.

For more information, please chcek this link.

http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb2ff3358411d1829f0000e829fbfe/content.htm

Doubt 2:

It should be like this.

TABLES: SPFLI.

SELECT-OPTIONS: PARRTIME FOR SPFLI-ARRTIME.

INITIALIZATION.

PARRTIME-SIGN = 'I'.

PARRTIME-OPTION = 'BT'.

PARRTIME-LOW = '200000'.

PARRTIME-HIGH = '240000'.

APPEND PARRTIME.

Hope this will help.

Regards,

Ferry Lianto

0 Kudos

Hi,

Thanks for reply.

One more doubt , this is on Wild,

PARAMETERS: PCARRID LIKE SPFLI-CARRID.

when the user don't input anything in PCARRID (i.e empty field and press F8), i want to show all results..

i tried like this, but not working.

PARAMETERS: PCARRID LIKE SPFLI-CARRID.

replace all occurrences of '*' in PCARRID with '%' .

SELECT CARRID CITYFROM CITYTO ARRTIME INTO ITAB FROM SPFLI WHERE CARRID LIKE PCARRID.

suggest me..

Thanks

J

0 Kudos

In that case, it is easier to use a select-option that looks like a parameter. Here is how.

If the user leaves the field empty, the SELECT will pick up all records.



report zrich_0001.

tables: spfli.

data: itab type table of spfli with header line.

<b>select-options: scarrid for spfli-carrid no intervals no-extension.</b>

select carrid cityfrom cityto arrtime
<b>       into corresponding fields of table itab from spfli
            where carrid in scarrid.</b>


loop at itab.

  write:/ itab-carrid, itab-cityfrom, itab-cityto, itab-arrtime.
endloop.


Please make sure to award points for helpful answers and mark you post as solved when solved completely. Thanks.

Regards,

Rich Heilman

0 Kudos

Hi,

Many thanks for reply.

anybody can explain more on Type, Types, Data and Like.

Thanks

J

ferry_lianto
Active Contributor
0 Kudos

Hi Jen,

Perhaps you can do something like this.

AT SELECTION SCREEN ON VALUE REQUEST FOR PCARRID.
    PERFORM VALUES_CARRID.

FORM VALUES_CARRID.

  ...              <-- your logic 

ENDFORM.         " VALUES_CARRID

Hope this will help.

Regards,

Ferry Lianto

aris_hidalgo
Contributor
0 Kudos

Hi,

Please take a look at the example below. This is how I do it in reports:

TYPES: BEGIN OF t_final,

bukrs LIKE bsik-bukrs, "Company Code

lifnr LIKE bsik-lifnr, "Account number of vendor or creditor

hkont LIKE bsik-hkont, "General ledger account

belnr LIKE bsik-belnr, "Accounting document number

gjahr LIKE bsik-gjahr, "Fiscal year

shkzg LIKE bsik-shkzg, "Debit/credit indicator

dmbtr LIKE bsik-dmbtr, "Amount in local currency

sgtxt LIKE bsik-sgtxt, "Item Text

buzei LIKE bsik-buzei, "Number of Line Item

budat LIKE bkpf-budat, "Posting date in the document

bldat LIKE bkpf-bldat, "Document date in document

xblnr LIKE bkpf-xblnr, "Reference document number

bktxt LIKE bkpf-bktxt, "Document header text

name1 LIKE lfa1-name1, "Vendor name

s_dat(10) type c, "Start date(from long text)

e_dat(10) type c, "End date(from long text)

amount1 LIKE bsik-dmbtr, "If 30 days and below

amount2 LIKE bsik-dmbtr, "If > 30 and < 60 days

amount3 LIKE bsik-dmbtr, "If > 60 and < 90 days

amount4 LIKE bsik-dmbtr, "If > 90 and < 120 days

amount5 LIKE bsik-dmbtr, "If > 180 days

END OF t_final.

DATA: it_final TYPE STANDARD TABLE OF t_final.

FIELD-SYMBOLS: <fs_final> LIKE LINE OF it_final.

Regards!

ferry_lianto
Active Contributor
0 Kudos

Anybody can explain more on Type, Types, Data and Like.

Did you check the link on my previous above reply?

http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb2ff3358411d1829f0000e829fbfe/content.htm

Did your <b>Doubt 1 and Doubt 2</b> (original questions) solve?

If they did, please close the thread and reward points as a way to say thanks.

Regards,

Ferry Lianto

Former Member
0 Kudos

Hi Jen,

ABAP distinguishes between types and objects. Types are descriptions that do not occupy memory. Objects are instances of types, and do occupy their own memory space. A type describes the technical attributes of all of the objects with that type.

You can use the addition

TYPE <type>

to refer to any data type <type> that is already known at this point in the program.

DATA <f> TYPE <type>.

The data object <f> has a data type corresponding to the type <type>.

DATA <f> LIKE <obj>.

The data object <f> inherits all of the technical attributes of the data object <obj>.

Take an example :

<b>types</b> : begin of ty_tab,

name(30),

pwd(10),

end of ty_tab.

<b>data</b> : itab <b>like</b> ty_tab.

See here we declared the structure of ty_tab, which do not occupy memory. So if we run this, we will get compile time error like this : Field TY_TAB is unknown. It is neither in one of the specified tables nor defined by a DATA statement.

So in this case u need to correct the error with "TYPE" statement...like this.

<b>types</b> : begin of ty_tab,

name(30),

pwd(10),

end of ty_tab.

<b>data</b> : itab <b>type</b> ty_tab.

Hope u understood the difference. Data is the keyword used for declaring the data types as well as data objects.

If found helpful, please do reward.

Former Member
0 Kudos

types: begin of structtab,

name(10) type c,

age type i,

end of structtab. " creating structure

type : tab type table of structtab. " creating type

data: itab type tab. " creating internal table

or you can directly say

data : itab type table of structtab. " creating internal table

hope you can understand types , type, data.

creating work area :

data: wa like line of itab.

or

data : wa type structtab.

Message was edited by: Dana Boopalam

Former Member
0 Kudos

Hi Jen,

<b>DOUBT 1</b>

Consider this dummy code. I will explain it there.

Using the <b>TYPES</b> we can declare a structure in our

program and this structure can be used for declaring Internal Tables and Work Areas of of type this structure.

The fields in the structure can be predefined data types(C, N, D, T) or form the Data Dictionary.


TYPES :  BEGIN OF str_mara,
         matnr TYPE mara-matnr,
         mtart TYPE mara-mtart,
         mbrsh TYPE mara-mbrsh,
         matkl TYPE mara-matkl,
         qnty  TYPE p DECIMALS 2,
         END OF str_mara.

Here in this structure declaration I have used <b>TYPE</b>

to refer to a field which already exists(i.e in Data Dictionary) that can even be done using <b>LIKE</b>(LIKE is something like inherit the attributes of the referenced element). I will expalin how LIKE can be used.

Consider now I declare an Internal table using the structure I have created.

<b>DATA : it_mara1 TYPE STANDARD TABLE OF str_mara</b>

When I declared a structure using <b>TYPES</b> it was just defined, now when I declare it using <b>DATA</b> statement, its created in the program memory and space is allocated for it.

Now <b>it_mara</b> has been defined previously in the same program. I can declare another Internal Table of type structure <b>str_mara</b> in my program using <b>LIKE</b>

<b>DATA : it_mara2 LIKE it_mara1.</b>

Thus it_mara2 has same attributes as that of it_mara1.

Now I can declare a work area using the structure or predefined Internal table(using LIKE).

<b>DATA : wa_mara TYPE str_mara.</b>

or

<b>DATA : wa_mara LIKE LINE OF it_mara1.</b>

Dont make use of <b>LIKE</b> use <b>TYPE</b> instead.

Regards,

Arun Sambargi.

Former Member
0 Kudos

Abt Doubr 1:

Type statement is used to create structure for custom data types, so that they can be declared again and again. Data statement is used for declaring variables. like is used to give the variable as the same structure as of any field in any pre-declared table. Types is used to declare variable of generic types.

like:

Data: var1 type i.

Data var2 like mara-matnr.

Def. of internal table:

Data: begin of itab occurs 0,

a1 type c,

a2 type f,

end of itab.

Def of Work Area:

data: begin of itab1,

a1 type c,

a2 type f,

end of itab1.

__________________________________________________

Doubt 2:

SELECT-OPTIONS

INITIALIZATION.

TABLES: SPFLI.

SELECT-OPTIONS: PARRTIME FOR SPFLI-ARRTIME.

PARRTIME-SIGN = 'I'.

PARRTIME-OPTION = 'BT'.

PARRTIME-LOW = '200000'.

PARRTIME-HIGH = '240000'.

Former Member
0 Kudos

hi

TYPE, you assign datatype directly to the data object while declaring. LIKE,you assign the datatype of another object to the declaring data object. The datatype is referenced indirectly.

or

Type is a keyword used to refer to a data type whereas Like is a keyword used to copy the existing properties of already existing data object.

you can define internal table as:

data: BEGIN OF STRUCT occurs 0,

CARRID LIKE SPFLI-CARRID,

CITYFROM LIKE SPFLI-CITYFROM,

CITYTO LIKE SPFLI-CITYTO,

ARRTIME LIKE SPFLI-ARRTIME,

END OF STRUCT.

you can define work area for internal table as:

data:struct1 like table of struct.