sy-subrc & write

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

Post Reply
Palmik777
Posts: 2
Joined: Wed Jun 05, 2013 6:21 am

sy-subrc & write

Post by Palmik777 » Wed Jun 05, 2013 7:20 am

Hello,
Im starting with ABAP and I need some help with my first steps. Could you please help me to clarify code below?

I created database of Tcodes in SE11 and I would like to create report but this report doesnt work as expected.

In database I can see 6records (six lines)

Current code :

Code: Select all

  1	report Z_TRANSACTIONLISTTEST2.
  2	tables ZTRANSACTIONLIST.
  3	select * from ZTRANSACTIONLIST where TCODE = 'SE80'.
  4	 write / ZTRANSACTIONLIST-ID.
  5	 write ZTRANSACTIONLIST-TCODE.
  6	* write ZTRANSACTIONLIST-SOURCE.
  7	*      /  ZTRANSACTIONLIST-ID.
  8	endselect.
  9	                                                                                                                                                                                                                                                               
 10	 uline.
 11	      if sy-subrc <> 0.
 12	       write: 'no records found'.
 13	      endif.
 14	                                                                                                                                                                                                                                                               
 15	      if sy-subrc = 1.
 16	       write : 'Only one record found'.
 17	      endif.
 18	                                                                                                                                                                                                                                                               
 19	      if sy-subrc < 10.
 20	       write / sy-dbcnt.
 21	       write: 'records found'.
 22	      endif.
output showed me:

00000000 SE80

1 records found


Question is:
1) why report showed me "1 records found"? I thought that line 15 specify to show "Only one record found". I tried change number in line 15 from = 1 to =6 (records in table) but still I get ecaxtly same output 1 records found
2) I commented on line 3 "where TCODE = 'SE80'." - I got list of all records (6 lines):

00000001 SE09
00000002 SE10
00000000 SE11
00000000 SE38
00000000 SE80
00000000 SYST STRUKTUR

than I uncoment line sixth line and I got 8 lines in output because ZTRANSACTIONLIST-SOURCE is showed under TCODE - why is showed under TCODE? I would like to show near every TCODE, not under...


00000001 SE09
00000002 SE10
TEST
00000000 SE11
ABAP BOOK, GOOGLE
00000000 SE38
00000000 SE80
00000000 SYST STRUKTUR



Thank you

Gothmog
Posts: 1952
Joined: Wed Sep 12, 2007 4:46 am
Location: Probably not home

Re: sy-subrc & write

Post by Gothmog » Thu Jun 06, 2013 3:38 am

For your first question, sy-subrc is a return code, generally indicating if the instruction executed was successful.
F1 will give you the values depending on the instruction - usually, 0 for success, 4 or 8 for an error.
What you wanted to test was the value sy-dbcnt.

For your second question, what is the size of ZTRANSACTIONLIST-SOURCE, and does it fit in the line-size of your report?
(tip : you can adjust this line size up to 1023 characters using the LINE-SIZE addition of the REPORT statement)
68 74 74 70 3a 2f 2f 74 69 6e 79 75 72 6c 2e 63 6f 6d 2f 62 64 6f 37 6d 77 67

Palmik777
Posts: 2
Joined: Wed Jun 05, 2013 6:21 am

Re: sy-subrc & write

Post by Palmik777 » Fri Jun 07, 2013 4:39 am

1) understand now and its solved. Thank you

I wanted: If there is not any record - show "No records found". If there is one record, show "Only one record found", if there is more than one record, show "xx records found" and now my code showed exactly what i want:

Code: Select all

9	REPORT  Z_TRANSACTIONLIST LINE-SIZE 500.
 10	tables ZTRANSACTIONLIST.
 11	select * from ZTRANSACTIONLIST where TCODE > 'S'.
 12	    write / ZTRANSACTIONLIST-ID.
 13	    write ZTRANSACTIONLIST-TCODE.
 14	    write ZTRANSACTIONLIST-SOURCE.
 15	*      /  ZTRANSACTIONLIST-ID.
 16	   endselect.
 17	                                                                                                                                                                                                                                                               
 18	    uline.
 19	         if sy-subrc <> 0.
 20	          write: 'no records found'.
 21	         endif.
 22	                                                                                                                                                                                                                                                               
 23	         if sy-dbcnt = 1.
 24	          write : 'Only one record found'.
 25	         endif.
 26	                                                                                                                                                                                                                                                               
 27	         if sy-dbcnt > 1.
 28	          write / sy-dbcnt.
 29	          write: 'records found'.
 30	         endif.

2) ZTRANSACTIONLIST-SOURCE - is CHAR Lenght 255, decimal places 0 (information from SE11). I tried proposed LINE-SIZE 500 and it works now, thank you !!!.

So, both are solved now and I have next questions. Do you know if somewhere exist better place for my question? (like IRC or other...)

YuriT
Posts: 885
Joined: Fri Feb 03, 2006 6:40 am
Location: Basel/Riga

Re: sy-subrc & write

Post by YuriT » Mon Jun 10, 2013 3:36 am

Nope, this is the only right place

Post Reply