Application Development and Automation 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: 
Read only

Developing a report

former_member612655
Participant
0 Likes
1,614

Hi,

My requirement to develope a report where i need to display the werks,name1(plant description), lgort, lgobe, prctr fields from t001w,t001l,cepc, zmm_business tables.zmm_business table in my own table which contains werks, lgort, prctr fields.Initially i need to retrieve the data of werks, lgort,prctr fields from zmm_business tables and then combine with the standard tables to retrive the name1 and lgobe fields to display . Actually i started developing this report but i am failed to display the name1(plant description) field .Can you please provide some guidelines to develope this report.

regard,

bhavani

6 REPLIES 6
Read only

former_member199306
Participant
0 Likes
1,430

Hi Bhavani,

kindly share your code and check the data is coming in your Z table or not.

Read only

former_member612655
Participant
0 Likes
1,430

Hi Bhupendra,

I am sharing my code, what i was developed

REPORT ZMM_BUSINESS_BASE.
TABLES : ZMM_BUSINESS,T001W,T001L,CEPC.
TYPES : BEGIN OF TY_FINAL,
LGORT TYPE T001L-LGORT,
LIFNR TYPE T001L-LIFNR,
LGOBE TYPE T001L-LGOBE,
WERKS TYPE T001W-WERKS,
NAME1 TYPE T001W-NAME1,
LAND1 TYPE T001W-LAND1,
PRCTR TYPE CEPC-PRCTR,
END OF TY_FINAL.
DATA : WA_FINAL TYPE TY_FINAL,
IT_FINAL TYPE TABLE OF TY_FINAL.

TYPES : BEGIN OF TY_CEPC,
PRCTR TYPE CEPC-PRCTR,
LAND1 TYPE CEPC-LAND1,
END OF TY_CEPC.
DATA : WA_CEPC TYPE TY_CEPC,
IT_CEPC TYPE TABLE OF TY_CEPC.

TYPES : BEGIN OF TY_T001L,
LGORT TYPE T001L-LGORT,
LGOBE TYPE T001L-LGOBE,
LIFNR TYPE T001L-LIFNR,
END OF TY_T001L.
DATA : WA_T001L TYPE TY_T001L,
IT_T001L TYPE TABLE OF TY_T001L.

TYPES : BEGIN OF TY_T001W,
WERKS TYPE T001W-WERKS,
NAME1 TYPE T001W-NAME1,
LIFNR TYPE T001W-LIFNR,
LAND1 TYPE T001W-LAND1,
END OF TY_T001W.
DATA : WA_T001W TYPE TY_T001W,
IT_T001W TYPE TABLE OF TY_T001W.

TYPES : BEGIN OF TY_ZMM_BUSINESS,
WERKS TYPE WERKS_D,
LGORT TYPE LGORT_D,
PRCTR TYPE PRCTR,
END OF TY_ZMM_BUSINESS.
DATA : WA_ZMM_BUSINESS TYPE TY_ZMM_BUSINESS,
IT_ZMM_BUSINESS TYPE TABLE OF TY_ZMM_BUSINESS.

DATA : L_PROG TYPE SY-REPID,
IT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
WA_FIELDLAYOUT TYPE SLIS_LAYOUT_ALV,
WA_FIELDCAT LIKE LINE OF IT_FIELDCAT.

SELECTION-SCREEN BEGIN OF BLOCK A WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS : S_WERKS FOR T001W-WERKS,

S_LGORT FOR T001L-LGORT,

S_PRCTR FOR CEPC-PRCTR.
SELECTION-SCREEN END OF BLOCK A.

START-OF-SELECTION .
PERFORM GET_ZMM_BUSINESS.
PERFORM GET_T001W.
PERFORM GET_T001L.
PERFORM GET_CEPC.
PERFORM DIS.
PERFORM SET_FCAT.
PERFORM DISPLAY_ALV.

FORM GET_ZMM_BUSINESS.
SELECT WERKS LGORT PRCTR FROM ZMM_BUSINESS INTO TABLE IT_ZMM_BUSINESS WHERE WERKS IN S_WERKS.
ENDFORM.

FORM GET_T001L.
IF IT_ZMM_BUSINESS IS NOT INITIAL.
SELECT LGORT LGOBE LIFNR FROM T001L INTO TABLE IT_T001L FOR ALL ENTRIES IN IT_ZMM_BUSINESS WHERE LGORT = IT_ZMM_BUSINESS-LGORT.
ENDIF.
ENDFORM.

FORM GET_T001W.
IF IT_T001L IS NOT INITIAL.
SELECT WERKS NAME1 LIFNR LAND1 FROM T001W INTO
TABLE IT_T001W FOR ALL ENTRIES IN IT_T001L WHERE LIFNR = IT_T001L-LIFNR.
ENDIF.
ENDFORM.

FORM GET_CEPC.
IF IT_T001W IS NOT INITIAL.
SELECT PRCTR LAND1 FROM CEPC INTO TABLE IT_CEPC FOR ALL ENTRIES IN IT_T001W WHERE LAND1 = IT_T001W-land1.
ENDIF.
ENDFORM.

FORM DIS.
LOOP AT IT_ZMM_BUSINESS INTO WA_ZMM_BUSINESS.
WA_FINAL-WERKS = WA_ZMM_BUSINESS-WERKS.
WA_FINAL-LGORT = WA_ZMM_BUSINESS-LGORT.
WA_FINAL-PRCTR = WA_ZMM_BUSINESS-PRCTR.

LOOP AT IT_T001L INTO WA_T001L.
WA_FINAL-LGOBE = WA_T001L-LGOBE.
WA_FINAL-LIFNR = WA_T001L-LIFNR.
ENDLOOP.

LOOP AT IT_CEPC INTO WA_CEPC.
WA_FINAL-LAND1 = WA_CEPC-LAND1.
ENDLOOP.

READ TABLE IT_T001W INTO WA_T001W WITH KEY LIFNR = WA_T001L-LIFNR.
WA_FINAL-NAME1 = WA_T001W-NAME1.

APPEND WA_FINAL TO IT_FINAL.

CLEAR : WA_ZMM_BUSINESS,
WA_T001W,
WA_T001L,
WA_CEPC.
ENDLOOP.
ENDFORM.

FORM SET_FCAT.
* Calling SUB_FCAT_ALV form for displaying fields
PERFORM SUB_FCAT_ALV USING : 'WERKS' 'Plant',
'NAME1' 'plant description.',
'LGORT' 'storage location',
'LGOBE' 'storage location description.',
'LIFNR' 'vendor.',
'PRCTR' 'profit center.',
'LAND1' 'Country'.
* End of Calling SUB_FCAT_ALV form for displaying fields
ENDFORM.

FORM DISPLAY_ALV.
WA_FIELDLAYOUT-COLWIDTH_OPTIMIZE = 'X'.
L_PROG = SY-REPID.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = L_PROG
IS_LAYOUT = WA_FIELDLAYOUT
IT_FIELDCAT = IT_FIELDCAT
TABLES
T_OUTTAB = IT_FINAL
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.

IF SY-SUBRC <> 0.
* Implement suitable error handling here
* it_final.
ENDIF.
ENDFORM.

*** Form for updating field catalog
FORM SUB_FCAT_ALV USING P_FNAME TYPE CHAR20
P_TXT TYPE CHAR50.
DATA SNO TYPE I.
SNO = SNO + 1.
WA_FIELDCAT-COL_POS = SNO.
WA_FIELDCAT-FIELDNAME = P_FNAME.
WA_FIELDCAT-SELTEXT_L = P_TXT.

APPEND WA_FIELDCAT TO IT_FIELDCAT.

CLEAR WA_FIELDCAT.

ENDFORM.

Read only

0 Likes
1,430

Hi, Bhavani

you have taken loop for getting the value from table T001L, kindly check if value coming in WA_T001L-LIFNR is satisfying your read statement over table T001w. Debug your code you will get the solution.

Read only

former_member612655
Participant
1,430

Thanks Bhupendra for your reply. Now I am going to debug the code like as u said.

Read only

1,430

Please use Comment button when replying to others. Your Answer button is for posting the answers to the original question. Answers and comments are two different things on SCN now.

Read only

Jelena_Perfiljeva
Active Contributor
0 Likes
1,430

There are many issues with this program.

1. TABLES command is obsolete. I'm guessing it's included because of the SELECT-OPTIONS but you don't have to use TABLES for that, you can simply declare individual variables to use as a reference.

2. I'm all for modularization but in this case the data reading is split into multiple subroutines that are using global tables. I feel you'd be better off having just one main subroutine to prepare the data in this case. (Of course, ideally, we shouldn't even use subroutines anymore and use classes instead but, all things considered, that would be the least of my worries.) Also DIS is not a descriptive name for the routine, please use better names at least.

3. Selection options S_LGORT and S_PRCTR are not used anywhere in the program. Either remove them or use them.

4. Don't use REUSE_ALV... FM, unless you are on a very old release. Use SALV instead (Google it), it requires much less code and makes the whole field catalog logic unnecessary.

5. Use SELECT... JOIN instead of FOR ALL ENTRIES (FAE). For example, you're reading data from T001L by using primary key field (LGORT), that's a straight-forward inner join.

6. I don't understand some of the business logic here though. WERKS is the field in Z table. T001W is a plant master table where WERKS is primary key. But you're using WHERE LIFNR = IT_T001L-LIFNR. Why? Also then later in the program you are only taking a name field from it. Anyone looking at the report would think that it's the name for the WERKS in Z table. The profit center selection is even weirder. All P/Cs for the whole country? Isn't that a bit extreme?

7. Moving on to big LOOP - I'm lost here as well. What/how exactly are you expecting to appear on this report? In a scenario when additional data is selected using FAE, we usually end up with a LOOP over main table, like in your case, but then when reading data from other tables we'd use some WHERE conditions. Instead, what you have is two meaningless LOOPs over all entries in two internal tables that just set the same variable over and over. With this code you'll just end up with the same last value in the table every time. What is the point of this? READ is slightly better (just lacks sy-subrc check) but then your key value obviously won't be correct because of the silly LOOP above.

But in general, FAE seems unnecessary here, you could just read the data using one SELECT with JOIN directly into "final" table. (Not sure about the p/c data though but, again, I suspect business logic here is just incorrect.)