Skip to Content
avatar image
Former Member

sap script

Hi,

Pls send me sample code for sapscript.

Thx,

Sofia

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • avatar image
    Former Member
    Aug 17, 2007 at 06:55 AM

    Hi

    &----


    *& Report ZTEST12121

    *& SAPScripts Example 1

    &----


    REPORT ztest12121.

    *DATABASE TABLES

    TABLES: ekko,ekpo,lfa1.

    *INTERNAL TABLES AND STRUCTURES

    DATA i_ekko LIKE ekko.

    DATA i_ekpo LIKE ekpo OCCURS 0 WITH HEADER LINE.

    DATA i_lfa1 LIKE lfa1.

    *PARAMETERS

    PARAMETERS: p_ebeln LIKE ekko-ebeln.

    *VARIABLES

    DATA MAT TYPE STRING VALUE 'MAT NO'.

    DATA iTe TYPE STRING VALUE 'ITEM NO'.

    DATA QTY TYPE STRING VALUE 'QTY'.

    DATA UOM TYPE STRING VALUE 'UOM'.

    DATA NET TYPE STRING VALUE 'NET PRICE'.

    Data var type integer value 0.

    *DATABASE SELECTS

    *Header data

    SELECT SINGLE * FROM ekko INTO i_ekko WHERE ekko~ebeln = p_ebeln.

    IF sy-subrc = 0.

    *Item Data

    SELECT * FROM ekpo INTO TABLE i_ekpo WHERE ekpo~ebeln = p_ebeln.

    IF sy-subrc NE 0.

    WRITE 'PURCHASE DOCUMENT ITEM DATA ERROR'.

    ELSE.

    *Vendor Details

    SELECT SINGLE * FROM lfa1 INTO i_lfa1 WHERE lfa1~lifnr = i_ekko-lifnr.

    IF sy-subrc NE 0.

    WRITE 'VENDOR DOCUMENT ITEM DATA ERROR'.

    ENDIF.

    ENDIF.

    ELSE.

    WRITE 'THIS PURCHASE DOCUMENT NUMBER DOESNOT EXISTS'.

    ENDIF.

    CALL FUNCTION 'OPEN_FORM'

    EXPORTING

    • APPLICATION = 'TX'

    • ARCHIVE_INDEX =

    • ARCHIVE_PARAMS =

    • DEVICE = 'PRINTER'

    • DIALOG = 'X'

    form = 'ZSCRIPT_1'

    language = sy-langu

    • OPTIONS =

    • MAIL_SENDER =

    • MAIL_RECIPIENT =

    • MAIL_APPL_OBJECT =

    • RAW_DATA_INTERFACE = '*'

    • SPONUMIV =

    • IMPORTING

    • LANGUAGE =

    • NEW_ARCHIVE_PARAMS =

    • RESULT =

    • EXCEPTIONS

    • CANCELED = 1

    • DEVICE = 2

    • FORM = 3

    • OPTIONS = 4

    • UNCLOSED = 5

    • MAIL_OPTIONS = 6

    • ARCHIVE_ERROR = 7

    • INVALID_FAX_NUMBER = 8

    • MORE_PARAMS_NEEDED_IN_BATCH = 9

    • SPOOL_ERROR = 10

    • CODEPAGE = 11

    • OTHERS = 12

    .

    IF sy-subrc <> 0.

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

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

    ENDIF.

    CALL FUNCTION 'WRITE_FORM'

    EXPORTING

    ELEMENT = 'OFFICEAD'

    FUNCTION = 'SET'

    TYPE = 'BODY'

    WINDOW = 'OFFICEAD'

    .

    IF sy-subrc <> 0.

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

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

    ENDIF.

    CALL FUNCTION 'WRITE_FORM'

    EXPORTING

    ELEMENT = 'PODET'

    FUNCTION = 'SET'

    TYPE = 'BODY'

    WINDOW = 'PODET'

    .

    IF sy-subrc <> 0.

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

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

    ENDIF.

    CALL FUNCTION 'WRITE_FORM'

    EXPORTING

    ELEMENT = 'TOP'

    FUNCTION = 'SET'

    TYPE = 'TOP'

    WINDOW = 'MAIN'

    .

    IF sy-subrc <> 0.

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

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

    ENDIF.

    LOOP AT I_EKPO.

    var = i_ekpo-netpr * i_ekpo-menge.

    CALL FUNCTION 'WRITE_FORM'

    EXPORTING

    ELEMENT = 'BODY'

    FUNCTION = 'SET'

    TYPE = 'BODY'

    WINDOW = 'MAIN'

    .

    IF sy-subrc <> 0.

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

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

    ENDIF.

    ENDLOOP.

    CALL FUNCTION 'CLOSE_FORM'

    • IMPORTING

    • RESULT =

    • RDI_RESULT =

    • TABLES

    • OTFDATA =

    • EXCEPTIONS

    • UNOPENED = 1

    • BAD_PAGEFORMAT_FOR_PRINT = 2

    • SEND_ERROR = 3

    • SPOOL_ERROR = 4

    • CODEPAGE = 5

    • OTHERS = 6

    .

    IF sy-subrc <> 0.

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

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

    ENDIF.

    <b>Reward points for useful Answers</b>

    Regards

    Anji

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Aug 17, 2007 at 10:15 AM

    Sapscript are much more easier than reports if you know the concept of windows and all .I hope u know that .I am just attching driver program and afterwards windows .

    PARAMETERS p_inv TYPE vbrk-vbeln OBLIGATORY.

    TYPES : BEGIN OF ty_vbrp,

    arktx LIKE vbrp-arktx,

    fkimg LIKE vbrp-fkimg,

    netwr LIKE vbrp-netwr,

    mwsbp LIKE vbrp-mwsbp,

    vgbel LIKE vbrp-vgbel,

    vgpos LIKE vbrp-vgpos,

    brgew LIKE vbrp-brgew,

    END OF ty_vbrp.

    DATA : i_text TYPE STANDARD TABLE OF ty_tline INITIAL SIZE 0 ,

    i_text1 TYPE STANDARD TABLE OF ty_tline INITIAL SIZE 0 ,

    i_vbrp TYPE STANDARD TABLE OF ty_vbrp INITIAL SIZE 0,

    w_vbrp TYPE ty_vbrp,

    DATA : w_werks LIKE lips-werks,

    w_vbeln LIKE vbrp-vbeln,

    w_adrnr LIKE t001w-adrnr,

    w_adrnr1 LIKE kna1-adrnr,

    w_name1 LIKE adrc-name1,

    w_name2 like adrc-name2,

    w_street LIKE adrc-street,

    w_str_suppl3 LIKE adrc-str_suppl3,

    w_location LIKE adrc-location,

    w_city1 LIKE adrc-city1,

    w_post_code1 LIKE adrc-post_code1,

    w_bukrs LIKE j_1imocomp-bukrs,

    w_cstno LIKE j_1imocomp-j_1icstno,

    w_cstno1 LIKE j_1imocust-j_1icstno,

    w_paval LIKE t001z-paval,

    DATA : w_returncode TYPE sy-subrc,

    w_screen TYPE c,

    retcode LIKE sy-subrc,

    xscreen(1) TYPE c,

    xdialog,

    xdevice(10).

    select single vbeln

    into w_vbeln

    from bseg

    where belnr = p_inv.

    SELECT SINGLE werks vgbel

    INTO (w_werks,w_vgbel)

    FROM vbrp

    WHERE vbeln = w_vbeln.

    SELECT SINGLE adrnr

    INTO w_adrnr

    FROM t001w

    WHERE werks = w_werks .

    SELECT SINGLE name1 name2 street str_suppl3 location city1 post_code1

    INTO (w_name1,w_name2,w_street,w_str_suppl3, w_location,w_city1,w_post_code1)

    FROM adrc

    WHERE addrnumber = w_adrnr.

    SELECT SINGLE vsart bldat kunnr

    INTO (w_vsart,w_bldat,w_kunnr)

    FROM likp

    WHERE vbeln = w_vgbel.

    w_rdoc = p_inv.

    SELECT SINGLE name1 name2 name3 house_num1 street city1 post_code1

    INTO (w_consgname1,w_consgname2,w_consgname3,w_consghousenum1,w_consgstreet,w_consgcity1,w_consgpost_code1)

    FROM adrc

    WHERE addrnumber = w_adrnr1.

    SELECT arktx fkimg netwr mwsbp vgbel vgpos brgew

    FROM vbrp

    INTO TABLE i_vbrp

    WHERE vbeln = w_vbeln.

    CALL FUNCTION 'OPEN_FORM'

    EXPORTING

    application = 'TX'

    archive_index = toa_dara

    archive_params = arc_params

    device = 'PRINTER'

    dialog = 'X'

    form = 'ZCINDVAT32'

    language = sy-langu

    OPTIONS = itcpo.

    CALL FUNCTION 'WRITE_FORM'

    EXPORTING

    element = 'HEADER1 '

    window = 'HEADER'.

    CALL FUNCTION 'WRITE_FORM'

    EXPORTING

    element = 'FOOTER1 '

    window = 'FOOTER'.

    CALL FUNCTION 'WRITE_FORM'

    EXPORTING

    element = 'HEADER1 '

    window = 'MAIN'.

    LOOP AT i_vbrp INTO w_vbrp.

    CONCATENATE w_vbrp-vgbel w_vbrp-vgpos INTO w_object.

    w_val = w_vbrp-netwr + w_vbrp-mwsbp.

    w_counter1 = w_counter1 + 1.

    CALL FUNCTION 'WRITE_FORM'

    EXPORTING

    element = 'VALUES1 '

    window = 'MAIN'.

    CLEAR w_val.

    ENDLOOP.

    CALL FUNCTION 'CLOSE_FORM'.

    *endif.

    *endform.

    WINDOWS :

    HEADER

    Element HEADER1

    This is how we have to draw lines in script .

    /* BOX FRAME 10 TW

    /: BOX XPOS '1.60' CM YPOS '3.65' CM WIDTH '3.0' CM HEIGHT 0 TW FRAME 10 TW

    /: BOX XPOS '5.30' CM YPOS '3.65' CM WIDTH '3.0' CM HEIGHT 0 TW FRAME 10 TW

    /: BOX XPOS '22.3' CM YPOS '3.65' CM WIDTH '4.8' CM HEIGHT 0 TW FRAME 10 TW

    /: BOX XPOS '3.20' CM YPOS '4.15' CM WIDTH '5.1' CM HEIGHT 0 TW FRAME 10 TW

    /: BOX XPOS '22.3' CM YPOS '4.15' CM WIDTH '4.8'CM HEIGHT 0 TW FRAME 10 TW

    /* BOX XPOS '7.80'CM YPOS '4.65' CM WIDTH '6.0' CM HEIGHT 0 TW FRAME 10 TW

    /* BOX XPOS '7.80'CM YPOS '5.15' CM WIDTH '6.0' CM HEIGHT 0 TW FRAME 10 TW

    /: BOX XPOS '7.00'CM YPOS '5.65' CM WIDTH '6.0' CM HEIGHT 0 TW FRAME 10 TW

    /: BOX XPOS '7.00'CM YPOS '6.15' CM WIDTH '6.0' CM HEIGHT 0 TW FRAME 10 TW

    /: BOX XPOS '7.00'CM YPOS '6.65' CM WIDTH '6.0' CM HEIGHT 0 TW FRAME 10 TW

    /: BOX XPOS '7.00'CM YPOS '7.15' CM WIDTH '6.0' CM HEIGHT 0 TW FRAME 10 TW

    /: BOX XPOS '7.00'CM YPOS '8.15' CM WIDTH '6.0' CM HEIGHT 0 TW FRAME 10 TW

    /: BOX XPOS '7.00'CM YPOS '8.65' CM WIDTH '6.0' CM HEIGHT 0 TW FRAME 10 TW

    /: BOX XPOS '21.10'CM YPOS '5.65' CM WIDTH '6.0' CM HEIGHT 0 TW FRAME 10 TW

    /: BOX XPOS '21.1'CM YPOS '6.15' CM WIDTH '6.0' CM HEIGHT 0 TW FRAME 10 TW

    /: BOX XPOS '21.1'CM YPOS '6.65' CM WIDTH '6.0' CM HEIGHT 0 TW FRAME 10 TW

    /: BOX XPOS '21.1'CM YPOS '7.15' CM WIDTH '6.0' CM HEIGHT 0 TW FRAME 10 TW

    /: BOX XPOS '21.1'CM YPOS '8.15' CM WIDTH '6.0' CM HEIGHT 0 TW FRAME 10 TW

    /: BOX XPOS '21.1'CM YPOS '8.65' CM WIDTH '6.0' CM HEIGHT 0 TW FRAME 10 TW

    MAIN

    Element HEADER1

    /: BOX FRAME 10 TW

    /* BOX YPOS '0.9' CM WIDTH '27.4' CM HEIGHT 0 TW FRAME 10 TW

    /: BOX YPOS '1.4' CM WIDTH '27.4' CM HEIGHT 0 TW FRAME 10 TW

    /: BOX YPOS '1.9' CM WIDTH '27.4' CM HEIGHT 0 TW FRAME 10 TW

    /: BOX YPOS '2.4' CM WIDTH '27.4' CM HEIGHT 0 TW FRAME 10 TW

    /: BOX YPOS '2.9' CM WIDTH '27.4' CM HEIGHT 0 TW FRAME 10 TW

    /: BOX YPOS '3.4' CM WIDTH '27.4' CM HEIGHT 0 TW FRAME 10 TW

    /: BOX YPOS '3.9' CM WIDTH '27.4' CM HEIGHT 0 TW FRAME 10 TW

    /: BOX YPOS '4.4' CM WIDTH '27.4' CM HEIGHT 0 TW FRAME 10 TW

    /: BOX YPOS '4.9' CM WIDTH '27.4' CM HEIGHT 0 TW FRAME 10 TW

    /: BOX YPOS '5.4' CM WIDTH '27.4' CM HEIGHT 0 TW FRAME 10 TW

    /: BOX XPOS '12.4' CM YPOS '0.5' CM WIDTH '3.0' CM HEIGHT 0 TW FRAME 10 TW

    /: BOX XPOS '20' CM YPOS '0.5' CM WIDTH '4.4' CM HEIGHT 0 TW FRAME 10 TW

    /* VERTICAL LINES

    /: BOX XPOS '1.6' CM YPOS '0.0' CM WIDTH 0 TW HEIGHT '5.9' CM FRAME 10 TW

    /: BOX XPOS '4.6' CM YPOS '0.0' CM WIDTH 0 TW HEIGHT '5.9' CM FRAME 10 TW

    /: BOX XPOS '8.4' CM YPOS '0.0' CM WIDTH 0 TW HEIGHT '5.9' CM FRAME 10 TW

    /: BOX XPOS '11' CM YPOS '0.0' CM WIDTH 0 TW HEIGHT '5.9' CM FRAME 10 TW

    /: BOX XPOS '12.4' CM YPOS '0.0' CM WIDTH 0 TW HEIGHT '5.9' CM FRAME 10 TW

    /: BOX XPOS '15.4' CM YPOS '0.0' CM WIDTH 0 TW HEIGHT '5.9' CM FRAME 10 TW

    /: BOX XPOS '17.8' CM YPOS '0.0' CM WIDTH 0 TW HEIGHT '5.9' CM FRAME 10 TW

    /: BOX XPOS '20' CM YPOS '0.0' CM WIDTH 0 TW HEIGHT '5.9' CM FRAME 10 TW

    /: BOX XPOS '24.4' CM YPOS '0.0' CM WIDTH 0 TW HEIGHT '5.9' CM FRAME 10 TW

    /: BOX XPOS '13.9' CM YPOS '0.5' CM WIDTH 0 TW HEIGHT '5.4' CM FRAME 10 TW

    /: BOX XPOS '22.2' CM YPOS '0.5' CM WIDTH 0 TW HEIGHT '5.4' CM FRAME 10 TW

    In the same way all windows can be defined.

    PS : If you ask any specific probelm then it would be much easier for us to reply 😊

    Please reward points if useful

    Add comment
    10|10000 characters needed characters exceeded