Application Development and Automation 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: 
Read only

Problem in type declaration

Former Member
0 Likes
879

Hi All,

I have to declare a type like below:

types: BEGIN OF ty_cm_record ,

rectype TYPE c,

compid(3) TYPE c, "Distribution Channel

filler TYPE c VALUE 'C',

count(5) TYPE n, "record count

distro(3) TYPE c, "Second key - Distribution

end of ty_cm_records.

data:it_cm_records type standard table of ty_cm_record.

above i have to declare a default value of filler as 'C' in type declaration .But i am getting error as ' expected after C.

We can do it like below:

types: BEGIN OF ty_cm_record occurs 0,

rectype TYPE c,

compid(3) TYPE c, "Distribution Channel

filler TYPE c VALUE 'C',

count(5) TYPE n, "record count

distro(3) TYPE c, "Second key - Distribution

end of ty_cm_records.

but this type declaration is not permitted in our coding standard

Please sugest the solution.

Thanks

Mohit Khandelwal

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
855

Then you have to use a global Constant for Filler and assign it wherever it is used.

CONSTANTS filler TYPE C VALUE 'C'.

Regards

Karthik D

8 REPLIES 8
Read only

Former Member
0 Likes
856

Then you have to use a global Constant for Filler and assign it wherever it is used.

CONSTANTS filler TYPE C VALUE 'C'.

Regards

Karthik D

Read only

0 Likes
855

hi ,

But how i would assign this feild to fiiler to my internal table once i declared filler as a constant.

Thanks

Mohit

Read only

0 Likes
855

How you are fetching entries into your internal table, if you add record by record you can assign it to the workarea before inserting it into the internal table, if you are fetching records using select statement, write a loop after it to set all filler to the value of filler constant.

Regards

Karthik D

Read only

Former Member
0 Likes
855

Hi,


DATA: BEGIN OF ty_cm_records OCCURS 0,
rectype TYPE c,
compid(3) TYPE c, "Distribution Channel
filler TYPE c VALUE 'C',
count(5) TYPE n, "record count
distro(3) TYPE c, "Second key - Distribution
END OF ty_cm_records.

as you donot want to use this...better declare filler as constant...like the above post...

Read only

0 Likes
855

hi,

thanks for your sugestion.but this field filler should be present in my table ty_cm_reocrds.

Thanks

Mohit

Read only

Former Member
0 Likes
855

Hi,

have u seen what happens when u use OCCURS 0 and why u cannot use 'VALUES' in Types....


types: BEGIN OF ty_cm_record occurs 0,
rectype TYPE c,
compid(3) TYPE c, "Distribution Channel
filler TYPE c VALUE 'C',
count(5) TYPE n, "record count
distro(3) TYPE c, "Second key - Distribution
end of ty_cm_records.

This is what is getting populated in its *header* part 
RECTYPE	                                   
COMPID	                                   
FILLER	                                   	C
COUNT	                                   	00000
DISTRO	                                   

and u cannot use values in Types because it is a type...it doesnot contain any data....

and if u use

data:it_cm_records type standard table of ty_cm_record.

there is no header part....

so define a header line with the initial value...


DATA: BEGIN OF ty_cm_record,
        rectype TYPE c,
        compid(3) TYPE c, 
        filler TYPE c VALUE 'C',
        count(5) TYPE n, 
        distro(3) TYPE c, 
END OF ty_cm_record.

DATA : it_cm_records LIKE STANDARD TABLE OF ty_cm_record.

see both the ty_cm_record. and it_cm_records..

Read only

Former Member
0 Likes
855

Hi,

I think we can not assign values in type declarations. you can declare one work area and assign the values.

Try like this:

types: BEGIN OF ty_cm_record ,

rectype TYPE c,

compid(3) TYPE c,

filler TYPE C,

count(5) TYPE n, "record count

distro(3) TYPE c, "Second key - Distribution

end of ty_cm_record.

data:it_cm_records type ty_cm_record.

it_cm_records-filler = 'C'.

Regards,

Bhaskar

Read only

Former Member
0 Likes
855

TYPES: BEGIN OF TY_CM_RECORD,

RECTYPE TYPE C,

COMPID(3) TYPE C, "Distribution Channel

FILLER TYPE C,

COUNT(5) TYPE N, "record count

DISTRO(3) TYPE C, "Second key - Distribution

END OF TY_CM_RECORD.

DATA:IT_CM_RECORDS TYPE STANDARD TABLE OF TY_CM_RECORD WITH HEADER LINE.

IT_CM_RECORDS-FILLER = 'C'.