You are on page 1of 16

Top of Form

My Home > ABAP Development > ABAP Development and
Programming > My first SAP Script step by step

Search the w iki
Bottom of Form

My first SAP Script step by step

ViewComments (0)Attachments (12)Info
Additional Features

Added by Krishna Chauhan , last edited by Krishna Chauhan on Jan 13, 2009 (view change)
Top of Form

Labels:
tutorial, abap

Bottom of Form

.

.

.

.

.

.

.

.

Code in SE38: .

ernam like mara-ernam. dismm like marc-dismm. matnr like mara-matnr. data: begin of it_final occurs 0. tables: mara. matnr like makt-matnr. ersda like mara-ersda. werks like mard-werks. *---internal table to get data from mara data: begin of it_mara occurs 0. maktx like makt-maktx. .*&---------------------------------------------------------------------* *& Report YKC_SCRIPT_DRIVER_PRO *& *&---------------------------------------------------------------------* *&Krishna Chauhan (Sparta Consulting) *&Date: 09 Jan 2009 *&---------------------------------------------------------------------* REPORT YKC_SCRIPT_DRIVER_PRO. beskz like marc-beskz. ernam like mara-ernam. end of it_final.mard. matnr like mara-matnr. ersda like mara-ersda. makt. marc. *---internal table to store mat description data: begin of it_makt occurs 0. lgort like mard-lgort. end of it_mara.

*--internal table to keep data from mard data: begin of it_mard occurs 0. dismm like marc-dismm. PERFORM start_form. PERFORM end_form. werks like mard-werks. maktx like makt-maktx. PERFORM open_form. *&---------------------------------------------------------------------* *& Form GET_DATA *&---------------------------------------------------------------------* * text: Getting data into final internal table for display *----------------------------------------------------------------------* form GET_DATA .spras like makt-spras. ENDLOOP. lgort like mard-lgort. PERFORM write_form. endif. end of it_makt. Start-of-selection. beskz like marc-beskz. sort it_mara by matnr. end of it_mard. *--internal table to keep data from marc data: begin of it_marc occurs 0. werks like marc-werks. PERFORM close-form. select matnr spras maktx from makt into table it_makt for all entries in it_mara where matnr = it_mara-matnr and spras = 'E'. Select-options s_matnr for mara-matnr. perform get_data. if not it_mara[] is initial. LOOP AT it_final. matnr like mara-matnr. . end of it_marc. select matnr werks beskz dismm from marc into table it_marc for all entries in it_mara where matnr = it_mara-matnr. matnr like mara-matnr. *---getting common data from mara & marc on the basis of matnr. select matnr ersda ernam from mara into table it_mara where matnr in s_matnr.

append it_final. endif. endif. it_final-beskz = it_marc-beskz. sort it_marc by matnr werks. if sy-subrc = 0. *---getting werks. it_final-maktx = it_makt-maktx. loop at it_mard. beskz. if sy-subrc = 0. ersda. Endform. endform. it_final-lgort = it_mard-lgort. if sy-subrc = 0. " GET_DATA *&---------------------------------------------------------------------* *& Form OPEN-FORM *&---------------------------------------------------------------------* * text: opening script form *----------------------------------------------------------------------* Form OPEN_FORM . dismm into it_final it_final-werks = it_mard-werks. it_final-ernam = it_mara-ernam. if not it_marc[] is initial. *---getting material desc read table it_makt with key matnr = it_mard-matnr binary search. lgort. read table it_mara with key matnr = it_mard-matnr binary search. endif. ernam into it-final it_final-matnr = it_mara-matnr. clear it_final. it_final-ersda = it_mara-ersda. "OPEN-FORM *&---------------------------------------------------------------------* . endif. 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. CALL FUNCTION 'OPEN_FORM' EXPORTING Form = 'YKC_FIRST_SCRIPT'. read table it_marc with key matnr = it_mard-matnr werks = it_mard-werks binary search. endloop.*---gettng common data from marc & mard on the basis of matnr & werks. *---getting matnr. it_final-dismm = it_marc-dismm. sort it_mard by matnr werks.

"START_FORM *&---------------------------------------------------------------------* *& Form WRITE_FORM *&---------------------------------------------------------------------* * text: Writing into form *----------------------------------------------------------------------* Form WRITE_FORM . CALL FUNCTION 'WRITE_FORM' EXPORTING element = 'E2' * FUNCTION = 'SET' * TYPE = 'BODY' Window = 'MAIN' . CALL FUNCTION 'WRITE_FORM' EXPORTING Element = 'E1' * FUNCTION = 'SET' * TYPE = 'BODY' Window = 'WINDOW1' . CALL FUNCTION 'START_FORM' EXPORTING Form = 'YKC_FIRST_SCRIPT'. *--CALL FUNCTION 'WRITE_FORM' EXPORTING Window = 'GRAPH1'. CALL FUNCTION 'END_FORM' * IMPORTING * RESULT = * EXCEPTIONS * UNOPENED =1 * BAD_PAGEFORMAT_FOR_PRINT * SPOOL_ERROR * OTHERS =3 =4 =2 . endform.*& Form START_FORM *&---------------------------------------------------------------------* * Text: Starting form *----------------------------------------------------------------------* Form START_FORM . Endform. " WRITE_FORM *&---------------------------------------------------------------------* *& Form END_FORM *&---------------------------------------------------------------------* * text: Ending form *----------------------------------------------------------------------* form END_FORM .

ENDIF endform.. CALL FUNCTION 'CLOSE_FORM' * IMPORTING * RESULT * RDI_RESULT = = * TABLES * OTFDATA = * EXCEPTIONS * UNOPENED =1 * BAD_PAGEFORMAT_FOR_PRINT * SEND_ERROR * SPOOL_ERROR * OTHERS =3 =4 =5 . * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. " END_FORM *&---------------------------------------------------------------------* *& Form CLOSE-FORM *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* form CLOSE-FORM . endform. The output will be: "CLOSE-FORM =2 . IF sy-subrc <> 0.

Contact Us Site Index Marketing Opportunities Legal Terms Privacy Impressum Powered by SAP NetWeaver .