2013 Aug 26 2:59 PM
Hello developers,
I am not an ABAP developer, but I want to write a simple program with selection screen, which extracts some data from
the database. Let's say table KNA1, or a table join KNA1+KNB1.
In fact I made a lot of Querys in SQVI and SQ01, but I want to write a real program.
Thanks in advance
ILIAN
2013 Aug 26 3:03 PM
Hi Ilian,
Simple program only wrote "Helo Word"
You will need to write a SELECT statement, but you will need also to print your data into the screen. This second part is the more complex. If you would like to print as ALV grid, you will need to use Oo concept or function module ..
I'm sure you could find a lot of place with example of simple Oo ALV Grid with extract of one table.
regards
Fred
2013 Aug 26 4:39 PM
2013 Aug 26 3:54 PM
hello
Here is a link to write simple SQL statements using ABAP
http://www.saphub.com/abap-tutorial/selective-reading-using-open-sql/
Here is a link to write a simple ALV program -
http://wiki.sdn.sap.com/wiki/display/ABAP/Simple+ALV+list+for+beginners
best regards,
swanand
2013 Aug 26 4:23 PM
Transaction ABAPDOCU
Just invest some time on it, and you'll know more than some of us do.
2013 Aug 26 4:24 PM
Hello,
Please use the following link..
https://www.google.co.in/#fp=40855a382358404c&q=selection%20screen%20in%20abap%20tutorial
BR
Chandra..
2013 Aug 27 8:00 AM
hi,
i understand that you know about selection screen and databse. So write the simple program try this.
go to se38 type in the program name and press create.
type the following code.....
parameters: p_kunnr type kunnr.
data: t_kna1 type table of kna1, internal table to store the data
w_kna1 type kna1 " work area
start of selection.
select * from kna1 into table t_kna1 where kunnr = p_kunnr.
here you can give appropritate heading for colums using the wirte statement given below.
eg: write : / at 20 text-001. (now double click on text-001 and wirte the text required)
loop at t_kna1 into w_kna1.
write : / at 20 w_kna1-kunnr ( or write : / w_kna1-kunnr under text-001) (both ways u can use)
at 40 w_kna1-land1
.
.
. you can write all the fields which u want to display
.
.
endloop
regards
Suneesh Thampi
2013 Aug 27 9:46 AM
Hi,
Below is the cod efor simple report program with selection to display the data from the database.
TABLES: vbrk.
TYPES: BEGIN OF ty_vbrk,
vbeln LIKE vbrk-vbeln,
fkart LIKE vbrk-fkart,
fktyp LIKE vbrk-fktyp,
vkorg LIKE vbrk-vkorg,
knumv LIKE vbrk-knumv,
fkdat LIKE vbrk-fkdat,
END OF ty_vbrk.
DATA: t_vbrk TYPE TABLE OF ty_vbrk,
x_vbrk TYPE ty_vbrk.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-000.
SELECT-OPTIONS: so_vbeln FOR vbrk-vbeln.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
SELECT
vbeln
fkart
fktyp
vkorg
knumv
fkdat FROM vbrk
INTO TABLE t_vbrk
WHERE vbeln IN so_vbeln.
LOOP AT t_vbrk INTO x_vbrk.
WRITE: /
x_vbrk-vbeln,
x_vbrk-fkart, 19 sy-vline,
x_vbrk-fktyp, 39 sy-vline,
x_vbrk-vkorg, 59 sy-vline,
x_vbrk-knumv, 79 sy-vline,
x_vbrk-fkdat, 99 sy-vline.
ENDLOOP.
Regards,
Riju Thomas.
2013 Aug 27 9:52 AM
Why do you use the TABLES sentence at the start of your "program"? It's an obsolete sentence, and you can use "x_vbrk-vbeln" for your SELECT-OPTION parameter.
Anyways, if the original poster wants to learn some ABAP, why to provide him with our code if SAP did it itself through the ABAPDOCU transaction? That transaction has the program, the documentation and the samples at hand... We can flood this thread with tons of pieces of code, and it will still been less useful than a single sight to the ABAPDOCU transaction...
Teach to fish, and don't feed fish to hungry people if they are not in a hurry.
2013 Aug 27 11:31 AM
Thanks everyone,
I forgot to mention that I have experience with many other languages, but ABAP is something different
I am almost ready with my program.
Thanks for all the replys
Best regards
ILIAN
2013 Aug 27 1:44 PM
2013 Aug 28 8:03 AM
*&---------------------------------------------------------------------*
*& Report Z_SIMPLE_PROGRAM
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT Z_SIMPLE_PROGRAM.
SELECTION-SCREEN BEGIN OF SCREEN 500.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TIT1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN POSITION 20.
PARAMETERS P1_BUKRS LIKE knb1-bukrs.
SELECTION-SCREEN COMMENT 1(12) COM1 FOR FIELD P1_BUKRS.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK B1.
TIT1 = 'Fields'.
COM1 = 'Company code'.
SELECTION-SCREEN END OF SCREEN 500.
DATA: BEGIN OF gwa_customer,
kunnr TYPE kna1-kunnr,
name1 TYPE kna1-name1,
name2 TYPE kna1-name2,
ort01 TYPE kna1-ort01,
adrnr TYPE kna1-adrnr,
bukrs TYPE knb1-bukrs,
END OF gwa_customer,
itab LIKE SORTED TABLE OF gwa_customer
WITH NON-UNIQUE KEY kunnr.
CALL SELECTION-SCREEN '0500' .
SELECT kna1~kunnr kna1~name1 kna1~name2 kna1~ort01 kna1~adrnr knb1~bukrs
INTO CORRESPONDING FIELDS OF TABLE itab
FROM kna1
JOIN knb1 ON kna1~kunnr = knb1~kunnr
WHERE knb1~bukrs = p1_bukrs.
LOOP AT itab INTO gwa_customer.
WRITE: / gwa_customer-kunnr, gwa_customer-name1,
gwa_customer-name2, gwa_customer-ort01,
gwa_customer-adrnr, gwa_customer-bukrs.
ENDLOOP.
Now I have to change the output to ALV. It seems not an easy task to do
Cheers!
2013 Aug 28 9:00 AM
Few suggestions, if you allow me to do them:
1- the selection screen should be simplified: you can use a text symbol for the block title (just change your TIT1 with "text-001" or similar. Once you'll do that, double click over the 001 and the system will ask you to create the text symbol.
2- you don't need to add a comment to name your parameter. Once the program has been saved, you can go to the text menu and seek the parameter texts. There you can change your P1_BUKRS for a text, and your translation will be easier.
3- you don't need to assign a number to the selection screen. By default, the system will create the screen from your code and assign the number 1000 to it.
And a comment about readibility (this word exists?): try to use a more explicit naming convention. You don't need to call gwa_ to all your global work-areas (althoug is NOT a bad idea), but use something more explicit for the table (maybe t_customers).
For the ALV output, check function modules REUSE_ALV_FIELDCATALOG_MERGE and REUSE_ALV_GRID_DISPLAY if you want to do the traditional way, oro take a look at SALV_TABLE* programs.
2013 Aug 28 10:09 AM
Hiii ILIAN Grigorov
As u have started with writing the real program (executable) in se38)t-code) abap editor.
now u should know some basic events of report program.
reports are of two kinds
1> Basic report
2>secondary report or classic report
There are events in both types of report playinh huge role.
so some events of basic report are (serial)
load-of-program.
initialization
at selection-screen output (For screen modification) corresponds for PBO
at selection-screen (For field validation) corresponds for PAI
star- of- selection (default event)
end-of-selection
top of page (get executed when the control reach any write statement, used to write header in basic report)
end of page (used to write footer).
Events of classical report
top-of- page during line-selection (To write header in classical report)
at line-selection (get executed for double click at a line or hotspot)
at pf
at user-command
After this there are control break processing statement like
at new-----ENDAT
at first -----endat (Process for the first loop only, used to write header, sum of any filed)
at endof ---endat
at last ------endat( process at the last loop, used to write footer, sub total)
sum.
Then the system field concept like\
sy-subrc (used to check the successful exection)
sy-lsind
sy-lisel
sy-tabix
sy-index
just get through these.
regards
Syed