You are on page 1of 5

REPORT ZBASIC.

TABLES : VBRP , VBUK , VBPA , VBRK .

SELECT-OPTIONS: SALES FOR VBRK-VKORG,


DIST FOR VBRK-VTWEG,
DIV FOR VBRK-SPART,
SOLD FOR VBRK-KUNAG,
BILLINGD FOR VBRK-FKDAT,
DELIVERY FOR VBRP-VBELN,
BILLINGT FOR VBRK-FKART.
TYPES :
MATNR
VGBEL
AUBEL
LFSKT
VBELN
POSNR
ERNAM

BEGIN OF X_VBRPVBUK,
TYPE VBRP-MATNR,
TYPE VBRP-VGBEL,
TYPE VBRP-AUBEL,
TYPE VBUK-LFSTK,
TYPE VBRP-VBELN,
TYPE VBRP-POSNR,
TYPE VBRP-ERNAM,

END OF X_VBRPVBUK.
TYPES : BEGIN OF X_VBRK,
VKORG TYPE VBRK-VKORG,
VTWEG TYPE VBRK-VTWEG,
SPART TYPE VBRK-SPART,
KUNAG TYPE VBRK-KUNAG,
FKDAT TYPE VBRK-FKDAT,
*
VBELN TYPE VBRK-VBELN,
FKART TYPE VBRK-FKART,
ERNAM TYPE VBRK-ERNAM,
WAERK TYPE VBRK-WAERK,
NETWR TYPE VBRK-NETWR,
END OF X_VBRK.
TYPES : BEGIN OF X_VBPA,
PARVW TYPE VBPA-PARVW,
KUNNR TYPE VBPA-KUNNR,
POSNR TYPE VBPA-POSNR,
END OF X_VBPA.
TYPES : BEGIN OF X_FINAL,
MATNR TYPE VBRP-MATNR,
VGBEL TYPE VBRP-VGBEL,
AUBEL TYPE VBRP-AUBEL,
LFSKT TYPE VBUK-LFSTK,
VBELN TYPE VBRP-VBELN,
POSNR TYPE VBRP-POSNR,
ERNAM TYPE VBRP-ERNAM,
VKORG TYPE VBRK-VKORG,
VTWEG TYPE VBRK-VTWEG,
SPART TYPE VBRK-SPART,
KUNAG TYPE VBRK-KUNAG,
FKDAT TYPE VBRK-FKDAT,
*
VBELN TYPE VBRK-VBELN,
FKART TYPE VBRK-FKART,
*
ERNAM TYPE VBRK-ERNAME,
WAERK TYPE VBRK-WAERK,
NETWR TYPE VBRK-NETWR,
PARVW TYPE VBPA-PARVW,

KUNNR TYPE VBPA-KUNNR,


POSNR TYPE VBPA-POSNR,

END OF X_FINAL.
DATA : IT_VBRPVBUK TYPE TABLE OF X_VBRPVBUK WITH HEADER LINE,
IT_VBRK TYPE TABLE OF X_VBRK WITH HEADER LINE,
IT_VBPA TYPE TABLE OF X_VBPA WITH HEADER LINE,
IT_FINAL TYPE TABLE OF X_FINAL WITH HEADER LINE.
INITIALIZATION.
DELIVERY-SIGN = 'I'.
DELIVERY-OPTION = 'BT'.
DELIVERY-LOW = ' '.
DELIVERY-HIGH = ' '.
APPEND DELIVERY.
AT SELECTION-SCREEN.
PERFORM VALIDATION.
START-OF-SELECTION.
PERFORM INERJOIN.
PERFORM JOIN_VBRK.
PERFORM JOIN_VBPA.
END-OF-SELECTION.
PERFORM MOVEALL.
PERFORM DISPLAY.
TOP-OF-PAGE.
PERFORM PREPARED_HEADER.
*&---------------------------------------------------------------------*
*&
Form INERJOIN
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM INERJOIN .
SELECT VBRP~MATNR
VBRP~VGBEL
VBRP~AUBEL
VBUK~LFSTK
VBRP~VBELN
VBRP~POSNR
VBRP~ERNAM FROM VBRP INNER JOIN VBUK ON VBRP~VBELN = VBUK~VBELN INTO TABLE IT_VBRPVBUK
WHERE VBRP~VBELN IN DELIVERY.
ENDFORM.
" INERJOIN
*&---------------------------------------------------------------------*
*&
Form JOIN_VBRK
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM JOIN_VBRK .
IF IT_VBRPVBUK[] IS NOT INITIAL.
SELECT VKORG
VTWEG
SPART
KUNAG

FKDAT
FKART
ERNAM
WAERK
NETWR
from VBRK
INTO TABLE IT_VBRK
FOR ALL ENTRIES IN it_VBRPVBUK
WHERE ERNAM = it_VBRPVBUK-ERNAM.
ENDIF.

ENDFORM.
" JOIN_VBRK
*&---------------------------------------------------------------------*
*&
Form JOIN_VBPA
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM JOIN_VBPA .
IF it_VBRPVBUK[] is NOT INITIAL.
SELECT PARVW KUNNR POSNR
INTO TABLE it_VBPA
from vbPA
FOR ALL ENTRIES IN it_VBRPVBUK
WHERE POSNR = it_VBRPVBUK-POSNR.
endif.
ENDFORM.
" JOIN_VBPA
*&---------------------------------------------------------------------*
*&
Form MOVEALL
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM MOVEALL .
loop at IT_VBRPVBUK.
MOVE-CORRESPONDING IT_VBRPVBUK to it_final.

READ TABLE it_vbRK with KEY ERNAM = IT_VBRPVBUK-ERNAM.


if sy-subrc = 0.
move : IT_VBRK-VKORG TO IT_FINAL-VKORG,
IT_VBRK-ERNAM TO IT_FINAL-ERNAM,
IT_VBRK-WAERK TO IT_FINAL-WAERK,
IT_VBRK-NETWR TO IT_FINAL-NETWR,
IT_VBRK-VTWEG TO IT_FINAL-VTWEG,
IT_VBRK-SPART TO IT_FINAL-SPART,
IT_VBRK-KUNAG TO IT_FINAL-KUNAG,
IT_VBRK-FKDAT TO IT_FINAL-FKDAT,
IT_VBRK-VBELN TO IT_FINAL-VBELN,
IT_VBRK-FKART to it_final-FKART.
ENDIF.

READ TABLE it_vbPA WITH KEY POSNR = IT_VBRPVBUK-POSNR.


if sy-subrc = 0.

MOVE : it_vbPA-PARVW TO IT_FINAL-PARVW,


it_vbPA-KUNNR TO IT_FINAL-KUNNR,
it_vbPA-POSNR to it_final-POSNR.
ENDIF.
APPEND IT_FINAL.

endloop.
ENDFORM.
" MOVEALL
*&---------------------------------------------------------------------*
*&
Form DISPLAY
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM DISPLAY .
LOOP AT IT_FINAL.
WRITE : / IT_FINAL-MATNR COLOR 3,
IT_FINAL-VGBEL COLOR 3,
IT_FINAL-AUBEL,
IT_FINAL-LFSKT,
IT_FINAL-VKORG,
IT_FINAL-VTWEG,
IT_FINAL-SPART,
IT_FINAL-KUNAG,
IT_FINAL-FKDAT,
IT_FINAL-VBELN,
IT_FINAL-FKART,
IT_FINAL-POSNR,
IT_FINAL-PARVW,
IT_FINAL-KUNNR COLOR 3,
IT_FINAL-NETWR COLOR 6 INVERSE ON,
IT_FINAL-WAERK.
ENDLOOP.
ENDFORM.
*&---------------------------------------------------------------------*
*&
Form VALIDATION
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*
FORM VALIDATION .
DATA : P TYPE VBRP-VBELN.
SELECT SINGLE VBELN INTO P FROM VBRP WHERE VBELN IN DELIVERY.
IF SY-SUBRC <> 0.
MESSAGE 'INVALID DETAILS' TYPE 'I'.
ENDIF.

ENDFORM.
" VALIDATION
*&---------------------------------------------------------------------*
*&
Form PREPARED_HEADER
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
* --> p1
text
* <-- p2
text
*----------------------------------------------------------------------*

FORM PREPARED_HEADER .

WRITE : 'DESPATCH DETAILS'.


ULINE.
ENDFORM.