step by step sapscript

48

Upload: kapil-nimker

Post on 07-Apr-2015

456 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Step by Step Sapscript

Log In Register About Us How to Contribute

Welcome Guest

SDN Community BPX Community BusinessObjects University Alliances SAP EcoHub

Home Forums Wiki Blogs Articles eLearning Downloads Code Exchange Career Center Events InnoCentive Idea Place

Added by Krishna Chauhan, last edited by Krishna Chauhan on Jan 13, 2009

My first SAP Script step by step

SAP Community Network Wiki - ABAP Development - My first SAP Scri... http://wiki.sdn.sap.com/wiki/display/ABAP/My+first+SAP+Script+step...

1 of 9 12/3/2010 6:15 PM

Page 2: Step by Step Sapscript

SAP Community Network Wiki - ABAP Development - My first SAP Scri... http://wiki.sdn.sap.com/wiki/display/ABAP/My+first+SAP+Script+step...

2 of 9 12/3/2010 6:15 PM

Page 3: Step by Step Sapscript

SAP Community Network Wiki - ABAP Development - My first SAP Scri... http://wiki.sdn.sap.com/wiki/display/ABAP/My+first+SAP+Script+step...

3 of 9 12/3/2010 6:15 PM

Page 4: Step by Step Sapscript

SAP Community Network Wiki - ABAP Development - My first SAP Scri... http://wiki.sdn.sap.com/wiki/display/ABAP/My+first+SAP+Script+step...

4 of 9 12/3/2010 6:15 PM

Page 5: Step by Step Sapscript

SAP Community Network Wiki - ABAP Development - My first SAP Scri... http://wiki.sdn.sap.com/wiki/display/ABAP/My+first+SAP+Script+step...

5 of 9 12/3/2010 6:15 PM

Page 6: Step by Step Sapscript

Code in SE38:

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

*& Report YKC_SCRIPT_DRIVER_PRO

*&

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

*&Krishna Chauhan (Sparta Consulting)

*&Date: 09 Jan 2009

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

REPORT YKC_SCRIPT_DRIVER_PRO.

tables: mara, makt, marc,mard.

data: begin of it_final occurs 0,

matnr like mara-matnr,

maktx like makt-maktx,

ersda like mara-ersda,

ernam like mara-ernam,

werks like mard-werks,

lgort like mard-lgort,

beskz like marc-beskz,

dismm like marc-dismm,

end of it_final.

*---internal table to get data from mara

data: begin of it_mara occurs 0,

matnr like mara-matnr,

ersda like mara-ersda,

ernam like mara-ernam,

end of it_mara.

*---internal table to store mat description

data: begin of it_makt occurs 0,

matnr like makt-matnr,

spras like makt-spras,

maktx like makt-maktx,

end of it_makt.

*--internal table to keep data from marc

data: begin of it_marc occurs 0,

matnr like mara-matnr,

werks like marc-werks,

beskz like marc-beskz,

dismm like marc-dismm,

end of it_marc.

*--internal table to keep data from mard

data: begin of it_mard occurs 0,

matnr like mara-matnr,

werks like mard-werks,

lgort like mard-lgort,

end of it_mard.

Select-options s_matnr for mara-matnr.

Start-of-selection.

perform get_data.

PERFORM open_form.

LOOP AT it_final.

PERFORM start_form.

PERFORM write_form.

PERFORM end_form.

SAP Community Network Wiki - ABAP Development - My first SAP Scri... http://wiki.sdn.sap.com/wiki/display/ABAP/My+first+SAP+Script+step...

6 of 9 12/3/2010 6:15 PM

Page 7: Step by Step Sapscript

ENDLOOP.

PERFORM close-form.

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

*& Form GET_DATA

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

* text: Getting data into final internal table for display

*----------------------------------------------------------------------*

form GET_DATA .

select matnr ersda ernam

from mara into table it_mara

where matnr in s_matnr.

sort it_mara by matnr.

if not it_mara[] is initial.

*---getting common data from mara & marc on the basis of matnr.

select matnr werks beskz dismm

from marc into table it_marc

for all entries in it_mara

where matnr = it_mara-matnr.

select matnr spras maktx

from makt into table it_makt

for all entries in it_mara

where matnr = it_mara-matnr

and spras = 'E'.

endif.

*---gettng common data from marc & mard on the basis of matnr & werks.

sort it_marc by matnr werks.

if not it_marc[] is initial.

select matnr werks lgort

from mard into table it_mard

for all entries in it_marc

where matnr = it_marc-matnr

and werks = it_marc-werks.

endif.

sort it_mard by matnr werks.

loop at it_mard.

read table it_mara with key matnr = it_mard-matnr binary search.

if sy-subrc = 0.

*---getting matnr, ersda, ernam into it-final

it_final-matnr = it_mara-matnr.

it_final-ersda = it_mara-ersda.

it_final-ernam = it_mara-ernam.

endif.

*---getting material desc

read table it_makt with key matnr = it_mard-matnr binary search.

if sy-subrc = 0.

it_final-maktx = it_makt-maktx.

endif.

*---getting werks, lgort, beskz, dismm into it_final

it_final-werks = it_mard-werks.

it_final-lgort = it_mard-lgort.

read table it_marc with key matnr = it_mard-matnr

werks = it_mard-werks

binary search.

if sy-subrc = 0.

it_final-beskz = it_marc-beskz.

it_final-dismm = it_marc-dismm.

endif.

append it_final.

clear it_final.

endloop.

endform. " GET_DATA

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

*& Form OPEN-FORM

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

* text: opening script form

*----------------------------------------------------------------------*

Form OPEN_FORM .

CALL FUNCTION 'OPEN_FORM'

EXPORTING

Form = 'YKC_FIRST_SCRIPT'.

Endform. "OPEN-FORM

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

*& Form START_FORM

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

* Text: Starting form

*----------------------------------------------------------------------*

SAP Community Network Wiki - ABAP Development - My first SAP Scri... http://wiki.sdn.sap.com/wiki/display/ABAP/My+first+SAP+Script+step...

7 of 9 12/3/2010 6:15 PM

Page 8: Step by Step Sapscript

Form START_FORM .

CALL FUNCTION 'START_FORM'

EXPORTING

Form = 'YKC_FIRST_SCRIPT'.

Endform. "START_FORM

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

*& Form WRITE_FORM

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

* text: Writing into form

*----------------------------------------------------------------------*

Form WRITE_FORM .

*---

CALL FUNCTION 'WRITE_FORM'

EXPORTING

Window = 'GRAPH1'.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

Element = 'E1'

* FUNCTION = 'SET'

* TYPE = 'BODY'

Window = 'WINDOW1'

.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

element = 'E2'

* FUNCTION = 'SET'

* TYPE = 'BODY'

Window = 'MAIN'

.

endform. " WRITE_FORM

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

*& Form END_FORM

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

* text: Ending form

*----------------------------------------------------------------------*

form END_FORM .

CALL FUNCTION 'END_FORM'

* IMPORTING

* RESULT =

* EXCEPTIONS

* UNOPENED = 1

* BAD_PAGEFORMAT_FOR_PRINT = 2

* SPOOL_ERROR = 3

* OTHERS = 4

.

IF sy-subrc <> 0.

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF

endform. " END_FORM

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

*& Form CLOSE-FORM

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

* text

*----------------------------------------------------------------------*

form CLOSE-FORM .

CALL FUNCTION 'CLOSE_FORM'

* IMPORTING

* RESULT =

* RDI_RESULT =

* TABLES

* OTFDATA =

* EXCEPTIONS

* UNOPENED = 1

* BAD_PAGEFORMAT_FOR_PRINT = 2

* SEND_ERROR = 3

* SPOOL_ERROR = 4

* OTHERS = 5

.

endform. "CLOSE-FORM

The output will be:

SAP Community Network Wiki - ABAP Development - My first SAP Scri... http://wiki.sdn.sap.com/wiki/display/ABAP/My+first+SAP+Script+step...

8 of 9 12/3/2010 6:15 PM

Page 9: Step by Step Sapscript

Labels

Contact Us Site Index Marketing Opportunities Legal Terms Privacy Impressum

Powered by SAP NetWeaver

tutorial abap

SAP Community Network Wiki - ABAP Development - My first SAP Scri... http://wiki.sdn.sap.com/wiki/display/ABAP/My+first+SAP+Script+step...

9 of 9 12/3/2010 6:15 PM