Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

Batch Input with 'Call Transaction'

Requirement:

Choose a transaction and write a Batch Input program with 'Call Transaction'. Do not use the
Message tab feature of 'Call Transaction'. In this case the last error message will be at the SY-
MSG* system fields. Recreate the complete error message from table T100! (This example is
also used by the demonstration of SY-MSG* system  fields)

Solution:
REPORT ZSYSTEM LINE-SIZE 255.
TABLES: T100.
* Batch-input data
DATA: BEGIN OF G_BDCDATA OCCURS 100.
        INCLUDE STRUCTURE BDCDATA.
DATA: END OF G_BDCDATA.

DATA: G_MESSAGE(200).

PERFORM FILL_BDCDATA.
CALL TRANSACTION 'FI01'  USING G_BDCDATA  MODE 'N'.
* of course it is nicer with a message itab, but this example
* should also demostrate the use of system variables.
SELECT SINGLE * FROM T100 WHERE
                SPRSL = 'E'
            AND ARBGB = SY-MSGID
            AND MSGNR = SY-MSGNO.
G_MESSAGE = T100-TEXT.

PERFORM REPLACE_PARAMETERS  USING     SY-MSGV1


                                      SY-MSGV2
                                      SY-MSGV3
                                      SY-MSGV4
                            CHANGING  G_MESSAGE.

WRITE: / 'System variables:'.


SKIP.
WRITE: / '        Sy-msgty:', SY-MSGTY.
WRITE: / '        Sy-msgid:', SY-MSGID.
WRITE: / '        Sy-msgno:', SY-MSGNO.
WRITE: / '        Sy-msgv1:', SY-MSGV1.
WRITE: / '        Sy-msgv2:', SY-MSGV2.
WRITE: / '        Sy-msgv3:', SY-MSGV3.
WRITE: / '        Sy-msgv4:', SY-MSGV4.
SKIP.
WRITE: / 'The transaction was called with a wrong country code.'.
WRITE: / 'The error message should be either that or that you have'.
WRITE: / '  no authorisation to execute the transaction'.
SKIP.
WRITE: / 'Message:'.
SKIP.
WRITE: / SY-MSGTY, G_MESSAGE.

*---------------------------------------------------------------------*
*       Build up the BDC-table                                        *
*---------------------------------------------------------------------*
FORM FILL_BDCDATA.
  REFRESH G_BDCDATA.

  PERFORM BDC_DYNPRO USING 'SAPMF02B' '0100'.


  PERFORM BDC_FIELD USING 'BNKA-BANKS' 'ZZZ'.
  PERFORM BDC_FIELD USING 'BDC_OKCODE' 'QQQQQ'.

ENDFORM.

*---------------------------------------------------------------------*
*       FORM BDC_DYNPRO                                               *
*---------------------------------------------------------------------*
*       Batchinput: Start new Dynpro                                  *
*---------------------------------------------------------------------*
FORM BDC_DYNPRO USING P_PROGRAM P_DYNPRO.
  CLEAR G_BDCDATA.
  G_BDCDATA-PROGRAM = P_PROGRAM.
  G_BDCDATA-DYNPRO = P_DYNPRO.
  G_BDCDATA-DYNBEGIN = 'X'.
  APPEND G_BDCDATA.
ENDFORM.                               " BDC_DYNPRO

*---------------------------------------------------------------------*
*       FORM BDC_FIELD                                                *
*---------------------------------------------------------------------*
*       Batchinput: Feld hinzufugen                                   *
*---------------------------------------------------------------------*
FORM BDC_FIELD USING P_FNAM P_FVAL.
  CLEAR G_BDCDATA.
  G_BDCDATA-FNAM = P_FNAM.
  G_BDCDATA-FVAL = P_FVAL.
  APPEND G_BDCDATA.
ENDFORM.                               " BDC_FIELD
*---------------------------------------------------------------------*
*       FORM REPLACE_PARAMETERS                                       *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
*  -->  P_PAR_1                                                       *
*  -->  P_PAR_2                                                       *
*  -->  P_PAR_3                                                       *
*  -->  P_PAR_4                                                       *
*  -->  P_MESSAGE                                                     *
*---------------------------------------------------------------------*
FORM REPLACE_PARAMETERS  USING    P_PAR_1
                                  P_PAR_2
                                  P_PAR_3
                                  P_PAR_4
                         CHANGING P_MESSAGE.

* erst mal pruefen, ob numerierte Parameter verwendet wurden


  DO.
    REPLACE '&1' WITH P_PAR_1 INTO P_MESSAGE.
    IF SY-SUBRC <> 0.
      EXIT.
    ENDIF.
  ENDDO.
  DO.
    REPLACE '&2' WITH P_PAR_2 INTO P_MESSAGE.
    IF SY-SUBRC <> 0.
      EXIT.
    ENDIF.
  ENDDO.
  DO.
    REPLACE '&3' WITH P_PAR_3 INTO P_MESSAGE.
    IF SY-SUBRC <> 0.
      EXIT.
    ENDIF.
  ENDDO.
  DO.
    REPLACE '&4' WITH P_PAR_4 INTO P_MESSAGE.
    IF SY-SUBRC <> 0.
      EXIT.
    ENDIF.
  ENDDO.
* falls keine numerierten Parameter vorh., ersetzen wie gehabt
  REPLACE '&' WITH P_PAR_1 INTO P_MESSAGE.
  CONDENSE P_MESSAGE.
  IF SY-SUBRC EQ 0.
    REPLACE '&' WITH P_PAR_2 INTO P_MESSAGE.
    CONDENSE P_MESSAGE.
    IF SY-SUBRC EQ 0.
      REPLACE '&' WITH P_PAR_3 INTO P_MESSAGE.
      CONDENSE P_MESSAGE.
      IF SY-SUBRC EQ 0.
        REPLACE '&' WITH P_PAR_4 INTO P_MESSAGE.
        CONDENSE P_MESSAGE.
      ENDIF.
    ENDIF.
  ENDIF.

ENDFORM.                               "replace_parameters

Interactive Reporting

Requirement:

List the first 100 purchase requsitions at the plant 'PL01' (table EBAN). Then make it possible to
change the purchase requisition itself from the list by clicking twice on the row or by using a
push-button.

Solution:

In the purchasing (MM modul) you can process the purchase requisitions. The purchase
requisitions define primarily the need for a material/service. List the first 100 purchase
requsitions at the plant 'PL01' (table EBAN). Then make it possible to change the purchase
requisition itself from the list by clicking twice on the row or by using a push-button.

ADDITIONAL REQUIREMENTS TO THE LIST:

1. CONTENT: PURCHASE REQUISITION NUMBER, ITEM NUMBER, DOCUMENT


TYPE, MATERIAL, QUANTITY, UNIT OF MEASURE

2. LAYOUT: MAIN HEADER SHOULD INCLUDE

PROGRAM NAME, COMPANY NAME, PLANT, PURCHASE GROUP, CREATION DATE,


PAGE NUMBER

3. ONE PAGE SHOULD HAVE 50 LINE ITEM

 
 

report zmjud001 no standard page heading line-size 85 line-count 50.


* DATA /TABLES DECLARATION*
tables: eban.
data: prog_nam(8).
data: begin of pur_req occurs 100,
ekgrp like eban-ekgrp,
werks like eban-werks,
banfn like eban-banfn,
bnfpo like eban-bnfpo,
bsart like eban-bsart,
estkz like eban-estkz,
matnr like eban-matnr,
menge like eban-menge,
meins like eban-meins,
numb(3) type n.
data: end of pur_req.
* THE REPORT HEADER
prog_nam = sy-repid.
top-of-page.
perform header_write.
* SELECTION
start-of-selection.
pur_req-numb = 1.
* SELECT ONLY THOSE FIELDS THAT WILL BE USED FROM THE TABLE EBAN,
AND ONLY
*THE FIRST100 RECORDS OF THE THE PLANT 'PL01'
select banfn bnfpo bsart ekgrp matnr werks menge meins frgdt estkz
into corresponding fields of eban from eban up to 100 rows
where bsart = 'NB' "document type 'NB' = purchase requisition
and werks = 'PL01'
and statu = 'N' "processing status
and loekz = ' '. "deletion indicator
* THE SELECTED RECORDS SHOULD BE APPENDED TO INTERNAL TABLE
'PUR_REQ'
pur_req-banfn = eban-banfn.
pur_req-matnr = eban-matnr.
pur_req-werks = eban-werks.
pur_req-ekgrp = eban-ekgrp.
pur_req-bnfpo = eban-bnfpo.
pur_req-bsart = eban-bsart.
pur_req-menge = eban-menge.
pur_req-meins = eban-meins.
pur_req-estkz = eban-estkz.
append pur_req.
pur_req-numb = pur_req-numb + 1.
endselect.
* CHECK WHETHER THE TABLE EBAN CONTAINS ANY PURCHASE REQUISITIONS
if sy-subrc ne 0.
write: / 'No Purchase Requisition found.'.
endif.
* PROCESS THE INTERNAL TABLE; WRITE OUT THE REQUIRED FIELDS AND HIDE
THE
*FIELDS YOU ARE GOING TO USE LATER
loop at pur_req.
write: /1 pur_req-numb, 9 pur_req-banfn, 21 pur_req-bnfpo, 31 pur_req-bsart, 41 pur_req-matnr,
61 pur_req-menge unit pur_req-meins, 82 pur_req-meins.
hide: pur_req-matnr, pur_req-werks, pur_req-banfn.
endloop.
clear pur_req-banfn. clear pur_req-matnr. clear pur_req-werks.
* IN THE MENU PAINTER (SE41) CREATE A STATUS TO YOUR PROGRAM. HERE
YOU CAN
*DEFINE THE PUSH-BUTTON
set pf-status 'basic'.
* CHOOSE A REQUISITION (WITH DOUBLE CLICKING OR PUSH-BUTTON) IN THE
LIST! THE
*PURCHASE REQUISITION IS GOING TO COME UP
at line-selection.
if pur_req-banfn <> space.
set parameter id 'BAN' field pur_req-banfn. " parameter id for pruchase req. number
call transaction 'ME52' and skip first screen. "trans. code 'ME52': Change Purchase Requis.
clear pur_req-banfn. clear pur_req-matnr.
clear pur_req-werks.
endif.
* FORM THE HEADER
form header_write.
write: / prog_nam, 32 'FUN-FACTORY',
/ 'Purch.Gr.:', pur_req-ekgrp, 26 'Purchase Requisition List',
61 'As Of Date:', 75 sy-datum,
/ 'Plant:', pur_req-werks, 61 'Page:', 75 sy-pagno.
uline.
write: / text-001,
/ text-002.
uline.
endform.

 
NOTES:

1. PUSH-BUTTON DEFINITION (SE11)

In the Menu Painter a status must be created where you can maintain the function keys

2. MAINTAIN THE TEXT ELEMENT TO THE HEADER OF THE LIST

(SE38 choose the object component 'TEXT ELEMENTS' at the first screen, then
the'TEXT SYMBOLS'. Here you can add a number (I.E. 001) to 'TEXT SYMBOL' and
write the header title into the text field like this:

001
Numb.__Requisition__Item___Document_____Material_____________________Quantity_Uni
t_of

002
_________Number_____Num______Type________________________________________Me
asure

THE FIRST 15 LINE ITEMS OF THE RESULT AND THE HEADERS:

ZMJUD001 FUN-FACTORY
Purch. Gr.: 001 Purchase Requisition List As Of Date: 05/09/1997
Plant: D031 Page: 1
-------------------------------------------------------------------------
Numb. Requisition Item Document Material Quantity Unit of
Number Num Type Measure
-------------------------------------------------------------------------
1 10049227 00010 NB 11141-030 23.000 CS
2 10049223 00010 NB 11141-030 23.000 CS
3 10049225 00010 NB 11141-030 13.000 CS
4 10049226 00010 NB 11141-030 9.000 CS
5 10049224 00010 NB 11141-030 23.000 CS
6 10049222 00010 NB 11141-030 23.000 CS
7 10049221 00010 NB 11141-030 38.000 CS
8 10049228 00010 NB 11141-030 23.000 CS
9 10049229 00010 NB 11141-030 23.000 CS
10 10049230 00010 NB 11141-030 22.000 CS
11 10049231 00010 NB 11141-030 24.000 CS
12 10049232 00010 NB 11141-030 24.000 CS
13 10049233 00010 NB 11141-030 24.000 CS
14 10049234 00010 NB 11141-030 23.000 CS
15 10049235 00010 NB 11141-030 5.000 CS
Creating Extract Dataset

Requirement:

Write a program that lists the Vendors and their Accounting documents. Create extract dataset
from KDF logical database. Loop through the dataset to create the required report. Don't list
those vendors which has no documents

Solution:

report zfwr0001 no standard page heading.

tables: lfa1, bsik.

field-groups: header, item1, item2.

insert lfa1-lifnr bsik-belnr into header.

insert lfa1-land1 lfa1-name1 into item1.

insert bsik-belnr bsik-budat into item2.

start-of-selection.

get lfa1.

....extract item1.

get bsik.

....extract item2.

end-of-selection.

loop.

....at item1 with item2.

........skip.

........write:/ 'Vendor number:', 28 'Name:', 56 'City:'.

........write: 16 lfa1-lifnr, 33(20) lfa1-name1, 62(20) lfa1-ort01.

........write:/ 'Document no.', 15 'Date'.

....endat.

....at item2.
........write:/ bsik-belnr, 13 bsik-budat.

....endat.

endloop.

Additional task:

Don't forget to set the Logical database to KDF on the "Program Attributes" screen.

Result:
Vendor number: 100124 Name:Coca Cola City: New York
Document no. Date
1800000316 01/08/1997
Vendor number: 100126 Name: Universal Studios City: Los Angeles
Document no. Date
1800000109 12/02/1996
1800000341 01/10/1997
1800000321 01/14/1997

You might also like