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 with write statement

Former Member
0 Likes
1,157

I need some help on the following program. when I run this program in debug mode and click on the "it_uct200g" in the select statement, I see the data that was selected. the problem is that the if statement is not working noe is the last write statement. when you click on these fields there is nothing data be displayed. I am not sure why I would see data when I click on the table in the select statement and not when I clicked on the separate fields within the table.

REPORT ZTEST3.

TABLES:

UCT200G.

TYPES: BEGIN OF ty_uct200g,

siselid TYPE uct200g-siselid,

fieldname TYPE uct200g-fieldname,

sisel TYPE uct200g-sisel,

END OF ty_uct200g.

data: it_uct200g TYPE STANDARD TABLE OF ty_uct200g with header line.

*

----


*START-OF-SELECTION *

----


START-OF-SELECTION.

select siselid fieldname sisel

FROM UCT200G INTO TABLE it_uct200g

WHERE fieldname = '/BIC/ZVTYPE1 '

AND sisel = 'PLANNING '.

write: / 'process successful return code = ', sy-subrc.

if it_uct200g-sisel = 'PLANNING '.

write: / ' the field is filled'.

endif.

write: / '****', it_uct200g-siselid,'',it_uct200g-fieldname,'*',it_uct200g-sisel.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,112

I am having problems setting up the program to use work areas. I have included part of the program. would it be possible for someone to fix what I have coded to have the work aresa properly defined.

thanks in advance

REPORT ZTEST3.

TYPES: BEGIN OF ty_uct200g,

siselid TYPE uct200g-siselid,

fieldname TYPE uct200g-fieldname,

sisel TYPE uct200g-sisel,

END OF ty_uct200g.

data: it_uct200g type ty_uct200g.

data: wa_200g type ty_uct200g.

----


*START-OF-SELECTION *

----


START-OF-SELECTION.

select siselid fieldname sisel

FROM UCT200G INTO wa_200g

WHERE fieldname = '/BIC/ZVTYPE1 '

AND sisel = 'PLANNING '.

  • write: / 'process successful return code = ', sy-subrc.

loop at ty_uct200g into wa_200g.

write: / 'uct200g****', wa_200g-siselid,'',wa_200g-fieldname,'*',wa_200g-sisel.

endloop.

*

11 REPLIES 11
Read only

Former Member
0 Likes
1,112

That's probably because you are looking at the header line. You may want to loop at the table and then write, or read the table with an index of 1.

Read only

0 Likes
1,112

ur write statement is not in loop so it checks the last record present in headerline ... if the last record is not the record in if statement then u dont fetch record.

or write select statement like

select fields from dbtable into itab where ......

if field = 'PLANNING'.

write: / 'UR STATEMENT'.

endselect.

or as rich told put it in loop at itab.

Read only

RichHeilman
Developer Advocate
Developer Advocate
0 Likes
1,112

The reason is that you need to read the table, or loop at it to put something in the header line of the table.



REPORT ZTEST3.
TABLES:
UCT200G.

TYPES: BEGIN OF ty_uct200g,
siselid TYPE uct200g-siselid,
fieldname TYPE uct200g-fieldname,
sisel TYPE uct200g-sisel,
END OF ty_uct200g.



data: it_uct200g TYPE STANDARD TABLE OF ty_uct200g with header line.
*
*-------------------------------------------------------*
*START-OF-SELECTION *
*-------------------------------------------------------*
START-OF-SELECTION.

select siselid fieldname sisel
FROM UCT200G INTO TABLE it_uct200g
WHERE fieldname = '/BIC/ZVTYPE1 '
AND sisel = 'PLANNING '.

write: / 'process successful return code = ', sy-subrc.

<b>loop at it_uct200g.</b>

if it_uct200g-sisel = 'PLANNING '.
write: / ' the field is filled'.
endif.

write: / '*****', it_uct200g-siselid,'*',it_uct200g-fieldname,'*',it_uct200g-sisel.
<b>
endloop.</b>

You are doing an array fetch, which means that you are getting all of the data into the internal table all at one shot. You have to then loop at the table to read the records or use the READ TABLE statement to read records directly. This puts the data into the header line where you can access the data.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,112

I have the program working and it is doing everything that I want it to do. I created this as a program to be able to test it. I now want to copy this code into a method and I am getting a lot of errors on the tables relating to OO context. Is it possible to turn this code into a finction and call this function from the method or do I have to re-code all of the tables to make them conform to OO standards.

thanks in advance

Read only

0 Likes
1,112

One big thing is that you are not allow to use header lines in OO, just use work areas instead. Then it should be fine.

Please remember to award points for helpful answers and mark your posta as solved when solved completely. Thanks.

Regards,

Rich Heilman

Read only

Former Member
0 Likes
1,112

can I use the work areas in my test program and after it is tested and correct, copy the code to the method? it is much easier to test the program than the method.

Read only

0 Likes
1,112

Hi ,

Just try to change the definition of your internal table as without header line.

<i>data: it_uct200g TYPE STANDARD TABLE OF ty_uct200g with header line.</i>

TO

<b>data: it_uct200g TYPE STANDARD TABLE OF ty_uct200g.</b>

and loop thru the table or read the table whenever you want to access the contents of the table.

Regards,

Raghav

Read only

Former Member
0 Likes
1,113

I am having problems setting up the program to use work areas. I have included part of the program. would it be possible for someone to fix what I have coded to have the work aresa properly defined.

thanks in advance

REPORT ZTEST3.

TYPES: BEGIN OF ty_uct200g,

siselid TYPE uct200g-siselid,

fieldname TYPE uct200g-fieldname,

sisel TYPE uct200g-sisel,

END OF ty_uct200g.

data: it_uct200g type ty_uct200g.

data: wa_200g type ty_uct200g.

----


*START-OF-SELECTION *

----


START-OF-SELECTION.

select siselid fieldname sisel

FROM UCT200G INTO wa_200g

WHERE fieldname = '/BIC/ZVTYPE1 '

AND sisel = 'PLANNING '.

  • write: / 'process successful return code = ', sy-subrc.

loop at ty_uct200g into wa_200g.

write: / 'uct200g****', wa_200g-siselid,'',wa_200g-fieldname,'*',wa_200g-sisel.

endloop.

*

Read only

0 Likes
1,112

Hi Tim. change like so.




report ztest3.
types: begin of ty_uct200g,
       siselid type uct200g-siselid,
       fieldname type uct200g-fieldname,
       sisel type uct200g-sisel,
       end of ty_uct200g.
<b>data: it_uct200g type table of ty_uct200g.
data: wa_200g like line of it_uct200g.</b>
*----------------------------------------------------------------------*
*START-OF-SELECTION *
*----------------------------------------------------------------------*
start-of-selection.

  select siselid fieldname sisel
  from uct200g into wa_200g
  where fieldname = '/BIC/ZVTYPE1 '
  and sisel = 'PLANNING '.
* write: / 'process successful return code = ', sy-subrc.
    loop at ty_uct200g into wa_200g.
     write: / 'uct200g*****', wa_200g-siselid,'*',wa_200g-fieldname,'*',
       wa_200g-sisel.
    endloop.
*

Please make sure to award points for helpful answers and mark your post as solved when you question has been ansewred.

Thanks.

Regards

Rich HEilman

Message was edited by: Rich Heilman

Read only

Former Member
0 Likes
1,112

Rich,

I tried your suggestion and receive the following

<b>"the field "TY_UCT200G" is unknown, but there is a field with the similar name "IT_UCT200G".</b>

Read only

0 Likes
1,112

I have since edited the post. Make sure that you work area is defined like this. Like line of the itab not the type.

data: wa_200g like line of <b>it_</b>uct200g.

Regards,

Rich Heilman