2009 Mar 05 6:25 PM
Hello ...
I have a requirement to create a report of all production orders for a given workcenter. The user enters the workcenter (CRHD-ARBPL), plant (CRHD-WERKS) and a date range, and wants to see a list of orders (AUFNR) that fall within that date range along with some other data from AFKO and AFPO.
I can't figure out a good, consistent way to get from workcenter to production orders.
Any ideas?
Thanks!
Sharon
2009 Mar 06 1:51 AM
Hi there check this program for relation between SO PO and Production order
REPORT z_so_info.
TABLES: vbak, vbap, afko, afpo.
*Field catalog
TYPE-POOLS: slis.
DATA: lv_repid TYPE sy-repid VALUE sy-repid,
xfield TYPE slis_t_fieldcat_alv,
afield TYPE slis_fieldcat_alv.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(25) text-002.
SELECT-OPTIONS: so_so FOR vbak-vbeln OBLIGATORY.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-003.
PARAMETERS:
p_kunnr LIKE vbak-kunnr, " sold-to
p_kunwe LIKE vbak-kunnr. " ship-to
SELECTION-SCREEN END OF BLOCK b2.
*--------------------------------------------------*
*Constants
*--------------------------------------------------*
CONSTANTS: c_zor TYPE vbak-auart VALUE 'ZOR',
c_we TYPE vbpa-parvw VALUE 'WE',
c_ag TYPE vbpa-parvw VALUE 'AG'.
* c_space TYPE space.
*--------------------------------------------------*
*Ranges
*--------------------------------------------------*
RANGES: ra_parvw FOR vbpa-parvw,
ra_kunnr FOR vbpa-kunnr.
*--------------------------------------------------*
*Tables
*--------------------------------------------------*
DATA: BEGIN OF gt_output OCCURS 0,
vbeln LIKE vbak-vbeln, " sales order number
posnr LIKE vbap-posnr, " SO item number
matnr LIKE vbap-matnr, " material number
sh LIKE vbpa-kunnr, " Ship-to
sp LIKE vbpa-kunnr, " Sold-to
lifnr LIKE ekko-lifnr, " Vendor
bstnk LIKE vbak-bstnk, " PO number
banfn LIKE vbep-banfn, " Purchase requi
po_st TYPE char30, " PO status text
pstyv TYPE vbap-pstyv, " Item catagory
aufnr LIKE afpo-aufnr, " Production Order
prd_stat TYPE string, " Prd order status
END OF gt_output.
DATA: wa_output LIKE gt_output.
FIELD-SYMBOLS: <fs_output> LIKE gt_output.
*Table for sales order and PO
TYPES : BEGIN OF gs_data,
vbeln TYPE vbak-vbeln,
posnr TYPE vbap-posnr,
pstyv TYPE vbap-pstyv,
matnr TYPE vbap-matnr,
END OF gs_data.
DATA: gt_data TYPE STANDARD TABLE OF gs_data,
wa_data TYPE gs_data.
*Table for Production Orders
TYPES: BEGIN OF gs_prd,
aufnr TYPE afpo-aufnr,
posnr TYPE afpo-posnr,
kdauf TYPE afpo-kdauf,
kdpos TYPE afpo-kdpos,
wepos TYPE afpo-wepos, "Goods Receipt Indicator
elikz TYPE afpo-elikz, "Delivery Completed Indicator
objnr TYPE aufk-objnr, "Object number
* getri TYPE afko-getri, "Confirmed Order Finish Date
* gltri TYPE afko-gltri, "Actual finish date
END OF gs_prd.
DATA: gt_prd TYPE STANDARD TABLE OF gs_prd,
wa_prd TYPE gs_prd.
*Table for partner data
TYPES: BEGIN OF gs_partner,
vbeln TYPE vbak-vbeln,
posnr TYPE vbap-posnr,
parvw TYPE vbpa-parvw,
kunnr TYPE vbpa-kunnr,
END OF gs_partner.
DATA: gt_partner TYPE STANDARD TABLE OF gs_partner,
wa_partner TYPE gs_partner.
TYPES: BEGIN OF gs_po,
ebeln TYPE ekkn-ebeln,
ebelp TYPE ekkn-ebelp,
vbeln TYPE ekkn-vbeln,
vbelp TYPE ekkn-vbelp,
END OF gs_po.
DATA: gt_po TYPE STANDARD TABLE OF gs_po,
wa_po TYPE gs_po.
TYPES: BEGIN OF gs_preq,
vbeln TYPE vbep-vbeln,
posnr TYPE vbep-posnr,
banfn TYPE vbep-banfn,
END OF gs_preq.
DATA: gt_preq TYPE STANDARD TABLE OF gs_preq,
wa_preq TYPE gs_preq.
TYPES: BEGIN OF gs_po_stat,
ebeln TYPE ekko-ebeln,
procstat TYPE ekko-procstat,
lifnr TYPE ekko-lifnr,
END OF gs_po_stat.
DATA: gt_po_stat TYPE STANDARD TABLE OF gs_po_stat,
wa_po_stat TYPE gs_po_stat.
*--------------------------------------------------*
*Field symbols
*--------------------------------------------------*
FIELD-SYMBOLS: <fs> TYPE tj02t-txt04,
<fs_temp> TYPE tj02t-txt04,
<fs_stat> TYPE char30.
*--------------------------------------------------*
START-OF-SELECTION.
*--------------------------------------------------*
PERFORM fr_build_range.
PERFORM fr_get_data.
PERFORM fr_build_fc.
PERFORM fr_output.
*&---------------------------------------------------------------------*
*& Form fr_get_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fr_get_data.
*Get SO
SELECT a~vbeln a~posnr a~pstyv a~matnr
FROM vbap AS a
JOIN vbak AS b
ON a~vbeln = b~vbeln
JOIN vbpa AS c
ON b~vbeln = c~vbeln
INTO TABLE gt_data
WHERE b~vbeln IN so_so
AND b~auart EQ c_zor "Only Sales Orders
AND c~kunnr IN ra_kunnr. "from selection screen
DELETE ADJACENT DUPLICATES FROM gt_data COMPARING vbeln posnr.
*get data of the production order
IF NOT gt_data[] IS INITIAL.
SELECT a~aufnr a~posnr a~kdauf a~kdpos a~wepos a~elikz
b~objnr
FROM afpo AS a
JOIN aufk AS b
ON a~aufnr = b~aufnr
INTO TABLE gt_prd
FOR ALL ENTRIES IN gt_data
WHERE a~kdauf EQ gt_data-vbeln
AND a~kdpos EQ gt_data-posnr.
ENDIF.
*Get partner data
IF NOT gt_data[] IS INITIAL.
SELECT vbeln posnr parvw kunnr
FROM vbpa
INTO TABLE gt_partner
FOR ALL ENTRIES IN gt_data
WHERE vbeln EQ gt_data-vbeln.
ENDIF.
*Get Purchase Order
IF NOT gt_data[] IS INITIAL.
SELECT ebeln ebelp vbeln vbelp
FROM ekkn
INTO TABLE gt_po
FOR ALL ENTRIES IN gt_data
WHERE vbeln EQ gt_data-vbeln
AND vbelp EQ gt_data-posnr.
SELECT vbeln posnr banfn
FROM vbep
INTO TABLE gt_preq
FOR ALL ENTRIES IN gt_data
WHERE vbeln EQ gt_data-vbeln
AND posnr EQ gt_data-posnr.
ENDIF.
IF NOT gt_po[] IS INITIAL.
SELECT a~ebeln a~procstat a~lifnr
FROM ekko AS a
JOIN ekpo AS b
ON a~ebeln = b~ebeln
INTO TABLE gt_po_stat
FOR ALL ENTRIES IN gt_po
WHERE b~ebeln EQ gt_po-ebeln
AND b~ebelp EQ gt_po-ebelp.
ENDIF.
*Move data to output table
LOOP AT gt_data INTO wa_data.
wa_output-vbeln = wa_data-vbeln.
wa_output-posnr = wa_data-posnr.
wa_output-pstyv = wa_data-pstyv.
wa_output-matnr = wa_data-matnr.
READ TABLE gt_po INTO wa_po WITH KEY vbeln = wa_data-vbeln
vbelp = wa_data-posnr.
IF sy-subrc EQ 0.
wa_output-bstnk = wa_po-ebeln.
READ TABLE gt_po_stat INTO wa_po_stat WITH KEY ebeln = wa_po-ebeln.
IF sy-subrc EQ 0.
wa_output-lifnr = wa_po_stat-lifnr.
CASE wa_po_stat-procstat.
WHEN '01'.
wa_output-po_st = 'Version in process'.
WHEN '02'.
wa_output-po_st = 'Active'.
WHEN '03'.
wa_output-po_st = 'In release'.
WHEN '04'.
wa_output-po_st = 'Partially released'.
WHEN '05'.
wa_output-po_st = 'Released Completely'.
WHEN '08'.
wa_output-po_st = 'Rejected'.
ENDCASE.
ENDIF. "inner read subrc
ENDIF. "outer read subrc
READ TABLE gt_preq INTO wa_preq WITH KEY vbeln = wa_data-vbeln
posnr = wa_data-posnr.
IF sy-subrc EQ 0.
wa_output-banfn = wa_preq-banfn.
ENDIF.
READ TABLE gt_prd INTO wa_prd WITH KEY kdauf = wa_data-vbeln
kdpos = wa_data-posnr.
IF sy-subrc EQ 0.
wa_output-aufnr = wa_prd-aufnr.
*get the purchase requisition for production order as well
SELECT SINGLE banfn
FROM ebkn
INTO wa_output-banfn
WHERE aufnr EQ wa_prd-aufnr.
*Get the status of the production order
PERFORM fr_get_prd_stat USING wa_prd-objnr
CHANGING wa_output-prd_stat.
ENDIF. " sy-subrc
READ TABLE gt_partner INTO wa_partner WITH KEY vbeln = wa_data-vbeln
parvw = c_we.
IF sy-subrc EQ 0.
wa_output-sh = wa_partner-kunnr.
ENDIF.
READ TABLE gt_partner INTO wa_partner WITH KEY vbeln = wa_data-vbeln
parvw = c_ag.
IF sy-subrc EQ 0.
wa_output-sp = wa_partner-kunnr.
ENDIF.
APPEND wa_output TO gt_output.
CLEAR: wa_data, wa_prd,wa_partner,wa_output.
ENDLOOP.
ENDFORM. " fr_get_data
*&---------------------------------------------------------------------*
*& Form fr_build_range
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fr_build_range .
*Range for partner function
MOVE 'I' TO ra_parvw-sign.
MOVE 'EQ' TO ra_parvw-option.
MOVE 'SH' TO ra_parvw-low. " we
APPEND ra_parvw.
CLEAR ra_parvw.
MOVE 'I' TO ra_parvw-sign.
MOVE 'EQ' TO ra_parvw-option.
MOVE 'SP' TO ra_parvw-low. " ag
APPEND ra_parvw.
CLEAR ra_parvw.
*Range for ship-to and sold-to
MOVE 'I' TO ra_kunnr-sign.
MOVE 'EQ' TO ra_kunnr-option.
MOVE p_kunnr TO ra_kunnr-low.
APPEND ra_kunnr.
CLEAR ra_kunnr.
MOVE 'I' TO ra_kunnr-sign.
MOVE 'EQ' TO ra_kunnr-option.
MOVE p_kunwe TO ra_kunnr-low.
APPEND ra_kunnr.
CLEAR ra_kunnr.
ENDFORM. " fr_build_range
*&---------------------------------------------------------------------*
*& Form fr_build_fc
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fr_build_fc .
* sales order number
afield-fieldname = 'VBELN'.
afield-seltext_s = 'Sales #'.
afield-ref_tabname = 'VBAK'.
APPEND afield TO xfield. CLEAR afield.
* sales ITEM number
afield-fieldname = 'POSNR'.
afield-seltext_s = 'Item #'.
afield-ref_tabname = 'VBAP'.
APPEND afield TO xfield. CLEAR afield.
* Material Number
afield-fieldname = 'MATNR'.
afield-seltext_s = 'Material #'.
afield-ref_tabname = 'VBAP'.
afield-outputlen = 10.
APPEND afield TO xfield. CLEAR afield.
*Vendor Number
afield-fieldname = 'LIFNR'.
afield-seltext_s = 'Vendor Num.'.
afield-ref_tabname = 'EKKO'.
APPEND afield TO xfield. CLEAR afield.
* ship-to-party
afield-fieldname = 'SH'.
afield-seltext_s = 'Ship-to'.
afield-ref_tabname = 'VBPA'.
APPEND afield TO xfield. CLEAR afield.
* sold-to-party
afield-fieldname = 'SP'.
afield-seltext_s = 'Sold-to'.
afield-ref_tabname = 'VBPA'.
APPEND afield TO xfield. CLEAR afield.
*PO number
afield-fieldname = 'BSTNK'.
afield-seltext_s = 'PO NUM'.
afield-ref_tabname = 'EKKO'.
APPEND afield TO xfield. CLEAR afield.
*PO status
* afield-fieldname = 'PO_STAT'.
* afield-seltext_s = 'Step'.
* afield-ref_tabname = 'zbacklog_v2'.
* APPEND afield TO xfield. CLEAR afield.
*PO step status
afield-fieldname = 'PO_ST'.
afield-seltext_s = 'PO.Status'.
afield-ref_tabname = 'zbacklog_v2'.
APPEND afield TO xfield. CLEAR afield.
*Purchase requisition
afield-fieldname = 'BANFN'.
afield-seltext_s = 'Pur. Req.'.
afield-ref_tabname = 'VBEP'.
APPEND afield TO xfield. CLEAR afield.
*Item catagory
afield-fieldname = 'PSTYV'.
afield-seltext_s = 'Itm. Catg'.
afield-ref_tabname = 'VBAP'.
APPEND afield TO xfield. CLEAR afield.
*Prodcution Order number
afield-fieldname = 'AUFNR'.
afield-seltext_m = 'Prod.Order'.
afield-ref_tabname = 'AFKO'.
APPEND afield TO xfield. CLEAR afield.
*PRODCUTION status
afield-fieldname = 'PRD_STAT'.
afield-seltext_s = 'Prd. Step'.
afield-ref_tabname = 'zbacklog_v2'.
afield-outputlen = 20.
APPEND afield TO xfield. CLEAR afield.
*PRODUCTION step status
* afield-fieldname = 'PRD_ST'.
* afield-seltext_s = 'Prd. Status'.
* afield-ref_tabname = 'zbacklog_v2'.
* APPEND afield TO xfield. CLEAR afield.
ENDFORM. " fr_build_fc
*&---------------------------------------------------------------------*
*& Form fr_output
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fr_output .
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-repid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_STRUCTURE_NAME =
* IS_LAYOUT =
it_fieldcat = xfield[]
i_default = 'X'
i_save = 'A'
TABLES
t_outtab = gt_output
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM. " fr_output
*&---------------------------------------------------------------------*
*& Form fr_get_prd_stat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_WA_PRD_OBJNR text
*----------------------------------------------------------------------*
FORM fr_get_prd_stat USING p_objnr CHANGING p_prd_stat.
DATA: lt_status TYPE STANDARD TABLE OF jstat,
wa_status TYPE jstat,
lv_status TYPE tj02t-txt04,
lv_temp2 TYPE char5,
lv_buff TYPE string.
CALL FUNCTION 'STATUS_READ'
EXPORTING
client = sy-mandt
objnr = p_objnr
only_active = 'X'
TABLES
status = lt_status
EXCEPTIONS
object_not_found = 1
OTHERS = 2.
LOOP AT lt_status INTO wa_status.
IF wa_status-stat(1) EQ 'I'.
SELECT txt04 FROM tj02t
INTO lv_status
WHERE istat EQ wa_status-stat
AND spras EQ 'E'.
ENDSELECT.
lv_temp2 = lv_status.
CONCATENATE lv_temp2 p_prd_stat INTO p_prd_stat
SEPARATED BY ','.
ENDIF.
CLEAR: wa_status, lv_status, lv_temp2.
ENDLOOP.
lv_buff = p_prd_stat.
*Status of Production Order
IF lv_buff CS 'CRTD'.
p_prd_stat = 'Not Active'.
ENDIF.
IF lv_buff CS 'REL'.
IF lv_buff CS 'GMPS'.
p_prd_stat = 'Printed In Prod'.
ELSE.
p_prd_stat = 'Printed'.
ENDIF.
ENDIF.
IF lv_buff CS 'TECO'.
p_prd_stat = 'Technically Compt.'.
ENDIF.
ENDFORM. " fr_get_prd_stat
2009 Mar 06 1:51 AM
Hi there check this program for relation between SO PO and Production order
REPORT z_so_info.
TABLES: vbak, vbap, afko, afpo.
*Field catalog
TYPE-POOLS: slis.
DATA: lv_repid TYPE sy-repid VALUE sy-repid,
xfield TYPE slis_t_fieldcat_alv,
afield TYPE slis_fieldcat_alv.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(25) text-002.
SELECT-OPTIONS: so_so FOR vbak-vbeln OBLIGATORY.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-003.
PARAMETERS:
p_kunnr LIKE vbak-kunnr, " sold-to
p_kunwe LIKE vbak-kunnr. " ship-to
SELECTION-SCREEN END OF BLOCK b2.
*--------------------------------------------------*
*Constants
*--------------------------------------------------*
CONSTANTS: c_zor TYPE vbak-auart VALUE 'ZOR',
c_we TYPE vbpa-parvw VALUE 'WE',
c_ag TYPE vbpa-parvw VALUE 'AG'.
* c_space TYPE space.
*--------------------------------------------------*
*Ranges
*--------------------------------------------------*
RANGES: ra_parvw FOR vbpa-parvw,
ra_kunnr FOR vbpa-kunnr.
*--------------------------------------------------*
*Tables
*--------------------------------------------------*
DATA: BEGIN OF gt_output OCCURS 0,
vbeln LIKE vbak-vbeln, " sales order number
posnr LIKE vbap-posnr, " SO item number
matnr LIKE vbap-matnr, " material number
sh LIKE vbpa-kunnr, " Ship-to
sp LIKE vbpa-kunnr, " Sold-to
lifnr LIKE ekko-lifnr, " Vendor
bstnk LIKE vbak-bstnk, " PO number
banfn LIKE vbep-banfn, " Purchase requi
po_st TYPE char30, " PO status text
pstyv TYPE vbap-pstyv, " Item catagory
aufnr LIKE afpo-aufnr, " Production Order
prd_stat TYPE string, " Prd order status
END OF gt_output.
DATA: wa_output LIKE gt_output.
FIELD-SYMBOLS: <fs_output> LIKE gt_output.
*Table for sales order and PO
TYPES : BEGIN OF gs_data,
vbeln TYPE vbak-vbeln,
posnr TYPE vbap-posnr,
pstyv TYPE vbap-pstyv,
matnr TYPE vbap-matnr,
END OF gs_data.
DATA: gt_data TYPE STANDARD TABLE OF gs_data,
wa_data TYPE gs_data.
*Table for Production Orders
TYPES: BEGIN OF gs_prd,
aufnr TYPE afpo-aufnr,
posnr TYPE afpo-posnr,
kdauf TYPE afpo-kdauf,
kdpos TYPE afpo-kdpos,
wepos TYPE afpo-wepos, "Goods Receipt Indicator
elikz TYPE afpo-elikz, "Delivery Completed Indicator
objnr TYPE aufk-objnr, "Object number
* getri TYPE afko-getri, "Confirmed Order Finish Date
* gltri TYPE afko-gltri, "Actual finish date
END OF gs_prd.
DATA: gt_prd TYPE STANDARD TABLE OF gs_prd,
wa_prd TYPE gs_prd.
*Table for partner data
TYPES: BEGIN OF gs_partner,
vbeln TYPE vbak-vbeln,
posnr TYPE vbap-posnr,
parvw TYPE vbpa-parvw,
kunnr TYPE vbpa-kunnr,
END OF gs_partner.
DATA: gt_partner TYPE STANDARD TABLE OF gs_partner,
wa_partner TYPE gs_partner.
TYPES: BEGIN OF gs_po,
ebeln TYPE ekkn-ebeln,
ebelp TYPE ekkn-ebelp,
vbeln TYPE ekkn-vbeln,
vbelp TYPE ekkn-vbelp,
END OF gs_po.
DATA: gt_po TYPE STANDARD TABLE OF gs_po,
wa_po TYPE gs_po.
TYPES: BEGIN OF gs_preq,
vbeln TYPE vbep-vbeln,
posnr TYPE vbep-posnr,
banfn TYPE vbep-banfn,
END OF gs_preq.
DATA: gt_preq TYPE STANDARD TABLE OF gs_preq,
wa_preq TYPE gs_preq.
TYPES: BEGIN OF gs_po_stat,
ebeln TYPE ekko-ebeln,
procstat TYPE ekko-procstat,
lifnr TYPE ekko-lifnr,
END OF gs_po_stat.
DATA: gt_po_stat TYPE STANDARD TABLE OF gs_po_stat,
wa_po_stat TYPE gs_po_stat.
*--------------------------------------------------*
*Field symbols
*--------------------------------------------------*
FIELD-SYMBOLS: <fs> TYPE tj02t-txt04,
<fs_temp> TYPE tj02t-txt04,
<fs_stat> TYPE char30.
*--------------------------------------------------*
START-OF-SELECTION.
*--------------------------------------------------*
PERFORM fr_build_range.
PERFORM fr_get_data.
PERFORM fr_build_fc.
PERFORM fr_output.
*&---------------------------------------------------------------------*
*& Form fr_get_data
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fr_get_data.
*Get SO
SELECT a~vbeln a~posnr a~pstyv a~matnr
FROM vbap AS a
JOIN vbak AS b
ON a~vbeln = b~vbeln
JOIN vbpa AS c
ON b~vbeln = c~vbeln
INTO TABLE gt_data
WHERE b~vbeln IN so_so
AND b~auart EQ c_zor "Only Sales Orders
AND c~kunnr IN ra_kunnr. "from selection screen
DELETE ADJACENT DUPLICATES FROM gt_data COMPARING vbeln posnr.
*get data of the production order
IF NOT gt_data[] IS INITIAL.
SELECT a~aufnr a~posnr a~kdauf a~kdpos a~wepos a~elikz
b~objnr
FROM afpo AS a
JOIN aufk AS b
ON a~aufnr = b~aufnr
INTO TABLE gt_prd
FOR ALL ENTRIES IN gt_data
WHERE a~kdauf EQ gt_data-vbeln
AND a~kdpos EQ gt_data-posnr.
ENDIF.
*Get partner data
IF NOT gt_data[] IS INITIAL.
SELECT vbeln posnr parvw kunnr
FROM vbpa
INTO TABLE gt_partner
FOR ALL ENTRIES IN gt_data
WHERE vbeln EQ gt_data-vbeln.
ENDIF.
*Get Purchase Order
IF NOT gt_data[] IS INITIAL.
SELECT ebeln ebelp vbeln vbelp
FROM ekkn
INTO TABLE gt_po
FOR ALL ENTRIES IN gt_data
WHERE vbeln EQ gt_data-vbeln
AND vbelp EQ gt_data-posnr.
SELECT vbeln posnr banfn
FROM vbep
INTO TABLE gt_preq
FOR ALL ENTRIES IN gt_data
WHERE vbeln EQ gt_data-vbeln
AND posnr EQ gt_data-posnr.
ENDIF.
IF NOT gt_po[] IS INITIAL.
SELECT a~ebeln a~procstat a~lifnr
FROM ekko AS a
JOIN ekpo AS b
ON a~ebeln = b~ebeln
INTO TABLE gt_po_stat
FOR ALL ENTRIES IN gt_po
WHERE b~ebeln EQ gt_po-ebeln
AND b~ebelp EQ gt_po-ebelp.
ENDIF.
*Move data to output table
LOOP AT gt_data INTO wa_data.
wa_output-vbeln = wa_data-vbeln.
wa_output-posnr = wa_data-posnr.
wa_output-pstyv = wa_data-pstyv.
wa_output-matnr = wa_data-matnr.
READ TABLE gt_po INTO wa_po WITH KEY vbeln = wa_data-vbeln
vbelp = wa_data-posnr.
IF sy-subrc EQ 0.
wa_output-bstnk = wa_po-ebeln.
READ TABLE gt_po_stat INTO wa_po_stat WITH KEY ebeln = wa_po-ebeln.
IF sy-subrc EQ 0.
wa_output-lifnr = wa_po_stat-lifnr.
CASE wa_po_stat-procstat.
WHEN '01'.
wa_output-po_st = 'Version in process'.
WHEN '02'.
wa_output-po_st = 'Active'.
WHEN '03'.
wa_output-po_st = 'In release'.
WHEN '04'.
wa_output-po_st = 'Partially released'.
WHEN '05'.
wa_output-po_st = 'Released Completely'.
WHEN '08'.
wa_output-po_st = 'Rejected'.
ENDCASE.
ENDIF. "inner read subrc
ENDIF. "outer read subrc
READ TABLE gt_preq INTO wa_preq WITH KEY vbeln = wa_data-vbeln
posnr = wa_data-posnr.
IF sy-subrc EQ 0.
wa_output-banfn = wa_preq-banfn.
ENDIF.
READ TABLE gt_prd INTO wa_prd WITH KEY kdauf = wa_data-vbeln
kdpos = wa_data-posnr.
IF sy-subrc EQ 0.
wa_output-aufnr = wa_prd-aufnr.
*get the purchase requisition for production order as well
SELECT SINGLE banfn
FROM ebkn
INTO wa_output-banfn
WHERE aufnr EQ wa_prd-aufnr.
*Get the status of the production order
PERFORM fr_get_prd_stat USING wa_prd-objnr
CHANGING wa_output-prd_stat.
ENDIF. " sy-subrc
READ TABLE gt_partner INTO wa_partner WITH KEY vbeln = wa_data-vbeln
parvw = c_we.
IF sy-subrc EQ 0.
wa_output-sh = wa_partner-kunnr.
ENDIF.
READ TABLE gt_partner INTO wa_partner WITH KEY vbeln = wa_data-vbeln
parvw = c_ag.
IF sy-subrc EQ 0.
wa_output-sp = wa_partner-kunnr.
ENDIF.
APPEND wa_output TO gt_output.
CLEAR: wa_data, wa_prd,wa_partner,wa_output.
ENDLOOP.
ENDFORM. " fr_get_data
*&---------------------------------------------------------------------*
*& Form fr_build_range
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fr_build_range .
*Range for partner function
MOVE 'I' TO ra_parvw-sign.
MOVE 'EQ' TO ra_parvw-option.
MOVE 'SH' TO ra_parvw-low. " we
APPEND ra_parvw.
CLEAR ra_parvw.
MOVE 'I' TO ra_parvw-sign.
MOVE 'EQ' TO ra_parvw-option.
MOVE 'SP' TO ra_parvw-low. " ag
APPEND ra_parvw.
CLEAR ra_parvw.
*Range for ship-to and sold-to
MOVE 'I' TO ra_kunnr-sign.
MOVE 'EQ' TO ra_kunnr-option.
MOVE p_kunnr TO ra_kunnr-low.
APPEND ra_kunnr.
CLEAR ra_kunnr.
MOVE 'I' TO ra_kunnr-sign.
MOVE 'EQ' TO ra_kunnr-option.
MOVE p_kunwe TO ra_kunnr-low.
APPEND ra_kunnr.
CLEAR ra_kunnr.
ENDFORM. " fr_build_range
*&---------------------------------------------------------------------*
*& Form fr_build_fc
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fr_build_fc .
* sales order number
afield-fieldname = 'VBELN'.
afield-seltext_s = 'Sales #'.
afield-ref_tabname = 'VBAK'.
APPEND afield TO xfield. CLEAR afield.
* sales ITEM number
afield-fieldname = 'POSNR'.
afield-seltext_s = 'Item #'.
afield-ref_tabname = 'VBAP'.
APPEND afield TO xfield. CLEAR afield.
* Material Number
afield-fieldname = 'MATNR'.
afield-seltext_s = 'Material #'.
afield-ref_tabname = 'VBAP'.
afield-outputlen = 10.
APPEND afield TO xfield. CLEAR afield.
*Vendor Number
afield-fieldname = 'LIFNR'.
afield-seltext_s = 'Vendor Num.'.
afield-ref_tabname = 'EKKO'.
APPEND afield TO xfield. CLEAR afield.
* ship-to-party
afield-fieldname = 'SH'.
afield-seltext_s = 'Ship-to'.
afield-ref_tabname = 'VBPA'.
APPEND afield TO xfield. CLEAR afield.
* sold-to-party
afield-fieldname = 'SP'.
afield-seltext_s = 'Sold-to'.
afield-ref_tabname = 'VBPA'.
APPEND afield TO xfield. CLEAR afield.
*PO number
afield-fieldname = 'BSTNK'.
afield-seltext_s = 'PO NUM'.
afield-ref_tabname = 'EKKO'.
APPEND afield TO xfield. CLEAR afield.
*PO status
* afield-fieldname = 'PO_STAT'.
* afield-seltext_s = 'Step'.
* afield-ref_tabname = 'zbacklog_v2'.
* APPEND afield TO xfield. CLEAR afield.
*PO step status
afield-fieldname = 'PO_ST'.
afield-seltext_s = 'PO.Status'.
afield-ref_tabname = 'zbacklog_v2'.
APPEND afield TO xfield. CLEAR afield.
*Purchase requisition
afield-fieldname = 'BANFN'.
afield-seltext_s = 'Pur. Req.'.
afield-ref_tabname = 'VBEP'.
APPEND afield TO xfield. CLEAR afield.
*Item catagory
afield-fieldname = 'PSTYV'.
afield-seltext_s = 'Itm. Catg'.
afield-ref_tabname = 'VBAP'.
APPEND afield TO xfield. CLEAR afield.
*Prodcution Order number
afield-fieldname = 'AUFNR'.
afield-seltext_m = 'Prod.Order'.
afield-ref_tabname = 'AFKO'.
APPEND afield TO xfield. CLEAR afield.
*PRODCUTION status
afield-fieldname = 'PRD_STAT'.
afield-seltext_s = 'Prd. Step'.
afield-ref_tabname = 'zbacklog_v2'.
afield-outputlen = 20.
APPEND afield TO xfield. CLEAR afield.
*PRODUCTION step status
* afield-fieldname = 'PRD_ST'.
* afield-seltext_s = 'Prd. Status'.
* afield-ref_tabname = 'zbacklog_v2'.
* APPEND afield TO xfield. CLEAR afield.
ENDFORM. " fr_build_fc
*&---------------------------------------------------------------------*
*& Form fr_output
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM fr_output .
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
i_callback_program = sy-repid
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_STRUCTURE_NAME =
* IS_LAYOUT =
it_fieldcat = xfield[]
i_default = 'X'
i_save = 'A'
TABLES
t_outtab = gt_output
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM. " fr_output
*&---------------------------------------------------------------------*
*& Form fr_get_prd_stat
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_WA_PRD_OBJNR text
*----------------------------------------------------------------------*
FORM fr_get_prd_stat USING p_objnr CHANGING p_prd_stat.
DATA: lt_status TYPE STANDARD TABLE OF jstat,
wa_status TYPE jstat,
lv_status TYPE tj02t-txt04,
lv_temp2 TYPE char5,
lv_buff TYPE string.
CALL FUNCTION 'STATUS_READ'
EXPORTING
client = sy-mandt
objnr = p_objnr
only_active = 'X'
TABLES
status = lt_status
EXCEPTIONS
object_not_found = 1
OTHERS = 2.
LOOP AT lt_status INTO wa_status.
IF wa_status-stat(1) EQ 'I'.
SELECT txt04 FROM tj02t
INTO lv_status
WHERE istat EQ wa_status-stat
AND spras EQ 'E'.
ENDSELECT.
lv_temp2 = lv_status.
CONCATENATE lv_temp2 p_prd_stat INTO p_prd_stat
SEPARATED BY ','.
ENDIF.
CLEAR: wa_status, lv_status, lv_temp2.
ENDLOOP.
lv_buff = p_prd_stat.
*Status of Production Order
IF lv_buff CS 'CRTD'.
p_prd_stat = 'Not Active'.
ENDIF.
IF lv_buff CS 'REL'.
IF lv_buff CS 'GMPS'.
p_prd_stat = 'Printed In Prod'.
ELSE.
p_prd_stat = 'Printed'.
ENDIF.
ENDIF.
IF lv_buff CS 'TECO'.
p_prd_stat = 'Technically Compt.'.
ENDIF.
ENDFORM. " fr_get_prd_stat
2009 Mar 06 5:34 AM
Hi Sharon
You want full report?
else Check TCode "IW39".
Regards.
2009 Mar 06 4:32 PM
Thanks so much for the replies...
I couldn't get anything to come up when using transaction IW39 - I'm not sure what tables it's going against, but it wouldn't return anything.
And J@Y, your program was helpful, but I ended up finding the link by going from CRHD to AFVC using object ID, then getting all orders from AFKO where AFKO-AUFPL = AFVC-AUFPL.
Thanks again!
Sharon