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

structure declaration

Former Member
0 Likes
4,617

hi this is pradeep, and expecting help from u.

the below declared is structure to output data.

data : begin of st_report,

plant like zpgm_parts-werks,

pgmat like zpgm_parts-pgm_matnr, " pgm material

finmat like zpgm_parts-fin_matnr,"finished material

mvt543 like mseg-bwart, "543/544 movement type

name1 like lfa1-name1, " vendor

ebeln like mseg-ebeln, "po#

ebelp like mseg-ebelp, "po item #

mbl543 like mseg-mblnr, "mat doc# of 543/544

dat543 like mkpf-budat, " date of 543/544

mvt101 like mseg-bwart, "101/102 movement type

mbl101 like mseg-mblnr, "mat doc# of 101/102

dat101 like mkpf-budat, "date of 101/102

mvt541 like mseg-bwart, "541/542 movement type

mbl541 like mseg-mblnr, "mat doc# of 541/542

dat541 like mkpf-budat, "date of 541/542

xabln like mkpf-xabln,

zeile like mseg-zeile,

end of st_report.

in what way it is different from declaring int table.and when structure declaration can be used.

one more question

these r the constants in my report and r being refered to the field mseg-bwart, why it was done so

constants: c_101 like mseg-bwart value '101',

c_102 like mseg-bwart value '102',

c_544 like mseg-bwart value '544',

c_543 like mseg-bwart value '543',

c_541 like mseg-bwart value '541',

c_542 like mseg-bwart value '542',

c_122 like mseg-bwart value '122'.

thanku

pradeep.

6 REPLIES 6
Read only

Former Member
0 Likes
943

Hi pradeep,

1. in what way it is different from declaring int table.and when structure declaration can be used.

The only difference is OCCURS 0

2. It would be an internal table if the

declaration was like this.

data : begin of st_report <b>OCCURS 0,</b>

3.

these r the constants in my report and r being refered to the field mseg-bwart, why it was done so

BWART = Movement Type

4. This field can take various values,

depending upon the business transaction.

5. In your report, there might be

many movement types (BWART)

required in SQL.

6. So instead of hardcoding in SQL itself,

we can hardcode in the CONSTANT declaration,

and use this constant in other parts of the code.

7. In this way, if the value of BWART needs to be changed,

we need to change only the declaration of the CONSTANT,

(and not other parts of the abap code, where it might be used)

regards,

amit m.

Read only

Former Member
0 Likes
943

Hi

If you have to declare a table:

data : begin of st_report OCCURS N,

plant like zpgm_parts-werks,

pgmat like zpgm_parts-pgm_matnr, " pgm material

finmat like zpgm_parts-fin_matnr,"finished material

mvt543 like mseg-bwart, "543/544 movement type

name1 like lfa1-name1, " vendor

ebeln like mseg-ebeln, "po#

ebelp like mseg-ebelp, "po item #

mbl543 like mseg-mblnr, "mat doc# of 543/544

dat543 like mkpf-budat, " date of 543/544

mvt101 like mseg-bwart, "101/102 movement type

mbl101 like mseg-mblnr, "mat doc# of 101/102

dat101 like mkpf-budat, "date of 101/102

mvt541 like mseg-bwart, "541/542 movement type

mbl541 like mseg-mblnr, "mat doc# of 541/542

dat541 like mkpf-budat, "date of 541/542

xabln like mkpf-xabln,

zeile like mseg-zeile,

end of st_report.

So the declarations are similar excpet for option OCCUR

OCCUR N initializes the space of memory to can contain almost N records.

Infact you should remember the structure is flat.

It uses a structure when it needs a structureted variable, for example if it needs read a table without header line.

That's the right way to declare a constant, because in this way the variable can't be changed at runtime.

Max

Read only

0 Likes
943

It will create a structe with the needed fields..

DATA: BEGIN OF i_sub <b>occurs 0</b> ,

mandt TYPE afvgd-mandt,

aufpl TYPE afvgd-aufpl,

END OF i_sub.

Add occurs 0. Now your Internal table is ready.

Read only

Former Member
0 Likes
943

Hi Pradeep,

A structure declaration will always be with types, like

<b>Types: begin of ty_tab,

vbeln like vbak-vbeln,

vgbel like vbak-vgbel,

ebeln like ekko-ebeln,

end of ty_tab.</b>

If you want to create an internal table with respect to this structure then you declare like this

<b>Data: i_tab type standard table of ty_tab.</b>

This declaration will create an internal table without an header line.

<b>Constants:</b>

When you assign a value of type constant, this particular value cannot be changed in the program. Its like a fixed value.

<b>Constants: c_a value 'A'.</b>

The value of c_a will be 'A' throughout the program. In the program they are checking the value to be equal to the constant they have declared. They are checking if the value is same.

Hope this soves ur issue. Reward if useful.

Regards,

Tushar

Message was edited by: Tushar Marshall Dass

Read only

Former Member
0 Likes
943

Hi Pradheep,

<i>in what way it is different from declaring int table.and when structure declaration can be used.</i>

If you include <b> OCCURS 0 </b> then structure will become itab.Structure is used for many of the itabs.

Example :

DATA : Begin of address,

name type string,

loc type string,

END of Address.

<b>

DATA : Staff_address TYPE Address occurs 0.

DATA : Student_address TYPE Address occurs 0.

</b>

<i> the constants in my report and r being refered to the field mseg-bwart, why it was done so

</i>

Unlike variables Constant can't be changed while execution.

Rgds,

Jothi.

Pl close the thread if your problem is solved.

Read only

Former Member
0 Likes
943

Hi,

The addition OCCURS 0 will change the structure as internal table.

That is now the declaration you gave will act as a structure, that is it is similar to a line. But not a table. But if you want this to act as a table. Declare as I said above.

i.e,

data: begin of sp_report occurs 0,

...

...

end of sp_report.

But if you want to declare an internal table, always do it like this,

types: begin of ty_rep

...

...

end of ty_rep.

DATA: <struct> type ty_rep, "structure

<internal_table> like standard table of <struct>.

"internal table

Regs,

Venkat Ramanan