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

Simple Code

Former Member
0 Likes
1,076

Hi experts,

What is the meaning/use of this code?

DATA BEGIN OF MY_TEXT OCCURS 1.

INCLUDE STRUCTURE BAPITGB.

DATA END OF MY_TEXT.

Regards,

Nmc

1 ACCEPTED SOLUTION
Read only

former_member150733
Contributor
0 Likes
1,027

This creates an internal table with name MY_TEXT and this internal table has the structure of BAPITGB.

Regards,

Anish Thomas

10 REPLIES 10
Read only

former_member150733
Contributor
0 Likes
1,028

This creates an internal table with name MY_TEXT and this internal table has the structure of BAPITGB.

Regards,

Anish Thomas

Read only

Former Member
0 Likes
1,027

The idea behind this is to reuse the structure created the dictionary while creating the internal table.

This could be as simple as

DATA : MY_TEXT TYPE TABLE OF BAPITGB.

Regards,

Ravi

Note - Please mark all the helpful answers

Read only

Former Member
0 Likes
1,027

The code craetes an internal table with one component named LINE. The component LINE is character type with length 255. This internal table can be used is a program to carry a text in 255 character format.

The syntax 'include structure' creates components in internal table. In this case the structure BAPITGB has only one componet called LINE.

Read only

Former Member
0 Likes
1,027

Hi experts,

What is the meaning of the occurs 1 in the code?

Regards,

Nmc

Read only

0 Likes
1,027

OCCURS clause is telling the system the expected number of rows in the internal table.

however, with the latest versions this syntax is not necessary any more and will become obsolete eventually.

Regards,

Ravi

Read only

Former Member
0 Likes
1,027

Hi Marc,

The main purpose of this is you can add more fields in addtion to included structure to your internal table.For example.

For your internal table "itab" you want to add all fields structure "A" & some of the fields from Structure B.

Suppose if structure A is having 100 fields and from B you are adding 3 fields.

In practical you can not declare all 100 fields from A and 3 fields form B in your internal table.

For that reason Include structure is useful.See the below code.

DATA BEGIN OF MY_TEXT OCCURS 1.

INCLUDE STRUCTURE BAPITGB.

XYZ like mara-matnr,

klm like viqmma-qmnum,

ghi like kna1-kunnr,

DATA END OF MY_TEXT.

Pls. reward points if it is helpful......

Read only

Former Member
0 Likes
1,027

Hi experts,

I can't seem to know what's wrong with the code

Syntax error:

"MY_RETURN" cannot be converted to a character-type field

Here is the code:

REPORT z_test_nmc5.

----


  • DATA/VARIABLE DECLARATION *

----


DATA: my_id LIKE bapiret2-id, " Messages, Message Class

my_number LIKE bapiret2-number, " Messages, Message Number

my_textformat LIKE bapitga-textformat, " Format of documentation texts when read by BAPIs

my_message_v1 LIKE bapiret2-message_v1, " Message Variables

my_message LIKE bapiret2-message, " Message Text

my_return TYPE bapiret2. " Return Parameter

DATA BEGIN OF my_text OCCURS 1.

INCLUDE STRUCTURE bapitgb.

DATA END OF my_text.

----


  • CONSTANTS DECLARATION *

----


CONSTANTS: c_f1(2) TYPE c VALUE 'F1',

c_024 TYPE i VALUE '024',

c_asc(3) TYPE c VALUE 'ASC',

c_0001(4) TYPE c VALUE '0001'.

----


  • START-OF-SELECTION *

----


START-OF-SELECTION.

  • Enter values in object

my_id = c_f1.

my_number = c_024.

my_textformat = c_asc.

my_message_v1 = c_0001.

  • BAPI Call

CALL FUNCTION 'BAPI_MESSAGE_GETDETAIL'

EXPORTING

id = my_id

number = my_number

textformat = my_textformat

message_v1 = my_message_v1

IMPORTING

message = my_message

return = my_return

TABLES

text = my_text.

  • Print Results

WRITE:/ 'Input' COLOR 5.

WRITE:/ 'my_id:', my_id.

WRITE:/ 'my_number:', my_number.

WRITE:/ 'my_textformat:', my_textformat.

WRITE:/ 'Output' COLOR 5.

WRITE:/ 'my_message:', my_message.

WRITE:/ 'my_return:', my_return. <----


Syntax Error

WRITE:/ 'Text output' COLOR 5.

LOOP AT my_text.

WRITE:/ my_text.

ENDLOOP.

Regards,

Nmc

Read only

0 Likes
1,027

Hullo,

I'm guessing you're using a UNICODE version of SAP (4.7 or higher)..

Your problem is that you're getting a syntax errror when trying to write my_return.

your problem is that my_return is not a single variable but a structured variable (or workarea). IIRC as soon as there are non-c type fields in a structure you can't write the whole structure as one big variable (hence the error: "cannot be converted to a character-type field").

the following code:

data: ...
      ...
      my_return TYPE bapiret2. " Return Parameter

is your problem.

You should declare the my_return vatiable according to the field of bapiret2 you want to use instead of the whole structure. Just like you have done with all the other 'my_...' variables.

Or, if you meant to use the whole structure, you'll have to write each field separately, insted of the whole structure in one go.

Hope this helps.

Read only

anversha_s
Active Contributor
0 Likes
1,027

hi,

<b>* This is a way to Build internal table and work area from existing internal table,

  • adding additional fields</b>

<i>chk this code.</i>

TYPES: BEGIN OF t_repdata.
        INCLUDE STRUCTURE tab_ekpo.  "could include EKKO table itself!!
TYPES: bukrs  TYPE ekpo-werks,
       bstyp  TYPE ekpo-bukrs.
TYPES: END OF t_repdata.

DATA: it_repdata TYPE STANDARD TABLE OF t_repdata INITIAL SIZE 0,   "itab
      wa_repdata TYPE t_repdata.                 "work area (header line)

rgds

Anver

Read only

Former Member
0 Likes
1,027

Hi experts,

My problem has not been solved. Need help.

Regards,

Nmc