Sei sulla pagina 1di 17

My first SAP Script step by step

Tiny Link

Wiki Markup

Close

Move Page My

Set Page Location Move

OK

Cancel

Click to select the

Search

Recently View ed

Know n Location

The specified pag Brow se

You could try relo HTTP Status

You must make a

Failed to retrieve

Move failed. Ther

You cannot move

My first SAP Scri

ABAP Developme

ABAP Developme

You cannot move

Page Ordering

Back

Reorder

Move

Unknow n user or

Page Restrictions

Editing restricted

Cancel

Close

Save

Link to this Page

Link

There w ere no re

There w ere no pa Show ing <b>{0}<


ABAP

1710

Page restrictions apply


Attachments:12
Added by Krishna Chauhan, last edited by Krishna Chauhan on Jan 13, 2009 (view change)
view

Error reading the

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.
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

*----------------------------------------------------------------------*
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
* SPOOL_ERROR

=3

=2

* 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
* SEND_ERROR

=3

* SPOOL_ERROR
* OTHERS

=4
=5

.
endform.
The output will be:

"CLOSE-FORM

=2

Potrebbero piacerti anche