Program to Mass Select Purchase Order and print history

4.6x

* Mass check PO history instead of doing it one at time via transaction ME22N.

report ZPOHISTORY line-size 132 no standard page heading.

tables : ekko,
         ekpo,
         ekbe,
         mseg,
         mkpf,
         bkpf,
         rbkp,
         lfa1.
 

select-options:  xebeln for ekko-ebeln memory id bes.
 

data: wttlqty like ekbe-menge,
      wttlamt like ekbe-dmbtr,
      wgrqty  like ekbe-menge,
      wgramt  like ekbe-dmbtr,
      wirqty  like ekbe-menge,
      wiramt  like ekbe-dmbtr.

data: wtxt1(4),
      wrefno like mkpf-xblnr,
      wbktxt like mkpf-bktxt.

data: begin of awkey,
        belnr like rbkp-belnr,
        gjahr like rbkp-gjahr,
      end of awkey.

field-groups: header.

insert
   ekko-ebeln
   ekko-lifnr
   ekbe-belnr
   ekbe-gjahr
   ekbe-ebelp
   ekbe-bwart
   ekbe-budat
   ekbe-menge
   ekbe-dmbtr
   ekbe-waers
   ekbe-bewtp
   ekpo-matnr
   ekpo-meins
   ekpo-txz01
*  bkpf-belnr
   wbktxt
   wrefno
   wtxt1
       into header.

select * from ekko where ebeln in xebeln.
  select * from ekpo where ebeln = ekko-ebeln.
    select * from ekbe where ebeln = ekko-ebeln and
                             ebelp = ekpo-ebelp and
                             ( bewtp = 'R' or
                               bewtp = 'E' or
                               bewtp = 'Q' ).
     if ekbe-bewtp = 'E'.
        wtxt1 = 'GR'.
        select single * from mkpf where mblnr = ekbe-belnr and
                                        mjahr = ekbe-gjahr.
        if sy-subrc = 0.
          wrefno = mkpf-xblnr.
          wbktxt = mkpf-bktxt.
        endif.
      else.
        if ekbe-bewtp = 'R'.
          select single * from bkpf where BUKRS = '0001' and
                                          BELNR = ekbe-belnr and
                                          gjahr = ekbe-gjahr.
          wtxt1 = 'IR'.
          wrefno = bkpf-xblnr.
          wbktxt = bkpf-bktxt.
        else.
          select single * from rbkp where belnr = ekbe-belnr and
                                          gjahr = ekbe-gjahr.
          wtxt1 = 'IR-L'.
          wrefno = rbkp-xblnr.
          wbktxt = rbkp-bktxt.
        endif.
      endif.
      if ekbe-shkzg = 'H'.
        ekbe-dmbtr = ekbe-dmbtr * -1.
        ekbe-menge = ekbe-menge * -1.
      endif.
      extract header.
      clear: wrefno, wbktxt.
    endselect.
  endselect.
endselect.

sort by ekko-ebeln ekbe-ebelp ekbe-bewtp ekbe-belnr.

loop.
  at new ekko-ebeln.
    perform po_head.
  endat.
  at new ekbe-ebelp.
    format color col_group inverse.
    write:/ '|', ekpo-matnr, ekpo-txz01,
          130 '|'.
    format inverse off.
  endat.
  format color col_normal.
  shift ekbe-ebelp.
  write:/ '|' no-gap,
          wtxt1 no-gap, '|' no-gap,
          ekbe-belnr no-gap, '|' no-gap,
          (4) ekbe-ebelp no-gap, '|' no-gap,
          ekbe-bwart no-gap, '|' no-gap,
          ekbe-budat dd/mm/yy no-gap, '|' no-gap,
          (15) ekbe-menge , ekpo-meins no-gap, '|' no-gap,
          (15) ekbe-dmbtr,
*          (3) ekbe-waers no-gap, '|' no-gap,
          'SGD' no-gap, '|' no-gap,
*          bkpf-belnr, '|' no-gap,
          wrefno no-gap, '|' no-gap,
          wbktxt no-gap, '|' no-gap.
  hide: ekbe-belnr, ekbe-gjahr, ekbe-bewtp.
  wttlqty = wttlqty + ekbe-menge.
  wttlamt = wttlamt + ekbe-dmbtr.
  at end of ekbe-bewtp.
    format color col_total.
    if wtxt1 = 'GR'.
      write:/ '|' ,
              'Item', ekbe-ebelp, 'Goods Receipts'.
*              25 '|'.
*              130 '|'.
      wgrqty  = wgrqty + wttlqty.
      wgramt  = wgramt + wttlamt.
    elseif wtxt1 = 'IR' or
           wtxt1 = 'IR-L'.
      write:/ '|' ,
              'Item', ekbe-ebelp, 'Invoices'.
      wirqty  = wirqty + wttlqty.
      wiramt  = wiramt + wttlamt.
    endif.
    write: 35 '|' no-gap,
           (15) wttlqty,
           '   |' no-gap,
           (15) wttlamt,
           '   |' no-gap,
              130 '|'.
    clear: wttlqty, wttlamt.
  endat.
  at end of ekbe-ebelp.
    uline at /1(130).
  endat.
  at end of ekko-ebeln.
    format color col_positive.
    write:/ '|' ,
            'Total Goods Receipts',
           35 '|' no-gap,
           (15) wgrqty,
           '   |' no-gap,
           (15) wgramt,
           '   |' no-gap,
              130 '|'.
    write:/ '|' ,
            'Total Invoices',
           35 '|' no-gap,
           (15) wirqty,
           '   |' no-gap,
           (15) wiramt,
           '   |' no-gap,
              130 '|'.
    clear: wirqty, wgrqty, wiramt, wgramt.
    uline at /1(130).
  endat.
endloop.

at line-selection.

  if sy-lisel+1(2) = 'GR'.
*if ekbe-bewtp = 'E'.
    set parameter id: 'MBN' field ekbe-belnr,
                      'MJA' field ekbe-gjahr.
    call transaction 'MB03'.
  elseif sy-lisel+1(4) = 'IR-L'.
    set parameter id: 'RBN' field rbkp-belnr,
                      'GJR' field ekbe-gjahr.
    call transaction 'MIR4' and skip first screen.
  elseif sy-lisel+1(2) = 'IR'.
*       ekbe-bewtp = 'R'.
    set parameter id: 'BLN' field ekbe-belnr,
                      'BUK' field '0001',
                      'GJR' field ekbe-gjahr.
    call transaction 'FB03' and skip first screen.
  endif.

*---------------------------------------------------------------------*
*       FORM PO_HEAD                                                  *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
form po_head.
  skip.
  uline at 1(130).
  format color col_key.
  select single * from lfa1 where lifnr = ekko-lifnr.
  write:/ '|', ekko-ebeln, lfa1-name1, '(', ekko-lifnr, ')',
          130 '|'.
  uline at /1(130).
  format color col_heading.
  write:/ '|' no-gap,
          'Cat ' no-gap, '|' no-gap,
          'Doc No    ' no-gap, '|' no-gap,
          'Itm', '|' no-gap,
          'Mvt' no-gap, '|' no-gap,
          'Pstg.dt', '|' no-gap,
          '        Qty in OUn', '|' no-gap,
          'Value in local curr' no-gap, '|' no-gap,
*          'Acc Doc   ', '|' no-gap,
          'Ref No         ', '|' no-gap,
          'Doc Text                ',  '|' no-gap.
  uline at /1(130).
endform.

More Function Module
Functions / SAP Script / ALV

Tables
Database Table

ABAP Books List
ABAP/4 Certification, Programming, Smartforms, Sapscripts and Object Oriented Programming Books

Smart Forms
SAP Smartforms

ABAP Menu:
ABAP Example Hints and Tips

Return to Index:-
SAP ABAP/4 Programming, Basis Administration, Configuration Hints and Tips

(c) www.gotothings.com All material on this site is Copyright.
Every effort is made to ensure the content integrity.  Information used on this site is at your own risk.
All product names are trademarks of their respective companies.  The site www.gotothings.com is in no way affiliated with SAP AG.
Any unauthorised copying or mirroring is prohibited.