Monday, July 16, 2007

my first ABAP program

No, it's not a "hello world" program ;p

One of main job of an ABAPer is create ABAP report.
Report content 4 basic component.
1. Data declaration.
2. Selection screen.
3. Select Data.
4. Write Report.


I assume you already familiar with data dictionary. For an example, we have a table "SFLIGHT", with following fields:
1. CARRID (Airline carrier ID)
2. CONNID (Flight connection Id)
3. FLDATE (Flight date).
4.SEATSMAX (Maximum capacity).
We wan to create a report that can be filtered based on Airline carrier ID and Flight connection Id.
Go to transaction code SE38 (SAP Menu->Tools>ABAP Workbench->Development->ABAP Editor), enter program name with prefix Z, for example ZTEST0001, then choose "Create" button.


Then, enter title for program, and choose 1 "Executable Program" for program type. If screen input for development class appear, click "Local Object".

Then, go to following steps.
1. Data declaration



TABLES: sflight.

DATA: BEGIN OF t_report OCCURS 3,
carrid LIKE sflight-carrid,
connid LIKE sflight-connid,
fldate LIKE sflight-fldate,
seatsmax LIKE sflight-seatsmax,
END OF t_report.

2. Selection screen



SELECT-OPTIONS s_carrid FOR sflight-carrid.
SELECT-OPTIONS s_connid FOR sflight-connid.

It will generate selection screen like picture below.


3. Select data



SELECT * FROM sflight
WHERE carrid IN s_carrid AND
connid IN s_connid.
t_report-carrid = sflight-carrid.
t_report-connid = sflight-connid.
t_report-fldate = sflight-fldate.
t_report-seatsmax = sflight-seatsmax.
APPEND t_report.
ENDSELECT.
IF sy-subrc NE 0. "sy-subrc = return code
WRITE 'Data not found'.
ENDIF.

4. Write data



LOOP AT t_report.
skip. "comment:Go to next line
WRITE t_report-carrid.
WRITE t_report-connid.
WRITE t_report-fldate.
WRITE t_report-seatsmax.
ENDLOOP.

The result :


Here is the complete program:


REPORT ZTEST0001 .
*Data Declaration
tables: sflight.

DATA: BEGIN OF t_report OCCURS 3,
carrid LIKE sflight-carrid,
connid LIKE sflight-connid,
fldate LIKE sflight-fldate,
seatsmax LIKE sflight-seatsmax,
END OF t_report.

*Selection Screen
SELECT-OPTIONS s_carrid FOR sflight-carrid.
SELECT-OPTIONS s_connid FOR sflight-connid.

*Get Data
SELECT * FROM sflight
WHERE carrid IN s_carrid AND
connid IN s_connid.
t_report-carrid = sflight-carrid.
t_report-connid = sflight-connid.
t_report-fldate = sflight-fldate.
t_report-seatsmax = sflight-seatsmax.
APPEND t_report.
ENDSELECT.
IF sy-subrc NE 0.
WRITE 'Data not found'.
ENDIF.

*Write Data
LOOP AT t_report.
skip. "comment:Go to next line
WRITE t_report-carrid.
WRITE t_report-connid.
WRITE t_report-fldate.
WRITE t_report-seatsmax.
ENDLOOP.

5 komentar:

Anonymous said...

I liked the explanation is very simple

Observer to write a strongly

thank you for your time

seventyros said...

For a Excellent Online Resource for SAP EP and SAP Web Dynpro ABAP, Visit Learn SAP Online

Madhu said...

Explanation is very simple to understand.

Keep it up

umesh said...

actually i am intrested in doing the sap/abap module .but i cant understand the ,ecactly whats the mean of report(can u take the example of any mnc company) can u guys suggestd me .. i want to be abaper .
and come to ur explanation its awesome .. thanks

plates said...

nice your blog and very nice dear your blog psoting we like its you can see our also plates