TABLES:vbrk,vbrp,kna1,nast.
DATA : BEGIN OF kitab OCCURS 0,
vbeln LIKE vbrk-vbeln,
fkdat LIKE vbrk-fkdat,
fkart LIKE vbrk-fkart,
knumv LIKE konv-knumv,
name1 LIKE kna1-name1,
END OF kitab.
DATA: BEGIN OF in_itab OCCURS 0,
vbeln LIKE vbrp-vbeln,
posnr LIKE vbrp-posnr,
fkimg LIKE vbrp-fkimg,
meins LIKE vbrp-meins,
matnr LIKE vbrp-matnr,
arktx LIKE vbrp-arktx,
END OF in_itab.
DATA : BEGIN OF citab OCCURS 0,
kposn LIKE konv-kposn,
kbetr LIKE konv-kbetr,
kwert LIKE konv-kwert,
END OF citab.
DATA : BEGIN OF itab_nast,
datvr LIKE nast-datvr,
uhrvr LIKE nast-uhrvr,
END OF itab_nast.
DATA: flag,count.
DATA: BEGIN OF fin_itab OCCURS 0,
vbeln LIKE vbrp-vbeln,
posnr LIKE vbrp-posnr,
fkimg LIKE vbrp-fkimg,
meins LIKE vbrp-meins,
matnr LIKE vbrp-matnr,
arktx LIKE vbrp-arktx,
kwert LIKE konv-kwert,
kbetr LIKE konv-kbetr,
END OF fin_itab.
PARAMETERS : p_vbeln LIKE vbrk-vbeln.
AT SELECTION-SCREEN.
SELECT SINGLE vbeln FROM vbrk INTO p_vbeln WHERE vbeln = p_vbeln.
IF sy-subrc <> 0.
MESSAGE e000.
LEAVE PROGRAM.
ENDIF.
START-OF-SELECTION.
PERFORM selection.
PERFORM check.
CALL FUNCTION '/1BCDWB/SF00000239'
EXPORTING
* ARCHIVE_INDEX =
* ARCHIVE_INDEX_TAB =
* ARCHIVE_PARAMETERS =
* CONTROL_PARAMETERS =
* MAIL_APPL_OBJ =
* MAIL_RECIPIENT =
* MAIL_SENDER =
* OUTPUT_OPTIONS =
* USER_SETTINGS = 'X'
pflag = FLAG
* IMPORTING
* DOCUMENT_OUTPUT_INFO =
* JOB_OUTPUT_INFO =
* JOB_OUTPUT_OPTIONS =
tables
itab = FIN_ITAB
hitab = KITAB
* EXCEPTIONS
* FORMATTING_ERROR = 1
* INTERNAL_ERROR = 2
* SEND_ERROR = 3
* USER_CANCELED = 4
* OTHERS = 5
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*&---------------------------------------------------------------------*
*& Form selection
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM selection .
SELECT a~vbeln a~fkdat a~fkart a~knumv b~name1 INTO TABLE kitab
FROM vbrk AS a INNER JOIN kna1 AS b
ON a~kunrg = b~kunnr
WHERE vbeln = p_vbeln.
READ TABLE kitab INDEX 1.
SELECT kposn kwert kbetr FROM konv INTO TABLE citab WHERE knumv = kitab-knumv
AND kschl = 'ZHPR'.
SELECT vbeln posnr fkimg meins matnr arktx FROM vbrp INTO TABLE in_itab
WHERE vbeln = kitab-vbeln.
LOOP AT in_itab.
LOOP AT citab.
IF in_itab-posnr = citab-kposn.
MOVE-CORRESPONDING in_itab TO fin_itab.
MOVE-CORRESPONDING citab TO fin_itab.
APPEND fin_itab.
ENDIF.
ENDLOOP.
ENDLOOP.
ENDFORM. " selection
*&---------------------------------------------------------------------*
*& Form check
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM check .
UNPACK p_vbeln TO p_vbeln.
SELECT datvr uhrvr INTO itab_nast FROM nast WHERE nacha = '1' AND
objky = p_vbeln.
ENDSELECT.
IF sy-subrc = 0.
flag = 1.
ELSE.
flag = 0.
ENDIF.