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: 

How to fetch data and merge into a temperory single table

Former Member
0 Kudos

Hi experts,

I have a serious issue, I want to use "HRHAP_DOCUMENT_GET_DETAIL", This FM didn't have a normal table, it uses structure and we can't use loop and read table function.

First Table: ELEMENT_DESC_TAB

Second Table: HAP_T_BO_TAB

Please guide me how can i fetch data from two tables, I want to fetch data from tables and then append it into a temporary table, after that its my choice where to use it.

below is my code

*&---------------------------------------------------------------------*

*& Report  ZTEST_SAROSH

*&

*&---------------------------------------------------------------------*

*&

*&

*&---------------------------------------------------------------------*

REPORT  ZTEST_SAROSH.

* Global Data Declaration

TABLES: HRHAP.

TYPES : BEGIN OF TY_PROJ,

        ELEMENT_DESC_TAB TYPE HAP_T_BODY_ELEMENT_DESCR,

        HAP_T_BO_TAB TYPE HAP_T_BODY_CELLS,

        END OF TY_PROJ.

*INTERNAL TABLE DEFINATION

DATA : IT_PROJ TYPE TABLE OF TY_PROJ WITH HEADER LINE,

       WA_PROJ TYPE TY_PROJ.

data: p_APPRAISALID LIKE HAP_S_APPRAISAL_ID. "DEFAUT 'LH',

*            p_connid LIKE spfli-connid DEFAULT '400'.

DATA: APPRAISAL_ID TYPE HAP_S_APPRAISAL_ID.

*      APPRAILSA_DESC TYPE c.

data: ELEMENT_DESC_TAB TYPE HAP_T_BODY_ELEMENT_DESCR,

      ABC TYPE HAP_T_BODY_ELEMENT_DESCR,

      HAP_T_BO_TAB TYPE HAP_T_BODY_CELLS.

p_APPRAISALID = '00188B3066411ED28F940BF8102A6B4C0000'.

*ALV data declarations

data: fieldcatalog type slis_t_fieldcat_alv with header line,

        gd_tab_group type slis_t_sp_group_alv,

        gd_layout    type slis_layout_alv,

        gd_repid     like sy-repid.

perform data_retrieval.

perform build_fieldcatalog.

perform build_layout.

perform display_alv_report.

form data_retrieval.

CALL FUNCTION 'HRHAP_DOCUMENT_GET_DETAIL'

  EXPORTING

*   ADD_ON_APPLICATION            =

*   MODE                          = ' '

*   UI_MODE                       = ' '

    PLAN_VERSION                  = '01'

    S_APPRAISAL_ID                = p_APPRAISALID

*   ADMINISTRATOR                 = ' '

*   S_DISPLAY_UI                  =

*   NO_ACTION_LOG                 = ' '

*   IGNORE_COLUMN_NUMBER          =

IMPORTING

*   S_DOC_PROCESSING              =

*   S_HEADER_TEXTS                =

*   T_HEADER_APPRAISER            =

*   T_HEADER_APPRAISEE            =

*   T_HEADER_PART_APPRAISER       =

*   T_HEADER_OTHERS               =

*   S_HEADER_STATUS               =

*   S_HEADER_DATES                =

*   T_HEADER_ADD_DATA             = 'dfdf'

*    S_HEADER_DISPLAY              = 'APPRAISAL_ID'

*   T_BUTTONS                     =

*   T_BODY_COLUMNS                =

*    T_BODY_ELEMENTS               = 'DESC'

*   T_BODY_ELEMENT_BUTTONS        =

   T_BODY_ELEMENT_DESCR          = ELEMENT_DESC_TAB

   T_BODY_CELLS                  = HAP_T_BO_TAB

*   T_BODY_CELL_VAL_VALUES        =

*   T_BODY_CELL_VAL_RANGES        =

*   T_BODY_CELL_VAL_C_LIKE        =

*   T_BODY_CELL_VAL_DESCR         =

*   T_BODY_CELL_NOTES             =

*   T_STATUS_NOTES                =

*   T_STATUS_DESCRIPTION          =

*   S_RETURN                      =

          .

LOOP AT ELEMENT_DESC_TAB INTO ABC.

READ TABLE HAP_T_BO_TAB WITH KEY ROW_IID = ELEMENT_DESC_TAB-ROW_IID. " VALUE_NUM <> 0.

ENDLOOP.

CASE sy-subrc.

   WHEN 1.

       WRITE 'No data available'.

       EXIT.

ENDCASE.

ENDFORM.

*&---------------------------------------------------------------------*

*&      Form  BUILD_FIELDCATALOG

*&---------------------------------------------------------------------*

*       Build Fieldcatalog for ALV Report

*----------------------------------------------------------------------*

*VSNO = VSNO + 1.

*     it_proj-SNO = VSNO.

form build_fieldcatalog.

    fieldcatalog-fieldname   = 'ELEMENT_DESC_TAB'.

    fieldcatalog-seltext_m   = 'Decsription'.

    fieldcatalog-col_pos     = 1.

    fieldcatalog-outputlen   = 10.

    fieldcatalog-emphasize   = 'C170'.

    fieldcatalog-key         = 'X'.

    fieldcatalog-do_sum      = 'X'.

    fieldcatalog-no_zero     = 'X'.

    append fieldcatalog to fieldcatalog.

    clear  fieldcatalog.

    fieldcatalog-fieldname   = 'HAP_T_BO_TAB'.

    fieldcatalog-seltext_m   = 'No'.

    fieldcatalog-col_pos     = 2.

    fieldcatalog-outputlen   = 10.

    fieldcatalog-emphasize   = 'C170'.

    fieldcatalog-key         = 'X'.

    fieldcatalog-do_sum      = 'X'.

    fieldcatalog-no_zero     = 'X'.

    append fieldcatalog to fieldcatalog.

    clear  fieldcatalog.

endform.                    " BUILD_FIELDCATALOG

*&---------------------------------------------------------------------*

*&      Form  BUILD_LAYOUT

*&---------------------------------------------------------------------*

*       Build layout for ALV grid report

*----------------------------------------------------------------------*

form build_layout.

    gd_layout-no_input          = 'X'.

    gd_layout-colwidth_optimize = 'X'.

    gd_layout-totals_text       = 'Totals'(201).

    gd_layout-totals_only        = 'X'.

    gd_layout-f2code            = 'DISP'.  "Sets fcode for when double

*                                         "click(press f2)

    gd_layout-zebra             = 'X'.

    gd_layout-group_change_edit = 'X'.

    gd_layout-header_text       = 'helllllo'.

    gd_layout-expand_fieldname = 'EXPAND'.

    gd_layout-window_titlebar = 'Hierarchical ALV list display'.

    gd_layout-lights_tabname = 'IT_PROJ'.

    gd_layout-colwidth_optimize = 'X'.

endform.                    " BUILD_LAYOUT

*&---------------------------------------------------------------------*

*&      Form  DISPLAY_ALV_REPORT

*&---------------------------------------------------------------------*

*       Display report using ALV grid

*----------------------------------------------------------------------*

form display_alv_report.

    gd_repid = sy-repid.

    call function 'REUSE_ALV_LIST_DISPLAY'

         exporting

              i_callback_program      = gd_repid

*            i_callback_top_of_page   = 'TOP_OF_PAGE'  "see FORM

*            i_callback_user_command = 'USER_COMMAND'

*            i_grid_title           = outtext

              is_layout               = gd_layout

              it_fieldcat             = fieldcatalog[]

              it_special_groups       = gd_tab_group

*            IT_EVENTS                = GT_XEVENTS

              i_save                  = 'X'

*            is_variant              = z_template

         tables

              t_outtab                = IT_PROJ

*            t_outtabnew                = it_prps

         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.                    " DISPLAY_ALV_REPORT

*-------------------------------------------------------------------*

* Form  TOP-OF-PAGE                                                 *

*-------------------------------------------------------------------*

* ALV Report Header                                                 *

*-------------------------------------------------------------------*

* Handling Exceptions

* Displaying Results

*WRITE:/ "ELEMENT_DESC_TAB,

*      HAP_T_BO_TAB.

*       ELEMENTS.

Regards

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

HAP_T_BODY_ELEMENT_DESCR and HAP_T_BO_TAB are not just structures these are internal tables because the data type is a table type. so you can use loop at and read statements to read the data into a separate internal table having all the fields necessary.

thanks.

15 REPLIES 15

Former Member
0 Kudos

Hi

First get all the appraisal id into an internal table and loop the FM

and then append each record into ur table..

Hope this helps

Regards

0 Kudos

Hi,

I have tried in my code, but didn't get results can you suggest me with the code

Former Member
0 Kudos

Hi,

HAP_T_BODY_ELEMENT_DESCR and HAP_T_BO_TAB are not just structures these are internal tables because the data type is a table type. so you can use loop at and read statements to read the data into a separate internal table having all the fields necessary.

thanks.

0 Kudos

Hi,

I have tried loop statement but didn't getting the results, can you guide me using code

0 Kudos

Create an internal table with fields required from both the tables. You have a common field ROW_IID  so

Loop at first table into wa.

read second table into wa2 with key row_iid = wa-row_iid.

if sy-subrc = 0.

populate wa of temp internal table and append to it.

endif.

endloop.

hope this helps you.

0 Kudos

Hi Sarosh,

The work area ABC you have declared is of type HAP_T_BODY_ELEMENT_DESCR which is a table type so u cannot loop into this type. Please declare ABC of type HAP_S_BODY_ELEMENT_DESCR.

DATA: ABC TYPE HAP_S_BODY_ELEMENT_DESCR.

Hope this works.

Regards,

Shanth

0 Kudos

Hi,

thanks for help, How can i incorporate changes in my program

0 Kudos

declare ABC as type HAP_S_BODY_ELEMENT_DESCR.

declare XYZ as type HAP_S_BODY_CELLS.

hey create a table with all the fields you need to store into.

LOOP AT ELEMENT_DESC_TAB into ABC.

READ TABLE HAP_T_BO_TAB into XYZ with key row_iid = ABC-row_iid.

wa_proj-hap_t_body_element = ABC.

wa_proj-hap_t_bo_tab = xyz.

append wa_proj to it_proj.

endloop.


0 Kudos

Hi,

I have done this now how to get data in table?

0 Kudos

what have you done changes in your code?

0 Kudos

*&---------------------------------------------------------------------*
*& Report  ZTEST_SAROSH
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT  ZTEST_SAROSH.
* Global Data Declaration
TABLES: HRHAP.

TYPES: BEGIN OF MY_FIELDS,

ROW_IID type HAP_S_BODY_ELEMENT_DESCR-ROW_IID,

TLINE type HAP_S_BODY_ELEMENT_DESCR-TLINE,

  END OF MY_FIELDS.



TYPES : BEGIN OF TY_PROJ,
         ELEMENT_DESC_TAB TYPE HAP_T_BODY_ELEMENT_DESCR,
         HAP_T_BO_TAB TYPE HAP_T_BODY_CELLS,
         END OF TY_PROJ.

*INTERNAL TABLE DEFINATION
DATA : IT_PROJ TYPE TABLE OF TY_PROJ WITH HEADER LINE,
*      MY_FIELDS TYPE TABLE OF ELEMENT_DESC_TAB,
        WA_PROJ TYPE TY_PROJ.

data: p_APPRAISALID LIKE HAP_S_APPRAISAL_ID. "DEFAUT 'LH',
*            p_connid LIKE spfli-connid DEFAULT '400'.
DATA: APPRAISAL_ID TYPE HAP_S_APPRAISAL_ID.
*      APPRAILSA_DESC TYPE c.

data: ELEMENT_DESC_TAB TYPE HAP_S_BODY_ELEMENT_DESCR,
       ABC TYPE HAP_S_BODY_ELEMENT_DESCR,
       XYZ TYPE HAP_S_BODY_CELLS,
       HAP_T_BO_TAB TYPE HAP_T_BODY_CELLS.

p_APPRAISALID = '00188B3066411ED28F940BF8102A6B4C0000'.

*ALV data declarations
data: fieldcatalog type slis_t_fieldcat_alv with header line,
         gd_tab_group type slis_t_sp_group_alv,
         gd_layout    type slis_layout_alv,
         gd_repid     like sy-repid.


perform data_retrieval.
perform build_fieldcatalog.
perform build_layout.
perform display_alv_report.

form data_retrieval.

CALL FUNCTION 'HRHAP_DOCUMENT_GET_DETAIL'
   EXPORTING
*   ADD_ON_APPLICATION            =
*   MODE                          = ' '
*   UI_MODE                       = ' '
     PLAN_VERSION                  = '01'
     S_APPRAISAL_ID                = p_APPRAISALID
*   ADMINISTRATOR                 = ' '
*   S_DISPLAY_UI                  =
*   NO_ACTION_LOG                 = ' '
*   IGNORE_COLUMN_NUMBER          =
  IMPORTING
*   S_DOC_PROCESSING              =
*   S_HEADER_TEXTS                =
*   T_HEADER_APPRAISER            =
*   T_HEADER_APPRAISEE            =
*   T_HEADER_PART_APPRAISER       =
*   T_HEADER_OTHERS               =
*   S_HEADER_STATUS               =
*   S_HEADER_DATES                =
*   T_HEADER_ADD_DATA             = 'dfdf'
*    S_HEADER_DISPLAY              = 'APPRAISAL_ID'
*   T_BUTTONS                     =
*   T_BODY_COLUMNS                =
*    T_BODY_ELEMENTS               = 'DESC'
*   T_BODY_ELEMENT_BUTTONS        =
    T_BODY_ELEMENT_DESCR          = ELEMENT_DESC_TAB
    T_BODY_CELLS                  = HAP_T_BO_TAB
*   T_BODY_CELL_VAL_VALUES        =
*   T_BODY_CELL_VAL_RANGES        =
*   T_BODY_CELL_VAL_C_LIKE        =
*   T_BODY_CELL_VAL_DESCR         =
*   T_BODY_CELL_NOTES             =
*   T_STATUS_NOTES                =
*   T_STATUS_DESCRIPTION          =
*   S_RETURN                      =
.


LOOP AT MY_FIELDS into ABC.
*LOOP AT ELEMENT_DESC_TAB INTO ABC.
*READ TABLE HAP_T_BO_TAB WITH KEY ROW_IID = ELEMENT_DESC_TAB-ROW_IID. " VALUE_NUM <> 0.
*ENDLOOP.

READ TABLE HAP_T_BO_TAB into XYZ with key row_iid = ABC-row_iid.
wa_proj-hap_t_body_element = ABC.
wa_proj-hap_t_bo_tab = xyz.
append wa_proj to it_proj.
endloop.

CASE sy-subrc.
    WHEN 1.
        WRITE 'No data available'.
        EXIT.
ENDCASE.
ENDFORM.
*&---------------------------------------------------------------------*
*&      Form  BUILD_FIELDCATALOG
*&---------------------------------------------------------------------*
*       Build Fieldcatalog for ALV Report
*----------------------------------------------------------------------*
*VSNO = VSNO + 1.

*     it_proj-SNO = VSNO.


form build_fieldcatalog.
     fieldcatalog-fieldname   = 'ELEMENT_DESC_TAB'.
     fieldcatalog-seltext_m   = 'Decsription'.
     fieldcatalog-col_pos     = 1.
     fieldcatalog-outputlen   = 10.
     fieldcatalog-emphasize   = 'C170'.
     fieldcatalog-key         = 'X'.
     fieldcatalog-do_sum      = 'X'.
     fieldcatalog-no_zero     = 'X'.
     append fieldcatalog to fieldcatalog.
     clear  fieldcatalog.

     fieldcatalog-fieldname   = 'HAP_T_BO_TAB'.
     fieldcatalog-seltext_m   = 'No'.
     fieldcatalog-col_pos     = 2.
     fieldcatalog-outputlen   = 10.
     fieldcatalog-emphasize   = 'C170'.
     fieldcatalog-key         = 'X'.
     fieldcatalog-do_sum      = 'X'.
     fieldcatalog-no_zero     = 'X'.
     append fieldcatalog to fieldcatalog.
     clear  fieldcatalog.



endform.                    " BUILD_FIELDCATALOG

*&---------------------------------------------------------------------*
*&      Form  BUILD_LAYOUT
*&---------------------------------------------------------------------*
*       Build layout for ALV grid report
*----------------------------------------------------------------------*
form build_layout.
     gd_layout-no_input          = 'X'.
     gd_layout-colwidth_optimize = 'X'.
     gd_layout-totals_text       = 'Totals'(201).
     gd_layout-totals_only        = 'X'.
     gd_layout-f2code            = 'DISP'.  "Sets fcode for when double
*                                         "click(press f2)
     gd_layout-zebra             = 'X'.
     gd_layout-group_change_edit = 'X'.
     gd_layout-header_text       = 'helllllo'.

     gd_layout-expand_fieldname = 'EXPAND'.
     gd_layout-window_titlebar = 'Hierarchical ALV list display'.
     gd_layout-lights_tabname = 'IT_PROJ'.
     gd_layout-colwidth_optimize = 'X'.


endform.                    " BUILD_LAYOUT

*&---------------------------------------------------------------------*
*&      Form  DISPLAY_ALV_REPORT
*&---------------------------------------------------------------------*
*       Display report using ALV grid
*----------------------------------------------------------------------*
form display_alv_report.
     gd_repid = sy-repid.
     call function 'REUSE_ALV_LIST_DISPLAY'
          exporting
               i_callback_program      = gd_repid
*            i_callback_top_of_page   = 'TOP_OF_PAGE'  "see FORM
*            i_callback_user_command = 'USER_COMMAND'
*            i_grid_title           = outtext
               is_layout               = gd_layout
               it_fieldcat             = fieldcatalog[]
               it_special_groups       = gd_tab_group
*            IT_EVENTS                = GT_XEVENTS
               i_save                  = 'X'
*            is_variant              = z_template

          tables
               t_outtab                = IT_PROJ

*            t_outtabnew                = it_prps
          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.                    " DISPLAY_ALV_REPORT

*-------------------------------------------------------------------*
* Form  TOP-OF-PAGE                                                 *
*-------------------------------------------------------------------*
* ALV Report Header                                                 *
*-------------------------------------------------------------------*

* Handling Exceptions


* Displaying Results

*WRITE:/ "ELEMENT_DESC_TAB,
*      HAP_T_BO_TAB.
*       ELEMENTS.

0 Kudos

this is my code, can you please suggest me changes in this

Regards

0 Kudos

Hi,

replace your loop logic with this and try.

LOOP AT element_desc_tab into ABC.

READ TABLE HAP_T_BO_TAB into XYZ with key row_iid = ABC-row_iid.

if sy-subrc = 0.

wa_proj-hap_t_body_element = ABC.

wa_proj-hap_t_bo_tab = xyz.

append wa_proj to it_proj.

endif.

endloop.

if this doesnt work interchange the looping and reading tables because multiple values may come in hap_t_bo_tab for same row_iid.

thanks.

0 Kudos

I have tried but nor working,

Just let me know how can i get data from this FM , then put in an internal table using while loop, so i can get all records in table

CALL FUNCTION 'HRHAP_DOCUMENT_GET_DETAIL'
   EXPORTING
*   ADD_ON_APPLICATION            =
*   MODE                          = ' '
*   UI_MODE                       = ' '
     PLAN_VERSION                  = '01'
     S_APPRAISAL_ID                = p_APPRAISALID
*   ADMINISTRATOR                 = ' '
*   S_DISPLAY_UI                  =
*   NO_ACTION_LOG                 = ' '
*   IGNORE_COLUMN_NUMBER          =
  IMPORTING
*   S_DOC_PROCESSING              =
*   S_HEADER_TEXTS                =
*   T_HEADER_APPRAISER            =
*   T_HEADER_APPRAISEE            =
*   T_HEADER_PART_APPRAISER       =
*   T_HEADER_OTHERS               =
*   S_HEADER_STATUS               =
*   S_HEADER_DATES                =
*   T_HEADER_ADD_DATA             = 'dfdf'
*    S_HEADER_DISPLAY              = 'APPRAISAL_ID'
*   T_BUTTONS                     =
*   T_BODY_COLUMNS                =
*    T_BODY_ELEMENTS               = 'DESC'
*   T_BODY_ELEMENT_BUTTONS        =
    T_BODY_ELEMENT_DESCR          = ELEMENT_DESC_TAB
    T_BODY_CELLS                  = HAP_T_BO_TAB
*   T_BODY_CELL_VAL_VALUES        =
*   T_BODY_CELL_VAL_RANGES        =
*   T_BODY_CELL_VAL_C_LIKE        =
*   T_BODY_CELL_VAL_DESCR         =
*   T_BODY_CELL_NOTES             =
*   T_STATUS_NOTES                =
*   T_STATUS_DESCRIPTION          =
*   S_RETURN                      =
.


LOOP AT MY_FIELDS into ABC.
*LOOP AT ELEMENT_DESC_TAB INTO ABC.
*READ TABLE HAP_T_BO_TAB WITH KEY ROW_IID = ELEMENT_DESC_TAB-ROW_IID. " VALUE_NUM <> 0.
*ENDLOOP.

0 Kudos

Are you getting data into ELEMENT_DESC_TAB and HAP_T_BO_TAB? check in debugger. if so.. the code i mentioned should works fine.