The following program is displaying some useful information of material from table MARA based on the material number by a select option in the selection screen.
Here we have created a custom structure of the internal table named it_mara. This structure ty_mara contains Material No, Creation Date, Name, Material Type and Group. Hence output will have only these fields. We have declared an work area wa_mara for internal table. Here the internal table is of standard table type.
Now under INITIALIZATION event we have initialized the Program name, date and user name which are to be displayed at the Top of page. TOP OF PAGE is another event where we are declaring the select option s_matnr in a selection screen for input of material no.
Next we are declaring the START-OF-SELECTION event under which we mention a subroutine get_mara. Subroutine is declared by the key word perform. Under this perform we select required fields from MARA into internal table it_mara based on the where condition. So after getting proper data from the MARA table we shall prepare the output in the subroutine of get_output.
Now on the next event END-OF-SELECTION we are declaring a subroutine get_output and inside there we are looping the internal table it_mara into wa_mara. Hence we fetch the data from internal table to the work area and then display it with simple write statement. Since this is a loop, so one by one record will be fetched into work area and then it will be displayed.
Now we want to display the name of the fields heading at the beginning. To do this we call control break statement at first & endat inside the loop. At first statement will be triggered at the first time of the loop. Similarly when the listing will be completed then At Last - endat statement will be triggered to display ending of report message.
Now on the next event END-OF-SELECTION we are declaring a subroutine get_output and inside there we are looping the internal table it_mara into wa_mara. Hence we fetch the data from internal table to the work area and then display it with simple write statement. Since this is a loop, so one by one record will be fetched into work area and then it will be displayed.
Now we want to display the name of the fields heading at the beginning. To do this we call control break statement at first & endat inside the loop. At first statement will be triggered at the first time of the loop. Similarly when the listing will be completed then At Last - endat statement will be triggered to display ending of report message.
Next we raise the event TOP-OF-PAGE which is used to display the top message. On the top we can write program name, user name, date etc.
REPORT zabap_gui.
*Declaring the line type of database table
TABLES: mara.
*------Declaring the local types for Internal table & Work area--------*
TYPES: BEGIN OF ty_mara,
matnr TYPE mara-matnr, "Material No.
ersda TYPE mara-ersda, "Creation Data
ernam TYPE mara-ernam, "Created By
mtart TYPE mara-mtart, "Material Type
matkl TYPE mara-matkl, "Material Group
END OF ty_mara.
*-----Declaring the Internal table & work area-------------------------*
DATA: wa_mara TYPE ty_mara,
it_mara TYPE STANDARD TABLE OF ty_mara,
v_repid TYPE sy-repid, "Program name
v_date TYPE sy-datum, "Current date
v_user TYPE sy-uname. "User name
*-------------Event initialization-------------------------------------*
INITIALIZATION.
v_repid = sy-repid.
v_date = sy-datum.
v_user = sy-uname.
*-Declaring the selection screen & select option for input-------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS s_matnr FOR mara-matnr OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.
*-----Event start of selection-----------------------------------------*
START-OF-SELECTION.
PERFORM get_mara.
*---Event end of selection---------------------------------------------*
END-OF-SELECTION.
PERFORM get_output.
*---Event top of page--------------------------------------------------*
TOP-OF-PAGE.
PERFORM top_page.
*&---------------------------------------------------------------------*
*& Form get_mara
*&---------------------------------------------------------------------*
* Select data from MARA table
*----------------------------------------------------------------------*
FORM get_mara .
SELECT matnr ersda ernam mtart matkl
FROM mara INTO TABLE it_mara
WHERE matnr IN s_matnr.
IF sy-subrc <> 0.
MESSAGE 'Material Doesn''t Exist.' TYPE 'I'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. " get_mara
*&---------------------------------------------------------------------*
*& Form get_output
*&---------------------------------------------------------------------*
* Preparing the classical output with WRITE statement
*----------------------------------------------------------------------*
FORM get_output .
IF it_mara IS NOT INITIAL.
LOOP AT it_mara INTO wa_mara.
"Control break statement – it will display one time at first line
AT FIRST.
WRITE: /3 'Material No.',
25 'Created By',
40 'Group',
55 'Type',
70 'Creation Date'.
ULINE.
SKIP.
ENDAT.
WRITE: / wa_mara-matnr,
25 wa_mara-ernam,
40 wa_mara-matkl,
55 wa_mara-mtart,
70 wa_mara-ersda.
"Control break statement – it will display one time at last line
AT LAST.
ULINE.
WRITE: /15 '~~End of Material Display~~'.
ENDAT.
ENDLOOP.
ENDIF.
ENDFORM. " get_output
*&---------------------------------------------------------------------*
*& Form top_page
*&---------------------------------------------------------------------*
* Top pf page to display top information
*----------------------------------------------------------------------*
FORM top_page .
WRITE: / 'Material Details',
/ 'Date: ', 12 v_date DD/MM/YYYY,
/ 'User: ', 12 v_user,
/ 'Report: ', 12 v_repid.
ULINE.
SKIP.
ENDFORM. " top_page
TABLES: mara.
*------Declaring the local types for Internal table & Work area--------*
TYPES: BEGIN OF ty_mara,
matnr TYPE mara-matnr, "Material No.
ersda TYPE mara-ersda, "Creation Data
ernam TYPE mara-ernam, "Created By
mtart TYPE mara-mtart, "Material Type
matkl TYPE mara-matkl, "Material Group
END OF ty_mara.
*-----Declaring the Internal table & work area-------------------------*
DATA: wa_mara TYPE ty_mara,
it_mara TYPE STANDARD TABLE OF ty_mara,
v_repid TYPE sy-repid, "Program name
v_date TYPE sy-datum, "Current date
v_user TYPE sy-uname. "User name
*-------------Event initialization-------------------------------------*
INITIALIZATION.
v_repid = sy-repid.
v_date = sy-datum.
v_user = sy-uname.
*-Declaring the selection screen & select option for input-------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS s_matnr FOR mara-matnr OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b1.
*-----Event start of selection-----------------------------------------*
START-OF-SELECTION.
PERFORM get_mara.
*---Event end of selection---------------------------------------------*
END-OF-SELECTION.
PERFORM get_output.
*---Event top of page--------------------------------------------------*
TOP-OF-PAGE.
PERFORM top_page.
*&---------------------------------------------------------------------*
*& Form get_mara
*&---------------------------------------------------------------------*
* Select data from MARA table
*----------------------------------------------------------------------*
FORM get_mara .
SELECT matnr ersda ernam mtart matkl
FROM mara INTO TABLE it_mara
WHERE matnr IN s_matnr.
IF sy-subrc <> 0.
MESSAGE 'Material Doesn''t Exist.' TYPE 'I'.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. " get_mara
*&---------------------------------------------------------------------*
*& Form get_output
*&---------------------------------------------------------------------*
* Preparing the classical output with WRITE statement
*----------------------------------------------------------------------*
FORM get_output .
IF it_mara IS NOT INITIAL.
LOOP AT it_mara INTO wa_mara.
"Control break statement – it will display one time at first line
AT FIRST.
WRITE: /3 'Material No.',
25 'Created By',
40 'Group',
55 'Type',
70 'Creation Date'.
ULINE.
SKIP.
ENDAT.
WRITE: / wa_mara-matnr,
25 wa_mara-ernam,
40 wa_mara-matkl,
55 wa_mara-mtart,
70 wa_mara-ersda.
"Control break statement – it will display one time at last line
AT LAST.
ULINE.
WRITE: /15 '~~End of Material Display~~'.
ENDAT.
ENDLOOP.
ENDIF.
ENDFORM. " get_output
*&---------------------------------------------------------------------*
*& Form top_page
*&---------------------------------------------------------------------*
* Top pf page to display top information
*----------------------------------------------------------------------*
FORM top_page .
WRITE: / 'Material Details',
/ 'Date: ', 12 v_date DD/MM/YYYY,
/ 'User: ', 12 v_user,
/ 'Report: ', 12 v_repid.
ULINE.
SKIP.
ENDFORM. " top_page
Below is the output:
Output:
5 comments:
would you provide some more basics information of abap data dictionary
Fantastic Blog Mr.Sandip Roy. Extraordinary work.
SAP Success Factors Real Time Hands on Training in Chennai...
Don't always Depend on Training Institute Alone and so please aware of Best Trainers too..
http://thecreatingexperts.com/sap-successfactors-training-in-chennai/
If You need a Best Trainer over SAP Success Factors Means??? Please ready for an DEMO From the Trainer MR.Karthick
CONTACT:8122241286
Both Classroom/Online Training is Available!!!!!!
Informative Blog...For a long time I was craving for a career growth in programming and then I came to know that THE CREATING EXPERTS is the one who provide training with hands on training and real time scenarios
http://thecreatingexperts.com/sap-abap-training-in-chennai/
contact 8122241286
Great information. the information provided is of great use as i got to learn new things. If you are looking for real time training in SAP ABAP, kindly contact sieve software
Sieve software offers real time training by industry experts with live projects and placement support.
SAP ABAP TRAINING IN HYDERABAD
Post a Comment