SOURCE CODE:
*-----------------------------------------------------------------------
* Program Name: Z689_SAPSCRIPT
* Date : 03/28/2007
* Author : Sayee Manojnah Kasala
* Description : Print program to display the Sales Order Details
*-----------------------------------------------------------------------
REPORT Z689_SAPSCRIPT
LINE-SIZE 80
LINE-COUNT 120
NO STANDARD PAGE HEADING.
*-----------------------------------------------------------------------
* Tables
TABLES: vbap, " Sales Document: Item Data
vbak, " Sales Document: Header Data
kna1. " General Data in Customer Master
* Selection screen
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_kunnr FOR kna1-kunnr NO-EXTENSION.
SELECTION-SCREEN END OF BLOCK b1.
* Data declaration
DATA: BEGIN OF i_vbak OCCURS 0,
vbeln LIKE vbak-vbeln,
kunnr LIKE vbak-kunnr,
END OF i_vbak.
DATA: BEGIN OF i_vbap OCCURS 0,
vbeln LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
matnr LIKE vbap-matnr,
matkl LIKE vbap-matkl,
netpr LIKE vbap-netpr,
END OF i_vbap.
DATA: BEGIN OF i_final OCCURS 0,
kunnr LIKE vbak-kunnr,
vbeln LIKE vbak-vbeln,
posnr LIKE vbap-posnr,
matnr LIKE vbap-matnr,
matkl LIKE vbap-matkl,
netpr LIKE vbap-netpr,
END OF i_final.
DATA: wa_final LIKE i_final,
land1 LIKE kna1-land1,
name1 LIKE kna1-name1,
landx LIKE t005t-landx.
* Start of selection
START-OF-SELECTION.
SELECT vbeln kunnr
FROM vbak INTO TABLE i_vbak
WHERE kunnr IN s_kunnr.
IF sy-subrc = 0.
SELECT vbeln posnr matnr matkl netpr
FROM vbap INTO TABLE i_vbap
FOR ALL ENTRIES IN i_vbak
WHERE vbeln = i_vbak-vbeln.
ENDIF.
LOOP AT i_vbak.
LOOP AT i_vbap WHERE vbeln = i_vbak-vbeln.
MOVE: i_vbak-kunnr TO i_final-kunnr,
i_vbak-vbeln TO i_final-vbeln,
i_vbap-posnr TO i_final-posnr,
i_vbap-matnr TO i_final-matnr,
i_vbap-matkl TO i_final-matkl,
i_vbap-netpr TO i_final-netpr.
APPEND i_final.
CLEAR: i_vbap,i_final.
ENDLOOP.
CLEAR: i_vbak.
ENDLOOP.
IF i_final[] IS NOT INITIAL.
SORT i_final BY kunnr.
ENDIF.
* Call OPEN FORM
CALL FUNCTION 'OPEN_FORM'
EXPORTING
form = 'Z689_SAPSCRIPT'
language = sy-langu.
LOOP AT i_final.
wa_final = i_final.
AT NEW kunnr.
* Call START FORM
CALL FUNCTION 'START_FORM'
EXPORTING
form = 'Z689_SAPSCRIPT'
startpage = 'PAGE1'
program = 'Z689_SAPSCRIPT'.
ENDAT.
* Call WRITE FORM
CALL FUNCTION 'WRITE_FORM'
EXPORTING
element = 'ELEMENT'
window = 'MAIN'.
AT END OF kunnr.
* Call END FORM
CALL FUNCTION 'END_FORM'.
ENDAT.
ENDLOOP.
*Call CLOSE FORM
CALL FUNCTION 'CLOSE_FORM'.
Calling a subroutine in SAP Script:
The subroutine Z689_SUBROUTINE is used to display the Customer Details through SAP Script.
In a SAP Script, the subroutine has to be called as shown below:
Below is the subroutine pool used in the creation of the SAP Script:
*-----------------------------------------------------------------------
* Program Name : Z689_SUBROUTINE
* Date : 03/28/2007
* Author : Sayee Manojnah Kasala
* Description : This is the subroutine used for SAP Script,
* Z689_SAPSCRIPT.It fetches customer details like
* customer name & place
*-----------------------------------------------------------------------
PROGRAM Z689_SUBROUTINE.
* Form GET_LAND1
* Fetches the country key
*&---------------------------------------------------------------------*
*& Form get_land1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->INTABLE text
* -->OUTTABLE text
*----------------------------------------------------------------------*
FORM get_land1 TABLES intable STRUCTURE itcsy
outtable STRUCTURE itcsy.
DATA: v_kunnr LIKE kna1-kunnr,
v_land1 LIKE kna1-land1,
v_name1 LIKE kna1-name1.
READ TABLE intable INDEX 1.
v_kunnr = intable-value.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = v_kunnr
IMPORTING
output = v_kunnr.
IF sy-subrc = 0.
SELECT SINGLE land1
FROM kna1
INTO v_land1
WHERE kunnr = v_kunnr.
IF sy-subrc = 0.
READ TABLE outtable INDEX 1.
outtable-value = v_land1.
MODIFY outtable INDEX 1.
ENDIF.
SELECT SINGLE name1
FROM kna1
INTO v_name1
WHERE kunnr = v_kunnr.
IF sy-subrc = 0.
READ TABLE outtable INDEX 2.
outtable-value = v_name1.
MODIFY outtable INDEX 2.
ENDIF.
ENDIF.
CLEAR: intable,outtable.
ENDFORM. "get_land1
* Form GET_LANDX
* Fetches the Country Name
*&---------------------------------------------------------------------*
*& Form get_landx
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->INTABLE text
* -->OUTTABLE text
*----------------------------------------------------------------------*
FORM get_landx TABLES intable STRUCTURE itcsy
outtable STRUCTURE itcsy.
DATA: v_land1 LIKE kna1-land1,
v_landx LIKE t005t-landx.
READ TABLE intable INDEX 1.
v_land1 = intable-value.
IF sy-subrc = 0.
SELECT SINGLE landx
FROM t005t
INTO v_landx
WHERE land1 = v_land1 AND spras = 'E'.
IF sy-subrc = 0.
READ TABLE outtable INDEX 1.
outtable-value = v_landx.
MODIFY outtable INDEX 1.
ENDIF.
ENDIF.
CLEAR: intable,outtable.
ENDFORM. "get_landx
Test Case:
Enter the customer numbers & click on execute.
The output will be as below:
The next page that will be displayed is
No comments:
Post a Comment