SAP R/3

ABAP/4 Example Code: Download OTF Spool to PDF

*** This program receive spool id and destination file name ***
DATA: it_pdf TYPE TABLE OF TLINE WITH HEADER LINE,
      gv_string TYPE string.

PARAMETERS: p_spool LIKE TSP01-RQIDENT,
            p_file LIKE RLGRAP-FILENAME.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
  CALL FUNCTION ’KD_GET_FILENAME_ON_F4’
    EXPORTING
*     PROGRAM_NAME        = SYST-REPID
*     DYNPRO_N

How to define macro in ABAP/4

We can define macro by apply statement DEFINE ... END-OF-DEFINITION.

Example


DATA: itab TYPE TABLE OF sflight WITH HEADER LINE.
RANGES: r_carrid FOR sflight-carrid.
DEFINE append_range.
  &1-sign = &2.
  &1-option = &3.
  &1-low = &4.
  append &1.
END-OF-DEFINITION.
INITIALIZATION.
  append_range r_carrid ’I’ ’EQ’ ’AA’.
  append_range r_carrid ’I’ ’EQ’ ’AB’.
START-OF-SELECTION.
  SELECT * FROM sflight INTO TABLE itab
           WHERE carrid in r_carrid.
  IF SY-SUBRC = 0.
    LOOP AT itab.
      WRITE:/ itab-carrid, itab-connid, itab-fldate.
    ENDLOOP.
  ENDIF.
Note: You can define parameters only 9 (&1 ...

ABAP/4 Example Code: How to call SAPscript form from ABAP report

Now we already have SAPscript form name ’ZFORM001’ and in this form we have element ’LINE1’ on window ’MAIN’. We want to call this form from ABAP report.

Example:


START-OF-SELECTION.
  PERFORM OPEN_FORM.
  PERFORM START_FORM.
  PERFORM WRITE_FORM USING ’LINE1’.
  PERFORM END_FORM.
  PERFORM CLOSE_FORM.

*&---------------------------------------------------------------------*
*&      Form  OPEN_FORM
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM OPEN_FORM .
  CALL FUNCTION ’OPEN_FORM’
*   EXPORTING
*     APPLICATION                       = ’TX’
*     ARCHIVE_INDEX                     =
*     ARCHIVE_PARAMS                    =
*     DEVICE                            = ’PRINTER’
*     DIALOG                            = ’X’
*     FORM                              = ’ ’
*     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.

ABAP/4 Example Code: SAVE_TEXT

You can create and save long text by apply function module ’SAVE_TEXT’.

Example: We will create program for create standard text. The created text will be contained text ’Test Create Text’. you can input name of long text on selection screen. After you run this program, you can check the output of program in transaction SO10 (Standard Text).


DATA: GW_THEAD LIKE THEAD,
      IT_LINE TYPE TABLE OF TLINE WITH HEADER LINE.
PARAMETERS: P_TXTNAM LIKE THEAD-TDNAME.
START-OF-SELECTION.

ABAP/4 Example Code: GET & GET ... LATE


*** Using Logical Database: F1S ***
TABLES: SPFLI,
SFLIGHT,
SBOOK,
        SCARR.
START-OF-SELECTION.
  GET SPFLI.
    WRITE:/ ’SPFLI: ’, SPFLI-CARRID, SPFLI-CONNID, SPFLI-AIRPFROM, SPFLI-AIRPTO.
    GET SFLIGHT.
WRITE:/  ’  SFLIGHT: ’, SFLIGHT-CARRID, SFLIGHT-CONNID,
SFLIGHT-FLDATE.
      GET SBOOK.
        WRITE:/ ’    SBOOK: ’, SBOOK-CARRID, SBOOK-CONNID,

How to define variable in SAPscript

You can define variable in SAPscript by apply statement ’DEFINE’.

Example: We will define variable name = ’TXT1’ and initial value = ’Text1’. After we already define it, we will write a value of field.


/: DEFINE &TXT1& = ’Text1’
*  Test Define Text = &TXT1&
img10

The Output is

 img11