12-11-2019 8:05 AM
TABLE : VBRP
The quantities of the material are not displaying as per original table
INPUT
INVOICE(VBELN) ________ TO ___________
My output:
My source code :
REPORT ZALV_DYNAMIC.
TYPE-POOLS: slis.
TABLES: vbrp.
TYPES : BEGIN OF ts_vbrp,
vbeln TYPE vbrp-vbeln,
fklmg TYPE vbrp-fklmg,
matnr TYPE vbrp-matnr,
END OF ts_vbrp.
DATA:
* Internal tables
i_data TYPE STANDARD TABLE OF ts_vbrp,
i_data_temp TYPE STANDARD TABLE OF ts_vbrp,
i_fcat TYPE lvc_t_fcat,
i_dynamic_table TYPE REF TO data,
i_fieldcat TYPE slis_t_fieldcat_alv,
* Work area
wa_fcat TYPE lvc_s_fcat,
wa_dyn_line TYPE REF TO data,
wa_data TYPE ts_vbrp,
* Variable
v_field_name TYPE fieldname,
v_tabix TYPE sy-tabix,
v_fieldname TYPE fieldname,
v_seltext TYPE scrtext_l.
*---------------------------------------------------------------------*
* Field Symbols *
*---------------------------------------------------------------------*
FIELD-SYMBOLS:
<i_dyn_table> TYPE STANDARD TABLE,
<i_final_table> TYPE STANDARD TABLE,
<wa_dyn> TYPE any,
<wa_final> TYPE any.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
SELECT-OPTIONS s_invoi FOR vbrp-vbeln.
SELECTION-SCREEN END OF BLOCK b1.
START-OF-SELECTION.
PERFORM sub_slect_data.
* Populate the dynamic columns needed for each run
PERFORM sub_populate_catlog.
*
* Build the dynamic internal table
PERFORM sub_build_int_table.
*
* Build ALF Field Catalog information
PERFORM sub_alv_field_cat.
* Display data
PERFORM sub_display_data.
*&---------------------------------------------------------------------*
*& Form SUB_SLECT_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM sub_slect_data .
SELECT vbeln
fklmg
matnr
FROM vbrp
INTO TABLE i_data
WHERE vbeln IN s_invoi.
IF sy-subrc EQ 0.
SORT i_data BY vbeln.
i_data_temp[] = i_data[].
SORT i_data_temp BY matnr.
DELETE ADJACENT DUPLICATES FROM i_data_temp
COMPARING matnr.
ENDIF.
ENDFORM. "sub_slect_data
*&---------------------------------------------------------------------*
*& Form SUB_POPULATE_CATLOG
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM sub_populate_catlog .
v_field_name = 'VBELN'.
* There is one INVOICE DOC column
PERFORM sub_pop_field_catlog USING v_field_name.
v_field_name = 'MATNR'.
* There would be 'N' number of dynamic MATERIAL columns
* depending on the INVOICE and MATNR combination
LOOP AT i_data_temp INTO wa_data.
PERFORM sub_pop_field_catlog USING v_field_name.
ENDLOOP.
ENDFORM. "sub_populate_catlog
*&---------------------------------------------------------------------*
*& Form SUB_POP_FIELD_CATLOG
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
* -->P_V_FIELD_NAME text
*&---------------------------------------------------------------------*
FORM sub_pop_field_catlog USING p_l_field_name TYPE fieldname.
DATA: l_i_dfies TYPE STANDARD TABLE OF dfies,
l_wa_dfies TYPE dfies.
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
tabname = 'VBRP'
fieldname = p_l_field_name
TABLES
dfies_tab = l_i_dfies
EXCEPTIONS
not_found = 1
internal_error = 2
OTHERS = 3.
IF sy-subrc EQ 0.
CLEAR l_wa_dfies.
READ TABLE l_i_dfies INTO l_wa_dfies INDEX 1.
CLEAR wa_fcat.
* Since we want the material number to be the header text
* Replacing the field name with actual plant value
IF v_field_name = 'MATNR'.
l_wa_dfies-fieldname = wa_data-matnr.
ENDIF.
MOVE-CORRESPONDING l_wa_dfies TO wa_fcat.
APPEND wa_fcat TO i_fcat.
ENDIF.
ENDFORM. "sub_pop_field_catlog
**&---------------------------------------------------------------------*
**& Form SUB_ALV_FIELD_CAT
**&---------------------------------------------------------------------*
**& text
**&---------------------------------------------------------------------*
**& --> p1 text
**& <-- p2 text
**&---------------------------------------------------------------------*
FORM sub_alv_field_cat .
* Build field catalog for Material
PERFORM sub_fill_alv_field_cat USING
'VBELN' '<I_DYN_TABLE>' 'L' 'Billing Doc' 20.
* Number of matnr columns would be dynamic for materials
LOOP AT i_data_temp INTO wa_data.
v_fieldname = wa_data-matnr.
v_seltext = wa_data-matnr.
PERFORM sub_fill_alv_field_cat USING
v_fieldname '<I_DYN_TABLE>' 'L' v_seltext 18.
ENDLOOP.
ENDFORM. "sub_alv_field_cat
*&---------------------------------------------------------------------*
*& Form SUB_FILL_ALV_FIELD_CAT
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
* -->P_ text
* -->P_ text
* -->P_ text
* -->P_ text
* -->P_36 text
*&---------------------------------------------------------------------*
FORM sub_fill_alv_field_cat USING
p_fldnam TYPE fieldname
p_tabnam TYPE tabname
p_justif TYPE char1
p_seltext TYPE dd03p-scrtext_l
p_outlen TYPE i.
DATA l_lfl_fcat TYPE slis_fieldcat_alv.
l_lfl_fcat-fieldname = p_fldnam.
l_lfl_fcat-tabname = p_tabnam.
l_lfl_fcat-just = p_justif.
l_lfl_fcat-seltext_l = p_seltext.
l_lfl_fcat-outputlen = p_outlen.
APPEND l_lfl_fcat TO i_fieldcat.
CLEAR l_lfl_fcat.
ENDFORM. "sub_fill_alv_field_cat
*&---------------------------------------------------------------------*
*& Form SUB_BUILD_INT_TABLE
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM sub_build_int_table .
* Prepare the dynamic internal table with required columns of each run
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = i_fcat
IMPORTING
ep_table = i_dynamic_table
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
* Assign the structure of dynamic table to field symbol
ASSIGN i_dynamic_table->* TO <i_dyn_table>.
* Create the dynamic work area
CREATE DATA wa_dyn_line LIKE LINE OF <i_dyn_table>.
ASSIGN wa_dyn_line->* TO <wa_dyn>.
ENDFORM. "sub_build_int_table
*&---------------------------------------------------------------------*
*& Form SUB_DISPLAY_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& --> p1 text
*& <-- p2 text
*&---------------------------------------------------------------------*
FORM sub_display_data.
DATA: l_count TYPE i,
l_factor TYPE i,
l_wa_layout TYPE slis_layout_alv,
I TYPE I.
LOOP AT i_data INTO wa_data.
CLEAR: l_factor, l_count.
**********NEW*************
READ TABLE i_data_temp WITH KEY MATNR = WA_DATA-MATNR
TRANSPORTING NO FIELDS
BINARY SEARCH.
IF sy-subrc EQ 0.
* <wa_dyn>+0(18) = wa_data-matnr.
<wa_dyn>+0(18) = wa_data-VBELN.
l_factor = sy-tabix - 1.
l_count = 18 + ( 36 * l_factor ).
<wa_dyn>+l_count(36) = wa_data-fklmg.
* AT END OF matnr.
AT END OF MATNR.
APPEND <wa_dyn> TO <i_dyn_table>.
CLEAR <wa_dyn>.
ENDAT.
ENDIF.
ENDLOOP.
l_wa_layout-colwidth_optimize = 'X'.
l_wa_layout-zebra = 'X'.
* Funtion module for displaying the ALV report
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
is_layout = l_wa_layout
it_fieldcat = i_fieldcat
TABLES
t_outtab = <i_dyn_table>
EXCEPTIONS
program_error = 1
OTHERS = 2.
ENDFORM.
12-19-2019 5:12 AM
The code is unreadable, sorry. I was unable to read the whole thing but there is clearly a problem when you read data from VBRP and then just delete "duplicates" from it comparing material. If there are two invoices for the same material then one of them would not be shown in the report after that. I'm having hard time imagining why would anyone want a report like that.
Overall, I don't really understand what this program is supposed to do. What's so "dynamic" about it? You read very specific data from the database, using a clearly defined structure. If you want to present this in an ALV grid then just do that.
Also, please don't use the obsolete REUSE... functions for ALV. Use SALV instead, look up demo programs in SE38 by SALV*DEMO*. There is also a lot of other obsolete techniques, please make sure to read the current ABAP guidelines in the documentation or lookup DSAG guidelines.
12-11-2019 8:31 AM
Hello Bhasker Reddy Anugu,
This is Just a Normal report, may we know what have you tried?
12-11-2019 12:41 PM
EYES WIDE OPEN
IS THAT ROBOT
OR HUMAN?
IS THAT A QUESTION?
12-11-2019 12:49 PM
I know a good programmer is a slack programmer (Namely "do not reinvent the wheel"), but here, he wants us to do his job ??? 🙂
12-13-2019 5:29 PM
Hi bhaskerreddy_anugu14 I recommend having a look at this tutorial to learn more about SAP Community Q&A and how to best ask a question to receive helpful answers.
https://developers.sap.com/tutorials/community-qa.html
Best regards,
Mynyna (SAP Community moderator)
12-19-2019 5:12 AM
The code is unreadable, sorry. I was unable to read the whole thing but there is clearly a problem when you read data from VBRP and then just delete "duplicates" from it comparing material. If there are two invoices for the same material then one of them would not be shown in the report after that. I'm having hard time imagining why would anyone want a report like that.
Overall, I don't really understand what this program is supposed to do. What's so "dynamic" about it? You read very specific data from the database, using a clearly defined structure. If you want to present this in an ALV grid then just do that.
Also, please don't use the obsolete REUSE... functions for ALV. Use SALV instead, look up demo programs in SE38 by SALV*DEMO*. There is also a lot of other obsolete techniques, please make sure to read the current ABAP guidelines in the documentation or lookup DSAG guidelines.