cancel
Showing results for 
Search instead for 
Did you mean: 

Performance Issue

Former Member
0 Kudos

<b>Please help me with this program.

It is posing too much database performance issue

please help me to overcome it. It is urgent.</b>

Description:

This program generates a report with the following fields: Sales

ducumnet, Documnet date, Sales item, User status, Sold-to party,

Material, First date, Mat. av. date, NPC confirmation text, Transit

time, Delivery, Shipping point, Purchase order and Not print PO

checkbox.

The user has the possibility to change the item status and first date

for selected sales order items. These updates are made through a

batchinput.

The user may also refresh the report by clicking on the refresh

button. A new selection is made and printed to the screen.

report zsr0037r message-id zs no standard page heading line-size 260.
include: zbnmessr.
tables: vbak, vbep, zs032, zs034, vbpa.
tables: marc.

***CHECKBOX***
data: markfield(1) type c.

***ITEM STATUS***
data: v_status(2)  type c.

***HEADERS POSITION***
data: w_position   type i value 18,
      w_position3  type i value 39,
      w_position2  type i value 30,
      w_position4  type i value 46,
      w_position5  type i value 58,
      w_position14   type i value 80,
      w_position15   type i value 96,
      w_position6  type i value  112,
      w_position7  type i value  128,
      w_position8  type i value 138,
      w_position9  type i value 186,
      w_position10 type i value 195,
      w_position11 type i value 210,
      w_position12 type i value 227,
      w_position16 type i value 239,
      w_position13 type i value 247.

data: v_new_date   like vbep-edatu,
      v_new_status like vbak-lifsk,
      v_ok_code(1) type c.

***COUNTERS***
data: w_i          type i,
      w_ii         type i.

data: job_number like tbtcjob-jobcount,
      job_name   like tbtcjob-jobname value 'ZV_ZS17'.


***INTERNAL TABLE FOR TEMPORARY DATA STORAGE***

types : begin of gts_vbak,
      vbeln   type vbak-vbeln,
      audat   type vbak-audat,
      vkorg   type vbak-vkorg,    "added for authorization D21K918231
      vkgrp   type vbak-vkgrp,    "added for authorization D21K918231
      vkbur   type vbak-vkbur,    "added for authorization D21K918231
      kunnr   type vbak-kunnr,
      end of gts_vbak.
data : gt_vbak type standard table of gts_vbak,
       gs_vbak type gts_vbak.

types : begin of gts_vbpa,
      vbeln type vbpa-vbeln,
      kunnr type vbpa-kunnr,
      end of gts_vbpa.
data : gt_vbpa type standard table of gts_vbpa,
       gs_vbpa type gts_vbpa.

data : tabix type sy-tabix.

types: begin of gts_temp,
      vbeln  type vbap-vbeln,
      posnr  type vbap-posnr,
      matnr  type vbap-matnr,
      uepos  type vbap-uepos,
      werks type vbap-werks,
      vstel  type vbap-vstel,
      route  type vbap-route,
      objnr  type jest-objnr,
      stat   type jest-stat,
      kunnr  type vbak-kunnr,
      audat  type vbak-audat,
      end of gts_temp.
data : gt_temp type standard table of gts_temp,
       gs_temp type gts_temp.
field-symbols : <gfs_temp> type gts_temp.

types: begin of gts_medx,
       vbeln type vbap-vbeln,
       posnr type vbap-posnr,
       end of gts_medx.
data : gt_medx type standard table of gts_medx,
       gs_medx type gts_medx.

types: begin of gts_display,
      objnr  type jest-objnr,
      vbeln  type vbap-vbeln,
      posnr  type vbap-posnr,
      matnr  type vbap-matnr,
      kunnr  type vbak-kunnr,
      audat  type vbak-audat,
      edatu  type vbep-edatu,
      mbdat  type vbep-mbdat,
      wmeng  type vbep-wmeng,
      bmeng  type vbep-bmeng,
      tdline type tline-tdline,
      vstel  type vbap-vstel,
      po_nr  type vbfa-vbeln,
      po_item type vbfa-posnn,
      txt04  type tj30t-txt04,
      traztd type tvro-traztd,
      dil_nr type vbfa-vbeln,
      dil_item type vbfa-posnn,
      mtart  type mara-mtart,
      uepos  type vbap-uepos,
      stat   type jest-stat,
      end of gts_display.
data : gt_display type standard table of gts_display,
       gs_display type gts_display.
field-symbols : <gfs_display> type gts_display.

types: begin of gts_display2,
      objnr  type jest-objnr,
      vbeln  type vbap-vbeln,
      posnr  type vbap-posnr,
      matnr  type vbap-matnr,
      kunnr  type vbak-kunnr,
      audat  type vbak-audat,
      edatu  type vbep-edatu,
      mbdat  type vbep-mbdat,
      tdline type tline-tdline,
      vstel  type vbap-vstel,
      po_nr  type vbfa-vbeln,
      txt04  type tj30t-txt04,
      traztd type tvro-traztd,
      dil_nr type vbfa-vbeln,
      mtart  type mara-mtart,
      uepos  type vbap-uepos,
      stat   type jest-stat,
      end of gts_display2.
data : gt_display2 type standard table of gts_display2,
       gs_display2 type gts_display2.


types:  begin of gts_po,
      vbeln    type vbap-vbeln,
      check(1) type c,
      vstel    type vbap-vstel,
      lgort type zs032-lgort, ">>INS xbmvnag-5018589
      end of gts_po.
data : gt_po type standard table of gts_po,
       gs_po type gts_po.

DATA : BEGIN OF gt_vbep OCCURS 1,
        vbeln like vbep-vbeln ,
        posnr like vbep-posnr,
        edatu like vbep-edatu,
        mbdat like vbep-mbdat ,
        wmeng like  vbep-wmeng ,
        bmeng like  vbep-bmeng ,
      END   OF gt_vbep.

data : gd_int type i, gd_idx type i.
data : gd_posnn type vbfa-posnn.
types : BEGIN OF gts_po1,
        vbelv type vbfa-vbelv ,
        posnv type vbfa-posnv,
        vbeln type vbfa-vbeln,
        posnn type vbfa-posnn,
        ebelp type ekpo-ebelp,
        END OF gts_po1.
data : gt_po1 type standard table of gts_po1,
       gs_po1 type gts_po1.
field-symbols : <gfs_po1> type gts_po1.
Types : BEGIN OF gts_del,
        vbelv type vbfa-vbelv ,
        posnv type vbfa-posnv,
        vbeln type vbfa-vbeln,
        posnn type vbfa-posnn,
       END OF gts_del.
data : gt_del type standard table of gts_del,
       gs_del type gts_del.

 data : gt_temppo  type standard table of gts_po1,
        gs_temppo type gts_po1,
       gt_tempdel type standard table of gts_del,
       gs_tempdel type gts_del.

types : begin of gts_ekpo,
        ebeln type ekpo-ebeln,
        ebelp type ekpo-ebelp,
        loekz type ekpo-loekz,
        end of gts_ekpo.
data : gt_ekpo type standard table of gts_ekpo,
       gs_ekpo type gts_ekpo.
types : begin of gtd_zs032,
        lgort type zs032-lgort,
        resend type zs032-resend,
        end of gtd_zs032.
data : gt_zs032 type standard table of gtd_zs032,
       gs_zs032 type gtd_zs032.
***TABLE FOR TRANSLATING ITEM STATUS***

types : begin of gts_tj30t,
        stsma type tj30t-stsma,
        estat type tj30t-estat,
        txt04 type tj30t-txt04,
        end of gts_tj30t.
data : gt_tj30t type standard table of gts_tj30t,
       gs_tj30t type gts_tj30t.

***NPC CONFIRMATION TEXT***
data: v_lines like tline occurs 0 with header line.

***IMPORT AND EXPORT READ_TEXT***
data: v_id        like  thead-tdid,
      v_language  like  thead-tdspras,
      v_name      like  thead-tdname,
      v_object    like  thead-tdobject,
      v_order(10) type n value 0,
      v_line(6)   type n value 0.

***TRANSLATED ITEM STATUS RANGE***
data: i_status type range of jest-stat with header line.

***CONSTANTS***
data: c_stsma like tj30t-stsma value 'Z0000003',
      c_so(2) type c           value 'C',        "SALES ORDER
      c_po(2) type c           value 'V',        "PURCHASE ORDER
      c_dil(2) type c          value 'J'.        "DELIVERY


*----------------------------------------------------------------------*
*        SELECTION SCREEN                                              *
*----------------------------------------------------------------------*


*** Status ***
select-options s_status for v_status obligatory
                    default 'B1' no-extension .

*** Organizational Data ***
selection-screen skip 1.
selection-screen begin of block b1 with frame title text-s02.

select-options: s_vkorg for  vbak-vkorg obligatory,
                s_vtweg for  vbak-vtweg obligatory,
                s_vkgrp for  vbak-vkgrp obligatory,         "RV032502
                s_vkbur for  vbak-vkbur obligatory.         "RV032502
selection-screen end of block b1.

*** Sales Document Data ***
selection-screen skip 1.
selection-screen begin of block b2 with frame title text-s03.
select-options: s_vbeln for vbak-vbeln,
                s_audat for vbak-audat,
                s_etdat for vbep-edatu,
                s_kunnr for vbak-kunnr,
                s_global for vbpa-kunnr.
selection-screen end of block b2.


*----------------------------------------------------------------------*
*        START OF SELECTION                                            *
*----------------------------------------------------------------------*

start-of-selection.

*** TRANSLATE IEM STATUS B1-B4 INTO THE FORMAT E0001-E0004 ***
  perform f_translate_status.

***  GET DATA FOR DISPLAY  ***
  perform f_get_data.

end-of-selection.

*** ERROR MESSAGE ***
  if gt_display[] is initial.    "No data found for specified selection
    message i002.               "screen criteria
    exit.
  endif.

*** ACTIVATE INTERACTIVE BUTTONS ON APPLICATION TOOLBAR ***
  set pf-status 'UPDT'.


*** WRITE THE REPORT TO THE SCREEN  ***
  perform f_write_report.

*** WRITE STANDAR REPORT HEADERS ***
top-of-page.
  call function 'Z_STD_REPORT_HEADER'
       EXPORTING
            repid = 'ZSR0037R'.
*     TEXT_LINE2       =


  perform f_header.

*** WRITE REPORT HEADERS WHEN REFRESHING SCREEN ***
top-of-page during line-selection.
  call function 'Z_STD_REPORT_HEADER'
       EXPORTING
            repid = 'ZSR0037R'.
*     TEXT_LINE2       =

  perform f_header.

*----------------------------------------------------------------------*
*        AT USER COMMAND                                               *
*----------------------------------------------------------------------*

at user-command.

*** Check for Item Lines selected by the user ***
  if sy-ucomm = 'UPDATE'.
    perform f_read_checkbox.

*** Error Message-No Selected Sales Order Items***
    if w_ii = 0.
      message i056.
      exit.
    endif.

*** ACTIVATE POP-UP SCREEN WHEN USER PRESSES <UPDATE> ***
    perform f_user_dialog.
***USER PRESSES <CONTINUE>***
    if v_ok_code eq 'J'.

*** READ CHECKBOX FOR RESEND PO ***
      perform f_read_checkbox_resend_po.
*** COMPARE WITH DEFAULT VALUE FOR VENDOR ***
*** EXPORTING THE PO MO. TO CUSTOM TABLE  ***
      perform f_compare_default.

***  change database file
      export
          v_new_date
          v_new_status
          gt_medx to database zkpi(zq) id 'Delivery_Upload'.

      call function 'JOB_OPEN'
           EXPORTING
                jobname          = job_name
           IMPORTING
                jobcount         = job_number
           EXCEPTIONS
                cant_create_job  = 1
                invalid_job_data = 2
                jobname_missing  = 3
                others           = 4.
      if sy-subrc ne 0.
        perform write_message using 'ZB'
                                    'E'
                                    '656'
                                    '' '' '' ''.
      endif.

      call function 'JOB_SUBMIT'
           EXPORTING
                authcknam               = sy-uname
                jobcount                = job_number
                jobname                 = job_name
                report                  = 'ZSR0037S'
           EXCEPTIONS
                bad_priparams           = 1
                bad_xpgflags            = 2
                invalid_jobdata         = 3
                jobname_missing         = 4
                job_notex               = 5
                job_submit_failed       = 6
                lock_failed             = 7
                program_missing         = 8
                prog_abap_and_extpg_set = 9
                others                  = 10.
      if sy-subrc ne 0.
        perform write_message using 'ZB'
                                    'E'
                                    '656'
                                    '' '' '' ''.
      endif.

      call function 'JOB_CLOSE'
           EXPORTING
                jobcount             = job_number
                jobname              = job_name
                strtimmed            = 'X'
           EXCEPTIONS
                cant_start_immediate = 1
                invalid_startdate    = 2
                jobname_missing      = 3
                job_close_failed     = 4
                job_nosteps          = 5
                job_notex            = 6
                lock_failed          = 7
                others               = 8.
      if sy-subrc ne 0.
        perform write_message using 'ZB'
                                    'E'
                                    '656'
                                    '' '' '' ''.
      endif.

      perform write_message using 'BT'
                                    'I'
                                    '156'
                                    job_name '' '' ''.
    endif.
  endif.
*** REFRESH THE REPORT WHEN USER PRESSES <REFRESH>
  if sy-ucomm = 'REFRESH'.
    sy-lsind = 0.
    perform f_get_data.
    perform f_write_report.
  endif.

  if sy-ucomm = 'SELE'.
    perform select_all.
  endif.

  if sy-ucomm = 'DESE'.
    perform delselect_all.
  endif.

*----------------------------------------------------------------------*
*       FORMS                                                          *
*----------------------------------------------------------------------*

***  GET ITEM NPC CONFIRMATION TEXT  ***********************************
form f_get_item_text.

  v_id = 'Z103'.
  v_language = sy-langu.
  v_order = gs_temp-vbeln.
  v_line = gs_temp-posnr.
  concatenate v_order v_line into v_name.
  v_object = 'VBBP'.

  clear    v_lines.
  refresh  v_lines.

  call function 'READ_TEXT'
    exporting
      client                        = sy-mandt
      id                            = v_id
      language                      = v_language
      name                          = v_name
      object                        = v_object
*     ARCHIVE_HANDLE                = 0
*     LOCAL_CAT                     = ' '
*   IMPORTING
*     HEADER                        =
    tables
      lines                         =  v_lines
  exceptions
     id                            = 0
     language                      = 0
     name                          = 0
     not_found                     = 0
     object                        = 0
     reference_check               = 0
     wrong_access_to_archive       = 0
     others                        = 0.

  if sy-subrc <> 0.
  endif.
endform.

*** WRITE REPORT *******************************************************
form f_write_report.

  data: w_i type i value 0.
  format color col_normal.
  w_i = 0.
  loop at gt_display into gs_display.
    if w_i = 0.
      format intensified on.
      w_i = 1.
    else.
      format intensified off.
      w_i = 0.
    endif.

*** CHECK FOR PIPECHAIN VENDOR ***
    select single resend from  zs032
                         into  zs032-pipec
                         where lgort = gs_display-vstel.


    markfield = ' '.
    write:  / ' ', markfield as checkbox, ' ',
       5 '|',

**requested quantity,confirmed quantity,schedule line date,
*purchase order item are added in the output display.
          gs_display-vbeln,
       at  18  gs_display-audat, ' ',
       at  30  gs_display-posnr no-zero, ' ',
       at  39  gs_display-txt04, '  ',
       at  46  gs_display-vstel, ' ',
       at  55  gs_display-matnr, ' ',
       at  73  gs_display-wmeng, ' ',
       at  88  gs_display-bmeng, ' ',
       at  114 gs_display-edatu, ' ',
       at  128 gs_display-mbdat, ' ',
       at  142 gs_display-tdline(50),
       at  182 gs_display-traztd,'  ',
       at  197 gs_display-dil_nr,'  ',
       at  210  gs_display-kunnr, ' ',
       at  229 gs_display-po_nr, '  ',
       at  240 gs_display-po_item,'  '.


*** DEFAULT CHECKBOX IF PIPECHAIN VENDOR***
    if zs032-pipec = 'X' and sy-subrc = 0.
      markfield = 'X'.
    else.
      markfield = ' '.
    endif.
    write: markfield as checkbox, '      '.

  endloop.
  write / 'END OF REPORT'.

endform.

****  SELECTION OF DATA FOR DISPLAY ************************************
form f_get_data.
Clear gs_po1.
refresh gt_po1.
Clear gs_del.
Refresh gt_del.

  clear   gs_vbak.
  refresh gt_vbak.
  clear   gs_temp.
  refresh gt_temp.
  clear   gs_display.
  refresh gt_display.

*** SELECT SO#, SOLD-TO PARTY, DOCUMENT DATE ***
  select vbeln audat vkorg vkgrp vkbur kunnr
                           from vbak
                           into table gt_vbak
                           where vbeln  in s_vbeln and
                                 audat  in s_audat and
                                 vkorg  in s_vkorg and
                                 vtweg  in s_vtweg and
                                 vkgrp  in s_vkgrp and      
                                 vkbur  in s_vkbur and      
                                 kunnr  in s_kunnr.

    if not gt_vbak[] is initial.
      select vbeln kunnr into table gt_vbpa
                    from vbpa
                    for all entries in gt_vbak
                    where vbeln = gt_vbak-vbeln
                    and posnr = '000000'
                    and parvw = 'ZC'.
    endif.
    sort gt_vbpa by vbeln.


    loop at gt_vbak into gs_vbak.
      tabix = sy-tabix.

      read table gt_vbpa into gs_vbpa with key vbeln = gs_vbak-vbeln
                                           binary search.
      if sy-subrc = 0.
        if not gs_vbpa-kunnr in s_global.
          delete gt_vbak  index tabix.
        endif.
      endif.
    ENDLOOP.

if not  gt_vbak[] is initial.
* Start of changes xbmvnag-5018589
 select a~vbeln
        a~posnr
        a~matnr
        a~uepos
        a~werks
        a~vstel
        a~route
        a~objnr
        b~stat
   from vbap as A inner join
        jest as B ON
        a~objnr eq b~objnr
   into corresponding fields of table gt_temp
   for all entries in gt_vbak
   where a~vbeln eq gt_vbak-vbeln
    and  b~stat in i_status
    and b~inact eq ' '.   ">>INS xbmvnag-5018589
endif.

clear: gs_temp,gs_vbak,tabix.
    loop at gt_vbak into gs_vbak.
      loop at gt_temp assigning <gfs_temp>
                    where vbeln = gs_vbak-vbeln.
        tabix = sy-tabix.
        move gs_vbak-vbeln to <gfs_temp>-vbeln.
        move gs_vbak-audat to <gfs_temp>-audat.
        move gs_vbak-kunnr to <gfs_temp>-kunnr.
      endloop.
      clear gs_vbak.
    endloop.

IF not gt_temp[] is initial.
      select  vbeln
              posnr
              edatu
              mbdat
              wmeng
              bmeng
         from vbep
              appending corresponding fields of table gt_display
              for all entries in gt_temp
         where vbeln eq gt_temp-vbeln and
               posnr eq gt_temp-posnr and
               edatu in s_etdat .
endif.


if not gt_display[] is initial.
      select vbelv
             posnv
             vbeln
             posnn
        from vbfa
        into corresponding fields of table gt_po1
        for all entries in gt_display
       where vbelv   eq gt_display-vbeln and
             posnv   eq gt_display-posnr and
             vbtyp_v eq c_so   and    "SALES ORDER
             vbtyp_n eq c_po.         "PURCHASE ORDER

endif.

loop at gt_po1 assigning <gfs_po1>.
clear gd_int.
gd_posnn = <gfs_po1>-posnn.
shift gd_posnn left deleting leading '0'.
gd_int = gd_posnn.
<gfs_po1>-ebelp = gd_int.
endloop.
select ebeln ebelp loekz from ekpo
             into table gt_ekpo
             for all entries in gt_po1
             where ebeln eq gt_po1-vbeln
             and   ebelp eq gt_po1-ebelp.
sort gt_ekpo by ebeln ebelp.
Loop at gt_po1 into gs_po1.
read table gt_ekpo into gs_ekpo
                   with key ebeln = gs_po1-vbeln
                            ebelp = gs_po1-ebelp
                            binary search.
if sy-subrc eq 0 and gs_ekpo-loekz eq 'L'.

       Delete gt_po1 index sy-tabix.
endif.
 clear gs_ekpo. ">>INS xbmvnag-5018589
Endloop.


if not  gt_po1[] is initial.

      select vbelv
             posnv
             vbeln
             posnn
        from vbfa
                   appending corresponding fields of table gt_del
                   for all entries in gt_po1
        where vbelv   eq gt_po1-vbelv and
              posnv   eq gt_po1-posnv and
              vbtyp_v eq c_so   and   "SALES ORDER
              vbtyp_n eq c_dil.       "DELIVERY
endif.



*** DELETE ITEMS THAT ARE NOT SPP, AGO OR STANDALONE SM ***
  gt_display2[] = gt_display[].

 sort gt_display by vbeln posnr edatu."ins line edtanan3900737

  append lines of gt_po1 to gt_temppo.
  append lines of gt_del to gt_tempdel.
sort gt_po1 by vbelv posnv.
sort gt_temppo by vbelv posnv.
sort gt_del by vbelv posnv.
sort gt_tempdel by vbelv posnv.
sort gt_display2 by uepos vbeln.
sort gt_temp by vbeln posnr.
sort gt_tj30t by stsma estat.
loop at gt_display assigning <gfs_display>.

    If <gfs_display>-bmeng NE 0 .

      clear gs_po1. ">>INS xbmvnag-5018589
      Read table gt_po1 into gs_po1
                        with key vbelv = <gfs_display>-vbeln
                                 posnv = <gfs_display>-posnr
                        binary search. ">>INS xbmvnag-5018589
      if sy-subrc EQ 0.
        move : gs_po1-vbeln to <gfs_display>-po_nr,
               gs_po1-posnn to <gfs_display>-po_item.
      endif.
      if <gfs_display>-po_nr is initial.
        clear gs_temppo. ">>xbmvnag-5018589
        read table gt_temppo into gs_temppo
                             with key vbelv = <gfs_display>-vbeln
                                      posnv =  <gfs_display>-posnr
                             binary search. ">>INS xbmvnag-5018589
        if sy-subrc = 0.
          move : gs_temppo-vbeln to <gfs_display>-po_nr,
                 gs_temppo-posnn to <gfs_display>-po_item.
        endif.
      endif.

*to pass the values of delivery number
      clear gs_del. ">>INS xbmvnag-5018589
      Read table gt_del into gs_del
                        with key vbelv = <gfs_display>-vbeln
                                 posnv = <gfs_display>-posnr
                         binary search. ">>INS xbmvnag-5018589

      if sy-subrc EQ 0 .
        move : gs_del-vbeln to <gfs_display>-dil_nr,
               gs_del-posnn to <gfs_display>-dil_item.
      endif.
      if <gfs_display>-dil_nr is initial.
        clear gs_tempdel. ">>INS xbmvnag-5018589
        read table gt_tempdel into gs_tempdel
                              with key vbeln = gt_vbep-vbeln
                                       posnv =  gt_vbep-posnr
                           binary search. ">>INS xbmvnag-5018589

        if sy-subrc = 0.
          move : gs_del-vbeln to <gfs_display>-dil_nr,
                 gs_del-posnn to <gfs_display>-dil_item.
        endif.
      endif.

      if <gfs_display>-po_nr is initial.
        clear gs_display2. ">>INS xbmvnag-5018589
        read table gt_display2 into gs_display2
                              with key uepos = <gfs_display>-posnr
                                       vbeln = <gfs_display>-vbeln
                              binary search. ">>INS xbmvnag-5018589
        if sy-subrc = 0.
        move gs_display2-po_nr to  <gfs_display>-po_nr.
      endif.
    endif.
 ENDIF.
      clear gs_temp. 
      read table gt_temp into gs_temp
                        with key vbeln = <gfs_display>-vbeln
                                 posnr = <gfs_display>-posnr
                        binary search. 
      if sy-subrc EQ 0.
        <gfs_display>-matnr = gs_temp-matnr .
        <gfs_display>-stat  = gs_temp-stat .
        <gfs_display>-vstel = gs_temp-vstel.
        <gfs_display>-kunnr = gs_temp-kunnr .
        <gfs_display>-audat = gs_temp-audat.
        select single traztd from  tvro
                                into  <gfs_display>-traztd
                                where route eq gs_temp-route.
        select single mtart from  mara
                              into  <gfs_display>-mtart
                              where matnr eq gs_temp-matnr.

      endif.

      call function 'Z_CHECK_PLANT_MATERIAL_TYPE'
           EXPORTING
                matnr                  = gs_temp-matnr	
                werks                  = gs_temp-werks
           IMPORTING
                umrsl                  = marc-umrsl
           EXCEPTIONS
                no_material_type_found = 1
                no_entry_found_in_marc = 2
                others                 = 3.

      if sy-subrc = 0.
        <gfs_display>-mtart = marc-umrsl.
      endif.

*** TRANSLATE STATUS E001->B1...  ****
      clear gs_tj30t.   ">>INS xbmvnag-5018589
      read table gt_tj30t into gs_tj30t
                         with key stsma = c_stsma
                                  estat = gs_temp-stat
                         binary search. ">>INS xbmvnag-5018589
      if sy-subrc eq 0.
        <gfs_display>-txt04  =  gs_tj30t-txt04.
      endif.

*     Get the NPC confirmation text from the SO item.
      perform f_get_item_text.
      IF v_lines[] IS INITIAL OR
         <gfs_display>-po_nr IS INITIAL.

      ELSE.
        READ TABLE v_lines WITH KEY
                           tdline(10) = <gfs_display>-po_nr.
        IF sy-subrc = 0.
          MOVE-CORRESPONDING v_lines TO <gfs_display>.
        ENDIF.
      ENDIF.
     clear gs_po1.
      clear gs_del.
      delete gt_po1 where vbeln = <gfs_display>-po_nr
                      and posnn = <gfs_display>-po_item.
       delete gt_del where vbeln = <gfs_display>-dil_nr
                      and posnn = <gfs_display>-dil_item.
      clear gs_temp .
  endloop.


endform.

****  USER DIALOGBOX  **************************************************
form f_user_dialog.
  call function 'ZPOPUP_TO_FETCH_TWO_VALUES'
       EXPORTING
            textline1      = text-025
            textline2      = text-026
            textline3      = text-027  "
       IMPORTING
            answer         = v_ok_code
            value1         = v_new_date  "
            value2         = v_new_status
       EXCEPTIONS
            titel_too_long = 0
            others         = 0.

  if sy-subrc <> 0.
  endif.

endform.

*** WRITE HEADERS  *****************************************************
form f_header.
  format color col_heading.
  skip.
  write: / ' ', text-001,
           at w_position text-004,
           at w_position2 text-002,
           at w_position3 text-003,
          at w_position4 text-018,
          at w_position14 text-030,
           at w_position15 text-031,
           at w_position6  text-033,
           at w_position7 text-012,
           at w_position8 text-005,
           at w_position9 text-016,
            at w_position11 text-009,
           at w_position12 text-020,
           at w_position16 text-034,
           at w_position13 text-022.

  write: / ' ', text-006,
           at w_position text-013,
           at w_position2 text-007,
           at w_position3 text-008,
            at w_position4 text-019,
           at w_position5 text-010,
           at w_position14 text-032,
           at w_position15 text-032,
           at w_position6 text-011,
           at w_position7 text-013,
           at w_position8 text-014,
           at w_position9 text-017,
           at w_position10 text-024,
           at w_position11 text-015,
           at w_position12 text-021,
           at w_position16 text-035,
           at w_position13 text-023.
  format color off.
  uline.
endform.

***  MOVE SELECTED SALES ORDER # AND ITEM # TO I_MEDX ******************
form f_read_checkbox.
  w_i = 4.                     " First line of data in the report.
  w_ii = 0.
  refresh gt_medx.
  clear gs_medx.

  do.
    read line w_i.
    if sy-subrc ne 0.
      exit.
    endif.
    w_i = w_i + 1.

* Move user-selected (VBELN) and (posnr) to internal table I_MEDX *
    if sy-lisel+2(1) = 'X'.
      move sy-lisel+6(10) to gs_medx-vbeln.
      move sy-lisel+30(6) to gs_medx-posnr.
      append gs_medx to gt_medx.
      clear  gs_medx.
      w_ii = w_ii + 1.
    endif.

  enddo.
endform.

*** TRANFER ALL UPDATED POs THAT HAVE THE RESEND CHECKBOX CHECKED ***
form f_read_checkbox_resend_po.
  w_i = 4.                     " First line of data in the report.
  w_ii = 0.

  do.
    read line w_i.
    if sy-subrc ne 0.
      exit.
    endif.
    w_i = w_i + 1.

* Move user-selected "Resend PO" to databese table I_MEDX *
    if sy-lisel+168(1) = 'X' and not sy-lisel+155(10) is initial.
      move sy-lisel+168(1)  to gs_po-check.
      move sy-lisel+154(10) to gs_po-vbeln.
      move sy-lisel+146(4)  to gs_po-vstel.
      append gs_po to gt_po.
      clear  gs_po.
      w_ii = w_ii + 1.
    endif.

  enddo.
endform.

*** CHECK FOR CHANGED "RESEND PO" **************************************
form f_compare_default.

select lgort resend from zs032
              into table gt_zs032
              for all entries in gt_po
              where lgort = gt_po-vstel.
gd_idx = 1.
  loop at gt_po into gs_po.

*** COMPARE WITH DEFAULT VALUE FOR "RESEND PO" ***

read table gt_zs032 into gs_zs032 index gd_idx.
IF sy-subrc <> 0. EXIT. ENDIF.
if gs_zs032-lgort = gs_po-vstel.

     if gs_zs032-resend eq gs_po-check.
    else.
*** UPDATE CUSTOM TABLE WITH PO NO. ***
      move gs_po-vbeln to zs034-vbeln.
      insert zs034.
      commit work.
    endif.
   add 1 to gd_idx.
endif.
  endloop.
  clear   gs_po.
  refresh gt_po.
endform.


***** TRANSLATE STATUS *************************************************
form f_translate_status.

***  SELECT TJ30T INTO INTERNAL TABLE ***
  select stsma estat txt04 from tj30t into table gt_tj30t
                      where spras eq sy-langu
                      and stsma = 'Z0000003'.">>INS xbmvnag-5018589
 sort gt_tj30t by stsma estat txt04.
***  TRANSLATE ITEM STATUS, B1->E001... ***
  loop at s_status.
    clear gs_tj30t.
    read table gt_tj30t into gs_tj30t with key
              txt04 = s_status-low
                     binary search. 
    if sy-subrc = 0.
      move gs_tj30t-estat   to i_status-low.
      move s_status-sign   to i_status-sign.
      move s_status-option to i_status-option.
    endif.
   clear gs_tj30t.
   read table gt_tj30t into gs_tj30t with key
                     txt04 = s_status-high
                     binary search. 
    if sy-subrc = 0.
      move gs_tj30t-estat to i_status-high.
    endif.
    if i_status-sign ne space and i_status-option ne space. "PV060302
      append i_status.
    endif.                                                  "PV060302
  endloop.
endform.
*&---------------------------------------------------------------------*
*&      Form  DELSELECT_ALL
*&---------------------------------------------------------------------*
form delselect_all.
  do.
    read line sy-index.
    if sy-subrc ne 0.
      exit.
    endif.
    if sy-lisel+4(1) = '|'.
      sy-lisel+2(1) = ' '.
      modify line sy-index.
    endif.
  enddo.
  clear sy-ucomm.

endform.                    " DELSELECT_ALL

*&---------------------------------------------------------------------*
*&      Form  SELECT_ALL
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form select_all.
  do.
    read line sy-index.
    if sy-subrc ne 0.
      exit.
    endif.
    if sy-lisel+4(1) = '|'.
      sy-lisel+2(1) = 'X'.
      modify line sy-index.
    endif.
  enddo.
  clear sy-ucomm.

Accepted Solutions (1)

Accepted Solutions (1)

rmazzali
Active Contributor
0 Kudos

Create Indexes on the DB tables according to your select statements.

Also try to change VBAK/VBAP nested selctions with table VAPMA that contains a mix of header/item data.

pls. reward if helpful

Roberto

Former Member
0 Kudos

hi robert,

thanks for ur suggestion.

here in this select statment:

select vbeln audat vkorg vkgrp vkbur kunnr
                          from vbak
                          into table gt_vbak
                          where vbeln  in s_vbeln
                                audat  in s_audat
                                vkorg  in s_vkorg
                                vtweg  in s_vtweg
                                vkgrp  in s_vkgrp
                                vkbur  in s_vkbur
                                kunnr  in s_kunnr.

the system is pulling loads of records and so by doing for all entries it is making the system slow. Could u tell me is there any alternate for this?

rmazzali
Active Contributor
0 Kudos

the only way in to create an index on vbak for fields:

vbeln audat vkorg vtweg vkgrp vkbur kunnr

Roberto

Answers (0)