Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Can anyone give me a sample around using "REUSE_ALV_HIERSEQ_LIST_DISPLAY"

Former Member
0 Kudos

I learned the program BALVHD01_GROUP but I alway got error

Runtime Errors ITAB_ILLEGAL_COMPONENT

000690

000700 IF SY-SUBRC NE 0.

000710 RAISE SORTFIELD_NOT_FOUND.

000720 ENDIF.

000730 IF RFLG_AS_TEXT IS INITIAL AND RFLG_STABLE = 'X'.

> SORT RT_OUTTAB STABLE

000750 BY (A01) ASCENDING

please help me~ thanks

6 REPLIES 6

former_member188685
Active Contributor
0 Kudos
report ZTEST message-id id.

*---------------------------------------------------------------------*
*          Type pools
*---------------------------------------------------------------------*
type-pools : slis.
*---------------------------------------------------------------------*
*          Tables
*---------------------------------------------------------------------*
tables: t616u ,
        vbpa  ,
        vbap  ,
        vbak  ,
        mara  ,
        t005t ,
        t604t .
*---------------------------------------------------------------------*
*          Internal Tables
*---------------------------------------------------------------------*
* To store first line contents of report
data : begin of it_output occurs 0,
         vbeln      like vbap-vbeln,           " Sales order number
         posnr      like vbap-posnr,           " Sales order line
         matnr      like vbap-matnr,           " Material Number
         arktx      like vbap-arktx,           " Description of material
         herkl      like vbap-zzherkl,         " Country of origin
         landx      like t005t-landx,          " Country Description
         stawn      like vbap-zzstawn,         " HTS Commodity code
         text1      like t604t-text1,          " HTS Description
         check,                                " Check box for selection
         line_color(4),                        " Line color
         vbpos(17),                            " Key for Hier List
       end of it_output.
* To store second line contents of report
data: begin of it_output2 occurs 0,
         herkl      like vbap-zzherkl,         " Country of origin
         stawn      like vbap-zzstawn,         " HTS Commodity code
         vbpos(17),                            " Key for Hier List
      end of it_output2.
* Internal table to store details of sales order
data : begin of it_material occurs 0,
         vbeln      like vbap-vbeln,           " Sales order number
         posnr      like vbap-posnr,           " Sales order line
         matnr      like vbap-matnr,           " Material Number
         werks      like vbap-werks,           " Plant
         arktx      like vbap-arktx,           " Description of material
         herkl      like vbap-zzherkl,         " Country of origin
         stawn      like vbap-zzstawn,         " HTS Commodity code
       end of it_material.
* Internal table to store error messages
data : begin of it_errmsgs occurs 0,
         vbeln       like vbap-vbeln,           " Sales order number
         posnr       like vbap-posnr,           " Sales order line
         message(100) type c,                   " Error Message
       end of it_errmsgs.

* WORKING STORAGE FOR BAPI INTERFACE
data: begin of it_bapiparex occurs 0.
        include structure bapiparex.                        "1710
data: end of it_bapiparex.

data: begin of it_bape.
data: structure like bapiparex-structure.                   "len 30
        include structure bape_vbap.                        "len 261
data:       filler(1419) type c.                            "len 1419
data: end of it_bape.

data: begin of it_bapex.
data: structure like bapiparex-structure.                   "len 30
        include structure bape_vbapx.                       "len 22
data:       filler(1658) type c.
data: end of it_bapex.

*Internal Tables to capture BapirETURN messages
data: it_bapireturn1 like bapiret2 occurs 0 with header line,
      it_bapireturn2 like bapiret2 occurs 0 with header line.

data: x_orderitemx like bapisdh1x.
data: v_export type c.
data: begin of itmupd occurs 0.
        include structure bapisditmx.
data: end of itmupd.
data: begin of itmfld occurs 0.
        include structure bapisditm.
data: end of itmfld.
* Internal table for field catalog
data : it_fieldcat type slis_t_fieldcat_alv with header line,
* Internal table for Events
       it_events   type slis_t_event with header line.
*---------------------------------------------------------------------*
*         Global Variables
*---------------------------------------------------------------------*
data:    v_tabix         like  sy-tabix,          " Line index
         v_repid         like  sy-repid,          " Program name
         x_layout        type  slis_layout_alv,   " Output layout
         v_herkl(6),
         v_stawn(34).
*---------------------------------------------------------------------*
*          Selection Screen
*---------------------------------------------------------------------*
selection-screen : begin of block blk1
                       with frame title text-001. " Geography-Receipt
select-options :
* Country
 s_land1 for  vbpa-land1,
* Ship-to-Party
 s_kunnr for  vbpa-kunnr.

selection-screen  : end of block blk1.


selection-screen  : begin of block blk2
                        with frame title text-002 . " Geography-Export
select-options :
* Sales Organization
 s_vkorg    for vbak-vkorg,
* Shipping Point / Receiving Point
 s_vstel    for vbap-vstel,
* Plant
 s_werks    for vbap-werks.

selection-screen  : end of block blk2.


selection-screen  : begin of block blk3
                        with frame title text-003." Further Doc.Data
select-options :
* Created on
s_erdat    for vbak-erdat.


selection-screen :begin of line.
*-Sales document Radiobutton - Select-Option
parameters : r_select  radiobutton group grp1 .
selection-screen comment 4(25) text-015 for field r_select.
*-Select Option for Sales Order
select-options : s_vbeln  for vbap-vbeln.
selection-screen :end of line.

selection-screen :begin of line.
*-Sales document Radiobutton - Parameter
parameters : r_parmtr  radiobutton group grp1 .
selection-screen comment 4(28) text-015 for field r_parmtr.
parameters: p_vbeln like vbak-vbeln.
selection-screen :end of line.

selection-screen :begin of line.
*-Item
selection-screen comment 3(26) text-016 for field s_posnr.
select-options: s_posnr for vbap-posnr.
selection-screen :end of line.


select-options :
* Created By
s_ernam    for vbak-ernam,
* Sales Order Type
s_auart    for vbak-auart,
* Material
s_matnr    for vbap-matnr,
* Material Group
s_matkl    for vbap-matkl.

selection-screen  : end of block blk3.


selection-screen begin of block blk4 with frame .
*To Display error record only
parameters p_errors as checkbox .

selection-screen end of block blk4.
*---------------------------------------------------------------------*
*          Start of Selection
*---------------------------------------------------------------------*
start-of-selection.
* Selecting data depending on selection criteria
  perform select_data.

*---------------------------------------------------------------------*
*          End of Selection
*---------------------------------------------------------------------*
end-of-selection.
*Display report output
  perform display_output.

*&---------------------------------------------------------------------*
*&      Form  SELECT_DATA
*&---------------------------------------------------------------------*
*        Select data based on selection criteria
*----------------------------------------------------------------------*
form select_data.
*Refresh & clear internal tables before populating data
  refresh : it_output ,
            it_output2,
            it_material.
  clear   : it_output,
            it_material,
            it_output2.
*Fetching data from VBAP
*-Sales Order - Select-Option
  if r_select = 'X'.            
    select vbap~vbeln
           vbap~posnr
           vbap~matnr
           vbap~werks
           vbap~arktx
           vbap~zzherkl
           vbap~zzstawn into table it_material
           from vbap
           inner join vbak
           on vbap~vbeln = vbak~vbeln
           where vbak~vkorg in s_vkorg
           and   vbap~vstel in s_vstel
           and   vbap~werks in s_werks
           and   vbak~erdat in s_erdat
           and   vbak~vbeln in s_vbeln
           and   vbak~ernam in s_ernam
           and   vbak~auart in s_auart
           and   vbap~matnr in s_matnr
           and   vbap~matkl in s_matkl.
*-Sales Order - Parameter & Item - Select-Option
  elseif r_parmtr = 'X'.           
    select vbap~vbeln
           vbap~posnr
           vbap~matnr
           vbap~werks
           vbap~arktx
           vbap~zzherkl
           vbap~zzstawn into table it_material
           from vbap
           inner join vbak
           on vbap~vbeln = vbak~vbeln
           where vbak~vkorg in s_vkorg
           and   vbap~vstel in s_vstel
           and   vbap~werks in s_werks
           and   vbak~erdat in s_erdat
           and   vbak~vbeln  = p_vbeln
           and   vbak~ernam in s_ernam
           and   vbak~auart in s_auart
           and   vbap~posnr in s_posnr
           and   vbap~matnr in s_matnr
           and   vbap~matkl in s_matkl.
  endif.          
* If sy-subrc is not equal to zero exit
  if sy-subrc <> 0 .
    exit.
  endif.
* Else Excluding records
  loop at it_material.
    v_tabix = sy-tabix.
    select single kunnr
                from vbpa
                into vbpa-vbeln
                where vbeln = it_material-vbeln  and
                      posnr = it_material-posnr  and
                      parvw = 'WE'               and
                      kunnr in s_kunnr           and
                      land1 in s_land1.
    if sy-subrc <> 0.
      select single kunnr
                  from vbpa
                  into vbpa-vbeln
                  where vbeln = it_material-vbeln    and
                        posnr = '000000'             and
                        parvw = 'WE'                 and
                        kunnr in s_kunnr             and
                        land1 in s_land1.
      if sy-subrc <> 0.
        delete it_material index v_tabix.
        continue.
      endif.
    endif.
* Delete recods that are not export relevant.
    call function 'Z_DETER_EXPORT_REL'
         exporting
              salesorder = it_material-vbeln
              lineitem   = it_material-posnr
         importing
              flag       = v_export.
    if v_export = ' '.
      delete it_material index v_tabix.
      continue.
    endif.
* Populating IT_OUTPUT from IT_MATERIAL.
    move-corresponding it_material to it_output.

*Populating SecondLine In the Output
    select single herkl
                  stawn
                  from marc
                  into (it_output2-herkl,
                       it_output2-stawn)
                  where matnr = it_material-matnr and
                        werks = it_material-werks .
    if sy-subrc  = 0.
      shift it_material-vbeln left deleting leading '0'.
      concatenate it_material-vbeln
                  it_material-posnr
             into it_output2-vbpos
             separated by '/'.
      append it_output2.
    endif.
* If Errors Only Check Box is checked.
    if p_errors = 'X'.
      clear : v_herkl, v_stawn.
      concatenate : it_output2-herkl it_material-herkl into v_herkl,
                    it_output2-stawn it_material-stawn into v_stawn.
      condense : v_herkl, v_stawn.
      if v_herkl is initial or v_stawn is initial.  
      else.
        delete it_material index v_tabix.
        continue.
      endif.
    endif.
* Country Description
    select single landx
                  from t005t
                  into it_output-landx
                  where spras = 'EN'  and
                  land1 = it_material-herkl.
* HTS Description
    select single text1
                  from t604t
                  into it_output-text1
                  where spras = 'EN'  and
                  land1 = it_material-herkl and
                  stawn = it_material-stawn.
*VBELN/POSNR
    shift it_material-vbeln left deleting leading '0'.
    concatenate it_material-vbeln
                it_material-posnr
           into it_output-vbpos
           separated by '/'.
    append it_output.
    clear it_output.
  endloop.
endform.                    " SELECT_DATA
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_OUTPUT
*&---------------------------------------------------------------------*
*        Display Report
*----------------------------------------------------------------------*
form display_output.

  data : l_pf_formname   type slis_formname value 'PF_STATUS',
         l_user_formname type slis_formname value 'USER_COMMAND',
         keyinfo type slis_keyinfo_alv.

  v_repid = sy-repid.
* populate fieldcatalog
  perform build_fieldcatalog.
* Populate events internal table
  perform build_events.
* Layout initialization.
  perform layout using x_layout.
  x_layout-info_fieldname    = 'LINE_COLOR'.
* Specifying KeyFields for List.
  keyinfo-header01 = 'VBPOS'.
  keyinfo-item01   = 'VBPOS'.
  call function 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
       exporting
            i_callback_program       = v_repid
            i_callback_pf_status_set = l_pf_formname
            i_callback_user_command  = l_user_formname
            is_layout                = x_layout
            it_fieldcat              = it_fieldcat[]
            it_events                = it_events[]
            i_tabname_header         = 'IT_OUTPUT'
            i_tabname_item           = 'IT_OUTPUT2'
            is_keyinfo               = keyinfo
       tables
            t_outtab_header          = it_output
            t_outtab_item            = it_output2
       exceptions
            program_error            = 1
            others                   = 2.
endform.                    " DISPLAY_OUTPUT
*&---------------------------------------------------------------------*
*&      Form  TOP-OF-LIST
*&---------------------------------------------------------------------*
*        For Top of list
*----------------------------------------------------------------------*
form top-of-list.
* Display Steelcase header
  call function 'Z_HEADER'.
endform.                    " TOP-OF-LIST


*---------------------------------------------------------------------*
*       FORM LAYOUT                                                   *
*---------------------------------------------------------------------*
form layout using l_layout type slis_layout_alv.
  l_layout-box_fieldname      = 'CHECK'.
  l_layout-box_tabname        = 'IT_OUTPUT'.
  l_layout-colwidth_optimize  = 'X'.
endform.
*---------------------------------------------------------------------*
*&      Form  USER_COMMAND
*&---------------------------------------------------------------------*
*      Processing User command
*----------------------------------------------------------------------*
*      -->P_UCOMM     Screens, function code triggered by PAI
*      -->P_SELFIELD  information cursor position ALV
*----------------------------------------------------------------------*
form user_command using    p_ucomm    like sy-ucomm
                            p_selfield type slis_selfield.

  data : l_index like sy-tabix.
  l_index = p_selfield-tabindex.
  case p_ucomm.
    when 'SAVE'.
      perform validate_input.
      perform save_sales_docu.
      p_selfield-refresh = 'X'.
*Display Messages
      if it_errmsgs[] is initial.
        message s899 with 'Record(s) Successfully Updated'.
      else.
        perform display_errors.
      endif.
    when '&IC1'.
* On Double click display the sales order.
      read table it_output index l_index.
      set parameter  id 'AUN' field it_output-vbeln.
      call transaction 'VA03' and skip first screen.
  endcase.
endform.                    " USER_COMMAND
*---------------------------------------------------------------------*
*       FORM pf_status                                                *
*---------------------------------------------------------------------*
*       Set pf status
*----------------------------------------------------------------------*
*  -->  p_extab    excluding Fcode table
*---------------------------------------------------------------------*
form pf_status using    p_extab type slis_t_extab.
  data : l_extab type slis_extab.
  set pf-status 'STANDARD' excluding p_extab.
endform.                    " PF_STATUS_SET

*&---------------------------------------------------------------------*
*&      Form  SAVE_SALES_DOCU
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
form save_sales_docu.
  data v_tabix like sy-tabix.
  refresh   it_errmsgs.
  clear     it_errmsgs.
*Setting the flag field as update
  x_orderitemx-updateflag = 'U'.
  loop at it_output.
    v_tabix = sy-tabix.
    refresh : it_bapireturn1,
              it_bapireturn2,
              it_bapiparex,
              itmfld,
              itmupd.
    clear   : it_bapireturn1,
              it_bapireturn2,
              it_bapiparex,
              itmfld,
              itmupd,
              it_bape,
              it_bapex.
    if it_output-check = ' '.
      continue.
    endif.
* if the sales order is checked populate IT_BAPIREX.
    it_bape-structure = 'BAPE_VBAP'.
    it_bape-vbeln     = it_output-vbeln.
    it_bape-posnr     = it_output-posnr.
    it_bape-zzherkl   = it_output-herkl.
    it_bape-zzstawn   = it_output-stawn.
    append it_bape to it_bapiparex.

    it_bapex-structure = 'BAPE_VBAPX'.
    it_bapex-vbeln     = it_output-vbeln.
    it_bapex-posnr     = it_output-posnr.
    it_bapex-zzherkl   = 'X'.
    it_bapex-zzstawn   = 'X'.
    append it_bapex to it_bapiparex.

    itmfld-itm_number = it_output-posnr.
    append itmfld.
    itmupd-itm_number = it_output-posnr.
    itmupd-updateflag = 'U'.
    append itmupd.

    call function 'BAPI_SALESORDER_CHANGE'
         exporting
              salesdocument    = it_output-vbeln
              order_header_inx = x_orderitemx
         tables
              return           = it_bapireturn1
              order_item_in    = itmfld
              order_item_inx   = itmupd
              extensionin      = it_bapiparex.
*Store the error messages in internal table
    loop at it_bapireturn1 where type = 'E'.
      it_errmsgs-vbeln = it_output-vbeln.
      it_errmsgs-posnr = it_output-posnr.
      it_errmsgs-message = it_bapireturn1-message.
      append it_errmsgs.
      clear it_errmsgs.
      it_output-line_color = 'C600'.
    endloop.
*Commit the bapi transaction if no error messages are there.
    if sy-subrc <> 0.
      refresh it_bapireturn2.
      clear it_bapireturn2.
      call function 'BAPI_TRANSACTION_COMMIT'
           exporting
                wait   = 'X'
           importing
                return = it_bapireturn2.
*If commit is not succesful capture the error messages.
      if  not it_bapireturn2 is  initial.
        it_errmsgs-vbeln = it_output-vbeln.
        it_errmsgs-posnr = it_output-posnr.
        it_errmsgs-message = it_bapireturn2-message.
        append it_errmsgs.
        clear it_errmsgs.
        it_output-line_color = 'C600'.
      else.
*If salesOrder is updated refresh the data from the database.
        it_output-line_color = ' '.
        select single zzherkl
                      zzstawn
              from vbap
              into (it_output-herkl ,
                    it_output-stawn)
              where vbeln = it_output-vbeln and
                    posnr = it_output-posnr.
      endif.
    endif.
* Make the checkboxes unchecked after updating the salesorder.
    it_output-check = ' '.
    modify it_output index v_tabix.
  endloop.
endform.                    " SAVE_SALES_DOCU
*&---------------------------------------------------------------------*
*&      Form  VALIDATE_INPUT
*&---------------------------------------------------------------------*
*      To Validate Input Fields
*----------------------------------------------------------------------*
form validate_input.
  loop at it_output.
    v_tabix = sy-tabix.
* check if the Country of origin exists.
    if not it_output-herkl is initial.
      select single landx
                    from t005t
                    into t005t-landx
                    where spras = 'EN' and
                          land1 = it_output-herkl.
      if sy-subrc <> 0.
        message e899 with it_output-herkl text-011 .
        exit.
      endif.
* Move country description to display field
      move t005t-landx to it_output-landx.
    else.
      move space to it_output-landx.
    endif.
* check if the Commodity code exists.
    if not it_output-stawn is initial.
      select single text1
                    from t604t
                    into t604t-text1
                    where spras = 'EN' and
                          land1 = it_output-herkl and
                          stawn = it_output-stawn.
      if sy-subrc <> 0.
        message e899 with it_output-stawn text-012 .
        exit.
      endif.
* Move commodity description to display field
      move t604t-text1 to it_output-text1.
    else .
      move space to it_output-text1.
    endif.
    modify it_output index v_tabix.
  endloop.
endform.                    " VALIDATE_INPUT
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ERRORS
*&---------------------------------------------------------------------*
*       Display PopUp Messages
*----------------------------------------------------------------------*
form display_errors.
*variables
  data : l_pos(1) type n value 1. " Field pos
* Fieldcatalog for popup
  data : it_fieldcat_pop type slis_t_fieldcat_alv with header line.
* Sales Order #
  it_fieldcat_pop-fieldname         = 'VBELN'.
  it_fieldcat_pop-tabname           = 'IT_ERRMSGS'.
  it_fieldcat_pop-col_pos           = l_pos.
  it_fieldcat_pop-seltext_m         = 'Sales Order# '.
  it_fieldcat_pop-ddictxt           = 'M'.
  it_fieldcat_pop-outputlen         = 10.
  it_fieldcat_pop-no_zero           = 'X'.
  append it_fieldcat_pop.
  clear  it_fieldcat_pop.
  l_pos                              = l_pos + 1.
* Message
  it_fieldcat_pop-fieldname         = 'MESSAGE'.
  it_fieldcat_pop-tabname           = 'IT_ERRMSGS'.
  it_fieldcat_pop-col_pos           = l_pos.
  it_fieldcat_pop-seltext_m         = 'Message'.
  it_fieldcat_pop-ddictxt           = 'M'.
  it_fieldcat_pop-outputlen         = 255.
  it_fieldcat_pop-no_zero           = 'X'.
  append it_fieldcat_pop.
  clear  it_fieldcat_pop.

  call function 'REUSE_ALV_POPUP_TO_SELECT'
       exporting
            i_title       = 'Errors'
            i_tabname     = 'IT_ERRMSGS'
            it_fieldcat   = it_fieldcat_pop[]
       tables
            t_outtab      = it_errmsgs
       exceptions
            program_error = 1
            others        = 2.
endform.                    " DISPLAY_ERRORS

*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*      Builds FieldCatalog
*----------------------------------------------------------------------*
form build_fieldcatalog.
  data : l_pos(2) type n value 1.
  refresh it_fieldcat.
  clear   it_fieldcat.
* Field Catalog for first line in Output.
* Order/Line
  it_fieldcat-fieldname = 'VBPOS'.
  it_fieldcat-tabname   = 'IT_OUTPUT'.
  it_fieldcat-col_pos   = l_pos.
  it_fieldcat-outputlen = 17.
  it_fieldcat-seltext_m =  text-013.   "Order/Line
  append it_fieldcat.
  clear  it_fieldcat.
  l_pos = l_pos + 1.
* Material#
  it_fieldcat-fieldname  = 'MATNR'.
  it_fieldcat-tabname   = 'IT_OUTPUT'.
  it_fieldcat-col_pos   = l_pos.
  it_fieldcat-outputlen = 18.
  it_fieldcat-seltext_m =  text-006.   "Material#
  append it_fieldcat.
  clear  it_fieldcat.
  l_pos = l_pos + 1.
* Material Desc
  it_fieldcat-fieldname   = 'ARKTX'.
  it_fieldcat-tabname   = 'IT_OUTPUT'.
  it_fieldcat-col_pos   = l_pos.
  it_fieldcat-outputlen = 40.
  it_fieldcat-seltext_m =  text-007.   "Material Desc
  append it_fieldcat.
  clear  it_fieldcat.
  l_pos = l_pos + 1.
* Cnty of Origin
  it_fieldcat-fieldname   = 'HERKL'.
  it_fieldcat-tabname   = 'IT_OUTPUT'.
  it_fieldcat-input     = 'X'.
  it_fieldcat-col_pos   = l_pos.
  it_fieldcat-outputlen =  3.
  it_fieldcat-seltext_m =  text-008.   "Cnty of Origin
  append it_fieldcat.
  clear  it_fieldcat.
  l_pos = l_pos + 1.
* Country Description
  it_fieldcat-fieldname   = 'LANDX'.
  it_fieldcat-tabname   = 'IT_OUTPUT'.
  it_fieldcat-col_pos   = l_pos.
  it_fieldcat-outputlen = 15.
  it_fieldcat-seltext_m =  text-009.   "Description
  append it_fieldcat.
  clear  it_fieldcat.
  l_pos = l_pos + 1.
* HTS Code
  it_fieldcat-fieldname   = 'STAWN'.
  it_fieldcat-tabname   = 'IT_OUTPUT'.
  it_fieldcat-input     = 'X'.
  it_fieldcat-col_pos   = l_pos.
  it_fieldcat-outputlen = 17.
  it_fieldcat-seltext_m =  text-010.   "HTS Code
  append it_fieldcat.
  clear  it_fieldcat.
  l_pos = l_pos + 1.
* HTS Description
  it_fieldcat-fieldname   = 'TEXT1'.
  it_fieldcat-tabname   = 'IT_OUTPUT'.
  it_fieldcat-col_pos   = l_pos.
  it_fieldcat-outputlen = 15.
  it_fieldcat-seltext_m =  text-009.   "Description
  append it_fieldcat.
  clear  it_fieldcat.
* Field Catalog for second line in Output.
* Cnty of Origin
  l_pos = 1.
  it_fieldcat-fieldname = 'HERKL'.
  it_fieldcat-tabname   = 'IT_OUTPUT2'.
  it_fieldcat-col_pos   = '1'.
  it_fieldcat-outputlen =  18.
  it_fieldcat-seltext_m =  text-014.   "Cnty of Origin
  append it_fieldcat.
  clear  it_fieldcat.
  l_pos = l_pos + 1.
* HTS Code
  it_fieldcat-fieldname = 'STAWN'.
  it_fieldcat-tabname   = 'IT_OUTPUT2'.
  it_fieldcat-col_pos   = '2'.
  it_fieldcat-outputlen = 17.
  it_fieldcat-seltext_m =  text-010.   "HTS Code
  append it_fieldcat.
  clear  it_fieldcat.
endform.                    " BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*&      Form  BUILD_EVENTS
*&---------------------------------------------------------------------*
*       Populate Events Table
*----------------------------------------------------------------------*
form build_events.
  refresh it_events.
  clear   it_events.
*ADD Top of Page event.
  it_events-name = 'TOP_OF_PAGE'.
  it_events-form = 'TOP_OF_PAGE'.
  append it_events.
  clear  it_events.
*ADD Top of LIST event.
  it_events-name = 'TOP_OF_LIST'.
  it_events-form = 'TOP-OF-LIST'.
  append it_events.
  clear  it_events.
endform.                    " BUILD_EVENTS

0 Kudos

Hi Vijay & Others,

I see your sample program including logic to post customer fields by BAPI_SALESORDER_CHANGE. I am trying to use this bapi to post customer fields in VBAP too.

But I can not get it work. Can you tell me the steps to

enhance this BAPI? Do I need to extend the conmunication strucure VBAPKOMX / VBAPCOM ? Do I need to use BADI to write some code to transfer values? If I need, which BADI? Thanks in advance.

Former Member
0 Kudos

Hi here is a sample program on using that function module.

Hope this will help u.

Satish

report zuseofhashedtables.

************************************************************************

    • Program: ZUseOfHashedTables **

************************************************************************

    • Author: Horacio Zapettini **

    • **

    • Versions: 4.6b - 4.6c **

************************************************************************

    • Notes: **

    • this program shows how we can use hashed tables to improve **

    • the responce time. **

    • It shows, **

    • 1. how to declare hashed tables **

    • 2. a cache-like technique to improve access to master data **

    • 3. how to collect data using hashed tables **

    • 4. how to avoid deletions of unwanted data **

************************************************************************

    • Results: the test we run read about 31000 rows from mkpf, 150000 **

    • rows from mseg, 500 rows from makt and 400 from lfa1. **

    • it filled ht_lst with 24500 rows and displayed them in **

    • alv grid format. **

    • **

    • It took about 65 secodns to perform this task (first time **

    • we run it when all the db buffers are empty. **

    • **

    • The same program with standard tables needed 140 seconds **

    • to run with the same recordset and with buffers filled in **

    • **

    • A simmilar test over more than a million rows

************************************************************************

    • Objetive: show a list that consists of all the material movements **

    • '101' - '901' for a certain range of dates in mkpf-budat. **

    • the columns to be displayed are: **

    • mkpf-budat, **

    • mkpf-mblnr, **

    • mseg-lifnr, **

    • lfa1-name1, **

    • mkpf-xblnr, **

    • mseg-zeile **

    • mseg-charg, **

    • mseg-matnr, **

    • makt-maktx, **

    • mseg-erfmg, **

    • mseg-erfme. **

    • or show a sumary list by matnr - menge **

    • **

    • You'll have to create a pf-status called vista - **

    • See form set_pf_status for details **

************************************************************************

    • tables used -

tables: mkpf,

mseg,

lfa1,

makt.

    • global hashed tables used

*

data: begin of wa_mkpf, "header

mblnr like mkpf-mblnr,

mjahr like mkpf-mjahr,

budat like mkpf-budat,

xblnr like mkpf-xblnr,

end of wa_mkpf.

data: ht_mkpf like hashed table of wa_mkpf

with unique key mblnr mjahr

with header line.

data: st_mkpf like standard table of wa_mkpf

with header line.

*

data: begin of wa_mseg, " line items

mblnr like mseg-mblnr,

mjahr like mseg-mjahr,

zeile like mseg-zeile,

bwart like mseg-bwart,

charg like mseg-charg,

matnr like mseg-matnr,

lifnr like mseg-lifnr,

erfmg like mseg-erfmg,

erfme like mseg-erfme,

end of wa_mseg.

data ht_mseg like hashed table of wa_mseg

with unique key mblnr mjahr zeile

with header line.

data st_mseg like standard table of wa_mseg

with header line.

    • cache structure for lfa1 records

data: begin of wa_lfa1,

lifnr like lfa1-lifnr,

name1 like lfa1-name1,

end of wa_lfa1.

data ht_lfa1 like hashed table of wa_lfa1

with unique key lifnr

with header line.

    • cache structure for material related data

data: begin of wa_material,

matnr like makt-matnr,

maktx like makt-maktx,

end of wa_material.

data: ht_material like hashed table of wa_material

with unique key matnr

with header line.

    • result table

data: begin of wa_lst, "

budat like mkpf-budat,

mblnr like mseg-mblnr,

lifnr like mseg-lifnr,

name1 like lfa1-name1,

xblnr like mkpf-xblnr,

zeile like mseg-zeile,

charg like mseg-charg,

matnr like mseg-matnr,

maktx like makt-maktx,

erfmg like mseg-erfmg,

erfme like mseg-erfme,

mjahr like mseg-mjahr,

end of wa_lst.

data: ht_lst like hashed table of wa_lst

with unique key mblnr mjahr zeile

with header line.

data: begin of wa_lst1, " sumary by material

matnr like mseg-matnr,

maktx like makt-maktx,

erfmg like mseg-erfmg,

erfme like mseg-erfme,

color_line(4) TYPE c, " Line color

color_cell TYPE lvc_t_scol, " Cell color

celltab type LVC_T_STYL,

end of wa_lst1.

data: ht_lst1 like hashed table of wa_lst1

with unique key matnr

with header line.

    • structures for alv grid display.

    • itabs

type-pools: slis.

data: it_lst like standard table of wa_lst with header line,

it_fieldcat_lst type slis_t_fieldcat_alv with header line,

it_sort_lst type slis_t_sortinfo_alv,

it_lst1 like standard table of wa_lst1 with header line,

it_fieldcat_lst1 type slis_t_fieldcat_alv with header line,

it_sort_lst1 type slis_t_sortinfo_alv.

    • structures

data: wa_sort type slis_sortinfo_alv,

ls_layout type slis_layout_alv.

    • color management.

DATA : wa_color TYPE lvc_s_scol.

  • Internal table for color management.

DATA : it_color TYPE TABLE OF lvc_s_scol.

  • itab for input enabling.

DATA: lt_celltab TYPE lvc_t_styl. "

    • global varialbes

data: g_lines type i.

data: g_repid like sy-repid,

ok_code like sy-ucomm.

    • selection-screen

"text: Dates:

select-options: so_budat for mkpf-budat default sy-datum.

"text: Material numbers.

select-options: so_matnr for mseg-matnr.

selection-screen uline.

selection-screen skip 1.

"Text: show summary by material.

parameters: gp_bymat as checkbox default ''.

parameters: gp_hier as checkbox default 'X'.

start-of-selection.

perform get_data.

perform show_data.

end-of-selection.

*----


*

  • FORM get_data *

*----


*

  • ........ *

*----


*

form get_data.

select mblnr mjahr budat xblnr

into table ht_mkpf

from mkpf

where budat in so_budat. " make use of std index.

    • have we retrieved data from mkpf?

describe table ht_mkpf lines g_lines.

if g_lines > 0.

    • if true then retrieve all related records from mseg.

    • Doing this way we make sure that the access is by primary key

    • of mseg.

    • The reason is that is faster to filter them in memory

    • than to allow the db server to do it.

select mblnr mjahr zeile bwart charg

matnr lifnr erfmg erfme

into table ht_mseg

from mseg

for all entries in ht_mkpf

where mblnr = ht_mkpf-mblnr

and mjahr = ht_mkpf-mjahr.

endif.

    • fill t_lst or t_lst1 according to user's choice.

if gp_bymat = ' '.

perform fill_ht_lst.

else.

perform fill_ht_lst1.

endif.

endform.

form fill_ht_lst.

refresh ht_lst.

    • Example: how to discard unwanted data in an efficient way.

loop at ht_mseg.

  • filter unwanted data

check ht_mseg-bwart = '101' or ht_mseg-bwart = '901'.

check ht_mseg-matnr in so_matnr.

  • read header line.

read table ht_mkpf with table key mblnr = ht_mseg-mblnr

mjahr = ht_mseg-mjahr.

clear ht_lst.

  • * note : this may be faster if you specify field by field.

move-corresponding ht_mkpf to ht_lst.

move-corresponding ht_mseg to ht_lst.

perform read_lfa1 using ht_mseg-lifnr changing ht_lst-name1.

perform read_material using ht_mseg-matnr changing ht_lst-maktx.

insert table ht_lst.

endloop.

endform.

form fill_ht_lst1.

data: colorear.

refresh ht_lst1.

    • Example: how to discard unwanted data in an efficient way.

    • hot to simulate a collect in a faster way

loop at ht_mseg.

  • filter unwanted data

check ht_mseg-bwart = '101' or ht_mseg-bwart = '901'.

check ht_mseg-matnr in so_matnr.

  • * note : this may be faster if you specify field by field.

read table ht_lst1 with table key matnr = ht_mseg-matnr

transporting erfmg.

if sy-subrc <> 0. " if matnr doesn't exist in sumary table

" insert a new record

clear ht_lst1.

ht_lst1-matnr = ht_mseg-matnr.

perform read_material using ht_mseg-matnr changing ht_lst1-maktx.

ht_lst1-erfmg = ht_mseg-erfmg.

ht_lst1-erfme = ht_mseg-erfme.

if colorear = ''.

colorear = 'X'.

refresh it_color.

ht_lst1-color_cell[] = it_color[].

MOVE 'C410' TO ht_lst1-color_line.

else.

colorear = ' '.

refresh it_color. clear it_color.

MOVE 'MATNR' TO wa_color-fname.

MOVE '6' TO wa_color-color-col.

MOVE '1' TO wa_color-color-int.

MOVE '1' TO wa_color-color-inv.

APPEND wa_color TO it_color.

MOVE 'MAKTX' TO wa_color-fname.

MOVE '3' TO wa_color-color-col.

MOVE '1' TO wa_color-color-int.

MOVE '1' TO wa_color-color-inv.

APPEND wa_color TO it_color.

MOVE 'ERFMG' TO wa_color-fname.

MOVE '5' TO wa_color-color-col.

MOVE '1' TO wa_color-color-int.

MOVE '1' TO wa_color-color-inv.

APPEND wa_color TO it_color.

ht_lst1-color_cell[] = it_color[].

clear ht_lst1-color_line.

endif.

insert table ht_lst1.

else." a record was found.

" collect erfmg. To do so, fill in the unique key and add

" the numeric fields.

ht_lst1-matnr = ht_mseg-matnr.

add ht_mseg-erfmg to ht_lst1-erfmg.

modify table ht_lst1 transporting erfmg.

endif.

endloop.

endform.

    • implementation of cache for lfa1.

form read_lfa1 using p_lifnr changing p_name1.

read table ht_lfa1 with table key lifnr = p_lifnr

transporting name1.

if sy-subrc <> 0.

clear ht_lfa1.

ht_lfa1-lifnr = p_lifnr.

select single name1

into ht_lfa1-name1

from lfa1

where lifnr = p_lifnr.

if sy-subrc <> 0. ht_lfa1-name1 = 'n/a in lfa1'. endif.

insert table ht_lfa1.

endif.

p_name1 = ht_lfa1-name1.

endform.

    • implementation of cache for material data

form read_material using p_matnr changing p_maktx.

read table ht_material with table key matnr = p_matnr

transporting maktx.

if sy-subrc <> 0.

ht_material-matnr = p_matnr.

select single maktx into ht_material-maktx

from makt

where spras = sy-langu

and matnr = p_matnr.

if sy-subrc <> 0. ht_material-maktx = 'n/a in makt'. endif.

insert table ht_material.

endif.

p_maktx = ht_material-maktx.

endform.

form show_data.

if gp_hier = 'X'. "no anda.

  • perform show_hierarchicalALV.

else.

if gp_bymat = ' '.

perform show_ht_lst.

else.

perform show_ht_lst1.

endif.

endif.

endform.

form show_hierarchicalALV.

st_mkpf[] = ht_mkpf[].

st_mseg[] = ht_mseg[].

call function 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'

  • exporting

  • I_INTERFACE_CHECK = ' '

  • I_CALLBACK_PROGRAM =

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

  • IS_LAYOUT =

  • IT_FIELDCAT =

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

  • IT_SORT =

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

  • IT_EVENTS =

  • IT_EVENT_EXIT =

  • i_tabname_header =

  • i_tabname_item =

  • I_STRUCTURE_NAME_HEADER =

  • I_STRUCTURE_NAME_ITEM =

  • is_keyinfo =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_BUFFER_ACTIVE =

  • I_BYPASSING_BUFFER =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

tables

t_outtab_header = st_mkpf

t_outtab_item = st_mseg

  • EXCEPTIONS

  • PROGRAM_ERROR = 1

  • OTHERS = 2

.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

endform.

form show_ht_lst.

"needed because the FM can't use a hashed table.

it_lst[] = ht_lst[].

perform fill_layout using 'full display'

changing ls_layout.

perform fill_columns_lst.

  • perform sort_lst.

g_repid = sy-repid.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_callback_program = g_repid

i_callback_pf_status_set = 'SET_PF_STATUS'

is_layout = ls_layout

it_fieldcat = it_fieldcat_lst[]

  • it_sort = it_sort_lst

tables

t_outtab = it_lst

exceptions

program_error = 1

others = 2.

endform.

form show_ht_lst1.

"needed because the FM can't use a hashed table.

it_lst1[] = ht_lst1[].

perform fill_layout using 'Sumary by matnr'

changing ls_layout.

perform fill_columns_lst1.

  • perform sort_lst.

g_repid = sy-repid.

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

i_callback_program = g_repid

i_callback_pf_status_set = 'SET_PF_STATUS'

is_layout = ls_layout

it_fieldcat = it_fieldcat_lst1[]

  • it_sort = it_sort_lst

tables

t_outtab = it_lst1

exceptions

program_error = 1

others = 2.

endform.

form fill_layout using p_window_titlebar

changing cs_layo type slis_layout_alv.

clear cs_layo.

cs_layo-window_titlebar = p_window_titlebar.

cs_layo-edit = 'X'.

cs_layo-edit_mode = space.

MOVE 'COLOR_LINE' TO cs_layo-info_fieldname.

  • Field that identify cell color in inetrnal table

MOVE 'COLOR_CELL' TO cs_layo-coltab_fieldname.

  • move 'CELLTAB' TO cs_layo-stylefname.

endform. " armar_layout_stock

form set_pf_status using rt_extab type slis_t_extab.

    • create a new status

    • and then select extras -> adjust template -> listviewer

set pf-status 'VISTA'.

endform. "set_pf_status

define add_lst.

clear it_fieldcat_lst.

it_fieldcat_lst-fieldname = &1.

it_fieldcat_lst-outputlen = &2.

it_fieldcat_lst-ddictxt = 'L'.

it_fieldcat_lst-seltext_l = &1.

it_fieldcat_lst-seltext_m = &1.

it_fieldcat_lst-seltext_m = &1.

if &1 = 'MATNR'.

it_fieldcat_lst-emphasize = 'C111'.

endif.

append it_fieldcat_lst.

end-of-definition.

define add_lst1.

clear it_fieldcat_lst.

it_fieldcat_lst1-fieldname = &1.

it_fieldcat_lst1-outputlen = &2.

it_fieldcat_lst1-ddictxt = 'L'.

it_fieldcat_lst1-seltext_l = &1.

it_fieldcat_lst1-seltext_m = &1.

it_fieldcat_lst1-seltext_m = &1.

append it_fieldcat_lst1.

end-of-definition.

form fill_columns_lst.

  • set columns for output.

refresh it_fieldcat_lst.

*

add_lst 'BUDAT' 10.

add_lst 'MBLNR' 10.

add_lst 'LIFNR' 10.

add_lst 'NAME1' 35.

add_lst 'XBLNR' 15.

add_lst 'ZEILE' 5.

add_lst 'CHARG' 10.

add_lst 'MATNR' 18.

add_lst 'MAKTX' 30.

add_lst 'ERFMG' 17.

add_lst 'ERFME' 5.

add_lst 'MJAHR' 4.

endform.

form fill_columns_lst1.

  • set columns for output.

refresh it_fieldcat_lst1.

add_lst1 'MATNR' 18.

add_lst1 'MAKTX' 30.

add_lst1 'ERFMG' 17.

add_lst1 'ERFME' 5..

endform.

Horacio Zapettini

-

-


Program to Calculate FI Opening Balance

How to find the Opening balance for a given period in FI Module for a Particular GL A/c.

I was calculated opening balance, code is below maybe it will be helpful.

*find period.

CALL FUNCTION 'DATE_TO_PERIOD_CONVERT'

EXPORTING

i_date = s_budat-low

i_periv = i_tab-periv "'K4'

IMPORTING

e_buper = v_donem

e_gjahr = v_gjahr

EXCEPTIONS

input_false = 1

t009_notfound = 2

t009b_notfound = 3

OTHERS = 4.

*calc opening balance hesabý

SELECT * FROM knc1 WHERE kunnr = i_tab-kunnr

AND bukrs = i_tab-bukrs " s_bukrs

AND gjahr EQ v_gjahr.

v_dnm = v_donem.

  • opening balance first calc > old year ,

WHILE v_dnm > 1.

v_dnm = v_dnm - 1.

CONCATENATE 'knc1-um' v_dnm 's' INTO v_field_name_borc.

CONCATENATE 'knc1-um' v_dnm 'h' INTO v_field_name_alacak.

ASSIGN (v_field_name_borc) TO old

  • add days which is from selected date-low month

IF v_donem > 1.

v_dnm = v_donem - 1.

ELSE.

v_dnm = v_donem.

ENDIF.

SELECT SINGLE * FROM t009b WHERE periv = i_tab-periv "'K4'

AND bdatj = s_budat-low+0(4)

AND poper = v_dnm.

t009b-butag = t009b-butag + 1.

IF s_budat-low+6(2) NE t009b-butag.

v_date_high = s_budat-low - 1.

IF v_donem = 1.

v_date_low = s_budat-low.

v_date_low+4(4) = '0101'.

ELSE.

CONCATENATE t009b-bdatj t009b-bumon t009b-butag INTO

v_date_low.

ENDIF.

SELECT * FROM bsad WHERE bukrs EQ i_tab-bukrs "IN s_bukrs

AND kunnr = i_tab-kunnr

AND budat BETWEEN v_date_low AND

v_date_high

AND umskz = space

AND blart IN s_blart.

IF bsad-shkzg = 'S'.

i_tab-dmbtr_s = i_tab-dmbtr_s + ( bsad-dmbtr ).

ELSEIF bsad-shkzg = 'H'.

i_tab-dmbtr_h = i_tab-dmbtr_h + ( bsad-dmbtr ).

ENDIF.

ENDSELECT.

SELECT * FROM bsid WHERE bukrs EQ i_tab-bukrs "IN s_bukrs

AND kunnr = i_tab-kunnr

AND budat BETWEEN v_date_low AND

v_date_high

AND umskz = space

AND blart IN s_blart.

  • AND gsber IN gsber.

IF bsid-shkzg = 'S'.

i_tab-dmbtr_s = i_tab-dmbtr_s + ( bsid-dmbtr ).

ELSEIF bsid-shkzg = 'H'.

i_tab-dmbtr_h = i_tab-dmbtr_h + ( bsid-dmbtr ).

ENDIF.

ENDSELECT.

ENDIF.

"opening balance ( þirket bazlý )z1 degeri

i_tab-z1 = i_tab-z1 + ( knc1-umsav + i_tab-dmbtr_s - i_tab-dmbtr_h ).

  • for israel

i_tab-dmbtril_s = i_tab-dmbtr_s .

i_tab-dmbtril_h = i_tab-dmbtr_h .

ENDSELECT.

sreemsft
Contributor
0 Kudos
report  zsree_po_alv no standard page heading line-size 220
                                           message-id zsree.


***********************************************************************
*              D A T A   D E C L A R A T I O N
***********************************************************************

***********************************************************************
*          T Y P E S   D E C L A R A T I O N
***********************************************************************

type-pools: slis.  " SAP standard type pools

types: begin of t_tab,
        vbeln type vbak-vbeln, " Sales and distribution document number
        erdat type vbak-erdat, " Date on which the record was created
        kunnr type vbak-kunnr, " Sold-to party 1
        vdatu type vbak-vdatu, " Requested delivery date
       end of t_tab.

types: begin of t_tab1,
        vbeln type vbap-vbeln,   " Sales and distribution
                                         " document number
        posnr type vbap-posnr,   " Sales document item
        matnr type vbap-matnr,   " Material number
        arktx type vbap-arktx,   " Short text for sales order item
        kwmeng type vbap-kwmeng, " Cumulative order quantity
                                              " in sales units
       end of t_tab1.

types: begin of t_tab2,
        bstkd type vbkd-bstkd, " Customer purchase order number
        vbeln type vbkd-vbeln, " Sales and distribution document number
       end of t_tab2.

types: begin of t_tab3,
        vbeln type vbep-vbeln, " Sales and distribution document number
        posnr type vbep-posnr, " Sales document item
        etenr type vbep-etenr, " Schedule line
        bddat type vbep-bddat, " Requirement date
                                   " (deadline for procurement)
        bmeng type vbep-bmeng, " Confirmed quantity
        vrkme type vbep-vrkme, " Sales unit
       end of t_tab3.

types: begin of t_tab4,
        kunnr type kna1-kunnr,  " Customer number
        name1 type kna1-name1,                              " Name
       end of t_tab4.

types: begin of t_tab5,
        vbeln type vbuk-vbeln,  " Sales and distribution document number
        lfgsk type vbuk-lfgsk,  " Overall delivery status for all items
       end of t_tab5.

types: begin of t_tab6,
        vbeln type vbup-vbeln, " Sales and distribution document number
        posnr type vbup-posnr, " Item number of the SD document
       end of t_tab6.

types: begin of t_tab8,
        vbeln type vbak-vbeln, " Sales and distribution document number
       end of t_tab8.

***********************************************************************
*               G L O B A L   V A R I A B L E S
***********************************************************************

data: v_repid          type sy-repid,  " Program name
*---  To store the internal table name
      v_tabname        type slis_tabname,
*---  Internal table to get PO catalog details
      it_fieldcat1     type slis_t_fieldcat_alv,
*---  Internal table to get SO catalog details
      it_fieldcat2     type slis_t_fieldcat_alv,
*---  Internal table to get SE catalog details
      it_fieldcat3     type slis_t_fieldcat_alv,
*---  Work area to change field catalog.
      wa_fieldcat1     type slis_fieldcat_alv,
*---  Internal table to get Events
      it_events        type slis_t_event,
*---  Internal table to get Events
      it_events1       type slis_t_event,
*---  Internal table to get Events
      it_events2       type slis_t_event,
*---  Work area for Events
      wa_events        type slis_alv_event,
*---  Work area for Layout
      wa_layout        type slis_layout_alv,
*---  Internal table for Keyinfo
      it_keyinfo       type slis_keyinfo_alv,
*---  To store the selected field value
      v_selfield_value type slis_selfield-value,
*---  To store the variant types
      i_variant        like disvariant,
*---  To store the hierarchical layout types
      i_variant1       like disvariant,
*---  To get the total lines of table IT_VBEP1
      v_linc type i.


***********************************************************************
*       V A R I A B L E S   F O R   S E L E C T -  O P T I O N S
***********************************************************************

data: v_auart  type vbak-auart,  " Sales document
      v_erdat  type vbak-erdat,  " Date on which the record was created
      v_ernam  type vbak-ernam,  " Name of person who created the object
      v_vkorg  type vbak-vkorg,  " Sales organization
      v_vtweg  type vbak-vtweg,  " Distribution channel
      v_spart  type vbak-spart,  " Division
      v_vbeln  type vbak-vbeln,  " Sales document
      v_bstkd  type vbkd-bstkd,  " Customer purchase order number
      v_kunnr  type vbak-kunnr,  " Customer number 1
      v_werks  type vbap-werks,  " Plant (own or external)
      v_lifsk  type vbak-lifsk,  " Delivery block
      v_lfgsk  type vbuk-lfgsk,  " Delivery block (Document Header)
      v_lfgsa  type vbup-lfgsa,  " Overall delivery status of the item
      v_spart1 type vbap-spart,  " Division
      v_prctr  type vbap-prctr.  " Profit Center

***********************************************************************
*              F L A G S   D E C L A R A T I O N
***********************************************************************
data: fg_error.        " Flag to check whether the data populated or not

***********************************************************************
*      I N T E R N A L   T A B L E S   D E C L A R A T I O N
***********************************************************************

*---Declaring Internal Table IT_VBAK Of type T_TAB
data: it_vbak type standard table of t_tab with header line.

*---Declaring Internal Table IT_VBAP Of type T_TAB1
data: it_vbap type standard table of t_tab1 with header line.

*---Declaring Internal Table IT_VBKD Of type T_TAB2
data: it_vbkd type standard table of t_tab2 with header line.

*---Declaring Internal Table IT_VBEP Of type T_TAB3
data: it_vbep type standard table of t_tab3 with header line.

*---Declaring Internal Table IT_VBEP1 Of Type T_TAB3
data: it_vbep1 type standard table of t_tab3 with header line.

*---Declaring Internal Table IT_KNA1 Of type T_TAB4
data: it_kna1 type standard table of t_tab4 with header line.

*---Declaring Internal Table IT_VBUK Of type T_TAB5
data: it_vbuk type standard table of t_tab5 with header line.

*---Declaring Internal Table IT_VBUP Of type T_TAB6
data: it_vbup type standard table of t_tab6 with header line.

*---Declaring Internal Table of type VBAK
data: it_vbak1 type standard table of t_tab8 with header line.

*---Declaring a final internal table which contains PO details
data: begin of it_final1 occurs 0,
        bstkd like vbkd-bstkd,  " Customer purchase order number
        kunnr like vbak-kunnr,  " Customer number
        name1 like kna1-name1,  " Name
        vdatu like vbak-vdatu,  " Requested delivery date
      end of it_final1.

*---Declaring a final internal table which contains SO details
data: begin of it_final2 occurs 0,
        vbeln like vbak-vbeln,  " Sales and distribution document number
        vdatu like vbak-vdatu,  " Requested delivery date
        erdat like vbak-erdat,  " Date on which the record was created
        lfgsk like vbuk-lfgsk,  " Overall delivery status for all items
        check,
      end of it_final2.

*---Declaring a final internal table which contains SE details
data: begin of it_final3 occurs 0,
        vbeln  like vbep-vbeln,  " Sales and distribution
                                           " document number
        posnr  like vbep-posnr,  " Sales document item
        etenr  like vbep-etenr,  " Schedule line
        matnr  like vbap-matnr,  " Material number
        arktx  like vbap-arktx,  " Short text for sales order item
        bddat  like vbep-bddat,  " Requirement date
                                   " (deadline for procurement)
        kwmeng like vbap-kwmeng, " Cumulative order quantity
                                   " in sales units
        bmeng  like vbep-bmeng,  " Confirmed quantity
      end of it_final3.

*---Declaring an internal table which contains SO details of selected PO
data: begin of it_final4 occurs 0,
        vbeln like vbak-vbeln,  " Sales and distribution
                                  " document number
        vdatu like vbak-vdatu,  " Requested delivery date
        erdat like vbak-erdat,  " Date on which the record was created
        lfgsk like vbuk-lfgsk,  " Overall delivery status for all items
        check,
      end of it_final4.

*---Declaring an internal table which contains SE details of selected PO
data: begin of it_final5 occurs 0,
        vbeln  like vbep-vbeln, " Sales and distribution
                                  " document number
        posnr  like vbep-posnr, " Item number of the SD document
        etenr  like vbep-etenr, " Schedule line
        matnr  like vbap-matnr, " Material number
        arktx  like vbap-arktx, " Short text for sales order item
        bddat  like vbep-bddat, " Requirement date
                                  " (deadline for procurement)
        kwmeng like vbap-kwmeng, " Cumulative order quantity in
                                   " sales unit
        bmeng  like vbep-bmeng, "  Confirmed quantity
      end of it_final5.


***********************************************************************
*                S E L E C T I O N    S C R E E N
***********************************************************************

*---Selection screen tab 1
selection-screen begin of block b1 with frame title text-001.
select-options:  s_auart for v_auart,  " Sales document type
                 s_erdat for v_erdat,  " Date on which the
                                              " record was created
                 s_ernam for v_ernam no intervals no-extension.
" Name of Person who Created the Object
selection-screen end of block b1.

*---Selection screen tab 2
selection-screen begin of block b2 with frame title text-002.
select-options:  s_vkorg for v_vkorg,  " Sales organization
                 s_vtweg for v_vtweg,  " Distribution channel
                 s_spart for v_spart.  " Division
selection-screen end of block b2.

*---Subscreen 1
selection-screen begin of screen 110 as subscreen.
selection-screen begin of block b3 with frame.
select-options:  s_vbeln for v_vbeln,  " Sales document
                 s_bstkd for v_bstkd,  " Customer purchase
                                                 " order number
                 s_kunnr for v_kunnr,  " Customer number
                 s_werks for v_werks,  " Plant (Own or External)
                 s_lifsk for v_lifsk.  " Delivery block
" (document header)
selection-screen end of block b3.
selection-screen end of screen 110.

*---Subscreen 2
selection-screen begin of screen 120 as subscreen.
selection-screen begin of block b4 with frame.
select-options:  s_lfgsk for v_lfgsk,  " Delivery block
                                               " (document header)
                 s_lfgsa for v_lfgsa,  " Overall delivery
                                               " status of the item
                 s_spart1 for v_spart1, " Division
                 s_prctr for v_prctr.  " Profit center
selection-screen end of block b4.
selection-screen end of screen 120.

*---Tab 3 for Selection screen
selection-screen: begin of tabbed block mytab for 7 lines,
                  tab (20) button1 user-command push1,
                  tab (20) button2 user-command push2,
                  end of block mytab.

*---Selection screen to choose the type of the list to be displayed
selection-screen begin of block b6 with frame title text-005.
selection-screen begin of line.
selection-screen comment 1(18) text-006 for field p_radio1.
parameters: p_radio1 radiobutton group g1 default 'X' user-command sree.
selection-screen comment 35(20) text-007 for field p_radio2.
parameters: p_radio2 radiobutton group g1.
selection-screen end of line.
selection-screen end of block b6.

*---Selection screen to choose the list typr from a variant
selection-screen begin of block b7 with frame title text-008.
parameters: p_var type disvariant-variant modif id abc.
selection-screen end of block b7.

***********************************************************************
*                I N I T I A L I Z A T I O N
***********************************************************************

initialization.

  perform initialization. " Initializes different fields

***********************************************************************
*            A T   S E L E C T I O N   S C R E E N
***********************************************************************

at selection-screen.

  perform at_selection_screen. " At selection screen validations


***********************************************************************
*       A T   S E L E C T I O N   S C R E E N   O U T P U T
***********************************************************************

at selection-screen output.

*---If radio button 1 is clicked disables the parameter P_VAR
  if p_radio1 = 'X'.
    loop at screen.
      check screen-group1 = 'ABC'.
      screen-active = 0.
      modify screen.
    endloop.
  endif.

***********************************************************************
* A T  S E L E C T I O N   S C R E E N   O N   V A L U E  R E Q U E S T
***********************************************************************
at selection-screen on value-request for p_var.

  perform f4_for_variant. " Gets the variant to select the layout


***********************************************************************
*             S T A R T   O F   S E L E C T I O N
***********************************************************************

start-of-selection.

  perform get_data. " Gets the data into the internal tables
  perform get_final_data. " Gets the final data to be displayed

  if it_vbkd[] is initial.  " If no data found gives an information msg
    message i003.
    fg_error = 'X'.
    stop.
  endif.

***********************************************************************
*             E N D   O F   S E L E C T I O N
***********************************************************************
end-of-selection.

  perform key_info. " Gets the header and item key info

  if not fg_error = 'X'.

    if p_radio1 = 'X'.

      perform get_events. " Gets the events

      v_tabname = 'IT_FINAL1'.
*---  Populates the field catalog for PO details using table IT_FINAL1
      perform fieldcatalog_merge1 using v_tabname
                                       it_fieldcat1.
*---  Modifies the field catalog for PO details
      perform modify_fldcat.

      v_tabname = 'IT_FINAL2'.
*---  Populates the field catalog for SO details using table IT_FINAL2
      perform fieldcatalog_merge1 using v_tabname
                                        it_fieldcat2.
      v_tabname = 'IT_FINAL3'.
*---  Populates the field catalog for SE details using table IT_FINAL3
      perform fieldcatalog_merge1 using v_tabname
                                        it_fieldcat2.
*---  Gets the User command and sets the pf-status
      perform alv_init.

*---  Modifies the layout into alternative colors
      wa_layout-zebra = 'X'.

      v_tabname = 'IT_FINAL1'.
*---  Populates the Blocked List info for PO details
      perform block_list using  wa_layout
                                it_fieldcat1
                                v_tabname
                                it_events.
*---  Gets the events for the Hierarchical list of SO and SE details
      perform get_events1.

*---  Modifies the field catalog for Hierarchical list
      perform modify_fieldcat_hirarchical.

*---  Appends the Hierarchical list to the Blocked list
      perform block_list_hs.

*---  Displays the Blocked list
      perform block_display.

    elseif p_radio2 = 'X'.

*---  Makes the hierarchical list in expand all mode
      wa_layout-expand_fieldname = 'CHECK'.

*---  Gets the events of the Hierarchical list
      perform get_events2.

      v_tabname = 'IT_FINAL2'.
*---  Populates the field catalog for SO details using table IT_FINAL2
      perform fieldcatalog_merge1 using v_tabname
                                        it_fieldcat2.
      v_tabname = 'IT_FINAL3'.
*---  Populates the field catalog for SE details using table IT_FINAL3
      perform fieldcatalog_merge1 using v_tabname
                                        it_fieldcat2.
*---  Modifies the field catalog for Hierarchical list
      perform modify_fieldcat_hirarchical.

*---  Displays SO and SE details in a Hierarchical list format
      perform hierarchical_display tables it_final2
                                          it_final3
                                   using  it_fieldcat2
                                          it_events2
                                          'IT_FINAL2'
                                          'IT_FINAL3'.


    endif.

  endif.
*&---------------------------------------------------------------------*
*&      Form  INITIALIZATION
*&---------------------------------------------------------------------*
*       Initializes the selection screen
*----------------------------------------------------------------------*
form initialization .

  button1 = text-003.            " Button1 Text
  button2 = text-004.            " Button2 Text
  mytab-prog = sy-repid.         " Program Name
  mytab-dynnr = 110.             " Default Screen
  mytab-activetab = 'BUTTON1'.   " Default Tab

  perform variant_init.

endform.                    " INITIALIZATION

*&---------------------------------------------------------------------*
*&      Form  AT_SELECTION_SCREEN
*&---------------------------------------------------------------------*
*   Chooses a particular screen when clicking on a particular button
*----------------------------------------------------------------------*
form at_selection_screen .

  case sy-ucomm.
    when 'PUSH1'.
      mytab-dynnr = 110.
      mytab-activetab = 'BUTTON1'.
    when 'PUSH2'.
      mytab-dynnr = 120.
      mytab-activetab = 'BUTTON2'.
  endcase.

endform.                    " AT_SELECTION_SCREEN

*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       Populates the Internal tables
*----------------------------------------------------------------------*
form get_data .

*---Selecting the VBELN from VBAK into a temporary table to reduce
*---                                             database access
  select vbeln " Sales and distribution document number
    from vbak
    into table it_vbak1
   where vbeln in s_vbeln
     and erdat in s_erdat
     and ernam in s_ernam
     and auart in s_auart
     and lifsk in s_lifsk
     and vkorg in s_vkorg
     and vtweg in s_vtweg
     and spart in s_spart
     and kunnr in s_kunnr.

*---Selecting VBELN POSNR ETENR BDDAT WMENG BMENG VRKME from VBEP Into
*---                                                             IT_VBEP
  if not it_vbak1[] is initial.
    select vbeln  " Sales and distribution document number
           posnr  " Sales document item
           etenr  " Schedule line
           bddat  " Requirement date (Deadline for procurement)
           bmeng  " Confirmed quantity
           vrkme  " Sales unit
      from vbep
        into table it_vbep
    for all entries in it_vbak1
     where vbeln = it_vbak1-vbeln.
  endif.
*---Selecting VBELN POSNR MATNR ARKTX from VBAP Into IT_VBAP
  if not it_vbep[] is initial.
    select vbeln  " Sales and distribution document number
           posnr  " Sales document item
           matnr  " Material number
           arktx  " Short text for sales order item
           kwmeng " Cumulative order quantity in sales units
      from vbap
      into table it_vbap
       for all entries in it_vbep
     where vbeln = it_vbep-vbeln
       and posnr = it_vbep-posnr
       and werks in s_werks
       and spart in s_spart1
       and prctr in s_prctr.
  endif.

*---Selecting VBELN POSNR from VBUP Into IT_VBUP
  if not it_vbap[] is initial.
    select vbeln  " Sales and distribution document number
           posnr  " Item number of the SD document
      from vbup
      into table it_vbup
       for all entries in it_vbap
     where vbeln = it_vbap-vbeln
       and posnr = it_vbap-posnr
       and lfgsa in s_lfgsa.
  endif.

*---Selecting VBELN ERDAT VDATU KUNNR from VBAK Into IT_VBAK
  if not it_vbup[] is initial.
    select vbeln
           erdat
           kunnr
           vdatu
      from vbak
      into table it_vbak
       for all entries in it_vbup
     where vbeln = it_vbup-vbeln
       and erdat in s_erdat
       and ernam in s_ernam
       and auart in s_auart
       and vkorg in s_vkorg
       and vtweg in s_vtweg
       and spart in s_spart
       and kunnr in s_kunnr
       and lifsk in s_lifsk.
    if sy-subrc = 0.
      sort it_vbak by vbeln descending.
    endif.
  endif.

*---Selecting VBELN LFGSK from VBUK Into IT_VBUK
  if not it_vbak[] is initial.
    select vbeln
           lfgsk
      from vbuk
      into table it_vbuk
       for all entries in it_vbak
     where vbeln = it_vbak-vbeln
       and lfgsk in s_lfgsk.

    select kunnr
           name1
      from kna1
      into table it_kna1
       for all entries in it_vbak
     where kunnr = it_vbak-kunnr.
  endif.

*---Selecting BSTKD VBELN from VBKD Into IT_VBKD
  if not it_vbuk[] is initial.
    select bstkd
           vbeln
      from vbkd
      into table it_vbkd
       for all entries in it_vbuk
     where vbeln = it_vbuk-vbeln
       and bstkd in s_bstkd.
    if sy-subrc = 0.
      sort it_vbkd by vbeln bstkd descending.
      delete adjacent duplicates from it_vbkd comparing vbeln.
      sort it_vbkd by bstkd descending.
    endif.
  endif.

endform.                    " GET_DATA

*&---------------------------------------------------------------------*
*&      Form  GET_FINAL_DATA
*&---------------------------------------------------------------------*
*    Populates the final data to be displayed into internal tables
*----------------------------------------------------------------------*
form get_final_data .

*---Moving the PO details into a final table IT_FINAL1
  data: lv_tabix type sy-tabix.
  loop at it_vbkd.
    at new bstkd.
      lv_tabix = sy-tabix.
      clear it_vbkd.
      read table it_vbkd index lv_tabix.
      if sy-subrc = 0.
        clear it_vbak.
        read table it_vbak with key vbeln = it_vbkd-vbeln.
        clear it_kna1.
        read table it_kna1 with key kunnr = it_vbak-kunnr.
        if sy-subrc = 0.
          it_final1-bstkd = it_vbkd-bstkd.
          it_final1-kunnr = it_vbak-kunnr.
          it_final1-name1 = it_kna1-name1.
          it_final1-vdatu = it_vbak-vdatu.
          append it_final1.
          clear it_final1.
        endif.
      endif.
    endat.
  endloop.

*---Moving the SO details into a final table IT_FINAL2
  loop at it_vbkd.
    loop at it_vbak where vbeln = it_vbkd-vbeln.
      clear it_vbuk.
      read table it_vbuk with key vbeln = it_vbak-vbeln.
      it_final2-vbeln = it_vbak-vbeln.
      it_final2-vdatu = it_vbak-vdatu.
      it_final2-erdat = it_vbak-erdat.
      it_final2-lfgsk = it_vbuk-lfgsk.
      it_final2-check = 'X'.
      append it_final2.
      clear it_final2.
    endloop.
  endloop.

*---Moving the SE details into a final table IT_FINAL3
  refresh it_vbep1.
  clear it_vbep1.
  loop at it_vbap.
    loop at it_vbep where vbeln = it_vbap-vbeln
                      and posnr = it_vbap-posnr.
      it_vbep1 = it_vbep.
      append it_vbep1.
      clear it_vbep1.
    endloop.

    describe table it_vbep1 lines v_linc.
    if v_linc = 1.
      clear it_vbep1.
      read table it_vbep1 index 1.
      it_final3-vbeln  = it_vbep-vbeln.
      it_final3-posnr  = it_vbep1-posnr.
      it_final3-etenr  = it_vbep1-etenr.
      it_final3-matnr  = it_vbap-matnr.
      it_final3-arktx  = it_vbap-arktx.
      it_final3-bddat  = it_vbep1-bddat.
      it_final3-kwmeng = it_vbap-kwmeng.
      it_final3-bmeng  = it_vbep1-bmeng.
      append it_final3.
      clear it_final3.

    else.
      loop at it_vbep1 where bmeng <> 0.
        it_final3-vbeln  = it_vbep-vbeln.
        it_final3-posnr  = it_vbep1-posnr.
        it_final3-etenr  = it_vbep1-etenr.
        it_final3-matnr  = it_vbap-matnr.
        it_final3-arktx  = it_vbap-arktx.
        it_final3-bddat  = it_vbep1-bddat.
        it_final3-kwmeng = it_vbap-kwmeng.
        it_final3-bmeng  = it_vbep1-bmeng.
        append it_final3.
        clear it_final3.

      endloop.
    endif.
    refresh it_vbep1.
    clear it_vbep1.

  endloop.

endform.                    " GET_FINAL_DATA


*&---------------------------------------------------------------------*
*&      Form  FIELDCATALOG_MERGE1
*&---------------------------------------------------------------------*
*      Fills the field catalog by depending on the tables given
*----------------------------------------------------------------------*
form fieldcatalog_merge1 using v_tab type slis_tabname
                               v_field type slis_t_fieldcat_alv.

  call function 'REUSE_ALV_FIELDCATALOG_MERGE'
    exporting
      i_program_name         = v_repid
      i_internal_tabname     = v_tab
      i_inclname             = v_repid
    changing
      ct_fieldcat            = v_field
    exceptions
      inconsistent_interface = 1
      program_error          = 2
      others                 = 3.

  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.

endform.                    " FIELDCATALOG_MERGE1

*&---------------------------------------------------------------------*
*&      Form  KEY_INFO
*&---------------------------------------------------------------------*
*       Gets the Header and Item key into details
*----------------------------------------------------------------------*
form key_info .

  it_keyinfo-header01 = 'VBELN'.
  it_keyinfo-item01 = 'VBELN'.

endform.                    " KEY_INFO


*&---------------------------------------------------------------------*
*&      Form  HIERARCHICAL_DISPLAY
*&---------------------------------------------------------------------*
*       Displays the SO & SE details in a hierarchical list format
*----------------------------------------------------------------------*
form hierarchical_display   tables p_tab1 p_tab2
                            using  p_fieldcat type slis_t_fieldcat_alv
                                   p_events   type slis_t_event
                                   p_table1   type slis_tabname
                                   p_table2   type slis_tabname.

  i_variant1-variant = p_var.

  call function 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
    exporting
      i_callback_program       = v_repid
      i_callback_pf_status_set = 'PF_STATUS'
      is_layout                = wa_layout
*     I_CALLBACK_USER_COMMAND  = ' '
      it_fieldcat              = p_fieldcat
      i_save                   = 'X'
      is_variant               = i_variant1
      it_events                = p_events
      i_tabname_header         = p_table1
      i_tabname_item           = p_table2
      is_keyinfo               = it_keyinfo
    tables
      t_outtab_header          = p_tab1
      t_outtab_item            = p_tab2
    exceptions
      program_error            = 1
      others                   = 2.

  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.

endform.                    " HIERARCHICAL_DISPLAY


*&---------------------------------------------------------------------*
*&      Form  ALV_INIT
*&---------------------------------------------------------------------*
*       Gets the User command and sets the pf-status
*----------------------------------------------------------------------*
form alv_init .

  call function 'REUSE_ALV_BLOCK_LIST_INIT'
    exporting
      i_callback_program       = v_repid
      i_callback_pf_status_set = 'PF_STATUS'
      i_callback_user_command  = 'PO_USER_COMMAND'.

endform.                    " ALV_INIT

*&---------------------------------------------------------------------*
*&      Form  BLOCK_LIST
*&---------------------------------------------------------------------*
*       Appends the PO details into the Blocked list
*----------------------------------------------------------------------*
form block_list  using    p_wa_layout type slis_layout_alv
                          p_it_fieldcat1 type slis_t_fieldcat_alv
                          p_v_tabname type slis_tabname
                          p_it_events type slis_t_event.

  call function 'REUSE_ALV_BLOCK_LIST_APPEND'
    exporting
      is_layout                  = p_wa_layout
      it_fieldcat                = p_it_fieldcat1
      i_tabname                  = p_v_tabname
      it_events                  = p_it_events
    tables
      t_outtab                   = it_final1
    exceptions
      program_error              = 1
      maximum_of_appends_reached = 2
      others                     = 3.

  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.

  wa_layout-expand_fieldname = 'CHECK'.

endform.                    " BLOCK_LIST

*&---------------------------------------------------------------------*
*&      Form  BLOCK_LIST_HS
*&---------------------------------------------------------------------*
*       Appends the SO & SE details to the blocked list
*----------------------------------------------------------------------*
form block_list_hs .

  call function 'REUSE_ALV_BLOCK_LIST_HS_APPEND'
    exporting
      is_layout                  = wa_layout
      it_fieldcat                = it_fieldcat2
      is_keyinfo                 = it_keyinfo
      i_header_tabname           = 'IT_FINAL2'
      i_item_tabname             = 'IT_FINAL3'
      it_events                  = it_events1
    tables
      t_outtab_header            = it_final2
      t_outtab_item              = it_final3
    exceptions
      program_error              = 1
      maximum_of_appends_reached = 2
      others                     = 3.
  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.


endform.                    " BLOCK_LIST_HS

*&---------------------------------------------------------------------*
*&      Form  BLOCK_DISPLAY
*&---------------------------------------------------------------------*
*       Displays the Blocked list
*----------------------------------------------------------------------*
form block_display .

  call function 'REUSE_ALV_BLOCK_LIST_DISPLAY'
    exceptions
      program_error = 1
      others        = 2.

  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.

endform.                    " BLOCK_DISPLAY


*&---------------------------------------------------------------------*
*&      Form  MODIFY_FLDCAT
*&---------------------------------------------------------------------*
*       Modifies the field catalog of PO details
*----------------------------------------------------------------------*

form modify_fldcat .

  loop at it_fieldcat1 into wa_fieldcat1 .
    case wa_fieldcat1-fieldname .
      when 'BSTKD' .
        wa_fieldcat1-seltext_l = 'PO Number'(010).
        wa_fieldcat1-outputlen = 35 .
        wa_fieldcat1-ddictxt = 'L' .
      when 'KUNNR' .
        wa_fieldcat1-outputlen = 15 .
        wa_fieldcat1-seltext_l = 'Sold-To Pt.'(011).
        wa_fieldcat1-ddictxt = 'L' .
      when 'NAME1' .
        wa_fieldcat1-outputlen = 35 .
        wa_fieldcat1-seltext_l = 'Name1'(012).
        wa_fieldcat1-ddictxt = 'L' .
      when 'VDATU' .
        wa_fieldcat1-outputlen = 15 .
        wa_fieldcat1-seltext_l = 'Req.Dlv.Dt.'(013).
        wa_fieldcat1-ddictxt = 'L' .
    endcase .
    modify it_fieldcat1 from wa_fieldcat1 .
  endloop.

endform.                    " MODIFY_FLDCAT

*&---------------------------------------------------------------------*
*&      Form  MODIFY_FIELDCAT_HIRARCHICAL
*&---------------------------------------------------------------------*
*       Modifies the field catalog of SO & SE details
*----------------------------------------------------------------------*

form modify_fieldcat_hirarchical.

  loop at it_fieldcat2 into wa_fieldcat1.
    case wa_fieldcat1-fieldname.
      when 'VBELN' .
        wa_fieldcat1-outputlen = 20.
        wa_fieldcat1-seltext_m = 'SD Doc'(014).
        wa_fieldcat1-ddictxt   = 'M'.
      when 'VDATU' .
        wa_fieldcat1-outputlen = 20.
        wa_fieldcat1-seltext_m = 'Req.Dlv.Dt'(015).
        wa_fieldcat1-ddictxt   = 'M'.
      when 'ERDAT' .
        wa_fieldcat1-outputlen = 20.
        wa_fieldcat1-seltext_m = 'Rec Created Date'(016).
        wa_fieldcat1-ddictxt   = 'M'.
      when 'LFGSK' .
        wa_fieldcat1-outputlen = 20.
        wa_fieldcat1-seltext_m = 'Dlv Status'(017).
        wa_fieldcat1-ddictxt   = 'M'.
      when 'CHECK'.
        wa_fieldcat1-no_out    = 'X'.
    endcase .
    modify it_fieldcat2 from wa_fieldcat1.
  endloop.

endform.                    " MODIFY_FIELDCAT_HIRARCHICAL

*&---------------------------------------------------------------------*
*&      Form  GET_EVENTS
*&---------------------------------------------------------------------*
*       Gets the events for the list
*----------------------------------------------------------------------*
form get_events.

  call function 'REUSE_ALV_EVENTS_GET'
    exporting
      i_list_type     = 2
    importing
      et_events       = it_events
    exceptions
      list_type_wrong = 1
      others          = 2.
  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.

  read table it_events into wa_events
                       with key name = slis_ev_top_of_list.
  if sy-subrc = 0.
    wa_events-form = 'TOP_OF_LIST'.
    modify it_events from wa_events index sy-tabix.
  endif.

  read table it_events into wa_events
                     with key name = slis_ev_user_command.
  if sy-subrc = 0.
    wa_events-form = 'PO_USER_COMMAND'.
    modify it_events from wa_events index sy-tabix.
  endif.

endform.                    " GET_EVENTS

*&---------------------------------------------------------------------*
*&      Form  GET_EVENTS1
*&---------------------------------------------------------------------*
*     Gets the events for the list
*----------------------------------------------------------------------*
form get_events1 .

  call function 'REUSE_ALV_EVENTS_GET'
    exporting
      i_list_type     = 3
    importing
      et_events       = it_events1
    exceptions
      list_type_wrong = 1
      others          = 2.
  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.

  clear wa_events.
  read table it_events1 into wa_events
                       with key name = slis_ev_top_of_list.
  if sy-subrc = 0.
    wa_events-form = 'TOP_OF_LIST1'.
    modify it_events1 from wa_events index sy-tabix.
  endif.

endform.                    " GET_EVENTS1

*---------------------------------------------------------------------*
*     T O P  -  O F  -  L I S T
*---------------------------------------------------------------------*
*     Displays the Top of list of PO details
*----------------------------------------------------------------------*

form top_of_list.

  skip.
  write 'SYRATECH CORPORATION'(025).
  skip.
  write:/ 'System  :'(021), sy-mandt,
        / 'User    :'(022), sy-uname,
        / 'Date    :'(023), sy-datum,
        / 'Time    :'(024), sy-uzeit.
  skip.
  write:/ 'PO DETAILS'(019).

endform.                    "TOP_OF_LIST

*---------------------------------------------------------------------*
*     T O P   O F   L I S T 1
*---------------------------------------------------------------------*
*     Displays the Top of list of SO & SE details
*----------------------------------------------------------------------*

form top_of_list1.

  write:/ 'SO & SE DETAILS'(020).

endform.                    "TOP_OF_LIST1

*---------------------------------------------------------------------*
*     P F - S T A T U S
*---------------------------------------------------------------------*
*     Sets the Pf-Status
*----------------------------------------------------------------------*

form pf_status using rt_extab type slis_t_extab.

  set pf-status 'ZSREEPO'.

endform.                    "PF_STATUS

*---------------------------------------------------------------------*
*     U S E R   C O M M A N D
*---------------------------------------------------------------------*
*     Gets the user command and perform different operations
*----------------------------------------------------------------------*

form po_user_command using p_ucomm    type sy-ucomm
                           p_selfield type slis_selfield.

  case p_selfield-tabname.

    when 'IT_FINAL1'.
*---If user clicks on PO number, displays the SO and SE details of that
*---                                               particular PO number
      v_selfield_value = p_selfield-value.
*--- Gets the current layout details and process appropriate action
      perform display_secondary_list.

    when 'IT_FINAL2'.
*---If user clicks on the sales order number in the SO level the
*---                      transaction VA03 will open in a new window
      if p_selfield-fieldname = 'VBELN'.
        perform call_transaction_va03. " Calls the transaction in a
        " separate window
      endif.

    when 'IT_FINAL3'.
*---If user clicks on the sales order number in the Line Item the
*---               Intelligroup home page will open in a new browser
      if p_selfield-fieldname = 'VBELN'.
        perform open_browser. " Opens the Browser in a new window
      endif.

  endcase.

endform.                    "USER_COMMAND


*&---------------------------------------------------------------------*
*&      Form  CALL_TRANSACTION_VA03
*&---------------------------------------------------------------------*
*       Calls the transaction VA03 in a new session
*----------------------------------------------------------------------*
form call_transaction_va03 .

  call function 'ABAP4_CALL_TRANSACTION' starting new task 'TEST'
    destination 'NONE'
    exporting
      tcode                   = 'VA03'
    exceptions
      call_transaction_denied = 1
      tcode_invalid           = 2
      others                  = 3.
  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.

endform.                    " CALL_TRANSACTION_VL10

*&---------------------------------------------------------------------*
*&      Form  GET_EVENTS2
*&---------------------------------------------------------------------*
*       Gets the events for SO & SE details
*----------------------------------------------------------------------*
form get_events2 .

  call function 'REUSE_ALV_EVENTS_GET'
    exporting
      i_list_type     = 1
    importing
      et_events       = it_events2
    exceptions
      list_type_wrong = 1
      others          = 2.
  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.

  clear wa_events.
  read table it_events2 into wa_events
                        with key name = slis_ev_top_of_list.
  if sy-subrc = 0.
    wa_events-form = 'TOP_OF_LIST1'.
    modify it_events2 from wa_events index sy-tabix.
  endif.

  read table it_events2 into wa_events
                        with key name = slis_ev_user_command.
  if sy-subrc = 0.
    wa_events-form = 'PO_USER_COMMAND'.
    modify it_events2 from wa_events index sy-tabix.
  endif.

endform.                    " GET_EVENTS2

*&---------------------------------------------------------------------*
*&      Form  OPEN_BROWSER
*&---------------------------------------------------------------------*
*       Opens the Intelligroup home page in a new browser
*----------------------------------------------------------------------*
form open_browser .

  call function 'CALL_BROWSER'
    exporting
      url                    = 'WWW.INTELLIGROUP.COM'
      new_window             = 'X'
    exceptions
      frontend_not_supported = 1
      frontend_error         = 2
      prog_not_found         = 3
      no_batch               = 4
      unspecified_error      = 5
      others                 = 6.

  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.

endform.                    " OPEN_BROWSER

*&---------------------------------------------------------------------*
*&      Form  DISPLAY_SO_SE_DETAILS
*&---------------------------------------------------------------------*
*       Displays the
*----------------------------------------------------------------------*
form display_so_se_details using p_selfield type slis_selfield-value.

  refresh: it_final4, it_final5.
*---Moving the SO details into a final table IT_FINAL4
  loop at it_vbkd where bstkd = p_selfield.
    loop at it_vbak where vbeln = it_vbkd-vbeln.
      clear it_vbuk.
      read table it_vbuk with key vbeln = it_vbak-vbeln.
      it_final4-vbeln = it_vbak-vbeln.
      it_final4-vdatu = it_vbak-vdatu.
      it_final4-erdat = it_vbak-erdat.
      it_final4-lfgsk = it_vbuk-lfgsk.
      it_final4-check = 'X'.
      append it_final4.
      clear it_final4.
    endloop.
  endloop.

  loop at it_final4.
    loop at it_vbap where vbeln = it_final4-vbeln.
      loop at it_vbep where vbeln = it_vbap-vbeln
                        and posnr = it_vbap-posnr.
        it_vbep1 = it_vbep.
        append it_vbep1.
        clear it_vbep1.
      endloop.

*---Moving the SE details into a final table IT_FINAL5

      describe table it_vbep1 lines v_linc.
      if v_linc = 1.
        clear it_vbep1.
        read table it_vbep1 index 1.
        it_final5-vbeln  = it_vbep-vbeln.
        it_final5-posnr  = it_vbep1-posnr.
        it_final5-etenr  = it_vbep1-etenr.
        it_final5-matnr  = it_vbap-matnr.
        it_final5-arktx  = it_vbap-arktx.
        it_final5-bddat  = it_vbep1-bddat.
        it_final5-kwmeng = it_vbap-kwmeng.
        it_final5-bmeng  = it_vbep1-bmeng.
        append it_final5.
        clear it_final5.

      else.
        loop at it_vbep1 where bmeng <> 0.
          it_final5-vbeln  = it_vbep-vbeln.
          it_final5-posnr  = it_vbep1-posnr.
          it_final5-etenr  = it_vbep1-etenr.
          it_final5-matnr  = it_vbap-matnr.
          it_final5-arktx  = it_vbap-arktx.
          it_final5-bddat  = it_vbep1-bddat.
          it_final5-kwmeng = it_vbap-kwmeng.
          it_final5-bmeng  = it_vbep1-bmeng.
          append it_final5.
          clear it_final5.
        endloop.
      endif.
      refresh it_vbep1.
      clear it_vbep1.
    endloop.
  endloop.

  v_tabname = 'IT_FINAL4'.
*---Populates the field catalog for SO details
  perform fieldcatalog_merge1 using v_tabname
                                    it_fieldcat3.

  v_tabname = 'IT_FINAL5'.
*---Populates the field catalog for SE details
  perform fieldcatalog_merge1 using v_tabname
                                    it_fieldcat3.

  perform modify_fieldcat_hirarchical2.

*---Displays the SO & SE details in a hierarchical format
  perform hierarchical_display tables it_final4
                                      it_final5
                               using  it_fieldcat3
                                      it_events2
                                     'IT_FINAL4'
                                     'IT_FINAL5'.

endform.                    " GET_SECLIST_DATA

*&---------------------------------------------------------------------*
*&      Form  VARIANT_INIT
*&---------------------------------------------------------------------*
*       Gets the variant
*----------------------------------------------------------------------*
form variant_init.

  v_repid = sy-repid.
  clear i_variant.
  i_variant-report = v_repid.

endform.                    " VARIANT_INIT

*&---------------------------------------------------------------------*
*&      Form  F4_FOR_VARIANT
*&---------------------------------------------------------------------*
*     Gets the variant to select the layout
*----------------------------------------------------------------------*
form f4_for_variant.

  data: lv_save(1)        type c, " To save the variant
        lv_exit(1)        type c. " To get Dialog cancelled by user

  call function 'REUSE_ALV_VARIANT_F4'
    exporting
      is_variant    = i_variant
      i_save        = lv_save
    importing
      e_exit        = lv_exit
      es_variant    = i_variant1
    exceptions
      not_found     = 1
      program_error = 2
      others        = 3.
  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  else.
    if lv_exit = space.
      p_var = i_variant1-variant.
    endif.
  endif.

endform.                    " F4_FOR_VARIANT

*&---------------------------------------------------------------------*
*&      Form  DISPLAY_SECONDARY_LIST
*&---------------------------------------------------------------------*
*       Gets the current layout and process appropriate action
*----------------------------------------------------------------------*
form display_secondary_list .

  data: i_fieldcat1 type slis_t_fieldcat_alv, " Internal table for
                                               "temporary field catalog
        lv_fieldcat type slis_fieldcat_alv, " Work area for temporary
                                               " field catalog
        lv_colpos   type i, " To store the column position
        lv_colpos1  type i, " To store the column position
        lv_layout1  type slis_layout_alv. " Work Area for Layout

  clear i_fieldcat1.
  refresh i_fieldcat1.

  call function 'REUSE_ALV_LIST_LAYOUT_INFO_GET'
    importing
      es_layout     = lv_layout1
      et_fieldcat   = i_fieldcat1
    exceptions
      no_infos      = 1
      program_error = 2
      others        = 3.

  if sy-subrc <> 0.
    message id sy-msgid type sy-msgty number sy-msgno
            with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.

  clear: lv_colpos1, lv_colpos.
  lv_colpos1 = 2.
  lv_colpos  = 2.

*--- After changing the field catalog of PO details, user can get the
*---  list of SO & Line item details  in Hierarchical list form by
*---  clicking only on the Purchase Order number.
  loop at i_fieldcat1 into lv_fieldcat.
    if lv_fieldcat-no_out <> 'X'.
      lv_colpos1 = lv_colpos1 + lv_fieldcat-outputlen + 1.
      if lv_fieldcat-fieldname = 'BSTKD'.
        if  sy-cucol >= lv_colpos and sy-cucol <= lv_colpos1.
          perform display_so_se_details using v_selfield_value.
          clear v_selfield_value.
          exit.
        endif.
      endif.
      lv_colpos = lv_colpos + lv_fieldcat-outputlen + 1.
    endif.
  endloop.
endform.                    " DISPLAY_SECONDARY_LIST

*&---------------------------------------------------------------------*
*&      Form  MODIFY_FIELDCAT_HIRARCHICAL2
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
form modify_fieldcat_hirarchical2 .

 loop at it_fieldcat3 into wa_fieldcat1.
    case wa_fieldcat1-fieldname.
      when 'VBELN' .
        wa_fieldcat1-outputlen = 20.
        wa_fieldcat1-seltext_m = 'SD Doc'(014).
        wa_fieldcat1-ddictxt   = 'M'.
      when 'VDATU' .
        wa_fieldcat1-outputlen = 20.
        wa_fieldcat1-seltext_m = 'Req.Dlv.Dt'(015).
        wa_fieldcat1-ddictxt   = 'M'.
      when 'ERDAT' .
        wa_fieldcat1-outputlen = 20.
        wa_fieldcat1-seltext_m = 'Rec Created Date'(016).
        wa_fieldcat1-ddictxt   = 'M'.
      when 'LFGSK' .
        wa_fieldcat1-outputlen = 20.
        wa_fieldcat1-seltext_m = 'Dlv Status'(017).
        wa_fieldcat1-ddictxt   = 'M'.
      when 'CHECK'.
        wa_fieldcat1-no_out    = 'X'.
    endcase .
    modify it_fieldcat3 from wa_fieldcat1.
  endloop.

endform.                    " MODIFY_FIELDCAT_HIRARCHICAL2

Former Member
0 Kudos

&----


*& Report ZALV *

*& *

&----


*& *

*& *

&----


report zalv.

*-- Table declaration

tables: mkpf,ekko.

*-- types declaration

*-- for GR numbers

types: begin of t_mkpf_gr,

mblnr type mkpf-mblnr,

mjahr type mkpf-mjahr,

end of t_mkpf_gr.

types: begin of t_mseg_gr,

mblnr type mkpf-mblnr,

matnr type mseg-matnr,

lifnr type mseg-lifnr,

erfmg type mseg-erfmg,

erfme type mseg-erfme,

ebeln type mseg-ebeln,

ebelp type mseg-ebelp,

smbln type mseg-smbln,

end of t_mseg_gr.

types: begin of t_makt_txt,

matnr type mseg-matnr,

maktx type makt-maktx,

end of t_makt_txt.

types: begin of t_lfa1,

lifnr type lfa1-lifnr,

name1 type lfa1-name1,

land1 type lfa1-land1,

end of t_lfa1.

types: begin of t_eikp,

exnum type eikp-exnum,

expvz type eikp-expvz,

zolla type eikp-zolla,

pronu type eikp-pronu,

proda type eikp-proda,

kzgbe type eikp-kzgbe,

vorpa type eikp-vorpa,

vorda type eikp-vorda,

kzabe type eikp-kzabe,

refnr type eikp-refnr,

end of t_eikp.

types: begin of t_ekko,

ebeln type mseg-ebeln,

ekgrp type ekko-ekgrp,

waers type ekko-waers,

wkurs type ekko-wkurs,

inco1 type ekko-inco1,

knumv type ekko-knumv,

end of t_ekko.

types: begin of t_konv,

knumv type konv-knumv,

kschl type konv-kschl,

kbetr type konv-kbetr,

kwert type konv-kwert,

end of t_konv.

types: begin of t_t685t,

kschl type konv-kschl,

vtext type t685t-vtext,

end of t_t685t.

types :begin of t_final_tab,

mblnr type mseg-mblnr,

matnr type mseg-matnr,

lifnr type mseg-lifnr,

erfmg type mseg-erfmg,

erfme type mseg-erfme,

maktx type makt-maktx,

name1 type lfa1-name1,

ebeln type ekko-ebeln,

ekgrp type ekko-ekgrp,

waers type ekko-waers,

wkurs type ekko-wkurs,

inco1 type ekko-inco1,

knumv type ekko-knumv,

exnum type eikp-exnum,

expvz type eikp-expvz,

zolla type eikp-zolla,

pronu type eikp-pronu,

proda type eikp-proda,

kzgbe type eikp-kzgbe,

vorpa type eikp-vorpa,

vorda type eikp-vorda,

kzabe type eikp-kzabe,

end of t_final_tab.

types :begin of t_po_data,

knumv type konv-knumv,

vtext type t685t-vtext,

kschl type konv-kschl,

kbetr type konv-kbetr,

kwert type konv-kwert,

end of t_po_data.

*-- Declaration of Type Groups

type-pools : slis.

data : i_fldcat_head type slis_t_fieldcat_alv,

wa_fldcat_head type slis_fieldcat_alv.

data : i_events type slis_t_event,

wa_event like line of i_events.

data : wa_layout type slis_layout_alv.

data: it_sort type slis_sortinfo_alv occurs 0 with header line.

data: begin of it_dele occurs 0,

mblnr type mseg-mblnr,

smbln type mseg-smbln,

end of it_dele.

*-- Internal Table Declaration

*-- for MKPF GR Numbers

data :it_mkpf_gr type standard table of t_mkpf_gr with header line.

data :it_mseg_gr type standard table of t_mseg_gr with header line.

data: it_makt_txt type standard table of t_makt_txt with header line.

data :it_eikp type standard table of t_eikp with header line.

data :it_ekko type standard table of t_ekko with header line.

data :it_lfa1 type standard table of t_lfa1 with header line.

data :it_konv type standard table of t_konv with header line.

data :it_t685t type standard table of t_t685t with header line.

data :it_final_tab type standard table of t_final_tab with header line.

data :it_po_data type standard table of t_po_data with header line.

types : begin of t_final_tab1.

include structure it_final_tab.

types: vtext type t685t-vtext,

kschl type konv-kschl,

kbetr type konv-kbetr,

kwert type konv-kwert,

end of t_final_tab1.

*data :it_final_tab1 type standard table of t_final_tab1 with header

*line.

data: begin of it_final_tab1 occurs 0,

mblnr like mseg-mblnr,

matnr like mseg-matnr,

  • lifnr LIKE mseg-lifnr,

erfmg like mseg-erfmg,

erfme like mseg-erfme,

maktx like makt-maktx,

name1 like lfa1-name1,

ebeln like ekko-ebeln,

  • ekgrp LIKE ekko-ekgrp,

waers like ekko-waers,

wkurs like ekko-wkurs,

inco1 like ekko-inco1,

  • knumv LIKE ekko-knumv,

  • exnum LIKE eikp-exnum,

expvz like eikp-expvz,

zolla like eikp-zolla,

pronu like eikp-pronu,

proda like eikp-proda,

kzgbe like eikp-kzgbe,

vorpa like eikp-vorpa,

vorda like eikp-vorda,

kzabe like eikp-kzabe,

  • vtext LIKE t685t-vtext,

kschl like konv-kschl,

kbetr like konv-kbetr,

kwert like konv-kwert,

end of it_final_tab1.

*-- declaration of variables

data : v_repid type sy-repid.

*-- Selection Screen Design

*-- for selection screen.

selection-screen : begin of block blk.

select-options: s_budat for mkpf-budat.

select-options: s_mjahr for mkpf-mjahr.

select-options: s_ekgrp for ekko-ekgrp.

selection-screen : end of block blk.

*-- for initialiing ALV Process.

initialization.

perform initalize_alv_process.

*-- START-OF SELECTION.

start-of-selection.

*--Processing the Data for ALV

perform get_data.

*--Getting the ALV Events

perform get_events.

*--Doing sorting

perform do_sort.

*--Setting the LAYOUT for ALV

perform set_layout.

*--Setting the FIELD CATALOG for ALV

perform set_fldcat_i_head.

*-- END-OF-SELECTION

end-of-selection.

*--Generating the ALV GRID DISPLAY

perform <b>list</b>_display.

----


  • --> p1 text

  • <-- p2 text

----


form get_data.

*-- for GR Numbers

perform gr_numbers.

*-- for data processing.

perform process_data.

endform. " GET_DATA

&----


*& Form gr_numbers

&----


  • Getting GR Numbers

----


form gr_numbers.

select mblnr

mjahr

from mkpf

into table it_mkpf_gr

where budat in s_budat

and mjahr in s_mjahr

and vgart = 'WE'.

sort it_mkpf_gr by mblnr.

*

*select mblnr

  • matnr

  • lifnr

  • erfmg

  • erfme

  • ebeln

  • ebelp

  • smbln

  • from mseg

  • into table it_mseg_gr

  • for all entries in it_mkpf_gr

  • where mblnr = it_mkpf_gr-mblnr

  • and MJAHR = it_mkpf_gr-mjahr.

select mg~mblnr

mg~matnr

mg~lifnr

mg~erfmg

mg~erfme

mg~ebeln

mg~ebelp

mg~smbln

from mseg as mg

join lfa1 as lf

on mglifnr = lflifnr

into table it_mseg_gr

for all entries in it_mkpf_gr

where mg~mblnr = it_mkpf_gr-mblnr

and mg~mjahr = it_mkpf_gr-mjahr

and mg~bukrs = '0373'

and lf~land1 ne 'IN'.

sort it_mseg_gr by mblnr matnr.

clear: it_mseg_gr.

loop at it_mseg_gr where smbln ne ' '.

it_dele-mblnr = it_mseg_gr-smbln.

append it_dele.

clear it_dele.

delete it_mseg_gr.

endloop.

clear: it_mseg_gr.

sort it_mseg_gr by mblnr matnr.

sort it_dele by mblnr.

loop at it_mseg_gr.

read table it_dele with key mblnr = it_mseg_gr-mblnr.

if sy-subrc = 0.

delete it_mseg_gr.

endif.

endloop.

sort it_mseg_gr by mblnr matnr.

select matnr

maktx

from makt

into table it_makt_txt

for all entries in it_mseg_gr

where matnr = it_mseg_gr-matnr

and spras = 'EN'.

sort it_makt_txt by matnr.

select ebeln

ekgrp

waers

wkurs

inco1

knumv

from ekko

into table it_ekko

for all entries in it_mseg_gr

where ebeln = it_mseg_gr-ebeln

and ekgrp in s_ekgrp

and loekz = ' '.

sort it_ekko by ebeln.

select exnum

expvz

zolla

pronu

proda

kzgbe

vorpa

vorda

kzabe

refnr

from eikp

into table it_eikp

for all entries in it_mseg_gr

where refnr = it_mseg_gr-ebeln.

sort it_eikp by refnr.

  • T685T-VTEXT

select knumv

kschl

kbetr

kwert

from konv

into table it_konv

for all entries in it_ekko

where knumv = it_ekko-knumv.

select kschl

vtext

from t685t

into table it_t685t

for all entries in it_konv

where kschl = it_konv-kschl

and spras = 'EN'

and kappl = 'M'.

loop at it_konv.

it_po_data-knumv = it_konv-knumv.

read table it_t685t with key kschl = it_konv-kschl.

if sy-subrc = 0.

it_po_data-vtext = it_t685t-vtext.

endif.

read table it_ekko with key knumv = it_konv-knumv.

if sy-subrc = 0.

it_po_data-kschl = it_konv-kschl.

it_po_data-kbetr = it_konv-kbetr.

it_po_data-kwert = it_konv-kwert.

append it_po_data.

clear it_po_data.

endif.

endloop.

endform. " gr_numbers

&----


*& Form process_data

&----


  • Processing the Data

----


form process_data.

loop at it_mseg_gr.

it_final_tab-mblnr = it_mseg_gr-mblnr.

it_final_tab-matnr = it_mseg_gr-matnr.

it_final_tab-lifnr = it_mseg_gr-lifnr.

it_final_tab-erfmg = it_mseg_gr-erfmg.

it_final_tab-erfme = it_mseg_gr-erfme.

read table it_makt_txt with key matnr = it_mseg_gr-matnr.

if sy-subrc = 0.

it_final_tab-maktx = it_makt_txt-maktx.

endif.

read table it_lfa1 with key lifnr = it_mseg_gr-lifnr.

if sy-subrc = 0.

it_final_tab-name1 = it_lfa1-name1.

endif.

read table it_ekko with key ebeln = it_mseg_gr-ebeln.

if sy-subrc = 0.

it_final_tab-ebeln = it_ekko-ebeln.

it_final_tab-ekgrp = it_ekko-ekgrp.

it_final_tab-waers = it_ekko-waers.

it_final_tab-wkurs = it_ekko-wkurs.

it_final_tab-inco1 = it_ekko-inco1.

it_final_tab-knumv = it_ekko-knumv.

endif.

read table it_eikp with key refnr = it_mseg_gr-ebeln.

if sy-subrc = 0.

it_final_tab-exnum = it_eikp-exnum.

it_final_tab-expvz = it_eikp-expvz.

it_final_tab-zolla = it_eikp-zolla.

it_final_tab-pronu = it_eikp-pronu.

it_final_tab-proda = it_eikp-proda.

it_final_tab-kzgbe = it_eikp-kzgbe.

it_final_tab-vorpa = it_eikp-vorpa.

it_final_tab-vorda = it_eikp-vorda.

it_final_tab-kzabe = it_eikp-kzabe.

endif.

append it_final_tab.

clear it_final_tab.

endloop.

sort it_final_tab by knumv.

loop at it_konv.

it_po_data-knumv = it_konv-knumv.

read table it_t685t with key kschl = it_konv-kschl.

if sy-subrc = 0.

it_po_data-vtext = it_t685t-vtext.

endif.

read table it_ekko with key knumv = it_konv-knumv.

if sy-subrc = 0.

it_po_data-kschl = it_konv-kschl.

it_po_data-kbetr = it_konv-kbetr.

it_po_data-kwert = it_konv-kwert.

append it_po_data.

clear it_po_data.

endif.

endloop.

loop at it_po_data.

read table it_final_tab with key knumv = it_po_data-knumv.

if sy-subrc = 0.

it_final_tab1-mblnr = it_final_tab-mblnr.

it_final_tab1-matnr = it_final_tab-matnr.

  • it_final_tab1-lifnr = it_final_tab-lifnr.

it_final_tab1-erfmg = it_final_tab-erfmg.

it_final_tab1-erfme = it_final_tab-erfme.

it_final_tab1-maktx = it_final_tab-maktx.

it_final_tab1-name1 = it_final_tab-name1.

it_final_tab1-ebeln = it_final_tab-ebeln.

  • it_final_tab1-ekgrp = it_final_tab-ekgrp.

it_final_tab1-waers = it_final_tab-waers.

it_final_tab1-wkurs = it_final_tab-wkurs.

it_final_tab1-inco1 = it_final_tab-inco1.

  • it_final_tab1-knumv = it_final_tab-knumv.

  • it_final_tab1-exnum = it_final_tab-exnum.

it_final_tab1-expvz = it_final_tab-expvz.

it_final_tab1-zolla = it_final_tab-zolla.

it_final_tab1-pronu = it_final_tab-pronu.

it_final_tab1-proda = it_final_tab-proda.

it_final_tab1-kzgbe = it_final_tab-kzgbe.

it_final_tab1-vorpa = it_final_tab-vorpa.

it_final_tab1-vorda = it_final_tab-vorda.

it_final_tab1-kzabe = it_final_tab-kzabe.

endif.

  • it_final_tab1-knumv = it_po_data-knumv.

  • it_final_tab1-vtext = it_po_data-vtext.

it_final_tab1-kschl = it_po_data-kschl.

it_final_tab1-kbetr = it_po_data-kbetr.

it_final_tab1-kwert = it_po_data-kwert.

append it_final_tab1.

clear it_final_tab1.

endloop.

sort it_final_tab1 by mblnr ebeln kschl.

*format color col_normal intensified off inverse off.

*uline (396).

*loop at it_final_tab1.

*write:/ sy-vline,

  • it_final_tab1-MATNR,sy-vline,

  • it_final_tab1-maktx,sy-vline,

  • it_final_tab1-ERFMG,sy-vline,

  • it_final_tab1-ERFME,sy-vline,

  • it_final_tab1-MBLNR,sy-vline,

  • it_final_tab1-ZOLLA,sy-vline,

  • it_final_tab1-EXPVZ,sy-vline,

  • it_final_tab1-EBELN,sy-vline,

  • it_final_tab1-name1,sy-vline,

  • it_final_tab1-PRONU,sy-vline,

  • it_final_tab1-PRODA,sy-vline,

  • it_final_tab1-inco1,sy-vline,

  • it_final_tab1-kschl,sy-vline,

  • it_final_tab1-kbetr,sy-vline,

  • it_final_tab1-kwert,sy-vline,

  • it_final_tab1-waers,sy-vline,

  • it_final_tab1-KZGBE,sy-vline,

  • it_final_tab1-VORPA,sy-vline,

  • it_final_tab1-VORDA,sy-vline,

  • it_final_tab1-wkurs,sy-vline,

  • it_final_tab1-KZABE,sy-vline.

    • it_final_tab1-LIFNR,sy-vline,

    • it_final_tab1-EKGRP,sy-vline,

    • it_final_tab1-knumv,sy-vline,

    • it_final_tab1-EXNUM,sy-vline,

    • it_final_tab1-knumv,sy-vline.

    • it_final_tab1-vtext,sy-vline,

*endloop.

*format reset.

*new-line.

*uline (396).

endform. " process_data

&----


*& Form INITALIZE_ALV_PROCESS

&----


  • Basic Initialization for ALV

----


form initalize_alv_process.

v_repid = sy-repid.

endform. " INITALIZE_ALV_PROCESS

&----


*& <b> Form LIST_DISPLAY</b>

&----


  • Generating the ALV GRID DISPLAY

----


<b>form list_display .</b>

<b> call function 'REUSE_ALV_LIST_DISPLAY'</b>

exporting

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

i_callback_program = v_repid

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

  • I_CALLBACK_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME =

  • I_BACKGROUND_ID = ' '

  • I_GRID_TITLE = ' '

  • I_GRID_SETTINGS =

is_layout = wa_layout

it_fieldcat = i_fldcat_head[]

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

it_sort = it_sort[]

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

it_events = i_events[]

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • IT_ALV_GRAPHICS =

  • IT_HYPERLINK =

  • IT_ADD_FIELDCAT =

  • IT_EXCEPT_QINFO =

  • I_HTML_HEIGHT_TOP =

  • I_HTML_HEIGHT_END =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

tables

t_outtab = it_final_tab1

exceptions

program_error = 1

others = 2

.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

endform. " LIST_DISPLAY

&----


*& Form SET_FLDCAT_I_HEAD

&----


  • Generating the Field Catalog

----


form set_fldcat_i_head .

call function 'REUSE_ALV_FIELDCATALOG_MERGE'

exporting

i_program_name = v_repid

i_internal_tabname = 'IT_FINAL_TAB1'

  • I_STRUCTURE_NAME =

  • I_CLIENT_NEVER_DISPLAY = 'X'

i_inclname = v_repid

  • I_BYPASSING_BUFFER =

  • I_BUFFER_ACTIVE =

changing

ct_fieldcat = i_fldcat_head

  • EXCEPTIONS

  • INCONSISTENT_INTERFACE = 1

  • PROGRAM_ERROR = 2

  • OTHERS = 3

.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

loop at i_fldcat_head into wa_fldcat_head.

case wa_fldcat_head-fieldname.

when 'MATNR'.

wa_fldcat_head-col_pos = '1'.

wa_fldcat_head-just = 'C'.

wa_fldcat_head-outputlen = '18'.

wa_fldcat_head-seltext_m = 'Material Code'. "middle key word

wa_fldcat_head-ddictxt = 'M'.

wa_fldcat_head-ref_tabname = ' '.

when 'MAKTX'.

wa_fldcat_head-col_pos = '2'.

wa_fldcat_head-outputlen = '40'.

wa_fldcat_head-seltext_s = 'Item Name'.

wa_fldcat_head-ddictxt = 'M'.

when 'ERFMG'.

wa_fldcat_head-col_pos = '3'.

wa_fldcat_head-outputlen = '17'.

wa_fldcat_head-seltext_l = 'Quantity'.

wa_fldcat_head-ddictxt = 'L'.

when 'ERFME'.

wa_fldcat_head-col_pos = '4'.

wa_fldcat_head-outputlen = '3'.

wa_fldcat_head-seltext_l = 'Unit'.

wa_fldcat_head-ddictxt = 'L'.

when 'MBLNR'.

wa_fldcat_head-col_pos = '5'.

wa_fldcat_head-outputlen = '10'.

wa_fldcat_head-seltext_l = 'GRN No'.

wa_fldcat_head-ddictxt = 'L'.

wa_fldcat_head-key = ' '.

  • WA_FLDCAT_HEAD-DO_SUM = 'X'.

when 'ZOLLA'.

wa_fldcat_head-col_pos = '6'.

wa_fldcat_head-outputlen = '13'.

wa_fldcat_head-seltext_l = 'Custom Office'.

wa_fldcat_head-ddictxt = 'L'.

when 'EXPVZ'.

wa_fldcat_head-col_pos = '7'.

wa_fldcat_head-outputlen = '16'.

wa_fldcat_head-seltext_l = 'Mode Of Shipment'.

wa_fldcat_head-ddictxt = 'L'.

when 'EBELN'.

wa_fldcat_head-col_pos = '8'.

wa_fldcat_head-outputlen = '10'.

wa_fldcat_head-seltext_l = 'PO No'.

wa_fldcat_head-ddictxt = 'L'.

wa_fldcat_head-key = ' '.

when 'NAME1'.

wa_fldcat_head-col_pos = '9'.

wa_fldcat_head-outputlen = '35'.

wa_fldcat_head-seltext_l = 'Supplier'.

wa_fldcat_head-ddictxt = 'L'.

when 'PRONU'.

wa_fldcat_head-col_pos = '10'.

wa_fldcat_head-outputlen = '25'.

wa_fldcat_head-seltext_l = 'Invoice No'.

wa_fldcat_head-ddictxt = 'L'.

when 'PRODA'.

wa_fldcat_head-col_pos = '11'.

wa_fldcat_head-outputlen = '10'.

wa_fldcat_head-seltext_l = 'Invoice Date'.

wa_fldcat_head-ddictxt = 'L'.

when 'INCO1'.

wa_fldcat_head-col_pos = '12'.

wa_fldcat_head-outputlen = '15'.

wa_fldcat_head-seltext_l = 'Price Condition'.

wa_fldcat_head-ddictxt = 'L'.

when 'KSCHL'.

wa_fldcat_head-col_pos = '13'.

wa_fldcat_head-outputlen = '14'.

wa_fldcat_head-seltext_l = 'Condition Type'.

wa_fldcat_head-ddictxt = 'L'.

when 'KBETR'.

wa_fldcat_head-col_pos = '14'.

wa_fldcat_head-outputlen = '16'.

wa_fldcat_head-seltext_l = 'Unit Rate'.

wa_fldcat_head-ddictxt = 'L'.

when 'KWERT'.

wa_fldcat_head-col_pos = '15'.

wa_fldcat_head-outputlen = '18'.

wa_fldcat_head-seltext_l = 'Condition Value'.

wa_fldcat_head-ddictxt = 'L'.

*--CALCULATING THE INVOICE TOTAL

wa_fldcat_head-do_sum = 'X'.

when 'WAERS'.

wa_fldcat_head-col_pos = '16'.

wa_fldcat_head-outputlen = '16'.

wa_fldcat_head-seltext_l = 'Invoice Currency'.

wa_fldcat_head-ddictxt = 'L'.

when 'KZGBE'.

wa_fldcat_head-col_pos = '17'.

wa_fldcat_head-outputlen = '30'.

wa_fldcat_head-seltext_l = 'AWB/BL No.'.

wa_fldcat_head-ddictxt = 'L'.

when 'VORPA'.

wa_fldcat_head-col_pos = '18'.

wa_fldcat_head-outputlen = '10'.

wa_fldcat_head-seltext_l = 'PrelDocType'.

wa_fldcat_head-ddictxt = 'L'.

when 'VORDA'.

wa_fldcat_head-col_pos = '19'.

wa_fldcat_head-outputlen = '11'.

wa_fldcat_head-seltext_l = 'AWB/BL Date'.

wa_fldcat_head-ddictxt = 'L'.

when 'WKURS'.

wa_fldcat_head-col_pos = '20'.

wa_fldcat_head-outputlen = '13'.

wa_fldcat_head-seltext_l = 'Exchange Rate'.

wa_fldcat_head-ddictxt = 'L'.

when 'KZABE'.

wa_fldcat_head-col_pos = '21'.

wa_fldcat_head-outputlen = '30'.

wa_fldcat_head-seltext_l = 'Arrival of Consignment'.

wa_fldcat_head-ddictxt = 'L'.

endcase.

modify i_fldcat_head from wa_fldcat_head index sy-tabix.

endloop.

endform. " SET_FLDCAT_I_HEAD

&----


*& Form SET_LAYOUT

&----


  • Setting the Layout

----


form set_layout .

  • wa_layout-detail_popup = 'X'.

wa_layout-colwidth_optimize = 'X'.

wa_layout-zebra = 'X'.

wa_layout-totals_text = 'Totals'.

wa_layout-subtotals_text = 'Sub Totals'.

endform. " SET_LAYOUT

&----


*& Form GET_EVENTS

&----


  • Calling a Form when Top of page event triggers

----


form get_events .

call function 'REUSE_ALV_EVENTS_GET'

  • EXPORTING

  • I_LIST_TYPE = 0

importing

et_events = i_events

exceptions

list_type_wrong = 1

others = 2.

if sy-subrc <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

endif.

if not i_events[] is initial.

read table i_events into wa_event with key name = 'TOP_OF_PAGE'.

wa_event-form = 'GENERATE_USERCOMMAND'.

modify i_events from wa_event index sy-tabix.

endif.

endform. " GET_EVENTS

&----


*& Form GENERATE_USERCOMMAND

&----


  • Printig Header Text and Logo in Top of Page

----


form generate_usercommand .

data : i_comment type slis_t_listheader,

wa_comment type slis_listheader.

wa_comment-typ = 'H'.

wa_comment-info = 'GE BETZ - BILL OF ENTRY REPORT'.

append wa_comment to i_comment.

call function 'REUSE_ALV_COMMENTARY_WRITE'

exporting

it_list_commentary = i_comment

i_logo = 'ENJOYSAP_LOGO'

  • I_END_OF_LIST_GRID =

.

endform. " GENERATE_USERCOMMAND

&----


*& Form DO_SORT

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form do_sort .

*-- Populating the sort table

it_sort-fieldname = 'MATNR'.

it_sort-tabname = 'IT_FINAL_TAB1'.

it_sort-up = 'X'.

it_sort-subtot = 'X'.

append it_sort.

endform. " DO_SORT

former_member181962
Active Contributor
0 Kudos

Hi Yi,

See the programs,

BCALV_TEST_HIERSEQ_LIST BCALV_TEST_HIERSEQ_LIST_EVENTS

Regards,

Ravi