Tips and Tricks for the ABAP® Programming Language
Y9030011: List generation with FIELD-GROUPS and random number generator ‘QF05_RANDOM’
Through the function module ‘QF05_RANDOM’ random numbers can be created. In connection with e.g. FIELD-GROUPS different list steps are possible.
ABAP™-Source-Code
You can cut and paste the source code directly into the ABAP™-Workbench.
REPORT Y9030011 LINE-SIZE 130. "Release 3.1G, 4.5A
************************************************************************
* Copyright (c) 1999 by CT-Team, 33415 Verl, http://www.ct-software.com
*
* You can use or modify this report for your own work as long
* as you don't try to sell or republish it.
* In no event will the author be liable for indirect, special,
* Incidental, or consequental damages (if any) arising out of
* the use of this report.
*
*//////////////////////////////////////////////////////////////////////*
* Subject: Creation of lists mit extra data
BREAK-POINT.
MOVE: 'List creation with ''FIELD-GROUPS, INSERT, EXTRACT ...'' '
TO SY-TITLE.
*//////////////////////////////////////////////////////////////////////*
************************************************************************
* Declaration of variables *
************************************************************************
*
DATA: LAGERORT(4) TYPE N. "Header
DATA: LAGERREGAL(3) TYPE N. "
DATA: PALETTE(1) TYPE N. "
DATA: MENGE1(4) TYPE P. "Group
DATA: MENGE2(4) TYPE P. "
DATA: MENGE3(4) TYPE P. "
*.......................................................................
DATA: OMENGE1(4) TYPE P. "Computing fields
DATA: OMENGE2(4) TYPE P. "
DATA: OMENGE3(4) TYPE P. "
DATA: NMENGE1(4) TYPE P. "
DATA: NMENGE2(4) TYPE P. "
DATA: NMENGE3(4) TYPE P. "
DATA: GMENGE1(4) TYPE P. "
DATA: GMENGE2(4) TYPE P. "
DATA: GMENGE3(4) TYPE P. "
*.......................................................................
DATA: ZAHL LIKE QF00-RAN_NUMBER. "Help fields
DATA: EWERT TYPE I. "
DATA: PALETTE2(2) TYPE N. "
*
************************************************************************
* Assigning of fields to FIELD-GROUPS (no memory consumption) *
************************************************************************
*..................Deklaration of groups ..............................
FIELD-GROUPS: HEADER, GRUPPE_A.
*
*..................Deklaration of groups fields ........................
INSERT LAGERORT LAGERREGAL PALETTE INTO HEADER.
INSERT MENGE1 MENGE2 MENGE3 INTO GRUPPE_A.
*//////////////////////////////////////////////////////////////////////*
*-------------------------- Main Section ----------------------------*
*//////////////////////////////////////////////////////////////////////*
*
PERFORM AUFBAU-DATENVOLUMEN.
SORT. "the extra data will be sorted
PERFORM DISPLAY.
PERFORM AUSWERTEN-EXTRAKT-BESTAND.
*
*//////////////////////////////////////////////////////////////////////*
************* Subroutines *******************
*//////////////////////////////////////////////////////////////////////*
*
************************************************************************
* The data volume is created
************************************************************************
FORM AUFBAU-DATENVOLUMEN.
*
SKIP 2. ULINE.
WRITE:/1 'Step 1: The data volume will be generated ' COLOR 5.
*.......................................................................
*
DO 5 TIMES.
PERFORM ZUFALL USING ZAHL EWERT.
MOVE EWERT TO LAGERORT.
DO 3 TIMES.
PERFORM ZUFALL USING ZAHL EWERT.
MOVE EWERT TO LAGERREGAL.
DO 8 TIMES.
PERFORM ZUFALL USING ZAHL EWERT.
MOVE EWERT TO PALETTE2.
IF PALETTE2+1(1) EQ 0.
MOVE PALETTE2+0(1) TO PALETTE.
ELSE.
MOVE PALETTE2+1(1) TO PALETTE.
ENDIF.
DO 1 TIMES.
PERFORM ZUFALL USING ZAHL EWERT.
MENGE3 = EWERT * LAGERREGAL.
MENGE2 = EWERT * PALETTE2.
MENGE1 = EWERT * LAGERORT.
EXTRACT GRUPPE_A.
ENDDO.
ENDDO.
ENDDO.
ENDDO.
*
ENDFORM.
************************************************************************
* Determination of a random number from 1 to 100
************************************************************************
FORM ZUFALL USING ZAHL EWERT.
*.......................................................................
DO 10 TIMES.
CALL FUNCTION 'QF05_RANDOM'
IMPORTING RAN_NUMBER = ZAHL.
*
ZAHL = ZAHL * 100.
MOVE ZAHL TO EWERT.
IF EWERT NE 0.
EXIT.
ENDIF.
ENDDO.
*
IF EWERT EQ 0.
WRITE: /1 'Attention, random number is ''0'', please check routine'.
ENDIF.
*
ENDFORM.
************************************************************************
* Display of the generated data volume
************************************************************************
FORM DISPLAY.
*
SKIP 2. ULINE.
WRITE:/1 'Step 2: The generated data volumne after SORT: ' COLOR 5.
SKIP 1.
*
LOOP.
WRITE: /1 'Lagerort:',
11 LAGERORT,
17 'Lagerregal:',
29 LAGERREGAL,
33 'Palette:',
42 PALETTE,
48 MENGE1,
58 MENGE2,
68 MENGE3.
ENDLOOP.
*
ENDFORM.
************************************************************************
* The extracted data will evaluated
************************************************************************
FORM AUSWERTEN-EXTRAKT-BESTAND.
*
SKIP 2. ULINE.
WRITE:/1 'Step 3: The extracted data will be evaluated' COLOR 6.
*.......................................................................
LOOP.
*....................... AT NEW ......................................
AT NEW LAGERORT.
SKIP 2.
WRITE: /1 'LAGERORT:', LAGERORT.
ENDAT.
*.......................................................................
AT NEW LAGERREGAL.
SKIP 1.
WRITE: /5 'LAGERREGAL:', LAGERREGAL,
46 'Menge1 Menge2 Menge3'.
ENDAT.
*....................... AT END ......................................
AT END OF PALETTE.
WRITE: /12 'Summe PALETTE ', PALETTE.
PERFORM GESAMT-ONUMMER.
PERFORM DISPLAY-EXTRAKT.
ENDAT.
*.......................................................................
AT END OF LAGERREGAL.
WRITE: /7 'Summe LAGERREGAL:', LAGERREGAL.
PERFORM GESAMT-LNUMMER.
WRITE:
45 OMENGE1,
55 OMENGE2,
65 OMENGE3.
CLEAR: OMENGE1, OMENGE2, OMENGE3.
ENDAT.
*.......................................................................
AT END OF LAGERORT.
WRITE: /3 'Summe LAGERORT:', LAGERORT.
WRITE:
45 NMENGE1,
55 NMENGE2,
65 NMENGE3.
PERFORM GESAMT-MENGE.
CLEAR: NMENGE1, NMENGE2, NMENGE3.
ENDAT.
*.......................................................................
ENDLOOP.
*
SKIP 3. ULINE.
WRITE: /1 'Sum of all LAGERORTE:',
45 GMENGE1,
55 GMENGE2,
65 GMENGE3.
*
ENDFORM.
************************************************************************
* The content of the computing fields will be listed
************************************************************************
FORM DISPLAY-EXTRAKT.
*
WRITE:
45 MENGE1,
55 MENGE2,
65 MENGE3.
*.........................further aktion ............................
*
*
*
ENDFORM.
************************************************************************
* FIELDGROUP LAGERREGAL
************************************************************************
FORM GESAMT-LNUMMER.
*
*.......................................................................
ADD OMENGE1 TO NMENGE1.
ADD OMENGE2 TO NMENGE2.
ADD OMENGE3 TO NMENGE3.
*.........................further aktion ............................
*
*
ENDFORM.
************************************************************************
* FIELDGROUP Paletten
************************************************************************
FORM GESAMT-ONUMMER.
*
*.......................................................................
ADD MENGE1 TO OMENGE1.
ADD MENGE2 TO OMENGE2.
ADD MENGE3 TO OMENGE3.
*.........................further aktion ............................
*
*
ENDFORM.
************************************************************************
* FIELDGROUP LAGERORT
************************************************************************
FORM GESAMT-MENGE.
*
*.......................................................................
ADD NMENGE1 TO GMENGE1.
ADD NMENGE2 TO GMENGE2.
ADD NMENGE3 TO GMENGE3.
*.........................further aktion ............................
*
*
ENDFORM.
************************************************************************
******************* END OF PROGRAM *************************************
************************************************************************
