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 program

ILIAN_Grigorov
Contributor
0 Likes
1,986

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

13 REPLIES 13
Read only

FredericGirod
Active Contributor
0 Likes
1,729

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

Read only

0 Likes
1,729

Read only

Former Member
0 Likes
1,729

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

Read only

VXLozano
Active Contributor
0 Likes
1,729

Transaction ABAPDOCU

Just invest some time on it, and you'll know more than some of us do.

Read only

Former Member
0 Likes
1,729
Read only

Former Member
0 Likes
1,729

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

Read only

Former Member
0 Likes
1,729

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.

Read only

0 Likes
1,729

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.

Read only

ILIAN_Grigorov
Contributor
0 Likes
1,729

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

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,729

Did you find Examples and demos by SAP in wiki space of scn ?

Regards,

Raymond

Read only

ILIAN_Grigorov
Contributor
0 Likes
1,729

*&---------------------------------------------------------------------*

*& 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!

Read only

0 Likes
1,729

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.

Read only

0 Likes
1,729

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